@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
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Helper for resolving a request's effective base URL from a provider
3
+ * descriptor and an optional caller-supplied endpoint override.
4
+ *
5
+ * @packageDocumentation
6
+ */
7
+ import { Result } from '@fgv/ts-utils';
8
+ import { type IAiProviderDescriptor } from './model';
9
+ /**
10
+ * Builds an OpenAI-style `Authorization: Bearer ${key}` header, or an empty
11
+ * record when the key is empty. Self-hosted/local OpenAI-compatible servers
12
+ * (Ollama, LM Studio, llama.cpp) often reject `Authorization: Bearer ` with
13
+ * an empty key, so we omit the header entirely in that case.
14
+ *
15
+ * @internal
16
+ */
17
+ export declare function bearerAuthHeader(apiKey: string): Record<string, string>;
18
+ /**
19
+ * Resolves the effective base URL for a request, validating the optional
20
+ * `endpoint` override when present. Returns the URL with any trailing slash
21
+ * stripped so per-route suffix concatenation (e.g. `/chat/completions`)
22
+ * produces the same shape regardless of whether the caller supplied an
23
+ * override or the descriptor's default is used.
24
+ *
25
+ * @internal
26
+ */
27
+ export declare function resolveEffectiveBaseUrl(descriptor: IAiProviderDescriptor, endpoint?: string): Result<string>;
28
+ //# sourceMappingURL=endpoint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endpoint.d.ts","sourceRoot":"","sources":["../../../src/packlets/ai-assist/endpoint.ts"],"names":[],"mappings":"AAoBA;;;;;GAKG;AAEH,OAAO,EAAQ,MAAM,EAAW,MAAM,eAAe,CAAC;AAEtD,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAErD;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAEvE;AAED;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,qBAAqB,EACjC,QAAQ,CAAC,EAAE,MAAM,GAChB,MAAM,CAAC,MAAM,CAAC,CA+BhB"}
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ // Copyright (c) 2026 Erik Fortune
3
+ //
4
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ // of this software and associated documentation files (the "Software"), to deal
6
+ // in the Software without restriction, including without limitation the rights
7
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ // copies of the Software, and to permit persons to whom the Software is
9
+ // furnished to do so, subject to the following conditions:
10
+ //
11
+ // The above copyright notice and this permission notice shall be included in all
12
+ // copies or substantial portions of the Software.
13
+ //
14
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ // SOFTWARE.
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.bearerAuthHeader = bearerAuthHeader;
23
+ exports.resolveEffectiveBaseUrl = resolveEffectiveBaseUrl;
24
+ /**
25
+ * Helper for resolving a request's effective base URL from a provider
26
+ * descriptor and an optional caller-supplied endpoint override.
27
+ *
28
+ * @packageDocumentation
29
+ */
30
+ const ts_utils_1 = require("@fgv/ts-utils");
31
+ /**
32
+ * Builds an OpenAI-style `Authorization: Bearer ${key}` header, or an empty
33
+ * record when the key is empty. Self-hosted/local OpenAI-compatible servers
34
+ * (Ollama, LM Studio, llama.cpp) often reject `Authorization: Bearer ` with
35
+ * an empty key, so we omit the header entirely in that case.
36
+ *
37
+ * @internal
38
+ */
39
+ function bearerAuthHeader(apiKey) {
40
+ return apiKey.length > 0 ? { Authorization: `Bearer ${apiKey}` } : {};
41
+ }
42
+ /**
43
+ * Resolves the effective base URL for a request, validating the optional
44
+ * `endpoint` override when present. Returns the URL with any trailing slash
45
+ * stripped so per-route suffix concatenation (e.g. `/chat/completions`)
46
+ * produces the same shape regardless of whether the caller supplied an
47
+ * override or the descriptor's default is used.
48
+ *
49
+ * @internal
50
+ */
51
+ function resolveEffectiveBaseUrl(descriptor, endpoint) {
52
+ if (endpoint === undefined) {
53
+ if (!descriptor.baseUrl) {
54
+ return (0, ts_utils_1.fail)(`provider "${descriptor.id}" has no API endpoint configured`);
55
+ }
56
+ return (0, ts_utils_1.succeed)(descriptor.baseUrl.replace(/\/+$/, ''));
57
+ }
58
+ if (typeof endpoint !== 'string' || endpoint.length === 0) {
59
+ return (0, ts_utils_1.fail)(`provider "${descriptor.id}": endpoint must be a non-empty http(s) URL`);
60
+ }
61
+ let parsed;
62
+ try {
63
+ parsed = new URL(endpoint);
64
+ }
65
+ catch (_a) {
66
+ return (0, ts_utils_1.fail)(`provider "${descriptor.id}": endpoint is not a valid URL`);
67
+ }
68
+ if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
69
+ return (0, ts_utils_1.fail)(`provider "${descriptor.id}": endpoint must use http or https (got ${parsed.protocol})`);
70
+ }
71
+ if (parsed.search.length > 0 || parsed.hash.length > 0) {
72
+ return (0, ts_utils_1.fail)(`provider "${descriptor.id}": endpoint must not include a query string or fragment`);
73
+ }
74
+ if (parsed.username.length > 0 || parsed.password.length > 0) {
75
+ return (0, ts_utils_1.fail)(`provider "${descriptor.id}": endpoint must not include userinfo; pass credentials via apiKey instead`);
76
+ }
77
+ // Reconstruct from origin + pathname so the returned URL is normalized
78
+ // (no userinfo, no query, no fragment) and the suffix concat in callers
79
+ // produces a well-formed request URL.
80
+ return (0, ts_utils_1.succeed)(`${parsed.origin}${parsed.pathname}`.replace(/\/+$/, ''));
81
+ }
82
+ //# sourceMappingURL=endpoint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endpoint.js","sourceRoot":"","sources":["../../../src/packlets/ai-assist/endpoint.ts"],"names":[],"mappings":";AAAA,kCAAkC;AAClC,EAAE;AACF,+EAA+E;AAC/E,gF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D,IAAI,MAAM,CAAC,QAAQ,KAAK,OAAO,IAAI,MAAM,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAChE,OAAO,IAAA,eAAI,EAAC,aAAa,UAAU,CAAC,EAAE,2CAA2C,MAAM,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvG,CAAC;IACD,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvD,OAAO,IAAA,eAAI,EAAC,aAAa,UAAU,CAAC,EAAE,yDAAyD,CAAC,CAAC;IACnG,CAAC;IACD,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC7D,OAAO,IAAA,eAAI,EACT,aAAa,UAAU,CAAC,EAAE,4EAA4E,CACvG,CAAC;IACJ,CAAC;IACD,uEAAuE;IACvE,wEAAwE;IACxE,sCAAsC;IACtC,OAAO,IAAA,kBAAO,EAAC,GAAG,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3E,CAAC","sourcesContent":["// Copyright (c) 2026 Erik Fortune\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in all\n// copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n// SOFTWARE.\n\n/**\n * Helper for resolving a request's effective base URL from a provider\n * descriptor and an optional caller-supplied endpoint override.\n *\n * @packageDocumentation\n */\n\nimport { fail, Result, succeed } from '@fgv/ts-utils';\n\nimport { type IAiProviderDescriptor } from './model';\n\n/**\n * Builds an OpenAI-style `Authorization: Bearer ${key}` header, or an empty\n * record when the key is empty. Self-hosted/local OpenAI-compatible servers\n * (Ollama, LM Studio, llama.cpp) often reject `Authorization: Bearer ` with\n * an empty key, so we omit the header entirely in that case.\n *\n * @internal\n */\nexport function bearerAuthHeader(apiKey: string): Record<string, string> {\n return apiKey.length > 0 ? { Authorization: `Bearer ${apiKey}` } : {};\n}\n\n/**\n * Resolves the effective base URL for a request, validating the optional\n * `endpoint` override when present. Returns the URL with any trailing slash\n * stripped so per-route suffix concatenation (e.g. `/chat/completions`)\n * produces the same shape regardless of whether the caller supplied an\n * override or the descriptor's default is used.\n *\n * @internal\n */\nexport function resolveEffectiveBaseUrl(\n descriptor: IAiProviderDescriptor,\n endpoint?: string\n): Result<string> {\n if (endpoint === undefined) {\n if (!descriptor.baseUrl) {\n return fail(`provider \"${descriptor.id}\" has no API endpoint configured`);\n }\n return succeed(descriptor.baseUrl.replace(/\\/+$/, ''));\n }\n if (typeof endpoint !== 'string' || endpoint.length === 0) {\n return fail(`provider \"${descriptor.id}\": endpoint must be a non-empty http(s) URL`);\n }\n let parsed: URL;\n try {\n parsed = new URL(endpoint);\n } catch {\n return fail(`provider \"${descriptor.id}\": endpoint is not a valid URL`);\n }\n if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {\n return fail(`provider \"${descriptor.id}\": endpoint must use http or https (got ${parsed.protocol})`);\n }\n if (parsed.search.length > 0 || parsed.hash.length > 0) {\n return fail(`provider \"${descriptor.id}\": endpoint must not include a query string or fragment`);\n }\n if (parsed.username.length > 0 || parsed.password.length > 0) {\n return fail(\n `provider \"${descriptor.id}\": endpoint must not include userinfo; pass credentials via apiKey instead`\n );\n }\n // Reconstruct from origin + pathname so the returned URL is normalized\n // (no userinfo, no query, no fragment) and the suffix concat in callers\n // produces a well-formed request URL.\n return succeed(`${parsed.origin}${parsed.pathname}`.replace(/\\/+$/, ''));\n}\n"]}
@@ -2,9 +2,10 @@
2
2
  * AI assist packlet - provider registry, prompt class, settings, and API client.
