@botbotgo/agent-harness 0.0.309 → 0.0.311

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 (195) hide show
  1. package/README.md +14 -0
  2. package/README.zh.md +14 -0
  3. package/dist/acp.d.ts +1 -116
  4. package/dist/acp.js +1 -310
  5. package/dist/api.d.ts +1 -1
  6. package/dist/api.js +1 -1
  7. package/dist/cli/chat-interactive.d.ts +24 -0
  8. package/dist/cli/chat-interactive.js +244 -0
  9. package/dist/cli/chat-rendering.d.ts +9 -0
  10. package/dist/cli/chat-rendering.js +102 -0
  11. package/dist/cli/chat-stream.d.ts +23 -0
  12. package/dist/cli/chat-stream.js +330 -0
  13. package/dist/cli/chat-ui.d.ts +20 -0
  14. package/dist/cli/chat-ui.js +198 -0
  15. package/dist/cli/chat-workspace.d.ts +15 -0
  16. package/dist/cli/chat-workspace.js +205 -0
  17. package/dist/cli/main.d.ts +52 -0
  18. package/dist/cli/main.js +323 -0
  19. package/dist/cli/managed-service-commands.d.ts +23 -0
  20. package/dist/cli/managed-service-commands.js +63 -0
  21. package/dist/cli/managed-service.d.ts +27 -0
  22. package/dist/cli/managed-service.js +61 -0
  23. package/dist/cli/options-init-chat.d.ts +16 -0
  24. package/dist/cli/options-init-chat.js +108 -0
  25. package/dist/cli/options-runtime.d.ts +27 -0
  26. package/dist/cli/options-runtime.js +158 -0
  27. package/dist/cli/options-serve.d.ts +24 -0
  28. package/dist/cli/options-serve.js +166 -0
  29. package/dist/cli/options.d.ts +5 -0
  30. package/dist/cli/options.js +47 -0
  31. package/dist/cli/process-guards.d.ts +14 -0
  32. package/dist/cli/process-guards.js +139 -0
  33. package/dist/cli/request-tree.d.ts +12 -0
  34. package/dist/cli/request-tree.js +296 -0
  35. package/dist/cli/runtime-commands.d.ts +15 -0
  36. package/dist/cli/runtime-commands.js +247 -0
  37. package/dist/cli/runtime-output.d.ts +5 -0
  38. package/dist/cli/runtime-output.js +124 -0
  39. package/dist/cli/server-commands.d.ts +36 -0
  40. package/dist/cli/server-commands.js +250 -0
  41. package/dist/cli/workspace.d.ts +6 -0
  42. package/dist/cli/workspace.js +71 -0
  43. package/dist/cli.d.ts +1 -77
  44. package/dist/cli.js +2 -3023
  45. package/dist/client/acp.d.ts +1 -50
  46. package/dist/client/acp.js +1 -219
  47. package/dist/client/in-process.d.ts +5 -5
  48. package/dist/client/index.d.ts +2 -2
  49. package/dist/client/index.js +1 -1
  50. package/dist/contracts/runtime-evaluation.d.ts +103 -0
  51. package/dist/contracts/runtime-evaluation.js +1 -0
  52. package/dist/contracts/runtime-memory.d.ts +162 -0
  53. package/dist/contracts/runtime-memory.js +1 -0
  54. package/dist/contracts/runtime-observability.d.ts +248 -0
  55. package/dist/contracts/runtime-observability.js +1 -0
  56. package/dist/contracts/runtime-requests.d.ts +342 -0
  57. package/dist/contracts/runtime-requests.js +1 -0
  58. package/dist/contracts/runtime-scheduling.d.ts +146 -0
  59. package/dist/contracts/runtime-scheduling.js +1 -0
  60. package/dist/contracts/runtime.d.ts +5 -1042
  61. package/dist/contracts/runtime.js +27 -1
  62. package/dist/flow/build-flow-graph.js +4 -875
  63. package/dist/flow/flow-graph-normalization.d.ts +56 -0
  64. package/dist/flow/flow-graph-normalization.js +214 -0
  65. package/dist/flow/flow-graph-runtime.d.ts +8 -0
  66. package/dist/flow/flow-graph-runtime.js +107 -0
  67. package/dist/flow/flow-graph-upstream.d.ts +18 -0
  68. package/dist/flow/flow-graph-upstream.js +498 -0
  69. package/dist/flow/types.d.ts +1 -1
  70. package/dist/index.d.ts +3 -3
  71. package/dist/index.js +1 -1
  72. package/dist/init-project.d.ts +1 -12
  73. package/dist/init-project.js +1 -651
  74. package/dist/{procedural → knowledge/procedural}/manager.d.ts +3 -3
  75. package/dist/{procedural → knowledge/procedural}/manager.js +6 -6
  76. package/dist/mcp.d.ts +2 -76
  77. package/dist/mcp.js +2 -428
  78. package/dist/package-version.d.ts +1 -1
  79. package/dist/package-version.js +1 -1
  80. package/dist/persistence/file-store.js +1 -1
  81. package/dist/persistence/sqlite-runtime.d.ts +19 -0
  82. package/dist/persistence/sqlite-runtime.js +86 -0
  83. package/dist/persistence/sqlite-store.js +11 -99
  84. package/dist/{request-events.d.ts → projections/request-events.d.ts} +1 -1
  85. package/dist/{upstream-events.js → projections/upstream-events.js} +1 -1
  86. package/dist/protocol/a2a/http-discovery.d.ts +39 -0
  87. package/dist/protocol/a2a/http-discovery.js +178 -0
  88. package/dist/protocol/a2a/http-rpc.d.ts +28 -0
  89. package/dist/protocol/a2a/http-rpc.js +623 -0
  90. package/dist/protocol/a2a/http.d.ts +72 -1
  91. package/dist/protocol/a2a/http.js +14 -1124
  92. package/dist/protocol/a2a/task-state.d.ts +29 -0
  93. package/dist/protocol/a2a/task-state.js +317 -0
  94. package/dist/protocol/acp/client.js +1 -1
  95. package/dist/protocol/acp/harness-client.d.ts +50 -0
  96. package/dist/protocol/acp/harness-client.js +219 -0
  97. package/dist/protocol/acp/server.d.ts +116 -0
  98. package/dist/protocol/acp/server.js +310 -0
  99. package/dist/protocol/ag-ui/http.js +1 -1
  100. package/dist/protocol/mcp/server.d.ts +76 -0
  101. package/dist/protocol/mcp/server.js +428 -0
  102. package/dist/resource/backend/workspace-scoped-backend.d.ts +40 -0
  103. package/dist/resource/backend/workspace-scoped-backend.js +296 -0
  104. package/dist/resource/mcp/tool-support.d.ts +35 -0
  105. package/dist/resource/mcp/tool-support.js +296 -0
  106. package/dist/resource/mcp-tool-support.d.ts +2 -35
  107. package/dist/resource/mcp-tool-support.js +2 -296
  108. package/dist/resource/providers/resource-provider.d.ts +22 -0
  109. package/dist/resource/providers/resource-provider.js +215 -0
  110. package/dist/resource/resource-impl.d.ts +3 -33
  111. package/dist/resource/resource-impl.js +2 -808
  112. package/dist/resource/resource-types.d.ts +33 -0
  113. package/dist/resource/resource-types.js +1 -0
  114. package/dist/resource/tools/function-tool-resolver.d.ts +2 -0
  115. package/dist/resource/tools/function-tool-resolver.js +306 -0
  116. package/dist/runtime/adapter/middleware-assembly.js +1 -1
  117. package/dist/runtime/adapter/model/invocation-request.js +2 -2
  118. package/dist/runtime/adapter/model/message-assembly.js +1 -1
  119. package/dist/runtime/agent-runtime-adapter.d.ts +3 -63
  120. package/dist/runtime/agent-runtime-adapter.js +7 -235
  121. package/dist/runtime/agent-runtime-assembly.d.ts +67 -0
  122. package/dist/runtime/agent-runtime-assembly.js +211 -0
  123. package/dist/runtime/harness/background-runtime.d.ts +1 -1
  124. package/dist/runtime/harness/events/event-sink.js +1 -1
  125. package/dist/runtime/harness/events/runtime-event-operations.d.ts +1 -1
  126. package/dist/runtime/harness/events/streaming.js +1 -1
  127. package/dist/runtime/harness/public-shapes.d.ts +43 -0
  128. package/dist/runtime/harness/public-shapes.js +186 -0
  129. package/dist/runtime/harness/run/inspection.js +2 -2
  130. package/dist/runtime/harness/run/resources.js +1 -1
  131. package/dist/runtime/harness/run/surface-semantics.js +1 -1
  132. package/dist/runtime/harness/system/inventory.d.ts +1 -1
  133. package/dist/runtime/harness/system/inventory.js +2 -2
  134. package/dist/runtime/harness/system/policy-engine.js +1 -1
  135. package/dist/runtime/harness/system/runtime-memory-manager.js +1 -1
  136. package/dist/runtime/harness/system/skill-requirements.d.ts +1 -1
  137. package/dist/runtime/harness/system/skill-requirements.js +1 -1
  138. package/dist/runtime/harness.d.ts +2 -2
  139. package/dist/runtime/harness.js +7 -191
  140. package/dist/runtime/maintenance/checkpoint-maintenance.js +1 -1
  141. package/dist/runtime/maintenance/runtime-record-maintenance.js +1 -1
  142. package/dist/runtime/parsing/output-content.d.ts +11 -0
  143. package/dist/runtime/parsing/output-content.js +442 -0
  144. package/dist/runtime/parsing/output-parsing.d.ts +3 -29
  145. package/dist/runtime/parsing/output-parsing.js +3 -806
  146. package/dist/runtime/parsing/output-recovery.d.ts +14 -0
  147. package/dist/runtime/parsing/output-recovery.js +288 -0
  148. package/dist/runtime/parsing/output-tool-args.d.ts +4 -0
  149. package/dist/runtime/parsing/output-tool-args.js +120 -0
  150. package/dist/runtime/support/runtime-factories.js +1 -1
  151. package/dist/scaffold/init-project.d.ts +12 -0
  152. package/dist/scaffold/init-project.js +651 -0
  153. package/dist/{extensions.d.ts → tooling/extensions.d.ts} +1 -1
  154. package/dist/{extensions.js → tooling/extensions.js} +3 -3
  155. package/dist/{tool-modules.d.ts → tooling/module-loader.d.ts} +1 -1
  156. package/dist/{tool-modules.js → tooling/module-loader.js} +2 -2
  157. package/dist/workspace/agent-binding-compiler.js +2 -2
  158. package/dist/workspace/compile.js +2 -2
  159. package/dist/workspace/object-loader-paths.d.ts +11 -0
  160. package/dist/workspace/object-loader-paths.js +75 -0
  161. package/dist/workspace/object-loader-readers.d.ts +21 -0
  162. package/dist/workspace/object-loader-readers.js +187 -0
  163. package/dist/workspace/object-loader.d.ts +0 -1
  164. package/dist/workspace/object-loader.js +6 -260
  165. package/dist/workspace/resource-compilers.js +1 -1
  166. package/dist/workspace/support/discovery.js +1 -1
  167. package/package.json +1 -1
  168. package/dist/runtime/adapter/index.d.ts +0 -13
  169. package/dist/runtime/adapter/index.js +0 -13
  170. package/dist/runtime/harness/index.d.ts +0 -19
  171. package/dist/runtime/harness/index.js +0 -19
  172. package/dist/runtime/maintenance/index.d.ts +0 -4
  173. package/dist/runtime/maintenance/index.js +0 -4
  174. package/dist/runtime/parsing/index.d.ts +0 -2
  175. package/dist/runtime/parsing/index.js +0 -2
  176. package/dist/runtime/support/index.d.ts +0 -4
  177. package/dist/runtime/support/index.js +0 -4
  178. package/dist/workspace/support/index.d.ts +0 -2
  179. package/dist/workspace/support/index.js +0 -2
  180. /package/dist/{procedural → knowledge/procedural}/config.d.ts +0 -0
  181. /package/dist/{procedural → knowledge/procedural}/config.js +0 -0
  182. /package/dist/{procedural → knowledge/procedural}/index.d.ts +0 -0
  183. /package/dist/{procedural → knowledge/procedural}/index.js +0 -0
  184. /package/dist/{presentation.d.ts → projections/presentation.d.ts} +0 -0
  185. /package/dist/{presentation.js → projections/presentation.js} +0 -0
  186. /package/dist/{request-events.js → projections/request-events.js} +0 -0
  187. /package/dist/{upstream-events.d.ts → projections/upstream-events.d.ts} +0 -0
  188. /package/dist/runtime/{support → env}/runtime-env.d.ts +0 -0
  189. /package/dist/runtime/{support → env}/runtime-env.js +0 -0
  190. /package/dist/runtime/{support → layout}/runtime-layout.d.ts +0 -0
  191. /package/dist/runtime/{support → layout}/runtime-layout.js +0 -0
  192. /package/dist/runtime/{support → prompts}/runtime-prompts.d.ts +0 -0
  193. /package/dist/runtime/{support → prompts}/runtime-prompts.js +0 -0
  194. /package/dist/runtime/{support → skills}/skill-metadata.d.ts +0 -0
  195. /package/dist/runtime/{support → skills}/skill-metadata.js +0 -0
