forked from Blendman974/faceclaw
External assistant backend: agent bridge client + MCP server
Phase 3 of the voice-assistant design: assistant.backend=external routes utterances over a dial-out websocket to faceclaw-agent-bridge (an OpenClaw plugin on the user's machine). The phone serves its ToolRegistry as MCP on the same socket, with proactive gating and rate limiting enforced locally. New Assistant settings section with backend/bridge settings. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XCdkQyB3RUVPTuEmhxVEdp
This commit is contained in:
1 parent
474844f961
commit
48bac85cbe
9 files changed
+722
-56
No files matched your search
@@ -350,6 +350,65 @@ export const assistantSkipConfirmationSetting = new ConfigSettingBoolean({
|
||||
description: "After a wakeword utterance, send the transcript straight to the assistant instead of stopping at the Send/Type confirmation menu.",
|
||||
});
|
||||
|
||||
export type AssistantBackendKind = "direct" | "external";
|
||||
|
||||
const assistantBackendLabels: Record<AssistantBackendKind, string> = {
|
||||
direct: "On-phone (API key)",
|
||||
external: "My own agent (bridge)",
|
||||
};
|
||||
|
||||
export const assistantBackendSetting = new ConfigSettingEnum<AssistantBackendKind>({
|
||||
id: "assistant-backend",
|
||||
label: "Assistant backend",
|
||||
storageKey: "assistant.backend",
|
||||
defaultValue: "direct",
|
||||
values: ["direct", "external"],
|
||||
formatValue: (value) => assistantBackendLabels[value] ?? value,
|
||||
description:
|
||||
"Who answers assistant queries: an LLM called directly from the phone (needs an API key), or your own long-running agent (e.g. OpenClaw) reached through the faceclaw-agent-bridge plugin.",
|
||||
});
|
||||
|
||||
export const assistantBridgeHostSetting = new ConfigSettingString({
|
||||
id: "assistant-bridge-host",
|
||||
label: "Bridge host",
|
||||
storageKey: "assistant.bridgeHost",
|
||||
defaultValue: "",
|
||||
editorTitle: "Agent bridge host (tailscale IP)",
|
||||
glassesEditTitle: "Edit bridge host",
|
||||
description:
|
||||
"Hostname or IP address (e.g. a Tailscale address) of the machine running the agent bridge.",
|
||||
});
|
||||
|
||||
export const assistantBridgePortSetting = new ConfigSettingString({
|
||||
id: "assistant-bridge-port",
|
||||
label: "Bridge port",
|
||||
storageKey: "assistant.bridgePort",
|
||||
defaultValue: "8790",
|
||||
editorTitle: "Agent bridge port",
|
||||
glassesEditTitle: "Edit bridge port",
|
||||
description: "TCP port the agent bridge listens on. The default is 8790.",
|
||||
});
|
||||
|
||||
export const assistantBridgeTokenSetting = new ConfigSettingString({
|
||||
id: "assistant-bridge-token",
|
||||
label: "Bridge token",
|
||||
storageKey: "assistant.bridgeToken",
|
||||
defaultValue: "",
|
||||
editorTitle: "Agent bridge auth token",
|
||||
glassesEditTitle: "Edit bridge token",
|
||||
formatValue: (value) => (value ? `${value.slice(0, 6)}...` : "(not set)"),
|
||||
description: "Shared secret that must match the bridge's configured token.",
|
||||
});
|
||||
|
||||
export const assistantAllowProactiveSetting = new ConfigSettingBoolean({
|
||||
id: "assistant-allow-proactive",
|
||||
label: "Allow proactive agent actions",
|
||||
storageKey: "assistant.allowProactive",
|
||||
defaultValue: true,
|
||||
description:
|
||||
"Let the external agent use glasses tools outside of a conversation, e.g. showing an alert when a long-running job finishes. Rate-limited; only tools marked proactive-safe are allowed.",
|
||||
});
|
||||
|
||||
export const elevenLabsApiKeySetting = new ConfigSettingString({
|
||||
id: "elevenlabs-api-key",
|
||||
label: "ElevenLabs key",
|
||||
|
||||
@@ -8,6 +8,11 @@ import type { MenuItem } from "../menu";
|
||||
import { shell } from "../shell/shell";
|
||||
import {
|
||||
anthropicApiKeySetting,
|
||||
assistantAllowProactiveSetting,
|
||||
assistantBackendSetting,
|
||||
assistantBridgeHostSetting,
|
||||
assistantBridgePortSetting,
|
||||
assistantBridgeTokenSetting,
|
||||
assistantModelSetting,
|
||||
assistantSkipConfirmationSetting,
|
||||
batteryDisplayModeSetting,
|
||||
@@ -69,10 +74,21 @@ function settingsSections(): SettingsSection[] {
|
||||
items: [
|
||||
enumSettingMenuItem(wakeWordActionSetting),
|
||||
enumSettingMenuItem(voiceProviderSetting),
|
||||
],
|
||||
},
|
||||
{
|
||||
label: "Assistant",
|
||||
items: [
|
||||
// On-phone LLM loop vs the user's own agent via the bridge plugin.
|
||||
enumSettingMenuItem(assistantBackendSetting),
|
||||
enumSettingMenuItem(assistantModelSetting),
|
||||
// When on, a wakeword utterance goes straight to the assistant with no
|
||||
// Send/Type menu step.
|
||||
toggleSettingMenuItem(assistantSkipConfirmationSetting),
|
||||
textSettingMenuItem(assistantBridgeHostSetting),
|
||||
textSettingMenuItem(assistantBridgePortSetting),
|
||||
textSettingMenuItem(assistantBridgeTokenSetting),
|
||||
toggleSettingMenuItem(assistantAllowProactiveSetting),
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
+25
-9
@@ -6,12 +6,16 @@ import { DashboardInputEvent, Layer, LayerActions, LayerContext, LayerStack, noo
|
||||
import { MenuLayer, type MenuItem } from "../menu";
|
||||
import { VoiceInputLayer, type VoiceSendTarget } from "../apps/voice-input";
|
||||
import { AssistantLayer } from "../apps/assistant";
|
||||
import { AssistantSession } from "../../assistant/session";
|
||||
import { resolveAssistantModel, type ResolvedAssistantModel } from "../../assistant/models";
|
||||
import { AssistantSession, type AssistantBackendConfig } from "../../assistant/session";
|
||||
import { resolveAssistantModel } from "../../assistant/models";
|
||||
import type { AssistantContext } from "../../assistant/types";
|
||||
import { SingleNotificationLayer } from "../notifications";
|
||||
import {
|
||||
anthropicApiKeySetting,
|
||||
assistantBackendSetting,
|
||||
assistantBridgeHostSetting,
|
||||
assistantBridgePortSetting,
|
||||
assistantBridgeTokenSetting,
|
||||
assistantModelSetting,
|
||||
assistantSkipConfirmationSetting,
|
||||
batteryDisplayModeSetting,
|
||||
@@ -722,24 +726,32 @@ class Shell {
|
||||
}
|
||||
|
||||
private ensureAssistantSession(): AssistantSession | null {
|
||||
const llm = this.resolveAssistantConfiguration();
|
||||
if (!llm) return null;
|
||||
const config = this.resolveAssistantConfiguration();
|
||||
if (!config) return null;
|
||||
if (
|
||||
!this.assistantSession ||
|
||||
this.assistantSession.isExpired() ||
|
||||
!this.assistantSession.matchesConfiguration(llm)
|
||||
!this.assistantSession.matchesConfiguration(config)
|
||||
) {
|
||||
this.assistantSession?.cancel();
|
||||
this.assistantSession = new AssistantSession(llm);
|
||||
this.assistantSession = new AssistantSession(config);
|
||||
}
|
||||
return this.assistantSession;
|
||||
}
|
||||
|
||||
private resolveAssistantConfiguration(): ResolvedAssistantModel | null {
|
||||
return resolveAssistantModel(assistantModelSetting.get(), {
|
||||
private resolveAssistantConfiguration(): AssistantBackendConfig | null {
|
||||
if (assistantBackendSetting.get() === "external") {
|
||||
const host = assistantBridgeHostSetting.get().trim();
|
||||
const token = assistantBridgeTokenSetting.get();
|
||||
if (!host || !token) return null;
|
||||
const port = parseInt(assistantBridgePortSetting.get(), 10) || 8790;
|
||||
return { kind: "external", bridge: { host, port, token } };
|
||||
}
|
||||
const llm = resolveAssistantModel(assistantModelSetting.get(), {
|
||||
anthropic: anthropicApiKeySetting.get(),
|
||||
openai: openAiApiKeySetting.get(),
|
||||
});
|
||||
return llm ? { kind: "direct", llm } : null;
|
||||
}
|
||||
|
||||
private buildAssistantContext(): AssistantContext {
|
||||
@@ -761,7 +773,11 @@ class Shell {
|
||||
sendToAssistant(text: string): void {
|
||||
const session = this.ensureAssistantSession();
|
||||
if (!session) {
|
||||
this.showAlert("Set an API key for the selected assistant model in Settings.");
|
||||
this.showAlert(
|
||||
assistantBackendSetting.get() === "external"
|
||||
? "Configure the agent bridge host and token in Settings."
|
||||
: "Set an API key for the selected assistant model in Settings.",
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (!this.screenOn) this.wake("sidebar");
|
||||
|
||||
Reference in new issue
Block a user