@gt-fe/eap-runtime 0.0.8

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 (326) hide show
  1. package/README.md +323 -0
  2. package/dist/api/handlers/index.d.ts +3 -0
  3. package/dist/api/handlers/index.js +4 -0
  4. package/dist/api/handlers/invoke.handler.d.ts +77 -0
  5. package/dist/api/handlers/invoke.handler.js +411 -0
  6. package/dist/api/handlers/messages.handler.d.ts +53 -0
  7. package/dist/api/handlers/messages.handler.js +80 -0
  8. package/dist/api/handlers/stream.handler.d.ts +92 -0
  9. package/dist/api/handlers/stream.handler.js +432 -0
  10. package/dist/api/index.d.ts +3 -0
  11. package/dist/api/index.js +4 -0
  12. package/dist/api/middleware/auth.middleware.d.ts +96 -0
  13. package/dist/api/middleware/auth.middleware.js +158 -0
  14. package/dist/api/middleware/index.d.ts +1 -0
  15. package/dist/api/middleware/index.js +2 -0
  16. package/dist/api/routes/agent.routes.d.ts +44 -0
  17. package/dist/api/routes/agent.routes.js +204 -0
  18. package/dist/api/routes/index.d.ts +3 -0
  19. package/dist/api/routes/index.js +4 -0
  20. package/dist/api/routes/session.routes.d.ts +82 -0
  21. package/dist/api/routes/session.routes.js +169 -0
  22. package/dist/api/routes/task.routes.d.ts +75 -0
  23. package/dist/api/routes/task.routes.js +108 -0
  24. package/dist/checkpoint/checkpoint-serializer.d.ts +58 -0
  25. package/dist/checkpoint/checkpoint-serializer.js +81 -0
  26. package/dist/checkpoint/composite-checkpoint-saver.d.ts +42 -0
  27. package/dist/checkpoint/composite-checkpoint-saver.js +118 -0
  28. package/dist/checkpoint/contracts/checkpoint-saver.contract.d.ts +65 -0
  29. package/dist/checkpoint/contracts/checkpoint-saver.contract.js +12 -0
  30. package/dist/checkpoint/contracts/index.d.ts +1 -0
  31. package/dist/checkpoint/contracts/index.js +1 -0
  32. package/dist/checkpoint/file-checkpoint-saver.d.ts +19 -0
  33. package/dist/checkpoint/file-checkpoint-saver.js +98 -0
  34. package/dist/checkpoint/hybrid-checkpoint-saver.d.ts +130 -0
  35. package/dist/checkpoint/hybrid-checkpoint-saver.js +211 -0
  36. package/dist/checkpoint/in-memory-checkpoint-saver.d.ts +14 -0
  37. package/dist/checkpoint/in-memory-checkpoint-saver.js +46 -0
  38. package/dist/checkpoint/index.d.ts +16 -0
  39. package/dist/checkpoint/index.js +13 -0
  40. package/dist/checkpoint/mongo-checkpoint-saver.d.ts +38 -0
  41. package/dist/checkpoint/mongo-checkpoint-saver.js +56 -0
  42. package/dist/checkpoint/pg-checkpoint-saver.d.ts +59 -0
  43. package/dist/checkpoint/pg-checkpoint-saver.js +140 -0
  44. package/dist/checkpoint/redis-checkpoint-saver.d.ts +68 -0
  45. package/dist/checkpoint/redis-checkpoint-saver.js +173 -0
  46. package/dist/checkpoint/restore-checkpoint.d.ts +33 -0
  47. package/dist/checkpoint/restore-checkpoint.js +33 -0
  48. package/dist/common/agent-code.d.ts +10 -0
  49. package/dist/common/agent-code.js +12 -0
  50. package/dist/common/concurrency.d.ts +79 -0
  51. package/dist/common/concurrency.js +121 -0
  52. package/dist/common/health.d.ts +40 -0
  53. package/dist/common/health.js +37 -0
  54. package/dist/common/index.d.ts +5 -0
  55. package/dist/common/index.js +5 -0
  56. package/dist/common/logger.d.ts +34 -0
  57. package/dist/common/logger.js +38 -0
  58. package/dist/common/queue-consumer.d.ts +125 -0
  59. package/dist/common/queue-consumer.js +159 -0
  60. package/dist/common/trace-id.d.ts +2 -0
  61. package/dist/common/trace-id.js +8 -0
  62. package/dist/common/types.d.ts +104 -0
  63. package/dist/common/types.js +14 -0
  64. package/dist/contracts/index.d.ts +11 -0
  65. package/dist/contracts/index.js +10 -0
  66. package/dist/contracts/permission-checker.d.ts +10 -0
  67. package/dist/contracts/permission-checker.js +4 -0
  68. package/dist/contracts/trace-collector.d.ts +211 -0
  69. package/dist/contracts/trace-collector.js +13 -0
  70. package/dist/governance/governance-client.d.ts +38 -0
  71. package/dist/governance/governance-client.js +95 -0
  72. package/dist/governance/index.d.ts +7 -0
  73. package/dist/governance/index.js +5 -0
  74. package/dist/governance/permission-guard.d.ts +19 -0
  75. package/dist/governance/permission-guard.js +59 -0
  76. package/dist/graph/adapters/index.d.ts +3 -0
  77. package/dist/graph/adapters/index.js +3 -0
  78. package/dist/graph/adapters/langgraph-checkpointer.d.ts +40 -0
  79. package/dist/graph/adapters/langgraph-checkpointer.js +211 -0
  80. package/dist/graph/adapters/langgraph.adapter.d.ts +190 -0
  81. package/dist/graph/adapters/langgraph.adapter.js +1303 -0
  82. package/dist/graph/adapters/subgraph-compiler.d.ts +39 -0
  83. package/dist/graph/adapters/subgraph-compiler.js +248 -0
  84. package/dist/graph/condition-evaluator.d.ts +57 -0
  85. package/dist/graph/condition-evaluator.js +162 -0
  86. package/dist/graph/contracts/executable-graph.d.ts +340 -0
  87. package/dist/graph/contracts/executable-graph.js +10 -0
  88. package/dist/graph/contracts/index.d.ts +2 -0
  89. package/dist/graph/contracts/index.js +2 -0
  90. package/dist/graph/contracts/state-graph.contract.d.ts +76 -0
  91. package/dist/graph/contracts/state-graph.contract.js +11 -0
  92. package/dist/graph/hitl/hitl-handler.d.ts +199 -0
  93. package/dist/graph/hitl/hitl-handler.js +480 -0
  94. package/dist/graph/hitl/index.d.ts +1 -0
  95. package/dist/graph/hitl/index.js +1 -0
  96. package/dist/graph/index.d.ts +7 -0
  97. package/dist/graph/index.js +7 -0
  98. package/dist/graph/nodes/index.d.ts +2 -0
  99. package/dist/graph/nodes/index.js +2 -0
  100. package/dist/graph/nodes/llm-node.d.ts +182 -0
  101. package/dist/graph/nodes/llm-node.js +281 -0
  102. package/dist/graph/nodes/skill-bind-node.d.ts +32 -0
  103. package/dist/graph/nodes/skill-bind-node.js +116 -0
  104. package/dist/graph/nodes/tool-node.d.ts +75 -0
  105. package/dist/graph/nodes/tool-node.js +324 -0
  106. package/dist/graph/resolve-graph-prompt.d.ts +5 -0
  107. package/dist/graph/resolve-graph-prompt.js +75 -0
  108. package/dist/graph/retry/budget-aware-retry.d.ts +91 -0
  109. package/dist/graph/retry/budget-aware-retry.js +126 -0
  110. package/dist/graph/retry/index.d.ts +9 -0
  111. package/dist/graph/retry/index.js +8 -0
  112. package/dist/graph/retry/node-retry.d.ts +123 -0
  113. package/dist/graph/retry/node-retry.js +235 -0
  114. package/dist/graph/skill-audit-recorder.d.ts +126 -0
  115. package/dist/graph/skill-audit-recorder.js +114 -0
  116. package/dist/index.d.ts +21 -0
  117. package/dist/index.js +32 -0
  118. package/dist/memory/compression/compression-stats.d.ts +109 -0
  119. package/dist/memory/compression/compression-stats.js +144 -0
  120. package/dist/memory/compression/compression.repository.d.ts +62 -0
  121. package/dist/memory/compression/compression.repository.js +71 -0
  122. package/dist/memory/compression/index.d.ts +10 -0
  123. package/dist/memory/compression/index.js +15 -0
  124. package/dist/memory/compression/llm-summarize.d.ts +58 -0
  125. package/dist/memory/compression/llm-summarize.js +192 -0
  126. package/dist/memory/compression/sliding-window.compression.d.ts +60 -0
  127. package/dist/memory/compression/sliding-window.compression.js +175 -0
  128. package/dist/memory/index.d.ts +4 -0
  129. package/dist/memory/index.js +7 -0
  130. package/dist/memory/long-term-memory.service.d.ts +94 -0
  131. package/dist/memory/long-term-memory.service.js +120 -0
  132. package/dist/memory/message-compression.service.d.ts +128 -0
  133. package/dist/memory/message-compression.service.js +69 -0
  134. package/dist/memory/pg-memory.repository.d.ts +44 -0
  135. package/dist/memory/pg-memory.repository.js +108 -0
  136. package/dist/memory/semantic-retrieval.service.d.ts +148 -0
  137. package/dist/memory/semantic-retrieval.service.js +238 -0
  138. package/dist/providers/echo-llm-provider.d.ts +10 -0
  139. package/dist/providers/echo-llm-provider.js +87 -0
  140. package/dist/providers/http-llm-provider.d.ts +35 -0
  141. package/dist/providers/http-llm-provider.js +404 -0
  142. package/dist/providers/index.d.ts +7 -0
  143. package/dist/providers/index.js +5 -0
  144. package/dist/providers/local-llm-provider.d.ts +27 -0
  145. package/dist/providers/local-llm-provider.js +105 -0
  146. package/dist/providers/resolve-llm-model.d.ts +13 -0
  147. package/dist/providers/resolve-llm-model.js +30 -0
  148. package/dist/providers/routing-llm-provider.d.ts +28 -0
  149. package/dist/providers/routing-llm-provider.js +79 -0
  150. package/dist/registry/agent-models.d.ts +1 -0
  151. package/dist/registry/agent-models.js +1 -0
  152. package/dist/registry/agent-registry-client.d.ts +56 -0
  153. package/dist/registry/agent-registry-client.js +36 -0
  154. package/dist/registry/definition-cache.d.ts +37 -0
  155. package/dist/registry/definition-cache.js +82 -0
  156. package/dist/registry/deployment-snapshot.d.ts +99 -0
  157. package/dist/registry/deployment-snapshot.js +542 -0
  158. package/dist/registry/graph-loader.d.ts +134 -0
  159. package/dist/registry/graph-loader.js +985 -0
  160. package/dist/registry/index.d.ts +9 -0
  161. package/dist/registry/index.js +9 -0
  162. package/dist/registry/preload-errors.d.ts +13 -0
  163. package/dist/registry/preload-errors.js +35 -0
  164. package/dist/registry/preload-flags.d.ts +22 -0
  165. package/dist/registry/preload-flags.js +44 -0
  166. package/dist/registry/skill-io-guard.d.ts +25 -0
  167. package/dist/registry/skill-io-guard.js +98 -0
  168. package/dist/registry/skill-tree.d.ts +27 -0
  169. package/dist/registry/skill-tree.js +183 -0
  170. package/dist/runtime/agent-runtime.d.ts +106 -0
  171. package/dist/runtime/agent-runtime.js +777 -0
  172. package/dist/runtime/dev-runtime.d.ts +69 -0
  173. package/dist/runtime/dev-runtime.js +199 -0
  174. package/dist/runtime/index.d.ts +4 -0
  175. package/dist/runtime/index.js +3 -0
  176. package/dist/runtime/storage-profile.d.ts +50 -0
  177. package/dist/runtime/storage-profile.js +138 -0
  178. package/dist/runtime/types.d.ts +120 -0
  179. package/dist/runtime/types.js +9 -0
  180. package/dist/server.d.ts +12 -0
  181. package/dist/server.js +161 -0
  182. package/dist/session/compression-middleware.d.ts +126 -0
  183. package/dist/session/compression-middleware.js +230 -0
  184. package/dist/session/file-message.repository.d.ts +25 -0
  185. package/dist/session/file-message.repository.js +78 -0
  186. package/dist/session/file-session.repository.d.ts +72 -0
  187. package/dist/session/file-session.repository.js +212 -0
  188. package/dist/session/index.d.ts +13 -0
  189. package/dist/session/index.js +12 -0
  190. package/dist/session/message.service.d.ts +80 -0
  191. package/dist/session/message.service.js +128 -0
  192. package/dist/session/persist-turn-messages.d.ts +145 -0
  193. package/dist/session/persist-turn-messages.js +325 -0
  194. package/dist/session/pg-message.repository.d.ts +49 -0
  195. package/dist/session/pg-message.repository.js +149 -0
  196. package/dist/session/pg-session.repository.d.ts +46 -0
  197. package/dist/session/pg-session.repository.js +117 -0
  198. package/dist/session/session-context.service.d.ts +49 -0
  199. package/dist/session/session-context.service.js +66 -0
  200. package/dist/session/session.service.d.ts +194 -0
  201. package/dist/session/session.service.js +166 -0
  202. package/dist/sse/connection-event-logger.d.ts +21 -0
  203. package/dist/sse/connection-event-logger.js +33 -0
  204. package/dist/sse/contracts/index.d.ts +1 -0
  205. package/dist/sse/contracts/index.js +1 -0
  206. package/dist/sse/contracts/sse-emitter.contract.d.ts +74 -0
  207. package/dist/sse/contracts/sse-emitter.contract.js +11 -0
  208. package/dist/sse/event-buffer.d.ts +20 -0
  209. package/dist/sse/event-buffer.js +45 -0
  210. package/dist/sse/events/code-events.d.ts +19 -0
  211. package/dist/sse/events/code-events.js +9 -0
  212. package/dist/sse/events/collaboration-events.d.ts +37 -0
  213. package/dist/sse/events/collaboration-events.js +11 -0
  214. package/dist/sse/events/connection-events.d.ts +13 -0
  215. package/dist/sse/events/connection-events.js +9 -0
  216. package/dist/sse/events/file-events.d.ts +29 -0
  217. package/dist/sse/events/file-events.js +10 -0
  218. package/dist/sse/events/hitl-events.d.ts +33 -0
  219. package/dist/sse/events/hitl-events.js +10 -0
  220. package/dist/sse/events/index.d.ts +107 -0
  221. package/dist/sse/events/index.js +96 -0
  222. package/dist/sse/events/plan-events.d.ts +38 -0
  223. package/dist/sse/events/plan-events.js +11 -0
  224. package/dist/sse/events/reasoning-events.d.ts +35 -0
  225. package/dist/sse/events/reasoning-events.js +13 -0
  226. package/dist/sse/events/response-events.d.ts +25 -0
  227. package/dist/sse/events/response-events.js +12 -0
  228. package/dist/sse/events/session-events.d.ts +43 -0
  229. package/dist/sse/events/session-events.js +12 -0
  230. package/dist/sse/events/skill-events.d.ts +48 -0
  231. package/dist/sse/events/skill-events.js +11 -0
  232. package/dist/sse/events/stats-events.d.ts +44 -0
  233. package/dist/sse/events/stats-events.js +12 -0
  234. package/dist/sse/events/tool-events.d.ts +68 -0
  235. package/dist/sse/events/tool-events.js +14 -0
  236. package/dist/sse/index.d.ts +8 -0
  237. package/dist/sse/index.js +8 -0
  238. package/dist/sse/sse-connection-manager.d.ts +116 -0
  239. package/dist/sse/sse-connection-manager.js +185 -0
  240. package/dist/sse/sse-emitter.d.ts +108 -0
  241. package/dist/sse/sse-emitter.js +210 -0
  242. package/dist/sse/sse-heartbeat.d.ts +58 -0
  243. package/dist/sse/sse-heartbeat.js +76 -0
  244. package/dist/sse/trace-collector.d.ts +60 -0
  245. package/dist/sse/trace-collector.js +107 -0
  246. package/dist/task/contracts/index.d.ts +2 -0
  247. package/dist/task/contracts/index.js +1 -0
  248. package/dist/task/contracts/task-manager.contract.d.ts +160 -0
  249. package/dist/task/contracts/task-manager.contract.js +10 -0
  250. package/dist/task/index.d.ts +7 -0
  251. package/dist/task/index.js +5 -0
  252. package/dist/task/pg-task.repository.d.ts +47 -0
  253. package/dist/task/pg-task.repository.js +131 -0
  254. package/dist/task/task-progress-tracker.d.ts +67 -0
  255. package/dist/task/task-progress-tracker.js +80 -0
  256. package/dist/task/task-timeout.d.ts +70 -0
  257. package/dist/task/task-timeout.js +116 -0
  258. package/dist/task/task.service.d.ts +84 -0
  259. package/dist/task/task.service.js +233 -0
  260. package/dist/token/compression-budget-integration.d.ts +145 -0
  261. package/dist/token/compression-budget-integration.js +185 -0
  262. package/dist/token/context-window-budget.d.ts +113 -0
  263. package/dist/token/context-window-budget.js +134 -0
  264. package/dist/token/contracts/index.d.ts +1 -0
  265. package/dist/token/contracts/index.js +1 -0
  266. package/dist/token/contracts/token-budget.contract.d.ts +77 -0
  267. package/dist/token/contracts/token-budget.contract.js +11 -0
  268. package/dist/token/index.d.ts +12 -0
  269. package/dist/token/index.js +10 -0
  270. package/dist/token/pg-token-budget.repository.d.ts +39 -0
  271. package/dist/token/pg-token-budget.repository.js +116 -0
  272. package/dist/token/session-budget-checker.d.ts +54 -0
  273. package/dist/token/session-budget-checker.js +72 -0
  274. package/dist/token/token-budget-guard.d.ts +66 -0
  275. package/dist/token/token-budget-guard.js +97 -0
  276. package/dist/token/token-budget.service.d.ts +86 -0
  277. package/dist/token/token-budget.service.js +130 -0
  278. package/dist/token/token-detail-mode.d.ts +73 -0
  279. package/dist/token/token-detail-mode.js +107 -0
  280. package/dist/token/token-estimator.d.ts +80 -0
  281. package/dist/token/token-estimator.js +134 -0
  282. package/dist/token/token-stats.service.d.ts +88 -0
  283. package/dist/token/token-stats.service.js +94 -0
  284. package/dist/tool/create-tool-executor.d.ts +33 -0
  285. package/dist/tool/create-tool-executor.js +60 -0
  286. package/dist/tool/dev-http-executor.d.ts +18 -0
  287. package/dist/tool/dev-http-executor.js +96 -0
  288. package/dist/tool/dev-mcp-executor.d.ts +29 -0
  289. package/dist/tool/dev-mcp-executor.js +84 -0
  290. package/dist/tool/dev-tool-executor.d.ts +23 -0
  291. package/dist/tool/dev-tool-executor.js +55 -0
  292. package/dist/tool/file-artifact.d.ts +11 -0
  293. package/dist/tool/file-artifact.js +90 -0
  294. package/dist/tool/http-tool-executor.d.ts +17 -0
  295. package/dist/tool/http-tool-executor.js +158 -0
  296. package/dist/tool/index.d.ts +18 -0
  297. package/dist/tool/index.js +17 -0
  298. package/dist/tool/loaded-tool-definition.d.ts +35 -0
  299. package/dist/tool/loaded-tool-definition.js +9 -0
  300. package/dist/tool/local-mcp-client.d.ts +23 -0
  301. package/dist/tool/local-mcp-client.js +225 -0
  302. package/dist/tool/local-tool-executor.d.ts +37 -0
  303. package/dist/tool/local-tool-executor.js +249 -0
  304. package/dist/tool/mcp-tool-executor.d.ts +23 -0
  305. package/dist/tool/mcp-tool-executor.js +160 -0
  306. package/dist/tool/mock-tool-executor.d.ts +28 -0
  307. package/dist/tool/mock-tool-executor.js +65 -0
  308. package/dist/tool/system-prompt-builder.d.ts +114 -0
  309. package/dist/tool/system-prompt-builder.js +213 -0
  310. package/dist/tool/tool-confirmation.d.ts +29 -0
  311. package/dist/tool/tool-confirmation.js +81 -0
  312. package/dist/tool/tool-event-emitter.d.ts +58 -0
  313. package/dist/tool/tool-event-emitter.js +154 -0
  314. package/dist/tool/tool-execution-router.d.ts +25 -0
  315. package/dist/tool/tool-execution-router.js +50 -0
  316. package/dist/tool/tool-executor.interface.d.ts +85 -0
  317. package/dist/tool/tool-executor.interface.js +7 -0
  318. package/dist/tool/tool-orchestrator.d.ts +22 -0
  319. package/dist/tool/tool-orchestrator.js +104 -0
  320. package/dist/tool/tool-result-injector.d.ts +64 -0
  321. package/dist/tool/tool-result-injector.js +65 -0
  322. package/dist/utils/format-error.d.ts +4 -0
  323. package/dist/utils/format-error.js +4 -0
  324. package/dist/utils/http-error.d.ts +11 -0
  325. package/dist/utils/http-error.js +24 -0
  326. package/package.json +56 -0
