@botbotgo/agent-harness 0.0.475 → 0.0.476
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.
- package/README.md +3 -1234
- package/README.zh.md +3 -1191
- package/dist/acp.js +1 -1
- package/dist/api.js +1 -404
- package/dist/benchmark/checkpoint-resume-cost-benchmark.js +1 -55
- package/dist/benchmark/deepagent-local-model-benchmark.js +2 -35
- package/dist/benchmark/upstream-runtime-ab-benchmark.js +1 -179
- package/dist/cli/chat-interactive.js +25 -244
- package/dist/cli/chat-rendering.js +6 -100
- package/dist/cli/chat-stream.js +23 -512
- package/dist/cli/chat-ui.js +21 -199
- package/dist/cli/chat-workspace.js +2 -210
- package/dist/cli/main.js +21 -428
- package/dist/cli/managed-service-commands.js +9 -63
- package/dist/cli/managed-service.js +2 -137
- package/dist/cli/options-init-chat.js +1 -108
- package/dist/cli/options-runtime.js +1 -158
- package/dist/cli/options-serve.js +1 -282
- package/dist/cli/options.js +2 -19
- package/dist/cli/process-guards.js +1 -139
- package/dist/cli/request-tree.js +7 -296
- package/dist/cli/runtime-commands.js +12 -258
- package/dist/cli/runtime-output.js +16 -155
- package/dist/cli/server-commands.js +16 -270
- package/dist/cli/workspace.js +1 -67
- package/dist/cli.js +1 -7
- package/dist/client/acp.js +1 -1
- package/dist/client/in-process.js +1 -67
- package/dist/client/index.js +1 -2
- package/dist/client/types.js +0 -1
- package/dist/client.js +1 -1
- package/dist/contracts/core.js +1 -1
- package/dist/contracts/runtime-evaluation.js +0 -1
- package/dist/contracts/runtime-memory.js +0 -1
- package/dist/contracts/runtime-observability.js +0 -1
- package/dist/contracts/runtime-requests.js +0 -1
- package/dist/contracts/runtime-scheduling.js +0 -1
- package/dist/contracts/runtime.js +1 -27
- package/dist/contracts/types.js +1 -3
- package/dist/contracts/workspace.js +0 -1
- package/dist/flow/build-flow-graph.js +1 -50
- package/dist/flow/export-mermaid.js +2 -464
- package/dist/flow/export-sequence-mermaid.js +2 -325
- package/dist/flow/flow-graph-normalization.js +1 -214
- package/dist/flow/flow-graph-runtime.js +1 -107
- package/dist/flow/flow-graph-upstream.js +1 -494
- package/dist/flow/index.js +1 -3
- package/dist/flow/types.js +0 -1
- package/dist/index.js +1 -5
- package/dist/init-project.js +1 -1
- package/dist/knowledge/config.js +1 -32
- package/dist/knowledge/contracts.js +0 -1
- package/dist/knowledge/index.js +1 -2
- package/dist/knowledge/module.js +12 -909
- package/dist/knowledge/procedural/config.js +1 -125
- package/dist/knowledge/procedural/index.js +1 -2
- package/dist/knowledge/procedural/manager.js +9 -345
- package/dist/mcp.js +1 -2
- package/dist/package-version.d.ts +1 -1
- package/dist/package-version.js +1 -2
- package/dist/persistence/file-store.js +3 -758
- package/dist/persistence/sqlite-request-context-store.js +5 -54
- package/dist/persistence/sqlite-request-queue-store.js +10 -108
- package/dist/persistence/sqlite-runtime.js +1 -86
- package/dist/persistence/sqlite-store.js +62 -810
- package/dist/persistence/types.js +0 -1
- package/dist/projections/presentation.js +37 -206
- package/dist/projections/request-events.js +2 -502
- package/dist/projections/upstream-events.js +1 -201
- package/dist/protocol/a2a/http-discovery.js +1 -178
- package/dist/protocol/a2a/http-rpc.js +6 -622
- package/dist/protocol/a2a/http.js +1 -138
- package/dist/protocol/a2a/task-state.js +3 -317
- package/dist/protocol/acp/client.js +8 -294
- package/dist/protocol/acp/harness-client.js +1 -218
- package/dist/protocol/acp/http.js +5 -130
- package/dist/protocol/acp/server.js +1 -310
- package/dist/protocol/acp/stdio.js +2 -69
- package/dist/protocol/ag-ui/http.js +3 -378
- package/dist/protocol/mcp/server.js +1 -428
- package/dist/resource/backend/workspace-scoped-backend.js +1 -319
- package/dist/resource/isolation.js +1 -237
- package/dist/resource/mcp/tool-support.js +3 -296
- package/dist/resource/mcp-tool-support.js +1 -2
- package/dist/resource/providers/resource-provider.js +1 -215
- package/dist/resource/resource-impl.js +1 -3
- package/dist/resource/resource-types.js +0 -1
- package/dist/resource/resource.js +1 -1
- package/dist/resource/sources.js +1 -247
- package/dist/resource/tools/function-tool-resolver.js +2 -272
- package/dist/runtime/adapter/compat/deepagent-compat.js +1 -29
- package/dist/runtime/adapter/compat/openai-compatible.js +1 -55
- package/dist/runtime/adapter/direct-builtin-utility.js +2 -90
- package/dist/runtime/adapter/flow/execution-context.js +1 -71
- package/dist/runtime/adapter/flow/invocation-flow.js +8 -425
- package/dist/runtime/adapter/flow/invoke-runtime.js +1 -20
- package/dist/runtime/adapter/flow/stream-runtime.js +11 -1395
- package/dist/runtime/adapter/invocation-result.js +2 -473
- package/dist/runtime/adapter/local-tool-invocation.js +6 -638
- package/dist/runtime/adapter/middleware/context-hygiene.js +1 -83
- package/dist/runtime/adapter/middleware-assembly.js +5 -477
- package/dist/runtime/adapter/model/invocation-request.js +3 -183
- package/dist/runtime/adapter/model/message-assembly.js +1 -28
- package/dist/runtime/adapter/model/model-providers.js +23 -1115
- package/dist/runtime/adapter/model/prompted-json-tool-call-capture.js +1 -40
- package/dist/runtime/adapter/model/prompted-json-tool-policy.js +1 -22
- package/dist/runtime/adapter/resilience.js +1 -104
- package/dist/runtime/adapter/runtime-adapter-support.js +3 -141
- package/dist/runtime/adapter/runtime-shell.js +5 -166
- package/dist/runtime/adapter/stream-event-projection.js +2 -622
- package/dist/runtime/adapter/stream-text-consumption.js +1 -18
- package/dist/runtime/adapter/terminal-status.js +2 -67
- package/dist/runtime/adapter/tool/builtin-middleware-tools.js +6 -627
- package/dist/runtime/adapter/tool/declared-middleware.js +1 -154
- package/dist/runtime/adapter/tool/interrupt-policy.js +1 -34
- package/dist/runtime/adapter/tool/provider-tool.js +1 -25
- package/dist/runtime/adapter/tool/resolved-tool.js +1 -225
- package/dist/runtime/adapter/tool/tool-arguments.js +3 -486
- package/dist/runtime/adapter/tool/tool-hitl.js +1 -346
- package/dist/runtime/adapter/tool/tool-name-mapping.js +1 -128
- package/dist/runtime/adapter/tool/tool-output-artifacts.js +2 -88
- package/dist/runtime/adapter/tool/tool-replay.js +1 -37
- package/dist/runtime/adapter/tool-resolution.js +1 -86
- package/dist/runtime/adapter/upstream-configurable-keys.js +1 -2
- package/dist/runtime/agent-runtime-adapter.js +60 -2338
- package/dist/runtime/agent-runtime-assembly.js +7 -249
- package/dist/runtime/env/runtime-env.js +1 -62
- package/dist/runtime/harness/background-runtime.js +1 -8
- package/dist/runtime/harness/bindings.js +1 -58
- package/dist/runtime/harness/events/event-bus.js +1 -16
- package/dist/runtime/harness/events/event-sink.js +1 -61
- package/dist/runtime/harness/events/events.js +1 -80
- package/dist/runtime/harness/events/listener-runtime.js +1 -13
- package/dist/runtime/harness/events/runtime-event-operations.js +1 -9
- package/dist/runtime/harness/events/streaming.js +1 -100
- package/dist/runtime/harness/events/timeline.js +1 -52
- package/dist/runtime/harness/public-shapes.js +1 -186
- package/dist/runtime/harness/run/artifact-paths.js +1 -15
- package/dist/runtime/harness/run/governance.js +1 -295
- package/dist/runtime/harness/run/helpers.js +1 -71
- package/dist/runtime/harness/run/inspection.js +1 -409
- package/dist/runtime/harness/run/operator-overview.js +1 -80
- package/dist/runtime/harness/run/queue-diagnostics.js +1 -15
- package/dist/runtime/harness/run/recovery.js +1 -162
- package/dist/runtime/harness/run/resources.js +1 -60
- package/dist/runtime/harness/run/resume.js +1 -56
- package/dist/runtime/harness/run/routing.js +1 -48
- package/dist/runtime/harness/run/run-lifecycle.js +1 -66
- package/dist/runtime/harness/run/run-operations.js +1 -217
- package/dist/runtime/harness/run/run-queue.js +1 -43
- package/dist/runtime/harness/run/run-slot-acquisition.js +1 -157
- package/dist/runtime/harness/run/session-records.js +1 -97
- package/dist/runtime/harness/run/start-run.js +1 -120
- package/dist/runtime/harness/run/startup-runtime.js +1 -69
- package/dist/runtime/harness/run/stream-run.js +8 -1418
- package/dist/runtime/harness/run/surface-semantics.js +1 -79
- package/dist/runtime/harness/runtime-defaults.js +1 -39
- package/dist/runtime/harness/system/boundary-analysis.js +1 -234
- package/dist/runtime/harness/system/health-monitor.js +1 -258
- package/dist/runtime/harness/system/inventory.js +1 -129
- package/dist/runtime/harness/system/mem0-ingestion-sync.js +5 -345
- package/dist/runtime/harness/system/policy-engine.js +1 -175
- package/dist/runtime/harness/system/runtime-memory-candidates.js +4 -110
- package/dist/runtime/harness/system/runtime-memory-consolidation.js +1 -51
- package/dist/runtime/harness/system/runtime-memory-manager.js +10 -693
- package/dist/runtime/harness/system/runtime-memory-policy.js +1 -155
- package/dist/runtime/harness/system/runtime-memory-records.js +11 -577
- package/dist/runtime/harness/system/runtime-memory-sync.js +5 -206
- package/dist/runtime/harness/system/session-memory-sync.js +3 -113
- package/dist/runtime/harness/system/skill-requirements.js +1 -112
- package/dist/runtime/harness/system/store.js +9 -365
- package/dist/runtime/harness/tool-gateway/index.js +1 -2
- package/dist/runtime/harness/tool-gateway/policy.js +1 -45
- package/dist/runtime/harness/tool-gateway/validation.js +1 -176
- package/dist/runtime/harness/tool-schema.js +1 -3
- package/dist/runtime/harness.js +3 -1490
- package/dist/runtime/index.js +1 -3
- package/dist/runtime/layout/runtime-layout.js +1 -31
- package/dist/runtime/maintenance/checkpoint-maintenance.js +2 -178
- package/dist/runtime/maintenance/file-checkpoint-saver.js +1 -106
- package/dist/runtime/maintenance/runtime-record-maintenance.js +2 -169
- package/dist/runtime/maintenance/sqlite-checkpoint-saver.js +4 -289
- package/dist/runtime/parsing/output-content.js +10 -550
- package/dist/runtime/parsing/output-parsing.js +1 -4
- package/dist/runtime/parsing/output-recovery.js +3 -213
- package/dist/runtime/parsing/output-tool-args.js +7 -663
- package/dist/runtime/parsing/stream-event-parsing.js +3 -362
- package/dist/runtime/prompts/runtime-prompts.js +4 -73
- package/dist/runtime/scheduling/system-schedule-manager.js +11 -532
- package/dist/runtime/skills/skill-metadata.js +1 -197
- package/dist/runtime/startup-tracing.js +2 -37
- package/dist/runtime/support/compiled-binding.js +1 -290
- package/dist/runtime/support/embedding-models.js +1 -118
- package/dist/runtime/support/harness-support.js +5 -137
- package/dist/runtime/support/llamaindex.js +1 -108
- package/dist/runtime/support/runtime-adapter-options.js +1 -29
- package/dist/runtime/support/runtime-factories.js +1 -51
- package/dist/runtime/support/vector-stores.js +9 -270
- package/dist/scaffold/init-project.js +54 -233
- package/dist/tooling/extensions.js +1 -311
- package/dist/tooling/module-loader.js +1 -55
- package/dist/tools.js +1 -176
- package/dist/utils/agent-display.js +1 -18
- package/dist/utils/bundled-text.js +4 -39
- package/dist/utils/compiled-binding.js +1 -33
- package/dist/utils/fs.js +2 -45
- package/dist/utils/id.js +1 -9
- package/dist/utils/message-content.js +1 -30
- package/dist/utils/object.js +1 -6
- package/dist/workspace/agent-binding-compiler.js +3 -613
- package/dist/workspace/compile.js +1 -472
- package/dist/workspace/framework-contract-validation.js +2 -322
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/object-loader-paths.js +1 -71
- package/dist/workspace/object-loader-readers.js +1 -187
- package/dist/workspace/object-loader.js +1 -754
- package/dist/workspace/resource-compilers.js +1 -374
- package/dist/workspace/support/agent-capabilities.js +1 -37
- package/dist/workspace/support/agent-execution-config.js +1 -44
- package/dist/workspace/support/discovery.js +1 -147
- package/dist/workspace/support/source-collectors.js +1 -30
- package/dist/workspace/support/source-protocols.js +2 -192
- package/dist/workspace/support/workspace-ref-utils.js +1 -362
- package/dist/workspace/tool-hydration.js +1 -280
- package/dist/workspace/validate.js +1 -99
- package/dist/workspace/yaml-object-reader.js +1 -285
- package/package.json +7 -3
|
@@ -1,325 +1,2 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
"ls",
|
|
4
|
-
"read-file",
|
|
5
|
-
"write-file",
|
|
6
|
-
"task",
|
|
7
|
-
"glob",
|
|
8
|
-
"grep",
|
|
9
|
-
"bash",
|
|
10
|
-
"sh",
|
|
11
|
-
"cat",
|
|
12
|
-
]);
|
|
13
|
-
function sanitizeAlias(value) {
|
|
14
|
-
return value.replace(/[^A-Za-z0-9_]/g, "_");
|
|
15
|
-
}
|
|
16
|
-
function escapeLabel(value) {
|
|
17
|
-
return value.replace(/"/g, '\\"');
|
|
18
|
-
}
|
|
19
|
-
function formatAgentParticipantLabel(node) {
|
|
20
|
-
const agentId = node.agentId ?? "agent";
|
|
21
|
-
if (node.agentName && node.agentName !== agentId) {
|
|
22
|
-
return `Agent:${agentId} (${node.agentName})`;
|
|
23
|
-
}
|
|
24
|
-
return `Agent:${agentId}`;
|
|
25
|
-
}
|
|
26
|
-
function nodeIdentity(node) {
|
|
27
|
-
if (node.kind === "agent") {
|
|
28
|
-
const fromAgentId = typeof node.detail.fromAgentId === "string" ? node.detail.fromAgentId : "agent";
|
|
29
|
-
const toAgentId = node.agentId ?? "agent";
|
|
30
|
-
return `${node.kind}:${fromAgentId}:${toAgentId}`;
|
|
31
|
-
}
|
|
32
|
-
return `${node.kind}:${node.agentId ?? "-"}:${node.label}`;
|
|
33
|
-
}
|
|
34
|
-
function collapseProductNodes(nodes) {
|
|
35
|
-
const selected = new Map();
|
|
36
|
-
for (const node of nodes) {
|
|
37
|
-
const key = nodeIdentity(node);
|
|
38
|
-
const existing = selected.get(key);
|
|
39
|
-
if (!existing) {
|
|
40
|
-
selected.set(key, node);
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
const existingCompleted = existing.status === "completed";
|
|
44
|
-
const nodeCompleted = node.status === "completed";
|
|
45
|
-
const preferCompleted = !existingCompleted && nodeCompleted;
|
|
46
|
-
const preserveCompleted = existingCompleted && !nodeCompleted;
|
|
47
|
-
const preferLatest = !preserveCompleted && (existing.sequenceEnd ?? 0) <= (node.sequenceEnd ?? 0);
|
|
48
|
-
if (preferCompleted || preferLatest) {
|
|
49
|
-
selected.set(key, node);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return [...selected.values()].sort((left, right) => (left.sequenceStart ?? 0) - (right.sequenceStart ?? 0));
|
|
53
|
-
}
|
|
54
|
-
function findDelegationCarrierToolNodeIds(nodes) {
|
|
55
|
-
const delegationSourceEventIds = new Set(nodes
|
|
56
|
-
.filter((node) => node.kind === "agent")
|
|
57
|
-
.flatMap((node) => node.sourceEventIds));
|
|
58
|
-
return new Set(nodes
|
|
59
|
-
.filter((node) => node.kind === "tool" && node.sourceEventIds.some((id) => delegationSourceEventIds.has(id)))
|
|
60
|
-
.map((node) => node.id));
|
|
61
|
-
}
|
|
62
|
-
function trimToolNodesForProductView(nodes, delegatingAgentIds) {
|
|
63
|
-
const keptToolKeys = new Set();
|
|
64
|
-
const orderedToolKeysByAgentId = new Map();
|
|
65
|
-
const toolKeyByNodeId = new Map();
|
|
66
|
-
const genericToolKeysByAgentId = new Map();
|
|
67
|
-
for (const node of nodes) {
|
|
68
|
-
if (node.kind !== "tool") {
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
const agentId = node.agentId ?? "";
|
|
72
|
-
const toolName = (() => {
|
|
73
|
-
if (typeof node.detail.toolName === "string" && node.detail.toolName.trim().length > 0) {
|
|
74
|
-
return node.detail.toolName.trim();
|
|
75
|
-
}
|
|
76
|
-
const labelMatch = /^(?:Calling|Completed) tool (.+?)(?: \[[^\]]+\])?$/i.exec(node.label);
|
|
77
|
-
return labelMatch?.[1]?.trim() || node.label;
|
|
78
|
-
})();
|
|
79
|
-
const normalizedToolName = toolName.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
80
|
-
const toolKey = `${agentId}:${normalizedToolName}`;
|
|
81
|
-
toolKeyByNodeId.set(node.id, toolKey);
|
|
82
|
-
if (GENERIC_PRODUCT_TOOL_FAMILIES.has(normalizedToolName)) {
|
|
83
|
-
let genericToolKeys = genericToolKeysByAgentId.get(agentId);
|
|
84
|
-
if (!genericToolKeys) {
|
|
85
|
-
genericToolKeys = new Set();
|
|
86
|
-
genericToolKeysByAgentId.set(agentId, genericToolKeys);
|
|
87
|
-
}
|
|
88
|
-
genericToolKeys.add(toolKey);
|
|
89
|
-
}
|
|
90
|
-
const toolKeys = orderedToolKeysByAgentId.get(agentId);
|
|
91
|
-
if (toolKeys) {
|
|
92
|
-
if (!toolKeys.includes(toolKey)) {
|
|
93
|
-
toolKeys.push(toolKey);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
orderedToolKeysByAgentId.set(agentId, [toolKey]);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
for (const [agentId, toolKeys] of orderedToolKeysByAgentId.entries()) {
|
|
101
|
-
const genericToolKeys = genericToolKeysByAgentId.get(agentId) ?? new Set();
|
|
102
|
-
const preferredToolKeys = toolKeys.filter((toolKey) => !genericToolKeys.has(toolKey));
|
|
103
|
-
const selectedToolKeys = preferredToolKeys.length > 0
|
|
104
|
-
? preferredToolKeys.slice(-2)
|
|
105
|
-
: delegatingAgentIds.has(agentId)
|
|
106
|
-
? []
|
|
107
|
-
: toolKeys.slice(-2);
|
|
108
|
-
selectedToolKeys.forEach((toolKey) => keptToolKeys.add(toolKey));
|
|
109
|
-
}
|
|
110
|
-
return nodes.filter((node) => node.kind !== "tool" || keptToolKeys.has(toolKeyByNodeId.get(node.id) ?? ""));
|
|
111
|
-
}
|
|
112
|
-
function selectNodes(graph, options) {
|
|
113
|
-
const includedKinds = options.includeKinds
|
|
114
|
-
? new Set(options.includeKinds)
|
|
115
|
-
: options.view === "debug"
|
|
116
|
-
? null
|
|
117
|
-
: PRODUCT_VIEW_KINDS;
|
|
118
|
-
const filtered = graph.nodes.filter((node) => {
|
|
119
|
-
if (node.layer === "detail") {
|
|
120
|
-
return false;
|
|
121
|
-
}
|
|
122
|
-
if (includedKinds) {
|
|
123
|
-
return includedKinds.has(node.kind);
|
|
124
|
-
}
|
|
125
|
-
return node.kind === "request"
|
|
126
|
-
|| node.kind === "agent"
|
|
127
|
-
|| node.kind === "approval"
|
|
128
|
-
|| node.kind === "recovery"
|
|
129
|
-
|| node.kind === "llm"
|
|
130
|
-
|| node.kind === "tool"
|
|
131
|
-
|| node.kind === "skill"
|
|
132
|
-
|| node.kind === "memory"
|
|
133
|
-
|| node.kind === "artifact";
|
|
134
|
-
});
|
|
135
|
-
if (options.view === "debug") {
|
|
136
|
-
return filtered;
|
|
137
|
-
}
|
|
138
|
-
const collapsedNodes = collapseProductNodes(filtered);
|
|
139
|
-
const delegationCarrierToolNodeIds = findDelegationCarrierToolNodeIds(collapsedNodes);
|
|
140
|
-
const delegatingAgentIds = new Set(collapsedNodes
|
|
141
|
-
.filter((node) => node.kind === "agent" && typeof node.detail.fromAgentId === "string")
|
|
142
|
-
.map((node) => node.detail.fromAgentId));
|
|
143
|
-
const productNodes = collapsedNodes.filter((node) => node.kind === "agent" || !delegationCarrierToolNodeIds.has(node.id));
|
|
144
|
-
return trimToolNodesForProductView(productNodes, delegatingAgentIds);
|
|
145
|
-
}
|
|
146
|
-
function getParticipantsForNode(node) {
|
|
147
|
-
const runtimeParticipant = { id: "runtime", alias: "Runtime", label: "Runtime" };
|
|
148
|
-
const agentParticipant = {
|
|
149
|
-
id: `agent:${node.agentId ?? "agent"}`,
|
|
150
|
-
alias: sanitizeAlias(`Agent_${node.agentId ?? "agent"}`),
|
|
151
|
-
label: formatAgentParticipantLabel(node),
|
|
152
|
-
};
|
|
153
|
-
if (node.kind === "request") {
|
|
154
|
-
return [
|
|
155
|
-
{ id: "user", alias: "User", label: "User" },
|
|
156
|
-
runtimeParticipant,
|
|
157
|
-
agentParticipant,
|
|
158
|
-
];
|
|
159
|
-
}
|
|
160
|
-
if (node.kind === "agent") {
|
|
161
|
-
const fromAgentId = typeof node.detail.fromAgentId === "string" ? node.detail.fromAgentId : "agent";
|
|
162
|
-
return [
|
|
163
|
-
{
|
|
164
|
-
id: `agent:${fromAgentId}`,
|
|
165
|
-
alias: sanitizeAlias(`Agent_${fromAgentId}`),
|
|
166
|
-
label: typeof node.detail.fromAgentName === "string" && node.detail.fromAgentName !== fromAgentId
|
|
167
|
-
? `Agent:${fromAgentId} (${node.detail.fromAgentName})`
|
|
168
|
-
: `Agent:${fromAgentId}`,
|
|
169
|
-
},
|
|
170
|
-
agentParticipant,
|
|
171
|
-
];
|
|
172
|
-
}
|
|
173
|
-
if (node.kind === "approval") {
|
|
174
|
-
return [
|
|
175
|
-
runtimeParticipant,
|
|
176
|
-
{ id: "operator", alias: "Operator", label: "Operator" },
|
|
177
|
-
];
|
|
178
|
-
}
|
|
179
|
-
if (node.kind === "llm") {
|
|
180
|
-
return [
|
|
181
|
-
agentParticipant,
|
|
182
|
-
{ id: "model", alias: "Model", label: "Model" },
|
|
183
|
-
];
|
|
184
|
-
}
|
|
185
|
-
if (node.kind === "tool") {
|
|
186
|
-
return [
|
|
187
|
-
agentParticipant,
|
|
188
|
-
{
|
|
189
|
-
id: `tool:${node.label}`,
|
|
190
|
-
alias: sanitizeAlias(`Tool_${node.label}`),
|
|
191
|
-
label: `Tool:${node.label.replace(/\s+\[[^\]]+\]$/, "")}`,
|
|
192
|
-
},
|
|
193
|
-
];
|
|
194
|
-
}
|
|
195
|
-
if (node.kind === "skill") {
|
|
196
|
-
return [
|
|
197
|
-
agentParticipant,
|
|
198
|
-
{ id: "skill", alias: "Skill", label: "Skill" },
|
|
199
|
-
];
|
|
200
|
-
}
|
|
201
|
-
if (node.kind === "memory") {
|
|
202
|
-
return [
|
|
203
|
-
agentParticipant,
|
|
204
|
-
{ id: "memory", alias: "Memory", label: "Memory" },
|
|
205
|
-
];
|
|
206
|
-
}
|
|
207
|
-
if (node.kind === "recovery") {
|
|
208
|
-
return [
|
|
209
|
-
runtimeParticipant,
|
|
210
|
-
agentParticipant,
|
|
211
|
-
];
|
|
212
|
-
}
|
|
213
|
-
if (node.kind === "artifact") {
|
|
214
|
-
return [
|
|
215
|
-
runtimeParticipant,
|
|
216
|
-
{ id: "artifact", alias: "ArtifactStore", label: "ArtifactStore" },
|
|
217
|
-
];
|
|
218
|
-
}
|
|
219
|
-
return [runtimeParticipant, agentParticipant];
|
|
220
|
-
}
|
|
221
|
-
function renderArrowForNode(node) {
|
|
222
|
-
if (node.kind === "request" && node.status === "started") {
|
|
223
|
-
return { from: "User", to: "Runtime", text: node.label };
|
|
224
|
-
}
|
|
225
|
-
if (node.kind === "request" && (node.status === "completed" || node.status === "failed")) {
|
|
226
|
-
return { from: "Runtime", to: "User", text: node.label };
|
|
227
|
-
}
|
|
228
|
-
if (node.kind === "agent") {
|
|
229
|
-
const fromAgentId = typeof node.detail.fromAgentId === "string" ? node.detail.fromAgentId : "agent";
|
|
230
|
-
return {
|
|
231
|
-
from: sanitizeAlias(`Agent_${fromAgentId}`),
|
|
232
|
-
to: sanitizeAlias(`Agent_${node.agentId ?? "agent"}`),
|
|
233
|
-
text: node.label,
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
if (node.kind === "approval" && node.status === "waiting") {
|
|
237
|
-
return { from: "Runtime", to: "Operator", text: node.label };
|
|
238
|
-
}
|
|
239
|
-
if (node.kind === "approval" && node.status === "resolved") {
|
|
240
|
-
return { from: "Operator", to: "Runtime", text: node.label };
|
|
241
|
-
}
|
|
242
|
-
if (node.kind === "recovery") {
|
|
243
|
-
return { from: "Runtime", to: sanitizeAlias(`Agent_${node.agentId ?? "agent"}`), text: node.label };
|
|
244
|
-
}
|
|
245
|
-
if (node.kind === "llm") {
|
|
246
|
-
return {
|
|
247
|
-
from: sanitizeAlias(`Agent_${node.agentId ?? "agent"}`),
|
|
248
|
-
to: "Model",
|
|
249
|
-
text: node.label,
|
|
250
|
-
dashed: node.status === "completed" || node.status === "failed",
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
if (node.kind === "tool") {
|
|
254
|
-
return {
|
|
255
|
-
from: sanitizeAlias(`Agent_${node.agentId ?? "agent"}`),
|
|
256
|
-
to: sanitizeAlias(`Tool_${node.label}`),
|
|
257
|
-
text: node.label,
|
|
258
|
-
dashed: node.status === "completed" || node.status === "failed",
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
if (node.kind === "skill") {
|
|
262
|
-
return {
|
|
263
|
-
from: sanitizeAlias(`Agent_${node.agentId ?? "agent"}`),
|
|
264
|
-
to: "Skill",
|
|
265
|
-
text: node.label,
|
|
266
|
-
dashed: node.status === "completed" || node.status === "failed",
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
if (node.kind === "memory") {
|
|
270
|
-
return {
|
|
271
|
-
from: sanitizeAlias(`Agent_${node.agentId ?? "agent"}`),
|
|
272
|
-
to: "Memory",
|
|
273
|
-
text: node.label,
|
|
274
|
-
dashed: node.status === "completed" || node.status === "failed",
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
if (node.kind === "artifact") {
|
|
278
|
-
return { from: "Runtime", to: "ArtifactStore", text: node.label };
|
|
279
|
-
}
|
|
280
|
-
return { from: "Runtime", to: sanitizeAlias(`Agent_${node.agentId ?? "agent"}`), text: node.label };
|
|
281
|
-
}
|
|
282
|
-
function getRuntimeSurface(graph) {
|
|
283
|
-
const runtimeSurface = graph.metadata.runtimeSurface;
|
|
284
|
-
return Array.isArray(runtimeSurface) ? runtimeSurface : [];
|
|
285
|
-
}
|
|
286
|
-
export function exportFlowGraphToSequenceMermaid(graph, options = {}) {
|
|
287
|
-
const nodes = selectNodes(graph, options);
|
|
288
|
-
const productView = (options.view ?? "product") === "product";
|
|
289
|
-
const lines = ["sequenceDiagram"];
|
|
290
|
-
const participants = new Map();
|
|
291
|
-
for (const node of nodes) {
|
|
292
|
-
for (const participant of getParticipantsForNode(node)) {
|
|
293
|
-
participants.set(participant.id, participant);
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
for (const participant of participants.values()) {
|
|
297
|
-
lines.push(` participant ${participant.alias} as ${escapeLabel(participant.label)}`);
|
|
298
|
-
}
|
|
299
|
-
for (const node of nodes) {
|
|
300
|
-
const arrow = renderArrowForNode(node);
|
|
301
|
-
const connector = arrow.dashed ? "-->>" : "->>";
|
|
302
|
-
lines.push(` ${arrow.from}${connector}${arrow.to}: ${escapeLabel(node.label)}`);
|
|
303
|
-
}
|
|
304
|
-
if (productView) {
|
|
305
|
-
const seenReturnPairs = new Set();
|
|
306
|
-
for (const item of getRuntimeSurface(graph)) {
|
|
307
|
-
if (item.kind !== "agent" || item.status !== "completed") {
|
|
308
|
-
continue;
|
|
309
|
-
}
|
|
310
|
-
const fromAgentId = item.ownerAgentId ?? null;
|
|
311
|
-
const toAgentId = item.agentId ?? null;
|
|
312
|
-
if (!fromAgentId || !toAgentId) {
|
|
313
|
-
continue;
|
|
314
|
-
}
|
|
315
|
-
const pairKey = `${fromAgentId}:${toAgentId}`;
|
|
316
|
-
if (seenReturnPairs.has(pairKey)) {
|
|
317
|
-
continue;
|
|
318
|
-
}
|
|
319
|
-
seenReturnPairs.add(pairKey);
|
|
320
|
-
const fromAgentName = item.ownerAgentName ?? fromAgentId;
|
|
321
|
-
lines.push(` ${sanitizeAlias(`Agent_${toAgentId}`)}-->>${sanitizeAlias(`Agent_${fromAgentId}`)}: Return to ${escapeLabel(fromAgentName)}`);
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
return lines.join("\n");
|
|
325
|
-
}
|
|
1
|
+
const p=new Set(["agent","tool","skill","memory"]),k=new Set(["ls","read-file","write-file","task","glob","grep","bash","sh","cat"]);function o(t){return t.replace(/[^A-Za-z0-9_]/g,"_")}function m(t){return t.replace(/"/g,'\\"')}function A(t){const a=t.agentId??"agent";return t.agentName&&t.agentName!==a?`Agent:${a} (${t.agentName})`:`Agent:${a}`}function I(t){if(t.kind==="agent"){const a=typeof t.detail.fromAgentId=="string"?t.detail.fromAgentId:"agent",e=t.agentId??"agent";return`${t.kind}:${a}:${e}`}return`${t.kind}:${t.agentId??"-"}:${t.label}`}function $(t){const a=new Map;for(const e of t){const l=I(e),s=a.get(l);if(!s){a.set(l,e);continue}const c=s.status==="completed",r=e.status==="completed",i=!c&&r,f=!(c&&!r)&&(s.sequenceEnd??0)<=(e.sequenceEnd??0);(i||f)&&a.set(l,e)}return[...a.values()].sort((e,l)=>(e.sequenceStart??0)-(l.sequenceStart??0))}function b(t){const a=new Set(t.filter(e=>e.kind==="agent").flatMap(e=>e.sourceEventIds));return new Set(t.filter(e=>e.kind==="tool"&&e.sourceEventIds.some(l=>a.has(l))).map(e=>e.id))}function y(t,a){const e=new Set,l=new Map,s=new Map,c=new Map;for(const r of t){if(r.kind!=="tool")continue;const i=r.agentId??"",f=(typeof r.detail.toolName=="string"&&r.detail.toolName.trim().length>0?r.detail.toolName.trim():/^(?:Calling|Completed) tool (.+?)(?: \[[^\]]+\])?$/i.exec(r.label)?.[1]?.trim()||r.label).toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,""),u=`${i}:${f}`;if(s.set(r.id,u),k.has(f)){let d=c.get(i);d||(d=new Set,c.set(i,d)),d.add(u)}const g=l.get(i);g?g.includes(u)||g.push(u):l.set(i,[u])}for(const[r,i]of l.entries()){const n=c.get(r)??new Set,f=i.filter(g=>!n.has(g));(f.length>0?f.slice(-2):a.has(r)?[]:i.slice(-2)).forEach(g=>e.add(g))}return t.filter(r=>r.kind!=="tool"||e.has(s.get(r.id)??""))}function w(t,a){const e=a.includeKinds?new Set(a.includeKinds):a.view==="debug"?null:p,l=t.nodes.filter(n=>n.layer==="detail"?!1:e?e.has(n.kind):n.kind==="request"||n.kind==="agent"||n.kind==="approval"||n.kind==="recovery"||n.kind==="llm"||n.kind==="tool"||n.kind==="skill"||n.kind==="memory"||n.kind==="artifact");if(a.view==="debug")return l;const s=$(l),c=b(s),r=new Set(s.filter(n=>n.kind==="agent"&&typeof n.detail.fromAgentId=="string").map(n=>n.detail.fromAgentId)),i=s.filter(n=>n.kind==="agent"||!c.has(n.id));return y(i,r)}function N(t){const a={id:"runtime",alias:"Runtime",label:"Runtime"},e={id:`agent:${t.agentId??"agent"}`,alias:o(`Agent_${t.agentId??"agent"}`),label:A(t)};if(t.kind==="request")return[{id:"user",alias:"User",label:"User"},a,e];if(t.kind==="agent"){const l=typeof t.detail.fromAgentId=="string"?t.detail.fromAgentId:"agent";return[{id:`agent:${l}`,alias:o(`Agent_${l}`),label:typeof t.detail.fromAgentName=="string"&&t.detail.fromAgentName!==l?`Agent:${l} (${t.detail.fromAgentName})`:`Agent:${l}`},e]}return t.kind==="approval"?[a,{id:"operator",alias:"Operator",label:"Operator"}]:t.kind==="llm"?[e,{id:"model",alias:"Model",label:"Model"}]:t.kind==="tool"?[e,{id:`tool:${t.label}`,alias:o(`Tool_${t.label}`),label:`Tool:${t.label.replace(/\s+\[[^\]]+\]$/,"")}`}]:t.kind==="skill"?[e,{id:"skill",alias:"Skill",label:"Skill"}]:t.kind==="memory"?[e,{id:"memory",alias:"Memory",label:"Memory"}]:t.kind==="recovery"?[a,e]:t.kind==="artifact"?[a,{id:"artifact",alias:"ArtifactStore",label:"ArtifactStore"}]:[a,e]}function S(t){if(t.kind==="request"&&t.status==="started")return{from:"User",to:"Runtime",text:t.label};if(t.kind==="request"&&(t.status==="completed"||t.status==="failed"))return{from:"Runtime",to:"User",text:t.label};if(t.kind==="agent"){const a=typeof t.detail.fromAgentId=="string"?t.detail.fromAgentId:"agent";return{from:o(`Agent_${a}`),to:o(`Agent_${t.agentId??"agent"}`),text:t.label}}return t.kind==="approval"&&t.status==="waiting"?{from:"Runtime",to:"Operator",text:t.label}:t.kind==="approval"&&t.status==="resolved"?{from:"Operator",to:"Runtime",text:t.label}:t.kind==="recovery"?{from:"Runtime",to:o(`Agent_${t.agentId??"agent"}`),text:t.label}:t.kind==="llm"?{from:o(`Agent_${t.agentId??"agent"}`),to:"Model",text:t.label,dashed:t.status==="completed"||t.status==="failed"}:t.kind==="tool"?{from:o(`Agent_${t.agentId??"agent"}`),to:o(`Tool_${t.label}`),text:t.label,dashed:t.status==="completed"||t.status==="failed"}:t.kind==="skill"?{from:o(`Agent_${t.agentId??"agent"}`),to:"Skill",text:t.label,dashed:t.status==="completed"||t.status==="failed"}:t.kind==="memory"?{from:o(`Agent_${t.agentId??"agent"}`),to:"Memory",text:t.label,dashed:t.status==="completed"||t.status==="failed"}:t.kind==="artifact"?{from:"Runtime",to:"ArtifactStore",text:t.label}:{from:"Runtime",to:o(`Agent_${t.agentId??"agent"}`),text:t.label}}function h(t){const a=t.metadata.runtimeSurface;return Array.isArray(a)?a:[]}function _(t,a={}){const e=w(t,a),l=(a.view??"product")==="product",s=["sequenceDiagram"],c=new Map;for(const r of e)for(const i of N(r))c.set(i.id,i);for(const r of c.values())s.push(` participant ${r.alias} as ${m(r.label)}`);for(const r of e){const i=S(r),n=i.dashed?"-->>":"->>";s.push(` ${i.from}${n}${i.to}: ${m(r.label)}`)}if(l){const r=new Set;for(const i of h(t)){if(i.kind!=="agent"||i.status!=="completed")continue;const n=i.ownerAgentId??null,f=i.agentId??null;if(!n||!f)continue;const u=`${n}:${f}`;if(r.has(u))continue;r.add(u);const g=i.ownerAgentName??n;s.push(` ${o(`Agent_${f}`)}-->>${o(`Agent_${n}`)}: Return to ${m(g)}`)}}return s.join(`
|
|
2
|
+
`)}export{_ as exportFlowGraphToSequenceMermaid};
|
|
@@ -1,214 +1 @@
|
|
|
1
|
-
import
|
|
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
|
-
}
|
|
1
|
+
import{formatAgentName as c}from"../utils/agent-display.js";function i(e){return typeof e=="object"&&e!==null?e:null}function s(e){return typeof e=="string"&&e.trim().length>0?e.trim():null}function m(e){const t=i(e),r=t&&Object.prototype.hasOwnProperty.call(t,"event")?t.event:void 0,a=i(t?.surfaceItem),l=t&&r&&typeof r=="object"&&!Array.isArray(r)?r:e,o=s(t?.agentId)??s(a?.agentId),n=s(t?.agentName)??s(a?.agentName);return{event:l,agentId:o??void 0,agentName:n??void 0,...a?{surfaceItem:a}:{}}}function y(e){return e}function I(e){return e.map(t=>{const r=t,a=s(r.sessionId)??"",l=s(r.requestId)??"";return{eventId:String(t.eventId),eventType:String(t.eventType),timestamp:String(t.timestamp),sessionId:a,requestId:l,sequence:Number(t.sequence),source:t.source,payload:t.payload??{}}})}function u(e,t=new Set){if(Array.isArray(e)){for(const n of e)u(n,t);return t}const r=i(e);if(!r)return t;const a=Array.isArray(r.id)?r.id.filter(n=>typeof n=="string"):[],l=i(r.kwargs),o=a.includes("AIMessage")?s(l?.name):null;o&&o!=="assistant"&&t.add(o);for(const n of Object.values(r))u(n,t);return t}function q(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,80)||"node"}function d(e){return e.replace(/[_-]+/g," ").replace(/\s+/g," ").trim().split(" ").filter(Boolean).map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" ")}function p(e){return e.replace(/\s+/g," ").trim()}function v(e){return e.sessionId}function b(e){return e.requestId}function k(e){return e.type==="step"?e.step:e.type==="tool-result"?`Tool result ${d(e.toolName)}`:e.text}function A(e){return e.type==="tool-result"?"result":e.type==="thinking"?"thinking":e.category}function x(e){return e.type==="thinking"||e.type==="tool-result"?"completed":e.category==="approval"&&e.status==="started"?"waiting":e.status}function T(e){if(e.eventType==="request.created")return{kind:"request",status:"started",label:"Request created",detail:e.payload};if(e.eventType==="request.queued")return{kind:"queue",status:"waiting",label:"Queued",detail:e.payload};if(e.eventType==="request.dequeued")return{kind:"queue",status:"completed",label:"Dequeued",detail:e.payload};if(e.eventType==="approval.requested")return{kind:"approval",status:"waiting",label:"Approval requested",detail:e.payload};if(e.eventType==="approval.resolved")return{kind:"approval",status:"resolved",label:"Approval resolved",detail:e.payload};if(e.eventType==="request.resumed")return{kind:"recovery",status:"completed",label:"Request resumed",detail:e.payload};if(e.eventType==="artifact.created")return{kind:"artifact",status:"completed",label:"Artifact created",detail:e.payload};if(e.eventType==="request.state.changed"){const t=typeof e.payload.state=="string"?e.payload.state:"";return t==="waiting_for_approval"?{kind:"approval",status:"waiting",label:"Waiting for approval",detail:e.payload}:t==="failed"?{kind:"request",status:"failed",label:"Request failed",detail:e.payload}:t==="completed"?{kind:"request",status:"completed",label:"Request completed",detail:e.payload}:{kind:"request",status:"started",label:t?`Request ${t}`:"Request state changed",detail:e.payload}}return{kind:e.kind,status:"completed",label:e.eventType,detail:e.payload}}function h(e,t){if(t.type==="step"){const r=p(t.step);if(r)return r}return t.type==="tool-result"?`Tool ${d(t.toolName)}`:t.type==="thinking"?"Model reasoning":d(e)}function f(e,t){const r=p(t).replace(/^Calling LLM\s+/i,"").replace(/^Completed LLM\s+/i,"").replace(/^Calling tool\s+/i,"").replace(/^Completed tool\s+/i,"").replace(/^Tool\s+/i,"").replace(/\s+failed$/i,"").replace(/^Calling skill\s+/i,"").replace(/^Completed skill\s+/i,"").replace(/^Accessing memory\s+/i,"").replace(/^Completed memory\s+/i,"").replace(/^Running\s+/i,"").replace(/^Completed\s+/i,"");return`${e}:${r.toLowerCase()}`}function w(e){return e.toLowerCase().replace(/[_-]+/g," ").replace(/\s+/g," ").trim()}function C(e,t,r){return`${f(e,t)}:${r??"ungrouped"}`}function N(e,t){const r=t.find(o=>{const n=i(o.payload);return typeof n?.agentId=="string"&&n.agentId.trim().length>0}),a=r?i(r.payload):null,l=typeof e.metadata?.currentAgentId=="string"?e.metadata.currentAgentId:null;return l&&l.trim().length>0?l.trim():a?.agentId&&typeof a.agentId=="string"&&a.agentId.trim().length>0?a.agentId.trim():"agent"}function L(e,t){return t&&t.trim().length>0?t.trim():c(e)}export{i as asObject,C as buildAttemptKey,u as collectNestedAgentNames,L as deriveAgentName,N as deriveInitialAgentId,A as deriveNodeKindFromProjection,T as deriveRuntimeNode,x as deriveStatusFromProjection,m as extractUpstreamEventEnvelope,h as normalizeAttemptLabel,p as normalizeLabel,I as normalizeRuntimeEvents,w as normalizeToolIdentity,k as readProjectionLabel,b as readRequestId,v as readSessionId,s as readString,f as semanticNameFromLabel,q as slugify,d as titleCase};
|
|
@@ -1,107 +1 @@
|
|
|
1
|
-
import
|
|
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
|
-
}
|
|
1
|
+
import{deriveRuntimeNode as c,slugify as m}from"./flow-graph-normalization.js";function q(v){const p=[],a=[],r=[];let o=null,i=0,n=0,s=null,t=null;for(const e of v){const u=c(e),d={id:`rt:${e.requestId}:${e.sequence}:${m(e.eventType)}`,layer:"runtime",kind:u.kind,label:u.label,status:u.status,sessionId:e.sessionId,requestId:e.requestId,startedAt:e.timestamp,endedAt:e.timestamp,sequenceStart:e.sequence,sequenceEnd:e.sequence,sourceEventIds:[e.eventId],detail:{...u.detail,eventType:e.eventType,source:e.source}};if(p.push(d),o){const l=e.eventType==="approval.resolved"?"approval":e.eventType==="request.resumed"?"resume":"sequence";a.push({id:`edge:${o.id}->${d.id}`,from:o.id,to:d.id,kind:l,...l==="approval"?{label:typeof e.payload.decision=="string"?e.payload.decision:"resolved"}:{},sourceEventIds:[o.sourceEventIds[0],e.eventId]})}if(o=d,e.eventType==="request.created"||e.eventType==="request.dequeued"||e.eventType==="request.resumed"){i+=1,s={id:`group:${e.requestId}:segment:${i}`,kind:"segment",label:e.eventType==="request.created"?`Execution segment ${i}`:e.eventType==="request.resumed"?`Resumed segment ${i}`:`Dequeued segment ${i}`,nodeIds:[d.id],startedAt:e.timestamp,anchorNodeId:d.id},r.push(s),t=null,d.groupId=s.id;continue}if(e.eventType==="approval.requested"){n+=1,t={id:`group:${e.requestId}:approval:${n}`,kind:"approval-window",label:`Approval window ${n}`,nodeIds:[d.id],startedAt:e.timestamp,anchorNodeId:d.id},r.push(t),d.groupId=t.id;continue}if(e.eventType==="approval.resolved"){t||(n+=1,t={id:`group:${e.requestId}:approval:${n}`,kind:"approval-window",label:`Approval window ${n}`,nodeIds:[],anchorNodeId:d.id},r.push(t)),t.nodeIds.push(d.id),t.endedAt=e.timestamp,d.groupId=t.id;continue}if(t&&!t.endedAt){t.nodeIds.push(d.id),d.groupId=t.id;continue}s&&(s.nodeIds.push(d.id),s.endedAt=e.timestamp,d.groupId=s.id)}return{nodes:p,edges:a,groups:r}}export{q as buildRuntimeNodes};
|