@paybond/kit 0.10.0 → 0.11.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 (335) hide show
  1. package/completion-presets/catalog.json +1187 -0
  2. package/completion-presets/catalog.sha256 +1 -0
  3. package/dev/trace-ui/dashboard.html +617 -0
  4. package/dist/agent/adapter.d.ts +51 -0
  5. package/dist/agent/adapter.js +66 -0
  6. package/dist/agent/attach-bundle.d.ts +37 -0
  7. package/dist/agent/attach-bundle.js +118 -0
  8. package/dist/agent/authorization-cache.d.ts +22 -0
  9. package/dist/agent/authorization-cache.js +36 -0
  10. package/dist/agent/deferred-tools.d.ts +11 -0
  11. package/dist/agent/deferred-tools.js +62 -0
  12. package/dist/agent/discover.d.ts +41 -0
  13. package/dist/agent/discover.js +147 -0
  14. package/dist/agent/evidence.d.ts +9 -0
  15. package/dist/agent/evidence.js +28 -0
  16. package/dist/agent/facade.d.ts +48 -0
  17. package/dist/agent/facade.js +112 -0
  18. package/dist/agent/gateway-trace-reporter.d.ts +28 -0
  19. package/dist/agent/gateway-trace-reporter.js +49 -0
  20. package/dist/agent/generic-runner.d.ts +14 -0
  21. package/dist/agent/generic-runner.js +49 -0
  22. package/dist/agent/generic-sandbox-demo.d.ts +36 -0
  23. package/dist/agent/generic-sandbox-demo.js +82 -0
  24. package/dist/agent/guarded-agent.d.ts +49 -0
  25. package/dist/agent/guarded-agent.js +100 -0
  26. package/dist/agent/index.d.ts +13 -0
  27. package/dist/agent/index.js +13 -0
  28. package/dist/agent/instrument.d.ts +156 -0
  29. package/dist/agent/instrument.js +442 -0
  30. package/dist/agent/interceptor.d.ts +24 -0
  31. package/dist/agent/interceptor.js +440 -0
  32. package/dist/agent/lazy-context-tools.d.ts +15 -0
  33. package/dist/agent/lazy-context-tools.js +81 -0
  34. package/dist/agent/registry-file.d.ts +39 -0
  35. package/dist/agent/registry-file.js +219 -0
  36. package/dist/agent/registry.d.ts +37 -0
  37. package/dist/agent/registry.js +128 -0
  38. package/dist/agent/run.d.ts +124 -0
  39. package/dist/agent/run.js +301 -0
  40. package/dist/agent/types.d.ts +318 -0
  41. package/dist/agent/types.js +42 -0
  42. package/dist/agent-recognition.d.ts +72 -0
  43. package/dist/agent-recognition.js +165 -0
  44. package/dist/bincode-wire.d.ts +18 -0
  45. package/dist/bincode-wire.js +93 -0
  46. package/dist/claude-agents/config.d.ts +21 -0
  47. package/dist/claude-agents/config.js +145 -0
  48. package/dist/claude-agents/index.d.ts +2 -0
  49. package/dist/claude-agents/index.js +2 -0
  50. package/dist/claude-agents/sandbox-demo.d.ts +30 -0
  51. package/dist/claude-agents/sandbox-demo.js +91 -0
  52. package/dist/cli/agent/env-quote.d.ts +1 -0
  53. package/dist/cli/agent/env-quote.js +6 -0
  54. package/dist/cli/agent/env-write.d.ts +8 -0
  55. package/dist/cli/agent/env-write.js +47 -0
  56. package/dist/cli/agent/paybond.d.ts +16 -0
  57. package/dist/cli/agent/paybond.js +55 -0
  58. package/dist/cli/agent/policy-file.d.ts +29 -0
  59. package/dist/cli/agent/policy-file.js +61 -0
  60. package/dist/cli/agent/production-evidence.d.ts +24 -0
  61. package/dist/cli/agent/production-evidence.js +98 -0
  62. package/dist/cli/agent/run-store.d.ts +30 -0
  63. package/dist/cli/agent/run-store.js +42 -0
  64. package/dist/cli/agent/run-trace-store.d.ts +39 -0
  65. package/dist/cli/agent/run-trace-store.js +143 -0
  66. package/dist/cli/agent-run-trace-table.d.ts +9 -0
  67. package/dist/cli/agent-run-trace-table.js +24 -0
  68. package/dist/cli/agent-sandbox-smoke-checklist.d.ts +9 -0
  69. package/dist/cli/agent-sandbox-smoke-checklist.js +50 -0
  70. package/dist/cli/command-spec.d.ts +1 -0
  71. package/dist/cli/command-spec.js +286 -5
  72. package/dist/cli/commands/agent.d.ts +16 -0
  73. package/dist/cli/commands/agent.js +1135 -0
  74. package/dist/cli/commands/dev.d.ts +7 -0
  75. package/dist/cli/commands/dev.js +348 -0
  76. package/dist/cli/commands/discovery.js +3 -3
  77. package/dist/cli/commands/policy.d.ts +13 -0
  78. package/dist/cli/commands/policy.js +769 -0
  79. package/dist/cli/commands/setup.d.ts +3 -0
  80. package/dist/cli/commands/setup.js +124 -8
  81. package/dist/cli/commands/workflows.js +9 -4
  82. package/dist/cli/config.d.ts +2 -0
  83. package/dist/cli/config.js +4 -2
  84. package/dist/cli/context.js +2 -1
  85. package/dist/cli/credentials.js +2 -2
  86. package/dist/cli/doctor-agent-middleware.d.ts +5 -0
  87. package/dist/cli/doctor-agent-middleware.js +49 -0
  88. package/dist/cli/globals.d.ts +1 -0
  89. package/dist/cli/globals.js +11 -1
  90. package/dist/cli/help.d.ts +1 -1
  91. package/dist/cli/help.js +35 -3
  92. package/dist/cli/mcp-install.js +2 -2
  93. package/dist/cli/mcp-policy.d.ts +3 -0
  94. package/dist/cli/mcp-policy.js +19 -13
  95. package/dist/cli/mcp-verify-config.js +9 -11
  96. package/dist/cli/redact.js +29 -8
  97. package/dist/cli/router.js +105 -2
  98. package/dist/cli/smoke-deep-links.d.ts +15 -0
  99. package/dist/cli/smoke-deep-links.js +63 -0
  100. package/dist/cli/telemetry.d.ts +17 -0
  101. package/dist/cli/telemetry.js +94 -0
  102. package/dist/completion-catalog-digest.d.ts +2 -0
  103. package/dist/completion-catalog-digest.js +2 -0
  104. package/dist/completion-catalog-integrity.d.ts +2 -0
  105. package/dist/completion-catalog-integrity.js +17 -0
  106. package/dist/completion-catalog.d.ts +49 -0
  107. package/dist/completion-catalog.js +62 -0
  108. package/dist/completion-contract-digest.d.ts +37 -0
  109. package/dist/completion-contract-digest.js +73 -0
  110. package/dist/completion-forbidden-fields.d.ts +5 -0
  111. package/dist/completion-forbidden-fields.js +26 -0
  112. package/dist/completion-init.d.ts +8 -0
  113. package/dist/completion-init.js +334 -0
  114. package/dist/completion-resolve.d.ts +21 -0
  115. package/dist/completion-resolve.js +86 -0
  116. package/dist/completion-validate-evidence.d.ts +24 -0
  117. package/dist/completion-validate-evidence.js +145 -0
  118. package/dist/dev/offline-gateway.d.ts +24 -0
  119. package/dist/dev/offline-gateway.js +102 -0
  120. package/dist/dev/trace-buffer.d.ts +61 -0
  121. package/dist/dev/trace-buffer.js +330 -0
  122. package/dist/dev/trace-security-headers.d.ts +11 -0
  123. package/dist/dev/trace-security-headers.js +16 -0
  124. package/dist/dev/trace-server.d.ts +8 -0
  125. package/dist/dev/trace-server.js +38 -0
  126. package/dist/dev/trace-ui.d.ts +4 -0
  127. package/dist/dev/trace-ui.js +25 -0
  128. package/dist/dev/wiremock-up.d.ts +15 -0
  129. package/dist/dev/wiremock-up.js +118 -0
  130. package/dist/doctor-completion.d.ts +17 -0
  131. package/dist/doctor-completion.js +428 -0
  132. package/dist/gateway-url.d.ts +7 -0
  133. package/dist/gateway-url.js +69 -0
  134. package/dist/index.d.ts +119 -2
  135. package/dist/index.js +267 -6
  136. package/dist/init.js +374 -57
  137. package/dist/langgraph/awrap-tool-call.d.ts +25 -0
  138. package/dist/langgraph/awrap-tool-call.js +81 -0
  139. package/dist/langgraph/config.d.ts +13 -0
  140. package/dist/langgraph/config.js +11 -0
  141. package/dist/langgraph/index.d.ts +4 -0
  142. package/dist/langgraph/index.js +4 -0
  143. package/dist/langgraph/sandbox-demo.d.ts +40 -0
  144. package/dist/langgraph/sandbox-demo.js +96 -0
  145. package/dist/langgraph/tool-node.d.ts +10 -0
  146. package/dist/langgraph/tool-node.js +38 -0
  147. package/dist/login.js +7 -0
  148. package/dist/mcp/index.d.ts +1 -0
  149. package/dist/mcp/index.js +1 -0
  150. package/dist/mcp/tool-surface.d.ts +25 -0
  151. package/dist/mcp/tool-surface.js +17 -0
  152. package/dist/mcp-capability-token-cache.d.ts +24 -0
  153. package/dist/mcp-capability-token-cache.js +101 -0
  154. package/dist/mcp-evidence-policy.d.ts +48 -0
  155. package/dist/mcp-evidence-policy.js +117 -0
  156. package/dist/mcp-policy-reload.d.ts +79 -0
  157. package/dist/mcp-policy-reload.js +200 -0
  158. package/dist/mcp-sep2828-evidence.d.ts +36 -0
  159. package/dist/mcp-sep2828-evidence.js +65 -0
  160. package/dist/mcp-server.d.ts +6 -0
  161. package/dist/mcp-server.js +224 -44
  162. package/dist/openai-agents/index.d.ts +40 -0
  163. package/dist/openai-agents/index.js +151 -0
  164. package/dist/openai-agents/sandbox-demo.d.ts +34 -0
  165. package/dist/openai-agents/sandbox-demo.js +118 -0
  166. package/dist/payee-evidence.js +2 -29
  167. package/dist/policy/catalog.d.ts +31 -0
  168. package/dist/policy/catalog.js +48 -0
  169. package/dist/policy/compose-utils.d.ts +3 -0
  170. package/dist/policy/compose-utils.js +4 -0
  171. package/dist/policy/compose.d.ts +20 -0
  172. package/dist/policy/compose.js +240 -0
  173. package/dist/policy/digest.d.ts +7 -0
  174. package/dist/policy/digest.js +75 -0
  175. package/dist/policy/domain.d.ts +15 -0
  176. package/dist/policy/domain.js +28 -0
  177. package/dist/policy/guardrail-spec.d.ts +17 -0
  178. package/dist/policy/guardrail-spec.js +140 -0
  179. package/dist/policy/guardrails.d.ts +48 -0
  180. package/dist/policy/guardrails.js +72 -0
  181. package/dist/policy/index.d.ts +21 -0
  182. package/dist/policy/index.js +21 -0
  183. package/dist/policy/init.d.ts +102 -0
  184. package/dist/policy/init.js +351 -0
  185. package/dist/policy/intent-spec.d.ts +52 -0
  186. package/dist/policy/intent-spec.js +176 -0
  187. package/dist/policy/json-path.d.ts +4 -0
  188. package/dist/policy/json-path.js +23 -0
  189. package/dist/policy/layers-io.d.ts +7 -0
  190. package/dist/policy/layers-io.js +28 -0
  191. package/dist/policy/load-effective.d.ts +22 -0
  192. package/dist/policy/load-effective.js +77 -0
  193. package/dist/policy/load.d.ts +85 -0
  194. package/dist/policy/load.js +164 -0
  195. package/dist/policy/merge.d.ts +29 -0
  196. package/dist/policy/merge.js +297 -0
  197. package/dist/policy/parse-text.d.ts +2 -0
  198. package/dist/policy/parse-text.js +126 -0
  199. package/dist/policy/policy-api.d.ts +45 -0
  200. package/dist/policy/policy-api.js +61 -0
  201. package/dist/policy/presets.d.ts +19 -0
  202. package/dist/policy/presets.js +66 -0
  203. package/dist/policy/registry.d.ts +7 -0
  204. package/dist/policy/registry.js +33 -0
  205. package/dist/policy/reload.d.ts +86 -0
  206. package/dist/policy/reload.js +233 -0
  207. package/dist/policy/render-yaml.d.ts +3 -0
  208. package/dist/policy/render-yaml.js +69 -0
  209. package/dist/policy/sandbox-bootstrap.d.ts +19 -0
  210. package/dist/policy/sandbox-bootstrap.js +66 -0
  211. package/dist/policy/schema.d.ts +204 -0
  212. package/dist/policy/schema.js +255 -0
  213. package/dist/policy/snapshot.d.ts +33 -0
  214. package/dist/policy/snapshot.js +23 -0
  215. package/dist/policy/validate-remote.d.ts +43 -0
  216. package/dist/policy/validate-remote.js +104 -0
  217. package/dist/policy/validate.d.ts +36 -0
  218. package/dist/policy/validate.js +150 -0
  219. package/dist/policy/watcher.d.ts +29 -0
  220. package/dist/policy/watcher.js +112 -0
  221. package/dist/principal-intent.d.ts +52 -0
  222. package/dist/principal-intent.js +193 -37
  223. package/dist/project-init.d.ts +34 -0
  224. package/dist/project-init.js +898 -0
  225. package/dist/sep2828-signature.d.ts +10 -0
  226. package/dist/sep2828-signature.js +134 -0
  227. package/dist/solutions/api.d.ts +22 -0
  228. package/dist/solutions/api.js +40 -0
  229. package/dist/solutions/catalog.d.ts +34 -0
  230. package/dist/solutions/catalog.js +129 -0
  231. package/dist/solutions/index.d.ts +2 -0
  232. package/dist/solutions/index.js +2 -0
  233. package/dist/template-init.d.ts +54 -0
  234. package/dist/template-init.js +203 -0
  235. package/dist/vercel-ai/config.d.ts +15 -0
  236. package/dist/vercel-ai/config.js +13 -0
  237. package/dist/vercel-ai/index.d.ts +4 -0
  238. package/dist/vercel-ai/index.js +4 -0
  239. package/dist/vercel-ai/sandbox-demo.d.ts +44 -0
  240. package/dist/vercel-ai/sandbox-demo.js +153 -0
  241. package/dist/vercel-ai/tool-approval.d.ts +16 -0
  242. package/dist/vercel-ai/tool-approval.js +41 -0
  243. package/dist/vercel-ai/wrap-tools.d.ts +9 -0
  244. package/dist/vercel-ai/wrap-tools.js +40 -0
  245. package/dist/x402-receipt-evidence.d.ts +29 -0
  246. package/dist/x402-receipt-evidence.js +97 -0
  247. package/dist/x402-receipt-signature.d.ts +12 -0
  248. package/dist/x402-receipt-signature.js +211 -0
  249. package/package.json +75 -3
  250. package/solutions/aws.json +17 -0
  251. package/solutions/saas.json +17 -0
  252. package/solutions/shopping.json +17 -0
  253. package/solutions/travel.json +18 -0
  254. package/templates/manifest.json +169 -0
  255. package/templates/openai-shopping-agent/.env.example +3 -0
  256. package/templates/openai-shopping-agent/.github/workflows/smoke.yml +20 -0
  257. package/templates/openai-shopping-agent/LICENSE +201 -0
  258. package/templates/openai-shopping-agent/README.md +29 -0
  259. package/templates/openai-shopping-agent/package.json +22 -0
  260. package/templates/openai-shopping-agent/paybond.policy.yaml +22 -0
  261. package/templates/openai-shopping-agent/src/index.ts +22 -0
  262. package/templates/openai-shopping-agent/src/paybond.config.ts +51 -0
  263. package/templates/openai-shopping-agent/tsconfig.json +13 -0
  264. package/templates/paybond-aws-operator/.env.example +3 -0
  265. package/templates/paybond-aws-operator/.github/workflows/smoke.yml +20 -0
  266. package/templates/paybond-aws-operator/LICENSE +201 -0
  267. package/templates/paybond-aws-operator/README.md +29 -0
  268. package/templates/paybond-aws-operator/package.json +20 -0
  269. package/templates/paybond-aws-operator/paybond.policy.yaml +22 -0
  270. package/templates/paybond-aws-operator/src/index.ts +54 -0
  271. package/templates/paybond-aws-operator/src/paybond.config.ts +51 -0
  272. package/templates/paybond-aws-operator/tsconfig.json +13 -0
  273. package/templates/paybond-claude-agents-demo/.env.example +3 -0
  274. package/templates/paybond-claude-agents-demo/.github/workflows/smoke.yml +20 -0
  275. package/templates/paybond-claude-agents-demo/LICENSE +201 -0
  276. package/templates/paybond-claude-agents-demo/README.md +29 -0
  277. package/templates/paybond-claude-agents-demo/package.json +22 -0
  278. package/templates/paybond-claude-agents-demo/paybond.policy.yaml +22 -0
  279. package/templates/paybond-claude-agents-demo/src/index.ts +22 -0
  280. package/templates/paybond-claude-agents-demo/src/paybond.config.ts +51 -0
  281. package/templates/paybond-claude-agents-demo/tsconfig.json +13 -0
  282. package/templates/paybond-invoice-agent/.env.example +3 -0
  283. package/templates/paybond-invoice-agent/.github/workflows/smoke.yml +19 -0
  284. package/templates/paybond-invoice-agent/LICENSE +201 -0
  285. package/templates/paybond-invoice-agent/README.md +29 -0
  286. package/templates/paybond-invoice-agent/app.py +27 -0
  287. package/templates/paybond-invoice-agent/package.json +6 -0
  288. package/templates/paybond-invoice-agent/paybond.policy.yaml +22 -0
  289. package/templates/paybond-invoice-agent/paybond_config.py +45 -0
  290. package/templates/paybond-invoice-agent/requirements.txt +2 -0
  291. package/templates/paybond-mcp-coding-agent/.env.example +3 -0
  292. package/templates/paybond-mcp-coding-agent/.github/workflows/smoke.yml +20 -0
  293. package/templates/paybond-mcp-coding-agent/LICENSE +201 -0
  294. package/templates/paybond-mcp-coding-agent/README.md +39 -0
  295. package/templates/paybond-mcp-coding-agent/package.json +20 -0
  296. package/templates/paybond-mcp-coding-agent/paybond.policy.yaml +25 -0
  297. package/templates/paybond-mcp-coding-agent/src/index.ts +40 -0
  298. package/templates/paybond-mcp-coding-agent/src/paybond.config.ts +51 -0
  299. package/templates/paybond-mcp-coding-agent/tsconfig.json +13 -0
  300. package/templates/paybond-openai-agents-demo/.env.example +3 -0
  301. package/templates/paybond-openai-agents-demo/.github/workflows/smoke.yml +20 -0
  302. package/templates/paybond-openai-agents-demo/LICENSE +201 -0
  303. package/templates/paybond-openai-agents-demo/README.md +29 -0
  304. package/templates/paybond-openai-agents-demo/package.json +22 -0
  305. package/templates/paybond-openai-agents-demo/paybond.policy.yaml +22 -0
  306. package/templates/paybond-openai-agents-demo/src/index.ts +22 -0
  307. package/templates/paybond-openai-agents-demo/src/paybond.config.ts +51 -0
  308. package/templates/paybond-openai-agents-demo/tsconfig.json +13 -0
  309. package/templates/paybond-procurement-agent/.env.example +3 -0
  310. package/templates/paybond-procurement-agent/.github/workflows/smoke.yml +20 -0
  311. package/templates/paybond-procurement-agent/LICENSE +201 -0
  312. package/templates/paybond-procurement-agent/README.md +29 -0
  313. package/templates/paybond-procurement-agent/package.json +20 -0
  314. package/templates/paybond-procurement-agent/paybond.policy.yaml +25 -0
  315. package/templates/paybond-procurement-agent/src/index.ts +54 -0
  316. package/templates/paybond-procurement-agent/src/paybond.config.ts +51 -0
  317. package/templates/paybond-procurement-agent/tsconfig.json +13 -0
  318. package/templates/paybond-travel-agent/.env.example +3 -0
  319. package/templates/paybond-travel-agent/.github/workflows/smoke.yml +20 -0
  320. package/templates/paybond-travel-agent/LICENSE +201 -0
  321. package/templates/paybond-travel-agent/README.md +29 -0
  322. package/templates/paybond-travel-agent/package.json +23 -0
  323. package/templates/paybond-travel-agent/paybond.policy.yaml +22 -0
  324. package/templates/paybond-travel-agent/src/index.ts +22 -0
  325. package/templates/paybond-travel-agent/src/paybond.config.ts +51 -0
  326. package/templates/paybond-travel-agent/tsconfig.json +13 -0
  327. package/templates/paybond-vercel-shopping-agent/.env.example +3 -0
  328. package/templates/paybond-vercel-shopping-agent/.github/workflows/smoke.yml +20 -0
  329. package/templates/paybond-vercel-shopping-agent/LICENSE +201 -0
  330. package/templates/paybond-vercel-shopping-agent/README.md +29 -0
  331. package/templates/paybond-vercel-shopping-agent/package.json +22 -0
  332. package/templates/paybond-vercel-shopping-agent/paybond.policy.yaml +22 -0
  333. package/templates/paybond-vercel-shopping-agent/src/index.ts +22 -0
  334. package/templates/paybond-vercel-shopping-agent/src/paybond.config.ts +51 -0
  335. package/templates/paybond-vercel-shopping-agent/tsconfig.json +13 -0
