@deepstrike/sdk 0.2.52 → 0.2.61

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.
Files changed (151) hide show
  1. package/README.md +28 -28
  2. package/dist/agent-ir.d.ts +103 -0
  3. package/dist/agent-ir.js +134 -0
  4. package/dist/agent.d.ts +67 -0
  5. package/dist/agent.js +36 -0
  6. package/dist/collaboration/harness.js +1 -1
  7. package/dist/collaboration/modes/creator-verifier.d.ts +2 -7
  8. package/dist/collaboration/modes/creator-verifier.js +4 -6
  9. package/dist/collaboration/pool.d.ts +8 -20
  10. package/dist/collaboration/pool.js +27 -97
  11. package/dist/compat/anthropic/mcp.d.ts +15 -0
  12. package/dist/compat/anthropic/mcp.js +10 -0
  13. package/dist/compat/openai/agent.d.ts +34 -0
  14. package/dist/compat/openai/agent.js +24 -0
  15. package/dist/governance.d.ts +1 -17
  16. package/dist/governance.js +1 -34
  17. package/dist/guardrail.d.ts +6 -0
  18. package/dist/guardrail.js +1 -0
  19. package/dist/handoff-target.d.ts +12 -0
  20. package/dist/handoff-target.js +1 -0
  21. package/dist/harness/manifest.js +0 -4
  22. package/dist/index.d.ts +19 -7
  23. package/dist/index.js +8 -5
  24. package/dist/kernel.d.ts +2 -20
  25. package/dist/knowledge/public.d.ts +29 -0
  26. package/dist/knowledge/public.js +1 -0
  27. package/dist/mcp-server.d.ts +28 -0
  28. package/dist/mcp-server.js +1 -0
  29. package/dist/memory/agent.d.ts +2 -2
  30. package/dist/memory/agent.js +2 -2
  31. package/dist/memory/durable.d.ts +16 -0
  32. package/dist/memory/durable.js +46 -0
  33. package/dist/memory/in-memory-store.d.ts +9 -7
  34. package/dist/memory/in-memory-store.js +8 -2
  35. package/dist/memory/protocols.d.ts +22 -4
  36. package/dist/memory/public.d.ts +4 -3
  37. package/dist/memory/public.js +3 -2
  38. package/dist/os/public.d.ts +1 -1
  39. package/dist/os/public.js +1 -1
  40. package/dist/providers/anthropic-adapter.d.ts +59 -0
  41. package/dist/providers/anthropic-adapter.js +530 -0
  42. package/dist/providers/anthropic-compatible.d.ts +2 -3
  43. package/dist/providers/anthropic-compatible.js +8 -5
  44. package/dist/providers/anthropic.d.ts +20 -23
  45. package/dist/providers/anthropic.js +176 -395
  46. package/dist/providers/base.d.ts +2 -2
  47. package/dist/providers/base.js +50 -8
  48. package/dist/providers/capability-router.d.ts +29 -0
  49. package/dist/providers/capability-router.js +43 -0
  50. package/dist/providers/catalog.d.ts +16 -4
  51. package/dist/providers/catalog.js +112 -36
  52. package/dist/providers/content-normalization.d.ts +57 -0
  53. package/dist/providers/content-normalization.js +238 -0
  54. package/dist/providers/content-policy.d.ts +16 -0
  55. package/dist/providers/content-policy.js +39 -0
  56. package/dist/providers/credentials.d.ts +83 -0
  57. package/dist/providers/credentials.js +190 -0
  58. package/dist/providers/endpoints.d.ts +137 -0
  59. package/dist/providers/endpoints.js +128 -0
  60. package/dist/providers/factories.js +25 -9
  61. package/dist/providers/gemini-adapter.d.ts +33 -0
  62. package/dist/providers/gemini-adapter.js +264 -0
  63. package/dist/providers/gemini.d.ts +16 -3
  64. package/dist/providers/gemini.js +97 -195
  65. package/dist/providers/model-catalog.d.ts +37 -0
  66. package/dist/providers/model-catalog.js +62 -0
  67. package/dist/providers/model-registry.d.ts +119 -0
  68. package/dist/providers/model-registry.js +379 -0
  69. package/dist/providers/ollama-adapter.d.ts +65 -0
  70. package/dist/providers/ollama-adapter.js +188 -0
  71. package/dist/providers/ollama.d.ts +9 -4
  72. package/dist/providers/ollama.js +96 -109
  73. package/dist/providers/openai-chat-dialects.d.ts +154 -0
  74. package/dist/providers/openai-chat-dialects.js +179 -0
  75. package/dist/providers/openai-chat.d.ts +46 -18
  76. package/dist/providers/openai-chat.js +416 -51
  77. package/dist/providers/openai-responses-adapter.d.ts +42 -0
  78. package/dist/providers/openai-responses-adapter.js +343 -0
  79. package/dist/providers/openai-responses.d.ts +19 -33
  80. package/dist/providers/openai-responses.js +164 -264
  81. package/dist/providers/openai.d.ts +29 -76
  82. package/dist/providers/openai.js +195 -292
  83. package/dist/providers/protocol-adapter.d.ts +39 -0
  84. package/dist/providers/protocol-adapter.js +13 -0
  85. package/dist/providers/protocol-capabilities.d.ts +34 -0
  86. package/dist/providers/protocol-capabilities.js +44 -0
  87. package/dist/providers/provider-error.d.ts +31 -0
  88. package/dist/providers/provider-error.js +153 -0
  89. package/dist/providers/public.d.ts +26 -3
  90. package/dist/providers/public.js +13 -1
  91. package/dist/providers/registry.d.ts +7 -6
  92. package/dist/providers/registry.js +47 -20
  93. package/dist/providers/request-plan.d.ts +89 -0
  94. package/dist/providers/request-plan.js +199 -0
  95. package/dist/providers/usage-normalizer.d.ts +48 -0
  96. package/dist/providers/usage-normalizer.js +139 -0
  97. package/dist/providers/vendor-profiles.d.ts +2 -15
  98. package/dist/providers/vendor-profiles.js +14 -60
  99. package/dist/runtime/canonical-kernel-step.d.ts +1 -2
  100. package/dist/runtime/canonical-kernel-step.js +47 -12
  101. package/dist/runtime/context-policy.d.ts +10 -12
  102. package/dist/runtime/context-policy.js +6 -8
  103. package/dist/runtime/durable-content.d.ts +50 -0
  104. package/dist/runtime/durable-content.js +159 -0
  105. package/dist/runtime/execution-plane.d.ts +2 -2
  106. package/dist/runtime/execution-plane.js +2 -2
  107. package/dist/runtime/kernel-event-log.js +0 -1
  108. package/dist/runtime/kernel-step.d.ts +0 -1
  109. package/dist/runtime/kernel-step.js +4 -2
  110. package/dist/runtime/mcp-proxy-plane.d.ts +25 -1
  111. package/dist/runtime/mcp-proxy-plane.js +44 -6
  112. package/dist/runtime/output-schema.d.ts +1 -2
  113. package/dist/runtime/provider-replay.d.ts +5 -1
  114. package/dist/runtime/provider-replay.js +26 -27
  115. package/dist/runtime/reactive-session.d.ts +1 -1
  116. package/dist/runtime/reactive-session.js +2 -3
  117. package/dist/runtime/run-group.d.ts +1 -1
  118. package/dist/runtime/runner.d.ts +31 -45
  119. package/dist/runtime/runner.js +178 -63
  120. package/dist/runtime/session-log.d.ts +8 -1
  121. package/dist/runtime/session-log.js +42 -2
  122. package/dist/runtime/session-repair.d.ts +1 -1
  123. package/dist/runtime/session-repair.js +1 -1
  124. package/dist/runtime/sub-agent-orchestrator.d.ts +1 -1
  125. package/dist/runtime/sub-agent-orchestrator.js +8 -11
  126. package/dist/runtime/workflow-control-flow.d.ts +0 -4
  127. package/dist/runtime/workflow-control-flow.js +0 -16
  128. package/dist/session.d.ts +11 -0
  129. package/dist/session.js +1 -0
  130. package/dist/skill.d.ts +17 -0
  131. package/dist/skill.js +16 -0
  132. package/dist/skills/loader.d.ts +3 -0
  133. package/dist/tools/errors.d.ts +1 -3
  134. package/dist/tools/errors.js +1 -3
  135. package/dist/tools/index.d.ts +3 -0
  136. package/dist/types/agent.d.ts +21 -9
  137. package/dist/types/agent.js +30 -4
  138. package/dist/types.d.ts +135 -17
  139. package/package.json +4 -4
  140. package/dist/providers/deepseek.d.ts +0 -46
  141. package/dist/providers/deepseek.js +0 -97
  142. package/dist/providers/glm.d.ts +0 -25
  143. package/dist/providers/glm.js +0 -48
  144. package/dist/providers/kimi.d.ts +0 -23
  145. package/dist/providers/kimi.js +0 -30
  146. package/dist/providers/minimax.d.ts +0 -49
  147. package/dist/providers/minimax.js +0 -98
  148. package/dist/providers/profiles.d.ts +0 -1992
  149. package/dist/providers/profiles.js +0 -796
  150. package/dist/providers/qwen.d.ts +0 -38
  151. package/dist/providers/qwen.js +0 -97
