attocode 0.1.0
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 +48 -0
- package/LICENSE +21 -0
- package/README.md +164 -0
- package/dist/src/adapters.d.ts +83 -0
- package/dist/src/adapters.d.ts.map +1 -0
- package/dist/src/adapters.js +221 -0
- package/dist/src/adapters.js.map +1 -0
- package/dist/src/agent-tools/index.d.ts +7 -0
- package/dist/src/agent-tools/index.d.ts.map +1 -0
- package/dist/src/agent-tools/index.js +8 -0
- package/dist/src/agent-tools/index.js.map +1 -0
- package/dist/src/agent-tools/lsp-file-tools.d.ts +33 -0
- package/dist/src/agent-tools/lsp-file-tools.d.ts.map +1 -0
- package/dist/src/agent-tools/lsp-file-tools.js +200 -0
- package/dist/src/agent-tools/lsp-file-tools.js.map +1 -0
- package/dist/src/agent.d.ts +667 -0
- package/dist/src/agent.d.ts.map +1 -0
- package/dist/src/agent.js +2824 -0
- package/dist/src/agent.js.map +1 -0
- package/dist/src/cli.d.ts +36 -0
- package/dist/src/cli.d.ts.map +1 -0
- package/dist/src/cli.js +176 -0
- package/dist/src/cli.js.map +1 -0
- package/dist/src/commands/handler.d.ts +22 -0
- package/dist/src/commands/handler.d.ts.map +1 -0
- package/dist/src/commands/handler.js +1320 -0
- package/dist/src/commands/handler.js.map +1 -0
- package/dist/src/commands/init.d.ts +7 -0
- package/dist/src/commands/init.d.ts.map +1 -0
- package/dist/src/commands/init.js +153 -0
- package/dist/src/commands/init.js.map +1 -0
- package/dist/src/commands/types.d.ts +70 -0
- package/dist/src/commands/types.d.ts.map +1 -0
- package/dist/src/commands/types.js +8 -0
- package/dist/src/commands/types.js.map +1 -0
- package/dist/src/config.d.ts +22 -0
- package/dist/src/config.d.ts.map +1 -0
- package/dist/src/config.js +25 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/core/index.d.ts +32 -0
- package/dist/src/core/index.d.ts.map +1 -0
- package/dist/src/core/index.js +35 -0
- package/dist/src/core/index.js.map +1 -0
- package/dist/src/core/process-handlers.d.ts +43 -0
- package/dist/src/core/process-handlers.d.ts.map +1 -0
- package/dist/src/core/process-handlers.js +117 -0
- package/dist/src/core/process-handlers.js.map +1 -0
- package/dist/src/core/protocol/bridge.d.ts +117 -0
- package/dist/src/core/protocol/bridge.d.ts.map +1 -0
- package/dist/src/core/protocol/bridge.js +149 -0
- package/dist/src/core/protocol/bridge.js.map +1 -0
- package/dist/src/core/protocol/index.d.ts +8 -0
- package/dist/src/core/protocol/index.d.ts.map +1 -0
- package/dist/src/core/protocol/index.js +8 -0
- package/dist/src/core/protocol/index.js.map +1 -0
- package/dist/src/core/protocol/types.d.ts +539 -0
- package/dist/src/core/protocol/types.d.ts.map +1 -0
- package/dist/src/core/protocol/types.js +149 -0
- package/dist/src/core/protocol/types.js.map +1 -0
- package/dist/src/core/queues/atomic-counter.d.ts +36 -0
- package/dist/src/core/queues/atomic-counter.d.ts.map +1 -0
- package/dist/src/core/queues/atomic-counter.js +46 -0
- package/dist/src/core/queues/atomic-counter.js.map +1 -0
- package/dist/src/core/queues/event-queue.d.ts +126 -0
- package/dist/src/core/queues/event-queue.d.ts.map +1 -0
- package/dist/src/core/queues/event-queue.js +208 -0
- package/dist/src/core/queues/event-queue.js.map +1 -0
- package/dist/src/core/queues/index.d.ts +12 -0
- package/dist/src/core/queues/index.d.ts.map +1 -0
- package/dist/src/core/queues/index.js +15 -0
- package/dist/src/core/queues/index.js.map +1 -0
- package/dist/src/core/queues/submission-queue.d.ts +116 -0
- package/dist/src/core/queues/submission-queue.d.ts.map +1 -0
- package/dist/src/core/queues/submission-queue.js +236 -0
- package/dist/src/core/queues/submission-queue.js.map +1 -0
- package/dist/src/costs/index.d.ts +22 -0
- package/dist/src/costs/index.d.ts.map +1 -0
- package/dist/src/costs/index.js +22 -0
- package/dist/src/costs/index.js.map +1 -0
- package/dist/src/costs/model-registry.d.ts +80 -0
- package/dist/src/costs/model-registry.d.ts.map +1 -0
- package/dist/src/costs/model-registry.js +237 -0
- package/dist/src/costs/model-registry.js.map +1 -0
- package/dist/src/costs/types.d.ts +50 -0
- package/dist/src/costs/types.d.ts.map +1 -0
- package/dist/src/costs/types.js +2 -0
- package/dist/src/costs/types.js.map +1 -0
- package/dist/src/defaults.d.ts +114 -0
- package/dist/src/defaults.d.ts.map +1 -0
- package/dist/src/defaults.js +457 -0
- package/dist/src/defaults.js.map +1 -0
- package/dist/src/first-run.d.ts +35 -0
- package/dist/src/first-run.d.ts.map +1 -0
- package/dist/src/first-run.js +94 -0
- package/dist/src/first-run.js.map +1 -0
- package/dist/src/hello.d.ts +2 -0
- package/dist/src/hello.d.ts.map +1 -0
- package/dist/src/hello.js +4 -0
- package/dist/src/hello.js.map +1 -0
- package/dist/src/integrations/agent-registry.d.ts +160 -0
- package/dist/src/integrations/agent-registry.d.ts.map +1 -0
- package/dist/src/integrations/agent-registry.js +446 -0
- package/dist/src/integrations/agent-registry.js.map +1 -0
- package/dist/src/integrations/auto-compaction.d.ts +177 -0
- package/dist/src/integrations/auto-compaction.d.ts.map +1 -0
- package/dist/src/integrations/auto-compaction.js +428 -0
- package/dist/src/integrations/auto-compaction.js.map +1 -0
- package/dist/src/integrations/cancellation.d.ts +162 -0
- package/dist/src/integrations/cancellation.d.ts.map +1 -0
- package/dist/src/integrations/cancellation.js +339 -0
- package/dist/src/integrations/cancellation.js.map +1 -0
- package/dist/src/integrations/codebase-context.d.ts +319 -0
- package/dist/src/integrations/codebase-context.d.ts.map +1 -0
- package/dist/src/integrations/codebase-context.js +816 -0
- package/dist/src/integrations/codebase-context.js.map +1 -0
- package/dist/src/integrations/compaction.d.ts +192 -0
- package/dist/src/integrations/compaction.d.ts.map +1 -0
- package/dist/src/integrations/compaction.js +376 -0
- package/dist/src/integrations/compaction.js.map +1 -0
- package/dist/src/integrations/context-engineering.d.ts +246 -0
- package/dist/src/integrations/context-engineering.d.ts.map +1 -0
- package/dist/src/integrations/context-engineering.js +394 -0
- package/dist/src/integrations/context-engineering.js.map +1 -0
- package/dist/src/integrations/diff-utils.d.ts +105 -0
- package/dist/src/integrations/diff-utils.d.ts.map +1 -0
- package/dist/src/integrations/diff-utils.js +497 -0
- package/dist/src/integrations/diff-utils.js.map +1 -0
- package/dist/src/integrations/economics.d.ts +192 -0
- package/dist/src/integrations/economics.d.ts.map +1 -0
- package/dist/src/integrations/economics.js +431 -0
- package/dist/src/integrations/economics.js.map +1 -0
- package/dist/src/integrations/execution-policy.d.ts +189 -0
- package/dist/src/integrations/execution-policy.d.ts.map +1 -0
- package/dist/src/integrations/execution-policy.js +352 -0
- package/dist/src/integrations/execution-policy.js.map +1 -0
- package/dist/src/integrations/file-change-tracker.d.ts +161 -0
- package/dist/src/integrations/file-change-tracker.d.ts.map +1 -0
- package/dist/src/integrations/file-change-tracker.js +520 -0
- package/dist/src/integrations/file-change-tracker.js.map +1 -0
- package/dist/src/integrations/hierarchical-config.d.ts +212 -0
- package/dist/src/integrations/hierarchical-config.d.ts.map +1 -0
- package/dist/src/integrations/hierarchical-config.js +484 -0
- package/dist/src/integrations/hierarchical-config.js.map +1 -0
- package/dist/src/integrations/hooks.d.ts +114 -0
- package/dist/src/integrations/hooks.d.ts.map +1 -0
- package/dist/src/integrations/hooks.js +326 -0
- package/dist/src/integrations/hooks.js.map +1 -0
- package/dist/src/integrations/ignore.d.ts +143 -0
- package/dist/src/integrations/ignore.d.ts.map +1 -0
- package/dist/src/integrations/ignore.js +417 -0
- package/dist/src/integrations/ignore.js.map +1 -0
- package/dist/src/integrations/image-renderer.d.ts +119 -0
- package/dist/src/integrations/image-renderer.d.ts.map +1 -0
- package/dist/src/integrations/image-renderer.js +306 -0
- package/dist/src/integrations/image-renderer.js.map +1 -0
- package/dist/src/integrations/index.d.ts +42 -0
- package/dist/src/integrations/index.d.ts.map +1 -0
- package/dist/src/integrations/index.js +73 -0
- package/dist/src/integrations/index.js.map +1 -0
- package/dist/src/integrations/lsp.d.ts +196 -0
- package/dist/src/integrations/lsp.d.ts.map +1 -0
- package/dist/src/integrations/lsp.js +582 -0
- package/dist/src/integrations/lsp.js.map +1 -0
- package/dist/src/integrations/mcp-client.d.ts +270 -0
- package/dist/src/integrations/mcp-client.d.ts.map +1 -0
- package/dist/src/integrations/mcp-client.js +698 -0
- package/dist/src/integrations/mcp-client.js.map +1 -0
- package/dist/src/integrations/mcp-tool-search.d.ts +77 -0
- package/dist/src/integrations/mcp-tool-search.d.ts.map +1 -0
- package/dist/src/integrations/mcp-tool-search.js +220 -0
- package/dist/src/integrations/mcp-tool-search.js.map +1 -0
- package/dist/src/integrations/memory.d.ts +108 -0
- package/dist/src/integrations/memory.d.ts.map +1 -0
- package/dist/src/integrations/memory.js +288 -0
- package/dist/src/integrations/memory.js.map +1 -0
- package/dist/src/integrations/multi-agent.d.ts +150 -0
- package/dist/src/integrations/multi-agent.d.ts.map +1 -0
- package/dist/src/integrations/multi-agent.js +306 -0
- package/dist/src/integrations/multi-agent.js.map +1 -0
- package/dist/src/integrations/observability.d.ts +162 -0
- package/dist/src/integrations/observability.d.ts.map +1 -0
- package/dist/src/integrations/observability.js +406 -0
- package/dist/src/integrations/observability.js.map +1 -0
- package/dist/src/integrations/openrouter-pricing.d.ts +42 -0
- package/dist/src/integrations/openrouter-pricing.d.ts.map +1 -0
- package/dist/src/integrations/openrouter-pricing.js +124 -0
- package/dist/src/integrations/openrouter-pricing.js.map +1 -0
- package/dist/src/integrations/pending-plan.d.ts +171 -0
- package/dist/src/integrations/pending-plan.d.ts.map +1 -0
- package/dist/src/integrations/pending-plan.js +244 -0
- package/dist/src/integrations/pending-plan.js.map +1 -0
- package/dist/src/integrations/persistence.d.ts +48 -0
- package/dist/src/integrations/persistence.d.ts.map +1 -0
- package/dist/src/integrations/persistence.js +196 -0
- package/dist/src/integrations/persistence.js.map +1 -0
- package/dist/src/integrations/planning.d.ts +96 -0
- package/dist/src/integrations/planning.d.ts.map +1 -0
- package/dist/src/integrations/planning.js +338 -0
- package/dist/src/integrations/planning.js.map +1 -0
- package/dist/src/integrations/pty-shell.d.ts +169 -0
- package/dist/src/integrations/pty-shell.d.ts.map +1 -0
- package/dist/src/integrations/pty-shell.js +367 -0
- package/dist/src/integrations/pty-shell.js.map +1 -0
- package/dist/src/integrations/react.d.ts +139 -0
- package/dist/src/integrations/react.d.ts.map +1 -0
- package/dist/src/integrations/react.js +273 -0
- package/dist/src/integrations/react.js.map +1 -0
- package/dist/src/integrations/resources.d.ts +177 -0
- package/dist/src/integrations/resources.d.ts.map +1 -0
- package/dist/src/integrations/resources.js +311 -0
- package/dist/src/integrations/resources.js.map +1 -0
- package/dist/src/integrations/result-synthesizer.d.ts +389 -0
- package/dist/src/integrations/result-synthesizer.d.ts.map +1 -0
- package/dist/src/integrations/result-synthesizer.js +951 -0
- package/dist/src/integrations/result-synthesizer.js.map +1 -0
- package/dist/src/integrations/routing.d.ts +117 -0
- package/dist/src/integrations/routing.d.ts.map +1 -0
- package/dist/src/integrations/routing.js +347 -0
- package/dist/src/integrations/routing.js.map +1 -0
- package/dist/src/integrations/rules.d.ts +131 -0
- package/dist/src/integrations/rules.d.ts.map +1 -0
- package/dist/src/integrations/rules.js +284 -0
- package/dist/src/integrations/rules.js.map +1 -0
- package/dist/src/integrations/safety.d.ts +142 -0
- package/dist/src/integrations/safety.d.ts.map +1 -0
- package/dist/src/integrations/safety.js +342 -0
- package/dist/src/integrations/safety.js.map +1 -0
- package/dist/src/integrations/sandbox/basic.d.ts +74 -0
- package/dist/src/integrations/sandbox/basic.d.ts.map +1 -0
- package/dist/src/integrations/sandbox/basic.js +310 -0
- package/dist/src/integrations/sandbox/basic.js.map +1 -0
- package/dist/src/integrations/sandbox/docker.d.ts +94 -0
- package/dist/src/integrations/sandbox/docker.d.ts.map +1 -0
- package/dist/src/integrations/sandbox/docker.js +293 -0
- package/dist/src/integrations/sandbox/docker.js.map +1 -0
- package/dist/src/integrations/sandbox/index.d.ts +182 -0
- package/dist/src/integrations/sandbox/index.d.ts.map +1 -0
- package/dist/src/integrations/sandbox/index.js +382 -0
- package/dist/src/integrations/sandbox/index.js.map +1 -0
- package/dist/src/integrations/sandbox/landlock.d.ts +59 -0
- package/dist/src/integrations/sandbox/landlock.d.ts.map +1 -0
- package/dist/src/integrations/sandbox/landlock.js +326 -0
- package/dist/src/integrations/sandbox/landlock.js.map +1 -0
- package/dist/src/integrations/sandbox/seatbelt.d.ts +68 -0
- package/dist/src/integrations/sandbox/seatbelt.d.ts.map +1 -0
- package/dist/src/integrations/sandbox/seatbelt.js +298 -0
- package/dist/src/integrations/sandbox/seatbelt.js.map +1 -0
- package/dist/src/integrations/semantic-cache.d.ts +178 -0
- package/dist/src/integrations/semantic-cache.d.ts.map +1 -0
- package/dist/src/integrations/semantic-cache.js +372 -0
- package/dist/src/integrations/semantic-cache.js.map +1 -0
- package/dist/src/integrations/session-store.d.ts +183 -0
- package/dist/src/integrations/session-store.d.ts.map +1 -0
- package/dist/src/integrations/session-store.js +345 -0
- package/dist/src/integrations/session-store.js.map +1 -0
- package/dist/src/integrations/shared-blackboard.d.ts +403 -0
- package/dist/src/integrations/shared-blackboard.d.ts.map +1 -0
- package/dist/src/integrations/shared-blackboard.js +710 -0
- package/dist/src/integrations/shared-blackboard.js.map +1 -0
- package/dist/src/integrations/skills.d.ts +171 -0
- package/dist/src/integrations/skills.d.ts.map +1 -0
- package/dist/src/integrations/skills.js +403 -0
- package/dist/src/integrations/skills.js.map +1 -0
- package/dist/src/integrations/smart-decomposer.d.ts +322 -0
- package/dist/src/integrations/smart-decomposer.d.ts.map +1 -0
- package/dist/src/integrations/smart-decomposer.js +856 -0
- package/dist/src/integrations/smart-decomposer.js.map +1 -0
- package/dist/src/integrations/sourcegraph.d.ts +169 -0
- package/dist/src/integrations/sourcegraph.d.ts.map +1 -0
- package/dist/src/integrations/sourcegraph.js +379 -0
- package/dist/src/integrations/sourcegraph.js.map +1 -0
- package/dist/src/integrations/sqlite-store.d.ts +518 -0
- package/dist/src/integrations/sqlite-store.d.ts.map +1 -0
- package/dist/src/integrations/sqlite-store.js +1423 -0
- package/dist/src/integrations/sqlite-store.js.map +1 -0
- package/dist/src/integrations/streaming.d.ts +102 -0
- package/dist/src/integrations/streaming.d.ts.map +1 -0
- package/dist/src/integrations/streaming.js +362 -0
- package/dist/src/integrations/streaming.js.map +1 -0
- package/dist/src/integrations/thread-manager.d.ts +199 -0
- package/dist/src/integrations/thread-manager.d.ts.map +1 -0
- package/dist/src/integrations/thread-manager.js +357 -0
- package/dist/src/integrations/thread-manager.js.map +1 -0
- package/dist/src/main.d.ts +26 -0
- package/dist/src/main.d.ts.map +1 -0
- package/dist/src/main.js +170 -0
- package/dist/src/main.js.map +1 -0
- package/dist/src/modes/index.d.ts +10 -0
- package/dist/src/modes/index.d.ts.map +1 -0
- package/dist/src/modes/index.js +10 -0
- package/dist/src/modes/index.js.map +1 -0
- package/dist/src/modes/repl.d.ts +19 -0
- package/dist/src/modes/repl.d.ts.map +1 -0
- package/dist/src/modes/repl.js +393 -0
- package/dist/src/modes/repl.js.map +1 -0
- package/dist/src/modes/tui.d.ts +29 -0
- package/dist/src/modes/tui.d.ts.map +1 -0
- package/dist/src/modes/tui.js +272 -0
- package/dist/src/modes/tui.js.map +1 -0
- package/dist/src/modes.d.ts +179 -0
- package/dist/src/modes.d.ts.map +1 -0
- package/dist/src/modes.js +385 -0
- package/dist/src/modes.js.map +1 -0
- package/dist/src/observability/tracer.d.ts +111 -0
- package/dist/src/observability/tracer.d.ts.map +1 -0
- package/dist/src/observability/tracer.js +300 -0
- package/dist/src/observability/tracer.js.map +1 -0
- package/dist/src/observability/types.d.ts +271 -0
- package/dist/src/observability/types.d.ts.map +1 -0
- package/dist/src/observability/types.js +24 -0
- package/dist/src/observability/types.js.map +1 -0
- package/dist/src/paths.d.ts +101 -0
- package/dist/src/paths.d.ts.map +1 -0
- package/dist/src/paths.js +148 -0
- package/dist/src/paths.js.map +1 -0
- package/dist/src/persistence/index.d.ts +38 -0
- package/dist/src/persistence/index.d.ts.map +1 -0
- package/dist/src/persistence/index.js +48 -0
- package/dist/src/persistence/index.js.map +1 -0
- package/dist/src/persistence/migrator.d.ts +135 -0
- package/dist/src/persistence/migrator.d.ts.map +1 -0
- package/dist/src/persistence/migrator.js +303 -0
- package/dist/src/persistence/migrator.js.map +1 -0
- package/dist/src/persistence/schema.d.ts +101 -0
- package/dist/src/persistence/schema.d.ts.map +1 -0
- package/dist/src/persistence/schema.js +395 -0
- package/dist/src/persistence/schema.js.map +1 -0
- package/dist/src/providers/adapters/anthropic.d.ts +20 -0
- package/dist/src/providers/adapters/anthropic.d.ts.map +1 -0
- package/dist/src/providers/adapters/anthropic.js +124 -0
- package/dist/src/providers/adapters/anthropic.js.map +1 -0
- package/dist/src/providers/adapters/mock.d.ts +25 -0
- package/dist/src/providers/adapters/mock.d.ts.map +1 -0
- package/dist/src/providers/adapters/mock.js +133 -0
- package/dist/src/providers/adapters/mock.js.map +1 -0
- package/dist/src/providers/adapters/openai.d.ts +21 -0
- package/dist/src/providers/adapters/openai.d.ts.map +1 -0
- package/dist/src/providers/adapters/openai.js +126 -0
- package/dist/src/providers/adapters/openai.js.map +1 -0
- package/dist/src/providers/adapters/openrouter.d.ts +49 -0
- package/dist/src/providers/adapters/openrouter.d.ts.map +1 -0
- package/dist/src/providers/adapters/openrouter.js +363 -0
- package/dist/src/providers/adapters/openrouter.js.map +1 -0
- package/dist/src/providers/provider.d.ts +54 -0
- package/dist/src/providers/provider.d.ts.map +1 -0
- package/dist/src/providers/provider.js +111 -0
- package/dist/src/providers/provider.js.map +1 -0
- package/dist/src/providers/resilient-fetch.d.ts +99 -0
- package/dist/src/providers/resilient-fetch.d.ts.map +1 -0
- package/dist/src/providers/resilient-fetch.js +208 -0
- package/dist/src/providers/resilient-fetch.js.map +1 -0
- package/dist/src/providers/types.d.ts +227 -0
- package/dist/src/providers/types.d.ts.map +1 -0
- package/dist/src/providers/types.js +24 -0
- package/dist/src/providers/types.js.map +1 -0
- package/dist/src/session-picker.d.ts +28 -0
- package/dist/src/session-picker.d.ts.map +1 -0
- package/dist/src/session-picker.js +256 -0
- package/dist/src/session-picker.js.map +1 -0
- package/dist/src/test-sqlite.d.ts +2 -0
- package/dist/src/test-sqlite.d.ts.map +1 -0
- package/dist/src/test-sqlite.js +114 -0
- package/dist/src/test-sqlite.js.map +1 -0
- package/dist/src/tools/agent.d.ts +44 -0
- package/dist/src/tools/agent.d.ts.map +1 -0
- package/dist/src/tools/agent.js +110 -0
- package/dist/src/tools/agent.js.map +1 -0
- package/dist/src/tools/bash.d.ts +52 -0
- package/dist/src/tools/bash.d.ts.map +1 -0
- package/dist/src/tools/bash.js +141 -0
- package/dist/src/tools/bash.js.map +1 -0
- package/dist/src/tools/file.d.ts +47 -0
- package/dist/src/tools/file.d.ts.map +1 -0
- package/dist/src/tools/file.js +263 -0
- package/dist/src/tools/file.js.map +1 -0
- package/dist/src/tools/permission.d.ts +43 -0
- package/dist/src/tools/permission.d.ts.map +1 -0
- package/dist/src/tools/permission.js +216 -0
- package/dist/src/tools/permission.js.map +1 -0
- package/dist/src/tools/registry.d.ts +63 -0
- package/dist/src/tools/registry.d.ts.map +1 -0
- package/dist/src/tools/registry.js +250 -0
- package/dist/src/tools/registry.js.map +1 -0
- package/dist/src/tools/standard.d.ts +57 -0
- package/dist/src/tools/standard.d.ts.map +1 -0
- package/dist/src/tools/standard.js +113 -0
- package/dist/src/tools/standard.js.map +1 -0
- package/dist/src/tools/types.d.ts +146 -0
- package/dist/src/tools/types.d.ts.map +1 -0
- package/dist/src/tools/types.js +28 -0
- package/dist/src/tools/types.js.map +1 -0
- package/dist/src/tools/undo.d.ts +71 -0
- package/dist/src/tools/undo.d.ts.map +1 -0
- package/dist/src/tools/undo.js +123 -0
- package/dist/src/tools/undo.js.map +1 -0
- package/dist/src/tracing/cache-boundary-tracker.d.ts +189 -0
- package/dist/src/tracing/cache-boundary-tracker.d.ts.map +1 -0
- package/dist/src/tracing/cache-boundary-tracker.js +411 -0
- package/dist/src/tracing/cache-boundary-tracker.js.map +1 -0
- package/dist/src/tracing/trace-collector.d.ts +274 -0
- package/dist/src/tracing/trace-collector.d.ts.map +1 -0
- package/dist/src/tracing/trace-collector.js +727 -0
- package/dist/src/tracing/trace-collector.js.map +1 -0
- package/dist/src/tracing/types.d.ts +657 -0
- package/dist/src/tracing/types.d.ts.map +1 -0
- package/dist/src/tracing/types.js +39 -0
- package/dist/src/tracing/types.js.map +1 -0
- package/dist/src/tricks/failure-evidence.d.ts +268 -0
- package/dist/src/tricks/failure-evidence.d.ts.map +1 -0
- package/dist/src/tricks/failure-evidence.js +544 -0
- package/dist/src/tricks/failure-evidence.js.map +1 -0
- package/dist/src/tricks/json-utils.d.ts +77 -0
- package/dist/src/tricks/json-utils.d.ts.map +1 -0
- package/dist/src/tricks/json-utils.js +247 -0
- package/dist/src/tricks/json-utils.js.map +1 -0
- package/dist/src/tricks/kv-cache-context.d.ts +227 -0
- package/dist/src/tricks/kv-cache-context.d.ts.map +1 -0
- package/dist/src/tricks/kv-cache-context.js +377 -0
- package/dist/src/tricks/kv-cache-context.js.map +1 -0
- package/dist/src/tricks/recitation.d.ts +208 -0
- package/dist/src/tricks/recitation.d.ts.map +1 -0
- package/dist/src/tricks/recitation.js +374 -0
- package/dist/src/tricks/recitation.js.map +1 -0
- package/dist/src/tricks/reversible-compaction.d.ts +251 -0
- package/dist/src/tricks/reversible-compaction.d.ts.map +1 -0
- package/dist/src/tricks/reversible-compaction.js +555 -0
- package/dist/src/tricks/reversible-compaction.js.map +1 -0
- package/dist/src/tricks/serialization-diversity.d.ts +197 -0
- package/dist/src/tricks/serialization-diversity.d.ts.map +1 -0
- package/dist/src/tricks/serialization-diversity.js +460 -0
- package/dist/src/tricks/serialization-diversity.js.map +1 -0
- package/dist/src/tui/app.d.ts +42 -0
- package/dist/src/tui/app.d.ts.map +1 -0
- package/dist/src/tui/app.js +1076 -0
- package/dist/src/tui/app.js.map +1 -0
- package/dist/src/tui/components/ApprovalDialog.d.ts +28 -0
- package/dist/src/tui/components/ApprovalDialog.d.ts.map +1 -0
- package/dist/src/tui/components/ApprovalDialog.js +59 -0
- package/dist/src/tui/components/ApprovalDialog.js.map +1 -0
- package/dist/src/tui/components/InputArea.d.ts +35 -0
- package/dist/src/tui/components/InputArea.d.ts.map +1 -0
- package/dist/src/tui/components/InputArea.js +144 -0
- package/dist/src/tui/components/InputArea.js.map +1 -0
- package/dist/src/tui/components/MessageItem.d.ts +28 -0
- package/dist/src/tui/components/MessageItem.d.ts.map +1 -0
- package/dist/src/tui/components/MessageItem.js +27 -0
- package/dist/src/tui/components/MessageItem.js.map +1 -0
- package/dist/src/tui/components/ScrollableBox.d.ts +41 -0
- package/dist/src/tui/components/ScrollableBox.d.ts.map +1 -0
- package/dist/src/tui/components/ScrollableBox.js +101 -0
- package/dist/src/tui/components/ScrollableBox.js.map +1 -0
- package/dist/src/tui/components/ToolCallItem.d.ts +33 -0
- package/dist/src/tui/components/ToolCallItem.d.ts.map +1 -0
- package/dist/src/tui/components/ToolCallItem.js +91 -0
- package/dist/src/tui/components/ToolCallItem.js.map +1 -0
- package/dist/src/tui/components/index.d.ts +13 -0
- package/dist/src/tui/components/index.d.ts.map +1 -0
- package/dist/src/tui/components/index.js +15 -0
- package/dist/src/tui/components/index.js.map +1 -0
- package/dist/src/tui/event-display.d.ts +19 -0
- package/dist/src/tui/event-display.d.ts.map +1 -0
- package/dist/src/tui/event-display.js +178 -0
- package/dist/src/tui/event-display.js.map +1 -0
- package/dist/src/tui/index.d.ts +105 -0
- package/dist/src/tui/index.d.ts.map +1 -0
- package/dist/src/tui/index.js +214 -0
- package/dist/src/tui/index.js.map +1 -0
- package/dist/src/tui/input/CommandPalette.d.ts +55 -0
- package/dist/src/tui/input/CommandPalette.d.ts.map +1 -0
- package/dist/src/tui/input/CommandPalette.js +135 -0
- package/dist/src/tui/input/CommandPalette.js.map +1 -0
- package/dist/src/tui/input/index.d.ts +7 -0
- package/dist/src/tui/input/index.d.ts.map +1 -0
- package/dist/src/tui/input/index.js +7 -0
- package/dist/src/tui/input/index.js.map +1 -0
- package/dist/src/tui/theme/index.d.ts +45 -0
- package/dist/src/tui/theme/index.d.ts.map +1 -0
- package/dist/src/tui/theme/index.js +215 -0
- package/dist/src/tui/theme/index.js.map +1 -0
- package/dist/src/tui/types.d.ts +214 -0
- package/dist/src/tui/types.d.ts.map +1 -0
- package/dist/src/tui/types.js +27 -0
- package/dist/src/tui/types.js.map +1 -0
- package/dist/src/types.d.ts +905 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +9 -0
- package/dist/src/types.js.map +1 -0
- package/package.json +89 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mock Provider
|
|
3
|
+
*
|
|
4
|
+
* A mock LLM provider for testing and demonstration.
|
|
5
|
+
* Always available as a fallback.
|
|
6
|
+
*/
|
|
7
|
+
import { registerProvider } from '../provider.js';
|
|
8
|
+
const SCENARIOS = [
|
|
9
|
+
{
|
|
10
|
+
trigger: /hello\s*world|create.*file/i,
|
|
11
|
+
responses: [
|
|
12
|
+
`I'll create a hello world file for you.
|
|
13
|
+
|
|
14
|
+
\`\`\`json
|
|
15
|
+
{ "tool": "write_file", "input": { "path": "hello.ts", "content": "console.log('Hello, World!');" } }
|
|
16
|
+
\`\`\``,
|
|
17
|
+
"I've created hello.ts with a simple Hello World program. You can run it with `npx tsx hello.ts`.",
|
|
18
|
+
],
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
trigger: /list|show.*files|what.*files/i,
|
|
22
|
+
responses: [
|
|
23
|
+
`I'll list the files in the current directory.
|
|
24
|
+
|
|
25
|
+
\`\`\`json
|
|
26
|
+
{ "tool": "list_files", "input": { "path": "." } }
|
|
27
|
+
\`\`\``,
|
|
28
|
+
"Here are the files I found in the directory.",
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
trigger: /read|show.*content|what.*in/i,
|
|
33
|
+
responses: [
|
|
34
|
+
`I'll read that file for you.
|
|
35
|
+
|
|
36
|
+
\`\`\`json
|
|
37
|
+
{ "tool": "read_file", "input": { "path": "package.json" } }
|
|
38
|
+
\`\`\``,
|
|
39
|
+
"Here are the contents of the file.",
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
trigger: /fix|debug|error/i,
|
|
44
|
+
responses: [
|
|
45
|
+
`Let me analyze the issue. First, I'll read the file.
|
|
46
|
+
|
|
47
|
+
\`\`\`json
|
|
48
|
+
{ "tool": "read_file", "input": { "path": "src/main.ts" } }
|
|
49
|
+
\`\`\``,
|
|
50
|
+
`I see the issue. Let me fix it.
|
|
51
|
+
|
|
52
|
+
\`\`\`json
|
|
53
|
+
{ "tool": "edit_file", "input": { "path": "src/main.ts", "old": "bug", "new": "fix" } }
|
|
54
|
+
\`\`\``,
|
|
55
|
+
"I've fixed the bug. The issue was caused by incorrect variable scope.",
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
];
|
|
59
|
+
// =============================================================================
|
|
60
|
+
// MOCK PROVIDER
|
|
61
|
+
// =============================================================================
|
|
62
|
+
export class MockProvider {
|
|
63
|
+
name = 'mock';
|
|
64
|
+
defaultModel = 'mock-model';
|
|
65
|
+
callCount = 0;
|
|
66
|
+
currentScenario = null;
|
|
67
|
+
scenarioIndex = 0;
|
|
68
|
+
isConfigured() {
|
|
69
|
+
return true; // Always available
|
|
70
|
+
}
|
|
71
|
+
async chat(messages, _options) {
|
|
72
|
+
// Simulate network latency
|
|
73
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
74
|
+
this.callCount++;
|
|
75
|
+
// Get the most recent user message
|
|
76
|
+
const lastUserMessage = [...messages]
|
|
77
|
+
.reverse()
|
|
78
|
+
.find(m => m.role === 'user');
|
|
79
|
+
const content = lastUserMessage?.content ?? '';
|
|
80
|
+
// Try to match a scenario
|
|
81
|
+
if (!this.currentScenario || this.scenarioIndex >= this.currentScenario.responses.length) {
|
|
82
|
+
// Find a new scenario
|
|
83
|
+
this.currentScenario = SCENARIOS.find(s => s.trigger.test(content)) ?? null;
|
|
84
|
+
this.scenarioIndex = 0;
|
|
85
|
+
}
|
|
86
|
+
let response;
|
|
87
|
+
if (this.currentScenario && this.scenarioIndex < this.currentScenario.responses.length) {
|
|
88
|
+
response = this.currentScenario.responses[this.scenarioIndex];
|
|
89
|
+
this.scenarioIndex++;
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
// Default response
|
|
93
|
+
response = `I understand. Let me help you with that.
|
|
94
|
+
|
|
95
|
+
Based on the context, here's my analysis:
|
|
96
|
+
- The task appears to be: ${content.slice(0, 50)}...
|
|
97
|
+
- I've processed the request successfully.
|
|
98
|
+
|
|
99
|
+
Is there anything specific you'd like me to clarify?`;
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
content: response,
|
|
103
|
+
stopReason: 'end_turn',
|
|
104
|
+
usage: {
|
|
105
|
+
inputTokens: content.length / 4,
|
|
106
|
+
outputTokens: response.length / 4,
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Reset the mock state for testing.
|
|
112
|
+
*/
|
|
113
|
+
reset() {
|
|
114
|
+
this.callCount = 0;
|
|
115
|
+
this.currentScenario = null;
|
|
116
|
+
this.scenarioIndex = 0;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Get the number of calls made.
|
|
120
|
+
*/
|
|
121
|
+
getCallCount() {
|
|
122
|
+
return this.callCount;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
// =============================================================================
|
|
126
|
+
// REGISTRATION
|
|
127
|
+
// =============================================================================
|
|
128
|
+
registerProvider('mock', {
|
|
129
|
+
priority: 100, // Lowest priority - only use if nothing else is configured
|
|
130
|
+
detect: () => true, // Always available
|
|
131
|
+
create: async () => new MockProvider(),
|
|
132
|
+
});
|
|
133
|
+
//# sourceMappingURL=mock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock.js","sourceRoot":"","sources":["../../../../src/providers/adapters/mock.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAWlD,MAAM,SAAS,GAAmB;IAChC;QACE,OAAO,EAAE,6BAA6B;QACtC,SAAS,EAAE;YACT;;;;OAIC;YACD,kGAAkG;SACnG;KACF;IACD;QACE,OAAO,EAAE,+BAA+B;QACxC,SAAS,EAAE;YACT;;;;OAIC;YACD,8CAA8C;SAC/C;KACF;IACD;QACE,OAAO,EAAE,8BAA8B;QACvC,SAAS,EAAE;YACT;;;;OAIC;YACD,oCAAoC;SACrC;KACF;IACD;QACE,OAAO,EAAE,kBAAkB;QAC3B,SAAS,EAAE;YACT;;;;OAIC;YACD;;;;OAIC;YACD,uEAAuE;SACxE;KACF;CACF,CAAC;AAEF,gFAAgF;AAChF,gBAAgB;AAChB,gFAAgF;AAEhF,MAAM,OAAO,YAAY;IACd,IAAI,GAAG,MAAM,CAAC;IACd,YAAY,GAAG,YAAY,CAAC;IAE7B,SAAS,GAAG,CAAC,CAAC;IACd,eAAe,GAAwB,IAAI,CAAC;IAC5C,aAAa,GAAG,CAAC,CAAC;IAE1B,YAAY;QACV,OAAO,IAAI,CAAC,CAAC,mBAAmB;IAClC,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,QAAmB,EAAE,QAAsB;QACpD,2BAA2B;QAC3B,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;QAEvD,IAAI,CAAC,SAAS,EAAE,CAAC;QAEjB,mCAAmC;QACnC,MAAM,eAAe,GAAG,CAAC,GAAG,QAAQ,CAAC;aAClC,OAAO,EAAE;aACT,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC;QAEhC,MAAM,OAAO,GAAG,eAAe,EAAE,OA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AgF;AAChF,eAAe;AACf,gFAAgF;AAEhF,gBAAgB,CAAC,MAAM,EAAE;IACvB,QAAQ,EAAE,GAAG,EAAE,2DAA2D;IAC1E,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,mBAAmB;IACvC,MAAM,EAAE,KAAK,IAAI,EAAE,CAAC,IAAI,YAAY,EAAE;CACvC,CAAC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI Provider Adapter
|
|
3
|
+
*
|
|
4
|
+
* Adapts the OpenAI API to our LLMProvider interface.
|
|
5
|
+
*/
|
|
6
|
+
import type { LLMProvider, Message, ChatOptions, ChatResponse, OpenAIConfig } from '../types.js';
|
|
7
|
+
export declare class OpenAIProvider implements LLMProvider {
|
|
8
|
+
readonly name = "openai";
|
|
9
|
+
readonly defaultModel = "gpt-4-turbo-preview";
|
|
10
|
+
private apiKey;
|
|
11
|
+
private model;
|
|
12
|
+
private baseUrl;
|
|
13
|
+
private organization?;
|
|
14
|
+
private networkConfig;
|
|
15
|
+
constructor(config?: OpenAIConfig);
|
|
16
|
+
isConfigured(): boolean;
|
|
17
|
+
chat(messages: Message[], options?: ChatOptions): Promise<ChatResponse>;
|
|
18
|
+
private handleError;
|
|
19
|
+
private mapStopReason;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=openai.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../../../src/providers/adapters/openai.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,OAAO,EACP,WAAW,EACX,YAAY,EACZ,YAAY,EACb,MAAM,aAAa,CAAC;AASrB,qBAAa,cAAe,YAAW,WAAW;IAChD,QAAQ,CAAC,IAAI,YAAY;IACzB,QAAQ,CAAC,YAAY,yBAAyB;IAE9C,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,YAAY,CAAC,CAAS;IAC9B,OAAO,CAAC,aAAa,CAAgB;gBAEzB,MAAM,CAAC,EAAE,YAAY;IAYjC,YAAY,IAAI,OAAO;IAIjB,IAAI,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IA+E7E,OAAO,CAAC,WAAW;IAqBnB,OAAO,CAAC,aAAa;CAQtB"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI Provider Adapter
|
|
3
|
+
*
|
|
4
|
+
* Adapts the OpenAI API to our LLMProvider interface.
|
|
5
|
+
*/
|
|
6
|
+
import { ProviderError } from '../types.js';
|
|
7
|
+
import { registerProvider, hasEnv, requireEnv } from '../provider.js';
|
|
8
|
+
import { resilientFetch } from '../resilient-fetch.js';
|
|
9
|
+
// =============================================================================
|
|
10
|
+
// OPENAI PROVIDER
|
|
11
|
+
// =============================================================================
|
|
12
|
+
export class OpenAIProvider {
|
|
13
|
+
name = 'openai';
|
|
14
|
+
defaultModel = 'gpt-4-turbo-preview';
|
|
15
|
+
apiKey;
|
|
16
|
+
model;
|
|
17
|
+
baseUrl;
|
|
18
|
+
organization;
|
|
19
|
+
networkConfig;
|
|
20
|
+
constructor(config) {
|
|
21
|
+
this.apiKey = config?.apiKey ?? requireEnv('OPENAI_API_KEY');
|
|
22
|
+
this.model = config?.model ?? this.defaultModel;
|
|
23
|
+
this.baseUrl = config?.baseUrl ?? 'https://api.openai.com';
|
|
24
|
+
this.organization = config?.organization ?? process.env.OPENAI_ORG_ID;
|
|
25
|
+
this.networkConfig = {
|
|
26
|
+
timeout: 120000, // 2 minutes
|
|
27
|
+
maxRetries: 3,
|
|
28
|
+
baseRetryDelay: 1000,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
isConfigured() {
|
|
32
|
+
return hasEnv('OPENAI_API_KEY');
|
|
33
|
+
}
|
|
34
|
+
async chat(messages, options) {
|
|
35
|
+
const model = options?.model ?? this.model;
|
|
36
|
+
// OpenAI uses the same message format, just need to type it correctly
|
|
37
|
+
const openaiMessages = messages.map(m => ({
|
|
38
|
+
role: m.role,
|
|
39
|
+
content: m.content,
|
|
40
|
+
}));
|
|
41
|
+
// Build request body
|
|
42
|
+
const body = {
|
|
43
|
+
model,
|
|
44
|
+
messages: openaiMessages,
|
|
45
|
+
max_tokens: options?.maxTokens ?? 4096,
|
|
46
|
+
temperature: options?.temperature ?? 0.7,
|
|
47
|
+
...(options?.stopSequences && { stop: options.stopSequences }),
|
|
48
|
+
};
|
|
49
|
+
const headers = {
|
|
50
|
+
'Content-Type': 'application/json',
|
|
51
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
52
|
+
};
|
|
53
|
+
if (this.organization) {
|
|
54
|
+
headers['OpenAI-Organization'] = this.organization;
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
const { response } = await resilientFetch({
|
|
58
|
+
url: `${this.baseUrl}/v1/chat/completions`,
|
|
59
|
+
init: {
|
|
60
|
+
method: 'POST',
|
|
61
|
+
headers,
|
|
62
|
+
body: JSON.stringify(body),
|
|
63
|
+
},
|
|
64
|
+
providerName: this.name,
|
|
65
|
+
networkConfig: this.networkConfig,
|
|
66
|
+
onRetry: (attempt, delay, error) => {
|
|
67
|
+
console.warn(`[OpenAI] Retry attempt ${attempt} after ${delay}ms: ${error.message}`);
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
if (!response.ok) {
|
|
71
|
+
const error = await response.text();
|
|
72
|
+
throw this.handleError(response.status, error);
|
|
73
|
+
}
|
|
74
|
+
const data = await response.json();
|
|
75
|
+
const choice = data.choices[0];
|
|
76
|
+
return {
|
|
77
|
+
content: choice.message.content,
|
|
78
|
+
stopReason: this.mapStopReason(choice.finish_reason),
|
|
79
|
+
usage: {
|
|
80
|
+
inputTokens: data.usage.prompt_tokens,
|
|
81
|
+
outputTokens: data.usage.completion_tokens,
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
if (error instanceof ProviderError)
|
|
87
|
+
throw error;
|
|
88
|
+
throw new ProviderError(`OpenAI request failed: ${error.message}`, this.name, 'NETWORK_ERROR', error);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
handleError(status, body) {
|
|
92
|
+
let code = 'UNKNOWN';
|
|
93
|
+
if (status === 401)
|
|
94
|
+
code = 'AUTHENTICATION_FAILED';
|
|
95
|
+
else if (status === 429)
|
|
96
|
+
code = 'RATE_LIMITED';
|
|
97
|
+
else if (status === 400) {
|
|
98
|
+
if (body.includes('context_length')) {
|
|
99
|
+
code = 'CONTEXT_LENGTH_EXCEEDED';
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
code = 'INVALID_REQUEST';
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
else if (status >= 500)
|
|
106
|
+
code = 'SERVER_ERROR';
|
|
107
|
+
return new ProviderError(`OpenAI API error (${status}): ${body}`, this.name, code);
|
|
108
|
+
}
|
|
109
|
+
mapStopReason(reason) {
|
|
110
|
+
switch (reason) {
|
|
111
|
+
case 'stop': return 'end_turn';
|
|
112
|
+
case 'length': return 'max_tokens';
|
|
113
|
+
case 'stop_sequence': return 'stop_sequence';
|
|
114
|
+
default: return 'end_turn';
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
// =============================================================================
|
|
119
|
+
// REGISTRATION
|
|
120
|
+
// =============================================================================
|
|
121
|
+
registerProvider('openai', {
|
|
122
|
+
priority: 2,
|
|
123
|
+
detect: () => hasEnv('OPENAI_API_KEY'),
|
|
124
|
+
create: async () => new OpenAIProvider(),
|
|
125
|
+
});
|
|
126
|
+
//# sourceMappingURL=openai.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai.js","sourceRoot":"","s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,MAAM,MAAM,IAAI,EAAE,EACvC,IAAI,CAAC,IAAI,EACT,IAAI,CACL,CAAC;IACJ,CAAC;IAEO,aAAa,CAAC,MAAc;QAClC,QAAQ,MAAM,EAAE,CAAC;YACf,KAAK,MAAM,CAAC,CAAC,OAAO,UAAU,CAAC;YAC/B,KAAK,QAAQ,CAAC,CAAC,OAAO,YAAY,CAAC;YACnC,KAAK,eAAe,CAAC,CAAC,OAAO,eAAe,CAAC;YAC7C,OAAO,CAAC,CAAC,OAAO,UAAU,CAAC;QAC7B,CAAC;IACH,CAAC;CACF;AAED,gFAAgF;AAChF,eAAe;AACf,gFAAgF;AAEhF,gBAAgB,CAAC,QAAQ,EAAE;IACzB,QAAQ,EAAE,CAAC;IACX,MAAM,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,gBAAgB,CAAC;IACtC,MAAM,EAAE,KAAK,IAAI,EAAE,CAAC,IAAI,cAAc,EAAE;CACzC,CAAC,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenRouter Provider Adapter
|
|
3
|
+
*
|
|
4
|
+
* Adapts the OpenRouter API (OpenAI-compatible) to our LLMProvider interface.
|
|
5
|
+
* OpenRouter provides access to 100+ models from various providers through
|
|
6
|
+
* a single API key.
|
|
7
|
+
*/
|
|
8
|
+
import type { LLMProvider, LLMProviderWithTools, Message, MessageWithContent, ChatOptions, ChatOptionsWithTools, ChatResponse, ChatResponseWithTools, OpenRouterConfig } from '../types.js';
|
|
9
|
+
export declare class OpenRouterProvider implements LLMProvider, LLMProviderWithTools {
|
|
10
|
+
readonly name = "openrouter";
|
|
11
|
+
readonly defaultModel: string;
|
|
12
|
+
private apiKey;
|
|
13
|
+
private model;
|
|
14
|
+
private baseUrl;
|
|
15
|
+
private siteUrl?;
|
|
16
|
+
private siteName?;
|
|
17
|
+
private networkConfig;
|
|
18
|
+
constructor(config?: OpenRouterConfig);
|
|
19
|
+
isConfigured(): boolean;
|
|
20
|
+
chat(messages: Message[], options?: ChatOptions): Promise<ChatResponse>;
|
|
21
|
+
/**
|
|
22
|
+
* ═══════════════════════════════════════════════════════════════════════════
|
|
23
|
+
* NATIVE TOOL USE: Why This Matters
|
|
24
|
+
* ═══════════════════════════════════════════════════════════════════════════
|
|
25
|
+
*
|
|
26
|
+
* Before (Lesson 1): Parse JSON from text response
|
|
27
|
+
* LLM returns: "I'll use the read_file tool:\n```json\n{\"path\": \"x.ts\"}\n```"
|
|
28
|
+
* We parse: Extract JSON with regex → JSON.parse → Hope it's valid
|
|
29
|
+
* Problems: Hallucinated formats, partial JSON, extra text
|
|
30
|
+
*
|
|
31
|
+
* After (Native tool use):
|
|
32
|
+
* LLM returns: { tool_calls: [{ function: { name: "read_file", arguments: "{\"path\":\"x.ts\"}" }}] }
|
|
33
|
+
* We use: Structured response → Always valid JSON → Type-safe
|
|
34
|
+
* Benefits: No parsing errors, proper function calling semantics
|
|
35
|
+
*
|
|
36
|
+
* This method enables native tool use through OpenRouter's OpenAI-compatible API.
|
|
37
|
+
* ═══════════════════════════════════════════════════════════════════════════
|
|
38
|
+
*/
|
|
39
|
+
chatWithTools(messages: (Message | MessageWithContent)[], options?: ChatOptionsWithTools): Promise<ChatResponseWithTools>;
|
|
40
|
+
/**
|
|
41
|
+
* Query the generation endpoint to get actual cost with retry.
|
|
42
|
+
* OpenRouter's generation data may not be immediately available after completion,
|
|
43
|
+
* so we retry with exponential backoff.
|
|
44
|
+
*/
|
|
45
|
+
private queryGenerationCost;
|
|
46
|
+
private handleError;
|
|
47
|
+
private mapStopReason;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=openrouter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openrouter.d.ts","sourceRoot":"","sources":["../../../../src/providers/adapters/openrouter.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,oBAAoB,EACpB,OAAO,EACP,kBAAkB,EAClB,WAAW,EACX,oBAAoB,EACpB,YAAY,EACZ,qBAAqB,EAErB,gBAAgB,EACjB,MAAM,aAAa,CAAC;AAuCrB,qBAAa,kBAAmB,YAAW,WAAW,EAAE,oBAAoB;IAC1E,QAAQ,CAAC,IAAI,gBAAgB;IAC7B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAE9B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,OAAO,CAAkC;IACjD,OAAO,CAAC,OAAO,CAAC,CAAS;IACzB,OAAO,CAAC,QAAQ,CAAC,CAAS;IAC1B,OAAO,CAAC,aAAa,CAAgB;gBAEzB,MAAM,CAAC,EAAE,gBAAgB;IAarC,YAAY,IAAI,OAAO;IAIjB,IAAI,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IA+F7E;;;;;;;;;;;;;;;;;OAiBG;IACG,aAAa,CACjB,QAAQ,EAAE,CAAC,OAAO,GAAG,kBAAkB,CAAC,EAAE,EAC1C,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,qBAAqB,CAAC;IAwKjC;;;;OAIG;YACW,mBAAmB;IA4DjC,OAAO,CAAC,WAAW;IAqBnB,OAAO,CAAC,aAAa;CAStB"}
|