@fgv/ts-extras 5.1.0-2 → 5.1.0-21

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 (272) hide show
  1. package/dist/index.browser.js +2 -1
  2. package/dist/index.browser.js.map +1 -0
  3. package/dist/index.js.map +1 -0
  4. package/dist/packlets/ai-assist/apiClient.js +807 -67
  5. package/dist/packlets/ai-assist/apiClient.js.map +1 -0
  6. package/dist/packlets/ai-assist/chatRequestBuilders.js +180 -0
  7. package/dist/packlets/ai-assist/chatRequestBuilders.js.map +1 -0
  8. package/dist/packlets/ai-assist/converters.js +2 -1
  9. package/dist/packlets/ai-assist/converters.js.map +1 -0
  10. package/dist/packlets/ai-assist/endpoint.js +78 -0
  11. package/dist/packlets/ai-assist/endpoint.js.map +1 -0
  12. package/dist/packlets/ai-assist/index.js +4 -3
  13. package/dist/packlets/ai-assist/index.js.map +1 -0
  14. package/dist/packlets/ai-assist/model.js +20 -3
  15. package/dist/packlets/ai-assist/model.js.map +1 -0
  16. package/dist/packlets/ai-assist/registry.js +137 -10
  17. package/dist/packlets/ai-assist/registry.js.map +1 -0
  18. package/dist/packlets/ai-assist/sseParser.js +122 -0
  19. package/dist/packlets/ai-assist/sseParser.js.map +1 -0
  20. package/dist/packlets/ai-assist/streamingAdapters/anthropic.js +192 -0
  21. package/dist/packlets/ai-assist/streamingAdapters/anthropic.js.map +1 -0
  22. package/dist/packlets/ai-assist/streamingAdapters/common.js +77 -0
  23. package/dist/packlets/ai-assist/streamingAdapters/common.js.map +1 -0
  24. package/dist/packlets/ai-assist/streamingAdapters/gemini.js +160 -0
  25. package/dist/packlets/ai-assist/streamingAdapters/gemini.js.map +1 -0
  26. package/dist/packlets/ai-assist/streamingAdapters/openaiChat.js +150 -0
  27. package/dist/packlets/ai-assist/streamingAdapters/openaiChat.js.map +1 -0
  28. package/dist/packlets/ai-assist/streamingAdapters/openaiResponses.js +164 -0
  29. package/dist/packlets/ai-assist/streamingAdapters/openaiResponses.js.map +1 -0
  30. package/dist/packlets/ai-assist/streamingAdapters/proxy.js +157 -0
  31. package/dist/packlets/ai-assist/streamingAdapters/proxy.js.map +1 -0
  32. package/dist/packlets/ai-assist/streamingClient.js +94 -0
  33. package/dist/packlets/ai-assist/streamingClient.js.map +1 -0
  34. package/dist/packlets/ai-assist/toolFormats.js.map +1 -0
  35. package/dist/packlets/conversion/converters.js +34 -1
  36. package/dist/packlets/conversion/converters.js.map +1 -0
  37. package/dist/packlets/conversion/index.js.map +1 -0
  38. package/dist/packlets/crypto-utils/constants.js.map +1 -0
  39. package/dist/packlets/crypto-utils/converters.js.map +1 -0
  40. package/dist/packlets/crypto-utils/directEncryptionProvider.js.map +1 -0
  41. package/dist/packlets/crypto-utils/encryptedFile.js.map +1 -0
  42. package/dist/packlets/crypto-utils/index.browser.js +2 -0
  43. package/dist/packlets/crypto-utils/index.browser.js.map +1 -0
  44. package/dist/packlets/crypto-utils/index.js +2 -0
  45. package/dist/packlets/crypto-utils/index.js.map +1 -0
  46. package/dist/packlets/crypto-utils/keyPairAlgorithmParams.js +63 -0
  47. package/dist/packlets/crypto-utils/keyPairAlgorithmParams.js.map +1 -0
  48. package/dist/packlets/crypto-utils/keystore/converters.js +101 -9
  49. package/dist/packlets/crypto-utils/keystore/converters.js.map +1 -0
  50. package/dist/packlets/crypto-utils/keystore/index.js +1 -0
  51. package/dist/packlets/crypto-utils/keystore/index.js.map +1 -0
  52. package/dist/packlets/crypto-utils/keystore/keyStore.js +431 -118
  53. package/dist/packlets/crypto-utils/keystore/keyStore.js.map +1 -0
  54. package/dist/packlets/crypto-utils/keystore/model.js +22 -1
  55. package/dist/packlets/crypto-utils/keystore/model.js.map +1 -0
  56. package/dist/packlets/crypto-utils/keystore/privateKeyStorage.js +21 -0
  57. package/dist/packlets/crypto-utils/keystore/privateKeyStorage.js.map +1 -0
  58. package/dist/packlets/crypto-utils/model.js +10 -0
  59. package/dist/packlets/crypto-utils/model.js.map +1 -0
  60. package/dist/packlets/crypto-utils/nodeCryptoProvider.js +163 -1
  61. package/dist/packlets/crypto-utils/nodeCryptoProvider.js.map +1 -0
  62. package/dist/packlets/csv/csvFileHelpers.js.map +1 -0
  63. package/dist/packlets/csv/csvHelpers.js.map +1 -0
  64. package/dist/packlets/csv/index.browser.js.map +1 -0
  65. package/dist/packlets/csv/index.js.map +1 -0
  66. package/dist/packlets/experimental/extendedArray.js.map +1 -0
  67. package/dist/packlets/experimental/formatter.js.map +1 -0
  68. package/dist/packlets/experimental/index.js.map +1 -0
  69. package/dist/packlets/experimental/rangeOf.js.map +1 -0
  70. package/dist/packlets/hash/index.browser.js.map +1 -0
  71. package/dist/packlets/hash/index.js.map +1 -0
  72. package/dist/packlets/hash/index.node.js.map +1 -0
  73. package/dist/packlets/hash/md5Normalizer.browser.js.map +1 -0
  74. package/dist/packlets/hash/md5Normalizer.js.map +1 -0
  75. package/dist/packlets/mustache/index.js.map +1 -0
  76. package/dist/packlets/mustache/interfaces.js.map +1 -0
  77. package/dist/packlets/mustache/mustacheTemplate.js.map +1 -0
  78. package/dist/packlets/record-jar/index.browser.js.map +1 -0
  79. package/dist/packlets/record-jar/index.js.map +1 -0
  80. package/dist/packlets/record-jar/recordJarFileHelpers.js.map +1 -0
  81. package/dist/packlets/record-jar/recordJarHelpers.js.map +1 -0
  82. package/dist/packlets/yaml/converters.js.map +1 -0
  83. package/dist/packlets/yaml/index.js +1 -0
  84. package/dist/packlets/yaml/index.js.map +1 -0
  85. package/dist/packlets/yaml/serializers.js +48 -0
  86. package/dist/packlets/yaml/serializers.js.map +1 -0
  87. package/dist/packlets/zip-file-tree/index.js.map +1 -0
  88. package/dist/packlets/zip-file-tree/zipFileTreeAccessors.js +2 -2
  89. package/dist/packlets/zip-file-tree/zipFileTreeAccessors.js.map +1 -0
  90. package/dist/packlets/zip-file-tree/zipFileTreeWriter.js.map +1 -0
  91. package/dist/ts-extras.d.ts +1499 -41
  92. package/dist/tsdoc-metadata.json +1 -1
  93. package/lib/index.browser.d.ts +2 -1
  94. package/lib/index.browser.d.ts.map +1 -0
  95. package/lib/index.browser.js +3 -1
  96. package/lib/index.browser.js.map +1 -0
  97. package/lib/index.d.ts.map +1 -0
  98. package/lib/index.js.map +1 -0
  99. package/lib/packlets/ai-assist/apiClient.d.ts +140 -1
  100. package/lib/packlets/ai-assist/apiClient.d.ts.map +1 -0
  101. package/lib/packlets/ai-assist/apiClient.js +810 -66
  102. package/lib/packlets/ai-assist/apiClient.js.map +1 -0
  103. package/lib/packlets/ai-assist/chatRequestBuilders.d.ts +89 -0
  104. package/lib/packlets/ai-assist/chatRequestBuilders.d.ts.map +1 -0
  105. package/lib/packlets/ai-assist/chatRequestBuilders.js +189 -0
  106. package/lib/packlets/ai-assist/chatRequestBuilders.js.map +1 -0
  107. package/lib/packlets/ai-assist/converters.d.ts.map +1 -0
  108. package/lib/packlets/ai-assist/converters.js +2 -1
  109. package/lib/packlets/ai-assist/converters.js.map +1 -0
  110. package/lib/packlets/ai-assist/endpoint.d.ts +28 -0
  111. package/lib/packlets/ai-assist/endpoint.d.ts.map +1 -0
  112. package/lib/packlets/ai-assist/endpoint.js +82 -0
  113. package/lib/packlets/ai-assist/endpoint.js.map +1 -0
  114. package/lib/packlets/ai-assist/index.d.ts +4 -3
  115. package/lib/packlets/ai-assist/index.d.ts.map +1 -0
  116. package/lib/packlets/ai-assist/index.js +12 -1
  117. package/lib/packlets/ai-assist/index.js.map +1 -0
  118. package/lib/packlets/ai-assist/model.d.ts +341 -3
  119. package/lib/packlets/ai-assist/model.d.ts.map +1 -0
  120. package/lib/packlets/ai-assist/model.js +21 -3
  121. package/lib/packlets/ai-assist/model.js.map +1 -0
  122. package/lib/packlets/ai-assist/registry.d.ts +34 -1
  123. package/lib/packlets/ai-assist/registry.d.ts.map +1 -0
  124. package/lib/packlets/ai-assist/registry.js +140 -11
  125. package/lib/packlets/ai-assist/registry.js.map +1 -0
  126. package/lib/packlets/ai-assist/sseParser.d.ts +45 -0
  127. package/lib/packlets/ai-assist/sseParser.d.ts.map +1 -0
  128. package/lib/packlets/ai-assist/sseParser.js +127 -0
  129. package/lib/packlets/ai-assist/sseParser.js.map +1 -0
  130. package/lib/packlets/ai-assist/streamingAdapters/anthropic.d.ts +18 -0
  131. package/lib/packlets/ai-assist/streamingAdapters/anthropic.d.ts.map +1 -0
  132. package/lib/packlets/ai-assist/streamingAdapters/anthropic.js +195 -0
  133. package/lib/packlets/ai-assist/streamingAdapters/anthropic.js.map +1 -0
  134. package/lib/packlets/ai-assist/streamingAdapters/common.d.ts +79 -0
  135. package/lib/packlets/ai-assist/streamingAdapters/common.d.ts.map +1 -0
  136. package/lib/packlets/ai-assist/streamingAdapters/common.js +81 -0
  137. package/lib/packlets/ai-assist/streamingAdapters/common.js.map +1 -0
  138. package/lib/packlets/ai-assist/streamingAdapters/gemini.d.ts +19 -0
  139. package/lib/packlets/ai-assist/streamingAdapters/gemini.d.ts.map +1 -0
  140. package/lib/packlets/ai-assist/streamingAdapters/gemini.js +163 -0
  141. package/lib/packlets/ai-assist/streamingAdapters/gemini.js.map +1 -0
  142. package/lib/packlets/ai-assist/streamingAdapters/openaiChat.d.ts +18 -0
  143. package/lib/packlets/ai-assist/streamingAdapters/openaiChat.d.ts.map +1 -0
  144. package/lib/packlets/ai-assist/streamingAdapters/openaiChat.js +153 -0
  145. package/lib/packlets/ai-assist/streamingAdapters/openaiChat.js.map +1 -0
  146. package/lib/packlets/ai-assist/streamingAdapters/openaiResponses.d.ts +19 -0
  147. package/lib/packlets/ai-assist/streamingAdapters/openaiResponses.d.ts.map +1 -0
  148. package/lib/packlets/ai-assist/streamingAdapters/openaiResponses.js +167 -0
  149. package/lib/packlets/ai-assist/streamingAdapters/openaiResponses.js.map +1 -0
  150. package/lib/packlets/ai-assist/streamingAdapters/proxy.d.ts +34 -0
  151. package/lib/packlets/ai-assist/streamingAdapters/proxy.d.ts.map +1 -0
  152. package/lib/packlets/ai-assist/streamingAdapters/proxy.js +160 -0
  153. package/lib/packlets/ai-assist/streamingAdapters/proxy.js.map +1 -0
  154. package/lib/packlets/ai-assist/streamingClient.d.ts +33 -0
  155. package/lib/packlets/ai-assist/streamingClient.d.ts.map +1 -0
  156. package/lib/packlets/ai-assist/streamingClient.js +99 -0
  157. package/lib/packlets/ai-assist/streamingClient.js.map +1 -0
  158. package/lib/packlets/ai-assist/toolFormats.d.ts.map +1 -0
  159. package/lib/packlets/ai-assist/toolFormats.js.map +1 -0
  160. package/lib/packlets/conversion/converters.d.ts +8 -1
  161. package/lib/packlets/conversion/converters.d.ts.map +1 -0
  162. package/lib/packlets/conversion/converters.js +35 -2
  163. package/lib/packlets/conversion/converters.js.map +1 -0
  164. package/lib/packlets/conversion/index.d.ts.map +1 -0
  165. package/lib/packlets/conversion/index.js.map +1 -0
  166. package/lib/packlets/crypto-utils/constants.d.ts.map +1 -0
  167. package/lib/packlets/crypto-utils/constants.js.map +1 -0
  168. package/lib/packlets/crypto-utils/converters.d.ts.map +1 -0
  169. package/lib/packlets/crypto-utils/converters.js.map +1 -0
  170. package/lib/packlets/crypto-utils/directEncryptionProvider.d.ts.map +1 -0
  171. package/lib/packlets/crypto-utils/directEncryptionProvider.js.map +1 -0
  172. package/lib/packlets/crypto-utils/encryptedFile.d.ts.map +1 -0
  173. package/lib/packlets/crypto-utils/encryptedFile.js.map +1 -0
  174. package/lib/packlets/crypto-utils/index.browser.d.ts +1 -0
  175. package/lib/packlets/crypto-utils/index.browser.d.ts.map +1 -0
  176. package/lib/packlets/crypto-utils/index.browser.js +4 -1
  177. package/lib/packlets/crypto-utils/index.browser.js.map +1 -0
  178. package/lib/packlets/crypto-utils/index.d.ts +1 -0
  179. package/lib/packlets/crypto-utils/index.d.ts.map +1 -0
  180. package/lib/packlets/crypto-utils/index.js +4 -1
  181. package/lib/packlets/crypto-utils/index.js.map +1 -0
  182. package/lib/packlets/crypto-utils/keyPairAlgorithmParams.d.ts +50 -0
  183. package/lib/packlets/crypto-utils/keyPairAlgorithmParams.d.ts.map +1 -0
  184. package/lib/packlets/crypto-utils/keyPairAlgorithmParams.js +66 -0
  185. package/lib/packlets/crypto-utils/keyPairAlgorithmParams.js.map +1 -0
  186. package/lib/packlets/crypto-utils/keystore/converters.d.ts +68 -6
  187. package/lib/packlets/crypto-utils/keystore/converters.d.ts.map +1 -0
  188. package/lib/packlets/crypto-utils/keystore/converters.js +100 -8
  189. package/lib/packlets/crypto-utils/keystore/converters.js.map +1 -0
  190. package/lib/packlets/crypto-utils/keystore/index.d.ts +1 -0
  191. package/lib/packlets/crypto-utils/keystore/index.d.ts.map +1 -0
  192. package/lib/packlets/crypto-utils/keystore/index.js +1 -0
  193. package/lib/packlets/crypto-utils/keystore/index.js.map +1 -0
  194. package/lib/packlets/crypto-utils/keystore/keyStore.d.ts +125 -12
  195. package/lib/packlets/crypto-utils/keystore/keyStore.d.ts.map +1 -0
  196. package/lib/packlets/crypto-utils/keystore/keyStore.js +431 -118
  197. package/lib/packlets/crypto-utils/keystore/keyStore.js.map +1 -0
  198. package/lib/packlets/crypto-utils/keystore/model.d.ts +248 -17
  199. package/lib/packlets/crypto-utils/keystore/model.d.ts.map +1 -0
  200. package/lib/packlets/crypto-utils/keystore/model.js +24 -2
  201. package/lib/packlets/crypto-utils/keystore/model.js.map +1 -0
  202. package/lib/packlets/crypto-utils/keystore/privateKeyStorage.d.ts +50 -0
  203. package/lib/packlets/crypto-utils/keystore/privateKeyStorage.d.ts.map +1 -0
  204. package/lib/packlets/crypto-utils/keystore/privateKeyStorage.js +22 -0
  205. package/lib/packlets/crypto-utils/keystore/privateKeyStorage.js.map +1 -0
  206. package/lib/packlets/crypto-utils/model.d.ts +145 -0
  207. package/lib/packlets/crypto-utils/model.d.ts.map +1 -0
  208. package/lib/packlets/crypto-utils/model.js +11 -1
  209. package/lib/packlets/crypto-utils/model.js.map +1 -0
  210. package/lib/packlets/crypto-utils/nodeCryptoProvider.d.ts +51 -1
  211. package/lib/packlets/crypto-utils/nodeCryptoProvider.d.ts.map +1 -0
  212. package/lib/packlets/crypto-utils/nodeCryptoProvider.js +162 -0
  213. package/lib/packlets/crypto-utils/nodeCryptoProvider.js.map +1 -0
  214. package/lib/packlets/csv/csvFileHelpers.d.ts.map +1 -0
  215. package/lib/packlets/csv/csvFileHelpers.js.map +1 -0
  216. package/lib/packlets/csv/csvHelpers.d.ts.map +1 -0
  217. package/lib/packlets/csv/csvHelpers.js.map +1 -0
  218. package/lib/packlets/csv/index.browser.d.ts.map +1 -0
  219. package/lib/packlets/csv/index.browser.js.map +1 -0
  220. package/lib/packlets/csv/index.d.ts.map +1 -0
  221. package/lib/packlets/csv/index.js.map +1 -0
  222. package/lib/packlets/experimental/extendedArray.d.ts.map +1 -0
  223. package/lib/packlets/experimental/extendedArray.js.map +1 -0
  224. package/lib/packlets/experimental/formatter.d.ts.map +1 -0
  225. package/lib/packlets/experimental/formatter.js.map +1 -0
  226. package/lib/packlets/experimental/index.d.ts.map +1 -0
  227. package/lib/packlets/experimental/index.js.map +1 -0
  228. package/lib/packlets/experimental/rangeOf.d.ts.map +1 -0
  229. package/lib/packlets/experimental/rangeOf.js.map +1 -0
  230. package/lib/packlets/hash/index.browser.d.ts.map +1 -0
  231. package/lib/packlets/hash/index.browser.js.map +1 -0
  232. package/lib/packlets/hash/index.d.ts.map +1 -0
  233. package/lib/packlets/hash/index.js.map +1 -0
  234. package/lib/packlets/hash/index.node.d.ts.map +1 -0
  235. package/lib/packlets/hash/index.node.js.map +1 -0
  236. package/lib/packlets/hash/md5Normalizer.browser.d.ts.map +1 -0
  237. package/lib/packlets/hash/md5Normalizer.browser.js.map +1 -0
  238. package/lib/packlets/hash/md5Normalizer.d.ts.map +1 -0
  239. package/lib/packlets/hash/md5Normalizer.js.map +1 -0
  240. package/lib/packlets/mustache/index.d.ts.map +1 -0
  241. package/lib/packlets/mustache/index.js.map +1 -0
  242. package/lib/packlets/mustache/interfaces.d.ts.map +1 -0
  243. package/lib/packlets/mustache/interfaces.js.map +1 -0
  244. package/lib/packlets/mustache/mustacheTemplate.d.ts.map +1 -0
  245. package/lib/packlets/mustache/mustacheTemplate.js.map +1 -0
  246. package/lib/packlets/record-jar/index.browser.d.ts.map +1 -0
  247. package/lib/packlets/record-jar/index.browser.js.map +1 -0
  248. package/lib/packlets/record-jar/index.d.ts.map +1 -0
  249. package/lib/packlets/record-jar/index.js.map +1 -0
  250. package/lib/packlets/record-jar/recordJarFileHelpers.d.ts.map +1 -0
  251. package/lib/packlets/record-jar/recordJarFileHelpers.js.map +1 -0
  252. package/lib/packlets/record-jar/recordJarHelpers.d.ts.map +1 -0
  253. package/lib/packlets/record-jar/recordJarHelpers.js.map +1 -0
  254. package/lib/packlets/yaml/converters.d.ts.map +1 -0
  255. package/lib/packlets/yaml/converters.js.map +1 -0
  256. package/lib/packlets/yaml/index.d.ts +1 -0
  257. package/lib/packlets/yaml/index.d.ts.map +1 -0
  258. package/lib/packlets/yaml/index.js +1 -0
  259. package/lib/packlets/yaml/index.js.map +1 -0
  260. package/lib/packlets/yaml/serializers.d.ts +45 -0
  261. package/lib/packlets/yaml/serializers.d.ts.map +1 -0
  262. package/lib/packlets/yaml/serializers.js +84 -0
  263. package/lib/packlets/yaml/serializers.js.map +1 -0
  264. package/lib/packlets/zip-file-tree/index.d.ts.map +1 -0
  265. package/lib/packlets/zip-file-tree/index.js.map +1 -0
  266. package/lib/packlets/zip-file-tree/zipFileTreeAccessors.d.ts +2 -2
  267. package/lib/packlets/zip-file-tree/zipFileTreeAccessors.d.ts.map +1 -0
  268. package/lib/packlets/zip-file-tree/zipFileTreeAccessors.js +2 -2
  269. package/lib/packlets/zip-file-tree/zipFileTreeAccessors.js.map +1 -0
  270. package/lib/packlets/zip-file-tree/zipFileTreeWriter.d.ts.map +1 -0
  271. package/lib/packlets/zip-file-tree/zipFileTreeWriter.js.map +1 -0
  272. package/package.json +24 -23
