@theoremjs/agents 0.0.0-stage → 0.3.1

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 (588) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +545 -2
  3. package/esm/_dnt.polyfills.d.ts +66 -0
  4. package/esm/_dnt.polyfills.js +51 -0
  5. package/esm/mod.d.ts +79 -0
  6. package/esm/mod.js +49 -0
  7. package/esm/package.json +3 -0
  8. package/esm/src/cli/bin.d.ts +7 -0
  9. package/esm/src/cli/bin.js +9 -0
  10. package/esm/src/cli/commands/bench.d.ts +6 -0
  11. package/esm/src/cli/commands/bench.js +480 -0
  12. package/esm/src/cli/commands/detect-compile.d.ts +17 -0
  13. package/esm/src/cli/commands/detect-compile.js +22 -0
  14. package/esm/src/cli/commands/eval.d.ts +37 -0
  15. package/esm/src/cli/commands/eval.js +190 -0
  16. package/esm/src/cli/commands/fuzz-canary.d.ts +15 -0
  17. package/esm/src/cli/commands/fuzz-canary.js +241 -0
  18. package/esm/src/cli/commands/fuzz-guardrails.d.ts +2 -0
  19. package/esm/src/cli/commands/fuzz-guardrails.js +5 -0
  20. package/esm/src/cli/commands/profile.d.ts +2 -0
  21. package/esm/src/cli/commands/profile.js +80 -0
  22. package/esm/src/cli/commands/run.d.ts +13 -0
  23. package/esm/src/cli/commands/run.js +45 -0
  24. package/esm/src/cli/commands/test.d.ts +26 -0
  25. package/esm/src/cli/commands/test.js +143 -0
  26. package/esm/src/cli/event-log.d.ts +15 -0
  27. package/esm/src/cli/event-log.js +136 -0
  28. package/esm/src/cli/index.d.ts +10 -0
  29. package/esm/src/cli/index.js +267 -0
  30. package/esm/src/cli/matrix/fixtures.d.ts +10 -0
  31. package/esm/src/cli/matrix/fixtures.js +67 -0
  32. package/esm/src/cli/matrix/synthesizer.d.ts +18 -0
  33. package/esm/src/cli/matrix/synthesizer.js +103 -0
  34. package/esm/src/evals/attachments.d.ts +5 -0
  35. package/esm/src/evals/attachments.js +55 -0
  36. package/esm/src/evals/breakdown.d.ts +30 -0
  37. package/esm/src/evals/breakdown.js +69 -0
  38. package/esm/src/evals/graders/answer.d.ts +16 -0
  39. package/esm/src/evals/graders/answer.js +134 -0
  40. package/esm/src/evals/graders/code.d.ts +40 -0
  41. package/esm/src/evals/graders/code.js +184 -0
  42. package/esm/src/evals/graders/judge.d.ts +24 -0
  43. package/esm/src/evals/graders/judge.js +367 -0
  44. package/esm/src/evals/graders/latency.d.ts +6 -0
  45. package/esm/src/evals/graders/latency.js +82 -0
  46. package/esm/src/evals/graders/live.d.ts +14 -0
  47. package/esm/src/evals/graders/live.js +42 -0
  48. package/esm/src/evals/graders/media.d.ts +18 -0
  49. package/esm/src/evals/graders/media.js +91 -0
  50. package/esm/src/evals/graders/shared.d.ts +11 -0
  51. package/esm/src/evals/graders/shared.js +62 -0
  52. package/esm/src/evals/graders/transcript.d.ts +19 -0
  53. package/esm/src/evals/graders/transcript.js +202 -0
  54. package/esm/src/evals/mod.d.ts +34 -0
  55. package/esm/src/evals/mod.js +22 -0
  56. package/esm/src/evals/record.d.ts +41 -0
  57. package/esm/src/evals/record.js +107 -0
  58. package/esm/src/evals/rubrics/catalog.d.ts +148 -0
  59. package/esm/src/evals/rubrics/catalog.js +846 -0
  60. package/esm/src/evals/rubrics/mod.d.ts +24 -0
  61. package/esm/src/evals/rubrics/mod.js +55 -0
  62. package/esm/src/evals/rubrics/mustache.d.ts +23 -0
  63. package/esm/src/evals/rubrics/mustache.js +154 -0
  64. package/esm/src/evals/rubrics/types.d.ts +54 -0
  65. package/esm/src/evals/rubrics/types.js +74 -0
  66. package/esm/src/evals/run.d.ts +75 -0
  67. package/esm/src/evals/run.js +418 -0
  68. package/esm/src/evals/suite.d.ts +28 -0
  69. package/esm/src/evals/suite.js +97 -0
  70. package/esm/src/evals/summary.d.ts +35 -0
  71. package/esm/src/evals/summary.js +31 -0
  72. package/esm/src/evals/trial.d.ts +14 -0
  73. package/esm/src/evals/trial.js +135 -0
  74. package/esm/src/evals/types.d.ts +169 -0
  75. package/esm/src/evals/types.js +113 -0
  76. package/esm/src/evals/verdict.d.ts +23 -0
  77. package/esm/src/evals/verdict.js +48 -0
  78. package/esm/src/guardrails/boundaries.d.ts +41 -0
  79. package/esm/src/guardrails/boundaries.js +103 -0
  80. package/esm/src/guardrails/canary-gate.d.ts +22 -0
  81. package/esm/src/guardrails/canary-gate.js +40 -0
  82. package/esm/src/guardrails/canary.d.ts +146 -0
  83. package/esm/src/guardrails/canary.js +974 -0
  84. package/esm/src/guardrails/compile-egress.d.ts +12 -0
  85. package/esm/src/guardrails/compile-egress.js +12 -0
  86. package/esm/src/guardrails/corpus/canary-egress-attacks.d.ts +24 -0
  87. package/esm/src/guardrails/corpus/canary-egress-attacks.js +305 -0
  88. package/esm/src/guardrails/corpus/fuzz-inbound.d.ts +5 -0
  89. package/esm/src/guardrails/corpus/fuzz-inbound.js +199 -0
  90. package/esm/src/guardrails/corpus/inbound-payloads.d.ts +5 -0
  91. package/esm/src/guardrails/corpus/inbound-payloads.js +120 -0
  92. package/esm/src/guardrails/corpus/live-attacks.d.ts +15 -0
  93. package/esm/src/guardrails/corpus/live-attacks.js +229 -0
  94. package/esm/src/guardrails/corpus/mod.d.ts +7 -0
  95. package/esm/src/guardrails/corpus/mod.js +4 -0
  96. package/esm/src/guardrails/corpus/secrets.d.ts +12 -0
  97. package/esm/src/guardrails/corpus/secrets.js +16 -0
  98. package/esm/src/guardrails/corpus/strings.d.ts +23 -0
  99. package/esm/src/guardrails/corpus/strings.js +29 -0
  100. package/esm/src/guardrails/corpus/types.d.ts +36 -0
  101. package/esm/src/guardrails/corpus/types.js +1 -0
  102. package/esm/src/guardrails/credential-rules.d.ts +36 -0
  103. package/esm/src/guardrails/credential-rules.js +3001 -0
  104. package/esm/src/guardrails/credential-scan.d.ts +45 -0
  105. package/esm/src/guardrails/credential-scan.js +172 -0
  106. package/esm/src/guardrails/destinations.d.ts +45 -0
  107. package/esm/src/guardrails/destinations.js +234 -0
  108. package/esm/src/guardrails/detect-at.d.ts +107 -0
  109. package/esm/src/guardrails/detect-at.js +434 -0
  110. package/esm/src/guardrails/detect-reply.d.ts +61 -0
  111. package/esm/src/guardrails/detect-reply.js +95 -0
  112. package/esm/src/guardrails/detect-stream.d.ts +33 -0
  113. package/esm/src/guardrails/detect-stream.js +77 -0
  114. package/esm/src/guardrails/detectors.d.ts +216 -0
  115. package/esm/src/guardrails/detectors.js +503 -0
  116. package/esm/src/guardrails/egress-automata.d.ts +12 -0
  117. package/esm/src/guardrails/egress-automata.js +25582 -0
  118. package/esm/src/guardrails/egress-compiler.d.ts +55 -0
  119. package/esm/src/guardrails/egress-compiler.js +431 -0
  120. package/esm/src/guardrails/egress-patterns.d.ts +26 -0
  121. package/esm/src/guardrails/egress-patterns.js +36 -0
  122. package/esm/src/guardrails/egress-stream.d.ts +123 -0
  123. package/esm/src/guardrails/egress-stream.js +774 -0
  124. package/esm/src/guardrails/egress-urls.d.ts +86 -0
  125. package/esm/src/guardrails/egress-urls.js +909 -0
  126. package/esm/src/guardrails/egress.d.ts +46 -0
  127. package/esm/src/guardrails/egress.js +124 -0
  128. package/esm/src/guardrails/error.d.ts +31 -0
  129. package/esm/src/guardrails/error.js +96 -0
  130. package/esm/src/guardrails/event-schemas.d.ts +100 -0
  131. package/esm/src/guardrails/event-schemas.js +48 -0
  132. package/esm/src/guardrails/events.d.ts +13 -0
  133. package/esm/src/guardrails/events.js +45 -0
  134. package/esm/src/guardrails/hints.d.ts +14 -0
  135. package/esm/src/guardrails/hints.js +57 -0
  136. package/esm/src/guardrails/hits.d.ts +14 -0
  137. package/esm/src/guardrails/hits.js +30 -0
  138. package/esm/src/guardrails/host-patterns.d.ts +85 -0
  139. package/esm/src/guardrails/host-patterns.js +173 -0
  140. package/esm/src/guardrails/injection-patterns.d.ts +20 -0
  141. package/esm/src/guardrails/injection-patterns.js +126 -0
  142. package/esm/src/guardrails/injection-reversed.d.ts +9 -0
  143. package/esm/src/guardrails/injection-reversed.js +49 -0
  144. package/esm/src/guardrails/injection.d.ts +30 -0
  145. package/esm/src/guardrails/injection.js +460 -0
  146. package/esm/src/guardrails/labels.d.ts +40 -0
  147. package/esm/src/guardrails/labels.js +874 -0
  148. package/esm/src/guardrails/live-outbound-gate.d.ts +55 -0
  149. package/esm/src/guardrails/live-outbound-gate.js +298 -0
  150. package/esm/src/guardrails/mod.d.ts +54 -0
  151. package/esm/src/guardrails/mod.js +34 -0
  152. package/esm/src/guardrails/network.d.ts +46 -0
  153. package/esm/src/guardrails/network.js +330 -0
  154. package/esm/src/guardrails/normalize.d.ts +20 -0
  155. package/esm/src/guardrails/normalize.js +165 -0
  156. package/esm/src/guardrails/policy.d.ts +4 -0
  157. package/esm/src/guardrails/policy.js +21 -0
  158. package/esm/src/guardrails/progressive-yield.d.ts +110 -0
  159. package/esm/src/guardrails/progressive-yield.js +281 -0
  160. package/esm/src/guardrails/prompt-echo.d.ts +40 -0
  161. package/esm/src/guardrails/prompt-echo.js +306 -0
  162. package/esm/src/guardrails/quota.d.ts +21 -0
  163. package/esm/src/guardrails/quota.js +80 -0
  164. package/esm/src/guardrails/rules.d.ts +47 -0
  165. package/esm/src/guardrails/rules.js +47 -0
  166. package/esm/src/guardrails/sanitize.d.ts +40 -0
  167. package/esm/src/guardrails/sanitize.js +160 -0
  168. package/esm/src/guardrails/sensitive-groups.d.ts +21 -0
  169. package/esm/src/guardrails/sensitive-groups.js +12 -0
  170. package/esm/src/guardrails/sensitive.d.ts +22 -0
  171. package/esm/src/guardrails/sensitive.js +234 -0
  172. package/esm/src/guardrails/serialize.d.ts +15 -0
  173. package/esm/src/guardrails/serialize.js +37 -0
  174. package/esm/src/guardrails/testing.d.ts +11 -0
  175. package/esm/src/guardrails/testing.js +10 -0
  176. package/esm/src/guardrails/theorem-error.d.ts +21 -0
  177. package/esm/src/guardrails/theorem-error.js +54 -0
  178. package/esm/src/guardrails/thought-guard.d.ts +76 -0
  179. package/esm/src/guardrails/thought-guard.js +664 -0
  180. package/esm/src/guardrails/tool-directives.d.ts +38 -0
  181. package/esm/src/guardrails/tool-directives.js +195 -0
  182. package/esm/src/guardrails/tool-leak.d.ts +26 -0
  183. package/esm/src/guardrails/tool-leak.js +45 -0
  184. package/esm/src/guardrails/tool-result.d.ts +92 -0
  185. package/esm/src/guardrails/tool-result.js +272 -0
  186. package/esm/src/guardrails/types.d.ts +250 -0
  187. package/esm/src/guardrails/types.js +58 -0
  188. package/esm/src/host/client-turn.d.ts +36 -0
  189. package/esm/src/host/client-turn.js +80 -0
  190. package/esm/src/host/mint-trace.d.ts +29 -0
  191. package/esm/src/host/mint-trace.js +60 -0
  192. package/esm/src/host/mod.d.ts +13 -0
  193. package/esm/src/host/mod.js +11 -0
  194. package/esm/src/host/readStreamingJsonStringField.d.ts +2 -0
  195. package/esm/src/host/readStreamingJsonStringField.js +27 -0
  196. package/esm/src/host/reply.d.ts +13 -0
  197. package/esm/src/host/reply.js +41 -0
  198. package/esm/src/interface/blocks.d.ts +11 -0
  199. package/esm/src/interface/blocks.js +283 -0
  200. package/esm/src/interface/composer-actions.d.ts +24 -0
  201. package/esm/src/interface/composer-actions.js +33 -0
  202. package/esm/src/interface/draft.d.ts +20 -0
  203. package/esm/src/interface/draft.js +39 -0
  204. package/esm/src/interface/from-profile.d.ts +24 -0
  205. package/esm/src/interface/from-profile.js +179 -0
  206. package/esm/src/interface/history.d.ts +46 -0
  207. package/esm/src/interface/history.js +278 -0
  208. package/esm/src/interface/inputs.d.ts +11 -0
  209. package/esm/src/interface/inputs.js +67 -0
  210. package/esm/src/interface/mod.d.ts +33 -0
  211. package/esm/src/interface/mod.js +22 -0
  212. package/esm/src/interface/models.d.ts +26 -0
  213. package/esm/src/interface/models.js +50 -0
  214. package/esm/src/interface/pending.d.ts +57 -0
  215. package/esm/src/interface/pending.js +152 -0
  216. package/esm/src/interface/profile-interface.d.ts +4 -0
  217. package/esm/src/interface/profile-interface.js +237 -0
  218. package/esm/src/interface/session.d.ts +71 -0
  219. package/esm/src/interface/session.js +128 -0
  220. package/esm/src/interface/stop.d.ts +13 -0
  221. package/esm/src/interface/stop.js +28 -0
  222. package/esm/src/interface/tool-calls.d.ts +32 -0
  223. package/esm/src/interface/tool-calls.js +127 -0
  224. package/esm/src/interface/tool-invoke.d.ts +6 -0
  225. package/esm/src/interface/tool-invoke.js +22 -0
  226. package/esm/src/interface/tool-media.d.ts +11 -0
  227. package/esm/src/interface/tool-media.js +113 -0
  228. package/esm/src/interface/types.d.ts +278 -0
  229. package/esm/src/interface/types.js +5 -0
  230. package/esm/src/kernel/api-catalog.d.ts +85 -0
  231. package/esm/src/kernel/api-catalog.js +229 -0
  232. package/esm/src/kernel/auth/credential-source.d.ts +23 -0
  233. package/esm/src/kernel/auth/credential-source.js +11 -0
  234. package/esm/src/kernel/auth/crypto.d.ts +56 -0
  235. package/esm/src/kernel/auth/crypto.js +163 -0
  236. package/esm/src/kernel/auth/mod.d.ts +5 -0
  237. package/esm/src/kernel/auth/mod.js +5 -0
  238. package/esm/src/kernel/auth/oauth.d.ts +18 -0
  239. package/esm/src/kernel/auth/oauth.js +439 -0
  240. package/esm/src/kernel/auth/scope-refusal.d.ts +9 -0
  241. package/esm/src/kernel/auth/scope-refusal.js +8 -0
  242. package/esm/src/kernel/auth/typed-secret.d.ts +13 -0
  243. package/esm/src/kernel/auth/typed-secret.js +23 -0
  244. package/esm/src/kernel/auth/types.d.ts +152 -0
  245. package/esm/src/kernel/auth/types.js +1 -0
  246. package/esm/src/kernel/checkpoint.d.ts +43 -0
  247. package/esm/src/kernel/checkpoint.js +58 -0
  248. package/esm/src/kernel/default-scope.d.ts +72 -0
  249. package/esm/src/kernel/default-scope.js +121 -0
  250. package/esm/src/kernel/engine/call-trace.d.ts +19 -0
  251. package/esm/src/kernel/engine/call-trace.js +29 -0
  252. package/esm/src/kernel/engine/compaction.d.ts +71 -0
  253. package/esm/src/kernel/engine/compaction.js +203 -0
  254. package/esm/src/kernel/engine/decision.d.ts +43 -0
  255. package/esm/src/kernel/engine/decision.js +439 -0
  256. package/esm/src/kernel/engine/embedding.d.ts +8 -0
  257. package/esm/src/kernel/engine/embedding.js +118 -0
  258. package/esm/src/kernel/engine/hash.d.ts +6 -0
  259. package/esm/src/kernel/engine/hash.js +22 -0
  260. package/esm/src/kernel/engine/live-inbound.d.ts +19 -0
  261. package/esm/src/kernel/engine/live-inbound.js +44 -0
  262. package/esm/src/kernel/engine/live-ingress.d.ts +15 -0
  263. package/esm/src/kernel/engine/live-ingress.js +42 -0
  264. package/esm/src/kernel/engine/record.d.ts +3 -0
  265. package/esm/src/kernel/engine/record.js +11 -0
  266. package/esm/src/kernel/engine/repair.d.ts +7 -0
  267. package/esm/src/kernel/engine/repair.js +36 -0
  268. package/esm/src/kernel/engine/runner/gates.d.ts +5 -0
  269. package/esm/src/kernel/engine/runner/gates.js +508 -0
  270. package/esm/src/kernel/engine/runner/mod.d.ts +29 -0
  271. package/esm/src/kernel/engine/runner/mod.js +625 -0
  272. package/esm/src/kernel/engine/runner/nested.d.ts +32 -0
  273. package/esm/src/kernel/engine/runner/nested.js +134 -0
  274. package/esm/src/kernel/engine/runner/schema-validation.d.ts +35 -0
  275. package/esm/src/kernel/engine/runner/schema-validation.js +179 -0
  276. package/esm/src/kernel/engine/runner/stages.d.ts +28 -0
  277. package/esm/src/kernel/engine/runner/stages.js +41 -0
  278. package/esm/src/kernel/engine/runner/state.d.ts +97 -0
  279. package/esm/src/kernel/engine/runner/state.js +50 -0
  280. package/esm/src/kernel/engine/runner/step-order.d.ts +27 -0
  281. package/esm/src/kernel/engine/runner/step-order.js +165 -0
  282. package/esm/src/kernel/engine/runner/steps.d.ts +14 -0
  283. package/esm/src/kernel/engine/runner/steps.js +519 -0
  284. package/esm/src/kernel/engine/runner/stream.d.ts +71 -0
  285. package/esm/src/kernel/engine/runner/stream.js +376 -0
  286. package/esm/src/kernel/engine/runner/usage.d.ts +45 -0
  287. package/esm/src/kernel/engine/runner/usage.js +148 -0
  288. package/esm/src/kernel/engine/session/mod.d.ts +33 -0
  289. package/esm/src/kernel/engine/session/mod.js +1182 -0
  290. package/esm/src/kernel/engine/session/session-trace.d.ts +115 -0
  291. package/esm/src/kernel/engine/session/session-trace.js +500 -0
  292. package/esm/src/kernel/engine/token-estimate.d.ts +23 -0
  293. package/esm/src/kernel/engine/token-estimate.js +38 -0
  294. package/esm/src/kernel/engine/tool-trace.d.ts +58 -0
  295. package/esm/src/kernel/engine/tool-trace.js +132 -0
  296. package/esm/src/kernel/engine/tree.d.ts +2 -0
  297. package/esm/src/kernel/engine/tree.js +17 -0
  298. package/esm/src/kernel/engine/turn-trace.d.ts +119 -0
  299. package/esm/src/kernel/engine/turn-trace.js +855 -0
  300. package/esm/src/kernel/engine/usage.d.ts +36 -0
  301. package/esm/src/kernel/engine/usage.js +151 -0
  302. package/esm/src/kernel/interaction-parts.d.ts +13 -0
  303. package/esm/src/kernel/interaction-parts.js +40 -0
  304. package/esm/src/kernel/json.d.ts +10 -0
  305. package/esm/src/kernel/json.js +3 -0
  306. package/esm/src/kernel/mod.d.ts +74 -0
  307. package/esm/src/kernel/mod.js +45 -0
  308. package/esm/src/kernel/profile-graph.d.ts +145 -0
  309. package/esm/src/kernel/profile-graph.js +158 -0
  310. package/esm/src/kernel/profile-presence.d.ts +18 -0
  311. package/esm/src/kernel/profile-presence.js +158 -0
  312. package/esm/src/kernel/profile-scope.d.ts +40 -0
  313. package/esm/src/kernel/profile-scope.js +274 -0
  314. package/esm/src/kernel/protocols/binding.d.ts +65 -0
  315. package/esm/src/kernel/protocols/binding.js +125 -0
  316. package/esm/src/kernel/protocols/limits.d.ts +15 -0
  317. package/esm/src/kernel/protocols/limits.js +28 -0
  318. package/esm/src/kernel/protocols/mod.d.ts +5 -0
  319. package/esm/src/kernel/protocols/mod.js +5 -0
  320. package/esm/src/kernel/protocols/prices.d.ts +36 -0
  321. package/esm/src/kernel/protocols/prices.js +37 -0
  322. package/esm/src/kernel/protocols/protocol.d.ts +253 -0
  323. package/esm/src/kernel/protocols/protocol.js +253 -0
  324. package/esm/src/kernel/protocols/provider.d.ts +108 -0
  325. package/esm/src/kernel/protocols/provider.js +143 -0
  326. package/esm/src/kernel/protocols/runtime.d.ts +55 -0
  327. package/esm/src/kernel/protocols/runtime.js +534 -0
  328. package/esm/src/kernel/provider-budget.d.ts +32 -0
  329. package/esm/src/kernel/provider-budget.js +262 -0
  330. package/esm/src/kernel/provider-dispatch.d.ts +13 -0
  331. package/esm/src/kernel/provider-dispatch.js +36 -0
  332. package/esm/src/kernel/provider-live.d.ts +7 -0
  333. package/esm/src/kernel/provider-live.js +189 -0
  334. package/esm/src/kernel/provider-runtime.d.ts +57 -0
  335. package/esm/src/kernel/provider-runtime.js +524 -0
  336. package/esm/src/kernel/registry/attachments.d.ts +46 -0
  337. package/esm/src/kernel/registry/attachments.js +220 -0
  338. package/esm/src/kernel/registry/catalog.d.ts +25 -0
  339. package/esm/src/kernel/registry/catalog.js +85 -0
  340. package/esm/src/kernel/registry/embedding-rules.d.ts +28 -0
  341. package/esm/src/kernel/registry/embedding-rules.js +66 -0
  342. package/esm/src/kernel/registry/ingress.d.ts +12 -0
  343. package/esm/src/kernel/registry/ingress.js +179 -0
  344. package/esm/src/kernel/registry/kernel-registry.d.ts +15 -0
  345. package/esm/src/kernel/registry/kernel-registry.js +15 -0
  346. package/esm/src/kernel/registry/profile-outputs.d.ts +3 -0
  347. package/esm/src/kernel/registry/profile-outputs.js +10 -0
  348. package/esm/src/kernel/registry/profiles.d.ts +116 -0
  349. package/esm/src/kernel/registry/profiles.js +773 -0
  350. package/esm/src/kernel/registry/provider-request.d.ts +6 -0
  351. package/esm/src/kernel/registry/provider-request.js +34 -0
  352. package/esm/src/kernel/registry/resolve.d.ts +17 -0
  353. package/esm/src/kernel/registry/resolve.js +238 -0
  354. package/esm/src/kernel/registry/schemas.d.ts +12 -0
  355. package/esm/src/kernel/registry/schemas.js +27 -0
  356. package/esm/src/kernel/registry/slot-fill.d.ts +7 -0
  357. package/esm/src/kernel/registry/slot-fill.js +22 -0
  358. package/esm/src/kernel/registry/sole-model.d.ts +2 -0
  359. package/esm/src/kernel/registry/sole-model.js +4 -0
  360. package/esm/src/kernel/registry/system-prompt.d.ts +8 -0
  361. package/esm/src/kernel/registry/system-prompt.js +32 -0
  362. package/esm/src/kernel/registry/system-role.d.ts +3 -0
  363. package/esm/src/kernel/registry/system-role.js +9 -0
  364. package/esm/src/kernel/registry/vault.d.ts +14 -0
  365. package/esm/src/kernel/registry/vault.js +1 -0
  366. package/esm/src/kernel/schema.d.ts +226 -0
  367. package/esm/src/kernel/schema.js +895 -0
  368. package/esm/src/kernel/scope.d.ts +29 -0
  369. package/esm/src/kernel/scope.js +45 -0
  370. package/esm/src/kernel/stages.d.ts +176 -0
  371. package/esm/src/kernel/stages.js +431 -0
  372. package/esm/src/kernel/stop.d.ts +116 -0
  373. package/esm/src/kernel/stop.js +137 -0
  374. package/esm/src/kernel/system-parts.d.ts +26 -0
  375. package/esm/src/kernel/system-parts.js +98 -0
  376. package/esm/src/kernel/tools/activity-label.d.ts +22 -0
  377. package/esm/src/kernel/tools/activity-label.js +435 -0
  378. package/esm/src/kernel/tools/agent.d.ts +66 -0
  379. package/esm/src/kernel/tools/agent.js +212 -0
  380. package/esm/src/kernel/tools/coordinate.d.ts +4 -0
  381. package/esm/src/kernel/tools/coordinate.js +165 -0
  382. package/esm/src/kernel/tools/events.d.ts +66 -0
  383. package/esm/src/kernel/tools/events.js +184 -0
  384. package/esm/src/kernel/tools/execute.d.ts +100 -0
  385. package/esm/src/kernel/tools/execute.js +1173 -0
  386. package/esm/src/kernel/tools/gate-answer.d.ts +60 -0
  387. package/esm/src/kernel/tools/gate-answer.js +65 -0
  388. package/esm/src/kernel/tools/handler-events.d.ts +45 -0
  389. package/esm/src/kernel/tools/handler-events.js +106 -0
  390. package/esm/src/kernel/tools/harness.d.ts +17 -0
  391. package/esm/src/kernel/tools/harness.js +43 -0
  392. package/esm/src/kernel/tools/http-limit.d.ts +27 -0
  393. package/esm/src/kernel/tools/http-limit.js +85 -0
  394. package/esm/src/kernel/tools/invoke.d.ts +32 -0
  395. package/esm/src/kernel/tools/invoke.js +282 -0
  396. package/esm/src/kernel/tools/mcp-sessions.d.ts +23 -0
  397. package/esm/src/kernel/tools/mcp-sessions.js +69 -0
  398. package/esm/src/kernel/tools/mod.d.ts +10 -0
  399. package/esm/src/kernel/tools/mod.js +7 -0
  400. package/esm/src/kernel/tools/model-text.d.ts +16 -0
  401. package/esm/src/kernel/tools/model-text.js +31 -0
  402. package/esm/src/kernel/tools/operation.d.ts +76 -0
  403. package/esm/src/kernel/tools/operation.js +100 -0
  404. package/esm/src/kernel/tools/page-answer.d.ts +8 -0
  405. package/esm/src/kernel/tools/page-answer.js +19 -0
  406. package/esm/src/kernel/tools/permission.d.ts +15 -0
  407. package/esm/src/kernel/tools/permission.js +38 -0
  408. package/esm/src/kernel/tools/project.d.ts +11 -0
  409. package/esm/src/kernel/tools/project.js +55 -0
  410. package/esm/src/kernel/tools/registry.d.ts +27 -0
  411. package/esm/src/kernel/tools/registry.js +143 -0
  412. package/esm/src/kernel/tools/remote.d.ts +144 -0
  413. package/esm/src/kernel/tools/remote.js +1125 -0
  414. package/esm/src/kernel/tools/resolve.d.ts +31 -0
  415. package/esm/src/kernel/tools/resolve.js +267 -0
  416. package/esm/src/kernel/tools/run.d.ts +28 -0
  417. package/esm/src/kernel/tools/run.js +86 -0
  418. package/esm/src/kernel/tools/schema.d.ts +10 -0
  419. package/esm/src/kernel/tools/schema.js +95 -0
  420. package/esm/src/kernel/tools/signed-in-fetch.d.ts +19 -0
  421. package/esm/src/kernel/tools/signed-in-fetch.js +45 -0
  422. package/esm/src/kernel/tools/stage-run.d.ts +116 -0
  423. package/esm/src/kernel/tools/stage-run.js +198 -0
  424. package/esm/src/kernel/tools/types.d.ts +497 -0
  425. package/esm/src/kernel/tools/types.js +1 -0
  426. package/esm/src/kernel/tools/unchecked-output.d.ts +14 -0
  427. package/esm/src/kernel/tools/unchecked-output.js +18 -0
  428. package/esm/src/kernel/turn-events.d.ts +776 -0
  429. package/esm/src/kernel/turn-events.js +543 -0
  430. package/esm/src/kernel/types.d.ts +1025 -0
  431. package/esm/src/kernel/types.js +1 -0
  432. package/esm/src/kernel/util/base64.d.ts +4 -0
  433. package/esm/src/kernel/util/base64.js +15 -0
  434. package/esm/src/kernel/util/exact-type.d.ts +31 -0
  435. package/esm/src/kernel/util/exact-type.js +1 -0
  436. package/esm/src/kernel/util/find-last.d.ts +3 -0
  437. package/esm/src/kernel/util/find-last.js +9 -0
  438. package/esm/src/kernel/util/mime.d.ts +2 -0
  439. package/esm/src/kernel/util/mime.js +4 -0
  440. package/esm/src/kernel/util/partial-json.d.ts +23 -0
  441. package/esm/src/kernel/util/partial-json.js +128 -0
  442. package/esm/src/kernel/util/record.d.ts +2 -0
  443. package/esm/src/kernel/util/record.js +4 -0
  444. package/esm/src/observability/destinations.d.ts +14 -0
  445. package/esm/src/observability/destinations.js +43 -0
  446. package/esm/src/observability/jsonl.d.ts +18 -0
  447. package/esm/src/observability/jsonl.js +110 -0
  448. package/esm/src/observability/mod.d.ts +22 -0
  449. package/esm/src/observability/mod.js +16 -0
  450. package/esm/src/observability/openinference.d.ts +11 -0
  451. package/esm/src/observability/openinference.js +205 -0
  452. package/esm/src/observability/otlp.d.ts +71 -0
  453. package/esm/src/observability/otlp.js +98 -0
  454. package/esm/src/observability/phoenix.d.ts +30 -0
  455. package/esm/src/observability/phoenix.js +71 -0
  456. package/esm/src/observability/policy.d.ts +17 -0
  457. package/esm/src/observability/policy.js +73 -0
  458. package/esm/src/observability/resolve-policy.d.ts +8 -0
  459. package/esm/src/observability/resolve-policy.js +64 -0
  460. package/esm/src/observability/spans.d.ts +22 -0
  461. package/esm/src/observability/spans.js +72 -0
  462. package/esm/src/observability/trace-catalog.d.ts +128 -0
  463. package/esm/src/observability/trace-catalog.js +906 -0
  464. package/esm/src/observability/trace-record.d.ts +23 -0
  465. package/esm/src/observability/trace-record.js +228 -0
  466. package/esm/src/observability/trace-schema.d.ts +57 -0
  467. package/esm/src/observability/trace-schema.js +59 -0
  468. package/esm/src/observability/trace-sink.d.ts +14 -0
  469. package/esm/src/observability/trace-sink.js +3 -0
  470. package/esm/src/observability/trace-span.d.ts +98 -0
  471. package/esm/src/observability/trace-span.js +201 -0
  472. package/esm/src/observability/trace.d.ts +13 -0
  473. package/esm/src/observability/trace.js +37 -0
  474. package/esm/src/observability/types.d.ts +109 -0
  475. package/esm/src/observability/types.js +3 -0
  476. package/esm/src/presets/google/speech-voices.d.ts +9 -0
  477. package/esm/src/presets/google/speech-voices.js +38 -0
  478. package/esm/src/presets/google-limits.d.ts +13 -0
  479. package/esm/src/presets/google-limits.js +18 -0
  480. package/esm/src/presets/google.d.ts +119 -0
  481. package/esm/src/presets/google.js +197 -0
  482. package/esm/src/presets/local.d.ts +26 -0
  483. package/esm/src/presets/local.js +30 -0
  484. package/esm/src/presets/mod.d.ts +11 -0
  485. package/esm/src/presets/mod.js +9 -0
  486. package/esm/src/presets/openrouter.d.ts +26 -0
  487. package/esm/src/presets/openrouter.js +31 -0
  488. package/esm/src/providers/embedding-limits.d.ts +7 -0
  489. package/esm/src/providers/embedding-limits.js +12 -0
  490. package/esm/src/providers/gemini/embedding-protocol.d.ts +8 -0
  491. package/esm/src/providers/gemini/embedding-protocol.js +125 -0
  492. package/esm/src/providers/gemini/interactions-protocol.d.ts +8 -0
  493. package/esm/src/providers/gemini/interactions-protocol.js +105 -0
  494. package/esm/src/providers/gemini/live-protocol.d.ts +3 -0
  495. package/esm/src/providers/gemini/live-protocol.js +191 -0
  496. package/esm/src/providers/gemini/prices.d.ts +3 -0
  497. package/esm/src/providers/gemini/prices.js +63 -0
  498. package/esm/src/providers/gemini/provider.d.ts +7 -0
  499. package/esm/src/providers/gemini/provider.js +39 -0
  500. package/esm/src/providers/google/api-error.d.ts +8 -0
  501. package/esm/src/providers/google/api-error.js +123 -0
  502. package/esm/src/providers/google/builtins.d.ts +14 -0
  503. package/esm/src/providers/google/builtins.js +57 -0
  504. package/esm/src/providers/google/grounding.d.ts +5 -0
  505. package/esm/src/providers/google/grounding.js +226 -0
  506. package/esm/src/providers/google/interactions/framing.d.ts +27 -0
  507. package/esm/src/providers/google/interactions/framing.js +304 -0
  508. package/esm/src/providers/google/interactions/steps.d.ts +12 -0
  509. package/esm/src/providers/google/interactions/steps.js +200 -0
  510. package/esm/src/providers/google/interactions/stream.d.ts +23 -0
  511. package/esm/src/providers/google/interactions/stream.js +230 -0
  512. package/esm/src/providers/google/live/framing.d.ts +61 -0
  513. package/esm/src/providers/google/live/framing.js +597 -0
  514. package/esm/src/providers/google/live/stream.d.ts +13 -0
  515. package/esm/src/providers/google/live/stream.js +57 -0
  516. package/esm/src/providers/google/thinking.d.ts +3 -0
  517. package/esm/src/providers/google/thinking.js +8 -0
  518. package/esm/src/providers/google/urls.d.ts +4 -0
  519. package/esm/src/providers/google/urls.js +4 -0
  520. package/esm/src/providers/google/usage.d.ts +7 -0
  521. package/esm/src/providers/google/usage.js +49 -0
  522. package/esm/src/providers/live.d.ts +6 -0
  523. package/esm/src/providers/live.js +6 -0
  524. package/esm/src/providers/local/embedding-protocol.d.ts +7 -0
  525. package/esm/src/providers/local/embedding-protocol.js +60 -0
  526. package/esm/src/providers/local/provider.d.ts +7 -0
  527. package/esm/src/providers/local/provider.js +28 -0
  528. package/esm/src/providers/mod.d.ts +32 -0
  529. package/esm/src/providers/mod.js +23 -0
  530. package/esm/src/providers/open-ai/protocol.d.ts +3 -0
  531. package/esm/src/providers/open-ai/protocol.js +189 -0
  532. package/esm/src/providers/openrouter/embedding-protocol.d.ts +6 -0
  533. package/esm/src/providers/openrouter/embedding-protocol.js +86 -0
  534. package/esm/src/providers/openrouter/image.d.ts +15 -0
  535. package/esm/src/providers/openrouter/image.js +34 -0
  536. package/esm/src/providers/openrouter/images-protocol.d.ts +3 -0
  537. package/esm/src/providers/openrouter/images-protocol.js +82 -0
  538. package/esm/src/providers/openrouter/openai/compat.d.ts +19 -0
  539. package/esm/src/providers/openrouter/openai/compat.js +162 -0
  540. package/esm/src/providers/openrouter/openai/image-payload.d.ts +9 -0
  541. package/esm/src/providers/openrouter/openai/image-payload.js +115 -0
  542. package/esm/src/providers/openrouter/openai/reasoning-state.d.ts +2 -0
  543. package/esm/src/providers/openrouter/openai/reasoning-state.js +31 -0
  544. package/esm/src/providers/openrouter/openai/usage.d.ts +8 -0
  545. package/esm/src/providers/openrouter/openai/usage.js +56 -0
  546. package/esm/src/providers/openrouter/protocol.d.ts +8 -0
  547. package/esm/src/providers/openrouter/protocol.js +171 -0
  548. package/esm/src/providers/openrouter/provider.d.ts +10 -0
  549. package/esm/src/providers/openrouter/provider.js +50 -0
  550. package/esm/src/providers/shared/carried-tool-files.d.ts +7 -0
  551. package/esm/src/providers/shared/carried-tool-files.js +43 -0
  552. package/esm/src/providers/shared/pcm.d.ts +14 -0
  553. package/esm/src/providers/shared/pcm.js +78 -0
  554. package/esm/src/providers/shared/protocol-events.d.ts +8 -0
  555. package/esm/src/providers/shared/protocol-events.js +20 -0
  556. package/esm/src/providers/shared/response-identity.d.ts +11 -0
  557. package/esm/src/providers/shared/response-identity.js +12 -0
  558. package/esm/src/providers/shared/retry.d.ts +17 -0
  559. package/esm/src/providers/shared/retry.js +90 -0
  560. package/esm/src/providers/shared/sse.d.ts +6 -0
  561. package/esm/src/providers/shared/sse.js +93 -0
  562. package/esm/src/providers/shared/structured-output.d.ts +4 -0
  563. package/esm/src/providers/shared/structured-output.js +11 -0
  564. package/esm/src/providers/shared/tool-args.d.ts +24 -0
  565. package/esm/src/providers/shared/tool-args.js +88 -0
  566. package/esm/src/providers/shared/tool-draft.d.ts +16 -0
  567. package/esm/src/providers/shared/tool-draft.js +14 -0
  568. package/esm/src/providers/shared/upstream-tap.d.ts +8 -0
  569. package/esm/src/providers/shared/upstream-tap.js +85 -0
  570. package/esm/src/providers/shared/upstream-tape.d.ts +6 -0
  571. package/esm/src/providers/shared/upstream-tape.js +88 -0
  572. package/esm/src/providers/system-one/protocol.d.ts +8 -0
  573. package/esm/src/providers/system-one/protocol.js +93 -0
  574. package/esm/src/providers/types.d.ts +51 -0
  575. package/esm/src/providers/types.js +2 -0
  576. package/esm/src/providers/typesafe/provider.d.ts +7 -0
  577. package/esm/src/providers/typesafe/provider.js +24 -0
  578. package/esm/src/surface/formats.d.ts +46 -0
  579. package/esm/src/surface/formats.js +178 -0
  580. package/esm/src/surface/mod.d.ts +16 -0
  581. package/esm/src/surface/mod.js +12 -0
  582. package/esm/src/surface/runtime.d.ts +44 -0
  583. package/esm/src/surface/runtime.js +441 -0
  584. package/esm/src/surface/tools.d.ts +9 -0
  585. package/esm/src/surface/tools.js +62 -0
  586. package/esm/src/surface/types.d.ts +110 -0
  587. package/esm/src/surface/types.js +4 -0
  588. package/package.json +100 -4
