@botbotgo/agent-harness 0.0.308 → 0.0.310

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.
Files changed (195) hide show
  1. package/README.md +17 -1
  2. package/README.zh.md +17 -1
  3. package/dist/acp.d.ts +1 -116
  4. package/dist/acp.js +1 -310
  5. package/dist/api.d.ts +4 -2
  6. package/dist/api.js +4 -1
  7. package/dist/cli/chat-interactive.d.ts +24 -0
  8. package/dist/cli/chat-interactive.js +244 -0
  9. package/dist/cli/chat-rendering.d.ts +9 -0
  10. package/dist/cli/chat-rendering.js +102 -0
  11. package/dist/cli/chat-stream.d.ts +23 -0
  12. package/dist/cli/chat-stream.js +330 -0
  13. package/dist/cli/chat-ui.d.ts +20 -0
  14. package/dist/cli/chat-ui.js +198 -0
  15. package/dist/cli/chat-workspace.d.ts +15 -0
  16. package/dist/cli/chat-workspace.js +205 -0
  17. package/dist/cli/main.d.ts +52 -0
  18. package/dist/cli/main.js +323 -0
  19. package/dist/cli/managed-service-commands.d.ts +23 -0
  20. package/dist/cli/managed-service-commands.js +63 -0
  21. package/dist/cli/managed-service.d.ts +27 -0
  22. package/dist/cli/managed-service.js +61 -0
  23. package/dist/cli/options-init-chat.d.ts +16 -0
  24. package/dist/cli/options-init-chat.js +108 -0
  25. package/dist/cli/options-runtime.d.ts +27 -0
  26. package/dist/cli/options-runtime.js +158 -0
  27. package/dist/cli/options-serve.d.ts +24 -0
  28. package/dist/cli/options-serve.js +166 -0
  29. package/dist/cli/options.d.ts +5 -0
  30. package/dist/cli/options.js +47 -0
  31. package/dist/cli/process-guards.d.ts +14 -0
  32. package/dist/cli/process-guards.js +139 -0
  33. package/dist/cli/request-tree.d.ts +12 -0
  34. package/dist/cli/request-tree.js +296 -0
  35. package/dist/cli/runtime-commands.d.ts +15 -0
  36. package/dist/cli/runtime-commands.js +247 -0
  37. package/dist/cli/runtime-output.d.ts +5 -0
  38. package/dist/cli/runtime-output.js +124 -0
  39. package/dist/cli/server-commands.d.ts +36 -0
  40. package/dist/cli/server-commands.js +250 -0
  41. package/dist/cli/workspace.d.ts +6 -0
  42. package/dist/cli/workspace.js +71 -0
  43. package/dist/cli.d.ts +1 -67
  44. package/dist/cli.js +2 -2734
  45. package/dist/client/acp.d.ts +1 -50
  46. package/dist/client/acp.js +1 -219
  47. package/dist/client/in-process.d.ts +5 -5
  48. package/dist/client/index.d.ts +2 -2
  49. package/dist/client/index.js +1 -1
  50. package/dist/contracts/runtime-evaluation.d.ts +103 -0
  51. package/dist/contracts/runtime-evaluation.js +1 -0
  52. package/dist/contracts/runtime-memory.d.ts +162 -0
  53. package/dist/contracts/runtime-memory.js +1 -0
  54. package/dist/contracts/runtime-observability.d.ts +248 -0
  55. package/dist/contracts/runtime-observability.js +1 -0
  56. package/dist/contracts/runtime-requests.d.ts +342 -0
  57. package/dist/contracts/runtime-requests.js +1 -0
  58. package/dist/contracts/runtime-scheduling.d.ts +146 -0
  59. package/dist/contracts/runtime-scheduling.js +1 -0
  60. package/dist/contracts/runtime.d.ts +5 -1042
  61. package/dist/contracts/runtime.js +27 -1
  62. package/dist/flow/build-flow-graph.js +4 -875
  63. package/dist/flow/flow-graph-normalization.d.ts +56 -0
  64. package/dist/flow/flow-graph-normalization.js +214 -0
  65. package/dist/flow/flow-graph-runtime.d.ts +8 -0
  66. package/dist/flow/flow-graph-runtime.js +107 -0
  67. package/dist/flow/flow-graph-upstream.d.ts +18 -0
  68. package/dist/flow/flow-graph-upstream.js +498 -0
  69. package/dist/flow/types.d.ts +1 -1
  70. package/dist/index.d.ts +4 -4
  71. package/dist/index.js +2 -2
  72. package/dist/init-project.d.ts +1 -12
  73. package/dist/init-project.js +1 -651
  74. package/dist/{procedural → knowledge/procedural}/manager.d.ts +3 -3
  75. package/dist/{procedural → knowledge/procedural}/manager.js +6 -6
  76. package/dist/mcp.d.ts +2 -62
  77. package/dist/mcp.js +2 -253
  78. package/dist/package-version.d.ts +1 -1
  79. package/dist/package-version.js +1 -1
  80. package/dist/persistence/file-store.js +1 -1
  81. package/dist/persistence/sqlite-runtime.d.ts +19 -0
  82. package/dist/persistence/sqlite-runtime.js +86 -0
  83. package/dist/persistence/sqlite-store.js +11 -99
  84. package/dist/{request-events.d.ts → projections/request-events.d.ts} +1 -1
  85. package/dist/{upstream-events.js → projections/upstream-events.js} +1 -1
  86. package/dist/protocol/a2a/http-discovery.d.ts +39 -0
  87. package/dist/protocol/a2a/http-discovery.js +178 -0
  88. package/dist/protocol/a2a/http-rpc.d.ts +28 -0
  89. package/dist/protocol/a2a/http-rpc.js +623 -0
  90. package/dist/protocol/a2a/http.d.ts +72 -1
  91. package/dist/protocol/a2a/http.js +14 -1124
  92. package/dist/protocol/a2a/task-state.d.ts +29 -0
  93. package/dist/protocol/a2a/task-state.js +317 -0
  94. package/dist/protocol/acp/client.js +1 -1
  95. package/dist/protocol/acp/harness-client.d.ts +50 -0
  96. package/dist/protocol/acp/harness-client.js +219 -0
  97. package/dist/protocol/acp/server.d.ts +116 -0
  98. package/dist/protocol/acp/server.js +310 -0
  99. package/dist/protocol/ag-ui/http.js +1 -1
  100. package/dist/protocol/mcp/server.d.ts +76 -0
  101. package/dist/protocol/mcp/server.js +428 -0
  102. package/dist/resource/backend/workspace-scoped-backend.d.ts +40 -0
  103. package/dist/resource/backend/workspace-scoped-backend.js +296 -0
  104. package/dist/resource/mcp/tool-support.d.ts +35 -0
  105. package/dist/resource/mcp/tool-support.js +296 -0
  106. package/dist/resource/mcp-tool-support.d.ts +2 -35
  107. package/dist/resource/mcp-tool-support.js +2 -296
  108. package/dist/resource/providers/resource-provider.d.ts +22 -0
  109. package/dist/resource/providers/resource-provider.js +215 -0
  110. package/dist/resource/resource-impl.d.ts +3 -33
  111. package/dist/resource/resource-impl.js +2 -808
  112. package/dist/resource/resource-types.d.ts +33 -0
  113. package/dist/resource/resource-types.js +1 -0
  114. package/dist/resource/tools/function-tool-resolver.d.ts +2 -0
  115. package/dist/resource/tools/function-tool-resolver.js +306 -0
  116. package/dist/runtime/adapter/middleware-assembly.js +1 -1
  117. package/dist/runtime/adapter/model/invocation-request.js +2 -2
  118. package/dist/runtime/adapter/model/message-assembly.js +1 -1
  119. package/dist/runtime/agent-runtime-adapter.d.ts +3 -63
  120. package/dist/runtime/agent-runtime-adapter.js +5 -233
  121. package/dist/runtime/agent-runtime-assembly.d.ts +67 -0
  122. package/dist/runtime/agent-runtime-assembly.js +211 -0
  123. package/dist/runtime/harness/background-runtime.d.ts +1 -1
  124. package/dist/runtime/harness/events/event-sink.js +1 -1
  125. package/dist/runtime/harness/events/runtime-event-operations.d.ts +1 -1
  126. package/dist/runtime/harness/events/streaming.js +1 -1
  127. package/dist/runtime/harness/public-shapes.d.ts +43 -0
  128. package/dist/runtime/harness/public-shapes.js +186 -0
  129. package/dist/runtime/harness/run/inspection.js +2 -2
  130. package/dist/runtime/harness/run/resources.js +1 -1
  131. package/dist/runtime/harness/run/surface-semantics.js +1 -1
  132. package/dist/runtime/harness/system/inventory.d.ts +1 -1
  133. package/dist/runtime/harness/system/inventory.js +2 -2
  134. package/dist/runtime/harness/system/policy-engine.js +1 -1
  135. package/dist/runtime/harness/system/runtime-memory-manager.js +1 -1
  136. package/dist/runtime/harness/system/skill-requirements.d.ts +1 -1
  137. package/dist/runtime/harness/system/skill-requirements.js +1 -1
  138. package/dist/runtime/harness.d.ts +3 -2
  139. package/dist/runtime/harness.js +11 -191
  140. package/dist/runtime/maintenance/checkpoint-maintenance.js +1 -1
  141. package/dist/runtime/maintenance/runtime-record-maintenance.js +1 -1
  142. package/dist/runtime/parsing/output-content.d.ts +11 -0
  143. package/dist/runtime/parsing/output-content.js +442 -0
  144. package/dist/runtime/parsing/output-parsing.d.ts +3 -29
  145. package/dist/runtime/parsing/output-parsing.js +3 -806
  146. package/dist/runtime/parsing/output-recovery.d.ts +14 -0
  147. package/dist/runtime/parsing/output-recovery.js +288 -0
  148. package/dist/runtime/parsing/output-tool-args.d.ts +4 -0
  149. package/dist/runtime/parsing/output-tool-args.js +120 -0
  150. package/dist/runtime/support/runtime-factories.js +1 -1
  151. package/dist/scaffold/init-project.d.ts +12 -0
  152. package/dist/scaffold/init-project.js +651 -0
  153. package/dist/{extensions.d.ts → tooling/extensions.d.ts} +1 -1
  154. package/dist/{extensions.js → tooling/extensions.js} +3 -3
  155. package/dist/{tool-modules.d.ts → tooling/module-loader.d.ts} +1 -1
  156. package/dist/{tool-modules.js → tooling/module-loader.js} +2 -2
  157. package/dist/workspace/agent-binding-compiler.js +2 -2
  158. package/dist/workspace/compile.js +2 -2
  159. package/dist/workspace/object-loader-paths.d.ts +11 -0
  160. package/dist/workspace/object-loader-paths.js +75 -0
  161. package/dist/workspace/object-loader-readers.d.ts +21 -0
  162. package/dist/workspace/object-loader-readers.js +187 -0
  163. package/dist/workspace/object-loader.d.ts +0 -1
  164. package/dist/workspace/object-loader.js +6 -260
  165. package/dist/workspace/resource-compilers.js +1 -1
  166. package/dist/workspace/support/discovery.js +1 -1
  167. package/package.json +1 -1
  168. package/dist/runtime/adapter/index.d.ts +0 -13
  169. package/dist/runtime/adapter/index.js +0 -13
  170. package/dist/runtime/harness/index.d.ts +0 -19
  171. package/dist/runtime/harness/index.js +0 -19
  172. package/dist/runtime/maintenance/index.d.ts +0 -4
  173. package/dist/runtime/maintenance/index.js +0 -4
  174. package/dist/runtime/parsing/index.d.ts +0 -2
  175. package/dist/runtime/parsing/index.js +0 -2
  176. package/dist/runtime/support/index.d.ts +0 -4
  177. package/dist/runtime/support/index.js +0 -4
  178. package/dist/workspace/support/index.d.ts +0 -2
  179. package/dist/workspace/support/index.js +0 -2
  180. /package/dist/{procedural → knowledge/procedural}/config.d.ts +0 -0
  181. /package/dist/{procedural → knowledge/procedural}/config.js +0 -0
  182. /package/dist/{procedural → knowledge/procedural}/index.d.ts +0 -0
  183. /package/dist/{procedural → knowledge/procedural}/index.js +0 -0
  184. /package/dist/{presentation.d.ts → projections/presentation.d.ts} +0 -0
  185. /package/dist/{presentation.js → projections/presentation.js} +0 -0
  186. /package/dist/{request-events.js → projections/request-events.js} +0 -0
  187. /package/dist/{upstream-events.d.ts → projections/upstream-events.d.ts} +0 -0
  188. /package/dist/runtime/{support → env}/runtime-env.d.ts +0 -0
  189. /package/dist/runtime/{support → env}/runtime-env.js +0 -0
  190. /package/dist/runtime/{support → layout}/runtime-layout.d.ts +0 -0
  191. /package/dist/runtime/{support → layout}/runtime-layout.js +0 -0
  192. /package/dist/runtime/{support → prompts}/runtime-prompts.d.ts +0 -0
  193. /package/dist/runtime/{support → prompts}/runtime-prompts.js +0 -0
  194. /package/dist/runtime/{support → skills}/skill-metadata.d.ts +0 -0
  195. /package/dist/runtime/{support → skills}/skill-metadata.js +0 -0