3
3
  * @packageDocumentation
4
4
  */
5
- export { AiPrompt, type AiProviderId, type AiServerToolType, type AiServerToolConfig, type IAiWebSearchToolConfig, type IAiToolEnablement, type IAiCompletionResponse, type IChatMessage, type AiApiFormat, type IAiProviderDescriptor, type IAiAssistProviderConfig, type IAiAssistSettings, DEFAULT_AI_ASSIST, type IAiAssistKeyStore, type ModelSpec, type ModelSpecKey, type IModelSpecMap, allModelSpecKeys, MODEL_SPEC_BASE_KEY, resolveModel } from './model';
6
- export { allProviderIds, getProviderDescriptors, getProviderDescriptor } from './registry';
7
- export { callProviderCompletion, callProxiedCompletion, type IProviderCompletionParams } from './apiClient';
5
+ export { AiPrompt, type AiModelCapability, type AiProviderId, type AiServerToolType, type AiServerToolConfig, type IAiWebSearchToolConfig, type IAiToolEnablement, type IAiCompletionResponse, type IChatMessage, type AiApiFormat, type AiImageApiFormat, type IAiImageModelCapability, type IAiProviderDescriptor, type IAiAssistProviderConfig, type IAiAssistSettings, DEFAULT_AI_ASSIST, type IAiAssistKeyStore, type IAiImageAttachment, type IAiImageData, type IAiImageGenerationOptions, type IAiImageGenerationParams, type IAiGeneratedImage, type IAiImageGenerationResponse, type IAiModelCapabilityRule, type IAiModelCapabilityConfig, type IAiModelInfo, type IAiStreamEvent, type IAiStreamTextDelta, type IAiStreamToolEvent, type IAiStreamDone, type IAiStreamError, type ModelSpec, type ModelSpecKey, type IModelSpecMap, allModelSpecKeys, MODEL_SPEC_BASE_KEY, resolveModel, toDataUrl } from './model';
6
+ export { allProviderIds, getProviderDescriptors, getProviderDescriptor, resolveImageCapability, supportsImageGeneration, DEFAULT_MODEL_CAPABILITY_CONFIG } from './registry';
7
+ export { callProviderCompletion, callProxiedCompletion, callProviderImageGeneration, callProxiedImageGeneration, callProviderListModels, callProxiedListModels, type IProviderCompletionParams, type IProviderImageGenerationParams, type IProviderListModelsParams } from './apiClient';
8
+ export { callProviderCompletionStream, callProxiedCompletionStream, type IProviderCompletionStreamParams } from './streamingClient';
8
9
  export { aiProviderId, aiServerToolType, aiWebSearchToolConfig, aiServerToolConfig, aiToolEnablement, aiAssistProviderConfig, aiAssistSettings, modelSpecKey, modelSpec } from './converters';
