@aigne/agent-runtime 1.12.0-beta.5

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 (234) hide show
  1. package/LICENSE.md +26 -0
  2. package/README.md +79 -0
  3. package/dist/agent-runners/ai-runner.cjs +133 -0
  4. package/dist/agent-runners/ai-runner.d.cts +33 -0
  5. package/dist/agent-runners/ai-runner.d.cts.map +1 -0
  6. package/dist/agent-runners/ai-runner.d.mts +33 -0
  7. package/dist/agent-runners/ai-runner.d.mts.map +1 -0
  8. package/dist/agent-runners/ai-runner.mjs +134 -0
  9. package/dist/agent-runners/ai-runner.mjs.map +1 -0
  10. package/dist/agent-runners/ash-runner.cjs +272 -0
  11. package/dist/agent-runners/ash-runner.d.cts +30 -0
  12. package/dist/agent-runners/ash-runner.d.cts.map +1 -0
  13. package/dist/agent-runners/ash-runner.d.mts +30 -0
  14. package/dist/agent-runners/ash-runner.d.mts.map +1 -0
  15. package/dist/agent-runners/ash-runner.mjs +273 -0
  16. package/dist/agent-runners/ash-runner.mjs.map +1 -0
  17. package/dist/agent-runners/budget.cjs +71 -0
  18. package/dist/agent-runners/budget.d.cts +40 -0
  19. package/dist/agent-runners/budget.d.cts.map +1 -0
  20. package/dist/agent-runners/budget.d.mts +40 -0
  21. package/dist/agent-runners/budget.d.mts.map +1 -0
  22. package/dist/agent-runners/budget.mjs +67 -0
  23. package/dist/agent-runners/budget.mjs.map +1 -0
  24. package/dist/agent-runners/code-runner.cjs +61 -0
  25. package/dist/agent-runners/code-runner.mjs +61 -0
  26. package/dist/agent-runners/code-runner.mjs.map +1 -0
  27. package/dist/agent-runners/env-whitelist.cjs +36 -0
  28. package/dist/agent-runners/env-whitelist.d.cts +5 -0
  29. package/dist/agent-runners/env-whitelist.d.cts.map +1 -0
  30. package/dist/agent-runners/env-whitelist.d.mts +5 -0
  31. package/dist/agent-runners/env-whitelist.d.mts.map +1 -0
  32. package/dist/agent-runners/env-whitelist.mjs +36 -0
  33. package/dist/agent-runners/env-whitelist.mjs.map +1 -0
  34. package/dist/agent-runners/guide-rails.cjs +47 -0
  35. package/dist/agent-runners/guide-rails.d.cts +16 -0
  36. package/dist/agent-runners/guide-rails.d.cts.map +1 -0
  37. package/dist/agent-runners/guide-rails.d.mts +16 -0
  38. package/dist/agent-runners/guide-rails.d.mts.map +1 -0
  39. package/dist/agent-runners/guide-rails.mjs +48 -0
  40. package/dist/agent-runners/guide-rails.mjs.map +1 -0
  41. package/dist/agent-runners/hook-channel.cjs +55 -0
  42. package/dist/agent-runners/hook-channel.d.cts +38 -0
  43. package/dist/agent-runners/hook-channel.d.cts.map +1 -0
  44. package/dist/agent-runners/hook-channel.d.mts +38 -0
  45. package/dist/agent-runners/hook-channel.d.mts.map +1 -0
  46. package/dist/agent-runners/hook-channel.mjs +55 -0
  47. package/dist/agent-runners/hook-channel.mjs.map +1 -0
  48. package/dist/agent-runners/hooks.cjs +107 -0
  49. package/dist/agent-runners/hooks.d.cts +41 -0
  50. package/dist/agent-runners/hooks.d.cts.map +1 -0
  51. package/dist/agent-runners/hooks.d.mts +41 -0
  52. package/dist/agent-runners/hooks.d.mts.map +1 -0
  53. package/dist/agent-runners/hooks.mjs +107 -0
  54. package/dist/agent-runners/hooks.mjs.map +1 -0
  55. package/dist/agent-runners/memory-afs.cjs +342 -0
  56. package/dist/agent-runners/memory-afs.d.cts +221 -0
  57. package/dist/agent-runners/memory-afs.d.cts.map +1 -0
  58. package/dist/agent-runners/memory-afs.d.mts +221 -0
  59. package/dist/agent-runners/memory-afs.d.mts.map +1 -0
  60. package/dist/agent-runners/memory-afs.mjs +326 -0
  61. package/dist/agent-runners/memory-afs.mjs.map +1 -0
  62. package/dist/agent-runners/memory-archive.cjs +263 -0
  63. package/dist/agent-runners/memory-archive.d.cts +47 -0
  64. package/dist/agent-runners/memory-archive.d.cts.map +1 -0
  65. package/dist/agent-runners/memory-archive.d.mts +47 -0
  66. package/dist/agent-runners/memory-archive.d.mts.map +1 -0
  67. package/dist/agent-runners/memory-archive.mjs +257 -0
  68. package/dist/agent-runners/memory-archive.mjs.map +1 -0
  69. package/dist/agent-runners/orchestrator-runner.cjs +302 -0
  70. package/dist/agent-runners/orchestrator-runner.d.cts +23 -0
  71. package/dist/agent-runners/orchestrator-runner.d.cts.map +1 -0
  72. package/dist/agent-runners/orchestrator-runner.d.mts +23 -0
  73. package/dist/agent-runners/orchestrator-runner.d.mts.map +1 -0
  74. package/dist/agent-runners/orchestrator-runner.mjs +303 -0
  75. package/dist/agent-runners/orchestrator-runner.mjs.map +1 -0
  76. package/dist/agent-runners/orchestrator-state.cjs +68 -0
  77. package/dist/agent-runners/orchestrator-state.d.cts +23 -0
  78. package/dist/agent-runners/orchestrator-state.d.cts.map +1 -0
  79. package/dist/agent-runners/orchestrator-state.d.mts +23 -0
  80. package/dist/agent-runners/orchestrator-state.d.mts.map +1 -0
  81. package/dist/agent-runners/orchestrator-state.mjs +65 -0
  82. package/dist/agent-runners/orchestrator-state.mjs.map +1 -0
  83. package/dist/agent-runners/retry.cjs +30 -0
  84. package/dist/agent-runners/retry.d.cts +13 -0
  85. package/dist/agent-runners/retry.d.cts.map +1 -0
  86. package/dist/agent-runners/retry.d.mts +13 -0
  87. package/dist/agent-runners/retry.d.mts.map +1 -0
  88. package/dist/agent-runners/retry.mjs +30 -0
  89. package/dist/agent-runners/retry.mjs.map +1 -0
  90. package/dist/agent-runners/scratchpad-afs.cjs +276 -0
  91. package/dist/agent-runners/scratchpad-afs.d.cts +103 -0
  92. package/dist/agent-runners/scratchpad-afs.d.cts.map +1 -0
  93. package/dist/agent-runners/scratchpad-afs.d.mts +103 -0
  94. package/dist/agent-runners/scratchpad-afs.d.mts.map +1 -0
  95. package/dist/agent-runners/scratchpad-afs.mjs +271 -0
  96. package/dist/agent-runners/scratchpad-afs.mjs.map +1 -0
  97. package/dist/agent-runners/stream-router.cjs +72 -0
  98. package/dist/agent-runners/stream-router.d.cts +22 -0
  99. package/dist/agent-runners/stream-router.d.cts.map +1 -0
  100. package/dist/agent-runners/stream-router.d.mts +22 -0
  101. package/dist/agent-runners/stream-router.d.mts.map +1 -0
  102. package/dist/agent-runners/stream-router.mjs +72 -0
  103. package/dist/agent-runners/stream-router.mjs.map +1 -0
  104. package/dist/agent-runners/system-prompt.cjs +35 -0
  105. package/dist/agent-runners/system-prompt.d.cts +17 -0
  106. package/dist/agent-runners/system-prompt.d.cts.map +1 -0
  107. package/dist/agent-runners/system-prompt.d.mts +17 -0
  108. package/dist/agent-runners/system-prompt.d.mts.map +1 -0
  109. package/dist/agent-runners/system-prompt.mjs +34 -0
  110. package/dist/agent-runners/system-prompt.mjs.map +1 -0
  111. package/dist/agent-runners/team-modes/aggregates.cjs +36 -0
  112. package/dist/agent-runners/team-modes/aggregates.mjs +35 -0
  113. package/dist/agent-runners/team-modes/aggregates.mjs.map +1 -0
  114. package/dist/agent-runners/team-modes/iterate.cjs +46 -0
  115. package/dist/agent-runners/team-modes/iterate.mjs +47 -0
  116. package/dist/agent-runners/team-modes/iterate.mjs.map +1 -0
  117. package/dist/agent-runners/team-modes/parallel.cjs +59 -0
  118. package/dist/agent-runners/team-modes/parallel.mjs +60 -0
  119. package/dist/agent-runners/team-modes/parallel.mjs.map +1 -0
  120. package/dist/agent-runners/team-modes/reflection.cjs +155 -0
  121. package/dist/agent-runners/team-modes/reflection.mjs +156 -0
  122. package/dist/agent-runners/team-modes/reflection.mjs.map +1 -0
  123. package/dist/agent-runners/team-modes/sequential.cjs +63 -0
  124. package/dist/agent-runners/team-modes/sequential.mjs +64 -0
  125. package/dist/agent-runners/team-modes/sequential.mjs.map +1 -0
  126. package/dist/agent-runners/team-modes/utils.cjs +39 -0
  127. package/dist/agent-runners/team-modes/utils.mjs +36 -0
  128. package/dist/agent-runners/team-modes/utils.mjs.map +1 -0
  129. package/dist/agent-runners/team-runner.cjs +277 -0
  130. package/dist/agent-runners/team-runner.d.cts +34 -0
  131. package/dist/agent-runners/team-runner.d.cts.map +1 -0
  132. package/dist/agent-runners/team-runner.d.mts +34 -0
  133. package/dist/agent-runners/team-runner.d.mts.map +1 -0
  134. package/dist/agent-runners/team-runner.mjs +278 -0
  135. package/dist/agent-runners/team-runner.mjs.map +1 -0
  136. package/dist/agent-runners/template-context.cjs +32 -0
  137. package/dist/agent-runners/template-context.d.cts +43 -0
  138. package/dist/agent-runners/template-context.d.cts.map +1 -0
  139. package/dist/agent-runners/template-context.d.mts +43 -0
  140. package/dist/agent-runners/template-context.d.mts.map +1 -0
  141. package/dist/agent-runners/template-context.mjs +33 -0
  142. package/dist/agent-runners/template-context.mjs.map +1 -0
  143. package/dist/index.cjs +123 -0
  144. package/dist/index.d.cts +29 -0
  145. package/dist/index.d.mts +29 -0
  146. package/dist/index.mjs +29 -0
  147. package/dist/program/agent-action.cjs +496 -0
  148. package/dist/program/agent-action.d.cts +42 -0
  149. package/dist/program/agent-action.d.cts.map +1 -0
  150. package/dist/program/agent-action.d.mts +42 -0
  151. package/dist/program/agent-action.d.mts.map +1 -0
  152. package/dist/program/agent-action.mjs +497 -0
  153. package/dist/program/agent-action.mjs.map +1 -0
  154. package/dist/program/agent-messages-tools.cjs +137 -0
  155. package/dist/program/agent-messages-tools.d.cts +59 -0
  156. package/dist/program/agent-messages-tools.d.cts.map +1 -0
  157. package/dist/program/agent-messages-tools.d.mts +59 -0
  158. package/dist/program/agent-messages-tools.d.mts.map +1 -0
  159. package/dist/program/agent-messages-tools.mjs +130 -0
  160. package/dist/program/agent-messages-tools.mjs.map +1 -0
  161. package/dist/program/agent-runner-registry.cjs +314 -0
  162. package/dist/program/agent-runner-registry.d.cts +52 -0
  163. package/dist/program/agent-runner-registry.d.cts.map +1 -0
  164. package/dist/program/agent-runner-registry.d.mts +52 -0
  165. package/dist/program/agent-runner-registry.d.mts.map +1 -0
  166. package/dist/program/agent-runner-registry.mjs +313 -0
  167. package/dist/program/agent-runner-registry.mjs.map +1 -0
  168. package/dist/program/agent-subscribe.cjs +72 -0
  169. package/dist/program/agent-subscribe.d.cts +18 -0
  170. package/dist/program/agent-subscribe.d.cts.map +1 -0
  171. package/dist/program/agent-subscribe.d.mts +18 -0
  172. package/dist/program/agent-subscribe.d.mts.map +1 -0
  173. package/dist/program/agent-subscribe.mjs +73 -0
  174. package/dist/program/agent-subscribe.mjs.map +1 -0
  175. package/dist/program/agent-tools.cjs +135 -0
  176. package/dist/program/agent-tools.d.cts +35 -0
  177. package/dist/program/agent-tools.d.cts.map +1 -0
  178. package/dist/program/agent-tools.d.mts +35 -0
  179. package/dist/program/agent-tools.d.mts.map +1 -0
  180. package/dist/program/agent-tools.mjs +136 -0
  181. package/dist/program/agent-tools.mjs.map +1 -0
  182. package/dist/program/manifest-nesting.cjs +57 -0
  183. package/dist/program/manifest-nesting.d.cts +13 -0
  184. package/dist/program/manifest-nesting.d.cts.map +1 -0
  185. package/dist/program/manifest-nesting.d.mts +13 -0
  186. package/dist/program/manifest-nesting.d.mts.map +1 -0
  187. package/dist/program/manifest-nesting.mjs +57 -0
  188. package/dist/program/manifest-nesting.mjs.map +1 -0
  189. package/dist/program/result-contract.cjs +55 -0
  190. package/dist/program/result-contract.d.cts +23 -0
  191. package/dist/program/result-contract.d.cts.map +1 -0
  192. package/dist/program/result-contract.d.mts +23 -0
  193. package/dist/program/result-contract.d.mts.map +1 -0
  194. package/dist/program/result-contract.mjs +51 -0
  195. package/dist/program/result-contract.mjs.map +1 -0
  196. package/dist/program/runner-error.cjs +71 -0
  197. package/dist/program/runner-error.d.cts +25 -0
  198. package/dist/program/runner-error.d.cts.map +1 -0
  199. package/dist/program/runner-error.d.mts +25 -0
  200. package/dist/program/runner-error.d.mts.map +1 -0
  201. package/dist/program/runner-error.mjs +72 -0
  202. package/dist/program/runner-error.mjs.map +1 -0
  203. package/dist/program/scoped-afs.cjs +538 -0
  204. package/dist/program/scoped-afs.d.cts +245 -0
  205. package/dist/program/scoped-afs.d.cts.map +1 -0
  206. package/dist/program/scoped-afs.d.mts +245 -0
  207. package/dist/program/scoped-afs.d.mts.map +1 -0
  208. package/dist/program/scoped-afs.mjs +531 -0
  209. package/dist/program/scoped-afs.mjs.map +1 -0
  210. package/dist/program/session-hierarchy.cjs +1 -0
  211. package/dist/program/session-hierarchy.d.cts +2 -0
  212. package/dist/program/session-hierarchy.d.mts +2 -0
  213. package/dist/program/session-hierarchy.mjs +3 -0
  214. package/dist/program/tool-discovery/ash-frontmatter.cjs +83 -0
  215. package/dist/program/tool-discovery/ash-frontmatter.d.cts +21 -0
  216. package/dist/program/tool-discovery/ash-frontmatter.d.cts.map +1 -0
  217. package/dist/program/tool-discovery/ash-frontmatter.d.mts +21 -0
  218. package/dist/program/tool-discovery/ash-frontmatter.d.mts.map +1 -0
  219. package/dist/program/tool-discovery/ash-frontmatter.mjs +84 -0
  220. package/dist/program/tool-discovery/ash-frontmatter.mjs.map +1 -0
  221. package/dist/program/tool-discovery/dot-path-resolver.cjs +60 -0
  222. package/dist/program/tool-discovery/dot-path-resolver.mjs +61 -0
  223. package/dist/program/tool-discovery/dot-path-resolver.mjs.map +1 -0
  224. package/dist/program/tool-discovery/skill-gate.cjs +36 -0
  225. package/dist/program/tool-discovery/skill-gate.d.cts +10 -0
  226. package/dist/program/tool-discovery/skill-gate.d.cts.map +1 -0
  227. package/dist/program/tool-discovery/skill-gate.d.mts +10 -0
  228. package/dist/program/tool-discovery/skill-gate.d.mts.map +1 -0
  229. package/dist/program/tool-discovery/skill-gate.mjs +35 -0
  230. package/dist/program/tool-discovery/skill-gate.mjs.map +1 -0
  231. package/dist/providers/basic/ash/dist/index.cjs +1809 -0
  232. package/dist/providers/basic/ash/dist/index.mjs +1807 -0
  233. package/dist/providers/basic/ash/dist/index.mjs.map +1 -0
  234. package/package.json +67 -0
