@_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.
- package/.skills/tc-component-usage-skills/reference/component-api.md +27 -0
- package/.skills/tc-generator/SKILL.md +1 -1
- package/.skills/tc-generator/reference/project-template/ssr/apps/hello/hello.entry.tsx +6 -1
- package/.skills/tc-generator/reference/runtime-extensions.md +10 -0
- package/AGENT_README.md +8 -2
- package/CHANGE.md +27 -0
- package/README.md +157 -8
- package/cjs/app/ai/agent/agent-scanner.service.js +1 -1
- package/cjs/app/ai/agent/agent.module.js +1 -1
- package/cjs/app/ai/ai-config.module.js +1 -1
- package/cjs/app/ai/ai-config.service.js +1 -1
- package/cjs/app/ai/ai.controller.js +1 -1
- package/cjs/app/ai/ai.module.js +1 -1
- package/cjs/app/ai/guardrail/guardrail.module.js +1 -1
- package/cjs/app/ai/guardrail/guardrail.service.js +1 -1
- package/cjs/app/ai/index.js +1 -0
- package/cjs/app/ai/mcp/internal/read-sse-response.js +2 -0
- package/cjs/app/ai/mcp/internal/stdio-process.js +1 -0
- package/cjs/app/ai/mcp/mcp-registry.service.js +2 -2
- package/cjs/app/ai/mcp/mcp.client.js +2 -3
- package/cjs/app/ai/mcp/mcp.loader.js +1 -1
- package/cjs/app/ai/mcp/mcp.module.js +1 -1
- package/cjs/app/ai/memory/checkpoint.service.js +1 -1
- package/cjs/app/ai/memory/memory.module.js +1 -1
- package/cjs/app/ai/memory/thread.service.js +1 -1
- package/cjs/app/ai/models/chat-sse.js +4 -0
- package/cjs/app/ai/models/chat.js +1 -0
- package/cjs/app/ai/models/http.js +1 -0
- package/cjs/app/ai/models/image.js +1 -0
- package/cjs/app/ai/models/video.js +1 -0
- package/cjs/app/ai/nest-service-provider.js +1 -0
- package/cjs/app/ai/rag/rag.module.js +1 -1
- package/cjs/app/ai/rag/retriever.service.js +1 -1
- package/cjs/app/ai/retention/conversation-retention.service.js +1 -1
- package/cjs/app/ai/runtime/ai-runtime-startup.validator.js +1 -1
- package/cjs/app/ai/runtime/ai-runtime.js +1 -0
- package/cjs/app/ai/runtime/internal/context-compaction.service.js +3 -3
- package/cjs/app/ai/runtime/internal/declaration-snapshot.js +1 -0
- package/cjs/app/ai/runtime/internal/owned-runtime-resources.js +1 -0
- package/cjs/app/ai/runtime/langchain/langchain-planner.service.js +1 -1
- package/cjs/app/ai/runtime/langgraph/langgraph-orchestrator.service.js +1 -1
- package/cjs/app/ai/runtime/runtime.module.js +1 -1
- package/cjs/app/ai/skill/skill-scanner.service.js +1 -1
- package/cjs/app/ai/skill/skill.module.js +1 -1
- package/cjs/app/ai/snapshot-data.js +1 -0
- package/cjs/app/ai/store/internal/create-vector-store.js +1 -0
- package/cjs/app/ai/store/store.module.js +1 -1
- package/cjs/app/ai/tool/builtin/index.js +1 -1
- package/cjs/app/ai/tool/builtin/invoke-agent.tool.js +1 -1
- package/cjs/app/ai/tool/builtin/retrieve.tool.js +1 -1
- package/cjs/app/ai/tool/executor.service.js +1 -1
- package/cjs/app/ai/tool/tool-registry.service.js +1 -1
- package/cjs/app/ai/tool/tool.module.js +1 -1
- package/cjs/app/ai/trace/trace.service.js +1 -1
- package/cjs/app/csr/controller.js +1 -1
- package/cjs/app/csr/types.js +0 -0
- package/cjs/app/html/browser-options.js +1 -1
- package/cjs/app/html/shell.js +31 -16
- package/cjs/app/http/api-signing.js +1 -0
- package/cjs/app/http/body-parser.middleware.js +1 -1
- package/cjs/app/http/csp-nonce.js +1 -0
- package/cjs/app/http/error-response.js +1 -1
- package/cjs/app/http/exception-filter.js +1 -1
- package/cjs/app/http/request-body-parser-policy.js +1 -0
- package/cjs/app/http/security.guard.js +1 -1
- package/cjs/app/project/controller.js +1 -1
- package/cjs/app/project/service.js +1 -1
- package/cjs/app/providers/foundation.js +1 -1
- package/cjs/app/ssr/artifacts.js +1 -1
- package/cjs/app/ssr/controller.js +1 -1
- package/cjs/app/ssr/html.js +17 -17
- package/cjs/app/ssr/stream.js +1 -1
- package/cjs/app/static-assets.middleware.js +1 -1
- package/cjs/app/template-core.module.js +1 -1
- package/cjs/app/view/entry.tpl +2 -2
- package/cjs/bundler/buildSSR.js +1 -1
- package/cjs/bundler/entryCollect.js +1 -1
- package/cjs/bundler/feSharedConfig.js +1 -1
- package/cjs/bundler/utils.js +3 -3
- package/cjs/config/config.default.js +1 -1
- package/cjs/packages/common/index.js +1 -1
- package/cjs/packages/core/bootstrap.js +1 -1
- package/cjs/packages/core/startup.js +1 -1
- package/esm/app/ai/agent/agent-scanner.service.js +33 -36
- package/esm/app/ai/agent/agent.module.js +9 -7
- package/esm/app/ai/ai-config.module.js +14 -7
- package/esm/app/ai/ai-config.service.js +24 -20
- package/esm/app/ai/ai.controller.js +41 -41
- package/esm/app/ai/ai.module.js +15 -15
- package/esm/app/ai/guardrail/guardrail.module.js +11 -9
- package/esm/app/ai/guardrail/guardrail.service.js +5 -10
- package/esm/app/ai/index.js +2 -0
- package/esm/app/ai/mcp/internal/read-sse-response.js +35 -0
- package/esm/app/ai/mcp/internal/stdio-process.js +59 -0
- package/esm/app/ai/mcp/mcp-registry.service.js +10 -15
- package/esm/app/ai/mcp/mcp.client.js +77 -78
- package/esm/app/ai/mcp/mcp.loader.js +64 -42
- package/esm/app/ai/mcp/mcp.module.js +62 -22
- package/esm/app/ai/memory/checkpoint.service.js +18 -28
- package/esm/app/ai/memory/memory.module.js +15 -12
- package/esm/app/ai/memory/thread.service.js +21 -26
- package/esm/app/ai/models/chat-sse.js +44 -0
- package/esm/app/ai/models/chat.js +60 -0
- package/esm/app/ai/models/http.js +52 -0
- package/esm/app/ai/models/image.js +37 -0
- package/esm/app/ai/models/video.js +32 -0
- package/esm/app/ai/nest-service-provider.js +10 -0
- package/esm/app/ai/rag/rag.module.js +24 -15
- package/esm/app/ai/rag/retriever.service.js +37 -54
- package/esm/app/ai/retention/conversation-retention.service.js +16 -34
- package/esm/app/ai/runtime/ai-runtime-startup.validator.js +2 -19
- package/esm/app/ai/runtime/ai-runtime.js +104 -0
- package/esm/app/ai/runtime/internal/context-compaction.service.js +139 -145
- package/esm/app/ai/runtime/internal/declaration-snapshot.js +32 -0
- package/esm/app/ai/runtime/internal/owned-runtime-resources.js +21 -0
- package/esm/app/ai/runtime/langchain/langchain-planner.service.js +43 -49
- package/esm/app/ai/runtime/langgraph/langgraph-orchestrator.service.js +273 -225
- package/esm/app/ai/runtime/runtime.module.js +56 -35
- package/esm/app/ai/skill/skill-scanner.service.js +11 -16
- package/esm/app/ai/skill/skill.module.js +11 -9
- package/esm/app/ai/snapshot-data.js +24 -0
- package/esm/app/ai/store/internal/create-vector-store.js +10 -0
- package/esm/app/ai/store/store.module.js +9 -13
- package/esm/app/ai/tool/builtin/index.js +16 -4
- package/esm/app/ai/tool/builtin/invoke-agent.tool.js +30 -34
- package/esm/app/ai/tool/builtin/retrieve.tool.js +9 -13
- package/esm/app/ai/tool/executor.service.js +22 -29
- package/esm/app/ai/tool/tool-registry.service.js +6 -16
- package/esm/app/ai/tool/tool.module.js +26 -12
- package/esm/app/ai/trace/trace.service.js +15 -28
- package/esm/app/csr/controller.js +114 -63
- package/esm/app/csr/types.js +0 -0
- package/esm/app/html/browser-options.js +2 -2
- package/esm/app/html/shell.js +173 -32
- package/esm/app/http/api-signing.js +13 -0
- package/esm/app/http/body-parser.middleware.js +47 -27
- package/esm/app/http/csp-nonce.js +13 -0
- package/esm/app/http/error-response.js +8 -5
- package/esm/app/http/exception-filter.js +4 -4
- package/esm/app/http/request-body-parser-policy.js +46 -0
- package/esm/app/http/security.guard.js +23 -21
- package/esm/app/project/controller.js +15 -15
- package/esm/app/project/service.js +3 -3
- package/esm/app/providers/foundation.js +5 -5
- package/esm/app/ssr/artifacts.js +25 -21
- package/esm/app/ssr/controller.js +148 -75
- package/esm/app/ssr/html.js +49 -44
- package/esm/app/ssr/stream.js +25 -24
- package/esm/app/static-assets.middleware.js +4 -4
- package/esm/app/template-core.module.js +57 -52
- package/esm/app/view/entry.tpl +2 -2
- package/esm/bundler/buildSSR.js +1 -1
- package/esm/bundler/entryCollect.js +9 -9
- package/esm/bundler/feSharedConfig.js +42 -42
- package/esm/bundler/utils.js +78 -90
- package/esm/config/config.default.js +4 -3
- package/esm/packages/common/index.js +6 -6
- package/esm/packages/core/bootstrap.js +5 -5
- package/esm/packages/core/startup.js +69 -46
- package/fe/frontend/src/common/request.js +5 -2
- package/fe/frontend/src/hooks/useRouterParams.d.ts +4 -2
- package/fe/packages/common/ssr/hydration.d.ts +9 -0
- package/fe/packages/react/core/Label/Label.d.ts +1 -0
- package/fe/packages/react/core/Label/Label.js +3 -1
- package/fe/packages/react/core/internal/i18n/default.d.ts +13 -0
- package/fe/packages/react/core/internal/i18n/default.js +16 -1
- package/fe/packages/react/core/internal/i18n/en-US.d.ts +13 -0
- package/fe/packages/react/core/internal/i18n/en-US.js +16 -1
- package/fe/packages/react/forms/DataTable/index.d.ts +2 -0
- package/fe/packages/react/forms/DataTable/index.js +43 -29
- package/fe/packages/react/forms/Form/FormItem.js +39 -12
- package/fe/packages/react/forms/MultiSelect/MultiSelect.d.ts +26 -0
- package/fe/packages/react/forms/MultiSelect/MultiSelect.js +218 -0
- package/fe/packages/react/forms/MultiSelect/index.d.ts +1 -0
- package/fe/packages/react/forms/MultiSelect/index.js +2 -0
- package/fe/packages/react/forms/Pagination/Pagination.d.ts +6 -1
- package/fe/packages/react/forms/Pagination/Pagination.js +13 -4
- package/fe/packages/react/forms/Select/Select.d.ts +11 -0
- package/fe/packages/react/forms/Select/Select.js +20 -7
- package/fe/packages/react/forms/index.d.ts +1 -0
- package/fe/packages/react/forms/index.js +3 -1
- package/fe/packages/react/i18n/getUiReactLocale.d.ts +26 -0
- package/fe/packages/react/index.js +2 -1
- package/fe/packages/react/overlays/Drawer/Drawer.d.ts +3 -2
- package/fe/packages/react/overlays/Drawer/Drawer.js +16 -2
- package/fe/packages/react/overlays/Dropdown/Dropdown.d.ts +12 -2
- package/fe/packages/react/overlays/Dropdown/Dropdown.js +27 -14
- package/fe/packages/react/overlays/Modal/Modal.d.ts +11 -3
- package/fe/packages/react/overlays/Modal/Modal.js +26 -2
- package/fe/packages/react/overlays/Modal/ModalManager.d.ts +13 -12
- package/fe/packages/react/overlays/Modal/ModalManager.js +15 -5
- package/fe/packages/react/overlays/Modal/index.d.ts +1 -0
- package/fe/packages/react/overlays/Overlay/Overlay.d.ts +6 -2
- package/fe/packages/react/overlays/Overlay/Overlay.js +31 -14
- package/fe/packages/react/overlays/Overlay/focusTypes.d.ts +8 -0
- package/fe/packages/react/overlays/Overlay/focusTypes.js +0 -0
- package/fe/packages/react/overlays/Overlay/index.d.ts +1 -0
- package/fe/packages/react/overlays/Overlay/overlayStack.d.ts +16 -0
- package/fe/packages/react/overlays/Overlay/overlayStack.js +290 -0
- package/fe/packages/react/overlays/Popup/Popup.d.ts +5 -4
- package/fe/packages/react/overlays/Popup/Popup.js +28 -11
- package/fe/packages/react/ui/components/index.js +2 -1
- package/fe/packages/react/ui/index.js +2 -1
- package/fe/ssr/components/StreamingRender/StreamingCache.d.ts +1 -0
- package/fe/ssr/components/StreamingRender/StreamingCache.js +5 -1
- package/fe/ssr/components/StreamingRender/StreamingRender.js +1 -1
- package/fe/ssr/components/StreamingRender/StreamingScript.d.ts +1 -0
- package/fe/ssr/components/StreamingRender/StreamingScript.js +9 -1
- package/fe/ssr/createSSREntry.d.ts +9 -3
- package/fe/ssr/createSSREntry.js +43 -19
- package/fe/ssr/index.d.ts +4 -1
- package/fe/ssr/index.js +2 -1
- package/fe/ssr/router.d.ts +76 -0
- package/fe/ssr/router.js +349 -0
- package/fe/ssr/types.d.ts +1 -1
- package/models/packages/common/ssr/hydration.d.ts +9 -0
- package/models/packages/react/core/Label/Label.d.ts +1 -0
- package/models/packages/react/core/internal/i18n/default.d.ts +13 -0
- package/models/packages/react/core/internal/i18n/en-US.d.ts +13 -0
- package/models/packages/react/forms/DataTable/index.d.ts +2 -0
- package/models/packages/react/forms/MultiSelect/MultiSelect.d.ts +26 -0
- package/models/packages/react/forms/MultiSelect/index.d.ts +1 -0
- package/models/packages/react/forms/Pagination/Pagination.d.ts +6 -1
- package/models/packages/react/forms/Select/Select.d.ts +11 -0
- package/models/packages/react/forms/index.d.ts +1 -0
- package/models/packages/react/i18n/getUiReactLocale.d.ts +26 -0
- package/models/packages/react/overlays/Drawer/Drawer.d.ts +3 -2
- package/models/packages/react/overlays/Dropdown/Dropdown.d.ts +12 -2
- package/models/packages/react/overlays/Modal/Modal.d.ts +11 -3
- package/models/packages/react/overlays/Modal/ModalManager.d.ts +13 -12
- package/models/packages/react/overlays/Modal/index.d.ts +1 -0
- package/models/packages/react/overlays/Overlay/Overlay.d.ts +6 -2
- package/models/packages/react/overlays/Overlay/focusTypes.d.ts +8 -0
- package/models/packages/react/overlays/Overlay/index.d.ts +1 -0
- package/models/packages/react/overlays/Overlay/overlayStack.d.ts +16 -0
- package/models/packages/react/overlays/Popup/Popup.d.ts +5 -4
- package/package.json +26 -1
- package/types/app/ai/agent/agent-scanner.service.d.ts +4 -4
- package/types/app/ai/ai-config.service.d.ts +7 -3
- package/types/app/ai/guardrail/guardrail.service.d.ts +2 -2
- package/types/app/ai/index.d.ts +9 -0
- package/types/app/ai/mcp/internal/load-mcp-config.d.ts +2 -2
- package/types/app/ai/mcp/internal/read-sse-response.d.ts +2 -0
- package/types/app/ai/mcp/internal/stdio-process.d.ts +5 -0
- package/types/app/ai/mcp/mcp-registry.service.d.ts +5 -3
- package/types/app/ai/mcp/mcp.client.d.ts +7 -4
- package/types/app/ai/mcp/mcp.loader.d.ts +11 -11
- package/types/app/ai/mcp/mcp.module.d.ts +5 -5
- package/types/app/ai/memory/thread.service.d.ts +3 -3
- package/types/app/ai/models/chat-sse.d.ts +5 -0
- package/types/app/ai/models/chat.d.ts +22 -0
- package/types/app/ai/models/http.d.ts +20 -0
- package/types/app/ai/models/image.d.ts +69 -0
- package/types/app/ai/models/video.d.ts +99 -0
- package/types/app/ai/nest-service-provider.d.ts +6 -0
- package/types/app/ai/retention/conversation-retention.service.d.ts +3 -4
- package/types/app/ai/runtime/ai-runtime-startup.validator.d.ts +2 -3
- package/types/app/ai/runtime/ai-runtime.d.ts +46 -0
- package/types/app/ai/runtime/internal/agent-run-context.d.ts +4 -0
- package/types/app/ai/runtime/internal/context-compaction.service.d.ts +2 -2
- package/types/app/ai/runtime/internal/declaration-snapshot.d.ts +8 -0
- package/types/app/ai/runtime/internal/owned-runtime-resources.d.ts +5 -0
- package/types/app/ai/runtime/langchain/langchain-planner.service.d.ts +1 -1
- package/types/app/ai/runtime/langgraph/langgraph-orchestrator.service.d.ts +33 -16
- package/types/app/ai/skill/skill-scanner.service.d.ts +3 -4
- package/types/app/ai/snapshot-data.d.ts +1 -0
- package/types/app/ai/store/internal/create-vector-store.d.ts +4 -0
- package/types/app/ai/tool/builtin/index.d.ts +1 -1
- package/types/app/ai/tool/builtin/invoke-agent.tool.d.ts +10 -3
- package/types/app/ai/tool/builtin/retrieve.tool.d.ts +4 -3
- package/types/app/ai/tool/executor.service.d.ts +3 -3
- package/types/app/ai/tool/tool-registry.service.d.ts +2 -7
- package/types/app/ai/tool/tool.interface.d.ts +1 -1
- package/types/app/ai/tool/tool.module.d.ts +8 -1
- package/types/app/ai/trace/trace.service.d.ts +4 -5
- package/types/app/csr/types.d.ts +10 -0
- package/types/app/html/browser-options.d.ts +1 -1
- package/types/app/html/shell.d.ts +37 -10
- package/types/app/http/api-signing.d.ts +16 -0
- package/types/app/http/body-parser.middleware.d.ts +6 -2
- package/types/app/http/csp-nonce.d.ts +3 -0
- package/types/app/http/error-response.d.ts +1 -0
- package/types/app/http/request-body-parser-policy.d.ts +8 -0
- package/types/app/http/security.guard.d.ts +1 -0
- package/types/app/ssr/artifacts.d.ts +6 -3
- package/types/app/ssr/html.d.ts +7 -0
- package/types/app/ssr/stream.d.ts +1 -1
- package/types/app/ssr/types.d.ts +56 -0
- package/types/bundler/buildSSR.d.ts +2 -1
- package/types/bundler/index.d.ts +1 -1
- package/types/bundler/state.d.ts +13 -0
- package/types/bundler/utils.d.ts +3 -14
- package/types/config/config.default.d.ts +9 -3
- package/types/index.d.ts +4 -1
- package/types/packages/common/ssr/hydration.d.ts +13 -0
- package/types/packages/core/index.d.ts +1 -1
- package/types/packages/core/startup.d.ts +41 -0
|
@@ -1,34 +1,41 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { readSseResponse as e } from "./internal/read-sse-response.js";
|
|
2
|
+
import { spawnStdioProcess as t } from "./internal/stdio-process.js";
|
|
3
|
+
import { DEFAULT_MCP_TIMEOUT_MS as n, MCP_PROTOCOL_VERSION as r } from "./mcp.types.js";
|
|
3
4
|
//#region app/ai/mcp/mcp.client.ts
|
|
4
|
-
|
|
5
|
+
var i = 1e3;
|
|
6
|
+
function a(e) {
|
|
5
7
|
return typeof e == "object" && !!e && !Array.isArray(e);
|
|
6
8
|
}
|
|
7
|
-
function
|
|
8
|
-
return
|
|
9
|
+
function o(e) {
|
|
10
|
+
return a(e) && typeof e.name == "string" && e.name.trim() !== "" && (e.description === void 0 || typeof e.description == "string") && (e.inputSchema === void 0 || a(e.inputSchema));
|
|
9
11
|
}
|
|
10
|
-
function
|
|
12
|
+
function s(e) {
|
|
11
13
|
return e instanceof Error ? e.message : String(e);
|
|
12
14
|
}
|
|
13
|
-
var
|
|
15
|
+
var c = class {
|
|
14
16
|
transport;
|
|
15
17
|
timeoutMs;
|
|
16
18
|
pending = /* @__PURE__ */ new Map();
|
|
19
|
+
httpLifetime = new AbortController();
|
|
17
20
|
nextId = 1;
|
|
18
21
|
stdoutBuffer = "";
|
|
19
|
-
|
|
22
|
+
stdio;
|
|
20
23
|
sessionId;
|
|
21
|
-
|
|
24
|
+
handshake;
|
|
25
|
+
closing;
|
|
22
26
|
deadReason;
|
|
23
|
-
constructor(
|
|
24
|
-
this.config =
|
|
27
|
+
constructor(e) {
|
|
28
|
+
this.config = e, this.transport = e.command ? "stdio" : "http", this.timeoutMs = e.timeoutMs !== void 0 && e.timeoutMs > 0 ? e.timeoutMs : n;
|
|
25
29
|
}
|
|
26
30
|
get name() {
|
|
27
31
|
return this.config.name;
|
|
28
32
|
}
|
|
29
|
-
|
|
33
|
+
connect() {
|
|
34
|
+
return this.closing ? Promise.reject(/* @__PURE__ */ Error(`MCP client 已关闭:${this.name}`)) : this.deadReason ? Promise.reject(/* @__PURE__ */ Error(`MCP ${this.name} ${this.deadReason}`)) : this.handshake ??= this.initialize();
|
|
35
|
+
}
|
|
36
|
+
async initialize() {
|
|
30
37
|
this.transport === "stdio" && this.startStdio(), await this.request("initialize", {
|
|
31
|
-
protocolVersion:
|
|
38
|
+
protocolVersion: r,
|
|
32
39
|
capabilities: {},
|
|
33
40
|
clientInfo: {
|
|
34
41
|
name: "template-core",
|
|
@@ -37,8 +44,17 @@ var o = class {
|
|
|
37
44
|
}), await this.notify("notifications/initialized");
|
|
38
45
|
}
|
|
39
46
|
async listTools() {
|
|
40
|
-
let e =
|
|
41
|
-
|
|
47
|
+
let e = [], t = /* @__PURE__ */ new Set(), n;
|
|
48
|
+
do {
|
|
49
|
+
let r = await this.request("tools/list", n === void 0 ? {} : { cursor: n });
|
|
50
|
+
if (!a(r)) break;
|
|
51
|
+
if (Array.isArray(r.tools)) for (let t of r.tools) o(t) && e.push(t);
|
|
52
|
+
if (n = typeof r.nextCursor == "string" ? r.nextCursor : void 0, n !== void 0) {
|
|
53
|
+
if (t.has(n)) throw Error(`MCP tools/list repeated cursor: ${this.name}`);
|
|
54
|
+
t.add(n);
|
|
55
|
+
}
|
|
56
|
+
} while (n !== void 0);
|
|
57
|
+
return e;
|
|
42
58
|
}
|
|
43
59
|
callTool(e, t) {
|
|
44
60
|
return this.request("tools/call", {
|
|
@@ -46,19 +62,11 @@ var o = class {
|
|
|
46
62
|
arguments: t ?? {}
|
|
47
63
|
});
|
|
48
64
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (this.closed = !0, this.failAll("连接已关闭"), this.child) {
|
|
52
|
-
try {
|
|
53
|
-
this.child.stdin.end();
|
|
54
|
-
} catch {}
|
|
55
|
-
this.child.kill(), this.child = void 0;
|
|
56
|
-
}
|
|
57
|
-
this.sessionId = void 0, this.stdoutBuffer = "";
|
|
58
|
-
}
|
|
65
|
+
close() {
|
|
66
|
+
return this.closing ? this.closing : (this.failAll("连接已关闭"), this.httpLifetime.abort(/* @__PURE__ */ Error(`MCP client 已关闭:${this.name}`)), this.stdoutBuffer = "", this.closing = this.stdio?.close() ?? this.closeHttpSession(), this.closing);
|
|
59
67
|
}
|
|
60
68
|
request(e, t) {
|
|
61
|
-
if (this.
|
|
69
|
+
if (this.closing) return Promise.reject(/* @__PURE__ */ Error(`MCP client 已关闭,无法调用 ${e}:${this.config.name}`));
|
|
62
70
|
if (this.deadReason) return Promise.reject(/* @__PURE__ */ Error(`MCP ${e} 失败:${this.config.name} ${this.deadReason}`));
|
|
63
71
|
let n = this.nextId++, r = {
|
|
64
72
|
jsonrpc: "2.0",
|
|
@@ -94,28 +102,16 @@ var o = class {
|
|
|
94
102
|
await this.postHttp(n);
|
|
95
103
|
}
|
|
96
104
|
startStdio() {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
...process.env,
|
|
101
|
-
...this.config.env ?? {}
|
|
102
|
-
},
|
|
103
|
-
stdio: [
|
|
104
|
-
"pipe",
|
|
105
|
-
"pipe",
|
|
106
|
-
"pipe"
|
|
107
|
-
]
|
|
108
|
-
});
|
|
109
|
-
e.stdout.setEncoding("utf8"), e.stdout.on("data", (e) => this.consumeStdout(e)), e.stdin.on("error", (e) => {
|
|
110
|
-
console.log(`[ai] mcp ${this.config.name} stdin error: ${a(e)}`);
|
|
111
|
-
}), e.stderr.setEncoding("utf8"), e.stderr.on("data", (e) => {
|
|
105
|
+
this.stdio = t(this.config);
|
|
106
|
+
let { child: e } = this.stdio;
|
|
107
|
+
e.stdout.setEncoding("utf8"), e.stdout.on("data", (e) => this.consumeStdout(e)), e.stdout.once("end", () => this.markDead("stdio stdout 已关闭")), e.stdout.on("error", (e) => this.markDead(`stdio stdout - ${e.message}`)), e.stdin.on("error", (e) => this.markDead(`stdio stdin - ${e.message}`)), e.stderr.setEncoding("utf8"), e.stderr.on("data", (e) => {
|
|
112
108
|
let t = String(e).trim();
|
|
113
109
|
t !== "" && console.log(`[ai] mcp ${this.config.name} stderr: ${t}`);
|
|
114
110
|
}), e.on("error", (e) => {
|
|
115
|
-
this.markDead(`启动失败 - ${
|
|
111
|
+
this.markDead(`启动失败 - ${s(e)}`);
|
|
116
112
|
}), e.on("exit", (e, t) => {
|
|
117
113
|
this.markDead(`server 已退出(code=${e ?? "-"} signal=${t ?? "-"})`);
|
|
118
|
-
})
|
|
114
|
+
});
|
|
119
115
|
}
|
|
120
116
|
consumeStdout(e) {
|
|
121
117
|
this.stdoutBuffer += e;
|
|
@@ -136,43 +132,46 @@ var o = class {
|
|
|
136
132
|
this.handleMessage(t);
|
|
137
133
|
}
|
|
138
134
|
writeStdio(e) {
|
|
139
|
-
if (!this.child
|
|
140
|
-
this.child.stdin.write(`${JSON.stringify(e)}\n`);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
let
|
|
135
|
+
if (!this.stdio?.child.stdin.writable) throw Error(`MCP stdio 通道不可写:${this.config.name}`);
|
|
136
|
+
this.stdio.child.stdin.write(`${JSON.stringify(e)}\n`);
|
|
137
|
+
}
|
|
138
|
+
httpHeaders() {
|
|
139
|
+
let e = new Headers(this.config.headers);
|
|
140
|
+
return e.has("Content-Type") || e.set("Content-Type", "application/json"), e.has("Accept") || e.set("Accept", "application/json, text/event-stream"), e.set("Connection", "close"), this.sessionId && e.set("Mcp-Session-Id", this.sessionId), e;
|
|
141
|
+
}
|
|
142
|
+
async closeHttpSession() {
|
|
143
|
+
if (!this.sessionId) return;
|
|
144
|
+
let e = this.httpHeaders();
|
|
145
|
+
this.sessionId = void 0;
|
|
146
|
+
let t = await fetch(this.config.url, {
|
|
147
|
+
method: "DELETE",
|
|
148
|
+
headers: e,
|
|
149
|
+
signal: AbortSignal.timeout(Math.min(i, this.timeoutMs))
|
|
150
|
+
});
|
|
151
|
+
if (await t.body?.cancel(), !t.ok && ![
|
|
152
|
+
404,
|
|
153
|
+
405,
|
|
154
|
+
410,
|
|
155
|
+
501
|
|
156
|
+
].includes(t.status)) throw Error(`MCP HTTP DELETE 失败:${this.name} ${t.status} ${t.statusText}`);
|
|
157
|
+
}
|
|
158
|
+
async postHttp(t, n) {
|
|
159
|
+
let r = AbortSignal.any([this.httpLifetime.signal, AbortSignal.timeout(this.timeoutMs)]), i = await fetch(this.config.url, {
|
|
144
160
|
method: "POST",
|
|
145
|
-
headers:
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}), r = n.headers.get("mcp-session-id");
|
|
154
|
-
if (r && (this.sessionId = r), !n.ok) throw Error(`MCP HTTP ${e.method} 失败:${n.status} ${n.statusText}`);
|
|
155
|
-
if (t !== void 0) {
|
|
156
|
-
if ((n.headers.get("content-type") ?? "").includes("text/event-stream")) {
|
|
157
|
-
for (let e of this.parseSse(await n.text())) this.handleMessage(e);
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
this.handleMessage(await n.json());
|
|
161
|
+
headers: this.httpHeaders(),
|
|
162
|
+
body: JSON.stringify(t),
|
|
163
|
+
signal: r
|
|
164
|
+
}), a = i.headers.get("mcp-session-id");
|
|
165
|
+
if (a && !this.httpLifetime.signal.aborted && t.method === "initialize" && (this.sessionId = a), !i.ok) throw await i.body?.cancel(), Error(`MCP HTTP ${t.method} 失败:${i.status} ${i.statusText}`);
|
|
166
|
+
if (n === void 0) {
|
|
167
|
+
await i.body?.cancel();
|
|
168
|
+
return;
|
|
161
169
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
for (let n of e.split("\n")) {
|
|
166
|
-
let e = n.trim();
|
|
167
|
-
if (!e.startsWith("data:")) continue;
|
|
168
|
-
let r = e.slice(5).trim();
|
|
169
|
-
if (!(r === "" || r === "[DONE]")) try {
|
|
170
|
-
t.push(JSON.parse(r));
|
|
171
|
-
} catch {
|
|
172
|
-
console.log(`[ai] mcp ${this.config.name} SSE data 非 JSON,已忽略`);
|
|
173
|
-
}
|
|
170
|
+
if ((i.headers.get("content-type") ?? "").includes("text/event-stream")) {
|
|
171
|
+
this.settle(n, await e(i, n, r));
|
|
172
|
+
return;
|
|
174
173
|
}
|
|
175
|
-
|
|
174
|
+
this.handleMessage(await i.json());
|
|
176
175
|
}
|
|
177
176
|
handleMessage(e) {
|
|
178
177
|
let t = e;
|
|
@@ -196,4 +195,4 @@ var o = class {
|
|
|
196
195
|
}
|
|
197
196
|
};
|
|
198
197
|
//#endregion
|
|
199
|
-
export {
|
|
198
|
+
export { c as McpClient };
|
|
@@ -1,63 +1,85 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { McpClient as n } from "./mcp.client.js";
|
|
4
|
-
import { Injectable as r } from "@nestjs/common";
|
|
5
|
-
import i from "@oxc-project/runtime/helpers/decorateMetadata";
|
|
6
|
-
import a from "@oxc-project/runtime/helpers/decorate";
|
|
1
|
+
import { loadMcpConfig as e } from "./internal/load-mcp-config.js";
|
|
2
|
+
import { McpClient as t } from "./mcp.client.js";
|
|
7
3
|
//#region app/ai/mcp/mcp.loader.ts
|
|
8
|
-
|
|
9
|
-
function s(e) {
|
|
10
|
-
return e instanceof Error ? e.message : String(e);
|
|
11
|
-
}
|
|
12
|
-
function c(e, t, n) {
|
|
4
|
+
function n(e, t) {
|
|
13
5
|
return {
|
|
14
|
-
name:
|
|
15
|
-
description:
|
|
16
|
-
inputSchema:
|
|
6
|
+
name: t.name,
|
|
7
|
+
description: t.description ?? `MCP tool from ${e.name}`,
|
|
8
|
+
inputSchema: t.inputSchema ?? {},
|
|
17
9
|
source: "mcp",
|
|
18
|
-
execute(e)
|
|
19
|
-
return t.callTool(n.name, e);
|
|
20
|
-
}
|
|
10
|
+
execute: (n) => e.callTool(t.name, n)
|
|
21
11
|
};
|
|
22
12
|
}
|
|
23
|
-
var
|
|
13
|
+
var r = class {
|
|
14
|
+
clients = [];
|
|
24
15
|
loaded = [];
|
|
16
|
+
loading;
|
|
17
|
+
closing;
|
|
25
18
|
constructor(e) {
|
|
26
19
|
this.configService = e;
|
|
27
20
|
}
|
|
28
21
|
loadMcpConfig() {
|
|
29
|
-
let
|
|
30
|
-
return
|
|
22
|
+
let t = e(this.configService);
|
|
23
|
+
return t.enabled ? t.servers : (t.servers.length && console.log("[ai] mcp 已配置 servers 但 ai.mcp.enabled 未打开,跳过"), []);
|
|
24
|
+
}
|
|
25
|
+
load({ skipUnavailable: e = !1 } = {}) {
|
|
26
|
+
return this.closing ? Promise.reject(/* @__PURE__ */ Error("[ai] MCP loader is closing")) : this.loading ??= this.openServers(this.clients, e);
|
|
31
27
|
}
|
|
32
|
-
async
|
|
33
|
-
let
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
async discover(e, t) {
|
|
29
|
+
let r;
|
|
30
|
+
try {
|
|
31
|
+
await e.connect(), r = await e.listTools();
|
|
32
|
+
} catch (n) {
|
|
33
|
+
let r = n instanceof Error ? n.message : String(n), i = Error(`[ai] mcp server 连接失败:${e.name} - ${r}`, { cause: n });
|
|
34
|
+
if (!t) throw i;
|
|
36
35
|
try {
|
|
37
|
-
await e.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
name: t.name,
|
|
41
|
-
client: e,
|
|
42
|
-
tools: n.map((n) => c(t.name, e, n))
|
|
43
|
-
});
|
|
44
|
-
} catch (n) {
|
|
45
|
-
console.log(`[ai] mcp server 连接失败:${t.name} - ${s(n)}`), await e.close().catch(() => void 0);
|
|
36
|
+
await e.close();
|
|
37
|
+
} catch (e) {
|
|
38
|
+
throw AggregateError([i, e], i.message, { cause: i });
|
|
46
39
|
}
|
|
40
|
+
console.warn(i.message);
|
|
41
|
+
return;
|
|
47
42
|
}
|
|
48
|
-
return
|
|
43
|
+
return {
|
|
44
|
+
name: e.name,
|
|
45
|
+
client: e,
|
|
46
|
+
tools: r.map((t) => n(e, t))
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
async openServers(e, n) {
|
|
50
|
+
let r = [];
|
|
51
|
+
try {
|
|
52
|
+
for (let i of this.loadMcpConfig()) {
|
|
53
|
+
let a = new t(i);
|
|
54
|
+
e.push(a);
|
|
55
|
+
let o = await this.discover(a, n);
|
|
56
|
+
if (e !== this.clients) throw Error("MCP loader closed during discovery");
|
|
57
|
+
o ? r.push(o) : e.pop();
|
|
58
|
+
}
|
|
59
|
+
} catch (t) {
|
|
60
|
+
try {
|
|
61
|
+
await (e === this.clients ? this.closeAll() : this.closing);
|
|
62
|
+
} catch (e) {
|
|
63
|
+
throw AggregateError([t, e], "[ai] MCP startup and rollback failed", { cause: t });
|
|
64
|
+
}
|
|
65
|
+
throw t;
|
|
66
|
+
}
|
|
67
|
+
return this.loaded = r, r;
|
|
49
68
|
}
|
|
50
69
|
get connections() {
|
|
51
70
|
return this.loaded;
|
|
52
71
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
72
|
+
closeAll() {
|
|
73
|
+
if (this.closing) return this.closing;
|
|
74
|
+
let e = this.clients;
|
|
75
|
+
return this.clients = [], this.loaded = [], this.closing = Promise.allSettled(e.map((e) => e.close())).then((e) => {
|
|
76
|
+
let t = e.flatMap((e) => e.status === "rejected" ? [e.reason] : []);
|
|
77
|
+
if (t.length === 1) throw t[0];
|
|
78
|
+
if (t.length > 1) throw AggregateError(t, "[ai] MCP clients failed to close");
|
|
79
|
+
}).finally(() => {
|
|
80
|
+
this.loading = void 0, this.closing = void 0;
|
|
81
|
+
}), this.closing;
|
|
59
82
|
}
|
|
60
83
|
};
|
|
61
|
-
l = a([r(), i("design:paramtypes", [typeof (o = e !== void 0 && e) == "function" ? o : Object])], l);
|
|
62
84
|
//#endregion
|
|
63
|
-
export {
|
|
85
|
+
export { r as McpLoader };
|
|
@@ -1,30 +1,70 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import a from "
|
|
7
|
-
import o from "
|
|
1
|
+
import { AiConfigService as e } from "../ai-config.service.js";
|
|
2
|
+
import { LangGraphOrchestratorService as t } from "../runtime/langgraph/langgraph-orchestrator.service.js";
|
|
3
|
+
import { ToolRegistryService as n } from "../tool/tool-registry.service.js";
|
|
4
|
+
import { ToolModule as r } from "../tool/tool.module.js";
|
|
5
|
+
import { RuntimeModule as i } from "../runtime/runtime.module.js";
|
|
6
|
+
import { McpRegistryService as a } from "./mcp-registry.service.js";
|
|
7
|
+
import { McpLoader as o } from "./mcp.loader.js";
|
|
8
|
+
import { Inject as s, Module as c } from "@nestjs/common";
|
|
9
|
+
import l from "@oxc-project/runtime/helpers/decorate";
|
|
10
|
+
import u from "@oxc-project/runtime/helpers/decorateMetadata";
|
|
11
|
+
import d from "@oxc-project/runtime/helpers/decorateParam";
|
|
8
12
|
//#region app/ai/mcp/mcp.module.ts
|
|
9
|
-
var
|
|
10
|
-
constructor(e, t, n) {
|
|
11
|
-
this.loader = e, this.registry = t, this.toolRegistry = n;
|
|
13
|
+
var f, p, m, h, g = class {
|
|
14
|
+
constructor(e, t, n, r) {
|
|
15
|
+
this.loader = e, this.registry = t, this.toolRegistry = n, this.orchestrator = r;
|
|
12
16
|
}
|
|
13
17
|
async onModuleInit() {
|
|
14
|
-
await this.loader.load(
|
|
18
|
+
await this.loader.load({ skipUnavailable: !0 });
|
|
19
|
+
try {
|
|
20
|
+
this.registry.registerAll(this.toolRegistry);
|
|
21
|
+
} catch (e) {
|
|
22
|
+
try {
|
|
23
|
+
await this.loader.closeAll();
|
|
24
|
+
} catch (t) {
|
|
25
|
+
throw AggregateError([e, t], "[ai] MCP registration and cleanup failed", { cause: e });
|
|
26
|
+
}
|
|
27
|
+
throw e;
|
|
28
|
+
}
|
|
15
29
|
}
|
|
16
30
|
async onModuleDestroy() {
|
|
17
|
-
|
|
31
|
+
let e = [];
|
|
32
|
+
try {
|
|
33
|
+
await this.orchestrator.close();
|
|
34
|
+
} catch (t) {
|
|
35
|
+
e.push(t);
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
await this.loader.closeAll();
|
|
39
|
+
} catch (t) {
|
|
40
|
+
e.push(t);
|
|
41
|
+
}
|
|
42
|
+
if (e.length === 1) throw e[0];
|
|
43
|
+
if (e.length > 1) throw AggregateError(e, "[ai] AI module resources failed to close");
|
|
18
44
|
}
|
|
19
45
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
46
|
+
g = l([
|
|
47
|
+
c({
|
|
48
|
+
imports: [r, i],
|
|
49
|
+
providers: [{
|
|
50
|
+
provide: o,
|
|
51
|
+
inject: [e],
|
|
52
|
+
useFactory: (e) => new o(e)
|
|
53
|
+
}, {
|
|
54
|
+
provide: a,
|
|
55
|
+
inject: [o],
|
|
56
|
+
useFactory: (e) => new a(e)
|
|
57
|
+
}],
|
|
58
|
+
exports: [o, a]
|
|
59
|
+
}),
|
|
60
|
+
d(2, s(n)),
|
|
61
|
+
d(3, s(t)),
|
|
62
|
+
u("design:paramtypes", [
|
|
63
|
+
typeof (f = o !== void 0 && o) == "function" ? f : Object,
|
|
64
|
+
typeof (p = a !== void 0 && a) == "function" ? p : Object,
|
|
65
|
+
typeof (m = typeof Pick < "u" && Pick) == "function" ? m : Object,
|
|
66
|
+
typeof (h = typeof Pick < "u" && Pick) == "function" ? h : Object
|
|
67
|
+
])
|
|
68
|
+
], g);
|
|
29
69
|
//#endregion
|
|
30
|
-
export {
|
|
70
|
+
export { g as McpModule };
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import { THREAD_STATE_STORE as e } from "../store/store.interface.js";
|
|
2
|
-
import { Inject as t, Injectable as n } from "@nestjs/common";
|
|
3
|
-
import r from "@oxc-project/runtime/helpers/decorateMetadata";
|
|
4
|
-
import i from "@oxc-project/runtime/helpers/decorate";
|
|
5
|
-
import a from "@oxc-project/runtime/helpers/decorateParam";
|
|
6
1
|
//#region app/ai/memory/checkpoint.service.ts
|
|
7
|
-
var
|
|
2
|
+
var e = 1, t = class {
|
|
8
3
|
constructor(e) {
|
|
9
4
|
this.store = e;
|
|
10
5
|
}
|
|
@@ -30,18 +25,18 @@ var o = 1, s = class {
|
|
|
30
25
|
return this.store.commitThreadMigration(e.threadId, t, n, r, e);
|
|
31
26
|
}
|
|
32
27
|
async save(e) {
|
|
33
|
-
let t =
|
|
28
|
+
let t = n(e);
|
|
34
29
|
if (!await this.compareAndSet(t, e.revision ?? 0)) throw Error(`[ai] checkpoint revision conflict for ${e.threadId}`);
|
|
35
30
|
}
|
|
36
|
-
createInitialCheckpoint(
|
|
31
|
+
createInitialCheckpoint(t, n, r) {
|
|
37
32
|
return {
|
|
38
|
-
threadId:
|
|
39
|
-
schemaVersion:
|
|
40
|
-
agentId:
|
|
33
|
+
threadId: t,
|
|
34
|
+
schemaVersion: e,
|
|
35
|
+
agentId: n,
|
|
41
36
|
pinnedContext: {
|
|
42
|
-
initialGoal:
|
|
37
|
+
initialGoal: r,
|
|
43
38
|
hardConstraints: [],
|
|
44
|
-
latestUserDirection:
|
|
39
|
+
latestUserDirection: r
|
|
45
40
|
},
|
|
46
41
|
rollingSummary: {
|
|
47
42
|
goal: null,
|
|
@@ -57,22 +52,17 @@ var o = 1, s = class {
|
|
|
57
52
|
};
|
|
58
53
|
}
|
|
59
54
|
};
|
|
60
|
-
|
|
61
|
-
n(),
|
|
62
|
-
a(0, t(e)),
|
|
63
|
-
r("design:paramtypes", [Object])
|
|
64
|
-
], s);
|
|
65
|
-
function c(e) {
|
|
55
|
+
function n(t) {
|
|
66
56
|
return {
|
|
67
|
-
...
|
|
68
|
-
schemaVersion:
|
|
69
|
-
agentId:
|
|
70
|
-
pinnedContext:
|
|
57
|
+
...t,
|
|
58
|
+
schemaVersion: t.schemaVersion ?? e,
|
|
59
|
+
agentId: t.agentId ?? "",
|
|
60
|
+
pinnedContext: t.pinnedContext ?? {
|
|
71
61
|
initialGoal: "",
|
|
72
62
|
hardConstraints: [],
|
|
73
63
|
latestUserDirection: ""
|
|
74
64
|
},
|
|
75
|
-
rollingSummary:
|
|
65
|
+
rollingSummary: t.rollingSummary ?? {
|
|
76
66
|
goal: null,
|
|
77
67
|
constraints: [],
|
|
78
68
|
facts: [],
|
|
@@ -80,10 +70,10 @@ function c(e) {
|
|
|
80
70
|
progress: [],
|
|
81
71
|
openWork: []
|
|
82
72
|
},
|
|
83
|
-
summarizedThroughSeq:
|
|
84
|
-
revision:
|
|
85
|
-
updatedAt:
|
|
73
|
+
summarizedThroughSeq: t.summarizedThroughSeq ?? 0,
|
|
74
|
+
revision: t.revision ?? 0,
|
|
75
|
+
updatedAt: t.updatedAt ?? Date.now()
|
|
86
76
|
};
|
|
87
77
|
}
|
|
88
78
|
//#endregion
|
|
89
|
-
export {
|
|
79
|
+
export { t as CheckpointService };
|
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import i from "
|
|
1
|
+
import { AiConfigService as e } from "../ai-config.service.js";
|
|
2
|
+
import { provideAiService as t } from "../nest-service-provider.js";
|
|
3
|
+
import { CheckpointService as n } from "./checkpoint.service.js";
|
|
4
|
+
import { THREAD_STATE_STORE as r } from "../store/store.interface.js";
|
|
5
|
+
import { StoreModule as i } from "../store/store.module.js";
|
|
6
|
+
import { ThreadService as a } from "./thread.service.js";
|
|
7
|
+
import { Module as o } from "@nestjs/common";
|
|
8
|
+
import s from "@oxc-project/runtime/helpers/decorate";
|
|
6
9
|
//#region app/ai/memory/memory.module.ts
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
imports: [
|
|
10
|
-
providers: [t, e],
|
|
11
|
-
exports: [
|
|
12
|
-
})],
|
|
10
|
+
var c = class {};
|
|
11
|
+
c = s([o({
|
|
12
|
+
imports: [i],
|
|
13
|
+
providers: [t(a, e), t(n, r)],
|
|
14
|
+
exports: [a, n]
|
|
15
|
+
})], c);
|
|
13
16
|
//#endregion
|
|
14
|
-
export {
|
|
17
|
+
export { c as MemoryModule };
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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";
|
|
6
|
-
import { randomUUID as a } from "crypto";
|
|
1
|
+
import { resolveMemoryMaxTurns as e } from "./internal/load-memory-config.js";
|
|
2
|
+
import { randomUUID as t } from "crypto";
|
|
7
3
|
//#region app/ai/memory/thread.service.ts
|
|
8
|
-
var
|
|
4
|
+
var n = class {
|
|
9
5
|
constructor(e) {
|
|
10
6
|
this.configService = e;
|
|
11
7
|
}
|
|
12
8
|
createThread() {
|
|
13
|
-
return
|
|
9
|
+
return t();
|
|
14
10
|
}
|
|
15
11
|
ensureThread(e) {
|
|
16
12
|
let t = typeof e == "string" ? e.trim() : "";
|
|
@@ -23,7 +19,7 @@ var o, s = class {
|
|
|
23
19
|
})) : [];
|
|
24
20
|
}
|
|
25
21
|
selectRecentCompleteTurns(e, t = {}) {
|
|
26
|
-
return
|
|
22
|
+
return r(e, t);
|
|
27
23
|
}
|
|
28
24
|
truncate(e, t) {
|
|
29
25
|
let n = this.resolveLimit(t);
|
|
@@ -46,35 +42,34 @@ var o, s = class {
|
|
|
46
42
|
updatedAt: Date.now()
|
|
47
43
|
};
|
|
48
44
|
}
|
|
49
|
-
resolveLimit(
|
|
50
|
-
return typeof
|
|
45
|
+
resolveLimit(t) {
|
|
46
|
+
return typeof t == "number" && Number.isFinite(t) && t > 0 ? Math.floor(t) : e(this.configService);
|
|
51
47
|
}
|
|
52
48
|
};
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
let n = [...e].sort((e, t) => e.seq - t.seq), r = t.maxTokens, i = [];
|
|
49
|
+
async function r(e, t = {}) {
|
|
50
|
+
let n = [...e].sort((e, t) => e.seq - t.seq), r = t.maxTokens, a = [];
|
|
56
51
|
for (let e = n.length - 1; e > 0;) {
|
|
57
|
-
let
|
|
58
|
-
if (!
|
|
59
|
-
if (
|
|
52
|
+
let o = n[e], s = n[e - 1];
|
|
53
|
+
if (!o || !s) break;
|
|
54
|
+
if (o.role !== "assistant" || s.role !== "user" || o.seq !== s.seq + 1) {
|
|
60
55
|
--e;
|
|
61
56
|
continue;
|
|
62
57
|
}
|
|
63
|
-
let
|
|
58
|
+
let c = [
|
|
59
|
+
s,
|
|
64
60
|
o,
|
|
65
|
-
a
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (r !== void 0 && c > r) {
|
|
61
|
+
...a
|
|
62
|
+
], l = t.countTokens ? await t.countTokens(c) : i(c);
|
|
63
|
+
if (r !== void 0 && l > r) {
|
|
69
64
|
e -= 2;
|
|
70
65
|
continue;
|
|
71
66
|
}
|
|
72
|
-
|
|
67
|
+
a.unshift(s, o), e -= 2;
|
|
73
68
|
}
|
|
74
|
-
return
|
|
69
|
+
return a;
|
|
75
70
|
}
|
|
76
|
-
function
|
|
71
|
+
function i(e) {
|
|
77
72
|
return e.reduce((e, t) => e + Math.max(1, Math.ceil(Buffer.byteLength(t.content, "utf8") / 4)), 0);
|
|
78
73
|
}
|
|
79
74
|
//#endregion
|
|
80
|
-
export {
|
|
75
|
+
export { n as ThreadService, r as selectRecentCompleteTurns };
|