9
10
  export { resolveEffectiveTools } from './toolFormats';
10
11
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/ai-assist/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,QAAQ,EACR,KAAK,iBAAiB,EACtB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,KAAK,uBAAuB,EAC5B,KAAK,iBAAiB,EACtB,iBAAiB,EACjB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,yBAAyB,EAC9B,KAAK,wBAAwB,EAC7B,KAAK,iBAAiB,EACtB,KAAK,0BAA0B,EAC/B,KAAK,sBAAsB,EAC3B,KAAK,wBAAwB,EAC7B,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,gBAAgB,EAChB,mBAAmB,EACnB,YAAY,EACZ,SAAS,EACV,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,cAAc,EACd,sBAAsB,EACtB,qBAAqB,EACrB,sBAAsB,EACtB,uBAAuB,EACvB,+BAA+B,EAChC,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,2BAA2B,EAC3B,0BAA0B,EAC1B,sBAAsB,EACtB,qBAAqB,EACrB,KAAK,yBAAyB,EAC9B,KAAK,8BAA8B,EACnC,KAAK,yBAAyB,EAC/B,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,4BAA4B,EAC5B,2BAA2B,EAC3B,KAAK,+BAA+B,EACrC,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,qBAAqB,EACrB,kBAAkB,EAClB,gBAAgB,EAChB,sBAAsB,EACtB,gBAAgB,EAChB,YAAY,EACZ,SAAS,EACV,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC"}
@@ -4,20 +4,31 @@
4
4
  * @packageDocumentation
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.resolveEffectiveTools = exports.modelSpec = exports.modelSpecKey = exports.aiAssistSettings = exports.aiAssistProviderConfig = exports.aiToolEnablement = exports.aiServerToolConfig = exports.aiWebSearchToolConfig = exports.aiServerToolType = exports.aiProviderId = exports.callProxiedCompletion = exports.callProviderCompletion = exports.getProviderDescriptor = exports.getProviderDescriptors = exports.allProviderIds = exports.resolveModel = exports.MODEL_SPEC_BASE_KEY = exports.allModelSpecKeys = exports.DEFAULT_AI_ASSIST = exports.AiPrompt = void 0;
7
+ exports.resolveEffectiveTools = exports.modelSpec = exports.modelSpecKey = exports.aiAssistSettings = exports.aiAssistProviderConfig = exports.aiToolEnablement = exports.aiServerToolConfig = exports.aiWebSearchToolConfig = exports.aiServerToolType = exports.aiProviderId = exports.callProxiedCompletionStream = exports.callProviderCompletionStream = exports.callProxiedListModels = exports.callProviderListModels = exports.callProxiedImageGeneration = exports.callProviderImageGeneration = exports.callProxiedCompletion = exports.callProviderCompletion = exports.DEFAULT_MODEL_CAPABILITY_CONFIG = exports.supportsImageGeneration = exports.resolveImageCapability = exports.getProviderDescriptor = exports.getProviderDescriptors = exports.allProviderIds = exports.toDataUrl = exports.resolveModel = exports.MODEL_SPEC_BASE_KEY = exports.allModelSpecKeys = exports.DEFAULT_AI_ASSIST = exports.AiPrompt = void 0;
8
8
  var model_1 = require("./model");
9
9
  Object.defineProperty(exports, "AiPrompt", { enumerable: true, get: function () { return model_1.AiPrompt; } });
10
10
  Object.defineProperty(exports, "DEFAULT_AI_ASSIST", { enumerable: true, get: function () { return model_1.DEFAULT_AI_ASSIST; } });
11
11
  Object.defineProperty(exports, "allModelSpecKeys", { enumerable: true, get: function () { return model_1.allModelSpecKeys; } });
12
12
  Object.defineProperty(exports, "MODEL_SPEC_BASE_KEY", { enumerable: true, get: function () { return model_1.MODEL_SPEC_BASE_KEY; } });
13
13
  Object.defineProperty(exports, "resolveModel", { enumerable: true, get: function () { return model_1.resolveModel; } });