@@ -0,0 +1,498 @@
1
+ import { createUpstreamTimelineReducer } from "../projections/upstream-events.js";
2
+ import { asObject, buildAttemptKey, deriveAgentName, deriveNodeKindFromProjection, deriveStatusFromProjection, extractUpstreamEventEnvelope, normalizeAttemptLabel, normalizeToolIdentity, readRequestId, readSessionId, slugify, titleCase, } from "./flow-graph-normalization.js";
3
+ import { buildSurfaceId, resolveSurfaceAction, stripStepPrefix, } from "../runtime/harness/run/surface-semantics.js";
4
+ function buildSurfaceStepLabel(surfaceItem) {
5
+ const kind = surfaceItem.kind;
6
+ const name = typeof surfaceItem.name === "string" && surfaceItem.name.trim().length > 0
7
+ ? surfaceItem.name.trim()
8
+ : typeof surfaceItem.id === "string"
9
+ ? surfaceItem.id
10
+ : "";
11
+ const status = surfaceItem.status;
12
+ if (!kind || !name || !status || (status !== "started" && status !== "completed" && status !== "failed")) {
13
+ return null;
14
+ }
15
+ if (kind === "llm") {
16
+ return status === "started" ? `Calling LLM ${name}` : `Completed LLM ${name}`;
17
+ }
18
+ if (kind === "tool") {
19
+ if (status === "failed") {
20
+ return `Tool ${name} failed`;
21
+ }
22
+ return status === "started" ? `Calling tool ${name}` : `Completed tool ${name}`;
23
+ }
24
+ if (kind === "skill") {
25
+ return status === "started" ? `Calling skill ${name}` : `Completed skill ${name}`;
26
+ }
27
+ if (kind === "memory") {
28
+ return status === "started" ? `Accessing memory ${name}` : `Completed memory ${name}`;
29
+ }
30
+ return null;
31
+ }
32
+ function createDelegationNodeFromSurfaceItem(surfaceItem, fallbackAgentId, fallbackAgentName, sourceEventId, ordinal) {
33
+ if (surfaceItem.kind !== "agent") {
34
+ return null;
35
+ }
36
+ const toAgentId = typeof surfaceItem.agentId === "string" && surfaceItem.agentId.trim().length > 0
37
+ ? surfaceItem.agentId.trim()
38
+ : fallbackAgentId;
39
+ const toAgentName = deriveAgentName(toAgentId, typeof surfaceItem.agentName === "string" ? surfaceItem.agentName : undefined);
40
+ const fromAgentId = typeof surfaceItem.ownerAgentId === "string" && surfaceItem.ownerAgentId.trim().length > 0
41
+ ? surfaceItem.ownerAgentId.trim()
42
+ : fallbackAgentId;
43
+ const fromAgentName = deriveAgentName(fromAgentId, typeof surfaceItem.ownerAgentName === "string" ? surfaceItem.ownerAgentName : fallbackAgentName);
44
+ return {
45
+ id: `delegate:${slugify(fromAgentId)}:${slugify(toAgentId)}:${ordinal}`,
46
+ layer: "execution",
47
+ kind: "agent",
48
+ label: `Delegate to ${titleCase(typeof surfaceItem.name === "string" ? surfaceItem.name : toAgentId)}`,
49
+ status: surfaceItem.status === "failed" ? "failed" : surfaceItem.status === "started" ? "started" : "completed",
50
+ sessionId: "",
51
+ requestId: "",
52
+ agentId: toAgentId,
53
+ agentName: toAgentName,
54
+ sourceEventIds: [sourceEventId],
55
+ detail: {
56
+ fromAgentId,
57
+ fromAgentName,
58
+ toAgentId,
59
+ toAgentName,
60
+ ...(typeof surfaceItem.action === "string" ? { action: surfaceItem.action } : {}),
61
+ },
62
+ };
63
+ }
64
+ function extractDelegatedAgentId(event) {
65
+ const typed = asObject(event);
66
+ if (!typed) {
67
+ return null;
68
+ }
69
+ const eventName = typeof typed.event === "string" ? typed.event : "";
70
+ const toolName = typeof typed.name === "string" ? typed.name : "";
71
+ if (toolName !== "task" || (eventName !== "on_tool_start" && !(eventName === "on_chain_start" && typed.run_type === "tool"))) {
72
+ return null;
73
+ }
74
+ const data = asObject(typed.data);
75
+ const input = asObject(data?.input);
76
+ const nestedInput = typeof input?.input === "string"
77
+ ? asObject(JSON.parse(input.input))
78
+ : asObject(input?.input);
79
+ const subagentType = typeof input?.subagent_type === "string"
80
+ ? input.subagent_type
81
+ : typeof input?.subagentType === "string"
82
+ ? input.subagentType
83
+ : typeof nestedInput?.subagent_type === "string"
84
+ ? nestedInput.subagent_type
85
+ : typeof nestedInput?.subagentType === "string"
86
+ ? nestedInput.subagentType
87
+ : null;
88
+ return subagentType && subagentType.trim().length > 0 ? subagentType.trim() : null;
89
+ }
90
+ export function convertUpstreamEventsWithAgents(upstreamEvents, initialAgentId) {
91
+ const reducer = createUpstreamTimelineReducer();
92
+ const projections = [];
93
+ const delegationNodes = [];
94
+ let currentAgentId = initialAgentId;
95
+ let currentAgentName = deriveAgentName(initialAgentId);
96
+ let ordinal = 0;
97
+ upstreamEvents.forEach((event, index) => {
98
+ const sourceEventId = `upstream:${index + 1}`;
99
+ const envelope = extractUpstreamEventEnvelope(event);
100
+ if (envelope.agentId && envelope.agentId !== currentAgentId) {
101
+ currentAgentId = envelope.agentId;
102
+ currentAgentName = deriveAgentName(currentAgentId, envelope.agentName);
103
+ }
104
+ else if (envelope.agentName) {
105
+ currentAgentName = deriveAgentName(currentAgentId, envelope.agentName);
106
+ }
107
+ const emitted = reducer.consume(envelope.event);
108
+ for (const projection of emitted) {
109
+ if (envelope.surfaceItem && projection.type === "step") {
110
+ continue;
111
+ }
112
+ projections.push({
113
+ projection,
114
+ agentId: currentAgentId,
115
+ agentName: currentAgentName,
116
+ sourceEventId,
117
+ });
118
+ }
119
+ if (envelope.surfaceItem) {
120
+ const delegationNode = createDelegationNodeFromSurfaceItem(envelope.surfaceItem, currentAgentId, currentAgentName, sourceEventId, ordinal + 1);
121
+ if (delegationNode) {
122
+ ordinal += 1;
123
+ delegationNodes.push(delegationNode);
124
+ }
125
+ else {
126
+ const step = buildSurfaceStepLabel(envelope.surfaceItem);
127
+ if (step) {
128
+ projections.push({
129
+ projection: {
130
+ type: "step",
131
+ key: `surface:${index + 1}:${envelope.surfaceItem.id ?? step}`,
132
+ category: envelope.surfaceItem.kind,
133
+ status: envelope.surfaceItem.status,
134
+ step,
135
+ },
136
+ agentId: currentAgentId,
137
+ agentName: currentAgentName,
138
+ sourceEventId,
139
+ });
140
+ }
141
+ }
142
+ }
143
+ if (envelope.surfaceItem) {
144
+ return;
145
+ }
146
+ const delegatedAgentId = extractDelegatedAgentId(envelope.event);
147
+ if (!delegatedAgentId || delegatedAgentId === currentAgentId) {
148
+ return;
149
+ }
150
+ const delegatedAgentName = deriveAgentName(delegatedAgentId);
151
+ ordinal += 1;
152
+ delegationNodes.push({
153
+ id: `delegate:${slugify(initialAgentId)}:${slugify(delegatedAgentId)}:${ordinal}`,
154
+ layer: "execution",
155
+ kind: "agent",
156
+ label: `Delegate to ${titleCase(delegatedAgentId)}`,
157
+ status: "completed",
158
+ sessionId: "",
159
+ requestId: "",
160
+ agentId: delegatedAgentId,
161
+ agentName: delegatedAgentName,
162
+ sourceEventIds: [sourceEventId],
163
+ detail: {
164
+ fromAgentId: currentAgentId,
165
+ fromAgentName: currentAgentName,
166
+ toAgentId: delegatedAgentId,
167
+ toAgentName: delegatedAgentName,
168
+ },
169
+ });
170
+ currentAgentId = delegatedAgentId;
171
+ currentAgentName = delegatedAgentName;
172
+ });
173
+ return { projections, delegationNodes };
174
+ }
175
+ function selectInitialGroup(groups) {
176
+ return groups.find((group) => group.kind === "segment") ?? groups[0] ?? null;
177
+ }
178
+ export function buildAttempts(projectionRecords, delegationNodes, runtimeGroups, sessionId, requestId) {
179
+ const nodes = [];
180
+ const edges = [];
181
+ const groups = [];
182
+ const attempts = [];
183
+ const activeAttemptsByKey = new Map();
184
+ const toolAttemptsByName = new Map();
185
+ const attemptSetGroups = new Map();
186
+ let currentGroup = selectInitialGroup(runtimeGroups);
187
+ let awaitingResumeAfterApproval = false;
188
+ let previousAttempt = null;
189
+ let ordinal = 0;
190
+ let pendingDelegationNode = null;
191
+ let delegationIndex = 0;
192
+ const segmentGroups = runtimeGroups.filter((group) => group.kind === "segment");
193
+ let nextSegmentIndex = currentGroup && currentGroup.kind === "segment"
194
+ ? Math.max(segmentGroups.findIndex((group) => group.id === currentGroup?.id), 0)
195
+ : 0;
196
+ function promoteToNextSegment() {
197
+ if (nextSegmentIndex + 1 < segmentGroups.length) {
198
+ nextSegmentIndex += 1;
199
+ currentGroup = segmentGroups[nextSegmentIndex] ?? currentGroup;
200
+ }
201
+ }
202
+ function createAttempt(kind, label, projection, agentId, agentName) {
203
+ ordinal += 1;
204
+ const attempt = {
205
+ id: `attempt:${requestId}:${slugify(kind)}:${slugify(label)}:${ordinal}`,
206
+ kind,
207
+ label,
208
+ status: deriveStatusFromProjection(projection),
209
+ agentId,
210
+ agentName,
211
+ groupId: currentGroup?.id,
212
+ sourceEventIds: [],
213
+ attemptKey: buildAttemptKey(kind, label, currentGroup?.id),
214
+ detail: {},
215
+ projectionKeys: [],
216
+ ...(projection.type === "tool-result" ? { toolName: projection.toolName } : {}),
217
+ };
218
+ attempts.push(attempt);
219
+ if (kind === "tool" || (projection.type === "tool-result" && projection.toolName)) {
220
+ const toolName = projection.type === "tool-result"
221
+ ? normalizeToolIdentity(projection.toolName)
222
+ : normalizeToolIdentity(label.replace(/^Calling tool\s+/i, ""));
223
+ const existing = toolAttemptsByName.get(toolName) ?? [];
224
+ if (existing.length > 0) {
225
+ const prior = existing[existing.length - 1];
226
+ const edgeKind = prior.status === "failed" ? "retry" : "fallback";
227
+ edges.push({
228
+ id: `edge:${prior.id}->${attempt.id}`,
229
+ from: prior.id,
230
+ to: attempt.id,
231
+ kind: edgeKind,
232
+ sourceEventIds: [],
233
+ confidence: 0.55,
234
+ });
235
+ }
236
+ existing.push(attempt);
237
+ toolAttemptsByName.set(toolName, existing);
238
+ }
239
+ return attempt;
240
+ }
241
+ for (const record of projectionRecords) {
242
+ const projection = record.projection;
243
+ if (!pendingDelegationNode
244
+ && delegationIndex < delegationNodes.length
245
+ && delegationNodes[delegationIndex]?.agentId === record.agentId
246
+ && (!previousAttempt || previousAttempt.agentId !== record.agentId)) {
247
+ const sourceNode = delegationNodes[delegationIndex];
248
+ delegationIndex += 1;
249
+ pendingDelegationNode = {
250
+ ...sourceNode,
251
+ sessionId,
252
+ requestId,
253
+ groupId: currentGroup?.id,
254
+ };
255
+ nodes.push(pendingDelegationNode);
256
+ if (previousAttempt) {
257
+ edges.push({
258
+ id: `edge:${previousAttempt.id}->${pendingDelegationNode.id}`,
259
+ from: previousAttempt.id,
260
+ to: pendingDelegationNode.id,
261
+ kind: "spawn",
262
+ label: "delegate",
263
+ sourceEventIds: [...pendingDelegationNode.sourceEventIds],
264
+ confidence: 0.9,
265
+ });
266
+ }
267
+ else if (currentGroup?.anchorNodeId) {
268
+ edges.push({
269
+ id: `edge:${currentGroup.anchorNodeId}->${pendingDelegationNode.id}`,
270
+ from: currentGroup.anchorNodeId,
271
+ to: pendingDelegationNode.id,
272
+ kind: "spawn",
273
+ label: "delegate",
274
+ sourceEventIds: [...pendingDelegationNode.sourceEventIds],
275
+ confidence: 0.9,
276
+ });
277
+ }
278
+ }
279
+ if (previousAttempt
280
+ && previousAttempt.agentId
281
+ && record.agentId !== previousAttempt.agentId
282
+ && delegationIndex < delegationNodes.length) {
283
+ const sourceNode = delegationNodes[delegationIndex];
284
+ delegationIndex += 1;
285
+ pendingDelegationNode = {
286
+ ...sourceNode,
287
+ sessionId,
288
+ requestId,
289
+ groupId: currentGroup?.id,
290
+ };
291
+ nodes.push(pendingDelegationNode);
292
+ edges.push({
293
+ id: `edge:${previousAttempt.id}->${pendingDelegationNode.id}`,
294
+ from: previousAttempt.id,
295
+ to: pendingDelegationNode.id,
296
+ kind: "spawn",
297
+ label: "delegate",
298
+ sourceEventIds: [...pendingDelegationNode.sourceEventIds],
299
+ confidence: 0.9,
300
+ });
301
+ }
302
+ if (projection.type === "thinking") {
303
+ ordinal += 1;
304
+ const detailNode = {
305
+ id: `detail:${requestId}:thinking:${ordinal}`,
306
+ layer: "detail",
307
+ kind: "thinking",
308
+ label: "Model reasoning",
309
+ status: "completed",
310
+ sessionId,
311
+ requestId,
312
+ groupId: currentGroup?.id,
313
+ sourceEventIds: [],
314
+ detail: { text: projection.text },
315
+ };
316
+ nodes.push(detailNode);
317
+ if (previousAttempt) {
318
+ edges.push({
319
+ id: `edge:${previousAttempt.id}->${detailNode.id}`,
320
+ from: previousAttempt.id,
321
+ to: detailNode.id,
322
+ kind: "result",
323
+ sourceEventIds: [],
324
+ confidence: 0.6,
325
+ });
326
+ }
327
+ continue;
328
+ }
329
+ const kind = deriveNodeKindFromProjection(projection);
330
+ const label = normalizeAttemptLabel(kind, projection);
331
+ if (kind === "approval") {
332
+ const activeApproval = runtimeGroups.find((group) => group.kind === "approval-window");
333
+ if (activeApproval) {
334
+ currentGroup = activeApproval;
335
+ }
336
+ awaitingResumeAfterApproval = true;
337
+ }
338
+ else if (awaitingResumeAfterApproval && currentGroup?.kind === "approval-window") {
339
+ promoteToNextSegment();
340
+ awaitingResumeAfterApproval = false;
341
+ }
342
+ const attemptKey = buildAttemptKey(kind, label, currentGroup?.id);
343
+ let attempt;
344
+ if (projection.type === "step" && projection.status === "started") {
345
+ attempt = createAttempt(kind, label, projection, record.agentId, record.agentName);
346
+ activeAttemptsByKey.set(attemptKey, attempt);
347
+ }
348
+ else if (projection.type === "tool-result") {
349
+ const toolName = normalizeToolIdentity(projection.toolName);
350
+ const existing = toolAttemptsByName.get(toolName) ?? [];
351
+ attempt = [...existing].reverse().find((candidate) => candidate.groupId === currentGroup?.id) ?? existing[existing.length - 1];
352
+ if (!attempt) {
353
+ attempt = createAttempt("tool", `Calling tool ${titleCase(toolName)}`, projection, record.agentId, record.agentName);
354
+ }
355
+ }
356
+ else {
357
+ attempt = activeAttemptsByKey.get(attemptKey);
358
+ if (!attempt) {
359
+ attempt = createAttempt(kind, label, projection, record.agentId, record.agentName);
360
+ }
361
+ }
362
+ attempt.agentId = attempt.agentId ?? record.agentId;
363
+ attempt.agentName = attempt.agentName ?? record.agentName;
364
+ attempt.projectionKeys.push(projection.key);
365
+ attempt.sourceEventIds.push(record.sourceEventId);
366
+ if (projection.type === "step") {
367
+ attempt.status = deriveStatusFromProjection(projection);
368
+ attempt.detail.category = projection.category;
369
+ attempt.detail.step = projection.step;
370
+ }
371
+ else if (projection.type === "tool-result") {
372
+ attempt.status = projection.isError ? "failed" : "completed";
373
+ attempt.toolName = projection.toolName;
374
+ attempt.detail.toolName = projection.toolName;
375
+ attempt.detail.result = projection.output;
376
+ attempt.detail.resultIsError = projection.isError === true;
377
+ if (projection.isError) {
378
+ activeAttemptsByKey.delete(buildAttemptKey("tool", attempt.label, attempt.groupId));
379
+ }
380
+ }
381
+ if (!attemptSetGroups.has(`${kind}:${currentGroup?.id ?? "ungrouped"}`)) {
382
+ attemptSetGroups.set(`${kind}:${currentGroup?.id ?? "ungrouped"}`, {
383
+ id: `group:${requestId}:attempt-set:${slugify(kind)}:${attemptSetGroups.size + 1}`,
384
+ kind: "attempt-set",
385
+ label: `${titleCase(kind)} attempts`,
386
+ nodeIds: [],
387
+ });
388
+ }
389
+ const attemptGroup = attemptSetGroups.get(`${kind}:${currentGroup?.id ?? "ungrouped"}`);
390
+ if (!attemptGroup.nodeIds.includes(attempt.id)) {
391
+ attemptGroup.nodeIds.push(attempt.id);
392
+ }
393
+ if (pendingDelegationNode && pendingDelegationNode.id !== attempt.id) {
394
+ edges.push({
395
+ id: `edge:${pendingDelegationNode.id}->${attempt.id}`,
396
+ from: pendingDelegationNode.id,
397
+ to: attempt.id,
398
+ kind: "spawn",
399
+ sourceEventIds: [...pendingDelegationNode.sourceEventIds, ...attempt.sourceEventIds],
400
+ confidence: 0.9,
401
+ });
402
+ pendingDelegationNode = null;
403
+ }
404
+ else if (previousAttempt && previousAttempt.id !== attempt.id) {
405
+ edges.push({
406
+ id: `edge:${previousAttempt.id}->${attempt.id}`,
407
+ from: previousAttempt.id,
408
+ to: attempt.id,
409
+ kind: kind === "approval" ? "approval" : "sequence",
410
+ sourceEventIds: [],
411
+ confidence: 0.7,
412
+ });
413
+ }
414
+ else if (!previousAttempt && currentGroup?.anchorNodeId) {
415
+ edges.push({
416
+ id: `edge:${currentGroup.anchorNodeId}->${attempt.id}`,
417
+ from: currentGroup.anchorNodeId,
418
+ to: attempt.id,
419
+ kind: "contains",
420
+ sourceEventIds: [],
421
+ confidence: 0.8,
422
+ });
423
+ }
424
+ previousAttempt = attempt;
425
+ if (projection.type === "step" && projection.status !== "started") {
426
+ activeAttemptsByKey.delete(attemptKey);
427
+ }
428
+ }
429
+ for (const attempt of attempts) {
430
+ nodes.push({
431
+ id: attempt.id,
432
+ layer: "attempt",
433
+ kind: attempt.kind,
434
+ label: attempt.label,
435
+ status: attempt.status,
436
+ sessionId,
437
+ requestId,
438
+ agentId: attempt.agentId,
439
+ agentName: attempt.agentName,
440
+ groupId: attempt.groupId,
441
+ sequenceStart: attempt.sequenceStart,
442
+ sequenceEnd: attempt.sequenceEnd,
443
+ startedAt: attempt.startedAt,
444
+ endedAt: attempt.endedAt,
445
+ sourceEventIds: [...new Set(attempt.sourceEventIds)],
446
+ detail: { ...attempt.detail, projectionKeys: attempt.projectionKeys },
447
+ });
448
+ }
449
+ groups.push(...attemptSetGroups.values());
450
+ return { nodes, edges, groups };
451
+ }
452
+ export function resolveContext(input, runtimeTimeline, projections) {
453
+ const timelineHead = runtimeTimeline[0];
454
+ const inputSessionId = readSessionId(input);
455
+ const inputRequestId = readRequestId(input);
456
+ if (inputSessionId && inputRequestId) {
457
+ return { sessionId: inputSessionId, requestId: inputRequestId };
458
+ }
459
+ if (timelineHead) {
460
+ return {
461
+ sessionId: inputSessionId ?? timelineHead.sessionId,
462
+ requestId: inputRequestId ?? timelineHead.requestId,
463
+ };
464
+ }
465
+ const firstProjection = projections[0];
466
+ if (!inputSessionId || !inputRequestId) {
467
+ throw new Error(`buildFlowGraph requires sessionId and requestId when runtime timeline data is absent${firstProjection ? "" : " or empty"}.`);
468
+ }
469
+ return { sessionId: inputSessionId, requestId: inputRequestId };
470
+ }
471
+ export function buildRuntimeSurface(nodes) {
472
+ return nodes
473
+ .filter((node) => node.layer !== "detail"
474
+ && (node.kind === "agent" || node.kind === "llm" || node.kind === "memory" || node.kind === "skill" || node.kind === "tool"))
475
+ .map((node) => ({
476
+ kind: node.kind,
477
+ id: buildSurfaceId(node.kind, node.kind === "agent" ? (node.agentId ?? node.agentName ?? "agent") : node.label),
478
+ name: node.kind === "agent"
479
+ ? (node.agentName ?? node.agentId ?? "Agent")
480
+ : stripStepPrefix(node.label),
481
+ action: resolveSurfaceAction({
482
+ kind: node.kind,
483
+ step: node.label,
484
+ event: node.detail,
485
+ }),
486
+ status: node.status === "resolved" ? "completed" : node.status,
487
+ agentId: node.agentId,
488
+ agentName: node.agentName,
489
+ ownerAgentId: node.kind === "agent"
490
+ ? (typeof node.detail.fromAgentId === "string" ? node.detail.fromAgentId : node.agentId)
491
+ : node.agentId,
492
+ ownerAgentName: node.kind === "agent"
493
+ ? (typeof node.detail.fromAgentName === "string" ? node.detail.fromAgentName : node.agentName)
494
+ : node.agentName,
495
+ sourceEventId: node.sourceEventIds[0],
496
+ detail: { ...node.detail },
497
+ }));
498
+ }
@@ -1,5 +1,5 @@
1
1
  import type { HarnessEvent, RuntimeTimelineItem } from "../contracts/types.js";
