@marinoscar/platform-api 0.1.0-next.5 → 0.1.0-next.6

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 (241) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/ai/core/ai-error.d.ts +15 -158
  3. package/dist/ai/core/ai-error.d.ts.map +1 -1
  4. package/dist/ai/core/ai-error.js +58 -221
  5. package/dist/ai/core/ai-error.js.map +1 -1
  6. package/dist/ai/core/capabilities.d.ts +3 -126
  7. package/dist/ai/core/capabilities.d.ts.map +1 -1
  8. package/dist/ai/core/capabilities.js +13 -109
  9. package/dist/ai/core/capabilities.js.map +1 -1
  10. package/dist/ai/core/conversation.d.ts +2 -15
  11. package/dist/ai/core/conversation.d.ts.map +1 -1
  12. package/dist/ai/core/conversation.js +9 -54
  13. package/dist/ai/core/conversation.js.map +1 -1
  14. package/dist/ai/core/hosted-tools.d.ts +3 -172
  15. package/dist/ai/core/hosted-tools.d.ts.map +1 -1
  16. package/dist/ai/core/hosted-tools.js +20 -286
  17. package/dist/ai/core/hosted-tools.js.map +1 -1
  18. package/dist/ai/core/provider-adapter.interface.d.ts +3 -260
  19. package/dist/ai/core/provider-adapter.interface.d.ts.map +1 -1
  20. package/dist/ai/core/provider-adapter.interface.js +7 -29
  21. package/dist/ai/core/provider-adapter.interface.js.map +1 -1
  22. package/dist/ai/core/structured-output.d.ts +3 -49
  23. package/dist/ai/core/structured-output.d.ts.map +1 -1
  24. package/dist/ai/core/structured-output.js +9 -80
  25. package/dist/ai/core/structured-output.js.map +1 -1
  26. package/dist/ai/core/tools.d.ts +3 -93
  27. package/dist/ai/core/tools.d.ts.map +1 -1
  28. package/dist/ai/core/tools.js +9 -73
  29. package/dist/ai/core/tools.js.map +1 -1
  30. package/dist/ai/core/types/file-inputs.types.d.ts +3 -102
  31. package/dist/ai/core/types/file-inputs.types.d.ts.map +1 -1
  32. package/dist/ai/core/types/file-inputs.types.js +14 -78
  33. package/dist/ai/core/types/file-inputs.types.js.map +1 -1
  34. package/dist/ai/core/types/media.types.d.ts +3 -616
  35. package/dist/ai/core/types/media.types.d.ts.map +1 -1
  36. package/dist/ai/core/types/media.types.js +33 -203
  37. package/dist/ai/core/types/media.types.js.map +1 -1
  38. package/dist/ai/core/types/responses.types.d.ts +3 -619
  39. package/dist/ai/core/types/responses.types.d.ts.map +1 -1
  40. package/dist/ai/core/types/responses.types.js +9 -57
  41. package/dist/ai/core/types/responses.types.js.map +1 -1
  42. package/dist/ai/http/dto/ai-images.dto.d.ts +4 -4
  43. package/dist/ai/index.d.ts +1 -1
  44. package/dist/ai/index.d.ts.map +1 -1
  45. package/dist/ai/index.js +3 -3
  46. package/dist/ai/index.js.map +1 -1
  47. package/dist/ai/providers/anthropic/anthropic-client.factory.d.ts +13 -15
  48. package/dist/ai/providers/anthropic/anthropic-client.factory.d.ts.map +1 -1
  49. package/dist/ai/providers/anthropic/anthropic-client.factory.js +23 -52
  50. package/dist/ai/providers/anthropic/anthropic-client.factory.js.map +1 -1
  51. package/dist/ai/providers/anthropic/anthropic.adapter.d.ts +15 -51
  52. package/dist/ai/providers/anthropic/anthropic.adapter.d.ts.map +1 -1
  53. package/dist/ai/providers/anthropic/anthropic.adapter.js +29 -293
  54. package/dist/ai/providers/anthropic/anthropic.adapter.js.map +1 -1
  55. package/dist/ai/providers/azure-openai/azure-openai-client.factory.d.ts +10 -14
  56. package/dist/ai/providers/azure-openai/azure-openai-client.factory.d.ts.map +1 -1
  57. package/dist/ai/providers/azure-openai/azure-openai-client.factory.js +20 -53
  58. package/dist/ai/providers/azure-openai/azure-openai-client.factory.js.map +1 -1
  59. package/dist/ai/providers/azure-openai/azure-openai.adapter.d.ts +14 -31
  60. package/dist/ai/providers/azure-openai/azure-openai.adapter.d.ts.map +1 -1
  61. package/dist/ai/providers/azure-openai/azure-openai.adapter.js +25 -170
  62. package/dist/ai/providers/azure-openai/azure-openai.adapter.js.map +1 -1
  63. package/dist/ai/providers/gemini/gemini-client.factory.d.ts +13 -18
  64. package/dist/ai/providers/gemini/gemini-client.factory.d.ts.map +1 -1
  65. package/dist/ai/providers/gemini/gemini-client.factory.js +24 -68
  66. package/dist/ai/providers/gemini/gemini-client.factory.js.map +1 -1
  67. package/dist/ai/providers/gemini/gemini.adapter.d.ts +15 -58
  68. package/dist/ai/providers/gemini/gemini.adapter.d.ts.map +1 -1
  69. package/dist/ai/providers/gemini/gemini.adapter.js +29 -348
  70. package/dist/ai/providers/gemini/gemini.adapter.js.map +1 -1
  71. package/dist/ai/providers/openai/openai-client.factory.d.ts +13 -35
  72. package/dist/ai/providers/openai/openai-client.factory.d.ts.map +1 -1
  73. package/dist/ai/providers/openai/openai-client.factory.js +25 -64
  74. package/dist/ai/providers/openai/openai-client.factory.js.map +1 -1
  75. package/dist/ai/providers/openai/openai.adapter.d.ts +15 -48
  76. package/dist/ai/providers/openai/openai.adapter.d.ts.map +1 -1
  77. package/dist/ai/providers/openai/openai.adapter.js +27 -206
  78. package/dist/ai/providers/openai/openai.adapter.js.map +1 -1
  79. package/dist/ai/providers/openai-compatible/openai-compatible-client.factory.d.ts +11 -11
  80. package/dist/ai/providers/openai-compatible/openai-compatible-client.factory.d.ts.map +1 -1
  81. package/dist/ai/providers/openai-compatible/openai-compatible-client.factory.js +18 -41
  82. package/dist/ai/providers/openai-compatible/openai-compatible-client.factory.js.map +1 -1
  83. package/dist/ai/providers/openai-compatible/openai-compatible.adapter.d.ts +14 -32
  84. package/dist/ai/providers/openai-compatible/openai-compatible.adapter.d.ts.map +1 -1
  85. package/dist/ai/providers/openai-compatible/openai-compatible.adapter.js +25 -149
  86. package/dist/ai/providers/openai-compatible/openai-compatible.adapter.js.map +1 -1
  87. package/dist/ai/providers/platform-ai-tracer.d.ts +4 -0
  88. package/dist/ai/providers/platform-ai-tracer.d.ts.map +1 -0
  89. package/dist/ai/providers/platform-ai-tracer.js +20 -0
  90. package/dist/ai/providers/platform-ai-tracer.js.map +1 -0
  91. package/dist/ai/runtime/ai-image-run-request.d.ts +1 -1
  92. package/dist/ai/testing/conformance/ai-no-sdk-leak.suite.d.ts +28 -5
  93. package/dist/ai/testing/conformance/ai-no-sdk-leak.suite.d.ts.map +1 -1
  94. package/dist/ai/testing/conformance/ai-no-sdk-leak.suite.js +54 -9
  95. package/dist/ai/testing/conformance/ai-no-sdk-leak.suite.js.map +1 -1
  96. package/dist/ai/testing/index.d.ts +1 -1
  97. package/dist/ai/testing/index.d.ts.map +1 -1
  98. package/dist/ai/testing/index.js +2 -1
  99. package/dist/ai/testing/index.js.map +1 -1
  100. package/dist/jobs/rate-limit.error.d.ts +2 -26
  101. package/dist/jobs/rate-limit.error.d.ts.map +1 -1
  102. package/dist/jobs/rate-limit.error.js +4 -52
  103. package/dist/jobs/rate-limit.error.js.map +1 -1
  104. package/dist/storage/config/storage-config.controller.d.ts +1 -1
  105. package/package.json +3 -2
  106. package/dist/ai/providers/anthropic/anthropic-errors.d.ts +0 -16
  107. package/dist/ai/providers/anthropic/anthropic-errors.d.ts.map +0 -1
  108. package/dist/ai/providers/anthropic/anthropic-errors.js +0 -156
  109. package/dist/ai/providers/anthropic/anthropic-errors.js.map +0 -1
  110. package/dist/ai/providers/anthropic/anthropic-messages.mapper.d.ts +0 -80
  111. package/dist/ai/providers/anthropic/anthropic-messages.mapper.d.ts.map +0 -1
  112. package/dist/ai/providers/anthropic/anthropic-messages.mapper.js +0 -536
  113. package/dist/ai/providers/anthropic/anthropic-messages.mapper.js.map +0 -1
  114. package/dist/ai/providers/anthropic/anthropic-model-catalog.d.ts +0 -49
  115. package/dist/ai/providers/anthropic/anthropic-model-catalog.d.ts.map +0 -1
  116. package/dist/ai/providers/anthropic/anthropic-model-catalog.js +0 -198
  117. package/dist/ai/providers/anthropic/anthropic-model-catalog.js.map +0 -1
  118. package/dist/ai/providers/anthropic/anthropic-stream.mapper.d.ts +0 -35
  119. package/dist/ai/providers/anthropic/anthropic-stream.mapper.d.ts.map +0 -1
  120. package/dist/ai/providers/anthropic/anthropic-stream.mapper.js +0 -203
  121. package/dist/ai/providers/anthropic/anthropic-stream.mapper.js.map +0 -1
  122. package/dist/ai/providers/anthropic/testing/anthropic-fixtures.d.ts +0 -18
  123. package/dist/ai/providers/anthropic/testing/anthropic-fixtures.d.ts.map +0 -1
  124. package/dist/ai/providers/anthropic/testing/anthropic-fixtures.js +0 -120
  125. package/dist/ai/providers/anthropic/testing/anthropic-fixtures.js.map +0 -1
  126. package/dist/ai/providers/anthropic/testing/anthropic-mock-transport.d.ts +0 -59
  127. package/dist/ai/providers/anthropic/testing/anthropic-mock-transport.d.ts.map +0 -1
  128. package/dist/ai/providers/anthropic/testing/anthropic-mock-transport.js +0 -206
  129. package/dist/ai/providers/anthropic/testing/anthropic-mock-transport.js.map +0 -1
  130. package/dist/ai/providers/azure-openai/azure-openai-settings.d.ts +0 -23
  131. package/dist/ai/providers/azure-openai/azure-openai-settings.d.ts.map +0 -1
  132. package/dist/ai/providers/azure-openai/azure-openai-settings.js +0 -54
  133. package/dist/ai/providers/azure-openai/azure-openai-settings.js.map +0 -1
  134. package/dist/ai/providers/gemini/gemini-content.mapper.d.ts +0 -98
  135. package/dist/ai/providers/gemini/gemini-content.mapper.d.ts.map +0 -1
  136. package/dist/ai/providers/gemini/gemini-content.mapper.js +0 -665
  137. package/dist/ai/providers/gemini/gemini-content.mapper.js.map +0 -1
  138. package/dist/ai/providers/gemini/gemini-embeddings.mapper.d.ts +0 -13
  139. package/dist/ai/providers/gemini/gemini-embeddings.mapper.d.ts.map +0 -1
  140. package/dist/ai/providers/gemini/gemini-embeddings.mapper.js +0 -78
  141. package/dist/ai/providers/gemini/gemini-embeddings.mapper.js.map +0 -1
  142. package/dist/ai/providers/gemini/gemini-errors.d.ts +0 -32
  143. package/dist/ai/providers/gemini/gemini-errors.d.ts.map +0 -1
  144. package/dist/ai/providers/gemini/gemini-errors.js +0 -191
  145. package/dist/ai/providers/gemini/gemini-errors.js.map +0 -1
  146. package/dist/ai/providers/gemini/gemini-model-catalog.d.ts +0 -45
  147. package/dist/ai/providers/gemini/gemini-model-catalog.d.ts.map +0 -1
  148. package/dist/ai/providers/gemini/gemini-model-catalog.js +0 -264
  149. package/dist/ai/providers/gemini/gemini-model-catalog.js.map +0 -1
  150. package/dist/ai/providers/gemini/gemini-stream.mapper.d.ts +0 -31
  151. package/dist/ai/providers/gemini/gemini-stream.mapper.d.ts.map +0 -1
  152. package/dist/ai/providers/gemini/gemini-stream.mapper.js +0 -118
  153. package/dist/ai/providers/gemini/gemini-stream.mapper.js.map +0 -1
  154. package/dist/ai/providers/gemini/testing/gemini-fixtures.d.ts +0 -80
  155. package/dist/ai/providers/gemini/testing/gemini-fixtures.d.ts.map +0 -1
  156. package/dist/ai/providers/gemini/testing/gemini-fixtures.js +0 -118
  157. package/dist/ai/providers/gemini/testing/gemini-fixtures.js.map +0 -1
  158. package/dist/ai/providers/gemini/testing/gemini-mock-transport.d.ts +0 -82
  159. package/dist/ai/providers/gemini/testing/gemini-mock-transport.d.ts.map +0 -1
  160. package/dist/ai/providers/gemini/testing/gemini-mock-transport.js +0 -342
  161. package/dist/ai/providers/gemini/testing/gemini-mock-transport.js.map +0 -1
  162. package/dist/ai/providers/openai/openai-audio.mapper.d.ts +0 -42
  163. package/dist/ai/providers/openai/openai-audio.mapper.d.ts.map +0 -1
  164. package/dist/ai/providers/openai/openai-audio.mapper.js +0 -266
  165. package/dist/ai/providers/openai/openai-audio.mapper.js.map +0 -1
  166. package/dist/ai/providers/openai/openai-call-telemetry.d.ts +0 -25
  167. package/dist/ai/providers/openai/openai-call-telemetry.d.ts.map +0 -1
  168. package/dist/ai/providers/openai/openai-call-telemetry.js +0 -93
  169. package/dist/ai/providers/openai/openai-call-telemetry.js.map +0 -1
  170. package/dist/ai/providers/openai/openai-chat-completions-stream.mapper.d.ts +0 -41
  171. package/dist/ai/providers/openai/openai-chat-completions-stream.mapper.d.ts.map +0 -1
  172. package/dist/ai/providers/openai/openai-chat-completions-stream.mapper.js +0 -173
  173. package/dist/ai/providers/openai/openai-chat-completions-stream.mapper.js.map +0 -1
  174. package/dist/ai/providers/openai/openai-chat-completions.engine.d.ts +0 -33
  175. package/dist/ai/providers/openai/openai-chat-completions.engine.d.ts.map +0 -1
  176. package/dist/ai/providers/openai/openai-chat-completions.engine.js +0 -165
  177. package/dist/ai/providers/openai/openai-chat-completions.engine.js.map +0 -1
  178. package/dist/ai/providers/openai/openai-chat-completions.mapper.d.ts +0 -42
  179. package/dist/ai/providers/openai/openai-chat-completions.mapper.d.ts.map +0 -1
  180. package/dist/ai/providers/openai/openai-chat-completions.mapper.js +0 -304
  181. package/dist/ai/providers/openai/openai-chat-completions.mapper.js.map +0 -1
  182. package/dist/ai/providers/openai/openai-embeddings.mapper.d.ts +0 -25
  183. package/dist/ai/providers/openai/openai-embeddings.mapper.d.ts.map +0 -1
  184. package/dist/ai/providers/openai/openai-embeddings.mapper.js +0 -81
  185. package/dist/ai/providers/openai/openai-embeddings.mapper.js.map +0 -1
  186. package/dist/ai/providers/openai/openai-errors.d.ts +0 -45
  187. package/dist/ai/providers/openai/openai-errors.d.ts.map +0 -1
  188. package/dist/ai/providers/openai/openai-errors.js +0 -247
  189. package/dist/ai/providers/openai/openai-errors.js.map +0 -1
  190. package/dist/ai/providers/openai/openai-family-guards.d.ts +0 -4
  191. package/dist/ai/providers/openai/openai-family-guards.d.ts.map +0 -1
  192. package/dist/ai/providers/openai/openai-family-guards.js +0 -19
  193. package/dist/ai/providers/openai/openai-family-guards.js.map +0 -1
  194. package/dist/ai/providers/openai/openai-images.mapper.d.ts +0 -23
  195. package/dist/ai/providers/openai/openai-images.mapper.d.ts.map +0 -1
  196. package/dist/ai/providers/openai/openai-images.mapper.js +0 -164
  197. package/dist/ai/providers/openai/openai-images.mapper.js.map +0 -1
  198. package/dist/ai/providers/openai/openai-model-catalog.d.ts +0 -36
  199. package/dist/ai/providers/openai/openai-model-catalog.d.ts.map +0 -1
  200. package/dist/ai/providers/openai/openai-model-catalog.js +0 -209
  201. package/dist/ai/providers/openai/openai-model-catalog.js.map +0 -1
  202. package/dist/ai/providers/openai/openai-realtime.mapper.d.ts +0 -18
  203. package/dist/ai/providers/openai/openai-realtime.mapper.d.ts.map +0 -1
  204. package/dist/ai/providers/openai/openai-realtime.mapper.js +0 -159
  205. package/dist/ai/providers/openai/openai-realtime.mapper.js.map +0 -1
  206. package/dist/ai/providers/openai/openai-redirect-guard.d.ts +0 -9
  207. package/dist/ai/providers/openai/openai-redirect-guard.d.ts.map +0 -1
  208. package/dist/ai/providers/openai/openai-redirect-guard.js +0 -61
  209. package/dist/ai/providers/openai/openai-redirect-guard.js.map +0 -1
  210. package/dist/ai/providers/openai/openai-responses.engine.d.ts +0 -50
  211. package/dist/ai/providers/openai/openai-responses.engine.d.ts.map +0 -1
  212. package/dist/ai/providers/openai/openai-responses.engine.js +0 -206
  213. package/dist/ai/providers/openai/openai-responses.engine.js.map +0 -1
  214. package/dist/ai/providers/openai/openai-responses.mapper.d.ts +0 -64
  215. package/dist/ai/providers/openai/openai-responses.mapper.d.ts.map +0 -1
  216. package/dist/ai/providers/openai/openai-responses.mapper.js +0 -580
  217. package/dist/ai/providers/openai/openai-responses.mapper.js.map +0 -1
  218. package/dist/ai/providers/openai/openai-stream.mapper.d.ts +0 -28
  219. package/dist/ai/providers/openai/openai-stream.mapper.d.ts.map +0 -1
  220. package/dist/ai/providers/openai/openai-stream.mapper.js +0 -139
  221. package/dist/ai/providers/openai/openai-stream.mapper.js.map +0 -1
  222. package/dist/ai/providers/openai/testing/chat-completions-fixtures.d.ts +0 -24
  223. package/dist/ai/providers/openai/testing/chat-completions-fixtures.d.ts.map +0 -1
  224. package/dist/ai/providers/openai/testing/chat-completions-fixtures.js +0 -72
  225. package/dist/ai/providers/openai/testing/chat-completions-fixtures.js.map +0 -1
  226. package/dist/ai/providers/openai/testing/conformance-responders.d.ts +0 -7
  227. package/dist/ai/providers/openai/testing/conformance-responders.d.ts.map +0 -1
  228. package/dist/ai/providers/openai/testing/conformance-responders.js +0 -64
  229. package/dist/ai/providers/openai/testing/conformance-responders.js.map +0 -1
  230. package/dist/ai/providers/openai/testing/openai-fixtures.d.ts +0 -52
  231. package/dist/ai/providers/openai/testing/openai-fixtures.d.ts.map +0 -1
  232. package/dist/ai/providers/openai/testing/openai-fixtures.js +0 -208
  233. package/dist/ai/providers/openai/testing/openai-fixtures.js.map +0 -1
  234. package/dist/ai/providers/openai/testing/openai-mock-transport.d.ts +0 -242
  235. package/dist/ai/providers/openai/testing/openai-mock-transport.d.ts.map +0 -1
  236. package/dist/ai/providers/openai/testing/openai-mock-transport.js +0 -523
  237. package/dist/ai/providers/openai/testing/openai-mock-transport.js.map +0 -1
  238. package/dist/ai/providers/openai-compatible/openai-compatible-settings.d.ts +0 -13
  239. package/dist/ai/providers/openai-compatible/openai-compatible-settings.d.ts.map +0 -1
  240. package/dist/ai/providers/openai-compatible/openai-compatible-settings.js +0 -29
  241. package/dist/ai/providers/openai-compatible/openai-compatible-settings.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @marinoscar/platform-api
