@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,56 @@
1
+ import type { RuntimeTimelineItem, RuntimeSurfaceItem } from "../contracts/types.js";
2
+ import type { BuildFlowGraphInput, BuildFlowGraphRuntimeEvent, FlowGroup, FlowNode, FlowNodeKind, FlowNodeStatus } from "./types.js";
3
+ import type { UpstreamTimelineProjection } from "../projections/upstream-events.js";
4
+ export type ProjectionRecord = {
5
+ projection: UpstreamTimelineProjection;
6
+ agentId: string;
7
+ agentName: string;
8
+ sourceEventId: string;
9
+ };
10
+ export type UpstreamEventEnvelope = {
11
+ event: unknown;
12
+ agentId?: string;
13
+ agentName?: string;
14
+ surfaceItem?: Partial<RuntimeSurfaceItem>;
15
+ };
16
+ export type InternalAttemptRecord = {
17
+ id: string;
18
+ kind: FlowNodeKind;
19
+ label: string;
20
+ status: FlowNodeStatus;
21
+ agentId?: string;
22
+ agentName?: string;
23
+ groupId?: string;
24
+ sourceEventIds: string[];
25
+ startedAt?: string;
26
+ endedAt?: string;
27
+ sequenceStart?: number;
28
+ sequenceEnd?: number;
29
+ detail: Record<string, unknown>;
30
+ attemptKey: string;
31
+ toolName?: string;
32
+ projectionKeys: string[];
33
+ };
34
+ export type InternalGroupState = FlowGroup & {
35
+ anchorNodeId?: string;
36
+ };
37
+ export declare function asObject(value: unknown): Record<string, unknown> | null;
38
+ export declare function readString(value: unknown): string | null;
39
+ export declare function extractUpstreamEventEnvelope(value: unknown): UpstreamEventEnvelope;
40
+ export declare function normalizeRuntimeEvents(events: readonly BuildFlowGraphRuntimeEvent[]): import("../contracts/types.js").HarnessEvent[];
41
+ export declare function collectNestedAgentNames(value: unknown, names?: Set<string>): Set<string>;
42
+ export declare function slugify(value: string): string;
43
+ export declare function titleCase(value: string): string;
44
+ export declare function normalizeLabel(value: string): string;
45
+ export declare function readSessionId(input: BuildFlowGraphInput): string | undefined;
46
+ export declare function readRequestId(input: BuildFlowGraphInput): string | undefined;
47
+ export declare function readProjectionLabel(projection: UpstreamTimelineProjection): string;
48
+ export declare function deriveNodeKindFromProjection(projection: UpstreamTimelineProjection): FlowNodeKind;
49
+ export declare function deriveStatusFromProjection(projection: UpstreamTimelineProjection): FlowNodeStatus;
50
+ export declare function deriveRuntimeNode(input: RuntimeTimelineItem): Pick<FlowNode, "kind" | "status" | "label" | "detail">;
51
+ export declare function normalizeAttemptLabel(kind: FlowNodeKind, projection: UpstreamTimelineProjection): string;
52
+ export declare function semanticNameFromLabel(kind: FlowNodeKind, label: string): string;
53
+ export declare function normalizeToolIdentity(value: string): string;
54
+ export declare function buildAttemptKey(kind: FlowNodeKind, label: string, groupId?: string): string;
55
+ export declare function deriveInitialAgentId(input: BuildFlowGraphInput, runtimeTimeline: readonly RuntimeTimelineItem[]): string;
56
+ export declare function deriveAgentName(agentId: string, explicitName?: string): string;
@@ -0,0 +1,214 @@
1
+ import { formatAgentName } from "../utils/agent-display.js";
2
+ export function asObject(value) {
3
+ return typeof value === "object" && value !== null ? value : null;
4
+ }
5
+ export function readString(value) {
6
+ return typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
7
+ }
8
+ export function extractUpstreamEventEnvelope(value) {
9
+ const typed = asObject(value);
10
+ const nestedEvent = typed && Object.prototype.hasOwnProperty.call(typed, "event") ? typed.event : undefined;
11
+ const surfaceItem = asObject(typed?.surfaceItem);
12
+ const event = typed
13
+ && nestedEvent
14
+ && typeof nestedEvent === "object"
15
+ && !Array.isArray(nestedEvent)
16
+ ? nestedEvent
17
+ : value;
18
+ const agentId = readString(typed?.agentId) ?? readString(surfaceItem?.agentId);
19
+ const agentName = readString(typed?.agentName) ?? readString(surfaceItem?.agentName);
20
+ return {
21
+ event,
22
+ agentId: agentId ?? undefined,
23
+ agentName: agentName ?? undefined,
24
+ ...(surfaceItem ? { surfaceItem } : {}),
25
+ };
26
+ }
27
+ function normalizeRuntimeEventType(eventType) {
28
+ return eventType;
29
+ }
30
+ export function normalizeRuntimeEvents(events) {
31
+ return events.map((event) => {
32
+ const typed = event;
33
+ const sessionId = readString(typed.sessionId) ?? "";
34
+ const requestId = readString(typed.requestId) ?? "";
35
+ return {
36
+ eventId: String(event.eventId),
37
+ eventType: normalizeRuntimeEventType(String(event.eventType)),
38
+ timestamp: String(event.timestamp),
39
+ sessionId,
40
+ requestId,
41
+ sequence: Number(event.sequence),
42
+ source: event.source,
43
+ payload: event.payload ?? {},
44
+ };
45
+ });
46
+ }
47
+ export function collectNestedAgentNames(value, names = new Set()) {
48
+ if (Array.isArray(value)) {
49
+ for (const item of value) {
50
+ collectNestedAgentNames(item, names);
51
+ }
52
+ return names;
53
+ }
54
+ const typed = asObject(value);
55
+ if (!typed) {
56
+ return names;
57
+ }
58
+ const idParts = Array.isArray(typed.id) ? typed.id.filter((item) => typeof item === "string") : [];
59
+ const kwargs = asObject(typed.kwargs);
60
+ const kwargsName = idParts.includes("AIMessage") ? readString(kwargs?.name) : null;
61
+ if (kwargsName && kwargsName !== "assistant") {
62
+ names.add(kwargsName);
63
+ }
64
+ for (const nested of Object.values(typed)) {
65
+ collectNestedAgentNames(nested, names);
66
+ }
67
+ return names;
68
+ }
69
+ export function slugify(value) {
70
+ return value
71
+ .toLowerCase()
72
+ .replace(/[^a-z0-9]+/g, "-")
73
+ .replace(/^-+|-+$/g, "")
74
+ .slice(0, 80) || "node";
75
+ }
76
+ export function titleCase(value) {
77
+ return value
78
+ .replace(/[_-]+/g, " ")
79
+ .replace(/\s+/g, " ")
80
+ .trim()
81
+ .split(" ")
82
+ .filter(Boolean)
83
+ .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
84
+ .join(" ");
85
+ }
86
+ export function normalizeLabel(value) {
87
+ return value.replace(/\s+/g, " ").trim();
88
+ }
89
+ export function readSessionId(input) {
90
+ return input.sessionId;
91
+ }
92
+ export function readRequestId(input) {
93
+ return input.requestId;
94
+ }
95
+ export function readProjectionLabel(projection) {
96
+ if (projection.type === "step") {
97
+ return projection.step;
98
+ }
99
+ if (projection.type === "tool-result") {
100
+ return `Tool result ${titleCase(projection.toolName)}`;
101
+ }
102
+ return projection.text;
103
+ }
104
+ export function deriveNodeKindFromProjection(projection) {
105
+ if (projection.type === "tool-result") {
106
+ return "result";
107
+ }
108
+ if (projection.type === "thinking") {
109
+ return "thinking";
110
+ }
111
+ return projection.category;
112
+ }
113
+ export function deriveStatusFromProjection(projection) {
114
+ if (projection.type === "thinking" || projection.type === "tool-result") {
115
+ return "completed";
116
+ }
117
+ return projection.category === "approval" && projection.status === "started" ? "waiting" : projection.status;
118
+ }
119
+ export function deriveRuntimeNode(input) {
120
+ if (input.eventType === "request.created") {
121
+ return { kind: "request", status: "started", label: "Request created", detail: input.payload };
122
+ }
123
+ if (input.eventType === "request.queued") {
124
+ return { kind: "queue", status: "waiting", label: "Queued", detail: input.payload };
125
+ }
126
+ if (input.eventType === "request.dequeued") {
127
+ return { kind: "queue", status: "completed", label: "Dequeued", detail: input.payload };
128
+ }
129
+ if (input.eventType === "approval.requested") {
130
+ return { kind: "approval", status: "waiting", label: "Approval requested", detail: input.payload };
131
+ }
132
+ if (input.eventType === "approval.resolved") {
133
+ return { kind: "approval", status: "resolved", label: "Approval resolved", detail: input.payload };
134
+ }
135
+ if (input.eventType === "request.resumed") {
136
+ return { kind: "recovery", status: "completed", label: "Request resumed", detail: input.payload };
137
+ }
138
+ if (input.eventType === "artifact.created") {
139
+ return { kind: "artifact", status: "completed", label: "Artifact created", detail: input.payload };
140
+ }
141
+ if (input.eventType === "request.state.changed") {
142
+ const state = typeof input.payload.state === "string" ? input.payload.state : "";
143
+ if (state === "waiting_for_approval") {
144
+ return { kind: "approval", status: "waiting", label: "Waiting for approval", detail: input.payload };
145
+ }
146
+ if (state === "failed") {
147
+ return { kind: "request", status: "failed", label: "Request failed", detail: input.payload };
148
+ }
149
+ if (state === "completed") {
150
+ return { kind: "request", status: "completed", label: "Request completed", detail: input.payload };
151
+ }
152
+ return { kind: "request", status: "started", label: state ? `Request ${state}` : "Request state changed", detail: input.payload };
153
+ }
154
+ return { kind: input.kind, status: "completed", label: input.eventType, detail: input.payload };
155
+ }
156
+ export function normalizeAttemptLabel(kind, projection) {
157
+ if (projection.type === "step") {
158
+ const label = normalizeLabel(projection.step);
159
+ if (label) {
160
+ return label;
161
+ }
162
+ }
163
+ if (projection.type === "tool-result") {
164
+ return `Tool ${titleCase(projection.toolName)}`;
165
+ }
166
+ if (projection.type === "thinking") {
167
+ return "Model reasoning";
168
+ }
169
+ return titleCase(kind);
170
+ }
171
+ export function semanticNameFromLabel(kind, label) {
172
+ const normalized = normalizeLabel(label)
173
+ .replace(/^Calling LLM\s+/i, "")
174
+ .replace(/^Completed LLM\s+/i, "")
175
+ .replace(/^Calling tool\s+/i, "")
176
+ .replace(/^Completed tool\s+/i, "")
177
+ .replace(/^Tool\s+/i, "")
178
+ .replace(/\s+failed$/i, "")
179
+ .replace(/^Calling skill\s+/i, "")
180
+ .replace(/^Completed skill\s+/i, "")
181
+ .replace(/^Accessing memory\s+/i, "")
182
+ .replace(/^Completed memory\s+/i, "")
183
+ .replace(/^Running\s+/i, "")
184
+ .replace(/^Completed\s+/i, "");
185
+ return `${kind}:${normalized.toLowerCase()}`;
186
+ }
187
+ export function normalizeToolIdentity(value) {
188
+ return value
189
+ .toLowerCase()
190
+ .replace(/[_-]+/g, " ")
191
+ .replace(/\s+/g, " ")
192
+ .trim();
193
+ }
194
+ export function buildAttemptKey(kind, label, groupId) {
195
+ return `${semanticNameFromLabel(kind, label)}:${groupId ?? "ungrouped"}`;
196
+ }
197
+ export function deriveInitialAgentId(input, runtimeTimeline) {
198
+ const candidate = runtimeTimeline.find((item) => {
199
+ const payload = asObject(item.payload);
200
+ return typeof payload?.agentId === "string" && payload.agentId.trim().length > 0;
201
+ });
202
+ const payload = candidate ? asObject(candidate.payload) : null;
203
+ const metadataAgentId = typeof input.metadata?.currentAgentId === "string" ? input.metadata.currentAgentId : null;
204
+ if (metadataAgentId && metadataAgentId.trim().length > 0) {
205
+ return metadataAgentId.trim();
206
+ }
207
+ if (payload?.agentId && typeof payload.agentId === "string" && payload.agentId.trim().length > 0) {
208
+ return payload.agentId.trim();
209
+ }
210
+ return "agent";
211
+ }
212
+ export function deriveAgentName(agentId, explicitName) {
213
+ return explicitName && explicitName.trim().length > 0 ? explicitName.trim() : formatAgentName(agentId);
214
+ }
@@ -0,0 +1,8 @@
1
+ import type { RuntimeTimelineItem } from "../contracts/types.js";
2
+ import type { FlowEdge, FlowNode } from "./types.js";
3
+ import { type InternalGroupState } from "./flow-graph-normalization.js";
4
+ export declare function buildRuntimeNodes(timeline: readonly RuntimeTimelineItem[]): {
5
+ nodes: FlowNode[];
6
+ edges: FlowEdge[];
7
+ groups: InternalGroupState[];
8
+ };
@@ -0,0 +1,107 @@
1
+ import { deriveRuntimeNode, slugify } from "./flow-graph-normalization.js";
2
+ export function buildRuntimeNodes(timeline) {
3
+ const nodes = [];
4
+ const edges = [];
5
+ const groups = [];
6
+ let previousNode = null;
7
+ let segmentOrdinal = 0;
8
+ let approvalOrdinal = 0;
9
+ let activeExecutionGroup = null;
10
+ let activeApprovalGroup = null;
11
+ for (const item of timeline) {
12
+ const mapped = deriveRuntimeNode(item);
13
+ const node = {
14
+ id: `rt:${item.requestId}:${item.sequence}:${slugify(item.eventType)}`,
15
+ layer: "runtime",
16
+ kind: mapped.kind,
17
+ label: mapped.label,
18
+ status: mapped.status,
19
+ sessionId: item.sessionId,
20
+ requestId: item.requestId,
21
+ startedAt: item.timestamp,
22
+ endedAt: item.timestamp,
23
+ sequenceStart: item.sequence,
24
+ sequenceEnd: item.sequence,
25
+ sourceEventIds: [item.eventId],
26
+ detail: { ...mapped.detail, eventType: item.eventType, source: item.source },
27
+ };
28
+ nodes.push(node);
29
+ if (previousNode) {
30
+ const kind = item.eventType === "approval.resolved"
31
+ ? "approval"
32
+ : item.eventType === "request.resumed"
33
+ ? "resume"
34
+ : "sequence";
35
+ edges.push({
36
+ id: `edge:${previousNode.id}->${node.id}`,
37
+ from: previousNode.id,
38
+ to: node.id,
39
+ kind,
40
+ ...(kind === "approval" ? { label: typeof item.payload.decision === "string" ? item.payload.decision : "resolved" } : {}),
41
+ sourceEventIds: [previousNode.sourceEventIds[0], item.eventId],
42
+ });
43
+ }
44
+ previousNode = node;
45
+ if (item.eventType === "request.created" || item.eventType === "request.dequeued" || item.eventType === "request.resumed") {
46
+ segmentOrdinal += 1;
47
+ activeExecutionGroup = {
48
+ id: `group:${item.requestId}:segment:${segmentOrdinal}`,
49
+ kind: "segment",
50
+ label: item.eventType === "request.created"
51
+ ? `Execution segment ${segmentOrdinal}`
52
+ : item.eventType === "request.resumed"
53
+ ? `Resumed segment ${segmentOrdinal}`
54
+ : `Dequeued segment ${segmentOrdinal}`,
55
+ nodeIds: [node.id],
56
+ startedAt: item.timestamp,
57
+ anchorNodeId: node.id,
58
+ };
59
+ groups.push(activeExecutionGroup);
60
+ activeApprovalGroup = null;
61
+ node.groupId = activeExecutionGroup.id;
62
+ continue;
63
+ }
64
+ if (item.eventType === "approval.requested") {
65
+ approvalOrdinal += 1;
66
+ activeApprovalGroup = {
67
+ id: `group:${item.requestId}:approval:${approvalOrdinal}`,
68
+ kind: "approval-window",
69
+ label: `Approval window ${approvalOrdinal}`,
70
+ nodeIds: [node.id],
71
+ startedAt: item.timestamp,
72
+ anchorNodeId: node.id,
73
+ };
74
+ groups.push(activeApprovalGroup);
75
+ node.groupId = activeApprovalGroup.id;
76
+ continue;
77
+ }
78
+ if (item.eventType === "approval.resolved") {
79
+ if (!activeApprovalGroup) {
80
+ approvalOrdinal += 1;
81
+ activeApprovalGroup = {
82
+ id: `group:${item.requestId}:approval:${approvalOrdinal}`,
83
+ kind: "approval-window",
84
+ label: `Approval window ${approvalOrdinal}`,
85
+ nodeIds: [],
86
+ anchorNodeId: node.id,
87
+ };
88
+ groups.push(activeApprovalGroup);
89
+ }
90
+ activeApprovalGroup.nodeIds.push(node.id);
91
+ activeApprovalGroup.endedAt = item.timestamp;
92
+ node.groupId = activeApprovalGroup.id;
93
+ continue;
94
+ }
95
+ if (activeApprovalGroup && !activeApprovalGroup.endedAt) {
96
+ activeApprovalGroup.nodeIds.push(node.id);
97
+ node.groupId = activeApprovalGroup.id;
98
+ continue;
99
+ }
100
+ if (activeExecutionGroup) {
101
+ activeExecutionGroup.nodeIds.push(node.id);
102
+ activeExecutionGroup.endedAt = item.timestamp;
103
+ node.groupId = activeExecutionGroup.id;
104
+ }
105
+ }
106
+ return { nodes, edges, groups };
107
+ }
@@ -0,0 +1,18 @@
1
+ import type { RuntimeSurfaceItem, RuntimeTimelineItem } from "../contracts/types.js";
2
+ import { type UpstreamTimelineProjection } from "../projections/upstream-events.js";
3
+ import type { BuildFlowGraphInput, FlowEdge, FlowGroup, FlowNode } from "./types.js";
4
+ import { type InternalGroupState, type ProjectionRecord } from "./flow-graph-normalization.js";
5
+ export declare function convertUpstreamEventsWithAgents(upstreamEvents: readonly unknown[], initialAgentId: string): {
6
+ projections: ProjectionRecord[];
7
+ delegationNodes: FlowNode[];
8
+ };
9
+ export declare function buildAttempts(projectionRecords: readonly ProjectionRecord[], delegationNodes: readonly FlowNode[], runtimeGroups: readonly InternalGroupState[], sessionId: string, requestId: string): {
10
+ nodes: FlowNode[];
11
+ edges: FlowEdge[];
12
+ groups: FlowGroup[];
13
+ };
14
+ export declare function resolveContext(input: BuildFlowGraphInput, runtimeTimeline: readonly RuntimeTimelineItem[], projections: readonly UpstreamTimelineProjection[]): {
15
+ sessionId: string;
16
+ requestId: string;
17
+ };
18
+ export declare function buildRuntimeSurface(nodes: readonly FlowNode[]): RuntimeSurfaceItem[];