@techis/ai-runtime 0.3.0-rc.16 → 0.4.0-rc.4

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 (287) hide show
  1. package/ADAPTER-AUTHORING.md +101 -0
  2. package/ADAPTER-CONFORMANCE.md +50 -0
  3. package/ANTHROPIC-MESSAGES.md +115 -0
  4. package/API.md +275 -0
  5. package/GEMINI-INTERACTIONS.md +49 -0
  6. package/MIGRATION.md +114 -0
  7. package/MOONSHOT-CHAT.md +53 -0
  8. package/OPENAI-RESPONSES.md +62 -0
  9. package/README.md +52 -39
  10. package/THIRD_PARTY_NOTICES +34 -34
  11. package/ZAI-CHAT.md +35 -0
  12. package/dist/adapters/anthropic-capabilities.d.ts +14 -0
  13. package/dist/adapters/anthropic-capabilities.d.ts.map +1 -0
  14. package/dist/adapters/anthropic-capabilities.js +63 -0
  15. package/dist/adapters/anthropic-capabilities.js.map +1 -0
  16. package/dist/adapters/anthropic-mapping.d.ts +7 -0
  17. package/dist/adapters/anthropic-mapping.d.ts.map +1 -0
  18. package/dist/adapters/anthropic-mapping.js +370 -0
  19. package/dist/adapters/anthropic-mapping.js.map +1 -0
  20. package/dist/adapters/anthropic-stream.d.ts +16 -0
  21. package/dist/adapters/anthropic-stream.d.ts.map +1 -0
  22. package/dist/adapters/anthropic-stream.js +271 -0
  23. package/dist/adapters/anthropic-stream.js.map +1 -0
  24. package/dist/adapters/anthropic.d.ts +4 -0
  25. package/dist/adapters/anthropic.d.ts.map +1 -0
  26. package/dist/adapters/anthropic.js +63 -0
  27. package/dist/adapters/anthropic.js.map +1 -0
  28. package/dist/adapters/chat-stream.d.ts +17 -0
  29. package/dist/adapters/chat-stream.d.ts.map +1 -0
  30. package/dist/adapters/chat-stream.js +220 -0
  31. package/dist/adapters/chat-stream.js.map +1 -0
  32. package/dist/adapters/conformance.d.ts +75 -0
  33. package/dist/adapters/conformance.d.ts.map +1 -0
  34. package/dist/adapters/conformance.js +156 -0
  35. package/dist/adapters/conformance.js.map +1 -0
  36. package/dist/adapters/gemini-mapping.d.ts +17 -0
  37. package/dist/adapters/gemini-mapping.d.ts.map +1 -0
  38. package/dist/adapters/gemini-mapping.js +295 -0
  39. package/dist/adapters/gemini-mapping.js.map +1 -0
  40. package/dist/adapters/gemini-stream.d.ts +6 -0
  41. package/dist/adapters/gemini-stream.d.ts.map +1 -0
  42. package/dist/adapters/gemini-stream.js +316 -0
  43. package/dist/adapters/gemini-stream.js.map +1 -0
  44. package/dist/adapters/gemini.d.ts +3 -1
  45. package/dist/adapters/gemini.d.ts.map +1 -1
  46. package/dist/adapters/gemini.js +43 -62
  47. package/dist/adapters/gemini.js.map +1 -1
  48. package/dist/adapters/http.d.ts +22 -6
  49. package/dist/adapters/http.d.ts.map +1 -1
  50. package/dist/adapters/http.js +152 -56
  51. package/dist/adapters/http.js.map +1 -1
  52. package/dist/adapters/moonshot-mapping.d.ts +14 -0
  53. package/dist/adapters/moonshot-mapping.d.ts.map +1 -0
  54. package/dist/adapters/moonshot-mapping.js +242 -0
  55. package/dist/adapters/moonshot-mapping.js.map +1 -0
  56. package/dist/adapters/moonshot.d.ts.map +1 -1
  57. package/dist/adapters/moonshot.js +48 -13
  58. package/dist/adapters/moonshot.js.map +1 -1
  59. package/dist/adapters/openai-mapping.d.ts +13 -0
  60. package/dist/adapters/openai-mapping.d.ts.map +1 -0
  61. package/dist/adapters/openai-mapping.js +242 -0
  62. package/dist/adapters/openai-mapping.js.map +1 -0
  63. package/dist/adapters/openai-stream.d.ts +5 -0
  64. package/dist/adapters/openai-stream.d.ts.map +1 -0
  65. package/dist/adapters/openai-stream.js +288 -0
  66. package/dist/adapters/openai-stream.js.map +1 -0
  67. package/dist/adapters/openai.d.ts +1 -1
  68. package/dist/adapters/openai.d.ts.map +1 -1
  69. package/dist/adapters/openai.js +32 -65
  70. package/dist/adapters/openai.js.map +1 -1
  71. package/dist/adapters/registry.d.ts +12 -1
  72. package/dist/adapters/registry.d.ts.map +1 -1
  73. package/dist/adapters/registry.js +145 -1
  74. package/dist/adapters/registry.js.map +1 -1
  75. package/dist/adapters/request-capabilities.d.ts +4 -0
  76. package/dist/adapters/request-capabilities.d.ts.map +1 -0
  77. package/dist/adapters/request-capabilities.js +53 -0
  78. package/dist/adapters/request-capabilities.js.map +1 -0
  79. package/dist/adapters/sse.d.ts +24 -0
  80. package/dist/adapters/sse.d.ts.map +1 -0
  81. package/dist/adapters/sse.js +209 -0
  82. package/dist/adapters/sse.js.map +1 -0
  83. package/dist/adapters/stream-evidence.d.ts +14 -0
  84. package/dist/adapters/stream-evidence.d.ts.map +1 -0
  85. package/dist/adapters/stream-evidence.js +69 -0
  86. package/dist/adapters/stream-evidence.js.map +1 -0
  87. package/dist/adapters/types.d.ts +99 -1
  88. package/dist/adapters/types.d.ts.map +1 -1
  89. package/dist/adapters/validation.d.ts +8 -0
  90. package/dist/adapters/validation.d.ts.map +1 -0
  91. package/dist/adapters/validation.js +231 -0
  92. package/dist/adapters/validation.js.map +1 -0
  93. package/dist/adapters/zai-mapping.d.ts +12 -0
  94. package/dist/adapters/zai-mapping.d.ts.map +1 -0
  95. package/dist/adapters/zai-mapping.js +246 -0
  96. package/dist/adapters/zai-mapping.js.map +1 -0
  97. package/dist/adapters/zai.d.ts +1 -25
  98. package/dist/adapters/zai.d.ts.map +1 -1
  99. package/dist/adapters/zai.js +37 -67
  100. package/dist/adapters/zai.js.map +1 -1
  101. package/dist/bundle-source.d.ts.map +1 -1
  102. package/dist/bundle-source.js +9 -7
  103. package/dist/bundle-source.js.map +1 -1
  104. package/dist/catalog-delivery.d.ts +7 -0
  105. package/dist/catalog-delivery.d.ts.map +1 -1
  106. package/dist/catalog-delivery.js +87 -39
  107. package/dist/catalog-delivery.js.map +1 -1
  108. package/dist/catalog-publication-source.d.ts +16 -0
  109. package/dist/catalog-publication-source.d.ts.map +1 -0
  110. package/dist/catalog-publication-source.js +99 -0
  111. package/dist/catalog-publication-source.js.map +1 -0
  112. package/dist/catalog-publication.d.ts +50 -0
  113. package/dist/catalog-publication.d.ts.map +1 -0
  114. package/dist/catalog-publication.js +127 -0
  115. package/dist/catalog-publication.js.map +1 -0
  116. package/dist/catalog-reader-configuration.d.ts +6 -0
  117. package/dist/catalog-reader-configuration.d.ts.map +1 -0
  118. package/dist/catalog-reader-configuration.js +2 -0
  119. package/dist/catalog-reader-configuration.js.map +1 -0
  120. package/dist/catalog-transfer.d.ts +11 -0
  121. package/dist/catalog-transfer.d.ts.map +1 -0
  122. package/dist/catalog-transfer.js +55 -0
  123. package/dist/catalog-transfer.js.map +1 -0
  124. package/dist/client.d.ts +9 -1
  125. package/dist/client.d.ts.map +1 -1
  126. package/dist/client.js +14 -6
  127. package/dist/client.js.map +1 -1
  128. package/dist/compatibility-client.d.ts +58 -0
  129. package/dist/compatibility-client.d.ts.map +1 -0
  130. package/dist/compatibility-client.js +116 -0
  131. package/dist/compatibility-client.js.map +1 -0
  132. package/dist/compatibility-execution.d.ts +47 -0
  133. package/dist/compatibility-execution.d.ts.map +1 -0
  134. package/dist/compatibility-execution.js +2 -0
  135. package/dist/compatibility-execution.js.map +1 -0
  136. package/dist/compatibility-stream-projection.d.ts +116 -0
  137. package/dist/compatibility-stream-projection.d.ts.map +1 -0
  138. package/dist/compatibility-stream-projection.js +188 -0
  139. package/dist/compatibility-stream-projection.js.map +1 -0
  140. package/dist/compatibility-types.d.ts +281 -0
  141. package/dist/compatibility-types.d.ts.map +1 -0
  142. package/dist/compatibility-types.js +2 -0
  143. package/dist/compatibility-types.js.map +1 -0
  144. package/dist/continuation.d.ts +49 -0
  145. package/dist/continuation.d.ts.map +1 -0
  146. package/dist/continuation.js +187 -0
  147. package/dist/continuation.js.map +1 -0
  148. package/dist/cost.d.ts +19 -4
  149. package/dist/cost.d.ts.map +1 -1
  150. package/dist/cost.js +109 -38
  151. package/dist/cost.js.map +1 -1
  152. package/dist/direct-model-client.d.ts +4 -0
  153. package/dist/direct-model-client.d.ts.map +1 -0
  154. package/dist/direct-model-client.js +37 -0
  155. package/dist/direct-model-client.js.map +1 -0
  156. package/dist/direct-model-types.d.ts +40 -0
  157. package/dist/direct-model-types.d.ts.map +1 -0
  158. package/dist/direct-model-types.js +2 -0
  159. package/dist/direct-model-types.js.map +1 -0
  160. package/dist/errors.d.ts +27 -1
  161. package/dist/errors.d.ts.map +1 -1
  162. package/dist/errors.js +10 -7
  163. package/dist/errors.js.map +1 -1
  164. package/dist/execution-configuration.d.ts +33 -0
  165. package/dist/execution-configuration.d.ts.map +1 -0
  166. package/dist/execution-configuration.js +16 -0
  167. package/dist/execution-configuration.js.map +1 -0
  168. package/dist/feature-planning.d.ts +23 -0
  169. package/dist/feature-planning.d.ts.map +1 -0
  170. package/dist/feature-planning.js +249 -0
  171. package/dist/feature-planning.js.map +1 -0
  172. package/dist/feature-policy.d.ts +13 -0
  173. package/dist/feature-policy.d.ts.map +1 -0
  174. package/dist/feature-policy.js +60 -0
  175. package/dist/feature-policy.js.map +1 -0
  176. package/dist/generation-input.d.ts +7 -0
  177. package/dist/generation-input.d.ts.map +1 -0
  178. package/dist/generation-input.js +24 -0
  179. package/dist/generation-input.js.map +1 -0
  180. package/dist/generation-stream.d.ts +35 -0
  181. package/dist/generation-stream.d.ts.map +1 -0
  182. package/dist/generation-stream.js +178 -0
  183. package/dist/generation-stream.js.map +1 -0
  184. package/dist/index.d.ts +36 -5
  185. package/dist/index.d.ts.map +1 -1
  186. package/dist/index.js +30 -3
  187. package/dist/index.js.map +1 -1
  188. package/dist/model-client-types.d.ts +99 -0
  189. package/dist/model-client-types.d.ts.map +1 -0
  190. package/dist/model-client-types.js +7 -0
  191. package/dist/model-client-types.js.map +1 -0
  192. package/dist/model-client.d.ts +3 -0
  193. package/dist/model-client.d.ts.map +1 -0
  194. package/dist/model-client.js +96 -0
  195. package/dist/model-client.js.map +1 -0
  196. package/dist/model-configuration.d.ts +40 -0
  197. package/dist/model-configuration.d.ts.map +1 -0
  198. package/dist/model-configuration.js +102 -0
  199. package/dist/model-configuration.js.map +1 -0
  200. package/dist/named-client-types.d.ts +72 -0
  201. package/dist/named-client-types.d.ts.map +1 -0
  202. package/dist/named-client-types.js +4 -0
  203. package/dist/named-client-types.js.map +1 -0
  204. package/dist/named-client.d.ts +4 -0
  205. package/dist/named-client.d.ts.map +1 -0
  206. package/dist/named-client.js +68 -0
  207. package/dist/named-client.js.map +1 -0
  208. package/dist/named-configuration.d.ts +57 -0
  209. package/dist/named-configuration.d.ts.map +1 -0
  210. package/dist/named-configuration.js +119 -0
  211. package/dist/named-configuration.js.map +1 -0
  212. package/dist/native-operation.d.ts +6 -0
  213. package/dist/native-operation.d.ts.map +1 -0
  214. package/dist/native-operation.js +45 -0
  215. package/dist/native-operation.js.map +1 -0
  216. package/dist/package-updates.d.ts +2 -0
  217. package/dist/package-updates.d.ts.map +1 -1
  218. package/dist/package-updates.js +5 -9
  219. package/dist/package-updates.js.map +1 -1
  220. package/dist/profile-client.d.ts +13 -0
  221. package/dist/profile-client.d.ts.map +1 -0
  222. package/dist/profile-client.js +57 -0
  223. package/dist/profile-client.js.map +1 -0
  224. package/dist/published-catalog.d.ts +22 -0
  225. package/dist/published-catalog.d.ts.map +1 -0
  226. package/dist/published-catalog.js +25 -0
  227. package/dist/published-catalog.js.map +1 -0
  228. package/dist/reasoning-resolution.d.ts.map +1 -1
  229. package/dist/reasoning-resolution.js +11 -2
  230. package/dist/reasoning-resolution.js.map +1 -1
  231. package/dist/request-mapping.d.ts +15 -0
  232. package/dist/request-mapping.d.ts.map +1 -0
  233. package/dist/request-mapping.js +479 -0
  234. package/dist/request-mapping.js.map +1 -0
  235. package/dist/resolution.d.ts.map +1 -1
  236. package/dist/resolution.js +7 -10
  237. package/dist/resolution.js.map +1 -1
  238. package/dist/result-mapping.d.ts +17 -0
  239. package/dist/result-mapping.d.ts.map +1 -0
  240. package/dist/result-mapping.js +123 -0
  241. package/dist/result-mapping.js.map +1 -0
  242. package/dist/route-adoption-node.d.ts +22 -0
  243. package/dist/route-adoption-node.d.ts.map +1 -0
  244. package/dist/route-adoption-node.js +134 -0
  245. package/dist/route-adoption-node.js.map +1 -0
  246. package/dist/route-adoption.d.ts +100 -0
  247. package/dist/route-adoption.d.ts.map +1 -0
  248. package/dist/route-adoption.js +176 -0
  249. package/dist/route-adoption.js.map +1 -0
  250. package/dist/route-client.d.ts +78 -0
  251. package/dist/route-client.d.ts.map +1 -0
  252. package/dist/route-client.js +91 -0
  253. package/dist/route-client.js.map +1 -0
  254. package/dist/route-readiness.d.ts +27 -0
  255. package/dist/route-readiness.d.ts.map +1 -0
  256. package/dist/route-readiness.js +78 -0
  257. package/dist/route-readiness.js.map +1 -0
  258. package/dist/route-set-file-source.d.ts +7 -0
  259. package/dist/route-set-file-source.d.ts.map +1 -0
  260. package/dist/route-set-file-source.js +27 -0
  261. package/dist/route-set-file-source.js.map +1 -0
  262. package/dist/route-set-json-source.d.ts +27 -0
  263. package/dist/route-set-json-source.d.ts.map +1 -0
  264. package/dist/route-set-json-source.js +126 -0
  265. package/dist/route-set-json-source.js.map +1 -0
  266. package/dist/route-set.d.ts +30 -0
  267. package/dist/route-set.d.ts.map +1 -0
  268. package/dist/route-set.js +33 -0
  269. package/dist/route-set.js.map +1 -0
  270. package/dist/run.d.ts +42 -4
  271. package/dist/run.d.ts.map +1 -1
  272. package/dist/run.js +925 -474
  273. package/dist/run.js.map +1 -1
  274. package/dist/system-instructions.d.ts +23 -0
  275. package/dist/system-instructions.d.ts.map +1 -0
  276. package/dist/system-instructions.js +57 -0
  277. package/dist/system-instructions.js.map +1 -0
  278. package/dist/types.d.ts +3 -1
  279. package/dist/types.d.ts.map +1 -1
  280. package/dist/types.js.map +1 -1
  281. package/dist/version.d.ts +1 -1
  282. package/dist/version.d.ts.map +1 -1
  283. package/dist/version.js +1 -1
  284. package/dist/version.js.map +1 -1
  285. package/package.json +35 -26
  286. package/third-party-licenses.json +2 -7
  287. /package/third-party-licenses/{fast-uri@3.1.7 → fast-uri@3.1.9}/LICENSE +0 -0