@@ -0,0 +1,116 @@
1
+ import type { ArtifactRecord, HarnessEvent, HarnessStreamItem, RequestRecord, RequestOptions, SessionRecord } from "../../contracts/types.js";
2
+ import type { AgentHarnessRuntime } from "../../runtime/harness.js";
3
+ import { getApproval, type PublicRequestListeners } from "../../api.js";
4
+ type JsonRpcId = string | number | null;
5
+ export type AcpJsonRpcRequest = {
6
+ jsonrpc?: "2.0";
7
+ id?: JsonRpcId;
8
+ method: string;
9
+ params?: unknown;
10
+ };
11
+ export type AcpJsonRpcError = {
12
+ jsonrpc: "2.0";
13
+ id: JsonRpcId;
14
+ error: {
15
+ code: number;
16
+ message: string;
17
+ data?: unknown;
18
+ };
19
+ };
20
+ export type AcpJsonRpcSuccess = {
21
+ jsonrpc: "2.0";
22
+ id: JsonRpcId;
23
+ result: unknown;
24
+ };
25
+ export type AcpJsonRpcResponse = AcpJsonRpcError | AcpJsonRpcSuccess;
26
+ export type AcpSessionRecord = SessionRecord;
27
+ export type AcpRequestRecord = RequestRecord;
28
+ export type AcpApproval = Awaited<ReturnType<typeof getApproval>> extends infer T ? Exclude<T, null> : never;
29
+ export type AcpArtifact = ArtifactRecord & {
30
+ content?: unknown;
31
+ };
32
+ export type AcpRequestParams = Omit<Extract<RequestOptions, {
33
+ input: unknown;
34
+ }>, "listeners"> & {
35
+ sessionId?: string;
36
+ streamId?: string;
37
+ listeners?: PublicRequestListeners;
38
+ };
39
+ export type AcpServerCapabilities = {
40
+ sessions: {
41
+ list: true;
42
+ get: true;
43
+ summaries: true;
44
+ };
45
+ requests: {
46
+ submit: true;
47
+ list: true;
48
+ get: true;
49
+ plan: {
50
+ get: true;
51
+ };
52
+ cancel: true;
53
+ stream: true;
54
+ trace: {
55
+ list: true;
56
+ };
57
+ };
58
+ approvals: {
59
+ list: true;
60
+ get: true;
61
+ resolve: true;
62
+ };
63
+ artifacts: {
64
+ list: true;
65
+ read: true;
66
+ };
67
+ events: {
68
+ subscribe: true;
69
+ list: true;
70
+ };
71
+ runtime: {
72
+ health: true;
73
+ overview: true;
74
+ };
75
+ };
76
+ export type AcpEventNotification = {
77
+ jsonrpc: "2.0";
78
+ method: "events.runtime";
79
+ params: {
80
+ event: {
81
+ eventId: string;
82
+ eventType: string;
83
+ timestamp: string;
84
+ sessionId: string;
85
+ requestId: string;
86
+ sequence: number;
87
+ source: HarnessEvent["source"];
88
+ payload: Record<string, unknown>;
89
+ };
90
+ };
91
+ };
92
+ export type AcpStreamNotification = {
93
+ jsonrpc: "2.0";
94
+ method: "requests.stream";
95
+ params: {
96
+ streamId: string;
97
+ item: HarnessStreamItem;
98
+ };
99
+ };
100
+ export type AcpNotification = AcpEventNotification | AcpStreamNotification;
101
+ export declare class AgentHarnessAcpServer {
102
+ private readonly runtime;
103
+ private readonly listeners;
104
+ constructor(runtime: AgentHarnessRuntime);
105
+ capabilities(): AcpServerCapabilities;
106
+ subscribe(listener: (notification: AcpNotification) => void): () => void;
107
+ handle(request: AcpJsonRpcRequest): Promise<AcpJsonRpcResponse | undefined>;
108
+ private methodExists;
109
+ private emitNotification;
110
+ private dispatch;
111
+ private submitStreamingRequest;
112
+ }
113
+ export declare function createAcpServer(runtime: AgentHarnessRuntime): AgentHarnessAcpServer;
114
+ export { createAcpStdioClient } from "./client.js";
115
+ export { createAcpHttpClient } from "./client.js";
116
+ export type { AcpHttpClient, AcpHttpClientOptions, AcpStdioClient, AcpStdioClientOptions } from "./client.js";
@@ -0,0 +1,310 @@
1
+ import { cancelRequest, getApproval, getArtifact, getHealth, getOperatorOverview, getRequestPlanState, getRequest, getSession, listApprovals, listRequestEvents, listRequestArtifacts, listRequestTraceItems, listRequests, listSessionSummaries, listSessions, request, resolveApproval, } from "../../api.js";
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,6 +1,6 @@
1
1
  import { createServer } from "node:http";
