@langchain/react 0.1.3 → 0.2.1
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/README.md +246 -14
- package/dist/context.cjs +108 -0
- package/dist/context.cjs.map +1 -0
- package/dist/context.d.cts +109 -0
- package/dist/context.d.cts.map +1 -0
- package/dist/context.d.ts +109 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +107 -0
- package/dist/context.js.map +1 -0
- package/dist/index.cjs +7 -1
- package/dist/index.d.cts +4 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/stream.cjs +5 -4
- package/dist/stream.cjs.map +1 -1
- package/dist/stream.custom.cjs +22 -2
- package/dist/stream.custom.cjs.map +1 -1
- package/dist/stream.custom.js +22 -1
- package/dist/stream.custom.js.map +1 -1
- package/dist/stream.d.cts +3 -3
- package/dist/stream.d.cts.map +1 -1
- package/dist/stream.d.ts +3 -3
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +5 -3
- package/dist/stream.js.map +1 -1
- package/dist/stream.lgp.cjs +11 -2
- package/dist/stream.lgp.cjs.map +1 -1
- package/dist/stream.lgp.js +11 -1
- package/dist/stream.lgp.js.map +1 -1
- package/dist/suspense-stream.cjs +203 -0
- package/dist/suspense-stream.cjs.map +1 -0
- package/dist/suspense-stream.d.cts +81 -0
- package/dist/suspense-stream.d.cts.map +1 -0
- package/dist/suspense-stream.d.ts +81 -0
- package/dist/suspense-stream.d.ts.map +1 -0
- package/dist/suspense-stream.js +201 -0
- package/dist/suspense-stream.js.map +1 -0
- package/dist/thread.cjs +0 -1
- package/dist/thread.cjs.map +1 -1
- package/dist/types.d.cts +18 -2
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.ts +18 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +7 -37
- package/dist/_virtual/_rolldown/runtime.cjs +0 -23
- package/dist/node_modules/.pnpm/@langchain_langgraph@1.2.1_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___z_dc6decfb18baf112a7d3c3203e2e3228/node_modules/@langchain/langgraph/dist/channels/base.d.cts +0 -83
- package/dist/node_modules/.pnpm/@langchain_langgraph@1.2.1_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___z_dc6decfb18baf112a7d3c3203e2e3228/node_modules/@langchain/langgraph/dist/channels/base.d.cts.map +0 -1
- package/dist/node_modules/.pnpm/@langchain_langgraph@1.2.1_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___z_dc6decfb18baf112a7d3c3203e2e3228/node_modules/@langchain/langgraph/dist/channels/base.d.ts +0 -83
- package/dist/node_modules/.pnpm/@langchain_langgraph@1.2.1_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___z_dc6decfb18baf112a7d3c3203e2e3228/node_modules/@langchain/langgraph/dist/channels/base.d.ts.map +0 -1
- package/dist/node_modules/.pnpm/@langchain_langgraph@1.2.1_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___z_dc6decfb18baf112a7d3c3203e2e3228/node_modules/@langchain/langgraph/dist/constants.d.cts +0 -42
- package/dist/node_modules/.pnpm/@langchain_langgraph@1.2.1_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___z_dc6decfb18baf112a7d3c3203e2e3228/node_modules/@langchain/langgraph/dist/constants.d.cts.map +0 -1
- package/dist/node_modules/.pnpm/@langchain_langgraph@1.2.1_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___z_dc6decfb18baf112a7d3c3203e2e3228/node_modules/@langchain/langgraph/dist/constants.d.ts +0 -42
- package/dist/node_modules/.pnpm/@langchain_langgraph@1.2.1_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___z_dc6decfb18baf112a7d3c3203e2e3228/node_modules/@langchain/langgraph/dist/constants.d.ts.map +0 -1
- package/dist/node_modules/.pnpm/@langchain_langgraph@1.2.1_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___z_dc6decfb18baf112a7d3c3203e2e3228/node_modules/@langchain/langgraph/dist/graph/zod/index.d.cts +0 -2
- package/dist/node_modules/.pnpm/@langchain_langgraph@1.2.1_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___z_dc6decfb18baf112a7d3c3203e2e3228/node_modules/@langchain/langgraph/dist/graph/zod/index.d.ts +0 -2
- package/dist/node_modules/.pnpm/@langchain_langgraph@1.2.1_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___z_dc6decfb18baf112a7d3c3203e2e3228/node_modules/@langchain/langgraph/dist/graph/zod/meta.d.cts +0 -109
- package/dist/node_modules/.pnpm/@langchain_langgraph@1.2.1_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___z_dc6decfb18baf112a7d3c3203e2e3228/node_modules/@langchain/langgraph/dist/graph/zod/meta.d.cts.map +0 -1
- package/dist/node_modules/.pnpm/@langchain_langgraph@1.2.1_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___z_dc6decfb18baf112a7d3c3203e2e3228/node_modules/@langchain/langgraph/dist/graph/zod/meta.d.ts +0 -109
- package/dist/node_modules/.pnpm/@langchain_langgraph@1.2.1_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___z_dc6decfb18baf112a7d3c3203e2e3228/node_modules/@langchain/langgraph/dist/graph/zod/meta.d.ts.map +0 -1
- package/dist/node_modules/.pnpm/@langchain_langgraph@1.2.1_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___z_dc6decfb18baf112a7d3c3203e2e3228/node_modules/@langchain/langgraph/dist/graph/zod/plugin.d.cts +0 -31
- package/dist/node_modules/.pnpm/@langchain_langgraph@1.2.1_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___z_dc6decfb18baf112a7d3c3203e2e3228/node_modules/@langchain/langgraph/dist/graph/zod/plugin.d.cts.map +0 -1
- package/dist/node_modules/.pnpm/@langchain_langgraph@1.2.1_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___z_dc6decfb18baf112a7d3c3203e2e3228/node_modules/@langchain/langgraph/dist/graph/zod/plugin.d.ts +0 -31
- package/dist/node_modules/.pnpm/@langchain_langgraph@1.2.1_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___z_dc6decfb18baf112a7d3c3203e2e3228/node_modules/@langchain/langgraph/dist/graph/zod/plugin.d.ts.map +0 -1
- package/dist/node_modules/.pnpm/@langchain_langgraph@1.2.1_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___z_dc6decfb18baf112a7d3c3203e2e3228/node_modules/@langchain/langgraph/dist/graph/zod/zod-registry.d.cts +0 -49
- package/dist/node_modules/.pnpm/@langchain_langgraph@1.2.1_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___z_dc6decfb18baf112a7d3c3203e2e3228/node_modules/@langchain/langgraph/dist/graph/zod/zod-registry.d.cts.map +0 -1
- package/dist/node_modules/.pnpm/@langchain_langgraph@1.2.1_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___z_dc6decfb18baf112a7d3c3203e2e3228/node_modules/@langchain/langgraph/dist/graph/zod/zod-registry.d.ts +0 -49
- package/dist/node_modules/.pnpm/@langchain_langgraph@1.2.1_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___z_dc6decfb18baf112a7d3c3203e2e3228/node_modules/@langchain/langgraph/dist/graph/zod/zod-registry.d.ts.map +0 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/ReactAgent.d.cts +0 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/ReactAgent.d.ts +0 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/index.d.cts +0 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/index.d.ts +0 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/middleware/contextEditing.d.cts +0 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/middleware/contextEditing.d.ts +0 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/middleware/dynamicSystemPrompt.d.cts +0 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/middleware/dynamicSystemPrompt.d.ts +0 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/middleware/hitl.d.cts +0 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/middleware/hitl.d.ts +0 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/middleware/llmToolSelector.d.cts +0 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/middleware/llmToolSelector.d.ts +0 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/middleware/modelCallLimit.d.cts +0 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/middleware/modelCallLimit.d.ts +0 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/middleware/modelFallback.d.cts +0 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/middleware/modelFallback.d.ts +0 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/middleware/modelRetry.d.cts +0 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/middleware/modelRetry.d.ts +0 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/middleware/pii.d.cts +0 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/middleware/pii.d.ts +0 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/middleware/piiRedaction.d.cts +0 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/middleware/piiRedaction.d.ts +0 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/middleware/provider/anthropic/promptCaching.d.cts +0 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/middleware/provider/anthropic/promptCaching.d.ts +0 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/middleware/provider/openai/moderation.d.cts +0 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/middleware/provider/openai/moderation.d.ts +0 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/middleware/summarization.d.cts +0 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/middleware/summarization.d.ts +0 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/middleware/todoListMiddleware.d.cts +0 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/middleware/todoListMiddleware.d.ts +0 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/middleware/toolCallLimit.d.cts +0 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/middleware/toolCallLimit.d.ts +0 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/middleware/toolEmulator.d.cts +0 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/middleware/toolEmulator.d.ts +0 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/middleware/toolRetry.d.cts +0 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/middleware/toolRetry.d.ts +0 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/middleware/types.d.cts +0 -2
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/middleware/types.d.ts +0 -2
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/middleware.d.cts +0 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/middleware.d.ts +0 -1
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/types.d.cts +0 -2
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/agents/types.d.ts +0 -2
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/index.d.cts +0 -2
- package/dist/node_modules/.pnpm/langchain@1.2.30_@langchain_core@1.1.31_openai@6.27.0_ws@8.19.0_zod@4.3.6___openai@6.27_afd3ba7574abac8ef5d4f1eb16ab2ab0/node_modules/langchain/dist/index.d.ts +0 -2
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/ZodError.d.cts +0 -155
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/ZodError.d.cts.map +0 -1
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/ZodError.d.ts +0 -155
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/ZodError.d.ts.map +0 -1
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/helpers/errorUtil.d.cts +0 -13
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/helpers/errorUtil.d.cts.map +0 -1
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/helpers/errorUtil.d.ts +0 -13
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/helpers/errorUtil.d.ts.map +0 -1
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/helpers/parseUtil.d.cts +0 -63
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/helpers/parseUtil.d.cts.map +0 -1
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/helpers/parseUtil.d.ts +0 -63
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/helpers/parseUtil.d.ts.map +0 -1
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/helpers/typeAliases.d.cts +0 -5
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/helpers/typeAliases.d.cts.map +0 -1
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/helpers/typeAliases.d.ts +0 -5
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/helpers/typeAliases.d.ts.map +0 -1
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/helpers/util.d.cts +0 -64
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/helpers/util.d.cts.map +0 -1
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/helpers/util.d.ts +0 -64
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/helpers/util.d.ts.map +0 -1
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/standard-schema.d.cts +0 -106
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/standard-schema.d.cts.map +0 -1
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/standard-schema.d.ts +0 -106
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/standard-schema.d.ts.map +0 -1
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/types.d.cts +0 -291
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/types.d.cts.map +0 -1
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/types.d.ts +0 -291
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/types.d.ts.map +0 -1
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/checks.d.cts +0 -29
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/checks.d.cts.map +0 -1
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/checks.d.ts +0 -29
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/checks.d.ts.map +0 -1
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/core.d.cts +0 -29
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/core.d.cts.map +0 -1
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/core.d.ts +0 -29
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/core.d.ts.map +0 -1
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/errors.d.cts +0 -105
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/errors.d.cts.map +0 -1
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/errors.d.ts +0 -105
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/errors.d.ts.map +0 -1
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/json-schema.d.cts +0 -70
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/json-schema.d.cts.map +0 -1
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/json-schema.d.ts +0 -70
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/json-schema.d.ts.map +0 -1
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/registries.d.cts +0 -24
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/registries.d.cts.map +0 -1
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/registries.d.ts +0 -24
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/registries.d.ts.map +0 -1
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/schemas.d.cts +0 -97
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/schemas.d.cts.map +0 -1
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/schemas.d.ts +0 -97
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/schemas.d.ts.map +0 -1
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/standard-schema.d.cts +0 -79
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/standard-schema.d.cts.map +0 -1
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/standard-schema.d.ts +0 -79
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/standard-schema.d.ts.map +0 -1
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/to-json-schema.d.cts +0 -52
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/to-json-schema.d.cts.map +0 -1
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/to-json-schema.d.ts +0 -52
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/to-json-schema.d.ts.map +0 -1
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/util.d.cts +0 -17
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/util.d.cts.map +0 -1
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/util.d.ts +0 -17
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/util.d.ts.map +0 -1
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/versions.d.cts +0 -9
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/versions.d.cts.map +0 -1
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/versions.d.ts +0 -9
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/versions.d.ts.map +0 -1
- package/dist/react-ui/client.cjs +0 -136
- package/dist/react-ui/client.cjs.map +0 -1
- package/dist/react-ui/client.d.cts +0 -88
- package/dist/react-ui/client.d.cts.map +0 -1
- package/dist/react-ui/client.d.ts +0 -88
- package/dist/react-ui/client.d.ts.map +0 -1
- package/dist/react-ui/client.js +0 -130
- package/dist/react-ui/client.js.map +0 -1
- package/dist/react-ui/index.cjs +0 -14
- package/dist/react-ui/index.cjs.map +0 -1
- package/dist/react-ui/index.d.cts +0 -3
- package/dist/react-ui/index.d.ts +0 -3
- package/dist/react-ui/index.js +0 -8
- package/dist/react-ui/index.js.map +0 -1
- package/dist/react-ui/server/index.cjs +0 -5
- package/dist/react-ui/server/index.d.cts +0 -3
- package/dist/react-ui/server/index.d.ts +0 -3
- package/dist/react-ui/server/index.js +0 -3
- package/dist/react-ui/server/server.cjs +0 -56
- package/dist/react-ui/server/server.cjs.map +0 -1
- package/dist/react-ui/server/server.d.cts +0 -54
- package/dist/react-ui/server/server.d.cts.map +0 -1
- package/dist/react-ui/server/server.d.ts +0 -54
- package/dist/react-ui/server/server.d.ts.map +0 -1
- package/dist/react-ui/server/server.js +0 -55
- package/dist/react-ui/server/server.js.map +0 -1
- package/dist/react-ui/types.cjs +0 -37
- package/dist/react-ui/types.cjs.map +0 -1
- package/dist/react-ui/types.d.cts +0 -25
- package/dist/react-ui/types.d.cts.map +0 -1
- package/dist/react-ui/types.d.ts +0 -25
- package/dist/react-ui/types.d.ts.map +0 -1
- package/dist/react-ui/types.js +0 -35
- package/dist/react-ui/types.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @langchain/react
|
|
2
2
|
|
|
3
|
-
React SDK for building AI-powered applications with [LangChain](https://
|
|
3
|
+
React SDK for building AI-powered applications with [Deep Agents](https://docs.langchain.com/oss/javascript/deepagents/overview), [LangChain](https://docs.langchain.com/oss/javascript/langchain/overview) and [LangGraph](https://docs.langchain.com/oss/javascript/langgraph/overview). It provides a `useStream` hook that manages streaming, state, branching, and interrupts out of the box.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -8,7 +8,7 @@ React SDK for building AI-powered applications with [LangChain](https://js.langc
|
|
|
8
8
|
npm install @langchain/react @langchain/core
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
**Peer dependencies:** `react` (^18 || ^19),
|
|
11
|
+
**Peer dependencies:** `react` (^18 || ^19), `@langchain/core` (^1.1.27)
|
|
12
12
|
|
|
13
13
|
## Quick Start
|
|
14
14
|
|
|
@@ -80,6 +80,159 @@ function Chat() {
|
|
|
80
80
|
| `queue.cancel(id)` | `(id: string) => Promise<boolean>` | Cancel a pending run on the server by its run ID. |
|
|
81
81
|
| `queue.clear()` | `() => Promise<void>` | Cancel all pending runs on the server. |
|
|
82
82
|
|
|
83
|
+
## `useSuspenseStream`
|
|
84
|
+
|
|
85
|
+
`useSuspenseStream` is a companion hook to `useStream` that integrates with React's [Suspense](https://react.dev/reference/react/Suspense) and [Error Boundary](https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary) protocols. Instead of handling loading and error states inside your component, you declare them in parent boundaries:
|
|
86
|
+
|
|
87
|
+
```tsx
|
|
88
|
+
import { Suspense } from "react";
|
|
89
|
+
import { ErrorBoundary } from "react-error-boundary";
|
|
90
|
+
import { useSuspenseStream } from "@langchain/react";
|
|
91
|
+
|
|
92
|
+
function App() {
|
|
93
|
+
return (
|
|
94
|
+
<ErrorBoundary
|
|
95
|
+
fallback={({ error, resetErrorBoundary }) => (
|
|
96
|
+
<div>
|
|
97
|
+
<p>{error.message}</p>
|
|
98
|
+
<button onClick={resetErrorBoundary}>Retry</button>
|
|
99
|
+
</div>
|
|
100
|
+
)}
|
|
101
|
+
>
|
|
102
|
+
<Suspense fallback={<Spinner />}>
|
|
103
|
+
<Chat />
|
|
104
|
+
</Suspense>
|
|
105
|
+
</ErrorBoundary>
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function Chat() {
|
|
110
|
+
// No isLoading/error checks needed — Suspense and ErrorBoundary handle them.
|
|
111
|
+
const { messages, submit, isStreaming } = useSuspenseStream({
|
|
112
|
+
assistantId: "agent",
|
|
113
|
+
apiUrl: "http://localhost:2024",
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
return (
|
|
117
|
+
<div>
|
|
118
|
+
{messages.map((msg, i) => (
|
|
119
|
+
<div key={msg.id ?? i}>{msg.content}</div>
|
|
120
|
+
))}
|
|
121
|
+
{isStreaming && <TypingIndicator />}
|
|
122
|
+
|
|
123
|
+
<button
|
|
124
|
+
onClick={() =>
|
|
125
|
+
void submit({
|
|
126
|
+
messages: [{ type: "human", content: "Hello!" }],
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
>
|
|
130
|
+
Send
|
|
131
|
+
</button>
|
|
132
|
+
</div>
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### How it works
|
|
138
|
+
|
|
139
|
+
- **Suspends** while the initial thread history is loading (e.g. when a `threadId` is provided and the thread data is being fetched). The nearest `<Suspense>` boundary renders its fallback during this time.
|
|
140
|
+
- **Throws errors** to the nearest Error Boundary when the stream encounters an error outside of active streaming.
|
|
141
|
+
- **Does not suspend during streaming.** Streaming is incremental — messages arrive progressively and the UI must update in real time. The `isStreaming` flag indicates whether tokens are currently arriving.
|
|
142
|
+
|
|
143
|
+
### Options
|
|
144
|
+
|
|
145
|
+
`useSuspenseStream` accepts the same options as `useStream` (LangGraph Platform mode), plus:
|
|
146
|
+
|
|
147
|
+
| Option | Type | Description |
|
|
148
|
+
|---|---|---|
|
|
149
|
+
| `suspenseCache` | `SuspenseCache` | Optional cache instance for Suspense history prefetching. Useful in tests to avoid cross-test cache sharing. |
|
|
150
|
+
|
|
151
|
+
### Return Values
|
|
152
|
+
|
|
153
|
+
The return type is identical to `useStream` except:
|
|
154
|
+
|
|
155
|
+
| Removed | Reason |
|
|
156
|
+
|---|---|
|
|
157
|
+
| `isLoading` | Replaced by `isStreaming`; initial loading is handled by Suspense. |
|
|
158
|
+
| `error` | Thrown to the nearest Error Boundary instead. |
|
|
159
|
+
| `isThreadLoading` | Handled by Suspense (the component suspends until the thread is ready). |
|
|
160
|
+
|
|
161
|
+
| Added | Type | Description |
|
|
162
|
+
|---|---|---|
|
|
163
|
+
| `isStreaming` | `boolean` | `true` while the stream is receiving data. The component is never suspended during streaming. |
|
|
164
|
+
|
|
165
|
+
All other properties (`messages`, `submit`, `stop`, `interrupt`, `branch`, `switchThread`, `queue`, etc.) are unchanged.
|
|
166
|
+
|
|
167
|
+
### Thread-switching with Suspense
|
|
168
|
+
|
|
169
|
+
`useSuspenseStream` works naturally with thread switching. When the `threadId` changes, the component suspends while the new thread's history loads, and `<Suspense>` shows a smooth skeleton/fallback transition:
|
|
170
|
+
|
|
171
|
+
```tsx
|
|
172
|
+
function App() {
|
|
173
|
+
const [threadId, setThreadId] = useState<string | null>(null);
|
|
174
|
+
|
|
175
|
+
return (
|
|
176
|
+
<div className="flex">
|
|
177
|
+
<ThreadSidebar onSelect={setThreadId} />
|
|
178
|
+
|
|
179
|
+
<Suspense fallback={<ThreadSkeleton />}>
|
|
180
|
+
<ChatPanel threadId={threadId} />
|
|
181
|
+
</Suspense>
|
|
182
|
+
</div>
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function ChatPanel({ threadId }: { threadId: string | null }) {
|
|
187
|
+
const { messages, submit, isStreaming } = useSuspenseStream({
|
|
188
|
+
assistantId: "agent",
|
|
189
|
+
apiUrl: "http://localhost:2024",
|
|
190
|
+
threadId,
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
return <MessageList messages={messages} />;
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Error recovery
|
|
198
|
+
|
|
199
|
+
When an error is thrown to an Error Boundary, call `invalidateSuspenseCache()` in the boundary's reset handler so the retry triggers a fresh data fetch:
|
|
200
|
+
|
|
201
|
+
```tsx
|
|
202
|
+
import { invalidateSuspenseCache } from "@langchain/react";
|
|
203
|
+
|
|
204
|
+
<ErrorBoundary
|
|
205
|
+
onReset={() => invalidateSuspenseCache()}
|
|
206
|
+
fallbackRender={({ error, resetErrorBoundary }) => (
|
|
207
|
+
<div>
|
|
208
|
+
<p>{error.message}</p>
|
|
209
|
+
<button onClick={resetErrorBoundary}>Retry</button>
|
|
210
|
+
</div>
|
|
211
|
+
)}
|
|
212
|
+
>
|
|
213
|
+
<Suspense fallback={<Spinner />}>
|
|
214
|
+
<Chat />
|
|
215
|
+
</Suspense>
|
|
216
|
+
</ErrorBoundary>
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
For test isolation, you can create and pass a dedicated cache instance:
|
|
220
|
+
|
|
221
|
+
```tsx
|
|
222
|
+
import { createSuspenseCache, useSuspenseStream } from "@langchain/react";
|
|
223
|
+
|
|
224
|
+
const suspenseCache = createSuspenseCache();
|
|
225
|
+
|
|
226
|
+
function Chat() {
|
|
227
|
+
const stream = useSuspenseStream({
|
|
228
|
+
assistantId: "agent",
|
|
229
|
+
apiUrl: "http://localhost:2024",
|
|
230
|
+
suspenseCache,
|
|
231
|
+
});
|
|
232
|
+
// ...
|
|
233
|
+
}
|
|
234
|
+
```
|
|
235
|
+
|
|
83
236
|
## Type Safety
|
|
84
237
|
|
|
85
238
|
### With `createAgent`
|
|
@@ -327,31 +480,110 @@ function Chat() {
|
|
|
327
480
|
}
|
|
328
481
|
```
|
|
329
482
|
|
|
330
|
-
The custom transport interface returns the same properties as the standard `useStream` hook, including `getMessagesMetadata`, `branch`, `setBranch`, `switchThread`, and all message/interrupt/subagent helpers. When using a custom transport, `getMessagesMetadata` returns stream metadata sent alongside messages during streaming; `branch` and `setBranch` provide local branch state management.
|
|
483
|
+
The custom transport interface returns the same properties as the standard `useStream` hook, including `getMessagesMetadata`, `branch`, `setBranch`, `switchThread`, and all message/interrupt/subagent helpers. When using a custom transport, `getMessagesMetadata` returns stream metadata sent alongside messages during streaming; `branch` and `setBranch` provide local branch state management. `onFinish` is also supported and receives a synthetic `ThreadState` built from the final locally streamed values; the run metadata argument is `undefined`.
|
|
331
484
|
|
|
332
|
-
##
|
|
485
|
+
## Sharing State with `StreamProvider`
|
|
333
486
|
|
|
334
|
-
|
|
487
|
+
When multiple components in a tree need access to the same stream (a message list, a header with loading status, an input bar), use `StreamProvider` and `useStreamContext` to avoid prop drilling:
|
|
335
488
|
|
|
336
489
|
```tsx
|
|
337
|
-
import {
|
|
338
|
-
|
|
339
|
-
|
|
490
|
+
import { StreamProvider, useStreamContext } from "@langchain/react";
|
|
491
|
+
|
|
492
|
+
function App() {
|
|
493
|
+
return (
|
|
494
|
+
<StreamProvider assistantId="agent" apiUrl="http://localhost:2024">
|
|
495
|
+
<ChatHeader />
|
|
496
|
+
<MessageList />
|
|
497
|
+
<MessageInput />
|
|
498
|
+
</StreamProvider>
|
|
499
|
+
);
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
function ChatHeader() {
|
|
503
|
+
const { isLoading, error } = useStreamContext();
|
|
504
|
+
return (
|
|
505
|
+
<header>
|
|
506
|
+
<h1>Chat</h1>
|
|
507
|
+
{isLoading && <span>Thinking...</span>}
|
|
508
|
+
{error != null && <span>Error occurred</span>}
|
|
509
|
+
</header>
|
|
510
|
+
);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
function MessageList() {
|
|
514
|
+
const { messages, getMessagesMetadata } = useStreamContext();
|
|
515
|
+
return (
|
|
516
|
+
<div>
|
|
517
|
+
{messages.map((msg, i) => (
|
|
518
|
+
<div key={msg.id ?? i}>{msg.content}</div>
|
|
519
|
+
))}
|
|
520
|
+
</div>
|
|
521
|
+
);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
function MessageInput() {
|
|
525
|
+
const { submit, isLoading } = useStreamContext();
|
|
526
|
+
return (
|
|
527
|
+
<button
|
|
528
|
+
disabled={isLoading}
|
|
529
|
+
onClick={() =>
|
|
530
|
+
void submit({
|
|
531
|
+
messages: [{ type: "human", content: "Hello!" }],
|
|
532
|
+
})
|
|
533
|
+
}
|
|
534
|
+
>
|
|
535
|
+
Send
|
|
536
|
+
</button>
|
|
537
|
+
);
|
|
538
|
+
}
|
|
539
|
+
```
|
|
540
|
+
|
|
541
|
+
### Type Safety with `StreamProvider`
|
|
542
|
+
|
|
543
|
+
Pass agent or state types to both `StreamProvider` and `useStreamContext`:
|
|
544
|
+
|
|
545
|
+
```tsx
|
|
546
|
+
import type { agent } from "./agent";
|
|
547
|
+
|
|
548
|
+
function App() {
|
|
549
|
+
return (
|
|
550
|
+
<StreamProvider<typeof agent>
|
|
551
|
+
assistantId="agent"
|
|
552
|
+
apiUrl="http://localhost:2024"
|
|
553
|
+
>
|
|
554
|
+
<Chat />
|
|
555
|
+
</StreamProvider>
|
|
556
|
+
);
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
function Chat() {
|
|
560
|
+
const { toolCalls } = useStreamContext<typeof agent>();
|
|
561
|
+
// toolCalls are fully typed from the agent's tools
|
|
562
|
+
}
|
|
340
563
|
```
|
|
341
564
|
|
|
342
|
-
|
|
343
|
-
- **`LoadExternalComponent`** - Render UI components defined by the server
|
|
344
|
-
- **`uiMessageReducer`** - Reducer for managing UI message state
|
|
565
|
+
### Multiple Agents
|
|
345
566
|
|
|
346
|
-
|
|
567
|
+
Nest providers for multi-agent scenarios — each subtree gets its own isolated stream:
|
|
347
568
|
|
|
348
569
|
```tsx
|
|
349
|
-
|
|
570
|
+
function MultiAgentApp() {
|
|
571
|
+
return (
|
|
572
|
+
<div style={{ display: "grid", gridTemplateColumns: "1fr 1fr" }}>
|
|
573
|
+
<StreamProvider assistantId="researcher" apiUrl="http://localhost:2024">
|
|
574
|
+
<ResearchPanel />
|
|
575
|
+
</StreamProvider>
|
|
576
|
+
<StreamProvider assistantId="writer" apiUrl="http://localhost:2024">
|
|
577
|
+
<WriterPanel />
|
|
578
|
+
</StreamProvider>
|
|
579
|
+
</div>
|
|
580
|
+
);
|
|
581
|
+
}
|
|
350
582
|
```
|
|
351
583
|
|
|
352
584
|
## Playground
|
|
353
585
|
|
|
354
|
-
For complete end-to-end examples with full agentic UIs, visit the [
|
|
586
|
+
For complete end-to-end examples with full agentic UIs, visit the [LangChain UI Playground](https://docs.langchain.com/playground).
|
|
355
587
|
|
|
356
588
|
## License
|
|
357
589
|
|
package/dist/context.cjs
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
const require_stream = require("./stream.cjs");
|
|
3
|
+
let react = require("react");
|
|
4
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
5
|
+
//#region src/context.tsx
|
|
6
|
+
const StreamContext = (0, react.createContext)(null);
|
|
7
|
+
/**
|
|
8
|
+
* Provides a shared `useStream` instance to all descendants via React Context.
|
|
9
|
+
*
|
|
10
|
+
* Use `StreamProvider` when multiple components in a subtree need access to the
|
|
11
|
+
* same stream state (messages, loading status, errors, interrupts, etc.) without
|
|
12
|
+
* prop drilling.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* import { StreamProvider, useStreamContext } from "@langchain/react";
|
|
17
|
+
*
|
|
18
|
+
* function App() {
|
|
19
|
+
* return (
|
|
20
|
+
* <StreamProvider assistantId="agent" apiUrl="http://localhost:2024">
|
|
21
|
+
* <ChatHeader />
|
|
22
|
+
* <MessageList />
|
|
23
|
+
* <MessageInput />
|
|
24
|
+
* </StreamProvider>
|
|
25
|
+
* );
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* function ChatHeader() {
|
|
29
|
+
* const { isLoading, error } = useStreamContext();
|
|
30
|
+
* return (
|
|
31
|
+
* <header>
|
|
32
|
+
* {isLoading && <span>Thinking...</span>}
|
|
33
|
+
* {error && <span>Error</span>}
|
|
34
|
+
* </header>
|
|
35
|
+
* );
|
|
36
|
+
* }
|
|
37
|
+
*
|
|
38
|
+
* function MessageList() {
|
|
39
|
+
* const { messages } = useStreamContext();
|
|
40
|
+
* return messages.map((msg, i) => <div key={msg.id ?? i}>{msg.content}</div>);
|
|
41
|
+
* }
|
|
42
|
+
*
|
|
43
|
+
* function MessageInput() {
|
|
44
|
+
* const { submit } = useStreamContext();
|
|
45
|
+
* return (
|
|
46
|
+
* <button onClick={() => submit({ messages: [{ type: "human", content: "Hi" }] })}>
|
|
47
|
+
* Send
|
|
48
|
+
* </button>
|
|
49
|
+
* );
|
|
50
|
+
* }
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* Multiple providers can be nested for multi-agent scenarios:
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```tsx
|
|
57
|
+
* <StreamProvider assistantId="researcher" apiUrl="http://localhost:2024">
|
|
58
|
+
* <ResearchPanel />
|
|
59
|
+
* </StreamProvider>
|
|
60
|
+
* <StreamProvider assistantId="writer" apiUrl="http://localhost:2024">
|
|
61
|
+
* <WriterPanel />
|
|
62
|
+
* </StreamProvider>
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
function StreamProvider(props) {
|
|
66
|
+
const { children, ...options } = props;
|
|
67
|
+
const stream = require_stream.useStream(options);
|
|
68
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(StreamContext.Provider, {
|
|
69
|
+
value: stream,
|
|
70
|
+
children
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Accesses the shared stream instance from the nearest `StreamProvider`.
|
|
75
|
+
*
|
|
76
|
+
* Throws if called outside of a `StreamProvider`.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```tsx
|
|
80
|
+
* function MessageList() {
|
|
81
|
+
* const { messages, getMessagesMetadata } = useStreamContext();
|
|
82
|
+
* return messages.map((msg, i) => {
|
|
83
|
+
* const metadata = getMessagesMetadata(msg, i);
|
|
84
|
+
* return <div key={msg.id ?? i}>{msg.content}</div>;
|
|
85
|
+
* });
|
|
86
|
+
* }
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* @example With type parameters for full type safety:
|
|
90
|
+
* ```tsx
|
|
91
|
+
* import type { agent } from "./agent";
|
|
92
|
+
*
|
|
93
|
+
* function Chat() {
|
|
94
|
+
* const { toolCalls } = useStreamContext<typeof agent>();
|
|
95
|
+
* // toolCalls are fully typed from the agent's tools
|
|
96
|
+
* }
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
function useStreamContext() {
|
|
100
|
+
const context = (0, react.useContext)(StreamContext);
|
|
101
|
+
if (context === null) throw new Error("useStreamContext must be used within a <StreamProvider>. Wrap your component tree with <StreamProvider> or use useStream() directly.");
|
|
102
|
+
return context;
|
|
103
|
+
}
|
|
104
|
+
//#endregion
|
|
105
|
+
exports.StreamProvider = StreamProvider;
|
|
106
|
+
exports.useStreamContext = useStreamContext;
|
|
107
|
+
|
|
108
|
+
//# sourceMappingURL=context.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.cjs","names":["useStream"],"sources":["../src/context.tsx"],"sourcesContent":["/* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */\n\n\"use client\";\n\nimport { createContext, useContext, type ReactNode } from \"react\";\nimport type { BagTemplate } from \"@langchain/langgraph-sdk\";\nimport type {\n ResolveStreamOptions,\n InferBag,\n InferStateType,\n UseStreamCustomOptions,\n} from \"@langchain/langgraph-sdk/ui\";\nimport { useStream } from \"./stream.js\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst StreamContext = createContext<any | null>(null);\n\n/**\n * Props for the StreamProvider component.\n * Accepts all `useStream` options plus `children`.\n */\nexport type StreamProviderProps<\n T = Record<string, unknown>,\n Bag extends BagTemplate = BagTemplate,\n> = ResolveStreamOptions<T, InferBag<T, Bag>> & { children: ReactNode };\n\n/**\n * Props for the StreamProvider component when using a custom transport.\n * Accepts all `useStream` custom options plus `children`.\n */\nexport type StreamProviderCustomProps<\n T = Record<string, unknown>,\n Bag extends BagTemplate = BagTemplate,\n> = UseStreamCustomOptions<InferStateType<T>, InferBag<T, Bag>> & {\n children: ReactNode;\n};\n\n/**\n * Provides a shared `useStream` instance to all descendants via React Context.\n *\n * Use `StreamProvider` when multiple components in a subtree need access to the\n * same stream state (messages, loading status, errors, interrupts, etc.) without\n * prop drilling.\n *\n * @example\n * ```tsx\n * import { StreamProvider, useStreamContext } from \"@langchain/react\";\n *\n * function App() {\n * return (\n * <StreamProvider assistantId=\"agent\" apiUrl=\"http://localhost:2024\">\n * <ChatHeader />\n * <MessageList />\n * <MessageInput />\n * </StreamProvider>\n * );\n * }\n *\n * function ChatHeader() {\n * const { isLoading, error } = useStreamContext();\n * return (\n * <header>\n * {isLoading && <span>Thinking...</span>}\n * {error && <span>Error</span>}\n * </header>\n * );\n * }\n *\n * function MessageList() {\n * const { messages } = useStreamContext();\n * return messages.map((msg, i) => <div key={msg.id ?? i}>{msg.content}</div>);\n * }\n *\n * function MessageInput() {\n * const { submit } = useStreamContext();\n * return (\n * <button onClick={() => submit({ messages: [{ type: \"human\", content: \"Hi\" }] })}>\n * Send\n * </button>\n * );\n * }\n * ```\n *\n * Multiple providers can be nested for multi-agent scenarios:\n *\n * @example\n * ```tsx\n * <StreamProvider assistantId=\"researcher\" apiUrl=\"http://localhost:2024\">\n * <ResearchPanel />\n * </StreamProvider>\n * <StreamProvider assistantId=\"writer\" apiUrl=\"http://localhost:2024\">\n * <WriterPanel />\n * </StreamProvider>\n * ```\n */\nexport function StreamProvider<\n T = Record<string, unknown>,\n Bag extends BagTemplate = BagTemplate,\n>(\n props: StreamProviderProps<T, Bag> | StreamProviderCustomProps<T, Bag>,\n): ReactNode {\n const { children, ...options } = props;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const stream = useStream<T, Bag>(options as any);\n\n return (\n <StreamContext.Provider value={stream}>{children}</StreamContext.Provider>\n );\n}\n\n/**\n * Accesses the shared stream instance from the nearest `StreamProvider`.\n *\n * Throws if called outside of a `StreamProvider`.\n *\n * @example\n * ```tsx\n * function MessageList() {\n * const { messages, getMessagesMetadata } = useStreamContext();\n * return messages.map((msg, i) => {\n * const metadata = getMessagesMetadata(msg, i);\n * return <div key={msg.id ?? i}>{msg.content}</div>;\n * });\n * }\n * ```\n *\n * @example With type parameters for full type safety:\n * ```tsx\n * import type { agent } from \"./agent\";\n *\n * function Chat() {\n * const { toolCalls } = useStreamContext<typeof agent>();\n * // toolCalls are fully typed from the agent's tools\n * }\n * ```\n */\nexport function useStreamContext<\n T = Record<string, unknown>,\n Bag extends BagTemplate = BagTemplate,\n>(): ReturnType<typeof useStream<T, Bag>> {\n const context = useContext(StreamContext);\n if (context === null) {\n throw new Error(\n \"useStreamContext must be used within a <StreamProvider>. \" +\n \"Wrap your component tree with <StreamProvider> or use useStream() directly.\",\n );\n }\n return context;\n}\n"],"mappings":";;;;;AAeA,MAAM,iBAAA,GAAA,MAAA,eAA0C,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgFrD,SAAgB,eAId,OACW;CACX,MAAM,EAAE,UAAU,GAAG,YAAY;CAEjC,MAAM,SAASA,eAAAA,UAAkB,QAAe;AAEhD,QACE,iBAAA,GAAA,kBAAA,KAAC,cAAc,UAAf;EAAwB,OAAO;EAAS;EAAkC,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8B9E,SAAgB,mBAG0B;CACxC,MAAM,WAAA,GAAA,MAAA,YAAqB,cAAc;AACzC,KAAI,YAAY,KACd,OAAM,IAAI,MACR,uIAED;AAEH,QAAO"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { useStream } from "./stream.cjs";
|
|
2
|
+
import { BagTemplate } from "@langchain/langgraph-sdk";
|
|
3
|
+
import { InferBag, InferStateType, ResolveStreamOptions, UseStreamCustomOptions } from "@langchain/langgraph-sdk/ui";
|
|
4
|
+
import { ReactNode } from "react";
|
|
5
|
+
|
|
6
|
+
//#region src/context.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Props for the StreamProvider component.
|
|
9
|
+
* Accepts all `useStream` options plus `children`.
|
|
10
|
+
*/
|
|
11
|
+
type StreamProviderProps<T = Record<string, unknown>, Bag extends BagTemplate = BagTemplate> = ResolveStreamOptions<T, InferBag<T, Bag>> & {
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Props for the StreamProvider component when using a custom transport.
|
|
16
|
+
* Accepts all `useStream` custom options plus `children`.
|
|
17
|
+
*/
|
|
18
|
+
type StreamProviderCustomProps<T = Record<string, unknown>, Bag extends BagTemplate = BagTemplate> = UseStreamCustomOptions<InferStateType<T>, InferBag<T, Bag>> & {
|
|
19
|
+
children: ReactNode;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Provides a shared `useStream` instance to all descendants via React Context.
|
|
23
|
+
*
|
|
24
|
+
* Use `StreamProvider` when multiple components in a subtree need access to the
|
|
25
|
+
* same stream state (messages, loading status, errors, interrupts, etc.) without
|
|
26
|
+
* prop drilling.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```tsx
|
|
30
|
+
* import { StreamProvider, useStreamContext } from "@langchain/react";
|
|
31
|
+
*
|
|
32
|
+
* function App() {
|
|
33
|
+
* return (
|
|
34
|
+
* <StreamProvider assistantId="agent" apiUrl="http://localhost:2024">
|
|
35
|
+
* <ChatHeader />
|
|
36
|
+
* <MessageList />
|
|
37
|
+
* <MessageInput />
|
|
38
|
+
* </StreamProvider>
|
|
39
|
+
* );
|
|
40
|
+
* }
|
|
41
|
+
*
|
|
42
|
+
* function ChatHeader() {
|
|
43
|
+
* const { isLoading, error } = useStreamContext();
|
|
44
|
+
* return (
|
|
45
|
+
* <header>
|
|
46
|
+
* {isLoading && <span>Thinking...</span>}
|
|
47
|
+
* {error && <span>Error</span>}
|
|
48
|
+
* </header>
|
|
49
|
+
* );
|
|
50
|
+
* }
|
|
51
|
+
*
|
|
52
|
+
* function MessageList() {
|
|
53
|
+
* const { messages } = useStreamContext();
|
|
54
|
+
* return messages.map((msg, i) => <div key={msg.id ?? i}>{msg.content}</div>);
|
|
55
|
+
* }
|
|
56
|
+
*
|
|
57
|
+
* function MessageInput() {
|
|
58
|
+
* const { submit } = useStreamContext();
|
|
59
|
+
* return (
|
|
60
|
+
* <button onClick={() => submit({ messages: [{ type: "human", content: "Hi" }] })}>
|
|
61
|
+
* Send
|
|
62
|
+
* </button>
|
|
63
|
+
* );
|
|
64
|
+
* }
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* Multiple providers can be nested for multi-agent scenarios:
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```tsx
|
|
71
|
+
* <StreamProvider assistantId="researcher" apiUrl="http://localhost:2024">
|
|
72
|
+
* <ResearchPanel />
|
|
73
|
+
* </StreamProvider>
|
|
74
|
+
* <StreamProvider assistantId="writer" apiUrl="http://localhost:2024">
|
|
75
|
+
* <WriterPanel />
|
|
76
|
+
* </StreamProvider>
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
declare function StreamProvider<T = Record<string, unknown>, Bag extends BagTemplate = BagTemplate>(props: StreamProviderProps<T, Bag> | StreamProviderCustomProps<T, Bag>): ReactNode;
|
|
80
|
+
/**
|
|
81
|
+
* Accesses the shared stream instance from the nearest `StreamProvider`.
|
|
82
|
+
*
|
|
83
|
+
* Throws if called outside of a `StreamProvider`.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```tsx
|
|
87
|
+
* function MessageList() {
|
|
88
|
+
* const { messages, getMessagesMetadata } = useStreamContext();
|
|
89
|
+
* return messages.map((msg, i) => {
|
|
90
|
+
* const metadata = getMessagesMetadata(msg, i);
|
|
91
|
+
* return <div key={msg.id ?? i}>{msg.content}</div>;
|
|
92
|
+
* });
|
|
93
|
+
* }
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* @example With type parameters for full type safety:
|
|
97
|
+
* ```tsx
|
|
98
|
+
* import type { agent } from "./agent";
|
|
99
|
+
*
|
|
100
|
+
* function Chat() {
|
|
101
|
+
* const { toolCalls } = useStreamContext<typeof agent>();
|
|
102
|
+
* // toolCalls are fully typed from the agent's tools
|
|
103
|
+
* }
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
declare function useStreamContext<T = Record<string, unknown>, Bag extends BagTemplate = BagTemplate>(): ReturnType<typeof useStream<T, Bag>>;
|
|
107
|
+
//#endregion
|
|
108
|
+
export { StreamProvider, StreamProviderCustomProps, StreamProviderProps, useStreamContext };
|
|
109
|
+
//# sourceMappingURL=context.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.cts","names":[],"sources":["../src/context.tsx"],"mappings":";;;;;;;;AAqBA;;KAAY,mBAAA,KACN,MAAA,+BACQ,WAAA,GAAc,WAAA,IACxB,oBAAA,CAAqB,CAAA,EAAG,QAAA,CAAS,CAAA,EAAG,GAAA;EAAU,QAAA,EAAU,SAAA;AAAA;;;;;KAMhD,yBAAA,KACN,MAAA,+BACQ,WAAA,GAAc,WAAA,IACxB,sBAAA,CAAuB,cAAA,CAAe,CAAA,GAAI,QAAA,CAAS,CAAA,EAAG,GAAA;EACxD,QAAA,EAAU,SAAA;AAAA;;;;;;;;;;;;;;;;;AAJZ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiEA;;;;;;;;;;;;iBAAgB,cAAA,KACV,MAAA,+BACQ,WAAA,GAAc,WAAA,CAAA,CAE1B,KAAA,EAAO,mBAAA,CAAoB,CAAA,EAAG,GAAA,IAAO,yBAAA,CAA0B,CAAA,EAAG,GAAA,IACjE,SAAA;;;;;;;;;;;;;;;;;;AAoCH;;;;;;;;;iBAAgB,gBAAA,KACV,MAAA,+BACQ,WAAA,GAAc,WAAA,CAAA,CAAA,GACvB,UAAA,QAAkB,SAAA,CAAU,CAAA,EAAG,GAAA"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { useStream } from "./stream.js";
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
|
+
import { InferBag, InferStateType, ResolveStreamOptions, UseStreamCustomOptions } from "@langchain/langgraph-sdk/ui";
|
|
4
|
+
import { BagTemplate } from "@langchain/langgraph-sdk";
|
|
5
|
+
|
|
6
|
+
//#region src/context.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Props for the StreamProvider component.
|
|
9
|
+
* Accepts all `useStream` options plus `children`.
|
|
10
|
+
*/
|
|
11
|
+
type StreamProviderProps<T = Record<string, unknown>, Bag extends BagTemplate = BagTemplate> = ResolveStreamOptions<T, InferBag<T, Bag>> & {
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Props for the StreamProvider component when using a custom transport.
|
|
16
|
+
* Accepts all `useStream` custom options plus `children`.
|
|
17
|
+
*/
|
|
18
|
+
type StreamProviderCustomProps<T = Record<string, unknown>, Bag extends BagTemplate = BagTemplate> = UseStreamCustomOptions<InferStateType<T>, InferBag<T, Bag>> & {
|
|
19
|
+
children: ReactNode;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Provides a shared `useStream` instance to all descendants via React Context.
|
|
23
|
+
*
|
|
24
|
+
* Use `StreamProvider` when multiple components in a subtree need access to the
|
|
25
|
+
* same stream state (messages, loading status, errors, interrupts, etc.) without
|
|
26
|
+
* prop drilling.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```tsx
|
|
30
|
+
* import { StreamProvider, useStreamContext } from "@langchain/react";
|
|
31
|
+
*
|
|
32
|
+
* function App() {
|
|
33
|
+
* return (
|
|
34
|
+
* <StreamProvider assistantId="agent" apiUrl="http://localhost:2024">
|
|
35
|
+
* <ChatHeader />
|
|
36
|
+
* <MessageList />
|
|
37
|
+
* <MessageInput />
|
|
38
|
+
* </StreamProvider>
|
|
39
|
+
* );
|
|
40
|
+
* }
|
|
41
|
+
*
|
|
42
|
+
* function ChatHeader() {
|
|
43
|
+
* const { isLoading, error } = useStreamContext();
|
|
44
|
+
* return (
|
|
45
|
+
* <header>
|
|
46
|
+
* {isLoading && <span>Thinking...</span>}
|
|
47
|
+
* {error && <span>Error</span>}
|
|
48
|
+
* </header>
|
|
49
|
+
* );
|
|
50
|
+
* }
|
|
51
|
+
*
|
|
52
|
+
* function MessageList() {
|
|
53
|
+
* const { messages } = useStreamContext();
|
|
54
|
+
* return messages.map((msg, i) => <div key={msg.id ?? i}>{msg.content}</div>);
|
|
55
|
+
* }
|
|
56
|
+
*
|
|
57
|
+
* function MessageInput() {
|
|
58
|
+
* const { submit } = useStreamContext();
|
|
59
|
+
* return (
|
|
60
|
+
* <button onClick={() => submit({ messages: [{ type: "human", content: "Hi" }] })}>
|
|
61
|
+
* Send
|
|
62
|
+
* </button>
|
|
63
|
+
* );
|
|
64
|
+
* }
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* Multiple providers can be nested for multi-agent scenarios:
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```tsx
|
|
71
|
+
* <StreamProvider assistantId="researcher" apiUrl="http://localhost:2024">
|
|
72
|
+
* <ResearchPanel />
|
|
73
|
+
* </StreamProvider>
|
|
74
|
+
* <StreamProvider assistantId="writer" apiUrl="http://localhost:2024">
|
|
75
|
+
* <WriterPanel />
|
|
76
|
+
* </StreamProvider>
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
declare function StreamProvider<T = Record<string, unknown>, Bag extends BagTemplate = BagTemplate>(props: StreamProviderProps<T, Bag> | StreamProviderCustomProps<T, Bag>): ReactNode;
|
|
80
|
+
/**
|
|
81
|
+
* Accesses the shared stream instance from the nearest `StreamProvider`.
|
|
82
|
+
*
|
|
83
|
+
* Throws if called outside of a `StreamProvider`.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```tsx
|
|
87
|
+
* function MessageList() {
|
|
88
|
+
* const { messages, getMessagesMetadata } = useStreamContext();
|
|
89
|
+
* return messages.map((msg, i) => {
|
|
90
|
+
* const metadata = getMessagesMetadata(msg, i);
|
|
91
|
+
* return <div key={msg.id ?? i}>{msg.content}</div>;
|
|
92
|
+
* });
|
|
93
|
+
* }
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* @example With type parameters for full type safety:
|
|
97
|
+
* ```tsx
|
|
98
|
+
* import type { agent } from "./agent";
|
|
99
|
+
*
|
|
100
|
+
* function Chat() {
|
|
101
|
+
* const { toolCalls } = useStreamContext<typeof agent>();
|
|
102
|
+
* // toolCalls are fully typed from the agent's tools
|
|
103
|
+
* }
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
declare function useStreamContext<T = Record<string, unknown>, Bag extends BagTemplate = BagTemplate>(): ReturnType<typeof useStream<T, Bag>>;
|
|
107
|
+
//#endregion
|
|
108
|
+
export { StreamProvider, StreamProviderCustomProps, StreamProviderProps, useStreamContext };
|
|
109
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","names":[],"sources":["../src/context.tsx"],"mappings":";;;;;;;;AAqBA;;KAAY,mBAAA,KACN,MAAA,+BACQ,WAAA,GAAc,WAAA,IACxB,oBAAA,CAAqB,CAAA,EAAG,QAAA,CAAS,CAAA,EAAG,GAAA;EAAU,QAAA,EAAU,SAAA;AAAA;;;;;KAMhD,yBAAA,KACN,MAAA,+BACQ,WAAA,GAAc,WAAA,IACxB,sBAAA,CAAuB,cAAA,CAAe,CAAA,GAAI,QAAA,CAAS,CAAA,EAAG,GAAA;EACxD,QAAA,EAAU,SAAA;AAAA;;;;;;;;;;;;;;;;;AAJZ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiEA;;;;;;;;;;;;iBAAgB,cAAA,KACV,MAAA,+BACQ,WAAA,GAAc,WAAA,CAAA,CAE1B,KAAA,EAAO,mBAAA,CAAoB,CAAA,EAAG,GAAA,IAAO,yBAAA,CAA0B,CAAA,EAAG,GAAA,IACjE,SAAA;;;;;;;;;;;;;;;;;;AAoCH;;;;;;;;;iBAAgB,gBAAA,KACV,MAAA,+BACQ,WAAA,GAAc,WAAA,CAAA,CAAA,GACvB,UAAA,QAAkB,SAAA,CAAU,CAAA,EAAG,GAAA"}
|