@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,310 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const CAPABILITIES = {
|
|
3
|
-
sessions: { list: true, get: true, summaries: true },
|
|
4
|
-
requests: { submit: true, list: true, get: true, plan: { get: true }, cancel: true, stream: true, trace: { list: true } },
|
|
5
|
-
approvals: { list: true, get: true, resolve: true },
|
|
6
|
-
artifacts: { list: true, read: true },
|
|
7
|
-
events: { subscribe: true, list: true },
|
|
8
|
-
runtime: { health: true, overview: true },
|
|
9
|
-
};
|
|
10
|
-
function asObject(value, method) {
|
|
11
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
12
|
-
throw new Error(`${method} requires an object params payload.`);
|
|
13
|
-
}
|
|
14
|
-
return value;
|
|
15
|
-
}
|
|
16
|
-
function readOptionalString(value) {
|
|
17
|
-
return typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
|
|
18
|
-
}
|
|
19
|
-
function readRequiredString(value, field, method) {
|
|
20
|
-
const normalized = readOptionalString(value);
|
|
21
|
-
if (!normalized) {
|
|
22
|
-
throw new Error(`${method} requires ${field}.`);
|
|
23
|
-
}
|
|
24
|
-
return normalized;
|
|
25
|
-
}
|
|
26
|
-
function toNotification(event) {
|
|
27
|
-
return {
|
|
28
|
-
jsonrpc: "2.0",
|
|
29
|
-
method: "events.runtime",
|
|
30
|
-
params: {
|
|
31
|
-
event: {
|
|
32
|
-
eventId: event.eventId,
|
|
33
|
-
eventType: event.eventType,
|
|
34
|
-
timestamp: event.timestamp,
|
|
35
|
-
sessionId: event.sessionId,
|
|
36
|
-
requestId: event.requestId,
|
|
37
|
-
sequence: event.sequence,
|
|
38
|
-
source: event.source,
|
|
39
|
-
payload: event.payload,
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
function toStreamNotification(streamId, item) {
|
|
45
|
-
return {
|
|
46
|
-
jsonrpc: "2.0",
|
|
47
|
-
method: "requests.stream",
|
|
48
|
-
params: {
|
|
49
|
-
streamId,
|
|
50
|
-
item,
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
async function readArtifactContent(runtime, params) {
|
|
55
|
-
const method = "artifacts.read";
|
|
56
|
-
const sessionId = readRequiredString(params.sessionId, "sessionId", method);
|
|
57
|
-
const requestId = readRequiredString(params.requestId, "requestId", method);
|
|
58
|
-
const artifactPath = readRequiredString(params.artifactPath, "artifactPath", method);
|
|
59
|
-
const listing = await listRequestArtifacts(runtime, { sessionId, requestId });
|
|
60
|
-
const artifact = listing.items.find((item) => item.path === artifactPath);
|
|
61
|
-
if (!artifact) {
|
|
62
|
-
throw new Error(`Artifact not found for ${requestId}: ${artifactPath}`);
|
|
63
|
-
}
|
|
64
|
-
return {
|
|
65
|
-
...artifact,
|
|
66
|
-
content: await getArtifact(runtime, { sessionId, requestId, artifactPath }),
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
export class AgentHarnessAcpServer {
|
|
70
|
-
runtime;
|
|
71
|
-
listeners = new Set();
|
|
72
|
-
constructor(runtime) {
|
|
73
|
-
this.runtime = runtime;
|
|
74
|
-
this.runtime.subscribe((event) => {
|
|
75
|
-
this.emitNotification(toNotification(event));
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
capabilities() {
|
|
79
|
-
return CAPABILITIES;
|
|
80
|
-
}
|
|
81
|
-
subscribe(listener) {
|
|
82
|
-
this.listeners.add(listener);
|
|
83
|
-
return () => {
|
|
84
|
-
this.listeners.delete(listener);
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
async handle(request) {
|
|
88
|
-
const id = request.id ?? null;
|
|
89
|
-
if (!request || typeof request !== "object" || typeof request.method !== "string" || request.method.trim().length === 0) {
|
|
90
|
-
return {
|
|
91
|
-
jsonrpc: "2.0",
|
|
92
|
-
id,
|
|
93
|
-
error: {
|
|
94
|
-
code: -32600,
|
|
95
|
-
message: "Invalid JSON-RPC request.",
|
|
96
|
-
},
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
if (request.jsonrpc !== undefined && request.jsonrpc !== "2.0") {
|
|
100
|
-
return {
|
|
101
|
-
jsonrpc: "2.0",
|
|
102
|
-
id,
|
|
103
|
-
error: {
|
|
104
|
-
code: -32600,
|
|
105
|
-
message: "Only JSON-RPC 2.0 requests are supported.",
|
|
106
|
-
},
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
try {
|
|
110
|
-
const result = await this.dispatch(request.method, request.params);
|
|
111
|
-
if (request.id === undefined) {
|
|
112
|
-
return undefined;
|
|
113
|
-
}
|
|
114
|
-
return {
|
|
115
|
-
jsonrpc: "2.0",
|
|
116
|
-
id,
|
|
117
|
-
result,
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
catch (error) {
|
|
121
|
-
if (request.id === undefined) {
|
|
122
|
-
return undefined;
|
|
123
|
-
}
|
|
124
|
-
return {
|
|
125
|
-
jsonrpc: "2.0",
|
|
126
|
-
id,
|
|
127
|
-
error: {
|
|
128
|
-
code: this.methodExists(request.method) ? -32602 : -32601,
|
|
129
|
-
message: error instanceof Error ? error.message : "ACP request failed.",
|
|
130
|
-
},
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
methodExists(method) {
|
|
135
|
-
return new Set([
|
|
136
|
-
"capabilities.get",
|
|
137
|
-
"sessions.list",
|
|
138
|
-
"sessions.get",
|
|
139
|
-
"sessions.summaries",
|
|
140
|
-
"requests.submit",
|
|
141
|
-
"requests.list",
|
|
142
|
-
"requests.get",
|
|
143
|
-
"requests.plan.get",
|
|
144
|
-
"requests.cancel",
|
|
145
|
-
"requests.stream",
|
|
146
|
-
"requests.trace.list",
|
|
147
|
-
"approvals.list",
|
|
148
|
-
"approvals.get",
|
|
149
|
-
"approvals.resolve",
|
|
150
|
-
"artifacts.list",
|
|
151
|
-
"artifacts.read",
|
|
152
|
-
"events.list",
|
|
153
|
-
"runtime.health",
|
|
154
|
-
"runtime.overview",
|
|
155
|
-
]).has(method);
|
|
156
|
-
}
|
|
157
|
-
emitNotification(notification) {
|
|
158
|
-
for (const listener of Array.from(this.listeners)) {
|
|
159
|
-
try {
|
|
160
|
-
listener(notification);
|
|
161
|
-
}
|
|
162
|
-
catch {
|
|
163
|
-
// Ignore subscriber failures so one ACP consumer cannot tear down the server.
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
async dispatch(method, params) {
|
|
168
|
-
switch (method) {
|
|
169
|
-
case "capabilities.get":
|
|
170
|
-
return this.capabilities();
|
|
171
|
-
case "sessions.list": {
|
|
172
|
-
const payload = params === undefined ? {} : asObject(params, method);
|
|
173
|
-
return listSessions(this.runtime, {
|
|
174
|
-
agentId: readOptionalString(payload.agentId),
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
case "sessions.get": {
|
|
178
|
-
const payload = asObject(params, method);
|
|
179
|
-
return getSession(this.runtime, readRequiredString(payload.sessionId, "sessionId", method));
|
|
180
|
-
}
|
|
181
|
-
case "sessions.summaries": {
|
|
182
|
-
const payload = params === undefined ? {} : asObject(params, method);
|
|
183
|
-
return listSessionSummaries(this.runtime, {
|
|
184
|
-
agentId: readOptionalString(payload.agentId),
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
case "requests.submit": {
|
|
188
|
-
const payload = asObject(params, method);
|
|
189
|
-
if (readOptionalString(payload.streamId)) {
|
|
190
|
-
return this.submitStreamingRequest(payload, method);
|
|
191
|
-
}
|
|
192
|
-
return request(this.runtime, {
|
|
193
|
-
agentId: readOptionalString(payload.agentId),
|
|
194
|
-
input: payload.input,
|
|
195
|
-
invocation: payload.invocation,
|
|
196
|
-
listeners: payload.listeners,
|
|
197
|
-
priority: typeof payload.priority === "number" ? payload.priority : undefined,
|
|
198
|
-
sessionId: readOptionalString(payload.sessionId),
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
case "requests.cancel": {
|
|
202
|
-
const payload = asObject(params, method);
|
|
203
|
-
return cancelRequest(this.runtime, {
|
|
204
|
-
requestId: readRequiredString(payload.requestId, "requestId", method),
|
|
205
|
-
reason: readOptionalString(payload.reason),
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
case "requests.list": {
|
|
209
|
-
const payload = params === undefined ? {} : asObject(params, method);
|
|
210
|
-
return listRequests(this.runtime, {
|
|
211
|
-
agentId: readOptionalString(payload.agentId),
|
|
212
|
-
sessionId: readOptionalString(payload.sessionId),
|
|
213
|
-
state: payload.state,
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
case "requests.get": {
|
|
217
|
-
const payload = asObject(params, method);
|
|
218
|
-
return getRequest(this.runtime, readRequiredString(payload.requestId, "requestId", method));
|
|
219
|
-
}
|
|
220
|
-
case "requests.plan.get": {
|
|
221
|
-
const payload = asObject(params, method);
|
|
222
|
-
return getRequestPlanState(this.runtime, {
|
|
223
|
-
sessionId: readRequiredString(payload.sessionId, "sessionId", method),
|
|
224
|
-
requestId: readRequiredString(payload.requestId, "requestId", method),
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
case "requests.trace.list": {
|
|
228
|
-
const payload = asObject(params, method);
|
|
229
|
-
return listRequestTraceItems(this.runtime, {
|
|
230
|
-
sessionId: readRequiredString(payload.sessionId, "sessionId", method),
|
|
231
|
-
requestId: readRequiredString(payload.requestId, "requestId", method),
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
case "approvals.list": {
|
|
235
|
-
const payload = params === undefined ? {} : asObject(params, method);
|
|
236
|
-
return listApprovals(this.runtime, {
|
|
237
|
-
status: payload.status,
|
|
238
|
-
sessionId: readOptionalString(payload.sessionId),
|
|
239
|
-
requestId: readOptionalString(payload.requestId),
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
case "approvals.get": {
|
|
243
|
-
const payload = asObject(params, method);
|
|
244
|
-
return getApproval(this.runtime, readRequiredString(payload.approvalId, "approvalId", method));
|
|
245
|
-
}
|
|
246
|
-
case "approvals.resolve": {
|
|
247
|
-
const payload = asObject(params, method);
|
|
248
|
-
return resolveApproval(this.runtime, {
|
|
249
|
-
approvalId: readRequiredString(payload.approvalId, "approvalId", method),
|
|
250
|
-
decision: payload.decision,
|
|
251
|
-
editedInput: payload.editedInput,
|
|
252
|
-
requestId: readOptionalString(payload.requestId),
|
|
253
|
-
sessionId: readOptionalString(payload.sessionId),
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
case "artifacts.list": {
|
|
257
|
-
const payload = asObject(params, method);
|
|
258
|
-
return listRequestArtifacts(this.runtime, {
|
|
259
|
-
sessionId: readRequiredString(payload.sessionId, "sessionId", method),
|
|
260
|
-
requestId: readRequiredString(payload.requestId, "requestId", method),
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
case "artifacts.read":
|
|
264
|
-
return readArtifactContent(this.runtime, asObject(params, method));
|
|
265
|
-
case "events.list": {
|
|
266
|
-
const payload = asObject(params, method);
|
|
267
|
-
return listRequestEvents(this.runtime, {
|
|
268
|
-
sessionId: readRequiredString(payload.sessionId, "sessionId", method),
|
|
269
|
-
requestId: readRequiredString(payload.requestId, "requestId", method),
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
case "runtime.health":
|
|
273
|
-
return getHealth(this.runtime);
|
|
274
|
-
case "runtime.overview": {
|
|
275
|
-
const payload = params === undefined ? {} : asObject(params, method);
|
|
276
|
-
return getOperatorOverview(this.runtime, {
|
|
277
|
-
limit: typeof payload.limit === "number" ? payload.limit : undefined,
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
default:
|
|
281
|
-
throw new Error(`Unknown ACP method: ${method}`);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
async submitStreamingRequest(payload, method) {
|
|
285
|
-
const streamId = readRequiredString(payload.streamId, "streamId", method);
|
|
286
|
-
let finalResult;
|
|
287
|
-
for await (const item of this.runtime.streamEvents({
|
|
288
|
-
agentId: readOptionalString(payload.agentId),
|
|
289
|
-
input: payload.input,
|
|
290
|
-
invocation: payload.invocation,
|
|
291
|
-
listeners: payload.listeners,
|
|
292
|
-
priority: typeof payload.priority === "number" ? payload.priority : undefined,
|
|
293
|
-
sessionId: readOptionalString(payload.sessionId),
|
|
294
|
-
})) {
|
|
295
|
-
this.emitNotification(toStreamNotification(streamId, item));
|
|
296
|
-
if (item.type === "result") {
|
|
297
|
-
finalResult = item.result;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
if (finalResult) {
|
|
301
|
-
return finalResult;
|
|
302
|
-
}
|
|
303
|
-
throw new Error("ACP streaming request completed without a terminal result.");
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
export function createAcpServer(runtime) {
|
|
307
|
-
return new AgentHarnessAcpServer(runtime);
|
|
308
|
-
}
|
|
309
|
-
export { createAcpStdioClient } from "./client.js";
|
|
310
|
-
export { createAcpHttpClient } from "./client.js";
|
|
1
|
+
import{cancelRequest as I,getApproval as p,getArtifact as f,getHealth as q,getOperatorOverview as g,getRequestPlanState as m,getRequest as y,getSession as h,listApprovals as v,listRequestEvents as w,listRequestArtifacts as d,listRequestTraceItems as b,listRequests as A,listSessionSummaries as S,listSessions as R,request as j,resolveApproval as E}from"../../api.js";const P={sessions:{list:!0,get:!0,summaries:!0},requests:{submit:!0,list:!0,get:!0,plan:{get:!0},cancel:!0,stream:!0,trace:{list:!0}},approvals:{list:!0,get:!0,resolve:!0},artifacts:{list:!0,read:!0},events:{subscribe:!0,list:!0},runtime:{health:!0,overview:!0}};function n(r,e){if(!r||typeof r!="object"||Array.isArray(r))throw new Error(`${e} requires an object params payload.`);return r}function o(r){return typeof r=="string"&&r.trim().length>0?r.trim():void 0}function i(r,e,s){const t=o(r);if(!t)throw new Error(`${s} requires ${e}.`);return t}function C(r){return{jsonrpc:"2.0",method:"events.runtime",params:{event:{eventId:r.eventId,eventType:r.eventType,timestamp:r.timestamp,sessionId:r.sessionId,requestId:r.requestId,sequence:r.sequence,source:r.source,payload:r.payload}}}}function N(r,e){return{jsonrpc:"2.0",method:"requests.stream",params:{streamId:r,item:e}}}async function O(r,e){const s="artifacts.read",t=i(e.sessionId,"sessionId",s),u=i(e.requestId,"requestId",s),a=i(e.artifactPath,"artifactPath",s),c=(await d(r,{sessionId:t,requestId:u})).items.find(l=>l.path===a);if(!c)throw new Error(`Artifact not found for ${u}: ${a}`);return{...c,content:await f(r,{sessionId:t,requestId:u,artifactPath:a})}}class x{runtime;listeners=new Set;constructor(e){this.runtime=e,this.runtime.subscribe(s=>{this.emitNotification(C(s))})}capabilities(){return P}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}async handle(e){const s=e.id??null;if(!e||typeof e!="object"||typeof e.method!="string"||e.method.trim().length===0)return{jsonrpc:"2.0",id:s,error:{code:-32600,message:"Invalid JSON-RPC request."}};if(e.jsonrpc!==void 0&&e.jsonrpc!=="2.0")return{jsonrpc:"2.0",id:s,error:{code:-32600,message:"Only JSON-RPC 2.0 requests are supported."}};try{const t=await this.dispatch(e.method,e.params);return e.id===void 0?void 0:{jsonrpc:"2.0",id:s,result:t}}catch(t){return e.id===void 0?void 0:{jsonrpc:"2.0",id:s,error:{code:this.methodExists(e.method)?-32602:-32601,message:t instanceof Error?t.message:"ACP request failed."}}}}methodExists(e){return new Set(["capabilities.get","sessions.list","sessions.get","sessions.summaries","requests.submit","requests.list","requests.get","requests.plan.get","requests.cancel","requests.stream","requests.trace.list","approvals.list","approvals.get","approvals.resolve","artifacts.list","artifacts.read","events.list","runtime.health","runtime.overview"]).has(e)}emitNotification(e){for(const s of Array.from(this.listeners))try{s(e)}catch{}}async dispatch(e,s){switch(e){case"capabilities.get":return this.capabilities();case"sessions.list":{const t=s===void 0?{}:n(s,e);return R(this.runtime,{agentId:o(t.agentId)})}case"sessions.get":{const t=n(s,e);return h(this.runtime,i(t.sessionId,"sessionId",e))}case"sessions.summaries":{const t=s===void 0?{}:n(s,e);return S(this.runtime,{agentId:o(t.agentId)})}case"requests.submit":{const t=n(s,e);return o(t.streamId)?this.submitStreamingRequest(t,e):j(this.runtime,{agentId:o(t.agentId),input:t.input,invocation:t.invocation,listeners:t.listeners,priority:typeof t.priority=="number"?t.priority:void 0,sessionId:o(t.sessionId)})}case"requests.cancel":{const t=n(s,e);return I(this.runtime,{requestId:i(t.requestId,"requestId",e),reason:o(t.reason)})}case"requests.list":{const t=s===void 0?{}:n(s,e);return A(this.runtime,{agentId:o(t.agentId),sessionId:o(t.sessionId),state:t.state})}case"requests.get":{const t=n(s,e);return y(this.runtime,i(t.requestId,"requestId",e))}case"requests.plan.get":{const t=n(s,e);return m(this.runtime,{sessionId:i(t.sessionId,"sessionId",e),requestId:i(t.requestId,"requestId",e)})}case"requests.trace.list":{const t=n(s,e);return b(this.runtime,{sessionId:i(t.sessionId,"sessionId",e),requestId:i(t.requestId,"requestId",e)})}case"approvals.list":{const t=s===void 0?{}:n(s,e);return v(this.runtime,{status:t.status,sessionId:o(t.sessionId),requestId:o(t.requestId)})}case"approvals.get":{const t=n(s,e);return p(this.runtime,i(t.approvalId,"approvalId",e))}case"approvals.resolve":{const t=n(s,e);return E(this.runtime,{approvalId:i(t.approvalId,"approvalId",e),decision:t.decision,editedInput:t.editedInput,requestId:o(t.requestId),sessionId:o(t.sessionId)})}case"artifacts.list":{const t=n(s,e);return d(this.runtime,{sessionId:i(t.sessionId,"sessionId",e),requestId:i(t.requestId,"requestId",e)})}case"artifacts.read":return O(this.runtime,n(s,e));case"events.list":{const t=n(s,e);return w(this.runtime,{sessionId:i(t.sessionId,"sessionId",e),requestId:i(t.requestId,"requestId",e)})}case"runtime.health":return q(this.runtime);case"runtime.overview":{const t=s===void 0?{}:n(s,e);return g(this.runtime,{limit:typeof t.limit=="number"?t.limit:void 0})}default:throw new Error(`Unknown ACP method: ${e}`)}}async submitStreamingRequest(e,s){const t=i(e.streamId,"streamId",s);let u;for await(const a of this.runtime.streamEvents({agentId:o(e.agentId),input:e.input,invocation:e.invocation,listeners:e.listeners,priority:typeof e.priority=="number"?e.priority:void 0,sessionId:o(e.sessionId)}))this.emitNotification(N(t,a)),a.type==="result"&&(u=a.result);if(u)return u;throw new Error("ACP streaming request completed without a terminal result.")}}function H(r){return new x(r)}import{createAcpStdioClient as z}from"./client.js";import{createAcpHttpClient as L}from"./client.js";export{x as AgentHarnessAcpServer,L as createAcpHttpClient,H as createAcpServer,z as createAcpStdioClient};
|
|
@@ -1,69 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
function writeJsonLine(output, payload) {
|
|
4
|
-
return new Promise((resolve, reject) => {
|
|
5
|
-
output.write(`${JSON.stringify(payload)}\n`, (error) => {
|
|
6
|
-
if (error) {
|
|
7
|
-
reject(error);
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
resolve();
|
|
11
|
-
});
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
export function serveAcpOverStdio(runtime, options = {}) {
|
|
15
|
-
const input = options.input ?? process.stdin;
|
|
16
|
-
const output = options.output ?? process.stdout;
|
|
17
|
-
const server = createAcpServer(runtime);
|
|
18
|
-
const unsubscribe = server.subscribe((notification) => {
|
|
19
|
-
void writeJsonLine(output, notification);
|
|
20
|
-
});
|
|
21
|
-
const lineReader = createInterface({
|
|
22
|
-
input,
|
|
23
|
-
crlfDelay: Infinity,
|
|
24
|
-
});
|
|
25
|
-
const completed = (async () => {
|
|
26
|
-
try {
|
|
27
|
-
for await (const line of lineReader) {
|
|
28
|
-
const trimmed = line.trim();
|
|
29
|
-
if (trimmed.length === 0) {
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
let request;
|
|
33
|
-
try {
|
|
34
|
-
request = JSON.parse(trimmed);
|
|
35
|
-
}
|
|
36
|
-
catch {
|
|
37
|
-
await writeJsonLine(output, {
|
|
38
|
-
jsonrpc: "2.0",
|
|
39
|
-
id: null,
|
|
40
|
-
error: {
|
|
41
|
-
code: -32700,
|
|
42
|
-
message: "Invalid JSON payload.",
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
const response = await server.handle(request);
|
|
48
|
-
if (response) {
|
|
49
|
-
await writeJsonLine(output, response);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
finally {
|
|
54
|
-
unsubscribe();
|
|
55
|
-
lineReader.close();
|
|
56
|
-
}
|
|
57
|
-
})();
|
|
58
|
-
return {
|
|
59
|
-
completed,
|
|
60
|
-
close: async () => {
|
|
61
|
-
unsubscribe();
|
|
62
|
-
lineReader.close();
|
|
63
|
-
if (typeof input.destroy === "function") {
|
|
64
|
-
input.destroy();
|
|
65
|
-
}
|
|
66
|
-
await completed.catch(() => undefined);
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
}
|
|
1
|
+
import{createInterface as p}from"node:readline";import{createAcpServer as y}from"../../acp.js";function c(o,r){return new Promise((e,t)=>{o.write(`${JSON.stringify(r)}
|
|
2
|
+
`,n=>{if(n){t(n);return}e()})})}function v(o,r={}){const e=r.input??process.stdin,t=r.output??process.stdout,n=y(o),a=n.subscribe(s=>{c(t,s)}),i=p({input:e,crlfDelay:1/0}),u=(async()=>{try{for await(const s of i){const f=s.trim();if(f.length===0)continue;let l;try{l=JSON.parse(f)}catch{await c(t,{jsonrpc:"2.0",id:null,error:{code:-32700,message:"Invalid JSON payload."}});continue}const d=await n.handle(l);d&&await c(t,d)}}finally{a(),i.close()}})();return{completed:u,close:async()=>{a(),i.close(),typeof e.destroy=="function"&&e.destroy(),await u.catch(()=>{})}}}export{v as serveAcpOverStdio};
|