@langchain/react 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (214) hide show
  1. package/README.md +225 -14
  2. package/dist/context.cjs +108 -0
  3. package/dist/context.cjs.map +1 -0
  4. package/dist/context.d.cts +109 -0
  5. package/dist/context.d.cts.map +1 -0
  6. package/dist/context.d.ts +109 -0
  7. package/dist/context.d.ts.map +1 -0
  8. package/dist/context.js +107 -0
  9. package/dist/context.js.map +1 -0
  10. package/dist/index.cjs +6 -1
  11. package/dist/index.d.cts +4 -2
  12. package/dist/index.d.cts.map +1 -1
  13. package/dist/index.d.ts +4 -2
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +3 -1
  16. package/dist/stream.cjs +0 -1
  17. package/dist/stream.cjs.map +1 -1
  18. package/dist/stream.custom.cjs +23 -3
  19. package/dist/stream.custom.cjs.map +1 -1
  20. package/dist/stream.custom.js +23 -2
  21. package/dist/stream.custom.js.map +1 -1
  22. package/dist/stream.d.cts +8 -6
  23. package/dist/stream.d.cts.map +1 -1
  24. package/dist/stream.d.ts +8 -6
  25. package/dist/stream.d.ts.map +1 -1
  26. package/dist/stream.js.map +1 -1
  27. package/dist/stream.lgp.cjs +12 -3
  28. package/dist/stream.lgp.cjs.map +1 -1
  29. package/dist/stream.lgp.js +13 -3
  30. package/dist/stream.lgp.js.map +1 -1
  31. package/dist/suspense-stream.cjs +187 -0
  32. package/dist/suspense-stream.cjs.map +1 -0
  33. package/dist/suspense-stream.d.cts +62 -0
  34. package/dist/suspense-stream.d.cts.map +1 -0
  35. package/dist/suspense-stream.d.ts +62 -0
  36. package/dist/suspense-stream.d.ts.map +1 -0
  37. package/dist/suspense-stream.js +186 -0
  38. package/dist/suspense-stream.js.map +1 -0
  39. package/dist/thread.cjs +0 -1
  40. package/dist/thread.cjs.map +1 -1
  41. package/dist/types.d.cts +18 -2
  42. package/dist/types.d.cts.map +1 -1
  43. package/dist/types.d.ts +18 -2
  44. package/dist/types.d.ts.map +1 -1
  45. package/package.json +7 -37
  46. package/dist/_virtual/_rolldown/runtime.cjs +0 -23
  47. 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
  48. 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
  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/channels/base.d.ts +0 -83
  50. 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
  51. 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
  52. 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
  53. 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
  54. 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
  55. 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
  56. 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
  57. 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
  58. 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
  59. 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
  60. 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
  61. 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
  62. 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
  63. 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
  64. 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
  65. 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
  66. 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
  67. 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
  68. 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
  69. 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
  70. 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
  71. 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
  72. 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
  73. 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
  74. 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
  75. 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
  76. 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
  77. 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
  78. 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
  79. 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
  80. 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
  81. 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
  82. 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
  83. 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
  84. 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
  85. 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
  86. 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
  87. 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
  88. 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
  89. 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
  90. 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
  91. 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
  92. 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
  93. 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
  94. 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
  95. 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
  96. 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
  97. 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
  98. 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
  99. 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
  100. 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
  101. 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
  102. 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
  103. 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
  104. 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
  105. 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
  106. 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
  107. 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
  108. 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
  109. 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
  110. 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
  111. 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
  112. 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
  113. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/ZodError.d.cts +0 -155
  114. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/ZodError.d.cts.map +0 -1
  115. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/ZodError.d.ts +0 -155
  116. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/ZodError.d.ts.map +0 -1
  117. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/helpers/errorUtil.d.cts +0 -13
  118. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/helpers/errorUtil.d.cts.map +0 -1
  119. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/helpers/errorUtil.d.ts +0 -13
  120. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/helpers/errorUtil.d.ts.map +0 -1
  121. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/helpers/parseUtil.d.cts +0 -63
  122. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/helpers/parseUtil.d.cts.map +0 -1
  123. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/helpers/parseUtil.d.ts +0 -63
  124. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/helpers/parseUtil.d.ts.map +0 -1
  125. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/helpers/typeAliases.d.cts +0 -5
  126. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/helpers/typeAliases.d.cts.map +0 -1
  127. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/helpers/typeAliases.d.ts +0 -5
  128. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/helpers/typeAliases.d.ts.map +0 -1
  129. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/helpers/util.d.cts +0 -64
  130. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/helpers/util.d.cts.map +0 -1
  131. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/helpers/util.d.ts +0 -64
  132. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/helpers/util.d.ts.map +0 -1
  133. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/standard-schema.d.cts +0 -106
  134. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/standard-schema.d.cts.map +0 -1
  135. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/standard-schema.d.ts +0 -106
  136. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/standard-schema.d.ts.map +0 -1
  137. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/types.d.cts +0 -291
  138. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/types.d.cts.map +0 -1
  139. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/types.d.ts +0 -291
  140. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v3/types.d.ts.map +0 -1
  141. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/checks.d.cts +0 -29
  142. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/checks.d.cts.map +0 -1
  143. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/checks.d.ts +0 -29
  144. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/checks.d.ts.map +0 -1
  145. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/core.d.cts +0 -29
  146. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/core.d.cts.map +0 -1
  147. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/core.d.ts +0 -29
  148. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/core.d.ts.map +0 -1
  149. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/errors.d.cts +0 -105
  150. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/errors.d.cts.map +0 -1
  151. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/errors.d.ts +0 -105
  152. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/errors.d.ts.map +0 -1
  153. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/json-schema.d.cts +0 -70
  154. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/json-schema.d.cts.map +0 -1
  155. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/json-schema.d.ts +0 -70
  156. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/json-schema.d.ts.map +0 -1
  157. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/registries.d.cts +0 -24
  158. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/registries.d.cts.map +0 -1
  159. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/registries.d.ts +0 -24
  160. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/registries.d.ts.map +0 -1
  161. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/schemas.d.cts +0 -97
  162. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/schemas.d.cts.map +0 -1
  163. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/schemas.d.ts +0 -97
  164. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/schemas.d.ts.map +0 -1
  165. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/standard-schema.d.cts +0 -79
  166. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/standard-schema.d.cts.map +0 -1
  167. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/standard-schema.d.ts +0 -79
  168. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/standard-schema.d.ts.map +0 -1
  169. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/to-json-schema.d.cts +0 -52
  170. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/to-json-schema.d.cts.map +0 -1
  171. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/to-json-schema.d.ts +0 -52
  172. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/to-json-schema.d.ts.map +0 -1
  173. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/util.d.cts +0 -17
  174. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/util.d.cts.map +0 -1
  175. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/util.d.ts +0 -17
  176. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/util.d.ts.map +0 -1
  177. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/versions.d.cts +0 -9
  178. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/versions.d.cts.map +0 -1
  179. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/versions.d.ts +0 -9
  180. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/versions.d.ts.map +0 -1
  181. package/dist/react-ui/client.cjs +0 -136
  182. package/dist/react-ui/client.cjs.map +0 -1
  183. package/dist/react-ui/client.d.cts +0 -84
  184. package/dist/react-ui/client.d.cts.map +0 -1
  185. package/dist/react-ui/client.d.ts +0 -84
  186. package/dist/react-ui/client.d.ts.map +0 -1
  187. package/dist/react-ui/client.js +0 -130
  188. package/dist/react-ui/client.js.map +0 -1
  189. package/dist/react-ui/index.cjs +0 -14
  190. package/dist/react-ui/index.cjs.map +0 -1
  191. package/dist/react-ui/index.d.cts +0 -3
  192. package/dist/react-ui/index.d.ts +0 -3
  193. package/dist/react-ui/index.js +0 -8
  194. package/dist/react-ui/index.js.map +0 -1
  195. package/dist/react-ui/server/index.cjs +0 -5
  196. package/dist/react-ui/server/index.d.cts +0 -3
  197. package/dist/react-ui/server/index.d.ts +0 -3
  198. package/dist/react-ui/server/index.js +0 -3
  199. package/dist/react-ui/server/server.cjs +0 -56
  200. package/dist/react-ui/server/server.cjs.map +0 -1
  201. package/dist/react-ui/server/server.d.cts +0 -54
  202. package/dist/react-ui/server/server.d.cts.map +0 -1
  203. package/dist/react-ui/server/server.d.ts +0 -54
  204. package/dist/react-ui/server/server.d.ts.map +0 -1
  205. package/dist/react-ui/server/server.js +0 -55
  206. package/dist/react-ui/server/server.js.map +0 -1
  207. package/dist/react-ui/types.cjs +0 -37
  208. package/dist/react-ui/types.cjs.map +0 -1
  209. package/dist/react-ui/types.d.cts +0 -25
  210. package/dist/react-ui/types.d.cts.map +0 -1
  211. package/dist/react-ui/types.d.ts +0 -25
  212. package/dist/react-ui/types.d.ts.map +0 -1
  213. package/dist/react-ui/types.js +0 -35
  214. package/dist/react-ui/types.js.map +0 -1