@@ -1,5 +1,6 @@
1
1
  import { Conversion } from '@fgv/ts-utils';
2
2
  import { Converter } from '@fgv/ts-utils';
3
+ import { DateTime } from 'luxon';
3
4
  import { FileTree } from '@fgv/ts-json-base';
4
5
  import { Hash as Hash_2 } from '@fgv/ts-utils';
5
6
  import { JsonValue } from '@fgv/ts-json-base';
@@ -22,6 +23,7 @@ declare type AiApiFormat = 'openai' | 'anthropic' | 'gemini';
22
23
  declare namespace AiAssist {
23
24
  export {
24
25
  AiPrompt,
26
+ AiModelCapability,
25
27
  AiProviderId,
26
28
  AiServerToolType,
27
29
  AiServerToolConfig,
@@ -30,23 +32,52 @@ declare namespace AiAssist {
30
32
  IAiCompletionResponse,
31
33
  IChatMessage,
32
34
  AiApiFormat,
35
+ AiImageApiFormat,
36
+ IAiImageModelCapability,
33
37
  IAiProviderDescriptor,
34
38
  IAiAssistProviderConfig,
35
39
  IAiAssistSettings,
36
40
  DEFAULT_AI_ASSIST,
37
41
  IAiAssistKeyStore,
42
+ IAiImageAttachment,
43
+ IAiImageData,
44
+ IAiImageGenerationOptions,
45
+ IAiImageGenerationParams,
46
+ IAiGeneratedImage,
47
+ IAiImageGenerationResponse,
48
+ IAiModelCapabilityRule,
49
+ IAiModelCapabilityConfig,
50
+ IAiModelInfo,
51
+ IAiStreamEvent,
52
+ IAiStreamTextDelta,
53
+ IAiStreamToolEvent,
54
+ IAiStreamDone,
55
+ IAiStreamError,
38
56
  ModelSpec,
39
57
  ModelSpecKey,
40
58
  IModelSpecMap,
41
59
  allModelSpecKeys,
42
60
  MODEL_SPEC_BASE_KEY,
43
61
  resolveModel,
62
+ toDataUrl,
44
63
  allProviderIds,
45
64
  getProviderDescriptors,
46
65
  getProviderDescriptor,
66
+ resolveImageCapability,
67
+ supportsImageGeneration,
68
+ DEFAULT_MODEL_CAPABILITY_CONFIG,
47
69
  callProviderCompletion,
48
70
  callProxiedCompletion,
71
+ callProviderImageGeneration,
72
+ callProxiedImageGeneration,
73
+ callProviderListModels,
74
+ callProxiedListModels,
49
75
  IProviderCompletionParams,
76
+ IProviderImageGenerationParams,
77
+ IProviderListModelsParams,
78
+ callProviderCompletionStream,
79
+ callProxiedCompletionStream,
80
+ IProviderCompletionStreamParams,
50
81
  aiProviderId,
51
82
  aiServerToolType,
52
83
  aiWebSearchToolConfig,
@@ -73,6 +104,36 @@ declare const aiAssistProviderConfig: Converter<IAiAssistProviderConfig>;
73
104
  */
74
105
  declare const aiAssistSettings: Converter<IAiAssistSettings>;
75
106
 
107
+ /**
108
+ * API format categories for image-generation provider routing.
109
+ *
110
+ * @remarks
111
+ * - `'openai-images'` — OpenAI Images API. Routes to `/images/generations`
112
+ * (text-only) or `/images/edits` (when reference images are present).
113
+ * - `'xai-images'` — xAI Images API. Same wire shape as OpenAI but text-only;
114
+ * no reference-image support on grok-2-image.
115
+ * - `'gemini-imagen'` — Google Imagen `:predict` endpoint. Text-only.
116
+ * - `'gemini-image-out'` — Google Gemini chat-style `:generateContent`
117
+ * endpoint that returns image parts (Gemini 2.5 Flash Image / "Nano
118
+ * Banana"). Accepts reference images.
119
+ *
120
+ * @public
121
+ */
122
+ declare type AiImageApiFormat = 'openai-images' | 'gemini-imagen' | 'xai-images' | 'gemini-image-out';
123
+
124
+ /**
125
+ * Capability vocabulary used to describe what a model can do. Used as both
126
+ * a filter and as a tag in {@link AiAssist.IAiModelInfo.capabilities}.
127
+ *
128
+ * @remarks
129
+ * Adding a new capability is cheap; adding the *first* one after consumers
130
+ * already exist forces churn. The initial vocabulary is intentionally broad
131
+ * even though only `image-generation` is fully exercised today.
132
+ *
133
+ * @public
134
+ */
135
+ declare type AiModelCapability = 'chat' | 'tools' | 'vision' | 'image-generation';
136
+
76
137
  /**
77
138
  * A structured AI prompt with system/user split for direct API calls,
78
139
  * and a lazily-constructed combined version for copy/paste workflows.
@@ -83,8 +144,18 @@ declare class AiPrompt {
83
144
  readonly system: string;
84
145
  /** User request: the specific entity generation request. */
85
146
  readonly user: string;
86
- constructor(user: string, system: string);
87
- /** Combined single-string version (user + system joined) for copy/paste. */
147
+ /**
148
+ * Optional image attachments. When present, vision-capable providers will
149
+ * include them in the user message; non-vision providers will reject the
150
+ * call up front (see {@link AiAssist.IAiProviderDescriptor.acceptsImageInput}).
151
+ */
152
+ readonly attachments: ReadonlyArray<IAiImageAttachment>;
153
+ constructor(user: string, system: string, attachments?: ReadonlyArray<IAiImageAttachment>);
154
+ /**
155
+ * Combined single-string version (user + system joined) for copy/paste.
156
+ * When attachments are present, includes a sentinel noting they aren't
157
+ * part of the copied text.
158
+ */
88
159
  get combined(): string;
89
160
  }
90
161
 
@@ -92,7 +163,7 @@ declare class AiPrompt {
92
163
  * All known AI provider identifiers.
93
164
  * @public
94
165
  */
95
- declare type AiProviderId = 'copy-paste' | 'xai-grok' | 'openai' | 'anthropic' | 'google-gemini' | 'groq' | 'mistral';
166
+ declare type AiProviderId = 'copy-paste' | 'xai-grok' | 'openai' | 'openai-compat' | 'anthropic' | 'google-gemini' | 'groq' | 'mistral' | 'ollama';
96
167
 
97
168
  /**
98
169
  * Converter for {@link AiProviderId}.
@@ -136,12 +207,30 @@ declare const aiToolEnablement: Converter<IAiToolEnablement>;
136
207
  */
137
208
  declare const aiWebSearchToolConfig: Converter<IAiWebSearchToolConfig>;
138
209
 
210
+ /**
211
+ * All valid key pair algorithms.
212
+ * @public
213
+ */
214
+ declare const allKeyPairAlgorithms: ReadonlyArray<KeyPairAlgorithm>;
215
+
216
+ /**
217
+ * All valid asymmetric secret types.
218
+ * @public
219
+ */
220
+ declare const allKeyStoreAsymmetricSecretTypes: ReadonlyArray<KeyStoreAsymmetricSecretType>;
221
+
139
222
  /**
140
223
  * All valid key store secret types.
141
224
  * @public
142
225
  */
143
226
  declare const allKeyStoreSecretTypes: ReadonlyArray<KeyStoreSecretType>;
144
227
 
228
+ /**
229
+ * All valid symmetric secret types.
230
+ * @public
231
+ */
232
+ declare const allKeyStoreSymmetricSecretTypes: ReadonlyArray<KeyStoreSymmetricSecretType>;
233
+
145
234
  /**
146
235
  * All valid {@link ModelSpecKey} values.
147
236
  * @public
@@ -179,6 +268,60 @@ declare const base64String: Converter<string>;
179
268
  */
180
269
  declare function callProviderCompletion(params: IProviderCompletionParams): Promise<Result<IAiCompletionResponse>>;
181
270
 
271
+ /**
272
+ * Calls the appropriate streaming chat completion API for a given provider.
273
+ *
274
+ * @remarks
275
+ * Pre-flight rejection: when `descriptor.streamingCorsRestricted === true`
276
+ * and the call isn't being routed through a proxy, this returns
277
+ * `Result.fail` before fetch is invoked. Callers should route through
278
+ * {@link AiAssist.callProxiedCompletionStream} or surface the failure to the user.
279
+ *
280
+ * Connection-time failures (auth, network, non-2xx) surface as the outer
281
+ * `Result.fail`. Once iteration begins, errors mid-stream surface as a
282
+ * terminal error event ({@link AiAssist.IAiStreamError}) followed by the iterable
283
+ * ending. The final successful event is {@link AiAssist.IAiStreamDone}.
284
+ *
285
+ * @param params - Request parameters including descriptor, API key, prompt, and optional tools
286
+ * @returns A streaming iterable of unified events, or a Result.fail
287
+ * @public
288
+ */
289
+ declare function callProviderCompletionStream(params: IProviderCompletionStreamParams): Promise<Result<AsyncIterable<IAiStreamEvent>>>;
290
+
291
+ /**
292
+ * Calls the appropriate image-generation API for a given provider.
293
+ *
294
+ * Resolves a {@link IAiImageModelCapability} from
295
+ * {@link IAiProviderDescriptor.imageGeneration} for the requested model and
296
+ * routes by its `format`:
297
+ * - `'openai-images'` for OpenAI (DALL-E, gpt-image-1)
298
+ * - `'xai-images'` for xAI Grok image models
299
+ * - `'gemini-imagen'` for Google Imagen `:predict`
300
+ * - `'gemini-image-out'` for Gemini chat-style image output (Nano Banana)
301
+ *
302
+ * Image-model selection reuses the existing `'image'` {@link ModelSpecKey}.
303
+ * When `request.referenceImages` is non-empty, the call is rejected up front
304
+ * unless the resolved capability declares `acceptsImageReferenceInput`.
305
+ *
306
+ * @param params - Request parameters including descriptor, API key, and prompt
307
+ * @returns The generated images, or a failure
308
+ * @public
309
+ */
310
+ declare function callProviderImageGeneration(params: IProviderImageGenerationParams): Promise<Result<IAiImageGenerationResponse>>;
311
+
312
+ /**
313
+ * Lists models available from a provider, with capabilities resolved from
314
+ * native provider info (where supplied) and a configurable rule set.
315
+ *
316
+ * Routes based on `descriptor.apiFormat` — listing reuses the existing
317
+ * format dispatch and does not require a separate descriptor field.
318
+ *
319
+ * @param params - Request parameters including descriptor, API key, and optional capability filter
320
+ * @returns The resolved model list, or a failure
321
+ * @public
322
+ */
323
+ declare function callProviderListModels(params: IProviderListModelsParams): Promise<Result<ReadonlyArray<IAiModelInfo>>>;
324
+
182
325
  /**
183
326
  * Calls the AI completion endpoint on a proxy server instead of calling
184
327
  * the provider API directly from the browser.
@@ -194,6 +337,71 @@ declare function callProviderCompletion(params: IProviderCompletionParams): Prom
194
337
  */
195
338
  declare function callProxiedCompletion(proxyUrl: string, params: IProviderCompletionParams): Promise<Result<IAiCompletionResponse>>;
196
339
 
340
+ /**
341
+ * Calls the streaming chat endpoint on a proxy server instead of calling
342
+ * the provider directly from the browser.
343
+ *
344
+ * @remarks
345
+ * Proxy contract:
346
+ * - Endpoint: `POST ${proxyUrl}/api/ai/completion-stream`
347
+ * - Request body: same JSON as `/api/ai/completion` plus `"stream": true`
348
+ * - Response: `Content-Type: text/event-stream`; body is the unified
349
+ * {@link AiAssist.IAiStreamEvent} JSON-serialized one event per SSE `data:` line
350
+ * (no `event:` line needed since the type discriminator is in the JSON).
351
+ * - Error response (when the proxy can't even start): JSON `{error: string}`
352
+ * with a non-2xx status, surfaced as `proxy: ${error}`.
353
+ *
354
+ * The proxy server is responsible for opening the upstream SSE connection,
355
+ * translating provider-native events to the unified vocabulary, and
356
+ * forwarding events as they arrive (no buffering). The library does not
357
+ * ship a proxy implementation.
358
+ *
359
+ * @public
360
+ */
361
+ declare function callProxiedCompletionStream(proxyUrl: string, params: IProviderCompletionStreamParams): Promise<Result<AsyncIterable<IAiStreamEvent>>>;
362
+
363
+ /**
364
+ * Calls the image-generation endpoint on a proxy server instead of calling
365
+ * the provider API directly from the browser.
366
+ *
367
+ * @remarks
368
+ * The proxy contract:
369
+ * - Endpoint: `POST ${proxyUrl}/api/ai/image-generation`
370
+ * - Request body: `{providerId, apiKey, params, modelOverride?}`
371
+ * - Success response body: an {@link IAiImageGenerationResponse}
372
+ * - Error response body: `{error: string}` (surfaced as `proxy: ${error}`)
373
+ *
374
+ * The proxy server is responsible for descriptor lookup, model resolution,
375
+ * provider dispatch, and response normalization. When `params.referenceImages`
376
+ * is present, the proxy is also responsible for repackaging it into the
377
+ * upstream wire format (e.g. multipart/form-data for OpenAI `/images/edits`,
378
+ * `inlineData` parts for Gemini `:generateContent`).
379
+ *
380
+ * @param proxyUrl - Base URL of the proxy server (e.g. `http://localhost:3001`)
381
+ * @param params - Same parameters as {@link callProviderImageGeneration}
382
+ * @returns The generated images, or a failure
383
+ * @public
384
+ */
385
+ declare function callProxiedImageGeneration(proxyUrl: string, params: IProviderImageGenerationParams): Promise<Result<IAiImageGenerationResponse>>;
386
+
387
+ /**
388
+ * Calls the model-listing endpoint on a proxy server.
389
+ *
390
+ * @remarks
391
+ * Proxy contract:
392
+ * - Endpoint: `POST ${proxyUrl}/api/ai/list-models`
393
+ * - Request body: `{providerId, apiKey, capability?}`. Capability config is
394
+ * not forwarded — the proxy applies its own (typically the same default
395
+ * the library ships).
396
+ * - Success response body: an `IAiModelInfo[]` (under key `models`) where
397
+ * `capabilities` is serialized as a string array (not Set, which doesn't
398
+ * round-trip through JSON).
399
+ * - Error response body: `{error: string}`, surfaced as `proxy: ${error}`.
400
+ *
401
+ * @public
402
+ */
403
+ declare function callProxiedListModels(proxyUrl: string, params: IProviderListModelsParams): Promise<Result<ReadonlyArray<IAiModelInfo>>>;
404
+
197
405
  declare namespace Constants {
198
406
  export {
199
407
  ENCRYPTED_FILE_FORMAT,
@@ -210,7 +418,8 @@ declare namespace Converters {
210
418
  extendedArrayOf,
211
419
  rangeTypeOf,
212
420
  rangeOf,
213
- isoDate
421
+ isoDate,
422
+ isoDateTime
214
423
  }
215
424
  }
216
425
  export { Converters }
@@ -219,6 +428,12 @@ declare namespace Converters_2 {
219
428
  export {
220
429
  keystoreFormat,
221
430
  keystoreSecretType,
431
+ keystoreSymmetricSecretType,
432
+ keystoreAsymmetricSecretType,
433
+ keyPairAlgorithm,
434
+ jsonWebKeyShape,
435
+ keystoreSymmetricEntryJson,
436
+ keystoreAsymmetricEntryJson,
222
437
  keystoreSecretEntryJson,
223
438
  keystoreVaultContents,
224
439
  keystoreFile
@@ -271,6 +486,8 @@ declare namespace CryptoUtils {
271
486
  Converters_3 as Converters,
272
487
  DirectEncryptionProvider,
273
488
  IDirectEncryptionProviderParams,
489
+ IKeyPairAlgorithmParams,
490
+ keyPairAlgorithmParams,
274
491
  NodeCryptoProvider,
275
492
  nodeCryptoProvider,
276
493
  createEncryptedFile,
@@ -284,6 +501,10 @@ declare namespace CryptoUtils {
284
501
  EncryptedFileFormat,
285
502
  INamedSecret,
286
503
  IEncryptionResult,
504
+ KeyPairAlgorithm,
505
+ IWrapBytesOptions,
506
+ IWrappedBytes,
507
+ allKeyPairAlgorithms,
287
508
  KeyDerivationFunction,
288
509
  IKeyDerivationParams,
289
510
  IEncryptedFile,
@@ -345,6 +566,16 @@ declare const DEFAULT_ALGORITHM: "AES-256-GCM";
345
566
  */
346
567
  declare const DEFAULT_KEYSTORE_ITERATIONS: number;
347
568
 
569
+ /**
570
+ * Default capability config used by `callProviderListModels` when callers
571
+ * don't supply their own. Patterns are intentionally narrow — false
572
+ * positives are worse than missing a model. Caller can override per call
573
+ * via {@link IProviderListModelsParams.capabilityConfig}.
574
+ *
575
+ * @public
576
+ */
577
+ declare const DEFAULT_MODEL_CAPABILITY_CONFIG: IAiModelCapabilityConfig;
578
+
348
579
  /**
349
580
  * Default {@link Experimental.RangeOfFormats | formats} to use for both
350
581
  * open-ended and complete {@link Experimental.RangeOf | RangeOf<T>}.
@@ -532,7 +763,7 @@ declare class ExtendedArray<T> extends Array<T> {
532
763
  * If `onError` is `'failOnError'` (default), then the entire conversion fails if any element cannot
533
764
  * be converted. If `onError` is `'ignoreErrors'`, then failing elements are silently ignored.
534
765
  * @param converter - `Converter` used to convert each item in the array
535
- * @param ignoreErrors - Specifies treatment of unconvertible elements
766
+ * @param onError - Specifies treatment of unconvertible elements
536
767
  * @beta
537
768
  */
538
769
  declare function extendedArrayOf<T, TC = undefined>(label: string, converter: Converter<T, TC>, onError?: Conversion.OnError): Converter<ExtendedArray<T>, TC>;
@@ -650,6 +881,50 @@ declare namespace Hash {
650
881
  }
651
882
  export { Hash }
652
883
 
884
+ /**
885
+ * Options for adding an asymmetric keypair to the key store.
886
+ * @public
887
+ */
888
+ declare interface IAddKeyPairOptions {
889
+ /**
890
+ * Algorithm to use for the new keypair.
891
+ */
892
+ readonly algorithm: KeyPairAlgorithm;
893
+ /**
894
+ * Optional description for the entry.
895
+ */
896
+ readonly description?: string;
897
+ /**
898
+ * Whether to replace an existing entry with the same name.
899
+ * Replacement mints a fresh storage `id` and best-effort deletes the
900
+ * displaced storage blob; see the keystore design doc for details.
901
+ */
902
+ readonly replace?: boolean;
903
+ }
904
+
905
+ /**
906
+ * Result of adding an asymmetric keypair to the key store.
907
+ * @public
908
+ */
909
+ declare interface IAddKeyPairResult {
910
+ /**
911
+ * The asymmetric entry that was added.
912
+ */
913
+ readonly entry: IKeyStoreAsymmetricEntry;
914
+ /**
915
+ * Whether this replaced an existing entry.
916
+ */
917
+ readonly replaced: boolean;
918
+ /**
919
+ * Best-effort warning from displaced-resource cleanup. Set when this call
920
+ * replaced a prior entry but the corresponding
921
+ * {@link CryptoUtils.KeyStore.IPrivateKeyStorage}.delete failed; the new
922
+ * keypair is still committed and the orphaned blob is left for consumer-side
923
+ * GC to reconcile.
924
+ */
925
+ readonly warning?: string;
926
+ }
927
+
653
928
  /**
654
929
  * Options for adding a secret derived from a password.
655
930
  * @public
@@ -700,11 +975,19 @@ declare interface IAddSecretResult {
700
975
  /**
701
976
  * The secret entry that was added.
702
977
  */
703
- readonly entry: IKeyStoreSecretEntry;
978
+ readonly entry: IKeyStoreSymmetricEntry;
704
979
  /**
705
980
  * Whether this replaced an existing secret.
706
981
  */
707
982
  readonly replaced: boolean;
983
+ /**
984
+ * Best-effort warning from displaced-resource cleanup. Set when this call
985
+ * replaced an asymmetric-keypair entry but the corresponding
986
+ * {@link CryptoUtils.KeyStore.IPrivateKeyStorage}.delete failed; the new
987
+ * entry is still committed and the orphaned blob is left for consumer-side
988
+ * GC to reconcile.
989
+ */
990
+ readonly warning?: string;
708
991
  }
709
992
 
710
993
  /**
@@ -734,6 +1017,14 @@ declare interface IAiAssistProviderConfig {
734
1017
  readonly model?: ModelSpec;
735
1018
  /** Tool enablement/configuration. Tools are disabled unless explicitly enabled. */
736
1019
  readonly tools?: ReadonlyArray<IAiToolEnablement>;
1020
+ /**
1021
+ * Optional caller-supplied endpoint URL (http/https). Overrides
1022
+ * `descriptor.baseUrl` for this provider. Used to point a provider at a
1023
+ * self-hosted server (Ollama, LM Studio, llama.cpp's openai-server) or a
1024
+ * local proxy. Validation lives in `@fgv/ts-extras` — query strings,
1025
+ * fragments, and userinfo are rejected.
1026
+ */
1027
+ readonly endpoint?: string;
737
1028
  }
738
1029
 
739
1030
  /**
@@ -762,6 +1053,201 @@ declare interface IAiCompletionResponse {
762
1053
  readonly truncated: boolean;
763
1054
  }
764
1055
 
1056
+ /**
1057
+ * A single generated image.
1058
+ * @public
1059
+ */
1060
+ declare interface IAiGeneratedImage extends IAiImageData {
1061
+ /**
1062
+ * The prompt as rewritten by the provider, if any. OpenAI's image models
1063
+ * commonly rewrite prompts; other providers do not.
1064
+ */
1065
+ readonly revisedPrompt?: string;
1066
+ }
1067
+
1068
+ /**
1069
+ * Image attachment for a vision (image-input) prompt.
1070
+ *
1071
+ * @remarks
1072
+ * Extends {@link IAiImageData} with an OpenAI-specific `detail` hint that is
1073
+ * silently ignored by Anthropic, Gemini, and other providers.
1074
+ *
1075
+ * @public
1076
+ */
1077
+ declare interface IAiImageAttachment extends IAiImageData {
1078
+ /**
1079
+ * OpenAI vision detail hint:
1080
+ * - `'low'`: faster, cheaper, lower fidelity
1081
+ * - `'high'`: slower, more expensive, higher fidelity
1082
+ * - `'auto'` (default): provider chooses
1083
+ *
1084
+ * Ignored by providers other than OpenAI.
1085
+ */
1086
+ readonly detail?: 'low' | 'high' | 'auto';
1087
+ }
1088
+
1089
+ /**
1090
+ * Universal image representation used for both image input (vision prompts)
1091
+ * and image output (generation responses).
1092
+ *
1093
+ * @remarks
1094
+ * The base64 string is raw — no `data:` URL prefix. Use {@link AiAssist.toDataUrl} to
1095
+ * format it for browser-display contexts.
1096
+ *
1097
+ * @public
1098
+ */
1099
+ declare interface IAiImageData {
1100
+ /** MIME type, e.g. `'image/png'`, `'image/jpeg'`, `'image/webp'`. */
1101
+ readonly mimeType: string;
1102
+ /** Base64-encoded image bytes (no `data:` prefix). */
1103
+ readonly base64: string;
1104
+ }
1105
+
1106
+ /**
1107
+ * Options for image generation requests.
1108
+ *
1109
+ * @remarks
1110
+ * Provider compatibility is documented per field. The library does not
1111
+ * pre-validate against per-model constraints (e.g. `dall-e-3` rejects
1112
+ * `count > 1`); provider 400 errors surface through the failure path.
1113
+ *
1114
+ * @public
1115
+ */
1116
+ declare interface IAiImageGenerationOptions {
1117
+ /**
1118
+ * Image dimensions. Used by openai-format providers (mapped to the
1119
+ * provider's `size` field). Ignored by Imagen — use
1120
+ * {@link IAiImageGenerationOptions.imagen} `aspectRatio` instead.
1121
+ *
1122
+ * Note: each model has its own accepted set; `dall-e-3` only accepts the
1123
+ * values listed here.
1124
+ */
1125
+ readonly size?: '1024x1024' | '1024x1792' | '1792x1024' | 'auto';
1126
+ /**
1127
+ * Number of images to generate. Default 1.
1128
+ *
1129
+ * Note: `dall-e-3` rejects `count > 1`.
1130
+ */
1131
+ readonly count?: number;
1132
+ /** Generation quality hint where supported. */
1133
+ readonly quality?: 'standard' | 'high';
1134
+ /** Random seed for reproducibility, where supported. */
1135
+ readonly seed?: number;
1136
+ /**
1137
+ * Imagen-specific options. Ignored by other providers.
1138
+ */
1139
+ readonly imagen?: {
1140
+ readonly negativePrompt?: string;
1141
+ readonly aspectRatio?: '1:1' | '3:4' | '4:3' | '9:16' | '16:9';
1142
+ };
1143
+ }
1144
+
1145
+ /**
1146
+ * Parameters for an image-generation request.
1147
+ * @public
1148
+ */
1149
+ declare interface IAiImageGenerationParams {
1150
+ /** The text prompt describing the desired image. */
1151
+ readonly prompt: string;
1152
+ /** Optional generation options. */
1153
+ readonly options?: IAiImageGenerationOptions;
1154
+ /**
1155
+ * Optional reference images. When present, the provider will use them as
1156
+ * visual context (e.g. to preserve a character's appearance across multiple
1157
+ * generations). The dispatcher resolves the
1158
+ * {@link AiAssist.IAiImageModelCapability} for the requested model and
1159
+ * rejects the call up front if `acceptsImageReferenceInput` is not set on
1160
+ * the matching capability. An empty array is treated identically to
1161
+ * `undefined`.
1162
+ */
1163
+ readonly referenceImages?: ReadonlyArray<IAiImageAttachment>;
1164
+ }
1165
+
1166
+ /**
1167
+ * Result of an image-generation call.
1168
+ * @public
1169
+ */
1170
+ declare interface IAiImageGenerationResponse {
1171
+ /** The generated images, in provider-returned order. */
1172
+ readonly images: ReadonlyArray<IAiGeneratedImage>;
1173
+ }
1174
+
1175
+ /**
1176
+ * Image-generation capability for a model family within a provider. Used as
1177
+ * an entry in {@link IAiProviderDescriptor.imageGeneration}.
1178
+ *
1179
+ * @public
1180
+ */
1181
+ declare interface IAiImageModelCapability {
1182
+ /**
1183
+ * Prefix matched against the resolved image model id. The empty string is
1184
+ * the catch-all and matches every model. When multiple rules' prefixes
1185
+ * match a model id, the longest prefix wins; ties are broken by
1186
+ * first-encountered.
1187
+ */
1188
+ readonly modelPrefix: string;
1189
+ /** API format used to dispatch requests for matching models. */
1190
+ readonly format: AiImageApiFormat;
1191
+ /**
1192
+ * Whether matching models accept reference images via
1193
+ * {@link AiAssist.IAiImageGenerationParams.referenceImages}. When false or
1194
+ * undefined, calls that include reference images are rejected up front.
1195
+ *
1196
+ * @remarks
1197
+ * Per-model constraints beyond ref support (e.g. dall-e-3 ignores edits)
1198
+ * are not validated here and surface as provider 400s, consistent with the
1199
+ * existing image-generation policy.
1200
+ */
1201
+ readonly acceptsImageReferenceInput?: boolean;
1202
+ }
1203
+
1204
+ /**
1205
+ * Configuration that maps model id patterns to capabilities. Used to
1206
+ * augment (or, where the provider supplies no capability info, fully
1207
+ * derive) the capability set for each listed model.
1208
+ * @public
1209
+ */
1210
+ declare interface IAiModelCapabilityConfig {
1211
+ /** Per-provider rules. Tried before {@link AiAssist.IAiModelCapabilityConfig.global}. */
1212
+ readonly perProvider?: {
1213
+ readonly [P in AiProviderId]?: ReadonlyArray<IAiModelCapabilityRule>;
1214
+ };
1215
+ /** Cross-provider fallback rules. */
1216
+ readonly global?: ReadonlyArray<IAiModelCapabilityRule>;
1217
+ }
1218
+
1219
+ /**
1220
+ * One rule in an {@link IAiModelCapabilityConfig}. Multiple rules can match
1221
+ * a single model — their capability arrays are unioned.
1222
+ * @public
1223
+ */
1224
+ declare interface IAiModelCapabilityRule {
1225
+ /** RegExp tested against the model id (using `.test`). */
1226
+ readonly idPattern: RegExp;
1227
+ /** Capabilities this rule attributes to matching models. */
1228
+ readonly capabilities: ReadonlyArray<AiModelCapability>;
1229
+ /**
1230
+ * Friendly display-name override for matching models. The function form
1231
+ * lets one rule format many ids (e.g. `(id) => id.toUpperCase()`).
1232
+ * If multiple matching rules supply `displayName`, the first match wins.
1233
+ */
1234
+ readonly displayName?: string | ((id: string) => string);
1235
+ }
1236
+
1237
+ /**
1238
+ * Information about a single model returned by a provider's list endpoint,
1239
+ * with capabilities already resolved (native + config rules).
1240
+ * @public
1241
+ */
1242
+ declare interface IAiModelInfo {
1243
+ /** Provider-native model identifier. */
1244
+ readonly id: string;
1245
+ /** Resolved capability set — union of native declarations and config rules. */
1246
+ readonly capabilities: ReadonlySet<AiModelCapability>;
1247
+ /** Friendly name for display, when known. */
1248
+ readonly displayName?: string;
1249
+ }
1250
+
765
1251
  /**
766
1252
  * Describes a single AI provider — single source of truth for all metadata.
767
1253
  * @public
@@ -785,6 +1271,111 @@ declare interface IAiProviderDescriptor {
785
1271
  readonly supportedTools: ReadonlyArray<AiServerToolType>;
786
1272
  /** Whether this provider's API enforces CORS restrictions that prevent direct browser calls. */
787
1273
  readonly corsRestricted: boolean;
1274
+ /**
1275
+ * Whether this provider's streaming completion endpoint requires a proxy
1276
+ * for direct browser calls. Some providers gate streaming separately from
1277
+ * non-streaming (rare), so this is tracked independently from
1278
+ * {@link IAiProviderDescriptor.corsRestricted}.
1279
+ *
1280
+ * @remarks
1281
+ * When `true`, `callProviderCompletionStream` rejects up front unless the
1282
+ * call is being routed through a proxy.
1283
+ */
1284
+ readonly streamingCorsRestricted: boolean;
1285
+ /**
1286
+ * Whether this provider's chat completions API accepts image input
1287
+ * (i.e. supports vision prompts). When false, calls with
1288
+ * `prompt.attachments` are rejected up front.
1289
+ */
1290
+ readonly acceptsImageInput: boolean;
1291
+ /**
1292
+ * Image-generation capabilities, scoped to model id prefixes. Empty or
1293
+ * undefined means the provider does not support image generation.
1294
+ *
1295
+ * @remarks
1296
+ * The dispatcher matches the resolved model id against each rule's
1297
+ * `modelPrefix` and selects the longest match (see
1298
+ * {@link AiAssist.resolveImageCapability}). An empty `modelPrefix` is the
1299
+ * catch-all and matches every model id.
1300
+ *
1301
+ * Multiple entries support providers that host more than one image-API
1302
+ * surface under one baseUrl. Google Gemini is the canonical case: the
1303
+ * `imagen-*` family is predict-only via `:predict`, while
1304
+ * `gemini-2.5-flash-image` uses chat-style `:generateContent` and accepts
1305
+ * reference images. Listing both lets callers pick the right model and the
1306
+ * dispatcher routes accordingly.
1307
+ *
1308
+ * Image-model selection reuses the existing `image` {@link ModelSpecKey}.
1309
+ * Providers that declare `imageGeneration` should declare a model in
1310
+ * `defaultModel.image`, e.g. `{ base: 'gpt-4o', image: 'dall-e-3' }`.
1311
+ */
1312
+ readonly imageGeneration?: ReadonlyArray<IAiImageModelCapability>;
1313
+ }
1314
+
1315
+ /**
1316
+ * Terminal success event for a streaming completion. Carries the aggregated
1317
+ * full text and truncation status for callers that want both the progressive
1318
+ * UI and the complete result.
1319
+ * @public
1320
+ */
1321
+ declare interface IAiStreamDone {
1322
+ readonly type: 'done';
1323
+ /** Whether the response was truncated due to token limits. */
1324
+ readonly truncated: boolean;
1325
+ /** The full concatenated text from all `text-delta` events. */
1326
+ readonly fullText: string;
1327
+ }
1328
+
1329
+ /**
1330
+ * Terminal failure event for a streaming completion. After this event no
1331
+ * further events are emitted.
1332
+ *
1333
+ * @remarks
1334
+ * Connection-time failures (auth, network, pre-flight CORS rejection) are
1335
+ * surfaced via the outer `Result.fail` returned by
1336
+ * `callProviderCompletionStream` rather than as an `error` event, so callers
1337
+ * can distinguish "didn't start" from "started but errored mid-stream."
1338
+ *
1339
+ * @public
1340
+ */
1341
+ declare interface IAiStreamError {
1342
+ readonly type: 'error';
1343
+ readonly message: string;
1344
+ }
1345
+
1346
+ /**
1347
+ * Discriminated union of events emitted by a streaming completion.
1348
+ * @public
1349
+ */
1350
+ declare type IAiStreamEvent = IAiStreamTextDelta | IAiStreamToolEvent | IAiStreamDone | IAiStreamError;
1351
+
1352
+ /**
1353
+ * A text-content delta arriving during a streaming completion.
1354
+ * @public
1355
+ */
1356
+ declare interface IAiStreamTextDelta {
1357
+ readonly type: 'text-delta';
1358
+ /** The newly arrived text fragment. */
1359
+ readonly delta: string;
1360
+ }
1361
+
1362
+ /**
1363
+ * A server-side tool progress event arriving during a streaming completion.
1364
+ * Surfaced for providers that emit explicit tool-progress markers (OpenAI
1365
+ * Responses API, Anthropic). Gemini's grounding doesn't emit these.
1366
+ * @public
1367
+ */
1368
+ declare interface IAiStreamToolEvent {
1369
+ readonly type: 'tool-event';
1370
+ /** Which server-side tool this event describes. */
1371
+ readonly toolType: AiServerToolType;
1372
+ /** Tool lifecycle phase. */
1373
+ readonly phase: 'started' | 'completed';
1374
+ /**
1375
+ * Optional provider-specific detail. For web_search this is typically the
1376
+ * search query when available; format varies by provider.
1377
+ */
1378
+ readonly detail?: string;
788
1379
  }
789
1380
 
790
1381
  /**
@@ -937,6 +1528,12 @@ declare interface ICryptoProvider {
937
1528
  * @returns Success with derived 32-byte key, or Failure with error
938
1529
  */
939
1530
  deriveKey(password: string, salt: Uint8Array, iterations: number): Promise<Result<Uint8Array>>;
1531
+ /**
1532
+ * Computes a SHA-256 hash of the given data.
1533
+ * @param data - UTF-8 string to hash
1534
+ * @returns Success with hex-encoded hash string, or Failure with error
1535
+ */
1536
+ sha256(data: string): Promise<Result<string>>;
940
1537
  /**
941
1538
  * Generates cryptographically secure random bytes.
942
1539
  * @param length - Number of bytes to generate
@@ -955,6 +1552,73 @@ declare interface ICryptoProvider {
955
1552
  * @returns Success with decoded bytes, or Failure if invalid base64
956
1553
  */
957
1554
  fromBase64(base64: string): Result<Uint8Array>;
1555
+ /**
1556
+ * Generates a new asymmetric keypair for the requested algorithm.
1557
+ * @param algorithm - The {@link CryptoUtils.KeyPairAlgorithm | algorithm} to use.
1558
+ * @param extractable - Whether the resulting `CryptoKey` objects may be exported.
1559
+ * Set `false` on backends that store `CryptoKey` references directly (e.g.
1560
+ * IndexedDB). Set `true` when the private key must round-trip through JWK or
1561
+ * PKCS#8 (e.g. encrypted-file backends).
1562
+ * @returns Success with the generated `CryptoKeyPair`, or Failure with error context.
1563
+ */
1564
+ generateKeyPair(algorithm: KeyPairAlgorithm, extractable: boolean): Promise<Result<CryptoKeyPair>>;
1565
+ /**
1566
+ * Exports the public half of a keypair as a JSON Web Key.
1567
+ * @param publicKey - The public `CryptoKey` to export. Must be an `extractable`
1568
+ * key generated for an asymmetric algorithm.
1569
+ * @returns Success with the JWK, or Failure with error context.
1570
+ */
1571
+ exportPublicKeyJwk(publicKey: CryptoKey): Promise<Result<JsonWebKey>>;
1572
+ /**
1573
+ * Re-imports a public-key JWK as a `CryptoKey` usable for verification or
1574
+ * encryption (depending on algorithm).
1575
+ * @param jwk - The JSON Web Key produced by {@link CryptoUtils.ICryptoProvider.exportPublicKeyJwk | exportPublicKeyJwk}.
1576
+ * @param algorithm - The {@link CryptoUtils.KeyPairAlgorithm | algorithm} the
1577
+ * key was generated for. Determines the import parameters and key usages.
1578
+ * @returns Success with the imported public `CryptoKey`, or Failure with error context.
1579
+ */
1580
+ importPublicKeyJwk(jwk: JsonWebKey, algorithm: KeyPairAlgorithm): Promise<Result<CryptoKey>>;
1581
+ /**
1582
+ * Wraps `plaintext` for delivery to the holder of the private key paired
1583
+ * with `recipientPublicKey`. Uses ECIES with ECDH P-256, HKDF-SHA256, and
1584
+ * AES-GCM-256.
1585
+ *
1586
+ * Generates a fresh ephemeral keypair per call; the ephemeral private key
1587
+ * is discarded after the shared-secret derive. Only the recipient (with the
1588
+ * matching private key) and the same HKDF parameters can recover
1589
+ * `plaintext`.
1590
+ *
1591
+ * Empty `plaintext` is permitted; the resulting wrap contains only the
1592
+ * 16-byte GCM authentication tag and round-trips back to an empty
1593
+ * `Uint8Array`.
1594
+ * @param plaintext - The bytes to wrap. Any length supported by AES-GCM
1595
+ * (in practice, well below 2^39 - 256 bits).
1596
+ * @param recipientPublicKey - The recipient's ECDH P-256 public `CryptoKey`.
1597
+ * Must have algorithm name `'ECDH'` and named curve `'P-256'`; mismatched
1598
+ * algorithm or curve yields a `Failure` with error context.
1599
+ * @param options - HKDF parameters; see {@link CryptoUtils.IWrapBytesOptions | IWrapBytesOptions}.
1600
+ * @returns `Success` with the wrapped payload, or `Failure` with error context.
1601
+ */
1602
+ wrapBytes(plaintext: Uint8Array, recipientPublicKey: CryptoKey, options: IWrapBytesOptions): Promise<Result<IWrappedBytes>>;
1603
+ /**
1604
+ * Inverse of {@link CryptoUtils.ICryptoProvider.wrapBytes | wrapBytes}.
1605
+ * Recovers the original `plaintext` from a wrapped payload using the
1606
+ * recipient's private key.
1607
+ *
1608
+ * Returns a `Failure` (never throws) on any of:
1609
+ * - Tampered nonce or ciphertext (AES-GCM authentication fails)
1610
+ * - Wrong private key (different shared secret derives a different wrap key)
1611
+ * - Wrong HKDF parameters (different wrap key)
1612
+ * - Malformed `ephemeralPublicKey` JWK
1613
+ * - Malformed base64 in `nonce` or `ciphertext`
1614
+ * @param wrapped - The wrapped payload produced by `wrapBytes`.
1615
+ * @param recipientPrivateKey - The recipient's ECDH P-256 private
1616
+ * `CryptoKey`. Must have algorithm name `'ECDH'` and named curve `'P-256'`,
1617
+ * and key usages including `'deriveKey'` or `'deriveBits'`.
1618
+ * @param options - The same HKDF parameters used at wrap time.
1619
+ * @returns `Success` with the original `plaintext`, or `Failure` with error context.
1620
+ */
1621
+ unwrapBytes(wrapped: IWrappedBytes, recipientPrivateKey: CryptoKey, options: IWrapBytesOptions): Promise<Result<Uint8Array>>;
958
1622
  }
959
1623
 
960
1624
  /**
@@ -1093,6 +1757,19 @@ declare interface IEncryptionResult {
1093
1757
  readonly encryptedData: Uint8Array;
1094
1758
  }
1095
1759
 
1760
+ /**
1761
+ * Options for importing raw key material via {@link KeyStore.importSecret}.
1762
+ * Extends {@link IImportSecretOptions} with a type classification.
1763
+ * @public
1764
+ */
1765
+ declare interface IImportKeyOptions extends IImportSecretOptions {
1766
+ /**
1767
+ * Symmetric secret type classification for the imported key material.
1768
+ * @defaultValue 'encryption-key'
1769
+ */
1770
+ readonly type?: KeyStoreSymmetricSecretType;
1771
+ }
1772
+
1096
1773
  /**
1097
1774
  * Options for importing a secret.
1098
1775
  * @public
@@ -1124,6 +1801,122 @@ declare interface IKeyDerivationParams {
1124
1801
  readonly iterations: number;
1125
1802
  }
1126
1803
 
1804
+ /**
1805
+ * WebCrypto parameters for a single {@link CryptoUtils.KeyPairAlgorithm}.
1806
+ * Implementations of {@link CryptoUtils.ICryptoProvider} use this table to
1807
+ * translate the small public algorithm enum into the WebCrypto algorithm
1808
+ * objects and key-usage arrays expected by `crypto.subtle`.
1809
+ * @public
1810
+ */
1811
+ declare interface IKeyPairAlgorithmParams {
1812
+ /**
1813
+ * Algorithm parameters for `crypto.subtle.generateKey`. Always an asymmetric
1814
+ * variant — these algorithms produce a `CryptoKeyPair`, not a single key.
1815
+ * The literal `{ name: 'Ed25519' }` member covers WebCrypto's Secure-Curves
1816
+ * Ed25519 algorithm, which takes only a `name`; using a literal rather than
1817
+ * the base `Algorithm` keeps the union closed to the algorithms this table
1818
+ * supports.
1819
+ */
1820
+ readonly generateKey: RsaHashedKeyGenParams | EcKeyGenParams | {
1821
+ readonly name: 'Ed25519';
1822
+ };
1823
+ /**
1824
+ * Algorithm parameters for `crypto.subtle.importKey('jwk', ...)` when
1825
+ * importing the public half of a keypair. The literal `{ name: 'Ed25519' }`
1826
+ * member covers Ed25519 imports, which take only a `name`; using a literal
1827
+ * rather than the base `Algorithm` keeps the union closed to the algorithms
1828
+ * this table supports.
1829
+ */
1830
+ readonly importPublicKey: RsaHashedImportParams | EcKeyImportParams | {
1831
+ readonly name: 'Ed25519';
1832
+ };
1833
+ /**
1834
+ * Default key usages for the generated `CryptoKeyPair`. Both halves receive
1835
+ * the usages WebCrypto considers valid for their role; the platform filters.
1836
+ */
1837
+ readonly keyPairUsages: ReadonlyArray<KeyUsage>;
1838
+ /**
1839
+ * Key usages applied when re-importing only the public key.
1840
+ */
1841
+ readonly publicKeyUsages: ReadonlyArray<KeyUsage>;
1842
+ }
1843
+
1844
+ /**
1845
+ * An asymmetric keypair entry stored in the vault (in-memory representation).
1846
+ * Holds only the public key (as a JWK) and a stable handle (`id`) the
1847
+ * {@link CryptoUtils.KeyStore.IPrivateKeyStorage} provider uses to fetch the private key.
1848
+ * @public
1849
+ */
1850
+ declare interface IKeyStoreAsymmetricEntry {
1851
+ /**
1852
+ * Unique name for this entry (used as vault lookup key, renameable).
1853
+ */
1854
+ readonly name: string;
1855
+ /**
1856
+ * Asymmetric secret type discriminator.
1857
+ */
1858
+ readonly type: KeyStoreAsymmetricSecretType;
1859
+ /**
1860
+ * Immutable handle used by {@link CryptoUtils.KeyStore.IPrivateKeyStorage} to address the
1861
+ * private key. Independent of `name`; survives renames.
1862
+ */
1863
+ readonly id: string;
1864
+ /**
1865
+ * Algorithm used to generate this keypair.
1866
+ */
1867
+ readonly algorithm: KeyPairAlgorithm;
1868
+ /**
1869
+ * The public key as a JSON Web Key.
1870
+ */
1871
+ readonly publicKeyJwk: JsonWebKey;
1872
+ /**
1873
+ * Optional description for this entry.
1874
+ */
1875
+ readonly description?: string;
1876
+ /**
1877
+ * When this entry was added (ISO 8601).
1878
+ */
1879
+ readonly createdAt: string;
1880
+ }
1881
+
1882
+ /**
1883
+ * JSON-serializable representation of an asymmetric keypair entry.
1884
+ * The private key is not present here — it lives in the
1885
+ * {@link CryptoUtils.KeyStore.IPrivateKeyStorage} provider, addressed by `id`.
1886
+ * @public
1887
+ */
1888
+ declare interface IKeyStoreAsymmetricEntryJson {
1889
+ /**
1890
+ * Unique name for this entry.
1891
+ */
1892
+ readonly name: string;
1893
+ /**
1894
+ * Asymmetric secret type discriminator.
1895
+ */
1896
+ readonly type: KeyStoreAsymmetricSecretType;
1897
+ /**
1898
+ * Immutable handle used by {@link CryptoUtils.KeyStore.IPrivateKeyStorage} to address the
1899
+ * private key.
1900
+ */
1901
+ readonly id: string;
1902
+ /**
1903
+ * Algorithm used to generate this keypair.
1904
+ */
1905
+ readonly algorithm: KeyPairAlgorithm;
1906
+ /**
1907
+ * The public key as a JSON Web Key.
1908
+ */
1909
+ readonly publicKeyJwk: JsonWebKey;
1910
+ /**
1911
+ * Optional description.
1912
+ */
1913
+ readonly description?: string;
1914
+ /**
1915
+ * When this entry was added (ISO 8601).
1916
+ */
1917
+ readonly createdAt: string;
1918
+ }
1919
+
1127
1920
  /**
1128
1921
  * Parameters for creating a new key store.
1129
1922
  * @public
@@ -1137,8 +1930,26 @@ declare interface IKeyStoreCreateParams {
1137
1930
  * PBKDF2 iterations (defaults to DEFAULT_KEYSTORE_ITERATIONS).
1138
1931
  */
1139
1932
  readonly iterations?: number;
1933
+ /**
1934
+ * Optional private-key storage backend. Required to use `addKeyPair` /
1935
+ * `getKeyPair`; absent backends still permit opening, listing, and reading
1936
+ * public-key metadata for asymmetric entries.
1937
+ */
1938
+ readonly privateKeyStorage?: IPrivateKeyStorage;
1140
1939
  }
1141
1940
 
1941
+ /**
1942
+ * Any vault entry, discriminated by `type`.
1943
+ * @public
1944
+ */
1945
+ declare type IKeyStoreEntry = IKeyStoreSymmetricEntry | IKeyStoreAsymmetricEntry;
1946
+
1947
+ /**
1948
+ * Any JSON vault entry, discriminated by `type`.
1949
+ * @public
1950
+ */
1951
+ declare type IKeyStoreEntryJson = IKeyStoreSymmetricEntryJson | IKeyStoreAsymmetricEntryJson;
1952
+
1142
1953
  /**
1143
1954
  * The encrypted key store file format.
1144
1955
  * @public
@@ -1183,22 +1994,46 @@ declare interface IKeyStoreOpenParams {
1183
1994
  * The encrypted key store file content.
1184
1995
  */
1185
1996
  readonly keystoreFile: IKeyStoreFile;
1997
+ /**
1998
+ * Optional private-key storage backend. Required to use `addKeyPair` /
1999
+ * `getKeyPair`; absent backends still permit opening, listing, and reading
2000
+ * public-key metadata for asymmetric entries.
2001
+ */
2002
+ readonly privateKeyStorage?: IPrivateKeyStorage;
1186
2003
  }
1187
2004
 
1188
2005
  /**
1189
- * A secret entry stored in the vault (in-memory representation).
2006
+ * Backwards-compatible alias for {@link CryptoUtils.KeyStore.IKeyStoreSymmetricEntry}.
2007
+ * @deprecated Use {@link CryptoUtils.KeyStore.IKeyStoreSymmetricEntry} for symmetric
2008
+ * entries or {@link CryptoUtils.KeyStore.IKeyStoreEntry} for the discriminated union.
2009
+ * @public
2010
+ */
2011
+ declare type IKeyStoreSecretEntry = IKeyStoreSymmetricEntry;
2012
+
2013
+ /**
2014
+ * Backwards-compatible alias for {@link CryptoUtils.KeyStore.IKeyStoreSymmetricEntryJson}.
2015
+ * @deprecated Use {@link CryptoUtils.KeyStore.IKeyStoreSymmetricEntryJson} for
2016
+ * symmetric entries or {@link CryptoUtils.KeyStore.IKeyStoreEntryJson} for the
2017
+ * discriminated union.
2018
+ * @public
2019
+ */
2020
+ declare type IKeyStoreSecretEntryJson = IKeyStoreSymmetricEntryJson;
2021
+
2022
+ /**
2023
+ * A symmetric secret entry stored in the vault (in-memory representation).
2024
+ * Holds the raw key material directly — for `'encryption-key'` it is a 32-byte
2025
+ * AES-256 key; for `'api-key'` it is the UTF-8 encoded API key string.
1190
2026
  * @public
1191
2027
  */
1192
- declare interface IKeyStoreSecretEntry {
2028
+ declare interface IKeyStoreSymmetricEntry {
1193
2029
  /**
1194
2030
  * Unique name for this secret (used as lookup key).
1195
2031
  */
1196
2032
  readonly name: string;
1197
2033
  /**
1198
- * Secret type discriminator.
1199
- * Defaults to `'encryption-key'` for backwards compatibility.
2034
+ * Symmetric secret type discriminator.
1200
2035
  */
1201
- readonly type: KeyStoreSecretType;
2036
+ readonly type: KeyStoreSymmetricSecretType;
1202
2037
  /**
1203
2038
  * The secret data.
1204
2039
  * - For `'encryption-key'`: 32-byte AES-256 key.
@@ -1216,19 +2051,34 @@ declare interface IKeyStoreSecretEntry {
1216
2051
  }
1217
2052
 
1218
2053
  /**
1219
- * JSON-serializable version of secret entry (for storage).
2054
+ * JSON-serializable representation of a symmetric secret entry.
2055
+ *
2056
+ * @remarks
2057
+ * Describes the *normalized* shape after parsing. `type` is required here
2058
+ * because the converter (see
2059
+ * {@link CryptoUtils.KeyStore.Converters.keystoreSymmetricEntryJson | keystoreSymmetricEntryJson})
2060
+ * injects the default `'encryption-key'` when reading vaults written before
2061
+ * asymmetric-keypair support added the discriminator. Raw on-wire bytes from
2062
+ * a legacy vault may therefore omit `type`; downstream code only ever sees
2063
+ * the post-conversion shape declared here.
2064
+ *
1220
2065
  * @public
1221
2066
  */
1222
- declare interface IKeyStoreSecretEntryJson {
2067
+ declare interface IKeyStoreSymmetricEntryJson {
1223
2068
  /**
1224
2069
  * Unique name for this secret.
1225
2070
  */
1226
2071
  readonly name: string;
1227
2072
  /**
1228
- * Secret type discriminator.
1229
- * Optional for backwards compatibility — missing means `'encryption-key'`.
2073
+ * Symmetric secret type discriminator.
2074
+ *
2075
+ * Required on this normalized model type. Vaults written prior to the
2076
+ * asymmetric-keypair support may omit this field on the wire; the
2077
+ * converter injects `'encryption-key'` when missing for backwards
2078
+ * compatibility, so by the time a value of this type is observed the
2079
+ * discriminator is always present.
1230
2080
  */
1231
- readonly type?: KeyStoreSecretType;
2081
+ readonly type: KeyStoreSymmetricSecretType;
1232
2082
  /**
1233
2083
  * Base64-encoded secret data.
1234
2084
  */
@@ -1244,7 +2094,7 @@ declare interface IKeyStoreSecretEntryJson {
1244
2094
  }
1245
2095
 
1246
2096
  /**
1247
- * The decrypted vault contents - a versioned map of secrets.
2097
+ * The decrypted vault contents - a versioned map of entries.
1248
2098
  * @public
1249
2099
  */
1250
2100
  declare interface IKeyStoreVaultContents {
@@ -1253,9 +2103,9 @@ declare interface IKeyStoreVaultContents {
1253
2103
  */
1254
2104
  readonly version: KeyStoreFormat;
1255
2105
  /**
1256
- * Map of secret name to secret entry.
2106
+ * Map of entry name to entry (symmetric or asymmetric).
1257
2107
  */
1258
- readonly secrets: Record<string, IKeyStoreSecretEntryJson>;
2108
+ readonly secrets: Record<string, IKeyStoreEntryJson>;
1259
2109
  }
1260
2110
 
1261
2111
  /**
@@ -1338,6 +2188,55 @@ declare interface INamedSecret {
1338
2188
  readonly key: Uint8Array;
1339
2189
  }
1340
2190
 
2191
+ /**
2192
+ * Pluggable backend that persists raw asymmetric private keys outside of the
2193
+ * encrypted keystore vault. Concrete implementations live in platform-specific
2194
+ * packages (e.g. an IndexedDB-backed implementation in `@fgv/ts-web-extras` or
2195
+ * an encrypted-file implementation in `@fgv/ts-chocolate`).
2196
+ *
2197
+ * The keystore writes storage-first: a private key is always stored here
2198
+ * before the corresponding public-key vault entry is committed. Conversely,
2199
+ * deletes hit the vault first and then this storage best-effort. As a result,
2200
+ * crashes or skipped saves can leave orphaned blobs here; callers are expected
2201
+ * to reconcile via {@link CryptoUtils.KeyStore.IPrivateKeyStorage.list} cross-referenced
2202
+ * against the keystore's asymmetric entries.
2203
+ *
2204
+ * @public
2205
+ */
2206
+ declare interface IPrivateKeyStorage {
2207
+ /**
2208
+ * Whether keys generated for this backend may be marked
2209
+ * `extractable: false`. `true` on backends that store `CryptoKey`
2210
+ * objects directly (e.g. IndexedDB). `false` on backends that must
2211
+ * round-trip via JWK (e.g. encrypted-file backends).
2212
+ */
2213
+ readonly supportsNonExtractable: boolean;
2214
+ /**
2215
+ * Stores `key` under `id`. Returns the stored `id` on success so the
2216
+ * call can compose into a Result chain.
2217
+ * @param id - Storage handle to write under.
2218
+ * @param key - The private `CryptoKey` to persist.
2219
+ */
2220
+ store(id: string, key: CryptoKey): Promise<Result<string>>;
2221
+ /**
2222
+ * Loads the private key previously stored under `id`.
2223
+ * @param id - Storage handle to look up.
2224
+ */
2225
+ load(id: string): Promise<Result<CryptoKey>>;
2226
+ /**
2227
+ * Deletes the entry stored under `id`. Returns the deleted `id` on
2228
+ * success so the call can compose into a Result chain.
2229
+ * @param id - Storage handle to remove.
2230
+ */
2231
+ delete(id: string): Promise<Result<string>>;
2232
+ /**
2233
+ * Lists every `id` currently held by the backend. Used by consumers to
2234
+ * garbage-collect orphans left by crashes or aborted sessions; the
2235
+ * keystore itself does not invoke this automatically.
2236
+ */
2237
+ list(): Promise<Result<readonly string[]>>;
2238
+ }
2239
+
1341
2240
  /**
1342
2241
  * Parameters for a provider completion request.
1343
2242
  * @public
@@ -1362,6 +2261,134 @@ declare interface IProviderCompletionParams {
1362
2261
  readonly logger?: Logging.ILogger;
1363
2262
  /** Server-side tools to include in the request. Overrides settings-level tool config when provided. */
1364
2263
  readonly tools?: ReadonlyArray<AiServerToolConfig>;
2264
+ /** Optional abort signal for cancelling the in-flight request. */
2265
+ readonly signal?: AbortSignal;
2266
+ /**
2267
+ * Optional override of the descriptor's default base URL. When set, the
2268
+ * dispatcher uses this URL (scheme + host + optional port + optional path
2269
+ * prefix) and appends the descriptor's per-route suffix (e.g.
2270
+ * `/chat/completions`) the same way it composes against the default.
2271
+ *
2272
+ * Must be a well-formed `http`/`https` URL string. Used to dispatch the same
2273
+ * provider descriptor against a self-hosted or local endpoint (e.g.
2274
+ * `http://localhost:11434/v1` for Ollama, or LAN-hosted OpenAI-compatible
2275
+ * servers).
2276
+ *
2277
+ * Setting `endpoint` does not change the auth shape: providers with
2278
+ * `needsSecret === true` still require an API key.
2279
+ */
2280
+ readonly endpoint?: string;
2281
+ }
2282
+
2283
+ /**
2284
+ * Parameters for a streaming completion request. Structurally identical to
2285
+ * the non-streaming `IProviderCompletionParams`; kept as its own interface
2286
+ * so callers can be explicit about which path they're invoking.
2287
+ *
2288
+ * @public
2289
+ */
2290
+ declare interface IProviderCompletionStreamParams {
2291
+ /** The provider descriptor */
2292
+ readonly descriptor: IAiProviderDescriptor;
2293
+ /** API key for authentication */
2294
+ readonly apiKey: string;
2295
+ /** The structured prompt to send */
2296
+ readonly prompt: AiPrompt;
2297
+ /**
2298
+ * Prior conversation history to insert between the system prompt and the
2299
+ * prompt's user message. The new user turn (carried by `prompt.user`) is
2300
+ * always sent last, so the wire shape becomes
2301
+ * `[system, ...messagesBefore, user=prompt.user]`.
2302
+ */
2303
+ readonly messagesBefore?: ReadonlyArray<IChatMessage>;
2304
+ /** Sampling temperature (default: 0.7) */
2305
+ readonly temperature?: number;
2306
+ /** Optional model override — string or context-aware map. */
2307
+ readonly modelOverride?: ModelSpec;
2308
+ /** Optional logger for request/response observability. */
2309
+ readonly logger?: Logging.ILogger;
2310
+ /** Server-side tools to include in the request. */
2311
+ readonly tools?: ReadonlyArray<AiServerToolConfig>;
2312
+ /** Optional abort signal for cancelling the in-flight stream. */
2313
+ readonly signal?: AbortSignal;
2314
+ /**
2315
+ * Optional override of the descriptor's default base URL. Same semantics as
2316
+ * the non-streaming completion path: a well-formed `http`/`https` URL is
2317
+ * substituted for `descriptor.baseUrl` when composing the streaming
2318
+ * request, with the per-format suffix appended unchanged. Validated at the
2319
+ * dispatcher; auth shape is unaffected.
2320
+ */
2321
+ readonly endpoint?: string;
2322
+ }
2323
+
2324
+ /**
2325
+ * Parameters for an image-generation request.
2326
+ * @public
2327
+ */
2328
+ declare interface IProviderImageGenerationParams {
2329
+ /** The provider descriptor */
2330
+ readonly descriptor: IAiProviderDescriptor;
2331
+ /** API key for authentication */
2332
+ readonly apiKey: string;
2333
+ /** The image-generation request */
2334
+ readonly params: IAiImageGenerationParams;
2335
+ /** Optional model override — string or context-aware map (uses descriptor.defaultModel.image otherwise) */
2336
+ readonly modelOverride?: ModelSpec;
2337
+ /** Optional logger for request/response observability. */
2338
+ readonly logger?: Logging.ILogger;
2339
+ /** Optional abort signal for cancelling the in-flight request. */
2340
+ readonly signal?: AbortSignal;
2341
+ /**
2342
+ * Optional override of the descriptor's default base URL. Same semantics as
2343
+ * the non-streaming completion path's endpoint: a well-formed `http`/`https`
2344
+ * URL substituted for `descriptor.baseUrl` when composing the request, with
2345
+ * the per-route suffix (e.g. `/images/generations`, `:predict`) appended
2346
+ * unchanged.
2347
+ */
2348
+ readonly endpoint?: string;
2349
+ }
2350
+
2351
+ /**
2352
+ * Parameters for a list-models request.
2353
+ * @public
2354
+ */
2355
+ declare interface IProviderListModelsParams {
2356
+ /** The provider descriptor */
2357
+ readonly descriptor: IAiProviderDescriptor;
2358
+ /** API key for authentication */
2359
+ readonly apiKey: string;
2360
+ /** Optional capability filter; when set, only models declaring this capability are returned. */
2361
+ readonly capability?: AiModelCapability;
2362
+ /** Optional capability config override (defaults to {@link DEFAULT_MODEL_CAPABILITY_CONFIG}). */
2363
+ readonly capabilityConfig?: IAiModelCapabilityConfig;
2364
+ /** Optional logger for request/response observability. */
2365
+ readonly logger?: Logging.ILogger;
2366
+ /** Optional abort signal for cancelling the in-flight request. */
2367
+ readonly signal?: AbortSignal;
2368
+ /**
2369
+ * Optional override of the descriptor's default base URL — a well-formed
2370
+ * `http`/`https` URL substituted for `descriptor.baseUrl`, with the
2371
+ * per-format `/models` route appended unchanged.
2372
+ */
2373
+ readonly endpoint?: string;
2374
+ }
2375
+
2376
+ /**
2377
+ * Result of removing a secret from the key store.
2378
+ * @public
2379
+ */
2380
+ declare interface IRemoveSecretResult {
2381
+ /**
2382
+ * The secret entry that was removed from the vault.
2383
+ */
2384
+ readonly entry: IKeyStoreEntry;
2385
+ /**
2386
+ * Best-effort warning from {@link CryptoUtils.KeyStore.IPrivateKeyStorage}.delete
2387
+ * for asymmetric entries when the storage call failed. The vault entry is
2388
+ * still considered removed and the orphaned blob is left for consumer-side
2389
+ * GC to reconcile.
2390
+ */
2391
+ readonly warning?: string;
1365
2392
  }
1366
2393
 
1367
2394
  /**
@@ -1399,6 +2426,13 @@ declare function isKeyStoreFile(json: unknown): boolean;
1399
2426
  */
1400
2427
  declare const isoDate: Converter<Date, unknown>;
1401
2428
 
2429
+ /**
2430
+ * A `Converter` which converts an iso formatted string, a number or a `Date` object to
2431
+ * a `DateTime` object.
2432
+ * @public
2433
+ */
2434
+ declare const isoDateTime: Converter<DateTime, unknown>;
2435
+
1402
2436
  /**
1403
2437
  * Represents a variable reference extracted from a Mustache template.
1404
2438
  * @public
@@ -1423,6 +2457,95 @@ declare interface IVariableRef {
1423
2457
  readonly isSection: boolean;
1424
2458
  }
1425
2459
 
2460
+ /**
2461
+ * Caller-supplied HKDF parameters that domain-separate one
2462
+ * {@link CryptoUtils.ICryptoProvider.wrapBytes | wrapBytes} call from another.
2463
+ * Two wraps that share recipient but differ on `salt` or `info` derive distinct
2464
+ * wrap keys, so callers should pick values that bind the wrap to its
2465
+ * application context (e.g. a content hash for `salt` and a secret name for
2466
+ * `info`).
2467
+ *
2468
+ * Both fields are required; pass an empty `Uint8Array` if the caller has no
2469
+ * value to bind on a given axis. Silent defaulting would hide protocol
2470
+ * mistakes, so the API does not pick defaults.
2471
+ * @public
2472
+ */
2473
+ declare interface IWrapBytesOptions {
2474
+ /**
2475
+ * HKDF salt. Domain-separates this wrap from others in different contexts.
2476
+ * Caller picks; common choices include a content hash, document id, channel
2477
+ * id, etc.
2478
+ */
2479
+ readonly salt: Uint8Array;
2480
+ /**
2481
+ * HKDF info. Further binds the derived key to a specific use within the
2482
+ * calling application. Caller picks; common choices include a secret name,
2483
+ * message type, or version tag.
2484
+ */
2485
+ readonly info: Uint8Array;
2486
+ }
2487
+
2488
+ /**
2489
+ * Output of {@link CryptoUtils.ICryptoProvider.wrapBytes | wrapBytes}. The
2490
+ * shape is JSON-serializable so it can travel directly over the wire or be
2491
+ * persisted as-is.
2492
+ * @public
2493
+ */
2494
+ declare interface IWrappedBytes {
2495
+ /**
2496
+ * Sender's ephemeral ECDH P-256 public key as a JSON Web Key. The matching
2497
+ * ephemeral private key is dropped after the shared-secret derive.
2498
+ */
2499
+ readonly ephemeralPublicKey: JsonWebKey;
2500
+ /**
2501
+ * AES-GCM nonce, base64-encoded. 12 bytes (96 bits) — the standard AES-GCM
2502
+ * nonce length.
2503
+ */
2504
+ readonly nonce: string;
2505
+ /**
2506
+ * AES-GCM ciphertext concatenated with the 16-byte authentication tag,
2507
+ * base64-encoded. Tampering with either the nonce or the ciphertext causes
2508
+ * unwrap to fail GCM authentication.
2509
+ */
2510
+ readonly ciphertext: string;
2511
+ }
2512
+
2513
+ /**
2514
+ * Options for YAML serialization, mirroring commonly-used `js-yaml` `DumpOptions`.
2515
+ * @public
2516
+ */
2517
+ declare interface IYamlSerializeOptions {
2518
+ /**
2519
+ * Indentation width in spaces (default: 2).
2520
+ */
2521
+ readonly indent?: number;
2522
+ /**
2523
+ * Nesting level at which to switch from block to flow style.
2524
+ * -1 means block style everywhere (default: -1).
2525
+ */
2526
+ readonly flowLevel?: number;
2527
+ /**
2528
+ * If true, sort keys when dumping (default: false).
2529
+ */
2530
+ readonly sortKeys?: boolean;
2531
+ /**
2532
+ * Maximum line width (default: 80).
2533
+ */
2534
+ readonly lineWidth?: number;
2535
+ /**
2536
+ * If true, don't convert duplicate objects into references (default: false).
2537
+ */
2538
+ readonly noRefs?: boolean;
2539
+ /**
2540
+ * If true, don't add an indentation level to array elements (default: false).
2541
+ */
2542
+ readonly noArrayIndent?: boolean;
2543
+ /**
2544
+ * If true, all non-key strings will be quoted (default: false).
2545
+ */
2546
+ readonly forceQuotes?: boolean;
2547
+ }
2548
+
1426
2549
  /**
1427
2550
  * Simple interface for a file to be added to a zip file.
1428
2551
  * @public
@@ -1452,6 +2575,24 @@ declare interface JarRecordParserOptions {
1452
2575
  readonly fixedContinuationSize?: number;
1453
2576
  }
1454
2577
 
2578
+ /**
2579
+ * In-place shape check for a JSON Web Key. Asserts only that the input is a
2580
+ * non-array object whose `kty` discriminator is a string; every other JWK
2581
+ * field passes through untouched. This is intentionally **not** a true JWK
2582
+ * validator — per-algorithm correctness (RSA `n`/`e`, EC `crv`/`x`/`y`,
2583
+ * key-size constraints, etc.) is delegated to `crypto.subtle.importKey` at
2584
+ * first use, which is the authoritative checker. The "shape" suffix in the
2585
+ * name is the warning sign for readers expecting full validation.
2586
+ * @remarks
2587
+ * Built with `Validators.object` (in-place, non-strict) so unknown JWK fields
2588
+ * survive the round-trip; the cast to `FieldValidators<JsonWebKey>` is required
2589
+ * only because TypeScript's mapped type demands an entry for every key in
2590
+ * `JsonWebKey`. At runtime the `ObjectValidator` only inspects keys present in
2591
+ * the field-validators map.
2592
+ * @public
2593
+ */
2594
+ declare const jsonWebKeyShape: Validator<JsonWebKey>;
2595
+
1455
2596
  /**
1456
2597
  * Supported key derivation functions.
1457
2598
  * @public
@@ -1470,18 +2611,63 @@ declare const keyDerivationFunction: Converter<KeyDerivationFunction>;
1470
2611
  */
1471
2612
  declare const keyDerivationParams: Converter<IKeyDerivationParams>;
1472
2613
 
2614
+ /**
2615
+ * Asymmetric keypair algorithms supported by the crypto provider.
2616
+ * - `'ecdsa-p256'`: ECDSA over the P-256 curve, for signing.
2617
+ * - `'rsa-oaep-2048'`: RSA-OAEP, 2048-bit modulus with SHA-256, for encryption.
2618
+ * - `'ecdh-p256'`: ECDH over the P-256 curve, for key agreement
2619
+ * (e.g. as the recipient keypair in
2620
+ * {@link CryptoUtils.ICryptoProvider.wrapBytes | wrapBytes} /
2621
+ * {@link CryptoUtils.ICryptoProvider.unwrapBytes | unwrapBytes}).
2622
+ * - `'ed25519'`: EdDSA over the Edwards25519 curve, for signing.
2623
+ * Deterministic — the per-signature nonce is derived from the private key
2624
+ * and message rather than sampled randomly, eliminating the random-nonce
2625
+ * reuse risk that ECDSA carries. Distinct from X25519 (key agreement over
2626
+ * the Montgomery form, Curve25519).
2627
+ * @public
2628
+ */
2629
+ declare type KeyPairAlgorithm = 'ecdsa-p256' | 'rsa-oaep-2048' | 'ecdh-p256' | 'ed25519';
2630
+
2631
+ /**
2632
+ * Converter for {@link CryptoUtils.KeyStore.KeyPairAlgorithm | key pair algorithm}.
2633
+ * @public
2634
+ */
2635
+ declare const keyPairAlgorithm: Converter<KeyPairAlgorithm>;
2636
+
2637
+ /**
2638
+ * Lookup table from {@link CryptoUtils.KeyPairAlgorithm} to the WebCrypto
2639
+ * parameters needed to drive `crypto.subtle`. Shared between every
2640
+ * {@link CryptoUtils.ICryptoProvider} implementation since both Node and
2641
+ * browser providers speak the same WebCrypto API. Exposed for downstream
2642
+ * provider implementations (e.g. browser-side providers in `@fgv/ts-web-extras`).
2643
+ * @public
2644
+ */
2645
+ declare const keyPairAlgorithmParams: Readonly<Record<KeyPairAlgorithm, IKeyPairAlgorithmParams>>;
2646
+
1473
2647
  declare namespace KeyStore {
1474
2648
  export {
1475
2649
  Converters_2 as Converters,
1476
2650
  KeyStore_2 as KeyStore,
1477
2651
  isKeyStoreFile,
2652
+ allKeyPairAlgorithms,
2653
+ KeyPairAlgorithm,
1478
2654
  KeyStoreFormat,
1479
2655
  KEYSTORE_FORMAT,
1480
2656
  DEFAULT_KEYSTORE_ITERATIONS,
1481
2657
  MIN_SALT_LENGTH,
2658
+ KeyStoreSymmetricSecretType,
2659
+ allKeyStoreSymmetricSecretTypes,
2660
+ KeyStoreAsymmetricSecretType,
2661
+ allKeyStoreAsymmetricSecretTypes,
1482
2662
  KeyStoreSecretType,
1483
2663
  allKeyStoreSecretTypes,
2664
+ IKeyStoreSymmetricEntry,
2665
+ IKeyStoreAsymmetricEntry,
2666
+ IKeyStoreEntry,
1484
2667
  IKeyStoreSecretEntry,
2668
+ IKeyStoreSymmetricEntryJson,
2669
+ IKeyStoreAsymmetricEntryJson,
2670
+ IKeyStoreEntryJson,
1485
2671
  IKeyStoreSecretEntryJson,
1486
2672
  IKeyStoreVaultContents,
1487
2673
  IKeyStoreFile,
@@ -1491,9 +2677,14 @@ declare namespace KeyStore {
1491
2677
  IAddSecretResult,
1492
2678
  IAddSecretOptions,
1493
2679
  IImportSecretOptions,
2680
+ IImportKeyOptions,
1494
2681
  IAddSecretFromPasswordOptions,
1495
2682
  DEFAULT_SECRET_ITERATIONS,
1496
- IAddSecretFromPasswordResult
2683
+ IAddSecretFromPasswordResult,
2684
+ IAddKeyPairOptions,
2685
+ IAddKeyPairResult,
2686
+ IRemoveSecretResult,
2687
+ IPrivateKeyStorage
1497
2688
  }
1498
2689
  }
1499
2690
 
@@ -1530,6 +2721,7 @@ declare namespace KeyStore {
1530
2721
  */
1531
2722
  declare class KeyStore_2 implements IEncryptionProvider {
1532
2723
  private readonly _cryptoProvider;
2724
+ private readonly _privateKeyStorage;
1533
2725
  private readonly _iterations;
1534
2726
  private _keystoreFile;
1535
2727
  private _salt;
@@ -1571,6 +2763,21 @@ declare class KeyStore_2 implements IEncryptionProvider {
1571
2763
  * @public
1572
2764
  */
1573
2765
  unlock(password: string): Promise<Result<KeyStore_2>>;
2766
+ /**
2767
+ * Unlocks an existing key store with a pre-derived key, bypassing
2768
+ * PBKDF2 key derivation. Use this when the derived key has been
2769
+ * stored externally (e.g., in another key store) and the original
2770
+ * password is no longer available.
2771
+ *
2772
+ * The supplied key must have been derived from the correct password
2773
+ * using the key store file's own PBKDF2 parameters (salt and
2774
+ * iteration count).
2775
+ *
2776
+ * @param derivedKey - The pre-derived master key (32 bytes for AES-256)
2777
+ * @returns Success with this instance when unlocked, Failure if key is incorrect
2778
+ * @public
2779
+ */
2780
+ unlockWithKey(derivedKey: Uint8Array): Promise<Result<KeyStore_2>>;
1574
2781
  /**
1575
2782
  * Locks the key store, clearing all secrets from memory.
1576
2783
  * @param force - If true, discards unsaved changes
@@ -1613,12 +2820,23 @@ declare class KeyStore_2 implements IEncryptionProvider {
1613
2820
  */
1614
2821
  listSecrets(): Result<readonly string[]>;
1615
2822
  /**
1616
- * Gets a secret by name.
2823
+ * Gets a secret by name. Returns the {@link CryptoUtils.KeyStore.IKeyStoreEntry | discriminated union}
2824
+ * — callers must check `entry.type` before accessing `key`/`id` since asymmetric
2825
+ * entries carry no raw key material.
1617
2826
  * @param name - Name of the secret
1618
2827
  * @returns Success with secret entry, Failure if not found or locked
1619
2828
  * @public
1620
2829
  */
1621
- getSecret(name: string): Result<IKeyStoreSecretEntry>;
2830
+ getSecret(name: string): Result<IKeyStoreEntry>;
2831
+ /**
2832
+ * Returns the public-key JWK for an asymmetric-keypair entry.
2833
+ * Available without {@link CryptoUtils.KeyStore.IPrivateKeyStorage} since the
2834
+ * public key lives in the vault metadata directly.
2835
+ * @param name - Name of the entry
2836
+ * @returns Success with the JWK, Failure if not found, locked, or wrong type
2837
+ * @public
2838
+ */
2839
+ getPublicKeyJwk(name: string): Result<JsonWebKey>;
1622
2840
  /**
1623
2841
  * Checks if a secret exists.
1624
2842
  * @param name - Name of the secret
@@ -1635,14 +2853,20 @@ declare class KeyStore_2 implements IEncryptionProvider {
1635
2853
  */
1636
2854
  addSecret(name: string, options?: IAddSecretOptions): Promise<Result<IAddSecretResult>>;
1637
2855
  /**
1638
- * Imports an existing secret key.
2856
+ * Imports raw 32-byte key material into the vault.
2857
+ *
2858
+ * Always validates that the key is exactly 32 bytes (AES-256). The optional
2859
+ * `type` field is a classification label stored with the entry; it does not
2860
+ * change the validation rules. For importing UTF-8 API key strings (variable
2861
+ * length), use {@link KeyStore.importApiKey} instead.
2862
+ *
1639
2863
  * @param name - Unique name for the secret
1640
- * @param key - The 32-byte AES-256 key
1641
- * @param options - Optional description, whether to replace existing
2864
+ * @param key - The 32-byte AES-256 key material
2865
+ * @param options - Optional type classification, description, whether to replace existing
1642
2866
  * @returns Success with entry, Failure if locked, key invalid, or exists and !replace
1643
2867
  * @public
1644
2868
  */
1645
- importSecret(name: string, key: Uint8Array, options?: IImportSecretOptions): Result<IAddSecretResult>;
2869
+ importSecret(name: string, key: Uint8Array, options?: IImportKeyOptions): Promise<Result<IAddSecretResult>>;
1646
2870
  /**
1647
2871
  * Adds a secret derived from a password using PBKDF2.
1648
2872
  *
@@ -1659,12 +2883,16 @@ declare class KeyStore_2 implements IEncryptionProvider {
1659
2883
  */
1660
2884
  addSecretFromPassword(name: string, password: string, options?: IAddSecretFromPasswordOptions): Promise<Result<IAddSecretFromPasswordResult>>;
1661
2885
  /**
1662
- * Removes a secret by name.
2886
+ * Removes a secret by name. Vault-first: the in-memory vault entry is dropped
2887
+ * before any storage cleanup runs. For asymmetric-keypair entries, best-effort
2888
+ * calls {@link CryptoUtils.KeyStore.IPrivateKeyStorage}.delete on the entry's
2889
+ * `id`; a failure is reported via `warning` on the result but does not roll
2890
+ * back the vault removal.
1663
2891
  * @param name - Name of the secret to remove
1664
- * @returns Success with removed entry, Failure if not found or locked
2892
+ * @returns Success with removed entry (and optional warning), Failure if not found or locked
1665
2893
  * @public
1666
2894
  */
1667
- removeSecret(name: string): Result<IKeyStoreSecretEntry>;
2895
+ removeSecret(name: string): Promise<Result<IRemoveSecretResult>>;
1668
2896
  /**
1669
2897
  * Imports an API key string into the vault.
1670
2898
  * The string is UTF-8 encoded and stored with type `'api-key'`.
@@ -1674,7 +2902,7 @@ declare class KeyStore_2 implements IEncryptionProvider {
1674
2902
  * @returns Success with entry, Failure if locked, empty, or exists and !replace
1675
2903
  * @public
1676
2904
  */
1677
- importApiKey(name: string, apiKey: string, options?: IImportSecretOptions): Result<IAddSecretResult>;
2905
+ importApiKey(name: string, apiKey: string, options?: IImportSecretOptions): Promise<Result<IAddSecretResult>>;
1678
2906
  /**
1679
2907
  * Retrieves an API key string by name.
1680
2908
  * Only works for secrets with type `'api-key'`.
@@ -1683,6 +2911,41 @@ declare class KeyStore_2 implements IEncryptionProvider {
1683
2911
  * @public
1684
2912
  */
1685
2913
  getApiKey(name: string): Result<string>;
2914
+ /**
2915
+ * Adds a new asymmetric keypair to the vault. Storage-first: the private key
2916
+ * is stored under a freshly-minted `id` before the public-key vault entry is
2917
+ * committed. If the storage call fails, no vault entry is written and the
2918
+ * operation returns Failure.
2919
+ *
2920
+ * When `replace: true` displaces an existing entry (asymmetric or symmetric),
2921
+ * a fresh `id` is minted; the displaced entry's resources are released
2922
+ * best-effort. Failure of the storage delete is reported via `warning` on the
2923
+ * result but does not roll back the replacement.
2924
+ *
2925
+ * Requires a {@link CryptoUtils.KeyStore.IPrivateKeyStorage} backend
2926
+ * supplied at construction.
2927
+ *
2928
+ * @param name - Unique name for the entry
2929
+ * @param options - Algorithm, optional description, replace flag
2930
+ * @returns Success with the new entry, Failure if locked, no provider, or storage write failed
2931
+ * @public
2932
+ */
2933
+ addKeyPair(name: string, options: IAddKeyPairOptions): Promise<Result<IAddKeyPairResult>>;
2934
+ /**
2935
+ * Retrieves the keypair for an asymmetric-keypair entry. The private key is
2936
+ * loaded from {@link CryptoUtils.KeyStore.IPrivateKeyStorage} on every call —
2937
+ * the keystore never caches private `CryptoKey` references between calls.
2938
+ * The public key is re-imported from the vault's JWK so callers always
2939
+ * receive a `CryptoKey` rather than the JWK form.
2940
+ * @param name - Name of the entry
2941
+ * @returns Success with `{ publicKey, privateKey }`, Failure if not found,
2942
+ * locked, wrong type, no provider, or storage load failed.
2943
+ * @public
2944
+ */
2945
+ getKeyPair(name: string): Promise<Result<{
2946
+ publicKey: CryptoKey;
2947
+ privateKey: CryptoKey;
2948
+ }>>;
1686
2949
  /**
1687
2950
  * Lists secret names filtered by type.
1688
2951
  * @param type - The secret type to filter by
@@ -1697,7 +2960,7 @@ declare class KeyStore_2 implements IEncryptionProvider {
1697
2960
  * @returns Success with updated entry, Failure if source not found, target exists, or locked
1698
2961
  * @public
1699
2962
  */
1700
- renameSecret(oldName: string, newName: string): Result<IKeyStoreSecretEntry>;
2963
+ renameSecret(oldName: string, newName: string): Result<IKeyStoreEntry>;
1701
2964
  /**
1702
2965
  * Saves the key store, returning the encrypted file content.
1703
2966
  * Requires the master password to encrypt.
@@ -1706,6 +2969,20 @@ declare class KeyStore_2 implements IEncryptionProvider {
1706
2969
  * @public
1707
2970
  */
1708
2971
  save(password: string): Promise<Result<IKeyStoreFile>>;
2972
+ /**
2973
+ * Saves the key store using a pre-derived key, bypassing PBKDF2 key
2974
+ * derivation. Use this when the derived key has been stored externally
2975
+ * (e.g., in another key store) and the original password is no longer
2976
+ * available.
2977
+ *
2978
+ * The supplied key must be the same key that was (or would be) derived
2979
+ * from the master password using the key store's PBKDF2 parameters.
2980
+ *
2981
+ * @param derivedKey - The pre-derived master key (32 bytes for AES-256)
2982
+ * @returns Success with IKeyStoreFile, Failure if locked or key invalid
2983
+ * @public
2984
+ */
2985
+ saveWithKey(derivedKey: Uint8Array): Promise<Result<IKeyStoreFile>>;
1709
2986
  /**
1710
2987
  * Changes the master password.
1711
2988
  * Re-encrypts the vault with the new password-derived key.
@@ -1730,6 +3007,33 @@ declare class KeyStore_2 implements IEncryptionProvider {
1730
3007
  * @public
1731
3008
  */
1732
3009
  getEncryptionConfig(): Result<Pick<IEncryptionConfig, 'secretProvider' | 'cryptoProvider'>>;
3010
+ /**
3011
+ * Encrypts the vault with a derived key and returns the key store file.
3012
+ * Shared by `save()` and `saveWithKey()`.
3013
+ */
3014
+ private _encryptVault;
3015
+ /**
3016
+ * Decrypts the vault with a derived key and loads secrets into memory.
3017
+ * Shared by `unlock()` and `unlockWithKey()`.
3018
+ */
3019
+ private _decryptVault;
3020
+ /**
3021
+ * Releases the resources held by an entry being displaced from the vault.
3022
+ * Symmetric entries get their key buffer zeroed in place. Asymmetric entries
3023
+ * have their private-key blob best-effort deleted from
3024
+ * {@link CryptoUtils.KeyStore.IPrivateKeyStorage}; if the storage call fails,
3025
+ * a warning string is returned but the displacement still proceeds — the
3026
+ * orphaned blob is left for consumer-side GC. Without a configured provider,
3027
+ * asymmetric cleanup is silently skipped.
3028
+ * @returns A warning string if storage cleanup failed, otherwise undefined.
3029
+ */
3030
+ private _releaseEntryResources;
3031
+ /**
3032
+ * Mints a fresh UUID v4 storage handle using the crypto provider's
3033
+ * {@link CryptoUtils.ICryptoProvider.generateRandomBytes | generateRandomBytes}.
3034
+ * Random-bytes failures propagate as Failure.
3035
+ */
3036
+ private _generateId;
1733
3037
  }
1734
3038
 
1735
3039
  /**
@@ -1738,6 +3042,31 @@ declare class KeyStore_2 implements IEncryptionProvider {
1738
3042
  */
1739
3043
  declare const KEYSTORE_FORMAT: KeyStoreFormat;
1740
3044
 
3045
+ /**
3046
+ * Converter for {@link CryptoUtils.KeyStore.IKeyStoreAsymmetricEntryJson | asymmetric keypair entry} in JSON form.
3047
+ * The `publicKeyJwk` field passes through {@link CryptoUtils.KeyStore.Converters.jsonWebKeyShape | jsonWebKeyShape}
3048
+ * (shape check only — see its docs); cryptographic correctness is enforced by
3049
+ * `crypto.subtle.importKey` at use.
3050
+ * @public
3051
+ */
3052
+ declare const keystoreAsymmetricEntryJson: Converter<IKeyStoreAsymmetricEntryJson>;
3053
+
3054
+ /**
3055
+ * Discriminator for asymmetric secret types stored in the vault.
3056
+ * - `'asymmetric-keypair'`: A public/private key pair. The public key is held in
3057
+ * the vault as a JWK; the private key lives in the supplied
3058
+ * {@link CryptoUtils.KeyStore.IPrivateKeyStorage} provider.
3059
+ * @public
3060
+ */
3061
+ declare type KeyStoreAsymmetricSecretType = 'asymmetric-keypair';
3062
+
3063
+ /**
3064
+ * Converter for {@link CryptoUtils.KeyStore.KeyStoreAsymmetricSecretType | asymmetric secret type} discriminator.
3065
+ * Accepts only `'asymmetric-keypair'`.
3066
+ * @public
3067
+ */
3068
+ declare const keystoreAsymmetricSecretType: Converter<KeyStoreAsymmetricSecretType>;
3069
+
1741
3070
  /**
1742
3071
  * Converter for {@link CryptoUtils.KeyStore.IKeyStoreFile | encrypted key store file}.
1743
3072
  * @public
@@ -1763,25 +3092,59 @@ declare const keystoreFormat: Converter<KeyStoreFormat>;
1763
3092
  declare type KeyStoreLockState = 'locked' | 'unlocked';
1764
3093
 
1765
3094
  /**
1766
- * Converter for {@link CryptoUtils.KeyStore.IKeyStoreSecretEntryJson | key store secret entry} in JSON format.
1767
- * The `type` field is optional for backwards compatibility — missing means `'encryption-key'`.
3095
+ * Discriminated-union converter for any {@link CryptoUtils.KeyStore.IKeyStoreEntryJson | key store entry} in JSON form.
3096
+ * Routes by the `type` field: `'asymmetric-keypair'` is parsed by
3097
+ * {@link CryptoUtils.KeyStore.Converters.keystoreAsymmetricEntryJson | keystoreAsymmetricEntryJson},
3098
+ * anything else (including a missing `type` field for backwards compatibility) by
3099
+ * {@link CryptoUtils.KeyStore.Converters.keystoreSymmetricEntryJson | keystoreSymmetricEntryJson}.
3100
+ * @public
3101
+ */
3102
+ declare const keystoreSecretEntryJson: Converter<IKeyStoreEntryJson>;
3103
+
3104
+ /**
3105
+ * Discriminator for any secret type stored in the vault.
3106
+ * @public
3107
+ */
3108
+ declare type KeyStoreSecretType = KeyStoreSymmetricSecretType | KeyStoreAsymmetricSecretType;
3109
+
3110
+ /**
3111
+ * Converter for {@link CryptoUtils.KeyStore.KeyStoreSecretType | any key store secret type} discriminator.
3112
+ * Accepts both symmetric and asymmetric type values.
3113
+ * @public
3114
+ */
3115
+ declare const keystoreSecretType: Converter<KeyStoreSecretType>;
3116
+
3117
+ /**
3118
+ * Converter for {@link CryptoUtils.KeyStore.IKeyStoreSymmetricEntryJson | symmetric secret entry} in JSON form.
3119
+ *
3120
+ * @remarks
3121
+ * Backwards compatibility with vaults written before asymmetric-keypair
3122
+ * support: those entries may lack the `type` discriminator on the wire. To
3123
+ * keep the model type honest (`type` is required on
3124
+ * {@link CryptoUtils.KeyStore.IKeyStoreSymmetricEntryJson}, see its docs),
3125
+ * we declare `type` in `optionalFields` so the inner `Converters.object` will
3126
+ * accept input without it, then `.map()` injects the default
3127
+ * `'encryption-key'` when missing. The output therefore always carries the
3128
+ * discriminator and downstream code never sees the legacy missing-type form.
3129
+ *
1768
3130
  * @public
1769
3131
  */
1770
- declare const keystoreSecretEntryJson: Converter<IKeyStoreSecretEntryJson>;
3132
+ declare const keystoreSymmetricEntryJson: Converter<IKeyStoreSymmetricEntryJson>;
1771
3133
 
1772
3134
  /**
1773
- * Discriminator for secret types stored in the vault.
3135
+ * Discriminator for symmetric secret types stored in the vault.
1774
3136
  * - `'encryption-key'`: A 32-byte AES-256 encryption key.
1775
3137
  * - `'api-key'`: An arbitrary-length API key string (UTF-8 encoded).
1776
3138
  * @public
1777
3139
  */
1778
- declare type KeyStoreSecretType = 'encryption-key' | 'api-key';
3140
+ declare type KeyStoreSymmetricSecretType = 'encryption-key' | 'api-key';
1779
3141
 
1780
3142
  /**
1781
- * Converter for {@link CryptoUtils.KeyStore.KeyStoreSecretType | key store secret type} discriminator.
3143
+ * Converter for {@link CryptoUtils.KeyStore.KeyStoreSymmetricSecretType | symmetric secret type} discriminator.
3144
+ * Accepts only `'encryption-key'` and `'api-key'`.
1782
3145
  * @public
1783
3146
  */
1784
- declare const keystoreSecretType: Converter<KeyStoreSecretType>;
3147
+ declare const keystoreSymmetricSecretType: Converter<KeyStoreSymmetricSecretType>;
1785
3148
 
1786
3149
  /**
1787
3150
  * Converter for {@link CryptoUtils.KeyStore.IKeyStoreVaultContents | key store vault contents} (decrypted state).
@@ -1971,6 +3334,12 @@ declare class NodeCryptoProvider implements ICryptoProvider {
1971
3334
  * @returns `Success` with derived 32-byte key, or `Failure` with an error.
1972
3335
  */
1973
3336
  deriveKey(password: string, salt: Uint8Array, iterations: number): Promise<Result<Uint8Array>>;
3337
+ /**
3338
+ * Computes a SHA-256 hash of the given data.
3339
+ * @param data - UTF-8 string to hash
3340
+ * @returns `Success` with hex-encoded hash string, or `Failure` with an error.
3341
+ */
3342
+ sha256(data: string): Promise<Result<string>>;
1974
3343
  /**
1975
3344
  * Generates cryptographically secure random bytes.
1976
3345
  * @param length - Number of bytes to generate
@@ -1989,6 +3358,50 @@ declare class NodeCryptoProvider implements ICryptoProvider {
1989
3358
  * @returns Success with decoded bytes, or Failure if invalid base64
1990
3359
  */
1991
3360
  fromBase64(base64: string): Result<Uint8Array>;
3361
+ /**
3362
+ * Generates a new asymmetric keypair using Node's WebCrypto.
3363
+ * @param algorithm - The {@link CryptoUtils.KeyPairAlgorithm | algorithm} to use.
3364
+ * @param extractable - Whether the resulting keys may be exported.
3365
+ * @returns `Success` with the generated `CryptoKeyPair`, or `Failure` with an error.
3366
+ */
3367
+ generateKeyPair(algorithm: KeyPairAlgorithm, extractable: boolean): Promise<Result<CryptoKeyPair>>;
3368
+ /**
3369
+ * Exports a public `CryptoKey` as a JSON Web Key.
3370
+ * @remarks
3371
+ * Rejects non-public keys at runtime. WebCrypto's `exportKey('jwk', ...)`
3372
+ * does not enforce public-vs-private; without this guard a caller that
3373
+ * passed an extractable private key would receive its private fields
3374
+ * (`d`, `p`, `q`, ...) as JWK, defeating the method's name.
3375
+ * @param publicKey - Extractable public key to export.
3376
+ * @returns `Success` with the JWK, or `Failure` if not a public key or if export fails.
3377
+ */
3378
+ exportPublicKeyJwk(publicKey: CryptoKey): Promise<Result<JsonWebKey>>;
3379
+ /**
3380
+ * Imports a public-key JWK as a `CryptoKey` for the requested algorithm.
3381
+ * @param jwk - The JSON Web Key produced by a prior export.
3382
+ * @param algorithm - The algorithm the key was generated for.
3383
+ * @returns `Success` with the imported public `CryptoKey`, or `Failure` with an error.
3384
+ */
3385
+ importPublicKeyJwk(jwk: JsonWebKey, algorithm: KeyPairAlgorithm): Promise<Result<CryptoKey>>;
3386
+ /**
3387
+ * Wraps `plaintext` for the holder of `recipientPublicKey` using
3388
+ * ECIES (ECDH P-256 + HKDF-SHA256 + AES-GCM-256). See
3389
+ * {@link CryptoUtils.ICryptoProvider.wrapBytes | ICryptoProvider.wrapBytes}.
3390
+ * @param plaintext - The bytes to wrap.
3391
+ * @param recipientPublicKey - The recipient's ECDH P-256 public `CryptoKey`.
3392
+ * @param options - HKDF salt and info; see {@link CryptoUtils.IWrapBytesOptions | IWrapBytesOptions}.
3393
+ * @returns `Success` with the wrapped payload, or `Failure` with an error.
3394
+ */
3395
+ wrapBytes(plaintext: Uint8Array, recipientPublicKey: CryptoKey, options: IWrapBytesOptions): Promise<Result<IWrappedBytes>>;
3396
+ /**
3397
+ * Unwraps a payload produced by `wrapBytes` using the recipient's private
3398
+ * key. See {@link CryptoUtils.ICryptoProvider.unwrapBytes | ICryptoProvider.unwrapBytes}.
3399
+ * @param wrapped - The wrapped payload.
3400
+ * @param recipientPrivateKey - The recipient's ECDH P-256 private `CryptoKey`.
3401
+ * @param options - HKDF salt and info matching the wrap call.
3402
+ * @returns `Success` with the original `plaintext`, or `Failure` with an error.
3403
+ */
3404
+ unwrapBytes(wrapped: IWrappedBytes, recipientPrivateKey: CryptoKey, options: IWrapBytesOptions): Promise<Result<Uint8Array>>;
1992
3405
  }
1993
3406
 
1994
3407
  /**
@@ -2218,6 +3631,22 @@ export { RecordJar }
2218
3631
  */
2219
3632
  declare function resolveEffectiveTools(descriptor: IAiProviderDescriptor, settingsTools?: ReadonlyArray<IAiToolEnablement>, perCallTools?: ReadonlyArray<AiServerToolConfig>): ReadonlyArray<AiServerToolConfig>;
2220
3633
 
3634
+ /**
3635
+ * Resolve the image-generation capability that applies to a given model id
3636
+ * for a provider. Returns the entry from
3637
+ * {@link IAiProviderDescriptor.imageGeneration} whose `modelPrefix` is the
3638
+ * longest prefix of `modelId`. Ties are broken by first-encountered, so rule
3639
+ * order does not matter for correctness — only for tie-breaking among rules
3640
+ * with identical-length prefixes (an unusual case).
3641
+ *
3642
+ * @param descriptor - The provider descriptor
3643
+ * @param modelId - The resolved image model id
3644
+ * @returns The matching capability, or `undefined` when no rule matches or
3645
+ * the provider declares no image-generation capabilities.
3646
+ * @public
3647
+ */
3648
+ declare function resolveImageCapability(descriptor: IAiProviderDescriptor, modelId: string): IAiImageModelCapability | undefined;
3649
+
2221
3650
  /**
2222
3651
  * Resolves a {@link ModelSpec} to a concrete model string given an optional context key.
2223
3652
  *
@@ -2241,6 +3670,16 @@ declare function resolveModel(spec: ModelSpec, context?: string): string;
2241
3670
  */
2242
3671
  declare type SecretProvider = (secretName: string) => Promise<Result<Uint8Array>>;
2243
3672
 
3673
+ /**
3674
+ * Whether a provider declares any image-generation capability at all.
3675
+ *
3676
+ * @param descriptor - The provider descriptor
3677
+ * @returns `true` when {@link IAiProviderDescriptor.imageGeneration} has at
3678
+ * least one entry; `false` otherwise.
3679
+ * @public
3680
+ */
3681
+ declare function supportsImageGeneration(descriptor: IAiProviderDescriptor): boolean;
3682
+
2244
3683
  /**
2245
3684
  * Helper function to create a `StringConverter` which converts
2246
3685
  * `unknown` to `string`, applying template conversions supplied at construction time or at
@@ -2261,6 +3700,14 @@ declare function templateString(defaultContext?: unknown): Conversion.StringConv
2261
3700
  */
2262
3701
  declare function toBase64(bytes: Uint8Array): string;
2263
3702
 
3703
+ /**
3704
+ * Formats an {@link IAiImageData} as a `data:` URL suitable for browser display.
3705
+ * @param image - The image to format
3706
+ * @returns A `data:<mime>;base64,<data>` URL string
3707
+ * @public
3708
+ */
3709
+ declare function toDataUrl(image: IAiImageData): string;
3710
+
2264
3711
  /**
2265
3712
  * Attempts to parse and decrypt a JSON object as an {@link CryptoUtils.IEncryptedFile | encrypted file}.
2266
3713
  * @typeParam TPayload - Expected type of decrypted content
@@ -2283,7 +3730,9 @@ declare const uint8ArrayFromBase64: Converter<Uint8Array>;
2283
3730
 
2284
3731
  declare namespace Yaml {
2285
3732
  export {
2286
- yamlConverter
3733
+ yamlConverter,
3734
+ yamlStringify,
3735
+ IYamlSerializeOptions
2287
3736
  }
2288
3737
  }
2289
3738
  export { Yaml }
@@ -2296,6 +3745,15 @@ export { Yaml }
2296
3745
  */
2297
3746
  declare function yamlConverter<T>(converter: Converter<T>): Converter<T>;
2298
3747
 
3748
+ /**
3749
+ * Serializes a value to a YAML string.
3750
+ * @param value - The value to serialize (must be an object or array)
3751
+ * @param options - Optional serialization options
3752
+ * @returns `Success` with YAML string, or `Failure` with error
3753
+ * @public
3754
+ */
3755
+ declare function yamlStringify(value: unknown, options?: IYamlSerializeOptions): Result<string>;
3756
+
2299
3757
  /**
2300
3758
  * Supported compression levels for zip files.
2301
3759
  * @public
@@ -2449,8 +3907,8 @@ declare class ZipFileTreeAccessors<TCT extends string = string> implements FileT
2449
3907
  private constructor();
2450
3908
  /**
2451
3909
  * Default function to infer the content type of a file.
2452
- * @param filePath - The path of the file.
2453
- * @param provided - Optional supplied content type.
3910
+ * @param __filePath - The path of the file.
3911
+ * @param __provided - Optional supplied content type.
2454
3912
  * @returns `Success` with the content type of the file if successful, or
2455
3913
  * `Failure` with an error message otherwise.
2456
3914
  * @remarks This default implementation always returns `Success` with `undefined`.