@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,100 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { applyRequestStreamItemToSnapshot, createInitialRequestEventSnapshot, toRequestDataEvents, } from "../../../projections/request-events.js";
|
|
3
|
-
export async function emitOutputDeltaAndCreateItem(emit, sessionId, requestId, agentId, content) {
|
|
4
|
-
await emit(sessionId, requestId, 3, "output.delta", {
|
|
5
|
-
content,
|
|
6
|
-
});
|
|
7
|
-
return {
|
|
8
|
-
type: "content",
|
|
9
|
-
sessionId,
|
|
10
|
-
requestId,
|
|
11
|
-
agentId,
|
|
12
|
-
content,
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
export function createContentBlocksItem(sessionId, requestId, agentId, contentBlocks) {
|
|
16
|
-
return {
|
|
17
|
-
type: "content-blocks",
|
|
18
|
-
sessionId,
|
|
19
|
-
requestId,
|
|
20
|
-
agentId,
|
|
21
|
-
contentBlocks,
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
export function createToolResultKey(toolName, output, isError) {
|
|
25
|
-
let serializedOutput = "";
|
|
26
|
-
try {
|
|
27
|
-
serializedOutput = JSON.stringify(output);
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
30
|
-
serializedOutput = String(output);
|
|
31
|
-
}
|
|
32
|
-
const preview = serializedOutput.length > 512
|
|
33
|
-
? `${serializedOutput.slice(0, 497)}...[${serializedOutput.length} chars]`
|
|
34
|
-
: serializedOutput;
|
|
35
|
-
return JSON.stringify([toolName, preview, isError === true]);
|
|
36
|
-
}
|
|
37
|
-
export async function dispatchRequestListeners(stream, listeners, options) {
|
|
38
|
-
const notifyIfPresent = async (listener, value) => {
|
|
39
|
-
if (!listener) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
await options.notifyListener(listener, value);
|
|
43
|
-
};
|
|
44
|
-
let latestEvent;
|
|
45
|
-
let latestResult;
|
|
46
|
-
let output = "";
|
|
47
|
-
let snapshot = createInitialRequestEventSnapshot();
|
|
48
|
-
for await (const item of stream) {
|
|
49
|
-
snapshot = applyRequestStreamItemToSnapshot(snapshot, item);
|
|
50
|
-
if (item.type === "event") {
|
|
51
|
-
latestEvent = item.event;
|
|
52
|
-
await notifyIfPresent(listeners.onEvent, item.event);
|
|
53
|
-
}
|
|
54
|
-
else if (item.type === "upstream-event") {
|
|
55
|
-
await notifyIfPresent(listeners.onUpstreamEvent, item.event);
|
|
56
|
-
if (item.surfaceItem) {
|
|
57
|
-
await notifyIfPresent(listeners.onTraceItem, {
|
|
58
|
-
sessionId: item.sessionId,
|
|
59
|
-
requestId: item.requestId,
|
|
60
|
-
surfaceItem: item.surfaceItem,
|
|
61
|
-
event: item.event,
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
else if (item.type === "result") {
|
|
66
|
-
latestResult = item.result;
|
|
67
|
-
}
|
|
68
|
-
else if (item.type === "plan-state") {
|
|
69
|
-
await notifyIfPresent(listeners.onPlanState, item.planState);
|
|
70
|
-
}
|
|
71
|
-
else if (item.type === "content") {
|
|
72
|
-
output += item.content;
|
|
73
|
-
}
|
|
74
|
-
for (const dataEvent of toRequestDataEvents(item)) {
|
|
75
|
-
await notifyIfPresent(listeners.dataListener, dataEvent);
|
|
76
|
-
}
|
|
77
|
-
await notifyIfPresent(listeners.eventListener, snapshot);
|
|
78
|
-
}
|
|
79
|
-
if (!latestEvent) {
|
|
80
|
-
throw new Error("run did not emit any events");
|
|
81
|
-
}
|
|
82
|
-
if (latestResult) {
|
|
83
|
-
return mergeRequestResultOutput(latestResult, output);
|
|
84
|
-
}
|
|
85
|
-
const session = await options.getSession(latestEvent.sessionId);
|
|
86
|
-
if (!session) {
|
|
87
|
-
throw new Error(`Unknown session ${latestEvent.sessionId}`);
|
|
88
|
-
}
|
|
89
|
-
return createFallbackRequestResultFromLatestEvent({
|
|
90
|
-
latestEvent,
|
|
91
|
-
currentState: session.currentState,
|
|
92
|
-
latestRequestId: session.latestRequestId,
|
|
93
|
-
entryAgentId: session.entryAgentId,
|
|
94
|
-
latestAgentId: session.currentAgentId ?? session.requests[0]?.agentId,
|
|
95
|
-
approvalId: session.pendingDecision?.approvalId,
|
|
96
|
-
pendingActionId: session.pendingDecision?.pendingActionId,
|
|
97
|
-
output,
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
export const dispatchRunListeners = dispatchRequestListeners;
|
|
1
|
+
import{createFallbackRequestResultFromLatestEvent as l,mergeRequestResultOutput as d}from"../run/helpers.js";import{applyRequestStreamItemToSnapshot as f,createInitialRequestEventSnapshot as I,toRequestDataEvents as y}from"../../../projections/request-events.js";async function w(o,n,s,e,a){return await o(n,s,3,"output.delta",{content:a}),{type:"content",sessionId:n,requestId:s,agentId:e,content:a}}function R(o,n,s,e){return{type:"content-blocks",sessionId:o,requestId:n,agentId:s,contentBlocks:e}}function h(o,n,s){let e="";try{e=JSON.stringify(n)}catch{e=String(n)}const a=e.length>512?`${e.slice(0,497)}...[${e.length} chars]`:e;return JSON.stringify([o,a,s===!0])}async function m(o,n,s){const e=async(t,p)=>{t&&await s.notifyListener(t,p)};let a,i,u="",c=I();for await(const t of o){c=f(c,t),t.type==="event"?(a=t.event,await e(n.onEvent,t.event)):t.type==="upstream-event"?(await e(n.onUpstreamEvent,t.event),t.surfaceItem&&await e(n.onTraceItem,{sessionId:t.sessionId,requestId:t.requestId,surfaceItem:t.surfaceItem,event:t.event})):t.type==="result"?i=t.result:t.type==="plan-state"?await e(n.onPlanState,t.planState):t.type==="content"&&(u+=t.content);for(const p of y(t))await e(n.dataListener,p);await e(n.eventListener,c)}if(!a)throw new Error("run did not emit any events");if(i)return d(i,u);const r=await s.getSession(a.sessionId);if(!r)throw new Error(`Unknown session ${a.sessionId}`);return l({latestEvent:a,currentState:r.currentState,latestRequestId:r.latestRequestId,entryAgentId:r.entryAgentId,latestAgentId:r.currentAgentId??r.requests[0]?.agentId,approvalId:r.pendingDecision?.approvalId,pendingActionId:r.pendingDecision?.pendingActionId,output:u})}const S=m;export{R as createContentBlocksItem,h as createToolResultKey,m as dispatchRequestListeners,S as dispatchRunListeners,w as emitOutputDeltaAndCreateItem};
|
|
@@ -1,52 +1 @@
|
|
|
1
|
-
function
|
|
2
|
-
switch (event.eventType) {
|
|
3
|
-
case "request.queued":
|
|
4
|
-
case "request.dequeued":
|
|
5
|
-
return "queue";
|
|
6
|
-
case "approval.requested":
|
|
7
|
-
case "approval.resolved":
|
|
8
|
-
return "approval";
|
|
9
|
-
case "request.resumed":
|
|
10
|
-
return "recovery";
|
|
11
|
-
case "artifact.created":
|
|
12
|
-
return "artifact";
|
|
13
|
-
case "request.created":
|
|
14
|
-
case "request.state.changed":
|
|
15
|
-
return "request";
|
|
16
|
-
default:
|
|
17
|
-
return "other";
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
export function projectRuntimeTimeline(events, options = {}) {
|
|
21
|
-
const filtered = events.filter((event) => {
|
|
22
|
-
if (options.sessionId && event.sessionId !== options.sessionId) {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
if (options.requestId && event.requestId !== options.requestId) {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
return true;
|
|
29
|
-
});
|
|
30
|
-
return [...filtered]
|
|
31
|
-
.sort((left, right) => {
|
|
32
|
-
const timestampComparison = left.timestamp.localeCompare(right.timestamp);
|
|
33
|
-
if (timestampComparison !== 0) {
|
|
34
|
-
return timestampComparison;
|
|
35
|
-
}
|
|
36
|
-
if (left.sequence !== right.sequence) {
|
|
37
|
-
return left.sequence - right.sequence;
|
|
38
|
-
}
|
|
39
|
-
return left.eventId.localeCompare(right.eventId);
|
|
40
|
-
})
|
|
41
|
-
.map((event) => ({
|
|
42
|
-
eventId: event.eventId,
|
|
43
|
-
sessionId: event.sessionId,
|
|
44
|
-
requestId: event.requestId,
|
|
45
|
-
eventType: event.eventType,
|
|
46
|
-
timestamp: event.timestamp,
|
|
47
|
-
sequence: event.sequence,
|
|
48
|
-
source: event.source,
|
|
49
|
-
kind: classifyTimelineItem(event),
|
|
50
|
-
payload: event.payload,
|
|
51
|
-
}));
|
|
52
|
-
}
|
|
1
|
+
function a(t){switch(t.eventType){case"request.queued":case"request.dequeued":return"queue";case"approval.requested":case"approval.resolved":return"approval";case"request.resumed":return"recovery";case"artifact.created":return"artifact";case"request.created":case"request.state.changed":return"request";default:return"other"}}function n(t,r={}){return[...t.filter(e=>!(r.sessionId&&e.sessionId!==r.sessionId||r.requestId&&e.requestId!==r.requestId))].sort((e,s)=>{const u=e.timestamp.localeCompare(s.timestamp);return u!==0?u:e.sequence!==s.sequence?e.sequence-s.sequence:e.eventId.localeCompare(s.eventId)}).map(e=>({eventId:e.eventId,sessionId:e.sessionId,requestId:e.requestId,eventType:e.eventType,timestamp:e.timestamp,sequence:e.sequence,source:e.source,kind:a(e),payload:e.payload}))}export{n as projectRuntimeTimeline};
|
|
@@ -1,186 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
export function toPublicRequestResultShape(result) {
|
|
3
|
-
return {
|
|
4
|
-
sessionId: result.sessionId ?? result.legacySessionId ?? "",
|
|
5
|
-
requestId: result.requestId ?? result.legacyRequestId ?? "",
|
|
6
|
-
state: result.state,
|
|
7
|
-
output: result.output,
|
|
8
|
-
finalMessageText: result.finalMessageText,
|
|
9
|
-
outputContent: result.outputContent,
|
|
10
|
-
contentBlocks: result.contentBlocks,
|
|
11
|
-
structuredResponse: result.structuredResponse,
|
|
12
|
-
interruptContent: result.interruptContent,
|
|
13
|
-
agentId: result.agentId,
|
|
14
|
-
approvalId: result.approvalId,
|
|
15
|
-
pendingActionId: result.pendingActionId,
|
|
16
|
-
delegationId: result.delegationId,
|
|
17
|
-
artifacts: result.artifacts,
|
|
18
|
-
metadata: result.metadata,
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
export function toPublicHarnessStreamItem(item) {
|
|
22
|
-
switch (item.type) {
|
|
23
|
-
case "commentary":
|
|
24
|
-
return {
|
|
25
|
-
type: "commentary",
|
|
26
|
-
sessionId: item.sessionId,
|
|
27
|
-
requestId: item.requestId,
|
|
28
|
-
agentId: item.agentId,
|
|
29
|
-
content: item.content,
|
|
30
|
-
};
|
|
31
|
-
case "content":
|
|
32
|
-
return {
|
|
33
|
-
type: "content",
|
|
34
|
-
sessionId: item.sessionId,
|
|
35
|
-
requestId: item.requestId,
|
|
36
|
-
agentId: item.agentId,
|
|
37
|
-
content: item.content,
|
|
38
|
-
};
|
|
39
|
-
case "content-blocks":
|
|
40
|
-
return {
|
|
41
|
-
type: "content-blocks",
|
|
42
|
-
sessionId: item.sessionId,
|
|
43
|
-
requestId: item.requestId,
|
|
44
|
-
agentId: item.agentId,
|
|
45
|
-
contentBlocks: item.contentBlocks,
|
|
46
|
-
};
|
|
47
|
-
case "tool-result":
|
|
48
|
-
return {
|
|
49
|
-
type: "tool-result",
|
|
50
|
-
sessionId: item.sessionId,
|
|
51
|
-
requestId: item.requestId,
|
|
52
|
-
agentId: item.agentId,
|
|
53
|
-
toolName: item.toolName,
|
|
54
|
-
output: item.output,
|
|
55
|
-
...(item.isError !== undefined ? { isError: item.isError } : {}),
|
|
56
|
-
};
|
|
57
|
-
case "plan-state":
|
|
58
|
-
return {
|
|
59
|
-
type: "plan-state",
|
|
60
|
-
sessionId: item.sessionId,
|
|
61
|
-
requestId: item.requestId,
|
|
62
|
-
agentId: item.agentId,
|
|
63
|
-
planState: item.planState,
|
|
64
|
-
};
|
|
65
|
-
case "upstream-event":
|
|
66
|
-
return {
|
|
67
|
-
type: "upstream-event",
|
|
68
|
-
sessionId: item.sessionId,
|
|
69
|
-
requestId: item.requestId,
|
|
70
|
-
...(item.surfaceItem ? { surfaceItem: item.surfaceItem } : {}),
|
|
71
|
-
event: item.event,
|
|
72
|
-
};
|
|
73
|
-
case "result":
|
|
74
|
-
return {
|
|
75
|
-
type: "result",
|
|
76
|
-
result: toPublicRequestResultShape(item.result),
|
|
77
|
-
};
|
|
78
|
-
default:
|
|
79
|
-
return item;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
export function mergeMemoryItems(...groups) {
|
|
83
|
-
const merged = new Map();
|
|
84
|
-
for (const group of groups) {
|
|
85
|
-
for (const item of group) {
|
|
86
|
-
if (!merged.has(item.id)) {
|
|
87
|
-
merged.set(item.id, item);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return Array.from(merged.values());
|
|
92
|
-
}
|
|
93
|
-
function normalizeSessionListText(content, limit) {
|
|
94
|
-
if (!content) {
|
|
95
|
-
return undefined;
|
|
96
|
-
}
|
|
97
|
-
const collapsed = extractMessageText(content).replace(/\s+/g, " ").trim();
|
|
98
|
-
if (!collapsed) {
|
|
99
|
-
return undefined;
|
|
100
|
-
}
|
|
101
|
-
return collapsed.length > limit ? `${collapsed.slice(0, limit - 1).trimEnd()}…` : collapsed;
|
|
102
|
-
}
|
|
103
|
-
export function toSessionListSummary(session) {
|
|
104
|
-
const titleSource = session.firstMessage?.role === "user" ? session.firstMessage : session.lastMessage;
|
|
105
|
-
return {
|
|
106
|
-
agentId: session.agentId,
|
|
107
|
-
entryAgentId: session.entryAgentId,
|
|
108
|
-
sessionId: session.sessionId,
|
|
109
|
-
latestRequestId: session.latestRequestId,
|
|
110
|
-
createdAt: session.createdAt,
|
|
111
|
-
updatedAt: session.updatedAt,
|
|
112
|
-
status: session.status,
|
|
113
|
-
currentAgentId: session.currentAgentId,
|
|
114
|
-
messageCount: session.messageCount,
|
|
115
|
-
hasVisibleMessages: session.messageCount > 0,
|
|
116
|
-
lastMessageRole: session.lastMessage?.role,
|
|
117
|
-
title: normalizeSessionListText(titleSource?.content, 72),
|
|
118
|
-
snippet: normalizeSessionListText(session.lastMessage?.content, 160),
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
export function summarizeApprovalEvidence(approvals) {
|
|
122
|
-
const toolNames = Array.from(new Set(approvals
|
|
123
|
-
.map((approval) => approval.toolName)
|
|
124
|
-
.filter((toolName) => typeof toolName === "string" && toolName.trim().length > 0)));
|
|
125
|
-
const approvalReasons = Array.from(new Set(approvals
|
|
126
|
-
.map((approval) => approval.approvalReason)
|
|
127
|
-
.filter((reason) => typeof reason === "string" && reason.trim().length > 0)));
|
|
128
|
-
return {
|
|
129
|
-
total: approvals.length,
|
|
130
|
-
pending: approvals.filter((approval) => approval.status === "pending").length,
|
|
131
|
-
approved: approvals.filter((approval) => approval.status === "approved").length,
|
|
132
|
-
edited: approvals.filter((approval) => approval.status === "edited").length,
|
|
133
|
-
rejected: approvals.filter((approval) => approval.status === "rejected").length,
|
|
134
|
-
expired: approvals.filter((approval) => approval.status === "expired").length,
|
|
135
|
-
toolNames,
|
|
136
|
-
approvalReasons,
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
export function toRequestSummary(summary) {
|
|
140
|
-
return {
|
|
141
|
-
requestId: summary.requestId,
|
|
142
|
-
sessionId: summary.sessionId,
|
|
143
|
-
agentId: summary.agentId,
|
|
144
|
-
parentRequestId: summary.parentRequestId,
|
|
145
|
-
executionMode: summary.executionMode,
|
|
146
|
-
adapterKind: summary.adapterKind,
|
|
147
|
-
createdAt: summary.createdAt,
|
|
148
|
-
updatedAt: summary.updatedAt,
|
|
149
|
-
state: summary.state,
|
|
150
|
-
checkpointRef: summary.checkpointRef,
|
|
151
|
-
resumable: summary.resumable,
|
|
152
|
-
startedAt: summary.startedAt,
|
|
153
|
-
endedAt: summary.endedAt,
|
|
154
|
-
lastActivityAt: summary.lastActivityAt,
|
|
155
|
-
currentAgentId: summary.currentAgentId,
|
|
156
|
-
delegationChain: summary.delegationChain,
|
|
157
|
-
runtimeSnapshot: summary.runtimeSnapshot,
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
export function cloneRequestRecord(record) {
|
|
161
|
-
return {
|
|
162
|
-
...toRequestSummary(record),
|
|
163
|
-
traceItems: record.traceItems,
|
|
164
|
-
runtimeTimeline: record.runtimeTimeline,
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
export function cloneSessionRecord(record) {
|
|
168
|
-
return {
|
|
169
|
-
sessionId: record.sessionId,
|
|
170
|
-
entryAgentId: record.entryAgentId,
|
|
171
|
-
currentAgentId: record.currentAgentId,
|
|
172
|
-
currentState: record.currentState,
|
|
173
|
-
latestRequestId: record.latestRequestId,
|
|
174
|
-
createdAt: record.createdAt,
|
|
175
|
-
updatedAt: record.updatedAt,
|
|
176
|
-
messages: record.messages,
|
|
177
|
-
requests: record.requests.map(cloneRequestRecord),
|
|
178
|
-
pendingDecision: record.pendingDecision,
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
export function deriveRequestInputFromTranscript(transcript, requestId) {
|
|
182
|
-
const candidate = [...transcript]
|
|
183
|
-
.reverse()
|
|
184
|
-
.find((message) => message.role === "user" && (!requestId || message.requestId === requestId));
|
|
185
|
-
return candidate ? { input: candidate.content } : null;
|
|
186
|
-
}
|
|
1
|
+
import{extractMessageText as d}from"../../utils/message-content.js";function a(e){return{sessionId:e.sessionId??e.legacySessionId??"",requestId:e.requestId??e.legacyRequestId??"",state:e.state,output:e.output,finalMessageText:e.finalMessageText,outputContent:e.outputContent,contentBlocks:e.contentBlocks,structuredResponse:e.structuredResponse,interruptContent:e.interruptContent,agentId:e.agentId,approvalId:e.approvalId,pendingActionId:e.pendingActionId,delegationId:e.delegationId,artifacts:e.artifacts,metadata:e.metadata}}function I(e){switch(e.type){case"commentary":return{type:"commentary",sessionId:e.sessionId,requestId:e.requestId,agentId:e.agentId,content:e.content};case"content":return{type:"content",sessionId:e.sessionId,requestId:e.requestId,agentId:e.agentId,content:e.content};case"content-blocks":return{type:"content-blocks",sessionId:e.sessionId,requestId:e.requestId,agentId:e.agentId,contentBlocks:e.contentBlocks};case"tool-result":return{type:"tool-result",sessionId:e.sessionId,requestId:e.requestId,agentId:e.agentId,toolName:e.toolName,output:e.output,...e.isError!==void 0?{isError:e.isError}:{}};case"plan-state":return{type:"plan-state",sessionId:e.sessionId,requestId:e.requestId,agentId:e.agentId,planState:e.planState};case"upstream-event":return{type:"upstream-event",sessionId:e.sessionId,requestId:e.requestId,...e.surfaceItem?{surfaceItem:e.surfaceItem}:{},event:e.event};case"result":return{type:"result",result:a(e.result)};default:return e}}function i(...e){const n=new Map;for(const s of e)for(const t of s)n.has(t.id)||n.set(t.id,t);return Array.from(n.values())}function r(e,n){if(!e)return;const s=d(e).replace(/\s+/g," ").trim();if(s)return s.length>n?`${s.slice(0,n-1).trimEnd()}\u2026`:s}function p(e){const n=e.firstMessage?.role==="user"?e.firstMessage:e.lastMessage;return{agentId:e.agentId,entryAgentId:e.entryAgentId,sessionId:e.sessionId,latestRequestId:e.latestRequestId,createdAt:e.createdAt,updatedAt:e.updatedAt,status:e.status,currentAgentId:e.currentAgentId,messageCount:e.messageCount,hasVisibleMessages:e.messageCount>0,lastMessageRole:e.lastMessage?.role,title:r(n?.content,72),snippet:r(e.lastMessage?.content,160)}}function g(e){const n=Array.from(new Set(e.map(t=>t.toolName).filter(t=>typeof t=="string"&&t.trim().length>0))),s=Array.from(new Set(e.map(t=>t.approvalReason).filter(t=>typeof t=="string"&&t.trim().length>0)));return{total:e.length,pending:e.filter(t=>t.status==="pending").length,approved:e.filter(t=>t.status==="approved").length,edited:e.filter(t=>t.status==="edited").length,rejected:e.filter(t=>t.status==="rejected").length,expired:e.filter(t=>t.status==="expired").length,toolNames:n,approvalReasons:s}}function o(e){return{requestId:e.requestId,sessionId:e.sessionId,agentId:e.agentId,parentRequestId:e.parentRequestId,executionMode:e.executionMode,adapterKind:e.adapterKind,createdAt:e.createdAt,updatedAt:e.updatedAt,state:e.state,checkpointRef:e.checkpointRef,resumable:e.resumable,startedAt:e.startedAt,endedAt:e.endedAt,lastActivityAt:e.lastActivityAt,currentAgentId:e.currentAgentId,delegationChain:e.delegationChain,runtimeSnapshot:e.runtimeSnapshot}}function u(e){return{...o(e),traceItems:e.traceItems,runtimeTimeline:e.runtimeTimeline}}function l(e){return{sessionId:e.sessionId,entryAgentId:e.entryAgentId,currentAgentId:e.currentAgentId,currentState:e.currentState,latestRequestId:e.latestRequestId,createdAt:e.createdAt,updatedAt:e.updatedAt,messages:e.messages,requests:e.requests.map(u),pendingDecision:e.pendingDecision}}function f(e,n){const s=[...e].reverse().find(t=>t.role==="user"&&(!n||t.requestId===n));return s?{input:s.content}:null}export{u as cloneRequestRecord,l as cloneSessionRecord,f as deriveRequestInputFromTranscript,i as mergeMemoryItems,g as summarizeApprovalEvidence,I as toPublicHarnessStreamItem,a as toPublicRequestResultShape,o as toRequestSummary,p as toSessionListSummary};
|
|
@@ -1,15 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
export function normalizeRecordedArtifactPath(input) {
|
|
3
|
-
const trimmed = input.trim().replaceAll("\\", "/").replace(/^\.\/+/, "");
|
|
4
|
-
if (!trimmed) {
|
|
5
|
-
throw new Error("Artifact path must be a non-empty relative path.");
|
|
6
|
-
}
|
|
7
|
-
if (trimmed.startsWith("/") || /^[a-z]:\//i.test(trimmed)) {
|
|
8
|
-
throw new Error("Artifact path must stay relative to the persisted run artifact directory.");
|
|
9
|
-
}
|
|
10
|
-
const normalized = path.posix.normalize(trimmed);
|
|
11
|
-
if (normalized === "." || normalized.startsWith("../") || normalized.includes("/../")) {
|
|
12
|
-
throw new Error("Artifact path must stay inside the persisted run artifact directory.");
|
|
13
|
-
}
|
|
14
|
-
return normalized;
|
|
15
|
-
}
|
|
1
|
+
import i from"node:path";function o(e){const t=e.trim().replaceAll("\\","/").replace(/^\.\/+/,"");if(!t)throw new Error("Artifact path must be a non-empty relative path.");if(t.startsWith("/")||/^[a-z]:\//i.test(t))throw new Error("Artifact path must stay relative to the persisted run artifact directory.");const r=i.posix.normalize(t);if(r==="."||r.startsWith("../")||r.includes("/../"))throw new Error("Artifact path must stay inside the persisted run artifact directory.");return r}export{o as normalizeRecordedArtifactPath};
|