14
+ Object.defineProperty(exports, "toDataUrl", { enumerable: true, get: function () { return model_1.toDataUrl; } });
14
15
  var registry_1 = require("./registry");
15
16
  Object.defineProperty(exports, "allProviderIds", { enumerable: true, get: function () { return registry_1.allProviderIds; } });
16
17
  Object.defineProperty(exports, "getProviderDescriptors", { enumerable: true, get: function () { return registry_1.getProviderDescriptors; } });
17
18
  Object.defineProperty(exports, "getProviderDescriptor", { enumerable: true, get: function () { return registry_1.getProviderDescriptor; } });
19
+ Object.defineProperty(exports, "resolveImageCapability", { enumerable: true, get: function () { return registry_1.resolveImageCapability; } });
20
+ Object.defineProperty(exports, "supportsImageGeneration", { enumerable: true, get: function () { return registry_1.supportsImageGeneration; } });
21
+ Object.defineProperty(exports, "DEFAULT_MODEL_CAPABILITY_CONFIG", { enumerable: true, get: function () { return registry_1.DEFAULT_MODEL_CAPABILITY_CONFIG; } });
18
22
  var apiClient_1 = require("./apiClient");
19
23
  Object.defineProperty(exports, "callProviderCompletion", { enumerable: true, get: function () { return apiClient_1.callProviderCompletion; } });
20
24
  Object.defineProperty(exports, "callProxiedCompletion", { enumerable: true, get: function () { return apiClient_1.callProxiedCompletion; } });
25
+ Object.defineProperty(exports, "callProviderImageGeneration", { enumerable: true, get: function () { return apiClient_1.callProviderImageGeneration; } });
26
+ Object.defineProperty(exports, "callProxiedImageGeneration", { enumerable: true, get: function () { return apiClient_1.callProxiedImageGeneration; } });
27
+ Object.defineProperty(exports, "callProviderListModels", { enumerable: true, get: function () { return apiClient_1.callProviderListModels; } });
28
+ Object.defineProperty(exports, "callProxiedListModels", { enumerable: true, get: function () { return apiClient_1.callProxiedListModels; } });
29
+ var streamingClient_1 = require("./streamingClient");
30
+ Object.defineProperty(exports, "callProviderCompletionStream", { enumerable: true, get: function () { return streamingClient_1.callProviderCompletionStream; } });
31
+ Object.defineProperty(exports, "callProxiedCompletionStream", { enumerable: true, get: function () { return streamingClient_1.callProxiedCompletionStream; } });
21
32
  var converters_1 = require("./converters");
22
33
  Object.defineProperty(exports, "aiProviderId", { enumerable: true, get: function () { return converters_1.aiProviderId; } });
23
34
  Object.defineProperty(exports, "aiServerToolType", { enumerable: true, get: function () { return converters_1.aiServerToolType; } });
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/ai-assist/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,iCAuCiB;AAtCf,iGAAA,QAAQ,OAAA;AAeR,0GAAA,iBAAiB,OAAA;AAmBjB,yGAAA,gBAAgB,OAAA;AAChB,4GAAA,mBAAmB,OAAA;AACnB,qGAAA,YAAY,OAAA;AACZ,kGAAA,SAAS,OAAA;AAGX,uCAOoB;AANlB,0GAAA,cAAc,OAAA;AACd,kHAAA,sBAAsB,OAAA;AACtB,iHAAA,qBAAqB,OAAA;AACrB,kHAAA,sBAAsB,OAAA;AACtB,mHAAA,uBAAuB,OAAA;AACvB,2HAAA,+BAA+B,OAAA;AAGjC,yCAUqB;AATnB,mHAAA,sBAAsB,OAAA;AACtB,kHAAA,qBAAqB,OAAA;AACrB,wHAAA,2BAA2B,OAAA;AAC3B,uHAAA,0BAA0B,OAAA;AAC1B,mHAAA,sBAAsB,OAAA;AACtB,kHAAA,qBAAqB,OAAA;AAMvB,qDAI2B;AAHzB,+HAAA,4BAA4B,OAAA;AAC5B,8HAAA,2BAA2B,OAAA;AAI7B,2CAUsB;AATpB,0GAAA,YAAY,OAAA;AACZ,8GAAA,gBAAgB,OAAA;AAChB,mHAAA,qBAAqB,OAAA;AACrB,gHAAA,kBAAkB,OAAA;AAClB,8GAAA,gBAAgB,OAAA;AAChB,oHAAA,sBAAsB,OAAA;AACtB,8GAAA,gBAAgB,OAAA;AAChB,0GAAA,YAAY,OAAA;AACZ,uGAAA,SAAS,OAAA;AAGX,6CAAsD;AAA7C,oHAAA,qBAAqB,OAAA","sourcesContent":["/**\n * AI assist packlet - provider registry, prompt class, settings, and API client.\n * @packageDocumentation\n */\n\nexport {\n AiPrompt,\n type AiModelCapability,\n type AiProviderId,\n type AiServerToolType,\n type AiServerToolConfig,\n type IAiWebSearchToolConfig,\n type IAiToolEnablement,\n type IAiCompletionResponse,\n type IChatMessage,\n type AiApiFormat,\n type AiImageApiFormat,\n type IAiImageModelCapability,\n type IAiProviderDescriptor,\n type IAiAssistProviderConfig,\n type IAiAssistSettings,\n DEFAULT_AI_ASSIST,\n type IAiAssistKeyStore,\n type IAiImageAttachment,\n type IAiImageData,\n type IAiImageGenerationOptions,\n type IAiImageGenerationParams,\n type IAiGeneratedImage,\n type IAiImageGenerationResponse,\n type IAiModelCapabilityRule,\n type IAiModelCapabilityConfig,\n type IAiModelInfo,\n type IAiStreamEvent,\n type IAiStreamTextDelta,\n type IAiStreamToolEvent,\n type IAiStreamDone,\n type IAiStreamError,\n type ModelSpec,\n type ModelSpecKey,\n type IModelSpecMap,\n allModelSpecKeys,\n MODEL_SPEC_BASE_KEY,\n resolveModel,\n toDataUrl\n} from './model';\n\nexport {\n allProviderIds,\n getProviderDescriptors,\n getProviderDescriptor,\n resolveImageCapability,\n supportsImageGeneration,\n DEFAULT_MODEL_CAPABILITY_CONFIG\n} from './registry';\n\nexport {\n callProviderCompletion,\n callProxiedCompletion,\n callProviderImageGeneration,\n callProxiedImageGeneration,\n callProviderListModels,\n callProxiedListModels,\n type IProviderCompletionParams,\n type IProviderImageGenerationParams,\n type IProviderListModelsParams\n} from './apiClient';\n\nexport {\n callProviderCompletionStream,\n callProxiedCompletionStream,\n type IProviderCompletionStreamParams\n} from './streamingClient';\n\nexport {\n aiProviderId,\n aiServerToolType,\n aiWebSearchToolConfig,\n aiServerToolConfig,\n aiToolEnablement,\n aiAssistProviderConfig,\n aiAssistSettings,\n modelSpecKey,\n modelSpec\n} from './converters';\n\nexport { resolveEffectiveTools } from './toolFormats';\n"]}
@@ -3,6 +3,49 @@
3
3
  * @packageDocumentation
