@_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,47 +1,41 @@
1
- import { AiConfigService as e } from "../ai-config.service.js";
2
- import { findAiDeclarationFiles as t } from "../declaration-paths.js";
3
- import { Injectable as n } from "@nestjs/common";
4
- import r from "node:fs";
5
- import i from "node:path";
6
- import { pathToFileURL as a } from "node:url";
7
- import o from "@oxc-project/runtime/helpers/decorateMetadata";
8
- import s from "@oxc-project/runtime/helpers/decorate";
1
+ import { findAiDeclarationFiles as e } from "../declaration-paths.js";
2
+ import t from "node:fs";
3
+ import n from "node:path";
4
+ import { pathToFileURL as r } from "node:url";
9
5
  //#region app/ai/agent/agent-scanner.service.ts
10
- var c, l = new Set([
6
+ var i = new Set([
11
7
  ".cjs",
12
8
  ".js",
13
9
  ".mjs"
14
10
  ]);
15
- function u(e) {
11
+ function a(e) {
16
12
  if (typeof e != "object" || !e) return !1;
17
13
  let t = e;
18
14
  return typeof t.name == "string" && t.name.trim() !== "" && Array.isArray(t.skills) && Array.isArray(t.tools);
19
15
  }
20
- async function d(e) {
21
- let t = await import(a(e).href);
22
- return [t?.default, ...Object.values(t ?? {})].find((e) => typeof e == "string" && e.trim() !== "");
16
+ function o(e) {
17
+ return typeof e == "string" && e !== "" && e.trim() === e;
23
18
  }
24
- function f(e, t, n) {
25
- if (i.isAbsolute(t)) return t;
26
- let a = i.resolve(i.dirname(e), t);
27
- return r.existsSync(a) ? a : i.resolve(n, t);
19
+ async function s(e) {
20
+ let t = await import(r(e).href);
21
+ return [t?.default, ...Object.values(t ?? {})].find((e) => typeof e == "string" && e.trim() !== "");
28
22
  }
29
- async function p(e, t, n) {
30
- let a = t.promptFile;
31
- if (typeof a != "string" || a.trim() === "") return t;
32
- let o = f(e, a, n);
23
+ async function c(e, r, a) {
24
+ let o = e.promptFile;
25
+ if (typeof o != "string" || o.trim() === "") return e;
26
+ let c = a && n.resolve(n.dirname(a), o), l = c && t.existsSync(c) ? c : n.resolve(r, o);
33
27
  try {
34
- let e = l.has(i.extname(o)) ? await d(o) : r.readFileSync(o, "utf8").trim();
35
- return e ? {
36
- ...t,
37
- prompt: e
38
- } : t;
39
- } catch (n) {
40
- let r = n instanceof Error ? n.message : String(n);
41
- return console.log(`[ai] agent promptFile unreadable: ${e} - ${o} (${r})`), t;
28
+ let r = i.has(n.extname(l)) ? await s(l) : t.readFileSync(l, "utf8").trim();
29
+ return r ? {
30
+ ...e,
31
+ prompt: r
32
+ } : e;
33
+ } catch (t) {
34
+ let n = t instanceof Error ? t.message : String(t);
35
+ return console.log(`[ai] agent promptFile unreadable: ${a ?? e.name} - ${l} (${n})`), e;
42
36
  }
43
37
  }
44
- var m = class {
38
+ var l = class {
45
39
  agents = /* @__PURE__ */ new Map();
46
40
  constructor(e) {
47
41
  this.configService = e;
@@ -58,15 +52,15 @@ var m = class {
58
52
  async scan() {
59
53
  for (let e of this.findAgentFiles()) {
60
54
  let t = await this.loadAgent(e);
61
- t && this.register(await p(e, t, this.configService.baseDir));
55
+ t && this.add(await c(t, this.configService.baseDir, e));
62
56
  }
63
57
  }
64
58
  findAgentFiles() {
65
- return t(this.configService, "agent");
59
+ return e(this.configService, "agent");
66
60
  }
67
61
  async loadAgent(e) {
68
62
  try {
69
- let t = await import(a(e).href), n = [t?.default, t].find(u);
63
+ let t = await import(r(e).href), n = [t?.default, t].find(a);
70
64
  if (!n) {
71
65
  console.log(`[ai] agent skipped, invalid definition: ${e}`);
72
66
  return;
@@ -78,7 +72,11 @@ var m = class {
78
72
  return;
79
73
  }
80
74
  }
81
- register(e) {
75
+ async register(e) {
76
+ if (!a(e) || !o(e.name) || !e.tools.every(o) || !e.skills.every(o)) throw Error("[ai] agent register fail: definition requires a non-empty name, skills, and tools");
77
+ this.add(await c(e, this.configService.baseDir));
78
+ }
79
+ add(e) {
82
80
  this.agents.has(e.name) && console.log(`[ai] agent overwritten: ${e.name}`), this.agents.set(e.name, e);
83
81
  }
84
82
  logRegisteredAgents() {
@@ -86,6 +84,5 @@ var m = class {
86
84
  console.log(`[ai] agents registered (${e.length}): ${e.join(", ")}`);
87
85
  }
88
86
  };
89
- m = s([n(), o("design:paramtypes", [typeof (c = e !== void 0 && e) == "function" ? c : Object])], m);
90
87
  //#endregion
91
- export { m as AgentScannerService };
88
+ export { l as AgentScannerService };
@@ -1,11 +1,13 @@
1
1
  import { AgentScannerService as e } from "./agent-scanner.service.js";
2
- import { Module as t } from "@nestjs/common";
3
- import n from "@oxc-project/runtime/helpers/decorate";
2
+ import { AiConfigService as t } from "../ai-config.service.js";
3
+ import { provideAiService as n } from "../nest-service-provider.js";
4
+ import { Module as r } from "@nestjs/common";
5
+ import i from "@oxc-project/runtime/helpers/decorate";
4
6
  //#region app/ai/agent/agent.module.ts
5
- var r = class {};
6
- r = n([t({
7
- providers: [e],
7
+ var a = class {};
8
+ a = i([r({
9
+ providers: [n(e, t)],
8
10
  exports: [e]
9
- })], r);
11
+ })], a);
10
12
  //#endregion
11
- export { r as AgentModule };
13
+ export { a as AgentModule };
@@ -1,17 +1,24 @@
1
1
  import { AiConfigService as e } from "./ai-config.service.js";
2
- import { Global as t, Module as n } from "@nestjs/common";
3
- import r from "@oxc-project/runtime/helpers/decorate";
2
+ import { TC_CONFIG as t } from "../../packages/core/tokens.js";
3
+ import { TemplateCoreRuntime as n } from "../../packages/core/startup.js";
4
+ import "../../packages/core/index.js";
5
+ import { Global as r, Module as i } from "@nestjs/common";
6
+ import a from "@oxc-project/runtime/helpers/decorate";
4
7
  //#region app/ai/ai-config.module.ts
5
- var i, a = i = class {
8
+ var o, s = o = class {
6
9
  static register() {
7
10
  return {
8
- module: i,
11
+ module: o,
9
12
  global: !0,
10
- providers: [e],
13
+ providers: [{
14
+ provide: e,
15
+ inject: [t, n],
16
+ useFactory: (t, n) => new e(t, n)
17
+ }],
11
18
  exports: [e]
12
19
  };
13
20
  }
14
21
  };
15
- a = i = r([t(), n({})], a);
22
+ s = o = a([r(), i({})], s);
16
23
  //#endregion
17
- export { a as AiConfigModule };
24
+ export { s as AiConfigModule };
@@ -1,19 +1,28 @@
1
- import { ConfigService as e } from "../../packages/core/config-service.js";
2
- import { TC_CONFIG as t } from "../../packages/core/tokens.js";
3
- import { TemplateCoreRuntime as n } from "../../packages/core/startup.js";
4
- import "../../packages/core/index.js";
5
- import { Inject as r, Injectable as i } from "@nestjs/common";
6
- import a from "node:path";
7
- import o from "@oxc-project/runtime/helpers/decorateMetadata";
8
- import s from "@oxc-project/runtime/helpers/decorate";
9
- import c from "@oxc-project/runtime/helpers/decorateParam";
1
+ import { snapshotData as e } from "./snapshot-data.js";
2
+ import t from "node:path";
10
3
  //#region app/ai/ai-config.service.ts
11
- var l, u, d = class {
12
- constructor(e, t) {
13
- this.configuration = e, this.runtime = t;
4
+ function n(e) {
5
+ return typeof e.baseDir == "string" && typeof e.config == "object" && e.config !== null;
6
+ }
7
+ function r(e, t) {
8
+ return Object.prototype.hasOwnProperty.call(e, t) ? e[t] : t.split(".").reduce((e, t) => {
9
+ if (!(typeof e != "object" || !e)) return e[t];
10
+ }, e);
11
+ }
12
+ var i = class {
13
+ configuration;
14
+ resolvedBaseDir;
15
+ constructor(i, a) {
16
+ if (n(i)) {
17
+ let n = e(i.config);
18
+ this.configuration = { get: (e) => r(n, e) }, this.resolvedBaseDir = t.resolve(i.baseDir);
19
+ return;
20
+ }
21
+ if (!a) throw Error("[ai] TemplateCoreRuntime is required for Nest AI configuration");
22
+ this.configuration = i, this.resolvedBaseDir = typeof a.options?.baseDir == "string" ? a.options.baseDir : process.cwd();
14
23
  }
15
24
  get baseDir() {
16
- return this.runtime.options.baseDir;
25
+ return this.resolvedBaseDir;
17
26
  }
18
27
  get(e) {
19
28
  let t = this.configuration.get(e);
@@ -26,13 +35,8 @@ var l, u, d = class {
26
35
  return i;
27
36
  }
28
37
  resolvePath(e) {
29
- return a.resolve(this.baseDir, e);
38
+ return t.resolve(this.baseDir, e);
30
39
  }
31
40
  };
32
- d = s([
33
- i(),
34
- c(0, r(t)),
35
- o("design:paramtypes", [typeof (l = e !== void 0 && e) == "function" ? l : Object, typeof (u = n !== void 0 && n) == "function" ? u : Object])
36
- ], d);
37
41
  //#endregion
38
- export { d as AiConfigService };
42
+ export { i as AiConfigService };
@@ -1,11 +1,11 @@
1
- import { AiConfigService as e } from "./ai-config.service.js";
2
- import { AgentScannerService as t } from "./agent/agent-scanner.service.js";
3
- import { ToolRegistryService as n } from "./tool/tool-registry.service.js";
4
- import { TraceService as r } from "./trace/trace.service.js";
5
- import { LangGraphOrchestratorService as i } from "./runtime/langgraph/langgraph-orchestrator.service.js";
1
+ import { AgentScannerService as e } from "./agent/agent-scanner.service.js";
2
+ import { AiConfigService as t } from "./ai-config.service.js";
3
+ import { LangGraphOrchestratorService as n } from "./runtime/langgraph/langgraph-orchestrator.service.js";
4
+ import { ToolRegistryService as r } from "./tool/tool-registry.service.js";
5
+ import { TraceService as i } from "./trace/trace.service.js";
6
6
  import { Body as a, Controller as o, Get as s, HttpCode as c, Param as l, Post as u, Res as d } from "@nestjs/common";
7
- import f from "@oxc-project/runtime/helpers/decorateMetadata";
8
- import p from "@oxc-project/runtime/helpers/decorate";
7
+ import f from "@oxc-project/runtime/helpers/decorate";
8
+ import p from "@oxc-project/runtime/helpers/decorateMetadata";
9
9
  import m from "@oxc-project/runtime/helpers/decorateParam";
10
10
  //#region app/ai/ai.controller.ts
11
11
  function h(e) {
@@ -109,53 +109,53 @@ function y(y) {
109
109
  };
110
110
  }
111
111
  };
112
- return p([
112
+ return f([
113
113
  s("tool/list"),
114
- f("design:type", Function),
115
- f("design:paramtypes", []),
116
- f("design:returntype", void 0)
117
- ], T.prototype, "toolList", null), p([
114
+ p("design:type", Function),
115
+ p("design:paramtypes", []),
116
+ p("design:returntype", void 0)
117
+ ], T.prototype, "toolList", null), f([
118
118
  s("agent/list"),
119
- f("design:type", Function),
120
- f("design:paramtypes", []),
121
- f("design:returntype", void 0)
122
- ], T.prototype, "agentList", null), p([
119
+ p("design:type", Function),
120
+ p("design:paramtypes", []),
121
+ p("design:returntype", void 0)
122
+ ], T.prototype, "agentList", null), f([
123
123
  s("agent/config"),
124
- f("design:type", Function),
125
- f("design:paramtypes", []),
126
- f("design:returntype", void 0)
127
- ], T.prototype, "agentConfig", null), p([
124
+ p("design:type", Function),
125
+ p("design:paramtypes", []),
126
+ p("design:returntype", void 0)
127
+ ], T.prototype, "agentConfig", null), f([
128
128
  s("agent/graph"),
129
- f("design:type", Function),
130
- f("design:paramtypes", []),
131
- f("design:returntype", void 0)
132
- ], T.prototype, "agentGraph", null), p([
129
+ p("design:type", Function),
130
+ p("design:paramtypes", []),
131
+ p("design:returntype", void 0)
132
+ ], T.prototype, "agentGraph", null), f([
133
133
  u("agent/run"),
134
134
  c(200),
135
135
  m(0, a()),
136
- f("design:type", Function),
137
- f("design:paramtypes", [Object]),
138
- f("design:returntype", Promise)
139
- ], T.prototype, "agentRun", null), p([
136
+ p("design:type", Function),
137
+ p("design:paramtypes", [Object]),
138
+ p("design:returntype", Promise)
139
+ ], T.prototype, "agentRun", null), f([
140
140
  u("agent/run/stream"),
141
141
  c(200),
142
142
  m(0, a()),
143
143
  m(1, d()),
144
- f("design:type", Function),
145
- f("design:paramtypes", [Object, Object]),
146
- f("design:returntype", Promise)
147
- ], T.prototype, "agentRunStream", null), p([
144
+ p("design:type", Function),
145
+ p("design:paramtypes", [Object, Object]),
146
+ p("design:returntype", Promise)
147
+ ], T.prototype, "agentRunStream", null), f([
148
148
  s("trace/:runId"),
149
149
  m(0, l("runId")),
150
- f("design:type", Function),
151
- f("design:paramtypes", [String]),
152
- f("design:returntype", Promise)
153
- ], T.prototype, "trace", null), T = p([o(`${y}/ai`), f("design:paramtypes", [
154
- typeof (b = n !== void 0 && n) == "function" ? b : Object,
155
- typeof (x = t !== void 0 && t) == "function" ? x : Object,
156
- typeof (S = i !== void 0 && i) == "function" ? S : Object,
157
- typeof (C = r !== void 0 && r) == "function" ? C : Object,
158
- typeof (w = e !== void 0 && e) == "function" ? w : Object
150
+ p("design:type", Function),
151
+ p("design:paramtypes", [String]),
152
+ p("design:returntype", Promise)
153
+ ], T.prototype, "trace", null), T = f([o(`${y}/ai`), p("design:paramtypes", [
154
+ typeof (b = r !== void 0 && r) == "function" ? b : Object,
155
+ typeof (x = e !== void 0 && e) == "function" ? x : Object,
156
+ typeof (S = n !== void 0 && n) == "function" ? S : Object,
157
+ typeof (C = i !== void 0 && i) == "function" ? C : Object,
158
+ typeof (w = t !== void 0 && t) == "function" ? w : Object
159
159
  ])], T), T;
160
160
  }
161
161
  //#endregion
@@ -2,13 +2,13 @@ import { AgentModule as e } from "./agent/agent.module.js";
2
2
  import { AiConfigModule as t } from "./ai-config.module.js";
3
3
  import { createAiController as n } from "./ai.controller.js";
4
4
  import { GuardrailModule as r } from "./guardrail/guardrail.module.js";
5
- import { SkillModule as i } from "./skill/skill.module.js";
6
- import { ToolModule as a } from "./tool/tool.module.js";
7
- import { McpModule as o } from "./mcp/mcp.module.js";
8
- import { StoreModule as s } from "./store/store.module.js";
9
- import { MemoryModule as c } from "./memory/memory.module.js";
10
- import { RagModule as l } from "./rag/rag.module.js";
11
- import { RuntimeModule as u } from "./runtime/runtime.module.js";
5
+ import { StoreModule as i } from "./store/store.module.js";
6
+ import { MemoryModule as a } from "./memory/memory.module.js";
7
+ import { SkillModule as o } from "./skill/skill.module.js";
8
+ import { ToolModule as s } from "./tool/tool.module.js";
9
+ import { RuntimeModule as c } from "./runtime/runtime.module.js";
10
+ import { McpModule as l } from "./mcp/mcp.module.js";
11
+ import { RagModule as u } from "./rag/rag.module.js";
12
12
  import { Global as d, Module as f } from "@nestjs/common";
13
13
  import p from "@oxc-project/runtime/helpers/decorate";
14
14
  //#region app/ai/ai.module.ts
@@ -16,13 +16,13 @@ var m, h = [
16
16
  t.register(),
17
17
  e,
18
18
  r,
19
- o,
20
- c,
21
19
  l,
20
+ a,
22
21
  u,
22
+ c,
23
+ o,
23
24
  i,
24
- s,
25
- a
25
+ s
26
26
  ], g = m = class {
27
27
  static register(t) {
28
28
  return {
@@ -32,13 +32,13 @@ var m, h = [
32
32
  controllers: [n(t)],
33
33
  exports: [
34
34
  e,
35
- o,
36
- c,
37
35
  l,
36
+ a,
38
37
  u,
38
+ c,
39
+ o,
39
40
  i,
40
- s,
41
- a
41
+ s
42
42
  ]
43
43
  };
44
44
  }
@@ -1,11 +1,13 @@
1
- import { GuardrailService as e } from "./guardrail.service.js";
2
- import { Module as t } from "@nestjs/common";
3
- import n from "@oxc-project/runtime/helpers/decorate";
1
+ import { AiConfigService as e } from "../ai-config.service.js";
2
+ import { provideAiService as t } from "../nest-service-provider.js";
3
+ import { GuardrailService as n } from "./guardrail.service.js";
4
+ import { Module as r } from "@nestjs/common";
5
+ import i from "@oxc-project/runtime/helpers/decorate";
4
6
  //#region app/ai/guardrail/guardrail.module.ts
5
- var r = class {};
6
- r = n([t({
7
- providers: [e],
8
- exports: [e]
9
- })], r);
7
+ var a = class {};
8
+ a = i([r({
9
+ providers: [t(n, e)],
10
+ exports: [n]
11
+ })], a);
10
12
  //#endregion
11
- export { r as GuardrailModule };
13
+ export { a as GuardrailModule };
@@ -1,15 +1,11 @@
1
- import { AiConfigService as e } from "../ai-config.service.js";
2
- import { resolveGuardrailRules as t } from "./internal/load-guardrail-config.js";
3
- import { Injectable as n } from "@nestjs/common";
4
- import r from "@oxc-project/runtime/helpers/decorateMetadata";
5
- import i from "@oxc-project/runtime/helpers/decorate";
1
+ import { resolveGuardrailRules as e } from "./internal/load-guardrail-config.js";
6
2
  //#region app/ai/guardrail/guardrail.service.ts
7
- var a, o = class {
3
+ var t = class {
8
4
  constructor(e) {
9
5
  this.configService = e;
10
6
  }
11
- check(e) {
12
- let n = typeof e == "string" ? e : String(e ?? ""), { blockedKeywords: r, blockedPatterns: i } = t(this.configService);
7
+ check(t) {
8
+ let n = typeof t == "string" ? t : String(t ?? ""), { blockedKeywords: r, blockedPatterns: i } = e(this.configService);
13
9
  for (let e of r ?? []) if (n.toLowerCase().includes(e.toLowerCase())) return {
14
10
  safe: !1,
15
11
  reason: `命中禁用关键词:${e}`
@@ -30,6 +26,5 @@ var a, o = class {
30
26
  return { safe: !0 };
31
27
  }
32
28
  };
33
- o = i([n(), r("design:paramtypes", [typeof (a = e !== void 0 && e) == "function" ? a : Object])], o);
34
29
  //#endregion
35
- export { o as GuardrailService };
30
+ export { t as GuardrailService };
@@ -0,0 +1,2 @@
1
+ import { createAiRuntime as e } from "./runtime/ai-runtime.js";
2
+ export { e as createAiRuntime };
@@ -0,0 +1,35 @@
1
+ import { createInterface as e } from "node:readline";
2
+ import { Readable as t } from "node:stream";
3
+ //#region app/ai/mcp/internal/read-sse-response.ts
4
+ function n(e, t) {
5
+ if (!e.length) return;
6
+ let n;
7
+ try {
8
+ n = JSON.parse(e.join("\n"));
9
+ } catch {
10
+ return;
11
+ }
12
+ if (!(!n || typeof n != "object" || "method" in n || !("id" in n)) && !(n.id !== t && n.id !== String(t)) && ("result" in n || "error" in n)) return n;
13
+ }
14
+ async function r(r, i, a) {
15
+ if (!r.body) throw Error("MCP SSE response has no body");
16
+ let o = t.fromWeb(r.body, { signal: a }), s = e({
17
+ input: o,
18
+ crlfDelay: Infinity
19
+ }), c = [];
20
+ try {
21
+ for await (let e of s) if (e === "") {
22
+ let e = n(c, i);
23
+ if (e) return e;
24
+ c = [];
25
+ } else e.startsWith("data:") ? c.push(e.slice(5).replace(/^ /, "")) : e === "data" && c.push("");
26
+ a.throwIfAborted();
27
+ let e = n(c, i);
28
+ if (e) return e;
29
+ throw Error(`MCP SSE stream ended before response ${i}`);
30
+ } finally {
31
+ s.close(), o.destroy();
32
+ }
33
+ }
34
+ //#endregion
35
+ export { r as readSseResponse };
@@ -0,0 +1,59 @@
1
+ import { spawn as e } from "node:child_process";
2
+ import { setTimeout as t } from "node:timers/promises";
3
+ //#region app/ai/mcp/internal/stdio-process.ts
4
+ var n = 250, r = 1e3;
5
+ function i(i) {
6
+ if (!i.command) throw Error(`MCP stdio command missing: ${i.name}`);
7
+ let a = process.platform !== "win32", o = e(i.command, i.args ?? [], {
8
+ cwd: i.cwd,
9
+ env: {
10
+ ...process.env,
11
+ ...i.env
12
+ },
13
+ stdio: [
14
+ "pipe",
15
+ "pipe",
16
+ "pipe"
17
+ ],
18
+ detached: a
19
+ }), s = o.pid, c = a && s !== void 0 && s > 1 && s !== process.pid ? s : void 0, l = !1, u;
20
+ function d(e) {
21
+ if (c === void 0) return !1;
22
+ try {
23
+ return process.kill(-c, e);
24
+ } catch (e) {
25
+ let { code: t } = e;
26
+ if (t === "EPERM") return !0;
27
+ if (t !== "ESRCH") throw e;
28
+ return c = void 0, !1;
29
+ }
30
+ }
31
+ function f(e) {
32
+ a ? d(e) : o.exitCode === null && o.signalCode === null && o.kill(e);
33
+ }
34
+ async function p(e) {
35
+ let n = performance.now() + e;
36
+ for (; d(0) || !l;) {
37
+ let e = n - performance.now();
38
+ if (e <= 0) return !1;
39
+ await t(Math.min(20, e));
40
+ }
41
+ return !0;
42
+ }
43
+ async function m() {
44
+ if (o.stdin.end(), !await p(n) && (f("SIGTERM"), !await p(n) && (f("SIGKILL"), o.stdin.destroy(), o.stdout.destroy(), o.stderr.destroy(), !await p(r)))) throw Error(`MCP stdio processes did not exit: ${i.name}`);
45
+ }
46
+ function h() {
47
+ return u ??= m();
48
+ }
49
+ return o.once("exit", () => {
50
+ h().catch(() => void 0);
51
+ }), o.once("close", () => {
52
+ l = !0;
53
+ }), {
54
+ child: o,
55
+ close: h
56
+ };
57
+ }
58
+ //#endregion
59
+ export { i as spawnStdioProcess };
@@ -1,25 +1,20 @@
1
- import { McpLoader as e } from "./mcp.loader.js";
2
- import { Injectable as t } from "@nestjs/common";
3
- import n from "@oxc-project/runtime/helpers/decorateMetadata";
4
- import r from "@oxc-project/runtime/helpers/decorate";
5
1
  //#region app/ai/mcp/mcp-registry.service.ts
6
- var i, a = class {
2
+ var e = class {
7
3
  constructor(e) {
8
4
  this.loader = e;
9
5
  }
10
6
  registerAll(e) {
11
- let t = this.loader.connections, n = [];
12
- for (let r of t) {
13
- for (let t of r.tools) {
14
- if (t.source !== "mcp") throw Error(`[ai] mcp registry 只接受 source=mcp 的 tool:${t.name}`);
15
- e.register(t), n.push(t.name);
7
+ let t = [];
8
+ for (let n of this.loader.connections) {
9
+ for (let r of n.tools) {
10
+ if (r.source !== "mcp") throw Error(`[ai] mcp registry 只接受 source=mcp 的 tool:${r.name}`);
11
+ e.register(r), t.push(r.name);
16
12
  }
17
- let t = r.tools.map((e) => e.name);
18
- console.log(`[ai] mcp server ${r.name}: ${t.length > 0 ? t.join(", ") : "(无 tool)"}`);
13
+ let r = n.tools.map((e) => e.name);
14
+ console.log(`[ai] mcp server ${n.name}: ${r.length > 0 ? r.join(", ") : "(无 tool)"}`);
19
15
  }
20
- console.log(`[ai] mcp tools registered (${n.length}): \n ${n.join(", \n")}`);
16
+ console.log(`[ai] mcp tools registered (${t.length}): \n ${t.join(", \n")}`);
21
17
  }
22
18
  };
23
- a = r([t(), n("design:paramtypes", [typeof (i = e !== void 0 && e) == "function" ? i : Object])], a);
24
19
  //#endregion
25
- export { a as McpRegistryService };
20
+ export { e as McpRegistryService };