Merge branch 'pr-57'

This commit is contained in:
James Babcock committed 2026-11-01 00:29:16 -07:00
commit 7f3e3f2305
25 files changed
+1888 -41

No files matched your search

+7 -1
View File
@@ -2,6 +2,7 @@ import { streamAnthropicMessage } from "../native/anthropic";
import { streamHermesChat } from "../native/hermes";
import { streamLocalModel } from "../native/local-llm";
import { streamOpenAiResponse } from "../native/openai";
import { streamOpenAiCompatibleChat } from "../native/openai-chat";
import type {
LlmContentBlock,
LlmMessage,
@@ -40,6 +41,8 @@ export type DirectTurnOptions = {
effort?: "low" | "medium" | "high";
/** Hermes: the API root, and the server-side session this conversation maps to. */
baseUrl?: string;
/** Venice-only web search for this interactive turn. */
webSearch?: boolean;
sessionId?: string;
system: string;
/** Owned by the session; this loop appends assistant + tool_result messages. */
@@ -85,11 +88,12 @@ export class DirectAssistantBackend {
return;
}
const streamOptions: LlmStreamOptions = {
const streamOptions: LlmStreamOptions & { webSearch?: boolean } = {
apiKey: options.apiKey,
model: options.model,
system: options.system,
effort: options.effort,
webSearch: options.webSearch,
messages: options.messages,
// Hermes runs its own tools; Faceclaw's are not offered to it.
tools: options.provider === "hermes" ? [] : options.buildTools(),
@@ -143,6 +147,8 @@ export class DirectAssistantBackend {
streamHandle =
options.provider === "hermes"
? streamHermesChat({ ...streamOptions, baseUrl: options.baseUrl ?? "", sessionId: options.sessionId ?? "" })
: options.provider === "openai-compatible"
? streamOpenAiCompatibleChat({ ...streamOptions, baseUrl: options.baseUrl ?? "" })
: options.provider === "openai"
? streamOpenAiResponse(streamOptions)
: options.provider === "local"
+1 -1
View File
@@ -15,7 +15,7 @@ export type LlmContentBlock =
}
| { type: "tool_result"; tool_use_id: string; content: string; is_error?: boolean }
/** Opaque state required to continue a provider's stateless conversation. */
| { type: "provider_item"; provider: "openai"; item: any };
| { type: "provider_item"; provider: "openai" | "openai-compatible"; item: any };
export type LlmMessage = {
role: "user" | "assistant";
+25 -2
View File
@@ -1,4 +1,5 @@
import { isLocalModelReady, isLocalModelSupported, LOCAL_MODEL } from "../native/local-llm";
import { isVeniceApiBaseUrl } from "../native/openai-chat";
export const ASSISTANT_MODEL_VALUES = [
"auto",
@@ -11,6 +12,7 @@ export const ASSISTANT_MODEL_VALUES = [
"sol",
"qwen",
"hermes",
"openai-compatible",
] as const;
/**
@@ -26,7 +28,7 @@ export function supportedAssistantModel(value: AssistantModel): AssistantModel {
return value === "qwen" && !isLocalModelSupported() ? "auto" : value;
}
export type AssistantProvider = "anthropic" | "openai" | "local" | "hermes";
export type AssistantProvider = "anthropic" | "openai" | "local" | "hermes" | "openai-compatible";
export type AssistantApiKeys = {
anthropic: string;
@@ -34,6 +36,11 @@ export type AssistantApiKeys = {
/** A Hermes Agent API server; only the voice assistant passes these. */
hermesUrl?: string;
hermesKey?: string;
openAiCompatibleUrl?: string;
openAiCompatibleKey?: string;
openAiCompatibleModel?: string;
/** Venice web search, applied only when the resolved root is Venice. */
veniceWebSearch?: boolean;
};
export type ResolvedAssistantModel = {
@@ -42,8 +49,10 @@ export type ResolvedAssistantModel = {
model: string;
apiKey: string;
effort?: "low" | "medium" | "high";
/** API root for providers that are not fixed services (Hermes). */
/** API root for Hermes or an OpenAI-compatible provider. */
baseUrl?: string;
/** Whether Venice web search is enabled for this interactive assistant turn. */
webSearch?: boolean;
};
type ModelDefinition = {
@@ -69,6 +78,7 @@ const MODEL_DEFINITIONS: Record<Exclude<AssistantModel, "auto">, ModelDefinition
qwen: { label: `${LOCAL_MODEL.label} (on-phone)`, provider: "local", model: LOCAL_MODEL.id },
// Your own Hermes Agent (its API server), with its own tools and memory.
hermes: { label: "Hermes agent", provider: "hermes", model: "hermes-agent" },
"openai-compatible": { label: "OpenAI-compatible", provider: "openai-compatible", model: "custom" },
};
export function assistantModelLabel(value: AssistantModel): string {
@@ -112,6 +122,19 @@ export function resolveAssistantModel(
if (!baseUrl) return null;
return { selection, provider: "hermes", model: definition.model, apiKey: keys.hermesKey?.trim() ?? "", baseUrl };
}
if (definition.provider === "openai-compatible") {
const baseUrl = keys.openAiCompatibleUrl?.trim() ?? "";
const model = keys.openAiCompatibleModel?.trim() ?? "";
if (!baseUrl || !model) return null;
return {
selection,
provider: definition.provider,
model,
apiKey: keys.openAiCompatibleKey?.trim() ?? "",
baseUrl,
webSearch: isVeniceApiBaseUrl(baseUrl) && keys.veniceWebSearch === true,
};
}
if (definition.provider === "local") {
if (!isLocalModelReady()) return null;
return {
+9 -2
View File
@@ -95,14 +95,20 @@ export class AssistantSession {
// original model. Preserve visible conversation when switching engines.
if (this.config.kind !== config.kind ||
(this.config.kind === "direct" && config.kind === "direct" &&
(this.config.llm.model !== config.llm.model || this.config.llm.provider !== config.llm.provider))) {
(this.config.llm.model !== config.llm.model || this.config.llm.provider !== config.llm.provider ||
(this.config.llm.baseUrl ?? "") !== (config.llm.baseUrl ?? "")))) {
this.rebuildTextHistory();
}
this.config = config;
}
private engine(): string {
return this.config.kind === "direct" ? `${this.config.llm.provider}:${this.config.llm.model}` : "external";
if (this.config.kind !== "direct") return "external";
const llm = this.config.llm;
// Keep the legacy engine ID for built-in providers so upgrading does not
// discard their opaque history. Custom endpoints need endpoint isolation.
const endpoint = llm.provider === "openai-compatible" ? `:${llm.baseUrl ?? ""}` : "";
return `${llm.provider}:${llm.model}${endpoint}`;
}
private rebuildTextHistory(): void {
@@ -192,6 +198,7 @@ export class AssistantSession {
model: llm.model,
effort: llm.effort,
baseUrl: llm.baseUrl,
webSearch: llm.webSearch,
sessionId: this.hermesSessionId,
system: llm.provider === "hermes" ? HERMES_SYSTEM_PROMPT
: isLocal ? ASSISTANT_SYSTEM_PROMPT_BASE : buildAssistantSystemPrompt(ctx),