@botbotgo/agent-harness 0.0.308 → 0.0.310
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -1
- package/README.zh.md +17 -1
- package/dist/acp.d.ts +1 -116
- package/dist/acp.js +1 -310
- package/dist/api.d.ts +4 -2
- package/dist/api.js +4 -1
- package/dist/cli/chat-interactive.d.ts +24 -0
- package/dist/cli/chat-interactive.js +244 -0
- package/dist/cli/chat-rendering.d.ts +9 -0
- package/dist/cli/chat-rendering.js +102 -0
- package/dist/cli/chat-stream.d.ts +23 -0
- package/dist/cli/chat-stream.js +330 -0
- package/dist/cli/chat-ui.d.ts +20 -0
- package/dist/cli/chat-ui.js +198 -0
- package/dist/cli/chat-workspace.d.ts +15 -0
- package/dist/cli/chat-workspace.js +205 -0
- package/dist/cli/main.d.ts +52 -0
- package/dist/cli/main.js +323 -0
- package/dist/cli/managed-service-commands.d.ts +23 -0
- package/dist/cli/managed-service-commands.js +63 -0
- package/dist/cli/managed-service.d.ts +27 -0
- package/dist/cli/managed-service.js +61 -0
- package/dist/cli/options-init-chat.d.ts +16 -0
- package/dist/cli/options-init-chat.js +108 -0
- package/dist/cli/options-runtime.d.ts +27 -0
- package/dist/cli/options-runtime.js +158 -0
- package/dist/cli/options-serve.d.ts +24 -0
- package/dist/cli/options-serve.js +166 -0
- package/dist/cli/options.d.ts +5 -0
- package/dist/cli/options.js +47 -0
- package/dist/cli/process-guards.d.ts +14 -0
- package/dist/cli/process-guards.js +139 -0
- package/dist/cli/request-tree.d.ts +12 -0
- package/dist/cli/request-tree.js +296 -0
- package/dist/cli/runtime-commands.d.ts +15 -0
- package/dist/cli/runtime-commands.js +247 -0
- package/dist/cli/runtime-output.d.ts +5 -0
- package/dist/cli/runtime-output.js +124 -0
- package/dist/cli/server-commands.d.ts +36 -0
- package/dist/cli/server-commands.js +250 -0
- package/dist/cli/workspace.d.ts +6 -0
- package/dist/cli/workspace.js +71 -0
- package/dist/cli.d.ts +1 -67
- package/dist/cli.js +2 -2734
- package/dist/client/acp.d.ts +1 -50
- package/dist/client/acp.js +1 -219
- package/dist/client/in-process.d.ts +5 -5
- package/dist/client/index.d.ts +2 -2
- package/dist/client/index.js +1 -1
- package/dist/contracts/runtime-evaluation.d.ts +103 -0
- package/dist/contracts/runtime-evaluation.js +1 -0
- package/dist/contracts/runtime-memory.d.ts +162 -0
- package/dist/contracts/runtime-memory.js +1 -0
- package/dist/contracts/runtime-observability.d.ts +248 -0
- package/dist/contracts/runtime-observability.js +1 -0
- package/dist/contracts/runtime-requests.d.ts +342 -0
- package/dist/contracts/runtime-requests.js +1 -0
- package/dist/contracts/runtime-scheduling.d.ts +146 -0
- package/dist/contracts/runtime-scheduling.js +1 -0
- package/dist/contracts/runtime.d.ts +5 -1042
- package/dist/contracts/runtime.js +27 -1
- package/dist/flow/build-flow-graph.js +4 -875
- package/dist/flow/flow-graph-normalization.d.ts +56 -0
- package/dist/flow/flow-graph-normalization.js +214 -0
- package/dist/flow/flow-graph-runtime.d.ts +8 -0
- package/dist/flow/flow-graph-runtime.js +107 -0
- package/dist/flow/flow-graph-upstream.d.ts +18 -0
- package/dist/flow/flow-graph-upstream.js +498 -0
- package/dist/flow/types.d.ts +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -2
- package/dist/init-project.d.ts +1 -12
- package/dist/init-project.js +1 -651
- package/dist/{procedural → knowledge/procedural}/manager.d.ts +3 -3
- package/dist/{procedural → knowledge/procedural}/manager.js +6 -6
- package/dist/mcp.d.ts +2 -62
- package/dist/mcp.js +2 -253
- package/dist/package-version.d.ts +1 -1
- package/dist/package-version.js +1 -1
- package/dist/persistence/file-store.js +1 -1
- package/dist/persistence/sqlite-runtime.d.ts +19 -0
- package/dist/persistence/sqlite-runtime.js +86 -0
- package/dist/persistence/sqlite-store.js +11 -99
- package/dist/{request-events.d.ts → projections/request-events.d.ts} +1 -1
- package/dist/{upstream-events.js → projections/upstream-events.js} +1 -1
- package/dist/protocol/a2a/http-discovery.d.ts +39 -0
- package/dist/protocol/a2a/http-discovery.js +178 -0
- package/dist/protocol/a2a/http-rpc.d.ts +28 -0
- package/dist/protocol/a2a/http-rpc.js +623 -0
- package/dist/protocol/a2a/http.d.ts +72 -1
- package/dist/protocol/a2a/http.js +14 -1124
- package/dist/protocol/a2a/task-state.d.ts +29 -0
- package/dist/protocol/a2a/task-state.js +317 -0
- package/dist/protocol/acp/client.js +1 -1
- package/dist/protocol/acp/harness-client.d.ts +50 -0
- package/dist/protocol/acp/harness-client.js +219 -0
- package/dist/protocol/acp/server.d.ts +116 -0
- package/dist/protocol/acp/server.js +310 -0
- package/dist/protocol/ag-ui/http.js +1 -1
- package/dist/protocol/mcp/server.d.ts +76 -0
- package/dist/protocol/mcp/server.js +428 -0
- package/dist/resource/backend/workspace-scoped-backend.d.ts +40 -0
- package/dist/resource/backend/workspace-scoped-backend.js +296 -0
- package/dist/resource/mcp/tool-support.d.ts +35 -0
- package/dist/resource/mcp/tool-support.js +296 -0
- package/dist/resource/mcp-tool-support.d.ts +2 -35
- package/dist/resource/mcp-tool-support.js +2 -296
- package/dist/resource/providers/resource-provider.d.ts +22 -0
- package/dist/resource/providers/resource-provider.js +215 -0
- package/dist/resource/resource-impl.d.ts +3 -33
- package/dist/resource/resource-impl.js +2 -808
- package/dist/resource/resource-types.d.ts +33 -0
- package/dist/resource/resource-types.js +1 -0
- package/dist/resource/tools/function-tool-resolver.d.ts +2 -0
- package/dist/resource/tools/function-tool-resolver.js +306 -0
- package/dist/runtime/adapter/middleware-assembly.js +1 -1
- package/dist/runtime/adapter/model/invocation-request.js +2 -2
- package/dist/runtime/adapter/model/message-assembly.js +1 -1
- package/dist/runtime/agent-runtime-adapter.d.ts +3 -63
- package/dist/runtime/agent-runtime-adapter.js +5 -233
- package/dist/runtime/agent-runtime-assembly.d.ts +67 -0
- package/dist/runtime/agent-runtime-assembly.js +211 -0
- package/dist/runtime/harness/background-runtime.d.ts +1 -1
- package/dist/runtime/harness/events/event-sink.js +1 -1
- package/dist/runtime/harness/events/runtime-event-operations.d.ts +1 -1
- package/dist/runtime/harness/events/streaming.js +1 -1
- package/dist/runtime/harness/public-shapes.d.ts +43 -0
- package/dist/runtime/harness/public-shapes.js +186 -0
- package/dist/runtime/harness/run/inspection.js +2 -2
- package/dist/runtime/harness/run/resources.js +1 -1
- package/dist/runtime/harness/run/surface-semantics.js +1 -1
- package/dist/runtime/harness/system/inventory.d.ts +1 -1
- package/dist/runtime/harness/system/inventory.js +2 -2
- package/dist/runtime/harness/system/policy-engine.js +1 -1
- package/dist/runtime/harness/system/runtime-memory-manager.js +1 -1
- package/dist/runtime/harness/system/skill-requirements.d.ts +1 -1
- package/dist/runtime/harness/system/skill-requirements.js +1 -1
- package/dist/runtime/harness.d.ts +3 -2
- package/dist/runtime/harness.js +11 -191
- package/dist/runtime/maintenance/checkpoint-maintenance.js +1 -1
- package/dist/runtime/maintenance/runtime-record-maintenance.js +1 -1
- package/dist/runtime/parsing/output-content.d.ts +11 -0
- package/dist/runtime/parsing/output-content.js +442 -0
- package/dist/runtime/parsing/output-parsing.d.ts +3 -29
- package/dist/runtime/parsing/output-parsing.js +3 -806
- package/dist/runtime/parsing/output-recovery.d.ts +14 -0
- package/dist/runtime/parsing/output-recovery.js +288 -0
- package/dist/runtime/parsing/output-tool-args.d.ts +4 -0
- package/dist/runtime/parsing/output-tool-args.js +120 -0
- package/dist/runtime/support/runtime-factories.js +1 -1
- package/dist/scaffold/init-project.d.ts +12 -0
- package/dist/scaffold/init-project.js +651 -0
- package/dist/{extensions.d.ts → tooling/extensions.d.ts} +1 -1
- package/dist/{extensions.js → tooling/extensions.js} +3 -3
- package/dist/{tool-modules.d.ts → tooling/module-loader.d.ts} +1 -1
- package/dist/{tool-modules.js → tooling/module-loader.js} +2 -2
- package/dist/workspace/agent-binding-compiler.js +2 -2
- package/dist/workspace/compile.js +2 -2
- package/dist/workspace/object-loader-paths.d.ts +11 -0
- package/dist/workspace/object-loader-paths.js +75 -0
- package/dist/workspace/object-loader-readers.d.ts +21 -0
- package/dist/workspace/object-loader-readers.js +187 -0
- package/dist/workspace/object-loader.d.ts +0 -1
- package/dist/workspace/object-loader.js +6 -260
- package/dist/workspace/resource-compilers.js +1 -1
- package/dist/workspace/support/discovery.js +1 -1
- package/package.json +1 -1
- package/dist/runtime/adapter/index.d.ts +0 -13
- package/dist/runtime/adapter/index.js +0 -13
- package/dist/runtime/harness/index.d.ts +0 -19
- package/dist/runtime/harness/index.js +0 -19
- package/dist/runtime/maintenance/index.d.ts +0 -4
- package/dist/runtime/maintenance/index.js +0 -4
- package/dist/runtime/parsing/index.d.ts +0 -2
- package/dist/runtime/parsing/index.js +0 -2
- package/dist/runtime/support/index.d.ts +0 -4
- package/dist/runtime/support/index.js +0 -4
- package/dist/workspace/support/index.d.ts +0 -2
- package/dist/workspace/support/index.js +0 -2
- /package/dist/{procedural → knowledge/procedural}/config.d.ts +0 -0
- /package/dist/{procedural → knowledge/procedural}/config.js +0 -0
- /package/dist/{procedural → knowledge/procedural}/index.d.ts +0 -0
- /package/dist/{procedural → knowledge/procedural}/index.js +0 -0
- /package/dist/{presentation.d.ts → projections/presentation.d.ts} +0 -0
- /package/dist/{presentation.js → projections/presentation.js} +0 -0
- /package/dist/{request-events.js → projections/request-events.js} +0 -0
- /package/dist/{upstream-events.d.ts → projections/upstream-events.d.ts} +0 -0
- /package/dist/runtime/{support → env}/runtime-env.d.ts +0 -0
- /package/dist/runtime/{support → env}/runtime-env.js +0 -0
- /package/dist/runtime/{support → layout}/runtime-layout.d.ts +0 -0
- /package/dist/runtime/{support → layout}/runtime-layout.js +0 -0
- /package/dist/runtime/{support → prompts}/runtime-prompts.d.ts +0 -0
- /package/dist/runtime/{support → prompts}/runtime-prompts.js +0 -0
- /package/dist/runtime/{support → skills}/skill-metadata.d.ts +0 -0
- /package/dist/runtime/{support → skills}/skill-metadata.js +0 -0
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
import { AIMessage } from "langchain";
|
|
2
|
+
import { salvageToolArgs, isLikelyToolArgsObject, normalizeKnownToolArgs, tryParseJson } from "./output-tool-args.js";
|
|
3
|
+
export function sanitizeVisibleText(value) {
|
|
4
|
+
return value
|
|
5
|
+
.replace(/[A-Za-z0-9_]*Middleware\.after_model/g, "")
|
|
6
|
+
.replace(/todoListMiddleware\.after_model/g, "")
|
|
7
|
+
.replace(/__end__+/g, "")
|
|
8
|
+
.trim();
|
|
9
|
+
}
|
|
10
|
+
function isLikelyMemoryWriteArgsObject(value) {
|
|
11
|
+
if (typeof value !== "object" || !value || Array.isArray(value)) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
const typed = value;
|
|
15
|
+
const target = typeof typed.file_path === "string"
|
|
16
|
+
? typed.file_path
|
|
17
|
+
: typeof typed.path === "string"
|
|
18
|
+
? typed.path
|
|
19
|
+
: "";
|
|
20
|
+
return target.startsWith("/memories/") && typeof typed.content === "string";
|
|
21
|
+
}
|
|
22
|
+
export function readTextContent(value) {
|
|
23
|
+
if (typeof value === "string")
|
|
24
|
+
return value;
|
|
25
|
+
if (Array.isArray(value))
|
|
26
|
+
return value.map((item) => readTextContent(item)).join("");
|
|
27
|
+
if (typeof value === "object" && value) {
|
|
28
|
+
if (isLikelyMemoryWriteArgsObject(value)) {
|
|
29
|
+
return "";
|
|
30
|
+
}
|
|
31
|
+
if ("text" in value && typeof value.text === "string") {
|
|
32
|
+
return value.text;
|
|
33
|
+
}
|
|
34
|
+
if ("content" in value) {
|
|
35
|
+
return readTextContent(value.content);
|
|
36
|
+
}
|
|
37
|
+
if ("lc_kwargs" in value && typeof value.lc_kwargs === "object") {
|
|
38
|
+
return readTextContent((value.lc_kwargs).content);
|
|
39
|
+
}
|
|
40
|
+
if ("kwargs" in value && typeof value.kwargs === "object") {
|
|
41
|
+
return readTextContent((value.kwargs).content);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return "";
|
|
45
|
+
}
|
|
46
|
+
function extractMessageContent(message) {
|
|
47
|
+
if (typeof message !== "object" || !message)
|
|
48
|
+
return "";
|
|
49
|
+
const typed = message;
|
|
50
|
+
if (typed.content !== undefined)
|
|
51
|
+
return readTextContent(typed.content);
|
|
52
|
+
if (typeof typed.kwargs === "object" && typed.kwargs) {
|
|
53
|
+
return readTextContent(typed.kwargs.content);
|
|
54
|
+
}
|
|
55
|
+
return "";
|
|
56
|
+
}
|
|
57
|
+
function isToolMessageLike(message) {
|
|
58
|
+
if (typeof message !== "object" || !message)
|
|
59
|
+
return false;
|
|
60
|
+
const typed = message;
|
|
61
|
+
const ids = Array.isArray(typed.id) ? typed.id.filter((item) => typeof item === "string") : [];
|
|
62
|
+
const typeName = ids.at(-1);
|
|
63
|
+
const runtimeType = typeof typed._getType === "function"
|
|
64
|
+
? typed._getType()
|
|
65
|
+
: typeof typed.getType === "function"
|
|
66
|
+
? typed.getType()
|
|
67
|
+
: undefined;
|
|
68
|
+
return typeName === "ToolMessage" || runtimeType === "tool";
|
|
69
|
+
}
|
|
70
|
+
function extractToolMessageContents(messages) {
|
|
71
|
+
if (!Array.isArray(messages))
|
|
72
|
+
return [];
|
|
73
|
+
const results = [];
|
|
74
|
+
for (const message of messages) {
|
|
75
|
+
if (!isToolMessageLike(message))
|
|
76
|
+
continue;
|
|
77
|
+
const content = extractMessageContent(message);
|
|
78
|
+
if (content)
|
|
79
|
+
results.push(content);
|
|
80
|
+
}
|
|
81
|
+
return results;
|
|
82
|
+
}
|
|
83
|
+
export function hasToolCalls(value) {
|
|
84
|
+
if (typeof value !== "object" || !value)
|
|
85
|
+
return false;
|
|
86
|
+
const typed = value;
|
|
87
|
+
if (Array.isArray(typed.tool_calls) && typed.tool_calls.length > 0)
|
|
88
|
+
return true;
|
|
89
|
+
if (typeof typed.kwargs === "object" && typed.kwargs) {
|
|
90
|
+
return Array.isArray(typed.kwargs.tool_calls) && typed.kwargs.tool_calls.length > 0;
|
|
91
|
+
}
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
function extractAssistantTextFromMessages(messages) {
|
|
95
|
+
if (!Array.isArray(messages))
|
|
96
|
+
return "";
|
|
97
|
+
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
98
|
+
const message = messages[index];
|
|
99
|
+
if (typeof message !== "object" || !message)
|
|
100
|
+
continue;
|
|
101
|
+
const typed = message;
|
|
102
|
+
const explicitRole = typeof typed.role === "string" ? typed.role.trim().toLowerCase() : undefined;
|
|
103
|
+
if (explicitRole === "assistant" || explicitRole === "ai") {
|
|
104
|
+
const content = extractMessageContent(message);
|
|
105
|
+
if (content)
|
|
106
|
+
return content;
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
const ids = Array.isArray(typed.id) ? typed.id.filter((item) => typeof item === "string") : [];
|
|
110
|
+
const typeName = ids.at(-1);
|
|
111
|
+
const runtimeType = typeof message._getType === "function"
|
|
112
|
+
? message._getType()
|
|
113
|
+
: typeof message.getType === "function"
|
|
114
|
+
? message.getType()
|
|
115
|
+
: undefined;
|
|
116
|
+
if (!(typeName === "AIMessage" || runtimeType === "ai"))
|
|
117
|
+
continue;
|
|
118
|
+
const kwargs = typeof typed.kwargs === "object" && typed.kwargs ? typed.kwargs : undefined;
|
|
119
|
+
if (hasToolCalls(message))
|
|
120
|
+
continue;
|
|
121
|
+
if (Array.isArray(kwargs?.tool_calls) && kwargs.tool_calls.length > 0)
|
|
122
|
+
continue;
|
|
123
|
+
const content = extractMessageContent(message);
|
|
124
|
+
if (content)
|
|
125
|
+
return content;
|
|
126
|
+
}
|
|
127
|
+
return "";
|
|
128
|
+
}
|
|
129
|
+
function extractEmptyAssistantMessageReason(messages) {
|
|
130
|
+
if (!Array.isArray(messages))
|
|
131
|
+
return null;
|
|
132
|
+
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
133
|
+
const message = messages[index];
|
|
134
|
+
if (typeof message !== "object" || !message)
|
|
135
|
+
continue;
|
|
136
|
+
const typed = message;
|
|
137
|
+
const ids = Array.isArray(typed.id) ? typed.id.filter((item) => typeof item === "string") : [];
|
|
138
|
+
const typeName = ids.at(-1);
|
|
139
|
+
const runtimeType = typeof message._getType === "function"
|
|
140
|
+
? message._getType()
|
|
141
|
+
: typeof message.getType === "function"
|
|
142
|
+
? message.getType()
|
|
143
|
+
: undefined;
|
|
144
|
+
const kwargs = typeof typed.kwargs === "object" && typed.kwargs ? typed.kwargs : undefined;
|
|
145
|
+
if (!(typeName === "AIMessage" || runtimeType === "ai")) {
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
if (hasToolCalls(message)) {
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
const content = extractMessageContent(message).trim();
|
|
152
|
+
if (content) {
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
const responseMetadata = typeof kwargs?.response_metadata === "object" && kwargs.response_metadata
|
|
156
|
+
? kwargs.response_metadata
|
|
157
|
+
: {};
|
|
158
|
+
return {
|
|
159
|
+
finishReason: typeof responseMetadata.finish_reason === "string" ? responseMetadata.finish_reason : undefined,
|
|
160
|
+
modelProvider: typeof responseMetadata.model_provider === "string" ? responseMetadata.model_provider : undefined,
|
|
161
|
+
modelName: typeof responseMetadata.model_name === "string" ? responseMetadata.model_name : undefined,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
function extractStructuredOutputText(value) {
|
|
167
|
+
if (typeof value !== "object" || !value)
|
|
168
|
+
return "";
|
|
169
|
+
if (isLikelyMemoryWriteArgsObject(value))
|
|
170
|
+
return "";
|
|
171
|
+
const typed = value;
|
|
172
|
+
const fromMessages = extractAssistantTextFromMessages(typed.messages);
|
|
173
|
+
if (fromMessages)
|
|
174
|
+
return fromMessages;
|
|
175
|
+
if (typed.output && typeof typed.output === "object") {
|
|
176
|
+
const outputRecord = typed.output;
|
|
177
|
+
const nestedMessages = extractAssistantTextFromMessages(outputRecord.messages);
|
|
178
|
+
if (nestedMessages)
|
|
179
|
+
return nestedMessages;
|
|
180
|
+
const nestedContent = readTextContent(outputRecord.content);
|
|
181
|
+
if (nestedContent)
|
|
182
|
+
return nestedContent;
|
|
183
|
+
}
|
|
184
|
+
return readTextContent(typed.content);
|
|
185
|
+
}
|
|
186
|
+
function normalizePotentialLineNumberedDocument(value) {
|
|
187
|
+
return value
|
|
188
|
+
.split("\n")
|
|
189
|
+
.map((line) => line.replace(/^\s*\d+\s+/, ""))
|
|
190
|
+
.join("\n")
|
|
191
|
+
.trim();
|
|
192
|
+
}
|
|
193
|
+
function isLikelySkillDocumentText(value) {
|
|
194
|
+
const normalized = normalizePotentialLineNumberedDocument(value);
|
|
195
|
+
if (!normalized.startsWith("---")) {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
const lower = normalized.toLowerCase();
|
|
199
|
+
return (lower.includes("\nname: ") &&
|
|
200
|
+
lower.includes("\ndescription: ") &&
|
|
201
|
+
lower.includes("\n# ") &&
|
|
202
|
+
lower.includes("## workflow"));
|
|
203
|
+
}
|
|
204
|
+
export function containsLikelySkillDocument(value) {
|
|
205
|
+
if (typeof value === "string") {
|
|
206
|
+
return isLikelySkillDocumentText(value);
|
|
207
|
+
}
|
|
208
|
+
if (Array.isArray(value)) {
|
|
209
|
+
return value.some((item) => containsLikelySkillDocument(item));
|
|
210
|
+
}
|
|
211
|
+
if (typeof value === "object" && value) {
|
|
212
|
+
const typed = value;
|
|
213
|
+
if (typed.content !== undefined && containsLikelySkillDocument(typed.content)) {
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
216
|
+
if (typed.output !== undefined && containsLikelySkillDocument(typed.output)) {
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
219
|
+
if (typed.messages !== undefined && containsLikelySkillDocument(typed.messages)) {
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
if (typed.kwargs !== undefined && containsLikelySkillDocument(typed.kwargs)) {
|
|
223
|
+
return true;
|
|
224
|
+
}
|
|
225
|
+
return Object.values(typed).some((item) => containsLikelySkillDocument(item));
|
|
226
|
+
}
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
export function extractToolFallbackContext(value) {
|
|
230
|
+
if (typeof value !== "object" || !value)
|
|
231
|
+
return "";
|
|
232
|
+
const typed = value;
|
|
233
|
+
const messages = extractToolMessageContents(typed.messages).filter((message) => !isLikelySkillDocumentText(message));
|
|
234
|
+
if (messages.length > 0)
|
|
235
|
+
return messages.slice(-3).join("\n\n");
|
|
236
|
+
if (typed.output && typeof typed.output === "object") {
|
|
237
|
+
const nested = extractToolFallbackContext(typed.output);
|
|
238
|
+
if (nested)
|
|
239
|
+
return nested;
|
|
240
|
+
}
|
|
241
|
+
return "";
|
|
242
|
+
}
|
|
243
|
+
export function extractVisibleOutput(value) {
|
|
244
|
+
const structured = extractStructuredOutputText(value);
|
|
245
|
+
if (structured && !isLikelySkillDocumentText(structured))
|
|
246
|
+
return structured;
|
|
247
|
+
if (typeof value === "string") {
|
|
248
|
+
const parsed = tryParseJson(value);
|
|
249
|
+
if (parsed) {
|
|
250
|
+
if (isLikelyMemoryWriteArgsObject(parsed))
|
|
251
|
+
return "";
|
|
252
|
+
const parsedStructured = extractStructuredOutputText(parsed);
|
|
253
|
+
if (parsedStructured && !isLikelySkillDocumentText(parsedStructured))
|
|
254
|
+
return parsedStructured;
|
|
255
|
+
if (isLikelyToolArgsObject(parsed))
|
|
256
|
+
return "";
|
|
257
|
+
}
|
|
258
|
+
if (isLikelySkillDocumentText(value))
|
|
259
|
+
return "";
|
|
260
|
+
return value;
|
|
261
|
+
}
|
|
262
|
+
if (typeof value === "object" && value) {
|
|
263
|
+
const typed = value;
|
|
264
|
+
if (typed.output !== undefined) {
|
|
265
|
+
const nested = extractVisibleOutput(typed.output);
|
|
266
|
+
if (nested)
|
|
267
|
+
return nested;
|
|
268
|
+
}
|
|
269
|
+
if (typed.content !== undefined) {
|
|
270
|
+
const nested = extractVisibleOutput(typed.content);
|
|
271
|
+
if (nested)
|
|
272
|
+
return nested;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return "";
|
|
276
|
+
}
|
|
277
|
+
function isContentBlock(value) {
|
|
278
|
+
return typeof value === "object" && value !== null && typeof value.type === "string";
|
|
279
|
+
}
|
|
280
|
+
function normalizeContentBlocks(value) {
|
|
281
|
+
if (!Array.isArray(value)) {
|
|
282
|
+
return [];
|
|
283
|
+
}
|
|
284
|
+
return value.filter(isContentBlock).map((block) => ({ ...block }));
|
|
285
|
+
}
|
|
286
|
+
function extractStructuredOutputContent(value) {
|
|
287
|
+
if (typeof value !== "object" || !value)
|
|
288
|
+
return undefined;
|
|
289
|
+
const typed = value;
|
|
290
|
+
if (typed.output && typeof typed.output === "object") {
|
|
291
|
+
const nested = extractStructuredOutputContent(typed.output);
|
|
292
|
+
if (nested !== undefined)
|
|
293
|
+
return nested;
|
|
294
|
+
}
|
|
295
|
+
if (typed.content !== undefined) {
|
|
296
|
+
return typed.content;
|
|
297
|
+
}
|
|
298
|
+
if (!Array.isArray(typed.messages)) {
|
|
299
|
+
return undefined;
|
|
300
|
+
}
|
|
301
|
+
for (let index = typed.messages.length - 1; index >= 0; index -= 1) {
|
|
302
|
+
const message = typed.messages[index];
|
|
303
|
+
if (typeof message !== "object" || !message)
|
|
304
|
+
continue;
|
|
305
|
+
const ids = Array.isArray(message.id)
|
|
306
|
+
? (message.id.filter((item) => typeof item === "string"))
|
|
307
|
+
: [];
|
|
308
|
+
const typeName = ids.at(-1);
|
|
309
|
+
const runtimeType = typeof message._getType === "function"
|
|
310
|
+
? message._getType()
|
|
311
|
+
: typeof message.getType === "function"
|
|
312
|
+
? message.getType()
|
|
313
|
+
: undefined;
|
|
314
|
+
if (!(typeName === "AIMessage" || runtimeType === "ai")) {
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
if (hasToolCalls(message)) {
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
const directContent = message.content;
|
|
321
|
+
if (directContent !== undefined) {
|
|
322
|
+
return directContent;
|
|
323
|
+
}
|
|
324
|
+
const kwargs = typeof message.kwargs === "object" && message.kwargs
|
|
325
|
+
? (message.kwargs)
|
|
326
|
+
: undefined;
|
|
327
|
+
if (kwargs?.content !== undefined) {
|
|
328
|
+
return kwargs.content;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
return undefined;
|
|
332
|
+
}
|
|
333
|
+
export function extractOutputContent(value) {
|
|
334
|
+
const content = extractStructuredOutputContent(value);
|
|
335
|
+
if (content !== undefined) {
|
|
336
|
+
return content;
|
|
337
|
+
}
|
|
338
|
+
return undefined;
|
|
339
|
+
}
|
|
340
|
+
export function extractContentBlocks(value) {
|
|
341
|
+
const outputContent = extractOutputContent(value);
|
|
342
|
+
if (outputContent === undefined) {
|
|
343
|
+
return [];
|
|
344
|
+
}
|
|
345
|
+
if (typeof outputContent === "string") {
|
|
346
|
+
return outputContent.trim() ? [{ type: "text", text: outputContent }] : [];
|
|
347
|
+
}
|
|
348
|
+
return normalizeContentBlocks(outputContent);
|
|
349
|
+
}
|
|
350
|
+
export function extractEmptyAssistantMessageFailure(value) {
|
|
351
|
+
if (typeof value !== "object" || !value)
|
|
352
|
+
return "";
|
|
353
|
+
const typed = value;
|
|
354
|
+
const reason = extractEmptyAssistantMessageReason(typed.messages)
|
|
355
|
+
?? (typeof typed.output === "object" && typed.output
|
|
356
|
+
? extractEmptyAssistantMessageReason(typed.output.messages)
|
|
357
|
+
: null);
|
|
358
|
+
if (!reason) {
|
|
359
|
+
return "";
|
|
360
|
+
}
|
|
361
|
+
const detailParts = [
|
|
362
|
+
reason.finishReason ? `finish_reason=${reason.finishReason}` : "",
|
|
363
|
+
reason.modelProvider ? `model_provider=${reason.modelProvider}` : "",
|
|
364
|
+
reason.modelName ? `model_name=${reason.modelName}` : "",
|
|
365
|
+
].filter(Boolean);
|
|
366
|
+
return [
|
|
367
|
+
"empty_final_ai_message: model returned no visible assistant content and no tool calls",
|
|
368
|
+
detailParts.length > 0 ? `(${detailParts.join(", ")})` : "",
|
|
369
|
+
].filter(Boolean).join(" ");
|
|
370
|
+
}
|
|
371
|
+
function isAiMessageLike(value) {
|
|
372
|
+
if (typeof value !== "object" || !value)
|
|
373
|
+
return false;
|
|
374
|
+
const typed = value;
|
|
375
|
+
return typeof typed._getType === "function" && typed._getType() === "ai" && ("content" in typed || "tool_calls" in typed);
|
|
376
|
+
}
|
|
377
|
+
function normalizeAgentMessage(value) {
|
|
378
|
+
if (!AIMessage.isInstance(value) && !isAiMessageLike(value))
|
|
379
|
+
return value;
|
|
380
|
+
const typed = value;
|
|
381
|
+
const normalizedToolCalls = Array.isArray(typed.tool_calls)
|
|
382
|
+
? typed.tool_calls.map((toolCall) => {
|
|
383
|
+
if (typeof toolCall !== "object" || !toolCall)
|
|
384
|
+
return toolCall;
|
|
385
|
+
const parsedArgs = salvageToolArgs(toolCall.args);
|
|
386
|
+
return parsedArgs ? { ...toolCall, args: normalizeKnownToolArgs(toolCall.name, parsedArgs) } : toolCall;
|
|
387
|
+
})
|
|
388
|
+
: [];
|
|
389
|
+
const normalizedInvalidToolCalls = Array.isArray(typed.invalid_tool_calls)
|
|
390
|
+
? typed.invalid_tool_calls
|
|
391
|
+
.map((toolCall) => {
|
|
392
|
+
if (typeof toolCall !== "object" || !toolCall)
|
|
393
|
+
return null;
|
|
394
|
+
const parsedArgs = salvageToolArgs(toolCall.args);
|
|
395
|
+
if (!parsedArgs)
|
|
396
|
+
return toolCall;
|
|
397
|
+
return {
|
|
398
|
+
...toolCall,
|
|
399
|
+
args: normalizeKnownToolArgs(toolCall.name, parsedArgs),
|
|
400
|
+
type: "tool_call",
|
|
401
|
+
error: undefined,
|
|
402
|
+
};
|
|
403
|
+
})
|
|
404
|
+
.filter((toolCall) => toolCall !== null)
|
|
405
|
+
: [];
|
|
406
|
+
const recoveredToolCalls = normalizedInvalidToolCalls.filter((toolCall) => typeof toolCall.args === "object" && !!toolCall.args && !Array.isArray(toolCall.args));
|
|
407
|
+
const normalizedContent = typeof typed.content === "string" || Array.isArray(typed.content)
|
|
408
|
+
? typed.content
|
|
409
|
+
: typeof typed.content === "object" && typed.content
|
|
410
|
+
? readTextContent(typed.content)
|
|
411
|
+
: "";
|
|
412
|
+
return new AIMessage({
|
|
413
|
+
content: normalizedContent,
|
|
414
|
+
name: typeof typed.name === "string" ? typed.name : undefined,
|
|
415
|
+
additional_kwargs: typeof typed.additional_kwargs === "object" && typed.additional_kwargs ? typed.additional_kwargs : {},
|
|
416
|
+
response_metadata: typeof typed.response_metadata === "object" && typed.response_metadata ? typed.response_metadata : {},
|
|
417
|
+
id: typeof typed.id === "string" ? typed.id : undefined,
|
|
418
|
+
tool_calls: [...normalizedToolCalls, ...recoveredToolCalls],
|
|
419
|
+
invalid_tool_calls: normalizedInvalidToolCalls.filter((toolCall) => toolCall.type !== "tool_call"),
|
|
420
|
+
usage_metadata: typeof typed.usage_metadata === "object" && typed.usage_metadata ? typed.usage_metadata : undefined,
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
export function wrapNormalizedMessage(value) {
|
|
424
|
+
return normalizeAgentMessage(value);
|
|
425
|
+
}
|
|
426
|
+
export function extractReasoningText(value) {
|
|
427
|
+
if (typeof value !== "object" || !value)
|
|
428
|
+
return "";
|
|
429
|
+
const typed = value;
|
|
430
|
+
const chunk = typed.data?.chunk ?? value;
|
|
431
|
+
if (typeof chunk !== "object" || !chunk)
|
|
432
|
+
return "";
|
|
433
|
+
if ("additional_kwargs" in chunk && typeof chunk.additional_kwargs === "object") {
|
|
434
|
+
const kwargs = chunk.additional_kwargs;
|
|
435
|
+
return typeof kwargs?.reasoning === "string" ? kwargs.reasoning : "";
|
|
436
|
+
}
|
|
437
|
+
if ("kwargs" in chunk && typeof chunk.kwargs === "object") {
|
|
438
|
+
const kwargs = chunk.kwargs;
|
|
439
|
+
return typeof kwargs?.additional_kwargs?.reasoning === "string" ? kwargs.additional_kwargs.reasoning : "";
|
|
440
|
+
}
|
|
441
|
+
return "";
|
|
442
|
+
}
|
|
@@ -1,29 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
export
|
|
4
|
-
export declare function tryParseJson(value: string): unknown | null;
|
|
5
|
-
export declare function salvageToolArgs(value: unknown): Record<string, unknown> | null;
|
|
6
|
-
export declare function isLikelyToolArgsObject(value: unknown): boolean;
|
|
7
|
-
export declare function readTextContent(value: unknown): string;
|
|
8
|
-
export declare function hasToolCalls(value: unknown): boolean;
|
|
9
|
-
export declare function containsLikelySkillDocument(value: unknown): boolean;
|
|
10
|
-
export declare function extractToolFallbackContext(value: unknown): string;
|
|
11
|
-
export declare function extractVisibleOutput(value: unknown): string;
|
|
12
|
-
export declare function extractOutputContent(value: unknown): unknown;
|
|
13
|
-
export declare function extractContentBlocks(value: unknown): unknown[];
|
|
14
|
-
export declare function extractEmptyAssistantMessageFailure(value: unknown): string;
|
|
15
|
-
export declare function isToolCallParseFailure(error: unknown): boolean;
|
|
16
|
-
export declare function isToolCallValidationFailure(error: unknown): boolean;
|
|
17
|
-
export declare function isToolCallRecoveryFailure(error: unknown): boolean;
|
|
18
|
-
export declare function isWorkspacePathScopeFailure(error: unknown): boolean;
|
|
19
|
-
export declare function isRepairableWriteTodosPlaceholderFailure(error: unknown): boolean;
|
|
20
|
-
export declare function isRetrySafeInvalidToolSelectionError(value: unknown): boolean;
|
|
21
|
-
export declare function shouldValidateExecutionWithoutToolEvidence(request: unknown): boolean;
|
|
22
|
-
export declare function resolveExecutionWithoutToolEvidenceInstruction(request: unknown, result: unknown): string | null;
|
|
23
|
-
export declare function resolveExecutionWithoutToolEvidenceTextInstruction(request: unknown, assistantText: string, toolCallEvidence?: boolean): string | null;
|
|
24
|
-
export declare function isRepairableWriteTodosContentFailure(error: unknown): boolean;
|
|
25
|
-
export declare function isRepairableWriteTodosEmptyFailure(error: unknown): boolean;
|
|
26
|
-
export declare function resolveToolCallRecoveryInstruction(error: unknown): string | null;
|
|
27
|
-
export declare function appendToolRecoveryInstruction(input: unknown, instruction: string): unknown;
|
|
28
|
-
export declare function wrapResolvedModel<T>(value: T): T;
|
|
29
|
-
export declare function extractReasoningText(value: unknown): string;
|
|
1
|
+
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_DESCRIPTIVE_CONTENT_INSTRUCTION, WRITE_TODOS_FULL_ENTRY_INSTRUCTION, WRITE_TODOS_NON_EMPTY_INITIAL_LIST_INSTRUCTION, appendToolRecoveryInstruction, isRepairableWriteTodosContentFailure, isRepairableWriteTodosEmptyFailure, isRepairableWriteTodosPlaceholderFailure, isRetrySafeInvalidToolSelectionError, isToolCallRecoveryFailure, isToolCallValidationFailure, isWorkspacePathScopeFailure, resolveExecutionWithoutToolEvidenceInstruction, resolveExecutionWithoutToolEvidenceTextInstruction, resolveToolCallRecoveryInstruction, shouldValidateExecutionWithoutToolEvidence, wrapResolvedModel, } from "./output-recovery.js";
|
|
2
|
+
export { containsLikelySkillDocument, extractContentBlocks, extractEmptyAssistantMessageFailure, extractOutputContent, extractReasoningText, extractToolFallbackContext, extractVisibleOutput, hasToolCalls, readTextContent, sanitizeVisibleText, } from "./output-content.js";
|
|
3
|
+
export { isLikelyToolArgsObject, salvageToolArgs, tryParseJson, } from "./output-tool-args.js";
|