@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,138 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createPersistentId } from "../../utils/id.js";
|
|
3
|
-
import { buildAgentCard, normalizePath, parseA2aServiceParameters, SUPPORTED_A2A_VERSIONS, writeA2aDiscoveryHeaders, writeJson, writeOptionalAgentCardIntegrityHeaders, } from "./http-discovery.js";
|
|
4
|
-
import { createPushNotificationRegistry, handleA2aJsonRpcRequest, readRequestBody, toError } from "./http-rpc.js";
|
|
5
|
-
export async function serveA2aOverHttp(runtime, options = {}) {
|
|
6
|
-
const hostname = options.hostname?.trim() || "127.0.0.1";
|
|
7
|
-
const port = typeof options.port === "number" && Number.isFinite(options.port) ? options.port : 0;
|
|
8
|
-
const rpcPath = normalizePath(options.rpcPath, "/a2a");
|
|
9
|
-
const agentCardPath = normalizePath(options.agentCardPath, "/.well-known/agent-card.json");
|
|
10
|
-
const buildCardOptions = () => ({
|
|
11
|
-
agentName: options.agentName ?? "agent-harness-runtime",
|
|
12
|
-
agentDescription: options.agentDescription ?? "Agent-harness A2A bridge over the persisted runtime surface.",
|
|
13
|
-
rpcUrl: `http://${hostname}:${resolvedPort}${rpcPath}`,
|
|
14
|
-
...(options.documentationUrl ? { documentationUrl: options.documentationUrl } : {}),
|
|
15
|
-
...(options.provider ? { provider: options.provider } : {}),
|
|
16
|
-
...(options.defaultAgentId ? { defaultAgentId: options.defaultAgentId } : {}),
|
|
17
|
-
...(options.registryUrls ? { registryUrls: options.registryUrls } : {}),
|
|
18
|
-
...(options.agentCardSignature ? { agentCardSignature: options.agentCardSignature } : {}),
|
|
19
|
-
});
|
|
20
|
-
const pushNotifications = createPushNotificationRegistry(runtime, createPersistentId);
|
|
21
|
-
const httpServer = createServer(async (request, response) => {
|
|
22
|
-
try {
|
|
23
|
-
const requestUrl = new URL(request.url ?? "/", `http://${hostname}`);
|
|
24
|
-
const serviceParameters = parseA2aServiceParameters(requestUrl, request);
|
|
25
|
-
if (!serviceParameters) {
|
|
26
|
-
writeJson(response, 400, {
|
|
27
|
-
error: {
|
|
28
|
-
code: -32009,
|
|
29
|
-
message: `A2A version not supported. Supported versions: ${SUPPORTED_A2A_VERSIONS.join(", ")}.`,
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
writeA2aDiscoveryHeaders(response);
|
|
35
|
-
if (request.method === "OPTIONS" && (requestUrl.pathname === rpcPath || requestUrl.pathname === agentCardPath || requestUrl.pathname === "/.well-known/agent.json")) {
|
|
36
|
-
if (requestUrl.pathname === agentCardPath || requestUrl.pathname === "/.well-known/agent.json") {
|
|
37
|
-
writeOptionalAgentCardIntegrityHeaders(response, {
|
|
38
|
-
registryUrls: options.registryUrls,
|
|
39
|
-
agentCardSignature: options.agentCardSignature,
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
response.statusCode = 204;
|
|
43
|
-
response.setHeader("Allow", "GET,HEAD,POST,OPTIONS");
|
|
44
|
-
response.end();
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
if (request.method === "HEAD" && (requestUrl.pathname === agentCardPath || requestUrl.pathname === "/.well-known/agent.json")) {
|
|
48
|
-
writeOptionalAgentCardIntegrityHeaders(response, {
|
|
49
|
-
registryUrls: options.registryUrls,
|
|
50
|
-
agentCardSignature: options.agentCardSignature,
|
|
51
|
-
});
|
|
52
|
-
response.statusCode = 200;
|
|
53
|
-
response.setHeader("content-type", "application/json; charset=utf-8");
|
|
54
|
-
response.end();
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
if (request.method === "GET" && (requestUrl.pathname === agentCardPath || requestUrl.pathname === "/.well-known/agent.json")) {
|
|
58
|
-
writeOptionalAgentCardIntegrityHeaders(response, {
|
|
59
|
-
registryUrls: options.registryUrls,
|
|
60
|
-
agentCardSignature: options.agentCardSignature,
|
|
61
|
-
});
|
|
62
|
-
writeJson(response, 200, buildAgentCard(runtime, buildCardOptions()));
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
if (request.method === "POST" && (requestUrl.pathname === rpcPath || requestUrl.pathname === agentCardPath)) {
|
|
66
|
-
let payload;
|
|
67
|
-
try {
|
|
68
|
-
payload = JSON.parse(await readRequestBody(request));
|
|
69
|
-
}
|
|
70
|
-
catch {
|
|
71
|
-
writeJson(response, 400, toError(null, -32700, "Invalid JSON payload."));
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
if (payload.jsonrpc !== "2.0" || typeof payload.method !== "string") {
|
|
75
|
-
writeJson(response, 400, toError(payload.id ?? null, -32600, "Invalid JSON-RPC request."));
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
try {
|
|
79
|
-
await handleA2aJsonRpcRequest({
|
|
80
|
-
runtime,
|
|
81
|
-
request,
|
|
82
|
-
response,
|
|
83
|
-
payload,
|
|
84
|
-
serviceParameters,
|
|
85
|
-
serverOptions: options,
|
|
86
|
-
buildCardOptions,
|
|
87
|
-
pushNotifications,
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
catch (error) {
|
|
91
|
-
writeJson(response, 200, toError(payload.id ?? null, -32000, error instanceof Error ? error.message : String(error)));
|
|
92
|
-
}
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
writeJson(response, 404, {
|
|
96
|
-
error: "Not Found",
|
|
97
|
-
rpcPath,
|
|
98
|
-
agentCardPath,
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
catch (error) {
|
|
102
|
-
writeJson(response, 500, {
|
|
103
|
-
error: error instanceof Error ? error.message : "A2A HTTP transport failed.",
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
const completed = new Promise((resolve, reject) => {
|
|
108
|
-
httpServer.once("close", resolve);
|
|
109
|
-
httpServer.once("error", reject);
|
|
110
|
-
});
|
|
111
|
-
await new Promise((resolve, reject) => {
|
|
112
|
-
httpServer.listen(port, hostname, () => resolve());
|
|
113
|
-
httpServer.once("error", reject);
|
|
114
|
-
});
|
|
115
|
-
const address = httpServer.address();
|
|
116
|
-
const resolvedPort = typeof address === "object" && address ? address.port : port;
|
|
117
|
-
return {
|
|
118
|
-
hostname,
|
|
119
|
-
port: resolvedPort,
|
|
120
|
-
rpcPath,
|
|
121
|
-
agentCardPath,
|
|
122
|
-
rpcUrl: `http://${hostname}:${resolvedPort}${rpcPath}`,
|
|
123
|
-
agentCardUrl: `http://${hostname}:${resolvedPort}${agentCardPath}`,
|
|
124
|
-
completed,
|
|
125
|
-
close: async () => {
|
|
126
|
-
pushNotifications.unsubscribe();
|
|
127
|
-
await new Promise((resolve, reject) => {
|
|
128
|
-
httpServer.close((error) => {
|
|
129
|
-
if (error) {
|
|
130
|
-
reject(error);
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
resolve();
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
},
|
|
137
|
-
};
|
|
138
|
-
}
|
|
1
|
+
import{createServer as C}from"node:http";import{createPersistentId as U}from"../../utils/id.js";import{buildAgentCard as v,normalizePath as P,parseA2aServiceParameters as O,SUPPORTED_A2A_VERSIONS as N,writeA2aDiscoveryHeaders as $,writeJson as i,writeOptionalAgentCardIntegrityHeaders as h}from"./http-discovery.js";import{createPushNotificationRegistry as I,handleA2aJsonRpcRequest as j,readRequestBody as E,toError as f}from"./http-rpc.js";async function D(s,r={}){const d=r.hostname?.trim()||"127.0.0.1",y=typeof r.port=="number"&&Number.isFinite(r.port)?r.port:0,c=P(r.rpcPath,"/a2a"),n=P(r.agentCardPath,"/.well-known/agent-card.json"),S=()=>({agentName:r.agentName??"agent-harness-runtime",agentDescription:r.agentDescription??"Agent-harness A2A bridge over the persisted runtime surface.",rpcUrl:`http://${d}:${o}${c}`,...r.documentationUrl?{documentationUrl:r.documentationUrl}:{},...r.provider?{provider:r.provider}:{},...r.defaultAgentId?{defaultAgentId:r.defaultAgentId}:{},...r.registryUrls?{registryUrls:r.registryUrls}:{},...r.agentCardSignature?{agentCardSignature:r.agentCardSignature}:{}}),w=I(s,U),l=C(async(a,t)=>{try{const e=new URL(a.url??"/",`http://${d}`),A=O(e,a);if(!A){i(t,400,{error:{code:-32009,message:`A2A version not supported. Supported versions: ${N.join(", ")}.`}});return}if($(t),a.method==="OPTIONS"&&(e.pathname===c||e.pathname===n||e.pathname==="/.well-known/agent.json")){(e.pathname===n||e.pathname==="/.well-known/agent.json")&&h(t,{registryUrls:r.registryUrls,agentCardSignature:r.agentCardSignature}),t.statusCode=204,t.setHeader("Allow","GET,HEAD,POST,OPTIONS"),t.end();return}if(a.method==="HEAD"&&(e.pathname===n||e.pathname==="/.well-known/agent.json")){h(t,{registryUrls:r.registryUrls,agentCardSignature:r.agentCardSignature}),t.statusCode=200,t.setHeader("content-type","application/json; charset=utf-8"),t.end();return}if(a.method==="GET"&&(e.pathname===n||e.pathname==="/.well-known/agent.json")){h(t,{registryUrls:r.registryUrls,agentCardSignature:r.agentCardSignature}),i(t,200,v(s,S()));return}if(a.method==="POST"&&(e.pathname===c||e.pathname===n)){let g;try{g=JSON.parse(await E(a))}catch{i(t,400,f(null,-32700,"Invalid JSON payload."));return}if(g.jsonrpc!=="2.0"||typeof g.method!="string"){i(t,400,f(g.id??null,-32600,"Invalid JSON-RPC request."));return}try{await j({runtime:s,request:a,response:t,payload:g,serviceParameters:A,serverOptions:r,buildCardOptions:S,pushNotifications:w})}catch(u){i(t,200,f(g.id??null,-32e3,u instanceof Error?u.message:String(u)))}return}i(t,404,{error:"Not Found",rpcPath:c,agentCardPath:n})}catch(e){i(t,500,{error:e instanceof Error?e.message:"A2A HTTP transport failed."})}}),p=new Promise((a,t)=>{l.once("close",a),l.once("error",t)});await new Promise((a,t)=>{l.listen(y,d,()=>a()),l.once("error",t)});const m=l.address(),o=typeof m=="object"&&m?m.port:y;return{hostname:d,port:o,rpcPath:c,agentCardPath:n,rpcUrl:`http://${d}:${o}${c}`,agentCardUrl:`http://${d}:${o}${n}`,completed:p,close:async()=>{w.unsubscribe(),await new Promise((a,t)=>{l.close(e=>{if(e){t(e);return}a()})})}}}export{D as serveA2aOverHttp};
|
|
@@ -1,317 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
return "TASK_STATE_SUBMITTED";
|
|
5
|
-
case "running":
|
|
6
|
-
return "TASK_STATE_WORKING";
|
|
7
|
-
case "waiting_for_approval":
|
|
8
|
-
return "TASK_STATE_INPUT_REQUIRED";
|
|
9
|
-
case "completed":
|
|
10
|
-
return "TASK_STATE_COMPLETED";
|
|
11
|
-
case "cancelled":
|
|
12
|
-
return "TASK_STATE_CANCELED";
|
|
13
|
-
case "failed":
|
|
14
|
-
default:
|
|
15
|
-
return "TASK_STATE_FAILED";
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
export function mapTaskStatusToRequestState(state) {
|
|
19
|
-
switch (state?.toLowerCase().replace(/^task_state_/, "").replace(/_/g, "-")) {
|
|
20
|
-
case "submitted":
|
|
21
|
-
return "queued";
|
|
22
|
-
case "working":
|
|
23
|
-
return "running";
|
|
24
|
-
case "input-required":
|
|
25
|
-
return "waiting_for_approval";
|
|
26
|
-
case "completed":
|
|
27
|
-
return "completed";
|
|
28
|
-
case "failed":
|
|
29
|
-
return "failed";
|
|
30
|
-
case "canceled":
|
|
31
|
-
case "cancelled":
|
|
32
|
-
return "cancelled";
|
|
33
|
-
default:
|
|
34
|
-
return undefined;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
export function toTextParts(text) {
|
|
38
|
-
if (typeof text !== "string" || text.length === 0) {
|
|
39
|
-
return [];
|
|
40
|
-
}
|
|
41
|
-
return [{ text, mediaType: "text/plain" }];
|
|
42
|
-
}
|
|
43
|
-
function contentToText(content) {
|
|
44
|
-
if (typeof content === "string") {
|
|
45
|
-
return content;
|
|
46
|
-
}
|
|
47
|
-
if (!Array.isArray(content)) {
|
|
48
|
-
return undefined;
|
|
49
|
-
}
|
|
50
|
-
const text = content
|
|
51
|
-
.filter((part) => part.type === "text" && typeof part.text === "string")
|
|
52
|
-
.map((part) => part.text)
|
|
53
|
-
.join("\n\n")
|
|
54
|
-
.trim();
|
|
55
|
-
return text.length > 0 ? text : undefined;
|
|
56
|
-
}
|
|
57
|
-
export function toSessionRecord(session) {
|
|
58
|
-
return session ? toSessionRecordInternal(session) : null;
|
|
59
|
-
}
|
|
60
|
-
function toSessionRecordInternal(session) {
|
|
61
|
-
return {
|
|
62
|
-
sessionId: session.sessionId,
|
|
63
|
-
entryAgentId: session.entryAgentId,
|
|
64
|
-
currentAgentId: session.currentAgentId,
|
|
65
|
-
currentState: session.currentState,
|
|
66
|
-
latestRequestId: session.latestRequestId,
|
|
67
|
-
createdAt: session.createdAt,
|
|
68
|
-
updatedAt: session.updatedAt,
|
|
69
|
-
messages: session.messages,
|
|
70
|
-
requests: session.requests.map((request) => ({
|
|
71
|
-
requestId: request.requestId,
|
|
72
|
-
sessionId: request.sessionId,
|
|
73
|
-
agentId: request.agentId,
|
|
74
|
-
executionMode: request.executionMode,
|
|
75
|
-
adapterKind: request.adapterKind,
|
|
76
|
-
createdAt: request.createdAt,
|
|
77
|
-
updatedAt: request.updatedAt,
|
|
78
|
-
state: request.state,
|
|
79
|
-
checkpointRef: request.checkpointRef,
|
|
80
|
-
resumable: request.resumable,
|
|
81
|
-
startedAt: request.startedAt,
|
|
82
|
-
endedAt: request.endedAt,
|
|
83
|
-
lastActivityAt: request.lastActivityAt,
|
|
84
|
-
currentAgentId: request.currentAgentId,
|
|
85
|
-
delegationChain: request.delegationChain,
|
|
86
|
-
runtimeSnapshot: request.runtimeSnapshot,
|
|
87
|
-
traceItems: request.traceItems,
|
|
88
|
-
runtimeTimeline: request.runtimeTimeline,
|
|
89
|
-
})),
|
|
90
|
-
pendingDecision: session.pendingDecision,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
export function toRequestRecord(request) {
|
|
94
|
-
if (!request) {
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
return {
|
|
98
|
-
requestId: request.requestId,
|
|
99
|
-
sessionId: request.sessionId,
|
|
100
|
-
agentId: request.agentId,
|
|
101
|
-
executionMode: request.executionMode,
|
|
102
|
-
adapterKind: request.adapterKind,
|
|
103
|
-
createdAt: request.createdAt,
|
|
104
|
-
updatedAt: request.updatedAt,
|
|
105
|
-
state: request.state,
|
|
106
|
-
checkpointRef: request.checkpointRef,
|
|
107
|
-
resumable: request.resumable,
|
|
108
|
-
startedAt: request.startedAt,
|
|
109
|
-
endedAt: request.endedAt,
|
|
110
|
-
lastActivityAt: request.lastActivityAt,
|
|
111
|
-
currentAgentId: request.currentAgentId,
|
|
112
|
-
delegationChain: request.delegationChain,
|
|
113
|
-
runtimeSnapshot: request.runtimeSnapshot,
|
|
114
|
-
traceItems: request.traceItems,
|
|
115
|
-
runtimeTimeline: request.runtimeTimeline,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
export function buildTaskFromSessionAndRequest(session, request, approvals, output, failureMessage) {
|
|
119
|
-
if (!session || !request) {
|
|
120
|
-
return null;
|
|
121
|
-
}
|
|
122
|
-
const latestUserMessage = [...session.messages].reverse().find((message) => message.role === "user");
|
|
123
|
-
const latestAgentMessage = [...session.messages].reverse().find((message) => message.role === "assistant");
|
|
124
|
-
const approval = approvals.find((item) => item.status === "pending");
|
|
125
|
-
const latestAgentText = contentToText(latestAgentMessage?.content);
|
|
126
|
-
const latestUserText = contentToText(latestUserMessage?.content);
|
|
127
|
-
const statusText = request.state === "waiting_for_approval"
|
|
128
|
-
? approval
|
|
129
|
-
? `Approval required for tool ${approval.toolName}.`
|
|
130
|
-
: "Approval required."
|
|
131
|
-
: output ?? latestAgentText ?? failureMessage;
|
|
132
|
-
return {
|
|
133
|
-
id: request.requestId,
|
|
134
|
-
contextId: session.sessionId,
|
|
135
|
-
kind: "task",
|
|
136
|
-
status: {
|
|
137
|
-
state: mapRequestState(request.state),
|
|
138
|
-
timestamp: request.updatedAt,
|
|
139
|
-
...(statusText ? {
|
|
140
|
-
message: {
|
|
141
|
-
role: "ROLE_AGENT",
|
|
142
|
-
messageId: `${request.requestId}:status`,
|
|
143
|
-
parts: toTextParts(statusText),
|
|
144
|
-
},
|
|
145
|
-
} : {}),
|
|
146
|
-
},
|
|
147
|
-
history: [
|
|
148
|
-
...(latestUserText
|
|
149
|
-
? [{
|
|
150
|
-
role: "ROLE_USER",
|
|
151
|
-
messageId: `${request.requestId}:user`,
|
|
152
|
-
parts: toTextParts(latestUserText),
|
|
153
|
-
}]
|
|
154
|
-
: []),
|
|
155
|
-
...(latestAgentText
|
|
156
|
-
? [{
|
|
157
|
-
role: "ROLE_AGENT",
|
|
158
|
-
messageId: `${request.requestId}:agent`,
|
|
159
|
-
parts: toTextParts(latestAgentText),
|
|
160
|
-
}]
|
|
161
|
-
: []),
|
|
162
|
-
],
|
|
163
|
-
artifacts: [],
|
|
164
|
-
metadata: {
|
|
165
|
-
agentId: request.agentId,
|
|
166
|
-
sessionId: session.sessionId,
|
|
167
|
-
requestId: request.requestId,
|
|
168
|
-
state: request.state,
|
|
169
|
-
approvalIds: approvals.map((item) => item.approvalId),
|
|
170
|
-
},
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
export async function buildTaskFromRuntime(runtime, requestId) {
|
|
174
|
-
const request = await runtime.getRequest(requestId);
|
|
175
|
-
if (!request) {
|
|
176
|
-
return null;
|
|
177
|
-
}
|
|
178
|
-
const session = await runtime.getSessionRecord(request.sessionId);
|
|
179
|
-
const approvals = await runtime.listApprovals({ sessionId: request.sessionId, requestId: request.requestId });
|
|
180
|
-
return buildTaskFromSessionAndRequest(toSessionRecord(session), toRequestRecord(request), approvals);
|
|
181
|
-
}
|
|
182
|
-
export async function hydrateTaskStateFromEvents(runtime, task) {
|
|
183
|
-
if (!task) {
|
|
184
|
-
return null;
|
|
185
|
-
}
|
|
186
|
-
const events = await runtime.listRequestEvents(task.contextId, task.id);
|
|
187
|
-
const lastStateChange = [...events].reverse().find((event) => event.eventType === "request.state.changed");
|
|
188
|
-
const observedState = typeof lastStateChange?.payload?.state === "string" ? lastStateChange.payload.state : undefined;
|
|
189
|
-
if (!observedState) {
|
|
190
|
-
return task;
|
|
191
|
-
}
|
|
192
|
-
return {
|
|
193
|
-
...task,
|
|
194
|
-
status: {
|
|
195
|
-
...task.status,
|
|
196
|
-
state: mapRequestState(observedState),
|
|
197
|
-
},
|
|
198
|
-
metadata: {
|
|
199
|
-
...task.metadata,
|
|
200
|
-
state: observedState,
|
|
201
|
-
},
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
export async function listTasksFromRuntime(runtime, params) {
|
|
205
|
-
const runState = mapTaskStatusToRequestState(params.state);
|
|
206
|
-
const requests = await runtime.listRequests({
|
|
207
|
-
...(params.agentId ? { agentId: params.agentId } : {}),
|
|
208
|
-
...(params.contextId ? { sessionId: params.contextId } : {}),
|
|
209
|
-
...(runState ? { state: runState } : {}),
|
|
210
|
-
});
|
|
211
|
-
const startIndex = params.cursor ? Number.parseInt(Buffer.from(params.cursor, "base64url").toString("utf8"), 10) || 0 : 0;
|
|
212
|
-
const page = requests.slice(startIndex, startIndex + params.limit);
|
|
213
|
-
const tasks = (await Promise.all(page.map((request) => buildTaskFromRuntime(runtime, request.requestId)))).filter((task) => Boolean(task));
|
|
214
|
-
const nextIndex = startIndex + page.length;
|
|
215
|
-
const nextPageToken = nextIndex < requests.length ? Buffer.from(String(nextIndex), "utf8").toString("base64url") : "";
|
|
216
|
-
return {
|
|
217
|
-
tasks,
|
|
218
|
-
pageSize: params.limit,
|
|
219
|
-
totalSize: requests.length,
|
|
220
|
-
nextPageToken,
|
|
221
|
-
...(nextPageToken ? { nextCursor: nextPageToken } : {}),
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
export function isV1Method(method) {
|
|
225
|
-
return /^[A-Z]/.test(method);
|
|
226
|
-
}
|
|
227
|
-
export function toSendMessageResult(method, task) {
|
|
228
|
-
if (!task || !isV1Method(method)) {
|
|
229
|
-
return task;
|
|
230
|
-
}
|
|
231
|
-
return { task };
|
|
232
|
-
}
|
|
233
|
-
function toStatusUpdate(task) {
|
|
234
|
-
return {
|
|
235
|
-
taskId: task.id,
|
|
236
|
-
contextId: task.contextId,
|
|
237
|
-
kind: "status-update",
|
|
238
|
-
status: task.status,
|
|
239
|
-
final: isTerminalTaskState(task.status.state),
|
|
240
|
-
metadata: task.metadata,
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
export function toStreamingResult(method, task, mode) {
|
|
244
|
-
if (!task) {
|
|
245
|
-
return null;
|
|
246
|
-
}
|
|
247
|
-
if (!isV1Method(method)) {
|
|
248
|
-
return task;
|
|
249
|
-
}
|
|
250
|
-
if (mode === "status-update") {
|
|
251
|
-
return {
|
|
252
|
-
statusUpdate: toStatusUpdate(task),
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
return { task };
|
|
256
|
-
}
|
|
257
|
-
export function withStreamingStatusText(task, text) {
|
|
258
|
-
if (!task || typeof text !== "string" || text.length === 0) {
|
|
259
|
-
return task;
|
|
260
|
-
}
|
|
261
|
-
return {
|
|
262
|
-
...task,
|
|
263
|
-
status: {
|
|
264
|
-
...task.status,
|
|
265
|
-
message: {
|
|
266
|
-
role: "ROLE_AGENT",
|
|
267
|
-
messageId: `${task.id}:status`,
|
|
268
|
-
parts: toTextParts(text),
|
|
269
|
-
},
|
|
270
|
-
},
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
export function withRunResult(task, result, streamedText) {
|
|
274
|
-
if (!task) {
|
|
275
|
-
return null;
|
|
276
|
-
}
|
|
277
|
-
const statusText = streamedText || result.output;
|
|
278
|
-
return {
|
|
279
|
-
...task,
|
|
280
|
-
status: {
|
|
281
|
-
...task.status,
|
|
282
|
-
state: mapRequestState(result.state),
|
|
283
|
-
...(statusText
|
|
284
|
-
? {
|
|
285
|
-
message: {
|
|
286
|
-
role: "ROLE_AGENT",
|
|
287
|
-
messageId: `${task.id}:status`,
|
|
288
|
-
parts: toTextParts(statusText),
|
|
289
|
-
},
|
|
290
|
-
}
|
|
291
|
-
: {}),
|
|
292
|
-
},
|
|
293
|
-
metadata: {
|
|
294
|
-
...task.metadata,
|
|
295
|
-
state: result.state,
|
|
296
|
-
},
|
|
297
|
-
};
|
|
298
|
-
}
|
|
299
|
-
export function isTerminalTaskState(state) {
|
|
300
|
-
return state === "TASK_STATE_COMPLETED" || state === "TASK_STATE_FAILED" || state === "TASK_STATE_CANCELED";
|
|
301
|
-
}
|
|
302
|
-
export function clonePushNotificationConfig(config) {
|
|
303
|
-
return {
|
|
304
|
-
id: config.id,
|
|
305
|
-
taskId: config.taskId,
|
|
306
|
-
url: config.url,
|
|
307
|
-
...(config.token ? { token: config.token } : {}),
|
|
308
|
-
...(config.authentication ? { authentication: config.authentication } : {}),
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
export function fingerprintTaskForPush(task) {
|
|
312
|
-
return JSON.stringify({
|
|
313
|
-
state: task.status.state,
|
|
314
|
-
timestamp: task.status.timestamp,
|
|
315
|
-
message: task.status.message,
|
|
316
|
-
});
|
|
317
|
-
}
|
|
1
|
+
function p(t){switch(t){case"queued":return"TASK_STATE_SUBMITTED";case"running":return"TASK_STATE_WORKING";case"waiting_for_approval":return"TASK_STATE_INPUT_REQUIRED";case"completed":return"TASK_STATE_COMPLETED";case"cancelled":return"TASK_STATE_CANCELED";default:return"TASK_STATE_FAILED"}}function f(t){switch(t?.toLowerCase().replace(/^task_state_/,"").replace(/_/g,"-")){case"submitted":return"queued";case"working":return"running";case"input-required":return"waiting_for_approval";case"completed":return"completed";case"failed":return"failed";case"canceled":case"cancelled":return"cancelled";default:return}}function c(t){return typeof t!="string"||t.length===0?[]:[{text:t,mediaType:"text/plain"}]}function A(t){if(typeof t=="string")return t;if(!Array.isArray(t))return;const e=t.filter(n=>n.type==="text"&&typeof n.text=="string").map(n=>n.text).join(`
|
|
2
|
+
|
|
3
|
+
`).trim();return e.length>0?e:void 0}function m(t){return t?T(t):null}function T(t){return{sessionId:t.sessionId,entryAgentId:t.entryAgentId,currentAgentId:t.currentAgentId,currentState:t.currentState,latestRequestId:t.latestRequestId,createdAt:t.createdAt,updatedAt:t.updatedAt,messages:t.messages,requests:t.requests.map(e=>({requestId:e.requestId,sessionId:e.sessionId,agentId:e.agentId,executionMode:e.executionMode,adapterKind:e.adapterKind,createdAt:e.createdAt,updatedAt:e.updatedAt,state:e.state,checkpointRef:e.checkpointRef,resumable:e.resumable,startedAt:e.startedAt,endedAt:e.endedAt,lastActivityAt:e.lastActivityAt,currentAgentId:e.currentAgentId,delegationChain:e.delegationChain,runtimeSnapshot:e.runtimeSnapshot,traceItems:e.traceItems,runtimeTimeline:e.runtimeTimeline})),pendingDecision:t.pendingDecision}}function S(t){return t?{requestId:t.requestId,sessionId:t.sessionId,agentId:t.agentId,executionMode:t.executionMode,adapterKind:t.adapterKind,createdAt:t.createdAt,updatedAt:t.updatedAt,state:t.state,checkpointRef:t.checkpointRef,resumable:t.resumable,startedAt:t.startedAt,endedAt:t.endedAt,lastActivityAt:t.lastActivityAt,currentAgentId:t.currentAgentId,delegationChain:t.delegationChain,runtimeSnapshot:t.runtimeSnapshot,traceItems:t.traceItems,runtimeTimeline:t.runtimeTimeline}:null}function x(t,e,n,a,r){if(!t||!e)return null;const d=[...t.messages].reverse().find(i=>i.role==="user"),l=[...t.messages].reverse().find(i=>i.role==="assistant"),u=n.find(i=>i.status==="pending"),s=A(l?.content),o=A(d?.content),I=e.state==="waiting_for_approval"?u?`Approval required for tool ${u.toolName}.`:"Approval required.":a??s??r;return{id:e.requestId,contextId:t.sessionId,kind:"task",status:{state:p(e.state),timestamp:e.updatedAt,...I?{message:{role:"ROLE_AGENT",messageId:`${e.requestId}:status`,parts:c(I)}}:{}},history:[...o?[{role:"ROLE_USER",messageId:`${e.requestId}:user`,parts:c(o)}]:[],...s?[{role:"ROLE_AGENT",messageId:`${e.requestId}:agent`,parts:c(s)}]:[]],artifacts:[],metadata:{agentId:e.agentId,sessionId:t.sessionId,requestId:e.requestId,state:e.state,approvalIds:n.map(i=>i.approvalId)}}}async function E(t,e){const n=await t.getRequest(e);if(!n)return null;const a=await t.getSessionRecord(n.sessionId),r=await t.listApprovals({sessionId:n.sessionId,requestId:n.requestId});return x(m(a),S(n),r)}async function R(t,e){if(!e)return null;const a=[...await t.listRequestEvents(e.contextId,e.id)].reverse().find(d=>d.eventType==="request.state.changed"),r=typeof a?.payload?.state=="string"?a.payload.state:void 0;return r?{...e,status:{...e.status,state:p(r)},metadata:{...e.metadata,state:r}}:e}async function y(t,e){const n=f(e.state),a=await t.listRequests({...e.agentId?{agentId:e.agentId}:{},...e.contextId?{sessionId:e.contextId}:{},...n?{state:n}:{}}),r=e.cursor&&Number.parseInt(Buffer.from(e.cursor,"base64url").toString("utf8"),10)||0,d=a.slice(r,r+e.limit),l=(await Promise.all(d.map(o=>E(t,o.requestId)))).filter(o=>!!o),u=r+d.length,s=u<a.length?Buffer.from(String(u),"utf8").toString("base64url"):"";return{tasks:l,pageSize:e.limit,totalSize:a.length,nextPageToken:s,...s?{nextCursor:s}:{}}}function g(t){return/^[A-Z]/.test(t)}function v(t,e){return!e||!g(t)?e:{task:e}}function _(t){return{taskId:t.id,contextId:t.contextId,kind:"status-update",status:t.status,final:h(t.status.state),metadata:t.metadata}}function w(t,e,n){return e?g(t)?n==="status-update"?{statusUpdate:_(e)}:{task:e}:e:null}function C(t,e){return!t||typeof e!="string"||e.length===0?t:{...t,status:{...t.status,message:{role:"ROLE_AGENT",messageId:`${t.id}:status`,parts:c(e)}}}}function K(t,e,n){if(!t)return null;const a=n||e.output;return{...t,status:{...t.status,state:p(e.state),...a?{message:{role:"ROLE_AGENT",messageId:`${t.id}:status`,parts:c(a)}}:{}},metadata:{...t.metadata,state:e.state}}}function h(t){return t==="TASK_STATE_COMPLETED"||t==="TASK_STATE_FAILED"||t==="TASK_STATE_CANCELED"}function L(t){return{id:t.id,taskId:t.taskId,url:t.url,...t.token?{token:t.token}:{},...t.authentication?{authentication:t.authentication}:{}}}function N(t){return JSON.stringify({state:t.status.state,timestamp:t.status.timestamp,message:t.status.message})}export{E as buildTaskFromRuntime,x as buildTaskFromSessionAndRequest,L as clonePushNotificationConfig,N as fingerprintTaskForPush,R as hydrateTaskStateFromEvents,h as isTerminalTaskState,g as isV1Method,y as listTasksFromRuntime,p as mapRequestState,f as mapTaskStatusToRequestState,S as toRequestRecord,v as toSendMessageResult,m as toSessionRecord,w as toStreamingResult,c as toTextParts,K as withRunResult,C as withStreamingStatusText};
|