@llumiverse/common 1.3.0 → 1.4.0-dev.20260629.090753Z

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 (192) hide show
  1. package/lib/capability/anthropic.d.ts +3 -0
  2. package/lib/capability/anthropic.d.ts.map +1 -0
  3. package/lib/capability/anthropic.js +92 -0
  4. package/lib/capability/anthropic.js.map +1 -0
  5. package/lib/{types/capability → capability}/azure_foundry.d.ts +1 -1
  6. package/lib/capability/azure_foundry.d.ts.map +1 -0
  7. package/lib/capability/azure_foundry.js +394 -0
  8. package/lib/capability/azure_foundry.js.map +1 -0
  9. package/lib/{types/capability → capability}/bedrock.d.ts +1 -1
  10. package/lib/capability/bedrock.d.ts.map +1 -0
  11. package/lib/capability/bedrock.js +300 -0
  12. package/lib/capability/bedrock.js.map +1 -0
  13. package/lib/{types/capability → capability}/openai.d.ts +1 -1
  14. package/lib/capability/openai.d.ts.map +1 -0
  15. package/lib/capability/openai.js +179 -0
  16. package/lib/capability/openai.js.map +1 -0
  17. package/lib/{types/capability → capability}/vertexai.d.ts +1 -1
  18. package/lib/capability/vertexai.d.ts.map +1 -0
  19. package/lib/capability/vertexai.js +137 -0
  20. package/lib/capability/vertexai.js.map +1 -0
  21. package/lib/{types/capability.d.ts → capability.d.ts} +1 -1
  22. package/lib/capability.d.ts.map +1 -0
  23. package/lib/{esm/capability.js → capability.js} +17 -17
  24. package/lib/capability.js.map +1 -0
  25. package/lib/index.d.ts +14 -0
  26. package/lib/index.d.ts.map +1 -0
  27. package/lib/index.js +14 -0
  28. package/lib/index.js.map +1 -0
  29. package/lib/{types/options → options}/anthropic.d.ts +2 -2
  30. package/lib/options/anthropic.d.ts.map +1 -0
  31. package/lib/{esm/options → options}/anthropic.js +14 -11
  32. package/lib/options/anthropic.js.map +1 -0
  33. package/lib/{types/options → options}/azure_foundry.d.ts +14 -14
  34. package/lib/options/azure_foundry.d.ts.map +1 -0
  35. package/lib/{esm/options → options}/azure_foundry.js +126 -126
  36. package/lib/options/azure_foundry.js.map +1 -0
  37. package/lib/{types/options → options}/bedrock.d.ts +16 -16
  38. package/lib/{types/options → options}/bedrock.d.ts.map +1 -1
  39. package/lib/options/bedrock.js +489 -0
  40. package/lib/options/bedrock.js.map +1 -0
  41. package/lib/options/context-windows.d.ts.map +1 -0
  42. package/lib/options/context-windows.js.map +1 -0
  43. package/lib/options/embedding.d.ts +38 -0
  44. package/lib/options/embedding.d.ts.map +1 -0
  45. package/lib/options/embedding.js +77 -0
  46. package/lib/options/embedding.js.map +1 -0
  47. package/lib/{types/options → options}/fallback.d.ts +2 -2
  48. package/lib/options/fallback.d.ts.map +1 -0
  49. package/lib/options/fallback.js +65 -0
  50. package/lib/options/fallback.js.map +1 -0
  51. package/lib/{types/options → options}/groq.d.ts +2 -2
  52. package/lib/options/groq.d.ts.map +1 -0
  53. package/lib/options/groq.js +54 -0
  54. package/lib/options/groq.js.map +1 -0
  55. package/lib/options/openai.d.ts +40 -0
  56. package/lib/options/openai.d.ts.map +1 -0
  57. package/lib/options/openai.js +284 -0
  58. package/lib/options/openai.js.map +1 -0
  59. package/lib/{types/options → options}/shared-parsing.d.ts +1 -1
  60. package/lib/options/shared-parsing.d.ts.map +1 -0
  61. package/lib/{esm/options → options}/shared-parsing.js +14 -17
  62. package/lib/options/shared-parsing.js.map +1 -0
  63. package/lib/options/version-parsing.d.ts.map +1 -0
  64. package/lib/{esm/options → options}/version-parsing.js +15 -15
  65. package/lib/options/version-parsing.js.map +1 -0
  66. package/lib/{types/options → options}/vertexai.d.ts +15 -15
  67. package/lib/options/vertexai.d.ts.map +1 -0
  68. package/lib/options/vertexai.js +606 -0
  69. package/lib/options/vertexai.js.map +1 -0
  70. package/lib/{types/options.d.ts → options.d.ts} +1 -1
  71. package/lib/options.d.ts.map +1 -0
  72. package/lib/{esm/options.js → options.js} +8 -8
  73. package/lib/options.js.map +1 -0
  74. package/lib/{types/types.d.ts → types.d.ts} +143 -35
  75. package/lib/types.d.ts.map +1 -0
  76. package/lib/{esm/types.js → types.js} +21 -23
  77. package/lib/types.js.map +1 -0
  78. package/package.json +11 -34
  79. package/src/LlumiverseError.test.ts +18 -72
  80. package/src/capability/anthropic.ts +61 -11
  81. package/src/capability/azure_foundry.ts +303 -65
  82. package/src/capability/bedrock.ts +201 -56
  83. package/src/capability/openai.ts +135 -41
  84. package/src/capability/vertexai.ts +105 -35
  85. package/src/capability.ts +18 -18
  86. package/src/index.ts +13 -12
  87. package/src/options/anthropic.ts +16 -13
  88. package/src/options/azure_foundry.ts +157 -143
  89. package/src/options/bedrock.ts +247 -185
  90. package/src/options/context-windows.ts +2 -2
  91. package/src/options/embedding.ts +92 -0
  92. package/src/options/fallback.ts +50 -17
  93. package/src/options/groq.ts +48 -21
  94. package/src/options/openai.ts +228 -183
  95. package/src/options/shared-parsing.ts +16 -21
  96. package/src/options/version-parsing.ts +17 -17
  97. package/src/options/vertexai.ts +382 -288
  98. package/src/options.ts +8 -8
  99. package/src/types.ts +260 -155
  100. package/lib/cjs/capability/anthropic.js +0 -45
  101. package/lib/cjs/capability/anthropic.js.map +0 -1
  102. package/lib/cjs/capability/azure_foundry.js +0 -160
  103. package/lib/cjs/capability/azure_foundry.js.map +0 -1
  104. package/lib/cjs/capability/bedrock.js +0 -158
  105. package/lib/cjs/capability/bedrock.js.map +0 -1
  106. package/lib/cjs/capability/openai.js +0 -98
  107. package/lib/cjs/capability/openai.js.map +0 -1
  108. package/lib/cjs/capability/vertexai.js +0 -80
  109. package/lib/cjs/capability/vertexai.js.map +0 -1
  110. package/lib/cjs/capability.js +0 -115
  111. package/lib/cjs/capability.js.map +0 -1
  112. package/lib/cjs/index.js +0 -29
  113. package/lib/cjs/index.js.map +0 -1
  114. package/lib/cjs/options/anthropic.js +0 -34
  115. package/lib/cjs/options/anthropic.js.map +0 -1
  116. package/lib/cjs/options/azure_foundry.js +0 -423
  117. package/lib/cjs/options/azure_foundry.js.map +0 -1
  118. package/lib/cjs/options/bedrock.js +0 -427
  119. package/lib/cjs/options/bedrock.js.map +0 -1
  120. package/lib/cjs/options/context-windows.js +0 -138
  121. package/lib/cjs/options/context-windows.js.map +0 -1
  122. package/lib/cjs/options/fallback.js +0 -35
  123. package/lib/cjs/options/fallback.js.map +0 -1
  124. package/lib/cjs/options/groq.js +0 -37
  125. package/lib/cjs/options/groq.js.map +0 -1
  126. package/lib/cjs/options/openai.js +0 -246
  127. package/lib/cjs/options/openai.js.map +0 -1
  128. package/lib/cjs/options/shared-parsing.js +0 -144
  129. package/lib/cjs/options/shared-parsing.js.map +0 -1
  130. package/lib/cjs/options/version-parsing.js +0 -326
  131. package/lib/cjs/options/version-parsing.js.map +0 -1
  132. package/lib/cjs/options/vertexai.js +0 -525
  133. package/lib/cjs/options/vertexai.js.map +0 -1
  134. package/lib/cjs/options.js +0 -33
  135. package/lib/cjs/options.js.map +0 -1
  136. package/lib/cjs/package.json +0 -3
  137. package/lib/cjs/types.js +0 -307
  138. package/lib/cjs/types.js.map +0 -1
  139. package/lib/esm/capability/anthropic.js +0 -42
  140. package/lib/esm/capability/anthropic.js.map +0 -1
  141. package/lib/esm/capability/azure_foundry.js +0 -157
  142. package/lib/esm/capability/azure_foundry.js.map +0 -1
  143. package/lib/esm/capability/bedrock.js +0 -155
  144. package/lib/esm/capability/bedrock.js.map +0 -1
  145. package/lib/esm/capability/openai.js +0 -95
  146. package/lib/esm/capability/openai.js.map +0 -1
  147. package/lib/esm/capability/vertexai.js +0 -77
  148. package/lib/esm/capability/vertexai.js.map +0 -1
  149. package/lib/esm/capability.js.map +0 -1
  150. package/lib/esm/index.js +0 -13
  151. package/lib/esm/index.js.map +0 -1
  152. package/lib/esm/options/anthropic.js.map +0 -1
  153. package/lib/esm/options/azure_foundry.js.map +0 -1
  154. package/lib/esm/options/bedrock.js +0 -423
  155. package/lib/esm/options/bedrock.js.map +0 -1
  156. package/lib/esm/options/context-windows.js.map +0 -1
  157. package/lib/esm/options/fallback.js +0 -32
  158. package/lib/esm/options/fallback.js.map +0 -1
  159. package/lib/esm/options/groq.js +0 -34
  160. package/lib/esm/options/groq.js.map +0 -1
  161. package/lib/esm/options/openai.js +0 -243
  162. package/lib/esm/options/openai.js.map +0 -1
  163. package/lib/esm/options/shared-parsing.js.map +0 -1
  164. package/lib/esm/options/version-parsing.js.map +0 -1
  165. package/lib/esm/options/vertexai.js +0 -519
  166. package/lib/esm/options/vertexai.js.map +0 -1
  167. package/lib/esm/options.js.map +0 -1
  168. package/lib/esm/types.js.map +0 -1
  169. package/lib/types/capability/anthropic.d.ts +0 -3
  170. package/lib/types/capability/anthropic.d.ts.map +0 -1
  171. package/lib/types/capability/azure_foundry.d.ts.map +0 -1
  172. package/lib/types/capability/bedrock.d.ts.map +0 -1
  173. package/lib/types/capability/openai.d.ts.map +0 -1
  174. package/lib/types/capability/vertexai.d.ts.map +0 -1
  175. package/lib/types/capability.d.ts.map +0 -1
  176. package/lib/types/index.d.ts +0 -13
  177. package/lib/types/index.d.ts.map +0 -1
  178. package/lib/types/options/anthropic.d.ts.map +0 -1
  179. package/lib/types/options/azure_foundry.d.ts.map +0 -1
  180. package/lib/types/options/context-windows.d.ts.map +0 -1
  181. package/lib/types/options/fallback.d.ts.map +0 -1
  182. package/lib/types/options/groq.d.ts.map +0 -1
  183. package/lib/types/options/openai.d.ts +0 -40
  184. package/lib/types/options/openai.d.ts.map +0 -1
  185. package/lib/types/options/shared-parsing.d.ts.map +0 -1
  186. package/lib/types/options/version-parsing.d.ts.map +0 -1
  187. package/lib/types/options/vertexai.d.ts.map +0 -1
  188. package/lib/types/options.d.ts.map +0 -1
  189. package/lib/types/types.d.ts.map +0 -1
  190. /package/lib/{types/options → options}/context-windows.d.ts +0 -0
  191. /package/lib/{esm/options → options}/context-windows.js +0 -0
  192. /package/lib/{types/options → options}/version-parsing.d.ts +0 -0