4
4
  */
5
5
  import { type Result } from '@fgv/ts-utils';
6
+ /**
7
+ * Universal image representation used for both image input (vision prompts)
8
+ * and image output (generation responses).
9
+ *
10
+ * @remarks
11
+ * The base64 string is raw — no `data:` URL prefix. Use {@link AiAssist.toDataUrl} to
12
+ * format it for browser-display contexts.
13
+ *
14
+ * @public
15
+ */
16
+ export interface IAiImageData {
17
+ /** MIME type, e.g. `'image/png'`, `'image/jpeg'`, `'image/webp'`. */
18
+ readonly mimeType: string;
19
+ /** Base64-encoded image bytes (no `data:` prefix). */
20
+ readonly base64: string;
21
+ }
22
+ /**
23
+ * Formats an {@link IAiImageData} as a `data:` URL suitable for browser display.
24
+ * @param image - The image to format
25
+ * @returns A `data:<mime>;base64,<data>` URL string
26
+ * @public
27
+ */
28
+ export declare function toDataUrl(image: IAiImageData): string;
29
+ /**
30
+ * Image attachment for a vision (image-input) prompt.
31
+ *
32
+ * @remarks
33
+ * Extends {@link IAiImageData} with an OpenAI-specific `detail` hint that is
34
+ * silently ignored by Anthropic, Gemini, and other providers.
35
+ *
36
+ * @public
37
+ */
38
+ export interface IAiImageAttachment extends IAiImageData {
39
+ /**
40
+ * OpenAI vision detail hint:
41
+ * - `'low'`: faster, cheaper, lower fidelity
42
+ * - `'high'`: slower, more expensive, higher fidelity
43
+ * - `'auto'` (default): provider chooses
44
+ *
45
+ * Ignored by providers other than OpenAI.
46
+ */
47
+ readonly detail?: 'low' | 'high' | 'auto';
48
+ }
6
49
  /**
7
50
  * A structured AI prompt with system/user split for direct API calls,
8
51
  * and a lazily-constructed combined version for copy/paste workflows.
@@ -13,8 +56,18 @@ export declare class AiPrompt {
13
56
  readonly system: string;
14
57
  /** User request: the specific entity generation request. */
15
58
  readonly user: string;
16
- constructor(user: string, system: string);
17
- /** Combined single-string version (user + system joined) for copy/paste. */
59
+ /**
60
+ * Optional image attachments. When present, vision-capable providers will
61
+ * include them in the user message; non-vision providers will reject the
62
+ * call up front (see {@link AiAssist.IAiProviderDescriptor.acceptsImageInput}).
63
+ */
64
+ readonly attachments: ReadonlyArray<IAiImageAttachment>;
65
+ constructor(user: string, system: string, attachments?: ReadonlyArray<IAiImageAttachment>);
66
+ /**
67
+ * Combined single-string version (user + system joined) for copy/paste.
68
+ * When attachments are present, includes a sentinel noting they aren't
69
+ * part of the copied text.
70
+ */
18
71
  get combined(): string;
19
72
  }
20
73
  /**
@@ -133,12 +186,28 @@ export declare function resolveModel(spec: ModelSpec, context?: string): string;
133
186
  * All known AI provider identifiers.
134
187
  * @public
135
188
  */
136
- export type AiProviderId = 'copy-paste' | 'xai-grok' | 'openai' | 'anthropic' | 'google-gemini' | 'groq' | 'mistral';
189
+ export type AiProviderId = 'copy-paste' | 'xai-grok' | 'openai' | 'openai-compat' | 'anthropic' | 'google-gemini' | 'groq' | 'mistral' | 'ollama';
137
190
  /**
138
191
  * API format categories for provider routing.
139
192
  * @public
140
193
  */
