failproofai 1.0.7-beta.0 → 1.0.7-beta.2
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 +3 -3
- 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.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.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.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.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.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.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.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.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.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 +7 -7
- package/.next/standalone/.next/server/app/settings/page.js +2 -2
- 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/[root-of-the-server]__0l3yhx4._.js +2 -2
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__0o07qi9._.js +1 -1
- 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/package_json_[json]_cjs_1nxcc4v._.js +1 -1
- package/.next/standalone/.next/server/chunks/src_hooks_18qtd42._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__04usis8._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__056wjo4._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/{[root-of-the-server]__1p28m0u._.js → [root-of-the-server]__0l44ual._.js} +2 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0n0xg95._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0rwtwpm._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0s_yomn._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__11mayhe._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1pprgri._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1q4p5b8._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/_042cgl1._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/_08x1r5t._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/_0bqoto4._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/{_0cf1olg._.js → _1mel6y1._.js} +2 -2
- package/.next/standalone/.next/server/chunks/ssr/{_135-c3y._.js → _1v-jvrv._.js} +1 -1
- 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_actions_get-scheduled-audit_ts_0ei9sni._.js +1 -1
- 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 +1 -1
- package/.next/standalone/.next/server/chunks/ssr/app_settings_02tf1h4._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/src_hooks_15t8kqj._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/src_hooks_1fm2w5z._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/src_hooks_1j0zy3v._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/src_hooks_builtin-policies_ts_09j2ndl._.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 +22 -22
- package/.next/standalone/.next/static/chunks/043j99m8ykg__.css +2 -0
- package/.next/standalone/.next/static/chunks/{0289oapk24zql.js → 0fqd7m_u81mi5.js} +1 -1
- package/.next/standalone/.next/static/chunks/{2tqszh84mp_2l.js → 129ag2bw93bdh.js} +1 -1
- package/.next/standalone/.next/static/chunks/{0pyy9m5cm8zku.js → 1qd741hzlmjbo.js} +1 -1
- package/.next/standalone/.next/static/chunks/{3vwnzfx9q80yl.js → 2_pltstd8-xgs.js} +1 -1
- package/.next/standalone/.next/static/chunks/{3vp7c3knkh8mr.js → 2c8j9l6j_b1ci.js} +1 -1
- package/.next/standalone/.next/static/chunks/3-k569wzcli8q.js +1 -0
- package/.next/standalone/.next/static/chunks/{3cdkxrukvlvul.js → 3brze37td_wnc.js} +1 -1
- package/.next/standalone/.next/static/chunks/{3dnd-_29uiaj3.js → 3otmypm6j_xfo.js} +2 -2
- package/.next/standalone/.next/static/chunks/{00i9thnpht4l1.js → 3ugmd_7dyn0id.js} +1 -1
- package/.next/standalone/.next/static/chunks/3yxro_r2_o9ad.js +69 -0
- package/.next/standalone/PROBE-FOLLOWUP.md +186 -0
- package/.next/standalone/app/actions/get-jev-config.ts +38 -23
- package/.next/standalone/app/actions/update-jev-config.ts +1 -1
- package/.next/standalone/app/settings/jev-panel.tsx +33 -29
- package/.next/standalone/package.json +10 -10
- 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 +119 -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 +281 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/ai-4/package.json +13 -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 +168 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/ai-5/package.json +13 -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 +463 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/langchain-0.3/package.json +15 -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 +579 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/langchain-dup-core/package.json +15 -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 +6417 -0
- package/.next/standalone/sdk/typescript/integration/fixtures/mastra-0/package.json +15 -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/README.md +2 -2
- package/dist/cli.mjs +225 -30
- package/dist/worker.mjs +120 -14
- package/package.json +10 -10
- package/scripts/build-policy-pack.mjs +14 -0
- package/src/audit/features.ts +3 -2
- package/src/hooks/builtin-policies.ts +156 -5
- package/src/hooks/jev-cli.ts +57 -1
- package/src/hooks/manager.ts +1 -1
- package/src/hooks/pack-cli.ts +191 -24
- package/src/hooks/pack-store.ts +1 -1
- package/src/hooks/policy-catalog.ts +148 -9
- package/src/hooks/types.ts +1 -1
- package/.next/standalone/.next/static/chunks/15heikmy3yjzc.js +0 -1
- package/.next/standalone/.next/static/chunks/285spx855h_3r.css +0 -2
- package/.next/standalone/.next/static/chunks/2plg9qae1yejv.js +0 -69
- /package/.next/standalone/.next/static/{qbVI48kgBOf9CTOKcFIk2 → gbEOjBgZAxF2UIUwZVHNu}/_buildManifest.js +0 -0
- /package/.next/standalone/.next/static/{qbVI48kgBOf9CTOKcFIk2 → gbEOjBgZAxF2UIUwZVHNu}/_clientMiddlewareManifest.js +0 -0
- /package/.next/standalone/.next/static/{qbVI48kgBOf9CTOKcFIk2 → gbEOjBgZAxF2UIUwZVHNu}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one logging surface for this SDK.
|
|
3
|
+
*
|
|
4
|
+
* Python's SDK reaches for `logging.getLogger(__name__)`, which gives the host
|
|
5
|
+
* application a named, level-filtered, individually-silenceable channel for
|
|
6
|
+
* free. Node has no stdlib equivalent, and this package is contractually
|
|
7
|
+
* zero-dependency, so it cannot pull in `pino` or `debug` — a telemetry library
|
|
8
|
+
* that installs into other people's agent processes must not hand them a
|
|
9
|
+
* dependency they did not choose.
|
|
10
|
+
*
|
|
11
|
+
* So: a minimal level-filtered logger over `console`, with a `setLogger()`
|
|
12
|
+
* escape hatch so a host that already has structured logging can route ours
|
|
13
|
+
* into it rather than having two formats interleaved on stderr.
|
|
14
|
+
*
|
|
15
|
+
* DEFAULT LEVEL IS `warn`, deliberately. Every `logger.warning(...)` in the
|
|
16
|
+
* ported modules marks a condition that silently costs the caller telemetry —
|
|
17
|
+
* a full queue, a dropped event, an unresolvable session. Defaulting to
|
|
18
|
+
* `error` would hide exactly the messages that exist because the failure is
|
|
19
|
+
* otherwise invisible; defaulting to `info` would put startup chatter into
|
|
20
|
+
* somebody's agent output.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
export type LogLevel = "debug" | "info" | "warn" | "error" | "silent";
|
|
24
|
+
|
|
25
|
+
export interface Logger {
|
|
26
|
+
debug(message: string, ...args: unknown[]): void;
|
|
27
|
+
info(message: string, ...args: unknown[]): void;
|
|
28
|
+
warn(message: string, ...args: unknown[]): void;
|
|
29
|
+
error(message: string, ...args: unknown[]): void;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const ORDER: Record<LogLevel, number> = {
|
|
33
|
+
debug: 10,
|
|
34
|
+
info: 20,
|
|
35
|
+
warn: 30,
|
|
36
|
+
error: 40,
|
|
37
|
+
silent: 100,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
function envLevel(): LogLevel {
|
|
41
|
+
const raw = (process.env.FAILPROOFAI_SDK_LOG_LEVEL ?? "").trim().toLowerCase();
|
|
42
|
+
return raw in ORDER ? (raw as LogLevel) : "warn";
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
let level: LogLevel = envLevel();
|
|
46
|
+
let sink: Logger | null = null;
|
|
47
|
+
|
|
48
|
+
/** Route this SDK's log lines into the host's own logger. `null` restores the default. */
|
|
49
|
+
export function setLogger(next: Logger | null): void {
|
|
50
|
+
sink = next;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Override the level. Also readable from `FAILPROOFAI_SDK_LOG_LEVEL`. */
|
|
54
|
+
export function setLogLevel(next: LogLevel): void {
|
|
55
|
+
level = next;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Re-read `FAILPROOFAI_SDK_LOG_LEVEL`. Used by tests that mutate the environment. */
|
|
59
|
+
export function resetLogLevel(): void {
|
|
60
|
+
level = envLevel();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function emit(
|
|
64
|
+
method: "debug" | "info" | "warn" | "error",
|
|
65
|
+
message: string,
|
|
66
|
+
args: unknown[],
|
|
67
|
+
): void {
|
|
68
|
+
if (ORDER[method] < ORDER[level]) return;
|
|
69
|
+
// A logger that throws is a logger that takes the host agent down over a
|
|
70
|
+
// diagnostic. Nothing in this file may do that.
|
|
71
|
+
try {
|
|
72
|
+
if (sink) {
|
|
73
|
+
sink[method](message, ...args);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
// `console.warn`/`console.error` go to stderr, which is where a library's
|
|
77
|
+
// diagnostics belong: stdout is frequently the agent's own protocol channel
|
|
78
|
+
// (an MCP server speaks JSON-RPC over it) and writing there corrupts it.
|
|
79
|
+
const line = `[failproofai-sdk] ${message}`;
|
|
80
|
+
if (method === "warn") console.warn(line, ...args);
|
|
81
|
+
else console.error(line, ...args);
|
|
82
|
+
} catch {
|
|
83
|
+
/* empty */
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export const logger: Logger = {
|
|
88
|
+
debug: (message, ...args) => emit("debug", message, args),
|
|
89
|
+
info: (message, ...args) => emit("info", message, args),
|
|
90
|
+
warn: (message, ...args) => emit("warn", message, args),
|
|
91
|
+
error: (message, ...args) => emit("error", message, args),
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/** `logger.error` plus the error's stack, mirroring Python's `logger.exception`. */
|
|
95
|
+
export function logException(message: string, error: unknown): void {
|
|
96
|
+
const detail = error instanceof Error ? (error.stack ?? error.message) : String(error);
|
|
97
|
+
emit("error", `${message}: ${detail}`, []);
|
|
98
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Next.js support: `withFailproofai(nextConfig)`.
|
|
3
|
+
*
|
|
4
|
+
* ## Why this exists
|
|
5
|
+
*
|
|
6
|
+
* `next build` BUNDLES a server's dependencies into its own output by default,
|
|
7
|
+
* and none of LangChain, Mastra or LlamaIndex is on Next's built-in external
|
|
8
|
+
* list. `instrument()` attaches to the framework copy in `node_modules`; a
|
|
9
|
+
* bundled app runs a different copy, so the adapter reports success and
|
|
10
|
+
* records nothing. (The Vercel AI SDK is unaffected: ai 7 reads its telemetry
|
|
11
|
+
* integrations from a global, and `telemetry()` is passed at the call site.)
|
|
12
|
+
*
|
|
13
|
+
* The cure Next documents for exactly this is `serverExternalPackages`: a
|
|
14
|
+
* package listed there is loaded from `node_modules` at run time, so the copy
|
|
15
|
+
* `instrument()` patched is the copy the routes run. This wrapper adds the
|
|
16
|
+
* packages the adapters need, keeps everything the app already lists, and
|
|
17
|
+
* records what it added so `instrument()` can tell a configured app from an
|
|
18
|
+
* unconfigured one (see `nextExternalsGap` in `integrations/index.ts`).
|
|
19
|
+
*
|
|
20
|
+
* // next.config.ts
|
|
21
|
+
* import { withFailproofai } from "@failproofai/sdk/next";
|
|
22
|
+
* export default withFailproofai({ ...yourConfig });
|
|
23
|
+
*
|
|
24
|
+
* `@failproofai/sdk` itself is on the list for a second reason: bundled, the
|
|
25
|
+
* SDK would be compiled separately into `instrumentation.ts` and into each
|
|
26
|
+
* route, so `instrument()` would configure one copy while the routes record
|
|
27
|
+
* through another.
|
|
28
|
+
*
|
|
29
|
+
* This module runs where `next.config` runs — Node, at build and at server
|
|
30
|
+
* start — and imports nothing, so it is safe to load from any config file.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Packages a Next.js server must load from `node_modules` for `instrument()` to
|
|
35
|
+
* reach them. Listing one the app does not install is harmless: Next only
|
|
36
|
+
* consults the list for imports that actually occur.
|
|
37
|
+
*/
|
|
38
|
+
export const NEXT_EXTERNAL_PACKAGES: readonly string[] = [
|
|
39
|
+
"@failproofai/sdk",
|
|
40
|
+
// LangChain / LangGraph: every run goes through @langchain/core's callback
|
|
41
|
+
// manager, which is what the adapter patches. Listing core is sufficient —
|
|
42
|
+
// a bundled `@langchain/langgraph` importing it still gets the external copy.
|
|
43
|
+
"@langchain/core",
|
|
44
|
+
"@langchain/langgraph",
|
|
45
|
+
"langchain",
|
|
46
|
+
// Mastra: Agent and the workflow engine are patched in @mastra/core.
|
|
47
|
+
"@mastra/core",
|
|
48
|
+
// LlamaIndex: the callback bus lives in @llamaindex/core, and the agent
|
|
49
|
+
// workflow runtime that is patched lives in @llamaindex/workflow.
|
|
50
|
+
"llamaindex",
|
|
51
|
+
"@llamaindex/core",
|
|
52
|
+
"@llamaindex/workflow",
|
|
53
|
+
"@llamaindex/workflow-core",
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The environment variable `withFailproofai` sets when Next evaluates the
|
|
58
|
+
* config: the comma-separated external list, so `instrument()` in the same
|
|
59
|
+
* server process knows the app was configured. Set it yourself (to the
|
|
60
|
+
* packages you listed, or to `1`) if you configure `serverExternalPackages` by
|
|
61
|
+
* hand and want to silence the warning.
|
|
62
|
+
*/
|
|
63
|
+
export const NEXT_EXTERNALS_ENV = "FAILPROOFAI_NEXT_EXTERNALS";
|
|
64
|
+
|
|
65
|
+
type NextConfigObject = Record<string, unknown> & {
|
|
66
|
+
serverExternalPackages?: string[];
|
|
67
|
+
transpilePackages?: string[];
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/** What `withFailproofai` guarantees about the config it returns. */
|
|
71
|
+
export interface WithFailproofaiExternals {
|
|
72
|
+
serverExternalPackages: string[];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Add the packages `instrument()` needs to `serverExternalPackages`.
|
|
77
|
+
*
|
|
78
|
+
* Accepts every form a `next.config` may export: an object, or a function of
|
|
79
|
+
* `(phase, context)` returning one (sync or async). The result has the same
|
|
80
|
+
* shape as the input. Packages the app lists in `transpilePackages` are left
|
|
81
|
+
* out — Next rejects a package that is both — and `instrument()` will warn for
|
|
82
|
+
* the framework instead, which is the honest outcome.
|
|
83
|
+
*/
|
|
84
|
+
export function withFailproofai<A extends unknown[], R>(
|
|
85
|
+
config: (...args: A) => R,
|
|
86
|
+
): (...args: A) => R extends Promise<infer C> ? Promise<C & WithFailproofaiExternals> : R & WithFailproofaiExternals;
|
|
87
|
+
export function withFailproofai<C extends object>(config?: C): C & WithFailproofaiExternals;
|
|
88
|
+
export function withFailproofai(config?: unknown): unknown {
|
|
89
|
+
if (typeof config === "function") {
|
|
90
|
+
const wrapped = (...args: unknown[]): unknown => {
|
|
91
|
+
const produced = (config as (...a: unknown[]) => unknown)(...args);
|
|
92
|
+
return produced instanceof Promise
|
|
93
|
+
? produced.then((value) => apply(value as NextConfigObject))
|
|
94
|
+
: apply(produced as NextConfigObject);
|
|
95
|
+
};
|
|
96
|
+
return wrapped;
|
|
97
|
+
}
|
|
98
|
+
return apply((config ?? {}) as NextConfigObject);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function apply(config: NextConfigObject): NextConfigObject {
|
|
102
|
+
const existing = Array.isArray(config.serverExternalPackages) ? config.serverExternalPackages : [];
|
|
103
|
+
const transpiled = new Set(Array.isArray(config.transpilePackages) ? config.transpilePackages : []);
|
|
104
|
+
const merged = [...new Set([...existing, ...NEXT_EXTERNAL_PACKAGES.filter((p) => !transpiled.has(p))])];
|
|
105
|
+
try {
|
|
106
|
+
// Next evaluates the config inside the server process for `next start` and
|
|
107
|
+
// `next dev`, before `instrumentation.ts` runs — so this reaches
|
|
108
|
+
// `instrument()`. A standalone build does not evaluate it; there
|
|
109
|
+
// `instrument()` reads the resolved config Next stores instead.
|
|
110
|
+
process.env[NEXT_EXTERNALS_ENV] = merged.join(",");
|
|
111
|
+
} catch {
|
|
112
|
+
// An environment that forbids writing env vars loses only the marker.
|
|
113
|
+
}
|
|
114
|
+
return { ...config, serverExternalPackages: merged };
|
|
115
|
+
}
|
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A CommonJS `require` this package can use from either module system.
|
|
3
|
+
*
|
|
4
|
+
* The adapters need three things Node only offers through `require`: reading a
|
|
5
|
+
* framework's `package.json` for its version, asking whether a package
|
|
6
|
+
* resolves at all, and inspecting `require.cache`. Reaching for them the
|
|
7
|
+
* obvious way — `createRequire(import.meta.url)` — compiles under ESM and is a
|
|
8
|
+
* syntax error under CommonJS, so a package that ships both builds cannot use
|
|
9
|
+
* it without a bundler shim. This module has none.
|
|
10
|
+
*
|
|
11
|
+
* The anchor is the **consuming application**, not this file: the frameworks
|
|
12
|
+
* we detect are the application's dependencies, and under pnpm or a workspace
|
|
13
|
+
* this package may sit somewhere that cannot see them at all. Where the
|
|
14
|
+
* application IS has two answers and neither is always right — see `anchors()`.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { existsSync, readFileSync, readdirSync, realpathSync } from "node:fs";
|
|
18
|
+
import { createRequire } from "node:module";
|
|
19
|
+
import { dirname, isAbsolute, join } from "node:path";
|
|
20
|
+
|
|
21
|
+
// `createRequire` wants a file path to resolve relative to; the file need not
|
|
22
|
+
// exist, only its directory is used.
|
|
23
|
+
const requireAt = (dir: string): NodeJS.Require => createRequire(join(dir, "__failproofai_anchor__.js"));
|
|
24
|
+
const appRequire = requireAt(process.cwd());
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The directories to resolve the application's dependencies from, best first.
|
|
28
|
+
*
|
|
29
|
+
* The working directory alone was the first answer, and it is wrong twice: a
|
|
30
|
+
* service started with no working directory set runs from `/`, where nothing
|
|
31
|
+
* resolves and `instrument()` reports it found no framework; and in a monorepo
|
|
32
|
+
* whose root hoists a different `@langchain/core` than the app's own nested
|
|
33
|
+
* one, it resolved the ROOT copy — patched a class the app never loads, and
|
|
34
|
+
* reported success.
|
|
35
|
+
*
|
|
36
|
+
* The entry script's directory is the better anchor whenever the entry is the
|
|
37
|
+
* application's own code. It is not when the entry is a launcher living in
|
|
38
|
+
* `node_modules` (`next start`, a process manager's wrapper): resolving from
|
|
39
|
+
* there finds whatever the launcher's package sits beside, so the working
|
|
40
|
+
* directory keeps precedence in that case. Both are always tried; which one is
|
|
41
|
+
* asked FIRST only matters when they disagree.
|
|
42
|
+
*/
|
|
43
|
+
function anchors(): string[] {
|
|
44
|
+
const cwd = process.cwd();
|
|
45
|
+
const entry = process.argv[1];
|
|
46
|
+
const dirs: string[] = [];
|
|
47
|
+
if (typeof entry === "string" && entry !== "" && isAbsolute(entry)) {
|
|
48
|
+
const dir = dirname(entry);
|
|
49
|
+
const launcher = dir.split(/[\\/]/).includes("node_modules");
|
|
50
|
+
if (launcher) dirs.push(cwd, dir);
|
|
51
|
+
else dirs.push(dir, cwd);
|
|
52
|
+
} else {
|
|
53
|
+
dirs.push(cwd);
|
|
54
|
+
}
|
|
55
|
+
return [...new Set(dirs)];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export const nodeRequire: NodeJS.Require = appRequire;
|
|
59
|
+
|
|
60
|
+
/** Every `require.cache` key currently loaded, for "is this already imported". */
|
|
61
|
+
export function loadedModulePaths(): string[] {
|
|
62
|
+
try {
|
|
63
|
+
return Object.keys(appRequire.cache);
|
|
64
|
+
} catch {
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The resolved filename for `specifier`, or null when it cannot be found. */
|
|
70
|
+
export function resolveFrom(specifier: string): string | null {
|
|
71
|
+
const found: string[] = [];
|
|
72
|
+
for (const dir of anchors()) {
|
|
73
|
+
try {
|
|
74
|
+
const path = requireAt(dir).resolve(specifier);
|
|
75
|
+
if (!found.includes(path)) found.push(path);
|
|
76
|
+
} catch {
|
|
77
|
+
// Either the package is absent from here or its `exports` map does not
|
|
78
|
+
// expose this subpath. Both are ordinary; try the next anchor.
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// A copy something has already `require`d is the one in use, whichever
|
|
82
|
+
// anchor found it.
|
|
83
|
+
return found.find(isRequired) ?? found[0] ?? null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Whether the process entry point is a CommonJS module.
|
|
88
|
+
*
|
|
89
|
+
* `require.main` is the entry module under CommonJS and `undefined` when the
|
|
90
|
+
* entry is an ES module — and the entry's module system decides which copy of
|
|
91
|
+
* a dual-published framework the application's own imports reach. That is the
|
|
92
|
+
* copy an adapter has to patch; see `resolveCopies`.
|
|
93
|
+
*/
|
|
94
|
+
export function entryIsCommonJs(): boolean {
|
|
95
|
+
try {
|
|
96
|
+
return isCommonJsMain(appRequire.main);
|
|
97
|
+
} catch {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Whether the application's own imports of a dual-published framework reach
|
|
104
|
+
* its CommonJS copy — the copy an adapter must patch. See `requireModuleCopies`.
|
|
105
|
+
*
|
|
106
|
+
* Usually that is the entry point's module system. The exception is a server
|
|
107
|
+
* whose entry is a CommonJS LAUNCHER that loads the application's code another
|
|
108
|
+
* way. Next.js is the one that matters: `next start` is a CommonJS script, but
|
|
109
|
+
* every package the server loads from `node_modules` at run time (anything in
|
|
110
|
+
* `serverExternalPackages`) is loaded with `import()` — by Turbopack and by
|
|
111
|
+
* webpack alike — so the application runs the ES-module copies. Reading the
|
|
112
|
+
* launcher as "a CommonJS app" patched the CommonJS copies instead, and
|
|
113
|
+
* `instrument()` in `instrumentation.ts` reported success for LangChain, Mastra
|
|
114
|
+
* and LlamaIndex while recording nothing.
|
|
115
|
+
*
|
|
116
|
+
* Next sets `NEXT_RUNTIME` in its server processes (and inlines it into the
|
|
117
|
+
* bundles it builds), before `instrumentation.ts` runs.
|
|
118
|
+
*/
|
|
119
|
+
export function appImportsReachCommonJs(): boolean {
|
|
120
|
+
if (isNextServer()) return false;
|
|
121
|
+
return entryIsCommonJs();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Running inside a Next.js server process (Node or Edge runtime). */
|
|
125
|
+
export function isNextServer(): boolean {
|
|
126
|
+
try {
|
|
127
|
+
const runtime = process.env.NEXT_RUNTIME;
|
|
128
|
+
return typeof runtime === "string" && runtime !== "";
|
|
129
|
+
} catch {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Whether a `require.main` value names a CommonJS entry module.
|
|
136
|
+
*
|
|
137
|
+
* Node answers `undefined` for an ES-module entry; Deno answers `null`. A bare
|
|
138
|
+
* `!== undefined` read Deno's `null` as "CommonJS", so an ES-module Deno app
|
|
139
|
+
* had its frameworks' CommonJS copies patched while its own imports reached the
|
|
140
|
+
* untouched ES-module copies: `instrument()` returned success and nothing was
|
|
141
|
+
* recorded. Only an actual module object counts.
|
|
142
|
+
*/
|
|
143
|
+
export function isCommonJsMain(main: unknown): boolean {
|
|
144
|
+
return typeof main === "object" && main !== null;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Whether `path` is in the CommonJS module cache, i.e. has been `require`d. */
|
|
148
|
+
export function isRequired(path: string): boolean {
|
|
149
|
+
try {
|
|
150
|
+
return Object.prototype.hasOwnProperty.call(appRequire.cache, path);
|
|
151
|
+
} catch {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* The file an ES-module `import(specifier)` from the application would load,
|
|
158
|
+
* or null when it cannot be worked out.
|
|
159
|
+
*
|
|
160
|
+
* A dual-published framework (`@langchain/core`, `@mastra/core`, `llamaindex`,
|
|
161
|
+
* …) ships two copies of every module — `exports["./x"].import` and
|
|
162
|
+
* `exports["./x"].require` — and they are two different objects in memory.
|
|
163
|
+
* `resolveFrom` can only ever name the `require` one, because `createRequire`
|
|
164
|
+
* resolves with CommonJS conditions. Patching that copy in an ES-module
|
|
165
|
+
* application is a silent no-op: `instrument()` reports success, the app's own
|
|
166
|
+
* imports reach the untouched ESM copy, and no event is ever recorded.
|
|
167
|
+
*
|
|
168
|
+
* `import.meta.resolve` would answer this directly, but it does not exist in
|
|
169
|
+
* the CommonJS build and cannot take a parent URL without a flag — and the
|
|
170
|
+
* parent has to be the APPLICATION, not this file (see the module comment). So
|
|
171
|
+
* this reads the package's `exports` map itself, with Node's ESM conditions
|
|
172
|
+
* (`node`, `import`, `default`). It only has to handle what packages actually
|
|
173
|
+
* publish: condition objects, arrays, and single-`*` subpath patterns.
|
|
174
|
+
*/
|
|
175
|
+
export function resolveEsm(specifier: string): string | null {
|
|
176
|
+
const { name, subpath } = splitSpecifier(specifier);
|
|
177
|
+
if (name === null) return null;
|
|
178
|
+
const root = packageRoot(name, specifier);
|
|
179
|
+
if (root === null) return null;
|
|
180
|
+
let manifest: { exports?: unknown; main?: unknown };
|
|
181
|
+
try {
|
|
182
|
+
manifest = JSON.parse(readFileSync(join(root, "package.json"), "utf8")) as typeof manifest;
|
|
183
|
+
} catch {
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
if (manifest.exports === undefined) {
|
|
187
|
+
// No exports map: Node's ESM loader reads `main` exactly as `require`
|
|
188
|
+
// does, so there is only one copy and CommonJS resolution already names it.
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
const target = matchExports(manifest.exports, subpath, ESM_CONDITIONS);
|
|
192
|
+
if (target === null || !target.startsWith("./")) return null;
|
|
193
|
+
const file = join(root, target);
|
|
194
|
+
return existsSync(file) ? file : null;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const ESM_CONDITIONS: readonly string[] = ["node", "import", "default"];
|
|
198
|
+
const CJS_CONDITIONS: readonly string[] = ["node", "require", "default"];
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* The file `subpath` of the package installed at `root` resolves to, for an
|
|
202
|
+
* `import` or a `require` — or null. `root` is a package directory found on
|
|
203
|
+
* disk rather than by resolution (see `nestedCopies`), so there is no
|
|
204
|
+
* specifier to hand Node's resolver; this reads the package's own `exports`.
|
|
205
|
+
*/
|
|
206
|
+
export function resolveExportsAt(root: string, subpath: string, kind: "import" | "require"): string | null {
|
|
207
|
+
let manifest: { exports?: unknown; main?: unknown };
|
|
208
|
+
try {
|
|
209
|
+
manifest = JSON.parse(readFileSync(join(root, "package.json"), "utf8")) as typeof manifest;
|
|
210
|
+
} catch {
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
let target: string | null;
|
|
214
|
+
if (manifest.exports === undefined) {
|
|
215
|
+
if (subpath !== ".") return null;
|
|
216
|
+
target = typeof manifest.main === "string" ? manifest.main : "index.js";
|
|
217
|
+
if (!target.startsWith("./")) target = `./${target}`;
|
|
218
|
+
} else {
|
|
219
|
+
target = matchExports(manifest.exports, subpath, kind === "import" ? ESM_CONDITIONS : CJS_CONDITIONS);
|
|
220
|
+
}
|
|
221
|
+
if (target === null || !target.startsWith("./")) return null;
|
|
222
|
+
const file = join(root, target);
|
|
223
|
+
return existsSync(file) ? file : null;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** Bounds on `nestedCopies`' walk: it runs once, at `instrument()`, over a tree nobody sized. */
|
|
227
|
+
const NESTED_MAX_DEPTH = 4;
|
|
228
|
+
const NESTED_MAX_DIRS = 20_000;
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Every OTHER installed copy of package `name` the application can end up
|
|
232
|
+
* running: the real directories of the copies nested BENEATH some dependency
|
|
233
|
+
* (`node_modules/<dep>/node_modules/<name>`, at any depth up to a bound), in
|
|
234
|
+
* every `node_modules` on the application's resolution chain — plus, under
|
|
235
|
+
* pnpm, every version in the virtual store (`node_modules/.pnpm/<name>@<v>`).
|
|
236
|
+
*
|
|
237
|
+
* A copy exists there because a dependency could not share the application's
|
|
238
|
+
* — it pinned a different version as a hard dependency — and everything that
|
|
239
|
+
* dependency builds is built on it. `resolveFrom` can never name one: Node's
|
|
240
|
+
* resolution from the application stops at the application's own copy.
|
|
241
|
+
*
|
|
242
|
+
* Deliberately NOT included: a `<name>` sitting directly in some ancestor
|
|
243
|
+
* `node_modules`. The nearest one is the application's own copy, and a farther
|
|
244
|
+
* one is a monorepo root's hoist the application's imports never reach.
|
|
245
|
+
*/
|
|
246
|
+
export function nestedCopies(name: string): string[] {
|
|
247
|
+
const found = new Map<string, true>();
|
|
248
|
+
const seen = new Set<string>();
|
|
249
|
+
let budget = NESTED_MAX_DIRS;
|
|
250
|
+
const real = (path: string): string | null => {
|
|
251
|
+
try {
|
|
252
|
+
return realpathSync(path);
|
|
253
|
+
} catch {
|
|
254
|
+
return null;
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
const list = (dir: string): string[] => {
|
|
258
|
+
try {
|
|
259
|
+
return readdirSync(dir);
|
|
260
|
+
} catch {
|
|
261
|
+
return [];
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
const candidate = (dir: string): void => {
|
|
265
|
+
const path = real(dir);
|
|
266
|
+
if (path !== null && manifestNames(join(path, "package.json"), name)) found.set(path, true);
|
|
267
|
+
};
|
|
268
|
+
const scan = (modules: string, depth: number): void => {
|
|
269
|
+
const key = real(modules);
|
|
270
|
+
if (key === null || seen.has(key)) return;
|
|
271
|
+
seen.add(key);
|
|
272
|
+
for (const entry of list(modules)) {
|
|
273
|
+
if (budget <= 0) return;
|
|
274
|
+
if (entry === ".pnpm") {
|
|
275
|
+
// pnpm's virtual store: one directory per installed version.
|
|
276
|
+
const prefix = `${name.replace("/", "+")}@`;
|
|
277
|
+
for (const version of list(join(modules, entry))) {
|
|
278
|
+
if (version.startsWith(prefix)) candidate(join(modules, entry, version, "node_modules", name));
|
|
279
|
+
}
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
if (entry.startsWith(".")) continue;
|
|
283
|
+
const packages = entry.startsWith("@") ? list(join(modules, entry)).map((sub) => join(modules, entry, sub)) : [join(modules, entry)];
|
|
284
|
+
for (const pkg of packages) {
|
|
285
|
+
if (budget-- <= 0) return;
|
|
286
|
+
// The top level of a scanned `node_modules` is never a candidate.
|
|
287
|
+
if (depth > 0 && pkg === join(modules, name)) {
|
|
288
|
+
candidate(pkg);
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
if (depth < NESTED_MAX_DEPTH) {
|
|
292
|
+
const inner = join(pkg, "node_modules");
|
|
293
|
+
if (existsSync(inner)) scan(inner, depth + 1);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
for (const anchor of anchors()) {
|
|
299
|
+
let dir = anchor;
|
|
300
|
+
for (;;) {
|
|
301
|
+
const modules = join(dir, "node_modules");
|
|
302
|
+
if (existsSync(modules)) scan(modules, 0);
|
|
303
|
+
const parent = dirname(dir);
|
|
304
|
+
if (parent === dir) break;
|
|
305
|
+
dir = parent;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
return [...found.keys()];
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function splitSpecifier(specifier: string): { name: string | null; subpath: string } {
|
|
312
|
+
const parts = specifier.split("/");
|
|
313
|
+
const scoped = specifier.startsWith("@");
|
|
314
|
+
if (scoped && parts.length < 2) return { name: null, subpath: "." };
|
|
315
|
+
const name = scoped ? `${parts[0]}/${parts[1]}` : parts[0]!;
|
|
316
|
+
const rest = parts.slice(scoped ? 2 : 1);
|
|
317
|
+
return { name, subpath: rest.length === 0 ? "." : `./${rest.join("/")}` };
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* The directory holding `name`'s `package.json`, as the application sees it.
|
|
322
|
+
*
|
|
323
|
+
* CommonJS resolution of the package (or of the requested subpath) is used
|
|
324
|
+
* first, because that is precisely the install the application would load —
|
|
325
|
+
* under pnpm, a workspace, or nested `node_modules` alike — and then walked up
|
|
326
|
+
* to the manifest that names it. Only when CommonJS cannot resolve it at all
|
|
327
|
+
* (an ESM-only package whose `exports` has no `require` condition) does this
|
|
328
|
+
* fall back to walking `node_modules` up from each of `anchors()`.
|
|
329
|
+
*/
|
|
330
|
+
function packageRoot(name: string, specifier: string): string | null {
|
|
331
|
+
for (const candidate of [specifier, name, `${name}/package.json`]) {
|
|
332
|
+
const entry = resolveFrom(candidate);
|
|
333
|
+
if (entry === null) continue;
|
|
334
|
+
let dir = dirname(entry);
|
|
335
|
+
for (;;) {
|
|
336
|
+
if (manifestNames(join(dir, "package.json"), name)) return dir;
|
|
337
|
+
const parent = dirname(dir);
|
|
338
|
+
if (parent === dir) break;
|
|
339
|
+
dir = parent;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
for (const anchor of anchors()) {
|
|
343
|
+
let dir = anchor;
|
|
344
|
+
for (;;) {
|
|
345
|
+
const candidate = join(dir, "node_modules", name);
|
|
346
|
+
if (manifestNames(join(candidate, "package.json"), name)) return candidate;
|
|
347
|
+
const parent = dirname(dir);
|
|
348
|
+
if (parent === dir) break;
|
|
349
|
+
dir = parent;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
return null;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
function manifestNames(path: string, name: string): boolean {
|
|
356
|
+
try {
|
|
357
|
+
return (JSON.parse(readFileSync(path, "utf8")) as { name?: unknown }).name === name;
|
|
358
|
+
} catch {
|
|
359
|
+
return false;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/** Node's `PACKAGE_EXPORTS_RESOLVE`, reduced to what packages publish. */
|
|
364
|
+
function matchExports(exports: unknown, subpath: string, conditions: readonly string[]): string | null {
|
|
365
|
+
const isSubpathMap =
|
|
366
|
+
typeof exports === "object" &&
|
|
367
|
+
exports !== null &&
|
|
368
|
+
!Array.isArray(exports) &&
|
|
369
|
+
Object.keys(exports).some((key) => key.startsWith("."));
|
|
370
|
+
if (!isSubpathMap) {
|
|
371
|
+
return subpath === "." ? resolveTarget(exports, conditions, null) : null;
|
|
372
|
+
}
|
|
373
|
+
const map = exports as Record<string, unknown>;
|
|
374
|
+
if (Object.prototype.hasOwnProperty.call(map, subpath) && !subpath.includes("*")) {
|
|
375
|
+
return resolveTarget(map[subpath], conditions, null);
|
|
376
|
+
}
|
|
377
|
+
// Longest matching `prefix*suffix` pattern wins, as in Node.
|
|
378
|
+
let best: { key: string; match: string } | null = null;
|
|
379
|
+
for (const key of Object.keys(map)) {
|
|
380
|
+
const star = key.indexOf("*");
|
|
381
|
+
if (star === -1 || key.indexOf("*", star + 1) !== -1) continue;
|
|
382
|
+
const prefix = key.slice(0, star);
|
|
383
|
+
const suffix = key.slice(star + 1);
|
|
384
|
+
if (
|
|
385
|
+
subpath.startsWith(prefix) &&
|
|
386
|
+
subpath.endsWith(suffix) &&
|
|
387
|
+
subpath.length >= key.length &&
|
|
388
|
+
(best === null || prefix.length > best.key.indexOf("*"))
|
|
389
|
+
) {
|
|
390
|
+
best = { key, match: subpath.slice(prefix.length, subpath.length - suffix.length) };
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
return best === null ? null : resolveTarget(map[best.key], conditions, best.match);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function resolveTarget(target: unknown, conditions: readonly string[], match: string | null): string | null {
|
|
397
|
+
if (typeof target === "string") {
|
|
398
|
+
return match === null ? target : target.replaceAll("*", match);
|
|
399
|
+
}
|
|
400
|
+
if (Array.isArray(target)) {
|
|
401
|
+
for (const entry of target) {
|
|
402
|
+
const resolved = resolveTarget(entry, conditions, match);
|
|
403
|
+
if (resolved !== null) return resolved;
|
|
404
|
+
}
|
|
405
|
+
return null;
|
|
406
|
+
}
|
|
407
|
+
if (typeof target === "object" && target !== null) {
|
|
408
|
+
for (const [key, value] of Object.entries(target)) {
|
|
409
|
+
if (key !== "default" && !conditions.includes(key)) continue;
|
|
410
|
+
const resolved = resolveTarget(value, conditions, match);
|
|
411
|
+
if (resolved !== null) return resolved;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
return null;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/** `require(specifier)`, or null on any failure. Never throws. */
|
|
418
|
+
export function tryRequire<T = unknown>(specifier: string): T | null {
|
|
419
|
+
try {
|
|
420
|
+
return appRequire(specifier) as T;
|
|
421
|
+
} catch {
|
|
422
|
+
return null;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* A real dynamic `import()`, in both halves of the dual build.
|
|
428
|
+
*
|
|
429
|
+
* TypeScript downlevels `import(x)` to `require(x)` when it emits CommonJS,
|
|
430
|
+
* which is exactly wrong for the packages this SDK reaches for: the Vercel AI
|
|
431
|
+
* SDK is ESM-only, so the CommonJS build would report the framework as "not
|
|
432
|
+
* importable" for the users most likely to have it. Building the import through
|
|
433
|
+
* the `Function` constructor hides it from that transform, so both builds
|
|
434
|
+
* perform a genuine dynamic import and both can load an ESM-only framework.
|
|
435
|
+
*
|
|
436
|
+
* The `Function` here takes no caller-controlled input: the body is this fixed
|
|
437
|
+
* literal and the specifier arrives as an argument.
|
|
438
|
+
*/
|
|
439
|
+
// eslint-disable-next-line @typescript-eslint/no-implied-eval -- fixed literal body, no caller input; see above
|
|
440
|
+
const dynamicImport = new Function("specifier", "return import(specifier);") as (
|
|
441
|
+
specifier: string,
|
|
442
|
+
) => Promise<unknown>;
|
|
443
|
+
|
|
444
|
+
export async function importModule(specifier: string): Promise<unknown> {
|
|
445
|
+
return await dynamicImport(specifier);
|
|
446
|
+
}
|