@otto-assistant/bridge 0.4.92
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/bin.js +2 -0
- package/dist/agent-model.e2e.test.js +755 -0
- package/dist/ai-tool-to-genai.js +233 -0
- package/dist/ai-tool-to-genai.test.js +267 -0
- package/dist/ai-tool.js +6 -0
- package/dist/anthropic-auth-plugin.js +728 -0
- package/dist/anthropic-auth-plugin.test.js +125 -0
- package/dist/anthropic-auth-state.js +231 -0
- package/dist/bin.js +90 -0
- package/dist/channel-management.js +227 -0
- package/dist/cli-parsing.test.js +137 -0
- package/dist/cli-send-thread.e2e.test.js +356 -0
- package/dist/cli.js +3276 -0
- package/dist/commands/abort.js +65 -0
- package/dist/commands/action-buttons.js +245 -0
- package/dist/commands/add-project.js +113 -0
- package/dist/commands/agent.js +335 -0
- package/dist/commands/ask-question.js +274 -0
- package/dist/commands/btw.js +116 -0
- package/dist/commands/compact.js +120 -0
- package/dist/commands/context-usage.js +140 -0
- package/dist/commands/create-new-project.js +130 -0
- package/dist/commands/diff.js +63 -0
- package/dist/commands/file-upload.js +275 -0
- package/dist/commands/fork.js +220 -0
- package/dist/commands/gemini-apikey.js +70 -0
- package/dist/commands/login.js +885 -0
- package/dist/commands/mcp.js +239 -0
- package/dist/commands/memory-snapshot.js +24 -0
- package/dist/commands/mention-mode.js +44 -0
- package/dist/commands/merge-worktree.js +159 -0
- package/dist/commands/model-variant.js +364 -0
- package/dist/commands/model.js +776 -0
- package/dist/commands/new-worktree.js +366 -0
- package/dist/commands/paginated-select.js +57 -0
- package/dist/commands/permissions.js +274 -0
- package/dist/commands/queue.js +206 -0
- package/dist/commands/remove-project.js +115 -0
- package/dist/commands/restart-opencode-server.js +127 -0
- package/dist/commands/resume.js +149 -0
- package/dist/commands/run-command.js +79 -0
- package/dist/commands/screenshare.js +303 -0
- package/dist/commands/screenshare.test.js +20 -0
- package/dist/commands/session-id.js +78 -0
- package/dist/commands/session.js +176 -0
- package/dist/commands/share.js +80 -0
- package/dist/commands/tasks.js +205 -0
- package/dist/commands/types.js +2 -0
- package/dist/commands/undo-redo.js +305 -0
- package/dist/commands/unset-model.js +138 -0
- package/dist/commands/upgrade.js +42 -0
- package/dist/commands/user-command.js +155 -0
- package/dist/commands/verbosity.js +125 -0
- package/dist/commands/worktree-settings.js +43 -0
- package/dist/commands/worktrees.js +410 -0
- package/dist/condense-memory.js +33 -0
- package/dist/config.js +94 -0
- package/dist/context-awareness-plugin.js +363 -0
- package/dist/context-awareness-plugin.test.js +124 -0
- package/dist/critique-utils.js +95 -0
- package/dist/database.js +1310 -0
- package/dist/db.js +251 -0
- package/dist/db.test.js +138 -0
- package/dist/debounce-timeout.js +28 -0
- package/dist/debounced-process-flush.js +77 -0
- package/dist/discord-bot.js +1008 -0
- package/dist/discord-command-registration.js +524 -0
- package/dist/discord-urls.js +81 -0
- package/dist/discord-utils.js +591 -0
- package/dist/discord-utils.test.js +134 -0
- package/dist/errors.js +157 -0
- package/dist/escape-backticks.test.js +429 -0
- package/dist/event-stream-real-capture.e2e.test.js +533 -0
- package/dist/eventsource-parser.test.js +327 -0
- package/dist/exec-async.js +26 -0
- package/dist/external-opencode-sync.js +480 -0
- package/dist/format-tables.js +302 -0
- package/dist/format-tables.test.js +308 -0
- package/dist/forum-sync/config.js +79 -0
- package/dist/forum-sync/discord-operations.js +154 -0
- package/dist/forum-sync/index.js +5 -0
- package/dist/forum-sync/markdown.js +113 -0
- package/dist/forum-sync/sync-to-discord.js +417 -0
- package/dist/forum-sync/sync-to-files.js +190 -0
- package/dist/forum-sync/types.js +53 -0
- package/dist/forum-sync/watchers.js +307 -0
- package/dist/gateway-proxy-reconnect.e2e.test.js +394 -0
- package/dist/gateway-proxy.e2e.test.js +483 -0
- package/dist/genai-worker-wrapper.js +111 -0
- package/dist/genai-worker.js +311 -0
- package/dist/genai.js +232 -0
- package/dist/generated/browser.js +17 -0
- package/dist/generated/client.js +37 -0
- package/dist/generated/commonInputTypes.js +10 -0
- package/dist/generated/enums.js +52 -0
- package/dist/generated/internal/class.js +49 -0
- package/dist/generated/internal/prismaNamespace.js +253 -0
- package/dist/generated/internal/prismaNamespaceBrowser.js +223 -0
- package/dist/generated/models/bot_api_keys.js +1 -0
- package/dist/generated/models/bot_tokens.js +1 -0
- package/dist/generated/models/channel_agents.js +1 -0
- package/dist/generated/models/channel_directories.js +1 -0
- package/dist/generated/models/channel_mention_mode.js +1 -0
- package/dist/generated/models/channel_models.js +1 -0
- package/dist/generated/models/channel_verbosity.js +1 -0
- package/dist/generated/models/channel_worktrees.js +1 -0
- package/dist/generated/models/forum_sync_configs.js +1 -0
- package/dist/generated/models/global_models.js +1 -0
- package/dist/generated/models/ipc_requests.js +1 -0
- package/dist/generated/models/part_messages.js +1 -0
- package/dist/generated/models/scheduled_tasks.js +1 -0
- package/dist/generated/models/session_agents.js +1 -0
- package/dist/generated/models/session_events.js +1 -0
- package/dist/generated/models/session_models.js +1 -0
- package/dist/generated/models/session_start_sources.js +1 -0
- package/dist/generated/models/thread_sessions.js +1 -0
- package/dist/generated/models/thread_worktrees.js +1 -0
- package/dist/generated/models.js +1 -0
- package/dist/heap-monitor.js +122 -0
- package/dist/hrana-server.js +263 -0
- package/dist/hrana-server.test.js +370 -0
- package/dist/html-actions.js +123 -0
- package/dist/html-actions.test.js +70 -0
- package/dist/html-components.js +117 -0
- package/dist/html-components.test.js +34 -0
- package/dist/image-optimizer-plugin.js +153 -0
- package/dist/image-utils.js +112 -0
- package/dist/interaction-handler.js +397 -0
- package/dist/ipc-polling.js +252 -0
- package/dist/ipc-tools-plugin.js +193 -0
- package/dist/kimaki-digital-twin.e2e.test.js +161 -0
- package/dist/kimaki-opencode-plugin-loading.e2e.test.js +87 -0
- package/dist/kimaki-opencode-plugin.js +17 -0
- package/dist/kimaki-opencode-plugin.test.js +98 -0
- package/dist/limit-heading-depth.js +25 -0
- package/dist/limit-heading-depth.test.js +105 -0
- package/dist/logger.js +165 -0
- package/dist/markdown.js +342 -0
- package/dist/markdown.test.js +257 -0
- package/dist/message-finish-field.e2e.test.js +165 -0
- package/dist/message-formatting.js +413 -0
- package/dist/message-formatting.test.js +73 -0
- package/dist/message-preprocessing.js +330 -0
- package/dist/onboarding-tutorial.js +172 -0
- package/dist/onboarding-welcome.js +37 -0
- package/dist/openai-realtime.js +224 -0
- package/dist/opencode-command-detection.js +65 -0
- package/dist/opencode-command-detection.test.js +240 -0
- package/dist/opencode-command.js +129 -0
- package/dist/opencode-command.test.js +48 -0
- package/dist/opencode-interrupt-plugin.js +361 -0
- package/dist/opencode-interrupt-plugin.test.js +458 -0
- package/dist/opencode.js +861 -0
- package/dist/otto/branding.js +22 -0
- package/dist/otto/index.js +21 -0
- package/dist/parse-permission-rules.test.js +117 -0
- package/dist/patch-text-parser.js +97 -0
- package/dist/plugin-logger.js +59 -0
- package/dist/privacy-sanitizer.js +105 -0
- package/dist/queue-advanced-abort.e2e.test.js +293 -0
- package/dist/queue-advanced-action-buttons.e2e.test.js +206 -0
- package/dist/queue-advanced-e2e-setup.js +786 -0
- package/dist/queue-advanced-footer.e2e.test.js +472 -0
- package/dist/queue-advanced-model-switch.e2e.test.js +299 -0
- package/dist/queue-advanced-permissions-typing.e2e.test.js +180 -0
- package/dist/queue-advanced-question.e2e.test.js +261 -0
- package/dist/queue-advanced-typing-interrupt.e2e.test.js +114 -0
- package/dist/queue-advanced-typing.e2e.test.js +153 -0
- package/dist/queue-drain-after-interactive-ui.e2e.test.js +119 -0
- package/dist/queue-interrupt-drain.e2e.test.js +135 -0
- package/dist/queue-question-select-drain.e2e.test.js +120 -0
- package/dist/runtime-idle-sweeper.js +52 -0
- package/dist/runtime-lifecycle.e2e.test.js +508 -0
- package/dist/sentry.js +23 -0
- package/dist/session-handler/agent-utils.js +67 -0
- package/dist/session-handler/event-stream-state.js +420 -0
- package/dist/session-handler/event-stream-state.test.js +563 -0
- package/dist/session-handler/model-utils.js +124 -0
- package/dist/session-handler/opencode-session-event-log.js +94 -0
- package/dist/session-handler/thread-runtime-state.js +104 -0
- package/dist/session-handler/thread-session-runtime.js +3258 -0
- package/dist/session-handler.js +9 -0
- package/dist/session-search.js +100 -0
- package/dist/session-search.test.js +40 -0
- package/dist/session-title-rename.test.js +80 -0
- package/dist/startup-service.js +153 -0
- package/dist/startup-time.e2e.test.js +296 -0
- package/dist/store.js +17 -0
- package/dist/system-message.js +613 -0
- package/dist/system-message.test.js +602 -0
- package/dist/task-runner.js +295 -0
- package/dist/task-schedule.js +209 -0
- package/dist/task-schedule.test.js +71 -0
- package/dist/test-utils.js +299 -0
- package/dist/thinking-utils.js +35 -0
- package/dist/thread-message-queue.e2e.test.js +999 -0
- package/dist/tools.js +357 -0
- package/dist/undo-redo.e2e.test.js +161 -0
- package/dist/unnest-code-blocks.js +146 -0
- package/dist/unnest-code-blocks.test.js +673 -0
- package/dist/upgrade.js +114 -0
- package/dist/utils.js +144 -0
- package/dist/voice-attachment.js +34 -0
- package/dist/voice-handler.js +646 -0
- package/dist/voice-message.e2e.test.js +1021 -0
- package/dist/voice.js +447 -0
- package/dist/voice.test.js +235 -0
- package/dist/wait-session.js +94 -0
- package/dist/websockify.js +69 -0
- package/dist/worker-types.js +4 -0
- package/dist/worktree-lifecycle.e2e.test.js +308 -0
- package/dist/worktree-utils.js +3 -0
- package/dist/worktrees.js +929 -0
- package/dist/worktrees.test.js +189 -0
- package/dist/xml.js +92 -0
- package/dist/xml.test.js +32 -0
- package/package.json +98 -0
- package/schema.prisma +295 -0
- package/skills/batch/SKILL.md +87 -0
- package/skills/critique/SKILL.md +112 -0
- package/skills/egaki/SKILL.md +100 -0
- package/skills/errore/SKILL.md +647 -0
- package/skills/event-sourcing-state/SKILL.md +252 -0
- package/skills/gitchamber/SKILL.md +93 -0
- package/skills/goke/SKILL.md +644 -0
- package/skills/jitter/EDITOR.md +219 -0
- package/skills/jitter/EXPORT-INTERNALS.md +309 -0
- package/skills/jitter/SKILL.md +158 -0
- package/skills/jitter/jitter-clipboard.json +1042 -0
- package/skills/jitter/package.json +14 -0
- package/skills/jitter/tsconfig.json +15 -0
- package/skills/jitter/utils/actions.ts +212 -0
- package/skills/jitter/utils/export.ts +114 -0
- package/skills/jitter/utils/index.ts +141 -0
- package/skills/jitter/utils/snapshot.ts +154 -0
- package/skills/jitter/utils/traverse.ts +246 -0
- package/skills/jitter/utils/types.ts +279 -0
- package/skills/jitter/utils/wait.ts +133 -0
- package/skills/lintcn/SKILL.md +873 -0
- package/skills/new-skill/SKILL.md +211 -0
- package/skills/npm-package/SKILL.md +239 -0
- package/skills/playwriter/SKILL.md +35 -0
- package/skills/proxyman/SKILL.md +215 -0
- package/skills/security-review/SKILL.md +208 -0
- package/skills/simplify/SKILL.md +58 -0
- package/skills/spiceflow/SKILL.md +14 -0
- package/skills/termcast/SKILL.md +945 -0
- package/skills/tuistory/SKILL.md +250 -0
- package/skills/usecomputer/SKILL.md +264 -0
- package/skills/x-articles/SKILL.md +554 -0
- package/skills/zele/SKILL.md +112 -0
- package/skills/zustand-centralized-state/SKILL.md +1004 -0
- package/src/agent-model.e2e.test.ts +976 -0
- package/src/ai-tool-to-genai.test.ts +296 -0
- package/src/ai-tool-to-genai.ts +283 -0
- package/src/ai-tool.ts +39 -0
- package/src/anthropic-auth-plugin.test.ts +159 -0
- package/src/anthropic-auth-plugin.ts +861 -0
- package/src/anthropic-auth-state.ts +282 -0
- package/src/bin.ts +111 -0
- package/src/channel-management.ts +334 -0
- package/src/cli-parsing.test.ts +195 -0
- package/src/cli-send-thread.e2e.test.ts +464 -0
- package/src/cli.ts +4581 -0
- package/src/commands/abort.ts +89 -0
- package/src/commands/action-buttons.ts +364 -0
- package/src/commands/add-project.ts +149 -0
- package/src/commands/agent.ts +473 -0
- package/src/commands/ask-question.ts +390 -0
- package/src/commands/btw.ts +164 -0
- package/src/commands/compact.ts +157 -0
- package/src/commands/context-usage.ts +199 -0
- package/src/commands/create-new-project.ts +190 -0
- package/src/commands/diff.ts +91 -0
- package/src/commands/file-upload.ts +389 -0
- package/src/commands/fork.ts +321 -0
- package/src/commands/gemini-apikey.ts +104 -0
- package/src/commands/login.ts +1173 -0
- package/src/commands/mcp.ts +307 -0
- package/src/commands/memory-snapshot.ts +30 -0
- package/src/commands/mention-mode.ts +68 -0
- package/src/commands/merge-worktree.ts +223 -0
- package/src/commands/model-variant.ts +483 -0
- package/src/commands/model.ts +1053 -0
- package/src/commands/new-worktree.ts +510 -0
- package/src/commands/paginated-select.ts +81 -0
- package/src/commands/permissions.ts +397 -0
- package/src/commands/queue.ts +271 -0
- package/src/commands/remove-project.ts +155 -0
- package/src/commands/restart-opencode-server.ts +162 -0
- package/src/commands/resume.ts +230 -0
- package/src/commands/run-command.ts +123 -0
- package/src/commands/screenshare.test.ts +30 -0
- package/src/commands/screenshare.ts +366 -0
- package/src/commands/session-id.ts +109 -0
- package/src/commands/session.ts +227 -0
- package/src/commands/share.ts +106 -0
- package/src/commands/tasks.ts +293 -0
- package/src/commands/types.ts +25 -0
- package/src/commands/undo-redo.ts +386 -0
- package/src/commands/unset-model.ts +173 -0
- package/src/commands/upgrade.ts +52 -0
- package/src/commands/user-command.ts +198 -0
- package/src/commands/verbosity.ts +173 -0
- package/src/commands/worktree-settings.ts +70 -0
- package/src/commands/worktrees.ts +552 -0
- package/src/condense-memory.ts +36 -0
- package/src/config.ts +111 -0
- package/src/context-awareness-plugin.test.ts +142 -0
- package/src/context-awareness-plugin.ts +510 -0
- package/src/critique-utils.ts +139 -0
- package/src/database.ts +1876 -0
- package/src/db.test.ts +162 -0
- package/src/db.ts +286 -0
- package/src/debounce-timeout.ts +43 -0
- package/src/debounced-process-flush.ts +104 -0
- package/src/discord-bot.ts +1330 -0
- package/src/discord-command-registration.ts +693 -0
- package/src/discord-urls.ts +88 -0
- package/src/discord-utils.test.ts +153 -0
- package/src/discord-utils.ts +800 -0
- package/src/errors.ts +201 -0
- package/src/escape-backticks.test.ts +469 -0
- package/src/event-stream-real-capture.e2e.test.ts +692 -0
- package/src/eventsource-parser.test.ts +351 -0
- package/src/exec-async.ts +35 -0
- package/src/external-opencode-sync.ts +685 -0
- package/src/format-tables.test.ts +335 -0
- package/src/format-tables.ts +445 -0
- package/src/forum-sync/config.ts +92 -0
- package/src/forum-sync/discord-operations.ts +241 -0
- package/src/forum-sync/index.ts +9 -0
- package/src/forum-sync/markdown.ts +172 -0
- package/src/forum-sync/sync-to-discord.ts +595 -0
- package/src/forum-sync/sync-to-files.ts +294 -0
- package/src/forum-sync/types.ts +175 -0
- package/src/forum-sync/watchers.ts +454 -0
- package/src/gateway-proxy-reconnect.e2e.test.ts +523 -0
- package/src/gateway-proxy.e2e.test.ts +640 -0
- package/src/genai-worker-wrapper.ts +164 -0
- package/src/genai-worker.ts +386 -0
- package/src/genai.ts +321 -0
- package/src/generated/browser.ts +114 -0
- package/src/generated/client.ts +138 -0
- package/src/generated/commonInputTypes.ts +736 -0
- package/src/generated/enums.ts +88 -0
- package/src/generated/internal/class.ts +384 -0
- package/src/generated/internal/prismaNamespace.ts +2386 -0
- package/src/generated/internal/prismaNamespaceBrowser.ts +326 -0
- package/src/generated/models/bot_api_keys.ts +1288 -0
- package/src/generated/models/bot_tokens.ts +1656 -0
- package/src/generated/models/channel_agents.ts +1256 -0
- package/src/generated/models/channel_directories.ts +1859 -0
- package/src/generated/models/channel_mention_mode.ts +1300 -0
- package/src/generated/models/channel_models.ts +1288 -0
- package/src/generated/models/channel_verbosity.ts +1228 -0
- package/src/generated/models/channel_worktrees.ts +1300 -0
- package/src/generated/models/forum_sync_configs.ts +1452 -0
- package/src/generated/models/global_models.ts +1288 -0
- package/src/generated/models/ipc_requests.ts +1485 -0
- package/src/generated/models/part_messages.ts +1302 -0
- package/src/generated/models/scheduled_tasks.ts +2320 -0
- package/src/generated/models/session_agents.ts +1086 -0
- package/src/generated/models/session_events.ts +1439 -0
- package/src/generated/models/session_models.ts +1114 -0
- package/src/generated/models/session_start_sources.ts +1408 -0
- package/src/generated/models/thread_sessions.ts +1781 -0
- package/src/generated/models/thread_worktrees.ts +1356 -0
- package/src/generated/models.ts +30 -0
- package/src/heap-monitor.ts +152 -0
- package/src/hrana-server.test.ts +434 -0
- package/src/hrana-server.ts +314 -0
- package/src/html-actions.test.ts +87 -0
- package/src/html-actions.ts +174 -0
- package/src/html-components.test.ts +38 -0
- package/src/html-components.ts +181 -0
- package/src/image-optimizer-plugin.ts +194 -0
- package/src/image-utils.ts +149 -0
- package/src/interaction-handler.ts +576 -0
- package/src/ipc-polling.ts +326 -0
- package/src/ipc-tools-plugin.ts +236 -0
- package/src/kimaki-digital-twin.e2e.test.ts +199 -0
- package/src/kimaki-opencode-plugin-loading.e2e.test.ts +109 -0
- package/src/kimaki-opencode-plugin.test.ts +108 -0
- package/src/kimaki-opencode-plugin.ts +18 -0
- package/src/limit-heading-depth.test.ts +116 -0
- package/src/limit-heading-depth.ts +26 -0
- package/src/logger.ts +208 -0
- package/src/markdown.test.ts +308 -0
- package/src/markdown.ts +410 -0
- package/src/message-finish-field.e2e.test.ts +192 -0
- package/src/message-formatting.test.ts +81 -0
- package/src/message-formatting.ts +533 -0
- package/src/message-preprocessing.ts +455 -0
- package/src/onboarding-tutorial.ts +176 -0
- package/src/onboarding-welcome.ts +49 -0
- package/src/openai-realtime.ts +358 -0
- package/src/opencode-command-detection.test.ts +307 -0
- package/src/opencode-command-detection.ts +76 -0
- package/src/opencode-command.test.ts +70 -0
- package/src/opencode-command.ts +188 -0
- package/src/opencode-interrupt-plugin.test.ts +677 -0
- package/src/opencode-interrupt-plugin.ts +477 -0
- package/src/opencode.ts +1110 -0
- package/src/otto/branding.ts +23 -0
- package/src/otto/index.ts +22 -0
- package/src/parse-permission-rules.test.ts +127 -0
- package/src/patch-text-parser.ts +107 -0
- package/src/plugin-logger.ts +68 -0
- package/src/privacy-sanitizer.ts +142 -0
- package/src/queue-advanced-abort.e2e.test.ts +382 -0
- package/src/queue-advanced-action-buttons.e2e.test.ts +268 -0
- package/src/queue-advanced-e2e-setup.ts +873 -0
- package/src/queue-advanced-footer.e2e.test.ts +576 -0
- package/src/queue-advanced-model-switch.e2e.test.ts +383 -0
- package/src/queue-advanced-permissions-typing.e2e.test.ts +245 -0
- package/src/queue-advanced-question.e2e.test.ts +316 -0
- package/src/queue-advanced-typing-interrupt.e2e.test.ts +146 -0
- package/src/queue-advanced-typing.e2e.test.ts +199 -0
- package/src/queue-drain-after-interactive-ui.e2e.test.ts +151 -0
- package/src/queue-interrupt-drain.e2e.test.ts +166 -0
- package/src/queue-question-select-drain.e2e.test.ts +152 -0
- package/src/runtime-idle-sweeper.ts +76 -0
- package/src/runtime-lifecycle.e2e.test.ts +641 -0
- package/src/schema.sql +173 -0
- package/src/sentry.ts +26 -0
- package/src/session-handler/agent-utils.ts +97 -0
- package/src/session-handler/event-stream-fixtures/real-session-action-buttons.jsonl +45 -0
- package/src/session-handler/event-stream-fixtures/real-session-footer-suppressed-on-pre-idle-interrupt.jsonl +40 -0
- package/src/session-handler/event-stream-fixtures/real-session-permission-external-file.jsonl +23 -0
- package/src/session-handler/event-stream-fixtures/real-session-task-normal.jsonl +22 -0
- package/src/session-handler/event-stream-fixtures/real-session-task-three-parallel-sleeps.jsonl +277 -0
- package/src/session-handler/event-stream-fixtures/real-session-task-user-interruption.jsonl +46 -0
- package/src/session-handler/event-stream-fixtures/session-abort-after-idle-race.jsonl +21 -0
- package/src/session-handler/event-stream-fixtures/session-concurrent-messages-serialized.jsonl +56 -0
- package/src/session-handler/event-stream-fixtures/session-explicit-abort.jsonl +44 -0
- package/src/session-handler/event-stream-fixtures/session-normal-completion.jsonl +29 -0
- package/src/session-handler/event-stream-fixtures/session-tool-call-noisy-stream.jsonl +29 -0
- package/src/session-handler/event-stream-fixtures/session-two-completions-same-session.jsonl +50 -0
- package/src/session-handler/event-stream-fixtures/session-user-interruption.jsonl +59 -0
- package/src/session-handler/event-stream-fixtures/session-voice-queued-followup.jsonl +52 -0
- package/src/session-handler/event-stream-state.test.ts +645 -0
- package/src/session-handler/event-stream-state.ts +608 -0
- package/src/session-handler/model-utils.ts +183 -0
- package/src/session-handler/opencode-session-event-log.ts +130 -0
- package/src/session-handler/thread-runtime-state.ts +212 -0
- package/src/session-handler/thread-session-runtime.ts +4281 -0
- package/src/session-handler.ts +15 -0
- package/src/session-search.test.ts +50 -0
- package/src/session-search.ts +148 -0
- package/src/session-title-rename.test.ts +112 -0
- package/src/startup-service.ts +200 -0
- package/src/startup-time.e2e.test.ts +373 -0
- package/src/store.ts +122 -0
- package/src/system-message.test.ts +612 -0
- package/src/system-message.ts +723 -0
- package/src/task-runner.ts +421 -0
- package/src/task-schedule.test.ts +84 -0
- package/src/task-schedule.ts +311 -0
- package/src/test-utils.ts +435 -0
- package/src/thinking-utils.ts +61 -0
- package/src/thread-message-queue.e2e.test.ts +1219 -0
- package/src/tools.ts +430 -0
- package/src/undici.d.ts +12 -0
- package/src/undo-redo.e2e.test.ts +209 -0
- package/src/unnest-code-blocks.test.ts +713 -0
- package/src/unnest-code-blocks.ts +185 -0
- package/src/upgrade.ts +127 -0
- package/src/utils.ts +212 -0
- package/src/voice-attachment.ts +51 -0
- package/src/voice-handler.ts +908 -0
- package/src/voice-message.e2e.test.ts +1255 -0
- package/src/voice.test.ts +281 -0
- package/src/voice.ts +627 -0
- package/src/wait-session.ts +147 -0
- package/src/websockify.ts +101 -0
- package/src/worker-types.ts +64 -0
- package/src/worktree-lifecycle.e2e.test.ts +391 -0
- package/src/worktree-utils.ts +4 -0
- package/src/worktrees.test.ts +223 -0
- package/src/worktrees.ts +1294 -0
- package/src/xml.test.ts +38 -0
- package/src/xml.ts +121 -0
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
// Worker thread for GenAI voice processing.
|
|
2
|
+
// Runs in a separate thread to handle audio encoding/decoding without blocking.
|
|
3
|
+
// Resamples 24kHz GenAI output to 48kHz stereo Opus packets for Discord.
|
|
4
|
+
import { parentPort, threadId } from 'node:worker_threads';
|
|
5
|
+
import { createWriteStream } from 'node:fs';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import * as errore from 'errore';
|
|
8
|
+
import { Resampler } from '@purinton/resampler';
|
|
9
|
+
import * as prism from 'prism-media';
|
|
10
|
+
import { startGenAiSession } from './genai.js';
|
|
11
|
+
import { getTools } from './tools.js';
|
|
12
|
+
import { mkdir } from 'node:fs/promises';
|
|
13
|
+
import { createLogger, formatErrorWithStack, LogPrefix } from './logger.js';
|
|
14
|
+
import { initSentry, notifyError } from './sentry.js';
|
|
15
|
+
if (!parentPort) {
|
|
16
|
+
throw new Error('This module must be run as a worker thread');
|
|
17
|
+
}
|
|
18
|
+
const workerLogger = createLogger(`${LogPrefix.WORKER}_${threadId}`);
|
|
19
|
+
workerLogger.log('GenAI worker started');
|
|
20
|
+
// Initialize Sentry in worker thread (inherits KIMAKI_SENTRY_DSN from parent)
|
|
21
|
+
initSentry();
|
|
22
|
+
// Define sendError early so it can be used by global handlers
|
|
23
|
+
function sendError(error) {
|
|
24
|
+
if (parentPort) {
|
|
25
|
+
parentPort.postMessage({
|
|
26
|
+
type: 'error',
|
|
27
|
+
error,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
// Add global error handlers for the worker thread
|
|
32
|
+
process.on('uncaughtException', (error) => {
|
|
33
|
+
workerLogger.error('Uncaught exception in worker:', error);
|
|
34
|
+
void notifyError(error, 'Uncaught exception in GenAI worker');
|
|
35
|
+
sendError(`Worker crashed: ${error.message}`);
|
|
36
|
+
process.exit(1);
|
|
37
|
+
});
|
|
38
|
+
process.on('unhandledRejection', (reason, promise) => {
|
|
39
|
+
const formattedReason = formatErrorWithStack(reason);
|
|
40
|
+
workerLogger.error('Unhandled rejection in worker:', formattedReason, 'at promise:', promise);
|
|
41
|
+
const error = reason instanceof Error
|
|
42
|
+
? reason
|
|
43
|
+
: new Error(formattedReason);
|
|
44
|
+
void notifyError(error, 'Unhandled rejection in GenAI worker');
|
|
45
|
+
sendError(`Worker unhandled rejection: ${formattedReason}`);
|
|
46
|
+
});
|
|
47
|
+
// Audio configuration
|
|
48
|
+
const AUDIO_CONFIG = {
|
|
49
|
+
inputSampleRate: 24000, // GenAI output
|
|
50
|
+
inputChannels: 1,
|
|
51
|
+
outputSampleRate: 48000, // Discord expects
|
|
52
|
+
outputChannels: 2,
|
|
53
|
+
opusFrameSize: 960, // 20ms at 48kHz
|
|
54
|
+
};
|
|
55
|
+
// Initialize audio processing components
|
|
56
|
+
const resampler = new Resampler({
|
|
57
|
+
inRate: AUDIO_CONFIG.inputSampleRate,
|
|
58
|
+
outRate: AUDIO_CONFIG.outputSampleRate,
|
|
59
|
+
inChannels: AUDIO_CONFIG.inputChannels,
|
|
60
|
+
outChannels: AUDIO_CONFIG.outputChannels,
|
|
61
|
+
volume: 1,
|
|
62
|
+
filterWindow: 8,
|
|
63
|
+
});
|
|
64
|
+
const opusEncoder = new prism.opus.Encoder({
|
|
65
|
+
rate: AUDIO_CONFIG.outputSampleRate,
|
|
66
|
+
channels: AUDIO_CONFIG.outputChannels,
|
|
67
|
+
frameSize: AUDIO_CONFIG.opusFrameSize,
|
|
68
|
+
});
|
|
69
|
+
// Pipe resampler to encoder with error handling
|
|
70
|
+
resampler.pipe(opusEncoder).on('error', (error) => {
|
|
71
|
+
workerLogger.error('Pipe error between resampler and encoder:', error);
|
|
72
|
+
void notifyError(error, 'GenAI worker audio pipeline error');
|
|
73
|
+
sendError(`Audio pipeline error: ${error.message}`);
|
|
74
|
+
});
|
|
75
|
+
// Opus packet queue and interval for 20ms packet sending
|
|
76
|
+
const opusPacketQueue = [];
|
|
77
|
+
let packetInterval = null;
|
|
78
|
+
// Send packets every 20ms
|
|
79
|
+
function startPacketSending() {
|
|
80
|
+
if (packetInterval)
|
|
81
|
+
return;
|
|
82
|
+
packetInterval = setInterval(() => {
|
|
83
|
+
const packet = opusPacketQueue.shift();
|
|
84
|
+
if (!packet)
|
|
85
|
+
return;
|
|
86
|
+
// Transfer packet as ArrayBuffer
|
|
87
|
+
const arrayBuffer = packet.buffer.slice(packet.byteOffset, packet.byteOffset + packet.byteLength);
|
|
88
|
+
parentPort.postMessage({
|
|
89
|
+
type: 'assistantOpusPacket',
|
|
90
|
+
packet: arrayBuffer,
|
|
91
|
+
}, [arrayBuffer]);
|
|
92
|
+
}, 20);
|
|
93
|
+
}
|
|
94
|
+
function stopPacketSending() {
|
|
95
|
+
if (packetInterval) {
|
|
96
|
+
clearInterval(packetInterval);
|
|
97
|
+
packetInterval = null;
|
|
98
|
+
}
|
|
99
|
+
opusPacketQueue.length = 0;
|
|
100
|
+
}
|
|
101
|
+
// Session state
|
|
102
|
+
let session = null;
|
|
103
|
+
// Audio log stream for assistant audio
|
|
104
|
+
let audioLogStream = null;
|
|
105
|
+
// Create assistant audio log stream for debugging
|
|
106
|
+
async function createAssistantAudioLogStream(guildId, channelId) {
|
|
107
|
+
if (!process.env.DEBUG)
|
|
108
|
+
return null;
|
|
109
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
110
|
+
const audioDir = path.join(process.cwd(), 'discord-audio-logs', guildId, channelId);
|
|
111
|
+
const mkdirError = await errore.tryAsync({
|
|
112
|
+
try: () => mkdir(audioDir, { recursive: true }),
|
|
113
|
+
catch: (e) => e,
|
|
114
|
+
});
|
|
115
|
+
if (mkdirError instanceof Error) {
|
|
116
|
+
workerLogger.error(`Failed to create audio log directory:`, mkdirError.message);
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
// Create stream for assistant audio (24kHz mono s16le PCM)
|
|
120
|
+
const outputFileName = `assistant_${timestamp}.24.pcm`;
|
|
121
|
+
const outputFilePath = path.join(audioDir, outputFileName);
|
|
122
|
+
const outputAudioStream = createWriteStream(outputFilePath);
|
|
123
|
+
// Add error handler to prevent crashes
|
|
124
|
+
outputAudioStream.on('error', (error) => {
|
|
125
|
+
workerLogger.error(`Assistant audio log stream error:`, error);
|
|
126
|
+
});
|
|
127
|
+
workerLogger.log(`Created assistant audio log: ${outputFilePath}`);
|
|
128
|
+
return outputAudioStream;
|
|
129
|
+
}
|
|
130
|
+
// Handle encoded Opus packets
|
|
131
|
+
opusEncoder.on('data', (packet) => {
|
|
132
|
+
opusPacketQueue.push(packet);
|
|
133
|
+
});
|
|
134
|
+
// Handle stream end events
|
|
135
|
+
opusEncoder.on('end', () => {
|
|
136
|
+
workerLogger.log('Opus encoder stream ended');
|
|
137
|
+
});
|
|
138
|
+
resampler.on('end', () => {
|
|
139
|
+
workerLogger.log('Resampler stream ended');
|
|
140
|
+
});
|
|
141
|
+
// Handle errors
|
|
142
|
+
resampler.on('error', (error) => {
|
|
143
|
+
workerLogger.error(`Resampler error:`, error);
|
|
144
|
+
void notifyError(error, 'GenAI worker resampler error');
|
|
145
|
+
sendError(`Resampler error: ${error.message}`);
|
|
146
|
+
});
|
|
147
|
+
opusEncoder.on('error', (error) => {
|
|
148
|
+
workerLogger.error(`Encoder error:`, error);
|
|
149
|
+
const errMsg = error.message || '';
|
|
150
|
+
// Check for specific corrupted data errors
|
|
151
|
+
if (errMsg.includes('The compressed data passed is corrupted')) {
|
|
152
|
+
workerLogger.warn('Received corrupted audio data in opus encoder');
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
void notifyError(error, 'GenAI worker encoder error');
|
|
156
|
+
sendError(`Encoder error: ${errMsg}`);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
async function cleanupAsync() {
|
|
160
|
+
workerLogger.log(`Starting async cleanup`);
|
|
161
|
+
stopPacketSending();
|
|
162
|
+
if (session) {
|
|
163
|
+
workerLogger.log(`Stopping GenAI session`);
|
|
164
|
+
session.stop();
|
|
165
|
+
session = null;
|
|
166
|
+
}
|
|
167
|
+
// Wait for audio log stream to finish writing
|
|
168
|
+
if (audioLogStream) {
|
|
169
|
+
workerLogger.log(`Closing assistant audio log stream`);
|
|
170
|
+
await new Promise((resolve, reject) => {
|
|
171
|
+
audioLogStream.end(() => {
|
|
172
|
+
workerLogger.log(`Assistant audio log stream closed`);
|
|
173
|
+
resolve();
|
|
174
|
+
});
|
|
175
|
+
audioLogStream.on('error', reject);
|
|
176
|
+
// Add timeout to prevent hanging
|
|
177
|
+
setTimeout(() => {
|
|
178
|
+
workerLogger.log(`Audio stream close timeout, continuing`);
|
|
179
|
+
resolve();
|
|
180
|
+
}, 3000);
|
|
181
|
+
});
|
|
182
|
+
audioLogStream = null;
|
|
183
|
+
}
|
|
184
|
+
// Unpipe and end the encoder first
|
|
185
|
+
resampler.unpipe(opusEncoder);
|
|
186
|
+
// End the encoder stream
|
|
187
|
+
await new Promise((resolve) => {
|
|
188
|
+
opusEncoder.end(() => {
|
|
189
|
+
workerLogger.log(`Opus encoder ended`);
|
|
190
|
+
resolve();
|
|
191
|
+
});
|
|
192
|
+
// Add timeout
|
|
193
|
+
setTimeout(resolve, 1000);
|
|
194
|
+
});
|
|
195
|
+
// End the resampler stream
|
|
196
|
+
await new Promise((resolve) => {
|
|
197
|
+
resampler.end(() => {
|
|
198
|
+
workerLogger.log(`Resampler ended`);
|
|
199
|
+
resolve();
|
|
200
|
+
});
|
|
201
|
+
// Add timeout
|
|
202
|
+
setTimeout(resolve, 1000);
|
|
203
|
+
});
|
|
204
|
+
workerLogger.log(`Async cleanup complete`);
|
|
205
|
+
}
|
|
206
|
+
// Handle messages from main thread
|
|
207
|
+
parentPort.on('message', async (message) => {
|
|
208
|
+
try {
|
|
209
|
+
switch (message.type) {
|
|
210
|
+
case 'init': {
|
|
211
|
+
workerLogger.log(`Initializing with directory:`, message.directory);
|
|
212
|
+
// Create audio log stream for assistant audio
|
|
213
|
+
audioLogStream = await createAssistantAudioLogStream(message.guildId, message.channelId);
|
|
214
|
+
// Start packet sending interval
|
|
215
|
+
startPacketSending();
|
|
216
|
+
// Get tools for the directory
|
|
217
|
+
const { tools } = await getTools({
|
|
218
|
+
directory: message.directory,
|
|
219
|
+
onMessageCompleted: (params) => {
|
|
220
|
+
parentPort.postMessage({
|
|
221
|
+
type: 'toolCallCompleted',
|
|
222
|
+
...params,
|
|
223
|
+
});
|
|
224
|
+
},
|
|
225
|
+
});
|
|
226
|
+
// Start GenAI session
|
|
227
|
+
session = await startGenAiSession({
|
|
228
|
+
tools,
|
|
229
|
+
systemMessage: message.systemMessage,
|
|
230
|
+
geminiApiKey: message.geminiApiKey,
|
|
231
|
+
onAssistantAudioChunk({ data }) {
|
|
232
|
+
// Write to audio log if enabled
|
|
233
|
+
if (audioLogStream && !audioLogStream.destroyed) {
|
|
234
|
+
audioLogStream.write(data, (err) => {
|
|
235
|
+
if (err) {
|
|
236
|
+
workerLogger.error('Error writing to audio log:', err);
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
// Write PCM data to resampler which will output Opus packets
|
|
241
|
+
if (!resampler.destroyed) {
|
|
242
|
+
resampler.write(data, (err) => {
|
|
243
|
+
if (err) {
|
|
244
|
+
workerLogger.error('Error writing to resampler:', err);
|
|
245
|
+
sendError(`Failed to process audio: ${err.message}`);
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
onAssistantStartSpeaking() {
|
|
251
|
+
parentPort.postMessage({
|
|
252
|
+
type: 'assistantStartSpeaking',
|
|
253
|
+
});
|
|
254
|
+
},
|
|
255
|
+
onAssistantStopSpeaking() {
|
|
256
|
+
parentPort.postMessage({
|
|
257
|
+
type: 'assistantStopSpeaking',
|
|
258
|
+
});
|
|
259
|
+
},
|
|
260
|
+
onAssistantInterruptSpeaking() {
|
|
261
|
+
parentPort.postMessage({
|
|
262
|
+
type: 'assistantInterruptSpeaking',
|
|
263
|
+
});
|
|
264
|
+
},
|
|
265
|
+
});
|
|
266
|
+
// Notify main thread we're ready
|
|
267
|
+
parentPort.postMessage({
|
|
268
|
+
type: 'ready',
|
|
269
|
+
});
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
case 'sendRealtimeInput': {
|
|
273
|
+
if (!session) {
|
|
274
|
+
sendError('Session not initialized');
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
session.session.sendRealtimeInput({
|
|
278
|
+
audio: message.audio,
|
|
279
|
+
audioStreamEnd: message.audioStreamEnd,
|
|
280
|
+
});
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
case 'sendTextInput': {
|
|
284
|
+
if (!session) {
|
|
285
|
+
sendError('Session not initialized');
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
session.session.sendRealtimeInput({
|
|
289
|
+
text: message.text,
|
|
290
|
+
});
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
case 'interrupt': {
|
|
294
|
+
workerLogger.log(`Interrupting playback`);
|
|
295
|
+
// Clear the opus packet queue
|
|
296
|
+
opusPacketQueue.length = 0;
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
case 'stop': {
|
|
300
|
+
workerLogger.log(`Stopping worker`);
|
|
301
|
+
await cleanupAsync();
|
|
302
|
+
// process.exit(0)
|
|
303
|
+
break;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
catch (error) {
|
|
308
|
+
workerLogger.error(`Error handling message:`, error);
|
|
309
|
+
sendError(error instanceof Error ? error.message : 'Unknown error in worker');
|
|
310
|
+
}
|
|
311
|
+
});
|
package/dist/genai.js
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
// Google GenAI Live session manager for real-time voice interactions.
|
|
2
|
+
// Establishes bidirectional audio streaming with Gemini, handles tool calls,
|
|
3
|
+
// and manages the assistant's audio output for Discord voice channels.
|
|
4
|
+
import { GoogleGenAI, LiveServerMessage, MediaResolution, Modality, Session, } from '@google/genai';
|
|
5
|
+
import { writeFile } from 'fs';
|
|
6
|
+
import { createLogger, LogPrefix } from './logger.js';
|
|
7
|
+
import { aiToolToCallableTool } from './ai-tool-to-genai.js';
|
|
8
|
+
const genaiLogger = createLogger(LogPrefix.GENAI);
|
|
9
|
+
const audioParts = [];
|
|
10
|
+
function saveBinaryFile(fileName, content) {
|
|
11
|
+
writeFile(fileName, content, 'utf8', (err) => {
|
|
12
|
+
if (err) {
|
|
13
|
+
genaiLogger.error(`Error writing file ${fileName}:`, err);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
genaiLogger.log(`Appending stream content to file ${fileName}.`);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function convertToWav(rawData, mimeType) {
|
|
20
|
+
const options = parseMimeType(mimeType);
|
|
21
|
+
const dataLength = rawData.reduce((a, b) => a + b.length, 0);
|
|
22
|
+
const wavHeader = createWavHeader(dataLength, options);
|
|
23
|
+
const buffer = Buffer.concat(rawData);
|
|
24
|
+
return Buffer.concat([wavHeader, buffer]);
|
|
25
|
+
}
|
|
26
|
+
function parseMimeType(mimeType) {
|
|
27
|
+
const [fileType, ...params] = mimeType.split(';').map((s) => s.trim());
|
|
28
|
+
const [_, format] = fileType?.split('/') || [];
|
|
29
|
+
const options = {
|
|
30
|
+
numChannels: 1,
|
|
31
|
+
bitsPerSample: 16,
|
|
32
|
+
};
|
|
33
|
+
if (format && format.startsWith('L')) {
|
|
34
|
+
const bits = parseInt(format.slice(1), 10);
|
|
35
|
+
if (!isNaN(bits)) {
|
|
36
|
+
options.bitsPerSample = bits;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
for (const param of params) {
|
|
40
|
+
const [key, value] = param.split('=').map((s) => s.trim());
|
|
41
|
+
if (key === 'rate') {
|
|
42
|
+
options.sampleRate = parseInt(value || '', 10);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return options;
|
|
46
|
+
}
|
|
47
|
+
function createWavHeader(dataLength, options) {
|
|
48
|
+
const { numChannels, sampleRate, bitsPerSample } = options;
|
|
49
|
+
// http://soundfile.sapp.org/doc/WaveFormat
|
|
50
|
+
const byteRate = (sampleRate * numChannels * bitsPerSample) / 8;
|
|
51
|
+
const blockAlign = (numChannels * bitsPerSample) / 8;
|
|
52
|
+
const buffer = Buffer.alloc(44);
|
|
53
|
+
buffer.write('RIFF', 0); // ChunkID
|
|
54
|
+
buffer.writeUInt32LE(36 + dataLength, 4); // ChunkSize
|
|
55
|
+
buffer.write('WAVE', 8); // Format
|
|
56
|
+
buffer.write('fmt ', 12); // Subchunk1ID
|
|
57
|
+
buffer.writeUInt32LE(16, 16); // Subchunk1Size (PCM)
|
|
58
|
+
buffer.writeUInt16LE(1, 20); // AudioFormat (1 = PCM)
|
|
59
|
+
buffer.writeUInt16LE(numChannels, 22); // NumChannels
|
|
60
|
+
buffer.writeUInt32LE(sampleRate, 24); // SampleRate
|
|
61
|
+
buffer.writeUInt32LE(byteRate, 28); // ByteRate
|
|
62
|
+
buffer.writeUInt16LE(blockAlign, 32); // BlockAlign
|
|
63
|
+
buffer.writeUInt16LE(bitsPerSample, 34); // BitsPerSample
|
|
64
|
+
buffer.write('data', 36); // Subchunk2ID
|
|
65
|
+
buffer.writeUInt32LE(dataLength, 40); // Subchunk2Size
|
|
66
|
+
return buffer;
|
|
67
|
+
}
|
|
68
|
+
function defaultAudioChunkHandler({ data, mimeType, }) {
|
|
69
|
+
audioParts.push(data);
|
|
70
|
+
const fileName = 'audio.wav';
|
|
71
|
+
const buffer = convertToWav(audioParts, mimeType);
|
|
72
|
+
saveBinaryFile(fileName, buffer);
|
|
73
|
+
}
|
|
74
|
+
export async function startGenAiSession({ onAssistantAudioChunk, onAssistantStartSpeaking, onAssistantStopSpeaking, onAssistantInterruptSpeaking, systemMessage, tools, geminiApiKey, } = {}) {
|
|
75
|
+
let session = undefined;
|
|
76
|
+
const callableTools = [];
|
|
77
|
+
let isAssistantSpeaking = false;
|
|
78
|
+
const audioChunkHandler = onAssistantAudioChunk || defaultAudioChunkHandler;
|
|
79
|
+
// Convert AI SDK tools to GenAI CallableTools
|
|
80
|
+
if (tools) {
|
|
81
|
+
for (const [name, tool] of Object.entries(tools)) {
|
|
82
|
+
callableTools.push(aiToolToCallableTool(tool, name));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function handleModelTurn(message) {
|
|
86
|
+
if (message.toolCall) {
|
|
87
|
+
genaiLogger.log('Tool call:', message.toolCall);
|
|
88
|
+
// Handle tool calls
|
|
89
|
+
if (message.toolCall.functionCalls && callableTools.length > 0) {
|
|
90
|
+
for (const tool of callableTools) {
|
|
91
|
+
if (!message.toolCall.functionCalls.some((x) => x.name === tool.name)) {
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
tool
|
|
95
|
+
.callTool(message.toolCall.functionCalls)
|
|
96
|
+
.then((parts) => {
|
|
97
|
+
const functionResponses = parts
|
|
98
|
+
.filter((part) => part.functionResponse)
|
|
99
|
+
.map((part) => ({
|
|
100
|
+
response: part.functionResponse.response,
|
|
101
|
+
id: part.functionResponse.id,
|
|
102
|
+
name: part.functionResponse.name,
|
|
103
|
+
}));
|
|
104
|
+
if (functionResponses.length > 0 && session) {
|
|
105
|
+
session.sendToolResponse({ functionResponses });
|
|
106
|
+
genaiLogger.log('client-toolResponse: ' +
|
|
107
|
+
JSON.stringify({ functionResponses }));
|
|
108
|
+
}
|
|
109
|
+
})
|
|
110
|
+
.catch((error) => {
|
|
111
|
+
genaiLogger.error('Error handling tool calls:', error);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (message.serverContent?.modelTurn?.parts) {
|
|
117
|
+
for (const part of message.serverContent.modelTurn.parts) {
|
|
118
|
+
if (part?.fileData) {
|
|
119
|
+
genaiLogger.log(`File: ${part?.fileData.fileUri}`);
|
|
120
|
+
}
|
|
121
|
+
if (part?.inlineData) {
|
|
122
|
+
const inlineData = part.inlineData;
|
|
123
|
+
if (!inlineData.mimeType ||
|
|
124
|
+
!inlineData.mimeType.startsWith('audio/')) {
|
|
125
|
+
genaiLogger.log('Skipping non-audio inlineData:', inlineData.mimeType);
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
// Trigger start speaking callback the first time audio is received
|
|
129
|
+
if (!isAssistantSpeaking && onAssistantStartSpeaking) {
|
|
130
|
+
isAssistantSpeaking = true;
|
|
131
|
+
onAssistantStartSpeaking();
|
|
132
|
+
}
|
|
133
|
+
const buffer = Buffer.from(inlineData?.data ?? '', 'base64');
|
|
134
|
+
audioChunkHandler({
|
|
135
|
+
data: buffer,
|
|
136
|
+
mimeType: inlineData.mimeType ?? '',
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
if (part?.text) {
|
|
140
|
+
genaiLogger.log('Text:', part.text);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
// Handle input transcription (user's audio transcription)
|
|
145
|
+
if (message.serverContent?.inputTranscription?.text) {
|
|
146
|
+
genaiLogger.log('[user transcription]', message.serverContent.inputTranscription.text);
|
|
147
|
+
}
|
|
148
|
+
// Handle output transcription (model's audio transcription)
|
|
149
|
+
if (message.serverContent?.outputTranscription?.text) {
|
|
150
|
+
genaiLogger.log('[assistant transcription]', message.serverContent.outputTranscription.text);
|
|
151
|
+
}
|
|
152
|
+
if (message.serverContent?.interrupted) {
|
|
153
|
+
genaiLogger.log('Assistant was interrupted');
|
|
154
|
+
if (isAssistantSpeaking && onAssistantInterruptSpeaking) {
|
|
155
|
+
isAssistantSpeaking = false;
|
|
156
|
+
onAssistantInterruptSpeaking();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (message.serverContent?.turnComplete) {
|
|
160
|
+
genaiLogger.log('Assistant turn complete');
|
|
161
|
+
if (isAssistantSpeaking && onAssistantStopSpeaking) {
|
|
162
|
+
isAssistantSpeaking = false;
|
|
163
|
+
onAssistantStopSpeaking();
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const apiKey = geminiApiKey || process.env.GEMINI_API_KEY;
|
|
168
|
+
if (!apiKey) {
|
|
169
|
+
genaiLogger.error('No Gemini API key provided');
|
|
170
|
+
throw new Error('Gemini API key is required for voice interactions');
|
|
171
|
+
}
|
|
172
|
+
const ai = new GoogleGenAI({
|
|
173
|
+
apiKey,
|
|
174
|
+
});
|
|
175
|
+
const model = 'gemini-3.1-flash-live-preview';
|
|
176
|
+
session = await ai.live.connect({
|
|
177
|
+
model,
|
|
178
|
+
callbacks: {
|
|
179
|
+
onopen: function () {
|
|
180
|
+
genaiLogger.debug('Opened');
|
|
181
|
+
},
|
|
182
|
+
onmessage: function (message) {
|
|
183
|
+
// genaiLogger.log(message)
|
|
184
|
+
try {
|
|
185
|
+
handleModelTurn(message);
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
genaiLogger.error('Error handling turn:', error);
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
onerror: function (e) {
|
|
192
|
+
genaiLogger.debug('Error:', e.message);
|
|
193
|
+
},
|
|
194
|
+
onclose: function (e) {
|
|
195
|
+
genaiLogger.debug('Close:', e.reason);
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
config: {
|
|
199
|
+
tools: callableTools,
|
|
200
|
+
responseModalities: [Modality.AUDIO],
|
|
201
|
+
mediaResolution: MediaResolution.MEDIA_RESOLUTION_MEDIUM,
|
|
202
|
+
inputAudioTranscription: {}, // transcribes your input speech
|
|
203
|
+
outputAudioTranscription: {}, // transcribes the model's spoken audio
|
|
204
|
+
systemInstruction: {
|
|
205
|
+
parts: [
|
|
206
|
+
{
|
|
207
|
+
text: systemMessage || '',
|
|
208
|
+
},
|
|
209
|
+
],
|
|
210
|
+
},
|
|
211
|
+
speechConfig: {
|
|
212
|
+
voiceConfig: {
|
|
213
|
+
prebuiltVoiceConfig: {
|
|
214
|
+
voiceName: 'Charon', // Orus also not bad
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
contextWindowCompression: {
|
|
219
|
+
triggerTokens: '25600',
|
|
220
|
+
slidingWindow: { targetTokens: '12800' },
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
});
|
|
224
|
+
return {
|
|
225
|
+
session,
|
|
226
|
+
stop: () => {
|
|
227
|
+
const currentSession = session;
|
|
228
|
+
session = undefined;
|
|
229
|
+
currentSession?.close();
|
|
230
|
+
},
|
|
231
|
+
};
|
|
232
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* !!! This is code generated by Prisma. Do not edit directly. !!! */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
// biome-ignore-all lint: generated file
|
|
4
|
+
// @ts-nocheck
|
|
5
|
+
/*
|
|
6
|
+
* This file should be your main import to use Prisma-related types and utilities in a browser.
|
|
7
|
+
* Use it to get access to models, enums, and input types.
|
|
8
|
+
*
|
|
9
|
+
* This file does not contain a `PrismaClient` class, nor several other helpers that are intended as server-side only.
|
|
10
|
+
* See `client.ts` for the standard, server-side entry point.
|
|
11
|
+
*
|
|
12
|
+
* 🟢 You can import this file directly.
|
|
13
|
+
*/
|
|
14
|
+
import * as Prisma from './internal/prismaNamespaceBrowser.js';
|
|
15
|
+
export { Prisma };
|
|
16
|
+
export * as $Enums from './enums.js';
|
|
17
|
+
export * from './enums.js';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/* !!! This is code generated by Prisma. Do not edit directly. !!! */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
// biome-ignore-all lint: generated file
|
|
4
|
+
// @ts-nocheck
|
|
5
|
+
/*
|
|
6
|
+
* This file should be your main import to use Prisma. Through it you get access to all the models, enums, and input types.
|
|
7
|
+
* If you're looking for something you can import in the client-side of your application, please refer to the `browser.ts` file instead.
|
|
8
|
+
*
|
|
9
|
+
* 🟢 You can import this file directly.
|
|
10
|
+
*/
|
|
11
|
+
import * as process from 'node:process';
|
|
12
|
+
import * as path from 'node:path';
|
|
13
|
+
import { fileURLToPath } from 'node:url';
|
|
14
|
+
globalThis['__dirname'] = path.dirname(fileURLToPath(import.meta.url));
|
|
15
|
+
import * as runtime from "@prisma/client/runtime/client";
|
|
16
|
+
import * as $Enums from "./enums.js";
|
|
17
|
+
import * as $Class from "./internal/class.js";
|
|
18
|
+
import * as Prisma from "./internal/prismaNamespace.js";
|
|
19
|
+
export * as $Enums from './enums.js';
|
|
20
|
+
export * from "./enums.js";
|
|
21
|
+
/**
|
|
22
|
+
* ## Prisma Client
|
|
23
|
+
*
|
|
24
|
+
* Type-safe database client for TypeScript
|
|
25
|
+
* @example
|
|
26
|
+
* ```
|
|
27
|
+
* const prisma = new PrismaClient({
|
|
28
|
+
* adapter: new PrismaPg({ connectionString: process.env.DATABASE_URL })
|
|
29
|
+
* })
|
|
30
|
+
* // Fetch zero or more Thread_sessions
|
|
31
|
+
* const thread_sessions = await prisma.thread_sessions.findMany()
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* Read more in our [docs](https://pris.ly/d/client).
|
|
35
|
+
*/
|
|
36
|
+
export const PrismaClient = $Class.getPrismaClientClass();
|
|
37
|
+
export { Prisma };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* !!! This is code generated by Prisma. Do not edit directly. !!! */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
// biome-ignore-all lint: generated file
|
|
4
|
+
// @ts-nocheck
|
|
5
|
+
/*
|
|
6
|
+
* This file exports various common sort, input & filter types that are not directly linked to a particular model.
|
|
7
|
+
*
|
|
8
|
+
* 🟢 You can import this file directly.
|
|
9
|
+
*/
|
|
10
|
+
import * as $Enums from "./enums.js";
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/* !!! This is code generated by Prisma. Do not edit directly. !!! */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
// biome-ignore-all lint: generated file
|
|
4
|
+
// @ts-nocheck
|
|
5
|
+
/*
|
|
6
|
+
* This file exports all enum related types from the schema.
|
|
7
|
+
*
|
|
8
|
+
* 🟢 You can import this file directly.
|
|
9
|
+
*/
|
|
10
|
+
export const ThreadSessionSource = {
|
|
11
|
+
kimaki: 'kimaki',
|
|
12
|
+
external_poll: 'external_poll'
|
|
13
|
+
};
|
|
14
|
+
export const BotMode = {
|
|
15
|
+
self_hosted: 'self_hosted',
|
|
16
|
+
gateway: 'gateway'
|
|
17
|
+
};
|
|
18
|
+
export const ChannelType = {
|
|
19
|
+
text: 'text',
|
|
20
|
+
voice: 'voice'
|
|
21
|
+
};
|
|
22
|
+
export const WorktreeStatus = {
|
|
23
|
+
pending: 'pending',
|
|
24
|
+
ready: 'ready',
|
|
25
|
+
error: 'error'
|
|
26
|
+
};
|
|
27
|
+
export const VerbosityLevel = {
|
|
28
|
+
tools_and_text: 'tools_and_text',
|
|
29
|
+
text_and_essential_tools: 'text_and_essential_tools',
|
|
30
|
+
text_only: 'text_only'
|
|
31
|
+
};
|
|
32
|
+
export const task_status = {
|
|
33
|
+
planned: 'planned',
|
|
34
|
+
running: 'running',
|
|
35
|
+
completed: 'completed',
|
|
36
|
+
cancelled: 'cancelled',
|
|
37
|
+
failed: 'failed'
|
|
38
|
+
};
|
|
39
|
+
export const task_schedule_kind = {
|
|
40
|
+
at: 'at',
|
|
41
|
+
cron: 'cron'
|
|
42
|
+
};
|
|
43
|
+
export const ipc_request_type = {
|
|
44
|
+
file_upload: 'file_upload',
|
|
45
|
+
action_buttons: 'action_buttons'
|
|
46
|
+
};
|
|
47
|
+
export const ipc_request_status = {
|
|
48
|
+
pending: 'pending',
|
|
49
|
+
processing: 'processing',
|
|
50
|
+
completed: 'completed',
|
|
51
|
+
cancelled: 'cancelled'
|
|
52
|
+
};
|