141
194
  export type AiApiFormat = 'openai' | 'anthropic' | 'gemini';
195
+ /**
196
+ * API format categories for image-generation provider routing.
197
+ *
198
+ * @remarks
199
+ * - `'openai-images'` — OpenAI Images API. Routes to `/images/generations`
200
+ * (text-only) or `/images/edits` (when reference images are present).
201
+ * - `'xai-images'` — xAI Images API. Same wire shape as OpenAI but text-only;
202
+ * no reference-image support on grok-2-image.
203
+ * - `'gemini-imagen'` — Google Imagen `:predict` endpoint. Text-only.
204
+ * - `'gemini-image-out'` — Google Gemini chat-style `:generateContent`
205
+ * endpoint that returns image parts (Gemini 2.5 Flash Image / "Nano
206
+ * Banana"). Accepts reference images.
207
+ *
208
+ * @public
209
+ */
210
+ export type AiImageApiFormat = 'openai-images' | 'gemini-imagen' | 'xai-images' | 'gemini-image-out';
142
211
  /**
143
212
  * Result of an AI provider completion call.
144
213
  * @public
@@ -149,6 +218,67 @@ export interface IAiCompletionResponse {
149
218
  /** Whether the response was truncated due to token limits */
150
219
  readonly truncated: boolean;
151
220
  }
221
+ /**
222
+ * A text-content delta arriving during a streaming completion.
223
+ * @public
224
+ */
225
+ export interface IAiStreamTextDelta {
226
+ readonly type: 'text-delta';
227
+ /** The newly arrived text fragment. */
228
+ readonly delta: string;
229
+ }
230
+ /**
231
+ * A server-side tool progress event arriving during a streaming completion.
232
+ * Surfaced for providers that emit explicit tool-progress markers (OpenAI
233
+ * Responses API, Anthropic). Gemini's grounding doesn't emit these.
234
+ * @public
235
+ */
236
+ export interface IAiStreamToolEvent {
237
+ readonly type: 'tool-event';
238
+ /** Which server-side tool this event describes. */
239
+ readonly toolType: AiServerToolType;
240
+ /** Tool lifecycle phase. */
241
+ readonly phase: 'started' | 'completed';
242
+ /**
243
+ * Optional provider-specific detail. For web_search this is typically the
244
+ * search query when available; format varies by provider.
245
+ */
246
+ readonly detail?: string;
247
+ }
248
+ /**
249
+ * Terminal success event for a streaming completion. Carries the aggregated
250
+ * full text and truncation status for callers that want both the progressive
251
+ * UI and the complete result.
252
+ * @public
253
+ */
254
+ export interface IAiStreamDone {
255
+ readonly type: 'done';
256
+ /** Whether the response was truncated due to token limits. */
257
+ readonly truncated: boolean;
258
+ /** The full concatenated text from all `text-delta` events. */
259
+ readonly fullText: string;
260
+ }
261
+ /**
262
+ * Terminal failure event for a streaming completion. After this event no
263
+ * further events are emitted.
264
+ *
265
+ * @remarks
266
+ * Connection-time failures (auth, network, pre-flight CORS rejection) are
267
+ * surfaced via the outer `Result.fail` returned by
268
+ * `callProviderCompletionStream` rather than as an `error` event, so callers
269
+ * can distinguish "didn't start" from "started but errored mid-stream."
270
+ *
271
+ * @public
272
+ */
273
+ export interface IAiStreamError {
274
+ readonly type: 'error';
275
+ readonly message: string;
276
+ }
277
+ /**
278
+ * Discriminated union of events emitted by a streaming completion.
279
+ * @public
280
+ */
281
+ export type IAiStreamEvent = IAiStreamTextDelta | IAiStreamToolEvent | IAiStreamDone | IAiStreamError;
152
282
  /**
153
283
  * Describes a single AI provider — single source of truth for all metadata.
154
284
  * @public
@@ -172,6 +302,206 @@ export interface IAiProviderDescriptor {
172
302
  readonly supportedTools: ReadonlyArray<AiServerToolType>;
173
303
  /** Whether this provider's API enforces CORS restrictions that prevent direct browser calls. */
174
304
  readonly corsRestricted: boolean;