2
2
  import { createPersistentId } from "../../utils/id.js";
3
- import { createUpstreamTimelineReducer } from "../../upstream-events.js";
3
+ import { createUpstreamTimelineReducer } from "../../projections/upstream-events.js";
4
4
  function normalizePath(value, fallback) {
5
5
  const source = typeof value === "string" && value.trim().length > 0 ? value.trim() : fallback;
6
6
  return source.startsWith("/") ? source : `/${source}`;
@@ -0,0 +1,76 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import type { ApprovalRecord, ArtifactListing, CompiledTool, HarnessEvent, ParsedToolObject, RequestRecord, RequestResult, RequestState, RequestSummary, RuntimeSessionPackage, RuntimeSessionPackageInput, SessionRecord, SessionSummary } from "../../contracts/types.js";
3
+ export type ToolMcpServerOptions = {
4
+ agentId: string;
5
+ serverInfo?: {
6
+ name?: string;
7
+ version?: string;
8
+ };
9
+ includeToolNames?: string[];
10
+ };
11
+ export type ToolMcpServerTool = {
12
+ compiledTool: CompiledTool;
13
+ resolvedTool: unknown;
14
+ sourceTool?: ParsedToolObject;
15
+ };
16
+ export type RuntimeMcpServerOptions = {
17
+ serverInfo?: {
18
+ name?: string;
19
+ version?: string;
20
+ };
21
+ };
22
+ export type RuntimeMcpStreamableHttpServerOptions = RuntimeMcpServerOptions & {
23
+ hostname?: string;
24
+ port?: number;
25
+ path?: string;
26
+ };
27
+ export type RuntimeMcpStreamableHttpServer = {
28
+ hostname: string;
29
+ port: number;
30
+ path: string;
31
+ url: string;
32
+ completed: Promise<void>;
33
+ close: () => Promise<void>;
34
+ };
35
+ type RuntimeMcpRuntime = {
36
+ listSessions: (filter?: {
37
+ agentId?: string;
38
+ }) => Promise<SessionSummary[]>;
39
+ getSessionRecord: (sessionId: string) => Promise<SessionRecord | null>;
40
+ listRequests: (filter?: {
41
+ agentId?: string;
42
+ sessionId?: string;
43
+ state?: RequestState;
44
+ }) => Promise<RequestSummary[]>;
45
+ getRequest: (requestId: string) => Promise<RequestRecord | null>;
46
+ listApprovals: (filter?: {
47
+ status?: ApprovalRecord["status"];
48
+ sessionId?: string;
49
+ requestId?: string;
50
+ }) => Promise<ApprovalRecord[]>;
51
+ getApproval: (approvalId: string) => Promise<ApprovalRecord | null>;
52
+ resume: (options: {
53
+ approvalId?: string;
54
+ sessionId?: string;
55
+ requestId?: string;
56
+ decision?: "approve" | "edit" | "reject";
57
+ editedInput?: Record<string, unknown>;
58
+ }) => Promise<RequestResult>;
59
+ listRequestArtifacts: (sessionId: string, requestId: string) => Promise<ArtifactListing>;
60
+ readRequestArtifact: (sessionId: string, requestId: string, artifactPath: string) => Promise<unknown>;
61
+ listRequestEvents: (sessionId: string, requestId: string) => Promise<HarnessEvent[]>;
62
+ exportRequestPackage: (input: {
63
+ sessionId: string;
64
+ requestId: string;
65
+ includeArtifacts?: boolean;
66
+ includeArtifactContents?: boolean;
67
+ includeRuntimeHealth?: boolean;
68
+ }) => Promise<unknown>;
69
+ exportSessionPackage: (input: RuntimeSessionPackageInput) => Promise<RuntimeSessionPackage>;
70
+ };
71
+ export declare function createToolMcpServerFromTools(tools: ToolMcpServerTool[], options: ToolMcpServerOptions): Promise<McpServer>;
72
+ export declare function serveToolsOverStdioFromHarness(tools: ToolMcpServerTool[], options: ToolMcpServerOptions): Promise<McpServer>;
73
+ export declare function createRuntimeMcpServer(runtime: RuntimeMcpRuntime, options?: RuntimeMcpServerOptions): Promise<McpServer>;
74
+ export declare function serveRuntimeMcpOverStdio(runtime: RuntimeMcpRuntime, options?: RuntimeMcpServerOptions): Promise<McpServer>;
75
+ export declare function serveRuntimeMcpOverStreamableHttp(runtime: RuntimeMcpRuntime, options?: RuntimeMcpStreamableHttpServerOptions): Promise<RuntimeMcpStreamableHttpServer>;
76
+ export {};