@_tc/template-core 0.4.0 → 0.4.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.
Files changed (297) hide show
  1. package/.skills/tc-component-usage-skills/reference/component-api.md +27 -0
  2. package/.skills/tc-generator/SKILL.md +1 -1
  3. package/.skills/tc-generator/reference/project-template/ssr/apps/hello/hello.entry.tsx +6 -1
  4. package/.skills/tc-generator/reference/runtime-extensions.md +10 -0
  5. package/AGENT_README.md +8 -2
  6. package/CHANGE.md +27 -0
  7. package/README.md +157 -8
  8. package/cjs/app/ai/agent/agent-scanner.service.js +1 -1
  9. package/cjs/app/ai/agent/agent.module.js +1 -1
  10. package/cjs/app/ai/ai-config.module.js +1 -1
  11. package/cjs/app/ai/ai-config.service.js +1 -1
  12. package/cjs/app/ai/ai.controller.js +1 -1
  13. package/cjs/app/ai/ai.module.js +1 -1
  14. package/cjs/app/ai/guardrail/guardrail.module.js +1 -1
  15. package/cjs/app/ai/guardrail/guardrail.service.js +1 -1
  16. package/cjs/app/ai/index.js +1 -0
  17. package/cjs/app/ai/mcp/internal/read-sse-response.js +2 -0
  18. package/cjs/app/ai/mcp/internal/stdio-process.js +1 -0
  19. package/cjs/app/ai/mcp/mcp-registry.service.js +2 -2
  20. package/cjs/app/ai/mcp/mcp.client.js +2 -3
  21. package/cjs/app/ai/mcp/mcp.loader.js +1 -1
  22. package/cjs/app/ai/mcp/mcp.module.js +1 -1
  23. package/cjs/app/ai/memory/checkpoint.service.js +1 -1
  24. package/cjs/app/ai/memory/memory.module.js +1 -1
  25. package/cjs/app/ai/memory/thread.service.js +1 -1
  26. package/cjs/app/ai/models/chat-sse.js +4 -0
  27. package/cjs/app/ai/models/chat.js +1 -0
  28. package/cjs/app/ai/models/http.js +1 -0
  29. package/cjs/app/ai/models/image.js +1 -0
  30. package/cjs/app/ai/models/video.js +1 -0
  31. package/cjs/app/ai/nest-service-provider.js +1 -0
  32. package/cjs/app/ai/rag/rag.module.js +1 -1
  33. package/cjs/app/ai/rag/retriever.service.js +1 -1
  34. package/cjs/app/ai/retention/conversation-retention.service.js +1 -1
  35. package/cjs/app/ai/runtime/ai-runtime-startup.validator.js +1 -1
  36. package/cjs/app/ai/runtime/ai-runtime.js +1 -0
  37. package/cjs/app/ai/runtime/internal/context-compaction.service.js +3 -3
  38. package/cjs/app/ai/runtime/internal/declaration-snapshot.js +1 -0
  39. package/cjs/app/ai/runtime/internal/owned-runtime-resources.js +1 -0
  40. package/cjs/app/ai/runtime/langchain/langchain-planner.service.js +1 -1
  41. package/cjs/app/ai/runtime/langgraph/langgraph-orchestrator.service.js +1 -1
  42. package/cjs/app/ai/runtime/runtime.module.js +1 -1
  43. package/cjs/app/ai/skill/skill-scanner.service.js +1 -1
  44. package/cjs/app/ai/skill/skill.module.js +1 -1
  45. package/cjs/app/ai/snapshot-data.js +1 -0
  46. package/cjs/app/ai/store/internal/create-vector-store.js +1 -0
  47. package/cjs/app/ai/store/store.module.js +1 -1
  48. package/cjs/app/ai/tool/builtin/index.js +1 -1
  49. package/cjs/app/ai/tool/builtin/invoke-agent.tool.js +1 -1
  50. package/cjs/app/ai/tool/builtin/retrieve.tool.js +1 -1
  51. package/cjs/app/ai/tool/executor.service.js +1 -1
  52. package/cjs/app/ai/tool/tool-registry.service.js +1 -1
  53. package/cjs/app/ai/tool/tool.module.js +1 -1
  54. package/cjs/app/ai/trace/trace.service.js +1 -1
  55. package/cjs/app/csr/controller.js +1 -1
  56. package/cjs/app/csr/types.js +0 -0
  57. package/cjs/app/html/browser-options.js +1 -1
  58. package/cjs/app/html/shell.js +31 -16
  59. package/cjs/app/http/api-signing.js +1 -0
  60. package/cjs/app/http/body-parser.middleware.js +1 -1
  61. package/cjs/app/http/csp-nonce.js +1 -0
  62. package/cjs/app/http/error-response.js +1 -1
  63. package/cjs/app/http/exception-filter.js +1 -1
  64. package/cjs/app/http/request-body-parser-policy.js +1 -0
  65. package/cjs/app/http/security.guard.js +1 -1
  66. package/cjs/app/project/controller.js +1 -1
  67. package/cjs/app/project/service.js +1 -1
  68. package/cjs/app/providers/foundation.js +1 -1
  69. package/cjs/app/ssr/artifacts.js +1 -1
  70. package/cjs/app/ssr/controller.js +1 -1
  71. package/cjs/app/ssr/html.js +17 -17
  72. package/cjs/app/ssr/stream.js +1 -1
  73. package/cjs/app/static-assets.middleware.js +1 -1
  74. package/cjs/app/template-core.module.js +1 -1
  75. package/cjs/app/view/entry.tpl +2 -2
  76. package/cjs/bundler/buildSSR.js +1 -1
  77. package/cjs/bundler/entryCollect.js +1 -1
  78. package/cjs/bundler/feSharedConfig.js +1 -1
  79. package/cjs/bundler/utils.js +3 -3
  80. package/cjs/config/config.default.js +1 -1
  81. package/cjs/packages/common/index.js +1 -1
  82. package/cjs/packages/core/bootstrap.js +1 -1
  83. package/cjs/packages/core/startup.js +1 -1
  84. package/esm/app/ai/agent/agent-scanner.service.js +33 -36
  85. package/esm/app/ai/agent/agent.module.js +9 -7
  86. package/esm/app/ai/ai-config.module.js +14 -7
  87. package/esm/app/ai/ai-config.service.js +24 -20
  88. package/esm/app/ai/ai.controller.js +41 -41
  89. package/esm/app/ai/ai.module.js +15 -15
  90. package/esm/app/ai/guardrail/guardrail.module.js +11 -9
  91. package/esm/app/ai/guardrail/guardrail.service.js +5 -10
  92. package/esm/app/ai/index.js +2 -0
  93. package/esm/app/ai/mcp/internal/read-sse-response.js +35 -0
  94. package/esm/app/ai/mcp/internal/stdio-process.js +59 -0
  95. package/esm/app/ai/mcp/mcp-registry.service.js +10 -15
  96. package/esm/app/ai/mcp/mcp.client.js +77 -78
  97. package/esm/app/ai/mcp/mcp.loader.js +64 -42
  98. package/esm/app/ai/mcp/mcp.module.js +62 -22
  99. package/esm/app/ai/memory/checkpoint.service.js +18 -28
  100. package/esm/app/ai/memory/memory.module.js +15 -12
  101. package/esm/app/ai/memory/thread.service.js +21 -26
  102. package/esm/app/ai/models/chat-sse.js +44 -0
  103. package/esm/app/ai/models/chat.js +60 -0
  104. package/esm/app/ai/models/http.js +52 -0
  105. package/esm/app/ai/models/image.js +37 -0
  106. package/esm/app/ai/models/video.js +32 -0
  107. package/esm/app/ai/nest-service-provider.js +10 -0
  108. package/esm/app/ai/rag/rag.module.js +24 -15
  109. package/esm/app/ai/rag/retriever.service.js +37 -54
  110. package/esm/app/ai/retention/conversation-retention.service.js +16 -34
  111. package/esm/app/ai/runtime/ai-runtime-startup.validator.js +2 -19
  112. package/esm/app/ai/runtime/ai-runtime.js +104 -0
  113. package/esm/app/ai/runtime/internal/context-compaction.service.js +139 -145
  114. package/esm/app/ai/runtime/internal/declaration-snapshot.js +32 -0
  115. package/esm/app/ai/runtime/internal/owned-runtime-resources.js +21 -0
  116. package/esm/app/ai/runtime/langchain/langchain-planner.service.js +43 -49
  117. package/esm/app/ai/runtime/langgraph/langgraph-orchestrator.service.js +273 -225
  118. package/esm/app/ai/runtime/runtime.module.js +56 -35
  119. package/esm/app/ai/skill/skill-scanner.service.js +11 -16
  120. package/esm/app/ai/skill/skill.module.js +11 -9
  121. package/esm/app/ai/snapshot-data.js +24 -0
  122. package/esm/app/ai/store/internal/create-vector-store.js +10 -0
  123. package/esm/app/ai/store/store.module.js +9 -13
  124. package/esm/app/ai/tool/builtin/index.js +16 -4
  125. package/esm/app/ai/tool/builtin/invoke-agent.tool.js +30 -34
  126. package/esm/app/ai/tool/builtin/retrieve.tool.js +9 -13
  127. package/esm/app/ai/tool/executor.service.js +22 -29
  128. package/esm/app/ai/tool/tool-registry.service.js +6 -16
  129. package/esm/app/ai/tool/tool.module.js +26 -12
  130. package/esm/app/ai/trace/trace.service.js +15 -28
  131. package/esm/app/csr/controller.js +114 -63
  132. package/esm/app/csr/types.js +0 -0
  133. package/esm/app/html/browser-options.js +2 -2
  134. package/esm/app/html/shell.js +173 -32
  135. package/esm/app/http/api-signing.js +13 -0
  136. package/esm/app/http/body-parser.middleware.js +47 -27
  137. package/esm/app/http/csp-nonce.js +13 -0
  138. package/esm/app/http/error-response.js +8 -5
  139. package/esm/app/http/exception-filter.js +4 -4
  140. package/esm/app/http/request-body-parser-policy.js +46 -0
  141. package/esm/app/http/security.guard.js +23 -21
  142. package/esm/app/project/controller.js +15 -15
  143. package/esm/app/project/service.js +3 -3
  144. package/esm/app/providers/foundation.js +5 -5
  145. package/esm/app/ssr/artifacts.js +25 -21
  146. package/esm/app/ssr/controller.js +148 -75
  147. package/esm/app/ssr/html.js +49 -44
  148. package/esm/app/ssr/stream.js +25 -24
  149. package/esm/app/static-assets.middleware.js +4 -4
  150. package/esm/app/template-core.module.js +57 -52
  151. package/esm/app/view/entry.tpl +2 -2
  152. package/esm/bundler/buildSSR.js +1 -1
  153. package/esm/bundler/entryCollect.js +9 -9
  154. package/esm/bundler/feSharedConfig.js +42 -42
  155. package/esm/bundler/utils.js +78 -90
  156. package/esm/config/config.default.js +4 -3
  157. package/esm/packages/common/index.js +6 -6
  158. package/esm/packages/core/bootstrap.js +5 -5
  159. package/esm/packages/core/startup.js +69 -46
  160. package/fe/frontend/src/common/request.js +5 -2
  161. package/fe/frontend/src/hooks/useRouterParams.d.ts +4 -2
  162. package/fe/packages/common/ssr/hydration.d.ts +9 -0
  163. package/fe/packages/react/core/Label/Label.d.ts +1 -0
  164. package/fe/packages/react/core/Label/Label.js +3 -1
  165. package/fe/packages/react/core/internal/i18n/default.d.ts +13 -0
  166. package/fe/packages/react/core/internal/i18n/default.js +16 -1
  167. package/fe/packages/react/core/internal/i18n/en-US.d.ts +13 -0
  168. package/fe/packages/react/core/internal/i18n/en-US.js +16 -1
  169. package/fe/packages/react/forms/DataTable/index.d.ts +2 -0
  170. package/fe/packages/react/forms/DataTable/index.js +43 -29
  171. package/fe/packages/react/forms/Form/FormItem.js +39 -12
  172. package/fe/packages/react/forms/MultiSelect/MultiSelect.d.ts +26 -0
  173. package/fe/packages/react/forms/MultiSelect/MultiSelect.js +218 -0
  174. package/fe/packages/react/forms/MultiSelect/index.d.ts +1 -0
  175. package/fe/packages/react/forms/MultiSelect/index.js +2 -0
  176. package/fe/packages/react/forms/Pagination/Pagination.d.ts +6 -1
  177. package/fe/packages/react/forms/Pagination/Pagination.js +13 -4
  178. package/fe/packages/react/forms/Select/Select.d.ts +11 -0
  179. package/fe/packages/react/forms/Select/Select.js +20 -7
  180. package/fe/packages/react/forms/index.d.ts +1 -0
  181. package/fe/packages/react/forms/index.js +3 -1
  182. package/fe/packages/react/i18n/getUiReactLocale.d.ts +26 -0
  183. package/fe/packages/react/index.js +2 -1
  184. package/fe/packages/react/overlays/Drawer/Drawer.d.ts +3 -2
  185. package/fe/packages/react/overlays/Drawer/Drawer.js +16 -2
  186. package/fe/packages/react/overlays/Dropdown/Dropdown.d.ts +12 -2
  187. package/fe/packages/react/overlays/Dropdown/Dropdown.js +27 -14
  188. package/fe/packages/react/overlays/Modal/Modal.d.ts +11 -3
  189. package/fe/packages/react/overlays/Modal/Modal.js +26 -2
  190. package/fe/packages/react/overlays/Modal/ModalManager.d.ts +13 -12
  191. package/fe/packages/react/overlays/Modal/ModalManager.js +15 -5
  192. package/fe/packages/react/overlays/Modal/index.d.ts +1 -0
  193. package/fe/packages/react/overlays/Overlay/Overlay.d.ts +6 -2
  194. package/fe/packages/react/overlays/Overlay/Overlay.js +31 -14
  195. package/fe/packages/react/overlays/Overlay/focusTypes.d.ts +8 -0
  196. package/fe/packages/react/overlays/Overlay/focusTypes.js +0 -0
  197. package/fe/packages/react/overlays/Overlay/index.d.ts +1 -0
  198. package/fe/packages/react/overlays/Overlay/overlayStack.d.ts +16 -0
  199. package/fe/packages/react/overlays/Overlay/overlayStack.js +290 -0
  200. package/fe/packages/react/overlays/Popup/Popup.d.ts +5 -4
  201. package/fe/packages/react/overlays/Popup/Popup.js +28 -11
  202. package/fe/packages/react/ui/components/index.js +2 -1
  203. package/fe/packages/react/ui/index.js +2 -1
  204. package/fe/ssr/components/StreamingRender/StreamingCache.d.ts +1 -0
  205. package/fe/ssr/components/StreamingRender/StreamingCache.js +5 -1
  206. package/fe/ssr/components/StreamingRender/StreamingRender.js +1 -1
  207. package/fe/ssr/components/StreamingRender/StreamingScript.d.ts +1 -0
  208. package/fe/ssr/components/StreamingRender/StreamingScript.js +9 -1
  209. package/fe/ssr/createSSREntry.d.ts +9 -3
  210. package/fe/ssr/createSSREntry.js +43 -19
  211. package/fe/ssr/index.d.ts +4 -1
  212. package/fe/ssr/index.js +2 -1
  213. package/fe/ssr/router.d.ts +76 -0
  214. package/fe/ssr/router.js +349 -0
  215. package/fe/ssr/types.d.ts +1 -1
  216. package/models/packages/common/ssr/hydration.d.ts +9 -0
  217. package/models/packages/react/core/Label/Label.d.ts +1 -0
  218. package/models/packages/react/core/internal/i18n/default.d.ts +13 -0
  219. package/models/packages/react/core/internal/i18n/en-US.d.ts +13 -0
  220. package/models/packages/react/forms/DataTable/index.d.ts +2 -0
  221. package/models/packages/react/forms/MultiSelect/MultiSelect.d.ts +26 -0
  222. package/models/packages/react/forms/MultiSelect/index.d.ts +1 -0
  223. package/models/packages/react/forms/Pagination/Pagination.d.ts +6 -1
  224. package/models/packages/react/forms/Select/Select.d.ts +11 -0
  225. package/models/packages/react/forms/index.d.ts +1 -0
  226. package/models/packages/react/i18n/getUiReactLocale.d.ts +26 -0
  227. package/models/packages/react/overlays/Drawer/Drawer.d.ts +3 -2
  228. package/models/packages/react/overlays/Dropdown/Dropdown.d.ts +12 -2
  229. package/models/packages/react/overlays/Modal/Modal.d.ts +11 -3
  230. package/models/packages/react/overlays/Modal/ModalManager.d.ts +13 -12
  231. package/models/packages/react/overlays/Modal/index.d.ts +1 -0
  232. package/models/packages/react/overlays/Overlay/Overlay.d.ts +6 -2
  233. package/models/packages/react/overlays/Overlay/focusTypes.d.ts +8 -0
  234. package/models/packages/react/overlays/Overlay/index.d.ts +1 -0
  235. package/models/packages/react/overlays/Overlay/overlayStack.d.ts +16 -0
  236. package/models/packages/react/overlays/Popup/Popup.d.ts +5 -4
  237. package/package.json +26 -1
  238. package/types/app/ai/agent/agent-scanner.service.d.ts +4 -4
  239. package/types/app/ai/ai-config.service.d.ts +7 -3
  240. package/types/app/ai/guardrail/guardrail.service.d.ts +2 -2
  241. package/types/app/ai/index.d.ts +9 -0
  242. package/types/app/ai/mcp/internal/load-mcp-config.d.ts +2 -2
  243. package/types/app/ai/mcp/internal/read-sse-response.d.ts +2 -0
  244. package/types/app/ai/mcp/internal/stdio-process.d.ts +5 -0
  245. package/types/app/ai/mcp/mcp-registry.service.d.ts +5 -3
  246. package/types/app/ai/mcp/mcp.client.d.ts +7 -4
  247. package/types/app/ai/mcp/mcp.loader.d.ts +11 -11
  248. package/types/app/ai/mcp/mcp.module.d.ts +5 -5
  249. package/types/app/ai/memory/thread.service.d.ts +3 -3
  250. package/types/app/ai/models/chat-sse.d.ts +5 -0
  251. package/types/app/ai/models/chat.d.ts +22 -0
  252. package/types/app/ai/models/http.d.ts +20 -0
  253. package/types/app/ai/models/image.d.ts +69 -0
  254. package/types/app/ai/models/video.d.ts +99 -0
  255. package/types/app/ai/nest-service-provider.d.ts +6 -0
  256. package/types/app/ai/retention/conversation-retention.service.d.ts +3 -4
  257. package/types/app/ai/runtime/ai-runtime-startup.validator.d.ts +2 -3
  258. package/types/app/ai/runtime/ai-runtime.d.ts +46 -0
  259. package/types/app/ai/runtime/internal/agent-run-context.d.ts +4 -0
  260. package/types/app/ai/runtime/internal/context-compaction.service.d.ts +2 -2
  261. package/types/app/ai/runtime/internal/declaration-snapshot.d.ts +8 -0
  262. package/types/app/ai/runtime/internal/owned-runtime-resources.d.ts +5 -0
  263. package/types/app/ai/runtime/langchain/langchain-planner.service.d.ts +1 -1
  264. package/types/app/ai/runtime/langgraph/langgraph-orchestrator.service.d.ts +33 -16
  265. package/types/app/ai/skill/skill-scanner.service.d.ts +3 -4
  266. package/types/app/ai/snapshot-data.d.ts +1 -0
  267. package/types/app/ai/store/internal/create-vector-store.d.ts +4 -0
  268. package/types/app/ai/tool/builtin/index.d.ts +1 -1
  269. package/types/app/ai/tool/builtin/invoke-agent.tool.d.ts +10 -3
  270. package/types/app/ai/tool/builtin/retrieve.tool.d.ts +4 -3
  271. package/types/app/ai/tool/executor.service.d.ts +3 -3
  272. package/types/app/ai/tool/tool-registry.service.d.ts +2 -7
  273. package/types/app/ai/tool/tool.interface.d.ts +1 -1
  274. package/types/app/ai/tool/tool.module.d.ts +8 -1
  275. package/types/app/ai/trace/trace.service.d.ts +4 -5
  276. package/types/app/csr/types.d.ts +10 -0
  277. package/types/app/html/browser-options.d.ts +1 -1
  278. package/types/app/html/shell.d.ts +37 -10
  279. package/types/app/http/api-signing.d.ts +16 -0
  280. package/types/app/http/body-parser.middleware.d.ts +6 -2
  281. package/types/app/http/csp-nonce.d.ts +3 -0
  282. package/types/app/http/error-response.d.ts +1 -0
  283. package/types/app/http/request-body-parser-policy.d.ts +8 -0
  284. package/types/app/http/security.guard.d.ts +1 -0
  285. package/types/app/ssr/artifacts.d.ts +6 -3
  286. package/types/app/ssr/html.d.ts +7 -0
  287. package/types/app/ssr/stream.d.ts +1 -1
  288. package/types/app/ssr/types.d.ts +56 -0
  289. package/types/bundler/buildSSR.d.ts +2 -1
  290. package/types/bundler/index.d.ts +1 -1
  291. package/types/bundler/state.d.ts +13 -0
  292. package/types/bundler/utils.d.ts +3 -14
  293. package/types/config/config.default.d.ts +9 -3
  294. package/types/index.d.ts +4 -1
  295. package/types/packages/common/ssr/hydration.d.ts +13 -0
  296. package/types/packages/core/index.d.ts +1 -1
  297. package/types/packages/core/startup.d.ts +41 -0
