@botbotgo/agent-harness 0.0.229 → 0.0.231
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/dist/contracts/runtime.d.ts +32 -4
- package/dist/package-version.d.ts +1 -1
- package/dist/package-version.js +1 -1
- package/dist/persistence/file-store.d.ts +2 -0
- package/dist/persistence/file-store.js +10 -2
- package/dist/persistence/sqlite-store.d.ts +2 -0
- package/dist/persistence/sqlite-store.js +23 -9
- package/dist/persistence/types.d.ts +3 -0
- package/dist/protocol/a2a/http.js +6 -0
- package/dist/runtime/harness/run/stream-run.d.ts +2 -0
- package/dist/runtime/harness/run/stream-run.js +1 -0
- package/dist/runtime/harness/run/thread-records.d.ts +2 -1
- package/dist/runtime/harness/run/thread-records.js +66 -37
- package/dist/runtime/harness.js +15 -23
- package/package.json +1 -1
|
@@ -62,6 +62,26 @@ export type RuntimeTimelineProjectionOptions = {
|
|
|
62
62
|
threadId?: string;
|
|
63
63
|
runId?: string;
|
|
64
64
|
};
|
|
65
|
+
/**
|
|
66
|
+
* Ordered upstream/runtime execution trace projected from persisted upstream events.
|
|
67
|
+
* This is an inspection surface for recovery/debugging, not a second execution protocol.
|
|
68
|
+
*/
|
|
69
|
+
export type RuntimeHistoryItem = {
|
|
70
|
+
type: "thinking";
|
|
71
|
+
text: string;
|
|
72
|
+
} | {
|
|
73
|
+
type: "step";
|
|
74
|
+
step: string;
|
|
75
|
+
category: "llm" | "tool" | "skill" | "memory" | "chain" | "approval";
|
|
76
|
+
status: "started" | "completed" | "failed";
|
|
77
|
+
key: string;
|
|
78
|
+
} | {
|
|
79
|
+
type: "tool-result";
|
|
80
|
+
toolName: string;
|
|
81
|
+
output: unknown;
|
|
82
|
+
isError?: boolean;
|
|
83
|
+
key: string;
|
|
84
|
+
};
|
|
65
85
|
export type RuntimeQueueDiagnostics = {
|
|
66
86
|
status: HealthStatus;
|
|
67
87
|
activeRunSlots: number;
|
|
@@ -462,7 +482,11 @@ export type RequestSummary = Omit<ThreadRunRecord, "threadId" | "runId"> & {
|
|
|
462
482
|
sessionId: string;
|
|
463
483
|
requestId: string;
|
|
464
484
|
};
|
|
465
|
-
export type RequestRecord = RequestSummary
|
|
485
|
+
export type RequestRecord = RequestSummary & {
|
|
486
|
+
history?: RuntimeHistoryItem[];
|
|
487
|
+
upstreamEvents?: unknown[];
|
|
488
|
+
runtimeTimeline?: RuntimeTimelineItem[];
|
|
489
|
+
};
|
|
466
490
|
/**
|
|
467
491
|
* Backward-compatible alias for older thread/run terminology.
|
|
468
492
|
*/
|
|
@@ -470,7 +494,11 @@ export type RunSummary = Omit<RequestSummary, "sessionId" | "requestId"> & {
|
|
|
470
494
|
threadId: string;
|
|
471
495
|
runId: string;
|
|
472
496
|
};
|
|
473
|
-
export type RunRecord = RunSummary
|
|
497
|
+
export type RunRecord = RunSummary & {
|
|
498
|
+
history?: RuntimeHistoryItem[];
|
|
499
|
+
upstreamEvents?: unknown[];
|
|
500
|
+
runtimeTimeline?: RuntimeTimelineItem[];
|
|
501
|
+
};
|
|
474
502
|
/**
|
|
475
503
|
* Persisted session inspection record assembled from runtime records.
|
|
476
504
|
* This is an inspectable projection, not a second session semantic model.
|
|
@@ -484,7 +512,7 @@ export type SessionRecord = {
|
|
|
484
512
|
createdAt: string;
|
|
485
513
|
updatedAt: string;
|
|
486
514
|
messages: TranscriptMessage[];
|
|
487
|
-
requests:
|
|
515
|
+
requests: RequestRecord[];
|
|
488
516
|
pendingDecision?: {
|
|
489
517
|
approvalId: string;
|
|
490
518
|
pendingActionId: string;
|
|
@@ -499,7 +527,7 @@ export type SessionRecord = {
|
|
|
499
527
|
export type ThreadRecord = Omit<SessionRecord, "sessionId" | "latestRequestId" | "requests"> & {
|
|
500
528
|
threadId: string;
|
|
501
529
|
latestRunId: string;
|
|
502
|
-
runs:
|
|
530
|
+
runs: RunRecord[];
|
|
503
531
|
};
|
|
504
532
|
export type ResumeOptions = {
|
|
505
533
|
threadId?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const AGENT_HARNESS_VERSION = "0.0.
|
|
1
|
+
export declare const AGENT_HARNESS_VERSION = "0.0.230";
|
package/dist/package-version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const AGENT_HARNESS_VERSION = "0.0.
|
|
1
|
+
export const AGENT_HARNESS_VERSION = "0.0.230";
|
|
@@ -60,6 +60,8 @@ export declare class FilePersistence implements RuntimePersistence {
|
|
|
60
60
|
currentAgentId?: string | null;
|
|
61
61
|
delegationChain?: string[];
|
|
62
62
|
runtimeSnapshot?: RunSummary["runtimeSnapshot"] | null;
|
|
63
|
+
upstreamEvents?: unknown[];
|
|
64
|
+
appendUpstreamEvent?: unknown;
|
|
63
65
|
}): Promise<void>;
|
|
64
66
|
deleteThread(threadId: string): Promise<boolean>;
|
|
65
67
|
saveRunRequest(threadId: string, runId: string, request: PersistedRunRequest): Promise<void>;
|
|
@@ -91,6 +91,7 @@ export class FilePersistence {
|
|
|
91
91
|
currentAgentId: input.currentAgentId ?? input.agentId,
|
|
92
92
|
delegationChain: input.delegationChain ?? [input.currentAgentId ?? input.agentId],
|
|
93
93
|
runtimeSnapshot: input.runtimeSnapshot ?? null,
|
|
94
|
+
upstreamEvents: [],
|
|
94
95
|
};
|
|
95
96
|
await Promise.all([
|
|
96
97
|
writeJson(path.join(runDir, "meta.json"), meta),
|
|
@@ -375,11 +376,17 @@ export class FilePersistence {
|
|
|
375
376
|
return readJson(path.join(this.runDir(threadId, runId), "lifecycle.json"));
|
|
376
377
|
}
|
|
377
378
|
async getRunInspection(threadId, runId) {
|
|
378
|
-
|
|
379
|
+
const inspection = await readJson(path.join(this.runDir(threadId, runId), "inspection.json"));
|
|
380
|
+
return {
|
|
381
|
+
...inspection,
|
|
382
|
+
upstreamEvents: Array.isArray(inspection.upstreamEvents) ? inspection.upstreamEvents : [],
|
|
383
|
+
};
|
|
379
384
|
}
|
|
380
385
|
async updateRunInspection(threadId, runId, patch) {
|
|
381
386
|
const inspectionPath = path.join(this.runDir(threadId, runId), "inspection.json");
|
|
382
|
-
const current = await
|
|
387
|
+
const current = await this.getRunInspection(threadId, runId);
|
|
388
|
+
const nextUpstreamEvents = patch.upstreamEvents
|
|
389
|
+
?? (patch.appendUpstreamEvent === undefined ? current.upstreamEvents : [...current.upstreamEvents, patch.appendUpstreamEvent]);
|
|
383
390
|
await writeJson(inspectionPath, {
|
|
384
391
|
...current,
|
|
385
392
|
...(patch.endedAt !== undefined ? { endedAt: patch.endedAt } : {}),
|
|
@@ -387,6 +394,7 @@ export class FilePersistence {
|
|
|
387
394
|
...(patch.currentAgentId !== undefined ? { currentAgentId: patch.currentAgentId } : {}),
|
|
388
395
|
...(patch.delegationChain ? { delegationChain: patch.delegationChain } : {}),
|
|
389
396
|
...(patch.runtimeSnapshot !== undefined ? { runtimeSnapshot: patch.runtimeSnapshot } : {}),
|
|
397
|
+
upstreamEvents: nextUpstreamEvents,
|
|
390
398
|
});
|
|
391
399
|
}
|
|
392
400
|
async deleteThread(threadId) {
|
|
@@ -81,6 +81,8 @@ export declare class SqlitePersistence implements RuntimePersistence {
|
|
|
81
81
|
currentAgentId?: string | null;
|
|
82
82
|
delegationChain?: string[];
|
|
83
83
|
runtimeSnapshot?: RunSummary["runtimeSnapshot"] | null;
|
|
84
|
+
upstreamEvents?: unknown[];
|
|
85
|
+
appendUpstreamEvent?: unknown;
|
|
84
86
|
}): Promise<void>;
|
|
85
87
|
deleteThread(threadId: string): Promise<boolean>;
|
|
86
88
|
saveRunRequest(threadId: string, runId: string, request: PersistedRunRequest): Promise<void>;
|
|
@@ -4,7 +4,7 @@ import { createClient } from "@libsql/client";
|
|
|
4
4
|
import { fileExists, readJson, writeJson } from "../utils/fs.js";
|
|
5
5
|
import { SqliteRunContextStore } from "./sqlite-run-context-store.js";
|
|
6
6
|
import { SqliteRunQueueStore } from "./sqlite-run-queue-store.js";
|
|
7
|
-
const RUNTIME_SQLITE_SCHEMA_VERSION =
|
|
7
|
+
const RUNTIME_SQLITE_SCHEMA_VERSION = 4;
|
|
8
8
|
const RUNTIME_SQLITE_SCHEMA_FAMILY = "agent-harness-runtime";
|
|
9
9
|
function asRow(value) {
|
|
10
10
|
return value;
|
|
@@ -191,6 +191,7 @@ export class SqlitePersistence {
|
|
|
191
191
|
current_agent_id TEXT,
|
|
192
192
|
delegation_chain_json TEXT NOT NULL,
|
|
193
193
|
runtime_snapshot_json TEXT,
|
|
194
|
+
upstream_events_json TEXT NOT NULL DEFAULT '[]',
|
|
194
195
|
FOREIGN KEY (thread_id) REFERENCES threads(thread_id),
|
|
195
196
|
FOREIGN KEY (run_id) REFERENCES runs(run_id)
|
|
196
197
|
)
|
|
@@ -461,19 +462,26 @@ export class SqlitePersistence {
|
|
|
461
462
|
current_agent_id TEXT,
|
|
462
463
|
delegation_chain_json TEXT NOT NULL,
|
|
463
464
|
runtime_snapshot_json TEXT,
|
|
465
|
+
upstream_events_json TEXT NOT NULL DEFAULT '[]',
|
|
464
466
|
FOREIGN KEY (thread_id) REFERENCES threads(thread_id),
|
|
465
467
|
FOREIGN KEY (run_id) REFERENCES runs(run_id)
|
|
466
468
|
)
|
|
467
469
|
`);
|
|
468
470
|
await this.rawExecute(`
|
|
469
471
|
INSERT OR IGNORE INTO run_inspection
|
|
470
|
-
(run_id, thread_id, started_at, ended_at, last_activity_at, current_agent_id, delegation_chain_json, runtime_snapshot_json)
|
|
471
|
-
SELECT run_id, thread_id, created_at, NULL, updated_at, agent_id, json_array(agent_id), NULL
|
|
472
|
+
(run_id, thread_id, started_at, ended_at, last_activity_at, current_agent_id, delegation_chain_json, runtime_snapshot_json, upstream_events_json)
|
|
473
|
+
SELECT run_id, thread_id, created_at, NULL, updated_at, agent_id, json_array(agent_id), NULL, '[]'
|
|
472
474
|
FROM runs
|
|
473
475
|
`);
|
|
474
476
|
await this.rawExecute("INSERT OR REPLACE INTO runtime_metadata (key, value) VALUES (?, ?)", ["schema_version", String(RUNTIME_SQLITE_SCHEMA_VERSION)]);
|
|
475
477
|
return;
|
|
476
478
|
}
|
|
479
|
+
if (version === "3") {
|
|
480
|
+
await this.rawExecute("ALTER TABLE run_inspection ADD COLUMN upstream_events_json TEXT NOT NULL DEFAULT '[]'");
|
|
481
|
+
await this.rawExecute("UPDATE run_inspection SET upstream_events_json = '[]' WHERE upstream_events_json IS NULL");
|
|
482
|
+
await this.rawExecute("INSERT OR REPLACE INTO runtime_metadata (key, value) VALUES (?, ?)", ["schema_version", String(RUNTIME_SQLITE_SCHEMA_VERSION)]);
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
477
485
|
if (version !== String(RUNTIME_SQLITE_SCHEMA_VERSION)) {
|
|
478
486
|
throw new Error(`Unsupported runtime sqlite schema version ${JSON.stringify(version)} in ${this.dbPath}. Expected ${RUNTIME_SQLITE_SCHEMA_VERSION}.`);
|
|
479
487
|
}
|
|
@@ -522,8 +530,8 @@ export class SqlitePersistence {
|
|
|
522
530
|
args: [input.runId],
|
|
523
531
|
}, {
|
|
524
532
|
sql: `INSERT OR REPLACE INTO run_inspection
|
|
525
|
-
(run_id, thread_id, started_at, ended_at, last_activity_at, current_agent_id, delegation_chain_json, runtime_snapshot_json)
|
|
526
|
-
VALUES (?, ?, ?, NULL, ?, ?, ?, ?)`,
|
|
533
|
+
(run_id, thread_id, started_at, ended_at, last_activity_at, current_agent_id, delegation_chain_json, runtime_snapshot_json, upstream_events_json)
|
|
534
|
+
VALUES (?, ?, ?, NULL, ?, ?, ?, ?, ?)`,
|
|
527
535
|
args: [
|
|
528
536
|
input.runId,
|
|
529
537
|
input.threadId,
|
|
@@ -532,6 +540,7 @@ export class SqlitePersistence {
|
|
|
532
540
|
input.currentAgentId ?? input.agentId,
|
|
533
541
|
JSON.stringify(input.delegationChain ?? [input.currentAgentId ?? input.agentId]),
|
|
534
542
|
input.runtimeSnapshot ? JSON.stringify(input.runtimeSnapshot) : null,
|
|
543
|
+
"[]",
|
|
535
544
|
],
|
|
536
545
|
}, {
|
|
537
546
|
sql: `INSERT INTO thread_messages
|
|
@@ -575,8 +584,8 @@ export class SqlitePersistence {
|
|
|
575
584
|
(run_id, cancel_requested, cancel_reason, cancel_requested_at, heartbeat_at, worker_id, worker_started_at)
|
|
576
585
|
VALUES (?, 0, NULL, NULL, NULL, NULL, NULL)`, [input.runId]);
|
|
577
586
|
await this.execute(`INSERT OR REPLACE INTO run_inspection
|
|
578
|
-
(run_id, thread_id, started_at, ended_at, last_activity_at, current_agent_id, delegation_chain_json, runtime_snapshot_json)
|
|
579
|
-
VALUES (?, ?, ?, NULL, ?, ?, ?, ?)`, [
|
|
587
|
+
(run_id, thread_id, started_at, ended_at, last_activity_at, current_agent_id, delegation_chain_json, runtime_snapshot_json, upstream_events_json)
|
|
588
|
+
VALUES (?, ?, ?, NULL, ?, ?, ?, ?, ?)`, [
|
|
580
589
|
input.runId,
|
|
581
590
|
input.threadId,
|
|
582
591
|
input.startedAt ?? input.createdAt,
|
|
@@ -584,6 +593,7 @@ export class SqlitePersistence {
|
|
|
584
593
|
input.currentAgentId ?? input.agentId,
|
|
585
594
|
JSON.stringify(input.delegationChain ?? [input.currentAgentId ?? input.agentId]),
|
|
586
595
|
input.runtimeSnapshot ? JSON.stringify(input.runtimeSnapshot) : null,
|
|
596
|
+
"[]",
|
|
587
597
|
]);
|
|
588
598
|
}
|
|
589
599
|
async setRunState(threadId, runId, state, checkpointRef) {
|
|
@@ -734,7 +744,7 @@ export class SqlitePersistence {
|
|
|
734
744
|
};
|
|
735
745
|
}
|
|
736
746
|
async getRunInspection(threadId, runId) {
|
|
737
|
-
const row = await this.selectOne(`SELECT started_at, ended_at, last_activity_at, current_agent_id, delegation_chain_json, runtime_snapshot_json
|
|
747
|
+
const row = await this.selectOne(`SELECT started_at, ended_at, last_activity_at, current_agent_id, delegation_chain_json, runtime_snapshot_json, upstream_events_json
|
|
738
748
|
FROM run_inspection
|
|
739
749
|
WHERE thread_id = ? AND run_id = ?`, [threadId, runId]);
|
|
740
750
|
if (!row) {
|
|
@@ -747,18 +757,22 @@ export class SqlitePersistence {
|
|
|
747
757
|
currentAgentId: asNullableString(row.current_agent_id),
|
|
748
758
|
delegationChain: parseJson(row.delegation_chain_json),
|
|
749
759
|
runtimeSnapshot: row.runtime_snapshot_json ? parseJson(row.runtime_snapshot_json) : null,
|
|
760
|
+
upstreamEvents: row.upstream_events_json ? parseJson(row.upstream_events_json) : [],
|
|
750
761
|
};
|
|
751
762
|
}
|
|
752
763
|
async updateRunInspection(threadId, runId, patch) {
|
|
753
764
|
const current = await this.getRunInspection(threadId, runId);
|
|
765
|
+
const nextUpstreamEvents = patch.upstreamEvents
|
|
766
|
+
?? (patch.appendUpstreamEvent === undefined ? current.upstreamEvents : [...current.upstreamEvents, patch.appendUpstreamEvent]);
|
|
754
767
|
await this.execute(`UPDATE run_inspection
|
|
755
|
-
SET ended_at = ?, last_activity_at = ?, current_agent_id = ?, delegation_chain_json = ?, runtime_snapshot_json = ?
|
|
768
|
+
SET ended_at = ?, last_activity_at = ?, current_agent_id = ?, delegation_chain_json = ?, runtime_snapshot_json = ?, upstream_events_json = ?
|
|
756
769
|
WHERE run_id = ? AND thread_id = ?`, [
|
|
757
770
|
patch.endedAt === undefined ? current.endedAt : patch.endedAt,
|
|
758
771
|
patch.lastActivityAt ?? current.lastActivityAt,
|
|
759
772
|
patch.currentAgentId === undefined ? current.currentAgentId : patch.currentAgentId,
|
|
760
773
|
JSON.stringify(patch.delegationChain ?? current.delegationChain),
|
|
761
774
|
JSON.stringify(patch.runtimeSnapshot === undefined ? current.runtimeSnapshot : patch.runtimeSnapshot),
|
|
775
|
+
JSON.stringify(nextUpstreamEvents),
|
|
762
776
|
runId,
|
|
763
777
|
threadId,
|
|
764
778
|
]);
|
|
@@ -32,6 +32,7 @@ export type PersistedRunInspection = {
|
|
|
32
32
|
currentAgentId: string | null;
|
|
33
33
|
delegationChain: string[];
|
|
34
34
|
runtimeSnapshot: RuntimeSnapshot | null;
|
|
35
|
+
upstreamEvents: unknown[];
|
|
35
36
|
};
|
|
36
37
|
export type PersistedRunRequest = {
|
|
37
38
|
input: MessageContent;
|
|
@@ -139,6 +140,8 @@ export interface RuntimePersistence {
|
|
|
139
140
|
currentAgentId?: string | null;
|
|
140
141
|
delegationChain?: string[];
|
|
141
142
|
runtimeSnapshot?: RuntimeSnapshot | null;
|
|
143
|
+
upstreamEvents?: unknown[];
|
|
144
|
+
appendUpstreamEvent?: unknown;
|
|
142
145
|
}): Promise<void>;
|
|
143
146
|
deleteThread(threadId: string): Promise<boolean>;
|
|
144
147
|
saveRunRequest(threadId: string, runId: string, request: PersistedRunRequest): Promise<void>;
|
|
@@ -382,6 +382,9 @@ function toSessionRecord(session) {
|
|
|
382
382
|
currentAgentId: run.currentAgentId,
|
|
383
383
|
delegationChain: run.delegationChain,
|
|
384
384
|
runtimeSnapshot: run.runtimeSnapshot,
|
|
385
|
+
upstreamEvents: run.upstreamEvents,
|
|
386
|
+
history: run.history,
|
|
387
|
+
runtimeTimeline: run.runtimeTimeline,
|
|
385
388
|
})),
|
|
386
389
|
pendingDecision: session.pendingDecision,
|
|
387
390
|
};
|
|
@@ -407,6 +410,9 @@ function toRequestRecord(request) {
|
|
|
407
410
|
currentAgentId: request.currentAgentId,
|
|
408
411
|
delegationChain: request.delegationChain,
|
|
409
412
|
runtimeSnapshot: request.runtimeSnapshot,
|
|
413
|
+
upstreamEvents: request.upstreamEvents,
|
|
414
|
+
history: request.history,
|
|
415
|
+
runtimeTimeline: request.runtimeTimeline,
|
|
410
416
|
};
|
|
411
417
|
}
|
|
412
418
|
function buildTaskFromSessionAndRequest(session, request, approvals, output, failureMessage) {
|
|
@@ -53,6 +53,8 @@ type StreamRunOptions = {
|
|
|
53
53
|
currentAgentId?: string | null;
|
|
54
54
|
delegationChain?: string[];
|
|
55
55
|
runtimeSnapshot?: RuntimeSnapshot | null;
|
|
56
|
+
upstreamEvents?: unknown[];
|
|
57
|
+
appendUpstreamEvent?: unknown;
|
|
56
58
|
}) => Promise<void>;
|
|
57
59
|
emitSyntheticFallback: (threadId: string, runId: string, selectedAgentId: string, error: unknown) => Promise<void>;
|
|
58
60
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { ApprovalRecord, SessionRecord, SessionSummary, ThreadRecord, ThreadSummary } from "../../../contracts/types.js";
|
|
1
|
+
import type { ApprovalRecord, RequestRecord, SessionRecord, SessionSummary, RunSummary, ThreadRecord, ThreadSummary } from "../../../contracts/types.js";
|
|
2
2
|
import type { RuntimePersistence } from "../../../persistence/types.js";
|
|
3
|
+
export declare function buildRequestInspectionRecord(persistence: RuntimePersistence, request: RunSummary): Promise<RequestRecord>;
|
|
3
4
|
export declare function buildSessionInspectionRecord(input: {
|
|
4
5
|
persistence: RuntimePersistence;
|
|
5
6
|
getSession: (sessionId: string) => Promise<SessionSummary | null>;
|
|
@@ -1,11 +1,73 @@
|
|
|
1
1
|
import { isTerminalRunState, toInspectableApprovalRecord } from "./helpers.js";
|
|
2
|
+
import { projectRuntimeTimeline } from "../events/timeline.js";
|
|
3
|
+
import { createUpstreamTimelineReducer } from "../../../upstream-events.js";
|
|
2
4
|
function selectLatestPendingApproval(approvals) {
|
|
3
5
|
return approvals
|
|
4
6
|
.filter((approval) => approval.status === "pending")
|
|
5
7
|
.sort((left, right) => right.requestedAt.localeCompare(left.requestedAt))[0];
|
|
6
8
|
}
|
|
9
|
+
function buildRunInspectionProjection(upstreamEvents) {
|
|
10
|
+
const reducer = createUpstreamTimelineReducer();
|
|
11
|
+
const history = upstreamEvents.flatMap((event) => reducer.consume(event));
|
|
12
|
+
return {
|
|
13
|
+
upstreamEvents,
|
|
14
|
+
history,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export async function buildRequestInspectionRecord(persistence, request) {
|
|
18
|
+
const inspection = await persistence.getRunInspection(request.threadId, request.runId);
|
|
19
|
+
const runtimeEvents = await persistence.listRunEvents(request.threadId, request.runId);
|
|
20
|
+
const { upstreamEvents, history } = buildRunInspectionProjection(inspection.upstreamEvents);
|
|
21
|
+
return {
|
|
22
|
+
requestId: request.runId,
|
|
23
|
+
sessionId: request.threadId,
|
|
24
|
+
agentId: request.agentId,
|
|
25
|
+
executionMode: request.executionMode,
|
|
26
|
+
adapterKind: request.adapterKind,
|
|
27
|
+
createdAt: request.createdAt,
|
|
28
|
+
updatedAt: request.updatedAt,
|
|
29
|
+
state: request.state,
|
|
30
|
+
checkpointRef: request.checkpointRef,
|
|
31
|
+
resumable: request.resumable,
|
|
32
|
+
startedAt: request.startedAt,
|
|
33
|
+
endedAt: request.endedAt,
|
|
34
|
+
lastActivityAt: request.lastActivityAt,
|
|
35
|
+
currentAgentId: request.currentAgentId,
|
|
36
|
+
delegationChain: request.delegationChain,
|
|
37
|
+
runtimeSnapshot: request.runtimeSnapshot,
|
|
38
|
+
upstreamEvents,
|
|
39
|
+
history,
|
|
40
|
+
runtimeTimeline: projectRuntimeTimeline(runtimeEvents, {
|
|
41
|
+
threadId: request.threadId,
|
|
42
|
+
runId: request.runId,
|
|
43
|
+
}),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function toRunRecord(request) {
|
|
47
|
+
return {
|
|
48
|
+
runId: request.requestId,
|
|
49
|
+
threadId: request.sessionId,
|
|
50
|
+
agentId: request.agentId,
|
|
51
|
+
executionMode: request.executionMode,
|
|
52
|
+
adapterKind: request.adapterKind,
|
|
53
|
+
createdAt: request.createdAt,
|
|
54
|
+
updatedAt: request.updatedAt,
|
|
55
|
+
state: request.state,
|
|
56
|
+
checkpointRef: request.checkpointRef,
|
|
57
|
+
resumable: request.resumable,
|
|
58
|
+
startedAt: request.startedAt,
|
|
59
|
+
endedAt: request.endedAt,
|
|
60
|
+
lastActivityAt: request.lastActivityAt,
|
|
61
|
+
currentAgentId: request.currentAgentId,
|
|
62
|
+
delegationChain: request.delegationChain,
|
|
63
|
+
runtimeSnapshot: request.runtimeSnapshot,
|
|
64
|
+
upstreamEvents: request.upstreamEvents,
|
|
65
|
+
history: request.history,
|
|
66
|
+
runtimeTimeline: request.runtimeTimeline,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
7
69
|
export async function buildSessionInspectionRecord(input, sessionId) {
|
|
8
|
-
const [sessionSummary, meta, messages,
|
|
70
|
+
const [sessionSummary, meta, messages, requestSummaries] = await Promise.all([
|
|
9
71
|
input.getSession(sessionId),
|
|
10
72
|
input.persistence.getThreadMeta(sessionId),
|
|
11
73
|
input.persistence.listThreadMessages(sessionId, 200),
|
|
@@ -15,6 +77,7 @@ export async function buildSessionInspectionRecord(input, sessionId) {
|
|
|
15
77
|
return null;
|
|
16
78
|
}
|
|
17
79
|
const latestRequestId = sessionSummary.latestRequestId;
|
|
80
|
+
const requests = await Promise.all(requestSummaries.map((request) => buildRequestInspectionRecord(input.persistence, request)));
|
|
18
81
|
const latestApprovals = await input.persistence.getRunApprovals(sessionId, latestRequestId);
|
|
19
82
|
const pendingApproval = selectLatestPendingApproval(latestApprovals);
|
|
20
83
|
return {
|
|
@@ -26,24 +89,7 @@ export async function buildSessionInspectionRecord(input, sessionId) {
|
|
|
26
89
|
createdAt: meta.createdAt,
|
|
27
90
|
updatedAt: sessionSummary.updatedAt,
|
|
28
91
|
messages,
|
|
29
|
-
requests
|
|
30
|
-
requestId: request.runId,
|
|
31
|
-
sessionId: request.threadId,
|
|
32
|
-
agentId: request.agentId,
|
|
33
|
-
executionMode: request.executionMode,
|
|
34
|
-
adapterKind: request.adapterKind,
|
|
35
|
-
createdAt: request.createdAt,
|
|
36
|
-
updatedAt: request.updatedAt,
|
|
37
|
-
state: request.state,
|
|
38
|
-
checkpointRef: request.checkpointRef,
|
|
39
|
-
resumable: request.resumable,
|
|
40
|
-
startedAt: request.startedAt,
|
|
41
|
-
endedAt: request.endedAt,
|
|
42
|
-
lastActivityAt: request.lastActivityAt,
|
|
43
|
-
currentAgentId: request.currentAgentId,
|
|
44
|
-
delegationChain: request.delegationChain,
|
|
45
|
-
runtimeSnapshot: request.runtimeSnapshot,
|
|
46
|
-
})),
|
|
92
|
+
requests,
|
|
47
93
|
pendingDecision: pendingApproval
|
|
48
94
|
? {
|
|
49
95
|
approvalId: pendingApproval.approvalId,
|
|
@@ -83,24 +129,7 @@ export async function buildThreadInspectionRecord(input, threadId) {
|
|
|
83
129
|
createdAt: session.createdAt,
|
|
84
130
|
updatedAt: session.updatedAt,
|
|
85
131
|
messages: session.messages,
|
|
86
|
-
runs: session.requests.map((request) => (
|
|
87
|
-
runId: request.requestId,
|
|
88
|
-
threadId: request.sessionId,
|
|
89
|
-
agentId: request.agentId,
|
|
90
|
-
executionMode: request.executionMode,
|
|
91
|
-
adapterKind: request.adapterKind,
|
|
92
|
-
createdAt: request.createdAt,
|
|
93
|
-
updatedAt: request.updatedAt,
|
|
94
|
-
state: request.state,
|
|
95
|
-
checkpointRef: request.checkpointRef,
|
|
96
|
-
resumable: request.resumable,
|
|
97
|
-
startedAt: request.startedAt,
|
|
98
|
-
endedAt: request.endedAt,
|
|
99
|
-
lastActivityAt: request.lastActivityAt,
|
|
100
|
-
currentAgentId: request.currentAgentId,
|
|
101
|
-
delegationChain: request.delegationChain,
|
|
102
|
-
runtimeSnapshot: request.runtimeSnapshot,
|
|
103
|
-
})),
|
|
132
|
+
runs: session.requests.map((request) => toRunRecord(request)),
|
|
104
133
|
pendingDecision: session.pendingDecision,
|
|
105
134
|
}
|
|
106
135
|
: null;
|
package/dist/runtime/harness.js
CHANGED
|
@@ -39,7 +39,7 @@ import { resolveRuntimeAdapterOptions } from "./support/runtime-adapter-options.
|
|
|
39
39
|
import { initializeHarnessRuntime, reclaimExpiredClaimedRuns as reclaimHarnessExpiredClaimedRuns, recoverStartupRuns as recoverHarnessStartupRuns, isStaleRunningRun as isHarnessStaleRunningRun, } from "./harness/run/startup-runtime.js";
|
|
40
40
|
import { streamHarnessRun } from "./harness/run/stream-run.js";
|
|
41
41
|
import { defaultRequestedAgentId, prepareRunStart } from "./harness/run/start-run.js";
|
|
42
|
-
import { buildSessionInspectionRecord, deleteSessionRecord, deleteThreadRecord, getPublicApproval, listPublicApprovals, } from "./harness/run/thread-records.js";
|
|
42
|
+
import { buildRequestInspectionRecord, buildSessionInspectionRecord, deleteSessionRecord, deleteThreadRecord, getPublicApproval, listPublicApprovals, } from "./harness/run/thread-records.js";
|
|
43
43
|
export class AgentHarnessRuntime {
|
|
44
44
|
workspace;
|
|
45
45
|
runtimeAdapterOptions;
|
|
@@ -541,26 +541,7 @@ export class AgentHarnessRuntime {
|
|
|
541
541
|
}
|
|
542
542
|
async getRequest(requestId) {
|
|
543
543
|
const request = await this.persistence.getRun(requestId);
|
|
544
|
-
return request
|
|
545
|
-
? {
|
|
546
|
-
requestId: request.runId,
|
|
547
|
-
sessionId: request.threadId,
|
|
548
|
-
agentId: request.agentId,
|
|
549
|
-
executionMode: request.executionMode,
|
|
550
|
-
adapterKind: request.adapterKind,
|
|
551
|
-
createdAt: request.createdAt,
|
|
552
|
-
updatedAt: request.updatedAt,
|
|
553
|
-
state: request.state,
|
|
554
|
-
checkpointRef: request.checkpointRef,
|
|
555
|
-
resumable: request.resumable,
|
|
556
|
-
startedAt: request.startedAt,
|
|
557
|
-
endedAt: request.endedAt,
|
|
558
|
-
lastActivityAt: request.lastActivityAt,
|
|
559
|
-
currentAgentId: request.currentAgentId,
|
|
560
|
-
delegationChain: request.delegationChain,
|
|
561
|
-
runtimeSnapshot: request.runtimeSnapshot,
|
|
562
|
-
}
|
|
563
|
-
: null;
|
|
544
|
+
return request ? buildRequestInspectionRecord(this.persistence, request) : null;
|
|
564
545
|
}
|
|
565
546
|
async getRun(runId) {
|
|
566
547
|
const request = await this.getRequest(runId);
|
|
@@ -582,6 +563,9 @@ export class AgentHarnessRuntime {
|
|
|
582
563
|
currentAgentId: request.currentAgentId,
|
|
583
564
|
delegationChain: request.delegationChain,
|
|
584
565
|
runtimeSnapshot: request.runtimeSnapshot,
|
|
566
|
+
upstreamEvents: request.upstreamEvents,
|
|
567
|
+
history: request.history,
|
|
568
|
+
runtimeTimeline: request.runtimeTimeline,
|
|
585
569
|
}
|
|
586
570
|
: null;
|
|
587
571
|
}
|
|
@@ -648,6 +632,9 @@ export class AgentHarnessRuntime {
|
|
|
648
632
|
currentAgentId: request.currentAgentId,
|
|
649
633
|
delegationChain: request.delegationChain,
|
|
650
634
|
runtimeSnapshot: request.runtimeSnapshot,
|
|
635
|
+
upstreamEvents: request.upstreamEvents,
|
|
636
|
+
history: request.history,
|
|
637
|
+
runtimeTimeline: request.runtimeTimeline,
|
|
651
638
|
})),
|
|
652
639
|
pendingDecision: session.pendingDecision,
|
|
653
640
|
}
|
|
@@ -1760,12 +1747,17 @@ function toSessionRecord(record) {
|
|
|
1760
1747
|
createdAt: record.createdAt,
|
|
1761
1748
|
updatedAt: record.updatedAt,
|
|
1762
1749
|
messages: record.messages,
|
|
1763
|
-
requests: record.runs.map(
|
|
1750
|
+
requests: record.runs.map(toRequestRecord),
|
|
1764
1751
|
pendingDecision: record.pendingDecision,
|
|
1765
1752
|
};
|
|
1766
1753
|
}
|
|
1767
1754
|
function toRequestRecord(record) {
|
|
1768
|
-
return
|
|
1755
|
+
return {
|
|
1756
|
+
...toRequestSummary(record),
|
|
1757
|
+
upstreamEvents: record.upstreamEvents,
|
|
1758
|
+
history: record.history,
|
|
1759
|
+
runtimeTimeline: record.runtimeTimeline,
|
|
1760
|
+
};
|
|
1769
1761
|
}
|
|
1770
1762
|
function deriveRunRequestFromTranscript(transcript, runId) {
|
|
1771
1763
|
const candidate = [...transcript]
|