@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,468 @@
|
|
|
1
|
+
import {
|
|
2
|
+
A2AHistoryConverter,
|
|
3
|
+
ACPClientHistoryConverter,
|
|
4
|
+
ACPServerHistoryConverter,
|
|
5
|
+
ClaudeSDKHistoryConverter,
|
|
6
|
+
GatewayHistoryConverter,
|
|
7
|
+
GoogleADKHistoryConverter,
|
|
8
|
+
OpencodeHistoryConverter,
|
|
9
|
+
ParlantHistoryConverter,
|
|
10
|
+
asOptionalString,
|
|
11
|
+
buildA2AAuthHeaders,
|
|
12
|
+
extractClaudeSessionId,
|
|
13
|
+
extractGoogleAdkSessionId,
|
|
14
|
+
extractOpencodeSessionId,
|
|
15
|
+
findLatestTaskMetadata,
|
|
16
|
+
parseDate,
|
|
17
|
+
parseToolCall,
|
|
18
|
+
parseToolResult
|
|
19
|
+
} from "./chunk-FUODYQRE.js";
|
|
20
|
+
import "./chunk-AVVDPXP4.js";
|
|
21
|
+
import "./chunk-SFVKOEQH.js";
|
|
22
|
+
import "./chunk-ZZJRRBPQ.js";
|
|
23
|
+
import "./chunk-3BKAC4OZ.js";
|
|
24
|
+
import "./chunk-OD2G5LFQ.js";
|
|
25
|
+
import "./chunk-YR3BOQNW.js";
|
|
26
|
+
|
|
27
|
+
// src/converters/vercel-ai-sdk.ts
|
|
28
|
+
function flushPendingToolCalls(messages, pendingToolCalls) {
|
|
29
|
+
if (pendingToolCalls.length === 0) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
messages.push({
|
|
33
|
+
role: "assistant",
|
|
34
|
+
content: [...pendingToolCalls]
|
|
35
|
+
});
|
|
36
|
+
pendingToolCalls.length = 0;
|
|
37
|
+
}
|
|
38
|
+
function flushPendingToolResults(messages, pendingToolResults) {
|
|
39
|
+
if (pendingToolResults.length === 0) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
messages.push({
|
|
43
|
+
role: "tool",
|
|
44
|
+
content: [...pendingToolResults]
|
|
45
|
+
});
|
|
46
|
+
pendingToolResults.length = 0;
|
|
47
|
+
}
|
|
48
|
+
var VercelAISDKHistoryConverter = class {
|
|
49
|
+
agentName;
|
|
50
|
+
constructor(agentName = "") {
|
|
51
|
+
this.agentName = agentName;
|
|
52
|
+
}
|
|
53
|
+
setAgentName(name) {
|
|
54
|
+
this.agentName = name;
|
|
55
|
+
}
|
|
56
|
+
convert(raw) {
|
|
57
|
+
const messages = [];
|
|
58
|
+
const pendingToolCalls = [];
|
|
59
|
+
const pendingToolResults = [];
|
|
60
|
+
for (const entry of raw) {
|
|
61
|
+
const messageType = String(entry.message_type ?? "text");
|
|
62
|
+
const content = String(entry.content ?? "");
|
|
63
|
+
if (messageType === "tool_call") {
|
|
64
|
+
flushPendingToolResults(messages, pendingToolResults);
|
|
65
|
+
const parsed = parseToolCall(content);
|
|
66
|
+
if (parsed) {
|
|
67
|
+
pendingToolCalls.push({
|
|
68
|
+
type: "tool-call",
|
|
69
|
+
toolCallId: parsed.toolCallId,
|
|
70
|
+
toolName: parsed.name,
|
|
71
|
+
input: parsed.args
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (messageType === "tool_result") {
|
|
77
|
+
flushPendingToolCalls(messages, pendingToolCalls);
|
|
78
|
+
const parsed = parseToolResult(content);
|
|
79
|
+
if (parsed) {
|
|
80
|
+
pendingToolResults.push({
|
|
81
|
+
type: "tool-result",
|
|
82
|
+
toolCallId: parsed.toolCallId,
|
|
83
|
+
toolName: parsed.name,
|
|
84
|
+
output: parsed.isError ? { error: parsed.output } : parsed.output
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (messageType !== "text") {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
flushPendingToolCalls(messages, pendingToolCalls);
|
|
93
|
+
flushPendingToolResults(messages, pendingToolResults);
|
|
94
|
+
const role = String(entry.role ?? "user");
|
|
95
|
+
const senderName = String(entry.sender_name ?? "");
|
|
96
|
+
if (role === "assistant" && senderName === this.agentName) {
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
messages.push({
|
|
100
|
+
role: "user",
|
|
101
|
+
content: senderName ? `[${senderName}]: ${content}` : content
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
flushPendingToolCalls(messages, pendingToolCalls);
|
|
105
|
+
flushPendingToolResults(messages, pendingToolResults);
|
|
106
|
+
return messages;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
// src/converters/anthropic.ts
|
|
111
|
+
function flushPendingToolCalls2(messages, pendingToolCalls) {
|
|
112
|
+
if (pendingToolCalls.length === 0) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
messages.push({
|
|
116
|
+
role: "assistant",
|
|
117
|
+
content: [...pendingToolCalls]
|
|
118
|
+
});
|
|
119
|
+
pendingToolCalls.length = 0;
|
|
120
|
+
}
|
|
121
|
+
function flushPendingToolResults2(messages, pendingToolResults) {
|
|
122
|
+
if (pendingToolResults.length === 0) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
messages.push({
|
|
126
|
+
role: "user",
|
|
127
|
+
content: [...pendingToolResults]
|
|
128
|
+
});
|
|
129
|
+
pendingToolResults.length = 0;
|
|
130
|
+
}
|
|
131
|
+
function patchOrphanedToolUses(messages) {
|
|
132
|
+
for (let index = 0; index < messages.length; index += 1) {
|
|
133
|
+
const message = messages[index];
|
|
134
|
+
if (message.role !== "assistant" || !Array.isArray(message.content)) {
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
const toolUseIds = /* @__PURE__ */ new Map();
|
|
138
|
+
for (const block of message.content) {
|
|
139
|
+
if (block.type === "tool_use") {
|
|
140
|
+
toolUseIds.set(block.id, block.name);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (toolUseIds.size === 0) {
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
const nextMessage = messages[index + 1];
|
|
147
|
+
const matchedIds = /* @__PURE__ */ new Set();
|
|
148
|
+
if (nextMessage?.role === "user" && Array.isArray(nextMessage.content)) {
|
|
149
|
+
for (const block of nextMessage.content) {
|
|
150
|
+
if (block.type === "tool_result" && toolUseIds.has(block.tool_use_id)) {
|
|
151
|
+
matchedIds.add(block.tool_use_id);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
const syntheticResults = [...toolUseIds.entries()].filter(([toolUseId]) => !matchedIds.has(toolUseId)).map(([toolUseId]) => ({
|
|
156
|
+
type: "tool_result",
|
|
157
|
+
tool_use_id: toolUseId,
|
|
158
|
+
content: "Error: tool execution was interrupted",
|
|
159
|
+
is_error: true
|
|
160
|
+
}));
|
|
161
|
+
if (syntheticResults.length === 0) {
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
if (nextMessage?.role === "user") {
|
|
165
|
+
if (typeof nextMessage.content === "string") {
|
|
166
|
+
nextMessage.content = [
|
|
167
|
+
...syntheticResults,
|
|
168
|
+
{ type: "text", text: nextMessage.content }
|
|
169
|
+
];
|
|
170
|
+
} else {
|
|
171
|
+
nextMessage.content = [...syntheticResults, ...nextMessage.content];
|
|
172
|
+
}
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
messages.splice(index + 1, 0, {
|
|
176
|
+
role: "user",
|
|
177
|
+
content: syntheticResults
|
|
178
|
+
});
|
|
179
|
+
index += 1;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
var AnthropicHistoryConverter = class {
|
|
183
|
+
agentName;
|
|
184
|
+
constructor(agentName = "") {
|
|
185
|
+
this.agentName = agentName;
|
|
186
|
+
}
|
|
187
|
+
setAgentName(name) {
|
|
188
|
+
this.agentName = name;
|
|
189
|
+
}
|
|
190
|
+
convert(raw) {
|
|
191
|
+
const messages = [];
|
|
192
|
+
const pendingToolCalls = [];
|
|
193
|
+
const pendingToolResults = [];
|
|
194
|
+
for (const entry of raw) {
|
|
195
|
+
const messageType = String(entry.message_type ?? "text");
|
|
196
|
+
const content = String(entry.content ?? "");
|
|
197
|
+
if (messageType === "tool_call") {
|
|
198
|
+
flushPendingToolResults2(messages, pendingToolResults);
|
|
199
|
+
const parsed = parseToolCall(content);
|
|
200
|
+
if (parsed) {
|
|
201
|
+
pendingToolCalls.push({
|
|
202
|
+
type: "tool_use",
|
|
203
|
+
id: parsed.toolCallId,
|
|
204
|
+
name: parsed.name,
|
|
205
|
+
input: parsed.args
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
if (messageType === "tool_result") {
|
|
211
|
+
flushPendingToolCalls2(messages, pendingToolCalls);
|
|
212
|
+
const parsed = parseToolResult(content);
|
|
213
|
+
if (parsed) {
|
|
214
|
+
pendingToolResults.push({
|
|
215
|
+
type: "tool_result",
|
|
216
|
+
tool_use_id: parsed.toolCallId,
|
|
217
|
+
content: parsed.output,
|
|
218
|
+
...parsed.isError ? { is_error: true } : {}
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
if (messageType !== "text") {
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
flushPendingToolCalls2(messages, pendingToolCalls);
|
|
227
|
+
flushPendingToolResults2(messages, pendingToolResults);
|
|
228
|
+
const role = String(entry.role ?? "user");
|
|
229
|
+
const senderName = String(entry.sender_name ?? "");
|
|
230
|
+
if (role === "assistant" && senderName === this.agentName) {
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
messages.push({
|
|
234
|
+
role: "user",
|
|
235
|
+
content: senderName ? `[${senderName}]: ${content}` : content
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
flushPendingToolCalls2(messages, pendingToolCalls);
|
|
239
|
+
flushPendingToolResults2(messages, pendingToolResults);
|
|
240
|
+
patchOrphanedToolUses(messages);
|
|
241
|
+
return messages;
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
// src/converters/codex.ts
|
|
246
|
+
var CodexHistoryConverter = class {
|
|
247
|
+
setAgentName(_name) {
|
|
248
|
+
}
|
|
249
|
+
convert(raw) {
|
|
250
|
+
const metadata = findLatestTaskMetadata(
|
|
251
|
+
raw,
|
|
252
|
+
(entry) => typeof entry.codex_thread_id === "string" && entry.codex_thread_id.length > 0
|
|
253
|
+
);
|
|
254
|
+
if (!metadata) {
|
|
255
|
+
return {
|
|
256
|
+
threadId: null,
|
|
257
|
+
roomId: null,
|
|
258
|
+
createdAt: null
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
return {
|
|
262
|
+
threadId: asOptionalString(metadata.codex_thread_id),
|
|
263
|
+
roomId: asOptionalString(metadata.codex_room_id),
|
|
264
|
+
createdAt: parseDate(metadata.codex_created_at)
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
function extractCodexSessionId(raw) {
|
|
269
|
+
const metadata = findLatestTaskMetadata(
|
|
270
|
+
raw,
|
|
271
|
+
(entry) => typeof entry.codex_thread_id === "string" && entry.codex_thread_id.length > 0
|
|
272
|
+
);
|
|
273
|
+
const sessionId = metadata?.codex_thread_id;
|
|
274
|
+
return typeof sessionId === "string" && sessionId.length > 0 ? sessionId : null;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// src/converters/gemini.ts
|
|
278
|
+
function flushPendingToolCalls3(messages, pendingToolCalls) {
|
|
279
|
+
if (pendingToolCalls.length === 0) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
messages.push({
|
|
283
|
+
role: "model",
|
|
284
|
+
parts: [...pendingToolCalls]
|
|
285
|
+
});
|
|
286
|
+
pendingToolCalls.length = 0;
|
|
287
|
+
}
|
|
288
|
+
function flushPendingToolResults3(messages, pendingToolResults) {
|
|
289
|
+
if (pendingToolResults.length === 0) {
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
messages.push({
|
|
293
|
+
role: "user",
|
|
294
|
+
parts: [...pendingToolResults]
|
|
295
|
+
});
|
|
296
|
+
pendingToolResults.length = 0;
|
|
297
|
+
}
|
|
298
|
+
function mergeConsecutiveRoles(messages) {
|
|
299
|
+
if (messages.length <= 1) {
|
|
300
|
+
return messages;
|
|
301
|
+
}
|
|
302
|
+
const merged = [messages[0]];
|
|
303
|
+
for (const message of messages.slice(1)) {
|
|
304
|
+
const previous = merged[merged.length - 1];
|
|
305
|
+
if (previous && previous.role === message.role) {
|
|
306
|
+
previous.parts = [...previous.parts, ...message.parts];
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
309
|
+
merged.push(message);
|
|
310
|
+
}
|
|
311
|
+
return merged;
|
|
312
|
+
}
|
|
313
|
+
var GeminiHistoryConverter = class {
|
|
314
|
+
agentName;
|
|
315
|
+
constructor(agentName = "") {
|
|
316
|
+
this.agentName = agentName;
|
|
317
|
+
}
|
|
318
|
+
setAgentName(name) {
|
|
319
|
+
this.agentName = name;
|
|
320
|
+
}
|
|
321
|
+
convert(raw) {
|
|
322
|
+
const messages = [];
|
|
323
|
+
const pendingToolCalls = [];
|
|
324
|
+
const pendingToolResults = [];
|
|
325
|
+
for (const entry of raw) {
|
|
326
|
+
const messageType = String(entry.message_type ?? "text");
|
|
327
|
+
const content = String(entry.content ?? "");
|
|
328
|
+
if (messageType === "tool_call") {
|
|
329
|
+
flushPendingToolResults3(messages, pendingToolResults);
|
|
330
|
+
const parsed = parseToolCall(content);
|
|
331
|
+
if (parsed) {
|
|
332
|
+
pendingToolCalls.push({
|
|
333
|
+
type: "function_call",
|
|
334
|
+
id: parsed.toolCallId,
|
|
335
|
+
name: parsed.name,
|
|
336
|
+
args: parsed.args
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
341
|
+
if (messageType === "tool_result") {
|
|
342
|
+
flushPendingToolCalls3(messages, pendingToolCalls);
|
|
343
|
+
const parsed = parseToolResult(content);
|
|
344
|
+
if (parsed) {
|
|
345
|
+
pendingToolResults.push({
|
|
346
|
+
type: "function_response",
|
|
347
|
+
tool_call_id: parsed.toolCallId,
|
|
348
|
+
name: parsed.name,
|
|
349
|
+
response: parsed.isError ? { error: parsed.output } : { output: parsed.output }
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
if (messageType !== "text") {
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
const role = String(entry.role ?? "user");
|
|
358
|
+
const senderName = String(entry.sender_name ?? "");
|
|
359
|
+
if (role === "assistant" && senderName === this.agentName) {
|
|
360
|
+
if (pendingToolCalls.length > 0 || pendingToolResults.length > 0) {
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
flushPendingToolCalls3(messages, pendingToolCalls);
|
|
364
|
+
flushPendingToolResults3(messages, pendingToolResults);
|
|
365
|
+
messages.push({
|
|
366
|
+
role: "model",
|
|
367
|
+
parts: [{ type: "text", text: content }]
|
|
368
|
+
});
|
|
369
|
+
continue;
|
|
370
|
+
}
|
|
371
|
+
flushPendingToolCalls3(messages, pendingToolCalls);
|
|
372
|
+
flushPendingToolResults3(messages, pendingToolResults);
|
|
373
|
+
messages.push({
|
|
374
|
+
role: "user",
|
|
375
|
+
parts: [{ type: "text", text: senderName ? `[${senderName}]: ${content}` : content }]
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
flushPendingToolCalls3(messages, pendingToolCalls);
|
|
379
|
+
flushPendingToolResults3(messages, pendingToolResults);
|
|
380
|
+
return mergeConsecutiveRoles(messages);
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
// src/converters/langchain.ts
|
|
385
|
+
var LangChainHistoryConverter = class {
|
|
386
|
+
agentName;
|
|
387
|
+
constructor(agentName = "") {
|
|
388
|
+
this.agentName = agentName;
|
|
389
|
+
}
|
|
390
|
+
setAgentName(name) {
|
|
391
|
+
this.agentName = name;
|
|
392
|
+
}
|
|
393
|
+
convert(raw) {
|
|
394
|
+
const messages = [];
|
|
395
|
+
const pendingToolCalls = [];
|
|
396
|
+
for (const entry of raw) {
|
|
397
|
+
const messageType = String(entry.message_type ?? "text");
|
|
398
|
+
const content = String(entry.content ?? "");
|
|
399
|
+
const role = String(entry.role ?? "user");
|
|
400
|
+
const senderName = String(entry.sender_name ?? "");
|
|
401
|
+
if (messageType === "tool_call") {
|
|
402
|
+
const parsed = parseToolCall(content);
|
|
403
|
+
if (parsed) {
|
|
404
|
+
pendingToolCalls.push(parsed);
|
|
405
|
+
}
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
408
|
+
if (messageType === "tool_result") {
|
|
409
|
+
const parsed = parseToolResult(content);
|
|
410
|
+
if (!parsed) {
|
|
411
|
+
continue;
|
|
412
|
+
}
|
|
413
|
+
const matchingCallIndex = pendingToolCalls.findIndex(
|
|
414
|
+
(toolCall) => toolCall.toolCallId === parsed.toolCallId || toolCall.name === parsed.name
|
|
415
|
+
);
|
|
416
|
+
if (matchingCallIndex >= 0) {
|
|
417
|
+
const matchingCall = pendingToolCalls.splice(matchingCallIndex, 1)[0];
|
|
418
|
+
messages.push({
|
|
419
|
+
type: "ai",
|
|
420
|
+
content: "",
|
|
421
|
+
tool_calls: [{
|
|
422
|
+
id: matchingCall.toolCallId,
|
|
423
|
+
name: matchingCall.name,
|
|
424
|
+
args: matchingCall.args
|
|
425
|
+
}]
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
messages.push({
|
|
429
|
+
type: "tool",
|
|
430
|
+
content: parsed.output,
|
|
431
|
+
tool_call_id: parsed.toolCallId
|
|
432
|
+
});
|
|
433
|
+
continue;
|
|
434
|
+
}
|
|
435
|
+
if (messageType !== "text") {
|
|
436
|
+
continue;
|
|
437
|
+
}
|
|
438
|
+
if (role === "assistant" && senderName === this.agentName) {
|
|
439
|
+
continue;
|
|
440
|
+
}
|
|
441
|
+
messages.push({
|
|
442
|
+
type: "human",
|
|
443
|
+
content: senderName ? `[${senderName}]: ${content}` : content
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
return messages;
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
export {
|
|
450
|
+
A2AHistoryConverter,
|
|
451
|
+
ACPClientHistoryConverter,
|
|
452
|
+
ACPServerHistoryConverter,
|
|
453
|
+
AnthropicHistoryConverter,
|
|
454
|
+
ClaudeSDKHistoryConverter,
|
|
455
|
+
CodexHistoryConverter,
|
|
456
|
+
GatewayHistoryConverter,
|
|
457
|
+
GeminiHistoryConverter,
|
|
458
|
+
GoogleADKHistoryConverter,
|
|
459
|
+
LangChainHistoryConverter,
|
|
460
|
+
OpencodeHistoryConverter,
|
|
461
|
+
ParlantHistoryConverter,
|
|
462
|
+
VercelAISDKHistoryConverter,
|
|
463
|
+
buildA2AAuthHeaders,
|
|
464
|
+
extractClaudeSessionId,
|
|
465
|
+
extractCodexSessionId,
|
|
466
|
+
extractGoogleAdkSessionId,
|
|
467
|
+
extractOpencodeSessionId
|
|
468
|
+
};
|
package/dist/core.cjs
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
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/core/index.ts
|
|
21
|
+
var core_exports = {};
|
|
22
|
+
__export(core_exports, {
|
|
23
|
+
ConsoleLogger: () => ConsoleLogger,
|
|
24
|
+
NoopLogger: () => NoopLogger,
|
|
25
|
+
RuntimeStateError: () => RuntimeStateError,
|
|
26
|
+
SimpleAdapter: () => SimpleAdapter,
|
|
27
|
+
ThenvoiSdkError: () => ThenvoiSdkError,
|
|
28
|
+
TransportError: () => TransportError,
|
|
29
|
+
UnsupportedFeatureError: () => UnsupportedFeatureError,
|
|
30
|
+
ValidationError: () => ValidationError
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(core_exports);
|
|
33
|
+
|
|
34
|
+
// src/core/simpleAdapter.ts
|
|
35
|
+
var SimpleAdapter = class {
|
|
36
|
+
historyConverter;
|
|
37
|
+
agentName = "";
|
|
38
|
+
agentDescription = "";
|
|
39
|
+
constructor(options) {
|
|
40
|
+
this.historyConverter = options?.historyConverter;
|
|
41
|
+
}
|
|
42
|
+
async onCleanup(_roomId) {
|
|
43
|
+
}
|
|
44
|
+
async onStarted(agentName, agentDescription) {
|
|
45
|
+
this.agentName = agentName;
|
|
46
|
+
this.agentDescription = agentDescription;
|
|
47
|
+
}
|
|
48
|
+
async onEvent(input) {
|
|
49
|
+
const history = this.convertHistory(input.history);
|
|
50
|
+
await this.onMessage(
|
|
51
|
+
input.message,
|
|
52
|
+
input.tools,
|
|
53
|
+
history,
|
|
54
|
+
input.participantsMessage,
|
|
55
|
+
input.contactsMessage,
|
|
56
|
+
{
|
|
57
|
+
isSessionBootstrap: input.isSessionBootstrap,
|
|
58
|
+
roomId: input.roomId
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
convertHistory(provider) {
|
|
63
|
+
if (!this.historyConverter) {
|
|
64
|
+
return provider;
|
|
65
|
+
}
|
|
66
|
+
return provider.convert(this.historyConverter);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// src/core/errors.ts
|
|
71
|
+
var ThenvoiSdkError = class extends Error {
|
|
72
|
+
constructor(message, cause) {
|
|
73
|
+
super(message, cause !== void 0 ? { cause } : void 0);
|
|
74
|
+
this.name = "ThenvoiSdkError";
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
var UnsupportedFeatureError = class extends ThenvoiSdkError {
|
|
78
|
+
constructor(message) {
|
|
79
|
+
super(message);
|
|
80
|
+
this.name = "UnsupportedFeatureError";
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
var ValidationError = class extends ThenvoiSdkError {
|
|
84
|
+
constructor(message, cause) {
|
|
85
|
+
super(message, cause);
|
|
86
|
+
this.name = "ValidationError";
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
var TransportError = class extends ThenvoiSdkError {
|
|
90
|
+
constructor(message, cause) {
|
|
91
|
+
super(message, cause);
|
|
92
|
+
this.name = "TransportError";
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
var RuntimeStateError = class extends ThenvoiSdkError {
|
|
96
|
+
constructor(message) {
|
|
97
|
+
super(message);
|
|
98
|
+
this.name = "RuntimeStateError";
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
// src/core/logger.ts
|
|
103
|
+
var noop = () => void 0;
|
|
104
|
+
var REDACTED_VALUE = "[REDACTED]";
|
|
105
|
+
var CIRCULAR_VALUE = "[Circular]";
|
|
106
|
+
var SENSITIVE_KEY_PATTERN = /(authorization|api[-_]?key|token|secret|password|cookie)/i;
|
|
107
|
+
var NoopLogger = class {
|
|
108
|
+
debug = noop;
|
|
109
|
+
info = noop;
|
|
110
|
+
warn = noop;
|
|
111
|
+
error = noop;
|
|
112
|
+
};
|
|
113
|
+
var ConsoleLogger = class {
|
|
114
|
+
debug(message, context) {
|
|
115
|
+
this.emit("debug", message, context);
|
|
116
|
+
}
|
|
117
|
+
info(message, context) {
|
|
118
|
+
this.emit("info", message, context);
|
|
119
|
+
}
|
|
120
|
+
warn(message, context) {
|
|
121
|
+
this.emit("warn", message, context);
|
|
122
|
+
}
|
|
123
|
+
error(message, context) {
|
|
124
|
+
const payload = context ? ` ${safeSerializeContext(context)}` : "";
|
|
125
|
+
process.stderr.write(`${message}${payload}
|
|
126
|
+
`);
|
|
127
|
+
}
|
|
128
|
+
emit(level, message, context) {
|
|
129
|
+
const fn = console[level];
|
|
130
|
+
if (context === void 0) {
|
|
131
|
+
fn(message);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
fn(message, sanitizeValue(context));
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
function safeSerializeContext(context) {
|
|
138
|
+
try {
|
|
139
|
+
return JSON.stringify(sanitizeValue(context));
|
|
140
|
+
} catch {
|
|
141
|
+
return JSON.stringify({ context: "[Unserializable]" });
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function sanitizeValue(value, seen = /* @__PURE__ */ new WeakSet()) {
|
|
145
|
+
if (value === null || value === void 0) {
|
|
146
|
+
return value;
|
|
147
|
+
}
|
|
148
|
+
if (typeof value !== "object") {
|
|
149
|
+
return value;
|
|
150
|
+
}
|
|
151
|
+
if (value instanceof Error) {
|
|
152
|
+
return sanitizeValue(
|
|
153
|
+
{
|
|
154
|
+
name: value.name,
|
|
155
|
+
message: value.message,
|
|
156
|
+
stack: value.stack,
|
|
157
|
+
...value.cause !== void 0 ? { cause: value.cause } : {}
|
|
158
|
+
},
|
|
159
|
+
seen
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
if (seen.has(value)) {
|
|
163
|
+
return CIRCULAR_VALUE;
|
|
164
|
+
}
|
|
165
|
+
seen.add(value);
|
|
166
|
+
if (Array.isArray(value)) {
|
|
167
|
+
return value.map((entry) => sanitizeValue(entry, seen));
|
|
168
|
+
}
|
|
169
|
+
const sanitized = {};
|
|
170
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
171
|
+
sanitized[key] = SENSITIVE_KEY_PATTERN.test(key) ? REDACTED_VALUE : sanitizeValue(entry, seen);
|
|
172
|
+
}
|
|
173
|
+
return sanitized;
|
|
174
|
+
}
|
|
175
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
176
|
+
0 && (module.exports = {
|
|
177
|
+
ConsoleLogger,
|
|
178
|
+
NoopLogger,
|
|
179
|
+
RuntimeStateError,
|
|
180
|
+
SimpleAdapter,
|
|
181
|
+
ThenvoiSdkError,
|
|
182
|
+
TransportError,
|
|
183
|
+
UnsupportedFeatureError,
|
|
184
|
+
ValidationError
|
|
185
|
+
});
|
package/dist/core.d.cts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export { S as SimpleAdapter } from './simpleAdapter-DqhvjsGr.cjs';
|
|
2
|
+
export { A as AdapterToolsProtocol, a as AgentToolsProtocol, C as ContactTools, F as FrameworkAdapter, b as FrameworkAdapterInput, H as HistoryConverter, M as MemoryTools, c as MessagingTools, P as ParticipantTools, d as PeerLookupTools, e as Preprocessor, R as RoomParticipantTools, T as ToolExecutor, f as ToolSchemaProvider } from './protocols-CInhtFpA.cjs';
|
|
3
|
+
export { C as ConsoleLogger, L as Logger, N as NoopLogger } from './logger-CABQOnlR.cjs';
|
|
4
|
+
import './dtos-DUpbIu8k.cjs';
|
|
5
|
+
|
|
6
|
+
declare class ThenvoiSdkError extends Error {
|
|
7
|
+
constructor(message: string, cause?: unknown);
|
|
8
|
+
}
|
|
9
|
+
declare class UnsupportedFeatureError extends ThenvoiSdkError {
|
|
10
|
+
constructor(message: string);
|
|
11
|
+
}
|
|
12
|
+
declare class ValidationError extends ThenvoiSdkError {
|
|
13
|
+
constructor(message: string, cause?: unknown);
|
|
14
|
+
}
|
|
15
|
+
declare class TransportError extends ThenvoiSdkError {
|
|
16
|
+
constructor(message: string, cause?: unknown);
|
|
17
|
+
}
|
|
18
|
+
declare class RuntimeStateError extends ThenvoiSdkError {
|
|
19
|
+
constructor(message: string);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { RuntimeStateError, ThenvoiSdkError, TransportError, UnsupportedFeatureError, ValidationError };
|
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export { S as SimpleAdapter } from './simpleAdapter-9OE_p6QW.js';
|
|
2
|
+
export { A as AdapterToolsProtocol, a as AgentToolsProtocol, C as ContactTools, F as FrameworkAdapter, b as FrameworkAdapterInput, H as HistoryConverter, M as MemoryTools, c as MessagingTools, P as ParticipantTools, d as PeerLookupTools, e as Preprocessor, R as RoomParticipantTools, T as ToolExecutor, f as ToolSchemaProvider } from './protocols-DrhzOH6K.js';
|
|
3
|
+
export { C as ConsoleLogger, L as Logger, N as NoopLogger } from './logger-CABQOnlR.js';
|
|
4
|
+
import './dtos-DUpbIu8k.js';
|
|
5
|
+
|
|
6
|
+
declare class ThenvoiSdkError extends Error {
|
|
7
|
+
constructor(message: string, cause?: unknown);
|
|
8
|
+
}
|
|
9
|
+
declare class UnsupportedFeatureError extends ThenvoiSdkError {
|
|
10
|
+
constructor(message: string);
|
|
11
|
+
}
|
|
12
|
+
declare class ValidationError extends ThenvoiSdkError {
|
|
13
|
+
constructor(message: string, cause?: unknown);
|
|
14
|
+
}
|
|
15
|
+
declare class TransportError extends ThenvoiSdkError {
|
|
16
|
+
constructor(message: string, cause?: unknown);
|
|
17
|
+
}
|
|
18
|
+
declare class RuntimeStateError extends ThenvoiSdkError {
|
|
19
|
+
constructor(message: string);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { RuntimeStateError, ThenvoiSdkError, TransportError, UnsupportedFeatureError, ValidationError };
|