@amodalai/core 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/LICENSE +21 -0
- package/dist/.last_build +0 -0
- package/dist/src/amodal-config.d.ts +194 -0
- package/dist/src/amodal-config.js +326 -0
- package/dist/src/amodal-config.js.map +1 -0
- package/dist/src/audit/audit-logger.d.ts +52 -0
- package/dist/src/audit/audit-logger.js +137 -0
- package/dist/src/audit/audit-logger.js.map +1 -0
- package/dist/src/audit/audit-outputs.d.ts +34 -0
- package/dist/src/audit/audit-outputs.js +73 -0
- package/dist/src/audit/audit-outputs.js.map +1 -0
- package/dist/src/audit/audit-redact.d.ts +14 -0
- package/dist/src/audit/audit-redact.js +55 -0
- package/dist/src/audit/audit-redact.js.map +1 -0
- package/dist/src/audit/audit-types.d.ts +122 -0
- package/dist/src/audit/audit-types.js +64 -0
- package/dist/src/audit/audit-types.js.map +1 -0
- package/dist/src/audit/index.d.ts +10 -0
- package/dist/src/audit/index.js +10 -0
- package/dist/src/audit/index.js.map +1 -0
- package/dist/src/eval/eval-cost.d.ts +33 -0
- package/dist/src/eval/eval-cost.js +73 -0
- package/dist/src/eval/eval-cost.js.map +1 -0
- package/dist/src/eval/eval-diff.d.ts +11 -0
- package/dist/src/eval/eval-diff.js +97 -0
- package/dist/src/eval/eval-diff.js.map +1 -0
- package/dist/src/eval/eval-formatter.d.ts +23 -0
- package/dist/src/eval/eval-formatter.js +221 -0
- package/dist/src/eval/eval-formatter.js.map +1 -0
- package/dist/src/eval/eval-judge.d.ts +26 -0
- package/dist/src/eval/eval-judge.js +76 -0
- package/dist/src/eval/eval-judge.js.map +1 -0
- package/dist/src/eval/eval-run-builder.d.ts +25 -0
- package/dist/src/eval/eval-run-builder.js +78 -0
- package/dist/src/eval/eval-run-builder.js.map +1 -0
- package/dist/src/eval/eval-runner.d.ts +36 -0
- package/dist/src/eval/eval-runner.js +92 -0
- package/dist/src/eval/eval-runner.js.map +1 -0
- package/dist/src/eval/eval-session-provider.d.ts +40 -0
- package/dist/src/eval/eval-session-provider.js +46 -0
- package/dist/src/eval/eval-session-provider.js.map +1 -0
- package/dist/src/eval/eval-types.d.ts +146 -0
- package/dist/src/eval/eval-types.js +7 -0
- package/dist/src/eval/eval-types.js.map +1 -0
- package/dist/src/eval/experiment-runner.d.ts +16 -0
- package/dist/src/eval/experiment-runner.js +73 -0
- package/dist/src/eval/experiment-runner.js.map +1 -0
- package/dist/src/eval/experiment-types.d.ts +56 -0
- package/dist/src/eval/experiment-types.js +7 -0
- package/dist/src/eval/experiment-types.js.map +1 -0
- package/dist/src/eval/index.d.ts +22 -0
- package/dist/src/eval/index.js +18 -0
- package/dist/src/eval/index.js.map +1 -0
- package/dist/src/eval/multi-model-runner.d.ts +42 -0
- package/dist/src/eval/multi-model-runner.js +70 -0
- package/dist/src/eval/multi-model-runner.js.map +1 -0
- package/dist/src/eval/platform-eval-client.d.ts +105 -0
- package/dist/src/eval/platform-eval-client.js +155 -0
- package/dist/src/eval/platform-eval-client.js.map +1 -0
- package/dist/src/index.d.ts +41 -0
- package/dist/src/index.js +68 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/knowledge/index.d.ts +11 -0
- package/dist/src/knowledge/index.js +12 -0
- package/dist/src/knowledge/index.js.map +1 -0
- package/dist/src/knowledge/kb-formatter.d.ts +15 -0
- package/dist/src/knowledge/kb-formatter.js +78 -0
- package/dist/src/knowledge/kb-formatter.js.map +1 -0
- package/dist/src/knowledge/kb-index.d.ts +27 -0
- package/dist/src/knowledge/kb-index.js +66 -0
- package/dist/src/knowledge/kb-index.js.map +1 -0
- package/dist/src/knowledge/kb-types.d.ts +54 -0
- package/dist/src/knowledge/kb-types.js +7 -0
- package/dist/src/knowledge/kb-types.js.map +1 -0
- package/dist/src/knowledge/knowledge-store.d.ts +56 -0
- package/dist/src/knowledge/knowledge-store.js +141 -0
- package/dist/src/knowledge/knowledge-store.js.map +1 -0
- package/dist/src/knowledge/load-knowledge.d.ts +30 -0
- package/dist/src/knowledge/load-knowledge.js +161 -0
- package/dist/src/knowledge/load-knowledge.js.map +1 -0
- package/dist/src/knowledge/propose-kb-update.d.ts +32 -0
- package/dist/src/knowledge/propose-kb-update.js +148 -0
- package/dist/src/knowledge/propose-kb-update.js.map +1 -0
- package/dist/src/knowledge/propose-knowledge.d.ts +34 -0
- package/dist/src/knowledge/propose-knowledge.js +163 -0
- package/dist/src/knowledge/propose-knowledge.js.map +1 -0
- package/dist/src/mcp/index.d.ts +7 -0
- package/dist/src/mcp/index.js +7 -0
- package/dist/src/mcp/index.js.map +1 -0
- package/dist/src/mcp/mcp-manager.d.ts +96 -0
- package/dist/src/mcp/mcp-manager.js +192 -0
- package/dist/src/mcp/mcp-manager.js.map +1 -0
- package/dist/src/packages/config-deps.d.ts +20 -0
- package/dist/src/packages/config-deps.js +77 -0
- package/dist/src/packages/config-deps.js.map +1 -0
- package/dist/src/packages/env-file.d.ts +28 -0
- package/dist/src/packages/env-file.js +143 -0
- package/dist/src/packages/env-file.js.map +1 -0
- package/dist/src/packages/frontmatter.d.ts +28 -0
- package/dist/src/packages/frontmatter.js +77 -0
- package/dist/src/packages/frontmatter.js.map +1 -0
- package/dist/src/packages/index.d.ts +16 -0
- package/dist/src/packages/index.js +17 -0
- package/dist/src/packages/index.js.map +1 -0
- package/dist/src/packages/lock-file.d.ts +35 -0
- package/dist/src/packages/lock-file.js +117 -0
- package/dist/src/packages/lock-file.js.map +1 -0
- package/dist/src/packages/manifest-reader.d.ts +19 -0
- package/dist/src/packages/manifest-reader.js +91 -0
- package/dist/src/packages/manifest-reader.js.map +1 -0
- package/dist/src/packages/merge-engine.d.ts +63 -0
- package/dist/src/packages/merge-engine.js +357 -0
- package/dist/src/packages/merge-engine.js.map +1 -0
- package/dist/src/packages/npm-context.d.ts +56 -0
- package/dist/src/packages/npm-context.js +235 -0
- package/dist/src/packages/npm-context.js.map +1 -0
- package/dist/src/packages/npm-registry.d.ts +35 -0
- package/dist/src/packages/npm-registry.js +107 -0
- package/dist/src/packages/npm-registry.js.map +1 -0
- package/dist/src/packages/package-error.d.ts +16 -0
- package/dist/src/packages/package-error.js +17 -0
- package/dist/src/packages/package-error.js.map +1 -0
- package/dist/src/packages/package-types.d.ts +477 -0
- package/dist/src/packages/package-types.js +156 -0
- package/dist/src/packages/package-types.js.map +1 -0
- package/dist/src/packages/resolver.d.ts +41 -0
- package/dist/src/packages/resolver.js +353 -0
- package/dist/src/packages/resolver.js.map +1 -0
- package/dist/src/platform/config-builder.d.ts +24 -0
- package/dist/src/platform/config-builder.js +70 -0
- package/dist/src/platform/config-builder.js.map +1 -0
- package/dist/src/platform/index.d.ts +8 -0
- package/dist/src/platform/index.js +9 -0
- package/dist/src/platform/index.js.map +1 -0
- package/dist/src/platform/platform-client.d.ts +160 -0
- package/dist/src/platform/platform-client.js +486 -0
- package/dist/src/platform/platform-client.js.map +1 -0
- package/dist/src/platform/platform-types.d.ts +81 -0
- package/dist/src/platform/platform-types.js +18 -0
- package/dist/src/platform/platform-types.js.map +1 -0
- package/dist/src/providers/content-generator/google-to-llm.d.ts +87 -0
- package/dist/src/providers/content-generator/google-to-llm.js +226 -0
- package/dist/src/providers/content-generator/google-to-llm.js.map +1 -0
- package/dist/src/providers/content-generator/index.d.ts +10 -0
- package/dist/src/providers/content-generator/index.js +9 -0
- package/dist/src/providers/content-generator/index.js.map +1 -0
- package/dist/src/providers/content-generator/llm-to-google.d.ts +59 -0
- package/dist/src/providers/content-generator/llm-to-google.js +178 -0
- package/dist/src/providers/content-generator/llm-to-google.js.map +1 -0
- package/dist/src/providers/content-generator/multi-provider-content-generator.d.ts +61 -0
- package/dist/src/providers/content-generator/multi-provider-content-generator.js +144 -0
- package/dist/src/providers/content-generator/multi-provider-content-generator.js.map +1 -0
- package/dist/src/providers/runtime/anthropic-provider.d.ts +18 -0
- package/dist/src/providers/runtime/anthropic-provider.js +253 -0
- package/dist/src/providers/runtime/anthropic-provider.js.map +1 -0
- package/dist/src/providers/runtime/azure-provider.d.ts +25 -0
- package/dist/src/providers/runtime/azure-provider.js +206 -0
- package/dist/src/providers/runtime/azure-provider.js.map +1 -0
- package/dist/src/providers/runtime/bedrock-provider.d.ts +22 -0
- package/dist/src/providers/runtime/bedrock-provider.js +276 -0
- package/dist/src/providers/runtime/bedrock-provider.js.map +1 -0
- package/dist/src/providers/runtime/failover-provider.d.ts +30 -0
- package/dist/src/providers/runtime/failover-provider.js +124 -0
- package/dist/src/providers/runtime/failover-provider.js.map +1 -0
- package/dist/src/providers/runtime/google-provider.d.ts +17 -0
- package/dist/src/providers/runtime/google-provider.js +239 -0
- package/dist/src/providers/runtime/google-provider.js.map +1 -0
- package/dist/src/providers/runtime/index.d.ts +16 -0
- package/dist/src/providers/runtime/index.js +16 -0
- package/dist/src/providers/runtime/index.js.map +1 -0
- package/dist/src/providers/runtime/openai-provider.d.ts +21 -0
- package/dist/src/providers/runtime/openai-provider.js +266 -0
- package/dist/src/providers/runtime/openai-provider.js.map +1 -0
- package/dist/src/providers/runtime/provider-errors.d.ts +39 -0
- package/dist/src/providers/runtime/provider-errors.js +50 -0
- package/dist/src/providers/runtime/provider-errors.js.map +1 -0
- package/dist/src/providers/runtime/provider-factory.d.ts +19 -0
- package/dist/src/providers/runtime/provider-factory.js +45 -0
- package/dist/src/providers/runtime/provider-factory.js.map +1 -0
- package/dist/src/providers/runtime/runtime-provider-types.d.ts +63 -0
- package/dist/src/providers/runtime/runtime-provider-types.js +7 -0
- package/dist/src/providers/runtime/runtime-provider-types.js.map +1 -0
- package/dist/src/providers/runtime/streaming-types.d.ts +40 -0
- package/dist/src/providers/runtime/streaming-types.js +7 -0
- package/dist/src/providers/runtime/streaming-types.js.map +1 -0
- package/dist/src/repo/config-schema.d.ts +238 -0
- package/dist/src/repo/config-schema.js +155 -0
- package/dist/src/repo/config-schema.js.map +1 -0
- package/dist/src/repo/connection-schemas.d.ts +449 -0
- package/dist/src/repo/connection-schemas.js +109 -0
- package/dist/src/repo/connection-schemas.js.map +1 -0
- package/dist/src/repo/connection-types.d.ts +29 -0
- package/dist/src/repo/connection-types.js +7 -0
- package/dist/src/repo/connection-types.js.map +1 -0
- package/dist/src/repo/drift-detector.d.ts +26 -0
- package/dist/src/repo/drift-detector.js +66 -0
- package/dist/src/repo/drift-detector.js.map +1 -0
- package/dist/src/repo/graphql-drift-detector.d.ts +27 -0
- package/dist/src/repo/graphql-drift-detector.js +66 -0
- package/dist/src/repo/graphql-drift-detector.js.map +1 -0
- package/dist/src/repo/graphql-parser.d.ts +30 -0
- package/dist/src/repo/graphql-parser.js +125 -0
- package/dist/src/repo/graphql-parser.js.map +1 -0
- package/dist/src/repo/graphql-surface-parser.d.ts +20 -0
- package/dist/src/repo/graphql-surface-parser.js +74 -0
- package/dist/src/repo/graphql-surface-parser.js.map +1 -0
- package/dist/src/repo/index.d.ts +30 -0
- package/dist/src/repo/index.js +29 -0
- package/dist/src/repo/index.js.map +1 -0
- package/dist/src/repo/local-reader.d.ts +10 -0
- package/dist/src/repo/local-reader.js +299 -0
- package/dist/src/repo/local-reader.js.map +1 -0
- package/dist/src/repo/openapi-parser.d.ts +35 -0
- package/dist/src/repo/openapi-parser.js +93 -0
- package/dist/src/repo/openapi-parser.js.map +1 -0
- package/dist/src/repo/parsers.d.ts +91 -0
- package/dist/src/repo/parsers.js +454 -0
- package/dist/src/repo/parsers.js.map +1 -0
- package/dist/src/repo/platform-reader.d.ts +10 -0
- package/dist/src/repo/platform-reader.js +206 -0
- package/dist/src/repo/platform-reader.js.map +1 -0
- package/dist/src/repo/repo-loader.d.ts +14 -0
- package/dist/src/repo/repo-loader.js +25 -0
- package/dist/src/repo/repo-loader.js.map +1 -0
- package/dist/src/repo/repo-types.d.ts +159 -0
- package/dist/src/repo/repo-types.js +17 -0
- package/dist/src/repo/repo-types.js.map +1 -0
- package/dist/src/repo/spec-syncer.d.ts +30 -0
- package/dist/src/repo/spec-syncer.js +85 -0
- package/dist/src/repo/spec-syncer.js.map +1 -0
- package/dist/src/repo/store-loader.d.ts +19 -0
- package/dist/src/repo/store-loader.js +94 -0
- package/dist/src/repo/store-loader.js.map +1 -0
- package/dist/src/repo/store-schemas.d.ts +313 -0
- package/dist/src/repo/store-schemas.js +103 -0
- package/dist/src/repo/store-schemas.js.map +1 -0
- package/dist/src/repo/store-tool-schema.d.ts +29 -0
- package/dist/src/repo/store-tool-schema.js +103 -0
- package/dist/src/repo/store-tool-schema.js.map +1 -0
- package/dist/src/repo/store-types.d.ts +91 -0
- package/dist/src/repo/store-types.js +7 -0
- package/dist/src/repo/store-types.js.map +1 -0
- package/dist/src/repo/surface-parser.d.ts +17 -0
- package/dist/src/repo/surface-parser.js +75 -0
- package/dist/src/repo/surface-parser.js.map +1 -0
- package/dist/src/repo/tool-loader.d.ts +33 -0
- package/dist/src/repo/tool-loader.js +240 -0
- package/dist/src/repo/tool-loader.js.map +1 -0
- package/dist/src/repo/tool-types.d.ts +205 -0
- package/dist/src/repo/tool-types.js +61 -0
- package/dist/src/repo/tool-types.js.map +1 -0
- package/dist/src/roles/index.d.ts +7 -0
- package/dist/src/roles/index.js +8 -0
- package/dist/src/roles/index.js.map +1 -0
- package/dist/src/roles/role-filter.d.ts +33 -0
- package/dist/src/roles/role-filter.js +55 -0
- package/dist/src/roles/role-filter.js.map +1 -0
- package/dist/src/roles/role-types.d.ts +76 -0
- package/dist/src/roles/role-types.js +38 -0
- package/dist/src/roles/role-types.js.map +1 -0
- package/dist/src/runtime/connection-bridge.d.ts +19 -0
- package/dist/src/runtime/connection-bridge.js +103 -0
- package/dist/src/runtime/connection-bridge.js.map +1 -0
- package/dist/src/runtime/context-compiler.d.ts +35 -0
- package/dist/src/runtime/context-compiler.js +183 -0
- package/dist/src/runtime/context-compiler.js.map +1 -0
- package/dist/src/runtime/default-prompt.d.ts +28 -0
- package/dist/src/runtime/default-prompt.js +71 -0
- package/dist/src/runtime/default-prompt.js.map +1 -0
- package/dist/src/runtime/explore-tool.d.ts +96 -0
- package/dist/src/runtime/explore-tool.js +111 -0
- package/dist/src/runtime/explore-tool.js.map +1 -0
- package/dist/src/runtime/index.d.ts +26 -0
- package/dist/src/runtime/index.js +19 -0
- package/dist/src/runtime/index.js.map +1 -0
- package/dist/src/runtime/output-pipeline.d.ts +62 -0
- package/dist/src/runtime/output-pipeline.js +69 -0
- package/dist/src/runtime/output-pipeline.js.map +1 -0
- package/dist/src/runtime/plan-mode.d.ts +39 -0
- package/dist/src/runtime/plan-mode.js +81 -0
- package/dist/src/runtime/plan-mode.js.map +1 -0
- package/dist/src/runtime/preference-client.d.ts +39 -0
- package/dist/src/runtime/preference-client.js +70 -0
- package/dist/src/runtime/preference-client.js.map +1 -0
- package/dist/src/runtime/preference-detector.d.ts +22 -0
- package/dist/src/runtime/preference-detector.js +95 -0
- package/dist/src/runtime/preference-detector.js.map +1 -0
- package/dist/src/runtime/request-integration.d.ts +18 -0
- package/dist/src/runtime/request-integration.js +36 -0
- package/dist/src/runtime/request-integration.js.map +1 -0
- package/dist/src/runtime/runtime-types.d.ts +48 -0
- package/dist/src/runtime/runtime-types.js +7 -0
- package/dist/src/runtime/runtime-types.js.map +1 -0
- package/dist/src/runtime/session-setup.d.ts +53 -0
- package/dist/src/runtime/session-setup.js +90 -0
- package/dist/src/runtime/session-setup.js.map +1 -0
- package/dist/src/runtime/telemetry-client.d.ts +39 -0
- package/dist/src/runtime/telemetry-client.js +87 -0
- package/dist/src/runtime/telemetry-client.js.map +1 -0
- package/dist/src/runtime/telemetry-hooks.d.ts +47 -0
- package/dist/src/runtime/telemetry-hooks.js +115 -0
- package/dist/src/runtime/telemetry-hooks.js.map +1 -0
- package/dist/src/runtime/token-allocator.d.ts +34 -0
- package/dist/src/runtime/token-allocator.js +86 -0
- package/dist/src/runtime/token-allocator.js.map +1 -0
- package/dist/src/runtime/user-context.d.ts +49 -0
- package/dist/src/runtime/user-context.js +135 -0
- package/dist/src/runtime/user-context.js.map +1 -0
- package/dist/src/sdk.d.ts +57 -0
- package/dist/src/sdk.js +377 -0
- package/dist/src/sdk.js.map +1 -0
- package/dist/src/security/action-gate.d.ts +23 -0
- package/dist/src/security/action-gate.js +78 -0
- package/dist/src/security/action-gate.js.map +1 -0
- package/dist/src/security/field-scrubber.d.ts +27 -0
- package/dist/src/security/field-scrubber.js +152 -0
- package/dist/src/security/field-scrubber.js.map +1 -0
- package/dist/src/security/index.d.ts +14 -0
- package/dist/src/security/index.js +15 -0
- package/dist/src/security/index.js.map +1 -0
- package/dist/src/security/leak-detector.d.ts +23 -0
- package/dist/src/security/leak-detector.js +51 -0
- package/dist/src/security/leak-detector.js.map +1 -0
- package/dist/src/security/output-guard.d.ts +33 -0
- package/dist/src/security/output-guard.js +118 -0
- package/dist/src/security/output-guard.js.map +1 -0
- package/dist/src/security/pattern-scanner.d.ts +19 -0
- package/dist/src/security/pattern-scanner.js +66 -0
- package/dist/src/security/pattern-scanner.js.map +1 -0
- package/dist/src/security/scope-checker.d.ts +27 -0
- package/dist/src/security/scope-checker.js +52 -0
- package/dist/src/security/scope-checker.js.map +1 -0
- package/dist/src/security/scrub-tracker.d.ts +21 -0
- package/dist/src/security/scrub-tracker.js +39 -0
- package/dist/src/security/scrub-tracker.js.map +1 -0
- package/dist/src/security/security-types.d.ts +69 -0
- package/dist/src/security/security-types.js +17 -0
- package/dist/src/security/security-types.js.map +1 -0
- package/dist/src/security/threshold-evaluator.d.ts +13 -0
- package/dist/src/security/threshold-evaluator.js +44 -0
- package/dist/src/security/threshold-evaluator.js.map +1 -0
- package/dist/src/snapshot/index.d.ts +8 -0
- package/dist/src/snapshot/index.js +9 -0
- package/dist/src/snapshot/index.js.map +1 -0
- package/dist/src/snapshot/snapshot-builder.d.ts +37 -0
- package/dist/src/snapshot/snapshot-builder.js +152 -0
- package/dist/src/snapshot/snapshot-builder.js.map +1 -0
- package/dist/src/snapshot/snapshot-loader.d.ts +29 -0
- package/dist/src/snapshot/snapshot-loader.js +188 -0
- package/dist/src/snapshot/snapshot-loader.js.map +1 -0
- package/dist/src/snapshot/snapshot-types.d.ts +1940 -0
- package/dist/src/snapshot/snapshot-types.js +145 -0
- package/dist/src/snapshot/snapshot-types.js.map +1 -0
- package/dist/src/stores/index.d.ts +6 -0
- package/dist/src/stores/index.js +7 -0
- package/dist/src/stores/index.js.map +1 -0
- package/dist/src/stores/store-backend.d.ts +135 -0
- package/dist/src/stores/store-backend.js +7 -0
- package/dist/src/stores/store-backend.js.map +1 -0
- package/dist/src/templates/connections.d.ts +14 -0
- package/dist/src/templates/connections.js +7 -0
- package/dist/src/templates/connections.js.map +1 -0
- package/dist/src/templates/index.d.ts +7 -0
- package/dist/src/templates/index.js +8 -0
- package/dist/src/templates/index.js.map +1 -0
- package/dist/src/templates/template-resolver.d.ts +45 -0
- package/dist/src/templates/template-resolver.js +121 -0
- package/dist/src/templates/template-resolver.js.map +1 -0
- package/dist/src/tool-context.d.ts +33 -0
- package/dist/src/tool-context.js +7 -0
- package/dist/src/tool-context.js.map +1 -0
- package/dist/src/tool-registration.d.ts +14 -0
- package/dist/src/tool-registration.js +51 -0
- package/dist/src/tool-registration.js.map +1 -0
- package/dist/src/tools/amodal-tool-errors.d.ts +24 -0
- package/dist/src/tools/amodal-tool-errors.js +28 -0
- package/dist/src/tools/amodal-tool-errors.js.map +1 -0
- package/dist/src/tools/amodal-tool-names.d.ts +14 -0
- package/dist/src/tools/amodal-tool-names.js +15 -0
- package/dist/src/tools/amodal-tool-names.js.map +1 -0
- package/dist/src/tools/chain-tool-registry.d.ts +20 -0
- package/dist/src/tools/chain-tool-registry.js +49 -0
- package/dist/src/tools/chain-tool-registry.js.map +1 -0
- package/dist/src/tools/chain-tool-types.d.ts +190 -0
- package/dist/src/tools/chain-tool-types.js +50 -0
- package/dist/src/tools/chain-tool-types.js.map +1 -0
- package/dist/src/tools/chain-tool.d.ts +34 -0
- package/dist/src/tools/chain-tool.js +294 -0
- package/dist/src/tools/chain-tool.js.map +1 -0
- package/dist/src/tools/custom-tool-registrar.d.ts +8 -0
- package/dist/src/tools/custom-tool-registrar.js +10 -0
- package/dist/src/tools/custom-tool-registrar.js.map +1 -0
- package/dist/src/tools/definitions/amodal-tools.d.ts +9 -0
- package/dist/src/tools/definitions/amodal-tools.js +192 -0
- package/dist/src/tools/definitions/amodal-tools.js.map +1 -0
- package/dist/src/tools/function-tool-registry.d.ts +22 -0
- package/dist/src/tools/function-tool-registry.js +45 -0
- package/dist/src/tools/function-tool-registry.js.map +1 -0
- package/dist/src/tools/function-tool-types.d.ts +76 -0
- package/dist/src/tools/function-tool-types.js +27 -0
- package/dist/src/tools/function-tool-types.js.map +1 -0
- package/dist/src/tools/function-tool.d.ts +34 -0
- package/dist/src/tools/function-tool.js +97 -0
- package/dist/src/tools/function-tool.js.map +1 -0
- package/dist/src/tools/http-tool-registry.d.ts +20 -0
- package/dist/src/tools/http-tool-registry.js +34 -0
- package/dist/src/tools/http-tool-registry.js.map +1 -0
- package/dist/src/tools/http-tool-types.d.ts +92 -0
- package/dist/src/tools/http-tool-types.js +44 -0
- package/dist/src/tools/http-tool-types.js.map +1 -0
- package/dist/src/tools/http-tool.d.ts +32 -0
- package/dist/src/tools/http-tool.js +176 -0
- package/dist/src/tools/http-tool.js.map +1 -0
- package/dist/src/tools/merge-template.d.ts +33 -0
- package/dist/src/tools/merge-template.js +65 -0
- package/dist/src/tools/merge-template.js.map +1 -0
- package/dist/src/tools/request-tool-types.d.ts +46 -0
- package/dist/src/tools/request-tool-types.js +20 -0
- package/dist/src/tools/request-tool-types.js.map +1 -0
- package/dist/src/tools/request-tool.d.ts +29 -0
- package/dist/src/tools/request-tool.js +268 -0
- package/dist/src/tools/request-tool.js.map +1 -0
- package/dist/src/tools/store-query-tool.d.ts +29 -0
- package/dist/src/tools/store-query-tool.js +82 -0
- package/dist/src/tools/store-query-tool.js.map +1 -0
- package/dist/src/tools/store-write-tool.d.ts +26 -0
- package/dist/src/tools/store-write-tool.js +84 -0
- package/dist/src/tools/store-write-tool.js.map +1 -0
- package/dist/src/tools/tool-definition-types.d.ts +21 -0
- package/dist/src/tools/tool-definition-types.js +7 -0
- package/dist/src/tools/tool-definition-types.js.map +1 -0
- package/dist/src/tools/tool-utils.d.ts +29 -0
- package/dist/src/tools/tool-utils.js +66 -0
- package/dist/src/tools/tool-utils.js.map +1 -0
- package/dist/src/versions/bundle-loader.d.ts +37 -0
- package/dist/src/versions/bundle-loader.js +99 -0
- package/dist/src/versions/bundle-loader.js.map +1 -0
- package/dist/src/versions/dependency-manager.d.ts +54 -0
- package/dist/src/versions/dependency-manager.js +132 -0
- package/dist/src/versions/dependency-manager.js.map +1 -0
- package/dist/src/versions/handler-loader.d.ts +27 -0
- package/dist/src/versions/handler-loader.js +62 -0
- package/dist/src/versions/handler-loader.js.map +1 -0
- package/dist/src/versions/index.d.ts +10 -0
- package/dist/src/versions/index.js +11 -0
- package/dist/src/versions/index.js.map +1 -0
- package/dist/src/versions/version-bundle-types.d.ts +1278 -0
- package/dist/src/versions/version-bundle-types.js +207 -0
- package/dist/src/versions/version-bundle-types.js.map +1 -0
- package/dist/src/versions/version-manager.d.ts +89 -0
- package/dist/src/versions/version-manager.js +124 -0
- package/dist/src/versions/version-manager.js.map +1 -0
- package/dist/src/widgets/index.d.ts +8 -0
- package/dist/src/widgets/index.js +8 -0
- package/dist/src/widgets/index.js.map +1 -0
- package/dist/src/widgets/present-tool.d.ts +21 -0
- package/dist/src/widgets/present-tool.js +107 -0
- package/dist/src/widgets/present-tool.js.map +1 -0
- package/dist/src/widgets/widget-types.d.ts +78 -0
- package/dist/src/widgets/widget-types.js +28 -0
- package/dist/src/widgets/widget-types.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +50 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Amodal Labs, Inc.
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
6
|
+
import { createRuntimeProvider } from '../runtime/provider-factory.js';
|
|
7
|
+
import { FailoverProvider } from '../runtime/failover-provider.js';
|
|
8
|
+
import { convertGenerateContentParams, normalizeContents, } from './google-to-llm.js';
|
|
9
|
+
import { convertLLMResponse, convertStreamEvent, } from './llm-to-google.js';
|
|
10
|
+
/**
|
|
11
|
+
* ContentGenerator that routes LLM calls through our RuntimeProvider system.
|
|
12
|
+
*
|
|
13
|
+
* Implements the upstream ContentGenerator interface structurally — the
|
|
14
|
+
* actual type comes from @google/gemini-cli-core which we don't import
|
|
15
|
+
* directly. The upstream Config accepts any object matching the interface.
|
|
16
|
+
*/
|
|
17
|
+
export class MultiProviderContentGenerator {
|
|
18
|
+
provider;
|
|
19
|
+
constructor(modelConfig) {
|
|
20
|
+
if (modelConfig.fallback) {
|
|
21
|
+
this.provider = new FailoverProvider(modelConfig);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
this.provider = createRuntimeProvider(modelConfig);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Non-streaming content generation.
|
|
29
|
+
*/
|
|
30
|
+
async generateContent(request, _userPromptId, _role) {
|
|
31
|
+
const llmRequest = convertGenerateContentParams(request);
|
|
32
|
+
process.stderr.write(`[MPCG] generateContent: ${String(llmRequest.tools.length)} tools, ${String(llmRequest.messages.length)} messages\n`);
|
|
33
|
+
const llmResponse = await this.provider.chat(llmRequest);
|
|
34
|
+
process.stderr.write(`[MPCG] response stopReason=${llmResponse.stopReason}, blocks=${String(llmResponse.content.length)}, types=${llmResponse.content.map(b => b.type).join(',')}\n`);
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- structural match to GenerateContentResponse class
|
|
36
|
+
return convertLLMResponse(llmResponse);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Streaming content generation.
|
|
40
|
+
*
|
|
41
|
+
* Returns an async generator that yields GenerateContentResponse chunks
|
|
42
|
+
* as our RuntimeProvider streams events.
|
|
43
|
+
*/
|
|
44
|
+
async generateContentStream(request, _userPromptId, _role) {
|
|
45
|
+
const llmRequest = convertGenerateContentParams(request);
|
|
46
|
+
process.stderr.write(`[MPCG] generateContentStream: ${String(llmRequest.tools.length)} tools, ${String(llmRequest.messages.length)} messages\n`);
|
|
47
|
+
// Debug: log raw tools from request before conversion
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Gemini SDK request config
|
|
49
|
+
const rawTools = request.config?.['tools'];
|
|
50
|
+
if (rawTools) {
|
|
51
|
+
for (const rt of rawTools) {
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Gemini SDK tool type
|
|
53
|
+
const t = rt;
|
|
54
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Gemini SDK tool declarations
|
|
55
|
+
const fds = t['functionDeclarations'];
|
|
56
|
+
if (fds) {
|
|
57
|
+
for (const fd of fds) {
|
|
58
|
+
process.stderr.write(`[MPCG] raw FD keys: ${Object.keys(fd).join(',')}\n`);
|
|
59
|
+
// Check first tool in detail
|
|
60
|
+
if (fds.indexOf(fd) === 0) {
|
|
61
|
+
process.stderr.write(`[MPCG] raw FD[0] detail: ${JSON.stringify(fd).slice(0, 300)}\n`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
for (const tool of llmRequest.tools) {
|
|
68
|
+
const params = tool.parameters;
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- debug logging
|
|
70
|
+
const req = (params['required'] ?? []);
|
|
71
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- debug logging
|
|
72
|
+
process.stderr.write(`[MPCG] converted tool: ${tool.name} | required: [${req.join(',')}] | props: [${Object.keys((params['properties'] ?? {})).join(',')}]\n`);
|
|
73
|
+
}
|
|
74
|
+
if (this.provider.chatStream) {
|
|
75
|
+
return this.streamFromProvider(llmRequest);
|
|
76
|
+
}
|
|
77
|
+
// Fallback: non-streaming chat, emit as single chunk
|
|
78
|
+
return this.fakeStream(llmRequest);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Estimate token count based on character length.
|
|
82
|
+
*
|
|
83
|
+
* Provider-specific tokenizers could be added later; for now a rough
|
|
84
|
+
* estimate (chars / 4) is sufficient since this is only used for
|
|
85
|
+
* context window overflow checks.
|
|
86
|
+
*/
|
|
87
|
+
async countTokens(request) {
|
|
88
|
+
const contents = normalizeContents(request.contents);
|
|
89
|
+
let charCount = 0;
|
|
90
|
+
for (const content of contents) {
|
|
91
|
+
for (const part of content.parts ?? []) {
|
|
92
|
+
if (typeof part.text === 'string') {
|
|
93
|
+
charCount += part.text.length;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const estimatedTokens = Math.ceil(charCount / 4);
|
|
98
|
+
return { totalTokens: estimatedTokens };
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Embeddings are not supported for non-Google providers.
|
|
102
|
+
*/
|
|
103
|
+
async embedContent(_request) {
|
|
104
|
+
throw new Error('Embeddings are not supported for non-Google providers. ' +
|
|
105
|
+
'Use a Google model or a dedicated embedding service.');
|
|
106
|
+
}
|
|
107
|
+
// -------------------------------------------------------------------------
|
|
108
|
+
// Private helpers
|
|
109
|
+
// -------------------------------------------------------------------------
|
|
110
|
+
async *streamFromProvider(request) {
|
|
111
|
+
// Track tool names from tool_use_start events so we can patch them
|
|
112
|
+
// into the complete functionCall emitted on tool_use_end.
|
|
113
|
+
const toolNameMap = new Map();
|
|
114
|
+
// chatStream is guaranteed non-null by caller check
|
|
115
|
+
for await (const event of this.provider.chatStream(request)) {
|
|
116
|
+
process.stderr.write(`[MPCG] stream event: ${event.type}${event.type === 'tool_use_start' ? ` name=${event.name}` : ''}${event.type === 'tool_use_end' ? ` id=${event.id}` : ''}\n`);
|
|
117
|
+
// Track tool names
|
|
118
|
+
if (event.type === 'tool_use_start') {
|
|
119
|
+
toolNameMap.set(event.id, event.name);
|
|
120
|
+
}
|
|
121
|
+
const chunk = convertStreamEvent(event);
|
|
122
|
+
if (chunk) {
|
|
123
|
+
// Patch the tool name into tool_use_end chunks
|
|
124
|
+
if (event.type === 'tool_use_end') {
|
|
125
|
+
const name = toolNameMap.get(event.id) ?? '';
|
|
126
|
+
const candidate = chunk.candidates?.[0];
|
|
127
|
+
const part = candidate?.content?.parts?.[0];
|
|
128
|
+
if (part?.functionCall) {
|
|
129
|
+
part.functionCall.name = name;
|
|
130
|
+
}
|
|
131
|
+
toolNameMap.delete(event.id);
|
|
132
|
+
}
|
|
133
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- structural match
|
|
134
|
+
yield chunk;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
async *fakeStream(request) {
|
|
139
|
+
const response = await this.provider.chat(request);
|
|
140
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- structural match
|
|
141
|
+
yield convertLLMResponse(response);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=multi-provider-content-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multi-provider-content-generator.js","sourceRoot":"","sources":["../../../../src/providers/content-generator/multi-provider-content-generator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAeH,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EACL,4BAA4B,EAC5B,iBAAiB,GAElB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,kBAAkB,EAClB,kBAAkB,GAEnB,MAAM,oBAAoB,CAAC;AAE5B;;;;;;GAMG;AACH,MAAM,OAAO,6BAA6B;IACvB,QAAQ,CAAkB;IAE3C,YAAY,WAAwB;QAClC,IAAI,WAAW,CAAC,QAAQ,EAAE,CAAC;YACzB,IAAI,C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AAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACnD,2FAA2F;QAC3F,MAAM,kBAAkB,CAAC,QAAQ,CAAwC,CAAC;IAC5E,CAAC;CACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Amodal Labs, Inc.
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
6
|
+
import type { ModelConfig } from '../../repo/config-schema.js';
|
|
7
|
+
import type { RuntimeProvider, LLMChatRequest, LLMChatResponse } from './runtime-provider-types.js';
|
|
8
|
+
import type { LLMStreamEvent } from './streaming-types.js';
|
|
9
|
+
/**
|
|
10
|
+
* RuntimeProvider backed by the Anthropic Messages API.
|
|
11
|
+
*/
|
|
12
|
+
export declare class AnthropicRuntimeProvider implements RuntimeProvider {
|
|
13
|
+
private readonly apiKey;
|
|
14
|
+
private readonly baseUrl?;
|
|
15
|
+
constructor(config: ModelConfig);
|
|
16
|
+
chat(request: LLMChatRequest): Promise<LLMChatResponse>;
|
|
17
|
+
chatStream(request: LLMChatRequest): AsyncGenerator<LLMStreamEvent>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Amodal Labs, Inc.
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
6
|
+
import { ProviderError, RateLimitError, ProviderTimeoutError } from './provider-errors.js';
|
|
7
|
+
/**
|
|
8
|
+
* RuntimeProvider backed by the Anthropic Messages API.
|
|
9
|
+
*/
|
|
10
|
+
export class AnthropicRuntimeProvider {
|
|
11
|
+
apiKey;
|
|
12
|
+
baseUrl;
|
|
13
|
+
constructor(config) {
|
|
14
|
+
const key = config.credentials?.['ANTHROPIC_API_KEY']
|
|
15
|
+
?? process.env['ANTHROPIC_API_KEY']
|
|
16
|
+
?? (config.baseUrl ? '' : undefined);
|
|
17
|
+
if (!key && key !== '') {
|
|
18
|
+
throw new ProviderError('ANTHROPIC_API_KEY is not set', { provider: 'anthropic' });
|
|
19
|
+
}
|
|
20
|
+
this.apiKey = key;
|
|
21
|
+
this.baseUrl = config.baseUrl;
|
|
22
|
+
}
|
|
23
|
+
async chat(request) {
|
|
24
|
+
const { default: Anthropic } = await import('@anthropic-ai/sdk');
|
|
25
|
+
const client = new Anthropic({
|
|
26
|
+
apiKey: this.apiKey,
|
|
27
|
+
...(this.baseUrl ? { baseURL: this.baseUrl } : {}),
|
|
28
|
+
});
|
|
29
|
+
const messages = convertMessages(request.messages);
|
|
30
|
+
const tools = convertTools(request.tools);
|
|
31
|
+
try {
|
|
32
|
+
const response = await client.messages.create({
|
|
33
|
+
model: request.model,
|
|
34
|
+
max_tokens: request.maxTokens ?? 4096,
|
|
35
|
+
system: request.systemPrompt,
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- SDK boundary: our AnthropicMessage[] maps to MessageParam[]
|
|
37
|
+
messages: messages,
|
|
38
|
+
...(tools.length > 0
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- SDK boundary: our AnthropicTool[] maps to ToolUnion[]
|
|
40
|
+
? { tools: tools }
|
|
41
|
+
: {}),
|
|
42
|
+
});
|
|
43
|
+
/* eslint-disable @typescript-eslint/no-unsafe-type-assertion -- SDK boundary: non-streaming response shape */
|
|
44
|
+
const msg = response;
|
|
45
|
+
/* eslint-enable @typescript-eslint/no-unsafe-type-assertion */
|
|
46
|
+
return {
|
|
47
|
+
content: convertResponseBlocks(msg.content),
|
|
48
|
+
stopReason: mapStopReason(msg.stop_reason),
|
|
49
|
+
usage: {
|
|
50
|
+
inputTokens: msg.usage.input_tokens,
|
|
51
|
+
outputTokens: msg.usage.output_tokens,
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
throw classifyError(err);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async *chatStream(request) {
|
|
60
|
+
const { default: Anthropic } = await import('@anthropic-ai/sdk');
|
|
61
|
+
const client = new Anthropic({
|
|
62
|
+
apiKey: this.apiKey,
|
|
63
|
+
...(this.baseUrl ? { baseURL: this.baseUrl } : {}),
|
|
64
|
+
});
|
|
65
|
+
const messages = convertMessages(request.messages);
|
|
66
|
+
const tools = convertTools(request.tools);
|
|
67
|
+
try {
|
|
68
|
+
/* eslint-disable @typescript-eslint/no-unsafe-type-assertion -- SDK boundary: stream events */
|
|
69
|
+
const stream = client.messages.stream({
|
|
70
|
+
model: request.model,
|
|
71
|
+
max_tokens: request.maxTokens ?? 4096,
|
|
72
|
+
system: request.systemPrompt,
|
|
73
|
+
messages: messages,
|
|
74
|
+
...(tools.length > 0
|
|
75
|
+
? { tools: tools }
|
|
76
|
+
: {}),
|
|
77
|
+
});
|
|
78
|
+
const toolInputBuffers = new Map();
|
|
79
|
+
for await (const event of stream) {
|
|
80
|
+
switch (event.type) {
|
|
81
|
+
case 'content_block_start':
|
|
82
|
+
if (event.content_block?.type === 'tool_use') {
|
|
83
|
+
const id = event.content_block.id ?? '';
|
|
84
|
+
const name = event.content_block.name ?? '';
|
|
85
|
+
toolInputBuffers.set(id, '');
|
|
86
|
+
yield { type: 'tool_use_start', id, name };
|
|
87
|
+
}
|
|
88
|
+
break;
|
|
89
|
+
case 'content_block_delta':
|
|
90
|
+
if (event.delta?.type === 'text_delta' && event.delta.text) {
|
|
91
|
+
yield { type: 'text_delta', text: event.delta.text };
|
|
92
|
+
}
|
|
93
|
+
else if (event.delta?.type === 'input_json_delta' && event.delta.partial_json) {
|
|
94
|
+
const id = findCurrentToolId(toolInputBuffers);
|
|
95
|
+
if (id) {
|
|
96
|
+
const prev = toolInputBuffers.get(id) ?? '';
|
|
97
|
+
toolInputBuffers.set(id, prev + event.delta.partial_json);
|
|
98
|
+
yield { type: 'tool_use_delta', id, inputDelta: event.delta.partial_json };
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
break;
|
|
102
|
+
case 'content_block_stop': {
|
|
103
|
+
// Find the last tool that hasn't been ended yet
|
|
104
|
+
for (const [id, jsonStr] of toolInputBuffers) {
|
|
105
|
+
let input = {};
|
|
106
|
+
try {
|
|
107
|
+
input = JSON.parse(jsonStr || '{}');
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
// Malformed — pass empty
|
|
111
|
+
}
|
|
112
|
+
yield { type: 'tool_use_end', id, input };
|
|
113
|
+
toolInputBuffers.delete(id);
|
|
114
|
+
break; // Only end one per content_block_stop
|
|
115
|
+
}
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
case 'message_delta':
|
|
119
|
+
yield {
|
|
120
|
+
type: 'message_end',
|
|
121
|
+
stopReason: mapStopReason(event.delta?.stop_reason ?? null),
|
|
122
|
+
usage: event.usage
|
|
123
|
+
? { inputTokens: event.usage.input_tokens ?? 0, outputTokens: event.usage.output_tokens ?? 0 }
|
|
124
|
+
: undefined,
|
|
125
|
+
};
|
|
126
|
+
break;
|
|
127
|
+
default:
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/* eslint-enable @typescript-eslint/no-unsafe-type-assertion */
|
|
132
|
+
}
|
|
133
|
+
catch (err) {
|
|
134
|
+
throw classifyError(err);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function findCurrentToolId(buffers) {
|
|
139
|
+
// Return the last key (most recently added tool)
|
|
140
|
+
let lastId;
|
|
141
|
+
for (const id of buffers.keys()) {
|
|
142
|
+
lastId = id;
|
|
143
|
+
}
|
|
144
|
+
return lastId;
|
|
145
|
+
}
|
|
146
|
+
function convertMessages(messages) {
|
|
147
|
+
const result = [];
|
|
148
|
+
for (const msg of messages) {
|
|
149
|
+
switch (msg.role) {
|
|
150
|
+
case 'user':
|
|
151
|
+
result.push({ role: 'user', content: msg.content });
|
|
152
|
+
break;
|
|
153
|
+
case 'assistant':
|
|
154
|
+
result.push({
|
|
155
|
+
role: 'assistant',
|
|
156
|
+
content: msg.content.map((block) => {
|
|
157
|
+
if (block.type === 'text') {
|
|
158
|
+
return { type: 'text', text: block.text };
|
|
159
|
+
}
|
|
160
|
+
return {
|
|
161
|
+
type: 'tool_use',
|
|
162
|
+
id: block.id,
|
|
163
|
+
name: block.name,
|
|
164
|
+
input: block.input,
|
|
165
|
+
};
|
|
166
|
+
}),
|
|
167
|
+
});
|
|
168
|
+
break;
|
|
169
|
+
case 'tool_result':
|
|
170
|
+
// Anthropic requires tool results inside a user message
|
|
171
|
+
result.push({
|
|
172
|
+
role: 'user',
|
|
173
|
+
content: [
|
|
174
|
+
{
|
|
175
|
+
type: 'tool_result',
|
|
176
|
+
tool_use_id: msg.toolCallId,
|
|
177
|
+
content: msg.content,
|
|
178
|
+
...(msg.isError ? { is_error: true } : {}),
|
|
179
|
+
},
|
|
180
|
+
],
|
|
181
|
+
});
|
|
182
|
+
break;
|
|
183
|
+
default:
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return result;
|
|
188
|
+
}
|
|
189
|
+
function convertTools(tools) {
|
|
190
|
+
return tools.map((t) => ({
|
|
191
|
+
name: t.name,
|
|
192
|
+
description: t.description,
|
|
193
|
+
input_schema: t.parameters,
|
|
194
|
+
}));
|
|
195
|
+
}
|
|
196
|
+
function convertResponseBlocks(blocks) {
|
|
197
|
+
const result = [];
|
|
198
|
+
for (const block of blocks) {
|
|
199
|
+
if (block.type === 'text' && block.text !== undefined) {
|
|
200
|
+
result.push({ type: 'text', text: block.text });
|
|
201
|
+
}
|
|
202
|
+
else if (block.type === 'tool_use' && block.id && block.name) {
|
|
203
|
+
result.push({
|
|
204
|
+
type: 'tool_use',
|
|
205
|
+
id: block.id,
|
|
206
|
+
name: block.name,
|
|
207
|
+
input: block.input ?? {},
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return result;
|
|
212
|
+
}
|
|
213
|
+
function mapStopReason(reason) {
|
|
214
|
+
switch (reason) {
|
|
215
|
+
case 'end_turn':
|
|
216
|
+
return 'end_turn';
|
|
217
|
+
case 'tool_use':
|
|
218
|
+
return 'tool_use';
|
|
219
|
+
case 'max_tokens':
|
|
220
|
+
return 'max_tokens';
|
|
221
|
+
default:
|
|
222
|
+
return 'end_turn';
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
function classifyError(err) {
|
|
226
|
+
if (err instanceof ProviderError) {
|
|
227
|
+
return err;
|
|
228
|
+
}
|
|
229
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- classifying unknown SDK errors
|
|
230
|
+
const errObj = err;
|
|
231
|
+
const status = errObj.status;
|
|
232
|
+
const message = errObj.message ?? String(err);
|
|
233
|
+
if (status === 429) {
|
|
234
|
+
return new RateLimitError(`Anthropic rate limited: ${message}`, {
|
|
235
|
+
provider: 'anthropic',
|
|
236
|
+
cause: err,
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
if (message.includes('timeout') || message.includes('ETIMEDOUT')) {
|
|
240
|
+
return new ProviderTimeoutError(`Anthropic timeout: ${message}`, {
|
|
241
|
+
provider: 'anthropic',
|
|
242
|
+
cause: err,
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
const retryable = typeof status === 'number' && status >= 500;
|
|
246
|
+
return new ProviderError(`Anthropic error: ${message}`, {
|
|
247
|
+
provider: 'anthropic',
|
|
248
|
+
statusCode: status,
|
|
249
|
+
retryable,
|
|
250
|
+
cause: err,
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
//# sourceMappingURL=anthropic-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic-provider.js","sourceRoot":"","sources":["../../../../src/providers/runtime/anthropic-provider.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAYH,OAAO,EAAC,aAAa,EAAE,cAAc,EAAE,oBAAoB,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,GAAG,CAAC;IAE9D,OAAO,IAAI,aAAa,CAAC,oBAAoB,OAAO,EAAE,EAAE;QACtD,QAAQ,EAAE,WAAW;QACrB,UAAU,EAAE,MAAM;QAClB,SAAS;QACT,KAAK,EAAE,GAAG;KACX,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Amodal Labs, Inc.
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
6
|
+
import type { ModelConfig } from '../../repo/config-schema.js';
|
|
7
|
+
import type { RuntimeProvider, LLMChatRequest, LLMChatResponse } from './runtime-provider-types.js';
|
|
8
|
+
/**
|
|
9
|
+
* RuntimeProvider for Azure OpenAI Service.
|
|
10
|
+
*
|
|
11
|
+
* Thin wrapper over OpenAIRuntimeProvider that sets up Azure-specific config:
|
|
12
|
+
* - Base URL: `https://{resource}.openai.azure.com/openai/deployments/{deployment}`
|
|
13
|
+
* - API key: reads AZURE_OPENAI_API_KEY
|
|
14
|
+
* - API version query param is handled by the OpenAI SDK when `azureOpenAI` options are set
|
|
15
|
+
*
|
|
16
|
+
* The OpenAI SDK natively supports Azure via `AzureOpenAI` client.
|
|
17
|
+
*/
|
|
18
|
+
export declare class AzureOpenAIRuntimeProvider implements RuntimeProvider {
|
|
19
|
+
private readonly apiKey;
|
|
20
|
+
private readonly resourceName;
|
|
21
|
+
private readonly deploymentName;
|
|
22
|
+
private readonly apiVersion;
|
|
23
|
+
constructor(config: ModelConfig);
|
|
24
|
+
chat(request: LLMChatRequest): Promise<LLMChatResponse>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Amodal Labs, Inc.
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
6
|
+
import { ProviderError } from './provider-errors.js';
|
|
7
|
+
/**
|
|
8
|
+
* RuntimeProvider for Azure OpenAI Service.
|
|
9
|
+
*
|
|
10
|
+
* Thin wrapper over OpenAIRuntimeProvider that sets up Azure-specific config:
|
|
11
|
+
* - Base URL: `https://{resource}.openai.azure.com/openai/deployments/{deployment}`
|
|
12
|
+
* - API key: reads AZURE_OPENAI_API_KEY
|
|
13
|
+
* - API version query param is handled by the OpenAI SDK when `azureOpenAI` options are set
|
|
14
|
+
*
|
|
15
|
+
* The OpenAI SDK natively supports Azure via `AzureOpenAI` client.
|
|
16
|
+
*/
|
|
17
|
+
export class AzureOpenAIRuntimeProvider {
|
|
18
|
+
apiKey;
|
|
19
|
+
resourceName;
|
|
20
|
+
deploymentName;
|
|
21
|
+
apiVersion;
|
|
22
|
+
constructor(config) {
|
|
23
|
+
const key = config.credentials?.['AZURE_OPENAI_API_KEY']
|
|
24
|
+
?? process.env['AZURE_OPENAI_API_KEY'];
|
|
25
|
+
if (!key) {
|
|
26
|
+
throw new ProviderError('AZURE_OPENAI_API_KEY is not set', { provider: 'azure' });
|
|
27
|
+
}
|
|
28
|
+
this.apiKey = key;
|
|
29
|
+
const resource = config.credentials?.['AZURE_OPENAI_RESOURCE']
|
|
30
|
+
?? process.env['AZURE_OPENAI_RESOURCE']
|
|
31
|
+
?? '';
|
|
32
|
+
if (!resource && !config.baseUrl) {
|
|
33
|
+
throw new ProviderError('AZURE_OPENAI_RESOURCE is not set and no baseUrl provided', { provider: 'azure' });
|
|
34
|
+
}
|
|
35
|
+
this.resourceName = resource;
|
|
36
|
+
this.deploymentName = config.model;
|
|
37
|
+
this.apiVersion = config.credentials?.['AZURE_OPENAI_API_VERSION']
|
|
38
|
+
?? process.env['AZURE_OPENAI_API_VERSION']
|
|
39
|
+
?? '2024-10-21';
|
|
40
|
+
}
|
|
41
|
+
async chat(request) {
|
|
42
|
+
const { AzureOpenAI } = await import('openai');
|
|
43
|
+
const client = new AzureOpenAI({
|
|
44
|
+
apiKey: this.apiKey,
|
|
45
|
+
endpoint: `https://${this.resourceName}.openai.azure.com`,
|
|
46
|
+
deployment: this.deploymentName,
|
|
47
|
+
apiVersion: this.apiVersion,
|
|
48
|
+
});
|
|
49
|
+
// Delegate to a helper provider that uses this pre-configured client
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- AzureOpenAI SDK type mismatch
|
|
51
|
+
return chatWithClient(client, request);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Execute chat using a pre-configured OpenAI-compatible client.
|
|
56
|
+
* Reuses the same conversion logic as OpenAIRuntimeProvider.
|
|
57
|
+
*/
|
|
58
|
+
async function chatWithClient(client, request) {
|
|
59
|
+
// We instantiate a temporary OpenAIRuntimeProvider just to reuse its
|
|
60
|
+
// conversion logic. Instead, we directly build the request using the same
|
|
61
|
+
// format as OpenAI.
|
|
62
|
+
const messages = convertMessages(request.systemPrompt, request.messages);
|
|
63
|
+
const tools = convertTools(request.tools);
|
|
64
|
+
try {
|
|
65
|
+
const response = await client.chat.completions.create({
|
|
66
|
+
model: request.model,
|
|
67
|
+
max_tokens: request.maxTokens ?? 4096,
|
|
68
|
+
messages,
|
|
69
|
+
...(tools.length > 0 ? { tools } : {}),
|
|
70
|
+
stream: false,
|
|
71
|
+
});
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- SDK boundary: Azure OpenAI response shape
|
|
73
|
+
const completion = response;
|
|
74
|
+
const choice = completion.choices[0];
|
|
75
|
+
if (!choice) {
|
|
76
|
+
throw new ProviderError('Azure OpenAI returned no choices', { provider: 'azure' });
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
content: convertResponseContent(choice.message),
|
|
80
|
+
stopReason: mapFinishReason(choice.finish_reason),
|
|
81
|
+
usage: completion.usage
|
|
82
|
+
? {
|
|
83
|
+
inputTokens: completion.usage.prompt_tokens,
|
|
84
|
+
outputTokens: completion.usage.completion_tokens ?? 0,
|
|
85
|
+
}
|
|
86
|
+
: undefined,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
throw classifyError(err);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
import { RateLimitError, ProviderTimeoutError } from './provider-errors.js';
|
|
94
|
+
function convertMessages(systemPrompt, messages) {
|
|
95
|
+
const result = [{ role: 'system', content: systemPrompt }];
|
|
96
|
+
for (const msg of messages) {
|
|
97
|
+
switch (msg.role) {
|
|
98
|
+
case 'user':
|
|
99
|
+
result.push({ role: 'user', content: msg.content });
|
|
100
|
+
break;
|
|
101
|
+
case 'assistant': {
|
|
102
|
+
const textParts = msg.content.filter((b) => b.type === 'text');
|
|
103
|
+
const toolParts = msg.content.filter((b) => b.type === 'tool_use');
|
|
104
|
+
const content = textParts.map((b) => b.text).join('') || null;
|
|
105
|
+
const toolCalls = toolParts.length > 0
|
|
106
|
+
? toolParts.map((b) => ({
|
|
107
|
+
id: b.id,
|
|
108
|
+
type: 'function',
|
|
109
|
+
function: {
|
|
110
|
+
name: b.name,
|
|
111
|
+
arguments: JSON.stringify(b.input),
|
|
112
|
+
},
|
|
113
|
+
}))
|
|
114
|
+
: undefined;
|
|
115
|
+
result.push({ role: 'assistant', content, tool_calls: toolCalls });
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
case 'tool_result':
|
|
119
|
+
result.push({
|
|
120
|
+
role: 'tool',
|
|
121
|
+
tool_call_id: msg.toolCallId,
|
|
122
|
+
content: msg.content,
|
|
123
|
+
});
|
|
124
|
+
break;
|
|
125
|
+
default:
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
function convertTools(tools) {
|
|
132
|
+
return tools.map((t) => ({
|
|
133
|
+
type: 'function',
|
|
134
|
+
function: {
|
|
135
|
+
name: t.name,
|
|
136
|
+
description: t.description,
|
|
137
|
+
parameters: t.parameters,
|
|
138
|
+
},
|
|
139
|
+
}));
|
|
140
|
+
}
|
|
141
|
+
function convertResponseContent(message) {
|
|
142
|
+
const blocks = [];
|
|
143
|
+
if (message.content) {
|
|
144
|
+
blocks.push({ type: 'text', text: message.content });
|
|
145
|
+
}
|
|
146
|
+
if (message.tool_calls) {
|
|
147
|
+
for (const tc of message.tool_calls) {
|
|
148
|
+
let input = {};
|
|
149
|
+
try {
|
|
150
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- SDK boundary: parsing JSON args
|
|
151
|
+
input = JSON.parse(tc.function.arguments);
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
// Malformed JSON — pass empty input
|
|
155
|
+
}
|
|
156
|
+
blocks.push({
|
|
157
|
+
type: 'tool_use',
|
|
158
|
+
id: tc.id,
|
|
159
|
+
name: tc.function.name,
|
|
160
|
+
input,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return blocks;
|
|
165
|
+
}
|
|
166
|
+
function mapFinishReason(reason) {
|
|
167
|
+
switch (reason) {
|
|
168
|
+
case 'stop':
|
|
169
|
+
return 'end_turn';
|
|
170
|
+
case 'tool_calls':
|
|
171
|
+
return 'tool_use';
|
|
172
|
+
case 'length':
|
|
173
|
+
return 'max_tokens';
|
|
174
|
+
default:
|
|
175
|
+
return 'end_turn';
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
function classifyError(err) {
|
|
179
|
+
if (err instanceof ProviderError) {
|
|
180
|
+
return err;
|
|
181
|
+
}
|
|
182
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- classifying unknown SDK errors
|
|
183
|
+
const errObj = err;
|
|
184
|
+
const status = errObj.status;
|
|
185
|
+
const message = errObj.message ?? String(err);
|
|
186
|
+
if (status === 429) {
|
|
187
|
+
return new RateLimitError(`Azure OpenAI rate limited: ${message}`, {
|
|
188
|
+
provider: 'azure',
|
|
189
|
+
cause: err,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
if (message.includes('timeout') || message.includes('ETIMEDOUT')) {
|
|
193
|
+
return new ProviderTimeoutError(`Azure OpenAI timeout: ${message}`, {
|
|
194
|
+
provider: 'azure',
|
|
195
|
+
cause: err,
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
const retryable = typeof status === 'number' && status >= 500;
|
|
199
|
+
return new ProviderError(`Azure OpenAI error: ${message}`, {
|
|
200
|
+
provider: 'azure',
|
|
201
|
+
statusCode: status,
|
|
202
|
+
retryable,
|
|
203
|
+
cause: err,
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
//# sourceMappingURL=azure-provider.js.map
|