@toddzheng024/dscode-desktop 0.0.0-stage → 0.7.33
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/LICENSE +21 -0
- package/README.md +120 -2
- package/THIRD_PARTY_NOTICES.md +30 -0
- package/bin/apply_patch +9 -0
- package/cordis.patch.yml +433 -0
- package/docs/CHANGELOG.md +641 -0
- package/docs/account-login.md +44 -0
- package/docs/auto-review.md +128 -0
- package/docs/browser-use.md +783 -0
- package/docs/computer-use.md +81 -0
- package/docs/custom-providers.md +88 -0
- package/docs/demo.md +76 -0
- package/docs/distribution.md +58 -0
- package/docs/dscode-ultra.md +75 -0
- package/docs/email.md +296 -0
- package/docs/exec.md +40 -0
- package/docs/hub-distribution.md +190 -0
- package/docs/memory.md +121 -0
- package/docs/opencode-go.md +61 -0
- package/docs/plugin-hub.md +68 -0
- package/docs/releases/0.2.0.md +28 -0
- package/docs/releases/0.3.0.md +21 -0
- package/docs/releases/0.4.0.md +20 -0
- package/docs/releases/0.5.0.md +19 -0
- package/docs/releases/0.6.0.md +20 -0
- package/docs/releases/0.7.0.md +22 -0
- package/docs/releases/0.7.1.md +20 -0
- package/docs/releases/0.7.10.md +10 -0
- package/docs/releases/0.7.11.md +17 -0
- package/docs/releases/0.7.12.md +11 -0
- package/docs/releases/0.7.13.md +12 -0
- package/docs/releases/0.7.14.md +11 -0
- package/docs/releases/0.7.15.md +11 -0
- package/docs/releases/0.7.16.md +10 -0
- package/docs/releases/0.7.17.md +12 -0
- package/docs/releases/0.7.18.md +13 -0
- package/docs/releases/0.7.19.md +8 -0
- package/docs/releases/0.7.2.md +19 -0
- package/docs/releases/0.7.20.md +10 -0
- package/docs/releases/0.7.21.md +9 -0
- package/docs/releases/0.7.22.md +11 -0
- package/docs/releases/0.7.23.md +14 -0
- package/docs/releases/0.7.24.md +11 -0
- package/docs/releases/0.7.25.md +8 -0
- package/docs/releases/0.7.26.md +18 -0
- package/docs/releases/0.7.27.md +8 -0
- package/docs/releases/0.7.28.md +22 -0
- package/docs/releases/0.7.29.md +12 -0
- package/docs/releases/0.7.3.md +23 -0
- package/docs/releases/0.7.30.md +19 -0
- package/docs/releases/0.7.31.md +14 -0
- package/docs/releases/0.7.32.md +14 -0
- package/docs/releases/0.7.33.md +30 -0
- package/docs/releases/0.7.4.md +16 -0
- package/docs/releases/0.7.5.md +18 -0
- package/docs/releases/0.7.6.md +29 -0
- package/docs/releases/0.7.7.md +36 -0
- package/docs/releases/0.7.8.md +14 -0
- package/docs/releases/0.7.9.md +15 -0
- package/docs/session-bridge.md +80 -0
- package/docs/session-cards.md +53 -0
- package/docs/session-communication.md +186 -0
- package/docs/session-metrics.md +41 -0
- package/docs/skills.md +81 -0
- package/docs/triggers.md +338 -0
- package/docs/tui-commands.md +204 -0
- package/extensions/browser/manifest.json +22 -0
- package/extensions/browser/popup.css +6 -0
- package/extensions/browser/popup.html +11 -0
- package/extensions/browser/popup.mjs +47 -0
- package/extensions/browser/protocol.mjs +168 -0
- package/extensions/browser/worker.mjs +94 -0
- package/icon.svg +7 -0
- package/locale/en.json +6 -0
- package/locale/zh-cn.json +6 -0
- package/node_modules/@deepseek-ai/node-addon-system/LICENSE +21 -0
- package/node_modules/@deepseek-ai/node-addon-system/README.i18n.yaml +6 -0
- package/node_modules/@deepseek-ai/node-addon-system/README.md +15 -0
- package/node_modules/@deepseek-ai/node-addon-system/README.zh.md +15 -0
- package/node_modules/@deepseek-ai/node-addon-system/lib/flock.d.ts +13 -0
- package/node_modules/@deepseek-ai/node-addon-system/lib/flock.js +51 -0
- package/node_modules/@deepseek-ai/node-addon-system/lib/index.d.ts +73 -0
- package/node_modules/@deepseek-ai/node-addon-system/lib/index.js +98 -0
- package/node_modules/@deepseek-ai/node-addon-system/package.json +45 -0
- package/node_modules/@deepseek-ai/node-addon-system/src/flock.c +164 -0
- package/node_modules/@deepseek-ai/node-addon-system/src/main.c +298 -0
- package/node_modules/@deepseek-ai/node-addon-system-darwin-arm64/LICENSE +28 -0
- package/node_modules/@deepseek-ai/node-addon-system-darwin-arm64/README.i18n.yaml +6 -0
- package/node_modules/@deepseek-ai/node-addon-system-darwin-arm64/README.md +9 -0
- package/node_modules/@deepseek-ai/node-addon-system-darwin-arm64/README.zh.md +9 -0
- package/node_modules/@deepseek-ai/node-addon-system-darwin-arm64/bin/system.node +0 -0
- package/node_modules/@deepseek-ai/node-addon-system-darwin-arm64/package.json +31 -0
- package/node_modules/@deepseek-ai/node-addon-system-darwin-arm64/prebuilds.json +6 -0
- package/node_modules/@deepseek-ai/node-addon-system-darwin-x64/LICENSE +28 -0
- package/node_modules/@deepseek-ai/node-addon-system-darwin-x64/README.i18n.yaml +6 -0
- package/node_modules/@deepseek-ai/node-addon-system-darwin-x64/README.md +9 -0
- package/node_modules/@deepseek-ai/node-addon-system-darwin-x64/README.zh.md +9 -0
- package/node_modules/@deepseek-ai/node-addon-system-darwin-x64/bin/system.node +0 -0
- package/node_modules/@deepseek-ai/node-addon-system-darwin-x64/package.json +31 -0
- package/node_modules/@deepseek-ai/node-addon-system-darwin-x64/prebuilds.json +6 -0
- package/node_modules/@deepseek-ai/node-addon-system-linux-arm64/LICENSE +28 -0
- package/node_modules/@deepseek-ai/node-addon-system-linux-arm64/README.i18n.yaml +6 -0
- package/node_modules/@deepseek-ai/node-addon-system-linux-arm64/README.md +11 -0
- package/node_modules/@deepseek-ai/node-addon-system-linux-arm64/README.zh.md +11 -0
- package/node_modules/@deepseek-ai/node-addon-system-linux-arm64/bin/glibc/system.node +0 -0
- package/node_modules/@deepseek-ai/node-addon-system-linux-arm64/bin/landlock-run +0 -0
- package/node_modules/@deepseek-ai/node-addon-system-linux-arm64/bin/musl/system.node +0 -0
- package/node_modules/@deepseek-ai/node-addon-system-linux-arm64/package.json +31 -0
- package/node_modules/@deepseek-ai/node-addon-system-linux-arm64/prebuilds.json +24 -0
- package/node_modules/@deepseek-ai/node-addon-system-linux-x64/LICENSE +28 -0
- package/node_modules/@deepseek-ai/node-addon-system-linux-x64/README.i18n.yaml +6 -0
- package/node_modules/@deepseek-ai/node-addon-system-linux-x64/README.md +11 -0
- package/node_modules/@deepseek-ai/node-addon-system-linux-x64/README.zh.md +11 -0
- package/node_modules/@deepseek-ai/node-addon-system-linux-x64/bin/glibc/system.node +0 -0
- package/node_modules/@deepseek-ai/node-addon-system-linux-x64/bin/landlock-run +0 -0
- package/node_modules/@deepseek-ai/node-addon-system-linux-x64/bin/musl/system.node +0 -0
- package/node_modules/@deepseek-ai/node-addon-system-linux-x64/package.json +31 -0
- package/node_modules/@deepseek-ai/node-addon-system-linux-x64/prebuilds.json +24 -0
- package/package.json +156 -4
- package/plugins/account/index.mjs +178 -0
- package/plugins/account/state.mjs +123 -0
- package/plugins/auto-review/audit.mjs +24 -0
- package/plugins/auto-review/index.mjs +267 -0
- package/plugins/auto-review/policy.mjs +92 -0
- package/plugins/browser/SKILL.md +158 -0
- package/plugins/browser/access.mjs +143 -0
- package/plugins/browser/config.mjs +60 -0
- package/plugins/browser/connection.mjs +385 -0
- package/plugins/browser/desktop-client.mjs +282 -0
- package/plugins/browser/desktop-host.mjs +74 -0
- package/plugins/browser/document-identity.mjs +57 -0
- package/plugins/browser/extension-relay.mjs +66 -0
- package/plugins/browser/files.mjs +32 -0
- package/plugins/browser/index.mjs +235 -0
- package/plugins/browser/mcp-entry.mjs +18 -0
- package/plugins/browser/mcp-tools.mjs +21 -0
- package/plugins/browser/presentation.mjs +45 -0
- package/plugins/browser/preview.mjs +77 -0
- package/plugins/browser/review.mjs +20 -0
- package/plugins/browser/screenshots.mjs +35 -0
- package/plugins/clipboard-image/clipboard-image.swift +56 -0
- package/plugins/clipboard-image/index.mjs +70 -0
- package/plugins/code-review/baseline.mjs +143 -0
- package/plugins/code-review/git.mjs +163 -0
- package/plugins/code-review/index.mjs +236 -0
- package/plugins/compaction/engine.mjs +304 -0
- package/plugins/compaction/tetris.mjs +65 -0
- package/plugins/compaction/threshold.mjs +98 -0
- package/plugins/computer-use/DESKTOP-SKILL.md +64 -0
- package/plugins/computer-use/desktop-host.mjs +75 -0
- package/plugins/computer-use/desktop-skill.mjs +28 -0
- package/plugins/computer-use/desktop-upstream.mjs +3 -0
- package/plugins/computer-use/index.mjs +37 -0
- package/plugins/cordis-config/plain.mjs +31 -0
- package/plugins/credentials/index.mjs +73 -0
- package/plugins/custom/adapter.mjs +110 -0
- package/plugins/custom/config.mjs +85 -0
- package/plugins/custom/desktop-client.mjs +150 -0
- package/plugins/custom/desktop-host.mjs +78 -0
- package/plugins/custom/images.mjs +32 -0
- package/plugins/custom/index.mjs +145 -0
- package/plugins/custom/wire.mjs +179 -0
- package/plugins/desktop/client.mjs +1041 -0
- package/plugins/desktop/index.mjs +10 -0
- package/plugins/desktop/shell-environment.mjs +9 -0
- package/plugins/desktop-workspace/hooks.mjs +29 -0
- package/plugins/desktop-workspace/index.mjs +37 -0
- package/plugins/dscode/board.mjs +260 -0
- package/plugins/dscode/child-target.mjs +11 -0
- package/plugins/dscode/control.mjs +17 -0
- package/plugins/dscode/desktop-client.mjs +55 -0
- package/plugins/dscode/desktop-host.mjs +37 -0
- package/plugins/dscode/index.mjs +270 -0
- package/plugins/email/cli.mjs +32 -0
- package/plugins/email/contacts.mjs +36 -0
- package/plugins/email/desktop-client.mjs +117 -0
- package/plugins/email/desktop-host.mjs +54 -0
- package/plugins/email/desktop-service.mjs +106 -0
- package/plugins/email/gmail-oauth.mjs +69 -0
- package/plugins/email/gmail-store.mjs +2 -0
- package/plugins/email/gmail.mjs +194 -0
- package/plugins/email/imap.mjs +136 -0
- package/plugins/email/inbox.d.mts +25 -0
- package/plugins/email/inbox.mjs +76 -0
- package/plugins/email/smtp.mjs +70 -0
- package/plugins/email/store.mjs +32 -0
- package/plugins/email-tools/index.mjs +46 -0
- package/plugins/exec/cli.mjs +64 -0
- package/plugins/exec/index.mjs +112 -0
- package/plugins/grok/adapter.mjs +114 -0
- package/plugins/grok/auth.mjs +76 -0
- package/plugins/grok/billing.mjs +146 -0
- package/plugins/grok/index.mjs +122 -0
- package/plugins/grok/models.mjs +129 -0
- package/plugins/grok/status.mjs +28 -0
- package/plugins/grok/wire.mjs +268 -0
- package/plugins/hub/catalog.mjs +82 -0
- package/plugins/hub/desktop-client.mjs +114 -0
- package/plugins/hub/desktop-host.mjs +129 -0
- package/plugins/i18n/messages.d.mts +21 -0
- package/plugins/i18n/messages.mjs +537 -0
- package/plugins/jev/approval.mjs +131 -0
- package/plugins/jev/client.mjs +74 -0
- package/plugins/jev/index.mjs +99 -0
- package/plugins/memory/content.mjs +57 -0
- package/plugins/memory/desktop-host.mjs +3 -0
- package/plugins/memory/index.mjs +168 -0
- package/plugins/memory/pipeline.mjs +79 -0
- package/plugins/memory/store.mjs +93 -0
- package/plugins/message-source/kind.mjs +20 -0
- package/plugins/opencode-go/adapter.mjs +96 -0
- package/plugins/opencode-go/command.mjs +128 -0
- package/plugins/opencode-go/index.mjs +120 -0
- package/plugins/opencode-go/models.mjs +58 -0
- package/plugins/opencode-go/oauth.mjs +194 -0
- package/plugins/opencode-go/search.mjs +86 -0
- package/plugins/opencode-go/usage.mjs +119 -0
- package/plugins/opencode-go/version.mjs +10 -0
- package/plugins/opencode-go/wire.mjs +73 -0
- package/plugins/openrouter/adapter.mjs +232 -0
- package/plugins/openrouter/index.mjs +123 -0
- package/plugins/openrouter/models.mjs +157 -0
- package/plugins/openrouter/search.mjs +113 -0
- package/plugins/openrouter/wire.mjs +101 -0
- package/plugins/providers/catalog.mjs +160 -0
- package/plugins/providers/chat-messages.mjs +120 -0
- package/plugins/providers/chat-stream.mjs +174 -0
- package/plugins/providers/desktop-client.mjs +84 -0
- package/plugins/providers/desktop-host.mjs +63 -0
- package/plugins/providers/effort.mjs +35 -0
- package/plugins/providers/http-errors.mjs +50 -0
- package/plugins/providers/openrouter-account.mjs +171 -0
- package/plugins/session-bridge/client.mjs +106 -0
- package/plugins/session-bridge/communication.mjs +260 -0
- package/plugins/session-bridge/index.mjs +68 -0
- package/plugins/session-bridge/mailbox.mjs +267 -0
- package/plugins/session-bridge/paths.mjs +21 -0
- package/plugins/session-bridge/server.mjs +172 -0
- package/plugins/session-bridge/tasks.mjs +229 -0
- package/plugins/session-cards/content.mjs +64 -0
- package/plugins/session-cards/index.mjs +38 -0
- package/plugins/session-cards/manager.mjs +140 -0
- package/plugins/session-metrics/attribution.mjs +30 -0
- package/plugins/session-metrics/balance.mjs +81 -0
- package/plugins/session-metrics/desktop-client.mjs +62 -0
- package/plugins/session-metrics/desktop-host.mjs +46 -0
- package/plugins/session-metrics/index.mjs +96 -0
- package/plugins/session-metrics/pricing.mjs +84 -0
- package/plugins/session-metrics/rate.mjs +59 -0
- package/plugins/session-metrics/store.mjs +75 -0
- package/plugins/session-metrics/turns.mjs +134 -0
- package/plugins/session-metrics/view.mjs +271 -0
- package/plugins/time-marks/desktop-host.mjs +2 -0
- package/plugins/time-marks/index.mjs +116 -0
- package/plugins/time-marks/marks.mjs +152 -0
- package/plugins/triggers/cli.mjs +558 -0
- package/plugins/triggers/commands.mjs +143 -0
- package/plugins/triggers/config.mjs +264 -0
- package/plugins/triggers/desktop-client.mjs +155 -0
- package/plugins/triggers/desktop-host.mjs +88 -0
- package/plugins/triggers/desktop-management.mjs +97 -0
- package/plugins/triggers/desktop-scheduler.mjs +125 -0
- package/plugins/triggers/host.mjs +24 -0
- package/plugins/triggers/index.mjs +27 -0
- package/plugins/triggers/job-cli.mjs +110 -0
- package/plugins/triggers/jobs.mjs +156 -0
- package/plugins/triggers/launchd.mjs +101 -0
- package/plugins/triggers/lease.mjs +24 -0
- package/plugins/triggers/log.mjs +104 -0
- package/plugins/triggers/management.mjs +181 -0
- package/plugins/triggers/options.mjs +117 -0
- package/plugins/triggers/overlay.mjs +7 -0
- package/plugins/triggers/poll.mjs +65 -0
- package/plugins/triggers/run.mjs +157 -0
- package/plugins/triggers/schedule.mjs +40 -0
- package/plugins/triggers/scheduler-service.mjs +46 -0
- package/plugins/triggers/scheduler.mjs +92 -0
- package/plugins/triggers/session-run.mjs +125 -0
- package/plugins/triggers/session.mjs +48 -0
- package/plugins/triggers/source-emit.mjs +19 -0
- package/plugins/triggers/source-host.mjs +78 -0
- package/plugins/triggers/source-ingress.mjs +70 -0
- package/plugins/triggers/source-sandbox.mjs +35 -0
- package/plugins/triggers/sources.mjs +45 -0
- package/plugins/triggers/spool.mjs +145 -0
- package/plugins/triggers/tools.mjs +67 -0
- package/plugins/triggers/unattended.mjs +18 -0
- package/plugins/tui-tools/composition.mjs +28 -0
- package/plugins/tui-tools/desktop-host.mjs +2 -0
- package/plugins/tui-tools/doctor-cli.mjs +22 -0
- package/plugins/tui-tools/doctor.mjs +148 -0
- package/plugins/tui-tools/hook-sources.mjs +113 -0
- package/plugins/tui-tools/hooks.mjs +23 -0
- package/plugins/tui-tools/index.mjs +268 -0
- package/plugins/tui-tools/sandbox-runner.mjs +123 -0
- package/plugins/tui-tools/shell.mjs +27 -0
- package/plugins/tui-tools/update.mjs +111 -0
- package/plugins/tui-tools/workspace-discovery.mjs +129 -0
- package/plugins/ultra/policy.mjs +42 -0
- package/plugins/worktree-subagent/worktree.mjs +56 -0
- package/runtime-sources.json +94 -0
- package/vendor/bash/LICENSE +21 -0
- package/vendor/bash/index.js +717 -0
- package/vendor/bash/types/background.d.ts +50 -0
- package/vendor/bash/types/index.d.ts +38 -0
- package/vendor/bash/types/render.d.ts +57 -0
- package/vendor/command-goal/LICENSE +21 -0
- package/vendor/command-goal/index.js +210 -0
- package/vendor/command-goal/types/index.d.ts +10 -0
- package/vendor/computer-use/LICENSE +21 -0
- package/vendor/computer-use/lib/approval-policy.js +12 -0
- package/vendor/computer-use/lib/approval-policy.js.map +1 -0
- package/vendor/computer-use/lib/artifacts.js +79 -0
- package/vendor/computer-use/lib/artifacts.js.map +1 -0
- package/vendor/computer-use/lib/backend.js +3 -0
- package/vendor/computer-use/lib/backend.js.map +1 -0
- package/vendor/computer-use/lib/client.js +369 -0
- package/vendor/computer-use/lib/client.js.map +1 -0
- package/vendor/computer-use/lib/config.js +159 -0
- package/vendor/computer-use/lib/config.js.map +1 -0
- package/vendor/computer-use/lib/confirmations.js +99 -0
- package/vendor/computer-use/lib/confirmations.js.map +1 -0
- package/vendor/computer-use/lib/diff.js +58 -0
- package/vendor/computer-use/lib/diff.js.map +1 -0
- package/vendor/computer-use/lib/errors.js +22 -0
- package/vendor/computer-use/lib/errors.js.map +1 -0
- package/vendor/computer-use/lib/exposure.js +244 -0
- package/vendor/computer-use/lib/exposure.js.map +1 -0
- package/vendor/computer-use/lib/index.js +66 -0
- package/vendor/computer-use/lib/index.js.map +1 -0
- package/vendor/computer-use/lib/leases.js +262 -0
- package/vendor/computer-use/lib/leases.js.map +1 -0
- package/vendor/computer-use/lib/providers/macos.js +243 -0
- package/vendor/computer-use/lib/providers/macos.js.map +1 -0
- package/vendor/computer-use/lib/providers/native-helper.js +726 -0
- package/vendor/computer-use/lib/providers/native-helper.js.map +1 -0
- package/vendor/computer-use/lib/providers/unsupported.js +51 -0
- package/vendor/computer-use/lib/providers/unsupported.js.map +1 -0
- package/vendor/computer-use/lib/service.js +608 -0
- package/vendor/computer-use/lib/service.js.map +1 -0
- package/vendor/computer-use/lib/skill.js +136 -0
- package/vendor/computer-use/lib/skill.js.map +1 -0
- package/vendor/computer-use/lib/target-resolver.js +180 -0
- package/vendor/computer-use/lib/target-resolver.js.map +1 -0
- package/vendor/computer-use/lib/tools.js +511 -0
- package/vendor/computer-use/lib/tools.js.map +1 -0
- package/vendor/computer-use/lib/types/approval-policy.d.ts +13 -0
- package/vendor/computer-use/lib/types/approval-policy.d.ts.map +1 -0
- package/vendor/computer-use/lib/types/artifacts.d.ts +10 -0
- package/vendor/computer-use/lib/types/artifacts.d.ts.map +1 -0
- package/vendor/computer-use/lib/types/backend.d.ts +124 -0
- package/vendor/computer-use/lib/types/backend.d.ts.map +1 -0
- package/vendor/computer-use/lib/types/client/index.d.ts +83 -0
- package/vendor/computer-use/lib/types/client/index.d.ts.map +1 -0
- package/vendor/computer-use/lib/types/config.d.ts +94 -0
- package/vendor/computer-use/lib/types/config.d.ts.map +1 -0
- package/vendor/computer-use/lib/types/confirmations.d.ts +23 -0
- package/vendor/computer-use/lib/types/confirmations.d.ts.map +1 -0
- package/vendor/computer-use/lib/types/diff.d.ts +5 -0
- package/vendor/computer-use/lib/types/diff.d.ts.map +1 -0
- package/vendor/computer-use/lib/types/errors.d.ts +15 -0
- package/vendor/computer-use/lib/types/errors.d.ts.map +1 -0
- package/vendor/computer-use/lib/types/exposure.d.ts +30 -0
- package/vendor/computer-use/lib/types/exposure.d.ts.map +1 -0
- package/vendor/computer-use/lib/types/index.d.ts +21 -0
- package/vendor/computer-use/lib/types/index.d.ts.map +1 -0
- package/vendor/computer-use/lib/types/leases.d.ts +81 -0
- package/vendor/computer-use/lib/types/leases.d.ts.map +1 -0
- package/vendor/computer-use/lib/types/providers/macos.d.ts +39 -0
- package/vendor/computer-use/lib/types/providers/macos.d.ts.map +1 -0
- package/vendor/computer-use/lib/types/providers/native-helper.d.ts +48 -0
- package/vendor/computer-use/lib/types/providers/native-helper.d.ts.map +1 -0
- package/vendor/computer-use/lib/types/providers/unsupported.d.ts +23 -0
- package/vendor/computer-use/lib/types/providers/unsupported.d.ts.map +1 -0
- package/vendor/computer-use/lib/types/service.d.ts +58 -0
- package/vendor/computer-use/lib/types/service.d.ts.map +1 -0
- package/vendor/computer-use/lib/types/skill.d.ts +14 -0
- package/vendor/computer-use/lib/types/skill.d.ts.map +1 -0
- package/vendor/computer-use/lib/types/target-resolver.d.ts +38 -0
- package/vendor/computer-use/lib/types/target-resolver.d.ts.map +1 -0
- package/vendor/computer-use/lib/types/tools.d.ts +6 -0
- package/vendor/computer-use/lib/types/tools.d.ts.map +1 -0
- package/vendor/computer-use/lib/types/types.d.ts +270 -0
- package/vendor/computer-use/lib/types/types.d.ts.map +1 -0
- package/vendor/computer-use/lib/types/web.d.ts +33 -0
- package/vendor/computer-use/lib/types/web.d.ts.map +1 -0
- package/vendor/computer-use/lib/types.js +9 -0
- package/vendor/computer-use/lib/types.js.map +1 -0
- package/vendor/computer-use/lib/web.js +188 -0
- package/vendor/computer-use/lib/web.js.map +1 -0
- package/vendor/computer-use/native/macos/Sources/Fixture/main.swift +412 -0
- package/vendor/computer-use/native/macos/Sources/Helper/CursorImage.swift +11 -0
- package/vendor/computer-use/native/macos/Sources/Helper/CursorMotion.swift +67 -0
- package/vendor/computer-use/native/macos/Sources/Helper/CursorOverlay.swift +840 -0
- package/vendor/computer-use/native/macos/Sources/Helper/TargetedPointer.swift +327 -0
- package/vendor/computer-use/native/macos/Sources/Helper/WindowNumberMatcher.swift +29 -0
- package/vendor/computer-use/native/macos/Sources/Helper/main.swift +1244 -0
- package/vendor/computer-use/native/macos/Sources/Monitor/main.swift +153 -0
- package/vendor/computer-use/native/macos/bin/dsh-computer-use-helper +0 -0
- package/vendor/computer-use/native/macos/manifest.json +14 -0
- package/vendor/persistent/LICENSE +21 -0
- package/vendor/persistent/index.js +411 -0
- package/vendor/persistent/types/index.d.ts +24 -0
- package/vendor/subagent/LICENSE +21 -0
- package/vendor/subagent/index.js +694 -0
- package/vendor/subagent/invariant.js +52 -0
- package/vendor/subagent/model-selection-settings.js +68 -0
- package/vendor/subagent/types/index.d.ts +82 -0
- package/vendor/subagent/types/invariant.d.ts +16 -0
- package/vendor/subagent/types/list-models.d.ts +10 -0
- package/vendor/subagent/types/model-selection-settings.d.ts +45 -0
- package/vendor/subagent/types/model-selection-state.d.ts +48 -0
- package/vendor/subagent/types/model-selection.d.ts +81 -0
- package/vendor/subagent-core/LICENSE +21 -0
- package/vendor/subagent-core/index.js +3202 -0
- package/vendor/subagent-core/invariant.js +76 -0
- package/vendor/subagent-core/typert.host.d.ts +3 -0
- package/vendor/subagent-core/typert.host.js +978 -0
- package/vendor/subagent-core/typert.remote-client.d.ts +25 -0
- package/vendor/subagent-core/typert.remote-client.js +114 -0
- package/vendor/subagent-core/types/archive-admission.d.ts +16 -0
- package/vendor/subagent-core/types/archive-admission.js +151 -0
- package/vendor/subagent-core/types/assistant-output.d.ts +48 -0
- package/vendor/subagent-core/types/assistant-output.js +73 -0
- package/vendor/subagent-core/types/catalog.d.ts +84 -0
- package/vendor/subagent-core/types/catalog.js +109 -0
- package/vendor/subagent-core/types/child-agent.d.ts +156 -0
- package/vendor/subagent-core/types/child-agent.js +213 -0
- package/vendor/subagent-core/types/client.d.ts +8 -0
- package/vendor/subagent-core/types/client.js +7 -0
- package/vendor/subagent-core/types/continuation-activation.d.ts +267 -0
- package/vendor/subagent-core/types/continuation-activation.js +700 -0
- package/vendor/subagent-core/types/continuation-messages.d.ts +62 -0
- package/vendor/subagent-core/types/continuation-messages.js +106 -0
- package/vendor/subagent-core/types/continuation.d.ts +124 -0
- package/vendor/subagent-core/types/continuation.js +455 -0
- package/vendor/subagent-core/types/control-types.d.ts +135 -0
- package/vendor/subagent-core/types/control-types.js +8 -0
- package/vendor/subagent-core/types/control.d.ts +45 -0
- package/vendor/subagent-core/types/control.js +79 -0
- package/vendor/subagent-core/types/depth.d.ts +31 -0
- package/vendor/subagent-core/types/depth.js +39 -0
- package/vendor/subagent-core/types/descriptor.d.ts +144 -0
- package/vendor/subagent-core/types/descriptor.js +193 -0
- package/vendor/subagent-core/types/error.d.ts +11 -0
- package/vendor/subagent-core/types/error.js +14 -0
- package/vendor/subagent-core/types/inbox.d.ts +43 -0
- package/vendor/subagent-core/types/inbox.js +61 -0
- package/vendor/subagent-core/types/index.d.ts +320 -0
- package/vendor/subagent-core/types/index.js +475 -0
- package/vendor/subagent-core/types/internal.d.ts +58 -0
- package/vendor/subagent-core/types/internal.js +58 -0
- package/vendor/subagent-core/types/invariant.d.ts +13 -0
- package/vendor/subagent-core/types/invariant.js +91 -0
- package/vendor/subagent-core/types/lifecycle.d.ts +113 -0
- package/vendor/subagent-core/types/lifecycle.js +180 -0
- package/vendor/subagent-core/types/list-children.d.ts +36 -0
- package/vendor/subagent-core/types/list-children.js +166 -0
- package/vendor/subagent-core/types/out-of-process.d.ts +118 -0
- package/vendor/subagent-core/types/out-of-process.js +219 -0
- package/vendor/subagent-core/types/projection-types.d.ts +82 -0
- package/vendor/subagent-core/types/projection-types.js +7 -0
- package/vendor/subagent-core/types/projection.d.ts +100 -0
- package/vendor/subagent-core/types/projection.js +157 -0
- package/vendor/subagent-core/types/run-settlement.d.ts +17 -0
- package/vendor/subagent-core/types/run-settlement.js +70 -0
- package/vendor/subagent-core/types/types.d.ts +377 -0
- package/vendor/subagent-core/types/types.js +19 -0
- package/vendor/subagent-driver/LICENSE +21 -0
- package/vendor/subagent-driver/index.js +255 -0
- package/vendor/subagent-driver/types/index.d.ts +33 -0
- package/vendor/subagent-driver/types/structured.d.ts +42 -0
- package/vendor/subagent-fork/LICENSE +21 -0
- package/vendor/subagent-fork/index.js +61 -0
- package/vendor/subagent-fork/types/index.d.ts +20 -0
- package/vendor/subagent-spawn/LICENSE +21 -0
- package/vendor/subagent-spawn/index.js +45 -0
- package/vendor/subagent-spawn/types/index.d.ts +19 -0
- package/vendor/terminal/LICENSE +21 -0
- package/vendor/terminal/index.js +1093 -0
- package/vendor/terminal/types/config.d.ts +82 -0
- package/vendor/terminal/types/index.d.ts +36 -0
- package/vendor/terminal/types/sanitize.d.ts +47 -0
- package/vendor/terminal/types/session.d.ts +87 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import z from '@deepseek-ai/schemastery';
|
|
2
|
+
import { watchFile, unwatchFile } from 'node:fs';
|
|
3
|
+
import { credentialRef } from '@deepseek-ai/dsh-credentials';
|
|
4
|
+
import { createToolResultMessage, resolveImageAttachmentAccess } from '@deepseek-ai/dsh-llm';
|
|
5
|
+
import { CustomStore, validateProfile, customId, keyRef, isCustomId } from './config.mjs';
|
|
6
|
+
import { CustomAdapter, authHeaders } from './adapter.mjs';
|
|
7
|
+
|
|
8
|
+
export const name = 'dscode-custom';
|
|
9
|
+
export const inject = ['llm', 'credentials'];
|
|
10
|
+
export const Config = z.object({ path: z.string().default('') });
|
|
11
|
+
export const getCustomProviders = ctx => ctx.get('dscodeCustom');
|
|
12
|
+
|
|
13
|
+
export class CustomProviders {
|
|
14
|
+
constructor({ store = new CustomStore(), credentials, resolveAttachments, resolveImageAccess, fetch = globalThis.fetch, changed = () => {} }) {
|
|
15
|
+
Object.assign(this, { store, credentials, fetch, changed });
|
|
16
|
+
this.providers = [];
|
|
17
|
+
this.adapter = new CustomAdapter({ profile: id => this.providers.find(p => p.id === id), resolveKey: p => this.resolveKey(p), resolveAttachments, resolveImageAccess, fetch });
|
|
18
|
+
}
|
|
19
|
+
async refresh() {
|
|
20
|
+
const snapshot = await this.store.read();
|
|
21
|
+
if (snapshot.revision !== this.revision) {
|
|
22
|
+
this.providers = snapshot.providers; this.revision = snapshot.revision; this.changed(this.providers);
|
|
23
|
+
}
|
|
24
|
+
return snapshot;
|
|
25
|
+
}
|
|
26
|
+
async list() {
|
|
27
|
+
const snapshot = await this.refresh();
|
|
28
|
+
return { ...snapshot, providers: await Promise.all(snapshot.providers.map(async p => {
|
|
29
|
+
const facts = await this.credentials.describe(credentialRef(keyRef(p.id)));
|
|
30
|
+
return { ...p, credentialStatus: p.auth === 'none' ? 'No authentication' : facts.configured ? facts.source === 'env' ? 'Key from environment' : 'Key saved' : 'API key missing' };
|
|
31
|
+
})) };
|
|
32
|
+
}
|
|
33
|
+
newProfile() { return { id: customId(), name: '', baseURL: '', api: 'chat-completions', auth: 'bearer', backend: 'generic', timeoutMs: 180000, models: [] }; }
|
|
34
|
+
async resolveKey(profile, draftKey) {
|
|
35
|
+
if (profile.auth === 'none') return undefined;
|
|
36
|
+
if (draftKey) return draftKey;
|
|
37
|
+
return (await this.credentials.resolve(credentialRef(keyRef(profile.id))))?.value;
|
|
38
|
+
}
|
|
39
|
+
async save(input, key, revision) {
|
|
40
|
+
const profile = validateProfile(input);
|
|
41
|
+
if (key && (/[\s\x00-\x1f]/.test(key) || key.length > 4096)) throw Error('Paste only the API key, without whitespace');
|
|
42
|
+
await this.store.update(revision, async providers => {
|
|
43
|
+
if (key) await this.credentials.set(credentialRef(keyRef(profile.id)), key);
|
|
44
|
+
return [...providers.filter(p => p.id !== profile.id), profile];
|
|
45
|
+
});
|
|
46
|
+
return this.list();
|
|
47
|
+
}
|
|
48
|
+
async remove(id, revision) {
|
|
49
|
+
if (!isCustomId(id)) throw Error('Invalid custom provider ID');
|
|
50
|
+
await this.store.update(revision, async providers => {
|
|
51
|
+
const ref = credentialRef(keyRef(id));
|
|
52
|
+
const facts = await this.credentials.describe(ref);
|
|
53
|
+
// Native credentials supplied by the environment are read-only. They
|
|
54
|
+
// cannot keep a deleted route alive or prevent removing its configuration.
|
|
55
|
+
if (facts.source !== 'env') await this.credentials.unset(ref);
|
|
56
|
+
return providers.filter(p => p.id !== id);
|
|
57
|
+
});
|
|
58
|
+
return this.list();
|
|
59
|
+
}
|
|
60
|
+
async clearKey(id) { await this.credentials.unset(credentialRef(keyRef(id))); }
|
|
61
|
+
async json(profile, path, key, signal) {
|
|
62
|
+
const response = await this.fetch(profile.baseURL + path, { redirect: 'error', headers: authHeaders(profile, key), signal: AbortSignal.any([AbortSignal.timeout(10000), ...(signal ? [signal] : [])]) });
|
|
63
|
+
if (!response.ok) { await response.body?.cancel(); throw Error(`Model discovery returned HTTP ${response.status}`); }
|
|
64
|
+
return response.json();
|
|
65
|
+
}
|
|
66
|
+
async discover(input, draftKey, signal) {
|
|
67
|
+
const profile = validateProfile(input), key = await this.resolveKey(profile, draftKey);
|
|
68
|
+
let listing;
|
|
69
|
+
try { listing = await this.json(profile, '/models', key, signal); }
|
|
70
|
+
// Transport exceptions can carry request headers; do not retain their cause.
|
|
71
|
+
// eslint-disable-next-line preserve-caught-error
|
|
72
|
+
catch (error) { if (signal?.aborted) throw Error('Discovery cancelled'); throw Error(error.message?.startsWith('Model discovery returned HTTP') ? error.message : 'Could not discover models; check the address and key, or add a model manually'); }
|
|
73
|
+
if (signal?.aborted) throw Error('Discovery cancelled');
|
|
74
|
+
if (!Array.isArray(listing.data)) throw Error('Model listing has no data array; enter a model manually');
|
|
75
|
+
const backend = listing.data.some(m => m.owned_by === 'omlx') ? 'omlx' : 'generic';
|
|
76
|
+
let status = [];
|
|
77
|
+
if (backend === 'omlx') {
|
|
78
|
+
try {
|
|
79
|
+
const metadata = await this.json(profile, '/models/status', key, signal);
|
|
80
|
+
if (Array.isArray(metadata?.models)) status = metadata.models;
|
|
81
|
+
} catch { /* Optional oMLX metadata; the standard listing still works. */ }
|
|
82
|
+
if (signal?.aborted) throw Error('Discovery cancelled');
|
|
83
|
+
}
|
|
84
|
+
const positive = value => Number.isSafeInteger(value) && value > 0;
|
|
85
|
+
const models = [];
|
|
86
|
+
for (const entry of listing.data) {
|
|
87
|
+
if (typeof entry.id !== 'string' || !entry.id.trim() || models.some(m => m.id === entry.id)) continue;
|
|
88
|
+
const detail = status.find(m => m?.id === entry.id);
|
|
89
|
+
const contextWindow = [detail?.max_context_window, entry.max_model_len, entry.context_length, entry.context_window].find(positive);
|
|
90
|
+
const maxTokens = [detail?.max_tokens, entry.max_output_tokens].find(value => positive(value) && (!contextWindow || value < contextWindow));
|
|
91
|
+
models.push({ id: entry.id, name: entry.name ?? entry.id, thinking: 'default',
|
|
92
|
+
...(positive(contextWindow) ? { contextWindow, contextSource: 'server' } : {}),
|
|
93
|
+
...(positive(maxTokens) && (!positive(contextWindow) || maxTokens < contextWindow) ? { maxTokens, outputSource: 'server' } : {}) });
|
|
94
|
+
}
|
|
95
|
+
return { backend, models };
|
|
96
|
+
}
|
|
97
|
+
/** Probe only this draft, without registering it or touching files. */
|
|
98
|
+
async test(input, modelId, draftKey, signal) {
|
|
99
|
+
const profile = validateProfile(input), model = profile.models.find(m => m.id === modelId);
|
|
100
|
+
if (!model?.contextWindow) throw Error('Fill in the model context window before testing');
|
|
101
|
+
const adapter = new CustomAdapter({ profile: () => profile, resolveKey: p => this.resolveKey(p, draftKey), fetch: this.fetch });
|
|
102
|
+
const stages = [];
|
|
103
|
+
const call = async (messages, tools) => {
|
|
104
|
+
const chunks = [];
|
|
105
|
+
for await (const chunk of adapter.stream({ provider: profile.id, model: model.id, messages, tools, maxTokens: 512, ...(profile.backend === 'omlx' ? { reasoningEffort: 'off' } : {}), signal })) chunks.push(chunk);
|
|
106
|
+
const finish = chunks.find(c => c.type === 'finish');
|
|
107
|
+
if (!finish || !['stop', 'tool-calls'].includes(finish.reason.kind)) throw Error('Probe did not complete normally');
|
|
108
|
+
return { blocks: chunks.filter(c => c.type === 'block-end').map(c => c.block), replayState: finish.replayState };
|
|
109
|
+
};
|
|
110
|
+
try {
|
|
111
|
+
const plain = await call([{ role: 'user', content: [{ type: 'text', text: 'Reply with exactly CUSTOM_OK.' }] }]);
|
|
112
|
+
if (!plain.blocks.some(b => b.type === 'text' && b.text.trim() === 'CUSTOM_OK')) throw Error('Text probe returned an unexpected answer');
|
|
113
|
+
stages.push({ name: 'Text and streaming', status: 'passed' });
|
|
114
|
+
const tools = [{ name: 'lookup_probe', description: 'Look up a test value.', parameters: { type: 'object', properties: { name: { type: 'string' } }, required: ['name'], additionalProperties: false } }];
|
|
115
|
+
const messages = [{ role: 'user', content: [{ type: 'text', text: 'Call lookup_probe with name studio. After the tool returns, reply with exactly its value.' }] }];
|
|
116
|
+
const first = await call(messages, tools);
|
|
117
|
+
const calls = first.blocks.filter(b => b.type === 'tool-call');
|
|
118
|
+
if (calls.length !== 1 || calls[0].name !== 'lookup_probe' || JSON.parse(calls[0].arguments).name !== 'studio') throw Error('Tool probe returned an unexpected call');
|
|
119
|
+
stages.push({ name: 'Streamed tool arguments', status: 'passed' });
|
|
120
|
+
messages.push({ role: 'assistant', source: { provider: profile.id, model: model.id, replayState: first.replayState }, content: first.blocks });
|
|
121
|
+
messages.push(createToolResultMessage({ callId: calls[0].id, content: [{ type: 'text', text: '{"value":"CUSTOM_TOOL_OK"}' }], isError: false }));
|
|
122
|
+
const second = await call(messages, tools);
|
|
123
|
+
if (second.blocks.some(b => b.type === 'tool-call') || !second.blocks.some(b => b.type === 'text' && b.text.trim() === 'CUSTOM_TOOL_OK')) throw Error('Tool result replay returned an unexpected answer');
|
|
124
|
+
stages.push({ name: 'Tool result round trip', status: 'passed' }, { name: 'Images, thinking and long context', status: 'not tested' });
|
|
125
|
+
} catch (error) { stages.push({ name: 'Probe', status: 'failed', message: signal?.aborted ? 'Cancelled' : error.message }); }
|
|
126
|
+
return stages;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export async function apply(ctx, config = {}) {
|
|
131
|
+
let registration;
|
|
132
|
+
const service = new CustomProviders({ store: new CustomStore(config.path || undefined), credentials: ctx.credentials,
|
|
133
|
+
resolveAttachments: () => ctx.get('attachments'),
|
|
134
|
+
resolveImageAccess: (attachments, ref) => resolveImageAttachmentAccess(attachments, hostPath => ctx.get('fs')?.processPathFromHostPath(hostPath), ref),
|
|
135
|
+
changed: profiles => {
|
|
136
|
+
const ids = profiles.map(p => p.id);
|
|
137
|
+
if (registration) registration.replace(ids);
|
|
138
|
+
else if (ids.length) registration = ctx.llm.registerAdapter(ids, service.adapter);
|
|
139
|
+
} });
|
|
140
|
+
ctx.provide('dscodeCustom', service);
|
|
141
|
+
try { await service.refresh(); } catch { ctx.logger.warn('Could not read custom providers; repair ~/.dscode/providers.yaml'); }
|
|
142
|
+
const refresh = () => { void service.refresh().catch(() => ctx.logger.warn('Invalid custom provider edit; retaining the last valid configuration')); };
|
|
143
|
+
watchFile(service.store.path, { persistent: false, interval: 1000 }, refresh);
|
|
144
|
+
ctx.effect(() => () => unwatchFile(service.store.path, refresh));
|
|
145
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { LlmError } from '@deepseek-ai/dsh-llm';
|
|
2
|
+
import { serializeMessages } from '../providers/chat-messages.mjs';
|
|
3
|
+
import { errorCode } from '../providers/http-errors.mjs';
|
|
4
|
+
|
|
5
|
+
export const REPLAY_KIND = 'dscode-custom';
|
|
6
|
+
const textOf = blocks => blocks.filter(b => b.type === 'text').map(b => b.text).join('');
|
|
7
|
+
const toolDefinitions = options => (options.tools ?? []).map(t => ({ name: t.name, description: t.description, parameters: t.parameters }));
|
|
8
|
+
function nativeReasoning(message, profile, model) {
|
|
9
|
+
const source = message.source, replay = source?.replayState?.response;
|
|
10
|
+
return source?.provider === profile.id && source.model === model && replay?.kind === REPLAY_KIND && replay.api === profile.api
|
|
11
|
+
? replay.nativeReasoning ?? [] : [];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function requestBody(profile, model, options, images) {
|
|
15
|
+
const budget = options.maxTokens ?? model.maxTokens ?? Math.min(4096, Math.floor(model.contextWindow / 4));
|
|
16
|
+
const temperature = options.temperature === undefined ? {} : { temperature: options.temperature };
|
|
17
|
+
const tools = toolDefinitions(options);
|
|
18
|
+
const serialization = { model: model.id, images, dialect: { provider: profile.id, reasoningContent: () => false } };
|
|
19
|
+
const effort = options.reasoningEffort;
|
|
20
|
+
const thinking = effort === 'off' ? false : effort === 'high' ? true : model.thinking === 'off' ? false : model.thinking === 'on' ? true : undefined;
|
|
21
|
+
if (effort !== undefined && !(profile.backend === 'omlx' && ['off', 'high'].includes(effort))) throw new LlmError('This custom model does not advertise that reasoning effort', 'UNSUPPORTED_REASONING_EFFORT');
|
|
22
|
+
if (thinking !== undefined && profile.backend !== 'omlx') throw new LlmError('Thinking overrides currently require an identified oMLX service; use Server default', 'INVALID_REQUEST');
|
|
23
|
+
const extra = thinking === undefined ? {} : profile.api === 'chat-completions' ? { enable_thinking: thinking } : { chat_template_kwargs: { enable_thinking: thinking } };
|
|
24
|
+
const common = { model: model.id, stream: true, ...temperature, ...extra };
|
|
25
|
+
if (profile.api === 'chat-completions') return { ...common,
|
|
26
|
+
messages: serializeMessages(options.messages, { ...serialization, system: options.system }),
|
|
27
|
+
max_tokens: budget, stream_options: { include_usage: true }, ...(tools.length ? { tools: tools.map(f => ({ type: 'function', function: f })) } : {}), ...(options.stop ? { stop: options.stop } : {}) };
|
|
28
|
+
|
|
29
|
+
// Stateless replay: the local session remains authoritative, including native
|
|
30
|
+
// reasoning items/signatures when the same endpoint protocol produced them.
|
|
31
|
+
const input = [], anthropic = [];
|
|
32
|
+
const system = [options.system, ...options.messages.filter(m => m.role === 'system').map(m => textOf(m.content))].filter(Boolean).join('\n\n');
|
|
33
|
+
for (const message of options.messages.filter(m => m.role !== 'system')) {
|
|
34
|
+
const native = nativeReasoning(message, profile, model.id);
|
|
35
|
+
if (profile.api === 'responses') input.push(...native);
|
|
36
|
+
const parts = [];
|
|
37
|
+
if (profile.api === 'anthropic' && message.role === 'assistant') parts.push(...native);
|
|
38
|
+
for (const wire of serializeMessages([message], serialization)) {
|
|
39
|
+
if (wire.role === 'tool') {
|
|
40
|
+
input.push({ type: 'function_call_output', call_id: wire.tool_call_id, output: wire.content });
|
|
41
|
+
parts.push({ type: 'tool_result', tool_use_id: wire.tool_call_id, content: wire.content,
|
|
42
|
+
...(message.role === 'tool' && message.isError ? { is_error: true } : {}) });
|
|
43
|
+
} else {
|
|
44
|
+
if (wire.content) {
|
|
45
|
+
const content = typeof wire.content === 'string' ? [{ type: 'text', text: wire.content }] : wire.content;
|
|
46
|
+
if (profile.api === 'responses') input.push({ role: wire.role, content: content.map(part => part.type === 'text'
|
|
47
|
+
? { type: wire.role === 'assistant' ? 'output_text' : 'input_text', text: part.text }
|
|
48
|
+
: { type: 'input_image', image_url: part.image_url.url, detail: 'auto' }) });
|
|
49
|
+
else for (const part of content) {
|
|
50
|
+
if (part.type === 'text') parts.push(part);
|
|
51
|
+
else {
|
|
52
|
+
// The shared serializer creates data URLs from prepared attachment bytes.
|
|
53
|
+
const [, mediaType, data] = /^data:([^;]+);base64,(.*)$/.exec(part.image_url.url);
|
|
54
|
+
parts.push({ type: 'image', source: { type: 'base64', media_type: mediaType, data } });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
for (const call of wire.tool_calls ?? []) {
|
|
59
|
+
input.push({ type: 'function_call', call_id: call.id, name: call.function.name, arguments: call.function.arguments });
|
|
60
|
+
let args;
|
|
61
|
+
try { args = JSON.parse(call.function.arguments); } catch { throw new LlmError('Cannot replay invalid tool arguments', 'INVALID_REQUEST'); }
|
|
62
|
+
parts.push({ type: 'tool_use', id: call.id, name: call.function.name, input: args });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (parts.length) {
|
|
67
|
+
const role = message.role === 'assistant' ? 'assistant' : 'user';
|
|
68
|
+
if (anthropic.at(-1)?.role === role) anthropic.at(-1).content.push(...parts);
|
|
69
|
+
else anthropic.push({ role, content: parts });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (profile.api === 'responses') return { ...common, input, ...(system ? { instructions: system } : {}), max_output_tokens: budget, store: false, include: ['reasoning.encrypted_content'], ...(tools.length ? { tools: tools.map(t => ({ type: 'function', ...t })) } : {}) };
|
|
73
|
+
// Native parallel tool results arrive as separate messages. After merging
|
|
74
|
+
// their user turns, all results must precede accompanying text and screenshots.
|
|
75
|
+
for (const message of anthropic) if (message.role === 'user') {
|
|
76
|
+
message.content = [...message.content.filter(p => p.type === 'tool_result'), ...message.content.filter(p => p.type !== 'tool_result')];
|
|
77
|
+
}
|
|
78
|
+
return { ...common, messages: anthropic, ...(system ? { system } : {}), max_tokens: budget, ...(tools.length ? { tools: tools.map(t => ({ name: t.name, description: t.description, input_schema: t.parameters })) } : {}), ...(options.stop ? { stop_sequences: options.stop } : {}) };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const delta = (value, extra = {}) => JSON.stringify({ choices: [{ index: 0, delta: value }], ...extra });
|
|
82
|
+
const toolDelta = (index, id, name, args = '') => delta({ tool_calls: [{ index, ...(id ? { id } : {}), function: { ...(name ? { name } : {}), arguments: args } }] });
|
|
83
|
+
function responseUsage(u) {
|
|
84
|
+
return u && { prompt_tokens: u.input_tokens, completion_tokens: u.output_tokens, prompt_tokens_details: { cached_tokens: u.input_tokens_details?.cached_tokens ?? 0 }, completion_tokens_details: { reasoning_tokens: u.output_tokens_details?.reasoning_tokens ?? 0 } };
|
|
85
|
+
}
|
|
86
|
+
function anthropicUsage(u) {
|
|
87
|
+
return { prompt_tokens: (u.input_tokens ?? 0) + (u.cache_read_input_tokens ?? 0) + (u.cache_creation_input_tokens ?? 0), completion_tokens: u.output_tokens ?? 0,
|
|
88
|
+
prompt_tokens_details: { cached_tokens: u.cache_read_input_tokens ?? 0, cache_write_tokens: u.cache_creation_input_tokens ?? 0 } };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Normalize the two event protocols to the shared chat stream assembler. */
|
|
92
|
+
export async function* normalizedEvents(payloads, api, replay) {
|
|
93
|
+
if (api === 'chat-completions') { yield* payloads; return; }
|
|
94
|
+
let usage = {}, finish = 'stop';
|
|
95
|
+
const blocks = new Map(), emitted = new Set(), native = new Map();
|
|
96
|
+
for await (const raw of payloads) {
|
|
97
|
+
if (raw === '[DONE]') continue;
|
|
98
|
+
let event;
|
|
99
|
+
try { event = JSON.parse(raw); } catch { throw new LlmError('Malformed custom API stream event', 'MALFORMED_RESPONSE'); }
|
|
100
|
+
if (event.error || event.type === 'error' || event.type === 'response.failed') {
|
|
101
|
+
const error = event.error ?? event.response?.error;
|
|
102
|
+
throw new LlmError('Custom API returned an error during streaming', errorCode(undefined, { ...error, metadata: { error_type: error?.code ?? error?.type } }));
|
|
103
|
+
}
|
|
104
|
+
if (event.type === 'response.refusal.delta') throw new LlmError('Custom model declined this request', 'CONTENT_FILTER');
|
|
105
|
+
if (api === 'responses') {
|
|
106
|
+
const i = event.output_index ?? 0;
|
|
107
|
+
if (event.type === 'response.output_item.added') {
|
|
108
|
+
blocks.set(i, event.item);
|
|
109
|
+
if (event.item?.type === 'function_call') yield toolDelta(i, event.item.call_id, event.item.name);
|
|
110
|
+
} else if (event.type === 'response.output_text.delta') {
|
|
111
|
+
emitted.add(`text:${i}`); yield delta({ content: event.delta });
|
|
112
|
+
} else if (event.type === 'response.reasoning_summary_text.delta' || event.type === 'response.reasoning_text.delta') {
|
|
113
|
+
emitted.add(`reasoning:${i}`); yield delta({ reasoning_content: event.delta });
|
|
114
|
+
} else if (event.type === 'response.function_call_arguments.delta') {
|
|
115
|
+
emitted.add(`args:${i}`); yield toolDelta(i, undefined, undefined, event.delta);
|
|
116
|
+
} else if (event.type === 'response.output_item.done') {
|
|
117
|
+
blocks.set(i, event.item);
|
|
118
|
+
if (event.item?.type === 'reasoning') native.set(i, event.item);
|
|
119
|
+
}
|
|
120
|
+
if (['response.completed', 'response.incomplete'].includes(event.type)) {
|
|
121
|
+
const response = event.response;
|
|
122
|
+
if (!response || response.status === 'failed') throw new LlmError('Custom response failed', 'TRANSPORT');
|
|
123
|
+
const items = response.output ?? [...blocks.values()];
|
|
124
|
+
for (const [index, item] of items.entries()) {
|
|
125
|
+
if (item.type === 'function_call' && !emitted.has(`args:${index}`)) yield toolDelta(index, item.call_id, item.name, item.arguments ?? '{}');
|
|
126
|
+
if (item.type === 'message' && !emitted.has(`text:${index}`)) {
|
|
127
|
+
const text = (item.content ?? []).map(b => b.text ?? '').join('');
|
|
128
|
+
if (text) yield delta({ content: text });
|
|
129
|
+
}
|
|
130
|
+
if (item.type === 'reasoning') {
|
|
131
|
+
native.set(index, item);
|
|
132
|
+
if (!emitted.has(`reasoning:${index}`)) {
|
|
133
|
+
const text = (item.summary ?? []).map(b => b.text ?? '').join('');
|
|
134
|
+
if (text) yield delta({ reasoning_content: text });
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
replay.nativeReasoning = [...native.values()];
|
|
139
|
+
const incomplete = response.incomplete_details?.reason;
|
|
140
|
+
finish = event.type === 'response.incomplete' ? incomplete === 'max_output_tokens' ? 'length' : 'content_filter' : 'stop';
|
|
141
|
+
yield JSON.stringify({ id: response.id, choices: [{ delta: {}, finish_reason: finish }], usage: responseUsage(response.usage) });
|
|
142
|
+
yield '[DONE]'; return;
|
|
143
|
+
}
|
|
144
|
+
} else {
|
|
145
|
+
if (event.type === 'message_start') { usage = { ...event.message?.usage }; yield delta({}, { id: event.message?.id }); }
|
|
146
|
+
if (event.type === 'content_block_start') {
|
|
147
|
+
const b = { ...event.content_block }; blocks.set(event.index, b);
|
|
148
|
+
if (b.type === 'tool_use') yield toolDelta(event.index, b.id, b.name);
|
|
149
|
+
if (b.type === 'text' && b.text) yield delta({ content: b.text });
|
|
150
|
+
if (b.type === 'thinking' || b.type === 'redacted_thinking') {
|
|
151
|
+
native.set(event.index, b);
|
|
152
|
+
if (b.thinking) yield delta({ reasoning_content: b.thinking });
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (event.type === 'content_block_delta') {
|
|
156
|
+
const d = event.delta, b = blocks.get(event.index);
|
|
157
|
+
if (d.type === 'text_delta') yield delta({ content: d.text });
|
|
158
|
+
if (d.type === 'input_json_delta') { emitted.add(`args:${event.index}`); yield toolDelta(event.index, undefined, undefined, d.partial_json); }
|
|
159
|
+
if (d.type === 'thinking_delta') { if (b) b.thinking = (b.thinking ?? '') + d.thinking; yield delta({ reasoning_content: d.thinking }); }
|
|
160
|
+
if (d.type === 'signature_delta' && b) b.signature = (b.signature ?? '') + d.signature;
|
|
161
|
+
}
|
|
162
|
+
if (event.type === 'content_block_stop') {
|
|
163
|
+
const b = blocks.get(event.index);
|
|
164
|
+
if (b?.type === 'tool_use' && !emitted.has(`args:${event.index}`)) yield toolDelta(event.index, undefined, undefined, JSON.stringify(b.input ?? {}));
|
|
165
|
+
}
|
|
166
|
+
if (event.type === 'message_delta') {
|
|
167
|
+
usage = { ...usage, ...event.usage };
|
|
168
|
+
const reason = event.delta?.stop_reason;
|
|
169
|
+
finish = reason === 'max_tokens' ? 'length' : reason === 'tool_use' ? 'tool_calls' : ['end_turn', 'stop_sequence', null, undefined].includes(reason) ? 'stop' : reason;
|
|
170
|
+
}
|
|
171
|
+
if (event.type === 'message_stop') {
|
|
172
|
+
replay.nativeReasoning = [...native.values()];
|
|
173
|
+
yield JSON.stringify({ choices: [{ delta: {}, finish_reason: finish }], usage: anthropicUsage(usage) });
|
|
174
|
+
yield '[DONE]'; return;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
throw new LlmError('Custom API stream ended before its terminal event', 'TRANSPORT');
|
|
179
|
+
}
|