@@ -0,0 +1,187 @@
1
+ "use client";
2
+ const require_stream_lgp = require("./stream.lgp.cjs");
3
+ let react = require("react");
4
+ let _langchain_langgraph_sdk_client = require("@langchain/langgraph-sdk/client");
5
+ //#region src/suspense-stream.tsx
6
+ const threadCache = /* @__PURE__ */ new Map();
7
+ function getCacheKey(client, threadId, limit) {
8
+ return `suspense:${(0, _langchain_langgraph_sdk_client.getClientConfigHash)(client)}:${threadId}:${limit}`;
9
+ }
10
+ function fetchThreadHistory(client, threadId, options) {
11
+ if (options?.limit === false) return client.threads.getState(threadId).then((state) => {
12
+ if (state.checkpoint == null) return [];
13
+ return [state];
14
+ });
15
+ const limit = typeof options?.limit === "number" ? options.limit : 10;
16
+ return client.threads.getHistory(threadId, { limit });
17
+ }
18
+ function getOrCreateCacheEntry(client, threadId, limit) {
19
+ const key = getCacheKey(client, threadId, limit);
20
+ let entry = threadCache.get(key);
21
+ if (!entry) {
22
+ entry = {
23
+ status: "pending",
24
+ promise: fetchThreadHistory(client, threadId, { limit }).then((data) => {
25
+ threadCache.set(key, {
26
+ status: "resolved",
27
+ data
28
+ });
29
+ }).catch((error) => {
30
+ threadCache.set(key, {
31
+ status: "rejected",
32
+ error
33
+ });
34
+ })
35
+ };
36
+ threadCache.set(key, entry);
37
+ }
38
+ return entry;
39
+ }
40
+ /**
41
+ * Clear the internal Suspense cache used by {@link useSuspenseStream}.
42
+ *
43
+ * Call this from an Error Boundary's `onReset` callback so that a retry
44
+ * triggers a fresh thread-history fetch rather than re-throwing the
45
+ * cached error.
46
+ *
47
+ * @example
48
+ * ```tsx
49
+ * <ErrorBoundary
50
+ * onReset={() => invalidateSuspenseCache()}
51
+ * fallbackRender={({ resetErrorBoundary }) => (
52
+ * <button onClick={resetErrorBoundary}>Retry</button>
53
+ * )}
54
+ * >
55
+ * <Suspense fallback={<Spinner />}>
56
+ * <Chat />
57
+ * </Suspense>
58
+ * </ErrorBoundary>
59
+ * ```
60
+ */
61
+ function invalidateSuspenseCache() {
62
+ threadCache.clear();
63
+ }
64
+ function useSuspenseStream(options) {
65
+ const client = (0, react.useMemo)(() => options.client ?? new _langchain_langgraph_sdk_client.Client({
66
+ apiUrl: options.apiUrl,
67
+ apiKey: options.apiKey,
68
+ callerOptions: options.callerOptions,
69
+ defaultHeaders: options.defaultHeaders
70
+ }), [
71
+ options.client,
72
+ options.apiKey,
73
+ options.apiUrl,
74
+ options.callerOptions,
75
+ options.defaultHeaders
76
+ ]);
77
+ const { threadId } = options;
78
+ const historyLimit = typeof options.fetchStateHistory === "object" && options.fetchStateHistory != null ? options.fetchStateHistory.limit ?? false : options.fetchStateHistory ?? false;
79
+ const needsHistoryFetch = threadId != null && options.thread == null;
80
+ let cacheEntry;
81
+ if (needsHistoryFetch) cacheEntry = getOrCreateCacheEntry(client, threadId, historyLimit);
82
+ const cachedData = cacheEntry?.status === "resolved" ? cacheEntry.data : void 0;
83
+ const cachedDataRef = (0, react.useRef)(cachedData);
84
+ if (cachedData != null) cachedDataRef.current = cachedData;
85
+ const [, setMutateVersion] = (0, react.useState)(0);
86
+ const mutate = (0, react.useCallback)(async (mutateId) => {
87
+ const fetchId = mutateId ?? threadId;
88
+ if (!fetchId) return void 0;
89
+ try {
90
+ const data = await fetchThreadHistory(client, fetchId, { limit: historyLimit });
91
+ const key = getCacheKey(client, fetchId, historyLimit);
92
+ threadCache.set(key, {
93
+ status: "resolved",
94
+ data
95
+ });
96
+ cachedDataRef.current = data;
97
+ setMutateVersion((v) => v + 1);
98
+ return data;
99
+ } catch {
100
+ return;
101
+ }
102
+ }, [
103
+ client,
104
+ threadId,
105
+ historyLimit
106
+ ]);
107
+ const thread = (0, react.useMemo)(() => {
108
+ if (!needsHistoryFetch) return options.thread;
109
+ return {
110
+ data: cachedDataRef.current,
111
+ error: void 0,
112
+ isLoading: false,
113
+ mutate
114
+ };
115
+ }, [
116
+ needsHistoryFetch,
117
+ options.thread,
118
+ cachedData,
119
+ mutate
120
+ ]);
121
+ const stream = require_stream_lgp.useStreamLGP({
122
+ ...options,
123
+ client,
124
+ thread
125
+ });
126
+ if (needsHistoryFetch && cacheEntry && !stream.isLoading) {
127
+ if (cacheEntry.status === "pending") throw cacheEntry.promise;
128
+ if (cacheEntry.status === "rejected") {
129
+ const key = getCacheKey(client, threadId, historyLimit);
130
+ threadCache.delete(key);
131
+ throw cacheEntry.error instanceof Error ? cacheEntry.error : new Error(String(cacheEntry.error));
132
+ }
133
+ }
134
+ if (stream.error != null && !stream.isLoading) throw stream.error instanceof Error ? stream.error : new Error(String(stream.error));
135
+ return {
136
+ get values() {
137
+ return stream.values;
138
+ },
139
+ get messages() {
140
+ return stream.messages;
141
+ },
142
+ get toolCalls() {
143
+ return stream.toolCalls;
144
+ },
145
+ get toolProgress() {
146
+ return stream.toolProgress;
147
+ },
148
+ getToolCalls: stream.getToolCalls.bind(stream),
149
+ get interrupt() {
150
+ return stream.interrupt;
151
+ },
152
+ get interrupts() {
153
+ return stream.interrupts;
154
+ },
155
+ get subagents() {
156
+ return stream.subagents;
157
+ },
158
+ get activeSubagents() {
159
+ return stream.activeSubagents;
160
+ },
161
+ getSubagent: stream.getSubagent.bind(stream),
162
+ getSubagentsByType: stream.getSubagentsByType.bind(stream),
163
+ getSubagentsByMessage: stream.getSubagentsByMessage.bind(stream),
164
+ getMessagesMetadata: stream.getMessagesMetadata.bind(stream),
165
+ get history() {
166
+ return stream.history;
167
+ },
168
+ get experimental_branchTree() {
169
+ return stream.experimental_branchTree;
170
+ },
171
+ stop: stream.stop,
172
+ submit: stream.submit,
173
+ switchThread: stream.switchThread,
174
+ joinStream: stream.joinStream,
175
+ branch: stream.branch,
176
+ setBranch: stream.setBranch,
177
+ client: stream.client,
178
+ assistantId: stream.assistantId,
179
+ queue: stream.queue,
180
+ isStreaming: stream.isLoading
181
+ };
182
+ }
183
+ //#endregion
184
+ exports.invalidateSuspenseCache = invalidateSuspenseCache;
185
+ exports.useSuspenseStream = useSuspenseStream;
186
+
187
+ //# sourceMappingURL=suspense-stream.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"suspense-stream.cjs","names":["Client","useStreamLGP"],"sources":["../src/suspense-stream.tsx"],"sourcesContent":["/* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */\n\n\"use client\";\n\nimport { useCallback, useMemo, useRef, useState } from \"react\";\nimport type { ThreadState, BagTemplate } from \"@langchain/langgraph-sdk\";\nimport { Client, getClientConfigHash } from \"@langchain/langgraph-sdk/client\";\nimport type {\n UseStreamThread,\n ResolveStreamOptions,\n ResolveStreamInterface,\n InferBag,\n} from \"@langchain/langgraph-sdk/ui\";\nimport { useStreamLGP } from \"./stream.lgp.js\";\nimport type { WithClassMessages } from \"./stream.js\";\n\n// ---------------------------------------------------------------------------\n// Suspense cache\n// ---------------------------------------------------------------------------\n\ntype SuspenseCacheEntry<T> =\n | { status: \"pending\"; promise: Promise<void> }\n | { status: \"resolved\"; data: T }\n | { status: \"rejected\"; error: unknown };\n\nconst threadCache = new Map<string, SuspenseCacheEntry<unknown>>();\n\nfunction getCacheKey(\n client: Client,\n threadId: string,\n limit: boolean | number,\n): string {\n return `suspense:${getClientConfigHash(client)}:${threadId}:${limit}`;\n}\n\nfunction fetchThreadHistory<StateType extends Record<string, unknown>>(\n client: Client,\n threadId: string,\n options?: { limit?: boolean | number },\n): Promise<ThreadState<StateType>[]> {\n if (options?.limit === false) {\n return client.threads.getState<StateType>(threadId).then((state) => {\n if (state.checkpoint == null) return [];\n return [state];\n });\n }\n\n const limit = typeof options?.limit === \"number\" ? options.limit : 10;\n return client.threads.getHistory<StateType>(threadId, { limit });\n}\n\nfunction getOrCreateCacheEntry<StateType extends Record<string, unknown>>(\n client: Client,\n threadId: string,\n limit: boolean | number,\n): SuspenseCacheEntry<ThreadState<StateType>[]> {\n const key = getCacheKey(client, threadId, limit);\n let entry = threadCache.get(key) as\n | SuspenseCacheEntry<ThreadState<StateType>[]>\n | undefined;\n\n if (!entry) {\n // Start fetch. The promise always resolves (never rejects) so React\n // Suspense correctly waits for it and then retries the render.\n const promise = fetchThreadHistory<StateType>(client, threadId, { limit })\n .then((data) => {\n threadCache.set(key, { status: \"resolved\", data });\n })\n .catch((error: unknown) => {\n threadCache.set(key, { status: \"rejected\", error });\n });\n\n entry = { status: \"pending\", promise };\n threadCache.set(key, entry);\n }\n\n return entry;\n}\n\n/**\n * Clear the internal Suspense cache used by {@link useSuspenseStream}.\n *\n * Call this from an Error Boundary's `onReset` callback so that a retry\n * triggers a fresh thread-history fetch rather than re-throwing the\n * cached error.\n *\n * @example\n * ```tsx\n * <ErrorBoundary\n * onReset={() => invalidateSuspenseCache()}\n * fallbackRender={({ resetErrorBoundary }) => (\n * <button onClick={resetErrorBoundary}>Retry</button>\n * )}\n * >\n * <Suspense fallback={<Spinner />}>\n * <Chat />\n * </Suspense>\n * </ErrorBoundary>\n * ```\n */\nexport function invalidateSuspenseCache(): void {\n threadCache.clear();\n}\n\n// ---------------------------------------------------------------------------\n// Return-type helper\n// ---------------------------------------------------------------------------\n\ntype WithSuspense<T> = Omit<T, \"isLoading\" | \"error\" | \"isThreadLoading\"> & {\n isStreaming: boolean;\n};\n\n// ---------------------------------------------------------------------------\n// Hook\n// ---------------------------------------------------------------------------\n\n/**\n * A Suspense-compatible variant of {@link useStream} for LangGraph Platform.\n *\n * `useSuspenseStream` suspends the component while the initial thread\n * history is being fetched and throws errors to the nearest React Error\n * Boundary. During active streaming the component stays rendered and\n * `isStreaming` indicates whether tokens are arriving.\n *\n * @example\n * ```tsx\n * <ErrorBoundary fallback={<ErrorDisplay />}>\n * <Suspense fallback={<Spinner />}>\n * <Chat />\n * </Suspense>\n * </ErrorBoundary>\n *\n * function Chat() {\n * const { messages, submit, isStreaming } = useSuspenseStream({\n * assistantId: \"agent\",\n * apiUrl: \"http://localhost:2024\",\n * });\n * return <MessageList messages={messages} />;\n * }\n * ```\n *\n * @template T - Either a ReactAgent / DeepAgent type or a state record type.\n * @template Bag - Type configuration bag (ConfigurableType, InterruptType, …).\n */\nexport function useSuspenseStream<\n T = Record<string, unknown>,\n Bag extends BagTemplate = BagTemplate,\n>(\n options: ResolveStreamOptions<T, InferBag<T, Bag>>,\n): WithClassMessages<WithSuspense<ResolveStreamInterface<T, InferBag<T, Bag>>>>;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function useSuspenseStream(options: any): any {\n type StateType = Record<string, unknown>;\n\n // ---- client (needed before useStreamLGP for cache key derivation) ----\n const client = useMemo(\n () =>\n options.client ??\n new Client({\n apiUrl: options.apiUrl,\n apiKey: options.apiKey,\n callerOptions: options.callerOptions,\n defaultHeaders: options.defaultHeaders,\n }),\n [\n options.client,\n options.apiKey,\n options.apiUrl,\n options.callerOptions,\n options.defaultHeaders,\n ],\n );\n\n const { threadId } = options;\n\n const historyLimit: boolean | number =\n typeof options.fetchStateHistory === \"object\" &&\n options.fetchStateHistory != null\n ? (options.fetchStateHistory.limit ?? false)\n : (options.fetchStateHistory ?? false);\n\n // Only manage history via the suspense cache when the caller hasn't\n // supplied an external `thread` and there's a threadId to load.\n const needsHistoryFetch = threadId != null && options.thread == null;\n\n // ---- suspense cache lookup (synchronous, may create fetch) ----\n let cacheEntry: SuspenseCacheEntry<ThreadState<StateType>[]> | undefined;\n\n if (needsHistoryFetch) {\n cacheEntry = getOrCreateCacheEntry<StateType>(\n client,\n threadId,\n historyLimit,\n );\n }\n\n const cachedData =\n cacheEntry?.status === \"resolved\" ? cacheEntry.data : undefined;\n\n // ---- mutable ref so `mutate` always writes the freshest data ----\n const cachedDataRef = useRef(cachedData);\n if (cachedData != null) {\n cachedDataRef.current = cachedData;\n }\n\n // Re-render trigger after external mutate calls.\n const [, setMutateVersion] = useState(0);\n\n const mutate = useCallback(\n async (\n mutateId?: string,\n ): Promise<ThreadState<StateType>[] | null | undefined> => {\n const fetchId = mutateId ?? threadId;\n if (!fetchId) return undefined;\n try {\n const data = await fetchThreadHistory<StateType>(client, fetchId, {\n limit: historyLimit,\n });\n const key = getCacheKey(client, fetchId, historyLimit);\n threadCache.set(key, { status: \"resolved\", data });\n cachedDataRef.current = data;\n setMutateVersion((v) => v + 1);\n return data;\n } catch {\n return undefined;\n }\n },\n [client, threadId, historyLimit],\n );\n\n // ---- build thread override for useStreamLGP ----\n const thread: UseStreamThread<StateType> | undefined = useMemo(() => {\n if (!needsHistoryFetch) return options.thread;\n return {\n data: cachedDataRef.current,\n error: undefined,\n isLoading: false,\n mutate,\n };\n // `cachedData` is included so the memo recomputes when the cache\n // transitions from pending → resolved across suspend/retry cycles.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [needsHistoryFetch, options.thread, cachedData, mutate]);\n\n // ---- delegate to useStreamLGP (must always run – Rules of Hooks) ----\n const stream = useStreamLGP({\n ...options,\n client,\n thread,\n });\n\n // ---- post-hook: suspend or throw ----\n\n // Suspend while thread history is loading, but only when the stream\n // itself is idle. If an active stream is running (e.g. the thread was\n // just created during submit), suspending would discard the stream\n // state, so we skip it.\n if (needsHistoryFetch && cacheEntry && !stream.isLoading) {\n if (cacheEntry.status === \"pending\") {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw cacheEntry.promise;\n }\n if (cacheEntry.status === \"rejected\") {\n // Clear cache so a subsequent retry (ErrorBoundary reset) starts\n // a fresh fetch instead of re-throwing the stale error.\n const key = getCacheKey(client, threadId!, historyLimit);\n threadCache.delete(key);\n // eslint-disable-next-line no-instanceof/no-instanceof\n throw cacheEntry.error instanceof Error\n ? cacheEntry.error\n : new Error(String(cacheEntry.error));\n }\n }\n\n // Throw non-streaming errors to the nearest Error Boundary.\n if (stream.error != null && !stream.isLoading) {\n // eslint-disable-next-line no-instanceof/no-instanceof\n throw stream.error instanceof Error\n ? stream.error\n : new Error(String(stream.error));\n }\n\n // Build return object explicitly to avoid triggering throwing getters\n // (e.g. `history` throws when `fetchStateHistory` is not set).\n return {\n get values() {\n return stream.values;\n },\n get messages() {\n return stream.messages;\n },\n get toolCalls() {\n return stream.toolCalls;\n },\n get toolProgress() {\n return stream.toolProgress;\n },\n getToolCalls: stream.getToolCalls.bind(stream),\n get interrupt() {\n return stream.interrupt;\n },\n get interrupts() {\n return stream.interrupts;\n },\n get subagents() {\n return stream.subagents;\n },\n get activeSubagents() {\n return stream.activeSubagents;\n },\n getSubagent: stream.getSubagent.bind(stream),\n getSubagentsByType: stream.getSubagentsByType.bind(stream),\n getSubagentsByMessage: stream.getSubagentsByMessage.bind(stream),\n getMessagesMetadata: stream.getMessagesMetadata.bind(stream),\n get history() {\n return stream.history;\n },\n get experimental_branchTree() {\n return stream.experimental_branchTree;\n },\n stop: stream.stop,\n submit: stream.submit,\n switchThread: stream.switchThread,\n joinStream: stream.joinStream,\n branch: stream.branch,\n setBranch: stream.setBranch,\n client: stream.client,\n assistantId: stream.assistantId,\n queue: stream.queue,\n isStreaming: stream.isLoading,\n };\n}\n"],"mappings":";;;;;AAyBA,MAAM,8BAAc,IAAI,KAA0C;AAElE,SAAS,YACP,QACA,UACA,OACQ;AACR,QAAO,aAAA,GAAA,gCAAA,qBAAgC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C;;;AAK3C,KAAI,OAAO,SAAS,QAAQ,CAAC,OAAO,UAElC,OAAM,OAAO,iBAAiB,QAC1B,OAAO,QACP,IAAI,MAAM,OAAO,OAAO,MAAM,CAAC;AAKrC,QAAO;EACL,IAAI,SAAS;AACX,UAAO,OAAO;;EAEhB,IAAI,WAAW;AACb,UAAO,OAAO;;EAEhB,IAAI,YAAY;AACd,UAAO,OAAO;;EAEhB,IAAI,eAAe;AACjB,UAAO,OAAO;;EAEhB,cAAc,OAAO,aAAa,KAAK,OAAO;EAC9C,IAAI,YAAY;AACd,UAAO,OAAO;;EAEhB,IAAI,aAAa;AACf,UAAO,OAAO;;EAEhB,IAAI,YAAY;AACd,UAAO,OAAO;;EAEhB,IAAI,kBAAkB;AACpB,UAAO,OAAO;;EAEhB,aAAa,OAAO,YAAY,KAAK,OAAO;EAC5C,oBAAoB,OAAO,mBAAmB,KAAK,OAAO;EAC1D,uBAAuB,OAAO,sBAAsB,KAAK,OAAO;EAChE,qBAAqB,OAAO,oBAAoB,KAAK,OAAO;EAC5D,IAAI,UAAU;AACZ,UAAO,OAAO;;EAEhB,IAAI,0BAA0B;AAC5B,UAAO,OAAO;;EAEhB,MAAM,OAAO;EACb,QAAQ,OAAO;EACf,cAAc,OAAO;EACrB,YAAY,OAAO;EACnB,QAAQ,OAAO;EACf,WAAW,OAAO;EAClB,QAAQ,OAAO;EACf,aAAa,OAAO;EACpB,OAAO,OAAO;EACd,aAAa,OAAO;EACrB"}
@@ -0,0 +1,62 @@
1
+ import { WithClassMessages } from "./stream.cjs";
2
+ import { BagTemplate } from "@langchain/langgraph-sdk";
3
+ import { InferBag, ResolveStreamInterface, ResolveStreamOptions } from "@langchain/langgraph-sdk/ui";
4
+
5
+ //#region src/suspense-stream.d.ts
6
+ /**
7
+ * Clear the internal Suspense cache used by {@link useSuspenseStream}.
8
+ *
9
+ * Call this from an Error Boundary's `onReset` callback so that a retry
10
+ * triggers a fresh thread-history fetch rather than re-throwing the
11
+ * cached error.
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * <ErrorBoundary
16
+ * onReset={() => invalidateSuspenseCache()}
17
+ * fallbackRender={({ resetErrorBoundary }) => (
18
+ * <button onClick={resetErrorBoundary}>Retry</button>
19
+ * )}
20
+ * >
21
+ * <Suspense fallback={<Spinner />}>
22
+ * <Chat />
23
+ * </Suspense>
24
+ * </ErrorBoundary>
25
+ * ```
26
+ */
27
+ declare function invalidateSuspenseCache(): void;
28
+ type WithSuspense<T> = Omit<T, "isLoading" | "error" | "isThreadLoading"> & {
29
+ isStreaming: boolean;
30
+ };
31
+ /**
32
+ * A Suspense-compatible variant of {@link useStream} for LangGraph Platform.
33
+ *
34
+ * `useSuspenseStream` suspends the component while the initial thread
35
+ * history is being fetched and throws errors to the nearest React Error
36
+ * Boundary. During active streaming the component stays rendered and
37
+ * `isStreaming` indicates whether tokens are arriving.
38
+ *
39
+ * @example
40
+ * ```tsx
41
+ * <ErrorBoundary fallback={<ErrorDisplay />}>
42
+ * <Suspense fallback={<Spinner />}>
43
+ * <Chat />
44
+ * </Suspense>
45
+ * </ErrorBoundary>
46
+ *
47
+ * function Chat() {
48
+ * const { messages, submit, isStreaming } = useSuspenseStream({
49
+ * assistantId: "agent",
50
+ * apiUrl: "http://localhost:2024",
51
+ * });
52
+ * return <MessageList messages={messages} />;
53
+ * }
54
+ * ```
55
+ *
56
+ * @template T - Either a ReactAgent / DeepAgent type or a state record type.
57
+ * @template Bag - Type configuration bag (ConfigurableType, InterruptType, …).
58
+ */
59
+ declare function useSuspenseStream<T = Record<string, unknown>, Bag extends BagTemplate = BagTemplate>(options: ResolveStreamOptions<T, InferBag<T, Bag>>): WithClassMessages<WithSuspense<ResolveStreamInterface<T, InferBag<T, Bag>>>>;
60
+ //#endregion
61
+ export { invalidateSuspenseCache, useSuspenseStream };
62
+ //# sourceMappingURL=suspense-stream.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"suspense-stream.d.cts","names":[],"sources":["../src/suspense-stream.tsx"],"mappings":";;;;;;;AAoGA;;;;;AAEC;;;;;;;;;;AA0CD;;;;iBA5CgB,uBAAA,CAAA;AAAA,KAQX,YAAA,MAAkB,IAAA,CAAK,CAAA;EAC1B,WAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAmCc,iBAAA,KACV,MAAA,+BACQ,WAAA,GAAc,WAAA,CAAA,CAE1B,OAAA,EAAS,oBAAA,CAAqB,CAAA,EAAG,QAAA,CAAS,CAAA,EAAG,GAAA,KAC5C,iBAAA,CAAkB,YAAA,CAAa,sBAAA,CAAuB,CAAA,EAAG,QAAA,CAAS,CAAA,EAAG,GAAA"}
@@ -0,0 +1,62 @@
1
+ import { WithClassMessages } from "./stream.js";
2
+ import { InferBag, ResolveStreamInterface, ResolveStreamOptions } from "@langchain/langgraph-sdk/ui";
3
+ import { BagTemplate } from "@langchain/langgraph-sdk";
4
+
5
+ //#region src/suspense-stream.d.ts
6
+ /**
7
+ * Clear the internal Suspense cache used by {@link useSuspenseStream}.
8
+ *
9
+ * Call this from an Error Boundary's `onReset` callback so that a retry
10
+ * triggers a fresh thread-history fetch rather than re-throwing the
11
+ * cached error.
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * <ErrorBoundary
16
+ * onReset={() => invalidateSuspenseCache()}
17
+ * fallbackRender={({ resetErrorBoundary }) => (
18
+ * <button onClick={resetErrorBoundary}>Retry</button>
19
+ * )}
20
+ * >
21
+ * <Suspense fallback={<Spinner />}>
22
+ * <Chat />
23
+ * </Suspense>
24
+ * </ErrorBoundary>
25
+ * ```
26
+ */
27
+ declare function invalidateSuspenseCache(): void;
28
+ type WithSuspense<T> = Omit<T, "isLoading" | "error" | "isThreadLoading"> & {
29
+ isStreaming: boolean;
30
+ };
31
+ /**
32
+ * A Suspense-compatible variant of {@link useStream} for LangGraph Platform.
33
+ *
34
+ * `useSuspenseStream` suspends the component while the initial thread
35
+ * history is being fetched and throws errors to the nearest React Error
36
+ * Boundary. During active streaming the component stays rendered and
37
+ * `isStreaming` indicates whether tokens are arriving.
38
+ *
39
+ * @example
40
+ * ```tsx
41
+ * <ErrorBoundary fallback={<ErrorDisplay />}>
42
+ * <Suspense fallback={<Spinner />}>
43
+ * <Chat />
44
+ * </Suspense>
45
+ * </ErrorBoundary>
46
+ *
47
+ * function Chat() {
48
+ * const { messages, submit, isStreaming } = useSuspenseStream({
49
+ * assistantId: "agent",
50
+ * apiUrl: "http://localhost:2024",
51
+ * });
52
+ * return <MessageList messages={messages} />;
53
+ * }
54
+ * ```
55
+ *
56
+ * @template T - Either a ReactAgent / DeepAgent type or a state record type.
57
+ * @template Bag - Type configuration bag (ConfigurableType, InterruptType, …).
58
+ */
59
+ declare function useSuspenseStream<T = Record<string, unknown>, Bag extends BagTemplate = BagTemplate>(options: ResolveStreamOptions<T, InferBag<T, Bag>>): WithClassMessages<WithSuspense<ResolveStreamInterface<T, InferBag<T, Bag>>>>;
60
+ //#endregion
61
+ export { invalidateSuspenseCache, useSuspenseStream };
62
+ //# sourceMappingURL=suspense-stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"suspense-stream.d.ts","names":[],"sources":["../src/suspense-stream.tsx"],"mappings":";;;;;;;AAoGA;;;;;AAEC;;;;;;;;;;AA0CD;;;;iBA5CgB,uBAAA,CAAA;AAAA,KAQX,YAAA,MAAkB,IAAA,CAAK,CAAA;EAC1B,WAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAmCc,iBAAA,KACV,MAAA,+BACQ,WAAA,GAAc,WAAA,CAAA,CAE1B,OAAA,EAAS,oBAAA,CAAqB,CAAA,EAAG,QAAA,CAAS,CAAA,EAAG,GAAA,KAC5C,iBAAA,CAAkB,YAAA,CAAa,sBAAA,CAAuB,CAAA,EAAG,QAAA,CAAS,CAAA,EAAG,GAAA"}
@@ -0,0 +1,186 @@
1
+ "use client";
2
+ import { useStreamLGP } from "./stream.lgp.js";
3
+ import { useCallback, useMemo, useRef, useState } from "react";
4
+ import { Client, getClientConfigHash } from "@langchain/langgraph-sdk/client";
5
+ //#region src/suspense-stream.tsx
6
+ const threadCache = /* @__PURE__ */ new Map();
7
+ function getCacheKey(client, threadId, limit) {
8
+ return `suspense:${getClientConfigHash(client)}:${threadId}:${limit}`;
9
+ }
10
+ function fetchThreadHistory(client, threadId, options) {
11
+ if (options?.limit === false) return client.threads.getState(threadId).then((state) => {
12
+ if (state.checkpoint == null) return [];
13
+ return [state];
14
+ });
15
+ const limit = typeof options?.limit === "number" ? options.limit : 10;
16
+ return client.threads.getHistory(threadId, { limit });
17
+ }
18
+ function getOrCreateCacheEntry(client, threadId, limit) {
19
+ const key = getCacheKey(client, threadId, limit);
20
+ let entry = threadCache.get(key);
21
+ if (!entry) {
22
+ entry = {
23
+ status: "pending",
24
+ promise: fetchThreadHistory(client, threadId, { limit }).then((data) => {
25
+ threadCache.set(key, {
26
+ status: "resolved",
27
+ data
28
+ });
29
+ }).catch((error) => {
30
+ threadCache.set(key, {
31
+ status: "rejected",
32
+ error
33
+ });
34
+ })
35
+ };
36
+ threadCache.set(key, entry);
37
+ }
38
+ return entry;
39
+ }
40
+ /**
41
+ * Clear the internal Suspense cache used by {@link useSuspenseStream}.
42
+ *
43
+ * Call this from an Error Boundary's `onReset` callback so that a retry
44
+ * triggers a fresh thread-history fetch rather than re-throwing the
45
+ * cached error.
46
+ *
47
+ * @example
48
+ * ```tsx
49
+ * <ErrorBoundary
50
+ * onReset={() => invalidateSuspenseCache()}
51
+ * fallbackRender={({ resetErrorBoundary }) => (
52
+ * <button onClick={resetErrorBoundary}>Retry</button>
53
+ * )}
54
+ * >
55
+ * <Suspense fallback={<Spinner />}>
56
+ * <Chat />
57
+ * </Suspense>
58
+ * </ErrorBoundary>
59
+ * ```
60
+ */
61
+ function invalidateSuspenseCache() {
62
+ threadCache.clear();
63
+ }
64
+ function useSuspenseStream(options) {
65
+ const client = useMemo(() => options.client ?? new Client({
66
+ apiUrl: options.apiUrl,
67
+ apiKey: options.apiKey,
68
+ callerOptions: options.callerOptions,
69
+ defaultHeaders: options.defaultHeaders
70
+ }), [
71
+ options.client,
72
+ options.apiKey,
73
+ options.apiUrl,
74
+ options.callerOptions,
75
+ options.defaultHeaders
76
+ ]);
77
+ const { threadId } = options;
78
+ const historyLimit = typeof options.fetchStateHistory === "object" && options.fetchStateHistory != null ? options.fetchStateHistory.limit ?? false : options.fetchStateHistory ?? false;
79
+ const needsHistoryFetch = threadId != null && options.thread == null;
80
+ let cacheEntry;
81
+ if (needsHistoryFetch) cacheEntry = getOrCreateCacheEntry(client, threadId, historyLimit);
82
+ const cachedData = cacheEntry?.status === "resolved" ? cacheEntry.data : void 0;
83
+ const cachedDataRef = useRef(cachedData);
84
+ if (cachedData != null) cachedDataRef.current = cachedData;
85
+ const [, setMutateVersion] = useState(0);
86
+ const mutate = useCallback(async (mutateId) => {
87
+ const fetchId = mutateId ?? threadId;
88
+ if (!fetchId) return void 0;
89
+ try {
90
+ const data = await fetchThreadHistory(client, fetchId, { limit: historyLimit });
91
+ const key = getCacheKey(client, fetchId, historyLimit);
92
+ threadCache.set(key, {
93
+ status: "resolved",
94
+ data
95
+ });
96
+ cachedDataRef.current = data;
97
+ setMutateVersion((v) => v + 1);
98
+ return data;
99
+ } catch {
100
+ return;
101
+ }
102
+ }, [
103
+ client,
104
+ threadId,
105
+ historyLimit
106
+ ]);
107
+ const thread = useMemo(() => {
108
+ if (!needsHistoryFetch) return options.thread;
109
+ return {
110
+ data: cachedDataRef.current,
111
+ error: void 0,
112
+ isLoading: false,
113
+ mutate
114
+ };
115
+ }, [
116
+ needsHistoryFetch,
117
+ options.thread,
118
+ cachedData,
119
+ mutate
120
+ ]);
121
+ const stream = useStreamLGP({
122
+ ...options,
123
+ client,
124
+ thread
125
+ });
126
+ if (needsHistoryFetch && cacheEntry && !stream.isLoading) {
127
+ if (cacheEntry.status === "pending") throw cacheEntry.promise;
128
+ if (cacheEntry.status === "rejected") {
129
+ const key = getCacheKey(client, threadId, historyLimit);
130
+ threadCache.delete(key);
131
+ throw cacheEntry.error instanceof Error ? cacheEntry.error : new Error(String(cacheEntry.error));
132
+ }
133
+ }
134
+ if (stream.error != null && !stream.isLoading) throw stream.error instanceof Error ? stream.error : new Error(String(stream.error));
135
+ return {
136
+ get values() {
137
+ return stream.values;
138
+ },
139
+ get messages() {
140
+ return stream.messages;
141
+ },
142
+ get toolCalls() {
143
+ return stream.toolCalls;
144
+ },
145
+ get toolProgress() {
146
+ return stream.toolProgress;
147
+ },
148
+ getToolCalls: stream.getToolCalls.bind(stream),
149
+ get interrupt() {
150
+ return stream.interrupt;
151
+ },
152
+ get interrupts() {
153
+ return stream.interrupts;
154
+ },
155
+ get subagents() {
156
+ return stream.subagents;
157
+ },
158
+ get activeSubagents() {
159
+ return stream.activeSubagents;
160
+ },
161
+ getSubagent: stream.getSubagent.bind(stream),
162
+ getSubagentsByType: stream.getSubagentsByType.bind(stream),
163
+ getSubagentsByMessage: stream.getSubagentsByMessage.bind(stream),
164
+ getMessagesMetadata: stream.getMessagesMetadata.bind(stream),
165
+ get history() {
166
+ return stream.history;
167
+ },
168
+ get experimental_branchTree() {
169
+ return stream.experimental_branchTree;
170
+ },
171
+ stop: stream.stop,
172
+ submit: stream.submit,
173
+ switchThread: stream.switchThread,
174
+ joinStream: stream.joinStream,
175
+ branch: stream.branch,
176
+ setBranch: stream.setBranch,
177
+ client: stream.client,
178
+ assistantId: stream.assistantId,
179
+ queue: stream.queue,
180
+ isStreaming: stream.isLoading
181
+ };
182
+ }
183
+ //#endregion
184
+ export { invalidateSuspenseCache, useSuspenseStream };
185
+
186
+ //# sourceMappingURL=suspense-stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"suspense-stream.js","names":[],"sources":["../src/suspense-stream.tsx"],"sourcesContent":["/* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */\n\n\"use client\";\n\nimport { useCallback, useMemo, useRef, useState } from \"react\";\nimport type { ThreadState, BagTemplate } from \"@langchain/langgraph-sdk\";\nimport { Client, getClientConfigHash } from \"@langchain/langgraph-sdk/client\";\nimport type {\n UseStreamThread,\n ResolveStreamOptions,\n ResolveStreamInterface,\n InferBag,\n} from \"@langchain/langgraph-sdk/ui\";\nimport { useStreamLGP } from \"./stream.lgp.js\";\nimport type { WithClassMessages } from \"./stream.js\";\n\n// ---------------------------------------------------------------------------\n// Suspense cache\n// ---------------------------------------------------------------------------\n\ntype SuspenseCacheEntry<T> =\n | { status: \"pending\"; promise: Promise<void> }\n | { status: \"resolved\"; data: T }\n | { status: \"rejected\"; error: unknown };\n\nconst threadCache = new Map<string, SuspenseCacheEntry<unknown>>();\n\nfunction getCacheKey(\n client: Client,\n threadId: string,\n limit: boolean | number,\n): string {\n return `suspense:${getClientConfigHash(client)}:${threadId}:${limit}`;\n}\n\nfunction fetchThreadHistory<StateType extends Record<string, unknown>>(\n client: Client,\n threadId: string,\n options?: { limit?: boolean | number },\n): Promise<ThreadState<StateType>[]> {\n if (options?.limit === false) {\n return client.threads.getState<StateType>(threadId).then((state) => {\n if (state.checkpoint == null) return [];\n return [state];\n });\n }\n\n const limit = typeof options?.limit === \"number\" ? options.limit : 10;\n return client.threads.getHistory<StateType>(threadId, { limit });\n}\n\nfunction getOrCreateCacheEntry<StateType extends Record<string, unknown>>(\n client: Client,\n threadId: string,\n limit: boolean | number,\n): SuspenseCacheEntry<ThreadState<StateType>[]> {\n const key = getCacheKey(client, threadId, limit);\n let entry = threadCache.get(key) as\n | SuspenseCacheEntry<ThreadState<StateType>[]>\n | undefined;\n\n if (!entry) {\n // Start fetch. The promise always resolves (never rejects) so React\n // Suspense correctly waits for it and then retries the render.\n const promise = fetchThreadHistory<StateType>(client, threadId, { limit })\n .then((data) => {\n threadCache.set(key, { status: \"resolved\", data });\n })\n .catch((error: unknown) => {\n threadCache.set(key, { status: \"rejected\", error });\n });\n\n entry = { status: \"pending\", promise };\n threadCache.set(key, entry);\n }\n\n return entry;\n}\n\n/**\n * Clear the internal Suspense cache used by {@link useSuspenseStream}.\n *\n * Call this from an Error Boundary's `onReset` callback so that a retry\n * triggers a fresh thread-history fetch rather than re-throwing the\n * cached error.\n *\n * @example\n * ```tsx\n * <ErrorBoundary\n * onReset={() => invalidateSuspenseCache()}\n * fallbackRender={({ resetErrorBoundary }) => (\n * <button onClick={resetErrorBoundary}>Retry</button>\n * )}\n * >\n * <Suspense fallback={<Spinner />}>\n * <Chat />\n * </Suspense>\n * </ErrorBoundary>\n * ```\n */\nexport function invalidateSuspenseCache(): void {\n threadCache.clear();\n}\n\n// ---------------------------------------------------------------------------\n// Return-type helper\n// ---------------------------------------------------------------------------\n\ntype WithSuspense<T> = Omit<T, \"isLoading\" | \"error\" | \"isThreadLoading\"> & {\n isStreaming: boolean;\n};\n\n// ---------------------------------------------------------------------------\n// Hook\n// ---------------------------------------------------------------------------\n\n/**\n * A Suspense-compatible variant of {@link useStream} for LangGraph Platform.\n *\n * `useSuspenseStream` suspends the component while the initial thread\n * history is being fetched and throws errors to the nearest React Error\n * Boundary. During active streaming the component stays rendered and\n * `isStreaming` indicates whether tokens are arriving.\n *\n * @example\n * ```tsx\n * <ErrorBoundary fallback={<ErrorDisplay />}>\n * <Suspense fallback={<Spinner />}>\n * <Chat />\n * </Suspense>\n * </ErrorBoundary>\n *\n * function Chat() {\n * const { messages, submit, isStreaming } = useSuspenseStream({\n * assistantId: \"agent\",\n * apiUrl: \"http://localhost:2024\",\n * });\n * return <MessageList messages={messages} />;\n * }\n * ```\n *\n * @template T - Either a ReactAgent / DeepAgent type or a state record type.\n * @template Bag - Type configuration bag (ConfigurableType, InterruptType, …).\n */\nexport function useSuspenseStream<\n T = Record<string, unknown>,\n Bag extends BagTemplate = BagTemplate,\n>(\n options: ResolveStreamOptions<T, InferBag<T, Bag>>,\n): WithClassMessages<WithSuspense<ResolveStreamInterface<T, InferBag<T, Bag>>>>;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function useSuspenseStream(options: any): any {\n type StateType = Record<string, unknown>;\n\n // ---- client (needed before useStreamLGP for cache key derivation) ----\n const client = useMemo(\n () =>\n options.client ??\n new Client({\n apiUrl: options.apiUrl,\n apiKey: options.apiKey,\n callerOptions: options.callerOptions,\n defaultHeaders: options.defaultHeaders,\n }),\n [\n options.client,\n options.apiKey,\n options.apiUrl,\n options.callerOptions,\n options.defaultHeaders,\n ],\n );\n\n const { threadId } = options;\n\n const historyLimit: boolean | number =\n typeof options.fetchStateHistory === \"object\" &&\n options.fetchStateHistory != null\n ? (options.fetchStateHistory.limit ?? false)\n : (options.fetchStateHistory ?? false);\n\n // Only manage history via the suspense cache when the caller hasn't\n // supplied an external `thread` and there's a threadId to load.\n const needsHistoryFetch = threadId != null && options.thread == null;\n\n // ---- suspense cache lookup (synchronous, may create fetch) ----\n let cacheEntry: SuspenseCacheEntry<ThreadState<StateType>[]> | undefined;\n\n if (needsHistoryFetch) {\n cacheEntry = getOrCreateCacheEntry<StateType>(\n client,\n threadId,\n historyLimit,\n );\n }\n\n const cachedData =\n cacheEntry?.status === \"resolved\" ? cacheEntry.data : undefined;\n\n // ---- mutable ref so `mutate` always writes the freshest data ----\n const cachedDataRef = useRef(cachedData);\n if (cachedData != null) {\n cachedDataRef.current = cachedData;\n }\n\n // Re-render trigger after external mutate calls.\n const [, setMutateVersion] = useState(0);\n\n const mutate = useCallback(\n async (\n mutateId?: string,\n ): Promise<ThreadState<StateType>[] | null | undefined> => {\n const fetchId = mutateId ?? threadId;\n if (!fetchId) return undefined;\n try {\n const data = await fetchThreadHistory<StateType>(client, fetchId, {\n limit: historyLimit,\n });\n const key = getCacheKey(client, fetchId, historyLimit);\n threadCache.set(key, { status: \"resolved\", data });\n cachedDataRef.current = data;\n setMutateVersion((v) => v + 1);\n return data;\n } catch {\n return undefined;\n }\n },\n [client, threadId, historyLimit],\n );\n\n // ---- build thread override for useStreamLGP ----\n const thread: UseStreamThread<StateType> | undefined = useMemo(() => {\n if (!needsHistoryFetch) return options.thread;\n return {\n data: cachedDataRef.current,\n error: undefined,\n isLoading: false,\n mutate,\n };\n // `cachedData` is included so the memo recomputes when the cache\n // transitions from pending → resolved across suspend/retry cycles.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [needsHistoryFetch, options.thread, cachedData, mutate]);\n\n // ---- delegate to useStreamLGP (must always run – Rules of Hooks) ----\n const stream = useStreamLGP({\n ...options,\n client,\n thread,\n });\n\n // ---- post-hook: suspend or throw ----\n\n // Suspend while thread history is loading, but only when the stream\n // itself is idle. If an active stream is running (e.g. the thread was\n // just created during submit), suspending would discard the stream\n // state, so we skip it.\n if (needsHistoryFetch && cacheEntry && !stream.isLoading) {\n if (cacheEntry.status === \"pending\") {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw cacheEntry.promise;\n }\n if (cacheEntry.status === \"rejected\") {\n // Clear cache so a subsequent retry (ErrorBoundary reset) starts\n // a fresh fetch instead of re-throwing the stale error.\n const key = getCacheKey(client, threadId!, historyLimit);\n threadCache.delete(key);\n // eslint-disable-next-line no-instanceof/no-instanceof\n throw cacheEntry.error instanceof Error\n ? cacheEntry.error\n : new Error(String(cacheEntry.error));\n }\n }\n\n // Throw non-streaming errors to the nearest Error Boundary.\n if (stream.error != null && !stream.isLoading) {\n // eslint-disable-next-line no-instanceof/no-instanceof\n throw stream.error instanceof Error\n ? stream.error\n : new Error(String(stream.error));\n }\n\n // Build return object explicitly to avoid triggering throwing getters\n // (e.g. `history` throws when `fetchStateHistory` is not set).\n return {\n get values() {\n return stream.values;\n },\n get messages() {\n return stream.messages;\n },\n get toolCalls() {\n return stream.toolCalls;\n },\n get toolProgress() {\n return stream.toolProgress;\n },\n getToolCalls: stream.getToolCalls.bind(stream),\n get interrupt() {\n return stream.interrupt;\n },\n get interrupts() {\n return stream.interrupts;\n },\n get subagents() {\n return stream.subagents;\n },\n get activeSubagents() {\n return stream.activeSubagents;\n },\n getSubagent: stream.getSubagent.bind(stream),\n getSubagentsByType: stream.getSubagentsByType.bind(stream),\n getSubagentsByMessage: stream.getSubagentsByMessage.bind(stream),\n getMessagesMetadata: stream.getMessagesMetadata.bind(stream),\n get history() {\n return stream.history;\n },\n get experimental_branchTree() {\n return stream.experimental_branchTree;\n },\n stop: stream.stop,\n submit: stream.submit,\n switchThread: stream.switchThread,\n joinStream: stream.joinStream,\n branch: stream.branch,\n setBranch: stream.setBranch,\n client: stream.client,\n assistantId: stream.assistantId,\n queue: stream.queue,\n isStreaming: stream.isLoading,\n };\n}\n"],"mappings":";;;;;AAyBA,MAAM,8BAAc,IAAI,KAA0C;AAElE,SAAS,YACP,QACA,UACA,OACQ;AACR,QAAO,YAAY,oBAAoB,OAAO,CAAC,GAAG,SAAS,GAAG;;AAGhE,SAAS,mBACP,QACA,UACA,SACmC;AACnC,KAAI,SAAS,UAAU,MACrB,QAAO,OAAO,QAAQ,SAAoB,SAAS,CAAC,MAAM,UAAU;AAClE,MAAI,MAAM,cAAc,KAAM,QAAO,EAAE;AACvC,SAAO,CAAC,MAAM;GACd;CAGJ,MAAM,QAAQ,OAAO,SAAS,UAAU,WAAW,QAAQ,QAAQ;AACnE,QAAO,OAAO,QAAQ,WAAsB,UAAU,EAAE,OAAO,CAAC;;AAGlE,SAAS,sBACP,QACA,UACA,OAC8C;CAC9C,MAAM,MAAM,YAAY,QAAQ,UAAU,MAAM;CAChD,IAAI,QAAQ,YAAY,IAAI,IAAI;AAIhC,KAAI,CAAC,OAAO;AAWV,UAAQ;GAAE,QAAQ;GAAW,SARb,mBAA8B,QAAQ,UAAU,EAAE,OAAO,CAAC,CACvE,MAAM,SAAS;AACd,gBAAY,IAAI,KAAK;KAAE,QAAQ;KAAY;KAAM,CAAC;KAClD,CACD,OAAO,UAAmB;AACzB,gBAAY,IAAI,KAAK;KAAE,QAAQ;KAAY;KAAO,CAAC;KACnD;GAEkC;AACtC,cAAY,IAAI,KAAK,MAAM;;AAG7B,QAAO;;;;;;;;;;;;;;;;;;;;;;;AAwBT,SAAgB,0BAAgC;AAC9C,aAAY,OAAO;;AAmDrB,SAAgB,kBAAkB,S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+1,4 @@
1
1
  "use client";