@@ -1,50 +1,42 @@
1
- import { AiConfigService as e } from "../../ai-config.service.js";
2
- import { AgentScannerService as t } from "../../agent/agent-scanner.service.js";
3
- import { GuardrailService as n } from "../../guardrail/guardrail.service.js";
4
- import { CheckpointService as r } from "../../memory/checkpoint.service.js";
5
- import { ThreadService as i } from "../../memory/thread.service.js";
6
- import { SkillScannerService as a } from "../../skill/skill-scanner.service.js";
7
- import { agentRunContext as o } from "../internal/agent-run-context.js";
8
- import { resolveMaxIterations as s } from "../internal/load-runtime-config.js";
9
- import { ToolRegistryService as c } from "../../tool/tool-registry.service.js";
10
- import { ExecutorService as l } from "../../tool/executor.service.js";
11
- import { TraceService as u } from "../../trace/trace.service.js";
12
- import { InProcessThreadExecutionCoordinator as d, THREAD_EXECUTION_COORDINATOR as f } from "../thread-execution-coordinator.js";
13
- import { ConversationRetentionService as p } from "../../retention/conversation-retention.service.js";
14
- import { LangChainPlannerService as m } from "../langchain/langchain-planner.service.js";
15
- import { ContextCompactionService as h } from "../internal/context-compaction.service.js";
16
- import { createArchiveMessageId as g } from "../../store/internal/archive-id.js";
17
- import { RunEventQueue as _ } from "../internal/run-event-queue.js";
18
- import { toStructuredTools as v } from "../langchain/skill-tool.adapter.js";
19
- import { hasOutput as y } from "./agent.state.js";
20
- import { AGENT_GRAPH_EDGES as b, AGENT_GRAPH_NODES as x, buildAgentGraph as S } from "./agent.graph.js";
21
- import { Inject as C, Injectable as w, Optional as T } from "@nestjs/common";
22
- import E from "@oxc-project/runtime/helpers/decorateMetadata";
23
- import D from "@oxc-project/runtime/helpers/decorate";
24
- import O from "@oxc-project/runtime/helpers/decorateParam";
1
+ import { resolveMaxIterations as e } from "../internal/load-runtime-config.js";
2
+ import { createArchiveMessageId as t } from "../../store/internal/archive-id.js";
3
+ import { agentRunContext as n } from "../internal/agent-run-context.js";
4
+ import { RunEventQueue as r } from "../internal/run-event-queue.js";
5
+ import { InProcessThreadExecutionCoordinator as i } from "../thread-execution-coordinator.js";
6
+ import { toStructuredTools as a } from "../langchain/skill-tool.adapter.js";
7
+ import { hasOutput as o } from "./agent.state.js";
8
+ import { AGENT_GRAPH_EDGES as s, AGENT_GRAPH_NODES as c, buildAgentGraph as l } from "./agent.graph.js";
25
9
  //#region app/ai/runtime/langgraph/langgraph-orchestrator.service.ts