@@ -0,0 +1,49 @@
1
+ # Gemini Interactions v1 mapping
2
+
3
+ The unpublished `0.4.0-rc.1` source uses stable Interactions v1 for Gemini final and streaming calls through both client coding styles. `createGeminiInteractionsAdapter()` is the current factory. `createGeminiGenerateContentAdapter()` is a compatibility alias returning the same implementation. The catalog route ID remains `gemini-generate-content`; adapter version `2.0.0` and protocol `gemini-interactions-v1` identify the transport change explicitly. Previously published/adopted packages are not changed.
4
+
5
+ The [stable v1 reference](https://ai.google.dev/api/interactions-api-v1), [OpenAPI specification](https://ai.google.dev/static/api/interactions-v1.openapi.json), [migration guide](https://ai.google.dev/gemini-api/docs/migrate-to-interactions) and [function guide](https://ai.google.dev/gemini-api/docs/function-calling) were reviewed on 21 October 2026. The specification SHA-256 is `809db6ee195b03a6fee667f31772b8f8dfb45e84f2b012947ccd24d38f6120af`; a fresh fetch on 22 October for streaming has the same hash. Generic/beta documentation examples are not the transport version authority. Synthetic tests do not prove model availability or live access.
6
+
7
+ ## Adoption and request mapping
8
+
9
+ The default endpoint is `https://generativelanguage.googleapis.com/v1/interactions`. An explicitly configured official beta endpoint is rejected with an adoption error; it is not silently rewritten. A configured v1 base path receives `/interactions`. Other host-owned complete proxy endpoints remain supported. Existing API-key, query-parameter and bearer-token-as-API-key credential forms retain their behavior. Model pins are sent unchanged; no current model is substituted for an older pin.
10
+
11
+ The adapter defaults to `store: false`. Set shared `store: true` explicitly to request stored-state continuation. Server IDs are reused only under the existing exact provider/model/implementation/configuration binding rules. Provider-reported non-storage prevents ID reuse. Default/stateless calls replay complete retained history, including thought/search signatures, unknown steps and native message metadata.
12
+
13
+ Text and URL/base64 images map to typed content. User and assistant history become `user_input` and `model_output` steps. System/developer text is combined in order into the provider's top-level instruction with a diagnostic; non-text system content is rejected on a primary or omitted with a backup warning. Image detail `low`/`high` maps directly, `auto` leaves resolution to the provider, and `original` cannot be guaranteed. Native content can carry additional documented provider fields explicitly.
14
+
15
+ JSON-object and JSON-schema output use native text response format with `application/json`; text uses `text/plain`. Completed structured results also pass runtime validation. Reviewed native siblings such as seed, stop sequences, thought summaries, safety settings and service tier remain available through the selected provider namespace. Shared controls and output caps win over native siblings. Background/agent execution and runtime-owned history/tools cannot be selected through extensions.
16
+
17
+ ## Tools and provider limits
18
+
19
+ Functions map to native flat declarations; calls retain object arguments, IDs and native fields. Client results become function-result steps. Strings and objects retain their values; null, booleans, numbers and general arrays are serialized as JSON strings because the native result union does not carry every JSON value directly. `isError` maps to the native flag, including explicit false. No functions are executed by the runtime.
20
+
21
+ Shared automatic/none/required/named selection maps to native auto/none/any/allowed-tools settings. Strict automatic function schemas use native `validated` mode, which applies to all declared functions and is disclosed. The reviewed protocol cannot combine that mode with forced selection; a primary rejects that combination, while a backup removes strict enforcement with a warning and keeps the supported forced choice. Explicit parallel-call control is unavailable, although multiple returned calls and their results are supported.
22
+
23
+ Function-call history must have object arguments. Valid object JSON strings are parsed for the wire without changing the caller's original data. A primary rejects malformed/non-object argument history. A backup preserves that history as labeled client-provided text context, without repairing arguments or executing tools.
24
+
25
+ Hosted search maps to `google_search` with web search enabled and can coexist with functions. Common search size/location/domain/offline restrictions are absent from the reviewed v1 schema; primary requests reject unsupported restrictions and backups warn while retaining search. Search steps, signatures and citations remain available.
26
+
27
+ The reviewed v1 configuration supports thinking levels minimal/low/medium/high. It has no old token-budget control, guaranteed reasoning-off switch, temperature or top-p field. The runtime does not convert a budget or disabled setting into an approximate level. Existing profiles/catalog metadata must be explicitly reviewed for this adapter version. Backups retain their established warning/degradation behavior.
28
+
29
+ ## Results, errors and usage
30
+
31
+ The adapter preserves ordered output steps, thought signatures, function calls, citations, unknown blocks and complete native JSON. Thought summaries are not answer text. An echoed `user_input` remains in the native body and is not appended to the client's history twice. An incomplete interaction remains incomplete; a failed interaction remains failed rather than being relabeled as refusal. The reviewed v1 status model has no separate refusal status, so safety/error diagnostics remain native evidence. In-progress/background polling is not performed. Provider cancellation stops execution with partial usage/native evidence. HTTP classification remains authoritative.
32
+
33
+ V1 reports visible output and thought tokens separately. Shared output usage includes both exactly once; it stays unknown if either component is absent. Input is not increased by tool-use prompt tokens again. Reported grounding counts are used as counts; result count is not substituted. Cache-write usage is not fabricated. Tool/tier pricing remains unknown where unqualified. Complete native counters remain available even when a shared aggregate cannot be computed.
34
+
35
+ Receipts and default error serialization omit unrestricted native bodies, thought signatures, citations, prompts and credentials. Native bodies and continuation remain caller-controlled sensitive data. Live, packaged-artifact and Windows x64 Studio qualification are separate release tasks.
36
+
37
+ ## Public streaming
38
+
39
+ Set `stream: true` on either client interface and iterate its stream; `finalResult()` returns the complete result, continuation envelope and receipt. Calling `finalResult()` first drains internally. The same v1 endpoint, credential forms, store policy, request mapping and configuration pins apply. The adapter sends native `stream: true` and introduces no polling, automatic resume or client-tool execution.
40
+
41
+ The [streaming guide](https://ai.google.dev/gemini-api/docs/streaming) describes interaction lifecycle events and indexed start/delta/stop steps. Text already present at step start and later text deltas are exposed incrementally. Thought summaries produce reasoning events; signatures stay in native data and replay history. Multiple function steps can interleave with distinct tool indexes and output positions. Complete argument strings are parsed as objects at step stop; raw fragments remain in native events. Object arguments supplied at step start are preserved. Invalid JSON or non-object completed arguments fail without repair. An interrupted or incomplete call retains its raw partial arguments and incomplete status.
42
+
43
+ Search calls/results, citations, thought signatures, unknown step fields and original events remain available. `native.body` is an assembled interaction combining lifecycle metadata with ordered steps; `native.events` retains original parsed JSON and SSE event/ID metadata. Unknown delta types remain in those original events instead of receiving guessed merge semantics. Existing generated-media exclusions remain; retained native media blocks are not a promise of supported media generation. Echoed input is retained natively and excluded from newly generated canonical output.
44
+
45
+ A terminal `interaction.completed` event is required. The optional REST `[DONE]` marker is preserved when received; clean EOF after a valid completed event also terminates successfully. EOF before that event, contradictory terminal identities/content, duplicate lifecycle events, missing step stops on completed output, invalid positions and malformed/oversized data fail explicitly. Incomplete/failed/cancelled completion can retain open steps and partial content. Status updates alone never fabricate successful completion.
46
+
47
+ Cumulative usage from event metadata, status updates, step stops and completion replaces or extends earlier reports; per-step `step_usage` is not added again. Error-event usage is captured before error classification. The documented `gateway_timeout` stream error becomes a retryable provider timeout before exposure; other error events retain native diagnostics with invalid-output classification. HTTP error classification remains authoritative. Once any provider data reaches the caller, a later failure cannot switch providers. Both successful and failed invocations retain one terminal receipt; default receipts omit unrestricted native bodies and signatures.
48
+
49
+ The shared 1 MiB frame/32 MiB transport bounds, backpressure, abort and deadline behavior apply. Cancellation via `abort()` or early iterator return closes the reader. Stored and stateless streamed calls reuse the same exact-binding and native-step continuation rules as final calls.
package/MIGRATION.md ADDED
@@ -0,0 +1,114 @@
1
+ # Runtime 0.4 development migration
2
+
3
+ ## Request route and route set terminology
4
+
5
+ Current source exposes `RequestRoute` / routeId / routeName and `RouteSet` / routeSetId. Use `routeSetSource` with
6
+ `createRouteSetResolver` or `createHttpRouteSetResolver`, then `startRun({ routeName, systemInstructions })`.
7
+ Use `createRequestRouteRun` for a held route and catalog. Host provider credentials/endpoints and independent instruction retrieval
8
+ are separate inputs. The [API guide](API.md#request-routes-and-route-sets) includes a complete typed host example.
9
+
10
+ New route-set JSON uses schema 5 and new execution receipts use schema 6. New single-route exports use `request-route-export`
11
+ schema 1. The supplied readers accept old records/JSON and validate the original storage hashes. Use `hashRequestRoute` and
12
+ `validateRouteSetSnapshot`; do not recompute historical IDs or hash renamed JSON as if it were the original storage document.
13
+ Model settings, ordered backups, captured workflows, exact revisions and receipt ID values retain their earlier behavior.
14
+
15
+ Old SDK entry points and old HTTP endpoints remain deprecated compatibility paths. New endpoints are `/routes` and `/route-sets`;
16
+ the management service must be upgraded before clients switch URLs. Existing services and packages were not deployed/published by
17
+ the source change. Different consumers can upgrade separately, retaining old endpoints until they adopt new DTOs and receipt sinks.
18
+ Equal old/new aliases normalize; conflicting aliases fail explicitly. Canonical clients do not silently fall back to an older server.
19
+
20
+ No live store conversion is required. Retained catalog delivery envelopes, native/workspace/persona configuration and general bundle
21
+ manifests remain separate legacy protocols. Route-shaped offer helpers project verified catalog offers without rewriting delivery proofs.
22
+ The repository's `docs/route-terminology-migration-2026-10-30.md` records qualification artifacts and the external rollout steps.
23
+
24
+ ## Earlier 0.4 migration notes
25
+
26
+ This document describes source changes in the unpublished `0.4.0-rc.1` runtime/contracts pair. Provider and artifact qualification remain tracked in the product-finalization ledger; this is not a publication or compatibility claim for an installed release.
27
+
28
+ ## Existing persona and profile callers
29
+
30
+ `createAIClient`, `captureWorkflow`, `startRun` and `run.generate` retain their existing arguments and result shape. `generate` returns text or validated structured output with an execution receipt. It remains a final-result API. Refusal, incomplete output, failed output and a response requiring client tool continuation reject with the canonical error and receipt; received rich/native data remains accessible on the error. Use `responses.create` or `chat.completions.create` when the client needs tool calls, continuation or streaming.
31
+
32
+ Captured workflows and runs retain exact manifest, profile, catalog, price and instruction identities. Refreshing the client's configuration affects newly captured work; it never rewrites an existing run or adopts a package's newly available catalog. Request model fields in the new interfaces assert the configured primary, rather than changing routing.
33
+
34
+ Existing execute-only adapters remain valid with omitted `contractVersion` or version 1. The `adapters` option still replaces the complete adapter set, including an intentionally empty set. New `adapterRegistration.add`/`replace` entries preserve other defaults and cannot be combined with `adapters`. Rich adapters use contract version 2. Both legacy generation and the new interfaces enter the same engine; V2 adapters receive its canonical request as well as the legacy request fields.
35
+
36
+ ## Deliberate behavior changes
37
+
38
+ - A backup feature mismatch produces a warning and an effective request containing supported features; it no longer prevents a valid primary call. Omitted schemas can produce a visibly degraded text result. Integrity and authorization failures still stop execution.
39
+ - Explicit output requests can replace defaults upward or downward, bounded by intersected model/context/profile/client/invocation limits. Remaining context includes input usage; reasoning defaults, disabled thinking and exact controls retain distinct meanings.
40
+ - Unknown model metadata does not mean unsupported. The runtime warns and attempts controls the installed adapter can represent; a known unsupported primary feature still rejects.
41
+ - Receipts emitted by the new runtime use legacy schema 2 or native schema 4. Upgrade receipt readers with the runtime/contracts pair; historical schema 1/3 records remain readable by the new contracts.
42
+ - Reported usage is retained on incomplete, refused and failed output. Stream usage snapshots merge by dimension; the latest reported value wins, including zero. A missing dimension remains unknown. The terminal receipt carries the last attempt's usage; aggregate all dispatched attempts for call totals.
43
+ - Cost estimates now carry bounded uncertainty codes. Missing cache counters, unpriced used dimensions, unknown long-context rates, provider tools, native service-tier/region selectors and free-text price conditions keep reported cost unknown. Cache and reasoning subsets are never added to input/output totals twice.
44
+ - Success without reported usage retains labeled preflight cost evidence. Preflight estimates use the input heuristic, output cap and highest known input/cache/write rate; they are not exact monetary guarantees. Opaque continuation history cannot be priced preflight. An explicit estimated-cost cap rejects an unpriceable request before provider dispatch; complete reported usage can price opaque history afterward.
45
+ - The local usage package adds `FileNativeExecutionReceiptStore` for native schema 3/4 receipts. The existing `FileExecutionReceiptStore` and default repository/page types retain their legacy API; native and legacy stores use separate roots.
46
+ - Gemini adapter 2 uses stable Interactions v1 while retaining its catalog route and factory alias. Explicit old beta endpoint pins require adoption; model pins are unchanged. The adapter defaults to stateless calls. Review old token-budget/disabled/sampling settings because v1 exposes different controls; see the [complete Gemini mapping](GEMINI-INTERACTIONS.md).
47
+ - Moonshot adapter 2 retains Chat transport for both client signatures, adds complete tool/history/native mapping, and uses native JSON-schema output. Reviewed K3/K2.6/K2.7 sampling and tool-choice restrictions are planned per model; review existing settings during adoption. Native cache-tier selections remain unpriced without qualification; see the [Moonshot mapping](MOONSHOT-CHAT.md).
48
+ - Anthropic adapter 2 uses API version `2026-10-21`; sampling controls are removed. It adds client tool/result replay, preserved thinking/signatures, native search, native schema output and explicit paused turns. Review model-specific thinking/tool-choice restrictions and invalid content placements during adoption. Generic JSON-object mode uses a disclosed prompt plus local validation; see the [Anthropic mapping](ANTHROPIC-MESSAGES.md).
49
+ - OpenAI adapter 2 now exposes true public streaming through both client styles. The shared adapter event union adds `refusal-delta`; custom stream consumers using exhaustive switches should handle it. Responses exposes refusal delta/done events and Chat exposes `delta.refusal`, without placing refusal text in answer content. See the [streaming guide](OPENAI-RESPONSES.md#public-streaming).
50
+ - Z.AI adapter 2 exposes public streaming through both client styles, including reasoning, indexed function arguments and native search data. The runtime sets `tool_stream` for function requests; that field is now reserved in provider extensions. Streamed `native.body` is assembled from chunks, while `native.events` retains the originals. See the [Z.AI streaming guide](ZAI-CHAT.md#public-streaming).
51
+ - Gemini adapter 2 exposes v1 public streaming through both styles using the same adopted endpoint and credential forms as final calls. Step deltas preserve signatures, search data and function arguments; stored/stateless continuation remains client-owned. Streamed `native.body` is assembled, and original events remain accessible. See the [Gemini streaming guide](GEMINI-INTERACTIONS.md#public-streaming).
52
+ - Moonshot adapter 2 exposes public streaming through both styles with reasoning, client-owned functions and native replay. It requests usage for internal accounting independently of the Chat client's projected usage option, supports root/choice usage, and does not send Z.AI-specific controls. See the [Moonshot streaming guide](MOONSHOT-CHAT.md#public-streaming).
53
+ - Anthropic adapter 2 exposes public streaming through both styles using its existing versioned Messages transport and shared final-call assembler. Thinking/signatures, client functions, hosted blocks, citations and cumulative usage survive streaming and replay. Late classifier refusals retain partial text and expose separate refusal content. See the [Anthropic streaming guide](ANTHROPIC-MESSAGES.md#public-streaming).
54
+ - A bundle whose runtime range excludes the new reader remains rejected. Re-export a reviewed configuration for the selected reader and explicitly adopt its new identity; never edit a historical manifest or bypass its hash/version verification.
55
+
56
+ The public coding style does not choose the provider endpoint. OpenAI transport uses Responses for either coding style. Client tools and application workflows continue to execute in client code.
57
+
58
+ ## Move a caller to the shared interfaces
59
+
60
+ Keep `generate` for a final text/structured result. Move to the matching rich signature when the application must handle function calls, refusal/incomplete outcomes, native data or streaming. These are alternate call examples; invoking all three makes three provider requests. Host configuration still selects the primary/backup models.
61
+
62
+ ```ts
63
+ import type { AIRun } from '@techis/ai-runtime';
64
+
65
+ export function existingCall(run: AIRun, input: string) {
66
+ return run.generate({ input, operationId: 'summary' });
67
+ }
68
+
69
+ export function responsesCall(run: AIRun, input: string) {
70
+ return run.responses.create({ input }, { operationId: 'summary' });
71
+ }
72
+
73
+ export function chatCall(run: AIRun, input: string) {
74
+ return run.chat.completions.create({ messages: [{ role: 'user', content: input }] }, { operationId: 'summary' });
75
+ }
76
+ ```
77
+
78
+ A provider SDK client is not interchangeable with a run. Move construction to the runtime's host-owned configuration/credential setup, bind an operation ID with `createCompatibleClient` if helpful, and remove unsupported SDK-only fields. The request `model` is an assertion against the configured primary; move actual routing choices to configuration. Do not use a Chat-style request to select an OpenAI Chat endpoint. See the [field mapping](API.md#two-client-signatures).
79
+
80
+ Rich results add canonical `outcome`, `items`, `native`, `continuation`, `diagnostics`, `runtime_usage` and a receipt. Handle `requires_action`, `refused` and `incomplete` explicitly instead of assuming nonempty text means success. Chat streaming includes `runtime.*` extension events alongside chunks; discriminate the union. Stream iteration and `finalResult()` share one operation, not two calls. Cancellation and partial output can prevent fallback; see [streaming](API.md#streaming).
81
+
82
+ ## Extensions and adapter registration
83
+
84
+ Put native JSON under `providerOptions.<provider>`. Profile-slot options are the base and call options override leaves by recursive object merge; arrays/scalars/null replace, absence inherits. Runtime-owned fields and nested control paths reject collisions before dispatch. Only the selected provider namespace is forwarded. Native options cannot override credentials, endpoint, model routing, timing or configuration identity. See the [full precedence rules](API.md#native-extensions-and-precedence).
85
+
86
+ Keep `adapters` if the application intentionally supplies the entire set. Use `adapterRegistration.add` for new routes or `replace` for default routes while retaining other defaults; these options are mutually exclusive. A replacement's actual identity/version remains in receipts, independently of its declared compatible route version. Explicit registration snapshots metadata and binds instance methods. Existing execute-only adapters remain contract 1; implementing contract 2 requires truthful features, canonical output and any advertised streaming. See [adapter authoring](ADAPTER-AUTHORING.md) and [qualification](ADAPTER-CONFORMANCE.md).
87
+
88
+ ## Catalog inbox upgrades
89
+
90
+ The catalog delivery client verifies every ancestor's integrity, trusted root, exact lineage and immutable profile identities, then checks the
91
+ resulting head's runtime range before any inbox write or notification. Historical ancestors may target an older runtime: they prove history,
92
+ while `inbox.releases[inbox.head]` identifies the current offer. A historical-only chain remains rejected when its head excludes the installed
93
+ runtime. The same rule applies to empty or duplicate checks after upgrading an existing inbox. Read/acknowledgment still permits inspection
94
+ of retained historical records. Installing a package does not invoke a check, change a trust anchor or adopt a configuration.
95
+
96
+ The preview pair carries sequence 6 over the exact existing accepted payload and profile offers with `>=0.4.0-rc.1 <0.5.0` compatibility.
97
+ Its parent, original trusted root and first three deliveries remain unchanged. Existing inboxes can ingest the successor alone or the full
98
+ chain; fresh inboxes need the complete verified chain. Repeated checks and restarts retain existing notices/acknowledgments without duplicates.
99
+ Corrupt, forked or missing ancestors and an incompatible resulting current offer fail atomically. Old data remains available for recovery.
100
+
101
+ This new distribution envelope does not re-review model facts or establish current live access. The accepted release's older `packageVersion`
102
+ and review timestamp remain provenance; the runtime package version and the new delivery's explicit reader range describe the current code.
103
+ Consumer adoption and rollback still require complete compatible configuration and package pairs, independently of inbox ingestion.
104
+
105
+ ## Adopt and recover explicitly
106
+
107
+ 1. Retain the exact installed runtime/contracts archives or lockfile, adapter implementations, validated configuration/bundle and receipt-reader version before changing anything.
108
+ 2. Review the deliberate changes above and every selected provider's native mapping; verify account/model availability separately from synthetic compatibility.
109
+ 3. Install a matching runtime/contracts pair in a disposable consumer from the intended artifacts; compile the application's imports and exercise final/stream, tools, native options, failures and backups.
110
+ 4. Export a new reviewed configuration whose reader range and adapter requirements permit that pair, preserving historical manifest bytes and recording source provenance; historical catalog compatibility still needs evaluation.
111
+ 5. Adopt the exact new package/configuration identities explicitly and start new runs; already captured runs retain their pins.
112
+ 6. To recover, restore the complete prior package pair, adapters and compatible configuration together, then start new runs and verify the restored identities; do not combine an old reader with a new-only bundle or rewrite hashes/ranges to bypass rejection.
113
+
114
+ For native named configuration, retain configuration/workspace/revision identities and native receipt stores. Do not translate it into an environment bundle to force an older reader to accept it. Development source qualification, actual registry publication, installation and consumer adoption are separate outcomes. These instructions do not claim that `0.4.0-rc.1` has been published or that the retained historical catalog is compatible with it.
@@ -0,0 +1,53 @@
1
+ # Moonshot Chat mapping
2
+
3
+ Adapter `moonshot-chat-completions` version `2.0.0`, contract 2, uses `POST https://api.moonshot.ai/v1/chat/completions` for both public coding styles. The factory and catalog route remain `createMoonshotChatCompletionsAdapter` and `moonshot-chat-completions`. Protocol selection is independent of the caller's coding signature. Adoption of this unpublished runtime remains explicit; existing model IDs, endpoints and historical catalog records are not rewritten.
4
+
5
+ The adapter carries ordered roles, URL/base64 image parts, native JSON-schema output, client function declarations/results, reasoning controls and provider extensions. Developer messages use the system role with a diagnostic. Native schema names default to `output`; explicit strict true/false values are retained for output schemas and function declarations. Provider schema restrictions and actual model quality still apply, and the runtime validates requested final JSON locally.
6
+
7
+ Returned parallel calls are client work: IDs, original argument strings (including malformed strings), object arguments and results are preserved without execution. A boolean tool-error marker is represented as a JSON object in the tool-result string. Complete assistant messages retain `reasoning_content`, citations and unknown fields through continuation. Canonical calls are appended once. The Chat protocol uses full transcript replay, not server-side response IDs.
8
+
9
+ ## Model and transport limits
10
+
11
+ - K3 accepts low/high/max effort, always thinks, and supports automatic, none and required tool choice.
12
+ - K2.6 can disable thinking; K2.7 Code always thinks. Neither supports required tool choice. Named forcing requires an explicitly disabled thinking control on a model that permits it.
13
+ - The reviewed K3/K2.6/K2.7 families have fixed temperature/top-p settings. Shared sampling requests reject on a primary and are omitted with warnings on a backup. Other models retain the protocol mapping without an invented capability claim.
14
+ - There is no shared image-detail, explicit parallel-call, storage or response-ID control. Returned parallel calls remain supported independently of a request-side parallel switch.
15
+ - Hosted search is not advertised on this Chat route. The retired built-in search flow and standalone search REST APIs require client workflow; the runtime does not add an execution loop. Declare a client-owned search function and return its result when needed.
16
+
17
+ `resolveRequestCapabilities(model, reasoning)` exposes model/control-specific limits alongside static `requestCapabilities`. The runtime validates its result before credential resolution, passes cloned inputs, and rechecks limits if fallback reasoning changes. Unsupported primary choices fail; backup feature omissions produce diagnostics while keeping supported functions and native schema behavior.
18
+
19
+ ## Results and accounting
20
+
21
+ The complete JSON body and safe HTTP request ID remain on `native`; prompts, reasoning, arbitrary response fields and credentials are excluded from default error serialization and receipts. `stop`, `tool_calls` and `length` map to final, client-action and incomplete outcomes. An explicitly returned refusal field is recognized without interpreting ordinary text as a refusal. Unknown/malformed finish states reject with native and partial output/usage evidence. HTTP failures retain their original authentication/rate/server classification.
22
+
23
+ Input/output totals are used directly. Cached and cache-write input counters are subsets, not extra input. The nested cached counter takes precedence over the documented top-level alias. Reasoning counts are normalized only when explicitly reported; no count is inferred from reasoning text. Absent dimensions stay unknown. `prompt_cache_options` is preserved, and selecting a native cache tier keeps cost unknown until that tier has qualified pricing. Calls never discover or update prices automatically.
24
+
25
+ ## Reviewed sources and validation scope
26
+
27
+ Reviewed 21 October 2026: [Chat API](https://platform.kimi.ai/docs/api/chat), [model parameters](https://platform.kimi.ai/docs/api/models-overview), [tool choice](https://platform.kimi.ai/docs/guide/use-tool-choice), [structured output](https://platform.kimi.ai/docs/guide/response_format), [thinking](https://platform.kimi.ai/docs/guide/use-thinking-models), [cache accounting](https://platform.kimi.ai/docs/guide/context-caching) and [search migration](https://platform.kimi.ai/docs/guide/use-web-search). The Chat reference and [streaming guide](https://platform.kimi.ai/docs/guide/utilize-the-streaming-output-feature-of-kimi-api) were freshly reviewed on 22 October. Source hashes and synthetic qualification are recorded in the product-finalization evidence. This does not establish live account/model access.
28
+
29
+ ## Public streaming
30
+
31
+ Both client styles accept `stream: true` and return a lazy `GenerationStream` with incremental events, cancellation and `finalResult()`.
32
+ Moonshot uses the same Chat endpoint, model controls and request mapper for final and streaming calls. The adapter always requests
33
+ `stream_options.include_usage: true` for runtime accounting; the client's Chat `stream_options.include_usage` controls the projected usage
34
+ chunk. It does not disable internal accounting. Z.AI's `tool_stream` is never sent to Moonshot.
35
+
36
+ Text, explicit refusal, reasoning and indexed tool-argument fragments are exposed as they arrive. The client owns tool execution and the next
37
+ turn. Raw argument strings are preserved, including malformed JSON, so the client can validate them. Replayed assistant messages retain
38
+ reasoning and native fields; streaming tool indexes are not sent back as tool-call properties. Native schema enforcement, model-specific tool
39
+ choice, image input and provider extensions retain their final-call semantics.
40
+
41
+ `native.body` is an assembled Chat response, while `native.events` preserves every original parsed chunk and SSE metadata. Unknown fields,
42
+ false/null values and annotations remain accessible. Opaque returned source data does not advertise a hosted search workflow on this route.
43
+ The parser requires a supported finish reason followed by `[DONE]`; premature EOF, inconsistent IDs/indexes, malformed known fields, invalid
44
+ UTF-8 and configured size violations reject with partial native data. `length` remains incomplete, and a refusal field remains refused.
45
+
46
+ Cumulative usage is read from the chunk root or its single choice, preferring root usage when both are present. A separate empty-choice usage
47
+ chunk is supported. Reported counters merge without adding repeated totals; missing counters stay unknown, including after disconnects.
48
+ Cache reads/writes and reasoning counters retain the accounting rules above. HTTP errors keep authentication/rate/server classifications;
49
+ in-stream provider errors preserve their native envelope and partial evidence without guessing retryability from undocumented codes.
50
+
51
+ Abort, deadlines, disconnects and early iterator return close the stream and retain available evidence. Once provider output has reached the
52
+ client, retry and fallback are prohibited. An unexposed internal `finalResult()` drain retains normal retry policy. Default receipts omit
53
+ prompts, reasoning, raw results and credentials. Qualification uses synthetic transport fixtures through both public interfaces.
@@ -0,0 +1,62 @@
1
+ # OpenAI Responses mapping
2
+
3
+ This guide describes the unpublished `0.4.0-rc.1` runtime's `openai-responses` adapter, version `2.0.0`, contract 2. Both client coding styles use the OpenAI Responses endpoint. The public compatibility interfaces cover the documented shared contract; they are not full OpenAI SDK replacements.
4
+
5
+ The final-call mapping was reviewed on 21 October 2026 against the [official Responses SDK source at commit b4e8176](https://github.com/openai/openai-node/blob/b4e8176a7a9c598fee0615548c77d637a6990f40/src/resources/responses/responses.ts) and the [function-calling guide](https://developers.openai.com/api/docs/guides/function-calling). Public streaming was qualified against the [streaming-events reference](https://developers.openai.com/api/reference/resources/responses/streaming-events) on 22 October. Adopting a future mapping requires a reviewed version change. Synthetic tests do not establish live model/account availability.
6
+
7
+ ## Requests and client tools
8
+
9
+ The adapter carries ordered roles, text, URL/base64 images with detail, function declarations, tool selection, parallel calls and client-supplied results. Call IDs remain distinct from output item IDs. Original argument strings, including malformed strings, remain available for the client to inspect. The runtime does not execute functions or run the client's loop.
10
+
11
+ String function results pass through unchanged; other JSON results are serialized, preserving false, zero, empty objects and null. A canonical function result with `isError: true` becomes the JSON string `{"is_error":true,"output":...}` because this protocol has no separate function-result error flag.
12
+
13
+ Shared fields own model, instructions/history, tools, output format, reasoning effort and output limits. Selected OpenAI native options preserve additional siblings such as verbosity, reasoning summaries, metadata and service tier. Options for another provider are never transmitted to OpenAI. `conversation`, `prompt` and `background` are reserved: they would bypass runtime-owned history/instructions or require asynchronous polling outside this interface. See [migration notes](MIGRATION.md) for extension precedence and registration.
14
+
15
+ Native web search can coexist with client functions. Search restrictions and options pass through; the adapter requests search-source inclusion. Search results and citations remain available in the full native body. Hosted tool charges are not inferred from token prices.
16
+
17
+ ## Results and continuation
18
+
19
+ The result retains ordered messages, refusals, function calls, reasoning/search items and unknown native items. Message phase, annotations, log probabilities and function metadata remain in native replay data. Both coding styles expose canonical `items`, `native`, `continuation`, usage and the execution receipt; Responses output can also be appended to a later input.
20
+
21
+ Stored response IDs are reused only through the runtime's exact-bound continuation rules. With `store: false`, the adapter requests encrypted reasoning content and preserves full replay history instead. Provider-reported `store: false` also prevents response-ID reuse. Portable history survives a provider/model switch, while incompatible native metadata is stripped with diagnostics.
22
+
23
+ Rich interfaces return refused and incomplete outcomes with their received data and usage. Legacy generation retains its terminal-error policy. Failed/malformed responses retain native and partial evidence on explicit error properties. HTTP classification remains authoritative even if the body reports a different error code. Queued/in-progress responses are rejected; no hidden polling occurs. Receipts and default error serialization omit unrestricted provider bodies.
24
+
25
+ ## Usage and pricing
26
+
27
+ Reported input, output, cached-input, cache-write and reasoning counters retain explicit zeros; absent counters stay unknown. Cache and reasoning counters are subsets, not additional tokens. Known web-search calls are counted; an unrecognized hosted call prevents a claim of complete tool metering. A returned non-default service tier or hosted tool can make cost unknown even when the request did not select one. Only bounded uncertainty codes reach persisted receipts.
28
+
29
+ ## Public streaming
30
+
31
+ `stream: true` sends an incremental Responses request through either client coding style. The returned stream is single-consumer and pulls on
32
+ demand. `finalResult()` can drain it directly or return the same completed result after iteration. `abort()` and early iterator return cancel the
33
+ underlying reader and settle one canonical receipt.
34
+
35
+ ```ts
36
+ import type { AIRun } from '@techis/ai-runtime';
37
+
38
+ export async function explainStream(run: AIRun, renderText: (text: string) => void, renderRefusal: (text: string) => void) {
39
+ const stream = run.responses.create({ input: 'Explain this result', stream: true }, { operationId: 'explain.stream' });
40
+ for await (const event of stream) {
41
+ if (event.type === 'response.output_text.delta') renderText(event.delta);
42
+ if (event.type === 'response.refusal.delta') renderRefusal(event.delta);
43
+ }
44
+ return stream.finalResult();
45
+ }
46
+ ```
47
+
48
+ Responses events carry stable output-item/content indexes. Chat chunks carry incremental content, refusal, reasoning and function arguments;
49
+ tool indexes are distinct from output indexes, and call IDs differ from item IDs. Requested Chat usage appears in the optional final usage chunk.
50
+ Canonical item/content completion events precede the public terminal result. Original provider event ordering remains available in `runtime.native`
51
+ events and the final `native.events`, including provider sequence numbers, SSE names/IDs, unknown fields and future event types. Unknown preludes
52
+ are retained within the transport bound until the response identity is available.
53
+
54
+ Thinking summaries, encrypted reasoning, citations, hosted-search results and tool arguments retain their native forms. Parallel function deltas
55
+ can interleave; calls are finalized once and returned for client execution. Streaming never runs a tool loop. Continuation follows the same stored
56
+ ID or complete stateless replay rules as final calls.
57
+
58
+ Malformed JSON/UTF-8, inconsistent indexes/IDs, duplicate sequences, contradictory final text/arguments and EOF before a terminal response fail
59
+ explicitly. Shared limits are 1 MiB per SSE frame and 32 MiB aggregate, with additional canonical result bounds. Refusal and incomplete output are
60
+ distinct outcomes; failed streams retain observed content, native events and cumulative usage. Default serialized errors and receipts omit those
61
+ sensitive bodies. A retry/fallback can occur before provider output is exposed; once any provider-derived event reaches the consumer, that
62
+ invocation cannot switch providers. An internal `finalResult()` drain exposes no intermediate events and retains the pre-exposure retry policy.
package/README.md CHANGED
@@ -1,22 +1,59 @@
1
1
  # @techis/ai-runtime
2
2
 
3
- Release 0.3.0-rc.15. Registry installation is available after this version is published.
4
-
5
- TECHIS AI Runtime executes application-defined AI work through versioned configuration. It resolves a persona to an execution profile, applies model-specific reasoning controls, follows bounded retries and ordered fallbacks, and returns a terminal execution receipt.
6
-
7
- ## Install the approved prerelease
8
-
9
- Once published:
10
-
11
- ```sh
12
- npm install @techis/ai-runtime@0.3.0-rc.15
3
+ The Embedded Models adoption candidate adds direct stable-Route-ID selection, anonymous JSON/file sources, host-owned durable
4
+ import/qualification/activation/rollback, readiness and optional required-feature policies. `createModelRun` executes one exact model and
5
+ settings through the common engine and emits a separate truthful `DirectModelExecutionReceipt`. See [the API additions](API.md).
6
+ Applications retain their instructions, provider credentials, functions, execution-point assignments and orchestration. Qualification uses
7
+ Node 24.20.0 on Windows x64; other runtime/platform combinations need their own checks.
8
+
9
+ ## Request routes and route sets
10
+
11
+ New integrations use `RequestRoute`, `routeId`, `routeName`, `RouteSet` and `routeSetId`. A request route contains a primary model,
12
+ its settings and optional ordered backups; a route set collects named routes for loading together. Use `createAIClient` with
13
+ `routeSetSource(createHttpRouteSetResolver(...))` and `startRun({ routeName, systemInstructions })`, or `createRequestRouteRun` for
14
+ an independently held route. The host supplies provider credentials and endpoints. Workspace/persona registration is unnecessary.
15
+
16
+ The source repository includes docs/request-routes.md and docs/route-terminology-migration-2026-10-30.md. The runtime package includes the matching API.md and MIGRATION.md guides.
17
+ Old profile/model-configuration SDK names remain deprecated compatibility paths; their historical examples below retain those signatures.
18
+ Canonical route-set snapshots use schema 5; route execution receipts use schema 6. Existing identifiers, history and old JSON remain readable
19
+ through the supplied codecs. Packages and remote services have not been published or deployed by this local change.
20
+
21
+
22
+ The current source is the unpublished `0.4.0-rc.4` preview candidate. Local archive qualification does not mean this version is available from a registry. Runtime requires the exactly matching `@techis/ai-contracts` dependency. Qualification uses Node.js 24.20.0 on Windows x64.
23
+
24
+ TECHIS AI Runtime executes application-defined work through versioned configuration: pinned models and instructions, independent primary/backup controls, bounded retries, cancellation and one terminal execution receipt. Applications own their functions, tool loops and workflows. Provider adapters carry provider-hosted search.
25
+
26
+ Runs expose both `responses.create` and `chat.completions.create` coding styles, plus the existing final-result `generate` API. The styles help clients preserve familiar call shapes; they cover the documented shared contract, not every member of a provider SDK. Both styles use the same configured routing and native adapter. OpenAI outbound requests use Responses.
27
+
28
+ ## Read the guides
29
+
30
+ - [API guide](API.md): setup, both styles, supported fields, results, streaming, tools, native options, errors and timing.
31
+ - [Migration](MIGRATION.md): existing callers, deliberate behavior changes, version pairing, explicit adoption and recovery.
32
+ - [Adapter authoring](ADAPTER-AUTHORING.md) and [conformance](ADAPTER-CONFORMANCE.md): per-client additions/replacements, contract versions and synthetic qualification.
33
+ - Native mappings: [OpenAI Responses](OPENAI-RESPONSES.md), [Z.AI Chat](ZAI-CHAT.md), [Gemini Interactions v1](GEMINI-INTERACTIONS.md), [Moonshot Chat](MOONSHOT-CHAT.md), [Anthropic Messages](ANTHROPIC-MESSAGES.md).
34
+
35
+ ## Call a configured run
36
+
37
+ This function accepts host-owned configuration, credentials and a persona already present in that configuration. Invoking it can make provider calls and incur provider charges. A catalog alone is not an execution configuration.
38
+
39
+ ```ts
40
+ import { createAIClient, type CreateAIClientOptions } from '@techis/ai-runtime';
41
+
42
+ export async function explain(options: CreateAIClientOptions, personaId: string, input: string, signal: AbortSignal) {
43
+ const client = createAIClient(options);
44
+ const workflow = await client.captureWorkflow();
45
+ const run = await workflow.startRun({ personaId });
46
+ return run.responses.create({ input }, {
47
+ operationId: 'explain', signal, execution: { timingPolicy: 'caller', deadlineMs: 300_000 }
48
+ });
49
+ }
13
50
  ```
14
51
 
15
- npm installs the exactly matching `@techis/ai-contracts` dependency automatically. Node.js 20.19 or later is required; qualification used Node.js 24.20.0. This package does not require Studio or the management packages.
52
+ Supply an inline snapshot, an exported bundle through `bundleSource({ directory })`, or another supported configuration source. A named-configuration client instead resolves an application/configuration/workspace identity and starts a run with `bindingId`; see the [API guide](API.md#configuration-and-pins). Keep credentials in the trusted host.
16
53
 
17
- ## Inspect the packaged catalog without a model call
54
+ ## Inspect the packaged catalog locally
18
55
 
19
- ```js
56
+ ```ts
20
57
  import { getInstalledCatalogDelivery, RUNTIME_VERSION } from '@techis/ai-runtime';
21
58
 
22
59
  const delivery = getInstalledCatalogDelivery();
@@ -25,32 +62,8 @@ console.log(delivery.release.catalog.models.map(model => model.displayName));
25
62
  console.log(delivery.profiles.map(offer => offer.name));
26
63
  ```
27
64
 
28
- Catalog inspection does not contact a provider, select a profile or change application configuration. A package update makes its reviewed catalog available; adoption and exact profile selection remain explicit application decisions. Existing captured workflows keep their pinned configuration.
29
-
30
- ## Execute application work
31
-
32
- Create a client with `createAIClient`, your application/environment identity and a validated configuration source. The source supplies catalog, profiles, personas, assignments and manifest references; a catalog by itself is not a complete execution configuration. Supported sources include an inline snapshot and an exported bundle via `bundleSource({ directory })`. Supply a host-owned credential resolver and appropriate provider access. Capture a workflow or start a run for a configured persona, then call `generate` with your input and operation ID. Exported TypeScript declarations describe configuration and receipt interfaces.
33
-
34
- The configured profile determines primary/fallback order and independent reasoning settings. Provider availability, entitlements and charges remain the application's responsibility. Do not expose provider credentials in client-side code. Model/API calls are not free merely because runtime use is free.
35
-
36
- ## Caller-owned timing and cancellation
37
-
38
- Pass a workflow AbortSignal to every generation. Opt in per call with:
39
-
40
- ```js
41
- await run.generate({ input, operationId: 'research.synthesize', signal: workflowSignal,
42
- execution: { timingPolicy: 'caller', deadlineMs: 300_000 } });
43
- ```
44
-
45
- Each call starts its own total budget, including queue waits, credential resolution, attempts, backoff and fallback.
46
- Set attemptTimeoutMs to add a per-attempt bound; omit it to use the remaining total budget without a hidden 60-second ceiling.
47
- Omit both timers in caller mode to rely on cancellation and provider/transport limits. Cancellation rejects queued/late work,
48
- stops HTTP, discards late results and prevents subsequent retry/fallback. Custom transports must honour AbortSignal to stop their own work.
49
- Omitting timingPolicy retains legacy profile/default timing. No profile identity, history or saved selection is rewritten.
65
+ Inspection verifies the delivery's integrity and makes no provider call or adoption. The preview pair includes a compatible current envelope over the exact accepted payload and retains every historical delivery and the original trust root. `createCatalogDeliveryClient.check()` verifies the complete history and requires a compatible resulting head before saving the inbox; historical notices do not authorize adoption of old incompatible offers. Consumer selection remains explicit, and captured workflows retain their pins across refreshes. See [catalog upgrades](MIGRATION.md#catalog-inbox-upgrades).
50
66
 
51
67
  ## Licensing and notices
52
68
 
53
- TECH-IS INC. licenses its material under the included [TECHIS Developer Integration License](LICENSE): free integration,
54
- including commercial applications, subject to its terms. Third-party dependencies retain their own licences; see
55
- [THIRD_PARTY_NOTICES](THIRD_PARTY_NOTICES) and accompanying full texts. Compiled JavaScript is inspectable.
56
- Provider/API charges remain separate. Legal and permission enquiries: arinze@techinceptions.com.
69
+ TECH-IS INC. licenses its material under the included [TECHIS Developer Integration License](LICENSE): free integration, including commercial applications, subject to its terms. Third-party dependencies retain their own licences; see [THIRD_PARTY_NOTICES](THIRD_PARTY_NOTICES) and accompanying full texts. Compiled JavaScript is inspectable. Provider/API charges remain separate. Legal and permission enquiries: arinze@techinceptions.com.
@@ -1,34 +1,34 @@
1
- THIRD-PARTY NOTICES
2
-
3
- The TECHIS Developer Integration License covers only TECHIS-owned material in runtime/contracts. Third-party rights remain independent. These archives do not bundle the dependency implementations. The following full upstream licence texts are included for the locked dependency versions and downstream bundling. Semver ranges can resolve other versions; preserve the notices for the versions actually distributed. TypeScript is a compiler reference only, not a runtime dependency or TECHIS-owned code.
4
-
5
- ajv@8.20.0 - MIT
6
- external npm dependency; not bundled in the runtime/contracts archives
7
- third-party-licenses/ajv@8.20.0/LICENSE
8
-
9
- fast-deep-equal@3.1.3 - MIT
10
- external npm dependency; not bundled in the runtime/contracts archives
11
- third-party-licenses/fast-deep-equal@3.1.3/LICENSE
12
-
13
- fast-uri@3.1.7 - BSD-3-Clause
14
- external npm dependency; not bundled in the runtime/contracts archives
15
- third-party-licenses/fast-uri@3.1.7/LICENSE
16
-
17
- json-schema-traverse@1.0.0 - MIT
18
- external npm dependency; not bundled in the runtime/contracts archives
19
- third-party-licenses/json-schema-traverse@1.0.0/LICENSE
20
-
21
- require-from-string@2.0.2 - MIT
22
- external npm dependency; not bundled in the runtime/contracts archives
23
- third-party-licenses/require-from-string@2.0.2/license
24
-
25
- ajv-formats@3.0.1 - MIT
26
- external npm dependency; not bundled in the runtime/contracts archives
27
- third-party-licenses/ajv-formats@3.0.1/LICENSE
28
-
29
- typescript@5.9.3 - Apache-2.0
30
- compiler reference only; not shipped
31
- third-party-licenses/typescript@5.9.3/LICENSE.txt
32
- third-party-licenses/typescript@5.9.3/ThirdPartyNoticeText.txt
33
-
34
- See third-party-licenses.json for exact notice hashes and scope.
1
+ THIRD-PARTY NOTICES
2
+
3
+ The TECHIS Developer Integration License covers only TECHIS-owned material in runtime/contracts. Third-party rights remain independent. These archives do not bundle the dependency implementations. The following full upstream licence texts are included for the locked dependency versions and downstream bundling. Semver ranges can resolve other versions; preserve the notices for the versions actually distributed. TypeScript is a compiler reference only, not a runtime dependency or TECHIS-owned code.
4
+
5
+ ajv@8.20.0 - MIT
6
+ external npm dependency; not bundled in the runtime/contracts archives
7
+ third-party-licenses/ajv@8.20.0/LICENSE
8
+
9
+ fast-deep-equal@3.1.3 - MIT
10
+ external npm dependency; not bundled in the runtime/contracts archives
11
+ third-party-licenses/fast-deep-equal@3.1.3/LICENSE
12
+
13
+ fast-uri@3.1.9 - BSD-3-Clause
14
+ external npm dependency; not bundled in the runtime/contracts archives
15
+ third-party-licenses/fast-uri@3.1.9/LICENSE
16
+
17
+ json-schema-traverse@1.0.0 - MIT
18
+ external npm dependency; not bundled in the runtime/contracts archives
19
+ third-party-licenses/json-schema-traverse@1.0.0/LICENSE
20
+
21
+ require-from-string@2.0.2 - MIT
22
+ external npm dependency; not bundled in the runtime/contracts archives
23
+ third-party-licenses/require-from-string@2.0.2/license
24
+
25
+ ajv-formats@3.0.1 - MIT
26
+ external npm dependency; not bundled in the runtime/contracts archives
27
+ third-party-licenses/ajv-formats@3.0.1/LICENSE
28
+
29
+ typescript@5.9.3 - Apache-2.0
30
+ compiler reference only; not shipped
31
+ third-party-licenses/typescript@5.9.3/LICENSE.txt
32
+ third-party-licenses/typescript@5.9.3/ThirdPartyNoticeText.txt
33
+
34
+ See third-party-licenses.json for exact notice hashes and scope.
package/ZAI-CHAT.md ADDED
@@ -0,0 +1,35 @@
1
+ # Z.AI Chat mapping
2
+
3
+ The unpublished `0.4.0-rc.1` source includes `zai-chat-completions` adapter `2.0.0`, contract 2. Both client coding styles use Z.AI's native Chat endpoint. The [Chat reference](https://docs.z.ai/api-reference/llm/chat-completion), [OpenAPI](https://docs.z.ai/openapi.json), [function guide](https://docs.z.ai/guides/capabilities/function-calling) and [thinking guide](https://docs.z.ai/guides/capabilities/thinking-mode) were reviewed on 21 October 2026; streaming references were reviewed on 22 October. This qualifies synthetic final and public-streaming protocol behavior; live account/model access remains a separate check.
4
+
5
+ ## Calls, results and continuation
6
+
7
+ The adapter carries ordered system/user/assistant history, text, URL/base64 images, function definitions, automatic tool selection, multiple returned calls and client results. Developer messages map to system with a diagnostic. Image detail, explicit parallel-call control, storage control and response-ID continuation are not documented by this protocol. Unsupported primary controls fail before credentials; backups warn and continue after omitting the unsupported controls.
8
+
9
+ Function calls preserve IDs and original string/object arguments in canonical output and native data. Replay serializes object arguments as JSON. The adapter groups adjacent canonical calls into one assistant message and returns client results in their supplied order. It does not execute tools. Non-string results are serialized; `isError: true` uses a JSON envelope with `is_error` and `output` because the protocol lacks a separate error flag.
10
+
11
+ Each assistant native snapshot preserves `reasoning_content` and other fields. Continuation and appended Responses output replay those fields with the calls exactly once. Use the continuation envelope with the Chat-style client when reasoning/native metadata is needed. `providerOptions.zai.thinking.clear_thinking: false` is preserved alongside runtime-owned reasoning controls. The provider's interleaved/preserved thinking rules require complete, unmodified reasoning history; it remains caller-controlled sensitive data.
12
+
13
+ The result retains full native JSON, search references, unknown fields, request IDs and any reported usage. `length` and `model_context_window_exceeded` produce incomplete outcomes; `sensitive` and explicit refusals produce refused outcomes. A provider network finish becomes a retryable error with partial evidence. Other malformed/unknown terminal states fail explicitly. HTTP classification remains authoritative. Legacy generation retains its terminal-error policy. Receipts omit unrestricted native data.
14
+
15
+ ## Schema and search limits
16
+
17
+ The reviewed protocol supports automatic function selection, not required/named/none selection. It does not document strict function argument enforcement. The adapter declares these limits through `requestCapabilities`; backups retain function definitions with an explicit warning when strict enforcement is unavailable.
18
+
19
+ JSON-schema requests use schema instructions and native JSON-object mode, followed by runtime validation of completed output. Diagnostics distinguish this from provider-enforced JSON Schema; no native strict-schema guarantee is made. Function/tool outcomes are returned to the client without misclassifying them as invalid schema output.
20
+
21
+ Hosted search can coexist with client functions. Current Chat search uses `search_pro_jina`, boolean flags and numeric counts. Common search options map `medium`/`high` context size and a single allowed domain. Unsupported common restrictions fail on the primary or are omitted with backup warnings. The selected `providerOptions.zai.web_search` object supplies native search-only fields such as `search_query`, `count`, `search_recency_filter`, `require_search` and `result_sequence`; it is consumed inside the search tool, not emitted as a top-level field. A hosted-search declaration is required. Runtime-owned enablement and shared restrictions take precedence over native siblings.
22
+
23
+ Usage preserves zero versus absent values, including cached input and any reported reasoning/cache-write detail. Search result count is not treated as invocation count or a tool-call cap. Unreported tool/cache pricing remains unknown. Source/specification changes require reviewed adapter/package versions and explicit consumer adoption.
24
+
25
+ ## Public streaming
26
+
27
+ Set `stream: true` on either public client interface and iterate the returned stream, then call `finalResult()` for the complete result and receipt. Calling `finalResult()` first drains the stream internally. `abort()` and early iterator return cancel the active request. Text, refusal, reasoning and indexed function arguments are incremental; the runtime never invokes returned functions.
28
+
29
+ The adapter sends native `stream: true` and adds `tool_stream: true` when client function definitions are present. Both are runtime-owned fields, so `providerOptions.zai.tool_stream` rejects as a collision. Chat-style `stream_options.include_usage` controls the client projection and is not sent to Z.AI. The [API reference](https://docs.z.ai/api-reference/llm/chat-completion) lists tool streaming for GLM-5.3/5.2/5.1/5 and GLM-4.7/4.6. The [tool-stream guide](https://docs.z.ai/guides/capabilities/stream-tool) still has a narrower GLM-5-only note despite using GLM-5.3 in its example; the API reference governs this mapping. Model/account qualification is still required.
30
+
31
+ Every original JSON chunk and the `[DONE]` sentinel remain in `native.events`, including SSE IDs/event names and unknown fields. `native.body` is an assembled Chat message, not a separately received final JSON response. Text, refusal, reasoning and string arguments concatenate; one complete object argument remains an object. Interleaved calls retain their indexes, IDs and names. Source and annotation arrays append in arrival order, usage details merge as cumulative reports, and other native metadata takes the latest reported value. Exact original chunks remain available even when metadata is replaced. The assembled assistant message preserves reasoning and native call data for client-owned continuation.
32
+
33
+ The parser requires one choice at index zero, stable response/model identities, dense final tool indexes, a recognized non-null finish reason and the [documented completion sentinel](https://docs.z.ai/guides/capabilities/streaming). It accepts late usage-only chunks before `[DONE]`. Premature EOF, contradictory IDs/names, deltas after the finish, malformed JSON/UTF-8 and oversized responses fail with partial native evidence. Function argument strings are not repaired or parsed into guessed objects. A finish reason alone is not successful completion.
34
+
35
+ Refusal, incomplete output and provider errors retain their actual outcomes and reported usage. The shared 1 MiB frame/32 MiB transport bounds, backpressure, deadlines and one-terminal-receipt rules apply. A failure after provider data reaches the caller cannot switch to another provider; unexposed internal drains retain the normal retry policy. Default receipts omit prompts, reasoning, arguments, search bodies and credentials.
@@ -0,0 +1,14 @@
1
+ import { type ModelDefinition, type NativeReasoningControl } from "@techis/ai-contracts";
2
+ import type { NativeSettings, ProviderRequestCapabilities } from "./types.js";
3
+ export declare const ANTHROPIC_IDENTITY: {
4
+ readonly provider: "anthropic";
5
+ readonly adapterId: "anthropic-messages";
6
+ readonly adapterVersion: "2.0.0";
7
+ };
8
+ export declare const ANTHROPIC_API_VERSION = "2026-10-21";
9
+ export declare const supportsInlineSystem: (model: ModelDefinition) => boolean;
10
+ /** Reviewed version/model limits, independent of catalog discovery or account access. */
11
+ export declare function anthropicCapabilities(model: ModelDefinition, control?: NativeReasoningControl): ProviderRequestCapabilities;
12
+ /** https://platform.claude.com/docs/en/build-with-claude/thinking */
13
+ export declare function anthropicReasoning(model: ModelDefinition, control: NativeReasoningControl): NativeSettings;
14
+ //# sourceMappingURL=anthropic-capabilities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic-capabilities.d.ts","sourceRoot":"","sources":["../../src/adapters/anthropic-capabilities.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,eAAe,EAAE,KAAK,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAEpH,OAAO,KAAK,EAAE,cAAc,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAC;AAE9E,eAAO,MAAM,kBAAkB;;;;CAA+F,CAAC;AAC/H,eAAO,MAAM,qBAAqB,eAAe,CAAC;AAalD,eAAO,MAAM,oBAAoB,GAAI,OAAO,eAAe,YAAuC,CAAC;AAEnG,yFAAyF;AACzF,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,eAAe,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG,2BAA2B,CAQ3H;AAED,qEAAqE;AACrE,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,sBAAsB,GAAG,cAAc,CA4B1G"}