@fgv/ts-extras 5.1.0-26 → 5.1.0-28

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 (149) hide show
  1. package/dist/index.browser.js +2 -2
  2. package/dist/index.browser.js.map +1 -1
  3. package/dist/packlets/ai-assist/apiClient.js +300 -213
  4. package/dist/packlets/ai-assist/apiClient.js.map +1 -1
  5. package/dist/packlets/ai-assist/chatRequestBuilders.js +6 -0
  6. package/dist/packlets/ai-assist/chatRequestBuilders.js.map +1 -1
  7. package/dist/packlets/ai-assist/imageOptionsResolver.js +212 -0
  8. package/dist/packlets/ai-assist/imageOptionsResolver.js.map +1 -0
  9. package/dist/packlets/ai-assist/index.js +1 -0
  10. package/dist/packlets/ai-assist/index.js.map +1 -1
  11. package/dist/packlets/ai-assist/model.js +1 -1
  12. package/dist/packlets/ai-assist/model.js.map +1 -1
  13. package/dist/packlets/ai-assist/registry.js +120 -22
  14. package/dist/packlets/ai-assist/registry.js.map +1 -1
  15. package/dist/packlets/ai-assist/sseParser.js +1 -0
  16. package/dist/packlets/ai-assist/sseParser.js.map +1 -1
  17. package/dist/packlets/ai-assist/streamingAdapters/anthropic.js +17 -12
  18. package/dist/packlets/ai-assist/streamingAdapters/anthropic.js.map +1 -1
  19. package/dist/packlets/ai-assist/streamingAdapters/common.js +2 -0
  20. package/dist/packlets/ai-assist/streamingAdapters/common.js.map +1 -1
  21. package/dist/packlets/ai-assist/streamingAdapters/gemini.js +17 -5
  22. package/dist/packlets/ai-assist/streamingAdapters/gemini.js.map +1 -1
  23. package/dist/packlets/ai-assist/streamingAdapters/openaiChat.js +19 -4
  24. package/dist/packlets/ai-assist/streamingAdapters/openaiChat.js.map +1 -1
  25. package/dist/packlets/ai-assist/streamingAdapters/openaiResponses.js +20 -5
  26. package/dist/packlets/ai-assist/streamingAdapters/openaiResponses.js.map +1 -1
  27. package/dist/packlets/ai-assist/streamingAdapters/proxy.js +9 -3
  28. package/dist/packlets/ai-assist/streamingAdapters/proxy.js.map +1 -1
  29. package/dist/packlets/ai-assist/streamingClient.js +28 -6
  30. package/dist/packlets/ai-assist/streamingClient.js.map +1 -1
  31. package/dist/packlets/ai-assist/thinkingOptionsResolver.js +265 -0
  32. package/dist/packlets/ai-assist/thinkingOptionsResolver.js.map +1 -0
  33. package/dist/packlets/conversion/converters.js +1 -0
  34. package/dist/packlets/conversion/converters.js.map +1 -1
  35. package/dist/packlets/crypto-utils/converters.js +24 -4
  36. package/dist/packlets/crypto-utils/converters.js.map +1 -1
  37. package/dist/packlets/crypto-utils/hpkeProvider.js +333 -0
  38. package/dist/packlets/crypto-utils/hpkeProvider.js.map +1 -0
  39. package/dist/packlets/crypto-utils/index.browser.js +3 -0
  40. package/dist/packlets/crypto-utils/index.browser.js.map +1 -1
  41. package/dist/packlets/crypto-utils/index.js +2 -0
  42. package/dist/packlets/crypto-utils/index.js.map +1 -1
  43. package/dist/packlets/crypto-utils/keystore/converters.js +2 -2
  44. package/dist/packlets/crypto-utils/keystore/converters.js.map +1 -1
  45. package/dist/packlets/crypto-utils/keystore/keyStore.js +108 -2
  46. package/dist/packlets/crypto-utils/keystore/keyStore.js.map +1 -1
  47. package/dist/packlets/crypto-utils/keystore/model.js.map +1 -1
  48. package/dist/packlets/crypto-utils/model.js +21 -0
  49. package/dist/packlets/crypto-utils/model.js.map +1 -1
  50. package/dist/packlets/crypto-utils/nodeCryptoProvider.js +74 -0
  51. package/dist/packlets/crypto-utils/nodeCryptoProvider.js.map +1 -1
  52. package/dist/ts-extras.d.ts +1029 -137
  53. package/dist/tsdoc-metadata.json +1 -1
  54. package/lib/index.browser.d.ts +2 -2
  55. package/lib/index.browser.d.ts.map +1 -1
  56. package/lib/index.browser.js +4 -3
  57. package/lib/index.browser.js.map +1 -1
  58. package/lib/packlets/ai-assist/apiClient.d.ts +29 -85
  59. package/lib/packlets/ai-assist/apiClient.d.ts.map +1 -1
  60. package/lib/packlets/ai-assist/apiClient.js +300 -213
  61. package/lib/packlets/ai-assist/apiClient.js.map +1 -1
  62. package/lib/packlets/ai-assist/chatRequestBuilders.d.ts.map +1 -1
  63. package/lib/packlets/ai-assist/chatRequestBuilders.js +6 -0
  64. package/lib/packlets/ai-assist/chatRequestBuilders.js.map +1 -1
  65. package/lib/packlets/ai-assist/imageOptionsResolver.d.ts +74 -0
  66. package/lib/packlets/ai-assist/imageOptionsResolver.d.ts.map +1 -0
  67. package/lib/packlets/ai-assist/imageOptionsResolver.js +216 -0
  68. package/lib/packlets/ai-assist/imageOptionsResolver.js.map +1 -0
  69. package/lib/packlets/ai-assist/index.d.ts +2 -1
  70. package/lib/packlets/ai-assist/index.d.ts.map +1 -1
  71. package/lib/packlets/ai-assist/index.js +4 -1
  72. package/lib/packlets/ai-assist/index.js.map +1 -1
  73. package/lib/packlets/ai-assist/model.d.ts +410 -35
  74. package/lib/packlets/ai-assist/model.d.ts.map +1 -1
  75. package/lib/packlets/ai-assist/model.js +1 -1
  76. package/lib/packlets/ai-assist/model.js.map +1 -1
  77. package/lib/packlets/ai-assist/registry.d.ts.map +1 -1
  78. package/lib/packlets/ai-assist/registry.js +120 -22
  79. package/lib/packlets/ai-assist/registry.js.map +1 -1
  80. package/lib/packlets/ai-assist/sseParser.d.ts.map +1 -1
  81. package/lib/packlets/ai-assist/sseParser.js +1 -0
  82. package/lib/packlets/ai-assist/sseParser.js.map +1 -1
  83. package/lib/packlets/ai-assist/streamingAdapters/anthropic.d.ts +2 -1
  84. package/lib/packlets/ai-assist/streamingAdapters/anthropic.d.ts.map +1 -1
  85. package/lib/packlets/ai-assist/streamingAdapters/anthropic.js +17 -12
  86. package/lib/packlets/ai-assist/streamingAdapters/anthropic.js.map +1 -1
  87. package/lib/packlets/ai-assist/streamingAdapters/common.d.ts +5 -1
  88. package/lib/packlets/ai-assist/streamingAdapters/common.d.ts.map +1 -1
  89. package/lib/packlets/ai-assist/streamingAdapters/common.js +2 -0
  90. package/lib/packlets/ai-assist/streamingAdapters/common.js.map +1 -1
  91. package/lib/packlets/ai-assist/streamingAdapters/gemini.d.ts +2 -1
  92. package/lib/packlets/ai-assist/streamingAdapters/gemini.d.ts.map +1 -1
  93. package/lib/packlets/ai-assist/streamingAdapters/gemini.js +17 -5
  94. package/lib/packlets/ai-assist/streamingAdapters/gemini.js.map +1 -1
  95. package/lib/packlets/ai-assist/streamingAdapters/openaiChat.d.ts +2 -1
  96. package/lib/packlets/ai-assist/streamingAdapters/openaiChat.d.ts.map +1 -1
  97. package/lib/packlets/ai-assist/streamingAdapters/openaiChat.js +19 -4
  98. package/lib/packlets/ai-assist/streamingAdapters/openaiChat.js.map +1 -1
  99. package/lib/packlets/ai-assist/streamingAdapters/openaiResponses.d.ts +2 -1
  100. package/lib/packlets/ai-assist/streamingAdapters/openaiResponses.d.ts.map +1 -1
  101. package/lib/packlets/ai-assist/streamingAdapters/openaiResponses.js +20 -5
  102. package/lib/packlets/ai-assist/streamingAdapters/openaiResponses.js.map +1 -1
  103. package/lib/packlets/ai-assist/streamingAdapters/proxy.d.ts.map +1 -1
  104. package/lib/packlets/ai-assist/streamingAdapters/proxy.js +9 -3
  105. package/lib/packlets/ai-assist/streamingAdapters/proxy.js.map +1 -1
  106. package/lib/packlets/ai-assist/streamingClient.d.ts.map +1 -1
  107. package/lib/packlets/ai-assist/streamingClient.js +28 -6
  108. package/lib/packlets/ai-assist/streamingClient.js.map +1 -1
  109. package/lib/packlets/ai-assist/thinkingOptionsResolver.d.ts +71 -0
  110. package/lib/packlets/ai-assist/thinkingOptionsResolver.d.ts.map +1 -0
  111. package/lib/packlets/ai-assist/thinkingOptionsResolver.js +270 -0
  112. package/lib/packlets/ai-assist/thinkingOptionsResolver.js.map +1 -0
  113. package/lib/packlets/conversion/converters.d.ts.map +1 -1
  114. package/lib/packlets/conversion/converters.js +1 -0
  115. package/lib/packlets/conversion/converters.js.map +1 -1
  116. package/lib/packlets/crypto-utils/converters.d.ts +12 -1
  117. package/lib/packlets/crypto-utils/converters.d.ts.map +1 -1
  118. package/lib/packlets/crypto-utils/converters.js +25 -5
  119. package/lib/packlets/crypto-utils/converters.js.map +1 -1
  120. package/lib/packlets/crypto-utils/hpkeProvider.d.ts +142 -0
  121. package/lib/packlets/crypto-utils/hpkeProvider.d.ts.map +1 -0
  122. package/lib/packlets/crypto-utils/hpkeProvider.js +337 -0
  123. package/lib/packlets/crypto-utils/hpkeProvider.js.map +1 -0
  124. package/lib/packlets/crypto-utils/index.browser.d.ts +1 -0
  125. package/lib/packlets/crypto-utils/index.browser.d.ts.map +1 -1
  126. package/lib/packlets/crypto-utils/index.browser.js +5 -1
  127. package/lib/packlets/crypto-utils/index.browser.js.map +1 -1
  128. package/lib/packlets/crypto-utils/index.d.ts +1 -0
  129. package/lib/packlets/crypto-utils/index.d.ts.map +1 -1
  130. package/lib/packlets/crypto-utils/index.js +4 -1
  131. package/lib/packlets/crypto-utils/index.js.map +1 -1
  132. package/lib/packlets/crypto-utils/keystore/converters.js +1 -1
  133. package/lib/packlets/crypto-utils/keystore/converters.js.map +1 -1
  134. package/lib/packlets/crypto-utils/keystore/keyStore.d.ts +32 -2
  135. package/lib/packlets/crypto-utils/keystore/keyStore.d.ts.map +1 -1
  136. package/lib/packlets/crypto-utils/keystore/keyStore.js +116 -10
  137. package/lib/packlets/crypto-utils/keystore/keyStore.js.map +1 -1
  138. package/lib/packlets/crypto-utils/keystore/model.d.ts +21 -3
  139. package/lib/packlets/crypto-utils/keystore/model.d.ts.map +1 -1
  140. package/lib/packlets/crypto-utils/keystore/model.js.map +1 -1
  141. package/lib/packlets/crypto-utils/model.d.ts +165 -9
  142. package/lib/packlets/crypto-utils/model.d.ts.map +1 -1
  143. package/lib/packlets/crypto-utils/model.js +22 -1
  144. package/lib/packlets/crypto-utils/model.js.map +1 -1
  145. package/lib/packlets/crypto-utils/nodeCryptoProvider.d.ts +39 -0
  146. package/lib/packlets/crypto-utils/nodeCryptoProvider.d.ts.map +1 -1
  147. package/lib/packlets/crypto-utils/nodeCryptoProvider.js +74 -0
  148. package/lib/packlets/crypto-utils/nodeCryptoProvider.js.map +1 -1
  149. package/package.json +13 -13
