failproofai 1.0.7-beta.1 → 1.0.7
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.
- package/.next/standalone/.next/BUILD_ID +1 -1
- package/.next/standalone/.next/build-manifest.json +3 -3
- package/.next/standalone/.next/prerender-manifest.json +4 -4
- package/.next/standalone/.next/required-server-files.json +1 -1
- package/.next/standalone/.next/server/app/_global-error/page/server-reference-manifest.json +1 -1
- package/.next/standalone/.next/server/app/_global-error/page.js +4 -4
- package/.next/standalone/.next/server/app/_global-error/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/_global-error.html +1 -1
- package/.next/standalone/.next/server/app/_global-error.rsc +7 -7
- package/.next/standalone/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +6 -6
- package/.next/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +7 -7
- package/.next/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/_not-found/page/server-reference-manifest.json +1 -1
- package/.next/standalone/.next/server/app/_not-found/page.js +4 -4
- package/.next/standalone/.next/server/app/_not-found/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/_not-found.html +1 -1
- package/.next/standalone/.next/server/app/_not-found.rsc +15 -15
- package/.next/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +15 -15
- package/.next/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +14 -14
- package/.next/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
- package/.next/standalone/.next/server/app/api/audit/invite/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/audit/run/route.js +7 -8
- package/.next/standalone/.next/server/app/api/audit/run/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/audit/status/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/auth/login-request/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/auth/login-verify/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/auth/logout/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/auth/status/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/download/[project]/[session]/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/audit/page/server-reference-manifest.json +2 -2
- package/.next/standalone/.next/server/app/audit/page.js +5 -7
- package/.next/standalone/.next/server/app/audit/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/audit/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/index.html +1 -1
- package/.next/standalone/.next/server/app/index.rsc +15 -15
- package/.next/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +14 -14
- package/.next/standalone/.next/server/app/index.segments/_full.segment.rsc +15 -15
- package/.next/standalone/.next/server/app/index.segments/_tree.segment.rsc +2 -2
- package/.next/standalone/.next/server/app/page/server-reference-manifest.json +1 -1
- package/.next/standalone/.next/server/app/page.js +6 -6
- package/.next/standalone/.next/server/app/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/policies/page/server-reference-manifest.json +14 -14
- package/.next/standalone/.next/server/app/policies/page.js +11 -13
- package/.next/standalone/.next/server/app/policies/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/policies/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/project/[name]/page/server-reference-manifest.json +1 -1
- package/.next/standalone/.next/server/app/project/[name]/page.js +7 -8
- package/.next/standalone/.next/server/app/project/[name]/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/project/[name]/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/project/[name]/session/[sessionId]/page/react-loadable-manifest.json +2 -2
- package/.next/standalone/.next/server/app/project/[name]/session/[sessionId]/page/server-reference-manifest.json +2 -2
- package/.next/standalone/.next/server/app/project/[name]/session/[sessionId]/page.js +7 -7
- package/.next/standalone/.next/server/app/project/[name]/session/[sessionId]/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/project/[name]/session/[sessionId]/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/projects/page/server-reference-manifest.json +1 -1
- package/.next/standalone/.next/server/app/projects/page.js +6 -7
- package/.next/standalone/.next/server/app/projects/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/projects/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/settings/page/server-reference-manifest.json +8 -41
- package/.next/standalone/.next/server/app/settings/page.js +9 -12
- package/.next/standalone/.next/server/app/settings/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/settings/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/chunks/{[externals]__1j-zsg5._.js → [externals]__1_bftcl._.js} +1 -1
- package/.next/standalone/.next/server/chunks/{[externals]__19_pzeq._.js → [externals]__1msfs-h._.js} +1 -1
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__0o07qi9._.js +1 -1
- package/.next/standalone/.next/server/chunks/{[root-of-the-server]__1bf34x4._.js → [root-of-the-server]__1_r2rbg._.js} +7 -5
- package/.next/standalone/.next/server/chunks/_09dz7xv._.js +21 -21
- package/.next/standalone/.next/server/chunks/_0tovk6q._.js +1 -1
- package/.next/standalone/.next/server/chunks/_0trp3yc._.js +1 -1
- package/.next/standalone/.next/server/chunks/{_1q5i8mb._.js → _1c3k-8x._.js} +2 -2
- package/.next/standalone/.next/server/chunks/_1ek68ln._.js +16 -16
- package/.next/standalone/.next/server/chunks/node_modules_posthog-node_dist_entrypoints_index_node_mjs_09z9-p7._.js +1 -1
- package/.next/standalone/.next/server/chunks/package_json_[json]_cjs_1nxcc4v._.js +1 -1
- package/.next/standalone/.next/server/chunks/src_hooks_0iu54mz._.js +3 -0
- package/.next/standalone/.next/server/chunks/src_hooks_custom-hooks-loader_ts_0lnb3n3._.js +2 -4
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0-_ki57._.js +4 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__013jr2b._.js +4 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__01wy8d-._.js +4 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__02npjtd._.js +4 -0
- package/.next/standalone/.next/server/chunks/ssr/{[root-of-the-server]__0yxwl6j._.js → [root-of-the-server]__0bd3mje._.js} +2 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0cg-bgc._.js +5 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0cpu_mj._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/{[root-of-the-server]__1mf3zp6._.js → [root-of-the-server]__0cxe_2_._.js} +3 -3
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0da85px._.js +4 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0ftmoxc._.js +4 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0p-5p8u._.js +4 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0u3w0ll._.js +22 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__17d_ffl._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__19d9tgz._.js +5 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1ctpynv._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1jiwfsj._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1p2otjt._.js +4 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1phc187._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/_06imw3p._.js +5 -0
- package/.next/standalone/.next/server/chunks/ssr/_08x1r5t._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/{_1w_5l7t._.js → _0h_douw._.js} +1 -1
- package/.next/standalone/.next/server/chunks/ssr/{_214wgrp._.js → _1-i_gzc._.js} +2 -2
- package/.next/standalone/.next/server/chunks/ssr/{_0bn2oo8._.js → _166t73i._.js} +1 -1
- package/.next/standalone/.next/server/chunks/ssr/{_1q46vxx._.js → _1_qswah._.js} +2 -2
- package/.next/standalone/.next/server/chunks/ssr/{_1gb0ifp._.js → _1es2j7i._.js} +5 -5
- package/.next/standalone/.next/server/chunks/ssr/_1u8-lu2._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/_1zopuov._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/_next-internal_server_app_policies_page_actions_1sp2-yo.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/app_audit__components_audit-dashboard_tsx_0p9ud47._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/app_global-error_tsx_1kp6l3x._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/app_policies_hooks-client_tsx_19dqvpc._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/app_settings_settings-client_tsx_20lq-mq._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/{node_modules_next_dist_18_d8l1._.js → node_modules_next_dist_0drixxt._.js} +4 -4
- package/.next/standalone/.next/server/chunks/ssr/src_hooks_1cv9_c4._.js +10 -0
- package/.next/standalone/.next/server/chunks/ssr/src_hooks_builtin-policies_ts_09j2ndl._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/src_hooks_fp-home_ts_0je3xkv._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/src_hooks_pack-cli_ts_0t7me65._.js +1 -1
- package/.next/standalone/.next/server/middleware-build-manifest.js +3 -3
- package/.next/standalone/.next/server/pages/404.html +1 -1
- package/.next/standalone/.next/server/pages/500.html +1 -1
- package/.next/standalone/.next/server/server-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/server-reference-manifest.json +23 -56
- package/.next/standalone/.next/static/chunks/094xgi4owxaqf.js +1 -0
- package/.next/standalone/.next/static/chunks/0__8a7m868fvf.js +1 -0
- package/.next/standalone/.next/static/chunks/{12tvm75t5ffui.js → 0o6qlkgubtoex.js} +1 -1
- package/.next/standalone/.next/static/chunks/13i7-9is-vhys.js +1 -0
- package/.next/standalone/.next/static/chunks/1rz20_pz828f3.js +6 -0
- package/.next/standalone/.next/static/chunks/2k9f4tyv04809.css +1 -0
- package/.next/standalone/.next/static/chunks/{0vmd180qfntfb.js → 2klitrtzpaoe0.js} +1 -1
- package/.next/standalone/.next/static/chunks/{258668t68du6b.js → 2mdh397ghgnvv.js} +1 -1
- package/.next/standalone/.next/static/chunks/2rshywgeqsyzk.css +2 -0
- package/.next/standalone/.next/static/chunks/3pzx4chkhko9k.js +1 -0
- package/.next/standalone/.next/static/chunks/{0qrbdkv9qmvli.js → 3rh5o7e16irrm.js} +1 -1
- package/.next/standalone/.next/static/chunks/{29fql3nbnfc9q.js → 43ufqrz8qo3h-.js} +1 -1
- package/.next/standalone/SECURITY.md +53 -0
- package/.next/standalone/app/actions/pack-actions.ts +0 -12
- package/.next/standalone/app/policies/hooks-client.tsx +0 -9
- package/.next/standalone/app/settings/page.tsx +1 -20
- package/.next/standalone/app/settings/settings-client.tsx +1 -27
- package/.next/standalone/app/settings/settings.css +0 -79
- package/.next/standalone/package.json +9 -9
- package/.next/standalone/sdk/python/skill/SKILL.md +60 -14
- package/.next/standalone/sdk/python/skill/agents/openai.yaml +2 -1
- package/.next/standalone/sdk/python/skill/references/evaluator.md +255 -0
- package/.next/standalone/sdk/python/skill/references/events.md +17 -8
- package/.next/standalone/sdk/python/skill/references/frameworks.md +3 -0
- package/.next/standalone/sdk/python/skill/references/install.md +3 -0
- package/.next/standalone/sdk/python/skill/references/integration.md +6 -2
- package/.next/standalone/sdk/python/skill/references/typescript.md +568 -0
- package/.next/standalone/sdk/typescript/CHANGELOG.md +133 -0
- package/.next/standalone/sdk/typescript/LICENSE +42 -0
- package/.next/standalone/sdk/typescript/README.md +552 -0
- package/.next/standalone/sdk/typescript/eslint.config.mjs +59 -0
- package/.next/standalone/sdk/typescript/examples/research-agent.ts +197 -0
- package/.next/standalone/sdk/typescript/integration/ai.test.ts +920 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/ai-4/agent.ts +337 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/ai-4/package-lock.json +261 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/ai-4/package.json +16 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/ai-4/surfaces.ts +605 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/ai-4/tsconfig.json +12 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/ai-4/tsconfig.surfaces.json +4 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/ai-5/agent.ts +342 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/ai-5/package-lock.json +156 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/ai-5/package.json +16 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/ai-5/surfaces.ts +628 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/ai-5/tsconfig.json +12 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/ai-5/tsconfig.surfaces.json +4 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/ai-6/agent.ts +346 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/ai-6/package-lock.json +156 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/ai-6/package.json +13 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/ai-6/surfaces.ts +651 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/ai-6/tsconfig.json +12 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/ai-6/tsconfig.surfaces.json +4 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/ai-7/agent.ts +350 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/ai-7/package-lock.json +153 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/ai-7/package.json +13 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/ai-7/surfaces.ts +651 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/ai-7/tsconfig.json +12 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/ai-7/tsconfig.surfaces.json +4 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/langchain-0.3/agent.ts +623 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/langchain-0.3/package-lock.json +344 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/langchain-0.3/package.json +19 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/langchain-0.3/tsconfig.json +12 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/langchain-1/agent-v1.ts +99 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/langchain-1/agent.ts +623 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/langchain-1/package-lock.json +336 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/langchain-1/package.json +15 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/langchain-1/tsconfig.json +12 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/langchain-dup-core/agent.ts +96 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/langchain-dup-core/package-lock.json +441 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/langchain-dup-core/package.json +19 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/langchain-dup-core/tsconfig.json +12 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/langchain-dup-core/vendor/lc-weather-provider/index.cjs +53 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/langchain-dup-core/vendor/lc-weather-provider/index.mjs +55 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/langchain-dup-core/vendor/lc-weather-provider/package.json +18 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/llamaindex-0.11/agent.ts +659 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/llamaindex-0.11/package-lock.json +635 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/llamaindex-0.11/package.json +15 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/llamaindex-0.11/tsconfig.json +12 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/llamaindex-0.12/agent.ts +659 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/llamaindex-0.12/package-lock.json +553 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/llamaindex-0.12/package.json +15 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/llamaindex-0.12/tsconfig.json +12 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/mastra-0/agent.ts +877 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/mastra-0/mcp-server.mjs +66 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/mastra-0/package-lock.json +6797 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/mastra-0/package.json +24 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/mastra-0/tsconfig.json +12 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/mastra-1/agent.ts +872 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/mastra-1/mcp-server.mjs +66 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/mastra-1/package-lock.json +2540 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/mastra-1/package.json +15 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/mastra-1/tsconfig.json +12 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/nextjs/app/actions.ts +18 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/nextjs/app/api/ai/route.ts +42 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/nextjs/app/api/edge/route.ts +29 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/nextjs/app/api/langgraph/route.ts +21 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/nextjs/app/api/llamaindex/route.ts +11 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/nextjs/app/api/mastra/route.ts +19 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/nextjs/app/api/status/route.ts +7 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/nextjs/app/layout.tsx +9 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/nextjs/app/page.tsx +15 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/nextjs/instrumentation.ts +15 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/nextjs/lib/ai.ts +61 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/nextjs/lib/langgraph.ts +68 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/nextjs/lib/llamaindex.ts +98 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/nextjs/lib/mastra.ts +90 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/nextjs/next.config.ts +52 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/nextjs/package-lock.json +4343 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/nextjs/package.json +28 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/runtimes/agent.ts +51 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/runtimes/deno-npm.ts +76 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/runtimes/package-lock.json +484 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/runtimes/package.json +15 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/types/agent.ts +79 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/types/package-lock.json +740 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/types/package.json +11 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/vanilla/agent.ts +197 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/vanilla/package-lock.json +70 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/vanilla/package.json +12 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/vanilla/tsconfig.json +12 -0
- package/.next/standalone/sdk/typescript/integration/global-setup.ts +29 -0
- package/.next/standalone/sdk/typescript/integration/harness.ts +451 -0
- package/.next/standalone/sdk/typescript/integration/langchain.test.ts +682 -0
- package/.next/standalone/sdk/typescript/integration/llamaindex.test.ts +709 -0
- package/.next/standalone/sdk/typescript/integration/mastra-coverage.test.ts +386 -0
- package/.next/standalone/sdk/typescript/integration/mastra.test.ts +311 -0
- package/.next/standalone/sdk/typescript/integration/nextjs.test.ts +341 -0
- package/.next/standalone/sdk/typescript/integration/runtime-parity.ts +180 -0
- package/.next/standalone/sdk/typescript/integration/runtimes.bun.test.ts +15 -0
- package/.next/standalone/sdk/typescript/integration/runtimes.core.test.ts +113 -0
- package/.next/standalone/sdk/typescript/integration/runtimes.deno.test.ts +19 -0
- package/.next/standalone/sdk/typescript/integration/types.test.ts +141 -0
- package/.next/standalone/sdk/typescript/integration/vanilla.test.ts +255 -0
- package/.next/standalone/sdk/typescript/package-lock.json +2640 -0
- package/.next/standalone/sdk/typescript/package.json +401 -0
- package/.next/standalone/sdk/typescript/scripts/finalize-build.mjs +123 -0
- package/.next/standalone/sdk/typescript/scripts/release.mjs +177 -0
- package/.next/standalone/sdk/typescript/src/clock.ts +58 -0
- package/.next/standalone/sdk/typescript/src/context.ts +214 -0
- package/.next/standalone/sdk/typescript/src/edge/adapter.ts +18 -0
- package/.next/standalone/sdk/typescript/src/edge/ai.ts +116 -0
- package/.next/standalone/sdk/typescript/src/edge/index.ts +238 -0
- package/.next/standalone/sdk/typescript/src/edge/langchain.ts +18 -0
- package/.next/standalone/sdk/typescript/src/edge/llamaindex.ts +12 -0
- package/.next/standalone/sdk/typescript/src/edge/mastra.ts +17 -0
- package/.next/standalone/sdk/typescript/src/edge/notice.ts +33 -0
- package/.next/standalone/sdk/typescript/src/environment.ts +75 -0
- package/.next/standalone/sdk/typescript/src/evaluator/authoring.ts +480 -0
- package/.next/standalone/sdk/typescript/src/evaluator/cli.ts +96 -0
- package/.next/standalone/sdk/typescript/src/evaluator/client.ts +421 -0
- package/.next/standalone/sdk/typescript/src/evaluator/expression.ts +1292 -0
- package/.next/standalone/sdk/typescript/src/evaluator/index.ts +144 -0
- package/.next/standalone/sdk/typescript/src/evaluator/protocol.ts +747 -0
- package/.next/standalone/sdk/typescript/src/evaluator/runtime.ts +930 -0
- package/.next/standalone/sdk/typescript/src/evaluator/sandbox-worker.ts +171 -0
- package/.next/standalone/sdk/typescript/src/evaluator/source-limits.ts +27 -0
- package/.next/standalone/sdk/typescript/src/evaluator/source.ts +509 -0
- package/.next/standalone/sdk/typescript/src/events.ts +879 -0
- package/.next/standalone/sdk/typescript/src/exit.ts +117 -0
- package/.next/standalone/sdk/typescript/src/index.ts +186 -0
- package/.next/standalone/sdk/typescript/src/integrations/ai.ts +1566 -0
- package/.next/standalone/sdk/typescript/src/integrations/compat.ts +322 -0
- package/.next/standalone/sdk/typescript/src/integrations/core.ts +1321 -0
- package/.next/standalone/sdk/typescript/src/integrations/index.ts +355 -0
- package/.next/standalone/sdk/typescript/src/integrations/langchain.ts +2340 -0
- package/.next/standalone/sdk/typescript/src/integrations/llamaindex.ts +2111 -0
- package/.next/standalone/sdk/typescript/src/integrations/mastra.ts +1802 -0
- package/.next/standalone/sdk/typescript/src/logger.ts +98 -0
- package/.next/standalone/sdk/typescript/src/next.ts +115 -0
- package/.next/standalone/sdk/typescript/src/node-require.ts +446 -0
- package/.next/standalone/sdk/typescript/src/redact.ts +305 -0
- package/.next/standalone/sdk/typescript/src/resolver.ts +120 -0
- package/.next/standalone/sdk/typescript/src/runtime.ts +29 -0
- package/.next/standalone/sdk/typescript/src/schema.ts +410 -0
- package/.next/standalone/sdk/typescript/src/scopes.ts +701 -0
- package/.next/standalone/sdk/typescript/src/shared.ts +33 -0
- package/.next/standalone/sdk/typescript/src/version.ts +5 -0
- package/.next/standalone/sdk/typescript/src/writer.ts +934 -0
- package/.next/standalone/sdk/typescript/test/adapters.test.ts +397 -0
- package/.next/standalone/sdk/typescript/test/ai.test.ts +1076 -0
- package/.next/standalone/sdk/typescript/test/copies.test.ts +204 -0
- package/.next/standalone/sdk/typescript/test/edge.test.ts +183 -0
- package/.next/standalone/sdk/typescript/test/evaluator-client.test.ts +234 -0
- package/.next/standalone/sdk/typescript/test/evaluator-protocol.test.ts +225 -0
- package/.next/standalone/sdk/typescript/test/events.test.ts +193 -0
- package/.next/standalone/sdk/typescript/test/expression.test.ts +181 -0
- package/.next/standalone/sdk/typescript/test/global-setup.ts +26 -0
- package/.next/standalone/sdk/typescript/test/helpers.ts +130 -0
- package/.next/standalone/sdk/typescript/test/integrations.test.ts +369 -0
- package/.next/standalone/sdk/typescript/test/langchain-copies.test.ts +204 -0
- package/.next/standalone/sdk/typescript/test/langchain.test.ts +999 -0
- package/.next/standalone/sdk/typescript/test/llamaindex.test.ts +1760 -0
- package/.next/standalone/sdk/typescript/test/mastra-coverage.test.ts +501 -0
- package/.next/standalone/sdk/typescript/test/mastra-lifecycle.test.ts +479 -0
- package/.next/standalone/sdk/typescript/test/mastra.test.ts +285 -0
- package/.next/standalone/sdk/typescript/test/next.test.ts +109 -0
- package/.next/standalone/sdk/typescript/test/packaging.test.ts +312 -0
- package/.next/standalone/sdk/typescript/test/redaction.test.ts +171 -0
- package/.next/standalone/sdk/typescript/test/runtimes.test.ts +101 -0
- package/.next/standalone/sdk/typescript/test/sandbox.test.ts +189 -0
- package/.next/standalone/sdk/typescript/test/scopes.test.ts +271 -0
- package/.next/standalone/sdk/typescript/test/setup.ts +19 -0
- package/.next/standalone/sdk/typescript/test/skill-snippets.test.ts +73 -0
- package/.next/standalone/sdk/typescript/test/spool-contract.test.ts +124 -0
- package/.next/standalone/sdk/typescript/test/tracker-bounds.test.ts +191 -0
- package/.next/standalone/sdk/typescript/test/wire-format.test.ts +214 -0
- package/.next/standalone/sdk/typescript/test/writer.test.ts +407 -0
- package/.next/standalone/sdk/typescript/tsconfig.build.json +15 -0
- package/.next/standalone/sdk/typescript/tsconfig.cjs.json +19 -0
- package/.next/standalone/sdk/typescript/tsconfig.json +28 -0
- package/.next/standalone/sdk/typescript/vitest.config.ts +33 -0
- package/.next/standalone/sdk/typescript/vitest.integration.config.ts +23 -0
- package/.next/standalone/server.js +1 -1
- package/bin/failproofai.mjs +2 -115
- package/dist/cli.mjs +6538 -13686
- package/dist/index.js +1 -19
- package/dist/worker.mjs +2085 -8012
- package/package.json +9 -9
- package/pi-extension/index.ts +0 -11
- package/scripts/build-policy-pack.mjs +2 -39
- package/src/hooks/builtin-policies.ts +3 -21
- package/src/hooks/cloud-enrollment-cli.ts +1 -1
- package/src/hooks/cloud-managed-policies.ts +0 -22
- package/src/hooks/custom-hooks-loader.ts +7 -45
- package/src/hooks/custom-hooks-registry.ts +1 -45
- package/src/hooks/first-run-gate.ts +0 -5
- package/src/hooks/fp-home.ts +0 -23
- package/src/hooks/handler.ts +6 -265
- package/src/hooks/hook-activity-store.ts +1 -105
- package/src/hooks/hook-telemetry.ts +0 -41
- package/src/hooks/loader-utils.ts +0 -6
- package/src/hooks/pack-cli.ts +17 -278
- package/src/hooks/pack-manifest.ts +7 -479
- package/src/hooks/pack-store.ts +10 -156
- package/src/hooks/policy-catalog.ts +0 -65
- package/src/hooks/policy-evaluator.ts +796 -940
- package/src/hooks/policy-registry.ts +0 -25
- package/src/hooks/policy-types.ts +0 -126
- package/src/hooks/worker-server.ts +26 -119
- package/src/index.ts +0 -6
- package/.next/standalone/.next/server/chunks/src_hooks_01frwmb._.js +0 -5
- package/.next/standalone/.next/server/chunks/src_hooks_18qtd42._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__01bmjsj._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__04usis8._.js +0 -4
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__056wjo4._.js +0 -4
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__059yza8._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0eip4_k._.js +0 -22
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0n0xg95._.js +0 -4
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0qcb0mg._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0qxnccm._.js +0 -5
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0rwtwpm._.js +0 -4
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0s_yomn._.js +0 -4
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0soxz2z._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0yrsbd_._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__11mayhe._.js +0 -4
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__13d-wb6._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1dinjii._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1pprgri._.js +0 -4
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1q4p5b8._.js +0 -4
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1qiz0e4._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/_042cgl1._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/_0bqoto4._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/_0uyu3jf._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/_1feuvhb._.js +0 -5
- package/.next/standalone/.next/server/chunks/ssr/app_actions_get-scheduled-audit_ts_0ei9sni._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/app_settings_02tf1h4._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/node_modules_next_dist_0w6mzq5._.js +0 -151
- package/.next/standalone/.next/server/chunks/ssr/src_hooks_095a_79._.js +0 -5
- package/.next/standalone/.next/server/chunks/ssr/src_hooks_15t8kqj._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/src_hooks_18k8rl0._.js +0 -12
- package/.next/standalone/.next/server/chunks/ssr/src_hooks_1fm2w5z._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/src_hooks_1j0zy3v._.js +0 -3
- package/.next/standalone/.next/static/chunks/0cd-_8-c-m1ea.js +0 -6
- package/.next/standalone/.next/static/chunks/0uldbut9y2-e8.js +0 -1
- package/.next/standalone/.next/static/chunks/1u5zsejmgrir_.js +0 -1
- package/.next/standalone/.next/static/chunks/285spx855h_3r.css +0 -2
- package/.next/standalone/.next/static/chunks/2qv4hshejedtx.css +0 -1
- package/.next/standalone/.next/static/chunks/2vkvu9-opa_1z.js +0 -1
- package/.next/standalone/.next/static/chunks/37lhv7wa3ywt6.js +0 -1
- package/.next/standalone/app/actions/get-jev-config.ts +0 -409
- package/.next/standalone/app/actions/update-jev-config.ts +0 -420
- package/.next/standalone/app/components/jev-notices.tsx +0 -96
- package/.next/standalone/app/settings/jev-panel.tsx +0 -469
- package/src/hooks/effective-reviewers.ts +0 -79
- package/src/hooks/jev-activity.ts +0 -385
- package/src/hooks/jev-cli.ts +0 -1193
- package/src/hooks/policy-authority.ts +0 -333
- package/src/hooks/policy-reviewability.ts +0 -229
- package/src/hooks/semantic/combine.ts +0 -541
- package/src/hooks/semantic/compile.ts +0 -176
- package/src/hooks/semantic/decide.ts +0 -392
- package/src/hooks/semantic/envelope.ts +0 -1296
- package/src/hooks/semantic/evaluator.ts +0 -547
- package/src/hooks/semantic/facts.ts +0 -292
- package/src/hooks/semantic/intent.ts +0 -1190
- package/src/hooks/semantic/jev-client.ts +0 -643
- package/src/hooks/semantic/jev-config.ts +0 -594
- package/src/hooks/semantic/jev-review.ts +0 -374
- package/src/hooks/semantic/jev-stats.ts +0 -289
- package/src/hooks/semantic/jev-throttle.ts +0 -421
- package/src/hooks/semantic/pack-policies.ts +0 -251
- package/src/hooks/semantic/policies.ts +0 -596
- package/src/hooks/semantic/precondition-names.ts +0 -60
- package/src/hooks/semantic/preconditions.ts +0 -58
- package/src/hooks/semantic/redact.ts +0 -2910
- package/src/hooks/semantic/types.ts +0 -145
- package/src/hooks/semver-precedence.ts +0 -128
- /package/.next/standalone/.next/static/{T8YAYM9h_64fKv705vug7 → PgeWCHmyVbjRznv2VO7KF}/_buildManifest.js +0 -0
- /package/.next/standalone/.next/static/{T8YAYM9h_64fKv705vug7 → PgeWCHmyVbjRznv2VO7KF}/_clientMiddlewareManifest.js +0 -0
- /package/.next/standalone/.next/static/{T8YAYM9h_64fKv705vug7 → PgeWCHmyVbjRznv2VO7KF}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,701 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scopes: `session()`, `agent()`, `toolCall()`.
|
|
3
|
+
*
|
|
4
|
+
* These are the ergonomic surface over `failproofai.event.*`. Each binds run
|
|
5
|
+
* identity onto the `AsyncLocalStorage` in `context.ts` so that everything
|
|
6
|
+
* emitted inside — including code that has never heard of the SDK's identity
|
|
7
|
+
* options — lands on the right session and agent.
|
|
8
|
+
*
|
|
9
|
+
* ## Two forms, and why
|
|
10
|
+
*
|
|
11
|
+
* **Callback (preferred).** `await agent("planner", fn)` runs `fn` inside
|
|
12
|
+
* `AsyncLocalStorage.run()`. Nothing to unwind: the binding exists for exactly
|
|
13
|
+
* the async subtree the callback creates and disappears with it, so the
|
|
14
|
+
* entire class of "a scope was entered here and exited over there" bugs is
|
|
15
|
+
* unreachable. Use this unless you cannot.
|
|
16
|
+
*
|
|
17
|
+
* **`using` (escape hatch).** `using span = agent.open("planner")` binds with
|
|
18
|
+
* `enterWith` and unwinds in `[Symbol.dispose]`. Needed when the work is not a
|
|
19
|
+
* single function — a scope opened in a constructor and closed in a teardown,
|
|
20
|
+
* a block that straddles an existing control structure. It carries the same
|
|
21
|
+
* hazard Python's context managers do: a scope opened in one async context and
|
|
22
|
+
* disposed in another leaves its frame bound where it was set. `context.ts`
|
|
23
|
+
* warns once when it detects that.
|
|
24
|
+
*
|
|
25
|
+
* Both forms emit byte-identical events; the only difference is who unwinds.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { randomUUID } from "node:crypto";
|
|
29
|
+
|
|
30
|
+
import * as context from "./context.js";
|
|
31
|
+
import { nowMicros } from "./clock.js";
|
|
32
|
+
import { ProcessExit, onProcessExit } from "./exit.js";
|
|
33
|
+
import type { Identity, Store } from "./context.js";
|
|
34
|
+
import { runtime } from "./runtime.js";
|
|
35
|
+
|
|
36
|
+
// `Symbol.dispose` is only defined from Node 20.5 / V8 11.7. Defining it here
|
|
37
|
+
// means `using` works on every runtime this package supports, and assigning it
|
|
38
|
+
// when it already exists is a no-op rather than a conflict.
|
|
39
|
+
interface SymbolConstructorWithDispose {
|
|
40
|
+
dispose?: symbol;
|
|
41
|
+
asyncDispose?: symbol;
|
|
42
|
+
}
|
|
43
|
+
const symbolShim = Symbol as unknown as SymbolConstructorWithDispose;
|
|
44
|
+
symbolShim.dispose ??= Symbol.for("nodejs.dispose");
|
|
45
|
+
symbolShim.asyncDispose ??= Symbol.for("nodejs.asyncDispose");
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* `AUTO` — infer the enclosing agent from the context stack (the default);
|
|
49
|
+
* `null` — force a root span, emitting no `parentId` at all;
|
|
50
|
+
* a string — use this id verbatim.
|
|
51
|
+
*
|
|
52
|
+
* `parentId` has three states and `null` is a meaningful one of them, so the
|
|
53
|
+
* default cannot be `null`.
|
|
54
|
+
*/
|
|
55
|
+
export const AUTO = Symbol.for("failproofai.AUTO");
|
|
56
|
+
export type ParentId = string | null | typeof AUTO;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* True for a cancellation rather than a failure.
|
|
60
|
+
*
|
|
61
|
+
* A cancellation must not emit an `error` event, or every cancelled run
|
|
62
|
+
* pollutes the Errors surface. JavaScript has no `CancelledError`; the
|
|
63
|
+
* equivalent is the `AbortError` an `AbortSignal` produces, which both
|
|
64
|
+
* `DOMException` and Node's own APIs raise under that name (`ABORT_ERR` is the
|
|
65
|
+
* `code` Node sets on its own variant).
|
|
66
|
+
*/
|
|
67
|
+
export function isCancellation(error: unknown): boolean {
|
|
68
|
+
if (typeof error !== "object" || error === null) return false;
|
|
69
|
+
const named = error as { name?: unknown; code?: unknown };
|
|
70
|
+
return named.name === "AbortError" || named.code === "ABORT_ERR";
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function errorName(error: unknown): string {
|
|
74
|
+
if (error instanceof Error) {
|
|
75
|
+
// Several SDKs subclass Error without setting `name` — openai's
|
|
76
|
+
// `BadRequestError` reports `name === "Error"` — so the class, which is
|
|
77
|
+
// what anyone reading the Errors surface is looking for, would be lost.
|
|
78
|
+
const own = error.name || "Error";
|
|
79
|
+
const ctor = (error as { constructor?: { name?: unknown } }).constructor?.name;
|
|
80
|
+
if (own === "Error" && typeof ctor === "string" && ctor !== "" && ctor !== "Error") return ctor;
|
|
81
|
+
return own;
|
|
82
|
+
}
|
|
83
|
+
return typeof error;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// ---------------------------------------------------------------------------
|
|
87
|
+
// what is still open when the process exits
|
|
88
|
+
// ---------------------------------------------------------------------------
|
|
89
|
+
|
|
90
|
+
/** One open scope; `close` emits its closing event with a `ProcessExit`. */
|
|
91
|
+
interface OpenScope {
|
|
92
|
+
closed: boolean;
|
|
93
|
+
opened: number;
|
|
94
|
+
close(exitCode: number): void;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const openScopes = new Set<OpenScope>();
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Track a scope until it settles. Returns a guard the settle path calls: it
|
|
101
|
+
* answers false when the exit closer already ended the scope, so the event is
|
|
102
|
+
* never emitted twice.
|
|
103
|
+
*/
|
|
104
|
+
function trackOpen(close: (exitCode: number) => void): { settle(): boolean } {
|
|
105
|
+
const entry: OpenScope = { closed: false, opened: nowMicros(), close };
|
|
106
|
+
openScopes.add(entry);
|
|
107
|
+
return {
|
|
108
|
+
settle(): boolean {
|
|
109
|
+
openScopes.delete(entry);
|
|
110
|
+
if (entry.closed) return false;
|
|
111
|
+
entry.closed = true;
|
|
112
|
+
return true;
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
onProcessExit(() =>
|
|
118
|
+
[...openScopes].map((entry) => ({
|
|
119
|
+
opened: entry.opened,
|
|
120
|
+
close(exitCode: number): void {
|
|
121
|
+
openScopes.delete(entry);
|
|
122
|
+
if (entry.closed) return;
|
|
123
|
+
entry.closed = true;
|
|
124
|
+
entry.close(exitCode);
|
|
125
|
+
},
|
|
126
|
+
})),
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
function errorMessage(error: unknown): string {
|
|
130
|
+
if (error instanceof Error) return error.message;
|
|
131
|
+
return String(error);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function describe(error: unknown): string {
|
|
135
|
+
const text = errorMessage(error);
|
|
136
|
+
const name = errorName(error);
|
|
137
|
+
return text ? `${name}: ${text}` : name;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function stackOf(error: unknown): string | undefined {
|
|
141
|
+
return error instanceof Error ? (error.stack ?? undefined) : undefined;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function isThenable(value: unknown): value is PromiseLike<unknown> {
|
|
145
|
+
return (
|
|
146
|
+
typeof value === "object" &&
|
|
147
|
+
value !== null &&
|
|
148
|
+
typeof (value as PromiseLike<unknown>).then === "function"
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Run `body`, then `settle`, preserving whether `body` was sync or async.
|
|
154
|
+
*
|
|
155
|
+
* A scope whose callback is synchronous must stay synchronous: wrapping every
|
|
156
|
+
* body in a promise would make `session(() => 1)` return a `Promise<number>`,
|
|
157
|
+
* which breaks the one case where a caller genuinely cannot await — a
|
|
158
|
+
* constructor, a synchronous framework hook, an `EventEmitter` listener.
|
|
159
|
+
*/
|
|
160
|
+
function settleWith<T>(
|
|
161
|
+
body: () => T,
|
|
162
|
+
onSuccess: (value: Awaited<T>) => void,
|
|
163
|
+
onFailure: (error: unknown) => void,
|
|
164
|
+
): T {
|
|
165
|
+
let result: T;
|
|
166
|
+
try {
|
|
167
|
+
result = body();
|
|
168
|
+
} catch (error) {
|
|
169
|
+
onFailure(error);
|
|
170
|
+
throw error;
|
|
171
|
+
}
|
|
172
|
+
if (isThenable(result)) {
|
|
173
|
+
return (result as PromiseLike<Awaited<T>>).then(
|
|
174
|
+
(value) => {
|
|
175
|
+
onSuccess(value);
|
|
176
|
+
return value;
|
|
177
|
+
},
|
|
178
|
+
(error: unknown) => {
|
|
179
|
+
onFailure(error);
|
|
180
|
+
throw error;
|
|
181
|
+
},
|
|
182
|
+
) as T;
|
|
183
|
+
}
|
|
184
|
+
onSuccess(result as Awaited<T>);
|
|
185
|
+
return result;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// ---------------------------------------------------------------------------
|
|
189
|
+
// session
|
|
190
|
+
// ---------------------------------------------------------------------------
|
|
191
|
+
|
|
192
|
+
export interface SessionOptions {
|
|
193
|
+
sessionId?: string;
|
|
194
|
+
agentId?: string;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** The handle `session.open()` returns. Disposing it unwinds the binding. */
|
|
198
|
+
export class SessionScope {
|
|
199
|
+
readonly id: string;
|
|
200
|
+
private readonly previous: Store;
|
|
201
|
+
private readonly entered: Store;
|
|
202
|
+
private readonly agentId: string | undefined;
|
|
203
|
+
private disposed = false;
|
|
204
|
+
|
|
205
|
+
constructor(options: SessionOptions = {}) {
|
|
206
|
+
const store = context.snapshot();
|
|
207
|
+
this.id = options.sessionId ?? store.sessionId ?? randomUUID().replace(/-/g, "");
|
|
208
|
+
let next = context.withSessionBound(store, this.id);
|
|
209
|
+
this.agentId = options.agentId;
|
|
210
|
+
if (options.agentId !== undefined) next = context.withAgentPushed(next, options.agentId);
|
|
211
|
+
this.entered = next;
|
|
212
|
+
this.previous = context.enterWith(next);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
dispose(): void {
|
|
216
|
+
if (this.disposed) return;
|
|
217
|
+
this.disposed = true;
|
|
218
|
+
// Unwind unconditionally: a scope that leaks an agent frame misattributes
|
|
219
|
+
// every later event in the process. When the current store is not the one
|
|
220
|
+
// we entered, something below us bound its own and never unwound, or we are
|
|
221
|
+
// being disposed from a different async context — repair by value rather
|
|
222
|
+
// than stamping the caller's context with a store from somewhere else.
|
|
223
|
+
const now = context.snapshot();
|
|
224
|
+
if (now === this.entered) {
|
|
225
|
+
context.enterWith(this.previous);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
context.noteCrossContextExit();
|
|
229
|
+
let repaired = now;
|
|
230
|
+
if (this.agentId !== undefined) repaired = context.withAgentDiscarded(repaired, this.agentId);
|
|
231
|
+
context.enterWith({ sessionId: this.previous.sessionId, agentStack: repaired.agentStack });
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
[Symbol.dispose](): void {
|
|
235
|
+
this.dispose();
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export interface SessionFn {
|
|
240
|
+
/** Bind a session for the duration of `body`. Emits no events — identity only. */
|
|
241
|
+
<T>(body: (sessionId: string) => T): T;
|
|
242
|
+
<T>(options: SessionOptions, body: (sessionId: string) => T): T;
|
|
243
|
+
/** The `using` form: `using s = failproofai.session.open()`. */
|
|
244
|
+
open(options?: SessionOptions): SessionScope;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Bind a session id (and optionally an agent id) for the enclosing work.
|
|
249
|
+
*
|
|
250
|
+
* await failproofai.session(async (sid) => {
|
|
251
|
+
* failproofai.event.agentStart({ agentId: "main", goal: "..." });
|
|
252
|
+
* });
|
|
253
|
+
*
|
|
254
|
+
* Emits **no events** — it is identity only. `agent()` is what brackets a run
|
|
255
|
+
* with `agent_start`/`agent_end`.
|
|
256
|
+
*
|
|
257
|
+
* An omitted `sessionId` reuses an already-bound session if there is one, and
|
|
258
|
+
* otherwise generates one. That inheritance is what lets a nested scope stay
|
|
259
|
+
* inside one run instead of splitting it into two sessions.
|
|
260
|
+
*/
|
|
261
|
+
const sessionImpl = (<T>(
|
|
262
|
+
first: SessionOptions | ((sessionId: string) => T),
|
|
263
|
+
second?: (sessionId: string) => T,
|
|
264
|
+
): T => {
|
|
265
|
+
const options = typeof first === "function" ? {} : first;
|
|
266
|
+
const body = typeof first === "function" ? first : second!;
|
|
267
|
+
const store = context.snapshot();
|
|
268
|
+
const id = options.sessionId ?? store.sessionId ?? randomUUID().replace(/-/g, "");
|
|
269
|
+
let next = context.withSessionBound(store, id);
|
|
270
|
+
if (options.agentId !== undefined) next = context.withAgentPushed(next, options.agentId);
|
|
271
|
+
return context.runWith(next, () => body(id));
|
|
272
|
+
}) as SessionFn;
|
|
273
|
+
|
|
274
|
+
sessionImpl.open = (options: SessionOptions = {}): SessionScope => new SessionScope(options);
|
|
275
|
+
|
|
276
|
+
export const session: SessionFn = sessionImpl;
|
|
277
|
+
|
|
278
|
+
// ---------------------------------------------------------------------------
|
|
279
|
+
// agent
|
|
280
|
+
// ---------------------------------------------------------------------------
|
|
281
|
+
|
|
282
|
+
export interface AgentOptions {
|
|
283
|
+
sessionId?: string;
|
|
284
|
+
goal?: string;
|
|
285
|
+
parentId?: ParentId;
|
|
286
|
+
/** The `outcome` on `agent_end` when the block completes normally. */
|
|
287
|
+
outcome?: string;
|
|
288
|
+
summary?: string;
|
|
289
|
+
/** Any other key is attached to `agent_start` only. */
|
|
290
|
+
[field: string]: unknown;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function resolveAgentEntry(
|
|
294
|
+
agentId: string,
|
|
295
|
+
options: AgentOptions,
|
|
296
|
+
): { sid: string; parent: string | null | undefined; next: Store } {
|
|
297
|
+
const store = context.snapshot();
|
|
298
|
+
const sid = options.sessionId ?? store.sessionId ?? randomUUID().replace(/-/g, "");
|
|
299
|
+
|
|
300
|
+
let parent: string | null | undefined;
|
|
301
|
+
if (options.parentId === undefined || options.parentId === AUTO) {
|
|
302
|
+
// Only inherit within the SAME session. An explicit `sessionId` that
|
|
303
|
+
// differs from the ambient one is the documented way to start a NEW run,
|
|
304
|
+
// and the enclosing agent does not exist in it — the span tree is keyed by
|
|
305
|
+
// session, so the child would render as a root with a dangling parent, or
|
|
306
|
+
// get grafted onto whatever agent in its own session happened to share the
|
|
307
|
+
// id. The ordinary long-lived-server shape reaches it directly:
|
|
308
|
+
//
|
|
309
|
+
// await agent("server", { sessionId: "boot" }, async () => {
|
|
310
|
+
// for (const rid of requests) {
|
|
311
|
+
// await agent("handler", { sessionId: rid }, ...); // parent="server"
|
|
312
|
+
// }
|
|
313
|
+
// });
|
|
314
|
+
//
|
|
315
|
+
// A caller who genuinely wants a cross-session link can still pass
|
|
316
|
+
// `parentId` explicitly.
|
|
317
|
+
const currentAgent =
|
|
318
|
+
store.agentStack.length > 0 ? store.agentStack[store.agentStack.length - 1]! : null;
|
|
319
|
+
parent = sid === store.sessionId ? currentAgent : null;
|
|
320
|
+
} else {
|
|
321
|
+
parent = options.parentId;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const next = context.withAgentPushed(context.withSessionBound(store, sid), agentId);
|
|
325
|
+
return { sid, parent, next };
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function agentStartFields(options: AgentOptions): Record<string, unknown> {
|
|
329
|
+
const { sessionId, goal, parentId, outcome, summary, ...fields } = options;
|
|
330
|
+
void sessionId;
|
|
331
|
+
void goal;
|
|
332
|
+
void parentId;
|
|
333
|
+
void outcome;
|
|
334
|
+
void summary;
|
|
335
|
+
return fields;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function emitAgentEnd(
|
|
339
|
+
sid: string,
|
|
340
|
+
agentId: string,
|
|
341
|
+
options: AgentOptions,
|
|
342
|
+
error: unknown,
|
|
343
|
+
hadError: boolean,
|
|
344
|
+
): void {
|
|
345
|
+
let outcome: string;
|
|
346
|
+
if (!hadError) {
|
|
347
|
+
outcome = options.outcome ?? "success";
|
|
348
|
+
} else if (isCancellation(error)) {
|
|
349
|
+
outcome = "cancelled";
|
|
350
|
+
} else {
|
|
351
|
+
outcome = "failed";
|
|
352
|
+
// `error` strictly BEFORE `agent_end`, because the dashboard closes the
|
|
353
|
+
// agent span at `agent_end` and anything after it is attributed to nothing.
|
|
354
|
+
runtime.event.error({
|
|
355
|
+
sessionId: sid,
|
|
356
|
+
agentId,
|
|
357
|
+
errorType: errorName(error),
|
|
358
|
+
message: errorMessage(error),
|
|
359
|
+
// A ProcessExit's stack is the SDK's own exit path — noise, not a cause.
|
|
360
|
+
traceback: error instanceof ProcessExit ? undefined : stackOf(error),
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
// The literal is `"failed"`, never `"failure"` — only
|
|
364
|
+
// `error|failed|timeout|rejected` count as a failure server-side.
|
|
365
|
+
runtime.event.agentEnd({
|
|
366
|
+
sessionId: sid,
|
|
367
|
+
agentId,
|
|
368
|
+
outcome,
|
|
369
|
+
summary: options.summary,
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/** The handle `agent.open()` returns. Disposing it emits `agent_end`. */
|
|
374
|
+
export class AgentScope {
|
|
375
|
+
readonly agentId: string;
|
|
376
|
+
readonly sessionId: string;
|
|
377
|
+
readonly identity: Identity;
|
|
378
|
+
private readonly options: AgentOptions;
|
|
379
|
+
private readonly previous: Store;
|
|
380
|
+
private readonly entered: Store;
|
|
381
|
+
private disposed = false;
|
|
382
|
+
/** Set by `fail()` so a `using` block can still record a failure. */
|
|
383
|
+
private failure: { error: unknown } | null = null;
|
|
384
|
+
|
|
385
|
+
constructor(agentId = "main", options: AgentOptions = {}) {
|
|
386
|
+
this.agentId = agentId;
|
|
387
|
+
this.options = options;
|
|
388
|
+
const { sid, parent, next } = resolveAgentEntry(agentId, options);
|
|
389
|
+
this.sessionId = sid;
|
|
390
|
+
this.entered = next;
|
|
391
|
+
this.previous = context.enterWith(next);
|
|
392
|
+
try {
|
|
393
|
+
runtime.event.agentStart({
|
|
394
|
+
sessionId: sid,
|
|
395
|
+
agentId,
|
|
396
|
+
goal: options.goal,
|
|
397
|
+
parentId: parent,
|
|
398
|
+
...agentStartFields(options),
|
|
399
|
+
});
|
|
400
|
+
} catch (error) {
|
|
401
|
+
// A rejected `agent_start` (a reserved extra, say) must not leave a
|
|
402
|
+
// half-entered scope behind: the disposer never runs if the constructor
|
|
403
|
+
// throws.
|
|
404
|
+
this.unwind();
|
|
405
|
+
throw error;
|
|
406
|
+
}
|
|
407
|
+
this.identity = context.current();
|
|
408
|
+
this.open = trackOpen((exitCode) =>
|
|
409
|
+
emitAgentEnd(
|
|
410
|
+
this.sessionId,
|
|
411
|
+
this.agentId,
|
|
412
|
+
this.options,
|
|
413
|
+
new ProcessExit(exitCode, `agent ${JSON.stringify(this.agentId)}`),
|
|
414
|
+
true,
|
|
415
|
+
),
|
|
416
|
+
);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
private readonly open: { settle(): boolean };
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Record that this span failed. `using` has no exception channel to a
|
|
423
|
+
* disposer, so a caller who catches inside the block tells us here.
|
|
424
|
+
*/
|
|
425
|
+
fail(error: unknown): void {
|
|
426
|
+
this.failure = { error };
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
dispose(): void {
|
|
430
|
+
if (this.disposed) return;
|
|
431
|
+
this.disposed = true;
|
|
432
|
+
try {
|
|
433
|
+
if (!this.open.settle()) return;
|
|
434
|
+
emitAgentEnd(
|
|
435
|
+
this.sessionId,
|
|
436
|
+
this.agentId,
|
|
437
|
+
this.options,
|
|
438
|
+
this.failure?.error,
|
|
439
|
+
this.failure !== null,
|
|
440
|
+
);
|
|
441
|
+
} finally {
|
|
442
|
+
// Unwound in a `finally` so the stack is intact even if emission itself
|
|
443
|
+
// blew up. A leaked frame is worse than a lost event.
|
|
444
|
+
this.unwind();
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
private unwind(): void {
|
|
449
|
+
const now = context.snapshot();
|
|
450
|
+
if (now === this.entered) {
|
|
451
|
+
context.enterWith(this.previous);
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
context.noteCrossContextExit();
|
|
455
|
+
context.enterWith({
|
|
456
|
+
sessionId: this.previous.sessionId,
|
|
457
|
+
agentStack: context.withAgentDiscarded(now, this.agentId).agentStack,
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
[Symbol.dispose](): void {
|
|
462
|
+
this.dispose();
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
export interface AgentFn {
|
|
467
|
+
<T>(agentId: string, body: (identity: Identity) => T): T;
|
|
468
|
+
<T>(agentId: string, options: AgentOptions, body: (identity: Identity) => T): T;
|
|
469
|
+
/** The `using` form: `using span = failproofai.agent.open("planner")`. */
|
|
470
|
+
open(agentId?: string, options?: AgentOptions): AgentScope;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* Bracket a run (or a sub-run) with `agent_start` / `agent_end`.
|
|
475
|
+
*
|
|
476
|
+
* await failproofai.agent("planner", { goal: question }, async () => { ... });
|
|
477
|
+
*
|
|
478
|
+
* Keep `agentId` low-cardinality (a node/role name, never a UUID): it is a
|
|
479
|
+
* `LowCardinality(String)` column and the primary facet across every session.
|
|
480
|
+
*
|
|
481
|
+
* Extra keys are attached to `agent_start` only; `agent_end` carries `outcome`
|
|
482
|
+
* and `summary`.
|
|
483
|
+
*
|
|
484
|
+
* Exit semantics, which are the whole point:
|
|
485
|
+
*
|
|
486
|
+
* | thrown | events | outcome |
|
|
487
|
+
* |-------------------------|-------------------|---------------|
|
|
488
|
+
* | nothing | `agent_end` | `options.outcome` |
|
|
489
|
+
* | any error | `error`, then end | `"failed"` |
|
|
490
|
+
* | an `AbortError` | `agent_end` only | `"cancelled"` |
|
|
491
|
+
*
|
|
492
|
+
* The error is always re-thrown.
|
|
493
|
+
*/
|
|
494
|
+
const agentImpl = (<T>(
|
|
495
|
+
agentId: string,
|
|
496
|
+
second: AgentOptions | ((identity: Identity) => T),
|
|
497
|
+
third?: (identity: Identity) => T,
|
|
498
|
+
): T => {
|
|
499
|
+
const options = typeof second === "function" ? {} : second;
|
|
500
|
+
const body = typeof second === "function" ? second : third!;
|
|
501
|
+
const { sid, parent, next } = resolveAgentEntry(agentId, options);
|
|
502
|
+
|
|
503
|
+
return context.runWith(next, () => {
|
|
504
|
+
runtime.event.agentStart({
|
|
505
|
+
sessionId: sid,
|
|
506
|
+
agentId,
|
|
507
|
+
goal: options.goal,
|
|
508
|
+
parentId: parent,
|
|
509
|
+
...agentStartFields(options),
|
|
510
|
+
});
|
|
511
|
+
const open = trackOpen((exitCode) =>
|
|
512
|
+
emitAgentEnd(sid, agentId, options, new ProcessExit(exitCode, `agent ${JSON.stringify(agentId)}`), true),
|
|
513
|
+
);
|
|
514
|
+
return settleWith(
|
|
515
|
+
() => body(context.current()),
|
|
516
|
+
() => {
|
|
517
|
+
if (open.settle()) emitAgentEnd(sid, agentId, options, undefined, false);
|
|
518
|
+
},
|
|
519
|
+
(error) => {
|
|
520
|
+
if (open.settle()) emitAgentEnd(sid, agentId, options, error, true);
|
|
521
|
+
},
|
|
522
|
+
);
|
|
523
|
+
});
|
|
524
|
+
}) as AgentFn;
|
|
525
|
+
|
|
526
|
+
agentImpl.open = (agentId = "main", options: AgentOptions = {}): AgentScope =>
|
|
527
|
+
new AgentScope(agentId, options);
|
|
528
|
+
|
|
529
|
+
export const agent: AgentFn = agentImpl;
|
|
530
|
+
|
|
531
|
+
// ---------------------------------------------------------------------------
|
|
532
|
+
// toolCall
|
|
533
|
+
// ---------------------------------------------------------------------------
|
|
534
|
+
|
|
535
|
+
/** The handle a `toolCall` body receives. Set `.output`; read `.id`. */
|
|
536
|
+
export class ToolCall {
|
|
537
|
+
readonly id: string;
|
|
538
|
+
/**
|
|
539
|
+
* What the tool produced. When the body returns a value and this was never
|
|
540
|
+
* set, the returned value is recorded instead — so the common
|
|
541
|
+
* `await toolCall("search", { input }, () => search(q))` needs no assignment.
|
|
542
|
+
*/
|
|
543
|
+
output: unknown = undefined;
|
|
544
|
+
private assigned = false;
|
|
545
|
+
|
|
546
|
+
constructor(toolCallId: string) {
|
|
547
|
+
this.id = toolCallId;
|
|
548
|
+
// A plain field would make "never set" and "set to undefined"
|
|
549
|
+
// indistinguishable, and the difference decides whether the body's return
|
|
550
|
+
// value is used.
|
|
551
|
+
let stored: unknown;
|
|
552
|
+
Object.defineProperty(this, "output", {
|
|
553
|
+
get: () => stored,
|
|
554
|
+
set: (value: unknown) => {
|
|
555
|
+
stored = value;
|
|
556
|
+
this.assigned = true;
|
|
557
|
+
},
|
|
558
|
+
enumerable: true,
|
|
559
|
+
configurable: true,
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
/** True once `.output` has been assigned, whatever it was assigned to. */
|
|
564
|
+
get outputAssigned(): boolean {
|
|
565
|
+
return this.assigned;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
export interface ToolCallOptions {
|
|
570
|
+
toolCallId?: string;
|
|
571
|
+
input?: Record<string, unknown> | null;
|
|
572
|
+
/** Any other key is attached to `tool_use` only. */
|
|
573
|
+
[field: string]: unknown;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
function toolUseFields(options: ToolCallOptions): Record<string, unknown> {
|
|
577
|
+
const { toolCallId, input, ...fields } = options;
|
|
578
|
+
void toolCallId;
|
|
579
|
+
void input;
|
|
580
|
+
return fields;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
/** The handle `toolCall.open()` returns. Disposing it emits `tool_result`. */
|
|
584
|
+
export class ToolCallScope {
|
|
585
|
+
readonly call: ToolCall;
|
|
586
|
+
private readonly toolName: string;
|
|
587
|
+
private readonly sid: string | null;
|
|
588
|
+
private readonly aid: string;
|
|
589
|
+
private disposed = false;
|
|
590
|
+
private failure: { error: unknown } | null = null;
|
|
591
|
+
|
|
592
|
+
constructor(toolName: string, options: ToolCallOptions = {}) {
|
|
593
|
+
this.toolName = toolName;
|
|
594
|
+
// Resolve once, at entry: a tool that opens its own scope inside must not
|
|
595
|
+
// make the closing `tool_result` land on a different agent id.
|
|
596
|
+
this.sid = context.sessionId();
|
|
597
|
+
this.aid = context.agentId();
|
|
598
|
+
this.call = new ToolCall(options.toolCallId ?? randomUUID().replace(/-/g, ""));
|
|
599
|
+
runtime.event.toolUse({
|
|
600
|
+
sessionId: this.sid,
|
|
601
|
+
agentId: this.aid,
|
|
602
|
+
toolName,
|
|
603
|
+
toolCallId: this.call.id,
|
|
604
|
+
input: options.input,
|
|
605
|
+
...toolUseFields(options),
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
fail(error: unknown): void {
|
|
610
|
+
this.failure = { error };
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
dispose(): void {
|
|
614
|
+
if (this.disposed) return;
|
|
615
|
+
this.disposed = true;
|
|
616
|
+
// A tool still open at exit is closed by the event namespace (exit.ts),
|
|
617
|
+
// which sees every tool_use; its tool_result there makes this a no-op.
|
|
618
|
+
const failed = this.failure !== null && !isCancellation(this.failure.error);
|
|
619
|
+
runtime.event.toolResult({
|
|
620
|
+
sessionId: this.sid,
|
|
621
|
+
agentId: this.aid,
|
|
622
|
+
toolName: this.toolName,
|
|
623
|
+
toolCallId: this.call.id,
|
|
624
|
+
output: this.call.output,
|
|
625
|
+
error: failed ? describe(this.failure!.error) : undefined,
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
[Symbol.dispose](): void {
|
|
630
|
+
this.dispose();
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
export interface ToolCallFn {
|
|
635
|
+
<T>(toolName: string, body: (call: ToolCall) => T): T;
|
|
636
|
+
<T>(toolName: string, options: ToolCallOptions, body: (call: ToolCall) => T): T;
|
|
637
|
+
/** The `using` form: `using t = failproofai.toolCall.open("web_search")`. */
|
|
638
|
+
open(toolName: string, options?: ToolCallOptions): ToolCallScope;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* Bracket a tool invocation with `tool_use` / `tool_result`.
|
|
643
|
+
*
|
|
644
|
+
* const hits = await failproofai.toolCall("web_search", { input: { q } }, () => search(q));
|
|
645
|
+
*
|
|
646
|
+
* `toolCallId` defaults to a fresh uuid. Identity comes from the enclosing
|
|
647
|
+
* scope; if nothing is bound, the underlying `event.toolUse()` throws the usual
|
|
648
|
+
* `TypeError` naming the fix.
|
|
649
|
+
*
|
|
650
|
+
* The body's resolved value is recorded as `output` unless the handle's
|
|
651
|
+
* `.output` was assigned, in which case that wins.
|
|
652
|
+
*
|
|
653
|
+
* On failure this emits `tool_result({ error: "TypeName: msg" })` and **no
|
|
654
|
+
* `error` event**. A tool failure the agent loop catches is not a run-level
|
|
655
|
+
* error, and one that propagates is reported exactly once, by the enclosing
|
|
656
|
+
* `agent()`. Cancellation closes the leaf with no `error` string at all, for
|
|
657
|
+
* the same reason `agent()` does not mark it failed.
|
|
658
|
+
*/
|
|
659
|
+
const toolCallImpl = (<T>(
|
|
660
|
+
toolName: string,
|
|
661
|
+
second: ToolCallOptions | ((call: ToolCall) => T),
|
|
662
|
+
third?: (call: ToolCall) => T,
|
|
663
|
+
): T => {
|
|
664
|
+
const options = typeof second === "function" ? {} : second;
|
|
665
|
+
const body = typeof second === "function" ? second : third!;
|
|
666
|
+
|
|
667
|
+
const sid = context.sessionId();
|
|
668
|
+
const aid = context.agentId();
|
|
669
|
+
const call = new ToolCall(options.toolCallId ?? randomUUID().replace(/-/g, ""));
|
|
670
|
+
|
|
671
|
+
runtime.event.toolUse({
|
|
672
|
+
sessionId: sid,
|
|
673
|
+
agentId: aid,
|
|
674
|
+
toolName,
|
|
675
|
+
toolCallId: call.id,
|
|
676
|
+
input: options.input,
|
|
677
|
+
...toolUseFields(options),
|
|
678
|
+
});
|
|
679
|
+
|
|
680
|
+
const finish = (output: unknown, error: unknown, failed: boolean): void => {
|
|
681
|
+
runtime.event.toolResult({
|
|
682
|
+
sessionId: sid,
|
|
683
|
+
agentId: aid,
|
|
684
|
+
toolName,
|
|
685
|
+
toolCallId: call.id,
|
|
686
|
+
output,
|
|
687
|
+
error: failed && !isCancellation(error) ? describe(error) : undefined,
|
|
688
|
+
});
|
|
689
|
+
};
|
|
690
|
+
|
|
691
|
+
return settleWith(
|
|
692
|
+
() => body(call),
|
|
693
|
+
(value) => finish(call.outputAssigned ? call.output : value, undefined, false),
|
|
694
|
+
(error) => finish(call.outputAssigned ? call.output : undefined, error, true),
|
|
695
|
+
);
|
|
696
|
+
}) as ToolCallFn;
|
|
697
|
+
|
|
698
|
+
toolCallImpl.open = (toolName: string, options: ToolCallOptions = {}): ToolCallScope =>
|
|
699
|
+
new ToolCallScope(toolName, options);
|
|
700
|
+
|
|
701
|
+
export const toolCall: ToolCallFn = toolCallImpl;
|