@retinue/agentkit 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 +22 -0
- package/README.md +310 -0
- package/dist/adapters/bullmq/consumer.d.ts +33 -0
- package/dist/adapters/bullmq/consumer.js +41 -0
- package/dist/adapters/bullmq/dispatcher.d.ts +74 -0
- package/dist/adapters/bullmq/dispatcher.js +160 -0
- package/dist/adapters/bullmq/export.d.ts +31 -0
- package/dist/adapters/bullmq/export.js +53 -0
- package/dist/adapters/bullmq/extraction.d.ts +42 -0
- package/dist/adapters/bullmq/extraction.js +63 -0
- package/dist/adapters/bullmq/index.d.ts +13 -0
- package/dist/adapters/bullmq/index.js +13 -0
- package/dist/adapters/bullmq/lock.d.ts +77 -0
- package/dist/adapters/bullmq/lock.js +126 -0
- package/dist/adapters/bullmq/queue.d.ts +50 -0
- package/dist/adapters/bullmq/queue.js +81 -0
- package/dist/adapters/memory/artifact-exports.d.ts +11 -0
- package/dist/adapters/memory/artifact-exports.js +102 -0
- package/dist/adapters/memory/artifacts.d.ts +15 -0
- package/dist/adapters/memory/artifacts.js +134 -0
- package/dist/adapters/memory/blobs.d.ts +7 -0
- package/dist/adapters/memory/blobs.js +27 -0
- package/dist/adapters/memory/evaluation.d.ts +18 -0
- package/dist/adapters/memory/evaluation.js +148 -0
- package/dist/adapters/memory/files.d.ts +27 -0
- package/dist/adapters/memory/files.js +0 -0
- package/dist/adapters/memory/flows.d.ts +16 -0
- package/dist/adapters/memory/flows.js +117 -0
- package/dist/adapters/memory/hitl.d.ts +9 -0
- package/dist/adapters/memory/hitl.js +130 -0
- package/dist/adapters/memory/idempotency.d.ts +13 -0
- package/dist/adapters/memory/idempotency.js +32 -0
- package/dist/adapters/memory/index.d.ts +39 -0
- package/dist/adapters/memory/index.js +107 -0
- package/dist/adapters/memory/knowledge.d.ts +43 -0
- package/dist/adapters/memory/knowledge.js +248 -0
- package/dist/adapters/memory/mcp.d.ts +9 -0
- package/dist/adapters/memory/mcp.js +37 -0
- package/dist/adapters/memory/message-store.d.ts +17 -0
- package/dist/adapters/memory/message-store.js +70 -0
- package/dist/adapters/memory/principal-memory.d.ts +7 -0
- package/dist/adapters/memory/principal-memory.js +83 -0
- package/dist/adapters/memory/runtime.d.ts +29 -0
- package/dist/adapters/memory/runtime.js +0 -0
- package/dist/adapters/memory/sessions.d.ts +29 -0
- package/dist/adapters/memory/sessions.js +0 -0
- package/dist/adapters/memory/skills.d.ts +10 -0
- package/dist/adapters/memory/skills.js +41 -0
- package/dist/adapters/memory/thread-summary.d.ts +7 -0
- package/dist/adapters/memory/thread-summary.js +29 -0
- package/dist/adapters/memory/usage-limits.d.ts +13 -0
- package/dist/adapters/memory/usage-limits.js +72 -0
- package/dist/adapters/memory/usage.d.ts +16 -0
- package/dist/adapters/memory/usage.js +279 -0
- package/dist/adapters/otel/index.d.ts +111 -0
- package/dist/adapters/otel/index.js +133 -0
- package/dist/adapters/postgres/artifact-exports.d.ts +12 -0
- package/dist/adapters/postgres/artifact-exports.js +117 -0
- package/dist/adapters/postgres/artifacts.d.ts +16 -0
- package/dist/adapters/postgres/artifacts.js +172 -0
- package/dist/adapters/postgres/checkpoint-store.d.ts +16 -0
- package/dist/adapters/postgres/checkpoint-store.js +34 -0
- package/dist/adapters/postgres/config.d.ts +15 -0
- package/dist/adapters/postgres/config.js +187 -0
- package/dist/adapters/postgres/conversation-store.d.ts +4 -0
- package/dist/adapters/postgres/conversation-store.js +82 -0
- package/dist/adapters/postgres/evaluation.d.ts +17 -0
- package/dist/adapters/postgres/evaluation.js +193 -0
- package/dist/adapters/postgres/file-content.d.ts +30 -0
- package/dist/adapters/postgres/file-content.js +111 -0
- package/dist/adapters/postgres/files.d.ts +19 -0
- package/dist/adapters/postgres/files.js +209 -0
- package/dist/adapters/postgres/flows.d.ts +20 -0
- package/dist/adapters/postgres/flows.js +206 -0
- package/dist/adapters/postgres/hitl.d.ts +5 -0
- package/dist/adapters/postgres/hitl.js +247 -0
- package/dist/adapters/postgres/index.d.ts +35 -0
- package/dist/adapters/postgres/index.js +35 -0
- package/dist/adapters/postgres/knowledge.d.ts +48 -0
- package/dist/adapters/postgres/knowledge.js +255 -0
- package/dist/adapters/postgres/memory.d.ts +14 -0
- package/dist/adapters/postgres/memory.js +194 -0
- package/dist/adapters/postgres/message-store.d.ts +11 -0
- package/dist/adapters/postgres/message-store.js +145 -0
- package/dist/adapters/postgres/migrations.d.ts +69 -0
- package/dist/adapters/postgres/migrations.js +1594 -0
- package/dist/adapters/postgres/pg-executor.d.ts +19 -0
- package/dist/adapters/postgres/pg-executor.js +32 -0
- package/dist/adapters/postgres/retention.d.ts +26 -0
- package/dist/adapters/postgres/retention.js +59 -0
- package/dist/adapters/postgres/rollups.d.ts +17 -0
- package/dist/adapters/postgres/rollups.js +267 -0
- package/dist/adapters/postgres/run-coordinator.d.ts +5 -0
- package/dist/adapters/postgres/run-coordinator.js +98 -0
- package/dist/adapters/postgres/run-event-log.d.ts +26 -0
- package/dist/adapters/postgres/run-event-log.js +30 -0
- package/dist/adapters/postgres/run-store.d.ts +4 -0
- package/dist/adapters/postgres/run-store.js +199 -0
- package/dist/adapters/postgres/schema.d.ts +39 -0
- package/dist/adapters/postgres/schema.js +70 -0
- package/dist/adapters/postgres/session-state.d.ts +7 -0
- package/dist/adapters/postgres/session-state.js +99 -0
- package/dist/adapters/postgres/sql.d.ts +8 -0
- package/dist/adapters/postgres/sql.js +2 -0
- package/dist/adapters/postgres/transaction.d.ts +37 -0
- package/dist/adapters/postgres/transaction.js +93 -0
- package/dist/adapters/postgres/unit-of-work.d.ts +18 -0
- package/dist/adapters/postgres/unit-of-work.js +8 -0
- package/dist/adapters/postgres/usage-limits.d.ts +15 -0
- package/dist/adapters/postgres/usage-limits.js +136 -0
- package/dist/adapters/postgres/usage.d.ts +15 -0
- package/dist/adapters/postgres/usage.js +226 -0
- package/dist/adapters/redis/index.d.ts +9 -0
- package/dist/adapters/redis/index.js +9 -0
- package/dist/adapters/redis/realtime.d.ts +74 -0
- package/dist/adapters/redis/realtime.js +112 -0
- package/dist/adapters/supabase/index.d.ts +88 -0
- package/dist/adapters/supabase/index.js +84 -0
- package/dist/adapters/supabase/realtime.d.ts +30 -0
- package/dist/adapters/supabase/realtime.js +53 -0
- package/dist/adapters/supabase/rls.d.ts +99 -0
- package/dist/adapters/supabase/rls.js +216 -0
- package/dist/adapters/supabase/storage.d.ts +50 -0
- package/dist/adapters/supabase/storage.js +207 -0
- package/dist/agents/agent.d.ts +66 -0
- package/dist/agents/agent.js +209 -0
- package/dist/agents/define.d.ts +21 -0
- package/dist/agents/define.js +63 -0
- package/dist/agents/engine.d.ts +98 -0
- package/dist/agents/engine.js +462 -0
- package/dist/agents/index.d.ts +50 -0
- package/dist/agents/index.js +17 -0
- package/dist/artifacts/index.d.ts +114 -0
- package/dist/artifacts/index.js +219 -0
- package/dist/authorization/index.d.ts +76 -0
- package/dist/authorization/index.js +76 -0
- package/dist/capabilities/index.d.ts +120 -0
- package/dist/capabilities/index.js +167 -0
- package/dist/capabilities/runtime.d.ts +89 -0
- package/dist/capabilities/runtime.js +84 -0
- package/dist/citations/index.d.ts +161 -0
- package/dist/citations/index.js +182 -0
- package/dist/context/assembler.d.ts +82 -0
- package/dist/context/assembler.js +129 -0
- package/dist/context/compaction.d.ts +45 -0
- package/dist/context/compaction.js +55 -0
- package/dist/context/index.d.ts +75 -0
- package/dist/context/index.js +17 -0
- package/dist/core/content-parts.d.ts +194 -0
- package/dist/core/content-parts.js +23 -0
- package/dist/core/context.d.ts +51 -0
- package/dist/core/context.js +9 -0
- package/dist/core/env.d.ts +25 -0
- package/dist/core/env.js +41 -0
- package/dist/core/errors.d.ts +30 -0
- package/dist/core/errors.js +65 -0
- package/dist/core/events.d.ts +139 -0
- package/dist/core/events.js +99 -0
- package/dist/core/ids.d.ts +52 -0
- package/dist/core/ids.js +13 -0
- package/dist/core/index.d.ts +9 -0
- package/dist/core/index.js +9 -0
- package/dist/core/tokens.d.ts +22 -0
- package/dist/core/tokens.js +22 -0
- package/dist/core/validation.d.ts +34 -0
- package/dist/core/validation.js +176 -0
- package/dist/documents/extraction.d.ts +121 -0
- package/dist/documents/extraction.js +293 -0
- package/dist/documents/index.d.ts +199 -0
- package/dist/documents/index.js +65 -0
- package/dist/documents/parsers/pdf.d.ts +47 -0
- package/dist/documents/parsers/pdf.js +508 -0
- package/dist/documents/parsers/text.d.ts +59 -0
- package/dist/documents/parsers/text.js +325 -0
- package/dist/documents/read-tool.d.ts +52 -0
- package/dist/documents/read-tool.js +109 -0
- package/dist/documents/render.d.ts +29 -0
- package/dist/documents/render.js +59 -0
- package/dist/documents/vision.d.ts +159 -0
- package/dist/documents/vision.js +214 -0
- package/dist/entries/adapters-bullmq.d.ts +8 -0
- package/dist/entries/adapters-bullmq.js +8 -0
- package/dist/entries/adapters-otel.d.ts +13 -0
- package/dist/entries/adapters-otel.js +13 -0
- package/dist/entries/adapters-postgres.d.ts +10 -0
- package/dist/entries/adapters-postgres.js +10 -0
- package/dist/entries/adapters-redis.d.ts +3 -0
- package/dist/entries/adapters-redis.js +3 -0
- package/dist/entries/context.d.ts +20 -0
- package/dist/entries/context.js +20 -0
- package/dist/entries/flows.d.ts +15 -0
- package/dist/entries/flows.js +15 -0
- package/dist/entries/hitl.d.ts +10 -0
- package/dist/entries/hitl.js +10 -0
- package/dist/entries/knowledge.d.ts +18 -0
- package/dist/entries/knowledge.js +19 -0
- package/dist/entries/mcp.d.ts +10 -0
- package/dist/entries/mcp.js +10 -0
- package/dist/entries/observability.d.ts +14 -0
- package/dist/entries/observability.js +16 -0
- package/dist/entries/persistence.d.ts +11 -0
- package/dist/entries/persistence.js +11 -0
- package/dist/entries/providers.d.ts +14 -0
- package/dist/entries/providers.js +14 -0
- package/dist/entries/runtime.d.ts +13 -0
- package/dist/entries/runtime.js +13 -0
- package/dist/entries/server.d.ts +24 -0
- package/dist/entries/server.js +24 -0
- package/dist/entries/tools.d.ts +21 -0
- package/dist/entries/tools.js +21 -0
- package/dist/entries/usage.d.ts +10 -0
- package/dist/entries/usage.js +10 -0
- package/dist/evaluation/gate.d.ts +168 -0
- package/dist/evaluation/gate.js +180 -0
- package/dist/evaluation/graders.d.ts +125 -0
- package/dist/evaluation/graders.js +203 -0
- package/dist/evaluation/index.d.ts +120 -0
- package/dist/evaluation/index.js +183 -0
- package/dist/evaluation/judge.d.ts +75 -0
- package/dist/evaluation/judge.js +111 -0
- package/dist/export/index.d.ts +162 -0
- package/dist/export/index.js +363 -0
- package/dist/export/markdown.d.ts +19 -0
- package/dist/export/markdown.js +29 -0
- package/dist/export/pdf.d.ts +73 -0
- package/dist/export/pdf.js +407 -0
- package/dist/files/context.d.ts +97 -0
- package/dist/files/context.js +185 -0
- package/dist/files/index.d.ts +210 -0
- package/dist/files/index.js +338 -0
- package/dist/files/read-tool.d.ts +81 -0
- package/dist/files/read-tool.js +163 -0
- package/dist/files/turn-parts.d.ts +96 -0
- package/dist/files/turn-parts.js +171 -0
- package/dist/flows/index.d.ts +270 -0
- package/dist/flows/index.js +62 -0
- package/dist/flows/interpreter.d.ts +146 -0
- package/dist/flows/interpreter.js +426 -0
- package/dist/flows/runner.d.ts +145 -0
- package/dist/flows/runner.js +270 -0
- package/dist/graphql/index.d.ts +8 -0
- package/dist/graphql/index.js +8 -0
- package/dist/graphql/resolvers.d.ts +237 -0
- package/dist/graphql/resolvers.js +253 -0
- package/dist/graphql/schema.d.ts +11 -0
- package/dist/graphql/schema.js +258 -0
- package/dist/graphql/sse.d.ts +77 -0
- package/dist/graphql/sse.js +100 -0
- package/dist/hitl/approved-execution.d.ts +127 -0
- package/dist/hitl/approved-execution.js +177 -0
- package/dist/hitl/index.d.ts +79 -0
- package/dist/hitl/index.js +12 -0
- package/dist/hitl/service.d.ts +221 -0
- package/dist/hitl/service.js +268 -0
- package/dist/idempotency/index.d.ts +70 -0
- package/dist/idempotency/index.js +59 -0
- package/dist/index.d.ts +103 -0
- package/dist/index.js +60 -0
- package/dist/knowledge/chunking.d.ts +57 -0
- package/dist/knowledge/chunking.js +158 -0
- package/dist/knowledge/index.d.ts +119 -0
- package/dist/knowledge/index.js +166 -0
- package/dist/knowledge/retrieval.d.ts +146 -0
- package/dist/knowledge/retrieval.js +170 -0
- package/dist/loadtest/harness.d.ts +168 -0
- package/dist/loadtest/harness.js +507 -0
- package/dist/loadtest/index.d.ts +13 -0
- package/dist/loadtest/index.js +13 -0
- package/dist/loadtest/injection.d.ts +89 -0
- package/dist/loadtest/injection.js +147 -0
- package/dist/loadtest/metrics.d.ts +197 -0
- package/dist/loadtest/metrics.js +160 -0
- package/dist/loadtest/runbooks.d.ts +28 -0
- package/dist/loadtest/runbooks.js +159 -0
- package/dist/loadtest/scenario.d.ts +104 -0
- package/dist/loadtest/scenario.js +208 -0
- package/dist/mcp/egress.d.ts +53 -0
- package/dist/mcp/egress.js +115 -0
- package/dist/mcp/index.d.ts +93 -0
- package/dist/mcp/index.js +33 -0
- package/dist/mcp/provider.d.ts +62 -0
- package/dist/mcp/provider.js +0 -0
- package/dist/models/index.d.ts +98 -0
- package/dist/models/index.js +74 -0
- package/dist/models/pricing.d.ts +24 -0
- package/dist/models/pricing.js +37 -0
- package/dist/models/provider-factory.d.ts +31 -0
- package/dist/models/provider-factory.js +67 -0
- package/dist/models/streaming.d.ts +145 -0
- package/dist/models/streaming.js +272 -0
- package/dist/models/vision.d.ts +38 -0
- package/dist/models/vision.js +62 -0
- package/dist/persistence/index.d.ts +1654 -0
- package/dist/persistence/index.js +226 -0
- package/dist/principal-memory/index.d.ts +106 -0
- package/dist/principal-memory/index.js +89 -0
- package/dist/retention/index.d.ts +89 -0
- package/dist/retention/index.js +70 -0
- package/dist/runtime/checkpoint.d.ts +37 -0
- package/dist/runtime/checkpoint.js +22 -0
- package/dist/runtime/index.d.ts +118 -0
- package/dist/runtime/index.js +69 -0
- package/dist/runtime/retry.d.ts +95 -0
- package/dist/runtime/retry.js +126 -0
- package/dist/runtime/serialization.d.ts +85 -0
- package/dist/runtime/serialization.js +95 -0
- package/dist/runtime/streaming.d.ts +54 -0
- package/dist/runtime/streaming.js +115 -0
- package/dist/runtime/worker.d.ts +130 -0
- package/dist/runtime/worker.js +405 -0
- package/dist/security/checklist.d.ts +53 -0
- package/dist/security/checklist.js +204 -0
- package/dist/security/findings.d.ts +56 -0
- package/dist/security/findings.js +168 -0
- package/dist/security/index.d.ts +14 -0
- package/dist/security/index.js +14 -0
- package/dist/security/prompt-safety.d.ts +100 -0
- package/dist/security/prompt-safety.js +133 -0
- package/dist/server/boot.d.ts +32 -0
- package/dist/server/boot.js +36 -0
- package/dist/server/cli-worker.d.ts +37 -0
- package/dist/server/cli-worker.js +151 -0
- package/dist/server/cli.d.ts +27 -0
- package/dist/server/cli.js +74 -0
- package/dist/server/config.d.ts +42 -0
- package/dist/server/config.js +127 -0
- package/dist/server/health.d.ts +59 -0
- package/dist/server/health.js +90 -0
- package/dist/server/host.d.ts +39 -0
- package/dist/server/host.js +124 -0
- package/dist/server/index.d.ts +15 -0
- package/dist/server/index.js +15 -0
- package/dist/server/main.d.ts +16 -0
- package/dist/server/main.js +31 -0
- package/dist/server/sse-route.d.ts +21 -0
- package/dist/server/sse-route.js +282 -0
- package/dist/skills/index.d.ts +67 -0
- package/dist/skills/index.js +31 -0
- package/dist/skills/resolver.d.ts +54 -0
- package/dist/skills/resolver.js +121 -0
- package/dist/teams/index.d.ts +93 -0
- package/dist/teams/index.js +207 -0
- package/dist/telemetry/index.d.ts +157 -0
- package/dist/telemetry/index.js +71 -0
- package/dist/telemetry/instrument.d.ts +108 -0
- package/dist/telemetry/instrument.js +232 -0
- package/dist/telemetry/log-events.d.ts +17 -0
- package/dist/telemetry/log-events.js +58 -0
- package/dist/telemetry/metrics.d.ts +123 -0
- package/dist/telemetry/metrics.js +135 -0
- package/dist/telemetry/noop.d.ts +39 -0
- package/dist/telemetry/noop.js +143 -0
- package/dist/telemetry/redaction.d.ts +64 -0
- package/dist/telemetry/redaction.js +153 -0
- package/dist/telemetry/spans.d.ts +56 -0
- package/dist/telemetry/spans.js +78 -0
- package/dist/telemetry/trace-context.d.ts +55 -0
- package/dist/telemetry/trace-context.js +60 -0
- package/dist/toolkit/compute.d.ts +53 -0
- package/dist/toolkit/compute.js +152 -0
- package/dist/toolkit/data.d.ts +98 -0
- package/dist/toolkit/data.js +235 -0
- package/dist/toolkit/http.d.ts +113 -0
- package/dist/toolkit/http.js +205 -0
- package/dist/toolkit/index.d.ts +21 -0
- package/dist/toolkit/index.js +17 -0
- package/dist/toolkit/web.d.ts +107 -0
- package/dist/toolkit/web.js +147 -0
- package/dist/tools/define.d.ts +25 -0
- package/dist/tools/define.js +45 -0
- package/dist/tools/delegating.d.ts +132 -0
- package/dist/tools/delegating.js +211 -0
- package/dist/tools/index.d.ts +129 -0
- package/dist/tools/index.js +33 -0
- package/dist/tools/library/compute.d.ts +11 -0
- package/dist/tools/library/compute.js +46 -0
- package/dist/tools/library/data.d.ts +16 -0
- package/dist/tools/library/data.js +92 -0
- package/dist/tools/library/http.d.ts +28 -0
- package/dist/tools/library/http.js +71 -0
- package/dist/tools/library/index.d.ts +97 -0
- package/dist/tools/library/index.js +134 -0
- package/dist/tools/library/knowledge.d.ts +39 -0
- package/dist/tools/library/knowledge.js +58 -0
- package/dist/tools/library/web.d.ts +19 -0
- package/dist/tools/library/web.js +65 -0
- package/dist/tools/meta-tools.d.ts +19 -0
- package/dist/tools/meta-tools.js +36 -0
- package/dist/tools/registry.d.ts +146 -0
- package/dist/tools/registry.js +291 -0
- package/dist/usage/index.d.ts +105 -0
- package/dist/usage/index.js +20 -0
- package/dist/usage/quota.d.ts +258 -0
- package/dist/usage/quota.js +510 -0
- package/dist/usage/recorder.d.ts +29 -0
- package/dist/usage/recorder.js +96 -0
- package/dist/usage/rollups.d.ts +121 -0
- package/dist/usage/rollups.js +157 -0
- package/dist/worker/export.d.ts +57 -0
- package/dist/worker/export.js +81 -0
- package/dist/worker/extraction.d.ts +57 -0
- package/dist/worker/extraction.js +84 -0
- package/dist/worker/main.d.ts +103 -0
- package/dist/worker/main.js +159 -0
- package/package.json +187 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP — outbound server consumption. `@proposed`: no specification section covers this
|
|
3
|
+
* yet, so these contracts are the open proposal, not settled design.
|
|
4
|
+
*
|
|
5
|
+
* Direction matters. The repository already ships an *inbound* MCP server
|
|
6
|
+
* (`web/src/lib/mcp/server.ts`) that exposes Chorus tools to external clients. This
|
|
7
|
+
* module is the other direction: a tenant registers their own MCP server and the
|
|
8
|
+
* assistant gains its tools.
|
|
9
|
+
*
|
|
10
|
+
* An imported tool is a `ToolProvider` like any other, which means it inherits the
|
|
11
|
+
* whole authorization and approval path rather than sitting beside it.
|
|
12
|
+
*/
|
|
13
|
+
import type { ExecutionContext } from "../core/context.js";
|
|
14
|
+
import type { TenantId } from "../core/ids.js";
|
|
15
|
+
import type { ToolDescriptor, ToolEffect, ToolProvider } from "../tools/index.js";
|
|
16
|
+
export declare const MCP_TRANSPORTS: readonly ["stdio", "streamable-http", "sse"];
|
|
17
|
+
export type McpTransport = (typeof MCP_TRANSPORTS)[number];
|
|
18
|
+
export type McpAuth = {
|
|
19
|
+
readonly kind: "none";
|
|
20
|
+
} | {
|
|
21
|
+
readonly kind: "bearer";
|
|
22
|
+
readonly credentialRef: string;
|
|
23
|
+
} | {
|
|
24
|
+
readonly kind: "oauth";
|
|
25
|
+
readonly credentialRef: string;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Credentials are referenced, never inlined — `credentialRef` points at secret storage.
|
|
29
|
+
* Nothing in this record may reach model context.
|
|
30
|
+
*/
|
|
31
|
+
export type McpServerConnection = {
|
|
32
|
+
readonly id: string;
|
|
33
|
+
readonly tenantId: TenantId;
|
|
34
|
+
readonly label: string;
|
|
35
|
+
readonly transport: McpTransport;
|
|
36
|
+
/** URL for HTTP transports, command for stdio. Validated against the egress policy. */
|
|
37
|
+
readonly endpoint: string;
|
|
38
|
+
readonly auth: McpAuth;
|
|
39
|
+
readonly enabled: boolean;
|
|
40
|
+
readonly createdAt: string;
|
|
41
|
+
readonly lastHandshakeAt?: string;
|
|
42
|
+
readonly lastError?: string;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* MCP does not classify side effects the way the platform does. `readOnlyHint` and
|
|
46
|
+
* `destructiveHint` are advisory and come from the remote server, which is untrusted.
|
|
47
|
+
* So classification defaults to the safe end and only an administrator can relax it.
|
|
48
|
+
*/
|
|
49
|
+
export type McpToolHints = {
|
|
50
|
+
readonly readOnlyHint?: boolean;
|
|
51
|
+
readonly destructiveHint?: boolean;
|
|
52
|
+
readonly openWorldHint?: boolean;
|
|
53
|
+
};
|
|
54
|
+
export type McpToolClassification = {
|
|
55
|
+
readonly effect: ToolEffect;
|
|
56
|
+
readonly source: "hint" | "administrator" | "default";
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Safe default: anything not explicitly classified by an administrator is treated as an
|
|
60
|
+
* external write and requires approval. A remote server cannot talk its way down to
|
|
61
|
+
* `read` — a `readOnlyHint` alone is not enough, because the hint is attacker-controlled
|
|
62
|
+
* when the server is.
|
|
63
|
+
*/
|
|
64
|
+
export declare const classifyMcpTool: (hints: McpToolHints, administratorEffect?: ToolEffect) => McpToolClassification;
|
|
65
|
+
/** Namespaced so two servers exposing `search` cannot collide. */
|
|
66
|
+
export declare const mcpToolName: (serverId: string, toolName: string) => string;
|
|
67
|
+
/**
|
|
68
|
+
* MCP servers may change their tool list between calls. The run records a hash of what
|
|
69
|
+
* it discovered, so a catalog that shifted mid-run is detectable after the fact.
|
|
70
|
+
*/
|
|
71
|
+
export type McpCatalogSnapshot = {
|
|
72
|
+
readonly connectionId: string;
|
|
73
|
+
readonly toolListHash: string;
|
|
74
|
+
readonly discoveredAt: string;
|
|
75
|
+
readonly tools: readonly ToolDescriptor[];
|
|
76
|
+
};
|
|
77
|
+
/** Bridges one connection into the ordinary tool pipeline. */
|
|
78
|
+
export interface McpToolProvider extends ToolProvider {
|
|
79
|
+
readonly connectionId: string;
|
|
80
|
+
snapshot(context: ExecutionContext): Promise<McpCatalogSnapshot>;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* MCP resources and prompts are context, not tools. They belong on the context-provider
|
|
84
|
+
* path so they are budgeted and pruned like every other section.
|
|
85
|
+
*/
|
|
86
|
+
export type McpResourceRef = {
|
|
87
|
+
readonly connectionId: string;
|
|
88
|
+
readonly uri: string;
|
|
89
|
+
readonly mimeType?: string;
|
|
90
|
+
};
|
|
91
|
+
export * from "./egress.js";
|
|
92
|
+
export * from "./provider.js";
|
|
93
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP — outbound server consumption. `@proposed`: no specification section covers this
|
|
3
|
+
* yet, so these contracts are the open proposal, not settled design.
|
|
4
|
+
*
|
|
5
|
+
* Direction matters. The repository already ships an *inbound* MCP server
|
|
6
|
+
* (`web/src/lib/mcp/server.ts`) that exposes Chorus tools to external clients. This
|
|
7
|
+
* module is the other direction: a tenant registers their own MCP server and the
|
|
8
|
+
* assistant gains its tools.
|
|
9
|
+
*
|
|
10
|
+
* An imported tool is a `ToolProvider` like any other, which means it inherits the
|
|
11
|
+
* whole authorization and approval path rather than sitting beside it.
|
|
12
|
+
*/
|
|
13
|
+
export const MCP_TRANSPORTS = ["stdio", "streamable-http", "sse"];
|
|
14
|
+
/**
|
|
15
|
+
* Safe default: anything not explicitly classified by an administrator is treated as an
|
|
16
|
+
* external write and requires approval. A remote server cannot talk its way down to
|
|
17
|
+
* `read` — a `readOnlyHint` alone is not enough, because the hint is attacker-controlled
|
|
18
|
+
* when the server is.
|
|
19
|
+
*/
|
|
20
|
+
export const classifyMcpTool = (hints, administratorEffect) => {
|
|
21
|
+
if (administratorEffect !== undefined) {
|
|
22
|
+
return { effect: administratorEffect, source: "administrator" };
|
|
23
|
+
}
|
|
24
|
+
if (hints.destructiveHint === true) {
|
|
25
|
+
return { effect: "destructive", source: "hint" };
|
|
26
|
+
}
|
|
27
|
+
return { effect: "external-write", source: "default" };
|
|
28
|
+
};
|
|
29
|
+
/** Namespaced so two servers exposing `search` cannot collide. */
|
|
30
|
+
export const mcpToolName = (serverId, toolName) => `mcp__${serverId}__${toolName}`;
|
|
31
|
+
export * from "./egress.js";
|
|
32
|
+
export * from "./provider.js";
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP tool provider & connection store — `docs/10-mcp-integration.md`.
|
|
3
|
+
*
|
|
4
|
+
* Bridges a tenant's MCP server into the ordinary tool pipeline: each remote tool becomes a `Tool`
|
|
5
|
+
* with a platform-classified effect, an `mcp__<server>__<tool>` namespaced name, and an approval
|
|
6
|
+
* policy derived from that effect — so imported tools inherit the whole authorization + approval
|
|
7
|
+
* path instead of sitting beside it. Effects are classified safe-by-default (untrusted hints cannot
|
|
8
|
+
* reach `read`; only an administrator can relax). A per-run catalog snapshot hash makes a tool list
|
|
9
|
+
* that shifted mid-run detectable after the fact. Connections are tenant-scoped and never expose
|
|
10
|
+
* credentials — auth carries only a `credentialRef`, and the model-facing view is redacted.
|
|
11
|
+
*/
|
|
12
|
+
import type { TenantId } from "../core/ids.js";
|
|
13
|
+
import type { ToolEffect } from "../tools/index.js";
|
|
14
|
+
import { type McpCatalogSnapshot, type McpServerConnection, type McpToolHints, type McpToolProvider } from "./index.js";
|
|
15
|
+
/** A remote tool as reported by an MCP server. Untrusted — descriptions/schemas are attacker data. */
|
|
16
|
+
export type McpRemoteTool = {
|
|
17
|
+
readonly name: string;
|
|
18
|
+
readonly description?: string;
|
|
19
|
+
readonly inputSchema?: unknown;
|
|
20
|
+
readonly outputSchema?: unknown;
|
|
21
|
+
readonly hints?: McpToolHints;
|
|
22
|
+
};
|
|
23
|
+
/** The MCP client the host wires to a real transport. Kept minimal and injectable for tests. */
|
|
24
|
+
export interface McpClient {
|
|
25
|
+
listTools(): Promise<readonly McpRemoteTool[]>;
|
|
26
|
+
callTool(name: string, input: unknown): Promise<unknown>;
|
|
27
|
+
}
|
|
28
|
+
/** Deterministic, order-independent hash of a tool list, for catalog-drift detection. */
|
|
29
|
+
export declare const hashToolList: (tools: readonly {
|
|
30
|
+
name: string;
|
|
31
|
+
}[]) => string;
|
|
32
|
+
/** True when the two snapshots describe different tool lists — i.e. the catalog drifted. */
|
|
33
|
+
export declare const detectCatalogDrift: (a: McpCatalogSnapshot, b: McpCatalogSnapshot) => boolean;
|
|
34
|
+
export declare const createMcpToolProvider: (config: {
|
|
35
|
+
readonly connection: McpServerConnection;
|
|
36
|
+
readonly client: McpClient;
|
|
37
|
+
/** Administrator effect classifications by remote tool name (relaxes the safe default). */
|
|
38
|
+
readonly adminEffects?: Readonly<Record<string, ToolEffect>>;
|
|
39
|
+
readonly clock?: () => string;
|
|
40
|
+
}) => McpToolProvider;
|
|
41
|
+
/** The model/log-safe view of a connection: no endpoint, no credential reference at all. */
|
|
42
|
+
export declare const redactConnection: (connection: McpServerConnection) => Pick<McpServerConnection, "id" | "tenantId" | "label" | "transport" | "enabled">;
|
|
43
|
+
/** Tenant-scoped connection registry. Endpoints are egress-validated before storage. */
|
|
44
|
+
export interface McpConnectionStore {
|
|
45
|
+
register(input: {
|
|
46
|
+
tenantId: TenantId;
|
|
47
|
+
connection: McpServerConnection;
|
|
48
|
+
}): Promise<void>;
|
|
49
|
+
get(input: {
|
|
50
|
+
tenantId: TenantId;
|
|
51
|
+
id: string;
|
|
52
|
+
}): Promise<McpServerConnection | null>;
|
|
53
|
+
list(input: {
|
|
54
|
+
tenantId: TenantId;
|
|
55
|
+
}): Promise<readonly McpServerConnection[]>;
|
|
56
|
+
setEnabled(input: {
|
|
57
|
+
tenantId: TenantId;
|
|
58
|
+
id: string;
|
|
59
|
+
enabled: boolean;
|
|
60
|
+
}): Promise<void>;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
Binary file
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model platform — `docs/03-intelligence-runtime.md`.
|
|
3
|
+
*
|
|
4
|
+
* Provider-neutral. Agents state a policy and a role; they never hardcode model IDs.
|
|
5
|
+
*/
|
|
6
|
+
export declare const MODEL_PROVIDERS: readonly ["openai", "anthropic", "google", "mistral", "azure-openai", "bedrock", "openai-compatible"];
|
|
7
|
+
export type ModelProvider = (typeof MODEL_PROVIDERS)[number];
|
|
8
|
+
export type ModelLifecycle = "preview" | "generally-available" | "deprecated" | "retired";
|
|
9
|
+
export type InputModality = "text" | "image" | "audio" | "video" | "pdf";
|
|
10
|
+
export type ModelCapabilities = {
|
|
11
|
+
readonly tools: boolean;
|
|
12
|
+
readonly structuredOutput: boolean;
|
|
13
|
+
readonly reasoning: boolean;
|
|
14
|
+
readonly nativeSearch: boolean;
|
|
15
|
+
};
|
|
16
|
+
export type ModelLimits = {
|
|
17
|
+
readonly contextTokens: number;
|
|
18
|
+
readonly maxOutputTokens: number;
|
|
19
|
+
};
|
|
20
|
+
/** Prices are per million tokens, in minor currency units, to avoid float drift. */
|
|
21
|
+
export type ModelPricing = {
|
|
22
|
+
readonly currency: string;
|
|
23
|
+
readonly inputPerMillion: number;
|
|
24
|
+
readonly outputPerMillion: number;
|
|
25
|
+
readonly cacheReadPerMillion?: number;
|
|
26
|
+
readonly cacheWritePerMillion?: number;
|
|
27
|
+
/**
|
|
28
|
+
* How this provider charges for non-text input — REQ-036 (#185), AC-4.
|
|
29
|
+
*
|
|
30
|
+
* The field exists because getting it wrong is a wrong bill in **either** direction, and the two conventions
|
|
31
|
+
* are indistinguishable from the token counts alone:
|
|
32
|
+
*
|
|
33
|
+
* - `"in-input-tokens"` (the default, and what OpenAI does): an image is converted to input tokens by the
|
|
34
|
+
* provider and already counted in `inputTokens`. Adding a per-image charge on top **double-bills**.
|
|
35
|
+
* - `"per-unit"`: images and audio are billed separately, per image or per second, *in addition* to the text
|
|
36
|
+
* tokens. Not adding the charge **under-bills**, silently, and the shortfall scales with usage.
|
|
37
|
+
*
|
|
38
|
+
* Defaulting to `"in-input-tokens"` is the safe direction for the model catalogue we ship, and it means every
|
|
39
|
+
* existing pricing record keeps costing exactly what it did.
|
|
40
|
+
*/
|
|
41
|
+
readonly nonTextInput?: "in-input-tokens" | "per-unit";
|
|
42
|
+
/** Minor units per image sent. Only consulted when `nonTextInput` is `"per-unit"`. */
|
|
43
|
+
readonly perImageMinorUnits?: number;
|
|
44
|
+
/** Minor units per second of audio input. Only consulted when `nonTextInput` is `"per-unit"`. */
|
|
45
|
+
readonly perAudioSecondMinorUnits?: number;
|
|
46
|
+
};
|
|
47
|
+
export type ModelDefinition = {
|
|
48
|
+
readonly provider: ModelProvider;
|
|
49
|
+
readonly modelId: string;
|
|
50
|
+
readonly label: string;
|
|
51
|
+
readonly lifecycle: ModelLifecycle;
|
|
52
|
+
readonly inputModalities: readonly InputModality[];
|
|
53
|
+
readonly capabilities: ModelCapabilities;
|
|
54
|
+
readonly limits: ModelLimits;
|
|
55
|
+
readonly pricing: ModelPricing;
|
|
56
|
+
/** ISO 3166 regions the provider will process this model's data in. */
|
|
57
|
+
readonly dataResidency: readonly string[];
|
|
58
|
+
};
|
|
59
|
+
/** `fast` and `smart` let an agent express intent without naming a model. */
|
|
60
|
+
export type ModelRole = "fast" | "smart";
|
|
61
|
+
export type ModelPolicy = {
|
|
62
|
+
readonly role: ModelRole;
|
|
63
|
+
readonly requiredCapabilities?: Partial<ModelCapabilities>;
|
|
64
|
+
readonly requiredModalities?: readonly InputModality[];
|
|
65
|
+
readonly allowedProviders?: readonly ModelProvider[];
|
|
66
|
+
readonly dataResidency?: readonly string[];
|
|
67
|
+
/** Ceiling per run, in the pricing currency's minor units. */
|
|
68
|
+
readonly costCeilingMinorUnits?: number;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Resolution considers administrator policy, tenant policy, required capabilities,
|
|
72
|
+
* data residency, availability, cost ceiling and deprecation state.
|
|
73
|
+
*/
|
|
74
|
+
export interface ModelRegistry {
|
|
75
|
+
list(): readonly ModelDefinition[];
|
|
76
|
+
resolve(policy: ModelPolicy): ModelDefinition;
|
|
77
|
+
}
|
|
78
|
+
/** Administrator/tenant policy: ordered candidate model IDs per role (most preferred first). */
|
|
79
|
+
export type ModelRoleAssignments = Readonly<Record<ModelRole, readonly string[]>>;
|
|
80
|
+
export type ModelRegistryConfig = {
|
|
81
|
+
readonly models: readonly ModelDefinition[];
|
|
82
|
+
readonly roles: ModelRoleAssignments;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Resolves a role + constraints to a concrete model using the administrator's role assignments.
|
|
86
|
+
* Agents never name a model, so re-pointing a role here changes no agent code.
|
|
87
|
+
*/
|
|
88
|
+
export declare const createModelRegistry: (config: ModelRegistryConfig) => ModelRegistry;
|
|
89
|
+
/**
|
|
90
|
+
* `provider-factory` is **not** re-exported here — #196.
|
|
91
|
+
*
|
|
92
|
+
* It statically imports six `@ai-sdk/*` packages, so anything that pulls this barrel pulled all six. Since they
|
|
93
|
+
* are optional peers now, a root import must not reach them: a consumer using OpenAI would get a resolution
|
|
94
|
+
* failure for Anthropic. It lives behind the `./providers` subpath instead.
|
|
95
|
+
*/
|
|
96
|
+
export { computeModelCostMinorUnits } from "./pricing.js";
|
|
97
|
+
export * from "./streaming.js";
|
|
98
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model platform — `docs/03-intelligence-runtime.md`.
|
|
3
|
+
*
|
|
4
|
+
* Provider-neutral. Agents state a policy and a role; they never hardcode model IDs.
|
|
5
|
+
*/
|
|
6
|
+
import { AgentPlatformError } from "../core/errors.js";
|
|
7
|
+
export const MODEL_PROVIDERS = [
|
|
8
|
+
"openai",
|
|
9
|
+
"anthropic",
|
|
10
|
+
"google",
|
|
11
|
+
"mistral",
|
|
12
|
+
"azure-openai",
|
|
13
|
+
"bedrock",
|
|
14
|
+
"openai-compatible",
|
|
15
|
+
];
|
|
16
|
+
const covers = (have, need) => need.every((n) => have.includes(n));
|
|
17
|
+
/** A model is eligible when it clears every hard constraint in the policy. */
|
|
18
|
+
const eligible = (m, p) => {
|
|
19
|
+
if (m.lifecycle === "retired")
|
|
20
|
+
return false;
|
|
21
|
+
if (p.allowedProviders && !p.allowedProviders.includes(m.provider))
|
|
22
|
+
return false;
|
|
23
|
+
if (p.requiredModalities && !covers(m.inputModalities, p.requiredModalities))
|
|
24
|
+
return false;
|
|
25
|
+
if (p.dataResidency && !covers(m.dataResidency, p.dataResidency))
|
|
26
|
+
return false;
|
|
27
|
+
if (p.requiredCapabilities) {
|
|
28
|
+
for (const key of Object.keys(p.requiredCapabilities)) {
|
|
29
|
+
if (p.requiredCapabilities[key] && !m.capabilities[key])
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// Cost ceiling is honored at resolution as an output-price ceiling; the per-run budget is
|
|
34
|
+
// separately enforced at execution by the usage recorder.
|
|
35
|
+
if (p.costCeilingMinorUnits !== undefined && m.pricing.outputPerMillion > p.costCeilingMinorUnits) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
return true;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Resolves a role + constraints to a concrete model using the administrator's role assignments.
|
|
42
|
+
* Agents never name a model, so re-pointing a role here changes no agent code.
|
|
43
|
+
*/
|
|
44
|
+
export const createModelRegistry = (config) => {
|
|
45
|
+
const byId = new Map(config.models.map((m) => [m.modelId, m]));
|
|
46
|
+
return {
|
|
47
|
+
list: () => config.models,
|
|
48
|
+
resolve: (policy) => {
|
|
49
|
+
for (const id of config.roles[policy.role] ?? []) {
|
|
50
|
+
const m = byId.get(id);
|
|
51
|
+
if (m && eligible(m, policy))
|
|
52
|
+
return m;
|
|
53
|
+
}
|
|
54
|
+
throw new AgentPlatformError({
|
|
55
|
+
code: "capability_unavailable",
|
|
56
|
+
message: `No model satisfies role '${policy.role}' with the requested constraints`,
|
|
57
|
+
retryable: false,
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* `provider-factory` is **not** re-exported here — #196.
|
|
64
|
+
*
|
|
65
|
+
* It statically imports six `@ai-sdk/*` packages, so anything that pulls this barrel pulled all six. Since they
|
|
66
|
+
* are optional peers now, a root import must not reach them: a consumer using OpenAI would get a resolution
|
|
67
|
+
* failure for Anthropic. It lives behind the `./providers` subpath instead.
|
|
68
|
+
*/
|
|
69
|
+
// `computeModelCostMinorUnits` moved to `./pricing.ts` (#199): reaching it through this barrel pulled
|
|
70
|
+
// `streaming.js`, and with it the AI SDK, into the in-memory usage adapter. Re-exported here so the models
|
|
71
|
+
// subpath still offers it in one place.
|
|
72
|
+
export { computeModelCostMinorUnits } from "./pricing.js";
|
|
73
|
+
export * from "./streaming.js";
|
|
74
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a unit of usage costs — extracted from the models barrel (#199).
|
|
3
|
+
*
|
|
4
|
+
* Its own module because of what importing it used to drag in. `usage/recorder.ts` needs this one function, and
|
|
5
|
+
* reaching it through `models/index.js` pulled `streaming.js` with it — and `streaming.js` imports `ai`. So the
|
|
6
|
+
* in-memory usage adapter, which needs no model SDK and no network, transitively reached the AI SDK: a consumer
|
|
7
|
+
* importing `@retinue/agentkit/persistence` for an in-memory prototype loaded a provider library to do it.
|
|
8
|
+
*
|
|
9
|
+
* Nothing about the pricing arithmetic connects it to streaming. The barrel was the only thing joining them.
|
|
10
|
+
*/
|
|
11
|
+
import type { ModelPricing } from "./index.js";
|
|
12
|
+
/**
|
|
13
|
+
* Cost of a unit of usage, in the pricing currency's minor units. Prices are per-million tokens.
|
|
14
|
+
* Cached input is billed at the cache-read rate when present. This is what feeds usage accounting.
|
|
15
|
+
*/
|
|
16
|
+
export declare const computeModelCostMinorUnits: (pricing: ModelPricing, usage: {
|
|
17
|
+
readonly inputTokens: number;
|
|
18
|
+
readonly outputTokens: number;
|
|
19
|
+
readonly cachedInputTokens?: number;
|
|
20
|
+
/** Images sent with the turn — counted from the parts, not from the provider. See `NeutralUsage`. */
|
|
21
|
+
readonly imageCount?: number;
|
|
22
|
+
readonly audioSeconds?: number;
|
|
23
|
+
}) => number;
|
|
24
|
+
//# sourceMappingURL=pricing.d.ts.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a unit of usage costs — extracted from the models barrel (#199).
|
|
3
|
+
*
|
|
4
|
+
* Its own module because of what importing it used to drag in. `usage/recorder.ts` needs this one function, and
|
|
5
|
+
* reaching it through `models/index.js` pulled `streaming.js` with it — and `streaming.js` imports `ai`. So the
|
|
6
|
+
* in-memory usage adapter, which needs no model SDK and no network, transitively reached the AI SDK: a consumer
|
|
7
|
+
* importing `@retinue/agentkit/persistence` for an in-memory prototype loaded a provider library to do it.
|
|
8
|
+
*
|
|
9
|
+
* Nothing about the pricing arithmetic connects it to streaming. The barrel was the only thing joining them.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Cost of a unit of usage, in the pricing currency's minor units. Prices are per-million tokens.
|
|
13
|
+
* Cached input is billed at the cache-read rate when present. This is what feeds usage accounting.
|
|
14
|
+
*/
|
|
15
|
+
export const computeModelCostMinorUnits = (pricing, usage) => {
|
|
16
|
+
const cachedIn = usage.cachedInputTokens ?? 0;
|
|
17
|
+
const freshIn = Math.max(0, usage.inputTokens - cachedIn);
|
|
18
|
+
const perMillion = (tokens, price) => (tokens * price) / 1_000_000;
|
|
19
|
+
const tokenCost = perMillion(freshIn, pricing.inputPerMillion) +
|
|
20
|
+
perMillion(cachedIn, pricing.cacheReadPerMillion ?? pricing.inputPerMillion) +
|
|
21
|
+
perMillion(usage.outputTokens, pricing.outputPerMillion);
|
|
22
|
+
/**
|
|
23
|
+
* Non-text input, charged **only** where the provider prices it separately — #185 AC-4.
|
|
24
|
+
*
|
|
25
|
+
* The default is `"in-input-tokens"`, which means the image is already inside `inputTokens` and there is
|
|
26
|
+
* nothing to add. Adding it anyway is the double-bill this branch exists to prevent, and it would not show up
|
|
27
|
+
* in any test that only ever passes text.
|
|
28
|
+
*/
|
|
29
|
+
if (pricing.nonTextInput !== "per-unit")
|
|
30
|
+
return Math.round(tokenCost);
|
|
31
|
+
const images = Math.max(0, usage.imageCount ?? 0);
|
|
32
|
+
const seconds = Math.max(0, usage.audioSeconds ?? 0);
|
|
33
|
+
return Math.round(tokenCost +
|
|
34
|
+
images * (pricing.perImageMinorUnits ?? 0) +
|
|
35
|
+
seconds * (pricing.perAudioSecondMinorUnits ?? 0));
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=pricing.js.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider factory — `docs/03-intelligence-runtime.md`.
|
|
3
|
+
*
|
|
4
|
+
* Turns a resolved `ModelDefinition` into a concrete Vercel AI SDK language model. The AI SDK
|
|
5
|
+
* imports are confined to this `models` layer (enforced by the dependency-boundary check); the
|
|
6
|
+
* rest of the platform speaks the neutral `ModelDefinition`/`ModelPolicy` contracts.
|
|
7
|
+
*
|
|
8
|
+
* Credentials are supplied per provider (supporting a tenant's BYO keys) and never inlined into
|
|
9
|
+
* a model definition.
|
|
10
|
+
*/
|
|
11
|
+
import type { LanguageModel } from "ai";
|
|
12
|
+
import type { ModelDefinition, ModelProvider } from "./index.js";
|
|
13
|
+
/** Per-provider credentials. `apiKey`/`baseURL` fall back to the SDK's env defaults when unset. */
|
|
14
|
+
export type ProviderCredentials = {
|
|
15
|
+
readonly apiKey?: string;
|
|
16
|
+
readonly baseURL?: string;
|
|
17
|
+
/** Azure only. */
|
|
18
|
+
readonly resourceName?: string;
|
|
19
|
+
readonly apiVersion?: string;
|
|
20
|
+
/** A display name for OpenAI-compatible endpoints. */
|
|
21
|
+
readonly name?: string;
|
|
22
|
+
};
|
|
23
|
+
export type ProviderFactoryConfig = {
|
|
24
|
+
readonly credentials?: Partial<Record<ModelProvider, ProviderCredentials>>;
|
|
25
|
+
};
|
|
26
|
+
export interface ProviderFactory {
|
|
27
|
+
/** The AI SDK language model for a resolved definition, ready for generate/stream. */
|
|
28
|
+
languageModel(model: ModelDefinition): LanguageModel;
|
|
29
|
+
}
|
|
30
|
+
export declare const createProviderFactory: (config?: ProviderFactoryConfig) => ProviderFactory;
|
|
31
|
+
//# sourceMappingURL=provider-factory.d.ts.map
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider factory — `docs/03-intelligence-runtime.md`.
|
|
3
|
+
*
|
|
4
|
+
* Turns a resolved `ModelDefinition` into a concrete Vercel AI SDK language model. The AI SDK
|
|
5
|
+
* imports are confined to this `models` layer (enforced by the dependency-boundary check); the
|
|
6
|
+
* rest of the platform speaks the neutral `ModelDefinition`/`ModelPolicy` contracts.
|
|
7
|
+
*
|
|
8
|
+
* Credentials are supplied per provider (supporting a tenant's BYO keys) and never inlined into
|
|
9
|
+
* a model definition.
|
|
10
|
+
*/
|
|
11
|
+
import { createAnthropic } from "@ai-sdk/anthropic";
|
|
12
|
+
import { createAzure } from "@ai-sdk/azure";
|
|
13
|
+
import { createGoogleGenerativeAI } from "@ai-sdk/google";
|
|
14
|
+
import { createMistral } from "@ai-sdk/mistral";
|
|
15
|
+
import { createOpenAI } from "@ai-sdk/openai";
|
|
16
|
+
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
|
17
|
+
import { AgentPlatformError } from "../core/errors.js";
|
|
18
|
+
export const createProviderFactory = (config = {}) => {
|
|
19
|
+
const cred = (p) => config.credentials?.[p] ?? {};
|
|
20
|
+
return {
|
|
21
|
+
languageModel(model) {
|
|
22
|
+
const c = cred(model.provider);
|
|
23
|
+
switch (model.provider) {
|
|
24
|
+
case "openai":
|
|
25
|
+
return createOpenAI({ apiKey: c.apiKey, baseURL: c.baseURL })(model.modelId);
|
|
26
|
+
case "anthropic":
|
|
27
|
+
return createAnthropic({ apiKey: c.apiKey, baseURL: c.baseURL })(model.modelId);
|
|
28
|
+
case "google":
|
|
29
|
+
return createGoogleGenerativeAI({ apiKey: c.apiKey, baseURL: c.baseURL })(model.modelId);
|
|
30
|
+
case "mistral":
|
|
31
|
+
return createMistral({ apiKey: c.apiKey, baseURL: c.baseURL })(model.modelId);
|
|
32
|
+
case "azure-openai":
|
|
33
|
+
return createAzure({
|
|
34
|
+
apiKey: c.apiKey,
|
|
35
|
+
resourceName: c.resourceName,
|
|
36
|
+
baseURL: c.baseURL,
|
|
37
|
+
apiVersion: c.apiVersion,
|
|
38
|
+
})(model.modelId);
|
|
39
|
+
case "openai-compatible":
|
|
40
|
+
if (!c.baseURL) {
|
|
41
|
+
throw new AgentPlatformError({
|
|
42
|
+
code: "capability_unavailable",
|
|
43
|
+
message: "openai-compatible provider requires a baseURL credential",
|
|
44
|
+
retryable: false,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return createOpenAICompatible({ name: c.name ?? "openai-compatible", baseURL: c.baseURL, apiKey: c.apiKey })(model.modelId);
|
|
48
|
+
case "bedrock":
|
|
49
|
+
// Bedrock wiring (@ai-sdk/amazon-bedrock + AWS credentials) is a follow-up.
|
|
50
|
+
throw new AgentPlatformError({
|
|
51
|
+
code: "capability_unavailable",
|
|
52
|
+
message: "Amazon Bedrock provider is not wired yet",
|
|
53
|
+
retryable: false,
|
|
54
|
+
});
|
|
55
|
+
default: {
|
|
56
|
+
const exhaustive = model.provider;
|
|
57
|
+
throw new AgentPlatformError({
|
|
58
|
+
code: "capability_unavailable",
|
|
59
|
+
message: `Unknown provider ${String(exhaustive)}`,
|
|
60
|
+
retryable: false,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=provider-factory.js.map
|