@@ -3,6 +3,7 @@ import { Converter } from '@fgv/ts-utils';
3
3
  import { DateTime } from 'luxon';
4
4
  import { FileTree } from '@fgv/ts-json-base';
5
5
  import { Hash as Hash_2 } from '@fgv/ts-utils';
6
+ import { JsonObject } from '@fgv/ts-json-base';
6
7
  import { JsonValue } from '@fgv/ts-json-base';
7
8
  import { Logging } from '@fgv/ts-utils';
8
9
  import { Result } from '@fgv/ts-utils';
@@ -42,6 +43,30 @@ declare namespace AiAssist {
42
43
  IAiAssistKeyStore,
43
44
  IAiImageAttachment,
44
45
  IAiImageData,
46
+ AiImageSize,
47
+ AiImageQuality,
48
+ DallE2Size,
49
+ DallE3Size,
50
+ GptImageSize,
51
+ DallE3Quality,
52
+ GptImageQuality,
53
+ DallEModelNames,
54
+ GptImageModelNames,
55
+ GrokImagineModelNames,
56
+ Imagen4ModelNames,
57
+ GeminiFlashImageModelNames,
58
+ IDallEImageGenerationConfig,
59
+ IGptImageGenerationConfig,
60
+ IGrokImagineImageGenerationConfig,
61
+ IImagen4GenerationConfig,
62
+ IGeminiFlashImageGenerationConfig,
63
+ IDallEModelOptions,
64
+ IGptImageModelOptions,
65
+ IGrokImagineModelOptions,
66
+ IImagen4ModelOptions,
67
+ IGeminiFlashImageModelOptions,
68
+ IOtherModelOptions,
69
+ IModelFamilyConfig,
45
70
  IAiImageGenerationOptions,
46
71
  IAiImageGenerationParams,
47
72
  IAiGeneratedImage,
@@ -61,6 +86,25 @@ declare namespace AiAssist {
61
86
  MODEL_SPEC_BASE_KEY,
62
87
  resolveModel,
63
88
  toDataUrl,
89
+ AiThinkingMode,
90
+ IThinkingConfig,
91
+ IThinkingProviderConfig,
92
+ IAnthropicThinkingOptions,
93
+ IOpenAiThinkingOptions,
94
+ IGeminiThinkingOptions,
95
+ IXAiThinkingOptions,
96
+ IOtherThinkingOptions,
97
+ IAnthropicThinkingConfig,
98
+ IOpenAiThinkingConfig,
99
+ IGeminiThinkingConfig,
100
+ IXAiThinkingConfig,
101
+ AnthropicThinkingModelNames,
102
+ OpenAiThinkingModelNames,
103
+ GeminiThinkingModelNames,
104
+ XAiThinkingModelNames,
105
+ IResolvedImageOptions,
106
+ resolveImageOptions,
107
+ validateResolvedOptions,
64
108
  allProviderIds,
65
109
  getProviderDescriptors,
66
110
  getProviderDescriptor,
@@ -121,8 +165,9 @@ declare const aiAssistSettings: Converter<IAiAssistSettings>;
121
165
  * @remarks
122
166
  * - `'openai-images'` — OpenAI Images API. Routes to `/images/generations`
123
167
  * (text-only) or `/images/edits` (when reference images are present).
124
- * - `'xai-images'` — xAI Images API. Same wire shape as OpenAI but text-only;
125
- * no reference-image support on grok-2-image.
168
+ * - `'xai-images'` — xAI Images API. Text-only JSON generation request.
169
+ * - `'xai-images-edits'` xAI Images API for Grok Imagine models. Uses JSON
170
+ * body with `{ type: "image_url" }` objects (not multipart).
126
171
  * - `'gemini-imagen'` — Google Imagen `:predict` endpoint. Text-only.
127
172
  * - `'gemini-image-out'` — Google Gemini chat-style `:generateContent`
128
173
  * endpoint that returns image parts (Gemini 2.5 Flash Image / "Nano
@@ -130,7 +175,13 @@ declare const aiAssistSettings: Converter<IAiAssistSettings>;
130
175
  *
131
176
  * @public
132
177
  */
133
- declare type AiImageApiFormat = 'openai-images' | 'gemini-imagen' | 'xai-images' | 'gemini-image-out';
178
+ declare type AiImageApiFormat = 'openai-images' | 'gemini-imagen' | 'xai-images' | 'xai-images-edits' | 'gemini-image-out';
179
+
180
+ /** All accepted quality strings across all providers. @public */
181
+ declare type AiImageQuality = DallE3Quality | GptImageQuality;
182
+
183
+ /** All accepted image size strings across all providers. @public */
184
+ declare type AiImageSize = DallE2Size | DallE3Size | GptImageSize;
134
185
 
135
186
  /**
136
187
  * Capability vocabulary used to describe what a model can do. Used as both
@@ -143,7 +194,7 @@ declare type AiImageApiFormat = 'openai-images' | 'gemini-imagen' | 'xai-images'
143
194
  *
144
195
  * @public
145
196
  */
146
- declare type AiModelCapability = 'chat' | 'tools' | 'vision' | 'image-generation';
197
+ declare type AiModelCapability = 'chat' | 'tools' | 'vision' | 'image-generation' | 'thinking';
147
198
 
148
199
  /**
149
200
  * A structured AI prompt with system/user split for direct API calls,
@@ -206,6 +257,12 @@ declare type AiServerToolType = 'web_search';
206
257
  */
207
258
  declare const aiServerToolType: Converter<AiServerToolType>;
208
259
 
260
+ /**
261
+ * Thinking/reasoning mode support for a provider.
262
+ * @public
263
+ */
264
+ declare type AiThinkingMode = 'optional' | 'required' | 'unsupported';
265
+
209
266
  /**
210
267
  * Converter for {@link IAiToolEnablement}.
211
268
  * @public
@@ -254,6 +311,31 @@ declare const allModelSpecKeys: ReadonlyArray<ModelSpecKey>;
254
311
  */
255
312
  declare const allProviderIds: ReadonlyArray<AiProviderId>;
256
313
 
314
+ /**
315
+ * Model IDs for Anthropic thinking-capable models.
316
+ * @public
317
+ */
318
+ declare type AnthropicThinkingModelNames = 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7';
319
+
320
+ /**
321
+ * Recommended OWASP 2023 minimum Argon2id parameters.
322
+ * Suitable for recovery-row key derivation (high-entropy inputs).
323
+ * @public
324
+ */
325
+ declare const ARGON2ID_OWASP_MIN: IArgon2idParams;
326
+
327
+ /**
328
+ * Stronger Argon2id parameters suitable for user-typed passphrases.
329
+ * @public
330
+ */
331
+ declare const ARGON2ID_PASSPHRASE: IArgon2idParams;
332
+
333
+ /**
334
+ * Converter for {@link CryptoUtils.IArgon2idKeyDerivationParams | Argon2id key derivation parameters}.
335
+ * @public
336
+ */
337
+ declare const argon2idKeyDerivationParams: Converter<IArgon2idKeyDerivationParams>;
338
+
257
339
  /**
258
340
  * Converter for base64 strings (validates format).
259
341
  * @public
@@ -262,17 +344,8 @@ declare const base64String: Converter<string>;
262
344
 
263
345
  /**
264
346
  * Calls the appropriate chat completion API for a given provider.
265
- *
266
- * Routes based on the provider descriptor's `apiFormat` field:
267
- * - `'openai'` for xAI, OpenAI, Groq, Mistral
268
- * - `'anthropic'` for Anthropic Claude
269
- * - `'gemini'` for Google Gemini
270
- *
271
- * When tools are provided and the provider supports them:
272
- * - OpenAI-format providers switch to the Responses API
273
- * - Anthropic includes tools in the Messages API request
274
- * - Gemini includes Google Search grounding
275
- *
347
+ * Routes by `apiFormat`: `'openai'` (xAI/OpenAI/Groq/Mistral — switches to Responses API when
348
+ * tools are set), `'anthropic'`, or `'gemini'`.
276
349
  * @param params - Request parameters including descriptor, API key, prompt, and optional tools
277
350
  * @returns The completion response with content and truncation status, or a failure
278
351
  * @public
@@ -301,19 +374,10 @@ declare function callProviderCompletionStream(params: IProviderCompletionStreamP
301
374
 
302
375
  /**
303
376
  * Calls the appropriate image-generation API for a given provider.
304
- *
305
- * Resolves a {@link IAiImageModelCapability} from
306
- * {@link IAiProviderDescriptor.imageGeneration} for the requested model and
307
- * routes by its `format`:
308
- * - `'openai-images'` for OpenAI (DALL-E, gpt-image-1)
309
- * - `'xai-images'` for xAI Grok image models
310
- * - `'gemini-imagen'` for Google Imagen `:predict`
311
- * - `'gemini-image-out'` for Gemini chat-style image output (Nano Banana)
312
- *
313
- * Image-model selection reuses the existing `'image'` {@link ModelSpecKey}.
314
- * When `request.referenceImages` is non-empty, the call is rejected up front
315
- * unless the resolved capability declares `acceptsImageReferenceInput`.
316
- *
377
+ * Routes by the `format` field of the resolved {@link IAiImageModelCapability}:
378
+ * `'openai-images'`, `'xai-images'`, `'xai-images-edits'`, `'gemini-imagen'`,
379
+ * or `'gemini-image-out'`. Rejects up front if `referenceImages` is set but the
380
+ * capability does not declare `acceptsImageReferenceInput`.
317
381
  * @param params - Request parameters including descriptor, API key, and prompt
318
382
  * @returns The generated images, or a failure
319
383
  * @public
@@ -321,12 +385,8 @@ declare function callProviderCompletionStream(params: IProviderCompletionStreamP
321
385
  declare function callProviderImageGeneration(params: IProviderImageGenerationParams): Promise<Result<IAiImageGenerationResponse>>;
322
386
 
323
387
  /**
324
- * Lists models available from a provider, with capabilities resolved from
325
- * native provider info (where supplied) and a configurable rule set.
326
- *
327
- * Routes based on `descriptor.apiFormat` — listing reuses the existing
328
- * format dispatch and does not require a separate descriptor field.
329
- *
388
+ * Lists models available from a provider, routing by `descriptor.apiFormat`.
389
+ * Capabilities are resolved from native provider info and a configurable rule set.
330
390
  * @param params - Request parameters including descriptor, API key, and optional capability filter
331
391
  * @returns The resolved model list, or a failure
332
392
  * @public
@@ -374,20 +434,11 @@ declare function callProxiedCompletionStream(proxyUrl: string, params: IProvider
374
434
  /**
375
435
  * Calls the image-generation endpoint on a proxy server instead of calling
376
436
  * the provider API directly from the browser.
377
- *
378
- * @remarks
379
- * The proxy contract:
380
- * - Endpoint: `POST ${proxyUrl}/api/ai/image-generation`
381
- * - Request body: `{providerId, apiKey, params, modelOverride?}`
382
- * - Success response body: an {@link IAiImageGenerationResponse}
383
- * - Error response body: `{error: string}` (surfaced as `proxy: ${error}`)
384
- *
385
- * The proxy server is responsible for descriptor lookup, model resolution,
386
- * provider dispatch, and response normalization. When `params.referenceImages`
387
- * is present, the proxy is also responsible for repackaging it into the
388
- * upstream wire format (e.g. multipart/form-data for OpenAI `/images/edits`,
389
- * `inlineData` parts for Gemini `:generateContent`).
390
- *
437
+ * Endpoint: `POST ${proxyUrl}/api/ai/image-generation`. Request body:
438
+ * `{providerId, apiKey, params, modelOverride?}`. The proxy handles descriptor
439
+ * lookup, model resolution, provider dispatch, and response normalization
440
+ * (including repackaging `referenceImages` for the upstream wire format).
441
+ * Error body `{error: string}` is surfaced as `proxy: ${error}`.
391
442
  * @param proxyUrl - Base URL of the proxy server (e.g. `http://localhost:3001`)
392
443
  * @param params - Same parameters as {@link callProviderImageGeneration}
393
444
  * @returns The generated images, or a failure
@@ -397,18 +448,9 @@ declare function callProxiedImageGeneration(proxyUrl: string, params: IProviderI
397
448
 
398
449
  /**
399
450
  * Calls the model-listing endpoint on a proxy server.
400
- *
401
- * @remarks
402
- * Proxy contract:
403
- * - Endpoint: `POST ${proxyUrl}/api/ai/list-models`
404
- * - Request body: `{providerId, apiKey, capability?}`. Capability config is
405
- * not forwarded — the proxy applies its own (typically the same default
406
- * the library ships).
407
- * - Success response body: an `IAiModelInfo[]` (under key `models`) where
408
- * `capabilities` is serialized as a string array (not Set, which doesn't
409
- * round-trip through JSON).
410
- * - Error response body: `{error: string}`, surfaced as `proxy: ${error}`.
411
- *
451
+ * Endpoint: `POST ${proxyUrl}/api/ai/list-models`. Capability config is not
452
+ * forwarded. `capabilities` is serialized as a string array. Error body
453
+ * `{error: string}` is surfaced as `proxy: ${error}`.
412
454
  * @public
413
455
  */
414
456
  declare function callProxiedListModels(proxyUrl: string, params: IProviderListModelsParams): Promise<Result<ReadonlyArray<IAiModelInfo>>>;
@@ -458,6 +500,8 @@ declare namespace Converters_3 {
458
500
  encryptedFileFormat,
459
501
  encryptedFileErrorMode,
460
502
  keyDerivationFunction,
503
+ pbkdf2KeyDerivationParams,
504
+ argon2idKeyDerivationParams,
461
505
  keyDerivationParams,
462
506
  base64String,
463
507
  uint8ArrayFromBase64,
@@ -511,6 +555,8 @@ declare namespace CryptoUtils {
511
555
  importPublicKeyFromMultibaseSpki,
512
556
  multibaseBase64UrlDecode,
513
557
  multibaseBase64UrlEncode,
558
+ HpkeProvider,
559
+ IHpkeSealResult,
514
560
  isEncryptedFile,
515
561
  EncryptionAlgorithm,
516
562
  EncryptedFileFormat,
@@ -521,7 +567,13 @@ declare namespace CryptoUtils {
521
567
  IWrappedBytes,
522
568
  allKeyPairAlgorithms,
523
569
  KeyDerivationFunction,
570
+ IPbkdf2KeyDerivationParams,
571
+ IArgon2idKeyDerivationParams,
524
572
  IKeyDerivationParams,
573
+ IArgon2idParams,
574
+ ARGON2ID_OWASP_MIN,
575
+ ARGON2ID_PASSPHRASE,
576
+ IArgon2idProvider,
525
577
  IEncryptedFile,
526
578
  ICryptoProvider,
527
579
  IEncryptionProvider,
@@ -550,6 +602,18 @@ declare interface CsvOptions {
550
602
  delimiter?: string;
551
603
  }
552
604
 
605
+ /** Pixel dimension sizes accepted by dall-e-2. @public */
606
+ declare type DallE2Size = '256x256' | '512x512' | '1024x1024';
607
+
608
+ /** Quality values for dall-e-3. @public */
609
+ declare type DallE3Quality = 'standard' | 'hd';
610
+
611
+ /** Pixel dimension sizes accepted by dall-e-3. @public */
612
+ declare type DallE3Size = '1024x1024' | '1792x1024' | '1024x1792';
613
+
614
+ /** Model names in the DALL-E family. @public */
615
+ declare type DallEModelNames = 'dall-e-2' | 'dall-e-3';
616
+
553
617
  /**
554
618
  * Decrypts an {@link CryptoUtils.IEncryptedFile | encrypted file} and returns the JSON content.
555
619
  * @typeParam TPayload - Expected type of decrypted content
@@ -936,6 +1000,15 @@ declare const GCM_AUTH_TAG_SIZE: number;
936
1000
  */
937
1001
  declare const GCM_IV_SIZE: number;
938
1002
 
1003
+ /** Model names in the Gemini Flash Image family. @public */
1004
+ declare type GeminiFlashImageModelNames = 'gemini-2.5-flash-image';
1005
+
1006
+ /**
1007
+ * Model IDs for Google Gemini thinking-capable models.
1008
+ * @public
1009
+ */
1010
+ declare type GeminiThinkingModelNames = 'gemini-2.5-pro' | 'gemini-2.5-flash' | 'gemini-2.5-flash-lite';
1011
+
939
1012
  /**
940
1013
  * Calls {@link AiAssist.callProviderCompletion}, then runs the response text
941
1014
  * through a tolerant JSON converter (default:
@@ -972,6 +1045,18 @@ declare function getProviderDescriptor(id: string): Result<IAiProviderDescriptor
972
1045
  */
973
1046
  declare function getProviderDescriptors(): ReadonlyArray<IAiProviderDescriptor>;
974
1047
 
1048
+ /** Model names in the GPT Image family. @public */
1049
+ declare type GptImageModelNames = 'gpt-image-1';
1050
+
1051
+ /** Quality values for gpt-image-1. @public */
1052
+ declare type GptImageQuality = 'low' | 'medium' | 'high' | 'auto';
1053
+
1054
+ /** Pixel dimension sizes accepted by gpt-image-1. @public */
1055
+ declare type GptImageSize = '1024x1024' | '1536x1024' | '1024x1536' | 'auto';
1056
+
1057
+ /** Model names in the xAI Grok Imagine family. @public */
1058
+ declare type GrokImagineModelNames = 'grok-imagine-image' | 'grok-imagine-image-quality';
1059
+
975
1060
  declare namespace Hash {
976
1061
  export {
977
1062
  Md5Normalizer
@@ -979,6 +1064,128 @@ declare namespace Hash {
979
1064
  }
980
1065
  export { Hash }
981
1066
 
1067
+ /**
1068
+ * HPKE base mode (RFC 9180) — `DHKEM(X25519, HKDF-SHA256) + HKDF-SHA256 + AES-256-GCM`.
1069
+ *
1070
+ * Class-based provider that captures a `SubtleCrypto` instance at construction,
1071
+ * matching the existing `NodeCryptoProvider` / `BrowserCryptoProvider` / `KeyStore`
1072
+ * factory pattern used throughout `@fgv/ts-extras/crypto-utils`.
1073
+ *
1074
+ * **Node.js usage:**
1075
+ * ```typescript
1076
+ * import * as crypto from 'crypto';
1077
+ * const hpke = HpkeProvider.create(crypto.webcrypto.subtle).orThrow();
1078
+ * ```
1079
+ *
1080
+ * **Browser usage:**
1081
+ * ```typescript
1082
+ * const hpke = HpkeProvider.create(globalThis.crypto.subtle).orThrow();
1083
+ * ```
1084
+ *
1085
+ * **Runtime requirements:** Node.js 20+ (X25519 in `crypto.webcrypto`);
1086
+ * Chrome 113+, Safari 16.4+, Firefox 118+ (X25519 added to Web Crypto in 2023).
1087
+ * @public
1088
+ */
1089
+ declare class HpkeProvider {
1090
+ private readonly _subtle;
1091
+ private constructor();
1092
+ /**
1093
+ * Creates an `HpkeProvider` bound to the given `SubtleCrypto` instance.
1094
+ *
1095
+ * @param subtle - Web Crypto SubtleCrypto instance.
1096
+ * Node.js: `(await import('crypto')).webcrypto.subtle`.
1097
+ * Browser: `globalThis.crypto.subtle`.
1098
+ * @returns `Success` with the provider, or `Failure` if construction fails.
1099
+ */
1100
+ static create(subtle: SubtleCrypto): Result<HpkeProvider>;
1101
+ /**
1102
+ * HPKE base-mode seal (sender side). RFC 9180 §6.1.
1103
+ *
1104
+ * Generates a fresh ephemeral X25519 keypair, runs DHKEM Encap to produce a
1105
+ * shared secret and `enc` (32-byte raw ephemeral public key), derives the AEAD
1106
+ * key and nonce deterministically via the RFC 9180 key schedule, then encrypts
1107
+ * `plaintext` with AES-256-GCM.
1108
+ *
1109
+ * @param recipientPublicKey - Recipient's X25519 public `CryptoKey`
1110
+ * (`algorithm.name === 'X25519'`, `type === 'public'`, **`extractable: true`**).
1111
+ * Must be extractable — DHKEM Encap calls `exportKey('raw', ...)` on this key to
1112
+ * build the KEM shared-secret context. Keys imported with `extractable: false` will
1113
+ * cause this method to return a `Failure`.
1114
+ * @param info - Context-binding bytes. **Load-bearing — no default.**
1115
+ * Binds this ciphertext to a specific application context, preventing replay
1116
+ * across different contexts sharing the same recipient keypair.
1117
+ * Use `new TextEncoder().encode('myapp/v1/use-case\x00' + contextId)` pattern.
1118
+ * Never pass an empty array in production: empty `info` provides no context binding.
1119
+ * @param aad - Additional authenticated data. Integrity-protected but not encrypted.
1120
+ * `new Uint8Array(0)` is valid when no AAD is needed.
1121
+ * @param plaintext - Bytes to encrypt. `new Uint8Array(0)` is valid.
1122
+ * @returns `Success` with `{ enc, ciphertext }`, or `Failure` with error context.
1123
+ */
1124
+ sealBase(recipientPublicKey: CryptoKey, info: Uint8Array, aad: Uint8Array, plaintext: Uint8Array): Promise<Result<IHpkeSealResult>>;
1125
+ /**
1126
+ * HPKE base-mode open (recipient side). RFC 9180 §6.1.
1127
+ *
1128
+ * Decapsulates `enc` using the recipient's X25519 private key, derives the same
1129
+ * AEAD key and nonce from the shared secret and `info`, then authenticates and
1130
+ * decrypts `ciphertext` with AES-256-GCM.
1131
+ *
1132
+ * Returns `Failure` on any of:
1133
+ * - Wrong private key (different DH output → different key derivation)
1134
+ * - Wrong `info` (different key schedule context → different AEAD key)
1135
+ * - Wrong `aad` (AES-GCM authentication fails)
1136
+ * - Tampered `ciphertext` or `enc` (authentication fails or DH fails)
1137
+ * - `enc` not exactly 32 bytes
1138
+ * - `ciphertext` shorter than 16 bytes (no room for authentication tag)
1139
+ *
1140
+ * @param recipientPrivateKey - Recipient's X25519 private `CryptoKey`
1141
+ * (`algorithm.name === 'X25519'`, `type === 'private'`, `usages` includes `'deriveBits'`).
1142
+ * **Must be extractable** (`extractable: true`) — the recipient's public key bytes
1143
+ * are recovered from the JWK `x` field during Decap.
1144
+ * @param info - Context-binding bytes. Must exactly match `info` from `sealBase`.
1145
+ * @param aad - Must exactly match `aad` from `sealBase`.
1146
+ * @param enc - The encapsulated key from `sealBase` — exactly 32 bytes.
1147
+ * @param ciphertext - The ciphertext from `sealBase` — `plaintext.length + 16` bytes.
1148
+ * @returns `Success` with decrypted plaintext bytes, or `Failure` with error context.
1149
+ */
1150
+ openBase(recipientPrivateKey: CryptoKey, info: Uint8Array, aad: Uint8Array, enc: Uint8Array, ciphertext: Uint8Array): Promise<Result<Uint8Array>>;
1151
+ /**
1152
+ * HKDF-SHA256 key derivation (RFC 5869). Extract-then-Expand using SHA-256.
1153
+ *
1154
+ * This is raw RFC 5869 HKDF — it does **not** use RFC 9180's labeled variants.
1155
+ * The HPKE key schedule internally uses labeled HKDF; this method is the unlabeled
1156
+ * version for callers that need standalone key derivation.
1157
+ *
1158
+ * @param secret - Input keying material (IKM). Any length.
1159
+ * @param salt - Optional salt. Use `new Uint8Array(0)` if no salt is available
1160
+ * (RFC 5869: 32 zero bytes are used internally when salt is empty).
1161
+ * @param info - Context / application-binding bytes. Any length.
1162
+ * @param length - Number of output bytes to derive. Maximum 8160 bytes (255 × 32).
1163
+ * @returns `Success` with derived bytes, or `Failure` with error context.
1164
+ */
1165
+ hkdf(secret: Uint8Array, salt: Uint8Array, info: Uint8Array, length: number): Promise<Result<Uint8Array>>;
1166
+ /**
1167
+ * Encodes an {@link IHpkeSealResult} as a single contiguous byte array for wire transport.
1168
+ *
1169
+ * Format: `enc` (32 bytes, fixed) || `ciphertext` (variable length).
1170
+ * The 32-byte `enc` length is fixed for X25519; the split point is unambiguous.
1171
+ *
1172
+ * @param result - The output of {@link HpkeProvider.sealBase}.
1173
+ * @returns Concatenated bytes: `enc || ciphertext`.
1174
+ */
1175
+ static encodeEnvelope(result: IHpkeSealResult): Uint8Array;
1176
+ /**
1177
+ * Decodes an envelope produced by {@link HpkeProvider.encodeEnvelope}.
1178
+ *
1179
+ * Validates that the buffer is at least 48 bytes (32-byte enc + 16-byte minimum
1180
+ * ciphertext containing the AES-GCM auth tag; zero-length plaintext is the minimum
1181
+ * meaningful case).
1182
+ *
1183
+ * @param envelope - Envelope bytes from `encodeEnvelope`.
1184
+ * @returns `Success` with `{ enc, ciphertext }`, or `Failure` if malformed.
1185
+ */
1186
+ static decodeEnvelope(envelope: Uint8Array): Result<IHpkeSealResult>;
1187
+ }
1188
+
982
1189
  /**
983
1190
  * Options for adding an asymmetric keypair to the key store.
984
1191
  * @public
@@ -1023,6 +1230,25 @@ declare interface IAddKeyPairResult {
1023
1230
  readonly warning?: string;
1024
1231
  }
1025
1232
 
1233
+ /**
1234
+ * Options for adding an Argon2id password-derived secret.
1235
+ * @public
1236
+ */
1237
+ declare interface IAddSecretFromPasswordArgon2idOptions {
1238
+ /**
1239
+ * Argon2id parameters. Defaults to {@link CryptoUtils.ARGON2ID_OWASP_MIN}.
1240
+ */
1241
+ readonly params?: IArgon2idParams;
1242
+ /**
1243
+ * Optional description for the secret.
1244
+ */
1245
+ readonly description?: string;
1246
+ /**
1247
+ * Whether to replace an existing secret with the same name.
1248
+ */
1249
+ readonly replace?: boolean;
1250
+ }
1251
+
1026
1252
  /**
1027
1253
  * Options for adding a secret derived from a password.
1028
1254
  * @public
@@ -1205,39 +1431,46 @@ declare interface IAiImageData {
1205
1431
  * Options for image generation requests.
1206
1432
  *
1207
1433
  * @remarks
1208
- * Provider compatibility is documented per field. The library does not
1209
- * pre-validate against per-model constraints (e.g. `dall-e-3` rejects
1210
- * `count > 1`); provider 400 errors surface through the failure path.
1434
+ * Uses a layered architecture:
1435
+ * 1. Generic top-level options (size, count, quality, seed) apply across providers
1436
+ * via the resolved model's registry mapping.
1437
+ * 2. Optional `models` array contains model-family-scoped blocks; the resolver
1438
+ * picks applicable blocks based on the resolved model and applies them in
1439
+ * declaration order.
1440
+ *
1441
+ * **Merge precedence (later wins):**
1442
+ * 1. Generic top-level options (lowest precedence)
1443
+ * 2. Family-generic blocks (matching family, models field omitted)
1444
+ * 3. Model-specific blocks (models array includes resolved model name)
1445
+ * 4. Other blocks (provider: 'other', models array includes resolved model name)
1446
+ *
1447
+ * Provider-mismatch: blocks whose provider doesn't match the dispatcher's
1448
+ * provider lineage are silently skipped.
1211
1449
  *
1212
1450
  * @public
1213
1451
  */
1214
1452
  declare interface IAiImageGenerationOptions {
1215
1453
  /**
1216
- * Image dimensions. Used by openai-format providers (mapped to the
1217
- * provider's `size` field). Ignored by Imagen use
1218
- * {@link IAiImageGenerationOptions.imagen} `aspectRatio` instead.
1219
- *
1220
- * Note: each model has its own accepted set; `dall-e-3` only accepts the
1221
- * values listed here.
1454
+ * Image dimensions for OpenAI models (mapped to `size` field).
1455
+ * For xAI aspect ratio or Imagen aspect ratio, use the corresponding `models` family block.
1222
1456
  */
1223
- readonly size?: '1024x1024' | '1024x1792' | '1792x1024' | 'auto';
1457
+ readonly size?: AiImageSize;
1458
+ /** Number of images. Default 1. Some models enforce a maximum. */
1459
+ readonly count?: number;
1224
1460
  /**
1225
- * Number of images to generate. Default 1.
1226
- *
1227
- * Note: `dall-e-3` rejects `count > 1`.
1461
+ * Quality tier. Accepted values differ per model:
1462
+ * - dall-e-3: 'standard' | 'hd'
1463
+ * - gpt-image-1: 'low' | 'medium' | 'high' | 'auto'
1464
+ * Other models ignore this field.
1228
1465
  */
1229
- readonly count?: number;
1230
- /** Generation quality hint where supported. */
1231
- readonly quality?: 'standard' | 'high';
1232
- /** Random seed for reproducibility, where supported. */
1466
+ readonly quality?: AiImageQuality;
1467
+ /** Reproducibility seed, where supported. */
1233
1468
  readonly seed?: number;
1234
1469
  /**
1235
- * Imagen-specific options. Ignored by other providers.
1470
+ * Optional precision via model-family-scoped blocks. The resolver picks
1471
+ * applicable blocks dynamically based on the resolved model.
1236
1472
  */
1237
- readonly imagen?: {
1238
- readonly negativePrompt?: string;
1239
- readonly aspectRatio?: '1:1' | '3:4' | '4:3' | '9:16' | '16:9';
1240
- };
1473
+ readonly models?: ReadonlyArray<IModelFamilyConfig>;
1241
1474
  }
1242
1475
 
1243
1476
  /**
@@ -1290,13 +1523,25 @@ declare interface IAiImageModelCapability {
1290
1523
  * Whether matching models accept reference images via
1291
1524
  * {@link AiAssist.IAiImageGenerationParams.referenceImages}. When false or
1292
1525
  * undefined, calls that include reference images are rejected up front.
1293
- *
1294
- * @remarks
1295
- * Per-model constraints beyond ref support (e.g. dall-e-3 ignores edits)
1296
- * are not validated here and surface as provider 400s, consistent with the
1297
- * existing image-generation policy.
1298
1526
  */
1299
1527
  readonly acceptsImageReferenceInput?: boolean;
1528
+ /** Accepted size strings. When present, dispatcher pre-validates. */
1529
+ readonly acceptedSizes?: ReadonlyArray<string>;
1530
+ /** When true, quality param is sent. When false/undefined, don't send quality. */
1531
+ readonly supportsQualityParam?: boolean;
1532
+ /** Accepted quality values when supportsQualityParam is true. */
1533
+ readonly acceptedQualities?: ReadonlyArray<string>;
1534
+ /** Maximum count (n). When present, dispatcher pre-validates. */
1535
+ readonly maxCount?: number;
1536
+ /**
1537
+ * How to encode the output format on the wire:
1538
+ * - 'response-format': send response_format: 'b64_json' (dall-e-2, dall-e-3)
1539
+ * - 'output-format': send output_format (gpt-image-1)
1540
+ * - 'none': send neither (Imagen, Gemini Flash)
1541
+ */
1542
+ readonly outputParamStyle?: 'response-format' | 'output-format' | 'none';
1543
+ /** Default MIME type for response images. */
1544
+ readonly defaultOutputMimeType?: string;
1300
1545
  }
1301
1546
 
1302
1547
  /**
@@ -1386,6 +1631,13 @@ declare interface IAiProviderDescriptor {
1386
1631
  * `prompt.attachments` are rejected up front.
1387
1632
  */
1388
1633
  readonly acceptsImageInput: boolean;
1634
+ /**
1635
+ * Whether this provider supports thinking/reasoning mode.
1636
+ * - 'optional': thinking can be enabled but is not required
1637
+ * - 'required': thinking is always active (e.g. o-series models)
1638
+ * - 'unsupported': thinking is not supported
1639
+ */
1640
+ readonly thinkingMode: AiThinkingMode;
1389
1641
  /**
1390
1642
  * Image-generation capabilities, scoped to model id prefixes. Empty or
1391
1643
  * undefined means the provider does not support image generation.
@@ -1510,6 +1762,104 @@ declare interface IAiWebSearchToolConfig {
1510
1762
  readonly enableImageUnderstanding?: boolean;
1511
1763
  }
1512
1764
 
1765
+ /**
1766
+ * Anthropic-specific thinking configuration.
1767
+ * @public
1768
+ */
1769
+ declare interface IAnthropicThinkingConfig {
1770
+ /**
1771
+ * Anthropic effort level. Maps 1:1 to `output_config.effort` on the wire.
1772
+ * - 'low' | 'medium' | 'high': all thinking-capable models
1773
+ * - 'max': Opus 4.6 only
1774
+ */
1775
+ readonly effort?: 'low' | 'medium' | 'high' | 'max';
1776
+ }
1777
+
1778
+ /**
1779
+ * Anthropic-specific thinking options block.
1780
+ * @public
1781
+ */
1782
+ declare interface IAnthropicThinkingOptions {
1783
+ readonly provider: 'anthropic';
1784
+ readonly models?: ReadonlyArray<AnthropicThinkingModelNames>;
1785
+ readonly config: IAnthropicThinkingConfig;
1786
+ }
1787
+
1788
+ /**
1789
+ * Argon2id key derivation parameters (RFC 9106).
1790
+ * @public
1791
+ */
1792
+ declare interface IArgon2idKeyDerivationParams {
1793
+ /** Key derivation function discriminator. */
1794
+ readonly kdf: 'argon2id';
1795
+ /** Base64-encoded salt used for key derivation. */
1796
+ readonly salt: string;
1797
+ /** Memory cost in kibibytes. */
1798
+ readonly memoryKiB: number;
1799
+ /** Number of passes (time cost). */
1800
+ readonly iterations: number;
1801
+ /** Degree of parallelism. */
1802
+ readonly parallelism: number;
1803
+ }
1804
+
1805
+ /**
1806
+ * Parameters for Argon2id key derivation (RFC 9106).
1807
+ * All fields are required; fgv does not pick defaults silently.
1808
+ * @public
1809
+ */
1810
+ declare interface IArgon2idParams {
1811
+ /**
1812
+ * Memory cost in kibibytes (KiB).
1813
+ * OWASP 2023 minimum: 19456 (19 MiB). Stronger: 65536 (64 MiB).
1814
+ * Constraint: \>= 8.
1815
+ */
1816
+ readonly memoryKiB: number;
1817
+ /**
1818
+ * Number of passes (iterations / time cost).
1819
+ * OWASP 2023 minimum: 2. Range: \>= 1.
1820
+ */
1821
+ readonly iterations: number;
1822
+ /**
1823
+ * Degree of parallelism (threads).
1824
+ * Note: WASM-based implementations compute sequentially regardless of this value,
1825
+ * but the value is wired into the algorithm and AFFECTS the output hash bytes.
1826
+ * Callers must use the same parallelism value consistently for a given secret.
1827
+ * Range: 1–255.
1828
+ */
1829
+ readonly parallelism: number;
1830
+ /**
1831
+ * Number of output bytes (hash length).
1832
+ * Typical values: 16 (128-bit), 32 (256-bit, AES-256 key), 64 (512-bit).
1833
+ * Constraint: \>= 4.
1834
+ */
1835
+ readonly outputBytes: number;
1836
+ }
1837
+
1838
+ /**
1839
+ * Argon2id key derivation provider (RFC 9106).
1840
+ *
1841
+ * Implementations are in separate packages to avoid WASM bundle costs for
1842
+ * consumers who don't need Argon2id:
1843
+ * - Node: `@fgv/ts-extras-argon2` (`NodeArgon2Provider`)
1844
+ * - Browser: `@fgv/ts-web-extras-argon2` (`BrowserArgon2Provider`)
1845
+ *
1846
+ * @public
1847
+ */
1848
+ declare interface IArgon2idProvider {
1849
+ /**
1850
+ * Derives key material from a password using Argon2id (RFC 9106 §3.1).
1851
+ *
1852
+ * Returns the raw derived bytes as a `Uint8Array`. Both Node and browser
1853
+ * implementations produce bit-identical output for identical inputs.
1854
+ *
1855
+ * @param password - Password or passphrase. Accepts string (UTF-8) or raw bytes.
1856
+ * @param salt - Salt bytes. Must be random and unique per credential (\>= 16 bytes recommended).
1857
+ * @param params - Argon2id parameters. Use `ARGON2ID_OWASP_MIN` as a starting point.
1858
+ * @returns Success with derived bytes, Failure with error context.
1859
+ */
1860
+ argon2id(password: Uint8Array | string, salt: Uint8Array, params: IArgon2idParams): Promise<Result<Uint8Array>>;
1861
+ }
1862
+
1513
1863
  /**
1514
1864
  * A single chat message in OpenAI format.
1515
1865
  * @public
@@ -1740,6 +2090,110 @@ declare interface ICryptoProvider {
1740
2090
  * @returns `Success` with the original `plaintext`, or `Failure` with error context.
1741
2091
  */
1742
2092
  unwrapBytes(wrapped: IWrappedBytes, recipientPrivateKey: CryptoKey, options: IWrapBytesOptions): Promise<Result<Uint8Array>>;
2093
+ /**
2094
+ * Signs `data` with `privateKey` using the algorithm inferred from the key.
2095
+ * Delegates to `crypto.subtle.sign`; the algorithm is derived from
2096
+ * `privateKey.algorithm.name` — ECDSA keys are augmented with
2097
+ * `hash: 'SHA-256'` at sign time (the hash is not stored in the key);
2098
+ * all other algorithm names are passed through as-is.
2099
+ * Intended for Ed25519 and ECDSA-P256 asymmetric private keys; for
2100
+ * HMAC-SHA256 authentication codes use {@link ICryptoProvider.hmacSha256} instead.
2101
+ * @param privateKey - A `CryptoKey` with `'sign'` usage (e.g. generated by
2102
+ * {@link CryptoUtils.ICryptoProvider.generateKeyPair | generateKeyPair} with
2103
+ * `'ecdsa-p256'` or `'ed25519'`).
2104
+ * @param data - The bytes to sign.
2105
+ * @returns `Success` with the raw signature bytes, or `Failure` with error context.
2106
+ */
2107
+ sign(privateKey: CryptoKey, data: Uint8Array): Promise<Result<Uint8Array>>;
2108
+ /**
2109
+ * Verifies a signature produced by {@link ICryptoProvider.sign}.
2110
+ * Delegates to `crypto.subtle.verify`; the algorithm is derived from
2111
+ * `publicKey.algorithm.name` — ECDSA keys are augmented with
2112
+ * `hash: 'SHA-256'`; all other algorithm names are passed through as-is.
2113
+ * Intended for Ed25519 and ECDSA-P256 asymmetric public keys; for
2114
+ * HMAC-SHA256 verification use {@link ICryptoProvider.verifyHmacSha256} instead.
2115
+ * @param publicKey - A `CryptoKey` with `'verify'` usage (e.g. the public
2116
+ * half of a keypair generated by
2117
+ * {@link CryptoUtils.ICryptoProvider.generateKeyPair | generateKeyPair} with
2118
+ * `'ecdsa-p256'` or `'ed25519'`).
2119
+ * @param signature - The raw signature bytes produced by `sign`.
2120
+ * @param data - The original data that was signed.
2121
+ * @returns `Success` with `true` if the signature is valid, `false` if it is
2122
+ * not, or `Failure` with error context if the operation itself failed.
2123
+ */
2124
+ verify(publicKey: CryptoKey, signature: Uint8Array, data: Uint8Array): Promise<Result<boolean>>;
2125
+ /**
2126
+ * Compares two byte arrays in constant time.
2127
+ *
2128
+ * The comparison visits all bytes of `a` and `b` regardless of where they
2129
+ * diverge, accumulating XOR differences with bitwise-OR. No early-return is
2130
+ * possible once the length check passes, making timing independent of the
2131
+ * byte values. This prevents timing side-channels when comparing MAC outputs,
2132
+ * signed-token bytes, or any secret-derived byte sequences.
2133
+ *
2134
+ * Returns `false` immediately (before the loop) when `a.length !== b.length`;
2135
+ * the length mismatch itself is not secret in normal use.
2136
+ * @param a - First byte array.
2137
+ * @param b - Second byte array.
2138
+ * @returns `true` if the arrays have the same length and identical contents,
2139
+ * `false` otherwise.
2140
+ */
2141
+ timingSafeEqual(a: Uint8Array, b: Uint8Array): boolean;
2142
+ /**
2143
+ * Computes an HMAC-SHA256 authentication code for `data` using `key`.
2144
+ *
2145
+ * The key must be a `CryptoKey` with `'sign'` usage and algorithm name
2146
+ * `'HMAC'` (e.g. derived via PBKDF2 or imported with
2147
+ * `crypto.subtle.importKey`). Use {@link ICryptoProvider.verifyHmacSha256}
2148
+ * for constant-time verification of the output.
2149
+ * @param key - An HMAC `CryptoKey` with `'sign'` usage.
2150
+ * @param data - The bytes to authenticate.
2151
+ * @returns `Success` with the 32-byte MAC, or `Failure` with error context.
2152
+ */
2153
+ hmacSha256(key: CryptoKey, data: Uint8Array): Promise<Result<Uint8Array>>;
2154
+ /**
2155
+ * Verifies an HMAC-SHA256 authentication code in constant time.
2156
+ *
2157
+ * Computes the expected MAC over `data` with `key`, then compares it to
2158
+ * `signature` using {@link ICryptoProvider.timingSafeEqual} so that
2159
+ * mismatches do not leak information through timing.
2160
+ * @param key - An HMAC `CryptoKey` with `'sign'` usage.
2161
+ * @param signature - The MAC bytes to verify (typically 32 bytes).
2162
+ * @param data - The original data that was authenticated.
2163
+ * @returns `Success` with `true` if the MAC is valid, `false` if it is not,
2164
+ * or `Failure` with error context if the MAC computation itself failed.
2165
+ */
2166
+ verifyHmacSha256(key: CryptoKey, signature: Uint8Array, data: Uint8Array): Promise<Result<boolean>>;
2167
+ }
2168
+
2169
+ /**
2170
+ * Provider-specific config for DALL-E models (dall-e-2, dall-e-3).
2171
+ * @remarks
2172
+ * style is only valid for dall-e-3; the runtime validator rejects it for dall-e-2.
2173
+ * @public
2174
+ */
2175
+ declare interface IDallEImageGenerationConfig {
2176
+ /** Image dimensions (dall-e-2: 256x256|512x512|1024x1024; dall-e-3: 1024x1024|1792x1024|1024x1792). */
2177
+ readonly size?: DallE2Size | DallE3Size;
2178
+ /** dall-e-3 only. Quality tier. */
2179
+ readonly quality?: DallE3Quality;
2180
+ /** dall-e-3 only. Visual style. */
2181
+ readonly style?: 'vivid' | 'natural';
2182
+ }
2183
+
2184
+ /**
2185
+ * Options block scoped to DALL-E family models.
2186
+ * @public
2187
+ */
2188
+ declare interface IDallEModelOptions extends INamedModelFamilyConfig {
2189
+ /** Discriminator: openai provider lineage. */
2190
+ readonly provider: 'openai';
2191
+ /** Family identifier. */
2192
+ readonly family: 'dall-e';
2193
+ /** Optional model names this block applies to. Omit = applies to all DALL-E models. */
2194
+ readonly models?: DallEModelNames[];
2195
+ /** Family-specific config. */
2196
+ readonly config: IDallEImageGenerationConfig;
1743
2197
  }
1744
2198
 
1745
2199
  /**
@@ -1902,6 +2356,58 @@ declare interface IFencedStringifiedJsonOptions<T> extends IFencedStringifiedJso
1902
2356
  readonly inner: Converter<T> | Validator<T>;
1903
2357
  }
1904
2358
 
2359
+ /**
2360
+ * Provider-specific config for Gemini Flash Image.
2361
+ * @public
2362
+ */
2363
+ declare interface IGeminiFlashImageGenerationConfig {
2364
+ /** Aspect ratio string. */
2365
+ readonly aspectRatio?: string;
2366
+ }
2367
+
2368
+ /**
2369
+ * Options block scoped to Gemini Flash Image models.
2370
+ * @public
2371
+ */
2372
+ declare interface IGeminiFlashImageModelOptions extends INamedModelFamilyConfig {
2373
+ readonly provider: 'google';
2374
+ readonly family: 'gemini-flash-image';
2375
+ readonly models?: GeminiFlashImageModelNames[];
2376
+ readonly config: IGeminiFlashImageGenerationConfig;
2377
+ }
2378
+
2379
+ /**
2380
+ * Google Gemini-specific thinking configuration.
2381
+ * @public
2382
+ */
2383
+ declare interface IGeminiThinkingConfig {
2384
+ /**
2385
+ * Token budget for thinking. Maps 1:1 to `thinkingBudget` on the wire.
2386
+ * - 0: disable thinking (Flash and Flash-Lite only; error on Pro)
2387
+ * - positive integer: soft token cap
2388
+ * - -1: dynamic
2389
+ * - omitted: model default
2390
+ */
2391
+ readonly thinkingBudget?: number;
2392
+ /**
2393
+ * Whether to include thought summaries in the response.
2394
+ * @remarks
2395
+ * INERT in phase B. Adapters never send `includeThoughts: true`.
2396
+ * Wired up by the followup stream `ai-assist-thinking-events`.
2397
+ */
2398
+ readonly includeThoughts?: boolean;
2399
+ }
2400
+
2401
+ /**
2402
+ * Google Gemini-specific thinking options block.
2403
+ * @public
2404
+ */
2405
+ declare interface IGeminiThinkingOptions {
2406
+ readonly provider: 'google';
2407
+ readonly models?: ReadonlyArray<GeminiThinkingModelNames>;
2408
+ readonly config: IGeminiThinkingConfig;
2409
+ }
2410
+
1905
2411
  /**
1906
2412
  * Parameters for {@link AiAssist.generateJsonCompletion}. Extends
1907
2413
  * {@link AiAssist.IProviderCompletionParams} with JSON-validation knobs.
@@ -1942,6 +2448,110 @@ declare interface IGenerateJsonCompletionResult<T> {
1942
2448
  readonly response: IAiCompletionResponse;
1943
2449
  }
1944
2450
 
2451
+ /**
2452
+ * Provider-specific config for gpt-image-1.
2453
+ * @public
2454
+ */
2455
+ declare interface IGptImageGenerationConfig {
2456
+ /** Image dimensions. */
2457
+ readonly size?: GptImageSize;
2458
+ /** Quality tier. */
2459
+ readonly quality?: GptImageQuality;
2460
+ /** Output format (replaces response_format for this model). */
2461
+ readonly outputFormat?: 'png' | 'jpeg' | 'webp';
2462
+ /** JPEG/WebP compression level 0–100. */
2463
+ readonly outputCompression?: number;
2464
+ /** Background transparency control. */
2465
+ readonly background?: 'transparent' | 'opaque' | 'auto';
2466
+ /** Content moderation strictness. */
2467
+ readonly moderation?: 'low' | 'auto';
2468
+ }
2469
+
2470
+ /**
2471
+ * Options block scoped to GPT Image family models.
2472
+ * @public
2473
+ */
2474
+ declare interface IGptImageModelOptions extends INamedModelFamilyConfig {
2475
+ readonly provider: 'openai';
2476
+ readonly family: 'gpt-image';
2477
+ readonly models?: GptImageModelNames[];
2478
+ readonly config: IGptImageGenerationConfig;
2479
+ }
2480
+
2481
+ /**
2482
+ * Provider-specific config for xAI Grok Imagine models.
2483
+ * @public
2484
+ */
2485
+ declare interface IGrokImagineImageGenerationConfig {
2486
+ /** Aspect ratio string (xAI uses aspect ratios, not pixel dimensions). */
2487
+ readonly aspectRatio?: string;
2488
+ /** Resolution hint. */
2489
+ readonly resolution?: string;
2490
+ }
2491
+
2492
+ /**
2493
+ * Options block scoped to xAI Grok Imagine family models.
2494
+ * @public
2495
+ */
2496
+ declare interface IGrokImagineModelOptions extends INamedModelFamilyConfig {
2497
+ readonly provider: 'xai';
2498
+ readonly family: 'grok-imagine';
2499
+ readonly models?: GrokImagineModelNames[];
2500
+ readonly config: IGrokImagineImageGenerationConfig;
2501
+ }
2502
+
2503
+ /**
2504
+ * Output of {@link HpkeProvider.sealBase}.
2505
+ *
2506
+ * The `ciphertext` field includes the 16-byte AES-256-GCM authentication tag
2507
+ * appended by Web Crypto's `encrypt()` operation: `length = plaintext.length + 16`.
2508
+ * @public
2509
+ */
2510
+ declare interface IHpkeSealResult {
2511
+ /**
2512
+ * Encapsulated key — 32-byte raw X25519 ephemeral public key (`enc` in RFC 9180).
2513
+ * Must be transmitted to the recipient alongside `ciphertext`.
2514
+ */
2515
+ readonly enc: Uint8Array;
2516
+ /**
2517
+ * AES-256-GCM ciphertext with the 16-byte authentication tag appended.
2518
+ * Length = `plaintext.length + 16`.
2519
+ */
2520
+ readonly ciphertext: Uint8Array;
2521
+ }
2522
+
2523
+ /**
2524
+ * Provider-specific config for Google Imagen 4 models.
2525
+ * @public
2526
+ */
2527
+ declare interface IImagen4GenerationConfig {
2528
+ /** Aspect ratio string. */
2529
+ readonly aspectRatio?: '1:1' | '3:4' | '4:3' | '9:16' | '16:9';
2530
+ /** Output resolution. */
2531
+ readonly imageSize?: '1K' | '2K';
2532
+ /** Whether to add SynthID watermark. Must be false to use seed. */
2533
+ readonly addWatermark?: boolean;
2534
+ /** LLM-based prompt rewriting. */
2535
+ readonly enhancePrompt?: boolean;
2536
+ /** Output MIME type. */
2537
+ readonly outputMimeType?: 'image/jpeg' | 'image/png';
2538
+ /** JPEG compression quality. */
2539
+ readonly outputCompressionQuality?: number;
2540
+ /** Person generation policy. */
2541
+ readonly personGeneration?: 'allow_all' | 'allow_adult' | 'dont_allow';
2542
+ }
2543
+
2544
+ /**
2545
+ * Options block scoped to Google Imagen 4 models.
2546
+ * @public
2547
+ */
2548
+ declare interface IImagen4ModelOptions extends INamedModelFamilyConfig {
2549
+ readonly provider: 'google';
2550
+ readonly family: 'imagen-4';
2551
+ readonly models?: Imagen4ModelNames[];
2552
+ readonly config: IImagen4GenerationConfig;
2553
+ }
2554
+
1945
2555
  /**
1946
2556
  * Options for importing raw key material via {@link KeyStore.importSecret}.
1947
2557
  * Extends {@link IImportSecretOptions} with a type classification.
@@ -1968,23 +2578,10 @@ declare interface IImportSecretOptions extends IAddSecretOptions {
1968
2578
 
1969
2579
  /**
1970
2580
  * Key derivation parameters stored in encrypted files.
1971
- * Allows decryption with password without needing to know the original salt/iterations.
2581
+ * Discriminated union on `kdf` field: `'pbkdf2'` or `'argon2id'`.
1972
2582
  * @public
1973
2583
  */
1974
- declare interface IKeyDerivationParams {
1975
- /**
1976
- * Key derivation function used.
1977
- */
1978
- readonly kdf: KeyDerivationFunction;
1979
- /**
1980
- * Base64-encoded salt used for key derivation.
1981
- */
1982
- readonly salt: string;
1983
- /**
1984
- * Number of iterations used for key derivation.
1985
- */
1986
- readonly iterations: number;
1987
- }
2584
+ declare type IKeyDerivationParams = IPbkdf2KeyDerivationParams | IArgon2idKeyDerivationParams;
1988
2585
 
1989
2586
  /**
1990
2587
  * WebCrypto parameters for a single {@link CryptoUtils.KeyPairAlgorithm}.
@@ -2165,9 +2762,9 @@ declare interface IKeyStoreFile {
2165
2762
  */
2166
2763
  readonly encryptedData: string;
2167
2764
  /**
2168
- * Key derivation parameters (required for key store - always password-derived).
2765
+ * Key derivation parameters for the vault master key (always PBKDF2).
2169
2766
  */
2170
- readonly keyDerivation: IKeyDerivationParams;
2767
+ readonly keyDerivation: IPbkdf2KeyDerivationParams;
2171
2768
  }
2172
2769
 
2173
2770
  /**
@@ -2297,6 +2894,9 @@ declare interface IKeyStoreVaultContents {
2297
2894
  readonly secrets: Record<string, IKeyStoreEntryJson>;
2298
2895
  }
2299
2896
 
2897
+ /** Model names in the Imagen 4 family. @public */
2898
+ declare type Imagen4ModelNames = 'imagen-4.0-generate-001' | 'imagen-4.0-ultra-generate-001' | 'imagen-4.0-fast-generate-001';
2899
+
2300
2900
  /**
2301
2901
  * Details about a missing variable in context validation.
2302
2902
  * @public
@@ -2317,6 +2917,13 @@ declare interface IMissingVariableDetail {
2317
2917
  readonly existingPath: readonly string[];
2318
2918
  }
2319
2919
 
2920
+ /**
2921
+ * Discriminated union of all model-family option blocks.
2922
+ * Discriminated on `provider` + `family` fields.
2923
+ * @public
2924
+ */
2925
+ declare type IModelFamilyConfig = IDallEModelOptions | IGptImageModelOptions | IGrokImagineModelOptions | IImagen4ModelOptions | IGeminiFlashImageModelOptions | IOtherModelOptions;
2926
+
2320
2927
  /**
2321
2928
  * A model specification: either a simple model string or a record mapping
2322
2929
  * context keys to nested model specs.
@@ -2329,10 +2936,10 @@ declare interface IMissingVariableDetail {
2329
2936
  * @example
2330
2937
  * ```typescript
2331
2938
  * // Simple — same model for all contexts:
2332
- * const simple: ModelSpec = 'grok-4-1-fast';
2939
+ * const simple: ModelSpec = 'grok-4.3';
2333
2940
  *
2334
- * // Context-aware — reasoning model when tools are active:
2335
- * const split: ModelSpec = { base: 'grok-4-1-fast', tools: 'grok-4-1-fast-reasoning' };
2941
+ * // Context-aware — different model for tools and thinking:
2942
+ * const split: ModelSpec = { base: 'grok-4.3', tools: 'grok-4.3', thinking: 'grok-4.3' };
2336
2943
  *
2337
2944
  * // Future nested — per-tool model selection:
2338
2945
  * const nested: ModelSpec = { base: 'grok-fast', tools: { base: 'grok-r', image: 'grok-v' } };
@@ -2377,6 +2984,15 @@ declare interface IMustacheTemplateOptions {
2377
2984
  readonly includePartials?: boolean;
2378
2985
  }
2379
2986
 
2987
+ /**
2988
+ * Base shape shared by all named family option blocks.
2989
+ * Provides a typed `models` field for applicability filtering without unsafe casts.
2990
+ * @internal
2991
+ */
2992
+ declare interface INamedModelFamilyConfig {
2993
+ readonly models?: readonly string[];
2994
+ }
2995
+
2380
2996
  /**
2381
2997
  * Named secret for encryption/decryption.
2382
2998
  * @public
@@ -2392,6 +3008,80 @@ declare interface INamedSecret {
2392
3008
  readonly key: Uint8Array;
2393
3009
  }
2394
3010
 
3011
+ /**
3012
+ * OpenAI-specific thinking configuration.
3013
+ * @remarks
3014
+ * Maps to `reasoning_effort` (Chat Completions path) or `reasoning.effort`
3015
+ * (Responses API path) on the wire. The adapter selects the correct field.
3016
+ * @public
3017
+ */
3018
+ declare interface IOpenAiThinkingConfig {
3019
+ /**
3020
+ * OpenAI reasoning effort. Maps 1:1 to the wire field.
3021
+ * - 'none': disables reasoning (gpt-5.x only; rejected by o-series)
3022
+ * - 'minimal': fastest (gpt-5.x)
3023
+ * - 'low' | 'medium' | 'high': standard tiers
3024
+ * - 'xhigh': highest (select gpt-5.x models only)
3025
+ *
3026
+ * @remarks
3027
+ * When effective effort is 'none', reasoning is disabled and temperature is
3028
+ * accepted by gpt-5.x models. This is the only case where temperature and
3029
+ * thinking config co-exist without a Result.fail.
3030
+ */
3031
+ readonly effort?: 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
3032
+ }
3033
+
3034
+ /**
3035
+ * OpenAI-specific thinking options block.
3036
+ * @public
3037
+ */
3038
+ declare interface IOpenAiThinkingOptions {
3039
+ readonly provider: 'openai';
3040
+ readonly models?: ReadonlyArray<OpenAiThinkingModelNames>;
3041
+ readonly config: IOpenAiThinkingConfig;
3042
+ }
3043
+
3044
+ /**
3045
+ * Escape-hatch options block for models not covered by a named family.
3046
+ * @remarks
3047
+ * `models` is required — there is no implicit "all" for unknown model families.
3048
+ * `config` is `JsonObject` — passed verbatim to the wire request with no validation.
3049
+ * This is the "trust me, I know what I'm doing" path for callers who need to send
3050
+ * wire params our typed configs don't yet expose.
3051
+ * @public
3052
+ */
3053
+ declare interface IOtherModelOptions {
3054
+ readonly provider: 'other';
3055
+ readonly models: string[];
3056
+ readonly config: JsonObject;
3057
+ }
3058
+
3059
+ /**
3060
+ * Escape-hatch options block for providers not covered by typed configs.
3061
+ * @remarks
3062
+ * `models` is required — no implicit "all" for unknown providers.
3063
+ * `config` fields are merged verbatim into the wire request.
3064
+ * @public
3065
+ */
3066
+ declare interface IOtherThinkingOptions {
3067
+ readonly provider: 'other';
3068
+ readonly models: ReadonlyArray<string>;
3069
+ readonly config: JsonObject;
3070
+ }
3071
+
3072
+ /**
3073
+ * PBKDF2 key derivation parameters.
3074
+ * @public
3075
+ */
3076
+ declare interface IPbkdf2KeyDerivationParams {
3077
+ /** Key derivation function discriminator. */
3078
+ readonly kdf: 'pbkdf2';
3079
+ /** Base64-encoded salt used for key derivation. */
3080
+ readonly salt: string;
3081
+ /** Number of iterations used for key derivation. */
3082
+ readonly iterations: number;
3083
+ }
3084
+
2395
3085
  /**
2396
3086
  * Pluggable backend that persists raw asymmetric private keys outside of the
2397
3087
  * encrypted keystore vault. Concrete implementations live in platform-specific
@@ -2452,10 +3142,7 @@ declare interface IProviderCompletionParams {
2452
3142
  readonly apiKey: string;
2453
3143
  /** The structured prompt to send */
2454
3144
  readonly prompt: AiPrompt;
2455
- /**
2456
- * Additional messages to append after system+user (e.g. for correction retries).
2457
- * These are appended in order after the initial system and user messages.
2458
- */
3145
+ /** Additional messages to append after system+user in order (e.g. for correction retries). */
2459
3146
  readonly additionalMessages?: ReadonlyArray<IChatMessage>;
2460
3147
  /** Sampling temperature (default: 0.7) */
2461
3148
  readonly temperature?: number;
@@ -2468,20 +3155,17 @@ declare interface IProviderCompletionParams {
2468
3155
  /** Optional abort signal for cancelling the in-flight request. */
2469
3156
  readonly signal?: AbortSignal;
2470
3157
  /**
2471
- * Optional override of the descriptor's default base URL. When set, the
2472
- * dispatcher uses this URL (scheme + host + optional port + optional path
2473
- * prefix) and appends the descriptor's per-route suffix (e.g.
2474
- * `/chat/completions`) the same way it composes against the default.
2475
- *
2476
- * Must be a well-formed `http`/`https` URL string. Used to dispatch the same
2477
- * provider descriptor against a self-hosted or local endpoint (e.g.
2478
- * `http://localhost:11434/v1` for Ollama, or LAN-hosted OpenAI-compatible
2479
- * servers).
2480
- *
2481
- * Setting `endpoint` does not change the auth shape: providers with
2482
- * `needsSecret === true` still require an API key.
3158
+ * Optional override of the descriptor's default base URL (scheme + host +
3159
+ * optional port + path prefix). The per-route suffix (e.g. `/chat/completions`)
3160
+ * is appended unchanged. Must be a well-formed `http`/`https` URL. Auth shape
3161
+ * is unchanged: `needsSecret` providers still require an API key.
2483
3162
  */
2484
3163
  readonly endpoint?: string;
3164
+ /**
3165
+ * Optional thinking/reasoning config. Anthropic, OpenAI, and xAI reject `temperature` when
3166
+ * the effective merged effort is non-`'none'`; Gemini always accepts both.
3167
+ */
3168
+ readonly thinking?: IThinkingConfig;
2485
3169
  }
2486
3170
 
2487
3171
  /**
@@ -2523,6 +3207,10 @@ declare interface IProviderCompletionStreamParams {
2523
3207
  * dispatcher; auth shape is unaffected.
2524
3208
  */
2525
3209
  readonly endpoint?: string;
3210
+ /**
3211
+ * Optional thinking/reasoning mode configuration.
3212
+ */
3213
+ readonly thinking?: IThinkingConfig;
2526
3214
  }
2527
3215
 
2528
3216
  /**
@@ -2542,13 +3230,7 @@ declare interface IProviderImageGenerationParams {
2542
3230
  readonly logger?: Logging.ILogger;
2543
3231
  /** Optional abort signal for cancelling the in-flight request. */
2544
3232
  readonly signal?: AbortSignal;
2545
- /**
2546
- * Optional override of the descriptor's default base URL. Same semantics as
2547
- * the non-streaming completion path's endpoint: a well-formed `http`/`https`
2548
- * URL substituted for `descriptor.baseUrl` when composing the request, with
2549
- * the per-route suffix (e.g. `/images/generations`, `:predict`) appended
2550
- * unchanged.
2551
- */
3233
+ /** Optional override of the descriptor's base URL; per-route suffix is appended unchanged. */
2552
3234
  readonly endpoint?: string;
2553
3235
  }
2554
3236
 
@@ -2569,11 +3251,7 @@ declare interface IProviderListModelsParams {
2569
3251
  readonly logger?: Logging.ILogger;
2570
3252
  /** Optional abort signal for cancelling the in-flight request. */
2571
3253
  readonly signal?: AbortSignal;
2572
- /**
2573
- * Optional override of the descriptor's default base URL — a well-formed
2574
- * `http`/`https` URL substituted for `descriptor.baseUrl`, with the
2575
- * per-format `/models` route appended unchanged.
2576
- */
3254
+ /** Optional override of the descriptor's base URL; per-format `/models` route is appended unchanged. */
2577
3255
  readonly endpoint?: string;
2578
3256
  }
2579
3257
 
@@ -2605,6 +3283,38 @@ declare interface IRequiredMustacheTemplateOptions {
2605
3283
  readonly includePartials: boolean;
2606
3284
  }
2607
3285
 
3286
+ /**
3287
+ * The resolved, merged wire parameters for an image generation request.
3288
+ * Built from the layered options and ready for provider-specific encoding.
3289
+ * @public
3290
+ */
3291
+ declare interface IResolvedImageOptions {
3292
+ /** Number of images to generate. */
3293
+ readonly n: number;
3294
+ /** Image size (OpenAI-style pixel strings). */
3295
+ readonly size?: string;
3296
+ /** Quality tier. */
3297
+ readonly quality?: string;
3298
+ /** Seed for reproducibility. */
3299
+ readonly seed?: number;
3300
+ readonly style?: string;
3301
+ readonly outputFormat?: string;
3302
+ readonly outputCompression?: number;
3303
+ readonly background?: string;
3304
+ readonly moderation?: string;
3305
+ readonly aspectRatio?: string;
3306
+ readonly resolution?: string;
3307
+ readonly imagenAspectRatio?: string;
3308
+ readonly imageSize?: string;
3309
+ readonly addWatermark?: boolean;
3310
+ readonly enhancePrompt?: boolean;
3311
+ readonly imagenOutputMimeType?: string;
3312
+ readonly imagenOutputCompressionQuality?: number;
3313
+ readonly personGeneration?: string;
3314
+ readonly geminiAspectRatio?: string;
3315
+ readonly otherParams?: JsonObject;
3316
+ }
3317
+
2608
3318
  /**
2609
3319
  * Checks if a JSON object appears to be an encrypted file.
2610
3320
  * Uses the format field as a discriminator.
@@ -2637,6 +3347,39 @@ declare const isoDate: Converter<Date, unknown>;
2637
3347
  */
2638
3348
  declare const isoDateTime: Converter<DateTime, unknown>;
2639
3349
 
3350
+ /**
3351
+ * Thinking/reasoning mode configuration for a completion request.
3352
+ *
3353
+ * @remarks
3354
+ * The generic `effort` field covers the common-subset cross-provider vocabulary.
3355
+ * For provider-specific precision (Anthropic 'max', OpenAI 'xhigh', Gemini token
3356
+ * budgets, xAI effort-level tuning), use the `providers` array.
3357
+ *
3358
+ * Absence (or undefined) means "no thinking mode" — existing callers are unaffected.
3359
+ *
3360
+ * @public
3361
+ */
3362
+ declare interface IThinkingConfig {
3363
+ /**
3364
+ * Cross-provider effort level. Common-subset mapping:
3365
+ * - 'low': Anthropic effort:low | OpenAI effort:low | Gemini thinkingBudget:1024 | xAI reasoning_effort:low
3366
+ * - 'medium': effort:medium | effort:medium | thinkingBudget:4096 | reasoning_effort:medium
3367
+ * - 'high': effort:high | effort:high | thinkingBudget:8192 | reasoning_effort:high
3368
+ */
3369
+ readonly effort?: 'low' | 'medium' | 'high';
3370
+ /**
3371
+ * Optional per-provider precision blocks. Blocks for providers that don't
3372
+ * match the resolved model's provider are silently skipped.
3373
+ */
3374
+ readonly providers?: ReadonlyArray<IThinkingProviderConfig>;
3375
+ }
3376
+
3377
+ /**
3378
+ * Discriminated union of per-provider thinking config blocks.
3379
+ * @public
3380
+ */
3381
+ declare type IThinkingProviderConfig = IAnthropicThinkingOptions | IOpenAiThinkingOptions | IGeminiThinkingOptions | IXAiThinkingOptions | IOtherThinkingOptions;
3382
+
2640
3383
  /**
2641
3384
  * Represents a variable reference extracted from a Mustache template.
2642
3385
  * @public
@@ -2714,6 +3457,29 @@ declare interface IWrappedBytes {
2714
3457
  readonly ciphertext: string;
2715
3458
  }
2716
3459
 
3460
+ /**
3461
+ * xAI-specific thinking configuration.
3462
+ * @public
3463
+ */
3464
+ declare interface IXAiThinkingConfig {
3465
+ /**
3466
+ * xAI reasoning effort. Maps 1:1 to `reasoning_effort` on the wire.
3467
+ * For grok-4, the adapter omits this field (grok-4 always reasons and
3468
+ * rejects the parameter).
3469
+ */
3470
+ readonly effort?: 'none' | 'low' | 'medium' | 'high';
3471
+ }
3472
+
3473
+ /**
3474
+ * xAI-specific thinking options block.
3475
+ * @public
3476
+ */
3477
+ declare interface IXAiThinkingOptions {
3478
+ readonly provider: 'xai';
3479
+ readonly models?: ReadonlyArray<XAiThinkingModelNames>;
3480
+ readonly config: IXAiThinkingConfig;
3481
+ }
3482
+
2717
3483
  /**
2718
3484
  * Options for YAML serialization, mirroring commonly-used `js-yaml` `DumpOptions`.
2719
3485
  * @public
@@ -2826,7 +3592,7 @@ declare const jsonWebKeyShape: Validator<JsonWebKey>;
2826
3592
  * Supported key derivation functions.
2827
3593
  * @public
2828
3594
  */
2829
- declare type KeyDerivationFunction = 'pbkdf2';
3595
+ declare type KeyDerivationFunction = 'pbkdf2' | 'argon2id';
2830
3596
 
2831
3597
  /**
2832
3598
  * Converter for {@link CryptoUtils.KeyDerivationFunction | key derivation function} type.
@@ -2836,6 +3602,7 @@ declare const keyDerivationFunction: Converter<KeyDerivationFunction>;
2836
3602
 
2837
3603
  /**
2838
3604
  * Converter for {@link CryptoUtils.IKeyDerivationParams | key derivation parameters}.
3605
+ * Handles both PBKDF2 and Argon2id discriminated union arms.
2839
3606
  * @public
2840
3607
  */
2841
3608
  declare const keyDerivationParams: Converter<IKeyDerivationParams>;
@@ -2914,6 +3681,7 @@ declare namespace KeyStore {
2914
3681
  IAddSecretFromPasswordOptions,
2915
3682
  DEFAULT_SECRET_ITERATIONS,
2916
3683
  IAddSecretFromPasswordResult,
3684
+ IAddSecretFromPasswordArgon2idOptions,
2917
3685
  IAddKeyPairOptions,
2918
3686
  IAddKeyPairResult,
2919
3687
  IRemoveSecretResult,
@@ -3150,6 +3918,36 @@ declare class KeyStore_2 implements IEncryptionProvider {
3150
3918
  * @public
3151
3919
  */
3152
3920
  verifySecretFromPassword(name: string, password: string, keyDerivation: IKeyDerivationParams): Promise<Result<boolean>>;
3921
+ /**
3922
+ * Adds a secret derived from a password using Argon2id (RFC 9106).
3923
+ *
3924
+ * The Argon2id provider must be supplied explicitly; the KeyStore does not
3925
+ * hold one by default (consumers opt in by depending on the argon2 package).
3926
+ *
3927
+ * Returns the key derivation parameters so callers can store them alongside
3928
+ * encrypted artifacts, enabling future re-derivation and verification.
3929
+ *
3930
+ * @param name - Unique name for the secret
3931
+ * @param password - Password or passphrase
3932
+ * @param argon2idProvider - Argon2id provider (Node or Browser implementation)
3933
+ * @param options - Optional: Argon2id params (defaults to ARGON2ID_OWASP_MIN), description, replace flag
3934
+ * @returns Success with entry and keyDerivation params, Failure if locked or invalid
3935
+ * @public
3936
+ */
3937
+ addSecretFromPasswordArgon2id(name: string, password: string, argon2idProvider: IArgon2idProvider, options?: IAddSecretFromPasswordArgon2idOptions): Promise<Result<IAddSecretFromPasswordResult>>;
3938
+ /**
3939
+ * Verifies a candidate password against an Argon2id-derived entry using the
3940
+ * supplied key derivation parameters. Constant-time comparison.
3941
+ *
3942
+ * @param name - Name of the secret to verify against
3943
+ * @param password - Candidate password to test
3944
+ * @param argon2idProvider - Argon2id provider (must produce bit-identical output for identical inputs)
3945
+ * @param keyDerivation - The Argon2id key derivation parameters returned by `addSecretFromPasswordArgon2id`
3946
+ * @returns Success(true) if candidate matches stored key, Success(false) if not,
3947
+ * Failure if locked, secret missing, wrong type, or derivation fails
3948
+ * @public
3949
+ */
3950
+ verifySecretFromPasswordArgon2id(name: string, password: string, argon2idProvider: IArgon2idProvider, keyDerivation: IArgon2idKeyDerivationParams): Promise<Result<boolean>>;
3153
3951
  /**
3154
3952
  * Removes a secret by name. Vault-first: the in-memory vault entry is dropped
3155
3953
  * before any storage cleanup runs. For asymmetric-keypair entries, best-effort
@@ -3467,7 +4265,7 @@ declare const modelSpec: Converter<ModelSpec>;
3467
4265
  * Known context keys for model specification maps.
3468
4266
  * @public
3469
4267
  */
3470
- declare type ModelSpecKey = 'base' | 'tools' | 'image';
4268
+ declare type ModelSpecKey = 'base' | 'tools' | 'image' | 'thinking';
3471
4269
 
3472
4270
  /**
3473
4271
  * Converter for {@link ModelSpecKey}.
@@ -3702,6 +4500,45 @@ declare class NodeCryptoProvider implements ICryptoProvider {
3702
4500
  * @returns `Success` with the imported public `CryptoKey`, or `Failure` with error context.
3703
4501
  */
3704
4502
  importPublicKeySpki(spkiBytes: Uint8Array, algorithm: KeyPairAlgorithm): Promise<Result<CryptoKey>>;
4503
+ /**
4504
+ * Signs `data` with `privateKey` using the algorithm inferred from the key.
4505
+ * @param privateKey - A signing `CryptoKey` (`'ecdsa-p256'` or `'ed25519'`).
4506
+ * @param data - The bytes to sign.
4507
+ * @returns `Success` with the raw signature bytes, or `Failure` with error context.
4508
+ */
4509
+ sign(privateKey: CryptoKey, data: Uint8Array): Promise<Result<Uint8Array>>;
4510
+ /**
4511
+ * Verifies a signature produced by {@link NodeCryptoProvider.sign}.
4512
+ * @param publicKey - A verify `CryptoKey` (`'ecdsa-p256'` or `'ed25519'`).
4513
+ * @param signature - The raw signature bytes.
4514
+ * @param data - The original data that was signed.
4515
+ * @returns `Success` with `true` if valid, `false` if not, or `Failure` with error context.
4516
+ */
4517
+ verify(publicKey: CryptoKey, signature: Uint8Array, data: Uint8Array): Promise<Result<boolean>>;
4518
+ /**
4519
+ * Compares two byte arrays in constant time using Node's native
4520
+ * `crypto.timingSafeEqual`. Returns `false` for mismatched lengths
4521
+ * rather than throwing (Node's native throws on length mismatch).
4522
+ * @param a - First byte array.
4523
+ * @param b - Second byte array.
4524
+ * @returns `true` if lengths match and all bytes are equal, `false` otherwise.
4525
+ */
4526
+ timingSafeEqual(a: Uint8Array, b: Uint8Array): boolean;
4527
+ /**
4528
+ * Computes an HMAC-SHA256 MAC for `data` using `key`.
4529
+ * @param key - An HMAC `CryptoKey` with `'sign'` usage.
4530
+ * @param data - The bytes to authenticate.
4531
+ * @returns `Success` with the 32-byte MAC, or `Failure` with error context.
4532
+ */
4533
+ hmacSha256(key: CryptoKey, data: Uint8Array): Promise<Result<Uint8Array>>;
4534
+ /**
4535
+ * Verifies an HMAC-SHA256 MAC in constant time.
4536
+ * @param key - An HMAC `CryptoKey` with `'sign'` usage.
4537
+ * @param signature - The MAC bytes to verify.
4538
+ * @param data - The original data that was authenticated.
4539
+ * @returns `Success` with `true` if valid, `false` if not, or `Failure` with error context.
4540
+ */
4541
+ verifyHmacSha256(key: CryptoKey, signature: Uint8Array, data: Uint8Array): Promise<Result<boolean>>;
3705
4542
  /**
3706
4543
  * Wraps `plaintext` for the holder of `recipientPublicKey` using
3707
4544
  * ECIES (ECDH P-256 + HKDF-SHA256 + AES-GCM-256). See
@@ -3729,6 +4566,12 @@ declare class NodeCryptoProvider implements ICryptoProvider {
3729
4566
  */
3730
4567
  declare const nodeCryptoProvider: NodeCryptoProvider;
3731
4568
 
4569
+ /**
4570
+ * Model IDs for OpenAI thinking-capable models.
4571
+ * @public
4572
+ */
4573
+ declare type OpenAiThinkingModelNames = 'o3' | 'o4-mini' | 'o3-deep-research' | 'o4-mini-deep-research' | 'gpt-5' | 'gpt-5.1' | 'gpt-5.2' | 'gpt-5.5' | 'gpt-5-pro';
4574
+
3732
4575
  /**
3733
4576
  * Parses CSV data from a string.
3734
4577
  * @param body - The CSV string to parse.
@@ -3748,6 +4591,12 @@ declare function parseCsvString(body: string, options?: CsvOptions): Result<unkn
3748
4591
  */
3749
4592
  declare function parseRecordJarLines(lines: string[], options?: JarRecordParserOptions): Result<JarRecord[]>;
3750
4593
 
4594
+ /**
4595
+ * Converter for {@link CryptoUtils.IPbkdf2KeyDerivationParams | PBKDF2 key derivation parameters}.
4596
+ * @public
4597
+ */
4598
+ declare const pbkdf2KeyDerivationParams: Converter<IPbkdf2KeyDerivationParams>;
4599
+
3751
4600
  /**
3752
4601
  * Simple implementation of a possibly open-ended range of some comparable
3753
4602
  * type `<T>` with test and formatting.
@@ -3966,6 +4815,28 @@ declare function resolveEffectiveTools(descriptor: IAiProviderDescriptor, settin
3966
4815
  */
3967
4816
  declare function resolveImageCapability(descriptor: IAiProviderDescriptor, modelId: string): IAiImageModelCapability | undefined;
3968
4817
 
4818
+ /**
4819
+ * Resolves the merged image options for a given model and capability.
4820
+ *
4821
+ * @remarks
4822
+ * **Merge precedence (later wins):**
4823
+ * 1. Generic top-level options (size, count, quality, seed)
4824
+ * 2. Family-generic blocks (models field omitted, provider matches)
4825
+ * 3. Model-specific blocks (models array includes the resolved model name)
4826
+ * 4. Other blocks (provider: 'other', models array includes model name)
4827
+ *
4828
+ * Provider-mismatch blocks are silently skipped.
4829
+ *
4830
+ * Within each tier, declaration order — later declaration wins.
4831
+ *
4832
+ * @param modelId - The resolved model string
4833
+ * @param capability - The resolved IAiImageModelCapability for this model
4834
+ * @param options - Caller-supplied options
4835
+ * @returns The merged wire parameters
4836
+ * @public
4837
+ */
4838
+ declare function resolveImageOptions(modelId: string, capability: IAiImageModelCapability, options: IAiImageGenerationOptions | undefined): IResolvedImageOptions;
4839
+
3969
4840
  /**
3970
4841
  * Resolves a {@link ModelSpec} to a concrete model string given an optional context key.
3971
4842
  *
@@ -4055,6 +4926,27 @@ declare function tryDecryptFile<TPayload extends JsonValue = JsonValue, TMetadat
4055
4926
  */
4056
4927
  declare const uint8ArrayFromBase64: Converter<Uint8Array>;
4057
4928
 
4929
+ /**
4930
+ * Validates the resolved options against per-model registry constraints.
4931
+ *
4932
+ * @remarks
4933
+ * Fails fast on the first violation. Error format:
4934
+ * `model "${model}": ${field} "${value}" is not accepted; accepted values: ${JSON.stringify(accepted)}`
4935
+ *
4936
+ * @param modelId - The resolved model string
4937
+ * @param capability - The resolved capability entry from the registry
4938
+ * @param resolved - The merged options from resolveImageOptions
4939
+ * @returns The same resolved options on success, or a failure with a contextual message
4940
+ * @public
4941
+ */
4942
+ declare function validateResolvedOptions(modelId: string, capability: IAiImageModelCapability, resolved: IResolvedImageOptions): Result<IResolvedImageOptions>;
4943
+
4944
+ /**
4945
+ * Model IDs for xAI thinking-capable models.
4946
+ * @public
4947
+ */
4948
+ declare type XAiThinkingModelNames = 'grok-3-mini' | 'grok-4.3' | 'grok-4';
4949
+
4058
4950
  declare namespace Yaml {
4059
4951
  export {
4060
4952
  yamlConverter,