@@ -0,0 +1,1025 @@
1
+ import type { ProviderCheckpoint, ProviderContinuationPolicy } from './checkpoint.js';
2
+ import type { JsonObject } from './json.js';
3
+ import type { CacheMode, CacheTtl, CompactionMeter, CompactionOutcome, CompactionTiming, ContextSender, ContinueStopKind, FieldMeta, KeySlot, KeyVault, LiveActivityHandling, LiveEndSensitivity, LiveStartSensitivity, MediaInputKind, ProfileType, SpeechAudioFormat, StreamMode, SummaryMode, ThinkingLevel, ToolLoadTier, TurnStage, TurnStopKind } from './schema.js';
4
+ import type { StageHandler } from './stages.js';
5
+ import type { GateDecision } from './tools/gate-answer.js';
6
+ import type { PageToolExecution, ToolExecutionCoordinator } from './tools/operation.js';
7
+ import type { AgentCall, AgentCallHook, AgentCallRequest, AgentToolDef, AgentToolInput, AgentToolOutput, HostProfileToolsSpec, InvokeToolRequest, InvokeToolResume, InvokeToolStepCall, InvokeToolStepRequest, LiveProfileToolsSpec, ModelToolResult, PageAnswer, ProfileToolsSpec, RegisteredTool, ToolCallEvent, ToolFailure, ToolGate, ToolLoadContext, ToolPolicy, TurnToolSnapshot, WireFunctionTool } from './tools/types.js';
8
+ import type { AttemptReason, CallDone, CompactionFailure, CompactionResult, CompactionSignal, DoneFields, GroundingEvent, InteractionMediaPart, InteractionMediaRefPart, InteractionPart, InteractionTextPart, InvalidField, ModelEvent, ProviderEvidence, RemovedItem, SessionEnded, SessionEvent, SessionEventKind, SessionEventOf, Source, TurnCost, TurnEvent, TurnEventOf, TurnEventType, TurnGroundingCount, TurnHistoryMessage, TurnResponse, TurnTokenSide, TurnTokens } from './turn-events.js';
9
+ export type { AgentCall, AgentCallHook, AgentCallRequest, AgentToolDef, AgentToolInput, AgentToolOutput, AttemptReason, CacheMode, CacheTtl, CallDone, CompactionFailure, CompactionMeter, CompactionOutcome, CompactionResult, CompactionSignal, CompactionTiming, ContinueStopKind, DoneFields, FieldMeta, GroundingEvent, HostProfileToolsSpec, InteractionMediaPart, InteractionMediaRefPart, InteractionPart, InteractionTextPart, InvalidField, InvokeToolRequest, InvokeToolResume, InvokeToolStepCall, InvokeToolStepRequest, KeySlot, KeyVault, LiveActivityHandling, LiveEndSensitivity, LiveProfileToolsSpec, LiveStartSensitivity, MediaInputKind, ModelEvent, ProfileToolsSpec, ProfileType, ProviderEvidence, RegisteredTool, RemovedItem, SessionEnded, SessionEvent, SessionEventKind, SessionEventOf, Source, SpeechAudioFormat, StreamMode, SummaryMode, ThinkingLevel, ToolCallEvent, ToolFailure, ToolGate, ToolLoadContext, ToolLoadTier, ToolPolicy, TurnCost, TurnEvent, TurnEventOf, TurnEventType, TurnGroundingCount, TurnHistoryMessage, TurnResponse, TurnStage, TurnStopKind, TurnTokenSide, TurnTokens, TurnToolSnapshot, WireFunctionTool, };
10
+ /** A host-chosen key naming one model binding in a profile's `models`. */
11
+ export type ModelId = string;
12
+ /** The id of a provider-side tool such as web search. */
13
+ export type BuiltinToolId = string;
14
+ /** The id a profile lists in `tools.allow` and the model calls a tool by. */
15
+ export type ToolId = string;
16
+ /** The id of a registered structured-output schema. */
17
+ export type StructuredSchemaId = string;
18
+ /** A structured-output schema resolved to its JSON Schema. */
19
+ export interface ResolvedStructured {
20
+ id: StructuredSchemaId;
21
+ jsonSchema: Record<string, unknown>;
22
+ }
23
+ /** A provider-side tool the turn uses, with the args the request addressed to it. */
24
+ export interface ProviderBuiltin {
25
+ id: BuiltinToolId;
26
+ args?: JsonObject;
27
+ }
28
+ /** Args a request hands to built-in tools, each checked by the schema its adapter declares. */
29
+ export type BuiltInArgs = Record<BuiltinToolId, JsonObject>;
30
+ /** The id a profile is registered and run under. */
31
+ export type ProfileId = string;
32
+ /** The roles a history message can carry. */
33
+ export type ChatRole = 'system' | 'user' | 'assistant';
34
+ /** Host strings (presets own the vocabularies); an unpinned value is the provider default. */
35
+ export interface ProfileImageSpec {
36
+ aspectRatio?: string;
37
+ resolution?: string;
38
+ mimeType?: string;
39
+ quality?: string;
40
+ background?: string;
41
+ n?: number;
42
+ seed?: number;
43
+ outputCompression?: number;
44
+ references?: Array<TurnBlob | TurnMediaRef>;
45
+ /** Also request interleaved text with the images (Google: text + image `response_format`). */
46
+ includeText?: boolean;
47
+ }
48
+ import type { DecisionModelBinding, ModelBinding } from './protocols/binding.js';
49
+ export type { DecisionModelBinding, ModelBinding };
50
+ /**
51
+ * OpenRouter prompt-cache policy (`models.*.options.cache`).
52
+ *
53
+ * - `automatic` — top-level `cache_control`; breakpoint advances with the conversation.
54
+ * - `system` — explicit breakpoint on the system instruction only.
55
+ */
56
+ export interface CacheSpec {
57
+ mode: CacheMode;
58
+ /** Ephemeral TTL. Omit → provider default (typically 5m on Anthropic). */
59
+ ttl?: CacheTtl;
60
+ }
61
+ /** What a compaction trigger sees when it decides whether to compact. */
62
+ export interface CompactionTriggerContext {
63
+ tokens: number;
64
+ maxTokens: number;
65
+ compactAt: number;
66
+ meter: CompactionMeter;
67
+ /** Media parts not counted in `tokens` — no verified rule for this model. */
68
+ unknownMedia: number;
69
+ }
70
+ /** When history compacts and how: the meter, the token budget, and the compactor. */
71
+ export interface CompactionSpec {
72
+ /**
73
+ * Token budget compared by the trigger (`compactAt * maxTokens`).
74
+ * Meaning depends on `meter`: history budget vs full-prompt input budget.
75
+ */
76
+ maxTokens: number;
77
+ /** Fraction of `maxTokens` at which compaction fires. Must be in (0, 1). */
78
+ compactAt: number;
79
+ /**
80
+ * Recent exchanges kept verbatim (an exchange is a user message and everything up to the
81
+ * next one). `≥ 1` = exchange count, `(0, 1)` = fraction of `maxTokens`, `0` = compact all.
82
+ */
83
+ previousExchanges: number;
84
+ /**
85
+ * Profile id of the compaction agent. Must be registered before the owning profile.
86
+ * Omit it and the agent compacts its own history: the same instructions and model, no tools.
87
+ */
88
+ profile?: ProfileId;
89
+ /**
90
+ * When compaction runs relative to the primary turn.
91
+ * - `'before'`: kernel compacts synchronously before the turn; user pays latency on this turn.
92
+ * - `'after'`: kernel signals in the `done` event; host runs compaction asynchronously.
93
+ */
94
+ timing: CompactionTiming;
95
+ /**
96
+ * Threshold meter. Defaults to `'history'`.
97
+ * Use `'input'` when the host prefers provider full-prompt usage (after
98
+ * subtracting a known baseline in `maxTokens` / `compactAt`).
99
+ */
100
+ meter?: CompactionMeter;
101
+ /** Replaces the default `tokens > compactAt * maxTokens` check. */
102
+ trigger?: (ctx: CompactionTriggerContext) => boolean | Promise<boolean>;
103
+ }
104
+ /** `compactHistory` input, for `timing: 'after'`: the host passes back what `done.compaction` carried. */
105
+ export interface CompactHistoryRequest {
106
+ /** The profile whose model binding carries the `compaction` spec. */
107
+ profile: ProfileId;
108
+ /** That binding; defaults to the profile's `defaultModel`. */
109
+ model?: ModelId;
110
+ history: TurnHistoryMessage[];
111
+ /** `done.compaction.tokens`: a failed compactor drops `toCompact` only when this is over `maxTokens`. */
112
+ tokens: number;
113
+ signal?: AbortSignal;
114
+ traceparent?: string;
115
+ conversationId?: string;
116
+ metadata?: Record<string, unknown>;
117
+ }
118
+ /** A structured-output schema given inline. */
119
+ export interface StructuredSpec {
120
+ jsonSchema: Record<string, unknown>;
121
+ }
122
+ /** Caps on the files a turn may attach. */
123
+ export interface MediaLimits {
124
+ maxFiles: number;
125
+ maxBytes: number;
126
+ maxTurnBytes: number;
127
+ limitsByMime?: Record<string, number>;
128
+ }
129
+ /** The input kinds a profile accepts, with their limits. */
130
+ export interface MimeInputs extends Partial<MediaLimits> {
131
+ text?: boolean;
132
+ attachments?: {
133
+ accept: string[];
134
+ };
135
+ voice?: {
136
+ accept: string[];
137
+ };
138
+ }
139
+ /** Why an attachment was refused. */
140
+ export type AttachmentValidationCode = 'mime_not_allowed' | 'too_many_files' | 'too_many_of_kind' | 'file_too_large' | 'turn_too_large' | 'attachments_not_accepted' | 'voice_not_accepted' | 'limits_unconfigured';
141
+ /**
142
+ * Structured parameters for rendering one validation issue. Validation emits
143
+ * codes + params only; the wording is the labels' `attachments.*` lines.
144
+ */
145
+ export interface AttachmentValidationParams {
146
+ maxFiles?: number;
147
+ maxBytes?: number;
148
+ maxTurnBytes?: number;
149
+ mimeType?: string;
150
+ /** The kind of media a count is of, such as `PDF` or `image`. */
151
+ kind?: string;
152
+ channel?: 'attachment' | 'voice';
153
+ }
154
+ /** One reason a turn's files were refused; `fileName` names the file when the problem is one file's. */
155
+ export interface AttachmentValidationIssue {
156
+ code: AttachmentValidationCode;
157
+ params?: AttachmentValidationParams;
158
+ fileName?: string;
159
+ }
160
+ /** Picks the structured-output schema by the value of a turn slot, with a fallback. */
161
+ export interface StructuredBySlot {
162
+ by: string;
163
+ map: Record<string, string>;
164
+ fallback: string;
165
+ }
166
+ /** What a host validator returns for a candidate output. */
167
+ export interface ValidationResult {
168
+ isValid: boolean;
169
+ error?: string;
170
+ finding?: string;
171
+ data?: Record<string, unknown>;
172
+ }
173
+ /** A host function that checks one structured-output field. */
174
+ export type ProfileValidator = (candidate: unknown, slots?: Record<string, string>) => ValidationResult | Promise<ValidationResult>;
175
+ /** A tool call the turn completed, as an item check reads it. */
176
+ export interface TurnToolResult {
177
+ tool: string;
178
+ /** The output the call settled with, after any `post_tool` `mutate`. */
179
+ output: unknown;
180
+ }
181
+ /** What an item check reads of the turn whose reply it is checking. */
182
+ export interface ItemCheckTurn {
183
+ slots?: Record<string, string>;
184
+ /** Every tool call the turn completed, in order, across its attempts. */
185
+ toolResults: readonly TurnToolResult[];
186
+ }
187
+ /** A host function that checks one item of a list against what the turn's tools returned. */
188
+ export type ProfileItemCheck = (item: unknown, turn: ItemCheckTurn) => ValidationResult | Promise<ValidationResult>;
189
+ /**
190
+ * A host check on each item of one list in a structured reply. A refused item
191
+ * never fails the reply: `drop` removes it, and `fix` first asks the model to
192
+ * rewrite the refused items alone, then removes any that are refused again.
193
+ */
194
+ export interface ProfileItemRule {
195
+ check: ProfileItemCheck;
196
+ onFail: 'drop' | 'fix';
197
+ }
198
+ /** Host validators a profile runs on its structured output. */
199
+ export interface ProfileValidationSpec {
200
+ /**
201
+ * Host domain validators keyed by dotted paths into structured output
202
+ * (e.g. `diagram.mermaid`). Presence/required is owned by the JSON Schema;
203
+ * these run only for required paths and for optional paths that are present.
204
+ */
205
+ fields?: Record<string, ProfileValidator>;
206
+ /** Host checks on list items, keyed by the dotted path of a list in the structured output. */
207
+ items?: Record<string, ProfileItemRule>;
208
+ maxRetries?: number;
209
+ }
210
+ /** `voice` is the TTS voice id, not ingress audio (`inputs.voice`). */
211
+ export interface ProfileSpeechSpec {
212
+ voice?: string;
213
+ /** How the script is delivered, in plain words: pace, mood, accent. Never read aloud. */
214
+ style?: string;
215
+ /** The speaking rate; 1 is the voice's own pace. */
216
+ speed?: number;
217
+ /** A provider that cannot make the format refuses the turn. */
218
+ format?: SpeechAudioFormat;
219
+ }
220
+ /** What one speech turn sets for itself; each field given replaces the profile's `speech` field of that name. */
221
+ export type TurnSpeech = Pick<ProfileSpeechSpec, 'voice' | 'style' | 'speed'>;
222
+ /** Voice activity detection settings for a live session. */
223
+ export interface LiveVadSpec {
224
+ activityHandling?: LiveActivityHandling;
225
+ startSensitivity?: LiveStartSensitivity;
226
+ endSensitivity?: LiveEndSensitivity;
227
+ prefixPaddingMs?: number;
228
+ silenceDurationMs?: number;
229
+ }
230
+ /**
231
+ * Context window compression for a live session: once the context reaches the
232
+ * trigger, the mechanism shrinks it. Without it, Gemini ends audio sessions at
233
+ * 15 minutes and audio-video sessions at 2.
234
+ */
235
+ export interface LiveContextCompressionSpec {
236
+ /**
237
+ * Context tokens, counted before a turn, that start compression. A whole
238
+ * number above 0. Omit → provider default (Gemini: 80% of the model's context
239
+ * window).
240
+ */
241
+ triggerTokens?: number;
242
+ /** Drops the oldest turns; the system instruction stays. Gemini's only mechanism. */
243
+ slidingWindow: LiveSlidingWindowSpec;
244
+ }
245
+ /** Sliding-window context compression for a live session. */
246
+ export interface LiveSlidingWindowSpec {
247
+ /**
248
+ * Tokens to keep after compressing. A whole number above 0, below
249
+ * `triggerTokens`. Omit → provider default (Gemini: half of `triggerTokens`).
250
+ */
251
+ targetTokens?: number;
252
+ }
253
+ /** Which sides of a live session are transcribed. */
254
+ export interface LiveTranscriptionSpec {
255
+ input?: boolean;
256
+ output?: boolean;
257
+ }
258
+ /**
259
+ * Realtime ingress modalities for a live session.
260
+ * Distinct from turn `inputs` (file attachments, MIME limits) — these gate
261
+ * `LiveSession.sendAudio` / `sendVideo` / `sendText` channels.
262
+ */
263
+ export interface LiveIngressSpec {
264
+ /** Microphone PCM via `sendAudio`. Omit → enabled. */
265
+ audio?: boolean;
266
+ /** Webcam JPEG frames via `sendVideo`. Omit → enabled. */
267
+ video?: boolean;
268
+ /** Typed text via `sendText`. Omit → disabled (opt-in). */
269
+ text?: boolean;
270
+ }
271
+ /** The prompt a resumed call opens with, and how long away earns it. */
272
+ export interface LiveResumedSpec {
273
+ prompt: string;
274
+ /** The shortest time away, in milliseconds, the agent remarks on. Omit → `DEFAULT_RESUMED_AFTER_MS`. */
275
+ afterMs?: number;
276
+ }
277
+ /** The settings only a live profile has: ingress, voice, detection, windowing, transcription, and resumption. */
278
+ export interface ProfileLiveSpec {
279
+ ingress?: LiveIngressSpec;
280
+ voice?: string;
281
+ vad?: LiveVadSpec;
282
+ sessionResumption?: boolean;
283
+ /** A prompt the session sends itself when a call opens new, so the agent speaks first. Omit → the agent waits. */
284
+ greeting?: string;
285
+ /** What the agent is prompted with when a call resumes after the caller was away. Omit → a resumed call is silent. */
286
+ resumed?: LiveResumedSpec;
287
+ /** Context window compression. Omit → none: the provider ends the session at its limit. */
288
+ contextCompression?: LiveContextCompressionSpec;
289
+ transcription?: LiveTranscriptionSpec;
290
+ }
291
+ /** How a profile's reply streams. */
292
+ export interface ProfileStreamingSpec {
293
+ mode?: StreamMode;
294
+ /** When false, filter `thought` events from the turn stream. */
295
+ streamThoughts?: boolean;
296
+ }
297
+ export type { MediaTurnBehaviourSpec, ProfileTurnBehaviourSpec, ProfileTurnResumptionSpec, TurnContinueFrom, TurnStop, } from './stop.js';
298
+ import type { LabelOverrides } from '../guardrails/labels.js';
299
+ import type { ResolveHost } from '../guardrails/network.js';
300
+ import type { DecisionGuardrailsSpec, HostGuardrailsSpec, ProfileGuardrailsSpec } from '../guardrails/types.js';
301
+ import type { ProfileObservabilitySpec } from '../observability/types.js';
302
+ import type { ToolCredentialSource } from './auth/credential-source.js';
303
+ import type { MediaTurnBehaviourSpec, ProfileTurnBehaviourSpec, TurnContinueFrom } from './stop.js';
304
+ /** The model fields every model-running profile shares. */
305
+ export interface ProfileModelFields {
306
+ providerContinuation?: ProviderContinuationPolicy;
307
+ /** Host-named models. Each key is a selectable model id when `allowModelSelect` is set. */
308
+ models: Record<ModelId, ModelBinding>;
309
+ /** The model a turn runs when it names none; registration fills it with the only key when there is one. */
310
+ defaultModel: ModelId;
311
+ /** Turn may pass `{ model: "<id>" }`; a name that is not a key of `models` is refused. */
312
+ allowModelSelect?: boolean;
313
+ /** Tool-loop ceiling. Omit = `DEFAULT_MAX_STEPS`; `1` = one-shot; `> 1` = hard cap. */
314
+ maxSteps?: number;
315
+ }
316
+ /** What a profile accepts as input. */
317
+ export interface ProfileInputsSpec {
318
+ text?: boolean;
319
+ attachments?: {
320
+ accept: string[];
321
+ };
322
+ voice?: {
323
+ accept: string[];
324
+ };
325
+ maxFiles?: number;
326
+ maxBytes?: number;
327
+ maxTurnBytes?: number;
328
+ limitsByMime?: Record<string, number>;
329
+ slots?: Record<string, string[]>;
330
+ context?: ProfileContextSpec;
331
+ }
332
+ /** What a live profile declares beside its ingress channels. */
333
+ export type LiveInputsSpec = Pick<ProfileInputsSpec, 'slots' | 'context'>;
334
+ /** Who may send a turn its context, and how much. */
335
+ export interface ProfileContextSpec {
336
+ from: ContextSender[];
337
+ maxChars: number;
338
+ }
339
+ /** The context each sender gives a turn: any JSON, or text. */
340
+ export type TurnContext = Partial<Record<ContextSender, unknown>>;
341
+ /** What a profile returns: its structured schema, validation, and streaming. */
342
+ export interface ProfileOutputsSpec {
343
+ structured?: StructuredSchemaId | StructuredBySlot | null;
344
+ validation?: ProfileValidationSpec;
345
+ streaming?: ProfileStreamingSpec;
346
+ }
347
+ /** Text a reply may not repeat when the rest of its prompt is marked shareable. */
348
+ export interface PrivateSystemPart {
349
+ private: string;
350
+ }
351
+ /** One part of a system prompt: plain text or a part kept out of traces. */
352
+ export type SystemPart = string | PrivateSystemPart;
353
+ /**
354
+ * A system prompt: a string, or parts sent concatenated as written. A string,
355
+ * or parts none of which is `{ private }`, is private throughout; once one
356
+ * part is `{ private }`, the plain strings beside it are shareable.
357
+ */
358
+ export type SystemPrompt = string | readonly SystemPart[];
359
+ /** A stretch of the system prompt as sent, and whether a reply may repeat it. */
360
+ export interface SystemPiece {
361
+ text: string;
362
+ private: boolean;
363
+ }
364
+ /** A profile's handle and system prompt. */
365
+ export interface ProfileIdentity {
366
+ handle: string;
367
+ system?: SystemPrompt;
368
+ systemByRole?: Record<string, SystemPrompt>;
369
+ }
370
+ /** The fields every profile type shares. */
371
+ export interface ProfileCommon {
372
+ providerContinuation?: ProviderContinuationPolicy;
373
+ id: ProfileId;
374
+ identity: ProfileIdentity;
375
+ models: Record<ModelId, ModelBinding>;
376
+ defaultModel: ModelId;
377
+ allowModelSelect?: boolean;
378
+ maxSteps?: number;
379
+ outputs?: ProfileOutputsSpec;
380
+ guardrails?: ProfileGuardrailsSpec;
381
+ observability?: ProfileObservabilitySpec;
382
+ /** This profile's wording: replaces any label default, and any `overrideLabels` entry, for this profile. */
383
+ labels?: LabelOverrides;
384
+ }
385
+ /** Any JSON value; the state a decision reads. */
386
+ export type DecisionJson = null | string | number | boolean | DecisionJson[] | {
387
+ [key: string]: DecisionJson;
388
+ };
389
+ /** What a decision profile accepts: JSON state up to a byte cap. */
390
+ export interface DecisionInputsSpec {
391
+ state: 'json';
392
+ maxStateBytes?: number;
393
+ }
394
+ /**
395
+ * A host-owned id for the decision a profile makes. The trace records it as
396
+ * `theorem.decision.contract`; it is not sent to the provider and does not constrain
397
+ * the questions a call asks.
398
+ */
399
+ export type DecisionContractId = string;
400
+ /** Decision profile. It cannot be passed to chat or live execution doors. */
401
+ export interface DecisionProfile {
402
+ type: 'decision';
403
+ id: ProfileId;
404
+ identity: Pick<ProfileIdentity, 'handle'>;
405
+ /** Exactly one model: a decision profile runs one model and never selects. */
406
+ models: Record<ModelId, DecisionModelBinding>;
407
+ inputs: DecisionInputsSpec;
408
+ decision: {
409
+ contract: DecisionContractId;
410
+ };
411
+ guardrails?: DecisionGuardrailsSpec;
412
+ observability?: ProfileObservabilitySpec;
413
+ /** This profile's wording: replaces any label default, and any `overrideLabels` entry, for this profile. */
414
+ labels?: LabelOverrides;
415
+ }
416
+ /** Text or nested text instruction entries. Non-text leaves are rejected locally. */
417
+ export type DecisionEntry = string | DecisionEntry[] | {
418
+ [key: string]: DecisionEntry;
419
+ };
420
+ /** A question answered by picking one of the named criteria. */
421
+ export interface DecisionChoiceQuestion {
422
+ type: 'choice';
423
+ instructions: DecisionEntry;
424
+ criteria: Record<string, DecisionEntry>;
425
+ }
426
+ /** A question answered with a single number, optionally with named criteria. */
427
+ export interface DecisionNoulQuestion {
428
+ type: 'noul';
429
+ instructions: DecisionEntry;
430
+ criteria?: Record<string, DecisionEntry>;
431
+ }
432
+ /** A question answered by scoring against an ordered list of criteria. */
433
+ export interface DecisionScoreQuestion {
434
+ type: 'score';
435
+ instructions: DecisionEntry;
436
+ criteria: readonly DecisionEntry[];
437
+ }
438
+ /** A question answered with the one box that holds what the instructions name, in an image. */
439
+ export interface DecisionBoxQuestion {
440
+ type: 'box';
441
+ instructions: DecisionEntry;
442
+ /**
443
+ * The image the box is in: a reference in `assets`, such as `<ghs02>`, or the state field that
444
+ * holds one, such as `photo.front`. Unset, the model reads the image from the instructions.
445
+ */
446
+ image?: string;
447
+ }
448
+ /** One question a decision answers. */
449
+ export type DecisionQuestion = DecisionChoiceQuestion | DecisionNoulQuestion | DecisionScoreQuestion | DecisionBoxQuestion;
450
+ /** An image a decision reads: PNG or JPEG bytes as base64, with no `data:` prefix. */
451
+ export interface DecisionAsset {
452
+ mimeType: 'image/png' | 'image/jpeg';
453
+ data: string;
454
+ }
455
+ /** A request to `runDecision`: the profile, the state to judge, and the questions to answer. */
456
+ export interface DecisionRequest {
457
+ profile: ProfileId;
458
+ state: Exclude<DecisionJson, null>;
459
+ questions: Record<string, DecisionQuestion>;
460
+ /**
461
+ * Images by reference. Write a reference as a string where its image belongs, in `state`, in a
462
+ * question's instructions, or in its criteria; the provider puts the image there.
463
+ */
464
+ assets?: Record<string, DecisionAsset>;
465
+ signal?: AbortSignal;
466
+ /** Host-owned metadata preserved on the decision's trace record; the kernel does not interpret it. */
467
+ metadata?: Record<string, unknown>;
468
+ /**
469
+ * W3C `traceparent` of the host span this decision runs under. The `decide`
470
+ * root joins that trace as its child; without it the decision starts a new
471
+ * trace. A malformed value throws.
472
+ */
473
+ traceparent?: string;
474
+ }
475
+ /** The model's answer to one decision question. */
476
+ export type DecisionAnswer = {
477
+ type: 'choice';
478
+ choice: string;
479
+ confidence: number;
480
+ probabilities: Record<string, number>;
481
+ } | {
482
+ type: 'noul';
483
+ noul: number;
484
+ } | {
485
+ type: 'score';
486
+ score: number;
487
+ confidence: number;
488
+ legend: Record<string, string>;
489
+ probabilities: Record<string, number>;
490
+ }
491
+ /** Edges are fractions of the image, from its top-left corner. */
492
+ | {
493
+ type: 'box';
494
+ box: {
495
+ top: number;
496
+ bottom: number;
497
+ left: number;
498
+ right: number;
499
+ };
500
+ confidence: number;
501
+ };
502
+ /** What `runDecision` returns: the model and an answer for each question. */
503
+ export interface DecisionResult {
504
+ model: string;
505
+ answers: Record<string, DecisionAnswer>;
506
+ /** Provider-reported tokens and cost; a cost worked out from the provider's prices is `estimated`. */
507
+ usage?: {
508
+ inputTokens: number;
509
+ outputTokens: number;
510
+ costUsd?: number;
511
+ estimated?: true;
512
+ };
513
+ }
514
+ /** One provider-neutral input part for an embedding request. */
515
+ export type EmbeddingPart = {
516
+ type: 'text';
517
+ text: string;
518
+ } | {
519
+ type: 'media';
520
+ mimeType: string;
521
+ data: string;
522
+ } | {
523
+ type: 'media-ref';
524
+ mimeType: string;
525
+ uri: string;
526
+ };
527
+ /** One embedding input. Media-only inputs remain valid for native local models. */
528
+ export type EmbeddingInput = string | {
529
+ parts: readonly EmbeddingPart[];
530
+ };
531
+ /** A profile's accepted embedding input kinds and limits. */
532
+ export interface EmbeddingInputsSpec {
533
+ text?: boolean;
534
+ attachments?: {
535
+ accept: string[];
536
+ };
537
+ maxFiles?: number;
538
+ maxBytes?: number;
539
+ maxTurnBytes?: number;
540
+ limitsByMime?: Record<string, number>;
541
+ }
542
+ /** A profile that returns vectors instead of a model turn. */
543
+ export interface EmbeddingProfile extends Omit<ProfileCommon, 'identity' | 'outputs' | 'maxSteps'> {
544
+ type: 'embedding';
545
+ identity: Pick<ProfileIdentity, 'handle'>;
546
+ inputs: EmbeddingInputsSpec;
547
+ }
548
+ /**
549
+ * What the inputs are for in a search: `query` for what someone asks,
550
+ * `document` for what is searched. A model that embeds the two the same way
551
+ * ignores it.
552
+ */
553
+ export type EmbeddingTask = 'query' | 'document';
554
+ /** A request to `runEmbedding`. */
555
+ export interface EmbeddingRequest {
556
+ profile: ProfileId;
557
+ model?: ModelId;
558
+ input: EmbeddingInput | readonly EmbeddingInput[];
559
+ task?: EmbeddingTask;
560
+ signal?: AbortSignal;
561
+ metadata?: Record<string, unknown>;
562
+ traceparent?: string;
563
+ }
564
+ /** One vector returned for one ordered embedding input. */
565
+ export interface EmbeddingVector {
566
+ index: number;
567
+ values: readonly number[];
568
+ dimensions: number;
569
+ }
570
+ /** Provider usage for an embedding call. */
571
+ export interface EmbeddingUsage {
572
+ inputTokens?: number;
573
+ costUsd?: number;
574
+ estimated?: true;
575
+ }
576
+ /** The normalized result of `runEmbedding`. */
577
+ export interface EmbeddingResult {
578
+ model: string;
579
+ embeddings: readonly EmbeddingVector[];
580
+ usage?: EmbeddingUsage;
581
+ }
582
+ /** A profile that runs text turns. */
583
+ export interface TextProfile extends ProfileCommon {
584
+ type: 'text';
585
+ tools: ProfileToolsSpec;
586
+ inputs: ProfileInputsSpec;
587
+ turnBehaviour?: ProfileTurnBehaviourSpec;
588
+ }
589
+ /**
590
+ * An image profile's inputs: no voice channel, and attachments within
591
+ * `IMAGE_ATTACHMENT_ACCEPT`. Every attachment is a reference the model reads;
592
+ * `maxFiles` caps them.
593
+ */
594
+ export type ImageInputsSpec = Omit<ProfileInputsSpec, 'voice'>;
595
+ /** A profile that generates images. */
596
+ export interface ImageProfile extends ProfileCommon {
597
+ type: 'image';
598
+ image: ProfileImageSpec;
599
+ tools: ProfileToolsSpec;
600
+ inputs: ImageInputsSpec;
601
+ turnBehaviour?: MediaTurnBehaviourSpec;
602
+ }
603
+ /**
604
+ * Unary TTS — text-in locked by type; no tools / inputs block. The input text is the transcript;
605
+ * there is no system prompt, so no canary is planted and nothing of the profile's own can leak.
606
+ */
607
+ export interface SpeechProfile extends Omit<ProfileCommon, 'identity'> {
608
+ type: 'speech';
609
+ identity: Pick<ProfileIdentity, 'handle'>;
610
+ speech: ProfileSpeechSpec;
611
+ turnBehaviour?: MediaTurnBehaviourSpec;
612
+ }
613
+ /** A profile that holds a live audio session. */
614
+ export interface LiveProfile extends Omit<ProfileCommon, 'outputs'> {
615
+ type: 'live';
616
+ live: ProfileLiveSpec;
617
+ inputs?: LiveInputsSpec;
618
+ tools: LiveProfileToolsSpec;
619
+ /** Stage inject gate only; live resumption is `live.sessionResumption`. */
620
+ turnBehaviour?: Pick<ProfileTurnBehaviourSpec, 'allowSteering'>;
621
+ }
622
+ /**
623
+ * Host-driven tool execution; never runs a model. `invokeTool` runs any tool in
624
+ * `tools.allow` with no visibility, loading tiers, or path gating. `guardrails` holds only
625
+ * the guards that fire on `invokeTool`: quota, canary, and egress guard a model turn, so
626
+ * `defineProfile` refuses them rather than accept inert config.
627
+ */
628
+ export interface HostProfile {
629
+ type: 'host';
630
+ id: ProfileId;
631
+ tools: HostProfileToolsSpec;
632
+ guardrails?: HostGuardrailsSpec;
633
+ observability?: ProfileObservabilitySpec;
634
+ /** This profile's wording: replaces any label default, and any `overrideLabels` entry, for this profile. */
635
+ labels?: LabelOverrides;
636
+ }
637
+ /** The contract that defines an agent’s capabilities and the rules for its interactions. Its type determines which settings it accepts. */
638
+ export type Profile = TextProfile | ImageProfile | SpeechProfile | LiveProfile | DecisionProfile | EmbeddingProfile | HostProfile;
639
+ /** Profiles that run a model turn — every type except `host` and `decision` (which runs through `runDecision`). */
640
+ export type ModelProfile = Exclude<Profile, HostProfile | DecisionProfile | EmbeddingProfile>;
641
+ /** The image a profile asks the model to return. */
642
+ export interface ImageResponseFormat {
643
+ type: 'image';
644
+ mimeType?: string;
645
+ aspectRatio?: string;
646
+ /** Adapters map it to the provider wire key (Google `imageSize`, OpenRouter `resolution`). */
647
+ resolution?: string;
648
+ quality?: string;
649
+ background?: string;
650
+ n?: number;
651
+ seed?: number;
652
+ outputCompression?: number;
653
+ includeText: boolean;
654
+ }
655
+ /** A file sent inline with a turn. */
656
+ export interface TurnBlob {
657
+ mimeType: string;
658
+ data: string;
659
+ /** The file's name, used only to tell the user which file was refused; never sent to the model. */
660
+ name?: string;
661
+ }
662
+ /**
663
+ * Media attachment supplied by reference (provider file uri) instead of bytes.
664
+ * MIME acceptance still applies; base64 and byte limits do not.
665
+ */
666
+ export interface TurnMediaRef {
667
+ mimeType: string;
668
+ uri: string;
669
+ /** The file's name, used only to tell the user which file was refused; never sent to the model. */
670
+ name?: string;
671
+ }
672
+ /** A rejected output and the guidance to retry it with. */
673
+ export interface TurnRepairRequest {
674
+ previousOutput: string;
675
+ rejection: string;
676
+ guidance?: string;
677
+ }
678
+ /** What the user sent for a turn: text, slots, attachments, voice, and history. */
679
+ export interface TurnInput {
680
+ text?: string;
681
+ role?: string;
682
+ slots?: Record<string, string>;
683
+ /** What the page or the host wants the model to know, by sender; the profile's `inputs.context` allows it. */
684
+ context?: TurnContext;
685
+ attachments?: Array<TurnBlob | TurnMediaRef>;
686
+ voice?: TurnBlob[];
687
+ history?: TurnHistoryMessage[];
688
+ repair?: TurnRepairRequest;
689
+ /**
690
+ * Optional host-supplied history token count for `meter: 'history'`.
691
+ * When set, overrides the local history estimate. Not full-prompt API tokens.
692
+ */
693
+ historyTokens?: number;
694
+ /**
695
+ * Optional host-supplied full-prompt input token count for `meter: 'input'`
696
+ * with `timing: 'before'` (typically the previous turn's `tokens.input`).
697
+ * Ignored when `meter` is `'history'`.
698
+ */
699
+ inputTokens?: number;
700
+ }
701
+ /** A turn request whose `input` is always present. */
702
+ export type NormalizedTurnRequest = TurnRequest & {
703
+ input: TurnInput;
704
+ };
705
+ /**
706
+ * An earlier trace this one follows from. Recorded as a span link on the
707
+ * root, so a developer can walk a conversation across records.
708
+ */
709
+ export interface TurnTraceLink {
710
+ /** The earlier root's `traceparent` (its terminal `done.traceparent`). */
711
+ traceparent: string;
712
+ /** `resume` after a pause, `continue` after a resumeable stop, `retry` of a failed turn. */
713
+ kind: 'resume' | 'continue' | 'retry';
714
+ /** How the earlier turn stopped, when the host knows. */
715
+ stop?: TurnStopKind;
716
+ }
717
+ /** A request to `runTurn`: the profile, the input, and the host's hooks and keys. */
718
+ export interface TurnRequest {
719
+ execution?: ToolExecutionCoordinator;
720
+ pageExecution?: PageToolExecution;
721
+ providerState?: ProviderCheckpoint;
722
+ profile: ProfileId;
723
+ projectId?: string;
724
+ /**
725
+ * Sticky routing / cache session key for OpenRouter (`session_id`).
726
+ * Not the same as `projectId` or Gemini `previousInteractionId`.
727
+ */
728
+ sessionId?: string;
729
+ /** Selected model id when `profile.allowModelSelect` is true. */
730
+ model?: ModelId;
731
+ /** Selected effort alias when the binding has `allowEffortSelect`. */
732
+ effort?: string;
733
+ /**
734
+ * Args for built-in tools on the chosen model's `builtInTools`, by tool id.
735
+ * Each is parsed by the schema the provider's adapter declares for that tool.
736
+ */
737
+ builtInArgs?: BuiltInArgs;
738
+ /** Host-provided dynamic system prompt combined with profile persona */
739
+ system?: SystemPrompt;
740
+ /** This turn's voice, style, and speed, over `profile.speech`. Speech profiles only. */
741
+ speech?: TurnSpeech;
742
+ sessionPermissions?: string[];
743
+ /** Host channel/path for catalog `paths` filtering. */
744
+ path?: string;
745
+ /** Host-owned metadata preserved for traces; the kernel does not interpret it. */
746
+ metadata?: Record<string, unknown>;
747
+ /**
748
+ * W3C `traceparent` of the host span this turn runs under. The turn's root
749
+ * span joins that trace as its child; without it the turn starts a new trace.
750
+ * A malformed value throws.
751
+ */
752
+ traceparent?: string;
753
+ /** Host conversation id, recorded as `gen_ai.conversation.id`. */
754
+ conversationId?: string;
755
+ links?: TurnTraceLink[];
756
+ /**
757
+ * Opaque application context handed to tool `handler` / `preTool` and
758
+ * `tools.t1Policy` as `ctx.host`. The kernel never reads, logs, traces, or
759
+ * serializes it.
760
+ */
761
+ host?: unknown;
762
+ /**
763
+ * Optional abort signal. When aborted, THEOREM stops the turn and cancels
764
+ * in-flight provider HTTP where the adapter supports it.
765
+ */
766
+ signal?: AbortSignal;
767
+ /**
768
+ * Continue a prior resumeable stop. On text profiles the turn's user message
769
+ * is the continue instruction (no `input.text`); the host passes the partial
770
+ * reply as the last assistant message in `input.history`. Image and speech
771
+ * re-send the original request unchanged.
772
+ */
773
+ continueFrom?: TurnContinueFrom;
774
+ /**
775
+ * 1-based continue attempt when `continueFrom` is set.
776
+ * Compared to `profile.turnBehaviour.resumption.maxContinues` when that cap is set.
777
+ */
778
+ continuation?: number;
779
+ input?: TurnInput;
780
+ /** Credentials for authenticated HTTP / MCP tools, read by auth slot when a tool needs one. */
781
+ credentials?: ToolCredentialSource;
782
+ /**
783
+ * Resolves remote tool and OAuth host names before each request; a name that
784
+ * resolves to a private address is refused (see `fetchGuarded`).
785
+ */
786
+ resolveHost?: ResolveHost;
787
+ /** Text `runTurn` emits stages and applies the returned affordances. */
788
+ onStage?: StageHandler;
789
+ /**
790
+ * Runs before each agent tool call in this turn, and in the turns those
791
+ * calls run. Shape the called agent's request (history, model, provider) or
792
+ * refuse the call. Omit it: the agent runs on what the model sent.
793
+ */
794
+ onAgentCall?: AgentCallHook;
795
+ }
796
+ /** A profile projected for a client, with its secrets and server-only fields removed. */
797
+ export interface ProjectedProfile extends ProfileModelFields {
798
+ id: string;
799
+ type: ModelProfile['type'];
800
+ handle: string;
801
+ tools: Array<RegisteredTool | {
802
+ name: ToolId;
803
+ missing: true;
804
+ }>;
805
+ inputs: ProfileInputsSpec | null;
806
+ outputs: ProfileOutputsSpec | null;
807
+ image?: ProfileImageSpec | null;
808
+ speech?: ProfileSpeechSpec | null;
809
+ live?: ProfileLiveSpec | null;
810
+ }
811
+ /** The generation settings a provider call is made with. */
812
+ export interface ProviderGenerationConfig {
813
+ model: ModelId;
814
+ apiId: string;
815
+ /**
816
+ * Upstream stream vs batch, derived from `outputs.streaming.mode`.
817
+ * `true` = SSE (THEOREM default when mode is omitted); `false` = buffered.
818
+ */
819
+ stream?: boolean;
820
+ thinking?: ThinkingLevel;
821
+ summaries?: SummaryMode;
822
+ maxOutputTokens?: number;
823
+ temperature?: number;
824
+ builtins: BuiltinToolId[];
825
+ /** Forwarded as OpenRouter `session_id`. */
826
+ sessionId?: string;
827
+ }
828
+ /** The transport a provider adapter speaks. */
829
+ export type ProviderTransport = 'turn' | 'live';
830
+ /** A generation config after the profile and request are resolved, with its transport. */
831
+ export interface ResolvedGeneration extends ProviderGenerationConfig {
832
+ /** The request's `builtInArgs`, parsed. */
833
+ builtInArgs?: BuiltInArgs;
834
+ execution?: ToolExecutionCoordinator;
835
+ pageExecution?: PageToolExecution;
836
+ transport: ProviderTransport;
837
+ tools: TurnToolSnapshot;
838
+ sessionPermissions?: string[];
839
+ history?: TurnHistoryMessage[];
840
+ /** Tool-loop ceiling: the profile's `maxSteps`, or `DEFAULT_MAX_STEPS`. */
841
+ maxSteps?: number;
842
+ structured: ResolvedStructured | null;
843
+ image: ImageResponseFormat | null;
844
+ speech?: ProfileSpeechSpec;
845
+ live?: ProfileLiveSpec;
846
+ input: InteractionPart[];
847
+ /**
848
+ * The canary bound into the system prompt; empty with the canary off. A turn
849
+ * binds the profile's (`profileCanary`), the same for the same prompt; a
850
+ * Live session binds this one, minted for it.
851
+ */
852
+ canary: string;
853
+ /** Snapshotted synchronously before any async work; the runner binds the canary on top. */
854
+ resolvedSystem: readonly SystemPiece[];
855
+ /** `TurnRequest.host`, carried to tool contexts only. Never sent to providers or traces. */
856
+ host?: unknown;
857
+ }
858
+ /** One model call as the engine asks it: the resolved generation, the conversation, and the tools. */
859
+ export interface ModelRequest extends Omit<ProviderGenerationConfig, 'summaries' | 'builtins'> {
860
+ /** The turn's builtins with the args addressed to each. */
861
+ builtins: ProviderBuiltin[];
862
+ summaries?: SummaryMode;
863
+ providerState?: ProviderCheckpoint;
864
+ system: string;
865
+ input: InteractionPart[];
866
+ history?: TurnHistoryMessage[];
867
+ wireTools?: WireFunctionTool[];
868
+ structured: ResolvedStructured | null;
869
+ image: ImageResponseFormat | null;
870
+ speech?: ProfileSpeechSpec;
871
+ live?: ProfileLiveSpec;
872
+ /** Scrubbed SSE / HTTP rows for traces. */
873
+ tapUpstream?: (row: Record<string, unknown>) => void;
874
+ /** Host abort signal. */
875
+ signal?: AbortSignal;
876
+ }
877
+ /** One model call, streamed as the model's events. */
878
+ export interface TurnModel {
879
+ complete: (req: ModelRequest) => AsyncIterable<ModelEvent>;
880
+ }
881
+ /**
882
+ * Host request to open a long-lived live session (`runSession`).
883
+ * Profile must be `type: 'live'`.
884
+ */
885
+ export interface SessionRequest {
886
+ providerState?: ProviderCheckpoint;
887
+ profile: ProfileId;
888
+ /** Host-built system prompt merged with profile identity.system. */
889
+ system?: SystemPrompt;
890
+ /** Override `profile.live.voice` for this session. */
891
+ voice?: string;
892
+ /** As `TurnRequest.builtInArgs`. */
893
+ builtInArgs?: BuiltInArgs;
894
+ path?: string;
895
+ sessionPermissions?: string[];
896
+ history?: TurnHistoryMessage[];
897
+ /** The value chosen for each of the profile's `inputs.slots`. */
898
+ slots?: Record<string, string>;
899
+ /** What the page and the host tell the agent as the call opens; `sendContext` replaces it later. */
900
+ context?: TurnContext;
901
+ /** How long the caller was away before this resume, in milliseconds. The session keeps no clock across calls. */
902
+ awayMs?: number;
903
+ /** Optional realtime parts sent immediately after setup. A call that sends them gets no `live.greeting`. */
904
+ input?: InteractionPart[];
905
+ /**
906
+ * Registry-resolved tool snapshot from the process that owns the tool registry
907
+ * (`prepareTurnToolSnapshot`). When set, session setup declares `snapshot.wire`
908
+ * instead of resolving tools locally, so a relay process without the registry
909
+ * can open the session. Every custom id must be within the profile's
910
+ * `tools.allow`; ids outside it are refused.
911
+ */
912
+ snapshot?: TurnToolSnapshot;
913
+ signal?: AbortSignal;
914
+ /** Host-owned metadata preserved on every record the session writes. */
915
+ metadata?: Record<string, unknown>;
916
+ /**
917
+ * W3C `traceparent` of the host span this session runs under. The session's
918
+ * root span joins that trace as its child; without it the session starts a
919
+ * new trace. A malformed value throws.
920
+ */
921
+ traceparent?: string;
922
+ /** Host conversation id, recorded as `gen_ai.conversation.id`. */
923
+ conversationId?: string;
924
+ links?: TurnTraceLink[];
925
+ /** Immutable for the session; there is no `setOnStage`. */
926
+ onStage?: StageHandler;
927
+ /**
928
+ * As `TurnRequest.onAgentCall`, for the agent tools this session's calls run.
929
+ * Omit it: each agent runs on what the model sent, with the session's own
930
+ * provider options.
931
+ */
932
+ onAgentCall?: AgentCallHook;
933
+ /**
934
+ * Default credentials for `executeTool` (per-call args override). Without one, the
935
+ * session keeps keys typed at its sign-in gates in memory.
936
+ */
937
+ credentials?: ToolCredentialSource;
938
+ /**
939
+ * Resolves remote tool and OAuth host names before each request; a name that
940
+ * resolves to a private address is refused (see `fetchGuarded`).
941
+ */
942
+ resolveHost?: ResolveHost;
943
+ /** Opaque host slot for stages / tool execute (per-call args override). */
944
+ host?: unknown;
945
+ }
946
+ /**
947
+ * Run a call the model made in this session, by its id: once, with the
948
+ * model's input. `decision` answers a call waiting on a gate, and only such a
949
+ * call; `input` is the user's edit, and only with `approve` on a gated call.
950
+ */
951
+ export type LiveExecuteToolArgs = {
952
+ callId: string;
953
+ operationId?: string;
954
+ decision?: GateDecision;
955
+ input?: unknown;
956
+ /**
957
+ * The key the user typed at a sign-in gate, only with `approve` on that
958
+ * gate: the session sets it as the credential for the gate's slot
959
+ * (`credentialFromTypedSecret`) in the source the call runs with.
960
+ */
961
+ secret?: string;
962
+ credentials?: ToolCredentialSource;
963
+ host?: unknown;
964
+ /** The page's answer, for a call to a tool with `answeredBy: 'page'`. */
965
+ page?: PageAnswer;
966
+ };
967
+ /**
968
+ * Settle a call the model made in this session whose body ran in the process
969
+ * that owns the tool registry: `events` are that process's `invokeTool`
970
+ * events for `callId`, which ran with the model's input.
971
+ */
972
+ export type LiveAnswerToolCallArgs = {
973
+ callId: string;
974
+ events: readonly TurnEvent[];
975
+ };
976
+ /** What running a tool call during a live session returns. */
977
+ export type LiveExecuteToolResult = {
978
+ outputRaw?: unknown;
979
+ outputModel?: ModelToolResult;
980
+ failure?: ToolFailure;
981
+ awaiting?: boolean;
982
+ gated?: ToolGate;
983
+ };
984
+ /**
985
+ * Open live session returned by `runSession`. It streams events until
986
+ * `close()` and exposes realtime media ingress and staged tool execution.
987
+ */
988
+ export interface LiveSession {
989
+ readonly profileId: ProfileId;
990
+ readonly canary: string;
991
+ events(): AsyncGenerator<TurnEvent, void, undefined>;
992
+ /** `mimeType` states the audio as sent (`audio/pcm;rate=16000`); the API rejects what it cannot take. */
993
+ sendAudio(args: {
994
+ data: string;
995
+ mimeType: string;
996
+ }): Promise<void>;
997
+ /** `mimeType` states the frame as sent (`image/jpeg`). */
998
+ sendVideo(args: {
999
+ data: string;
1000
+ mimeType: string;
1001
+ }): Promise<void>;
1002
+ sendText(text: string): Promise<void>;
1003
+ /**
1004
+ * What the page or the host tells the model to know, by sender: it opens no turn and
1005
+ * draws no reply. Checked against `inputs.context` and read at the `context` boundary;
1006
+ * the model sees it from its next turn on.
1007
+ */
1008
+ sendContext(context: TurnContext): Promise<void>;
1009
+ /**
1010
+ * Run a call the model made through the registry, with stages; its events
1011
+ * join `events()`. A gate returns `gated` and answers the model nothing yet;
1012
+ * the call waits `gateTtlMs` for its `decision`. An unknown, settled,
1013
+ * running or expired call is a `request` error and runs nothing.
1014
+ */
1015
+ executeTool(args: LiveExecuteToolArgs): Promise<LiveExecuteToolResult>;
1016
+ /**
1017
+ * Settle a call whose body ran in the registry-owning process: its events
1018
+ * join `events()` and the model reads its `readBack`. A run that ends on a
1019
+ * gate leaves the call open; a released sign-in (`signInGate: 'answer'`)
1020
+ * takes its outcome until `gateTtlMs`. An unknown, settled, running or
1021
+ * expired call, or events that settle nothing for it, is a `request` error.
1022
+ */
1023
+ answerToolCall(args: LiveAnswerToolCallArgs): LiveExecuteToolResult;
1024
+ close(reason?: string): Promise<void>;
1025
+ }