@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,349 @@
|
|
|
1
|
+
import { summarizeText as summarizeSharedText } from '../text/summarization.js';
|
|
2
|
+
|
|
3
|
+
export const createNotificationTemplateRuntime = (deps) => {
|
|
4
|
+
const {
|
|
5
|
+
readSettingsFromDisk,
|
|
6
|
+
buildOpenCodeUrl,
|
|
7
|
+
getOpenCodeAuthHeaders,
|
|
8
|
+
resolveGitBinaryForSpawn,
|
|
9
|
+
} = deps;
|
|
10
|
+
|
|
11
|
+
const NOTIFICATION_BODY_MAX_CHARS = 1000;
|
|
12
|
+
const SESSION_INFO_CACHE_TTL_MS = 60 * 1000;
|
|
13
|
+
|
|
14
|
+
const cachedZenModels = { models: [] };
|
|
15
|
+
|
|
16
|
+
const sessionTitleCache = new Map();
|
|
17
|
+
const sessionInfoCache = new Map();
|
|
18
|
+
|
|
19
|
+
const createTimeoutSignal = (timeoutMs) => {
|
|
20
|
+
const controller = new AbortController();
|
|
21
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
22
|
+
return {
|
|
23
|
+
signal: controller.signal,
|
|
24
|
+
cleanup: () => clearTimeout(timer),
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const formatProjectLabel = (label) => {
|
|
29
|
+
if (!label || typeof label !== 'string') return '';
|
|
30
|
+
return label
|
|
31
|
+
.replace(/[-_]/g, ' ')
|
|
32
|
+
.replace(/\b\w/g, (char) => char.toUpperCase());
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const resolveNotificationTemplate = (template, variables) => {
|
|
36
|
+
if (!template || typeof template !== 'string') return '';
|
|
37
|
+
return template.replace(/\{(\w+)\}/g, (_match, key) => {
|
|
38
|
+
const value = variables[key];
|
|
39
|
+
if (value === undefined || value === null) return '';
|
|
40
|
+
return String(value);
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const shouldApplyResolvedTemplateMessage = (template, resolved, variables) => {
|
|
45
|
+
if (!resolved) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (typeof template !== 'string') {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (template.includes('{last_message}')) {
|
|
54
|
+
return typeof variables?.last_message === 'string' && variables.last_message.trim().length > 0;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return true;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const fetchFreeZenModels = async () => [];
|
|
61
|
+
|
|
62
|
+
const resolveZenModel = async (override) => {
|
|
63
|
+
const overrideModel = typeof override === 'string' ? override.trim() : '';
|
|
64
|
+
if (overrideModel) return overrideModel;
|
|
65
|
+
const settings = await readSettingsFromDisk().catch(() => ({}));
|
|
66
|
+
return typeof settings?.zenModel === 'string' && settings.zenModel.trim().length > 0
|
|
67
|
+
? settings.zenModel.trim()
|
|
68
|
+
: '';
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const validateZenModelAtStartup = async () => {};
|
|
72
|
+
|
|
73
|
+
const summarizeText = async (text, targetLength, zenModel) => {
|
|
74
|
+
if (!text || typeof text !== 'string' || text.trim().length === 0) return text;
|
|
75
|
+
const result = await summarizeSharedText({
|
|
76
|
+
text,
|
|
77
|
+
threshold: 0,
|
|
78
|
+
maxLength: targetLength,
|
|
79
|
+
zenModel,
|
|
80
|
+
mode: 'notification',
|
|
81
|
+
});
|
|
82
|
+
return typeof result?.summary === 'string' && result.summary.trim().length > 0
|
|
83
|
+
? result.summary
|
|
84
|
+
: text;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const extractTextFromParts = (parts, maxLength = NOTIFICATION_BODY_MAX_CHARS) => {
|
|
88
|
+
if (!Array.isArray(parts) || parts.length === 0) return '';
|
|
89
|
+
|
|
90
|
+
const textParts = parts
|
|
91
|
+
.filter((part) => part && (part.type === 'text' || typeof part.text === 'string' || typeof part.content === 'string'))
|
|
92
|
+
.map((part) => part.text || part.content || '')
|
|
93
|
+
.filter(Boolean);
|
|
94
|
+
|
|
95
|
+
let text = textParts.length > 0 ? textParts.join('\n').trim() : '';
|
|
96
|
+
|
|
97
|
+
if (maxLength > 0 && text.length > maxLength) {
|
|
98
|
+
text = text.slice(0, maxLength);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return text;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const extractLastMessageText = (payload, maxLength = NOTIFICATION_BODY_MAX_CHARS) => {
|
|
105
|
+
const info = payload?.properties?.info;
|
|
106
|
+
if (!info) return '';
|
|
107
|
+
|
|
108
|
+
const parts = info.parts || payload?.properties?.parts;
|
|
109
|
+
const text = extractTextFromParts(parts, maxLength);
|
|
110
|
+
if (text) return text;
|
|
111
|
+
|
|
112
|
+
const content = info.content;
|
|
113
|
+
if (Array.isArray(content)) {
|
|
114
|
+
const textContent = content
|
|
115
|
+
.filter((entry) => entry && (entry.type === 'text' || typeof entry.text === 'string'))
|
|
116
|
+
.map((entry) => entry.text || '')
|
|
117
|
+
.filter(Boolean);
|
|
118
|
+
if (textContent.length > 0) {
|
|
119
|
+
let result = textContent.join('\n').trim();
|
|
120
|
+
if (maxLength > 0 && result.length > maxLength) {
|
|
121
|
+
result = result.slice(0, maxLength);
|
|
122
|
+
}
|
|
123
|
+
return result;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return '';
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const fetchLastAssistantMessageText = async (sessionId, messageId, maxLength = NOTIFICATION_BODY_MAX_CHARS) => {
|
|
131
|
+
if (!sessionId) return '';
|
|
132
|
+
|
|
133
|
+
try {
|
|
134
|
+
const url = buildOpenCodeUrl(`/session/${encodeURIComponent(sessionId)}/message`, '');
|
|
135
|
+
const response = await fetch(`${url}?limit=5`, {
|
|
136
|
+
method: 'GET',
|
|
137
|
+
headers: {
|
|
138
|
+
Accept: 'application/json',
|
|
139
|
+
...getOpenCodeAuthHeaders(),
|
|
140
|
+
},
|
|
141
|
+
signal: AbortSignal.timeout(3000),
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
if (!response.ok) return '';
|
|
145
|
+
|
|
146
|
+
const messages = await response.json().catch(() => null);
|
|
147
|
+
if (!Array.isArray(messages)) return '';
|
|
148
|
+
|
|
149
|
+
let target = null;
|
|
150
|
+
if (messageId) {
|
|
151
|
+
target = messages.find((message) => message?.info?.id === messageId && message?.info?.role === 'assistant');
|
|
152
|
+
}
|
|
153
|
+
if (!target) {
|
|
154
|
+
for (let i = messages.length - 1; i >= 0; i -= 1) {
|
|
155
|
+
const message = messages[i];
|
|
156
|
+
if (message?.info?.role === 'assistant' && message?.info?.finish === 'stop') {
|
|
157
|
+
target = message;
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (!target || !Array.isArray(target.parts)) return '';
|
|
164
|
+
|
|
165
|
+
return extractTextFromParts(target.parts, maxLength);
|
|
166
|
+
} catch {
|
|
167
|
+
return '';
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const cacheSessionTitle = (sessionId, title) => {
|
|
172
|
+
if (typeof sessionId === 'string' && sessionId.length > 0 && typeof title === 'string' && title.length > 0) {
|
|
173
|
+
sessionTitleCache.set(sessionId, title);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const getCachedSessionTitle = (sessionId) => {
|
|
178
|
+
return sessionTitleCache.get(sessionId) ?? null;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
const maybeCacheSessionInfoFromEvent = (payload) => {
|
|
182
|
+
if (!payload || typeof payload !== 'object') return;
|
|
183
|
+
const type = payload.type;
|
|
184
|
+
if (type !== 'session.updated' && type !== 'session.created') return;
|
|
185
|
+
const info = payload.properties?.info;
|
|
186
|
+
if (!info || typeof info !== 'object') return;
|
|
187
|
+
cacheSessionTitle(info.id, info.title);
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
const fetchSessionInfo = async (sessionId) => {
|
|
191
|
+
if (!sessionId) return null;
|
|
192
|
+
|
|
193
|
+
const cached = sessionInfoCache.get(sessionId);
|
|
194
|
+
if (cached && Date.now() - cached.at < SESSION_INFO_CACHE_TTL_MS) {
|
|
195
|
+
return cached.data;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
try {
|
|
199
|
+
const url = buildOpenCodeUrl(`/session/${encodeURIComponent(sessionId)}`, '');
|
|
200
|
+
const response = await fetch(url, {
|
|
201
|
+
method: 'GET',
|
|
202
|
+
headers: { Accept: 'application/json' },
|
|
203
|
+
signal: AbortSignal.timeout(2000),
|
|
204
|
+
});
|
|
205
|
+
if (!response.ok) {
|
|
206
|
+
console.warn(`[Notification] fetchSessionInfo: ${response.status} for session ${sessionId}`);
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
const data = await response.json().catch(() => null);
|
|
210
|
+
if (data && typeof data === 'object') {
|
|
211
|
+
sessionInfoCache.set(sessionId, { data, at: Date.now() });
|
|
212
|
+
return data;
|
|
213
|
+
}
|
|
214
|
+
return null;
|
|
215
|
+
} catch (error) {
|
|
216
|
+
console.warn(`[Notification] fetchSessionInfo failed for ${sessionId}:`, error?.message || error);
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
const buildTemplateVariables = async (payload, sessionId) => {
|
|
222
|
+
const info = payload?.properties?.info || {};
|
|
223
|
+
|
|
224
|
+
let sessionTitle = payload?.properties?.sessionTitle || payload?.properties?.session?.title || (typeof info.sessionTitle === 'string' ? info.sessionTitle : '') || '';
|
|
225
|
+
|
|
226
|
+
if (!sessionTitle && sessionId) {
|
|
227
|
+
const cached = getCachedSessionTitle(sessionId);
|
|
228
|
+
if (cached) {
|
|
229
|
+
sessionTitle = cached;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
let sessionInfo = null;
|
|
234
|
+
if (!sessionTitle && sessionId) {
|
|
235
|
+
sessionInfo = await fetchSessionInfo(sessionId);
|
|
236
|
+
if (sessionInfo && typeof sessionInfo.title === 'string') {
|
|
237
|
+
sessionTitle = sessionInfo.title;
|
|
238
|
+
cacheSessionTitle(sessionId, sessionTitle);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const agentName = (() => {
|
|
243
|
+
const mode = typeof info.agent === 'string' && info.agent.trim().length > 0
|
|
244
|
+
? info.agent.trim()
|
|
245
|
+
: (typeof info.mode === 'string' ? info.mode.trim() : '');
|
|
246
|
+
if (!mode) return 'Agent';
|
|
247
|
+
return mode.split(/[-_\s]+/).filter(Boolean)
|
|
248
|
+
.map((token) => token.charAt(0).toUpperCase() + token.slice(1)).join(' ');
|
|
249
|
+
})();
|
|
250
|
+
|
|
251
|
+
const modelName = (() => {
|
|
252
|
+
const raw = typeof info.modelID === 'string' ? info.modelID.trim()
|
|
253
|
+
: (typeof info.model?.modelID === 'string' ? info.model.modelID.trim() : '');
|
|
254
|
+
if (!raw) return 'Assistant';
|
|
255
|
+
return raw.split(/[-_]+/).filter(Boolean)
|
|
256
|
+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(' ');
|
|
257
|
+
})();
|
|
258
|
+
|
|
259
|
+
let projectName = '';
|
|
260
|
+
let branch = '';
|
|
261
|
+
let worktreeDir = '';
|
|
262
|
+
|
|
263
|
+
const infoPath = info.path;
|
|
264
|
+
if (typeof infoPath?.root === 'string' && infoPath.root.length > 0) {
|
|
265
|
+
worktreeDir = infoPath.root;
|
|
266
|
+
} else if (typeof infoPath?.cwd === 'string' && infoPath.cwd.length > 0) {
|
|
267
|
+
worktreeDir = infoPath.cwd;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
try {
|
|
271
|
+
const settings = await readSettingsFromDisk();
|
|
272
|
+
const projects = Array.isArray(settings.projects) ? settings.projects : [];
|
|
273
|
+
|
|
274
|
+
if (worktreeDir) {
|
|
275
|
+
const normalizedDir = worktreeDir.replace(/\/+$/, '');
|
|
276
|
+
const matchedProject = projects.find((project) => {
|
|
277
|
+
if (!project || typeof project.path !== 'string') return false;
|
|
278
|
+
return project.path.replace(/\/+$/, '') === normalizedDir;
|
|
279
|
+
});
|
|
280
|
+
if (matchedProject && typeof matchedProject.label === 'string' && matchedProject.label.trim().length > 0) {
|
|
281
|
+
projectName = matchedProject.label.trim();
|
|
282
|
+
} else {
|
|
283
|
+
projectName = normalizedDir.split('/').filter(Boolean).pop() || '';
|
|
284
|
+
}
|
|
285
|
+
} else {
|
|
286
|
+
const activeId = typeof settings.activeProjectId === 'string' ? settings.activeProjectId : '';
|
|
287
|
+
const activeProject = activeId ? projects.find((project) => project && project.id === activeId) : projects[0];
|
|
288
|
+
if (activeProject) {
|
|
289
|
+
projectName = typeof activeProject.label === 'string' && activeProject.label.trim().length > 0
|
|
290
|
+
? activeProject.label.trim()
|
|
291
|
+
: typeof activeProject.path === 'string'
|
|
292
|
+
? activeProject.path.split('/').pop() || ''
|
|
293
|
+
: '';
|
|
294
|
+
worktreeDir = typeof activeProject.path === 'string' ? activeProject.path : '';
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
} catch {
|
|
298
|
+
if (worktreeDir && !projectName) {
|
|
299
|
+
projectName = worktreeDir.split('/').filter(Boolean).pop() || '';
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
if (worktreeDir) {
|
|
304
|
+
try {
|
|
305
|
+
const { simpleGit } = await import('simple-git');
|
|
306
|
+
const git = simpleGit({
|
|
307
|
+
baseDir: worktreeDir,
|
|
308
|
+
spawnOptions: { windowsHide: true },
|
|
309
|
+
binary: resolveGitBinaryForSpawn(),
|
|
310
|
+
});
|
|
311
|
+
branch = await Promise.race([
|
|
312
|
+
git.revparse(['--abbrev-ref', 'HEAD']),
|
|
313
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error('git timeout')), 3000)),
|
|
314
|
+
]).catch(() => '');
|
|
315
|
+
} catch {
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
return {
|
|
320
|
+
project_name: formatProjectLabel(projectName),
|
|
321
|
+
worktree: worktreeDir,
|
|
322
|
+
branch: typeof branch === 'string' ? branch.trim() : '',
|
|
323
|
+
session_name: sessionTitle,
|
|
324
|
+
agent_name: agentName,
|
|
325
|
+
model_name: modelName,
|
|
326
|
+
last_message: '',
|
|
327
|
+
session_id: sessionId || '',
|
|
328
|
+
};
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
const getCachedZenModels = () => cachedZenModels;
|
|
332
|
+
|
|
333
|
+
return {
|
|
334
|
+
createTimeoutSignal,
|
|
335
|
+
formatProjectLabel,
|
|
336
|
+
resolveNotificationTemplate,
|
|
337
|
+
shouldApplyResolvedTemplateMessage,
|
|
338
|
+
fetchFreeZenModels,
|
|
339
|
+
resolveZenModel,
|
|
340
|
+
validateZenModelAtStartup,
|
|
341
|
+
summarizeText,
|
|
342
|
+
extractTextFromParts,
|
|
343
|
+
extractLastMessageText,
|
|
344
|
+
fetchLastAssistantMessageText,
|
|
345
|
+
maybeCacheSessionInfoFromEvent,
|
|
346
|
+
buildTemplateVariables,
|
|
347
|
+
getCachedZenModels,
|
|
348
|
+
};
|
|
349
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { createNotificationTemplateRuntime } from './template-runtime.js';
|
|
4
|
+
|
|
5
|
+
const createRuntime = (settings = {}) => createNotificationTemplateRuntime({
|
|
6
|
+
readSettingsFromDisk: async () => settings,
|
|
7
|
+
persistSettings: vi.fn(async () => {}),
|
|
8
|
+
buildOpenCodeUrl: (path) => path,
|
|
9
|
+
getOpenCodeAuthHeaders: () => ({}),
|
|
10
|
+
resolveGitBinaryForSpawn: () => 'git',
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
describe('notification template runtime zen models', () => {
|
|
14
|
+
it('returns no selectable zen models after provider retirement', async () => {
|
|
15
|
+
const runtime = createRuntime();
|
|
16
|
+
const models = await runtime.fetchFreeZenModels();
|
|
17
|
+
|
|
18
|
+
expect(models).toEqual([]);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('preserves stored zen model value for compatibility without validation', async () => {
|
|
22
|
+
const runtime = createRuntime({ zenModel: 'trinity-large-preview-free' });
|
|
23
|
+
|
|
24
|
+
await expect(runtime.resolveZenModel()).resolves.toBe('trinity-large-preview-free');
|
|
25
|
+
});
|
|
26
|
+
});
|