@@ -0,0 +1,44 @@
1
+ export const ANTHROPIC_PROTOCOL_CAPABILITIES = {
2
+ acceptedInputModalities: ["text", "image"],
3
+ emittedOutputModalities: ["text"],
4
+ tools: true,
5
+ parallelToolCalls: true,
6
+ structuredOutput: false,
7
+ reasoningReplay: "required",
8
+ promptCaching: true,
9
+ mediaForms: { imageUrl: true, imageBase64: true },
10
+ };
11
+ export const GEMINI_PROTOCOL_CAPABILITIES = {
12
+ acceptedInputModalities: ["text", "image", "audio"],
13
+ emittedOutputModalities: ["text"],
14
+ tools: true,
15
+ reasoningReplay: "none",
16
+ mediaForms: { imageUrl: true, imageBase64: true, audioBase64: true },
17
+ };
18
+ export const OLLAMA_PROTOCOL_CAPABILITIES = {
19
+ acceptedInputModalities: ["text", "image"],
20
+ emittedOutputModalities: ["text"],
21
+ tools: true,
22
+ reasoningReplay: "none",
23
+ mediaForms: { imageBase64: true },
24
+ };
25
+ export const OPENAI_RESPONSES_PROTOCOL_CAPABILITIES = {
26
+ acceptedInputModalities: ["text", "image", "file"],
27
+ emittedOutputModalities: ["text"],
28
+ tools: true,
29
+ parallelToolCalls: true,
30
+ structuredOutput: true,
31
+ reasoningReplay: "optional",
32
+ promptCaching: true,
33
+ mediaForms: { imageUrl: true, imageBase64: true, fileId: true },
34
+ };
35
+ export const OPENAI_CHAT_PROTOCOL_CAPABILITIES = {
36
+ acceptedInputModalities: ["text", "image", "audio"],
37
+ emittedOutputModalities: ["text"],
38
+ tools: true,
39
+ parallelToolCalls: true,
40
+ structuredOutput: true,
41
+ reasoningReplay: "optional",
42
+ promptCaching: true,
43
+ mediaForms: { imageUrl: true, imageBase64: true, audioBase64: true },
44
+ };
@@ -0,0 +1,31 @@
1
+ export type ProviderErrorKind = "transport" | "auth" | "rate_limit" | "context_overflow" | "invalid_request" | "modality" | "model_unavailable" | "protocol" | "unknown";
2
+ export interface ProviderErrorOptions {
3
+ provider: string;
4
+ kind: ProviderErrorKind;
5
+ retryable: boolean;
6
+ message: string;
7
+ httpStatus?: number;
8
+ providerCode?: string;
9
+ cause?: unknown;
10
+ }
11
+ /** Stable provider-failure contract. Only the named scalar fields cross the host ABI. */
12
+ export declare class ProviderError extends Error {
13
+ readonly provider: string;
14
+ readonly kind: ProviderErrorKind;
15
+ readonly retryable: boolean;
16
+ readonly httpStatus?: number;
17
+ readonly providerCode?: string;
18
+ readonly cause: unknown;
19
+ constructor(options: ProviderErrorOptions);
20
+ }
21
+ export declare function classifyProviderError(provider: string, error: unknown): ProviderError;
22
+ export declare function circuitOpenError(provider: string): ProviderError;
23
+ /** Safe scalar projection for runner → canonical-host events. */
24
+ export declare function providerErrorEventFields(error: unknown): {
25
+ error_kind?: ProviderErrorKind;
26
+ retryable?: boolean;
27
+ http_status?: number;
28
+ provider_code?: string;
29
+ };
30
+ /** Provider errors expose their stable message without serializing the retained SDK cause. */
31
+ export declare function providerErrorMessage(error: unknown, fallback: (value: unknown) => string): string;
@@ -0,0 +1,153 @@
1
+ /** Stable provider-failure contract. Only the named scalar fields cross the host ABI. */
2
+ export class ProviderError extends Error {
3
+ provider;
4
+ kind;
5
+ retryable;
6
+ httpStatus;
7
+ providerCode;
8
+ cause;
9
+ constructor(options) {
10
+ super(options.message, options.cause === undefined ? undefined : { cause: options.cause });
11
+ this.name = "ProviderError";
12
+ this.provider = options.provider;
13
+ this.kind = options.kind;
14
+ this.retryable = options.retryable;
15
+ this.httpStatus = options.httpStatus;
16
+ this.providerCode = options.providerCode;
17
+ this.cause = options.cause;
18
+ }
19
+ }
20
+ const CONTEXT_OVERFLOW_CODES = new Set([
21
+ "context_length_exceeded",
22
+ "prompt_too_long",
23
+ ]);
24
+ const NETWORK_CODES = new Set([
25
+ "ECONNABORTED",
26
+ "ECONNREFUSED",
27
+ "ECONNRESET",
28
+ "EHOSTUNREACH",
29
+ "ENETUNREACH",
30
+ "ETIMEDOUT",
31
+ ]);
32
+ function object(value) {
33
+ return value && typeof value === "object" ? value : undefined;
34
+ }
35
+ function scalarString(value) {
36
+ return typeof value === "string" && value.length > 0 ? value : undefined;
37
+ }
38
+ function scalarStatus(value) {
39
+ return typeof value === "number" && Number.isInteger(value) && value >= 100 && value <= 599
40
+ ? value
41
+ : undefined;
42
+ }
43
+ function errorStatus(error) {
44
+ const outer = object(error);
45
+ const response = object(outer?.response);
46
+ return scalarStatus(outer?.httpStatus)
47
+ ?? scalarStatus(outer?.status)
48
+ ?? scalarStatus(response?.status);
49
+ }
50
+ function errorCode(error) {
51
+ const outer = object(error);
52
+ const nested = object(outer?.error);
53
+ const nestedError = object(nested?.error);
54
+ const body = object(outer?.body);
55
+ const bodyError = object(body?.error);
56
+ return scalarString(outer?.providerCode)
57
+ ?? scalarString(outer?.code)
58
+ ?? scalarString(outer?.error_code)
59
+ ?? scalarString(nested?.code)
60
+ ?? scalarString(nested?.error_code)
61
+ ?? scalarString(nestedError?.code)
62
+ ?? scalarString(nestedError?.error_code)
63
+ ?? scalarString(nestedError?.type)
64
+ ?? scalarString(bodyError?.code)
65
+ ?? scalarString(bodyError?.error_code);
66
+ }
67
+ function errorMessage(error) {
68
+ if (error instanceof Error && error.message)
69
+ return error.message;
70
+ return typeof error === "string" ? error : "Provider request failed";
71
+ }
72
+ function classifyKind(error, status, code) {
73
+ if (status === 413 || (code && CONTEXT_OVERFLOW_CODES.has(code.toLowerCase())))
74
+ return "context_overflow";
75
+ const name = error instanceof Error ? error.name : scalarString(object(error)?.name);
76
+ if (name === "UnsupportedModalityError")
77
+ return "modality";
78
+ if (name === "ProtocolResponseError")
79
+ return "protocol";
80
+ if (name === "ContentValidationError" || name === "ProviderReplayValidationError") {
81
+ return "invalid_request";
82
+ }
83
+ if (name === "APIConnectionError" || name === "APIConnectionTimeoutError")
84
+ return "transport";
85
+ if (status === 401 || status === 403)
86
+ return "auth";
87
+ if (status === 429)
88
+ return "rate_limit";
89
+ if (code === "model_not_found" || status === 404 || (status !== undefined && status >= 500)) {
90
+ return "model_unavailable";
91
+ }
92
+ if (status === 408 || status === 409)
93
+ return "transport";
94
+ if (status === 400 || status === 422)
95
+ return "invalid_request";
96
+ const normalizedCode = code?.toUpperCase();
97
+ if (normalizedCode && NETWORK_CODES.has(normalizedCode))
98
+ return "transport";
99
+ if (error instanceof TypeError && status === undefined)
100
+ return "transport";
101
+ return "unknown";
102
+ }
103
+ function retryable(kind, status) {
104
+ if (kind === "transport" || kind === "rate_limit" || kind === "model_unavailable")
105
+ return true;
106
+ if (kind === "unknown" && status !== undefined)
107
+ return status >= 500 && status !== 501;
108
+ return false;
109
+ }
110
+ export function classifyProviderError(provider, error) {
111
+ if (error instanceof ProviderError)
112
+ return error;
113
+ const httpStatus = errorStatus(error);
114
+ const providerCode = errorCode(error);
115
+ const kind = classifyKind(error, httpStatus, providerCode);
116
+ const explicitProtocolRetryable = kind === "protocol"
117
+ && typeof object(error)?.retryable === "boolean"
118
+ ? object(error).retryable
119
+ : undefined;
120
+ return new ProviderError({
121
+ provider,
122
+ kind,
123
+ retryable: explicitProtocolRetryable ?? retryable(kind, httpStatus),
124
+ message: errorMessage(error),
125
+ ...(httpStatus !== undefined ? { httpStatus } : {}),
126
+ ...(providerCode !== undefined ? { providerCode } : {}),
127
+ cause: error,
128
+ });
129
+ }
130
+ export function circuitOpenError(provider) {
131
+ return new ProviderError({
132
+ provider,
133
+ kind: "model_unavailable",
134
+ retryable: true,
135
+ providerCode: "circuit_open",
136
+ message: "Circuit breaker open",
137
+ });
138
+ }
139
+ /** Safe scalar projection for runner → canonical-host events. */
140
+ export function providerErrorEventFields(error) {
141
+ if (!(error instanceof ProviderError))
142
+ return {};
143
+ return {
144
+ error_kind: error.kind,
145
+ retryable: error.retryable,
146
+ ...(error.httpStatus !== undefined ? { http_status: error.httpStatus } : {}),
147
+ ...(error.providerCode !== undefined ? { provider_code: error.providerCode } : {}),
148
+ };
149
+ }
150
+ /** Provider errors expose their stable message without serializing the retained SDK cause. */
151
+ export function providerErrorMessage(error, fallback) {
152
+ return error instanceof ProviderError ? error.message : fallback(error);
153
+ }
@@ -3,8 +3,31 @@ export type { BackendProviderOptions } from "./factories.js";
3
3
  export { OpenAIChatProvider } from "./openai.js";
