@theoremjs/agents 0.0.0-stage → 0.3.0

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 (514) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1264 -2
  3. package/esm/_dnt.polyfills.d.ts +66 -0
  4. package/esm/_dnt.polyfills.js +51 -0
  5. package/esm/mod.d.ts +65 -0
  6. package/esm/mod.js +42 -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 +458 -0
  12. package/esm/src/cli/commands/egress-compile.d.ts +17 -0
  13. package/esm/src/cli/commands/egress-compile.js +25 -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 +202 -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 +25 -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 +72 -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 +4 -0
  35. package/esm/src/evals/attachments.js +53 -0
  36. package/esm/src/evals/breakdown.d.ts +28 -0
  37. package/esm/src/evals/breakdown.js +68 -0
  38. package/esm/src/evals/graders/answer.d.ts +13 -0
  39. package/esm/src/evals/graders/answer.js +133 -0
  40. package/esm/src/evals/graders/code.d.ts +64 -0
  41. package/esm/src/evals/graders/code.js +205 -0
  42. package/esm/src/evals/graders/judge.d.ts +20 -0
  43. package/esm/src/evals/graders/judge.js +365 -0
  44. package/esm/src/evals/graders/latency.d.ts +5 -0
  45. package/esm/src/evals/graders/latency.js +81 -0
  46. package/esm/src/evals/graders/live.d.ts +11 -0
  47. package/esm/src/evals/graders/live.js +40 -0
  48. package/esm/src/evals/graders/media.d.ts +18 -0
  49. package/esm/src/evals/graders/media.js +92 -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 +17 -0
  53. package/esm/src/evals/graders/transcript.js +200 -0
  54. package/esm/src/evals/mod.d.ts +42 -0
  55. package/esm/src/evals/mod.js +30 -0
  56. package/esm/src/evals/record.d.ts +35 -0
  57. package/esm/src/evals/record.js +105 -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 +118 -0
  67. package/esm/src/evals/run.js +452 -0
  68. package/esm/src/evals/suite.d.ts +19 -0
  69. package/esm/src/evals/suite.js +92 -0
  70. package/esm/src/evals/summary.d.ts +32 -0
  71. package/esm/src/evals/summary.js +30 -0
  72. package/esm/src/evals/trial.d.ts +27 -0
  73. package/esm/src/evals/trial.js +158 -0
  74. package/esm/src/evals/types.d.ts +260 -0
  75. package/esm/src/evals/types.js +126 -0
  76. package/esm/src/evals/verdict.d.ts +18 -0
  77. package/esm/src/evals/verdict.js +45 -0
  78. package/esm/src/guardrails/canary-gate.d.ts +21 -0
  79. package/esm/src/guardrails/canary-gate.js +40 -0
  80. package/esm/src/guardrails/canary.d.ts +112 -0
  81. package/esm/src/guardrails/canary.js +901 -0
  82. package/esm/src/guardrails/compile-egress.d.ts +11 -0
  83. package/esm/src/guardrails/compile-egress.js +11 -0
  84. package/esm/src/guardrails/corpus/canary-egress-attacks.d.ts +22 -0
  85. package/esm/src/guardrails/corpus/canary-egress-attacks.js +303 -0
  86. package/esm/src/guardrails/corpus/fuzz-inbound.d.ts +5 -0
  87. package/esm/src/guardrails/corpus/fuzz-inbound.js +202 -0
  88. package/esm/src/guardrails/corpus/inbound-payloads.d.ts +3 -0
  89. package/esm/src/guardrails/corpus/inbound-payloads.js +118 -0
  90. package/esm/src/guardrails/corpus/live-attacks.d.ts +13 -0
  91. package/esm/src/guardrails/corpus/live-attacks.js +224 -0
  92. package/esm/src/guardrails/corpus/mod.d.ts +7 -0
  93. package/esm/src/guardrails/corpus/mod.js +4 -0
  94. package/esm/src/guardrails/corpus/secrets.d.ts +12 -0
  95. package/esm/src/guardrails/corpus/secrets.js +16 -0
  96. package/esm/src/guardrails/corpus/strings.d.ts +23 -0
  97. package/esm/src/guardrails/corpus/strings.js +29 -0
  98. package/esm/src/guardrails/corpus/types.d.ts +32 -0
  99. package/esm/src/guardrails/corpus/types.js +1 -0
  100. package/esm/src/guardrails/egress-automata.d.ts +14 -0
  101. package/esm/src/guardrails/egress-automata.js +6059 -0
  102. package/esm/src/guardrails/egress-compiler.d.ts +33 -0
  103. package/esm/src/guardrails/egress-compiler.js +237 -0
  104. package/esm/src/guardrails/egress-patterns.d.ts +24 -0
  105. package/esm/src/guardrails/egress-patterns.js +32 -0
  106. package/esm/src/guardrails/egress-policy.d.ts +27 -0
  107. package/esm/src/guardrails/egress-policy.js +76 -0
  108. package/esm/src/guardrails/egress-rules.d.ts +54 -0
  109. package/esm/src/guardrails/egress-rules.js +49 -0
  110. package/esm/src/guardrails/egress-stream.d.ts +105 -0
  111. package/esm/src/guardrails/egress-stream.js +645 -0
  112. package/esm/src/guardrails/egress-urls.d.ts +83 -0
  113. package/esm/src/guardrails/egress-urls.js +917 -0
  114. package/esm/src/guardrails/egress.d.ts +106 -0
  115. package/esm/src/guardrails/egress.js +374 -0
  116. package/esm/src/guardrails/error.d.ts +26 -0
  117. package/esm/src/guardrails/error.js +91 -0
  118. package/esm/src/guardrails/event-schemas.d.ts +57 -0
  119. package/esm/src/guardrails/event-schemas.js +41 -0
  120. package/esm/src/guardrails/events.d.ts +9 -0
  121. package/esm/src/guardrails/events.js +42 -0
  122. package/esm/src/guardrails/hits.d.ts +8 -0
  123. package/esm/src/guardrails/hits.js +19 -0
  124. package/esm/src/guardrails/injection-patterns.d.ts +15 -0
  125. package/esm/src/guardrails/injection-patterns.js +94 -0
  126. package/esm/src/guardrails/injection.d.ts +14 -0
  127. package/esm/src/guardrails/injection.js +237 -0
  128. package/esm/src/guardrails/lexicon.d.ts +30 -0
  129. package/esm/src/guardrails/lexicon.js +478 -0
  130. package/esm/src/guardrails/live-outbound-gate.d.ts +54 -0
  131. package/esm/src/guardrails/live-outbound-gate.js +305 -0
  132. package/esm/src/guardrails/mod.d.ts +46 -0
  133. package/esm/src/guardrails/mod.js +29 -0
  134. package/esm/src/guardrails/network.d.ts +42 -0
  135. package/esm/src/guardrails/network.js +328 -0
  136. package/esm/src/guardrails/normalize.d.ts +6 -0
  137. package/esm/src/guardrails/normalize.js +132 -0
  138. package/esm/src/guardrails/policy.d.ts +19 -0
  139. package/esm/src/guardrails/policy.js +50 -0
  140. package/esm/src/guardrails/progressive-yield.d.ts +69 -0
  141. package/esm/src/guardrails/progressive-yield.js +237 -0
  142. package/esm/src/guardrails/prompt-echo.d.ts +38 -0
  143. package/esm/src/guardrails/prompt-echo.js +225 -0
  144. package/esm/src/guardrails/quota.d.ts +20 -0
  145. package/esm/src/guardrails/quota.js +80 -0
  146. package/esm/src/guardrails/rules.d.ts +56 -0
  147. package/esm/src/guardrails/rules.js +54 -0
  148. package/esm/src/guardrails/sanitize.d.ts +23 -0
  149. package/esm/src/guardrails/sanitize.js +184 -0
  150. package/esm/src/guardrails/sensitive.d.ts +29 -0
  151. package/esm/src/guardrails/sensitive.js +113 -0
  152. package/esm/src/guardrails/serialize.d.ts +14 -0
  153. package/esm/src/guardrails/serialize.js +37 -0
  154. package/esm/src/guardrails/testing.d.ts +9 -0
  155. package/esm/src/guardrails/testing.js +8 -0
  156. package/esm/src/guardrails/theorem-error.d.ts +18 -0
  157. package/esm/src/guardrails/theorem-error.js +53 -0
  158. package/esm/src/guardrails/thought-guard.d.ts +55 -0
  159. package/esm/src/guardrails/thought-guard.js +464 -0
  160. package/esm/src/guardrails/tool-directives.d.ts +19 -0
  161. package/esm/src/guardrails/tool-directives.js +109 -0
  162. package/esm/src/guardrails/tool-result.d.ts +61 -0
  163. package/esm/src/guardrails/tool-result.js +248 -0
  164. package/esm/src/guardrails/types.d.ts +242 -0
  165. package/esm/src/guardrails/types.js +54 -0
  166. package/esm/src/host/client-turn.d.ts +9 -0
  167. package/esm/src/host/client-turn.js +38 -0
  168. package/esm/src/host/mint-trace.d.ts +28 -0
  169. package/esm/src/host/mint-trace.js +59 -0
  170. package/esm/src/host/mod.d.ts +13 -0
  171. package/esm/src/host/mod.js +11 -0
  172. package/esm/src/host/readStreamingJsonStringField.d.ts +2 -0
  173. package/esm/src/host/readStreamingJsonStringField.js +68 -0
  174. package/esm/src/host/reply.d.ts +7 -0
  175. package/esm/src/host/reply.js +35 -0
  176. package/esm/src/interface/blocks.d.ts +8 -0
  177. package/esm/src/interface/blocks.js +213 -0
  178. package/esm/src/interface/composer-actions.d.ts +20 -0
  179. package/esm/src/interface/composer-actions.js +31 -0
  180. package/esm/src/interface/draft.d.ts +14 -0
  181. package/esm/src/interface/draft.js +28 -0
  182. package/esm/src/interface/from-profile.d.ts +12 -0
  183. package/esm/src/interface/from-profile.js +144 -0
  184. package/esm/src/interface/history.d.ts +40 -0
  185. package/esm/src/interface/history.js +269 -0
  186. package/esm/src/interface/inputs.d.ts +10 -0
  187. package/esm/src/interface/inputs.js +64 -0
  188. package/esm/src/interface/mod.d.ts +31 -0
  189. package/esm/src/interface/mod.js +21 -0
  190. package/esm/src/interface/models.d.ts +19 -0
  191. package/esm/src/interface/models.js +45 -0
  192. package/esm/src/interface/pending.d.ts +48 -0
  193. package/esm/src/interface/pending.js +146 -0
  194. package/esm/src/interface/profile-interface.d.ts +4 -0
  195. package/esm/src/interface/profile-interface.js +223 -0
  196. package/esm/src/interface/session.d.ts +64 -0
  197. package/esm/src/interface/session.js +121 -0
  198. package/esm/src/interface/tool-calls.d.ts +20 -0
  199. package/esm/src/interface/tool-calls.js +73 -0
  200. package/esm/src/interface/tool-invoke.d.ts +4 -0
  201. package/esm/src/interface/tool-invoke.js +20 -0
  202. package/esm/src/interface/tool-media.d.ts +9 -0
  203. package/esm/src/interface/tool-media.js +112 -0
  204. package/esm/src/interface/types.d.ts +213 -0
  205. package/esm/src/interface/types.js +4 -0
  206. package/esm/src/kernel/auth/credential-source.d.ts +23 -0
  207. package/esm/src/kernel/auth/credential-source.js +11 -0
  208. package/esm/src/kernel/auth/crypto.d.ts +51 -0
  209. package/esm/src/kernel/auth/crypto.js +161 -0
  210. package/esm/src/kernel/auth/mod.d.ts +5 -0
  211. package/esm/src/kernel/auth/mod.js +5 -0
  212. package/esm/src/kernel/auth/oauth.d.ts +17 -0
  213. package/esm/src/kernel/auth/oauth.js +438 -0
  214. package/esm/src/kernel/auth/scope-refusal.d.ts +9 -0
  215. package/esm/src/kernel/auth/scope-refusal.js +8 -0
  216. package/esm/src/kernel/auth/typed-secret.d.ts +13 -0
  217. package/esm/src/kernel/auth/typed-secret.js +23 -0
  218. package/esm/src/kernel/auth/types.d.ts +139 -0
  219. package/esm/src/kernel/auth/types.js +1 -0
  220. package/esm/src/kernel/default-scope.d.ts +34 -0
  221. package/esm/src/kernel/default-scope.js +72 -0
  222. package/esm/src/kernel/engine/compaction.d.ts +70 -0
  223. package/esm/src/kernel/engine/compaction.js +202 -0
  224. package/esm/src/kernel/engine/decision.d.ts +41 -0
  225. package/esm/src/kernel/engine/decision.js +412 -0
  226. package/esm/src/kernel/engine/hash.d.ts +6 -0
  227. package/esm/src/kernel/engine/hash.js +22 -0
  228. package/esm/src/kernel/engine/live-inbound.d.ts +9 -0
  229. package/esm/src/kernel/engine/live-inbound.js +19 -0
  230. package/esm/src/kernel/engine/live-ingress.d.ts +9 -0
  231. package/esm/src/kernel/engine/live-ingress.js +37 -0
  232. package/esm/src/kernel/engine/media-probe/audio.d.ts +7 -0
  233. package/esm/src/kernel/engine/media-probe/audio.js +342 -0
  234. package/esm/src/kernel/engine/media-probe/bytes.d.ts +6 -0
  235. package/esm/src/kernel/engine/media-probe/bytes.js +26 -0
  236. package/esm/src/kernel/engine/media-probe/image.d.ts +5 -0
  237. package/esm/src/kernel/engine/media-probe/image.js +171 -0
  238. package/esm/src/kernel/engine/media-probe/iso-bmff.d.ts +19 -0
  239. package/esm/src/kernel/engine/media-probe/iso-bmff.js +48 -0
  240. package/esm/src/kernel/engine/media-probe/matroska.d.ts +35 -0
  241. package/esm/src/kernel/engine/media-probe/matroska.js +226 -0
  242. package/esm/src/kernel/engine/media-probe/mp4.d.ts +22 -0
  243. package/esm/src/kernel/engine/media-probe/mp4.js +279 -0
  244. package/esm/src/kernel/engine/media-probe/opus.d.ts +4 -0
  245. package/esm/src/kernel/engine/media-probe/opus.js +23 -0
  246. package/esm/src/kernel/engine/media-probe/pdf.d.ts +5 -0
  247. package/esm/src/kernel/engine/media-probe/pdf.js +117 -0
  248. package/esm/src/kernel/engine/media-probe/video.d.ts +15 -0
  249. package/esm/src/kernel/engine/media-probe/video.js +49 -0
  250. package/esm/src/kernel/engine/record.d.ts +3 -0
  251. package/esm/src/kernel/engine/record.js +11 -0
  252. package/esm/src/kernel/engine/repair.d.ts +7 -0
  253. package/esm/src/kernel/engine/repair.js +36 -0
  254. package/esm/src/kernel/engine/runner/gates.d.ts +5 -0
  255. package/esm/src/kernel/engine/runner/gates.js +322 -0
  256. package/esm/src/kernel/engine/runner/mod.d.ts +15 -0
  257. package/esm/src/kernel/engine/runner/mod.js +574 -0
  258. package/esm/src/kernel/engine/runner/schema-validation.d.ts +14 -0
  259. package/esm/src/kernel/engine/runner/schema-validation.js +105 -0
  260. package/esm/src/kernel/engine/runner/stages.d.ts +28 -0
  261. package/esm/src/kernel/engine/runner/stages.js +48 -0
  262. package/esm/src/kernel/engine/runner/state.d.ts +76 -0
  263. package/esm/src/kernel/engine/runner/state.js +40 -0
  264. package/esm/src/kernel/engine/runner/steps.d.ts +14 -0
  265. package/esm/src/kernel/engine/runner/steps.js +360 -0
  266. package/esm/src/kernel/engine/runner/stream.d.ts +40 -0
  267. package/esm/src/kernel/engine/runner/stream.js +225 -0
  268. package/esm/src/kernel/engine/runner/usage.d.ts +45 -0
  269. package/esm/src/kernel/engine/runner/usage.js +150 -0
  270. package/esm/src/kernel/engine/session/mod.d.ts +31 -0
  271. package/esm/src/kernel/engine/session/mod.js +951 -0
  272. package/esm/src/kernel/engine/session/session-trace.d.ts +115 -0
  273. package/esm/src/kernel/engine/session/session-trace.js +489 -0
  274. package/esm/src/kernel/engine/token-estimate.d.ts +77 -0
  275. package/esm/src/kernel/engine/token-estimate.js +218 -0
  276. package/esm/src/kernel/engine/tool-trace.d.ts +58 -0
  277. package/esm/src/kernel/engine/tool-trace.js +131 -0
  278. package/esm/src/kernel/engine/tree.d.ts +2 -0
  279. package/esm/src/kernel/engine/tree.js +17 -0
  280. package/esm/src/kernel/engine/turn-trace.d.ts +118 -0
  281. package/esm/src/kernel/engine/turn-trace.js +863 -0
  282. package/esm/src/kernel/engine/usage.d.ts +30 -0
  283. package/esm/src/kernel/engine/usage.js +134 -0
  284. package/esm/src/kernel/interaction-parts.d.ts +10 -0
  285. package/esm/src/kernel/interaction-parts.js +22 -0
  286. package/esm/src/kernel/mod.d.ts +47 -0
  287. package/esm/src/kernel/mod.js +30 -0
  288. package/esm/src/kernel/profile-graph.d.ts +140 -0
  289. package/esm/src/kernel/profile-graph.js +151 -0
  290. package/esm/src/kernel/profile-presence.d.ts +9 -0
  291. package/esm/src/kernel/profile-presence.js +143 -0
  292. package/esm/src/kernel/profile-scope.d.ts +36 -0
  293. package/esm/src/kernel/profile-scope.js +262 -0
  294. package/esm/src/kernel/registry/attachments.d.ts +35 -0
  295. package/esm/src/kernel/registry/attachments.js +211 -0
  296. package/esm/src/kernel/registry/catalog.d.ts +19 -0
  297. package/esm/src/kernel/registry/catalog.js +78 -0
  298. package/esm/src/kernel/registry/ingress.d.ts +8 -0
  299. package/esm/src/kernel/registry/ingress.js +134 -0
  300. package/esm/src/kernel/registry/kernel-registry.d.ts +12 -0
  301. package/esm/src/kernel/registry/kernel-registry.js +8 -0
  302. package/esm/src/kernel/registry/profile-outputs.d.ts +3 -0
  303. package/esm/src/kernel/registry/profile-outputs.js +7 -0
  304. package/esm/src/kernel/registry/profiles.d.ts +92 -0
  305. package/esm/src/kernel/registry/profiles.js +698 -0
  306. package/esm/src/kernel/registry/provider-request.d.ts +6 -0
  307. package/esm/src/kernel/registry/provider-request.js +42 -0
  308. package/esm/src/kernel/registry/resolve.d.ts +14 -0
  309. package/esm/src/kernel/registry/resolve.js +237 -0
  310. package/esm/src/kernel/registry/schemas.d.ts +9 -0
  311. package/esm/src/kernel/registry/schemas.js +25 -0
  312. package/esm/src/kernel/registry/sole-model.d.ts +2 -0
  313. package/esm/src/kernel/registry/sole-model.js +4 -0
  314. package/esm/src/kernel/registry/system-prompt.d.ts +8 -0
  315. package/esm/src/kernel/registry/system-prompt.js +33 -0
  316. package/esm/src/kernel/registry/system-role.d.ts +3 -0
  317. package/esm/src/kernel/registry/system-role.js +9 -0
  318. package/esm/src/kernel/registry/vault.d.ts +13 -0
  319. package/esm/src/kernel/registry/vault.js +14 -0
  320. package/esm/src/kernel/schema.d.ts +172 -0
  321. package/esm/src/kernel/schema.js +653 -0
  322. package/esm/src/kernel/scope.d.ts +22 -0
  323. package/esm/src/kernel/scope.js +25 -0
  324. package/esm/src/kernel/stages.d.ts +141 -0
  325. package/esm/src/kernel/stages.js +388 -0
  326. package/esm/src/kernel/stop.d.ts +93 -0
  327. package/esm/src/kernel/stop.js +125 -0
  328. package/esm/src/kernel/system-parts.d.ts +26 -0
  329. package/esm/src/kernel/system-parts.js +98 -0
  330. package/esm/src/kernel/tools/activity-label.d.ts +16 -0
  331. package/esm/src/kernel/tools/activity-label.js +209 -0
  332. package/esm/src/kernel/tools/events.d.ts +51 -0
  333. package/esm/src/kernel/tools/events.js +149 -0
  334. package/esm/src/kernel/tools/execute.d.ts +64 -0
  335. package/esm/src/kernel/tools/execute.js +801 -0
  336. package/esm/src/kernel/tools/gate-answer.d.ts +50 -0
  337. package/esm/src/kernel/tools/gate-answer.js +54 -0
  338. package/esm/src/kernel/tools/harness.d.ts +16 -0
  339. package/esm/src/kernel/tools/harness.js +42 -0
  340. package/esm/src/kernel/tools/invoke.d.ts +10 -0
  341. package/esm/src/kernel/tools/invoke.js +129 -0
  342. package/esm/src/kernel/tools/mcp-sessions.d.ts +20 -0
  343. package/esm/src/kernel/tools/mcp-sessions.js +64 -0
  344. package/esm/src/kernel/tools/mod.d.ts +9 -0
  345. package/esm/src/kernel/tools/mod.js +6 -0
  346. package/esm/src/kernel/tools/model-text.d.ts +11 -0
  347. package/esm/src/kernel/tools/model-text.js +25 -0
  348. package/esm/src/kernel/tools/permission.d.ts +6 -0
  349. package/esm/src/kernel/tools/permission.js +38 -0
  350. package/esm/src/kernel/tools/project.d.ts +8 -0
  351. package/esm/src/kernel/tools/project.js +25 -0
  352. package/esm/src/kernel/tools/registry.d.ts +20 -0
  353. package/esm/src/kernel/tools/registry.js +84 -0
  354. package/esm/src/kernel/tools/remote.d.ts +110 -0
  355. package/esm/src/kernel/tools/remote.js +998 -0
  356. package/esm/src/kernel/tools/resolve.d.ts +28 -0
  357. package/esm/src/kernel/tools/resolve.js +259 -0
  358. package/esm/src/kernel/tools/schema.d.ts +10 -0
  359. package/esm/src/kernel/tools/schema.js +174 -0
  360. package/esm/src/kernel/tools/signed-in-fetch.d.ts +18 -0
  361. package/esm/src/kernel/tools/signed-in-fetch.js +45 -0
  362. package/esm/src/kernel/tools/stage-run.d.ts +93 -0
  363. package/esm/src/kernel/tools/stage-run.js +140 -0
  364. package/esm/src/kernel/tools/types.d.ts +287 -0
  365. package/esm/src/kernel/tools/types.js +1 -0
  366. package/esm/src/kernel/turn-events.d.ts +599 -0
  367. package/esm/src/kernel/turn-events.js +425 -0
  368. package/esm/src/kernel/types.d.ts +884 -0
  369. package/esm/src/kernel/types.js +1 -0
  370. package/esm/src/kernel/util/base64.d.ts +2 -0
  371. package/esm/src/kernel/util/base64.js +13 -0
  372. package/esm/src/kernel/util/exact-type.d.ts +31 -0
  373. package/esm/src/kernel/util/exact-type.js +1 -0
  374. package/esm/src/kernel/util/find-last.d.ts +3 -0
  375. package/esm/src/kernel/util/find-last.js +9 -0
  376. package/esm/src/kernel/util/mime.d.ts +2 -0
  377. package/esm/src/kernel/util/mime.js +4 -0
  378. package/esm/src/kernel/util/record.d.ts +1 -0
  379. package/esm/src/kernel/util/record.js +3 -0
  380. package/esm/src/observability/destinations.d.ts +9 -0
  381. package/esm/src/observability/destinations.js +38 -0
  382. package/esm/src/observability/jsonl.d.ts +18 -0
  383. package/esm/src/observability/jsonl.js +117 -0
  384. package/esm/src/observability/mod.d.ts +22 -0
  385. package/esm/src/observability/mod.js +16 -0
  386. package/esm/src/observability/openinference.d.ts +11 -0
  387. package/esm/src/observability/openinference.js +205 -0
  388. package/esm/src/observability/otlp.d.ts +68 -0
  389. package/esm/src/observability/otlp.js +98 -0
  390. package/esm/src/observability/phoenix.d.ts +29 -0
  391. package/esm/src/observability/phoenix.js +71 -0
  392. package/esm/src/observability/policy.d.ts +14 -0
  393. package/esm/src/observability/policy.js +69 -0
  394. package/esm/src/observability/resolve-policy.d.ts +8 -0
  395. package/esm/src/observability/resolve-policy.js +58 -0
  396. package/esm/src/observability/spans.d.ts +16 -0
  397. package/esm/src/observability/spans.js +56 -0
  398. package/esm/src/observability/trace-catalog.d.ts +111 -0
  399. package/esm/src/observability/trace-catalog.js +865 -0
  400. package/esm/src/observability/trace-record.d.ts +23 -0
  401. package/esm/src/observability/trace-record.js +223 -0
  402. package/esm/src/observability/trace-schema.d.ts +54 -0
  403. package/esm/src/observability/trace-schema.js +59 -0
  404. package/esm/src/observability/trace-sink.d.ts +13 -0
  405. package/esm/src/observability/trace-sink.js +3 -0
  406. package/esm/src/observability/trace-span.d.ts +92 -0
  407. package/esm/src/observability/trace-span.js +199 -0
  408. package/esm/src/observability/trace.d.ts +11 -0
  409. package/esm/src/observability/trace.js +35 -0
  410. package/esm/src/observability/types.d.ts +85 -0
  411. package/esm/src/observability/types.js +3 -0
  412. package/esm/src/presets/google/speech-voices.d.ts +8 -0
  413. package/esm/src/presets/google/speech-voices.js +38 -0
  414. package/esm/src/presets/google-limits.d.ts +12 -0
  415. package/esm/src/presets/google-limits.js +18 -0
  416. package/esm/src/presets/google.d.ts +104 -0
  417. package/esm/src/presets/google.js +188 -0
  418. package/esm/src/presets/mod.d.ts +10 -0
  419. package/esm/src/presets/mod.js +9 -0
  420. package/esm/src/presets/openrouter.d.ts +13 -0
  421. package/esm/src/presets/openrouter.js +13 -0
  422. package/esm/src/presets/typesafe.d.ts +2 -0
  423. package/esm/src/presets/typesafe.js +2 -0
  424. package/esm/src/providers/create-provider.d.ts +21 -0
  425. package/esm/src/providers/create-provider.js +90 -0
  426. package/esm/src/providers/decision/usage.d.ts +3 -0
  427. package/esm/src/providers/decision/usage.js +25 -0
  428. package/esm/src/providers/google/api-error.d.ts +8 -0
  429. package/esm/src/providers/google/api-error.js +123 -0
  430. package/esm/src/providers/google/grounding.d.ts +5 -0
  431. package/esm/src/providers/google/grounding.js +226 -0
  432. package/esm/src/providers/google/interactions/framing.d.ts +15 -0
  433. package/esm/src/providers/google/interactions/framing.js +263 -0
  434. package/esm/src/providers/google/interactions/mod.d.ts +2 -0
  435. package/esm/src/providers/google/interactions/mod.js +2 -0
  436. package/esm/src/providers/google/interactions/steps.d.ts +12 -0
  437. package/esm/src/providers/google/interactions/steps.js +200 -0
  438. package/esm/src/providers/google/interactions/stream.d.ts +24 -0
  439. package/esm/src/providers/google/interactions/stream.js +297 -0
  440. package/esm/src/providers/google/keys.d.ts +20 -0
  441. package/esm/src/providers/google/keys.js +87 -0
  442. package/esm/src/providers/google/live/framing.d.ts +51 -0
  443. package/esm/src/providers/google/live/framing.js +597 -0
  444. package/esm/src/providers/google/live/mod.d.ts +7 -0
  445. package/esm/src/providers/google/live/mod.js +7 -0
  446. package/esm/src/providers/google/live/openapi-schema.d.ts +1 -0
  447. package/esm/src/providers/google/live/openapi-schema.js +42 -0
  448. package/esm/src/providers/google/live/session.d.ts +14 -0
  449. package/esm/src/providers/google/live/session.js +150 -0
  450. package/esm/src/providers/google/live/stream.d.ts +51 -0
  451. package/esm/src/providers/google/live/stream.js +263 -0
  452. package/esm/src/providers/google/thinking.d.ts +3 -0
  453. package/esm/src/providers/google/thinking.js +8 -0
  454. package/esm/src/providers/google/urls.d.ts +6 -0
  455. package/esm/src/providers/google/urls.js +6 -0
  456. package/esm/src/providers/google/usage.d.ts +7 -0
  457. package/esm/src/providers/google/usage.js +49 -0
  458. package/esm/src/providers/local/local.d.ts +12 -0
  459. package/esm/src/providers/local/local.js +186 -0
  460. package/esm/src/providers/local/mod.d.ts +8 -0
  461. package/esm/src/providers/local/mod.js +8 -0
  462. package/esm/src/providers/mod.d.ts +11 -0
  463. package/esm/src/providers/mod.js +7 -0
  464. package/esm/src/providers/openrouter/cache-control.d.ts +5 -0
  465. package/esm/src/providers/openrouter/cache-control.js +4 -0
  466. package/esm/src/providers/openrouter/chat.d.ts +64 -0
  467. package/esm/src/providers/openrouter/chat.js +490 -0
  468. package/esm/src/providers/openrouter/image.d.ts +24 -0
  469. package/esm/src/providers/openrouter/image.js +187 -0
  470. package/esm/src/providers/openrouter/openai/compat.d.ts +19 -0
  471. package/esm/src/providers/openrouter/openai/compat.js +162 -0
  472. package/esm/src/providers/openrouter/openai/image-payload.d.ts +9 -0
  473. package/esm/src/providers/openrouter/openai/image-payload.js +115 -0
  474. package/esm/src/providers/openrouter/openai/sdk-messages.d.ts +10 -0
  475. package/esm/src/providers/openrouter/openai/sdk-messages.js +99 -0
  476. package/esm/src/providers/openrouter/openai/usage.d.ts +8 -0
  477. package/esm/src/providers/openrouter/openai/usage.js +56 -0
  478. package/esm/src/providers/openrouter/resolve-api-key.d.ts +3 -0
  479. package/esm/src/providers/openrouter/resolve-api-key.js +8 -0
  480. package/esm/src/providers/openrouter/speech.d.ts +18 -0
  481. package/esm/src/providers/openrouter/speech.js +109 -0
  482. package/esm/src/providers/probe.d.ts +5 -0
  483. package/esm/src/providers/probe.js +15 -0
  484. package/esm/src/providers/shared/builtin-wire.d.ts +4 -0
  485. package/esm/src/providers/shared/builtin-wire.js +9 -0
  486. package/esm/src/providers/shared/pcm.d.ts +14 -0
  487. package/esm/src/providers/shared/pcm.js +78 -0
  488. package/esm/src/providers/shared/response-identity.d.ts +11 -0
  489. package/esm/src/providers/shared/response-identity.js +12 -0
  490. package/esm/src/providers/shared/sse.d.ts +10 -0
  491. package/esm/src/providers/shared/sse.js +79 -0
  492. package/esm/src/providers/shared/structured-output.d.ts +4 -0
  493. package/esm/src/providers/shared/structured-output.js +11 -0
  494. package/esm/src/providers/shared/tool-args.d.ts +25 -0
  495. package/esm/src/providers/shared/tool-args.js +84 -0
  496. package/esm/src/providers/shared/upstream-tap.d.ts +8 -0
  497. package/esm/src/providers/shared/upstream-tap.js +85 -0
  498. package/esm/src/providers/shared/upstream-tape.d.ts +6 -0
  499. package/esm/src/providers/shared/upstream-tape.js +88 -0
  500. package/esm/src/providers/shared/vault.d.ts +13 -0
  501. package/esm/src/providers/shared/vault.js +41 -0
  502. package/esm/src/providers/types.d.ts +19 -0
  503. package/esm/src/providers/types.js +1 -0
  504. package/esm/src/surface/formats.d.ts +28 -0
  505. package/esm/src/surface/formats.js +139 -0
  506. package/esm/src/surface/mod.d.ts +14 -0
  507. package/esm/src/surface/mod.js +10 -0
  508. package/esm/src/surface/runtime.d.ts +40 -0
  509. package/esm/src/surface/runtime.js +439 -0
  510. package/esm/src/surface/tools.d.ts +15 -0
  511. package/esm/src/surface/tools.js +80 -0
  512. package/esm/src/surface/types.d.ts +104 -0
  513. package/esm/src/surface/types.js +4 -0
  514. package/package.json +108 -4