@@ -0,0 +1,34 @@
1
+ import type { Paybond } from "../index.js";
2
+ export type RunOpenAIAgentsSandboxDemoInput = {
3
+ paybond: Paybond;
4
+ operation?: string;
5
+ requestedSpendCents?: number;
6
+ evidencePreset?: string;
7
+ toolCallId?: string;
8
+ };
9
+ export type RunOpenAIAgentsSandboxDemoResult = {
10
+ bind: {
11
+ run_id: string;
12
+ tenant_id: string;
13
+ intent_id: string;
14
+ capability_token: string;
15
+ operation: string;
16
+ sandbox_lifecycle_status?: string;
17
+ };
18
+ guardrail: {
19
+ behavior: string;
20
+ };
21
+ execute: {
22
+ tool_result?: unknown;
23
+ evidence?: {
24
+ submitted: boolean;
25
+ sandbox_lifecycle_status?: string;
26
+ predicate_passed?: boolean | null;
27
+ };
28
+ };
29
+ };
30
+ /**
31
+ * No-LLM OpenAI Agents SDK sandbox demo: input guardrail pre-check + guarded
32
+ * `invoke` + auto-evidence.
33
+ */
34
+ export declare function runOpenAIAgentsSandboxDemo(input: RunOpenAIAgentsSandboxDemoInput): Promise<RunOpenAIAgentsSandboxDemoResult>;
@@ -0,0 +1,118 @@
1
+ import { createPaybondToolRegistry } from "../agent/registry.js";
2
+ import { createPaybondOpenAIAgentsConfig } from "./index.js";
3
+ function makePaidFunctionTool(name) {
4
+ return {
5
+ type: "function",
6
+ name,
7
+ description: `Paid operation ${name}`,
8
+ parameters: {
9
+ type: "object",
10
+ properties: {
11
+ estimatedPriceCents: { type: "integer", minimum: 0 },
12
+ },
13
+ required: ["estimatedPriceCents"],
14
+ additionalProperties: false,
15
+ },
16
+ strict: false,
17
+ invoke: async (_runContext, input) => {
18
+ const args = JSON.parse(input);
19
+ return JSON.stringify({
20
+ status: "completed",
21
+ cost_cents: args.estimatedPriceCents,
22
+ });
23
+ },
24
+ needsApproval: async () => false,
25
+ isEnabled: async () => true,
26
+ };
27
+ }
28
+ /**
29
+ * No-LLM OpenAI Agents SDK sandbox demo: input guardrail pre-check + guarded
30
+ * `invoke` + auto-evidence.
31
+ */
32
+ export async function runOpenAIAgentsSandboxDemo(input) {
33
+ const operation = (input.operation ?? "paid-tool").trim();
34
+ const requestedSpendCents = input.requestedSpendCents ?? 100;
35
+ const evidencePreset = (input.evidencePreset ?? "cost_and_completion").trim();
36
+ const toolCallId = (input.toolCallId ?? "openai-demo-1").trim();
37
+ const registry = createPaybondToolRegistry({
38
+ defaultDeny: true,
39
+ sideEffecting: {
40
+ [operation]: {
41
+ operation,
42
+ evidencePreset,
43
+ spendCents: (args) => typeof args === "object" &&
44
+ args !== null &&
45
+ "estimatedPriceCents" in args &&
46
+ typeof args.estimatedPriceCents === "number"
47
+ ? args.estimatedPriceCents
48
+ : requestedSpendCents,
49
+ evidenceMapper: (result) => {
50
+ const payload = result;
51
+ return {
52
+ status: payload.status,
53
+ cost_cents: payload.cost_cents,
54
+ };
55
+ },
56
+ },
57
+ },
58
+ });
59
+ const run = await input.paybond.agentRun.bind({
60
+ bootstrap: {
61
+ kind: "sandbox",
62
+ operation,
63
+ requestedSpendCents,
64
+ completionPreset: evidencePreset,
65
+ },
66
+ registry,
67
+ });
68
+ const paidTool = makePaidFunctionTool(operation);
69
+ const config = createPaybondOpenAIAgentsConfig(run, [paidTool]);
70
+ const guarded = config.tools[0];
71
+ if (!guarded) {
72
+ throw new Error("openai-agents sandbox demo missing guarded tool");
73
+ }
74
+ const toolCall = {
75
+ type: "function_call",
76
+ name: operation,
77
+ callId: toolCallId,
78
+ arguments: JSON.stringify({ estimatedPriceCents: requestedSpendCents }),
79
+ };
80
+ const guardrail = guarded.inputGuardrails?.[0];
81
+ const guardrailResult = guardrail
82
+ ? await guardrail.run({
83
+ agent: {},
84
+ context: {},
85
+ toolCall,
86
+ })
87
+ : undefined;
88
+ const output = (await guarded.invoke({}, JSON.stringify({ estimatedPriceCents: requestedSpendCents }), { toolCall }));
89
+ let toolResult;
90
+ try {
91
+ toolResult = JSON.parse(output);
92
+ }
93
+ catch {
94
+ toolResult = output;
95
+ }
96
+ const sandboxStatus = run.binding.sandbox?.sandboxLifecycleStatus;
97
+ return {
98
+ bind: {
99
+ run_id: run.runId,
100
+ tenant_id: run.tenantId,
101
+ intent_id: run.intentId,
102
+ capability_token: run.capabilityToken,
103
+ operation,
104
+ sandbox_lifecycle_status: sandboxStatus,
105
+ },
106
+ guardrail: {
107
+ behavior: guardrailResult?.behavior.type ?? "not-applicable",
108
+ },
109
+ execute: {
110
+ tool_result: toolResult,
111
+ evidence: {
112
+ submitted: true,
113
+ sandbox_lifecycle_status: sandboxStatus,
114
+ predicate_passed: true,
115
+ },
116
+ },
117
+ };
118
+ }
@@ -3,28 +3,9 @@
3
3
  */