4
4
  export { CircuitBreaker } from "./base.js";
5
5
  export { OpenAIResponsesAdapter } from "./openai-responses.js";
6
- export type { OpenAIResponsesRunState } from "./openai-responses.js";
6
+ export type { OpenAIResponsesRequestPlan, OpenAIResponsesRunState, OpenAIResponsesStreamState, } from "./openai-responses.js";
7
7
  export { OpenAIChatAdapter } from "./openai-chat.js";
8
- export { endpointProfiles, modelProfiles, getModelProfile } from "./profiles.js";
9
- export type { ModelProfileId, ProviderId } from "./profiles.js";
8
+ export { openAIChatDialects } from "./openai-chat-dialects.js";
9
+ export type { OpenAIChatDialectId, OpenAIChatWireDialect } from "./openai-chat-dialects.js";
10
+ export { GeminiAdapter } from "./gemini-adapter.js";
11
+ export { OllamaAdapter, OllamaNdjsonDecoder } from "./ollama-adapter.js";
12
+ export type { GeminiRequestPlan, GeminiStreamState, } from "./gemini-adapter.js";
13
+ export { ProtocolResponseError } from "./protocol-adapter.js";
14
+ export { ProviderError, classifyProviderError, } from "./provider-error.js";
15
+ export type { ProviderErrorKind, ProviderErrorOptions } from "./provider-error.js";
16
+ export type { AdapterDecodeInput, AdapterOutput, AdapterStreamInput, CanonicalStopReason, ProtocolAdapter, } from "./protocol-adapter.js";
17
+ export { endpointProfiles } from "./endpoints.js";
18
+ export type { EndpointProfile, EndpointProfileId, EndpointProtocol, ProviderId } from "./endpoints.js";
19
+ export { ContentPolicyError, contentDispositionFor } from "./content-policy.js";
20
+ export type { ContentDisposition, ContentPlacement } from "./content-policy.js";
21
+ export { CapabilityRouter } from "./capability-router.js";
22
+ export type { CapabilityRequirement, CapabilityRouteResult } from "./capability-router.js";
23
+ export { createProviderRequestPlan, createProviderRequestPlanForProvider, estimateProviderPromptTokens, measurementForPlan, normalizeProviderUsage, priceProviderUsage, recordPromptMeasurement } from "./request-plan.js";
24
+ export type { CostObservation, NormalizedProviderUsage, PricingSnapshot, ProviderRequestEndpoint, ProviderRequestPlan, RecordedPromptMeasurement } from "./request-plan.js";
25
+ export { CredentialResolutionError, OAuthCredentialResolver, redactCredential, resolveCredential } from "./credentials.js";
26
+ export type { CredentialOptions, CredentialRequest, CredentialResolver, OAuthAccessToken, OAuthCredentialResolverOptions, OAuthRefreshRequest, ProviderCredential, } from "./credentials.js";
27
+ export { DynamicModelCatalog, StaticModelCatalog } from "./model-catalog.js";
28
+ export type { ModelCatalog, ModelCatalogRefreshResult, ModelCatalogSource } from "./model-catalog.js";
29
+ export { modelRegistry, resolveEffectiveCapability } from "./model-registry.js";
30
+ export { ContentValidationError, ToolResultProjectionConflictError, normalizeCanonicalContext, normalizeCanonicalAdapterInput, normalizeToolResultPart, projectToolOutputToText, validateCanonicalAdapterInput, } from "./content-normalization.js";
31
+ export type { CanonicalAdapterInput, CanonicalMessage, CanonicalMessageBlock, CanonicalRenderedContext, CanonicalToolResult, } from "./content-normalization.js";
32
+ export type { CapabilityState, EffectiveCapability, EffectiveModelCapabilities, GenerationProtocol, ModelDescriptor, ModelKind, ModelRegistration, ResolvedProviderRuntime, } from "./model-registry.js";
10
33
  export type { ProviderRunState, ProviderToolSpec, ProviderReplay, RenderedContext, CacheBreakpointStrategy } from "../types.js";