26
- var k, A, j, M, N, P, F, I, L, R, z, B, V = class extends Error {
10
+ var u = class extends Error {
27
11
  code = "THREAD_MIGRATION_CONFLICT";
28
12
  retryable = !0;
29
13
  constructor(e) {
30
14
  super(`[ai] thread ${e} changed after migration preview; create a new preview`), this.name = "ThreadMigrationConflictError";
31
15
  }
32
16
  };
33
- function H(e) {
17
+ function d(e) {
34
18
  return typeof e == "string" ? e : e == null ? "" : JSON.stringify(e);
35
19
  }
36
- var U = class {
20
+ var f = class {
37
21
  threadExecutionCoordinator;
38
- constructor(e, t, n, r, i, a, o, s, c, l, u, f, p) {
39
- this.planner = e, this.executor = t, this.agentScanner = n, this.skillScanner = r, this.toolRegistry = i, this.traceService = a, this.guardrailService = o, this.threadService = s, this.checkpointService = c, this.configService = l, this.contextCompactionService = u, this.conversationRetention = p, this.threadExecutionCoordinator = f ?? new d();
22
+ runtimeId = Symbol("AgentRuntime");
23
+ lifecycleState = "open";
24
+ activeOperations = 0;
25
+ drainResolve;
26
+ closePromise;
27
+ constructor(e, t, n, r, a, o, s, c, l, u, d, f, p, m) {
28
+ this.planner = e, this.executor = t, this.agentScanner = n, this.skillScanner = r, this.toolRegistry = a, this.traceService = o, this.guardrailService = s, this.threadService = c, this.checkpointService = l, this.configService = u, this.contextCompactionService = d, this.conversationRetention = p, this.closeOwnedResources = m, this.threadExecutionCoordinator = f ?? new i();
40
29
  }
41
30
  getGraph() {
42
31
  return {
43
- nodes: [...x],
44
- edges: b.map((e) => ({ ...e }))
32
+ nodes: [...c],
33
+ edges: s.map((e) => ({ ...e }))
45
34
  };
46
35
  }
47
36
  async inspectThreadContext(e) {
37
+ return this.withOperation(() => this.inspectThreadContextInternal(e));
38
+ }
39
+ async inspectThreadContextInternal(e) {
48
40
  let t = this.requireThreadId(e);
49
41
  return this.threadExecutionCoordinator.runExclusive(t, async () => {
50
42
  let { checkpoint: e, archiveRevision: n } = await this.checkpointService.loadThreadState(t);
@@ -60,67 +52,73 @@ var U = class {
60
52
  });
61
53
  }
62
54
  async previewThreadMigration(e, t) {
63
- let n = this.requireThreadId(e), r = typeof t == "string" ? t.trim() : "";
64
- if (r === "") throw Error("[ai] target Agent is required for thread migration");
65
- let i = this.agentScanner.get(r);
66
- if (!i) throw Error(`[ai] agent 未注册:${r}`);
67
- await this.conversationRetention?.assertNotExpired(n);
68
- let a = await this.threadExecutionCoordinator.runExclusive(n, async () => {
69
- let { checkpoint: e, archive: t, archiveRevision: r } = await this.checkpointService.loadThreadState(n), i = e ?? this.checkpointService.createInitialCheckpoint(n, "", ""), a = t.length === 0 && e?.messages?.length ? e.messages.map(() => g()) : [];
70
- if (t.length === 0 && i.summarizedThroughSeq !== 0 && a.length > 0) throw Error("[ai] legacy checkpoint cursor cannot be matched to its messages");
71
- let o = t.length === 0 ? (e?.messages ?? []).map((e, t) => {
72
- let r = a[t];
73
- if (!r) throw Error("[ai] legacy checkpoint message could not be assigned an archive id");
55
+ return this.withOperation(() => this.previewThreadMigrationInternal(e, t));
56
+ }
57
+ async previewThreadMigrationInternal(e, n) {
58
+ let r = this.requireThreadId(e), i = typeof n == "string" ? n.trim() : "";
59
+ if (i === "") throw Error("[ai] target Agent is required for thread migration");
60
+ let a = this.agentScanner.get(i);
61
+ if (!a) throw Error(`[ai] agent 未注册:${i}`);
62
+ await this.conversationRetention?.assertNotExpired(r);
63
+ let o = await this.threadExecutionCoordinator.runExclusive(r, async () => {
64
+ let { checkpoint: e, archive: n, archiveRevision: i } = await this.checkpointService.loadThreadState(r), a = e ?? this.checkpointService.createInitialCheckpoint(r, "", ""), o = n.length === 0 && e?.messages?.length ? e.messages.map(() => t()) : [];
65
+ if (n.length === 0 && a.summarizedThroughSeq !== 0 && o.length > 0) throw Error("[ai] legacy checkpoint cursor cannot be matched to its messages");
66
+ let s = n.length === 0 ? (e?.messages ?? []).map((e, t) => {
67
+ let n = o[t];
68
+ if (!n) throw Error("[ai] legacy checkpoint message could not be assigned an archive id");
74
69
  return {
75
- threadId: n,
70
+ threadId: r,
76
71
  seq: t + 1,
77
- messageId: r,
72
+ messageId: n,
78
73
  role: e.role,
79
74
  content: e.content,
80
75
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
81
76
  };
82
- }) : [], s = {
83
- ...i.pinnedContext,
84
- initialGoal: i.pinnedContext.initialGoal || o[0]?.content || t.find((e) => e.role === "user")?.content || "",
85
- latestUserDirection: i.pinnedContext.latestUserDirection || ""
77
+ }) : [], c = {
78
+ ...a.pinnedContext,
79
+ initialGoal: a.pinnedContext.initialGoal || s[0]?.content || n.find((e) => e.role === "user")?.content || "",
80
+ latestUserDirection: a.pinnedContext.latestUserDirection || ""
86
81
  };
87
82
  return {
88
83
  checkpoint: {
89
- ...i,
90
- pinnedContext: s
84
+ ...a,
85
+ pinnedContext: c
91
86
  },
92
- archive: [...t, ...o],
93
- archiveRevision: r,
94
- legacyMessageIds: a
87
+ archive: [...n, ...s],
88
+ archiveRevision: i,
89
+ legacyMessageIds: o
95
90
  };
96
- }), o = await this.contextCompactionService.summarizeForMigration(a.checkpoint, a.archive, i.summaryModel ?? i.model);
91
+ }), s = await this.contextCompactionService.summarizeForMigration(o.checkpoint, o.archive, a.summaryModel ?? a.model);
97
92
  return {
98
- threadId: n,
99
- sourceAgentId: a.checkpoint.agentId,
100
- targetAgentId: i.name,
101
- checkpointRevision: a.checkpoint.revision,
102
- archiveRevision: a.archiveRevision,
93
+ threadId: r,
94
+ sourceAgentId: o.checkpoint.agentId,
95
+ targetAgentId: a.name,
96
+ checkpointRevision: o.checkpoint.revision,
97
+ archiveRevision: o.archiveRevision,
103
98
  candidatePinnedContext: {
104
- ...structuredClone(a.checkpoint.pinnedContext),
105
- ...o.latestUserDirection === void 0 ? {} : { latestUserDirection: o.latestUserDirection }
99
+ ...structuredClone(o.checkpoint.pinnedContext),
100
+ ...s.latestUserDirection === void 0 ? {} : { latestUserDirection: s.latestUserDirection }
106
101
  },
107
- candidateSummary: structuredClone(o.rollingSummary),
108
- coveredThroughSeq: o.summarizedThroughSeq,
109
- legacyMessageIds: a.legacyMessageIds
102
+ candidateSummary: structuredClone(s.rollingSummary),
103
+ coveredThroughSeq: s.summarizedThroughSeq,
104
+ legacyMessageIds: o.legacyMessageIds
110
105
  };
111
106
  }
112
107
  async confirmThreadMigration(e) {
108
+ return this.withOperation(() => this.confirmThreadMigrationInternal(e));
109
+ }
110
+ async confirmThreadMigrationInternal(e) {
113
111
  let t = this.requireThreadId(e?.threadId);
114
112
  return this.threadExecutionCoordinator.runExclusive(t, async () => {
115
113
  let n = this.agentScanner.get(e.targetAgentId);
116
114
  if (!n || n.name !== e.targetAgentId) throw Error(`[ai] target Agent is no longer registered: ${e.targetAgentId}`);
117
115
  let { checkpoint: r, archive: i, archiveRevision: a } = await this.checkpointService.loadThreadState(t), o = r?.revision ?? 0;
118
- if (o !== e.checkpointRevision || a !== e.archiveRevision || (r?.agentId ?? "") !== e.sourceAgentId) throw new V(t);
116
+ if (o !== e.checkpointRevision || a !== e.archiveRevision || (r?.agentId ?? "") !== e.sourceAgentId) throw new u(t);
119
117
  let s = i.length === 0 ? r?.messages ?? [] : [];
120
- if (e.legacyMessageIds.length !== s.length) throw new V(t);
118
+ if (e.legacyMessageIds.length !== s.length) throw new u(t);
121
119
  let c = s.map((n, r) => {
122
120
  let i = e.legacyMessageIds[r];
123
- if (!i) throw new V(t);
121
+ if (!i) throw new u(t);
124
122
  return {
125
123
  threadId: t,
126
124
  seq: e.archiveRevision + r + 1,
@@ -129,10 +127,10 @@ var U = class {
129
127
  content: n.content,
130
128
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
131
129
  };
132
- }), l = e.archiveRevision + c.length, u = r ?? this.checkpointService.createInitialCheckpoint(t, "", "");
133
- if (!Number.isSafeInteger(e.coveredThroughSeq) || e.coveredThroughSeq < u.summarizedThroughSeq || e.coveredThroughSeq > l) throw Error("[ai] migration preview contains an invalid summary cursor");
134
- let d = {
135
- ...u,
130
+ }), l = e.archiveRevision + c.length, d = r ?? this.checkpointService.createInitialCheckpoint(t, "", "");
131
+ if (!Number.isSafeInteger(e.coveredThroughSeq) || e.coveredThroughSeq < d.summarizedThroughSeq || e.coveredThroughSeq > l) throw Error("[ai] migration preview contains an invalid summary cursor");
132
+ let f = {
133
+ ...d,
136
134
  agentId: n.name,
137
135
  pinnedContext: structuredClone(e.candidatePinnedContext),
138
136
  rollingSummary: structuredClone(e.candidateSummary),
@@ -140,10 +138,10 @@ var U = class {
140
138
  revision: o,
141
139
  updatedAt: Date.now()
142
140
  };
143
- if (delete d.messages, !await this.checkpointService.commitMigration(d, e.archiveRevision, o, c)) throw new V(t);
144
- let f = await this.checkpointService.load(t);
145
- if (!f) throw Error(`[ai] migrated checkpoint could not be reloaded for ${t}`);
146
- return f;
141
+ if (delete f.messages, !await this.checkpointService.commitMigration(f, e.archiveRevision, o, c)) throw new u(t);
142
+ let p = await this.checkpointService.load(t);
143
+ if (!p) throw Error(`[ai] migrated checkpoint could not be reloaded for ${t}`);
144
+ return p;
147
145
  });
148
146
  }
149
147
  requireThreadId(e) {
@@ -152,168 +150,239 @@ var U = class {
152
150
  return t;
153
151
  }
154
152
  async run(e, t, n, r, i = {}) {
155
- let a = this.threadService.ensureThread(n);
156
- return this.threadExecutionCoordinator.runExclusive(a, () => this.runExclusive(e, t, a, r, i));
153
+ return this.withOperation(async () => {
154
+ let a = this.threadService.ensureThread(n);
155
+ return this.threadExecutionCoordinator.runExclusive(a, () => this.runExclusive(e, t, a, r, i));
156
+ });
157
+ }
158
+ async close() {
159
+ if (this.activeParent()) throw Error("[ai] runtime.close() cannot be called from an active run");
160
+ return this.closePromise ? this.closePromise : (this.lifecycleState = "closing", this.closePromise = this.drainAndClose(), this.closePromise);
161
+ }
162
+ onModuleDestroy() {
163
+ return this.close();
164
+ }
165
+ async withOperation(e) {
166
+ let t = this.acceptOperation();
167
+ try {
168
+ return await e();
169
+ } finally {
170
+ t();
171
+ }
157
172
  }
158
- async runExclusive(e, t, n, r, i = {}) {
159
- let a = this.agentScanner.get(e);
160
- if (!a) throw Error(`[ai] agent 未注册:${e}`);
161
- let c = H(t), l = this.guardrailService.check(c);
162
- if (!l.safe) {
163
- let e = `请求已被安全策略拦截:${l.reason ?? "命中安全规则"}`, o = {
173
+ activeParent() {
174
+ let e = n.getStore();
175
+ return e?.runtimeId === this.runtimeId && e.lease?.active ? e : void 0;
176
+ }
177
+ acceptOperation() {
178
+ if (this.lifecycleState !== "open" && !this.activeParent()) throw Error("[ai] runtime is closing and cannot accept a new run");
179
+ this.activeOperations += 1;
180
+ let e = !1;
181
+ return () => {
182
+ e || (e = !0, --this.activeOperations, this.lifecycleState === "closing" && this.activeOperations === 0 && (this.drainResolve?.(), this.drainResolve = void 0));
183
+ };
184
+ }
185
+ async drainAndClose() {
186
+ try {
187
+ if (this.activeOperations > 0 && await new Promise((e) => {
188
+ this.drainResolve = e;
189
+ }), this.closeOwnedResources) {
190
+ await this.closeOwnedResources();
191
+ return;
192
+ }
193
+ let e = (await Promise.allSettled([this.conversationRetention?.onModuleDestroy(), this.traceService.onModuleDestroy()].filter((e) => e !== void 0))).filter((e) => e.status === "rejected").map((e) => e.reason);
194
+ if (e.length === 1) throw e[0];
195
+ if (e.length > 1) throw AggregateError(e, "[ai] runtime resources failed to close");
196
+ } finally {
197
+ this.lifecycleState = "closed";
198
+ }
199
+ }
200
+ async runExclusive(t, i, s, c, u = {}) {
201
+ let f = this.agentScanner.get(t);
202
+ if (!f) throw Error(`[ai] agent 未注册:${t}`);
203
+ let p = d(i), m = this.guardrailService.check(p);
204
+ if (!m.safe) {
205
+ let e = `请求已被安全策略拦截:${m.reason ?? "命中安全规则"}`, t = {
164
206
  type: "guardrail",
165
207
  content: e,
166
208
  startedAt: (/* @__PURE__ */ new Date()).toISOString(),
167
209
  endedAt: (/* @__PURE__ */ new Date()).toISOString(),
168
- ...l.reason ? { error: l.reason } : {}
169
- }, s = await this.traceService.createRun(a.name, t);
170
- return await i.onStart?.(s.runId), await this.traceService.addStep(s.runId, o), await this.traceService.finish(s.runId, e), r?.({
210
+ ...m.reason ? { error: m.reason } : {}
211
+ }, n = await this.traceService.createRun(f.name, i);
212
+ return await u.onStart?.(n.runId), await this.traceService.addStep(n.runId, t), await this.traceService.finish(n.runId, e), c?.({
171
213
  type: "step",
172
- step: o
214
+ step: t
173
215
  }), {
174
- runId: s.runId,
216
+ runId: n.runId,
175
217
  output: e,
176
- steps: [o],
177
- threadId: n
218
+ steps: [t],
219
+ threadId: s
178
220
  };
179
221
  }
180
- await this.conversationRetention?.assertNotExpired(n);
181
- let { checkpoint: u, archive: d } = await this.checkpointService.loadThreadState(n);
182
- if (u && u.agentId === "") throw Error(`[ai] thread ${n} is not bound to an Agent; explicit migration is required`);
183
- if (u && u.agentId !== a.name) throw Error(`[ai] thread ${n} is bound to Agent ${u.agentId}; explicit migration is required`);
184
- if (!u && d.length > 0) throw Error(`[ai] thread ${n} has unbound archive history; explicit migration is required`);
185
- if (u?.messages?.length && d.length === 0) throw Error(`[ai] thread ${n} contains legacy messages; explicit migration is required`);
186
- let f = u ?? this.checkpointService.createInitialCheckpoint(n, a.name, c), p = i.hardConstraints === void 0 ? f : {
187
- ...f,
222
+ await this.conversationRetention?.assertNotExpired(s);
223
+ let { checkpoint: h, archive: g } = await this.checkpointService.loadThreadState(s);
224
+ if (h && h.agentId === "") throw Error(`[ai] thread ${s} is not bound to an Agent; explicit migration is required`);
225
+ if (h && h.agentId !== f.name) throw Error(`[ai] thread ${s} is bound to Agent ${h.agentId}; explicit migration is required`);
226
+ if (!h && g.length > 0) throw Error(`[ai] thread ${s} has unbound archive history; explicit migration is required`);
227
+ if (h?.messages?.length && g.length === 0) throw Error(`[ai] thread ${s} contains legacy messages; explicit migration is required`);
228
+ let _ = h ?? this.checkpointService.createInitialCheckpoint(s, f.name, p), v = u.hardConstraints === void 0 ? _ : {
229
+ ..._,
188
230
  pinnedContext: {
189
- ...f.pinnedContext,
190
- hardConstraints: [...i.hardConstraints]
231
+ ..._.pinnedContext,
232
+ hardConstraints: [...u.hardConstraints]
191
233
  }
192
- }, m = this.contextCompactionService.createSession({
193
- threadId: n,
194
- agent: a,
195
- checkpoint: p,
196
- archive: d,
197
- currentInput: c
198
- }), h = await this.traceService.createRun(a.name, t);
199
- await i.onStart?.(h.runId);
200
- let g = [], b = r ? new _() : void 0, x = !1, C = r ? (e) => {
201
- x ? r(e) : b?.push(e);
202
- } : void 0, w = /* @__PURE__ */ new Map(), T = Promise.resolve(), E = (e) => {
234
+ }, y = this.contextCompactionService.createSession({
235
+ threadId: s,
236
+ agent: f,
237
+ checkpoint: v,
238
+ archive: g,
239
+ currentInput: p
240
+ }), b = await this.traceService.createRun(f.name, i);
241
+ await u.onStart?.(b.runId);
242
+ let x = [], S = c ? new r() : void 0, C = !1, w = c ? (e) => {
243
+ C ? c(e) : S?.push(e);
244
+ } : void 0, T = /* @__PURE__ */ new Map(), E = Promise.resolve(), D = (e) => {
203
245
  let t = Object.fromEntries(Object.entries(e).filter(([, e]) => e !== void 0));
204
- return t.startedAt ??= (/* @__PURE__ */ new Date()).toISOString(), t.status !== "running" && (t.endedAt ??= t.startedAt), T = T.then(async () => {
205
- let n = w.get(e), r = n ?? t;
206
- n ? (Object.assign(n, t), await this.traceService.updateStep(h.runId, n)) : (w.set(e, r), g.push(r), await this.traceService.addStep(h.runId, r)), C?.({
246
+ return t.startedAt ??= (/* @__PURE__ */ new Date()).toISOString(), t.status !== "running" && (t.endedAt ??= t.startedAt), E = E.then(async () => {
247
+ let n = T.get(e), r = n ?? t;
248
+ n ? (Object.assign(n, t), await this.traceService.updateStep(b.runId, n)) : (T.set(e, r), x.push(r), await this.traceService.addStep(b.runId, r)), w?.({
207
249
  type: "step",
208
250
  step: structuredClone(r)
209
251
  });
210
- }), T;
211
- }, D = o.getStore();
212
- return o.run({
213
- runId: h.runId,
214
- agent: a.name,
215
- stack: [...D?.stack ?? [], a.name],
216
- record: E,
217
- ...C ? { emit: C } : {}
252
+ }), E;
253
+ }, O = this.activeParent(), k = { active: !0 };
254
+ return n.run({
255
+ runtimeId: this.runtimeId,
256
+ lease: k,
257
+ runId: b.runId,
258
+ agent: f.name,
259
+ stack: [...O?.stack ?? [], f.name],
260
+ record: D,
261
+ ...w ? { emit: w } : {}
218
262
  }, async () => {
219
- let e = m.initialMessages, t = s(this.configService), i = v([...a.skills ?? [], ...a.tools ?? []], {
220
- skillScanner: this.skillScanner,
221
- toolRegistry: this.toolRegistry
222
- }), o = S({
223
- planner: this.planner,
224
- executor: this.executor,
225
- tools: i,
226
- maxIterations: t,
227
- ...a.model ? { model: a.model } : {},
228
- prepareMessages: m.prepareMessages,
229
- getObservationOptions: (e) => this.toolRegistry.get(e)?.observation ?? {},
230
- ...C ? { onDelta: (e) => C({
231
- type: "delta",
232
- content: e
233
- }) } : {},
234
- record: E
235
- }), l = {
236
- messages: e,
237
- iteration: 0,
238
- pendingToolCalls: [],
239
- observations: [],
240
- lastContent: "",
241
- output: "",
242
- finished: !1
243
- }, u;
244
263
  try {
245
- if (b) {
246
- let e = this.runGraphStream(o, l, t, b);
247
- for (;;) {
248
- let t = await e.next();
249
- if (t.done) {
250
- u = t.value, x = !0;
251
- break;
264
+ let t = y.initialMessages, n = e(this.configService), r = a([...f.skills ?? [], ...f.tools ?? []], {
265
+ skillScanner: this.skillScanner,
266
+ toolRegistry: this.toolRegistry
267
+ }), i = l({
268
+ planner: this.planner,
269
+ executor: this.executor,
270
+ tools: r,
271
+ maxIterations: n,
272
+ ...f.model ? { model: f.model } : {},
273
+ prepareMessages: y.prepareMessages,
274
+ getObservationOptions: (e) => this.toolRegistry.get(e)?.observation ?? {},
275
+ ...w ? { onDelta: (e) => w({
276
+ type: "delta",
277
+ content: e
278
+ }) } : {},
279
+ record: D
280
+ }), u = {
281
+ messages: t,
282
+ iteration: 0,
283
+ pendingToolCalls: [],
284
+ observations: [],
285
+ lastContent: "",
286
+ output: "",
287
+ finished: !1
288
+ }, d;
289
+ try {
290
+ if (S) {
291
+ let e = this.runGraphStream(i, u, n, S);
292
+ try {
293
+ for (;;) {
294
+ let t = await e.next();
295
+ if (t.done) {
296
+ d = t.value, C = !0;
297
+ break;
298
+ }
299
+ c?.(t.value);
300
+ }
301
+ } finally {
302
+ C || await e.return(void 0);
252
303
  }
253
- r?.(t.value);
254
- }
255
- } else u = await o.invoke(l, { recursionLimit: t * 3 + 5 });
256
- } catch (e) {
257
- let t = e instanceof Error ? e.message : String(e);
258
- throw await T, await this.traceService.addStep(h.runId, {
304
+ } else d = await i.invoke(u, { recursionLimit: n * 3 + 5 });
305
+ } catch (e) {
306
+ let t = e instanceof Error ? e.message : String(e);
307
+ throw await E, await this.traceService.addStep(b.runId, {
308
+ type: "final",
309
+ content: "Agent run failed",
310
+ error: t
311
+ }), await this.traceService.finish(b.runId, { error: t }), e;
312
+ }
313
+ let m = d.output;
314
+ return o(m) || (m = o(d.lastContent) ? d.lastContent : `达到最大轮次(${n})`, await D({
259
315
  type: "final",
260
- content: "Agent run failed",
261
- error: t
262
- }), await this.traceService.finish(h.runId, { error: t }), e;
316
+ content: m
317
+ })), await this.traceService.finish(b.runId, m), await this.persistTurn(s, y.getCheckpoint(), f.name, p, m, b.runId), {
318
+ runId: b.runId,
319
+ output: m,
320
+ steps: x,
321
+ threadId: s
322
+ };
323
+ } finally {
324
+ k.active = !1;
263
325
  }
264
- let d = u.output;
265
- return y(d) || (d = y(u.lastContent) ? u.lastContent : `达到最大轮次(${t})`, await E({
266
- type: "final",
267
- content: d
268
- })), await this.traceService.finish(h.runId, d), await this.persistTurn(n, m.getCheckpoint(), a.name, c, d, h.runId), {
269
- runId: h.runId,
270
- output: d,
271
- steps: g,
272
- threadId: n
273
- };
274
326
  });
275
327
  }
276
328
  async *runGraphStream(e, t, n, r) {
277
- let i = t, a, o = (async () => {
278
- let r = await e.stream(t, {
279
- streamMode: "values",
280
- recursionLimit: n * 3 + 5
281
- });
282
- for await (let e of r) i = {
283
- ...e,
284
- output: y(e.output) ? e.output : i.output
285
- };
286
- })().catch((e) => {
287
- a = e;
288
- }).finally(() => r.close());
289
- for await (let e of r.events()) yield e;
290
- if (await o, a !== void 0) throw a;
329
+ let i = t, a, s, c = !1, l, u = !1, d = () => (c = !0, s ? (l ??= s.return(), l) : Promise.resolve()), f = (async () => {
330
+ try {
331
+ let r = await e.stream(t, {
332
+ streamMode: "values",
333
+ recursionLimit: n * 3 + 5
334
+ });
335
+ if (s = r, c) {
336
+ await d();
337
+ return;
338
+ }
339
+ for await (let e of r) i = {
340
+ ...e,
341
+ output: o(e.output) ? e.output : i.output
342
+ };
343
+ } catch (e) {
344
+ a = e;
345
+ } finally {
346
+ u = !0, r.close();
347
+ }
348
+ })();
349
+ try {
350
+ for await (let e of r.events()) yield e;
351
+ } finally {
352
+ if (!u) try {
353
+ await d();
354
+ } catch (e) {
355
+ a ??= e;
356
+ }
357
+ await f;
358
+ }
359
+ if (a !== void 0) throw a;
291
360
  return i;
292
361
  }
293
- async *runStream(e, t, n) {
294
- let r = [], i, a = !1, o, s, c = () => {
295
- let e = i;
296
- i = void 0, e?.();
297
- }, l = this.run(e, t, n, (e) => {
298
- r.push(e), c();
299
- }).then((e) => {
300
- s = e;
362
+ async *runStream(e, t, n, r = {}) {
363
+ let i = [], a, o = !1, s, c, l = () => {
364
+ let e = a;
365
+ a = void 0, e?.();
366
+ }, u = this.run(e, t, n, (e) => {
367
+ i.push(e), l();
368
+ }, r).then((e) => {
369
+ c = e;
301
370
  }).catch((e) => {
302
- o = e;
371
+ s = e;
303
372
  }).finally(() => {
304
- a = !0, c();
373
+ o = !0, l();
305
374
  });
306
- for (; !a || r.length > 0;) {
307
- if (r.length > 0) {
308
- yield r.shift();
375
+ for (; !o || i.length > 0;) {
376
+ if (i.length > 0) {
377
+ yield i.shift();
309
378
  continue;
310
379
  }
311
380
  await new Promise((e) => {
312
- i = e, (a || r.length > 0) && c();
381
+ a = e, (o || i.length > 0) && l();
313
382
  });
314
383
  }
315
- if (await l, o !== void 0) throw o;
316
- return s;
384
+ if (await u, s !== void 0) throw s;
385
+ return c;
317
386
  }
318
387
  async persistTurn(e, t, n, r, i, a) {
319
388
  (await this.checkpointService.loadArchive(e, 0)).length === 0 && t?.messages && t.messages.length > 0 && await this.checkpointService.appendArchiveMessages(e, t.messages), await this.checkpointService.appendArchiveMessages(e, [{
@@ -331,26 +400,5 @@ var U = class {
331
400
  }, o.updatedAt = Date.now(), await this.checkpointService.save(o);
332
401
  }
333
402
  };
334
- U = D([
335
- w(),
336
- O(11, T()),
337
- O(11, C(f)),
338
- O(12, T()),
339
- E("design:paramtypes", [
340
- typeof (k = m !== void 0 && m) == "function" ? k : Object,
341
- typeof (A = l !== void 0 && l) == "function" ? A : Object,
342
- typeof (j = t !== void 0 && t) == "function" ? j : Object,
343
- typeof (M = a !== void 0 && a) == "function" ? M : Object,
344
- typeof (N = c !== void 0 && c) == "function" ? N : Object,
345
- typeof (P = u !== void 0 && u) == "function" ? P : Object,
346
- typeof (F = n !== void 0 && n) == "function" ? F : Object,
347
- typeof (I = i !== void 0 && i) == "function" ? I : Object,
348
- typeof (L = r !== void 0 && r) == "function" ? L : Object,
349
- typeof (R = e !== void 0 && e) == "function" ? R : Object,
350
- typeof (z = h !== void 0 && h) == "function" ? z : Object,
351
- Object,
352
- typeof (B = p !== void 0 && p) == "function" ? B : Object
353
- ])
354
- ], U);
355
403
  //#endregion
356
- export { U as LangGraphOrchestratorService, V as ThreadMigrationConflictError };
404
+ export { f as LangGraphOrchestratorService, u as ThreadMigrationConflictError };