@thevinci/web 1.0.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/README.md +197 -0
- package/bin/cli-entry.js +55 -0
- package/bin/cli-output.js +145 -0
- package/bin/cli.js +4887 -0
- package/bin/cli.test.js +64 -0
- package/dist/apple-touch-icon-120x120.png +0 -0
- package/dist/apple-touch-icon-152x152.png +0 -0
- package/dist/apple-touch-icon-167x167.png +0 -0
- package/dist/apple-touch-icon-180x180.png +0 -0
- package/dist/apple-touch-icon.png +0 -0
- package/dist/apple-touch-icon.svg +528 -0
- package/dist/assets/JsonTreeView-CSm9OzXG.js +1 -0
- package/dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- package/dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
- package/dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
- package/dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
- package/dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
- package/dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- package/dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
- package/dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- package/dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
- package/dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
- package/dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
- package/dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- package/dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
- package/dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- package/dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
- package/dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- package/dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
- package/dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
- package/dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- package/dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
- package/dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
- package/dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
- package/dist/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
- package/dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- package/dist/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- package/dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
- package/dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
- package/dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
- package/dist/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- package/dist/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
- package/dist/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
- package/dist/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
- package/dist/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- package/dist/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
- package/dist/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
- package/dist/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
- package/dist/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
- package/dist/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
- package/dist/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
- package/dist/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
- package/dist/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
- package/dist/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
- package/dist/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
- package/dist/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
- package/dist/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
- package/dist/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
- package/dist/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
- package/dist/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
- package/dist/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
- package/dist/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
- package/dist/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
- package/dist/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
- package/dist/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
- package/dist/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
- package/dist/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
- package/dist/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
- package/dist/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
- package/dist/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
- package/dist/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
- package/dist/assets/MarkdownRendererImpl-DensKOLc.js +6 -0
- package/dist/assets/MultiRunWindow-Bo7THayo.js +1 -0
- package/dist/assets/OnboardingScreen-BDqmzTVR.js +2 -0
- package/dist/assets/SettingsWindow-coz__Ykw.js +1 -0
- package/dist/assets/TerminalView-DrZ-i3Dr.js +1 -0
- package/dist/assets/ToolOutputDialog-Eglzslt3.js +16 -0
- package/dist/assets/es-4o9ciP61.js +15 -0
- package/dist/assets/ibm-plex-mono-latin-400-normal-CvHOgSBP.woff +0 -0
- package/dist/assets/ibm-plex-mono-latin-400-normal-DMJ8VG8y.woff2 +0 -0
- package/dist/assets/ibm-plex-mono-latin-500-normal-CB9ihrfo.woff +0 -0
- package/dist/assets/ibm-plex-mono-latin-500-normal-DSY6xOcd.woff2 +0 -0
- package/dist/assets/ibm-plex-mono-latin-600-normal-BgSNZQsw.woff2 +0 -0
- package/dist/assets/ibm-plex-mono-latin-600-normal-DWFSQ4vo.woff +0 -0
- package/dist/assets/ibm-plex-sans-latin-400-normal-CDDApCn2.woff2 +0 -0
- package/dist/assets/ibm-plex-sans-latin-400-normal-CYLoc0-x.woff +0 -0
- package/dist/assets/ibm-plex-sans-latin-500-normal-6ng42L7E.woff2 +0 -0
- package/dist/assets/ibm-plex-sans-latin-500-normal-BgVn5rGT.woff +0 -0
- package/dist/assets/ibm-plex-sans-latin-600-normal-Cu4Hd6ag.woff +0 -0
- package/dist/assets/ibm-plex-sans-latin-600-normal-CuJfVYMP.woff2 +0 -0
- package/dist/assets/index-DLTDToSP.css +1 -0
- package/dist/assets/index-DgiFEKGN.js +1 -0
- package/dist/assets/ko-B20imCHE.js +15 -0
- package/dist/assets/main-BV3KOtdA.css +1 -0
- package/dist/assets/main-CDKJj0sH.js +226 -0
- package/dist/assets/main-LC-PSNVM.js +2 -0
- package/dist/assets/miniChat-CQUiG_cr.js +2 -0
- package/dist/assets/modelPrefsAutoSave-Dm799vzR.js +6986 -0
- package/dist/assets/pl-DQJ7LSzj.js +15 -0
- package/dist/assets/pt-BR-OmjHUz9y.js +15 -0
- package/dist/assets/renderElectronMiniChatApp-CARbeW0G.js +2 -0
- package/dist/assets/uk-BNFxOlO4.js +15 -0
- package/dist/assets/vendor--DBfsbEis.css +1 -0
- package/dist/assets/vendor-.bun-B9l0ZNi2.js +4094 -0
- package/dist/assets/wasm-CG6Dc4jp.js +1 -0
- package/dist/assets/wasmSttWorker-Dtlxac_K.js +1 -0
- package/dist/assets/wasmSttWorker-oo7Dm_jy.js +1806 -0
- package/dist/assets/worker-CbT6TVo7.js +155 -0
- package/dist/assets/zh-CN-C6T-Ac7F.js +15 -0
- package/dist/favicon-16.png +0 -0
- package/dist/favicon-32.png +0 -0
- package/dist/favicon.png +0 -0
- package/dist/favicon.svg +528 -0
- package/dist/index.html +607 -0
- package/dist/logo-dark-192x192.png +0 -0
- package/dist/logo-dark-512x512.png +0 -0
- package/dist/logo-dark-512x512.svg +528 -0
- package/dist/logo-light-192x192.png +0 -0
- package/dist/logo-light-512x512.png +0 -0
- package/dist/logo-light-512x512.svg +528 -0
- package/dist/mini-chat.html +16 -0
- package/dist/pwa-192.png +0 -0
- package/dist/pwa-512.png +0 -0
- package/dist/pwa-maskable-192.png +0 -0
- package/dist/pwa-maskable-512.png +0 -0
- package/dist/site.webmanifest +21 -0
- package/dist/sw.js +1 -0
- package/package.json +118 -0
- package/public/apple-touch-icon-120x120.png +0 -0
- package/public/apple-touch-icon-152x152.png +0 -0
- package/public/apple-touch-icon-167x167.png +0 -0
- package/public/apple-touch-icon-180x180.png +0 -0
- package/public/apple-touch-icon.png +0 -0
- package/public/apple-touch-icon.svg +528 -0
- package/public/favicon-16.png +0 -0
- package/public/favicon-32.png +0 -0
- package/public/favicon.png +0 -0
- package/public/favicon.svg +528 -0
- package/public/logo-dark-192x192.png +0 -0
- package/public/logo-dark-512x512.png +0 -0
- package/public/logo-dark-512x512.svg +528 -0
- package/public/logo-light-192x192.png +0 -0
- package/public/logo-light-512x512.png +0 -0
- package/public/logo-light-512x512.svg +528 -0
- package/public/pwa-192.png +0 -0
- package/public/pwa-512.png +0 -0
- package/public/pwa-maskable-192.png +0 -0
- package/public/pwa-maskable-512.png +0 -0
- package/public/site.webmanifest +21 -0
- package/server/TERMINAL_WS_PROTOCOL.md +48 -0
- package/server/index.d.ts +39 -0
- package/server/index.js +1311 -0
- package/server/lib/cloudflare-tunnel.js +650 -0
- package/server/lib/event-stream/DOCUMENTATION.md +61 -0
- package/server/lib/event-stream/directory-ws-bridge.js +185 -0
- package/server/lib/event-stream/global-hub.js +158 -0
- package/server/lib/event-stream/global-hub.test.js +140 -0
- package/server/lib/event-stream/global-ws-bridge.js +206 -0
- package/server/lib/event-stream/index.js +25 -0
- package/server/lib/event-stream/protocol.js +131 -0
- package/server/lib/event-stream/protocol.test.js +182 -0
- package/server/lib/event-stream/runtime.js +180 -0
- package/server/lib/event-stream/runtime.test.js +512 -0
- package/server/lib/event-stream/upstream-reader.js +226 -0
- package/server/lib/event-stream/upstream-reader.test.js +276 -0
- package/server/lib/fs/DOCUMENTATION.md +36 -0
- package/server/lib/fs/routes.js +1040 -0
- package/server/lib/fs/search.js +238 -0
- package/server/lib/git/DOCUMENTATION.md +152 -0
- package/server/lib/git/credentials.js +74 -0
- package/server/lib/git/identity-storage.js +112 -0
- package/server/lib/git/index.js +6 -0
- package/server/lib/git/routes.js +972 -0
- package/server/lib/git/service.js +3432 -0
- package/server/lib/git/service.test.js +39 -0
- package/server/lib/github/DOCUMENTATION.md +171 -0
- package/server/lib/github/auth.js +307 -0
- package/server/lib/github/device-flow.js +50 -0
- package/server/lib/github/index.js +24 -0
- package/server/lib/github/octokit.js +10 -0
- package/server/lib/github/pr-status.js +519 -0
- package/server/lib/github/repo/fork-detection.js +102 -0
- package/server/lib/github/repo/index.js +55 -0
- package/server/lib/github/routes.js +1560 -0
- package/server/lib/magic-prompts/routes.js +63 -0
- package/server/lib/magic-prompts/runtime.js +119 -0
- package/server/lib/notifications/DOCUMENTATION.md +122 -0
- package/server/lib/notifications/emitter-runtime.js +102 -0
- package/server/lib/notifications/index.js +4 -0
- package/server/lib/notifications/message.js +52 -0
- package/server/lib/notifications/message.test.js +34 -0
- package/server/lib/notifications/push-runtime.js +304 -0
- package/server/lib/notifications/routes.js +315 -0
- package/server/lib/notifications/runtime.js +566 -0
- package/server/lib/notifications/template-runtime.js +349 -0
- package/server/lib/notifications/template-runtime.test.js +26 -0
- package/server/lib/opencode/DOCUMENTATION.md +362 -0
- package/server/lib/opencode/agents.js +634 -0
- package/server/lib/opencode/auth-state-runtime.js +88 -0
- package/server/lib/opencode/auth.js +83 -0
- package/server/lib/opencode/bootstrap-runtime.js +131 -0
- package/server/lib/opencode/cli-entry-runtime.js +43 -0
- package/server/lib/opencode/cli-options.js +128 -0
- package/server/lib/opencode/commands.js +339 -0
- package/server/lib/opencode/config-entity-routes.js +370 -0
- package/server/lib/opencode/core-routes.js +500 -0
- package/server/lib/opencode/core-routes.test.js +26 -0
- package/server/lib/opencode/env-config.js +74 -0
- package/server/lib/opencode/env-keys.js +68 -0
- package/server/lib/opencode/env-runtime.js +1162 -0
- package/server/lib/opencode/env-runtime.test.js +116 -0
- package/server/lib/opencode/feature-routes-runtime.js +244 -0
- package/server/lib/opencode/hmr-state-runtime.js +85 -0
- package/server/lib/opencode/index.js +66 -0
- package/server/lib/opencode/lifecycle.js +1019 -0
- package/server/lib/opencode/lifecycle.test.js +240 -0
- package/server/lib/opencode/mcp.js +278 -0
- package/server/lib/opencode/network-runtime.js +104 -0
- package/server/lib/opencode/network-runtime.test.js +37 -0
- package/server/lib/opencode/opencode-resolution-runtime.js +71 -0
- package/server/lib/opencode/path-utils.js +100 -0
- package/server/lib/opencode/path-utils.test.js +71 -0
- package/server/lib/opencode/project-directory-runtime.js +124 -0
- package/server/lib/opencode/project-icon-routes.js +399 -0
- package/server/lib/opencode/project-icon-routes.test.js +107 -0
- package/server/lib/opencode/providers.js +96 -0
- package/server/lib/opencode/proxy.js +445 -0
- package/server/lib/opencode/pwa-manifest-routes.js +257 -0
- package/server/lib/opencode/pwa-manifest-routes.test.js +133 -0
- package/server/lib/opencode/routes.js +541 -0
- package/server/lib/opencode/server-startup-runtime.js +156 -0
- package/server/lib/opencode/server-utils-runtime.js +168 -0
- package/server/lib/opencode/server-utils-runtime.test.js +135 -0
- package/server/lib/opencode/session-runtime.js +356 -0
- package/server/lib/opencode/session-runtime.test.js +151 -0
- package/server/lib/opencode/settings-helpers.js +770 -0
- package/server/lib/opencode/settings-helpers.test.js +109 -0
- package/server/lib/opencode/settings-normalization-runtime.js +428 -0
- package/server/lib/opencode/settings-runtime.js +826 -0
- package/server/lib/opencode/settings-runtime.test.js +85 -0
- package/server/lib/opencode/shared.js +615 -0
- package/server/lib/opencode/shutdown-runtime.js +139 -0
- package/server/lib/opencode/shutdown-runtime.test.js +58 -0
- package/server/lib/opencode/skill-routes.js +701 -0
- package/server/lib/opencode/skills.js +548 -0
- package/server/lib/opencode/startup-pipeline-runtime.js +130 -0
- package/server/lib/opencode/static-routes-runtime.js +65 -0
- package/server/lib/opencode/theme-runtime.js +167 -0
- package/server/lib/opencode/tunnel-auth.js +591 -0
- package/server/lib/opencode/tunnel-wiring-runtime.js +94 -0
- package/server/lib/opencode/vinci-routes.js +76 -0
- package/server/lib/opencode/watcher.js +115 -0
- package/server/lib/opencode/watcher.test.js +239 -0
- package/server/lib/preview/proxy-runtime.js +1333 -0
- package/server/lib/preview/proxy-runtime.test.js +144 -0
- package/server/lib/projects/project-config.js +567 -0
- package/server/lib/projects/project-config.test.js +175 -0
- package/server/lib/projects/project-id.js +13 -0
- package/server/lib/quota/DOCUMENTATION.md +58 -0
- package/server/lib/quota/index.js +25 -0
- package/server/lib/quota/providers/claude.js +107 -0
- package/server/lib/quota/providers/codex.js +113 -0
- package/server/lib/quota/providers/copilot.js +165 -0
- package/server/lib/quota/providers/google/api.js +92 -0
- package/server/lib/quota/providers/google/auth.js +108 -0
- package/server/lib/quota/providers/google/index.js +124 -0
- package/server/lib/quota/providers/google/transforms.js +109 -0
- package/server/lib/quota/providers/index.js +168 -0
- package/server/lib/quota/providers/interface.js +55 -0
- package/server/lib/quota/providers/kimi.js +108 -0
- package/server/lib/quota/providers/minimax-cn-coding-plan.js +140 -0
- package/server/lib/quota/providers/minimax-coding-plan.js +139 -0
- package/server/lib/quota/providers/nanogpt.js +124 -0
- package/server/lib/quota/providers/ollama-cloud.js +112 -0
- package/server/lib/quota/providers/openai.js +91 -0
- package/server/lib/quota/providers/openrouter.js +92 -0
- package/server/lib/quota/providers/zai.js +91 -0
- package/server/lib/quota/providers/zhipuai-coding-plan.js +133 -0
- package/server/lib/quota/providers/zhipuai.js +114 -0
- package/server/lib/quota/routes.js +27 -0
- package/server/lib/quota/utils/auth.js +50 -0
- package/server/lib/quota/utils/formatters.js +85 -0
- package/server/lib/quota/utils/formatters.test.js +54 -0
- package/server/lib/quota/utils/index.js +10 -0
- package/server/lib/quota/utils/transformers.js +55 -0
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +44 -0
- package/server/lib/scheduled-tasks/routes.js +235 -0
- package/server/lib/scheduled-tasks/runtime.js +773 -0
- package/server/lib/scheduled-tasks/runtime.test.js +100 -0
- package/server/lib/security/request-security.js +115 -0
- package/server/lib/session-folders/routes.js +63 -0
- package/server/lib/session-folders/routes.test.js +102 -0
- package/server/lib/skills-catalog/DOCUMENTATION.md +178 -0
- package/server/lib/skills-catalog/cache.js +29 -0
- package/server/lib/skills-catalog/clawdhub/api.js +158 -0
- package/server/lib/skills-catalog/clawdhub/index.js +30 -0
- package/server/lib/skills-catalog/clawdhub/install.js +238 -0
- package/server/lib/skills-catalog/clawdhub/scan.js +113 -0
- package/server/lib/skills-catalog/curated-sources.js +21 -0
- package/server/lib/skills-catalog/git.js +77 -0
- package/server/lib/skills-catalog/index.js +42 -0
- package/server/lib/skills-catalog/install.js +294 -0
- package/server/lib/skills-catalog/scan.js +221 -0
- package/server/lib/skills-catalog/source.js +87 -0
- package/server/lib/terminal/DOCUMENTATION.md +76 -0
- package/server/lib/terminal/index.js +31 -0
- package/server/lib/terminal/output-replay-buffer.js +78 -0
- package/server/lib/terminal/output-replay-buffer.test.js +75 -0
- package/server/lib/terminal/runtime.js +850 -0
- package/server/lib/terminal/runtime.test.js +96 -0
- package/server/lib/terminal/terminal-ws-protocol.js +68 -0
- package/server/lib/terminal/terminal-ws-protocol.test.js +145 -0
- package/server/lib/text/DOCUMENTATION.md +35 -0
- package/server/lib/text/summarization.js +138 -0
- package/server/lib/text/summarization.test.js +34 -0
- package/server/lib/tts/DOCUMENTATION.md +146 -0
- package/server/lib/tts/base-url.js +62 -0
- package/server/lib/tts/capability-runtime.js +31 -0
- package/server/lib/tts/index.js +19 -0
- package/server/lib/tts/routes.js +261 -0
- package/server/lib/tts/routes.test.js +53 -0
- package/server/lib/tts/service.js +178 -0
- package/server/lib/tts/stt.js +75 -0
- package/server/lib/tunnels/DOCUMENTATION.md +18 -0
- package/server/lib/tunnels/index.js +166 -0
- package/server/lib/tunnels/managed-config.js +201 -0
- package/server/lib/tunnels/providers/cloudflare.js +260 -0
- package/server/lib/tunnels/registry.js +51 -0
- package/server/lib/tunnels/routes.js +605 -0
- package/server/lib/tunnels/types.js +219 -0
- package/server/lib/ui-auth/DOCUMENTATION.md +38 -0
- package/server/lib/ui-auth/ui-auth.js +673 -0
- package/server/lib/ui-auth/ui-passkeys.js +545 -0
- package/server/opencode-proxy.test.js +151 -0
- package/server/proxy-headers.js +61 -0
- package/server/proxy-headers.test.js +58 -0
- package/server/sse-routes.test.js +152 -0
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
const SESSION_COOLDOWN_DURATION_MS = 2000;
|
|
2
|
+
const SESSION_STATE_MAX_AGE_MS = 24 * 60 * 60 * 1000;
|
|
3
|
+
const SESSION_ATTENTION_MAX_AGE_MS = 24 * 60 * 60 * 1000;
|
|
4
|
+
const SESSION_STATE_CLEANUP_INTERVAL_MS = 60 * 60 * 1000;
|
|
5
|
+
|
|
6
|
+
const extractSessionStatusUpdate = (payload) => {
|
|
7
|
+
if (!payload || payload.type !== 'session.status') {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const properties = payload.properties && typeof payload.properties === 'object' ? payload.properties : {};
|
|
12
|
+
const status = properties.status && typeof properties.status === 'object' ? properties.status : {};
|
|
13
|
+
const info = properties.info && typeof properties.info === 'object' ? properties.info : {};
|
|
14
|
+
const sessionId = typeof properties.sessionID === 'string' ? properties.sessionID.trim() : '';
|
|
15
|
+
// Canonical OpenCode schema uses properties.status.type. Keep legacy info.type fallback for compatibility.
|
|
16
|
+
const type = typeof status.type === 'string'
|
|
17
|
+
? status.type.trim()
|
|
18
|
+
: (typeof info.type === 'string' ? info.type.trim() : '');
|
|
19
|
+
|
|
20
|
+
if (!sessionId || !type) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
sessionId,
|
|
26
|
+
type,
|
|
27
|
+
eventId: typeof payload.id === 'string' ? payload.id : '',
|
|
28
|
+
attempt: typeof status.attempt === 'number'
|
|
29
|
+
? status.attempt
|
|
30
|
+
: (typeof info.attempt === 'number' ? info.attempt : undefined),
|
|
31
|
+
message: typeof status.message === 'string'
|
|
32
|
+
? status.message
|
|
33
|
+
: (typeof info.message === 'string' ? info.message : undefined),
|
|
34
|
+
next: typeof status.next === 'number'
|
|
35
|
+
? status.next
|
|
36
|
+
: (typeof info.next === 'number' ? info.next : undefined),
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const deriveSessionActivityTransitions = (payload) => {
|
|
41
|
+
const update = extractSessionStatusUpdate(payload);
|
|
42
|
+
if (!update) {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (update.type === 'busy' || update.type === 'retry') {
|
|
47
|
+
return [{ sessionId: update.sessionId, phase: 'busy' }];
|
|
48
|
+
}
|
|
49
|
+
if (update.type === 'idle') {
|
|
50
|
+
return [{ sessionId: update.sessionId, phase: 'cooldown' }];
|
|
51
|
+
}
|
|
52
|
+
return [];
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const createSessionRuntime = ({ writeSseEvent, getNotificationClients, broadcastEvent }) => {
|
|
56
|
+
const sessionActivityPhases = new Map();
|
|
57
|
+
const sessionActivityCooldowns = new Map();
|
|
58
|
+
const sessionStates = new Map();
|
|
59
|
+
const sessionAttentionStates = new Map();
|
|
60
|
+
|
|
61
|
+
const getOrCreateAttentionState = (sessionId) => {
|
|
62
|
+
if (!sessionId || typeof sessionId !== 'string') return null;
|
|
63
|
+
|
|
64
|
+
let state = sessionAttentionStates.get(sessionId);
|
|
65
|
+
if (!state) {
|
|
66
|
+
state = {
|
|
67
|
+
needsAttention: false,
|
|
68
|
+
lastUserMessageAt: null,
|
|
69
|
+
lastStatusChangeAt: Date.now(),
|
|
70
|
+
viewedByClients: new Set(),
|
|
71
|
+
status: 'idle',
|
|
72
|
+
};
|
|
73
|
+
sessionAttentionStates.set(sessionId, state);
|
|
74
|
+
}
|
|
75
|
+
return state;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const setSessionActivityPhase = (sessionId, phase) => {
|
|
79
|
+
if (!sessionId || typeof sessionId !== 'string') return false;
|
|
80
|
+
|
|
81
|
+
const current = sessionActivityPhases.get(sessionId);
|
|
82
|
+
if (current?.phase === phase) return false;
|
|
83
|
+
if (phase === 'cooldown' && current?.phase !== 'busy') {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const existingTimer = sessionActivityCooldowns.get(sessionId);
|
|
88
|
+
if (existingTimer) {
|
|
89
|
+
clearTimeout(existingTimer);
|
|
90
|
+
sessionActivityCooldowns.delete(sessionId);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
sessionActivityPhases.set(sessionId, { phase, updatedAt: Date.now() });
|
|
94
|
+
|
|
95
|
+
if (phase === 'cooldown') {
|
|
96
|
+
const timer = setTimeout(() => {
|
|
97
|
+
const now = sessionActivityPhases.get(sessionId);
|
|
98
|
+
if (now?.phase === 'cooldown') {
|
|
99
|
+
setSessionActivityPhase(sessionId, 'idle');
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
sessionActivityCooldowns.delete(sessionId);
|
|
103
|
+
}, SESSION_COOLDOWN_DURATION_MS);
|
|
104
|
+
sessionActivityCooldowns.set(sessionId, timer);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (typeof broadcastEvent === 'function') {
|
|
108
|
+
broadcastEvent({
|
|
109
|
+
type: 'vinci:session-activity',
|
|
110
|
+
properties: {
|
|
111
|
+
sessionId,
|
|
112
|
+
phase,
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return true;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const updateSessionAttentionStatus = (sessionId, status) => {
|
|
121
|
+
const state = getOrCreateAttentionState(sessionId);
|
|
122
|
+
if (!state) return;
|
|
123
|
+
|
|
124
|
+
const prevStatus = state.status;
|
|
125
|
+
state.status = status;
|
|
126
|
+
state.lastStatusChangeAt = Date.now();
|
|
127
|
+
|
|
128
|
+
if ((prevStatus === 'busy' || prevStatus === 'retry') && status === 'idle') {
|
|
129
|
+
if (state.lastUserMessageAt && state.viewedByClients.size === 0) {
|
|
130
|
+
state.needsAttention = true;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const updateSessionState = (sessionId, status, eventId, metadata = {}) => {
|
|
136
|
+
if (!sessionId || typeof sessionId !== 'string') return;
|
|
137
|
+
|
|
138
|
+
const now = Date.now();
|
|
139
|
+
const existing = sessionStates.get(sessionId);
|
|
140
|
+
const existingAttentionState = sessionAttentionStates.get(sessionId);
|
|
141
|
+
if (existing && existing.lastUpdateAt > now - 5000 && status === existing.status) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
sessionStates.set(sessionId, {
|
|
146
|
+
status,
|
|
147
|
+
lastUpdateAt: now,
|
|
148
|
+
lastEventId: eventId || `server-${now}`,
|
|
149
|
+
metadata: { ...existing?.metadata, ...metadata },
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
updateSessionAttentionStatus(sessionId, status);
|
|
153
|
+
const attentionState = sessionAttentionStates.get(sessionId);
|
|
154
|
+
const attentionChanged = !!attentionState && existingAttentionState?.needsAttention !== attentionState.needsAttention;
|
|
155
|
+
const clients = getNotificationClients();
|
|
156
|
+
if (!existing || existing.status !== status || attentionChanged) {
|
|
157
|
+
const state = sessionStates.get(sessionId);
|
|
158
|
+
const syntheticPayload = {
|
|
159
|
+
type: 'vinci:session-status',
|
|
160
|
+
properties: {
|
|
161
|
+
sessionId,
|
|
162
|
+
status: state.status,
|
|
163
|
+
timestamp: state.lastUpdateAt,
|
|
164
|
+
metadata: state.metadata,
|
|
165
|
+
needsAttention: attentionState?.needsAttention ?? false,
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
if (typeof broadcastEvent === 'function') {
|
|
170
|
+
broadcastEvent(syntheticPayload);
|
|
171
|
+
} else if (clients.size > 0) {
|
|
172
|
+
for (const res of clients) {
|
|
173
|
+
try {
|
|
174
|
+
writeSseEvent(res, syntheticPayload);
|
|
175
|
+
} catch {
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const phase = status === 'busy' || status === 'retry' ? 'busy' : 'idle';
|
|
182
|
+
if (phase !== 'idle' || sessionActivityPhases.get(sessionId)?.phase !== 'cooldown') {
|
|
183
|
+
setSessionActivityPhase(sessionId, phase);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
const getSessionStateSnapshot = () => {
|
|
188
|
+
const result = {};
|
|
189
|
+
const now = Date.now();
|
|
190
|
+
for (const [sessionId, data] of sessionStates) {
|
|
191
|
+
if (now - data.lastUpdateAt > SESSION_STATE_MAX_AGE_MS) continue;
|
|
192
|
+
result[sessionId] = {
|
|
193
|
+
status: data.status,
|
|
194
|
+
lastUpdateAt: data.lastUpdateAt,
|
|
195
|
+
metadata: data.metadata,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
return result;
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
const getSessionState = (sessionId) => {
|
|
202
|
+
if (!sessionId) return null;
|
|
203
|
+
return sessionStates.get(sessionId) || null;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
const markSessionViewed = (sessionId, clientId) => {
|
|
207
|
+
const state = getOrCreateAttentionState(sessionId);
|
|
208
|
+
if (!state) return;
|
|
209
|
+
|
|
210
|
+
const wasNeedsAttention = state.needsAttention;
|
|
211
|
+
state.viewedByClients.add(clientId);
|
|
212
|
+
|
|
213
|
+
if (wasNeedsAttention) {
|
|
214
|
+
state.needsAttention = false;
|
|
215
|
+
|
|
216
|
+
const syntheticPayload = {
|
|
217
|
+
type: 'vinci:session-status',
|
|
218
|
+
properties: {
|
|
219
|
+
sessionId,
|
|
220
|
+
status: state.status,
|
|
221
|
+
timestamp: Date.now(),
|
|
222
|
+
metadata: {},
|
|
223
|
+
needsAttention: false,
|
|
224
|
+
},
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
if (typeof broadcastEvent === 'function') {
|
|
228
|
+
broadcastEvent(syntheticPayload);
|
|
229
|
+
} else {
|
|
230
|
+
const clients = getNotificationClients();
|
|
231
|
+
for (const res of clients) {
|
|
232
|
+
try {
|
|
233
|
+
writeSseEvent(res, syntheticPayload);
|
|
234
|
+
} catch {
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
const markSessionUnviewed = (sessionId, clientId) => {
|
|
242
|
+
const state = sessionAttentionStates.get(sessionId);
|
|
243
|
+
if (!state) return;
|
|
244
|
+
state.viewedByClients.delete(clientId);
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
const markUserMessageSent = (sessionId) => {
|
|
248
|
+
const state = getOrCreateAttentionState(sessionId);
|
|
249
|
+
if (!state) return;
|
|
250
|
+
state.lastUserMessageAt = Date.now();
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
const getSessionAttentionSnapshot = () => {
|
|
254
|
+
const result = {};
|
|
255
|
+
const now = Date.now();
|
|
256
|
+
for (const [sessionId, state] of sessionAttentionStates) {
|
|
257
|
+
if (now - state.lastStatusChangeAt > SESSION_ATTENTION_MAX_AGE_MS) continue;
|
|
258
|
+
result[sessionId] = {
|
|
259
|
+
needsAttention: state.needsAttention,
|
|
260
|
+
lastUserMessageAt: state.lastUserMessageAt,
|
|
261
|
+
lastStatusChangeAt: state.lastStatusChangeAt,
|
|
262
|
+
status: state.status,
|
|
263
|
+
isViewed: state.viewedByClients.size > 0,
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
return result;
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
const getSessionAttentionState = (sessionId) => {
|
|
270
|
+
if (!sessionId) return null;
|
|
271
|
+
const state = sessionAttentionStates.get(sessionId);
|
|
272
|
+
if (!state) return null;
|
|
273
|
+
return {
|
|
274
|
+
needsAttention: state.needsAttention,
|
|
275
|
+
lastUserMessageAt: state.lastUserMessageAt,
|
|
276
|
+
lastStatusChangeAt: state.lastStatusChangeAt,
|
|
277
|
+
status: state.status,
|
|
278
|
+
isViewed: state.viewedByClients.size > 0,
|
|
279
|
+
};
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
const getSessionActivitySnapshot = () => {
|
|
283
|
+
const result = {};
|
|
284
|
+
for (const [sessionId, data] of sessionActivityPhases) {
|
|
285
|
+
result[sessionId] = { type: data.phase };
|
|
286
|
+
}
|
|
287
|
+
return result;
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
const resetAllSessionActivityToIdle = () => {
|
|
291
|
+
for (const timer of sessionActivityCooldowns.values()) {
|
|
292
|
+
clearTimeout(timer);
|
|
293
|
+
}
|
|
294
|
+
sessionActivityCooldowns.clear();
|
|
295
|
+
const now = Date.now();
|
|
296
|
+
for (const [sessionId] of sessionActivityPhases) {
|
|
297
|
+
sessionActivityPhases.set(sessionId, { phase: 'idle', updatedAt: now });
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
const cleanupOldSessionStates = () => {
|
|
302
|
+
const now = Date.now();
|
|
303
|
+
for (const [sessionId, data] of sessionStates) {
|
|
304
|
+
if (now - data.lastUpdateAt > SESSION_STATE_MAX_AGE_MS) {
|
|
305
|
+
sessionStates.delete(sessionId);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
for (const [sessionId, state] of sessionAttentionStates) {
|
|
309
|
+
if (now - state.lastStatusChangeAt > SESSION_ATTENTION_MAX_AGE_MS) {
|
|
310
|
+
sessionAttentionStates.delete(sessionId);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
const cleanupInterval = setInterval(cleanupOldSessionStates, SESSION_STATE_CLEANUP_INTERVAL_MS);
|
|
316
|
+
|
|
317
|
+
const processOpenCodeSsePayload = (payload) => {
|
|
318
|
+
const transitions = deriveSessionActivityTransitions(payload);
|
|
319
|
+
for (const activity of transitions) {
|
|
320
|
+
setSessionActivityPhase(activity.sessionId, activity.phase);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
if (payload && payload.type === 'session.status') {
|
|
324
|
+
const update = extractSessionStatusUpdate(payload);
|
|
325
|
+
if (update) {
|
|
326
|
+
updateSessionState(update.sessionId, update.type, update.eventId || `sse-${Date.now()}`, {
|
|
327
|
+
attempt: update.attempt,
|
|
328
|
+
message: update.message,
|
|
329
|
+
next: update.next,
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
const dispose = () => {
|
|
336
|
+
clearInterval(cleanupInterval);
|
|
337
|
+
for (const timer of sessionActivityCooldowns.values()) {
|
|
338
|
+
clearTimeout(timer);
|
|
339
|
+
}
|
|
340
|
+
sessionActivityCooldowns.clear();
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
return {
|
|
344
|
+
processOpenCodeSsePayload,
|
|
345
|
+
getSessionActivitySnapshot,
|
|
346
|
+
getSessionStateSnapshot,
|
|
347
|
+
getSessionAttentionSnapshot,
|
|
348
|
+
getSessionState,
|
|
349
|
+
getSessionAttentionState,
|
|
350
|
+
markSessionViewed,
|
|
351
|
+
markSessionUnviewed,
|
|
352
|
+
markUserMessageSent,
|
|
353
|
+
resetAllSessionActivityToIdle,
|
|
354
|
+
dispose,
|
|
355
|
+
};
|
|
356
|
+
};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { createSessionRuntime } from './session-runtime.js';
|
|
4
|
+
|
|
5
|
+
describe('session runtime', () => {
|
|
6
|
+
const runtimes = [];
|
|
7
|
+
|
|
8
|
+
afterEach(() => {
|
|
9
|
+
for (const runtime of runtimes) {
|
|
10
|
+
runtime.dispose();
|
|
11
|
+
}
|
|
12
|
+
runtimes.length = 0;
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('broadcasts attention clears through the shared broadcaster', () => {
|
|
16
|
+
const events = [];
|
|
17
|
+
const runtime = createSessionRuntime({
|
|
18
|
+
writeSseEvent() {
|
|
19
|
+
throw new Error('SSE fallback should not be used when broadcastEvent is provided');
|
|
20
|
+
},
|
|
21
|
+
getNotificationClients: () => new Set(),
|
|
22
|
+
broadcastEvent: (payload) => {
|
|
23
|
+
events.push(payload);
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
runtimes.push(runtime);
|
|
27
|
+
|
|
28
|
+
runtime.processOpenCodeSsePayload({
|
|
29
|
+
type: 'session.status',
|
|
30
|
+
properties: {
|
|
31
|
+
sessionID: 'session-1',
|
|
32
|
+
status: {
|
|
33
|
+
type: 'busy',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
runtime.markUserMessageSent('session-1');
|
|
38
|
+
runtime.processOpenCodeSsePayload({
|
|
39
|
+
type: 'session.status',
|
|
40
|
+
properties: {
|
|
41
|
+
sessionID: 'session-1',
|
|
42
|
+
status: {
|
|
43
|
+
type: 'idle',
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
runtime.markSessionViewed('session-1', 'client-1');
|
|
48
|
+
|
|
49
|
+
expect(events).toContainEqual({
|
|
50
|
+
type: 'vinci:session-status',
|
|
51
|
+
properties: expect.objectContaining({
|
|
52
|
+
sessionId: 'session-1',
|
|
53
|
+
status: 'idle',
|
|
54
|
+
needsAttention: true,
|
|
55
|
+
}),
|
|
56
|
+
});
|
|
57
|
+
expect(events.at(-1)).toEqual({
|
|
58
|
+
type: 'vinci:session-status',
|
|
59
|
+
properties: {
|
|
60
|
+
sessionId: 'session-1',
|
|
61
|
+
status: 'idle',
|
|
62
|
+
timestamp: expect.any(Number),
|
|
63
|
+
metadata: {},
|
|
64
|
+
needsAttention: false,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('accepts legacy session.status info.type payloads', () => {
|
|
70
|
+
const events = [];
|
|
71
|
+
const runtime = createSessionRuntime({
|
|
72
|
+
writeSseEvent() {
|
|
73
|
+
throw new Error('SSE fallback should not be used when broadcastEvent is provided');
|
|
74
|
+
},
|
|
75
|
+
getNotificationClients: () => new Set(),
|
|
76
|
+
broadcastEvent: (payload) => {
|
|
77
|
+
events.push(payload);
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
runtimes.push(runtime);
|
|
81
|
+
|
|
82
|
+
runtime.processOpenCodeSsePayload({
|
|
83
|
+
type: 'session.status',
|
|
84
|
+
properties: {
|
|
85
|
+
sessionID: 'legacy-session-1',
|
|
86
|
+
info: {
|
|
87
|
+
type: 'busy',
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
expect(events).toContainEqual({
|
|
93
|
+
type: 'vinci:session-status',
|
|
94
|
+
properties: expect.objectContaining({
|
|
95
|
+
sessionId: 'legacy-session-1',
|
|
96
|
+
status: 'busy',
|
|
97
|
+
}),
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('broadcasts idle activity when cooldown expires', () => {
|
|
102
|
+
vi.useFakeTimers();
|
|
103
|
+
const events = [];
|
|
104
|
+
const runtime = createSessionRuntime({
|
|
105
|
+
writeSseEvent() {
|
|
106
|
+
throw new Error('SSE fallback should not be used when broadcastEvent is provided');
|
|
107
|
+
},
|
|
108
|
+
getNotificationClients: () => new Set(),
|
|
109
|
+
broadcastEvent: (payload) => {
|
|
110
|
+
events.push(payload);
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
try {
|
|
115
|
+
runtime.processOpenCodeSsePayload({
|
|
116
|
+
type: 'session.status',
|
|
117
|
+
properties: {
|
|
118
|
+
sessionID: 'session-activity-1',
|
|
119
|
+
status: {
|
|
120
|
+
type: 'busy',
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
runtime.processOpenCodeSsePayload({
|
|
125
|
+
type: 'session.status',
|
|
126
|
+
properties: {
|
|
127
|
+
sessionID: 'session-activity-1',
|
|
128
|
+
status: {
|
|
129
|
+
type: 'idle',
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
const activityPhases = () => events
|
|
135
|
+
.filter((event) => event.type === 'vinci:session-activity')
|
|
136
|
+
.map((event) => event.properties.phase);
|
|
137
|
+
|
|
138
|
+
expect(activityPhases()).toEqual(['busy', 'cooldown']);
|
|
139
|
+
|
|
140
|
+
vi.advanceTimersByTime(1999);
|
|
141
|
+
expect(activityPhases()).toEqual(['busy', 'cooldown']);
|
|
142
|
+
|
|
143
|
+
vi.advanceTimersByTime(1);
|
|
144
|
+
|
|
145
|
+
expect(activityPhases()).toEqual(['busy', 'cooldown', 'idle']);
|
|
146
|
+
} finally {
|
|
147
|
+
runtime.dispose();
|
|
148
|
+
vi.useRealTimers();
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
});
|