@@ -8,4 +8,16 @@ export { OpenAIChatProvider } from "./openai.js";
8
8
  export { CircuitBreaker } from "./base.js";
9
9
  export { OpenAIResponsesAdapter } from "./openai-responses.js";
10
10
  export { OpenAIChatAdapter } from "./openai-chat.js";
11
- export { endpointProfiles, modelProfiles, getModelProfile } from "./profiles.js";
11
+ export { openAIChatDialects } from "./openai-chat-dialects.js";
12
+ export { GeminiAdapter } from "./gemini-adapter.js";
13
+ export { OllamaAdapter, OllamaNdjsonDecoder } from "./ollama-adapter.js";
14
+ export { ProtocolResponseError } from "./protocol-adapter.js";
15
+ export { ProviderError, classifyProviderError, } from "./provider-error.js";
16
+ export { endpointProfiles } from "./endpoints.js";
17
+ export { ContentPolicyError, contentDispositionFor } from "./content-policy.js";
18
+ export { CapabilityRouter } from "./capability-router.js";
19
+ export { createProviderRequestPlan, createProviderRequestPlanForProvider, estimateProviderPromptTokens, measurementForPlan, normalizeProviderUsage, priceProviderUsage, recordPromptMeasurement } from "./request-plan.js";
20
+ export { CredentialResolutionError, OAuthCredentialResolver, redactCredential, resolveCredential } from "./credentials.js";
21
+ export { DynamicModelCatalog, StaticModelCatalog } from "./model-catalog.js";
22
+ export { modelRegistry, resolveEffectiveCapability } from "./model-registry.js";
23
+ export { ContentValidationError, ToolResultProjectionConflictError, normalizeCanonicalContext, normalizeCanonicalAdapterInput, normalizeToolResultPart, projectToolOutputToText, validateCanonicalAdapterInput, } from "./content-normalization.js";
@@ -1,18 +1,19 @@
1
- import type { LLMProvider } from "../types.js";
1
+ import type { LLMProvider, RuntimePolicy } from "../types.js";
2
+ import type { EndpointProtocol, ProviderId } from "./endpoints.js";
2
3
  export type ProviderRetry = {
3
4
  maxRetries: number;
4
5
  baseDelay: number;
5
6
  };
