nova-personal-agent-server 0.4.0 → 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 +12 -2
- 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 +13 -6
- 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 { memoryRememberSummary } from '../personal-agent/conversation-tool-bridge.js';
|
|
1
2
|
import { scheduledToolResult } from '../personal-agent/scheduled-tool-runtime.js';
|
|
2
3
|
import { dispatchSources, projectRecoveryTurns, recentDispatchSources } from './history.js';
|
|
3
4
|
import { taskToolArguments } from '../core/task-tools.js';
|
|
@@ -14,7 +15,51 @@ import { MAX_HOST_FACT_CHARS, MAX_LATE_SYNC_RESULTS, MAX_PENDING_TOOL_REFUSALS,
|
|
|
14
15
|
import { MAX_CONTINUATION_TASK_SUMMARY } from './session-state.js';
|
|
15
16
|
import { RealtimeDeliveryError } from './session.js';
|
|
16
17
|
const UNKNOWN_CONFIRMATION_TOOL_RESULT = JSON.stringify({ code: 'unknown_confirmation', state: 'refused' });
|
|
18
|
+
function acceptanceSummary(acceptance, event) {
|
|
19
|
+
const content = acceptance.host_item?.content;
|
|
20
|
+
if (event.name === 'memory__remember') {
|
|
21
|
+
let result = null;
|
|
22
|
+
try {
|
|
23
|
+
result = JSON.parse(content);
|
|
24
|
+
}
|
|
25
|
+
catch { /* Missing receipts are not committed writes. */ }
|
|
26
|
+
return memoryRememberSummary(event.arguments, result, acceptance.accepted);
|
|
27
|
+
}
|
|
28
|
+
if (typeof content !== 'string')
|
|
29
|
+
return '';
|
|
30
|
+
try {
|
|
31
|
+
const value = JSON.parse(content);
|
|
32
|
+
const inner = value.result && typeof value.result === 'object' ? value.result : value;
|
|
33
|
+
if (Array.isArray(inner.items))
|
|
34
|
+
return `${inner.items.length} 条`;
|
|
35
|
+
if (Array.isArray(inner.results))
|
|
36
|
+
return `${inner.results.length} 条`;
|
|
37
|
+
if (Array.isArray(inner.entries))
|
|
38
|
+
return `${inner.entries.length} 条`;
|
|
39
|
+
if (Array.isArray(inner.snippets))
|
|
40
|
+
return `${inner.snippets.length} 条`;
|
|
41
|
+
if (typeof inner.hit_count === 'number' && Number.isSafeInteger(inner.hit_count))
|
|
42
|
+
return `${inner.hit_count} 条`;
|
|
43
|
+
}
|
|
44
|
+
catch { /* non-JSON host results carry no safe summary */ }
|
|
45
|
+
return '';
|
|
46
|
+
}
|
|
17
47
|
export class ToolContinuations {
|
|
48
|
+
/** Text loops share admission/execution with voice without manufacturing provider events. */
|
|
49
|
+
async invokeStandalone(event, turn) {
|
|
50
|
+
if (!this.#ports.tools.bindings.has(event.name) || this.#ports.tools.hidden.has(event.name))
|
|
51
|
+
return this.#refusalAcceptance(event, 'unknown_tool', '{"code":"unknown_tool"}');
|
|
52
|
+
if (this.#ports.toolGate && !this.#ports.toolGate(event.name))
|
|
53
|
+
return this.#refusalAcceptance(event, 'chat_tool_forbidden', '{"code":"chat_tool_forbidden","state":"refused"}');
|
|
54
|
+
turn.signal.throwIfAborted();
|
|
55
|
+
const intercepted = await this.#interceptHost(event, turn.user.origin_ref, turn);
|
|
56
|
+
if (intercepted)
|
|
57
|
+
return intercepted;
|
|
58
|
+
const binding = this.#ports.tools.bindings.get(event.name);
|
|
59
|
+
if (binding?.kind === 'query')
|
|
60
|
+
return this.#ports.bridge.acceptPersonalMemoryRecall(event, { originRef: turn.user.origin_ref, signal: turn.signal });
|
|
61
|
+
return this.#ports.bridge.acceptToolCall(event, { originRef: turn.user.origin_ref, userTurn: turn.authority });
|
|
62
|
+
}
|
|
18
63
|
recordIntakeDispatch(intake, result) {
|
|
19
64
|
if (result.accepted && result.delegate_id !== null && result.delegate_id !== undefined) {
|
|
20
65
|
const title = intake.title ?? intake.target?.session_title;
|
|
@@ -111,6 +156,7 @@ export class ToolContinuations {
|
|
|
111
156
|
* preemption means something urgent is about to interrupt, so starting a turn now would produce one
|
|
112
157
|
* that is immediately cut off.
|
|
113
158
|
*/
|
|
159
|
+
#lastBlockedResponse = null;
|
|
114
160
|
#continuationRequestIsBlocked() {
|
|
115
161
|
return this.#ports.host.rendererPaused
|
|
116
162
|
|| this.session.floor.state === 'user_speaking'
|
|
@@ -184,6 +230,7 @@ export class ToolContinuations {
|
|
|
184
230
|
if (state === undefined)
|
|
185
231
|
continue;
|
|
186
232
|
if (state.output === 'pending') {
|
|
233
|
+
this.#ports.telemetry?.record('tool.continuation', { response_id: batch.provider_response_id, call_id: state.acceptance.host_item.call_id, stage: 'injecting' });
|
|
187
234
|
await this.session.injectToolOutput(state.acceptance.host_item);
|
|
188
235
|
state.output = 'confirmed';
|
|
189
236
|
}
|
|
@@ -205,8 +252,13 @@ export class ToolContinuations {
|
|
|
205
252
|
this.#continuationFifo.shift();
|
|
206
253
|
continue;
|
|
207
254
|
}
|
|
208
|
-
if (this.#continuationRequestIsBlocked())
|
|
255
|
+
if (this.#continuationRequestIsBlocked()) {
|
|
256
|
+
if (this.#lastBlockedResponse !== batch.provider_response_id)
|
|
257
|
+
this.#ports.telemetry?.record('tool.continuation', { response_id: batch.provider_response_id, stage: 'blocked', renderer_paused: this.#ports.host.rendererPaused, floor: this.session.floor.state, preempt: this.#ports.host.hasEligiblePreempt() });
|
|
258
|
+
this.#lastBlockedResponse = batch.provider_response_id;
|
|
209
259
|
return;
|
|
260
|
+
}
|
|
261
|
+
this.#lastBlockedResponse = null;
|
|
210
262
|
if (this.#ports.validateScopedContext && !await this.#ports.validateScopedContext()) {
|
|
211
263
|
this.#discardScopedBatch(batch);
|
|
212
264
|
this.#continuationFifo.shift();
|
|
@@ -215,6 +267,7 @@ export class ToolContinuations {
|
|
|
215
267
|
const requestResult = await this.session.requestToolContinuation(intents, {
|
|
216
268
|
originSpoken: this.#batchOriginWasDelivered(batch),
|
|
217
269
|
});
|
|
270
|
+
this.#ports.telemetry?.record('tool.continuation', { response_id: batch.provider_response_id, stage: requestResult });
|
|
218
271
|
// Retryable means the provider could not take it *now*: the batch keeps its place and the next
|
|
219
272
|
// pass tries again. Rejected means it never will.
|
|
220
273
|
if (requestResult === 'retryable')
|
|
@@ -723,6 +776,7 @@ export class ToolContinuations {
|
|
|
723
776
|
}
|
|
724
777
|
return;
|
|
725
778
|
}
|
|
779
|
+
this.#ports.onTool?.({ name: call.name, state: 'running', summary: '' });
|
|
726
780
|
const observedProviderResponseId = options.observedProviderResponseId ?? null;
|
|
727
781
|
const originRef = options.originRef ?? null;
|
|
728
782
|
const activeResponseId = this.session.activeProviderResponseId;
|
|
@@ -798,6 +852,9 @@ export class ToolContinuations {
|
|
|
798
852
|
else if (hidden) {
|
|
799
853
|
acceptance = this.#refusalAcceptance(event, 'unknown_tool', '{"code":"unknown_tool","state":"refused"}');
|
|
800
854
|
}
|
|
855
|
+
else if (this.#ports.toolGate && !this.#ports.toolGate(event.name)) {
|
|
856
|
+
acceptance = this.#refusalAcceptance(event, 'chat_tool_forbidden', '{"code":"chat_tool_forbidden","state":"refused"}');
|
|
857
|
+
}
|
|
801
858
|
else if (this.#ports.scopedTool) {
|
|
802
859
|
acceptance = await this.#ports.scopedTool(event);
|
|
803
860
|
}
|
|
@@ -871,6 +928,7 @@ export class ToolContinuations {
|
|
|
871
928
|
throw cause;
|
|
872
929
|
}
|
|
873
930
|
}
|
|
931
|
+
this.#ports.onTool?.({ name: event.name, state: acceptance.accepted ? 'ok' : 'error', summary: acceptanceSummary(acceptance, event) });
|
|
874
932
|
this.#recordToolAdmission({
|
|
875
933
|
callId: event.call_id,
|
|
876
934
|
logicalName: binding?.logical_name ?? null,
|
|
@@ -991,6 +1049,7 @@ export class ToolContinuations {
|
|
|
991
1049
|
? 'fulfilled'
|
|
992
1050
|
: 'rejected';
|
|
993
1051
|
input.state.sync = 'none';
|
|
1052
|
+
this.#ports.onTool?.({ name: input.event.name, state: input.state.acceptance.accepted ? 'ok' : 'error', summary: acceptanceSummary(input.state.acceptance, input.event) });
|
|
994
1053
|
this.#recordToolAdmission({
|
|
995
1054
|
callId: input.event.call_id,
|
|
996
1055
|
logicalName: input.state.logical_name,
|
|
@@ -1001,6 +1060,7 @@ export class ToolContinuations {
|
|
|
1001
1060
|
this.#ports.telemetry?.record('memory.recall', input.state.acceptance.telemetry);
|
|
1002
1061
|
}
|
|
1003
1062
|
const batch = this.#continuationBatches.get(callKey(input.event.session_epoch, input.providerResponseId));
|
|
1063
|
+
this.#ports.telemetry?.record('tool.continuation', { response_id: input.providerResponseId, stage: 'recall_resolved', phase: batch?.phase ?? 'missing', renderer_paused: this.#ports.host.rendererPaused, floor: this.session.floor.state });
|
|
1004
1064
|
if (superseded && batch !== undefined) {
|
|
1005
1065
|
batch.origin_status = 'cancelled';
|
|
1006
1066
|
batch.phase = 'ready';
|
|
@@ -1079,14 +1139,31 @@ export class ToolContinuations {
|
|
|
1079
1139
|
* The host tools. A controller receives the fenced public request and returns structured facts;
|
|
1080
1140
|
* RealtimeService alone maps those facts to provider-facing result language.
|
|
1081
1141
|
*/
|
|
1082
|
-
async #interceptHost(event, originRef) {
|
|
1142
|
+
async #interceptHost(event, originRef, standalone) {
|
|
1083
1143
|
if (event.name === CONFIRM_TOOL) {
|
|
1084
1144
|
return this.#refusalAcceptance(event, 'unknown_confirmation', UNKNOWN_CONFIRMATION_TOOL_RESULT);
|
|
1085
1145
|
}
|
|
1086
1146
|
if (this.#ports.taskHost?.isCurrent?.() === false)
|
|
1087
1147
|
return this.#refusalAcceptance(event, 'superseded', '{"code":"superseded"}');
|
|
1148
|
+
if (event.name === 'mobile__action') {
|
|
1149
|
+
const user = standalone?.user ?? this.#ports.intakeUser(), authority = standalone?.authority ?? this.#ports.currentUserTurn(event, originRef), host = this.#ports.spaceMobile;
|
|
1150
|
+
if (!host)
|
|
1151
|
+
return this.#refusalAcceptance(event, 'unsupported_tool', '{"code":"unsupported_tool"}');
|
|
1152
|
+
if (!authority || !user || event.session_epoch <= this.#ports.discardedInputEpoch() || user.epoch !== event.session_epoch || originRef !== user.origin_ref)
|
|
1153
|
+
return this.#refusalAcceptance(event, 'missing_origin_ref', '{"code":"missing_origin_ref"}');
|
|
1154
|
+
const args = { ...event.arguments };
|
|
1155
|
+
delete args.origin_ref;
|
|
1156
|
+
try {
|
|
1157
|
+
const result = await host.invoke(args, { request_id: originRef + ':' + event.call_id, stillWanted: authority.stillWanted });
|
|
1158
|
+
return scheduledToolResult(event, result);
|
|
1159
|
+
}
|
|
1160
|
+
catch (error) {
|
|
1161
|
+
const code = error instanceof Error ? error.message : 'mobile_action_failed';
|
|
1162
|
+
return scheduledToolResult(event, { code, state: 'refused' }, code, false);
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1088
1165
|
if (event.name === 'schedule') {
|
|
1089
|
-
const user = this.#ports.intakeUser(), authority = this.#ports.currentUserTurn(event, originRef), host = this.#ports.scheduleHost;
|
|
1166
|
+
const user = standalone?.user ?? this.#ports.intakeUser(), authority = standalone?.authority ?? this.#ports.currentUserTurn(event, originRef), host = this.#ports.scheduleHost;
|
|
1090
1167
|
if (!host)
|
|
1091
1168
|
return this.#refusalAcceptance(event, 'unsupported_tool', '{"code":"unsupported_tool"}');
|
|
1092
1169
|
if (!authority || !user || event.session_epoch <= this.#ports.discardedInputEpoch() || user.epoch !== event.session_epoch || originRef !== user.origin_ref)
|
|
@@ -1172,8 +1249,8 @@ export class ToolContinuations {
|
|
|
1172
1249
|
}
|
|
1173
1250
|
// Both act on the user's behalf, so both need the current user turn as origin: a spontaneous
|
|
1174
1251
|
// `cancel` would stop work nobody asked to stop.
|
|
1175
|
-
const user = this.#ports.intakeUser();
|
|
1176
|
-
if (event.session_epoch <= this.#ports.discardedInputEpoch() || originRef === null || user?.epoch !== event.session_epoch || originRef !== user.origin_ref) {
|
|
1252
|
+
const user = standalone?.user ?? this.#ports.intakeUser();
|
|
1253
|
+
if ((!standalone && event.session_epoch <= this.#ports.discardedInputEpoch()) || originRef === null || user?.epoch !== event.session_epoch || originRef !== user.origin_ref) {
|
|
1177
1254
|
return this.#refusalAcceptance(event, 'missing_origin_ref', '{"code":"missing_origin_ref"}');
|
|
1178
1255
|
}
|
|
1179
1256
|
const conversationItems = this.#ports.runtime.memory?.channels.get('conversation')?.items ?? [];
|
|
@@ -1193,7 +1270,7 @@ export class ToolContinuations {
|
|
|
1193
1270
|
return this.#refusalAcceptance(event, 'unsupported_tool', '{"code":"unsupported_tool"}');
|
|
1194
1271
|
// A user turn that supersedes an async controller operation makes its result informational only;
|
|
1195
1272
|
// the controller must re-check this fence before it changes executor state.
|
|
1196
|
-
const authority = this.#ports.currentUserTurn(event, originRef);
|
|
1273
|
+
const authority = standalone?.authority ?? this.#ports.currentUserTurn(event, originRef);
|
|
1197
1274
|
if (authority === null)
|
|
1198
1275
|
return this.#refusalAcceptance(event, 'superseded', '{"code":"superseded"}');
|
|
1199
1276
|
const revision = authority.acceptedUserInputRevision;
|
|
@@ -1221,7 +1298,7 @@ export class ToolContinuations {
|
|
|
1221
1298
|
return this.#refusalAcceptance(event, 'ambiguous_task', canonicalJson({ code: 'ambiguous_task', task_ids: candidates.map(task => task.id) }));
|
|
1222
1299
|
return this.#refusalAcceptance(event, 'not_running', '{"code":"not_running"}');
|
|
1223
1300
|
}
|
|
1224
|
-
let taskContext;
|
|
1301
|
+
let taskContext = standalone?.task;
|
|
1225
1302
|
if (event.name === DISPATCH_TOOL && event.arguments.task_id !== undefined) {
|
|
1226
1303
|
try {
|
|
1227
1304
|
const host = this.#ports.taskHost;
|
|
@@ -5,4 +5,21 @@ export class RealtimeSocketClosedError extends Error {
|
|
|
5
5
|
this.name = 'RealtimeSocketClosedError';
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* A handshake failure reduced to a user-actionable code. The message is the code itself and
|
|
10
|
+
* never carries the provider's text, the endpoint, or the credential.
|
|
11
|
+
*/
|
|
12
|
+
export class RealtimeConnectError extends Error {
|
|
13
|
+
code;
|
|
14
|
+
status;
|
|
15
|
+
/** Allowlisted-shape system error code (for example `EPROTO`); never provider text. */
|
|
16
|
+
systemCode;
|
|
17
|
+
constructor(code, status, systemCode) {
|
|
18
|
+
super(code);
|
|
19
|
+
this.systemCode = systemCode;
|
|
20
|
+
this.name = 'RealtimeConnectError';
|
|
21
|
+
this.code = code;
|
|
22
|
+
this.status = status;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
8
25
|
//# sourceMappingURL=transport.js.map
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
+
import { safeUsageContext } from '../usage/context.js';
|
|
1
2
|
const meters = ['inputTokens', 'outputTokens', 'inputTextTokens', 'inputAudioTokens',
|
|
2
3
|
'outputTextTokens', 'outputAudioTokens', 'cachedTokens', 'reasoningTokens',
|
|
3
|
-
'audioDurationMs', 'characters'];
|
|
4
|
-
export function
|
|
5
|
-
if (
|
|
6
|
-
return;
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
'audioDurationMs', 'characters', 'durationMs'];
|
|
5
|
+
export function normalizeUsageReport(value) {
|
|
6
|
+
if (!value || typeof value !== 'object')
|
|
7
|
+
return null;
|
|
8
|
+
const report = value;
|
|
9
|
+
if (!['qwen', 'stepfun', 'ark', 'deepseek', 'volcengine', 'openai', 'gemini', 'openrouter', 'custom', 'codex', 'acp'].includes(report.provider)
|
|
10
|
+
|| !['llm', 'realtime', 'asr', 'tts', 'embedding', 'agent'].includes(report.service)
|
|
9
11
|
|| typeof report.id !== 'string' || !report.id || report.id.length > 256
|
|
10
|
-
|| typeof report.model !== 'string' || !report.model || report.model.length > 256)
|
|
11
|
-
return;
|
|
12
|
+
|| typeof report.model !== 'string' || !report.model || report.model.length > 256 || !['complete', 'missing'].includes(report.status))
|
|
13
|
+
return null;
|
|
12
14
|
const counts = {};
|
|
13
15
|
let complete = report.status === 'complete';
|
|
14
16
|
for (const key of meters) {
|
|
@@ -20,18 +22,32 @@ export function reportUsage(reporter, report) {
|
|
|
20
22
|
else
|
|
21
23
|
counts[key] = value;
|
|
22
24
|
}
|
|
23
|
-
const required = report.service === 'asr' ? ['audioDurationMs']
|
|
25
|
+
const required = report.service === 'embedding' ? ['inputTokens'] : report.service === 'asr' ? ['audioDurationMs']
|
|
24
26
|
: report.service === 'tts' ? ['characters'] : ['inputTokens', 'outputTokens'];
|
|
25
27
|
if (required.some(key => counts[key] === undefined))
|
|
26
28
|
complete = false;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
return Object.freeze({ id: report.id, service: report.service, provider: report.provider, model: report.model,
|
|
30
|
+
status: complete ? 'complete' : 'missing', ...counts, ...safeUsageContext(report),
|
|
31
|
+
...(['cn-beijing', 'singapore', 'unknown'].includes(report.pricingRegion) ? { pricingRegion: report.pricingRegion } : {}),
|
|
32
|
+
...(['audio', 'text'].includes(report.outputModality) ? { outputModality: report.outputModality } : {}),
|
|
33
|
+
...(typeof report.timestamp === 'string' && Number.isFinite(Date.parse(report.timestamp)) ? { timestamp: new Date(report.timestamp).toISOString() } : {}),
|
|
34
|
+
...(['success', 'error', 'cancelled'].includes(report.outcome) ? { outcome: report.outcome } : {}),
|
|
35
|
+
...(typeof report.providerRequestId === 'string' && /^[\w.:/-]{1,256}$/u.test(report.providerRequestId) ? { providerRequestId: report.providerRequestId } : {}),
|
|
36
|
+
...(['enabled', 'disabled'].includes(report.reasoningMode) ? { reasoningMode: report.reasoningMode } : {}),
|
|
37
|
+
...(report.provider === 'openrouter' && typeof report.reportedCostUsd === 'number' && Number.isFinite(report.reportedCostUsd) && report.reportedCostUsd >= 0 ? { reportedCostUsd: report.reportedCostUsd } : {}), });
|
|
38
|
+
}
|
|
39
|
+
export function reportUsage(reporter, report) {
|
|
40
|
+
if (!reporter)
|
|
41
|
+
return;
|
|
42
|
+
const value = normalizeUsageReport(report);
|
|
43
|
+
if (value)
|
|
44
|
+
try {
|
|
45
|
+
reporter(value);
|
|
46
|
+
}
|
|
47
|
+
catch { /* Observability never changes generation or cancellation. */ }
|
|
48
|
+
}
|
|
49
|
+
export function bindUsageReporter(reporter, context) {
|
|
50
|
+
return reporter ? report => reportUsage(reporter, { ...context, ...report, feature: report.feature && report.feature !== 'other' ? report.feature : context.feature ?? 'other' }) : undefined;
|
|
35
51
|
}
|
|
36
52
|
/** Pricing is tied to the selected host endpoint, never inferred from a model name alone. */
|
|
37
53
|
export function usageReporterForEndpoint(reporter, endpoint) {
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import { selfHostedEndpoint } from '../../config/self-hosted.js';
|
|
2
|
+
import { abortable } from '../../core/camera-session.js';
|
|
1
3
|
import { translateSystemPrompt } from '../prompt-language.js';
|
|
2
4
|
import { randomUUID } from 'node:crypto';
|
|
3
5
|
import { reportUsage } from '../usage.js';
|
|
4
6
|
import { jsonValueSchema } from '../../core/events.js';
|
|
5
7
|
import { codePointLengthLikePython, stripLikePython } from '../../text/python-text.js';
|
|
6
8
|
import { MAX_REALTIME_TEXT } from '../protocol.js';
|
|
9
|
+
import { llmStreamLimits, llmToolCallLimit } from '../cascaded/llm-stream-limits.js';
|
|
10
|
+
import { rotatedCredential } from '../../config/credential-rotation.js';
|
|
7
11
|
export const MAX_ARK_REQUEST_BYTES = 4 * 1_024 * 1_024;
|
|
8
12
|
export const MAX_ARK_SSE_LINE_BYTES = 256 * 1_024;
|
|
9
13
|
export const MAX_ARK_SSE_EVENT_BYTES = 512 * 1_024;
|
|
@@ -74,7 +78,7 @@ async function boundedWait(promise, active, timeoutMs) {
|
|
|
74
78
|
reject(new ArkResponsesFailure('timeout'));
|
|
75
79
|
}, timeoutMs);
|
|
76
80
|
});
|
|
77
|
-
const value = await Promise.race([promise, timed]);
|
|
81
|
+
const value = await abortable(Promise.race([promise, timed]), active.controller.signal);
|
|
78
82
|
if (active.failureCode !== null)
|
|
79
83
|
throw new ArkResponsesFailure(active.failureCode);
|
|
80
84
|
return value;
|
|
@@ -156,6 +160,7 @@ function normalizeProviderEvent(value) {
|
|
|
156
160
|
return null;
|
|
157
161
|
}
|
|
158
162
|
class FetchArkResponsesGateway {
|
|
163
|
+
#compatible;
|
|
159
164
|
#onUsage;
|
|
160
165
|
#endpoint;
|
|
161
166
|
#apiKey;
|
|
@@ -163,13 +168,23 @@ class FetchArkResponsesGateway {
|
|
|
163
168
|
#instructions;
|
|
164
169
|
#fetch;
|
|
165
170
|
#idleTimeoutMs;
|
|
171
|
+
#streamLimits;
|
|
172
|
+
#toolCallLimit;
|
|
166
173
|
#closeTimeoutMs;
|
|
167
174
|
#active = new Set();
|
|
168
175
|
#closed = false;
|
|
169
176
|
#closePromise = null;
|
|
170
177
|
constructor(options) {
|
|
178
|
+
try {
|
|
179
|
+
this.#streamLimits = llmStreamLimits(options);
|
|
180
|
+
this.#toolCallLimit = llmToolCallLimit(options);
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
throw new ArkResponsesFailure('configuration');
|
|
184
|
+
}
|
|
185
|
+
this.#compatible = options.protocol === 'openai-compatible';
|
|
171
186
|
this.#onUsage = options.onUsage;
|
|
172
|
-
this.#endpoint = resolveResponsesEndpoint(options.baseUrl);
|
|
187
|
+
this.#endpoint = resolveResponsesEndpoint(this.#compatible ? selfHostedEndpoint(options.baseUrl, 'http', 'OPENAI_COMPATIBLE_BASE_URL') : options.baseUrl);
|
|
173
188
|
this.#apiKey = options.apiKey;
|
|
174
189
|
this.#model = options.model;
|
|
175
190
|
this.#instructions = options.instructions;
|
|
@@ -198,11 +213,13 @@ class FetchArkResponsesGateway {
|
|
|
198
213
|
.join('\n\n'),
|
|
199
214
|
input: inputItems,
|
|
200
215
|
tools,
|
|
201
|
-
parallel_tool_calls:
|
|
202
|
-
store:
|
|
216
|
+
parallel_tool_calls: this.#toolCallLimit > 1,
|
|
217
|
+
store: !this.#compatible,
|
|
203
218
|
stream: true,
|
|
204
|
-
thinking: { type: 'disabled' },
|
|
205
|
-
...(input.
|
|
219
|
+
...(this.#compatible ? { include: ['reasoning.encrypted_content'] } : { thinking: { type: 'disabled' } }),
|
|
220
|
+
...(input.textFormat ? { text: { format: input.textFormat } } : {}),
|
|
221
|
+
...(input.maxOutputTokens === undefined ? {} : { max_output_tokens: input.maxOutputTokens }),
|
|
222
|
+
...(this.#compatible || input.previousResponseId === null
|
|
206
223
|
? {}
|
|
207
224
|
: { previous_response_id: input.previousResponseId }),
|
|
208
225
|
});
|
|
@@ -227,8 +244,9 @@ class FetchArkResponsesGateway {
|
|
|
227
244
|
try {
|
|
228
245
|
response = await boundedWait(this.#fetch(this.#endpoint, {
|
|
229
246
|
method: 'POST',
|
|
247
|
+
...(this.#compatible ? { redirect: 'error' } : {}),
|
|
230
248
|
headers: {
|
|
231
|
-
authorization: `Bearer ${this.#apiKey}`,
|
|
249
|
+
authorization: `Bearer ${rotatedCredential(this.#apiKey)}`,
|
|
232
250
|
'content-type': 'application/json',
|
|
233
251
|
accept: 'text/event-stream',
|
|
234
252
|
},
|
|
@@ -266,7 +284,7 @@ class FetchArkResponsesGateway {
|
|
|
266
284
|
if (lineBytes.byteLength > 0 && lineBytes[lineBytes.byteLength - 1] === 13) {
|
|
267
285
|
lineBytes = lineBytes.subarray(0, lineBytes.byteLength - 1);
|
|
268
286
|
}
|
|
269
|
-
if (lineBytes.byteLength >
|
|
287
|
+
if (lineBytes.byteLength > this.#streamLimits.lineBytes) {
|
|
270
288
|
throw new ArkResponsesFailure('overflow');
|
|
271
289
|
}
|
|
272
290
|
let line;
|
|
@@ -287,7 +305,7 @@ class FetchArkResponsesGateway {
|
|
|
287
305
|
if (field === 'data') {
|
|
288
306
|
const encoded = new TextEncoder().encode(fieldValue);
|
|
289
307
|
dataBytes += encoded.byteLength + (dataLines.length === 0 ? 0 : 1);
|
|
290
|
-
if (dataBytes >
|
|
308
|
+
if (dataBytes > this.#streamLimits.eventBytes) {
|
|
291
309
|
throw new ArkResponsesFailure('overflow');
|
|
292
310
|
}
|
|
293
311
|
dataLines.push(fieldValue);
|
|
@@ -297,7 +315,7 @@ class FetchArkResponsesGateway {
|
|
|
297
315
|
if (dataLines.length === 0)
|
|
298
316
|
return null;
|
|
299
317
|
dispatchedEvents += 1;
|
|
300
|
-
if (dispatchedEvents >
|
|
318
|
+
if (dispatchedEvents > this.#streamLimits.events)
|
|
301
319
|
throw new ArkResponsesFailure('overflow');
|
|
302
320
|
const data = dataLines.join('\n');
|
|
303
321
|
dataLines = [];
|
|
@@ -311,14 +329,21 @@ class FetchArkResponsesGateway {
|
|
|
311
329
|
}
|
|
312
330
|
if (!isJsonObject(parsed))
|
|
313
331
|
throw new ArkResponsesFailure('protocol');
|
|
314
|
-
|
|
332
|
+
let event = normalizeProviderEvent(parsed);
|
|
333
|
+
if (event?.kind === 'response_completed') {
|
|
334
|
+
const output = isJsonObject(parsed.response) ? parsed.response.output : undefined;
|
|
335
|
+
if (Array.isArray(output) && output.every(isJsonObject))
|
|
336
|
+
event = { ...event, outputItems: copyJsonObjects(output) };
|
|
337
|
+
else if (this.#compatible)
|
|
338
|
+
throw new ArkResponsesFailure('protocol');
|
|
339
|
+
}
|
|
315
340
|
if (event?.kind === 'response_completed' || event?.kind === 'response_failed') {
|
|
316
341
|
const response = isJsonObject(parsed.response) ? parsed.response : {};
|
|
317
342
|
const usage = event.kind === 'response_completed' && isJsonObject(response.usage) ? response.usage : undefined;
|
|
318
343
|
const details = isJsonObject(usage?.input_tokens_details) ? usage.input_tokens_details : {};
|
|
319
344
|
const outputDetails = isJsonObject(usage?.output_tokens_details) ? usage.output_tokens_details : {};
|
|
320
345
|
reportUsage(this.#onUsage, {
|
|
321
|
-
id: usageId, service: 'llm', provider: 'ark', model: this.#model,
|
|
346
|
+
id: usageId, service: 'llm', provider: this.#compatible ? 'custom' : 'ark', model: this.#model,
|
|
322
347
|
status: usage === undefined ? 'missing' : 'complete',
|
|
323
348
|
...(usage === undefined ? {} : { inputTokens: usage.input_tokens, outputTokens: usage.output_tokens,
|
|
324
349
|
cachedTokens: details.cached_tokens, reasoningTokens: outputDetails.reasoning_tokens }),
|
|
@@ -359,7 +384,7 @@ class FetchArkResponsesGateway {
|
|
|
359
384
|
}
|
|
360
385
|
const chunk = copyReadableChunk(result.value);
|
|
361
386
|
aggregateBytes += chunk.byteLength;
|
|
362
|
-
if (aggregateBytes >
|
|
387
|
+
if (aggregateBytes > this.#streamLimits.responseBytes)
|
|
363
388
|
throw new ArkResponsesFailure('overflow');
|
|
364
389
|
buffered = concatBytes(buffered, chunk);
|
|
365
390
|
let newline = buffered.indexOf(10);
|
|
@@ -374,7 +399,7 @@ class FetchArkResponsesGateway {
|
|
|
374
399
|
}
|
|
375
400
|
newline = buffered.indexOf(10);
|
|
376
401
|
}
|
|
377
|
-
if (buffered.byteLength >
|
|
402
|
+
if (buffered.byteLength > this.#streamLimits.lineBytes) {
|
|
378
403
|
throw new ArkResponsesFailure('overflow');
|
|
379
404
|
}
|
|
380
405
|
}
|
|
@@ -389,7 +414,7 @@ class FetchArkResponsesGateway {
|
|
|
389
414
|
finally {
|
|
390
415
|
if (!usageReported)
|
|
391
416
|
reportUsage(this.#onUsage, {
|
|
392
|
-
id: usageId, service: 'llm', provider: 'ark', model: this.#model, status: 'missing',
|
|
417
|
+
id: usageId, service: 'llm', provider: this.#compatible ? 'custom' : 'ark', model: this.#model, status: 'missing',
|
|
393
418
|
});
|
|
394
419
|
input.signal?.removeEventListener('abort', onCallerAbort);
|
|
395
420
|
try {
|
|
@@ -6,6 +6,7 @@ import { isWellFormed, stripLikePython } from '../../text/python-text.js';
|
|
|
6
6
|
import { MAX_REALTIME_PCM_BYTES } from '../protocol.js';
|
|
7
7
|
import { MAX_VOLCENGINE_WIRE_FRAME_BYTES, pcm16BytesForDuration, volcengineInputPcm, } from './audio.js';
|
|
8
8
|
import { DEFAULT_VOLC_CLOSE_TIMEOUT_MS, DEFAULT_VOLC_CONNECT_TIMEOUT_MS, DEFAULT_VOLC_RECEIVE_TIMEOUT_MS, webSocketVolcBinaryConnector, } from './websocket.js';
|
|
9
|
+
import { rotatedCredential } from '../../config/credential-rotation.js';
|
|
9
10
|
export const MAX_VOLCENGINE_JSON_BYTES = 1_024 * 1_024;
|
|
10
11
|
export class DoubaoAsrError extends Error {
|
|
11
12
|
constructor(message) {
|
|
@@ -143,7 +144,7 @@ export function asrHeaders(input) {
|
|
|
143
144
|
throw new DoubaoAsrFailure('configuration');
|
|
144
145
|
}
|
|
145
146
|
return Object.freeze({
|
|
146
|
-
'X-Api-Key': input.apiKey,
|
|
147
|
+
'X-Api-Key': rotatedCredential(input.apiKey),
|
|
147
148
|
'X-Api-Resource-Id': input.resourceId,
|
|
148
149
|
'X-Api-Connect-Id': connectId,
|
|
149
150
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ConfigurationError } from '../../config/config.js';
|
|
2
2
|
import { volcengineInputPcm } from './audio.js';
|
|
3
|
+
import { throwIfAborted } from '../../core/guards.js';
|
|
3
4
|
const SAMPLE_RATE = 16_000;
|
|
4
5
|
const BYTES_PER_SAMPLE = 2;
|
|
5
6
|
const WINDOW_SAMPLES = 512;
|
|
@@ -227,11 +228,4 @@ function joinBytes(parts) {
|
|
|
227
228
|
}
|
|
228
229
|
return result;
|
|
229
230
|
}
|
|
230
|
-
function throwIfAborted(signal) {
|
|
231
|
-
if (!signal.aborted)
|
|
232
|
-
return;
|
|
233
|
-
if (signal.reason instanceof Error)
|
|
234
|
-
throw signal.reason;
|
|
235
|
-
throw new DOMException('This operation was aborted', 'AbortError');
|
|
236
|
-
}
|
|
237
231
|
//# sourceMappingURL=silence-endpointing.js.map
|
|
@@ -5,6 +5,7 @@ import { MAX_REALTIME_TEXT } from '../protocol.js';
|
|
|
5
5
|
import { MAX_VOLCENGINE_WIRE_FRAME_BYTES, volcengineOutputPcm } from './audio.js';
|
|
6
6
|
import { EventType, MessageType, VolcMessage } from './protocol.js';
|
|
7
7
|
import { DEFAULT_VOLC_CLOSE_TIMEOUT_MS, DEFAULT_VOLC_CONNECT_TIMEOUT_MS, DEFAULT_VOLC_RECEIVE_TIMEOUT_MS, webSocketVolcBinaryConnector, } from './websocket.js';
|
|
8
|
+
import { rotatedCredential } from '../../config/credential-rotation.js';
|
|
8
9
|
const boundaries = new Set([...`,。!?;:,.!?;:\n`]);
|
|
9
10
|
export class TextChunker {
|
|
10
11
|
#softLimit;
|
|
@@ -83,7 +84,7 @@ export function ttsHeaders(input) {
|
|
|
83
84
|
throw new DoubaoTtsFailure('configuration');
|
|
84
85
|
}
|
|
85
86
|
return Object.freeze({
|
|
86
|
-
'X-Api-Key': input.apiKey,
|
|
87
|
+
'X-Api-Key': rotatedCredential(input.apiKey),
|
|
87
88
|
'X-Api-Resource-Id': input.resourceId,
|
|
88
89
|
'X-Api-Connect-Id': connectId,
|
|
89
90
|
});
|
|
@@ -471,7 +471,7 @@ export class AoqChatServer {
|
|
|
471
471
|
const frame = { type: 'aoq.credentials', connection_id: c.id, request_id: requestId, credentials,
|
|
472
472
|
...(this.#options.runtime ? { mode: 'runtime' } : { session: { modalities: ['text', 'audio'], voice: this.#options.voice ?? 'longanqian',
|
|
473
473
|
input_audio_format: 'pcm', output_audio_format: 'pcm',
|
|
474
|
-
instructions: translateSystemPrompt('你是Nova
|
|
474
|
+
instructions: translateSystemPrompt('你是Nova,一个自然、友好的语音聊天助手。仅进行纯聊天,不执行工具,不操作文件、终端、项目或设备,也不声称已执行这些操作。', c.language ?? this.#options.language),
|
|
475
475
|
turn_detection: { type: 'smart_turn' } } }) };
|
|
476
476
|
if (Buffer.byteLength(JSON.stringify(frame)) >= MAX_JSON_BYTES) {
|
|
477
477
|
this.#unavailable(c);
|
|
@@ -14,6 +14,12 @@ const MOBILE_METHODS = new Set([...SCHEDULE_METHODS, 'state', 'life.mutate', 'fe
|
|
|
14
14
|
function mobileSnapshot(value) {
|
|
15
15
|
const keys = ['type', 'revision', 'reload_required', 'life', 'schedules', 'tasks', 'conversations', 'feed', 'memory', 'pending_approvals', 'pending_confirmations'];
|
|
16
16
|
const result = Object.fromEntries(keys.filter(key => key in value).map(key => [key, value[key]]));
|
|
17
|
+
if (value.conversations && typeof value.conversations === 'object') {
|
|
18
|
+
const conversations = value.conversations, items = Array.isArray(conversations.items) ? conversations.items : [], visible = items.filter(item => item.kind !== 'build'), ids = new Set(visible.map(item => item.id));
|
|
19
|
+
result.conversations = { ...conversations, items: visible.map(item => Object.fromEntries(Object.entries(item).filter(([key]) => !['build', 'plan', 'mode'].includes(key)))), selected_id: ids.has(conversations.selected_id) ? conversations.selected_id : 'chat:main', messages: (Array.isArray(conversations.messages) ? conversations.messages : []).filter(message => ids.has(message.conversation_id)), home_messages: (Array.isArray(conversations.home_messages) ? conversations.home_messages : []).filter(message => ids.has(message.conversation_id)) };
|
|
20
|
+
}
|
|
21
|
+
if (Array.isArray(value.tasks))
|
|
22
|
+
result.tasks = value.tasks.map((task) => Object.fromEntries(Object.entries(task).filter(([key]) => key !== 'approved_plan')));
|
|
17
23
|
// Mobile displays the same ranked/saved articles without source configuration.
|
|
18
24
|
if (value.news && typeof value.news === 'object' && !Array.isArray(value.news)) {
|
|
19
25
|
const news = value.news;
|
|
@@ -123,6 +129,8 @@ export class ClientServer {
|
|
|
123
129
|
const value = JSON.parse(raw);
|
|
124
130
|
if (!value || typeof value.type !== 'string')
|
|
125
131
|
throw new DesktopProtocolError('invalid client output');
|
|
132
|
+
if (value.local_build === true)
|
|
133
|
+
return;
|
|
126
134
|
if (this.#options.sharedWorkbench && !connection.personal && (value.type.startsWith('personal.') || value.type.startsWith('conversation.')))
|
|
127
135
|
return;
|
|
128
136
|
if (this.#options.sharedWorkbench && !connection.personal && value.type === 'caption' && value.conversation_id !== connection.legacyConversationId)
|
|
@@ -140,6 +148,19 @@ export class ClientServer {
|
|
|
140
148
|
connection.snapshot = undefined;
|
|
141
149
|
}
|
|
142
150
|
}
|
|
151
|
+
if (frame.data && typeof frame.data === 'object') {
|
|
152
|
+
const publicData = (input) => {
|
|
153
|
+
if (Array.isArray(input))
|
|
154
|
+
return input.filter(item => !(item && typeof item === 'object' && item.kind === 'build')).map(publicData);
|
|
155
|
+
if (!input || typeof input !== 'object')
|
|
156
|
+
return input;
|
|
157
|
+
const item = input;
|
|
158
|
+
if (Array.isArray(item.items) && typeof item.selected_id === 'string')
|
|
159
|
+
return mobileSnapshot({ conversations: item }).conversations;
|
|
160
|
+
return Object.fromEntries(Object.entries(item).filter(([key]) => !['approved_plan', 'plan', 'build', 'local_tool_approval'].includes(key)).map(([key, value]) => [key, publicData(value)]));
|
|
161
|
+
};
|
|
162
|
+
frame.data = publicData(frame.data);
|
|
163
|
+
}
|
|
143
164
|
raw = JSON.stringify(frame);
|
|
144
165
|
if (Buffer.byteLength(raw) > MAX_PERSONAL_BYTES) {
|
|
145
166
|
raw = JSON.stringify(value.type === 'personal.state'
|
|
@@ -57,6 +57,7 @@ export async function runServerEntry(options = {}) {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
const { runDesktopEntry } = await import('./desktop/desktop-session.js');
|
|
60
|
+
const { describeStartupError } = await import('./desktop/startup-error.js');
|
|
60
61
|
const aoq = config.mediaMode === 'aoq_runtime';
|
|
61
62
|
const environment = options.environment ?? process.env;
|
|
62
63
|
const aoqModule = aoq ? await import('./server/aoq-chat-server.js') : undefined;
|
|
@@ -74,6 +75,8 @@ export async function runServerEntry(options = {}) {
|
|
|
74
75
|
}
|
|
75
76
|
return await runDesktopEntry({
|
|
76
77
|
token: config.token, stop, onDiagnostic, listenBeforeRealtime: aoq,
|
|
78
|
+
// The failure code alone does not say which file or setting to fix; desktop prints the same redacted line.
|
|
79
|
+
onStartupFailure: error => { onDiagnostic(`[runtime-startup-error] ${describeStartupError(error)}`); },
|
|
77
80
|
announce: (_endpoint, readiness) => {
|
|
78
81
|
onDiagnostic(`[server-ready] ws://${readiness.host}:${readiness.port}/client/v1`);
|
|
79
82
|
return Promise.resolve();
|