@ouro.bot/cli 0.1.0-alpha.6 → 0.1.0-alpha.600
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/README.md +229 -183
- package/RepairGuide.ouro/agent.json +5 -0
- package/RepairGuide.ouro/psyche/IDENTITY.md +19 -0
- package/RepairGuide.ouro/psyche/SOUL.md +55 -0
- package/RepairGuide.ouro/skills/diagnose-broken-remote.md +63 -0
- package/RepairGuide.ouro/skills/diagnose-stacked-typed-issues.md +35 -0
- package/RepairGuide.ouro/skills/diagnose-sync-blocked.md +54 -0
- package/RepairGuide.ouro/skills/diagnose-vault-expired.md +60 -0
- package/SerpentGuide.ouro/agent.json +83 -0
- package/SerpentGuide.ouro/psyche/SOUL.md +25 -0
- package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/monty.md +2 -2
- package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/the-serpent.md +1 -1
- package/assets/ouroboros.png +0 -0
- package/changelog.json +4182 -0
- package/dist/arc/attention-types.js +8 -0
- package/dist/arc/cares.js +140 -0
- package/dist/arc/episodes.js +117 -0
- package/dist/arc/intentions.js +133 -0
- package/dist/arc/json-store.js +117 -0
- package/dist/arc/obligations.js +254 -0
- package/dist/arc/packets.js +193 -0
- package/dist/arc/presence.js +185 -0
- package/dist/arc/task-lifecycle.js +65 -0
- package/dist/heart/active-work.js +989 -0
- package/dist/heart/agent-entry.js +69 -3
- package/dist/heart/attachments/image-normalize.js +194 -0
- package/dist/heart/attachments/materialize.js +97 -0
- package/dist/heart/attachments/originals.js +88 -0
- package/dist/heart/attachments/render.js +29 -0
- package/dist/heart/attachments/sources/adapter.js +2 -0
- package/dist/heart/attachments/sources/bluebubbles.js +156 -0
- package/dist/heart/attachments/sources/cli-local-file.js +78 -0
- package/dist/heart/attachments/sources/index.js +16 -0
- package/dist/heart/attachments/store.js +103 -0
- package/dist/heart/attachments/types.js +93 -0
- package/dist/heart/auth/auth-flow.js +479 -0
- package/dist/heart/awaiting/await-alert.js +146 -0
- package/dist/heart/awaiting/await-expiry.js +108 -0
- package/dist/heart/awaiting/await-loader.js +91 -0
- package/dist/heart/awaiting/await-parser.js +141 -0
- package/dist/heart/awaiting/await-runtime-state.js +97 -0
- package/dist/heart/awaiting/await-scheduler.js +377 -0
- package/dist/heart/background-operations.js +281 -0
- package/dist/heart/bridges/manager.js +358 -0
- package/dist/heart/bridges/state-machine.js +135 -0
- package/dist/heart/bridges/store.js +123 -0
- package/dist/heart/bundle-state.js +168 -0
- package/dist/heart/commitments.js +142 -0
- package/dist/heart/config-registry.js +322 -0
- package/dist/heart/config.js +164 -135
- package/dist/heart/core.js +1069 -260
- package/dist/heart/cross-chat-delivery.js +131 -0
- package/dist/heart/daemon/agent-config-check.js +419 -0
- package/dist/heart/daemon/agent-discovery.js +180 -0
- package/dist/heart/daemon/agent-service.js +522 -0
- package/dist/heart/daemon/agentic-repair.js +547 -0
- package/dist/heart/daemon/bluebubbles-health-diagnostics.js +122 -0
- package/dist/heart/daemon/boot-sync-probe.js +197 -0
- package/dist/heart/daemon/cadence.js +70 -0
- package/dist/heart/daemon/cli-defaults.js +776 -0
- package/dist/heart/daemon/cli-exec.js +7571 -0
- package/dist/heart/daemon/cli-help.js +498 -0
- package/dist/heart/daemon/cli-parse.js +1599 -0
- package/dist/heart/daemon/cli-render-doctor.js +57 -0
- package/dist/heart/daemon/cli-render.js +763 -0
- package/dist/heart/daemon/cli-types.js +8 -0
- package/dist/heart/daemon/connect-bay.js +323 -0
- package/dist/heart/daemon/daemon-cli.js +30 -758
- package/dist/heart/daemon/daemon-entry.js +540 -8
- package/dist/heart/daemon/daemon-health.js +176 -0
- package/dist/heart/daemon/daemon-rollup.js +57 -0
- package/dist/heart/daemon/daemon-runtime-sync.js +287 -0
- package/dist/heart/daemon/daemon-tombstone.js +236 -0
- package/dist/heart/daemon/daemon.js +972 -20
- package/dist/heart/daemon/dns-workflow.js +394 -0
- package/dist/heart/daemon/doctor-types.js +8 -0
- package/dist/heart/daemon/doctor.js +873 -0
- package/dist/heart/daemon/health-monitor.js +122 -1
- package/dist/heart/daemon/hooks/agent-config-v2.js +33 -0
- package/dist/heart/daemon/hooks/bundle-meta.js +206 -0
- package/dist/heart/daemon/http-health-probe.js +80 -0
- package/dist/heart/daemon/human-command-screens.js +234 -0
- package/dist/heart/daemon/human-readiness.js +114 -0
- package/dist/heart/daemon/inner-status.js +89 -0
- package/dist/heart/daemon/interactive-repair.js +394 -0
- package/dist/heart/daemon/launchd.js +188 -0
- package/dist/heart/daemon/log-tailer.js +82 -12
- package/dist/heart/daemon/logs-prune.js +110 -0
- package/dist/heart/daemon/mcp-canary.js +297 -0
- package/dist/heart/daemon/message-router.js +17 -8
- package/dist/heart/daemon/os-cron-deps.js +135 -0
- package/dist/heart/daemon/os-cron.js +14 -12
- package/dist/heart/daemon/ouro-bot-entry.js +4 -2
- package/dist/heart/daemon/ouro-entry.js +3 -1
- package/dist/heart/daemon/process-manager.js +381 -26
- package/dist/heart/daemon/provider-discovery.js +137 -0
- package/dist/heart/daemon/provider-ping-progress.js +83 -0
- package/dist/heart/daemon/pulse.js +475 -0
- package/dist/heart/daemon/readiness-repair.js +365 -0
- package/dist/heart/daemon/run-hooks.js +39 -0
- package/dist/heart/daemon/runtime-logging.js +67 -16
- package/dist/heart/daemon/runtime-metadata.js +191 -0
- package/dist/heart/daemon/runtime-mode.js +67 -0
- package/dist/heart/daemon/safe-mode.js +161 -0
- package/dist/heart/daemon/sense-manager.js +731 -0
- package/dist/heart/daemon/session-id-resolver.js +131 -0
- package/dist/heart/daemon/skill-management-installer.js +94 -0
- package/dist/heart/daemon/socket-client.js +349 -0
- package/dist/heart/daemon/stale-bundle-prune.js +96 -0
- package/dist/heart/daemon/startup-tui.js +330 -0
- package/dist/heart/daemon/task-scheduler.js +3 -25
- package/dist/heart/daemon/terminal-ui.js +499 -0
- package/dist/heart/daemon/thoughts.js +524 -0
- package/dist/heart/daemon/up-progress.js +366 -0
- package/dist/heart/daemon/vault-items.js +56 -0
- package/dist/heart/delegation.js +62 -0
- package/dist/heart/habits/habit-migration.js +189 -0
- package/dist/heart/habits/habit-parser.js +140 -0
- package/dist/heart/habits/habit-runtime-state.js +100 -0
- package/dist/heart/habits/habit-scheduler.js +372 -0
- package/dist/heart/{daemon → hatch}/hatch-animation.js +10 -3
- package/dist/heart/{daemon → hatch}/hatch-flow.js +34 -136
- package/dist/heart/{daemon → hatch}/hatch-specialist.js +6 -8
- package/dist/heart/hatch/specialist-orchestrator.js +129 -0
- package/dist/heart/hatch/specialist-prompt.js +102 -0
- package/dist/heart/hatch/specialist-tools.js +306 -0
- package/dist/heart/identity.js +281 -67
- package/dist/heart/kept-notes.js +357 -0
- package/dist/heart/kicks.js +2 -20
- package/dist/heart/machine-identity.js +161 -0
- package/dist/heart/mail-import-discovery.js +353 -0
- package/dist/heart/mailbox/mailbox-http-hooks.js +66 -0
- package/dist/heart/mailbox/mailbox-http-response.js +7 -0
- package/dist/heart/mailbox/mailbox-http-routes.js +246 -0
- package/dist/heart/mailbox/mailbox-http-static.js +103 -0
- package/dist/heart/mailbox/mailbox-http-transport.js +116 -0
- package/dist/heart/mailbox/mailbox-http.js +99 -0
- package/dist/heart/mailbox/mailbox-read.js +31 -0
- package/dist/heart/mailbox/mailbox-types.js +27 -0
- package/dist/heart/mailbox/mailbox-view.js +195 -0
- package/dist/heart/mailbox/readers/agent-machine.js +382 -0
- package/dist/heart/mailbox/readers/continuity-readers.js +338 -0
- package/dist/heart/mailbox/readers/mail.js +367 -0
- package/dist/heart/mailbox/readers/runtime-readers.js +651 -0
- package/dist/heart/mailbox/readers/sessions.js +232 -0
- package/dist/heart/mailbox/readers/shared.js +111 -0
- package/dist/heart/mcp/mcp-server.js +656 -0
- package/dist/heart/migrate-config.js +100 -0
- package/dist/heart/model-capabilities.js +59 -0
- package/dist/heart/platform.js +81 -0
- package/dist/heart/progress-story.js +42 -0
- package/dist/heart/provider-attempt.js +134 -0
- package/dist/heart/provider-binding-resolver.js +267 -0
- package/dist/heart/provider-credentials.js +425 -0
- package/dist/heart/provider-failover.js +301 -0
- package/dist/heart/provider-models.js +81 -0
- package/dist/heart/provider-ping.js +262 -0
- package/dist/heart/provider-readiness-cache.js +40 -0
- package/dist/heart/provider-visibility.js +188 -0
- package/dist/heart/providers/anthropic-token.js +131 -0
- package/dist/heart/providers/anthropic.js +202 -50
- package/dist/heart/providers/azure.js +104 -13
- package/dist/heart/providers/error-classification.js +127 -0
- package/dist/heart/providers/github-copilot.js +145 -0
- package/dist/heart/providers/minimax-vlm.js +189 -0
- package/dist/heart/providers/minimax.js +29 -7
- package/dist/heart/providers/openai-codex.js +63 -39
- package/dist/heart/runtime-capability-check.js +170 -0
- package/dist/heart/runtime-credentials.js +367 -0
- package/dist/heart/runtime-cwd.js +87 -0
- package/dist/heart/sense-truth.js +70 -0
- package/dist/heart/session-activity.js +190 -0
- package/dist/heart/session-events.js +1149 -0
- package/dist/heart/session-playback-cli-main.js +5 -0
- package/dist/heart/session-playback-cli.js +36 -0
- package/dist/heart/session-playback.js +231 -0
- package/dist/heart/session-stats-cli-main.js +5 -0
- package/dist/heart/session-stats.js +182 -0
- package/dist/heart/session-transcript.js +243 -0
- package/dist/heart/start-of-turn-packet.js +345 -0
- package/dist/heart/streaming.js +129 -34
- package/dist/heart/sync-classification.js +176 -0
- package/dist/heart/sync.js +449 -0
- package/dist/heart/target-resolution.js +127 -0
- package/dist/heart/tempo.js +93 -0
- package/dist/heart/temporal-view.js +41 -0
- package/dist/heart/timeouts.js +101 -0
- package/dist/heart/tool-activity-callbacks.js +59 -0
- package/dist/heart/tool-description.js +143 -0
- package/dist/heart/tool-friction.js +55 -0
- package/dist/heart/tool-loop.js +200 -0
- package/dist/heart/turn-context.js +421 -0
- package/dist/heart/turn-coordinator.js +28 -0
- package/dist/heart/versioning/ouro-bot-global-installer.js +129 -0
- package/dist/heart/{daemon → versioning}/ouro-bot-wrapper.js +1 -1
- package/dist/heart/versioning/ouro-path-installer.js +426 -0
- package/dist/heart/{daemon → versioning}/ouro-uti.js +11 -2
- package/dist/heart/versioning/ouro-version-manager.js +295 -0
- package/dist/heart/versioning/staged-restart.js +146 -0
- package/dist/heart/versioning/update-checker.js +116 -0
- package/dist/heart/versioning/update-hooks.js +142 -0
- package/dist/heart/versioning/wrapper-publish-guard.js +86 -0
- package/dist/mailbox-ui/assets/index-B-461hes.js +61 -0
- package/dist/mailbox-ui/assets/index-BPr5vNuM.css +1 -0
- package/dist/mailbox-ui/index.html +15 -0
- package/dist/mailroom/attention.js +167 -0
- package/dist/mailroom/autonomy.js +209 -0
- package/dist/mailroom/blob-store.js +700 -0
- package/dist/mailroom/body-cache.js +61 -0
- package/dist/mailroom/core.js +788 -0
- package/dist/mailroom/entry.js +160 -0
- package/dist/mailroom/file-store.js +457 -0
- package/dist/mailroom/mbox-import.js +393 -0
- package/dist/mailroom/migration.js +164 -0
- package/dist/mailroom/outbound.js +380 -0
- package/dist/mailroom/policy.js +263 -0
- package/dist/mailroom/reader.js +233 -0
- package/dist/mailroom/search-cache.js +268 -0
- package/dist/mailroom/search-relevance.js +319 -0
- package/dist/mailroom/smtp-ingress.js +176 -0
- package/dist/mailroom/source-state.js +176 -0
- package/dist/mailroom/thread.js +109 -0
- package/dist/mailroom/travel-extract.js +89 -0
- package/dist/mind/bundle-manifest.js +77 -1
- package/dist/mind/context.js +174 -94
- package/dist/mind/diary-integrity.js +60 -0
- package/dist/mind/{memory.js → diary.js} +84 -96
- package/dist/mind/embedding-provider.js +60 -0
- package/dist/mind/file-state.js +179 -0
- package/dist/mind/first-impressions.js +16 -2
- package/dist/mind/friends/channel.js +74 -0
- package/dist/mind/friends/group-context.js +144 -0
- package/dist/mind/friends/resolver.js +54 -2
- package/dist/mind/friends/store-file.js +58 -3
- package/dist/mind/friends/trust-explanation.js +74 -0
- package/dist/mind/friends/types.js +10 -2
- package/dist/mind/journal-index.js +161 -0
- package/dist/mind/note-search.js +268 -0
- package/dist/mind/obligation-steering.js +221 -0
- package/dist/mind/pending.js +76 -9
- package/dist/mind/phrases.js +1 -0
- package/dist/mind/prompt-refresh.js +3 -2
- package/dist/mind/prompt.js +1267 -130
- package/dist/mind/provenance-trust.js +26 -0
- package/dist/mind/scrutiny.js +173 -0
- package/dist/mind/token-estimate.js +8 -12
- package/dist/nerves/cli-logging.js +22 -3
- package/dist/nerves/coverage/audit-rules.js +15 -6
- package/dist/nerves/coverage/audit.js +28 -2
- package/dist/nerves/coverage/cli.js +1 -1
- package/dist/nerves/coverage/contract.js +5 -5
- package/dist/nerves/coverage/file-completeness.js +129 -5
- package/dist/nerves/coverage/run-artifacts.js +1 -1
- package/dist/nerves/event-buffer.js +111 -0
- package/dist/nerves/index.js +224 -4
- package/dist/nerves/observation.js +20 -0
- package/dist/nerves/redact.js +79 -0
- package/dist/nerves/review/cli-main.js +5 -0
- package/dist/nerves/review/cli.js +156 -0
- package/dist/nerves/review/core.js +152 -0
- package/dist/nerves/runtime.js +5 -1
- package/dist/repertoire/ado-client.js +17 -56
- package/dist/repertoire/ado-semantic.js +11 -10
- package/dist/repertoire/api-client.js +97 -0
- package/dist/repertoire/bitwarden-store.js +997 -0
- package/dist/repertoire/bundle-templates.js +72 -0
- package/dist/repertoire/bw-installer.js +180 -0
- package/dist/repertoire/coding/codex-jsonl.js +64 -0
- package/dist/repertoire/coding/context-pack.js +330 -0
- package/dist/repertoire/coding/feedback.js +301 -0
- package/dist/repertoire/coding/index.js +4 -1
- package/dist/repertoire/coding/manager.js +220 -13
- package/dist/repertoire/coding/spawner.js +58 -12
- package/dist/repertoire/coding/tools.js +209 -7
- package/dist/repertoire/commerce-errors.js +109 -0
- package/dist/repertoire/commerce-self-test.js +156 -0
- package/dist/repertoire/credential-access.js +178 -0
- package/dist/repertoire/data/ado-endpoints.json +188 -0
- package/dist/repertoire/duffel-client.js +185 -0
- package/dist/repertoire/github-client.js +14 -55
- package/dist/repertoire/graph-client.js +11 -52
- package/dist/repertoire/guardrails.js +396 -0
- package/dist/repertoire/mcp-client.js +295 -0
- package/dist/repertoire/mcp-manager.js +362 -0
- package/dist/repertoire/mcp-tools.js +63 -0
- package/dist/repertoire/shell-sessions.js +133 -0
- package/dist/repertoire/skills.js +15 -24
- package/dist/repertoire/stripe-client.js +131 -0
- package/dist/repertoire/tasks/board.js +43 -5
- package/dist/repertoire/tasks/fix.js +182 -0
- package/dist/repertoire/tasks/index.js +39 -13
- package/dist/repertoire/tasks/lifecycle.js +2 -2
- package/dist/repertoire/tasks/parser.js +3 -2
- package/dist/repertoire/tasks/scanner.js +194 -37
- package/dist/repertoire/tasks/transitions.js +16 -79
- package/dist/repertoire/tool-results.js +29 -0
- package/dist/repertoire/tools-attachments.js +317 -0
- package/dist/repertoire/tools-awaiting.js +360 -0
- package/dist/repertoire/tools-base.js +56 -707
- package/dist/repertoire/tools-bluebubbles.js +94 -0
- package/dist/repertoire/tools-bridge.js +142 -0
- package/dist/repertoire/tools-bundle.js +984 -0
- package/dist/repertoire/tools-config.js +185 -0
- package/dist/repertoire/tools-continuity.js +248 -0
- package/dist/repertoire/tools-credential.js +381 -0
- package/dist/repertoire/tools-files.js +342 -0
- package/dist/repertoire/tools-flight.js +224 -0
- package/dist/repertoire/tools-flow.js +119 -0
- package/dist/repertoire/tools-github.js +1 -7
- package/dist/repertoire/tools-mail.js +1916 -0
- package/dist/repertoire/tools-notes.js +421 -0
- package/dist/repertoire/tools-obligations.js +142 -0
- package/dist/repertoire/tools-runtime.js +61 -0
- package/dist/repertoire/tools-session.js +809 -0
- package/dist/repertoire/tools-shell.js +120 -0
- package/dist/repertoire/tools-stripe.js +180 -0
- package/dist/repertoire/tools-surface.js +345 -0
- package/dist/repertoire/tools-teams.js +64 -61
- package/dist/repertoire/tools-travel.js +125 -0
- package/dist/repertoire/tools-trip.js +604 -0
- package/dist/repertoire/tools-user-profile.js +144 -0
- package/dist/repertoire/tools-vault.js +40 -0
- package/dist/repertoire/tools-voice.js +144 -0
- package/dist/repertoire/tools.js +154 -98
- package/dist/repertoire/travel-api-client.js +360 -0
- package/dist/repertoire/user-profile.js +131 -0
- package/dist/repertoire/vault-setup.js +246 -0
- package/dist/repertoire/vault-unlock.js +594 -0
- package/dist/scripts/claude-code-hook.js +41 -0
- package/dist/scripts/claude-code-stop-hook.js +47 -0
- package/dist/senses/attention-queue.js +116 -0
- package/dist/senses/await-turn-message.js +58 -0
- package/dist/senses/bluebubbles/active-turns.js +216 -0
- package/dist/senses/bluebubbles/attachment-cache.js +53 -0
- package/dist/senses/bluebubbles/attachment-download.js +137 -0
- package/dist/senses/bluebubbles/client.js +685 -0
- package/dist/senses/bluebubbles/entry.js +77 -0
- package/dist/senses/bluebubbles/inbound-log.js +126 -0
- package/dist/senses/bluebubbles/index.js +2548 -0
- package/dist/senses/bluebubbles/media.js +389 -0
- package/dist/senses/{bluebubbles-model.js → bluebubbles/model.js} +45 -16
- package/dist/senses/{bluebubbles-mutation-log.js → bluebubbles/mutation-log.js} +46 -6
- package/dist/senses/bluebubbles/processed-log.js +133 -0
- package/dist/senses/bluebubbles/replay.js +137 -0
- package/dist/senses/bluebubbles/runtime-state.js +137 -0
- package/dist/senses/bluebubbles/session-cleanup.js +72 -0
- package/dist/senses/bluebubbles-meta-guard.js +40 -0
- package/dist/senses/cli/bracketed-paste.js +82 -0
- package/dist/senses/cli/image-paste.js +287 -0
- package/dist/senses/cli/image-ref-navigation.js +75 -0
- package/dist/senses/cli/ink-app.js +156 -0
- package/dist/senses/cli/inline-diff.js +64 -0
- package/dist/senses/cli/input-keys.js +174 -0
- package/dist/senses/cli/kill-ring.js +86 -0
- package/dist/senses/cli/message-list.js +51 -0
- package/dist/senses/cli/ouro-tui.js +607 -0
- package/dist/senses/cli/spinner-imperative.js +135 -0
- package/dist/senses/cli/spinner.js +101 -0
- package/dist/senses/cli/status-line.js +60 -0
- package/dist/senses/cli/streaming-markdown.js +526 -0
- package/dist/senses/cli/tool-display.js +85 -0
- package/dist/senses/cli/tool-render.js +85 -0
- package/dist/senses/cli/tui-store.js +240 -0
- package/dist/senses/cli/virtual-list.js +35 -0
- package/dist/senses/cli-entry.js +60 -8
- package/dist/senses/cli-layout.js +187 -0
- package/dist/senses/cli.js +777 -264
- package/dist/senses/commands.js +66 -3
- package/dist/senses/continuity.js +94 -0
- package/dist/senses/habit-turn-message.js +108 -0
- package/dist/senses/inner-dialog-worker.js +209 -16
- package/dist/senses/inner-dialog.js +682 -91
- package/dist/senses/mail-entry.js +66 -0
- package/dist/senses/mail.js +379 -0
- package/dist/senses/pipeline.js +751 -0
- package/dist/senses/proactive-content-guard.js +51 -0
- package/dist/senses/shared-turn.js +392 -0
- package/dist/senses/surface-tool.js +70 -0
- package/dist/senses/teams-entry.js +60 -8
- package/dist/senses/teams.js +925 -195
- package/dist/senses/trust-gate.js +207 -2
- package/dist/senses/voice/audio-playback.js +237 -0
- package/dist/senses/voice/audio-routing.js +119 -0
- package/dist/senses/voice/elevenlabs.js +202 -0
- package/dist/senses/voice/floor-control.js +431 -0
- package/dist/senses/voice/floor-controller.js +115 -0
- package/dist/senses/voice/golden-path.js +116 -0
- package/dist/senses/voice/index.js +29 -0
- package/dist/senses/voice/meeting.js +113 -0
- package/dist/senses/voice/outbound.js +190 -0
- package/dist/senses/voice/phone.js +33 -0
- package/dist/senses/voice/playback.js +139 -0
- package/dist/senses/voice/realtime-eval.js +496 -0
- package/dist/senses/voice/realtime-trace.js +531 -0
- package/dist/senses/voice/transcript.js +70 -0
- package/dist/senses/voice/turn.js +191 -0
- package/dist/senses/voice/twilio-phone-runtime.js +807 -0
- package/dist/senses/voice/twilio-phone.js +5077 -0
- package/dist/senses/voice/types.js +2 -0
- package/dist/senses/voice/whisper.js +161 -0
- package/dist/senses/voice-entry.js +81 -0
- package/dist/senses/voice-realtime-eval-command.js +99 -0
- package/dist/senses/voice-realtime-eval-entry.js +21 -0
- package/dist/senses/voice-twilio-entry.js +87 -0
- package/dist/trips/core.js +138 -0
- package/dist/trips/store.js +265 -0
- package/package.json +52 -7
- package/skills/agent-commerce.md +106 -0
- package/skills/browser-navigation.md +117 -0
- package/skills/commerce-setup-guide.md +116 -0
- package/skills/commerce-setup.md +84 -0
- package/skills/configure-dev-tools.md +99 -0
- package/skills/travel-planning.md +138 -0
- package/AdoptionSpecialist.ouro/agent.json +0 -20
- package/AdoptionSpecialist.ouro/psyche/SOUL.md +0 -22
- package/dist/heart/daemon/specialist-orchestrator.js +0 -160
- package/dist/heart/daemon/specialist-prompt.js +0 -40
- package/dist/heart/daemon/specialist-session.js +0 -142
- package/dist/heart/daemon/specialist-tools.js +0 -128
- package/dist/heart/daemon/subagent-installer.js +0 -125
- package/dist/inner-worker-entry.js +0 -4
- package/dist/mind/associative-recall.js +0 -197
- package/dist/senses/bluebubbles-client.js +0 -279
- package/dist/senses/bluebubbles-entry.js +0 -11
- package/dist/senses/bluebubbles.js +0 -332
- package/subagents/README.md +0 -73
- package/subagents/work-doer.md +0 -233
- package/subagents/work-merger.md +0 -624
- package/subagents/work-planner.md +0 -373
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/basilisk.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/jafar.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/jormungandr.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/kaa.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/medusa.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/nagini.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/ouroboros.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/python.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/quetzalcoatl.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/sir-hiss.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/the-snake.md +0 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_ELEVENLABS_MIME_TYPE = exports.DEFAULT_ELEVENLABS_OUTPUT_FORMAT = exports.DEFAULT_ELEVENLABS_MODEL_ID = void 0;
|
|
4
|
+
exports.createNodeElevenLabsSocketFactory = createNodeElevenLabsSocketFactory;
|
|
5
|
+
exports.createElevenLabsTtsClient = createElevenLabsTtsClient;
|
|
6
|
+
const runtime_1 = require("../../nerves/runtime");
|
|
7
|
+
exports.DEFAULT_ELEVENLABS_MODEL_ID = "eleven_flash_v2_5";
|
|
8
|
+
exports.DEFAULT_ELEVENLABS_OUTPUT_FORMAT = "pcm_16000";
|
|
9
|
+
exports.DEFAULT_ELEVENLABS_MIME_TYPE = "audio/pcm;rate=16000";
|
|
10
|
+
function cleanTtsText(text) {
|
|
11
|
+
return text.replace(/\s+/g, " ").trim();
|
|
12
|
+
}
|
|
13
|
+
function elevenLabsStreamUrl(voiceId, modelId, outputFormat, autoMode) {
|
|
14
|
+
const params = new URLSearchParams({ model_id: modelId, output_format: outputFormat });
|
|
15
|
+
if (autoMode)
|
|
16
|
+
params.set("auto_mode", "true");
|
|
17
|
+
return `wss://api.elevenlabs.io/v1/text-to-speech/${encodeURIComponent(voiceId)}/stream-input?${params.toString()}`;
|
|
18
|
+
}
|
|
19
|
+
function mimeTypeForOutputFormat(outputFormat) {
|
|
20
|
+
if (outputFormat === "pcm_16000")
|
|
21
|
+
return "audio/pcm;rate=16000";
|
|
22
|
+
if (outputFormat === "ulaw_8000")
|
|
23
|
+
return "audio/x-mulaw;rate=8000";
|
|
24
|
+
if (outputFormat.startsWith("pcm_")) {
|
|
25
|
+
const rate = outputFormat.slice("pcm_".length);
|
|
26
|
+
return /^\d+$/.test(rate) ? `audio/pcm;rate=${rate}` : "audio/pcm";
|
|
27
|
+
}
|
|
28
|
+
return "audio/mpeg";
|
|
29
|
+
}
|
|
30
|
+
function payloadText(payload) {
|
|
31
|
+
if (payload && typeof payload === "object" && "data" in payload) {
|
|
32
|
+
return payloadText(payload.data);
|
|
33
|
+
}
|
|
34
|
+
if (typeof payload === "string")
|
|
35
|
+
return payload;
|
|
36
|
+
if (Buffer.isBuffer(payload))
|
|
37
|
+
return payload.toString("utf8");
|
|
38
|
+
return String(payload ?? "");
|
|
39
|
+
}
|
|
40
|
+
function createNodeElevenLabsSocketFactory(webSocketConstructor) {
|
|
41
|
+
const WebSocketConstructor = webSocketConstructor
|
|
42
|
+
?? globalThis.WebSocket;
|
|
43
|
+
if (!WebSocketConstructor) {
|
|
44
|
+
throw new Error("global WebSocket is unavailable; inject an ElevenLabs socketFactory");
|
|
45
|
+
}
|
|
46
|
+
return (url) => {
|
|
47
|
+
const socket = new WebSocketConstructor(url);
|
|
48
|
+
const handlers = {
|
|
49
|
+
open: [],
|
|
50
|
+
message: [],
|
|
51
|
+
error: [],
|
|
52
|
+
close: [],
|
|
53
|
+
};
|
|
54
|
+
const emit = (event, payload) => {
|
|
55
|
+
for (const handler of handlers[event]) {
|
|
56
|
+
handler(payload);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const attach = (event) => {
|
|
60
|
+
const listener = (payload) => emit(event, payload);
|
|
61
|
+
if (typeof socket.addEventListener === "function") {
|
|
62
|
+
socket.addEventListener(event, listener);
|
|
63
|
+
}
|
|
64
|
+
else if (typeof socket.on === "function") {
|
|
65
|
+
socket.on(event, listener);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
socket[`on${event}`] = listener;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
attach("open");
|
|
72
|
+
attach("message");
|
|
73
|
+
attach("error");
|
|
74
|
+
attach("close");
|
|
75
|
+
return {
|
|
76
|
+
on(event, handler) {
|
|
77
|
+
handlers[event].push(handler);
|
|
78
|
+
},
|
|
79
|
+
send(payload) {
|
|
80
|
+
socket.send(payload);
|
|
81
|
+
},
|
|
82
|
+
close() {
|
|
83
|
+
socket.close();
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function createElevenLabsTtsClient(options) {
|
|
89
|
+
const modelId = options.modelId ?? exports.DEFAULT_ELEVENLABS_MODEL_ID;
|
|
90
|
+
const outputFormat = options.outputFormat ?? exports.DEFAULT_ELEVENLABS_OUTPUT_FORMAT;
|
|
91
|
+
const autoMode = options.autoMode ?? true;
|
|
92
|
+
const socketFactory = options.socketFactory ?? createNodeElevenLabsSocketFactory();
|
|
93
|
+
const mimeType = mimeTypeForOutputFormat(outputFormat);
|
|
94
|
+
return {
|
|
95
|
+
async synthesize(request) {
|
|
96
|
+
const text = cleanTtsText(request.text);
|
|
97
|
+
if (!text) {
|
|
98
|
+
(0, runtime_1.emitNervesEvent)({
|
|
99
|
+
level: "error",
|
|
100
|
+
component: "senses",
|
|
101
|
+
event: "senses.voice_tts_error",
|
|
102
|
+
message: "voice TTS text is empty",
|
|
103
|
+
meta: { utteranceId: request.utteranceId },
|
|
104
|
+
});
|
|
105
|
+
throw new Error("voice TTS text is empty");
|
|
106
|
+
}
|
|
107
|
+
const url = elevenLabsStreamUrl(options.voiceId, modelId, outputFormat, autoMode);
|
|
108
|
+
const socket = socketFactory(url);
|
|
109
|
+
const chunks = [];
|
|
110
|
+
(0, runtime_1.emitNervesEvent)({
|
|
111
|
+
component: "senses",
|
|
112
|
+
event: "senses.voice_tts_start",
|
|
113
|
+
message: "starting ElevenLabs TTS",
|
|
114
|
+
meta: { utteranceId: request.utteranceId, modelId, voiceId: options.voiceId },
|
|
115
|
+
});
|
|
116
|
+
return new Promise((resolve, reject) => {
|
|
117
|
+
let settled = false;
|
|
118
|
+
const fail = (error) => {
|
|
119
|
+
if (settled)
|
|
120
|
+
return;
|
|
121
|
+
settled = true;
|
|
122
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
123
|
+
(0, runtime_1.emitNervesEvent)({
|
|
124
|
+
level: "error",
|
|
125
|
+
component: "senses",
|
|
126
|
+
event: "senses.voice_tts_error",
|
|
127
|
+
message: "ElevenLabs TTS failed",
|
|
128
|
+
meta: { utteranceId: request.utteranceId, error: message },
|
|
129
|
+
});
|
|
130
|
+
reject(new Error(`ElevenLabs TTS failed: ${message}`));
|
|
131
|
+
};
|
|
132
|
+
const finish = () => {
|
|
133
|
+
if (settled)
|
|
134
|
+
return;
|
|
135
|
+
settled = true;
|
|
136
|
+
const audio = Buffer.concat(chunks);
|
|
137
|
+
(0, runtime_1.emitNervesEvent)({
|
|
138
|
+
component: "senses",
|
|
139
|
+
event: "senses.voice_tts_end",
|
|
140
|
+
message: "finished ElevenLabs TTS",
|
|
141
|
+
meta: { utteranceId: request.utteranceId, chunkCount: chunks.length, byteLength: audio.byteLength },
|
|
142
|
+
});
|
|
143
|
+
socket.close();
|
|
144
|
+
resolve({
|
|
145
|
+
utteranceId: request.utteranceId,
|
|
146
|
+
audio,
|
|
147
|
+
byteLength: audio.byteLength,
|
|
148
|
+
chunkCount: chunks.length,
|
|
149
|
+
modelId,
|
|
150
|
+
voiceId: options.voiceId,
|
|
151
|
+
mimeType,
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
socket.on("open", () => {
|
|
155
|
+
socket.send(JSON.stringify({
|
|
156
|
+
text: " ",
|
|
157
|
+
xi_api_key: options.apiKey,
|
|
158
|
+
voice_settings: {
|
|
159
|
+
stability: 0.5,
|
|
160
|
+
similarity_boost: 0.8,
|
|
161
|
+
use_speaker_boost: true,
|
|
162
|
+
},
|
|
163
|
+
}));
|
|
164
|
+
socket.send(JSON.stringify({ text, try_trigger_generation: true }));
|
|
165
|
+
socket.send(JSON.stringify({ text: "" }));
|
|
166
|
+
});
|
|
167
|
+
socket.on("message", (payload) => {
|
|
168
|
+
try {
|
|
169
|
+
const parsed = JSON.parse(payloadText(payload));
|
|
170
|
+
if (typeof parsed.audio === "string" && parsed.audio.length > 0) {
|
|
171
|
+
const chunk = Buffer.from(parsed.audio, "base64");
|
|
172
|
+
chunks.push(chunk);
|
|
173
|
+
if (request.onAudioChunk) {
|
|
174
|
+
try {
|
|
175
|
+
const chunkResult = request.onAudioChunk(chunk);
|
|
176
|
+
if (chunkResult && typeof chunkResult.then === "function") {
|
|
177
|
+
void chunkResult.catch(fail);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
fail(error);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if (parsed.isFinal === true) {
|
|
186
|
+
finish();
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
fail(error);
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
socket.on("error", fail);
|
|
194
|
+
socket.on("close", () => {
|
|
195
|
+
if (!settled) {
|
|
196
|
+
fail(new Error("socket closed before final audio"));
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
},
|
|
201
|
+
};
|
|
202
|
+
}
|
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createInitialVoiceFloorState = createInitialVoiceFloorState;
|
|
4
|
+
exports.canRequestVoiceResponse = canRequestVoiceResponse;
|
|
5
|
+
exports.canSpeakToolHolding = canSpeakToolHolding;
|
|
6
|
+
exports.canSpeakToolResult = canSpeakToolResult;
|
|
7
|
+
exports.applyVoiceFloorEvent = applyVoiceFloorEvent;
|
|
8
|
+
exports.replayVoiceFloorEvents = replayVoiceFloorEvents;
|
|
9
|
+
exports.summarizeVoiceFloorState = summarizeVoiceFloorState;
|
|
10
|
+
const runtime_1 = require("../../nerves/runtime");
|
|
11
|
+
const MAX_TOOL_HOLDING_WORDS = 6;
|
|
12
|
+
function createInitialVoiceFloorState() {
|
|
13
|
+
return {
|
|
14
|
+
phase: "idle",
|
|
15
|
+
floorOwner: "none",
|
|
16
|
+
terminal: false,
|
|
17
|
+
hangupRequested: false,
|
|
18
|
+
pendingToolCallIds: [],
|
|
19
|
+
staleToolCallIds: [],
|
|
20
|
+
spokenToolCallIds: [],
|
|
21
|
+
callerTurnIds: [],
|
|
22
|
+
toolCalls: {},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function decision(allowed, action, reason, details = {}) {
|
|
26
|
+
return { allowed, action, reason, ...details };
|
|
27
|
+
}
|
|
28
|
+
function copyState(state) {
|
|
29
|
+
return {
|
|
30
|
+
...state,
|
|
31
|
+
pendingToolCallIds: [...state.pendingToolCallIds],
|
|
32
|
+
staleToolCallIds: [...state.staleToolCallIds],
|
|
33
|
+
spokenToolCallIds: [...state.spokenToolCallIds],
|
|
34
|
+
callerTurnIds: [...state.callerTurnIds],
|
|
35
|
+
toolCalls: { ...state.toolCalls },
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function withUnique(values, value) {
|
|
39
|
+
return values.includes(value) ? values : [...values, value];
|
|
40
|
+
}
|
|
41
|
+
function withoutValue(values, value) {
|
|
42
|
+
return values.filter((candidate) => candidate !== value);
|
|
43
|
+
}
|
|
44
|
+
function rememberCallerTurn(state, turnId) {
|
|
45
|
+
state.latestCallerTurnId = turnId;
|
|
46
|
+
state.callerTurnIds = withUnique(state.callerTurnIds, turnId);
|
|
47
|
+
}
|
|
48
|
+
function hasNewerCallerTurn(state, turnId) {
|
|
49
|
+
if (!turnId || !state.latestCallerTurnId || state.latestCallerTurnId === turnId)
|
|
50
|
+
return false;
|
|
51
|
+
const originalIndex = state.callerTurnIds.indexOf(turnId);
|
|
52
|
+
const latestIndex = state.callerTurnIds.indexOf(state.latestCallerTurnId);
|
|
53
|
+
return originalIndex >= 0 && latestIndex > originalIndex;
|
|
54
|
+
}
|
|
55
|
+
function toolState(state, toolCallId) {
|
|
56
|
+
return state.toolCalls[toolCallId];
|
|
57
|
+
}
|
|
58
|
+
function setToolState(state, nextTool) {
|
|
59
|
+
state.toolCalls = { ...state.toolCalls, [nextTool.toolCallId]: nextTool };
|
|
60
|
+
}
|
|
61
|
+
function phaseAfterAssistantSpeech(state) {
|
|
62
|
+
const pendingTools = state.pendingToolCallIds.map((toolCallId) => state.toolCalls[toolCallId]).filter(Boolean);
|
|
63
|
+
if (pendingTools.some((tool) => tool.status === "ready"))
|
|
64
|
+
return "tool-result-ready";
|
|
65
|
+
if (pendingTools.some((tool) => tool.status === "running"))
|
|
66
|
+
return "tool-running";
|
|
67
|
+
return "listening";
|
|
68
|
+
}
|
|
69
|
+
function suppressForHangup(state, event) {
|
|
70
|
+
return {
|
|
71
|
+
event,
|
|
72
|
+
state,
|
|
73
|
+
decision: decision(false, "suppress", "hangup_terminal", { atMs: event.atMs }),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function canRequestVoiceResponse(state, input) {
|
|
77
|
+
if (state.terminal || state.hangupRequested || state.floorOwner === "terminal") {
|
|
78
|
+
return decision(false, "suppress", "hangup_terminal", { responseId: input.responseId });
|
|
79
|
+
}
|
|
80
|
+
if (state.floorOwner === "caller" || state.phase === "caller-speaking" || state.phase === "interrupted") {
|
|
81
|
+
return decision(false, "delay", "caller_has_floor", { responseId: input.responseId });
|
|
82
|
+
}
|
|
83
|
+
if (state.floorOwner === "assistant" || state.activeAssistantSpeechId) {
|
|
84
|
+
return decision(false, "delay", "assistant_has_floor", { responseId: input.responseId });
|
|
85
|
+
}
|
|
86
|
+
if (state.pendingSpeech) {
|
|
87
|
+
return decision(false, "delay", "response_pending", { responseId: input.responseId });
|
|
88
|
+
}
|
|
89
|
+
return decision(true, "allow", "ready_for_response", { responseId: input.responseId });
|
|
90
|
+
}
|
|
91
|
+
function canSpeakToolHolding(state, input) {
|
|
92
|
+
if (state.terminal || state.hangupRequested || state.floorOwner === "terminal") {
|
|
93
|
+
return decision(false, "suppress", "hangup_terminal", { toolCallId: input.toolCallId });
|
|
94
|
+
}
|
|
95
|
+
if (state.floorOwner === "caller" || state.phase === "caller-speaking" || state.phase === "interrupted") {
|
|
96
|
+
return decision(false, "delay", "caller_has_floor", { toolCallId: input.toolCallId });
|
|
97
|
+
}
|
|
98
|
+
const tool = toolState(state, input.toolCallId);
|
|
99
|
+
if (!tool || tool.status === "spoken") {
|
|
100
|
+
return decision(false, "suppress", "missing_tool_call", { toolCallId: input.toolCallId });
|
|
101
|
+
}
|
|
102
|
+
if (tool.status === "stale" || state.staleToolCallIds.includes(input.toolCallId)) {
|
|
103
|
+
return decision(false, "suppress", "stale_tool_result", { toolCallId: input.toolCallId });
|
|
104
|
+
}
|
|
105
|
+
const words = input.text?.trim().split(/\s+/).filter(Boolean).length ?? 0;
|
|
106
|
+
if (words > MAX_TOOL_HOLDING_WORDS) {
|
|
107
|
+
return decision(false, "suppress", "tool_holding_too_long", { toolCallId: input.toolCallId });
|
|
108
|
+
}
|
|
109
|
+
return decision(true, "allow", "tool_presence_allowed", { toolCallId: input.toolCallId });
|
|
110
|
+
}
|
|
111
|
+
function canSpeakToolResult(state, input) {
|
|
112
|
+
if (state.terminal || state.hangupRequested || state.floorOwner === "terminal") {
|
|
113
|
+
return decision(false, "suppress", "hangup_terminal", { toolCallId: input.toolCallId });
|
|
114
|
+
}
|
|
115
|
+
if (state.floorOwner === "caller" || state.phase === "caller-speaking" || state.phase === "interrupted") {
|
|
116
|
+
return decision(false, "delay", "caller_has_floor", { toolCallId: input.toolCallId });
|
|
117
|
+
}
|
|
118
|
+
const tool = toolState(state, input.toolCallId);
|
|
119
|
+
if (!tool || tool.status === "spoken") {
|
|
120
|
+
return decision(false, "suppress", "missing_tool_result", { toolCallId: input.toolCallId });
|
|
121
|
+
}
|
|
122
|
+
if (tool.status === "stale" || state.staleToolCallIds.includes(input.toolCallId)) {
|
|
123
|
+
return decision(false, "suppress", "stale_tool_result", { toolCallId: input.toolCallId });
|
|
124
|
+
}
|
|
125
|
+
if (tool.status !== "ready") {
|
|
126
|
+
return decision(false, "delay", "tool_still_running", { toolCallId: input.toolCallId });
|
|
127
|
+
}
|
|
128
|
+
return decision(true, "allow", "tool_result_ready", { toolCallId: input.toolCallId });
|
|
129
|
+
}
|
|
130
|
+
function applyConnected(state, event) {
|
|
131
|
+
const next = copyState(state);
|
|
132
|
+
next.phase = "listening";
|
|
133
|
+
next.floorOwner = "none";
|
|
134
|
+
next.terminal = false;
|
|
135
|
+
next.hangupRequested = false;
|
|
136
|
+
next.callId = event.callId;
|
|
137
|
+
return { event, state: next, decision: decision(true, "allow", "call_connected", { atMs: event.atMs }) };
|
|
138
|
+
}
|
|
139
|
+
function applyCallerSpeechStarted(state, event) {
|
|
140
|
+
const next = copyState(state);
|
|
141
|
+
rememberCallerTurn(next, event.turnId);
|
|
142
|
+
next.floorOwner = "caller";
|
|
143
|
+
if (state.activeAssistantSpeechId) {
|
|
144
|
+
next.phase = "interrupted";
|
|
145
|
+
next.interruption = {
|
|
146
|
+
turnId: event.turnId,
|
|
147
|
+
interruptedSpeechId: state.activeAssistantSpeechId,
|
|
148
|
+
atMs: event.atMs,
|
|
149
|
+
};
|
|
150
|
+
return {
|
|
151
|
+
event,
|
|
152
|
+
state: next,
|
|
153
|
+
decision: decision(false, "cancel", "caller_barge_in", {
|
|
154
|
+
atMs: event.atMs,
|
|
155
|
+
responseId: state.activeAssistantSpeechId,
|
|
156
|
+
interruptionTurnId: event.turnId,
|
|
157
|
+
}),
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
next.phase = "caller-speaking";
|
|
161
|
+
return { event, state: next, decision: decision(true, "allow", "caller_floor_started", { atMs: event.atMs }) };
|
|
162
|
+
}
|
|
163
|
+
function applyCallerSpeechEnded(state, event) {
|
|
164
|
+
const next = copyState(state);
|
|
165
|
+
rememberCallerTurn(next, event.turnId);
|
|
166
|
+
if (!next.activeAssistantSpeechId) {
|
|
167
|
+
next.floorOwner = "none";
|
|
168
|
+
next.phase = "listening";
|
|
169
|
+
}
|
|
170
|
+
return { event, state: next, decision: decision(true, "allow", "caller_floor_released", { atMs: event.atMs }) };
|
|
171
|
+
}
|
|
172
|
+
function applyCallerTranscriptFinal(state, event) {
|
|
173
|
+
const next = copyState(state);
|
|
174
|
+
rememberCallerTurn(next, event.turnId);
|
|
175
|
+
if (!next.activeAssistantSpeechId) {
|
|
176
|
+
next.floorOwner = "none";
|
|
177
|
+
next.phase = "thinking";
|
|
178
|
+
}
|
|
179
|
+
return { event, state: next, decision: decision(true, "allow", "caller_turn_ready", { atMs: event.atMs }) };
|
|
180
|
+
}
|
|
181
|
+
function applyCallerTurnDismissed(state, event) {
|
|
182
|
+
if (state.latestCallerTurnId !== event.turnId) {
|
|
183
|
+
return {
|
|
184
|
+
event,
|
|
185
|
+
state,
|
|
186
|
+
decision: decision(false, "suppress", "stale_caller_turn", { atMs: event.atMs }),
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
if (state.floorOwner !== "caller") {
|
|
190
|
+
return {
|
|
191
|
+
event,
|
|
192
|
+
state,
|
|
193
|
+
decision: decision(true, "allow", "caller_turn_already_released", { atMs: event.atMs }),
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
const next = copyState(state);
|
|
197
|
+
if (next.activeAssistantSpeechId) {
|
|
198
|
+
next.floorOwner = "assistant";
|
|
199
|
+
next.phase = "speaking";
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
next.floorOwner = "none";
|
|
203
|
+
next.phase = "thinking";
|
|
204
|
+
}
|
|
205
|
+
next.interruption = undefined;
|
|
206
|
+
return {
|
|
207
|
+
event,
|
|
208
|
+
state: next,
|
|
209
|
+
decision: decision(true, "allow", "caller_turn_dismissed", { atMs: event.atMs }),
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
function applyAssistantResponseRequested(state, event) {
|
|
213
|
+
const requestDecision = canRequestVoiceResponse(state, { responseId: event.responseId, reason: event.reason });
|
|
214
|
+
if (!requestDecision.allowed)
|
|
215
|
+
return { event, state, decision: { ...requestDecision, atMs: event.atMs } };
|
|
216
|
+
const next = copyState(state);
|
|
217
|
+
next.phase = "thinking";
|
|
218
|
+
next.floorOwner = "none";
|
|
219
|
+
next.pendingSpeech = { responseId: event.responseId, reason: event.reason };
|
|
220
|
+
return { event, state: next, decision: { ...requestDecision, atMs: event.atMs } };
|
|
221
|
+
}
|
|
222
|
+
function applyAssistantSpeechStarted(state, event) {
|
|
223
|
+
const requestDecision = state.floorOwner === "caller"
|
|
224
|
+
? decision(false, "delay", "caller_has_floor", { atMs: event.atMs, responseId: event.responseId })
|
|
225
|
+
: decision(true, "allow", "assistant_speech_allowed", { atMs: event.atMs, responseId: event.responseId });
|
|
226
|
+
if (!requestDecision.allowed)
|
|
227
|
+
return { event, state, decision: requestDecision };
|
|
228
|
+
const next = copyState(state);
|
|
229
|
+
next.phase = "speaking";
|
|
230
|
+
next.floorOwner = "assistant";
|
|
231
|
+
next.activeAssistantSpeechId = event.responseId;
|
|
232
|
+
next.pendingSpeech = undefined;
|
|
233
|
+
return { event, state: next, decision: requestDecision };
|
|
234
|
+
}
|
|
235
|
+
function applyAssistantSpeechDone(state, event) {
|
|
236
|
+
const next = copyState(state);
|
|
237
|
+
if (next.activeAssistantSpeechId === event.responseId)
|
|
238
|
+
next.activeAssistantSpeechId = undefined;
|
|
239
|
+
if (next.floorOwner === "assistant")
|
|
240
|
+
next.floorOwner = "none";
|
|
241
|
+
next.phase = phaseAfterAssistantSpeech(next);
|
|
242
|
+
return { event, state: next, decision: decision(true, "allow", "assistant_speech_done", { atMs: event.atMs, responseId: event.responseId }) };
|
|
243
|
+
}
|
|
244
|
+
function applyAssistantSpeechCancelled(state, event) {
|
|
245
|
+
const next = copyState(state);
|
|
246
|
+
if (next.activeAssistantSpeechId === event.responseId)
|
|
247
|
+
next.activeAssistantSpeechId = undefined;
|
|
248
|
+
if (next.interruption) {
|
|
249
|
+
next.floorOwner = "caller";
|
|
250
|
+
next.phase = "caller-speaking";
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
next.floorOwner = "none";
|
|
254
|
+
next.phase = phaseAfterAssistantSpeech(next);
|
|
255
|
+
}
|
|
256
|
+
return {
|
|
257
|
+
event,
|
|
258
|
+
state: next,
|
|
259
|
+
decision: decision(true, "allow", "assistant_speech_cancelled", { atMs: event.atMs, responseId: event.responseId }),
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
function applyToolStarted(state, event) {
|
|
263
|
+
if (state.toolCalls[event.toolCallId]) {
|
|
264
|
+
return {
|
|
265
|
+
event,
|
|
266
|
+
state,
|
|
267
|
+
decision: decision(true, "allow", "duplicate_tool_start_ignored", { atMs: event.atMs, toolCallId: event.toolCallId }),
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
const next = copyState(state);
|
|
271
|
+
next.pendingToolCallIds = withUnique(next.pendingToolCallIds, event.toolCallId);
|
|
272
|
+
setToolState(next, {
|
|
273
|
+
toolCallId: event.toolCallId,
|
|
274
|
+
toolName: event.toolName,
|
|
275
|
+
turnId: event.turnId ?? next.latestCallerTurnId,
|
|
276
|
+
status: "running",
|
|
277
|
+
startedAtMs: event.atMs,
|
|
278
|
+
});
|
|
279
|
+
if (next.floorOwner === "none")
|
|
280
|
+
next.phase = "tool-running";
|
|
281
|
+
return { event, state: next, decision: decision(true, "allow", "tool_started", { atMs: event.atMs, toolCallId: event.toolCallId }) };
|
|
282
|
+
}
|
|
283
|
+
function applyToolHoldingSpoken(state, event) {
|
|
284
|
+
const holdingDecision = canSpeakToolHolding(state, { toolCallId: event.toolCallId, text: event.text });
|
|
285
|
+
if (!holdingDecision.allowed)
|
|
286
|
+
return { event, state, decision: { ...holdingDecision, atMs: event.atMs } };
|
|
287
|
+
return { event, state, decision: { ...holdingDecision, atMs: event.atMs } };
|
|
288
|
+
}
|
|
289
|
+
function applyToolCompleted(state, event) {
|
|
290
|
+
const existing = toolState(state, event.toolCallId);
|
|
291
|
+
if (!existing) {
|
|
292
|
+
return {
|
|
293
|
+
event,
|
|
294
|
+
state,
|
|
295
|
+
decision: decision(false, "suppress", "missing_tool_call", { atMs: event.atMs, toolCallId: event.toolCallId }),
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
if (existing.status !== "running") {
|
|
299
|
+
return {
|
|
300
|
+
event,
|
|
301
|
+
state,
|
|
302
|
+
decision: decision(true, "allow", "duplicate_tool_completion_ignored", { atMs: event.atMs, toolCallId: event.toolCallId }),
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
const turnId = event.turnId ?? existing.turnId;
|
|
306
|
+
const next = copyState(state);
|
|
307
|
+
if (hasNewerCallerTurn(next, turnId)) {
|
|
308
|
+
next.pendingToolCallIds = withoutValue(next.pendingToolCallIds, event.toolCallId);
|
|
309
|
+
next.staleToolCallIds = withUnique(next.staleToolCallIds, event.toolCallId);
|
|
310
|
+
setToolState(next, { ...existing, turnId, status: "stale", completedAtMs: event.atMs });
|
|
311
|
+
if (next.floorOwner === "none")
|
|
312
|
+
next.phase = "suppressing";
|
|
313
|
+
return {
|
|
314
|
+
event,
|
|
315
|
+
state: next,
|
|
316
|
+
decision: decision(false, "suppress", "newer_user_turn_started", { atMs: event.atMs, toolCallId: event.toolCallId }),
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
setToolState(next, { ...existing, turnId, status: "ready", completedAtMs: event.atMs });
|
|
320
|
+
next.pendingToolCallIds = withUnique(next.pendingToolCallIds, event.toolCallId);
|
|
321
|
+
if (next.floorOwner === "none")
|
|
322
|
+
next.phase = "tool-result-ready";
|
|
323
|
+
return { event, state: next, decision: decision(true, "allow", "tool_result_ready", { atMs: event.atMs, toolCallId: event.toolCallId }) };
|
|
324
|
+
}
|
|
325
|
+
function applyToolResultSpoken(state, event) {
|
|
326
|
+
const resultDecision = canSpeakToolResult(state, { toolCallId: event.toolCallId, text: event.text });
|
|
327
|
+
if (!resultDecision.allowed)
|
|
328
|
+
return { event, state, decision: { ...resultDecision, atMs: event.atMs } };
|
|
329
|
+
const existing = toolState(state, event.toolCallId);
|
|
330
|
+
const next = copyState(state);
|
|
331
|
+
setToolState(next, { ...existing, status: "spoken" });
|
|
332
|
+
next.pendingToolCallIds = withoutValue(next.pendingToolCallIds, event.toolCallId);
|
|
333
|
+
next.spokenToolCallIds = withUnique(next.spokenToolCallIds, event.toolCallId);
|
|
334
|
+
next.phase = phaseAfterAssistantSpeech(next);
|
|
335
|
+
return { event, state: next, decision: { ...resultDecision, atMs: event.atMs } };
|
|
336
|
+
}
|
|
337
|
+
function applyHangupRequested(state, event) {
|
|
338
|
+
const next = copyState(state);
|
|
339
|
+
next.phase = "hangup";
|
|
340
|
+
next.floorOwner = "terminal";
|
|
341
|
+
next.hangupRequested = true;
|
|
342
|
+
return { event, state: next, decision: decision(true, "allow", "hangup_requested", { atMs: event.atMs }) };
|
|
343
|
+
}
|
|
344
|
+
function applyCallEnded(state, event) {
|
|
345
|
+
const next = copyState(state);
|
|
346
|
+
next.phase = "ended";
|
|
347
|
+
next.floorOwner = "terminal";
|
|
348
|
+
next.terminal = true;
|
|
349
|
+
next.hangupRequested = true;
|
|
350
|
+
return { event, state: next, decision: decision(true, "allow", "call_ended", { atMs: event.atMs }) };
|
|
351
|
+
}
|
|
352
|
+
function applyVoiceFloorEvent(state, event) {
|
|
353
|
+
if (state.hangupRequested && event.type !== "call.ended" && event.type !== "hangup.requested")
|
|
354
|
+
return suppressForHangup(state, event);
|
|
355
|
+
switch (event.type) {
|
|
356
|
+
case "call.connected":
|
|
357
|
+
return applyConnected(state, event);
|
|
358
|
+
case "caller.speech.started":
|
|
359
|
+
return applyCallerSpeechStarted(state, event);
|
|
360
|
+
case "caller.speech.ended":
|
|
361
|
+
return applyCallerSpeechEnded(state, event);
|
|
362
|
+
case "caller.transcript.final":
|
|
363
|
+
return applyCallerTranscriptFinal(state, event);
|
|
364
|
+
case "caller.turn.dismissed":
|
|
365
|
+
return applyCallerTurnDismissed(state, event);
|
|
366
|
+
case "assistant.response.requested":
|
|
367
|
+
return applyAssistantResponseRequested(state, event);
|
|
368
|
+
case "assistant.speech.started":
|
|
369
|
+
return applyAssistantSpeechStarted(state, event);
|
|
370
|
+
case "assistant.speech.done":
|
|
371
|
+
return applyAssistantSpeechDone(state, event);
|
|
372
|
+
case "assistant.speech.cancelled":
|
|
373
|
+
return applyAssistantSpeechCancelled(state, event);
|
|
374
|
+
case "tool.call.started":
|
|
375
|
+
return applyToolStarted(state, event);
|
|
376
|
+
case "tool.holding.spoken":
|
|
377
|
+
return applyToolHoldingSpoken(state, event);
|
|
378
|
+
case "tool.call.completed":
|
|
379
|
+
return applyToolCompleted(state, event);
|
|
380
|
+
case "tool.result.spoken":
|
|
381
|
+
return applyToolResultSpoken(state, event);
|
|
382
|
+
case "hangup.requested":
|
|
383
|
+
return applyHangupRequested(state, event);
|
|
384
|
+
case "call.ended":
|
|
385
|
+
return applyCallEnded(state, event);
|
|
386
|
+
default:
|
|
387
|
+
throw new Error(`unknown voice floor event: ${String(event.type)}`);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
function replayVoiceFloorEvents(events) {
|
|
391
|
+
(0, runtime_1.emitNervesEvent)({
|
|
392
|
+
component: "senses",
|
|
393
|
+
event: "senses.voice_floor_replay_start",
|
|
394
|
+
message: "starting Voice floor-control replay",
|
|
395
|
+
meta: { events: events.length },
|
|
396
|
+
});
|
|
397
|
+
let state = createInitialVoiceFloorState();
|
|
398
|
+
const steps = [];
|
|
399
|
+
for (const event of events) {
|
|
400
|
+
const transition = applyVoiceFloorEvent(state, event);
|
|
401
|
+
steps.push(transition);
|
|
402
|
+
state = transition.state;
|
|
403
|
+
}
|
|
404
|
+
(0, runtime_1.emitNervesEvent)({
|
|
405
|
+
component: "senses",
|
|
406
|
+
event: "senses.voice_floor_replay_end",
|
|
407
|
+
message: "finished Voice floor-control replay",
|
|
408
|
+
meta: { events: events.length, phase: state.phase, floorOwner: state.floorOwner },
|
|
409
|
+
});
|
|
410
|
+
return { state, steps };
|
|
411
|
+
}
|
|
412
|
+
function listSummary(values) {
|
|
413
|
+
return values.length > 0 ? values.join(",") : "none";
|
|
414
|
+
}
|
|
415
|
+
function summarizeVoiceFloorState(state) {
|
|
416
|
+
const parts = [
|
|
417
|
+
`phase=${state.phase}`,
|
|
418
|
+
`floor=${state.floorOwner}`,
|
|
419
|
+
];
|
|
420
|
+
if (state.activeAssistantSpeechId)
|
|
421
|
+
parts.push(`activeSpeech=${state.activeAssistantSpeechId}`);
|
|
422
|
+
parts.push(`pendingTools=${listSummary(state.pendingToolCallIds)}`);
|
|
423
|
+
parts.push(`staleTools=${listSummary(state.staleToolCallIds)}`);
|
|
424
|
+
if (state.interruption)
|
|
425
|
+
parts.push(`interruption=${state.interruption.turnId}@${state.interruption.interruptedSpeechId}`);
|
|
426
|
+
if (state.hangupRequested)
|
|
427
|
+
parts.push("hangup=requested");
|
|
428
|
+
if (state.terminal)
|
|
429
|
+
parts.push("terminal=true");
|
|
430
|
+
return parts.join(" ");
|
|
431
|
+
}
|