@psnext/slingcli 2.4.20260507-3 → 2.4.20260509-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/LICENSE +1 -1
- package/README.md +1 -1
- package/bin/sling.js +12 -12
- package/node_modules/@aws-sdk/client-bedrock-runtime/package.json +2 -2
- package/node_modules/@aws-sdk/token-providers/package.json +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-agent-core/dist/agent-loop.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-agent-core/dist/agent.js +4 -3
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/agent-harness.js +526 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/branch-summarization.js +243 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/compaction.js +616 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/env/nodejs.js +348 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/execution-env.js +3 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/factory.js +9 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/messages.js +102 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/prompt-templates.js +194 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repo/jsonl.js +92 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repo/memory.js +42 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repo/shared.js +31 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/session.js +196 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/storage/jsonl.js +170 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/storage/memory.js +90 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/skills.js +258 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/system-prompt.js +30 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/types.js +16 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/shell-output.js +97 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/index.js +26 -0
- package/node_modules/{@mariozechner → @earendil-works}/pi-agent-core/dist/proxy.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-agent-core/package.json +7 -5
- package/node_modules/{@mariozechner → @earendil-works}/pi-ai/dist/cli.js +6 -6
- package/node_modules/{@mariozechner → @earendil-works}/pi-ai/dist/env-api-keys.js +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js +307 -0
- package/node_modules/@earendil-works/pi-ai/dist/image-models.js +23 -0
- package/node_modules/@earendil-works/pi-ai/dist/images-api-registry.js +22 -0
- package/node_modules/@earendil-works/pi-ai/dist/images.js +14 -0
- package/node_modules/{@mariozechner → @earendil-works}/pi-ai/dist/index.js +4 -0
- package/node_modules/{@mariozechner → @earendil-works}/pi-ai/dist/models.generated.js +427 -122
- package/node_modules/@earendil-works/pi-ai/dist/providers/images/openrouter.js +129 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/images/register-builtins.js +34 -0
- package/node_modules/{@mariozechner → @earendil-works}/pi-ai/dist/providers/openai-codex-responses.js +1 -1
- package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/providers/openai-completions.js +150 -122
- package/node_modules/{@mariozechner → @earendil-works}/pi-ai/dist/providers/openai-responses-shared.js +14 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-ai/dist/utils/oauth/openai-codex.js +25 -14
- package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/utils/overflow.js +3 -0
- package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/package.json +5 -4
- package/node_modules/@earendil-works/pi-coding-agent/dist/bun/register-bedrock.js +4 -0
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/cli/args.js +1 -0
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/cli/config-selector.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/cli/list-models.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/cli/session-picker.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/config.js +52 -30
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/agent-session.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/auth-storage.js +2 -2
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/compaction/branch-summarization.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/compaction/compaction.js +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/compaction/utils.js +153 -0
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/export-html/template.css +45 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/export-html/template.js +68 -4
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/extensions/loader.js +26 -12
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/keybindings.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/model-registry.js +3 -2
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/model-resolver.js +2 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/package-manager.js +22 -5
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/provider-display-names.js +1 -0
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/sdk.js +3 -3
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/tools/bash.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/tools/edit.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/tools/find.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/tools/grep.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/tools/ls.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/tools/read.js +3 -2
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/tools/render-utils.js +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/truncate.js +205 -0
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/tools/write.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/main.js +2 -2
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/migrations.js +3 -3
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/assistant-message.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/bash-execution.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/bordered-loader.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/branch-summary-message.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/compaction-summary-message.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/config-selector.js +25 -3
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/custom-editor.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/custom-message.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/earendil-announcement.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/extension-editor.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/extension-input.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/extension-selector.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/footer.js +1 -1
- package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/keybinding-hints.js +36 -0
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/login-dialog.js +4 -3
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/model-selector.js +2 -2
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/oauth-selector.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/scoped-models-selector.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/session-selector-search.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/session-selector.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/settings-selector.js +4 -2
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/show-images-selector.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/skill-invocation-message.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/theme-selector.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/thinking-selector.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/tool-execution.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/tree-selector.js +3 -2
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/user-message-selector.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/user-message.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/visual-truncate.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/interactive-mode.js +47 -32
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/theme/dark.json +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/theme/light.json +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/theme/theme.js +1 -1
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/package-manager-cli.js +42 -39
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/utils/clipboard.js +9 -2
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/utils/paths.js +16 -0
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/utils/version-check.js +9 -2
- package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/package.json +9 -8
- package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/components/image.js +14 -7
- package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/components/markdown.js +24 -84
- package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/terminal-image.js +10 -4
- package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/tui.js +73 -4
- package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/utils.js +33 -7
- package/node_modules/{@mariozechner → @earendil-works}/pi-tui/package.json +3 -3
- package/node_modules/@mariozechner/clipboard/README.md +58 -0
- package/node_modules/@mariozechner/clipboard/index.d.ts +23 -0
- package/node_modules/@mariozechner/clipboard-linux-x64-gnu/README.md +3 -0
- package/node_modules/@types/node/README.md +1 -1
- package/node_modules/@types/node/http2.d.ts +4 -1
- package/node_modules/@types/node/package.json +2 -2
- package/node_modules/@types/node/stream/web.d.ts +4 -0
- package/node_modules/brace-expansion/dist/commonjs/index.js +1 -1
- package/node_modules/brace-expansion/dist/commonjs/index.js.map +1 -1
- package/node_modules/brace-expansion/dist/esm/index.js +1 -1
- package/node_modules/brace-expansion/dist/esm/index.js.map +1 -1
- package/node_modules/brace-expansion/package.json +1 -1
- package/node_modules/fast-xml-builder/CHANGELOG.md +4 -0
- package/node_modules/fast-xml-builder/lib/fxb.cjs +1 -1
- package/node_modules/fast-xml-builder/lib/fxb.d.cts +91 -1
- package/node_modules/fast-xml-builder/lib/fxb.min.js +1 -1
- package/node_modules/fast-xml-builder/lib/fxb.min.js.map +1 -1
- package/node_modules/fast-xml-builder/package.json +3 -2
- package/node_modules/fast-xml-builder/src/fxb.d.ts +92 -3
- package/node_modules/fast-xml-builder/src/fxb.js +92 -31
- package/node_modules/fast-xml-builder/src/orderedJs2Xml.js +87 -33
- package/node_modules/get-east-asian-width/lookup-data.js +15 -12
- package/node_modules/get-east-asian-width/lookup.js +25 -22
- package/node_modules/get-east-asian-width/package.json +1 -1
- package/node_modules/jiti/README.md +258 -0
- package/node_modules/jiti/dist/babel.cjs +257 -0
- package/node_modules/jiti/dist/jiti.cjs +1 -0
- package/node_modules/jiti/lib/jiti.mjs +29 -0
- package/node_modules/jiti/lib/types.d.ts +420 -0
- package/node_modules/jiti/package.json +146 -0
- package/node_modules/protobufjs/dist/light/protobuf.js +5 -3
- package/node_modules/protobufjs/dist/light/protobuf.js.map +1 -1
- package/node_modules/protobufjs/dist/light/protobuf.min.js +3 -3
- package/node_modules/protobufjs/dist/light/protobuf.min.js.map +1 -1
- package/node_modules/protobufjs/dist/minimal/protobuf.js +2 -2
- package/node_modules/protobufjs/dist/minimal/protobuf.min.js +2 -2
- package/node_modules/protobufjs/dist/protobuf.js +5 -3
- package/node_modules/protobufjs/dist/protobuf.js.map +1 -1
- package/node_modules/protobufjs/dist/protobuf.min.js +3 -3
- package/node_modules/protobufjs/dist/protobuf.min.js.map +1 -1
- package/node_modules/protobufjs/package.json +1 -1
- package/node_modules/protobufjs/src/namespace.js +3 -1
- package/node_modules/semver/README.md +19 -4
- package/node_modules/semver/bin/semver.js +14 -10
- package/node_modules/semver/functions/truncate.js +48 -0
- package/node_modules/semver/index.js +2 -0
- package/node_modules/semver/internal/re.js +1 -1
- package/node_modules/semver/package.json +3 -3
- package/node_modules/semver/range.bnf +5 -4
- package/node_modules/socks/package.json +2 -2
- package/node_modules/xml-naming/README.md +189 -0
- package/node_modules/xml-naming/package.json +54 -0
- package/node_modules/xml-naming/src/index.d.ts +74 -0
- package/node_modules/xml-naming/src/index.js +270 -0
- package/package.json +6 -6
- package/sling-default-packages.json +2 -1
- package/slingshot/index.js +442 -23
- package/node_modules/@mariozechner/jiti/dist/babel.cjs +0 -246
- package/node_modules/@mariozechner/jiti/dist/jiti.cjs +0 -1
- package/node_modules/@mariozechner/jiti/package.json +0 -96
- package/node_modules/@mariozechner/pi-agent-core/dist/index.js +0 -9
- package/node_modules/@mariozechner/pi-agent-core/node_modules/@mariozechner/pi-ai/dist/cli.js +0 -116
- package/node_modules/@mariozechner/pi-agent-core/node_modules/@mariozechner/pi-ai/dist/env-api-keys.js +0 -166
- package/node_modules/@mariozechner/pi-agent-core/node_modules/@mariozechner/pi-ai/dist/index.js +0 -15
- package/node_modules/@mariozechner/pi-agent-core/node_modules/@mariozechner/pi-ai/dist/models.generated.js +0 -16568
- package/node_modules/@mariozechner/pi-agent-core/node_modules/@mariozechner/pi-ai/dist/providers/amazon-bedrock.js +0 -753
- package/node_modules/@mariozechner/pi-agent-core/node_modules/@mariozechner/pi-ai/dist/providers/openai-codex-responses.js +0 -909
- package/node_modules/@mariozechner/pi-agent-core/node_modules/@mariozechner/pi-ai/dist/providers/openai-responses-shared.js +0 -479
- package/node_modules/@mariozechner/pi-agent-core/node_modules/@mariozechner/pi-ai/dist/utils/oauth/openai-codex.js +0 -374
- package/node_modules/@mariozechner/pi-ai/dist/api-registry.js +0 -44
- package/node_modules/@mariozechner/pi-ai/dist/bedrock-provider.js +0 -6
- package/node_modules/@mariozechner/pi-ai/dist/models.js +0 -71
- package/node_modules/@mariozechner/pi-ai/dist/oauth.js +0 -2
- package/node_modules/@mariozechner/pi-ai/dist/providers/anthropic.js +0 -951
- package/node_modules/@mariozechner/pi-ai/dist/providers/azure-openai-responses.js +0 -208
- package/node_modules/@mariozechner/pi-ai/dist/providers/cloudflare.js +0 -26
- package/node_modules/@mariozechner/pi-ai/dist/providers/faux.js +0 -368
- package/node_modules/@mariozechner/pi-ai/dist/providers/github-copilot-headers.js +0 -29
- package/node_modules/@mariozechner/pi-ai/dist/providers/google-shared.js +0 -329
- package/node_modules/@mariozechner/pi-ai/dist/providers/google-vertex.js +0 -442
- package/node_modules/@mariozechner/pi-ai/dist/providers/google.js +0 -400
- package/node_modules/@mariozechner/pi-ai/dist/providers/mistral.js +0 -535
- package/node_modules/@mariozechner/pi-ai/dist/providers/openai-completions.js +0 -908
- package/node_modules/@mariozechner/pi-ai/dist/providers/openai-responses.js +0 -220
- package/node_modules/@mariozechner/pi-ai/dist/providers/register-builtins.js +0 -243
- package/node_modules/@mariozechner/pi-ai/dist/providers/simple-options.js +0 -39
- package/node_modules/@mariozechner/pi-ai/dist/providers/transform-messages.js +0 -184
- package/node_modules/@mariozechner/pi-ai/dist/stream.js +0 -27
- package/node_modules/@mariozechner/pi-ai/dist/types.js +0 -2
- package/node_modules/@mariozechner/pi-ai/dist/utils/event-stream.js +0 -81
- package/node_modules/@mariozechner/pi-ai/dist/utils/hash.js +0 -14
- package/node_modules/@mariozechner/pi-ai/dist/utils/headers.js +0 -8
- package/node_modules/@mariozechner/pi-ai/dist/utils/json-parse.js +0 -113
- package/node_modules/@mariozechner/pi-ai/dist/utils/oauth/anthropic.js +0 -335
- package/node_modules/@mariozechner/pi-ai/dist/utils/oauth/github-copilot.js +0 -292
- package/node_modules/@mariozechner/pi-ai/dist/utils/oauth/index.js +0 -121
- package/node_modules/@mariozechner/pi-ai/dist/utils/oauth/oauth-page.js +0 -105
- package/node_modules/@mariozechner/pi-ai/dist/utils/oauth/pkce.js +0 -31
- package/node_modules/@mariozechner/pi-ai/dist/utils/oauth/types.js +0 -2
- package/node_modules/@mariozechner/pi-ai/dist/utils/overflow.js +0 -146
- package/node_modules/@mariozechner/pi-ai/dist/utils/sanitize-unicode.js +0 -26
- package/node_modules/@mariozechner/pi-ai/dist/utils/typebox-helpers.js +0 -21
- package/node_modules/@mariozechner/pi-ai/dist/utils/validation.js +0 -281
- package/node_modules/@mariozechner/pi-ai/package.json +0 -108
- package/node_modules/@mariozechner/pi-coding-agent/dist/bun/register-bedrock.js +0 -4
- package/node_modules/@mariozechner/pi-coding-agent/dist/modes/interactive/components/keybinding-hints.js +0 -22
- package/node_modules/@mariozechner/pi-coding-agent/node_modules/@mariozechner/pi-agent-core/dist/agent-loop.js +0 -458
- package/node_modules/@mariozechner/pi-coding-agent/node_modules/@mariozechner/pi-agent-core/dist/agent.js +0 -398
- package/node_modules/@mariozechner/pi-coding-agent/node_modules/@mariozechner/pi-agent-core/dist/index.js +0 -9
- package/node_modules/@mariozechner/pi-coding-agent/node_modules/@mariozechner/pi-agent-core/dist/proxy.js +0 -278
- package/node_modules/@mariozechner/pi-coding-agent/node_modules/@mariozechner/pi-agent-core/dist/types.js +0 -2
- package/node_modules/@mariozechner/pi-coding-agent/node_modules/@mariozechner/pi-agent-core/package.json +0 -45
- package/node_modules/socks/.claude/settings.local.json +0 -26
- package/node_modules/std-env/LICENCE +0 -22
- package/node_modules/std-env/README.md +0 -118
- package/node_modules/std-env/dist/index.cjs +0 -1
- package/node_modules/std-env/dist/index.d.cts +0 -92
- package/node_modules/std-env/dist/index.d.mts +0 -92
- package/node_modules/std-env/dist/index.d.ts +0 -92
- package/node_modules/std-env/dist/index.mjs +0 -1
- package/node_modules/std-env/package.json +0 -46
- package/node_modules/yoctocolors/base.d.ts +0 -47
- package/node_modules/yoctocolors/base.js +0 -94
- package/node_modules/yoctocolors/index.d.ts +0 -2
- package/node_modules/yoctocolors/index.js +0 -2
- package/node_modules/yoctocolors/license +0 -9
- package/node_modules/yoctocolors/package.json +0 -69
- package/node_modules/yoctocolors/readme.md +0 -138
- /package/node_modules/{@mariozechner/pi-coding-agent/dist/core → @earendil-works/pi-agent-core/dist/harness}/compaction/utils.js +0 -0
- /package/node_modules/{@mariozechner/pi-coding-agent/dist/core/tools → @earendil-works/pi-agent-core/dist/harness/utils}/truncate.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-agent-core/dist/types.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/api-registry.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/bedrock-provider.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/models.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/oauth.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-ai/dist/providers/amazon-bedrock.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/providers/anthropic.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/providers/azure-openai-responses.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/providers/cloudflare.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/providers/faux.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/providers/github-copilot-headers.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/providers/google-shared.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/providers/google-vertex.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/providers/google.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/providers/mistral.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/providers/openai-responses.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/providers/register-builtins.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/providers/simple-options.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/providers/transform-messages.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-ai/dist/session-resources.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/stream.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/types.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-ai/dist/utils/diagnostics.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/utils/event-stream.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/utils/hash.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/utils/headers.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/utils/json-parse.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/utils/oauth/anthropic.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/utils/oauth/github-copilot.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/utils/oauth/index.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/utils/oauth/oauth-page.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/utils/oauth/pkce.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/utils/oauth/types.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/utils/sanitize-unicode.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/utils/typebox-helpers.js +0 -0
- /package/node_modules/{@mariozechner/pi-agent-core/node_modules/@mariozechner → @earendil-works}/pi-ai/dist/utils/validation.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/bun/cli.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/bun/restore-sandbox-env.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/cli/file-processor.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/cli/initial-message.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/cli.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/agent-session-runtime.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/agent-session-services.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/auth-guidance.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/bash-executor.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/compaction/index.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/defaults.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/diagnostics.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/event-bus.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/exec.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/export-html/ansi-to-html.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/export-html/index.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/export-html/template.html +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/export-html/tool-renderer.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/export-html/vendor/highlight.min.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/export-html/vendor/marked.min.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/extensions/index.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/extensions/runner.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/extensions/types.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/extensions/wrapper.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/footer-data-provider.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/index.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/messages.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/output-guard.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/prompt-templates.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/resolve-config-value.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/resource-loader.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/session-cwd.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/session-manager.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/settings-manager.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/skills.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/slash-commands.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/source-info.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/system-prompt.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/telemetry.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/timings.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/tools/edit-diff.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/tools/file-mutation-queue.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/tools/index.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/tools/output-accumulator.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/tools/path-utils.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/core/tools/tool-definition-wrapper.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/index.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/index.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/assets/clankolas.png +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/armin.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/countdown-timer.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/daxnuts.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/diff.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/dynamic-border.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/components/index.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/interactive/theme/theme-schema.json +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/print-mode.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/rpc/jsonl.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/rpc/rpc-client.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/rpc/rpc-mode.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/modes/rpc/rpc-types.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/utils/changelog.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/utils/child-process.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/utils/clipboard-image.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/utils/clipboard-native.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/utils/exif-orientation.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/utils/frontmatter.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/utils/fs-watch.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/utils/git.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/utils/image-convert.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/utils/image-resize.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/utils/mime.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/utils/photon.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/utils/pi-user-agent.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/utils/shell.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/utils/sleep.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-coding-agent/dist/utils/tools-manager.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/autocomplete.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/components/box.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/components/cancellable-loader.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/components/editor.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/components/input.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/components/loader.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/components/select-list.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/components/settings-list.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/components/spacer.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/components/text.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/components/truncated-text.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/editor-component.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/fuzzy.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/index.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/keybindings.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/keys.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/kill-ring.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/stdin-buffer.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/terminal.js +0 -0
- /package/node_modules/{@mariozechner → @earendil-works}/pi-tui/dist/undo-stack.js +0 -0
- /package/node_modules/{@mariozechner/jiti → jiti}/LICENSE +0 -0
- /package/node_modules/{@mariozechner/jiti → jiti}/lib/jiti-cli.mjs +0 -0
- /package/node_modules/{@mariozechner/jiti → jiti}/lib/jiti-hooks.mjs +0 -0
- /package/node_modules/{@mariozechner/jiti → jiti}/lib/jiti-native.mjs +0 -0
- /package/node_modules/{@mariozechner/jiti → jiti}/lib/jiti-register.d.mts +0 -0
- /package/node_modules/{@mariozechner/jiti → jiti}/lib/jiti-register.mjs +0 -0
- /package/node_modules/{@mariozechner/jiti/lib/jiti.mjs → jiti/lib/jiti-static.mjs} +0 -0
- /package/node_modules/{@mariozechner/jiti → jiti}/lib/jiti.cjs +0 -0
- /package/node_modules/{@mariozechner/jiti → jiti}/lib/jiti.d.cts +0 -0
- /package/node_modules/{@mariozechner/jiti → jiti}/lib/jiti.d.mts +0 -0
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
import OpenAI from "openai";
|
|
2
|
-
import { getEnvApiKey } from "../env-api-keys.js";
|
|
3
|
-
import { clampThinkingLevel } from "../models.js";
|
|
4
|
-
import { AssistantMessageEventStream } from "../utils/event-stream.js";
|
|
5
|
-
import { headersToRecord } from "../utils/headers.js";
|
|
6
|
-
import { isCloudflareProvider, resolveCloudflareBaseUrl } from "./cloudflare.js";
|
|
7
|
-
import { buildCopilotDynamicHeaders, hasCopilotVisionInput } from "./github-copilot-headers.js";
|
|
8
|
-
import { convertResponsesMessages, convertResponsesTools, processResponsesStream } from "./openai-responses-shared.js";
|
|
9
|
-
import { buildBaseOptions } from "./simple-options.js";
|
|
10
|
-
const OPENAI_TOOL_CALL_PROVIDERS = new Set(["openai", "openai-codex", "opencode"]);
|
|
11
|
-
/**
|
|
12
|
-
* Resolve cache retention preference.
|
|
13
|
-
* Defaults to "short" and uses PI_CACHE_RETENTION for backward compatibility.
|
|
14
|
-
*/
|
|
15
|
-
function resolveCacheRetention(cacheRetention) {
|
|
16
|
-
if (cacheRetention) {
|
|
17
|
-
return cacheRetention;
|
|
18
|
-
}
|
|
19
|
-
if (typeof process !== "undefined" && process.env.PI_CACHE_RETENTION === "long") {
|
|
20
|
-
return "long";
|
|
21
|
-
}
|
|
22
|
-
return "short";
|
|
23
|
-
}
|
|
24
|
-
function getCompat(model) {
|
|
25
|
-
return {
|
|
26
|
-
sendSessionIdHeader: model.compat?.sendSessionIdHeader ?? true,
|
|
27
|
-
supportsLongCacheRetention: model.compat?.supportsLongCacheRetention ?? true,
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
function getPromptCacheRetention(compat, cacheRetention) {
|
|
31
|
-
return cacheRetention === "long" && compat.supportsLongCacheRetention ? "24h" : undefined;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Generate function for OpenAI Responses API
|
|
35
|
-
*/
|
|
36
|
-
export const streamOpenAIResponses = (model, context, options) => {
|
|
37
|
-
const stream = new AssistantMessageEventStream();
|
|
38
|
-
// Start async processing
|
|
39
|
-
(async () => {
|
|
40
|
-
const output = {
|
|
41
|
-
role: "assistant",
|
|
42
|
-
content: [],
|
|
43
|
-
api: model.api,
|
|
44
|
-
provider: model.provider,
|
|
45
|
-
model: model.id,
|
|
46
|
-
usage: {
|
|
47
|
-
input: 0,
|
|
48
|
-
output: 0,
|
|
49
|
-
cacheRead: 0,
|
|
50
|
-
cacheWrite: 0,
|
|
51
|
-
totalTokens: 0,
|
|
52
|
-
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
|
53
|
-
},
|
|
54
|
-
stopReason: "stop",
|
|
55
|
-
timestamp: Date.now(),
|
|
56
|
-
};
|
|
57
|
-
try {
|
|
58
|
-
// Create OpenAI client
|
|
59
|
-
const apiKey = options?.apiKey || getEnvApiKey(model.provider) || "";
|
|
60
|
-
const cacheRetention = resolveCacheRetention(options?.cacheRetention);
|
|
61
|
-
const cacheSessionId = cacheRetention === "none" ? undefined : options?.sessionId;
|
|
62
|
-
const client = createClient(model, context, apiKey, options?.headers, cacheSessionId);
|
|
63
|
-
let params = buildParams(model, context, options);
|
|
64
|
-
const nextParams = await options?.onPayload?.(params, model);
|
|
65
|
-
if (nextParams !== undefined) {
|
|
66
|
-
params = nextParams;
|
|
67
|
-
}
|
|
68
|
-
const requestOptions = {
|
|
69
|
-
...(options?.signal ? { signal: options.signal } : {}),
|
|
70
|
-
...(options?.timeoutMs !== undefined ? { timeout: options.timeoutMs } : {}),
|
|
71
|
-
...(options?.maxRetries !== undefined ? { maxRetries: options.maxRetries } : {}),
|
|
72
|
-
};
|
|
73
|
-
const { data: openaiStream, response } = await client.responses.create(params, requestOptions).withResponse();
|
|
74
|
-
await options?.onResponse?.({ status: response.status, headers: headersToRecord(response.headers) }, model);
|
|
75
|
-
stream.push({ type: "start", partial: output });
|
|
76
|
-
await processResponsesStream(openaiStream, output, stream, model, {
|
|
77
|
-
serviceTier: options?.serviceTier,
|
|
78
|
-
applyServiceTierPricing: (usage, serviceTier) => applyServiceTierPricing(usage, serviceTier, model),
|
|
79
|
-
});
|
|
80
|
-
if (options?.signal?.aborted) {
|
|
81
|
-
throw new Error("Request was aborted");
|
|
82
|
-
}
|
|
83
|
-
if (output.stopReason === "aborted" || output.stopReason === "error") {
|
|
84
|
-
throw new Error("An unknown error occurred");
|
|
85
|
-
}
|
|
86
|
-
stream.push({ type: "done", reason: output.stopReason, message: output });
|
|
87
|
-
stream.end();
|
|
88
|
-
}
|
|
89
|
-
catch (error) {
|
|
90
|
-
for (const block of output.content) {
|
|
91
|
-
delete block.index;
|
|
92
|
-
// partialJson is only a streaming scratch buffer; never persist it.
|
|
93
|
-
delete block.partialJson;
|
|
94
|
-
}
|
|
95
|
-
output.stopReason = options?.signal?.aborted ? "aborted" : "error";
|
|
96
|
-
output.errorMessage = error instanceof Error ? error.message : JSON.stringify(error);
|
|
97
|
-
stream.push({ type: "error", reason: output.stopReason, error: output });
|
|
98
|
-
stream.end();
|
|
99
|
-
}
|
|
100
|
-
})();
|
|
101
|
-
return stream;
|
|
102
|
-
};
|
|
103
|
-
export const streamSimpleOpenAIResponses = (model, context, options) => {
|
|
104
|
-
const apiKey = options?.apiKey || getEnvApiKey(model.provider);
|
|
105
|
-
if (!apiKey) {
|
|
106
|
-
throw new Error(`No API key for provider: ${model.provider}`);
|
|
107
|
-
}
|
|
108
|
-
const base = buildBaseOptions(model, options, apiKey);
|
|
109
|
-
const clampedReasoning = options?.reasoning ? clampThinkingLevel(model, options.reasoning) : undefined;
|
|
110
|
-
const reasoningEffort = clampedReasoning === "off" ? undefined : clampedReasoning;
|
|
111
|
-
return streamOpenAIResponses(model, context, {
|
|
112
|
-
...base,
|
|
113
|
-
reasoningEffort,
|
|
114
|
-
});
|
|
115
|
-
};
|
|
116
|
-
function createClient(model, context, apiKey, optionsHeaders, sessionId) {
|
|
117
|
-
if (!apiKey) {
|
|
118
|
-
if (!process.env.OPENAI_API_KEY) {
|
|
119
|
-
throw new Error("OpenAI API key is required. Set OPENAI_API_KEY environment variable or pass it as an argument.");
|
|
120
|
-
}
|
|
121
|
-
apiKey = process.env.OPENAI_API_KEY;
|
|
122
|
-
}
|
|
123
|
-
const compat = getCompat(model);
|
|
124
|
-
const headers = { ...model.headers };
|
|
125
|
-
if (model.provider === "github-copilot") {
|
|
126
|
-
const hasImages = hasCopilotVisionInput(context.messages);
|
|
127
|
-
const copilotHeaders = buildCopilotDynamicHeaders({
|
|
128
|
-
messages: context.messages,
|
|
129
|
-
hasImages,
|
|
130
|
-
});
|
|
131
|
-
Object.assign(headers, copilotHeaders);
|
|
132
|
-
}
|
|
133
|
-
if (sessionId) {
|
|
134
|
-
if (compat.sendSessionIdHeader) {
|
|
135
|
-
headers.session_id = sessionId;
|
|
136
|
-
}
|
|
137
|
-
headers["x-client-request-id"] = sessionId;
|
|
138
|
-
}
|
|
139
|
-
// Merge options headers last so they can override defaults
|
|
140
|
-
if (optionsHeaders) {
|
|
141
|
-
Object.assign(headers, optionsHeaders);
|
|
142
|
-
}
|
|
143
|
-
const defaultHeaders = model.provider === "cloudflare-ai-gateway"
|
|
144
|
-
? {
|
|
145
|
-
...headers,
|
|
146
|
-
Authorization: headers.Authorization ?? null,
|
|
147
|
-
"cf-aig-authorization": `Bearer ${apiKey}`,
|
|
148
|
-
}
|
|
149
|
-
: headers;
|
|
150
|
-
return new OpenAI({
|
|
151
|
-
apiKey,
|
|
152
|
-
baseURL: isCloudflareProvider(model.provider) ? resolveCloudflareBaseUrl(model) : model.baseUrl,
|
|
153
|
-
dangerouslyAllowBrowser: true,
|
|
154
|
-
defaultHeaders,
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
function buildParams(model, context, options) {
|
|
158
|
-
const messages = convertResponsesMessages(model, context, OPENAI_TOOL_CALL_PROVIDERS);
|
|
159
|
-
const cacheRetention = resolveCacheRetention(options?.cacheRetention);
|
|
160
|
-
const compat = getCompat(model);
|
|
161
|
-
const params = {
|
|
162
|
-
model: model.id,
|
|
163
|
-
input: messages,
|
|
164
|
-
stream: true,
|
|
165
|
-
prompt_cache_key: cacheRetention === "none" ? undefined : options?.sessionId,
|
|
166
|
-
prompt_cache_retention: getPromptCacheRetention(compat, cacheRetention),
|
|
167
|
-
store: false,
|
|
168
|
-
};
|
|
169
|
-
if (options?.maxTokens) {
|
|
170
|
-
params.max_output_tokens = options?.maxTokens;
|
|
171
|
-
}
|
|
172
|
-
if (options?.temperature !== undefined) {
|
|
173
|
-
params.temperature = options?.temperature;
|
|
174
|
-
}
|
|
175
|
-
if (options?.serviceTier !== undefined) {
|
|
176
|
-
params.service_tier = options.serviceTier;
|
|
177
|
-
}
|
|
178
|
-
if (context.tools && context.tools.length > 0) {
|
|
179
|
-
params.tools = convertResponsesTools(context.tools);
|
|
180
|
-
}
|
|
181
|
-
if (model.reasoning) {
|
|
182
|
-
if (options?.reasoningEffort || options?.reasoningSummary) {
|
|
183
|
-
const effort = options?.reasoningEffort
|
|
184
|
-
? (model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort)
|
|
185
|
-
: "medium";
|
|
186
|
-
params.reasoning = {
|
|
187
|
-
effort: effort,
|
|
188
|
-
summary: options?.reasoningSummary || "auto",
|
|
189
|
-
};
|
|
190
|
-
params.include = ["reasoning.encrypted_content"];
|
|
191
|
-
}
|
|
192
|
-
else if (model.provider !== "github-copilot" && model.thinkingLevelMap?.off !== null) {
|
|
193
|
-
params.reasoning = {
|
|
194
|
-
effort: (model.thinkingLevelMap?.off ?? "none"),
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
return params;
|
|
199
|
-
}
|
|
200
|
-
function getServiceTierCostMultiplier(model, serviceTier) {
|
|
201
|
-
switch (serviceTier) {
|
|
202
|
-
case "flex":
|
|
203
|
-
return 0.5;
|
|
204
|
-
case "priority":
|
|
205
|
-
return model.id === "gpt-5.5" ? 2.5 : 2;
|
|
206
|
-
default:
|
|
207
|
-
return 1;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
function applyServiceTierPricing(usage, serviceTier, model) {
|
|
211
|
-
const multiplier = getServiceTierCostMultiplier(model, serviceTier);
|
|
212
|
-
if (multiplier === 1)
|
|
213
|
-
return;
|
|
214
|
-
usage.cost.input *= multiplier;
|
|
215
|
-
usage.cost.output *= multiplier;
|
|
216
|
-
usage.cost.cacheRead *= multiplier;
|
|
217
|
-
usage.cost.cacheWrite *= multiplier;
|
|
218
|
-
usage.cost.total = usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite;
|
|
219
|
-
}
|
|
220
|
-
//# sourceMappingURL=openai-responses.js.map
|
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
import { clearApiProviders, registerApiProvider } from "../api-registry.js";
|
|
2
|
-
import { AssistantMessageEventStream } from "../utils/event-stream.js";
|
|
3
|
-
const importNodeOnlyProvider = (specifier) => import(specifier);
|
|
4
|
-
let anthropicProviderModulePromise;
|
|
5
|
-
let azureOpenAIResponsesProviderModulePromise;
|
|
6
|
-
let googleProviderModulePromise;
|
|
7
|
-
let googleVertexProviderModulePromise;
|
|
8
|
-
let mistralProviderModulePromise;
|
|
9
|
-
let openAICodexResponsesProviderModulePromise;
|
|
10
|
-
let openAICompletionsProviderModulePromise;
|
|
11
|
-
let openAIResponsesProviderModulePromise;
|
|
12
|
-
let bedrockProviderModuleOverride;
|
|
13
|
-
let bedrockProviderModulePromise;
|
|
14
|
-
export function setBedrockProviderModule(module) {
|
|
15
|
-
bedrockProviderModuleOverride = {
|
|
16
|
-
stream: module.streamBedrock,
|
|
17
|
-
streamSimple: module.streamSimpleBedrock,
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
function forwardStream(target, source) {
|
|
21
|
-
(async () => {
|
|
22
|
-
for await (const event of source) {
|
|
23
|
-
target.push(event);
|
|
24
|
-
}
|
|
25
|
-
target.end();
|
|
26
|
-
})();
|
|
27
|
-
}
|
|
28
|
-
function createLazyLoadErrorMessage(model, error) {
|
|
29
|
-
return {
|
|
30
|
-
role: "assistant",
|
|
31
|
-
content: [],
|
|
32
|
-
api: model.api,
|
|
33
|
-
provider: model.provider,
|
|
34
|
-
model: model.id,
|
|
35
|
-
usage: {
|
|
36
|
-
input: 0,
|
|
37
|
-
output: 0,
|
|
38
|
-
cacheRead: 0,
|
|
39
|
-
cacheWrite: 0,
|
|
40
|
-
totalTokens: 0,
|
|
41
|
-
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
|
42
|
-
},
|
|
43
|
-
stopReason: "error",
|
|
44
|
-
errorMessage: error instanceof Error ? error.message : String(error),
|
|
45
|
-
timestamp: Date.now(),
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
function createLazyStream(loadModule) {
|
|
49
|
-
return (model, context, options) => {
|
|
50
|
-
const outer = new AssistantMessageEventStream();
|
|
51
|
-
loadModule()
|
|
52
|
-
.then((module) => {
|
|
53
|
-
const inner = module.stream(model, context, options);
|
|
54
|
-
forwardStream(outer, inner);
|
|
55
|
-
})
|
|
56
|
-
.catch((error) => {
|
|
57
|
-
const message = createLazyLoadErrorMessage(model, error);
|
|
58
|
-
outer.push({ type: "error", reason: "error", error: message });
|
|
59
|
-
outer.end(message);
|
|
60
|
-
});
|
|
61
|
-
return outer;
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
function createLazySimpleStream(loadModule) {
|
|
65
|
-
return (model, context, options) => {
|
|
66
|
-
const outer = new AssistantMessageEventStream();
|
|
67
|
-
loadModule()
|
|
68
|
-
.then((module) => {
|
|
69
|
-
const inner = module.streamSimple(model, context, options);
|
|
70
|
-
forwardStream(outer, inner);
|
|
71
|
-
})
|
|
72
|
-
.catch((error) => {
|
|
73
|
-
const message = createLazyLoadErrorMessage(model, error);
|
|
74
|
-
outer.push({ type: "error", reason: "error", error: message });
|
|
75
|
-
outer.end(message);
|
|
76
|
-
});
|
|
77
|
-
return outer;
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
function loadAnthropicProviderModule() {
|
|
81
|
-
anthropicProviderModulePromise ||= import("./anthropic.js").then((module) => {
|
|
82
|
-
const provider = module;
|
|
83
|
-
return {
|
|
84
|
-
stream: provider.streamAnthropic,
|
|
85
|
-
streamSimple: provider.streamSimpleAnthropic,
|
|
86
|
-
};
|
|
87
|
-
});
|
|
88
|
-
return anthropicProviderModulePromise;
|
|
89
|
-
}
|
|
90
|
-
function loadAzureOpenAIResponsesProviderModule() {
|
|
91
|
-
azureOpenAIResponsesProviderModulePromise ||= import("./azure-openai-responses.js").then((module) => {
|
|
92
|
-
const provider = module;
|
|
93
|
-
return {
|
|
94
|
-
stream: provider.streamAzureOpenAIResponses,
|
|
95
|
-
streamSimple: provider.streamSimpleAzureOpenAIResponses,
|
|
96
|
-
};
|
|
97
|
-
});
|
|
98
|
-
return azureOpenAIResponsesProviderModulePromise;
|
|
99
|
-
}
|
|
100
|
-
function loadGoogleProviderModule() {
|
|
101
|
-
googleProviderModulePromise ||= import("./google.js").then((module) => {
|
|
102
|
-
const provider = module;
|
|
103
|
-
return {
|
|
104
|
-
stream: provider.streamGoogle,
|
|
105
|
-
streamSimple: provider.streamSimpleGoogle,
|
|
106
|
-
};
|
|
107
|
-
});
|
|
108
|
-
return googleProviderModulePromise;
|
|
109
|
-
}
|
|
110
|
-
function loadGoogleVertexProviderModule() {
|
|
111
|
-
googleVertexProviderModulePromise ||= import("./google-vertex.js").then((module) => {
|
|
112
|
-
const provider = module;
|
|
113
|
-
return {
|
|
114
|
-
stream: provider.streamGoogleVertex,
|
|
115
|
-
streamSimple: provider.streamSimpleGoogleVertex,
|
|
116
|
-
};
|
|
117
|
-
});
|
|
118
|
-
return googleVertexProviderModulePromise;
|
|
119
|
-
}
|
|
120
|
-
function loadMistralProviderModule() {
|
|
121
|
-
mistralProviderModulePromise ||= import("./mistral.js").then((module) => {
|
|
122
|
-
const provider = module;
|
|
123
|
-
return {
|
|
124
|
-
stream: provider.streamMistral,
|
|
125
|
-
streamSimple: provider.streamSimpleMistral,
|
|
126
|
-
};
|
|
127
|
-
});
|
|
128
|
-
return mistralProviderModulePromise;
|
|
129
|
-
}
|
|
130
|
-
function loadOpenAICodexResponsesProviderModule() {
|
|
131
|
-
openAICodexResponsesProviderModulePromise ||= import("./openai-codex-responses.js").then((module) => {
|
|
132
|
-
const provider = module;
|
|
133
|
-
return {
|
|
134
|
-
stream: provider.streamOpenAICodexResponses,
|
|
135
|
-
streamSimple: provider.streamSimpleOpenAICodexResponses,
|
|
136
|
-
};
|
|
137
|
-
});
|
|
138
|
-
return openAICodexResponsesProviderModulePromise;
|
|
139
|
-
}
|
|
140
|
-
function loadOpenAICompletionsProviderModule() {
|
|
141
|
-
openAICompletionsProviderModulePromise ||= import("./openai-completions.js").then((module) => {
|
|
142
|
-
const provider = module;
|
|
143
|
-
return {
|
|
144
|
-
stream: provider.streamOpenAICompletions,
|
|
145
|
-
streamSimple: provider.streamSimpleOpenAICompletions,
|
|
146
|
-
};
|
|
147
|
-
});
|
|
148
|
-
return openAICompletionsProviderModulePromise;
|
|
149
|
-
}
|
|
150
|
-
function loadOpenAIResponsesProviderModule() {
|
|
151
|
-
openAIResponsesProviderModulePromise ||= import("./openai-responses.js").then((module) => {
|
|
152
|
-
const provider = module;
|
|
153
|
-
return {
|
|
154
|
-
stream: provider.streamOpenAIResponses,
|
|
155
|
-
streamSimple: provider.streamSimpleOpenAIResponses,
|
|
156
|
-
};
|
|
157
|
-
});
|
|
158
|
-
return openAIResponsesProviderModulePromise;
|
|
159
|
-
}
|
|
160
|
-
function loadBedrockProviderModule() {
|
|
161
|
-
if (bedrockProviderModuleOverride) {
|
|
162
|
-
return Promise.resolve(bedrockProviderModuleOverride);
|
|
163
|
-
}
|
|
164
|
-
bedrockProviderModulePromise ||= importNodeOnlyProvider("./amazon-bedrock.js").then((module) => {
|
|
165
|
-
const provider = module;
|
|
166
|
-
return {
|
|
167
|
-
stream: provider.streamBedrock,
|
|
168
|
-
streamSimple: provider.streamSimpleBedrock,
|
|
169
|
-
};
|
|
170
|
-
});
|
|
171
|
-
return bedrockProviderModulePromise;
|
|
172
|
-
}
|
|
173
|
-
export const streamAnthropic = createLazyStream(loadAnthropicProviderModule);
|
|
174
|
-
export const streamSimpleAnthropic = createLazySimpleStream(loadAnthropicProviderModule);
|
|
175
|
-
export const streamAzureOpenAIResponses = createLazyStream(loadAzureOpenAIResponsesProviderModule);
|
|
176
|
-
export const streamSimpleAzureOpenAIResponses = createLazySimpleStream(loadAzureOpenAIResponsesProviderModule);
|
|
177
|
-
export const streamGoogle = createLazyStream(loadGoogleProviderModule);
|
|
178
|
-
export const streamSimpleGoogle = createLazySimpleStream(loadGoogleProviderModule);
|
|
179
|
-
export const streamGoogleVertex = createLazyStream(loadGoogleVertexProviderModule);
|
|
180
|
-
export const streamSimpleGoogleVertex = createLazySimpleStream(loadGoogleVertexProviderModule);
|
|
181
|
-
export const streamMistral = createLazyStream(loadMistralProviderModule);
|
|
182
|
-
export const streamSimpleMistral = createLazySimpleStream(loadMistralProviderModule);
|
|
183
|
-
export const streamOpenAICodexResponses = createLazyStream(loadOpenAICodexResponsesProviderModule);
|
|
184
|
-
export const streamSimpleOpenAICodexResponses = createLazySimpleStream(loadOpenAICodexResponsesProviderModule);
|
|
185
|
-
export const streamOpenAICompletions = createLazyStream(loadOpenAICompletionsProviderModule);
|
|
186
|
-
export const streamSimpleOpenAICompletions = createLazySimpleStream(loadOpenAICompletionsProviderModule);
|
|
187
|
-
export const streamOpenAIResponses = createLazyStream(loadOpenAIResponsesProviderModule);
|
|
188
|
-
export const streamSimpleOpenAIResponses = createLazySimpleStream(loadOpenAIResponsesProviderModule);
|
|
189
|
-
const streamBedrockLazy = createLazyStream(loadBedrockProviderModule);
|
|
190
|
-
const streamSimpleBedrockLazy = createLazySimpleStream(loadBedrockProviderModule);
|
|
191
|
-
export function registerBuiltInApiProviders() {
|
|
192
|
-
registerApiProvider({
|
|
193
|
-
api: "anthropic-messages",
|
|
194
|
-
stream: streamAnthropic,
|
|
195
|
-
streamSimple: streamSimpleAnthropic,
|
|
196
|
-
});
|
|
197
|
-
registerApiProvider({
|
|
198
|
-
api: "openai-completions",
|
|
199
|
-
stream: streamOpenAICompletions,
|
|
200
|
-
streamSimple: streamSimpleOpenAICompletions,
|
|
201
|
-
});
|
|
202
|
-
registerApiProvider({
|
|
203
|
-
api: "mistral-conversations",
|
|
204
|
-
stream: streamMistral,
|
|
205
|
-
streamSimple: streamSimpleMistral,
|
|
206
|
-
});
|
|
207
|
-
registerApiProvider({
|
|
208
|
-
api: "openai-responses",
|
|
209
|
-
stream: streamOpenAIResponses,
|
|
210
|
-
streamSimple: streamSimpleOpenAIResponses,
|
|
211
|
-
});
|
|
212
|
-
registerApiProvider({
|
|
213
|
-
api: "azure-openai-responses",
|
|
214
|
-
stream: streamAzureOpenAIResponses,
|
|
215
|
-
streamSimple: streamSimpleAzureOpenAIResponses,
|
|
216
|
-
});
|
|
217
|
-
registerApiProvider({
|
|
218
|
-
api: "openai-codex-responses",
|
|
219
|
-
stream: streamOpenAICodexResponses,
|
|
220
|
-
streamSimple: streamSimpleOpenAICodexResponses,
|
|
221
|
-
});
|
|
222
|
-
registerApiProvider({
|
|
223
|
-
api: "google-generative-ai",
|
|
224
|
-
stream: streamGoogle,
|
|
225
|
-
streamSimple: streamSimpleGoogle,
|
|
226
|
-
});
|
|
227
|
-
registerApiProvider({
|
|
228
|
-
api: "google-vertex",
|
|
229
|
-
stream: streamGoogleVertex,
|
|
230
|
-
streamSimple: streamSimpleGoogleVertex,
|
|
231
|
-
});
|
|
232
|
-
registerApiProvider({
|
|
233
|
-
api: "bedrock-converse-stream",
|
|
234
|
-
stream: streamBedrockLazy,
|
|
235
|
-
streamSimple: streamSimpleBedrockLazy,
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
export function resetApiProviders() {
|
|
239
|
-
clearApiProviders();
|
|
240
|
-
registerBuiltInApiProviders();
|
|
241
|
-
}
|
|
242
|
-
registerBuiltInApiProviders();
|
|
243
|
-
//# sourceMappingURL=register-builtins.js.map
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
export function buildBaseOptions(model, options, apiKey) {
|
|
2
|
-
return {
|
|
3
|
-
temperature: options?.temperature,
|
|
4
|
-
maxTokens: options?.maxTokens ?? (model.maxTokens > 0 ? Math.min(model.maxTokens, 32000) : undefined),
|
|
5
|
-
signal: options?.signal,
|
|
6
|
-
apiKey: apiKey || options?.apiKey,
|
|
7
|
-
transport: options?.transport,
|
|
8
|
-
cacheRetention: options?.cacheRetention,
|
|
9
|
-
sessionId: options?.sessionId,
|
|
10
|
-
headers: options?.headers,
|
|
11
|
-
onPayload: options?.onPayload,
|
|
12
|
-
onResponse: options?.onResponse,
|
|
13
|
-
timeoutMs: options?.timeoutMs,
|
|
14
|
-
maxRetries: options?.maxRetries,
|
|
15
|
-
maxRetryDelayMs: options?.maxRetryDelayMs,
|
|
16
|
-
metadata: options?.metadata,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
export function clampReasoning(effort) {
|
|
20
|
-
return effort === "xhigh" ? "high" : effort;
|
|
21
|
-
}
|
|
22
|
-
export function adjustMaxTokensForThinking(baseMaxTokens, modelMaxTokens, reasoningLevel, customBudgets) {
|
|
23
|
-
const defaultBudgets = {
|
|
24
|
-
minimal: 1024,
|
|
25
|
-
low: 2048,
|
|
26
|
-
medium: 8192,
|
|
27
|
-
high: 16384,
|
|
28
|
-
};
|
|
29
|
-
const budgets = { ...defaultBudgets, ...customBudgets };
|
|
30
|
-
const minOutputTokens = 1024;
|
|
31
|
-
const level = clampReasoning(reasoningLevel);
|
|
32
|
-
let thinkingBudget = budgets[level];
|
|
33
|
-
const maxTokens = Math.min(baseMaxTokens + thinkingBudget, modelMaxTokens);
|
|
34
|
-
if (maxTokens <= thinkingBudget) {
|
|
35
|
-
thinkingBudget = Math.max(0, maxTokens - minOutputTokens);
|
|
36
|
-
}
|
|
37
|
-
return { maxTokens, thinkingBudget };
|
|
38
|
-
}
|
|
39
|
-
//# sourceMappingURL=simple-options.js.map
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
const NON_VISION_USER_IMAGE_PLACEHOLDER = "(image omitted: model does not support images)";
|
|
2
|
-
const NON_VISION_TOOL_IMAGE_PLACEHOLDER = "(tool image omitted: model does not support images)";
|
|
3
|
-
function replaceImagesWithPlaceholder(content, placeholder) {
|
|
4
|
-
const result = [];
|
|
5
|
-
let previousWasPlaceholder = false;
|
|
6
|
-
for (const block of content) {
|
|
7
|
-
if (block.type === "image") {
|
|
8
|
-
if (!previousWasPlaceholder) {
|
|
9
|
-
result.push({ type: "text", text: placeholder });
|
|
10
|
-
}
|
|
11
|
-
previousWasPlaceholder = true;
|
|
12
|
-
continue;
|
|
13
|
-
}
|
|
14
|
-
result.push(block);
|
|
15
|
-
previousWasPlaceholder = block.text === placeholder;
|
|
16
|
-
}
|
|
17
|
-
return result;
|
|
18
|
-
}
|
|
19
|
-
function downgradeUnsupportedImages(messages, model) {
|
|
20
|
-
if (model.input.includes("image")) {
|
|
21
|
-
return messages;
|
|
22
|
-
}
|
|
23
|
-
return messages.map((msg) => {
|
|
24
|
-
if (msg.role === "user" && Array.isArray(msg.content)) {
|
|
25
|
-
return {
|
|
26
|
-
...msg,
|
|
27
|
-
content: replaceImagesWithPlaceholder(msg.content, NON_VISION_USER_IMAGE_PLACEHOLDER),
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
if (msg.role === "toolResult") {
|
|
31
|
-
return {
|
|
32
|
-
...msg,
|
|
33
|
-
content: replaceImagesWithPlaceholder(msg.content, NON_VISION_TOOL_IMAGE_PLACEHOLDER),
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
return msg;
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Normalize tool call ID for cross-provider compatibility.
|
|
41
|
-
* OpenAI Responses API generates IDs that are 450+ chars with special characters like `|`.
|
|
42
|
-
* Anthropic APIs require IDs matching ^[a-zA-Z0-9_-]+$ (max 64 chars).
|
|
43
|
-
*/
|
|
44
|
-
export function transformMessages(messages, model, normalizeToolCallId) {
|
|
45
|
-
// Build a map of original tool call IDs to normalized IDs
|
|
46
|
-
const toolCallIdMap = new Map();
|
|
47
|
-
const imageAwareMessages = downgradeUnsupportedImages(messages, model);
|
|
48
|
-
// First pass: transform messages (unsupported image downgrade, thinking blocks, tool call ID normalization)
|
|
49
|
-
const transformed = imageAwareMessages.map((msg) => {
|
|
50
|
-
// User messages pass through unchanged
|
|
51
|
-
if (msg.role === "user") {
|
|
52
|
-
return msg;
|
|
53
|
-
}
|
|
54
|
-
// Handle toolResult messages - normalize toolCallId if we have a mapping
|
|
55
|
-
if (msg.role === "toolResult") {
|
|
56
|
-
const normalizedId = toolCallIdMap.get(msg.toolCallId);
|
|
57
|
-
if (normalizedId && normalizedId !== msg.toolCallId) {
|
|
58
|
-
return { ...msg, toolCallId: normalizedId };
|
|
59
|
-
}
|
|
60
|
-
return msg;
|
|
61
|
-
}
|
|
62
|
-
// Assistant messages need transformation check
|
|
63
|
-
if (msg.role === "assistant") {
|
|
64
|
-
const assistantMsg = msg;
|
|
65
|
-
const isSameModel = assistantMsg.provider === model.provider &&
|
|
66
|
-
assistantMsg.api === model.api &&
|
|
67
|
-
assistantMsg.model === model.id;
|
|
68
|
-
const transformedContent = assistantMsg.content.flatMap((block) => {
|
|
69
|
-
if (block.type === "thinking") {
|
|
70
|
-
// Redacted thinking is opaque encrypted content, only valid for the same model.
|
|
71
|
-
// Drop it for cross-model to avoid API errors.
|
|
72
|
-
if (block.redacted) {
|
|
73
|
-
return isSameModel ? block : [];
|
|
74
|
-
}
|
|
75
|
-
// For same model: keep thinking blocks with signatures (needed for replay)
|
|
76
|
-
// even if the thinking text is empty (OpenAI encrypted reasoning)
|
|
77
|
-
if (isSameModel && block.thinkingSignature)
|
|
78
|
-
return block;
|
|
79
|
-
// Skip empty thinking blocks, convert others to plain text
|
|
80
|
-
if (!block.thinking || block.thinking.trim() === "")
|
|
81
|
-
return [];
|
|
82
|
-
if (isSameModel)
|
|
83
|
-
return block;
|
|
84
|
-
return {
|
|
85
|
-
type: "text",
|
|
86
|
-
text: block.thinking,
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
if (block.type === "text") {
|
|
90
|
-
if (isSameModel)
|
|
91
|
-
return block;
|
|
92
|
-
return {
|
|
93
|
-
type: "text",
|
|
94
|
-
text: block.text,
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
if (block.type === "toolCall") {
|
|
98
|
-
const toolCall = block;
|
|
99
|
-
let normalizedToolCall = toolCall;
|
|
100
|
-
if (!isSameModel && toolCall.thoughtSignature) {
|
|
101
|
-
normalizedToolCall = { ...toolCall };
|
|
102
|
-
delete normalizedToolCall.thoughtSignature;
|
|
103
|
-
}
|
|
104
|
-
if (!isSameModel && normalizeToolCallId) {
|
|
105
|
-
const normalizedId = normalizeToolCallId(toolCall.id, model, assistantMsg);
|
|
106
|
-
if (normalizedId !== toolCall.id) {
|
|
107
|
-
toolCallIdMap.set(toolCall.id, normalizedId);
|
|
108
|
-
normalizedToolCall = { ...normalizedToolCall, id: normalizedId };
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return normalizedToolCall;
|
|
112
|
-
}
|
|
113
|
-
return block;
|
|
114
|
-
});
|
|
115
|
-
return {
|
|
116
|
-
...assistantMsg,
|
|
117
|
-
content: transformedContent,
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
return msg;
|
|
121
|
-
});
|
|
122
|
-
// Second pass: insert synthetic empty tool results for orphaned tool calls
|
|
123
|
-
// This preserves thinking signatures and satisfies API requirements
|
|
124
|
-
const result = [];
|
|
125
|
-
let pendingToolCalls = [];
|
|
126
|
-
let existingToolResultIds = new Set();
|
|
127
|
-
const insertSyntheticToolResults = () => {
|
|
128
|
-
if (pendingToolCalls.length > 0) {
|
|
129
|
-
for (const tc of pendingToolCalls) {
|
|
130
|
-
if (!existingToolResultIds.has(tc.id)) {
|
|
131
|
-
result.push({
|
|
132
|
-
role: "toolResult",
|
|
133
|
-
toolCallId: tc.id,
|
|
134
|
-
toolName: tc.name,
|
|
135
|
-
content: [{ type: "text", text: "No result provided" }],
|
|
136
|
-
isError: true,
|
|
137
|
-
timestamp: Date.now(),
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
pendingToolCalls = [];
|
|
142
|
-
existingToolResultIds = new Set();
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
for (let i = 0; i < transformed.length; i++) {
|
|
146
|
-
const msg = transformed[i];
|
|
147
|
-
if (msg.role === "assistant") {
|
|
148
|
-
// If we have pending orphaned tool calls from a previous assistant, insert synthetic results now
|
|
149
|
-
insertSyntheticToolResults();
|
|
150
|
-
// Skip errored/aborted assistant messages entirely.
|
|
151
|
-
// These are incomplete turns that shouldn't be replayed:
|
|
152
|
-
// - May have partial content (reasoning without message, incomplete tool calls)
|
|
153
|
-
// - Replaying them can cause API errors (e.g., OpenAI "reasoning without following item")
|
|
154
|
-
// - The model should retry from the last valid state
|
|
155
|
-
const assistantMsg = msg;
|
|
156
|
-
if (assistantMsg.stopReason === "error" || assistantMsg.stopReason === "aborted") {
|
|
157
|
-
continue;
|
|
158
|
-
}
|
|
159
|
-
// Track tool calls from this assistant message
|
|
160
|
-
const toolCalls = assistantMsg.content.filter((b) => b.type === "toolCall");
|
|
161
|
-
if (toolCalls.length > 0) {
|
|
162
|
-
pendingToolCalls = toolCalls;
|
|
163
|
-
existingToolResultIds = new Set();
|
|
164
|
-
}
|
|
165
|
-
result.push(msg);
|
|
166
|
-
}
|
|
167
|
-
else if (msg.role === "toolResult") {
|
|
168
|
-
existingToolResultIds.add(msg.toolCallId);
|
|
169
|
-
result.push(msg);
|
|
170
|
-
}
|
|
171
|
-
else if (msg.role === "user") {
|
|
172
|
-
// User message interrupts tool flow - insert synthetic results for orphaned calls
|
|
173
|
-
insertSyntheticToolResults();
|
|
174
|
-
result.push(msg);
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
result.push(msg);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
// If the conversation ends with unresolved tool calls, synthesize results now.
|
|
181
|
-
insertSyntheticToolResults();
|
|
182
|
-
return result;
|
|
183
|
-
}
|
|
184
|
-
//# sourceMappingURL=transform-messages.js.map
|