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,8 +1,10 @@
|
|
|
1
1
|
import { committedConversationPairsSchema } from '../history.js';
|
|
2
2
|
import { cascadedNarrationInstructions } from './llm.js';
|
|
3
|
-
import { originalImageUrl, MAX_CASCADED_LLM_HISTORY_ITEMS, MAX_CASCADED_LLM_HISTORY_CODEPOINTS } from './llm.js';
|
|
3
|
+
import { modelOutputTokens, originalImageUrl, toolObservations, trimToolImages, imageFreeMessage, MAX_CASCADED_LLM_HISTORY_ITEMS, MAX_CASCADED_LLM_HISTORY_CODEPOINTS } from './llm.js';
|
|
4
|
+
import { llmToolCallLimit } from './llm-stream-limits.js';
|
|
4
5
|
import { jsonValueSchema } from '../../core/events.js';
|
|
5
6
|
import { codePointLengthLikePython, stripLikePython } from '../../text/python-text.js';
|
|
7
|
+
import { canonicalJson } from '../../text/canonical-json.js';
|
|
6
8
|
import { MAX_REALTIME_TEXT } from '../protocol.js';
|
|
7
9
|
import { ArkResponsesFailure, createFetchArkResponsesGateway, } from '../volcengine/ark.js';
|
|
8
10
|
export class ArkCascadedLlmFailure extends Error {
|
|
@@ -65,6 +67,51 @@ function toolSchema(tool) {
|
|
|
65
67
|
});
|
|
66
68
|
}
|
|
67
69
|
class Session {
|
|
70
|
+
#historyLimits = { items: MAX_CASCADED_LLM_HISTORY_ITEMS, codepoints: MAX_CASCADED_LLM_HISTORY_CODEPOINTS };
|
|
71
|
+
setHistoryLimits(limits) { if (this.#started || limits.items < 1 || limits.items > 2048 || limits.codepoints < 1 || limits.codepoints > 32 * 1024 * 1024)
|
|
72
|
+
throw fail('configuration'); this.#historyLimits = { ...limits }; }
|
|
73
|
+
#portable = false;
|
|
74
|
+
checkpoint() {
|
|
75
|
+
this.#portable = true;
|
|
76
|
+
return structuredClone({ protocol: 'responses', history: this.#history, pending: this.#turnItems, pending_call_ids: this.#pendingCallIds });
|
|
77
|
+
}
|
|
78
|
+
restoreCheckpoint(checkpoint) {
|
|
79
|
+
if (this.#started || this.#seeded || this.#closed || !checkpoint || typeof checkpoint !== 'object' || Array.isArray(checkpoint) || checkpoint.protocol !== 'responses' || !Array.isArray(checkpoint.history) || !Array.isArray(checkpoint.pending))
|
|
80
|
+
throw fail('protocol');
|
|
81
|
+
// Read the earlier single-call journal format without discarding any tool result.
|
|
82
|
+
const pendingIds = checkpoint.pending_call_ids ?? (checkpoint.pending_call_id === null ? [] : [checkpoint.pending_call_id]);
|
|
83
|
+
if (!Array.isArray(pendingIds) || pendingIds.length > this.#toolCallLimit || !pendingIds.every(validIdentifier) || new Set(pendingIds).size !== pendingIds.length)
|
|
84
|
+
throw fail('protocol');
|
|
85
|
+
const objectItem = (item) => !!item && typeof item === 'object' && !Array.isArray(item);
|
|
86
|
+
if (!checkpoint.history.every(unit => Array.isArray(unit) && unit.every(objectItem)) || !checkpoint.pending.every(objectItem))
|
|
87
|
+
throw fail('protocol');
|
|
88
|
+
for (const unit of [...checkpoint.history, checkpoint.pending]) {
|
|
89
|
+
const outstanding = new Set();
|
|
90
|
+
for (const value of unit) {
|
|
91
|
+
if (value.type === 'function_call') {
|
|
92
|
+
if (!validIdentifier(value.call_id) || !validIdentifier(value.name) || typeof value.arguments !== 'string' || outstanding.has(value.call_id) || outstanding.size >= this.#toolCallLimit)
|
|
93
|
+
throw fail('protocol');
|
|
94
|
+
outstanding.add(value.call_id);
|
|
95
|
+
}
|
|
96
|
+
else if (value.type === 'function_call_output' && (typeof value.call_id !== 'string' || !outstanding.delete(value.call_id) || typeof value.output !== 'string'))
|
|
97
|
+
throw fail('protocol');
|
|
98
|
+
}
|
|
99
|
+
if (unit === checkpoint.pending) {
|
|
100
|
+
if (outstanding.size !== pendingIds.length || pendingIds.some(id => !outstanding.has(id)))
|
|
101
|
+
throw fail('protocol');
|
|
102
|
+
}
|
|
103
|
+
else if (outstanding.size)
|
|
104
|
+
throw fail('protocol');
|
|
105
|
+
}
|
|
106
|
+
this.#history = structuredClone(checkpoint.history);
|
|
107
|
+
this.#turnItems = structuredClone(checkpoint.pending);
|
|
108
|
+
this.#pendingCallIds = [...pendingIds];
|
|
109
|
+
this.#pendingToolContinuation = this.#pendingCallIds.length > 0;
|
|
110
|
+
this.#previousResponseId = null;
|
|
111
|
+
this.#portable = true;
|
|
112
|
+
this.#seeded = true;
|
|
113
|
+
trimToolImages([...this.#history.flat(), ...this.#turnItems]);
|
|
114
|
+
}
|
|
68
115
|
#gateway;
|
|
69
116
|
#started = false;
|
|
70
117
|
#seeded = false;
|
|
@@ -72,9 +119,14 @@ class Session {
|
|
|
72
119
|
#pendingToolContinuation = false;
|
|
73
120
|
#closed = false;
|
|
74
121
|
#visualHistory = false;
|
|
122
|
+
#pendingCallIds = [];
|
|
123
|
+
#toolCallLimit;
|
|
124
|
+
#stateless;
|
|
75
125
|
#history = [];
|
|
76
126
|
#turnItems = [];
|
|
77
|
-
constructor(gateway, history) {
|
|
127
|
+
constructor(gateway, history, stateless = false, toolCallLimit = 1) {
|
|
128
|
+
this.#stateless = stateless;
|
|
129
|
+
this.#toolCallLimit = toolCallLimit;
|
|
78
130
|
this.#gateway = gateway;
|
|
79
131
|
if (history !== undefined)
|
|
80
132
|
this.#seed(history);
|
|
@@ -102,27 +154,42 @@ class Session {
|
|
|
102
154
|
if (input.signal.aborted)
|
|
103
155
|
throw fail('aborted');
|
|
104
156
|
this.#started = true;
|
|
105
|
-
|
|
157
|
+
if (this.#stateless || this.#portable) {
|
|
158
|
+
const results = input.inputs.filter(item => item.kind === 'tool_result');
|
|
159
|
+
const expected = [...this.#pendingCallIds].sort(), actual = results.map(result => result.call_id).sort();
|
|
160
|
+
if (expected.length !== actual.length || expected.some((id, index) => id !== actual[index]) || input.inputs.slice(0, actual.length).some(item => item.kind !== 'tool_result'))
|
|
161
|
+
throw fail('protocol');
|
|
162
|
+
}
|
|
163
|
+
const current = inputItems(input.inputs);
|
|
106
164
|
const factOnly = input.inputs.some(item => item.kind === 'host_activation');
|
|
107
165
|
if (input.inputs.some(item => item.kind === 'user_text' && item.image))
|
|
108
166
|
this.#visualHistory = true;
|
|
167
|
+
// Local replay is required to actually evict old screenshots from provider context.
|
|
109
168
|
const continuing = this.#pendingToolContinuation;
|
|
110
|
-
const localHistory = (this.#visualHistory || (this.#previousResponseId === null && this.#history.length > 0)) && !continuing;
|
|
169
|
+
const localHistory = this.#stateless || this.#portable || (this.#visualHistory || (this.#previousResponseId === null && this.#history.length > 0)) && !continuing;
|
|
170
|
+
if (input.inputs.some(item => item.kind === 'tool_result' && item.images?.length))
|
|
171
|
+
this.#portable = true;
|
|
111
172
|
if (!continuing)
|
|
112
173
|
this.#turnItems = [];
|
|
113
|
-
this.#turnItems.push(...input.inputs.map(item => item.kind === 'user_text' ? {
|
|
174
|
+
this.#turnItems.push(...inputItems(input.inputs.map(item => item.kind === 'user_text' ? { kind: 'user_text', text: item.text } : item)));
|
|
175
|
+
trimToolImages([...this.#history.flat(), ...this.#turnItems]);
|
|
176
|
+
trimToolImages([...this.#history.flat(), ...current]);
|
|
177
|
+
if ((this.#stateless || this.#portable) && (this.#turnItems.length > this.#historyLimits.items || codePointLengthLikePython(JSON.stringify(this.#turnItems.map(imageFreeMessage))) > this.#historyLimits.codepoints))
|
|
178
|
+
throw fail('overflow');
|
|
114
179
|
let outputText = '';
|
|
180
|
+
let authorityText = '';
|
|
115
181
|
let responseId = null;
|
|
116
182
|
let terminal = false;
|
|
117
|
-
|
|
118
|
-
|
|
183
|
+
const pendingTools = [];
|
|
184
|
+
const toolsEnabled = input.tools.length > 0;
|
|
119
185
|
try {
|
|
120
186
|
for await (const event of this.#gateway.stream({
|
|
121
187
|
...(input.language === undefined ? {} : { language: input.language }),
|
|
122
|
-
inputItems: factOnly ? input.inputs.filter(item => item.kind === 'host_activation' || item.kind === 'tool_result')
|
|
123
|
-
: localHistory ? [...this.#history.flat(), ...current] : current,
|
|
188
|
+
inputItems: factOnly ? inputItems(input.inputs.filter(item => item.kind === 'host_activation' || item.kind === 'tool_result'))
|
|
189
|
+
: localHistory ? [...this.#history.flat(), ...((this.#stateless || this.#portable) && continuing ? this.#turnItems : current)] : current,
|
|
124
190
|
tools: input.tools.map(toolSchema),
|
|
125
191
|
previousResponseId: localHistory || (factOnly && !continuing) ? null : this.#previousResponseId,
|
|
192
|
+
maxOutputTokens: modelOutputTokens('ark'),
|
|
126
193
|
workspaceContext: factOnly ? null : input.workspaceContext ?? null,
|
|
127
194
|
responseAdaptation: factOnly ? cascadedNarrationInstructions(input.language) : input.responseAdaptation ?? null,
|
|
128
195
|
signal: input.signal,
|
|
@@ -136,43 +203,93 @@ class Session {
|
|
|
136
203
|
else if (event.kind === 'text_delta') {
|
|
137
204
|
if (responseId === null)
|
|
138
205
|
throw fail('protocol');
|
|
139
|
-
if (
|
|
206
|
+
if (pendingTools.length && !this.#stateless && !this.#portable)
|
|
140
207
|
throw fail('protocol');
|
|
141
|
-
textSeen = true;
|
|
142
208
|
outputText += event.text;
|
|
143
|
-
|
|
209
|
+
if (!toolsEnabled) {
|
|
210
|
+
// No tool can follow, so the text is final and may be spoken immediately.
|
|
211
|
+
yield event;
|
|
212
|
+
}
|
|
213
|
+
else if (input.previewText === true) {
|
|
214
|
+
// Text-mode UI can show and retract speculative text without speaking it.
|
|
215
|
+
yield { kind: 'text_preview', text: event.text };
|
|
216
|
+
authorityText += event.text;
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
// Tools are enabled: whether this is narration or the final reply is unknown until the
|
|
220
|
+
// response completes, so never hand it to TTS before that decision.
|
|
221
|
+
authorityText += event.text;
|
|
222
|
+
}
|
|
144
223
|
}
|
|
145
224
|
else if (event.kind === 'tool_call') {
|
|
146
|
-
if (responseId === null ||
|
|
225
|
+
if (responseId === null || pendingTools.length >= this.#toolCallLimit || pendingTools.some(call => call.call_id === event.call_id))
|
|
147
226
|
throw fail('protocol');
|
|
148
|
-
|
|
227
|
+
pendingTools.push(structuredClone(event));
|
|
149
228
|
}
|
|
150
229
|
else if (event.kind === 'response_completed') {
|
|
151
230
|
if (responseId === null || event.response_id !== responseId)
|
|
152
231
|
throw fail('protocol');
|
|
232
|
+
const portableOutput = (this.#stateless || this.#portable) && event.outputItems !== undefined;
|
|
233
|
+
if (portableOutput && pendingTools.length) {
|
|
234
|
+
const completed = event.outputItems.filter(item => item.type === 'function_call'), ordered = [];
|
|
235
|
+
for (const item of completed) {
|
|
236
|
+
const call = pendingTools.find(call => call.call_id === item.call_id);
|
|
237
|
+
if (!call || call.name !== item.name || typeof item.arguments !== 'string' || ordered.includes(call))
|
|
238
|
+
throw fail('protocol');
|
|
239
|
+
let args;
|
|
240
|
+
try {
|
|
241
|
+
args = JSON.parse(item.arguments);
|
|
242
|
+
}
|
|
243
|
+
catch {
|
|
244
|
+
throw fail('protocol');
|
|
245
|
+
}
|
|
246
|
+
if (!jsonObject(args) || canonicalJson(args) !== canonicalJson(call.arguments))
|
|
247
|
+
throw fail('protocol');
|
|
248
|
+
ordered.push(call);
|
|
249
|
+
}
|
|
250
|
+
if (ordered.length !== pendingTools.length)
|
|
251
|
+
throw fail('protocol');
|
|
252
|
+
pendingTools.splice(0, pendingTools.length, ...ordered);
|
|
253
|
+
}
|
|
153
254
|
terminal = true;
|
|
154
|
-
if (
|
|
155
|
-
this.#turnItems.push(
|
|
255
|
+
if (portableOutput)
|
|
256
|
+
this.#turnItems.push(...structuredClone(event.outputItems));
|
|
257
|
+
// Narration before a tool call is part of the user-visible text turn; voice keeps it
|
|
258
|
+
// withheld so it never reaches TTS before the tool decision is final.
|
|
259
|
+
if (pendingTools.length && authorityText !== '' && input.previewText === true)
|
|
260
|
+
yield { kind: 'text_delta', text: authorityText };
|
|
261
|
+
if (!pendingTools.length && authorityText !== '')
|
|
262
|
+
yield { kind: 'text_delta', text: authorityText };
|
|
263
|
+
for (const pendingTool of pendingTools) {
|
|
264
|
+
if (!portableOutput)
|
|
265
|
+
this.#turnItems.push({ type: 'function_call', call_id: pendingTool.call_id, name: pendingTool.name, arguments: JSON.stringify(pendingTool.arguments) });
|
|
156
266
|
yield pendingTool;
|
|
157
267
|
}
|
|
158
|
-
if (
|
|
159
|
-
this.#history.push([...this.#turnItems, { role: 'assistant', content: outputText }]);
|
|
268
|
+
if (!pendingTools.length) {
|
|
269
|
+
this.#history.push(portableOutput ? [...this.#turnItems] : [...this.#turnItems, { role: 'assistant', content: outputText }]);
|
|
160
270
|
this.#turnItems = [];
|
|
161
|
-
while (this.#history.length && (this.#history.flat().length >
|
|
271
|
+
while (this.#history.length && (this.#history.flat().length > this.#historyLimits.items || codePointLengthLikePython(JSON.stringify(this.#history.map(unit => unit.map(imageFreeMessage)))) > this.#historyLimits.codepoints))
|
|
162
272
|
this.#history.shift();
|
|
163
273
|
}
|
|
164
|
-
this.#previousResponseId = factOnly &&
|
|
165
|
-
this.#pendingToolContinuation =
|
|
166
|
-
|
|
274
|
+
this.#previousResponseId = factOnly && !pendingTools.length ? null : event.response_id;
|
|
275
|
+
this.#pendingToolContinuation = pendingTools.length > 0;
|
|
276
|
+
this.#pendingCallIds = pendingTools.map(call => call.call_id);
|
|
277
|
+
yield { kind: 'response_completed', response_id: event.response_id };
|
|
167
278
|
return;
|
|
168
279
|
}
|
|
169
280
|
else {
|
|
170
281
|
if (responseId !== null && event.response_id !== responseId)
|
|
171
282
|
throw fail('protocol');
|
|
283
|
+
const code = event.code === 'incomplete' ? 'output_limit' : event.code;
|
|
284
|
+
// An incomplete Responses turn is a provider output ceiling, not a protocol error.
|
|
285
|
+
// Release text held for the tool decision when the caller asked for display previews.
|
|
286
|
+
if (code === 'output_limit' && outputText !== '' && input.previewText === true && toolsEnabled)
|
|
287
|
+
yield { kind: 'text_delta', text: outputText };
|
|
172
288
|
this.#previousResponseId = null;
|
|
173
289
|
this.#pendingToolContinuation = false;
|
|
290
|
+
this.#pendingCallIds = [];
|
|
174
291
|
terminal = true;
|
|
175
|
-
yield event;
|
|
292
|
+
yield { ...event, code, ...(code === 'output_limit' ? { detail: 'length' } : {}) };
|
|
176
293
|
return;
|
|
177
294
|
}
|
|
178
295
|
}
|
|
@@ -186,6 +303,7 @@ class Session {
|
|
|
186
303
|
: fail(this.#closed ? 'closed' : input.signal.aborted ? 'aborted' : 'network');
|
|
187
304
|
this.#previousResponseId = null;
|
|
188
305
|
this.#pendingToolContinuation = false;
|
|
306
|
+
this.#pendingCallIds = [];
|
|
189
307
|
if (responseId !== null && !terminal) {
|
|
190
308
|
yield { kind: 'response_failed', response_id: responseId, code: stable.code };
|
|
191
309
|
return;
|
|
@@ -199,6 +317,7 @@ class Session {
|
|
|
199
317
|
if (this.#pendingToolContinuation)
|
|
200
318
|
this.#previousResponseId = null;
|
|
201
319
|
this.#pendingToolContinuation = false;
|
|
320
|
+
this.#pendingCallIds = [];
|
|
202
321
|
return Promise.resolve();
|
|
203
322
|
}
|
|
204
323
|
async close() {
|
|
@@ -207,6 +326,7 @@ class Session {
|
|
|
207
326
|
this.#turnItems = [];
|
|
208
327
|
this.#previousResponseId = null;
|
|
209
328
|
this.#pendingToolContinuation = false;
|
|
329
|
+
this.#pendingCallIds = [];
|
|
210
330
|
await this.#gateway.close();
|
|
211
331
|
}
|
|
212
332
|
}
|
|
@@ -214,6 +334,12 @@ export function createArkCascadedLlmSession(gateway) {
|
|
|
214
334
|
return new Session(gateway);
|
|
215
335
|
}
|
|
216
336
|
export function createArkCascadedLlmFactory(options) {
|
|
217
|
-
return { open: input => new Session(createFetchArkResponsesGateway(options), input?.history) };
|
|
337
|
+
return { open: input => new Session(createFetchArkResponsesGateway(options), input?.history, options.protocol === 'openai-compatible', llmToolCallLimit(options)) };
|
|
338
|
+
}
|
|
339
|
+
function inputItems(inputs) {
|
|
340
|
+
if (!inputs.some(input => input.kind === 'tool_result' && input.images?.length))
|
|
341
|
+
return inputs.map(inputItem);
|
|
342
|
+
const results = inputs.filter(input => input.kind === 'tool_result'), other = inputs.filter(input => input.kind !== 'tool_result');
|
|
343
|
+
return [...results.map(inputItem), ...toolObservations(results, true), ...other.map(inputItem)];
|
|
218
344
|
}
|
|
219
345
|
//# sourceMappingURL=ark-llm.js.map
|