theorum 0.1.15 → 1.1.3

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 (305) hide show
  1. package/README.md +241 -98
  2. package/esm/mod.d.ts +57 -28
  3. package/esm/mod.js +43 -23
  4. package/esm/src/cli/commands/bench.js +18 -18
  5. package/esm/src/cli/commands/fuzz-canary.d.ts +13 -0
  6. package/esm/src/cli/commands/fuzz-canary.js +191 -0
  7. package/esm/src/cli/commands/fuzz-guardrails.d.ts +3 -5
  8. package/esm/src/cli/commands/fuzz-guardrails.js +4 -581
  9. package/esm/src/cli/commands/guardrails-eval.d.ts +14 -0
  10. package/esm/src/cli/commands/guardrails-eval.js +15 -0
  11. package/esm/src/cli/commands/profile.js +35 -15
  12. package/esm/src/cli/commands/run.d.ts +3 -0
  13. package/esm/src/cli/commands/run.js +23 -32
  14. package/esm/src/cli/commands/test.d.ts +10 -1
  15. package/esm/src/cli/commands/test.js +34 -34
  16. package/esm/src/cli/event-log.d.ts +19 -0
  17. package/esm/src/cli/event-log.js +147 -0
  18. package/esm/src/cli/index.js +57 -11
  19. package/esm/src/cli/matrix/synthesizer.d.ts +10 -12
  20. package/esm/src/cli/matrix/synthesizer.js +45 -118
  21. package/esm/src/guardrails/canary-gate.d.ts +21 -0
  22. package/esm/src/guardrails/canary-gate.js +32 -0
  23. package/esm/src/guardrails/canary.d.ts +34 -0
  24. package/esm/src/guardrails/canary.js +150 -0
  25. package/esm/src/guardrails/corpus/canary-egress-attacks.d.ts +17 -0
  26. package/esm/src/guardrails/corpus/canary-egress-attacks.js +151 -0
  27. package/esm/src/guardrails/corpus/fuzz-inbound.d.ts +11 -0
  28. package/esm/src/guardrails/corpus/fuzz-inbound.js +213 -0
  29. package/esm/src/guardrails/corpus/inbound-payloads.d.ts +10 -0
  30. package/esm/src/guardrails/corpus/inbound-payloads.js +125 -0
  31. package/esm/src/guardrails/corpus/live-attacks.d.ts +20 -0
  32. package/esm/src/guardrails/corpus/live-attacks.js +231 -0
  33. package/esm/src/guardrails/corpus/mod.d.ts +14 -0
  34. package/esm/src/guardrails/corpus/mod.js +11 -0
  35. package/esm/src/guardrails/corpus/secrets.d.ts +17 -0
  36. package/esm/src/guardrails/corpus/secrets.js +17 -0
  37. package/esm/src/guardrails/corpus/strings.d.ts +28 -0
  38. package/esm/src/guardrails/corpus/strings.js +34 -0
  39. package/esm/src/guardrails/corpus/types.d.ts +38 -0
  40. package/esm/src/guardrails/corpus/types.js +6 -0
  41. package/esm/src/guardrails/egress.d.ts +32 -0
  42. package/esm/src/guardrails/egress.js +87 -0
  43. package/esm/src/guardrails/error.d.ts +14 -23
  44. package/esm/src/guardrails/error.js +87 -76
  45. package/esm/src/guardrails/eval/corpus.d.ts +108 -0
  46. package/esm/src/guardrails/eval/corpus.js +978 -0
  47. package/esm/src/guardrails/eval/mod.d.ts +51 -0
  48. package/esm/src/guardrails/eval/mod.js +133 -0
  49. package/esm/src/guardrails/eval/score.d.ts +66 -0
  50. package/esm/src/guardrails/eval/score.js +114 -0
  51. package/esm/src/guardrails/events.d.ts +25 -0
  52. package/esm/src/guardrails/events.js +56 -0
  53. package/esm/src/guardrails/hits.d.ts +24 -0
  54. package/esm/src/guardrails/hits.js +45 -0
  55. package/esm/src/guardrails/injection.js +28 -5
  56. package/esm/src/guardrails/lexicon.d.ts +39 -0
  57. package/esm/src/guardrails/lexicon.js +200 -0
  58. package/esm/src/guardrails/live-outbound-gate.d.ts +41 -0
  59. package/esm/src/guardrails/live-outbound-gate.js +222 -0
  60. package/esm/src/guardrails/mod.d.ts +30 -6
  61. package/esm/src/guardrails/mod.js +20 -5
  62. package/esm/src/guardrails/network.d.ts +19 -0
  63. package/esm/src/guardrails/network.js +234 -0
  64. package/esm/src/guardrails/policy.d.ts +35 -0
  65. package/esm/src/guardrails/policy.js +50 -0
  66. package/esm/src/guardrails/progressive-yield.d.ts +51 -0
  67. package/esm/src/guardrails/progressive-yield.js +98 -0
  68. package/esm/src/guardrails/quota.d.ts +17 -3
  69. package/esm/src/guardrails/quota.js +18 -4
  70. package/esm/src/guardrails/sanitize.d.ts +45 -19
  71. package/esm/src/guardrails/sanitize.js +177 -94
  72. package/esm/src/guardrails/sensitive.js +2 -1
  73. package/esm/src/guardrails/serialize.d.ts +35 -0
  74. package/esm/src/guardrails/serialize.js +58 -0
  75. package/esm/src/guardrails/testing.d.ts +17 -0
  76. package/esm/src/guardrails/testing.js +13 -0
  77. package/esm/src/guardrails/theorum-error.d.ts +12 -0
  78. package/esm/src/guardrails/theorum-error.js +15 -0
  79. package/esm/src/guardrails/tool-directives.d.ts +48 -0
  80. package/esm/src/guardrails/tool-directives.js +124 -0
  81. package/esm/src/guardrails/tool-result.d.ts +93 -0
  82. package/esm/src/guardrails/tool-result.js +276 -0
  83. package/esm/src/guardrails/types.d.ts +291 -0
  84. package/esm/src/guardrails/types.js +72 -0
  85. package/esm/src/host/client-turn.d.ts +19 -0
  86. package/esm/src/host/client-turn.js +36 -0
  87. package/esm/src/host/mint-trace.d.ts +1 -1
  88. package/esm/src/host/mod.d.ts +5 -3
  89. package/esm/src/host/mod.js +4 -3
  90. package/esm/src/kernel/auth/crypto.d.ts +42 -0
  91. package/esm/src/kernel/auth/crypto.js +106 -0
  92. package/esm/src/kernel/auth/mod.d.ts +11 -0
  93. package/esm/src/kernel/auth/mod.js +11 -0
  94. package/esm/src/kernel/auth/oauth.d.ts +47 -0
  95. package/esm/src/kernel/auth/oauth.js +278 -0
  96. package/esm/src/kernel/auth/types.d.ts +133 -0
  97. package/esm/src/kernel/auth/types.js +13 -0
  98. package/esm/src/kernel/engine/delta.d.ts +24 -2
  99. package/esm/src/kernel/engine/delta.js +478 -39
  100. package/esm/src/kernel/engine/live-inbound.d.ts +21 -0
  101. package/esm/src/kernel/engine/live-inbound.js +31 -0
  102. package/esm/src/kernel/engine/live-ingress.d.ts +19 -0
  103. package/esm/src/kernel/engine/live-ingress.js +47 -0
  104. package/esm/src/kernel/engine/repair.js +13 -12
  105. package/esm/src/kernel/engine/runner/gates.d.ts +1 -1
  106. package/esm/src/kernel/engine/runner/gates.js +130 -43
  107. package/esm/src/kernel/engine/runner/mod.d.ts +6 -4
  108. package/esm/src/kernel/engine/runner/mod.js +192 -53
  109. package/esm/src/kernel/engine/runner/schema-validation.js +3 -3
  110. package/esm/src/kernel/engine/runner/stages.d.ts +39 -0
  111. package/esm/src/kernel/engine/runner/stages.js +89 -0
  112. package/esm/src/kernel/engine/runner/state.d.ts +31 -0
  113. package/esm/src/kernel/engine/runner/steps.d.ts +1 -1
  114. package/esm/src/kernel/engine/runner/steps.js +244 -43
  115. package/esm/src/kernel/engine/runner/stream.d.ts +9 -3
  116. package/esm/src/kernel/engine/runner/stream.js +140 -44
  117. package/esm/src/kernel/engine/session/mod.d.ts +25 -0
  118. package/esm/src/kernel/engine/session/mod.js +557 -0
  119. package/esm/src/kernel/interaction-parts.d.ts +14 -0
  120. package/esm/src/kernel/interaction-parts.js +23 -0
  121. package/esm/src/kernel/mod.d.ts +21 -10
  122. package/esm/src/kernel/mod.js +11 -8
  123. package/esm/src/kernel/profile-graph.d.ts +159 -0
  124. package/esm/src/kernel/profile-graph.js +156 -0
  125. package/esm/src/kernel/registry/attachments.d.ts +12 -10
  126. package/esm/src/kernel/registry/attachments.js +33 -27
  127. package/esm/src/kernel/registry/catalog.d.ts +25 -24
  128. package/esm/src/kernel/registry/catalog.js +60 -101
  129. package/esm/src/kernel/registry/ingress.d.ts +9 -4
  130. package/esm/src/kernel/registry/ingress.js +97 -75
  131. package/esm/src/kernel/registry/profile-outputs.d.ts +4 -0
  132. package/esm/src/kernel/registry/profile-outputs.js +8 -0
  133. package/esm/src/kernel/registry/profiles.d.ts +55 -12
  134. package/esm/src/kernel/registry/profiles.js +413 -73
  135. package/esm/src/kernel/registry/provider-request.js +13 -7
  136. package/esm/src/kernel/registry/resolve.d.ts +8 -8
  137. package/esm/src/kernel/registry/resolve.js +169 -154
  138. package/esm/src/kernel/registry/schemas.js +1 -1
  139. package/esm/src/kernel/registry/sole-model.d.ts +8 -0
  140. package/esm/src/kernel/registry/sole-model.js +10 -0
  141. package/esm/src/kernel/registry/system-prompt.d.ts +10 -0
  142. package/esm/src/kernel/registry/system-prompt.js +40 -0
  143. package/esm/src/kernel/registry/system-role.d.ts +8 -0
  144. package/esm/src/kernel/registry/system-role.js +14 -0
  145. package/esm/src/kernel/registry/vault.d.ts +12 -7
  146. package/esm/src/kernel/registry/vault.js +32 -10
  147. package/esm/src/kernel/schema.d.ts +231 -0
  148. package/esm/src/kernel/schema.js +607 -0
  149. package/esm/src/kernel/stages.d.ts +175 -0
  150. package/esm/src/kernel/stages.js +476 -0
  151. package/esm/src/kernel/stop.d.ts +78 -19
  152. package/esm/src/kernel/stop.js +51 -16
  153. package/esm/src/kernel/tools/events.d.ts +41 -0
  154. package/esm/src/kernel/tools/events.js +71 -0
  155. package/esm/src/kernel/tools/execute.d.ts +84 -0
  156. package/esm/src/kernel/tools/execute.js +614 -0
  157. package/esm/src/kernel/tools/harness.d.ts +8 -0
  158. package/esm/src/kernel/tools/harness.js +46 -0
  159. package/esm/src/kernel/tools/invoke.d.ts +10 -0
  160. package/esm/src/kernel/tools/invoke.js +101 -0
  161. package/esm/src/kernel/tools/mod.d.ts +13 -0
  162. package/esm/src/kernel/tools/mod.js +11 -0
  163. package/esm/src/kernel/tools/permission.d.ts +15 -0
  164. package/esm/src/kernel/tools/permission.js +47 -0
  165. package/esm/src/kernel/tools/project.d.ts +12 -0
  166. package/esm/src/kernel/tools/project.js +36 -0
  167. package/esm/src/kernel/tools/registry.d.ts +23 -0
  168. package/esm/src/kernel/tools/registry.js +81 -0
  169. package/esm/src/kernel/tools/remote.d.ts +94 -0
  170. package/esm/src/kernel/tools/remote.js +577 -0
  171. package/esm/src/kernel/tools/resolve.d.ts +39 -0
  172. package/esm/src/kernel/tools/resolve.js +283 -0
  173. package/esm/src/kernel/tools/schema.d.ts +15 -0
  174. package/esm/src/kernel/tools/schema.js +176 -0
  175. package/esm/src/kernel/tools/stage-run.d.ts +105 -0
  176. package/esm/src/kernel/tools/stage-run.js +155 -0
  177. package/esm/src/kernel/tools/types.d.ts +394 -0
  178. package/esm/src/kernel/tools/types.js +9 -0
  179. package/esm/src/kernel/types.d.ts +540 -256
  180. package/esm/src/kernel/util/find-last.d.ts +2 -0
  181. package/esm/src/kernel/util/find-last.js +10 -0
  182. package/esm/src/observability/destinations.d.ts +31 -0
  183. package/esm/src/observability/destinations.js +67 -0
  184. package/esm/src/observability/mod.d.ts +10 -3
  185. package/esm/src/observability/mod.js +6 -2
  186. package/esm/src/observability/policy.d.ts +27 -0
  187. package/esm/src/observability/policy.js +80 -0
  188. package/esm/src/observability/resolve-policy.d.ts +16 -0
  189. package/esm/src/observability/resolve-policy.js +64 -0
  190. package/esm/src/observability/trace-attach.d.ts +8 -4
  191. package/esm/src/observability/trace-attach.js +50 -29
  192. package/esm/src/observability/trace-record.d.ts +23 -13
  193. package/esm/src/observability/trace-record.js +96 -39
  194. package/esm/src/observability/trace-sink.d.ts +19 -0
  195. package/esm/src/observability/trace-sink.js +10 -0
  196. package/esm/src/observability/trace-usage.d.ts +10 -3
  197. package/esm/src/observability/trace-usage.js +70 -17
  198. package/esm/src/observability/trace.d.ts +18 -7
  199. package/esm/src/observability/trace.js +34 -17
  200. package/esm/src/observability/types.d.ts +113 -0
  201. package/esm/src/observability/types.js +11 -0
  202. package/esm/src/presets/google/speech-voices.d.ts +11 -0
  203. package/esm/src/presets/google/speech-voices.js +41 -0
  204. package/esm/src/presets/google.d.ts +36 -24
  205. package/esm/src/presets/google.js +50 -63
  206. package/esm/src/presets/mod.d.ts +2 -2
  207. package/esm/src/presets/mod.js +1 -1
  208. package/esm/src/providers/create-provider.d.ts +20 -17
  209. package/esm/src/providers/create-provider.js +72 -26
  210. package/esm/src/providers/google/interactions/framing.d.ts +23 -0
  211. package/esm/src/providers/google/interactions/framing.js +269 -0
  212. package/esm/src/providers/google/interactions/mod.d.ts +7 -0
  213. package/esm/src/providers/google/interactions/mod.js +7 -0
  214. package/esm/src/providers/google/interactions/stream.d.ts +83 -0
  215. package/esm/src/providers/google/interactions/stream.js +588 -0
  216. package/esm/src/providers/google/keys.d.ts +26 -0
  217. package/esm/src/providers/{keys.js → google/keys.js} +19 -31
  218. package/esm/src/providers/google/live/framing.d.ts +49 -0
  219. package/esm/src/providers/google/live/framing.js +552 -0
  220. package/esm/src/providers/google/live/openapi-schema.d.ts +6 -0
  221. package/esm/src/providers/google/live/openapi-schema.js +46 -0
  222. package/esm/src/providers/google/live/session.d.ts +25 -0
  223. package/esm/src/providers/google/live/session.js +134 -0
  224. package/esm/src/providers/google/live/stream.d.ts +45 -0
  225. package/esm/src/providers/google/live/stream.js +214 -0
  226. package/esm/src/providers/google/urls.d.ts +6 -0
  227. package/esm/src/providers/google/urls.js +6 -0
  228. package/esm/src/providers/local/local.d.ts +30 -0
  229. package/esm/src/providers/{local.js → local/local.js} +66 -126
  230. package/esm/src/providers/local/mod.d.ts +9 -0
  231. package/esm/src/providers/local/mod.js +9 -0
  232. package/esm/src/providers/mod.d.ts +6 -3
  233. package/esm/src/providers/mod.js +3 -1
  234. package/esm/src/providers/openrouter/cache-control.d.ts +24 -0
  235. package/esm/src/providers/openrouter/cache-control.js +23 -0
  236. package/esm/src/providers/openrouter/chat.d.ts +107 -0
  237. package/esm/src/providers/{openrouter.js → openrouter/chat.js} +117 -231
  238. package/esm/src/providers/openrouter/image.d.ts +34 -0
  239. package/esm/src/providers/openrouter/image.js +275 -0
  240. package/esm/src/providers/openrouter/openai/chat-payload.d.ts +24 -0
  241. package/esm/src/providers/openrouter/openai/chat-payload.js +82 -0
  242. package/esm/src/providers/openrouter/openai/compat.d.ts +53 -0
  243. package/esm/src/providers/openrouter/openai/compat.js +213 -0
  244. package/esm/src/providers/openrouter/openai/image-payload.d.ts +18 -0
  245. package/esm/src/providers/openrouter/openai/image-payload.js +90 -0
  246. package/esm/src/providers/openrouter/openai/sdk-messages.d.ts +22 -0
  247. package/esm/src/providers/openrouter/openai/sdk-messages.js +122 -0
  248. package/esm/src/providers/openrouter/resolve-api-key.d.ts +9 -0
  249. package/esm/src/providers/openrouter/resolve-api-key.js +24 -0
  250. package/esm/src/providers/openrouter/speech.d.ts +23 -0
  251. package/esm/src/providers/{speech.js → openrouter/speech.js} +32 -55
  252. package/esm/src/providers/probe.d.ts +1 -0
  253. package/esm/src/providers/probe.js +22 -0
  254. package/esm/src/providers/shared/pcm.d.ts +12 -0
  255. package/esm/src/providers/{pcm.js → shared/pcm.js} +16 -3
  256. package/esm/src/providers/shared/sse.d.ts +18 -0
  257. package/esm/src/providers/shared/sse.js +87 -0
  258. package/esm/src/providers/shared/tool-args.d.ts +17 -0
  259. package/esm/src/providers/shared/tool-args.js +45 -0
  260. package/esm/src/providers/shared/upstream-tap.d.ts +5 -0
  261. package/esm/src/providers/{google-tap.js → shared/upstream-tap.js} +4 -7
  262. package/esm/src/providers/shared/upstream-tape.d.ts +6 -0
  263. package/esm/src/providers/{gemini-tape.js → shared/upstream-tape.js} +12 -22
  264. package/esm/src/providers/types.d.ts +27 -0
  265. package/esm/src/providers/types.js +1 -0
  266. package/package.json +11 -7
  267. package/docs/cli.md +0 -97
  268. package/docs/guardrails.md +0 -178
  269. package/docs/host.md +0 -97
  270. package/docs/kernel.md +0 -404
  271. package/docs/observability.md +0 -105
  272. package/docs/openrouter.md +0 -125
  273. package/docs/presets-google.md +0 -91
  274. package/docs/presets.md +0 -88
  275. package/docs/providers.md +0 -202
  276. package/docs/streaming.md +0 -96
  277. package/esm/src/kernel/engine/boundary.d.ts +0 -10
  278. package/esm/src/kernel/engine/boundary.js +0 -55
  279. package/esm/src/kernel/engine/runner/tools.d.ts +0 -13
  280. package/esm/src/kernel/engine/runner/tools.js +0 -198
  281. package/esm/src/kernel/registry/tools.d.ts +0 -12
  282. package/esm/src/kernel/registry/tools.js +0 -36
  283. package/esm/src/providers/expose-for-tests.d.ts +0 -1
  284. package/esm/src/providers/expose-for-tests.js +0 -25
  285. package/esm/src/providers/gemini-tape.d.ts +0 -2
  286. package/esm/src/providers/google-tap.d.ts +0 -3
  287. package/esm/src/providers/interactions.d.ts +0 -5
  288. package/esm/src/providers/interactions.js +0 -169
  289. package/esm/src/providers/keys.d.ts +0 -19
  290. package/esm/src/providers/local.d.ts +0 -29
  291. package/esm/src/providers/openrouter-mod.d.ts +0 -13
  292. package/esm/src/providers/openrouter-mod.js +0 -12
  293. package/esm/src/providers/openrouter-payload.d.ts +0 -39
  294. package/esm/src/providers/openrouter-payload.js +0 -195
  295. package/esm/src/providers/openrouter.d.ts +0 -15
  296. package/esm/src/providers/pcm.d.ts +0 -7
  297. package/esm/src/providers/provider.d.ts +0 -15
  298. package/esm/src/providers/provider.js +0 -202
  299. package/esm/src/providers/speech.d.ts +0 -23
  300. package/esm/src/providers/sse.d.ts +0 -7
  301. package/esm/src/providers/sse.js +0 -55
  302. package/esm/src/streaming/mod.d.ts +0 -9
  303. package/esm/src/streaming/mod.js +0 -8
  304. /package/esm/src/{streaming → host}/readStreamingJsonStringField.d.ts +0 -0
  305. /package/esm/src/{streaming → host}/readStreamingJsonStringField.js +0 -0