4
4
  import { sign, getPublicKey } from "@noble/ed25519";
5
5
  import { createHash } from "blake3";
6
- import { parse as parseUuid } from "uuid";
7
6
  import { ensureEd25519Sha512Sync } from "./ed25519-sync.js";
8
7
  import { jsonValueDigest } from "./json-digest.js";
9
- function concatBytes(...parts) {
10
- const n = parts.reduce((a, p) => a + p.length, 0);
11
- const out = new Uint8Array(n);
12
- let o = 0;
13
- for (const p of parts) {
14
- out.set(p, o);
15
- o += p.length;
16
- }
17
- return out;
18
- }
19
- function encodeU64(n) {
20
- const b = new Uint8Array(8);
21
- new DataView(b.buffer).setBigUint64(0, BigInt(n), true);
22
- return b;
23
- }
24
- function encodeBincodeString(s) {
25
- const utf8 = new TextEncoder().encode(s);
26
- return concatBytes(encodeU64(utf8.length), utf8);
27
- }
8
+ import { concatBytes, encodeBincodeString, encodeBincodeUuid, encodeFixed32, encodeU8, EVIDENCE_SIGN_VERSION, } from "./bincode-wire.js";
28
9
  /** BLAKE3 digest of concatenated artifact hashes (empty list matches Harbor / `paybond-evidence`). */