2
- require("./_virtual/_rolldown/runtime.cjs");
3
2
  let react = require("react");
4
3
  //#region src/thread.tsx
5
4
  const useControllableThreadId = (options) => {
@@ -1 +1 @@
1
- {"version":3,"file":"thread.cjs","names":[],"sources":["../src/thread.tsx"],"sourcesContent":["\"use client\";\n\nimport { useState, useRef, useCallback } from \"react\";\n\nexport const useControllableThreadId = (options?: {\n threadId?: string | null;\n onThreadId?: (threadId: string) => void;\n}): [string | null, (threadId: string | null) => void] => {\n const [localThreadId, _setLocalThreadId] = useState<string | null>(\n options?.threadId ?? null,\n );\n\n const onThreadIdRef = useRef(options?.onThreadId);\n onThreadIdRef.current = options?.onThreadId;\n\n const setThreadId = useCallback((threadId: string | null) => {\n _setLocalThreadId(threadId);\n if (threadId != null) onThreadIdRef.current?.(threadId);\n }, []);\n\n if (!options || !(\"threadId\" in options)) {\n return [localThreadId, setThreadId];\n }\n\n return [options.threadId ?? null, setThreadId];\n};\n"],"mappings":";;;;AAIA,MAAa,2BAA2B,YAGkB;CACxD,MAAM,CAAC,eAAe,sBAAA,GAAA,MAAA,UACpB,SAAS,YAAY,KACtB;CAED,MAAM,iBAAA,GAAA,MAAA,QAAuB,SAAS,WAAW;AACjD,eAAc,UAAU,SAAS;CAEjC,MAAM,eAAA,GAAA,MAAA,cAA2B,aAA4B;AAC3D,oBAAkB,SAAS;AAC3B,MAAI,YAAY,KAAM,eAAc,UAAU,SAAS;IACtD,EAAE,CAAC;AAEN,KAAI,CAAC,WAAW,EAAE,cAAc,SAC9B,QAAO,CAAC,eAAe,YAAY;AAGrC,QAAO,CAAC,QAAQ,YAAY,MAAM,YAAY"}
1
+ {"version":3,"file":"thread.cjs","names":[],"sources":["../src/thread.tsx"],"sourcesContent":["\"use client\";\n\nimport { useState, useRef, useCallback } from \"react\";\n\nexport const useControllableThreadId = (options?: {\n threadId?: string | null;\n onThreadId?: (threadId: string) => void;\n}): [string | null, (threadId: string | null) => void] => {\n const [localThreadId, _setLocalThreadId] = useState<string | null>(\n options?.threadId ?? null,\n );\n\n const onThreadIdRef = useRef(options?.onThreadId);\n onThreadIdRef.current = options?.onThreadId;\n\n const setThreadId = useCallback((threadId: string | null) => {\n _setLocalThreadId(threadId);\n if (threadId != null) onThreadIdRef.current?.(threadId);\n }, []);\n\n if (!options || !(\"threadId\" in options)) {\n return [localThreadId, setThreadId];\n }\n\n return [options.threadId ?? null, setThreadId];\n};\n"],"mappings":";;;AAIA,MAAa,2BAA2B,YAGkB;CACxD,MAAM,CAAC,eAAe,sBAAA,GAAA,MAAA,UACpB,SAAS,YAAY,KACtB;CAED,MAAM,iBAAA,GAAA,MAAA,QAAuB,SAAS,WAAW;AACjD,eAAc,UAAU,SAAS;CAEjC,MAAM,eAAA,GAAA,MAAA,cAA2B,aAA4B;AAC3D,oBAAkB,SAAS;AAC3B,MAAI,YAAY,KAAM,eAAc,UAAU,SAAS;IACtD,EAAE,CAAC;AAEN,KAAI,CAAC,WAAW,EAAE,cAAc,SAC9B,QAAO,CAAC,eAAe,YAAY;AAGrC,QAAO,CAAC,QAAQ,YAAY,MAAM,YAAY"}
package/dist/types.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { BaseMessage } from "@langchain/core/messages";
2
2
  import { BagTemplate, Client, StreamEvent, StreamMode, ThreadState, ToolProgress } from "@langchain/langgraph-sdk";
3
- import { CustomSubmitOptions, DefaultSubagentStates, GetConfigurableType, GetInterruptType, GetToolCallsType, GetUpdateType, MessageMetadata as MessageMetadata$1, QueueInterface, Sequence, StreamBase, SubagentStream, SubagentStreamInterface as SubagentStreamInterface$1, SubmitOptions, UseStreamCustomOptions } from "@langchain/langgraph-sdk/ui";
3
+ import { CustomSubmitOptions, DefaultSubagentStates, GetConfigurableType, GetInterruptType, GetToolCallsType, GetUpdateType, MessageMetadata as MessageMetadata$1, QueueInterface, Sequence, StreamBase, SubagentStream, SubagentStreamInterface as SubagentStreamInterface$1, SubmitOptions, UseStreamCustomOptions as UseStreamCustomOptions$1 } from "@langchain/langgraph-sdk/ui";
4
4
 
5
5
  //#region src/types.d.ts
6
6
  interface UseStream<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends BagTemplate = BagTemplate, SubagentStates extends Record<string, unknown> = DefaultSubagentStates> extends Omit<StreamBase<StateType, GetToolCallsType<StateType>, GetInterruptType<Bag>, SubagentStates>, "messages"> {
@@ -80,6 +80,22 @@ interface UseStream<StateType extends Record<string, unknown> = Record<string, u
80
80
  */
81
81
  queue: QueueInterface<StateType, SubmitOptions<StateType, GetConfigurableType<Bag>>>;
82
82
  }
83
+ /**
84
+ * Return type for {@link useSuspenseStream}.
85
+ *
86
+ * Identical to {@link UseStream} but without `isLoading`, `error`, and
87
+ * `isThreadLoading` (those states are handled by Suspense / Error Boundaries).
88
+ * An `isStreaming` flag is provided instead to indicate whether tokens are
89
+ * currently being received from the server.
90
+ */
91
+ type UseSuspenseStream<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends BagTemplate = BagTemplate, SubagentStates extends Record<string, unknown> = DefaultSubagentStates> = Omit<UseStream<StateType, Bag, SubagentStates>, "isLoading" | "error" | "isThreadLoading"> & {
92
+ /**
93
+ * Whether the stream is currently receiving data from the server.
94
+ * Unlike Suspense-based loading, streaming is incremental and the
95
+ * component stays rendered throughout.
96
+ */
97
+ isStreaming: boolean;
98
+ };
83
99
  type UseStreamCustom<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends BagTemplate = BagTemplate, SubagentStates extends Record<string, unknown> = DefaultSubagentStates> = Pick<UseStream<StateType, Bag, SubagentStates>, "values" | "error" | "isLoading" | "stop" | "interrupt" | "interrupts" | "messages" | "toolCalls" | "getToolCalls" | "getMessagesMetadata" | "branch" | "setBranch" | "subagents" | "activeSubagents" | "getSubagent" | "getSubagentsByType" | "getSubagentsByMessage"> & {
84
100
  submit: (values: GetUpdateType<Bag, StateType> | null | undefined, options?: CustomSubmitOptions<StateType, GetConfigurableType<Bag>>) => Promise<void>;
85
101
  switchThread: (newThreadId: string | null) => void;
@@ -89,5 +105,5 @@ type UseStreamCustom<StateType extends Record<string, unknown> = Record<string,
89
105
  queue: QueueInterface<StateType, CustomSubmitOptions<StateType, GetConfigurableType<Bag>>>;
90
106
  };
91
107
  //#endregion
92
- export { type SubagentStream, type SubagentStreamInterface$1 as SubagentStreamInterface, type SubmitOptions, UseStream, UseStreamCustom, type UseStreamCustomOptions };
108
+ export { type SubagentStream, type SubagentStreamInterface$1 as SubagentStreamInterface, UseStream, UseStreamCustom, type UseStreamCustomOptions$1 as UseStreamCustomOptions, UseSuspenseStream };
93
109
  //# sourceMappingURL=types.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.cts","names":[],"sources":["../src/types.tsx"],"mappings":";;;;;UAgFiB,SAAA,mBACG,MAAA,oBAA0B,MAAA,+BAChC,WAAA,GAAc,WAAA,yBACH,MAAA,oBAA0B,qBAAA,UACzC,IAAA,CACR,UAAA,CACE,SAAA,EACA,gBAAA,CAAiB,SAAA,GACjB,gBAAA,CAAiB,GAAA,GACjB,cAAA;EATa;;;EAgBf,QAAA,EAAU,WAAA;EAfkC;;;EAoB5C,eAAA;EAlBiD;;;EAuBjD,IAAA,QAAY,OAAA;EAlBO;;;EAuBnB,MAAA,GACE,MAAA,EAAQ,aAAA,CAAc,GAAA,EAAK,SAAA,sBAC3B,OAAA,GAAU,aAAA,CAAc,SAAA,EAAW,mBAAA,CAAoB,GAAA,OACpD,OAAA;EAlBK;;;EAuBV,MAAA;EAPU;;;EAYV,SAAA,GAAY,MAAA;EAXA;;;EAgBZ,OAAA,EAAS,WAAA,CAAY,SAAA;EAMa;;;;EAAlC,uBAAA,EAAyB,QAAA,CAAS,SAAA;EAkBpB;;;;;;;;EARd,mBAAA,GACE,OAAA,EAAS,WAAA,EACT,KAAA,cACG,iBAAA,CAAgB,SAAA;EA6CM;;;EAxC3B,YAAA,EAAc,YAAA;EArEF;;;EA0EZ,MAAA,EAAQ,MAAA;EA7EoC;;;EAkF5C,WAAA;EAhF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