@zhin.js/agent 1.1.14 → 1.1.16

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 (213) hide show
  1. package/README.md +5 -4
  2. package/lib/activity-feedback/adapter-integration.d.ts +33 -10
  3. package/lib/activity-feedback/adapter-integration.d.ts.map +1 -1
  4. package/lib/activity-feedback/adapter-integration.js +90 -88
  5. package/lib/activity-feedback/adapter-integration.js.map +1 -1
  6. package/lib/activity-feedback/ai-bus.d.ts +2 -1
  7. package/lib/activity-feedback/ai-bus.d.ts.map +1 -1
  8. package/lib/activity-feedback/ai-bus.js +14 -3
  9. package/lib/activity-feedback/ai-bus.js.map +1 -1
  10. package/lib/activity-feedback/index.d.ts +3 -3
  11. package/lib/activity-feedback/index.d.ts.map +1 -1
  12. package/lib/activity-feedback/index.js +2 -2
  13. package/lib/activity-feedback/index.js.map +1 -1
  14. package/lib/activity-feedback/manager.d.ts +0 -5
  15. package/lib/activity-feedback/manager.d.ts.map +1 -1
  16. package/lib/activity-feedback/manager.js +21 -17
  17. package/lib/activity-feedback/manager.js.map +1 -1
  18. package/lib/activity-feedback/turn-event-projector.d.ts +11 -0
  19. package/lib/activity-feedback/turn-event-projector.d.ts.map +1 -0
  20. package/lib/activity-feedback/turn-event-projector.js +58 -0
  21. package/lib/activity-feedback/turn-event-projector.js.map +1 -0
  22. package/lib/ai-event-subscriber.d.ts +2 -2
  23. package/lib/ai-event-subscriber.d.ts.map +1 -1
  24. package/lib/ai-event-subscriber.js +1 -1
  25. package/lib/ai-event-subscriber.js.map +1 -1
  26. package/lib/authoring/bridge.d.ts.map +1 -1
  27. package/lib/authoring/bridge.js +15 -4
  28. package/lib/authoring/bridge.js.map +1 -1
  29. package/lib/authoring/define-tool.d.ts +8 -3
  30. package/lib/authoring/define-tool.d.ts.map +1 -1
  31. package/lib/authoring/define-tool.js +10 -0
  32. package/lib/authoring/define-tool.js.map +1 -1
  33. package/lib/authoring/types.d.ts +10 -3
  34. package/lib/authoring/types.d.ts.map +1 -1
  35. package/lib/authoring/types.js.map +1 -1
  36. package/lib/config/zhin-agent-config.d.ts +1 -3
  37. package/lib/config/zhin-agent-config.d.ts.map +1 -1
  38. package/lib/config/zhin-agent-defaults.d.ts.map +1 -1
  39. package/lib/config/zhin-agent-defaults.js +0 -2
  40. package/lib/config/zhin-agent-defaults.js.map +1 -1
  41. package/lib/core/agent-core-run.js +1 -1
  42. package/lib/core/agent-core-run.js.map +1 -1
  43. package/lib/deferred-worker-runner.d.ts.map +1 -1
  44. package/lib/deferred-worker-runner.js +2 -15
  45. package/lib/deferred-worker-runner.js.map +1 -1
  46. package/lib/deferred-worker-tool-load.d.ts +1 -1
  47. package/lib/deferred-worker-tool-load.js +1 -1
  48. package/lib/event/event-emitter.js +1 -1
  49. package/lib/event/event-emitter.js.map +1 -1
  50. package/lib/hooks.d.ts +0 -12
  51. package/lib/hooks.d.ts.map +1 -1
  52. package/lib/hooks.js.map +1 -1
  53. package/lib/index.d.ts +8 -11
  54. package/lib/index.d.ts.map +1 -1
  55. package/lib/index.js +6 -7
  56. package/lib/index.js.map +1 -1
  57. package/lib/init/dispose-zhin-agent.d.ts +1 -1
  58. package/lib/init/dispose-zhin-agent.d.ts.map +1 -1
  59. package/lib/init/dispose-zhin-agent.js +2 -2
  60. package/lib/init/dispose-zhin-agent.js.map +1 -1
  61. package/lib/internal/agent-host.d.ts +0 -3
  62. package/lib/internal/agent-host.d.ts.map +1 -1
  63. package/lib/plugin-runtime/agent-host-port.d.ts +8 -0
  64. package/lib/plugin-runtime/agent-host-port.d.ts.map +1 -1
  65. package/lib/plugin-runtime/agent-host-port.js.map +1 -1
  66. package/lib/plugin-runtime/capability-ingress.d.ts +2 -0
  67. package/lib/plugin-runtime/capability-ingress.d.ts.map +1 -1
  68. package/lib/plugin-runtime/capability-ingress.js +7 -0
  69. package/lib/plugin-runtime/capability-ingress.js.map +1 -1
  70. package/lib/plugin-runtime/capability-tools.d.ts.map +1 -1
  71. package/lib/plugin-runtime/capability-tools.js +1 -0
  72. package/lib/plugin-runtime/capability-tools.js.map +1 -1
  73. package/lib/plugin-runtime/full-agent-turn-engine.d.ts.map +1 -1
  74. package/lib/plugin-runtime/full-agent-turn-engine.js +31 -29
  75. package/lib/plugin-runtime/full-agent-turn-engine.js.map +1 -1
  76. package/lib/plugin-runtime/index.d.ts +1 -0
  77. package/lib/plugin-runtime/index.d.ts.map +1 -1
  78. package/lib/plugin-runtime/index.js.map +1 -1
  79. package/lib/plugin-runtime/workroom-projection-outbound.d.ts +4 -4
  80. package/lib/plugin-runtime/workroom-projection-outbound.d.ts.map +1 -1
  81. package/lib/plugin-runtime/workroom-projection-outbound.js +2 -2
  82. package/lib/plugin-runtime/workroom-projection-outbound.js.map +1 -1
  83. package/lib/prompt/assembly.d.ts +3 -1
  84. package/lib/prompt/assembly.d.ts.map +1 -1
  85. package/lib/prompt/assembly.js +27 -52
  86. package/lib/prompt/assembly.js.map +1 -1
  87. package/lib/prompt/index.d.ts +3 -6
  88. package/lib/prompt/index.d.ts.map +1 -1
  89. package/lib/prompt/index.js +2 -4
  90. package/lib/prompt/index.js.map +1 -1
  91. package/lib/prompt/prompt-assembly-registry.d.ts +14 -6
  92. package/lib/prompt/prompt-assembly-registry.d.ts.map +1 -1
  93. package/lib/prompt/prompt-assembly-registry.js +14 -5
  94. package/lib/prompt/prompt-assembly-registry.js.map +1 -1
  95. package/lib/prompt/prompt-budget.d.ts +11 -6
  96. package/lib/prompt/prompt-budget.d.ts.map +1 -1
  97. package/lib/prompt/prompt-budget.js +42 -11
  98. package/lib/prompt/prompt-budget.js.map +1 -1
  99. package/lib/prompt/system-prompt.d.ts +2 -4
  100. package/lib/prompt/system-prompt.d.ts.map +1 -1
  101. package/lib/prompt/system-prompt.js +34 -54
  102. package/lib/prompt/system-prompt.js.map +1 -1
  103. package/lib/resource-hub/index.d.ts +15 -5
  104. package/lib/resource-hub/index.d.ts.map +1 -1
  105. package/lib/resource-hub/index.js +10 -0
  106. package/lib/resource-hub/index.js.map +1 -1
  107. package/lib/resource-hub/public-api.d.ts +10 -0
  108. package/lib/resource-hub/public-api.d.ts.map +1 -0
  109. package/lib/resource-hub/public-api.js +6 -0
  110. package/lib/resource-hub/public-api.js.map +1 -0
  111. package/lib/resource-hub/types.d.ts +2 -1
  112. package/lib/resource-hub/types.d.ts.map +1 -1
  113. package/lib/subagent/subagent-runtime.d.ts +13 -1
  114. package/lib/subagent/subagent-runtime.d.ts.map +1 -1
  115. package/lib/subagent/subagent-runtime.js +136 -34
  116. package/lib/subagent/subagent-runtime.js.map +1 -1
  117. package/lib/subagent/subagent-system-init.js +4 -4
  118. package/lib/subagent/subagent-system-init.js.map +1 -1
  119. package/lib/subagent/subagent-system.d.ts +2 -1
  120. package/lib/subagent/subagent-system.d.ts.map +1 -1
  121. package/lib/subagent/subagent-system.js +10 -3
  122. package/lib/subagent/subagent-system.js.map +1 -1
  123. package/lib/task-executor.d.ts +7 -1
  124. package/lib/task-executor.d.ts.map +1 -1
  125. package/lib/task-executor.js +74 -48
  126. package/lib/task-executor.js.map +1 -1
  127. package/lib/turn/inbound-queue-runtime.d.ts.map +1 -1
  128. package/lib/turn/inbound-queue-runtime.js +6 -2
  129. package/lib/turn/inbound-queue-runtime.js.map +1 -1
  130. package/lib/turn/inbound-turn-queue.d.ts +1 -0
  131. package/lib/turn/inbound-turn-queue.d.ts.map +1 -1
  132. package/lib/turn/inbound-turn-queue.js +14 -4
  133. package/lib/turn/inbound-turn-queue.js.map +1 -1
  134. package/lib/turn/index.d.ts +1 -1
  135. package/lib/turn/index.d.ts.map +1 -1
  136. package/lib/turn/index.js +1 -1
  137. package/lib/turn/index.js.map +1 -1
  138. package/lib/turn/turn-context-bridge.d.ts +0 -2
  139. package/lib/turn/turn-context-bridge.d.ts.map +1 -1
  140. package/lib/turn/turn-context-bridge.js +1 -8
  141. package/lib/turn/turn-context-bridge.js.map +1 -1
  142. package/lib/turn/turn-ingress.d.ts +3 -1
  143. package/lib/turn/turn-ingress.d.ts.map +1 -1
  144. package/lib/turn/turn-ingress.js.map +1 -1
  145. package/lib/turn/turn-pipeline.d.ts +1 -1
  146. package/lib/turn/turn-pipeline.d.ts.map +1 -1
  147. package/lib/turn/turn-pipeline.js +40 -3
  148. package/lib/turn/turn-pipeline.js.map +1 -1
  149. package/lib/typing-indicator/index.d.ts +4 -0
  150. package/lib/typing-indicator/index.d.ts.map +1 -1
  151. package/lib/typing-indicator/index.js +96 -23
  152. package/lib/typing-indicator/index.js.map +1 -1
  153. package/lib/utils/keyed-mutex.d.ts +1 -1
  154. package/lib/utils/keyed-mutex.d.ts.map +1 -1
  155. package/lib/utils/keyed-mutex.js +18 -4
  156. package/lib/utils/keyed-mutex.js.map +1 -1
  157. package/lib/workroom/journal.d.ts +4 -1
  158. package/lib/workroom/journal.d.ts.map +1 -1
  159. package/lib/workroom/journal.js +93 -6
  160. package/lib/workroom/journal.js.map +1 -1
  161. package/lib/workroom/kernel-contracts.d.ts +2 -1
  162. package/lib/workroom/kernel-contracts.d.ts.map +1 -1
  163. package/lib/workroom/kernel-state.d.ts.map +1 -1
  164. package/lib/workroom/kernel-state.js +35 -1
  165. package/lib/workroom/kernel-state.js.map +1 -1
  166. package/lib/workroom/runtime.d.ts +34 -1
  167. package/lib/workroom/runtime.d.ts.map +1 -1
  168. package/lib/workroom/runtime.js +97 -5
  169. package/lib/workroom/runtime.js.map +1 -1
  170. package/lib/workroom/workroom-kernel.d.ts +6 -0
  171. package/lib/workroom/workroom-kernel.d.ts.map +1 -1
  172. package/lib/workroom/workroom-kernel.js +129 -0
  173. package/lib/workroom/workroom-kernel.js.map +1 -1
  174. package/lib/workroom/workroom-run-control.d.ts +69 -0
  175. package/lib/workroom/workroom-run-control.d.ts.map +1 -0
  176. package/lib/workroom/workroom-run-control.js +144 -0
  177. package/lib/workroom/workroom-run-control.js.map +1 -0
  178. package/lib/workroom/workroom-scheduler.d.ts.map +1 -1
  179. package/lib/workroom/workroom-scheduler.js +9 -1
  180. package/lib/workroom/workroom-scheduler.js.map +1 -1
  181. package/lib/zhin-agent/index.d.ts +2 -5
  182. package/lib/zhin-agent/index.d.ts.map +1 -1
  183. package/lib/zhin-agent/index.js +23 -17
  184. package/lib/zhin-agent/index.js.map +1 -1
  185. package/package.json +12 -11
  186. package/lib/agent-prompt/format.d.ts +0 -6
  187. package/lib/agent-prompt/format.d.ts.map +0 -1
  188. package/lib/agent-prompt/format.js +0 -40
  189. package/lib/agent-prompt/format.js.map +0 -1
  190. package/lib/agent-prompt/index.d.ts +0 -5
  191. package/lib/agent-prompt/index.d.ts.map +0 -1
  192. package/lib/agent-prompt/index.js +0 -4
  193. package/lib/agent-prompt/index.js.map +0 -1
  194. package/lib/agent-prompt/registry.d.ts +0 -7
  195. package/lib/agent-prompt/registry.d.ts.map +0 -1
  196. package/lib/agent-prompt/registry.js +0 -23
  197. package/lib/agent-prompt/registry.js.map +0 -1
  198. package/lib/agent-prompt/resolver.d.ts +0 -13
  199. package/lib/agent-prompt/resolver.d.ts.map +0 -1
  200. package/lib/agent-prompt/resolver.js +0 -75
  201. package/lib/agent-prompt/resolver.js.map +0 -1
  202. package/lib/prompt/define-agent-prompt-section.d.ts +0 -29
  203. package/lib/prompt/define-agent-prompt-section.d.ts.map +0 -1
  204. package/lib/prompt/define-agent-prompt-section.js +0 -22
  205. package/lib/prompt/define-agent-prompt-section.js.map +0 -1
  206. package/lib/prompt/discover-prompt-sections.d.ts +0 -21
  207. package/lib/prompt/discover-prompt-sections.d.ts.map +0 -1
  208. package/lib/prompt/discover-prompt-sections.js +0 -49
  209. package/lib/prompt/discover-prompt-sections.js.map +0 -1
  210. package/lib/prompt/prompt-section-loader.d.ts +0 -27
  211. package/lib/prompt/prompt-section-loader.d.ts.map +0 -1
  212. package/lib/prompt/prompt-section-loader.js +0 -75
  213. package/lib/prompt/prompt-section-loader.js.map +0 -1