@@ -0,0 +1,314 @@
1
+ const require_budget = require('../agent-runners/budget.cjs');
2
+ const require_memory_archive = require('../agent-runners/memory-archive.cjs');
3
+ const require_ash_runner = require('../agent-runners/ash-runner.cjs');
4
+ const require_scratchpad_afs = require('../agent-runners/scratchpad-afs.cjs');
5
+ const require_hooks = require('../agent-runners/hooks.cjs');
6
+ const require_memory_afs = require('../agent-runners/memory-afs.cjs');
7
+ const require_agent_messages_tools = require('./agent-messages-tools.cjs');
8
+ const require_scoped_afs = require('./scoped-afs.cjs');
9
+ require('./session-hierarchy.cjs');
10
+ const require_code_runner = require('../agent-runners/code-runner.cjs');
11
+ const require_stream_router = require('../agent-runners/stream-router.cjs');
12
+ const require_system_prompt = require('../agent-runners/system-prompt.cjs');
13
+ const require_team_runner = require('../agent-runners/team-runner.cjs');
14
+ const require_agent_action = require('./agent-action.cjs');
15
+ const require_orchestrator_runner = require('../agent-runners/orchestrator-runner.cjs');
16
+ let _aigne_afs = require("@aigne/afs");
17
+ let _aigne_afs_agent = require("@aigne/afs-agent");
18
+
19
+ //#region src/program/agent-runner-registry.ts
20
+ const log = (0, _aigne_afs.makeNsLog)("agent-runtime");
21
+ /**
22
+ * B10 — extract a filesystem-safe scratch key from a raw session id.
23
+ *
24
+ * The AI runner accepts either a bare id (`abc`) or a full session path
25
+ * (`/instance/.sessions/agent/abc`). Scratch paths must not contain separators,
26
+ * so we take the last non-empty path component.
27
+ */
28
+ function scratchKeyFromSession(sessionId) {
29
+ const trimmed = sessionId.replace(/\/+$/, "");
30
+ const idx = trimmed.lastIndexOf("/");
31
+ return idx >= 0 ? trimmed.slice(idx + 1) : trimmed;
32
+ }
33
+ async function maybeProvisionScratch(afs, manifest, sessionId, runId) {
34
+ if (!manifest.scratch || !sessionId) return null;
35
+ const key = scratchKeyFromSession(sessionId);
36
+ if (!key) return null;
37
+ try {
38
+ return await require_scratchpad_afs.provisionScratchViaAFS(afs, key, runId);
39
+ } catch (err) {
40
+ log.warn(`[agent-runner] scratchpad provisioning failed for session=${key} runId=${runId}:`, err instanceof Error ? err.message : err);
41
+ return null;
42
+ }
43
+ }
44
+ function injectScratchPath(result, layout) {
45
+ const data = result.data ?? {};
46
+ data.scratch_path = layout.basePath;
47
+ const meta = data._meta && typeof data._meta === "object" ? data._meta : {};
48
+ meta.scratch_path = layout.basePath;
49
+ data._meta = meta;
50
+ result.data = data;
51
+ return result;
52
+ }
53
+ /**
54
+ * Resolve the effective tool whitelist for a runner. Phase 6 collapsed the
55
+ * parent-tools fallback: `ctx.afs.scope.allowedTools` is the single source
56
+ * of truth (computed by `projectForChild`). Callers without a scope fall
57
+ * back to the manifest's own tools.
58
+ */
59
+ function resolveEffectiveTools(context, childTools) {
60
+ const scope = context.afs.scope;
61
+ if (scope) return [...scope.allowedTools];
62
+ return childTools;
63
+ }
64
+ function withLifecycleHooks(runner) {
65
+ return async (input, context) => {
66
+ const blockletId = require_system_prompt.extractBlockletId(context.mountPath);
67
+ const scope = context.afs.scope;
68
+ const chainDepth = scope?.chainDepth ?? 0;
69
+ const dispatcher = require_hooks.createHookDispatcher(context.afs, context.manifest.hooks, {
70
+ mountPath: context.mountPath,
71
+ blockletId,
72
+ session: scope?.session ?? context.session,
73
+ chainDepth
74
+ });
75
+ const enrichedContext = {
76
+ ...context,
77
+ hookDispatcher: dispatcher
78
+ };
79
+ await dispatcher.fireOnStart(input);
80
+ try {
81
+ const result = await runner(input, enrichedContext);
82
+ await dispatcher.fireOnSuccess(result);
83
+ return result;
84
+ } catch (err) {
85
+ const message = err instanceof Error ? err.message : String(err);
86
+ await dispatcher.fireOnError({
87
+ code: "RUNNER_ERROR",
88
+ message
89
+ });
90
+ throw err;
91
+ }
92
+ };
93
+ }
94
+ const aiRunner = async (input, context) => {
95
+ const { manifest } = context;
96
+ const effectiveAfs = require_memory_afs.mountManifestMemory(context.afs, manifest.memory, context.mountPath);
97
+ const inputKey = manifest.inputKey ?? "message";
98
+ const task = String(input[inputKey] ?? "");
99
+ const callerBlockletId = require_system_prompt.extractBlockletId(context.mountPath);
100
+ const chain = context.chain ?? [];
101
+ (0, _aigne_afs_agent.checkSpawnDepth)(chain, manifest.maxSpawnDepth);
102
+ const { session: sessionId, parentSession: scopedParentSession } = require_scoped_afs.resolveChildSession(context.afs, context, _aigne_afs_agent.deriveChildSession);
103
+ const tools = resolveEffectiveTools(context, require_scoped_afs.normalizeManifestTools(manifest)).map((t) => ({
104
+ path: t.path,
105
+ ...t.ops ? { ops: t.ops } : {},
106
+ ...t.maxDepth != null ? { maxDepth: t.maxDepth } : {},
107
+ ...t.exclude_actions ? { exclude_actions: t.exclude_actions } : {}
108
+ }));
109
+ const messagingPath = require_agent_messages_tools.MESSAGING_TOOLS_GLOB;
110
+ if (!tools.some((t) => t.path === messagingPath || t.path === require_agent_messages_tools.MESSAGING_TOOLS_ROOT)) tools.push({
111
+ path: messagingPath,
112
+ ops: ["exec"]
113
+ });
114
+ if (manifest.memory) {
115
+ if (!tools.some((t) => t.path === "/memory/**" || t.path === "/memory" || t.path.startsWith("/memory/"))) tools.push({
116
+ path: "/memory/**",
117
+ ops: [
118
+ "read",
119
+ "list",
120
+ "exec"
121
+ ]
122
+ });
123
+ }
124
+ const model = typeof manifest.model === "string" ? manifest.model : manifest.model ? `${manifest.model.provider}/${manifest.model.name}` : "/dev/ai/.actions/chat";
125
+ const session = sessionId ? sessionId.startsWith("/") ? sessionId : `/instance/.sessions/agent/${sessionId}` : void 0;
126
+ const scopeBudget = context.afs.scope?.budget;
127
+ const resolved = require_budget.resolveBudget({
128
+ manifest: manifest.budget,
129
+ parentRemaining: scopeBudget ? Math.max(0, scopeBudget.limit - scopeBudget.consumed) : void 0
130
+ });
131
+ const tracker = require_budget.createBudgetTracker(resolved);
132
+ let system;
133
+ if (manifest.instructions) try {
134
+ const instrPath = manifest.instructions.startsWith("/") ? manifest.instructions : `/packages/${manifest.instructions}`;
135
+ const r = await effectiveAfs.read(instrPath);
136
+ system = String(r?.data?.content ?? "");
137
+ if (!system.trim()) system = void 0;
138
+ } catch {}
139
+ if (context.systemAppend) system = system ? `${system}\n\n${context.systemAppend}` : context.systemAppend;
140
+ else if (require_memory_archive.isHandoffReadThroughEnabled(manifest.memory) && !context.afs?.scope?.memoryDomain) {
141
+ const manifestDomain = manifest.memory && typeof manifest.memory === "object" ? manifest.memory.domain : void 0;
142
+ if (manifestDomain) {
143
+ const appendix = require_memory_archive.formatRecallForPrompt(await require_memory_archive.recallForHandoff({
144
+ afs: effectiveAfs,
145
+ domain: manifestDomain
146
+ }));
147
+ if (appendix) system = system ? `${system}\n\n${appendix}` : appendix;
148
+ }
149
+ }
150
+ const execArgs = {
151
+ task,
152
+ model,
153
+ tools,
154
+ budget: {
155
+ max_rounds: resolved.maxRounds,
156
+ total_tokens: resolved.totalTokens
157
+ },
158
+ session,
159
+ system,
160
+ skill_paths: manifest.skillPaths,
161
+ tool_choice: manifest.toolChoice,
162
+ exec_context: callerBlockletId ? { from: callerBlockletId } : void 0,
163
+ _scope_afs: effectiveAfs,
164
+ _parent_session: scopedParentSession,
165
+ _chain: [...chain, sessionId ?? "root"],
166
+ _abort_signal: tracker.signal
167
+ };
168
+ const streamNodeId = typeof input._stream_node_id === "string" ? input._stream_node_id : void 0;
169
+ const autoRouter = !input._on_tool_progress ? require_stream_router.createStreamProgressRouter({
170
+ afs: effectiveAfs,
171
+ sessionPath: require_stream_router.detectUISessionPath(session),
172
+ nodeId: streamNodeId
173
+ }) : null;
174
+ const baseProgress = input._on_tool_progress;
175
+ const skillStarts = !!(context.hookDispatcher && (manifest.hooks?.onSkillStart || manifest.hooks?.onSkillEnd)) ? /* @__PURE__ */ new Map() : null;
176
+ const fireSkillHooks = skillStarts ? (event) => {
177
+ const dispatcher = context.hookDispatcher;
178
+ const calls = event.calls;
179
+ if (!calls) return;
180
+ if (event.type === "tool_start") for (const c of calls) {
181
+ skillStarts.set(c.id, Date.now());
182
+ dispatcher.fireOnSkillStart(c.tool, c.args ?? {});
183
+ }
184
+ else if (event.type === "tool_result") for (const c of calls) {
185
+ const started = skillStarts.get(c.id);
186
+ const durationMs = started ? Date.now() - started : 0;
187
+ skillStarts.delete(c.id);
188
+ dispatcher.fireOnSkillEnd(c.tool, {
189
+ status: c.status === "error" ? "error" : "ok",
190
+ ...c.result !== void 0 ? { result: c.result } : {},
191
+ ...c.error !== void 0 ? { error: c.error } : {},
192
+ durationMs
193
+ });
194
+ }
195
+ } : null;
196
+ const listeners = [];
197
+ if (fireSkillHooks) listeners.push(fireSkillHooks);
198
+ if (baseProgress) listeners.push(baseProgress);
199
+ else if (autoRouter) listeners.push((event) => autoRouter.onProgress(event));
200
+ let composedProgress;
201
+ if (listeners.length === 1) composedProgress = listeners[0];
202
+ else if (listeners.length > 1) composedProgress = (event) => {
203
+ for (const l of listeners) l(event);
204
+ };
205
+ if (require_memory_archive.isMemoryArchiveEnabled(manifest.memory)) composedProgress = require_memory_archive.wrapToolProgress(composedProgress, {
206
+ afs: effectiveAfs,
207
+ session: sessionId ?? "default"
208
+ });
209
+ if (composedProgress) execArgs._on_tool_progress = composedProgress;
210
+ if (input.on_progress) execArgs.on_progress = input.on_progress;
211
+ if (typeof input._ui_session === "string") execArgs._ui_session = input._ui_session;
212
+ for (const [key, value] of Object.entries(input)) {
213
+ if (key === inputKey) continue;
214
+ if (key.startsWith("_")) continue;
215
+ if (key in execArgs) continue;
216
+ execArgs[key] = value;
217
+ }
218
+ const runId = crypto.randomUUID();
219
+ const scratchLayout = await maybeProvisionScratch(effectiveAfs, manifest, sessionId, runId);
220
+ if (scratchLayout) {
221
+ execArgs._scratch_path = scratchLayout.basePath;
222
+ execArgs._scratch_run_id = runId;
223
+ }
224
+ const result = await effectiveAfs.exec("/dev/agent/.actions/run", execArgs, {});
225
+ if (autoRouter) await autoRouter.flush();
226
+ const tokensUsed = result?.data?.total_tokens ?? result?.data?._meta?.tokens_used ?? 0;
227
+ tracker.consumeTokens(tokensUsed);
228
+ if (resolved.warnings.length > 0) {
229
+ const data = result?.data ?? {};
230
+ const meta = data._meta ?? {};
231
+ meta.warnings = [...Array.isArray(meta.warnings) ? meta.warnings : [], ...resolved.warnings];
232
+ data._meta = meta;
233
+ }
234
+ if (scratchLayout) injectScratchPath(result, scratchLayout);
235
+ return result;
236
+ };
237
+ const ashRunner = async (input, context) => {
238
+ const { manifest } = context;
239
+ const effectiveAfs = context.afs;
240
+ const chain = context.chain ?? [];
241
+ (0, _aigne_afs_agent.checkSpawnDepth)(chain, manifest.maxSpawnDepth);
242
+ const { session: sessionId, parentSession: scopedParentSession } = require_scoped_afs.resolveChildSession(context.afs, context, _aigne_afs_agent.deriveChildSession);
243
+ return await require_ash_runner.runAshAgent({
244
+ afs: effectiveAfs,
245
+ manifest,
246
+ input,
247
+ session: sessionId,
248
+ parentSession: scopedParentSession,
249
+ chain: [...chain, sessionId ?? "root"],
250
+ mountPath: context.mountPath
251
+ });
252
+ };
253
+ const teamRunner = async (input, context) => {
254
+ const { manifest } = context;
255
+ const chain = context.chain ?? [];
256
+ (0, _aigne_afs_agent.checkSpawnDepth)(chain, manifest.maxSpawnDepth);
257
+ const { session: sessionId, parentSession: scopedParentSession } = require_scoped_afs.resolveChildSession(context.afs, context, _aigne_afs_agent.deriveChildSession);
258
+ return await require_team_runner.runTeamAgent(input, {
259
+ ...context,
260
+ session: sessionId,
261
+ parentSession: scopedParentSession,
262
+ chain: [...chain, sessionId ?? "root"]
263
+ });
264
+ };
265
+ const orchestratorRunner = async (input, context) => {
266
+ const { manifest } = context;
267
+ const chain = context.chain ?? [];
268
+ (0, _aigne_afs_agent.checkSpawnDepth)(chain, manifest.maxSpawnDepth);
269
+ const { session: sessionId, parentSession: scopedParentSession } = require_scoped_afs.resolveChildSession(context.afs, context, _aigne_afs_agent.deriveChildSession);
270
+ return await require_orchestrator_runner.runOrchestratorAgent(input, {
271
+ ...context,
272
+ session: sessionId,
273
+ parentSession: scopedParentSession,
274
+ chain: [...chain, sessionId ?? "root"]
275
+ });
276
+ };
277
+ const runners = {
278
+ ai: withLifecycleHooks(aiRunner),
279
+ ash: withLifecycleHooks(ashRunner),
280
+ team: withLifecycleHooks(teamRunner),
281
+ orchestrator: withLifecycleHooks(orchestratorRunner),
282
+ code: withLifecycleHooks(require_code_runner.codeRunner)
283
+ };
284
+ function getRunnerForType(type) {
285
+ const runner = runners[type];
286
+ if (!runner) throw new Error(`RUNNER_NOT_IMPLEMENTED: agent type "${type}" is not yet supported`);
287
+ return runner;
288
+ }
289
+ function registerAgentActions(runtimeAFS, manifest, mountPath, options) {
290
+ const handlers = require_agent_action.createAgentActionHandlers(manifest, mountPath, { actionPrefix: options?.actionPrefix });
291
+ const afs = runtimeAFS;
292
+ if (typeof afs.registerCustomAction !== "function") return;
293
+ const prefix = options?.actionPrefix;
294
+ const runKey = prefix ? `${prefix}-run` : "run";
295
+ const cancelKey = prefix ? `${prefix}-cancel` : "cancel";
296
+ const statusKey = prefix ? `${prefix}-status` : "status";
297
+ afs.registerCustomAction(runKey, handlers.run.entry, async (args) => {
298
+ return handlers.run.handler(args, {
299
+ afs: runtimeAFS,
300
+ mountPath,
301
+ manifest
302
+ });
303
+ });
304
+ afs.registerCustomAction(cancelKey, handlers.cancel.entry, async (args) => {
305
+ return handlers.cancel.handler(args);
306
+ });
307
+ afs.registerCustomAction(statusKey, handlers.status.entry, async (args) => {
308
+ return handlers.status.handler(args);
309
+ });
310
+ }
311
+
312
+ //#endregion
313
+ exports.getRunnerForType = getRunnerForType;
314
+ exports.registerAgentActions = registerAgentActions;
@@ -0,0 +1,52 @@
1
+ import { HookDispatcher } from "../agent-runners/hooks.cjs";
2
+ import { AFSExecResult, AFSRoot, AgentManifest } from "@aigne/afs";
3
+
4
+ //#region src/program/agent-runner-registry.d.ts
5
+ /**
6
+ * Runner context — shape consumed by every agent runner.
7
+ *
8
+ * Phase 6 collapsed the grab-bag of parent-projection fields now that
9
+ * `AgentScope` carries the equivalent state:
10
+ *
11
+ * - `context.afs.scope.allowedTools` — tool whitelist
12
+ * - `context.afs.scope.budget` — per-scope budget limit/consumed
13
+ * - `context.afs.scope.memoryDomain` — per-scope memory provider
14
+ * - `context.afs.scope.chainDepth` — spawn-chain depth counter
15
+ *
16
+ * The remaining `mountPath` / `session` / `parentSession` / `chain` /
17
+ * `systemAppend` fields still live on the context because their natural
18
+ * home on `AgentScope` hasn't been added yet — see the follow-up note in
19
+ * `planning/agent-runtime-afs-first/tasks.md` (P7: scope schema additions).
20
+ */
21
+ interface RunnerContext {
22
+ afs: AFSRoot;
23
+ /** Blocklet mount root — used for instructions / script path resolution. */
24
+ mountPath: string;
25
+ manifest: AgentManifest;
26
+ /** @deprecated (P7) read from `ctx.afs.scope.session` once scope.session is the only source. */
27
+ session?: string;
28
+ /** @deprecated (P7) read from `ctx.afs.scope.parentSession`. */
29
+ parentSession?: string;
30
+ /** @deprecated (P7) derive from `ctx.afs.scope.chainDepth`. */
31
+ chain?: string[];
32
+ hookDispatcher?: HookDispatcher;
33
+ /** @deprecated (P7) caller-supplied system-prompt suffix; moves to scope in P7. */
34
+ systemAppend?: string;
35
+ }
36
+ type AgentRunner = (input: Record<string, unknown>, context: RunnerContext) => Promise<AFSExecResult>;
37
+ declare function getRunnerForType(type: string): AgentRunner;
38
+ /**
39
+ * Options for `registerAgentActions`.
40
+ *
41
+ * `actionPrefix` lets one blocklet's runtime AFS host many independent
42
+ * agents (e.g. nested manifests under `agents/<n>/`). Each prefix
43
+ * registers its own `${prefix}-run`/`${prefix}-cancel`/`${prefix}-status`
44
+ * customAction keys, so they coexist without colliding on the bare names.
45
+ */
46
+ interface RegisterAgentActionsOptions {
47
+ actionPrefix?: string;
48
+ }
49
+ declare function registerAgentActions(runtimeAFS: AFSRoot, manifest: AgentManifest, mountPath: string, options?: RegisterAgentActionsOptions): void;
50
+ //#endregion
51
+ export { AgentRunner, RegisterAgentActionsOptions, RunnerContext, getRunnerForType, registerAgentActions };
52
+ //# sourceMappingURL=agent-runner-registry.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-runner-registry.d.cts","names":[],"sources":["../../src/program/agent-runner-registry.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;UAkDiB,aAAA;EACf,GAAA,EAAK,OAAA;EA6EgB;EA3ErB,SAAA;EACA,QAAA,EAAU,aAAA;EA4ED;EA1ET,OAAA;EA2EG;EAzEH,aAAA;EAyEU;EAvEV,KAAA;EACA,cAAA,GAAiB,cAAA;EAqER;EAnET,YAAA;AAAA;AAAA,KAiEU,WAAA,IACV,KAAA,EAAO,MAAA,mBACP,OAAA,EAAS,aAAA,KACN,OAAA,CAAQ,aAAA;AAAA,iBA6aG,gBAAA,CAAiB,IAAA,WAAe,WAAA;;AAAhD;;;;;AAgBA;;UAAiB,2BAAA;EACf,YAAA;AAAA;AAAA,iBAGc,oBAAA,CACd,UAAA,EAAY,OAAA,EACZ,QAAA,EAAU,aAAA,EACV,SAAA,UACA,OAAA,GAAU,2BAAA"}
@@ -0,0 +1,52 @@
1
+ import { HookDispatcher } from "../agent-runners/hooks.mjs";
2
+ import { AFSExecResult, AFSRoot, AgentManifest } from "@aigne/afs";
3
+
4
+ //#region src/program/agent-runner-registry.d.ts
5
+ /**
6
+ * Runner context — shape consumed by every agent runner.
7
+ *
8
+ * Phase 6 collapsed the grab-bag of parent-projection fields now that
9
+ * `AgentScope` carries the equivalent state:
10
+ *
11
+ * - `context.afs.scope.allowedTools` — tool whitelist
12
+ * - `context.afs.scope.budget` — per-scope budget limit/consumed
13
+ * - `context.afs.scope.memoryDomain` — per-scope memory provider
14
+ * - `context.afs.scope.chainDepth` — spawn-chain depth counter
15
+ *
16
+ * The remaining `mountPath` / `session` / `parentSession` / `chain` /
17
+ * `systemAppend` fields still live on the context because their natural
18
+ * home on `AgentScope` hasn't been added yet — see the follow-up note in
19
+ * `planning/agent-runtime-afs-first/tasks.md` (P7: scope schema additions).
20
+ */
21
+ interface RunnerContext {
22
+ afs: AFSRoot;
23
+ /** Blocklet mount root — used for instructions / script path resolution. */
24
+ mountPath: string;
25
+ manifest: AgentManifest;
26
+ /** @deprecated (P7) read from `ctx.afs.scope.session` once scope.session is the only source. */
27
+ session?: string;
28
+ /** @deprecated (P7) read from `ctx.afs.scope.parentSession`. */
29
+ parentSession?: string;
30
+ /** @deprecated (P7) derive from `ctx.afs.scope.chainDepth`. */
31
+ chain?: string[];
32
+ hookDispatcher?: HookDispatcher;
33
+ /** @deprecated (P7) caller-supplied system-prompt suffix; moves to scope in P7. */
34
+ systemAppend?: string;
35
+ }
36
+ type AgentRunner = (input: Record<string, unknown>, context: RunnerContext) => Promise<AFSExecResult>;
37
+ declare function getRunnerForType(type: string): AgentRunner;
38
+ /**
39
+ * Options for `registerAgentActions`.
40
+ *
41
+ * `actionPrefix` lets one blocklet's runtime AFS host many independent
42
+ * agents (e.g. nested manifests under `agents/<n>/`). Each prefix
43
+ * registers its own `${prefix}-run`/`${prefix}-cancel`/`${prefix}-status`
44
+ * customAction keys, so they coexist without colliding on the bare names.
45
+ */
46
+ interface RegisterAgentActionsOptions {
47
+ actionPrefix?: string;
48
+ }
49
+ declare function registerAgentActions(runtimeAFS: AFSRoot, manifest: AgentManifest, mountPath: string, options?: RegisterAgentActionsOptions): void;
50
+ //#endregion
51
+ export { AgentRunner, RegisterAgentActionsOptions, RunnerContext, getRunnerForType, registerAgentActions };
52
+ //# sourceMappingURL=agent-runner-registry.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-runner-registry.d.mts","names":[],"sources":["../../src/program/agent-runner-registry.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;UAkDiB,aAAA;EACf,GAAA,EAAK,OAAA;EA6EgB;EA3ErB,SAAA;EACA,QAAA,EAAU,aAAA;EA4ED;EA1ET,OAAA;EA2EG;EAzEH,aAAA;EAyEU;EAvEV,KAAA;EACA,cAAA,GAAiB,cAAA;EAqER;EAnET,YAAA;AAAA;AAAA,KAiEU,WAAA,IACV,KAAA,EAAO,MAAA,mBACP,OAAA,EAAS,aAAA,KACN,OAAA,CAAQ,aAAA;AAAA,iBA6aG,gBAAA,CAAiB,IAAA,WAAe,WAAA;;AAAhD;;;;;AAgBA;;UAAiB,2BAAA;EACf,YAAA;AAAA;AAAA,iBAGc,oBAAA,CACd,UAAA,EAAY,OAAA,EACZ,QAAA,EAAU,aAAA,EACV,SAAA,UACA,OAAA,GAAU,2BAAA"}