@cjhyy/code-shell-core 0.5.0-rc.2 → 0.6.0-rc.1
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 +13 -10
- package/dist/agent/agent-definition-registry.d.ts +3 -0
- package/dist/agent/agent-definition-registry.js +3 -1
- package/dist/agent/agent-definition.d.ts +15 -0
- package/dist/agent/agent-definition.js +27 -3
- package/dist/arena/context/context-tools.js +47 -4
- package/dist/arena/ledger.js +9 -1
- package/dist/arena/strategies/utils.d.ts +1 -4
- package/dist/arena/strategies/utils.js +7 -84
- package/dist/automation/cron-expr.d.ts +10 -0
- package/dist/automation/cron-expr.js +23 -5
- package/dist/automation/runner.d.ts +21 -4
- package/dist/automation/runner.js +48 -12
- package/dist/automation/scheduler.d.ts +38 -0
- package/dist/automation/scheduler.js +89 -12
- package/dist/automation/store.js +5 -2
- package/dist/capability-control/disabled-lists.d.ts +25 -0
- package/dist/capability-control/disabled-lists.js +57 -0
- package/dist/capability-control/overlay.d.ts +15 -0
- package/dist/capability-control/overlay.js +27 -0
- package/dist/cc-orchestrator/agent-adapter.d.ts +50 -0
- package/dist/cc-orchestrator/agent-adapter.js +133 -0
- package/dist/cc-orchestrator/cc-capability.d.ts +19 -0
- package/dist/cc-orchestrator/cc-capability.js +53 -0
- package/dist/cc-orchestrator/codex-session-discovery.d.ts +24 -0
- package/dist/cc-orchestrator/codex-session-discovery.js +191 -0
- package/dist/cc-orchestrator/codex-session-history.d.ts +25 -0
- package/dist/cc-orchestrator/codex-session-history.js +187 -0
- package/dist/cc-orchestrator/external-agent-changes.d.ts +19 -0
- package/dist/cc-orchestrator/external-agent-changes.js +214 -0
- package/dist/cc-orchestrator/external-agent-driver.d.ts +18 -0
- package/dist/cc-orchestrator/external-agent-driver.js +69 -0
- package/dist/cc-orchestrator/index.d.ts +8 -0
- package/dist/cc-orchestrator/index.js +8 -0
- package/dist/cc-orchestrator/relevance-judge.d.ts +15 -0
- package/dist/cc-orchestrator/relevance-judge.js +29 -0
- package/dist/cc-orchestrator/session-discovery.d.ts +46 -0
- package/dist/cc-orchestrator/session-discovery.js +125 -0
- package/dist/cc-orchestrator/session-history.d.ts +19 -0
- package/dist/cc-orchestrator/session-history.js +67 -0
- package/dist/cli/agent-server-stdio.d.ts +15 -1
- package/dist/cli/agent-server-stdio.js +115 -17
- package/dist/cli/agent-server-tcp.js +40 -26
- package/dist/context/compaction.d.ts +56 -0
- package/dist/context/compaction.js +186 -0
- package/dist/context/manager.js +25 -4
- package/dist/cost-tracker.js +5 -61
- package/dist/credentials/cipher.d.ts +49 -0
- package/dist/credentials/cipher.js +45 -0
- package/dist/credentials/cookie-jar.d.ts +24 -0
- package/dist/credentials/cookie-jar.js +40 -0
- package/dist/credentials/index.d.ts +7 -0
- package/dist/credentials/index.js +5 -0
- package/dist/credentials/inject-credential-tool.d.ts +20 -0
- package/dist/credentials/inject-credential-tool.js +130 -0
- package/dist/credentials/store.d.ts +72 -0
- package/dist/credentials/store.js +184 -0
- package/dist/credentials/types.d.ts +56 -0
- package/dist/credentials/use-credential-tool.d.ts +29 -0
- package/dist/credentials/use-credential-tool.js +205 -0
- package/dist/credentials/use-gate.d.ts +56 -0
- package/dist/credentials/use-gate.js +52 -0
- package/dist/data/model-metadata.d.ts +77 -0
- package/dist/data/model-metadata.js +56 -0
- package/dist/data/model-metadata.json +216 -0
- package/dist/data/openrouter-models.d.ts +18 -7
- package/dist/data/openrouter-models.js +35 -8
- package/dist/engine/aux-key.d.ts +10 -0
- package/dist/engine/aux-key.js +11 -0
- package/dist/engine/dynamic-tool-defs.d.ts +19 -0
- package/dist/engine/dynamic-tool-defs.js +36 -0
- package/dist/engine/engine.d.ts +267 -138
- package/dist/engine/engine.js +957 -191
- package/dist/engine/friendly-error.d.ts +18 -0
- package/dist/engine/friendly-error.js +63 -0
- package/dist/engine/goal.d.ts +145 -0
- package/dist/engine/goal.js +144 -0
- package/dist/engine/image-policy.d.ts +13 -0
- package/dist/engine/image-policy.js +24 -0
- package/dist/engine/model-connections-pool.d.ts +17 -0
- package/dist/engine/model-connections-pool.js +66 -0
- package/dist/engine/model-facade.d.ts +10 -0
- package/dist/engine/model-facade.js +25 -0
- package/dist/engine/patch-orphaned-tools.js +3 -0
- package/dist/engine/resolve-llm-config.d.ts +16 -0
- package/dist/engine/resolve-llm-config.js +44 -0
- package/dist/engine/runtime.js +2 -1
- package/dist/engine/sandbox-cache-key.d.ts +10 -0
- package/dist/engine/sandbox-cache-key.js +9 -0
- package/dist/engine/sandbox-config.d.ts +31 -0
- package/dist/engine/sandbox-config.js +38 -0
- package/dist/engine/session-usage.d.ts +19 -0
- package/dist/engine/session-usage.js +25 -0
- package/dist/engine/steer-queue.d.ts +32 -0
- package/dist/engine/steer-queue.js +26 -0
- package/dist/engine/streaming-tool-queue.d.ts +12 -0
- package/dist/engine/streaming-tool-queue.js +50 -10
- package/dist/engine/turn-loop.d.ts +67 -3
- package/dist/engine/turn-loop.js +292 -41
- package/dist/engine/types.d.ts +175 -0
- package/dist/engine/types.js +13 -0
- package/dist/external-agents/config.d.ts +2 -0
- package/dist/external-agents/config.js +15 -0
- package/dist/external-agents/types.d.ts +31 -0
- package/dist/external-agents/types.js +1 -0
- package/dist/git/utils.js +11 -6
- package/dist/git/worktree.d.ts +48 -0
- package/dist/git/worktree.js +86 -10
- package/dist/hooks/goal-stop-hook.d.ts +28 -0
- package/dist/hooks/goal-stop-hook.js +186 -9
- package/dist/hooks/registry.d.ts +8 -0
- package/dist/hooks/registry.js +19 -0
- package/dist/hooks/shell-runner.js +10 -21
- package/dist/index.d.ts +49 -6
- package/dist/index.js +60 -4
- package/dist/llm/capabilities/param-specs.d.ts +14 -0
- package/dist/llm/capabilities/param-specs.js +62 -0
- package/dist/llm/capabilities/rules.js +4 -0
- package/dist/llm/capabilities/types.d.ts +10 -0
- package/dist/llm/client-base.d.ts +28 -1
- package/dist/llm/client-base.js +119 -13
- package/dist/llm/model-cache.js +4 -2
- package/dist/llm/model-pool.d.ts +14 -0
- package/dist/llm/model-pool.js +13 -0
- package/dist/llm/provider-auth.d.ts +41 -0
- package/dist/llm/provider-auth.js +76 -0
- package/dist/llm/provider-catalog.d.ts +4 -0
- package/dist/llm/providers/anthropic.js +64 -14
- package/dist/llm/providers/openai.d.ts +36 -0
- package/dist/llm/providers/openai.js +257 -51
- package/dist/llm/reasoning-setting.d.ts +3 -3
- package/dist/llm/reasoning-setting.js +9 -1
- package/dist/llm/stream-watchdog.js +5 -1
- package/dist/llm/token-counter.js +9 -2
- package/dist/llm/types.d.ts +4 -0
- package/dist/logging/sanitize-messages.js +22 -0
- package/dist/lsp/manager.d.ts +1 -1
- package/dist/lsp/manager.js +40 -10
- package/dist/model-catalog/builtin.d.ts +12 -0
- package/dist/model-catalog/builtin.js +407 -0
- package/dist/model-catalog/gen-connections.d.ts +20 -0
- package/dist/model-catalog/gen-connections.js +28 -0
- package/dist/model-catalog/index.d.ts +41 -0
- package/dist/model-catalog/index.js +90 -0
- package/dist/model-catalog/params.d.ts +20 -0
- package/dist/model-catalog/params.js +45 -0
- package/dist/model-catalog/resolve.d.ts +48 -0
- package/dist/model-catalog/resolve.js +33 -0
- package/dist/model-catalog/save-entry.d.ts +32 -0
- package/dist/model-catalog/save-entry.js +104 -0
- package/dist/model-catalog/types.d.ts +561 -0
- package/dist/model-catalog/types.js +93 -0
- package/dist/model-catalog/upsert.d.ts +9 -0
- package/dist/model-catalog/upsert.js +8 -0
- package/dist/onboarding.d.ts +12 -82
- package/dist/onboarding.js +61 -326
- package/dist/plugins/gitOps.d.ts +19 -0
- package/dist/plugins/gitOps.js +73 -4
- package/dist/plugins/installer/checkUpdate.d.ts +16 -0
- package/dist/plugins/installer/checkUpdate.js +32 -0
- package/dist/plugins/installer/codex/convertCommands.d.ts +19 -0
- package/dist/plugins/installer/codex/convertCommands.js +46 -0
- package/dist/plugins/installer/codex/convertMcp.d.ts +5 -2
- package/dist/plugins/installer/codex/convertMcp.js +45 -5
- package/dist/plugins/installer/install.js +25 -1
- package/dist/plugins/installer/installFromArchive.d.ts +43 -0
- package/dist/plugins/installer/installFromArchive.js +134 -0
- package/dist/plugins/installer/installFromSource.js +8 -2
- package/dist/plugins/installer/loadPluginAgents.js +6 -2
- package/dist/plugins/installer/loadPluginMcp.d.ts +9 -2
- package/dist/plugins/installer/loadPluginMcp.js +35 -2
- package/dist/plugins/installer/pruneDisabled.d.ts +24 -0
- package/dist/plugins/installer/pruneDisabled.js +73 -0
- package/dist/plugins/installer/types.d.ts +5 -2
- package/dist/plugins/installer/types.js +1 -0
- package/dist/plugins/installer/uninstall.js +4 -0
- package/dist/plugins/installer/unzip.d.ts +14 -0
- package/dist/plugins/installer/unzip.js +82 -0
- package/dist/plugins/installer/update.d.ts +14 -0
- package/dist/plugins/installer/update.js +53 -21
- package/dist/plugins/loadPluginHooks.d.ts +47 -1
- package/dist/plugins/loadPluginHooks.js +73 -1
- package/dist/plugins/marketplaceManager.d.ts +7 -0
- package/dist/plugins/marketplaceManager.js +20 -0
- package/dist/plugins/pluginCommandHook.js +4 -18
- package/dist/plugins/pluginContent.d.ts +30 -0
- package/dist/plugins/pluginContent.js +83 -0
- package/dist/plugins/pluginInstaller.d.ts +13 -0
- package/dist/plugins/pluginInstaller.js +42 -8
- package/dist/plugins/schemas.js +1 -0
- package/dist/plugins/types.d.ts +6 -0
- package/dist/preset/index.d.ts +7 -1
- package/dist/preset/index.js +96 -6
- package/dist/product/types.d.ts +1 -1
- package/dist/prompt/composer.d.ts +27 -0
- package/dist/prompt/composer.js +67 -21
- package/dist/prompt/instruction-scanner.js +5 -3
- package/dist/prompt/section-loader.js +1 -0
- package/dist/prompt/sections/base.md +1 -0
- package/dist/prompt/sections/browser.md +10 -0
- package/dist/prompt/sections/coding.md +4 -0
- package/dist/protocol/chat-session-manager.d.ts +8 -2
- package/dist/protocol/chat-session-manager.js +36 -0
- package/dist/protocol/chat-session.d.ts +65 -0
- package/dist/protocol/chat-session.js +94 -2
- package/dist/protocol/client.d.ts +27 -0
- package/dist/protocol/client.js +38 -0
- package/dist/protocol/server.d.ts +112 -0
- package/dist/protocol/server.js +586 -16
- package/dist/protocol/transport.js +3 -2
- package/dist/protocol/types.d.ts +46 -0
- package/dist/protocol/types.js +16 -0
- package/dist/quota/credentials.d.ts +3 -0
- package/dist/quota/credentials.js +80 -0
- package/dist/quota/index.d.ts +36 -0
- package/dist/quota/index.js +155 -0
- package/dist/quota/types.d.ts +48 -0
- package/dist/quota/types.js +13 -0
- package/dist/review/review-prompt.d.ts +28 -0
- package/dist/review/review-prompt.js +81 -0
- package/dist/run/FileRunStore.js +8 -3
- package/dist/run/RunApprovalBackend.js +25 -5
- package/dist/run/RunManager.d.ts +12 -0
- package/dist/run/RunManager.js +35 -0
- package/dist/run/factory.d.ts +1 -1
- package/dist/runtime/background-shell.d.ts +139 -0
- package/dist/runtime/background-shell.js +495 -0
- package/dist/runtime/output-clean.d.ts +24 -0
- package/dist/runtime/output-clean.js +41 -0
- package/dist/runtime/ring-file.d.ts +64 -0
- package/dist/runtime/ring-file.js +174 -0
- package/dist/runtime/safe-spawn.js +15 -34
- package/dist/runtime/spawn-common.d.ts +148 -0
- package/dist/runtime/spawn-common.js +303 -0
- package/dist/runtime/truncate-output.d.ts +22 -0
- package/dist/runtime/truncate-output.js +49 -0
- package/dist/runtime/utf8-cut.d.ts +11 -0
- package/dist/runtime/utf8-cut.js +23 -0
- package/dist/services/auto-dream.d.ts +4 -0
- package/dist/services/auto-dream.js +26 -26
- package/dist/services/diagnostics.d.ts +1 -2
- package/dist/services/diagnostics.js +12 -7
- package/dist/services/extract-memories.d.ts +14 -1
- package/dist/services/extract-memories.js +45 -6
- package/dist/services/memory-orchestrator.d.ts +21 -0
- package/dist/services/memory-orchestrator.js +125 -50
- package/dist/services/session-memory.js +24 -12
- package/dist/session/file-history.d.ts +124 -1
- package/dist/session/file-history.js +222 -6
- package/dist/session/memory.d.ts +116 -2
- package/dist/session/memory.js +250 -28
- package/dist/session/session-manager.d.ts +40 -0
- package/dist/session/session-manager.js +113 -3
- package/dist/session/simple-diff.d.ts +23 -0
- package/dist/session/simple-diff.js +84 -0
- package/dist/session/transcript.d.ts +25 -1
- package/dist/session/transcript.js +35 -2
- package/dist/session/undo-target.d.ts +67 -0
- package/dist/session/undo-target.js +144 -0
- package/dist/settings/disk-defaults.d.ts +9 -2
- package/dist/settings/disk-defaults.js +11 -2
- package/dist/settings/feature-flags.d.ts +64 -0
- package/dist/settings/feature-flags.js +61 -0
- package/dist/settings/manager.d.ts +68 -1
- package/dist/settings/manager.js +266 -29
- package/dist/settings/migrate-config.d.ts +45 -0
- package/dist/settings/migrate-config.js +125 -0
- package/dist/settings/schema-export.d.ts +25 -0
- package/dist/settings/schema-export.js +38 -0
- package/dist/settings/schema.d.ts +1186 -771
- package/dist/settings/schema.js +268 -97
- package/dist/skills/scanner.d.ts +9 -0
- package/dist/skills/scanner.js +30 -2
- package/dist/stt/resolve-transcribe.d.ts +31 -0
- package/dist/stt/resolve-transcribe.js +108 -0
- package/dist/stt/transcribe.d.ts +51 -0
- package/dist/stt/transcribe.js +65 -0
- package/dist/tool-system/browser-bridge.d.ts +226 -0
- package/dist/tool-system/browser-bridge.js +163 -0
- package/dist/tool-system/builtin/agent-heartbeat.d.ts +49 -0
- package/dist/tool-system/builtin/agent-heartbeat.js +89 -0
- package/dist/tool-system/builtin/agent-notifications.d.ts +12 -3
- package/dist/tool-system/builtin/agent-notifications.js +9 -3
- package/dist/tool-system/builtin/agent-output-file.d.ts +38 -0
- package/dist/tool-system/builtin/agent-output-file.js +72 -0
- package/dist/tool-system/builtin/agent-registry.d.ts +12 -0
- package/dist/tool-system/builtin/agent-registry.js +8 -0
- package/dist/tool-system/builtin/agent.d.ts +21 -1
- package/dist/tool-system/builtin/agent.js +489 -42
- package/dist/tool-system/builtin/apply-patch/applier.js +66 -8
- package/dist/tool-system/builtin/apply-patch/backup-targets.d.ts +10 -0
- package/dist/tool-system/builtin/apply-patch/backup-targets.js +30 -0
- package/dist/tool-system/builtin/apply-patch/index.js +0 -15
- package/dist/tool-system/builtin/background-jobs.d.ts +76 -0
- package/dist/tool-system/builtin/background-jobs.js +124 -0
- package/dist/tool-system/builtin/background-shell-tools.d.ts +20 -0
- package/dist/tool-system/builtin/background-shell-tools.js +108 -0
- package/dist/tool-system/builtin/background-work.d.ts +67 -0
- package/dist/tool-system/builtin/background-work.js +86 -0
- package/dist/tool-system/builtin/bash-output-style.d.ts +32 -0
- package/dist/tool-system/builtin/bash-output-style.js +40 -0
- package/dist/tool-system/builtin/bash.d.ts +5 -2
- package/dist/tool-system/builtin/bash.js +98 -62
- package/dist/tool-system/builtin/browser-tools.d.ts +33 -0
- package/dist/tool-system/builtin/browser-tools.js +312 -0
- package/dist/tool-system/builtin/cancel-goal.d.ts +31 -0
- package/dist/tool-system/builtin/cancel-goal.js +64 -0
- package/dist/tool-system/builtin/check-quota.d.ts +15 -0
- package/dist/tool-system/builtin/check-quota.js +34 -0
- package/dist/tool-system/builtin/config.js +7 -0
- package/dist/tool-system/builtin/cron.d.ts +7 -0
- package/dist/tool-system/builtin/cron.js +55 -3
- package/dist/tool-system/builtin/drive-claude-code.d.ts +30 -0
- package/dist/tool-system/builtin/drive-claude-code.js +157 -0
- package/dist/tool-system/builtin/edit-model-catalog.d.ts +3 -0
- package/dist/tool-system/builtin/edit-model-catalog.js +94 -0
- package/dist/tool-system/builtin/edit.js +20 -16
- package/dist/tool-system/builtin/eol.d.ts +29 -0
- package/dist/tool-system/builtin/eol.js +37 -0
- package/dist/tool-system/builtin/file-cache.d.ts +6 -0
- package/dist/tool-system/builtin/file-cache.js +8 -0
- package/dist/tool-system/builtin/generate-image.d.ts +35 -0
- package/dist/tool-system/builtin/generate-image.js +278 -50
- package/dist/tool-system/builtin/generate-video.d.ts +55 -0
- package/dist/tool-system/builtin/generate-video.js +361 -0
- package/dist/tool-system/builtin/glob.js +0 -7
- package/dist/tool-system/builtin/grep.js +6 -8
- package/dist/tool-system/builtin/image-providers.d.ts +86 -0
- package/dist/tool-system/builtin/image-providers.js +190 -0
- package/dist/tool-system/builtin/image-uploader.d.ts +33 -0
- package/dist/tool-system/builtin/image-uploader.js +74 -0
- package/dist/tool-system/builtin/index.d.ts +7 -1
- package/dist/tool-system/builtin/index.js +249 -25
- package/dist/tool-system/builtin/mcp-tools.js +23 -3
- package/dist/tool-system/builtin/memory.js +45 -7
- package/dist/tool-system/builtin/notebook-edit.js +0 -7
- package/dist/tool-system/builtin/powershell.js +4 -1
- package/dist/tool-system/builtin/read.js +10 -10
- package/dist/tool-system/builtin/repl.js +4 -1
- package/dist/tool-system/builtin/skill.js +9 -0
- package/dist/tool-system/builtin/sleep.js +3 -2
- package/dist/tool-system/builtin/tool-search.js +25 -7
- package/dist/tool-system/builtin/video-providers.d.ts +154 -0
- package/dist/tool-system/builtin/video-providers.js +235 -0
- package/dist/tool-system/builtin/web-fetch.js +12 -2
- package/dist/tool-system/builtin/web-search.js +21 -7
- package/dist/tool-system/builtin/worktree.d.ts +2 -1
- package/dist/tool-system/builtin/worktree.js +31 -4
- package/dist/tool-system/builtin/write.js +0 -6
- package/dist/tool-system/context.d.ts +154 -6
- package/dist/tool-system/executor.d.ts +3 -1
- package/dist/tool-system/executor.js +172 -88
- package/dist/tool-system/investigation-guard.js +1 -1
- package/dist/tool-system/mcp-manager.d.ts +42 -4
- package/dist/tool-system/mcp-manager.js +186 -20
- package/dist/tool-system/path-policy.d.ts +5 -0
- package/dist/tool-system/path-policy.js +307 -8
- package/dist/tool-system/permission.d.ts +36 -1
- package/dist/tool-system/permission.js +281 -69
- package/dist/tool-system/plan-mode-allowlist.d.ts +13 -2
- package/dist/tool-system/plan-mode-allowlist.js +24 -2
- package/dist/tool-system/registry.d.ts +1 -0
- package/dist/tool-system/registry.js +16 -2
- package/dist/tool-system/sandbox/index.d.ts +8 -0
- package/dist/tool-system/sandbox/index.js +7 -2
- package/dist/tool-system/validate-tool-metadata.d.ts +36 -0
- package/dist/tool-system/validate-tool-metadata.js +63 -0
- package/dist/types.d.ts +217 -6
- package/dist/updater.js +20 -9
- package/dist/utils/envUtils.d.ts +0 -9
- package/dist/utils/envUtils.js +3 -28
- package/dist/utils/exec.d.ts +40 -0
- package/dist/utils/exec.js +144 -0
- package/dist/utils/json.d.ts +12 -0
- package/dist/utils/json.js +92 -0
- package/dist/utils/theme.d.ts +1 -1
- package/dist/utils/theme.js +1 -1
- package/dist/utils/toolDisplay.js +0 -1
- package/package.json +13 -7
- package/dist/agent/coordinator.d.ts +0 -49
- package/dist/agent/coordinator.js +0 -77
- package/dist/settings/manager.test.js +0 -73
- package/dist/tool-system/builtin/remote-trigger.d.ts +0 -6
- package/dist/tool-system/builtin/remote-trigger.js +0 -54
- package/dist/tool-system/builtin/send-message.d.ts +0 -6
- package/dist/tool-system/builtin/send-message.js +0 -47
- /package/dist/{settings/manager.test.d.ts → credentials/types.js} +0 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ImageProvider — adapter interface for text-to-image generation (TODO 7.1).
|
|
3
|
+
*
|
|
4
|
+
* Lifts the hardcoded OpenAI `gpt-image-2` call out of generate-image.ts so
|
|
5
|
+
* GenerateImage can target multiple providers (OpenAI now; Gemini next) and
|
|
6
|
+
* take an optional provider/model. Each adapter takes resolved credentials +
|
|
7
|
+
* the request and returns a base64 PNG (or an error string). The tool layer
|
|
8
|
+
* owns credential resolution from settings, file writing, and user-facing
|
|
9
|
+
* formatting — adapters are pure "creds + prompt → bytes".
|
|
10
|
+
*
|
|
11
|
+
* `fetch` is injected so adapters are unit-testable without network. Production
|
|
12
|
+
* call sites pass the global `fetch`.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* OpenAI Images API adapter (`/images/generations`, b64_json). Identical wire
|
|
16
|
+
* behavior to the pre-refactor generate-image.ts: POST model/prompt/size/
|
|
17
|
+
* quality/n, read data[0].b64_json.
|
|
18
|
+
*/
|
|
19
|
+
export class OpenAIImageProvider {
|
|
20
|
+
fetchImpl;
|
|
21
|
+
kind = "openai";
|
|
22
|
+
constructor(fetchImpl = fetch) {
|
|
23
|
+
this.fetchImpl = fetchImpl;
|
|
24
|
+
}
|
|
25
|
+
async generate(req) {
|
|
26
|
+
// Trim a trailing slash so `${baseUrl}/images/...` doesn't double up.
|
|
27
|
+
const baseUrl = req.creds.baseUrl.replace(/\/+$/, "");
|
|
28
|
+
const hasInputs = !!req.inputImages && req.inputImages.length > 0;
|
|
29
|
+
let resp;
|
|
30
|
+
try {
|
|
31
|
+
if (hasInputs) {
|
|
32
|
+
// Image-to-image → the EDITS endpoint, which takes multipart/form-data
|
|
33
|
+
// with one or more `image[]` parts (gpt-image accepts up to 16). Do NOT
|
|
34
|
+
// set Content-Type manually — fetch sets the multipart boundary.
|
|
35
|
+
const form = new FormData();
|
|
36
|
+
form.append("model", req.model);
|
|
37
|
+
form.append("prompt", req.prompt);
|
|
38
|
+
if (req.size && req.size !== "auto")
|
|
39
|
+
form.append("size", req.size);
|
|
40
|
+
if (req.quality && req.quality !== "auto")
|
|
41
|
+
form.append("quality", req.quality);
|
|
42
|
+
form.append("n", "1");
|
|
43
|
+
for (const img of req.inputImages) {
|
|
44
|
+
// Copy into a fresh Uint8Array so the Blob gets a clean ArrayBuffer
|
|
45
|
+
// (avoids SharedArrayBuffer / offset typing issues across runtimes).
|
|
46
|
+
const buf = Uint8Array.from(img.bytes);
|
|
47
|
+
form.append("image[]", new Blob([buf], { type: img.mimeType }), img.filename);
|
|
48
|
+
}
|
|
49
|
+
resp = await this.fetchImpl(`${baseUrl}/images/edits`, {
|
|
50
|
+
method: "POST",
|
|
51
|
+
headers: { Authorization: `Bearer ${req.creds.apiKey}` },
|
|
52
|
+
body: form,
|
|
53
|
+
signal: req.signal,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
resp = await this.fetchImpl(`${baseUrl}/images/generations`, {
|
|
58
|
+
method: "POST",
|
|
59
|
+
headers: {
|
|
60
|
+
Authorization: `Bearer ${req.creds.apiKey}`,
|
|
61
|
+
"Content-Type": "application/json",
|
|
62
|
+
},
|
|
63
|
+
body: JSON.stringify({
|
|
64
|
+
model: req.model,
|
|
65
|
+
prompt: req.prompt,
|
|
66
|
+
size: req.size,
|
|
67
|
+
quality: req.quality,
|
|
68
|
+
n: 1,
|
|
69
|
+
}),
|
|
70
|
+
signal: req.signal,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
catch (err) {
|
|
75
|
+
return { ok: false, error: `request failed: ${err.message}` };
|
|
76
|
+
}
|
|
77
|
+
if (!resp.ok) {
|
|
78
|
+
const body = (await resp.text().catch(() => "")).slice(0, 500);
|
|
79
|
+
return { ok: false, error: `image API returned ${resp.status}: ${body}` };
|
|
80
|
+
}
|
|
81
|
+
let json;
|
|
82
|
+
try {
|
|
83
|
+
json = await resp.json();
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
return { ok: false, error: `could not parse image API response: ${err.message}` };
|
|
87
|
+
}
|
|
88
|
+
const b64 = json?.data?.[0]?.b64_json;
|
|
89
|
+
if (typeof b64 !== "string" || !b64) {
|
|
90
|
+
const preview = JSON.stringify(json).slice(0, 500);
|
|
91
|
+
return { ok: false, error: `no image in response: ${preview}` };
|
|
92
|
+
}
|
|
93
|
+
return { ok: true, b64 };
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Gemini Images adapter — the `generateContent` endpoint
|
|
98
|
+
* (`/models/{model}:generateContent`), API key in the `x-goog-api-key`
|
|
99
|
+
* header, prompt as a text content-part, PNG returned base64 in
|
|
100
|
+
* `candidates[].content.parts[].inline_data.data` (REST may camelCase it to
|
|
101
|
+
* `inlineData`; we read both). Wire shape per ai.google.dev image-generation
|
|
102
|
+
* docs. The OpenAI-style `size`/`quality` args don't map 1:1 to Gemini's
|
|
103
|
+
* aspectRatio/imageSize, so we only forward the prompt + IMAGE modality and
|
|
104
|
+
* leave Gemini's own defaults for dimensions (a later pass can map size →
|
|
105
|
+
* aspectRatio if needed).
|
|
106
|
+
*/
|
|
107
|
+
export class GeminiImageProvider {
|
|
108
|
+
fetchImpl;
|
|
109
|
+
kind = "google";
|
|
110
|
+
constructor(fetchImpl = fetch) {
|
|
111
|
+
this.fetchImpl = fetchImpl;
|
|
112
|
+
}
|
|
113
|
+
async generate(req) {
|
|
114
|
+
// Image generation uses the NATIVE Gemini REST path
|
|
115
|
+
// (`{base}/models/{model}:generateContent`). A provider configured for
|
|
116
|
+
// Gemini's OpenAI-compatibility layer carries a `…/openai` baseUrl (fine
|
|
117
|
+
// for chat) — strip that suffix so images hit the native endpoint without
|
|
118
|
+
// the user needing a second provider entry. A native `…/v1beta` baseUrl is
|
|
119
|
+
// left untouched.
|
|
120
|
+
const baseUrl = req.creds.baseUrl.replace(/\/+$/, "").replace(/\/openai$/, "");
|
|
121
|
+
let resp;
|
|
122
|
+
try {
|
|
123
|
+
// Image-to-image: Gemini conditions on input images passed as additional
|
|
124
|
+
// inline_data parts alongside the text prompt (base64, no data: prefix).
|
|
125
|
+
const parts = [{ text: req.prompt }];
|
|
126
|
+
for (const img of req.inputImages ?? []) {
|
|
127
|
+
parts.push({
|
|
128
|
+
inline_data: {
|
|
129
|
+
mime_type: img.mimeType,
|
|
130
|
+
data: Buffer.from(img.bytes).toString("base64"),
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
resp = await this.fetchImpl(`${baseUrl}/models/${req.model}:generateContent`, {
|
|
135
|
+
method: "POST",
|
|
136
|
+
headers: {
|
|
137
|
+
"x-goog-api-key": req.creds.apiKey,
|
|
138
|
+
"Content-Type": "application/json",
|
|
139
|
+
},
|
|
140
|
+
body: JSON.stringify({
|
|
141
|
+
contents: [{ parts }],
|
|
142
|
+
generationConfig: { responseModalities: ["TEXT", "IMAGE"] },
|
|
143
|
+
}),
|
|
144
|
+
signal: req.signal,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
catch (err) {
|
|
148
|
+
return { ok: false, error: `request failed: ${err.message}` };
|
|
149
|
+
}
|
|
150
|
+
if (!resp.ok) {
|
|
151
|
+
const body = (await resp.text().catch(() => "")).slice(0, 500);
|
|
152
|
+
return { ok: false, error: `image API returned ${resp.status}: ${body}` };
|
|
153
|
+
}
|
|
154
|
+
let json;
|
|
155
|
+
try {
|
|
156
|
+
json = await resp.json();
|
|
157
|
+
}
|
|
158
|
+
catch (err) {
|
|
159
|
+
return { ok: false, error: `could not parse image API response: ${err.message}` };
|
|
160
|
+
}
|
|
161
|
+
const parts = json
|
|
162
|
+
?.candidates?.[0]?.content?.parts ?? [];
|
|
163
|
+
for (const part of parts) {
|
|
164
|
+
// Accept both snake_case (inline_data) and camelCase (inlineData).
|
|
165
|
+
const inline = (part.inline_data ?? part.inlineData);
|
|
166
|
+
if (inline?.data)
|
|
167
|
+
return { ok: true, b64: inline.data };
|
|
168
|
+
}
|
|
169
|
+
const preview = JSON.stringify(json).slice(0, 500);
|
|
170
|
+
return { ok: false, error: `no image in response: ${preview}` };
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/** Default model per provider kind when the caller doesn't specify one. */
|
|
174
|
+
export const DEFAULT_IMAGE_MODEL = {
|
|
175
|
+
openai: "gpt-image-2",
|
|
176
|
+
// Nano Banana — the current recommended Gemini image model. Override per call
|
|
177
|
+
// via GenerateImage's `model` arg when a newer one (e.g. gemini-3.1-flash-image) is wanted.
|
|
178
|
+
google: "gemini-2.5-flash-image",
|
|
179
|
+
};
|
|
180
|
+
/** Registry of available image-provider adapters, keyed by `kind`. */
|
|
181
|
+
export function getImageProvider(kind, fetchImpl = fetch) {
|
|
182
|
+
switch (kind) {
|
|
183
|
+
case "openai":
|
|
184
|
+
return new OpenAIImageProvider(fetchImpl);
|
|
185
|
+
case "google":
|
|
186
|
+
return new GeminiImageProvider(fetchImpl);
|
|
187
|
+
default:
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface UploaderCreds {
|
|
2
|
+
baseUrl: string;
|
|
3
|
+
apiKey: string;
|
|
4
|
+
}
|
|
5
|
+
export type UploadResult = {
|
|
6
|
+
ok: true;
|
|
7
|
+
url: string;
|
|
8
|
+
} | {
|
|
9
|
+
ok: false;
|
|
10
|
+
error: string;
|
|
11
|
+
};
|
|
12
|
+
export interface ImageUploader {
|
|
13
|
+
readonly kind: string;
|
|
14
|
+
/** http/https → unchanged; local path → upload, return public URL. */
|
|
15
|
+
toUrl(pathOrUrl: string, creds: UploaderCreds, signal?: AbortSignal): Promise<UploadResult>;
|
|
16
|
+
}
|
|
17
|
+
export declare function isHttpUrl(s: string): boolean;
|
|
18
|
+
export declare class FalStorageUploader implements ImageUploader {
|
|
19
|
+
private readonly fetchImpl;
|
|
20
|
+
readonly kind = "fal";
|
|
21
|
+
private static readonly UPLOAD_BASE;
|
|
22
|
+
constructor(fetchImpl?: typeof fetch);
|
|
23
|
+
toUrl(pathOrUrl: string, creds: UploaderCreds, signal?: AbortSignal): Promise<UploadResult>;
|
|
24
|
+
/**
|
|
25
|
+
* Upload raw bytes to fal storage, return the public URL. Two-step flow
|
|
26
|
+
* (verified against live API 2026-06-10):
|
|
27
|
+
* 1. POST {UPLOAD_BASE}/storage/upload/initiate → { file_url, upload_url }
|
|
28
|
+
* 2. PUT <upload_url> with the bytes (signed URL, no Authorization)
|
|
29
|
+
* 3. file_url is the final public URL.
|
|
30
|
+
*/
|
|
31
|
+
private uploadBytes;
|
|
32
|
+
}
|
|
33
|
+
export declare function getImageUploader(kind: string, fetchImpl?: typeof fetch): ImageUploader | null;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ImageUploader — pluggable "local path → public URL" so image-to-video /
|
|
3
|
+
* reference-to-video can accept local files, not just URLs. fal storage is the
|
|
4
|
+
* first impl; swapping in another image host = another impl, no provider change.
|
|
5
|
+
*/
|
|
6
|
+
import { readFile } from "node:fs/promises";
|
|
7
|
+
import { basename } from "node:path";
|
|
8
|
+
export function isHttpUrl(s) {
|
|
9
|
+
return /^https?:\/\//i.test(s);
|
|
10
|
+
}
|
|
11
|
+
function mimeFromName(name) {
|
|
12
|
+
const ext = name.toLowerCase().split(".").pop() ?? "";
|
|
13
|
+
const map = { png: "image/png", jpg: "image/jpeg", jpeg: "image/jpeg", webp: "image/webp", gif: "image/gif" };
|
|
14
|
+
return map[ext] ?? "application/octet-stream";
|
|
15
|
+
}
|
|
16
|
+
export class FalStorageUploader {
|
|
17
|
+
fetchImpl;
|
|
18
|
+
kind = "fal";
|
|
19
|
+
// fal upload lives on a different host than queue.fal.run.
|
|
20
|
+
static UPLOAD_BASE = "https://rest.alpha.fal.ai";
|
|
21
|
+
constructor(fetchImpl = fetch) {
|
|
22
|
+
this.fetchImpl = fetchImpl;
|
|
23
|
+
}
|
|
24
|
+
async toUrl(pathOrUrl, creds, signal) {
|
|
25
|
+
if (isHttpUrl(pathOrUrl))
|
|
26
|
+
return { ok: true, url: pathOrUrl };
|
|
27
|
+
try {
|
|
28
|
+
const bytes = await readFile(pathOrUrl);
|
|
29
|
+
const url = await this.uploadBytes(bytes, basename(pathOrUrl), creds, signal);
|
|
30
|
+
return { ok: true, url };
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
return { ok: false, error: `fal upload error for ${pathOrUrl}: ${err.message}` };
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Upload raw bytes to fal storage, return the public URL. Two-step flow
|
|
38
|
+
* (verified against live API 2026-06-10):
|
|
39
|
+
* 1. POST {UPLOAD_BASE}/storage/upload/initiate → { file_url, upload_url }
|
|
40
|
+
* 2. PUT <upload_url> with the bytes (signed URL, no Authorization)
|
|
41
|
+
* 3. file_url is the final public URL.
|
|
42
|
+
*/
|
|
43
|
+
async uploadBytes(bytes, name, creds, signal) {
|
|
44
|
+
const mime = mimeFromName(name);
|
|
45
|
+
const ini = await this.fetchImpl(`${FalStorageUploader.UPLOAD_BASE}/storage/upload/initiate`, {
|
|
46
|
+
method: "POST",
|
|
47
|
+
headers: { Authorization: `Key ${creds.apiKey}`, "Content-Type": "application/json" },
|
|
48
|
+
body: JSON.stringify({ content_type: mime, file_name: name }),
|
|
49
|
+
signal,
|
|
50
|
+
});
|
|
51
|
+
if (!ini.ok)
|
|
52
|
+
throw new Error(`initiate failed: HTTP ${ini.status}`);
|
|
53
|
+
const { file_url, upload_url } = (await ini.json());
|
|
54
|
+
if (!file_url || !upload_url)
|
|
55
|
+
throw new Error("initiate: missing file_url/upload_url");
|
|
56
|
+
const put = await this.fetchImpl(upload_url, {
|
|
57
|
+
method: "PUT",
|
|
58
|
+
headers: { "Content-Type": mime },
|
|
59
|
+
body: bytes,
|
|
60
|
+
signal,
|
|
61
|
+
});
|
|
62
|
+
if (!put.ok)
|
|
63
|
+
throw new Error(`upload PUT failed: HTTP ${put.status}`);
|
|
64
|
+
return file_url;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export function getImageUploader(kind, fetchImpl = fetch) {
|
|
68
|
+
switch (kind) {
|
|
69
|
+
case "fal":
|
|
70
|
+
return new FalStorageUploader(fetchImpl);
|
|
71
|
+
default:
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -16,11 +16,15 @@ import type { RegisteredTool } from "../../types.js";
|
|
|
16
16
|
* 内置工具返回值:大多数返回纯文本字符串。需要回传图片(或其它结构化
|
|
17
17
|
* 内容块)的工具(view_image)可改为返回 `{ contentBlocks }`;此时
|
|
18
18
|
* registry 会把它放进 ToolResult.contentBlocks。可选的 `result` 字段是给
|
|
19
|
-
* transcript /
|
|
19
|
+
* transcript / 摘要用的纯文本镜像。沙箱执行类工具(Bash 等)可返回
|
|
20
|
+
* `{ result, sandbox }`,registry 把 sandbox 透传到 ToolResult.sandbox 供 UI 显示。
|
|
20
21
|
*/
|
|
21
22
|
export type BuiltinToolResult = string | {
|
|
22
23
|
contentBlocks: import("../../types.js").ContentBlock[];
|
|
23
24
|
result?: string;
|
|
25
|
+
} | {
|
|
26
|
+
result: string;
|
|
27
|
+
sandbox: import("../../types.js").ToolResult["sandbox"];
|
|
24
28
|
};
|
|
25
29
|
export type BuiltinToolFn = (args: Record<string, unknown>, ctx?: import("../context.js").ToolContext) => Promise<BuiltinToolResult>;
|
|
26
30
|
export interface BuiltinTool {
|
|
@@ -35,3 +39,5 @@ export declare const BUILTIN_TOOLS: BuiltinTool[];
|
|
|
35
39
|
* Keyed by the tool's `name` (must match the toolDef name).
|
|
36
40
|
*/
|
|
37
41
|
export declare const BUILTIN_TOOL_GUARDS: Map<string, (cwd: string) => boolean>;
|
|
42
|
+
/** UseCredential is available when the cwd's CredentialStore has ≥1 credential. */
|
|
43
|
+
export declare function isUseCredentialAvailable(cwd: string): boolean;
|