@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
|
@@ -40,16 +40,16 @@ function formatApprovalSection(approvals) {
|
|
|
40
40
|
return lines;
|
|
41
41
|
}
|
|
42
42
|
function renderRunSummaryMarkdown(input) {
|
|
43
|
-
const sessionId = input.
|
|
43
|
+
const sessionId = input.session.sessionId;
|
|
44
44
|
const userMessages = input.messages.filter((message) => message.role === "user").slice(-3);
|
|
45
45
|
const assistantMessages = input.messages.filter((message) => message.role === "assistant").slice(-3);
|
|
46
46
|
return [
|
|
47
|
-
"#
|
|
47
|
+
"# Request Memory Summary",
|
|
48
48
|
"",
|
|
49
|
-
`-
|
|
50
|
-
`-
|
|
49
|
+
`- session_id: ${sessionId}`,
|
|
50
|
+
`- request_id: ${input.requestId}`,
|
|
51
51
|
`- agent_id: ${input.agentId}`,
|
|
52
|
-
`- status: ${input.
|
|
52
|
+
`- status: ${input.session.status}`,
|
|
53
53
|
`- trigger: ${input.trigger}`,
|
|
54
54
|
`- captured_at: ${input.capturedAt}`,
|
|
55
55
|
"",
|
|
@@ -58,16 +58,16 @@ function renderRunSummaryMarkdown(input) {
|
|
|
58
58
|
...formatApprovalSection(input.approvals),
|
|
59
59
|
].join("\n");
|
|
60
60
|
}
|
|
61
|
-
function
|
|
62
|
-
const sessionId = input.
|
|
61
|
+
function renderSessionDigestMarkdown(input) {
|
|
62
|
+
const sessionId = input.session.sessionId;
|
|
63
63
|
const latestUser = input.messages.filter((message) => message.role === "user").at(-1);
|
|
64
64
|
const latestAssistant = input.messages.filter((message) => message.role === "assistant").at(-1);
|
|
65
65
|
return [
|
|
66
|
-
"# Durable
|
|
66
|
+
"# Durable Session Digest",
|
|
67
67
|
"",
|
|
68
|
-
`-
|
|
69
|
-
`-
|
|
70
|
-
`- status: ${input.
|
|
68
|
+
`- session_id: ${sessionId}`,
|
|
69
|
+
`- latest_request_id: ${input.requestId}`,
|
|
70
|
+
`- status: ${input.session.status}`,
|
|
71
71
|
`- last_memory_trigger: ${input.trigger}`,
|
|
72
72
|
`- updated_at: ${input.capturedAt}`,
|
|
73
73
|
"",
|
|
@@ -79,23 +79,26 @@ function renderThreadDigestMarkdown(input) {
|
|
|
79
79
|
"",
|
|
80
80
|
].join("\n");
|
|
81
81
|
}
|
|
82
|
-
const RUNTIME_MEMORY_EVENT_TYPES = new Set([
|
|
82
|
+
const RUNTIME_MEMORY_EVENT_TYPES = new Set([
|
|
83
|
+
"request.state.changed",
|
|
84
|
+
"approval.resolved",
|
|
85
|
+
]);
|
|
83
86
|
export function readRuntimeMemorySyncConfig(runtimeMemory) {
|
|
84
87
|
if (runtimeMemory?.enabled !== true) {
|
|
85
88
|
return undefined;
|
|
86
89
|
}
|
|
87
90
|
const ingestion = asRecord(runtimeMemory.ingestion);
|
|
88
91
|
const writeOnApprovalResolution = asBoolean(ingestion?.writeOnApprovalResolution) ?? true;
|
|
89
|
-
const
|
|
90
|
-
if (!writeOnApprovalResolution && !
|
|
92
|
+
const writeOnRequestCompletion = asBoolean(ingestion?.writeOnRequestCompletion) ?? true;
|
|
93
|
+
if (!writeOnApprovalResolution && !writeOnRequestCompletion) {
|
|
91
94
|
return undefined;
|
|
92
95
|
}
|
|
93
96
|
return {
|
|
94
97
|
enabled: true,
|
|
95
98
|
writeOnApprovalResolution,
|
|
96
|
-
|
|
99
|
+
writeOnRequestCompletion,
|
|
97
100
|
backgroundConsolidation: asBoolean(ingestion?.backgroundConsolidation) ?? true,
|
|
98
|
-
|
|
101
|
+
maxMessagesPerRequest: asPositiveInteger(ingestion?.maxMessagesPerRequest) ?? 40,
|
|
99
102
|
};
|
|
100
103
|
}
|
|
101
104
|
export class RuntimeMemorySync {
|
|
@@ -119,15 +122,15 @@ export class RuntimeMemorySync {
|
|
|
119
122
|
if (event.eventType === "approval.resolved") {
|
|
120
123
|
return this.config.writeOnApprovalResolution;
|
|
121
124
|
}
|
|
122
|
-
return this.config.
|
|
125
|
+
return this.config.writeOnRequestCompletion && event.payload.state === "completed";
|
|
123
126
|
}
|
|
124
127
|
async handleEvent(event) {
|
|
125
128
|
if (!this.shouldHandle(event)) {
|
|
126
129
|
return;
|
|
127
130
|
}
|
|
128
|
-
const trigger = event.eventType === "approval.resolved" ? "approval.resolved" : "
|
|
131
|
+
const trigger = event.eventType === "approval.resolved" ? "approval.resolved" : "request.completed";
|
|
129
132
|
const task = this.syncChain
|
|
130
|
-
.then(() => this.syncRun(event.sessionId
|
|
133
|
+
.then(() => this.syncRun(event.sessionId, event.requestId, trigger, event.timestamp))
|
|
131
134
|
.catch(() => {
|
|
132
135
|
// Fail open: runtime memory sync must not break the hot path.
|
|
133
136
|
});
|
|
@@ -140,24 +143,24 @@ export class RuntimeMemorySync {
|
|
|
140
143
|
});
|
|
141
144
|
this.pending.add(task);
|
|
142
145
|
}
|
|
143
|
-
async syncRun(
|
|
144
|
-
const [
|
|
145
|
-
this.persistence.getSession(
|
|
146
|
-
this.persistence.
|
|
147
|
-
this.persistence.
|
|
148
|
-
this.persistence.
|
|
146
|
+
async syncRun(sessionId, requestId, trigger, capturedAt) {
|
|
147
|
+
const [session, run, allMessages, approvals] = await Promise.all([
|
|
148
|
+
this.persistence.getSession(sessionId),
|
|
149
|
+
this.persistence.getRequest(requestId),
|
|
150
|
+
this.persistence.listSessionMessages(sessionId, this.config.maxMessagesPerRequest),
|
|
151
|
+
this.persistence.getRequestApprovals(sessionId, requestId),
|
|
149
152
|
]);
|
|
150
|
-
if (!
|
|
153
|
+
if (!session || !run) {
|
|
151
154
|
return;
|
|
152
155
|
}
|
|
153
|
-
const messages = allMessages.filter((message) =>
|
|
156
|
+
const messages = allMessages.filter((message) => message.requestId === requestId);
|
|
154
157
|
if (messages.length === 0) {
|
|
155
158
|
return;
|
|
156
159
|
}
|
|
157
|
-
const agentId = run.agentId ??
|
|
160
|
+
const agentId = run.agentId ?? session.agentId;
|
|
158
161
|
const summaryMarkdown = renderRunSummaryMarkdown({
|
|
159
|
-
|
|
160
|
-
|
|
162
|
+
session,
|
|
163
|
+
requestId,
|
|
161
164
|
agentId,
|
|
162
165
|
trigger,
|
|
163
166
|
capturedAt,
|
|
@@ -165,16 +168,16 @@ export class RuntimeMemorySync {
|
|
|
165
168
|
approvals,
|
|
166
169
|
});
|
|
167
170
|
await Promise.all([
|
|
168
|
-
this.store.put(this.
|
|
169
|
-
this.store.put(this.
|
|
171
|
+
this.store.put(this.resolveRequestNamespace(sessionId), `${requestId}.summary.md`, { content: `${summaryMarkdown}\n` }),
|
|
172
|
+
this.store.put(this.resolveRequestNamespace(sessionId), `${requestId}.record.json`, {
|
|
170
173
|
kind: "summary",
|
|
171
|
-
scope: "
|
|
172
|
-
|
|
173
|
-
|
|
174
|
+
scope: "session",
|
|
175
|
+
sessionId,
|
|
176
|
+
requestId,
|
|
174
177
|
agentId,
|
|
175
178
|
trigger,
|
|
176
179
|
capturedAt,
|
|
177
|
-
status:
|
|
180
|
+
status: session.status,
|
|
178
181
|
messageCount: messages.length,
|
|
179
182
|
approvalCount: approvals.length,
|
|
180
183
|
}),
|
|
@@ -182,20 +185,20 @@ export class RuntimeMemorySync {
|
|
|
182
185
|
if (!this.config.backgroundConsolidation) {
|
|
183
186
|
return;
|
|
184
187
|
}
|
|
185
|
-
const digestMarkdown =
|
|
186
|
-
|
|
187
|
-
|
|
188
|
+
const digestMarkdown = renderSessionDigestMarkdown({
|
|
189
|
+
session,
|
|
190
|
+
requestId,
|
|
188
191
|
trigger,
|
|
189
192
|
capturedAt,
|
|
190
193
|
messages,
|
|
191
194
|
});
|
|
192
|
-
await this.store.put(this.
|
|
195
|
+
await this.store.put(this.resolveSessionNamespace(sessionId), "durable-summary.md", { content: `${digestMarkdown}\n` });
|
|
193
196
|
}
|
|
194
|
-
|
|
195
|
-
return this.options.
|
|
197
|
+
resolveSessionNamespace(sessionId) {
|
|
198
|
+
return this.options.resolveSessionNamespace ? this.options.resolveSessionNamespace(sessionId) : ["memories", "sessions", sessionId];
|
|
196
199
|
}
|
|
197
|
-
|
|
198
|
-
return this.options.
|
|
200
|
+
resolveRequestNamespace(sessionId) {
|
|
201
|
+
return this.options.resolveRequestNamespace ? this.options.resolveRequestNamespace(sessionId) : ["memories", "requests", sessionId];
|
|
199
202
|
}
|
|
200
203
|
async close() {
|
|
201
204
|
await Promise.allSettled(Array.from(this.pending));
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import type { HarnessEvent, HarnessEventProjection } from "../../../contracts/types.js";
|
|
2
2
|
import type { RuntimePersistence } from "../../../persistence/types.js";
|
|
3
|
-
type
|
|
4
|
-
|
|
3
|
+
type SessionMemorySyncOptions = {
|
|
4
|
+
resolveSessionNamespace?: (sessionId: string) => string[];
|
|
5
5
|
};
|
|
6
|
-
export declare class
|
|
6
|
+
export declare class SessionMemorySync implements HarnessEventProjection {
|
|
7
7
|
private readonly persistence;
|
|
8
8
|
private readonly store?;
|
|
9
9
|
private readonly options;
|
|
10
10
|
private readonly pending;
|
|
11
11
|
private syncChain;
|
|
12
|
-
readonly name = "
|
|
12
|
+
readonly name = "session-memory-sync";
|
|
13
13
|
constructor(persistence: RuntimePersistence, store?: {
|
|
14
14
|
put: (namespace: string[], key: string, value: Record<string, any>) => Promise<void>;
|
|
15
|
-
} | undefined, options?:
|
|
15
|
+
} | undefined, options?: SessionMemorySyncOptions);
|
|
16
16
|
shouldHandle(event: HarnessEvent): boolean;
|
|
17
17
|
handleEvent(event: HarnessEvent): Promise<void>;
|
|
18
|
-
private
|
|
18
|
+
private syncSession;
|
|
19
19
|
close(): Promise<void>;
|
|
20
20
|
}
|
|
21
|
-
export {
|
|
21
|
+
export { SessionMemorySync as MemoryWorker };
|
|
@@ -6,19 +6,19 @@ function excerpt(message) {
|
|
|
6
6
|
const normalized = extractMessageText(message.content).replace(/\s+/g, " ").trim();
|
|
7
7
|
return normalized.length > 240 ? `${normalized.slice(0, 237)}...` : normalized;
|
|
8
8
|
}
|
|
9
|
-
function
|
|
10
|
-
const sessionId =
|
|
11
|
-
const latestRequestId =
|
|
9
|
+
function renderSessionSnapshotMarkdown(session, messages, approvals) {
|
|
10
|
+
const sessionId = session.sessionId;
|
|
11
|
+
const latestRequestId = session.latestRequestId;
|
|
12
12
|
const userMessages = messages.filter((message) => message.role === "user");
|
|
13
13
|
const assistantMessages = messages.filter((message) => message.role === "assistant");
|
|
14
14
|
return [
|
|
15
|
-
"#
|
|
15
|
+
"# Session Snapshot",
|
|
16
16
|
"",
|
|
17
|
-
`-
|
|
18
|
-
`-
|
|
19
|
-
`- agent_id: ${
|
|
20
|
-
`- status: ${
|
|
21
|
-
`- updated_at: ${
|
|
17
|
+
`- session_id: ${sessionId}`,
|
|
18
|
+
`- latest_request_id: ${latestRequestId}`,
|
|
19
|
+
`- agent_id: ${session.agentId}`,
|
|
20
|
+
`- status: ${session.status}`,
|
|
21
|
+
`- updated_at: ${session.updatedAt}`,
|
|
22
22
|
"",
|
|
23
23
|
"## Recent User Message",
|
|
24
24
|
excerpt(userMessages.at(-1)),
|
|
@@ -39,44 +39,44 @@ function formatOpenApprovalsSection(approvals) {
|
|
|
39
39
|
lines.push(`### ${approval.approvalId}`);
|
|
40
40
|
lines.push(`- pending_action_id: ${approval.pendingActionId}`);
|
|
41
41
|
lines.push(`- tool: ${approval.toolName}`);
|
|
42
|
-
lines.push(`-
|
|
42
|
+
lines.push(`- request_id: ${approval.requestId}`);
|
|
43
43
|
lines.push(`- requested_at: ${approval.requestedAt}`);
|
|
44
44
|
lines.push(`- allowed: ${approval.allowedDecisions.join(", ")}`);
|
|
45
45
|
lines.push("");
|
|
46
46
|
}
|
|
47
47
|
return lines;
|
|
48
48
|
}
|
|
49
|
-
function
|
|
50
|
-
return resolver ? resolver(
|
|
49
|
+
function resolveSessionNamespace(sessionId, resolver) {
|
|
50
|
+
return resolver ? resolver(sessionId) : ["memories", "sessions", sessionId];
|
|
51
51
|
}
|
|
52
|
-
const
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
52
|
+
const SESSION_MEMORY_EVENT_TYPES = new Set([
|
|
53
|
+
"request.state.changed",
|
|
54
|
+
"request.queued",
|
|
55
|
+
"request.dequeued",
|
|
56
56
|
"approval.resolved",
|
|
57
57
|
"approval.requested",
|
|
58
58
|
]);
|
|
59
|
-
export class
|
|
59
|
+
export class SessionMemorySync {
|
|
60
60
|
persistence;
|
|
61
61
|
store;
|
|
62
62
|
options;
|
|
63
63
|
pending = new Set();
|
|
64
64
|
syncChain = Promise.resolve();
|
|
65
|
-
name = "
|
|
65
|
+
name = "session-memory-sync";
|
|
66
66
|
constructor(persistence, store, options = {}) {
|
|
67
67
|
this.persistence = persistence;
|
|
68
68
|
this.store = store;
|
|
69
69
|
this.options = options;
|
|
70
70
|
}
|
|
71
71
|
shouldHandle(event) {
|
|
72
|
-
return
|
|
72
|
+
return SESSION_MEMORY_EVENT_TYPES.has(event.eventType);
|
|
73
73
|
}
|
|
74
74
|
async handleEvent(event) {
|
|
75
75
|
if (!this.shouldHandle(event)) {
|
|
76
76
|
return;
|
|
77
77
|
}
|
|
78
78
|
const task = this.syncChain
|
|
79
|
-
.then(() => this.
|
|
79
|
+
.then(() => this.syncSession(event.sessionId))
|
|
80
80
|
.catch(() => {
|
|
81
81
|
// Fail open: background memory digestion must not break the hot path.
|
|
82
82
|
});
|
|
@@ -89,25 +89,25 @@ export class ThreadMemorySync {
|
|
|
89
89
|
});
|
|
90
90
|
this.pending.add(task);
|
|
91
91
|
}
|
|
92
|
-
async
|
|
93
|
-
const
|
|
94
|
-
if (!
|
|
92
|
+
async syncSession(sessionId) {
|
|
93
|
+
const session = await this.persistence.getSession(sessionId);
|
|
94
|
+
if (!session) {
|
|
95
95
|
return;
|
|
96
96
|
}
|
|
97
97
|
const [messages, approvals] = await Promise.all([
|
|
98
|
-
this.persistence.
|
|
98
|
+
this.persistence.listSessionMessages(sessionId, 24),
|
|
99
99
|
this.persistence.listApprovals(),
|
|
100
100
|
]);
|
|
101
|
-
const pendingApprovals = approvals.filter((approval) =>
|
|
101
|
+
const pendingApprovals = approvals.filter((approval) => approval.sessionId === sessionId && approval.status === "pending");
|
|
102
102
|
if (!this.store) {
|
|
103
103
|
return;
|
|
104
104
|
}
|
|
105
|
-
await this.store.put(
|
|
106
|
-
content: `${
|
|
105
|
+
await this.store.put(resolveSessionNamespace(sessionId, this.options.resolveSessionNamespace), "snapshot.md", {
|
|
106
|
+
content: `${renderSessionSnapshotMarkdown(session, messages, pendingApprovals)}\n`,
|
|
107
107
|
});
|
|
108
108
|
}
|
|
109
109
|
async close() {
|
|
110
110
|
await Promise.allSettled(Array.from(this.pending));
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
|
-
export {
|
|
113
|
+
export { SessionMemorySync as MemoryWorker };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ApprovalRecord, ArtifactListing, CancelOptions, HarnessEvent, HarnessStreamItem, RuntimeHealthSnapshot, RuntimeOperatorOverview, ListMemoriesInput, ListMemoriesResult, MessageContent, RemoveMemoryInput,
|
|
1
|
+
import type { ApprovalRecord, ArtifactListing, CancelOptions, HarnessEvent, HarnessStreamItem, RuntimeHealthSnapshot, RuntimeOperatorOverview, ListMemoriesInput, ListMemoriesResult, MessageContent, RemoveMemoryInput, RequestOptions, RequestRecord, RequestResult, RequestSummary, RequestStartOptions, RestartConversationOptions, RuntimeAdapterOptions, RuntimeArtifactWriteInput, RuntimeEvaluationExport, RuntimeEvaluationExportInput, RuntimeEvaluationReplayInput, RuntimeEvaluationReplayResult, RuntimeRequestPackage, RuntimeRequestPackageInput, RuntimeSessionPackage, RuntimeSessionPackageInput, ResumeOptions, MemoryRecord, MemorizeInput, MemorizeResult, RecallInput, RecallResult, UpdateMemoryInput, SessionSummary, SessionRecord, SessionListSummary, WorkspaceBundle } from "../contracts/types.js";
|
|
2
2
|
import { type RuntimeMcpServerOptions, type ToolMcpServerOptions } from "../mcp.js";
|
|
3
3
|
import { type InventoryAgentRecord, type InventorySkillRecord } from "./harness/system/inventory.js";
|
|
4
4
|
import type { RequirementAssessmentOptions } from "./harness/system/skill-requirements.js";
|
|
@@ -16,15 +16,15 @@ export declare class AgentHarnessRuntime {
|
|
|
16
16
|
private readonly vectorStores;
|
|
17
17
|
private readonly runtimeEntryBindings;
|
|
18
18
|
private readonly defaultRuntimeEntryBinding?;
|
|
19
|
-
private readonly
|
|
19
|
+
private readonly defaultRuntimeRootValue;
|
|
20
20
|
private readonly defaultStore;
|
|
21
21
|
private readonly runtimeMemoryStore;
|
|
22
22
|
private readonly runtimeMemoryPolicy;
|
|
23
23
|
private readonly runtimeMemoryMaintenanceConfig;
|
|
24
24
|
private readonly routingRules;
|
|
25
25
|
private readonly routingDefaultAgentId?;
|
|
26
|
-
private readonly
|
|
27
|
-
private readonly
|
|
26
|
+
private readonly sessionMemorySync;
|
|
27
|
+
private readonly unregisterSessionMemorySync;
|
|
28
28
|
private readonly runtimeMemorySync;
|
|
29
29
|
private readonly unregisterRuntimeMemorySync;
|
|
30
30
|
private readonly mem0IngestionSync;
|
|
@@ -41,16 +41,16 @@ export declare class AgentHarnessRuntime {
|
|
|
41
41
|
private readonly concurrencyConfig;
|
|
42
42
|
private readonly backgroundTasks;
|
|
43
43
|
private readonly workerId;
|
|
44
|
-
private
|
|
44
|
+
private activeRequestSlots;
|
|
45
45
|
private pendingRunInsertionOrder;
|
|
46
|
-
private readonly
|
|
46
|
+
private readonly pendingRequestSlots;
|
|
47
47
|
private runtimeEventSequence;
|
|
48
48
|
private initialized;
|
|
49
49
|
private closed;
|
|
50
50
|
private readonly backgroundEventRuntime;
|
|
51
51
|
private readonly runtimeEventOperations;
|
|
52
52
|
private resolveRuntimeMemoryVectorStore;
|
|
53
|
-
private
|
|
53
|
+
private defaultRuntimeRoot;
|
|
54
54
|
private getDefaultRuntimeEntryAgentId;
|
|
55
55
|
private resolveSelectedAgentId;
|
|
56
56
|
private createPrepareRunStartRuntime;
|
|
@@ -70,43 +70,33 @@ export declare class AgentHarnessRuntime {
|
|
|
70
70
|
listSessionSummaries(filter?: {
|
|
71
71
|
agentId?: string;
|
|
72
72
|
}): Promise<SessionListSummary[]>;
|
|
73
|
-
listThreads(filter?: {
|
|
74
|
-
agentId?: string;
|
|
75
|
-
}): Promise<ThreadSummary[]>;
|
|
76
73
|
listRequests(filter?: {
|
|
77
74
|
agentId?: string;
|
|
78
75
|
sessionId?: string;
|
|
79
76
|
state?: RequestSummary["state"];
|
|
80
77
|
}): Promise<RequestSummary[]>;
|
|
81
|
-
listRuns(filter?: {
|
|
82
|
-
agentId?: string;
|
|
83
|
-
threadId?: string;
|
|
84
|
-
state?: RunSummary["state"];
|
|
85
|
-
}): Promise<RunSummary[]>;
|
|
86
78
|
memorize(input: MemorizeInput): Promise<MemorizeResult>;
|
|
87
79
|
recall(input: RecallInput): Promise<RecallResult>;
|
|
88
80
|
listMemories(input?: ListMemoriesInput): Promise<ListMemoriesResult>;
|
|
89
81
|
updateMemory(input: UpdateMemoryInput): Promise<MemoryRecord>;
|
|
90
82
|
removeMemory(input: RemoveMemoryInput): Promise<MemoryRecord>;
|
|
91
83
|
getRequest(requestId: string): Promise<RequestRecord | null>;
|
|
92
|
-
getRun(runId: string): Promise<RunRecord | null>;
|
|
93
84
|
private getSessionSummary;
|
|
94
|
-
private
|
|
85
|
+
private getSessionSummaryRecord;
|
|
86
|
+
getSession(sessionId: string): Promise<SessionRecord | null>;
|
|
95
87
|
getSessionRecord(sessionId: string): Promise<SessionRecord | null>;
|
|
96
|
-
getThread(threadId: string): Promise<ThreadRecord | null>;
|
|
97
88
|
listApprovals(filter?: {
|
|
98
89
|
status?: ApprovalRecord["status"];
|
|
99
90
|
sessionId?: string;
|
|
100
91
|
requestId?: string;
|
|
101
92
|
}): Promise<ApprovalRecord[]>;
|
|
102
93
|
getApproval(approvalId: string): Promise<ApprovalRecord | null>;
|
|
103
|
-
|
|
104
|
-
readArtifact(threadId: string, runId: string, artifactPath: string): Promise<unknown>;
|
|
94
|
+
listRequestArtifacts(sessionId: string, requestId: string): Promise<ArtifactListing>;
|
|
105
95
|
recordArtifact(input: RuntimeArtifactWriteInput): Promise<import("../contracts/types.js").ArtifactRecord>;
|
|
96
|
+
readRequestArtifact(sessionId: string, requestId: string, artifactPath: string): Promise<unknown>;
|
|
106
97
|
listRequestEvents(sessionId: string, requestId: string): Promise<HarnessEvent[]>;
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
exportRunPackage(input: RuntimeRunPackageInput): Promise<RuntimeRunPackage>;
|
|
98
|
+
exportRequestPackage(input: RuntimeRequestPackageInput): Promise<RuntimeRequestPackage>;
|
|
99
|
+
exportRunPackage(input: RuntimeRequestPackageInput): Promise<RuntimeRequestPackage>;
|
|
110
100
|
exportSessionPackage(input: RuntimeSessionPackageInput): Promise<RuntimeSessionPackage>;
|
|
111
101
|
exportEvaluationBundle(input: RuntimeEvaluationExportInput): Promise<RuntimeEvaluationExport>;
|
|
112
102
|
replayEvaluationBundle(input: RuntimeEvaluationReplayInput): Promise<RuntimeEvaluationReplayResult>;
|
|
@@ -116,50 +106,48 @@ export declare class AgentHarnessRuntime {
|
|
|
116
106
|
workspaceRoot: string;
|
|
117
107
|
agents: InventoryAgentRecord[];
|
|
118
108
|
};
|
|
119
|
-
private
|
|
109
|
+
private deleteSessionCheckpoints;
|
|
120
110
|
deleteSession(sessionId: string): Promise<boolean>;
|
|
121
|
-
deleteThread(threadId: string): Promise<boolean>;
|
|
122
|
-
deleteThreadLegacy(threadId: string): Promise<boolean>;
|
|
123
111
|
createToolMcpServer(options: ToolMcpServerOptions): Promise<import("@modelcontextprotocol/sdk/server/mcp").McpServer>;
|
|
124
112
|
serveToolsOverStdio(options: ToolMcpServerOptions): Promise<import("@modelcontextprotocol/sdk/server/mcp").McpServer>;
|
|
125
113
|
createRuntimeMcpServer(options?: RuntimeMcpServerOptions): Promise<import("@modelcontextprotocol/sdk/server/mcp").McpServer>;
|
|
126
114
|
serveRuntimeMcpOverStdio(options?: RuntimeMcpServerOptions): Promise<import("@modelcontextprotocol/sdk/server/mcp").McpServer>;
|
|
127
115
|
routeAgent(input: MessageContent, options?: {
|
|
128
|
-
|
|
116
|
+
sessionId?: string;
|
|
129
117
|
}): Promise<string>;
|
|
130
118
|
private emit;
|
|
131
119
|
private trackBackgroundTask;
|
|
132
120
|
private scheduleBackgroundStartupTask;
|
|
133
121
|
private resolveToolMcpServerTools;
|
|
134
122
|
private loadPriorHistory;
|
|
135
|
-
private
|
|
136
|
-
private
|
|
137
|
-
private
|
|
123
|
+
private loadRequestInput;
|
|
124
|
+
private getRequestCancellation;
|
|
125
|
+
private finalizeCancelledRequest;
|
|
138
126
|
private invokeWithHistory;
|
|
139
127
|
private resolveMemoryNamespace;
|
|
140
128
|
private getWorkspaceId;
|
|
141
129
|
private buildRuntimeMemoryContext;
|
|
142
130
|
private persistRuntimeMemoryCandidates;
|
|
143
|
-
private
|
|
144
|
-
private
|
|
145
|
-
private
|
|
146
|
-
private
|
|
147
|
-
private
|
|
131
|
+
private resolvePersistedRequestPriority;
|
|
132
|
+
private enqueuePendingRequestSlot;
|
|
133
|
+
private executeQueuedRequest;
|
|
134
|
+
private finalizeContinuedRequest;
|
|
135
|
+
private setRequestStateAndEmit;
|
|
148
136
|
private requestApprovalAndEmit;
|
|
149
137
|
private isDecisionRun;
|
|
150
138
|
private notifyListener;
|
|
151
|
-
private
|
|
152
|
-
private
|
|
153
|
-
run(options:
|
|
154
|
-
streamEvents(options:
|
|
155
|
-
resume(options: ResumeOptions): Promise<
|
|
156
|
-
restartConversation(options: RestartConversationOptions): Promise<
|
|
139
|
+
private acquireRequestSlot;
|
|
140
|
+
private dropPendingRequestSlot;
|
|
141
|
+
run(options: RequestOptions): Promise<RequestResult>;
|
|
142
|
+
streamEvents(options: RequestStartOptions): AsyncGenerator<HarnessStreamItem>;
|
|
143
|
+
resume(options: ResumeOptions): Promise<RequestResult>;
|
|
144
|
+
restartConversation(options: RestartConversationOptions): Promise<RequestResult & {
|
|
157
145
|
restart: Record<string, string>;
|
|
158
146
|
}>;
|
|
159
147
|
close(): Promise<void>;
|
|
160
148
|
stop(): Promise<void>;
|
|
161
|
-
|
|
162
|
-
private
|
|
163
|
-
private
|
|
164
|
-
private
|
|
149
|
+
cancelRequest(options: CancelOptions): Promise<RequestResult>;
|
|
150
|
+
private recoverStartupRequests;
|
|
151
|
+
private reclaimExpiredClaimedRequests;
|
|
152
|
+
private isStaleRunningRequest;
|
|
165
153
|
}
|