@band-ai/sdk 0.1.2
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/dist/CodexAdapter-A1k_LMdZ.d.ts +1278 -0
- package/dist/CodexAdapter-BbZD-nBd.d.cts +1278 -0
- package/dist/adapters.cjs +10643 -0
- package/dist/adapters.d.cts +217 -0
- package/dist/adapters.d.ts +217 -0
- package/dist/adapters.js +92 -0
- package/dist/backends-BnOLsG7w.d.cts +20 -0
- package/dist/backends-C4n6cKOf.d.ts +20 -0
- package/dist/chunk-3BKAC4OZ.js +44 -0
- package/dist/chunk-5CXIMAH2.js +52 -0
- package/dist/chunk-6AJA2OPC.js +3682 -0
- package/dist/chunk-A3TDK6GP.js +6674 -0
- package/dist/chunk-AVVDPXP4.js +39 -0
- package/dist/chunk-EDPKUUJL.js +177 -0
- package/dist/chunk-FUODYQRE.js +2562 -0
- package/dist/chunk-GVEQ3RAH.js +373 -0
- package/dist/chunk-INA6YZTZ.js +88 -0
- package/dist/chunk-IZPV6QS6.js +115 -0
- package/dist/chunk-LY55KYVI.js +0 -0
- package/dist/chunk-NIAQBANR.js +577 -0
- package/dist/chunk-OD2G5LFQ.js +78 -0
- package/dist/chunk-SFVKOEQH.js +103 -0
- package/dist/chunk-SG4WLD2H.js +1093 -0
- package/dist/chunk-YR3BOQNW.js +39 -0
- package/dist/chunk-ZZJRRBPQ.js +82 -0
- package/dist/claude-CcnQ5OUC.d.ts +53 -0
- package/dist/claude-CwTAxhwI.d.cts +53 -0
- package/dist/config.cjs +164 -0
- package/dist/config.d.cts +19 -0
- package/dist/config.d.ts +19 -0
- package/dist/config.js +9 -0
- package/dist/converters.cjs +1086 -0
- package/dist/converters.d.cts +143 -0
- package/dist/converters.d.ts +143 -0
- package/dist/converters.js +468 -0
- package/dist/core.cjs +185 -0
- package/dist/core.d.cts +22 -0
- package/dist/core.d.ts +22 -0
- package/dist/core.js +24 -0
- package/dist/customTools-BzF0IISO.d.cts +10 -0
- package/dist/customTools-BzF0IISO.d.ts +10 -0
- package/dist/dtos-DUpbIu8k.d.cts +163 -0
- package/dist/dtos-DUpbIu8k.d.ts +163 -0
- package/dist/history-ByessXNq.d.ts +24 -0
- package/dist/history-i6yN7neC.d.cts +24 -0
- package/dist/index.cjs +13914 -0
- package/dist/index.d.cts +63 -0
- package/dist/index.d.ts +63 -0
- package/dist/index.js +198 -0
- package/dist/linear.cjs +2207 -0
- package/dist/linear.d.cts +167 -0
- package/dist/linear.d.ts +167 -0
- package/dist/linear.js +2139 -0
- package/dist/logger-CABQOnlR.d.cts +21 -0
- package/dist/logger-CABQOnlR.d.ts +21 -0
- package/dist/mcp-claude.cjs +584 -0
- package/dist/mcp-claude.d.cts +4 -0
- package/dist/mcp-claude.d.ts +4 -0
- package/dist/mcp-claude.js +11 -0
- package/dist/mcp.cjs +1247 -0
- package/dist/mcp.d.cts +97 -0
- package/dist/mcp.d.ts +97 -0
- package/dist/mcp.js +27 -0
- package/dist/opencode-BBcDchcN.d.cts +159 -0
- package/dist/opencode-DthQQUsZ.d.ts +159 -0
- package/dist/pagination-BPiys10t.d.cts +25 -0
- package/dist/pagination-CcDkVFxK.d.ts +25 -0
- package/dist/protocols-CInhtFpA.d.cts +116 -0
- package/dist/protocols-DrhzOH6K.d.ts +116 -0
- package/dist/rest.cjs +1159 -0
- package/dist/rest.d.cts +144 -0
- package/dist/rest.d.ts +144 -0
- package/dist/rest.js +18 -0
- package/dist/runtime.cjs +5353 -0
- package/dist/runtime.d.cts +276 -0
- package/dist/runtime.d.ts +276 -0
- package/dist/runtime.js +274 -0
- package/dist/schemas-BpEBkq5V.d.cts +592 -0
- package/dist/schemas-vos1AaBc.d.ts +592 -0
- package/dist/sdk-HJUVSSWA.js +10 -0
- package/dist/simpleAdapter-9OE_p6QW.d.ts +29 -0
- package/dist/simpleAdapter-DqhvjsGr.d.cts +29 -0
- package/dist/testing.cjs +217 -0
- package/dist/testing.d.cts +126 -0
- package/dist/testing.d.ts +126 -0
- package/dist/testing.js +186 -0
- package/dist/types-7jVzOeOP.d.ts +446 -0
- package/dist/types-CSHFipIc.d.cts +331 -0
- package/dist/types-CovcHpYf.d.cts +446 -0
- package/dist/types-CxII3XkA.d.ts +331 -0
- package/package.json +189 -0
|
@@ -0,0 +1,1086 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/converters/index.ts
|
|
21
|
+
var converters_exports = {};
|
|
22
|
+
__export(converters_exports, {
|
|
23
|
+
A2AHistoryConverter: () => A2AHistoryConverter,
|
|
24
|
+
ACPClientHistoryConverter: () => ACPClientHistoryConverter,
|
|
25
|
+
ACPServerHistoryConverter: () => ACPServerHistoryConverter,
|
|
26
|
+
AnthropicHistoryConverter: () => AnthropicHistoryConverter,
|
|
27
|
+
ClaudeSDKHistoryConverter: () => ClaudeSDKHistoryConverter,
|
|
28
|
+
CodexHistoryConverter: () => CodexHistoryConverter,
|
|
29
|
+
GatewayHistoryConverter: () => GatewayHistoryConverter,
|
|
30
|
+
GeminiHistoryConverter: () => GeminiHistoryConverter,
|
|
31
|
+
GoogleADKHistoryConverter: () => GoogleADKHistoryConverter,
|
|
32
|
+
LangChainHistoryConverter: () => LangChainHistoryConverter,
|
|
33
|
+
OpencodeHistoryConverter: () => OpencodeHistoryConverter,
|
|
34
|
+
ParlantHistoryConverter: () => ParlantHistoryConverter,
|
|
35
|
+
VercelAISDKHistoryConverter: () => VercelAISDKHistoryConverter,
|
|
36
|
+
buildA2AAuthHeaders: () => buildA2AAuthHeaders,
|
|
37
|
+
extractClaudeSessionId: () => extractClaudeSessionId,
|
|
38
|
+
extractCodexSessionId: () => extractCodexSessionId,
|
|
39
|
+
extractGoogleAdkSessionId: () => extractGoogleAdkSessionId,
|
|
40
|
+
extractOpencodeSessionId: () => extractOpencodeSessionId
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(converters_exports);
|
|
43
|
+
|
|
44
|
+
// src/converters/acp-client.ts
|
|
45
|
+
var ACPClientHistoryConverter = class {
|
|
46
|
+
convert(raw) {
|
|
47
|
+
const roomToSession = {};
|
|
48
|
+
for (const entry of raw) {
|
|
49
|
+
const metadataRaw = entry.metadata;
|
|
50
|
+
if (!metadataRaw || typeof metadataRaw !== "object" || Array.isArray(metadataRaw)) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const metadata = metadataRaw;
|
|
54
|
+
const sessionId = metadata.acp_client_session_id;
|
|
55
|
+
const roomId = metadata.acp_client_room_id;
|
|
56
|
+
if (typeof sessionId === "string" && typeof roomId === "string" && sessionId && roomId) {
|
|
57
|
+
roomToSession[roomId] = sessionId;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return { roomToSession };
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// src/converters/acp-server.ts
|
|
65
|
+
var ACPServerHistoryConverter = class {
|
|
66
|
+
convert(raw) {
|
|
67
|
+
const sessionToRoom = {};
|
|
68
|
+
const sessionCwd = {};
|
|
69
|
+
const sessionMcpServers = {};
|
|
70
|
+
for (const entry of raw) {
|
|
71
|
+
const metadataRaw = entry.metadata;
|
|
72
|
+
if (!metadataRaw || typeof metadataRaw !== "object" || Array.isArray(metadataRaw)) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const metadata = metadataRaw;
|
|
76
|
+
const sessionId = metadata.acp_session_id;
|
|
77
|
+
if (typeof sessionId !== "string" || sessionId.length === 0) {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const roomId = typeof metadata.acp_room_id === "string" ? metadata.acp_room_id : typeof entry.room_id === "string" ? entry.room_id : null;
|
|
81
|
+
if (roomId) {
|
|
82
|
+
sessionToRoom[sessionId] = roomId;
|
|
83
|
+
}
|
|
84
|
+
if (typeof metadata.acp_cwd === "string" && metadata.acp_cwd.length > 0) {
|
|
85
|
+
sessionCwd[sessionId] = metadata.acp_cwd;
|
|
86
|
+
}
|
|
87
|
+
if (Array.isArray(metadata.acp_mcp_servers)) {
|
|
88
|
+
sessionMcpServers[sessionId] = metadata.acp_mcp_servers.filter((server) => !!server && typeof server === "object" && !Array.isArray(server));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
sessionToRoom,
|
|
93
|
+
sessionCwd,
|
|
94
|
+
sessionMcpServers
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
// src/converters/shared.ts
|
|
100
|
+
function asOptionalString(value) {
|
|
101
|
+
if (typeof value !== "string") {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
const trimmed = value.trim();
|
|
105
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
106
|
+
}
|
|
107
|
+
function parseDate(value) {
|
|
108
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
const parsed = new Date(value);
|
|
112
|
+
return Number.isNaN(parsed.getTime()) ? null : parsed;
|
|
113
|
+
}
|
|
114
|
+
function parseToolPayload(value) {
|
|
115
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
try {
|
|
119
|
+
const parsed = JSON.parse(value);
|
|
120
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
|
|
121
|
+
} catch {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function parseToolCall(value) {
|
|
126
|
+
const parsed = parseToolPayload(value);
|
|
127
|
+
const name = asOptionalString(parsed?.name);
|
|
128
|
+
const toolCallId = asOptionalString(parsed?.tool_call_id);
|
|
129
|
+
if (!name || !toolCallId) {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
const args = parsed?.args;
|
|
133
|
+
return {
|
|
134
|
+
name,
|
|
135
|
+
toolCallId,
|
|
136
|
+
args: args && typeof args === "object" && !Array.isArray(args) ? args : {}
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function parseToolResult(value) {
|
|
140
|
+
const parsed = parseToolPayload(value);
|
|
141
|
+
const name = asOptionalString(parsed?.name);
|
|
142
|
+
const toolCallId = asOptionalString(parsed?.tool_call_id);
|
|
143
|
+
if (!name || !toolCallId) {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
name,
|
|
148
|
+
toolCallId,
|
|
149
|
+
output: parsed?.output === void 0 ? "" : String(parsed.output),
|
|
150
|
+
isError: parsed?.is_error === true
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// src/converters/vercel-ai-sdk.ts
|
|
155
|
+
function flushPendingToolCalls(messages, pendingToolCalls) {
|
|
156
|
+
if (pendingToolCalls.length === 0) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
messages.push({
|
|
160
|
+
role: "assistant",
|
|
161
|
+
content: [...pendingToolCalls]
|
|
162
|
+
});
|
|
163
|
+
pendingToolCalls.length = 0;
|
|
164
|
+
}
|
|
165
|
+
function flushPendingToolResults(messages, pendingToolResults) {
|
|
166
|
+
if (pendingToolResults.length === 0) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
messages.push({
|
|
170
|
+
role: "tool",
|
|
171
|
+
content: [...pendingToolResults]
|
|
172
|
+
});
|
|
173
|
+
pendingToolResults.length = 0;
|
|
174
|
+
}
|
|
175
|
+
var VercelAISDKHistoryConverter = class {
|
|
176
|
+
agentName;
|
|
177
|
+
constructor(agentName = "") {
|
|
178
|
+
this.agentName = agentName;
|
|
179
|
+
}
|
|
180
|
+
setAgentName(name) {
|
|
181
|
+
this.agentName = name;
|
|
182
|
+
}
|
|
183
|
+
convert(raw) {
|
|
184
|
+
const messages = [];
|
|
185
|
+
const pendingToolCalls = [];
|
|
186
|
+
const pendingToolResults = [];
|
|
187
|
+
for (const entry of raw) {
|
|
188
|
+
const messageType = String(entry.message_type ?? "text");
|
|
189
|
+
const content = String(entry.content ?? "");
|
|
190
|
+
if (messageType === "tool_call") {
|
|
191
|
+
flushPendingToolResults(messages, pendingToolResults);
|
|
192
|
+
const parsed = parseToolCall(content);
|
|
193
|
+
if (parsed) {
|
|
194
|
+
pendingToolCalls.push({
|
|
195
|
+
type: "tool-call",
|
|
196
|
+
toolCallId: parsed.toolCallId,
|
|
197
|
+
toolName: parsed.name,
|
|
198
|
+
input: parsed.args
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
if (messageType === "tool_result") {
|
|
204
|
+
flushPendingToolCalls(messages, pendingToolCalls);
|
|
205
|
+
const parsed = parseToolResult(content);
|
|
206
|
+
if (parsed) {
|
|
207
|
+
pendingToolResults.push({
|
|
208
|
+
type: "tool-result",
|
|
209
|
+
toolCallId: parsed.toolCallId,
|
|
210
|
+
toolName: parsed.name,
|
|
211
|
+
output: parsed.isError ? { error: parsed.output } : parsed.output
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
if (messageType !== "text") {
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
flushPendingToolCalls(messages, pendingToolCalls);
|
|
220
|
+
flushPendingToolResults(messages, pendingToolResults);
|
|
221
|
+
const role = String(entry.role ?? "user");
|
|
222
|
+
const senderName = String(entry.sender_name ?? "");
|
|
223
|
+
if (role === "assistant" && senderName === this.agentName) {
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
messages.push({
|
|
227
|
+
role: "user",
|
|
228
|
+
content: senderName ? `[${senderName}]: ${content}` : content
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
flushPendingToolCalls(messages, pendingToolCalls);
|
|
232
|
+
flushPendingToolResults(messages, pendingToolResults);
|
|
233
|
+
return messages;
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
// src/adapters/a2a/A2AAdapter.ts
|
|
238
|
+
var import_node_crypto = require("crypto");
|
|
239
|
+
|
|
240
|
+
// src/adapters/shared/coercion.ts
|
|
241
|
+
function asOptionalRecord(value) {
|
|
242
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
243
|
+
return void 0;
|
|
244
|
+
}
|
|
245
|
+
return value;
|
|
246
|
+
}
|
|
247
|
+
function asNonEmptyString(value) {
|
|
248
|
+
if (typeof value !== "string") {
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
251
|
+
const trimmed = value.trim();
|
|
252
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// src/adapters/shared/history.ts
|
|
256
|
+
function findLatestTaskMetadata(raw, predicate) {
|
|
257
|
+
for (let index = raw.length - 1; index >= 0; index -= 1) {
|
|
258
|
+
const message = raw[index] ?? {};
|
|
259
|
+
const messageType = String(message.message_type ?? message.messageType ?? "");
|
|
260
|
+
if (messageType !== "task") {
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
const metadata = asOptionalRecord(message.metadata) ?? {};
|
|
264
|
+
if (predicate(metadata)) {
|
|
265
|
+
return metadata;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return null;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// src/adapters/a2a/types.ts
|
|
272
|
+
function buildA2AAuthHeaders(auth) {
|
|
273
|
+
const headers = {};
|
|
274
|
+
for (const [key, value] of Object.entries(auth?.headers ?? {})) {
|
|
275
|
+
headers[key] = sanitizeHeaderValue(value, key);
|
|
276
|
+
}
|
|
277
|
+
if (auth?.apiKey) {
|
|
278
|
+
headers["X-API-Key"] = sanitizeHeaderValue(auth.apiKey, "X-API-Key");
|
|
279
|
+
}
|
|
280
|
+
if (auth?.bearerToken) {
|
|
281
|
+
headers.Authorization = `Bearer ${sanitizeHeaderValue(auth.bearerToken, "Authorization")}`;
|
|
282
|
+
}
|
|
283
|
+
return headers;
|
|
284
|
+
}
|
|
285
|
+
function sanitizeHeaderValue(value, headerName) {
|
|
286
|
+
if (/[\r\n]/u.test(value)) {
|
|
287
|
+
throw new Error(`${headerName} header value must not contain CR or LF characters.`);
|
|
288
|
+
}
|
|
289
|
+
return value;
|
|
290
|
+
}
|
|
291
|
+
var A2AHistoryConverter = class {
|
|
292
|
+
convert(raw) {
|
|
293
|
+
const metadata = findLatestTaskMetadata(
|
|
294
|
+
raw,
|
|
295
|
+
(entry) => Object.prototype.hasOwnProperty.call(entry, "a2a_context_id")
|
|
296
|
+
);
|
|
297
|
+
if (metadata) {
|
|
298
|
+
return {
|
|
299
|
+
contextId: asNonEmptyString(metadata.a2a_context_id),
|
|
300
|
+
taskId: asNonEmptyString(metadata.a2a_task_id),
|
|
301
|
+
taskState: asNonEmptyString(metadata.a2a_task_state)
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
return {
|
|
305
|
+
contextId: null,
|
|
306
|
+
taskId: null,
|
|
307
|
+
taskState: null
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
// src/converters/anthropic.ts
|
|
313
|
+
function flushPendingToolCalls2(messages, pendingToolCalls) {
|
|
314
|
+
if (pendingToolCalls.length === 0) {
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
messages.push({
|
|
318
|
+
role: "assistant",
|
|
319
|
+
content: [...pendingToolCalls]
|
|
320
|
+
});
|
|
321
|
+
pendingToolCalls.length = 0;
|
|
322
|
+
}
|
|
323
|
+
function flushPendingToolResults2(messages, pendingToolResults) {
|
|
324
|
+
if (pendingToolResults.length === 0) {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
messages.push({
|
|
328
|
+
role: "user",
|
|
329
|
+
content: [...pendingToolResults]
|
|
330
|
+
});
|
|
331
|
+
pendingToolResults.length = 0;
|
|
332
|
+
}
|
|
333
|
+
function patchOrphanedToolUses(messages) {
|
|
334
|
+
for (let index = 0; index < messages.length; index += 1) {
|
|
335
|
+
const message = messages[index];
|
|
336
|
+
if (message.role !== "assistant" || !Array.isArray(message.content)) {
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
const toolUseIds = /* @__PURE__ */ new Map();
|
|
340
|
+
for (const block of message.content) {
|
|
341
|
+
if (block.type === "tool_use") {
|
|
342
|
+
toolUseIds.set(block.id, block.name);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
if (toolUseIds.size === 0) {
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
const nextMessage = messages[index + 1];
|
|
349
|
+
const matchedIds = /* @__PURE__ */ new Set();
|
|
350
|
+
if (nextMessage?.role === "user" && Array.isArray(nextMessage.content)) {
|
|
351
|
+
for (const block of nextMessage.content) {
|
|
352
|
+
if (block.type === "tool_result" && toolUseIds.has(block.tool_use_id)) {
|
|
353
|
+
matchedIds.add(block.tool_use_id);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
const syntheticResults = [...toolUseIds.entries()].filter(([toolUseId]) => !matchedIds.has(toolUseId)).map(([toolUseId]) => ({
|
|
358
|
+
type: "tool_result",
|
|
359
|
+
tool_use_id: toolUseId,
|
|
360
|
+
content: "Error: tool execution was interrupted",
|
|
361
|
+
is_error: true
|
|
362
|
+
}));
|
|
363
|
+
if (syntheticResults.length === 0) {
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
if (nextMessage?.role === "user") {
|
|
367
|
+
if (typeof nextMessage.content === "string") {
|
|
368
|
+
nextMessage.content = [
|
|
369
|
+
...syntheticResults,
|
|
370
|
+
{ type: "text", text: nextMessage.content }
|
|
371
|
+
];
|
|
372
|
+
} else {
|
|
373
|
+
nextMessage.content = [...syntheticResults, ...nextMessage.content];
|
|
374
|
+
}
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
messages.splice(index + 1, 0, {
|
|
378
|
+
role: "user",
|
|
379
|
+
content: syntheticResults
|
|
380
|
+
});
|
|
381
|
+
index += 1;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
var AnthropicHistoryConverter = class {
|
|
385
|
+
agentName;
|
|
386
|
+
constructor(agentName = "") {
|
|
387
|
+
this.agentName = agentName;
|
|
388
|
+
}
|
|
389
|
+
setAgentName(name) {
|
|
390
|
+
this.agentName = name;
|
|
391
|
+
}
|
|
392
|
+
convert(raw) {
|
|
393
|
+
const messages = [];
|
|
394
|
+
const pendingToolCalls = [];
|
|
395
|
+
const pendingToolResults = [];
|
|
396
|
+
for (const entry of raw) {
|
|
397
|
+
const messageType = String(entry.message_type ?? "text");
|
|
398
|
+
const content = String(entry.content ?? "");
|
|
399
|
+
if (messageType === "tool_call") {
|
|
400
|
+
flushPendingToolResults2(messages, pendingToolResults);
|
|
401
|
+
const parsed = parseToolCall(content);
|
|
402
|
+
if (parsed) {
|
|
403
|
+
pendingToolCalls.push({
|
|
404
|
+
type: "tool_use",
|
|
405
|
+
id: parsed.toolCallId,
|
|
406
|
+
name: parsed.name,
|
|
407
|
+
input: parsed.args
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
continue;
|
|
411
|
+
}
|
|
412
|
+
if (messageType === "tool_result") {
|
|
413
|
+
flushPendingToolCalls2(messages, pendingToolCalls);
|
|
414
|
+
const parsed = parseToolResult(content);
|
|
415
|
+
if (parsed) {
|
|
416
|
+
pendingToolResults.push({
|
|
417
|
+
type: "tool_result",
|
|
418
|
+
tool_use_id: parsed.toolCallId,
|
|
419
|
+
content: parsed.output,
|
|
420
|
+
...parsed.isError ? { is_error: true } : {}
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
continue;
|
|
424
|
+
}
|
|
425
|
+
if (messageType !== "text") {
|
|
426
|
+
continue;
|
|
427
|
+
}
|
|
428
|
+
flushPendingToolCalls2(messages, pendingToolCalls);
|
|
429
|
+
flushPendingToolResults2(messages, pendingToolResults);
|
|
430
|
+
const role = String(entry.role ?? "user");
|
|
431
|
+
const senderName = String(entry.sender_name ?? "");
|
|
432
|
+
if (role === "assistant" && senderName === this.agentName) {
|
|
433
|
+
continue;
|
|
434
|
+
}
|
|
435
|
+
messages.push({
|
|
436
|
+
role: "user",
|
|
437
|
+
content: senderName ? `[${senderName}]: ${content}` : content
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
flushPendingToolCalls2(messages, pendingToolCalls);
|
|
441
|
+
flushPendingToolResults2(messages, pendingToolResults);
|
|
442
|
+
patchOrphanedToolUses(messages);
|
|
443
|
+
return messages;
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
|
|
447
|
+
// src/adapters/a2a-gateway/A2AGatewayAdapter.ts
|
|
448
|
+
var import_node_crypto4 = require("crypto");
|
|
449
|
+
|
|
450
|
+
// src/adapters/a2a-gateway/history.ts
|
|
451
|
+
var GatewayHistoryConverter = class {
|
|
452
|
+
convert(raw) {
|
|
453
|
+
const contextToRoom = {};
|
|
454
|
+
const roomParticipants = /* @__PURE__ */ new Map();
|
|
455
|
+
for (const entry of raw) {
|
|
456
|
+
const metadata = asOptionalRecord(entry.metadata) ?? {};
|
|
457
|
+
const contextId = asNonEmptyString(metadata.gateway_context_id);
|
|
458
|
+
if (contextId) {
|
|
459
|
+
const roomId2 = asNonEmptyString(metadata.gateway_room_id) ?? asNonEmptyString(entry.room_id) ?? asNonEmptyString(entry.roomId);
|
|
460
|
+
if (roomId2) {
|
|
461
|
+
contextToRoom[contextId] = roomId2;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
const senderType = (asNonEmptyString(entry.sender_type) ?? asNonEmptyString(entry.senderType) ?? "").trim().toLowerCase();
|
|
465
|
+
const roomId = asNonEmptyString(entry.room_id) ?? asNonEmptyString(entry.roomId);
|
|
466
|
+
const senderId = asNonEmptyString(entry.sender_id) ?? asNonEmptyString(entry.senderId);
|
|
467
|
+
if (senderType !== "agent" || !roomId || !senderId) {
|
|
468
|
+
continue;
|
|
469
|
+
}
|
|
470
|
+
const participants = roomParticipants.get(roomId) ?? /* @__PURE__ */ new Set();
|
|
471
|
+
participants.add(senderId);
|
|
472
|
+
roomParticipants.set(roomId, participants);
|
|
473
|
+
}
|
|
474
|
+
const serializedParticipants = {};
|
|
475
|
+
for (const [roomId, participants] of roomParticipants) {
|
|
476
|
+
serializedParticipants[roomId] = [...participants];
|
|
477
|
+
}
|
|
478
|
+
return {
|
|
479
|
+
contextToRoom,
|
|
480
|
+
roomParticipants: serializedParticipants
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
// src/adapters/a2a-gateway/server.ts
|
|
486
|
+
var import_node_crypto3 = require("crypto");
|
|
487
|
+
|
|
488
|
+
// src/adapters/a2a-gateway/statusEvent.ts
|
|
489
|
+
var import_node_crypto2 = require("crypto");
|
|
490
|
+
|
|
491
|
+
// src/adapters/a2a-gateway/A2AGatewayAdapter.ts
|
|
492
|
+
var DEFAULT_PORT = 1e4;
|
|
493
|
+
var DEFAULT_GATEWAY_URL = `http://localhost:${DEFAULT_PORT}`;
|
|
494
|
+
|
|
495
|
+
// src/runtime/prompts.ts
|
|
496
|
+
var BASE_INSTRUCTIONS = `
|
|
497
|
+
## Environment
|
|
498
|
+
|
|
499
|
+
Multi-participant chat. Messages show sender: [Name]: content.
|
|
500
|
+
Messages prefixed with [System]: are platform updates (participant changes, contact updates, etc.) \u2014 not messages from users.
|
|
501
|
+
Use \`thenvoi_send_message(content, mentions)\` to respond. Plain text output is not delivered.
|
|
502
|
+
Mentions use handles: @<username> for users, @<username>/<agent-name> for agents.
|
|
503
|
+
|
|
504
|
+
## CRITICAL: Delegate When You Cannot Help Directly
|
|
505
|
+
|
|
506
|
+
You have NO internet access and NO real-time data. When asked about weather, news, stock prices,
|
|
507
|
+
or any current information you cannot answer directly:
|
|
508
|
+
|
|
509
|
+
1. Call \`thenvoi_lookup_peers()\` to find available specialized agents
|
|
510
|
+
2. If a relevant agent exists, call \`thenvoi_add_participant(name)\` to add them
|
|
511
|
+
3. Ask that agent using \`thenvoi_send_message(question, mentions=[agent_handle])\`
|
|
512
|
+
4. Wait for their response and relay it back to the user
|
|
513
|
+
|
|
514
|
+
NEVER say "I can't do that" without first checking if another agent can help via \`thenvoi_lookup_peers()\`.
|
|
515
|
+
|
|
516
|
+
## CRITICAL: Do NOT Remove Agents Automatically
|
|
517
|
+
|
|
518
|
+
After adding an agent to help with a task:
|
|
519
|
+
1. Ask your question and wait for their response
|
|
520
|
+
2. Relay their response back to the original requester
|
|
521
|
+
3. **Do NOT remove the agent** - they stay silent unless mentioned and may be useful for follow-ups
|
|
522
|
+
|
|
523
|
+
Only remove agents if the user explicitly requests it.
|
|
524
|
+
|
|
525
|
+
## CRITICAL: Always Relay Information Back to the Requester
|
|
526
|
+
|
|
527
|
+
When someone asks you to get information from another agent:
|
|
528
|
+
1. Ask the other agent for the information
|
|
529
|
+
2. When you receive the response, IMMEDIATELY relay it back to the ORIGINAL REQUESTER
|
|
530
|
+
3. Do NOT just thank the helper agent - the requester is waiting for their answer!
|
|
531
|
+
|
|
532
|
+
## IMPORTANT: Always Share Your Thinking
|
|
533
|
+
|
|
534
|
+
You MUST call \`thenvoi_send_event(content, message_type="thought")\` BEFORE every action.
|
|
535
|
+
This is required so users can see your reasoning process.
|
|
536
|
+
|
|
537
|
+
## Examples
|
|
538
|
+
|
|
539
|
+
### Simple question - answer directly
|
|
540
|
+
[John Doe]: What's 2+2?
|
|
541
|
+
-> thenvoi_send_event("Simple arithmetic, answering directly.", message_type="thought")
|
|
542
|
+
-> thenvoi_send_message("4", mentions=["@john"])
|
|
543
|
+
|
|
544
|
+
### User asks about weather (you cannot answer directly)
|
|
545
|
+
[John Doe]: What's the weather in Tokyo?
|
|
546
|
+
-> thenvoi_send_event("I can't check weather directly. Looking for a Weather Agent.", message_type="thought")
|
|
547
|
+
-> thenvoi_lookup_peers()
|
|
548
|
+
-> thenvoi_send_event("Found Weather Agent. Adding to room.", message_type="thought")
|
|
549
|
+
-> thenvoi_add_participant("Weather Agent")
|
|
550
|
+
-> thenvoi_send_message("What's the weather in Tokyo?", mentions=["@john/weather-agent"])
|
|
551
|
+
|
|
552
|
+
[Weather Agent]: Tokyo is 15\xB0C and cloudy.
|
|
553
|
+
-> thenvoi_send_event("Got weather response. Relaying back to John Doe.", message_type="thought")
|
|
554
|
+
-> thenvoi_send_message("The weather in Tokyo is 15\xB0C and cloudy.", mentions=["@john"])
|
|
555
|
+
|
|
556
|
+
### No suitable agent available
|
|
557
|
+
[John Doe]: What's the stock price of AAPL?
|
|
558
|
+
-> thenvoi_send_event("I can't check stock prices. Looking for a Stock Agent.", message_type="thought")
|
|
559
|
+
-> thenvoi_lookup_peers()
|
|
560
|
+
-> thenvoi_send_event("No stock agent available. Must inform user.", message_type="thought")
|
|
561
|
+
-> thenvoi_send_message("I don't have access to stock prices, and there's no specialized agent available to help with that.", mentions=["@john"])
|
|
562
|
+
|
|
563
|
+
### Follow-up question in same conversation
|
|
564
|
+
[John Doe]: What about London?
|
|
565
|
+
-> thenvoi_send_event("Follow-up weather question. Asking Weather Agent.", message_type="thought")
|
|
566
|
+
-> thenvoi_send_message("What's the weather in London?", mentions=["@john/weather-agent"])
|
|
567
|
+
|
|
568
|
+
[Weather Agent]: London is 8\xB0C and rainy.
|
|
569
|
+
-> thenvoi_send_event("Got London weather. Relaying to John Doe.", message_type="thought")
|
|
570
|
+
-> thenvoi_send_message("London is 8\xB0C and rainy.", mentions=["@john"])
|
|
571
|
+
`;
|
|
572
|
+
var TEMPLATES = {
|
|
573
|
+
default: `You are {agent_name}, {agent_description}.
|
|
574
|
+
|
|
575
|
+
{custom_section}
|
|
576
|
+
` + BASE_INSTRUCTIONS
|
|
577
|
+
};
|
|
578
|
+
|
|
579
|
+
// src/adapters/parlant/types.ts
|
|
580
|
+
var ParlantHistoryConverter = class {
|
|
581
|
+
convert(raw) {
|
|
582
|
+
const messages = [];
|
|
583
|
+
for (const entry of raw) {
|
|
584
|
+
const messageType = asNonEmptyString(entry.message_type) ?? "text";
|
|
585
|
+
if (messageType !== "text") {
|
|
586
|
+
continue;
|
|
587
|
+
}
|
|
588
|
+
const content = asNonEmptyString(entry.content);
|
|
589
|
+
if (!content) {
|
|
590
|
+
continue;
|
|
591
|
+
}
|
|
592
|
+
const sender = asNonEmptyString(entry.sender_name) ?? asNonEmptyString(entry.senderName) ?? "";
|
|
593
|
+
const senderType = asNonEmptyString(entry.sender_type) ?? asNonEmptyString(entry.senderType) ?? "User";
|
|
594
|
+
const role = (asNonEmptyString(entry.role) ?? "user").toLowerCase() === "assistant" ? "assistant" : "user";
|
|
595
|
+
if (role === "assistant") {
|
|
596
|
+
messages.push({
|
|
597
|
+
role,
|
|
598
|
+
content,
|
|
599
|
+
sender,
|
|
600
|
+
senderType
|
|
601
|
+
});
|
|
602
|
+
continue;
|
|
603
|
+
}
|
|
604
|
+
messages.push({
|
|
605
|
+
role,
|
|
606
|
+
content: sender ? `[${sender}]: ${content}` : content,
|
|
607
|
+
sender,
|
|
608
|
+
senderType
|
|
609
|
+
});
|
|
610
|
+
}
|
|
611
|
+
return messages;
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
|
|
615
|
+
// src/converters/claude-sdk.ts
|
|
616
|
+
var ClaudeSDKHistoryConverter = class {
|
|
617
|
+
agentName = "";
|
|
618
|
+
constructor(agentName = "") {
|
|
619
|
+
this.agentName = agentName;
|
|
620
|
+
}
|
|
621
|
+
setAgentName(name) {
|
|
622
|
+
this.agentName = name;
|
|
623
|
+
}
|
|
624
|
+
convert(raw) {
|
|
625
|
+
return {
|
|
626
|
+
text: buildClaudeSdkText(raw, this.agentName),
|
|
627
|
+
sessionId: extractClaudeSessionId(raw)
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
};
|
|
631
|
+
function extractClaudeSessionId(raw) {
|
|
632
|
+
const metadata = findLatestTaskMetadata(
|
|
633
|
+
raw,
|
|
634
|
+
(entry) => typeof entry.claude_sdk_session_id === "string" && entry.claude_sdk_session_id.length > 0 || typeof entry.claude_session_id === "string" && entry.claude_session_id.length > 0
|
|
635
|
+
);
|
|
636
|
+
const sessionId = metadata?.claude_sdk_session_id ?? metadata?.claude_session_id;
|
|
637
|
+
return typeof sessionId === "string" && sessionId.length > 0 ? sessionId : null;
|
|
638
|
+
}
|
|
639
|
+
function buildClaudeSdkText(raw, agentName) {
|
|
640
|
+
const lines = [];
|
|
641
|
+
for (const entry of raw) {
|
|
642
|
+
const messageType = String(entry.message_type ?? "text");
|
|
643
|
+
if (messageType === "task") {
|
|
644
|
+
continue;
|
|
645
|
+
}
|
|
646
|
+
const content = asOptionalString(entry.content);
|
|
647
|
+
if (!content) {
|
|
648
|
+
continue;
|
|
649
|
+
}
|
|
650
|
+
const role = String(entry.role ?? "user");
|
|
651
|
+
const senderName = asOptionalString(entry.sender_name) ?? "Unknown";
|
|
652
|
+
if (messageType === "text") {
|
|
653
|
+
if (role === "assistant" && senderName === agentName) {
|
|
654
|
+
continue;
|
|
655
|
+
}
|
|
656
|
+
lines.push(`[${senderName}]: ${content}`);
|
|
657
|
+
continue;
|
|
658
|
+
}
|
|
659
|
+
if (messageType === "tool_call" || messageType === "tool_result") {
|
|
660
|
+
lines.push(content);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
return lines.join("\n");
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
// src/converters/codex.ts
|
|
667
|
+
var CodexHistoryConverter = class {
|
|
668
|
+
setAgentName(_name) {
|
|
669
|
+
}
|
|
670
|
+
convert(raw) {
|
|
671
|
+
const metadata = findLatestTaskMetadata(
|
|
672
|
+
raw,
|
|
673
|
+
(entry) => typeof entry.codex_thread_id === "string" && entry.codex_thread_id.length > 0
|
|
674
|
+
);
|
|
675
|
+
if (!metadata) {
|
|
676
|
+
return {
|
|
677
|
+
threadId: null,
|
|
678
|
+
roomId: null,
|
|
679
|
+
createdAt: null
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
return {
|
|
683
|
+
threadId: asOptionalString(metadata.codex_thread_id),
|
|
684
|
+
roomId: asOptionalString(metadata.codex_room_id),
|
|
685
|
+
createdAt: parseDate(metadata.codex_created_at)
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
};
|
|
689
|
+
function extractCodexSessionId(raw) {
|
|
690
|
+
const metadata = findLatestTaskMetadata(
|
|
691
|
+
raw,
|
|
692
|
+
(entry) => typeof entry.codex_thread_id === "string" && entry.codex_thread_id.length > 0
|
|
693
|
+
);
|
|
694
|
+
const sessionId = metadata?.codex_thread_id;
|
|
695
|
+
return typeof sessionId === "string" && sessionId.length > 0 ? sessionId : null;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
// src/converters/google-adk.ts
|
|
699
|
+
function appendToolCalls(messages, pendingToolCalls) {
|
|
700
|
+
if (pendingToolCalls.length === 0) {
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
703
|
+
messages.push({
|
|
704
|
+
role: "model",
|
|
705
|
+
content: [...pendingToolCalls]
|
|
706
|
+
});
|
|
707
|
+
pendingToolCalls.length = 0;
|
|
708
|
+
}
|
|
709
|
+
function appendToolResults(messages, pendingToolResults) {
|
|
710
|
+
if (pendingToolResults.length === 0) {
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
messages.push({
|
|
714
|
+
role: "user",
|
|
715
|
+
content: [...pendingToolResults]
|
|
716
|
+
});
|
|
717
|
+
pendingToolResults.length = 0;
|
|
718
|
+
}
|
|
719
|
+
function patchOrphanedToolCalls(messages) {
|
|
720
|
+
for (let index = 0; index < messages.length; index += 1) {
|
|
721
|
+
const message = messages[index];
|
|
722
|
+
if (message.role !== "model" || !Array.isArray(message.content)) {
|
|
723
|
+
continue;
|
|
724
|
+
}
|
|
725
|
+
const callNames = /* @__PURE__ */ new Map();
|
|
726
|
+
for (const block of message.content) {
|
|
727
|
+
if (block.type === "function_call" && typeof block.id === "string" && block.id.length > 0) {
|
|
728
|
+
callNames.set(block.id, typeof block.name === "string" ? block.name : "");
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
if (callNames.size === 0) {
|
|
732
|
+
continue;
|
|
733
|
+
}
|
|
734
|
+
const nextMessage = messages[index + 1];
|
|
735
|
+
const matchedIds = /* @__PURE__ */ new Set();
|
|
736
|
+
if (nextMessage?.role === "user" && Array.isArray(nextMessage.content)) {
|
|
737
|
+
for (const block of nextMessage.content) {
|
|
738
|
+
if (block.type === "function_response" && typeof block.tool_call_id === "string" && callNames.has(block.tool_call_id)) {
|
|
739
|
+
matchedIds.add(block.tool_call_id);
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
const orphanedIds = [...callNames.keys()].filter((toolCallId) => !matchedIds.has(toolCallId));
|
|
744
|
+
if (orphanedIds.length === 0) {
|
|
745
|
+
continue;
|
|
746
|
+
}
|
|
747
|
+
const syntheticResponses = orphanedIds.map((toolCallId) => ({
|
|
748
|
+
type: "function_response",
|
|
749
|
+
tool_call_id: toolCallId,
|
|
750
|
+
name: callNames.get(toolCallId) ?? "",
|
|
751
|
+
output: "Error: tool execution was interrupted",
|
|
752
|
+
is_error: true
|
|
753
|
+
}));
|
|
754
|
+
if (nextMessage?.role === "user") {
|
|
755
|
+
if (typeof nextMessage.content === "string") {
|
|
756
|
+
nextMessage.content = [
|
|
757
|
+
...syntheticResponses,
|
|
758
|
+
{ type: "text", text: nextMessage.content }
|
|
759
|
+
];
|
|
760
|
+
} else if (Array.isArray(nextMessage.content)) {
|
|
761
|
+
nextMessage.content = [...syntheticResponses, ...nextMessage.content];
|
|
762
|
+
}
|
|
763
|
+
continue;
|
|
764
|
+
}
|
|
765
|
+
messages.splice(index + 1, 0, {
|
|
766
|
+
role: "user",
|
|
767
|
+
content: syntheticResponses
|
|
768
|
+
});
|
|
769
|
+
index += 1;
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
var GoogleADKHistoryConverter = class {
|
|
773
|
+
agentName = "";
|
|
774
|
+
constructor(agentName = "") {
|
|
775
|
+
this.agentName = agentName;
|
|
776
|
+
}
|
|
777
|
+
setAgentName(name) {
|
|
778
|
+
this.agentName = name;
|
|
779
|
+
}
|
|
780
|
+
convert(raw) {
|
|
781
|
+
const messages = [];
|
|
782
|
+
const pendingToolCalls = [];
|
|
783
|
+
const pendingToolResults = [];
|
|
784
|
+
for (const entry of raw) {
|
|
785
|
+
const messageType = String(entry.message_type ?? "text");
|
|
786
|
+
const content = String(entry.content ?? "");
|
|
787
|
+
if (messageType === "tool_call") {
|
|
788
|
+
appendToolResults(messages, pendingToolResults);
|
|
789
|
+
const parsed = parseToolCall(content);
|
|
790
|
+
if (parsed) {
|
|
791
|
+
pendingToolCalls.push({
|
|
792
|
+
type: "function_call",
|
|
793
|
+
id: parsed.toolCallId,
|
|
794
|
+
name: parsed.name,
|
|
795
|
+
args: parsed.args
|
|
796
|
+
});
|
|
797
|
+
}
|
|
798
|
+
continue;
|
|
799
|
+
}
|
|
800
|
+
if (messageType === "tool_result") {
|
|
801
|
+
appendToolCalls(messages, pendingToolCalls);
|
|
802
|
+
const parsed = parseToolResult(content);
|
|
803
|
+
if (parsed) {
|
|
804
|
+
pendingToolResults.push({
|
|
805
|
+
type: "function_response",
|
|
806
|
+
tool_call_id: parsed.toolCallId,
|
|
807
|
+
name: parsed.name,
|
|
808
|
+
output: parsed.output,
|
|
809
|
+
...parsed.isError ? { is_error: true } : {}
|
|
810
|
+
});
|
|
811
|
+
}
|
|
812
|
+
continue;
|
|
813
|
+
}
|
|
814
|
+
if (messageType === "thought" || messageType === "error") {
|
|
815
|
+
continue;
|
|
816
|
+
}
|
|
817
|
+
appendToolCalls(messages, pendingToolCalls);
|
|
818
|
+
appendToolResults(messages, pendingToolResults);
|
|
819
|
+
const senderName = String(entry.sender_name ?? "");
|
|
820
|
+
const role = String(entry.role ?? "user");
|
|
821
|
+
if (role === "assistant" && senderName === this.agentName) {
|
|
822
|
+
continue;
|
|
823
|
+
}
|
|
824
|
+
messages.push({
|
|
825
|
+
role: "user",
|
|
826
|
+
content: senderName ? `[${senderName}]: ${content}` : content
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
appendToolCalls(messages, pendingToolCalls);
|
|
830
|
+
appendToolResults(messages, pendingToolResults);
|
|
831
|
+
patchOrphanedToolCalls(messages);
|
|
832
|
+
return messages;
|
|
833
|
+
}
|
|
834
|
+
};
|
|
835
|
+
function extractGoogleAdkSessionId(raw) {
|
|
836
|
+
const metadata = findLatestTaskMetadata(
|
|
837
|
+
raw,
|
|
838
|
+
(entry) => typeof entry.google_adk_session_id === "string" && entry.google_adk_session_id.length > 0
|
|
839
|
+
);
|
|
840
|
+
const sessionId = metadata?.google_adk_session_id;
|
|
841
|
+
return typeof sessionId === "string" && sessionId.length > 0 ? sessionId : null;
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
// src/converters/gemini.ts
|
|
845
|
+
function flushPendingToolCalls3(messages, pendingToolCalls) {
|
|
846
|
+
if (pendingToolCalls.length === 0) {
|
|
847
|
+
return;
|
|
848
|
+
}
|
|
849
|
+
messages.push({
|
|
850
|
+
role: "model",
|
|
851
|
+
parts: [...pendingToolCalls]
|
|
852
|
+
});
|
|
853
|
+
pendingToolCalls.length = 0;
|
|
854
|
+
}
|
|
855
|
+
function flushPendingToolResults3(messages, pendingToolResults) {
|
|
856
|
+
if (pendingToolResults.length === 0) {
|
|
857
|
+
return;
|
|
858
|
+
}
|
|
859
|
+
messages.push({
|
|
860
|
+
role: "user",
|
|
861
|
+
parts: [...pendingToolResults]
|
|
862
|
+
});
|
|
863
|
+
pendingToolResults.length = 0;
|
|
864
|
+
}
|
|
865
|
+
function mergeConsecutiveRoles(messages) {
|
|
866
|
+
if (messages.length <= 1) {
|
|
867
|
+
return messages;
|
|
868
|
+
}
|
|
869
|
+
const merged = [messages[0]];
|
|
870
|
+
for (const message of messages.slice(1)) {
|
|
871
|
+
const previous = merged[merged.length - 1];
|
|
872
|
+
if (previous && previous.role === message.role) {
|
|
873
|
+
previous.parts = [...previous.parts, ...message.parts];
|
|
874
|
+
continue;
|
|
875
|
+
}
|
|
876
|
+
merged.push(message);
|
|
877
|
+
}
|
|
878
|
+
return merged;
|
|
879
|
+
}
|
|
880
|
+
var GeminiHistoryConverter = class {
|
|
881
|
+
agentName;
|
|
882
|
+
constructor(agentName = "") {
|
|
883
|
+
this.agentName = agentName;
|
|
884
|
+
}
|
|
885
|
+
setAgentName(name) {
|
|
886
|
+
this.agentName = name;
|
|
887
|
+
}
|
|
888
|
+
convert(raw) {
|
|
889
|
+
const messages = [];
|
|
890
|
+
const pendingToolCalls = [];
|
|
891
|
+
const pendingToolResults = [];
|
|
892
|
+
for (const entry of raw) {
|
|
893
|
+
const messageType = String(entry.message_type ?? "text");
|
|
894
|
+
const content = String(entry.content ?? "");
|
|
895
|
+
if (messageType === "tool_call") {
|
|
896
|
+
flushPendingToolResults3(messages, pendingToolResults);
|
|
897
|
+
const parsed = parseToolCall(content);
|
|
898
|
+
if (parsed) {
|
|
899
|
+
pendingToolCalls.push({
|
|
900
|
+
type: "function_call",
|
|
901
|
+
id: parsed.toolCallId,
|
|
902
|
+
name: parsed.name,
|
|
903
|
+
args: parsed.args
|
|
904
|
+
});
|
|
905
|
+
}
|
|
906
|
+
continue;
|
|
907
|
+
}
|
|
908
|
+
if (messageType === "tool_result") {
|
|
909
|
+
flushPendingToolCalls3(messages, pendingToolCalls);
|
|
910
|
+
const parsed = parseToolResult(content);
|
|
911
|
+
if (parsed) {
|
|
912
|
+
pendingToolResults.push({
|
|
913
|
+
type: "function_response",
|
|
914
|
+
tool_call_id: parsed.toolCallId,
|
|
915
|
+
name: parsed.name,
|
|
916
|
+
response: parsed.isError ? { error: parsed.output } : { output: parsed.output }
|
|
917
|
+
});
|
|
918
|
+
}
|
|
919
|
+
continue;
|
|
920
|
+
}
|
|
921
|
+
if (messageType !== "text") {
|
|
922
|
+
continue;
|
|
923
|
+
}
|
|
924
|
+
const role = String(entry.role ?? "user");
|
|
925
|
+
const senderName = String(entry.sender_name ?? "");
|
|
926
|
+
if (role === "assistant" && senderName === this.agentName) {
|
|
927
|
+
if (pendingToolCalls.length > 0 || pendingToolResults.length > 0) {
|
|
928
|
+
continue;
|
|
929
|
+
}
|
|
930
|
+
flushPendingToolCalls3(messages, pendingToolCalls);
|
|
931
|
+
flushPendingToolResults3(messages, pendingToolResults);
|
|
932
|
+
messages.push({
|
|
933
|
+
role: "model",
|
|
934
|
+
parts: [{ type: "text", text: content }]
|
|
935
|
+
});
|
|
936
|
+
continue;
|
|
937
|
+
}
|
|
938
|
+
flushPendingToolCalls3(messages, pendingToolCalls);
|
|
939
|
+
flushPendingToolResults3(messages, pendingToolResults);
|
|
940
|
+
messages.push({
|
|
941
|
+
role: "user",
|
|
942
|
+
parts: [{ type: "text", text: senderName ? `[${senderName}]: ${content}` : content }]
|
|
943
|
+
});
|
|
944
|
+
}
|
|
945
|
+
flushPendingToolCalls3(messages, pendingToolCalls);
|
|
946
|
+
flushPendingToolResults3(messages, pendingToolResults);
|
|
947
|
+
return mergeConsecutiveRoles(messages);
|
|
948
|
+
}
|
|
949
|
+
};
|
|
950
|
+
|
|
951
|
+
// src/converters/langchain.ts
|
|
952
|
+
var LangChainHistoryConverter = class {
|
|
953
|
+
agentName;
|
|
954
|
+
constructor(agentName = "") {
|
|
955
|
+
this.agentName = agentName;
|
|
956
|
+
}
|
|
957
|
+
setAgentName(name) {
|
|
958
|
+
this.agentName = name;
|
|
959
|
+
}
|
|
960
|
+
convert(raw) {
|
|
961
|
+
const messages = [];
|
|
962
|
+
const pendingToolCalls = [];
|
|
963
|
+
for (const entry of raw) {
|
|
964
|
+
const messageType = String(entry.message_type ?? "text");
|
|
965
|
+
const content = String(entry.content ?? "");
|
|
966
|
+
const role = String(entry.role ?? "user");
|
|
967
|
+
const senderName = String(entry.sender_name ?? "");
|
|
968
|
+
if (messageType === "tool_call") {
|
|
969
|
+
const parsed = parseToolCall(content);
|
|
970
|
+
if (parsed) {
|
|
971
|
+
pendingToolCalls.push(parsed);
|
|
972
|
+
}
|
|
973
|
+
continue;
|
|
974
|
+
}
|
|
975
|
+
if (messageType === "tool_result") {
|
|
976
|
+
const parsed = parseToolResult(content);
|
|
977
|
+
if (!parsed) {
|
|
978
|
+
continue;
|
|
979
|
+
}
|
|
980
|
+
const matchingCallIndex = pendingToolCalls.findIndex(
|
|
981
|
+
(toolCall) => toolCall.toolCallId === parsed.toolCallId || toolCall.name === parsed.name
|
|
982
|
+
);
|
|
983
|
+
if (matchingCallIndex >= 0) {
|
|
984
|
+
const matchingCall = pendingToolCalls.splice(matchingCallIndex, 1)[0];
|
|
985
|
+
messages.push({
|
|
986
|
+
type: "ai",
|
|
987
|
+
content: "",
|
|
988
|
+
tool_calls: [{
|
|
989
|
+
id: matchingCall.toolCallId,
|
|
990
|
+
name: matchingCall.name,
|
|
991
|
+
args: matchingCall.args
|
|
992
|
+
}]
|
|
993
|
+
});
|
|
994
|
+
}
|
|
995
|
+
messages.push({
|
|
996
|
+
type: "tool",
|
|
997
|
+
content: parsed.output,
|
|
998
|
+
tool_call_id: parsed.toolCallId
|
|
999
|
+
});
|
|
1000
|
+
continue;
|
|
1001
|
+
}
|
|
1002
|
+
if (messageType !== "text") {
|
|
1003
|
+
continue;
|
|
1004
|
+
}
|
|
1005
|
+
if (role === "assistant" && senderName === this.agentName) {
|
|
1006
|
+
continue;
|
|
1007
|
+
}
|
|
1008
|
+
messages.push({
|
|
1009
|
+
type: "human",
|
|
1010
|
+
content: senderName ? `[${senderName}]: ${content}` : content
|
|
1011
|
+
});
|
|
1012
|
+
}
|
|
1013
|
+
return messages;
|
|
1014
|
+
}
|
|
1015
|
+
};
|
|
1016
|
+
|
|
1017
|
+
// src/converters/opencode.ts
|
|
1018
|
+
var OpencodeHistoryConverter = class {
|
|
1019
|
+
setAgentName(_name) {
|
|
1020
|
+
}
|
|
1021
|
+
convert(raw) {
|
|
1022
|
+
const replayMessages = buildReplayMessages(raw);
|
|
1023
|
+
const metadata = findLatestTaskMetadata(
|
|
1024
|
+
raw,
|
|
1025
|
+
(entry) => typeof entry.opencode_session_id === "string" && entry.opencode_session_id.length > 0
|
|
1026
|
+
);
|
|
1027
|
+
if (!metadata) {
|
|
1028
|
+
return {
|
|
1029
|
+
sessionId: null,
|
|
1030
|
+
roomId: null,
|
|
1031
|
+
createdAt: null,
|
|
1032
|
+
replayMessages
|
|
1033
|
+
};
|
|
1034
|
+
}
|
|
1035
|
+
return {
|
|
1036
|
+
sessionId: asOptionalString(metadata.opencode_session_id),
|
|
1037
|
+
roomId: asOptionalString(metadata.opencode_room_id),
|
|
1038
|
+
createdAt: parseDate(metadata.opencode_created_at),
|
|
1039
|
+
replayMessages
|
|
1040
|
+
};
|
|
1041
|
+
}
|
|
1042
|
+
};
|
|
1043
|
+
function extractOpencodeSessionId(raw) {
|
|
1044
|
+
return asOptionalString(
|
|
1045
|
+
findLatestTaskMetadata(
|
|
1046
|
+
raw,
|
|
1047
|
+
(entry) => typeof entry.opencode_session_id === "string" && entry.opencode_session_id.length > 0
|
|
1048
|
+
)?.opencode_session_id
|
|
1049
|
+
);
|
|
1050
|
+
}
|
|
1051
|
+
function buildReplayMessages(raw) {
|
|
1052
|
+
const replayMessages = [];
|
|
1053
|
+
for (const entry of raw) {
|
|
1054
|
+
if (String(entry.message_type ?? "text") !== "text") {
|
|
1055
|
+
continue;
|
|
1056
|
+
}
|
|
1057
|
+
const content = asOptionalString(entry.content);
|
|
1058
|
+
if (!content) {
|
|
1059
|
+
continue;
|
|
1060
|
+
}
|
|
1061
|
+
const senderName = asOptionalString(entry.sender_name) ?? asOptionalString(entry.sender_type) ?? "Unknown";
|
|
1062
|
+
replayMessages.push(`[${senderName}]: ${content}`);
|
|
1063
|
+
}
|
|
1064
|
+
return replayMessages;
|
|
1065
|
+
}
|
|
1066
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1067
|
+
0 && (module.exports = {
|
|
1068
|
+
A2AHistoryConverter,
|
|
1069
|
+
ACPClientHistoryConverter,
|
|
1070
|
+
ACPServerHistoryConverter,
|
|
1071
|
+
AnthropicHistoryConverter,
|
|
1072
|
+
ClaudeSDKHistoryConverter,
|
|
1073
|
+
CodexHistoryConverter,
|
|
1074
|
+
GatewayHistoryConverter,
|
|
1075
|
+
GeminiHistoryConverter,
|
|
1076
|
+
GoogleADKHistoryConverter,
|
|
1077
|
+
LangChainHistoryConverter,
|
|
1078
|
+
OpencodeHistoryConverter,
|
|
1079
|
+
ParlantHistoryConverter,
|
|
1080
|
+
VercelAISDKHistoryConverter,
|
|
1081
|
+
buildA2AAuthHeaders,
|
|
1082
|
+
extractClaudeSessionId,
|
|
1083
|
+
extractCodexSessionId,
|
|
1084
|
+
extractGoogleAdkSessionId,
|
|
1085
|
+
extractOpencodeSessionId
|
|
1086
|
+
});
|