6
- /** Constructs a provider for one `(providerId, endpointProtocol)` pair. The lambda absorbs the
7
- * per-class constructor-shape differences (e.g. AnthropicProvider takes a `{ baseURL }` options
8
- * object, the rest take a positional `baseURL` string). */
9
- export type ProviderMaker = (apiKey: string, model: string | undefined, retry: ProviderRetry | undefined, baseURL: string | undefined) => LLMProvider;
7
+ /** Constructs a provider for one `(providerId, endpointProtocol)` pair. */
8
+ export type ProviderMaker = (apiKey: string, model: string | undefined, retry: ProviderRetry | undefined, baseURL: string | undefined, runtimePolicy: RuntimePolicy | undefined, authMode?: "api_key" | "bearer") => LLMProvider;
10
9
  /** Build the registry key for a `(providerId, endpointProtocol)` pair. */
11
10
  export declare function providerRegistryKey(providerId: string, protocol: string): string;
11
+ /** OAuth bearer is opt-in per provider/protocol. Compatible endpoints do not inherit this policy. */
12
+ export declare function supportsBearerCredential(providerId: ProviderId, protocol: EndpointProtocol): boolean;
12
13
  /**
13
14
  * Single source of truth for which provider class backs each `(vendor, wire)` pair. Consumed by
14
15
  * both `createProvider` (catalog) and the per-backend factory functions, so the two can no longer
15
16
  * drift. Adding a vendor/wire = add a row here (+ its `vendor-profiles` / `endpointProfiles` data) —
16
- * no dispatch branch to edit. Values are the same named classes as before, so `instanceof` holds.
17
+ * no dispatch branch to edit. Compatible rows are generated from dialect/profile data.
17
18
  */
