@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,213 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
function collectRequestMessages(request) {
|
|
5
|
-
if (typeof request !== "object" || !request || Array.isArray(request)) {
|
|
6
|
-
return [];
|
|
7
|
-
}
|
|
8
|
-
const typed = request;
|
|
9
|
-
return Array.isArray(typed.messages)
|
|
10
|
-
? typed.messages.filter((message) => typeof message === "object" && !!message && !Array.isArray(message))
|
|
11
|
-
: [];
|
|
12
|
-
}
|
|
13
|
-
function readMessageRole(message) {
|
|
14
|
-
return typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
|
|
15
|
-
}
|
|
16
|
-
function readLatestUserRequestText(request) {
|
|
17
|
-
const messages = collectRequestMessages(request);
|
|
18
|
-
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
19
|
-
const message = messages[index];
|
|
20
|
-
if (readMessageRole(message) !== "user") {
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
const content = readTextContent(message.content).trim();
|
|
24
|
-
if (content) {
|
|
25
|
-
return content;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return "";
|
|
29
|
-
}
|
|
30
|
-
function readSystemInstructionText(request) {
|
|
31
|
-
return collectRequestMessages(request)
|
|
32
|
-
.filter((message) => readMessageRole(message) === "system")
|
|
33
|
-
.map((message) => readTextContent(message.content).trim())
|
|
34
|
-
.filter(Boolean)
|
|
35
|
-
.join("\n\n");
|
|
36
|
-
}
|
|
37
|
-
function isToolCallParseFailure(error) {
|
|
38
|
-
return error instanceof Error && /error parsing tool call:/i.test(error.message);
|
|
39
|
-
}
|
|
40
|
-
function isStructuredValidationIssue(value) {
|
|
41
|
-
if (typeof value !== "object" || !value || Array.isArray(value))
|
|
42
|
-
return false;
|
|
43
|
-
const typed = value;
|
|
44
|
-
return typeof typed.code === "string" && Array.isArray(typed.path) && (typed.message === undefined || typeof typed.message === "string");
|
|
45
|
-
}
|
|
46
|
-
export function isToolCallValidationFailure(error) {
|
|
47
|
-
if (!(error instanceof Error))
|
|
48
|
-
return false;
|
|
49
|
-
const message = error.message.trim();
|
|
50
|
-
if (!message)
|
|
51
|
-
return false;
|
|
52
|
-
try {
|
|
53
|
-
const direct = JSON.parse(message);
|
|
54
|
-
if (Array.isArray(direct) && direct.length > 0 && direct.every((issue) => isStructuredValidationIssue(issue) && issue.path.length > 0)) {
|
|
55
|
-
return true;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
catch { }
|
|
59
|
-
if (/Invalid input:\s*expected .* received undefined/i.test(message) && /"path"\s*:\s*\[/.test(message)) {
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
return /Received tool input did not match expected schema/i.test(message)
|
|
63
|
-
&& (/(?:→\s*at|at)\s+[\w[\].]+/i.test(message) || /\bDetails:/i.test(message));
|
|
64
|
-
}
|
|
65
|
-
function collectErrorMessages(error) {
|
|
66
|
-
if (!error)
|
|
67
|
-
return [];
|
|
68
|
-
if (error instanceof Error) {
|
|
69
|
-
const nested = Array.isArray(error.errors)
|
|
70
|
-
? (error.errors ?? []).flatMap((item) => collectErrorMessages(item))
|
|
71
|
-
: [];
|
|
72
|
-
return [error.message, ...nested].filter((value) => typeof value === "string" && value.trim().length > 0);
|
|
73
|
-
}
|
|
74
|
-
if (typeof error === "string" && error.trim().length > 0)
|
|
75
|
-
return [error];
|
|
76
|
-
if (typeof error === "object") {
|
|
77
|
-
const record = error;
|
|
78
|
-
return [record.message, record.error, record.details].flatMap((item) => collectErrorMessages(item));
|
|
79
|
-
}
|
|
80
|
-
return [];
|
|
81
|
-
}
|
|
82
|
-
export function isWorkspacePathScopeFailure(error) {
|
|
83
|
-
return collectErrorMessages(error).some((message) => /outside the workspace root|workspace-relative path/i.test(message));
|
|
84
|
-
}
|
|
85
|
-
export function isInternalRuntimeSpillPathFailure(error) {
|
|
86
|
-
return collectErrorMessages(error).some((message) => /\/large_tool_results\/|internal runtime spill path/i.test(message));
|
|
87
|
-
}
|
|
88
|
-
export function isRepairableWriteTodosContentFailure(error) {
|
|
89
|
-
return error instanceof Error && /write_todos/i.test(error.message) && /todos\[\d+\]\.content/i.test(error.message);
|
|
90
|
-
}
|
|
91
|
-
export function isRepairableWriteTodosEmptyFailure(error) {
|
|
92
|
-
return error instanceof Error && /write_todos/i.test(error.message) && /Initial write_todos call cannot use an empty todo list/i.test(error.message);
|
|
93
|
-
}
|
|
94
|
-
export function isToolCallRecoveryFailure(error) {
|
|
95
|
-
return (isToolCallParseFailure(error) ||
|
|
96
|
-
isToolCallValidationFailure(error) ||
|
|
97
|
-
isRepairableWriteTodosEmptyFailure(error) ||
|
|
98
|
-
isInternalRuntimeSpillPathFailure(error) ||
|
|
99
|
-
isWorkspacePathScopeFailure(error));
|
|
100
|
-
}
|
|
101
|
-
export function isRetrySafeInvalidToolSelectionError(value) {
|
|
102
|
-
const text = readTextContent(value).trim();
|
|
103
|
-
return !!text && /is not a valid tool, try one of \[/i.test(text);
|
|
104
|
-
}
|
|
105
|
-
export function shouldValidateExecutionWithoutToolEvidence(request) {
|
|
106
|
-
const userText = readLatestUserRequestText(request);
|
|
107
|
-
if (userText) {
|
|
108
|
-
return true;
|
|
109
|
-
}
|
|
110
|
-
return readSystemInstructionText(request).length > 0;
|
|
111
|
-
}
|
|
112
|
-
export function resolveMissingPlanRecoveryInstruction(params) {
|
|
113
|
-
const hasPlanEvidence = params.hasWriteTodosEvidence === true
|
|
114
|
-
|| params.hasPlanStateEvidence === true;
|
|
115
|
-
if (params.requiresPlan !== true || hasPlanEvidence) {
|
|
116
|
-
return null;
|
|
117
|
-
}
|
|
118
|
-
return WRITE_TODOS_REQUIRED_PLAN_INSTRUCTION;
|
|
119
|
-
}
|
|
120
|
-
export function resolveExecutionWithoutToolEvidenceInstruction(request, result) {
|
|
121
|
-
const assistantText = readTextContent(result).trim();
|
|
122
|
-
return resolveExecutionWithoutToolEvidenceTextInstruction(request, assistantText, false, {});
|
|
123
|
-
}
|
|
124
|
-
export function resolveExecutionWithoutToolEvidenceTextInstruction(request, assistantText, toolCallEvidence = false, resultEvidence = {}) {
|
|
125
|
-
if (!shouldValidateExecutionWithoutToolEvidence(request)) {
|
|
126
|
-
return null;
|
|
127
|
-
}
|
|
128
|
-
const normalizedText = assistantText.trim();
|
|
129
|
-
const missingPlanRecoveryInstruction = resolveMissingPlanRecoveryInstruction({
|
|
130
|
-
request,
|
|
131
|
-
assistantText: normalizedText,
|
|
132
|
-
requiresPlan: resultEvidence.requiresPlan,
|
|
133
|
-
hasWriteTodosEvidence: resultEvidence.hasWriteTodosEvidence,
|
|
134
|
-
hasPlanStateEvidence: resultEvidence.hasIncompletePlanState === true || resultEvidence.hasPlanStateEvidence === true,
|
|
135
|
-
hasToolResultEvidence: resultEvidence.hasToolResultEvidence,
|
|
136
|
-
});
|
|
137
|
-
if (missingPlanRecoveryInstruction) {
|
|
138
|
-
return missingPlanRecoveryInstruction;
|
|
139
|
-
}
|
|
140
|
-
const hasUnfinishedExecution = resultEvidence.hasIncompletePlanState === true
|
|
141
|
-
|| resultEvidence.hasOpenTaskDelegation === true
|
|
142
|
-
|| resultEvidence.hasMissingDelegatedExecutionEvidence === true;
|
|
143
|
-
if (salvageJsonToolCalls(normalizedText).length > 0) {
|
|
144
|
-
return STRICT_TOOL_JSON_INSTRUCTION;
|
|
145
|
-
}
|
|
146
|
-
const hasExecutionEvidence = toolCallEvidence
|
|
147
|
-
|| resultEvidence.hasWriteTodosEvidence === true
|
|
148
|
-
|| resultEvidence.hasToolResultEvidence === true;
|
|
149
|
-
if (!normalizedText || !hasUnfinishedExecution) {
|
|
150
|
-
return null;
|
|
151
|
-
}
|
|
152
|
-
return hasExecutionEvidence ? REQUIRED_EXECUTION_CONTINUATION_INSTRUCTION : null;
|
|
153
|
-
}
|
|
154
|
-
export function resolveToolCallRecoveryInstruction(error) {
|
|
155
|
-
if (isRepairableWriteTodosEmptyFailure(error))
|
|
156
|
-
return WRITE_TODOS_NON_EMPTY_INITIAL_LIST_INSTRUCTION;
|
|
157
|
-
if (isRepairableWriteTodosContentFailure(error))
|
|
158
|
-
return WRITE_TODOS_FULL_ENTRY_INSTRUCTION;
|
|
159
|
-
if (isInternalRuntimeSpillPathFailure(error))
|
|
160
|
-
return INTERNAL_RUNTIME_SPILL_PATH_INSTRUCTION;
|
|
161
|
-
if (isWorkspacePathScopeFailure(error))
|
|
162
|
-
return WORKSPACE_RELATIVE_PATH_INSTRUCTION;
|
|
163
|
-
if (isToolCallRecoveryFailure(error))
|
|
164
|
-
return STRICT_TOOL_JSON_INSTRUCTION;
|
|
165
|
-
return null;
|
|
166
|
-
}
|
|
167
|
-
export function appendToolRecoveryInstruction(input, instruction) {
|
|
168
|
-
if (Array.isArray(input)) {
|
|
169
|
-
return [...input, { role: "system", content: instruction }];
|
|
170
|
-
}
|
|
171
|
-
if (typeof input === "object" && input && Array.isArray(input.messages)) {
|
|
172
|
-
return {
|
|
173
|
-
...input,
|
|
174
|
-
messages: [...(input.messages), { role: "system", content: instruction }],
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
return input;
|
|
178
|
-
}
|
|
179
|
-
export function wrapResolvedModel(value) {
|
|
180
|
-
if (typeof value !== "object" || value === null)
|
|
181
|
-
return value;
|
|
182
|
-
const target = value;
|
|
183
|
-
return new Proxy(target, {
|
|
184
|
-
get(currentTarget, prop, receiver) {
|
|
185
|
-
const member = Reflect.get(currentTarget, prop, receiver);
|
|
186
|
-
if (prop === "invoke" && typeof member === "function") {
|
|
187
|
-
return async (...args) => {
|
|
188
|
-
let activeArgs = [...args];
|
|
189
|
-
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
190
|
-
try {
|
|
191
|
-
return wrapNormalizedMessage(await member.apply(currentTarget, activeArgs));
|
|
192
|
-
}
|
|
193
|
-
catch (error) {
|
|
194
|
-
const recoveryInstruction = resolveToolCallRecoveryInstruction(error);
|
|
195
|
-
if (!recoveryInstruction || attempt === 2) {
|
|
196
|
-
throw error;
|
|
197
|
-
}
|
|
198
|
-
activeArgs = [...activeArgs];
|
|
199
|
-
activeArgs[0] = appendToolRecoveryInstruction(activeArgs[0], attempt === 0 ? recoveryInstruction : EXECUTION_WITH_TOOL_EVIDENCE_RETRY_INSTRUCTION);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
throw new Error("Model invocation retry loop exited unexpectedly.");
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
if ((prop === "bindTools" || prop === "withConfig" || prop === "withStructuredOutput") && typeof member === "function") {
|
|
206
|
-
return (...args) => wrapResolvedModel(member.apply(currentTarget, args));
|
|
207
|
-
}
|
|
208
|
-
if (typeof member === "function")
|
|
209
|
-
return member.bind(currentTarget);
|
|
210
|
-
return member;
|
|
211
|
-
},
|
|
212
|
-
});
|
|
213
|
-
}
|
|
1
|
+
import{EXECUTION_WITH_TOOL_EVIDENCE_RETRY_INSTRUCTION as E,INTERNAL_RUNTIME_SPILL_PATH_INSTRUCTION as g,REQUIRED_EXECUTION_CONTINUATION_INSTRUCTION as R,STRICT_TOOL_JSON_INSTRUCTION as d,WORKSPACE_RELATIVE_PATH_INSTRUCTION as _,WRITE_TODOS_FULL_ENTRY_INSTRUCTION as x,WRITE_TODOS_NON_EMPTY_INITIAL_LIST_INSTRUCTION as N,WRITE_TODOS_REQUIRED_PLAN_INSTRUCTION as S}from"../prompts/runtime-prompts.js";import{wrapNormalizedMessage as O,readTextContent as c}from"./output-content.js";import{salvageJsonToolCalls as A}from"./output-tool-args.js";function y(t){if(typeof t!="object"||!t||Array.isArray(t))return[];const e=t;return Array.isArray(e.messages)?e.messages.filter(n=>typeof n=="object"&&!!n&&!Array.isArray(n)):[]}function p(t){return typeof t.role=="string"?t.role.trim().toLowerCase():""}function C(t){const e=y(t);for(let n=e.length-1;n>=0;n-=1){const r=e[n];if(p(r)!=="user")continue;const i=c(r.content).trim();if(i)return i}return""}function v(t){return y(t).filter(e=>p(e)==="system").map(e=>c(e.content).trim()).filter(Boolean).join(`
|
|
2
|
+
|
|
3
|
+
`)}function P(t){return t instanceof Error&&/error parsing tool call:/i.test(t.message)}function U(t){if(typeof t!="object"||!t||Array.isArray(t))return!1;const e=t;return typeof e.code=="string"&&Array.isArray(e.path)&&(e.message===void 0||typeof e.message=="string")}function w(t){if(!(t instanceof Error))return!1;const e=t.message.trim();if(!e)return!1;try{const n=JSON.parse(e);if(Array.isArray(n)&&n.length>0&&n.every(r=>U(r)&&r.path.length>0))return!0}catch{}return/Invalid input:\s*expected .* received undefined/i.test(e)&&/"path"\s*:\s*\[/.test(e)?!0:/Received tool input did not match expected schema/i.test(e)&&(/(?:→\s*at|at)\s+[\w[\].]+/i.test(e)||/\bDetails:/i.test(e))}function u(t){if(!t)return[];if(t instanceof Error){const e=Array.isArray(t.errors)?(t.errors??[]).flatMap(n=>u(n)):[];return[t.message,...e].filter(n=>typeof n=="string"&&n.trim().length>0)}if(typeof t=="string"&&t.trim().length>0)return[t];if(typeof t=="object"){const e=t;return[e.message,e.error,e.details].flatMap(n=>u(n))}return[]}function I(t){return u(t).some(e=>/outside the workspace root|workspace-relative path/i.test(e))}function m(t){return u(t).some(e=>/\/large_tool_results\/|internal runtime spill path/i.test(e))}function W(t){return t instanceof Error&&/write_todos/i.test(t.message)&&/todos\[\d+\]\.content/i.test(t.message)}function h(t){return t instanceof Error&&/write_todos/i.test(t.message)&&/Initial write_todos call cannot use an empty todo list/i.test(t.message)}function L(t){return P(t)||w(t)||h(t)||m(t)||I(t)}function Y(t){const e=c(t).trim();return!!e&&/is not a valid tool, try one of \[/i.test(e)}function b(t){return C(t)?!0:v(t).length>0}function M(t){const e=t.hasWriteTodosEvidence===!0||t.hasPlanStateEvidence===!0;return t.requiresPlan!==!0||e?null:S}function z(t,e){const n=c(e).trim();return D(t,n,!1,{})}function D(t,e,n=!1,r={}){if(!b(t))return null;const i=e.trim(),o=M({request:t,assistantText:i,requiresPlan:r.requiresPlan,hasWriteTodosEvidence:r.hasWriteTodosEvidence,hasPlanStateEvidence:r.hasIncompletePlanState===!0||r.hasPlanStateEvidence===!0,hasToolResultEvidence:r.hasToolResultEvidence});if(o)return o;const a=r.hasIncompletePlanState===!0||r.hasOpenTaskDelegation===!0||r.hasMissingDelegatedExecutionEvidence===!0;if(A(i).length>0)return d;const s=n||r.hasWriteTodosEvidence===!0||r.hasToolResultEvidence===!0;return!i||!a?null:s?R:null}function F(t){return h(t)?N:W(t)?x:m(t)?g:I(t)?_:L(t)?d:null}function j(t,e){return Array.isArray(t)?[...t,{role:"system",content:e}]:typeof t=="object"&&t&&Array.isArray(t.messages)?{...t,messages:[...t.messages,{role:"system",content:e}]}:t}function k(t){if(typeof t!="object"||t===null)return t;const e=t;return new Proxy(e,{get(n,r,i){const o=Reflect.get(n,r,i);return r==="invoke"&&typeof o=="function"?async(...a)=>{let s=[...a];for(let l=0;l<3;l+=1)try{return O(await o.apply(n,s))}catch(f){const T=F(f);if(!T||l===2)throw f;s=[...s],s[0]=j(s[0],l===0?T:E)}throw new Error("Model invocation retry loop exited unexpectedly.")}:(r==="bindTools"||r==="withConfig"||r==="withStructuredOutput")&&typeof o=="function"?(...a)=>k(o.apply(n,a)):typeof o=="function"?o.bind(n):o}})}export{j as appendToolRecoveryInstruction,m as isInternalRuntimeSpillPathFailure,W as isRepairableWriteTodosContentFailure,h as isRepairableWriteTodosEmptyFailure,Y as isRetrySafeInvalidToolSelectionError,L as isToolCallRecoveryFailure,w as isToolCallValidationFailure,I as isWorkspacePathScopeFailure,z as resolveExecutionWithoutToolEvidenceInstruction,D as resolveExecutionWithoutToolEvidenceTextInstruction,M as resolveMissingPlanRecoveryInstruction,F as resolveToolCallRecoveryInstruction,b as shouldValidateExecutionWithoutToolEvidence,k as wrapResolvedModel};
|