2
2
 
3
+ ## 0.1.0-next.6
4
+
5
+ ### Minor Changes
6
+
7
+ - e1ca08c: New package `@marinoscar/platform-ai-providers` (#991): the five AI provider adapters (OpenAI, OpenAI-compatible, Azure OpenAI, Anthropic, Gemini) and the provider-agnostic core they implement, runnable in a plain Node process (no Nest, no database, no OpenTelemetry SDK). Subpaths: `.` (core types, `AiProviderAdapter` and its ports, `AiError` and its codes, capabilities, structured output, tools, hosted tools, conversation helpers, media and file-input types, `parseRetryAfterMs`, and the structural `AiLogger` and `AiTracer` ports), `./openai`, `./anthropic`, `./gemini`, and `./<provider>/testing` (mock transports and fixtures). `zod` is a required peer; each SDK is an optional peer loaded only by its subpath. Each adapter is built with `create*Adapter({ clients?, logger?, tracer? })`; without a tracer no span is started. API: `@marinoscar/platform-api/ai` keeps every exported name and type: it re-exports the core, its provider classes are now Nest subclasses of the lean adapters and client factories (same constructors, injection tokens, logger names and `ai.provider.call` spans), and `AiError` is still an `HttpException` with `toRateLimitError()` (the platform splices `HttpException` into its prototype chain when `ai/core/ai-error` loads). `parseRetryAfterMs` moved to the new package and `@marinoscar/platform-api/jobs` re-exports it. The `ai-no-sdk-leak` suite gains `aiProvidersPackageSdkDirs` and accepts a list of `sdkOwner` manifests; the platform package's own provider folders now import no SDK. Back-compat: no route, shape, id or behaviour changes; the platform package still depends on the three SDKs so an app gets them installed.
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [e1ca08c]
12
+ - @marinoscar/platform-ai-providers@0.1.0-next.6
13
+ - @marinoscar/platform-contract@0.1.0-next.6
14
+
3
15
  ## 0.1.0-next.5
4
16
 
5
17
  ### Patch Changes
@@ -1,161 +1,18 @@
1
1
  import { HttpException } from '@nestjs/common';
2
- import { CLASSIFY_RATE_LIMIT, RateLimitError, type RateLimitClassification, type SelfClassifyingRateLimit } from '../../jobs/index';
3
- /**
4
- * Every AI error code and the HTTP status it answers with. The codes are
5
- * permanent API strings: clients switch on `details.reason`.
6
- *
7
- * @stability experimental
8
- */
9
- export declare const AI_ERROR_STATUS: {
10
- /** AI is switched off (for the deployment, or for the caller's organization). */
11
- readonly AI_DISABLED: 403;
12
- /** The provider is switched off, or not registered. */
13
- readonly AI_PROVIDER_DISABLED: 403;
14
- /** No key may pay for this call (the policy needs the caller's own key). */
15
- readonly AI_KEY_REQUIRED: 403;
16
- /** The provider rejected the key. */
17
- readonly AI_KEY_INVALID: 400;
18
- /** An administrator has not enabled the model. */
19
- readonly AI_MODEL_NOT_ENABLED: 403;
20
- /** The key that would pay cannot reach the model. */
21
- readonly AI_MODEL_NOT_REACHABLE: 403;
22
- /** The request needs a capability the model or provider lacks. */
23
- readonly AI_CAPABILITY_UNSUPPORTED: 400;
24
- /** A hosted tool type an administrator has not switched on, or an MCP host outside the allowlist (#442). */
25
- readonly AI_TOOL_DISABLED: 403;
26
- /** Realtime voice sessions are switched off (`ai.defaults.allowRealtime`, #449). */
27
- readonly AI_REALTIME_DISABLED: 403;
28
- /** A deployment limit, or the provider's own rate limit, refused the call. */
29
- readonly AI_RATE_LIMITED: 429;
30
- /** The provider failed or could not be reached. */
31
- readonly AI_PROVIDER_UNAVAILABLE: 503;
32
- /** The provider's content filter refused the request or the output. */
33
- readonly AI_CONTENT_FILTERED: 422;
34
- /** The request itself is malformed. */
35
- readonly AI_INVALID_REQUEST: 400;
36
- /** The model's output did not match the requested schema. */
37
- readonly AI_STRUCTURED_OUTPUT_INVALID: 502;
38
- /** Object storage is not configured (or not usable) for this operation. */
39
- readonly AI_STORAGE_UNAVAILABLE: 503;
40
- };
41
- /**
42
- * One AI error code (a key of {@link AI_ERROR_STATUS}).
43
- *
44
- * @stability experimental
45
- */
46
- export type AiErrorCode = keyof typeof AI_ERROR_STATUS;
47
- /**
48
- * Every code, in declaration order.
49
- *
50
- * @stability experimental
51
- */
52
- export declare const AI_ERROR_CODES: AiErrorCode[];
53
- /**
54
- * Type guard for a string that arrived from somewhere untyped.
55
- *
56
- * @stability experimental
57
- */
58
- export declare function isAiErrorCode(value: unknown): value is AiErrorCode;
59
- /**
60
- * What an {@link AiError} may carry besides its code and message.
61
- *
62
- * @stability experimental
63
- */
64
- export interface AiErrorOptions {
65
- /** Provider-requested delay before retrying, when it named one. */
66
- retryAfterMs?: number;
67
- /** The underlying error. Kept for debugging, never serialised. */
68
- cause?: unknown;
69
- /** Extra machine-readable context. Must not contain secret material. */
70
- details?: Record<string, unknown>;
2
+ import { RateLimitError, type SelfClassifyingRateLimit } from '../../jobs/index';
3
+ declare module '@marinoscar/platform-ai-providers' {
4
+ interface AiError extends HttpException, SelfClassifyingRateLimit {
5
+ /**
6
+ * The queue's rate-limit signal for this error, or `null` when this
7
+ * error is not a rate limit. A job handler does
8
+ * `throw err.toRateLimitError() ?? err;` so a provider throttle defers
9
+ * the job instead of charging an attempt.
10
+ *
11
+ * @returns a `RateLimitError` for `AI_RATE_LIMITED`, otherwise `null`.
12
+ */
13
+ toRateLimitError(): RateLimitError | null;
14
+ }
71
15
  }
72
- /**
73
- * The body an {@link AiError} throws (wrapped by the exception filter in the
74
- * standard envelope).
75
- *
76
- * @stability experimental
77
- */
78
- export interface AiErrorBody {
79
- /** The AI error code. */
80
- code: AiErrorCode;
81
- /** A message safe to show. */
82
- message: string;
83
- /** Machine-readable context; `reason` is always the code. */
84
- details: Record<string, unknown> & {
85
- /** The AI error code, where clients read it. */
86
- reason: AiErrorCode;
87
- /** The provider-requested back-off, when it named one. */
88
- retryAfterMs?: number;
89
- };
90
- }
91
- /**
92
- * The one error the AI platform throws: an `HttpException` whose status
93
- * follows the code ({@link AI_ERROR_STATUS}) and whose body carries the code
94
- * in `details.reason`. Never carries key material; `cause` is never
95
- * serialised.
96
- *
97
- * @stability experimental
98
- */
99
- export declare class AiError extends HttpException implements SelfClassifyingRateLimit {
100
- /** The AI error code. */
101
- readonly code: AiErrorCode;
102
- /** The provider-requested back-off, when it named one. */
103
- readonly retryAfterMs?: number;
104
- readonly cause: unknown;
105
- constructor(code: AiErrorCode, message: string, opts?: AiErrorOptions);
106
- /** The public body, and nothing else — no `cause`, no stack. */
107
- toJSON(): AiErrorBody;
108
- /**
109
- * The queue's rate-limit signal for this error, or `null` when this error
110
- * is not a rate limit. A job handler does
111
- * `throw err.toRateLimitError() ?? err;` so a provider throttle defers the
112
- * job instead of charging an attempt.
113
- */
114
- toRateLimitError(): RateLimitError | null;
115
- /**
116
- * How the job queue's `classifyRateLimit` reads this error (issue #509):
117
- * a rate limit iff the CODE says so — `AI_RATE_LIMITED`, the same rule as
118
- * `toRateLimitError()` — and never by `.status`. That status is the HTTP
119
- * response status this platform assigned to the code (503 for
120
- * `AI_STORAGE_UNAVAILABLE` and `AI_PROVIDER_UNAVAILABLE`), not a
121
- * provider's capacity signal, so without this a thrown `AiError` 503 was
122
- * deferred as a throttle instead of failing or charging an attempt.
123
- *
124
- * A symbol-keyed prototype method: non-enumerable, so it never reaches
125
- * `toJSON()`, the exception filter's body, or a structured log line.
126
- */
127
- [CLASSIFY_RATE_LIMIT](): RateLimitClassification;
128
- /**
129
- * Type guard.
130
- *
131
- * @param value - anything caught.
132
- * @returns whether it is an `AiError`.
133
- */
134
- static isAiError(value: unknown): value is AiError;
135
- /**
136
- * Returns `err` unchanged when it is already an `AiError`, otherwise a new
137
- * `AiError(code)` with `err` as its (non-serialised) cause. The message is
138
- * generic ON PURPOSE — an SDK's own message may echo request details.
139
- */
140
- static wrap(err: unknown, code?: AiErrorCode, message?: string): AiError;
141
- }
142
- /**
143
- * The provider metadata in an `AiError`'s `details` that is safe to log —
144
- * the HTTP status and the provider's own short error code, type, offending
145
- * parameter and request id — and nothing else: never a URL or
146
- * key material. For `AI_INVALID_REQUEST` only, the cause's message is appended
147
- * as `providerMessage` (log-only, never in `details`), with key-like tokens,
148
- * Bearer credentials and URLs redacted. Fields an error does not carry are
149
- * left out; string values are capped and quoted so no provider string can
150
- * forge a log line.
151
- *
152
- * @stability experimental
153
- */
154
- export declare const AI_ERROR_LOG_DETAIL_KEYS: readonly ["status", "providerCode", "providerType", "param", "providerRequestId"];
155
- /**
156
- * `status=400 providerCode="…" … providerMessage="…"` for `error`, or `''` when it carries none of the safe fields.
157
- *
158
- * @stability experimental
159
- */
160
- export declare function aiErrorLogDetails(error: AiError): string;
16
+ export { AI_ERROR_CODES, AI_ERROR_LOG_DETAIL_KEYS, AI_ERROR_STATUS, AiError, aiErrorLogDetails, isAiErrorCode, } from '@marinoscar/platform-ai-providers';
17
+ export type { AiErrorBody, AiErrorCode, AiErrorOptions } from '@marinoscar/platform-ai-providers';
161
18
  //# sourceMappingURL=ai-error.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ai-error.d.ts","sourceRoot":"","sources":["../../../src/ai/core/ai-error.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,KAAK,uBAAuB,EAC5B,KAA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Ac,EAAE,MAAM,mCAAmC,CAAC"}
@@ -1,233 +1,70 @@
1
1
  "use strict";
2
2
  // =============================================================================
3
- // AI error taxonomy (issue #424, epic #419)
3
+ // AiError: the platform integration (issue #991; taxonomy #424, epic #419)
4
4
  // =============================================================================
5
5
  //
6
- // Every failure an AI caller can see is one of these codes. Adapters map their
7
- // SDK's errors onto them (an SDK error never escapes an adapter), and the
8
- // runtime gates (#431) raise them directly.
6
+ // The error taxonomy (`AI_ERROR_STATUS`, `AiError`, `aiErrorLogDetails`, ...)
7
+ // moved to `@marinoscar/platform-ai-providers`, where `AiError` extends plain
8
+ // `Error` so the adapters run without Nest. Inside the platform it must stay
9
+ // what it always was: a Nest `HttpException` (the global
10
+ // `HttpExceptionFilter` and Nest's own handlers test `instanceof
11
+ // HttpException`) with `toRateLimitError()` for job handlers. This module
12
+ // restores both, ONCE, when it is first loaded:
9
13
  //
10
- // The HTTP status is part of the code's definition rather than a choice made
11
- // at each throw site, so the same condition cannot surface as a 400 from one
12
- // endpoint and a 403 from another.
14
+ // 1. `HttpException.prototype` is spliced into `AiError`'s prototype chain
15
+ // (and `HttpException` into the static side), so `new AiError(...)
16
+ // instanceof HttpException` holds. The lean class already carries every
17
+ // member `HttpException`'s constructor would have set (`response`,
18
+ // `status`, `options`, `message`, `name`, in that order) and its own
19
+ // `getResponse()`/`getStatus()`, so the filter reads the same body and
20
+ // status as before. Its `[CLASSIFY_RATE_LIMIT]` method is keyed by the
21
+ // registered `Symbol.for('jobs.classifyRateLimit')`, the very symbol
22
+ // `jobs/` exports, so `classifyRateLimit` already believes it.
23
+ // 2. `toRateLimitError()` is added to the prototype, returning the queue's
24
+ // `RateLimitError` for `AI_RATE_LIMITED` and `null` otherwise.
25
+ // 3. A module augmentation gives the type the same two facts, so
26
+ // platform code (and `@marinoscar/platform-api/ai` consumers) still see
27
+ // an `AiError` that extends `HttpException` and has
28
+ // `toRateLimitError(): RateLimitError | null`.
29
+ //
30
+ // Every platform file that uses `AiError` reaches it through this module:
31
+ // the `ai/core/*` re-export shims import it for its side effect, and the
32
+ // provider wrappers import it directly, so the patch has always run before
33
+ // a platform code path can construct or catch an `AiError`.
13
34
  // =============================================================================
14
35
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.AI_ERROR_LOG_DETAIL_KEYS = exports.AiError = exports.AI_ERROR_CODES = exports.AI_ERROR_STATUS = void 0;
16
- exports.isAiErrorCode = isAiErrorCode;
17
- exports.aiErrorLogDetails = aiErrorLogDetails;
36
+ exports.isAiErrorCode = exports.aiErrorLogDetails = exports.AiError = exports.AI_ERROR_STATUS = exports.AI_ERROR_LOG_DETAIL_KEYS = exports.AI_ERROR_CODES = void 0;
18
37
  const common_1 = require("@nestjs/common");
38
+ const platform_ai_providers_1 = require("@marinoscar/platform-ai-providers");
19
39
  const index_1 = require("../../jobs/index");
20
- /**
21
- * Every AI error code and the HTTP status it answers with. The codes are
22
- * permanent API strings: clients switch on `details.reason`.
23
- *
24
- * @stability experimental
25
- */
26
- exports.AI_ERROR_STATUS = {
27
- /** AI is switched off (for the deployment, or for the caller's organization). */
28
- AI_DISABLED: 403,
29
- /** The provider is switched off, or not registered. */
30
- AI_PROVIDER_DISABLED: 403,
31
- /** No key may pay for this call (the policy needs the caller's own key). */
32
- AI_KEY_REQUIRED: 403,
33
- /** The provider rejected the key. */
34
- AI_KEY_INVALID: 400,
35
- /** An administrator has not enabled the model. */
36
- AI_MODEL_NOT_ENABLED: 403,
37
- /** The key that would pay cannot reach the model. */
38
- AI_MODEL_NOT_REACHABLE: 403,
39
- /** The request needs a capability the model or provider lacks. */
40
- AI_CAPABILITY_UNSUPPORTED: 400,
41
- /** A hosted tool type an administrator has not switched on, or an MCP host outside the allowlist (#442). */
42
- AI_TOOL_DISABLED: 403,
43
- /** Realtime voice sessions are switched off (`ai.defaults.allowRealtime`, #449). */
44
- AI_REALTIME_DISABLED: 403,
45
- /** A deployment limit, or the provider's own rate limit, refused the call. */
46
- AI_RATE_LIMITED: 429,
47
- /** The provider failed or could not be reached. */
48
- AI_PROVIDER_UNAVAILABLE: 503,
49
- /** The provider's content filter refused the request or the output. */
50
- AI_CONTENT_FILTERED: 422,
51
- /** The request itself is malformed. */
52
- AI_INVALID_REQUEST: 400,
53
- /** The model's output did not match the requested schema. */
54
- AI_STRUCTURED_OUTPUT_INVALID: 502,
55
- /** Object storage is not configured (or not usable) for this operation. */
56
- // Object storage is not configured (or not usable) for an operation whose
57
- // inputs or outputs are storage objects — image generation (#437) and the
58
- // media stories after it. An administrator fixes it at
59
- // `/admin/settings/storage`; the request itself was fine.
60
- AI_STORAGE_UNAVAILABLE: 503,
61
- };
62
- /**
63
- * Every code, in declaration order.
64
- *
65
- * @stability experimental
66
- */
67
- exports.AI_ERROR_CODES = Object.keys(exports.AI_ERROR_STATUS);
68
- /**
69
- * Type guard for a string that arrived from somewhere untyped.
70
- *
71
- * @stability experimental
72
- */
73
- function isAiErrorCode(value) {
74
- return typeof value === 'string' && Object.prototype.hasOwnProperty.call(exports.AI_ERROR_STATUS, value);
75
- }
76
- /**
77
- * The one error the AI platform throws: an `HttpException` whose status
78
- * follows the code ({@link AI_ERROR_STATUS}) and whose body carries the code
79
- * in `details.reason`. Never carries key material; `cause` is never
80
- * serialised.
81
- *
82
- * @stability experimental
83
- */
84
- class AiError extends common_1.HttpException {
85
- /** The AI error code. */
86
- code;
87
- /** The provider-requested back-off, when it named one. */
88
- retryAfterMs;
89
- constructor(code, message, opts = {}) {
90
- const details = {
91
- ...(opts.details ?? {}),
92
- // `reason` is written LAST so a caller-supplied `details.reason` can
93
- // never make the body disagree with `code`.
94
- reason: code,
95
- };
96
- if (opts.retryAfterMs !== undefined) {
97
- details.retryAfterMs = opts.retryAfterMs;
98
- }
99
- const body = { code, message, details };
100
- // No `options` argument: HttpException would copy `cause` onto two
101
- // enumerable properties (`options.cause` and `cause`). See header.
102
- super(body, exports.AI_ERROR_STATUS[code]);
103
- this.code = code;
104
- if (opts.retryAfterMs !== undefined) {
105
- this.retryAfterMs = opts.retryAfterMs;
106
- }
107
- Object.defineProperty(this, 'cause', {
108
- value: opts.cause,
109
- enumerable: false,
110
- writable: false,
111
- configurable: true,
112
- });
113
- // Keep `instanceof AiError` working however the class is downlevelled —
114
- // see the same line in `jobs/rate-limit.error.ts` for why it matters.
115
- Object.setPrototypeOf(this, AiError.prototype);
116
- }
117
- /** The public body, and nothing else — no `cause`, no stack. */
118
- toJSON() {
119
- return this.getResponse();
120
- }
121
- /**
122
- * The queue's rate-limit signal for this error, or `null` when this error
123
- * is not a rate limit. A job handler does
124
- * `throw err.toRateLimitError() ?? err;` so a provider throttle defers the
125
- * job instead of charging an attempt.
126
- */
127
- toRateLimitError() {
128
- if (this.code !== 'AI_RATE_LIMITED') {
129
- return null;
130
- }
131
- return new index_1.RateLimitError(this.message, this.retryAfterMs);
132
- }
133
- /**
134
- * How the job queue's `classifyRateLimit` reads this error (issue #509):
135
- * a rate limit iff the CODE says so — `AI_RATE_LIMITED`, the same rule as
136
- * `toRateLimitError()` — and never by `.status`. That status is the HTTP
137
- * response status this platform assigned to the code (503 for
138
- * `AI_STORAGE_UNAVAILABLE` and `AI_PROVIDER_UNAVAILABLE`), not a
139
- * provider's capacity signal, so without this a thrown `AiError` 503 was
140
- * deferred as a throttle instead of failing or charging an attempt.
141
- *
142
- * A symbol-keyed prototype method: non-enumerable, so it never reaches
143
- * `toJSON()`, the exception filter's body, or a structured log line.
144
- */
145
- [index_1.CLASSIFY_RATE_LIMIT]() {
146
- return this.code === 'AI_RATE_LIMITED'
147
- ? { rateLimited: true, retryAfterMs: this.retryAfterMs ?? null }
148
- : { rateLimited: false, retryAfterMs: null };
149
- }
150
- /**
151
- * Type guard.
152
- *
153
- * @param value - anything caught.
154
- * @returns whether it is an `AiError`.
155
- */
156
- static isAiError(value) {
157
- return value instanceof AiError;
158
- }
159
- /**
160
- * Returns `err` unchanged when it is already an `AiError`, otherwise a new
161
- * `AiError(code)` with `err` as its (non-serialised) cause. The message is
162
- * generic ON PURPOSE — an SDK's own message may echo request details.
163
- */
164
- static wrap(err, code = 'AI_PROVIDER_UNAVAILABLE', message = 'The AI provider request failed.') {
165
- if (err instanceof AiError) {
166
- return err;
167
- }
168
- return new AiError(code, message, { cause: err });
169
- }
170
- }
171
- exports.AiError = AiError;
172
- /**
173
- * The provider metadata in an `AiError`'s `details` that is safe to log —
174
- * the HTTP status and the provider's own short error code, type, offending
175
- * parameter and request id — and nothing else: never a URL or
176
- * key material. For `AI_INVALID_REQUEST` only, the cause's message is appended
177
- * as `providerMessage` (log-only, never in `details`), with key-like tokens,
178
- * Bearer credentials and URLs redacted. Fields an error does not carry are
179
- * left out; string values are capped and quoted so no provider string can
180
- * forge a log line.
181
- *
182
- * @stability experimental
183
- */
184
- exports.AI_ERROR_LOG_DETAIL_KEYS = ['status', 'providerCode', 'providerType', 'param', 'providerRequestId'];
185
- const AI_ERROR_LOG_VALUE_MAX = 120;
186
- const AI_ERROR_LOG_MESSAGE_MAX = 300;
187
- const AI_ERROR_LOG_REDACTIONS = [
188
- /\b(sk|rk|pk|sess)-[A-Za-z0-9_\-*]{6,}/g,
189
- /Bearer\s+\S+/gi,
190
- /https?:\/\/\S+/gi,
191
- ];
192
- /**
193
- * The provider's own message for a rejected request (the one field that says
194
- * WHY a 400 happened), redacted, whitespace-collapsed and capped; `null` when
195
- * the cause carries none.
196
- */
197
- function providerMessageForLog(cause) {
198
- if (!(cause instanceof Error) || typeof cause.message !== 'string' || cause.message.length === 0) {
199
- return null;
200
- }
201
- let message = cause.message;
202
- for (const pattern of AI_ERROR_LOG_REDACTIONS) {
203
- message = message.replace(pattern, '[redacted]');
204
- }
205
- message = message.replace(/\s+/g, ' ').trim().slice(0, AI_ERROR_LOG_MESSAGE_MAX);
206
- return message.length > 0 ? message : null;
207
- }
208
- /**
209
- * `status=400 providerCode="…" … providerMessage="…"` for `error`, or `''` when it carries none of the safe fields.
210
- *
211
- * @stability experimental
212
- */
213
- function aiErrorLogDetails(error) {
214
- const details = error.getResponse().details ?? {};
215
- const parts = [];
216
- for (const key of exports.AI_ERROR_LOG_DETAIL_KEYS) {
217
- const value = details[key];
218
- if (typeof value === 'number' && Number.isFinite(value)) {
219
- parts.push(`${key}=${value}`);
220
- }
221
- else if (typeof value === 'string' && value.length > 0) {
222
- parts.push(`${key}=${JSON.stringify(value.slice(0, AI_ERROR_LOG_VALUE_MAX))}`);
223
- }
224
- }
225
- if (error.code === 'AI_INVALID_REQUEST') {
226
- const providerMessage = providerMessageForLog(error.cause);
227
- if (providerMessage !== null) {
228
- parts.push(`providerMessage=${JSON.stringify(providerMessage)}`);
229
- }
40
+ /** True once this module has patched the class (it is evaluated once per module instance). */
41
+ const PATCHED = Symbol.for('platform-api.ai.AiErrorHttpException');
42
+ if (!platform_ai_providers_1.AiError[PATCHED]) {
43
+ Object.setPrototypeOf(platform_ai_providers_1.AiError.prototype, common_1.HttpException.prototype);
44
+ Object.setPrototypeOf(platform_ai_providers_1.AiError, common_1.HttpException);
45
+ Object.defineProperty(platform_ai_providers_1.AiError.prototype, 'toRateLimitError', {
46
+ value: function toRateLimitError() {
47
+ if (this.code !== 'AI_RATE_LIMITED') {
48
+ return null;
49
+ }
50
+ return new index_1.RateLimitError(this.message, this.retryAfterMs);
51
+ },
52
+ enumerable: false,
53
+ writable: true,
54
+ configurable: true,
55
+ });
56
+ // The lean class keys its classifier by `Symbol.for('jobs.classifyRateLimit')`;
57
+ // fail loudly at load time if the queue ever changes the symbol.
58
+ if (typeof platform_ai_providers_1.AiError.prototype[index_1.CLASSIFY_RATE_LIMIT] !== 'function') {
59
+ throw new Error('AiError does not implement the job queue CLASSIFY_RATE_LIMIT contract.');
230
60
  }
231
- return parts.join(' ');
61
+ Object.defineProperty(platform_ai_providers_1.AiError, PATCHED, { value: true });
232
62
  }
63
+ var platform_ai_providers_2 = require("@marinoscar/platform-ai-providers");
64
+ Object.defineProperty(exports, "AI_ERROR_CODES", { enumerable: true, get: function () { return platform_ai_providers_2.AI_ERROR_CODES; } });
65
+ Object.defineProperty(exports, "AI_ERROR_LOG_DETAIL_KEYS", { enumerable: true, get: function () { return platform_ai_providers_2.AI_ERROR_LOG_DETAIL_KEYS; } });
66
+ Object.defineProperty(exports, "AI_ERROR_STATUS", { enumerable: true, get: function () { return platform_ai_providers_2.AI_ERROR_STATUS; } });
67
+ Object.defineProperty(exports, "AiError", { enumerable: true, get: function () { return platform_ai_providers_2.AiError; } });
68
+ Object.defineProperty(exports, "aiErrorLogDetails", { enumerable: true, get: function () { return platform_ai_providers_2.aiErrorLogDetails; } });
69
+ Object.defineProperty(exports, "isAiErrorCode", { enumerable: true, get: function () { return platform_ai_providers_2.isAiErrorCode; } });
233
70
  //# sourceMappingURL=ai-error.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ai-error.js","sourceRoot":"","sources":["../../../src/ai/core/ai-error.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,4CAA4C;AAC5C,gFAAgF;AAChF,EAAE;AACF,+EAA+E;AAC/E,0EAA0E;AAC1E,4CAA4C;AAC5C,EAAE;AACF,6EAA6E;AAC7E,6EAA6E;AAC7E,mCAAmC;AACnC,gFAAgF;;;AAyEhF,sCAEC;AAqOD,8CAuBC;AArUD,2CAA+C;AAE/C,4CAK0B;AAE1B;;;;;GAKG;AACU,QAAA,eAAe,GAAG;IAC7B,iFAAiF;IACjF,WAAW,EAAE,GAAG;IAChB,uDAAuD;IACvD,oBAAoB,EAAE,GAAG;IACzB,4EAA4E;IAC5E,eAAe,EAAE,GAAG;IACpB,qCAAqC;IACrC,cAAc,EAAE,GAAG;IACnB,kDAAkD;IAClD,oBAAoB,EAAE,GAAG;IACzB,qDAAqD;IACrD,sBAAsB,EAAE,GAAG;IAC3B,kEAAkE;IAClE,yBAAyB,EAAE,GAAG;IAC9B,4GAA4G;IAC5G,gBAAgB,EAAE,GAAG;IACrB,oFAAoF;IACpF,oBAAoB,EAAE,GAAG;IACzB,8EAA8E;IAC9E,eAAe,EAAE,GAAG;IACpB,mDAAmD;IACnD,uB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AANzC,uHAAA,cAAc,OAAA;AACd,iIAAA,wBAAwB,OAAA;AACxB,wHAAA,eAAe,OAAA;AACf,gHAAA,OAAO,OAAA;AACP,0HAAA,iBAAiB,OAAA;AACjB,sHAAA,aAAa,OAAA"}
@@ -1,127 +1,4 @@
1
- import { z } from 'zod';
2
- /**
3
- * The capabilities the platform ships. Permanent strings: they are stored in
4
- * the catalog table and in administrator overrides, so renaming one is a data
5
- * migration, not a refactor. The vocabulary is OPEN (PP-14.17, #935): an app
6
- * or package adds its own with `registerAiCapability`; this tuple is only the
7
- * built-in part, which registers itself through that same function
8
- * (`./capability-registry.ts`).
9
- *
10
- * @stability experimental
11
- */
12
- export declare const BUILTIN_AI_CAPABILITIES: readonly ["responses", "reasoning", "tools", "hosted_tools", "structured_output", "streaming", "vision_input", "file_input", "image_generation", "image_edit", "audio_transcription", "audio_speech", "embeddings", "realtime"];
13
- /**
14
- * The capabilities the platform ships.
15
- *
16
- * @deprecated Use {@link BUILTIN_AI_CAPABILITIES}. The list is no longer the
17
- * set of capabilities a deployment knows (PP-14.17, #935); ask
18
- * `listAiCapabilities()` or `GET /api/admin/ai/capabilities`. Kept as an
19
- * alias for one release.
20
- * @stability experimental
21
- */
22
- export declare const AI_CAPABILITIES: readonly ["responses", "reasoning", "tools", "hosted_tools", "structured_output", "streaming", "vision_input", "file_input", "image_generation", "image_edit", "audio_transcription", "audio_speech", "embeddings", "realtime"];
23
- /**
24
- * One of {@link BUILTIN_AI_CAPABILITIES}.
25
- *
26
- * @stability experimental
27
- */
28
- export type BuiltinAiCapability = (typeof BUILTIN_AI_CAPABILITIES)[number];
29
- /**
30
- * A capability id: a built-in one (autocompleted) or any string an app or
31
- * package registered with `registerAiCapability`. See
32
- * `AI_CAPABILITY_ID_PATTERN`.
33
- *
34
- * @stability experimental
35
- */
36
- export type AiCapability = BuiltinAiCapability | (string & {});
37
- /**
38
- * What a model can read.
39
- *
40
- * @stability experimental
41
- */
42
- export declare const AI_INPUT_MODALITIES: readonly ["text", "image", "audio", "file"];
43
- /**
44
- * What a model can produce.
45
- *
46
- * @stability experimental
47
- */
48
- export declare const AI_OUTPUT_MODALITIES: readonly ["text", "image", "audio", "embedding"];
49
- /**
50
- * How hard a reasoning model may be asked to think.
51
- *
52
- * @stability experimental
53
- */
54
- export declare const AI_REASONING_EFFORTS: readonly ["minimal", "low", "medium", "high"];
55
- /**
56
- * One of {@link AI_INPUT_MODALITIES}.
57
- *
58
- * @stability experimental
59
- */
60
- export type AiInputModality = (typeof AI_INPUT_MODALITIES)[number];
61
- /**
62
- * One of {@link AI_OUTPUT_MODALITIES}.
63
- *
64
- * @stability experimental
65
- */
66
- export type AiOutputModality = (typeof AI_OUTPUT_MODALITIES)[number];
67
- /**
68
- * One of {@link AI_REASONING_EFFORTS}.
69
- *
70
- * @stability experimental
71
- */
72
- export type AiReasoningEffort = (typeof AI_REASONING_EFFORTS)[number];
73
- /**
74
- * The entries of the built-in capability enum (`z.enum(BUILTIN_AI_CAPABILITIES)`).
75
- *
76
- * @stability experimental
77
- */
78
- export type AiCapabilityEnum = {
79
- [K in BuiltinAiCapability]: K;
80
- };
81
- /**
82
- * The entries of the input-modality enum.
83
- *
84
- * @stability experimental
85
- */
86
- export type AiInputModalityEnum = {
87
- [K in AiInputModality]: K;
88
- };
89
- /**
90
- * The entries of the output-modality enum.
91
- *
92
- * @stability experimental
93
- */
94
- export type AiOutputModalityEnum = {
95
- [K in AiOutputModality]: K;
96
- };
97
- /**
98
- * The entries of the reasoning-effort enum.
99
- *
100
- * @stability experimental
101
- */
102
- export type AiReasoningEffortEnum = {
103
- [K in AiReasoningEffort]: K;
104
- };
105
- /**
106
- * What one model can do. Validated with this schema wherever it crosses a
107
- * trust boundary (an adapter's classifier output, an administrator override,
108
- * a JSONB column read back from the database).
109
- *
110
- * @stability experimental
111
- */
112
- export declare const aiModelCapabilitiesSchema: z.ZodObject<{
113
- capabilities: z.ZodArray<z.ZodString>;
114
- inputModalities: z.ZodArray<z.ZodEnum<AiInputModalityEnum>>;
115
- outputModalities: z.ZodArray<z.ZodEnum<AiOutputModalityEnum>>;
116
- reasoningEfforts: z.ZodOptional<z.ZodArray<z.ZodEnum<AiReasoningEffortEnum>>>;
117
- contextWindow: z.ZodOptional<z.ZodNumber>;
118
- maxOutputTokens: z.ZodOptional<z.ZodNumber>;
119
- voices: z.ZodOptional<z.ZodArray<z.ZodString>>;
120
- }, z.core.$strip>;
121
- /**
122
- * What one model can do (`aiModelCapabilitiesSchema`'s output).
123
- *
124
- * @stability experimental
125
- */
126
- export type AiModelCapabilities = z.infer<typeof aiModelCapabilitiesSchema>;
1
+ import './ai-error';
2
+ export { AI_CAPABILITIES, AI_INPUT_MODALITIES, AI_OUTPUT_MODALITIES, AI_REASONING_EFFORTS, aiModelCapabilitiesSchema, BUILTIN_AI_CAPABILITIES, } from '@marinoscar/platform-ai-providers';
3
+ export type { AiCapability, AiCapabilityEnum, AiInputModality, AiInputModalityEnum, AiModelCapabilities, AiOutputModality, AiOutputModalityEnum, AiReasoningEffort, AiReasoningEffortEnum, BuiltinAiCapability, } from '@marinoscar/platform-ai-providers';
127
4
  //# sourceMappingURL=capabilities.d.ts.map