18
19
  export declare const PROVIDER_REGISTRY: Record<string, ProviderMaker>;
@@ -1,35 +1,62 @@
1
1
  import { AnthropicProvider } from "./anthropic.js";
2
2
  import { OpenAIChatProvider } from "./openai.js";
3
3
  import { OpenAIResponsesProvider } from "./openai-responses.js";
4
- import { DeepSeekProvider, DeepSeekAnthropicProvider } from "./deepseek.js";
5
- import { KimiProvider, KimiAnthropicProvider } from "./kimi.js";
6
- import { QwenProvider, QwenAnthropicProvider } from "./qwen.js";
7
- import { GLMProvider, GLMAnthropicProvider } from "./glm.js";
8
- import { MiniMaxOpenAIProvider, MiniMaxAnthropicProvider } from "./minimax.js";
4
+ import { AnthropicCompatibleProvider } from "./anthropic-compatible.js";
9
5
  import { GeminiProvider } from "./gemini.js";
6
+ import { OllamaProvider } from "./ollama.js";
7
+ import { openAIChatDialects } from "./openai-chat-dialects.js";
8
+ import { endpointProfiles } from "./endpoints.js";
9
+ import { anthropicVendorProfiles } from "./vendor-profiles.js";
10
10
  /** Build the registry key for a `(providerId, endpointProtocol)` pair. */
