@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,550 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
let inString = false;
|
|
12
|
-
let quoteChar = "";
|
|
13
|
-
let escaping = false;
|
|
14
|
-
for (let index = match[0].length - 1; index < value.length; index += 1) {
|
|
15
|
-
const char = value[index];
|
|
16
|
-
if (inString) {
|
|
17
|
-
if (escaping) {
|
|
18
|
-
escaping = false;
|
|
19
|
-
continue;
|
|
20
|
-
}
|
|
21
|
-
if (char === "\\") {
|
|
22
|
-
escaping = true;
|
|
23
|
-
continue;
|
|
24
|
-
}
|
|
25
|
-
if (char === quoteChar) {
|
|
26
|
-
inString = false;
|
|
27
|
-
quoteChar = "";
|
|
28
|
-
}
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
if (char === "\"" || char === "'") {
|
|
32
|
-
inString = true;
|
|
33
|
-
quoteChar = char;
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
if (char === "(") {
|
|
37
|
-
depthParen += 1;
|
|
38
|
-
continue;
|
|
39
|
-
}
|
|
40
|
-
if (char === ")") {
|
|
41
|
-
depthParen -= 1;
|
|
42
|
-
if (depthParen === 0 && depthBracket === 0 && depthBrace === 0) {
|
|
43
|
-
const candidate = value.slice(0, index + 1);
|
|
44
|
-
return salvageFunctionLikeToolCall(candidate) ? candidate : null;
|
|
45
|
-
}
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
if (char === "[")
|
|
49
|
-
depthBracket += 1;
|
|
50
|
-
else if (char === "]")
|
|
51
|
-
depthBracket -= 1;
|
|
52
|
-
else if (char === "{")
|
|
53
|
-
depthBrace += 1;
|
|
54
|
-
else if (char === "}")
|
|
55
|
-
depthBrace -= 1;
|
|
56
|
-
}
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
function stripVisibleFunctionLikeToolCallText(value) {
|
|
60
|
-
let remaining = value.trim();
|
|
61
|
-
let removedLeadingCall = false;
|
|
62
|
-
if (salvageLabeledToolCall(remaining)) {
|
|
63
|
-
return "";
|
|
64
|
-
}
|
|
65
|
-
if (salvageJsonToolCalls(remaining).length > 0) {
|
|
66
|
-
return "";
|
|
67
|
-
}
|
|
68
|
-
while (remaining.length > 0) {
|
|
69
|
-
const consumed = consumeLeadingFunctionLikeToolCall(remaining);
|
|
70
|
-
if (!consumed) {
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
removedLeadingCall = true;
|
|
74
|
-
remaining = remaining.slice(consumed.length).trimStart();
|
|
75
|
-
}
|
|
76
|
-
const lineFiltered = remaining
|
|
77
|
-
.split("\n")
|
|
78
|
-
.map((line) => line.trim())
|
|
79
|
-
.filter((line) => !salvageFunctionLikeToolCall(line))
|
|
80
|
-
.join("\n")
|
|
81
|
-
.trim();
|
|
82
|
-
if (lineFiltered.length > 0) {
|
|
83
|
-
const prefixedToolCallMatch = /^(?:\s*(?:Ready|Understood|Okay|Ok|Got it|Sure|All set|Please provide a task for me to orchestrate)[.:!]?\s*)+([A-Za-z_][A-Za-z0-9_]*\([\s\S]*\))\s*$/u.exec(lineFiltered);
|
|
84
|
-
if (prefixedToolCallMatch && salvageFunctionLikeToolCall(prefixedToolCallMatch[1])) {
|
|
85
|
-
return "";
|
|
86
|
-
}
|
|
87
|
-
return lineFiltered;
|
|
88
|
-
}
|
|
89
|
-
return removedLeadingCall ? "" : value.trim();
|
|
90
|
-
}
|
|
91
|
-
export function sanitizeVisibleText(value) {
|
|
92
|
-
return stripVisibleFunctionLikeToolCallText(value
|
|
93
|
-
.replace(/\u001B\[[0-?]*[ -/]*[@-~]/g, "")
|
|
94
|
-
.replace(/<agent_memory>[\s\S]*?<\/agent_memory>/giu, "")
|
|
95
|
-
.replace(/<agent_memory>[\s\S]*$/giu, "")
|
|
96
|
-
.replace(/[A-Za-z0-9_]*Middleware\.after_model/g, "")
|
|
97
|
-
.replace(/todoListMiddleware\.after_model/g, "")
|
|
98
|
-
.replace(/__end__+/g, "")
|
|
99
|
-
.trim());
|
|
100
|
-
}
|
|
101
|
-
function isLikelyMemoryWriteArgsObject(value) {
|
|
102
|
-
if (typeof value !== "object" || !value || Array.isArray(value)) {
|
|
103
|
-
return false;
|
|
104
|
-
}
|
|
105
|
-
const typed = value;
|
|
106
|
-
const target = typeof typed.file_path === "string"
|
|
107
|
-
? typed.file_path
|
|
108
|
-
: typeof typed.path === "string"
|
|
109
|
-
? typed.path
|
|
110
|
-
: "";
|
|
111
|
-
return target.startsWith("/memories/") && typeof typed.content === "string";
|
|
112
|
-
}
|
|
113
|
-
export function readTextContent(value) {
|
|
114
|
-
if (typeof value === "string")
|
|
115
|
-
return value;
|
|
116
|
-
if (Array.isArray(value))
|
|
117
|
-
return value.map((item) => readTextContent(item)).join("");
|
|
118
|
-
if (typeof value === "object" && value) {
|
|
119
|
-
if (isLikelyMemoryWriteArgsObject(value)) {
|
|
120
|
-
return "";
|
|
121
|
-
}
|
|
122
|
-
if ("text" in value && typeof value.text === "string") {
|
|
123
|
-
return value.text;
|
|
124
|
-
}
|
|
125
|
-
if ("content" in value) {
|
|
126
|
-
return readTextContent(value.content);
|
|
127
|
-
}
|
|
128
|
-
if ("lc_kwargs" in value && typeof value.lc_kwargs === "object") {
|
|
129
|
-
return readTextContent((value.lc_kwargs).content);
|
|
130
|
-
}
|
|
131
|
-
if ("kwargs" in value && typeof value.kwargs === "object") {
|
|
132
|
-
return readTextContent((value.kwargs).content);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
return "";
|
|
136
|
-
}
|
|
137
|
-
function extractMessageContent(message) {
|
|
138
|
-
if (typeof message !== "object" || !message)
|
|
139
|
-
return "";
|
|
140
|
-
const typed = message;
|
|
141
|
-
if (typed.content !== undefined)
|
|
142
|
-
return readTextContent(typed.content);
|
|
143
|
-
if (typeof typed.kwargs === "object" && typed.kwargs) {
|
|
144
|
-
return readTextContent(typed.kwargs.content);
|
|
145
|
-
}
|
|
146
|
-
return "";
|
|
147
|
-
}
|
|
148
|
-
function isToolMessageLike(message) {
|
|
149
|
-
if (typeof message !== "object" || !message)
|
|
150
|
-
return false;
|
|
151
|
-
const typed = message;
|
|
152
|
-
const ids = Array.isArray(typed.id) ? typed.id.filter((item) => typeof item === "string") : [];
|
|
153
|
-
const typeName = ids.at(-1);
|
|
154
|
-
const runtimeType = typeof typed._getType === "function"
|
|
155
|
-
? typed._getType()
|
|
156
|
-
: typeof typed.getType === "function"
|
|
157
|
-
? typed.getType()
|
|
158
|
-
: undefined;
|
|
159
|
-
return typeName === "ToolMessage" || runtimeType === "tool";
|
|
160
|
-
}
|
|
161
|
-
function extractToolMessageContents(messages) {
|
|
162
|
-
if (!Array.isArray(messages))
|
|
163
|
-
return [];
|
|
164
|
-
const results = [];
|
|
165
|
-
for (const message of messages) {
|
|
166
|
-
if (!isToolMessageLike(message))
|
|
167
|
-
continue;
|
|
168
|
-
const content = extractMessageContent(message);
|
|
169
|
-
if (content)
|
|
170
|
-
results.push(content);
|
|
171
|
-
}
|
|
172
|
-
return results;
|
|
173
|
-
}
|
|
174
|
-
export function hasToolCalls(value) {
|
|
175
|
-
if (typeof value !== "object" || !value)
|
|
176
|
-
return false;
|
|
177
|
-
const typed = value;
|
|
178
|
-
if (Array.isArray(typed.tool_calls) && typed.tool_calls.length > 0)
|
|
179
|
-
return true;
|
|
180
|
-
if (typeof typed.kwargs === "object" && typed.kwargs) {
|
|
181
|
-
return Array.isArray(typed.kwargs.tool_calls) && typed.kwargs.tool_calls.length > 0;
|
|
182
|
-
}
|
|
183
|
-
return false;
|
|
184
|
-
}
|
|
185
|
-
function extractAssistantTextFromMessages(messages) {
|
|
186
|
-
if (!Array.isArray(messages))
|
|
187
|
-
return "";
|
|
188
|
-
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
189
|
-
const message = messages[index];
|
|
190
|
-
if (typeof message !== "object" || !message)
|
|
191
|
-
continue;
|
|
192
|
-
const typed = message;
|
|
193
|
-
const explicitRole = typeof typed.role === "string" ? typed.role.trim().toLowerCase() : undefined;
|
|
194
|
-
if (explicitRole === "assistant" || explicitRole === "ai") {
|
|
195
|
-
const content = extractMessageContent(message);
|
|
196
|
-
if (content)
|
|
197
|
-
return content;
|
|
198
|
-
return "";
|
|
199
|
-
}
|
|
200
|
-
const ids = Array.isArray(typed.id) ? typed.id.filter((item) => typeof item === "string") : [];
|
|
201
|
-
const typeName = ids.at(-1);
|
|
202
|
-
const runtimeType = typeof message._getType === "function"
|
|
203
|
-
? message._getType()
|
|
204
|
-
: typeof message.getType === "function"
|
|
205
|
-
? message.getType()
|
|
206
|
-
: undefined;
|
|
207
|
-
if (!(typeName === "AIMessage" || runtimeType === "ai"))
|
|
208
|
-
continue;
|
|
209
|
-
const kwargs = typeof typed.kwargs === "object" && typed.kwargs ? typed.kwargs : undefined;
|
|
210
|
-
if (hasToolCalls(message))
|
|
211
|
-
continue;
|
|
212
|
-
if (Array.isArray(kwargs?.tool_calls) && kwargs.tool_calls.length > 0)
|
|
213
|
-
continue;
|
|
214
|
-
const content = extractMessageContent(message);
|
|
215
|
-
if (content)
|
|
216
|
-
return content;
|
|
217
|
-
return "";
|
|
218
|
-
}
|
|
219
|
-
return "";
|
|
220
|
-
}
|
|
221
|
-
function extractEmptyAssistantMessageReason(messages) {
|
|
222
|
-
if (!Array.isArray(messages))
|
|
223
|
-
return null;
|
|
224
|
-
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
225
|
-
const message = messages[index];
|
|
226
|
-
if (typeof message !== "object" || !message)
|
|
227
|
-
continue;
|
|
228
|
-
const typed = message;
|
|
229
|
-
const ids = Array.isArray(typed.id) ? typed.id.filter((item) => typeof item === "string") : [];
|
|
230
|
-
const typeName = ids.at(-1);
|
|
231
|
-
const runtimeType = typeof message._getType === "function"
|
|
232
|
-
? message._getType()
|
|
233
|
-
: typeof message.getType === "function"
|
|
234
|
-
? message.getType()
|
|
235
|
-
: undefined;
|
|
236
|
-
const kwargs = typeof typed.kwargs === "object" && typed.kwargs ? typed.kwargs : undefined;
|
|
237
|
-
if (!(typeName === "AIMessage" || runtimeType === "ai")) {
|
|
238
|
-
continue;
|
|
239
|
-
}
|
|
240
|
-
if (hasToolCalls(message)) {
|
|
241
|
-
return null;
|
|
242
|
-
}
|
|
243
|
-
const content = extractMessageContent(message).trim();
|
|
244
|
-
if (content) {
|
|
245
|
-
return null;
|
|
246
|
-
}
|
|
247
|
-
const responseMetadata = typeof kwargs?.response_metadata === "object" && kwargs.response_metadata
|
|
248
|
-
? kwargs.response_metadata
|
|
249
|
-
: {};
|
|
250
|
-
return {
|
|
251
|
-
finishReason: typeof responseMetadata.finish_reason === "string" ? responseMetadata.finish_reason : undefined,
|
|
252
|
-
modelProvider: typeof responseMetadata.model_provider === "string" ? responseMetadata.model_provider : undefined,
|
|
253
|
-
modelName: typeof responseMetadata.model_name === "string" ? responseMetadata.model_name : undefined,
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
return null;
|
|
257
|
-
}
|
|
258
|
-
function extractStructuredOutputText(value) {
|
|
259
|
-
if (typeof value !== "object" || !value)
|
|
260
|
-
return "";
|
|
261
|
-
if (isLikelyMemoryWriteArgsObject(value))
|
|
262
|
-
return "";
|
|
263
|
-
const typed = value;
|
|
264
|
-
const fromMessages = extractAssistantTextFromMessages(typed.messages);
|
|
265
|
-
if (fromMessages)
|
|
266
|
-
return fromMessages;
|
|
267
|
-
if (typed.output && typeof typed.output === "object") {
|
|
268
|
-
const outputRecord = typed.output;
|
|
269
|
-
const nestedMessages = extractAssistantTextFromMessages(outputRecord.messages);
|
|
270
|
-
if (nestedMessages)
|
|
271
|
-
return nestedMessages;
|
|
272
|
-
const nestedContent = readTextContent(outputRecord.content);
|
|
273
|
-
if (nestedContent)
|
|
274
|
-
return nestedContent;
|
|
275
|
-
}
|
|
276
|
-
return readTextContent(typed.content);
|
|
277
|
-
}
|
|
278
|
-
function normalizePotentialLineNumberedDocument(value) {
|
|
279
|
-
return value
|
|
280
|
-
.split("\n")
|
|
281
|
-
.map((line) => line.replace(/^\s*\d+\s+/, ""))
|
|
282
|
-
.join("\n")
|
|
283
|
-
.trim();
|
|
284
|
-
}
|
|
285
|
-
function isLikelySkillDocumentText(value) {
|
|
286
|
-
const normalized = normalizePotentialLineNumberedDocument(value);
|
|
287
|
-
if (!normalized.startsWith("---")) {
|
|
288
|
-
return false;
|
|
289
|
-
}
|
|
290
|
-
const lower = normalized.toLowerCase();
|
|
291
|
-
return (lower.includes("\nname: ") &&
|
|
292
|
-
lower.includes("\ndescription: ") &&
|
|
293
|
-
lower.includes("\n# ") &&
|
|
294
|
-
lower.includes("## workflow"));
|
|
295
|
-
}
|
|
296
|
-
export function containsLikelySkillDocument(value) {
|
|
297
|
-
if (typeof value === "string") {
|
|
298
|
-
return isLikelySkillDocumentText(value);
|
|
299
|
-
}
|
|
300
|
-
if (Array.isArray(value)) {
|
|
301
|
-
return value.some((item) => containsLikelySkillDocument(item));
|
|
302
|
-
}
|
|
303
|
-
if (typeof value === "object" && value) {
|
|
304
|
-
const typed = value;
|
|
305
|
-
if (typed.content !== undefined && containsLikelySkillDocument(typed.content)) {
|
|
306
|
-
return true;
|
|
307
|
-
}
|
|
308
|
-
if (typed.output !== undefined && containsLikelySkillDocument(typed.output)) {
|
|
309
|
-
return true;
|
|
310
|
-
}
|
|
311
|
-
if (typed.messages !== undefined && containsLikelySkillDocument(typed.messages)) {
|
|
312
|
-
return true;
|
|
313
|
-
}
|
|
314
|
-
if (typed.kwargs !== undefined && containsLikelySkillDocument(typed.kwargs)) {
|
|
315
|
-
return true;
|
|
316
|
-
}
|
|
317
|
-
return Object.values(typed).some((item) => containsLikelySkillDocument(item));
|
|
318
|
-
}
|
|
319
|
-
return false;
|
|
320
|
-
}
|
|
321
|
-
export function extractToolFallbackContext(value) {
|
|
322
|
-
if (typeof value !== "object" || !value)
|
|
323
|
-
return "";
|
|
324
|
-
const typed = value;
|
|
325
|
-
const messages = extractToolMessageContents(typed.messages).filter((message) => !isLikelySkillDocumentText(message));
|
|
326
|
-
if (messages.length > 0)
|
|
327
|
-
return messages.slice(-3).join("\n\n");
|
|
328
|
-
if (typed.output && typeof typed.output === "object") {
|
|
329
|
-
const nested = extractToolFallbackContext(typed.output);
|
|
330
|
-
if (nested)
|
|
331
|
-
return nested;
|
|
332
|
-
}
|
|
333
|
-
return "";
|
|
334
|
-
}
|
|
335
|
-
export function extractVisibleOutput(value) {
|
|
336
|
-
const structured = extractStructuredOutputText(value);
|
|
337
|
-
if (structured && !isLikelySkillDocumentText(structured))
|
|
338
|
-
return structured;
|
|
339
|
-
if (typeof value === "string") {
|
|
340
|
-
const parsed = tryParseJson(value);
|
|
341
|
-
if (parsed) {
|
|
342
|
-
if (isLikelyMemoryWriteArgsObject(parsed))
|
|
343
|
-
return "";
|
|
344
|
-
const parsedStructured = extractStructuredOutputText(parsed);
|
|
345
|
-
if (parsedStructured && !isLikelySkillDocumentText(parsedStructured))
|
|
346
|
-
return parsedStructured;
|
|
347
|
-
if (isLikelyToolArgsObject(parsed))
|
|
348
|
-
return "";
|
|
349
|
-
}
|
|
350
|
-
if (isLikelySkillDocumentText(value))
|
|
351
|
-
return "";
|
|
352
|
-
return value;
|
|
353
|
-
}
|
|
354
|
-
if (typeof value === "object" && value) {
|
|
355
|
-
const typed = value;
|
|
356
|
-
if (typed.output !== undefined) {
|
|
357
|
-
const nested = extractVisibleOutput(typed.output);
|
|
358
|
-
if (nested)
|
|
359
|
-
return nested;
|
|
360
|
-
}
|
|
361
|
-
if (typed.content !== undefined) {
|
|
362
|
-
const nested = extractVisibleOutput(typed.content);
|
|
363
|
-
if (nested)
|
|
364
|
-
return nested;
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
return "";
|
|
368
|
-
}
|
|
369
|
-
function isContentBlock(value) {
|
|
370
|
-
return typeof value === "object" && value !== null && typeof value.type === "string";
|
|
371
|
-
}
|
|
372
|
-
function normalizeContentBlocks(value) {
|
|
373
|
-
if (!Array.isArray(value)) {
|
|
374
|
-
return [];
|
|
375
|
-
}
|
|
376
|
-
return value.filter(isContentBlock).map((block) => ({ ...block }));
|
|
377
|
-
}
|
|
378
|
-
function extractStructuredOutputContent(value) {
|
|
379
|
-
if (typeof value !== "object" || !value)
|
|
380
|
-
return undefined;
|
|
381
|
-
const typed = value;
|
|
382
|
-
if (typed.output && typeof typed.output === "object") {
|
|
383
|
-
const nested = extractStructuredOutputContent(typed.output);
|
|
384
|
-
if (nested !== undefined)
|
|
385
|
-
return nested;
|
|
386
|
-
}
|
|
387
|
-
if (typed.content !== undefined) {
|
|
388
|
-
return typed.content;
|
|
389
|
-
}
|
|
390
|
-
if (!Array.isArray(typed.messages)) {
|
|
391
|
-
return undefined;
|
|
392
|
-
}
|
|
393
|
-
for (let index = typed.messages.length - 1; index >= 0; index -= 1) {
|
|
394
|
-
const message = typed.messages[index];
|
|
395
|
-
if (typeof message !== "object" || !message)
|
|
396
|
-
continue;
|
|
397
|
-
const ids = Array.isArray(message.id)
|
|
398
|
-
? (message.id.filter((item) => typeof item === "string"))
|
|
399
|
-
: [];
|
|
400
|
-
const typeName = ids.at(-1);
|
|
401
|
-
const runtimeType = typeof message._getType === "function"
|
|
402
|
-
? message._getType()
|
|
403
|
-
: typeof message.getType === "function"
|
|
404
|
-
? message.getType()
|
|
405
|
-
: undefined;
|
|
406
|
-
if (!(typeName === "AIMessage" || runtimeType === "ai")) {
|
|
407
|
-
continue;
|
|
408
|
-
}
|
|
409
|
-
if (hasToolCalls(message)) {
|
|
410
|
-
continue;
|
|
411
|
-
}
|
|
412
|
-
const directContent = message.content;
|
|
413
|
-
if (directContent !== undefined) {
|
|
414
|
-
return directContent;
|
|
415
|
-
}
|
|
416
|
-
const kwargs = typeof message.kwargs === "object" && message.kwargs
|
|
417
|
-
? (message.kwargs)
|
|
418
|
-
: undefined;
|
|
419
|
-
if (kwargs?.content !== undefined) {
|
|
420
|
-
return kwargs.content;
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
return undefined;
|
|
424
|
-
}
|
|
425
|
-
export function extractOutputContent(value) {
|
|
426
|
-
const content = extractStructuredOutputContent(value);
|
|
427
|
-
if (content !== undefined) {
|
|
428
|
-
return content;
|
|
429
|
-
}
|
|
430
|
-
return undefined;
|
|
431
|
-
}
|
|
432
|
-
export function extractContentBlocks(value) {
|
|
433
|
-
const outputContent = extractOutputContent(value);
|
|
434
|
-
if (outputContent === undefined) {
|
|
435
|
-
return [];
|
|
436
|
-
}
|
|
437
|
-
if (typeof outputContent === "string") {
|
|
438
|
-
return outputContent.trim() ? [{ type: "text", text: outputContent }] : [];
|
|
439
|
-
}
|
|
440
|
-
return normalizeContentBlocks(outputContent);
|
|
441
|
-
}
|
|
442
|
-
export function extractEmptyAssistantMessageFailure(value) {
|
|
443
|
-
if (typeof value !== "object" || !value)
|
|
444
|
-
return "";
|
|
445
|
-
const typed = value;
|
|
446
|
-
const reason = extractEmptyAssistantMessageReason(typed.messages)
|
|
447
|
-
?? (typeof typed.output === "object" && typed.output
|
|
448
|
-
? extractEmptyAssistantMessageReason(typed.output.messages)
|
|
449
|
-
: null);
|
|
450
|
-
if (!reason) {
|
|
451
|
-
return "";
|
|
452
|
-
}
|
|
453
|
-
const detailParts = [
|
|
454
|
-
reason.finishReason ? `finish_reason=${reason.finishReason}` : "",
|
|
455
|
-
reason.modelProvider ? `model_provider=${reason.modelProvider}` : "",
|
|
456
|
-
reason.modelName ? `model_name=${reason.modelName}` : "",
|
|
457
|
-
].filter(Boolean);
|
|
458
|
-
return [
|
|
459
|
-
"empty_final_ai_message: model returned no visible assistant content and no tool calls",
|
|
460
|
-
detailParts.length > 0 ? `(${detailParts.join(", ")})` : "",
|
|
461
|
-
].filter(Boolean).join(" ");
|
|
462
|
-
}
|
|
463
|
-
function isAiMessageLike(value) {
|
|
464
|
-
if (typeof value !== "object" || !value)
|
|
465
|
-
return false;
|
|
466
|
-
const typed = value;
|
|
467
|
-
return typeof typed._getType === "function" && typed._getType() === "ai" && ("content" in typed || "tool_calls" in typed);
|
|
468
|
-
}
|
|
469
|
-
function normalizeAgentMessage(value) {
|
|
470
|
-
if (!AIMessage.isInstance(value) && !isAiMessageLike(value))
|
|
471
|
-
return value;
|
|
472
|
-
const typed = value;
|
|
473
|
-
const normalizedToolCalls = Array.isArray(typed.tool_calls)
|
|
474
|
-
? typed.tool_calls.map((toolCall) => {
|
|
475
|
-
if (typeof toolCall !== "object" || !toolCall)
|
|
476
|
-
return toolCall;
|
|
477
|
-
const parsedArgs = salvageToolArgs(toolCall.args);
|
|
478
|
-
return parsedArgs ? { ...toolCall, args: normalizeKnownToolArgs(toolCall.name, parsedArgs) } : toolCall;
|
|
479
|
-
})
|
|
480
|
-
: [];
|
|
481
|
-
const normalizedInvalidToolCalls = Array.isArray(typed.invalid_tool_calls)
|
|
482
|
-
? typed.invalid_tool_calls
|
|
483
|
-
.map((toolCall) => {
|
|
484
|
-
if (typeof toolCall !== "object" || !toolCall)
|
|
485
|
-
return null;
|
|
486
|
-
const parsedArgs = salvageToolArgs(toolCall.args);
|
|
487
|
-
if (!parsedArgs)
|
|
488
|
-
return toolCall;
|
|
489
|
-
return {
|
|
490
|
-
...toolCall,
|
|
491
|
-
args: normalizeKnownToolArgs(toolCall.name, parsedArgs),
|
|
492
|
-
type: "tool_call",
|
|
493
|
-
error: undefined,
|
|
494
|
-
};
|
|
495
|
-
})
|
|
496
|
-
.filter((toolCall) => toolCall !== null)
|
|
497
|
-
: [];
|
|
498
|
-
const normalizedContent = typeof typed.content === "string" || Array.isArray(typed.content)
|
|
499
|
-
? typed.content
|
|
500
|
-
: typeof typed.content === "object" && typed.content
|
|
501
|
-
? readTextContent(typed.content)
|
|
502
|
-
: "";
|
|
503
|
-
const recoveredToolCalls = normalizedInvalidToolCalls.filter((toolCall) => typeof toolCall.args === "object" && !!toolCall.args && !Array.isArray(toolCall.args));
|
|
504
|
-
const functionLikeToolCall = normalizedToolCalls.length === 0 && recoveredToolCalls.length === 0 && typeof normalizedContent === "string"
|
|
505
|
-
? salvageFunctionLikeToolCall(normalizedContent)
|
|
506
|
-
: null;
|
|
507
|
-
const labeledToolCall = normalizedToolCalls.length === 0 && recoveredToolCalls.length === 0 && !functionLikeToolCall && typeof normalizedContent === "string"
|
|
508
|
-
? salvageLabeledToolCall(normalizedContent)
|
|
509
|
-
: null;
|
|
510
|
-
const jsonToolCalls = normalizedToolCalls.length === 0 && recoveredToolCalls.length === 0 && !functionLikeToolCall && !labeledToolCall && typeof normalizedContent === "string"
|
|
511
|
-
? salvageJsonToolCalls(normalizedContent)
|
|
512
|
-
: [];
|
|
513
|
-
const hasRecoveredContentToolCalls = Boolean(functionLikeToolCall) || Boolean(labeledToolCall) || jsonToolCalls.length > 0;
|
|
514
|
-
return new AIMessage({
|
|
515
|
-
content: hasRecoveredContentToolCalls ? "" : normalizedContent,
|
|
516
|
-
name: typeof typed.name === "string" ? typed.name : undefined,
|
|
517
|
-
additional_kwargs: typeof typed.additional_kwargs === "object" && typed.additional_kwargs ? typed.additional_kwargs : {},
|
|
518
|
-
response_metadata: typeof typed.response_metadata === "object" && typed.response_metadata ? typed.response_metadata : {},
|
|
519
|
-
id: typeof typed.id === "string" ? typed.id : undefined,
|
|
520
|
-
tool_calls: [
|
|
521
|
-
...normalizedToolCalls,
|
|
522
|
-
...recoveredToolCalls,
|
|
523
|
-
...(functionLikeToolCall ? [{ name: functionLikeToolCall.name, args: functionLikeToolCall.args }] : []),
|
|
524
|
-
...(labeledToolCall ? [{ name: labeledToolCall.name, args: labeledToolCall.args }] : []),
|
|
525
|
-
...jsonToolCalls.map((toolCall) => ({ name: toolCall.name, args: toolCall.args })),
|
|
526
|
-
],
|
|
527
|
-
invalid_tool_calls: normalizedInvalidToolCalls.filter((toolCall) => toolCall.type !== "tool_call"),
|
|
528
|
-
usage_metadata: typeof typed.usage_metadata === "object" && typed.usage_metadata ? typed.usage_metadata : undefined,
|
|
529
|
-
});
|
|
530
|
-
}
|
|
531
|
-
export function wrapNormalizedMessage(value) {
|
|
532
|
-
return normalizeAgentMessage(value);
|
|
533
|
-
}
|
|
534
|
-
export function extractReasoningText(value) {
|
|
535
|
-
if (typeof value !== "object" || !value)
|
|
536
|
-
return "";
|
|
537
|
-
const typed = value;
|
|
538
|
-
const chunk = typed.data?.chunk ?? value;
|
|
539
|
-
if (typeof chunk !== "object" || !chunk)
|
|
540
|
-
return "";
|
|
541
|
-
if ("additional_kwargs" in chunk && typeof chunk.additional_kwargs === "object") {
|
|
542
|
-
const kwargs = chunk.additional_kwargs;
|
|
543
|
-
return typeof kwargs?.reasoning === "string" ? kwargs.reasoning : "";
|
|
544
|
-
}
|
|
545
|
-
if ("kwargs" in chunk && typeof chunk.kwargs === "object") {
|
|
546
|
-
const kwargs = chunk.kwargs;
|
|
547
|
-
return typeof kwargs?.additional_kwargs?.reasoning === "string" ? kwargs.additional_kwargs.reasoning : "";
|
|
548
|
-
}
|
|
549
|
-
return "";
|
|
550
|
-
}
|
|
1
|
+
import{AIMessage as A}from"langchain";import{salvageFunctionLikeToolCall as y,salvageJsonToolCalls as w,salvageLabeledToolCall as b,salvageToolArgs as T,isLikelyToolArgsObject as z,normalizeKnownToolArgs as j,tryParseJson as S}from"./output-tool-args.js";function B(e){const t=/^([A-Za-z_][A-Za-z0-9_]*)\(/.exec(e);if(!t)return null;let n=0,r=0,i=0,a=!1,c="",f=!1;for(let u=t[0].length-1;u<e.length;u+=1){const s=e[u];if(a){if(f){f=!1;continue}if(s==="\\"){f=!0;continue}s===c&&(a=!1,c="");continue}if(s==='"'||s==="'"){a=!0,c=s;continue}if(s==="("){n+=1;continue}if(s===")"){if(n-=1,n===0&&r===0&&i===0){const o=e.slice(0,u+1);return y(o)?o:null}continue}s==="["?r+=1:s==="]"?r-=1:s==="{"?i+=1:s==="}"&&(i-=1)}return null}function N(e){let t=e.trim(),n=!1;if(b(t)||w(t).length>0)return"";for(;t.length>0;){const i=B(t);if(!i)break;n=!0,t=t.slice(i.length).trimStart()}const r=t.split(`
|
|
2
|
+
`).map(i=>i.trim()).filter(i=>!y(i)).join(`
|
|
3
|
+
`).trim();if(r.length>0){const i=/^(?:\s*(?:Ready|Understood|Okay|Ok|Got it|Sure|All set|Please provide a task for me to orchestrate)[.:!]?\s*)+([A-Za-z_][A-Za-z0-9_]*\([\s\S]*\))\s*$/u.exec(r);return i&&y(i[1])?"":r}return n?"":e.trim()}function J(e){return N(e.replace(/\u001B\[[0-?]*[ -/]*[@-~]/g,"").replace(/<agent_memory>[\s\S]*?<\/agent_memory>/giu,"").replace(/<agent_memory>[\s\S]*$/giu,"").replace(/[A-Za-z0-9_]*Middleware\.after_model/g,"").replace(/todoListMiddleware\.after_model/g,"").replace(/__end__+/g,"").trim())}function _(e){if(typeof e!="object"||!e||Array.isArray(e))return!1;const t=e;return(typeof t.file_path=="string"?t.file_path:typeof t.path=="string"?t.path:"").startsWith("/memories/")&&typeof t.content=="string"}function d(e){if(typeof e=="string")return e;if(Array.isArray(e))return e.map(t=>d(t)).join("");if(typeof e=="object"&&e){if(_(e))return"";if("text"in e&&typeof e.text=="string")return e.text;if("content"in e)return d(e.content);if("lc_kwargs"in e&&typeof e.lc_kwargs=="object")return d(e.lc_kwargs.content);if("kwargs"in e&&typeof e.kwargs=="object")return d(e.kwargs.content)}return""}function m(e){if(typeof e!="object"||!e)return"";const t=e;return t.content!==void 0?d(t.content):typeof t.kwargs=="object"&&t.kwargs?d(t.kwargs.content):""}function O(e){if(typeof e!="object"||!e)return!1;const t=e,r=(Array.isArray(t.id)?t.id.filter(a=>typeof a=="string"):[]).at(-1),i=typeof t._getType=="function"?t._getType():typeof t.getType=="function"?t.getType():void 0;return r==="ToolMessage"||i==="tool"}function R(e){if(!Array.isArray(e))return[];const t=[];for(const n of e){if(!O(n))continue;const r=m(n);r&&t.push(r)}return t}function k(e){if(typeof e!="object"||!e)return!1;const t=e;return Array.isArray(t.tool_calls)&&t.tool_calls.length>0?!0:typeof t.kwargs=="object"&&t.kwargs?Array.isArray(t.kwargs.tool_calls)&&t.kwargs.tool_calls.length>0:!1}function h(e){if(!Array.isArray(e))return"";for(let t=e.length-1;t>=0;t-=1){const n=e[t];if(typeof n!="object"||!n)continue;const r=n,i=typeof r.role=="string"?r.role.trim().toLowerCase():void 0;if(i==="assistant"||i==="ai"){const o=m(n);return o||""}const c=(Array.isArray(r.id)?r.id.filter(o=>typeof o=="string"):[]).at(-1),f=typeof n._getType=="function"?n._getType():typeof n.getType=="function"?n.getType():void 0;if(!(c==="AIMessage"||f==="ai"))continue;const u=typeof r.kwargs=="object"&&r.kwargs?r.kwargs:void 0;if(k(n)||Array.isArray(u?.tool_calls)&&u.tool_calls.length>0)continue;const s=m(n);return s||""}return""}function x(e){if(!Array.isArray(e))return null;for(let t=e.length-1;t>=0;t-=1){const n=e[t];if(typeof n!="object"||!n)continue;const r=n,a=(Array.isArray(r.id)?r.id.filter(o=>typeof o=="string"):[]).at(-1),c=typeof n._getType=="function"?n._getType():typeof n.getType=="function"?n.getType():void 0,f=typeof r.kwargs=="object"&&r.kwargs?r.kwargs:void 0;if(!(a==="AIMessage"||c==="ai"))continue;if(k(n)||m(n).trim())return null;const s=typeof f?.response_metadata=="object"&&f.response_metadata?f.response_metadata:{};return{finishReason:typeof s.finish_reason=="string"?s.finish_reason:void 0,modelProvider:typeof s.model_provider=="string"?s.model_provider:void 0,modelName:typeof s.model_name=="string"?s.model_name:void 0}}return null}function M(e){if(typeof e!="object"||!e||_(e))return"";const t=e,n=h(t.messages);if(n)return n;if(t.output&&typeof t.output=="object"){const r=t.output,i=h(r.messages);if(i)return i;const a=d(r.content);if(a)return a}return d(t.content)}function P(e){return e.split(`
|
|
4
|
+
`).map(t=>t.replace(/^\s*\d+\s+/,"")).join(`
|
|
5
|
+
`).trim()}function g(e){const t=P(e);if(!t.startsWith("---"))return!1;const n=t.toLowerCase();return n.includes(`
|
|
6
|
+
name: `)&&n.includes(`
|
|
7
|
+
description: `)&&n.includes(`
|
|
8
|
+
# `)&&n.includes("## workflow")}function p(e){if(typeof e=="string")return g(e);if(Array.isArray(e))return e.some(t=>p(t));if(typeof e=="object"&&e){const t=e;return t.content!==void 0&&p(t.content)||t.output!==void 0&&p(t.output)||t.messages!==void 0&&p(t.messages)||t.kwargs!==void 0&&p(t.kwargs)?!0:Object.values(t).some(n=>p(n))}return!1}function F(e){if(typeof e!="object"||!e)return"";const t=e,n=R(t.messages).filter(r=>!g(r));if(n.length>0)return n.slice(-3).join(`
|
|
9
|
+
|
|
10
|
+
`);if(t.output&&typeof t.output=="object"){const r=F(t.output);if(r)return r}return""}function C(e){const t=M(e);if(t&&!g(t))return t;if(typeof e=="string"){const n=S(e);if(n){if(_(n))return"";const r=M(n);if(r&&!g(r))return r;if(z(n))return""}return g(e)?"":e}if(typeof e=="object"&&e){const n=e;if(n.output!==void 0){const r=C(n.output);if(r)return r}if(n.content!==void 0){const r=C(n.content);if(r)return r}}return""}function I(e){return typeof e=="object"&&e!==null&&typeof e.type=="string"}function $(e){return Array.isArray(e)?e.filter(I).map(t=>({...t})):[]}function L(e){if(typeof e!="object"||!e)return;const t=e;if(t.output&&typeof t.output=="object"){const n=L(t.output);if(n!==void 0)return n}if(t.content!==void 0)return t.content;if(Array.isArray(t.messages))for(let n=t.messages.length-1;n>=0;n-=1){const r=t.messages[n];if(typeof r!="object"||!r)continue;const a=(Array.isArray(r.id)?r.id.filter(s=>typeof s=="string"):[]).at(-1),c=typeof r._getType=="function"?r._getType():typeof r.getType=="function"?r.getType():void 0;if(!(a==="AIMessage"||c==="ai")||k(r))continue;const f=r.content;if(f!==void 0)return f;const u=typeof r.kwargs=="object"&&r.kwargs?r.kwargs:void 0;if(u?.content!==void 0)return u.content}}function Z(e){const t=L(e);if(t!==void 0)return t}function q(e){const t=Z(e);return t===void 0?[]:typeof t=="string"?t.trim()?[{type:"text",text:t}]:[]:$(t)}function G(e){if(typeof e!="object"||!e)return"";const t=e,n=x(t.messages)??(typeof t.output=="object"&&t.output?x(t.output.messages):null);if(!n)return"";const r=[n.finishReason?`finish_reason=${n.finishReason}`:"",n.modelProvider?`model_provider=${n.modelProvider}`:"",n.modelName?`model_name=${n.modelName}`:""].filter(Boolean);return["empty_final_ai_message: model returned no visible assistant content and no tool calls",r.length>0?`(${r.join(", ")})`:""].filter(Boolean).join(" ")}function D(e){if(typeof e!="object"||!e)return!1;const t=e;return typeof t._getType=="function"&&t._getType()==="ai"&&("content"in t||"tool_calls"in t)}function V(e){if(!A.isInstance(e)&&!D(e))return e;const t=e,n=Array.isArray(t.tool_calls)?t.tool_calls.map(o=>{if(typeof o!="object"||!o)return o;const l=T(o.args);return l?{...o,args:j(o.name,l)}:o}):[],r=Array.isArray(t.invalid_tool_calls)?t.invalid_tool_calls.map(o=>{if(typeof o!="object"||!o)return null;const l=T(o.args);return l?{...o,args:j(o.name,l),type:"tool_call",error:void 0}:o}).filter(o=>o!==null):[],i=typeof t.content=="string"||Array.isArray(t.content)?t.content:typeof t.content=="object"&&t.content?d(t.content):"",a=r.filter(o=>typeof o.args=="object"&&!!o.args&&!Array.isArray(o.args)),c=n.length===0&&a.length===0&&typeof i=="string"?y(i):null,f=n.length===0&&a.length===0&&!c&&typeof i=="string"?b(i):null,u=n.length===0&&a.length===0&&!c&&!f&&typeof i=="string"?w(i):[],s=!!c||!!f||u.length>0;return new A({content:s?"":i,name:typeof t.name=="string"?t.name:void 0,additional_kwargs:typeof t.additional_kwargs=="object"&&t.additional_kwargs?t.additional_kwargs:{},response_metadata:typeof t.response_metadata=="object"&&t.response_metadata?t.response_metadata:{},id:typeof t.id=="string"?t.id:void 0,tool_calls:[...n,...a,...c?[{name:c.name,args:c.args}]:[],...f?[{name:f.name,args:f.args}]:[],...u.map(o=>({name:o.name,args:o.args}))],invalid_tool_calls:r.filter(o=>o.type!=="tool_call"),usage_metadata:typeof t.usage_metadata=="object"&&t.usage_metadata?t.usage_metadata:void 0})}function K(e){return V(e)}function U(e){if(typeof e!="object"||!e)return"";const n=e.data?.chunk??e;if(typeof n!="object"||!n)return"";if("additional_kwargs"in n&&typeof n.additional_kwargs=="object"){const r=n.additional_kwargs;return typeof r?.reasoning=="string"?r.reasoning:""}if("kwargs"in n&&typeof n.kwargs=="object"){const r=n.kwargs;return typeof r?.additional_kwargs?.reasoning=="string"?r.additional_kwargs.reasoning:""}return""}export{p as containsLikelySkillDocument,q as extractContentBlocks,G as extractEmptyAssistantMessageFailure,Z as extractOutputContent,U as extractReasoningText,F as extractToolFallbackContext,C as extractVisibleOutput,k as hasToolCalls,d as readTextContent,J as sanitizeVisibleText,K as wrapNormalizedMessage};
|
|
@@ -1,4 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { BROWSER_CAPABILITY_DISCLAIMER_RECOVERY_INSTRUCTION, EXECUTION_WITH_TOOL_EVIDENCE_INSTRUCTION, EXECUTION_WITH_TOOL_EVIDENCE_RETRY_INSTRUCTION, INVALID_TOOL_SELECTION_RECOVERY_INSTRUCTION, STRICT_TOOL_JSON_INSTRUCTION, WORKSPACE_RELATIVE_PATH_INSTRUCTION, WRITE_TODOS_FULL_ENTRY_INSTRUCTION, WRITE_TODOS_NON_EMPTY_INITIAL_LIST_INSTRUCTION, } from "../prompts/runtime-prompts.js";
|
|
3
|
-
export { containsLikelySkillDocument, extractContentBlocks, extractEmptyAssistantMessageFailure, extractOutputContent, extractReasoningText, extractToolFallbackContext, extractVisibleOutput, hasToolCalls, readTextContent, sanitizeVisibleText, } from "./output-content.js";
|
|
4
|
-
export { isLikelyToolArgsObject, salvageToolArgs, tryParseJson, } from "./output-tool-args.js";
|
|
1
|
+
import{appendToolRecoveryInstruction as t,isRepairableWriteTodosContentFailure as T,isRepairableWriteTodosEmptyFailure as i,isRetrySafeInvalidToolSelectionError as l,resolveMissingPlanRecoveryInstruction as r,isToolCallRecoveryFailure as a,isToolCallValidationFailure as I,isWorkspacePathScopeFailure as s,resolveExecutionWithoutToolEvidenceInstruction as n,resolveExecutionWithoutToolEvidenceTextInstruction as E,resolveToolCallRecoveryInstruction as _,shouldValidateExecutionWithoutToolEvidence as O,wrapResolvedModel as R}from"./output-recovery.js";import{BROWSER_CAPABILITY_DISCLAIMER_RECOVERY_INSTRUCTION as C,EXECUTION_WITH_TOOL_EVIDENCE_INSTRUCTION as N,EXECUTION_WITH_TOOL_EVIDENCE_RETRY_INSTRUCTION as u,INVALID_TOOL_SELECTION_RECOVERY_INSTRUCTION as S,STRICT_TOOL_JSON_INSTRUCTION as x,WORKSPACE_RELATIVE_PATH_INSTRUCTION as p,WRITE_TODOS_FULL_ENTRY_INSTRUCTION as L,WRITE_TODOS_NON_EMPTY_INITIAL_LIST_INSTRUCTION as v}from"../prompts/runtime-prompts.js";import{containsLikelySkillDocument as W,extractContentBlocks as A,extractEmptyAssistantMessageFailure as U,extractOutputContent as y,extractReasoningText as V,extractToolFallbackContext as F,extractVisibleOutput as m,hasToolCalls as D,readTextContent as P,sanitizeVisibleText as b}from"./output-content.js";import{isLikelyToolArgsObject as h,salvageToolArgs as k,tryParseJson as Y}from"./output-tool-args.js";export{C as BROWSER_CAPABILITY_DISCLAIMER_RECOVERY_INSTRUCTION,N as EXECUTION_WITH_TOOL_EVIDENCE_INSTRUCTION,u as EXECUTION_WITH_TOOL_EVIDENCE_RETRY_INSTRUCTION,S as INVALID_TOOL_SELECTION_RECOVERY_INSTRUCTION,x as STRICT_TOOL_JSON_INSTRUCTION,p as WORKSPACE_RELATIVE_PATH_INSTRUCTION,L as WRITE_TODOS_FULL_ENTRY_INSTRUCTION,v as WRITE_TODOS_NON_EMPTY_INITIAL_LIST_INSTRUCTION,t as appendToolRecoveryInstruction,W as containsLikelySkillDocument,A as extractContentBlocks,U as extractEmptyAssistantMessageFailure,y as extractOutputContent,V as extractReasoningText,F as extractToolFallbackContext,m as extractVisibleOutput,D as hasToolCalls,h as isLikelyToolArgsObject,T as isRepairableWriteTodosContentFailure,i as isRepairableWriteTodosEmptyFailure,l as isRetrySafeInvalidToolSelectionError,a as isToolCallRecoveryFailure,I as isToolCallValidationFailure,s as isWorkspacePathScopeFailure,P as readTextContent,n as resolveExecutionWithoutToolEvidenceInstruction,E as resolveExecutionWithoutToolEvidenceTextInstruction,r as resolveMissingPlanRecoveryInstruction,_ as resolveToolCallRecoveryInstruction,k as salvageToolArgs,b as sanitizeVisibleText,O as shouldValidateExecutionWithoutToolEvidence,Y as tryParseJson,R as wrapResolvedModel};
|