synabun 2.2.1 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +53 -0
- package/README.md +1 -1
- package/docs/whatsapp.md +52 -20
- package/hooks/claude-code/pre-websearch.mjs +4 -1
- package/hooks/claude-code/prompt-submit.mjs +7 -0
- package/lib/mcp-build.js +519 -0
- package/lib/mcp-dist.js +10 -4
- package/lib/release-scan.mjs +23 -10
- package/lib/server-supervisor.js +7 -1
- package/lib/virustotal.mjs +146 -40
- package/mcp-server/dist/http.d.ts +57 -0
- package/mcp-server/dist/http.d.ts.map +1 -1
- package/mcp-server/dist/http.js +128 -18
- package/mcp-server/dist/http.js.map +1 -1
- package/mcp-server/dist/index.d.ts.map +1 -1
- package/mcp-server/dist/index.js +14 -9
- package/mcp-server/dist/index.js.map +1 -1
- package/mcp-server/dist/services/browser-route-flow.d.ts +119 -0
- package/mcp-server/dist/services/browser-route-flow.d.ts.map +1 -0
- package/mcp-server/dist/services/browser-route-flow.js +340 -0
- package/mcp-server/dist/services/browser-route-flow.js.map +1 -0
- package/mcp-server/dist/services/desktop-client.js +2 -2
- package/mcp-server/dist/services/desktop-client.js.map +1 -1
- package/mcp-server/dist/services/embedding-service.d.ts.map +1 -1
- package/mcp-server/dist/services/embedding-service.js +2 -1
- package/mcp-server/dist/services/embedding-service.js.map +1 -1
- package/mcp-server/dist/services/identity.d.ts +66 -3
- package/mcp-server/dist/services/identity.d.ts.map +1 -1
- package/mcp-server/dist/services/identity.js +61 -4
- package/mcp-server/dist/services/identity.js.map +1 -1
- package/mcp-server/dist/services/neural-interface.d.ts +133 -1
- package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
- package/mcp-server/dist/services/neural-interface.js +630 -64
- package/mcp-server/dist/services/neural-interface.js.map +1 -1
- package/mcp-server/dist/services/tool-catalog.js +2 -2
- package/mcp-server/dist/services/tool-catalog.js.map +1 -1
- package/mcp-server/dist/tools/agents.d.ts +3 -2
- package/mcp-server/dist/tools/agents.d.ts.map +1 -1
- package/mcp-server/dist/tools/agents.js +6 -4
- package/mcp-server/dist/tools/agents.js.map +1 -1
- package/mcp-server/dist/tools/bluesky.d.ts +20 -7
- package/mcp-server/dist/tools/bluesky.d.ts.map +1 -1
- package/mcp-server/dist/tools/bluesky.js +147 -45
- package/mcp-server/dist/tools/bluesky.js.map +1 -1
- package/mcp-server/dist/tools/browser-advanced.d.ts +13 -2
- package/mcp-server/dist/tools/browser-advanced.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-advanced.js +153 -18
- package/mcp-server/dist/tools/browser-advanced.js.map +1 -1
- package/mcp-server/dist/tools/browser-cheatsheet.d.ts +2 -0
- package/mcp-server/dist/tools/browser-cheatsheet.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-cheatsheet.js +3 -0
- package/mcp-server/dist/tools/browser-cheatsheet.js.map +1 -1
- package/mcp-server/dist/tools/browser-navigate.d.ts +3 -3
- package/mcp-server/dist/tools/browser-navigate.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-navigate.js +19 -16
- package/mcp-server/dist/tools/browser-navigate.js.map +1 -1
- package/mcp-server/dist/tools/browser-observe.d.ts +2 -1
- package/mcp-server/dist/tools/browser-observe.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-observe.js +61 -20
- package/mcp-server/dist/tools/browser-observe.js.map +1 -1
- package/mcp-server/dist/tools/morelogin.d.ts +13 -3
- package/mcp-server/dist/tools/morelogin.d.ts.map +1 -1
- package/mcp-server/dist/tools/morelogin.js +82 -19
- package/mcp-server/dist/tools/morelogin.js.map +1 -1
- package/mcp-server/dist/tools/skill-tools.d.ts +4 -4
- package/mcp-server/dist/tools/youtube/helpers.d.ts +1 -0
- package/mcp-server/dist/tools/youtube/helpers.d.ts.map +1 -1
- package/mcp-server/dist/tools/youtube/helpers.js +1 -1
- package/mcp-server/dist/tools/youtube/helpers.js.map +1 -1
- package/mcp-server/dist/tools/youtube/upload.d.ts.map +1 -1
- package/mcp-server/dist/tools/youtube/upload.js +225 -88
- package/mcp-server/dist/tools/youtube/upload.js.map +1 -1
- package/mcp-server/package-lock.json +2 -2
- package/mcp-server/package.json +1 -1
- package/mcp-server/src/http.ts +135 -17
- package/mcp-server/src/index.ts +15 -9
- package/mcp-server/src/services/browser-route-flow.ts +403 -0
- package/mcp-server/src/services/desktop-client.ts +2 -2
- package/mcp-server/src/services/embedding-service.ts +2 -1
- package/mcp-server/src/services/identity.ts +80 -4
- package/mcp-server/src/services/neural-interface.ts +648 -73
- package/mcp-server/src/services/tool-catalog.ts +2 -2
- package/mcp-server/src/tools/agents.ts +8 -4
- package/mcp-server/src/tools/bluesky.ts +164 -51
- package/mcp-server/src/tools/browser-advanced.ts +142 -17
- package/mcp-server/src/tools/browser-cheatsheet.ts +3 -0
- package/mcp-server/src/tools/browser-navigate.ts +19 -16
- package/mcp-server/src/tools/browser-observe.ts +62 -20
- package/mcp-server/src/tools/morelogin.ts +82 -19
- package/mcp-server/src/tools/youtube/helpers.ts +2 -2
- package/mcp-server/src/tools/youtube/upload.ts +218 -99
- package/neural-interface/i18n/en.json +655 -123
- package/neural-interface/i18n/pt-BR.json +542 -10
- package/neural-interface/lib/assistant-api.js +90 -23
- package/neural-interface/lib/assistant-brains/claude.js +5 -0
- package/neural-interface/lib/assistant-catalog.js +134 -3
- package/neural-interface/lib/assistant-dispatch.js +97 -1
- package/neural-interface/lib/assistant-persona.js +15 -7
- package/neural-interface/lib/assistant-router.js +6 -4
- package/neural-interface/lib/assistant-runtime.js +18 -1
- package/neural-interface/lib/assistant-task-prompt.js +5 -0
- package/neural-interface/lib/assistant-tools.js +10 -1
- package/neural-interface/lib/automation-approval.js +249 -0
- package/neural-interface/lib/automation-browser-owner-access.js +82 -0
- package/neural-interface/lib/backup-service.js +16 -1
- package/neural-interface/lib/browser-automation-routes.js +84 -0
- package/neural-interface/lib/browser-background-tab.js +72 -3
- package/neural-interface/lib/browser-execution.js +16 -3
- package/neural-interface/lib/browser-extraction.js +106 -45
- package/neural-interface/lib/browser-owner.js +48 -0
- package/neural-interface/lib/browser-profile-choices.js +143 -0
- package/neural-interface/lib/browser-profiles.js +142 -0
- package/neural-interface/lib/browser-session-close.js +84 -0
- package/neural-interface/lib/browser-start-handoff.js +202 -0
- package/neural-interface/lib/browser-tab-recovery.js +153 -0
- package/neural-interface/lib/browser-tool-policy.js +23 -4
- package/neural-interface/lib/browser-wedge-retire.js +64 -0
- package/neural-interface/lib/chromium-on-device-model.js +67 -0
- package/neural-interface/lib/claude-agent-bridge.js +43 -5
- package/neural-interface/lib/claude-background-hold.js +239 -0
- package/neural-interface/lib/claude-model-catalog.js +12 -0
- package/neural-interface/lib/effort-levels.js +28 -2
- package/neural-interface/lib/exec-loop-command.js +8 -0
- package/neural-interface/lib/http-guards.js +11 -6
- package/neural-interface/lib/local-profile-proxy.js +362 -0
- package/neural-interface/lib/local-profiles.js +929 -0
- package/neural-interface/lib/loop-logger.js +31 -5
- package/neural-interface/lib/maritaca/api.js +179 -0
- package/neural-interface/lib/maritaca/attachments.js +44 -0
- package/neural-interface/lib/maritaca/client.js +362 -0
- package/neural-interface/lib/maritaca/key-store.js +122 -0
- package/neural-interface/lib/maritaca/models.js +181 -0
- package/neural-interface/lib/maritaca/modes.js +39 -0
- package/neural-interface/lib/maritaca/opencode-proxy.js +236 -0
- package/neural-interface/lib/maritaca/opencode-stream.js +345 -0
- package/neural-interface/lib/maritaca/opencode.js +218 -0
- package/neural-interface/lib/maritaca/panel-bridge.js +273 -0
- package/neural-interface/lib/maritaca/sessions.js +198 -0
- package/neural-interface/lib/mcp-external-servers.js +37 -10
- package/neural-interface/lib/morelogin-agent-profiles.js +149 -0
- package/neural-interface/lib/morelogin.js +278 -14
- package/neural-interface/lib/native-loop-providers.js +124 -11
- package/neural-interface/lib/native-loop-runtime.js +112 -11
- package/neural-interface/lib/owner-authority.js +137 -43
- package/neural-interface/lib/page-session.js +111 -27
- package/neural-interface/lib/peer-identity.js +263 -43
- package/neural-interface/lib/provider-panel-api-key-auth.js +7 -2
- package/neural-interface/lib/pty-host/core.js +36 -0
- package/neural-interface/lib/pty-host/protocol.js +2 -0
- package/neural-interface/lib/request-gate.js +2 -0
- package/neural-interface/lib/skills/api-v2.js +13 -2
- package/neural-interface/lib/skills/creation-api.js +3 -1
- package/neural-interface/lib/skills/evals-api.js +5 -1
- package/neural-interface/lib/social-write-pacing.js +151 -0
- package/neural-interface/lib/system-activity.js +1 -1
- package/neural-interface/lib/terminal-token-redaction.js +293 -0
- package/neural-interface/lib/terminal-tokens.js +436 -0
- package/neural-interface/lib/worker-mcp-channel.js +45 -10
- package/neural-interface/package-lock.json +3 -2
- package/neural-interface/package.json +2 -1
- package/neural-interface/public/assets/mascot/README.md +11 -0
- package/neural-interface/public/assets/mascot/ask.gif +0 -0
- package/neural-interface/public/assets/mascot/ask.png +0 -0
- package/neural-interface/public/assets/mascot/blocked.gif +0 -0
- package/neural-interface/public/assets/mascot/blocked.png +0 -0
- package/neural-interface/public/assets/mascot/budget.gif +0 -0
- package/neural-interface/public/assets/mascot/budget.png +0 -0
- package/neural-interface/public/assets/mascot/computer.gif +0 -0
- package/neural-interface/public/assets/mascot/computer.png +0 -0
- package/neural-interface/public/assets/mascot/edit.gif +0 -0
- package/neural-interface/public/assets/mascot/edit.png +0 -0
- package/neural-interface/public/assets/mascot/error.gif +0 -0
- package/neural-interface/public/assets/mascot/error.png +0 -0
- package/neural-interface/public/assets/mascot/hover-attention.gif +0 -0
- package/neural-interface/public/assets/mascot/hover-attention.png +0 -0
- package/neural-interface/public/assets/mascot/idle-hero.gif +0 -0
- package/neural-interface/public/assets/mascot/idle-hero.png +0 -0
- package/neural-interface/public/assets/mascot/idle.gif +0 -0
- package/neural-interface/public/assets/mascot/idle.png +0 -0
- package/neural-interface/public/assets/mascot/manifest.json +254 -0
- package/neural-interface/public/assets/mascot/mcp.gif +0 -0
- package/neural-interface/public/assets/mascot/mcp.png +0 -0
- package/neural-interface/public/assets/mascot/memory.gif +0 -0
- package/neural-interface/public/assets/mascot/memory.png +0 -0
- package/neural-interface/public/assets/mascot/offline.gif +0 -0
- package/neural-interface/public/assets/mascot/offline.png +0 -0
- package/neural-interface/public/assets/mascot/pick.gif +0 -0
- package/neural-interface/public/assets/mascot/pick.png +0 -0
- package/neural-interface/public/assets/mascot/plan.gif +0 -0
- package/neural-interface/public/assets/mascot/plan.png +0 -0
- package/neural-interface/public/assets/mascot/present.gif +0 -0
- package/neural-interface/public/assets/mascot/present.png +0 -0
- package/neural-interface/public/assets/mascot/project.gif +0 -0
- package/neural-interface/public/assets/mascot/project.png +0 -0
- package/neural-interface/public/assets/mascot/read.gif +0 -0
- package/neural-interface/public/assets/mascot/read.png +0 -0
- package/neural-interface/public/assets/mascot/runs.gif +0 -0
- package/neural-interface/public/assets/mascot/runs.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/automation.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/automation.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/browser.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/browser.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/code.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/code.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/complex.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/complex.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/computer.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/computer.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/design.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/design.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/edit.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/edit.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/generic.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/generic.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/image_gen.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/image_gen.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/manifest.json +173 -0
- package/neural-interface/public/assets/mascot/scenes/memory.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/memory.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/quick.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/quick.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/read.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/read.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/research.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/research.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/review.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/review.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/search.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/search.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/shell.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/shell.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/thinking.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/thinking.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/video_gen.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/video_gen.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/web.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/web.png +0 -0
- package/neural-interface/public/assets/mascot/search.gif +0 -0
- package/neural-interface/public/assets/mascot/search.png +0 -0
- package/neural-interface/public/assets/mascot/shell.gif +0 -0
- package/neural-interface/public/assets/mascot/shell.png +0 -0
- package/neural-interface/public/assets/mascot/skill.gif +0 -0
- package/neural-interface/public/assets/mascot/skill.png +0 -0
- package/neural-interface/public/assets/mascot/sleep.gif +0 -0
- package/neural-interface/public/assets/mascot/sleep.png +0 -0
- package/neural-interface/public/assets/mascot/subagent.gif +0 -0
- package/neural-interface/public/assets/mascot/subagent.png +0 -0
- package/neural-interface/public/assets/mascot/success.gif +0 -0
- package/neural-interface/public/assets/mascot/success.png +0 -0
- package/neural-interface/public/assets/mascot/think.gif +0 -0
- package/neural-interface/public/assets/mascot/think.png +0 -0
- package/neural-interface/public/assets/mascot/wait.gif +0 -0
- package/neural-interface/public/assets/mascot/wait.png +0 -0
- package/neural-interface/public/assets/mascot/watch.gif +0 -0
- package/neural-interface/public/assets/mascot/watch.png +0 -0
- package/neural-interface/public/assets/mascot/web.gif +0 -0
- package/neural-interface/public/assets/mascot/web.png +0 -0
- package/neural-interface/public/onboarding.html +14 -1
- package/neural-interface/public/shared/agent-runtime-options.js +49 -8
- package/neural-interface/public/shared/agy/agy-panel.js +2 -2
- package/neural-interface/public/shared/agy/agy-render.js +41 -1
- package/neural-interface/public/shared/agy/agy-styles.js +5 -0
- package/neural-interface/public/shared/api.js +5 -4
- package/neural-interface/public/shared/assistant/asst-ask-styles.js +8 -8
- package/neural-interface/public/shared/assistant/asst-ask.js +1 -1
- package/neural-interface/public/shared/assistant/asst-brain-picker.js +99 -9
- package/neural-interface/public/shared/assistant/asst-computer.js +47 -2
- package/neural-interface/public/shared/assistant/asst-control.js +1 -1
- package/neural-interface/public/shared/assistant/asst-limit-wait.js +7 -5
- package/neural-interface/public/shared/assistant/asst-panel.js +13 -5
- package/neural-interface/public/shared/assistant/asst-rack-styles.js +4 -4
- package/neural-interface/public/shared/assistant/asst-render.js +16 -10
- package/neural-interface/public/shared/assistant/asst-route-models.js +64 -4
- package/neural-interface/public/shared/assistant/asst-route.js +24 -7
- package/neural-interface/public/shared/assistant/asst-routes-editor.js +154 -39
- package/neural-interface/public/shared/assistant/asst-run-stage.js +3 -3
- package/neural-interface/public/shared/assistant/asst-scene-styles.js +8 -111
- package/neural-interface/public/shared/assistant/asst-scenes.js +46 -318
- package/neural-interface/public/shared/assistant/asst-sidepanel.js +2 -2
- package/neural-interface/public/shared/assistant/asst-state.js +72 -2
- package/neural-interface/public/shared/assistant/asst-styles.js +60 -15
- package/neural-interface/public/shared/automation-approval-view.js +75 -0
- package/neural-interface/public/shared/cdx/cdx-panel.js +2 -2
- package/neural-interface/public/shared/cdx/cdx-render.js +73 -7
- package/neural-interface/public/shared/cdx/cdx-tabs.js +3 -3
- package/neural-interface/public/shared/context-menu-model.js +2 -0
- package/neural-interface/public/shared/cp/cp-agents.js +8 -0
- package/neural-interface/public/shared/cp/cp-permissions.js +6 -2
- package/neural-interface/public/shared/cp/cp-rehydrate.js +25 -1
- package/neural-interface/public/shared/cp/cp-tasks-model.js +33 -0
- package/neural-interface/public/shared/editor/editor-panel-logic.js +10 -0
- package/neural-interface/public/shared/editor/editor-panel.js +10 -2
- package/neural-interface/public/shared/html-shell.js +30 -22
- package/neural-interface/public/shared/judgments-log-origins.js +29 -0
- package/neural-interface/public/shared/morelogin-profile-choices.js +107 -0
- package/neural-interface/public/shared/morelogin-profile-field.js +186 -0
- package/neural-interface/public/shared/mtc/mtc-client.js +181 -0
- package/neural-interface/public/shared/mtc/mtc-compose.js +40 -0
- package/neural-interface/public/shared/mtc/mtc-copy.js +253 -0
- package/neural-interface/public/shared/mtc/mtc-logic.js +478 -0
- package/neural-interface/public/shared/mtc/mtc-panel.js +1354 -0
- package/neural-interface/public/shared/mtc/mtc-render.js +172 -0
- package/neural-interface/public/shared/mtc/mtc-styles.js +437 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-automation-ownership.js +23 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-events.js +13 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-icons.js +3 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-panel.js +10 -4
- package/neural-interface/public/shared/ocp-v2/ocp-v2-render.js +6 -86
- package/neural-interface/public/shared/ocp-v2/ocp-v2-ws.js +5 -2
- package/neural-interface/public/shared/owner-access.js +134 -0
- package/neural-interface/public/shared/owner-authority-view.js +92 -0
- package/neural-interface/public/shared/page-session.js +143 -14
- package/neural-interface/public/shared/poll-backoff.js +59 -0
- package/neural-interface/public/shared/provider-icons.js +3 -0
- package/neural-interface/public/shared/schedules-view.js +7 -0
- package/neural-interface/public/shared/server-back.js +50 -0
- package/neural-interface/public/shared/settings/settings-browser-owner-access.js +72 -0
- package/neural-interface/public/shared/settings/settings-data.js +7 -1
- package/neural-interface/public/shared/settings/settings-ia.js +3 -1
- package/neural-interface/public/shared/settings/settings-kit.js +11 -3
- package/neural-interface/public/shared/settings/settings-local-profiles.js +153 -0
- package/neural-interface/public/shared/settings/settings-maritaca-opencode.js +105 -0
- package/neural-interface/public/shared/settings/settings-shell.js +7 -0
- package/neural-interface/public/shared/shown-children.js +72 -0
- package/neural-interface/public/shared/sidepanel-session-status.js +16 -2
- package/neural-interface/public/shared/state.js +1 -1
- package/neural-interface/public/shared/static-bg-state.js +22 -0
- package/neural-interface/public/shared/styles.css +457 -164
- package/neural-interface/public/shared/synabun-mascot-assets.js +67 -0
- package/neural-interface/public/shared/synabun-mascot.js +136 -12
- package/neural-interface/public/shared/synabun-ticker.js +3 -0
- package/neural-interface/public/shared/synabun-tools.js +173 -0
- package/neural-interface/public/shared/tool-heartbeat.js +43 -0
- package/neural-interface/public/shared/tool-list-picker.js +3 -1
- package/neural-interface/public/shared/tool-list-view.js +23 -4
- package/neural-interface/public/shared/topright-overflow-logic.js +1 -0
- package/neural-interface/public/shared/ui-automation-approval.js +188 -0
- package/neural-interface/public/shared/ui-automation-studio.js +138 -91
- package/neural-interface/public/shared/ui-claude-panel.js +209 -31
- package/neural-interface/public/shared/ui-judgments.js +37 -10
- package/neural-interface/public/shared/ui-maritaca-panel.js +15 -0
- package/neural-interface/public/shared/ui-navbar.js +23 -0
- package/neural-interface/public/shared/ui-owner-access.js +191 -0
- package/neural-interface/public/shared/ui-owner-authority.js +162 -0
- package/neural-interface/public/shared/ui-panels.js +3 -1
- package/neural-interface/public/shared/ui-schedules-studio.js +118 -17
- package/neural-interface/public/shared/ui-scroll-follow.js +3 -0
- package/neural-interface/public/shared/ui-sessions.js +45 -16
- package/neural-interface/public/shared/ui-settings.js +676 -42
- package/neural-interface/public/shared/ui-sidepanel-session-entry.js +8 -2
- package/neural-interface/public/shared/ui-sidepanel-sessions.js +3 -3
- package/neural-interface/public/shared/ui-sidepanel-tray.js +24 -0
- package/neural-interface/public/shared/ui-sidepanel-windows.js +1 -1
- package/neural-interface/public/shared/ui-terminal.js +15 -7
- package/neural-interface/public/shared/ui-tutorial-preview.js +4 -0
- package/neural-interface/public/shared/ui-update.js +3 -0
- package/neural-interface/public/shared/ui-whiteboard.js +4 -0
- package/neural-interface/public/shared/window-keys.js +38 -0
- package/neural-interface/scripts/build-mascot-assets.mjs +30 -0
- package/neural-interface/server.js +2903 -359
- package/npm-shrinkwrap.json +5 -17
- package/package.json +5 -6
- package/postinstall.js +38 -39
- package/setup.js +33 -31
- package/skills/synabun/modules/changelog.md +14 -0
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
// ═══════════════════════════════════════════
|
|
2
|
+
// SynaBun — the Maritaca side panel's server end (/ws/maritaca)
|
|
3
|
+
// ═══════════════════════════════════════════
|
|
4
|
+
//
|
|
5
|
+
// One socket per panel window; no process (Maritaca is an HTTP API: lib/maritaca/client.js), so a
|
|
6
|
+
// turn is one streamed chat completion over the conversation's saved history (lib/maritaca/sessions.js).
|
|
7
|
+
// The page asks with `{ type, reqId, ... }` and gets `{ type: 'result', reqId, ok, data | error, code }`;
|
|
8
|
+
// what happens on its own comes as events:
|
|
9
|
+
//
|
|
10
|
+
// turn:start { sessionId, turnId, model, mode }
|
|
11
|
+
// turn:delta { sessionId, turnId, text } answer text as it streams
|
|
12
|
+
// turn:reasoning { sessionId, turnId, text } reasoning text (S5, Sabiá 4 Thinking)
|
|
13
|
+
// turn:end { sessionId, turnId, text, reasoning, usage, costBrl, finishReason, mode, error?, code? }
|
|
14
|
+
// settings:changed { status } the key or the defaults changed (any window)
|
|
15
|
+
//
|
|
16
|
+
// The hello carries the shipped model table whole (lib/maritaca/models.js rows), so the page can draw its pickers at
|
|
17
|
+
// once; `models` asks the API for the current list, merged over that table.
|
|
18
|
+
// Requests: hello, models, session:new, session:list, session:load, session:rename, session:delete, session:project,
|
|
19
|
+
// prompt, regenerate, cancel. `prompt` / `regenerate` take `mode: 'chat' | 'plan'` (lib/maritaca/modes.js: a plan turn
|
|
20
|
+
// carries the plan instruction after the user's system prompt and is saved as a plan; capability 'plan-mode') and a
|
|
21
|
+
// reasoning level, an alias of one included (models.js normalizeMaritacaEffort). The key is never on this socket: it is saved, tested and cleared through
|
|
22
|
+
// /api/maritaca/settings (lib/maritaca/api.js) and read here per prompt from the key store, so a key
|
|
23
|
+
// saved while a panel is open is used by its next prompt. `capabilities` in the hello answer lists
|
|
24
|
+
// what this server does; the page offers a feature only while it is listed (public/ reloads at any
|
|
25
|
+
// time, lib/ only with a restart). Nothing the page sends is trusted: ids are SynaBun's own 32-hex
|
|
26
|
+
// ids, text is bounded, a model is one the table or the API's list knows (the ids of the last `models` answer that
|
|
27
|
+
// came from the API are kept for that; else the saved default).
|
|
28
|
+
|
|
29
|
+
import { MARITACA_SESSION_LIMITS, historyForRequest, isSessionId } from './sessions.js';
|
|
30
|
+
import { findMaritacaModel, maritacaModelRows, maritacaUsageCostBrl, normalizeMaritacaEffort } from './models.js';
|
|
31
|
+
import { inlineMaritacaAttachments, MARITACA_ATTACHMENT_LIMITS } from './attachments.js';
|
|
32
|
+
import { maritacaSystemPrompt, normalizeMaritacaMode } from './modes.js';
|
|
33
|
+
|
|
34
|
+
export const MARITACA_WS_PATH = '/ws/maritaca';
|
|
35
|
+
export const MARITACA_PANEL_CAPABILITIES = Object.freeze([
|
|
36
|
+
'session-new', 'session-list', 'session-load', 'session-rename', 'session-delete', 'prompt', 'cancel', 'models',
|
|
37
|
+
'reasoning', 'reasoning-effort', 'usage', 'cost-brl', 'system-prompt', 'greeting-note',
|
|
38
|
+
'attachments', 'regenerate', 'edit-resend', 'session-project', 'plan-mode', 'effort-levels',
|
|
39
|
+
]);
|
|
40
|
+
export const MARITACA_LIMITS = Object.freeze({
|
|
41
|
+
maxPromptChars: MARITACA_SESSION_LIMITS.maxMessageChars,
|
|
42
|
+
maxTitleChars: MARITACA_SESSION_LIMITS.maxTitleChars,
|
|
43
|
+
maxProjectChars: 1000,
|
|
44
|
+
attachments: MARITACA_ATTACHMENT_LIMITS,
|
|
45
|
+
});
|
|
46
|
+
const REQ_ID_RE = /^[A-Za-z0-9._:-]{1,80}$/;
|
|
47
|
+
|
|
48
|
+
function bridgeError(code, message, status = 400) { return Object.assign(new Error(message), { code, status }); }
|
|
49
|
+
const str = (v, max) => (typeof v === 'string' ? v.slice(0, max) : '');
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @param {object} deps
|
|
53
|
+
* @param {object} deps.client lib/maritaca/client.js
|
|
54
|
+
* @param {object} deps.keyStore lib/maritaca/key-store.js
|
|
55
|
+
* @param {object} deps.sessions lib/maritaca/sessions.js
|
|
56
|
+
* @param {(info:{ sessionId:string, project:string|null, words:string })=>void} [deps.onHumanPrompt]
|
|
57
|
+
* @param {(line:string)=>void} [deps.log]
|
|
58
|
+
*/
|
|
59
|
+
export function createMaritacaPanelBridge({ client, keyStore, sessions, onHumanPrompt = null, log = () => {} } = {}) {
|
|
60
|
+
if (!client || !keyStore || !sessions) throw new Error('createMaritacaPanelBridge needs client, keyStore and sessions');
|
|
61
|
+
const live = new Set(); // socket states
|
|
62
|
+
const turns = new Map(); // sessionId → { turnId, controller, socket }
|
|
63
|
+
let liveModelIds = new Map(); // lower-cased id → id as the API listed it (the last live `models` answer)
|
|
64
|
+
let liveModelRows = new Map();
|
|
65
|
+
let turnSeq = 0;
|
|
66
|
+
|
|
67
|
+
function broadcast(message) { for (const state of live) state.send(message); }
|
|
68
|
+
|
|
69
|
+
function resolveModel(requested) {
|
|
70
|
+
const settings = keyStore.readSettings();
|
|
71
|
+
const row = findMaritacaModel(requested);
|
|
72
|
+
if (row) return row.id;
|
|
73
|
+
const wanted = str(requested, 80).trim();
|
|
74
|
+
const live = wanted ? liveModelIds.get(wanted.toLowerCase()) : null;
|
|
75
|
+
if (live) return live;
|
|
76
|
+
const fallback = findMaritacaModel(settings.model);
|
|
77
|
+
return fallback ? fallback.id : settings.model;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function runTurn(state, { sessionId, text, model, reasoningEffort, mode: requestedMode, attachments = [], messageIndex = null, editText }) {
|
|
81
|
+
const session = sessions.get(sessionId);
|
|
82
|
+
if (!session) throw bridgeError('SESSION_UNKNOWN', 'That conversation no longer exists.', 404);
|
|
83
|
+
if (turns.has(sessionId)) throw bridgeError('TURN_RUNNING', 'A reply is already streaming in this conversation.', 409);
|
|
84
|
+
const key = keyStore.readKey();
|
|
85
|
+
if (!key) throw bridgeError('NO_KEY', 'Save a Maritaca API key first.', 412);
|
|
86
|
+
const chosen = resolveModel(model || session.model);
|
|
87
|
+
const settings = keyStore.readSettings();
|
|
88
|
+
const row = findMaritacaModel(chosen) || liveModelRows.get(chosen.toLowerCase());
|
|
89
|
+
const asked = normalizeMaritacaEffort(reasoningEffort);
|
|
90
|
+
const saved = normalizeMaritacaEffort(settings.reasoningEffort);
|
|
91
|
+
const effort = asked && row?.efforts?.includes(asked) ? asked : saved && row?.efforts?.includes(saved) ? saved : null;
|
|
92
|
+
// A regenerate or an edit that names no mode keeps the mode of the prompt it reruns (a plan is regenerated as a plan).
|
|
93
|
+
const mode = requestedMode !== undefined ? normalizeMaritacaMode(requestedMode) : messageIndex !== null ? normalizeMaritacaMode(session.messages[messageIndex]?.mode) : 'chat';
|
|
94
|
+
if (messageIndex !== null) {
|
|
95
|
+
if (!Number.isInteger(messageIndex) || session.messages[messageIndex]?.role !== 'user') throw bridgeError('PROMPT_UNKNOWN', 'Choose a user message to retry.');
|
|
96
|
+
if (session.messages.slice(0, messageIndex + 1).some((m) => m.images?.length) && row?.vision !== true) throw bridgeError('IMAGE_UNSUPPORTED', 'This model does not read images.');
|
|
97
|
+
sessions.rewind(sessionId, messageIndex, editText, { mode });
|
|
98
|
+
} else {
|
|
99
|
+
if (session.messages.some((m) => m.images?.length) && row?.vision !== true) throw bridgeError('IMAGE_UNSUPPORTED', 'This model does not read images.');
|
|
100
|
+
const prompt = inlineMaritacaAttachments(text, attachments, { vision: row?.vision === true });
|
|
101
|
+
sessions.append(sessionId, { role: 'user', ...prompt, mode });
|
|
102
|
+
}
|
|
103
|
+
if (session.model !== chosen) sessions.update(sessionId, { model: chosen });
|
|
104
|
+
const history = historyForRequest(sessions.get(sessionId).messages, { systemPrompt: maritacaSystemPrompt({ systemPrompt: settings.systemPrompt, mode }) });
|
|
105
|
+
const turnId = `t${Date.now().toString(36)}-${++turnSeq}`;
|
|
106
|
+
const controller = new AbortController();
|
|
107
|
+
const snapshot = sessions.get(sessionId);
|
|
108
|
+
const turn = { turnId, controller, socket: state, sessionId, model: chosen, mode, startedAt: Date.now(), partialText: '', partialReasoning: '' };
|
|
109
|
+
turns.set(sessionId, turn);
|
|
110
|
+
try { onHumanPrompt?.({ sessionId, project: session.project || null, words: text }); } catch { /* the greeting's problem */ }
|
|
111
|
+
broadcast({ type: 'turn:start', sessionId, turnId, model: chosen, mode, startedAt: turn.startedAt, session: snapshot });
|
|
112
|
+
(async () => {
|
|
113
|
+
let result = null;
|
|
114
|
+
let failure = null;
|
|
115
|
+
try {
|
|
116
|
+
result = await client.chatStream({
|
|
117
|
+
key, model: chosen, messages: history, reasoningEffort: effort, temperature: settings.temperature, signal: controller.signal,
|
|
118
|
+
onEvent: (event) => {
|
|
119
|
+
// Kept here too: the client's chatStream rejects on a stop or a failure without handing back what streamed.
|
|
120
|
+
if (event.type === 'delta') { const offset = turn.partialText.length; turn.partialText += event.text || ''; broadcast({ type: 'turn:delta', sessionId, turnId, text: event.text, offset }); }
|
|
121
|
+
else if (event.type === 'reasoning') { const offset = turn.partialReasoning.length; turn.partialReasoning += event.text || ''; broadcast({ type: 'turn:reasoning', sessionId, turnId, text: event.text, offset }); }
|
|
122
|
+
},
|
|
123
|
+
partial: null,
|
|
124
|
+
});
|
|
125
|
+
} catch (error) {
|
|
126
|
+
failure = error;
|
|
127
|
+
}
|
|
128
|
+
turns.delete(sessionId);
|
|
129
|
+
const cancelled = controller.signal.aborted;
|
|
130
|
+
const text = result?.text || turn.partialText || '';
|
|
131
|
+
const reasoning = result?.reasoning || turn.partialReasoning || '';
|
|
132
|
+
const usage = result?.usage || null;
|
|
133
|
+
const costBrl = usage ? maritacaUsageCostBrl(chosen, usage) : null;
|
|
134
|
+
const finishReason = cancelled ? 'cancelled' : failure ? 'error' : result?.finishReason || 'stop';
|
|
135
|
+
const errorMessage = failure && !cancelled ? failure.message : null;
|
|
136
|
+
const code = failure && !cancelled ? failure.code || 'HTTP_ERROR' : null;
|
|
137
|
+
// The reply is saved whatever happened: a stop keeps what streamed (finishReason 'cancelled'); a failure leaves what
|
|
138
|
+
// streamed, or an empty assistant row, with its error, so the conversation shows what went wrong when it is opened again.
|
|
139
|
+
try { sessions.append(sessionId, { role: 'assistant', turnId, content: text, reasoning, usage, costBrl, model: chosen, finishReason, error: errorMessage, mode }); }
|
|
140
|
+
catch (error) { log(`[maritaca] could not save a reply: ${error?.message || error}`); }
|
|
141
|
+
if (failure && !cancelled) log(`[maritaca] turn failed: ${code} ${failure.message}`);
|
|
142
|
+
let saved = null;
|
|
143
|
+
try { saved = sessions.get(sessionId); } catch { /* completion still reaches the page after a storage failure */ }
|
|
144
|
+
broadcast({ type: 'turn:end', sessionId, turnId, text, reasoning, usage, costBrl, finishReason, mode, ...(saved ? { messageCount: saved.messages.length, priorCostBrl: saved.priorCostBrl || 0 } : {}), ...(errorMessage ? { error: errorMessage, code } : {}) });
|
|
145
|
+
})();
|
|
146
|
+
return { turnId, model: chosen, reasoningEffort: effort, mode, session: snapshot };
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function removeSession(sessionId) {
|
|
150
|
+
if (!isSessionId(sessionId)) throw bridgeError('SESSION_INVALID', 'Unknown conversation.');
|
|
151
|
+
turns.get(sessionId)?.controller.abort(new Error('deleted'));
|
|
152
|
+
const deleted = sessions.remove(sessionId);
|
|
153
|
+
broadcast({ type: 'session:deleted', sessionId });
|
|
154
|
+
return { deleted };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function renameSession(sessionId, title) {
|
|
158
|
+
if (!isSessionId(sessionId)) throw bridgeError('SESSION_INVALID', 'Unknown conversation.');
|
|
159
|
+
const session = sessions.update(sessionId, { title: str(title, MARITACA_LIMITS.maxTitleChars) });
|
|
160
|
+
if (!session) throw bridgeError('SESSION_UNKNOWN', 'That conversation no longer exists.', 404);
|
|
161
|
+
broadcast({ type: 'session:renamed', sessionId, title: session.title });
|
|
162
|
+
return { session: { id: session.id, title: session.title } };
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const handlers = {
|
|
166
|
+
async hello() {
|
|
167
|
+
const status = keyStore.status();
|
|
168
|
+
return { capabilities: [...MARITACA_PANEL_CAPABILITIES], limits: { ...MARITACA_LIMITS }, configured: status.configured, source: status.source, masked: status.masked, settings: status.settings, models: maritacaModelRows() };
|
|
169
|
+
},
|
|
170
|
+
async models() {
|
|
171
|
+
const listed = await client.listModels({ key: keyStore.readKey() });
|
|
172
|
+
if (listed.source === 'live' && Array.isArray(listed.models)) {
|
|
173
|
+
liveModelIds = new Map(listed.models.filter((m) => typeof m?.id === 'string' && m.id.trim()).map((m) => [m.id.trim().toLowerCase(), m.id.trim().slice(0, 80)]));
|
|
174
|
+
liveModelRows = new Map(listed.models.filter((m) => typeof m?.id === 'string').map((m) => [m.id.toLowerCase(), m]));
|
|
175
|
+
}
|
|
176
|
+
return { models: listed.models, source: listed.source, ...(listed.error ? { error: listed.error } : {}) };
|
|
177
|
+
},
|
|
178
|
+
async 'session:new'(msg) {
|
|
179
|
+
const session = sessions.create({ title: str(msg.title, MARITACA_LIMITS.maxTitleChars), model: resolveModel(msg.model), project: str(msg.project, MARITACA_LIMITS.maxProjectChars) || null });
|
|
180
|
+
return { session };
|
|
181
|
+
},
|
|
182
|
+
async 'session:list'(msg) {
|
|
183
|
+
return { sessions: sessions.list({ project: str(msg.project, MARITACA_LIMITS.maxProjectChars) || null, limit: msg.limit }) };
|
|
184
|
+
},
|
|
185
|
+
async 'session:load'(msg) {
|
|
186
|
+
if (!isSessionId(msg.sessionId)) throw bridgeError('SESSION_INVALID', 'Unknown conversation.');
|
|
187
|
+
const session = sessions.get(msg.sessionId);
|
|
188
|
+
if (!session) throw bridgeError('SESSION_UNKNOWN', 'That conversation no longer exists.', 404);
|
|
189
|
+
const turn = turns.get(session.id);
|
|
190
|
+
return { session, running: turn?.turnId || null, partial: turn ? { turnId: turn.turnId, text: turn.partialText, reasoning: turn.partialReasoning, startedAt: turn.startedAt, model: turn.model, mode: turn.mode } : null };
|
|
191
|
+
},
|
|
192
|
+
async 'session:rename'(msg) {
|
|
193
|
+
return renameSession(msg.sessionId, msg.title);
|
|
194
|
+
},
|
|
195
|
+
async 'session:delete'(msg) {
|
|
196
|
+
return removeSession(msg.sessionId);
|
|
197
|
+
},
|
|
198
|
+
async 'session:project'(msg) {
|
|
199
|
+
if (!isSessionId(msg.sessionId)) throw bridgeError('SESSION_INVALID', 'Unknown conversation.');
|
|
200
|
+
const session = sessions.update(msg.sessionId, { project: str(msg.project, MARITACA_LIMITS.maxProjectChars) || null });
|
|
201
|
+
if (!session) throw bridgeError('SESSION_UNKNOWN', 'That conversation no longer exists.', 404);
|
|
202
|
+
return { session: { id: session.id, project: session.project } };
|
|
203
|
+
},
|
|
204
|
+
async prompt(msg, state) {
|
|
205
|
+
if (!isSessionId(msg.sessionId)) throw bridgeError('SESSION_INVALID', 'Unknown conversation.');
|
|
206
|
+
const text = typeof msg.text === 'string' ? msg.text : '';
|
|
207
|
+
if (!text.trim() && !msg.attachments?.length) throw bridgeError('PROMPT_EMPTY', 'Type something first.');
|
|
208
|
+
if (text.length > MARITACA_LIMITS.maxPromptChars) throw bridgeError('PROMPT_TOO_LONG', `The message is longer than ${MARITACA_LIMITS.maxPromptChars} characters.`);
|
|
209
|
+
return runTurn(state, { sessionId: msg.sessionId, text, attachments: msg.attachments ?? [], model: str(msg.model, 80), reasoningEffort: str(msg.reasoningEffort, 20), mode: msg.mode === undefined ? 'chat' : str(msg.mode, 10) });
|
|
210
|
+
},
|
|
211
|
+
async regenerate(msg, state) {
|
|
212
|
+
if (!isSessionId(msg.sessionId)) throw bridgeError('SESSION_INVALID', 'Unknown conversation.');
|
|
213
|
+
const session = sessions.get(msg.sessionId);
|
|
214
|
+
if (!session) throw bridgeError('SESSION_UNKNOWN', 'That conversation no longer exists.', 404);
|
|
215
|
+
const messageIndex = msg.messageIndex === undefined ? session.messages.findLastIndex((m) => m.role === 'user') : msg.messageIndex;
|
|
216
|
+
if (!Number.isInteger(messageIndex) || session.messages[messageIndex]?.role !== 'user') throw bridgeError('PROMPT_UNKNOWN', 'Choose a user message to retry.');
|
|
217
|
+
if (msg.text !== undefined && (typeof msg.text !== 'string' || !msg.text.trim())) throw bridgeError('PROMPT_EMPTY', 'Type something first.');
|
|
218
|
+
if (typeof msg.text === 'string' && msg.text.length > MARITACA_LIMITS.maxPromptChars) throw bridgeError('PROMPT_TOO_LONG', 'The message is too long.');
|
|
219
|
+
return runTurn(state, { sessionId: msg.sessionId, text: msg.text ?? '', editText: msg.text, messageIndex, model: str(msg.model, 80), reasoningEffort: str(msg.reasoningEffort, 20), mode: msg.mode === undefined ? undefined : str(msg.mode, 10) });
|
|
220
|
+
},
|
|
221
|
+
async cancel(msg) {
|
|
222
|
+
if (!isSessionId(msg.sessionId)) throw bridgeError('SESSION_INVALID', 'Unknown conversation.');
|
|
223
|
+
const running = turns.get(msg.sessionId);
|
|
224
|
+
if (!running) return { cancelled: false };
|
|
225
|
+
running.controller.abort(new Error('cancelled'));
|
|
226
|
+
return { cancelled: true, turnId: running.turnId };
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
function handleSocket(ws) {
|
|
231
|
+
let closed = false;
|
|
232
|
+
const state = {
|
|
233
|
+
send(message) {
|
|
234
|
+
if (closed || ws.readyState !== 1) return;
|
|
235
|
+
try { ws.send(JSON.stringify(message)); } catch { /* the close handler cleans up */ }
|
|
236
|
+
},
|
|
237
|
+
};
|
|
238
|
+
live.add(state);
|
|
239
|
+
ws.on('message', async (raw) => {
|
|
240
|
+
let msg;
|
|
241
|
+
try { msg = JSON.parse(String(raw)); } catch { state.send({ type: 'result', reqId: null, ok: false, code: 'BAD_JSON', error: 'Not JSON.' }); return; }
|
|
242
|
+
const reqId = REQ_ID_RE.test(String(msg?.reqId || '')) ? String(msg.reqId) : null;
|
|
243
|
+
const type = typeof msg?.type === 'string' ? msg.type : '';
|
|
244
|
+
const handler = Object.hasOwn(handlers, type) ? handlers[type] : null;
|
|
245
|
+
if (!handler) { state.send({ type: 'result', reqId, ok: false, code: 'UNKNOWN_REQUEST', error: `Unknown request: ${type || '?'}` }); return; }
|
|
246
|
+
try {
|
|
247
|
+
const data = await handler(msg, state);
|
|
248
|
+
state.send({ type: 'result', reqId, ok: true, data });
|
|
249
|
+
} catch (error) {
|
|
250
|
+
state.send({ type: 'result', reqId, ok: false, code: error?.code || 'ERROR', error: error?.message || 'Something went wrong.' });
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
const end = () => { closed = true; live.delete(state); };
|
|
254
|
+
ws.on('close', end);
|
|
255
|
+
ws.on('error', end);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
return {
|
|
259
|
+
handleSocket,
|
|
260
|
+
liveCount: () => live.size,
|
|
261
|
+
turnsRunning: () => turns.size,
|
|
262
|
+
removeSession,
|
|
263
|
+
renameSession,
|
|
264
|
+
/** The key or the defaults changed (the REST router says so): every open panel is told. */
|
|
265
|
+
notifySettingsChanged: () => broadcast({ type: 'settings:changed', status: keyStore.status() }),
|
|
266
|
+
closeAll: async () => {
|
|
267
|
+
for (const turn of turns.values()) turn.controller.abort(new Error('shutdown'));
|
|
268
|
+
turns.clear();
|
|
269
|
+
live.clear();
|
|
270
|
+
},
|
|
271
|
+
_handlers: handlers,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
// ═══════════════════════════════════════════
|
|
2
|
+
// SynaBun — Maritaca AI: the conversation store
|
|
3
|
+
// ═══════════════════════════════════════════
|
|
4
|
+
//
|
|
5
|
+
// Maritaca keeps no conversation on its side: every request carries the whole history. SynaBun keeps
|
|
6
|
+
// each conversation as one JSON file, DATA_HOME/data/maritaca/sessions/<id>.json ({ id, title, model,
|
|
7
|
+
// project, createdAt, updatedAt, messages: [{ role, content, reasoning?, usage?, costBrl?, mode?, at }] }),
|
|
8
|
+
// bounded in messages and bytes; an id is SynaBun's own (never from a page), a project is a plain
|
|
9
|
+
// string the page shows (no file is read from it). Pure helpers first, then the store.
|
|
10
|
+
|
|
11
|
+
import { mkdirSync, readFileSync, readdirSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
12
|
+
import { randomUUID } from 'node:crypto';
|
|
13
|
+
import { join } from 'node:path';
|
|
14
|
+
|
|
15
|
+
export const MARITACA_SESSION_LIMITS = Object.freeze({
|
|
16
|
+
maxMessages: 400,
|
|
17
|
+
maxMessageChars: 200_000,
|
|
18
|
+
maxTitleChars: 120,
|
|
19
|
+
maxSessions: 500,
|
|
20
|
+
maxHistoryChars: 1_500_000, // what one request may carry; older turns are dropped first (the system prompt stays)
|
|
21
|
+
pruneGraceMs: 60_000, // a conversation updated this recently is never pruned to make room for a new one
|
|
22
|
+
});
|
|
23
|
+
const ID_RE = /^[a-f0-9]{32}$/;
|
|
24
|
+
|
|
25
|
+
export function newSessionId() { return randomUUID().replace(/-/g, ''); }
|
|
26
|
+
export function isSessionId(id) { return typeof id === 'string' && ID_RE.test(id); }
|
|
27
|
+
|
|
28
|
+
/** The title a first prompt gives a conversation: its first line, trimmed and bounded. */
|
|
29
|
+
export function titleFromPrompt(text, max = MARITACA_SESSION_LIMITS.maxTitleChars) {
|
|
30
|
+
const line = String(text || '').split(/\r?\n/).map((s) => s.trim()).find(Boolean) || '';
|
|
31
|
+
return line.length > max ? `${line.slice(0, max - 1).trimEnd()}…` : line;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The messages a request carries for a conversation: the system prompt (when any) and the newest
|
|
36
|
+
* turns that fit `maxChars`, oldest dropped first, never a tool message left without its call. An assistant row
|
|
37
|
+
* with no content (a failed or stopped turn) stays in the stored conversation for display but is left out of a
|
|
38
|
+
* request: some OpenAI-compatible servers refuse an empty assistant message with 400.
|
|
39
|
+
*/
|
|
40
|
+
export function historyForRequest(messages, { systemPrompt = '', maxChars = MARITACA_SESSION_LIMITS.maxHistoryChars } = {}) {
|
|
41
|
+
const turns = (Array.isArray(messages) ? messages : [])
|
|
42
|
+
.filter((m) => m && (m.role === 'user' || m.role === 'assistant') && typeof m.content === 'string')
|
|
43
|
+
.filter((m) => m.role !== 'assistant' || m.content.trim());
|
|
44
|
+
const out = [];
|
|
45
|
+
let used = systemPrompt.length;
|
|
46
|
+
for (let i = turns.length - 1; i >= 0; i--) {
|
|
47
|
+
const m = turns[i];
|
|
48
|
+
if (used + m.content.length > maxChars && out.length) break;
|
|
49
|
+
used += m.content.length;
|
|
50
|
+
out.unshift({ role: m.role, content: m.role === 'user' && m.images?.length ? [{ type: 'text', text: m.content }, ...m.images] : m.content });
|
|
51
|
+
}
|
|
52
|
+
return systemPrompt.trim() ? [{ role: 'system', content: systemPrompt }, ...out] : out;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The summary row a list shows. */
|
|
56
|
+
export function sessionSummary(session) {
|
|
57
|
+
const messages = Array.isArray(session?.messages) ? session.messages : [];
|
|
58
|
+
const last = messages[messages.length - 1] || null;
|
|
59
|
+
return {
|
|
60
|
+
id: session.id, title: session.title || '', model: session.model || null, project: session.project || null,
|
|
61
|
+
createdAt: session.createdAt, updatedAt: session.updatedAt, messageCount: messages.length,
|
|
62
|
+
preview: last ? String(last.content || '').slice(0, 160) : '',
|
|
63
|
+
costBrl: (Number(session.priorCostBrl) || 0) + messages.reduce((sum, m) => sum + (Number(m.costBrl) || 0), 0),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function createMaritacaSessionStore({ dir, limits = MARITACA_SESSION_LIMITS, now = () => new Date().toISOString() } = {}) {
|
|
68
|
+
if (!dir) throw new Error('createMaritacaSessionStore needs dir');
|
|
69
|
+
const pathOf = (id) => { if (!isSessionId(id)) throw Object.assign(new Error('Unknown conversation.'), { code: 'SESSION_INVALID', status: 400 }); return join(dir, `${id}.json`); };
|
|
70
|
+
|
|
71
|
+
function write(session) {
|
|
72
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
73
|
+
const target = pathOf(session.id);
|
|
74
|
+
const temp = `${target}.${randomUUID()}.tmp`;
|
|
75
|
+
try { writeFileSync(temp, JSON.stringify(session), { mode: 0o600, flag: 'wx' }); renameSync(temp, target); }
|
|
76
|
+
finally { rmSync(temp, { force: true }); }
|
|
77
|
+
return session;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function get(id) {
|
|
81
|
+
const path = pathOf(id);
|
|
82
|
+
let raw;
|
|
83
|
+
try { raw = readFileSync(path, 'utf8'); } catch (error) { if (error.code === 'ENOENT') return null; throw error; }
|
|
84
|
+
try {
|
|
85
|
+
const session = JSON.parse(raw);
|
|
86
|
+
if (!session || session.id !== id || !Array.isArray(session.messages)) return null;
|
|
87
|
+
return session;
|
|
88
|
+
} catch { return null; }
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function create({ title = '', model = null, project = null } = {}) {
|
|
92
|
+
const at = now();
|
|
93
|
+
const existing = list({ limit: 1000 });
|
|
94
|
+
if (existing.length >= limits.maxSessions) {
|
|
95
|
+
// The oldest conversations make room, never one updated within the grace (a turn may be streaming into it);
|
|
96
|
+
// when every candidate is that fresh nothing is pruned and the cap is exceeded for a while.
|
|
97
|
+
const grace = Number.isFinite(limits.pruneGraceMs) ? limits.pruneGraceMs : MARITACA_SESSION_LIMITS.pruneGraceMs;
|
|
98
|
+
const fresh = (row) => Date.parse(at) - Date.parse(row.updatedAt) < grace;
|
|
99
|
+
let excess = existing.length - (limits.maxSessions - 1);
|
|
100
|
+
for (let i = existing.length - 1; i >= 0 && excess > 0; i--) {
|
|
101
|
+
if (fresh(existing[i])) continue;
|
|
102
|
+
rmSync(join(dir, `${existing[i].id}.json`), { force: true });
|
|
103
|
+
excess--;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const session = {
|
|
107
|
+
id: newSessionId(), title: String(title || '').slice(0, limits.maxTitleChars), model: model ? String(model).slice(0, 80) : null,
|
|
108
|
+
project: project ? String(project).slice(0, 1000) : null, createdAt: at, updatedAt: at, messages: [],
|
|
109
|
+
};
|
|
110
|
+
return write(session);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function update(id, patch = {}) {
|
|
114
|
+
const session = get(id);
|
|
115
|
+
if (!session) return null;
|
|
116
|
+
if (typeof patch.title === 'string') session.title = patch.title.trim().slice(0, limits.maxTitleChars);
|
|
117
|
+
if (patch.model !== undefined) session.model = patch.model ? String(patch.model).slice(0, 80) : null;
|
|
118
|
+
if (patch.project !== undefined) session.project = patch.project ? String(patch.project).slice(0, 1000) : null;
|
|
119
|
+
session.updatedAt = now();
|
|
120
|
+
return write(session);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Appends one message ({ role, content, reasoning?, usage?, costBrl?, model? }); the oldest go when the list is full. */
|
|
124
|
+
function append(id, message) {
|
|
125
|
+
const session = get(id);
|
|
126
|
+
if (!session) return null;
|
|
127
|
+
const role = ['user', 'assistant'].includes(message?.role) ? message.role : null;
|
|
128
|
+
if (!role) throw Object.assign(new Error('A message is a user or assistant message.'), { code: 'MESSAGE_INVALID', status: 400 });
|
|
129
|
+
const content = String(message.content ?? '').slice(0, limits.maxMessageChars);
|
|
130
|
+
const entry = { role, content, at: now() };
|
|
131
|
+
if (role === 'user') {
|
|
132
|
+
if (typeof message.displayText === 'string') entry.displayText = message.displayText.slice(0, limits.maxMessageChars);
|
|
133
|
+
if (typeof message.attachmentText === 'string') entry.attachmentText = message.attachmentText.slice(0, limits.maxMessageChars);
|
|
134
|
+
if (Array.isArray(message.attachments)) entry.attachments = message.attachments.slice(0, 5);
|
|
135
|
+
if (Array.isArray(message.images) && message.images.length) entry.images = message.images.slice(0, 5);
|
|
136
|
+
}
|
|
137
|
+
if (typeof message.reasoning === 'string' && message.reasoning) entry.reasoning = message.reasoning.slice(0, limits.maxMessageChars);
|
|
138
|
+
if (message.usage && typeof message.usage === 'object') entry.usage = message.usage;
|
|
139
|
+
if (message.costBrl != null && Number.isFinite(Number(message.costBrl))) entry.costBrl = Number(message.costBrl);
|
|
140
|
+
if (message.model) entry.model = String(message.model).slice(0, 80);
|
|
141
|
+
if (message.turnId) entry.turnId = String(message.turnId).slice(0, 80);
|
|
142
|
+
if (message.finishReason) entry.finishReason = String(message.finishReason).slice(0, 40);
|
|
143
|
+
if (message.error) entry.error = String(message.error).slice(0, 400);
|
|
144
|
+
// Only a plan turn is marked (lib/maritaca/modes.js); a message without `mode` is a chat message.
|
|
145
|
+
if (message.mode === 'plan') entry.mode = 'plan';
|
|
146
|
+
session.messages.push(entry);
|
|
147
|
+
while (session.messages.length > limits.maxMessages) {
|
|
148
|
+
const removed = session.messages.shift();
|
|
149
|
+
session.priorCostBrl = (Number(session.priorCostBrl) || 0) + (Number(removed.costBrl) || 0);
|
|
150
|
+
}
|
|
151
|
+
if (!session.title && role === 'user') session.title = titleFromPrompt(message.displayText || content, limits.maxTitleChars);
|
|
152
|
+
session.updatedAt = entry.at;
|
|
153
|
+
write(session);
|
|
154
|
+
return entry;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function remove(id) {
|
|
158
|
+
const path = pathOf(id);
|
|
159
|
+
try { statSync(path); } catch { return false; }
|
|
160
|
+
rmSync(path, { force: true });
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Rewind to a user prompt for regenerate/edit. Preserve the cost of discarded replies. `mode` re-marks the prompt. */
|
|
165
|
+
function rewind(id, messageIndex, text = undefined, { mode } = {}) {
|
|
166
|
+
const session = get(id);
|
|
167
|
+
if (!session) return null;
|
|
168
|
+
const prompt = session.messages[messageIndex];
|
|
169
|
+
if (!Number.isInteger(messageIndex) || prompt?.role !== 'user') throw Object.assign(new Error('Choose a user message to retry.'), { code: 'PROMPT_UNKNOWN', status: 400 });
|
|
170
|
+
const next = text === undefined ? prompt.content : [text, prompt.attachmentText].filter(Boolean).join('\n\n');
|
|
171
|
+
if (next.length > limits.maxMessageChars) throw Object.assign(new Error('The message including files is too long.'), { code: 'PROMPT_TOO_LONG', status: 400 });
|
|
172
|
+
const removed = session.messages.slice(messageIndex + 1);
|
|
173
|
+
session.priorCostBrl = (Number(session.priorCostBrl) || 0) + removed.reduce((sum, m) => sum + (Number(m.costBrl) || 0), 0);
|
|
174
|
+
session.messages = session.messages.slice(0, messageIndex + 1);
|
|
175
|
+
if (text !== undefined) { prompt.displayText = text; prompt.content = next; }
|
|
176
|
+
if (mode === 'plan') prompt.mode = 'plan';
|
|
177
|
+
else if (mode !== undefined) delete prompt.mode;
|
|
178
|
+
session.updatedAt = now();
|
|
179
|
+
return write(session);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** Every conversation's summary, newest first; `project` narrows to one project. */
|
|
183
|
+
function list({ project = null, limit = 200 } = {}) {
|
|
184
|
+
let names = [];
|
|
185
|
+
try { names = readdirSync(dir).filter((name) => /^[a-f0-9]{32}\.json$/.test(name)); } catch { return []; }
|
|
186
|
+
const rows = [];
|
|
187
|
+
for (const name of names) {
|
|
188
|
+
const session = get(name.slice(0, 32));
|
|
189
|
+
if (!session) continue;
|
|
190
|
+
if (project && session.project !== project) continue;
|
|
191
|
+
rows.push(sessionSummary(session));
|
|
192
|
+
}
|
|
193
|
+
rows.sort((a, b) => String(b.updatedAt).localeCompare(String(a.updatedAt)));
|
|
194
|
+
return rows.slice(0, Math.max(1, Math.min(1000, Number(limit) || 200)));
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return { dir, create, get, update, append, rewind, remove, list };
|
|
198
|
+
}
|
|
@@ -14,22 +14,24 @@ export const EXTERNAL_SERVER_LIMITATIONS = Object.freeze({ codex: 'Plugin-provid
|
|
|
14
14
|
/** Where Antigravity keeps its MCP servers: { mcpServers: { name: { command, args, env, disabled } | { serverUrl, headers, disabled } } }. */
|
|
15
15
|
export function antigravityMcpConfigPath(home = homedir()) { return join(home, '.gemini', 'config', 'mcp_config.json'); }
|
|
16
16
|
export const externalServerName = name => typeof name === 'string' && /^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$/.test(name) && external(name);
|
|
17
|
+
// `reason` and `errno` say what went wrong without the path or a byte of the file; they reach the page.
|
|
18
|
+
const discoveryFailure = (message, reason, errno = null) => Object.assign(new Error(message), { code: 'MCP_DISCOVERY_FAILED', reason, ...(errno ? { errno } : {}) });
|
|
17
19
|
function read(path, fallback = null) {
|
|
18
20
|
try { return readFileSync(path, 'utf8'); }
|
|
19
|
-
catch (error) { if (error.code === 'ENOENT') return fallback; throw
|
|
21
|
+
catch (error) { if (error.code === 'ENOENT') return fallback; throw discoveryFailure('Could not read an MCP configuration source', 'unreadable', typeof error.code === 'string' && /^E[A-Z]+$/.test(error.code) ? error.code : null); }
|
|
20
22
|
}
|
|
21
23
|
function document(path) {
|
|
22
24
|
const text = read(path);
|
|
23
25
|
if (text === null) return {};
|
|
24
26
|
try { return object(parseJsonc(text)); }
|
|
25
|
-
catch { throw
|
|
27
|
+
catch { throw discoveryFailure('Could not parse an MCP configuration source', 'unparseable'); }
|
|
26
28
|
}
|
|
27
29
|
/** Names/kinds/enabled only: Codex keeps definitions and secrets in its own TOML. Quoted dotted names stay whole. */
|
|
28
30
|
export function parseCodexMcpServers(text = '') {
|
|
29
31
|
// Structural TOML reader: supports tables, dotted/quoted keys and inline maps without copying definitions.
|
|
30
32
|
const tokens = []; let at = 0;
|
|
31
33
|
const input = String(text);
|
|
32
|
-
const fail = () =>
|
|
34
|
+
const fail = () => discoveryFailure('Could not parse Codex MCP configuration', 'unparseable');
|
|
33
35
|
while (at < input.length) {
|
|
34
36
|
const ch = input[at];
|
|
35
37
|
if (ch === '#') { while (at < input.length && input[at] !== '\n') at++; continue; }
|
|
@@ -168,7 +170,7 @@ export function externalServerInventory({ provider, cwd = process.cwd(), codexHo
|
|
|
168
170
|
let base = opencodeConfig;
|
|
169
171
|
if (base == null) {
|
|
170
172
|
const docs = readOpencodeConfigDocuments(configDir);
|
|
171
|
-
if (docs.some(row => row.error)) throw
|
|
173
|
+
if (docs.some(row => row.error)) throw discoveryFailure('Could not parse an MCP configuration source', 'unparseable');
|
|
172
174
|
base = mergedOpencodeConfig(docs);
|
|
173
175
|
}
|
|
174
176
|
for (const [name, entry] of Object.entries(mcpServersOf(base))) add(name, entry, 'user');
|
|
@@ -254,13 +256,38 @@ export function selectExternalServers(tools, inventory) {
|
|
|
254
256
|
if (problems.length) throw Object.assign(new Error(problems.map(problem => problem.hint).join(' ')), { code: 'TOOLS_INVALID', status: 400, problems });
|
|
255
257
|
return { names: [...selected].sort(), disabled: inventory.servers.filter(row => !selected.has(row.name)).map(row => row.name) };
|
|
256
258
|
}
|
|
257
|
-
export
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
259
|
+
export const EXTERNAL_CATALOG_PROVIDERS = Object.freeze(['codex', 'opencode', 'claude-code', 'antigravity']);
|
|
260
|
+
/** The public form of a provider whose configuration could not be read: no path, no file content. */
|
|
261
|
+
export function externalDiscoveryError(provider, error) {
|
|
262
|
+
return { provider, code: 'MCP_DISCOVERY_FAILED', reason: error?.reason === 'unparseable' ? 'unparseable' : 'unreadable', ...(error?.errno ? { errno: error.errno } : {}) };
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Names-only catalog over every provider, with the providers that could not be read beside it.
|
|
266
|
+
* A provider in `errors` is `unknown` on every row, never `absent` or `deliverable`: nothing may read it
|
|
267
|
+
* as "no servers there". `strict` rethrows the first discovery failure (what every validation and grant
|
|
268
|
+
* path needs); any other error always propagates.
|
|
269
|
+
*/
|
|
270
|
+
export function externalCatalogReport(options = {}, { strict = false } = {}) {
|
|
271
|
+
const rows = new Map(), errors = [];
|
|
272
|
+
for (const provider of EXTERNAL_CATALOG_PROVIDERS) {
|
|
273
|
+
let servers;
|
|
274
|
+
try { servers = discoverExternalServers({ ...options, provider }); }
|
|
275
|
+
catch (error) { if (strict || error?.code !== 'MCP_DISCOVERY_FAILED') throw error; errors.push(externalDiscoveryError(provider, error)); continue; }
|
|
276
|
+
for (const row of servers) {
|
|
277
|
+
if (!rows.has(row.name)) rows.set(row.name, { ref: `mcp:${row.name}`, label: row.name, selectable: row.selectable, providers: { codex: 'absent', opencode: 'absent', 'claude-code': 'absent', antigravity: 'absent' }, blocked: row.blocked });
|
|
278
|
+
rows.get(row.name).providers[provider] = row.blocked ? 'blocked' : row.deliverable ? 'deliverable' : 'unavailable';
|
|
279
|
+
}
|
|
262
280
|
}
|
|
263
|
-
|
|
281
|
+
for (const { provider } of errors) for (const row of rows.values()) row.providers[provider] = 'unknown';
|
|
282
|
+
return { servers: [...rows.values()].sort((a, b) => a.ref.localeCompare(b.ref)), errors };
|
|
283
|
+
}
|
|
284
|
+
/** Strict: one unreadable provider fails the whole catalog (validation and worker paths). */
|
|
285
|
+
export function externalCatalog(options = {}) { return externalCatalogReport(options, { strict: true }).servers; }
|
|
286
|
+
/** One row's availability for a provider when the catalogs of several folders are merged. */
|
|
287
|
+
export function mergeExternalAvailability(previous, next) {
|
|
288
|
+
if (next === 'deliverable' || previous === 'absent') return next;
|
|
289
|
+
if (previous === 'unknown' && next !== 'absent') return next;
|
|
290
|
+
return previous;
|
|
264
291
|
}
|
|
265
292
|
/** Complete validated disabled entries, proved on 2.1.4. No owner env/header/URL payload in the disabled copy. */
|
|
266
293
|
export function scopeOpenCodeServers(config, tools, inventory, { node = process.execPath } = {}) {
|