@@ -1,6 +0,0 @@
1
- import type { AgentPromptSection } from '@zhin.js/core';
2
- export declare function sortAgentPromptSections(sections: AgentPromptSection[]): AgentPromptSection[];
3
- export declare function truncateAgentPromptText(text: string, maxChars: number): string;
4
- export declare function applyAgentPromptLimits(sections: AgentPromptSection[], sectionMaxChars: number, totalMaxChars: number): AgentPromptSection[];
5
- export declare function formatAgentPromptSectionsMarkdown(sections: AgentPromptSection[]): string;
6
- //# sourceMappingURL=format.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/agent-prompt/format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAExD,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,kBAAkB,EAAE,GAAG,kBAAkB,EAAE,CAE5F;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAI9E;AAED,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,kBAAkB,EAAE,EAC9B,eAAe,EAAE,MAAM,EACvB,aAAa,EAAE,MAAM,GACpB,kBAAkB,EAAE,CAiBtB;AAED,wBAAgB,iCAAiC,CAAC,QAAQ,EAAE,kBAAkB,EAAE,GAAG,MAAM,CAOxF"}
@@ -1,40 +0,0 @@
1
- export function sortAgentPromptSections(sections) {
2
- return [...sections].sort((a, b) => (a.priority ?? 100) - (b.priority ?? 100));
3
- }
4
- export function truncateAgentPromptText(text, maxChars) {
5
- if (text.length <= maxChars)
6
- return text;
7
- if (maxChars <= 1)
8
- return '…';
9
- return text.slice(0, maxChars - 1) + '…';
10
- }
11
- export function applyAgentPromptLimits(sections, sectionMaxChars, totalMaxChars) {
12
- const out = [];
13
- let used = 0;
14
- for (const section of sortAgentPromptSections(sections)) {
15
- const body = truncateAgentPromptText(section.body.trim(), sectionMaxChars);
16
- if (!body)
17
- continue;
18
- const titleLen = section.title ? section.title.length + 2 : 0;
19
- if (used + titleLen + body.length > totalMaxChars) {
20
- const remain = totalMaxChars - used - titleLen;
21
- if (remain <= 0)
22
- break;
23
- out.push({ ...section, body: truncateAgentPromptText(body, remain) });
24
- break;
25
- }
26
- out.push({ ...section, body });
27
- used += titleLen + body.length;
28
- }
29
- return out;
30
- }
31
- export function formatAgentPromptSectionsMarkdown(sections) {
32
- if (sections.length === 0)
33
- return '';
34
- const blocks = sections.map(s => {
35
- const head = s.title?.trim() ? `${s.title.trim()}\n\n` : '';
36
- return `${head}${s.body.trim()}`;
37
- });
38
- return blocks.join('\n\n');
39
- }
40
- //# sourceMappingURL=format.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"format.js","sourceRoot":"","sources":["../../src/agent-prompt/format.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,uBAAuB,CAAC,QAA8B;IACpE,OAAO,CAAC,GAAG,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,IAAI,GAAG,CAAC,CAAC,CAAC;AACjF,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,IAAY,EAAE,QAAgB;IACpE,IAAI,IAAI,CAAC,MAAM,IAAI,QAAQ;QAAE,OAAO,IAAI,CAAC;IACzC,IAAI,QAAQ,IAAI,CAAC;QAAE,OAAO,GAAG,CAAC;IAC9B,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC;AAC3C,CAAC;AAED,MAAM,UAAU,sBAAsB,CACpC,QAA8B,EAC9B,eAAuB,EACvB,aAAqB;IAErB,MAAM,GAAG,GAAyB,EAAE,CAAC;IACrC,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,KAAK,MAAM,OAAO,IAAI,uBAAuB,CAAC,QAAQ,CAAC,EAAE,CAAC;QACxD,MAAM,IAAI,GAAG,uBAAuB,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,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@@
1
- export { registerAgentPromptContributor, unregisterAgentPromptContributor, getAgentPromptContributor, clearAgentPromptContributors, } from './registry.js';
2
- export { resolveAgentPromptSections, resolveAgentPromptMarkdown, resolveDeferredToolsForPlatform, platformMatchesDeferredTask, } from './resolver.js';
3
- export type { ResolveAgentPromptOptions } from './resolver.js';
4
- export { formatAgentPromptSectionsMarkdown, applyAgentPromptLimits, sortAgentPromptSections, truncateAgentPromptText, } from './format.js';
5
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/agent-prompt/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,8BAA8B,EAC9B,gCAAgC,EAChC,yBAAyB,EACzB,4BAA4B,GAC7B,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,EAC1B,+BAA+B,EAC/B,2BAA2B,GAC5B,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EACL,iCAAiC,EACjC,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,GACxB,MAAM,aAAa,CAAC"}
@@ -1,4 +0,0 @@
1
- export { registerAgentPromptContributor, unregisterAgentPromptContributor, getAgentPromptContributor, clearAgentPromptContributors, } from './registry.js';
2
- export { resolveAgentPromptSections, resolveAgentPromptMarkdown, resolveDeferredToolsForPlatform, platformMatchesDeferredTask, } from './resolver.js';
3
- export { formatAgentPromptSectionsMarkdown, applyAgentPromptLimits, sortAgentPromptSections, truncateAgentPromptText, } from './format.js';
4
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/agent-prompt/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,8BAA8B,EAC9B,gCAAgC,EAChC,yBAAyB,EACzB,4BAA4B,GAC7B,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,EAC1B,+BAA+B,EAC/B,2BAA2B,GAC5B,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,iCAAiC,EACjC,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,GACxB,MAAM,aAAa,CAAC"}
@@ -1,7 +0,0 @@
1
- import { type AgentPromptContributor } from '@zhin.js/core';
2
- export declare function registerAgentPromptContributor(contributor: AgentPromptContributor): void;
3
- export declare function unregisterAgentPromptContributor(platform: string): void;
4
- export declare function getAgentPromptContributor(platform: string | undefined): AgentPromptContributor | undefined;
5
- /** Clear all contributors (tests). */
6
- export declare function clearAgentPromptContributors(): void;
7
- //# sourceMappingURL=registry.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/agent-prompt/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,sBAAsB,EAAa,MAAM,eAAe,CAAC;AAKvE,wBAAgB,8BAA8B,CAAC,WAAW,EAAE,sBAAsB,GAAG,IAAI,CAMxF;AAED,wBAAgB,gCAAgC,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAEvE;AAED,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,sBAAsB,GAAG,SAAS,CAG1G;AAED,sCAAsC;AACtC,wBAAgB,4BAA4B,IAAI,IAAI,CAEnD"}
@@ -1,23 +0,0 @@
1
- import { getLogger } from '@zhin.js/core';
2
- const logger = getLogger('AgentPromptRegistry');
3
- const contributors = new Map();
4
- export function registerAgentPromptContributor(contributor) {
5
- const key = contributor.platform;
6
- if (contributors.has(key)) {
7
- logger.warn(`Overriding AgentPromptContributor: ${key}`);
8
- }
9
- contributors.set(key, contributor);
10
- }
11
- export function unregisterAgentPromptContributor(platform) {
12
- contributors.delete(platform);
13
- }
14
- export function getAgentPromptContributor(platform) {
15
- if (!platform)
16
- return undefined;
17
- return contributors.get(platform);
18
- }
19
- /** Clear all contributors (tests). */
20
- export function clearAgentPromptContributors() {
21
- contributors.clear();
22
- }
23
- //# sourceMappingURL=registry.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/agent-prompt/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,SAAS,EAAE,MAAM,eAAe,CAAC;AACvE,MAAM,MAAM,GAAG,SAAS,CAAC,qBAAqB,CAAC,CAAC;AAEhD,MAAM,YAAY,GAAG,IAAI,GAAG,EAAkC,CAAC;AAE/D,MAAM,UAAU,8BAA8B,CAAC,WAAmC;IAChF,MAAM,GAAG,GAAG,WAAW,CAAC,QAAQ,CAAC;IACjC,IAAI,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1B,MAAM,CAAC,IAAI,CAAC,sCAAsC,GAAG,EAAE,CAAC,CAAC;IAC3D,CAAC;IACD,YAAY,CAAC,GAAG,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,gCAAgC,CAAC,QAAgB;IAC/D,YAAY,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,QAA4B;IACpE,IAAI,CAAC,QAAQ;QAAE,OAAO,SAAS,CAAC;IAChC,OAAO,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AACpC,CAAC;AAED,sCAAsC;AACtC,MAAM,UAAU,4BAA4B;IAC1C,YAAY,CAAC,KAAK,EAAE,CAAC;AACvB,CAAC"}
@@ -1,13 +0,0 @@
1
- import { type AgentPromptBuildContext, type AgentPromptSection } from '@zhin.js/core';
2
- import type { AgentTool } from '@zhin.js/ai';
3
- import { type ZhinAgentConfig } from '../config/index.js';
4
- export interface ResolveAgentPromptOptions {
5
- ctx: AgentPromptBuildContext;
6
- config?: Pick<Required<ZhinAgentConfig>, 'platformPromptSectionMaxChars' | 'platformPromptMaxChars'>;
7
- sessionId?: string;
8
- }
9
- export declare function resolveAgentPromptSections(options: ResolveAgentPromptOptions): Promise<AgentPromptSection[]>;
10
- export declare function resolveAgentPromptMarkdown(options: ResolveAgentPromptOptions): Promise<string>;
11
- export declare function resolveDeferredToolsForPlatform(ctx: AgentPromptBuildContext, query: string, goal: string, catalog: AgentTool[], maxTools: number, defaultSelect: (query: string, goal: string, catalog: AgentTool[], maxTools: number) => AgentTool[]): AgentTool[];
12
- export declare function platformMatchesDeferredTask(ctx: AgentPromptBuildContext, query: string, goal: string): boolean;
13
- //# sourceMappingURL=resolver.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../../src/agent-prompt/resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,uBAAuB,EAAE,KAAK,kBAAkB,EAAa,MAAM,eAAe,CAAC;AACjG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,KAAK,eAAe,EAAkB,MAAM,oBAAoB,CAAC;AAU1E,MAAM,WAAW,yBAAyB;IACxC,GAAG,EAAE,uBAAuB,CAAC;IAC7B,MAAM,CAAC,EAAE,IAAI,CACX,QAAQ,CAAC,eAAe,CAAC,EACzB,+BAA+B,GAAG,wBAAwB,CAC3D,CAAC;IACF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wBAAsB,0BAA0B,CAC9C,OAAO,EAAE,yBAAyB,GACjC,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAyC/B;AAED,wBAAsB,0BAA0B,CAC9C,OAAO,EAAE,yBAAyB,GACjC,OAAO,CAAC,MAAM,CAAC,CAGjB;AAED,wBAAgB,+BAA+B,CAC7C,GAAG,EAAE,uBAAuB,EAC5B,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,SAAS,EAAE,EACpB,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,CACb,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,SAAS,EAAE,EACpB,QAAQ,EAAE,MAAM,KACb,SAAS,EAAE,GACf,SAAS,EAAE,CAab;AAED,wBAAgB,2BAA2B,CACzC,GAAG,EAAE,uBAAuB,EAC5B,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,GACX,OAAO,CAUT"}
@@ -1,75 +0,0 @@
1
- import { getLogger } from '@zhin.js/core';
2
- import { DEFAULT_CONFIG } from '../config/index.js';
3
- import { createAIHookEvent, triggerAIHook } from '../hooks.js';
4
- import { applyAgentPromptLimits, formatAgentPromptSectionsMarkdown, sortAgentPromptSections, } from './format.js';
5
- import { getAgentPromptContributor } from './registry.js';
6
- const logger = getLogger('AgentPromptResolver');
7
- export async function resolveAgentPromptSections(options) {
8
- const { ctx, sessionId } = options;
9
- const limits = {
10
- sectionMax: options.config?.platformPromptSectionMaxChars
11
- ?? DEFAULT_CONFIG.platformPromptSectionMaxChars,
12
- totalMax: options.config?.platformPromptMaxChars
13
- ?? DEFAULT_CONFIG.platformPromptMaxChars,
14
- };
15
- const platform = ctx.platform;
16
- const contributor = getAgentPromptContributor(platform);
17
- let sections = [];
18
- if (contributor) {
19
- try {
20
- const built = await contributor.buildSections(ctx);
21
- if (built?.length) {
22
- sections.push(...built);
23
- }
24
- }
25
- catch (err) {
26
- const msg = err instanceof Error ? err.message : String(err);
27
- logger.warn(`AgentPromptContributor [${platform}] buildSections failed: ${msg}`);
28
- }
29
- }
30
- sections = sortAgentPromptSections(sections);
31
- const hookEvent = createAIHookEvent('agent', 'prompt', sessionId, {
32
- slot: ctx.slot,
33
- platform: ctx.platform,
34
- userMessagePreview: ctx.userMessagePreview,
35
- deferred: ctx.deferred,
36
- sections,
37
- });
38
- await triggerAIHook(hookEvent);
39
- const hookSections = hookEvent.context.sections;
40
- if (Array.isArray(hookSections)) {
41
- sections = sortAgentPromptSections(hookSections);
42
- }
43
- return applyAgentPromptLimits(sections, limits.sectionMax, limits.totalMax);
44
- }
45
- export async function resolveAgentPromptMarkdown(options) {
46
- const sections = await resolveAgentPromptSections(options);
47
- return formatAgentPromptSectionsMarkdown(sections);
48
- }
49
- export function resolveDeferredToolsForPlatform(ctx, query, goal, catalog, maxTools, defaultSelect) {
50
- const contributor = getAgentPromptContributor(ctx.platform);
51
- if (contributor?.matchesDeferredTask?.(ctx)) {
52
- const catalogLite = catalog.map((t) => ({ name: t.name, description: t.description }));
53
- const selected = contributor.selectDeferredTools?.(query, goal, catalogLite, maxTools);
54
- if (selected) {
55
- const byName = new Map(catalog.map((t) => [t.name, t]));
56
- return selected
57
- .map((item) => byName.get(item.name))
58
- .filter((tool) => tool != null);
59
- }
60
- }
61
- return defaultSelect(query, goal, catalog, maxTools);
62
- }
63
- export function platformMatchesDeferredTask(ctx, query, goal) {
64
- const contributor = getAgentPromptContributor(ctx.platform);
65
- if (contributor?.matchesDeferredTask) {
66
- try {
67
- return contributor.matchesDeferredTask(ctx);
68
- }
69
- catch {
70
- return false;
71
- }
72
- }
73
- return false;
74
- }
75
- //# sourceMappingURL=resolver.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolver.js","sourceRoot":"","sources":["../../src/agent-prompt/resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyD,SAAS,EAAE,MAAM,eAAe,CAAC;AAEjG,OAAO,EAAwB,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EACL,sBAAsB,EACtB,iCAAiC,EACjC,uBAAuB,GACxB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAC1D,MAAM,MAAM,GAAG,SAAS,CAAC,qBAAqB,CAAC,CAAC;AAWhD,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,OAAkC;IAElC,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IACnC,MAAM,MAAM,GAAG;Q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CAAC,IAAI,CAAC,CAAC;iBACpC,MAAM,CAAC,CAAC,IAAI,EAAqB,EAAE,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;IACD,OAAO,aAAa,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;AACvD,CAAC;AAED,MAAM,UAAU,2BAA2B,CACzC,GAA4B,EAC5B,KAAa,EACb,IAAY;IAEZ,MAAM,WAAW,GAAG,yBAAyB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC5D,IAAI,WAAW,EAAE,mBAAmB,EAAE,CAAC;QACrC,IAAI,CAAC;YACH,OAAO,WAAW,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;QAC9C,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -1,29 +0,0 @@
1
- import type { PromptLayer } from './prompt-builder.js';
2
- export interface AgentPromptSectionConfig {
3
- id: string;
4
- title: string;
5
- content: string;
6
- priority?: number;
7
- truncatable?: boolean;
8
- maxChars?: number;
9
- metadata?: Record<string, unknown>;
10
- /** 层级(用于分类,不直接影响排序) */
11
- layer?: PromptLayer | 'plugin';
12
- }
13
- /**
14
- * 定义一个 Agent 提示词节点。
15
- *
16
- * 插件将此函数的返回值作为 `agent/prompt-sections/` 下文件的默认导出,
17
- * 框架在 Agent 初始化时会自动发现并注册到 `PromptAssemblyRegistry`。
18
- *
19
- * @example
20
- * export default defineAgentPromptSection({
21
- * id: 'my-plugin:context',
22
- * title: 'My Context',
23
- * content: 'Rules and context...',
24
- * priority: 75,
25
- * truncatable: true,
26
- * });
27
- */
28
- export declare function defineAgentPromptSection(config: AgentPromptSectionConfig): AgentPromptSectionConfig;
29
- //# sourceMappingURL=define-agent-prompt-section.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"define-agent-prompt-section.d.ts","sourceRoot":"","sources":["../../src/prompt/define-agent-prompt-section.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD,MAAM,WAAW,wBAAwB;IACvC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,uBAAuB;IACvB,KAAK,CAAC,EAAE,WAAW,GAAG,QAAQ,CAAC;CAChC;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,wBAAwB,GAC/B,wBAAwB,CAK1B"}
@@ -1,22 +0,0 @@
1
- /**
2
- * 定义一个 Agent 提示词节点。
3
- *
4
- * 插件将此函数的返回值作为 `agent/prompt-sections/` 下文件的默认导出,
5
- * 框架在 Agent 初始化时会自动发现并注册到 `PromptAssemblyRegistry`。
6
- *
7
- * @example
8
- * export default defineAgentPromptSection({
9
- * id: 'my-plugin:context',
10
- * title: 'My Context',
11
- * content: 'Rules and context...',
12
- * priority: 75,
13
- * truncatable: true,
14
- * });
15
- */
16
- export function defineAgentPromptSection(config) {
17
- return {
18
- layer: 'plugin',
19
- ...config,
20
- };
21
- }
22
- //# sourceMappingURL=define-agent-prompt-section.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"define-agent-prompt-section.js","sourceRoot":"","sources":["../../src/prompt/define-agent-prompt-section.ts"],"names":[],"mappings":"AAcA;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,wBAAwB,CACtC,MAAgC;IAEhC,OAAO;QACL,KAAK,EAAE,QAAQ;QACf,GAAG,MAAM;KACV,CAAC;AACJ,CAAC"}
@@ -1,21 +0,0 @@
1
- import { type PromptSectionLoaderOptions } from './prompt-section-loader.js';
2
- import type { PromptAssemblyRegistry } from './prompt-assembly-registry.js';
3
- /**
4
- * 从一批插件根目录中发现并注册提示词节点。
5
- *
6
- * @returns 成功注册的节点总数
7
- */
8
- export declare function discoverAndRegisterPromptSections(pluginRootDirs: string[], registry: PromptAssemblyRegistry, options?: PromptSectionLoaderOptions): Promise<number>;
9
- /**
10
- * 在 Agent 初始化时调用,自动从 ctx 中获取所有插件根目录,
11
- * 扫描 `agent/prompt-sections/` 目录并注册到 registry。
12
- *
13
- * ctx 需要提供 `getPluginRoots()` 或 `plugins`(含 `root` 属性)。
14
- */
15
- export declare function bootstrapPromptSections(ctx: {
16
- getPluginRoots?: () => string[];
17
- plugins?: Array<{
18
- root?: string;
19
- }>;
20
- }, registry: PromptAssemblyRegistry, options?: PromptSectionLoaderOptions): Promise<void>;
21
- //# sourceMappingURL=discover-prompt-sections.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"discover-prompt-sections.d.ts","sourceRoot":"","sources":["../../src/prompt/discover-prompt-sections.ts"],"names":[],"mappings":"AAEA,OAAO,EAAuB,KAAK,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAClG,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAM5E;;;;GAIG;AACH,wBAAsB,iCAAiC,CACrD,cAAc,EAAE,MAAM,EAAE,EACxB,QAAQ,EAAE,sBAAsB,EAChC,OAAO,CAAC,EAAE,0BAA0B,GACnC,OAAO,CAAC,MAAM,CAAC,CAajB;AAED;;;;;GAKG;AACH,wBAAsB,uBAAuB,CAC3C,GAAG,EAAE;IACH,cAAc,CAAC,EAAE,MAAM,MAAM,EAAE,CAAC;IAChC,OAAO,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACpC,EACD,QAAQ,EAAE,sBAAsB,EAChC,OAAO,CAAC,EAAE,0BAA0B,GACnC,OAAO,CAAC,IAAI,CAAC,CAoBf"}
@@ -1,49 +0,0 @@
1
- import * as path from 'node:path';
2
- import { getLogger } from '@zhin.js/logger';
3
- import { PromptSectionLoader } from './prompt-section-loader.js';
4
- const logger = getLogger('PromptSectionDiscovery');
5
- const CONVENTION_SUBDIR = 'agent/prompt-sections';
6
- /**
7
- * 从一批插件根目录中发现并注册提示词节点。
8
- *
9
- * @returns 成功注册的节点总数
10
- */
11
- export async function discoverAndRegisterPromptSections(pluginRootDirs, registry, options) {
12
- const loader = new PromptSectionLoader();
13
- const subdir = options?.subdir ?? CONVENTION_SUBDIR;
14
- let count = 0;
15
- for (const root of pluginRootDirs) {
16
- const dirPath = path.join(root, subdir);
17
- const sections = await loader.loadFromDir(dirPath, { strict: options?.strict });
18
- await loader.registerToRegistry(sections, registry);
19
- count += sections.length;
20
- }
21
- return count;
22
- }
23
- /**
24
- * 在 Agent 初始化时调用,自动从 ctx 中获取所有插件根目录,
25
- * 扫描 `agent/prompt-sections/` 目录并注册到 registry。
26
- *
27
- * ctx 需要提供 `getPluginRoots()` 或 `plugins`(含 `root` 属性)。
28
- */
29
- export async function bootstrapPromptSections(ctx, registry, options) {
30
- let roots;
31
- if (typeof ctx.getPluginRoots === 'function') {
32
- roots = ctx.getPluginRoots();
33
- }
34
- else if (Array.isArray(ctx.plugins)) {
35
- roots = ctx.plugins
36
- .map(p => p.root)
37
- .filter((r) => typeof r === 'string');
38
- }
39
- else {
40
- roots = [];
41
- }
42
- if (roots.length === 0) {
43
- logger.debug('[bootstrapPromptSections] no plugin roots found — skipping discovery');
44
- return;
45
- }
46
- const count = await discoverAndRegisterPromptSections(roots, registry, options);
47
- logger.debug(`[bootstrapPromptSections] discovered ${count} prompt section(s) from ${roots.length} plugin(s)`);
48
- }
49
- //# sourceMappingURL=discover-prompt-sections.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"discover-prompt-sections.js","sourceRoot":"","sources":["../../src/prompt/discover-prompt-sections.ts"],"names":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K,GAAG,GAAG,CAAC,OAAO;aAChB,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;aAChB,MAAM,CAAC,CAAC,CAAC,EAAe,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC;IACvD,CAAC;SAAM,CAAC;QACN,KAAK,GAAG,EAAE,CAAC;IACb,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,MAAM,CAAC,KAAK,CAAC,sEAAsE,CAAC,CAAC;QACrF,OAAO;IACT,CAAC;IAED,MAAM,KAAK,GAAG,MAAM,iCAAiC,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;IAChF,MAAM,CAAC,KAAK,CAAC,wCAAwC,KAAK,2BAA2B,KAAK,CAAC,MAAM,YAAY,CAAC,CAAC;AACjH,CAAC"}
@@ -1,27 +0,0 @@
1
- import type { AgentPromptSectionConfig } from './define-agent-prompt-section.js';
2
- import type { PromptAssemblyRegistry } from './prompt-assembly-registry.js';
3
- export interface PromptSectionLoaderOptions {
4
- /**
5
- * 相对于插件根目录的 glob 模式
6
- * @default 'agent/prompt-sections'
7
- */
8
- subdir?: string;
9
- /**
10
- * 是否在发现失败时抛出错误
11
- * @default false
12
- */
13
- strict?: boolean;
14
- }
15
- export declare class PromptSectionLoader {
16
- /**
17
- * 从指定目录路径加载所有提示词节点文件。
18
- *
19
- * @param dirPath 绝对路径,对应 `agent/prompt-sections/` 目录
20
- */
21
- loadFromDir(dirPath: string, options?: Pick<PromptSectionLoaderOptions, 'strict'>): Promise<AgentPromptSectionConfig[]>;
22
- /**
23
- * 将提示词节点列表批量注册到 registry。
24
- */
25
- registerToRegistry(sections: AgentPromptSectionConfig[], registry: PromptAssemblyRegistry): Promise<void>;
26
- }
27
- //# sourceMappingURL=prompt-section-loader.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"prompt-section-loader.d.ts","sourceRoot":"","sources":["../../src/prompt/prompt-section-loader.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AACjF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAI5E,MAAM,WAAW,0BAA0B;IACzC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAYD,qBAAa,mBAAmB;IAC9B;;;;OAIG;IACG,WAAW,CACf,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,IAAI,CAAC,0BAA0B,EAAE,QAAQ,CAAC,GACnD,OAAO,CAAC,wBAAwB,EAAE,CAAC;IAyCtC;;OAEG;IACG,kBAAkB,CACtB,QAAQ,EAAE,wBAAwB,EAAE,EACpC,QAAQ,EAAE,sBAAsB,GAC/B,OAAO,CAAC,IAAI,CAAC;CAajB"}
@@ -1,75 +0,0 @@
1
- import * as path from 'node:path';
2
- import { getLogger } from '@zhin.js/logger';
3
- const logger = getLogger('PromptSectionLoader');
4
- function isValidPromptSection(obj) {
5
- if (!obj || typeof obj !== 'object')
6
- return false;
7
- const s = obj;
8
- return (typeof s['id'] === 'string' &&
9
- typeof s['title'] === 'string' &&
10
- typeof s['content'] === 'string');
11
- }
12
- export class PromptSectionLoader {
13
- /**
14
- * 从指定目录路径加载所有提示词节点文件。
15
- *
16
- * @param dirPath 绝对路径,对应 `agent/prompt-sections/` 目录
17
- */
18
- async loadFromDir(dirPath, options) {
19
- const { default: fs } = await import('node:fs');
20
- const sections = [];
21
- let files;
22
- try {
23
- // Node recursive readdir may be typed as Dirent[] depending on overloads; normalize to relative paths.
24
- const entries = fs.readdirSync(dirPath, { recursive: true });
25
- files = entries
26
- .map((entry) => {
27
- if (typeof entry === 'string')
28
- return entry;
29
- const parent = entry.parentPath ?? entry.path;
30
- return parent ? path.relative(dirPath, path.join(parent, entry.name)) : entry.name;
31
- })
32
- .filter((f) => f.endsWith('.ts') || f.endsWith('.js'));
33
- }
34
- catch {
35
- // 目录不存在时静默忽略
36
- return sections;
37
- }
38
- for (const rel of files) {
39
- const filePath = path.join(dirPath, rel);
40
- try {
41
- const mod = await import(filePath);
42
- const section = mod.default;
43
- if (isValidPromptSection(section)) {
44
- sections.push(section);
45
- }
46
- else {
47
- logger.warn(`[PromptSectionLoader] ${filePath} default export is not a valid AgentPromptSectionConfig — skipped`);
48
- }
49
- }
50
- catch (err) {
51
- if (options?.strict)
52
- throw err;
53
- logger.warn(`[PromptSectionLoader] failed to load ${filePath}: ${err.message}`);
54
- }
55
- }
56
- return sections;
57
- }
58
- /**
59
- * 将提示词节点列表批量注册到 registry。
60
- */
61
- async registerToRegistry(sections, registry) {
62
- for (const section of sections) {
63
- registry.register(section.id, {
64
- layer: section.layer ?? 'context',
65
- title: section.title,
66
- content: section.content,
67
- priority: section.priority ?? 50,
68
- truncatable: section.truncatable ?? true,
69
- maxChars: section.maxChars,
70
- metadata: section.metadata,
71
- });
72
- }
73
- }
74
- }
75
- //# sourceMappingURL=prompt-section-loader.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"prompt-section-loader.js","sourceRoot":"","sources":["../../src/prompt/prompt-section-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,MAAM,MAAM,GAAG,SAAS,CAAC,qBAAqB,CAAC,CAAC;AAgBhD,SAAS,oBAAoB,CAAC,GAAY;IACxC,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAClD,MAAM,CAAC,GAAG,GAA8B,CAAC;IACzC,OAAO,CACL,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,QAAQ;QAC3B,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ;QAC9B,OAAO,CAAC,CAAC,SAAS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