305
+ /**
306
+ * Whether this provider's streaming completion endpoint requires a proxy
307
+ * for direct browser calls. Some providers gate streaming separately from
308
+ * non-streaming (rare), so this is tracked independently from
309
+ * {@link IAiProviderDescriptor.corsRestricted}.
310
+ *
311
+ * @remarks
312
+ * When `true`, `callProviderCompletionStream` rejects up front unless the
313
+ * call is being routed through a proxy.
314
+ */
315
+ readonly streamingCorsRestricted: boolean;
316
+ /**
317
+ * Whether this provider's chat completions API accepts image input
318
+ * (i.e. supports vision prompts). When false, calls with
319
+ * `prompt.attachments` are rejected up front.
320
+ */
321
+ readonly acceptsImageInput: boolean;
322
+ /**
323
+ * Image-generation capabilities, scoped to model id prefixes. Empty or
324
+ * undefined means the provider does not support image generation.
325
+ *
326
+ * @remarks
327
+ * The dispatcher matches the resolved model id against each rule's
328
+ * `modelPrefix` and selects the longest match (see
329
+ * {@link AiAssist.resolveImageCapability}). An empty `modelPrefix` is the
330
+ * catch-all and matches every model id.
331
+ *
332
+ * Multiple entries support providers that host more than one image-API
333
+ * surface under one baseUrl. Google Gemini is the canonical case: the
334
+ * `imagen-*` family is predict-only via `:predict`, while
335
+ * `gemini-2.5-flash-image` uses chat-style `:generateContent` and accepts
336
+ * reference images. Listing both lets callers pick the right model and the
337
+ * dispatcher routes accordingly.
338
+ *
339
+ * Image-model selection reuses the existing `image` {@link ModelSpecKey}.
340
+ * Providers that declare `imageGeneration` should declare a model in
341
+ * `defaultModel.image`, e.g. `{ base: 'gpt-4o', image: 'dall-e-3' }`.
342
+ */
343
+ readonly imageGeneration?: ReadonlyArray<IAiImageModelCapability>;
344
+ }
345
+ /**
346
+ * Image-generation capability for a model family within a provider. Used as
347
+ * an entry in {@link IAiProviderDescriptor.imageGeneration}.
348
+ *
349
+ * @public
350
+ */
351
+ export interface IAiImageModelCapability {
352
+ /**
353
+ * Prefix matched against the resolved image model id. The empty string is
354
+ * the catch-all and matches every model. When multiple rules' prefixes
355
+ * match a model id, the longest prefix wins; ties are broken by
356
+ * first-encountered.
357
+ */
358
+ readonly modelPrefix: string;
359
+ /** API format used to dispatch requests for matching models. */
360
+ readonly format: AiImageApiFormat;
361
+ /**
362
+ * Whether matching models accept reference images via
363
+ * {@link AiAssist.IAiImageGenerationParams.referenceImages}. When false or
364
+ * undefined, calls that include reference images are rejected up front.
365
+ *
366
+ * @remarks
367
+ * Per-model constraints beyond ref support (e.g. dall-e-3 ignores edits)
368
+ * are not validated here and surface as provider 400s, consistent with the
369
+ * existing image-generation policy.
370
+ */
371
+ readonly acceptsImageReferenceInput?: boolean;
372
+ }
373
+ /**
374
+ * Options for image generation requests.
375
+ *
376
+ * @remarks
377
+ * Provider compatibility is documented per field. The library does not
378
+ * pre-validate against per-model constraints (e.g. `dall-e-3` rejects
379
+ * `count > 1`); provider 400 errors surface through the failure path.
380
+ *
381
+ * @public
382
+ */
383
+ export interface IAiImageGenerationOptions {
384
+ /**
385
+ * Image dimensions. Used by openai-format providers (mapped to the
386
+ * provider's `size` field). Ignored by Imagen — use
387
+ * {@link IAiImageGenerationOptions.imagen} `aspectRatio` instead.
388
+ *
389
+ * Note: each model has its own accepted set; `dall-e-3` only accepts the
390
+ * values listed here.
391
+ */
392
+ readonly size?: '1024x1024' | '1024x1792' | '1792x1024' | 'auto';
393
+ /**
394
+ * Number of images to generate. Default 1.
395
+ *
396
+ * Note: `dall-e-3` rejects `count > 1`.
397
+ */
398
+ readonly count?: number;
399
+ /** Generation quality hint where supported. */
400
+ readonly quality?: 'standard' | 'high';
401
+ /** Random seed for reproducibility, where supported. */
402
+ readonly seed?: number;
403
+ /**
404
+ * Imagen-specific options. Ignored by other providers.
405
+ */
406
+ readonly imagen?: {
407
+ readonly negativePrompt?: string;
408
+ readonly aspectRatio?: '1:1' | '3:4' | '4:3' | '9:16' | '16:9';
409
+ };
410
+ }
411
+ /**
412
+ * Parameters for an image-generation request.
413
+ * @public
414
+ */
415
+ export interface IAiImageGenerationParams {
416
+ /** The text prompt describing the desired image. */
417
+ readonly prompt: string;
418
+ /** Optional generation options. */
419
+ readonly options?: IAiImageGenerationOptions;
420
+ /**
421
+ * Optional reference images. When present, the provider will use them as
422
+ * visual context (e.g. to preserve a character's appearance across multiple
423
+ * generations). The dispatcher resolves the
424
+ * {@link AiAssist.IAiImageModelCapability} for the requested model and
425
+ * rejects the call up front if `acceptsImageReferenceInput` is not set on
426
+ * the matching capability. An empty array is treated identically to
427
+ * `undefined`.
428
+ */
429
+ readonly referenceImages?: ReadonlyArray<IAiImageAttachment>;
430
+ }
431
+ /**
432
+ * A single generated image.
433
+ * @public
434
+ */
435
+ export interface IAiGeneratedImage extends IAiImageData {
436
+ /**
437
+ * The prompt as rewritten by the provider, if any. OpenAI's image models
438
+ * commonly rewrite prompts; other providers do not.
439
+ */
440
+ readonly revisedPrompt?: string;
441
+ }
442
+ /**
443
+ * Capability vocabulary used to describe what a model can do. Used as both
444
+ * a filter and as a tag in {@link AiAssist.IAiModelInfo.capabilities}.
445
+ *
446
+ * @remarks
447
+ * Adding a new capability is cheap; adding the *first* one after consumers
448
+ * already exist forces churn. The initial vocabulary is intentionally broad
449
+ * even though only `image-generation` is fully exercised today.
450
+ *
451
+ * @public
452
+ */
453
+ export type AiModelCapability = 'chat' | 'tools' | 'vision' | 'image-generation';
454
+ /**
455
+ * Information about a single model returned by a provider's list endpoint,
456
+ * with capabilities already resolved (native + config rules).
457
+ * @public
458
+ */
459
+ export interface IAiModelInfo {
460
+ /** Provider-native model identifier. */
461
+ readonly id: string;
462
+ /** Resolved capability set — union of native declarations and config rules. */
463
+ readonly capabilities: ReadonlySet<AiModelCapability>;
464
+ /** Friendly name for display, when known. */
465
+ readonly displayName?: string;
466
+ }
467
+ /**
468
+ * One rule in an {@link IAiModelCapabilityConfig}. Multiple rules can match
469
+ * a single model — their capability arrays are unioned.
470
+ * @public
471
+ */
472
+ export interface IAiModelCapabilityRule {
473
+ /** RegExp tested against the model id (using `.test`). */
474
+ readonly idPattern: RegExp;
475
+ /** Capabilities this rule attributes to matching models. */
476
+ readonly capabilities: ReadonlyArray<AiModelCapability>;
477
+ /**
478
+ * Friendly display-name override for matching models. The function form
479
+ * lets one rule format many ids (e.g. `(id) => id.toUpperCase()`).
480
+ * If multiple matching rules supply `displayName`, the first match wins.
481
+ */
482
+ readonly displayName?: string | ((id: string) => string);
483
+ }
484
+ /**
485
+ * Configuration that maps model id patterns to capabilities. Used to
486
+ * augment (or, where the provider supplies no capability info, fully
487
+ * derive) the capability set for each listed model.
488
+ * @public
489
+ */
490
+ export interface IAiModelCapabilityConfig {
491
+ /** Per-provider rules. Tried before {@link AiAssist.IAiModelCapabilityConfig.global}. */
492
+ readonly perProvider?: {
493
+ readonly [P in AiProviderId]?: ReadonlyArray<IAiModelCapabilityRule>;
494
+ };
495
+ /** Cross-provider fallback rules. */
496
+ readonly global?: ReadonlyArray<IAiModelCapabilityRule>;
497
+ }
498
+ /**
499
+ * Result of an image-generation call.
500
+ * @public
501
+ */
502
+ export interface IAiImageGenerationResponse {
503
+ /** The generated images, in provider-returned order. */
504
+ readonly images: ReadonlyArray<IAiGeneratedImage>;
175
505
  }