11
11
  export function providerRegistryKey(providerId, protocol) {
12
12
  return `${providerId}:${protocol}`;
13
13
  }
14
+ /** OAuth bearer is opt-in per provider/protocol. Compatible endpoints do not inherit this policy. */
15
+ export function supportsBearerCredential(providerId, protocol) {
16
+ return (providerId === "openai" && (protocol === "openai-chat" || protocol === "openai-responses"))
17
+ || (providerId === "anthropic" && protocol === "anthropic-messages");
18
+ }
19
+ function openAIChatMaker(dialectId) {
20
+ const dialect = openAIChatDialects[dialectId];
21
+ return (apiKey, model, retry, baseURL, runtimePolicy, authMode) => new OpenAIChatProvider({
22
+ apiKey,
23
+ model,
24
+ retry,
25
+ baseURL: baseURL ?? endpointProfiles[dialect.endpointId].baseURL,
26
+ runtimePolicy,
27
+ dialect,
28
+ authMode,
29
+ });
30
+ }
31
+ const openAIChatRegistry = Object.fromEntries(Object.values(openAIChatDialects).map(dialect => [
32
+ providerRegistryKey(dialect.providerId, "openai-chat"),
33
+ openAIChatMaker(dialect.id),
34
+ ]));
35
+ function anthropicCompatibleMaker(vendorId) {
36
+ return (apiKey, model, retry, baseURL, runtimePolicy) => new AnthropicCompatibleProvider(anthropicVendorProfiles[vendorId], apiKey, model, retry, baseURL, runtimePolicy);
37
+ }
14
38
  /**
15
39
  * Single source of truth for which provider class backs each `(vendor, wire)` pair. Consumed by
16
40
  * both `createProvider` (catalog) and the per-backend factory functions, so the two can no longer
17
41
  * drift. Adding a vendor/wire = add a row here (+ its `vendor-profiles` / `endpointProfiles` data) —
18
- * no dispatch branch to edit. Values are the same named classes as before, so `instanceof` holds.
42
+ * no dispatch branch to edit. Compatible rows are generated from dialect/profile data.
19
43
  */
20
44
  export const PROVIDER_REGISTRY = {
21
- "anthropic:anthropic-messages": (k, m, r, b) => new AnthropicProvider(k, m, r, { baseURL: b }),
22
- "openai:openai-chat": (k, m, r, b) => new OpenAIChatProvider(k, m, r, b),
23
- "openai:openai-responses": (k, m, r, b) => new OpenAIResponsesProvider(k, m, r, b),
24
- "deepseek:openai-chat": (k, m, r, b) => new DeepSeekProvider(k, m, r, b),
25
- "deepseek:anthropic-messages": (k, m, r, b) => new DeepSeekAnthropicProvider(k, m, r, b),
26
- "kimi:openai-chat": (k, m, r, b) => new KimiProvider(k, m, r, b),
27
- "kimi:anthropic-messages": (k, m, r, b) => new KimiAnthropicProvider(k, m, r, b),
28
- "qwen:openai-chat": (k, m, r, b) => new QwenProvider(k, m, r, b),
29
- "qwen:anthropic-messages": (k, m, r, b) => new QwenAnthropicProvider(k, m, r, b),
30
- "glm:openai-chat": (k, m, r, b) => new GLMProvider(k, m, r, b),
31
- "glm:anthropic-messages": (k, m, r, b) => new GLMAnthropicProvider(k, m, r, b),
32
- "minimax:openai-chat": (k, m, r, b) => new MiniMaxOpenAIProvider(k, m, r, b),
33
- "minimax:anthropic-messages": (k, m, r, b) => new MiniMaxAnthropicProvider(k, m, r, b),
34
- "gemini:gemini": (k, m, r, b) => new GeminiProvider(k, m, r, b),
45
+ "anthropic:anthropic-messages": (k, m, r, b, p, authMode) => new AnthropicProvider({
46
+ apiKey: k,
47
+ model: m,
48
+ retry: r,
49
+ baseURL: b,
50
+ ...(p ? { runtimePolicy: p } : {}),
51
+ ...(authMode === "bearer" ? { authMode: "bearer" } : {}),
52
+ }),
53
+ "openai:openai-responses": (k, m, r, b, p, authMode) => new OpenAIResponsesProvider(k, m, r, b, p, authMode),
54
+ "deepseek:anthropic-messages": anthropicCompatibleMaker("deepseek"),
55
+ "kimi:anthropic-messages": anthropicCompatibleMaker("kimi"),
56
+ "qwen:anthropic-messages": anthropicCompatibleMaker("qwen"),
57
+ "glm:anthropic-messages": anthropicCompatibleMaker("glm"),
58
+ "minimax:anthropic-messages": anthropicCompatibleMaker("minimax"),
59
+ "gemini:gemini": (k, m, r, b, p) => new GeminiProvider(k, m, r, b, p),
60
+ "ollama:ollama-chat": (_k, m, _r, b, p) => new OllamaProvider(m, b, p),
61
+ ...openAIChatRegistry,
35
62
  };
