@cerebriline/llms 0.0.0-stage → 4.100.240

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 (204) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +15 -2
  3. package/dist/catalog/catalog-cline-recommended.d.ts +14 -0
  4. package/dist/catalog/catalog-cline-recommended.d.ts.map +1 -0
  5. package/dist/catalog/catalog-live.d.ts +64 -0
  6. package/dist/catalog/catalog-live.d.ts.map +1 -0
  7. package/dist/catalog/catalog.generated-access.d.ts +5 -0
  8. package/dist/catalog/catalog.generated-access.d.ts.map +1 -0
  9. package/dist/catalog/catalog.generated.d.ts +17 -0
  10. package/dist/catalog/catalog.generated.d.ts.map +1 -0
  11. package/dist/catalog/model-filters.d.ts +9 -0
  12. package/dist/catalog/model-filters.d.ts.map +1 -0
  13. package/dist/catalog/model-id-aliases.d.ts +11 -0
  14. package/dist/catalog/model-id-aliases.d.ts.map +1 -0
  15. package/dist/catalog/model-operation.d.ts +27 -0
  16. package/dist/catalog/model-operation.d.ts.map +1 -0
  17. package/dist/catalog/types.d.ts +367 -0
  18. package/dist/catalog/types.d.ts.map +1 -0
  19. package/dist/index.browser.d.ts +12 -0
  20. package/dist/index.browser.d.ts.map +1 -0
  21. package/dist/index.browser.js +16 -0
  22. package/dist/index.d.ts +30 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +272 -0
  25. package/dist/models.d.ts +10 -0
  26. package/dist/models.d.ts.map +1 -0
  27. package/dist/models.js +241 -0
  28. package/dist/providers/agent-slots.d.ts +100 -0
  29. package/dist/providers/agent-slots.d.ts.map +1 -0
  30. package/dist/providers/ai-sdk.d.ts +158 -0
  31. package/dist/providers/ai-sdk.d.ts.map +1 -0
  32. package/dist/providers/async.d.ts +2 -0
  33. package/dist/providers/async.d.ts.map +1 -0
  34. package/dist/providers/billing.d.ts +5 -0
  35. package/dist/providers/billing.d.ts.map +1 -0
  36. package/dist/providers/builtin-types.d.ts +34 -0
  37. package/dist/providers/builtin-types.d.ts.map +1 -0
  38. package/dist/providers/builtins-runtime.d.ts +3 -0
  39. package/dist/providers/builtins-runtime.d.ts.map +1 -0
  40. package/dist/providers/builtins.d.ts +30 -0
  41. package/dist/providers/builtins.d.ts.map +1 -0
  42. package/dist/providers/compat.d.ts +75 -0
  43. package/dist/providers/compat.d.ts.map +1 -0
  44. package/dist/providers/config.d.ts +521 -0
  45. package/dist/providers/config.d.ts.map +1 -0
  46. package/dist/providers/error-classification.d.ts +23 -0
  47. package/dist/providers/error-classification.d.ts.map +1 -0
  48. package/dist/providers/errors.d.ts +33 -0
  49. package/dist/providers/errors.d.ts.map +1 -0
  50. package/dist/providers/factory-registry.d.ts +92 -0
  51. package/dist/providers/factory-registry.d.ts.map +1 -0
  52. package/dist/providers/format.d.ts +2 -0
  53. package/dist/providers/format.d.ts.map +1 -0
  54. package/dist/providers/gateway.d.ts +123 -0
  55. package/dist/providers/gateway.d.ts.map +1 -0
  56. package/dist/providers/handler.d.ts +75 -0
  57. package/dist/providers/handler.d.ts.map +1 -0
  58. package/dist/providers/http.d.ts +10 -0
  59. package/dist/providers/http.d.ts.map +1 -0
  60. package/dist/providers/ids.d.ts +77 -0
  61. package/dist/providers/ids.d.ts.map +1 -0
  62. package/dist/providers/messages.d.ts +5 -0
  63. package/dist/providers/messages.d.ts.map +1 -0
  64. package/dist/providers/middleware/backoff.d.ts +11 -0
  65. package/dist/providers/middleware/backoff.d.ts.map +1 -0
  66. package/dist/providers/middleware/retry-empty-response.d.ts +74 -0
  67. package/dist/providers/middleware/retry-empty-response.d.ts.map +1 -0
  68. package/dist/providers/middleware/retry-rate-limit.d.ts +49 -0
  69. package/dist/providers/middleware/retry-rate-limit.d.ts.map +1 -0
  70. package/dist/providers/middleware/split-tool-images.d.ts +32 -0
  71. package/dist/providers/middleware/split-tool-images.d.ts.map +1 -0
  72. package/dist/providers/middleware/stream-part-classification.d.ts +33 -0
  73. package/dist/providers/middleware/stream-part-classification.d.ts.map +1 -0
  74. package/dist/providers/model-capabilities.d.ts +15 -0
  75. package/dist/providers/model-capabilities.d.ts.map +1 -0
  76. package/dist/providers/model-facts.d.ts +115 -0
  77. package/dist/providers/model-facts.d.ts.map +1 -0
  78. package/dist/providers/model-operations.d.ts +78 -0
  79. package/dist/providers/model-operations.d.ts.map +1 -0
  80. package/dist/providers/model-registry.d.ts +25 -0
  81. package/dist/providers/model-registry.d.ts.map +1 -0
  82. package/dist/providers/model-tools.d.ts +22 -0
  83. package/dist/providers/model-tools.d.ts.map +1 -0
  84. package/dist/providers/openai-codex-models.d.ts +11 -0
  85. package/dist/providers/openai-codex-models.d.ts.map +1 -0
  86. package/dist/providers/provider-ids.generated.d.ts +13 -0
  87. package/dist/providers/provider-ids.generated.d.ts.map +1 -0
  88. package/dist/providers/provider-keys.d.ts +13 -0
  89. package/dist/providers/provider-keys.d.ts.map +1 -0
  90. package/dist/providers/provider-request-capture.d.ts +10 -0
  91. package/dist/providers/provider-request-capture.d.ts.map +1 -0
  92. package/dist/providers/providers.generated.d.ts +19 -0
  93. package/dist/providers/providers.generated.d.ts.map +1 -0
  94. package/dist/providers/reasoning-history.d.ts +140 -0
  95. package/dist/providers/reasoning-history.d.ts.map +1 -0
  96. package/dist/providers/registry.d.ts +19 -0
  97. package/dist/providers/registry.d.ts.map +1 -0
  98. package/dist/providers/request-headers.d.ts +30 -0
  99. package/dist/providers/request-headers.d.ts.map +1 -0
  100. package/dist/providers/request-timings.d.ts +20 -0
  101. package/dist/providers/request-timings.d.ts.map +1 -0
  102. package/dist/providers/routing/anthropic-compatible.d.ts +35 -0
  103. package/dist/providers/routing/anthropic-compatible.d.ts.map +1 -0
  104. package/dist/providers/routing/bedrock-cache-point.d.ts +26 -0
  105. package/dist/providers/routing/bedrock-cache-point.d.ts.map +1 -0
  106. package/dist/providers/routing/generic-compatible.d.ts +10 -0
  107. package/dist/providers/routing/generic-compatible.d.ts.map +1 -0
  108. package/dist/providers/routing/glm-thinking.d.ts +16 -0
  109. package/dist/providers/routing/glm-thinking.d.ts.map +1 -0
  110. package/dist/providers/routing/minimax-thinking.d.ts +6 -0
  111. package/dist/providers/routing/minimax-thinking.d.ts.map +1 -0
  112. package/dist/providers/routing/portable-reasoning.d.ts +11 -0
  113. package/dist/providers/routing/portable-reasoning.d.ts.map +1 -0
  114. package/dist/providers/routing/provider-option-rules.d.ts +13 -0
  115. package/dist/providers/routing/provider-option-rules.d.ts.map +1 -0
  116. package/dist/providers/routing/provider-options-types.d.ts +57 -0
  117. package/dist/providers/routing/provider-options-types.d.ts.map +1 -0
  118. package/dist/providers/routing/provider-options.d.ts +27 -0
  119. package/dist/providers/routing/provider-options.d.ts.map +1 -0
  120. package/dist/providers/routing/reasoning-codecs.d.ts +4 -0
  121. package/dist/providers/routing/reasoning-codecs.d.ts.map +1 -0
  122. package/dist/providers/routing/reasoning-options.d.ts +8 -0
  123. package/dist/providers/routing/reasoning-options.d.ts.map +1 -0
  124. package/dist/providers/routing/utils.d.ts +31 -0
  125. package/dist/providers/routing/utils.d.ts.map +1 -0
  126. package/dist/providers/sdk-warnings.d.ts +14 -0
  127. package/dist/providers/sdk-warnings.d.ts.map +1 -0
  128. package/dist/providers/server-health.d.ts +66 -0
  129. package/dist/providers/server-health.d.ts.map +1 -0
  130. package/dist/providers/stream.d.ts +124 -0
  131. package/dist/providers/stream.d.ts.map +1 -0
  132. package/dist/providers/types.d.ts +10 -0
  133. package/dist/providers/types.d.ts.map +1 -0
  134. package/dist/providers/url.d.ts +3 -0
  135. package/dist/providers/url.d.ts.map +1 -0
  136. package/dist/providers/utils.d.ts +2 -0
  137. package/dist/providers/utils.d.ts.map +1 -0
  138. package/dist/providers/vendors/anthropic.d.ts +4 -0
  139. package/dist/providers/vendors/anthropic.d.ts.map +1 -0
  140. package/dist/providers/vendors/bedrock.d.ts +24 -0
  141. package/dist/providers/vendors/bedrock.d.ts.map +1 -0
  142. package/dist/providers/vendors/cline.d.ts +37 -0
  143. package/dist/providers/vendors/cline.d.ts.map +1 -0
  144. package/dist/providers/vendors/community.d.ts +8 -0
  145. package/dist/providers/vendors/community.d.ts.map +1 -0
  146. package/dist/providers/vendors/google.d.ts +12 -0
  147. package/dist/providers/vendors/google.d.ts.map +1 -0
  148. package/dist/providers/vendors/llamacpp-sampling.d.ts +130 -0
  149. package/dist/providers/vendors/llamacpp-sampling.d.ts.map +1 -0
  150. package/dist/providers/vendors/llamacpp-timings.d.ts +33 -0
  151. package/dist/providers/vendors/llamacpp-timings.d.ts.map +1 -0
  152. package/dist/providers/vendors/minimax-thinking.d.ts +5 -0
  153. package/dist/providers/vendors/minimax-thinking.d.ts.map +1 -0
  154. package/dist/providers/vendors/mistral.d.ts +4 -0
  155. package/dist/providers/vendors/mistral.d.ts.map +1 -0
  156. package/dist/providers/vendors/ollama-account.d.ts +128 -0
  157. package/dist/providers/vendors/ollama-account.d.ts.map +1 -0
  158. package/dist/providers/vendors/ollama-reachability.d.ts +42 -0
  159. package/dist/providers/vendors/ollama-reachability.d.ts.map +1 -0
  160. package/dist/providers/vendors/ollama-stall-watchdog.d.ts +86 -0
  161. package/dist/providers/vendors/ollama-stall-watchdog.d.ts.map +1 -0
  162. package/dist/providers/vendors/ollama-tool-images.d.ts +67 -0
  163. package/dist/providers/vendors/ollama-tool-images.d.ts.map +1 -0
  164. package/dist/providers/vendors/ollama.d.ts +256 -0
  165. package/dist/providers/vendors/ollama.d.ts.map +1 -0
  166. package/dist/providers/vendors/openai-compatible.d.ts +16 -0
  167. package/dist/providers/vendors/openai-compatible.d.ts.map +1 -0
  168. package/dist/providers/vendors/openai.d.ts +4 -0
  169. package/dist/providers/vendors/openai.d.ts.map +1 -0
  170. package/dist/providers/vendors/opencoti-agent-window.d.ts +44 -0
  171. package/dist/providers/vendors/opencoti-agent-window.d.ts.map +1 -0
  172. package/dist/providers/vendors/opencoti-kv-pressure.d.ts +322 -0
  173. package/dist/providers/vendors/opencoti-kv-pressure.d.ts.map +1 -0
  174. package/dist/providers/vendors/opencoti-liveness.d.ts +177 -0
  175. package/dist/providers/vendors/opencoti-liveness.d.ts.map +1 -0
  176. package/dist/providers/vendors/opencoti-window.d.ts +56 -0
  177. package/dist/providers/vendors/opencoti-window.d.ts.map +1 -0
  178. package/dist/providers/vendors/opencoti.d.ts +335 -0
  179. package/dist/providers/vendors/opencoti.d.ts.map +1 -0
  180. package/dist/providers/vendors/polykv-lead.d.ts +94 -0
  181. package/dist/providers/vendors/polykv-lead.d.ts.map +1 -0
  182. package/dist/providers/vendors/polykv-swarm.d.ts +705 -0
  183. package/dist/providers/vendors/polykv-swarm.d.ts.map +1 -0
  184. package/dist/providers/vendors/polykv.d.ts +958 -0
  185. package/dist/providers/vendors/polykv.d.ts.map +1 -0
  186. package/dist/providers/vendors/types.d.ts +176 -0
  187. package/dist/providers/vendors/types.d.ts.map +1 -0
  188. package/dist/providers/vendors/vertex.d.ts +4 -0
  189. package/dist/providers/vendors/vertex.d.ts.map +1 -0
  190. package/dist/providers/vendors/xollama-engine.d.ts +57 -0
  191. package/dist/providers/vendors/xollama-engine.d.ts.map +1 -0
  192. package/dist/providers/vendors/xollama.d.ts +188 -0
  193. package/dist/providers/vendors/xollama.d.ts.map +1 -0
  194. package/dist/providers.browser.d.ts +3 -0
  195. package/dist/providers.browser.d.ts.map +1 -0
  196. package/dist/providers.browser.js +16 -0
  197. package/dist/providers.d.ts +12 -0
  198. package/dist/providers.d.ts.map +1 -0
  199. package/dist/providers.js +272 -0
  200. package/dist/services/langfuse-telemetry.d.ts +19 -0
  201. package/dist/services/langfuse-telemetry.d.ts.map +1 -0
  202. package/dist/transcription.d.ts +53 -0
  203. package/dist/transcription.d.ts.map +1 -0
  204. package/package.json +84 -5
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Custom Handler Registry
3
+ *
4
+ * Allows users to register their own custom handlers that extend BaseHandler.
5
+ * This is useful for providers that require dependencies not included in this package
6
+ * (e.g., VSCode LM handler that requires the vscode package).
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import { registerHandler, BaseHandler, type ProviderConfig, type ApiStream, type Message } from "@cline/providers"
11
+ * import * as vscode from "vscode"
12
+ *
13
+ * class VSCodeLmHandler extends BaseHandler {
14
+ * async *createMessage(systemPrompt: string, messages: Message[]): ApiStream {
15
+ * // Implementation using vscode.lm API
16
+ * }
17
+ * }
18
+ *
19
+ * // Register the handler
20
+ * registerHandler("vscode-lm", (config) => new VSCodeLmHandler(config))
21
+ *
22
+ * // Now createHandler will use your custom handler for "vscode-lm"
23
+ * const handler = createHandler({ providerId: "vscode-lm", modelId: "copilot" })
24
+ * ```
25
+ */
26
+ import type { ApiHandler, HandlerFactory, LazyHandlerFactory, ProviderConfig } from "./types";
27
+ /**
28
+ * Register a custom handler factory for a provider ID
29
+ *
30
+ * Use this to add handlers for providers that require external dependencies
31
+ * not bundled with this package, or to override built-in handlers.
32
+ *
33
+ * @param providerId - The provider ID to register (can be existing or new)
34
+ * @param factory - Factory function that creates the handler
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * // Simple registration
39
+ * registerHandler("my-provider", (config) => new MyHandler(config))
40
+ *
41
+ * // Override built-in handler
42
+ * registerHandler("anthropic", (config) => new MyCustomAnthropicHandler(config))
43
+ * ```
44
+ */
45
+ export declare function registerHandler(providerId: string, factory: HandlerFactory<ProviderConfig>): void;
46
+ /**
47
+ * Register an async handler factory for lazy loading
48
+ *
49
+ * Use this when your handler has heavy dependencies that should be
50
+ * loaded only when needed.
51
+ *
52
+ * @param providerId - The provider ID to register
53
+ * @param factory - Async factory function that creates the handler
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * registerAsyncHandler("heavy-provider", async (config) => {
58
+ * const { HeavyHandler } = await import("./heavy-handler")
59
+ * return new HeavyHandler(config)
60
+ * })
61
+ * ```
62
+ */
63
+ export declare function registerAsyncHandler(providerId: string, factory: LazyHandlerFactory<ProviderConfig>): void;
64
+ /**
65
+ * Check if a custom handler is registered for a provider ID
66
+ *
67
+ * @param providerId - The provider ID to check
68
+ */
69
+ export declare function hasRegisteredHandler(providerId: string): boolean;
70
+ /**
71
+ * Get a registered handler (internal use)
72
+ *
73
+ * @param providerId - The provider ID to get
74
+ * @param config - The config to pass to the factory
75
+ * @returns The handler instance, or undefined if not registered
76
+ */
77
+ export declare function getRegisteredHandler(providerId: string, config: ProviderConfig): ApiHandler | undefined;
78
+ /**
79
+ * Get a registered handler asynchronously (internal use)
80
+ *
81
+ * @param providerId - The provider ID to get
82
+ * @param config - The config to pass to the factory
83
+ * @returns The handler instance, or undefined if not registered
84
+ */
85
+ export declare function getRegisteredHandlerAsync(providerId: string, config: ProviderConfig): Promise<ApiHandler | undefined>;
86
+ /**
87
+ * Check if a registered handler is async
88
+ *
89
+ * @param providerId - The provider ID to check
90
+ */
91
+ export declare function isRegisteredHandlerAsync(providerId: string): boolean;
92
+ //# sourceMappingURL=factory-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factory-registry.d.ts","sourceRoot":"","sources":["../../src/providers/factory-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EACX,UAAU,EACV,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,MAAM,SAAS,CAAC;AAejB;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,eAAe,CAC9B,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,cAAc,CAAC,cAAc,CAAC,GACrC,IAAI,CAEN;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,oBAAoB,CACnC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,kBAAkB,CAAC,cAAc,CAAC,GACzC,IAAI,CAEN;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAEhE;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CACnC,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,cAAc,GACpB,UAAU,GAAG,SAAS,CAaxB;AAED;;;;;;GAMG;AACH,wBAAsB,yBAAyB,CAC9C,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,cAAc,GACpB,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAWjC;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAGpE"}
@@ -0,0 +1,2 @@
1
+ export declare function extractErrorMessage(error: unknown): string;
2
+ //# sourceMappingURL=format.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/providers/format.ts"],"names":[],"mappings":"AAEA,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAyJ1D"}
@@ -0,0 +1,123 @@
1
+ import type { AgentModel, AgentModelEvent, GatewayConfig, GatewayModelDefinition, GatewayModelHandleOptions, GatewayModelSelection, GatewayProviderRegistration, GatewayStreamRequest, OutputCapReport } from "@cerebriline/shared";
2
+ import { GatewayRegistry } from "./registry";
3
+ export type * from "@cerebriline/shared";
4
+ /**
5
+ * The synthesized per-turn cap at the window this default was written for.
6
+ *
7
+ * Kept as the anchor of {@link DEFAULT_GATEWAY_OUTPUT_WINDOW_SHARE} rather than
8
+ * as the answer: 32,000 is the right cap for a 128k model and for no other.
9
+ */
10
+ export declare const DEFAULT_GATEWAY_MAX_OUTPUT_TOKENS = 32000;
11
+ /**
12
+ * The per-turn cap to synthesize when the caller asked for none.
13
+ *
14
+ * Only ever a default: an explicitly requested cap (the `num_predict` in the
15
+ * provider settings, or a `maxTokensPerTurn` on the session) is used as-is, and
16
+ * the room left in the window still clamps this.
17
+ *
18
+ * The share applies only where the model publishes no output ceiling of its
19
+ * own, which is where the flat number did the damage: local models declare a
20
+ * window and nothing else, so 32,000 was the whole answer at every window size.
21
+ * A model that does publish one already has a bound its own designers set, and
22
+ * the default's job there is to stay under it rather than to ask for all of it
23
+ * — on Anthropic, `max_tokens` is charged against the per-minute output limit
24
+ * whether or not the reply uses it, so raising a 32,000 request to a model's
25
+ * full 64,000 ceiling would cost throughput and buy nothing.
26
+ */
27
+ export declare function resolveDefaultMaxOutputTokens(model?: Pick<GatewayModelDefinition, "contextWindow" | "maxOutputTokens">): number;
28
+ /**
29
+ * The ceiling a provider named, if the failure was about the output cap.
30
+ *
31
+ * Deliberately narrow: it matches only messages that state a number, so a
32
+ * refusal for any other reason returns undefined and is rethrown untouched.
33
+ */
34
+ export declare function extractRejectedOutputCeiling(error: unknown): number | undefined;
35
+ /** Test seam; also lets a host drop what it learned when settings change. */
36
+ export declare function resetLearnedOutputCeilings(): void;
37
+ /**
38
+ * The smallest remaining-context cap worth sending as an output limit.
39
+ *
40
+ * That term is `contextWindow - estimatedInputTokens - reserve`: a difference of
41
+ * two large numbers, so it carries the estimate's error magnified. When it comes
42
+ * out below a floor, the estimate is the likelier explanation than a genuinely
43
+ * exhausted window -- compaction reads what the provider counted rather than an
44
+ * estimate, and would have fired first if the window were really full.
45
+ *
46
+ * Sending the tiny number anyway is worse than sending none. Observed live: an
47
+ * estimate running 1.7x high walked the cap down to 60 tokens; Ollama sizes an
48
+ * effort-level thinking budget as a share of `num_predict`, so the budget came
49
+ * out at 15 tokens, the forced end-of-thinking sequence spliced into a tool call
50
+ * the model had already started, and the turn died on "expected '{' in tool
51
+ * call" -- reported to the user as reaching the output limit.
52
+ */
53
+ export declare const GATEWAY_MIN_OUTPUT_TOKENS = 1024;
54
+ export interface Gateway {
55
+ registerProvider(registration: GatewayProviderRegistration): this;
56
+ configureProvider(config: NonNullable<GatewayConfig["providerConfigs"]>[number]): this;
57
+ listProviders(): ReturnType<GatewayRegistry["listProviders"]>;
58
+ listModels(providerId?: string): ReturnType<GatewayRegistry["listModels"]>;
59
+ createAgentModel(selection: GatewayModelSelection, options?: GatewayModelHandleOptions): AgentModel;
60
+ stream(request: GatewayStreamRequest): Promise<AsyncIterable<AgentModelEvent>>;
61
+ }
62
+ interface GatewayOutputCapInput {
63
+ /**
64
+ * Skip the process-wide overflow record. Set for every request that is not
65
+ * the conversation's own, whose budget arithmetic says nothing about the
66
+ * conversation's.
67
+ */
68
+ suppressGlobalNotes?: boolean;
69
+ /** The session the overflow record would describe. */
70
+ sessionId?: string;
71
+ requestedMaxTokens?: number;
72
+ model: Pick<GatewayModelDefinition, "contextWindow" | "maxOutputTokens">;
73
+ /**
74
+ * A ceiling the provider named while refusing a cap, for a model whose
75
+ * catalog entry publishes none.
76
+ *
77
+ * A clamp and not a published ceiling, which is why it is its own term
78
+ * rather than a `maxOutputTokens` written onto the model. Writing it there
79
+ * would also tell {@link resolveDefaultMaxOutputTokens} the model declares
80
+ * its own limit, and it would fall back to the flat 32,000 default -- so a
81
+ * model that had just said it accepts 131,072 would be held to a quarter of
82
+ * that. As a clamp the share still sets the number and this only bounds it.
83
+ */
84
+ outputCeilingTokens?: number;
85
+ estimatedInputTokens: number;
86
+ defaultMaxOutputTokens?: number;
87
+ outputReserveTokens?: number;
88
+ minOutputTokens?: number;
89
+ reasoningBudgetTokens?: number;
90
+ onContextOverflow?: (details: {
91
+ contextWindow: number;
92
+ estimatedInputTokens: number;
93
+ reserveTokens: number;
94
+ remainingContext: number;
95
+ minOutputTokens: number;
96
+ }) => void;
97
+ }
98
+ export declare function resolveGatewayRequestMaxTokens(input: GatewayOutputCapInput): number | undefined;
99
+ /**
100
+ * The cap and the term that set it.
101
+ *
102
+ * The cap alone is ambiguous in the one place it has to be acted on: a turn
103
+ * truncated at 32,000 tokens says nothing about whether 32,000 was the window's
104
+ * doing or the request's, and only the first is worth compacting for. The
105
+ * arithmetic that knows is this function's, so the answer is returned rather
106
+ * than reconstructed by a caller comparing numbers it would have to guess at.
107
+ */
108
+ export declare function resolveGatewayOutputCap(input: GatewayOutputCapInput): OutputCapReport;
109
+ export declare class DefaultGateway implements Gateway {
110
+ #private;
111
+ private readonly registry;
112
+ private readonly logger;
113
+ private readonly telemetry;
114
+ constructor(config?: GatewayConfig);
115
+ registerProvider(registration: GatewayProviderRegistration): this;
116
+ configureProvider(config: NonNullable<GatewayConfig["providerConfigs"]>[number]): this;
117
+ listProviders(): import("@cerebriline/shared").GatewayProviderManifest[];
118
+ listModels(providerId?: string): GatewayModelDefinition[];
119
+ createAgentModel(selection: GatewayModelSelection, options?: GatewayModelHandleOptions): AgentModel;
120
+ stream(request: GatewayStreamRequest): Promise<AsyncIterable<AgentModelEvent>>;
121
+ }
122
+ export declare function createGateway(config?: GatewayConfig): DefaultGateway;
123
+ //# sourceMappingURL=gateway.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gateway.d.ts","sourceRoot":"","sources":["../../src/providers/gateway.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Handler Interface Types
3
+ *
4
+ * Core interfaces that all provider handlers must implement.
5
+ */
6
+ import type { Message, ModelInfo, ToolDefinition } from "@cerebriline/shared";
7
+ import type { ApiStream, ApiStreamUsageChunk } from "./stream";
8
+ /**
9
+ * Model information returned by handlers
10
+ */
11
+ export interface HandlerModelInfo {
12
+ /** Model identifier */
13
+ id: string;
14
+ /** Model capabilities and pricing info */
15
+ info: ModelInfo;
16
+ }
17
+ /**
18
+ * Core API Handler interface
19
+ *
20
+ * All providers must implement this interface.
21
+ */
22
+ export interface ApiHandler {
23
+ /**
24
+ * Convert Cline messages into provider-specific message format
25
+ *
26
+ * @param systemPrompt - The system prompt to use
27
+ * @param messages - Conversation history
28
+ * @returns Provider-specific messages payload
29
+ */
30
+ getMessages(systemPrompt: string, messages: Message[]): unknown;
31
+ /**
32
+ * Create a streaming message completion
33
+ *
34
+ * @param systemPrompt - The system prompt to use
35
+ * @param messages - Conversation history
36
+ * @param tools - Optional tool definitions for native tool calling
37
+ * @returns An async generator yielding stream chunks
38
+ */
39
+ createMessage(systemPrompt: string, messages: Message[], tools?: ToolDefinition[]): ApiStream;
40
+ /**
41
+ * Get the current model configuration
42
+ */
43
+ getModel(): HandlerModelInfo;
44
+ /**
45
+ * Get usage information for the last API call (optional)
46
+ * Some providers can fetch this from a separate endpoint
47
+ */
48
+ getApiStreamUsage?(): Promise<ApiStreamUsageChunk | undefined>;
49
+ /**
50
+ * Abort the current request (optional)
51
+ */
52
+ abort?(): void;
53
+ /**
54
+ * Update the abort signal used for subsequent requests (optional).
55
+ */
56
+ setAbortSignal?(signal: AbortSignal | undefined): void;
57
+ }
58
+ /**
59
+ * Handler for simple single-turn completions
60
+ */
61
+ export interface SingleCompletionHandler {
62
+ /**
63
+ * Complete a single prompt without streaming
64
+ */
65
+ completePrompt(prompt: string): Promise<string>;
66
+ }
67
+ /**
68
+ * Factory function type for creating handlers
69
+ */
70
+ export type HandlerFactory<TConfig = unknown> = (config: TConfig) => ApiHandler;
71
+ /**
72
+ * Async factory for lazy-loaded handlers
73
+ */
74
+ export type LazyHandlerFactory<TConfig = unknown> = (config: TConfig) => Promise<ApiHandler>;
75
+ //# sourceMappingURL=handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../src/providers/handler.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACxE,OAAO,KAAK,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAE/D;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAChC,uBAAuB;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,0CAA0C;IAC1C,IAAI,EAAE,SAAS,CAAC;CAChB;AAED;;;;GAIG;AACH,MAAM,WAAW,UAAU;IAC1B;;;;;;OAMG;IACH,WAAW,CAAC,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAEhE;;;;;;;OAOG;IACH,aAAa,CACZ,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,OAAO,EAAE,EACnB,KAAK,CAAC,EAAE,cAAc,EAAE,GACtB,SAAS,CAAC;IAEb;;OAEG;IACH,QAAQ,IAAI,gBAAgB,CAAC;IAE7B;;;OAGG;IACH,iBAAiB,CAAC,IAAI,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC,CAAC;IAE/D;;OAEG;IACH,KAAK,CAAC,IAAI,IAAI,CAAC;IAEf;;OAEG;IACH,cAAc,CAAC,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,GAAG,IAAI,CAAC;CACvD;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACvC;;OAEG;IACH,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAChD;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,CAAC,OAAO,GAAG,OAAO,IAAI,CAAC,MAAM,EAAE,OAAO,KAAK,UAAU,CAAC;AAEhF;;GAEG;AACH,MAAM,MAAM,kBAAkB,CAAC,OAAO,GAAG,OAAO,IAAI,CACnD,MAAM,EAAE,OAAO,KACX,OAAO,CAAC,UAAU,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { GatewayProviderSettings } from "@cerebriline/shared";
2
+ export declare function ensureFetch(fetchImpl?: typeof fetch): typeof fetch;
3
+ export declare function resolveApiKey(settings: GatewayProviderSettings): Promise<string | undefined>;
4
+ export declare function fetchJson(url: string, init: RequestInit, options: {
5
+ fetch: typeof fetch;
6
+ timeoutMs?: number;
7
+ signal?: AbortSignal;
8
+ }): Promise<unknown>;
9
+ export declare function compactObject<T extends Record<string, unknown>>(value: T): T;
10
+ //# sourceMappingURL=http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/providers/http.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAE7D,wBAAgB,WAAW,CAAC,SAAS,CAAC,EAAE,OAAO,KAAK,GAAG,OAAO,KAAK,CAQlE;AAED,wBAAsB,aAAa,CAClC,QAAQ,EAAE,uBAAuB,GAC/B,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAoB7B;AAED,wBAAsB,SAAS,CAC9B,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE;IACR,KAAK,EAAE,OAAO,KAAK,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,WAAW,CAAC;CACrB,GACC,OAAO,CAAC,OAAO,CAAC,CA+BlB;AA0BD,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAI5E"}
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Built-in provider IDs
3
+ *
4
+ * Single source of truth for all built-in provider identifiers.
5
+ * Use BUILT_IN_PROVIDER_IDS for runtime operations (validation, iteration)
6
+ * Use BuiltInProviderId type for compile-time type safety
7
+ */
8
+ import { GENERATED_PROVIDER_IDS } from "./provider-ids.generated";
9
+ export declare enum BUILT_IN_PROVIDER {
10
+ ANTHROPIC = "anthropic",
11
+ CLAUDE_CODE = "claude-code",
12
+ CLINE = "cline",
13
+ CLINE_PASS = "cline-pass",
14
+ ELEVENLABS = "elevenlabs",
15
+ OPENAI_COMPATIBLE = "openai-compatible",
16
+ OPENAI_NATIVE = "openai-native",
17
+ OPENAI_CODEX = "openai-codex",
18
+ OPENAI_CODEX_CLI = "openai-codex-cli",
19
+ OPENCODE = "opencode",
20
+ BEDROCK = "bedrock",
21
+ VERTEX = "vertex",
22
+ GEMINI = "gemini",
23
+ OLLAMA = "ollama",
24
+ XOLLAMA = "xollama",
25
+ OPENCOTI = "opencoti",
26
+ LMSTUDIO = "lmstudio",
27
+ DEEPSEEK = "deepseek",
28
+ XAI = "xai",
29
+ TOGETHER = "together",
30
+ FIREWORKS = "fireworks",
31
+ GROQ = "groq",
32
+ POOLSIDE = "poolside",
33
+ CEREBRAS = "cerebras",
34
+ SAMBANOVA = "sambanova",
35
+ NEBIUS = "nebius",
36
+ BASETEN = "baseten",
37
+ REQUESTY = "requesty",
38
+ LITELLM = "litellm",
39
+ HUGGINGFACE = "huggingface",
40
+ VERCEL_AI_GATEWAY = "vercel-ai-gateway",
41
+ V0 = "v0",
42
+ AIHUBMIX = "aihubmix",
43
+ HICAP = "hicap",
44
+ NOUS_RESEARCH = "nousResearch",
45
+ HUAWEI_CLOUD_MAAS = "huawei-cloud-maas",
46
+ WANDB = "wandb",
47
+ XIAOMI = "xiaomi",
48
+ TENCENT_TOKENHUB = "tencent-tokenhub",
49
+ KILO = "kilo",
50
+ ZAI = "zai",
51
+ ZAI_CODING_PLAN = "zai-coding-plan",
52
+ QWEN = "qwen",
53
+ QWEN_CODE = "qwen-code",
54
+ DOUBAO = "doubao",
55
+ MISTRAL = "mistral",
56
+ MOONSHOT = "moonshot",
57
+ ASKSAGE = "asksage",
58
+ MINIMAX = "minimax",
59
+ DIFY = "dify",
60
+ OCA = "oca",
61
+ SAPAICORE = "sapaicore",
62
+ OPENROUTER = "openrouter"
63
+ }
64
+ /**
65
+ * Provider ID aliases normalized to canonical built-in IDs.
66
+ *
67
+ * Keep this map as the single source of truth for alias handling.
68
+ */
69
+ export type GeneratedBuiltInProviderId = (typeof GENERATED_PROVIDER_IDS)[number];
70
+ export type BuiltInProviderId = BUILT_IN_PROVIDER | GeneratedBuiltInProviderId;
71
+ export declare const PROVIDER_ID_ALIASES: Record<string, BuiltInProviderId>;
72
+ export declare const BUILT_IN_PROVIDER_IDS: readonly BuiltInProviderId[];
73
+ /** Check if a string is a valid built-in provider ID */
74
+ export declare function isBuiltInProviderId(id: string): id is BuiltInProviderId;
75
+ /** Normalize provider aliases to canonical IDs */
76
+ export declare function normalizeProviderId(providerId: string): string;
77
+ //# sourceMappingURL=ids.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ids.d.ts","sourceRoot":"","sources":["../../src/providers/ids.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,oBAAY,iBAAiB;IAE5B,SAAS,cAAc;IACvB,WAAW,gBAAgB;IAC3B,KAAK,UAAU;IACf,UAAU,eAAe;IACzB,UAAU,eAAe;IAEzB,iBAAiB,sBAAsB;IACvC,aAAa,kBAAkB;IAC/B,YAAY,iBAAiB;IAC7B,gBAAgB,qBAAqB;IAErC,QAAQ,aAAa;IAErB,OAAO,YAAY;IACnB,MAAM,WAAW;IACjB,MAAM,WAAW;IAEjB,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,QAAQ,aAAa;IAErB,QAAQ,aAAa;IACrB,GAAG,QAAQ;IACX,QAAQ,aAAa;IACrB,SAAS,cAAc;IACvB,IAAI,SAAS;IACb,QAAQ,aAAa;IACrB,QAAQ,aAAa;IACrB,SAAS,cAAc;IACvB,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,OAAO,YAAY;IACnB,WAAW,gBAAgB;IAC3B,iBAAiB,sBAAsB;IACvC,EAAE,OAAO;IACT,QAAQ,aAAa;IACrB,KAAK,UAAU;IACf,aAAa,iBAAiB;IAC9B,iBAAiB,sBAAsB;IACvC,KAAK,UAAU;IACf,MAAM,WAAW;IACjB,gBAAgB,qBAAqB;IACrC,IAAI,SAAS;IACb,GAAG,QAAQ;IACX,eAAe,oBAAoB;IAEnC,IAAI,SAAS;IACb,SAAS,cAAc;IACvB,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,IAAI,SAAS;IACb,GAAG,QAAQ;IACX,SAAS,cAAc;IAEvB,UAAU,eAAe;CACzB;AAED;;;;GAIG;AACH,MAAM,MAAM,0BAA0B,GACrC,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEzC,MAAM,MAAM,iBAAiB,GAAG,iBAAiB,GAAG,0BAA0B,CAAC;AAE/E,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAIjE,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAE7B,SAAS,iBAAiB,EAAE,CAAC;AAElC,wDAAwD;AACxD,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,MAAM,GAAG,EAAE,IAAI,iBAAiB,CAEvE;AAED,kDAAkD;AAClD,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAG9D"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Message Types — re-exported from @cline/shared
3
+ */
4
+ export type { ContentBlock, FileContent, ImageContent, Message, MessageRole, MessageWithMetadata, RedactedThinkingContent, TextContent, ThinkingContent, ToolDefinition, ToolResultContent, ToolUseContent, } from "@cerebriline/shared";
5
+ //# sourceMappingURL=messages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/providers/messages.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,YAAY,EACX,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,OAAO,EACP,WAAW,EACX,mBAAmB,EACnB,uBAAuB,EACvB,WAAW,EACX,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,cAAc,GACd,MAAM,eAAe,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The one sleep the retry middlewares wait on.
3
+ *
4
+ * Abort-aware, and it *resolves* on abort rather than throwing: a cancelled
5
+ * backoff is not itself an error, and the caller is in a better position to
6
+ * decide what to surface -- the user's abort reason, or the failure that put it
7
+ * into the backoff in the first place. Every caller checks the signal again on
8
+ * the other side for exactly that reason.
9
+ */
10
+ export declare function sleep(ms: number, signal?: AbortSignal): Promise<void>;
11
+ //# sourceMappingURL=backoff.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backoff.d.ts","sourceRoot":"","sources":["../../../src/providers/middleware/backoff.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBrE"}
@@ -0,0 +1,74 @@
1
+ import type { LanguageModelV4Middleware, LanguageModelV4Usage } from "@ai-sdk/provider";
2
+ /** Minimal logger surface (a subset of `BasicLogger`). */
3
+ interface RetryLogger {
4
+ log?(message: string, meta?: Record<string, unknown>): void;
5
+ }
6
+ export interface RetryEmptyResponseOptions {
7
+ /** Total attempts including the first (so `3` means up to 2 retries). */
8
+ maxAttempts?: number;
9
+ /** Delay before each empty-response retry, in milliseconds. */
10
+ retryDelayMs?: number;
11
+ /**
12
+ * Delay before the first network-interruption retry, in milliseconds;
13
+ * doubles for each subsequent one (2s → 4s with the defaults, matching
14
+ * the legacy extension's backoff).
15
+ */
16
+ networkRetryDelayMs?: number;
17
+ logger?: RetryLogger;
18
+ }
19
+ /** Default total attempts (first try + 2 retries). */
20
+ export declare const DEFAULT_EMPTY_RESPONSE_MAX_ATTEMPTS = 3;
21
+ /** Default delay before a retry. */
22
+ export declare const DEFAULT_EMPTY_RESPONSE_RETRY_DELAY_MS = 250;
23
+ /** Default delay before the first network-interruption retry. */
24
+ export declare const DEFAULT_NETWORK_RETRY_DELAY_MS = 2000;
25
+ /**
26
+ * Whether an error (anywhere in its `cause` chain) identifies a transient
27
+ * transport interruption — the connection died or timed out underneath a
28
+ * request the provider never rejected. An abort anywhere in the chain
29
+ * vetoes the match: cancelled requests surface the same socket vocabulary,
30
+ * and a user cancel must never be retried. Everything else — HTTP business
31
+ * errors, context-window errors, provider-reported payloads — does not
32
+ * match.
33
+ */
34
+ export declare function isTransientNetworkError(error: unknown): boolean;
35
+ /** Sum two standardized v4 usage records field by field. */
36
+ export declare function addUsage(a: LanguageModelV4Usage, b: LanguageModelV4Usage): LanguageModelV4Usage;
37
+ /**
38
+ * Fold the usage of discarded attempts into the finish part that is actually
39
+ * emitted, so hosted-provider billing reflects every request the turn made
40
+ * (including cache and reasoning detail), not just the accepted one.
41
+ *
42
+ * The sum is right for money and wrong for context, and both are read off the
43
+ * same field. A discarded attempt really was charged, so billing has to see
44
+ * it -- but the prompt did not double, and `inputTokens` is what the token
45
+ * calibration anchors to, what the compaction trigger compares against its
46
+ * threshold, and what the context meter draws.
47
+ *
48
+ * Measured on pandorum session 1789852877349_7bbnd: four turns in 71 reported
49
+ * two or three times their real prompt, the worst 151,608 tokens against a
50
+ * 65,536-token window -- a number no request could have been served at. One
51
+ * inflated count beat the compaction trigger outright; another became the
52
+ * calibration anchor, collapsed the next request's output cap to 6,099 and
53
+ * fired a compaction at 41% of the window.
54
+ *
55
+ * So the accepted attempt's own prompt travels beside the billed total rather
56
+ * than replacing it. It is set only when something was discarded: on an
57
+ * ordinary turn the two numbers are the same, and a field that is always
58
+ * present invites a reader to prefer it without asking why it exists.
59
+ */
60
+ /**
61
+ * Provider-metadata namespace for the one number this middleware has to tell
62
+ * the rest of the pipeline. Named for the product rather than a vendor because
63
+ * it is ours, and it sits beside the vendors' own keys (`ollama`, `llamacpp`)
64
+ * in the same bag.
65
+ */
66
+ export declare const RETRY_METADATA_NAMESPACE = "cerebriline";
67
+ /**
68
+ * Create a middleware that retries empty model responses. Apply it as the
69
+ * outermost middleware (first in the `wrapLanguageModel` array) so each retry
70
+ * re-runs the full request.
71
+ */
72
+ export declare function createRetryEmptyResponseMiddleware(options?: RetryEmptyResponseOptions): LanguageModelV4Middleware;
73
+ export {};
74
+ //# sourceMappingURL=retry-empty-response.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry-empty-response.d.ts","sourceRoot":"","sources":["../../../src/providers/middleware/retry-empty-response.ts"],"names":[],"mappings":"AAoEA,OAAO,KAAK,EACX,yBAAyB,EAGzB,oBAAoB,EACpB,MAAM,kBAAkB,CAAC;AAI1B,0DAA0D;AAC1D,UAAU,WAAW;IACpB,GAAG,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;CAC5D;AAED,MAAM,WAAW,yBAAyB;IACzC,yEAAyE;IACzE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,+DAA+D;IAC/D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,MAAM,CAAC,EAAE,WAAW,CAAC;CACrB;AAED,sDAAsD;AACtD,eAAO,MAAM,mCAAmC,IAAI,CAAC;AACrD,oCAAoC;AACpC,eAAO,MAAM,qCAAqC,MAAM,CAAC;AACzD,iEAAiE;AACjE,eAAO,MAAM,8BAA8B,OAAQ,CAAC;AA+BpD;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAsC/D;AAsBD,4DAA4D;AAC5D,wBAAgB,QAAQ,CACvB,CAAC,EAAE,oBAAoB,EACvB,CAAC,EAAE,oBAAoB,GACrB,oBAAoB,CAuBtB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,gBAAgB,CAAC;AA8CtD;;;;GAIG;AACH,wBAAgB,kCAAkC,CACjD,OAAO,GAAE,yBAA8B,GACrC,yBAAyB,CAiM3B"}
@@ -0,0 +1,49 @@
1
+ import type { LanguageModelV4Middleware } from "@ai-sdk/provider";
2
+ /** Minimal logger surface (a subset of `BasicLogger`). */
3
+ interface RetryLogger {
4
+ log?(message: string, meta?: Record<string, unknown>): void;
5
+ }
6
+ export interface RetryRateLimitOptions {
7
+ /** Total attempts including the first (so `4` means up to 3 retries). */
8
+ maxAttempts?: number;
9
+ /**
10
+ * Longest this will wait for one retry, whatever the server asked for.
11
+ *
12
+ * The engine's own answer is a flat `2`, but a proxy in front of it -- or a
13
+ * later release -- may name minutes, and an agent that disappears for ten
14
+ * of them is indistinguishable from one that hung.
15
+ */
16
+ maxRetryAfterMs?: number;
17
+ /** Wait when the refusal named no delay at all. */
18
+ defaultRetryAfterMs?: number;
19
+ logger?: RetryLogger;
20
+ /** Seam for tests; the real one is abort-aware. */
21
+ sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;
22
+ }
23
+ /** Default total attempts (first try + 3 retries). */
24
+ export declare const DEFAULT_RATE_LIMIT_MAX_ATTEMPTS = 4;
25
+ /** Default ceiling on one wait. */
26
+ export declare const DEFAULT_MAX_RETRY_AFTER_MS = 30000;
27
+ /** Default wait when the server named none. */
28
+ export declare const DEFAULT_RATE_LIMIT_RETRY_DELAY_MS = 2000;
29
+ /**
30
+ * The delay the server asked for, in milliseconds, or `undefined` when it
31
+ * asked for none.
32
+ *
33
+ * RFC 7231 allows either a delta in seconds or an HTTP-date, and a date already
34
+ * past reads as no wait rather than a negative one. Walked through the error's
35
+ * `cause` chain because a rejection may arrive wrapped -- the AI SDK's
36
+ * `APICallError` carries `responseHeaders`, but a transport that re-throws puts
37
+ * it one or two levels down.
38
+ */
39
+ export declare function readRetryAfterMs(error: unknown): number | undefined;
40
+ /**
41
+ * Create a middleware that waits out admission refusals.
42
+ *
43
+ * Applied inside `withEmptyResponseRetry` so every request the turn makes --
44
+ * the first and any empty-response re-dial -- is paced by the server's own
45
+ * answer.
46
+ */
47
+ export declare function createRetryRateLimitMiddleware(options?: RetryRateLimitOptions): LanguageModelV4Middleware;
48
+ export {};
49
+ //# sourceMappingURL=retry-rate-limit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry-rate-limit.d.ts","sourceRoot":"","sources":["../../../src/providers/middleware/retry-rate-limit.ts"],"names":[],"mappings":"AAsCA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAIlE,0DAA0D;AAC1D,UAAU,WAAW;IACpB,GAAG,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;CAC5D;AAED,MAAM,WAAW,qBAAqB;IACrC,yEAAyE;IACzE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mDAAmD;IACnD,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,mDAAmD;IACnD,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5D;AAED,sDAAsD;AACtD,eAAO,MAAM,+BAA+B,IAAI,CAAC;AACjD,mCAAmC;AACnC,eAAO,MAAM,0BAA0B,QAAS,CAAC;AACjD,+CAA+C;AAC/C,eAAO,MAAM,iCAAiC,OAAQ,CAAC;AA0BvD;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAsCnE;AAED;;;;;;GAMG;AACH,wBAAgB,8BAA8B,CAC7C,OAAO,GAAE,qBAA0B,GACjC,yBAAyB,CAmE3B"}
@@ -0,0 +1,32 @@
1
+ import type { LanguageModelV4Message, LanguageModelV4Middleware } from "@ai-sdk/provider";
2
+ /**
3
+ * Walk a `LanguageModelV4Prompt` and rewrite every `role:"tool"` message
4
+ * containing image/file parts inside its tool-result `output`s. See the
5
+ * file-level comment for the rewrite shape.
6
+ *
7
+ * Returns the (possibly new) prompt array and a `mutated` flag for
8
+ * test/observation use.
9
+ */
10
+ export declare function rewritePromptToolImages(prompt: LanguageModelV4Message[], options?: {
11
+ relocate?: boolean;
12
+ }): {
13
+ prompt: LanguageModelV4Message[];
14
+ mutated: boolean;
15
+ };
16
+ export declare const splitToolImagesMiddleware: LanguageModelV4Middleware;
17
+ /**
18
+ * The same checks, without the relocation.
19
+ *
20
+ * For a converter that can carry images on a tool message — Ollama's native
21
+ * API is the one in this codebase — the images stay where the tool put them.
22
+ * What is shared is everything that protects the request: the per-image and
23
+ * per-request byte budgets, base64 validation, and the omission placeholder
24
+ * for anything that fails them. What is not shared is the synthetic user
25
+ * message, which on that path costs the model its reasoning history.
26
+ *
27
+ * The vision-describer path is upstream of all of this and unaffected: when a
28
+ * second model reads the images, it has already replaced them with text in the
29
+ * transcript, and there is nothing here left to place.
30
+ */
31
+ export declare const keepToolImagesMiddleware: LanguageModelV4Middleware;
32
+ //# sourceMappingURL=split-tool-images.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"split-tool-images.d.ts","sourceRoot":"","sources":["../../../src/providers/middleware/split-tool-images.ts"],"names":[],"mappings":"AA0DA,OAAO,KAAK,EAGX,sBAAsB,EACtB,yBAAyB,EAIzB,MAAM,kBAAkB,CAAC;AAoT1B;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACtC,MAAM,EAAE,sBAAsB,EAAE,EAChC,OAAO,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,GAC9B;IACF,MAAM,EAAE,sBAAsB,EAAE,CAAC;IACjC,OAAO,EAAE,OAAO,CAAC;CACjB,CAyCA;AAsCD,eAAO,MAAM,yBAAyB,EAAE,yBACP,CAAC;AAElC;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,wBAAwB,EAAE,yBACL,CAAC"}
@@ -0,0 +1,33 @@
1
+ import type { LanguageModelV4StreamPart } from "@ai-sdk/provider";
2
+ export type ModelStreamPartClass =
3
+ /**
4
+ * Output that `emitAiSdkEvents()` converts into `AgentModelEvent`s and
5
+ * that therefore reaches the assistant message. A turn containing any of
6
+ * these is not empty.
7
+ */
8
+ "converted-content"
9
+ /**
10
+ * Real model output that Cline does not (yet) convert into agent events.
11
+ * The model responded, so retrying would waste billable requests and
12
+ * likely reproduce the same output — never retried. If a turn contains
13
+ * ONLY unsupported output the assistant message can still come out
14
+ * empty; that is an explicit contract gap of this bucket, preferred over
15
+ * silently re-billing a turn the model did answer.
16
+ */
17
+ | "unsupported-output"
18
+ /** Markers and metadata that do not constitute model output. */
19
+ | "structural"
20
+ /** `stream-start` — carries warnings; one per attempt. */
21
+ | "stream-start"
22
+ /** Terminal accounting part — carries usage and the finish reason. */
23
+ | "finish"
24
+ /** An upstream error surfaced as a stream part. */
25
+ | "error";
26
+ export declare function classifyModelStreamPart(part: LanguageModelV4StreamPart): ModelStreamPartClass;
27
+ /**
28
+ * Whether a completed attempt that contained only parts for which this
29
+ * returns `false` (plus `stream-start`/`finish`) counts as a genuinely empty
30
+ * turn. Both converted and unsupported output mean "the model responded".
31
+ */
32
+ export declare function isModelOutputPart(part: LanguageModelV4StreamPart): boolean;
33
+ //# sourceMappingURL=stream-part-classification.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream-part-classification.d.ts","sourceRoot":"","sources":["../../../src/providers/middleware/stream-part-classification.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAElE,MAAM,MAAM,oBAAoB;AAC/B;;;;GAIG;AACD,mBAAmB;AACrB;;;;;;;GAOG;GACD,oBAAoB;AACtB,gEAAgE;GAC9D,YAAY;AACd,0DAA0D;GACxD,cAAc;AAChB,sEAAsE;GACpE,QAAQ;AACV,mDAAmD;GACjD,OAAO,CAAC;AAEX,wBAAgB,uBAAuB,CACtC,IAAI,EAAE,yBAAyB,GAC7B,oBAAoB,CAoDtB;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,yBAAyB,GAAG,OAAO,CAG1E"}