176
506
  /**
177
507
  * Configuration for a single AI assist provider.
@@ -186,6 +516,14 @@ export interface IAiAssistProviderConfig {
186
516
  readonly model?: ModelSpec;
187
517
  /** Tool enablement/configuration. Tools are disabled unless explicitly enabled. */
188
518
  readonly tools?: ReadonlyArray<IAiToolEnablement>;
519
+ /**
520
+ * Optional caller-supplied endpoint URL (http/https). Overrides
521
+ * `descriptor.baseUrl` for this provider. Used to point a provider at a
522
+ * self-hosted server (Ollama, LM Studio, llama.cpp's openai-server) or a
523
+ * local proxy. Validation lives in `@fgv/ts-extras` — query strings,
524
+ * fragments, and userinfo are rejected.
525
+ */
526
+ readonly endpoint?: string;
189
527
  }
190
528
  /**
191
529
  * AI assist settings — which providers are enabled and their configuration.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/packlets/ai-assist/model.ts"],"names":[],"mappings":"AAoBA;;;GAGG;AAEH,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,eAAe,CAAC;AAM5C;;;;;;;;;GASG;AACH,MAAM,WAAW,YAAY;IAC3B,qEAAqE;IACrE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,sDAAsD;IACtD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CAErD;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,kBAAmB,SAAQ,YAAY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AG,MAAM,CAAC,MAAM,CAAC,CAAC;CACzC"}
@@ -20,7 +20,17 @@
20
20
  // SOFTWARE.
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
22
  exports.DEFAULT_AI_ASSIST = exports.MODEL_SPEC_BASE_KEY = exports.allModelSpecKeys = exports.AiPrompt = void 0;
23
+ exports.toDataUrl = toDataUrl;
23
24
  exports.resolveModel = resolveModel;
25
+ /**
26
+ * Formats an {@link IAiImageData} as a `data:` URL suitable for browser display.
27
+ * @param image - The image to format
28
+ * @returns A `data:<mime>;base64,<data>` URL string
29
+ * @public
30
+ */
31
+ function toDataUrl(image) {
32
+ return `data:${image.mimeType};base64,${image.base64}`;
33
+ }
24
34
  // ============================================================================
25
35
  // AiPrompt
26
36
  // ============================================================================
@@ -30,13 +40,21 @@ exports.resolveModel = resolveModel;
30
40
  * @public
31
41
  */
32
42
  class AiPrompt {
33
- constructor(user, system) {
43
+ constructor(user, system, attachments) {
34
44
  this.system = system;
35
45
  this.user = user;
46
+ this.attachments = attachments !== null && attachments !== void 0 ? attachments : [];
36
47
  }
37
- /** Combined single-string version (user + system joined) for copy/paste. */
48
+ /**
49
+ * Combined single-string version (user + system joined) for copy/paste.
50
+ * When attachments are present, includes a sentinel noting they aren't
51
+ * part of the copied text.
52
+ */
38
53
  get combined() {
39
- return `${this.user}\n\n${this.system}`;
54
+ const sentinel = this.attachments.length > 0
55
+ ? `\n\n[${this.attachments.length} image attachment(s) — not included in copied text]`
56
+ : '';
57
+ return `${this.user}${sentinel}\n\n${this.system}`;
40
58
  }
41
59
  }
42
60
  exports.AiPrompt = AiPrompt;