@code-yeongyu/senpi 2026.8.11 → 2026.8.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +185 -0
- package/dist/brand-dir-migration.d.ts +28 -0
- package/dist/brand-dir-migration.d.ts.map +1 -0
- package/dist/brand-dir-migration.js +77 -0
- package/dist/brand-dir-migration.js.map +1 -0
- package/dist/cli/grok-neo-gate.d.ts +0 -8
- package/dist/cli/grok-neo-gate.d.ts.map +1 -1
- package/dist/cli/grok-neo-gate.js +4 -2
- package/dist/cli/grok-neo-gate.js.map +1 -1
- package/dist/cli-main.d.ts +1 -1
- package/dist/cli-main.d.ts.map +1 -1
- package/dist/cli-main.js +4 -0
- package/dist/cli-main.js.map +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +3 -2
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +27 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +41 -9
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session.d.ts +8 -2
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +73 -11
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/brand.d.ts +79 -0
- package/dist/core/brand.d.ts.map +1 -0
- package/dist/core/brand.js +141 -0
- package/dist/core/brand.js.map +1 -0
- package/dist/core/dynamic-prompt/identity.d.ts.map +1 -1
- package/dist/core/dynamic-prompt/identity.js +2 -1
- package/dist/core/dynamic-prompt/identity.js.map +1 -1
- package/dist/core/event-bus.d.ts +5 -0
- package/dist/core/event-bus.d.ts.map +1 -1
- package/dist/core/event-bus.js +1 -0
- package/dist/core/event-bus.js.map +1 -1
- package/dist/core/experimental.d.ts.map +1 -1
- package/dist/core/experimental.js +2 -1
- package/dist/core/experimental.js.map +1 -1
- package/dist/core/extensions/builtin/btw/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/btw/index.js +7 -2
- package/dist/core/extensions/builtin/btw/index.js.map +1 -1
- package/dist/core/extensions/builtin/btw/side-query.d.ts +2 -0
- package/dist/core/extensions/builtin/btw/side-query.d.ts.map +1 -1
- package/dist/core/extensions/builtin/btw/side-query.js +39 -2
- package/dist/core/extensions/builtin/btw/side-query.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/availability.d.ts +2 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/availability.d.ts.map +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/availability.js +24 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/availability.js.map +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/index.d.ts +4 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/index.js +5 -2
- package/dist/core/extensions/builtin/claude-sdk-oauth/index.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/oauth-login.d.ts +6 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/oauth-login.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/oauth-login.js +16 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/oauth-login.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-commit-boundary.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-commit-boundary.js +10 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-commit-boundary.js.map +1 -1
- package/dist/core/extensions/builtin/compaction/index.d.ts +1 -0
- package/dist/core/extensions/builtin/compaction/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/compaction/index.js +1 -1
- package/dist/core/extensions/builtin/compaction/index.js.map +1 -1
- package/dist/core/extensions/builtin/compaction/log.d.ts.map +1 -1
- package/dist/core/extensions/builtin/compaction/log.js +2 -1
- package/dist/core/extensions/builtin/compaction/log.js.map +1 -1
- package/dist/core/extensions/builtin/config-reload/generated-shim-filter.d.ts.map +1 -1
- package/dist/core/extensions/builtin/config-reload/generated-shim-filter.js +4 -4
- package/dist/core/extensions/builtin/config-reload/generated-shim-filter.js.map +1 -1
- package/dist/core/extensions/builtin/goal/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/index.js +5 -0
- package/dist/core/extensions/builtin/goal/index.js.map +1 -1
- package/dist/core/extensions/builtin/goal/lifecycle-helpers.d.ts +2 -2
- package/dist/core/extensions/builtin/goal/lifecycle-helpers.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/lifecycle-helpers.js +3 -3
- package/dist/core/extensions/builtin/goal/lifecycle-helpers.js.map +1 -1
- package/dist/core/extensions/builtin/goal/monitor-continuation.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/monitor-continuation.js +6 -0
- package/dist/core/extensions/builtin/goal/monitor-continuation.js.map +1 -1
- package/dist/core/extensions/builtin/goal/store.d.ts +3 -2
- package/dist/core/extensions/builtin/goal/store.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/store.js +128 -101
- package/dist/core/extensions/builtin/goal/store.js.map +1 -1
- package/dist/core/extensions/builtin/goal/transitions.js +2 -1
- package/dist/core/extensions/builtin/goal/transitions.js.map +1 -1
- package/dist/core/extensions/builtin/help/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/help/index.js +3 -2
- package/dist/core/extensions/builtin/help/index.js.map +1 -1
- package/dist/core/extensions/builtin/imagegen/auth.d.ts +45 -0
- package/dist/core/extensions/builtin/imagegen/auth.d.ts.map +1 -0
- package/dist/core/extensions/builtin/imagegen/auth.js +137 -0
- package/dist/core/extensions/builtin/imagegen/auth.js.map +1 -0
- package/dist/core/extensions/builtin/imagegen/index.d.ts +5 -0
- package/dist/core/extensions/builtin/imagegen/index.d.ts.map +1 -0
- package/dist/core/extensions/builtin/imagegen/index.js +46 -0
- package/dist/core/extensions/builtin/imagegen/index.js.map +1 -0
- package/dist/core/extensions/builtin/imagegen/paths.d.ts +26 -0
- package/dist/core/extensions/builtin/imagegen/paths.d.ts.map +1 -0
- package/dist/core/extensions/builtin/imagegen/paths.js +52 -0
- package/dist/core/extensions/builtin/imagegen/paths.js.map +1 -0
- package/dist/core/extensions/builtin/imagegen/skill/SKILL.md +67 -0
- package/dist/core/extensions/builtin/imagegen/state.d.ts +26 -0
- package/dist/core/extensions/builtin/imagegen/state.d.ts.map +1 -0
- package/dist/core/extensions/builtin/imagegen/state.js +35 -0
- package/dist/core/extensions/builtin/imagegen/state.js.map +1 -0
- package/dist/core/extensions/builtin/imagegen/tool.d.ts +31 -0
- package/dist/core/extensions/builtin/imagegen/tool.d.ts.map +1 -0
- package/dist/core/extensions/builtin/imagegen/tool.js +174 -0
- package/dist/core/extensions/builtin/imagegen/tool.js.map +1 -0
- package/dist/core/extensions/builtin/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/index.js +9 -1
- package/dist/core/extensions/builtin/index.js.map +1 -1
- package/dist/core/extensions/builtin/mcp/control-inventory.d.ts +14 -0
- package/dist/core/extensions/builtin/mcp/control-inventory.d.ts.map +1 -0
- package/dist/core/extensions/builtin/mcp/control-inventory.js +22 -0
- package/dist/core/extensions/builtin/mcp/control-inventory.js.map +1 -0
- package/dist/core/extensions/builtin/mcp/expose/native-search.d.ts +2 -44
- package/dist/core/extensions/builtin/mcp/expose/native-search.d.ts.map +1 -1
- package/dist/core/extensions/builtin/mcp/expose/native-search.js +3 -97
- package/dist/core/extensions/builtin/mcp/expose/native-search.js.map +1 -1
- package/dist/core/extensions/builtin/mcp/expose/proxy.d.ts.map +1 -1
- package/dist/core/extensions/builtin/mcp/expose/proxy.js +15 -4
- package/dist/core/extensions/builtin/mcp/expose/proxy.js.map +1 -1
- package/dist/core/extensions/builtin/mcp/expose/session.d.ts +2 -1
- package/dist/core/extensions/builtin/mcp/expose/session.d.ts.map +1 -1
- package/dist/core/extensions/builtin/mcp/expose/session.js +2 -2
- package/dist/core/extensions/builtin/mcp/expose/session.js.map +1 -1
- package/dist/core/extensions/builtin/mcp/expose/tier-b.d.ts +13 -11
- package/dist/core/extensions/builtin/mcp/expose/tier-b.d.ts.map +1 -1
- package/dist/core/extensions/builtin/mcp/expose/tier-b.js +58 -59
- package/dist/core/extensions/builtin/mcp/expose/tier-b.js.map +1 -1
- package/dist/core/extensions/builtin/mcp/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/mcp/index.js +28 -36
- package/dist/core/extensions/builtin/mcp/index.js.map +1 -1
- package/dist/core/extensions/builtin/mcp/service-register.d.ts +2 -1
- package/dist/core/extensions/builtin/mcp/service-register.d.ts.map +1 -1
- package/dist/core/extensions/builtin/mcp/service-register.js +2 -2
- package/dist/core/extensions/builtin/mcp/service-register.js.map +1 -1
- package/dist/core/extensions/builtin/mcp/service-types.d.ts +4 -0
- package/dist/core/extensions/builtin/mcp/service-types.d.ts.map +1 -1
- package/dist/core/extensions/builtin/mcp/service-types.js.map +1 -1
- package/dist/core/extensions/builtin/mcp/service.d.ts +6 -11
- package/dist/core/extensions/builtin/mcp/service.d.ts.map +1 -1
- package/dist/core/extensions/builtin/mcp/service.js +79 -41
- package/dist/core/extensions/builtin/mcp/service.js.map +1 -1
- package/dist/core/extensions/builtin/mcp/wrap.d.ts +2 -0
- package/dist/core/extensions/builtin/mcp/wrap.d.ts.map +1 -1
- package/dist/core/extensions/builtin/mcp/wrap.js +3 -0
- package/dist/core/extensions/builtin/mcp/wrap.js.map +1 -1
- package/dist/core/extensions/builtin/openai-image-gen/externalize.d.ts +27 -0
- package/dist/core/extensions/builtin/openai-image-gen/externalize.d.ts.map +1 -0
- package/dist/core/extensions/builtin/openai-image-gen/externalize.js +133 -0
- package/dist/core/extensions/builtin/openai-image-gen/externalize.js.map +1 -0
- package/dist/core/extensions/builtin/openai-image-gen/gate.d.ts +21 -0
- package/dist/core/extensions/builtin/openai-image-gen/gate.d.ts.map +1 -0
- package/dist/core/extensions/builtin/openai-image-gen/gate.js +63 -0
- package/dist/core/extensions/builtin/openai-image-gen/gate.js.map +1 -0
- package/dist/core/extensions/builtin/openai-image-gen/index.d.ts +14 -0
- package/dist/core/extensions/builtin/openai-image-gen/index.d.ts.map +1 -0
- package/dist/core/extensions/builtin/openai-image-gen/index.js +77 -0
- package/dist/core/extensions/builtin/openai-image-gen/index.js.map +1 -0
- package/dist/core/extensions/builtin/openai-image-gen/inject.d.ts +15 -0
- package/dist/core/extensions/builtin/openai-image-gen/inject.d.ts.map +1 -0
- package/dist/core/extensions/builtin/openai-image-gen/inject.js +42 -0
- package/dist/core/extensions/builtin/openai-image-gen/inject.js.map +1 -0
- package/dist/core/extensions/builtin/prompt-preset/claude-fable-5.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-fable-5.js +2 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-fable-5.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-5.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-5.js +2 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-5.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.5.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.5.js +2 -1
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.5.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.js +2 -1
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/grok-4.5.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/grok-4.5.js +6 -5
- package/dist/core/extensions/builtin/prompt-preset/grok-4.5.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/kimi-k3.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/kimi-k3.js +2 -1
- package/dist/core/extensions/builtin/prompt-preset/kimi-k3.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/monitor-notify.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/monitor-notify.js +8 -1
- package/dist/core/extensions/builtin/terminal/monitor-notify.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/notify.d.ts +3 -1
- package/dist/core/extensions/builtin/terminal/notify.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/notify.js +4 -1
- package/dist/core/extensions/builtin/terminal/notify.js.map +1 -1
- package/dist/core/extensions/builtin/tool-search/engine/bm25.d.ts +22 -0
- package/dist/core/extensions/builtin/tool-search/engine/bm25.d.ts.map +1 -0
- package/dist/core/extensions/builtin/{mcp/expose → tool-search/engine}/bm25.js +16 -31
- package/dist/core/extensions/builtin/tool-search/engine/bm25.js.map +1 -0
- package/dist/core/extensions/builtin/tool-search/engine/document.d.ts +14 -0
- package/dist/core/extensions/builtin/tool-search/engine/document.d.ts.map +1 -0
- package/dist/core/extensions/builtin/tool-search/engine/document.js +2 -0
- package/dist/core/extensions/builtin/tool-search/engine/document.js.map +1 -0
- package/dist/core/extensions/builtin/tool-search/engine/marker.d.ts +55 -0
- package/dist/core/extensions/builtin/tool-search/engine/marker.d.ts.map +1 -0
- package/dist/core/extensions/builtin/tool-search/engine/marker.js +189 -0
- package/dist/core/extensions/builtin/tool-search/engine/marker.js.map +1 -0
- package/dist/core/extensions/builtin/tool-search/index.d.ts +7 -0
- package/dist/core/extensions/builtin/tool-search/index.d.ts.map +1 -0
- package/dist/core/extensions/builtin/tool-search/index.js +71 -0
- package/dist/core/extensions/builtin/tool-search/index.js.map +1 -0
- package/dist/core/extensions/builtin/tool-search/native-search.d.ts +52 -0
- package/dist/core/extensions/builtin/tool-search/native-search.d.ts.map +1 -0
- package/dist/core/extensions/builtin/tool-search/native-search.js +116 -0
- package/dist/core/extensions/builtin/tool-search/native-search.js.map +1 -0
- package/dist/core/extensions/builtin/tool-search/service.d.ts +38 -0
- package/dist/core/extensions/builtin/tool-search/service.d.ts.map +1 -0
- package/dist/core/extensions/builtin/tool-search/service.js +200 -0
- package/dist/core/extensions/builtin/tool-search/service.js.map +1 -0
- package/dist/core/extensions/builtin/tool-search/tool.d.ts +21 -0
- package/dist/core/extensions/builtin/tool-search/tool.d.ts.map +1 -0
- package/dist/core/extensions/builtin/tool-search/tool.js +95 -0
- package/dist/core/extensions/builtin/tool-search/tool.js.map +1 -0
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +31 -1
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +5 -1
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +28 -1
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +61 -4
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js +11 -0
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/generated-shim-banner.d.ts +15 -0
- package/dist/core/generated-shim-banner.d.ts.map +1 -0
- package/dist/core/generated-shim-banner.js +26 -0
- package/dist/core/generated-shim-banner.js.map +1 -0
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +7 -3
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +2 -1
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/provider-composer.d.ts +10 -1
- package/dist/core/provider-composer.d.ts.map +1 -1
- package/dist/core/provider-composer.js +9 -0
- package/dist/core/provider-composer.js.map +1 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +21 -10
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/session-log.d.ts.map +1 -1
- package/dist/core/session-log.js +4 -2
- package/dist/core/session-log.js.map +1 -1
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +3 -2
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/telemetry.d.ts.map +1 -1
- package/dist/core/telemetry.js +2 -1
- package/dist/core/telemetry.js.map +1 -1
- package/dist/core/timings.d.ts +0 -4
- package/dist/core/timings.d.ts.map +1 -1
- package/dist/core/timings.js +2 -1
- package/dist/core/timings.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/inspector-policy.d.ts.map +1 -1
- package/dist/inspector-policy.js +2 -1
- package/dist/inspector-policy.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +5 -4
- package/dist/main.js.map +1 -1
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +4 -0
- package/dist/migrations.js.map +1 -1
- package/dist/modes/index.d.ts +2 -2
- package/dist/modes/index.d.ts.map +1 -1
- package/dist/modes/index.js +1 -1
- package/dist/modes/index.js.map +1 -1
- package/dist/modes/interactive/external-editor.d.ts +2 -0
- package/dist/modes/interactive/external-editor.d.ts.map +1 -1
- package/dist/modes/interactive/external-editor.js +10 -4
- package/dist/modes/interactive/external-editor.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +6 -5
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/tips/catalog/cli-tips.d.ts.map +1 -1
- package/dist/modes/interactive/tips/catalog/cli-tips.js +2 -1
- package/dist/modes/interactive/tips/catalog/cli-tips.js.map +1 -1
- package/dist/modes/interactive/tips/catalog/ethos-tips.d.ts.map +1 -1
- package/dist/modes/interactive/tips/catalog/ethos-tips.js +4 -3
- package/dist/modes/interactive/tips/catalog/ethos-tips.js.map +1 -1
- package/dist/modes/interactive/tips/catalog/model-tips.d.ts.map +1 -1
- package/dist/modes/interactive/tips/catalog/model-tips.js +2 -1
- package/dist/modes/interactive/tips/catalog/model-tips.js.map +1 -1
- package/dist/modes/interactive/tips/catalog/session-tips.d.ts.map +1 -1
- package/dist/modes/interactive/tips/catalog/session-tips.js +2 -1
- package/dist/modes/interactive/tips/catalog/session-tips.js.map +1 -1
- package/dist/modes/interactive/tips/catalog/settings-tips.d.ts.map +1 -1
- package/dist/modes/interactive/tips/catalog/settings-tips.js +3 -2
- package/dist/modes/interactive/tips/catalog/settings-tips.js.map +1 -1
- package/dist/modes/interactive/tips/catalog/workspace-tips.d.ts.map +1 -1
- package/dist/modes/interactive/tips/catalog/workspace-tips.js +4 -3
- package/dist/modes/interactive/tips/catalog/workspace-tips.js.map +1 -1
- package/dist/modes/provider-native-rendering.d.ts.map +1 -1
- package/dist/modes/provider-native-rendering.js +33 -0
- package/dist/modes/provider-native-rendering.js.map +1 -1
- package/dist/modes/rpc/connection-handler.d.ts.map +1 -1
- package/dist/modes/rpc/connection-handler.js +148 -5
- package/dist/modes/rpc/connection-handler.js.map +1 -1
- package/dist/modes/rpc/custom-capability.d.ts +1 -0
- package/dist/modes/rpc/custom-capability.d.ts.map +1 -1
- package/dist/modes/rpc/custom-capability.js +1 -0
- package/dist/modes/rpc/custom-capability.js.map +1 -1
- package/dist/modes/rpc/multi-session-host.d.ts.map +1 -1
- package/dist/modes/rpc/multi-session-host.js +4 -1
- package/dist/modes/rpc/multi-session-host.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +5 -2
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +10 -1
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +2 -1
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +47 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/modes/rpc/session-binding.d.ts +2 -1
- package/dist/modes/rpc/session-binding.d.ts.map +1 -1
- package/dist/modes/rpc/session-binding.js +3 -2
- package/dist/modes/rpc/session-binding.js.map +1 -1
- package/dist/modes/rpc/session-command-router.d.ts +2 -1
- package/dist/modes/rpc/session-command-router.d.ts.map +1 -1
- package/dist/modes/rpc/session-command-router.js +3 -2
- package/dist/modes/rpc/session-command-router.js.map +1 -1
- package/dist/nearest-parent-config.d.ts +6 -1
- package/dist/nearest-parent-config.d.ts.map +1 -1
- package/dist/nearest-parent-config.js +18 -2
- package/dist/nearest-parent-config.js.map +1 -1
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +13 -1
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/rpc-entry.js +2 -0
- package/dist/rpc-entry.js.map +1 -1
- package/dist/self-update-bootstrap.d.ts.map +1 -1
- package/dist/self-update-bootstrap.js +6 -0
- package/dist/self-update-bootstrap.js.map +1 -1
- package/dist/senpi +3 -2
- package/dist/utils/pi-user-agent.d.ts +1 -1
- package/dist/utils/pi-user-agent.d.ts.map +1 -1
- package/dist/utils/pi-user-agent.js +4 -3
- package/dist/utils/pi-user-agent.js.map +1 -1
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +2 -1
- package/dist/utils/tools-manager.js.map +1 -1
- package/dist/utils/version-check.d.ts +3 -0
- package/dist/utils/version-check.d.ts.map +1 -1
- package/dist/utils/version-check.js +37 -6
- package/dist/utils/version-check.js.map +1 -1
- package/dist/valid-cwd.d.ts +2 -0
- package/dist/valid-cwd.d.ts.map +1 -0
- package/dist/valid-cwd.js +14 -0
- package/dist/valid-cwd.js.map +1 -0
- package/docs/environment-variables.md +8 -1
- package/docs/extensions.md +93 -13
- package/docs/mcp.md +2 -0
- package/docs/providers.md +2 -2
- package/docs/rpc.md +126 -0
- package/docs/skills.md +8 -0
- package/examples/extensions/searchable-tools.ts +49 -0
- package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +77 -0
- package/node_modules/@code-yeongyu/senpi-codemode/package.json +4 -4
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/jl/kernel.ts +14 -1
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/rb/kernel.ts +14 -1
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/shared/runtime-asset.ts +31 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.js +5 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.js.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/agent.d.ts +4 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/agent.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/agent.js +2 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/agent.js.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/types.d.ts +9 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/types.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/types.js.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/package.json +2 -2
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js +2 -2
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.js +4 -2
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js +7 -3
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-images.d.ts +8 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-images.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-images.js +222 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-images.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-images.lazy.d.ts +3 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-images.lazy.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-images.lazy.js +10 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-images.lazy.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses-shared.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses-shared.js +113 -4
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses-shared.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.js +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/transform-messages.d.ts +5 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/transform-messages.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/transform-messages.js +2 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/transform-messages.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/openai-codex.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/openai-codex.js +2 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/openai-codex.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/types.d.ts +10 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/types.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/types.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.d.ts +47 -0
- package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js +47 -0
- package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/index.d.ts +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/index.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/index.js +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/index.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/models.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/models.js +36 -13
- package/node_modules/@earendil-works/pi-ai/dist/models.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/openai-responses-compat.d.ts +2 -0
- package/node_modules/@earendil-works/pi-ai/dist/openai-responses-compat.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/openai-responses-compat.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/all.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/all.js +2 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/all.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/amazon-bedrock.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-workers-ai.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/google.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/nvidia.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/images/register-builtins.d.ts +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/images/register-builtins.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/images/register-builtins.js +18 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/images/register-builtins.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/openai-images.d.ts +3 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/openai-images.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/openai-images.js +16 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/openai-images.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/types.d.ts +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/types.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/types.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/prompt-cache-ttl.js +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/prompt-cache-ttl.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js +7 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/wire-identity.d.ts +14 -0
- package/node_modules/@earendil-works/pi-ai/dist/wire-identity.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/wire-identity.js +24 -0
- package/node_modules/@earendil-works/pi-ai/dist/wire-identity.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/package.json +1 -1
- package/node_modules/@earendil-works/pi-pty/dist/pipe-fallback.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-pty/dist/pipe-fallback.js +11 -3
- package/node_modules/@earendil-works/pi-pty/dist/pipe-fallback.js.map +1 -1
- package/node_modules/@earendil-works/pi-pty/package.json +1 -1
- package/node_modules/@earendil-works/pi-tui/package.json +1 -1
- package/package.json +9 -9
- package/dist/core/extensions/builtin/mcp/expose/bm25.d.ts +0 -30
- package/dist/core/extensions/builtin/mcp/expose/bm25.d.ts.map +0 -1
- package/dist/core/extensions/builtin/mcp/expose/bm25.js.map +0 -1
- package/dist/core/extensions/builtin/mcp/expose/lazy-activate.d.ts +0 -15
- package/dist/core/extensions/builtin/mcp/expose/lazy-activate.d.ts.map +0 -1
- package/dist/core/extensions/builtin/mcp/expose/lazy-activate.js +0 -33
- package/dist/core/extensions/builtin/mcp/expose/lazy-activate.js.map +0 -1
- package/dist/core/extensions/builtin/mcp/expose/tool-search.d.ts +0 -43
- package/dist/core/extensions/builtin/mcp/expose/tool-search.d.ts.map +0 -1
- package/dist/core/extensions/builtin/mcp/expose/tool-search.js +0 -125
- package/dist/core/extensions/builtin/mcp/expose/tool-search.js.map +0 -1
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import OpenAI from "openai";
|
|
2
|
+
import { formatProviderError, normalizeProviderError } from "../utils/error-body.js";
|
|
3
|
+
import { headersToRecord } from "../utils/headers.js";
|
|
4
|
+
import { retryProviderRequest } from "../utils/provider-retry.js";
|
|
5
|
+
import { sanitizeSurrogates } from "../utils/sanitize-unicode.js";
|
|
6
|
+
import { resolveOpenAIClientAuth } from "./openai-client-auth.js";
|
|
7
|
+
const MAX_PROMPT_CHARS = 32_000;
|
|
8
|
+
const MAX_IMAGE_BYTES = 24 * 1024 * 1024;
|
|
9
|
+
const ENDPOINT_SUFFIXES = ["/chat/completions", "/responses", "/models"];
|
|
10
|
+
const PNG_MAGIC = [0x89, 0x50, 0x4e, 0x47];
|
|
11
|
+
const JPEG_MAGIC = [0xff, 0xd8, 0xff];
|
|
12
|
+
const WEBP_MAGIC = [0x52, 0x49, 0x46, 0x46, 0x57, 0x45, 0x42, 0x50];
|
|
13
|
+
export const generateImages = async (model, context, options) => {
|
|
14
|
+
const output = {
|
|
15
|
+
api: model.api,
|
|
16
|
+
provider: model.provider,
|
|
17
|
+
model: model.id,
|
|
18
|
+
output: [],
|
|
19
|
+
stopReason: "stop",
|
|
20
|
+
timestamp: Date.now(),
|
|
21
|
+
};
|
|
22
|
+
try {
|
|
23
|
+
let params = buildParams(model, context, options);
|
|
24
|
+
const nextParams = await options?.onPayload?.(params, model);
|
|
25
|
+
if (nextParams !== undefined) {
|
|
26
|
+
if (!isGenerateParams(nextParams))
|
|
27
|
+
throw new Error("onPayload returned an invalid image generation payload");
|
|
28
|
+
params = nextParams;
|
|
29
|
+
}
|
|
30
|
+
const headers = { ...model.headers, ...options?.headers };
|
|
31
|
+
const auth = resolveOpenAIClientAuth(model.provider, options?.apiKey, headers);
|
|
32
|
+
const client = new OpenAI({
|
|
33
|
+
apiKey: auth.apiKey,
|
|
34
|
+
baseURL: normalizeBaseUrl(model.baseUrl),
|
|
35
|
+
dangerouslyAllowBrowser: true,
|
|
36
|
+
fetch: options?.fetch,
|
|
37
|
+
defaultHeaders: auth.headers,
|
|
38
|
+
});
|
|
39
|
+
const requestOptions = {
|
|
40
|
+
...(options?.signal ? { signal: options.signal } : {}),
|
|
41
|
+
...(options?.timeoutMs !== undefined ? { timeout: options.timeoutMs } : {}),
|
|
42
|
+
maxRetries: 0,
|
|
43
|
+
};
|
|
44
|
+
const { data: response, response: rawResponse } = await retryProviderRequest(() => client.images.generate(params, requestOptions).withResponse(), {
|
|
45
|
+
maxRetries: options?.maxRetries,
|
|
46
|
+
maxRetryDelayMs: options?.maxRetryDelayMs,
|
|
47
|
+
signal: options?.signal,
|
|
48
|
+
});
|
|
49
|
+
await options?.onResponse?.({ status: rawResponse.status, headers: headersToRecord(rawResponse.headers) }, model);
|
|
50
|
+
if (response.usage)
|
|
51
|
+
output.usage = parseUsage(response.usage, model);
|
|
52
|
+
if (!response.data || response.data.length === 0)
|
|
53
|
+
throw new Error("OpenAI images response contained no image data");
|
|
54
|
+
for (const datum of response.data) {
|
|
55
|
+
const image = await resolveImage(datum, options);
|
|
56
|
+
if (datum.revised_prompt?.trim()) {
|
|
57
|
+
output.output.push({ type: "text", text: datum.revised_prompt });
|
|
58
|
+
}
|
|
59
|
+
output.output.push(image);
|
|
60
|
+
}
|
|
61
|
+
return output;
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
output.stopReason = options?.signal?.aborted ? "aborted" : "error";
|
|
65
|
+
output.errorMessage = formatProviderError(normalizeProviderError(error));
|
|
66
|
+
return output;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
function buildParams(model, context, options) {
|
|
70
|
+
const promptParts = [];
|
|
71
|
+
for (const item of context.input) {
|
|
72
|
+
if (item.type === "image") {
|
|
73
|
+
throw new Error("generations does not accept image input; use the images edit endpoint");
|
|
74
|
+
}
|
|
75
|
+
const text = sanitizeSurrogates(item.text);
|
|
76
|
+
if (text.trim())
|
|
77
|
+
promptParts.push(text);
|
|
78
|
+
}
|
|
79
|
+
const prompt = promptParts.join("\n\n");
|
|
80
|
+
if (!prompt.trim())
|
|
81
|
+
throw new Error("Image generation requires a non-empty text prompt");
|
|
82
|
+
if (prompt.length > MAX_PROMPT_CHARS) {
|
|
83
|
+
throw new Error(`Image generation prompt exceeds ${MAX_PROMPT_CHARS} characters`);
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
model: model.id,
|
|
87
|
+
prompt,
|
|
88
|
+
size: options?.size ?? "auto",
|
|
89
|
+
quality: options?.quality ?? "auto",
|
|
90
|
+
n: options?.n ?? 1,
|
|
91
|
+
output_format: "png",
|
|
92
|
+
stream: false,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function isGenerateParams(value) {
|
|
96
|
+
return typeof value === "object" && value !== null && "prompt" in value && typeof value.prompt === "string";
|
|
97
|
+
}
|
|
98
|
+
function normalizeBaseUrl(baseUrl) {
|
|
99
|
+
let url;
|
|
100
|
+
try {
|
|
101
|
+
url = new URL(baseUrl);
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
throw new Error(`Invalid OpenAI images base URL: ${baseUrl}`);
|
|
105
|
+
}
|
|
106
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
107
|
+
throw new Error("OpenAI images base URL must use HTTP or HTTPS");
|
|
108
|
+
}
|
|
109
|
+
if (url.search || url.hash)
|
|
110
|
+
throw new Error("OpenAI images base URL must not include a query or fragment");
|
|
111
|
+
const pathname = url.pathname.replace(/\/+$/, "");
|
|
112
|
+
const normalizedPathname = pathname.toLowerCase();
|
|
113
|
+
if (normalizedPathname.includes("/images")) {
|
|
114
|
+
throw new Error("OpenAI images base URL must not include an images endpoint");
|
|
115
|
+
}
|
|
116
|
+
if (ENDPOINT_SUFFIXES.some((suffix) => normalizedPathname.endsWith(suffix))) {
|
|
117
|
+
throw new Error("OpenAI images base URL must not include a known API endpoint");
|
|
118
|
+
}
|
|
119
|
+
url.pathname = pathname.endsWith("/v1") ? pathname : `${pathname}/v1`;
|
|
120
|
+
return url.toString();
|
|
121
|
+
}
|
|
122
|
+
async function resolveImage(datum, options) {
|
|
123
|
+
const b64 = datum.b64_json?.trim();
|
|
124
|
+
if (b64)
|
|
125
|
+
return { type: "image", mimeType: "image/png", data: b64 };
|
|
126
|
+
const url = datum.url?.trim();
|
|
127
|
+
if (!url)
|
|
128
|
+
throw new Error("OpenAI images response datum contained no image data");
|
|
129
|
+
if (url.startsWith("data:"))
|
|
130
|
+
return parseDataUrl(url);
|
|
131
|
+
return hydrateImageUrl(url, options);
|
|
132
|
+
}
|
|
133
|
+
function parseDataUrl(url) {
|
|
134
|
+
const match = /^data:([^;,]+);base64,(.+)$/i.exec(url);
|
|
135
|
+
if (!match?.[1] || !match[2])
|
|
136
|
+
throw new Error("OpenAI images response contained an invalid data URL");
|
|
137
|
+
const mimeType = supportedMime(match[1]);
|
|
138
|
+
if (!mimeType)
|
|
139
|
+
throw new Error(`OpenAI images response used unsupported MIME type: ${match[1]}`);
|
|
140
|
+
return { type: "image", mimeType, data: match[2] };
|
|
141
|
+
}
|
|
142
|
+
async function hydrateImageUrl(url, options) {
|
|
143
|
+
let parsed;
|
|
144
|
+
try {
|
|
145
|
+
parsed = new URL(url);
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
throw new Error("OpenAI images response URL must be absolute");
|
|
149
|
+
}
|
|
150
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
151
|
+
throw new Error("OpenAI images response URL must use HTTP or HTTPS");
|
|
152
|
+
}
|
|
153
|
+
const response = await (options?.fetch ?? globalThis.fetch)(url, options?.signal ? { signal: options.signal } : {});
|
|
154
|
+
if (!response.ok)
|
|
155
|
+
throw new Error(`OpenAI image hydration failed with HTTP ${response.status}`);
|
|
156
|
+
const declaredLength = response.headers.get("content-length");
|
|
157
|
+
if (declaredLength && Number(declaredLength) > MAX_IMAGE_BYTES)
|
|
158
|
+
throw oversizedImageError();
|
|
159
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
160
|
+
if (bytes.byteLength === 0)
|
|
161
|
+
throw new Error("OpenAI image hydration returned an empty body");
|
|
162
|
+
if (bytes.byteLength > MAX_IMAGE_BYTES)
|
|
163
|
+
throw oversizedImageError();
|
|
164
|
+
const declaredMime = supportedMime(response.headers.get("content-type")?.split(";", 1)[0]);
|
|
165
|
+
const detectedMime = detectMime(bytes);
|
|
166
|
+
if (declaredMime && detectedMime && declaredMime !== detectedMime) {
|
|
167
|
+
throw new Error(`OpenAI image MIME mismatch: declared ${declaredMime}, detected ${detectedMime}`);
|
|
168
|
+
}
|
|
169
|
+
const mimeType = detectedMime ?? declaredMime;
|
|
170
|
+
if (!mimeType)
|
|
171
|
+
throw new Error("OpenAI image hydration returned unsupported image content");
|
|
172
|
+
return { type: "image", mimeType, data: bytesToBase64(bytes) };
|
|
173
|
+
}
|
|
174
|
+
function supportedMime(value) {
|
|
175
|
+
const normalized = value?.trim().toLowerCase();
|
|
176
|
+
if (normalized === "image/png" || normalized === "image/jpeg" || normalized === "image/webp")
|
|
177
|
+
return normalized;
|
|
178
|
+
return undefined;
|
|
179
|
+
}
|
|
180
|
+
function detectMime(bytes) {
|
|
181
|
+
if (hasMagic(bytes, PNG_MAGIC))
|
|
182
|
+
return "image/png";
|
|
183
|
+
if (hasMagic(bytes, JPEG_MAGIC))
|
|
184
|
+
return "image/jpeg";
|
|
185
|
+
if (hasMagic(bytes, WEBP_MAGIC.slice(0, 4)) && hasMagic(bytes, WEBP_MAGIC.slice(4), 8))
|
|
186
|
+
return "image/webp";
|
|
187
|
+
return undefined;
|
|
188
|
+
}
|
|
189
|
+
function hasMagic(bytes, magic, offset = 0) {
|
|
190
|
+
return magic.every((value, index) => bytes[offset + index] === value);
|
|
191
|
+
}
|
|
192
|
+
function bytesToBase64(bytes) {
|
|
193
|
+
let binary = "";
|
|
194
|
+
for (let offset = 0; offset < bytes.length; offset += 0x8000) {
|
|
195
|
+
binary += String.fromCharCode(...bytes.subarray(offset, offset + 0x8000));
|
|
196
|
+
}
|
|
197
|
+
return btoa(binary);
|
|
198
|
+
}
|
|
199
|
+
function oversizedImageError() {
|
|
200
|
+
return new Error("OpenAI image hydration exceeded the 24 MiB limit");
|
|
201
|
+
}
|
|
202
|
+
function parseUsage(rawUsage, model) {
|
|
203
|
+
const input = rawUsage.input_tokens ?? 0;
|
|
204
|
+
const output = rawUsage.output_tokens ?? 0;
|
|
205
|
+
const usage = {
|
|
206
|
+
input,
|
|
207
|
+
output,
|
|
208
|
+
cacheRead: 0,
|
|
209
|
+
cacheWrite: 0,
|
|
210
|
+
totalTokens: rawUsage.total_tokens ?? input + output,
|
|
211
|
+
cost: {
|
|
212
|
+
input: (model.cost.input / 1_000_000) * input,
|
|
213
|
+
output: (model.cost.output / 1_000_000) * output,
|
|
214
|
+
cacheRead: 0,
|
|
215
|
+
cacheWrite: 0,
|
|
216
|
+
total: 0,
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
usage.cost.total = usage.cost.input + usage.cost.output;
|
|
220
|
+
return usage;
|
|
221
|
+
}
|
|
222
|
+
//# sourceMappingURL=openai-images.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai-images.js","sourceRoot":"","sources":["../../src/api/openai-images.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAY5B,OAAO,EAAE,mBAA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CAAC;QAC9D,MAAM,IAAI,MAAM,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC;IAC3E,CAAC;IACD,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC;AACrB,CAAC;AAED,SAAS,mBAAmB;IAC3B,OAAO,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;AACtE,CAAC;AAED,SAAS,UAAU,CAClB,QAAkF,EAClF,KAAmC;IAEnC,MAAM,KAAK,GAAG,QAAQ,CAAC,YAAY,IAAI,CAAC,CAAC;IACzC,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,IAAI,CAAC,CAAC;IAC3C,MAAM,KAAK,GAAG;QACb,KAAK;QACL,MAAM;QACN,SAAS,EAAE,CAAC;QACZ,UAAU,EAAE,CAAC;QACb,WAAW,EAAE,QAAQ,CAAC,YAAY,IAAI,KAAK,GAAG,MAAM;QACpD,IAAI,EAAE;YACL,KAAK,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC,GAAG,KAAK;YAC7C,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC,GAAG,MAAM;YAChD,SAAS,EAAE,CAAC;YACZ,UAAU,EAAE,CAAC;YACb,KAAK,EAAE,CAAC;SACR;KACD,CAAC;IACF,KAAK,CAAC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC;IACxD,OAAO,KAAK,CAAC;AACd,CAAC","sourcesContent":["import OpenAI from \"openai\";\nimport type { Image, ImageGenerateParamsNonStreaming } from \"openai/resources/images.js\";\nimport type {\n\tAssistantImages,\n\tImageContent,\n\tImagesContext,\n\tImagesFunction,\n\tImagesModel,\n\tImagesOptions,\n\tProviderHeaders,\n\tTextContent,\n} from \"../types.ts\";\nimport { formatProviderError, normalizeProviderError } from \"../utils/error-body.ts\";\nimport { headersToRecord } from \"../utils/headers.ts\";\nimport { retryProviderRequest } from \"../utils/provider-retry.ts\";\nimport { sanitizeSurrogates } from \"../utils/sanitize-unicode.ts\";\nimport { resolveOpenAIClientAuth } from \"./openai-client-auth.ts\";\n\nconst MAX_PROMPT_CHARS = 32_000;\nconst MAX_IMAGE_BYTES = 24 * 1024 * 1024;\nconst ENDPOINT_SUFFIXES = [\"/chat/completions\", \"/responses\", \"/models\"] as const;\nconst PNG_MAGIC = [0x89, 0x50, 0x4e, 0x47] as const;\nconst JPEG_MAGIC = [0xff, 0xd8, 0xff] as const;\nconst WEBP_MAGIC = [0x52, 0x49, 0x46, 0x46, 0x57, 0x45, 0x42, 0x50] as const;\n\ntype SupportedImageMime = \"image/png\" | \"image/jpeg\" | \"image/webp\";\n\nexport interface OpenAIImagesOptions extends ImagesOptions {\n\tsize?: \"auto\" | \"1024x1024\" | \"1024x1536\" | \"1536x1024\";\n\tquality?: \"auto\" | \"low\" | \"medium\" | \"high\";\n\tn?: number;\n}\n\nexport const generateImages: ImagesFunction<\"openai-images\", OpenAIImagesOptions> = async (\n\tmodel: ImagesModel<\"openai-images\">,\n\tcontext: ImagesContext,\n\toptions?: OpenAIImagesOptions,\n) => {\n\tconst output: AssistantImages = {\n\t\tapi: model.api,\n\t\tprovider: model.provider,\n\t\tmodel: model.id,\n\t\toutput: [],\n\t\tstopReason: \"stop\",\n\t\ttimestamp: Date.now(),\n\t};\n\n\ttry {\n\t\tlet params = buildParams(model, context, options);\n\t\tconst nextParams = await options?.onPayload?.(params, model);\n\t\tif (nextParams !== undefined) {\n\t\t\tif (!isGenerateParams(nextParams)) throw new Error(\"onPayload returned an invalid image generation payload\");\n\t\t\tparams = nextParams;\n\t\t}\n\n\t\tconst headers: ProviderHeaders = { ...model.headers, ...options?.headers };\n\t\tconst auth = resolveOpenAIClientAuth(model.provider, options?.apiKey, headers);\n\t\tconst client = new OpenAI({\n\t\t\tapiKey: auth.apiKey,\n\t\t\tbaseURL: normalizeBaseUrl(model.baseUrl),\n\t\t\tdangerouslyAllowBrowser: true,\n\t\t\tfetch: options?.fetch,\n\t\t\tdefaultHeaders: auth.headers,\n\t\t});\n\t\tconst requestOptions = {\n\t\t\t...(options?.signal ? { signal: options.signal } : {}),\n\t\t\t...(options?.timeoutMs !== undefined ? { timeout: options.timeoutMs } : {}),\n\t\t\tmaxRetries: 0,\n\t\t};\n\t\tconst { data: response, response: rawResponse } = await retryProviderRequest(\n\t\t\t() => client.images.generate(params, requestOptions).withResponse(),\n\t\t\t{\n\t\t\t\tmaxRetries: options?.maxRetries,\n\t\t\t\tmaxRetryDelayMs: options?.maxRetryDelayMs,\n\t\t\t\tsignal: options?.signal,\n\t\t\t},\n\t\t);\n\t\tawait options?.onResponse?.({ status: rawResponse.status, headers: headersToRecord(rawResponse.headers) }, model);\n\n\t\tif (response.usage) output.usage = parseUsage(response.usage, model);\n\t\tif (!response.data || response.data.length === 0)\n\t\t\tthrow new Error(\"OpenAI images response contained no image data\");\n\n\t\tfor (const datum of response.data) {\n\t\t\tconst image = await resolveImage(datum, options);\n\t\t\tif (datum.revised_prompt?.trim()) {\n\t\t\t\toutput.output.push({ type: \"text\", text: datum.revised_prompt } satisfies TextContent);\n\t\t\t}\n\t\t\toutput.output.push(image);\n\t\t}\n\t\treturn output;\n\t} catch (error) {\n\t\toutput.stopReason = options?.signal?.aborted ? \"aborted\" : \"error\";\n\t\toutput.errorMessage = formatProviderError(normalizeProviderError(error));\n\t\treturn output;\n\t}\n};\n\nfunction buildParams(\n\tmodel: ImagesModel<\"openai-images\">,\n\tcontext: ImagesContext,\n\toptions?: OpenAIImagesOptions,\n): ImageGenerateParamsNonStreaming {\n\tconst promptParts: string[] = [];\n\tfor (const item of context.input) {\n\t\tif (item.type === \"image\") {\n\t\t\tthrow new Error(\"generations does not accept image input; use the images edit endpoint\");\n\t\t}\n\t\tconst text = sanitizeSurrogates(item.text);\n\t\tif (text.trim()) promptParts.push(text);\n\t}\n\tconst prompt = promptParts.join(\"\\n\\n\");\n\tif (!prompt.trim()) throw new Error(\"Image generation requires a non-empty text prompt\");\n\tif (prompt.length > MAX_PROMPT_CHARS) {\n\t\tthrow new Error(`Image generation prompt exceeds ${MAX_PROMPT_CHARS} characters`);\n\t}\n\treturn {\n\t\tmodel: model.id,\n\t\tprompt,\n\t\tsize: options?.size ?? \"auto\",\n\t\tquality: options?.quality ?? \"auto\",\n\t\tn: options?.n ?? 1,\n\t\toutput_format: \"png\",\n\t\tstream: false,\n\t};\n}\n\nfunction isGenerateParams(value: unknown): value is ImageGenerateParamsNonStreaming {\n\treturn typeof value === \"object\" && value !== null && \"prompt\" in value && typeof value.prompt === \"string\";\n}\n\nfunction normalizeBaseUrl(baseUrl: string): string {\n\tlet url: URL;\n\ttry {\n\t\turl = new URL(baseUrl);\n\t} catch {\n\t\tthrow new Error(`Invalid OpenAI images base URL: ${baseUrl}`);\n\t}\n\tif (url.protocol !== \"http:\" && url.protocol !== \"https:\") {\n\t\tthrow new Error(\"OpenAI images base URL must use HTTP or HTTPS\");\n\t}\n\tif (url.search || url.hash) throw new Error(\"OpenAI images base URL must not include a query or fragment\");\n\tconst pathname = url.pathname.replace(/\\/+$/, \"\");\n\tconst normalizedPathname = pathname.toLowerCase();\n\tif (normalizedPathname.includes(\"/images\")) {\n\t\tthrow new Error(\"OpenAI images base URL must not include an images endpoint\");\n\t}\n\tif (ENDPOINT_SUFFIXES.some((suffix) => normalizedPathname.endsWith(suffix))) {\n\t\tthrow new Error(\"OpenAI images base URL must not include a known API endpoint\");\n\t}\n\turl.pathname = pathname.endsWith(\"/v1\") ? pathname : `${pathname}/v1`;\n\treturn url.toString();\n}\n\nasync function resolveImage(datum: Image, options?: OpenAIImagesOptions): Promise<ImageContent> {\n\tconst b64 = datum.b64_json?.trim();\n\tif (b64) return { type: \"image\", mimeType: \"image/png\", data: b64 };\n\tconst url = datum.url?.trim();\n\tif (!url) throw new Error(\"OpenAI images response datum contained no image data\");\n\tif (url.startsWith(\"data:\")) return parseDataUrl(url);\n\treturn hydrateImageUrl(url, options);\n}\n\nfunction parseDataUrl(url: string): ImageContent {\n\tconst match = /^data:([^;,]+);base64,(.+)$/i.exec(url);\n\tif (!match?.[1] || !match[2]) throw new Error(\"OpenAI images response contained an invalid data URL\");\n\tconst mimeType = supportedMime(match[1]);\n\tif (!mimeType) throw new Error(`OpenAI images response used unsupported MIME type: ${match[1]}`);\n\treturn { type: \"image\", mimeType, data: match[2] };\n}\n\nasync function hydrateImageUrl(url: string, options?: OpenAIImagesOptions): Promise<ImageContent> {\n\tlet parsed: URL;\n\ttry {\n\t\tparsed = new URL(url);\n\t} catch {\n\t\tthrow new Error(\"OpenAI images response URL must be absolute\");\n\t}\n\tif (parsed.protocol !== \"http:\" && parsed.protocol !== \"https:\") {\n\t\tthrow new Error(\"OpenAI images response URL must use HTTP or HTTPS\");\n\t}\n\tconst response = await (options?.fetch ?? globalThis.fetch)(url, options?.signal ? { signal: options.signal } : {});\n\tif (!response.ok) throw new Error(`OpenAI image hydration failed with HTTP ${response.status}`);\n\tconst declaredLength = response.headers.get(\"content-length\");\n\tif (declaredLength && Number(declaredLength) > MAX_IMAGE_BYTES) throw oversizedImageError();\n\tconst bytes = new Uint8Array(await response.arrayBuffer());\n\tif (bytes.byteLength === 0) throw new Error(\"OpenAI image hydration returned an empty body\");\n\tif (bytes.byteLength > MAX_IMAGE_BYTES) throw oversizedImageError();\n\tconst declaredMime = supportedMime(response.headers.get(\"content-type\")?.split(\";\", 1)[0]);\n\tconst detectedMime = detectMime(bytes);\n\tif (declaredMime && detectedMime && declaredMime !== detectedMime) {\n\t\tthrow new Error(`OpenAI image MIME mismatch: declared ${declaredMime}, detected ${detectedMime}`);\n\t}\n\tconst mimeType = detectedMime ?? declaredMime;\n\tif (!mimeType) throw new Error(\"OpenAI image hydration returned unsupported image content\");\n\treturn { type: \"image\", mimeType, data: bytesToBase64(bytes) };\n}\n\nfunction supportedMime(value: string | undefined): SupportedImageMime | undefined {\n\tconst normalized = value?.trim().toLowerCase();\n\tif (normalized === \"image/png\" || normalized === \"image/jpeg\" || normalized === \"image/webp\") return normalized;\n\treturn undefined;\n}\n\nfunction detectMime(bytes: Uint8Array): SupportedImageMime | undefined {\n\tif (hasMagic(bytes, PNG_MAGIC)) return \"image/png\";\n\tif (hasMagic(bytes, JPEG_MAGIC)) return \"image/jpeg\";\n\tif (hasMagic(bytes, WEBP_MAGIC.slice(0, 4)) && hasMagic(bytes, WEBP_MAGIC.slice(4), 8)) return \"image/webp\";\n\treturn undefined;\n}\n\nfunction hasMagic(bytes: Uint8Array, magic: readonly number[], offset = 0): boolean {\n\treturn magic.every((value, index) => bytes[offset + index] === value);\n}\n\nfunction bytesToBase64(bytes: Uint8Array): string {\n\tlet binary = \"\";\n\tfor (let offset = 0; offset < bytes.length; offset += 0x8000) {\n\t\tbinary += String.fromCharCode(...bytes.subarray(offset, offset + 0x8000));\n\t}\n\treturn btoa(binary);\n}\n\nfunction oversizedImageError(): Error {\n\treturn new Error(\"OpenAI image hydration exceeded the 24 MiB limit\");\n}\n\nfunction parseUsage(\n\trawUsage: { input_tokens?: number; output_tokens?: number; total_tokens?: number },\n\tmodel: ImagesModel<\"openai-images\">,\n) {\n\tconst input = rawUsage.input_tokens ?? 0;\n\tconst output = rawUsage.output_tokens ?? 0;\n\tconst usage = {\n\t\tinput,\n\t\toutput,\n\t\tcacheRead: 0,\n\t\tcacheWrite: 0,\n\t\ttotalTokens: rawUsage.total_tokens ?? input + output,\n\t\tcost: {\n\t\t\tinput: (model.cost.input / 1_000_000) * input,\n\t\t\toutput: (model.cost.output / 1_000_000) * output,\n\t\t\tcacheRead: 0,\n\t\t\tcacheWrite: 0,\n\t\t\ttotal: 0,\n\t\t},\n\t};\n\tusage.cost.total = usage.cost.input + usage.cost.output;\n\treturn usage;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai-images.lazy.d.ts","sourceRoot":"","sources":["../../src/api/openai-images.lazy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,cAAc,EAAE,MAAM,aAAa,CAAC;AAE/D,eAAO,MAAM,eAAe,QAAO,cAQjC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const openaiImagesApi = () => ({
|
|
2
|
+
generateImages: async (model, context, options) => {
|
|
3
|
+
if (model.api !== "openai-images") {
|
|
4
|
+
throw new Error(`Mismatched api: ${model.api} expected openai-images`);
|
|
5
|
+
}
|
|
6
|
+
const openaiModel = { ...model, api: "openai-images" };
|
|
7
|
+
return (await import("./openai-images.js")).generateImages(openaiModel, context, options);
|
|
8
|
+
},
|
|
9
|
+
});
|
|
10
|
+
//# sourceMappingURL=openai-images.lazy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai-images.lazy.js","sourceRoot":"","sources":["../../src/api/openai-images.lazy.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,eAAe,GAAG,GAAmB,EAAE,CAAC,CAAC;IACrD,cAAc,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE;QACjD,IAAI,KAAK,CAAC,GAAG,KAAK,eAAe,EAAE,CAAC;YACnC,MAAM,IAAI,KAAK,CAAC,mBAAmB,KAAK,CAAC,GAAG,yBAAyB,CAAC,CAAC;QACxE,CAAC;QACD,MAAM,WAAW,GAAG,EAAE,GAAG,KAAK,EAAE,GAAG,EAAE,eAAe,EAAyC,CAAC;QAC9F,OAAO,CAAC,MAAM,MAAM,CAAC,oBAAoB,CAAC,CAAC,CAAC,cAAc,CAAC,WAAW,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAC3F,CAAC;CACD,CAAC,CAAC","sourcesContent":["import type { ImagesModel, ProviderImages } from \"../types.ts\";\n\nexport const openaiImagesApi = (): ProviderImages => ({\n\tgenerateImages: async (model, context, options) => {\n\t\tif (model.api !== \"openai-images\") {\n\t\t\tthrow new Error(`Mismatched api: ${model.api} expected openai-images`);\n\t\t}\n\t\tconst openaiModel = { ...model, api: \"openai-images\" } satisfies ImagesModel<\"openai-images\">;\n\t\treturn (await import(\"./openai-images.ts\")).generateImages(openaiModel, context, options);\n\t},\n});\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai-responses-shared.d.ts","sourceRoot":"","sources":["../../src/api/openai-responses-shared.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEX,IAAI,IAAI,UAAU,EAClB,6BAA6B,EAE7B,aAAa,EAOb,mBAAmB,EAEnB,MAAM,yCAAyC,CAAC;AAQjD,OAAO,KAAK,EACX,GAAG,EACH,gBAAgB,EAChB,OAAO,EAEP,KAAK,EAML,IAAI,EAEJ,KAAK,EACL,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AA2F5E,MAAM,WAAW,4BAA4B;IAC5C,WAAW,CAAC,EAAE,6BAA6B,CAAC,cAAc,CAAC,CAAC;IAC5D,0BAA0B,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzD,kBAAkB,CAAC,EAAE,CACpB,mBAAmB,EAAE,6BAA6B,CAAC,cAAc,CAAC,GAAG,SAAS,EAC9E,kBAAkB,EAAE,6BAA6B,CAAC,cAAc,CAAC,GAAG,SAAS,KACzE,6BAA6B,CAAC,cAAc,CAAC,GAAG,SAAS,CAAC;IAC/D,uBAAuB,CAAC,EAAE,CACzB,KAAK,EAAE,KAAK,EACZ,WAAW,EAAE,6BAA6B,CAAC,cAAc,CAAC,GAAG,SAAS,KAClE,IAAI,CAAC;CACV;AAED,MAAM,WAAW,+BAA+B;IAC/C,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,0BAA0B,CAAC,EAAE,WAAW,CAAC,MAA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BAAqB,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,EAAE,OAAO,CAAC,EAAE,4BAA4B,GAAG,UAAU,EAAE,CA6ClH;AA2FD,wBAAsB,sBAAsB,CAAC,IAAI,SAAS,GAAG,EAC5D,YAAY,EAAE,aAAa,CAAC,mBAAmB,CAAC,EAChD,MAAM,EAAE,gBAAgB,EACxB,MAAM,EAAE,2BAA2B,EACnC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,EAClB,OAAO,CAAC,EAAE,4BAA4B,GACpC,OAAO,CAAC,IAAI,CAAC,CAkZf"}
|
|
@@ -400,10 +400,57 @@ function appendCustomToolCallInput(block, nextInput, close) {
|
|
|
400
400
|
block.arguments = { [customInput.property]: nextInput };
|
|
401
401
|
return delta;
|
|
402
402
|
}
|
|
403
|
+
const MAX_NATIVE_IMAGE_BASE64_CHARS = 24 * 1024 * 1024;
|
|
404
|
+
function readNativeImageGenerationCall(value) {
|
|
405
|
+
if (typeof value !== "object" || value === null || !("type" in value) || !("status" in value))
|
|
406
|
+
return undefined;
|
|
407
|
+
if (value.type !== "image_generation_call" || typeof value.status !== "string")
|
|
408
|
+
return undefined;
|
|
409
|
+
return {
|
|
410
|
+
type: "image_generation_call",
|
|
411
|
+
...("id" in value && typeof value.id === "string" ? { id: value.id } : {}),
|
|
412
|
+
status: value.status,
|
|
413
|
+
...("result" in value && (typeof value.result === "string" || value.result === null)
|
|
414
|
+
? { result: value.result }
|
|
415
|
+
: {}),
|
|
416
|
+
...("revised_prompt" in value && typeof value.revised_prompt === "string"
|
|
417
|
+
? { revised_prompt: value.revised_prompt }
|
|
418
|
+
: {}),
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
function isValidBase64(value) {
|
|
422
|
+
return value.length > 0 && value.length % 4 === 0 && /^[A-Za-z0-9+/]*={0,2}$/.test(value);
|
|
423
|
+
}
|
|
424
|
+
function reconcileNativeImageGenerationCall(item) {
|
|
425
|
+
if (item.status !== "completed") {
|
|
426
|
+
return {
|
|
427
|
+
type: "image_generation_call",
|
|
428
|
+
...(item.id !== undefined ? { id: item.id } : {}),
|
|
429
|
+
status: item.status,
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
if (typeof item.result !== "string" || !isValidBase64(item.result)) {
|
|
433
|
+
return {
|
|
434
|
+
type: "image_generation_call",
|
|
435
|
+
...(item.id !== undefined ? { id: item.id } : {}),
|
|
436
|
+
status: "malformed",
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
return {
|
|
440
|
+
type: "image_generation_call",
|
|
441
|
+
...(item.id !== undefined ? { id: item.id } : {}),
|
|
442
|
+
status: "completed",
|
|
443
|
+
result: item.result,
|
|
444
|
+
...(item.revised_prompt?.trim() ? { revised_prompt: item.revised_prompt } : {}),
|
|
445
|
+
};
|
|
446
|
+
}
|
|
403
447
|
export async function processResponsesStream(openaiStream, output, stream, model, options) {
|
|
404
448
|
let sawTerminalResponseEvent = false;
|
|
449
|
+
let nativeImageBase64Chars = 0;
|
|
405
450
|
const outputSlots = new Map();
|
|
406
451
|
const reasoningBlocksById = new Map();
|
|
452
|
+
const nativeImageCharsByOutputIndex = new Map();
|
|
453
|
+
const finalizedNativeImageOutputIndexes = new Set();
|
|
407
454
|
const applyMessagePhaseStopReason = (item) => {
|
|
408
455
|
if (item.type === "message" && item.phase === "final_answer") {
|
|
409
456
|
output.stopReason = "stop";
|
|
@@ -486,19 +533,74 @@ export async function processResponsesStream(openaiStream, output, stream, model
|
|
|
486
533
|
stream.push({ type: "toolcall_start", contentIndex: slot.contentIndex, partial: output });
|
|
487
534
|
return slot;
|
|
488
535
|
}
|
|
489
|
-
const
|
|
490
|
-
|
|
536
|
+
const imageItem = readNativeImageGenerationCall(item);
|
|
537
|
+
const block = {
|
|
538
|
+
type: "providerNative",
|
|
539
|
+
subtype: item.type,
|
|
540
|
+
raw: imageItem ? reconcileNativeImageGenerationCall(imageItem) : item,
|
|
541
|
+
};
|
|
491
542
|
const slot = {
|
|
492
543
|
type: "providerNative",
|
|
493
544
|
block,
|
|
494
|
-
contentIndex: output.content.length
|
|
545
|
+
contentIndex: output.content.length,
|
|
495
546
|
};
|
|
547
|
+
if (imageItem)
|
|
548
|
+
reconcileNativeImageSlot(outputIndex, slot, imageItem);
|
|
549
|
+
output.content.push(block);
|
|
496
550
|
outputSlots.set(outputIndex, slot);
|
|
497
551
|
return slot;
|
|
498
552
|
};
|
|
499
553
|
const getOrCreateSlot = (outputIndex, item) => {
|
|
500
554
|
return outputSlots.get(outputIndex) ?? createSlot(outputIndex, item);
|
|
501
555
|
};
|
|
556
|
+
function scrubNativeImageResults() {
|
|
557
|
+
for (const block of output.content) {
|
|
558
|
+
if (block.type !== "providerNative" || block.subtype !== "image_generation_call")
|
|
559
|
+
continue;
|
|
560
|
+
const item = readNativeImageGenerationCall(block.raw);
|
|
561
|
+
if (typeof item?.result !== "string")
|
|
562
|
+
continue;
|
|
563
|
+
block.raw = {
|
|
564
|
+
type: "image_generation_call",
|
|
565
|
+
...(item.id !== undefined ? { id: item.id } : {}),
|
|
566
|
+
status: "malformed",
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
nativeImageBase64Chars = 0;
|
|
570
|
+
nativeImageCharsByOutputIndex.clear();
|
|
571
|
+
}
|
|
572
|
+
function reconcileNativeImageSlot(outputIndex, slot, item) {
|
|
573
|
+
const reconciled = reconcileNativeImageGenerationCall(item);
|
|
574
|
+
const previousChars = nativeImageCharsByOutputIndex.get(outputIndex) ?? 0;
|
|
575
|
+
const nextChars = typeof reconciled.result === "string" ? reconciled.result.length : 0;
|
|
576
|
+
const nextTotal = nativeImageBase64Chars - previousChars + nextChars;
|
|
577
|
+
if (nextTotal > MAX_NATIVE_IMAGE_BASE64_CHARS) {
|
|
578
|
+
scrubNativeImageResults();
|
|
579
|
+
throw new Error("Native image generation results exceed the 24 MiB base64 limit");
|
|
580
|
+
}
|
|
581
|
+
nativeImageBase64Chars = nextTotal;
|
|
582
|
+
if (nextChars > 0)
|
|
583
|
+
nativeImageCharsByOutputIndex.set(outputIndex, nextChars);
|
|
584
|
+
else
|
|
585
|
+
nativeImageCharsByOutputIndex.delete(outputIndex);
|
|
586
|
+
slot.block.subtype = "image_generation_call";
|
|
587
|
+
slot.block.raw = reconciled;
|
|
588
|
+
}
|
|
589
|
+
const backfillNativeImageGenerationCalls = (responseOutput) => {
|
|
590
|
+
for (const [outputIndex, outputItem] of responseOutput.entries()) {
|
|
591
|
+
if (finalizedNativeImageOutputIndexes.has(outputIndex))
|
|
592
|
+
continue;
|
|
593
|
+
const imageItem = readNativeImageGenerationCall(outputItem);
|
|
594
|
+
if (!imageItem)
|
|
595
|
+
continue;
|
|
596
|
+
const existingSlot = getSlot(outputIndex, "providerNative");
|
|
597
|
+
if (existingSlot)
|
|
598
|
+
reconcileNativeImageSlot(outputIndex, existingSlot, imageItem);
|
|
599
|
+
else
|
|
600
|
+
createSlot(outputIndex, outputItem);
|
|
601
|
+
outputSlots.delete(outputIndex);
|
|
602
|
+
}
|
|
603
|
+
};
|
|
502
604
|
// Azure OpenAI can omit reasoning.encrypted_content from response.output_item.done
|
|
503
605
|
// and provide it only in response.completed.response.output. Backfill the
|
|
504
606
|
// persisted reasoning signature from the terminal response to keep store:false
|
|
@@ -522,6 +624,7 @@ export async function processResponsesStream(openaiStream, output, stream, model
|
|
|
522
624
|
const finalizeResponse = (response) => {
|
|
523
625
|
sawTerminalResponseEvent = true;
|
|
524
626
|
backfillReasoningSignatures(response.output ?? []);
|
|
627
|
+
backfillNativeImageGenerationCalls(response.output ?? []);
|
|
525
628
|
if (response?.id) {
|
|
526
629
|
output.responseId = response.id;
|
|
527
630
|
}
|
|
@@ -659,7 +762,13 @@ export async function processResponsesStream(openaiStream, output, stream, model
|
|
|
659
762
|
const item = event.item;
|
|
660
763
|
applyMessagePhaseStopReason(item);
|
|
661
764
|
const slot = getOrCreateSlot(event.output_index, item);
|
|
662
|
-
|
|
765
|
+
const imageItem = readNativeImageGenerationCall(item);
|
|
766
|
+
if (imageItem && slot?.type === "providerNative") {
|
|
767
|
+
reconcileNativeImageSlot(event.output_index, slot, imageItem);
|
|
768
|
+
finalizedNativeImageOutputIndexes.add(event.output_index);
|
|
769
|
+
outputSlots.delete(event.output_index);
|
|
770
|
+
}
|
|
771
|
+
else if (item.type === "reasoning" && slot?.type === "thinking") {
|
|
663
772
|
const summaryText = item.summary?.map((s) => s.text).join("\n\n") || "";
|
|
664
773
|
const contentText = item.content?.map((c) => c.text).join("\n\n") || "";
|
|
665
774
|
slot.block.thinking = summaryText || contentText || slot.block.thinking;
|