package/src/types.ts CHANGED
@@ -20,7 +20,7 @@ export enum Providers {
20
20
  groq = 'groq',
21
21
  watsonx = 'watsonx',
22
22
  xai = 'xai',
23
- anthropic = 'anthropic'
23
+ anthropic = 'anthropic',
24
24
  }
25
25
 
26
26
  export interface ProviderParams {
@@ -33,145 +33,210 @@ export interface ProviderParams {
33
33
  }
34
34
 
35
35
  export const ProviderList: Record<Providers, ProviderParams> = {
36
- openai:
37
- {
36
+ openai: {
38
37
  id: Providers.openai,
39
- name: "OpenAI",
38
+ name: 'OpenAI',
40
39
  requiresApiKey: true,
41
40
  requiresEndpointUrl: false,
42
41
  supportSearch: false,
43
42
  },
44
- azure_openai:
45
- {
43
+ azure_openai: {
46
44
  id: Providers.azure_openai,
47
- name: "Azure OpenAI",
45
+ name: 'Azure OpenAI',
48
46
  requiresApiKey: false,
49
47
  requiresEndpointUrl: true,
50
48
  supportSearch: false,
51
49
  },
52
- azure_foundry:
53
- {
50
+ azure_foundry: {
54
51
  id: Providers.azure_foundry,
55
- name: "Azure Foundry",
52
+ name: 'Microsoft Foundry',
56
53
  requiresApiKey: true,
57
54
  requiresEndpointUrl: true,
58
55
  supportSearch: false,
59
56
  },
60
- huggingface_ie:
61
- {
57
+ huggingface_ie: {
62
58
  id: Providers.huggingface_ie,
63
- name: "HuggingFace Inference Endpoint",
59
+ name: 'HuggingFace Inference Endpoint',
64
60
  requiresApiKey: true,
65
61
  requiresEndpointUrl: true,
66
62
  },
67
- replicate:
68
- {
63
+ replicate: {
69
64
  id: Providers.replicate,
70
- name: "Replicate",
65
+ name: 'Replicate',
71
66
  requiresApiKey: true,
72
67
  requiresEndpointUrl: false,
73
68
  supportSearch: true,
74
69
  },
75
- bedrock:
76
- {
70
+ bedrock: {
77
71
  id: Providers.bedrock,
78
- name: "AWS Bedrock",
72
+ name: 'Amazon Bedrock',
79
73
  requiresApiKey: false,
80
74
  requiresEndpointUrl: false,
81
- endpointPlaceholder: "region name (eg. us-east-1)",
75
+ endpointPlaceholder: 'region name (eg. us-east-1)',
82
76
  supportSearch: false,
83
77
  },
84
78
  vertexai: {
85
79
  id: Providers.vertexai,
86
- name: "Google Agent Platform (Vertex AI)",
80
+ name: 'Google Agent Platform (Vertex AI)',
87
81
  requiresApiKey: false,
88
82
  requiresEndpointUrl: false,
89
83
  supportSearch: false,
90
84
  },
91
85
  togetherai: {
92
86
  id: Providers.togetherai,
93
- name: "Together AI",
94
- requiresApiKey: false,
87
+ name: 'Together AI',
88
+ requiresApiKey: true,
95
89
  requiresEndpointUrl: false,
96
90
  supportSearch: false,
97
91
  },
98
92
  mistralai: {
99
93
  id: Providers.mistralai,
100
- name: "Mistral AI",
94
+ name: 'Mistral AI',
101
95
  requiresApiKey: false,
102
96
  requiresEndpointUrl: false,
103
97
  supportSearch: false,
104
98
  },
105
99
  groq: {
106
100
  id: Providers.groq,
107
- name: "Groq Cloud",
101
+ name: 'Groq Cloud',
108
102
  requiresApiKey: false,
109
103
  requiresEndpointUrl: false,
110
104
  supportSearch: false,
111
105
  },
112
106
  watsonx: {
113
107
  id: Providers.watsonx,
114
- name: "IBM WatsonX",
108
+ name: 'IBM WatsonX',
115
109
  requiresApiKey: true,
116
110
  requiresEndpointUrl: true,
117
- supportSearch: false
111
+ supportSearch: false,
118
112
  },
119
113
  xai: {
120
114
  id: Providers.xai,
121
- name: "xAI (Grok)",
115
+ name: 'xAI (Grok)',
122
116
  requiresApiKey: true,
123
117
  requiresEndpointUrl: false,
124
- supportSearch: false
118
+ supportSearch: false,
125
119
  },
126
120
  openai_compatible: {
127
121
  id: Providers.openai_compatible,
128
- name: "OpenAI Compatible",
122
+ name: 'OpenAI Compatible',
129
123
  requiresApiKey: true,
130
124
  requiresEndpointUrl: true,
131
- endpointPlaceholder: "https://api.example.com/v1",
132
- supportSearch: false
125
+ endpointPlaceholder: 'https://api.example.com/v1',
126
+ supportSearch: false,
133
127
  },
134
128
  anthropic: {
135
129
  id: Providers.anthropic,
136
- name: "Anthropic",
130
+ name: 'Anthropic',
137
131
  requiresApiKey: true,
138
132
  requiresEndpointUrl: false,
139
133
  supportSearch: false,
140
134
  },
141
- }
135
+ };
142
136
 
143
137
  // ============== Embeddings ===============
144
138
 
139
+ /**
140
+ * Semantic task type for embedding models. Drivers map these to provider-
141
+ * specific values (e.g. "RETRIEVAL_QUERY" for Vertex, "search_query" for Cohere).
142
+ * - "query" — a search query to find relevant documents
143
+ * - "document" — a document to be indexed and retrieved
144
+ */
145
+ export type EmbeddingTaskType = 'query' | 'document';
146
+
147
+ /**
148
+ * One input to an embedding model. Discriminated by `type`.
149
+ * Drivers consume binary content via DataSource and may pass a provider-native
150
+ * URL (gs://, s3://, https://) when one is available.
151
+ */
152
+ export type EmbeddingInput = TextEmbeddingInput | ImageEmbeddingInput | VideoEmbeddingInput | AudioEmbeddingInput;
153
+
154
+ export interface TextEmbeddingInput {
155
+ type: 'text';
156
+ text: string;
157
+ /** Overrides EmbeddingsOptions.task_type for this input. */
158
+ task_type?: EmbeddingTaskType;
159
+ /** Document title hint — used by Vertex AI for RETRIEVAL_DOCUMENT. */
160
+ title?: string;
161
+ }
162
+
163
+ export interface ImageEmbeddingInput {
164
+ type: 'image';
165
+ source: DataSource;
166
+ }
167
+
168
+ export interface VideoEmbeddingInput {
169
+ type: 'video';
170
+ source: DataSource;
171
+ start_sec?: number;
172
+ length_sec?: number;
173
+ /** Vertex multimodal segment length. */
174
+ interval_sec?: number;
175
+ /** TwelveLabs Marengo. */
176
+ use_fixed_length_sec?: boolean;
177
+ /** TwelveLabs Marengo. */
178
+ min_clip_sec?: number;
179
+ /** TwelveLabs Marengo: which views to extract per segment. */
180
+ embedding_option?: ('visual-text' | 'visual-image' | 'audio')[];
181
+ }
182
+
183
+ export interface AudioEmbeddingInput {
184
+ type: 'audio';
185
+ source: DataSource;
186
+ start_sec?: number;
187
+ length_sec?: number;
188
+ }
189
+
145
190
  export interface EmbeddingsOptions {
191
+ inputs: EmbeddingInput[];
146
192
  /**
147
- * The text to generate the embeddings for. One of text or image is required.
148
- */
149
- text?: string;
150
- /**
151
- * The image to generate embeddings for
152
- */
153
- image?: string
154
- /**
155
- * The model to use to generate the embeddings. Optional.
193
+ * Provider model id. When omitted the driver picks a sensible default
194
+ * for the modalities present in `inputs`.
156
195
  */
157
196
  model?: string;
158
197
 
198
+ /** Default task type applied to text inputs that don't set their own. */
199
+ task_type?: EmbeddingTaskType;
200
+ /** Output dimension truncation (MRL). Vertex/OpenAI where supported. */
201
+ dimensions?: number;
159
202
  }
160
203
 
161
204
  export interface EmbeddingsResult {
162
- /**
163
- * The embedding vectors corresponding to the words in the input text.
164
- */
165
- values: number[];
166
- /**
167
- * The model used to generate the embeddings.
168
- */
205
+ /** One result item per input, in the same order as EmbeddingsOptions.inputs. */
206
+ results: EmbeddingResultItem[];
207
+ /** The provider model id that produced the result. */
169
208
  model: string;
209
+ /** Aggregate token usage when reported by the provider. */
210
+ usage?: EmbeddingsTokenUsage;
211
+ }
212
+
213
+ export interface EmbeddingResultItem {
170
214
  /**
171
- * Number of tokens of the input text.
215
+ * One or more vectors produced for this input.
216
+ * Single vector for text/image; multiple for segmented video/audio or
217
+ * joint-multimodal models that return per-modality vectors.
172
218
  */
173
- token_count?: number;
219
+ outputs: EmbeddingOutput[];
220
+ /** Token count attributed to this input, when reported by the provider. */
221
+ input_tokens?: number;
222
+ }
223
+
224
+ export interface EmbeddingOutput {
225
+ values: number[];
226
+ /** Which modality this vector represents (useful for joint-multimodal results). */
227
+ modality?: 'text' | 'image' | 'video' | 'audio';
228
+ /** Segment start time for video/audio. */
229
+ start_sec?: number;
230
+ /** Segment end time for video/audio. */
231
+ end_sec?: number;
232
+ /** TwelveLabs Marengo: which view of the segment this vector represents. */
233
+ embedding_option?: string;
234
+ }
174
235
 
236
+ export interface EmbeddingsTokenUsage {
237
+ input_tokens?: number;
238
+ input_text_tokens?: number;
239
+ input_image_tokens?: number;
175
240
  }
176
241
 
177
242
  export interface ResultValidationError {
@@ -195,11 +260,11 @@ export interface LlumiverseErrorContext {
195
260
 
196
261
  /**
197
262
  * Standardized error class for Llumiverse driver errors.
198
- *
263
+ *
199
264
  * Normalizes errors from different LLM providers (OpenAI, Anthropic, Bedrock, VertexAI, etc.)
200
265
  * into a consistent format. The primary value is the `retryable` flag, which enables upstream
201
266
  * consumers to implement smart retry logic.
202
- *
267
+ *
203
268
  * @example
204
269
  * ```typescript
205
270
  * try {
@@ -209,7 +274,7 @@ export interface LlumiverseErrorContext {
209
274
  * console.log(`Provider: ${error.context.provider}`);
210
275
  * console.log(`Model: ${error.context.model}`);
211
276
  * console.log(`Retryable: ${error.retryable}`);
212
- *
277
+ *
213
278
  * if (error.retryable) {
214
279
  * // Implement retry logic with exponential backoff
215
280
  * await retryWithBackoff(() => driver.execute(segments, options));
@@ -223,7 +288,7 @@ export interface LlumiverseErrorContext {
223
288
  * ```
224
289
  */
225
290
  export class LlumiverseError extends Error {
226
- /**
291
+ /**
227
292
  * HTTP status code (e.g., 429, 500) if available.
228
293
  * Undefined if the error doesn't have a numeric status code.
229
294
  */
@@ -235,12 +300,12 @@ export class LlumiverseError extends Error {
235
300
  */
236
301
  readonly name: string;
237
302
 
238
- /**
303
+ /**
239
304
  * Whether this error is retryable.
240
305
  * - True: Definitely retryable (rate limits, timeouts, server errors)
241
306
  * - False: Definitely not retryable (auth failures, invalid requests, malformed schemas)
242
307
  * - Undefined: Unknown retryability - allows consumers to decide default behavior
243
- *
308
+ *
244
309
  * When undefined, consumers can choose their retry strategy:
245
310
  * - Conservative: Don't retry unknown errors (avoid spam)
246
311
  * - Resilient: Retry unknown errors (prioritize success)
@@ -265,7 +330,7 @@ export class LlumiverseError extends Error {
265
330
  context: LlumiverseErrorContext,
266
331
  originalError: unknown,
267
332
  code?: number,
268
- name?: string
333
+ name?: string,
269
334
  ) {
270
335
  super(message);
271
336
  this.name = name || 'LlumiverseError';
@@ -293,16 +358,15 @@ export class LlumiverseError extends Error {
293
358
  context: this.context,
294
359
  stack: this.stack,
295
360
  // Include original error message if available
296
- originalErrorMessage: this.originalError instanceof Error
297
- ? this.originalError.message
298
- : String(this.originalError),
361
+ originalErrorMessage:
362
+ this.originalError instanceof Error ? this.originalError.message : String(this.originalError),
299
363
  };
300
364
  }
301
365
 
302
366
  /**
303
367
  * Type guard to check if an error is a LlumiverseError.
304
368
  * Useful for conditional error handling.
305
- *
369
+ *
306
370
  * @param error - The error to check
307
371
  * @returns True if the error is a LlumiverseError
308
372
  */
@@ -314,21 +378,22 @@ export class LlumiverseError extends Error {
314
378
  // ============== Result Types ===============
315
379
 
316
380
  export interface BaseResult {
317
- type: "text" | "json" | "image";
318
- value: any;
381
+ type: 'text' | 'json' | 'image';
382
+ value: unknown;
319
383
  }
320
384
 
321
385
  export interface TextResult extends BaseResult {
322
- type: "text";
386
+ type: 'text';
323
387
  value: string;
324
388
  }
325
389
 
326
390
  export interface JsonResult extends BaseResult {
327
- type: "json";
391
+ type: 'json';
392
+ value: JSONValue;
328
393
  }
329
394
 
330
395
  export interface ImageResult extends BaseResult {
331
- type: "image";
396
+ type: 'image';
332
397
  value: string; // base64 data url or real url
333
398
  }
334
399
 
@@ -337,17 +402,18 @@ export interface ImageResult extends BaseResult {
337
402
  */
338
403
  export type CompletionResult = TextResult | JsonResult | ImageResult;
339
404
 
340
-
341
405
  //Internal structure used in driver implementation.
342
406
  export interface CompletionChunkObject {
343
407
  result: CompletionResult[];
344
408
  token_usage?: ExecutionTokenUsage;
345
- finish_reason?: "stop" | "length" | string;
409
+ finish_reason?: 'stop' | 'length' | string;
346
410
  /**
347
411
  * Tool calls returned by the model during streaming.
348
412
  * Each chunk may contain partial tool call information that needs to be aggregated.
413
+ * Typed with `unknown` params because streamed chunks carry partial (often string)
414
+ * tool_input that is only parsed into a JSONObject once fully accumulated.
349
415
  */
350
- tool_use?: ToolUse[];
416
+ tool_use?: ToolUse<unknown>[];
351
417
  }
352
418
 
353
419
  /**
@@ -357,29 +423,29 @@ export interface CompletionChunkObject {
357
423
  * - Plain object schemas for simpler cases
358
424
  */
359
425
  export interface ToolDefinition {
360
- name: string,
361
- description?: string,
426
+ name: string;
427
+ description?: string;
362
428
  input_schema: {
363
429
  type?: unknown;
364
430
  properties?: Record<string, unknown> | null | undefined;
365
431
  required?: readonly string[] | string[];
366
432
  additionalProperties?: unknown;
367
433
  [k: string]: unknown;
368
- },
434
+ };
369
435
  }
370
436
  /**
371
437
  * A tool use instance represents a call to a tool.
372
438
  * The id property is used to identify the tool call.
373
439
  */
374
440
  export interface ToolUse<ParamsT = JSONObject> {
375
- id: string,
376
- tool_name: string,
377
- tool_input: ParamsT | null,
441
+ id: string;
442
+ tool_name: string;
443
+ tool_input: ParamsT | null;
378
444
  /**
379
445
  * Gemini thinking models require thought_signature to be passed back with tool results.
380
446
  * This preserves the model's reasoning state during multi-turn tool use.
381
447
  */
382
- thought_signature?: string,
448
+ thought_signature?: string;
383
449
  }
384
450
 
385
451
  export interface Completion {
@@ -389,11 +455,11 @@ export interface Completion {
389
455
  /**
390
456
  * Contains the tools from which the model awaits information.
391
457
  */
392
- tool_use?: ToolUse[];
458
+ tool_use?: ToolUse<unknown>[];
393
459
  /**
394
460
  * The finish reason as reported by the model: stop | length or other model specific values
395
461
  */
396
- finish_reason?: "stop" | "length" | "tool_use" | string;
462
+ finish_reason?: 'stop' | 'length' | 'tool_use' | string;
397
463
 
398
464
  /**
399
465
  * Set only if a result validation error occurred, otherwise if the result is valid the error field is undefined
@@ -404,7 +470,7 @@ export interface Completion {
404
470
  /**
405
471
  * The original response. Only included if the option include_original_response is set to true and the request is made using execute. Not supported when streaming.
406
472
  */
407
- original_response?: Record<string, any>;
473
+ original_response?: unknown;
408
474
 
409
475
  /**
410
476
  * The conversation context. This is an opaque structure that can be passed to the next request to restore the context.
@@ -412,7 +478,7 @@ export interface Completion {
412
478
  conversation?: unknown;
413
479
  }
414
480
 
415
- export interface ExecutionResponse<PromptT = any> extends Completion {
481
+ export interface ExecutionResponse<PromptT = unknown> extends Completion {
416
482
  prompt: PromptT;
417
483
  /**
418
484
  * The time it took to execute the request in seconds
@@ -424,8 +490,7 @@ export interface ExecutionResponse<PromptT = any> extends Completion {
424
490
  chunks?: number;
425
491
  }
426
492
 
427
-
428
- export interface CompletionStream<PromptT = any> extends AsyncIterable<string> {
493
+ export interface CompletionStream<PromptT = unknown> extends AsyncIterable<string> {
429
494
  completion: ExecutionResponse<PromptT> | undefined;
430
495
  }
431
496
 
@@ -435,7 +500,7 @@ export interface CompletionStream<PromptT = any> extends AsyncIterable<string> {
435
500
  * - Message-only: logger.info("message")
436
501
  * - Object-first: logger.info({ data }, "message")
437
502
  * - PREVENTS: logger.info("message", { data }) - compile error (objects not allowed in ...args)
438
- *
503
+ *
439
504
  * Additional args must be primitives (string | number | boolean) for string interpolation.
440
505
  */
441
506
  export interface Logger {
@@ -449,19 +514,52 @@ export interface Logger {
449
514
  error<T>(obj: T, msg?: T extends string ? never : string, ...args: (string | number | boolean)[]): void;
450
515
  }
451
516
 
517
+ /**
518
+ * HTTP timeouts applied to a driver's upstream LLM-provider calls.
519
+ *
520
+ * All values are in milliseconds. Drivers should map these onto whatever
521
+ * HTTP client their SDK uses; the defaults applied in
522
+ * `@llumiverse/core/createDriverHttpAgent` are:
523
+ * - headersTimeout: 60_000
524
+ * - bodyTimeout: 60_000
525
+ * - connectTimeout: 10_000
526
+ * - keepAliveTimeout: 30_000
527
+ *
528
+ * The defaults are deliberately tighter than Node's undici default
529
+ * (5 minutes for headers/body) so a hung upstream surfaces quickly. Bump
530
+ * `bodyTimeout` for streaming flows that have legitimate silent gaps
531
+ * (e.g. tool-using agents).
532
+ */
533
+ export interface HttpTimeoutOptions {
534
+ /** Time (ms) to wait for the first response byte after the request is sent. */
535
+ headersTimeout?: number;
536
+ /** Time (ms) between body chunks once streaming has started. */
537
+ bodyTimeout?: number;
538
+ /** TCP/TLS connect timeout (ms). */
539
+ connectTimeout?: number;
540
+ /** Idle socket reuse timeout (ms). */
541
+ keepAliveTimeout?: number;
542
+ }
543
+
452
544
  export interface DriverOptions {
453
- logger?: Logger | "console";
545
+ logger?: Logger | 'console';
546
+ /**
547
+ * Optional HTTP timeouts applied to the driver's upstream LLM-provider
548
+ * calls. Drivers that don't make HTTP calls (e.g. the in-process test
549
+ * driver) ignore this. See {@link HttpTimeoutOptions} for defaults.
550
+ */
551
+ httpTimeout?: HttpTimeoutOptions;
454
552
  }
455
553
 
456
554
  export type JSONSchemaTypeName =
457
- | "string" //
458
- | "number"
459
- | "integer"
460
- | "boolean"
461
- | "object"
462
- | "array"
463
- | "null"
464
- | "any";
555
+ | 'string' //
556
+ | 'number'
557
+ | 'integer'
558
+ | 'boolean'
559
+ | 'object'
560
+ | 'array'
561
+ | 'null'
562
+ | 'any';
465
563
 
466
564
  export type JSONSchemaType =
467
565
  | string //
@@ -475,7 +573,7 @@ export interface JSONSchemaObject {
475
573
  [key: string]: JSONSchemaType;
476
574
  }
477
575
 
478
- export interface JSONSchemaArray extends Array<JSONSchemaType> { }
576
+ export interface JSONSchemaArray extends Array<JSONSchemaType> {}
479
577
 
480
578
  export interface JSONSchemaProperties {
481
579
  [key: string]: JSONSchema;
@@ -485,12 +583,16 @@ export interface JSONSchema {
485
583
  type?: JSONSchemaTypeName | JSONSchemaTypeName[];
486
584
  description?: string;
487
585
  properties?: JSONSchemaProperties;
586
+ items?: JSONSchema;
587
+ format?: string;
588
+ editor?: unknown;
589
+ default?: unknown;
488
590
  additionalProperties?: boolean | JSONSchema;
489
591
  required?: string[];
490
- [k: string]: any;
592
+ [k: string]: unknown;
491
593
  }
492
594
 
493
- export type PromptFormatter<T = any> = (messages: PromptSegment[], schema?: JSONSchema) => T;
595
+ export type PromptFormatter<T = unknown> = (messages: PromptSegment[], schema?: JSONSchema) => T;
494
596
 
495
597
  //Options are split into PromptOptions, ModelOptions and ExecutionOptions.
496
598
  //ExecutionOptions are most often used within llumiverse as they are the most complete.
@@ -514,6 +616,12 @@ export interface StatelessExecutionOptions extends PromptOptions {
514
616
  include_original_response?: boolean;
515
617
  model_options?: ModelOptions;
516
618
 
619
+ /**
620
+ * Per-call HTTP timeouts for upstream LLM-provider calls. These override
621
+ * the driver's default `DriverOptions.httpTimeout` for this execution only.
622
+ */
623
+ httpTimeout?: HttpTimeoutOptions;
624
+
517
625
  /**
518
626
  * @deprecated This is deprecated. Use CompletionResult.type information instead.
519
627
  */
@@ -568,28 +676,28 @@ export interface ExecutionOptions extends StatelessExecutionOptions {
568
676
  //Common names to share between different models
569
677
  export enum SharedOptions {
570
678
  //Text
571
- max_tokens = "max_tokens",
572
- temperature = "temperature",
573
- top_p = "top_p",
574
- top_k = "top_k",
575
- presence_penalty = "presence_penalty",
576
- frequency_penalty = "frequency_penalty",
577
- stop_sequence = "stop_sequence",
578
- effort = "effort",
679
+ max_tokens = 'max_tokens',
680
+ temperature = 'temperature',
681
+ top_p = 'top_p',
682
+ top_k = 'top_k',
683
+ presence_penalty = 'presence_penalty',
684
+ frequency_penalty = 'frequency_penalty',
685
+ stop_sequence = 'stop_sequence',
686
+ effort = 'effort',
579
687
 
580
688
  //Image
581
- seed = "seed",
582
- number_of_images = "number_of_images",
689
+ seed = 'seed',
690
+ number_of_images = 'number_of_images',
583
691
  }
584
692
 
585
693
  export enum OptionType {
586
- numeric = "numeric",
587
- enum = "enum",
588
- boolean = "boolean",
589
- string_list = "string_list"
694
+ numeric = 'numeric',
695
+ enum = 'enum',
696
+ boolean = 'boolean',
697
+ string_list = 'string_list',
590
698
  }
591
699
 
592
- export type ReasoningEffort = "low" | "medium" | "high";
700
+ export type ReasoningEffort = 'low' | 'medium' | 'high';
593
701
 
594
702
  // ============== Model Options ===============
595
703
 
@@ -647,16 +755,16 @@ export interface StringListOptionInfo extends OptionInfoPrototype {
647
755
 
648
756
  // ============== Prompts ===============
649
757
  export enum PromptRole {
650
- safety = "safety",
651
- system = "system",
652
- user = "user",
653
- assistant = "assistant",
654
- negative = "negative",
655
- mask = "mask",
758
+ safety = 'safety',
759
+ system = 'system',
760
+ user = 'user',
761
+ assistant = 'assistant',
762
+ negative = 'negative',
763
+ mask = 'mask',
656
764
  /**
657
765
  * Used to send the response of a tool
658
766
  */
659
- tool = "tool"
767
+ tool = 'tool',
660
768
  }
661
769
 
662
770
  export interface PromptSegment {
@@ -671,7 +779,7 @@ export interface PromptSegment {
671
779
  * This should be copied from the ToolUse.thought_signature when sending tool responses.
672
780
  */
673
781
  thought_signature?: string;
674
- files?: DataSource[]
782
+ files?: DataSource[];
675
783
  }
676
784
 
677
785
  export interface ExecutionTokenUsage {
@@ -695,8 +803,8 @@ export interface ExecutionTokenUsage {
695
803
  * @deprecated This is deprecated. Use CompletionResult.type information instead.
696
804
  */
697
805
  export enum Modalities {
698
- text = "text",
699
- image = "image",
806
+ text = 'text',
807
+ image = 'image',
700
808
  }
701
809
 
702
810
  /**
@@ -731,7 +839,7 @@ export interface AIModel<ProviderKeys = string> {
731
839
  status?: AIModelStatus; //status of the model
732
840
  can_stream?: boolean; //if the model's response can be streamed
733
841
  is_custom?: boolean; //if the model is a custom model (a trained model)
734
- is_multimodal?: boolean //if the model support files and images
842
+ is_multimodal?: boolean; //if the model support files and images
735
843
  input_modalities?: string[]; //Input modalities supported by the model (e.g. text, image, video, audio)
736
844
  output_modalities?: string[]; //Output modalities supported by the model (e.g. text, image, video, audio)
737
845
  tool_support?: boolean; //if the model supports tool use
@@ -739,12 +847,12 @@ export interface AIModel<ProviderKeys = string> {
739
847
  }
740
848
 
741
849
  export enum AIModelStatus {
742
- Available = "available",
743
- Pending = "pending",
744
- Stopped = "stopped",
745
- Unavailable = "unavailable",
746
- Unknown = "unknown",
747
- Legacy = "legacy",
850
+ Available = 'available',
851
+ Pending = 'pending',
852
+ Stopped = 'stopped',
853
+ Unavailable = 'unavailable',
854
+ Unknown = 'unknown',
855
+ Legacy = 'legacy',
748
856
  }
749
857
 
750
858
  /**
@@ -761,37 +869,34 @@ export interface ModelSearchPayload {
761
869
  owner?: string;
762
870
  }
763
871
 
764
-
765
872
  export enum ModelType {
766
- Classifier = "classifier",
767
- Regressor = "regressor",
768
- Clustering = "clustering",
769
- AnomalyDetection = "anomaly-detection",
770
- TimeSeries = "time-series",
771
- Text = "text",
772
- Image = "image",
773
- Audio = "audio",
774
- Video = "video",
775
- Embedding = "embedding",
776
- Chat = "chat",
777
- Code = "code",
778
- NLP = "nlp",
779
- MultiModal = "multi-modal",
780
- Test = "test",
781
- Other = "other",
782
- Unknown = "unknown"
873
+ Classifier = 'classifier',
874
+ Regressor = 'regressor',
875
+ Clustering = 'clustering',
876
+ AnomalyDetection = 'anomaly-detection',
877
+ TimeSeries = 'time-series',
878
+ Text = 'text',
879
+ Image = 'image',
880
+ Audio = 'audio',
881
+ Video = 'video',
882
+ Embedding = 'embedding',
883
+ Chat = 'chat',
884
+ Code = 'code',
885
+ NLP = 'nlp',
886
+ MultiModal = 'multi-modal',
887
+ Test = 'test',
888
+ Other = 'other',
889
+ Unknown = 'unknown',
783
890
  }
784
891
 
785
-
786
892
  // ============== training =====================
787
893
 
788
-
789
-
790
894
  export interface DataSource {
791
895
  name: string;
792
896
  mime_type: string;
793
897
  getStream(): Promise<ReadableStream<Uint8Array | string>>;
794
898
  getURL(): Promise<string>;
899
+ getURI(): Promise<string>;
795
900
  }
796
901
 
797
902
  export interface TrainingOptions {
@@ -802,16 +907,16 @@ export interface TrainingOptions {
802
907
 
803
908
  export interface TrainingPromptOptions {
804
909
  segments: PromptSegment[];
805
- completion: CompletionResult[]
910
+ completion: CompletionResult[];
806
911
  model: string; // the model to train
807
912
  schema?: JSONSchema; // the result schema f any
808
913
  }
809
914
 
810
915
  export enum TrainingJobStatus {
811
- running = "running",
812
- succeeded = "succeeded",
813
- failed = "failed",
814
- cancelled = "cancelled",
916
+ running = 'running',
917
+ succeeded = 'succeeded',
918
+ failed = 'failed',
919
+ cancelled = 'cancelled',
815
920
  }
816
921
 
817
922
  export interface TrainingJob {