mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-16 12:03:23 +00:00
AgentInterface sets default streamFn and getApiKey
- Make Agent.streamFn and Agent.getApiKey public - AgentInterface sets defaults if not already set - Example no longer needs to configure these
This commit is contained in:
parent
92898f486b
commit
4d1936d3df
3 changed files with 21 additions and 14 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import type { ToolResultMessage, Usage } from "@mariozechner/pi-ai";
|
||||
import { streamSimple, type ToolResultMessage, type Usage } from "@mariozechner/pi-ai";
|
||||
import { html, LitElement } from "lit";
|
||||
import { customElement, property, query } from "lit/decorators.js";
|
||||
import { ModelSelector } from "../dialogs/ModelSelector.js";
|
||||
|
|
@ -12,6 +12,7 @@ import type { Agent, AgentEvent } from "@mariozechner/pi-agent-core";
|
|||
import type { Attachment } from "../utils/attachment-utils.js";
|
||||
import { formatUsage } from "../utils/format.js";
|
||||
import { i18n } from "../utils/i18n.js";
|
||||
import { createStreamFn } from "../utils/proxy-utils.js";
|
||||
import type { UserMessageWithAttachments } from "./Messages.js";
|
||||
import type { StreamingMessageContainer } from "./StreamingMessageContainer.js";
|
||||
|
||||
|
|
@ -130,6 +131,23 @@ export class AgentInterface extends LitElement {
|
|||
this._unsubscribeSession = undefined;
|
||||
}
|
||||
if (!this.session) return;
|
||||
|
||||
// Set default streamFn with proxy support if not already set
|
||||
if (this.session.streamFn === streamSimple) {
|
||||
this.session.streamFn = createStreamFn(async () => {
|
||||
const enabled = await getAppStorage().settings.get<boolean>("proxy.enabled");
|
||||
return enabled ? (await getAppStorage().settings.get<string>("proxy.url")) || undefined : undefined;
|
||||
});
|
||||
}
|
||||
|
||||
// Set default getApiKey if not already set
|
||||
if (!this.session.getApiKey) {
|
||||
this.session.getApiKey = async (provider: string) => {
|
||||
const key = await getAppStorage().providerKeys.get(provider);
|
||||
return key ?? undefined;
|
||||
};
|
||||
}
|
||||
|
||||
this._unsubscribeSession = this.session.subscribe(async (ev: AgentEvent) => {
|
||||
switch (ev.type) {
|
||||
case "message_start":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue