@botbotgo/agent-harness 0.0.290 → 0.0.291
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 +20 -20
- package/README.zh.md +14 -14
- package/dist/acp.d.ts +5 -5
- package/dist/acp.js +3 -3
- package/dist/api.d.ts +20 -21
- package/dist/api.js +38 -50
- package/dist/cli.js +47 -43
- package/dist/config/agents/orchestra.yaml +3 -3
- package/dist/config/knowledge/knowledge-runtime.yaml +4 -4
- package/dist/config/runtime/runtime-memory.yaml +7 -7
- package/dist/config/runtime/workspace.yaml +7 -7
- package/dist/contracts/core.d.ts +1 -1
- package/dist/contracts/runtime.d.ts +35 -40
- package/dist/contracts/workspace.d.ts +2 -2
- package/dist/flow/build-flow-graph.js +20 -33
- package/dist/flow/export-sequence-mermaid.js +4 -4
- package/dist/flow/types.d.ts +2 -2
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -1
- package/dist/init-project.js +10 -10
- package/dist/knowledge/module.js +37 -45
- package/dist/mcp.d.ts +9 -9
- package/dist/mcp.js +6 -6
- package/dist/package-version.d.ts +1 -1
- package/dist/package-version.js +1 -1
- package/dist/persistence/file-store.d.ts +69 -69
- package/dist/persistence/file-store.js +224 -221
- package/dist/persistence/sqlite-request-context-store.d.ts +22 -0
- package/dist/persistence/sqlite-request-context-store.js +64 -0
- package/dist/persistence/sqlite-request-queue-store.d.ts +41 -0
- package/dist/persistence/sqlite-request-queue-store.js +120 -0
- package/dist/persistence/sqlite-store.d.ts +72 -72
- package/dist/persistence/sqlite-store.js +361 -361
- package/dist/persistence/types.d.ts +84 -84
- package/dist/protocol/a2a/http.js +79 -74
- package/dist/protocol/ag-ui/http.d.ts +7 -7
- package/dist/protocol/ag-ui/http.js +20 -20
- package/dist/resource/resource-impl.js +1 -1
- package/dist/runtime/adapter/compat/deepagent-compat.d.ts +2 -2
- package/dist/runtime/adapter/flow/invocation-flow.d.ts +6 -5
- package/dist/runtime/adapter/flow/invocation-flow.js +6 -5
- package/dist/runtime/adapter/flow/stream-runtime.d.ts +3 -3
- package/dist/runtime/adapter/flow/stream-runtime.js +5 -4
- package/dist/runtime/adapter/invocation-result.d.ts +6 -5
- package/dist/runtime/adapter/invocation-result.js +5 -4
- package/dist/runtime/adapter/middleware-assembly.js +3 -2
- package/dist/runtime/adapter/tool/tool-hitl.js +1 -1
- package/dist/runtime/adapter/upstream-configurable-keys.d.ts +2 -0
- package/dist/runtime/adapter/upstream-configurable-keys.js +2 -0
- package/dist/runtime/agent-runtime-adapter.d.ts +11 -8
- package/dist/runtime/agent-runtime-adapter.js +36 -32
- package/dist/runtime/harness/events/events.d.ts +8 -8
- package/dist/runtime/harness/events/events.js +25 -19
- package/dist/runtime/harness/events/listener-runtime.d.ts +5 -4
- package/dist/runtime/harness/events/listener-runtime.js +7 -3
- package/dist/runtime/harness/events/runtime-event-operations.d.ts +7 -7
- package/dist/runtime/harness/events/runtime-event-operations.js +5 -5
- package/dist/runtime/harness/events/streaming.d.ts +8 -7
- package/dist/runtime/harness/events/streaming.js +20 -19
- package/dist/runtime/harness/events/timeline.js +6 -6
- package/dist/runtime/harness/index.d.ts +1 -1
- package/dist/runtime/harness/index.js +1 -1
- package/dist/runtime/harness/run/helpers.d.ts +14 -11
- package/dist/runtime/harness/run/helpers.js +10 -7
- package/dist/runtime/harness/run/inspection.d.ts +3 -2
- package/dist/runtime/harness/run/inspection.js +7 -7
- package/dist/runtime/harness/run/operator-overview.d.ts +2 -2
- package/dist/runtime/harness/run/operator-overview.js +18 -17
- package/dist/runtime/harness/run/queue-diagnostics.js +6 -6
- package/dist/runtime/harness/run/recovery.d.ts +15 -15
- package/dist/runtime/harness/run/recovery.js +53 -50
- package/dist/runtime/harness/run/resources.d.ts +2 -2
- package/dist/runtime/harness/run/resources.js +8 -8
- package/dist/runtime/harness/run/resume.d.ts +3 -3
- package/dist/runtime/harness/run/resume.js +4 -4
- package/dist/runtime/harness/run/routing.d.ts +4 -4
- package/dist/runtime/harness/run/routing.js +8 -8
- package/dist/runtime/harness/run/run-lifecycle.d.ts +12 -12
- package/dist/runtime/harness/run/run-lifecycle.js +26 -26
- package/dist/runtime/harness/run/run-operations.d.ts +45 -45
- package/dist/runtime/harness/run/run-operations.js +79 -78
- package/dist/runtime/harness/run/run-queue.d.ts +8 -8
- package/dist/runtime/harness/run/run-queue.js +16 -16
- package/dist/runtime/harness/run/run-slot-acquisition.d.ts +32 -32
- package/dist/runtime/harness/run/run-slot-acquisition.js +41 -41
- package/dist/runtime/harness/run/{thread-records.d.ts → session-records.d.ts} +6 -13
- package/dist/runtime/harness/run/{thread-records.js → session-records.js} +14 -60
- package/dist/runtime/harness/run/start-run.d.ts +36 -36
- package/dist/runtime/harness/run/start-run.js +55 -36
- package/dist/runtime/harness/run/startup-runtime.d.ts +9 -9
- package/dist/runtime/harness/run/startup-runtime.js +22 -20
- package/dist/runtime/harness/run/stream-run.d.ts +18 -18
- package/dist/runtime/harness/run/stream-run.js +52 -52
- package/dist/runtime/harness/runtime-defaults.d.ts +2 -2
- package/dist/runtime/harness/runtime-defaults.js +7 -7
- package/dist/runtime/harness/system/health-monitor.d.ts +3 -3
- package/dist/runtime/harness/system/health-monitor.js +18 -18
- package/dist/runtime/harness/system/mem0-ingestion-sync.d.ts +6 -6
- package/dist/runtime/harness/system/mem0-ingestion-sync.js +36 -27
- package/dist/runtime/harness/system/runtime-memory-candidates.js +2 -2
- package/dist/runtime/harness/system/runtime-memory-manager.d.ts +13 -13
- package/dist/runtime/harness/system/runtime-memory-manager.js +41 -38
- package/dist/runtime/harness/system/runtime-memory-policy.d.ts +1 -1
- package/dist/runtime/harness/system/runtime-memory-policy.js +1 -1
- package/dist/runtime/harness/system/runtime-memory-records.d.ts +4 -2
- package/dist/runtime/harness/system/runtime-memory-records.js +21 -8
- package/dist/runtime/harness/system/runtime-memory-sync.d.ts +6 -6
- package/dist/runtime/harness/system/runtime-memory-sync.js +47 -44
- package/dist/runtime/harness/system/{thread-memory-sync.d.ts → session-memory-sync.d.ts} +7 -7
- package/dist/runtime/harness/system/{thread-memory-sync.js → session-memory-sync.js} +28 -28
- package/dist/runtime/harness.d.ts +33 -45
- package/dist/runtime/harness.js +273 -291
- package/dist/runtime/maintenance/checkpoint-maintenance.js +2 -2
- package/dist/runtime/maintenance/file-checkpoint-saver.d.ts +1 -1
- package/dist/runtime/maintenance/file-checkpoint-saver.js +6 -6
- package/dist/runtime/maintenance/runtime-record-maintenance.d.ts +1 -1
- package/dist/runtime/maintenance/runtime-record-maintenance.js +33 -33
- package/dist/runtime/maintenance/sqlite-checkpoint-saver.d.ts +1 -1
- package/dist/runtime/maintenance/sqlite-checkpoint-saver.js +30 -10
- package/dist/runtime/support/harness-support.d.ts +2 -2
- package/dist/runtime/support/harness-support.js +7 -7
- package/dist/runtime/support/runtime-adapter-options.d.ts +2 -2
- package/dist/runtime/support/runtime-adapter-options.js +3 -3
- package/dist/runtime/support/runtime-factories.d.ts +2 -2
- package/dist/runtime/support/runtime-factories.js +10 -10
- package/dist/workspace/agent-binding-compiler.js +3 -3
- package/dist/workspace/object-loader.js +1 -1
- package/dist/workspace/support/workspace-ref-utils.d.ts +4 -3
- package/dist/workspace/support/workspace-ref-utils.js +5 -4
- package/package.json +1 -1
- package/dist/persistence/sqlite-run-context-store.d.ts +0 -22
- package/dist/persistence/sqlite-run-context-store.js +0 -64
- package/dist/persistence/sqlite-run-queue-store.d.ts +0 -41
- package/dist/persistence/sqlite-run-queue-store.js +0 -120
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { extractMessageText } from "../../../utils/message-content.js";
|
|
2
2
|
import { createHarnessEvent, createPendingApproval } from "../../support/harness-support.js";
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
async function updateInspection(persistence, sessionId, requestId, patch) {
|
|
4
|
+
await persistence.updateRequestInspection(sessionId, requestId, patch);
|
|
5
|
+
}
|
|
6
|
+
async function setRequestState(persistence, sessionId, requestId, state, checkpointRef) {
|
|
7
|
+
await persistence.setRequestState(sessionId, requestId, state, checkpointRef);
|
|
8
|
+
}
|
|
9
|
+
export async function emitHarnessEvent(runtime, sessionId, requestId, sequence, eventType, payload, source = "runtime") {
|
|
10
|
+
const event = createHarnessEvent(sessionId, requestId, sequence, eventType, payload, source);
|
|
5
11
|
if (runtime.backgroundEventTypes.has(event.eventType)) {
|
|
6
12
|
runtime.trackBackgroundTask(runtime.persistence.appendEvent(event).catch(() => {
|
|
7
13
|
// Fail open for telemetry-style event persistence.
|
|
@@ -13,42 +19,42 @@ export async function emitHarnessEvent(runtime, threadId, runId, sequence, event
|
|
|
13
19
|
runtime.publishEvent(event);
|
|
14
20
|
return event;
|
|
15
21
|
}
|
|
16
|
-
export async function
|
|
17
|
-
return emitHarnessEvent(runtime,
|
|
22
|
+
export async function emitRequestCreatedEvent(runtime, sessionId, requestId, payload) {
|
|
23
|
+
return emitHarnessEvent(runtime, sessionId, requestId, 1, "request.created", payload);
|
|
18
24
|
}
|
|
19
|
-
export async function
|
|
20
|
-
await runtime.persistence
|
|
25
|
+
export async function setRequestStateAndEmitEvent(runtime, sessionId, requestId, sequence, state, options) {
|
|
26
|
+
await setRequestState(runtime.persistence, sessionId, requestId, state, options.checkpointRef ?? null);
|
|
21
27
|
const now = new Date(Date.now()).toISOString();
|
|
22
|
-
await runtime.persistence
|
|
28
|
+
await updateInspection(runtime.persistence, sessionId, requestId, {
|
|
23
29
|
lastActivityAt: now,
|
|
24
30
|
...(state === "completed" || state === "failed" || state === "cancelled" ? { endedAt: now } : {}),
|
|
25
31
|
});
|
|
26
|
-
return emitHarnessEvent(runtime,
|
|
32
|
+
return emitHarnessEvent(runtime, sessionId, requestId, sequence, "request.state.changed", {
|
|
27
33
|
previousState: options.previousState,
|
|
28
34
|
state,
|
|
29
35
|
checkpointRef: options.checkpointRef ?? null,
|
|
30
36
|
...(options.error ? { error: options.error } : {}),
|
|
31
37
|
});
|
|
32
38
|
}
|
|
33
|
-
export async function persistApproval(runtime,
|
|
34
|
-
const approval = createPendingApproval(
|
|
39
|
+
export async function persistApproval(runtime, sessionId, requestId, checkpointRef, input, interruptContent) {
|
|
40
|
+
const approval = createPendingApproval(sessionId, requestId, checkpointRef, extractMessageText(input), interruptContent);
|
|
35
41
|
await runtime.persistence.createApproval(approval);
|
|
36
|
-
const artifact = await runtime.persistence.
|
|
37
|
-
artifactId: `artifact-approval-${
|
|
42
|
+
const artifact = await runtime.persistence.createRequestArtifact(sessionId, requestId, {
|
|
43
|
+
artifactId: `artifact-approval-${requestId}`,
|
|
38
44
|
kind: "approval-packet",
|
|
39
|
-
path: `artifacts/approval-${
|
|
45
|
+
path: `artifacts/approval-${requestId}.json`,
|
|
40
46
|
createdAt: approval.requestedAt,
|
|
41
47
|
}, approval);
|
|
42
|
-
await emitHarnessEvent(runtime,
|
|
48
|
+
await emitHarnessEvent(runtime, sessionId, requestId, 5, "artifact.created", {
|
|
43
49
|
artifactId: artifact.artifactId,
|
|
44
50
|
kind: artifact.kind,
|
|
45
51
|
path: artifact.path,
|
|
46
52
|
});
|
|
47
53
|
return approval;
|
|
48
54
|
}
|
|
49
|
-
export async function requestApprovalAndEmitEvent(runtime,
|
|
50
|
-
const approval = await persistApproval(runtime,
|
|
51
|
-
const event = await emitHarnessEvent(runtime,
|
|
55
|
+
export async function requestApprovalAndEmitEvent(runtime, sessionId, requestId, input, interruptContent, checkpointRef, sequence) {
|
|
56
|
+
const approval = await persistApproval(runtime, sessionId, requestId, checkpointRef, input, interruptContent);
|
|
57
|
+
const event = await emitHarnessEvent(runtime, sessionId, requestId, sequence, "approval.requested", {
|
|
52
58
|
approvalId: approval.approvalId,
|
|
53
59
|
pendingActionId: approval.pendingActionId,
|
|
54
60
|
toolName: approval.toolName,
|
|
@@ -58,7 +64,7 @@ export async function requestApprovalAndEmitEvent(runtime, threadId, runId, inpu
|
|
|
58
64
|
});
|
|
59
65
|
return { approval, event };
|
|
60
66
|
}
|
|
61
|
-
export async function emitSyntheticFallbackEvent(runtime,
|
|
67
|
+
export async function emitSyntheticFallbackEvent(runtime, sessionId, requestId, selectedAgentId, error, sequence = 3) {
|
|
62
68
|
const payload = typeof error === "object" && error !== null && "reason" in error
|
|
63
69
|
? {
|
|
64
70
|
...error,
|
|
@@ -68,7 +74,7 @@ export async function emitSyntheticFallbackEvent(runtime, threadId, runId, selec
|
|
|
68
74
|
reason: error instanceof Error ? error.message : String(error),
|
|
69
75
|
selectedAgentId,
|
|
70
76
|
};
|
|
71
|
-
await emitHarnessEvent(runtime,
|
|
77
|
+
await emitHarnessEvent(runtime, sessionId, requestId, sequence, "runtime.synthetic_fallback", {
|
|
72
78
|
...payload,
|
|
73
79
|
});
|
|
74
80
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RequestListeners, RequestResult } from "../../../contracts/types.js";
|
|
2
2
|
import { type InternalHarnessStreamItem } from "./streaming.js";
|
|
3
3
|
export declare function createListenerDispatchRuntime(input: {
|
|
4
4
|
notifyListener: <T>(listener: ((value: T) => void | Promise<void>) | undefined, value: T) => Promise<void>;
|
|
5
|
-
|
|
6
|
-
currentState:
|
|
5
|
+
getSession: (sessionId: string) => Promise<{
|
|
6
|
+
currentState: RequestResult["state"];
|
|
7
7
|
latestRequestId: string;
|
|
8
8
|
entryAgentId: string;
|
|
9
9
|
currentAgentId?: string;
|
|
@@ -16,5 +16,6 @@ export declare function createListenerDispatchRuntime(input: {
|
|
|
16
16
|
};
|
|
17
17
|
} | null>;
|
|
18
18
|
}): {
|
|
19
|
-
|
|
19
|
+
dispatchRequestListeners: (stream: AsyncGenerator<InternalHarnessStreamItem>, listeners: RequestListeners) => Promise<RequestResult>;
|
|
20
|
+
dispatchRunListeners: (stream: AsyncGenerator<InternalHarnessStreamItem>, listeners: RequestListeners) => Promise<RequestResult>;
|
|
20
21
|
};
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { dispatchRequestListeners as dispatchStreamingRequestListeners } from "./streaming.js";
|
|
2
2
|
export function createListenerDispatchRuntime(input) {
|
|
3
3
|
return {
|
|
4
|
-
|
|
4
|
+
dispatchRequestListeners: (stream, listeners) => dispatchStreamingRequestListeners(stream, listeners, {
|
|
5
5
|
notifyListener: (listener, value) => input.notifyListener(listener, value),
|
|
6
|
-
|
|
6
|
+
getSession: (sessionId) => input.getSession(sessionId),
|
|
7
|
+
}),
|
|
8
|
+
dispatchRunListeners: (stream, listeners) => dispatchStreamingRequestListeners(stream, listeners, {
|
|
9
|
+
notifyListener: (listener, value) => input.notifyListener(listener, value),
|
|
10
|
+
getSession: (sessionId) => input.getSession(sessionId),
|
|
7
11
|
}),
|
|
8
12
|
};
|
|
9
13
|
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import type { HarnessEvent, MessageContent,
|
|
2
|
-
import {
|
|
3
|
-
type EventRuntime = Parameters<typeof
|
|
1
|
+
import type { HarnessEvent, MessageContent, RequestResult } from "../../../contracts/types.js";
|
|
2
|
+
import { emitRequestCreatedEvent } from "./events.js";
|
|
3
|
+
type EventRuntime = Parameters<typeof emitRequestCreatedEvent>[0];
|
|
4
4
|
export declare function createRuntimeEventOperations(runtime: EventRuntime): {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
emitRequestCreated: (sessionId: string, requestId: string, payload: Record<string, unknown>) => Promise<HarnessEvent>;
|
|
6
|
+
setRequestStateAndEmit: (sessionId: string, requestId: string, sequence: number, state: RequestResult["state"], options: {
|
|
7
7
|
previousState: string | null;
|
|
8
8
|
checkpointRef?: string | null;
|
|
9
9
|
error?: string;
|
|
10
10
|
}) => Promise<HarnessEvent>;
|
|
11
|
-
requestApprovalAndEmit: (
|
|
11
|
+
requestApprovalAndEmit: (sessionId: string, requestId: string, input: MessageContent, interruptContent: string | undefined, checkpointRef: string, sequence: number) => Promise<{
|
|
12
12
|
approval: import("../../../contracts/runtime.js").InternalApprovalRecord;
|
|
13
13
|
event: HarnessEvent;
|
|
14
14
|
}>;
|
|
15
|
-
emitSyntheticFallback: (
|
|
15
|
+
emitSyntheticFallback: (sessionId: string, requestId: string, selectedAgentId: string, error: unknown, sequence?: number) => Promise<void>;
|
|
16
16
|
};
|
|
17
17
|
export {};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { emitRequestCreatedEvent, emitSyntheticFallbackEvent, requestApprovalAndEmitEvent, setRequestStateAndEmitEvent } from "./events.js";
|
|
2
2
|
export function createRuntimeEventOperations(runtime) {
|
|
3
3
|
return {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
requestApprovalAndEmit: (
|
|
7
|
-
emitSyntheticFallback: (
|
|
4
|
+
emitRequestCreated: (sessionId, requestId, payload) => emitRequestCreatedEvent(runtime, sessionId, requestId, payload),
|
|
5
|
+
setRequestStateAndEmit: (sessionId, requestId, sequence, state, options) => setRequestStateAndEmitEvent(runtime, sessionId, requestId, sequence, state, options),
|
|
6
|
+
requestApprovalAndEmit: (sessionId, requestId, input, interruptContent, checkpointRef, sequence) => requestApprovalAndEmitEvent(runtime, sessionId, requestId, input, interruptContent, checkpointRef, sequence),
|
|
7
|
+
emitSyntheticFallback: (sessionId, requestId, selectedAgentId, error, sequence) => emitSyntheticFallbackEvent(runtime, sessionId, requestId, selectedAgentId, error, sequence),
|
|
8
8
|
};
|
|
9
9
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { HarnessEvent, HarnessStreamItem,
|
|
1
|
+
import type { HarnessEvent, HarnessStreamItem, RequestListeners, RequestResult } from "../../../contracts/types.js";
|
|
2
2
|
export type InternalHarnessStreamItem = HarnessStreamItem | {
|
|
3
3
|
type: "content";
|
|
4
4
|
sessionId: string;
|
|
@@ -20,13 +20,13 @@ export type InternalHarnessStreamItem = HarnessStreamItem | {
|
|
|
20
20
|
output: unknown;
|
|
21
21
|
isError?: boolean;
|
|
22
22
|
};
|
|
23
|
-
export declare function emitOutputDeltaAndCreateItem(emit: (
|
|
24
|
-
export declare function createContentBlocksItem(
|
|
23
|
+
export declare function emitOutputDeltaAndCreateItem(emit: (sessionId: string, requestId: string, sequence: number, eventType: string, payload: Record<string, unknown>) => Promise<HarnessEvent>, sessionId: string, requestId: string, agentId: string, content: string): Promise<InternalHarnessStreamItem>;
|
|
24
|
+
export declare function createContentBlocksItem(sessionId: string, requestId: string, agentId: string, contentBlocks: unknown[]): InternalHarnessStreamItem;
|
|
25
25
|
export declare function createToolResultKey(toolName: string, output: unknown, isError?: boolean): string;
|
|
26
|
-
export declare function
|
|
26
|
+
export declare function dispatchRequestListeners(stream: AsyncGenerator<InternalHarnessStreamItem>, listeners: RequestListeners, options: {
|
|
27
27
|
notifyListener: <T>(listener: ((value: T) => void | Promise<void>) | undefined, value: T) => Promise<void>;
|
|
28
|
-
|
|
29
|
-
currentState:
|
|
28
|
+
getSession: (sessionId: string) => Promise<{
|
|
29
|
+
currentState: RequestResult["state"];
|
|
30
30
|
latestRequestId: string;
|
|
31
31
|
entryAgentId: string;
|
|
32
32
|
currentAgentId?: string;
|
|
@@ -38,4 +38,5 @@ export declare function dispatchRunListeners(stream: AsyncGenerator<InternalHarn
|
|
|
38
38
|
pendingActionId?: string;
|
|
39
39
|
};
|
|
40
40
|
} | null>;
|
|
41
|
-
}): Promise<
|
|
41
|
+
}): Promise<RequestResult>;
|
|
42
|
+
export declare const dispatchRunListeners: typeof dispatchRequestListeners;
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export async function emitOutputDeltaAndCreateItem(emit,
|
|
3
|
-
await emit(
|
|
1
|
+
import { createFallbackRequestResultFromLatestEvent, mergeRequestResultOutput } from "../run/helpers.js";
|
|
2
|
+
export async function emitOutputDeltaAndCreateItem(emit, sessionId, requestId, agentId, content) {
|
|
3
|
+
await emit(sessionId, requestId, 3, "output.delta", {
|
|
4
4
|
content,
|
|
5
5
|
});
|
|
6
6
|
return {
|
|
7
7
|
type: "content",
|
|
8
|
-
sessionId
|
|
9
|
-
requestId
|
|
8
|
+
sessionId,
|
|
9
|
+
requestId,
|
|
10
10
|
agentId,
|
|
11
11
|
content,
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
|
-
export function createContentBlocksItem(
|
|
14
|
+
export function createContentBlocksItem(sessionId, requestId, agentId, contentBlocks) {
|
|
15
15
|
return {
|
|
16
16
|
type: "content-blocks",
|
|
17
|
-
sessionId
|
|
18
|
-
requestId
|
|
17
|
+
sessionId,
|
|
18
|
+
requestId,
|
|
19
19
|
agentId,
|
|
20
20
|
contentBlocks,
|
|
21
21
|
};
|
|
@@ -30,7 +30,7 @@ export function createToolResultKey(toolName, output, isError) {
|
|
|
30
30
|
}
|
|
31
31
|
return JSON.stringify([toolName, serializedOutput, isError === true]);
|
|
32
32
|
}
|
|
33
|
-
export async function
|
|
33
|
+
export async function dispatchRequestListeners(stream, listeners, options) {
|
|
34
34
|
let latestEvent;
|
|
35
35
|
let latestResult;
|
|
36
36
|
let output = "";
|
|
@@ -65,20 +65,21 @@ export async function dispatchRunListeners(stream, listeners, options) {
|
|
|
65
65
|
throw new Error("run did not emit any events");
|
|
66
66
|
}
|
|
67
67
|
if (latestResult) {
|
|
68
|
-
return
|
|
68
|
+
return mergeRequestResultOutput(latestResult, output);
|
|
69
69
|
}
|
|
70
|
-
const
|
|
71
|
-
if (!
|
|
70
|
+
const session = await options.getSession(latestEvent.sessionId);
|
|
71
|
+
if (!session) {
|
|
72
72
|
throw new Error(`Unknown session ${latestEvent.sessionId}`);
|
|
73
73
|
}
|
|
74
|
-
return
|
|
74
|
+
return createFallbackRequestResultFromLatestEvent({
|
|
75
75
|
latestEvent,
|
|
76
|
-
currentState:
|
|
77
|
-
|
|
78
|
-
entryAgentId:
|
|
79
|
-
latestAgentId:
|
|
80
|
-
approvalId:
|
|
81
|
-
pendingActionId:
|
|
76
|
+
currentState: session.currentState,
|
|
77
|
+
latestRequestId: session.latestRequestId,
|
|
78
|
+
entryAgentId: session.entryAgentId,
|
|
79
|
+
latestAgentId: session.currentAgentId ?? session.requests[0]?.agentId,
|
|
80
|
+
approvalId: session.pendingDecision?.approvalId,
|
|
81
|
+
pendingActionId: session.pendingDecision?.pendingActionId,
|
|
82
82
|
output,
|
|
83
83
|
});
|
|
84
84
|
}
|
|
85
|
+
export const dispatchRunListeners = dispatchRequestListeners;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
function classifyTimelineItem(event) {
|
|
2
2
|
switch (event.eventType) {
|
|
3
|
-
case "
|
|
4
|
-
case "
|
|
3
|
+
case "request.queued":
|
|
4
|
+
case "request.dequeued":
|
|
5
5
|
return "queue";
|
|
6
6
|
case "approval.requested":
|
|
7
7
|
case "approval.resolved":
|
|
8
8
|
return "approval";
|
|
9
|
-
case "
|
|
9
|
+
case "request.resumed":
|
|
10
10
|
return "recovery";
|
|
11
11
|
case "artifact.created":
|
|
12
12
|
return "artifact";
|
|
13
|
-
case "
|
|
14
|
-
case "
|
|
15
|
-
return "
|
|
13
|
+
case "request.created":
|
|
14
|
+
case "request.state.changed":
|
|
15
|
+
return "request";
|
|
16
16
|
default:
|
|
17
17
|
return "other";
|
|
18
18
|
}
|
|
@@ -16,4 +16,4 @@ export * from "./run/run-queue.js";
|
|
|
16
16
|
export * from "./system/skill-requirements.js";
|
|
17
17
|
export * from "./system/store.js";
|
|
18
18
|
export * from "./events/streaming.js";
|
|
19
|
-
export * from "./system/
|
|
19
|
+
export * from "./system/session-memory-sync.js";
|
|
@@ -16,4 +16,4 @@ export * from "./run/run-queue.js";
|
|
|
16
16
|
export * from "./system/skill-requirements.js";
|
|
17
17
|
export * from "./system/store.js";
|
|
18
18
|
export * from "./events/streaming.js";
|
|
19
|
-
export * from "./system/
|
|
19
|
+
export * from "./system/session-memory-sync.js";
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type { ApprovalRecord, HarnessEvent, InternalApprovalRecord, InvocationEnvelope,
|
|
1
|
+
import type { ApprovalRecord, HarnessEvent, InternalApprovalRecord, InvocationEnvelope, RequestListeners, RequestOptions, RequestResult, RequestStartOptions, MessageContent } from "../../../contracts/types.js";
|
|
2
2
|
export declare function toInspectableApprovalRecord(approval: InternalApprovalRecord): ApprovalRecord;
|
|
3
|
-
export declare function normalizeInvocationEnvelope(options:
|
|
3
|
+
export declare function normalizeInvocationEnvelope(options: RequestStartOptions): {
|
|
4
4
|
context?: Record<string, unknown>;
|
|
5
5
|
state?: Record<string, unknown>;
|
|
6
6
|
files?: Record<string, unknown>;
|
|
7
7
|
invocation?: InvocationEnvelope;
|
|
8
8
|
};
|
|
9
|
-
export declare function
|
|
10
|
-
export declare function
|
|
9
|
+
export declare function isTerminalRequestState(state: RequestResult["state"]): boolean;
|
|
10
|
+
export declare function buildPersistedRequestInput(input: MessageContent, invocation: {
|
|
11
11
|
context?: Record<string, unknown>;
|
|
12
12
|
state?: Record<string, unknown>;
|
|
13
13
|
files?: Record<string, unknown>;
|
|
@@ -18,16 +18,19 @@ export declare function buildPersistedRunRequest(input: MessageContent, invocati
|
|
|
18
18
|
invocation?: InvocationEnvelope;
|
|
19
19
|
savedAt: string;
|
|
20
20
|
};
|
|
21
|
-
export declare function
|
|
22
|
-
export declare function
|
|
23
|
-
export declare
|
|
24
|
-
export declare function
|
|
21
|
+
export declare function normalizeRequestPriority(priority?: number): number;
|
|
22
|
+
export declare function resolveRequestListeners(options: RequestOptions): RequestListeners | undefined;
|
|
23
|
+
export declare const resolveRunListeners: typeof resolveRequestListeners;
|
|
24
|
+
export declare function mergeRequestResultOutput(result: RequestResult, streamedOutput: string): RequestResult;
|
|
25
|
+
export declare const mergeRunResultOutput: typeof mergeRequestResultOutput;
|
|
26
|
+
export declare function createFallbackRequestResultFromLatestEvent(input: {
|
|
25
27
|
latestEvent: HarnessEvent;
|
|
26
|
-
currentState:
|
|
27
|
-
|
|
28
|
+
currentState: RequestResult["state"];
|
|
29
|
+
latestRequestId: string;
|
|
28
30
|
entryAgentId: string;
|
|
29
31
|
latestAgentId?: string;
|
|
30
32
|
approvalId?: string;
|
|
31
33
|
pendingActionId?: string;
|
|
32
34
|
output: string;
|
|
33
|
-
}):
|
|
35
|
+
}): RequestResult;
|
|
36
|
+
export declare const createFallbackRunResultFromLatestEvent: typeof createFallbackRequestResultFromLatestEvent;
|
|
@@ -12,10 +12,10 @@ export function normalizeInvocationEnvelope(options) {
|
|
|
12
12
|
invocation,
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
|
-
export function
|
|
15
|
+
export function isTerminalRequestState(state) {
|
|
16
16
|
return state === "completed" || state === "failed";
|
|
17
17
|
}
|
|
18
|
-
export function
|
|
18
|
+
export function buildPersistedRequestInput(input, invocation, priority) {
|
|
19
19
|
const envelope = invocation.invocation ?? {
|
|
20
20
|
...(invocation.context ? { context: invocation.context } : {}),
|
|
21
21
|
...(invocation.state ? { inputs: invocation.state } : {}),
|
|
@@ -35,30 +35,32 @@ export function buildPersistedRunRequest(input, invocation, priority) {
|
|
|
35
35
|
savedAt: new Date().toISOString(),
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
|
-
export function
|
|
38
|
+
export function normalizeRequestPriority(priority) {
|
|
39
39
|
if (!Number.isFinite(priority)) {
|
|
40
40
|
return 0;
|
|
41
41
|
}
|
|
42
42
|
return Math.trunc(priority);
|
|
43
43
|
}
|
|
44
|
-
export function
|
|
44
|
+
export function resolveRequestListeners(options) {
|
|
45
45
|
const listeners = options.listeners;
|
|
46
46
|
if (!listeners) {
|
|
47
47
|
return undefined;
|
|
48
48
|
}
|
|
49
49
|
return listeners;
|
|
50
50
|
}
|
|
51
|
-
export
|
|
51
|
+
export const resolveRunListeners = resolveRequestListeners;
|
|
52
|
+
export function mergeRequestResultOutput(result, streamedOutput) {
|
|
52
53
|
return {
|
|
53
54
|
...result,
|
|
54
55
|
output: result.output || streamedOutput,
|
|
55
56
|
finalMessageText: result.finalMessageText ?? result.output ?? streamedOutput,
|
|
56
57
|
};
|
|
57
58
|
}
|
|
58
|
-
export
|
|
59
|
+
export const mergeRunResultOutput = mergeRequestResultOutput;
|
|
60
|
+
export function createFallbackRequestResultFromLatestEvent(input) {
|
|
59
61
|
return {
|
|
60
62
|
sessionId: input.latestEvent.sessionId,
|
|
61
|
-
requestId: input.
|
|
63
|
+
requestId: input.latestRequestId,
|
|
62
64
|
agentId: input.latestAgentId ?? input.entryAgentId,
|
|
63
65
|
state: input.currentState,
|
|
64
66
|
output: input.output,
|
|
@@ -66,3 +68,4 @@ export function createFallbackRunResultFromLatestEvent(input) {
|
|
|
66
68
|
pendingActionId: input.pendingActionId,
|
|
67
69
|
};
|
|
68
70
|
}
|
|
71
|
+
export const createFallbackRunResultFromLatestEvent = createFallbackRequestResultFromLatestEvent;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { CompiledAgentBinding, RuntimeSnapshot, RuntimeSurfaceItem } from "../../../contracts/types.js";
|
|
2
|
-
export declare function
|
|
3
|
-
|
|
2
|
+
export declare function buildRequestRuntimeSnapshot(binding: CompiledAgentBinding, options?: {
|
|
3
|
+
requestId?: string;
|
|
4
|
+
legacyRequestId?: string;
|
|
4
5
|
}): RuntimeSnapshot;
|
|
5
6
|
export declare function consumeRunInspectionUpstreamEvent(input: {
|
|
6
7
|
event: unknown;
|
|
@@ -28,7 +28,7 @@ function readTracingConfig(binding) {
|
|
|
28
28
|
asObject(legacyDeepAgentTracing) ??
|
|
29
29
|
null);
|
|
30
30
|
}
|
|
31
|
-
function buildRuntimeSnapshotTracing(binding,
|
|
31
|
+
function buildRuntimeSnapshotTracing(binding, requestId) {
|
|
32
32
|
const tracing = readTracingConfig(binding);
|
|
33
33
|
const observability = asObject(binding.harnessRuntime.observability);
|
|
34
34
|
const runtimeTracing = asObject(observability?.tracing);
|
|
@@ -41,12 +41,12 @@ function buildRuntimeSnapshotTracing(binding, runId) {
|
|
|
41
41
|
}))
|
|
42
42
|
: [];
|
|
43
43
|
if (!tracing) {
|
|
44
|
-
if (!runtimeTracing ||
|
|
44
|
+
if (!runtimeTracing || requestId === undefined || runtimeTracing.enabled === false) {
|
|
45
45
|
return undefined;
|
|
46
46
|
}
|
|
47
47
|
return {
|
|
48
48
|
enabled: true,
|
|
49
|
-
correlationId:
|
|
49
|
+
correlationId: requestId,
|
|
50
50
|
metadata: {
|
|
51
51
|
...(typeof runtimeTracing.propagation === "string" ? { propagation: runtimeTracing.propagation } : {}),
|
|
52
52
|
...(exporters.length > 0 ? { exporters } : {}),
|
|
@@ -54,14 +54,14 @@ function buildRuntimeSnapshotTracing(binding, runId) {
|
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
56
|
const enabled = tracing.enabled !== false;
|
|
57
|
-
if (!enabled || !
|
|
57
|
+
if (!enabled || !requestId) {
|
|
58
58
|
return undefined;
|
|
59
59
|
}
|
|
60
60
|
const tags = readStringArray(tracing.tags);
|
|
61
61
|
const metadata = asObject(tracing.metadata);
|
|
62
62
|
return {
|
|
63
63
|
enabled: true,
|
|
64
|
-
correlationId:
|
|
64
|
+
correlationId: requestId,
|
|
65
65
|
...(tags.length > 0 ? { tags } : {}),
|
|
66
66
|
...((metadata && Object.keys(metadata).length > 0) || exporters.length > 0 || typeof runtimeTracing?.propagation === "string"
|
|
67
67
|
? {
|
|
@@ -74,9 +74,9 @@ function buildRuntimeSnapshotTracing(binding, runId) {
|
|
|
74
74
|
: {}),
|
|
75
75
|
};
|
|
76
76
|
}
|
|
77
|
-
export function
|
|
77
|
+
export function buildRequestRuntimeSnapshot(binding, options) {
|
|
78
78
|
const model = getBindingPrimaryModel(binding);
|
|
79
|
-
const tracing = buildRuntimeSnapshotTracing(binding, options?.
|
|
79
|
+
const tracing = buildRuntimeSnapshotTracing(binding, options?.requestId ?? options?.legacyRequestId);
|
|
80
80
|
const init = typeof model?.init === "object" && model.init ? model.init : {};
|
|
81
81
|
const baseUrl = typeof init.baseUrl === "string" && init.baseUrl.trim().length > 0
|
|
82
82
|
? init.baseUrl.trim()
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { ApprovalRecord,
|
|
1
|
+
import type { ApprovalRecord, RequestSummary, RuntimeOperatorOverview, RuntimeHealthSnapshot } from "../../../contracts/types.js";
|
|
2
2
|
export declare function projectOperatorOverview(input: {
|
|
3
3
|
health: RuntimeHealthSnapshot;
|
|
4
|
-
|
|
4
|
+
requests: RequestSummary[];
|
|
5
5
|
approvals: ApprovalRecord[];
|
|
6
6
|
limit?: number;
|
|
7
7
|
}): RuntimeOperatorOverview;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { projectQueueDiagnostics } from "./queue-diagnostics.js";
|
|
2
|
-
const
|
|
2
|
+
const ACTIVE_REQUEST_STATES = new Set([
|
|
3
3
|
"queued",
|
|
4
4
|
"claimed",
|
|
5
5
|
"running",
|
|
@@ -14,19 +14,19 @@ function sortNewestFirst(items, selectTimestamp) {
|
|
|
14
14
|
return rightTs.localeCompare(leftTs);
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
|
-
function
|
|
17
|
+
function summarizeRequestStates(requests) {
|
|
18
18
|
const states = {};
|
|
19
|
-
for (const
|
|
20
|
-
states[
|
|
19
|
+
for (const request of requests) {
|
|
20
|
+
states[request.state] = (states[request.state] ?? 0) + 1;
|
|
21
21
|
}
|
|
22
22
|
return states;
|
|
23
23
|
}
|
|
24
|
-
function collectGovernanceToolPolicies(
|
|
25
|
-
return
|
|
24
|
+
function collectGovernanceToolPolicies(requests) {
|
|
25
|
+
return requests.flatMap((request) => request.runtimeSnapshot?.governance?.bundles ?? [])
|
|
26
26
|
.flatMap((bundle) => bundle.toolPolicies);
|
|
27
27
|
}
|
|
28
|
-
function projectGovernanceDiagnostics(
|
|
29
|
-
const toolPolicies = collectGovernanceToolPolicies(
|
|
28
|
+
function projectGovernanceDiagnostics(requests) {
|
|
29
|
+
const toolPolicies = collectGovernanceToolPolicies(requests);
|
|
30
30
|
const highRiskTools = toolPolicies.filter((tool) => tool.risk === "high").length;
|
|
31
31
|
const approvalRequiredTools = toolPolicies.filter((tool) => tool.requiresApproval).length;
|
|
32
32
|
const autoApprovedTools = toolPolicies.filter((tool) => tool.decisionMode === "auto-approve").length;
|
|
@@ -35,7 +35,7 @@ function projectGovernanceDiagnostics(runs) {
|
|
|
35
35
|
const crossTenantTools = toolPolicies.filter((tool) => tool.tenantScope === "cross-tenant").length;
|
|
36
36
|
const writeAccessMcpTools = toolPolicies.filter((tool) => tool.category === "mcp" && tool.mcpAccess === "read-write").length;
|
|
37
37
|
return {
|
|
38
|
-
runsWithGovernance:
|
|
38
|
+
runsWithGovernance: requests.filter((request) => (request.runtimeSnapshot?.governance?.bundles?.length ?? 0) > 0).length,
|
|
39
39
|
highRiskTools,
|
|
40
40
|
approvalRequiredTools,
|
|
41
41
|
autoApprovedTools,
|
|
@@ -53,15 +53,20 @@ function projectGovernanceDiagnostics(runs) {
|
|
|
53
53
|
}
|
|
54
54
|
export function projectOperatorOverview(input) {
|
|
55
55
|
const limit = typeof input.limit === "number" && Number.isFinite(input.limit) && input.limit > 0 ? Math.floor(input.limit) : 5;
|
|
56
|
-
const
|
|
56
|
+
const activeRequests = sortNewestFirst(input.requests.filter((request) => ACTIVE_REQUEST_STATES.has(request.state)), (request) => request.lastActivityAt ?? request.updatedAt);
|
|
57
57
|
const pendingApprovals = sortNewestFirst(input.approvals.filter((approval) => approval.status === "pending"), (approval) => approval.requestedAt);
|
|
58
58
|
const queue = projectQueueDiagnostics(input.health, []);
|
|
59
|
-
const governance = projectGovernanceDiagnostics(
|
|
59
|
+
const governance = projectGovernanceDiagnostics(activeRequests);
|
|
60
|
+
const requestOverview = {
|
|
61
|
+
total: activeRequests.length,
|
|
62
|
+
states: summarizeRequestStates(activeRequests),
|
|
63
|
+
items: activeRequests.slice(0, limit),
|
|
64
|
+
};
|
|
60
65
|
return {
|
|
61
66
|
updatedAt: input.health.updatedAt,
|
|
62
67
|
summary: `${queue.summary} ` +
|
|
63
68
|
`pendingApprovals=${pendingApprovals.length} ` +
|
|
64
|
-
`
|
|
69
|
+
`activeRequests=${activeRequests.length} ` +
|
|
65
70
|
`${governance.summary}`,
|
|
66
71
|
health: input.health,
|
|
67
72
|
queue,
|
|
@@ -69,11 +74,7 @@ export function projectOperatorOverview(input) {
|
|
|
69
74
|
total: pendingApprovals.length,
|
|
70
75
|
items: pendingApprovals.slice(0, limit),
|
|
71
76
|
},
|
|
72
|
-
|
|
73
|
-
total: activeRuns.length,
|
|
74
|
-
states: summarizeStates(activeRuns),
|
|
75
|
-
items: activeRuns.slice(0, limit),
|
|
76
|
-
},
|
|
77
|
+
requests: requestOverview,
|
|
77
78
|
governance,
|
|
78
79
|
};
|
|
79
80
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
export function projectQueueDiagnostics(snapshot, timeline) {
|
|
2
2
|
const queueEvents = timeline.filter((item) => item.kind === "queue" || item.kind === "recovery");
|
|
3
|
-
const summary = `active=${snapshot.stats.
|
|
4
|
-
`pending=${snapshot.stats.
|
|
5
|
-
`stuck=${snapshot.stats.
|
|
3
|
+
const summary = `active=${snapshot.stats.activeRequestSlots} ` +
|
|
4
|
+
`pending=${snapshot.stats.pendingRequestSlots} ` +
|
|
5
|
+
`stuck=${snapshot.stats.stuckRequests} ` +
|
|
6
6
|
`workload=${snapshot.checks.workload.status}`;
|
|
7
7
|
return {
|
|
8
8
|
status: snapshot.checks.workload.status,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
activeRequestSlots: snapshot.stats.activeRequestSlots,
|
|
10
|
+
pendingRequestSlots: snapshot.stats.pendingRequestSlots,
|
|
11
|
+
stuckRequests: snapshot.stats.stuckRequests,
|
|
12
12
|
queueEvents,
|
|
13
13
|
summary,
|
|
14
14
|
};
|