@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,249 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export const DEFAULT_DEEPAGENT_RECURSION_LIMIT = 100;
|
|
9
|
-
const MODEL_EXPOSED_BUILTIN_MIDDLEWARE_TOOL_NAMES = new Set([
|
|
10
|
-
"fetch_url",
|
|
11
|
-
"http_request",
|
|
12
|
-
"send_message",
|
|
13
|
-
"request_approval",
|
|
14
|
-
"schedule_task",
|
|
15
|
-
]);
|
|
16
|
-
export function materializeModelExposedBuiltinMiddlewareTools(input) {
|
|
17
|
-
if (input.modelExposed === false || input.modelExposed === undefined) {
|
|
18
|
-
return [];
|
|
19
|
-
}
|
|
20
|
-
const explicitToolNames = new Set(input.explicitToolNames ?? []);
|
|
21
|
-
const allowedToolNames = Array.isArray(input.modelExposed)
|
|
22
|
-
? new Set(input.modelExposed)
|
|
23
|
-
: undefined;
|
|
24
|
-
const tools = [];
|
|
25
|
-
for (const [toolName, tool] of input.builtinTools.entries()) {
|
|
26
|
-
if (explicitToolNames.has(toolName)
|
|
27
|
-
|| !MODEL_EXPOSED_BUILTIN_MIDDLEWARE_TOOL_NAMES.has(toolName)
|
|
28
|
-
|| (allowedToolNames && !allowedToolNames.has(toolName))) {
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
tools.push(asStructuredExecutableTool(tool, toolName, tool.name));
|
|
32
|
-
}
|
|
33
|
-
return tools;
|
|
34
|
-
}
|
|
35
|
-
function formatCapabilityLine(item) {
|
|
36
|
-
const description = typeof item.description === "string" && item.description.length > 0
|
|
37
|
-
? `: ${item.description}`
|
|
38
|
-
: "";
|
|
39
|
-
return `- ${JSON.stringify(item.name)}${description}`;
|
|
40
|
-
}
|
|
41
|
-
function buildSkillCatalog(skillPaths) {
|
|
42
|
-
return skillPaths.map((skillPath) => {
|
|
43
|
-
const metadata = readSkillMetadata(skillPath);
|
|
44
|
-
return {
|
|
45
|
-
name: metadata.name,
|
|
46
|
-
...(metadata.description ? { description: metadata.description } : {}),
|
|
47
|
-
};
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
export function buildRuntimeTemporalContext(now = new Date()) {
|
|
51
|
-
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone || "system local time";
|
|
52
|
-
return [
|
|
53
|
-
"Runtime temporal context:",
|
|
54
|
-
`- Current date/time: ${now.toISOString()}`,
|
|
55
|
-
`- Local time zone: ${timeZone}`,
|
|
56
|
-
"Use the runtime date/time above as authoritative for interpreting current, latest, recent, today, tomorrow, yesterday, and tool-returned dates.",
|
|
57
|
-
"Do not reject tool evidence as future-dated solely because it is newer than the model's training data.",
|
|
58
|
-
].join("\n");
|
|
59
|
-
}
|
|
60
|
-
function appendRuntimeTemporalContext(systemPrompt) {
|
|
61
|
-
return [typeof systemPrompt === "string" ? systemPrompt : undefined, buildRuntimeTemporalContext()]
|
|
62
|
-
.filter((part) => typeof part === "string" && part.length > 0)
|
|
63
|
-
.join("\n\n");
|
|
64
|
-
}
|
|
65
|
-
export function buildDeepAgentSystemPromptWithCapabilityCatalog(input) {
|
|
66
|
-
const basePrompt = typeof input.systemPrompt === "string" ? input.systemPrompt : undefined;
|
|
67
|
-
const skills = buildSkillCatalog(input.skills ?? []);
|
|
68
|
-
const tools = input.tools ?? [];
|
|
69
|
-
const catalogPrompt = [
|
|
70
|
-
"Runtime capability catalog:",
|
|
71
|
-
"The runtime has configured the following available subagents, skills, and raw tools for this agent.",
|
|
72
|
-
"Use the configured capability descriptions and upstream DeepAgents tool semantics to decide how to proceed.",
|
|
73
|
-
...(input.subagents.length > 0
|
|
74
|
-
? [
|
|
75
|
-
"",
|
|
76
|
-
"Available subagents for task delegation:",
|
|
77
|
-
...input.subagents.map(formatCapabilityLine),
|
|
78
|
-
]
|
|
79
|
-
: [
|
|
80
|
-
"",
|
|
81
|
-
"Available subagents for task delegation: none.",
|
|
82
|
-
]),
|
|
83
|
-
...(skills.length > 0
|
|
84
|
-
? [
|
|
85
|
-
"",
|
|
86
|
-
"Available skills for this agent:",
|
|
87
|
-
...skills.map(formatCapabilityLine),
|
|
88
|
-
]
|
|
89
|
-
: [
|
|
90
|
-
"",
|
|
91
|
-
"Available skills for this agent: none.",
|
|
92
|
-
]),
|
|
93
|
-
...(tools.length > 0
|
|
94
|
-
? [
|
|
95
|
-
"",
|
|
96
|
-
"Raw tools available to this agent:",
|
|
97
|
-
...tools.map(formatCapabilityLine),
|
|
98
|
-
]
|
|
99
|
-
: [
|
|
100
|
-
"",
|
|
101
|
-
"Raw tools available to this agent: none.",
|
|
102
|
-
]),
|
|
103
|
-
"",
|
|
104
|
-
].join("\n");
|
|
105
|
-
return appendRuntimeTemporalContext([basePrompt, catalogPrompt].filter((part) => typeof part === "string" && part.length > 0).join("\n\n"));
|
|
106
|
-
}
|
|
107
|
-
export const buildDeepAgentSystemPromptWithCapabilityHierarchy = buildDeepAgentSystemPromptWithCapabilityCatalog;
|
|
108
|
-
export const buildDeepAgentSystemPromptWithSubagentCatalog = buildDeepAgentSystemPromptWithCapabilityCatalog;
|
|
109
|
-
export function resolveRunnableCheckpointer(options, binding) {
|
|
110
|
-
return options.checkpointerResolver ? options.checkpointerResolver(binding) : new MemorySaver();
|
|
111
|
-
}
|
|
112
|
-
export function resolveRunnableInterruptOn(binding) {
|
|
113
|
-
return compileInterruptOn(getBindingPrimaryTools(binding), getBindingInterruptCompatibilityRules(binding));
|
|
114
|
-
}
|
|
115
|
-
function buildUpstreamCreateBaseParams(binding, supportedFields) {
|
|
116
|
-
const executionParams = getBindingExecutionParams(binding);
|
|
117
|
-
if (!executionParams) {
|
|
118
|
-
throw new Error(`Agent ${binding.agent.id} has no compiled execution params`);
|
|
119
|
-
}
|
|
120
|
-
const source = executionParams;
|
|
121
|
-
const upstreamParams = Object.fromEntries(supportedFields
|
|
122
|
-
.filter((key) => key in source && source[key] !== undefined)
|
|
123
|
-
.map((key) => [key, source[key]]));
|
|
124
|
-
return upstreamParams;
|
|
125
|
-
}
|
|
126
|
-
export function buildLangChainCreateParams(input) {
|
|
127
|
-
const executionKind = getBindingExecutionKind(input.binding);
|
|
128
|
-
const executionParams = getBindingExecutionParams(input.binding);
|
|
129
|
-
if (executionKind !== "langchain-v1" || !executionParams) {
|
|
130
|
-
throw new Error(`Agent ${input.binding.agent.id} has no langchain params`);
|
|
131
|
-
}
|
|
132
|
-
const upstreamParams = buildUpstreamCreateBaseParams(input.binding, [
|
|
133
|
-
"model",
|
|
134
|
-
"tools",
|
|
135
|
-
"systemPrompt",
|
|
136
|
-
"stateSchema",
|
|
137
|
-
"contextSchema",
|
|
138
|
-
"checkpointer",
|
|
139
|
-
"store",
|
|
140
|
-
"responseFormat",
|
|
141
|
-
"middleware",
|
|
142
|
-
"name",
|
|
143
|
-
"description",
|
|
144
|
-
"includeAgentName",
|
|
145
|
-
"version",
|
|
146
|
-
]);
|
|
147
|
-
const legacyPassthrough = typeof input.binding.langchainAgentParams?.passthrough === "object" &&
|
|
148
|
-
input.binding.langchainAgentParams?.passthrough
|
|
149
|
-
? input.binding.langchainAgentParams.passthrough
|
|
150
|
-
: undefined;
|
|
151
|
-
const langchainPassthrough = typeof input.binding.harnessRuntime.langchain?.passthrough === "object" && input.binding.harnessRuntime.langchain?.passthrough
|
|
152
|
-
? input.binding.harnessRuntime.langchain.passthrough
|
|
153
|
-
: undefined;
|
|
154
|
-
return {
|
|
155
|
-
...upstreamParams,
|
|
156
|
-
...(legacyPassthrough ?? {}),
|
|
157
|
-
...(langchainPassthrough ?? {}),
|
|
158
|
-
...(input.passthroughOverride ?? {}),
|
|
159
|
-
systemPrompt: appendRuntimeTemporalContext(input.systemPromptOverride ?? executionParams.systemPrompt),
|
|
160
|
-
model: input.resolvedModel,
|
|
161
|
-
tools: input.resolvedTools,
|
|
162
|
-
middleware: input.resolvedMiddleware,
|
|
163
|
-
checkpointer: input.resolvedCheckpointer,
|
|
164
|
-
store: input.resolvedStore,
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
export function resolveLangChainInvocationConfig(binding, options) {
|
|
168
|
-
const executionKind = getBindingExecutionKind(binding) ?? binding.agent.executionMode;
|
|
169
|
-
const runtimePassthrough = executionKind === "deepagent"
|
|
170
|
-
? binding.harnessRuntime.deepagent?.passthrough
|
|
171
|
-
: binding.harnessRuntime.langchain?.passthrough;
|
|
172
|
-
const langchainPassthrough = typeof runtimePassthrough === "object" && runtimePassthrough
|
|
173
|
-
? runtimePassthrough
|
|
174
|
-
: undefined;
|
|
175
|
-
const config = {
|
|
176
|
-
configurable: {
|
|
177
|
-
[UPSTREAM_SESSION_CONFIG_KEY]: options.sessionId,
|
|
178
|
-
[UPSTREAM_REQUEST_CONFIG_KEY]: options.requestId,
|
|
179
|
-
},
|
|
180
|
-
};
|
|
181
|
-
if (typeof langchainPassthrough?.recursionLimit === "number") {
|
|
182
|
-
config.recursionLimit = langchainPassthrough.recursionLimit;
|
|
183
|
-
}
|
|
184
|
-
else if (executionKind === "deepagent") {
|
|
185
|
-
config.recursionLimit = DEFAULT_DEEPAGENT_RECURSION_LIMIT;
|
|
186
|
-
}
|
|
187
|
-
if (options.context) {
|
|
188
|
-
config.context = options.context;
|
|
189
|
-
}
|
|
190
|
-
if (options.toolRuntimeContext) {
|
|
191
|
-
config.toolRuntimeContext = options.toolRuntimeContext;
|
|
192
|
-
}
|
|
193
|
-
return config;
|
|
194
|
-
}
|
|
195
|
-
export function buildDeepAgentCreateParams(input) {
|
|
196
|
-
const executionKind = getBindingExecutionKind(input.binding);
|
|
197
|
-
if (executionKind !== "deepagent" || !getBindingExecutionParams(input.binding)) {
|
|
198
|
-
throw new Error(`Agent ${input.binding.agent.id} has no runnable params`);
|
|
199
|
-
}
|
|
200
|
-
const upstreamParams = buildUpstreamCreateBaseParams(input.binding, [
|
|
201
|
-
"model",
|
|
202
|
-
"tools",
|
|
203
|
-
"systemPrompt",
|
|
204
|
-
"middleware",
|
|
205
|
-
"subagents",
|
|
206
|
-
"responseFormat",
|
|
207
|
-
"contextSchema",
|
|
208
|
-
"checkpointer",
|
|
209
|
-
"store",
|
|
210
|
-
"backend",
|
|
211
|
-
"interruptOn",
|
|
212
|
-
"name",
|
|
213
|
-
"memory",
|
|
214
|
-
"skills",
|
|
215
|
-
]);
|
|
216
|
-
return {
|
|
217
|
-
...upstreamParams,
|
|
218
|
-
systemPrompt: buildDeepAgentSystemPromptWithSubagentCatalog({
|
|
219
|
-
systemPrompt: upstreamParams.systemPrompt,
|
|
220
|
-
subagents: input.resolvedSubagents,
|
|
221
|
-
skills: input.resolvedSkills,
|
|
222
|
-
tools: getBindingPrimaryTools(input.binding),
|
|
223
|
-
}),
|
|
224
|
-
skills: input.resolvedSkills,
|
|
225
|
-
model: input.resolvedModel,
|
|
226
|
-
tools: input.resolvedTools,
|
|
227
|
-
middleware: input.resolvedMiddleware,
|
|
228
|
-
subagents: input.resolvedSubagents,
|
|
229
|
-
interruptOn: input.resolvedInterruptOn,
|
|
230
|
-
...(input.resolvedCheckpointer !== undefined ? { checkpointer: input.resolvedCheckpointer } : {}),
|
|
231
|
-
...(input.resolvedStore !== undefined ? { store: input.resolvedStore } : {}),
|
|
232
|
-
...(input.resolvedBackend !== undefined ? { backend: input.resolvedBackend } : {}),
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
export function shouldAttachDeepAgentCheckpointer(binding, resolvedInterruptOn) {
|
|
236
|
-
if (binding.harnessRuntime.checkpointer !== undefined) {
|
|
237
|
-
return true;
|
|
238
|
-
}
|
|
239
|
-
return resolvedInterruptOn !== undefined && Object.keys(resolvedInterruptOn).length > 0;
|
|
240
|
-
}
|
|
241
|
-
export function shouldAttachDeepAgentStore(binding) {
|
|
242
|
-
return getBindingStoreConfig(binding) !== undefined || getBindingMemorySources(binding).length > 0;
|
|
243
|
-
}
|
|
244
|
-
export function shouldAttachDeepAgentBackend(binding) {
|
|
245
|
-
return (getBindingBackendConfig(binding) !== undefined ||
|
|
246
|
-
getBindingMemorySources(binding).length > 0 ||
|
|
247
|
-
getBindingSkills(binding).length > 0 ||
|
|
248
|
-
(getBindingMiddlewareConfigs(binding)?.length ?? 0) > 0);
|
|
249
|
-
}
|
|
1
|
+
import{MemorySaver as h}from"@langchain/langgraph";import{UPSTREAM_REQUEST_CONFIG_KEY as p,UPSTREAM_SESSION_CONFIG_KEY as f}from"./adapter/upstream-configurable-keys.js";import{asStructuredExecutableTool as b}from"./adapter/tool/resolved-tool.js";import{compileInterruptOn as x}from"./adapter/tool/interrupt-policy.js";import{readSkillMetadata as v}from"./skills/skill-metadata.js";import{getBindingBackendConfig as y,getBindingExecutionKind as a,getBindingExecutionParams as i,getBindingInterruptCompatibilityRules as P,getBindingMemorySources as d,getBindingMiddlewareConfigs as S,getBindingPrimaryTools as c,getBindingSkills as E,getBindingStoreConfig as k}from"./support/compiled-binding.js";const B="__agent_harness_interrupt__:",A=100,C=new Set(["fetch_url","http_request","send_message","request_approval","schedule_task"]);function L(e){if(e.modelExposed===!1||e.modelExposed===void 0)return[];const t=new Set(e.explicitToolNames??[]),n=Array.isArray(e.modelExposed)?new Set(e.modelExposed):void 0,r=[];for(const[s,o]of e.builtinTools.entries())t.has(s)||!C.has(s)||n&&!n.has(s)||r.push(b(o,s,o.name));return r}function l(e){const t=typeof e.description=="string"&&e.description.length>0?`: ${e.description}`:"";return`- ${JSON.stringify(e.name)}${t}`}function R(e){return e.map(t=>{const n=v(t);return{name:n.name,...n.description?{description:n.description}:{}}})}function _(e=new Date){const t=Intl.DateTimeFormat().resolvedOptions().timeZone||"system local time";return["Runtime temporal context:",`- Current date/time: ${e.toISOString()}`,`- Local time zone: ${t}`,"Use the runtime date/time above as authoritative for interpreting current, latest, recent, today, tomorrow, yesterday, and tool-returned dates.","Do not reject tool evidence as future-dated solely because it is newer than the model's training data."].join(`
|
|
2
|
+
`)}function m(e){return[typeof e=="string"?e:void 0,_()].filter(t=>typeof t=="string"&&t.length>0).join(`
|
|
3
|
+
|
|
4
|
+
`)}function g(e){const t=typeof e.systemPrompt=="string"?e.systemPrompt:void 0,n=R(e.skills??[]),r=e.tools??[],s=["Runtime capability catalog:","The runtime has configured the following available subagents, skills, and raw tools for this agent.","Use the configured capability descriptions and upstream DeepAgents tool semantics to decide how to proceed.",...e.subagents.length>0?["","Available subagents for task delegation:",...e.subagents.map(l)]:["","Available subagents for task delegation: none."],...n.length>0?["","Available skills for this agent:",...n.map(l)]:["","Available skills for this agent: none."],...r.length>0?["","Raw tools available to this agent:",...r.map(l)]:["","Raw tools available to this agent: none."],""].join(`
|
|
5
|
+
`);return m([t,s].filter(o=>typeof o=="string"&&o.length>0).join(`
|
|
6
|
+
|
|
7
|
+
`))}const j=g,w=g;function U(e,t){return e.checkpointerResolver?e.checkpointerResolver(t):new h}function $(e){return x(c(e),P(e))}function u(e,t){const n=i(e);if(!n)throw new Error(`Agent ${e.agent.id} has no compiled execution params`);const r=n;return Object.fromEntries(t.filter(o=>o in r&&r[o]!==void 0).map(o=>[o,r[o]]))}function F(e){const t=a(e.binding),n=i(e.binding);if(t!=="langchain-v1"||!n)throw new Error(`Agent ${e.binding.agent.id} has no langchain params`);const r=u(e.binding,["model","tools","systemPrompt","stateSchema","contextSchema","checkpointer","store","responseFormat","middleware","name","description","includeAgentName","version"]),s=typeof e.binding.langchainAgentParams?.passthrough=="object"&&e.binding.langchainAgentParams?.passthrough?e.binding.langchainAgentParams.passthrough:void 0,o=typeof e.binding.harnessRuntime.langchain?.passthrough=="object"&&e.binding.harnessRuntime.langchain?.passthrough?e.binding.harnessRuntime.langchain.passthrough:void 0;return{...r,...s??{},...o??{},...e.passthroughOverride??{},systemPrompt:m(e.systemPromptOverride??n.systemPrompt),model:e.resolvedModel,tools:e.resolvedTools,middleware:e.resolvedMiddleware,checkpointer:e.resolvedCheckpointer,store:e.resolvedStore}}function K(e,t){const n=a(e)??e.agent.executionMode,r=n==="deepagent"?e.harnessRuntime.deepagent?.passthrough:e.harnessRuntime.langchain?.passthrough,s=typeof r=="object"&&r?r:void 0,o={configurable:{[f]:t.sessionId,[p]:t.requestId}};return typeof s?.recursionLimit=="number"?o.recursionLimit=s.recursionLimit:n==="deepagent"&&(o.recursionLimit=A),t.context&&(o.context=t.context),t.toolRuntimeContext&&(o.toolRuntimeContext=t.toolRuntimeContext),o}function G(e){if(a(e.binding)!=="deepagent"||!i(e.binding))throw new Error(`Agent ${e.binding.agent.id} has no runnable params`);const n=u(e.binding,["model","tools","systemPrompt","middleware","subagents","responseFormat","contextSchema","checkpointer","store","backend","interruptOn","name","memory","skills"]);return{...n,systemPrompt:w({systemPrompt:n.systemPrompt,subagents:e.resolvedSubagents,skills:e.resolvedSkills,tools:c(e.binding)}),skills:e.resolvedSkills,model:e.resolvedModel,tools:e.resolvedTools,middleware:e.resolvedMiddleware,subagents:e.resolvedSubagents,interruptOn:e.resolvedInterruptOn,...e.resolvedCheckpointer!==void 0?{checkpointer:e.resolvedCheckpointer}:{},...e.resolvedStore!==void 0?{store:e.resolvedStore}:{},...e.resolvedBackend!==void 0?{backend:e.resolvedBackend}:{}}}function W(e,t){return e.harnessRuntime.checkpointer!==void 0?!0:t!==void 0&&Object.keys(t).length>0}function q(e){return k(e)!==void 0||d(e).length>0}function z(e){return y(e)!==void 0||d(e).length>0||E(e).length>0||(S(e)?.length??0)>0}export{B as AGENT_INTERRUPT_SENTINEL_PREFIX,A as DEFAULT_DEEPAGENT_RECURSION_LIMIT,G as buildDeepAgentCreateParams,g as buildDeepAgentSystemPromptWithCapabilityCatalog,j as buildDeepAgentSystemPromptWithCapabilityHierarchy,w as buildDeepAgentSystemPromptWithSubagentCatalog,F as buildLangChainCreateParams,_ as buildRuntimeTemporalContext,L as materializeModelExposedBuiltinMiddlewareTools,K as resolveLangChainInvocationConfig,U as resolveRunnableCheckpointer,$ as resolveRunnableInterruptOn,z as shouldAttachDeepAgentBackend,W as shouldAttachDeepAgentCheckpointer,q as shouldAttachDeepAgentStore};
|
|
@@ -1,62 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { existsSync, readdirSync } from "node:fs";
|
|
4
|
-
const COMMON_EXECUTABLE_DIRS = [
|
|
5
|
-
"/opt/homebrew/bin",
|
|
6
|
-
"/opt/homebrew/sbin",
|
|
7
|
-
"/usr/local/bin",
|
|
8
|
-
"/usr/local/sbin",
|
|
9
|
-
"/usr/bin",
|
|
10
|
-
"/bin",
|
|
11
|
-
"/usr/sbin",
|
|
12
|
-
"/sbin",
|
|
13
|
-
];
|
|
14
|
-
function normalizeEnvRecord(env) {
|
|
15
|
-
return Object.fromEntries(Object.entries(env).filter((entry) => typeof entry[1] === "string"));
|
|
16
|
-
}
|
|
17
|
-
function splitPathEntries(pathValue) {
|
|
18
|
-
return (pathValue ?? "")
|
|
19
|
-
.split(path.delimiter)
|
|
20
|
-
.map((entry) => entry.trim())
|
|
21
|
-
.filter(Boolean);
|
|
22
|
-
}
|
|
23
|
-
function discoverNvmExecutableDirs(home) {
|
|
24
|
-
const versionsRoot = path.join(home, ".nvm", "versions", "node");
|
|
25
|
-
if (!existsSync(versionsRoot)) {
|
|
26
|
-
return [];
|
|
27
|
-
}
|
|
28
|
-
return readdirSync(versionsRoot, { withFileTypes: true })
|
|
29
|
-
.filter((entry) => entry.isDirectory())
|
|
30
|
-
.map((entry) => path.join(versionsRoot, entry.name, "bin"));
|
|
31
|
-
}
|
|
32
|
-
function defaultExecutableDirs(env) {
|
|
33
|
-
const home = env.HOME ?? env.USERPROFILE ?? homedir();
|
|
34
|
-
return [
|
|
35
|
-
...COMMON_EXECUTABLE_DIRS,
|
|
36
|
-
path.join(home, ".pyenv", "shims"),
|
|
37
|
-
path.join(home, ".asdf", "shims"),
|
|
38
|
-
...discoverNvmExecutableDirs(home),
|
|
39
|
-
];
|
|
40
|
-
}
|
|
41
|
-
export function augmentExecutablePath(pathValue, env = process.env) {
|
|
42
|
-
const deduped = new Set();
|
|
43
|
-
for (const entry of [...splitPathEntries(pathValue), ...defaultExecutableDirs(env)]) {
|
|
44
|
-
deduped.add(entry);
|
|
45
|
-
}
|
|
46
|
-
return Array.from(deduped).join(path.delimiter);
|
|
47
|
-
}
|
|
48
|
-
export function createRuntimeEnv(env, baseEnv = process.env) {
|
|
49
|
-
const base = normalizeEnvRecord(baseEnv);
|
|
50
|
-
const merged = {
|
|
51
|
-
...base,
|
|
52
|
-
...(env ?? {}),
|
|
53
|
-
};
|
|
54
|
-
const combinedPath = [base.PATH, env?.PATH].filter((value) => typeof value === "string").join(path.delimiter);
|
|
55
|
-
merged.PATH = augmentExecutablePath(combinedPath, { ...base, ...(env ?? {}) });
|
|
56
|
-
return merged;
|
|
57
|
-
}
|
|
58
|
-
export function normalizeProcessExecutablePath(env = process.env) {
|
|
59
|
-
const normalized = augmentExecutablePath(env.PATH, env);
|
|
60
|
-
env.PATH = normalized;
|
|
61
|
-
return normalized;
|
|
62
|
-
}
|
|
1
|
+
import{homedir as m}from"node:os";import n from"node:path";import{existsSync as u,readdirSync as a}from"node:fs";const f=["/opt/homebrew/bin","/opt/homebrew/sbin","/usr/local/bin","/usr/local/sbin","/usr/bin","/bin","/usr/sbin","/sbin"];function l(e){return Object.fromEntries(Object.entries(e).filter(r=>typeof r[1]=="string"))}function p(e){return(e??"").split(n.delimiter).map(r=>r.trim()).filter(Boolean)}function b(e){const r=n.join(e,".nvm","versions","node");return u(r)?a(r,{withFileTypes:!0}).filter(t=>t.isDirectory()).map(t=>n.join(r,t.name,"bin")):[]}function d(e){const r=e.HOME??e.USERPROFILE??m();return[...f,n.join(r,".pyenv","shims"),n.join(r,".asdf","shims"),...b(r)]}function o(e,r=process.env){const t=new Set;for(const i of[...p(e),...d(r)])t.add(i);return Array.from(t).join(n.delimiter)}function y(e,r=process.env){const t=l(r),i={...t,...e??{}},s=[t.PATH,e?.PATH].filter(c=>typeof c=="string").join(n.delimiter);return i.PATH=o(s,{...t,...e??{}}),i}function j(e=process.env){const r=o(e.PATH,e);return e.PATH=r,r}export{o as augmentExecutablePath,y as createRuntimeEnv,j as normalizeProcessExecutablePath};
|
|
@@ -1,8 +1 @@
|
|
|
1
|
-
|
|
2
|
-
return {
|
|
3
|
-
persistence: input.persistence,
|
|
4
|
-
publishEvent: input.publishEvent,
|
|
5
|
-
trackBackgroundTask: input.trackBackgroundTask,
|
|
6
|
-
backgroundEventTypes: input.backgroundEventTypes,
|
|
7
|
-
};
|
|
8
|
-
}
|
|
1
|
+
function n(e){return{persistence:e.persistence,publishEvent:e.publishEvent,trackBackgroundTask:e.trackBackgroundTask,backgroundEventTypes:e.backgroundEventTypes}}export{n as createBackgroundEventRuntime};
|
|
@@ -1,58 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { toolRequiresRuntimeApproval } from "../adapter/tool/tool-hitl.js";
|
|
3
|
-
import { getBindingPrimaryTools } from "../support/compiled-binding.js";
|
|
4
|
-
import { compiledToolHasInputSchema } from "./tool-schema.js";
|
|
5
|
-
import { projectBindingToolGatewayPolicy } from "./tool-gateway/index.js";
|
|
6
|
-
export function getWorkspaceBinding(workspace, agentId) {
|
|
7
|
-
return workspace.bindings.get(agentId);
|
|
8
|
-
}
|
|
9
|
-
export function getRequiredWorkspaceBinding(workspace, agentId) {
|
|
10
|
-
const binding = getWorkspaceBinding(workspace, agentId);
|
|
11
|
-
if (!binding) {
|
|
12
|
-
throw new Error(`Unknown agent ${agentId}`);
|
|
13
|
-
}
|
|
14
|
-
return binding;
|
|
15
|
-
}
|
|
16
|
-
export function resolveWorkspaceAgentTools(input) {
|
|
17
|
-
const binding = getRequiredWorkspaceBinding(input.workspace, input.agentId);
|
|
18
|
-
const compiledTools = getBindingPrimaryTools(binding);
|
|
19
|
-
const resolvedTools = input.toolResolver ? input.toolResolver(compiledTools.map((tool) => tool.id), binding) : [];
|
|
20
|
-
return compiledTools.map((compiledTool, index) => ({
|
|
21
|
-
compiledTool,
|
|
22
|
-
resolvedTool: resolvedTools[index],
|
|
23
|
-
}));
|
|
24
|
-
}
|
|
25
|
-
export function bindingSupportsRunningReplay(binding) {
|
|
26
|
-
return getBindingPrimaryTools(binding).every((tool) => tool.retryable === true);
|
|
27
|
-
}
|
|
28
|
-
export function projectBindingToolExecutionPolicy(binding) {
|
|
29
|
-
const tools = getBindingPrimaryTools(binding);
|
|
30
|
-
const projectedTools = tools.map((tool) => ({
|
|
31
|
-
toolId: tool.id,
|
|
32
|
-
name: tool.name,
|
|
33
|
-
retryable: tool.retryable === true,
|
|
34
|
-
hasInputSchema: compiledToolHasInputSchema(tool),
|
|
35
|
-
requiresApproval: toolRequiresRuntimeApproval(tool),
|
|
36
|
-
}));
|
|
37
|
-
const retryableToolCount = projectedTools.filter((tool) => tool.retryable).length;
|
|
38
|
-
return {
|
|
39
|
-
agentId: binding.agent.id,
|
|
40
|
-
gateway: projectBindingToolGatewayPolicy(binding),
|
|
41
|
-
invokeTimeoutMs: resolveBindingTimeout(binding),
|
|
42
|
-
streamIdleTimeoutMs: resolveStreamIdleTimeout(binding) ?? 60_000,
|
|
43
|
-
providerRetries: resolveProviderRetryPolicy(binding),
|
|
44
|
-
validation: {
|
|
45
|
-
schemaBoundToolCount: projectedTools.filter((tool) => tool.hasInputSchema).length,
|
|
46
|
-
allToolsHaveSchemas: projectedTools.length > 0 && projectedTools.every((tool) => tool.hasInputSchema),
|
|
47
|
-
},
|
|
48
|
-
idempotencyHints: {
|
|
49
|
-
replayEligible: bindingSupportsRunningReplay(binding),
|
|
50
|
-
retryableToolCount,
|
|
51
|
-
nonRetryableToolCount: projectedTools.length - retryableToolCount,
|
|
52
|
-
},
|
|
53
|
-
tools: projectedTools,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
export function projectWorkspaceAgentToolExecutionPolicy(input) {
|
|
57
|
-
return projectBindingToolExecutionPolicy(getRequiredWorkspaceBinding(input.workspace, input.agentId));
|
|
58
|
-
}
|
|
1
|
+
import{resolveBindingTimeout as s,resolveProviderRetryPolicy as c,resolveStreamIdleTimeout as p}from"../adapter/resilience.js";import{toolRequiresRuntimeApproval as m}from"../adapter/tool/tool-hitl.js";import{getBindingPrimaryTools as l}from"../support/compiled-binding.js";import{compiledToolHasInputSchema as u}from"./tool-schema.js";import{projectBindingToolGatewayPolicy as d}from"./tool-gateway/index.js";function g(e,t){return e.bindings.get(t)}function i(e,t){const r=g(e,t);if(!r)throw new Error(`Unknown agent ${t}`);return r}function k(e){const t=i(e.workspace,e.agentId),r=l(t),n=e.toolResolver?e.toolResolver(r.map(o=>o.id),t):[];return r.map((o,a)=>({compiledTool:o,resolvedTool:n[a]}))}function y(e){return l(e).every(t=>t.retryable===!0)}function T(e){const r=l(e).map(o=>({toolId:o.id,name:o.name,retryable:o.retryable===!0,hasInputSchema:u(o),requiresApproval:m(o)})),n=r.filter(o=>o.retryable).length;return{agentId:e.agent.id,gateway:d(e),invokeTimeoutMs:s(e),streamIdleTimeoutMs:p(e)??6e4,providerRetries:c(e),validation:{schemaBoundToolCount:r.filter(o=>o.hasInputSchema).length,allToolsHaveSchemas:r.length>0&&r.every(o=>o.hasInputSchema)},idempotencyHints:{replayEligible:y(e),retryableToolCount:n,nonRetryableToolCount:r.length-n},tools:r}}function x(e){return T(i(e.workspace,e.agentId))}export{y as bindingSupportsRunningReplay,i as getRequiredWorkspaceBinding,g as getWorkspaceBinding,T as projectBindingToolExecutionPolicy,x as projectWorkspaceAgentToolExecutionPolicy,k as resolveWorkspaceAgentTools};
|
|
@@ -1,16 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
export class EventBus {
|
|
3
|
-
sink = createRuntimeEventSink();
|
|
4
|
-
publish(event) {
|
|
5
|
-
this.sink.publish(event);
|
|
6
|
-
}
|
|
7
|
-
subscribe(listener) {
|
|
8
|
-
return this.sink.subscribe(listener);
|
|
9
|
-
}
|
|
10
|
-
registerProjection(projection) {
|
|
11
|
-
return this.sink.registerProjection(projection);
|
|
12
|
-
}
|
|
13
|
-
async drain() {
|
|
14
|
-
await this.sink.drain();
|
|
15
|
-
}
|
|
16
|
-
}
|
|
1
|
+
import{createRuntimeEventSink as s}from"./event-sink.js";class e{sink=s();publish(i){this.sink.publish(i)}subscribe(i){return this.sink.subscribe(i)}registerProjection(i){return this.sink.registerProjection(i)}async drain(){await this.sink.drain()}}export{e as EventBus};
|
|
@@ -1,61 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { getEventSubscribers } from "../../../tooling/extensions.js";
|
|
3
|
-
const EVENT_PROJECTION_DRAIN_TIMEOUT_MS = 1_000;
|
|
4
|
-
function dispatchListener(listener, event) {
|
|
5
|
-
void Promise.resolve(listener(event));
|
|
6
|
-
}
|
|
7
|
-
export class RuntimeEventSinkImpl {
|
|
8
|
-
emitter = new EventEmitter();
|
|
9
|
-
projections = new Set();
|
|
10
|
-
inflightProjectionTasks = new Set();
|
|
11
|
-
trackProjectionTask(task) {
|
|
12
|
-
this.inflightProjectionTasks.add(task);
|
|
13
|
-
void task.finally(() => {
|
|
14
|
-
this.inflightProjectionTasks.delete(task);
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
publish(event) {
|
|
18
|
-
this.emitter.emit("event", event);
|
|
19
|
-
for (const projection of this.projections) {
|
|
20
|
-
if (projection.shouldHandle && !projection.shouldHandle(event)) {
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
this.trackProjectionTask(Promise.resolve(projection.handleEvent(event)));
|
|
24
|
-
}
|
|
25
|
-
for (const subscriber of getEventSubscribers()) {
|
|
26
|
-
dispatchListener(subscriber.onEvent, event);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
subscribe(listener) {
|
|
30
|
-
this.emitter.on("event", listener);
|
|
31
|
-
return () => this.emitter.off("event", listener);
|
|
32
|
-
}
|
|
33
|
-
registerProjection(projection) {
|
|
34
|
-
this.projections.add(projection);
|
|
35
|
-
return () => this.projections.delete(projection);
|
|
36
|
-
}
|
|
37
|
-
async drain() {
|
|
38
|
-
let timeoutHandle;
|
|
39
|
-
try {
|
|
40
|
-
await Promise.race([
|
|
41
|
-
(async () => {
|
|
42
|
-
while (this.inflightProjectionTasks.size > 0) {
|
|
43
|
-
await Promise.allSettled(Array.from(this.inflightProjectionTasks));
|
|
44
|
-
}
|
|
45
|
-
})(),
|
|
46
|
-
new Promise((resolve) => {
|
|
47
|
-
timeoutHandle = setTimeout(resolve, EVENT_PROJECTION_DRAIN_TIMEOUT_MS);
|
|
48
|
-
timeoutHandle.unref?.();
|
|
49
|
-
}),
|
|
50
|
-
]);
|
|
51
|
-
}
|
|
52
|
-
finally {
|
|
53
|
-
if (timeoutHandle) {
|
|
54
|
-
clearTimeout(timeoutHandle);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
export function createRuntimeEventSink() {
|
|
60
|
-
return new RuntimeEventSinkImpl();
|
|
61
|
-
}
|
|
1
|
+
import{EventEmitter as o}from"node:events";import{getEventSubscribers as n}from"../../../tooling/extensions.js";const r=1e3;function s(i,e){Promise.resolve(i(e))}class c{emitter=new o;projections=new Set;inflightProjectionTasks=new Set;trackProjectionTask(e){this.inflightProjectionTasks.add(e),e.finally(()=>{this.inflightProjectionTasks.delete(e)})}publish(e){this.emitter.emit("event",e);for(const t of this.projections)t.shouldHandle&&!t.shouldHandle(e)||this.trackProjectionTask(Promise.resolve(t.handleEvent(e)));for(const t of n())s(t.onEvent,e)}subscribe(e){return this.emitter.on("event",e),()=>this.emitter.off("event",e)}registerProjection(e){return this.projections.add(e),()=>this.projections.delete(e)}async drain(){let e;try{await Promise.race([(async()=>{for(;this.inflightProjectionTasks.size>0;)await Promise.allSettled(Array.from(this.inflightProjectionTasks))})(),new Promise(t=>{e=setTimeout(t,r),e.unref?.()})])}finally{e&&clearTimeout(e)}}}function h(){return new c}export{c as RuntimeEventSinkImpl,h as createRuntimeEventSink};
|
|
@@ -1,80 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { createHarnessEvent, createPendingApproval } from "../../support/harness-support.js";
|
|
3
|
-
async function updateInspection(persistence, sessionId, requestId, patch) {
|
|
4
|
-
await persistence.updateRequestInspection(sessionId, requestId, patch);
|
|
5
|
-
}
|
|
6
|
-
async function setRequestState(persistence, sessionId, requestId, state, checkpointRef) {
|
|
7
|
-
await persistence.setRequestState(sessionId, requestId, state, checkpointRef);
|
|
8
|
-
}
|
|
9
|
-
export async function emitHarnessEvent(runtime, sessionId, requestId, sequence, eventType, payload, source = "runtime") {
|
|
10
|
-
const event = createHarnessEvent(sessionId, requestId, sequence, eventType, payload, source);
|
|
11
|
-
if (runtime.backgroundEventTypes.has(event.eventType)) {
|
|
12
|
-
runtime.trackBackgroundTask(runtime.persistence.appendEvent(event).catch(() => {
|
|
13
|
-
// Fail open for telemetry-style event persistence.
|
|
14
|
-
}));
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
await runtime.persistence.appendEvent(event);
|
|
18
|
-
}
|
|
19
|
-
runtime.publishEvent(event);
|
|
20
|
-
return event;
|
|
21
|
-
}
|
|
22
|
-
export async function emitRequestCreatedEvent(runtime, sessionId, requestId, payload) {
|
|
23
|
-
return emitHarnessEvent(runtime, sessionId, requestId, 1, "request.created", payload);
|
|
24
|
-
}
|
|
25
|
-
export async function setRequestStateAndEmitEvent(runtime, sessionId, requestId, sequence, state, options) {
|
|
26
|
-
await setRequestState(runtime.persistence, sessionId, requestId, state, options.checkpointRef ?? null);
|
|
27
|
-
const now = new Date(Date.now()).toISOString();
|
|
28
|
-
await updateInspection(runtime.persistence, sessionId, requestId, {
|
|
29
|
-
lastActivityAt: now,
|
|
30
|
-
...(state === "completed" || state === "failed" || state === "cancelled" ? { endedAt: now } : {}),
|
|
31
|
-
});
|
|
32
|
-
return emitHarnessEvent(runtime, sessionId, requestId, sequence, "request.state.changed", {
|
|
33
|
-
previousState: options.previousState,
|
|
34
|
-
state,
|
|
35
|
-
checkpointRef: options.checkpointRef ?? null,
|
|
36
|
-
...(options.error ? { error: options.error } : {}),
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
export async function persistApproval(runtime, sessionId, requestId, checkpointRef, input, interruptContent) {
|
|
40
|
-
const approval = createPendingApproval(sessionId, requestId, checkpointRef, extractMessageText(input), interruptContent);
|
|
41
|
-
await runtime.persistence.createApproval(approval);
|
|
42
|
-
const artifact = await runtime.persistence.createRequestArtifact(sessionId, requestId, {
|
|
43
|
-
artifactId: `artifact-approval-${requestId}`,
|
|
44
|
-
kind: "approval-packet",
|
|
45
|
-
path: `artifacts/approval-${requestId}.json`,
|
|
46
|
-
createdAt: approval.requestedAt,
|
|
47
|
-
}, approval);
|
|
48
|
-
await emitHarnessEvent(runtime, sessionId, requestId, 5, "artifact.created", {
|
|
49
|
-
artifactId: artifact.artifactId,
|
|
50
|
-
kind: artifact.kind,
|
|
51
|
-
path: artifact.path,
|
|
52
|
-
});
|
|
53
|
-
return approval;
|
|
54
|
-
}
|
|
55
|
-
export async function requestApprovalAndEmitEvent(runtime, sessionId, requestId, input, interruptContent, checkpointRef, sequence) {
|
|
56
|
-
const approval = await persistApproval(runtime, sessionId, requestId, checkpointRef, input, interruptContent);
|
|
57
|
-
const event = await emitHarnessEvent(runtime, sessionId, requestId, sequence, "approval.requested", {
|
|
58
|
-
approvalId: approval.approvalId,
|
|
59
|
-
pendingActionId: approval.pendingActionId,
|
|
60
|
-
toolName: approval.toolName,
|
|
61
|
-
toolCallId: approval.toolCallId,
|
|
62
|
-
allowedDecisions: approval.allowedDecisions,
|
|
63
|
-
checkpointRef,
|
|
64
|
-
});
|
|
65
|
-
return { approval, event };
|
|
66
|
-
}
|
|
67
|
-
export async function emitSyntheticFallbackEvent(runtime, sessionId, requestId, selectedAgentId, error, sequence = 3) {
|
|
68
|
-
const payload = typeof error === "object" && error !== null && "reason" in error
|
|
69
|
-
? {
|
|
70
|
-
...error,
|
|
71
|
-
selectedAgentId,
|
|
72
|
-
}
|
|
73
|
-
: {
|
|
74
|
-
reason: error instanceof Error ? error.message : String(error),
|
|
75
|
-
selectedAgentId,
|
|
76
|
-
};
|
|
77
|
-
await emitHarnessEvent(runtime, sessionId, requestId, sequence, "runtime.synthetic_fallback", {
|
|
78
|
-
...payload,
|
|
79
|
-
});
|
|
80
|
-
}
|
|
1
|
+
import{extractMessageText as s}from"../../../utils/message-content.js";import{createHarnessEvent as v,createPendingApproval as f}from"../../support/harness-support.js";async function d(t,n,a,c){await t.updateRequestInspection(n,a,c)}async function u(t,n,a,c,e){await t.setRequestState(n,a,c,e)}async function r(t,n,a,c,e,o,i="runtime"){const p=v(n,a,c,e,o,i);return t.backgroundEventTypes.has(p.eventType)?t.trackBackgroundTask(t.persistence.appendEvent(p).catch(()=>{})):await t.persistence.appendEvent(p),t.publishEvent(p),p}async function E(t,n,a,c){return r(t,n,a,1,"request.created",c)}async function k(t,n,a,c,e,o){await u(t.persistence,n,a,e,o.checkpointRef??null);const i=new Date(Date.now()).toISOString();return await d(t.persistence,n,a,{lastActivityAt:i,...e==="completed"||e==="failed"||e==="cancelled"?{endedAt:i}:{}}),r(t,n,a,c,"request.state.changed",{previousState:o.previousState,state:e,checkpointRef:o.checkpointRef??null,...o.error?{error:o.error}:{}})}async function w(t,n,a,c,e,o){const i=f(n,a,c,s(e),o);await t.persistence.createApproval(i);const p=await t.persistence.createRequestArtifact(n,a,{artifactId:`artifact-approval-${a}`,kind:"approval-packet",path:`artifacts/approval-${a}.json`,createdAt:i.requestedAt},i);return await r(t,n,a,5,"artifact.created",{artifactId:p.artifactId,kind:p.kind,path:p.path}),i}async function h(t,n,a,c,e,o,i){const p=await w(t,n,a,o,c,e),l=await r(t,n,a,i,"approval.requested",{approvalId:p.approvalId,pendingActionId:p.pendingActionId,toolName:p.toolName,toolCallId:p.toolCallId,allowedDecisions:p.allowedDecisions,checkpointRef:o});return{approval:p,event:l}}async function g(t,n,a,c,e,o=3){const i=typeof e=="object"&&e!==null&&"reason"in e?{...e,selectedAgentId:c}:{reason:e instanceof Error?e.message:String(e),selectedAgentId:c};await r(t,n,a,o,"runtime.synthetic_fallback",{...i})}export{r as emitHarnessEvent,E as emitRequestCreatedEvent,g as emitSyntheticFallbackEvent,w as persistApproval,h as requestApprovalAndEmitEvent,k as setRequestStateAndEmitEvent};
|
|
@@ -1,13 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
export function createListenerDispatchRuntime(input) {
|
|
3
|
-
return {
|
|
4
|
-
dispatchRequestListeners: (stream, listeners) => dispatchStreamingRequestListeners(stream, listeners, {
|
|
5
|
-
notifyListener: (listener, value) => input.notifyListener(listener, value),
|
|
6
|
-
getSession: (sessionId) => input.getSession(sessionId),
|
|
7
|
-
}),
|
|
8
|
-
dispatchRunListeners: (stream, listeners) => dispatchStreamingRequestListeners(stream, listeners, {
|
|
9
|
-
notifyListener: (listener, value) => input.notifyListener(listener, value),
|
|
10
|
-
getSession: (sessionId) => input.getSession(sessionId),
|
|
11
|
-
}),
|
|
12
|
-
};
|
|
13
|
-
}
|
|
1
|
+
import{dispatchRequestListeners as r}from"./streaming.js";function L(s){return{dispatchRequestListeners:(t,i)=>r(t,i,{notifyListener:(e,n)=>s.notifyListener(e,n),getSession:e=>s.getSession(e)}),dispatchRunListeners:(t,i)=>r(t,i,{notifyListener:(e,n)=>s.notifyListener(e,n),getSession:e=>s.getSession(e)})}}export{L as createListenerDispatchRuntime};
|
|
@@ -1,9 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
export function createRuntimeEventOperations(runtime) {
|
|
3
|
-
return {
|
|
4
|
-
emitRequestCreated: (sessionId, requestId, payload) => emitRequestCreatedEvent(runtime, sessionId, requestId, payload),
|
|
5
|
-
setRequestStateAndEmit: (sessionId, requestId, sequence, state, options) => setRequestStateAndEmitEvent(runtime, sessionId, requestId, sequence, state, options),
|
|
6
|
-
requestApprovalAndEmit: (sessionId, requestId, input, interruptContent, checkpointRef, sequence) => requestApprovalAndEmitEvent(runtime, sessionId, requestId, input, interruptContent, checkpointRef, sequence),
|
|
7
|
-
emitSyntheticFallback: (sessionId, requestId, selectedAgentId, error, sequence) => emitSyntheticFallbackEvent(runtime, sessionId, requestId, selectedAgentId, error, sequence),
|
|
8
|
-
};
|
|
9
|
-
}
|
|
1
|
+
import{emitRequestCreatedEvent as E,emitSyntheticFallbackEvent as m,requestApprovalAndEmitEvent as o,setRequestStateAndEmitEvent as p}from"./events.js";function c(r){return{emitRequestCreated:(t,e,n)=>E(r,t,e,n),setRequestStateAndEmit:(t,e,n,a,i)=>p(r,t,e,n,a,i),requestApprovalAndEmit:(t,e,n,a,i,s)=>o(r,t,e,n,a,i,s),emitSyntheticFallback:(t,e,n,a,i)=>m(r,t,e,n,a,i)}}export{c as createRuntimeEventOperations};
|