nova-personal-agent-server 0.4.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +674 -201
- package/README.md +10 -0
- package/bin/nova-space-host.mjs +4 -0
- package/node_modules/@nova-personal-agent/relay/dist/src/cli.js +71 -0
- package/node_modules/@nova-personal-agent/relay/dist/src/client.js +340 -0
- package/node_modules/@nova-personal-agent/relay/dist/src/crypto.js +167 -0
- package/node_modules/@nova-personal-agent/relay/dist/src/live.js +169 -0
- package/node_modules/@nova-personal-agent/relay/dist/src/mailbox.js +217 -0
- package/node_modules/@nova-personal-agent/relay/dist/src/media.js +320 -0
- package/node_modules/@nova-personal-agent/relay/dist/src/pairing.js +13 -0
- package/node_modules/@nova-personal-agent/relay/dist/src/protocol.js +50 -0
- package/node_modules/@nova-personal-agent/relay/dist/src/security.js +305 -0
- package/node_modules/@nova-personal-agent/relay/dist/src/server.js +477 -0
- package/node_modules/@nova-personal-agent/relay/dist/src/source-address.js +58 -0
- package/node_modules/@nova-personal-agent/relay/package.json +1 -0
- package/package.json +11 -4
- package/runtime/dist/src/cascaded-text-provider.js +8 -3
- package/runtime/dist/src/composition/assembly.js +133 -35
- package/runtime/dist/src/composition/cascaded-realtime-assembly.js +114 -59
- package/runtime/dist/src/composition/production-composition.js +57 -21
- package/runtime/dist/src/composition/realtime-assembly.js +160 -52
- package/runtime/dist/src/composition/soul-context.js +22 -0
- package/runtime/dist/src/config/capability-registry.js +48 -3
- package/runtime/dist/src/config/cascaded-realtime-config.js +23 -10
- package/runtime/dist/src/config/config.js +541 -128
- package/runtime/dist/src/config/credential-rotation.js +26 -0
- package/runtime/dist/src/config/data-root.js +764 -0
- package/runtime/dist/src/config/diagnostics.js +3 -1
- package/runtime/dist/src/config/environment-contract.js +190 -188
- package/runtime/dist/src/config/model-routes.js +140 -0
- package/runtime/dist/src/config/voice-credentials.js +55 -0
- package/runtime/dist/src/connectors/composio/index.js +9 -0
- package/runtime/dist/src/connectors/feishu/index.js +258 -44
- package/runtime/dist/src/connectors/macos/mail.js +7 -3
- package/runtime/dist/src/connectors/macos/reader.js +3 -1
- package/runtime/dist/src/conversation-voice-provider.js +5 -2
- package/runtime/dist/src/core/causal-runtime.js +38 -3
- package/runtime/dist/src/core/context-view.js +7 -0
- package/runtime/dist/src/core/guards.js +32 -0
- package/runtime/dist/src/core/runtime.js +3 -0
- package/runtime/dist/src/core/schedule-tools.js +2 -2
- package/runtime/dist/src/core/source-processing-instructions.js +2 -2
- package/runtime/dist/src/core/source-processing-tools.js +3 -1
- package/runtime/dist/src/core/tool-schema.js +42 -7
- package/runtime/dist/src/desktop/desktop-camera.js +3 -5
- package/runtime/dist/src/desktop/desktop-control.js +41 -8
- package/runtime/dist/src/desktop/desktop-session.js +90 -19
- package/runtime/dist/src/desktop/desktop-wire.js +5 -7
- package/runtime/dist/src/desktop/startup-error.js +18 -16
- package/runtime/dist/src/desktop/workbench-acceptance.js +52 -14
- package/runtime/dist/src/desktop-entry.js +6 -2
- package/runtime/dist/src/desktop.js +5 -1
- package/runtime/dist/src/device/attempt.js +65 -0
- package/runtime/dist/src/device/authority.js +159 -0
- package/runtime/dist/src/device/gateway.js +87 -0
- package/runtime/dist/src/device/ledger.js +91 -0
- package/runtime/dist/src/device/ownership.js +92 -0
- package/runtime/dist/src/device/port.js +2 -0
- package/runtime/dist/src/device/schedule-ownership.js +103 -0
- package/runtime/dist/src/executors/acp/transport.js +2 -0
- package/runtime/dist/src/executors/browser.js +4 -3
- package/runtime/dist/src/executors/codex/adapter-project.js +58 -12
- package/runtime/dist/src/executors/codex/app-server-schema.js +12 -21
- package/runtime/dist/src/executors/codex/app-server-transport.js +32 -18
- package/runtime/dist/src/executors/codex/common.js +1 -1
- package/runtime/dist/src/executors/codex/contract.js +12 -16
- package/runtime/dist/src/executors/codex/credential-snapshot.js +1 -9
- package/runtime/dist/src/executors/codex/factory.js +54 -32
- package/runtime/dist/src/executors/codex/host-config.js +69 -20
- package/runtime/dist/src/executors/codex/launch-profile.js +3 -2
- package/runtime/dist/src/executors/codex/local-provider-credential.js +39 -0
- package/runtime/dist/src/executors/codex/process-owner.js +4 -6
- package/runtime/dist/src/executors/codex/production-host.js +33 -34
- package/runtime/dist/src/executors/codex/protocol.js +9 -14
- package/runtime/dist/src/executors/codex/session-title.js +6 -8
- package/runtime/dist/src/executors/codex/spawn-env.js +27 -6
- package/runtime/dist/src/executors/codex/turn-projection.js +12 -17
- package/runtime/dist/src/executors/codex/windows-guardian.js +4 -6
- package/runtime/dist/src/executors/coding/intake.js +12 -7
- package/runtime/dist/src/executors/computer-backend.js +18 -10
- package/runtime/dist/src/executors/computer-config.js +32 -0
- package/runtime/dist/src/executors/computer-device.js +68 -16
- package/runtime/dist/src/executors/computer-worker.js +18 -6
- package/runtime/dist/src/executors/computer.js +29 -56
- package/runtime/dist/src/executors/device-lock.js +14 -5
- package/runtime/dist/src/executors/gui-execution.js +2 -0
- package/runtime/dist/src/executors/index.js +0 -1
- package/runtime/dist/src/executors/mobile.js +9 -8
- package/runtime/dist/src/executors/native-process.js +4 -0
- package/runtime/dist/src/executors/search.js +3 -5
- package/runtime/dist/src/executors/task-resources.js +21 -0
- package/runtime/dist/src/executors/watcher.js +2 -4
- package/runtime/dist/src/experience/host.js +179 -0
- package/runtime/dist/src/index.js +2 -0
- package/runtime/dist/src/knowledge/assembly.js +3 -4
- package/runtime/dist/src/knowledge/embeddings.js +50 -34
- package/runtime/dist/src/knowledge/service.js +1 -0
- package/runtime/dist/src/knowledge/store-client.js +1 -6
- package/runtime/dist/src/knowledge/store-worker.js +1 -3
- package/runtime/dist/src/mem0/resource.js +25 -0
- package/runtime/dist/src/mem0/store-worker.js +234 -21
- package/runtime/dist/src/memory/consumer.js +31 -0
- package/runtime/dist/src/memory/engine-worker.js +210 -0
- package/runtime/dist/src/memory/entry.js +8 -1
- package/runtime/dist/src/memory/explicit-memory.js +20 -0
- package/runtime/dist/src/memory/factory.js +30 -15
- package/runtime/dist/src/memory/grounded-voicemem.js +10 -0
- package/runtime/dist/src/memory/ledger-recall-engine.js +86 -0
- package/runtime/dist/src/memory/prerecall-port.js +27 -0
- package/runtime/dist/src/memory/prerecall.js +1 -1
- package/runtime/dist/src/memory/production-engine.js +151 -0
- package/runtime/dist/src/memory/provenance.js +1 -0
- package/runtime/dist/src/memory/remote-personal-memory.js +3 -1
- package/runtime/dist/src/memory/retrieval.js +107 -22
- package/runtime/dist/src/memory/sensitivity.js +6 -2
- package/runtime/dist/src/memory/source-retrieval.js +11 -0
- package/runtime/dist/src/memory/tool-capabilities.js +46 -0
- package/runtime/dist/src/memory/voicemem-sdk/LICENSE +202 -0
- package/runtime/dist/src/memory/voicemem-sdk/NOTICE.md +97 -0
- package/runtime/dist/src/memory/voicemem-sdk/PATCH-NOTICE.md +23 -0
- package/runtime/dist/src/memory/voicemem-sdk/archive.js +12 -0
- package/runtime/dist/src/memory/voicemem-sdk/audio.js +111 -0
- package/runtime/dist/src/memory/voicemem-sdk/barge-in.js +59 -0
- package/runtime/dist/src/memory/voicemem-sdk/checkpoint.js +56 -0
- package/runtime/dist/src/memory/voicemem-sdk/cleanup.js +139 -0
- package/runtime/dist/src/memory/voicemem-sdk/dashscope-asr.js +254 -0
- package/runtime/dist/src/memory/voicemem-sdk/dashscope-tts.js +247 -0
- package/runtime/dist/src/memory/voicemem-sdk/evaluation.js +330 -0
- package/runtime/dist/src/memory/voicemem-sdk/extraction.js +220 -0
- package/runtime/dist/src/memory/voicemem-sdk/finetune-data.js +115 -0
- package/runtime/dist/src/memory/voicemem-sdk/finetune.js +170 -0
- package/runtime/dist/src/memory/voicemem-sdk/grounded-reply-preferences.js +81 -0
- package/runtime/dist/src/memory/voicemem-sdk/index.js +22 -0
- package/runtime/dist/src/memory/voicemem-sdk/local-embedding.js +164 -0
- package/runtime/dist/src/memory/voicemem-sdk/local-runtime.js +53 -0
- package/runtime/dist/src/memory/voicemem-sdk/local-speaker.js +240 -0
- package/runtime/dist/src/memory/voicemem-sdk/memory.js +767 -0
- package/runtime/dist/src/memory/voicemem-sdk/model-json.js +14 -0
- package/runtime/dist/src/memory/voicemem-sdk/personamem.js +209 -0
- package/runtime/dist/src/memory/voicemem-sdk/prompts/addenda.js +215 -0
- package/runtime/dist/src/memory/voicemem-sdk/prompts/additive-extraction.js +478 -0
- package/runtime/dist/src/memory/voicemem-sdk/prompts/index.js +32 -0
- package/runtime/dist/src/memory/voicemem-sdk/prompts/update-memory.js +152 -0
- package/runtime/dist/src/memory/voicemem-sdk/providers.js +325 -0
- package/runtime/dist/src/memory/voicemem-sdk/ranking.js +65 -0
- package/runtime/dist/src/memory/voicemem-sdk/reaction.js +33 -0
- package/runtime/dist/src/memory/voicemem-sdk/realtime.js +215 -0
- package/runtime/dist/src/memory/voicemem-sdk/reply.js +68 -0
- package/runtime/dist/src/memory/voicemem-sdk/routing.js +209 -0
- package/runtime/dist/src/memory/voicemem-sdk/slots.js +61 -0
- package/runtime/dist/src/memory/voicemem-sdk/speaker-bindings.js +120 -0
- package/runtime/dist/src/memory/voicemem-sdk/speaker-profiles.js +327 -0
- package/runtime/dist/src/memory/voicemem-sdk/store.js +577 -0
- package/runtime/dist/src/memory/voicemem-sdk/stream.js +317 -0
- package/runtime/dist/src/memory/voicemem-sdk/subgraph.js +113 -0
- package/runtime/dist/src/memory/voicemem-sdk/summaries.js +56 -0
- package/runtime/dist/src/memory/voicemem-sdk/time.js +157 -0
- package/runtime/dist/src/memory/voicemem-sdk/types.js +2 -0
- package/runtime/dist/src/memory-ledger/store-client.js +235 -37
- package/runtime/dist/src/memory-ledger/store-worker.js +8 -5
- package/runtime/dist/src/memory-ledger/store.js +91 -1
- package/runtime/dist/src/memory-substrate/consolidation.js +23 -7
- package/runtime/dist/src/memory-substrate/diary.js +27 -0
- package/runtime/dist/src/memory-substrate/engine-outbox.js +107 -0
- package/runtime/dist/src/memory-substrate/explicit-memory.js +112 -0
- package/runtime/dist/src/memory-substrate/fact-fidelity.js +68 -0
- package/runtime/dist/src/memory-substrate/feishu-consent.js +41 -0
- package/runtime/dist/src/memory-substrate/file-authority.js +29 -6
- package/runtime/dist/src/memory-substrate/life-operations.js +35 -9
- package/runtime/dist/src/memory-substrate/markdown-repository.js +271 -65
- package/runtime/dist/src/memory-substrate/memory-documents.js +96 -0
- package/runtime/dist/src/memory-substrate/migration.js +2 -0
- package/runtime/dist/src/memory-substrate/purge.js +12 -2
- package/runtime/dist/src/memory-substrate/resource.js +514 -129
- package/runtime/dist/src/memory-substrate/retrieval.js +8 -5
- package/runtime/dist/src/memory-substrate/source-operations.js +9 -1
- package/runtime/dist/src/memory-substrate/source-processing.js +436 -40
- package/runtime/dist/src/memory-substrate/source-retrieval.js +28 -0
- package/runtime/dist/src/memory-substrate/source-state.js +8 -0
- package/runtime/dist/src/memory-substrate/space-source-input.js +90 -0
- package/runtime/dist/src/memory-substrate/store.js +125 -23
- package/runtime/dist/src/model/goal-checkin-writer.js +72 -0
- package/runtime/dist/src/model/goal-writer.js +80 -0
- package/runtime/dist/src/model/jev-client.js +24 -13
- package/runtime/dist/src/model/model-adapters.js +2 -3
- package/runtime/dist/src/model/model-catalog.js +80 -0
- package/runtime/dist/src/model/model-gateway.js +47 -18
- package/runtime/dist/src/model/model-purpose.js +3 -4
- package/runtime/dist/src/model/personal-writer.js +536 -44
- package/runtime/dist/src/model/proactivity.js +50 -6
- package/runtime/dist/src/model/responses-model-gateway.js +59 -0
- package/runtime/dist/src/model/task-verifier.js +3 -3
- package/runtime/dist/src/model/timeline-anchors.js +77 -0
- package/runtime/dist/src/model/timeline-perspective.js +13 -0
- package/runtime/dist/src/model/timeline-selection.js +182 -0
- package/runtime/dist/src/model/understanding-writer.js +27 -0
- package/runtime/dist/src/model/vision-capability.js +3 -1
- package/runtime/dist/src/model/workbench-writer.js +96 -0
- package/runtime/dist/src/news/feeds.js +6 -10
- package/runtime/dist/src/news/interests.js +23 -0
- package/runtime/dist/src/news/service.js +87 -31
- package/runtime/dist/src/news/sources.json +116 -0
- package/runtime/dist/src/notifications/adapters/space-relay.js +4 -0
- package/runtime/dist/src/notifications/content.js +41 -0
- package/runtime/dist/src/notifications/contracts.js +4 -2
- package/runtime/dist/src/notifications/feed.js +6 -2
- package/runtime/dist/src/notifications/service.js +27 -14
- package/runtime/dist/src/notifications/store.js +3 -1
- package/runtime/dist/src/personal-agent/app-context.js +39 -4
- package/runtime/dist/src/personal-agent/chat-failure.js +37 -0
- package/runtime/dist/src/personal-agent/computer-use/contract.js +42 -0
- package/runtime/dist/src/personal-agent/computer-use/session.js +280 -0
- package/runtime/dist/src/personal-agent/computer-use/skill.js +18 -0
- package/runtime/dist/src/personal-agent/computer-use/tools.js +15 -0
- package/runtime/dist/src/personal-agent/context-candidates.js +9 -13
- package/runtime/dist/src/personal-agent/context-dependencies.js +28 -0
- package/runtime/dist/src/personal-agent/contracts.js +24 -4
- package/runtime/dist/src/personal-agent/conversation-runtime.js +440 -42
- package/runtime/dist/src/personal-agent/conversation-tool-bridge.js +97 -0
- package/runtime/dist/src/personal-agent/conversation-tool-policy.js +22 -0
- package/runtime/dist/src/personal-agent/conversations.js +71 -15
- package/runtime/dist/src/personal-agent/daily-brief.js +5 -0
- package/runtime/dist/src/personal-agent/daily-workbench.js +558 -0
- package/runtime/dist/src/personal-agent/discovery-window.js +36 -0
- package/runtime/dist/src/personal-agent/goal-checkin.js +53 -0
- package/runtime/dist/src/personal-agent/host.js +2379 -223
- package/runtime/dist/src/personal-agent/identity-context.js +33 -0
- package/runtime/dist/src/personal-agent/life.js +129 -11
- package/runtime/dist/src/personal-agent/local-shell.js +181 -0
- package/runtime/dist/src/personal-agent/local-tools.js +234 -0
- package/runtime/dist/src/personal-agent/preferred-name-sync.js +35 -0
- package/runtime/dist/src/personal-agent/profile-warmup.js +100 -39
- package/runtime/dist/src/personal-agent/project-digests.js +7 -3
- package/runtime/dist/src/personal-agent/project-history.js +36 -0
- package/runtime/dist/src/personal-agent/reading-copies.js +183 -0
- package/runtime/dist/src/personal-agent/scheduled-tasks.js +50 -13
- package/runtime/dist/src/personal-agent/scheduled-tool-runtime.js +26 -10
- package/runtime/dist/src/personal-agent/source-processing-agent.js +239 -17
- package/runtime/dist/src/personal-agent/sources.js +9 -1
- package/runtime/dist/src/personal-agent/store.js +124 -14
- package/runtime/dist/src/personal-agent/task-loop.js +3 -0
- package/runtime/dist/src/personal-agent/tasks.js +16 -4
- package/runtime/dist/src/personal-agent/timeline-brief.js +462 -0
- package/runtime/dist/src/personal-agent/timeline-cache.js +191 -0
- package/runtime/dist/src/personal-agent/timeline-cluster.js +30 -0
- package/runtime/dist/src/personal-agent/timeline-inputs.js +47 -0
- package/runtime/dist/src/personal-agent/timeline-time.js +60 -0
- package/runtime/dist/src/personal-agent/understanding-products.js +49 -0
- package/runtime/dist/src/personal-agent/understanding.js +7 -22
- package/runtime/dist/src/personal-agent/workbench-context.js +17 -21
- package/runtime/dist/src/personal-agent/workbench-copy.js +124 -0
- package/runtime/dist/src/personal-agent/workbench-evidence.js +77 -0
- package/runtime/dist/src/personal-agent/workbench-instructions.js +21 -0
- package/runtime/dist/src/personal-agent/workbench-runtime.js +1006 -0
- package/runtime/dist/src/personal-agent/workbench-shell-class.js +304 -0
- package/runtime/dist/src/personal-agent/workbench-store.js +292 -0
- package/runtime/dist/src/personal-agent/workbench-temporal.js +66 -0
- package/runtime/dist/src/projects/project-native-resource.js +10 -8
- package/runtime/dist/src/projects/project-store.js +36 -4
- package/runtime/dist/src/realtime/bridge.js +77 -8
- package/runtime/dist/src/realtime/capabilities.js +19 -0
- package/runtime/dist/src/realtime/cascaded/adapter.js +180 -40
- package/runtime/dist/src/realtime/cascaded/ark-llm.js +150 -24
- package/runtime/dist/src/realtime/cascaded/chat-completions-llm.js +243 -83
- package/runtime/dist/src/realtime/cascaded/llm-stream-limits.js +18 -0
- package/runtime/dist/src/realtime/cascaded/llm.js +96 -0
- package/runtime/dist/src/realtime/cascaded/openai-compatible-speech.js +251 -0
- package/runtime/dist/src/realtime/cascaded/provider.js +8 -0
- package/runtime/dist/src/realtime/evidence.js +1 -1
- package/runtime/dist/src/realtime/frontend-instructions.js +76 -55
- package/runtime/dist/src/realtime/gemini.js +14 -3
- package/runtime/dist/src/realtime/host-delivery.js +37 -4
- package/runtime/dist/src/realtime/protocol.js +18 -3
- package/runtime/dist/src/realtime/provider-projection.js +4 -1
- package/runtime/dist/src/realtime/provider-session.js +73 -16
- package/runtime/dist/src/realtime/qwen-transport.js +35 -4
- package/runtime/dist/src/realtime/qwen.js +144 -9
- package/runtime/dist/src/realtime/service-state.js +0 -1
- package/runtime/dist/src/realtime/service.js +93 -7
- package/runtime/dist/src/realtime/session.js +39 -32
- package/runtime/dist/src/realtime/sglang-native.js +214 -0
- package/runtime/dist/src/realtime/system-prompts.en.js +14 -2
- package/runtime/dist/src/realtime/telemetry.js +6 -3
- package/runtime/dist/src/realtime/tool-continuations.js +84 -7
- package/runtime/dist/src/realtime/transport.js +17 -0
- package/runtime/dist/src/realtime/usage.js +33 -17
- package/runtime/dist/src/realtime/volcengine/ark.js +40 -15
- package/runtime/dist/src/realtime/volcengine/asr.js +2 -1
- package/runtime/dist/src/realtime/volcengine/silence-endpointing.js +1 -7
- package/runtime/dist/src/realtime/volcengine/tts.js +2 -1
- package/runtime/dist/src/server/aoq-chat-server.js +1 -1
- package/runtime/dist/src/server/client-server.js +21 -0
- package/runtime/dist/src/server-entry.js +3 -0
- package/runtime/dist/src/space-host/admin-socket.js +115 -0
- package/runtime/dist/src/space-host/audio-owner.js +44 -0
- package/runtime/dist/src/space-host/cli.js +195 -0
- package/runtime/dist/src/space-host/config.js +247 -0
- package/runtime/dist/src/space-host/context-input.js +12 -0
- package/runtime/dist/src/space-host/contracts.js +10 -0
- package/runtime/dist/src/space-host/host-admin.js +114 -0
- package/runtime/dist/src/space-host/key-delivery.js +28 -0
- package/runtime/dist/src/space-host/mobile-tools.js +9 -0
- package/runtime/dist/src/space-host/model-settings.js +213 -0
- package/runtime/dist/src/space-host/projection.js +37 -0
- package/runtime/dist/src/space-host/push.js +137 -0
- package/runtime/dist/src/space-host/relay-transport.js +55 -0
- package/runtime/dist/src/space-host/service.js +841 -0
- package/runtime/dist/src/space-host/voice-crypto.js +240 -0
- package/runtime/dist/src/space-host/voice.js +600 -0
- package/runtime/dist/src/space-host/windows-secret-key.js +82 -0
- package/runtime/dist/src/storage/private-database.js +7 -10
- package/runtime/dist/src/text/unicode-normalize.js +5 -1
- package/runtime/dist/src/understanding/candidates.js +8 -10
- package/runtime/dist/src/understanding/fixture.js +1 -1
- package/runtime/dist/src/understanding/pipeline.js +4 -4
- package/runtime/dist/src/usage/context.js +23 -0
- package/runtime/dist/src/usage/index.js +4 -0
- package/runtime/dist/src/usage/ledger-worker.js +90 -0
- package/runtime/dist/src/usage/ledger.js +74 -0
- package/runtime/dist/src/usage/model-call.js +63 -0
- package/runtime/dist/src/usage/pricing.js +68 -0
- package/runtime/dist/src/usage/summary.js +69 -0
- package/runtime/dist/src/voicemem/store-client.js +104 -21
- package/runtime/dist/src/voicemem/store-worker.js +5 -8
- package/runtime/dist/src/voicemem/versioned-memory.js +1 -1
- package/src/command.mjs +8 -1
- package/runtime/dist/src/executors/autoglm.js +0 -376
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { realtimeCapabilities } from './capabilities.js';
|
|
1
2
|
import { canonicalJson } from '../text/canonical-json.js';
|
|
2
3
|
import { randomUUID } from 'node:crypto';
|
|
3
4
|
import { abortable } from '../core/camera-session.js';
|
|
@@ -15,6 +16,7 @@ const failure = () => new Error('Gemini Live protocol or connection failed');
|
|
|
15
16
|
* Internal transport replacement retains the host epoch but invalidates every old socket reader.
|
|
16
17
|
*/
|
|
17
18
|
export class GeminiLiveAdapter {
|
|
19
|
+
capabilities = realtimeCapabilities.gemini;
|
|
18
20
|
userResponseMode = 'automatic';
|
|
19
21
|
responseAdaptationMode = 'session_setup';
|
|
20
22
|
mediaCapability = { originalImageInput: false };
|
|
@@ -30,6 +32,8 @@ export class GeminiLiveAdapter {
|
|
|
30
32
|
#history = [];
|
|
31
33
|
#workspace;
|
|
32
34
|
#adaptation;
|
|
35
|
+
/** The guidance the current socket was set up with; only an acknowledged setup counts as delivered. */
|
|
36
|
+
#deliveredAdaptation;
|
|
33
37
|
#pending = new Map();
|
|
34
38
|
#calls = new Map();
|
|
35
39
|
#response;
|
|
@@ -72,6 +76,7 @@ export class GeminiLiveAdapter {
|
|
|
72
76
|
this.#user = undefined;
|
|
73
77
|
this.#workspace = undefined;
|
|
74
78
|
this.#adaptation = undefined;
|
|
79
|
+
this.#deliveredAdaptation = undefined;
|
|
75
80
|
this.#used = false;
|
|
76
81
|
await this.#serial(() => this.#open(options.signal));
|
|
77
82
|
return { epoch: this.#epoch, provider_session_id: `gemini-${this.#epoch}-${this.#id()}` };
|
|
@@ -149,13 +154,18 @@ export class GeminiLiveAdapter {
|
|
|
149
154
|
await this.#serial(async () => {
|
|
150
155
|
if (this.#adaptation && context.revision < this.#adaptation.revision)
|
|
151
156
|
throw failure();
|
|
152
|
-
|
|
157
|
+
// Compare with what the live socket carries: a cancelled or failed refresh leaves the old setup in place.
|
|
158
|
+
const prior = this.#deliveredAdaptation;
|
|
153
159
|
this.#adaptation = context;
|
|
154
|
-
if (JSON.stringify([prior?.content, prior?.user_sources]) === JSON.stringify([context.content, context.user_sources]))
|
|
160
|
+
if (this.#socket && JSON.stringify([prior?.content, prior?.user_sources]) === JSON.stringify([context.content, context.user_sources])) {
|
|
161
|
+
this.#deliveredAdaptation = context;
|
|
155
162
|
return;
|
|
163
|
+
}
|
|
156
164
|
// Empty initial guidance has no server-visible effect.
|
|
157
|
-
if (!prior && !context.content && !context.user_sources?.length)
|
|
165
|
+
if (!prior && !context.content && !context.user_sources?.length) {
|
|
166
|
+
this.#deliveredAdaptation = context;
|
|
158
167
|
return;
|
|
168
|
+
}
|
|
159
169
|
await this.#refresh(signal);
|
|
160
170
|
});
|
|
161
171
|
}
|
|
@@ -280,6 +290,7 @@ export class GeminiLiveAdapter {
|
|
|
280
290
|
ownedSignal.throwIfAborted();
|
|
281
291
|
if (this.#socket !== socket)
|
|
282
292
|
throw failure();
|
|
293
|
+
this.#deliveredAdaptation = this.#adaptation;
|
|
283
294
|
void this.#read(socket, this.#epoch);
|
|
284
295
|
}
|
|
285
296
|
catch {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { abortable } from '../core/camera-session.js';
|
|
1
2
|
import { USER_PRIORITY } from '../core/memory.js';
|
|
2
3
|
import { MAX_TRACKED_ORIGIN_DELIVERY_PROOFS, MAX_TRACKED_SEMANTIC_ACKNOWLEDGEMENTS, MAX_UNCERTAIN_DELIVERY_RETRIES, PREEMPTIVE_ALERT_CLEAR_ACK_DEADLINE_S, PREEMPTIVE_ALERT_DEADLINE_S, PREEMPT_MIN_PRIORITY, USER_HOLD_MAX_S, callKey, compareQueuedHostResponses, hostFactIntent, semanticAcknowledgement } from './service-state.js';
|
|
3
4
|
import { MAX_CONTINUATION_TASK_SUMMARY, MAX_PENDING_HOST_EVENTS } from './session-state.js';
|
|
@@ -281,10 +282,13 @@ export class HostDelivery {
|
|
|
281
282
|
this.#preemptiveAlert = null;
|
|
282
283
|
}
|
|
283
284
|
resumeAfterConversationClear() {
|
|
285
|
+
if (this.#rendererHostDeliveryPaused)
|
|
286
|
+
this.#ports.telemetry?.record('delivery.renderer_resumed', { via: 'conversation_clear' });
|
|
284
287
|
this.#rendererHostDeliveryPaused = false;
|
|
285
288
|
this.#rendererHostDeliveryBoundary = null;
|
|
286
289
|
}
|
|
287
290
|
pauseForConversationClear() {
|
|
291
|
+
this.#ports.telemetry?.record('delivery.renderer_paused', { resume: false, via: 'conversation_clear' });
|
|
288
292
|
this.#rendererHostDeliveryPaused = true;
|
|
289
293
|
this.#rendererHostDeliveryBoundary = {};
|
|
290
294
|
this.#preemptiveAlertToken += 1;
|
|
@@ -396,6 +400,7 @@ export class HostDelivery {
|
|
|
396
400
|
this.#ports.telemetry?.record('hostitem.queued', { event_id: intent.item.event_id });
|
|
397
401
|
this.#hostItemSeq += 1;
|
|
398
402
|
const queued = {
|
|
403
|
+
...(options.authorizeBeforeInject ? { authorizeBeforeInject: options.authorizeBeforeInject } : {}),
|
|
399
404
|
...(options.stillWanted ? { stillWanted: options.stillWanted } : {}),
|
|
400
405
|
...(options.onNotDelivered ? { onNotDelivered: options.onNotDelivered } : {}),
|
|
401
406
|
sortKey: [-effectivePriority, preemptive ? -1 : 0, this.#hostItemSeq],
|
|
@@ -547,6 +552,12 @@ export class HostDelivery {
|
|
|
547
552
|
eligibilityRevoked = true;
|
|
548
553
|
return eligible;
|
|
549
554
|
};
|
|
555
|
+
const authorization = queued.authorizeBeforeInject ? { authorizeBeforeInject: async () => {
|
|
556
|
+
const valid = await this.#authorizeQueued(queued);
|
|
557
|
+
if (!valid)
|
|
558
|
+
eligibilityRevoked = true;
|
|
559
|
+
return valid && responseAllowed();
|
|
560
|
+
} } : {};
|
|
550
561
|
let delivery;
|
|
551
562
|
try {
|
|
552
563
|
if (userActivation) {
|
|
@@ -554,7 +565,7 @@ export class HostDelivery {
|
|
|
554
565
|
// crossing a reconnect has to carry that activation or it lands in a session that never
|
|
555
566
|
// responds.
|
|
556
567
|
delivery = await this.session.deliverHostResponse(queued.intent, {
|
|
557
|
-
responseAllowed,
|
|
568
|
+
responseAllowed, ...authorization,
|
|
558
569
|
asUserActivation: true,
|
|
559
570
|
});
|
|
560
571
|
}
|
|
@@ -568,14 +579,14 @@ export class HostDelivery {
|
|
|
568
579
|
? 0.5
|
|
569
580
|
: null;
|
|
570
581
|
delivery = confirmationTimeout === null
|
|
571
|
-
? await this.session.deliverPreemptiveHostResponse(queued.intent, { responseAllowed })
|
|
582
|
+
? await this.session.deliverPreemptiveHostResponse(queued.intent, { responseAllowed, ...authorization })
|
|
572
583
|
: await this.session.deliverPreemptiveHostResponse(queued.intent, {
|
|
573
584
|
confirmationTimeout,
|
|
574
|
-
responseAllowed,
|
|
585
|
+
responseAllowed, ...authorization,
|
|
575
586
|
});
|
|
576
587
|
}
|
|
577
588
|
else {
|
|
578
|
-
delivery = await this.session.deliverHostResponse(queued.intent, { responseAllowed });
|
|
589
|
+
delivery = await this.session.deliverHostResponse(queued.intent, { responseAllowed, ...authorization });
|
|
579
590
|
}
|
|
580
591
|
}
|
|
581
592
|
catch (cause) {
|
|
@@ -589,6 +600,12 @@ export class HostDelivery {
|
|
|
589
600
|
throw cause;
|
|
590
601
|
}
|
|
591
602
|
const delivered = delivery.accepted;
|
|
603
|
+
if (!delivered && !eligibilityRevoked && queued.authorizeBeforeInject && !this.#ports.stopped()) {
|
|
604
|
+
this.requeueHostItem(queued);
|
|
605
|
+
break;
|
|
606
|
+
}
|
|
607
|
+
if (!delivered && eligibilityRevoked && delivery.injectionEpoch === null)
|
|
608
|
+
await this.#notDelivered(queued);
|
|
592
609
|
if (!delivered
|
|
593
610
|
&& eligibilityRevoked
|
|
594
611
|
&& delivery.injectionEpoch === this.session.sessionEpoch) {
|
|
@@ -630,6 +647,17 @@ export class HostDelivery {
|
|
|
630
647
|
}
|
|
631
648
|
}
|
|
632
649
|
}
|
|
650
|
+
async #authorizeQueued(queued) {
|
|
651
|
+
if (!queued.authorizeBeforeInject)
|
|
652
|
+
return true;
|
|
653
|
+
const signal = AbortSignal.any([this.#ports.stopSignal(), AbortSignal.timeout(5000)]);
|
|
654
|
+
try {
|
|
655
|
+
return await abortable(queued.authorizeBeforeInject(signal), signal) && !signal.aborted && !this.#ports.stopped();
|
|
656
|
+
}
|
|
657
|
+
catch {
|
|
658
|
+
return false;
|
|
659
|
+
}
|
|
660
|
+
}
|
|
633
661
|
/** Revalidate lifecycle eligibility at the final provider boundary. */
|
|
634
662
|
#queuedHostItemEligible(queued) {
|
|
635
663
|
if (queued.stillWanted && !queued.stillWanted())
|
|
@@ -1081,6 +1109,7 @@ export class HostDelivery {
|
|
|
1081
1109
|
const boundary = {};
|
|
1082
1110
|
this.#rendererHostDeliveryBoundary = boundary;
|
|
1083
1111
|
this.#rendererHostDeliveryPaused = true;
|
|
1112
|
+
this.#ports.telemetry?.record('delivery.renderer_paused', { resume: options.resumeDelivery === true });
|
|
1084
1113
|
try {
|
|
1085
1114
|
const releasedUserHold = this.session.releaseRendererUserHold();
|
|
1086
1115
|
const generation = this.session.currentGeneration;
|
|
@@ -1097,6 +1126,7 @@ export class HostDelivery {
|
|
|
1097
1126
|
if (options.resumeDelivery === true
|
|
1098
1127
|
&& this.#rendererHostDeliveryBoundary === boundary) {
|
|
1099
1128
|
this.#rendererHostDeliveryPaused = false;
|
|
1129
|
+
this.#ports.telemetry?.record('delivery.renderer_resumed', { via: 'playback_boundary' });
|
|
1100
1130
|
this.#ports.wake();
|
|
1101
1131
|
}
|
|
1102
1132
|
}
|
|
@@ -1272,6 +1302,8 @@ export class HostDelivery {
|
|
|
1272
1302
|
try {
|
|
1273
1303
|
delivery = await this.session.deliverPreemptiveHostResponse(queued.intent, {
|
|
1274
1304
|
confirmationTimeout: 0.5,
|
|
1305
|
+
...(queued.authorizeBeforeInject ? { authorizeBeforeInject: async () => { const valid = await this.#authorizeQueued(queued); if (!valid)
|
|
1306
|
+
lifecycleRevoked = true; return valid && this.#queuedHostItemEligible(queued); } } : {}),
|
|
1275
1307
|
responseAllowed: () => {
|
|
1276
1308
|
const eligible = this.#queuedHostItemEligible(queued);
|
|
1277
1309
|
if (!eligible)
|
|
@@ -1290,6 +1322,7 @@ export class HostDelivery {
|
|
|
1290
1322
|
if (delivery.injectionEpoch === this.session.sessionEpoch) {
|
|
1291
1323
|
await this.retireProviderHostEventNow(queued.intent.item.event_id);
|
|
1292
1324
|
}
|
|
1325
|
+
await this.#notDelivered(queued);
|
|
1293
1326
|
}
|
|
1294
1327
|
else {
|
|
1295
1328
|
this.requeueHostItem(queued);
|
|
@@ -35,6 +35,7 @@ export const hostContextItemSchema = z.object({
|
|
|
35
35
|
event_id: realtimeIdentifierSchema,
|
|
36
36
|
content: z.string().refine(value => !pythonWhitespaceOnly.test(value), 'text must be non-empty'),
|
|
37
37
|
context_read: z.literal(true).optional(),
|
|
38
|
+
source_processing_read: z.literal(true).optional(),
|
|
38
39
|
/** Host-authored public wording; private context is never used as the narration payload. */
|
|
39
40
|
speech_content: boundedText().optional(),
|
|
40
41
|
/** Explicit host classification: control receipts are not recoverable results. */
|
|
@@ -45,9 +46,11 @@ export const hostContextItemSchema = z.object({
|
|
|
45
46
|
workspace_instance_id: realtimeIdentifierSchema.optional(),
|
|
46
47
|
revision: z.number().int().nonnegative().optional(),
|
|
47
48
|
}).strict().superRefine((item, context) => {
|
|
49
|
+
if (item.source_processing_read && (!item.context_read || item.kind !== 'tool_output'))
|
|
50
|
+
context.addIssue({ code: 'custom', path: ['source_processing_read'], message: 'source processing reads require structured tool output' });
|
|
48
51
|
if (item.context_read && item.kind !== 'tool_output')
|
|
49
52
|
context.addIssue({ code: 'custom', path: ['context_read'], message: 'structured reads require tool output' });
|
|
50
|
-
if (item.context_read ? Buffer.byteLength(item.content) > 32768 : [...item.content].length > (item.kind === 'scheduled_task' ? 160000 : MAX_REALTIME_TEXT))
|
|
53
|
+
if (item.context_read ? Buffer.byteLength(item.content) > (item.source_processing_read ? 131072 : 32768) : [...item.content].length > (item.kind === 'scheduled_task' ? 160000 : MAX_REALTIME_TEXT))
|
|
51
54
|
context.addIssue({ code: 'custom', path: ['content'], message: 'host context exceeds text limit' });
|
|
52
55
|
if (item.speech_content !== undefined && item.kind !== 'progress' && item.kind !== 'final') {
|
|
53
56
|
context.addIssue({ code: 'custom', path: ['speech_content'], message: 'public narration requires a progress or final fact' });
|
|
@@ -323,8 +326,9 @@ export const responseAudioDeltaSchema = sessionEvent(z.literal('response_audio_d
|
|
|
323
326
|
pcm: z.instanceof(Uint8Array)
|
|
324
327
|
.refine(value => value.byteLength > 0 && value.byteLength % 2 === 0, 'pcm must be non-empty aligned PCM16 bytes'),
|
|
325
328
|
});
|
|
326
|
-
export const responseTranscriptDeltaSchema = sessionEvent(z.literal('response_transcript_delta'), responseTextShape);
|
|
327
|
-
export const
|
|
329
|
+
export const responseTranscriptDeltaSchema = sessionEvent(z.literal('response_transcript_delta'), { ...responseTextShape, full_text: boundedText().optional() });
|
|
330
|
+
export const MAX_REALTIME_FINAL_TRANSCRIPT_BYTES = 65536;
|
|
331
|
+
export const responseTranscriptFinalSchema = sessionEvent(z.literal('response_transcript_final'), { response_id: realtimeIdentifierSchema, text: z.string().refine(value => Buffer.byteLength(value, 'utf8') <= MAX_REALTIME_FINAL_TRANSCRIPT_BYTES, 'final transcript exceeds 64 KiB') });
|
|
328
332
|
export const toolCallReadySchema = sessionEvent(z.literal('tool_call_ready'), {
|
|
329
333
|
call_id: realtimeIdentifierSchema,
|
|
330
334
|
item_id: realtimeIdentifierSchema,
|
|
@@ -359,6 +363,16 @@ export const providerErrorEventSchema = sessionEvent(z.literal('provider_error')
|
|
|
359
363
|
code: realtimeIdentifierSchema,
|
|
360
364
|
recoverable: z.boolean().default(false),
|
|
361
365
|
});
|
|
366
|
+
/**
|
|
367
|
+
* Service lifecycle, not a provider utterance: the transport finished replacing
|
|
368
|
+
* the provider session and the new epoch is live.
|
|
369
|
+
*
|
|
370
|
+
* Lifecycle owners (the personal-agent conversation runtime) need this to tell
|
|
371
|
+
* the user their voice session recovered without waiting for them to speak into
|
|
372
|
+
* the new session first. Providers never emit it themselves; only
|
|
373
|
+
* `RealtimeService` publishes it through `onProviderEvent`.
|
|
374
|
+
*/
|
|
375
|
+
export const providerReconnectedEventSchema = sessionEvent(z.literal('provider_reconnected'), {});
|
|
362
376
|
export const realtimeProviderEventSchema = z.discriminatedUnion('kind', [
|
|
363
377
|
userSpeechStartedSchema,
|
|
364
378
|
userSpeechEndedSchema,
|
|
@@ -375,6 +389,7 @@ export const realtimeProviderEventSchema = z.discriminatedUnion('kind', [
|
|
|
375
389
|
responseYieldedSchema,
|
|
376
390
|
responseCancelRejectedSchema,
|
|
377
391
|
providerErrorEventSchema,
|
|
392
|
+
providerReconnectedEventSchema,
|
|
378
393
|
]);
|
|
379
394
|
export const responseAdaptationContextSchema = z.object({
|
|
380
395
|
revision: z.number().int().min(0).max(Number.MAX_SAFE_INTEGER),
|
|
@@ -177,7 +177,9 @@ export class ProviderProjection {
|
|
|
177
177
|
this.#startedDelegates.delete(delegateId);
|
|
178
178
|
this.publishExecutorState();
|
|
179
179
|
}
|
|
180
|
-
onSuggestionSelected(suggestion, reason) {
|
|
180
|
+
onSuggestionSelected(suggestion, reason, authorization = {}) {
|
|
181
|
+
if (typeof suggestion.content.personal_feed_id === 'string' && !authorization.authorizeBeforeInject)
|
|
182
|
+
return;
|
|
181
183
|
const progress = this.#isSelectedProgress(suggestion);
|
|
182
184
|
const coding = progress && suggestion.evidence_refs[0]?.startsWith(`${this.ports.coding?.channel}:`) === true;
|
|
183
185
|
if (coding && this.ports.codingProgressNarration.mode !== 'smart')
|
|
@@ -197,6 +199,7 @@ export class ProviderProjection {
|
|
|
197
199
|
...(reason.origin === null ? {} : { source: this.#workSource(reason.origin) }),
|
|
198
200
|
content: suggestionSpeechView(suggestion.content),
|
|
199
201
|
}), {
|
|
202
|
+
...authorization,
|
|
200
203
|
priority: hit ? Math.max(reason.priority, HIT_ALERT_MIN_PRIORITY) : reason.priority,
|
|
201
204
|
preemptive: false,
|
|
202
205
|
...(coding ? { owner: { delegate_id: reason.origin, channel: delegate.executor }, expiresAt: this.ports.clock.now() + PROGRESS_HOST_ITEM_TTL_S } : {}),
|
|
@@ -4,6 +4,7 @@ import { MAX_REALTIME_PCM_BYTES, hostContextItemSchema, hostResponseIntentSchema
|
|
|
4
4
|
const jsonObjectSchema = jsonValueSchema.refine(value => value !== null && !Array.isArray(value) && typeof value === 'object', 'tool schema must be a JSON object');
|
|
5
5
|
class InternalProtocolError extends RealtimeProtocolError {
|
|
6
6
|
}
|
|
7
|
+
const WITHDRAWN_SIGNATURE = JSON.stringify({ content: null });
|
|
7
8
|
export class RealtimeProviderSession {
|
|
8
9
|
async setLanguage(language) { await this.#provider.setLanguage?.(language); }
|
|
9
10
|
#provider;
|
|
@@ -19,6 +20,8 @@ export class RealtimeProviderSession {
|
|
|
19
20
|
#onDiagnostic;
|
|
20
21
|
#responseAdaptationTail = Promise.resolve();
|
|
21
22
|
#audioAdaptationRefresh;
|
|
23
|
+
#audioFenceVerified;
|
|
24
|
+
#audioFenceRead;
|
|
22
25
|
#responseAdaptationReadFailureDiagnosedEpoch = null;
|
|
23
26
|
#responseAdaptationAttempt = null;
|
|
24
27
|
#connectedObservers = new Set();
|
|
@@ -29,6 +32,7 @@ export class RealtimeProviderSession {
|
|
|
29
32
|
this.#onResponseAdaptationApplied = options.onResponseAdaptationApplied;
|
|
30
33
|
this.#onDiagnostic = options.onDiagnostic;
|
|
31
34
|
}
|
|
35
|
+
get capabilities() { return this.#provider.capabilities; }
|
|
32
36
|
get userResponseMode() {
|
|
33
37
|
return this.#provider.userResponseMode ?? 'automatic';
|
|
34
38
|
}
|
|
@@ -57,7 +61,7 @@ export class RealtimeProviderSession {
|
|
|
57
61
|
this.#state = 'connecting';
|
|
58
62
|
try {
|
|
59
63
|
const identity = sessionIdentitySchema.parse(await this.#provider.connect({
|
|
60
|
-
tools: structuredClone(parsedTools),
|
|
64
|
+
tools: this.capabilities?.model.functionCalling === false ? [] : structuredClone(parsedTools),
|
|
61
65
|
signal: combinedSignal(connectionAbort.signal, signal),
|
|
62
66
|
}));
|
|
63
67
|
if (identity.epoch <= this.#lastEpoch) {
|
|
@@ -70,6 +74,8 @@ export class RealtimeProviderSession {
|
|
|
70
74
|
this.#identity = Object.freeze({ ...identity });
|
|
71
75
|
this.#responseAdaptationTail = Promise.resolve();
|
|
72
76
|
this.#audioAdaptationRefresh = undefined;
|
|
77
|
+
this.#audioFenceVerified = undefined;
|
|
78
|
+
this.#audioFenceRead = undefined;
|
|
73
79
|
this.#responseAdaptationReadFailureDiagnosedEpoch = null;
|
|
74
80
|
this.#responseAdaptationAttempt = null;
|
|
75
81
|
this.#state = 'connected';
|
|
@@ -96,6 +102,9 @@ export class RealtimeProviderSession {
|
|
|
96
102
|
this.#state = 'disconnected';
|
|
97
103
|
}
|
|
98
104
|
this.#identity = null;
|
|
105
|
+
// A sanitized connect code (see RealtimeConnectError) is what the user can act on; keep it.
|
|
106
|
+
if (error instanceof Error && /^realtime_[a-z_]{1,64}$/u.test(error.message))
|
|
107
|
+
throw new RealtimeProtocolError(error.message);
|
|
99
108
|
throw protocolFailure('provider connect failed', error);
|
|
100
109
|
}
|
|
101
110
|
}
|
|
@@ -122,6 +131,8 @@ export class RealtimeProviderSession {
|
|
|
122
131
|
return this.connect({ tools }, signal);
|
|
123
132
|
}
|
|
124
133
|
async submitText(text, signal) {
|
|
134
|
+
if (this.capabilities?.model.textInput === false)
|
|
135
|
+
throw new RealtimeProtocolError('text input unavailable');
|
|
125
136
|
if (typeof text !== 'string' || !text.trim() || text.length > 4000 || !this.#provider.submitText)
|
|
126
137
|
throw new RealtimeProtocolError('text input unavailable');
|
|
127
138
|
const owner = this.#requiredConnectionOwner();
|
|
@@ -147,22 +158,16 @@ export class RealtimeProviderSession {
|
|
|
147
158
|
if (pcm.byteLength > MAX_REALTIME_PCM_BYTES) {
|
|
148
159
|
throw new RealtimeProtocolError('input PCM frame is too large');
|
|
149
160
|
}
|
|
161
|
+
if (this.capabilities?.model.audioInput === false)
|
|
162
|
+
throw new RealtimeProtocolError('audio input unavailable');
|
|
150
163
|
const owned = pcm.slice();
|
|
151
164
|
const owner = this.#requiredConnectionOwner();
|
|
152
165
|
try {
|
|
153
166
|
// Requested-response providers only transcribe PCM here. Their model sees memory at
|
|
154
167
|
// createResponse/ensureResponse, which revalidate authorization before generating.
|
|
155
168
|
// Automatic providers can generate directly from PCM and still need the input fence.
|
|
156
|
-
if (this.userResponseMode === 'automatic'
|
|
157
|
-
await this.#
|
|
158
|
-
}
|
|
159
|
-
else if (this.userResponseMode === 'automatic' && this.#audioAdaptationRefresh === undefined) {
|
|
160
|
-
const refresh = this.#refreshResponseAdaptation(owner, signal).catch(() => undefined).finally(() => {
|
|
161
|
-
if (this.#audioAdaptationRefresh === refresh)
|
|
162
|
-
this.#audioAdaptationRefresh = undefined;
|
|
163
|
-
});
|
|
164
|
-
this.#audioAdaptationRefresh = refresh;
|
|
165
|
-
}
|
|
169
|
+
if (this.userResponseMode === 'automatic')
|
|
170
|
+
await this.#audioAdaptationFence(owner, signal);
|
|
166
171
|
this.#assertCurrentConnection(owner);
|
|
167
172
|
signal?.throwIfAborted();
|
|
168
173
|
await this.#provider.sendAudio(owned, combinedSignal(owner.controller.signal, signal));
|
|
@@ -172,7 +177,28 @@ export class RealtimeProviderSession {
|
|
|
172
177
|
throw protocolFailure('provider audio send failed', error);
|
|
173
178
|
}
|
|
174
179
|
}
|
|
180
|
+
/**
|
|
181
|
+
* The memory context is read once per provider session and reused for every later audio frame.
|
|
182
|
+
* Frames wait only until that first read has succeeded (a read that cannot be verified still fails closed for a required fence);
|
|
183
|
+
* after that a frame never waits for memory, so the serial audio path cannot be stalled by a slow read.
|
|
184
|
+
*/
|
|
185
|
+
async #audioAdaptationFence(owner, signal) {
|
|
186
|
+
const epoch = owner.identity.epoch;
|
|
187
|
+
if (this.#audioFenceVerified?.epoch === epoch)
|
|
188
|
+
return;
|
|
189
|
+
if (this.#audioAdaptationRefresh === undefined) {
|
|
190
|
+
const read = this.#refreshResponseAdaptation(owner, signal).then(() => { this.#audioFenceVerified = { epoch, at: Date.now() }; });
|
|
191
|
+
const tracked = read.catch(() => undefined).finally(() => { if (this.#audioAdaptationRefresh === tracked)
|
|
192
|
+
this.#audioAdaptationRefresh = undefined; });
|
|
193
|
+
this.#audioAdaptationRefresh = tracked;
|
|
194
|
+
this.#audioFenceRead = read;
|
|
195
|
+
}
|
|
196
|
+
if (this.#responseAdaptationRequired?.() === true)
|
|
197
|
+
await this.#audioFenceRead;
|
|
198
|
+
}
|
|
175
199
|
async injectHostItem(input, options = {}) {
|
|
200
|
+
if (this.capabilities?.protocol.conversationItems === false)
|
|
201
|
+
throw new RealtimeProtocolError('conversation items unavailable');
|
|
176
202
|
const item = hostContextItemSchema.parse(input);
|
|
177
203
|
if (item.kind === 'workspace_context') {
|
|
178
204
|
throw new RealtimeProtocolError('workspace context delivery is unavailable until provider capability is proven');
|
|
@@ -245,6 +271,8 @@ export class RealtimeProviderSession {
|
|
|
245
271
|
}
|
|
246
272
|
}
|
|
247
273
|
async createResponse(intent, signal) {
|
|
274
|
+
if (this.capabilities?.protocol.clientResponses === false)
|
|
275
|
+
throw new RealtimeProtocolError('client responses unavailable');
|
|
248
276
|
const parsed = hostResponseIntentSchema.parse(intent);
|
|
249
277
|
const owner = this.#requiredConnectionOwner();
|
|
250
278
|
try {
|
|
@@ -258,7 +286,7 @@ export class RealtimeProviderSession {
|
|
|
258
286
|
}
|
|
259
287
|
}
|
|
260
288
|
async ensureResponse(userItemId, signal, requestId) {
|
|
261
|
-
if (this.#provider.ensureResponse === undefined) {
|
|
289
|
+
if (this.capabilities?.protocol.clientResponses === false || this.#provider.ensureResponse === undefined) {
|
|
262
290
|
throw new RealtimeProtocolError('provider response ensuring is unavailable');
|
|
263
291
|
}
|
|
264
292
|
const owner = this.#requiredConnectionOwner();
|
|
@@ -290,6 +318,8 @@ export class RealtimeProviderSession {
|
|
|
290
318
|
}
|
|
291
319
|
}
|
|
292
320
|
async cancelResponse(responseId, signal) {
|
|
321
|
+
if (this.capabilities?.protocol.cancelResponse === false)
|
|
322
|
+
throw new RealtimeProtocolError('response cancellation unavailable');
|
|
293
323
|
const parsed = realtimeIdentifierSchema.parse(responseId);
|
|
294
324
|
const owner = this.#requiredConnectionOwner();
|
|
295
325
|
try {
|
|
@@ -320,6 +350,8 @@ export class RealtimeProviderSession {
|
|
|
320
350
|
}
|
|
321
351
|
if (event.session_epoch !== owner.identity.epoch)
|
|
322
352
|
continue;
|
|
353
|
+
if (this.capabilities?.model.functionCalling === false && (event.kind === 'tool_call_ready' || event.kind === 'response_yielded'))
|
|
354
|
+
throw new InternalProtocolError('tool event from a conversation-only provider');
|
|
323
355
|
yield cloneProviderEvent(event);
|
|
324
356
|
}
|
|
325
357
|
}
|
|
@@ -386,6 +418,28 @@ export class RealtimeProviderSession {
|
|
|
386
418
|
await this.close();
|
|
387
419
|
throw new InternalProtocolError('memory authorization refresh failed; session closed');
|
|
388
420
|
} };
|
|
421
|
+
// A read that cannot be verified must not leave memory with the model, but the conversation may
|
|
422
|
+
// continue without it. A fresh connection holds none; anything else on this connection, including
|
|
423
|
+
// an attempt whose delivery was never confirmed, is replaced with an empty context at the same
|
|
424
|
+
// revision. Only a confirmed withdrawal is skipped; one that cannot be confirmed closes the session.
|
|
425
|
+
const withdrawUnverified = async () => {
|
|
426
|
+
if (!required || !this.#isCurrentConnection(owner))
|
|
427
|
+
return;
|
|
428
|
+
const previous = this.#responseAdaptationAttempt;
|
|
429
|
+
if (previous?.epoch !== owner.identity.epoch || (previous.confirmed && previous.signature === WITHDRAWN_SIGNATURE))
|
|
430
|
+
return;
|
|
431
|
+
try {
|
|
432
|
+
await this.#provider.replaceResponseAdaptation({ revision: previous.revision, content: null }, combinedSignal(owner.controller.signal, signal));
|
|
433
|
+
this.#assertCurrentConnection(owner);
|
|
434
|
+
this.#responseAdaptationAttempt = { epoch: owner.identity.epoch, revision: previous.revision, signature: WITHDRAWN_SIGNATURE, confirmed: true };
|
|
435
|
+
}
|
|
436
|
+
catch {
|
|
437
|
+
if (!this.#isCurrentConnection(owner))
|
|
438
|
+
return;
|
|
439
|
+
await this.close();
|
|
440
|
+
throw new InternalProtocolError('memory authorization withdrawal failed; session closed');
|
|
441
|
+
}
|
|
442
|
+
};
|
|
389
443
|
let raw;
|
|
390
444
|
const readSignal = AbortSignal.any([owner.controller.signal, ...(signal ? [signal] : []), AbortSignal.timeout(10000)]);
|
|
391
445
|
let aborted;
|
|
@@ -403,7 +457,7 @@ export class RealtimeProviderSession {
|
|
|
403
457
|
this.#responseAdaptationReadFailureDiagnosedEpoch = owner.identity.epoch;
|
|
404
458
|
this.#reportAdaptationDiagnostic('read_failed', owner.identity.epoch, null);
|
|
405
459
|
}
|
|
406
|
-
await
|
|
460
|
+
await withdrawUnverified();
|
|
407
461
|
return;
|
|
408
462
|
}
|
|
409
463
|
finally {
|
|
@@ -414,13 +468,13 @@ export class RealtimeProviderSession {
|
|
|
414
468
|
return;
|
|
415
469
|
signal?.throwIfAborted();
|
|
416
470
|
if (raw === undefined) {
|
|
417
|
-
await
|
|
471
|
+
await withdrawUnverified();
|
|
418
472
|
return;
|
|
419
473
|
}
|
|
420
474
|
const parsed = responseAdaptationContextSchema.safeParse(raw);
|
|
421
475
|
if (!parsed.success) {
|
|
422
476
|
this.#reportAdaptationDiagnostic('invalid', owner.identity.epoch, null);
|
|
423
|
-
await
|
|
477
|
+
await withdrawUnverified();
|
|
424
478
|
return;
|
|
425
479
|
}
|
|
426
480
|
const context = includeUserSources && this.#provider.responseAdaptationMode !== 'session_setup' ? parsed.data : { revision: parsed.data.revision, content: parsed.data.content,
|
|
@@ -436,7 +490,10 @@ export class RealtimeProviderSession {
|
|
|
436
490
|
this.#onResponseAdaptationApplied?.(context, owner.identity.epoch);
|
|
437
491
|
return;
|
|
438
492
|
}
|
|
439
|
-
|
|
493
|
+
// Advisory guidance does not retry a failed attempt on every frame. Required memory never takes an
|
|
494
|
+
// unconfirmed attempt (one cancelled mid-delivery) as delivered: it is sent again, and a failure
|
|
495
|
+
// then closes the session, before any input can reach the provider.
|
|
496
|
+
if (!required && previous !== null && previous.epoch === owner.identity.epoch
|
|
440
497
|
&& previous.revision === context.revision && previous.signature === signature)
|
|
441
498
|
return;
|
|
442
499
|
this.#responseAdaptationAttempt = {
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* nothing in the adapter's own tests can accidentally reach the network.
|
|
6
6
|
*/
|
|
7
7
|
import { WebSocket } from 'ws';
|
|
8
|
-
import { RealtimeSocketClosedError, } from './transport.js';
|
|
8
|
+
import { RealtimeConnectError, RealtimeSocketClosedError, } from './transport.js';
|
|
9
9
|
/** Bounds the inbound backlog so a firehose cannot grow memory without limit. */
|
|
10
10
|
export const MAX_QWEN_INBOUND_BACKLOG = 1_024;
|
|
11
11
|
class WebSocketRealtimeSocket {
|
|
@@ -123,9 +123,8 @@ export const webSocketRealtimeConnector = (options) => new Promise((resolve, rej
|
|
|
123
123
|
const onError = (error) => settle(() => {
|
|
124
124
|
socket.terminate();
|
|
125
125
|
// Never surface the provider's message: the endpoint carries the model and the
|
|
126
|
-
// request carries the credential.
|
|
127
|
-
|
|
128
|
-
reject(new Error('qwen realtime websocket failed to open'));
|
|
126
|
+
// request carries the credential. Only the HTTP status or socket error class survives.
|
|
127
|
+
reject(connectFailure(error));
|
|
129
128
|
});
|
|
130
129
|
const onAbort = () => settle(() => {
|
|
131
130
|
socket.terminate();
|
|
@@ -139,6 +138,38 @@ export const webSocketRealtimeConnector = (options) => new Promise((resolve, rej
|
|
|
139
138
|
if (options.signal.aborted)
|
|
140
139
|
onAbort();
|
|
141
140
|
});
|
|
141
|
+
const TLS_FAILURE = /^(?:CERT_|UNABLE_TO_|DEPTH_ZERO_|SELF_SIGNED_|ERR_TLS_|ERR_SSL_|EPROTO$)/u;
|
|
142
|
+
const UNREACHABLE = new Set([
|
|
143
|
+
'ECONNREFUSED', 'ECONNRESET', 'ENOTFOUND', 'EAI_AGAIN', 'EHOSTUNREACH', 'ENETUNREACH', 'EPIPE',
|
|
144
|
+
]);
|
|
145
|
+
/** Reduces a `ws` open failure to a sanitized code; `ws` reports a non-101 reply only in its message. */
|
|
146
|
+
export function connectFailure(error) {
|
|
147
|
+
const message = error instanceof Error ? error.message : '';
|
|
148
|
+
const status = /^Unexpected server response: (\d{3})$/u.exec(message)?.[1];
|
|
149
|
+
if (status !== undefined) {
|
|
150
|
+
const code = Number(status);
|
|
151
|
+
if (code === 401)
|
|
152
|
+
return new RealtimeConnectError('realtime_auth_rejected', code);
|
|
153
|
+
// 403 means the key was read but this account may not use the model, which needs a different fix than a wrong key.
|
|
154
|
+
if (code === 403)
|
|
155
|
+
return new RealtimeConnectError('realtime_forbidden', code);
|
|
156
|
+
if (code === 404)
|
|
157
|
+
return new RealtimeConnectError('realtime_endpoint_not_found', code);
|
|
158
|
+
if (code === 429)
|
|
159
|
+
return new RealtimeConnectError('realtime_rate_limited', code);
|
|
160
|
+
return new RealtimeConnectError('realtime_handshake_rejected', code);
|
|
161
|
+
}
|
|
162
|
+
const systemCode = error instanceof Error && 'code' in error ? String(error.code) : '';
|
|
163
|
+
if (systemCode === 'ETIMEDOUT' || /handshake has timed out/iu.test(message)) {
|
|
164
|
+
return new RealtimeConnectError('realtime_timeout');
|
|
165
|
+
}
|
|
166
|
+
if (UNREACHABLE.has(systemCode))
|
|
167
|
+
return new RealtimeConnectError('realtime_unreachable');
|
|
168
|
+
if (TLS_FAILURE.test(systemCode) || /certificate|self[- ]signed/iu.test(message))
|
|
169
|
+
return new RealtimeConnectError('realtime_tls_failed');
|
|
170
|
+
// Keep only the system error code (never provider text) so an unclassified failure still names its cause.
|
|
171
|
+
return new RealtimeConnectError('realtime_connect_failed', undefined, /^[A-Z][A-Z0-9_]{2,40}$/u.test(systemCode) ? systemCode : undefined);
|
|
172
|
+
}
|
|
142
173
|
/** Compatibility name retained for existing clients. */
|
|
143
174
|
export const webSocketQwenConnector = webSocketRealtimeConnector;
|
|
144
175
|
//# sourceMappingURL=qwen-transport.js.map
|