@botbotgo/agent-harness 0.0.475 → 0.0.476
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1234
- package/README.zh.md +3 -1191
- package/dist/acp.js +1 -1
- package/dist/api.js +1 -404
- package/dist/benchmark/checkpoint-resume-cost-benchmark.js +1 -55
- package/dist/benchmark/deepagent-local-model-benchmark.js +2 -35
- package/dist/benchmark/upstream-runtime-ab-benchmark.js +1 -179
- package/dist/cli/chat-interactive.js +25 -244
- package/dist/cli/chat-rendering.js +6 -100
- package/dist/cli/chat-stream.js +23 -512
- package/dist/cli/chat-ui.js +21 -199
- package/dist/cli/chat-workspace.js +2 -210
- package/dist/cli/main.js +21 -428
- package/dist/cli/managed-service-commands.js +9 -63
- package/dist/cli/managed-service.js +2 -137
- package/dist/cli/options-init-chat.js +1 -108
- package/dist/cli/options-runtime.js +1 -158
- package/dist/cli/options-serve.js +1 -282
- package/dist/cli/options.js +2 -19
- package/dist/cli/process-guards.js +1 -139
- package/dist/cli/request-tree.js +7 -296
- package/dist/cli/runtime-commands.js +12 -258
- package/dist/cli/runtime-output.js +16 -155
- package/dist/cli/server-commands.js +16 -270
- package/dist/cli/workspace.js +1 -67
- package/dist/cli.js +1 -7
- package/dist/client/acp.js +1 -1
- package/dist/client/in-process.js +1 -67
- package/dist/client/index.js +1 -2
- package/dist/client/types.js +0 -1
- package/dist/client.js +1 -1
- package/dist/contracts/core.js +1 -1
- package/dist/contracts/runtime-evaluation.js +0 -1
- package/dist/contracts/runtime-memory.js +0 -1
- package/dist/contracts/runtime-observability.js +0 -1
- package/dist/contracts/runtime-requests.js +0 -1
- package/dist/contracts/runtime-scheduling.js +0 -1
- package/dist/contracts/runtime.js +1 -27
- package/dist/contracts/types.js +1 -3
- package/dist/contracts/workspace.js +0 -1
- package/dist/flow/build-flow-graph.js +1 -50
- package/dist/flow/export-mermaid.js +2 -464
- package/dist/flow/export-sequence-mermaid.js +2 -325
- package/dist/flow/flow-graph-normalization.js +1 -214
- package/dist/flow/flow-graph-runtime.js +1 -107
- package/dist/flow/flow-graph-upstream.js +1 -494
- package/dist/flow/index.js +1 -3
- package/dist/flow/types.js +0 -1
- package/dist/index.js +1 -5
- package/dist/init-project.js +1 -1
- package/dist/knowledge/config.js +1 -32
- package/dist/knowledge/contracts.js +0 -1
- package/dist/knowledge/index.js +1 -2
- package/dist/knowledge/module.js +12 -909
- package/dist/knowledge/procedural/config.js +1 -125
- package/dist/knowledge/procedural/index.js +1 -2
- package/dist/knowledge/procedural/manager.js +9 -345
- package/dist/mcp.js +1 -2
- package/dist/package-version.d.ts +1 -1
- package/dist/package-version.js +1 -2
- package/dist/persistence/file-store.js +3 -758
- package/dist/persistence/sqlite-request-context-store.js +5 -54
- package/dist/persistence/sqlite-request-queue-store.js +10 -108
- package/dist/persistence/sqlite-runtime.js +1 -86
- package/dist/persistence/sqlite-store.js +62 -810
- package/dist/persistence/types.js +0 -1
- package/dist/projections/presentation.js +37 -206
- package/dist/projections/request-events.js +2 -502
- package/dist/projections/upstream-events.js +1 -201
- package/dist/protocol/a2a/http-discovery.js +1 -178
- package/dist/protocol/a2a/http-rpc.js +6 -622
- package/dist/protocol/a2a/http.js +1 -138
- package/dist/protocol/a2a/task-state.js +3 -317
- package/dist/protocol/acp/client.js +8 -294
- package/dist/protocol/acp/harness-client.js +1 -218
- package/dist/protocol/acp/http.js +5 -130
- package/dist/protocol/acp/server.js +1 -310
- package/dist/protocol/acp/stdio.js +2 -69
- package/dist/protocol/ag-ui/http.js +3 -378
- package/dist/protocol/mcp/server.js +1 -428
- package/dist/resource/backend/workspace-scoped-backend.js +1 -319
- package/dist/resource/isolation.js +1 -237
- package/dist/resource/mcp/tool-support.js +3 -296
- package/dist/resource/mcp-tool-support.js +1 -2
- package/dist/resource/providers/resource-provider.js +1 -215
- package/dist/resource/resource-impl.js +1 -3
- package/dist/resource/resource-types.js +0 -1
- package/dist/resource/resource.js +1 -1
- package/dist/resource/sources.js +1 -247
- package/dist/resource/tools/function-tool-resolver.js +2 -272
- package/dist/runtime/adapter/compat/deepagent-compat.js +1 -29
- package/dist/runtime/adapter/compat/openai-compatible.js +1 -55
- package/dist/runtime/adapter/direct-builtin-utility.js +2 -90
- package/dist/runtime/adapter/flow/execution-context.js +1 -71
- package/dist/runtime/adapter/flow/invocation-flow.js +8 -425
- package/dist/runtime/adapter/flow/invoke-runtime.js +1 -20
- package/dist/runtime/adapter/flow/stream-runtime.js +11 -1395
- package/dist/runtime/adapter/invocation-result.js +2 -473
- package/dist/runtime/adapter/local-tool-invocation.js +6 -638
- package/dist/runtime/adapter/middleware/context-hygiene.js +1 -83
- package/dist/runtime/adapter/middleware-assembly.js +5 -477
- package/dist/runtime/adapter/model/invocation-request.js +3 -183
- package/dist/runtime/adapter/model/message-assembly.js +1 -28
- package/dist/runtime/adapter/model/model-providers.js +23 -1115
- package/dist/runtime/adapter/model/prompted-json-tool-call-capture.js +1 -40
- package/dist/runtime/adapter/model/prompted-json-tool-policy.js +1 -22
- package/dist/runtime/adapter/resilience.js +1 -104
- package/dist/runtime/adapter/runtime-adapter-support.js +3 -141
- package/dist/runtime/adapter/runtime-shell.js +5 -166
- package/dist/runtime/adapter/stream-event-projection.js +2 -622
- package/dist/runtime/adapter/stream-text-consumption.js +1 -18
- package/dist/runtime/adapter/terminal-status.js +2 -67
- package/dist/runtime/adapter/tool/builtin-middleware-tools.js +6 -627
- package/dist/runtime/adapter/tool/declared-middleware.js +1 -154
- package/dist/runtime/adapter/tool/interrupt-policy.js +1 -34
- package/dist/runtime/adapter/tool/provider-tool.js +1 -25
- package/dist/runtime/adapter/tool/resolved-tool.js +1 -225
- package/dist/runtime/adapter/tool/tool-arguments.js +3 -486
- package/dist/runtime/adapter/tool/tool-hitl.js +1 -346
- package/dist/runtime/adapter/tool/tool-name-mapping.js +1 -128
- package/dist/runtime/adapter/tool/tool-output-artifacts.js +2 -88
- package/dist/runtime/adapter/tool/tool-replay.js +1 -37
- package/dist/runtime/adapter/tool-resolution.js +1 -86
- package/dist/runtime/adapter/upstream-configurable-keys.js +1 -2
- package/dist/runtime/agent-runtime-adapter.js +60 -2338
- package/dist/runtime/agent-runtime-assembly.js +7 -249
- package/dist/runtime/env/runtime-env.js +1 -62
- package/dist/runtime/harness/background-runtime.js +1 -8
- package/dist/runtime/harness/bindings.js +1 -58
- package/dist/runtime/harness/events/event-bus.js +1 -16
- package/dist/runtime/harness/events/event-sink.js +1 -61
- package/dist/runtime/harness/events/events.js +1 -80
- package/dist/runtime/harness/events/listener-runtime.js +1 -13
- package/dist/runtime/harness/events/runtime-event-operations.js +1 -9
- package/dist/runtime/harness/events/streaming.js +1 -100
- package/dist/runtime/harness/events/timeline.js +1 -52
- package/dist/runtime/harness/public-shapes.js +1 -186
- package/dist/runtime/harness/run/artifact-paths.js +1 -15
- package/dist/runtime/harness/run/governance.js +1 -295
- package/dist/runtime/harness/run/helpers.js +1 -71
- package/dist/runtime/harness/run/inspection.js +1 -409
- package/dist/runtime/harness/run/operator-overview.js +1 -80
- package/dist/runtime/harness/run/queue-diagnostics.js +1 -15
- package/dist/runtime/harness/run/recovery.js +1 -162
- package/dist/runtime/harness/run/resources.js +1 -60
- package/dist/runtime/harness/run/resume.js +1 -56
- package/dist/runtime/harness/run/routing.js +1 -48
- package/dist/runtime/harness/run/run-lifecycle.js +1 -66
- package/dist/runtime/harness/run/run-operations.js +1 -217
- package/dist/runtime/harness/run/run-queue.js +1 -43
- package/dist/runtime/harness/run/run-slot-acquisition.js +1 -157
- package/dist/runtime/harness/run/session-records.js +1 -97
- package/dist/runtime/harness/run/start-run.js +1 -120
- package/dist/runtime/harness/run/startup-runtime.js +1 -69
- package/dist/runtime/harness/run/stream-run.js +8 -1418
- package/dist/runtime/harness/run/surface-semantics.js +1 -79
- package/dist/runtime/harness/runtime-defaults.js +1 -39
- package/dist/runtime/harness/system/boundary-analysis.js +1 -234
- package/dist/runtime/harness/system/health-monitor.js +1 -258
- package/dist/runtime/harness/system/inventory.js +1 -129
- package/dist/runtime/harness/system/mem0-ingestion-sync.js +5 -345
- package/dist/runtime/harness/system/policy-engine.js +1 -175
- package/dist/runtime/harness/system/runtime-memory-candidates.js +4 -110
- package/dist/runtime/harness/system/runtime-memory-consolidation.js +1 -51
- package/dist/runtime/harness/system/runtime-memory-manager.js +10 -693
- package/dist/runtime/harness/system/runtime-memory-policy.js +1 -155
- package/dist/runtime/harness/system/runtime-memory-records.js +11 -577
- package/dist/runtime/harness/system/runtime-memory-sync.js +5 -206
- package/dist/runtime/harness/system/session-memory-sync.js +3 -113
- package/dist/runtime/harness/system/skill-requirements.js +1 -112
- package/dist/runtime/harness/system/store.js +9 -365
- package/dist/runtime/harness/tool-gateway/index.js +1 -2
- package/dist/runtime/harness/tool-gateway/policy.js +1 -45
- package/dist/runtime/harness/tool-gateway/validation.js +1 -176
- package/dist/runtime/harness/tool-schema.js +1 -3
- package/dist/runtime/harness.js +3 -1490
- package/dist/runtime/index.js +1 -3
- package/dist/runtime/layout/runtime-layout.js +1 -31
- package/dist/runtime/maintenance/checkpoint-maintenance.js +2 -178
- package/dist/runtime/maintenance/file-checkpoint-saver.js +1 -106
- package/dist/runtime/maintenance/runtime-record-maintenance.js +2 -169
- package/dist/runtime/maintenance/sqlite-checkpoint-saver.js +4 -289
- package/dist/runtime/parsing/output-content.js +10 -550
- package/dist/runtime/parsing/output-parsing.js +1 -4
- package/dist/runtime/parsing/output-recovery.js +3 -213
- package/dist/runtime/parsing/output-tool-args.js +7 -663
- package/dist/runtime/parsing/stream-event-parsing.js +3 -362
- package/dist/runtime/prompts/runtime-prompts.js +4 -73
- package/dist/runtime/scheduling/system-schedule-manager.js +11 -532
- package/dist/runtime/skills/skill-metadata.js +1 -197
- package/dist/runtime/startup-tracing.js +2 -37
- package/dist/runtime/support/compiled-binding.js +1 -290
- package/dist/runtime/support/embedding-models.js +1 -118
- package/dist/runtime/support/harness-support.js +5 -137
- package/dist/runtime/support/llamaindex.js +1 -108
- package/dist/runtime/support/runtime-adapter-options.js +1 -29
- package/dist/runtime/support/runtime-factories.js +1 -51
- package/dist/runtime/support/vector-stores.js +9 -270
- package/dist/scaffold/init-project.js +54 -233
- package/dist/tooling/extensions.js +1 -311
- package/dist/tooling/module-loader.js +1 -55
- package/dist/tools.js +1 -176
- package/dist/utils/agent-display.js +1 -18
- package/dist/utils/bundled-text.js +4 -39
- package/dist/utils/compiled-binding.js +1 -33
- package/dist/utils/fs.js +2 -45
- package/dist/utils/id.js +1 -9
- package/dist/utils/message-content.js +1 -30
- package/dist/utils/object.js +1 -6
- package/dist/workspace/agent-binding-compiler.js +3 -613
- package/dist/workspace/compile.js +1 -472
- package/dist/workspace/framework-contract-validation.js +2 -322
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/object-loader-paths.js +1 -71
- package/dist/workspace/object-loader-readers.js +1 -187
- package/dist/workspace/object-loader.js +1 -754
- package/dist/workspace/resource-compilers.js +1 -374
- package/dist/workspace/support/agent-capabilities.js +1 -37
- package/dist/workspace/support/agent-execution-config.js +1 -44
- package/dist/workspace/support/discovery.js +1 -147
- package/dist/workspace/support/source-collectors.js +1 -30
- package/dist/workspace/support/source-protocols.js +2 -192
- package/dist/workspace/support/workspace-ref-utils.js +1 -362
- package/dist/workspace/tool-hydration.js +1 -280
- package/dist/workspace/validate.js +1 -99
- package/dist/workspace/yaml-object-reader.js +1 -285
- package/package.json +7 -3
|
@@ -1,206 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
return typeof value === "boolean" ? value : undefined;
|
|
7
|
-
}
|
|
8
|
-
function asPositiveInteger(value) {
|
|
9
|
-
return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : undefined;
|
|
10
|
-
}
|
|
11
|
-
function excerpt(message) {
|
|
12
|
-
if (!message?.content) {
|
|
13
|
-
return "(none)";
|
|
14
|
-
}
|
|
15
|
-
const normalized = extractMessageText(message.content).replace(/\s+/g, " ").trim();
|
|
16
|
-
return normalized.length > 240 ? `${normalized.slice(0, 237)}...` : normalized;
|
|
17
|
-
}
|
|
18
|
-
function formatMessageSection(title, messages) {
|
|
19
|
-
const lines = [`## ${title}`, ""];
|
|
20
|
-
if (messages.length === 0) {
|
|
21
|
-
lines.push("(none)", "");
|
|
22
|
-
return lines;
|
|
23
|
-
}
|
|
24
|
-
for (const message of messages) {
|
|
25
|
-
lines.push(`- ${excerpt(message)}`);
|
|
26
|
-
}
|
|
27
|
-
lines.push("");
|
|
28
|
-
return lines;
|
|
29
|
-
}
|
|
30
|
-
function formatApprovalSection(approvals) {
|
|
31
|
-
const lines = ["## Approval Snapshot", ""];
|
|
32
|
-
if (approvals.length === 0) {
|
|
33
|
-
lines.push("(none)", "");
|
|
34
|
-
return lines;
|
|
35
|
-
}
|
|
36
|
-
for (const approval of approvals) {
|
|
37
|
-
lines.push(`- ${approval.approvalId}: ${approval.toolName} (${approval.status})`);
|
|
38
|
-
}
|
|
39
|
-
lines.push("");
|
|
40
|
-
return lines;
|
|
41
|
-
}
|
|
42
|
-
function renderRunSummaryMarkdown(input) {
|
|
43
|
-
const sessionId = input.session.sessionId;
|
|
44
|
-
const userMessages = input.messages.filter((message) => message.role === "user").slice(-3);
|
|
45
|
-
const assistantMessages = input.messages.filter((message) => message.role === "assistant").slice(-3);
|
|
46
|
-
return [
|
|
47
|
-
"# Request Memory Summary",
|
|
48
|
-
"",
|
|
49
|
-
`- session_id: ${sessionId}`,
|
|
50
|
-
`- request_id: ${input.requestId}`,
|
|
51
|
-
`- agent_id: ${input.agentId}`,
|
|
52
|
-
`- status: ${input.session.status}`,
|
|
53
|
-
`- trigger: ${input.trigger}`,
|
|
54
|
-
`- captured_at: ${input.capturedAt}`,
|
|
55
|
-
"",
|
|
56
|
-
...formatMessageSection("Recent User Messages", userMessages),
|
|
57
|
-
...formatMessageSection("Recent Assistant Messages", assistantMessages),
|
|
58
|
-
...formatApprovalSection(input.approvals),
|
|
59
|
-
].join("\n");
|
|
60
|
-
}
|
|
61
|
-
function renderSessionDigestMarkdown(input) {
|
|
62
|
-
const sessionId = input.session.sessionId;
|
|
63
|
-
const latestUser = input.messages.filter((message) => message.role === "user").at(-1);
|
|
64
|
-
const latestAssistant = input.messages.filter((message) => message.role === "assistant").at(-1);
|
|
65
|
-
return [
|
|
66
|
-
"# Durable Session Digest",
|
|
67
|
-
"",
|
|
68
|
-
`- session_id: ${sessionId}`,
|
|
69
|
-
`- latest_request_id: ${input.requestId}`,
|
|
70
|
-
`- status: ${input.session.status}`,
|
|
71
|
-
`- last_memory_trigger: ${input.trigger}`,
|
|
72
|
-
`- updated_at: ${input.capturedAt}`,
|
|
73
|
-
"",
|
|
74
|
-
"## Latest Durable User Context",
|
|
75
|
-
excerpt(latestUser),
|
|
76
|
-
"",
|
|
77
|
-
"## Latest Durable Assistant Context",
|
|
78
|
-
excerpt(latestAssistant),
|
|
79
|
-
"",
|
|
80
|
-
].join("\n");
|
|
81
|
-
}
|
|
82
|
-
const RUNTIME_MEMORY_EVENT_TYPES = new Set([
|
|
83
|
-
"request.state.changed",
|
|
84
|
-
"approval.resolved",
|
|
85
|
-
]);
|
|
86
|
-
export function readRuntimeMemorySyncConfig(runtimeMemory) {
|
|
87
|
-
if (runtimeMemory?.enabled !== true) {
|
|
88
|
-
return undefined;
|
|
89
|
-
}
|
|
90
|
-
const ingestion = asRecord(runtimeMemory.ingestion);
|
|
91
|
-
const writeOnApprovalResolution = asBoolean(ingestion?.writeOnApprovalResolution) ?? false;
|
|
92
|
-
const writeOnRequestCompletion = asBoolean(ingestion?.writeOnRequestCompletion) ?? false;
|
|
93
|
-
if (!writeOnApprovalResolution && !writeOnRequestCompletion) {
|
|
94
|
-
return undefined;
|
|
95
|
-
}
|
|
96
|
-
return {
|
|
97
|
-
enabled: true,
|
|
98
|
-
writeOnApprovalResolution,
|
|
99
|
-
writeOnRequestCompletion,
|
|
100
|
-
backgroundConsolidation: asBoolean(ingestion?.backgroundConsolidation) ?? true,
|
|
101
|
-
maxMessagesPerRequest: asPositiveInteger(ingestion?.maxMessagesPerRequest) ?? 40,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
export class RuntimeMemorySync {
|
|
105
|
-
persistence;
|
|
106
|
-
store;
|
|
107
|
-
config;
|
|
108
|
-
options;
|
|
109
|
-
pending = new Set();
|
|
110
|
-
syncChain = Promise.resolve();
|
|
111
|
-
name = "runtime-memory-sync";
|
|
112
|
-
constructor(persistence, store, config, options = {}) {
|
|
113
|
-
this.persistence = persistence;
|
|
114
|
-
this.store = store;
|
|
115
|
-
this.config = config;
|
|
116
|
-
this.options = options;
|
|
117
|
-
}
|
|
118
|
-
shouldHandle(event) {
|
|
119
|
-
if (!RUNTIME_MEMORY_EVENT_TYPES.has(event.eventType)) {
|
|
120
|
-
return false;
|
|
121
|
-
}
|
|
122
|
-
if (event.eventType === "approval.resolved") {
|
|
123
|
-
return this.config.writeOnApprovalResolution;
|
|
124
|
-
}
|
|
125
|
-
return this.config.writeOnRequestCompletion && event.payload.state === "completed";
|
|
126
|
-
}
|
|
127
|
-
async handleEvent(event) {
|
|
128
|
-
if (!this.shouldHandle(event)) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
const trigger = event.eventType === "approval.resolved" ? "approval.resolved" : "request.completed";
|
|
132
|
-
const task = this.syncChain
|
|
133
|
-
.then(() => this.syncRun(event.sessionId, event.requestId, trigger, event.timestamp))
|
|
134
|
-
.catch(() => {
|
|
135
|
-
// Fail open: runtime memory sync must not break the hot path.
|
|
136
|
-
});
|
|
137
|
-
this.syncChain = task
|
|
138
|
-
.catch(() => {
|
|
139
|
-
// Fail open: runtime memory sync must not break the hot path.
|
|
140
|
-
})
|
|
141
|
-
.finally(() => {
|
|
142
|
-
this.pending.delete(task);
|
|
143
|
-
});
|
|
144
|
-
this.pending.add(task);
|
|
145
|
-
}
|
|
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),
|
|
152
|
-
]);
|
|
153
|
-
if (!session || !run) {
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
const messages = allMessages.filter((message) => message.requestId === requestId);
|
|
157
|
-
if (messages.length === 0) {
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
const agentId = run.agentId ?? session.agentId;
|
|
161
|
-
const summaryMarkdown = renderRunSummaryMarkdown({
|
|
162
|
-
session,
|
|
163
|
-
requestId,
|
|
164
|
-
agentId,
|
|
165
|
-
trigger,
|
|
166
|
-
capturedAt,
|
|
167
|
-
messages,
|
|
168
|
-
approvals,
|
|
169
|
-
});
|
|
170
|
-
await Promise.all([
|
|
171
|
-
this.store.put(this.resolveRequestNamespace(sessionId), `${requestId}.summary.md`, { content: `${summaryMarkdown}\n` }),
|
|
172
|
-
this.store.put(this.resolveRequestNamespace(sessionId), `${requestId}.record.json`, {
|
|
173
|
-
kind: "summary",
|
|
174
|
-
scope: "session",
|
|
175
|
-
sessionId,
|
|
176
|
-
requestId,
|
|
177
|
-
agentId,
|
|
178
|
-
trigger,
|
|
179
|
-
capturedAt,
|
|
180
|
-
status: session.status,
|
|
181
|
-
messageCount: messages.length,
|
|
182
|
-
approvalCount: approvals.length,
|
|
183
|
-
}),
|
|
184
|
-
]);
|
|
185
|
-
if (!this.config.backgroundConsolidation) {
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
const digestMarkdown = renderSessionDigestMarkdown({
|
|
189
|
-
session,
|
|
190
|
-
requestId,
|
|
191
|
-
trigger,
|
|
192
|
-
capturedAt,
|
|
193
|
-
messages,
|
|
194
|
-
});
|
|
195
|
-
await this.store.put(this.resolveSessionNamespace(sessionId), "durable-summary.md", { content: `${digestMarkdown}\n` });
|
|
196
|
-
}
|
|
197
|
-
resolveSessionNamespace(sessionId) {
|
|
198
|
-
return this.options.resolveSessionNamespace ? this.options.resolveSessionNamespace(sessionId) : ["memories", "sessions", sessionId];
|
|
199
|
-
}
|
|
200
|
-
resolveRequestNamespace(sessionId) {
|
|
201
|
-
return this.options.resolveRequestNamespace ? this.options.resolveRequestNamespace(sessionId) : ["memories", "requests", sessionId];
|
|
202
|
-
}
|
|
203
|
-
async close() {
|
|
204
|
-
await Promise.allSettled(Array.from(this.pending));
|
|
205
|
-
}
|
|
206
|
-
}
|
|
1
|
+
import{extractMessageText as y}from"../../../utils/message-content.js";function R(s){return typeof s=="object"&&s!==null&&!Array.isArray(s)?s:void 0}function i(s){return typeof s=="boolean"?s:void 0}function $(s){return typeof s=="number"&&Number.isInteger(s)&&s>0?s:void 0}function c(s){if(!s?.content)return"(none)";const e=y(s.content).replace(/\s+/g," ").trim();return e.length>240?`${e.slice(0,237)}...`:e}function m(s,e){const t=[`## ${s}`,""];if(e.length===0)return t.push("(none)",""),t;for(const n of e)t.push(`- ${c(n)}`);return t.push(""),t}function v(s){const e=["## Approval Snapshot",""];if(s.length===0)return e.push("(none)",""),e;for(const t of s)e.push(`- ${t.approvalId}: ${t.toolName} (${t.status})`);return e.push(""),e}function M(s){const e=s.session.sessionId,t=s.messages.filter(o=>o.role==="user").slice(-3),n=s.messages.filter(o=>o.role==="assistant").slice(-3);return["# Request Memory Summary","",`- session_id: ${e}`,`- request_id: ${s.requestId}`,`- agent_id: ${s.agentId}`,`- status: ${s.session.status}`,`- trigger: ${s.trigger}`,`- captured_at: ${s.capturedAt}`,"",...m("Recent User Messages",t),...m("Recent Assistant Messages",n),...v(s.approvals)].join(`
|
|
2
|
+
`)}function S(s){const e=s.session.sessionId,t=s.messages.filter(o=>o.role==="user").at(-1),n=s.messages.filter(o=>o.role==="assistant").at(-1);return["# Durable Session Digest","",`- session_id: ${e}`,`- latest_request_id: ${s.requestId}`,`- status: ${s.session.status}`,`- last_memory_trigger: ${s.trigger}`,`- updated_at: ${s.capturedAt}`,"","## Latest Durable User Context",c(t),"","## Latest Durable Assistant Context",c(n),""].join(`
|
|
3
|
+
`)}const q=new Set(["request.state.changed","approval.resolved"]);function C(s){if(s?.enabled!==!0)return;const e=R(s.ingestion),t=i(e?.writeOnApprovalResolution)??!1,n=i(e?.writeOnRequestCompletion)??!1;if(!(!t&&!n))return{enabled:!0,writeOnApprovalResolution:t,writeOnRequestCompletion:n,backgroundConsolidation:i(e?.backgroundConsolidation)??!0,maxMessagesPerRequest:$(e?.maxMessagesPerRequest)??40}}class b{persistence;store;config;options;pending=new Set;syncChain=Promise.resolve();name="runtime-memory-sync";constructor(e,t,n,o={}){this.persistence=e,this.store=t,this.config=n,this.options=o}shouldHandle(e){return q.has(e.eventType)?e.eventType==="approval.resolved"?this.config.writeOnApprovalResolution:this.config.writeOnRequestCompletion&&e.payload.state==="completed":!1}async handleEvent(e){if(!this.shouldHandle(e))return;const t=e.eventType==="approval.resolved"?"approval.resolved":"request.completed",n=this.syncChain.then(()=>this.syncRun(e.sessionId,e.requestId,t,e.timestamp)).catch(()=>{});this.syncChain=n.catch(()=>{}).finally(()=>{this.pending.delete(n)}),this.pending.add(n)}async syncRun(e,t,n,o){const[r,l,d,u]=await Promise.all([this.persistence.getSession(e),this.persistence.getRequest(t),this.persistence.listSessionMessages(e,this.config.maxMessagesPerRequest),this.persistence.getRequestApprovals(e,t)]);if(!r||!l)return;const a=d.filter(f=>f.requestId===t);if(a.length===0)return;const p=l.agentId??r.agentId,g=M({session:r,requestId:t,agentId:p,trigger:n,capturedAt:o,messages:a,approvals:u});if(await Promise.all([this.store.put(this.resolveRequestNamespace(e),`${t}.summary.md`,{content:`${g}
|
|
4
|
+
`}),this.store.put(this.resolveRequestNamespace(e),`${t}.record.json`,{kind:"summary",scope:"session",sessionId:e,requestId:t,agentId:p,trigger:n,capturedAt:o,status:r.status,messageCount:a.length,approvalCount:u.length})]),!this.config.backgroundConsolidation)return;const h=S({session:r,requestId:t,trigger:n,capturedAt:o,messages:a});await this.store.put(this.resolveSessionNamespace(e),"durable-summary.md",{content:`${h}
|
|
5
|
+
`})}resolveSessionNamespace(e){return this.options.resolveSessionNamespace?this.options.resolveSessionNamespace(e):["memories","sessions",e]}resolveRequestNamespace(e){return this.options.resolveRequestNamespace?this.options.resolveRequestNamespace(e):["memories","requests",e]}async close(){await Promise.allSettled(Array.from(this.pending))}}export{b as RuntimeMemorySync,C as readRuntimeMemorySyncConfig};
|
|
@@ -1,113 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
return "(none)";
|
|
5
|
-
}
|
|
6
|
-
const normalized = extractMessageText(message.content).replace(/\s+/g, " ").trim();
|
|
7
|
-
return normalized.length > 240 ? `${normalized.slice(0, 237)}...` : normalized;
|
|
8
|
-
}
|
|
9
|
-
function renderSessionSnapshotMarkdown(session, messages, approvals) {
|
|
10
|
-
const sessionId = session.sessionId;
|
|
11
|
-
const latestRequestId = session.latestRequestId;
|
|
12
|
-
const userMessages = messages.filter((message) => message.role === "user");
|
|
13
|
-
const assistantMessages = messages.filter((message) => message.role === "assistant");
|
|
14
|
-
return [
|
|
15
|
-
"# Session Snapshot",
|
|
16
|
-
"",
|
|
17
|
-
`- session_id: ${sessionId}`,
|
|
18
|
-
`- latest_request_id: ${latestRequestId}`,
|
|
19
|
-
`- agent_id: ${session.agentId}`,
|
|
20
|
-
`- status: ${session.status}`,
|
|
21
|
-
`- updated_at: ${session.updatedAt}`,
|
|
22
|
-
"",
|
|
23
|
-
"## Recent User Message",
|
|
24
|
-
excerpt(userMessages.at(-1)),
|
|
25
|
-
"",
|
|
26
|
-
"## Recent Assistant Message",
|
|
27
|
-
excerpt(assistantMessages.at(-1)),
|
|
28
|
-
"",
|
|
29
|
-
...formatOpenApprovalsSection(approvals),
|
|
30
|
-
].join("\n");
|
|
31
|
-
}
|
|
32
|
-
function formatOpenApprovalsSection(approvals) {
|
|
33
|
-
const lines = ["## Open Approvals", ""];
|
|
34
|
-
if (approvals.length === 0) {
|
|
35
|
-
lines.push("(none)", "");
|
|
36
|
-
return lines;
|
|
37
|
-
}
|
|
38
|
-
for (const approval of approvals) {
|
|
39
|
-
lines.push(`### ${approval.approvalId}`);
|
|
40
|
-
lines.push(`- pending_action_id: ${approval.pendingActionId}`);
|
|
41
|
-
lines.push(`- tool: ${approval.toolName}`);
|
|
42
|
-
lines.push(`- request_id: ${approval.requestId}`);
|
|
43
|
-
lines.push(`- requested_at: ${approval.requestedAt}`);
|
|
44
|
-
lines.push(`- allowed: ${approval.allowedDecisions.join(", ")}`);
|
|
45
|
-
lines.push("");
|
|
46
|
-
}
|
|
47
|
-
return lines;
|
|
48
|
-
}
|
|
49
|
-
function resolveSessionNamespace(sessionId, resolver) {
|
|
50
|
-
return resolver ? resolver(sessionId) : ["memories", "sessions", sessionId];
|
|
51
|
-
}
|
|
52
|
-
const SESSION_MEMORY_EVENT_TYPES = new Set([
|
|
53
|
-
"request.state.changed",
|
|
54
|
-
"request.queued",
|
|
55
|
-
"request.dequeued",
|
|
56
|
-
"approval.resolved",
|
|
57
|
-
"approval.requested",
|
|
58
|
-
]);
|
|
59
|
-
export class SessionMemorySync {
|
|
60
|
-
persistence;
|
|
61
|
-
store;
|
|
62
|
-
options;
|
|
63
|
-
pending = new Set();
|
|
64
|
-
syncChain = Promise.resolve();
|
|
65
|
-
name = "session-memory-sync";
|
|
66
|
-
constructor(persistence, store, options = {}) {
|
|
67
|
-
this.persistence = persistence;
|
|
68
|
-
this.store = store;
|
|
69
|
-
this.options = options;
|
|
70
|
-
}
|
|
71
|
-
shouldHandle(event) {
|
|
72
|
-
return SESSION_MEMORY_EVENT_TYPES.has(event.eventType);
|
|
73
|
-
}
|
|
74
|
-
async handleEvent(event) {
|
|
75
|
-
if (!this.shouldHandle(event)) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
const task = this.syncChain
|
|
79
|
-
.then(() => this.syncSession(event.sessionId))
|
|
80
|
-
.catch(() => {
|
|
81
|
-
// Fail open: background memory digestion must not break the hot path.
|
|
82
|
-
});
|
|
83
|
-
this.syncChain = task
|
|
84
|
-
.catch(() => {
|
|
85
|
-
// Fail open: background memory digestion must not break the hot path.
|
|
86
|
-
})
|
|
87
|
-
.finally(() => {
|
|
88
|
-
this.pending.delete(task);
|
|
89
|
-
});
|
|
90
|
-
this.pending.add(task);
|
|
91
|
-
}
|
|
92
|
-
async syncSession(sessionId) {
|
|
93
|
-
const session = await this.persistence.getSession(sessionId);
|
|
94
|
-
if (!session) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
const [messages, approvals] = await Promise.all([
|
|
98
|
-
this.persistence.listSessionMessages(sessionId, 24),
|
|
99
|
-
this.persistence.listApprovals(),
|
|
100
|
-
]);
|
|
101
|
-
const pendingApprovals = approvals.filter((approval) => approval.sessionId === sessionId && approval.status === "pending");
|
|
102
|
-
if (!this.store) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
await this.store.put(resolveSessionNamespace(sessionId, this.options.resolveSessionNamespace), "snapshot.md", {
|
|
106
|
-
content: `${renderSessionSnapshotMarkdown(session, messages, pendingApprovals)}\n`,
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
async close() {
|
|
110
|
-
await Promise.allSettled(Array.from(this.pending));
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
export { SessionMemorySync as MemoryWorker };
|
|
1
|
+
import{extractMessageText as p}from"../../../utils/message-content.js";function c(t){if(!t?.content)return"(none)";const e=p(t.content).replace(/\s+/g," ").trim();return e.length>240?`${e.slice(0,237)}...`:e}function u(t,e,s){const n=t.sessionId,i=t.latestRequestId,r=e.filter(a=>a.role==="user"),o=e.filter(a=>a.role==="assistant");return["# Session Snapshot","",`- session_id: ${n}`,`- latest_request_id: ${i}`,`- agent_id: ${t.agentId}`,`- status: ${t.status}`,`- updated_at: ${t.updatedAt}`,"","## Recent User Message",c(r.at(-1)),"","## Recent Assistant Message",c(o.at(-1)),"",...l(s)].join(`
|
|
2
|
+
`)}function l(t){const e=["## Open Approvals",""];if(t.length===0)return e.push("(none)",""),e;for(const s of t)e.push(`### ${s.approvalId}`),e.push(`- pending_action_id: ${s.pendingActionId}`),e.push(`- tool: ${s.toolName}`),e.push(`- request_id: ${s.requestId}`),e.push(`- requested_at: ${s.requestedAt}`),e.push(`- allowed: ${s.allowedDecisions.join(", ")}`),e.push("");return e}function d(t,e){return e?e(t):["memories","sessions",t]}const h=new Set(["request.state.changed","request.queued","request.dequeued","approval.resolved","approval.requested"]);class g{persistence;store;options;pending=new Set;syncChain=Promise.resolve();name="session-memory-sync";constructor(e,s,n={}){this.persistence=e,this.store=s,this.options=n}shouldHandle(e){return h.has(e.eventType)}async handleEvent(e){if(!this.shouldHandle(e))return;const s=this.syncChain.then(()=>this.syncSession(e.sessionId)).catch(()=>{});this.syncChain=s.catch(()=>{}).finally(()=>{this.pending.delete(s)}),this.pending.add(s)}async syncSession(e){const s=await this.persistence.getSession(e);if(!s)return;const[n,i]=await Promise.all([this.persistence.listSessionMessages(e,24),this.persistence.listApprovals()]),r=i.filter(o=>o.sessionId===e&&o.status==="pending");this.store&&await this.store.put(d(e,this.options.resolveSessionNamespace),"snapshot.md",{content:`${u(s,n,r)}
|
|
3
|
+
`})}async close(){await Promise.allSettled(Array.from(this.pending))}}export{g as MemoryWorker,g as SessionMemorySync};
|
|
@@ -1,112 +1 @@
|
|
|
1
|
-
import path from
|
|
2
|
-
import { existsSync } from "node:fs";
|
|
3
|
-
import { augmentExecutablePath } from "../../env/runtime-env.js";
|
|
4
|
-
function dedupe(items) {
|
|
5
|
-
return Array.from(new Set(items.filter(Boolean)));
|
|
6
|
-
}
|
|
7
|
-
function pathEntries(pathValue) {
|
|
8
|
-
return augmentExecutablePath(pathValue ?? process.env.PATH ?? "")
|
|
9
|
-
.split(path.delimiter)
|
|
10
|
-
.map((entry) => entry.trim())
|
|
11
|
-
.filter(Boolean);
|
|
12
|
-
}
|
|
13
|
-
function isExecutableInPath(binName, searchPath) {
|
|
14
|
-
for (const entry of pathEntries(searchPath)) {
|
|
15
|
-
if (existsSync(path.join(entry, binName))) {
|
|
16
|
-
return true;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
function assessNamedRequirements(names, evaluator) {
|
|
22
|
-
return dedupe(names ?? []).map((name) => ({
|
|
23
|
-
name,
|
|
24
|
-
status: evaluator(name),
|
|
25
|
-
}));
|
|
26
|
-
}
|
|
27
|
-
function hasConfigPath(config, dottedPath) {
|
|
28
|
-
const parts = dottedPath.split(".").filter(Boolean);
|
|
29
|
-
let cursor = config;
|
|
30
|
-
for (const part of parts) {
|
|
31
|
-
if (typeof cursor !== "object" || cursor === null || Array.isArray(cursor) || !(part in cursor)) {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
cursor = cursor[part];
|
|
35
|
-
}
|
|
36
|
-
return cursor !== undefined;
|
|
37
|
-
}
|
|
38
|
-
function assessConfigRequirements(names, config) {
|
|
39
|
-
if (!names || names.length === 0) {
|
|
40
|
-
return [];
|
|
41
|
-
}
|
|
42
|
-
if (!config) {
|
|
43
|
-
return dedupe(names).map((name) => ({ name, status: "unknown" }));
|
|
44
|
-
}
|
|
45
|
-
if (Array.isArray(config)) {
|
|
46
|
-
const set = new Set(config);
|
|
47
|
-
return dedupe(names).map((name) => ({
|
|
48
|
-
name,
|
|
49
|
-
status: set.has(name) ? "satisfied" : "missing",
|
|
50
|
-
}));
|
|
51
|
-
}
|
|
52
|
-
return dedupe(names).map((name) => ({
|
|
53
|
-
name,
|
|
54
|
-
status: hasConfigPath(config, name) ? "satisfied" : "missing",
|
|
55
|
-
}));
|
|
56
|
-
}
|
|
57
|
-
function summarizeRequirementGroups(groups) {
|
|
58
|
-
const flat = groups.flat();
|
|
59
|
-
const missing = flat.some((item) => item.status === "missing");
|
|
60
|
-
const unknown = flat.some((item) => item.status === "unknown");
|
|
61
|
-
return {
|
|
62
|
-
ready: flat.length === 0 ? true : !missing && !unknown,
|
|
63
|
-
missing,
|
|
64
|
-
unknown,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
export function assessOpenClawRequirements(metadata, options = {}) {
|
|
68
|
-
if (!metadata?.requires) {
|
|
69
|
-
return undefined;
|
|
70
|
-
}
|
|
71
|
-
const availableBins = options.availableBins ? new Set(options.availableBins) : null;
|
|
72
|
-
const bins = assessNamedRequirements(metadata.requires.bins, (name) => availableBins
|
|
73
|
-
? (availableBins.has(name) ? "satisfied" : "missing")
|
|
74
|
-
: (isExecutableInPath(name, options.path) ? "satisfied" : "missing"));
|
|
75
|
-
const anyBins = assessNamedRequirements(metadata.requires.anyBins, (name) => availableBins
|
|
76
|
-
? (availableBins.has(name) ? "satisfied" : "missing")
|
|
77
|
-
: (isExecutableInPath(name, options.path) ? "satisfied" : "missing"));
|
|
78
|
-
const env = assessNamedRequirements(metadata.requires.env, (name) => options.env && options.env[name] ? "satisfied" : "missing");
|
|
79
|
-
const config = assessConfigRequirements(metadata.requires.config, options.config);
|
|
80
|
-
const primaryEnv = metadata.requires.primaryEnv
|
|
81
|
-
? {
|
|
82
|
-
name: metadata.requires.primaryEnv,
|
|
83
|
-
status: (options.env && options.env[metadata.requires.primaryEnv] ? "satisfied" : "missing"),
|
|
84
|
-
}
|
|
85
|
-
: undefined;
|
|
86
|
-
const anyBinsSummary = anyBins.length === 0
|
|
87
|
-
? []
|
|
88
|
-
: [{
|
|
89
|
-
name: anyBins.map((item) => item.name).join(" | "),
|
|
90
|
-
status: (anyBins.some((item) => item.status === "satisfied") ? "satisfied" : "missing"),
|
|
91
|
-
}];
|
|
92
|
-
const summary = summarizeRequirementGroups([
|
|
93
|
-
bins,
|
|
94
|
-
anyBinsSummary,
|
|
95
|
-
env,
|
|
96
|
-
config,
|
|
97
|
-
...(primaryEnv ? [[primaryEnv]] : []),
|
|
98
|
-
]);
|
|
99
|
-
return {
|
|
100
|
-
...summary,
|
|
101
|
-
bins,
|
|
102
|
-
anyBins,
|
|
103
|
-
env,
|
|
104
|
-
config,
|
|
105
|
-
...(primaryEnv ? { primaryEnv } : {}),
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
export function assessSkillRequirements(metadata, options = {}) {
|
|
109
|
-
return {
|
|
110
|
-
...(metadata.openclaw ? { openclaw: assessOpenClawRequirements(metadata.openclaw, options) } : {}),
|
|
111
|
-
};
|
|
112
|
-
}
|
|
1
|
+
import m from"node:path";import{existsSync as y}from"node:fs";import{augmentExecutablePath as g}from"../../env/runtime-env.js";function a(s){return Array.from(new Set(s.filter(Boolean)))}function h(s){return g(s??process.env.PATH??"").split(m.delimiter).map(n=>n.trim()).filter(Boolean)}function c(s,n){for(const e of h(n))if(y(m.join(e,s)))return!0;return!1}function f(s,n){return a(s??[]).map(e=>({name:e,status:n(e)}))}function v(s,n){const e=n.split(".").filter(Boolean);let i=s;for(const r of e){if(typeof i!="object"||i===null||Array.isArray(i)||!(r in i))return!1;i=i[r]}return i!==void 0}function d(s,n){if(!s||s.length===0)return[];if(!n)return a(s).map(e=>({name:e,status:"unknown"}));if(Array.isArray(n)){const e=new Set(n);return a(s).map(i=>({name:i,status:e.has(i)?"satisfied":"missing"}))}return a(s).map(e=>({name:e,status:v(n,e)?"satisfied":"missing"}))}function q(s){const n=s.flat(),e=n.some(r=>r.status==="missing"),i=n.some(r=>r.status==="unknown");return{ready:n.length===0?!0:!e&&!i,missing:e,unknown:i}}function w(s,n={}){if(!s?.requires)return;const e=n.availableBins?new Set(n.availableBins):null,i=f(s.requires.bins,t=>e?e.has(t)?"satisfied":"missing":c(t,n.path)?"satisfied":"missing"),r=f(s.requires.anyBins,t=>e?e.has(t)?"satisfied":"missing":c(t,n.path)?"satisfied":"missing"),o=f(s.requires.env,t=>n.env&&n.env[t]?"satisfied":"missing"),l=d(s.requires.config,n.config),u=s.requires.primaryEnv?{name:s.requires.primaryEnv,status:n.env&&n.env[s.requires.primaryEnv]?"satisfied":"missing"}:void 0,p=r.length===0?[]:[{name:r.map(t=>t.name).join(" | "),status:r.some(t=>t.status==="satisfied")?"satisfied":"missing"}];return{...q([i,p,o,l,...u?[[u]]:[]]),bins:i,anyBins:r,env:o,config:l,...u?{primaryEnv:u}:{}}}function S(s,n={}){return{...s.openclaw?{openclaw:w(s.openclaw,n)}:{}}}export{w as assessOpenClawRequirements,S as assessSkillRequirements};
|