2
- import type { UpstreamTimelineProjection } from "../upstream-events.js";
2
+ import type { UpstreamTimelineProjection } from "../projections/upstream-events.js";
3
3
  export type BuildFlowGraphRuntimeEvent = HarnessEvent | {
4
4
  eventId: string;
5
5
  eventType: string;
package/dist/index.d.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  export { AgentHarnessAcpServer, AgentHarnessRuntime, cancelRequest, createAgentHarness, createAcpServer, createAcpStdioClient, createRuntimeMcpServer, createUpstreamTimelineReducer, createToolMcpServer, deleteSession, describeInventory, exportEvaluationBundle, exportFlow, exportSequence, exportRequestPackage, exportSessionPackage, replayEvaluationBundle, getArtifact, getAgent, getApproval, getOperatorOverview, getRequestPlanState, getRequest, getHealth, listMemories, listRequestTraceItems, getSession, listAgentSkills, listRequestArtifacts, listApprovals, listRequests, listRequestEvents, listSessionSummaries, listSessions, memorize, normalizeUserChatInput, recordArtifact, request, recall, removeMemory, resolveApproval, serveA2aHttp, serveAcpHttp, serveAcpStdio, serveAgUiHttp, serveRuntimeMcpOverStdio, serveRuntimeMcpOverStreamableHttp, serveToolsOverStdio, subscribe, stop, updateMemory, } from "./api.js";
2
2
  export { AcpHarnessClient, InProcessHarnessClient, createAcpHarnessClient, createAcpHttpHarnessClient, createAcpStdioHarnessClient, createAgentHarnessClient, createInProcessHarnessClient, } from "./client.js";
3
3
  export { createKnowledgeModule, readKnowledgeRuntimeConfig } from "./knowledge/index.js";
4
- export { readProceduralMemoryRuntimeConfig } from "./procedural/index.js";
4
+ export { readProceduralMemoryRuntimeConfig } from "./knowledge/procedural/index.js";
5
5
  export type { AcpApproval, AcpHttpClient, AcpHttpClientOptions, AcpArtifact, AcpEventNotification, AcpNotification, AcpJsonRpcError, AcpJsonRpcRequest, AcpJsonRpcResponse, AcpJsonRpcSuccess, AcpRequestRecord, AcpRequestParams, AcpServerCapabilities, AcpSessionRecord, AcpStreamNotification, AcpStdioClient, AcpStdioClientOptions, } from "./acp.js";
6
6
  export type { Approval, CreateAgentHarnessOptions, ListMemoriesInput, ListMemoriesResult, MemoryDecision, MemoryKind, MemoryRecord, MemoryScope, MemorizeInput, MemorizeResult, NormalizeUserChatInputOptions, OperatorOverview, RecordArtifactInput, PublicRequestListeners, RequestData, RequestArtifactListing, RequestEvent, RequestEventType, RequestSnapshot, RequestPlanState, RequestPackage, RequestPackageInput, RequestFlowGraphInput, RequestResult, RequestTraceItem, RecallInput, RecallResult, RemoveMemoryInput, RuntimeEvaluationExport, RuntimeEvaluationExportInput, RuntimeEvaluationReplayInput, RuntimeEvaluationReplayResult, SessionListSummary, RuntimeSessionPackage, RuntimeSessionPackageInput, UpdateMemoryInput, UserChatInput, UserChatMessage, } from "./api.js";
7
7
  export type { AcpHarnessTransport, HarnessClient, HarnessClientApprovalFilter, HarnessClientRequestFilter, HarnessClientRequestOptions, HarnessClientRequestResult, HarnessClientRequestStartOptions, } from "./client.js";
8
8
  export type { KnowledgeListInput, KnowledgeMemorizeInput, KnowledgeModule, KnowledgeModuleDependencies, KnowledgeRecallInput, KnowledgeRuntimeConfig, KnowledgeRuntimeContext, } from "./knowledge/index.js";
9
- export type { ProceduralMemoryBackgroundConfig, ProceduralMemoryFormationConfig, ProceduralMemoryMaintenanceConfig, ProceduralMemoryMaintenanceIdleConfig, ProceduralMemoryMaintenanceScheduleConfig, ProceduralMemoryProviderConfig, ProceduralMemoryRetrievalConfig, ProceduralMemoryRuntimeConfig, } from "./procedural/index.js";
9
+ export type { ProceduralMemoryBackgroundConfig, ProceduralMemoryFormationConfig, ProceduralMemoryMaintenanceConfig, ProceduralMemoryMaintenanceIdleConfig, ProceduralMemoryMaintenanceScheduleConfig, ProceduralMemoryProviderConfig, ProceduralMemoryRetrievalConfig, ProceduralMemoryRuntimeConfig, } from "./knowledge/procedural/index.js";
10
10
  export type { A2aAgentCard, A2aHttpServer, A2aHttpServerOptions, A2aTask, A2aTaskState, AcpHttpServer, AcpHttpServerOptions, AcpStdioServer, AcpStdioServerOptions, AgUiEvent, AgUiHttpServer, AgUiHttpServerOptions, AgUiRequestAgentInput, } from "./api.js";
11
11
  export type { RuntimeMcpServerOptions, ToolMcpServerOptions } from "./mcp.js";
12
12
  export { tool } from "./tools.js";
13
- export type { UpstreamTimelineProjection, UpstreamTimelineReducer } from "./upstream-events.js";
13
+ export type { UpstreamTimelineProjection, UpstreamTimelineReducer } from "./projections/upstream-events.js";
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { AgentHarnessAcpServer, AgentHarnessRuntime, cancelRequest, createAgentHarness, createAcpServer, createAcpStdioClient, createRuntimeMcpServer, createUpstreamTimelineReducer, createToolMcpServer, deleteSession, describeInventory, exportEvaluationBundle, exportFlow, exportSequence, exportRequestPackage, exportSessionPackage, replayEvaluationBundle, getArtifact, getAgent, getApproval, getOperatorOverview, getRequestPlanState, getRequest, getHealth, listMemories, listRequestTraceItems, getSession, listAgentSkills, listRequestArtifacts, listApprovals, listRequests, listRequestEvents, listSessionSummaries, listSessions, memorize, normalizeUserChatInput, recordArtifact, request, recall, removeMemory, resolveApproval, serveA2aHttp, serveAcpHttp, serveAcpStdio, serveAgUiHttp, serveRuntimeMcpOverStdio, serveRuntimeMcpOverStreamableHttp, serveToolsOverStdio, subscribe, stop, updateMemory, } from "./api.js";
2
2
  export { AcpHarnessClient, InProcessHarnessClient, createAcpHarnessClient, createAcpHttpHarnessClient, createAcpStdioHarnessClient, createAgentHarnessClient, createInProcessHarnessClient, } from "./client.js";
3
3
  export { createKnowledgeModule, readKnowledgeRuntimeConfig } from "./knowledge/index.js";
4
- export { readProceduralMemoryRuntimeConfig } from "./procedural/index.js";
4
+ export { readProceduralMemoryRuntimeConfig } from "./knowledge/procedural/index.js";
5
5
  export { tool } from "./tools.js";
@@ -1,12 +1 @@
1
- export type InitTemplate = "deep-research" | "single-agent";
2
- export type InitProjectOptions = {
3
- template?: InitTemplate;
4
- provider?: string;
5
- model?: string;
6
- withWebSearch?: boolean;
7
- };
8
- export type InitProjectResult = {
9
- projectRoot: string;
10
- projectSlug: string;
11
- };
12
- export declare function initProject(projectRoot: string, projectName: string, options?: InitProjectOptions): Promise<InitProjectResult>;
1
+ export * from "./scaffold/init-project.js";