29
10
  export function artifactsDigest(artifactHashes32) {
30
11
  const h = createHash();
@@ -35,15 +16,7 @@ export function artifactsDigest(artifactHashes32) {
35
16
  return new Uint8Array(buf);
36
17
  }
37
18
  function encodeEvidenceSignV1(input) {
38
- const version = new Uint8Array([1]);
39
- const intentBytes = parseUuid(input.intentId);
40
- if (intentBytes.length !== 16) {
41
- throw new Error("intentId must be a UUID string");
42
- }
43
- if (input.payloadDigest.length !== 32 || input.artifactsDigest.length !== 32) {
44
- throw new Error("digest must be 32 bytes");
45
- }
46
- return concatBytes(version, encodeBincodeString(input.tenantId), encodeU64(16), intentBytes, encodeBincodeString(input.payeeDid), input.payloadDigest, input.artifactsDigest, encodeBincodeString(input.submittedAtRfc3339));
19
+ return concatBytes(encodeU8(EVIDENCE_SIGN_VERSION), encodeBincodeString(input.tenantId), encodeBincodeUuid(input.intentId), encodeBincodeString(input.payeeDid), encodeFixed32(input.payloadDigest), encodeFixed32(input.artifactsDigest), encodeBincodeString(input.submittedAtRfc3339));
47
20
  }
48
21
  function bytesToBase64(bytes) {
49
22
  let binary = "";
@@ -0,0 +1,31 @@
1
+ import { listGuardrailCatalogEntries } from "./guardrail-spec.js";
2
+ export type PolicyDomainCatalogEntry = {
3
+ id: string;
4
+ title: string;
5
+ layered: boolean;
6
+ };
7
+ export type PolicyPresetCatalogEntry = {
8
+ id: string;
9
+ kind: "composed" | "flat";
10
+ layered: boolean;
11
+ };
12
+ export type PolicySolutionCatalogEntry = {
13
+ id: string;
14
+ title: string;
15
+ domain: string;
16
+ guardrails: string[];
17
+ primary_operation: string;
18
+ };
19
+ /** List bundled domain layers for CLI and docs. */
20
+ export declare function listPolicyDomainCatalog(): PolicyDomainCatalogEntry[];
21
+ /** List flat and composed policy presets. */
22
+ export declare function listPolicyPresetCatalog(): PolicyPresetCatalogEntry[];
23
+ /** List bundled solution manifests. */
24
+ export declare function listPolicySolutionCatalog(): PolicySolutionCatalogEntry[];
25
+ /** Combined catalog payload for `paybond policy presets list`. */
26
+ export declare function listPolicyPresetsCatalog(): {
27
+ domains: PolicyDomainCatalogEntry[];
28
+ guardrails: ReturnType<typeof listGuardrailCatalogEntries>;
29
+ solutions: PolicySolutionCatalogEntry[];
30
+ presets: PolicyPresetCatalogEntry[];
31
+ };
@@ -0,0 +1,48 @@
1
+ import { LAYERED_POLICY_PRESET_IDS } from "./compose.js";
2
+ import { listGuardrailCatalogEntries } from "./guardrail-spec.js";
3
+ import { isLayeredPolicyPresetId, listPolicyPresetIds } from "./presets.js";
4
+ import { listSolutionIds, loadSolutionManifest } from "../solutions/catalog.js";
5
+ const DOMAIN_TITLES = {
6
+ travel: "Travel booking",
7
+ shopping: "Shopping checkout",
8
+ saas: "SaaS provisioning",
9
+ aws: "AWS operator",
10
+ };
11
+ /** List bundled domain layers for CLI and docs. */
12
+ export function listPolicyDomainCatalog() {
13
+ return LAYERED_POLICY_PRESET_IDS.map((id) => ({
14
+ id,
15
+ title: DOMAIN_TITLES[id] ?? id,
16
+ layered: true,
17
+ }));
18
+ }
19
+ /** List flat and composed policy presets. */
20
+ export function listPolicyPresetCatalog() {
21
+ return listPolicyPresetIds().map((id) => ({
22
+ id,
23
+ kind: isLayeredPolicyPresetId(id) ? "composed" : "flat",
24
+ layered: isLayeredPolicyPresetId(id),
25
+ }));
26
+ }
27
+ /** List bundled solution manifests. */
28
+ export function listPolicySolutionCatalog() {
29
+ return listSolutionIds().map((id) => {
30
+ const manifest = loadSolutionManifest(id);
31
+ return {
32
+ id: manifest.id,
33
+ title: manifest.title,
34
+ domain: manifest.policy_default.domain,
35
+ guardrails: [...manifest.policy_default.guardrails],
36
+ primary_operation: manifest.primary_operation,
37
+ };
38
+ });
39
+ }
40
+ /** Combined catalog payload for `paybond policy presets list`. */
41
+ export function listPolicyPresetsCatalog() {
42
+ return {
43
+ domains: listPolicyDomainCatalog(),
44
+ guardrails: listGuardrailCatalogEntries(),
45
+ solutions: listPolicySolutionCatalog(),
46
+ presets: listPolicyPresetCatalog(),
47
+ };
48
+ }
@@ -0,0 +1,3 @@
1
+ import type { PaybondPolicyToolEntry } from "./schema.js";
2
+ /** Clone a tool registry entry for compose merges. */
3
+ export declare function cloneToolEntry(entry: PaybondPolicyToolEntry): PaybondPolicyToolEntry;
@@ -0,0 +1,4 @@
1
+ /** Clone a tool registry entry for compose merges. */
2
+ export function cloneToolEntry(entry) {
3
+ return { ...entry };
4
+ }
@@ -0,0 +1,20 @@
1
+ import { type PolicyGuardrailLayer } from "./guardrails.js";
2
+ import { type PolicyPresetId } from "./presets.js";
3
+ import { type PaybondPolicyDocumentV1 } from "./schema.js";
4
+ export declare const LAYERED_POLICY_PRESET_IDS: readonly ["travel", "shopping", "saas", "aws"];
5
+ export type LayeredPolicyPresetId = (typeof LAYERED_POLICY_PRESET_IDS)[number];
6
+ /** Stack a domain document with one or more guardrail layers (same-tenant compose, not org inheritance). */
7
+ export declare function composePolicyLayers(domainDocument: PaybondPolicyDocumentV1, ...layers: PolicyGuardrailLayer[]): PaybondPolicyDocumentV1;
8
+ /** True when a bundled preset is composed from domain + guardrails layers. */
9
+ export declare function isLayeredPolicyPreset(presetId: string): presetId is LayeredPolicyPresetId;
10
+ /** Merge domain and guardrail YAML objects (bundled preset file generation). */
11
+ export declare function composePolicyPresetLayers(domain: Record<string, unknown>, guardrails: Record<string, unknown>): Record<string, unknown>;
12
+ /** Default bundled guardrail layers for a vertical preset id. */
13
+ export declare function bundledDefaultGuardrails(presetId: LayeredPolicyPresetId): PolicyGuardrailLayer[];
14
+ /** Compose the shipped default for a vertical preset (domain + bundled guardrails). */
15
+ export declare function composeBundledPresetDefault(presetId: LayeredPolicyPresetId): PaybondPolicyDocumentV1;
16
+ /** Load and compose a layered vertical preset (domain + guardrails YAML files). */
17
+ export declare function composeLayeredPolicyPresetDocument(presetId: LayeredPolicyPresetId): Record<string, unknown>;
18
+ /** Compare composed layered presets with bundled flat preset files (tests). */
19
+ export declare function assertLayeredPresetMatchesFlat(presetId: PolicyPresetId): void;
20
+ export { readPresetLayerYaml } from "./layers-io.js";
@@ -0,0 +1,240 @@
1
+ import { cloneToolEntry } from "./compose-utils.js";
2
+ import { guardrailLayerFromDocument } from "./guardrails.js";
3
+ import { loadBundledDefaultGuardrailsDocument, loadBundledDomainDocument, } from "./layers-io.js";
4
+ import { parsePolicyDocumentText } from "./parse-text.js";
5
+ import { readPolicyPresetYaml, resolvePolicyPresetPath } from "./presets.js";
6
+ import { parsePaybondPolicyDocumentV1, } from "./schema.js";
7
+ export const LAYERED_POLICY_PRESET_IDS = ["travel", "shopping", "saas", "aws"];
8
+ function mergeStricterDefaultDeny(...values) {
9
+ return values.some((value) => value === true);
10
+ }
11
+ function cloneDocument(document) {
12
+ return {
13
+ ...document,
14
+ tools: Object.fromEntries(Object.entries(document.tools).map(([name, entry]) => [name, cloneToolEntry(entry)])),
15
+ intent: document.intent
16
+ ? {
17
+ ...document.intent,
18
+ ...(document.intent.allowed_tools
19
+ ? { allowed_tools: [...document.intent.allowed_tools] }
20
+ : {}),
21
+ ...(document.intent.budget ? { budget: { ...document.intent.budget } } : {}),
22
+ ...(document.intent.policy_binding
23
+ ? { policy_binding: { ...document.intent.policy_binding } }
24
+ : {}),
25
+ }
26
+ : undefined,
27
+ };
28
+ }
29
+ function mergeToolEntry(base, patch) {
30
+ const merged = cloneToolEntry(base);
31
+ if (patch.side_effecting !== undefined) {
32
+ merged.side_effecting = patch.side_effecting;
33
+ }
34
+ if (patch.max_spend_cents !== undefined) {
35
+ merged.max_spend_cents =
36
+ merged.max_spend_cents !== undefined
37
+ ? Math.min(merged.max_spend_cents, patch.max_spend_cents)
38
+ : patch.max_spend_cents;
39
+ }
40
+ if (patch.spend_from_args !== undefined) {
41
+ merged.spend_from_args = patch.spend_from_args;
42
+ delete merged.max_spend_cents;
43
+ }
44
+ if (patch.evidence_preset !== undefined) {
45
+ merged.evidence_preset = patch.evidence_preset;
46
+ }
47
+ if (patch.vendor_pack !== undefined) {
48
+ merged.vendor_pack = patch.vendor_pack;
49
+ }
50
+ if (patch.operation !== undefined) {
51
+ merged.operation = patch.operation;
52
+ }
53
+ return merged;
54
+ }
55
+ function mergeBudgetCaps(current, nextUsd) {
56
+ const currency = current?.currency ?? "usd";
57
+ const currentUsd = current?.max_spend_usd;
58
+ return {
59
+ ...current,
60
+ currency,
61
+ max_spend_usd: currentUsd !== undefined ? Math.min(currentUsd, nextUsd) : nextUsd,
62
+ };
63
+ }
64
+ function applyReadOnlyFilter(document, searchOnly) {
65
+ const filteredEntries = Object.entries(document.tools).filter(([name, entry]) => {
66
+ if (entry.side_effecting) {
67
+ return false;
68
+ }
69
+ return !searchOnly || name.startsWith("search.");
70
+ });
71
+ document.tools = Object.fromEntries(filteredEntries);
72
+ if (document.intent?.allowed_tools) {
73
+ const allowed = new Set(Object.keys(document.tools));
74
+ document.intent.allowed_tools = document.intent.allowed_tools.filter((tool) => allowed.has(tool));
75
+ }
76
+ }
77
+ function assertEvidenceRequired(document) {
78
+ for (const [name, entry] of Object.entries(document.tools)) {
79
+ if (entry.side_effecting && !entry.evidence_preset) {
80
+ throw new Error(`side-effecting tool "${name}" must declare evidence_preset`);
81
+ }
82
+ }
83
+ }
84
+ function applyGuardrailLayer(document, layer) {
85
+ if (layer.default_deny !== undefined) {
86
+ document.default_deny = mergeStricterDefaultDeny(document.default_deny, layer.default_deny);
87
+ }
88
+ if (layer.tools) {
89
+ for (const [toolName, patch] of Object.entries(layer.tools)) {
90
+ const existing = document.tools[toolName];
91
+ if (existing) {
92
+ document.tools[toolName] = mergeToolEntry(existing, patch);
93
+ }
94
+ }
95
+ }
96
+ if (layer.intent) {
97
+ document.intent = {
98
+ ...document.intent,
99
+ ...layer.intent,
100
+ ...(layer.intent.allowed_tools
101
+ ? {
102
+ allowed_tools: layer.intent.allowed_tools,
103
+ }
104
+ : {}),
105
+ ...(layer.intent.budget
106
+ ? {
107
+ budget: {
108
+ ...document.intent?.budget,
109
+ ...layer.intent.budget,
110
+ },
111
+ }
112
+ : {}),
113
+ ...(layer.intent.policy_binding
114
+ ? {
115
+ policy_binding: {
116
+ ...document.intent?.policy_binding,
117
+ ...layer.intent.policy_binding,
118
+ },
119
+ }
120
+ : {}),
121
+ };
122
+ }
123
+ if (layer.caps?.sideEffectingMaxSpendCents !== undefined) {
124
+ const cents = layer.caps.sideEffectingMaxSpendCents;
125
+ for (const [toolName, entry] of Object.entries(document.tools)) {
126
+ if (entry.side_effecting) {
127
+ document.tools[toolName] = mergeToolEntry(entry, { max_spend_cents: cents });
128
+ }
129
+ }
130
+ }
131
+ if (layer.caps?.budgetMaxSpendUsd !== undefined) {
132
+ document.intent = {
133
+ ...document.intent,
134
+ budget: mergeBudgetCaps(document.intent?.budget, layer.caps.budgetMaxSpendUsd),
135
+ };
136
+ }
137
+ if (layer.filters?.readOnly || layer.filters?.readOnlySearch) {
138
+ applyReadOnlyFilter(document, Boolean(layer.filters.readOnlySearch));
139
+ }
140
+ if (layer.requireEvidence) {
141
+ assertEvidenceRequired(document);
142
+ }
143
+ }
144
+ /** Stack a domain document with one or more guardrail layers (same-tenant compose, not org inheritance). */
145
+ export function composePolicyLayers(domainDocument, ...layers) {
146
+ const composed = cloneDocument(domainDocument);
147
+ for (const layer of layers) {
148
+ applyGuardrailLayer(composed, layer);
149
+ }
150
+ assertEvidenceRequired(composed);
151
+ return composed;
152
+ }
153
+ /** True when a bundled preset is composed from domain + guardrails layers. */
154
+ export function isLayeredPolicyPreset(presetId) {
155
+ return LAYERED_POLICY_PRESET_IDS.includes(presetId.trim());
156
+ }
157
+ function guardrailsFileName(presetId) {
158
+ return `default-${presetId}.yaml`;
159
+ }
160
+ function deepMergeRecord(base, patch) {
161
+ const result = { ...base };
162
+ for (const [key, patchValue] of Object.entries(patch)) {
163
+ const baseValue = result[key];
164
+ if (baseValue &&
165
+ patchValue &&
166
+ typeof baseValue === "object" &&
167
+ typeof patchValue === "object" &&
168
+ !Array.isArray(baseValue) &&
169
+ !Array.isArray(patchValue)) {
170
+ result[key] = deepMergeRecord(baseValue, patchValue);
171
+ }
172
+ else {
173
+ result[key] = patchValue;
174
+ }
175
+ }
176
+ return result;
177
+ }
178
+ /** Merge domain and guardrail YAML objects (bundled preset file generation). */
179
+ export function composePolicyPresetLayers(domain, guardrails) {
180
+ return deepMergeRecord(domain, guardrails);
181
+ }
182
+ /** Default bundled guardrail layers for a vertical preset id. */
183
+ export function bundledDefaultGuardrails(presetId) {
184
+ return [guardrailLayerFromDocument(loadBundledDefaultGuardrailsDocument(presetId))];
185
+ }
186
+ /** Compose the shipped default for a vertical preset (domain + bundled guardrails). */
187
+ export function composeBundledPresetDefault(presetId) {
188
+ return composePolicyLayers(parsePaybondPolicyDocumentV1(loadBundledDomainDocument(presetId)), ...bundledDefaultGuardrails(presetId));
189
+ }
190
+ /** Load and compose a layered vertical preset (domain + guardrails YAML files). */
191
+ export function composeLayeredPolicyPresetDocument(presetId) {
192
+ const domain = loadBundledDomainDocument(presetId);
193
+ const guardrails = loadBundledDefaultGuardrailsDocument(presetId);
194
+ return composePolicyPresetLayers(domain, guardrails);
195
+ }
196
+ /** Compare composed layered presets with bundled flat preset files (tests). */
197
+ export function assertLayeredPresetMatchesFlat(presetId) {
198
+ if (!isLayeredPolicyPreset(presetId)) {
199
+ return;
200
+ }
201
+ const composed = composeLayeredPolicyPresetDocument(presetId);
202
+ const flatPath = resolvePolicyPresetPath(presetId);
203
+ const flat = parsePolicyDocumentText(readPolicyPresetYaml(presetId), flatPath);
204
+ if (JSON.stringify(normalizePolicyPresetDocument(composed)) !==
205
+ JSON.stringify(normalizePolicyPresetDocument(flat))) {
206
+ throw new Error(`composed preset ${presetId} does not match flat bundled file`);
207
+ }
208
+ }
209
+ function normalizePolicyPresetDocument(document) {
210
+ const tools = document.tools;
211
+ const normalizedTools = tools && typeof tools === "object" && !Array.isArray(tools)
212
+ ? Object.fromEntries(Object.entries(tools)
213
+ .sort(([left], [right]) => left.localeCompare(right))
214
+ .map(([name, entry]) => [
215
+ name,
216
+ entry && typeof entry === "object" && !Array.isArray(entry)
217
+ ? Object.fromEntries(Object.entries(entry).sort(([left], [right]) => left.localeCompare(right)))
218
+ : entry,
219
+ ]))
220
+ : tools;
221
+ const intent = document.intent;
222
+ const normalizedIntent = intent && typeof intent === "object" && !Array.isArray(intent)
223
+ ? {
224
+ ...intent,
225
+ ...(Array.isArray(intent.allowed_tools)
226
+ ? {
227
+ allowed_tools: [
228
+ ...intent.allowed_tools,
229
+ ].sort(),
230
+ }
231
+ : {}),
232
+ }
233
+ : intent;
234
+ return {
235
+ ...document,
236
+ ...(normalizedTools !== undefined ? { tools: normalizedTools } : {}),
237
+ ...(normalizedIntent !== undefined ? { intent: normalizedIntent } : {}),
238
+ };
239
+ }
240
+ export { readPresetLayerYaml } from "./layers-io.js";
@@ -0,0 +1,7 @@
1
+ import type { PaybondPolicyDocumentV1 } from "./schema.js";
2
+ /** Serialize a validated v1 policy document to Gateway-compatible JSON dict form. */
3
+ export declare function policyDocumentToDict(document: PaybondPolicyDocumentV1): Record<string, unknown>;
4
+ /** Return `sha256:<hex>` for the canonical JSON encoding of a v1 policy document. */
5
+ export declare function canonicalPolicyDocumentDigest(document: PaybondPolicyDocumentV1): string;
6
+ /** Human-readable policy version label (`{name}@{digest_short}`). */
7
+ export declare function policyVersionLabel(name: string, digest: string): string;
@@ -0,0 +1,75 @@
1
+ import { createHash } from "node:crypto";
2
+ /** Serialize a validated v1 policy document to Gateway-compatible JSON dict form. */
3
+ export function policyDocumentToDict(document) {
4
+ const tools = Object.fromEntries(Object.entries(document.tools).map(([toolName, entry]) => [
5
+ toolName,
6
+ {
7
+ side_effecting: entry.side_effecting,
8
+ ...(entry.max_spend_cents !== undefined ? { max_spend_cents: entry.max_spend_cents } : {}),
9
+ ...(entry.spend_from_args !== undefined ? { spend_from_args: entry.spend_from_args } : {}),
10
+ ...(entry.evidence_preset !== undefined ? { evidence_preset: entry.evidence_preset } : {}),
11
+ ...(entry.vendor_pack !== undefined ? { vendor_pack: entry.vendor_pack } : {}),
12
+ ...(entry.operation !== undefined ? { operation: entry.operation } : {}),
13
+ },
14
+ ]));
15
+ const payload = {
16
+ version: document.version,
17
+ name: document.name,
18
+ default_deny: document.default_deny,
19
+ tools,
20
+ };
21
+ if (document.intent) {
22
+ const intent = {};
23
+ if (document.intent.policy_binding) {
24
+ const binding = {
25
+ template_id: document.intent.policy_binding.template_id,
26
+ };
27
+ if (document.intent.policy_binding.version_seq !== undefined) {
28
+ binding.version_seq = document.intent.policy_binding.version_seq;
29
+ }
30
+ if (document.intent.policy_binding.head_digest !== undefined) {
31
+ binding.head_digest = document.intent.policy_binding.head_digest;
32
+ }
33
+ intent.policy_binding = binding;
34
+ }
35
+ if (document.intent.budget) {
36
+ intent.budget = document.intent.budget;
37
+ }
38
+ if (document.intent.allowed_tools?.length) {
39
+ intent.allowed_tools = document.intent.allowed_tools;
40
+ }
41
+ if (Object.keys(intent).length > 0) {
42
+ payload.intent = intent;
43
+ }
44
+ }
45
+ return payload;
46
+ }
47
+ function canonicalizeJson(value) {
48
+ if (Array.isArray(value)) {
49
+ return value.map(canonicalizeJson);
50
+ }
51
+ if (value && typeof value === "object") {
52
+ const row = value;
53
+ const out = {};
54
+ for (const key of Object.keys(row).sort()) {
55
+ out[key] = canonicalizeJson(row[key]);
56
+ }
57
+ return out;
58
+ }
59
+ return value;
60
+ }
61
+ /** Return `sha256:<hex>` for the canonical JSON encoding of a v1 policy document. */
62
+ export function canonicalPolicyDocumentDigest(document) {
63
+ const wire = policyDocumentToDict(document);
64
+ const text = JSON.stringify(canonicalizeJson(wire));
65
+ const hash = createHash("sha256").update(text, "utf8").digest("hex");
66
+ return `sha256:${hash}`;
67
+ }
68
+ /** Human-readable policy version label (`{name}@{digest_short}`). */
69
+ export function policyVersionLabel(name, digest) {
70
+ const trimmed = digest.trim();
71
+ const short = trimmed.startsWith("sha256:") && trimmed.length >= 15
72
+ ? trimmed.slice(7, 15)
73
+ : trimmed.slice(0, 8);
74
+ return `${name}@${short}`;
75
+ }
@@ -0,0 +1,15 @@
1
+ import { type PaybondPolicyDocumentV1 } from "./schema.js";
2
+ /** Travel booking domain: hotel booking + read-only web search. */
3
+ export declare function travel(): PaybondPolicyDocumentV1;
4
+ /** Shopping domain: checkout + product search. */
5
+ export declare function shopping(): PaybondPolicyDocumentV1;
6
+ /** SaaS domain: seat provisioning + plan listing. */
7
+ export declare function saas(): PaybondPolicyDocumentV1;
8
+ /** AWS operator domain: EC2 start + describe. */
9
+ export declare function aws(): PaybondPolicyDocumentV1;
10
+ export declare const domain: {
11
+ readonly travel: typeof travel;
12
+ readonly shopping: typeof shopping;
13
+ readonly saas: typeof saas;
14
+ readonly aws: typeof aws;
15
+ };
@@ -0,0 +1,28 @@
1
+ import { parsePaybondPolicyDocumentV1, } from "./schema.js";
2
+ import { loadBundledDomainDocument } from "./layers-io.js";
3
+ const LAYERED_POLICY_PRESET_IDS = ["travel", "shopping", "saas", "aws"];
4
+ function loadDomain(presetId) {
5
+ return parsePaybondPolicyDocumentV1(loadBundledDomainDocument(presetId));
6
+ }
7
+ /** Travel booking domain: hotel booking + read-only web search. */
8
+ export function travel() {
9
+ return loadDomain("travel");
10
+ }
11
+ /** Shopping domain: checkout + product search. */
12
+ export function shopping() {
13
+ return loadDomain("shopping");
14
+ }
15
+ /** SaaS domain: seat provisioning + plan listing. */
16
+ export function saas() {
17
+ return loadDomain("saas");
18
+ }
19
+ /** AWS operator domain: EC2 start + describe. */
20
+ export function aws() {
21
+ return loadDomain("aws");
22
+ }
23
+ export const domain = {
24
+ travel,
25
+ shopping,
26
+ saas,
27
+ aws,
28
+ };