@@ -0,0 +1,89 @@
1
+ import type { RenderedContext, ToolSchema, ProviderUsage } from "../types.js";
2
+ export interface ProviderRequestEndpoint {
3
+ id: string;
4
+ protocol: string;
5
+ baseURL: string;
6
+ }
7
+ /** One provider-visible request, deliberately excluding credentials and transport-only retries. */
8
+ export interface ProviderRequestPlan {
9
+ providerId: string;
10
+ modelId: string;
11
+ endpoint: ProviderRequestEndpoint;
12
+ context: RenderedContext;
13
+ tools: ToolSchema[];
14
+ options: Record<string, unknown>;
15
+ fingerprint: string;
16
+ stablePrefixFingerprint: string;
17
+ }
18
+ export interface NormalizedProviderUsage extends ProviderUsage {
19
+ /** Input not accounted as a cache read or write. `inputTokens` remains the full footprint. */
20
+ uncachedInputTokens: number;
21
+ }
22
+ /** Durable host fact: a specific logical request was counted before execution. */
23
+ export interface RecordedPromptMeasurement {
24
+ requestFingerprint: string;
25
+ inputTokens: number;
26
+ source: {
27
+ kind: "native";
28
+ provider: string;
29
+ } | {
30
+ kind: "local_exact";
31
+ tokenizer: string;
32
+ } | {
33
+ kind: "postflight";
34
+ } | {
35
+ kind: "heuristic";
36
+ };
37
+ confidence: "exact" | "high_confidence" | "low_confidence";
38
+ }
39
+ export interface PricingSnapshot {
40
+ version: string;
41
+ currency: string;
42
+ region: string;
43
+ effectiveFrom: string;
44
+ expiresAt?: string;
45
+ ratesPerMillion: {
46
+ input: number;
47
+ output: number;
48
+ cacheRead?: number;
49
+ cacheCreation?: number;
50
+ reasoning?: number;
51
+ };
52
+ }
53
+ export type CostObservation = {
54
+ source: "snapshot";
55
+ currency: string;
56
+ amount: number;
57
+ pricingVersion: string;
58
+ } | {
59
+ source: "unpriced";
60
+ reason: "pricing_snapshot_not_effective" | "pricing_snapshot_expired" | "invalid_pricing_snapshot";
61
+ };
62
+ export declare function createProviderRequestPlan(input: Omit<ProviderRequestPlan, "fingerprint" | "stablePrefixFingerprint" | "options"> & {
63
+ options?: Record<string, unknown>;
64
+ }): ProviderRequestPlan;
65
+ /** Build the plan from a resolved provider when the runner only has the public provider object. */
66
+ export declare function createProviderRequestPlanForProvider(provider: {
67
+ descriptor?(): {
68
+ provider: string;
69
+ protocol: string;
70
+ model: string;
71
+ };
72
+ requestPlanIdentity?(): {
73
+ providerId?: string;
74
+ modelId?: string;
75
+ endpoint?: {
76
+ id?: string;
77
+ protocol?: string;
78
+ baseURL?: string;
79
+ };
80
+ };
81
+ }, context: RenderedContext, tools: ToolSchema[], options?: Record<string, unknown>): ProviderRequestPlan;
82
+ export declare function estimateProviderPromptTokens(context: RenderedContext, tools: ToolSchema[]): number;
83
+ /** Bind a preflight count to its exact provider-visible request. Replay only reuses matching facts. */
84
+ export declare function recordPromptMeasurement(plan: Pick<ProviderRequestPlan, "fingerprint">, measurement: Omit<RecordedPromptMeasurement, "requestFingerprint">): RecordedPromptMeasurement;
85
+ export declare function measurementForPlan(plan: Pick<ProviderRequestPlan, "fingerprint">, recorded: RecordedPromptMeasurement | undefined): RecordedPromptMeasurement | undefined;
86
+ /** Normalize postflight provider facts without turning estimates into actual usage. */
87
+ export declare function normalizeProviderUsage(usage: ProviderUsage): NormalizedProviderUsage;
88
+ /** Cost is derived only from an explicit, time-valid host snapshot; otherwise it stays unknown. */
89
+ export declare function priceProviderUsage(usage: NormalizedProviderUsage, snapshot: PricingSnapshot, observedAt?: string | Date): CostObservation;