indusagi 0.12.32 → 0.12.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +340 -0
- package/CREDITS.md +22 -0
- package/NOTICE +17 -0
- package/README.md +47 -388
- package/dist/agent.js +27512 -0
- package/dist/ai.js +19758 -0
- package/dist/capabilities.js +2663 -0
- package/dist/cli.js +11653 -0
- package/dist/connectors-saas.js +3289 -0
- package/dist/index.js +16533 -0
- package/dist/interop.js +3181 -0
- package/dist/knowledge/guides/authoring-an-agent.md +53 -0
- package/dist/knowledge/guides/choosing-tools.md +49 -0
- package/dist/knowledge/guides/model-selection.md +51 -0
- package/dist/knowledge/guides/writing-system-prompts.md +53 -0
- package/dist/knowledge/index.ts +19 -0
- package/dist/knowledge/loader.ts +200 -0
- package/dist/knowledge/manifest.json +29 -0
- package/dist/llmgateway.js +3209 -0
- package/dist/mcp.js +1732 -0
- package/dist/memory.js +0 -0
- package/dist/react-host/index.js +101 -0
- package/dist/react-host/ink.js +97 -0
- package/dist/react-host/jsx-runtime.js +95 -0
- package/dist/react-ink.js +3821 -0
- package/dist/runtime.js +4387 -0
- package/dist/shell-app.js +12222 -0
- package/dist/smithy.js +7932 -0
- package/dist/swarm.js +8717 -0
- package/dist/tracing.js +724 -0
- package/dist/tui.js +2213 -0
- package/dist/types/capabilities/backends/index.d.ts +10 -0
- package/dist/types/capabilities/backends/node-backends.d.ts +28 -0
- package/dist/types/capabilities/capabilities.test.d.ts +14 -0
- package/dist/types/capabilities/files/diff.d.ts +49 -0
- package/dist/types/capabilities/files/edit.d.ts +21 -0
- package/dist/types/capabilities/files/ls.d.ts +16 -0
- package/dist/types/capabilities/files/read.d.ts +15 -0
- package/dist/types/capabilities/files/write.d.ts +16 -0
- package/dist/types/capabilities/index.d.ts +29 -0
- package/dist/types/capabilities/kernel/backends.d.ts +119 -0
- package/dist/types/capabilities/kernel/context.d.ts +48 -0
- package/dist/types/capabilities/kernel/index.d.ts +24 -0
- package/dist/types/capabilities/kernel/output.d.ts +40 -0
- package/dist/types/capabilities/kernel/registry.d.ts +61 -0
- package/dist/types/capabilities/kernel/spec.d.ts +113 -0
- package/dist/types/capabilities/planning/todo.d.ts +62 -0
- package/dist/types/capabilities/registry.d.ts +44 -0
- package/dist/types/capabilities/search/find.d.ts +33 -0
- package/dist/types/capabilities/search/grep.d.ts +30 -0
- package/dist/types/capabilities/shell/bash.d.ts +18 -0
- package/dist/types/capabilities/shell/process.d.ts +33 -0
- package/dist/types/capabilities/web/webfetch.d.ts +25 -0
- package/dist/types/capabilities/web/websearch.d.ts +23 -0
- package/dist/types/connectors-saas/connectors-saas.test.d.ts +12 -0
- package/dist/types/connectors-saas/index.d.ts +16 -0
- package/dist/types/connectors-saas/saas/adapter/composio-backend.d.ts +60 -0
- package/dist/types/connectors-saas/saas/control/connect.d.ts +114 -0
- package/dist/types/connectors-saas/saas/control/tools.d.ts +67 -0
- package/dist/types/connectors-saas/saas/core/builder.d.ts +86 -0
- package/dist/types/connectors-saas/saas/core/cache.d.ts +53 -0
- package/dist/types/connectors-saas/saas/core/index.d.ts +14 -0
- package/dist/types/connectors-saas/saas/core/port.d.ts +157 -0
- package/dist/types/connectors-saas/saas/core/scope-planner.d.ts +74 -0
- package/dist/types/connectors-saas/saas/gateway.d.ts +133 -0
- package/dist/types/connectors-saas/saas/render/format.d.ts +54 -0
- package/dist/types/connectors-saas/saas/render/index.d.ts +19 -0
- package/dist/types/connectors-saas/saas/render/summarizers.d.ts +58 -0
- package/dist/types/facade/agent.d.ts +1 -0
- package/dist/types/facade/ai.d.ts +1 -0
- package/dist/types/facade/bot/actions/bash.d.ts +56 -0
- package/dist/types/facade/bot/actions/composio/accounts.d.ts +22 -0
- package/dist/types/facade/bot/actions/composio/client.d.ts +39 -0
- package/dist/types/facade/bot/actions/composio/connect.d.ts +19 -0
- package/dist/types/facade/bot/actions/composio/enable.d.ts +25 -0
- package/dist/types/facade/bot/actions/composio/execute.d.ts +26 -0
- package/dist/types/facade/bot/actions/composio/helpers.d.ts +16 -0
- package/dist/types/facade/bot/actions/composio/index.d.ts +9 -0
- package/dist/types/facade/bot/actions/composio/provider.d.ts +8 -0
- package/dist/types/facade/bot/actions/composio/toolkits.d.ts +22 -0
- package/dist/types/facade/bot/actions/composio/tools.d.ts +28 -0
- package/dist/types/facade/bot/actions/composio/types.d.ts +137 -0
- package/dist/types/facade/bot/actions/crew/activity-tracker.d.ts +65 -0
- package/dist/types/facade/bot/actions/crew/cleanup.d.ts +50 -0
- package/dist/types/facade/bot/actions/crew/fs-lock.d.ts +11 -0
- package/dist/types/facade/bot/actions/crew/index.d.ts +11 -0
- package/dist/types/facade/bot/actions/crew/mailbox.d.ts +20 -0
- package/dist/types/facade/bot/actions/crew/model-policy.d.ts +22 -0
- package/dist/types/facade/bot/actions/crew/names.d.ts +27 -0
- package/dist/types/facade/bot/actions/crew/protocol.d.ts +74 -0
- package/dist/types/facade/bot/actions/crew/task-store.d.ts +88 -0
- package/dist/types/facade/bot/actions/crew/team-attach-claim.d.ts +35 -0
- package/dist/types/facade/bot/actions/crew/team-config.d.ts +54 -0
- package/dist/types/facade/bot/actions/crew/worktree.d.ts +39 -0
- package/dist/types/facade/bot/actions/edit-diff.d.ts +66 -0
- package/dist/types/facade/bot/actions/edit.d.ts +41 -0
- package/dist/types/facade/bot/actions/find.d.ts +25 -0
- package/dist/types/facade/bot/actions/grep.d.ts +43 -0
- package/dist/types/facade/bot/actions/index.d.ts +300 -0
- package/dist/types/facade/bot/actions/kit/hook-runner.d.ts +12 -0
- package/dist/types/facade/bot/actions/kit/image-resize.d.ts +19 -0
- package/dist/types/facade/bot/actions/kit/mime.d.ts +1 -0
- package/dist/types/facade/bot/actions/kit/shell.d.ts +12 -0
- package/dist/types/facade/bot/actions/ls.d.ts +41 -0
- package/dist/types/facade/bot/actions/path-utils.d.ts +8 -0
- package/dist/types/facade/bot/actions/process-controller.d.ts +14 -0
- package/dist/types/facade/bot/actions/process-manager.d.ts +59 -0
- package/dist/types/facade/bot/actions/process-types.d.ts +73 -0
- package/dist/types/facade/bot/actions/process.d.ts +37 -0
- package/dist/types/facade/bot/actions/read.d.ts +36 -0
- package/dist/types/facade/bot/actions/registry.d.ts +20 -0
- package/dist/types/facade/bot/actions/todo-store.d.ts +76 -0
- package/dist/types/facade/bot/actions/todo-types.d.ts +72 -0
- package/dist/types/facade/bot/actions/todo.d.ts +76 -0
- package/dist/types/facade/bot/actions/truncate.d.ts +78 -0
- package/dist/types/facade/bot/actions/webfetch.d.ts +35 -0
- package/dist/types/facade/bot/actions/websearch.d.ts +34 -0
- package/dist/types/facade/bot/actions/write.d.ts +30 -0
- package/dist/types/facade/bot/agent-loop.d.ts +20 -0
- package/dist/types/facade/bot/agent.d.ts +132 -0
- package/dist/types/facade/bot/error-handler.d.ts +7 -0
- package/dist/types/facade/bot/event-bus.d.ts +8 -0
- package/dist/types/facade/bot/index.d.ts +7 -0
- package/dist/types/facade/bot/messages.d.ts +83 -0
- package/dist/types/facade/bot/proxy.d.ts +70 -0
- package/dist/types/facade/bot/session-manager.d.ts +409 -0
- package/dist/types/facade/bot/state-manager.d.ts +21 -0
- package/dist/types/facade/bot/telemetry.d.ts +6 -0
- package/dist/types/facade/bot/types.d.ts +207 -0
- package/dist/types/facade/mcp-core/client-pool.d.ts +105 -0
- package/dist/types/facade/mcp-core/client.d.ts +157 -0
- package/dist/types/facade/mcp-core/config.d.ts +60 -0
- package/dist/types/facade/mcp-core/errors.d.ts +103 -0
- package/dist/types/facade/mcp-core/index.d.ts +55 -0
- package/dist/types/facade/mcp-core/schema-converter.d.ts +67 -0
- package/dist/types/facade/mcp-core/server.d.ts +110 -0
- package/dist/types/facade/mcp-core/tool-factory.d.ts +62 -0
- package/dist/types/facade/mcp-core/types.d.ts +288 -0
- package/dist/types/facade/mcp.d.ts +1 -0
- package/dist/types/facade/memory.d.ts +1 -0
- package/dist/types/facade/ml/adapters/amazon-bedrock.d.ts +32 -0
- package/dist/types/facade/ml/adapters/anthropic.d.ts +61 -0
- package/dist/types/facade/ml/adapters/azure-openai-responses.d.ts +14 -0
- package/dist/types/facade/ml/adapters/google-shared.d.ts +99 -0
- package/dist/types/facade/ml/adapters/google-vertex.d.ts +14 -0
- package/dist/types/facade/ml/adapters/google.d.ts +15 -0
- package/dist/types/facade/ml/adapters/kimi.d.ts +21 -0
- package/dist/types/facade/ml/adapters/mock.d.ts +9 -0
- package/dist/types/facade/ml/adapters/nvidia.d.ts +12 -0
- package/dist/types/facade/ml/adapters/openai-codex-responses.d.ts +8 -0
- package/dist/types/facade/ml/adapters/openai-completions.d.ts +24 -0
- package/dist/types/facade/ml/adapters/openai-responses-shared.d.ts +25 -0
- package/dist/types/facade/ml/adapters/openai-responses.d.ts +12 -0
- package/dist/types/facade/ml/adapters/openai-scaffold.d.ts +3 -0
- package/dist/types/facade/ml/adapters/register-builtins.d.ts +2 -0
- package/dist/types/facade/ml/adapters/simple-options.d.ts +26 -0
- package/dist/types/facade/ml/adapters/transform-messages.d.ts +23 -0
- package/dist/types/facade/ml/api-registry.d.ts +49 -0
- package/dist/types/facade/ml/cli.d.ts +2 -0
- package/dist/types/facade/ml/env-api-keys.d.ts +19 -0
- package/dist/types/facade/ml/index.d.ts +27 -0
- package/dist/types/facade/ml/kit/auth/anthropic.d.ts +17 -0
- package/dist/types/facade/ml/kit/auth/github-copilot.d.ts +22 -0
- package/dist/types/facade/ml/kit/auth/index.d.ts +50 -0
- package/dist/types/facade/ml/kit/auth/kimi.d.ts +23 -0
- package/dist/types/facade/ml/kit/auth/oauth-page.d.ts +2 -0
- package/dist/types/facade/ml/kit/auth/openai-codex.d.ts +36 -0
- package/dist/types/facade/ml/kit/auth/pkce.d.ts +12 -0
- package/dist/types/facade/ml/kit/auth/types.d.ts +67 -0
- package/dist/types/facade/ml/kit/base-stream-handler.d.ts +30 -0
- package/dist/types/facade/ml/kit/event-stream.d.ts +63 -0
- package/dist/types/facade/ml/kit/index.d.ts +14 -0
- package/dist/types/facade/ml/kit/json-parse.d.ts +23 -0
- package/dist/types/facade/ml/kit/message-transform.d.ts +32 -0
- package/dist/types/facade/ml/kit/output-factory.d.ts +8 -0
- package/dist/types/facade/ml/kit/overflow.d.ts +9 -0
- package/dist/types/facade/ml/kit/provider-adapter.d.ts +56 -0
- package/dist/types/facade/ml/kit/provider-client-builder.d.ts +36 -0
- package/dist/types/facade/ml/kit/provider-consolidation.d.ts +3 -0
- package/dist/types/facade/ml/kit/provider-constants.d.ts +34 -0
- package/dist/types/facade/ml/kit/provider-errors.d.ts +52 -0
- package/dist/types/facade/ml/kit/sanitize-unicode.d.ts +2 -0
- package/dist/types/facade/ml/kit/stream-event-helper.d.ts +38 -0
- package/dist/types/facade/ml/kit/stream-handler-types.d.ts +46 -0
- package/dist/types/facade/ml/kit/streaming-state-manager.d.ts +42 -0
- package/dist/types/facade/ml/kit/tool-converter.d.ts +49 -0
- package/dist/types/facade/ml/kit/typebox-helpers.d.ts +24 -0
- package/dist/types/facade/ml/kit/validation.d.ts +26 -0
- package/dist/types/facade/ml/models.d.ts +41 -0
- package/dist/types/facade/ml/models.generated.d.ts +12261 -0
- package/dist/types/facade/ml/stream.d.ts +27 -0
- package/dist/types/facade/ml/types.d.ts +269 -0
- package/dist/types/index.d.ts +16 -0
- package/dist/types/interop/index.d.ts +12 -0
- package/dist/types/interop/interop.test.d.ts +19 -0
- package/dist/types/interop/protocol-bridge/bridge.d.ts +52 -0
- package/dist/types/interop/protocol-bridge/contract.d.ts +249 -0
- package/dist/types/interop/protocol-bridge/endpoint.d.ts +124 -0
- package/dist/types/interop/protocol-bridge/fleet.d.ts +92 -0
- package/dist/types/interop/protocol-bridge/host.d.ts +61 -0
- package/dist/types/interop/protocol-bridge/index.d.ts +16 -0
- package/dist/types/interop/protocol-bridge/schema.d.ts +29 -0
- package/dist/types/llmgateway/catalog/cards.d.ts +18 -0
- package/dist/types/llmgateway/catalog/cost.d.ts +15 -0
- package/dist/types/llmgateway/catalog/index.d.ts +7 -0
- package/dist/types/llmgateway/catalog/query.d.ts +40 -0
- package/dist/types/llmgateway/connectors/anthropic.d.ts +35 -0
- package/dist/types/llmgateway/connectors/azure-openai.d.ts +33 -0
- package/dist/types/llmgateway/connectors/bedrock.d.ts +113 -0
- package/dist/types/llmgateway/connectors/google-vertex.d.ts +38 -0
- package/dist/types/llmgateway/connectors/google.d.ts +40 -0
- package/dist/types/llmgateway/connectors/index.d.ts +26 -0
- package/dist/types/llmgateway/connectors/kimi.d.ts +28 -0
- package/dist/types/llmgateway/connectors/mock.d.ts +37 -0
- package/dist/types/llmgateway/connectors/nvidia.d.ts +27 -0
- package/dist/types/llmgateway/connectors/ollama.d.ts +45 -0
- package/dist/types/llmgateway/connectors/openai-chat.d.ts +25 -0
- package/dist/types/llmgateway/connectors/openai-responses.d.ts +49 -0
- package/dist/types/llmgateway/contract/connector.d.ts +32 -0
- package/dist/types/llmgateway/contract/conversation.d.ts +86 -0
- package/dist/types/llmgateway/contract/emission.d.ts +55 -0
- package/dist/types/llmgateway/contract/errors.d.ts +27 -0
- package/dist/types/llmgateway/contract/index.d.ts +13 -0
- package/dist/types/llmgateway/contract/model-card.d.ts +42 -0
- package/dist/types/llmgateway/contract/options.d.ts +31 -0
- package/dist/types/llmgateway/contract/reply.d.ts +33 -0
- package/dist/types/llmgateway/conversion/index.d.ts +10 -0
- package/dist/types/llmgateway/conversion/mappers.d.ts +65 -0
- package/dist/types/llmgateway/conversion/openai-compatible.d.ts +46 -0
- package/dist/types/llmgateway/conversion/reduce.d.ts +20 -0
- package/dist/types/llmgateway/credentials/oauth.d.ts +73 -0
- package/dist/types/llmgateway/credentials/pkce.d.ts +52 -0
- package/dist/types/llmgateway/credentials/secrets.d.ts +74 -0
- package/dist/types/llmgateway/gateway.d.ts +34 -0
- package/dist/types/llmgateway/gateway.test.d.ts +14 -0
- package/dist/types/llmgateway/index.d.ts +11 -0
- package/dist/types/llmgateway/streaming/channel.d.ts +24 -0
- package/dist/types/llmgateway/streaming/index.d.ts +10 -0
- package/dist/types/llmgateway/streaming/ndjson.d.ts +17 -0
- package/dist/types/llmgateway/streaming/sse.d.ts +31 -0
- package/dist/types/react-host/index.d.ts +9 -0
- package/dist/types/react-host/ink.d.ts +5 -0
- package/dist/types/react-host/jsx-runtime.d.ts +4 -0
- package/dist/types/react-host/loader.d.ts +3 -0
- package/dist/types/react-ink/components/ChangelogBlock.d.ts +8 -0
- package/dist/types/react-ink/components/DisplayBlockView.d.ts +8 -0
- package/dist/types/react-ink/components/Footer.d.ts +11 -0
- package/dist/types/react-ink/components/MessageList.d.ts +14 -0
- package/dist/types/react-ink/components/MessageRow.d.ts +13 -0
- package/dist/types/react-ink/components/StatusLine.d.ts +9 -0
- package/dist/types/react-ink/components/TaskPanel.d.ts +11 -0
- package/dist/types/react-ink/components/ToolEventBlock.d.ts +24 -0
- package/dist/types/react-ink/components/dialogs/DialogFrame.d.ts +8 -0
- package/dist/types/react-ink/components/dialogs/LoginDialog.d.ts +14 -0
- package/dist/types/react-ink/components/dialogs/ModelDialog.d.ts +9 -0
- package/dist/types/react-ink/components/dialogs/OAuthDialog.d.ts +9 -0
- package/dist/types/react-ink/components/dialogs/ScopedModelsDialog.d.ts +9 -0
- package/dist/types/react-ink/components/dialogs/SelectableDialog.d.ts +22 -0
- package/dist/types/react-ink/components/dialogs/SessionDialog.d.ts +13 -0
- package/dist/types/react-ink/components/dialogs/SettingsDialog.d.ts +14 -0
- package/dist/types/react-ink/components/dialogs/StartupSessionPicker.d.ts +9 -0
- package/dist/types/react-ink/components/dialogs/ThemeDialog.d.ts +26 -0
- package/dist/types/react-ink/components/dialogs/TreeDialog.d.ts +8 -0
- package/dist/types/react-ink/components/dialogs/UserMessageDialog.d.ts +8 -0
- package/dist/types/react-ink/components/messages/AssistantMessage.d.ts +12 -0
- package/dist/types/react-ink/components/messages/BashMessage.d.ts +8 -0
- package/dist/types/react-ink/components/messages/BranchSummaryMessage.d.ts +8 -0
- package/dist/types/react-ink/components/messages/CompactionMessage.d.ts +8 -0
- package/dist/types/react-ink/components/messages/CustomMessage.d.ts +9 -0
- package/dist/types/react-ink/components/messages/SkillInvocationMessage.d.ts +7 -0
- package/dist/types/react-ink/components/messages/ToolCallMessage.d.ts +8 -0
- package/dist/types/react-ink/components/messages/ToolResultBlock.d.ts +12 -0
- package/dist/types/react-ink/components/messages/UserMessage.d.ts +9 -0
- package/dist/types/react-ink/diff/Diff.d.ts +22 -0
- package/dist/types/react-ink/diff/diff.test.d.ts +1 -0
- package/dist/types/react-ink/diff/structured.d.ts +41 -0
- package/dist/types/react-ink/diff/word-diff.d.ts +27 -0
- package/dist/types/react-ink/index.d.ts +42 -0
- package/dist/types/react-ink/markdown/Markdown.d.ts +23 -0
- package/dist/types/react-ink/markdown/MarkdownTable.d.ts +19 -0
- package/dist/types/react-ink/markdown/StreamingMarkdown.d.ts +34 -0
- package/dist/types/react-ink/markdown/format-token.d.ts +39 -0
- package/dist/types/react-ink/markdown/highlight.d.ts +31 -0
- package/dist/types/react-ink/theme-adapter.d.ts +66 -0
- package/dist/types/react-ink/types.d.ts +133 -0
- package/dist/types/react-ink/utils/message-groups.d.ts +25 -0
- package/dist/types/react-ink/utils/selection-dialog.d.ts +2 -0
- package/dist/types/react-ink/utils/session-browser.d.ts +27 -0
- package/dist/types/react-ink/utils/tool-display.d.ts +37 -0
- package/dist/types/runtime/cadence/cadence.test.d.ts +6 -0
- package/dist/types/runtime/cadence/fold.d.ts +48 -0
- package/dist/types/runtime/cadence/index.d.ts +12 -0
- package/dist/types/runtime/cadence/reducer.d.ts +44 -0
- package/dist/types/runtime/conductor/agent.d.ts +71 -0
- package/dist/types/runtime/conductor/index.d.ts +11 -0
- package/dist/types/runtime/contract/config.d.ts +44 -0
- package/dist/types/runtime/contract/effect.d.ts +41 -0
- package/dist/types/runtime/contract/errors.d.ts +22 -0
- package/dist/types/runtime/contract/events.d.ts +63 -0
- package/dist/types/runtime/contract/index.d.ts +18 -0
- package/dist/types/runtime/contract/run-state.d.ts +57 -0
- package/dist/types/runtime/contract/session.d.ts +42 -0
- package/dist/types/runtime/contract/signal.d.ts +49 -0
- package/dist/types/runtime/contract/tools.d.ts +45 -0
- package/dist/types/runtime/dispatch/index.d.ts +9 -0
- package/dist/types/runtime/dispatch/scheduler.d.ts +53 -0
- package/dist/types/runtime/index.d.ts +22 -0
- package/dist/types/runtime/ledger/accumulator.d.ts +44 -0
- package/dist/types/runtime/ledger/bus.d.ts +50 -0
- package/dist/types/runtime/ledger/index.d.ts +11 -0
- package/dist/types/runtime/memory/compactor.d.ts +56 -0
- package/dist/types/runtime/memory/estimate.d.ts +21 -0
- package/dist/types/runtime/memory/index.d.ts +8 -0
- package/dist/types/runtime/runtime.test.d.ts +15 -0
- package/dist/types/runtime/store/dag.d.ts +72 -0
- package/dist/types/runtime/store/hash.d.ts +18 -0
- package/dist/types/runtime/store/index.d.ts +12 -0
- package/dist/types/runtime/store/persist.d.ts +49 -0
- package/dist/types/runtime/turn/driver.d.ts +32 -0
- package/dist/types/runtime/turn/index.d.ts +8 -0
- package/dist/types/runtime/wire/index.d.ts +10 -0
- package/dist/types/runtime/wire/projectors.d.ts +53 -0
- package/dist/types/shell-app/auth-cli/index.d.ts +9 -0
- package/dist/types/shell-app/auth-cli/oauth-cli.d.ts +73 -0
- package/dist/types/shell-app/boot/context.d.ts +108 -0
- package/dist/types/shell-app/boot/index.d.ts +13 -0
- package/dist/types/shell-app/boot/pipeline.d.ts +66 -0
- package/dist/types/shell-app/boot/stages.d.ts +77 -0
- package/dist/types/shell-app/cli.d.ts +75 -0
- package/dist/types/shell-app/config/index.d.ts +11 -0
- package/dist/types/shell-app/config/locator.d.ts +85 -0
- package/dist/types/shell-app/config/settings.d.ts +91 -0
- package/dist/types/shell-app/index.d.ts +26 -0
- package/dist/types/shell-app/invocation/flags.d.ts +89 -0
- package/dist/types/shell-app/invocation/parse.d.ts +89 -0
- package/dist/types/shell-app/locate/brand.d.ts +71 -0
- package/dist/types/shell-app/locate/index.d.ts +12 -0
- package/dist/types/shell-app/locate/locator.d.ts +122 -0
- package/dist/types/shell-app/runners/contract.d.ts +116 -0
- package/dist/types/shell-app/runners/index.d.ts +15 -0
- package/dist/types/shell-app/runners/one-shot.d.ts +21 -0
- package/dist/types/shell-app/runners/registry.d.ts +34 -0
- package/dist/types/shell-app/runners/repl.d.ts +51 -0
- package/dist/types/shell-app/runners/wire.d.ts +34 -0
- package/dist/types/shell-app/shell-app.test.d.ts +14 -0
- package/dist/types/shell-app/upgrade/index.d.ts +9 -0
- package/dist/types/shell-app/upgrade/upgrades.d.ts +62 -0
- package/dist/types/smithy/config/flag-reader.d.ts +128 -0
- package/dist/types/smithy/config/index.d.ts +9 -0
- package/dist/types/smithy/forge.d.ts +135 -0
- package/dist/types/smithy/index.d.ts +36 -0
- package/dist/types/smithy/knowledge/index.d.ts +10 -0
- package/dist/types/smithy/knowledge/loader.d.ts +64 -0
- package/dist/types/smithy/persona/blueprint.d.ts +75 -0
- package/dist/types/smithy/persona/define-agent.d.ts +51 -0
- package/dist/types/smithy/persona/index.d.ts +14 -0
- package/dist/types/smithy/persona/profiles.d.ts +44 -0
- package/dist/types/smithy/runtime/index.d.ts +9 -0
- package/dist/types/smithy/runtime/tool-ledger.d.ts +130 -0
- package/dist/types/smithy/smithy.test.d.ts +20 -0
- package/dist/types/smithy/ui/index.d.ts +11 -0
- package/dist/types/smithy/ui/transcript.d.ts +183 -0
- package/dist/types/swarm/coordinator.d.ts +192 -0
- package/dist/types/swarm/index.d.ts +33 -0
- package/dist/types/swarm/isolation/index.d.ts +14 -0
- package/dist/types/swarm/isolation/runner.d.ts +61 -0
- package/dist/types/swarm/isolation/worktree.d.ts +142 -0
- package/dist/types/swarm/kernel/faults.d.ts +52 -0
- package/dist/types/swarm/kernel/ids.d.ts +25 -0
- package/dist/types/swarm/kernel/index.d.ts +26 -0
- package/dist/types/swarm/kernel/json-cell.d.ts +113 -0
- package/dist/types/swarm/kernel/jsonl-log.d.ts +81 -0
- package/dist/types/swarm/postbox/channel.d.ts +88 -0
- package/dist/types/swarm/postbox/codecs.d.ts +253 -0
- package/dist/types/swarm/postbox/index.d.ts +16 -0
- package/dist/types/swarm/roster/index.d.ts +16 -0
- package/dist/types/swarm/roster/manifest.d.ts +185 -0
- package/dist/types/swarm/swarm.test.d.ts +24 -0
- package/dist/types/swarm/telemetry/activity.d.ts +143 -0
- package/dist/types/swarm/workboard/board.d.ts +174 -0
- package/dist/types/swarm/workboard/dep-graph.d.ts +77 -0
- package/dist/types/swarm/workboard/index.d.ts +12 -0
- package/dist/types/tracing/adapter/index.d.ts +12 -0
- package/dist/types/tracing/adapter/runtime-trace.d.ts +54 -0
- package/dist/types/tracing/channel/index.d.ts +9 -0
- package/dist/types/tracing/channel/signal.d.ts +93 -0
- package/dist/types/tracing/index.d.ts +25 -0
- package/dist/types/tracing/recorder/index.d.ts +12 -0
- package/dist/types/tracing/recorder/recorder.d.ts +75 -0
- package/dist/types/tracing/recorder/sampling.d.ts +55 -0
- package/dist/types/tracing/redaction/index.d.ts +8 -0
- package/dist/types/tracing/redaction/secret-scrubber.d.ts +95 -0
- package/dist/types/tracing/registry/hub.d.ts +57 -0
- package/dist/types/tracing/registry/index.d.ts +7 -0
- package/dist/types/tracing/signal/handle.d.ts +73 -0
- package/dist/types/tracing/signal/index.d.ts +12 -0
- package/dist/types/tracing/signal/segment.d.ts +124 -0
- package/dist/types/tracing/sinks/base.d.ts +51 -0
- package/dist/types/tracing/sinks/console.d.ts +44 -0
- package/dist/types/tracing/sinks/file.d.ts +47 -0
- package/dist/types/tracing/sinks/index.d.ts +16 -0
- package/dist/types/tracing/sinks/stream.d.ts +46 -0
- package/dist/types/tracing/tracing.test.d.ts +7 -0
- package/dist/types/ui/autocomplete.d.ts +59 -0
- package/dist/types/ui/contracts.d.ts +38 -0
- package/dist/types/ui/editor-component.d.ts +100 -0
- package/dist/types/ui/fuzzy.d.ts +29 -0
- package/dist/types/ui/index.d.ts +8 -0
- package/dist/types/ui/keybindings.d.ts +62 -0
- package/dist/types/ui/keys.d.ts +171 -0
- package/dist/types/ui/theme-types.d.ts +36 -0
- package/dist/types/ui/utils.d.ts +101 -0
- package/dist/types/ui-bridge/InteractiveApp.d.ts +38 -0
- package/dist/types/ui-bridge/adapter.d.ts +90 -0
- package/dist/types/ui-bridge/index.d.ts +37 -0
- package/package.json +120 -107
- package/LICENSE +0 -8
- package/LICENSE-THIRD-PARTY.txt +0 -30
- package/local-dist-new/IndusForge/examples/research-agent.d.ts +0 -3
- package/local-dist-new/IndusForge/examples/research-agent.d.ts.map +0 -1
- package/local-dist-new/IndusForge/examples/research-agent.js +0 -18
- package/local-dist-new/IndusForge/examples/research-agent.js.map +0 -1
- package/local-dist-new/IndusForge/examples/review-agent.d.ts +0 -3
- package/local-dist-new/IndusForge/examples/review-agent.d.ts.map +0 -1
- package/local-dist-new/IndusForge/examples/review-agent.js +0 -18
- package/local-dist-new/IndusForge/examples/review-agent.js.map +0 -1
- package/local-dist-new/IndusForge/examples/terminal-builder-agent.d.ts +0 -3
- package/local-dist-new/IndusForge/examples/terminal-builder-agent.d.ts.map +0 -1
- package/local-dist-new/IndusForge/examples/terminal-builder-agent.js +0 -18
- package/local-dist-new/IndusForge/examples/terminal-builder-agent.js.map +0 -1
- package/local-dist-new/IndusForge/terminal-chat.d.ts +0 -2
- package/local-dist-new/IndusForge/terminal-chat.d.ts.map +0 -1
- package/local-dist-new/IndusForge/terminal-chat.js +0 -557
- package/local-dist-new/IndusForge/terminal-chat.js.map +0 -1
- package/local-dist-new/agent.d.ts +0 -6
- package/local-dist-new/agent.d.ts.map +0 -1
- package/local-dist-new/agent.js +0 -6
- package/local-dist-new/agent.js.map +0 -1
- package/local-dist-new/ai.d.ts +0 -6
- package/local-dist-new/ai.d.ts.map +0 -1
- package/local-dist-new/ai.js +0 -6
- package/local-dist-new/ai.js.map +0 -1
- package/local-dist-new/bot/actions/bash.d.ts +0 -56
- package/local-dist-new/bot/actions/bash.d.ts.map +0 -1
- package/local-dist-new/bot/actions/bash.js +0 -275
- package/local-dist-new/bot/actions/bash.js.map +0 -1
- package/local-dist-new/bot/actions/composio/accounts.d.ts +0 -23
- package/local-dist-new/bot/actions/composio/accounts.d.ts.map +0 -1
- package/local-dist-new/bot/actions/composio/accounts.js +0 -40
- package/local-dist-new/bot/actions/composio/accounts.js.map +0 -1
- package/local-dist-new/bot/actions/composio/client.d.ts +0 -40
- package/local-dist-new/bot/actions/composio/client.d.ts.map +0 -1
- package/local-dist-new/bot/actions/composio/client.js +0 -361
- package/local-dist-new/bot/actions/composio/client.js.map +0 -1
- package/local-dist-new/bot/actions/composio/connect.d.ts +0 -20
- package/local-dist-new/bot/actions/composio/connect.d.ts.map +0 -1
- package/local-dist-new/bot/actions/composio/connect.js +0 -41
- package/local-dist-new/bot/actions/composio/connect.js.map +0 -1
- package/local-dist-new/bot/actions/composio/enable.d.ts +0 -26
- package/local-dist-new/bot/actions/composio/enable.d.ts.map +0 -1
- package/local-dist-new/bot/actions/composio/enable.js +0 -66
- package/local-dist-new/bot/actions/composio/enable.js.map +0 -1
- package/local-dist-new/bot/actions/composio/execute.d.ts +0 -27
- package/local-dist-new/bot/actions/composio/execute.d.ts.map +0 -1
- package/local-dist-new/bot/actions/composio/execute.js +0 -46
- package/local-dist-new/bot/actions/composio/execute.js.map +0 -1
- package/local-dist-new/bot/actions/composio/helpers.d.ts +0 -17
- package/local-dist-new/bot/actions/composio/helpers.d.ts.map +0 -1
- package/local-dist-new/bot/actions/composio/helpers.js +0 -533
- package/local-dist-new/bot/actions/composio/helpers.js.map +0 -1
- package/local-dist-new/bot/actions/composio/index.d.ts +0 -10
- package/local-dist-new/bot/actions/composio/index.d.ts.map +0 -1
- package/local-dist-new/bot/actions/composio/index.js +0 -9
- package/local-dist-new/bot/actions/composio/index.js.map +0 -1
- package/local-dist-new/bot/actions/composio/provider.d.ts +0 -9
- package/local-dist-new/bot/actions/composio/provider.d.ts.map +0 -1
- package/local-dist-new/bot/actions/composio/provider.js +0 -54
- package/local-dist-new/bot/actions/composio/provider.js.map +0 -1
- package/local-dist-new/bot/actions/composio/toolkits.d.ts +0 -23
- package/local-dist-new/bot/actions/composio/toolkits.d.ts.map +0 -1
- package/local-dist-new/bot/actions/composio/toolkits.js +0 -40
- package/local-dist-new/bot/actions/composio/toolkits.js.map +0 -1
- package/local-dist-new/bot/actions/composio/tools.d.ts +0 -29
- package/local-dist-new/bot/actions/composio/tools.d.ts.map +0 -1
- package/local-dist-new/bot/actions/composio/tools.js +0 -72
- package/local-dist-new/bot/actions/composio/tools.js.map +0 -1
- package/local-dist-new/bot/actions/composio/types.d.ts +0 -138
- package/local-dist-new/bot/actions/composio/types.d.ts.map +0 -1
- package/local-dist-new/bot/actions/composio/types.js +0 -2
- package/local-dist-new/bot/actions/composio/types.js.map +0 -1
- package/local-dist-new/bot/actions/crew/activity-tracker.d.ts +0 -66
- package/local-dist-new/bot/actions/crew/activity-tracker.d.ts.map +0 -1
- package/local-dist-new/bot/actions/crew/activity-tracker.js +0 -480
- package/local-dist-new/bot/actions/crew/activity-tracker.js.map +0 -1
- package/local-dist-new/bot/actions/crew/cleanup.d.ts +0 -51
- package/local-dist-new/bot/actions/crew/cleanup.d.ts.map +0 -1
- package/local-dist-new/bot/actions/crew/cleanup.js +0 -219
- package/local-dist-new/bot/actions/crew/cleanup.js.map +0 -1
- package/local-dist-new/bot/actions/crew/fs-lock.d.ts +0 -12
- package/local-dist-new/bot/actions/crew/fs-lock.d.ts.map +0 -1
- package/local-dist-new/bot/actions/crew/fs-lock.js +0 -74
- package/local-dist-new/bot/actions/crew/fs-lock.js.map +0 -1
- package/local-dist-new/bot/actions/crew/index.d.ts +0 -12
- package/local-dist-new/bot/actions/crew/index.d.ts.map +0 -1
- package/local-dist-new/bot/actions/crew/index.js +0 -12
- package/local-dist-new/bot/actions/crew/index.js.map +0 -1
- package/local-dist-new/bot/actions/crew/mailbox.d.ts +0 -21
- package/local-dist-new/bot/actions/crew/mailbox.d.ts.map +0 -1
- package/local-dist-new/bot/actions/crew/mailbox.js +0 -106
- package/local-dist-new/bot/actions/crew/mailbox.js.map +0 -1
- package/local-dist-new/bot/actions/crew/model-policy.d.ts +0 -23
- package/local-dist-new/bot/actions/crew/model-policy.d.ts.map +0 -1
- package/local-dist-new/bot/actions/crew/model-policy.js +0 -113
- package/local-dist-new/bot/actions/crew/model-policy.js.map +0 -1
- package/local-dist-new/bot/actions/crew/names.d.ts +0 -28
- package/local-dist-new/bot/actions/crew/names.d.ts.map +0 -1
- package/local-dist-new/bot/actions/crew/names.js +0 -109
- package/local-dist-new/bot/actions/crew/names.js.map +0 -1
- package/local-dist-new/bot/actions/crew/protocol.d.ts +0 -75
- package/local-dist-new/bot/actions/crew/protocol.d.ts.map +0 -1
- package/local-dist-new/bot/actions/crew/protocol.js +0 -205
- package/local-dist-new/bot/actions/crew/protocol.js.map +0 -1
- package/local-dist-new/bot/actions/crew/task-store.d.ts +0 -89
- package/local-dist-new/bot/actions/crew/task-store.d.ts.map +0 -1
- package/local-dist-new/bot/actions/crew/task-store.js +0 -445
- package/local-dist-new/bot/actions/crew/task-store.js.map +0 -1
- package/local-dist-new/bot/actions/crew/team-attach-claim.d.ts +0 -36
- package/local-dist-new/bot/actions/crew/team-attach-claim.d.ts.map +0 -1
- package/local-dist-new/bot/actions/crew/team-attach-claim.js +0 -144
- package/local-dist-new/bot/actions/crew/team-attach-claim.js.map +0 -1
- package/local-dist-new/bot/actions/crew/team-config.d.ts +0 -55
- package/local-dist-new/bot/actions/crew/team-config.d.ts.map +0 -1
- package/local-dist-new/bot/actions/crew/team-config.js +0 -252
- package/local-dist-new/bot/actions/crew/team-config.js.map +0 -1
- package/local-dist-new/bot/actions/crew/worktree.d.ts +0 -40
- package/local-dist-new/bot/actions/crew/worktree.d.ts.map +0 -1
- package/local-dist-new/bot/actions/crew/worktree.js +0 -213
- package/local-dist-new/bot/actions/crew/worktree.js.map +0 -1
- package/local-dist-new/bot/actions/edit-diff.d.ts +0 -63
- package/local-dist-new/bot/actions/edit-diff.d.ts.map +0 -1
- package/local-dist-new/bot/actions/edit-diff.js +0 -255
- package/local-dist-new/bot/actions/edit-diff.js.map +0 -1
- package/local-dist-new/bot/actions/edit.d.ts +0 -42
- package/local-dist-new/bot/actions/edit.d.ts.map +0 -1
- package/local-dist-new/bot/actions/edit.js +0 -176
- package/local-dist-new/bot/actions/edit.js.map +0 -1
- package/local-dist-new/bot/actions/find.d.ts +0 -26
- package/local-dist-new/bot/actions/find.d.ts.map +0 -1
- package/local-dist-new/bot/actions/find.js +0 -170
- package/local-dist-new/bot/actions/find.js.map +0 -1
- package/local-dist-new/bot/actions/grep.d.ts +0 -43
- package/local-dist-new/bot/actions/grep.d.ts.map +0 -1
- package/local-dist-new/bot/actions/grep.js +0 -218
- package/local-dist-new/bot/actions/grep.js.map +0 -1
- package/local-dist-new/bot/actions/index.d.ts +0 -301
- package/local-dist-new/bot/actions/index.d.ts.map +0 -1
- package/local-dist-new/bot/actions/index.js +0 -255
- package/local-dist-new/bot/actions/index.js.map +0 -1
- package/local-dist-new/bot/actions/kit/hook-runner.d.ts +0 -13
- package/local-dist-new/bot/actions/kit/hook-runner.d.ts.map +0 -1
- package/local-dist-new/bot/actions/kit/hook-runner.js +0 -33
- package/local-dist-new/bot/actions/kit/hook-runner.js.map +0 -1
- package/local-dist-new/bot/actions/kit/image-resize.d.ts +0 -20
- package/local-dist-new/bot/actions/kit/image-resize.d.ts.map +0 -1
- package/local-dist-new/bot/actions/kit/image-resize.js +0 -93
- package/local-dist-new/bot/actions/kit/image-resize.js.map +0 -1
- package/local-dist-new/bot/actions/kit/mime.d.ts +0 -2
- package/local-dist-new/bot/actions/kit/mime.d.ts.map +0 -1
- package/local-dist-new/bot/actions/kit/mime.js +0 -65
- package/local-dist-new/bot/actions/kit/mime.js.map +0 -1
- package/local-dist-new/bot/actions/kit/shell.d.ts +0 -13
- package/local-dist-new/bot/actions/kit/shell.d.ts.map +0 -1
- package/local-dist-new/bot/actions/kit/shell.js +0 -103
- package/local-dist-new/bot/actions/kit/shell.js.map +0 -1
- package/local-dist-new/bot/actions/ls.d.ts +0 -41
- package/local-dist-new/bot/actions/ls.d.ts.map +0 -1
- package/local-dist-new/bot/actions/ls.js +0 -174
- package/local-dist-new/bot/actions/ls.js.map +0 -1
- package/local-dist-new/bot/actions/path-utils.d.ts +0 -8
- package/local-dist-new/bot/actions/path-utils.d.ts.map +0 -1
- package/local-dist-new/bot/actions/path-utils.js +0 -75
- package/local-dist-new/bot/actions/path-utils.js.map +0 -1
- package/local-dist-new/bot/actions/process-controller.d.ts +0 -15
- package/local-dist-new/bot/actions/process-controller.d.ts.map +0 -1
- package/local-dist-new/bot/actions/process-controller.js +0 -39
- package/local-dist-new/bot/actions/process-controller.js.map +0 -1
- package/local-dist-new/bot/actions/process-manager.d.ts +0 -60
- package/local-dist-new/bot/actions/process-manager.d.ts.map +0 -1
- package/local-dist-new/bot/actions/process-manager.js +0 -485
- package/local-dist-new/bot/actions/process-manager.js.map +0 -1
- package/local-dist-new/bot/actions/process-types.d.ts +0 -74
- package/local-dist-new/bot/actions/process-types.d.ts.map +0 -1
- package/local-dist-new/bot/actions/process-types.js +0 -7
- package/local-dist-new/bot/actions/process-types.js.map +0 -1
- package/local-dist-new/bot/actions/process.d.ts +0 -38
- package/local-dist-new/bot/actions/process.d.ts.map +0 -1
- package/local-dist-new/bot/actions/process.js +0 -360
- package/local-dist-new/bot/actions/process.js.map +0 -1
- package/local-dist-new/bot/actions/read.d.ts +0 -37
- package/local-dist-new/bot/actions/read.d.ts.map +0 -1
- package/local-dist-new/bot/actions/read.js +0 -190
- package/local-dist-new/bot/actions/read.js.map +0 -1
- package/local-dist-new/bot/actions/registry.d.ts +0 -21
- package/local-dist-new/bot/actions/registry.d.ts.map +0 -1
- package/local-dist-new/bot/actions/registry.js +0 -23
- package/local-dist-new/bot/actions/registry.js.map +0 -1
- package/local-dist-new/bot/actions/todo-store.d.ts +0 -77
- package/local-dist-new/bot/actions/todo-store.d.ts.map +0 -1
- package/local-dist-new/bot/actions/todo-store.js +0 -137
- package/local-dist-new/bot/actions/todo-store.js.map +0 -1
- package/local-dist-new/bot/actions/todo-types.d.ts +0 -73
- package/local-dist-new/bot/actions/todo-types.d.ts.map +0 -1
- package/local-dist-new/bot/actions/todo-types.js +0 -8
- package/local-dist-new/bot/actions/todo-types.js.map +0 -1
- package/local-dist-new/bot/actions/todo.d.ts +0 -77
- package/local-dist-new/bot/actions/todo.d.ts.map +0 -1
- package/local-dist-new/bot/actions/todo.js +0 -122
- package/local-dist-new/bot/actions/todo.js.map +0 -1
- package/local-dist-new/bot/actions/truncate.d.ts +0 -73
- package/local-dist-new/bot/actions/truncate.d.ts.map +0 -1
- package/local-dist-new/bot/actions/truncate.js +0 -221
- package/local-dist-new/bot/actions/truncate.js.map +0 -1
- package/local-dist-new/bot/actions/webfetch.d.ts +0 -36
- package/local-dist-new/bot/actions/webfetch.d.ts.map +0 -1
- package/local-dist-new/bot/actions/webfetch.js +0 -247
- package/local-dist-new/bot/actions/webfetch.js.map +0 -1
- package/local-dist-new/bot/actions/websearch.d.ts +0 -35
- package/local-dist-new/bot/actions/websearch.d.ts.map +0 -1
- package/local-dist-new/bot/actions/websearch.js +0 -132
- package/local-dist-new/bot/actions/websearch.js.map +0 -1
- package/local-dist-new/bot/actions/write.d.ts +0 -31
- package/local-dist-new/bot/actions/write.d.ts.map +0 -1
- package/local-dist-new/bot/actions/write.js +0 -139
- package/local-dist-new/bot/actions/write.js.map +0 -1
- package/local-dist-new/bot/agent-loop.d.ts +0 -15
- package/local-dist-new/bot/agent-loop.d.ts.map +0 -1
- package/local-dist-new/bot/agent-loop.js +0 -293
- package/local-dist-new/bot/agent-loop.js.map +0 -1
- package/local-dist-new/bot/agent.d.ts +0 -122
- package/local-dist-new/bot/agent.d.ts.map +0 -1
- package/local-dist-new/bot/agent.js +0 -393
- package/local-dist-new/bot/agent.js.map +0 -1
- package/local-dist-new/bot/error-handler.d.ts +0 -8
- package/local-dist-new/bot/error-handler.d.ts.map +0 -1
- package/local-dist-new/bot/error-handler.js +0 -8
- package/local-dist-new/bot/error-handler.js.map +0 -1
- package/local-dist-new/bot/event-bus.d.ts +0 -9
- package/local-dist-new/bot/event-bus.d.ts.map +0 -1
- package/local-dist-new/bot/event-bus.js +0 -15
- package/local-dist-new/bot/event-bus.js.map +0 -1
- package/local-dist-new/bot/index.d.ts +0 -8
- package/local-dist-new/bot/index.d.ts.map +0 -1
- package/local-dist-new/bot/index.js +0 -8
- package/local-dist-new/bot/index.js.map +0 -1
- package/local-dist-new/bot/messages.d.ts +0 -77
- package/local-dist-new/bot/messages.d.ts.map +0 -1
- package/local-dist-new/bot/messages.js +0 -116
- package/local-dist-new/bot/messages.js.map +0 -1
- package/local-dist-new/bot/proxy.d.ts +0 -66
- package/local-dist-new/bot/proxy.d.ts.map +0 -1
- package/local-dist-new/bot/proxy.js +0 -228
- package/local-dist-new/bot/proxy.js.map +0 -1
- package/local-dist-new/bot/session-manager.d.ts +0 -448
- package/local-dist-new/bot/session-manager.d.ts.map +0 -1
- package/local-dist-new/bot/session-manager.js +0 -1232
- package/local-dist-new/bot/session-manager.js.map +0 -1
- package/local-dist-new/bot/state-manager.d.ts +0 -22
- package/local-dist-new/bot/state-manager.d.ts.map +0 -1
- package/local-dist-new/bot/state-manager.js +0 -60
- package/local-dist-new/bot/state-manager.js.map +0 -1
- package/local-dist-new/bot/telemetry.d.ts +0 -7
- package/local-dist-new/bot/telemetry.d.ts.map +0 -1
- package/local-dist-new/bot/telemetry.js +0 -18
- package/local-dist-new/bot/telemetry.js.map +0 -1
- package/local-dist-new/bot/types.d.ts +0 -205
- package/local-dist-new/bot/types.d.ts.map +0 -1
- package/local-dist-new/bot/types.js +0 -60
- package/local-dist-new/bot/types.js.map +0 -1
- package/local-dist-new/cli.d.ts +0 -3
- package/local-dist-new/cli.d.ts.map +0 -1
- package/local-dist-new/cli.js +0 -3
- package/local-dist-new/cli.js.map +0 -1
- package/local-dist-new/index.d.ts +0 -7
- package/local-dist-new/index.d.ts.map +0 -1
- package/local-dist-new/index.js +0 -7
- package/local-dist-new/index.js.map +0 -1
- package/local-dist-new/mcp/client-pool.d.ts +0 -106
- package/local-dist-new/mcp/client-pool.d.ts.map +0 -1
- package/local-dist-new/mcp/client-pool.js +0 -234
- package/local-dist-new/mcp/client-pool.js.map +0 -1
- package/local-dist-new/mcp/client.d.ts +0 -158
- package/local-dist-new/mcp/client.d.ts.map +0 -1
- package/local-dist-new/mcp/client.js +0 -611
- package/local-dist-new/mcp/client.js.map +0 -1
- package/local-dist-new/mcp/config.d.ts +0 -61
- package/local-dist-new/mcp/config.d.ts.map +0 -1
- package/local-dist-new/mcp/config.js +0 -250
- package/local-dist-new/mcp/config.js.map +0 -1
- package/local-dist-new/mcp/errors.d.ts +0 -104
- package/local-dist-new/mcp/errors.d.ts.map +0 -1
- package/local-dist-new/mcp/errors.js +0 -146
- package/local-dist-new/mcp/errors.js.map +0 -1
- package/local-dist-new/mcp/index.d.ts +0 -56
- package/local-dist-new/mcp/index.d.ts.map +0 -1
- package/local-dist-new/mcp/index.js +0 -83
- package/local-dist-new/mcp/index.js.map +0 -1
- package/local-dist-new/mcp/schema-converter.d.ts +0 -68
- package/local-dist-new/mcp/schema-converter.d.ts.map +0 -1
- package/local-dist-new/mcp/schema-converter.js +0 -230
- package/local-dist-new/mcp/schema-converter.js.map +0 -1
- package/local-dist-new/mcp/server.d.ts +0 -111
- package/local-dist-new/mcp/server.d.ts.map +0 -1
- package/local-dist-new/mcp/server.js +0 -305
- package/local-dist-new/mcp/server.js.map +0 -1
- package/local-dist-new/mcp/tool-factory.d.ts +0 -63
- package/local-dist-new/mcp/tool-factory.d.ts.map +0 -1
- package/local-dist-new/mcp/tool-factory.js +0 -228
- package/local-dist-new/mcp/tool-factory.js.map +0 -1
- package/local-dist-new/mcp/types.d.ts +0 -289
- package/local-dist-new/mcp/types.d.ts.map +0 -1
- package/local-dist-new/mcp/types.js +0 -8
- package/local-dist-new/mcp/types.js.map +0 -1
- package/local-dist-new/mcp.d.ts +0 -2
- package/local-dist-new/mcp.d.ts.map +0 -1
- package/local-dist-new/mcp.js +0 -2
- package/local-dist-new/mcp.js.map +0 -1
- package/local-dist-new/ml/adapters/amazon-bedrock.d.ts +0 -33
- package/local-dist-new/ml/adapters/amazon-bedrock.d.ts.map +0 -1
- package/local-dist-new/ml/adapters/amazon-bedrock.js +0 -610
- package/local-dist-new/ml/adapters/amazon-bedrock.js.map +0 -1
- package/local-dist-new/ml/adapters/anthropic.d.ts +0 -62
- package/local-dist-new/ml/adapters/anthropic.d.ts.map +0 -1
- package/local-dist-new/ml/adapters/anthropic.js +0 -682
- package/local-dist-new/ml/adapters/anthropic.js.map +0 -1
- package/local-dist-new/ml/adapters/azure-openai-responses.d.ts +0 -15
- package/local-dist-new/ml/adapters/azure-openai-responses.d.ts.map +0 -1
- package/local-dist-new/ml/adapters/azure-openai-responses.js +0 -233
- package/local-dist-new/ml/adapters/azure-openai-responses.js.map +0 -1
- package/local-dist-new/ml/adapters/google-shared.d.ts +0 -60
- package/local-dist-new/ml/adapters/google-shared.d.ts.map +0 -1
- package/local-dist-new/ml/adapters/google-shared.js +0 -316
- package/local-dist-new/ml/adapters/google-shared.js.map +0 -1
- package/local-dist-new/ml/adapters/google-vertex.d.ts +0 -15
- package/local-dist-new/ml/adapters/google-vertex.d.ts.map +0 -1
- package/local-dist-new/ml/adapters/google-vertex.js +0 -396
- package/local-dist-new/ml/adapters/google-vertex.js.map +0 -1
- package/local-dist-new/ml/adapters/google.d.ts +0 -16
- package/local-dist-new/ml/adapters/google.d.ts.map +0 -1
- package/local-dist-new/ml/adapters/google.js +0 -381
- package/local-dist-new/ml/adapters/google.js.map +0 -1
- package/local-dist-new/ml/adapters/kimi.d.ts +0 -22
- package/local-dist-new/ml/adapters/kimi.d.ts.map +0 -1
- package/local-dist-new/ml/adapters/kimi.js +0 -249
- package/local-dist-new/ml/adapters/kimi.js.map +0 -1
- package/local-dist-new/ml/adapters/mock.d.ts +0 -10
- package/local-dist-new/ml/adapters/mock.d.ts.map +0 -1
- package/local-dist-new/ml/adapters/mock.js +0 -64
- package/local-dist-new/ml/adapters/mock.js.map +0 -1
- package/local-dist-new/ml/adapters/nvidia.d.ts +0 -14
- package/local-dist-new/ml/adapters/nvidia.d.ts.map +0 -1
- package/local-dist-new/ml/adapters/nvidia.js +0 -377
- package/local-dist-new/ml/adapters/nvidia.js.map +0 -1
- package/local-dist-new/ml/adapters/openai-codex-responses.d.ts +0 -9
- package/local-dist-new/ml/adapters/openai-codex-responses.d.ts.map +0 -1
- package/local-dist-new/ml/adapters/openai-codex-responses.js +0 -397
- package/local-dist-new/ml/adapters/openai-codex-responses.js.map +0 -1
- package/local-dist-new/ml/adapters/openai-completions.d.ts +0 -25
- package/local-dist-new/ml/adapters/openai-completions.d.ts.map +0 -1
- package/local-dist-new/ml/adapters/openai-completions.js +0 -831
- package/local-dist-new/ml/adapters/openai-completions.js.map +0 -1
- package/local-dist-new/ml/adapters/openai-responses-shared.d.ts +0 -26
- package/local-dist-new/ml/adapters/openai-responses-shared.d.ts.map +0 -1
- package/local-dist-new/ml/adapters/openai-responses-shared.js +0 -461
- package/local-dist-new/ml/adapters/openai-responses-shared.js.map +0 -1
- package/local-dist-new/ml/adapters/openai-responses.d.ts +0 -13
- package/local-dist-new/ml/adapters/openai-responses.d.ts.map +0 -1
- package/local-dist-new/ml/adapters/openai-responses.js +0 -209
- package/local-dist-new/ml/adapters/openai-responses.js.map +0 -1
- package/local-dist-new/ml/adapters/openai-scaffold.d.ts +0 -4
- package/local-dist-new/ml/adapters/openai-scaffold.d.ts.map +0 -1
- package/local-dist-new/ml/adapters/openai-scaffold.js +0 -33
- package/local-dist-new/ml/adapters/openai-scaffold.js.map +0 -1
- package/local-dist-new/ml/adapters/register-builtins.d.ts +0 -3
- package/local-dist-new/ml/adapters/register-builtins.d.ts.map +0 -1
- package/local-dist-new/ml/adapters/register-builtins.js +0 -143
- package/local-dist-new/ml/adapters/register-builtins.js.map +0 -1
- package/local-dist-new/ml/adapters/simple-options.d.ts +0 -27
- package/local-dist-new/ml/adapters/simple-options.d.ts.map +0 -1
- package/local-dist-new/ml/adapters/simple-options.js +0 -96
- package/local-dist-new/ml/adapters/simple-options.js.map +0 -1
- package/local-dist-new/ml/adapters/transform-messages.d.ts +0 -22
- package/local-dist-new/ml/adapters/transform-messages.d.ts.map +0 -1
- package/local-dist-new/ml/adapters/transform-messages.js +0 -147
- package/local-dist-new/ml/adapters/transform-messages.js.map +0 -1
- package/local-dist-new/ml/api-registry.d.ts +0 -50
- package/local-dist-new/ml/api-registry.d.ts.map +0 -1
- package/local-dist-new/ml/api-registry.js +0 -121
- package/local-dist-new/ml/api-registry.js.map +0 -1
- package/local-dist-new/ml/cli.d.ts +0 -3
- package/local-dist-new/ml/cli.d.ts.map +0 -1
- package/local-dist-new/ml/cli.js +0 -117
- package/local-dist-new/ml/cli.js.map +0 -1
- package/local-dist-new/ml/env-api-keys.d.ts +0 -18
- package/local-dist-new/ml/env-api-keys.d.ts.map +0 -1
- package/local-dist-new/ml/env-api-keys.js +0 -122
- package/local-dist-new/ml/env-api-keys.js.map +0 -1
- package/local-dist-new/ml/index.d.ts +0 -28
- package/local-dist-new/ml/index.d.ts.map +0 -1
- package/local-dist-new/ml/index.js +0 -28
- package/local-dist-new/ml/index.js.map +0 -1
- package/local-dist-new/ml/kit/auth/anthropic.d.ts +0 -18
- package/local-dist-new/ml/kit/auth/anthropic.d.ts.map +0 -1
- package/local-dist-new/ml/kit/auth/anthropic.js +0 -152
- package/local-dist-new/ml/kit/auth/anthropic.js.map +0 -1
- package/local-dist-new/ml/kit/auth/github-copilot.d.ts +0 -23
- package/local-dist-new/ml/kit/auth/github-copilot.d.ts.map +0 -1
- package/local-dist-new/ml/kit/auth/github-copilot.js +0 -275
- package/local-dist-new/ml/kit/auth/github-copilot.js.map +0 -1
- package/local-dist-new/ml/kit/auth/index.d.ts +0 -50
- package/local-dist-new/ml/kit/auth/index.d.ts.map +0 -1
- package/local-dist-new/ml/kit/auth/index.js +0 -112
- package/local-dist-new/ml/kit/auth/index.js.map +0 -1
- package/local-dist-new/ml/kit/auth/kimi.d.ts +0 -24
- package/local-dist-new/ml/kit/auth/kimi.d.ts.map +0 -1
- package/local-dist-new/ml/kit/auth/kimi.js +0 -30
- package/local-dist-new/ml/kit/auth/kimi.js.map +0 -1
- package/local-dist-new/ml/kit/auth/oauth-page.d.ts +0 -3
- package/local-dist-new/ml/kit/auth/oauth-page.d.ts.map +0 -1
- package/local-dist-new/ml/kit/auth/oauth-page.js +0 -105
- package/local-dist-new/ml/kit/auth/oauth-page.js.map +0 -1
- package/local-dist-new/ml/kit/auth/openai-codex.d.ts +0 -34
- package/local-dist-new/ml/kit/auth/openai-codex.d.ts.map +0 -1
- package/local-dist-new/ml/kit/auth/openai-codex.js +0 -373
- package/local-dist-new/ml/kit/auth/openai-codex.js.map +0 -1
- package/local-dist-new/ml/kit/auth/pkce.d.ts +0 -13
- package/local-dist-new/ml/kit/auth/pkce.d.ts.map +0 -1
- package/local-dist-new/ml/kit/auth/pkce.js +0 -31
- package/local-dist-new/ml/kit/auth/pkce.js.map +0 -1
- package/local-dist-new/ml/kit/auth/types.d.ts +0 -72
- package/local-dist-new/ml/kit/auth/types.d.ts.map +0 -1
- package/local-dist-new/ml/kit/auth/types.js +0 -11
- package/local-dist-new/ml/kit/auth/types.js.map +0 -1
- package/local-dist-new/ml/kit/base-stream-handler.d.ts +0 -16
- package/local-dist-new/ml/kit/base-stream-handler.d.ts.map +0 -1
- package/local-dist-new/ml/kit/base-stream-handler.js +0 -25
- package/local-dist-new/ml/kit/base-stream-handler.js.map +0 -1
- package/local-dist-new/ml/kit/event-stream.d.ts +0 -45
- package/local-dist-new/ml/kit/event-stream.d.ts.map +0 -1
- package/local-dist-new/ml/kit/event-stream.js +0 -178
- package/local-dist-new/ml/kit/event-stream.js.map +0 -1
- package/local-dist-new/ml/kit/index.d.ts +0 -15
- package/local-dist-new/ml/kit/index.d.ts.map +0 -1
- package/local-dist-new/ml/kit/index.js +0 -15
- package/local-dist-new/ml/kit/index.js.map +0 -1
- package/local-dist-new/ml/kit/json-parse.d.ts +0 -21
- package/local-dist-new/ml/kit/json-parse.d.ts.map +0 -1
- package/local-dist-new/ml/kit/json-parse.js +0 -44
- package/local-dist-new/ml/kit/json-parse.js.map +0 -1
- package/local-dist-new/ml/kit/message-transform.d.ts +0 -29
- package/local-dist-new/ml/kit/message-transform.d.ts.map +0 -1
- package/local-dist-new/ml/kit/message-transform.js +0 -55
- package/local-dist-new/ml/kit/message-transform.js.map +0 -1
- package/local-dist-new/ml/kit/output-factory.d.ts +0 -3
- package/local-dist-new/ml/kit/output-factory.d.ts.map +0 -1
- package/local-dist-new/ml/kit/output-factory.js +0 -23
- package/local-dist-new/ml/kit/output-factory.js.map +0 -1
- package/local-dist-new/ml/kit/overflow.d.ts +0 -10
- package/local-dist-new/ml/kit/overflow.d.ts.map +0 -1
- package/local-dist-new/ml/kit/overflow.js +0 -76
- package/local-dist-new/ml/kit/overflow.js.map +0 -1
- package/local-dist-new/ml/kit/provider-adapter.d.ts +0 -57
- package/local-dist-new/ml/kit/provider-adapter.d.ts.map +0 -1
- package/local-dist-new/ml/kit/provider-adapter.js +0 -37
- package/local-dist-new/ml/kit/provider-adapter.js.map +0 -1
- package/local-dist-new/ml/kit/provider-client-builder.d.ts +0 -37
- package/local-dist-new/ml/kit/provider-client-builder.d.ts.map +0 -1
- package/local-dist-new/ml/kit/provider-client-builder.js +0 -50
- package/local-dist-new/ml/kit/provider-client-builder.js.map +0 -1
- package/local-dist-new/ml/kit/provider-consolidation.d.ts +0 -4
- package/local-dist-new/ml/kit/provider-consolidation.d.ts.map +0 -1
- package/local-dist-new/ml/kit/provider-consolidation.js +0 -33
- package/local-dist-new/ml/kit/provider-consolidation.js.map +0 -1
- package/local-dist-new/ml/kit/provider-constants.d.ts +0 -35
- package/local-dist-new/ml/kit/provider-constants.d.ts.map +0 -1
- package/local-dist-new/ml/kit/provider-constants.js +0 -35
- package/local-dist-new/ml/kit/provider-constants.js.map +0 -1
- package/local-dist-new/ml/kit/provider-errors.d.ts +0 -46
- package/local-dist-new/ml/kit/provider-errors.d.ts.map +0 -1
- package/local-dist-new/ml/kit/provider-errors.js +0 -103
- package/local-dist-new/ml/kit/provider-errors.js.map +0 -1
- package/local-dist-new/ml/kit/sanitize-unicode.d.ts +0 -3
- package/local-dist-new/ml/kit/sanitize-unicode.d.ts.map +0 -1
- package/local-dist-new/ml/kit/sanitize-unicode.js +0 -60
- package/local-dist-new/ml/kit/sanitize-unicode.js.map +0 -1
- package/local-dist-new/ml/kit/stream-event-helper.d.ts +0 -28
- package/local-dist-new/ml/kit/stream-event-helper.d.ts.map +0 -1
- package/local-dist-new/ml/kit/stream-event-helper.js +0 -52
- package/local-dist-new/ml/kit/stream-event-helper.js.map +0 -1
- package/local-dist-new/ml/kit/stream-handler-types.d.ts +0 -43
- package/local-dist-new/ml/kit/stream-handler-types.d.ts.map +0 -1
- package/local-dist-new/ml/kit/stream-handler-types.js +0 -23
- package/local-dist-new/ml/kit/stream-handler-types.js.map +0 -1
- package/local-dist-new/ml/kit/streaming-state-manager.d.ts +0 -50
- package/local-dist-new/ml/kit/streaming-state-manager.d.ts.map +0 -1
- package/local-dist-new/ml/kit/streaming-state-manager.js +0 -67
- package/local-dist-new/ml/kit/streaming-state-manager.js.map +0 -1
- package/local-dist-new/ml/kit/tool-converter.d.ts +0 -50
- package/local-dist-new/ml/kit/tool-converter.d.ts.map +0 -1
- package/local-dist-new/ml/kit/tool-converter.js +0 -54
- package/local-dist-new/ml/kit/tool-converter.js.map +0 -1
- package/local-dist-new/ml/kit/typebox-helpers.d.ts +0 -24
- package/local-dist-new/ml/kit/typebox-helpers.d.ts.map +0 -1
- package/local-dist-new/ml/kit/typebox-helpers.js +0 -46
- package/local-dist-new/ml/kit/typebox-helpers.js.map +0 -1
- package/local-dist-new/ml/kit/validation.d.ts +0 -24
- package/local-dist-new/ml/kit/validation.d.ts.map +0 -1
- package/local-dist-new/ml/kit/validation.js +0 -119
- package/local-dist-new/ml/kit/validation.js.map +0 -1
- package/local-dist-new/ml/models.d.ts +0 -41
- package/local-dist-new/ml/models.d.ts.map +0 -1
- package/local-dist-new/ml/models.generated.d.ts +0 -12245
- package/local-dist-new/ml/models.generated.d.ts.map +0 -1
- package/local-dist-new/ml/models.generated.js +0 -12080
- package/local-dist-new/ml/models.generated.js.map +0 -1
- package/local-dist-new/ml/models.js +0 -126
- package/local-dist-new/ml/models.js.map +0 -1
- package/local-dist-new/ml/stream.d.ts +0 -12
- package/local-dist-new/ml/stream.d.ts.map +0 -1
- package/local-dist-new/ml/stream.js +0 -54
- package/local-dist-new/ml/stream.js.map +0 -1
- package/local-dist-new/ml/types.d.ts +0 -270
- package/local-dist-new/ml/types.d.ts.map +0 -1
- package/local-dist-new/ml/types.js +0 -169
- package/local-dist-new/ml/types.js.map +0 -1
- package/local-dist-new/observability.d.ts +0 -2
- package/local-dist-new/observability.d.ts.map +0 -1
- package/local-dist-new/observability.js +0 -2
- package/local-dist-new/observability.js.map +0 -1
- package/local-dist-new/react-host/index.d.ts +0 -10
- package/local-dist-new/react-host/index.d.ts.map +0 -1
- package/local-dist-new/react-host/index.js +0 -9
- package/local-dist-new/react-host/index.js.map +0 -1
- package/local-dist-new/react-host/ink.d.ts +0 -6
- package/local-dist-new/react-host/ink.d.ts.map +0 -1
- package/local-dist-new/react-host/ink.js +0 -7
- package/local-dist-new/react-host/ink.js.map +0 -1
- package/local-dist-new/react-host/jsx-runtime.d.ts +0 -5
- package/local-dist-new/react-host/jsx-runtime.d.ts.map +0 -1
- package/local-dist-new/react-host/jsx-runtime.js +0 -6
- package/local-dist-new/react-host/jsx-runtime.js.map +0 -1
- package/local-dist-new/react-host/loader.d.ts +0 -4
- package/local-dist-new/react-host/loader.d.ts.map +0 -1
- package/local-dist-new/react-host/loader.js +0 -108
- package/local-dist-new/react-host/loader.js.map +0 -1
- package/local-dist-new/react-ink/components/ChangelogBlock.d.ts +0 -9
- package/local-dist-new/react-ink/components/ChangelogBlock.d.ts.map +0 -1
- package/local-dist-new/react-ink/components/ChangelogBlock.js +0 -58
- package/local-dist-new/react-ink/components/ChangelogBlock.js.map +0 -1
- package/local-dist-new/react-ink/components/DisplayBlockView.d.ts +0 -9
- package/local-dist-new/react-ink/components/DisplayBlockView.d.ts.map +0 -1
- package/local-dist-new/react-ink/components/DisplayBlockView.js +0 -11
- package/local-dist-new/react-ink/components/DisplayBlockView.js.map +0 -1
- package/local-dist-new/react-ink/components/Footer.d.ts +0 -12
- package/local-dist-new/react-ink/components/Footer.d.ts.map +0 -1
- package/local-dist-new/react-ink/components/Footer.js +0 -113
- package/local-dist-new/react-ink/components/Footer.js.map +0 -1
- package/local-dist-new/react-ink/components/MessageList.d.ts +0 -15
- package/local-dist-new/react-ink/components/MessageList.d.ts.map +0 -1
- package/local-dist-new/react-ink/components/MessageList.js +0 -43
- package/local-dist-new/react-ink/components/MessageList.js.map +0 -1
- package/local-dist-new/react-ink/components/MessageRow.d.ts +0 -14
- package/local-dist-new/react-ink/components/MessageRow.d.ts.map +0 -1
- package/local-dist-new/react-ink/components/MessageRow.js +0 -35
- package/local-dist-new/react-ink/components/MessageRow.js.map +0 -1
- package/local-dist-new/react-ink/components/StatusLine.d.ts +0 -10
- package/local-dist-new/react-ink/components/StatusLine.d.ts.map +0 -1
- package/local-dist-new/react-ink/components/StatusLine.js +0 -39
- package/local-dist-new/react-ink/components/StatusLine.js.map +0 -1
- package/local-dist-new/react-ink/components/TaskPanel.d.ts +0 -12
- package/local-dist-new/react-ink/components/TaskPanel.d.ts.map +0 -1
- package/local-dist-new/react-ink/components/TaskPanel.js +0 -23
- package/local-dist-new/react-ink/components/TaskPanel.js.map +0 -1
- package/local-dist-new/react-ink/components/ToolEventBlock.d.ts +0 -18
- package/local-dist-new/react-ink/components/ToolEventBlock.d.ts.map +0 -1
- package/local-dist-new/react-ink/components/ToolEventBlock.js +0 -61
- package/local-dist-new/react-ink/components/ToolEventBlock.js.map +0 -1
- package/local-dist-new/react-ink/components/dialogs/DialogFrame.d.ts +0 -9
- package/local-dist-new/react-ink/components/dialogs/DialogFrame.d.ts.map +0 -1
- package/local-dist-new/react-ink/components/dialogs/DialogFrame.js +0 -6
- package/local-dist-new/react-ink/components/dialogs/DialogFrame.js.map +0 -1
- package/local-dist-new/react-ink/components/dialogs/LoginDialog.d.ts +0 -15
- package/local-dist-new/react-ink/components/dialogs/LoginDialog.d.ts.map +0 -1
- package/local-dist-new/react-ink/components/dialogs/LoginDialog.js +0 -10
- package/local-dist-new/react-ink/components/dialogs/LoginDialog.js.map +0 -1
- package/local-dist-new/react-ink/components/dialogs/ModelDialog.d.ts +0 -10
- package/local-dist-new/react-ink/components/dialogs/ModelDialog.d.ts.map +0 -1
- package/local-dist-new/react-ink/components/dialogs/ModelDialog.js +0 -64
- package/local-dist-new/react-ink/components/dialogs/ModelDialog.js.map +0 -1
- package/local-dist-new/react-ink/components/dialogs/OAuthDialog.d.ts +0 -10
- package/local-dist-new/react-ink/components/dialogs/OAuthDialog.d.ts.map +0 -1
- package/local-dist-new/react-ink/components/dialogs/OAuthDialog.js +0 -24
- package/local-dist-new/react-ink/components/dialogs/OAuthDialog.js.map +0 -1
- package/local-dist-new/react-ink/components/dialogs/ScopedModelsDialog.d.ts +0 -10
- package/local-dist-new/react-ink/components/dialogs/ScopedModelsDialog.d.ts.map +0 -1
- package/local-dist-new/react-ink/components/dialogs/ScopedModelsDialog.js +0 -95
- package/local-dist-new/react-ink/components/dialogs/ScopedModelsDialog.js.map +0 -1
- package/local-dist-new/react-ink/components/dialogs/SelectableDialog.d.ts +0 -17
- package/local-dist-new/react-ink/components/dialogs/SelectableDialog.d.ts.map +0 -1
- package/local-dist-new/react-ink/components/dialogs/SelectableDialog.js +0 -66
- package/local-dist-new/react-ink/components/dialogs/SelectableDialog.js.map +0 -1
- package/local-dist-new/react-ink/components/dialogs/SessionDialog.d.ts +0 -14
- package/local-dist-new/react-ink/components/dialogs/SessionDialog.d.ts.map +0 -1
- package/local-dist-new/react-ink/components/dialogs/SessionDialog.js +0 -201
- package/local-dist-new/react-ink/components/dialogs/SessionDialog.js.map +0 -1
- package/local-dist-new/react-ink/components/dialogs/SettingsDialog.d.ts +0 -15
- package/local-dist-new/react-ink/components/dialogs/SettingsDialog.d.ts.map +0 -1
- package/local-dist-new/react-ink/components/dialogs/SettingsDialog.js +0 -79
- package/local-dist-new/react-ink/components/dialogs/SettingsDialog.js.map +0 -1
- package/local-dist-new/react-ink/components/dialogs/StartupSessionPicker.d.ts +0 -10
- package/local-dist-new/react-ink/components/dialogs/StartupSessionPicker.d.ts.map +0 -1
- package/local-dist-new/react-ink/components/dialogs/StartupSessionPicker.js +0 -100
- package/local-dist-new/react-ink/components/dialogs/StartupSessionPicker.js.map +0 -1
- package/local-dist-new/react-ink/components/dialogs/ThemeDialog.d.ts +0 -8
- package/local-dist-new/react-ink/components/dialogs/ThemeDialog.d.ts.map +0 -1
- package/local-dist-new/react-ink/components/dialogs/ThemeDialog.js +0 -7
- package/local-dist-new/react-ink/components/dialogs/ThemeDialog.js.map +0 -1
- package/local-dist-new/react-ink/components/dialogs/TreeDialog.d.ts +0 -9
- package/local-dist-new/react-ink/components/dialogs/TreeDialog.d.ts.map +0 -1
- package/local-dist-new/react-ink/components/dialogs/TreeDialog.js +0 -7
- package/local-dist-new/react-ink/components/dialogs/TreeDialog.js.map +0 -1
- package/local-dist-new/react-ink/components/dialogs/UserMessageDialog.d.ts +0 -9
- package/local-dist-new/react-ink/components/dialogs/UserMessageDialog.d.ts.map +0 -1
- package/local-dist-new/react-ink/components/dialogs/UserMessageDialog.js +0 -7
- package/local-dist-new/react-ink/components/dialogs/UserMessageDialog.js.map +0 -1
- package/local-dist-new/react-ink/components/messages/AssistantMessage.d.ts +0 -13
- package/local-dist-new/react-ink/components/messages/AssistantMessage.d.ts.map +0 -1
- package/local-dist-new/react-ink/components/messages/AssistantMessage.js +0 -20
- package/local-dist-new/react-ink/components/messages/AssistantMessage.js.map +0 -1
- package/local-dist-new/react-ink/components/messages/BashMessage.d.ts +0 -9
- package/local-dist-new/react-ink/components/messages/BashMessage.d.ts.map +0 -1
- package/local-dist-new/react-ink/components/messages/BashMessage.js +0 -11
- package/local-dist-new/react-ink/components/messages/BashMessage.js.map +0 -1
- package/local-dist-new/react-ink/components/messages/BranchSummaryMessage.d.ts +0 -9
- package/local-dist-new/react-ink/components/messages/BranchSummaryMessage.d.ts.map +0 -1
- package/local-dist-new/react-ink/components/messages/BranchSummaryMessage.js +0 -6
- package/local-dist-new/react-ink/components/messages/BranchSummaryMessage.js.map +0 -1
- package/local-dist-new/react-ink/components/messages/CompactionMessage.d.ts +0 -9
- package/local-dist-new/react-ink/components/messages/CompactionMessage.d.ts.map +0 -1
- package/local-dist-new/react-ink/components/messages/CompactionMessage.js +0 -6
- package/local-dist-new/react-ink/components/messages/CompactionMessage.js.map +0 -1
- package/local-dist-new/react-ink/components/messages/CustomMessage.d.ts +0 -10
- package/local-dist-new/react-ink/components/messages/CustomMessage.d.ts.map +0 -1
- package/local-dist-new/react-ink/components/messages/CustomMessage.js +0 -9
- package/local-dist-new/react-ink/components/messages/CustomMessage.js.map +0 -1
- package/local-dist-new/react-ink/components/messages/SkillInvocationMessage.d.ts +0 -8
- package/local-dist-new/react-ink/components/messages/SkillInvocationMessage.d.ts.map +0 -1
- package/local-dist-new/react-ink/components/messages/SkillInvocationMessage.js +0 -10
- package/local-dist-new/react-ink/components/messages/SkillInvocationMessage.js.map +0 -1
- package/local-dist-new/react-ink/components/messages/ToolCallMessage.d.ts +0 -9
- package/local-dist-new/react-ink/components/messages/ToolCallMessage.d.ts.map +0 -1
- package/local-dist-new/react-ink/components/messages/ToolCallMessage.js +0 -8
- package/local-dist-new/react-ink/components/messages/ToolCallMessage.js.map +0 -1
- package/local-dist-new/react-ink/components/messages/ToolResultBlock.d.ts +0 -13
- package/local-dist-new/react-ink/components/messages/ToolResultBlock.d.ts.map +0 -1
- package/local-dist-new/react-ink/components/messages/ToolResultBlock.js +0 -8
- package/local-dist-new/react-ink/components/messages/ToolResultBlock.js.map +0 -1
- package/local-dist-new/react-ink/components/messages/UserMessage.d.ts +0 -10
- package/local-dist-new/react-ink/components/messages/UserMessage.d.ts.map +0 -1
- package/local-dist-new/react-ink/components/messages/UserMessage.js +0 -9
- package/local-dist-new/react-ink/components/messages/UserMessage.js.map +0 -1
- package/local-dist-new/react-ink/index.d.ts +0 -35
- package/local-dist-new/react-ink/index.d.ts.map +0 -1
- package/local-dist-new/react-ink/index.js +0 -35
- package/local-dist-new/react-ink/index.js.map +0 -1
- package/local-dist-new/react-ink/theme-adapter.d.ts +0 -10
- package/local-dist-new/react-ink/theme-adapter.d.ts.map +0 -1
- package/local-dist-new/react-ink/theme-adapter.js +0 -44
- package/local-dist-new/react-ink/theme-adapter.js.map +0 -1
- package/local-dist-new/react-ink/types.d.ts +0 -134
- package/local-dist-new/react-ink/types.d.ts.map +0 -1
- package/local-dist-new/react-ink/types.js +0 -2
- package/local-dist-new/react-ink/types.js.map +0 -1
- package/local-dist-new/react-ink/utils/message-groups.d.ts +0 -26
- package/local-dist-new/react-ink/utils/message-groups.d.ts.map +0 -1
- package/local-dist-new/react-ink/utils/message-groups.js +0 -240
- package/local-dist-new/react-ink/utils/message-groups.js.map +0 -1
- package/local-dist-new/react-ink/utils/selection-dialog.d.ts +0 -3
- package/local-dist-new/react-ink/utils/selection-dialog.d.ts.map +0 -1
- package/local-dist-new/react-ink/utils/selection-dialog.js +0 -18
- package/local-dist-new/react-ink/utils/selection-dialog.js.map +0 -1
- package/local-dist-new/react-ink/utils/session-browser.d.ts +0 -28
- package/local-dist-new/react-ink/utils/session-browser.d.ts.map +0 -1
- package/local-dist-new/react-ink/utils/session-browser.js +0 -191
- package/local-dist-new/react-ink/utils/session-browser.js.map +0 -1
- package/local-dist-new/react-ink/utils/tool-display.d.ts +0 -22
- package/local-dist-new/react-ink/utils/tool-display.d.ts.map +0 -1
- package/local-dist-new/react-ink/utils/tool-display.js +0 -349
- package/local-dist-new/react-ink/utils/tool-display.js.map +0 -1
- package/local-dist-new/react-ink.d.ts +0 -3
- package/local-dist-new/react-ink.d.ts.map +0 -1
- package/local-dist-new/react-ink.js +0 -2
- package/local-dist-new/react-ink.js.map +0 -1
- package/local-dist-new/tui.d.ts +0 -9
- package/local-dist-new/tui.d.ts.map +0 -1
- package/local-dist-new/tui.js +0 -8
- package/local-dist-new/tui.js.map +0 -1
- package/local-dist-new/ui/autocomplete.d.ts +0 -60
- package/local-dist-new/ui/autocomplete.d.ts.map +0 -1
- package/local-dist-new/ui/autocomplete.js +0 -393
- package/local-dist-new/ui/autocomplete.js.map +0 -1
- package/local-dist-new/ui/contracts.d.ts +0 -39
- package/local-dist-new/ui/contracts.d.ts.map +0 -1
- package/local-dist-new/ui/contracts.js +0 -2
- package/local-dist-new/ui/contracts.js.map +0 -1
- package/local-dist-new/ui/editor-component.d.ts +0 -101
- package/local-dist-new/ui/editor-component.d.ts.map +0 -1
- package/local-dist-new/ui/editor-component.js +0 -2
- package/local-dist-new/ui/editor-component.js.map +0 -1
- package/local-dist-new/ui/fuzzy.d.ts +0 -26
- package/local-dist-new/ui/fuzzy.d.ts.map +0 -1
- package/local-dist-new/ui/fuzzy.js +0 -177
- package/local-dist-new/ui/fuzzy.js.map +0 -1
- package/local-dist-new/ui/index.d.ts +0 -9
- package/local-dist-new/ui/index.d.ts.map +0 -1
- package/local-dist-new/ui/index.js +0 -6
- package/local-dist-new/ui/index.js.map +0 -1
- package/local-dist-new/ui/keybindings.d.ts +0 -52
- package/local-dist-new/ui/keybindings.d.ts.map +0 -1
- package/local-dist-new/ui/keybindings.js +0 -193
- package/local-dist-new/ui/keybindings.js.map +0 -1
- package/local-dist-new/ui/keys.d.ts +0 -168
- package/local-dist-new/ui/keys.d.ts.map +0 -1
- package/local-dist-new/ui/keys.js +0 -1093
- package/local-dist-new/ui/keys.js.map +0 -1
- package/local-dist-new/ui/theme-types.d.ts +0 -37
- package/local-dist-new/ui/theme-types.d.ts.map +0 -1
- package/local-dist-new/ui/theme-types.js +0 -2
- package/local-dist-new/ui/theme-types.js.map +0 -1
- package/local-dist-new/ui/utils.d.ts +0 -97
- package/local-dist-new/ui/utils.d.ts.map +0 -1
- package/local-dist-new/ui/utils.js +0 -860
- package/local-dist-new/ui/utils.js.map +0 -1
- package/observe.d.ts +0 -1
- package/observe.js +0 -1
|
@@ -0,0 +1,3209 @@
|
|
|
1
|
+
// src/llmgateway/contract/errors.ts
|
|
2
|
+
var GatewayError = class _GatewayError extends Error {
|
|
3
|
+
kind;
|
|
4
|
+
status;
|
|
5
|
+
provider;
|
|
6
|
+
constructor(kind, message, extra) {
|
|
7
|
+
super(message, extra?.cause !== void 0 ? { cause: extra.cause } : void 0);
|
|
8
|
+
this.name = "GatewayError";
|
|
9
|
+
this.kind = kind;
|
|
10
|
+
this.status = extra?.status;
|
|
11
|
+
this.provider = extra?.provider;
|
|
12
|
+
Object.setPrototypeOf(this, _GatewayError.prototype);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
function gatewayError(kind, message, extra) {
|
|
16
|
+
return new GatewayError(kind, message, extra);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// src/llmgateway/catalog/cards.ts
|
|
20
|
+
var MODEL_CARDS = [
|
|
21
|
+
// ── Anthropic (Claude) ──────────────────────────────────────────────────
|
|
22
|
+
{
|
|
23
|
+
id: "claude-opus-4",
|
|
24
|
+
provider: "anthropic",
|
|
25
|
+
api: "anthropic-messages",
|
|
26
|
+
displayName: "Claude Opus 4",
|
|
27
|
+
contextWindow: 2e5,
|
|
28
|
+
maxOutputTokens: 32e3,
|
|
29
|
+
modalities: ["text", "image"],
|
|
30
|
+
reasoning: true,
|
|
31
|
+
cost: {
|
|
32
|
+
// approximate — flagship tier
|
|
33
|
+
inputPerMTok: 15,
|
|
34
|
+
outputPerMTok: 75,
|
|
35
|
+
cacheReadPerMTok: 1.5,
|
|
36
|
+
cacheWritePerMTok: 18.75
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
id: "claude-sonnet-4",
|
|
41
|
+
provider: "anthropic",
|
|
42
|
+
api: "anthropic-messages",
|
|
43
|
+
displayName: "Claude Sonnet 4",
|
|
44
|
+
contextWindow: 2e5,
|
|
45
|
+
maxOutputTokens: 64e3,
|
|
46
|
+
modalities: ["text", "image"],
|
|
47
|
+
reasoning: true,
|
|
48
|
+
cost: {
|
|
49
|
+
// approximate — mid tier
|
|
50
|
+
inputPerMTok: 3,
|
|
51
|
+
outputPerMTok: 15,
|
|
52
|
+
cacheReadPerMTok: 0.3,
|
|
53
|
+
cacheWritePerMTok: 3.75
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
id: "claude-haiku-3-5",
|
|
58
|
+
provider: "anthropic",
|
|
59
|
+
api: "anthropic-messages",
|
|
60
|
+
displayName: "Claude Haiku 3.5",
|
|
61
|
+
contextWindow: 2e5,
|
|
62
|
+
maxOutputTokens: 8192,
|
|
63
|
+
modalities: ["text", "image"],
|
|
64
|
+
reasoning: false,
|
|
65
|
+
cost: {
|
|
66
|
+
// approximate — fast/cheap tier
|
|
67
|
+
inputPerMTok: 0.8,
|
|
68
|
+
outputPerMTok: 4,
|
|
69
|
+
cacheReadPerMTok: 0.08,
|
|
70
|
+
cacheWritePerMTok: 1
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
// ── OpenAI (GPT + o-series) ─────────────────────────────────────────────
|
|
74
|
+
{
|
|
75
|
+
id: "gpt-4o",
|
|
76
|
+
provider: "openai",
|
|
77
|
+
api: "openai-completions",
|
|
78
|
+
displayName: "GPT-4o",
|
|
79
|
+
contextWindow: 128e3,
|
|
80
|
+
maxOutputTokens: 16384,
|
|
81
|
+
modalities: ["text", "image", "audio"],
|
|
82
|
+
reasoning: false,
|
|
83
|
+
cost: {
|
|
84
|
+
// approximate — omni flagship
|
|
85
|
+
inputPerMTok: 2.5,
|
|
86
|
+
outputPerMTok: 10,
|
|
87
|
+
cacheReadPerMTok: 1.25
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
id: "gpt-4o-mini",
|
|
92
|
+
provider: "openai",
|
|
93
|
+
api: "openai-completions",
|
|
94
|
+
displayName: "GPT-4o mini",
|
|
95
|
+
contextWindow: 128e3,
|
|
96
|
+
maxOutputTokens: 16384,
|
|
97
|
+
modalities: ["text", "image"],
|
|
98
|
+
reasoning: false,
|
|
99
|
+
cost: {
|
|
100
|
+
// approximate — small omni
|
|
101
|
+
inputPerMTok: 0.15,
|
|
102
|
+
outputPerMTok: 0.6,
|
|
103
|
+
cacheReadPerMTok: 0.075
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
id: "o3",
|
|
108
|
+
provider: "openai",
|
|
109
|
+
api: "openai-responses",
|
|
110
|
+
displayName: "OpenAI o3",
|
|
111
|
+
contextWindow: 2e5,
|
|
112
|
+
maxOutputTokens: 1e5,
|
|
113
|
+
modalities: ["text", "image"],
|
|
114
|
+
reasoning: true,
|
|
115
|
+
cost: {
|
|
116
|
+
// approximate — reasoning flagship
|
|
117
|
+
inputPerMTok: 10,
|
|
118
|
+
outputPerMTok: 40,
|
|
119
|
+
cacheReadPerMTok: 2.5
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
id: "o4-mini",
|
|
124
|
+
provider: "openai",
|
|
125
|
+
api: "openai-responses",
|
|
126
|
+
displayName: "OpenAI o4-mini",
|
|
127
|
+
contextWindow: 2e5,
|
|
128
|
+
maxOutputTokens: 1e5,
|
|
129
|
+
modalities: ["text", "image"],
|
|
130
|
+
reasoning: true,
|
|
131
|
+
cost: {
|
|
132
|
+
// approximate — small reasoning
|
|
133
|
+
inputPerMTok: 1.1,
|
|
134
|
+
outputPerMTok: 4.4,
|
|
135
|
+
cacheReadPerMTok: 0.275
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
// ── Google (Gemini) ─────────────────────────────────────────────────────
|
|
139
|
+
{
|
|
140
|
+
id: "gemini-2.5-pro",
|
|
141
|
+
provider: "google",
|
|
142
|
+
api: "google-generative",
|
|
143
|
+
displayName: "Gemini 2.5 Pro",
|
|
144
|
+
contextWindow: 1e6,
|
|
145
|
+
maxOutputTokens: 65536,
|
|
146
|
+
modalities: ["text", "image", "audio"],
|
|
147
|
+
reasoning: true,
|
|
148
|
+
cost: {
|
|
149
|
+
// approximate — long-context pro tier
|
|
150
|
+
inputPerMTok: 1.25,
|
|
151
|
+
outputPerMTok: 10,
|
|
152
|
+
cacheReadPerMTok: 0.31
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
id: "gemini-2.5-flash",
|
|
157
|
+
provider: "google",
|
|
158
|
+
api: "google-generative",
|
|
159
|
+
displayName: "Gemini 2.5 Flash",
|
|
160
|
+
contextWindow: 1e6,
|
|
161
|
+
maxOutputTokens: 65536,
|
|
162
|
+
modalities: ["text", "image", "audio"],
|
|
163
|
+
reasoning: true,
|
|
164
|
+
cost: {
|
|
165
|
+
// approximate — fast flash tier
|
|
166
|
+
inputPerMTok: 0.3,
|
|
167
|
+
outputPerMTok: 2.5,
|
|
168
|
+
cacheReadPerMTok: 0.075
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
// ── NVIDIA (OpenAI-compatible NIM endpoint) ─────────────────────────────
|
|
172
|
+
{
|
|
173
|
+
id: "nvidia/llama-3.1-nemotron-70b-instruct",
|
|
174
|
+
provider: "nvidia",
|
|
175
|
+
api: "nvidia-openai-compatible",
|
|
176
|
+
displayName: "Nemotron 70B Instruct",
|
|
177
|
+
baseUrl: "https://integrate.api.nvidia.com/v1",
|
|
178
|
+
contextWindow: 128e3,
|
|
179
|
+
maxOutputTokens: 4096,
|
|
180
|
+
modalities: ["text"],
|
|
181
|
+
reasoning: false,
|
|
182
|
+
cost: {
|
|
183
|
+
// approximate — hosted NIM inference
|
|
184
|
+
inputPerMTok: 0.2,
|
|
185
|
+
outputPerMTok: 0.2
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
// ── Kimi / Moonshot (OpenAI-compatible) ─────────────────────────────────
|
|
189
|
+
{
|
|
190
|
+
id: "kimi-k2",
|
|
191
|
+
provider: "kimi",
|
|
192
|
+
api: "kimi-openai-compatible",
|
|
193
|
+
displayName: "Kimi K2",
|
|
194
|
+
baseUrl: "https://api.moonshot.ai/v1",
|
|
195
|
+
contextWindow: 256e3,
|
|
196
|
+
maxOutputTokens: 16384,
|
|
197
|
+
modalities: ["text"],
|
|
198
|
+
reasoning: true,
|
|
199
|
+
cost: {
|
|
200
|
+
// approximate — Moonshot hosted
|
|
201
|
+
inputPerMTok: 0.6,
|
|
202
|
+
outputPerMTok: 2.5,
|
|
203
|
+
cacheReadPerMTok: 0.15
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
// ── Ollama (local; pricing is zero — your own hardware) ─────────────────
|
|
207
|
+
{
|
|
208
|
+
id: "llama3.1:8b",
|
|
209
|
+
provider: "ollama",
|
|
210
|
+
api: "ollama",
|
|
211
|
+
displayName: "Llama 3.1 8B (local)",
|
|
212
|
+
baseUrl: "http://localhost:11434",
|
|
213
|
+
contextWindow: 128e3,
|
|
214
|
+
maxOutputTokens: 8192,
|
|
215
|
+
modalities: ["text"],
|
|
216
|
+
reasoning: false,
|
|
217
|
+
cost: {
|
|
218
|
+
// local inference — no per-token cost
|
|
219
|
+
inputPerMTok: 0,
|
|
220
|
+
outputPerMTok: 0
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
// ── Mock (deterministic test fixture; free) ─────────────────────────────
|
|
224
|
+
{
|
|
225
|
+
id: "mock-1",
|
|
226
|
+
provider: "mock",
|
|
227
|
+
api: "mock",
|
|
228
|
+
displayName: "Mock Model",
|
|
229
|
+
contextWindow: 32e3,
|
|
230
|
+
maxOutputTokens: 4096,
|
|
231
|
+
modalities: ["text"],
|
|
232
|
+
reasoning: false,
|
|
233
|
+
cost: {
|
|
234
|
+
inputPerMTok: 0,
|
|
235
|
+
outputPerMTok: 0
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
];
|
|
239
|
+
|
|
240
|
+
// src/llmgateway/catalog/query.ts
|
|
241
|
+
var CardSelection = class _CardSelection {
|
|
242
|
+
constructor(pool, tests) {
|
|
243
|
+
this.pool = pool;
|
|
244
|
+
this.tests = tests;
|
|
245
|
+
}
|
|
246
|
+
pool;
|
|
247
|
+
tests;
|
|
248
|
+
/** Begin a query over the given pool (defaults to the full catalog). */
|
|
249
|
+
static over(pool) {
|
|
250
|
+
return new _CardSelection(pool, []);
|
|
251
|
+
}
|
|
252
|
+
withTest(test) {
|
|
253
|
+
return new _CardSelection(this.pool, [...this.tests, test]);
|
|
254
|
+
}
|
|
255
|
+
/** Keep only cards from a specific vendor. */
|
|
256
|
+
byProvider(provider) {
|
|
257
|
+
return this.withTest((card) => card.provider === provider);
|
|
258
|
+
}
|
|
259
|
+
/** Keep only cards served over a specific wire dialect. */
|
|
260
|
+
byApi(api) {
|
|
261
|
+
return this.withTest((card) => card.api === api);
|
|
262
|
+
}
|
|
263
|
+
/** Keep cards whose reasoning capability matches `enabled`. */
|
|
264
|
+
reasoning(enabled) {
|
|
265
|
+
return this.withTest((card) => card.reasoning === enabled);
|
|
266
|
+
}
|
|
267
|
+
/** Materialize every card that satisfies all accumulated predicates. */
|
|
268
|
+
all() {
|
|
269
|
+
return this.pool.filter((card) => this.tests.every((test) => test(card)));
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Terminal lookup by exact `id`, also respecting any accumulated predicates.
|
|
273
|
+
* Returns `undefined` when no surviving card matches.
|
|
274
|
+
*/
|
|
275
|
+
find(id) {
|
|
276
|
+
return this.all().find((card) => card.id === id);
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
function models() {
|
|
280
|
+
return CardSelection.over(MODEL_CARDS);
|
|
281
|
+
}
|
|
282
|
+
function getCard(id) {
|
|
283
|
+
return MODEL_CARDS.find((card) => card.id === id);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// src/llmgateway/catalog/cost.ts
|
|
287
|
+
var TOKENS_PER_MTOK = 1e6;
|
|
288
|
+
function estimateCost(card, usage) {
|
|
289
|
+
const { cost } = card;
|
|
290
|
+
let dollars = 0;
|
|
291
|
+
dollars += usage.inputTokens / TOKENS_PER_MTOK * cost.inputPerMTok;
|
|
292
|
+
dollars += usage.outputTokens / TOKENS_PER_MTOK * cost.outputPerMTok;
|
|
293
|
+
if (usage.cacheReadTokens && cost.cacheReadPerMTok !== void 0) {
|
|
294
|
+
dollars += usage.cacheReadTokens / TOKENS_PER_MTOK * cost.cacheReadPerMTok;
|
|
295
|
+
}
|
|
296
|
+
if (usage.cacheWriteTokens && cost.cacheWritePerMTok !== void 0) {
|
|
297
|
+
dollars += usage.cacheWriteTokens / TOKENS_PER_MTOK * cost.cacheWritePerMTok;
|
|
298
|
+
}
|
|
299
|
+
return dollars;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// src/llmgateway/credentials/secrets.ts
|
|
303
|
+
var SECRET_TABLE = {
|
|
304
|
+
anthropic: {
|
|
305
|
+
provider: "anthropic",
|
|
306
|
+
scheme: "api-key",
|
|
307
|
+
envVars: ["ANTHROPIC_API_KEY"],
|
|
308
|
+
hint: "Anthropic Messages API bearer key."
|
|
309
|
+
},
|
|
310
|
+
openai: {
|
|
311
|
+
provider: "openai",
|
|
312
|
+
scheme: "api-key",
|
|
313
|
+
envVars: ["OPENAI_API_KEY"],
|
|
314
|
+
hint: "OpenAI platform API key."
|
|
315
|
+
},
|
|
316
|
+
google: {
|
|
317
|
+
provider: "google",
|
|
318
|
+
scheme: "api-key",
|
|
319
|
+
// Gemini Developer API: GEMINI_API_KEY is canonical; GOOGLE_API_KEY is the
|
|
320
|
+
// legacy/alias name still honored by the Generative Language API.
|
|
321
|
+
envVars: ["GEMINI_API_KEY", "GOOGLE_API_KEY"],
|
|
322
|
+
hint: "Google Generative Language (Gemini) API key."
|
|
323
|
+
},
|
|
324
|
+
"google-vertex": {
|
|
325
|
+
provider: "google-vertex",
|
|
326
|
+
scheme: "cloud-iam",
|
|
327
|
+
// Vertex authenticates via Application Default Credentials; these point at
|
|
328
|
+
// a service-account key file and the target project/region.
|
|
329
|
+
envVars: [
|
|
330
|
+
"GOOGLE_APPLICATION_CREDENTIALS",
|
|
331
|
+
"GOOGLE_VERTEX_PROJECT",
|
|
332
|
+
"GOOGLE_CLOUD_PROJECT"
|
|
333
|
+
],
|
|
334
|
+
hint: "Vertex AI via Application Default Credentials (service account)."
|
|
335
|
+
},
|
|
336
|
+
amazon: {
|
|
337
|
+
provider: "amazon",
|
|
338
|
+
scheme: "cloud-iam",
|
|
339
|
+
// Bedrock supports a short-lived bearer token, otherwise the standard
|
|
340
|
+
// AWS SigV4 credential chain.
|
|
341
|
+
envVars: [
|
|
342
|
+
"AWS_BEARER_TOKEN_BEDROCK",
|
|
343
|
+
"AWS_ACCESS_KEY_ID",
|
|
344
|
+
"AWS_PROFILE"
|
|
345
|
+
],
|
|
346
|
+
hint: "Amazon Bedrock via bearer token or AWS credential chain."
|
|
347
|
+
},
|
|
348
|
+
azure: {
|
|
349
|
+
provider: "azure",
|
|
350
|
+
scheme: "api-key",
|
|
351
|
+
envVars: ["AZURE_OPENAI_API_KEY", "AZURE_API_KEY"],
|
|
352
|
+
hint: "Azure OpenAI resource key (paired with endpoint + deployment)."
|
|
353
|
+
},
|
|
354
|
+
nvidia: {
|
|
355
|
+
provider: "nvidia",
|
|
356
|
+
scheme: "api-key",
|
|
357
|
+
envVars: ["NVIDIA_API_KEY"],
|
|
358
|
+
hint: "NVIDIA NIM / build.nvidia.com API key."
|
|
359
|
+
},
|
|
360
|
+
kimi: {
|
|
361
|
+
provider: "kimi",
|
|
362
|
+
scheme: "api-key",
|
|
363
|
+
// Moonshot AI ships the Kimi models; MOONSHOT_API_KEY is the documented
|
|
364
|
+
// name, KIMI_API_KEY is a common community alias.
|
|
365
|
+
envVars: ["MOONSHOT_API_KEY", "KIMI_API_KEY"],
|
|
366
|
+
hint: "Moonshot AI (Kimi) API key."
|
|
367
|
+
},
|
|
368
|
+
ollama: {
|
|
369
|
+
provider: "ollama",
|
|
370
|
+
scheme: "none",
|
|
371
|
+
envVars: [],
|
|
372
|
+
hint: "Local Ollama server \u2014 no credential required."
|
|
373
|
+
},
|
|
374
|
+
mock: {
|
|
375
|
+
provider: "mock",
|
|
376
|
+
scheme: "none",
|
|
377
|
+
envVars: [],
|
|
378
|
+
hint: "In-process mock transport \u2014 no credential required."
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
function readEnv(name) {
|
|
382
|
+
const raw = process.env[name];
|
|
383
|
+
if (raw === void 0) return void 0;
|
|
384
|
+
const trimmed = raw.trim();
|
|
385
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
386
|
+
}
|
|
387
|
+
async function resolveSecret(provider, override) {
|
|
388
|
+
if (override !== void 0) {
|
|
389
|
+
const trimmed = override.trim();
|
|
390
|
+
if (trimmed.length > 0) return trimmed;
|
|
391
|
+
}
|
|
392
|
+
const descriptor = SECRET_TABLE[provider];
|
|
393
|
+
if (descriptor.scheme === "none") return void 0;
|
|
394
|
+
for (const name of descriptor.envVars) {
|
|
395
|
+
const value = readEnv(name);
|
|
396
|
+
if (value !== void 0) return value;
|
|
397
|
+
}
|
|
398
|
+
return void 0;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// src/llmgateway/streaming/sse.ts
|
|
402
|
+
var LF = "\n";
|
|
403
|
+
var CR = "\r";
|
|
404
|
+
async function* sseEvents(body, signal) {
|
|
405
|
+
if (signal?.aborted) {
|
|
406
|
+
throw gatewayError("aborted", "request aborted before reading the event stream");
|
|
407
|
+
}
|
|
408
|
+
const reader = body.getReader();
|
|
409
|
+
const decoder = new TextDecoder("utf-8");
|
|
410
|
+
let pending = "";
|
|
411
|
+
let eventType = "message";
|
|
412
|
+
let dataLines = [];
|
|
413
|
+
let sawData = false;
|
|
414
|
+
const onAbort = () => {
|
|
415
|
+
void reader.cancel().catch(() => {
|
|
416
|
+
});
|
|
417
|
+
};
|
|
418
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
419
|
+
const resetEvent = () => {
|
|
420
|
+
eventType = "message";
|
|
421
|
+
dataLines = [];
|
|
422
|
+
sawData = false;
|
|
423
|
+
};
|
|
424
|
+
const dispatch = () => {
|
|
425
|
+
if (!sawData) {
|
|
426
|
+
resetEvent();
|
|
427
|
+
return void 0;
|
|
428
|
+
}
|
|
429
|
+
const out = { event: eventType, data: dataLines.join(LF) };
|
|
430
|
+
resetEvent();
|
|
431
|
+
return out;
|
|
432
|
+
};
|
|
433
|
+
const consumeLine = (line) => {
|
|
434
|
+
if (line === "") {
|
|
435
|
+
return dispatch();
|
|
436
|
+
}
|
|
437
|
+
if (line.startsWith(":")) {
|
|
438
|
+
return void 0;
|
|
439
|
+
}
|
|
440
|
+
const colon = line.indexOf(":");
|
|
441
|
+
let field;
|
|
442
|
+
let value;
|
|
443
|
+
if (colon === -1) {
|
|
444
|
+
field = line;
|
|
445
|
+
value = "";
|
|
446
|
+
} else {
|
|
447
|
+
field = line.slice(0, colon);
|
|
448
|
+
value = line.slice(colon + 1);
|
|
449
|
+
if (value.startsWith(" ")) {
|
|
450
|
+
value = value.slice(1);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
switch (field) {
|
|
454
|
+
case "event":
|
|
455
|
+
eventType = value;
|
|
456
|
+
break;
|
|
457
|
+
case "data":
|
|
458
|
+
dataLines.push(value);
|
|
459
|
+
sawData = true;
|
|
460
|
+
break;
|
|
461
|
+
// "id" and "retry" are valid SSE fields but irrelevant to LLM streams.
|
|
462
|
+
default:
|
|
463
|
+
break;
|
|
464
|
+
}
|
|
465
|
+
return void 0;
|
|
466
|
+
};
|
|
467
|
+
function* drainLines(atEnd) {
|
|
468
|
+
let start = 0;
|
|
469
|
+
let i = 0;
|
|
470
|
+
while (i < pending.length) {
|
|
471
|
+
const ch = pending[i];
|
|
472
|
+
if (ch === LF) {
|
|
473
|
+
yield pending.slice(start, i);
|
|
474
|
+
i += 1;
|
|
475
|
+
start = i;
|
|
476
|
+
} else if (ch === CR) {
|
|
477
|
+
if (i === pending.length - 1 && !atEnd) {
|
|
478
|
+
break;
|
|
479
|
+
}
|
|
480
|
+
yield pending.slice(start, i);
|
|
481
|
+
if (pending[i + 1] === LF) {
|
|
482
|
+
i += 2;
|
|
483
|
+
} else {
|
|
484
|
+
i += 1;
|
|
485
|
+
}
|
|
486
|
+
start = i;
|
|
487
|
+
} else {
|
|
488
|
+
i += 1;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
pending = pending.slice(start);
|
|
492
|
+
if (atEnd && pending.length > 0) {
|
|
493
|
+
const last = pending;
|
|
494
|
+
pending = "";
|
|
495
|
+
yield last;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
try {
|
|
499
|
+
for (; ; ) {
|
|
500
|
+
if (signal?.aborted) {
|
|
501
|
+
throw gatewayError("aborted", "request aborted while reading the event stream");
|
|
502
|
+
}
|
|
503
|
+
const { value, done } = await reader.read();
|
|
504
|
+
if (done) {
|
|
505
|
+
break;
|
|
506
|
+
}
|
|
507
|
+
pending += decoder.decode(value, { stream: true });
|
|
508
|
+
for (const line of drainLines(false)) {
|
|
509
|
+
const ev = consumeLine(line);
|
|
510
|
+
if (ev !== void 0) {
|
|
511
|
+
yield ev;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
pending += decoder.decode();
|
|
516
|
+
for (const line of drainLines(true)) {
|
|
517
|
+
const ev = consumeLine(line);
|
|
518
|
+
if (ev !== void 0) {
|
|
519
|
+
yield ev;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
} catch (cause) {
|
|
523
|
+
if (signal?.aborted) {
|
|
524
|
+
throw gatewayError("aborted", "request aborted while reading the event stream", { cause });
|
|
525
|
+
}
|
|
526
|
+
if (cause instanceof Error && cause.name === "GatewayError") {
|
|
527
|
+
throw cause;
|
|
528
|
+
}
|
|
529
|
+
throw gatewayError("transport", "failed reading the server-sent event stream", { cause });
|
|
530
|
+
} finally {
|
|
531
|
+
signal?.removeEventListener("abort", onAbort);
|
|
532
|
+
reader.releaseLock();
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
// src/llmgateway/conversion/reduce.ts
|
|
537
|
+
var EMPTY_USAGE = { inputTokens: 0, outputTokens: 0 };
|
|
538
|
+
function initial() {
|
|
539
|
+
return {
|
|
540
|
+
thinking: "",
|
|
541
|
+
text: "",
|
|
542
|
+
order: [],
|
|
543
|
+
calls: /* @__PURE__ */ new Map(),
|
|
544
|
+
usage: EMPTY_USAGE,
|
|
545
|
+
stop: "complete"
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
function ensureCall(state, id, name) {
|
|
549
|
+
const existing = state.calls.get(id);
|
|
550
|
+
if (existing === void 0) {
|
|
551
|
+
state.order.push(id);
|
|
552
|
+
state.calls.set(id, { name, args: "" });
|
|
553
|
+
} else if (name !== "" && existing.name === "") {
|
|
554
|
+
existing.name = name;
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
function step(state, emission) {
|
|
558
|
+
switch (emission.kind) {
|
|
559
|
+
case "text":
|
|
560
|
+
state.text += emission.delta;
|
|
561
|
+
break;
|
|
562
|
+
case "thinking":
|
|
563
|
+
state.thinking += emission.delta;
|
|
564
|
+
break;
|
|
565
|
+
case "tool_call_start":
|
|
566
|
+
ensureCall(state, emission.id, emission.name);
|
|
567
|
+
break;
|
|
568
|
+
case "tool_call_delta": {
|
|
569
|
+
ensureCall(state, emission.id, "");
|
|
570
|
+
const slot = state.calls.get(emission.id);
|
|
571
|
+
if (slot !== void 0) {
|
|
572
|
+
slot.args += emission.argsDelta;
|
|
573
|
+
}
|
|
574
|
+
break;
|
|
575
|
+
}
|
|
576
|
+
case "usage":
|
|
577
|
+
state.usage = emission.usage;
|
|
578
|
+
break;
|
|
579
|
+
case "stop":
|
|
580
|
+
state.stop = emission.stop;
|
|
581
|
+
break;
|
|
582
|
+
// `done` and `error` are terminal envelopes, not deltas to fold; a caller
|
|
583
|
+
// that hands them to the reducer simply contributes nothing.
|
|
584
|
+
case "done":
|
|
585
|
+
case "error":
|
|
586
|
+
break;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
function parseArgs(raw) {
|
|
590
|
+
const trimmed = raw.trim();
|
|
591
|
+
if (trimmed === "") {
|
|
592
|
+
return {};
|
|
593
|
+
}
|
|
594
|
+
try {
|
|
595
|
+
return JSON.parse(trimmed);
|
|
596
|
+
} catch {
|
|
597
|
+
return raw;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
function toBlocks(state) {
|
|
601
|
+
const blocks = [];
|
|
602
|
+
if (state.thinking !== "") {
|
|
603
|
+
const block = { kind: "thinking", text: state.thinking };
|
|
604
|
+
blocks.push(block);
|
|
605
|
+
}
|
|
606
|
+
if (state.text !== "") {
|
|
607
|
+
const block = { kind: "text", text: state.text };
|
|
608
|
+
blocks.push(block);
|
|
609
|
+
}
|
|
610
|
+
for (const id of state.order) {
|
|
611
|
+
const call = state.calls.get(id);
|
|
612
|
+
if (call === void 0) {
|
|
613
|
+
continue;
|
|
614
|
+
}
|
|
615
|
+
const block = {
|
|
616
|
+
kind: "tool_call",
|
|
617
|
+
id,
|
|
618
|
+
name: call.name,
|
|
619
|
+
input: parseArgs(call.args)
|
|
620
|
+
};
|
|
621
|
+
blocks.push(block);
|
|
622
|
+
}
|
|
623
|
+
return blocks;
|
|
624
|
+
}
|
|
625
|
+
function foldReply(model, emissions) {
|
|
626
|
+
const state = initial();
|
|
627
|
+
for (const emission of emissions) {
|
|
628
|
+
step(state, emission);
|
|
629
|
+
}
|
|
630
|
+
const blocks = toBlocks(state);
|
|
631
|
+
let stop = state.stop;
|
|
632
|
+
if (stop === "complete" && state.order.length > 0) {
|
|
633
|
+
stop = "tool_calls";
|
|
634
|
+
}
|
|
635
|
+
return {
|
|
636
|
+
role: "assistant",
|
|
637
|
+
model,
|
|
638
|
+
blocks,
|
|
639
|
+
usage: state.usage,
|
|
640
|
+
stop
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
// src/llmgateway/streaming/channel.ts
|
|
645
|
+
function channelOf(gen) {
|
|
646
|
+
return {
|
|
647
|
+
[Symbol.asyncIterator]() {
|
|
648
|
+
return gen();
|
|
649
|
+
}
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
async function collectReply(channel) {
|
|
653
|
+
const buffer = [];
|
|
654
|
+
let model = "unknown";
|
|
655
|
+
for await (const emission of channel) {
|
|
656
|
+
if (emission.kind === "done") {
|
|
657
|
+
return emission.reply;
|
|
658
|
+
}
|
|
659
|
+
if (emission.kind === "error") {
|
|
660
|
+
throw emission.error;
|
|
661
|
+
}
|
|
662
|
+
buffer.push(emission);
|
|
663
|
+
}
|
|
664
|
+
if (buffer.length === 0) {
|
|
665
|
+
throw gatewayError("transport", "channel closed without emitting any data");
|
|
666
|
+
}
|
|
667
|
+
return foldReply(model, buffer);
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
// src/llmgateway/conversion/mappers.ts
|
|
671
|
+
function stringifyToolOutput(output) {
|
|
672
|
+
if (typeof output === "string") {
|
|
673
|
+
return output;
|
|
674
|
+
}
|
|
675
|
+
try {
|
|
676
|
+
return JSON.stringify(output);
|
|
677
|
+
} catch {
|
|
678
|
+
return String(output);
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
function toArgumentString(input) {
|
|
682
|
+
if (typeof input === "string") {
|
|
683
|
+
return input;
|
|
684
|
+
}
|
|
685
|
+
try {
|
|
686
|
+
return JSON.stringify(input ?? {});
|
|
687
|
+
} catch {
|
|
688
|
+
return "{}";
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
function toOpenAIChatMessages(c) {
|
|
692
|
+
const messages = [];
|
|
693
|
+
if (c.system !== void 0 && c.system !== "") {
|
|
694
|
+
messages.push({ role: "system", content: c.system });
|
|
695
|
+
}
|
|
696
|
+
for (const turn of c.turns) {
|
|
697
|
+
switch (turn.role) {
|
|
698
|
+
case "user":
|
|
699
|
+
messages.push(openAiUserMessage(turn.blocks));
|
|
700
|
+
break;
|
|
701
|
+
case "assistant":
|
|
702
|
+
messages.push(openAiAssistantMessage(turn.blocks));
|
|
703
|
+
break;
|
|
704
|
+
case "tool":
|
|
705
|
+
for (const message of openAiToolMessages(turn.blocks)) {
|
|
706
|
+
messages.push(message);
|
|
707
|
+
}
|
|
708
|
+
break;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
return messages;
|
|
712
|
+
}
|
|
713
|
+
function openAiUserMessage(blocks) {
|
|
714
|
+
const parts = [];
|
|
715
|
+
let hasImage = false;
|
|
716
|
+
for (const block of blocks) {
|
|
717
|
+
if (block.kind === "text") {
|
|
718
|
+
parts.push({ type: "text", text: block.text });
|
|
719
|
+
} else if (block.kind === "image") {
|
|
720
|
+
hasImage = true;
|
|
721
|
+
parts.push({
|
|
722
|
+
type: "image_url",
|
|
723
|
+
image_url: { url: `data:${block.mediaType};base64,${block.dataBase64}` }
|
|
724
|
+
});
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
if (!hasImage) {
|
|
728
|
+
const text = parts.map((p) => p.text ?? "").join("");
|
|
729
|
+
return { role: "user", content: text };
|
|
730
|
+
}
|
|
731
|
+
return { role: "user", content: parts };
|
|
732
|
+
}
|
|
733
|
+
function openAiAssistantMessage(blocks) {
|
|
734
|
+
let text = "";
|
|
735
|
+
const toolCalls = [];
|
|
736
|
+
for (const block of blocks) {
|
|
737
|
+
if (block.kind === "text") {
|
|
738
|
+
text += block.text;
|
|
739
|
+
} else if (block.kind === "tool_call") {
|
|
740
|
+
toolCalls.push({
|
|
741
|
+
id: block.id,
|
|
742
|
+
type: "function",
|
|
743
|
+
function: { name: block.name, arguments: toArgumentString(block.input) }
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
const message = { role: "assistant", content: text === "" ? null : text };
|
|
748
|
+
if (toolCalls.length > 0) {
|
|
749
|
+
message.tool_calls = toolCalls;
|
|
750
|
+
}
|
|
751
|
+
return message;
|
|
752
|
+
}
|
|
753
|
+
function openAiToolMessages(blocks) {
|
|
754
|
+
const out = [];
|
|
755
|
+
for (const block of blocks) {
|
|
756
|
+
if (block.kind === "tool_result") {
|
|
757
|
+
out.push({
|
|
758
|
+
role: "tool",
|
|
759
|
+
tool_call_id: block.callId,
|
|
760
|
+
content: stringifyToolOutput(block.output)
|
|
761
|
+
});
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
return out;
|
|
765
|
+
}
|
|
766
|
+
function toOpenAITools(tools) {
|
|
767
|
+
if (tools === void 0 || tools.length === 0) {
|
|
768
|
+
return void 0;
|
|
769
|
+
}
|
|
770
|
+
return tools.map((tool) => ({
|
|
771
|
+
type: "function",
|
|
772
|
+
function: {
|
|
773
|
+
name: tool.name,
|
|
774
|
+
description: tool.description,
|
|
775
|
+
parameters: tool.parameters
|
|
776
|
+
}
|
|
777
|
+
}));
|
|
778
|
+
}
|
|
779
|
+
function toOpenAIToolChoice(choice) {
|
|
780
|
+
if (choice === void 0) {
|
|
781
|
+
return void 0;
|
|
782
|
+
}
|
|
783
|
+
return choice;
|
|
784
|
+
}
|
|
785
|
+
function anthropicThinkingBudget(level, maxOutput) {
|
|
786
|
+
const fraction = {
|
|
787
|
+
low: 0.2,
|
|
788
|
+
medium: 0.4,
|
|
789
|
+
high: 0.6,
|
|
790
|
+
max: 0.8
|
|
791
|
+
};
|
|
792
|
+
if (level === "off") {
|
|
793
|
+
return 0;
|
|
794
|
+
}
|
|
795
|
+
const budget = Math.floor(maxOutput * fraction[level]);
|
|
796
|
+
return Math.max(1024, budget);
|
|
797
|
+
}
|
|
798
|
+
function toAnthropicRequest(c, model, opts) {
|
|
799
|
+
const body = {
|
|
800
|
+
model: model.id,
|
|
801
|
+
max_tokens: opts.maxOutputTokens ?? model.maxOutputTokens,
|
|
802
|
+
messages: toAnthropicMessages(c)
|
|
803
|
+
};
|
|
804
|
+
if (c.system !== void 0 && c.system !== "") {
|
|
805
|
+
body.system = c.system;
|
|
806
|
+
}
|
|
807
|
+
const tools = toAnthropicTools(c.tools);
|
|
808
|
+
if (tools !== void 0) {
|
|
809
|
+
body.tools = tools;
|
|
810
|
+
}
|
|
811
|
+
const toolChoice = toAnthropicToolChoice(opts.toolChoice);
|
|
812
|
+
if (toolChoice !== void 0) {
|
|
813
|
+
body.tool_choice = toolChoice;
|
|
814
|
+
}
|
|
815
|
+
if (opts.temperature !== void 0) {
|
|
816
|
+
body.temperature = opts.temperature;
|
|
817
|
+
}
|
|
818
|
+
if (opts.topP !== void 0) {
|
|
819
|
+
body.top_p = opts.topP;
|
|
820
|
+
}
|
|
821
|
+
if (model.reasoning && opts.thinking !== void 0 && opts.thinking !== "off") {
|
|
822
|
+
const max = opts.maxOutputTokens ?? model.maxOutputTokens;
|
|
823
|
+
body.thinking = { type: "enabled", budget_tokens: anthropicThinkingBudget(opts.thinking, max) };
|
|
824
|
+
}
|
|
825
|
+
return body;
|
|
826
|
+
}
|
|
827
|
+
function toAnthropicMessages(c) {
|
|
828
|
+
const messages = [];
|
|
829
|
+
for (const turn of c.turns) {
|
|
830
|
+
if (turn.role === "tool") {
|
|
831
|
+
messages.push({ role: "user", content: anthropicContent(turn) });
|
|
832
|
+
} else {
|
|
833
|
+
messages.push({ role: turn.role, content: anthropicContent(turn) });
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
return messages;
|
|
837
|
+
}
|
|
838
|
+
function anthropicContent(turn) {
|
|
839
|
+
const content = [];
|
|
840
|
+
for (const block of turn.blocks) {
|
|
841
|
+
switch (block.kind) {
|
|
842
|
+
case "text":
|
|
843
|
+
content.push({ type: "text", text: block.text });
|
|
844
|
+
break;
|
|
845
|
+
case "thinking":
|
|
846
|
+
content.push(
|
|
847
|
+
block.signature !== void 0 ? { type: "thinking", thinking: block.text, signature: block.signature } : { type: "thinking", thinking: block.text }
|
|
848
|
+
);
|
|
849
|
+
break;
|
|
850
|
+
case "tool_call":
|
|
851
|
+
content.push({
|
|
852
|
+
type: "tool_use",
|
|
853
|
+
id: block.id,
|
|
854
|
+
name: block.name,
|
|
855
|
+
input: typeof block.input === "string" ? safeParse(block.input) : block.input ?? {}
|
|
856
|
+
});
|
|
857
|
+
break;
|
|
858
|
+
case "tool_result":
|
|
859
|
+
content.push({
|
|
860
|
+
type: "tool_result",
|
|
861
|
+
tool_use_id: block.callId,
|
|
862
|
+
content: stringifyToolOutput(block.output),
|
|
863
|
+
...block.isError === true ? { is_error: true } : {}
|
|
864
|
+
});
|
|
865
|
+
break;
|
|
866
|
+
case "image":
|
|
867
|
+
content.push({
|
|
868
|
+
type: "image",
|
|
869
|
+
source: { type: "base64", media_type: block.mediaType, data: block.dataBase64 }
|
|
870
|
+
});
|
|
871
|
+
break;
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
return content;
|
|
875
|
+
}
|
|
876
|
+
function toAnthropicTools(tools) {
|
|
877
|
+
if (tools === void 0 || tools.length === 0) {
|
|
878
|
+
return void 0;
|
|
879
|
+
}
|
|
880
|
+
return tools.map((tool) => ({
|
|
881
|
+
name: tool.name,
|
|
882
|
+
description: tool.description,
|
|
883
|
+
input_schema: tool.parameters
|
|
884
|
+
}));
|
|
885
|
+
}
|
|
886
|
+
function toAnthropicToolChoice(choice) {
|
|
887
|
+
switch (choice) {
|
|
888
|
+
case "auto":
|
|
889
|
+
return { type: "auto" };
|
|
890
|
+
case "required":
|
|
891
|
+
return { type: "any" };
|
|
892
|
+
case "none":
|
|
893
|
+
return { type: "none" };
|
|
894
|
+
default:
|
|
895
|
+
return void 0;
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
function toGoogleContents(c) {
|
|
899
|
+
const contents = [];
|
|
900
|
+
for (const turn of c.turns) {
|
|
901
|
+
const role = turn.role === "assistant" ? "model" : "user";
|
|
902
|
+
contents.push({ role, parts: googleParts(turn) });
|
|
903
|
+
}
|
|
904
|
+
return contents;
|
|
905
|
+
}
|
|
906
|
+
function googleParts(turn) {
|
|
907
|
+
const parts = [];
|
|
908
|
+
for (const block of turn.blocks) {
|
|
909
|
+
switch (block.kind) {
|
|
910
|
+
case "text":
|
|
911
|
+
parts.push({ text: block.text });
|
|
912
|
+
break;
|
|
913
|
+
case "thinking":
|
|
914
|
+
parts.push({ text: block.text, thought: true });
|
|
915
|
+
break;
|
|
916
|
+
case "tool_call":
|
|
917
|
+
parts.push({
|
|
918
|
+
functionCall: {
|
|
919
|
+
name: block.name,
|
|
920
|
+
args: typeof block.input === "string" ? safeParse(block.input) : block.input ?? {}
|
|
921
|
+
}
|
|
922
|
+
});
|
|
923
|
+
break;
|
|
924
|
+
case "tool_result":
|
|
925
|
+
parts.push({
|
|
926
|
+
functionResponse: {
|
|
927
|
+
name: block.callId,
|
|
928
|
+
response: { result: stringifyToolOutput(block.output) }
|
|
929
|
+
}
|
|
930
|
+
});
|
|
931
|
+
break;
|
|
932
|
+
case "image":
|
|
933
|
+
parts.push({ inlineData: { mimeType: block.mediaType, data: block.dataBase64 } });
|
|
934
|
+
break;
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
return parts;
|
|
938
|
+
}
|
|
939
|
+
function toGoogleSystemInstruction(c) {
|
|
940
|
+
if (c.system === void 0 || c.system === "") {
|
|
941
|
+
return void 0;
|
|
942
|
+
}
|
|
943
|
+
return { role: "system", parts: [{ text: c.system }] };
|
|
944
|
+
}
|
|
945
|
+
function toGoogleTools(tools) {
|
|
946
|
+
if (tools === void 0 || tools.length === 0) {
|
|
947
|
+
return void 0;
|
|
948
|
+
}
|
|
949
|
+
return [
|
|
950
|
+
{
|
|
951
|
+
functionDeclarations: tools.map((tool) => ({
|
|
952
|
+
name: tool.name,
|
|
953
|
+
description: tool.description,
|
|
954
|
+
parameters: tool.parameters
|
|
955
|
+
}))
|
|
956
|
+
}
|
|
957
|
+
];
|
|
958
|
+
}
|
|
959
|
+
function toResponsesInput(c) {
|
|
960
|
+
const input = [];
|
|
961
|
+
for (const turn of c.turns) {
|
|
962
|
+
switch (turn.role) {
|
|
963
|
+
case "user":
|
|
964
|
+
input.push({ type: "message", role: "user", content: responsesUserContent(turn.blocks) });
|
|
965
|
+
break;
|
|
966
|
+
case "assistant":
|
|
967
|
+
for (const item of responsesAssistantItems(turn.blocks)) {
|
|
968
|
+
input.push(item);
|
|
969
|
+
}
|
|
970
|
+
break;
|
|
971
|
+
case "tool":
|
|
972
|
+
for (const block of turn.blocks) {
|
|
973
|
+
if (block.kind === "tool_result") {
|
|
974
|
+
input.push({
|
|
975
|
+
type: "function_call_output",
|
|
976
|
+
call_id: block.callId,
|
|
977
|
+
output: stringifyToolOutput(block.output)
|
|
978
|
+
});
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
break;
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
return input;
|
|
985
|
+
}
|
|
986
|
+
function responsesUserContent(blocks) {
|
|
987
|
+
const parts = [];
|
|
988
|
+
for (const block of blocks) {
|
|
989
|
+
if (block.kind === "text") {
|
|
990
|
+
parts.push({ type: "input_text", text: block.text });
|
|
991
|
+
} else if (block.kind === "image") {
|
|
992
|
+
parts.push({
|
|
993
|
+
type: "input_image",
|
|
994
|
+
image_url: `data:${block.mediaType};base64,${block.dataBase64}`
|
|
995
|
+
});
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
return parts;
|
|
999
|
+
}
|
|
1000
|
+
function responsesAssistantItems(blocks) {
|
|
1001
|
+
const items = [];
|
|
1002
|
+
const content = [];
|
|
1003
|
+
for (const block of blocks) {
|
|
1004
|
+
if (block.kind === "text") {
|
|
1005
|
+
content.push({ type: "output_text", text: block.text });
|
|
1006
|
+
} else if (block.kind === "tool_call") {
|
|
1007
|
+
items.push({
|
|
1008
|
+
type: "function_call",
|
|
1009
|
+
call_id: block.id,
|
|
1010
|
+
name: block.name,
|
|
1011
|
+
arguments: toArgumentString(block.input)
|
|
1012
|
+
});
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
if (content.length > 0) {
|
|
1016
|
+
items.unshift({ type: "message", role: "assistant", content });
|
|
1017
|
+
}
|
|
1018
|
+
return items;
|
|
1019
|
+
}
|
|
1020
|
+
function toResponsesTools(tools) {
|
|
1021
|
+
if (tools === void 0 || tools.length === 0) {
|
|
1022
|
+
return void 0;
|
|
1023
|
+
}
|
|
1024
|
+
return tools.map((tool) => ({
|
|
1025
|
+
type: "function",
|
|
1026
|
+
name: tool.name,
|
|
1027
|
+
description: tool.description,
|
|
1028
|
+
parameters: tool.parameters
|
|
1029
|
+
}));
|
|
1030
|
+
}
|
|
1031
|
+
function safeParse(raw) {
|
|
1032
|
+
try {
|
|
1033
|
+
return JSON.parse(raw);
|
|
1034
|
+
} catch {
|
|
1035
|
+
return {};
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
// src/llmgateway/connectors/anthropic.ts
|
|
1040
|
+
var DEFAULT_BASE_URL = "https://api.anthropic.com";
|
|
1041
|
+
var ANTHROPIC_VERSION = "2023-06-01";
|
|
1042
|
+
function isObject(v) {
|
|
1043
|
+
return typeof v === "object" && v !== null;
|
|
1044
|
+
}
|
|
1045
|
+
function readString(o, key) {
|
|
1046
|
+
const v = o[key];
|
|
1047
|
+
return typeof v === "string" ? v : void 0;
|
|
1048
|
+
}
|
|
1049
|
+
function readNumber(o, key) {
|
|
1050
|
+
const v = o[key];
|
|
1051
|
+
return typeof v === "number" && Number.isFinite(v) ? v : void 0;
|
|
1052
|
+
}
|
|
1053
|
+
function mapStopReason(reason) {
|
|
1054
|
+
switch (reason) {
|
|
1055
|
+
case "end_turn":
|
|
1056
|
+
case "stop_sequence":
|
|
1057
|
+
return "complete";
|
|
1058
|
+
case "tool_use":
|
|
1059
|
+
return "tool_calls";
|
|
1060
|
+
case "max_tokens":
|
|
1061
|
+
return "max_output";
|
|
1062
|
+
case "refusal":
|
|
1063
|
+
return "refusal";
|
|
1064
|
+
case null:
|
|
1065
|
+
case void 0:
|
|
1066
|
+
case "":
|
|
1067
|
+
return void 0;
|
|
1068
|
+
default:
|
|
1069
|
+
return "complete";
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
function mergeUsage(current, raw) {
|
|
1073
|
+
if (!isObject(raw)) {
|
|
1074
|
+
return current;
|
|
1075
|
+
}
|
|
1076
|
+
const next = { ...current };
|
|
1077
|
+
const input = readNumber(raw, "input_tokens");
|
|
1078
|
+
if (input !== void 0) {
|
|
1079
|
+
next.inputTokens = input;
|
|
1080
|
+
}
|
|
1081
|
+
const output = readNumber(raw, "output_tokens");
|
|
1082
|
+
if (output !== void 0) {
|
|
1083
|
+
next.outputTokens = output;
|
|
1084
|
+
}
|
|
1085
|
+
const cacheRead = readNumber(raw, "cache_read_input_tokens");
|
|
1086
|
+
if (cacheRead !== void 0) {
|
|
1087
|
+
next.cacheReadTokens = cacheRead;
|
|
1088
|
+
}
|
|
1089
|
+
const cacheWrite = readNumber(raw, "cache_creation_input_tokens");
|
|
1090
|
+
if (cacheWrite !== void 0) {
|
|
1091
|
+
next.cacheWriteTokens = cacheWrite;
|
|
1092
|
+
}
|
|
1093
|
+
return next;
|
|
1094
|
+
}
|
|
1095
|
+
function parseEventData(event, provider) {
|
|
1096
|
+
if (event.data === "") {
|
|
1097
|
+
return void 0;
|
|
1098
|
+
}
|
|
1099
|
+
let parsed;
|
|
1100
|
+
try {
|
|
1101
|
+
parsed = JSON.parse(event.data);
|
|
1102
|
+
} catch (cause) {
|
|
1103
|
+
throw gatewayError("parse", "could not decode an Anthropic stream event", { provider, cause });
|
|
1104
|
+
}
|
|
1105
|
+
return isObject(parsed) ? parsed : void 0;
|
|
1106
|
+
}
|
|
1107
|
+
function* emitFromEvent(type, payload, state) {
|
|
1108
|
+
switch (type) {
|
|
1109
|
+
case "message_start": {
|
|
1110
|
+
const message = payload.message;
|
|
1111
|
+
if (isObject(message)) {
|
|
1112
|
+
state.usage = mergeUsage(state.usage, message.usage);
|
|
1113
|
+
yield { kind: "usage", usage: state.usage };
|
|
1114
|
+
}
|
|
1115
|
+
return;
|
|
1116
|
+
}
|
|
1117
|
+
case "content_block_start": {
|
|
1118
|
+
yield* emitBlockStart(payload, state);
|
|
1119
|
+
return;
|
|
1120
|
+
}
|
|
1121
|
+
case "content_block_delta": {
|
|
1122
|
+
yield* emitBlockDelta(payload, state);
|
|
1123
|
+
return;
|
|
1124
|
+
}
|
|
1125
|
+
case "content_block_stop": {
|
|
1126
|
+
return;
|
|
1127
|
+
}
|
|
1128
|
+
case "message_delta": {
|
|
1129
|
+
const delta = payload.delta;
|
|
1130
|
+
if (isObject(delta)) {
|
|
1131
|
+
const stop = mapStopReason(readString(delta, "stop_reason"));
|
|
1132
|
+
if (stop !== void 0) {
|
|
1133
|
+
yield { kind: "stop", stop };
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
const usage = payload.usage;
|
|
1137
|
+
if (usage !== void 0) {
|
|
1138
|
+
state.usage = mergeUsage(state.usage, usage);
|
|
1139
|
+
yield { kind: "usage", usage: state.usage };
|
|
1140
|
+
}
|
|
1141
|
+
return;
|
|
1142
|
+
}
|
|
1143
|
+
case "message_stop":
|
|
1144
|
+
case "ping":
|
|
1145
|
+
return;
|
|
1146
|
+
case "error": {
|
|
1147
|
+
const error = payload.error;
|
|
1148
|
+
const detail = isObject(error) ? readString(error, "message") : void 0;
|
|
1149
|
+
throw gatewayError("http", `Anthropic reported a stream error${detail !== void 0 ? `: ${detail}` : ""}`);
|
|
1150
|
+
}
|
|
1151
|
+
default:
|
|
1152
|
+
return;
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
function* emitBlockStart(payload, state) {
|
|
1156
|
+
const index = readNumber(payload, "index") ?? 0;
|
|
1157
|
+
const block = payload.content_block;
|
|
1158
|
+
if (!isObject(block)) {
|
|
1159
|
+
return;
|
|
1160
|
+
}
|
|
1161
|
+
if (readString(block, "type") === "tool_use") {
|
|
1162
|
+
const id = readString(block, "id") ?? `tool_${index}`;
|
|
1163
|
+
const name = readString(block, "name") ?? "";
|
|
1164
|
+
state.toolIds.set(index, id);
|
|
1165
|
+
yield { kind: "tool_call_start", id, name };
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
function* emitBlockDelta(payload, state) {
|
|
1169
|
+
const index = readNumber(payload, "index") ?? 0;
|
|
1170
|
+
const delta = payload.delta;
|
|
1171
|
+
if (!isObject(delta)) {
|
|
1172
|
+
return;
|
|
1173
|
+
}
|
|
1174
|
+
switch (readString(delta, "type")) {
|
|
1175
|
+
case "text_delta": {
|
|
1176
|
+
const text = readString(delta, "text");
|
|
1177
|
+
if (text !== void 0 && text !== "") {
|
|
1178
|
+
yield { kind: "text", delta: text };
|
|
1179
|
+
}
|
|
1180
|
+
return;
|
|
1181
|
+
}
|
|
1182
|
+
case "thinking_delta": {
|
|
1183
|
+
const thinking = readString(delta, "thinking");
|
|
1184
|
+
if (thinking !== void 0 && thinking !== "") {
|
|
1185
|
+
yield { kind: "thinking", delta: thinking };
|
|
1186
|
+
}
|
|
1187
|
+
return;
|
|
1188
|
+
}
|
|
1189
|
+
case "input_json_delta": {
|
|
1190
|
+
const fragment = readString(delta, "partial_json");
|
|
1191
|
+
if (fragment !== void 0 && fragment !== "") {
|
|
1192
|
+
const id = state.toolIds.get(index);
|
|
1193
|
+
if (id !== void 0) {
|
|
1194
|
+
yield { kind: "tool_call_delta", id, argsDelta: fragment };
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
return;
|
|
1198
|
+
}
|
|
1199
|
+
// `signature_delta` (thinking signatures) carries no user-visible content.
|
|
1200
|
+
default:
|
|
1201
|
+
return;
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
function endpointFor(model) {
|
|
1205
|
+
const base = (model.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
1206
|
+
return `${base}/v1/messages`;
|
|
1207
|
+
}
|
|
1208
|
+
async function postMessages(url, apiKey, body, signal) {
|
|
1209
|
+
let response;
|
|
1210
|
+
try {
|
|
1211
|
+
response = await fetch(url, {
|
|
1212
|
+
method: "POST",
|
|
1213
|
+
headers: {
|
|
1214
|
+
"content-type": "application/json",
|
|
1215
|
+
"x-api-key": apiKey,
|
|
1216
|
+
"anthropic-version": ANTHROPIC_VERSION
|
|
1217
|
+
},
|
|
1218
|
+
body: JSON.stringify(body),
|
|
1219
|
+
...signal !== void 0 ? { signal } : {}
|
|
1220
|
+
});
|
|
1221
|
+
} catch (cause) {
|
|
1222
|
+
if (signal?.aborted) {
|
|
1223
|
+
throw gatewayError("aborted", "request canceled before Anthropic responded", {
|
|
1224
|
+
provider: "anthropic",
|
|
1225
|
+
cause
|
|
1226
|
+
});
|
|
1227
|
+
}
|
|
1228
|
+
throw gatewayError("transport", "network call to Anthropic failed", { provider: "anthropic", cause });
|
|
1229
|
+
}
|
|
1230
|
+
if (!response.ok) {
|
|
1231
|
+
const detail = await readErrorBody(response);
|
|
1232
|
+
const kind = response.status === 401 || response.status === 403 ? "auth" : response.status === 429 ? "rate_limit" : "http";
|
|
1233
|
+
throw gatewayError(kind, `Anthropic returned HTTP ${response.status}${detail}`, {
|
|
1234
|
+
provider: "anthropic",
|
|
1235
|
+
status: response.status
|
|
1236
|
+
});
|
|
1237
|
+
}
|
|
1238
|
+
if (response.body === null) {
|
|
1239
|
+
throw gatewayError("transport", "Anthropic response arrived with no body", {
|
|
1240
|
+
provider: "anthropic",
|
|
1241
|
+
status: response.status
|
|
1242
|
+
});
|
|
1243
|
+
}
|
|
1244
|
+
return response;
|
|
1245
|
+
}
|
|
1246
|
+
async function readErrorBody(response) {
|
|
1247
|
+
try {
|
|
1248
|
+
const text = await response.text();
|
|
1249
|
+
return text === "" ? "" : `: ${text.slice(0, 500)}`;
|
|
1250
|
+
} catch {
|
|
1251
|
+
return "";
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
function asGatewayError(cause) {
|
|
1255
|
+
if (cause instanceof Error && cause.name === "GatewayError") {
|
|
1256
|
+
return cause;
|
|
1257
|
+
}
|
|
1258
|
+
return gatewayError("transport", "Anthropic stream failed", { provider: "anthropic", cause });
|
|
1259
|
+
}
|
|
1260
|
+
function createanthropicConnector(deps2) {
|
|
1261
|
+
const api = "anthropic-messages";
|
|
1262
|
+
async function requireKey(options) {
|
|
1263
|
+
const key = await deps2.resolveSecret("anthropic", options.apiKey);
|
|
1264
|
+
if (key === void 0 || key === "") {
|
|
1265
|
+
throw gatewayError("auth", "no Anthropic API key found (set ANTHROPIC_API_KEY or pass options.apiKey)", {
|
|
1266
|
+
provider: "anthropic"
|
|
1267
|
+
});
|
|
1268
|
+
}
|
|
1269
|
+
return key;
|
|
1270
|
+
}
|
|
1271
|
+
function stream2(model, conversation, options) {
|
|
1272
|
+
return channelOf(async function* run() {
|
|
1273
|
+
const collected = [];
|
|
1274
|
+
try {
|
|
1275
|
+
const apiKey = await requireKey(options);
|
|
1276
|
+
const body = toAnthropicRequest(conversation, model, options);
|
|
1277
|
+
body.stream = true;
|
|
1278
|
+
const response = await postMessages(endpointFor(model), apiKey, body, options.signal);
|
|
1279
|
+
const wire = response.body;
|
|
1280
|
+
const state = { toolIds: /* @__PURE__ */ new Map(), usage: { inputTokens: 0, outputTokens: 0 } };
|
|
1281
|
+
for await (const event of sseEvents(wire, options.signal)) {
|
|
1282
|
+
const payload = parseEventData(event, "anthropic");
|
|
1283
|
+
if (payload === void 0) {
|
|
1284
|
+
continue;
|
|
1285
|
+
}
|
|
1286
|
+
const type = event.event !== "message" ? event.event : readString(payload, "type") ?? event.event;
|
|
1287
|
+
for (const emission of emitFromEvent(type, payload, state)) {
|
|
1288
|
+
collected.push(emission);
|
|
1289
|
+
yield emission;
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
const reply = foldReply(model.id, collected);
|
|
1293
|
+
yield { kind: "done", reply };
|
|
1294
|
+
} catch (cause) {
|
|
1295
|
+
yield { kind: "error", error: asGatewayError(cause) };
|
|
1296
|
+
}
|
|
1297
|
+
});
|
|
1298
|
+
}
|
|
1299
|
+
function complete2(model, conversation, options) {
|
|
1300
|
+
return collectReply(stream2(model, conversation, options));
|
|
1301
|
+
}
|
|
1302
|
+
return {
|
|
1303
|
+
id: "anthropic",
|
|
1304
|
+
api,
|
|
1305
|
+
stream: stream2,
|
|
1306
|
+
complete: complete2
|
|
1307
|
+
};
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
// src/llmgateway/conversion/openai-compatible.ts
|
|
1311
|
+
function isObject2(v) {
|
|
1312
|
+
return typeof v === "object" && v !== null;
|
|
1313
|
+
}
|
|
1314
|
+
function str(o, key) {
|
|
1315
|
+
const v = o[key];
|
|
1316
|
+
return typeof v === "string" ? v : void 0;
|
|
1317
|
+
}
|
|
1318
|
+
function num(o, key) {
|
|
1319
|
+
const v = o[key];
|
|
1320
|
+
return typeof v === "number" && Number.isFinite(v) ? v : void 0;
|
|
1321
|
+
}
|
|
1322
|
+
function mapFinishReason(reason) {
|
|
1323
|
+
switch (reason) {
|
|
1324
|
+
case "stop":
|
|
1325
|
+
return "complete";
|
|
1326
|
+
case "length":
|
|
1327
|
+
return "max_output";
|
|
1328
|
+
case "tool_calls":
|
|
1329
|
+
case "function_call":
|
|
1330
|
+
return "tool_calls";
|
|
1331
|
+
case "content_filter":
|
|
1332
|
+
return "refusal";
|
|
1333
|
+
case null:
|
|
1334
|
+
case void 0:
|
|
1335
|
+
case "":
|
|
1336
|
+
return void 0;
|
|
1337
|
+
default:
|
|
1338
|
+
return "complete";
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
function readUsage(chunk) {
|
|
1342
|
+
const usage = chunk.usage;
|
|
1343
|
+
if (!isObject2(usage)) {
|
|
1344
|
+
return void 0;
|
|
1345
|
+
}
|
|
1346
|
+
const inputTokens = num(usage, "prompt_tokens") ?? 0;
|
|
1347
|
+
const outputTokens = num(usage, "completion_tokens") ?? 0;
|
|
1348
|
+
const result = { inputTokens, outputTokens };
|
|
1349
|
+
const details = usage.prompt_tokens_details;
|
|
1350
|
+
if (isObject2(details)) {
|
|
1351
|
+
const cached = num(details, "cached_tokens");
|
|
1352
|
+
if (cached !== void 0) {
|
|
1353
|
+
result.cacheReadTokens = cached;
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
return result;
|
|
1357
|
+
}
|
|
1358
|
+
function buildBody(model, c, opts, cfg, stream2) {
|
|
1359
|
+
const body = {
|
|
1360
|
+
model: model.id,
|
|
1361
|
+
messages: toOpenAIChatMessages(c),
|
|
1362
|
+
stream: stream2
|
|
1363
|
+
};
|
|
1364
|
+
if (stream2) {
|
|
1365
|
+
body.stream_options = { include_usage: true };
|
|
1366
|
+
}
|
|
1367
|
+
const tools = toOpenAITools(c.tools);
|
|
1368
|
+
if (tools !== void 0) {
|
|
1369
|
+
body.tools = tools;
|
|
1370
|
+
const choice = toOpenAIToolChoice(opts.toolChoice);
|
|
1371
|
+
if (choice !== void 0) {
|
|
1372
|
+
body.tool_choice = choice;
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
const maxTokens = opts.maxOutputTokens ?? model.maxOutputTokens;
|
|
1376
|
+
if (maxTokens > 0) {
|
|
1377
|
+
body.max_tokens = maxTokens;
|
|
1378
|
+
}
|
|
1379
|
+
if (opts.temperature !== void 0) {
|
|
1380
|
+
body.temperature = opts.temperature;
|
|
1381
|
+
}
|
|
1382
|
+
if (opts.topP !== void 0) {
|
|
1383
|
+
body.top_p = opts.topP;
|
|
1384
|
+
}
|
|
1385
|
+
if (cfg.bodyExtra !== void 0) {
|
|
1386
|
+
for (const [k, v] of Object.entries(cfg.bodyExtra)) {
|
|
1387
|
+
body[k] = v;
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
return body;
|
|
1391
|
+
}
|
|
1392
|
+
async function postChat(cfg, body, provider, signal) {
|
|
1393
|
+
const headers = { "content-type": "application/json", ...cfg.headers };
|
|
1394
|
+
let response;
|
|
1395
|
+
try {
|
|
1396
|
+
response = await fetch(cfg.url, {
|
|
1397
|
+
method: "POST",
|
|
1398
|
+
headers,
|
|
1399
|
+
body: JSON.stringify(body),
|
|
1400
|
+
...signal !== void 0 ? { signal } : {}
|
|
1401
|
+
});
|
|
1402
|
+
} catch (cause) {
|
|
1403
|
+
if (signal?.aborted) {
|
|
1404
|
+
throw gatewayError("aborted", "request aborted before a response arrived", { provider, cause });
|
|
1405
|
+
}
|
|
1406
|
+
throw gatewayError("transport", "network request to the provider failed", { provider, cause });
|
|
1407
|
+
}
|
|
1408
|
+
if (!response.ok) {
|
|
1409
|
+
const detail = await readErrorBody2(response);
|
|
1410
|
+
const kind = response.status === 401 || response.status === 403 ? "auth" : response.status === 429 ? "rate_limit" : "http";
|
|
1411
|
+
throw gatewayError(kind, `provider returned HTTP ${response.status}${detail}`, {
|
|
1412
|
+
provider,
|
|
1413
|
+
status: response.status
|
|
1414
|
+
});
|
|
1415
|
+
}
|
|
1416
|
+
if (response.body === null) {
|
|
1417
|
+
throw gatewayError("transport", "provider response had no body", { provider, status: response.status });
|
|
1418
|
+
}
|
|
1419
|
+
return response;
|
|
1420
|
+
}
|
|
1421
|
+
async function readErrorBody2(response) {
|
|
1422
|
+
try {
|
|
1423
|
+
const text = await response.text();
|
|
1424
|
+
return text === "" ? "" : `: ${text.slice(0, 500)}`;
|
|
1425
|
+
} catch {
|
|
1426
|
+
return "";
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
function* emitFromChunk(chunk, tracker) {
|
|
1430
|
+
const usage = readUsage(chunk);
|
|
1431
|
+
if (usage !== void 0) {
|
|
1432
|
+
yield { kind: "usage", usage };
|
|
1433
|
+
}
|
|
1434
|
+
const choices = chunk.choices;
|
|
1435
|
+
if (!Array.isArray(choices) || choices.length === 0) {
|
|
1436
|
+
return;
|
|
1437
|
+
}
|
|
1438
|
+
const choice = choices[0];
|
|
1439
|
+
if (!isObject2(choice)) {
|
|
1440
|
+
return;
|
|
1441
|
+
}
|
|
1442
|
+
const delta = choice.delta;
|
|
1443
|
+
if (isObject2(delta)) {
|
|
1444
|
+
const content = str(delta, "content");
|
|
1445
|
+
if (content !== void 0 && content !== "") {
|
|
1446
|
+
yield { kind: "text", delta: content };
|
|
1447
|
+
}
|
|
1448
|
+
const reasoning = str(delta, "reasoning_content") ?? str(delta, "reasoning");
|
|
1449
|
+
if (reasoning !== void 0 && reasoning !== "") {
|
|
1450
|
+
yield { kind: "thinking", delta: reasoning };
|
|
1451
|
+
}
|
|
1452
|
+
const toolCalls = delta.tool_calls;
|
|
1453
|
+
if (Array.isArray(toolCalls)) {
|
|
1454
|
+
for (const tc of toolCalls) {
|
|
1455
|
+
yield* emitToolCall(tc, tracker);
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
const finish = mapFinishReason(str(choice, "finish_reason"));
|
|
1460
|
+
if (finish !== void 0) {
|
|
1461
|
+
yield { kind: "stop", stop: finish };
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
function* emitToolCall(tc, tracker) {
|
|
1465
|
+
if (!isObject2(tc)) {
|
|
1466
|
+
return;
|
|
1467
|
+
}
|
|
1468
|
+
const index = num(tc, "index") ?? 0;
|
|
1469
|
+
const explicitId = str(tc, "id");
|
|
1470
|
+
const fn = tc.function;
|
|
1471
|
+
const name = isObject2(fn) ? str(fn, "name") : void 0;
|
|
1472
|
+
const args = isObject2(fn) ? str(fn, "arguments") : void 0;
|
|
1473
|
+
let id = tracker.ids.get(index);
|
|
1474
|
+
if (id === void 0) {
|
|
1475
|
+
id = explicitId ?? `call_${index}`;
|
|
1476
|
+
tracker.ids.set(index, id);
|
|
1477
|
+
yield { kind: "tool_call_start", id, name: name ?? "" };
|
|
1478
|
+
} else if (explicitId !== void 0 && explicitId !== id) {
|
|
1479
|
+
}
|
|
1480
|
+
if (args !== void 0 && args !== "") {
|
|
1481
|
+
yield { kind: "tool_call_delta", id, argsDelta: args };
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
function streamOpenAICompatibleChat(cfg, model, c, opts) {
|
|
1485
|
+
return channelOf(async function* run() {
|
|
1486
|
+
const provider = model.provider;
|
|
1487
|
+
const collected = [];
|
|
1488
|
+
try {
|
|
1489
|
+
const body = buildBody(model, c, opts, cfg, true);
|
|
1490
|
+
const response = await postChat(cfg, body, provider, opts.signal);
|
|
1491
|
+
const stream2 = response.body;
|
|
1492
|
+
const tracker = { ids: /* @__PURE__ */ new Map() };
|
|
1493
|
+
for await (const sse of sseEvents(stream2, opts.signal)) {
|
|
1494
|
+
const payload = sse.data;
|
|
1495
|
+
if (payload === "[DONE]") {
|
|
1496
|
+
break;
|
|
1497
|
+
}
|
|
1498
|
+
let chunk;
|
|
1499
|
+
try {
|
|
1500
|
+
chunk = JSON.parse(payload);
|
|
1501
|
+
} catch (cause) {
|
|
1502
|
+
throw gatewayError("parse", "failed to parse an OpenAI stream chunk", { provider, cause });
|
|
1503
|
+
}
|
|
1504
|
+
if (!isObject2(chunk)) {
|
|
1505
|
+
continue;
|
|
1506
|
+
}
|
|
1507
|
+
for (const emission of emitFromChunk(chunk, tracker)) {
|
|
1508
|
+
collected.push(emission);
|
|
1509
|
+
yield emission;
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
const reply = foldReply(model.id, collected);
|
|
1513
|
+
yield { kind: "done", reply };
|
|
1514
|
+
} catch (cause) {
|
|
1515
|
+
const error = cause instanceof Error && cause.name === "GatewayError" ? cause : gatewayError("transport", "OpenAI-compatible stream failed", { provider, cause });
|
|
1516
|
+
yield { kind: "error", error };
|
|
1517
|
+
}
|
|
1518
|
+
});
|
|
1519
|
+
}
|
|
1520
|
+
|
|
1521
|
+
// src/llmgateway/connectors/openai-chat.ts
|
|
1522
|
+
var DEFAULT_OPENAI_BASE_URL = "https://api.openai.com/v1";
|
|
1523
|
+
function endpointFor2(model) {
|
|
1524
|
+
const base = (model.baseUrl ?? DEFAULT_OPENAI_BASE_URL).replace(/\/+$/, "");
|
|
1525
|
+
return `${base}/chat/completions`;
|
|
1526
|
+
}
|
|
1527
|
+
var OpenAIChatConnector = class {
|
|
1528
|
+
constructor(deps2) {
|
|
1529
|
+
this.deps = deps2;
|
|
1530
|
+
}
|
|
1531
|
+
deps;
|
|
1532
|
+
id = "openai-chat";
|
|
1533
|
+
api = "openai-completions";
|
|
1534
|
+
stream(model, conversation, options) {
|
|
1535
|
+
const deps2 = this.deps;
|
|
1536
|
+
return channelOf(async function* run() {
|
|
1537
|
+
let cfg;
|
|
1538
|
+
try {
|
|
1539
|
+
cfg = await resolveConfig(deps2, model, options);
|
|
1540
|
+
} catch (cause) {
|
|
1541
|
+
const error = cause instanceof Error && cause.name === "GatewayError" ? cause : gatewayError("auth", "could not prepare the OpenAI request", {
|
|
1542
|
+
provider: model.provider,
|
|
1543
|
+
cause
|
|
1544
|
+
});
|
|
1545
|
+
yield { kind: "error", error };
|
|
1546
|
+
return;
|
|
1547
|
+
}
|
|
1548
|
+
yield* streamOpenAICompatibleChat(cfg, model, conversation, options);
|
|
1549
|
+
});
|
|
1550
|
+
}
|
|
1551
|
+
async complete(model, conversation, options) {
|
|
1552
|
+
return collectReply(this.stream(model, conversation, options));
|
|
1553
|
+
}
|
|
1554
|
+
};
|
|
1555
|
+
async function resolveConfig(deps2, model, options) {
|
|
1556
|
+
const key = await deps2.resolveSecret(model.provider, options.apiKey);
|
|
1557
|
+
if (key === void 0 || key === "") {
|
|
1558
|
+
throw gatewayError(
|
|
1559
|
+
"auth",
|
|
1560
|
+
"no OpenAI credential found \u2014 set OPENAI_API_KEY or pass options.apiKey",
|
|
1561
|
+
{ provider: model.provider }
|
|
1562
|
+
);
|
|
1563
|
+
}
|
|
1564
|
+
return {
|
|
1565
|
+
url: endpointFor2(model),
|
|
1566
|
+
headers: { authorization: `Bearer ${key}` }
|
|
1567
|
+
};
|
|
1568
|
+
}
|
|
1569
|
+
function createopenaichatConnector(deps2) {
|
|
1570
|
+
return new OpenAIChatConnector(deps2);
|
|
1571
|
+
}
|
|
1572
|
+
|
|
1573
|
+
// src/llmgateway/connectors/openai-responses.ts
|
|
1574
|
+
var DEFAULT_ORIGIN = "https://api.openai.com/v1";
|
|
1575
|
+
function isObject3(v) {
|
|
1576
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1577
|
+
}
|
|
1578
|
+
function readString2(o, key) {
|
|
1579
|
+
const v = o[key];
|
|
1580
|
+
return typeof v === "string" ? v : void 0;
|
|
1581
|
+
}
|
|
1582
|
+
function readNumber2(o, key) {
|
|
1583
|
+
const v = o[key];
|
|
1584
|
+
return typeof v === "number" && Number.isFinite(v) ? v : void 0;
|
|
1585
|
+
}
|
|
1586
|
+
function reasoningEffort(level) {
|
|
1587
|
+
switch (level) {
|
|
1588
|
+
case "low":
|
|
1589
|
+
return "low";
|
|
1590
|
+
case "medium":
|
|
1591
|
+
return "medium";
|
|
1592
|
+
case "high":
|
|
1593
|
+
case "max":
|
|
1594
|
+
return "high";
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
function mapStatus(status, incompleteReason) {
|
|
1598
|
+
switch (status) {
|
|
1599
|
+
case "completed":
|
|
1600
|
+
return "complete";
|
|
1601
|
+
case "incomplete":
|
|
1602
|
+
return incompleteReason === "max_output_tokens" ? "max_output" : "complete";
|
|
1603
|
+
case "failed":
|
|
1604
|
+
case "cancelled":
|
|
1605
|
+
return "error";
|
|
1606
|
+
default:
|
|
1607
|
+
return "complete";
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1610
|
+
function joinUrl(origin, path) {
|
|
1611
|
+
return origin.endsWith("/") ? origin.slice(0, -1) + path : origin + path;
|
|
1612
|
+
}
|
|
1613
|
+
function buildBody2(model, c, opts) {
|
|
1614
|
+
const body = {
|
|
1615
|
+
model: model.id,
|
|
1616
|
+
input: toResponsesInput(c),
|
|
1617
|
+
stream: true
|
|
1618
|
+
};
|
|
1619
|
+
if (c.system !== void 0 && c.system !== "") {
|
|
1620
|
+
body.instructions = c.system;
|
|
1621
|
+
}
|
|
1622
|
+
const tools = toResponsesTools(c.tools);
|
|
1623
|
+
if (tools !== void 0) {
|
|
1624
|
+
body.tools = tools;
|
|
1625
|
+
if (opts.toolChoice !== void 0) {
|
|
1626
|
+
body.tool_choice = opts.toolChoice;
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
const ceiling = opts.maxOutputTokens ?? model.maxOutputTokens;
|
|
1630
|
+
if (ceiling > 0) {
|
|
1631
|
+
body.max_output_tokens = ceiling;
|
|
1632
|
+
}
|
|
1633
|
+
if (opts.temperature !== void 0) {
|
|
1634
|
+
body.temperature = opts.temperature;
|
|
1635
|
+
}
|
|
1636
|
+
if (opts.topP !== void 0) {
|
|
1637
|
+
body.top_p = opts.topP;
|
|
1638
|
+
}
|
|
1639
|
+
if (model.reasoning && opts.thinking !== void 0 && opts.thinking !== "off") {
|
|
1640
|
+
body.reasoning = { effort: reasoningEffort(opts.thinking) };
|
|
1641
|
+
}
|
|
1642
|
+
return body;
|
|
1643
|
+
}
|
|
1644
|
+
async function postResponses(url, apiKey, body, provider, signal) {
|
|
1645
|
+
let response;
|
|
1646
|
+
try {
|
|
1647
|
+
response = await fetch(url, {
|
|
1648
|
+
method: "POST",
|
|
1649
|
+
headers: {
|
|
1650
|
+
"content-type": "application/json",
|
|
1651
|
+
authorization: `Bearer ${apiKey}`
|
|
1652
|
+
},
|
|
1653
|
+
body: JSON.stringify(body),
|
|
1654
|
+
...signal !== void 0 ? { signal } : {}
|
|
1655
|
+
});
|
|
1656
|
+
} catch (cause) {
|
|
1657
|
+
if (signal?.aborted) {
|
|
1658
|
+
throw gatewayError("aborted", "the Responses request was cancelled before a reply arrived", {
|
|
1659
|
+
provider,
|
|
1660
|
+
cause
|
|
1661
|
+
});
|
|
1662
|
+
}
|
|
1663
|
+
throw gatewayError("transport", "could not reach the OpenAI Responses endpoint", { provider, cause });
|
|
1664
|
+
}
|
|
1665
|
+
if (!response.ok) {
|
|
1666
|
+
const detail = await describeFailure(response);
|
|
1667
|
+
const kind = response.status === 401 || response.status === 403 ? "auth" : response.status === 429 ? "rate_limit" : "http";
|
|
1668
|
+
throw gatewayError(kind, `OpenAI Responses replied with HTTP ${response.status}${detail}`, {
|
|
1669
|
+
provider,
|
|
1670
|
+
status: response.status
|
|
1671
|
+
});
|
|
1672
|
+
}
|
|
1673
|
+
if (response.body === null) {
|
|
1674
|
+
throw gatewayError("transport", "OpenAI Responses returned an empty body", {
|
|
1675
|
+
provider,
|
|
1676
|
+
status: response.status
|
|
1677
|
+
});
|
|
1678
|
+
}
|
|
1679
|
+
return response;
|
|
1680
|
+
}
|
|
1681
|
+
async function describeFailure(response) {
|
|
1682
|
+
try {
|
|
1683
|
+
const text = await response.text();
|
|
1684
|
+
return text === "" ? "" : ` \u2014 ${text.slice(0, 500)}`;
|
|
1685
|
+
} catch {
|
|
1686
|
+
return "";
|
|
1687
|
+
}
|
|
1688
|
+
}
|
|
1689
|
+
function extractUsage(response) {
|
|
1690
|
+
const usage = response.usage;
|
|
1691
|
+
if (!isObject3(usage)) {
|
|
1692
|
+
return void 0;
|
|
1693
|
+
}
|
|
1694
|
+
const inputTokens = readNumber2(usage, "input_tokens") ?? 0;
|
|
1695
|
+
const outputTokens = readNumber2(usage, "output_tokens") ?? 0;
|
|
1696
|
+
const result = { inputTokens, outputTokens };
|
|
1697
|
+
const inputDetails = usage.input_tokens_details;
|
|
1698
|
+
if (isObject3(inputDetails)) {
|
|
1699
|
+
const cached = readNumber2(inputDetails, "cached_tokens");
|
|
1700
|
+
if (cached !== void 0) {
|
|
1701
|
+
result.cacheReadTokens = cached;
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
return result;
|
|
1705
|
+
}
|
|
1706
|
+
function* translateEvent(payload, calls) {
|
|
1707
|
+
const type = readString2(payload, "type");
|
|
1708
|
+
switch (type) {
|
|
1709
|
+
case "response.output_text.delta": {
|
|
1710
|
+
const delta = readString2(payload, "delta");
|
|
1711
|
+
if (delta !== void 0 && delta !== "") {
|
|
1712
|
+
yield { kind: "text", delta };
|
|
1713
|
+
}
|
|
1714
|
+
return;
|
|
1715
|
+
}
|
|
1716
|
+
case "response.reasoning_summary_text.delta":
|
|
1717
|
+
case "response.reasoning_text.delta": {
|
|
1718
|
+
const delta = readString2(payload, "delta");
|
|
1719
|
+
if (delta !== void 0 && delta !== "") {
|
|
1720
|
+
yield { kind: "thinking", delta };
|
|
1721
|
+
}
|
|
1722
|
+
return;
|
|
1723
|
+
}
|
|
1724
|
+
case "response.output_item.added": {
|
|
1725
|
+
yield* announceItem(payload, calls);
|
|
1726
|
+
return;
|
|
1727
|
+
}
|
|
1728
|
+
case "response.function_call_arguments.delta": {
|
|
1729
|
+
const itemId = readString2(payload, "item_id");
|
|
1730
|
+
const delta = readString2(payload, "delta");
|
|
1731
|
+
if (itemId === void 0 || delta === void 0 || delta === "") {
|
|
1732
|
+
return;
|
|
1733
|
+
}
|
|
1734
|
+
const id = calls.byItem.get(itemId) ?? itemId;
|
|
1735
|
+
yield { kind: "tool_call_delta", id, argsDelta: delta };
|
|
1736
|
+
return;
|
|
1737
|
+
}
|
|
1738
|
+
case "response.completed":
|
|
1739
|
+
case "response.incomplete":
|
|
1740
|
+
case "response.failed": {
|
|
1741
|
+
yield* finishResponse(payload);
|
|
1742
|
+
return;
|
|
1743
|
+
}
|
|
1744
|
+
default:
|
|
1745
|
+
return;
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
function* announceItem(payload, calls) {
|
|
1749
|
+
const item = payload.item;
|
|
1750
|
+
if (!isObject3(item)) {
|
|
1751
|
+
return;
|
|
1752
|
+
}
|
|
1753
|
+
if (readString2(item, "type") !== "function_call") {
|
|
1754
|
+
return;
|
|
1755
|
+
}
|
|
1756
|
+
const name = readString2(item, "name") ?? "";
|
|
1757
|
+
const callId = readString2(item, "call_id") ?? readString2(item, "id") ?? `call_${calls.byItem.size}`;
|
|
1758
|
+
const itemId = readString2(item, "id");
|
|
1759
|
+
if (itemId !== void 0) {
|
|
1760
|
+
calls.byItem.set(itemId, callId);
|
|
1761
|
+
}
|
|
1762
|
+
yield { kind: "tool_call_start", id: callId, name };
|
|
1763
|
+
}
|
|
1764
|
+
function* finishResponse(payload) {
|
|
1765
|
+
const response = isObject3(payload.response) ? payload.response : payload;
|
|
1766
|
+
const usage = extractUsage(response);
|
|
1767
|
+
if (usage !== void 0) {
|
|
1768
|
+
yield { kind: "usage", usage };
|
|
1769
|
+
}
|
|
1770
|
+
const status = readString2(response, "status");
|
|
1771
|
+
const incomplete = isObject3(response.incomplete_details) ? readString2(response.incomplete_details, "reason") : void 0;
|
|
1772
|
+
yield { kind: "stop", stop: mapStatus(status, incomplete) };
|
|
1773
|
+
}
|
|
1774
|
+
function createopenairesponsesConnector(deps2) {
|
|
1775
|
+
const { resolveSecret: resolveSecret2 } = deps2;
|
|
1776
|
+
const stream2 = (model, conversation, options) => {
|
|
1777
|
+
return channelOf(async function* run() {
|
|
1778
|
+
const provider = model.provider;
|
|
1779
|
+
const collected = [];
|
|
1780
|
+
try {
|
|
1781
|
+
const apiKey = await resolveSecret2(provider, options.apiKey);
|
|
1782
|
+
if (apiKey === void 0 || apiKey === "") {
|
|
1783
|
+
throw gatewayError("auth", "no OpenAI API key was found for the Responses endpoint", { provider });
|
|
1784
|
+
}
|
|
1785
|
+
const origin = model.baseUrl ?? DEFAULT_ORIGIN;
|
|
1786
|
+
const url = joinUrl(origin, "/responses");
|
|
1787
|
+
const body = buildBody2(model, conversation, options);
|
|
1788
|
+
const response = await postResponses(url, apiKey, body, provider, options.signal);
|
|
1789
|
+
const wire = response.body;
|
|
1790
|
+
const calls = { byItem: /* @__PURE__ */ new Map() };
|
|
1791
|
+
for await (const sse of sseEvents(wire, options.signal)) {
|
|
1792
|
+
const raw = sse.data;
|
|
1793
|
+
if (raw === "" || raw === "[DONE]") {
|
|
1794
|
+
continue;
|
|
1795
|
+
}
|
|
1796
|
+
let payload;
|
|
1797
|
+
try {
|
|
1798
|
+
payload = JSON.parse(raw);
|
|
1799
|
+
} catch (cause) {
|
|
1800
|
+
throw gatewayError("parse", "could not parse an OpenAI Responses stream event", {
|
|
1801
|
+
provider,
|
|
1802
|
+
cause
|
|
1803
|
+
});
|
|
1804
|
+
}
|
|
1805
|
+
if (!isObject3(payload)) {
|
|
1806
|
+
continue;
|
|
1807
|
+
}
|
|
1808
|
+
for (const emission of translateEvent(payload, calls)) {
|
|
1809
|
+
collected.push(emission);
|
|
1810
|
+
yield emission;
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
yield { kind: "done", reply: foldReply(model.id, collected) };
|
|
1814
|
+
} catch (cause) {
|
|
1815
|
+
const error = cause instanceof Error && cause.name === "GatewayError" ? cause : gatewayError("transport", "the OpenAI Responses stream failed", { provider, cause });
|
|
1816
|
+
yield { kind: "error", error };
|
|
1817
|
+
}
|
|
1818
|
+
});
|
|
1819
|
+
};
|
|
1820
|
+
const complete2 = (model, conversation, options) => {
|
|
1821
|
+
return collectReply(stream2(model, conversation, options));
|
|
1822
|
+
};
|
|
1823
|
+
return {
|
|
1824
|
+
id: "openai-responses",
|
|
1825
|
+
api: "openai-responses",
|
|
1826
|
+
stream: stream2,
|
|
1827
|
+
complete: complete2
|
|
1828
|
+
};
|
|
1829
|
+
}
|
|
1830
|
+
|
|
1831
|
+
// src/llmgateway/streaming/ndjson.ts
|
|
1832
|
+
async function* ndjsonLines(body, signal) {
|
|
1833
|
+
if (signal?.aborted) {
|
|
1834
|
+
throw gatewayError("aborted", "request aborted before reading the ndjson stream");
|
|
1835
|
+
}
|
|
1836
|
+
const reader = body.getReader();
|
|
1837
|
+
const decoder = new TextDecoder("utf-8");
|
|
1838
|
+
let pending = "";
|
|
1839
|
+
const onAbort = () => {
|
|
1840
|
+
void reader.cancel().catch(() => {
|
|
1841
|
+
});
|
|
1842
|
+
};
|
|
1843
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
1844
|
+
const parseLine = (raw) => {
|
|
1845
|
+
const line = raw.endsWith("\r") ? raw.slice(0, -1) : raw;
|
|
1846
|
+
const trimmed = line.trim();
|
|
1847
|
+
if (trimmed === "") {
|
|
1848
|
+
return void 0;
|
|
1849
|
+
}
|
|
1850
|
+
try {
|
|
1851
|
+
return JSON.parse(trimmed);
|
|
1852
|
+
} catch (cause) {
|
|
1853
|
+
throw gatewayError("parse", "failed to parse an ndjson line as JSON", { cause });
|
|
1854
|
+
}
|
|
1855
|
+
};
|
|
1856
|
+
try {
|
|
1857
|
+
for (; ; ) {
|
|
1858
|
+
if (signal?.aborted) {
|
|
1859
|
+
throw gatewayError("aborted", "request aborted while reading the ndjson stream");
|
|
1860
|
+
}
|
|
1861
|
+
const { value, done } = await reader.read();
|
|
1862
|
+
if (done) {
|
|
1863
|
+
break;
|
|
1864
|
+
}
|
|
1865
|
+
pending += decoder.decode(value, { stream: true });
|
|
1866
|
+
let nl = pending.indexOf("\n");
|
|
1867
|
+
while (nl !== -1) {
|
|
1868
|
+
const raw = pending.slice(0, nl);
|
|
1869
|
+
pending = pending.slice(nl + 1);
|
|
1870
|
+
const parsed = parseLine(raw);
|
|
1871
|
+
if (parsed !== void 0) {
|
|
1872
|
+
yield parsed;
|
|
1873
|
+
}
|
|
1874
|
+
nl = pending.indexOf("\n");
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
pending += decoder.decode();
|
|
1878
|
+
const tail = parseLine(pending);
|
|
1879
|
+
if (tail !== void 0) {
|
|
1880
|
+
yield tail;
|
|
1881
|
+
}
|
|
1882
|
+
} catch (cause) {
|
|
1883
|
+
if (signal?.aborted) {
|
|
1884
|
+
throw gatewayError("aborted", "request aborted while reading the ndjson stream", { cause });
|
|
1885
|
+
}
|
|
1886
|
+
if (cause instanceof Error && cause.name === "GatewayError") {
|
|
1887
|
+
throw cause;
|
|
1888
|
+
}
|
|
1889
|
+
throw gatewayError("transport", "failed reading the ndjson stream", { cause });
|
|
1890
|
+
} finally {
|
|
1891
|
+
signal?.removeEventListener("abort", onAbort);
|
|
1892
|
+
reader.releaseLock();
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
|
|
1896
|
+
// src/llmgateway/connectors/google.ts
|
|
1897
|
+
var DEFAULT_BASE_URL2 = "https://generativelanguage.googleapis.com";
|
|
1898
|
+
var PROVIDER = "google";
|
|
1899
|
+
function isObject4(value) {
|
|
1900
|
+
return typeof value === "object" && value !== null;
|
|
1901
|
+
}
|
|
1902
|
+
function readString3(o, key) {
|
|
1903
|
+
const v = o[key];
|
|
1904
|
+
return typeof v === "string" ? v : void 0;
|
|
1905
|
+
}
|
|
1906
|
+
function readNumber3(o, key) {
|
|
1907
|
+
const v = o[key];
|
|
1908
|
+
return typeof v === "number" && Number.isFinite(v) ? v : void 0;
|
|
1909
|
+
}
|
|
1910
|
+
function geminiThinkingBudget(level, maxOutput) {
|
|
1911
|
+
const fraction = {
|
|
1912
|
+
low: 0.2,
|
|
1913
|
+
medium: 0.4,
|
|
1914
|
+
high: 0.6,
|
|
1915
|
+
max: 0.8
|
|
1916
|
+
};
|
|
1917
|
+
const budget = Math.floor(maxOutput * fraction[level]);
|
|
1918
|
+
return Math.max(1024, budget);
|
|
1919
|
+
}
|
|
1920
|
+
function buildGenerationConfig(model, opts) {
|
|
1921
|
+
const maxOutputTokens = opts.maxOutputTokens ?? model.maxOutputTokens;
|
|
1922
|
+
const config = { maxOutputTokens };
|
|
1923
|
+
if (opts.temperature !== void 0) {
|
|
1924
|
+
config.temperature = opts.temperature;
|
|
1925
|
+
}
|
|
1926
|
+
if (opts.topP !== void 0) {
|
|
1927
|
+
config.topP = opts.topP;
|
|
1928
|
+
}
|
|
1929
|
+
if (model.reasoning && opts.thinking !== void 0 && opts.thinking !== "off") {
|
|
1930
|
+
config.thinkingConfig = {
|
|
1931
|
+
includeThoughts: true,
|
|
1932
|
+
thinkingBudget: geminiThinkingBudget(opts.thinking, maxOutputTokens)
|
|
1933
|
+
};
|
|
1934
|
+
}
|
|
1935
|
+
return config;
|
|
1936
|
+
}
|
|
1937
|
+
function buildRequestBody(model, conversation, opts) {
|
|
1938
|
+
const body = {
|
|
1939
|
+
contents: toGoogleContents(conversation),
|
|
1940
|
+
generationConfig: buildGenerationConfig(model, opts)
|
|
1941
|
+
};
|
|
1942
|
+
const systemInstruction = toGoogleSystemInstruction(conversation);
|
|
1943
|
+
if (systemInstruction !== void 0) {
|
|
1944
|
+
body.systemInstruction = systemInstruction;
|
|
1945
|
+
}
|
|
1946
|
+
const tools = toGoogleTools(conversation.tools);
|
|
1947
|
+
if (tools !== void 0) {
|
|
1948
|
+
body.tools = tools;
|
|
1949
|
+
}
|
|
1950
|
+
return body;
|
|
1951
|
+
}
|
|
1952
|
+
function streamEndpoint(model) {
|
|
1953
|
+
const base = (model.baseUrl ?? DEFAULT_BASE_URL2).replace(/\/+$/u, "");
|
|
1954
|
+
return `${base}/v1beta/models/${model.id}:streamGenerateContent?alt=sse`;
|
|
1955
|
+
}
|
|
1956
|
+
async function openStream(url, apiKey, body, signal) {
|
|
1957
|
+
let response;
|
|
1958
|
+
try {
|
|
1959
|
+
response = await fetch(url, {
|
|
1960
|
+
method: "POST",
|
|
1961
|
+
headers: {
|
|
1962
|
+
"content-type": "application/json",
|
|
1963
|
+
"x-goog-api-key": apiKey
|
|
1964
|
+
},
|
|
1965
|
+
body: JSON.stringify(body),
|
|
1966
|
+
...signal !== void 0 ? { signal } : {}
|
|
1967
|
+
});
|
|
1968
|
+
} catch (cause) {
|
|
1969
|
+
if (signal?.aborted) {
|
|
1970
|
+
throw gatewayError("aborted", "the Gemini request was aborted before a response arrived", {
|
|
1971
|
+
provider: PROVIDER,
|
|
1972
|
+
cause
|
|
1973
|
+
});
|
|
1974
|
+
}
|
|
1975
|
+
throw gatewayError("transport", "could not reach the Gemini endpoint", {
|
|
1976
|
+
provider: PROVIDER,
|
|
1977
|
+
cause
|
|
1978
|
+
});
|
|
1979
|
+
}
|
|
1980
|
+
if (!response.ok) {
|
|
1981
|
+
const detail = await readErrorDetail(response);
|
|
1982
|
+
const kind = response.status === 401 || response.status === 403 ? "auth" : response.status === 429 ? "rate_limit" : "http";
|
|
1983
|
+
throw gatewayError(kind, `Gemini replied with HTTP ${response.status}${detail}`, {
|
|
1984
|
+
provider: PROVIDER,
|
|
1985
|
+
status: response.status
|
|
1986
|
+
});
|
|
1987
|
+
}
|
|
1988
|
+
if (response.body === null) {
|
|
1989
|
+
throw gatewayError("transport", "the Gemini response carried no body to stream", {
|
|
1990
|
+
provider: PROVIDER,
|
|
1991
|
+
status: response.status
|
|
1992
|
+
});
|
|
1993
|
+
}
|
|
1994
|
+
return response;
|
|
1995
|
+
}
|
|
1996
|
+
async function readErrorDetail(response) {
|
|
1997
|
+
try {
|
|
1998
|
+
const text = await response.text();
|
|
1999
|
+
return text === "" ? "" : `: ${text.slice(0, 500)}`;
|
|
2000
|
+
} catch {
|
|
2001
|
+
return "";
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
2004
|
+
function mapFinishReason2(reason) {
|
|
2005
|
+
switch (reason) {
|
|
2006
|
+
case "STOP":
|
|
2007
|
+
return "complete";
|
|
2008
|
+
case "MAX_TOKENS":
|
|
2009
|
+
return "max_output";
|
|
2010
|
+
case "SAFETY":
|
|
2011
|
+
case "RECITATION":
|
|
2012
|
+
case "BLOCKLIST":
|
|
2013
|
+
case "PROHIBITED_CONTENT":
|
|
2014
|
+
case "SPII":
|
|
2015
|
+
return "refusal";
|
|
2016
|
+
case void 0:
|
|
2017
|
+
case "":
|
|
2018
|
+
case "FINISH_REASON_UNSPECIFIED":
|
|
2019
|
+
case "OTHER":
|
|
2020
|
+
return void 0;
|
|
2021
|
+
default:
|
|
2022
|
+
return "complete";
|
|
2023
|
+
}
|
|
2024
|
+
}
|
|
2025
|
+
function readUsage2(frame) {
|
|
2026
|
+
const meta = frame.usageMetadata;
|
|
2027
|
+
if (!isObject4(meta)) {
|
|
2028
|
+
return void 0;
|
|
2029
|
+
}
|
|
2030
|
+
const inputTokens = readNumber3(meta, "promptTokenCount") ?? 0;
|
|
2031
|
+
const outputTokens = readNumber3(meta, "candidatesTokenCount") ?? 0;
|
|
2032
|
+
const usage = { inputTokens, outputTokens };
|
|
2033
|
+
const cachedRead = readNumber3(meta, "cachedContentTokenCount");
|
|
2034
|
+
if (cachedRead !== void 0) {
|
|
2035
|
+
usage.cacheReadTokens = cachedRead;
|
|
2036
|
+
}
|
|
2037
|
+
return usage;
|
|
2038
|
+
}
|
|
2039
|
+
function* emitFromParts(parts, tracker) {
|
|
2040
|
+
for (const part of parts) {
|
|
2041
|
+
if (!isObject4(part)) {
|
|
2042
|
+
continue;
|
|
2043
|
+
}
|
|
2044
|
+
const text = readString3(part, "text");
|
|
2045
|
+
if (text !== void 0 && text !== "") {
|
|
2046
|
+
if (part.thought === true) {
|
|
2047
|
+
yield { kind: "thinking", delta: text };
|
|
2048
|
+
} else {
|
|
2049
|
+
yield { kind: "text", delta: text };
|
|
2050
|
+
}
|
|
2051
|
+
continue;
|
|
2052
|
+
}
|
|
2053
|
+
const functionCall = part.functionCall;
|
|
2054
|
+
if (isObject4(functionCall)) {
|
|
2055
|
+
const name = readString3(functionCall, "name") ?? "";
|
|
2056
|
+
const id = `gemini_call_${tracker.next}`;
|
|
2057
|
+
tracker.next += 1;
|
|
2058
|
+
yield { kind: "tool_call_start", id, name };
|
|
2059
|
+
const args = "args" in functionCall ? functionCall.args : {};
|
|
2060
|
+
yield { kind: "tool_call_delta", id, argsDelta: serializeArgs(args) };
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2063
|
+
}
|
|
2064
|
+
function serializeArgs(args) {
|
|
2065
|
+
if (typeof args === "string") {
|
|
2066
|
+
return args;
|
|
2067
|
+
}
|
|
2068
|
+
try {
|
|
2069
|
+
return JSON.stringify(args ?? {});
|
|
2070
|
+
} catch {
|
|
2071
|
+
return "{}";
|
|
2072
|
+
}
|
|
2073
|
+
}
|
|
2074
|
+
function* emitFromFrame(frame, tracker) {
|
|
2075
|
+
const usage = readUsage2(frame);
|
|
2076
|
+
if (usage !== void 0) {
|
|
2077
|
+
yield { kind: "usage", usage };
|
|
2078
|
+
}
|
|
2079
|
+
const candidates = frame.candidates;
|
|
2080
|
+
if (!Array.isArray(candidates) || candidates.length === 0) {
|
|
2081
|
+
return;
|
|
2082
|
+
}
|
|
2083
|
+
const candidate = candidates[0];
|
|
2084
|
+
if (!isObject4(candidate)) {
|
|
2085
|
+
return;
|
|
2086
|
+
}
|
|
2087
|
+
const content = candidate.content;
|
|
2088
|
+
if (isObject4(content) && Array.isArray(content.parts)) {
|
|
2089
|
+
yield* emitFromParts(content.parts, tracker);
|
|
2090
|
+
}
|
|
2091
|
+
const stop = mapFinishReason2(readString3(candidate, "finishReason"));
|
|
2092
|
+
if (stop !== void 0) {
|
|
2093
|
+
yield { kind: "stop", stop };
|
|
2094
|
+
}
|
|
2095
|
+
}
|
|
2096
|
+
function creategoogleConnector(deps2) {
|
|
2097
|
+
const { resolveSecret: resolveSecret2 } = deps2;
|
|
2098
|
+
return {
|
|
2099
|
+
id: "google-generative",
|
|
2100
|
+
api: "google-generative",
|
|
2101
|
+
stream(model, conversation, options) {
|
|
2102
|
+
return channelOf(async function* run() {
|
|
2103
|
+
const collected = [];
|
|
2104
|
+
try {
|
|
2105
|
+
const apiKey = await resolveSecret2(PROVIDER, options.apiKey);
|
|
2106
|
+
if (apiKey === void 0 || apiKey === "") {
|
|
2107
|
+
throw gatewayError("auth", "no Gemini API key was found (set GEMINI_API_KEY or pass apiKey)", {
|
|
2108
|
+
provider: PROVIDER
|
|
2109
|
+
});
|
|
2110
|
+
}
|
|
2111
|
+
const url = streamEndpoint(model);
|
|
2112
|
+
const body = buildRequestBody(model, conversation, options);
|
|
2113
|
+
const response = await openStream(url, apiKey, body, options.signal);
|
|
2114
|
+
const wire = response.body;
|
|
2115
|
+
const tracker = { next: 0 };
|
|
2116
|
+
for await (const event of sseEvents(wire, options.signal)) {
|
|
2117
|
+
const payload = event.data;
|
|
2118
|
+
if (payload === "" || payload === "[DONE]") {
|
|
2119
|
+
continue;
|
|
2120
|
+
}
|
|
2121
|
+
let frame;
|
|
2122
|
+
try {
|
|
2123
|
+
frame = JSON.parse(payload);
|
|
2124
|
+
} catch (cause) {
|
|
2125
|
+
throw gatewayError("parse", "could not parse a Gemini stream frame", {
|
|
2126
|
+
provider: PROVIDER,
|
|
2127
|
+
cause
|
|
2128
|
+
});
|
|
2129
|
+
}
|
|
2130
|
+
if (!isObject4(frame)) {
|
|
2131
|
+
continue;
|
|
2132
|
+
}
|
|
2133
|
+
for (const emission of emitFromFrame(frame, tracker)) {
|
|
2134
|
+
collected.push(emission);
|
|
2135
|
+
yield emission;
|
|
2136
|
+
}
|
|
2137
|
+
}
|
|
2138
|
+
const reply = foldReply(model.id, collected);
|
|
2139
|
+
yield { kind: "done", reply };
|
|
2140
|
+
} catch (cause) {
|
|
2141
|
+
const error = cause instanceof Error && cause.name === "GatewayError" ? cause : gatewayError("transport", "the Gemini stream failed", { provider: PROVIDER, cause });
|
|
2142
|
+
yield { kind: "error", error };
|
|
2143
|
+
}
|
|
2144
|
+
});
|
|
2145
|
+
},
|
|
2146
|
+
complete(model, conversation, options) {
|
|
2147
|
+
return collectReply(this.stream(model, conversation, options));
|
|
2148
|
+
}
|
|
2149
|
+
};
|
|
2150
|
+
}
|
|
2151
|
+
|
|
2152
|
+
// src/llmgateway/connectors/google-vertex.ts
|
|
2153
|
+
var PROVIDER2 = "google-vertex";
|
|
2154
|
+
var API_KIND = "google-vertex";
|
|
2155
|
+
var DEFAULT_LOCATION = "us-central1";
|
|
2156
|
+
var defaultBaseUrl = (location) => `https://${location}-aiplatform.googleapis.com`;
|
|
2157
|
+
function envValue(name) {
|
|
2158
|
+
const raw = process.env[name];
|
|
2159
|
+
if (raw === void 0) {
|
|
2160
|
+
return void 0;
|
|
2161
|
+
}
|
|
2162
|
+
const trimmed = raw.trim();
|
|
2163
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
2164
|
+
}
|
|
2165
|
+
function firstEnv(names) {
|
|
2166
|
+
for (const name of names) {
|
|
2167
|
+
const value = envValue(name);
|
|
2168
|
+
if (value !== void 0) {
|
|
2169
|
+
return value;
|
|
2170
|
+
}
|
|
2171
|
+
}
|
|
2172
|
+
return void 0;
|
|
2173
|
+
}
|
|
2174
|
+
function resolveTarget(model) {
|
|
2175
|
+
const project = firstEnv(["GOOGLE_VERTEX_PROJECT", "GOOGLE_CLOUD_PROJECT"]);
|
|
2176
|
+
if (project === void 0) {
|
|
2177
|
+
throw gatewayError(
|
|
2178
|
+
"auth",
|
|
2179
|
+
"no Vertex project found; set GOOGLE_VERTEX_PROJECT or GOOGLE_CLOUD_PROJECT",
|
|
2180
|
+
{ provider: PROVIDER2 }
|
|
2181
|
+
);
|
|
2182
|
+
}
|
|
2183
|
+
const location = firstEnv(["GOOGLE_VERTEX_LOCATION", "CLOUD_ML_REGION"]) ?? DEFAULT_LOCATION;
|
|
2184
|
+
const host = (model.baseUrl ?? defaultBaseUrl(location)).replace(/\/+$/, "");
|
|
2185
|
+
const url = `${host}/v1/projects/${encodeURIComponent(project)}/locations/${encodeURIComponent(location)}/publishers/google/models/${encodeURIComponent(model.id)}:streamGenerateContent?alt=sse`;
|
|
2186
|
+
return { project, location, url };
|
|
2187
|
+
}
|
|
2188
|
+
function toFunctionCallingConfig(choice) {
|
|
2189
|
+
switch (choice) {
|
|
2190
|
+
case "auto":
|
|
2191
|
+
return { functionCallingConfig: { mode: "AUTO" } };
|
|
2192
|
+
case "required":
|
|
2193
|
+
return { functionCallingConfig: { mode: "ANY" } };
|
|
2194
|
+
case "none":
|
|
2195
|
+
return { functionCallingConfig: { mode: "NONE" } };
|
|
2196
|
+
default:
|
|
2197
|
+
return void 0;
|
|
2198
|
+
}
|
|
2199
|
+
}
|
|
2200
|
+
function thinkingBudget(level, maxOutput) {
|
|
2201
|
+
if (level === void 0 || level === "off") {
|
|
2202
|
+
return void 0;
|
|
2203
|
+
}
|
|
2204
|
+
const fraction = {
|
|
2205
|
+
low: 0.2,
|
|
2206
|
+
medium: 0.4,
|
|
2207
|
+
high: 0.6,
|
|
2208
|
+
max: 0.8
|
|
2209
|
+
};
|
|
2210
|
+
return Math.max(0, Math.floor(maxOutput * fraction[level]));
|
|
2211
|
+
}
|
|
2212
|
+
function buildBody3(model, c, opts) {
|
|
2213
|
+
const body = {
|
|
2214
|
+
contents: toGoogleContents(c)
|
|
2215
|
+
};
|
|
2216
|
+
const systemInstruction = toGoogleSystemInstruction(c);
|
|
2217
|
+
if (systemInstruction !== void 0) {
|
|
2218
|
+
body.systemInstruction = systemInstruction;
|
|
2219
|
+
}
|
|
2220
|
+
const tools = toGoogleTools(c.tools);
|
|
2221
|
+
if (tools !== void 0) {
|
|
2222
|
+
body.tools = tools;
|
|
2223
|
+
const toolConfig = toFunctionCallingConfig(opts.toolChoice);
|
|
2224
|
+
if (toolConfig !== void 0) {
|
|
2225
|
+
body.toolConfig = toolConfig;
|
|
2226
|
+
}
|
|
2227
|
+
}
|
|
2228
|
+
const generationConfig = {};
|
|
2229
|
+
const maxTokens = opts.maxOutputTokens ?? model.maxOutputTokens;
|
|
2230
|
+
if (maxTokens > 0) {
|
|
2231
|
+
generationConfig.maxOutputTokens = maxTokens;
|
|
2232
|
+
}
|
|
2233
|
+
if (opts.temperature !== void 0) {
|
|
2234
|
+
generationConfig.temperature = opts.temperature;
|
|
2235
|
+
}
|
|
2236
|
+
if (opts.topP !== void 0) {
|
|
2237
|
+
generationConfig.topP = opts.topP;
|
|
2238
|
+
}
|
|
2239
|
+
if (model.reasoning) {
|
|
2240
|
+
const budget = thinkingBudget(opts.thinking, maxTokens);
|
|
2241
|
+
if (budget !== void 0) {
|
|
2242
|
+
generationConfig.thinkingConfig = { thinkingBudget: budget };
|
|
2243
|
+
}
|
|
2244
|
+
}
|
|
2245
|
+
if (Object.keys(generationConfig).length > 0) {
|
|
2246
|
+
body.generationConfig = generationConfig;
|
|
2247
|
+
}
|
|
2248
|
+
return body;
|
|
2249
|
+
}
|
|
2250
|
+
function isObject5(v) {
|
|
2251
|
+
return typeof v === "object" && v !== null;
|
|
2252
|
+
}
|
|
2253
|
+
function readString4(o, key) {
|
|
2254
|
+
const v = o[key];
|
|
2255
|
+
return typeof v === "string" ? v : void 0;
|
|
2256
|
+
}
|
|
2257
|
+
function readNumber4(o, key) {
|
|
2258
|
+
const v = o[key];
|
|
2259
|
+
return typeof v === "number" && Number.isFinite(v) ? v : void 0;
|
|
2260
|
+
}
|
|
2261
|
+
function readBool(o, key) {
|
|
2262
|
+
return o[key] === true;
|
|
2263
|
+
}
|
|
2264
|
+
function mapFinishReason3(reason) {
|
|
2265
|
+
switch (reason) {
|
|
2266
|
+
case void 0:
|
|
2267
|
+
case "":
|
|
2268
|
+
case "FINISH_REASON_UNSPECIFIED":
|
|
2269
|
+
return void 0;
|
|
2270
|
+
case "STOP":
|
|
2271
|
+
return "complete";
|
|
2272
|
+
case "MAX_TOKENS":
|
|
2273
|
+
return "max_output";
|
|
2274
|
+
case "SAFETY":
|
|
2275
|
+
case "RECITATION":
|
|
2276
|
+
case "BLOCKLIST":
|
|
2277
|
+
case "PROHIBITED_CONTENT":
|
|
2278
|
+
case "SPII":
|
|
2279
|
+
return "refusal";
|
|
2280
|
+
default:
|
|
2281
|
+
return "complete";
|
|
2282
|
+
}
|
|
2283
|
+
}
|
|
2284
|
+
function readUsage3(chunk) {
|
|
2285
|
+
const meta = chunk.usageMetadata;
|
|
2286
|
+
if (!isObject5(meta)) {
|
|
2287
|
+
return void 0;
|
|
2288
|
+
}
|
|
2289
|
+
const inputTokens = readNumber4(meta, "promptTokenCount") ?? 0;
|
|
2290
|
+
const candidate = readNumber4(meta, "candidatesTokenCount") ?? 0;
|
|
2291
|
+
const thoughts = readNumber4(meta, "thoughtsTokenCount") ?? 0;
|
|
2292
|
+
const result = {
|
|
2293
|
+
inputTokens,
|
|
2294
|
+
outputTokens: candidate + thoughts
|
|
2295
|
+
};
|
|
2296
|
+
const cached = readNumber4(meta, "cachedContentTokenCount");
|
|
2297
|
+
if (cached !== void 0) {
|
|
2298
|
+
result.cacheReadTokens = cached;
|
|
2299
|
+
}
|
|
2300
|
+
return result;
|
|
2301
|
+
}
|
|
2302
|
+
function* emitFromChunk2(chunk, tracker) {
|
|
2303
|
+
const usage = readUsage3(chunk);
|
|
2304
|
+
if (usage !== void 0) {
|
|
2305
|
+
yield { kind: "usage", usage };
|
|
2306
|
+
}
|
|
2307
|
+
const candidates = chunk.candidates;
|
|
2308
|
+
if (!Array.isArray(candidates) || candidates.length === 0) {
|
|
2309
|
+
return;
|
|
2310
|
+
}
|
|
2311
|
+
const candidate = candidates[0];
|
|
2312
|
+
if (!isObject5(candidate)) {
|
|
2313
|
+
return;
|
|
2314
|
+
}
|
|
2315
|
+
const content = candidate.content;
|
|
2316
|
+
if (isObject5(content)) {
|
|
2317
|
+
const parts = content.parts;
|
|
2318
|
+
if (Array.isArray(parts)) {
|
|
2319
|
+
for (const part of parts) {
|
|
2320
|
+
yield* emitFromPart(part, tracker);
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
}
|
|
2324
|
+
const finish = mapFinishReason3(readString4(candidate, "finishReason"));
|
|
2325
|
+
if (finish !== void 0) {
|
|
2326
|
+
yield { kind: "stop", stop: finish };
|
|
2327
|
+
}
|
|
2328
|
+
}
|
|
2329
|
+
function* emitFromPart(part, tracker) {
|
|
2330
|
+
if (!isObject5(part)) {
|
|
2331
|
+
return;
|
|
2332
|
+
}
|
|
2333
|
+
const functionCall = part.functionCall;
|
|
2334
|
+
if (isObject5(functionCall)) {
|
|
2335
|
+
const name = readString4(functionCall, "name") ?? "";
|
|
2336
|
+
const id = `vertex_call_${tracker.next}`;
|
|
2337
|
+
tracker.next += 1;
|
|
2338
|
+
yield { kind: "tool_call_start", id, name };
|
|
2339
|
+
const args = functionCall.args;
|
|
2340
|
+
const argsDelta = serializeArgs2(args);
|
|
2341
|
+
if (argsDelta !== "") {
|
|
2342
|
+
yield { kind: "tool_call_delta", id, argsDelta };
|
|
2343
|
+
}
|
|
2344
|
+
return;
|
|
2345
|
+
}
|
|
2346
|
+
const text = readString4(part, "text");
|
|
2347
|
+
if (text !== void 0 && text !== "") {
|
|
2348
|
+
if (readBool(part, "thought")) {
|
|
2349
|
+
yield { kind: "thinking", delta: text };
|
|
2350
|
+
} else {
|
|
2351
|
+
yield { kind: "text", delta: text };
|
|
2352
|
+
}
|
|
2353
|
+
}
|
|
2354
|
+
}
|
|
2355
|
+
function serializeArgs2(args) {
|
|
2356
|
+
if (args === void 0 || args === null) {
|
|
2357
|
+
return "";
|
|
2358
|
+
}
|
|
2359
|
+
if (typeof args === "string") {
|
|
2360
|
+
return args;
|
|
2361
|
+
}
|
|
2362
|
+
try {
|
|
2363
|
+
return JSON.stringify(args);
|
|
2364
|
+
} catch {
|
|
2365
|
+
return "";
|
|
2366
|
+
}
|
|
2367
|
+
}
|
|
2368
|
+
async function postStream(url, token, body, signal) {
|
|
2369
|
+
let response;
|
|
2370
|
+
try {
|
|
2371
|
+
response = await fetch(url, {
|
|
2372
|
+
method: "POST",
|
|
2373
|
+
headers: {
|
|
2374
|
+
"content-type": "application/json",
|
|
2375
|
+
authorization: `Bearer ${token}`
|
|
2376
|
+
},
|
|
2377
|
+
body: JSON.stringify(body),
|
|
2378
|
+
...signal !== void 0 ? { signal } : {}
|
|
2379
|
+
});
|
|
2380
|
+
} catch (cause) {
|
|
2381
|
+
if (signal?.aborted) {
|
|
2382
|
+
throw gatewayError("aborted", "Vertex request was aborted before a response arrived", {
|
|
2383
|
+
provider: PROVIDER2,
|
|
2384
|
+
cause
|
|
2385
|
+
});
|
|
2386
|
+
}
|
|
2387
|
+
throw gatewayError("transport", "network request to Vertex AI failed", {
|
|
2388
|
+
provider: PROVIDER2,
|
|
2389
|
+
cause
|
|
2390
|
+
});
|
|
2391
|
+
}
|
|
2392
|
+
if (!response.ok) {
|
|
2393
|
+
const detail = await readErrorBody3(response);
|
|
2394
|
+
const kind = response.status === 401 || response.status === 403 ? "auth" : response.status === 429 ? "rate_limit" : "http";
|
|
2395
|
+
throw gatewayError(kind, `Vertex AI returned HTTP ${response.status}${detail}`, {
|
|
2396
|
+
provider: PROVIDER2,
|
|
2397
|
+
status: response.status
|
|
2398
|
+
});
|
|
2399
|
+
}
|
|
2400
|
+
if (response.body === null) {
|
|
2401
|
+
throw gatewayError("transport", "Vertex AI response carried no body", {
|
|
2402
|
+
provider: PROVIDER2,
|
|
2403
|
+
status: response.status
|
|
2404
|
+
});
|
|
2405
|
+
}
|
|
2406
|
+
return response;
|
|
2407
|
+
}
|
|
2408
|
+
async function readErrorBody3(response) {
|
|
2409
|
+
try {
|
|
2410
|
+
const text = await response.text();
|
|
2411
|
+
return text === "" ? "" : `: ${text.slice(0, 500)}`;
|
|
2412
|
+
} catch {
|
|
2413
|
+
return "";
|
|
2414
|
+
}
|
|
2415
|
+
}
|
|
2416
|
+
function creategooglevertexConnector(deps2) {
|
|
2417
|
+
const { resolveSecret: resolveSecret2 } = deps2;
|
|
2418
|
+
function stream2(model, conversation, options) {
|
|
2419
|
+
return channelOf(async function* run() {
|
|
2420
|
+
const collected = [];
|
|
2421
|
+
try {
|
|
2422
|
+
const token = await resolveSecret2(PROVIDER2, options.apiKey);
|
|
2423
|
+
if (token === void 0 || token === "") {
|
|
2424
|
+
throw gatewayError(
|
|
2425
|
+
"auth",
|
|
2426
|
+
"no Google access token available for Vertex AI; provide one via apiKey or the environment",
|
|
2427
|
+
{ provider: PROVIDER2 }
|
|
2428
|
+
);
|
|
2429
|
+
}
|
|
2430
|
+
const target = resolveTarget(model);
|
|
2431
|
+
const body = buildBody3(model, conversation, options);
|
|
2432
|
+
const response = await postStream(target.url, token, body, options.signal);
|
|
2433
|
+
const sseBody = response.body;
|
|
2434
|
+
const tracker = { next: 0 };
|
|
2435
|
+
for await (const event of sseEvents(sseBody, options.signal)) {
|
|
2436
|
+
const payload = event.data;
|
|
2437
|
+
if (payload === "" || payload === "[DONE]") {
|
|
2438
|
+
continue;
|
|
2439
|
+
}
|
|
2440
|
+
let chunk;
|
|
2441
|
+
try {
|
|
2442
|
+
chunk = JSON.parse(payload);
|
|
2443
|
+
} catch (cause) {
|
|
2444
|
+
throw gatewayError("parse", "failed to parse a Vertex AI stream chunk", {
|
|
2445
|
+
provider: PROVIDER2,
|
|
2446
|
+
cause
|
|
2447
|
+
});
|
|
2448
|
+
}
|
|
2449
|
+
if (!isObject5(chunk)) {
|
|
2450
|
+
continue;
|
|
2451
|
+
}
|
|
2452
|
+
for (const emission of emitFromChunk2(chunk, tracker)) {
|
|
2453
|
+
collected.push(emission);
|
|
2454
|
+
yield emission;
|
|
2455
|
+
}
|
|
2456
|
+
}
|
|
2457
|
+
yield { kind: "done", reply: foldReply(model.id, collected) };
|
|
2458
|
+
} catch (cause) {
|
|
2459
|
+
const error = cause instanceof Error && cause.name === "GatewayError" ? cause : gatewayError("transport", "Vertex AI stream failed", { provider: PROVIDER2, cause });
|
|
2460
|
+
yield { kind: "error", error };
|
|
2461
|
+
}
|
|
2462
|
+
});
|
|
2463
|
+
}
|
|
2464
|
+
function complete2(model, conversation, options) {
|
|
2465
|
+
return collectReply(stream2(model, conversation, options));
|
|
2466
|
+
}
|
|
2467
|
+
return {
|
|
2468
|
+
id: "google-vertex",
|
|
2469
|
+
api: API_KIND,
|
|
2470
|
+
stream: stream2,
|
|
2471
|
+
complete: complete2
|
|
2472
|
+
};
|
|
2473
|
+
}
|
|
2474
|
+
|
|
2475
|
+
// src/llmgateway/connectors/bedrock.ts
|
|
2476
|
+
var PROVIDER3 = "amazon";
|
|
2477
|
+
var DIALECT = "amazon-bedrock";
|
|
2478
|
+
var FALLBACK_REGION = "us-east-1";
|
|
2479
|
+
function discoverRegion() {
|
|
2480
|
+
const env = (typeof process !== "undefined" ? process.env : void 0) ?? {};
|
|
2481
|
+
const region = env.AWS_REGION ?? env.AWS_DEFAULT_REGION ?? env.AWS_BEDROCK_REGION;
|
|
2482
|
+
const trimmed = region?.trim();
|
|
2483
|
+
return trimmed !== void 0 && trimmed !== "" ? trimmed : void 0;
|
|
2484
|
+
}
|
|
2485
|
+
function converseStreamUrl(model, region) {
|
|
2486
|
+
const base = model.baseUrl !== void 0 && model.baseUrl !== "" ? model.baseUrl.replace(/\/+$/, "") : `https://bedrock-runtime.${region}.amazonaws.com`;
|
|
2487
|
+
return `${base}/model/${encodeURIComponent(model.id)}/converse-stream`;
|
|
2488
|
+
}
|
|
2489
|
+
function stringifyOutput(output) {
|
|
2490
|
+
if (typeof output === "string") {
|
|
2491
|
+
return output;
|
|
2492
|
+
}
|
|
2493
|
+
try {
|
|
2494
|
+
return JSON.stringify(output);
|
|
2495
|
+
} catch {
|
|
2496
|
+
return String(output);
|
|
2497
|
+
}
|
|
2498
|
+
}
|
|
2499
|
+
function toJsonInput(input) {
|
|
2500
|
+
if (input !== null && typeof input === "object" && !Array.isArray(input)) {
|
|
2501
|
+
return input;
|
|
2502
|
+
}
|
|
2503
|
+
if (typeof input === "string") {
|
|
2504
|
+
try {
|
|
2505
|
+
const parsed = JSON.parse(input);
|
|
2506
|
+
if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
2507
|
+
return parsed;
|
|
2508
|
+
}
|
|
2509
|
+
} catch {
|
|
2510
|
+
}
|
|
2511
|
+
}
|
|
2512
|
+
return { value: input };
|
|
2513
|
+
}
|
|
2514
|
+
function toContentBlocks(block) {
|
|
2515
|
+
switch (block.kind) {
|
|
2516
|
+
case "text":
|
|
2517
|
+
return [{ text: block.text }];
|
|
2518
|
+
case "thinking":
|
|
2519
|
+
return [
|
|
2520
|
+
{
|
|
2521
|
+
reasoningContent: {
|
|
2522
|
+
reasoningText: block.signature !== void 0 ? { text: block.text, signature: block.signature } : { text: block.text }
|
|
2523
|
+
}
|
|
2524
|
+
}
|
|
2525
|
+
];
|
|
2526
|
+
case "image": {
|
|
2527
|
+
const slash = block.mediaType.indexOf("/");
|
|
2528
|
+
const format = slash >= 0 ? block.mediaType.slice(slash + 1) : block.mediaType;
|
|
2529
|
+
return [
|
|
2530
|
+
{
|
|
2531
|
+
image: {
|
|
2532
|
+
format,
|
|
2533
|
+
source: { bytes: block.dataBase64 }
|
|
2534
|
+
}
|
|
2535
|
+
}
|
|
2536
|
+
];
|
|
2537
|
+
}
|
|
2538
|
+
case "tool_call":
|
|
2539
|
+
return [
|
|
2540
|
+
{
|
|
2541
|
+
toolUse: {
|
|
2542
|
+
toolUseId: block.id,
|
|
2543
|
+
name: block.name,
|
|
2544
|
+
input: toJsonInput(block.input)
|
|
2545
|
+
}
|
|
2546
|
+
}
|
|
2547
|
+
];
|
|
2548
|
+
case "tool_result":
|
|
2549
|
+
return [
|
|
2550
|
+
{
|
|
2551
|
+
toolResult: {
|
|
2552
|
+
toolUseId: block.callId,
|
|
2553
|
+
content: [{ text: stringifyOutput(block.output) }],
|
|
2554
|
+
...block.isError === true ? { status: "error" } : {}
|
|
2555
|
+
}
|
|
2556
|
+
}
|
|
2557
|
+
];
|
|
2558
|
+
case "command": {
|
|
2559
|
+
const argv = block.args && block.args.length > 0 ? ` ${block.args.join(" ")}` : "";
|
|
2560
|
+
return [{ text: `$ ${block.command}${argv}` }];
|
|
2561
|
+
}
|
|
2562
|
+
}
|
|
2563
|
+
}
|
|
2564
|
+
function converseRole(turn) {
|
|
2565
|
+
return turn.role === "assistant" ? "assistant" : "user";
|
|
2566
|
+
}
|
|
2567
|
+
function toConverseMessages(conversation) {
|
|
2568
|
+
const messages = [];
|
|
2569
|
+
for (const turn of conversation.turns) {
|
|
2570
|
+
const content = [];
|
|
2571
|
+
for (const block of turn.blocks) {
|
|
2572
|
+
for (const wire of toContentBlocks(block)) {
|
|
2573
|
+
content.push(wire);
|
|
2574
|
+
}
|
|
2575
|
+
}
|
|
2576
|
+
if (content.length > 0) {
|
|
2577
|
+
messages.push({ role: converseRole(turn), content });
|
|
2578
|
+
}
|
|
2579
|
+
}
|
|
2580
|
+
return messages;
|
|
2581
|
+
}
|
|
2582
|
+
function toConverseSystem(conversation) {
|
|
2583
|
+
if (conversation.system === void 0 || conversation.system === "") {
|
|
2584
|
+
return void 0;
|
|
2585
|
+
}
|
|
2586
|
+
return [{ text: conversation.system }];
|
|
2587
|
+
}
|
|
2588
|
+
function toConverseTools(tools) {
|
|
2589
|
+
if (tools === void 0 || tools.length === 0) {
|
|
2590
|
+
return void 0;
|
|
2591
|
+
}
|
|
2592
|
+
return tools.map((tool) => ({
|
|
2593
|
+
toolSpec: {
|
|
2594
|
+
name: tool.name,
|
|
2595
|
+
description: tool.description,
|
|
2596
|
+
inputSchema: { json: tool.parameters }
|
|
2597
|
+
}
|
|
2598
|
+
}));
|
|
2599
|
+
}
|
|
2600
|
+
function toConverseToolChoice(options) {
|
|
2601
|
+
switch (options.toolChoice) {
|
|
2602
|
+
case "auto":
|
|
2603
|
+
return { auto: {} };
|
|
2604
|
+
case "required":
|
|
2605
|
+
return { any: {} };
|
|
2606
|
+
case "none":
|
|
2607
|
+
case void 0:
|
|
2608
|
+
return void 0;
|
|
2609
|
+
}
|
|
2610
|
+
}
|
|
2611
|
+
function toInferenceConfig(model, options) {
|
|
2612
|
+
const config = {
|
|
2613
|
+
maxTokens: options.maxOutputTokens ?? model.maxOutputTokens
|
|
2614
|
+
};
|
|
2615
|
+
if (options.temperature !== void 0) {
|
|
2616
|
+
config.temperature = options.temperature;
|
|
2617
|
+
}
|
|
2618
|
+
if (options.topP !== void 0) {
|
|
2619
|
+
config.topP = options.topP;
|
|
2620
|
+
}
|
|
2621
|
+
return config;
|
|
2622
|
+
}
|
|
2623
|
+
function buildConverseBody(model, conversation, options) {
|
|
2624
|
+
const body = {
|
|
2625
|
+
messages: toConverseMessages(conversation),
|
|
2626
|
+
inferenceConfig: toInferenceConfig(model, options)
|
|
2627
|
+
};
|
|
2628
|
+
const system = toConverseSystem(conversation);
|
|
2629
|
+
if (system !== void 0) {
|
|
2630
|
+
body.system = system;
|
|
2631
|
+
}
|
|
2632
|
+
const tools = toConverseTools(conversation.tools);
|
|
2633
|
+
if (tools !== void 0) {
|
|
2634
|
+
const toolConfig = { tools };
|
|
2635
|
+
const choice = toConverseToolChoice(options);
|
|
2636
|
+
if (choice !== void 0) {
|
|
2637
|
+
toolConfig.toolChoice = choice;
|
|
2638
|
+
}
|
|
2639
|
+
body.toolConfig = toolConfig;
|
|
2640
|
+
}
|
|
2641
|
+
return body;
|
|
2642
|
+
}
|
|
2643
|
+
async function requireSignedTransport(resolveSecret2, options) {
|
|
2644
|
+
const credential = await resolveSecret2(PROVIDER3, options.apiKey);
|
|
2645
|
+
const region = discoverRegion() ?? FALLBACK_REGION;
|
|
2646
|
+
void credential;
|
|
2647
|
+
void region;
|
|
2648
|
+
throw gatewayError(
|
|
2649
|
+
"unsupported",
|
|
2650
|
+
"bedrock streaming requires SigV4 (todo)",
|
|
2651
|
+
{ provider: PROVIDER3 }
|
|
2652
|
+
);
|
|
2653
|
+
}
|
|
2654
|
+
function createbedrockConnector(deps2) {
|
|
2655
|
+
const { resolveSecret: resolveSecret2 } = deps2;
|
|
2656
|
+
return {
|
|
2657
|
+
id: "bedrock",
|
|
2658
|
+
api: DIALECT,
|
|
2659
|
+
stream(model, conversation, options) {
|
|
2660
|
+
return channelOf(async function* () {
|
|
2661
|
+
const region = discoverRegion() ?? FALLBACK_REGION;
|
|
2662
|
+
const url = converseStreamUrl(model, region);
|
|
2663
|
+
const body = buildConverseBody(model, conversation, options);
|
|
2664
|
+
void url;
|
|
2665
|
+
void body;
|
|
2666
|
+
await requireSignedTransport(resolveSecret2, options);
|
|
2667
|
+
});
|
|
2668
|
+
},
|
|
2669
|
+
complete(model, conversation, options) {
|
|
2670
|
+
return collectReply(this.stream(model, conversation, options));
|
|
2671
|
+
}
|
|
2672
|
+
};
|
|
2673
|
+
}
|
|
2674
|
+
|
|
2675
|
+
// src/llmgateway/connectors/azure-openai.ts
|
|
2676
|
+
var AZURE_API_VERSION = "2024-08-01-preview";
|
|
2677
|
+
function deploymentName(model) {
|
|
2678
|
+
const id = model.id.trim();
|
|
2679
|
+
if (id === "") {
|
|
2680
|
+
throw gatewayError(
|
|
2681
|
+
"unsupported",
|
|
2682
|
+
"azure card is missing an id to use as the deployment name",
|
|
2683
|
+
{ provider: model.provider }
|
|
2684
|
+
);
|
|
2685
|
+
}
|
|
2686
|
+
return id;
|
|
2687
|
+
}
|
|
2688
|
+
function endpointFor3(model) {
|
|
2689
|
+
const base = model.baseUrl?.replace(/\/+$/, "");
|
|
2690
|
+
if (base === void 0 || base === "") {
|
|
2691
|
+
throw gatewayError(
|
|
2692
|
+
"unsupported",
|
|
2693
|
+
"azure card has no baseUrl; set it to the resource endpoint, e.g. https://<resource>.openai.azure.com",
|
|
2694
|
+
{ provider: model.provider }
|
|
2695
|
+
);
|
|
2696
|
+
}
|
|
2697
|
+
const deployment = encodeURIComponent(deploymentName(model));
|
|
2698
|
+
const query = new URLSearchParams({ "api-version": AZURE_API_VERSION });
|
|
2699
|
+
return `${base}/openai/deployments/${deployment}/chat/completions?${query.toString()}`;
|
|
2700
|
+
}
|
|
2701
|
+
var AzureOpenAIConnector = class {
|
|
2702
|
+
constructor(deps2) {
|
|
2703
|
+
this.deps = deps2;
|
|
2704
|
+
}
|
|
2705
|
+
deps;
|
|
2706
|
+
id = "azure-openai";
|
|
2707
|
+
api = "azure-openai";
|
|
2708
|
+
stream(model, conversation, options) {
|
|
2709
|
+
const deps2 = this.deps;
|
|
2710
|
+
return channelOf(async function* run() {
|
|
2711
|
+
let cfg;
|
|
2712
|
+
try {
|
|
2713
|
+
cfg = await resolveConfig2(deps2, model, options);
|
|
2714
|
+
} catch (cause) {
|
|
2715
|
+
const error = cause instanceof Error && cause.name === "GatewayError" ? cause : gatewayError("auth", "could not prepare the Azure OpenAI request", {
|
|
2716
|
+
provider: model.provider,
|
|
2717
|
+
cause
|
|
2718
|
+
});
|
|
2719
|
+
yield { kind: "error", error };
|
|
2720
|
+
return;
|
|
2721
|
+
}
|
|
2722
|
+
yield* streamOpenAICompatibleChat(cfg, model, conversation, options);
|
|
2723
|
+
});
|
|
2724
|
+
}
|
|
2725
|
+
async complete(model, conversation, options) {
|
|
2726
|
+
return collectReply(this.stream(model, conversation, options));
|
|
2727
|
+
}
|
|
2728
|
+
};
|
|
2729
|
+
async function resolveConfig2(deps2, model, options) {
|
|
2730
|
+
const url = endpointFor3(model);
|
|
2731
|
+
const key = await deps2.resolveSecret(model.provider, options.apiKey);
|
|
2732
|
+
if (key === void 0 || key === "") {
|
|
2733
|
+
throw gatewayError(
|
|
2734
|
+
"auth",
|
|
2735
|
+
"no Azure OpenAI credential found \u2014 set AZURE_OPENAI_API_KEY (or AZURE_API_KEY), or pass options.apiKey",
|
|
2736
|
+
{ provider: model.provider }
|
|
2737
|
+
);
|
|
2738
|
+
}
|
|
2739
|
+
return {
|
|
2740
|
+
url,
|
|
2741
|
+
// Azure authenticates with an api-key header, not an OpenAI bearer token.
|
|
2742
|
+
headers: { "api-key": key }
|
|
2743
|
+
};
|
|
2744
|
+
}
|
|
2745
|
+
function createazureopenaiConnector(deps2) {
|
|
2746
|
+
return new AzureOpenAIConnector(deps2);
|
|
2747
|
+
}
|
|
2748
|
+
|
|
2749
|
+
// src/llmgateway/connectors/nvidia.ts
|
|
2750
|
+
var DEFAULT_NVIDIA_BASE_URL = "https://integrate.api.nvidia.com/v1";
|
|
2751
|
+
function endpointFor4(model) {
|
|
2752
|
+
const base = (model.baseUrl ?? DEFAULT_NVIDIA_BASE_URL).replace(/\/+$/, "");
|
|
2753
|
+
return `${base}/chat/completions`;
|
|
2754
|
+
}
|
|
2755
|
+
function bodyOverridesFor(model) {
|
|
2756
|
+
if (!model.reasoning) {
|
|
2757
|
+
return void 0;
|
|
2758
|
+
}
|
|
2759
|
+
return { chat_template_kwargs: { thinking: true } };
|
|
2760
|
+
}
|
|
2761
|
+
var NvidiaConnector = class {
|
|
2762
|
+
constructor(deps2) {
|
|
2763
|
+
this.deps = deps2;
|
|
2764
|
+
}
|
|
2765
|
+
deps;
|
|
2766
|
+
id = "nvidia";
|
|
2767
|
+
api = "nvidia-openai-compatible";
|
|
2768
|
+
stream(model, conversation, options) {
|
|
2769
|
+
const deps2 = this.deps;
|
|
2770
|
+
return channelOf(async function* run() {
|
|
2771
|
+
let cfg;
|
|
2772
|
+
try {
|
|
2773
|
+
cfg = await assembleConfig(deps2, model, options);
|
|
2774
|
+
} catch (cause) {
|
|
2775
|
+
const error = cause instanceof Error && cause.name === "GatewayError" ? cause : gatewayError("auth", "unable to prepare the NVIDIA request", {
|
|
2776
|
+
provider: model.provider,
|
|
2777
|
+
cause
|
|
2778
|
+
});
|
|
2779
|
+
yield { kind: "error", error };
|
|
2780
|
+
return;
|
|
2781
|
+
}
|
|
2782
|
+
yield* streamOpenAICompatibleChat(cfg, model, conversation, options);
|
|
2783
|
+
});
|
|
2784
|
+
}
|
|
2785
|
+
async complete(model, conversation, options) {
|
|
2786
|
+
return collectReply(this.stream(model, conversation, options));
|
|
2787
|
+
}
|
|
2788
|
+
};
|
|
2789
|
+
async function assembleConfig(deps2, model, options) {
|
|
2790
|
+
const key = await deps2.resolveSecret(model.provider, options.apiKey);
|
|
2791
|
+
if (key === void 0 || key === "") {
|
|
2792
|
+
throw gatewayError(
|
|
2793
|
+
"auth",
|
|
2794
|
+
"missing NVIDIA credential \u2014 set NVIDIA_API_KEY or pass options.apiKey",
|
|
2795
|
+
{ provider: model.provider }
|
|
2796
|
+
);
|
|
2797
|
+
}
|
|
2798
|
+
const bodyExtra = bodyOverridesFor(model);
|
|
2799
|
+
return {
|
|
2800
|
+
url: endpointFor4(model),
|
|
2801
|
+
headers: { authorization: `Bearer ${key}` },
|
|
2802
|
+
...bodyExtra ? { bodyExtra } : {}
|
|
2803
|
+
};
|
|
2804
|
+
}
|
|
2805
|
+
function createnvidiaConnector(deps2) {
|
|
2806
|
+
return new NvidiaConnector(deps2);
|
|
2807
|
+
}
|
|
2808
|
+
|
|
2809
|
+
// src/llmgateway/connectors/kimi.ts
|
|
2810
|
+
var DEFAULT_MOONSHOT_BASE_URL = "https://api.moonshot.ai/v1";
|
|
2811
|
+
function endpointFor5(model) {
|
|
2812
|
+
const base = (model.baseUrl ?? DEFAULT_MOONSHOT_BASE_URL).replace(/\/+$/, "");
|
|
2813
|
+
return `${base}/chat/completions`;
|
|
2814
|
+
}
|
|
2815
|
+
var KimiConnector = class {
|
|
2816
|
+
constructor(deps2) {
|
|
2817
|
+
this.deps = deps2;
|
|
2818
|
+
}
|
|
2819
|
+
deps;
|
|
2820
|
+
id = "kimi";
|
|
2821
|
+
api = "kimi-openai-compatible";
|
|
2822
|
+
stream(model, conversation, options) {
|
|
2823
|
+
const deps2 = this.deps;
|
|
2824
|
+
return channelOf(async function* run() {
|
|
2825
|
+
let cfg;
|
|
2826
|
+
try {
|
|
2827
|
+
cfg = await resolveConfig3(deps2, model, options);
|
|
2828
|
+
} catch (cause) {
|
|
2829
|
+
const error = cause instanceof Error && cause.name === "GatewayError" ? cause : gatewayError("auth", "could not prepare the Kimi request", {
|
|
2830
|
+
provider: model.provider,
|
|
2831
|
+
cause
|
|
2832
|
+
});
|
|
2833
|
+
yield { kind: "error", error };
|
|
2834
|
+
return;
|
|
2835
|
+
}
|
|
2836
|
+
yield* streamOpenAICompatibleChat(cfg, model, conversation, options);
|
|
2837
|
+
});
|
|
2838
|
+
}
|
|
2839
|
+
async complete(model, conversation, options) {
|
|
2840
|
+
return collectReply(this.stream(model, conversation, options));
|
|
2841
|
+
}
|
|
2842
|
+
};
|
|
2843
|
+
async function resolveConfig3(deps2, model, options) {
|
|
2844
|
+
const key = await deps2.resolveSecret(model.provider, options.apiKey);
|
|
2845
|
+
if (key === void 0 || key === "") {
|
|
2846
|
+
throw gatewayError(
|
|
2847
|
+
"auth",
|
|
2848
|
+
"no Kimi credential found \u2014 set MOONSHOT_API_KEY (or KIMI_API_KEY), or pass options.apiKey",
|
|
2849
|
+
{ provider: model.provider }
|
|
2850
|
+
);
|
|
2851
|
+
}
|
|
2852
|
+
return {
|
|
2853
|
+
url: endpointFor5(model),
|
|
2854
|
+
headers: { authorization: `Bearer ${key}` }
|
|
2855
|
+
};
|
|
2856
|
+
}
|
|
2857
|
+
function createkimiConnector(deps2) {
|
|
2858
|
+
return new KimiConnector(deps2);
|
|
2859
|
+
}
|
|
2860
|
+
|
|
2861
|
+
// src/llmgateway/connectors/ollama.ts
|
|
2862
|
+
var DEFAULT_BASE_URL3 = "http://localhost:11434";
|
|
2863
|
+
var PROVIDER4 = "ollama";
|
|
2864
|
+
function isObject6(value) {
|
|
2865
|
+
return typeof value === "object" && value !== null;
|
|
2866
|
+
}
|
|
2867
|
+
function readString5(o, key) {
|
|
2868
|
+
const v = o[key];
|
|
2869
|
+
return typeof v === "string" ? v : void 0;
|
|
2870
|
+
}
|
|
2871
|
+
function readNumber5(o, key) {
|
|
2872
|
+
const v = o[key];
|
|
2873
|
+
return typeof v === "number" && Number.isFinite(v) ? v : void 0;
|
|
2874
|
+
}
|
|
2875
|
+
function buildOptions(model, opts) {
|
|
2876
|
+
const options = {};
|
|
2877
|
+
const numPredict = opts.maxOutputTokens ?? model.maxOutputTokens;
|
|
2878
|
+
if (numPredict > 0) {
|
|
2879
|
+
options.num_predict = numPredict;
|
|
2880
|
+
}
|
|
2881
|
+
if (opts.temperature !== void 0) {
|
|
2882
|
+
options.temperature = opts.temperature;
|
|
2883
|
+
}
|
|
2884
|
+
if (opts.topP !== void 0) {
|
|
2885
|
+
options.top_p = opts.topP;
|
|
2886
|
+
}
|
|
2887
|
+
return Object.keys(options).length > 0 ? options : void 0;
|
|
2888
|
+
}
|
|
2889
|
+
function buildRequestBody2(model, conversation, opts) {
|
|
2890
|
+
const body = {
|
|
2891
|
+
model: model.id,
|
|
2892
|
+
messages: toOpenAIChatMessages(conversation),
|
|
2893
|
+
stream: true
|
|
2894
|
+
};
|
|
2895
|
+
const tools = toOpenAITools(conversation.tools);
|
|
2896
|
+
if (tools !== void 0) {
|
|
2897
|
+
body.tools = tools;
|
|
2898
|
+
}
|
|
2899
|
+
const options = buildOptions(model, opts);
|
|
2900
|
+
if (options !== void 0) {
|
|
2901
|
+
body.options = options;
|
|
2902
|
+
}
|
|
2903
|
+
return body;
|
|
2904
|
+
}
|
|
2905
|
+
function chatEndpoint(model) {
|
|
2906
|
+
const base = (model.baseUrl ?? DEFAULT_BASE_URL3).replace(/\/+$/u, "");
|
|
2907
|
+
return `${base}/api/chat`;
|
|
2908
|
+
}
|
|
2909
|
+
function buildHeaders(secret) {
|
|
2910
|
+
const headers = { "content-type": "application/json" };
|
|
2911
|
+
if (secret !== void 0 && secret !== "") {
|
|
2912
|
+
headers.authorization = `Bearer ${secret}`;
|
|
2913
|
+
}
|
|
2914
|
+
return headers;
|
|
2915
|
+
}
|
|
2916
|
+
async function openStream2(url, headers, body, signal) {
|
|
2917
|
+
let response;
|
|
2918
|
+
try {
|
|
2919
|
+
response = await fetch(url, {
|
|
2920
|
+
method: "POST",
|
|
2921
|
+
headers,
|
|
2922
|
+
body: JSON.stringify(body),
|
|
2923
|
+
...signal !== void 0 ? { signal } : {}
|
|
2924
|
+
});
|
|
2925
|
+
} catch (cause) {
|
|
2926
|
+
if (signal?.aborted) {
|
|
2927
|
+
throw gatewayError("aborted", "the Ollama request was aborted before a response arrived", {
|
|
2928
|
+
provider: PROVIDER4,
|
|
2929
|
+
cause
|
|
2930
|
+
});
|
|
2931
|
+
}
|
|
2932
|
+
throw gatewayError("transport", "could not reach the Ollama daemon (is `ollama serve` running?)", {
|
|
2933
|
+
provider: PROVIDER4,
|
|
2934
|
+
cause
|
|
2935
|
+
});
|
|
2936
|
+
}
|
|
2937
|
+
if (!response.ok) {
|
|
2938
|
+
const detail = await readErrorDetail2(response);
|
|
2939
|
+
const kind = response.status === 401 || response.status === 403 ? "auth" : response.status === 429 ? "rate_limit" : "http";
|
|
2940
|
+
throw gatewayError(kind, `Ollama replied with HTTP ${response.status}${detail}`, {
|
|
2941
|
+
provider: PROVIDER4,
|
|
2942
|
+
status: response.status
|
|
2943
|
+
});
|
|
2944
|
+
}
|
|
2945
|
+
if (response.body === null) {
|
|
2946
|
+
throw gatewayError("transport", "the Ollama response carried no body to stream", {
|
|
2947
|
+
provider: PROVIDER4,
|
|
2948
|
+
status: response.status
|
|
2949
|
+
});
|
|
2950
|
+
}
|
|
2951
|
+
return response;
|
|
2952
|
+
}
|
|
2953
|
+
async function readErrorDetail2(response) {
|
|
2954
|
+
try {
|
|
2955
|
+
const text = await response.text();
|
|
2956
|
+
return text === "" ? "" : `: ${text.slice(0, 500)}`;
|
|
2957
|
+
} catch {
|
|
2958
|
+
return "";
|
|
2959
|
+
}
|
|
2960
|
+
}
|
|
2961
|
+
function mapDoneReason(reason) {
|
|
2962
|
+
switch (reason) {
|
|
2963
|
+
case "stop":
|
|
2964
|
+
return "complete";
|
|
2965
|
+
case "length":
|
|
2966
|
+
return "max_output";
|
|
2967
|
+
case void 0:
|
|
2968
|
+
case "":
|
|
2969
|
+
return void 0;
|
|
2970
|
+
default:
|
|
2971
|
+
return "complete";
|
|
2972
|
+
}
|
|
2973
|
+
}
|
|
2974
|
+
function readUsage4(line) {
|
|
2975
|
+
const inputTokens = readNumber5(line, "prompt_eval_count");
|
|
2976
|
+
const outputTokens = readNumber5(line, "eval_count");
|
|
2977
|
+
if (inputTokens === void 0 && outputTokens === void 0) {
|
|
2978
|
+
return void 0;
|
|
2979
|
+
}
|
|
2980
|
+
return {
|
|
2981
|
+
inputTokens: inputTokens ?? 0,
|
|
2982
|
+
outputTokens: outputTokens ?? 0
|
|
2983
|
+
};
|
|
2984
|
+
}
|
|
2985
|
+
function serializeArgs3(args) {
|
|
2986
|
+
if (typeof args === "string") {
|
|
2987
|
+
return args;
|
|
2988
|
+
}
|
|
2989
|
+
try {
|
|
2990
|
+
return JSON.stringify(args ?? {});
|
|
2991
|
+
} catch {
|
|
2992
|
+
return "{}";
|
|
2993
|
+
}
|
|
2994
|
+
}
|
|
2995
|
+
function* emitToolCalls(toolCalls, tracker) {
|
|
2996
|
+
for (const entry of toolCalls) {
|
|
2997
|
+
if (!isObject6(entry)) {
|
|
2998
|
+
continue;
|
|
2999
|
+
}
|
|
3000
|
+
const fn = entry.function;
|
|
3001
|
+
if (!isObject6(fn)) {
|
|
3002
|
+
continue;
|
|
3003
|
+
}
|
|
3004
|
+
const name = readString5(fn, "name") ?? "";
|
|
3005
|
+
const id = `ollama_call_${tracker.next}`;
|
|
3006
|
+
tracker.next += 1;
|
|
3007
|
+
yield { kind: "tool_call_start", id, name };
|
|
3008
|
+
const args = "arguments" in fn ? fn.arguments : {};
|
|
3009
|
+
yield { kind: "tool_call_delta", id, argsDelta: serializeArgs3(args) };
|
|
3010
|
+
}
|
|
3011
|
+
}
|
|
3012
|
+
function* emitFromLine(line, tracker) {
|
|
3013
|
+
const message = line.message;
|
|
3014
|
+
if (isObject6(message)) {
|
|
3015
|
+
const content = readString5(message, "content");
|
|
3016
|
+
if (content !== void 0 && content !== "") {
|
|
3017
|
+
yield { kind: "text", delta: content };
|
|
3018
|
+
}
|
|
3019
|
+
const toolCalls = message.tool_calls;
|
|
3020
|
+
if (Array.isArray(toolCalls)) {
|
|
3021
|
+
yield* emitToolCalls(toolCalls, tracker);
|
|
3022
|
+
}
|
|
3023
|
+
}
|
|
3024
|
+
if (line.done === true) {
|
|
3025
|
+
const usage = readUsage4(line);
|
|
3026
|
+
if (usage !== void 0) {
|
|
3027
|
+
yield { kind: "usage", usage };
|
|
3028
|
+
}
|
|
3029
|
+
const stop = mapDoneReason(readString5(line, "done_reason"));
|
|
3030
|
+
if (stop !== void 0) {
|
|
3031
|
+
yield { kind: "stop", stop };
|
|
3032
|
+
}
|
|
3033
|
+
}
|
|
3034
|
+
}
|
|
3035
|
+
function createollamaConnector(deps2) {
|
|
3036
|
+
const { resolveSecret: resolveSecret2 } = deps2;
|
|
3037
|
+
return {
|
|
3038
|
+
id: "ollama",
|
|
3039
|
+
api: "ollama",
|
|
3040
|
+
stream(model, conversation, options) {
|
|
3041
|
+
return channelOf(async function* run() {
|
|
3042
|
+
const collected = [];
|
|
3043
|
+
try {
|
|
3044
|
+
const secret = await resolveSecret2(PROVIDER4, options.apiKey);
|
|
3045
|
+
const url = chatEndpoint(model);
|
|
3046
|
+
const headers = buildHeaders(secret);
|
|
3047
|
+
const body = buildRequestBody2(model, conversation, options);
|
|
3048
|
+
const response = await openStream2(url, headers, body, options.signal);
|
|
3049
|
+
const wire = response.body;
|
|
3050
|
+
const tracker = { next: 0 };
|
|
3051
|
+
for await (const value of ndjsonLines(wire, options.signal)) {
|
|
3052
|
+
if (!isObject6(value)) {
|
|
3053
|
+
continue;
|
|
3054
|
+
}
|
|
3055
|
+
for (const emission of emitFromLine(value, tracker)) {
|
|
3056
|
+
collected.push(emission);
|
|
3057
|
+
yield emission;
|
|
3058
|
+
}
|
|
3059
|
+
if (value.done === true) {
|
|
3060
|
+
break;
|
|
3061
|
+
}
|
|
3062
|
+
}
|
|
3063
|
+
const reply = foldReply(model.id, collected);
|
|
3064
|
+
yield { kind: "done", reply };
|
|
3065
|
+
} catch (cause) {
|
|
3066
|
+
const error = cause instanceof Error && cause.name === "GatewayError" ? cause : gatewayError("transport", "the Ollama stream failed", { provider: PROVIDER4, cause });
|
|
3067
|
+
yield { kind: "error", error };
|
|
3068
|
+
}
|
|
3069
|
+
});
|
|
3070
|
+
},
|
|
3071
|
+
complete(model, conversation, options) {
|
|
3072
|
+
return collectReply(this.stream(model, conversation, options));
|
|
3073
|
+
}
|
|
3074
|
+
};
|
|
3075
|
+
}
|
|
3076
|
+
|
|
3077
|
+
// src/llmgateway/connectors/mock.ts
|
|
3078
|
+
var ECHO_CALL_ID = "mock_call_0";
|
|
3079
|
+
var SCRIPTED_USAGE = {
|
|
3080
|
+
inputTokens: 8,
|
|
3081
|
+
outputTokens: 5
|
|
3082
|
+
};
|
|
3083
|
+
function scriptedDeltas() {
|
|
3084
|
+
return [
|
|
3085
|
+
{ kind: "text", delta: "Hello" },
|
|
3086
|
+
{ kind: "text", delta: " world" },
|
|
3087
|
+
{ kind: "tool_call_start", id: ECHO_CALL_ID, name: "echo" },
|
|
3088
|
+
{ kind: "tool_call_delta", id: ECHO_CALL_ID, argsDelta: '{"msg":"hi"}' },
|
|
3089
|
+
{ kind: "usage", usage: { ...SCRIPTED_USAGE } },
|
|
3090
|
+
{ kind: "stop", stop: "tool_calls" }
|
|
3091
|
+
];
|
|
3092
|
+
}
|
|
3093
|
+
function finalDeltas() {
|
|
3094
|
+
return [
|
|
3095
|
+
{ kind: "text", delta: "Hello world" },
|
|
3096
|
+
{ kind: "usage", usage: { ...SCRIPTED_USAGE } },
|
|
3097
|
+
{ kind: "stop", stop: "complete" }
|
|
3098
|
+
];
|
|
3099
|
+
}
|
|
3100
|
+
function hasToolResult(conversation) {
|
|
3101
|
+
return conversation.turns.some((turn) => turn.blocks.some((block) => block.kind === "tool_result"));
|
|
3102
|
+
}
|
|
3103
|
+
function echoOffered(conversation) {
|
|
3104
|
+
return (conversation.tools ?? []).some((tool) => tool.name === "echo");
|
|
3105
|
+
}
|
|
3106
|
+
function pickDeltas(conversation) {
|
|
3107
|
+
return !hasToolResult(conversation) && echoOffered(conversation) ? scriptedDeltas() : finalDeltas();
|
|
3108
|
+
}
|
|
3109
|
+
var MockConnector = class {
|
|
3110
|
+
id = "mock";
|
|
3111
|
+
api = "mock";
|
|
3112
|
+
// The resolver is accepted for factory symmetry with the live connectors; the
|
|
3113
|
+
// mock dialect needs no credential, so it is intentionally not retained.
|
|
3114
|
+
constructor(_deps) {
|
|
3115
|
+
}
|
|
3116
|
+
stream(model, conversation, options) {
|
|
3117
|
+
const isAborted = () => options.signal?.aborted ?? false;
|
|
3118
|
+
const deltas = pickDeltas(conversation);
|
|
3119
|
+
return channelOf(async function* run() {
|
|
3120
|
+
if (isAborted()) {
|
|
3121
|
+
yield abortedDone(model.id);
|
|
3122
|
+
return;
|
|
3123
|
+
}
|
|
3124
|
+
for (const delta of deltas) {
|
|
3125
|
+
if (isAborted()) {
|
|
3126
|
+
yield abortedDone(model.id);
|
|
3127
|
+
return;
|
|
3128
|
+
}
|
|
3129
|
+
yield delta;
|
|
3130
|
+
}
|
|
3131
|
+
yield { kind: "done", reply: foldReply(model.id, deltas) };
|
|
3132
|
+
});
|
|
3133
|
+
}
|
|
3134
|
+
async complete(model, conversation, options) {
|
|
3135
|
+
return collectReply(this.stream(model, conversation, options));
|
|
3136
|
+
}
|
|
3137
|
+
};
|
|
3138
|
+
function abortedDone(modelId) {
|
|
3139
|
+
const reply = {
|
|
3140
|
+
role: "assistant",
|
|
3141
|
+
model: modelId,
|
|
3142
|
+
blocks: [],
|
|
3143
|
+
usage: { inputTokens: 0, outputTokens: 0 },
|
|
3144
|
+
stop: "aborted"
|
|
3145
|
+
};
|
|
3146
|
+
return { kind: "done", reply };
|
|
3147
|
+
}
|
|
3148
|
+
function createmockConnector(deps2) {
|
|
3149
|
+
return new MockConnector(deps2);
|
|
3150
|
+
}
|
|
3151
|
+
|
|
3152
|
+
// src/llmgateway/connectors/index.ts
|
|
3153
|
+
var deps = { resolveSecret };
|
|
3154
|
+
var CONNECTOR_REGISTRY = {
|
|
3155
|
+
"anthropic-messages": createanthropicConnector(deps),
|
|
3156
|
+
"openai-completions": createopenaichatConnector(deps),
|
|
3157
|
+
"openai-responses": createopenairesponsesConnector(deps),
|
|
3158
|
+
"google-generative": creategoogleConnector(deps),
|
|
3159
|
+
"google-vertex": creategooglevertexConnector(deps),
|
|
3160
|
+
"amazon-bedrock": createbedrockConnector(deps),
|
|
3161
|
+
"azure-openai": createazureopenaiConnector(deps),
|
|
3162
|
+
"nvidia-openai-compatible": createnvidiaConnector(deps),
|
|
3163
|
+
"kimi-openai-compatible": createkimiConnector(deps),
|
|
3164
|
+
ollama: createollamaConnector(deps),
|
|
3165
|
+
mock: createmockConnector(deps)
|
|
3166
|
+
};
|
|
3167
|
+
function connectorForApi(api) {
|
|
3168
|
+
return CONNECTOR_REGISTRY[api];
|
|
3169
|
+
}
|
|
3170
|
+
|
|
3171
|
+
// src/llmgateway/gateway.ts
|
|
3172
|
+
var NO_OPTIONS = {};
|
|
3173
|
+
function stream(modelId, conversation, options) {
|
|
3174
|
+
const card = getCard(modelId);
|
|
3175
|
+
if (card === void 0) {
|
|
3176
|
+
throw gatewayError("unsupported", `unknown model: ${modelId}`);
|
|
3177
|
+
}
|
|
3178
|
+
return streamWithCard(card, conversation, options);
|
|
3179
|
+
}
|
|
3180
|
+
function streamWithCard(card, conversation, options) {
|
|
3181
|
+
const connector = connectorForApi(card.api);
|
|
3182
|
+
return connector.stream(card, conversation, options ?? NO_OPTIONS);
|
|
3183
|
+
}
|
|
3184
|
+
function complete(modelId, conversation, options) {
|
|
3185
|
+
const card = getCard(modelId);
|
|
3186
|
+
if (card === void 0) {
|
|
3187
|
+
throw gatewayError("unsupported", `unknown model: ${modelId}`);
|
|
3188
|
+
}
|
|
3189
|
+
return completeWithCard(card, conversation, options);
|
|
3190
|
+
}
|
|
3191
|
+
function completeWithCard(card, conversation, options) {
|
|
3192
|
+
const connector = connectorForApi(card.api);
|
|
3193
|
+
return connector.complete(card, conversation, options ?? NO_OPTIONS);
|
|
3194
|
+
}
|
|
3195
|
+
export {
|
|
3196
|
+
CONNECTOR_REGISTRY,
|
|
3197
|
+
CardSelection,
|
|
3198
|
+
GatewayError,
|
|
3199
|
+
MODEL_CARDS,
|
|
3200
|
+
complete,
|
|
3201
|
+
completeWithCard,
|
|
3202
|
+
connectorForApi,
|
|
3203
|
+
estimateCost,
|
|
3204
|
+
gatewayError,
|
|
3205
|
+
getCard,
|
|
3206
|
+
models,
|
|
3207
|
+
stream,
|
|
3208
|
+
streamWithCard
|
|
3209
|
+
};
|