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 { TASK_CONTINUATION_INSTRUCTIONS, SCHEDULED_TASK_INSTRUCTIONS } from './cascaded/llm.js';
|
|
2
3
|
import { abortable } from '../core/camera-session.js';
|
|
3
4
|
import { committedConversationPairsSchema, MAX_PACKED_RECOVERY_CONTENT } from './history.js';
|
|
@@ -65,11 +66,13 @@ export class QwenRealtimeError extends Error {
|
|
|
65
66
|
this.name = 'QwenRealtimeError';
|
|
66
67
|
}
|
|
67
68
|
}
|
|
68
|
-
import { RealtimeSocketClosedError as QwenSocketClosedError } from './transport.js';
|
|
69
|
+
import { RealtimeConnectError, RealtimeSocketClosedError as QwenSocketClosedError } from './transport.js';
|
|
70
|
+
import { rotatedCredential } from '../config/credential-rotation.js';
|
|
69
71
|
// Compatibility exports for existing Qwen consumers. Native providers depend on transport.ts directly.
|
|
70
72
|
export { RealtimeSocketClosedError as QwenSocketClosedError } from './transport.js';
|
|
71
73
|
const providerEventEnvelope = z.record(z.string(), jsonValueSchema);
|
|
72
74
|
export class QwenAudioRealtimeAdapter {
|
|
75
|
+
get capabilities() { return realtimeCapabilities[this.#wireProfile.provider]; }
|
|
73
76
|
/** Qwen receives the bounded host text projection, never original camera bytes. */
|
|
74
77
|
mediaCapability = Object.freeze({ originalImageInput: false });
|
|
75
78
|
#onUsage;
|
|
@@ -91,6 +94,7 @@ export class QwenAudioRealtimeAdapter {
|
|
|
91
94
|
#language;
|
|
92
95
|
#instructions;
|
|
93
96
|
#wireProfile;
|
|
97
|
+
#telemetry;
|
|
94
98
|
#speechIds = new Map();
|
|
95
99
|
#narrations = new Map();
|
|
96
100
|
#pendingItems = new Map();
|
|
@@ -100,6 +104,13 @@ export class QwenAudioRealtimeAdapter {
|
|
|
100
104
|
#queueWaiter;
|
|
101
105
|
#socket;
|
|
102
106
|
#readySocket;
|
|
107
|
+
/** Bounded per-session counters that answer "did sound go out and what came back" without recording any content. */
|
|
108
|
+
#audioFramesSent = 0;
|
|
109
|
+
#audioBytesSent = 0;
|
|
110
|
+
#audioReports = 0;
|
|
111
|
+
#audioPeak = 0;
|
|
112
|
+
#audioReportedAt = 0;
|
|
113
|
+
#serverEvents = new Map();
|
|
103
114
|
#historyRestoring = false;
|
|
104
115
|
#historyRestored = false;
|
|
105
116
|
#conversationUsed = false;
|
|
@@ -120,6 +131,7 @@ export class QwenAudioRealtimeAdapter {
|
|
|
120
131
|
this.#initialHistory = options.history === undefined ? undefined : committedConversationPairsSchema.parse(options.history);
|
|
121
132
|
this.#onUsage = options.onUsage;
|
|
122
133
|
this.#wireProfile = options.wireProfile ?? qwenWireProfile;
|
|
134
|
+
this.#telemetry = options.telemetry;
|
|
123
135
|
this.#url = options.url;
|
|
124
136
|
this.#apiKey = options.apiKey;
|
|
125
137
|
this.#model = options.model;
|
|
@@ -150,34 +162,51 @@ export class QwenAudioRealtimeAdapter {
|
|
|
150
162
|
let initialInstructions = this.#instructions();
|
|
151
163
|
let providerSessionId;
|
|
152
164
|
let socket;
|
|
165
|
+
let stage = 'socket_open';
|
|
153
166
|
try {
|
|
154
167
|
socket = await this.#connector({
|
|
155
168
|
endpoint,
|
|
156
|
-
headers: { Authorization: `Bearer ${this.#apiKey}` },
|
|
169
|
+
headers: { Authorization: `Bearer ${rotatedCredential(this.#apiKey)}` },
|
|
157
170
|
openTimeout: this.#remaining(deadline),
|
|
158
171
|
signal: options.signal,
|
|
159
172
|
});
|
|
160
173
|
this.#socket = socket;
|
|
174
|
+
stage = 'session_created';
|
|
161
175
|
const created = await this.#untilDeadline(this.#receiveJson(socket), deadline);
|
|
176
|
+
if (created.type === 'error')
|
|
177
|
+
throw new ProviderSetupRejected(created);
|
|
162
178
|
providerSessionId = sessionId(created, 'session.created');
|
|
179
|
+
stage = 'instructions';
|
|
163
180
|
initialInstructions = this.#instructions();
|
|
181
|
+
stage = 'session_update';
|
|
164
182
|
await this.#untilDeadline(this.#sendJson({
|
|
165
183
|
type: 'session.update',
|
|
166
184
|
session: this.#wireProfile.session(options.tools, this.#voice, initialInstructions, this.#model),
|
|
167
185
|
}), deadline);
|
|
186
|
+
stage = 'session_updated';
|
|
168
187
|
const updated = await this.#untilDeadline(this.#receiveJson(socket), deadline);
|
|
188
|
+
if (updated.type === 'error')
|
|
189
|
+
throw new ProviderSetupRejected(updated);
|
|
190
|
+
this.#recordAcceptedSession(updated);
|
|
169
191
|
if (sessionId(updated, 'session.updated') !== providerSessionId) {
|
|
170
192
|
throw new QwenRealtimeError('qwen realtime session identity changed during setup');
|
|
171
193
|
}
|
|
172
194
|
}
|
|
173
195
|
catch (error) {
|
|
174
196
|
await this.#cleanupDetached();
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
197
|
+
const failure = options.signal.aborted
|
|
198
|
+
? { code: 'realtime_connect_aborted', error: new QwenRealtimeError('realtime_connect_aborted') }
|
|
199
|
+
: connectFailureCode(error, stage);
|
|
200
|
+
this.#recordConnect({
|
|
201
|
+
outcome: 'failed',
|
|
202
|
+
code: failure.code,
|
|
203
|
+
...('detail' in failure && failure.detail !== undefined ? { detail: failure.detail } : {}),
|
|
204
|
+
...(error instanceof RealtimeConnectError && error.status !== undefined ? { http_status: error.status } : {}),
|
|
205
|
+
...(error instanceof ProviderSetupRejected && error.providerCode !== undefined ? { provider_code: error.providerCode } : {}),
|
|
206
|
+
});
|
|
207
|
+
throw failure.error;
|
|
180
208
|
}
|
|
209
|
+
this.#recordConnect({ outcome: 'connected' });
|
|
181
210
|
this.#historyRestoring = false;
|
|
182
211
|
this.#historyRestored = false;
|
|
183
212
|
this.#conversationUsed = false;
|
|
@@ -190,6 +219,12 @@ export class QwenAudioRealtimeAdapter {
|
|
|
190
219
|
this.#responseAdaptationUncertain = false;
|
|
191
220
|
this.#responseAdaptationTail = Promise.resolve();
|
|
192
221
|
this.#readySocket = socket;
|
|
222
|
+
this.#audioFramesSent = 0;
|
|
223
|
+
this.#audioBytesSent = 0;
|
|
224
|
+
this.#audioPeak = 0;
|
|
225
|
+
this.#audioReports = 0;
|
|
226
|
+
this.#audioReportedAt = 0;
|
|
227
|
+
this.#serverEvents.clear();
|
|
193
228
|
if (this.#instructions() !== initialInstructions) {
|
|
194
229
|
await this.#sendJson({ type: 'session.update', session: { instructions: this.#instructions() } });
|
|
195
230
|
}
|
|
@@ -285,6 +320,22 @@ export class QwenAudioRealtimeAdapter {
|
|
|
285
320
|
type: 'input_audio_buffer.append',
|
|
286
321
|
audio: Buffer.from(this.#wireProfile.inputPcm(pcm)).toString('base64'),
|
|
287
322
|
}));
|
|
323
|
+
this.#audioFramesSent += 1;
|
|
324
|
+
this.#audioBytesSent += pcm.byteLength;
|
|
325
|
+
const view = new DataView(pcm.buffer, pcm.byteOffset, pcm.byteLength);
|
|
326
|
+
for (let i = 0; i + 1 < pcm.byteLength; i += 2) {
|
|
327
|
+
const level = Math.abs(view.getInt16(i, true));
|
|
328
|
+
if (level > this.#audioPeak)
|
|
329
|
+
this.#audioPeak = level;
|
|
330
|
+
}
|
|
331
|
+
// Level and volume only, never samples: reported at most every two seconds while audio flows, and never beyond 60 reports.
|
|
332
|
+
const now = Date.now();
|
|
333
|
+
if (this.#audioFramesSent === 1 || (now - this.#audioReportedAt >= 2000 && this.#audioReports < 60)) {
|
|
334
|
+
this.#audioReportedAt = now;
|
|
335
|
+
this.#audioReports += 1;
|
|
336
|
+
this.#recordSession({ audio_frames_sent: this.#audioFramesSent, audio_bytes_sent: this.#audioBytesSent, audio_peak: this.#audioPeak });
|
|
337
|
+
this.#audioPeak = 0;
|
|
338
|
+
}
|
|
288
339
|
}
|
|
289
340
|
catch (error) {
|
|
290
341
|
if (error instanceof QwenSocketClosedError)
|
|
@@ -541,6 +592,10 @@ export class QwenAudioRealtimeAdapter {
|
|
|
541
592
|
}
|
|
542
593
|
}
|
|
543
594
|
async createResponse(intent, signal) {
|
|
595
|
+
if (intent.kind === 'tool_result') {
|
|
596
|
+
await this.ensureResponse(signal);
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
544
599
|
// DashScope's official qwen-audio-agent targets injected results with one response-local
|
|
545
600
|
// instruction and disables tools for that response. Keeping that boundary per response avoids
|
|
546
601
|
// letting the latest real user turn (for example, "确认") own a later host result.
|
|
@@ -593,7 +648,7 @@ export class QwenAudioRealtimeAdapter {
|
|
|
593
648
|
return operation;
|
|
594
649
|
}
|
|
595
650
|
async ensureResponse(signal) {
|
|
596
|
-
|
|
651
|
+
signal.throwIfAborted();
|
|
597
652
|
// No response-local instruction or tool override: this is the provider finishing the existing
|
|
598
653
|
// real user turn, and the confirmation function must remain available.
|
|
599
654
|
await this.#sendJson({ type: 'response.create', response: { modalities: ['audio', 'text'] } });
|
|
@@ -761,6 +816,7 @@ export class QwenAudioRealtimeAdapter {
|
|
|
761
816
|
this.#confirmDelete(identity);
|
|
762
817
|
continue;
|
|
763
818
|
}
|
|
819
|
+
this.#noteServerEvent(event);
|
|
764
820
|
const normalized = this.#normalizeEvent(event, epoch);
|
|
765
821
|
if (normalized !== undefined && !this.#publish(normalized, epoch))
|
|
766
822
|
return;
|
|
@@ -1030,7 +1086,7 @@ export class QwenAudioRealtimeAdapter {
|
|
|
1030
1086
|
session_epoch: epoch,
|
|
1031
1087
|
kind: 'provider_error',
|
|
1032
1088
|
code: isTruthy(rawParam) ? `${code}.${param}`.slice(0, 80) : code,
|
|
1033
|
-
recoverable: code === 'response_idle_timeout',
|
|
1089
|
+
recoverable: code === 'response_idle_timeout' || code === 'user_idle_timeout',
|
|
1034
1090
|
};
|
|
1035
1091
|
}
|
|
1036
1092
|
#enqueue(event) {
|
|
@@ -1118,6 +1174,54 @@ export class QwenAudioRealtimeAdapter {
|
|
|
1118
1174
|
throw new QwenRealtimeError('qwen realtime connection was replaced');
|
|
1119
1175
|
}
|
|
1120
1176
|
}
|
|
1177
|
+
/** Server event types are an allowlisted vocabulary; anything else is counted as `other`. Error codes are limited to a safe shape. */
|
|
1178
|
+
#noteServerEvent(event) {
|
|
1179
|
+
try {
|
|
1180
|
+
const raw = typeof event.type === 'string' ? event.type : 'other';
|
|
1181
|
+
const type = /^[a-z_]+(?:\.[a-z_]+){0,3}$/u.test(raw) ? raw : 'other';
|
|
1182
|
+
const count = (this.#serverEvents.get(type) ?? 0) + 1;
|
|
1183
|
+
if (this.#serverEvents.size >= 40 && !this.#serverEvents.has(type))
|
|
1184
|
+
return;
|
|
1185
|
+
this.#serverEvents.set(type, count);
|
|
1186
|
+
// Rare, decisive events are recorded each time; chatty ones only on first sight.
|
|
1187
|
+
const rare = type === 'error' || type.startsWith('input_audio_buffer.speech') || type === 'conversation.item.input_audio_transcription.completed';
|
|
1188
|
+
if (count === 1 || (rare && count <= 20)) {
|
|
1189
|
+
const detail = event.error;
|
|
1190
|
+
const code = type === 'error' && detail !== null && typeof detail === 'object' && !Array.isArray(detail) && typeof detail.code === 'string' && /^[A-Za-z0-9_.-]{1,60}$/u.test(detail.code) ? detail.code : undefined;
|
|
1191
|
+
this.#recordSession({ server_event: type, count, ...(code === undefined ? {} : { error_code: code }) });
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
catch { /* diagnostic only */ }
|
|
1195
|
+
}
|
|
1196
|
+
/** What the service says it accepted: only short, shape-checked configuration names, never instructions or tools. */
|
|
1197
|
+
#recordAcceptedSession(updated) {
|
|
1198
|
+
try {
|
|
1199
|
+
const session = updated.session;
|
|
1200
|
+
if (session === null || typeof session !== 'object' || Array.isArray(session))
|
|
1201
|
+
return;
|
|
1202
|
+
const short = (value) => typeof value === 'string' && /^[A-Za-z0-9_.-]{1,40}$/u.test(value) ? value : undefined;
|
|
1203
|
+
const detection = session.turn_detection, detectionType = detection !== null && typeof detection === 'object' && !Array.isArray(detection) ? short(detection.type) : (detection === null ? 'none' : undefined);
|
|
1204
|
+
const out = { accepted: true };
|
|
1205
|
+
for (const [name, value] of [['input_audio_format', short(session.input_audio_format)], ['output_audio_format', short(session.output_audio_format)], ['model', short(session.model)], ['turn_detection', detectionType]])
|
|
1206
|
+
if (value !== undefined)
|
|
1207
|
+
out[name] = value;
|
|
1208
|
+
this.#recordSession(out);
|
|
1209
|
+
}
|
|
1210
|
+
catch { /* diagnostic only */ }
|
|
1211
|
+
}
|
|
1212
|
+
#recordSession(payload) {
|
|
1213
|
+
try {
|
|
1214
|
+
this.#telemetry?.record('integrated.session', { provider: this.#wireProfile.provider, ...payload });
|
|
1215
|
+
}
|
|
1216
|
+
catch { /* diagnostic only */ }
|
|
1217
|
+
}
|
|
1218
|
+
#recordConnect(payload) {
|
|
1219
|
+
// Diagnostics must never change the connect outcome.
|
|
1220
|
+
try {
|
|
1221
|
+
this.#telemetry?.record('integrated.connect', { provider: this.#wireProfile.provider, ...payload });
|
|
1222
|
+
}
|
|
1223
|
+
catch { /* diagnostic only */ }
|
|
1224
|
+
}
|
|
1121
1225
|
async #receiveJson(socket) {
|
|
1122
1226
|
const raw = await socket.receive();
|
|
1123
1227
|
let parsed;
|
|
@@ -1203,6 +1307,37 @@ class QwenTimeout extends Error {
|
|
|
1203
1307
|
this.name = 'QwenTimeout';
|
|
1204
1308
|
}
|
|
1205
1309
|
}
|
|
1310
|
+
/** A provider `error` event in place of the setup handshake (e.g. quota or model access). */
|
|
1311
|
+
class ProviderSetupRejected extends Error {
|
|
1312
|
+
providerCode;
|
|
1313
|
+
constructor(event) {
|
|
1314
|
+
super('realtime_session_rejected');
|
|
1315
|
+
const detail = event.error;
|
|
1316
|
+
const code = isJsonObject(detail) ? detail.code : undefined;
|
|
1317
|
+
// Shape checks still admit letter-only credentials; retain only known diagnostic codes.
|
|
1318
|
+
this.providerCode = typeof code === 'string' && ['Arrearage', 'invalid_api_key'].includes(code) ? code : undefined;
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
/** A bounded, secret-free label for an otherwise unclassified failure: the stage plus a system error code or error class name. */
|
|
1322
|
+
function unclassifiedDetail(error, stage) {
|
|
1323
|
+
const code = error instanceof RealtimeConnectError ? error.systemCode ?? '' : error instanceof Error && 'code' in error ? String(error.code) : '';
|
|
1324
|
+
const name = error instanceof Error ? error.name : '';
|
|
1325
|
+
const cause = /^[A-Z][A-Z0-9_]{2,40}$/u.test(code) ? code : /^[A-Za-z]{1,40}$/u.test(name) ? name : 'unknown';
|
|
1326
|
+
return `stage=${stage};cause=${cause}`;
|
|
1327
|
+
}
|
|
1328
|
+
function connectFailureCode(error, stage) {
|
|
1329
|
+
if (error instanceof RealtimeConnectError) {
|
|
1330
|
+
return { code: error.code, ...(error.code === 'realtime_connect_failed' ? { detail: unclassifiedDetail(error, stage) } : {}), error: new QwenRealtimeError(error.code) };
|
|
1331
|
+
}
|
|
1332
|
+
if (error instanceof ProviderSetupRejected)
|
|
1333
|
+
return { code: error.message, error: new QwenRealtimeError(error.message) };
|
|
1334
|
+
// Adapter-authored protocol text is constant (never provider data) and stays as a diagnostic detail.
|
|
1335
|
+
if (error instanceof QwenRealtimeError)
|
|
1336
|
+
return { code: 'realtime_protocol_error', detail: error.message.slice(0, 120), error: new QwenRealtimeError('realtime_protocol_error') };
|
|
1337
|
+
if (isTimeout(error))
|
|
1338
|
+
return { code: 'realtime_timeout', error: new QwenRealtimeError('realtime_timeout') };
|
|
1339
|
+
return { code: 'realtime_connect_failed', detail: unclassifiedDetail(error, stage), error: new QwenRealtimeError('realtime_connect_failed') };
|
|
1340
|
+
}
|
|
1206
1341
|
function isTimeout(error) {
|
|
1207
1342
|
return error instanceof QwenTimeout;
|
|
1208
1343
|
}
|
|
@@ -30,7 +30,6 @@ export const SYNC_RESULT_TITLE_CHARS = 120;
|
|
|
30
30
|
export const SYNC_RESULT_SNIPPET_CHARS = 400;
|
|
31
31
|
/** Longest a user may hold the floor before the hold is treated as stale and released. */
|
|
32
32
|
export const USER_HOLD_MAX_S = 30;
|
|
33
|
-
export const STALE_DELIVERY_RETRY_S = 1;
|
|
34
33
|
/** Below this priority a host item waits its turn; at or above it may interrupt the agent. */
|
|
35
34
|
export const PREEMPT_MIN_PRIORITY = 80;
|
|
36
35
|
/** Ordinary progress older than this is stale operational narration, not a current user fact. */
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { abortable } from '../core/camera-session.js';
|
|
1
2
|
import { parseMemoryRef } from '../core/memory.js';
|
|
2
3
|
import { TaskExecutionRejected } from '../personal-agent/task-loop.js';
|
|
3
4
|
import { taskGrantService } from '../personal-agent/tasks.js';
|
|
@@ -47,6 +48,7 @@ function sameAgentDescriptors(left, right) {
|
|
|
47
48
|
*/
|
|
48
49
|
const SHUTDOWN_GRACE_MS = 250;
|
|
49
50
|
export class RealtimeService {
|
|
51
|
+
invokeConversationTool(event, turn) { return this.#continuations.invokeStandalone(event, turn); }
|
|
50
52
|
async setLanguage(language) { await this.#provider.setLanguage?.(language); }
|
|
51
53
|
playbackStarted(utteranceId, generationEpoch) { return this.#host.playbackStarted(utteranceId, generationEpoch); }
|
|
52
54
|
#confirmation;
|
|
@@ -131,7 +133,12 @@ export class RealtimeService {
|
|
|
131
133
|
if (!admittedFeed)
|
|
132
134
|
void route.publish(notice).catch(() => this.#onDiagnostic('[realtime-diagnostic] notification_admission_failed'));
|
|
133
135
|
if (!route.local()) {
|
|
134
|
-
void this.session.injectHostContext(intent.item
|
|
136
|
+
void this.session.injectHostContext(intent.item, options.authorizeBeforeInject ? { authorizeBeforeInject: async () => { const guard = AbortSignal.any([this.#stop.signal, AbortSignal.timeout(5000)]); try {
|
|
137
|
+
return await abortable(options.authorizeBeforeInject(guard), guard) && !guard.aborted;
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
return false;
|
|
141
|
+
} } } : {}).catch(() => this.#onDiagnostic('[realtime-diagnostic] notification_context_unavailable'));
|
|
135
142
|
return;
|
|
136
143
|
}
|
|
137
144
|
const prior = options.stillWanted;
|
|
@@ -142,8 +149,10 @@ export class RealtimeService {
|
|
|
142
149
|
projectRuntimeEvent(event, currentConversation = true) {
|
|
143
150
|
this.#projection.projectRuntimeEvent(event, currentConversation);
|
|
144
151
|
}
|
|
145
|
-
onSuggestionSelected(suggestion, reason) {
|
|
146
|
-
this.#
|
|
152
|
+
onSuggestionSelected(suggestion, reason, authorization = {}) {
|
|
153
|
+
if (this.#provider.capabilities?.protocol.conversationItems === false || this.#provider.capabilities?.protocol.clientResponses === false)
|
|
154
|
+
return;
|
|
155
|
+
this.#projection.onSuggestionSelected(suggestion, reason, authorization);
|
|
147
156
|
}
|
|
148
157
|
session;
|
|
149
158
|
#intake;
|
|
@@ -308,6 +317,7 @@ export class RealtimeService {
|
|
|
308
317
|
controlledPreemptiveAlertReconnect: this.#controlledPreemptiveAlertReconnect,
|
|
309
318
|
clearingConversation: () => this.#clearingConversation,
|
|
310
319
|
stopped: () => this.#stop.signal.aborted,
|
|
320
|
+
stopSignal: () => this.#stop.signal,
|
|
311
321
|
providerFailed: () => this.#providerFailed,
|
|
312
322
|
wake: () => this.#deliveryReady.set(),
|
|
313
323
|
intakeFactEligible: (id, epoch) => this.#intake?.factEligible(id, epoch),
|
|
@@ -373,8 +383,11 @@ export class RealtimeService {
|
|
|
373
383
|
throw new TypeError('agent controller registry does not match compiled tool descriptors');
|
|
374
384
|
}
|
|
375
385
|
this.#continuations = new ToolContinuations({
|
|
386
|
+
...(options.spaceMobile ? { spaceMobile: options.spaceMobile } : {}),
|
|
376
387
|
...(options.scheduleHost ? { scheduleHost: options.scheduleHost } : {}),
|
|
377
388
|
...(options.scopedTool ? { scopedTool: options.scopedTool } : {}),
|
|
389
|
+
...(options.toolGate ? { toolGate: options.toolGate } : {}),
|
|
390
|
+
...(options.onTool ? { onTool: options.onTool } : {}),
|
|
378
391
|
...(options.validateScopedContext ? { validateScopedContext: options.validateScopedContext } : {}),
|
|
379
392
|
...(options.taskHost ? { taskHost: options.taskHost } : {}),
|
|
380
393
|
session: this.session, host: this.#host, runtime: this.#runtime,
|
|
@@ -649,6 +662,16 @@ export class RealtimeService {
|
|
|
649
662
|
const previous = this.#inputReady;
|
|
650
663
|
const replace = async () => {
|
|
651
664
|
this.#discardedInputEpoch = this.session.sessionEpoch;
|
|
665
|
+
if (this.#provider.capabilities?.model.nativeFullDuplex) {
|
|
666
|
+
try {
|
|
667
|
+
await this.playbackDisconnected({ resumeDelivery: false });
|
|
668
|
+
}
|
|
669
|
+
finally {
|
|
670
|
+
await this.#provider.close();
|
|
671
|
+
}
|
|
672
|
+
this.#notifyProviderEvent({ kind: 'provider_error', session_epoch: this.session.sessionEpoch, code: 'native_session_requires_restart', recoverable: false });
|
|
673
|
+
throw Error('native_session_requires_restart');
|
|
674
|
+
}
|
|
652
675
|
await this.#reconnectProviderSession({ reason: 'client_disconnect' });
|
|
653
676
|
};
|
|
654
677
|
const ready = previous === null ? replace() : previous.then(replace, replace);
|
|
@@ -682,7 +705,7 @@ export class RealtimeService {
|
|
|
682
705
|
await this.#provider.sendAudio(pcm, controller.signal);
|
|
683
706
|
}
|
|
684
707
|
async localSpeechOnset(speechId) {
|
|
685
|
-
if (this.#clearingConversation)
|
|
708
|
+
if (this.#clearingConversation || this.#provider.capabilities?.model.nativeFullDuplex === true)
|
|
686
709
|
return;
|
|
687
710
|
if (speechId !== this.#lastLocalSpeechOnsetId) {
|
|
688
711
|
this.#lastLocalSpeechOnsetId = speechId;
|
|
@@ -765,7 +788,18 @@ export class RealtimeService {
|
|
|
765
788
|
}
|
|
766
789
|
#failUncertainDelivery() {
|
|
767
790
|
this.#onDiagnostic('[realtime-diagnostic] uncertain_delivery_exhausted');
|
|
791
|
+
const alreadyFailed = this.#providerFailed;
|
|
768
792
|
this.#providerFailed = true;
|
|
793
|
+
// The UI may still believe the voice session is live; tell lifecycle owners the
|
|
794
|
+
// service is stopping, exactly like #taskFailed does for loop failures.
|
|
795
|
+
if (!alreadyFailed) {
|
|
796
|
+
this.#notifyProviderEvent({
|
|
797
|
+
kind: 'provider_error',
|
|
798
|
+
session_epoch: this.session.sessionEpoch,
|
|
799
|
+
code: 'uncertain_delivery_failed',
|
|
800
|
+
recoverable: false,
|
|
801
|
+
});
|
|
802
|
+
}
|
|
769
803
|
this.#host.releaseFailedDelivery();
|
|
770
804
|
this.#stop.abort();
|
|
771
805
|
this.#deliveryReady.set();
|
|
@@ -783,6 +817,8 @@ export class RealtimeService {
|
|
|
783
817
|
* its own, and CP3 says the two are never held together.
|
|
784
818
|
*/
|
|
785
819
|
async #deliveryPass() {
|
|
820
|
+
if (this.#provider.capabilities?.protocol.conversationItems === false || this.#provider.capabilities?.protocol.clientResponses === false)
|
|
821
|
+
return;
|
|
786
822
|
if (await this.#host.deliveryPass())
|
|
787
823
|
await this.driveContinuations();
|
|
788
824
|
}
|
|
@@ -832,6 +868,7 @@ export class RealtimeService {
|
|
|
832
868
|
async #reconnectProviderSession(options) {
|
|
833
869
|
const requestedEpoch = options.expectedEpoch ?? this.session.sessionEpoch;
|
|
834
870
|
this.#telemetry?.record('provider.reconnect', { reason: options.reason, outcome: 'started' });
|
|
871
|
+
let replacementAnnounced = false;
|
|
835
872
|
try {
|
|
836
873
|
return await this.#reconnectLock.run(async () => {
|
|
837
874
|
if (this.session.sessionEpoch !== requestedEpoch) {
|
|
@@ -872,6 +909,14 @@ export class RealtimeService {
|
|
|
872
909
|
this.#continuations.reconcileToolStateAfterReconnect(oldEpoch);
|
|
873
910
|
this.#host.reopenFailedSemanticAcknowledgements();
|
|
874
911
|
this.#host.reconcileSemanticAcknowledgementsAfterReconnect();
|
|
912
|
+
// Tell lifecycle owners before any queued delivery resumes, so a user
|
|
913
|
+
// whose transport just came back learns they can speak again without
|
|
914
|
+
// having to test the new session first.
|
|
915
|
+
this.#notifyProviderEvent({
|
|
916
|
+
kind: 'provider_reconnected',
|
|
917
|
+
session_epoch: this.session.sessionEpoch,
|
|
918
|
+
});
|
|
919
|
+
replacementAnnounced = true;
|
|
875
920
|
await this.driveContinuations();
|
|
876
921
|
await this.#deliveryPass();
|
|
877
922
|
this.#telemetry?.record('provider.reconnect', {
|
|
@@ -883,6 +928,17 @@ export class RealtimeService {
|
|
|
883
928
|
}
|
|
884
929
|
catch (failure) {
|
|
885
930
|
this.#telemetry?.record('provider.reconnect', { reason: options.reason, outcome: 'failed' });
|
|
931
|
+
// A failed replacement leaves no provider behind, so the transport will
|
|
932
|
+
// emit nothing else. Lifecycle owners must learn the outcome here. A failure after the
|
|
933
|
+
// replacement was announced is a delivery problem on a live session, not a dead transport.
|
|
934
|
+
if (!replacementAnnounced) {
|
|
935
|
+
this.#notifyProviderEvent({
|
|
936
|
+
kind: 'provider_error',
|
|
937
|
+
session_epoch: this.session.sessionEpoch,
|
|
938
|
+
code: 'reconnect_failed',
|
|
939
|
+
recoverable: false,
|
|
940
|
+
});
|
|
941
|
+
}
|
|
886
942
|
throw failure;
|
|
887
943
|
}
|
|
888
944
|
}
|
|
@@ -914,8 +970,15 @@ export class RealtimeService {
|
|
|
914
970
|
continue;
|
|
915
971
|
received = true;
|
|
916
972
|
try {
|
|
973
|
+
// A provider error is transport news, not conversation state: handleEvent
|
|
974
|
+
// may spend seconds replacing the session inside its recoverable arm, so
|
|
975
|
+
// lifecycle owners are told first. Otherwise the "reconnecting" notice
|
|
976
|
+
// would arrive only after the reconnect had already finished.
|
|
977
|
+
if (event.kind === 'provider_error')
|
|
978
|
+
this.#notifyProviderEvent(event);
|
|
917
979
|
await this.handleEvent(event);
|
|
918
|
-
|
|
980
|
+
if (event.kind !== 'provider_error')
|
|
981
|
+
this.#notifyProviderEvent(event);
|
|
919
982
|
}
|
|
920
983
|
catch (cause) {
|
|
921
984
|
if (event.kind === 'response_terminal')
|
|
@@ -1045,11 +1108,23 @@ export class RealtimeService {
|
|
|
1045
1108
|
await this.session.accept(event);
|
|
1046
1109
|
this.#onDiagnostic(`[realtime-diagnostic] provider_error code=${event.code} recoverable=${event.recoverable}`);
|
|
1047
1110
|
if (event.recoverable) {
|
|
1048
|
-
|
|
1111
|
+
// Cleared before the reconnect so the empty final caption cannot land after
|
|
1112
|
+
// "provider_reconnected" and make the desktop treat it as a fresh utterance.
|
|
1113
|
+
this.#clearCaptions();
|
|
1114
|
+
const replaced = await this.#reconnectProviderSession({
|
|
1049
1115
|
reason: 'recoverable_provider_error',
|
|
1050
1116
|
expectedEpoch: this.session.sessionEpoch,
|
|
1051
1117
|
});
|
|
1052
|
-
|
|
1118
|
+
// A false result means another reconnect replaced the session first, so
|
|
1119
|
+
// its own completion notification may have landed before this error was
|
|
1120
|
+
// reported. Re-state that the live epoch is usable, or a listener that
|
|
1121
|
+
// announced the gap would wait for a recovery that already happened.
|
|
1122
|
+
if (replaced === false) {
|
|
1123
|
+
this.#notifyProviderEvent({
|
|
1124
|
+
kind: 'provider_reconnected',
|
|
1125
|
+
session_epoch: this.session.sessionEpoch,
|
|
1126
|
+
});
|
|
1127
|
+
}
|
|
1053
1128
|
}
|
|
1054
1129
|
else {
|
|
1055
1130
|
this.#providerFailed = true;
|
|
@@ -1372,7 +1447,18 @@ export class RealtimeService {
|
|
|
1372
1447
|
this.#onDiagnostic('[realtime-diagnostic] task_failure_from_previous_run');
|
|
1373
1448
|
return;
|
|
1374
1449
|
}
|
|
1450
|
+
const alreadyFailed = this.#providerFailed;
|
|
1375
1451
|
this.#providerFailed = true;
|
|
1452
|
+
// Owners were told "recovered" or "connected" earlier; without a terminal notice they would keep
|
|
1453
|
+
// showing a live voice session after the service has stopped.
|
|
1454
|
+
if (!alreadyFailed) {
|
|
1455
|
+
this.#notifyProviderEvent({
|
|
1456
|
+
kind: 'provider_error',
|
|
1457
|
+
session_epoch: this.session.sessionEpoch,
|
|
1458
|
+
code: 'service_task_failed',
|
|
1459
|
+
recoverable: false,
|
|
1460
|
+
});
|
|
1461
|
+
}
|
|
1376
1462
|
this.#approvalHost.invalidateExecutorApproval('task_failed');
|
|
1377
1463
|
this.#host.releaseFailedDelivery();
|
|
1378
1464
|
this.#stop.abort();
|