@psnext/slingcli 2.4.20260507-3 → 2.4.20260509-2
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 +39 -16
- 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,909 +0,0 @@
|
|
|
1
|
-
// NEVER convert to top-level runtime imports - breaks browser/Vite builds (web-ui)
|
|
2
|
-
let _os = null;
|
|
3
|
-
const dynamicImport = (specifier) => import(specifier);
|
|
4
|
-
const NODE_OS_SPECIFIER = "node:" + "os";
|
|
5
|
-
if (typeof process !== "undefined" && (process.versions?.node || process.versions?.bun)) {
|
|
6
|
-
dynamicImport(NODE_OS_SPECIFIER).then((m) => {
|
|
7
|
-
_os = m;
|
|
8
|
-
});
|
|
9
|
-
}
|
|
10
|
-
import { getEnvApiKey } from "../env-api-keys.js";
|
|
11
|
-
import { clampThinkingLevel } from "../models.js";
|
|
12
|
-
import { AssistantMessageEventStream } from "../utils/event-stream.js";
|
|
13
|
-
import { headersToRecord } from "../utils/headers.js";
|
|
14
|
-
import { convertResponsesMessages, convertResponsesTools, processResponsesStream } from "./openai-responses-shared.js";
|
|
15
|
-
import { buildBaseOptions } from "./simple-options.js";
|
|
16
|
-
// ============================================================================
|
|
17
|
-
// Configuration
|
|
18
|
-
// ============================================================================
|
|
19
|
-
const DEFAULT_CODEX_BASE_URL = "https://chatgpt.com/backend-api";
|
|
20
|
-
const JWT_CLAIM_PATH = "https://api.openai.com/auth";
|
|
21
|
-
const MAX_RETRIES = 3;
|
|
22
|
-
const BASE_DELAY_MS = 1000;
|
|
23
|
-
const CODEX_TOOL_CALL_PROVIDERS = new Set(["openai", "openai-codex", "opencode"]);
|
|
24
|
-
const CODEX_RESPONSE_STATUSES = new Set([
|
|
25
|
-
"completed",
|
|
26
|
-
"incomplete",
|
|
27
|
-
"failed",
|
|
28
|
-
"cancelled",
|
|
29
|
-
"queued",
|
|
30
|
-
"in_progress",
|
|
31
|
-
]);
|
|
32
|
-
// ============================================================================
|
|
33
|
-
// Retry Helpers
|
|
34
|
-
// ============================================================================
|
|
35
|
-
function isRetryableError(status, errorText) {
|
|
36
|
-
if (status === 429 || status === 500 || status === 502 || status === 503 || status === 504) {
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
return /rate.?limit|overloaded|service.?unavailable|upstream.?connect|connection.?refused/i.test(errorText);
|
|
40
|
-
}
|
|
41
|
-
function sleep(ms, signal) {
|
|
42
|
-
return new Promise((resolve, reject) => {
|
|
43
|
-
if (signal?.aborted) {
|
|
44
|
-
reject(new Error("Request was aborted"));
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
const timeout = setTimeout(resolve, ms);
|
|
48
|
-
signal?.addEventListener("abort", () => {
|
|
49
|
-
clearTimeout(timeout);
|
|
50
|
-
reject(new Error("Request was aborted"));
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
// ============================================================================
|
|
55
|
-
// Main Stream Function
|
|
56
|
-
// ============================================================================
|
|
57
|
-
export const streamOpenAICodexResponses = (model, context, options) => {
|
|
58
|
-
const stream = new AssistantMessageEventStream();
|
|
59
|
-
(async () => {
|
|
60
|
-
const output = {
|
|
61
|
-
role: "assistant",
|
|
62
|
-
content: [],
|
|
63
|
-
api: "openai-codex-responses",
|
|
64
|
-
provider: model.provider,
|
|
65
|
-
model: model.id,
|
|
66
|
-
usage: {
|
|
67
|
-
input: 0,
|
|
68
|
-
output: 0,
|
|
69
|
-
cacheRead: 0,
|
|
70
|
-
cacheWrite: 0,
|
|
71
|
-
totalTokens: 0,
|
|
72
|
-
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
|
73
|
-
},
|
|
74
|
-
stopReason: "stop",
|
|
75
|
-
timestamp: Date.now(),
|
|
76
|
-
};
|
|
77
|
-
try {
|
|
78
|
-
const apiKey = options?.apiKey || getEnvApiKey(model.provider) || "";
|
|
79
|
-
if (!apiKey) {
|
|
80
|
-
throw new Error(`No API key for provider: ${model.provider}`);
|
|
81
|
-
}
|
|
82
|
-
const accountId = extractAccountId(apiKey);
|
|
83
|
-
let body = buildRequestBody(model, context, options);
|
|
84
|
-
const nextBody = await options?.onPayload?.(body, model);
|
|
85
|
-
if (nextBody !== undefined) {
|
|
86
|
-
body = nextBody;
|
|
87
|
-
}
|
|
88
|
-
const websocketRequestId = options?.sessionId || createCodexRequestId();
|
|
89
|
-
const sseHeaders = buildSSEHeaders(model.headers, options?.headers, accountId, apiKey, options?.sessionId);
|
|
90
|
-
const websocketHeaders = buildWebSocketHeaders(model.headers, options?.headers, accountId, apiKey, websocketRequestId);
|
|
91
|
-
const bodyJson = JSON.stringify(body);
|
|
92
|
-
const transport = options?.transport || "auto";
|
|
93
|
-
if (transport !== "sse") {
|
|
94
|
-
let websocketStarted = false;
|
|
95
|
-
try {
|
|
96
|
-
await processWebSocketStream(resolveCodexWebSocketUrl(model.baseUrl), body, websocketHeaders, output, stream, model, () => {
|
|
97
|
-
websocketStarted = true;
|
|
98
|
-
}, options);
|
|
99
|
-
if (options?.signal?.aborted) {
|
|
100
|
-
throw new Error("Request was aborted");
|
|
101
|
-
}
|
|
102
|
-
stream.push({
|
|
103
|
-
type: "done",
|
|
104
|
-
reason: output.stopReason,
|
|
105
|
-
message: output,
|
|
106
|
-
});
|
|
107
|
-
stream.end();
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
catch (error) {
|
|
111
|
-
if (transport === "websocket" || transport === "websocket-cached" || websocketStarted) {
|
|
112
|
-
throw error;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
// Fetch with retry logic for rate limits and transient errors
|
|
117
|
-
let response;
|
|
118
|
-
let lastError;
|
|
119
|
-
for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
|
|
120
|
-
if (options?.signal?.aborted) {
|
|
121
|
-
throw new Error("Request was aborted");
|
|
122
|
-
}
|
|
123
|
-
try {
|
|
124
|
-
response = await fetch(resolveCodexUrl(model.baseUrl), {
|
|
125
|
-
method: "POST",
|
|
126
|
-
headers: sseHeaders,
|
|
127
|
-
body: bodyJson,
|
|
128
|
-
signal: options?.signal,
|
|
129
|
-
});
|
|
130
|
-
await options?.onResponse?.({ status: response.status, headers: headersToRecord(response.headers) }, model);
|
|
131
|
-
if (response.ok) {
|
|
132
|
-
break;
|
|
133
|
-
}
|
|
134
|
-
const errorText = await response.text();
|
|
135
|
-
if (attempt < MAX_RETRIES && isRetryableError(response.status, errorText)) {
|
|
136
|
-
const delayMs = BASE_DELAY_MS * 2 ** attempt;
|
|
137
|
-
await sleep(delayMs, options?.signal);
|
|
138
|
-
continue;
|
|
139
|
-
}
|
|
140
|
-
// Parse error for friendly message on final attempt or non-retryable error
|
|
141
|
-
const fakeResponse = new Response(errorText, {
|
|
142
|
-
status: response.status,
|
|
143
|
-
statusText: response.statusText,
|
|
144
|
-
});
|
|
145
|
-
const info = await parseErrorResponse(fakeResponse);
|
|
146
|
-
throw new Error(info.friendlyMessage || info.message);
|
|
147
|
-
}
|
|
148
|
-
catch (error) {
|
|
149
|
-
if (error instanceof Error) {
|
|
150
|
-
if (error.name === "AbortError" || error.message === "Request was aborted") {
|
|
151
|
-
throw new Error("Request was aborted");
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
lastError = error instanceof Error ? error : new Error(String(error));
|
|
155
|
-
// Network errors are retryable
|
|
156
|
-
if (attempt < MAX_RETRIES && !lastError.message.includes("usage limit")) {
|
|
157
|
-
const delayMs = BASE_DELAY_MS * 2 ** attempt;
|
|
158
|
-
await sleep(delayMs, options?.signal);
|
|
159
|
-
continue;
|
|
160
|
-
}
|
|
161
|
-
throw lastError;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
if (!response?.ok) {
|
|
165
|
-
throw lastError ?? new Error("Failed after retries");
|
|
166
|
-
}
|
|
167
|
-
if (!response.body) {
|
|
168
|
-
throw new Error("No response body");
|
|
169
|
-
}
|
|
170
|
-
stream.push({ type: "start", partial: output });
|
|
171
|
-
await processStream(response, output, stream, model, options);
|
|
172
|
-
if (options?.signal?.aborted) {
|
|
173
|
-
throw new Error("Request was aborted");
|
|
174
|
-
}
|
|
175
|
-
stream.push({ type: "done", reason: output.stopReason, message: output });
|
|
176
|
-
stream.end();
|
|
177
|
-
}
|
|
178
|
-
catch (error) {
|
|
179
|
-
for (const block of output.content) {
|
|
180
|
-
// partialJson is only a streaming scratch buffer; never persist it.
|
|
181
|
-
delete block.partialJson;
|
|
182
|
-
}
|
|
183
|
-
output.stopReason = options?.signal?.aborted ? "aborted" : "error";
|
|
184
|
-
output.errorMessage = error instanceof Error ? error.message : String(error);
|
|
185
|
-
stream.push({ type: "error", reason: output.stopReason, error: output });
|
|
186
|
-
stream.end();
|
|
187
|
-
}
|
|
188
|
-
})();
|
|
189
|
-
return stream;
|
|
190
|
-
};
|
|
191
|
-
export const streamSimpleOpenAICodexResponses = (model, context, options) => {
|
|
192
|
-
const apiKey = options?.apiKey || getEnvApiKey(model.provider);
|
|
193
|
-
if (!apiKey) {
|
|
194
|
-
throw new Error(`No API key for provider: ${model.provider}`);
|
|
195
|
-
}
|
|
196
|
-
const base = buildBaseOptions(model, options, apiKey);
|
|
197
|
-
const clampedReasoning = options?.reasoning ? clampThinkingLevel(model, options.reasoning) : undefined;
|
|
198
|
-
const reasoningEffort = clampedReasoning === "off" ? undefined : clampedReasoning;
|
|
199
|
-
return streamOpenAICodexResponses(model, context, {
|
|
200
|
-
...base,
|
|
201
|
-
reasoningEffort,
|
|
202
|
-
});
|
|
203
|
-
};
|
|
204
|
-
// ============================================================================
|
|
205
|
-
// Request Building
|
|
206
|
-
// ============================================================================
|
|
207
|
-
function buildRequestBody(model, context, options) {
|
|
208
|
-
const messages = convertResponsesMessages(model, context, CODEX_TOOL_CALL_PROVIDERS, {
|
|
209
|
-
includeSystemPrompt: false,
|
|
210
|
-
});
|
|
211
|
-
const body = {
|
|
212
|
-
model: model.id,
|
|
213
|
-
store: false,
|
|
214
|
-
stream: true,
|
|
215
|
-
instructions: context.systemPrompt,
|
|
216
|
-
input: messages,
|
|
217
|
-
text: { verbosity: options?.textVerbosity || "low" },
|
|
218
|
-
include: ["reasoning.encrypted_content"],
|
|
219
|
-
prompt_cache_key: options?.sessionId,
|
|
220
|
-
tool_choice: "auto",
|
|
221
|
-
parallel_tool_calls: true,
|
|
222
|
-
};
|
|
223
|
-
if (options?.temperature !== undefined) {
|
|
224
|
-
body.temperature = options.temperature;
|
|
225
|
-
}
|
|
226
|
-
if (options?.serviceTier !== undefined) {
|
|
227
|
-
body.service_tier = options.serviceTier;
|
|
228
|
-
}
|
|
229
|
-
if (context.tools && context.tools.length > 0) {
|
|
230
|
-
body.tools = convertResponsesTools(context.tools, { strict: null });
|
|
231
|
-
}
|
|
232
|
-
if (options?.reasoningEffort !== undefined) {
|
|
233
|
-
const effort = options.reasoningEffort === "none"
|
|
234
|
-
? (model.thinkingLevelMap?.off ?? "none")
|
|
235
|
-
: (model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort);
|
|
236
|
-
if (effort !== null) {
|
|
237
|
-
body.reasoning = {
|
|
238
|
-
effort,
|
|
239
|
-
summary: options.reasoningSummary ?? "auto",
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
return body;
|
|
244
|
-
}
|
|
245
|
-
function getServiceTierCostMultiplier(model, serviceTier) {
|
|
246
|
-
switch (serviceTier) {
|
|
247
|
-
case "flex":
|
|
248
|
-
return 0.5;
|
|
249
|
-
case "priority":
|
|
250
|
-
return model.id === "gpt-5.5" ? 2.5 : 2;
|
|
251
|
-
default:
|
|
252
|
-
return 1;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
function applyServiceTierPricing(usage, serviceTier, model) {
|
|
256
|
-
const multiplier = getServiceTierCostMultiplier(model, serviceTier);
|
|
257
|
-
if (multiplier === 1)
|
|
258
|
-
return;
|
|
259
|
-
usage.cost.input *= multiplier;
|
|
260
|
-
usage.cost.output *= multiplier;
|
|
261
|
-
usage.cost.cacheRead *= multiplier;
|
|
262
|
-
usage.cost.cacheWrite *= multiplier;
|
|
263
|
-
usage.cost.total = usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite;
|
|
264
|
-
}
|
|
265
|
-
function resolveCodexServiceTier(responseServiceTier, requestServiceTier) {
|
|
266
|
-
if (responseServiceTier === "default" && (requestServiceTier === "flex" || requestServiceTier === "priority")) {
|
|
267
|
-
return requestServiceTier;
|
|
268
|
-
}
|
|
269
|
-
return responseServiceTier ?? requestServiceTier;
|
|
270
|
-
}
|
|
271
|
-
function resolveCodexUrl(baseUrl) {
|
|
272
|
-
const raw = baseUrl && baseUrl.trim().length > 0 ? baseUrl : DEFAULT_CODEX_BASE_URL;
|
|
273
|
-
const normalized = raw.replace(/\/+$/, "");
|
|
274
|
-
if (normalized.endsWith("/codex/responses"))
|
|
275
|
-
return normalized;
|
|
276
|
-
if (normalized.endsWith("/codex"))
|
|
277
|
-
return `${normalized}/responses`;
|
|
278
|
-
return `${normalized}/codex/responses`;
|
|
279
|
-
}
|
|
280
|
-
function resolveCodexWebSocketUrl(baseUrl) {
|
|
281
|
-
const url = new URL(resolveCodexUrl(baseUrl));
|
|
282
|
-
if (url.protocol === "https:")
|
|
283
|
-
url.protocol = "wss:";
|
|
284
|
-
if (url.protocol === "http:")
|
|
285
|
-
url.protocol = "ws:";
|
|
286
|
-
return url.toString();
|
|
287
|
-
}
|
|
288
|
-
// ============================================================================
|
|
289
|
-
// Response Processing
|
|
290
|
-
// ============================================================================
|
|
291
|
-
async function processStream(response, output, stream, model, options) {
|
|
292
|
-
await processResponsesStream(mapCodexEvents(parseSSE(response)), output, stream, model, {
|
|
293
|
-
serviceTier: options?.serviceTier,
|
|
294
|
-
resolveServiceTier: resolveCodexServiceTier,
|
|
295
|
-
applyServiceTierPricing: (usage, serviceTier) => applyServiceTierPricing(usage, serviceTier, model),
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
async function* mapCodexEvents(events) {
|
|
299
|
-
for await (const event of events) {
|
|
300
|
-
const type = typeof event.type === "string" ? event.type : undefined;
|
|
301
|
-
if (!type)
|
|
302
|
-
continue;
|
|
303
|
-
if (type === "error") {
|
|
304
|
-
const code = event.code || "";
|
|
305
|
-
const message = event.message || "";
|
|
306
|
-
throw new Error(`Codex error: ${message || code || JSON.stringify(event)}`);
|
|
307
|
-
}
|
|
308
|
-
if (type === "response.failed") {
|
|
309
|
-
const msg = event.response?.error?.message;
|
|
310
|
-
throw new Error(msg || "Codex response failed");
|
|
311
|
-
}
|
|
312
|
-
if (type === "response.done" || type === "response.completed" || type === "response.incomplete") {
|
|
313
|
-
const response = event.response;
|
|
314
|
-
const normalizedResponse = response
|
|
315
|
-
? { ...response, status: normalizeCodexStatus(response.status) }
|
|
316
|
-
: response;
|
|
317
|
-
yield { ...event, type: "response.completed", response: normalizedResponse };
|
|
318
|
-
return;
|
|
319
|
-
}
|
|
320
|
-
yield event;
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
function normalizeCodexStatus(status) {
|
|
324
|
-
if (typeof status !== "string")
|
|
325
|
-
return undefined;
|
|
326
|
-
return CODEX_RESPONSE_STATUSES.has(status) ? status : undefined;
|
|
327
|
-
}
|
|
328
|
-
// ============================================================================
|
|
329
|
-
// SSE Parsing
|
|
330
|
-
// ============================================================================
|
|
331
|
-
async function* parseSSE(response) {
|
|
332
|
-
if (!response.body)
|
|
333
|
-
return;
|
|
334
|
-
const reader = response.body.getReader();
|
|
335
|
-
const decoder = new TextDecoder();
|
|
336
|
-
let buffer = "";
|
|
337
|
-
try {
|
|
338
|
-
while (true) {
|
|
339
|
-
const { done, value } = await reader.read();
|
|
340
|
-
if (done)
|
|
341
|
-
break;
|
|
342
|
-
buffer += decoder.decode(value, { stream: true });
|
|
343
|
-
let idx = buffer.indexOf("\n\n");
|
|
344
|
-
while (idx !== -1) {
|
|
345
|
-
const chunk = buffer.slice(0, idx);
|
|
346
|
-
buffer = buffer.slice(idx + 2);
|
|
347
|
-
const dataLines = chunk
|
|
348
|
-
.split("\n")
|
|
349
|
-
.filter((l) => l.startsWith("data:"))
|
|
350
|
-
.map((l) => l.slice(5).trim());
|
|
351
|
-
if (dataLines.length > 0) {
|
|
352
|
-
const data = dataLines.join("\n").trim();
|
|
353
|
-
if (data && data !== "[DONE]") {
|
|
354
|
-
try {
|
|
355
|
-
yield JSON.parse(data);
|
|
356
|
-
}
|
|
357
|
-
catch { }
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
idx = buffer.indexOf("\n\n");
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
finally {
|
|
365
|
-
try {
|
|
366
|
-
await reader.cancel();
|
|
367
|
-
}
|
|
368
|
-
catch { }
|
|
369
|
-
try {
|
|
370
|
-
reader.releaseLock();
|
|
371
|
-
}
|
|
372
|
-
catch { }
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
// ============================================================================
|
|
376
|
-
// WebSocket Parsing
|
|
377
|
-
// ============================================================================
|
|
378
|
-
const OPENAI_BETA_RESPONSES_WEBSOCKETS = "responses_websockets=2026-02-06";
|
|
379
|
-
const SESSION_WEBSOCKET_CACHE_TTL_MS = 5 * 60 * 1000;
|
|
380
|
-
const websocketSessionCache = new Map();
|
|
381
|
-
const websocketDebugStats = new Map();
|
|
382
|
-
function getOrCreateWebSocketDebugStats(sessionId) {
|
|
383
|
-
let stats = websocketDebugStats.get(sessionId);
|
|
384
|
-
if (!stats) {
|
|
385
|
-
stats = {
|
|
386
|
-
requests: 0,
|
|
387
|
-
connectionsCreated: 0,
|
|
388
|
-
connectionsReused: 0,
|
|
389
|
-
cachedContextRequests: 0,
|
|
390
|
-
storeTrueRequests: 0,
|
|
391
|
-
fullContextRequests: 0,
|
|
392
|
-
deltaRequests: 0,
|
|
393
|
-
lastInputItems: 0,
|
|
394
|
-
};
|
|
395
|
-
websocketDebugStats.set(sessionId, stats);
|
|
396
|
-
}
|
|
397
|
-
return stats;
|
|
398
|
-
}
|
|
399
|
-
export function getOpenAICodexWebSocketDebugStats(sessionId) {
|
|
400
|
-
const stats = websocketDebugStats.get(sessionId);
|
|
401
|
-
return stats ? { ...stats } : undefined;
|
|
402
|
-
}
|
|
403
|
-
export function resetOpenAICodexWebSocketDebugStats(sessionId) {
|
|
404
|
-
if (sessionId) {
|
|
405
|
-
websocketDebugStats.delete(sessionId);
|
|
406
|
-
return;
|
|
407
|
-
}
|
|
408
|
-
websocketDebugStats.clear();
|
|
409
|
-
}
|
|
410
|
-
export function closeOpenAICodexWebSocketSessions(sessionId) {
|
|
411
|
-
const closeEntry = (entry) => {
|
|
412
|
-
if (entry.idleTimer)
|
|
413
|
-
clearTimeout(entry.idleTimer);
|
|
414
|
-
closeWebSocketSilently(entry.socket, 1000, "debug_close");
|
|
415
|
-
};
|
|
416
|
-
if (sessionId) {
|
|
417
|
-
const entry = websocketSessionCache.get(sessionId);
|
|
418
|
-
if (entry)
|
|
419
|
-
closeEntry(entry);
|
|
420
|
-
websocketSessionCache.delete(sessionId);
|
|
421
|
-
return;
|
|
422
|
-
}
|
|
423
|
-
for (const entry of websocketSessionCache.values()) {
|
|
424
|
-
closeEntry(entry);
|
|
425
|
-
}
|
|
426
|
-
websocketSessionCache.clear();
|
|
427
|
-
}
|
|
428
|
-
function getWebSocketConstructor() {
|
|
429
|
-
const ctor = globalThis.WebSocket;
|
|
430
|
-
if (typeof ctor !== "function")
|
|
431
|
-
return null;
|
|
432
|
-
return ctor;
|
|
433
|
-
}
|
|
434
|
-
function getWebSocketReadyState(socket) {
|
|
435
|
-
const readyState = socket.readyState;
|
|
436
|
-
return typeof readyState === "number" ? readyState : undefined;
|
|
437
|
-
}
|
|
438
|
-
function isWebSocketReusable(socket) {
|
|
439
|
-
const readyState = getWebSocketReadyState(socket);
|
|
440
|
-
// If readyState is unavailable, assume the runtime keeps it open/reusable.
|
|
441
|
-
return readyState === undefined || readyState === 1;
|
|
442
|
-
}
|
|
443
|
-
function closeWebSocketSilently(socket, code = 1000, reason = "done") {
|
|
444
|
-
try {
|
|
445
|
-
socket.close(code, reason);
|
|
446
|
-
}
|
|
447
|
-
catch { }
|
|
448
|
-
}
|
|
449
|
-
function scheduleSessionWebSocketExpiry(sessionId, entry) {
|
|
450
|
-
if (entry.idleTimer) {
|
|
451
|
-
clearTimeout(entry.idleTimer);
|
|
452
|
-
}
|
|
453
|
-
entry.idleTimer = setTimeout(() => {
|
|
454
|
-
if (entry.busy)
|
|
455
|
-
return;
|
|
456
|
-
closeWebSocketSilently(entry.socket, 1000, "idle_timeout");
|
|
457
|
-
websocketSessionCache.delete(sessionId);
|
|
458
|
-
}, SESSION_WEBSOCKET_CACHE_TTL_MS);
|
|
459
|
-
}
|
|
460
|
-
async function connectWebSocket(url, headers, signal) {
|
|
461
|
-
const WebSocketCtor = getWebSocketConstructor();
|
|
462
|
-
if (!WebSocketCtor) {
|
|
463
|
-
throw new Error("WebSocket transport is not available in this runtime");
|
|
464
|
-
}
|
|
465
|
-
const wsHeaders = headersToRecord(headers);
|
|
466
|
-
delete wsHeaders["OpenAI-Beta"];
|
|
467
|
-
return new Promise((resolve, reject) => {
|
|
468
|
-
let settled = false;
|
|
469
|
-
let socket;
|
|
470
|
-
try {
|
|
471
|
-
socket = new WebSocketCtor(url, { headers: wsHeaders });
|
|
472
|
-
}
|
|
473
|
-
catch (error) {
|
|
474
|
-
reject(error instanceof Error ? error : new Error(String(error)));
|
|
475
|
-
return;
|
|
476
|
-
}
|
|
477
|
-
const onOpen = () => {
|
|
478
|
-
if (settled)
|
|
479
|
-
return;
|
|
480
|
-
settled = true;
|
|
481
|
-
cleanup();
|
|
482
|
-
resolve(socket);
|
|
483
|
-
};
|
|
484
|
-
const onError = (event) => {
|
|
485
|
-
const error = extractWebSocketError(event);
|
|
486
|
-
if (settled)
|
|
487
|
-
return;
|
|
488
|
-
settled = true;
|
|
489
|
-
cleanup();
|
|
490
|
-
reject(error);
|
|
491
|
-
};
|
|
492
|
-
const onClose = (event) => {
|
|
493
|
-
const error = extractWebSocketCloseError(event);
|
|
494
|
-
if (settled)
|
|
495
|
-
return;
|
|
496
|
-
settled = true;
|
|
497
|
-
cleanup();
|
|
498
|
-
reject(error);
|
|
499
|
-
};
|
|
500
|
-
const onAbort = () => {
|
|
501
|
-
if (settled)
|
|
502
|
-
return;
|
|
503
|
-
settled = true;
|
|
504
|
-
cleanup();
|
|
505
|
-
socket.close(1000, "aborted");
|
|
506
|
-
reject(new Error("Request was aborted"));
|
|
507
|
-
};
|
|
508
|
-
const cleanup = () => {
|
|
509
|
-
socket.removeEventListener("open", onOpen);
|
|
510
|
-
socket.removeEventListener("error", onError);
|
|
511
|
-
socket.removeEventListener("close", onClose);
|
|
512
|
-
signal?.removeEventListener("abort", onAbort);
|
|
513
|
-
};
|
|
514
|
-
socket.addEventListener("open", onOpen);
|
|
515
|
-
socket.addEventListener("error", onError);
|
|
516
|
-
socket.addEventListener("close", onClose);
|
|
517
|
-
signal?.addEventListener("abort", onAbort);
|
|
518
|
-
});
|
|
519
|
-
}
|
|
520
|
-
async function acquireWebSocket(url, headers, sessionId, signal) {
|
|
521
|
-
if (!sessionId) {
|
|
522
|
-
const socket = await connectWebSocket(url, headers, signal);
|
|
523
|
-
return {
|
|
524
|
-
socket,
|
|
525
|
-
reused: false,
|
|
526
|
-
release: ({ keep } = {}) => {
|
|
527
|
-
if (keep === false) {
|
|
528
|
-
closeWebSocketSilently(socket);
|
|
529
|
-
return;
|
|
530
|
-
}
|
|
531
|
-
closeWebSocketSilently(socket);
|
|
532
|
-
},
|
|
533
|
-
};
|
|
534
|
-
}
|
|
535
|
-
const cached = websocketSessionCache.get(sessionId);
|
|
536
|
-
if (cached) {
|
|
537
|
-
if (cached.idleTimer) {
|
|
538
|
-
clearTimeout(cached.idleTimer);
|
|
539
|
-
cached.idleTimer = undefined;
|
|
540
|
-
}
|
|
541
|
-
if (!cached.busy && isWebSocketReusable(cached.socket)) {
|
|
542
|
-
cached.busy = true;
|
|
543
|
-
return {
|
|
544
|
-
socket: cached.socket,
|
|
545
|
-
entry: cached,
|
|
546
|
-
reused: true,
|
|
547
|
-
release: ({ keep } = {}) => {
|
|
548
|
-
if (!keep || !isWebSocketReusable(cached.socket)) {
|
|
549
|
-
closeWebSocketSilently(cached.socket);
|
|
550
|
-
websocketSessionCache.delete(sessionId);
|
|
551
|
-
return;
|
|
552
|
-
}
|
|
553
|
-
cached.busy = false;
|
|
554
|
-
scheduleSessionWebSocketExpiry(sessionId, cached);
|
|
555
|
-
},
|
|
556
|
-
};
|
|
557
|
-
}
|
|
558
|
-
if (cached.busy) {
|
|
559
|
-
const socket = await connectWebSocket(url, headers, signal);
|
|
560
|
-
return {
|
|
561
|
-
socket,
|
|
562
|
-
reused: false,
|
|
563
|
-
release: () => {
|
|
564
|
-
closeWebSocketSilently(socket);
|
|
565
|
-
},
|
|
566
|
-
};
|
|
567
|
-
}
|
|
568
|
-
if (!isWebSocketReusable(cached.socket)) {
|
|
569
|
-
closeWebSocketSilently(cached.socket);
|
|
570
|
-
websocketSessionCache.delete(sessionId);
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
const socket = await connectWebSocket(url, headers, signal);
|
|
574
|
-
const entry = { socket, busy: true };
|
|
575
|
-
websocketSessionCache.set(sessionId, entry);
|
|
576
|
-
return {
|
|
577
|
-
socket,
|
|
578
|
-
entry,
|
|
579
|
-
reused: false,
|
|
580
|
-
release: ({ keep } = {}) => {
|
|
581
|
-
if (!keep || !isWebSocketReusable(entry.socket)) {
|
|
582
|
-
closeWebSocketSilently(entry.socket);
|
|
583
|
-
if (entry.idleTimer)
|
|
584
|
-
clearTimeout(entry.idleTimer);
|
|
585
|
-
if (websocketSessionCache.get(sessionId) === entry) {
|
|
586
|
-
websocketSessionCache.delete(sessionId);
|
|
587
|
-
}
|
|
588
|
-
return;
|
|
589
|
-
}
|
|
590
|
-
entry.busy = false;
|
|
591
|
-
scheduleSessionWebSocketExpiry(sessionId, entry);
|
|
592
|
-
},
|
|
593
|
-
};
|
|
594
|
-
}
|
|
595
|
-
function extractWebSocketError(event) {
|
|
596
|
-
if (event && typeof event === "object" && "message" in event) {
|
|
597
|
-
const message = event.message;
|
|
598
|
-
if (typeof message === "string" && message.length > 0) {
|
|
599
|
-
return new Error(message);
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
return new Error("WebSocket error");
|
|
603
|
-
}
|
|
604
|
-
function extractWebSocketCloseError(event) {
|
|
605
|
-
if (event && typeof event === "object") {
|
|
606
|
-
const code = "code" in event ? event.code : undefined;
|
|
607
|
-
const reason = "reason" in event ? event.reason : undefined;
|
|
608
|
-
const codeText = typeof code === "number" ? ` ${code}` : "";
|
|
609
|
-
const reasonText = typeof reason === "string" && reason.length > 0 ? ` ${reason}` : "";
|
|
610
|
-
return new Error(`WebSocket closed${codeText}${reasonText}`.trim());
|
|
611
|
-
}
|
|
612
|
-
return new Error("WebSocket closed");
|
|
613
|
-
}
|
|
614
|
-
async function decodeWebSocketData(data) {
|
|
615
|
-
if (typeof data === "string")
|
|
616
|
-
return data;
|
|
617
|
-
if (data instanceof ArrayBuffer) {
|
|
618
|
-
return new TextDecoder().decode(new Uint8Array(data));
|
|
619
|
-
}
|
|
620
|
-
if (ArrayBuffer.isView(data)) {
|
|
621
|
-
const view = data;
|
|
622
|
-
return new TextDecoder().decode(new Uint8Array(view.buffer, view.byteOffset, view.byteLength));
|
|
623
|
-
}
|
|
624
|
-
if (data && typeof data === "object" && "arrayBuffer" in data) {
|
|
625
|
-
const blobLike = data;
|
|
626
|
-
const arrayBuffer = await blobLike.arrayBuffer();
|
|
627
|
-
return new TextDecoder().decode(new Uint8Array(arrayBuffer));
|
|
628
|
-
}
|
|
629
|
-
return null;
|
|
630
|
-
}
|
|
631
|
-
async function* parseWebSocket(socket, signal) {
|
|
632
|
-
const queue = [];
|
|
633
|
-
let pending = null;
|
|
634
|
-
let done = false;
|
|
635
|
-
let failed = null;
|
|
636
|
-
let sawCompletion = false;
|
|
637
|
-
const wake = () => {
|
|
638
|
-
if (!pending)
|
|
639
|
-
return;
|
|
640
|
-
const resolve = pending;
|
|
641
|
-
pending = null;
|
|
642
|
-
resolve();
|
|
643
|
-
};
|
|
644
|
-
const onMessage = (event) => {
|
|
645
|
-
void (async () => {
|
|
646
|
-
if (!event || typeof event !== "object" || !("data" in event))
|
|
647
|
-
return;
|
|
648
|
-
const text = await decodeWebSocketData(event.data);
|
|
649
|
-
if (!text)
|
|
650
|
-
return;
|
|
651
|
-
try {
|
|
652
|
-
const parsed = JSON.parse(text);
|
|
653
|
-
const type = typeof parsed.type === "string" ? parsed.type : "";
|
|
654
|
-
if (type === "response.completed" || type === "response.done" || type === "response.incomplete") {
|
|
655
|
-
sawCompletion = true;
|
|
656
|
-
done = true;
|
|
657
|
-
}
|
|
658
|
-
queue.push(parsed);
|
|
659
|
-
wake();
|
|
660
|
-
}
|
|
661
|
-
catch { }
|
|
662
|
-
})();
|
|
663
|
-
};
|
|
664
|
-
const onError = (event) => {
|
|
665
|
-
failed = extractWebSocketError(event);
|
|
666
|
-
done = true;
|
|
667
|
-
wake();
|
|
668
|
-
};
|
|
669
|
-
const onClose = (event) => {
|
|
670
|
-
if (sawCompletion) {
|
|
671
|
-
done = true;
|
|
672
|
-
wake();
|
|
673
|
-
return;
|
|
674
|
-
}
|
|
675
|
-
if (!failed) {
|
|
676
|
-
failed = extractWebSocketCloseError(event);
|
|
677
|
-
}
|
|
678
|
-
done = true;
|
|
679
|
-
wake();
|
|
680
|
-
};
|
|
681
|
-
const onAbort = () => {
|
|
682
|
-
failed = new Error("Request was aborted");
|
|
683
|
-
done = true;
|
|
684
|
-
wake();
|
|
685
|
-
};
|
|
686
|
-
socket.addEventListener("message", onMessage);
|
|
687
|
-
socket.addEventListener("error", onError);
|
|
688
|
-
socket.addEventListener("close", onClose);
|
|
689
|
-
signal?.addEventListener("abort", onAbort);
|
|
690
|
-
try {
|
|
691
|
-
while (true) {
|
|
692
|
-
if (signal?.aborted) {
|
|
693
|
-
throw new Error("Request was aborted");
|
|
694
|
-
}
|
|
695
|
-
if (queue.length > 0) {
|
|
696
|
-
yield queue.shift();
|
|
697
|
-
continue;
|
|
698
|
-
}
|
|
699
|
-
if (done)
|
|
700
|
-
break;
|
|
701
|
-
await new Promise((resolve) => {
|
|
702
|
-
pending = resolve;
|
|
703
|
-
});
|
|
704
|
-
}
|
|
705
|
-
if (failed) {
|
|
706
|
-
throw failed;
|
|
707
|
-
}
|
|
708
|
-
if (!sawCompletion) {
|
|
709
|
-
throw new Error("WebSocket stream closed before response.completed");
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
finally {
|
|
713
|
-
socket.removeEventListener("message", onMessage);
|
|
714
|
-
socket.removeEventListener("error", onError);
|
|
715
|
-
socket.removeEventListener("close", onClose);
|
|
716
|
-
signal?.removeEventListener("abort", onAbort);
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
function requestBodyWithoutInput(body) {
|
|
720
|
-
const { input: _input, previous_response_id: _previousResponseId, ...rest } = body;
|
|
721
|
-
return rest;
|
|
722
|
-
}
|
|
723
|
-
function responseInputsEqual(a, b) {
|
|
724
|
-
return JSON.stringify(a ?? []) === JSON.stringify(b ?? []);
|
|
725
|
-
}
|
|
726
|
-
function requestBodiesMatchExceptInput(a, b) {
|
|
727
|
-
return JSON.stringify(requestBodyWithoutInput(a)) === JSON.stringify(requestBodyWithoutInput(b));
|
|
728
|
-
}
|
|
729
|
-
function getCachedWebSocketInputDelta(body, continuation) {
|
|
730
|
-
if (!requestBodiesMatchExceptInput(body, continuation.lastRequestBody)) {
|
|
731
|
-
return undefined;
|
|
732
|
-
}
|
|
733
|
-
const currentInput = body.input ?? [];
|
|
734
|
-
const baseline = [...(continuation.lastRequestBody.input ?? []), ...continuation.lastResponseItems];
|
|
735
|
-
if (currentInput.length < baseline.length) {
|
|
736
|
-
return undefined;
|
|
737
|
-
}
|
|
738
|
-
const prefix = currentInput.slice(0, baseline.length);
|
|
739
|
-
if (!responseInputsEqual(prefix, baseline)) {
|
|
740
|
-
return undefined;
|
|
741
|
-
}
|
|
742
|
-
return currentInput.slice(baseline.length);
|
|
743
|
-
}
|
|
744
|
-
function buildCachedWebSocketRequestBody(entry, body) {
|
|
745
|
-
const continuation = entry.continuation;
|
|
746
|
-
if (!continuation) {
|
|
747
|
-
return body;
|
|
748
|
-
}
|
|
749
|
-
const delta = getCachedWebSocketInputDelta(body, continuation);
|
|
750
|
-
if (!delta || !continuation.lastResponseId) {
|
|
751
|
-
entry.continuation = undefined;
|
|
752
|
-
return body;
|
|
753
|
-
}
|
|
754
|
-
return {
|
|
755
|
-
...body,
|
|
756
|
-
previous_response_id: continuation.lastResponseId,
|
|
757
|
-
input: delta,
|
|
758
|
-
};
|
|
759
|
-
}
|
|
760
|
-
async function processWebSocketStream(url, body, headers, output, stream, model, onStart, options) {
|
|
761
|
-
const { socket, entry, reused, release } = await acquireWebSocket(url, headers, options?.sessionId, options?.signal);
|
|
762
|
-
let keepConnection = true;
|
|
763
|
-
const useCachedContext = options?.transport === "websocket-cached" || options?.transport === "auto";
|
|
764
|
-
// ChatGPT Codex Responses rejects `store: true` ("Store must be set to false").
|
|
765
|
-
// WebSocket continuation still works via connection-scoped previous_response_id state.
|
|
766
|
-
const fullBody = body;
|
|
767
|
-
const requestBody = useCachedContext && entry ? buildCachedWebSocketRequestBody(entry, fullBody) : fullBody;
|
|
768
|
-
const stats = options?.sessionId ? getOrCreateWebSocketDebugStats(options.sessionId) : undefined;
|
|
769
|
-
if (stats) {
|
|
770
|
-
stats.requests++;
|
|
771
|
-
if (reused)
|
|
772
|
-
stats.connectionsReused++;
|
|
773
|
-
else
|
|
774
|
-
stats.connectionsCreated++;
|
|
775
|
-
if (useCachedContext)
|
|
776
|
-
stats.cachedContextRequests++;
|
|
777
|
-
if (requestBody.store === true)
|
|
778
|
-
stats.storeTrueRequests++;
|
|
779
|
-
stats.lastInputItems = requestBody.input?.length ?? 0;
|
|
780
|
-
if (requestBody.previous_response_id) {
|
|
781
|
-
stats.deltaRequests++;
|
|
782
|
-
stats.lastDeltaInputItems = requestBody.input?.length ?? 0;
|
|
783
|
-
stats.lastPreviousResponseId = requestBody.previous_response_id;
|
|
784
|
-
}
|
|
785
|
-
else {
|
|
786
|
-
stats.fullContextRequests++;
|
|
787
|
-
stats.lastDeltaInputItems = undefined;
|
|
788
|
-
stats.lastPreviousResponseId = undefined;
|
|
789
|
-
}
|
|
790
|
-
}
|
|
791
|
-
try {
|
|
792
|
-
socket.send(JSON.stringify({ type: "response.create", ...requestBody }));
|
|
793
|
-
onStart();
|
|
794
|
-
stream.push({ type: "start", partial: output });
|
|
795
|
-
await processResponsesStream(mapCodexEvents(parseWebSocket(socket, options?.signal)), output, stream, model, {
|
|
796
|
-
serviceTier: options?.serviceTier,
|
|
797
|
-
resolveServiceTier: resolveCodexServiceTier,
|
|
798
|
-
applyServiceTierPricing: (usage, serviceTier) => applyServiceTierPricing(usage, serviceTier, model),
|
|
799
|
-
});
|
|
800
|
-
if (options?.signal?.aborted) {
|
|
801
|
-
keepConnection = false;
|
|
802
|
-
}
|
|
803
|
-
else if (useCachedContext && entry && output.responseId) {
|
|
804
|
-
const responseItems = convertResponsesMessages(model, { messages: [output] }, CODEX_TOOL_CALL_PROVIDERS, {
|
|
805
|
-
includeSystemPrompt: false,
|
|
806
|
-
}).filter((item) => item.type !== "function_call_output");
|
|
807
|
-
entry.continuation = {
|
|
808
|
-
lastRequestBody: fullBody,
|
|
809
|
-
lastResponseId: output.responseId,
|
|
810
|
-
lastResponseItems: responseItems,
|
|
811
|
-
};
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
catch (error) {
|
|
815
|
-
if (entry) {
|
|
816
|
-
entry.continuation = undefined;
|
|
817
|
-
}
|
|
818
|
-
keepConnection = false;
|
|
819
|
-
throw error;
|
|
820
|
-
}
|
|
821
|
-
finally {
|
|
822
|
-
release({ keep: keepConnection });
|
|
823
|
-
}
|
|
824
|
-
}
|
|
825
|
-
// ============================================================================
|
|
826
|
-
// Error Handling
|
|
827
|
-
// ============================================================================
|
|
828
|
-
async function parseErrorResponse(response) {
|
|
829
|
-
const raw = await response.text();
|
|
830
|
-
let message = raw || response.statusText || "Request failed";
|
|
831
|
-
let friendlyMessage;
|
|
832
|
-
try {
|
|
833
|
-
const parsed = JSON.parse(raw);
|
|
834
|
-
const err = parsed?.error;
|
|
835
|
-
if (err) {
|
|
836
|
-
const code = err.code || err.type || "";
|
|
837
|
-
if (/usage_limit_reached|usage_not_included|rate_limit_exceeded/i.test(code) || response.status === 429) {
|
|
838
|
-
const plan = err.plan_type ? ` (${err.plan_type.toLowerCase()} plan)` : "";
|
|
839
|
-
const mins = err.resets_at
|
|
840
|
-
? Math.max(0, Math.round((err.resets_at * 1000 - Date.now()) / 60000))
|
|
841
|
-
: undefined;
|
|
842
|
-
const when = mins !== undefined ? ` Try again in ~${mins} min.` : "";
|
|
843
|
-
friendlyMessage = `You have hit your ChatGPT usage limit${plan}.${when}`.trim();
|
|
844
|
-
}
|
|
845
|
-
message = err.message || friendlyMessage || message;
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
catch { }
|
|
849
|
-
return { message, friendlyMessage };
|
|
850
|
-
}
|
|
851
|
-
// ============================================================================
|
|
852
|
-
// Auth & Headers
|
|
853
|
-
// ============================================================================
|
|
854
|
-
function extractAccountId(token) {
|
|
855
|
-
try {
|
|
856
|
-
const parts = token.split(".");
|
|
857
|
-
if (parts.length !== 3)
|
|
858
|
-
throw new Error("Invalid token");
|
|
859
|
-
const payload = JSON.parse(atob(parts[1]));
|
|
860
|
-
const accountId = payload?.[JWT_CLAIM_PATH]?.chatgpt_account_id;
|
|
861
|
-
if (!accountId)
|
|
862
|
-
throw new Error("No account ID in token");
|
|
863
|
-
return accountId;
|
|
864
|
-
}
|
|
865
|
-
catch {
|
|
866
|
-
throw new Error("Failed to extract accountId from token");
|
|
867
|
-
}
|
|
868
|
-
}
|
|
869
|
-
function createCodexRequestId() {
|
|
870
|
-
if (typeof globalThis.crypto?.randomUUID === "function") {
|
|
871
|
-
return globalThis.crypto.randomUUID();
|
|
872
|
-
}
|
|
873
|
-
return `codex_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`;
|
|
874
|
-
}
|
|
875
|
-
function buildBaseCodexHeaders(initHeaders, additionalHeaders, accountId, token) {
|
|
876
|
-
const headers = new Headers(initHeaders);
|
|
877
|
-
for (const [key, value] of Object.entries(additionalHeaders || {})) {
|
|
878
|
-
headers.set(key, value);
|
|
879
|
-
}
|
|
880
|
-
headers.set("Authorization", `Bearer ${token}`);
|
|
881
|
-
headers.set("chatgpt-account-id", accountId);
|
|
882
|
-
headers.set("originator", "pi");
|
|
883
|
-
const userAgent = _os ? `pi (${_os.platform()} ${_os.release()}; ${_os.arch()})` : "pi (browser)";
|
|
884
|
-
headers.set("User-Agent", userAgent);
|
|
885
|
-
return headers;
|
|
886
|
-
}
|
|
887
|
-
function buildSSEHeaders(initHeaders, additionalHeaders, accountId, token, sessionId) {
|
|
888
|
-
const headers = buildBaseCodexHeaders(initHeaders, additionalHeaders, accountId, token);
|
|
889
|
-
headers.set("OpenAI-Beta", "responses=experimental");
|
|
890
|
-
headers.set("accept", "text/event-stream");
|
|
891
|
-
headers.set("content-type", "application/json");
|
|
892
|
-
if (sessionId) {
|
|
893
|
-
headers.set("session_id", sessionId);
|
|
894
|
-
headers.set("x-client-request-id", sessionId);
|
|
895
|
-
}
|
|
896
|
-
return headers;
|
|
897
|
-
}
|
|
898
|
-
function buildWebSocketHeaders(initHeaders, additionalHeaders, accountId, token, requestId) {
|
|
899
|
-
const headers = buildBaseCodexHeaders(initHeaders, additionalHeaders, accountId, token);
|
|
900
|
-
headers.delete("accept");
|
|
901
|
-
headers.delete("content-type");
|
|
902
|
-
headers.delete("OpenAI-Beta");
|
|
903
|
-
headers.delete("openai-beta");
|
|
904
|
-
headers.set("OpenAI-Beta", OPENAI_BETA_RESPONSES_WEBSOCKETS);
|
|
905
|
-
headers.set("x-client-request-id", requestId);
|
|
906
|
-
headers.set("session_id", requestId);
|
|
907
|
-
return headers;
|
|
908
|
-
}
|
|
909
|
-
//# sourceMappingURL=openai-codex-responses.js.map
|