package/esm/mod.d.ts CHANGED
@@ -11,24 +11,31 @@
11
11
  *
12
12
  * const profile = defineProfile({
13
13
  * id: "assistant.basic",
14
- * model: {
15
- * allow: ["gemini35FlashLite"],
16
- * config: {
17
- * gemini35FlashLite: {
18
- * apiId: "gemini-3.5-flash-lite",
19
- * thinking: { on: "high", off: "minimal" },
20
- * thinkingLevels: ["minimal", "low", "medium", "high"],
21
- * summaries: { on: "auto", off: "none" },
22
- * maxOutputTokens: 8192,
23
- * temperature: 1,
24
- * keyBuiltins: [],
25
- * },
14
+ * type: "text",
15
+ * identity: {
16
+ * handle: "assistant",
17
+ * system: "Answer plainly.",
18
+ * },
19
+ * models: {
20
+ * default: {
21
+ * protocol: "openAi",
22
+ * provider: "openrouter",
23
+ * apiId: "perplexity/sonar",
24
+ * efforts: { normal: "minimal" },
25
+ * summaries: false,
26
+ * maxOutputTokens: 8192,
27
+ * temperature: 1,
26
28
  * },
27
29
  * },
30
+ * maxSteps: 1,
28
31
  * tools: { allow: [] },
29
32
  * inputs: { text: true },
30
- * outputs: {},
31
- * guardrails: { quota: { perDay: 100 } },
33
+ * outputs: {
34
+ * streaming: { streamThoughts: false },
35
+ * },
36
+ * guardrails: {
37
+ * quota: { perDay: 100 },
38
+ * },
32
39
  * });
33
40
  *
34
41
  * registerProfile(profile);
@@ -37,23 +44,45 @@
37
44
  * @module
38
45
  */
39
46
  import "./_dnt.polyfills.js";
40
- export { describeError, isAbortError, publicError, TheorumError, throwIfAborted, toErrorEvent, } from './src/guardrails/error.js';
41
- export type { QuotaSlotStatus } from './src/guardrails/quota.js';
42
- export { clientIp, quotaMessage, releaseSlot, resetSlots, skipQuota, takeSlot, } from './src/guardrails/quota.js';
43
- export { PROJECT_ID_MAX, sanitizeProjectId, sanitizeText, sanitizeTurnRequest, } from './src/guardrails/sanitize.js';
47
+ export { describeError, isAbortError, PUBLIC_CANARY, publicError, TheorumError, throwIfAborted, toErrorEvent, } from './src/guardrails/error.js';
48
+ export { guardrailFromHits, guardrailFromVerdict, guardrailTurnEvent, projectGuardrailTurnEvent, } from './src/guardrails/events.js';
49
+ export { GUARDRAIL_MATCH_PREVIEW_MAX, hitFromSpan, matchPreview, projectGuardrailEvent, } from './src/guardrails/hits.js';
50
+ export type { LexiconKey, LexiconOverrides, LexiconParams } from './src/guardrails/lexicon.js';
51
+ export { LEXICON_KEYS, lexiconDefault, lexiconText, overrideLexicon, resetLexicon, } from './src/guardrails/lexicon.js';
52
+ export type { AdvisoryLevel, CanaryGateResult, CanaryGateSession, CanaryGuardrailSpec, CanaryStreamGate, DetectionOptions, EgressEnforcer, EgressOnBlock, GuardedToolText, GuardrailAction, GuardrailContext, GuardrailEvent, GuardrailHit, GuardrailStage, HostGuardrailsSpec, LiveOutboundBatchResult, LiveOutboundGateSession, NetworkGuardrailSpec, OutboundPayload, ProfileEgressSpec, ProfileGuardrailsSpec, ProgressiveYieldGate, ProgressiveYieldGateOptions, ProgressiveYieldResult, Provenance, QuotaGuardrailSpec, ResolvedGuardrailPolicy, ScanText, Severity, TaintGate, TaintGuardrailSpec, ToolOrigin, TrustLevel, TurnTaint, Verdict, } from './src/guardrails/mod.js';
53
+ export { ADVISORY_LEVELS, bindCanary, checkTaintGate, collectEgressHits, composeToolText, createCanaryGateSession, createCanaryStreamGate, createLiveOutboundGateSession, createOutboundProgressiveGate, createProgressiveYieldGate, DEFAULT_HOLDBACK, DIRECTIVE_RULES, detectionForTrust, directiveHits, EGRESS_ON_BLOCK, EGRESS_RULES, eventHasCanary, filterCanaryGatedEvents, finalizeLiveOutboundTurn, GUARDRAIL_STAGES, guardToolFailureText, guardToolResult, hitRules, inspectToolArguments, isRemoteOrigin, isSuspicious, isTainted, looksDirective, mintCanary, OMIT_CANARY, processLiveOutboundBatch, recordTaint, redactCanary, resolveGuardrailPolicy, runEnforcer, SEVERITIES, scanTextForCanaryLeak, scanTextOf, standardEgressEnforce, TAINT_GATES, TOOL_CLOSE, TOOL_ORIGINS, TRUST_LEVELS, textForScan, toolCallEvent, wrapToolData, wrapUserData, } from './src/guardrails/mod.js';
54
+ export { assertSafeUrl, isLocalhostName, isPrivateOrLocalAddress, } from './src/guardrails/network.js';
55
+ export type { QuotaExhausted, QuotaSlotStatus } from './src/guardrails/quota.js';
56
+ export { clientIp, quotaExhausted, releaseSlot, resetSlots, skipQuota, takeSlot, } from './src/guardrails/quota.js';
57
+ export { detectionForProfile, detectText, PROJECT_ID_MAX, redactSensitiveOnly, sanitizeProjectId, sanitizeText, sanitizeTurnRequest, sanitizeTurnRequestForTrace, sanitizeTurnRequestWithEvents, } from './src/guardrails/sanitize.js';
44
58
  export type { CompactionSplit, CompactionTokens } from './src/kernel/engine/compaction.js';
45
59
  export { compactionMeter, compactionNeeded, estimateHistoryTokens, HISTORY_MEDIA_TOKENS, HISTORY_TEXT_ENCODING, resolveCompactionTokens, resolveHistoryTokens, shouldCompact, splitForCompaction, } from './src/kernel/engine/compaction.js';
60
+ export { prepareLiveInboundText } from './src/kernel/engine/live-inbound.js';
61
+ export type { LiveIngressChannel } from './src/kernel/engine/live-ingress.js';
62
+ export { assertLiveIngress, assertLiveIngressConfigured, hasAnyLiveIngress, liveIngressChannelDefault, liveIngressEnabled, liveIngressEnabledFromSpec, } from './src/kernel/engine/live-ingress.js';
46
63
  export { runTurn } from './src/kernel/engine/runner.js';
47
- export { CATALOG, clampThinkingLevel, clampThinkingLevelForApiId, getTool, listBuiltinIds, mediaKindForMime, mimeAllowed, mimeEssence, modelEntryByApiId, registerTools, requireModelSpec, resetTools, } from './src/kernel/registry/catalog.js';
48
- export type { ProfileDefinition } from './src/kernel/registry/profiles.js';
64
+ export type { RunSessionOptions } from './src/kernel/engine/session/mod.js';
65
+ export { runSession } from './src/kernel/engine/session/mod.js';
66
+ export type { ProfileGraphEditor, ProfileGraphFacet, ProfileGraphFacetId, ProfileGraphRole, } from './src/kernel/profile-graph.js';
67
+ export { PROFILE_GRAPH, profileGraphFacet, spineFacetsForProfileType, } from './src/kernel/profile-graph.js';
68
+ export { assertAttachmentLimits, maxBytesForMime, requireMediaLimits, resolveMediaLimits, sanitizeCsvText, sanitizeTurnBlobs, sanitizeTurnBlobsForProfile, } from './src/kernel/registry/attachments.js';
69
+ export type { MediaInputChannel } from './src/kernel/registry/catalog.js';
70
+ export { clampThinkingLevel, clampThinkingLevelForApiId, mediaChannelForMime, mediaKindForMime, mimeAllowed, mimeEssence, modelEntryByApiId, requireModelBinding, } from './src/kernel/registry/catalog.js';
71
+ export type { ImageProfileDefinition, LiveProfileDefinition, ProfileDefinition, ProfileDefinitionBase, SpeechProfileDefinition, TextProfileDefinition, } from './src/kernel/registry/profiles.js';
49
72
  export { clearProfiles, defineProfile, getProfile, hasProfile, listProfiles, registerProfile, registerProfiles, } from './src/kernel/registry/profiles.js';
50
- export { projectProfile, resolveTurn } from './src/kernel/registry/resolve.js';
73
+ export { pickModel, projectProfile, resolveTurn } from './src/kernel/registry/resolve.js';
51
74
  export { getStructured, registerStructured } from './src/kernel/registry/schemas.js';
52
- export { executeTool } from './src/kernel/registry/tools.js';
53
- export type { ProfileResumeSpec, TurnContinueFrom, TurnStop, TurnStopKind, } from './src/kernel/stop.js';
54
- export { AUTO_CONTINUE_DELAY_MS, CONTINUE_INSTRUCTION, DEFAULT_AUTO_CONTINUE, GenerationStopError, isGenerationStopError, isResumeableStop, isUserCancelledStop, shouldAutoContinue, turnStopFromClientStreamEnd, turnStopFromInteractionStatus, turnStopFromOpenRouter, } from './src/kernel/stop.js';
75
+ export type { AuthUnauthenticatedPolicy, ContinueStopKind, CustomToolType, HttpMethod, PlaygroundAuthType, ToolAccess, ToolAuthType, ToolPermission, ToolType, TurnStopKind, } from './src/kernel/schema.js';
76
+ export { ATTACHMENT_ACCEPT_MIMES, AUTH_UNAUTHENTICATED_POLICIES, AWAITING_USER_INPUT_KINDS, AWAITING_USER_INPUT_STATUS, COMPACTION_METERS, COMPACTION_TIMINGS, CONTINUE_STOP_KINDS, catalogPathFor, coerceProtocol, coerceProvider, coerceSpeechFormat, DYNAMIC_FIELD_PARENTS, EXTRA_FIELDS, fieldMeta, HTTP_METHODS, isSpeechFormatAllowedForProtocol, isToolGateKind, isTurnInjectStage, isTurnStage, isValidPair, isValidProfileProtocol, KEY_SLOTS, LIVE_ACTIVITY_HANDLINGS, LIVE_CONTEXT_COMPRESSIONS, LIVE_SPEECH_SENSITIVITIES, MEDIA_INPUT_KIND_VALUES, MEDIA_INPUT_KINDS, MEDIA_WILDCARDS, OVERFLOW_KEY_SLOTS, PLAYGROUND_AUTH_TYPES, PROFILE_FIELDS, PROFILE_TYPE_PROTOCOLS, PROFILE_TYPES, PROTOCOL_PROVIDERS, PROTOCOLS, PROVIDERS, protocolsFor, protocolsForProfileType, providersFor, SCHEMA_ENFORCEMENTS, SPEECH_AUDIO_FORMATS, STREAM_MODES, SUMMARY_MODES, speechFormatsForProtocol, THINKING_LEVELS, TOOL_ACCESS, TOOL_AUTH_TYPES, TOOL_GATE_KINDS, TOOL_LOAD_TIERS, TOOL_PERMISSION, TOOL_TYPES, TURN_INJECT_STAGES, TURN_STAGES, TURN_STOP_KINDS, VOICE_ACCEPT_MIMES, } from './src/kernel/schema.js';
77
+ export type { AwaitingUserInput, StageAffordance, StageApplyInput, StageApplyOutput, StageApplyWarning, StageApplyWarningCode, StageContext, StageEventExtra, StageHandler, StageMutate, StageResult, } from './src/kernel/stages.js';
78
+ export { applyStageResult, isAwaitingUserInput, parseAwaitingUserInput, parseToolGate, STAGE_AFFORDANCE_MATRIX, STAGE_AFFORDANCES, stageAllowsAffordance, stageEventFields, } from './src/kernel/stages.js';
79
+ export type { ProfileTurnBehaviourSpec, ProfileTurnResumptionSpec, TurnContinueFrom, TurnStop, } from './src/kernel/stop.js';
80
+ export { AUTO_CONTINUE_DELAY_MS, CONTINUE_INSTRUCTION, DEFAULT_ALLOW_CONTINUE, DEFAULT_AUTO_CONTINUE, GenerationStopError, isContinueStopKind, isGenerationStopError, isResumeableStop, isUserCancelledStop, profileAllowsInject, profileAllowsSteering, profileTurnResumption, shouldAutoContinue, turnStopFromClientStreamEnd, turnStopFromInteractionStatus, turnStopFromOpenAiFinishReason, } from './src/kernel/stop.js';
81
+ export type { McpProtocolVersion, McpRpcResponse } from './src/kernel/tools/mod.js';
82
+ export { buildHttpToolTarget, executeHttpTool, executeMcpTool, formatToolResult, getTool, hasTool, invokeTool, isUnsupportedMcpProtocolError, listBuiltinIds, listFunctionIds, listTools, MCP_PROTOCOL_VERSIONS, parseMcpRpcResponse, prepareTurnToolSnapshot, registerHarnessTools, registerTool, registerTools, requireTool, resetTools, resolveToolAuth, } from './src/kernel/tools/mod.js';
55
83
  export type * from './src/kernel/types.js';
56
- export { jsonlSink, memorySink, noopSink, resolveTraceDir, sinkFromDir, writeTrace, } from './src/observability/trace.js';
57
- export type { TraceRecord } from './src/observability/trace-record.js';
58
- export type { CreateProviderOptions, GeminiTransport, GeminiVault, LocalProviderConfig, } from './src/providers/mod.js';
59
- export { createLocalProvider, createProvider, DEFAULT_LOCAL_BASE_URL, } from './src/providers/mod.js';
84
+ export type { JsonlSinkOptions, JsonlTraceDestination, ProfileObservabilitySpec, ResolvedObservabilityPolicy, ResolvedTraceInclude, ResolvedTraceScrub, TraceDestination, TraceIncludeSpec, TraceRecord, TraceScrubSpec, TraceSink, } from './src/observability/mod.js';
85
+ export { clearTraceDestinations, getTraceDestination, isJsonlTraceDestination, isTraceSink, jsonlDestination, jsonlSink, listTraceDestinationIds, memorySink, noopSink, registerTraceDestination, requireTraceDestination, resolveObservabilityPolicy, resolveTraceDir, resolveTraceWriter, sinkFromDir, writeTrace, } from './src/observability/mod.js';
86
+ export * from './src/presets/mod.js';
87
+ export type { CreateProviderOptions, GeminiTransport, KeyVault, LocalProviderConfig, OpenAiGatewayConfig, } from './src/providers/mod.js';
88
+ export { createProvider } from './src/providers/mod.js';
package/esm/mod.js CHANGED
@@ -11,24 +11,31 @@
11
11
  *
12
12
  * const profile = defineProfile({
13
13
  * id: "assistant.basic",
14
- * model: {
15
- * allow: ["gemini35FlashLite"],
16
- * config: {
17
- * gemini35FlashLite: {
18
- * apiId: "gemini-3.5-flash-lite",
19
- * thinking: { on: "high", off: "minimal" },
20
- * thinkingLevels: ["minimal", "low", "medium", "high"],
21
- * summaries: { on: "auto", off: "none" },
22
- * maxOutputTokens: 8192,
23
- * temperature: 1,
24
- * keyBuiltins: [],
25
- * },
14
+ * type: "text",
15
+ * identity: {
16
+ * handle: "assistant",
17
+ * system: "Answer plainly.",
18
+ * },
19
+ * models: {
20
+ * default: {
21
+ * protocol: "openAi",
22
+ * provider: "openrouter",
23
+ * apiId: "perplexity/sonar",
24
+ * efforts: { normal: "minimal" },
25
+ * summaries: false,
26
+ * maxOutputTokens: 8192,
27
+ * temperature: 1,
26
28
  * },
27
29
  * },
30
+ * maxSteps: 1,
28
31
  * tools: { allow: [] },
29
32
  * inputs: { text: true },
30
- * outputs: {},
31
- * guardrails: { quota: { perDay: 100 } },
33
+ * outputs: {
34
+ * streaming: { streamThoughts: false },
35
+ * },
36
+ * guardrails: {
37
+ * quota: { perDay: 100 },
38
+ * },
32
39
  * });
33
40
  *
34
41
  * registerProfile(profile);
@@ -37,16 +44,29 @@
37
44
  * @module
38
45
  */
39
46
  import "./_dnt.polyfills.js";
40
- export { describeError, isAbortError, publicError, TheorumError, throwIfAborted, toErrorEvent, } from './src/guardrails/error.js';
41
- export { clientIp, quotaMessage, releaseSlot, resetSlots, skipQuota, takeSlot, } from './src/guardrails/quota.js';
42
- export { PROJECT_ID_MAX, sanitizeProjectId, sanitizeText, sanitizeTurnRequest, } from './src/guardrails/sanitize.js';
47
+ export { describeError, isAbortError, PUBLIC_CANARY, publicError, TheorumError, throwIfAborted, toErrorEvent, } from './src/guardrails/error.js';
48
+ export { guardrailFromHits, guardrailFromVerdict, guardrailTurnEvent, projectGuardrailTurnEvent, } from './src/guardrails/events.js';
49
+ export { GUARDRAIL_MATCH_PREVIEW_MAX, hitFromSpan, matchPreview, projectGuardrailEvent, } from './src/guardrails/hits.js';
50
+ export { LEXICON_KEYS, lexiconDefault, lexiconText, overrideLexicon, resetLexicon, } from './src/guardrails/lexicon.js';
51
+ export { ADVISORY_LEVELS, bindCanary, checkTaintGate, collectEgressHits, composeToolText, createCanaryGateSession, createCanaryStreamGate, createLiveOutboundGateSession, createOutboundProgressiveGate, createProgressiveYieldGate, DEFAULT_HOLDBACK, DIRECTIVE_RULES, detectionForTrust, directiveHits, EGRESS_ON_BLOCK, EGRESS_RULES, eventHasCanary, filterCanaryGatedEvents, finalizeLiveOutboundTurn, GUARDRAIL_STAGES, guardToolFailureText, guardToolResult, hitRules, inspectToolArguments, isRemoteOrigin, isSuspicious, isTainted, looksDirective, mintCanary, OMIT_CANARY, processLiveOutboundBatch, recordTaint, redactCanary, resolveGuardrailPolicy, runEnforcer, SEVERITIES, scanTextForCanaryLeak, scanTextOf, standardEgressEnforce, TAINT_GATES, TOOL_CLOSE, TOOL_ORIGINS, TRUST_LEVELS, textForScan, toolCallEvent, wrapToolData, wrapUserData, } from './src/guardrails/mod.js';
52
+ export { assertSafeUrl, isLocalhostName, isPrivateOrLocalAddress, } from './src/guardrails/network.js';
53
+ export { clientIp, quotaExhausted, releaseSlot, resetSlots, skipQuota, takeSlot, } from './src/guardrails/quota.js';
54
+ export { detectionForProfile, detectText, PROJECT_ID_MAX, redactSensitiveOnly, sanitizeProjectId, sanitizeText, sanitizeTurnRequest, sanitizeTurnRequestForTrace, sanitizeTurnRequestWithEvents, } from './src/guardrails/sanitize.js';
43
55
  export { compactionMeter, compactionNeeded, estimateHistoryTokens, HISTORY_MEDIA_TOKENS, HISTORY_TEXT_ENCODING, resolveCompactionTokens, resolveHistoryTokens, shouldCompact, splitForCompaction, } from './src/kernel/engine/compaction.js';
56
+ export { prepareLiveInboundText } from './src/kernel/engine/live-inbound.js';
57
+ export { assertLiveIngress, assertLiveIngressConfigured, hasAnyLiveIngress, liveIngressChannelDefault, liveIngressEnabled, liveIngressEnabledFromSpec, } from './src/kernel/engine/live-ingress.js';
44
58
  export { runTurn } from './src/kernel/engine/runner.js';
45
- export { CATALOG, clampThinkingLevel, clampThinkingLevelForApiId, getTool, listBuiltinIds, mediaKindForMime, mimeAllowed, mimeEssence, modelEntryByApiId, registerTools, requireModelSpec, resetTools, } from './src/kernel/registry/catalog.js';
59
+ export { runSession } from './src/kernel/engine/session/mod.js';
60
+ export { PROFILE_GRAPH, profileGraphFacet, spineFacetsForProfileType, } from './src/kernel/profile-graph.js';
61
+ export { assertAttachmentLimits, maxBytesForMime, requireMediaLimits, resolveMediaLimits, sanitizeCsvText, sanitizeTurnBlobs, sanitizeTurnBlobsForProfile, } from './src/kernel/registry/attachments.js';
62
+ export { clampThinkingLevel, clampThinkingLevelForApiId, mediaChannelForMime, mediaKindForMime, mimeAllowed, mimeEssence, modelEntryByApiId, requireModelBinding, } from './src/kernel/registry/catalog.js';
46
63
  export { clearProfiles, defineProfile, getProfile, hasProfile, listProfiles, registerProfile, registerProfiles, } from './src/kernel/registry/profiles.js';
47
- export { projectProfile, resolveTurn } from './src/kernel/registry/resolve.js';
64
+ export { pickModel, projectProfile, resolveTurn } from './src/kernel/registry/resolve.js';
48
65
  export { getStructured, registerStructured } from './src/kernel/registry/schemas.js';
49
- export { executeTool } from './src/kernel/registry/tools.js';
50
- export { AUTO_CONTINUE_DELAY_MS, CONTINUE_INSTRUCTION, DEFAULT_AUTO_CONTINUE, GenerationStopError, isGenerationStopError, isResumeableStop, isUserCancelledStop, shouldAutoContinue, turnStopFromClientStreamEnd, turnStopFromInteractionStatus, turnStopFromOpenRouter, } from './src/kernel/stop.js';
51
- export { jsonlSink, memorySink, noopSink, resolveTraceDir, sinkFromDir, writeTrace, } from './src/observability/trace.js';
52
- export { createLocalProvider, createProvider, DEFAULT_LOCAL_BASE_URL, } from './src/providers/mod.js';
66
+ export { ATTACHMENT_ACCEPT_MIMES, AUTH_UNAUTHENTICATED_POLICIES, AWAITING_USER_INPUT_KINDS, AWAITING_USER_INPUT_STATUS, COMPACTION_METERS, COMPACTION_TIMINGS, CONTINUE_STOP_KINDS, catalogPathFor, coerceProtocol, coerceProvider, coerceSpeechFormat, DYNAMIC_FIELD_PARENTS, EXTRA_FIELDS, fieldMeta, HTTP_METHODS, isSpeechFormatAllowedForProtocol, isToolGateKind, isTurnInjectStage, isTurnStage, isValidPair, isValidProfileProtocol, KEY_SLOTS, LIVE_ACTIVITY_HANDLINGS, LIVE_CONTEXT_COMPRESSIONS, LIVE_SPEECH_SENSITIVITIES, MEDIA_INPUT_KIND_VALUES, MEDIA_INPUT_KINDS, MEDIA_WILDCARDS, OVERFLOW_KEY_SLOTS, PLAYGROUND_AUTH_TYPES, PROFILE_FIELDS, PROFILE_TYPE_PROTOCOLS, PROFILE_TYPES, PROTOCOL_PROVIDERS, PROTOCOLS, PROVIDERS, protocolsFor, protocolsForProfileType, providersFor, SCHEMA_ENFORCEMENTS, SPEECH_AUDIO_FORMATS, STREAM_MODES, SUMMARY_MODES, speechFormatsForProtocol, THINKING_LEVELS, TOOL_ACCESS, TOOL_AUTH_TYPES, TOOL_GATE_KINDS, TOOL_LOAD_TIERS, TOOL_PERMISSION, TOOL_TYPES, TURN_INJECT_STAGES, TURN_STAGES, TURN_STOP_KINDS, VOICE_ACCEPT_MIMES, } from './src/kernel/schema.js';
67
+ export { applyStageResult, isAwaitingUserInput, parseAwaitingUserInput, parseToolGate, STAGE_AFFORDANCE_MATRIX, STAGE_AFFORDANCES, stageAllowsAffordance, stageEventFields, } from './src/kernel/stages.js';
68
+ export { AUTO_CONTINUE_DELAY_MS, CONTINUE_INSTRUCTION, DEFAULT_ALLOW_CONTINUE, DEFAULT_AUTO_CONTINUE, GenerationStopError, isContinueStopKind, isGenerationStopError, isResumeableStop, isUserCancelledStop, profileAllowsInject, profileAllowsSteering, profileTurnResumption, shouldAutoContinue, turnStopFromClientStreamEnd, turnStopFromInteractionStatus, turnStopFromOpenAiFinishReason, } from './src/kernel/stop.js';
69
+ export { buildHttpToolTarget, executeHttpTool, executeMcpTool, formatToolResult, getTool, hasTool, invokeTool, isUnsupportedMcpProtocolError, listBuiltinIds, listFunctionIds, listTools, MCP_PROTOCOL_VERSIONS, parseMcpRpcResponse, prepareTurnToolSnapshot, registerHarnessTools, registerTool, registerTools, requireTool, resetTools, resolveToolAuth, } from './src/kernel/tools/mod.js';
70
+ export { clearTraceDestinations, getTraceDestination, isJsonlTraceDestination, isTraceSink, jsonlDestination, jsonlSink, listTraceDestinationIds, memorySink, noopSink, registerTraceDestination, requireTraceDestination, resolveObservabilityPolicy, resolveTraceDir, resolveTraceWriter, sinkFromDir, writeTrace, } from './src/observability/mod.js';
71
+ export * from './src/presets/mod.js';
72
+ export { createProvider } from './src/providers/mod.js';
@@ -12,11 +12,12 @@
12
12
  *
13
13
  * @module
14
14
  */
15
+ import { bindCanary, eventHasCanary, mintCanary } from '../../guardrails/canary.js';
15
16
  import { sanitizeTurnRequest } from '../../guardrails/sanitize.js';
16
- import { bindCanary, eventHasCanary, mintCanary } from '../../kernel/engine/boundary.js';
17
17
  import { runTurn } from '../../kernel/engine/runner.js';
18
18
  import { clearProfiles, registerProfile } from '../../kernel/registry/profiles.js';
19
- import { pickSystemRole, resolveTurn } from '../../kernel/registry/resolve.js';
19
+ import { resolveTurn } from '../../kernel/registry/resolve.js';
20
+ import { pickSystemRole } from '../../kernel/registry/system-role.js';
20
21
  import { buildRecord } from '../../observability/trace-record.js';
21
22
  const DEFAULT_CHUNKS = 200;
22
23
  const DEFAULT_ITERATIONS = 50;
@@ -25,28 +26,27 @@ const MS_PER_SEC = 1000;
25
26
  const BENCH_PROFILE_ID = '__bench__';
26
27
  function registerBenchProfile() {
27
28
  registerProfile({
29
+ type: 'text',
28
30
  id: BENCH_PROFILE_ID,
29
31
  identity: {
30
32
  handle: 'bench',
31
33
  system: 'You are a benchmark stub.',
32
34
  },
33
- model: {
34
- protocol: 'openAi',
35
- provider: 'openrouter',
36
- allow: ['bench-model'],
37
- config: {
38
- 'bench-model': {
39
- apiId: 'bench-model',
40
- thinking: { on: 'none', off: 'none' },
41
- thinkingLevels: ['none'],
42
- summaries: { on: 'none', off: 'none' },
43
- maxOutputTokens: 4096,
44
- temperature: 0,
45
- keyBuiltins: [],
46
- },
35
+ models: {
36
+ 'bench-model': {
37
+ protocol: 'openAi',
38
+ provider: 'openrouter',
39
+ apiId: 'bench-model',
40
+ efforts: { normal: 'none' },
41
+ summaries: false,
42
+ maxOutputTokens: 4096,
43
+ temperature: 0,
44
+ builtInTools: [],
47
45
  },
48
- thinking: 'none',
49
46
  },
47
+ defaultModel: 'bench-model',
48
+ tools: { allow: [] },
49
+ inputs: { text: true },
50
50
  guardrails: {
51
51
  canary: true,
52
52
  sanitizeInput: true,
@@ -94,7 +94,7 @@ async function measureRawProvider(provider) {
94
94
  model: 'bench-model',
95
95
  apiId: 'bench-model',
96
96
  thinking: 'none',
97
- summaries: 'none',
97
+ summaries: undefined,
98
98
  maxOutputTokens: 4096,
99
99
  temperature: 0,
100
100
  builtins: [],
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Adversarial canary egress fuzzer.
3
+ *
4
+ * Pipes synthetic model leak attempts through the real runTurn stream gate
5
+ * and Live batch gate, then reports bypasses — output that still contains
6
+ * the raw per-turn canary token where the gate should have blocked.
7
+ *
8
+ * @module
9
+ */
10
+ /** Run adversarial canary fuzz; returns true when no bypasses or false alarms. */
11
+ export declare function fuzzCanaryCommand(options?: {
12
+ canary?: string;
13
+ }): Promise<boolean>;
@@ -0,0 +1,191 @@
1
+ /**
2
+ * Adversarial canary egress fuzzer.
3
+ *
4
+ * Pipes synthetic model leak attempts through the real runTurn stream gate
5
+ * and Live batch gate, then reports bypasses — output that still contains
6
+ * the raw per-turn canary token where the gate should have blocked.
7
+ *
8
+ * @module
9
+ */
10
+ import { bindCanary, mintCanary, scanTextForCanaryLeak } from '../../guardrails/canary.js';
11
+ import { buildCanaryEgressAttacks, FIXED_CANARY, } from '../../guardrails/corpus/canary-egress-attacks.js';
12
+ import { createLiveOutboundGateSession, finalizeLiveOutboundTurn, processLiveOutboundBatch, } from '../../guardrails/live-outbound-gate.js';
13
+ import { yieldProviderEvents } from '../../kernel/engine/runner/stream.js';
14
+ import { clearProfiles, getProfile, registerProfile } from '../../kernel/registry/profiles.js';
15
+ import { resolveTurn } from '../../kernel/registry/resolve.js';
16
+ const FUZZ_PROFILE_ID = '__fuzz_canary__';
17
+ function registerFuzzCanaryProfile() {
18
+ registerProfile({
19
+ type: 'text',
20
+ id: FUZZ_PROFILE_ID,
21
+ identity: { handle: 'fuzz-canary', system: 'Canary fuzz profile.' },
22
+ models: {
23
+ 'fuzz-model': {
24
+ protocol: 'openAi',
25
+ provider: 'openrouter',
26
+ apiId: 'fuzz-model',
27
+ efforts: { normal: 'none' },
28
+ summaries: false,
29
+ maxOutputTokens: 4096,
30
+ temperature: 0,
31
+ builtInTools: [],
32
+ },
33
+ },
34
+ defaultModel: 'fuzz-model',
35
+ tools: { allow: [] },
36
+ inputs: { text: true },
37
+ guardrails: { canary: true },
38
+ });
39
+ }
40
+ function resolveFuzzGeneration(canary) {
41
+ const { generation } = resolveTurn({
42
+ profile: FUZZ_PROFILE_ID,
43
+ input: { text: 'fuzz' },
44
+ });
45
+ return { ...generation, canary };
46
+ }
47
+ async function collectEvents(gen) {
48
+ const out = [];
49
+ for await (const event of gen) {
50
+ out.push(event);
51
+ }
52
+ return out;
53
+ }
54
+ function clientVisibleWire(events) {
55
+ return JSON.stringify(events.filter((event) => event.type !== 'error'));
56
+ }
57
+ function literalCanaryReachedClient(events, canary) {
58
+ return clientVisibleWire(events).includes(canary);
59
+ }
60
+ function gateBlocked(events) {
61
+ return events.some((event) => event.type === 'error');
62
+ }
63
+ async function runStreamChannel(attack, generation, canary) {
64
+ async function* mockProvider() {
65
+ await Promise.resolve();
66
+ for (const event of attack.events) {
67
+ yield event;
68
+ }
69
+ }
70
+ const events = await collectEvents(yieldProviderEvents({
71
+ profile: getProfile(FUZZ_PROFILE_ID),
72
+ generation,
73
+ system: bindCanary('fuzz system', canary),
74
+ provider: { complete: mockProvider },
75
+ upstream: [],
76
+ }));
77
+ const blocked = gateBlocked(events);
78
+ const bypassed = attack.shouldBlock && literalCanaryReachedClient(events, canary);
79
+ const falseAlarm = !attack.shouldBlock && blocked;
80
+ return {
81
+ attack,
82
+ channel: 'runTurn.stream',
83
+ blocked,
84
+ bypassed,
85
+ falseAlarm,
86
+ clientWire: clientVisibleWire(events),
87
+ };
88
+ }
89
+ async function runLiveBatchChannel(attack, canary) {
90
+ const session = createLiveOutboundGateSession(getProfile(FUZZ_PROFILE_ID), canary);
91
+ const batch = await processLiveOutboundBatch(session, attack.events);
92
+ if (batch.action === 'withhold') {
93
+ return {
94
+ attack,
95
+ channel: 'live.batch',
96
+ blocked: true,
97
+ bypassed: false,
98
+ falseAlarm: !attack.shouldBlock,
99
+ clientWire: '',
100
+ };
101
+ }
102
+ const emitted = batch.action === 'emit' ? [...batch.events] : [];
103
+ const finalized = await finalizeLiveOutboundTurn(session);
104
+ if (finalized.action === 'withhold') {
105
+ return {
106
+ attack,
107
+ channel: 'live.batch',
108
+ blocked: true,
109
+ bypassed: false,
110
+ falseAlarm: !attack.shouldBlock,
111
+ clientWire: clientVisibleWire(emitted),
112
+ };
113
+ }
114
+ if (finalized.action === 'emit') {
115
+ emitted.push(...finalized.events);
116
+ }
117
+ const bypassed = attack.shouldBlock && literalCanaryReachedClient(emitted, canary);
118
+ const blocked = attack.shouldBlock && !bypassed;
119
+ return {
120
+ attack,
121
+ channel: 'live.batch',
122
+ blocked,
123
+ bypassed,
124
+ falseAlarm: false,
125
+ clientWire: clientVisibleWire(emitted),
126
+ };
127
+ }
128
+ function truncate(s, max) {
129
+ if (s.length <= max)
130
+ return s;
131
+ return `${s.slice(0, max - 3)}...`;
132
+ }
133
+ function printResults(results) {
134
+ const bypassed = results.filter((r) => r.bypassed);
135
+ const falseAlarms = results.filter((r) => r.falseAlarm);
136
+ const caught = results.filter((r) => r.attack.shouldBlock && r.blocked && !r.bypassed);
137
+ console.log(`\n${'═'.repeat(72)}`);
138
+ console.log(` TOTAL: ${results.length} | CAUGHT: ${caught.length} | BYPASSED: ${bypassed.length} | FALSE ALARM: ${falseAlarms.length}`);
139
+ console.log(`${'═'.repeat(72)}`);
140
+ if (bypassed.length > 0) {
141
+ console.log('\n\x1b[31mBYPASSED (canary reached client-visible output):\x1b[0m\n');
142
+ for (const r of bypassed) {
143
+ console.log(` ✗ ${r.attack.category}/${r.attack.name} [${r.channel}]`);
144
+ console.log(` \x1b[2m${truncate(r.clientWire, 90)}\x1b[0m`);
145
+ }
146
+ }
147
+ if (falseAlarms.length > 0) {
148
+ console.log('\n\x1b[33mFALSE ALARMS (benign payload blocked):\x1b[0m\n');
149
+ for (const r of falseAlarms) {
150
+ console.log(` ⚠ ${r.attack.category}/${r.attack.name} [${r.channel}]`);
151
+ }
152
+ }
153
+ if (bypassed.length === 0 && falseAlarms.length === 0) {
154
+ console.log('\n\x1b[32mAll leak attempts blocked; benign controls passed.\x1b[0m\n');
155
+ }
156
+ return bypassed.length === 0 && falseAlarms.length === 0;
157
+ }
158
+ /** Run adversarial canary fuzz; returns true when no bypasses or false alarms. */
159
+ export async function fuzzCanaryCommand(options) {
160
+ console.log('\n🔐 Theorum Canary Egress Adversarial Fuzzer\n');
161
+ clearProfiles();
162
+ registerFuzzCanaryProfile();
163
+ const canary = options?.canary ?? FIXED_CANARY;
164
+ if (!/^theo-[0-9a-f]{32}$/.test(canary)) {
165
+ console.error(`Invalid canary shape (expected theo- + 32 hex): ${canary}`);
166
+ return false;
167
+ }
168
+ // Sanity: mint path uses same shape
169
+ const minted = mintCanary();
170
+ if (!/^theo-[0-9a-f]{32}$/.test(minted)) {
171
+ console.error(`mintCanary produced unexpected shape: ${minted}`);
172
+ return false;
173
+ }
174
+ const generation = resolveFuzzGeneration(canary);
175
+ const attacks = buildCanaryEgressAttacks(canary);
176
+ console.log(`Canary: ${canary.slice(0, 12)}… (${attacks.length} attacks × 2 channels)`);
177
+ const results = [];
178
+ for (const attack of attacks) {
179
+ results.push(await runStreamChannel(attack, generation, canary));
180
+ results.push(await runLiveBatchChannel(attack, canary));
181
+ }
182
+ // Spot-check scan helper matches expectations
183
+ if (!scanTextForCanaryLeak(canary, canary)) {
184
+ console.error('scanTextForCanaryLeak failed to detect literal canary');
185
+ return false;
186
+ }
187
+ const ok = printResults(results);
188
+ clearProfiles();
189
+ console.log('');
190
+ return ok;
191
+ }
@@ -1,9 +1,7 @@
1
1
  /**
2
- * Adversarial guardrail fuzzer.
3
- *
4
- * Throws injection payloads at every sanitization ingress and reports
5
- * what gets through unchanged — meaning the guardrails missed it.
2
+ * Adversarial inbound guardrail fuzzer (CLI entry).
6
3
  *
7
4
  * @module
8
5
  */
9
- export declare function fuzzGuardrailsCommand(): void;
6
+ /** Run inbound fuzz; returns true when no expected catches are missed. */
7
+ export declare function fuzzGuardrailsCommand(): boolean;