nova-personal-agent-server 0.0.0-stage → 0.4.0
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 +201 -0
- package/README.md +30 -2
- package/bin/novapersonal-server.mjs +4 -0
- package/package.json +61 -4
- package/resources/endpointing/volcengine-v1/LICENSE.silero-vad.txt +21 -0
- package/resources/endpointing/volcengine-v1/MANIFEST.json +31 -0
- package/resources/endpointing/volcengine-v1/silence-16k-s16le.pcm +0 -0
- package/resources/endpointing/volcengine-v1/speech-16k-s16le.pcm +0 -0
- package/resources/native/codex-sandbox-probe +0 -0
- package/resources/native/project-native/nova_project_native.node +0 -0
- package/resources/native-resources-v1.json +1 -0
- package/runtime/dist/eval/demos.js +156 -0
- package/runtime/dist/eval/fixture-host.js +385 -0
- package/runtime/dist/eval/fixtures.js +319 -0
- package/runtime/dist/eval/realtime/session-fixtures.js +474 -0
- package/runtime/dist/eval/scorecard.js +285 -0
- package/runtime/dist/eval/sim.js +43 -0
- package/runtime/dist/src/cascaded-text-provider.js +31 -0
- package/runtime/dist/src/cli.js +96 -0
- package/runtime/dist/src/composition/assembly.js +352 -0
- package/runtime/dist/src/composition/cascaded-realtime-assembly.js +455 -0
- package/runtime/dist/src/composition/production-composition.js +389 -0
- package/runtime/dist/src/composition/realtime-assembly.js +1330 -0
- package/runtime/dist/src/config/capability-registry.js +315 -0
- package/runtime/dist/src/config/cascaded-realtime-config.js +146 -0
- package/runtime/dist/src/config/coding-backends.js +8 -0
- package/runtime/dist/src/config/coding-profiles.js +98 -0
- package/runtime/dist/src/config/config.js +857 -0
- package/runtime/dist/src/config/diagnostics.js +139 -0
- package/runtime/dist/src/config/environment-contract.js +202 -0
- package/runtime/dist/src/config/self-hosted.js +23 -0
- package/runtime/dist/src/connectors/composio/client.js +195 -0
- package/runtime/dist/src/connectors/composio/google.js +208 -0
- package/runtime/dist/src/connectors/composio/index.js +334 -0
- package/runtime/dist/src/connectors/feishu/cli.js +220 -0
- package/runtime/dist/src/connectors/feishu/index.js +980 -0
- package/runtime/dist/src/connectors/macos/calendar.js +35 -0
- package/runtime/dist/src/connectors/macos/mail.js +32 -0
- package/runtime/dist/src/connectors/macos/reader.js +62 -0
- package/runtime/dist/src/conversation-voice-provider.js +41 -0
- package/runtime/dist/src/core/approval-port.js +9 -0
- package/runtime/dist/src/core/approval.js +1328 -0
- package/runtime/dist/src/core/calls.js +35 -0
- package/runtime/dist/src/core/camera-session.js +32 -0
- package/runtime/dist/src/core/causal-runtime.js +650 -0
- package/runtime/dist/src/core/clock.js +139 -0
- package/runtime/dist/src/core/context-view.js +156 -0
- package/runtime/dist/src/core/effects.js +62 -0
- package/runtime/dist/src/core/events.js +217 -0
- package/runtime/dist/src/core/executor-diagnostic.js +9 -0
- package/runtime/dist/src/core/ids.js +32 -0
- package/runtime/dist/src/core/media-store.js +104 -0
- package/runtime/dist/src/core/memory.js +296 -0
- package/runtime/dist/src/core/pending-decision.js +64 -0
- package/runtime/dist/src/core/ports.js +125 -0
- package/runtime/dist/src/core/runtime.js +1459 -0
- package/runtime/dist/src/core/schedule-tools.js +15 -0
- package/runtime/dist/src/core/sims.js +186 -0
- package/runtime/dist/src/core/slots.js +97 -0
- package/runtime/dist/src/core/source-processing-instructions.js +3 -0
- package/runtime/dist/src/core/source-processing-tools.js +12 -0
- package/runtime/dist/src/core/suggestions.js +143 -0
- package/runtime/dist/src/core/task-tools.js +22 -0
- package/runtime/dist/src/core/tool-schema.js +212 -0
- package/runtime/dist/src/core/trace.js +34 -0
- package/runtime/dist/src/core/work-tools.js +94 -0
- package/runtime/dist/src/desktop/desktop-camera-source.js +31 -0
- package/runtime/dist/src/desktop/desktop-camera.js +281 -0
- package/runtime/dist/src/desktop/desktop-control.js +140 -0
- package/runtime/dist/src/desktop/desktop-progress.js +162 -0
- package/runtime/dist/src/desktop/desktop-session.js +2106 -0
- package/runtime/dist/src/desktop/desktop-tasks.js +80 -0
- package/runtime/dist/src/desktop/desktop-wire.js +605 -0
- package/runtime/dist/src/desktop/phone-desktop-entry.js +17 -0
- package/runtime/dist/src/desktop/startup-error.js +18 -0
- package/runtime/dist/src/desktop/workbench-acceptance.js +262 -0
- package/runtime/dist/src/desktop-entry.js +106 -0
- package/runtime/dist/src/desktop.js +1092 -0
- package/runtime/dist/src/executors/acp/backends.js +105 -0
- package/runtime/dist/src/executors/acp/mcp.js +81 -0
- package/runtime/dist/src/executors/acp/preflight.js +14 -0
- package/runtime/dist/src/executors/acp/process-owner.js +112 -0
- package/runtime/dist/src/executors/acp/transport.js +760 -0
- package/runtime/dist/src/executors/acp/windows-launch.js +68 -0
- package/runtime/dist/src/executors/agent-controller.js +244 -0
- package/runtime/dist/src/executors/autoglm.js +376 -0
- package/runtime/dist/src/executors/browser-device.js +102 -0
- package/runtime/dist/src/executors/browser.js +61 -0
- package/runtime/dist/src/executors/camera.js +101 -0
- package/runtime/dist/src/executors/chromium-frame-source.js +173 -0
- package/runtime/dist/src/executors/codex/adapter-live.js +292 -0
- package/runtime/dist/src/executors/codex/adapter-project.js +1306 -0
- package/runtime/dist/src/executors/codex/app-server-schema.js +712 -0
- package/runtime/dist/src/executors/codex/app-server-transport.js +1798 -0
- package/runtime/dist/src/executors/codex/approval-protocol.js +439 -0
- package/runtime/dist/src/executors/codex/common.js +655 -0
- package/runtime/dist/src/executors/codex/contract.js +581 -0
- package/runtime/dist/src/executors/codex/controller.js +141 -0
- package/runtime/dist/src/executors/codex/credential-snapshot.js +195 -0
- package/runtime/dist/src/executors/codex/factory.js +463 -0
- package/runtime/dist/src/executors/codex/host-config.js +238 -0
- package/runtime/dist/src/executors/codex/host.js +17 -0
- package/runtime/dist/src/executors/codex/index.js +19 -0
- package/runtime/dist/src/executors/codex/launch-profile.js +37 -0
- package/runtime/dist/src/executors/codex/local-sessions.js +119 -0
- package/runtime/dist/src/executors/codex/managed-mcp.js +196 -0
- package/runtime/dist/src/executors/codex/process-owner.js +398 -0
- package/runtime/dist/src/executors/codex/production-host.js +887 -0
- package/runtime/dist/src/executors/codex/progress-instructions.js +10 -0
- package/runtime/dist/src/executors/codex/protocol.js +581 -0
- package/runtime/dist/src/executors/codex/safe-json.js +87 -0
- package/runtime/dist/src/executors/codex/session-title.js +61 -0
- package/runtime/dist/src/executors/codex/shared-home.js +29 -0
- package/runtime/dist/src/executors/codex/spawn-env.js +162 -0
- package/runtime/dist/src/executors/codex/turn-projection.js +435 -0
- package/runtime/dist/src/executors/codex/version.js +38 -0
- package/runtime/dist/src/executors/codex/windows-guardian.js +716 -0
- package/runtime/dist/src/executors/coding/intake-model.js +103 -0
- package/runtime/dist/src/executors/coding/intake.js +824 -0
- package/runtime/dist/src/executors/coding/json-completion.js +14 -0
- package/runtime/dist/src/executors/coding/target-resolution.js +61 -0
- package/runtime/dist/src/executors/coding/work-order.js +50 -0
- package/runtime/dist/src/executors/coding-executor.js +23 -0
- package/runtime/dist/src/executors/computer-backend.js +188 -0
- package/runtime/dist/src/executors/computer-device.js +187 -0
- package/runtime/dist/src/executors/computer-worker.js +125 -0
- package/runtime/dist/src/executors/computer.js +100 -0
- package/runtime/dist/src/executors/device-lock.js +127 -0
- package/runtime/dist/src/executors/frame-source.js +29 -0
- package/runtime/dist/src/executors/gui-evidence.js +30 -0
- package/runtime/dist/src/executors/gui-execution.js +237 -0
- package/runtime/dist/src/executors/gui-runner.js +88 -0
- package/runtime/dist/src/executors/host-executor-capability.js +12 -0
- package/runtime/dist/src/executors/index.js +13 -0
- package/runtime/dist/src/executors/mcp-client.js +198 -0
- package/runtime/dist/src/executors/mcp.js +210 -0
- package/runtime/dist/src/executors/mobile-android.js +180 -0
- package/runtime/dist/src/executors/mobile-ios.js +303 -0
- package/runtime/dist/src/executors/mobile.js +78 -0
- package/runtime/dist/src/executors/search-mcp.js +146 -0
- package/runtime/dist/src/executors/search.js +524 -0
- package/runtime/dist/src/executors/task-resources.js +38 -0
- package/runtime/dist/src/executors/vision/assess.js +296 -0
- package/runtime/dist/src/executors/vision/controller-core.js +373 -0
- package/runtime/dist/src/executors/vision/controller.js +164 -0
- package/runtime/dist/src/executors/vision/lifecycle.js +69 -0
- package/runtime/dist/src/executors/vision.js +5 -0
- package/runtime/dist/src/executors/watcher.js +718 -0
- package/runtime/dist/src/http/bounded-response.js +37 -0
- package/runtime/dist/src/index.js +56 -0
- package/runtime/dist/src/knowledge/assembly.js +60 -0
- package/runtime/dist/src/knowledge/documents.js +520 -0
- package/runtime/dist/src/knowledge/embeddings.js +201 -0
- package/runtime/dist/src/knowledge/mcp.js +218 -0
- package/runtime/dist/src/knowledge/parse-worker.js +122 -0
- package/runtime/dist/src/knowledge/references.js +51 -0
- package/runtime/dist/src/knowledge/service.js +526 -0
- package/runtime/dist/src/knowledge/store-client.js +185 -0
- package/runtime/dist/src/knowledge/store-worker.js +843 -0
- package/runtime/dist/src/knowledge/types.js +2 -0
- package/runtime/dist/src/mcp/http-server.js +177 -0
- package/runtime/dist/src/mem0/resource.js +35 -0
- package/runtime/dist/src/mem0/store-worker.js +330 -0
- package/runtime/dist/src/memory/blackboard-session.js +205 -0
- package/runtime/dist/src/memory/blackboard-store.js +194 -0
- package/runtime/dist/src/memory/blackboard-worker.js +369 -0
- package/runtime/dist/src/memory/entry.js +39 -0
- package/runtime/dist/src/memory/factory.js +20 -0
- package/runtime/dist/src/memory/personal-memory-inspection.js +18 -0
- package/runtime/dist/src/memory/personal-memory.js +10 -0
- package/runtime/dist/src/memory/prerecall.js +20 -0
- package/runtime/dist/src/memory/provenance.js +17 -0
- package/runtime/dist/src/memory/remote-personal-memory.js +194 -0
- package/runtime/dist/src/memory/retrieval.js +235 -0
- package/runtime/dist/src/memory/sensitivity.js +261 -0
- package/runtime/dist/src/memory-ledger/models.js +98 -0
- package/runtime/dist/src/memory-ledger/store-client.js +210 -0
- package/runtime/dist/src/memory-ledger/store-worker.js +130 -0
- package/runtime/dist/src/memory-ledger/store.js +597 -0
- package/runtime/dist/src/memory-substrate/candidates.js +16 -0
- package/runtime/dist/src/memory-substrate/consolidation.js +124 -0
- package/runtime/dist/src/memory-substrate/file-authority.js +111 -0
- package/runtime/dist/src/memory-substrate/life-operations.js +280 -0
- package/runtime/dist/src/memory-substrate/markdown-repository.js +610 -0
- package/runtime/dist/src/memory-substrate/migration.js +87 -0
- package/runtime/dist/src/memory-substrate/profile-source-input.js +9 -0
- package/runtime/dist/src/memory-substrate/purge.js +398 -0
- package/runtime/dist/src/memory-substrate/resolution.js +32 -0
- package/runtime/dist/src/memory-substrate/resource.js +867 -0
- package/runtime/dist/src/memory-substrate/retrieval.js +85 -0
- package/runtime/dist/src/memory-substrate/source-operations.js +306 -0
- package/runtime/dist/src/memory-substrate/source-processing.js +326 -0
- package/runtime/dist/src/memory-substrate/source-state.js +93 -0
- package/runtime/dist/src/memory-substrate/store.js +534 -0
- package/runtime/dist/src/memory-substrate/workspace-projections.js +106 -0
- package/runtime/dist/src/memory-substrate/workspace.js +21 -0
- package/runtime/dist/src/model/jev-client.js +25 -0
- package/runtime/dist/src/model/model-adapters.js +64 -0
- package/runtime/dist/src/model/model-gateway.js +399 -0
- package/runtime/dist/src/model/model-lane.js +34 -0
- package/runtime/dist/src/model/model-purpose.js +5 -0
- package/runtime/dist/src/model/personal-writer.js +361 -0
- package/runtime/dist/src/model/proactivity.js +72 -0
- package/runtime/dist/src/model/prompting.js +279 -0
- package/runtime/dist/src/model/task-verifier.js +217 -0
- package/runtime/dist/src/model/vision-capability.js +10 -0
- package/runtime/dist/src/news/feeds.js +114 -0
- package/runtime/dist/src/news/jev-ranking.js +25 -0
- package/runtime/dist/src/news/ranking.js +26 -0
- package/runtime/dist/src/news/service.js +262 -0
- package/runtime/dist/src/notifications/adapters/feishu.js +10 -0
- package/runtime/dist/src/notifications/adapters/nova.js +15 -0
- package/runtime/dist/src/notifications/content.js +15 -0
- package/runtime/dist/src/notifications/contracts.js +9 -0
- package/runtime/dist/src/notifications/feed.js +8 -0
- package/runtime/dist/src/notifications/service.js +412 -0
- package/runtime/dist/src/notifications/store.js +4 -0
- package/runtime/dist/src/personal-agent/app-context.js +113 -0
- package/runtime/dist/src/personal-agent/approval-scope.js +8 -0
- package/runtime/dist/src/personal-agent/coding-targets.js +82 -0
- package/runtime/dist/src/personal-agent/context-candidates.js +94 -0
- package/runtime/dist/src/personal-agent/contracts.js +32 -0
- package/runtime/dist/src/personal-agent/conversation-runtime.js +536 -0
- package/runtime/dist/src/personal-agent/conversations.js +187 -0
- package/runtime/dist/src/personal-agent/daily-brief.js +53 -0
- package/runtime/dist/src/personal-agent/host.js +2403 -0
- package/runtime/dist/src/personal-agent/intake-task.js +37 -0
- package/runtime/dist/src/personal-agent/life.js +260 -0
- package/runtime/dist/src/personal-agent/memory-overview.js +19 -0
- package/runtime/dist/src/personal-agent/profile-sources.js +34 -0
- package/runtime/dist/src/personal-agent/profile-warmup.js +244 -0
- package/runtime/dist/src/personal-agent/project-digests.js +242 -0
- package/runtime/dist/src/personal-agent/sampling.js +20 -0
- package/runtime/dist/src/personal-agent/schedule-agent.js +60 -0
- package/runtime/dist/src/personal-agent/schedule-api.js +61 -0
- package/runtime/dist/src/personal-agent/schedule-presets.js +13 -0
- package/runtime/dist/src/personal-agent/schedule-reference.js +3 -0
- package/runtime/dist/src/personal-agent/scheduled-response-scope.js +38 -0
- package/runtime/dist/src/personal-agent/scheduled-run-authority.js +44 -0
- package/runtime/dist/src/personal-agent/scheduled-tasks.js +280 -0
- package/runtime/dist/src/personal-agent/scheduled-time.js +99 -0
- package/runtime/dist/src/personal-agent/scheduled-tool-runtime.js +109 -0
- package/runtime/dist/src/personal-agent/source-priority.js +142 -0
- package/runtime/dist/src/personal-agent/source-processing-agent.js +158 -0
- package/runtime/dist/src/personal-agent/source-walk.js +25 -0
- package/runtime/dist/src/personal-agent/sources.js +1484 -0
- package/runtime/dist/src/personal-agent/store-lock-worker.js +17 -0
- package/runtime/dist/src/personal-agent/store.js +146 -0
- package/runtime/dist/src/personal-agent/task-loop.js +163 -0
- package/runtime/dist/src/personal-agent/tasks.js +920 -0
- package/runtime/dist/src/personal-agent/turn-deadline.js +55 -0
- package/runtime/dist/src/personal-agent/understanding.js +160 -0
- package/runtime/dist/src/personal-agent/workbench-context.js +239 -0
- package/runtime/dist/src/projects/confirmed-project-capability.js +60 -0
- package/runtime/dist/src/projects/host-paths.js +133 -0
- package/runtime/dist/src/projects/managed-workspace-maintenance.js +351 -0
- package/runtime/dist/src/projects/project-confirmation.js +486 -0
- package/runtime/dist/src/projects/project-native-resource.js +284 -0
- package/runtime/dist/src/projects/project-node-files.js +169 -0
- package/runtime/dist/src/projects/project-root-file.js +16 -0
- package/runtime/dist/src/projects/project-state.js +504 -0
- package/runtime/dist/src/projects/project-store-files.js +1271 -0
- package/runtime/dist/src/projects/project-store.js +1345 -0
- package/runtime/dist/src/realtime/aoq.js +141 -0
- package/runtime/dist/src/realtime/bridge.js +652 -0
- package/runtime/dist/src/realtime/cascaded/adapter.js +1669 -0
- package/runtime/dist/src/realtime/cascaded/ark-llm.js +219 -0
- package/runtime/dist/src/realtime/cascaded/chat-completions-llm.js +478 -0
- package/runtime/dist/src/realtime/cascaded/gemini-speech.js +232 -0
- package/runtime/dist/src/realtime/cascaded/llm.js +37 -0
- package/runtime/dist/src/realtime/cascaded/ports.js +2 -0
- package/runtime/dist/src/realtime/cascaded/provider.js +216 -0
- package/runtime/dist/src/realtime/cascaded/qwen-llm.js +7 -0
- package/runtime/dist/src/realtime/cascaded/self-hosted-asr.js +110 -0
- package/runtime/dist/src/realtime/cascaded/self-hosted-tts.js +137 -0
- package/runtime/dist/src/realtime/cascaded/transcribe.js +42 -0
- package/runtime/dist/src/realtime/coding-progress-narration.js +28 -0
- package/runtime/dist/src/realtime/confirmation-turn-isolation.js +586 -0
- package/runtime/dist/src/realtime/dictation.js +28 -0
- package/runtime/dist/src/realtime/evidence.js +276 -0
- package/runtime/dist/src/realtime/floor.js +43 -0
- package/runtime/dist/src/realtime/frontend-instructions.js +195 -0
- package/runtime/dist/src/realtime/gemini.js +517 -0
- package/runtime/dist/src/realtime/history.js +122 -0
- package/runtime/dist/src/realtime/host-delivery.js +1711 -0
- package/runtime/dist/src/realtime/integrated-wire-profile.js +128 -0
- package/runtime/dist/src/realtime/memory-board.js +105 -0
- package/runtime/dist/src/realtime/openai-wire-profile.js +46 -0
- package/runtime/dist/src/realtime/playback.js +242 -0
- package/runtime/dist/src/realtime/project-confirmation-flow.js +1428 -0
- package/runtime/dist/src/realtime/prompt-language.js +17 -0
- package/runtime/dist/src/realtime/protocol.js +428 -0
- package/runtime/dist/src/realtime/provider-projection.js +526 -0
- package/runtime/dist/src/realtime/provider-session.js +491 -0
- package/runtime/dist/src/realtime/qwen-transport.js +144 -0
- package/runtime/dist/src/realtime/qwen.js +1377 -0
- package/runtime/dist/src/realtime/recall.js +341 -0
- package/runtime/dist/src/realtime/service-ports.js +8 -0
- package/runtime/dist/src/realtime/service-state.js +259 -0
- package/runtime/dist/src/realtime/service.js +1726 -0
- package/runtime/dist/src/realtime/session-state.js +684 -0
- package/runtime/dist/src/realtime/session.js +1976 -0
- package/runtime/dist/src/realtime/speech-prep.js +63 -0
- package/runtime/dist/src/realtime/streaming-speech.js +120 -0
- package/runtime/dist/src/realtime/system-prompts.en.js +136 -0
- package/runtime/dist/src/realtime/telemetry.js +144 -0
- package/runtime/dist/src/realtime/tool-continuations.js +1510 -0
- package/runtime/dist/src/realtime/transport.js +8 -0
- package/runtime/dist/src/realtime/usage.js +55 -0
- package/runtime/dist/src/realtime/user-origin-binding.js +173 -0
- package/runtime/dist/src/realtime/volcengine/ark.js +428 -0
- package/runtime/dist/src/realtime/volcengine/asr.js +573 -0
- package/runtime/dist/src/realtime/volcengine/audio.js +39 -0
- package/runtime/dist/src/realtime/volcengine/endpointing-capability.js +834 -0
- package/runtime/dist/src/realtime/volcengine/livekit-endpointing.js +714 -0
- package/runtime/dist/src/realtime/volcengine/local-eot-executor.js +33 -0
- package/runtime/dist/src/realtime/volcengine/protocol.js +247 -0
- package/runtime/dist/src/realtime/volcengine/silence-endpointing.js +237 -0
- package/runtime/dist/src/realtime/volcengine/tts.js +444 -0
- package/runtime/dist/src/realtime/volcengine/websocket.js +293 -0
- package/runtime/dist/src/server/aoq-chat-server.js +497 -0
- package/runtime/dist/src/server/client-pairing.js +192 -0
- package/runtime/dist/src/server/client-protocol.js +87 -0
- package/runtime/dist/src/server/client-server.js +312 -0
- package/runtime/dist/src/server/server-config.js +72 -0
- package/runtime/dist/src/server-entry.js +135 -0
- package/runtime/dist/src/storage/bounded-json.js +63 -0
- package/runtime/dist/src/storage/native-file-lock.js +8 -0
- package/runtime/dist/src/storage/native-resource-snapshot.js +41 -0
- package/runtime/dist/src/storage/private-database.js +120 -0
- package/runtime/dist/src/text/canonical-json.js +60 -0
- package/runtime/dist/src/text/python-number.js +18 -0
- package/runtime/dist/src/text/python-text.js +92 -0
- package/runtime/dist/src/text/unicode-casefold.js +29 -0
- package/runtime/dist/src/text/unicode-normalize.js +138 -0
- package/runtime/dist/src/text/unicode-tables.js +210 -0
- package/runtime/dist/src/understanding/candidates.js +77 -0
- package/runtime/dist/src/understanding/fixture.js +7 -0
- package/runtime/dist/src/understanding/jev.js +20 -0
- package/runtime/dist/src/understanding/pipeline.js +38 -0
- package/runtime/dist/src/voicemem/store-client.js +476 -0
- package/runtime/dist/src/voicemem/store-worker.js +380 -0
- package/runtime/dist/src/voicemem/versioned-memory.js +170 -0
- package/runtime/scripts/pair-device.mjs +109 -0
- package/src/command.mjs +48 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { stripLikePython } from '../text/python-text.js';
|
|
2
|
+
const unchanged = (frame) => frame;
|
|
3
|
+
const unchangedPcm = (pcm) => pcm;
|
|
4
|
+
// The adapter ignores unknown event types, so a retyped frame is dropped.
|
|
5
|
+
const DROPPED = Object.freeze({ type: 'stepfun.dropped' });
|
|
6
|
+
export const qwenWireProfile = Object.freeze({
|
|
7
|
+
provider: 'qwen',
|
|
8
|
+
voiceOptional: false,
|
|
9
|
+
session: (tools, voice, instructions, model) => ({
|
|
10
|
+
modalities: ['audio', 'text'], voice, instructions,
|
|
11
|
+
input_audio_format: 'pcm', output_audio_format: 'pcm',
|
|
12
|
+
...(model.startsWith('qwen3.5-omni-') ? {} : { max_history_turns: 20 }),
|
|
13
|
+
tools: [...tools],
|
|
14
|
+
turn_detection: { type: model.startsWith('qwen3.5-omni-') ? 'semantic_vad' : 'smart_turn' },
|
|
15
|
+
}),
|
|
16
|
+
outbound: unchanged,
|
|
17
|
+
inbound: unchanged,
|
|
18
|
+
classifyError: classifyLegacyCancellation,
|
|
19
|
+
inputPcm: unchangedPcm,
|
|
20
|
+
reset: () => undefined,
|
|
21
|
+
});
|
|
22
|
+
/** Stateful linear PCM16 conversion; input and output frame boundaries do not reset phase. */
|
|
23
|
+
export class Pcm16Resampler {
|
|
24
|
+
inputRate;
|
|
25
|
+
outputRate;
|
|
26
|
+
#sampleIndex = 0;
|
|
27
|
+
#nextOutputNumerator = 0;
|
|
28
|
+
#previous = 0;
|
|
29
|
+
constructor(inputRate, outputRate) {
|
|
30
|
+
this.inputRate = inputRate;
|
|
31
|
+
this.outputRate = outputRate;
|
|
32
|
+
}
|
|
33
|
+
reset() { this.#sampleIndex = 0; this.#nextOutputNumerator = 0; this.#previous = 0; }
|
|
34
|
+
convert(pcm) {
|
|
35
|
+
if (pcm.length % 2 !== 0)
|
|
36
|
+
throw new TypeError('PCM16 input must be aligned');
|
|
37
|
+
const source = new DataView(pcm.buffer, pcm.byteOffset, pcm.byteLength);
|
|
38
|
+
const output = new Int16Array(Math.ceil(pcm.length / 2 * this.outputRate / this.inputRate) + 2);
|
|
39
|
+
let count = 0;
|
|
40
|
+
for (let offset = 0; offset < pcm.length; offset += 2) {
|
|
41
|
+
const current = source.getInt16(offset, true);
|
|
42
|
+
const index = this.#sampleIndex++;
|
|
43
|
+
while (this.#nextOutputNumerator <= index * this.outputRate) {
|
|
44
|
+
const remainder = this.#nextOutputNumerator - (index - 1) * this.outputRate;
|
|
45
|
+
const sample = index === 0 ? current : this.#previous + (current - this.#previous) * remainder / this.outputRate;
|
|
46
|
+
output[count++] = Math.round(sample);
|
|
47
|
+
this.#nextOutputNumerator += this.inputRate;
|
|
48
|
+
}
|
|
49
|
+
this.#previous = current;
|
|
50
|
+
}
|
|
51
|
+
return new Uint8Array(output.buffer.slice(0, count * 2));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export function createStepFunWireProfile() {
|
|
55
|
+
const inputResampler = new Pcm16Resampler(16, 24);
|
|
56
|
+
// StepFun reports a call both as arguments.done and as output_item.done; deliver it once.
|
|
57
|
+
const seenToolCalls = new Set();
|
|
58
|
+
const firstToolCall = (frame) => {
|
|
59
|
+
const callId = frame.call_id;
|
|
60
|
+
if (typeof callId !== 'string')
|
|
61
|
+
return frame;
|
|
62
|
+
if (seenToolCalls.has(callId))
|
|
63
|
+
return DROPPED;
|
|
64
|
+
seenToolCalls.add(callId);
|
|
65
|
+
if (seenToolCalls.size > 256)
|
|
66
|
+
seenToolCalls.delete(seenToolCalls.values().next().value);
|
|
67
|
+
return frame;
|
|
68
|
+
};
|
|
69
|
+
return {
|
|
70
|
+
provider: 'stepfun',
|
|
71
|
+
classifyError: classifyLegacyCancellation,
|
|
72
|
+
voiceOptional: true,
|
|
73
|
+
session: (tools, voice, instructions) => ({
|
|
74
|
+
modalities: ['text', 'audio'], instructions,
|
|
75
|
+
...(voice === '' || voice === 'default' ? {} : { voice }),
|
|
76
|
+
input_audio_format: 'pcm16', output_audio_format: 'pcm16',
|
|
77
|
+
tools: tools.map(tool => {
|
|
78
|
+
if (tool.type !== 'function')
|
|
79
|
+
throw new TypeError('StepFun accepts function tools only');
|
|
80
|
+
if (typeof tool.name !== 'string' || typeof tool.description !== 'string'
|
|
81
|
+
|| typeof tool.parameters !== 'object' || tool.parameters === null
|
|
82
|
+
|| Array.isArray(tool.parameters))
|
|
83
|
+
throw new TypeError('invalid function tool');
|
|
84
|
+
return { type: 'function', function: {
|
|
85
|
+
name: tool.name, description: tool.description, parameters: tool.parameters,
|
|
86
|
+
} };
|
|
87
|
+
}),
|
|
88
|
+
turn_detection: { type: 'server_vad', prefix_padding_ms: 500 },
|
|
89
|
+
}),
|
|
90
|
+
outbound: unchanged,
|
|
91
|
+
inbound: frame => {
|
|
92
|
+
if (frame.type === 'response.output_item.done') {
|
|
93
|
+
const item = frame.item;
|
|
94
|
+
if (typeof item === 'object' && item !== null && !Array.isArray(item)
|
|
95
|
+
&& item.type === 'function_call') {
|
|
96
|
+
if (typeof frame.response_id !== 'string' || typeof item.id !== 'string'
|
|
97
|
+
|| typeof item.call_id !== 'string' || typeof item.name !== 'string'
|
|
98
|
+
|| typeof item.arguments !== 'string')
|
|
99
|
+
throw new TypeError('invalid StepFun function call');
|
|
100
|
+
return firstToolCall({ type: 'response.function_call_arguments.done',
|
|
101
|
+
response_id: frame.response_id, item_id: item.id,
|
|
102
|
+
call_id: item.call_id, name: item.name, arguments: item.arguments });
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (frame.type === 'response.function_call_arguments.done')
|
|
106
|
+
return firstToolCall(frame);
|
|
107
|
+
// StepFun ends truncated responses as incomplete; the shared host treats them as failed.
|
|
108
|
+
if (frame.type === 'response.done' && typeof frame.response === 'object' && frame.response !== null
|
|
109
|
+
&& !Array.isArray(frame.response) && frame.response.status === 'incomplete') {
|
|
110
|
+
return { ...frame, response: { ...frame.response, status: 'failed' } };
|
|
111
|
+
}
|
|
112
|
+
if (frame.type === 'response.cancelled' && typeof frame.response_id === 'string') {
|
|
113
|
+
return { type: 'response.done', response: { id: frame.response_id, status: 'cancelled' } };
|
|
114
|
+
}
|
|
115
|
+
return frame;
|
|
116
|
+
},
|
|
117
|
+
inputPcm: pcm => inputResampler.convert(pcm),
|
|
118
|
+
reset: () => { inputResampler.reset(); seenToolCalls.clear(); },
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/** Legacy services expose cancellation races only through prose; keep that quirk at their boundary. */
|
|
122
|
+
function classifyLegacyCancellation(error) {
|
|
123
|
+
const message = typeof error.message === 'string' ? stripLikePython(error.message).toLowerCase().replace(/\.+$/u, '') : '';
|
|
124
|
+
if (error.code === 'invalid_value' && (message === 'conversation has no active response' || message === 'no active response found to cancel'))
|
|
125
|
+
return 'no_active_response';
|
|
126
|
+
return /\bno active response\b/iu.test(message) ? 'ignore' : undefined;
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=integrated-wire-profile.js.map
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
|
+
export const MAX_BOARD_MESSAGE_BYTES = 256 * 1024;
|
|
3
|
+
export const MAX_BOARD_ITEMS_PER_CHANNEL = 50;
|
|
4
|
+
export const MAX_BOARD_CONTENT_CHARS = 2048;
|
|
5
|
+
export const MAX_BOARD_SUMMARY_CHARS = 4096;
|
|
6
|
+
export const MAX_BOARD_REFRESH_MESSAGE_BYTES = 64 * 1024;
|
|
7
|
+
export const MAX_BOARD_REFRESH_ITEMS_PER_CHANNEL = 12;
|
|
8
|
+
export const MAX_BOARD_REFRESH_CONTENT_CHARS = 768;
|
|
9
|
+
export const MAX_BOARD_REFRESH_SUMMARY_CHARS = 1024;
|
|
10
|
+
export const MAX_BOARD_REFRESH_DIAGNOSTICS = 32;
|
|
11
|
+
export function memoryBoardMessage(requestId, memory, diagnosticSnapshot = { version: 1, records: [] }, options = {}) {
|
|
12
|
+
const detail = options.channel === undefined ? options.detail ?? 'full' : 'full';
|
|
13
|
+
const profile = detail === 'compact'
|
|
14
|
+
? {
|
|
15
|
+
messageBytes: MAX_BOARD_REFRESH_MESSAGE_BYTES,
|
|
16
|
+
itemsPerChannel: MAX_BOARD_REFRESH_ITEMS_PER_CHANNEL,
|
|
17
|
+
contentChars: MAX_BOARD_REFRESH_CONTENT_CHARS,
|
|
18
|
+
summaryChars: MAX_BOARD_REFRESH_SUMMARY_CHARS,
|
|
19
|
+
diagnostics: MAX_BOARD_REFRESH_DIAGNOSTICS,
|
|
20
|
+
}
|
|
21
|
+
: {
|
|
22
|
+
messageBytes: MAX_BOARD_MESSAGE_BYTES,
|
|
23
|
+
itemsPerChannel: MAX_BOARD_ITEMS_PER_CHANNEL,
|
|
24
|
+
contentChars: MAX_BOARD_CONTENT_CHARS,
|
|
25
|
+
summaryChars: MAX_BOARD_SUMMARY_CHARS,
|
|
26
|
+
diagnostics: diagnosticSnapshot.records.length,
|
|
27
|
+
};
|
|
28
|
+
const selected = [...memory.channels.values()].filter(channel => options.channel === undefined || channel.name === options.channel);
|
|
29
|
+
const channels = selected.map(channel => channelView(channel, profile, options.before_seq));
|
|
30
|
+
const diagnostics = {
|
|
31
|
+
version: 1,
|
|
32
|
+
records: diagnosticSnapshot.records.slice(-profile.diagnostics),
|
|
33
|
+
};
|
|
34
|
+
let summariesDropped = false;
|
|
35
|
+
while (true) {
|
|
36
|
+
for (const channel of channels) {
|
|
37
|
+
const first = channel.items[0]?.seq;
|
|
38
|
+
channel.has_more = first !== undefined && memory.channels.get(channel.name).items.some(item => item.seq < first);
|
|
39
|
+
channel.next_before_seq = channel.has_more ? first : null;
|
|
40
|
+
}
|
|
41
|
+
const message = JSON.stringify({
|
|
42
|
+
type: 'memory.board', request_id: requestId, conversation_epoch: options.conversationEpoch ?? 0, diagnostics, channels,
|
|
43
|
+
});
|
|
44
|
+
if (Buffer.byteLength(message, 'utf8') <= profile.messageBytes)
|
|
45
|
+
return message;
|
|
46
|
+
if (diagnostics.records.length > 0) {
|
|
47
|
+
diagnostics.records = diagnostics.records.slice(1);
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
const populated = channels.filter(channel => channel.items.length > 0);
|
|
51
|
+
if (populated.length > 0) {
|
|
52
|
+
const largest = populated.reduce((current, candidate) => (candidate.items.length > current.items.length ? candidate : current));
|
|
53
|
+
largest.items = largest.items.slice(1);
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (!summariesDropped) {
|
|
57
|
+
summariesDropped = true;
|
|
58
|
+
for (const channel of channels)
|
|
59
|
+
channel.summary = null;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
return message;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function channelView(channel, profile, before) {
|
|
66
|
+
return {
|
|
67
|
+
name: channel.name,
|
|
68
|
+
next_before_seq: null,
|
|
69
|
+
has_more: false,
|
|
70
|
+
...(channel.restoredThroughSequence === 0 ? {} : { historical_through_seq: channel.restoredThroughSequence }),
|
|
71
|
+
summary: channel.summary === null
|
|
72
|
+
? null
|
|
73
|
+
: sliceCodePoints(channel.summary, profile.summaryChars),
|
|
74
|
+
uncompressed: channel.uncompressed,
|
|
75
|
+
item_count: channel.items.length,
|
|
76
|
+
retention_revision: channel.retentionRevision,
|
|
77
|
+
items: channel.items
|
|
78
|
+
.filter(item => before === undefined || item.seq < before)
|
|
79
|
+
.slice(-profile.itemsPerChannel)
|
|
80
|
+
.map(item => ({ ...itemView(item, profile.contentChars),
|
|
81
|
+
...(item.seq <= channel.restoredThroughSequence ? {
|
|
82
|
+
historical: true,
|
|
83
|
+
recorded_at_ms: channel.restoredRecord(item.seq).recordedAtMs,
|
|
84
|
+
} : {}),
|
|
85
|
+
})),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function itemView(item, contentChars) {
|
|
89
|
+
const content = JSON.stringify(item.content);
|
|
90
|
+
const truncated = [...content].length > contentChars;
|
|
91
|
+
return {
|
|
92
|
+
seq: item.seq,
|
|
93
|
+
ts: item.ts,
|
|
94
|
+
trust: item.trust,
|
|
95
|
+
priority: item.priority,
|
|
96
|
+
outcome: item.outcome,
|
|
97
|
+
refs: [...item.refs],
|
|
98
|
+
content: sliceCodePoints(content, contentChars),
|
|
99
|
+
...(truncated ? { truncated: true } : {}),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function sliceCodePoints(value, limit) {
|
|
103
|
+
return [...value].slice(0, limit).join('');
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=memory-board.js.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Pcm16Resampler } from './integrated-wire-profile.js';
|
|
2
|
+
/** OpenAI GA protocol translation. Host item delivery still requires server acknowledgments. */
|
|
3
|
+
export function createOpenAIWireProfile() {
|
|
4
|
+
const resampler = new Pcm16Resampler(16_000, 24_000);
|
|
5
|
+
const eventNames = {
|
|
6
|
+
'conversation.item.added': 'conversation.item.created',
|
|
7
|
+
'response.output_audio.delta': 'response.audio.delta',
|
|
8
|
+
'response.output_audio_transcript.delta': 'response.audio_transcript.delta',
|
|
9
|
+
'response.output_audio_transcript.done': 'response.audio_transcript.done',
|
|
10
|
+
'response.output_text.delta': 'response.text.delta',
|
|
11
|
+
};
|
|
12
|
+
return {
|
|
13
|
+
provider: 'openai', voiceOptional: false,
|
|
14
|
+
session: (tools, voice, instructions) => ({
|
|
15
|
+
type: 'realtime', instructions, output_modalities: ['audio'], tools: [...tools],
|
|
16
|
+
audio: {
|
|
17
|
+
input: { format: { type: 'audio/pcm', rate: 24_000 }, transcription: { model: 'gpt-transcribe' }, turn_detection: { type: 'server_vad' } },
|
|
18
|
+
output: { format: { type: 'audio/pcm', rate: 24_000 }, voice },
|
|
19
|
+
},
|
|
20
|
+
}),
|
|
21
|
+
outbound: frame => {
|
|
22
|
+
if (frame.type === 'response.create' && record(frame.response)) {
|
|
23
|
+
const { modalities, ...response } = frame.response;
|
|
24
|
+
return { ...frame, response: { ...response, ...(modalities === undefined ? {} : { output_modalities: ['audio'] }) } };
|
|
25
|
+
}
|
|
26
|
+
if (frame.type === 'session.update' && record(frame.session))
|
|
27
|
+
return { ...frame, session: { type: 'realtime', ...frame.session } };
|
|
28
|
+
return frame;
|
|
29
|
+
},
|
|
30
|
+
classifyError: error => error.code === 'response_cancel_not_active' ? 'no_active_response' : undefined,
|
|
31
|
+
inbound: frame => {
|
|
32
|
+
if (typeof frame.type === 'string' && eventNames[frame.type])
|
|
33
|
+
return { ...frame, type: eventNames[frame.type] };
|
|
34
|
+
if (frame.type === 'response.done' && record(frame.response) && frame.response.status === 'incomplete') {
|
|
35
|
+
return { ...frame, response: { ...frame.response, status: 'failed' } };
|
|
36
|
+
}
|
|
37
|
+
return frame;
|
|
38
|
+
},
|
|
39
|
+
inputPcm: pcm => resampler.convert(pcm),
|
|
40
|
+
reset: () => resampler.reset(),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function record(value) {
|
|
44
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=openai-wire-profile.js.map
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
export const MAX_PLAYBACK_FRAME_BYTES = 64 * 1024;
|
|
2
|
+
export const MAX_RENDERER_TOMBSTONES = 256;
|
|
3
|
+
export class PlaybackRegistry {
|
|
4
|
+
#nextGenerationEpoch;
|
|
5
|
+
#idFactory;
|
|
6
|
+
#onFrame;
|
|
7
|
+
#onClear;
|
|
8
|
+
#onAlert;
|
|
9
|
+
#byProvider = new Map();
|
|
10
|
+
#byRenderer = new Map();
|
|
11
|
+
#rendererTombstones = [];
|
|
12
|
+
#rendererTombstoneSet = new Set();
|
|
13
|
+
#generationEpoch = 0;
|
|
14
|
+
#currentProviderIdentity = null;
|
|
15
|
+
constructor(options) {
|
|
16
|
+
this.#nextGenerationEpoch = options.nextGenerationEpoch;
|
|
17
|
+
this.#idFactory = options.idFactory;
|
|
18
|
+
this.#onFrame = options.onFrame;
|
|
19
|
+
this.#onClear = options.onClear;
|
|
20
|
+
this.#onAlert = options.onAlert ?? (() => undefined);
|
|
21
|
+
}
|
|
22
|
+
get current() {
|
|
23
|
+
if (this.#currentProviderIdentity === null)
|
|
24
|
+
return null;
|
|
25
|
+
return this.#byProvider.get(this.#currentProviderIdentity)?.identity ?? null;
|
|
26
|
+
}
|
|
27
|
+
get hasUnreportedFence() {
|
|
28
|
+
return [...this.#byProvider.values()].some(state => state.fenced && !state.delivered);
|
|
29
|
+
}
|
|
30
|
+
get rendererTombstoneCount() {
|
|
31
|
+
return this.#rendererTombstones.length;
|
|
32
|
+
}
|
|
33
|
+
openResponse(input) {
|
|
34
|
+
if (!Number.isInteger(input.sessionEpoch) || input.sessionEpoch < 1 || input.responseId === '') {
|
|
35
|
+
throw new Error('sessionEpoch and responseId are required');
|
|
36
|
+
}
|
|
37
|
+
const providerIdentity = providerKey(input.sessionEpoch, input.responseId);
|
|
38
|
+
if (this.#byProvider.has(providerIdentity)) {
|
|
39
|
+
throw new Error('response already has a playback generation');
|
|
40
|
+
}
|
|
41
|
+
if (this.#currentProviderIdentity !== null) {
|
|
42
|
+
throw new Error('another playback generation is active');
|
|
43
|
+
}
|
|
44
|
+
this.#generationEpoch = this.#nextGenerationEpoch?.() ?? this.#generationEpoch + 1;
|
|
45
|
+
const identity = Object.freeze({
|
|
46
|
+
session_epoch: input.sessionEpoch,
|
|
47
|
+
generation_epoch: this.#generationEpoch,
|
|
48
|
+
generation_id: this.#requiredId(),
|
|
49
|
+
utterance_id: this.#requiredId(),
|
|
50
|
+
response_id: input.responseId,
|
|
51
|
+
});
|
|
52
|
+
const state = {
|
|
53
|
+
identity,
|
|
54
|
+
nextSequence: 0,
|
|
55
|
+
transcript: '',
|
|
56
|
+
providerTerminal: false,
|
|
57
|
+
fenced: false,
|
|
58
|
+
delivered: false,
|
|
59
|
+
started: false,
|
|
60
|
+
terminalDisposition: 'spoken',
|
|
61
|
+
};
|
|
62
|
+
this.#byProvider.set(providerIdentity, state);
|
|
63
|
+
this.#byRenderer.set(rendererKey(identity.utterance_id, identity.generation_epoch), state);
|
|
64
|
+
this.#currentProviderIdentity = providerIdentity;
|
|
65
|
+
return identity;
|
|
66
|
+
}
|
|
67
|
+
pushAudio(input) {
|
|
68
|
+
if (!(input.pcm instanceof Uint8Array) || input.pcm.byteLength === 0 || input.pcm.byteLength % 2 !== 0) {
|
|
69
|
+
throw new Error('pcm must be non-empty aligned PCM16 bytes');
|
|
70
|
+
}
|
|
71
|
+
const state = this.#byProvider.get(providerKey(input.sessionEpoch, input.responseId));
|
|
72
|
+
if (state === undefined || state.providerTerminal || state.fenced || state.delivered)
|
|
73
|
+
return false;
|
|
74
|
+
for (let offset = 0; offset < input.pcm.byteLength; offset += MAX_PLAYBACK_FRAME_BYTES) {
|
|
75
|
+
this.#onFrame({
|
|
76
|
+
utterance_id: state.identity.utterance_id,
|
|
77
|
+
generation_epoch: state.identity.generation_epoch,
|
|
78
|
+
sequence: state.nextSequence,
|
|
79
|
+
pcm: input.pcm.slice(offset, offset + MAX_PLAYBACK_FRAME_BYTES),
|
|
80
|
+
});
|
|
81
|
+
state.nextSequence += 1;
|
|
82
|
+
}
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
setTranscript(input) {
|
|
86
|
+
const state = this.#byProvider.get(providerKey(input.sessionEpoch, input.responseId));
|
|
87
|
+
if (state === undefined || state.delivered)
|
|
88
|
+
return false;
|
|
89
|
+
state.transcript = input.text;
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
markProviderTerminal(input) {
|
|
93
|
+
const state = this.#byProvider.get(providerKey(input.sessionEpoch, input.responseId));
|
|
94
|
+
if (state === undefined || state.fenced || state.delivered)
|
|
95
|
+
return false;
|
|
96
|
+
state.providerTerminal = true;
|
|
97
|
+
state.terminalDisposition = input.disposition ?? 'spoken';
|
|
98
|
+
if (state.nextSequence === 0)
|
|
99
|
+
this.#retire(state);
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
fenceCurrent(options = {}) {
|
|
103
|
+
const current = this.current;
|
|
104
|
+
if (current === null) {
|
|
105
|
+
if (options.alert === true)
|
|
106
|
+
this.#onAlert(null, null);
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
const fenced = options.alert === true
|
|
110
|
+
? this.alertFenceGeneration(current)
|
|
111
|
+
: this.switchGeneration(current);
|
|
112
|
+
return fenced ? current : null;
|
|
113
|
+
}
|
|
114
|
+
switchGeneration(generation) {
|
|
115
|
+
return this.#fenceGeneration(generation, false);
|
|
116
|
+
}
|
|
117
|
+
alertFenceGeneration(generation) {
|
|
118
|
+
return this.#fenceGeneration(generation, true);
|
|
119
|
+
}
|
|
120
|
+
retireClearUnknown(generation) {
|
|
121
|
+
const state = this.#stateForGeneration(generation);
|
|
122
|
+
if (state === undefined || state.delivered || !state.fenced)
|
|
123
|
+
return false;
|
|
124
|
+
this.#retire(state);
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
markStarted(utteranceId, generationEpoch) {
|
|
128
|
+
const state = this.#find(utteranceId, generationEpoch);
|
|
129
|
+
if (state === undefined || state.delivered || state.started)
|
|
130
|
+
return false;
|
|
131
|
+
state.started = true;
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
recordCleared(utteranceId, generationEpoch, playedMs) {
|
|
135
|
+
const state = this.#find(utteranceId, generationEpoch);
|
|
136
|
+
if (state === undefined || state.delivered || !state.fenced)
|
|
137
|
+
return null;
|
|
138
|
+
state.delivered = true;
|
|
139
|
+
const completion = this.#completion(state, state.started || (playedMs !== null && playedMs > 0) ? 'interrupted' : 'suppressed', playedMs);
|
|
140
|
+
this.#retire(state);
|
|
141
|
+
return completion;
|
|
142
|
+
}
|
|
143
|
+
ackDone(utteranceId, generationEpoch, playedMs = null) {
|
|
144
|
+
const state = this.#find(utteranceId, generationEpoch);
|
|
145
|
+
if (state === undefined
|
|
146
|
+
|| state.fenced
|
|
147
|
+
|| state.delivered
|
|
148
|
+
|| !state.providerTerminal
|
|
149
|
+
|| state.nextSequence === 0)
|
|
150
|
+
return null;
|
|
151
|
+
state.delivered = true;
|
|
152
|
+
let disposition = state.terminalDisposition;
|
|
153
|
+
if (disposition === 'interrupted'
|
|
154
|
+
&& !state.started
|
|
155
|
+
&& (playedMs === null || playedMs <= 0))
|
|
156
|
+
disposition = 'suppressed';
|
|
157
|
+
const completion = this.#completion(state, disposition, playedMs);
|
|
158
|
+
this.#retire(state);
|
|
159
|
+
return completion;
|
|
160
|
+
}
|
|
161
|
+
#completion(state, disposition, playedMs) {
|
|
162
|
+
return {
|
|
163
|
+
session_epoch: state.identity.session_epoch,
|
|
164
|
+
response_id: state.identity.response_id,
|
|
165
|
+
utterance_id: state.identity.utterance_id,
|
|
166
|
+
generation_epoch: state.identity.generation_epoch,
|
|
167
|
+
text: state.transcript,
|
|
168
|
+
disposition,
|
|
169
|
+
started: state.started,
|
|
170
|
+
played_ms: playedMs,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
#find(utteranceId, generationEpoch) {
|
|
174
|
+
const identity = rendererKey(utteranceId, generationEpoch);
|
|
175
|
+
if (this.#rendererTombstoneSet.has(identity))
|
|
176
|
+
return undefined;
|
|
177
|
+
return this.#byRenderer.get(identity);
|
|
178
|
+
}
|
|
179
|
+
#fenceGeneration(generation, alert) {
|
|
180
|
+
const state = this.#stateForGeneration(generation);
|
|
181
|
+
if (state === undefined
|
|
182
|
+
|| state.fenced
|
|
183
|
+
|| state.delivered
|
|
184
|
+
|| this.#currentProviderIdentity !== providerKey(generation.session_epoch, generation.response_id))
|
|
185
|
+
return false;
|
|
186
|
+
state.fenced = true;
|
|
187
|
+
this.#currentProviderIdentity = null;
|
|
188
|
+
if (alert) {
|
|
189
|
+
this.#onAlert(generation.utterance_id, generation.generation_epoch);
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
this.#onClear(generation.utterance_id, generation.generation_epoch);
|
|
193
|
+
}
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
#stateForGeneration(generation) {
|
|
197
|
+
const state = this.#byRenderer.get(rendererKey(generation.utterance_id, generation.generation_epoch));
|
|
198
|
+
return state !== undefined && sameGeneration(state.identity, generation) ? state : undefined;
|
|
199
|
+
}
|
|
200
|
+
#retire(state) {
|
|
201
|
+
const providerIdentity = providerKey(state.identity.session_epoch, state.identity.response_id);
|
|
202
|
+
const rendererIdentity = rendererKey(state.identity.utterance_id, state.identity.generation_epoch);
|
|
203
|
+
if (this.#byProvider.get(providerIdentity) === state)
|
|
204
|
+
this.#byProvider.delete(providerIdentity);
|
|
205
|
+
if (this.#byRenderer.get(rendererIdentity) === state)
|
|
206
|
+
this.#byRenderer.delete(rendererIdentity);
|
|
207
|
+
if (this.#currentProviderIdentity === providerIdentity)
|
|
208
|
+
this.#currentProviderIdentity = null;
|
|
209
|
+
this.#addRendererTombstone(rendererIdentity);
|
|
210
|
+
}
|
|
211
|
+
#addRendererTombstone(rendererIdentity) {
|
|
212
|
+
if (this.#rendererTombstoneSet.has(rendererIdentity))
|
|
213
|
+
return;
|
|
214
|
+
if (this.#rendererTombstones.length === MAX_RENDERER_TOMBSTONES) {
|
|
215
|
+
const expired = this.#rendererTombstones.shift();
|
|
216
|
+
if (expired !== undefined)
|
|
217
|
+
this.#rendererTombstoneSet.delete(expired);
|
|
218
|
+
}
|
|
219
|
+
this.#rendererTombstones.push(rendererIdentity);
|
|
220
|
+
this.#rendererTombstoneSet.add(rendererIdentity);
|
|
221
|
+
}
|
|
222
|
+
#requiredId() {
|
|
223
|
+
const value = this.#idFactory();
|
|
224
|
+
if (value === '')
|
|
225
|
+
throw new Error('playback ids must be non-empty');
|
|
226
|
+
return value;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
function providerKey(sessionEpoch, responseId) {
|
|
230
|
+
return JSON.stringify([sessionEpoch, responseId]);
|
|
231
|
+
}
|
|
232
|
+
function rendererKey(utteranceId, generationEpoch) {
|
|
233
|
+
return JSON.stringify([utteranceId, generationEpoch]);
|
|
234
|
+
}
|
|
235
|
+
function sameGeneration(left, right) {
|
|
236
|
+
return left.session_epoch === right.session_epoch
|
|
237
|
+
&& left.generation_epoch === right.generation_epoch
|
|
238
|
+
&& left.generation_id === right.generation_id
|
|
239
|
+
&& left.utterance_id === right.utterance_id
|
|
240
|
+
&& left.response_id === right.response_id;
|
|
241
|
+
}
|
|
242
|
+
//# sourceMappingURL=playback.js.map
|