@@ -0,0 +1,884 @@
1
+ import type { CacheMode, CacheTtl, CompactionMeter, CompactionOutcome, CompactionTiming, ContinueStopKind, FieldMeta, KeySlot, KeyVault, LiveActivityHandling, LiveEndSensitivity, LiveStartSensitivity, MediaInputKind, ProfileType, ProfileTypeProtocol, Protocol, Provider, SpeechAudioFormat, StreamMode, SummaryMode, ThinkingLevel, ToolLoadTier, TurnStage, TurnStopKind } from './schema.js';
2
+ import type { StageHandler } from './stages.js';
3
+ import type { GateDecision } from './tools/gate-answer.js';
4
+ import type { BuiltinWire, HostProfileToolsSpec, InvokeToolRequest, InvokeToolResume, LiveProfileToolsSpec, ModelToolResult, ProfileToolsSpec, RegisteredTool, ToolCallEvent, ToolFailure, ToolGate, ToolLoadContext, ToolPolicy, TurnToolSnapshot, WireFunctionTool } from './tools/types.js';
5
+ import type { CallDone, CompactionFailure, CompactionResult, CompactionSignal, DoneFields, GroundingEvent, InteractionMediaPart, InteractionMediaRefPart, InteractionPart, InteractionTextPart, ProviderEvent, ProviderEvidence, SessionEnded, SessionEvent, SessionEventKind, SessionEventOf, Source, TurnCost, TurnEvent, TurnEventOf, TurnEventType, TurnGroundingCount, TurnHistoryMessage, TurnResponse, TurnTokenSide, TurnTokens } from './turn-events.js';
6
+ export type { CacheMode, CacheTtl, CallDone, CompactionFailure, CompactionMeter, CompactionOutcome, CompactionResult, CompactionSignal, CompactionTiming, ContinueStopKind, DoneFields, FieldMeta, GroundingEvent, HostProfileToolsSpec, InteractionMediaPart, InteractionMediaRefPart, InteractionPart, InteractionTextPart, InvokeToolRequest, InvokeToolResume, KeySlot, KeyVault, LiveActivityHandling, LiveEndSensitivity, LiveProfileToolsSpec, LiveStartSensitivity, MediaInputKind, ProfileToolsSpec, ProfileType, ProfileTypeProtocol, Protocol, Provider, ProviderEvent, ProviderEvidence, RegisteredTool, 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, };
7
+ export type ModelId = string;
8
+ export type BuiltinToolId = string;
9
+ export type ToolId = string;
10
+ export type StructuredSchemaId = string;
11
+ export interface ResolvedStructured {
12
+ id: StructuredSchemaId;
13
+ jsonSchema: Record<string, unknown>;
14
+ }
15
+ export interface ProviderBuiltin {
16
+ id: BuiltinToolId;
17
+ wire: BuiltinWire;
18
+ }
19
+ export type ProfileId = string;
20
+ export type ChatRole = 'system' | 'user' | 'assistant';
21
+ /** Host strings (presets own the vocabularies); an unpinned value is the provider default. */
22
+ export interface ProfileImageSpec {
23
+ aspectRatio?: string;
24
+ resolution?: string;
25
+ mimeType?: string;
26
+ quality?: string;
27
+ background?: string;
28
+ n?: number;
29
+ seed?: number;
30
+ outputCompression?: number;
31
+ references?: Array<TurnBlob | TurnMediaRef>;
32
+ /** Also request interleaved text with the images (Google: text + image `response_format`). */
33
+ includeText?: boolean;
34
+ }
35
+ export interface ModelBinding {
36
+ protocol: Protocol;
37
+ provider: Provider;
38
+ apiId: string;
39
+ /** Alias → thinking level. One entry = fixed; two+ may be selectable at turn time. */
40
+ efforts?: Record<string, ThinkingLevel>;
41
+ /** Effort alias when the turn omits `effort`. Defaults to the only key when there is one. */
42
+ defaultEffort?: string;
43
+ /** Turn may pass `{ effort: "<alias>" }`. Requires two or more `efforts` keys. */
44
+ allowEffortSelect?: boolean;
45
+ /** Emit thinking summaries on the stream. Omit → provider default. */
46
+ summaries?: boolean;
47
+ /** Cap on output tokens. Omit → provider default. */
48
+ maxOutputTokens?: number;
49
+ /** Sampling temperature. Omit → provider default. */
50
+ temperature?: number;
51
+ builtInTools?: BuiltinToolId[];
52
+ /** Overrides `profile.key` for this model. */
53
+ key?: KeySlot;
54
+ /** Overrides `profile.fallbackKey` for this model. */
55
+ fallbackKey?: KeySlot;
56
+ compaction?: CompactionSpec;
57
+ /**
58
+ * OpenRouter prompt-cache policy. Omit → no opt-in `cache_control`.
59
+ * `defineProfile` accepts only when `provider` is `openrouter` (protocol `openAi`).
60
+ */
61
+ cache?: CacheSpec;
62
+ /** Gemini Interactions: whether the provider stores the interaction. Omit → provider default. */
63
+ store?: boolean;
64
+ /**
65
+ * Gemini Interactions: `true` chains each step and turn on Google's stored
66
+ * interaction (`previous_interaction_id`), so Google builds the context;
67
+ * `false` sends the history the host passes, plus this turn's steps, on every
68
+ * call — across turns the host builds that history. Required on every
69
+ * `geminiInteractions` binding; `true` needs `store` left on.
70
+ */
71
+ persistViaInteractionId?: boolean;
72
+ /**
73
+ * Local server that hosts the model (e.g. `ollama`, `vllm`, `llama.cpp`).
74
+ * Traces report it as `gen_ai.provider.name`; omit → the attribute is absent.
75
+ * `defineProfile` accepts only when `provider` is `local`.
76
+ */
77
+ server?: string;
78
+ }
79
+ /**
80
+ * OpenRouter prompt-cache policy (`models.*.cache`).
81
+ *
82
+ * - `automatic` — top-level `cache_control`; breakpoint advances with the conversation.
83
+ * - `system` — explicit breakpoint on the system instruction only.
84
+ */
85
+ export interface CacheSpec {
86
+ mode: CacheMode;
87
+ /** Ephemeral TTL. Omit → provider default (typically 5m on Anthropic). */
88
+ ttl?: CacheTtl;
89
+ }
90
+ export interface CompactionTriggerContext {
91
+ tokens: number;
92
+ maxTokens: number;
93
+ compactAt: number;
94
+ meter: CompactionMeter;
95
+ /** Media parts not counted in `tokens` — no verified rule for this model. */
96
+ unknownMedia: number;
97
+ }
98
+ export interface CompactionSpec {
99
+ /**
100
+ * Token budget compared by the trigger (`compactAt * maxTokens`).
101
+ * Meaning depends on `meter`: history budget vs full-prompt input budget.
102
+ */
103
+ maxTokens: number;
104
+ /** Fraction of `maxTokens` at which compaction fires. Must be in (0, 1). */
105
+ compactAt: number;
106
+ /**
107
+ * Recent exchanges kept verbatim (an exchange is a user message and everything up to the
108
+ * next one). `≥ 1` = exchange count, `(0, 1)` = fraction of `maxTokens`, `0` = compact all.
109
+ */
110
+ previousExchanges: number;
111
+ /**
112
+ * Profile id of the compaction agent. Must be registered before the owning profile.
113
+ * Omit it and the agent compacts its own history: the same instructions and model, no tools.
114
+ */
115
+ profile?: ProfileId;
116
+ /**
117
+ * When compaction runs relative to the primary turn.
118
+ * - `'before'`: kernel compacts synchronously before the turn; user pays latency on this turn.
119
+ * - `'after'`: kernel signals in the `done` event; host runs compaction asynchronously.
120
+ */
121
+ timing: CompactionTiming;
122
+ /**
123
+ * Threshold meter. Defaults to `'history'`.
124
+ * Use `'input'` when the host prefers provider full-prompt usage (after
125
+ * subtracting a known baseline in `maxTokens` / `compactAt`).
126
+ */
127
+ meter?: CompactionMeter;
128
+ /** Replaces the default `tokens > compactAt * maxTokens` check. */
129
+ trigger?: (ctx: CompactionTriggerContext) => boolean | Promise<boolean>;
130
+ }
131
+ /** `compactHistory` input, for `timing: 'after'`: the host passes back what `done.compaction` carried. */
132
+ export interface CompactHistoryRequest {
133
+ /** The profile whose model binding carries the `compaction` spec. */
134
+ profile: ProfileId;
135
+ /** That binding; defaults to the profile's `defaultModel`. */
136
+ model?: ModelId;
137
+ history: TurnHistoryMessage[];
138
+ /** `done.compaction.tokens`: a failed compactor drops `toCompact` only when this is over `maxTokens`. */
139
+ tokens: number;
140
+ signal?: AbortSignal;
141
+ traceparent?: string;
142
+ conversationId?: string;
143
+ metadata?: Record<string, unknown>;
144
+ }
145
+ export interface StructuredSpec {
146
+ jsonSchema: Record<string, unknown>;
147
+ }
148
+ export interface MediaLimits {
149
+ maxFiles: number;
150
+ maxBytes: number;
151
+ maxTurnBytes: number;
152
+ limitsByMime?: Record<string, number>;
153
+ }
154
+ export interface MimeInputs extends Partial<MediaLimits> {
155
+ text?: boolean;
156
+ attachments?: {
157
+ accept: string[];
158
+ };
159
+ voice?: {
160
+ accept: string[];
161
+ };
162
+ }
163
+ export type AttachmentValidationCode = 'mime_not_allowed' | 'too_many_files' | 'file_too_large' | 'turn_too_large' | 'attachments_not_accepted' | 'voice_not_accepted' | 'limits_unconfigured';
164
+ /**
165
+ * Structured parameters for rendering one validation issue. Validation emits
166
+ * codes + params only; the wording is the lexicon's `attachments.*` lines.
167
+ */
168
+ export interface AttachmentValidationParams {
169
+ maxFiles?: number;
170
+ maxBytes?: number;
171
+ maxTurnBytes?: number;
172
+ mimeType?: string;
173
+ channel?: 'attachment' | 'voice';
174
+ }
175
+ /** One reason a turn's files were refused; `fileName` names the file when the problem is one file's. */
176
+ export interface AttachmentValidationIssue {
177
+ code: AttachmentValidationCode;
178
+ params?: AttachmentValidationParams;
179
+ fileName?: string;
180
+ }
181
+ export interface StructuredBySlot {
182
+ by: string;
183
+ map: Record<string, string>;
184
+ fallback: string;
185
+ }
186
+ export interface ValidationResult {
187
+ isValid: boolean;
188
+ error?: string;
189
+ finding?: string;
190
+ data?: Record<string, unknown>;
191
+ }
192
+ export type ProfileValidator = (candidate: unknown, slots?: Record<string, string>) => ValidationResult | Promise<ValidationResult>;
193
+ export interface ProfileValidationSpec {
194
+ /**
195
+ * Host domain validators keyed by dotted paths into structured output
196
+ * (e.g. `diagram.mermaid`). Presence/required is owned by the JSON Schema;
197
+ * these run only for required paths and for optional paths that are present.
198
+ */
199
+ fields?: Record<string, ProfileValidator>;
200
+ maxRetries?: number;
201
+ }
202
+ /** `voice` is the TTS voice id, not ingress audio (`inputs.voice`). */
203
+ export interface ProfileSpeechSpec {
204
+ voice?: string;
205
+ /** `mp3` requires `protocol: 'openAi'` speech; rejected on Interactions. */
206
+ format?: SpeechAudioFormat;
207
+ }
208
+ export interface LiveVadSpec {
209
+ activityHandling?: LiveActivityHandling;
210
+ startSensitivity?: LiveStartSensitivity;
211
+ endSensitivity?: LiveEndSensitivity;
212
+ prefixPaddingMs?: number;
213
+ silenceDurationMs?: number;
214
+ }
215
+ /**
216
+ * Context window compression for a live session: once the context reaches the
217
+ * trigger, the mechanism shrinks it. Without it, Gemini ends audio sessions at
218
+ * 15 minutes and audio-video sessions at 2.
219
+ */
220
+ export interface LiveContextCompressionSpec {
221
+ /**
222
+ * Context tokens, counted before a turn, that start compression. A whole
223
+ * number above 0. Omit → provider default (Gemini: 80% of the model's context
224
+ * window).
225
+ */
226
+ triggerTokens?: number;
227
+ /** Drops the oldest turns; the system instruction stays. Gemini's only mechanism. */
228
+ slidingWindow: LiveSlidingWindowSpec;
229
+ }
230
+ export interface LiveSlidingWindowSpec {
231
+ /**
232
+ * Tokens to keep after compressing. A whole number above 0, below
233
+ * `triggerTokens`. Omit → provider default (Gemini: half of `triggerTokens`).
234
+ */
235
+ targetTokens?: number;
236
+ }
237
+ export interface LiveTranscriptionSpec {
238
+ input?: boolean;
239
+ output?: boolean;
240
+ }
241
+ /**
242
+ * Realtime ingress modalities for a live session.
243
+ * Distinct from turn `inputs` (file attachments, MIME limits) — these gate
244
+ * `LiveSession.sendAudio` / `sendVideo` / `sendText` channels.
245
+ */
246
+ export interface LiveIngressSpec {
247
+ /** Microphone PCM via `sendAudio`. Omit → enabled. */
248
+ audio?: boolean;
249
+ /** Webcam JPEG frames via `sendVideo`. Omit → enabled. */
250
+ video?: boolean;
251
+ /** Typed text via `sendText`. Omit → disabled (opt-in). */
252
+ text?: boolean;
253
+ }
254
+ export interface ProfileLiveSpec {
255
+ ingress?: LiveIngressSpec;
256
+ voice?: string;
257
+ vad?: LiveVadSpec;
258
+ sessionResumption?: boolean;
259
+ /** Context window compression. Omit → none: the provider ends the session at its limit. */
260
+ contextCompression?: LiveContextCompressionSpec;
261
+ transcription?: LiveTranscriptionSpec;
262
+ }
263
+ export interface ProfileStreamingSpec {
264
+ mode?: StreamMode;
265
+ /** When false, filter `thought` events from the turn stream. */
266
+ streamThoughts?: boolean;
267
+ }
268
+ export type { MediaTurnBehaviourSpec, ProfileTurnBehaviourSpec, ProfileTurnResumptionSpec, TurnContinueFrom, TurnStop, } from './stop.js';
269
+ import type { LexiconOverrides } from '../guardrails/lexicon.js';
270
+ import type { ResolveHost } from '../guardrails/network.js';
271
+ import type { DecisionGuardrailsSpec, HostGuardrailsSpec, ProfileGuardrailsSpec } from '../guardrails/types.js';
272
+ import type { ProfileObservabilitySpec } from '../observability/types.js';
273
+ import type { ToolCredentialSource } from './auth/credential-source.js';
274
+ import type { MediaTurnBehaviourSpec, ProfileTurnBehaviourSpec, TurnContinueFrom } from './stop.js';
275
+ export interface ProfileModelFields {
276
+ /** Host-named models. Each key is a selectable model id when `allowModelSelect` is set. */
277
+ models: Record<ModelId, ModelBinding>;
278
+ /** The model a turn runs when it names none; registration fills it with the only key when there is one. */
279
+ defaultModel: ModelId;
280
+ /** Turn may pass `{ model: "<id>" }`. Requires two or more `models` keys. */
281
+ allowModelSelect?: boolean;
282
+ /** Tool-loop ceiling. Omit or `<= 0` = unbounded; `1` = one-shot; `> 1` = hard cap. */
283
+ maxSteps?: number;
284
+ key?: KeySlot;
285
+ /** Retried once when `key` is refused for quota. Off unless set. */
286
+ fallbackKey?: KeySlot;
287
+ }
288
+ export interface ProfileInputsSpec {
289
+ text?: boolean;
290
+ attachments?: {
291
+ accept: string[];
292
+ };
293
+ voice?: {
294
+ accept: string[];
295
+ };
296
+ maxFiles?: number;
297
+ maxBytes?: number;
298
+ maxTurnBytes?: number;
299
+ limitsByMime?: Record<string, number>;
300
+ slots?: Record<string, string[]>;
301
+ }
302
+ export interface ProfileOutputsSpec {
303
+ structured?: StructuredSchemaId | StructuredBySlot | null;
304
+ validation?: ProfileValidationSpec;
305
+ streaming?: ProfileStreamingSpec;
306
+ }
307
+ /** Text a reply may not repeat when the rest of its prompt is marked shareable. */
308
+ export interface PrivateSystemPart {
309
+ private: string;
310
+ }
311
+ export type SystemPart = string | PrivateSystemPart;
312
+ /**
313
+ * A system prompt: a string, or parts sent concatenated as written. A string,
314
+ * or parts none of which is `{ private }`, is private throughout; once one
315
+ * part is `{ private }`, the plain strings beside it are shareable.
316
+ */
317
+ export type SystemPrompt = string | readonly SystemPart[];
318
+ /** A stretch of the system prompt as sent, and whether a reply may repeat it. */
319
+ export interface SystemPiece {
320
+ text: string;
321
+ private: boolean;
322
+ }
323
+ export interface ProfileIdentity {
324
+ handle: string;
325
+ system?: SystemPrompt;
326
+ systemByRole?: Record<string, SystemPrompt>;
327
+ }
328
+ export interface ProfileCommon {
329
+ id: ProfileId;
330
+ identity: ProfileIdentity;
331
+ models: Record<ModelId, ModelBinding>;
332
+ defaultModel: ModelId;
333
+ allowModelSelect?: boolean;
334
+ maxSteps?: number;
335
+ key?: KeySlot;
336
+ /** Retried once when `key` is refused for quota. Off unless set. */
337
+ fallbackKey?: KeySlot;
338
+ outputs?: ProfileOutputsSpec;
339
+ guardrails?: ProfileGuardrailsSpec;
340
+ observability?: ProfileObservabilitySpec;
341
+ /** This profile's wording: replaces any lexicon default, and any `overrideLexicon` entry, for this profile. */
342
+ lexicon?: LexiconOverrides;
343
+ }
344
+ export type DecisionJson = null | string | number | boolean | DecisionJson[] | {
345
+ [key: string]: DecisionJson;
346
+ };
347
+ /** A decision model binding follows the same protocol/provider/apiId spine as turn models. */
348
+ export interface DecisionModelBinding extends Pick<ModelBinding, 'apiId' | 'key'> {
349
+ protocol: 'decision';
350
+ provider: 'typesafe' | 'openrouter';
351
+ timeoutMs?: number;
352
+ }
353
+ export interface DecisionInputsSpec {
354
+ state: 'json';
355
+ maxStateBytes?: number;
356
+ }
357
+ /**
358
+ * A host-owned id for the decision a profile makes. The trace records it as
359
+ * `theorem.decision.contract`; it is not sent to the provider and does not constrain
360
+ * the questions a call asks.
361
+ */
362
+ export type DecisionContractId = string;
363
+ /** Decision profile. It cannot be passed to chat or live execution doors. */
364
+ export interface DecisionProfile {
365
+ type: 'decision';
366
+ id: ProfileId;
367
+ identity: Pick<ProfileIdentity, 'handle'>;
368
+ /** Exactly one model: a decision profile runs one model and never selects. */
369
+ models: Record<ModelId, DecisionModelBinding>;
370
+ key?: KeySlot;
371
+ inputs: DecisionInputsSpec;
372
+ decision: {
373
+ contract: DecisionContractId;
374
+ };
375
+ guardrails?: DecisionGuardrailsSpec;
376
+ observability?: ProfileObservabilitySpec;
377
+ /** This profile's wording: replaces any lexicon default, and any `overrideLexicon` entry, for this profile. */
378
+ lexicon?: LexiconOverrides;
379
+ }
380
+ /** Text or nested text instruction entries. Non-text leaves are rejected locally. */
381
+ export type DecisionEntry = string | DecisionEntry[] | {
382
+ [key: string]: DecisionEntry;
383
+ };
384
+ export interface DecisionChoiceQuestion {
385
+ type: 'choice';
386
+ instructions: DecisionEntry;
387
+ criteria: Record<string, DecisionEntry>;
388
+ }
389
+ export interface DecisionNoulQuestion {
390
+ type: 'noul';
391
+ instructions: DecisionEntry;
392
+ criteria?: Record<string, DecisionEntry>;
393
+ }
394
+ export interface DecisionScoreQuestion {
395
+ type: 'score';
396
+ instructions: DecisionEntry;
397
+ criteria: readonly DecisionEntry[];
398
+ }
399
+ export type DecisionQuestion = DecisionChoiceQuestion | DecisionNoulQuestion | DecisionScoreQuestion;
400
+ export interface DecisionRequest {
401
+ profile: ProfileId;
402
+ state: Exclude<DecisionJson, null>;
403
+ questions: Record<string, DecisionQuestion>;
404
+ signal?: AbortSignal;
405
+ /** Host-owned metadata preserved on the decision's trace record; the kernel does not interpret it. */
406
+ metadata?: Record<string, unknown>;
407
+ /**
408
+ * W3C `traceparent` of the host span this decision runs under. The `decide`
409
+ * root joins that trace as its child; without it the decision starts a new
410
+ * trace. A malformed value throws.
411
+ */
412
+ traceparent?: string;
413
+ }
414
+ export type DecisionAnswer = {
415
+ type: 'choice';
416
+ choice: string;
417
+ confidence: number;
418
+ probabilities: Record<string, number>;
419
+ } | {
420
+ type: 'noul';
421
+ noul: number;
422
+ } | {
423
+ type: 'score';
424
+ score: number;
425
+ confidence: number;
426
+ legend: Record<string, string>;
427
+ probabilities: Record<string, number>;
428
+ };
429
+ export interface DecisionResult {
430
+ model: string;
431
+ answers: Record<string, DecisionAnswer>;
432
+ /** Provider-reported tokens and cost, or a provider adapter's known model tariff. */
433
+ usage?: {
434
+ inputTokens: number;
435
+ outputTokens: number;
436
+ costUsd?: number;
437
+ };
438
+ }
439
+ export interface TextProfile extends ProfileCommon {
440
+ type: 'text';
441
+ tools: ProfileToolsSpec;
442
+ inputs: ProfileInputsSpec;
443
+ turnBehaviour?: ProfileTurnBehaviourSpec;
444
+ }
445
+ /**
446
+ * An image profile's inputs: no voice channel, and attachments within
447
+ * `IMAGE_ATTACHMENT_ACCEPT`. Every attachment is a reference the model reads;
448
+ * `maxFiles` caps them.
449
+ */
450
+ export type ImageInputsSpec = Omit<ProfileInputsSpec, 'voice'>;
451
+ export interface ImageProfile extends ProfileCommon {
452
+ type: 'image';
453
+ image: ProfileImageSpec;
454
+ tools: ProfileToolsSpec;
455
+ inputs: ImageInputsSpec;
456
+ turnBehaviour?: MediaTurnBehaviourSpec;
457
+ }
458
+ /**
459
+ * Speech guardrails: no canary. A speech turn has no system channel to bind a
460
+ * token into (Gemini TTS rejects developer instructions) and yields audio, not
461
+ * text a canary scan could read.
462
+ */
463
+ export type SpeechGuardrailsSpec = Omit<ProfileGuardrailsSpec, 'canary'> & {
464
+ canary?: false;
465
+ };
466
+ /** Unary TTS — text-in locked by type; no tools / inputs block. The input text is the transcript; there is no system prompt. */
467
+ export interface SpeechProfile extends Omit<ProfileCommon, 'identity' | 'guardrails'> {
468
+ type: 'speech';
469
+ identity: Pick<ProfileIdentity, 'handle'>;
470
+ /** Registration always stores `canary: false`. */
471
+ guardrails: SpeechGuardrailsSpec & {
472
+ canary: false;
473
+ };
474
+ speech: ProfileSpeechSpec;
475
+ turnBehaviour?: MediaTurnBehaviourSpec;
476
+ }
477
+ export interface LiveProfile extends Omit<ProfileCommon, 'outputs'> {
478
+ type: 'live';
479
+ live: ProfileLiveSpec;
480
+ tools: LiveProfileToolsSpec;
481
+ /** Stage inject gate only; live resumption is `live.sessionResumption`. */
482
+ turnBehaviour?: Pick<ProfileTurnBehaviourSpec, 'allowSteering'>;
483
+ }
484
+ /**
485
+ * Host-driven tool execution; never runs a model. `invokeTool` runs any tool in
486
+ * `tools.allow` with no visibility, loading tiers or path gating. `guardrails` holds only
487
+ * the guards that fire on `invokeTool`: quota, canary and egress guard a model turn, so
488
+ * `defineProfile` refuses them rather than accept inert config.
489
+ */
490
+ export interface HostProfile {
491
+ type: 'host';
492
+ id: ProfileId;
493
+ tools: HostProfileToolsSpec;
494
+ guardrails?: HostGuardrailsSpec;
495
+ observability?: ProfileObservabilitySpec;
496
+ /** This profile's wording: replaces any lexicon default, and any `overrideLexicon` entry, for this profile. */
497
+ lexicon?: LexiconOverrides;
498
+ }
499
+ export type Profile = TextProfile | ImageProfile | SpeechProfile | LiveProfile | DecisionProfile | HostProfile;
500
+ /** Profiles that run a model turn — every type except `host` and `decision` (which runs through `runDecision`). */
501
+ export type ModelProfile = Exclude<Profile, HostProfile | DecisionProfile>;
502
+ export interface ImageResponseFormat {
503
+ type: 'image';
504
+ mimeType?: string;
505
+ aspectRatio?: string;
506
+ /** Adapters map it to the provider wire key (Google `imageSize`, OpenRouter `resolution`). */
507
+ resolution?: string;
508
+ quality?: string;
509
+ background?: string;
510
+ n?: number;
511
+ seed?: number;
512
+ outputCompression?: number;
513
+ includeText: boolean;
514
+ }
515
+ export interface TurnBlob {
516
+ mimeType: string;
517
+ data: string;
518
+ /** The file's name, used only to tell the user which file was refused; never sent to the model. */
519
+ name?: string;
520
+ }
521
+ /**
522
+ * Media attachment supplied by reference (provider file uri) instead of bytes.
523
+ * MIME acceptance still applies; base64 and byte limits do not.
524
+ */
525
+ export interface TurnMediaRef {
526
+ mimeType: string;
527
+ uri: string;
528
+ /** The file's name, used only to tell the user which file was refused; never sent to the model. */
529
+ name?: string;
530
+ }
531
+ export interface TurnRepairRequest {
532
+ previousOutput: string;
533
+ rejection: string;
534
+ guidance?: string;
535
+ }
536
+ export interface TurnInput {
537
+ text?: string;
538
+ role?: string;
539
+ slots?: Record<string, string>;
540
+ attachments?: Array<TurnBlob | TurnMediaRef>;
541
+ voice?: TurnBlob[];
542
+ history?: TurnHistoryMessage[];
543
+ repair?: TurnRepairRequest;
544
+ /**
545
+ * Optional host-supplied history token count for `meter: 'history'`.
546
+ * When set, overrides the local history estimate. Not full-prompt API tokens.
547
+ */
548
+ historyTokens?: number;
549
+ /**
550
+ * Optional host-supplied full-prompt input token count for `meter: 'input'`
551
+ * with `timing: 'before'` (typically the previous turn's `tokens.input`).
552
+ * Ignored when `meter` is `'history'`.
553
+ */
554
+ inputTokens?: number;
555
+ sessionResumptionHandle?: string;
556
+ }
557
+ export type NormalizedTurnRequest = TurnRequest & {
558
+ input: TurnInput;
559
+ };
560
+ /**
561
+ * An earlier trace this one follows from. Recorded as a span link on the
562
+ * root, so a developer can walk a conversation across records.
563
+ */
564
+ export interface TurnTraceLink {
565
+ /** The earlier root's `traceparent` (its terminal `done.traceparent`). */
566
+ traceparent: string;
567
+ /** `resume` after a pause, `continue` after a resumeable stop, `retry` of a failed turn. */
568
+ kind: 'resume' | 'continue' | 'retry';
569
+ /** How the earlier turn stopped, when the host knows. */
570
+ stop?: TurnStopKind;
571
+ }
572
+ export interface TurnRequest {
573
+ profile: ProfileId;
574
+ projectId?: string;
575
+ /**
576
+ * Sticky routing / cache session key for OpenRouter (`session_id`).
577
+ * Not the same as `projectId` or Gemini `previousInteractionId`.
578
+ */
579
+ sessionId?: string;
580
+ /** Google Interactions server-side conversation state. Omit for stateless/manual history. */
581
+ previousInteractionId?: string;
582
+ /**
583
+ * Location bias for Interactions `google_maps` builtin.
584
+ * Wired as `tools: [{ type: "google_maps", latitude, longitude }]`.
585
+ * Ignored when `googleMaps` is not enabled for the selected model.
586
+ */
587
+ googleMapsLocation?: {
588
+ latitude: number;
589
+ longitude: number;
590
+ };
591
+ /** Optional Interactions storage override. Omit to let the selected model binding decide. */
592
+ store?: boolean;
593
+ /** Selected model id when `profile.allowModelSelect` is true. */
594
+ model?: ModelId;
595
+ /** Selected effort alias when the binding has `allowEffortSelect`. */
596
+ effort?: string;
597
+ /** Host-provided dynamic system prompt combined with profile persona */
598
+ system?: SystemPrompt;
599
+ sessionPermissions?: string[];
600
+ /** Host channel/path for catalog `paths` filtering. */
601
+ path?: string;
602
+ /** Host-owned metadata preserved for traces; the kernel does not interpret it. */
603
+ metadata?: Record<string, unknown>;
604
+ /**
605
+ * W3C `traceparent` of the host span this turn runs under. The turn's root
606
+ * span joins that trace as its child; without it the turn starts a new trace.
607
+ * A malformed value throws.
608
+ */
609
+ traceparent?: string;
610
+ /** Host conversation id, recorded as `gen_ai.conversation.id`. */
611
+ conversationId?: string;
612
+ links?: TurnTraceLink[];
613
+ /**
614
+ * Opaque application context handed to tool `handler` / `preTool` and
615
+ * `tools.t1Policy` as `ctx.host`. The kernel never reads, logs, traces, or
616
+ * serializes it.
617
+ */
618
+ host?: unknown;
619
+ /**
620
+ * Optional abort signal. When aborted, THEOREM stops the turn and cancels
621
+ * in-flight provider HTTP where the adapter supports it.
622
+ */
623
+ signal?: AbortSignal;
624
+ /**
625
+ * Continue a prior resumeable stop. On text profiles the turn's user message
626
+ * is the continue instruction (no `input.text`); the host passes the partial
627
+ * reply as the last assistant message in `input.history`. Image and speech
628
+ * re-send the original request unchanged.
629
+ */
630
+ continueFrom?: TurnContinueFrom;
631
+ /**
632
+ * 1-based continue attempt when `continueFrom` is set.
633
+ * Compared to `profile.turnBehaviour.resumption.maxContinues` when that cap is set.
634
+ */
635
+ continuation?: number;
636
+ input?: TurnInput;
637
+ /** Runs a `timing: 'before'` compactor the turn's provider cannot. */
638
+ compactionProvider?: ModelProvider;
639
+ sessionResumptionHandle?: string;
640
+ /** Credentials for authenticated HTTP / MCP tools, read by auth slot when a tool needs one. */
641
+ credentials?: ToolCredentialSource;
642
+ /**
643
+ * Resolves remote tool and OAuth host names before each request; a name that
644
+ * resolves to a private address is refused (see `fetchGuarded`).
645
+ */
646
+ resolveHost?: ResolveHost;
647
+ /** Text `runTurn` emits stages and applies the returned affordances. */
648
+ onStage?: StageHandler;
649
+ }
650
+ export interface ProjectedProfile extends ProfileModelFields {
651
+ id: string;
652
+ type: ModelProfile['type'];
653
+ handle: string;
654
+ tools: Array<RegisteredTool | {
655
+ name: ToolId;
656
+ missing: true;
657
+ }>;
658
+ inputs: ProfileInputsSpec | null;
659
+ outputs: ProfileOutputsSpec | null;
660
+ image?: ProfileImageSpec | null;
661
+ speech?: ProfileSpeechSpec | null;
662
+ live?: ProfileLiveSpec | null;
663
+ }
664
+ export interface ProviderGenerationConfig {
665
+ model: ModelId;
666
+ apiId: string;
667
+ previousInteractionId?: string;
668
+ store?: boolean;
669
+ /**
670
+ * Upstream stream vs batch, derived from `outputs.streaming.mode`.
671
+ * `true` = SSE (THEOREM default when mode is omitted); `false` = buffered.
672
+ */
673
+ stream?: boolean;
674
+ thinking?: ThinkingLevel;
675
+ summaries?: SummaryMode;
676
+ maxOutputTokens?: number;
677
+ temperature?: number;
678
+ builtins: BuiltinToolId[];
679
+ googleMapsLocation?: {
680
+ latitude: number;
681
+ longitude: number;
682
+ };
683
+ /** OpenRouter only. */
684
+ cache?: CacheSpec;
685
+ /** Forwarded as OpenRouter `session_id`. */
686
+ sessionId?: string;
687
+ }
688
+ export type ProviderTransport = 'interactions' | 'geminiLive' | 'openAiCompat';
689
+ export interface ResolvedGeneration extends ProviderGenerationConfig {
690
+ transport: ProviderTransport;
691
+ /**
692
+ * Whether the turn's steps chain on the stored interaction: a tool result or
693
+ * stage inject rides `continuation` after `previousInteractionId`. Only an
694
+ * Interactions binding chains, and never one with `persistViaInteractionId:
695
+ * false` — its steps each send the host's history plus the turn's steps so far.
696
+ */
697
+ chains: boolean;
698
+ tools: TurnToolSnapshot;
699
+ sessionPermissions?: string[];
700
+ history?: TurnHistoryMessage[];
701
+ /**
702
+ * Interactions-only: messages sent after `previousInteractionId` (tool
703
+ * results, stage injects) instead of history + user parts. The model reads
704
+ * the stored interaction plus these.
705
+ */
706
+ continuation?: TurnHistoryMessage[];
707
+ /** Tool-loop ceiling. `undefined` or `<= 0` = unbounded. */
708
+ maxSteps?: number;
709
+ structured: ResolvedStructured | null;
710
+ image: ImageResponseFormat | null;
711
+ speech?: ProfileSpeechSpec;
712
+ live?: ProfileLiveSpec;
713
+ input: InteractionPart[];
714
+ /**
715
+ * Vault key slot; every model but a local one without a key names one. Never sent on the wire.
716
+ */
717
+ keySlot?: KeySlot;
718
+ /** The slot a quota refusal on `keySlot` retries on once, when the profile names one. */
719
+ fallbackKeySlot?: KeySlot;
720
+ canary: string;
721
+ sessionResumptionHandle?: string;
722
+ /** Snapshotted synchronously before any async work; the runner binds the canary on top. */
723
+ resolvedSystem: readonly SystemPiece[];
724
+ /** `TurnRequest.host`, carried to tool contexts only. Never sent to providers or traces. */
725
+ host?: unknown;
726
+ }
727
+ /**
728
+ * `previousInteractionId`, `store`, `stream`, `summaries` and `continuation` are
729
+ * Google Interactions-only and absent otherwise. `keySlot` is required for every
730
+ * provider but local; it is never sent on the wire.
731
+ */
732
+ export interface ProviderCompleteRequest extends Omit<ProviderGenerationConfig, 'summaries' | 'builtins'> {
733
+ /** The turn's builtins with their wire names; adapters read no registry. */
734
+ builtins: ProviderBuiltin[];
735
+ summaries?: SummaryMode;
736
+ system: string;
737
+ input: InteractionPart[];
738
+ history?: TurnHistoryMessage[];
739
+ /** Sent after `previousInteractionId` instead of history + user parts; mapped like history. */
740
+ continuation?: TurnHistoryMessage[];
741
+ wireTools?: WireFunctionTool[];
742
+ structured: ResolvedStructured | null;
743
+ image: ImageResponseFormat | null;
744
+ speech?: ProfileSpeechSpec;
745
+ live?: ProfileLiveSpec;
746
+ sessionResumptionHandle?: string;
747
+ keySlot?: KeySlot;
748
+ /** The slot a quota refusal on `keySlot` retries on once. Never sent on the wire. */
749
+ fallbackKeySlot?: KeySlot;
750
+ /** Scrubbed SSE / HTTP rows for traces. */
751
+ tapUpstream?: (row: Record<string, unknown>) => void;
752
+ /** Host abort signal — adapters should pass this into fetch / SDK calls. */
753
+ signal?: AbortSignal;
754
+ }
755
+ export interface ModelProvider {
756
+ complete: (req: ProviderCompleteRequest) => AsyncIterable<ProviderEvent>;
757
+ }
758
+ /**
759
+ * Host request to open a long-lived live session (`runSession`).
760
+ * Profile must be `type: 'live'`.
761
+ */
762
+ export interface SessionRequest {
763
+ profile: ProfileId;
764
+ /** Host-built system prompt merged with profile identity.system. */
765
+ system?: SystemPrompt;
766
+ /** Override `profile.live.voice` for this session. */
767
+ voice?: string;
768
+ path?: string;
769
+ sessionPermissions?: string[];
770
+ history?: TurnHistoryMessage[];
771
+ sessionResumptionHandle?: string;
772
+ /** Optional realtime parts sent immediately after setup. */
773
+ input?: InteractionPart[];
774
+ /**
775
+ * Registry-resolved tool snapshot from the process that owns the tool registry
776
+ * (`prepareTurnToolSnapshot`). When set, session setup declares `snapshot.wire`
777
+ * instead of resolving tools locally, so a relay process without the registry
778
+ * can open the session. Every custom id must be within the profile's
779
+ * `tools.allow`; ids outside it are refused.
780
+ */
781
+ snapshot?: TurnToolSnapshot;
782
+ signal?: AbortSignal;
783
+ /** Host-owned metadata preserved on every record the session writes. */
784
+ metadata?: Record<string, unknown>;
785
+ /**
786
+ * W3C `traceparent` of the host span this session runs under. The session's
787
+ * root span joins that trace as its child; without it the session starts a
788
+ * new trace. A malformed value throws.
789
+ */
790
+ traceparent?: string;
791
+ /** Host conversation id, recorded as `gen_ai.conversation.id`. */
792
+ conversationId?: string;
793
+ links?: TurnTraceLink[];
794
+ /** Immutable for the session; there is no `setOnStage`. */
795
+ onStage?: StageHandler;
796
+ /**
797
+ * Default credentials for `executeTool` (per-call args override). Without one, the
798
+ * session keeps keys typed at its sign-in gates in memory.
799
+ */
800
+ credentials?: ToolCredentialSource;
801
+ /**
802
+ * Resolves remote tool and OAuth host names before each request; a name that
803
+ * resolves to a private address is refused (see `fetchGuarded`).
804
+ */
805
+ resolveHost?: ResolveHost;
806
+ /** Opaque host slot for stages / tool execute (per-call args override). */
807
+ host?: unknown;
808
+ }
809
+ /**
810
+ * Run a call the model made in this session, by its id: once, with the
811
+ * model's input. `decision` answers a call waiting on a gate, and only such a
812
+ * call; `input` is the user's edit, and only with `approve` on a gated call.
813
+ */
814
+ export type LiveExecuteToolArgs = {
815
+ callId: string;
816
+ decision?: GateDecision;
817
+ input?: unknown;
818
+ /**
819
+ * The key the user typed at a sign-in gate, only with `approve` on that
820
+ * gate: the session sets it as the credential for the gate's slot
821
+ * (`credentialFromTypedSecret`) in the source the call runs with.
822
+ */
823
+ secret?: string;
824
+ credentials?: ToolCredentialSource;
825
+ host?: unknown;
826
+ };
827
+ /**
828
+ * Settle a call the model made in this session whose body ran in the process
829
+ * that owns the tool registry: `events` are that process's `invokeTool`
830
+ * events for `callId`, which ran with the model's input.
831
+ */
832
+ export type LiveAnswerToolCallArgs = {
833
+ callId: string;
834
+ events: readonly TurnEvent[];
835
+ };
836
+ export type LiveExecuteToolResult = {
837
+ outputRaw?: unknown;
838
+ outputModel?: ModelToolResult;
839
+ failure?: ToolFailure;
840
+ awaiting?: boolean;
841
+ gated?: ToolGate;
842
+ };
843
+ /**
844
+ * Open Gemini Live session returned by `runSession`. It streams events until
845
+ * `close()` and exposes realtime media ingress and staged tool execution.
846
+ */
847
+ export interface LiveSession {
848
+ readonly profileId: ProfileId;
849
+ readonly canary: string;
850
+ events(): AsyncGenerator<TurnEvent, void, undefined>;
851
+ /** `mimeType` states the audio as sent (`audio/pcm;rate=16000`); the API rejects what it cannot take. */
852
+ sendAudio(args: {
853
+ data: string;
854
+ mimeType: string;
855
+ }): Promise<void>;
856
+ /** `mimeType` states the frame as sent (`image/jpeg`). */
857
+ sendVideo(args: {
858
+ data: string;
859
+ mimeType: string;
860
+ }): Promise<void>;
861
+ sendText(text: string): Promise<void>;
862
+ /**
863
+ * Text the model reads as background, not as the caller speaking: it opens no
864
+ * turn and draws no reply. Same `ingress.text` gate and inbound guardrails as
865
+ * `sendText`; the model sees it from its next turn on.
866
+ */
867
+ sendContext(text: string): Promise<void>;
868
+ /**
869
+ * Run a call the model made through the registry, with stages; its events
870
+ * join `events()`. A gate returns `gated` and answers the model nothing yet;
871
+ * the call waits `gateTtlMs` for its `decision`. An unknown, settled,
872
+ * running or expired call is a `request` error and runs nothing.
873
+ */
874
+ executeTool(args: LiveExecuteToolArgs): Promise<LiveExecuteToolResult>;
875
+ /**
876
+ * Settle a call whose body ran in the registry-owning process: its events
877
+ * join `events()` and the model reads its `readBack`. A run that ends on a
878
+ * gate leaves the call open; a released sign-in (`signInGate: 'answer'`)
879
+ * takes its outcome until `gateTtlMs`. An unknown, settled, running or
880
+ * expired call, or events that settle nothing for it, is a `request` error.
881
+ */
882
+ answerToolCall(args: LiveAnswerToolCallArgs): LiveExecuteToolResult;
883
+ close(reason?: string): Promise<void>;
884
+ }