@@ -0,0 +1,37 @@
1
+ /**
2
+ * LocalToolExecutor — 桌面本地 Code / MCP Tool 执行
3
+ *
4
+ * 优先 ILocalToolInstallStore;若无安装记录但 request.execution 带
5
+ * localPreferred / skill-script(或可解析的 code bundlePath+handler),则直接本机执行。
6
+ */
7
+ import type { ILocalToolInstallStore } from '@gt-fe/eap-contracts';
8
+ import type { IToolExecutor, ToolCallRequest, ToolCallResult } from './tool-executor.interface.js';
9
+ import { type ILocalMcpClient } from './local-mcp-client.js';
10
+ export interface LocalToolExecutorOptions {
11
+ installStore: ILocalToolInstallStore;
12
+ mcpClient?: ILocalMcpClient;
13
+ defaultHandler?: string;
14
+ timeoutMs?: number;
15
+ }
16
+ interface CodeExecutionSpec {
17
+ handlerPath: string;
18
+ runtime?: string;
19
+ args?: string[];
20
+ timeoutMs?: number;
21
+ }
22
+ /** 是否为应本机执行的 Skill script / 显式 localPreferred code execution */
23
+ export declare function isLocalPreferredExecution(raw: unknown): boolean;
24
+ /**
25
+ * 从 ToolCallRequest.execution 解析本机 code 执行规格(Skill scripts 等)。
26
+ */
27
+ export declare function resolveCodeExecutionFromRequest(request: ToolCallRequest): CodeExecutionSpec | null;
28
+ export declare class LocalToolExecutor implements IToolExecutor {
29
+ private readonly options;
30
+ private readonly mcpClient;
31
+ constructor(options: LocalToolExecutorOptions);
32
+ execute(request: ToolCallRequest): Promise<ToolCallResult>;
33
+ private executeCodeSpec;
34
+ private executeCode;
35
+ private executeMcp;
36
+ }
37
+ export {};
@@ -0,0 +1,249 @@
1
+ /**
2
+ * LocalToolExecutor — 桌面本地 Code / MCP Tool 执行
3
+ *
4
+ * 优先 ILocalToolInstallStore;若无安装记录但 request.execution 带
5
+ * localPreferred / skill-script(或可解析的 code bundlePath+handler),则直接本机执行。
6
+ */
7
+ import { spawn } from 'node:child_process';
8
+ import { existsSync } from 'node:fs';
9
+ import path from 'node:path';
10
+ import { resolveReadyInstallByToolName, resolveMcpExecutionFromInstall, resolveCodeHandlerFromInstall, } from '@gt-fe/eap-contracts';
11
+ import { fileArtifactFromToolOutput, fileBasesFromEnv } from './file-artifact.js';
12
+ import { LocalMcpClient } from './local-mcp-client.js';
13
+ /**
14
+ * 根据 execution.runtime 解析执行命令:
15
+ * - node(默认)→ process.execPath + [handlerPath]
16
+ * - python → python3 + [handlerPath]
17
+ * - executable → handlerPath 本身为可执行文件 + args
18
+ */
19
+ function resolveCommand(handlerPath, execution) {
20
+ const runtime = execution?.runtime;
21
+ switch (runtime) {
22
+ case 'python':
23
+ return { cmd: 'python3', args: [handlerPath, ...(execution?.args ?? [])] };
24
+ case 'executable':
25
+ return { cmd: handlerPath, args: execution?.args ?? [] };
26
+ case 'node':
27
+ default:
28
+ return { cmd: process.execPath, args: [handlerPath, ...(execution?.args ?? [])] };
29
+ }
30
+ }
31
+ function formatCodeLaunchError(err, spec) {
32
+ const code = err && typeof err === 'object' && 'code' in err
33
+ ? String(err.code)
34
+ : '';
35
+ const runtime = spec.runtime === 'python' || spec.runtime === 'executable' ? spec.runtime : 'node';
36
+ if (code === 'ENOENT') {
37
+ if (runtime === 'python') {
38
+ return new Error(`找不到 python3(tools[].runtime=python)。请安装 Python 3,并保证 python3 在 PATH 中。handler=${spec.handlerPath}`);
39
+ }
40
+ if (runtime === 'executable') {
41
+ return new Error(`找不到可执行文件 ${spec.cmd}(tools[].runtime=executable)。请确认文件存在、已 chmod +x,且匹配当前操作系统/架构。`);
42
+ }
43
+ return new Error(`找不到 Node 或 handler 文件:${spec.handlerPath}`);
44
+ }
45
+ if (code === 'EACCES') {
46
+ return new Error(`没有执行权限:${spec.cmd}。请 chmod +x 后重试。`);
47
+ }
48
+ return new Error(err instanceof Error ? err.message : String(err));
49
+ }
50
+ function runHandler(handlerPath, input, timeoutMs, execution) {
51
+ if (!existsSync(handlerPath)) {
52
+ return Promise.reject(new Error(`找不到 handler 文件:${handlerPath}。请检查 toolset.manifest.json 的 tools[].handler 与工具目录。`));
53
+ }
54
+ const { cmd, args } = resolveCommand(handlerPath, execution);
55
+ return new Promise((resolve, reject) => {
56
+ const child = spawn(cmd, args, { stdio: ['pipe', 'pipe', 'pipe'] });
57
+ let stdout = '';
58
+ let stderr = '';
59
+ let settled = false;
60
+ const finish = (fn) => {
61
+ if (settled)
62
+ return;
63
+ settled = true;
64
+ clearTimeout(timer);
65
+ fn();
66
+ };
67
+ const timer = setTimeout(() => {
68
+ child.kill('SIGKILL');
69
+ finish(() => reject(new Error(`Local tool timeout after ${timeoutMs}ms`)));
70
+ }, timeoutMs);
71
+ child.stdout.on('data', (d) => { stdout += d.toString(); });
72
+ child.stderr.on('data', (d) => { stderr += d.toString(); });
73
+ child.on('error', (err) => {
74
+ finish(() => reject(formatCodeLaunchError(err, {
75
+ runtime: execution?.runtime,
76
+ cmd,
77
+ handlerPath,
78
+ })));
79
+ });
80
+ child.on('close', (code) => {
81
+ if (code === 0) {
82
+ finish(() => resolve(stdout.trim()));
83
+ return;
84
+ }
85
+ finish(() => reject(new Error(stderr.trim() || `code 工具退出码 ${code}`)));
86
+ });
87
+ child.stdin.write(JSON.stringify(input ?? {}));
88
+ child.stdin.end();
89
+ });
90
+ }
91
+ /** 是否为应本机执行的 Skill script / 显式 localPreferred code execution */
92
+ export function isLocalPreferredExecution(raw) {
93
+ if (!raw || typeof raw !== 'object')
94
+ return false;
95
+ const e = raw;
96
+ if (e.protocol === 'mcp')
97
+ return false;
98
+ if (e.localPreferred === true || e.source === 'skill-script')
99
+ return true;
100
+ return false;
101
+ }
102
+ /**
103
+ * 从 ToolCallRequest.execution 解析本机 code 执行规格(Skill scripts 等)。
104
+ */
105
+ export function resolveCodeExecutionFromRequest(request) {
106
+ const raw = request.execution;
107
+ if (!raw || typeof raw !== 'object')
108
+ return null;
109
+ const e = raw;
110
+ if (e.protocol === 'mcp')
111
+ return null;
112
+ const runtime = typeof e.runtime === 'string' ? e.runtime : undefined;
113
+ const bundlePath = typeof e.bundlePath === 'string' ? e.bundlePath : undefined;
114
+ const handler = typeof e.handler === 'string' ? e.handler : '';
115
+ const command = typeof e.command === 'string' ? e.command : undefined;
116
+ const args = Array.isArray(e.args) ? e.args.map(String) : undefined;
117
+ const timeoutMs = typeof e.timeout === 'number' && e.timeout > 0 ? e.timeout : undefined;
118
+ if (runtime === 'executable') {
119
+ const handlerPath = handler
120
+ ? (path.isAbsolute(handler) || !bundlePath
121
+ ? handler
122
+ : path.resolve(bundlePath, handler.replace(/^\.\//, '')))
123
+ : (command ?? '');
124
+ if (!handlerPath)
125
+ return null;
126
+ return { handlerPath, runtime: 'executable', args, timeoutMs };
127
+ }
128
+ if (!handler)
129
+ return null;
130
+ const handlerPath = bundlePath
131
+ ? path.resolve(bundlePath, handler.replace(/^\.\//, ''))
132
+ : path.resolve(handler);
133
+ return {
134
+ handlerPath,
135
+ runtime: runtime ?? (command === 'python3' || command === 'python' ? 'python' : 'node'),
136
+ args,
137
+ timeoutMs,
138
+ };
139
+ }
140
+ export class LocalToolExecutor {
141
+ options;
142
+ mcpClient;
143
+ constructor(options) {
144
+ this.options = options;
145
+ this.mcpClient = options.mcpClient ?? new LocalMcpClient();
146
+ }
147
+ async execute(request) {
148
+ const install = resolveReadyInstallByToolName(this.options.installStore, request.toolName);
149
+ if (install && install.installStatus === 'ready') {
150
+ const toolType = install.type ?? request.toolType ?? 'code';
151
+ if (toolType === 'mcp') {
152
+ return this.executeMcp(request, install);
153
+ }
154
+ return this.executeCode(request, install);
155
+ }
156
+ // 无本地安装:仅 Skill scripts / localPreferred 走 request.execution
157
+ if (isLocalPreferredExecution(request.execution)) {
158
+ const fromReq = resolveCodeExecutionFromRequest(request);
159
+ if (fromReq) {
160
+ return this.executeCodeSpec(request, fromReq);
161
+ }
162
+ }
163
+ return {
164
+ toolCallId: request.toolCallId,
165
+ toolName: request.toolName,
166
+ content: '',
167
+ success: false,
168
+ error: `Tool not installed locally: ${request.toolName}`,
169
+ errorCode: 'NOT_INSTALLED',
170
+ runtime: 'local',
171
+ };
172
+ }
173
+ async executeCodeSpec(request, spec) {
174
+ try {
175
+ const stdout = await runHandler(spec.handlerPath, request.arguments, spec.timeoutMs ?? this.options.timeoutMs ?? 30_000, { runtime: spec.runtime, args: spec.args });
176
+ return {
177
+ toolCallId: request.toolCallId,
178
+ toolName: request.toolName,
179
+ content: stdout,
180
+ success: true,
181
+ runtime: 'local',
182
+ file: fileArtifactFromToolOutput(stdout, fileBasesFromEnv()),
183
+ };
184
+ }
185
+ catch (error) {
186
+ const message = error instanceof Error ? error.message : String(error);
187
+ return {
188
+ toolCallId: request.toolCallId,
189
+ toolName: request.toolName,
190
+ content: '',
191
+ success: false,
192
+ error: message,
193
+ errorCode: 'EXECUTION_FAILED',
194
+ runtime: 'local',
195
+ };
196
+ }
197
+ }
198
+ async executeCode(request, install) {
199
+ const handlerFile = resolveCodeHandlerFromInstall(install)
200
+ ?? this.options.defaultHandler
201
+ ?? 'handler.js';
202
+ const handlerPath = path.resolve(install.bundlePath, handlerFile.replace(/^\.\//, ''));
203
+ const execution = install.execution;
204
+ return this.executeCodeSpec(request, {
205
+ handlerPath,
206
+ runtime: execution?.runtime,
207
+ args: execution?.args,
208
+ });
209
+ }
210
+ async executeMcp(request, install) {
211
+ const execution = resolveMcpExecutionFromInstall(install);
212
+ if (!execution?.toolName) {
213
+ return {
214
+ toolCallId: request.toolCallId,
215
+ toolName: request.toolName,
216
+ content: '',
217
+ success: false,
218
+ error: `MCP execution not configured for: ${request.toolName}`,
219
+ errorCode: 'NOT_CONFIGURED',
220
+ runtime: 'local',
221
+ };
222
+ }
223
+ try {
224
+ const { content, file } = await this.mcpClient.invoke(execution, request.arguments, {
225
+ userId: request.authContext?.userId,
226
+ });
227
+ return {
228
+ toolCallId: request.toolCallId,
229
+ toolName: request.toolName,
230
+ content,
231
+ success: true,
232
+ runtime: 'local',
233
+ file,
234
+ };
235
+ }
236
+ catch (error) {
237
+ const message = error instanceof Error ? error.message : String(error);
238
+ return {
239
+ toolCallId: request.toolCallId,
240
+ toolName: request.toolName,
241
+ content: '',
242
+ success: false,
243
+ error: message,
244
+ errorCode: 'EXECUTION_FAILED',
245
+ runtime: 'local',
246
+ };
247
+ }
248
+ }
249
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * McpToolExecutor — Runtime → Tool Gateway 正式 MCP 出站(JSON-RPC over HTTP)
3
+ *
4
+ * @see docs/contracts/tool-execution.md §2.0
5
+ */
6
+ import type { IToolExecutor, ToolCallRequest, ToolCallResult } from './tool-executor.interface.js';
7
+ export interface McpToolExecutorOptions {
8
+ baseUrl: string;
9
+ timeout?: number;
10
+ /** MCP 入口路径,默认 /api/v1/mcp */
11
+ mcpPath?: string;
12
+ }
13
+ export declare class McpToolExecutor implements IToolExecutor {
14
+ private readonly baseUrl;
15
+ private readonly timeout;
16
+ private readonly mcpUrl;
17
+ private rpcId;
18
+ private initialized;
19
+ constructor(options: McpToolExecutorOptions);
20
+ execute(request: ToolCallRequest): Promise<ToolCallResult>;
21
+ private ensureInitialized;
22
+ private postRpc;
23
+ }
@@ -0,0 +1,160 @@
1
+ /**
2
+ * McpToolExecutor — Runtime → Tool Gateway 正式 MCP 出站(JSON-RPC over HTTP)
3
+ *
4
+ * @see docs/contracts/tool-execution.md §2.0
5
+ */
6
+ function resolveAgentCode(request) {
7
+ return request.authContext.agentCode ?? request.authContext.agentId;
8
+ }
9
+ function formatContent(result) {
10
+ const text = result?.content?.[0]?.text;
11
+ if (text != null)
12
+ return text;
13
+ return JSON.stringify(result ?? {});
14
+ }
15
+ function mapMcpError(status, body) {
16
+ const eapCode = body?.error?.data?.eapCode;
17
+ const message = body?.error?.message ?? `HTTP ${status}`;
18
+ if (status === 403 || eapCode?.includes('forbidden') || eapCode?.includes('auth')) {
19
+ return { error: message, errorCode: eapCode ?? 'NO_PERMISSION', retryable: false };
20
+ }
21
+ if (status === 429) {
22
+ return { error: message, errorCode: eapCode ?? 'RATE_LIMITED', retryable: true };
23
+ }
24
+ if (status === 503) {
25
+ return { error: message, errorCode: eapCode ?? 'CIRCUIT_OPEN', retryable: true };
26
+ }
27
+ if (status === 404) {
28
+ return { error: message, errorCode: eapCode ?? 'TOOL_NOT_FOUND', retryable: false };
29
+ }
30
+ if (status === 400) {
31
+ return { error: message, errorCode: eapCode ?? 'INVALID_ARGUMENTS', retryable: false };
32
+ }
33
+ return { error: message, errorCode: eapCode ?? 'EXECUTION_FAILED', retryable: false };
34
+ }
35
+ export class McpToolExecutor {
36
+ baseUrl;
37
+ timeout;
38
+ mcpUrl;
39
+ rpcId = 1;
40
+ initialized = false;
41
+ constructor(options) {
42
+ this.baseUrl = options.baseUrl.replace(/\/+$/, '');
43
+ this.timeout = options.timeout ?? 30_000;
44
+ const path = options.mcpPath ?? '/api/v1/mcp';
45
+ this.mcpUrl = `${this.baseUrl}${path.startsWith('/') ? path : `/${path}`}`;
46
+ }
47
+ async execute(request) {
48
+ try {
49
+ await this.ensureInitialized(request);
50
+ const agentCode = resolveAgentCode(request);
51
+ const correlationId = request.correlationId ?? request.toolCallId;
52
+ const id = this.rpcId++;
53
+ const response = await this.postRpc({
54
+ jsonrpc: '2.0',
55
+ id,
56
+ method: 'tools/call',
57
+ params: {
58
+ name: request.toolName,
59
+ arguments: request.arguments,
60
+ },
61
+ }, request, agentCode, correlationId);
62
+ if (!response.ok) {
63
+ let body = null;
64
+ try {
65
+ body = (await response.json());
66
+ }
67
+ catch {
68
+ body = null;
69
+ }
70
+ const mapped = mapMcpError(response.status, body);
71
+ return {
72
+ toolCallId: request.toolCallId,
73
+ toolName: request.toolName,
74
+ content: '',
75
+ success: false,
76
+ runtime: 'server',
77
+ ...mapped,
78
+ };
79
+ }
80
+ const body = (await response.json());
81
+ if (body.error) {
82
+ const mapped = mapMcpError(500, body);
83
+ return {
84
+ toolCallId: request.toolCallId,
85
+ toolName: request.toolName,
86
+ content: '',
87
+ success: false,
88
+ runtime: 'server',
89
+ ...mapped,
90
+ };
91
+ }
92
+ return {
93
+ toolCallId: request.toolCallId,
94
+ toolName: request.toolName,
95
+ content: formatContent(body.result),
96
+ success: true,
97
+ runtime: 'server',
98
+ };
99
+ }
100
+ catch (err) {
101
+ const message = err instanceof Error ? err.message : String(err);
102
+ return {
103
+ toolCallId: request.toolCallId,
104
+ toolName: request.toolName,
105
+ content: '',
106
+ success: false,
107
+ error: message,
108
+ errorCode: 'EXECUTION_FAILED',
109
+ retryable: false,
110
+ runtime: 'server',
111
+ };
112
+ }
113
+ }
114
+ async ensureInitialized(request) {
115
+ if (this.initialized)
116
+ return;
117
+ const agentCode = resolveAgentCode(request);
118
+ const correlationId = request.correlationId ?? request.toolCallId;
119
+ const id = this.rpcId++;
120
+ const response = await this.postRpc({
121
+ jsonrpc: '2.0',
122
+ id,
123
+ method: 'initialize',
124
+ params: {
125
+ protocolVersion: '2024-11-05',
126
+ capabilities: {},
127
+ clientInfo: { name: 'eap-runtime', version: '0.1.0' },
128
+ },
129
+ }, request, agentCode, correlationId);
130
+ if (!response.ok) {
131
+ throw new Error(`MCP initialize failed: HTTP ${response.status}`);
132
+ }
133
+ this.initialized = true;
134
+ }
135
+ async postRpc(payload, request, agentCode, correlationId) {
136
+ const controller = new AbortController();
137
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
138
+ try {
139
+ return await fetch(this.mcpUrl, {
140
+ method: 'POST',
141
+ headers: {
142
+ 'Content-Type': 'application/json',
143
+ Authorization: `Bearer ${request.authContext.delegationToken}`,
144
+ 'X-Agent-Code': agentCode,
145
+ 'X-Agent-Id': agentCode,
146
+ 'X-User-Id': request.authContext.userId,
147
+ // 上游 mcp-data-service 认 `userId`;Gateway 侧亦保留 X-User-Id
148
+ userId: request.authContext.userId,
149
+ 'X-Correlation-Id': correlationId,
150
+ ...(request.taskId ? { 'X-Task-Id': request.taskId } : {}),
151
+ },
152
+ body: JSON.stringify(payload),
153
+ signal: controller.signal,
154
+ });
155
+ }
156
+ finally {
157
+ clearTimeout(timeoutId);
158
+ }
159
+ }
160
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * MockToolExecutor — 本地开发模式的模拟 Tool 执行器
3
+ *
4
+ * 定位:`eap dev --tool-mode mock` 场景下替代真实 Gateway/Local 执行器,
5
+ * 让 Agent 开发者在无 foundation-service、无真实 Tool 依赖的前提下跑通 Graph。
6
+ *
7
+ * 响应查找顺序:
8
+ * 1. `${toolsDir}/<toolName>/mock.json`(用户自定义 Mock 响应)
9
+ * 2. `${toolsDir}/<toolName>/tool.manifest.json` 内嵌 `mockResponse` 字段
10
+ * 3. 兜底 echo:`{ toolName, arguments, note: "mock" }`
11
+ *
12
+ * 使用示例:
13
+ * const executor = new MockToolExecutor({ toolsDir: './tools' });
14
+ */
15
+ import type { IToolExecutor, ToolCallRequest, ToolCallResult } from './tool-executor.interface.js';
16
+ export interface MockToolExecutorOptions {
17
+ /** 本地 tools 根目录,默认 `./tools` 或读 `EAP_LOCAL_TOOLS_DIR` */
18
+ toolsDir?: string;
19
+ /** Mock 响应可自定义 delay,用于验证 SSE/流式表现 */
20
+ delayMs?: number;
21
+ }
22
+ export declare class MockToolExecutor implements IToolExecutor {
23
+ private readonly toolsDir;
24
+ private readonly delayMs;
25
+ constructor(options?: MockToolExecutorOptions);
26
+ execute(request: ToolCallRequest): Promise<ToolCallResult>;
27
+ private resolveMockResponse;
28
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * MockToolExecutor — 本地开发模式的模拟 Tool 执行器
3
+ *
4
+ * 定位:`eap dev --tool-mode mock` 场景下替代真实 Gateway/Local 执行器,
5
+ * 让 Agent 开发者在无 foundation-service、无真实 Tool 依赖的前提下跑通 Graph。
6
+ *
7
+ * 响应查找顺序:
8
+ * 1. `${toolsDir}/<toolName>/mock.json`(用户自定义 Mock 响应)
9
+ * 2. `${toolsDir}/<toolName>/tool.manifest.json` 内嵌 `mockResponse` 字段
10
+ * 3. 兜底 echo:`{ toolName, arguments, note: "mock" }`
11
+ *
12
+ * 使用示例:
13
+ * const executor = new MockToolExecutor({ toolsDir: './tools' });
14
+ */
15
+ import { readFile } from 'node:fs/promises';
16
+ import path from 'node:path';
17
+ async function readJsonFile(filePath) {
18
+ try {
19
+ const raw = await readFile(filePath, 'utf-8');
20
+ return JSON.parse(raw);
21
+ }
22
+ catch {
23
+ return undefined;
24
+ }
25
+ }
26
+ export class MockToolExecutor {
27
+ toolsDir;
28
+ delayMs;
29
+ constructor(options = {}) {
30
+ this.toolsDir =
31
+ options.toolsDir ?? process.env.EAP_LOCAL_TOOLS_DIR ?? './tools';
32
+ this.delayMs = options.delayMs ?? 0;
33
+ }
34
+ async execute(request) {
35
+ if (this.delayMs > 0) {
36
+ await new Promise((r) => setTimeout(r, this.delayMs));
37
+ }
38
+ const mockResponse = await this.resolveMockResponse(request.toolName);
39
+ const payload = mockResponse ?? {
40
+ toolName: request.toolName,
41
+ arguments: request.arguments,
42
+ note: 'mock: no explicit mockResponse found, echoing arguments',
43
+ };
44
+ return {
45
+ toolCallId: request.toolCallId,
46
+ toolName: request.toolName,
47
+ content: typeof payload === 'string' ? payload : JSON.stringify(payload),
48
+ success: true,
49
+ runtime: 'mock',
50
+ };
51
+ }
52
+ async resolveMockResponse(toolName) {
53
+ const toolDir = path.join(this.toolsDir, toolName);
54
+ // 优先级 1:独立 mock.json
55
+ const explicit = await readJsonFile(path.join(toolDir, 'mock.json'));
56
+ if (explicit !== undefined)
57
+ return explicit;
58
+ // 优先级 2:manifest 内嵌 mockResponse
59
+ const manifest = (await readJsonFile(path.join(toolDir, 'tool.manifest.json')));
60
+ if (manifest && manifest.mockResponse !== undefined) {
61
+ return manifest.mockResponse;
62
+ }
63
+ return undefined;
64
+ }
65
+ }
@@ -0,0 +1,114 @@
1
+ /**
2
+ * SystemPromptBuilder — 系统级提示词拼接(RT-5)
3
+ *
4
+ * 职责极简:代码常量 + 配置透传 + 字符串拼接。
5
+ *
6
+ * 输出结构:
7
+ * ```
8
+ * [平台规则常量] ← 代码内置,安全约束 + 行为准则(最高优先级)
9
+ * [当前时间] ← 运行时动态注入(自然周等时间规则的判定基准)
10
+ * [Agent 身份] ← agentName / agentCode
11
+ * [开发者提示词] ← Graph LLM 节点 config.systemPrompt,平台透传
12
+ * (Registry 无内嵌 Graph 的兜底路径读 agent.manifest.json prompts.system)
13
+ * ```
14
+ *
15
+ * Tools 不经过本类,走 API 的 tools 参数(见 loadedToolsToApiTools)。
16
+ *
17
+ * @see docs/status/module-status-and-backlog.md RT-5
18
+ */
19
+ import type { LoadedToolMap } from './loaded-tool-definition.js';
20
+ import type { LLMToolDefinition } from '../graph/nodes/llm-node.js';
21
+ /**
22
+
23
+ * 已装配 Skill 定义(由 GraphLoader 从预装快照加载)
24
+ * workflow / prompt 供子图按 skillId 解析与入口提示注入
25
+ */
26
+ export interface LoadedSkillInfo {
27
+ skillId: string;
28
+ name: string;
29
+ description?: string;
30
+ version?: string;
31
+ /** Skill 工作流(GraphDSL);缺省时子图节点须自带 subgraphDsl */
32
+ workflow?: import('../graph/contracts/executable-graph.js').GraphDSL;
33
+ /** 注入子图入口 LLM 系统上下文 */
34
+ prompt?: string;
35
+ toolRefs?: Array<string | {
36
+ toolId?: string;
37
+ name?: string;
38
+ version?: string;
39
+ toolset?: string;
40
+ enabledTools?: string[];
41
+ autoApprove?: string[];
42
+ }>;
43
+ inputDef?: unknown;
44
+ outputDef?: unknown;
45
+ /** Skill 包 scripts[] 物化出的虚拟 Tool(装配时并入 loadedTools) */
46
+ scriptTools?: import('./loaded-tool-definition.js').LoadedToolDefinition[];
47
+ }
48
+ /** skillId → 完整定义 */
49
+ export type LoadedSkillMap = Record<string, LoadedSkillInfo>;
50
+ export declare function toLoadedSkillMap(skills: LoadedSkillInfo[] | undefined): LoadedSkillMap | undefined;
51
+ /**
52
+ * 将各 Skill 的 scripts 虚拟 Tool 并入 loadedTools(同名不覆盖平台 Tool)。
53
+ * 装配点(invoke/stream/fork)在构造 GraphState 前调用。
54
+ */
55
+ export declare function mergeSkillScriptTools(loadedTools: LoadedToolMap | undefined, skills: LoadedSkillInfo[] | undefined): LoadedToolMap | undefined;
56
+ /**
57
+ * 按 Skill.toolRefs 收窄工具集。
58
+ * - 无 toolRefs / 空数组:不收窄(保持 Agent 全量,兼容旧 Skill)
59
+ * - string / name / toolId:精确匹配工具名
60
+ * - toolset + enabledTools:仅白名单子工具
61
+ * - toolset 无 enabledTools:匹配 toolId 前缀 `<toolset>:` 或 id 等于 toolset
62
+ * - 始终保留该 Skill 的 scriptTools
63
+ */
64
+ export declare function filterLoadedToolsForSkill(loadedTools: LoadedToolMap | undefined, skill: LoadedSkillInfo | undefined): LoadedToolMap | undefined;
65
+ /**
66
+ * 提示词构建上下文
67
+ */
68
+ export interface PromptBuildContext {
69
+ /**
70
+ * 开发者编写的系统提示词。
71
+ * 来源:Graph LLM 节点 config.systemPrompt(主路径);
72
+ * Registry 无内嵌 Graph 的兜底路径为 agent.manifest.json prompts.system。
73
+ */
74
+ developerPrompt?: string;
75
+ /** Agent 名称 */
76
+ agentName?: string;
77
+ /** Agent 代码标识 */
78
+ agentCode?: string;
79
+ /** 当前调用用户标识(可选,供「我 / 我的」类指代) */
80
+ userId?: string | null;
81
+ }
82
+ /**
83
+ * SystemPromptBuilder — 系统提示词拼接
84
+ *
85
+ * 四段式拼接:平台规则 + 当前时间 + Agent 身份 + 开发者提示词。
86
+ * 不注入工具列表(工具走 API tools 参数)。
87
+ * 不支持模板变量替换(开发者直接写最终文本)。
88
+ */
89
+ export declare class SystemPromptBuilder {
90
+ /**
91
+ * 构建完整系统提示词
92
+ */
93
+ build(context: PromptBuildContext): string;
94
+ private buildCurrentTime;
95
+ private buildAgentIdentity;
96
+ }
97
+ /**
98
+ * OpenAI function-calling tool definition(API tools 参数格式)
99
+ *
100
+ * 与 LLMNode 的 LLMToolDefinition 结构一致,此处作为别名导出,
101
+ * 方便 tool 模块的使用者按领域引用。
102
+ */
103
+ export type ApiToolDefinition = LLMToolDefinition;
104
+ /**
105
+ * 将平台的 LoadedToolMap 转为 OpenAI API 的 tools 参数
106
+ *
107
+ * 工具通过 API 的 tools 参数传入 LLM,不嵌入 system prompt。
108
+ * 可按需传入 skillTools 过滤子集(只暴露当前 Skill 需要的工具)。
109
+ *
110
+ * @param loadedTools - 已装配的工具映射
111
+ * @param skillTools - 可选,当前 Skill 所需的工具名称列表(过滤子集)
112
+ * @returns OpenAI API tools 参数数组
113
+ */
114
+ export declare function loadedToolsToApiTools(loadedTools: LoadedToolMap | undefined, skillTools?: string[]): ApiToolDefinition[];