@band-ai/sdk 0.2.1 → 0.3.1
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/{ClaudeSDKAdapter-Cna5P1dR.d.ts → ClaudeSDKAdapter-CXud2DBE.d.ts} +2 -1
- package/dist/{ClaudeSDKAdapter-BY4zEbCl.d.cts → ClaudeSDKAdapter-Cx6zhSaG.d.cts} +2 -1
- package/dist/adapters.cjs +246 -116
- package/dist/adapters.d.cts +14 -3
- package/dist/adapters.d.ts +14 -3
- package/dist/adapters.js +143 -44
- package/dist/chunk-F63TPOI3.js +29 -0
- package/dist/{chunk-3BKAC4OZ.js → chunk-JADCAMZY.js} +8 -0
- package/dist/{chunk-N2QTUMGO.js → chunk-JJF44XWA.js} +365 -249
- package/dist/{chunk-TLBCKDQO.js → chunk-K5KAEYPF.js} +2 -2
- package/dist/{chunk-ZZJRRBPQ.js → chunk-KXJ74J73.js} +1 -1
- package/dist/{chunk-NMZLX7TP.js → chunk-MQBBWYRP.js} +52 -45
- package/dist/{chunk-RV76SKFT.js → chunk-MQY74R7D.js} +2 -20
- package/dist/{chunk-LBWKISBS.js → chunk-OH6VVVKT.js} +21 -0
- package/dist/{chunk-EAI2M3WM.js → chunk-W5IAI6Z4.js} +1 -1
- package/dist/{chunk-4IAXZBXX.js → chunk-WA7CHXUS.js} +2 -2
- package/dist/{chunk-NT7TBFX2.js → chunk-XWHWJP4I.js} +2 -2
- package/dist/{chunk-WLCM2OXG.js → chunk-YJ42AZO4.js} +1 -1
- package/dist/converters.js +6 -5
- package/dist/index.cjs +405 -277
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +12 -11
- package/dist/mcp-claude.js +4 -3
- package/dist/mcp.js +5 -4
- package/dist/rest.js +3 -3
- package/dist/runtime.cjs +387 -362
- package/dist/runtime.d.cts +10 -39
- package/dist/runtime.d.ts +10 -39
- package/dist/runtime.js +20 -142
- package/dist/{schemas-BotL3ZLH.d.cts → schemas-BgJhlqqO.d.cts} +57 -13
- package/dist/{schemas-DBsC4J1g.d.ts → schemas-C4mK1WSs.d.ts} +57 -13
- package/dist/testing.cjs +11 -0
- package/dist/testing.js +8 -1
- package/dist/{types-D958TC71.d.cts → types-BNNtOXu3.d.cts} +1 -1
- package/dist/{types-BTN_ZETM.d.ts → types-DFUtpxah.d.ts} +1 -1
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { S as SimpleAdapter } from './simpleAdapter--wznuoOw.js';
|
|
2
2
|
import { A as AdapterToolsProtocol, a as AgentToolsProtocol, c as MessagingTools, T as ToolExecutor, f as ToolSchemaProvider, H as HistoryConverter } from './protocols-Bwwcql0h.js';
|
|
3
|
-
import { H as HistoryProvider, P as PlatformMessage } from './types-
|
|
3
|
+
import { H as HistoryProvider, P as PlatformMessage } from './types-DFUtpxah.js';
|
|
4
4
|
import { L as Logger } from './logger-CABQOnlR.js';
|
|
5
5
|
import { C as CustomToolDef } from './customTools-BzF0IISO.js';
|
|
6
6
|
import { m as ToolModelMessage, n as ToolModelSchema, M as MetadataMap } from './dtos-B8KU_q4d.js';
|
|
@@ -562,6 +562,7 @@ declare class GoogleADKAdapter extends SimpleAdapter<GoogleADKMessages, AdapterT
|
|
|
562
562
|
private buildPrompt;
|
|
563
563
|
private formatIncomingMessage;
|
|
564
564
|
private reportExecutionEvent;
|
|
565
|
+
private warnOnFailedSend;
|
|
565
566
|
}
|
|
566
567
|
|
|
567
568
|
interface LangGraphGraph {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { S as SimpleAdapter } from './simpleAdapter-BpT4XbZC.cjs';
|
|
2
2
|
import { A as AdapterToolsProtocol, a as AgentToolsProtocol, c as MessagingTools, T as ToolExecutor, f as ToolSchemaProvider, H as HistoryConverter } from './protocols-Bz1rxcUg.cjs';
|
|
3
|
-
import { H as HistoryProvider, P as PlatformMessage } from './types-
|
|
3
|
+
import { H as HistoryProvider, P as PlatformMessage } from './types-BNNtOXu3.cjs';
|
|
4
4
|
import { L as Logger } from './logger-CABQOnlR.cjs';
|
|
5
5
|
import { C as CustomToolDef } from './customTools-BzF0IISO.cjs';
|
|
6
6
|
import { m as ToolModelMessage, n as ToolModelSchema, M as MetadataMap } from './dtos-B8KU_q4d.cjs';
|
|
@@ -562,6 +562,7 @@ declare class GoogleADKAdapter extends SimpleAdapter<GoogleADKMessages, AdapterT
|
|
|
562
562
|
private buildPrompt;
|
|
563
563
|
private formatIncomingMessage;
|
|
564
564
|
private reportExecutionEvent;
|
|
565
|
+
private warnOnFailedSend;
|
|
565
566
|
}
|
|
566
567
|
|
|
567
568
|
interface LangGraphGraph {
|
package/dist/adapters.cjs
CHANGED
|
@@ -141,13 +141,17 @@ var init_memory = __esm({
|
|
|
141
141
|
});
|
|
142
142
|
|
|
143
143
|
// src/contracts/chatEvents.ts
|
|
144
|
-
|
|
144
|
+
function isBlankEventContent(content) {
|
|
145
|
+
return !VISIBLE_CONTENT_PATTERN.test(content);
|
|
146
|
+
}
|
|
147
|
+
var CHAT_EVENT_TYPES, CHAT_MESSAGE_TYPES, VISIBLE_CONTENT_PATTERN;
|
|
145
148
|
var init_chatEvents = __esm({
|
|
146
149
|
"src/contracts/chatEvents.ts"() {
|
|
147
150
|
"use strict";
|
|
148
151
|
init_errors();
|
|
149
152
|
CHAT_EVENT_TYPES = ["tool_call", "tool_result", "thought", "error", "task"];
|
|
150
153
|
CHAT_MESSAGE_TYPES = ["text", ...CHAT_EVENT_TYPES];
|
|
154
|
+
VISIBLE_CONTENT_PATTERN = /[\p{L}\p{N}\p{P}\p{S}]/u;
|
|
151
155
|
}
|
|
152
156
|
});
|
|
153
157
|
|
|
@@ -496,6 +500,13 @@ function isToolExecutorError(value) {
|
|
|
496
500
|
const candidate = value;
|
|
497
501
|
return candidate.ok === false && typeof candidate.errorType === "string" && TOOL_EXECUTOR_ERROR_TYPES.includes(candidate.errorType) && typeof candidate.toolName === "string" && typeof candidate.message === "string" && typeof candidate.legacyMessage === "string";
|
|
498
502
|
}
|
|
503
|
+
function isStructuredToolFailure(value) {
|
|
504
|
+
if (!value || typeof value !== "object") {
|
|
505
|
+
return false;
|
|
506
|
+
}
|
|
507
|
+
const payload = value;
|
|
508
|
+
return payload.ok === false && typeof payload.message === "string";
|
|
509
|
+
}
|
|
499
510
|
function toLegacyToolExecutorErrorMessage(value) {
|
|
500
511
|
if (typeof value === "string") {
|
|
501
512
|
return value;
|
|
@@ -1246,7 +1257,116 @@ ${customSection}`.trim();
|
|
|
1246
1257
|
return parts.join("\n\n");
|
|
1247
1258
|
}
|
|
1248
1259
|
|
|
1260
|
+
// src/runtime/types.ts
|
|
1261
|
+
function ensureHandlePrefix(handle) {
|
|
1262
|
+
if (!handle) {
|
|
1263
|
+
return null;
|
|
1264
|
+
}
|
|
1265
|
+
return handle.startsWith("@") ? handle : `@${handle}`;
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
// src/runtime/formatters.ts
|
|
1269
|
+
function isMetadataMap(value) {
|
|
1270
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
1271
|
+
}
|
|
1272
|
+
function mentionSubjectsFromMetadata(metadata) {
|
|
1273
|
+
const mentions = metadata?.mentions;
|
|
1274
|
+
if (!Array.isArray(mentions)) {
|
|
1275
|
+
return [];
|
|
1276
|
+
}
|
|
1277
|
+
const subjects = [];
|
|
1278
|
+
for (const mention of mentions) {
|
|
1279
|
+
if (!isMetadataMap(mention) || typeof mention.id !== "string") {
|
|
1280
|
+
continue;
|
|
1281
|
+
}
|
|
1282
|
+
const label = [mention.handle, mention.username, mention.name].find(
|
|
1283
|
+
(value) => typeof value === "string" && value.trim().length > 0
|
|
1284
|
+
);
|
|
1285
|
+
if (label === void 0) {
|
|
1286
|
+
continue;
|
|
1287
|
+
}
|
|
1288
|
+
subjects.push({ id: mention.id, handle: label });
|
|
1289
|
+
}
|
|
1290
|
+
return subjects;
|
|
1291
|
+
}
|
|
1292
|
+
function replaceUuidMentions(content, participants) {
|
|
1293
|
+
if (!content || participants.length === 0) {
|
|
1294
|
+
return content;
|
|
1295
|
+
}
|
|
1296
|
+
let next = content;
|
|
1297
|
+
for (const participant of participants) {
|
|
1298
|
+
const participantId = participant.id;
|
|
1299
|
+
const handle = participant.handle;
|
|
1300
|
+
if (typeof participantId === "string" && typeof handle === "string") {
|
|
1301
|
+
next = next.replaceAll(`@[[${participantId}]]`, ensureHandlePrefix(handle) ?? "");
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
return next;
|
|
1305
|
+
}
|
|
1306
|
+
function formatMessageForLlm(message, participants) {
|
|
1307
|
+
const senderType = String(message.sender_type ?? "");
|
|
1308
|
+
const senderName = String(message.sender_name ?? message.name ?? senderType);
|
|
1309
|
+
const content = participants ? replaceUuidMentions(String(message.content ?? ""), participants) : String(message.content ?? "");
|
|
1310
|
+
return {
|
|
1311
|
+
role: senderType === "Agent" ? "assistant" : "user",
|
|
1312
|
+
content,
|
|
1313
|
+
sender_name: senderName,
|
|
1314
|
+
sender_type: senderType,
|
|
1315
|
+
message_type: String(message.message_type ?? "text"),
|
|
1316
|
+
metadata: isMetadataMap(message.metadata) ? message.metadata : {}
|
|
1317
|
+
};
|
|
1318
|
+
}
|
|
1319
|
+
function formatHistoryForLlm(messages, options) {
|
|
1320
|
+
const excludeId = options?.excludeId;
|
|
1321
|
+
const participants = options?.participants;
|
|
1322
|
+
return messages.filter((message) => String(message.id ?? "") !== excludeId).map((message) => formatMessageForLlm(message, participants));
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
// src/adapters/shared/conversationPrompt.ts
|
|
1326
|
+
function systemUpdateParts(participantsMessage, contactsMessage) {
|
|
1327
|
+
const parts = [];
|
|
1328
|
+
if (participantsMessage) {
|
|
1329
|
+
parts.push(`[System]: ${participantsMessage}`);
|
|
1330
|
+
}
|
|
1331
|
+
if (contactsMessage) {
|
|
1332
|
+
parts.push(`[System]: ${contactsMessage}`);
|
|
1333
|
+
}
|
|
1334
|
+
return parts;
|
|
1335
|
+
}
|
|
1336
|
+
function buildConversationPrompt(options) {
|
|
1337
|
+
const parts = [];
|
|
1338
|
+
if (options.isSessionBootstrap && options.history.length > 0) {
|
|
1339
|
+
const historyText = options.history.raw.slice(-(options.maxHistoryMessages ?? 50)).map(formatHistoryLine).join("\n");
|
|
1340
|
+
parts.push(`${options.historyHeader}
|
|
1341
|
+
${historyText}`);
|
|
1342
|
+
}
|
|
1343
|
+
parts.push(...systemUpdateParts(options.participantsMessage, options.contactsMessage));
|
|
1344
|
+
parts.push(options.currentMessage);
|
|
1345
|
+
return parts.join("\n\n");
|
|
1346
|
+
}
|
|
1347
|
+
function formatHistoryLine(entry) {
|
|
1348
|
+
const sender = String(entry.sender_name ?? entry.sender_type ?? "Unknown");
|
|
1349
|
+
const content = String(entry.content ?? "");
|
|
1350
|
+
return `[${sender}]: ${content}`;
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1353
|
+
// src/adapters/shared/withTimeout.ts
|
|
1354
|
+
async function withTimeout(promise, timeoutMs, message) {
|
|
1355
|
+
let timer;
|
|
1356
|
+
try {
|
|
1357
|
+
return await Promise.race([
|
|
1358
|
+
promise,
|
|
1359
|
+
new Promise((_, reject) => {
|
|
1360
|
+
timer = setTimeout(() => reject(new Error(message)), timeoutMs);
|
|
1361
|
+
})
|
|
1362
|
+
]);
|
|
1363
|
+
} finally {
|
|
1364
|
+
clearTimeout(timer);
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1249
1368
|
// src/adapters/acp/ACPClientAdapter.ts
|
|
1369
|
+
init_chatEvents();
|
|
1250
1370
|
init_schemas();
|
|
1251
1371
|
|
|
1252
1372
|
// src/mcp/auth.ts
|
|
@@ -2029,6 +2149,7 @@ var acpModule = new LazyAsyncValue({
|
|
|
2029
2149
|
|
|
2030
2150
|
// src/adapters/acp/ACPClientAdapter.ts
|
|
2031
2151
|
var DEFAULT_PERMISSION_TIMEOUT_MS = 5 * 6e4;
|
|
2152
|
+
var SET_SESSION_MODE_TIMEOUT_MS = 1e4;
|
|
2032
2153
|
var ACPClientAdapter = class extends SimpleAdapter {
|
|
2033
2154
|
command;
|
|
2034
2155
|
cwd;
|
|
@@ -2046,6 +2167,7 @@ var ACPClientAdapter = class extends SimpleAdapter {
|
|
|
2046
2167
|
bootstrappedSessions = /* @__PURE__ */ new Set();
|
|
2047
2168
|
pendingPermissions = /* @__PURE__ */ new Map();
|
|
2048
2169
|
resolvePermission;
|
|
2170
|
+
resolveSessionMode;
|
|
2049
2171
|
permissionTimeoutMs;
|
|
2050
2172
|
logger;
|
|
2051
2173
|
backend = null;
|
|
@@ -2075,9 +2197,10 @@ var ACPClientAdapter = class extends SimpleAdapter {
|
|
|
2075
2197
|
this.clientCapabilities = options.clientCapabilities;
|
|
2076
2198
|
this.connectionFactory = options.connectionFactory ?? createSubprocessConnection;
|
|
2077
2199
|
this.resolvePermission = options.resolvePermission;
|
|
2200
|
+
this.resolveSessionMode = options.resolveSessionMode;
|
|
2078
2201
|
this.logger = options.logger ?? new NoopLogger();
|
|
2079
2202
|
this.permissionTimeoutMs = options.permissionTimeoutMs ?? DEFAULT_PERMISSION_TIMEOUT_MS;
|
|
2080
|
-
if (this.resolvePermission && (!Number.isFinite(this.permissionTimeoutMs) || this.permissionTimeoutMs <= 0)) {
|
|
2203
|
+
if ((this.resolvePermission || this.resolveSessionMode) && (!Number.isFinite(this.permissionTimeoutMs) || this.permissionTimeoutMs <= 0)) {
|
|
2081
2204
|
throw new ValidationError(`permissionTimeoutMs must be a positive finite number, got ${options.permissionTimeoutMs}`);
|
|
2082
2205
|
}
|
|
2083
2206
|
}
|
|
@@ -2091,7 +2214,7 @@ var ACPClientAdapter = class extends SimpleAdapter {
|
|
|
2091
2214
|
});
|
|
2092
2215
|
await this.ensureConnection();
|
|
2093
2216
|
}
|
|
2094
|
-
async onMessage(message, tools, history,
|
|
2217
|
+
async onMessage(message, tools, history, participantsMessage, contactsMessage, context) {
|
|
2095
2218
|
if (context.isSessionBootstrap) {
|
|
2096
2219
|
this.rehydrate(history);
|
|
2097
2220
|
}
|
|
@@ -2107,9 +2230,11 @@ var ACPClientAdapter = class extends SimpleAdapter {
|
|
|
2107
2230
|
sessionId,
|
|
2108
2231
|
(params) => this.handlePermissionRequest(tools, context.roomId, params)
|
|
2109
2232
|
);
|
|
2110
|
-
const
|
|
2233
|
+
const content = replaceUuidMentions(message.content, mentionSubjectsFromMetadata(message.metadata));
|
|
2234
|
+
const messageWithContext = [...systemUpdateParts(participantsMessage, contactsMessage), content].join("\n\n");
|
|
2235
|
+
const promptText = this.bootstrappedSessions.has(sessionId) ? messageWithContext : `${this.buildSystemContext(context.roomId, message)}
|
|
2111
2236
|
|
|
2112
|
-
${
|
|
2237
|
+
${messageWithContext}`;
|
|
2113
2238
|
this.bootstrappedSessions.add(sessionId);
|
|
2114
2239
|
try {
|
|
2115
2240
|
await connection.prompt({
|
|
@@ -2236,9 +2361,10 @@ ${message.content}`;
|
|
|
2236
2361
|
const mcpServers = await this.buildSessionMcpServers();
|
|
2237
2362
|
if (existingSessionId) {
|
|
2238
2363
|
const restored = await this.tryRestoreSession(connection, existingSessionId, mcpServers);
|
|
2239
|
-
if (restored) {
|
|
2364
|
+
if (restored.ok) {
|
|
2240
2365
|
this.activeSessions.add(existingSessionId);
|
|
2241
2366
|
this.bootstrappedSessions.add(existingSessionId);
|
|
2367
|
+
await this.configureSessionMode(roomId, existingSessionId, restored.modes, connection);
|
|
2242
2368
|
return existingSessionId;
|
|
2243
2369
|
}
|
|
2244
2370
|
}
|
|
@@ -2248,30 +2374,92 @@ ${message.content}`;
|
|
|
2248
2374
|
});
|
|
2249
2375
|
this.roomToSession.set(roomId, created.sessionId);
|
|
2250
2376
|
this.activeSessions.add(created.sessionId);
|
|
2377
|
+
await this.configureSessionMode(roomId, created.sessionId, created.modes, connection);
|
|
2251
2378
|
return created.sessionId;
|
|
2252
2379
|
}
|
|
2380
|
+
// Best-effort: never throws, so a mode switch going wrong can't take a
|
|
2381
|
+
// session establishment down with it.
|
|
2382
|
+
async configureSessionMode(roomId, sessionId, modes, connection) {
|
|
2383
|
+
if (!this.resolveSessionMode || !modes) {
|
|
2384
|
+
return;
|
|
2385
|
+
}
|
|
2386
|
+
const availableModes = Array.isArray(modes.availableModes) ? modes.availableModes : [];
|
|
2387
|
+
if (availableModes.length === 0) {
|
|
2388
|
+
return;
|
|
2389
|
+
}
|
|
2390
|
+
const selectedModeId = await this.resolveSessionModeManually(
|
|
2391
|
+
(signal) => this.resolveSessionMode({
|
|
2392
|
+
roomId,
|
|
2393
|
+
sessionId,
|
|
2394
|
+
currentModeId: modes.currentModeId,
|
|
2395
|
+
modes: availableModes
|
|
2396
|
+
}, signal),
|
|
2397
|
+
connection.signal
|
|
2398
|
+
);
|
|
2399
|
+
if (!selectedModeId || selectedModeId === modes.currentModeId) {
|
|
2400
|
+
return;
|
|
2401
|
+
}
|
|
2402
|
+
if (!availableModes.some((mode) => mode?.id === selectedModeId)) {
|
|
2403
|
+
this.safeWarn("resolveSessionMode selected a mode id this session does not advertise", {
|
|
2404
|
+
sessionId,
|
|
2405
|
+
selectedModeId,
|
|
2406
|
+
availableModeIds: availableModes.map((mode) => mode?.id)
|
|
2407
|
+
});
|
|
2408
|
+
return;
|
|
2409
|
+
}
|
|
2410
|
+
try {
|
|
2411
|
+
await withTimeout(
|
|
2412
|
+
connection.setSessionMode({ sessionId, modeId: selectedModeId }),
|
|
2413
|
+
SET_SESSION_MODE_TIMEOUT_MS,
|
|
2414
|
+
`setSessionMode did not respond within ${SET_SESSION_MODE_TIMEOUT_MS}ms`
|
|
2415
|
+
);
|
|
2416
|
+
} catch (error) {
|
|
2417
|
+
this.safeWarn("failed to switch session into the selected mode", {
|
|
2418
|
+
sessionId,
|
|
2419
|
+
selectedModeId,
|
|
2420
|
+
error: String(error)
|
|
2421
|
+
});
|
|
2422
|
+
}
|
|
2423
|
+
}
|
|
2424
|
+
async resolveSessionModeManually(resolver, signal) {
|
|
2425
|
+
const controller = new AbortController();
|
|
2426
|
+
const abort = () => controller.abort();
|
|
2427
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
2428
|
+
let timer;
|
|
2429
|
+
try {
|
|
2430
|
+
const cancelled = new Promise((resolve) => {
|
|
2431
|
+
controller.signal.addEventListener("abort", () => resolve(void 0), { once: true });
|
|
2432
|
+
});
|
|
2433
|
+
const timeout = new Promise((resolve) => {
|
|
2434
|
+
timer = setTimeout(() => resolve(void 0), this.permissionTimeoutMs);
|
|
2435
|
+
});
|
|
2436
|
+
return await Promise.race([
|
|
2437
|
+
Promise.resolve().then(() => resolver(controller.signal)).catch((error) => {
|
|
2438
|
+
this.safeWarn("resolveSessionMode threw; preserving the harness default", { error: String(error) });
|
|
2439
|
+
return void 0;
|
|
2440
|
+
}),
|
|
2441
|
+
timeout,
|
|
2442
|
+
cancelled
|
|
2443
|
+
]);
|
|
2444
|
+
} finally {
|
|
2445
|
+
clearTimeout(timer);
|
|
2446
|
+
signal.removeEventListener("abort", abort);
|
|
2447
|
+
controller.abort();
|
|
2448
|
+
}
|
|
2449
|
+
}
|
|
2253
2450
|
async tryRestoreSession(connection, sessionId, mcpServers) {
|
|
2451
|
+
const capabilities = this.connectionState?.agentCapabilities;
|
|
2452
|
+
const params = { cwd: this.cwd, mcpServers, sessionId };
|
|
2453
|
+
const restore = capabilities?.loadSession ? () => connection.loadSession(params) : capabilities?.sessionCapabilities?.resume ? () => connection.unstable_resumeSession(params) : null;
|
|
2454
|
+
if (!restore) {
|
|
2455
|
+
return { ok: false };
|
|
2456
|
+
}
|
|
2254
2457
|
try {
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
cwd: this.cwd,
|
|
2258
|
-
mcpServers,
|
|
2259
|
-
sessionId
|
|
2260
|
-
});
|
|
2261
|
-
return true;
|
|
2262
|
-
}
|
|
2263
|
-
if (this.connectionState?.agentCapabilities?.sessionCapabilities?.resume) {
|
|
2264
|
-
await connection.unstable_resumeSession({
|
|
2265
|
-
cwd: this.cwd,
|
|
2266
|
-
mcpServers,
|
|
2267
|
-
sessionId
|
|
2268
|
-
});
|
|
2269
|
-
return true;
|
|
2270
|
-
}
|
|
2458
|
+
const restored = await restore();
|
|
2459
|
+
return { ok: true, modes: restored?.modes };
|
|
2271
2460
|
} catch {
|
|
2272
|
-
return false;
|
|
2461
|
+
return { ok: false };
|
|
2273
2462
|
}
|
|
2274
|
-
return false;
|
|
2275
2463
|
}
|
|
2276
2464
|
async buildSessionMcpServers() {
|
|
2277
2465
|
const mcpServers = [...this.mcpServers];
|
|
@@ -2410,6 +2598,18 @@ ${message.content}`;
|
|
|
2410
2598
|
const matched = chosenId !== void 0 && options.some((option) => option.optionId === chosenId);
|
|
2411
2599
|
return matched ? { outcome: { outcome: "selected", optionId: chosenId } } : { outcome: { outcome: "cancelled" } };
|
|
2412
2600
|
}
|
|
2601
|
+
// A caller-supplied `Logger` isn't guaranteed to be synchronous or
|
|
2602
|
+
// non-throwing. Every best-effort warning in this file routes through here
|
|
2603
|
+
// so one failing sink — a synchronous throw, or an `async` implementation
|
|
2604
|
+
// rejecting (the `Logger` interface's `void` return type permits either;
|
|
2605
|
+
// a bare try/catch only ever catches the former) — can't turn a warning
|
|
2606
|
+
// into an unhandled rejection in its place.
|
|
2607
|
+
safeWarn(message, context) {
|
|
2608
|
+
try {
|
|
2609
|
+
Promise.resolve(this.logger.warn(message, context)).catch(() => void 0);
|
|
2610
|
+
} catch {
|
|
2611
|
+
}
|
|
2612
|
+
}
|
|
2413
2613
|
// Races the caller-supplied resolver against a timeout and against
|
|
2414
2614
|
// `controller`'s own abort signal — aborted externally by
|
|
2415
2615
|
// `cancelPendingPermissions`/`cancelAllPendingPermissions` (fired from
|
|
@@ -2433,10 +2633,7 @@ ${message.content}`;
|
|
|
2433
2633
|
// rejected promise, so both land in the `.catch` below rather than
|
|
2434
2634
|
// escaping this race uncaught.
|
|
2435
2635
|
Promise.resolve().then(() => this.resolvePermission(params, controller.signal)).catch((error) => {
|
|
2436
|
-
|
|
2437
|
-
this.logger.warn("resolvePermission threw; treating as no answer", { error: String(error) });
|
|
2438
|
-
} catch {
|
|
2439
|
-
}
|
|
2636
|
+
this.safeWarn("resolvePermission threw; treating as no answer", { error: String(error) });
|
|
2440
2637
|
return void 0;
|
|
2441
2638
|
}),
|
|
2442
2639
|
timeout,
|
|
@@ -2476,13 +2673,14 @@ ${message.content}`;
|
|
|
2476
2673
|
return;
|
|
2477
2674
|
}
|
|
2478
2675
|
for (const chunk of client.getCollectedChunks(input.sessionId)) {
|
|
2676
|
+
if (isBlankEventContent(chunk.content)) {
|
|
2677
|
+
continue;
|
|
2678
|
+
}
|
|
2479
2679
|
if (chunk.chunkType === "text") {
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
}]);
|
|
2485
|
-
}
|
|
2680
|
+
await input.tools.sendMessage(chunk.content, [{
|
|
2681
|
+
id: input.senderId,
|
|
2682
|
+
handle: input.senderHandle
|
|
2683
|
+
}]);
|
|
2486
2684
|
continue;
|
|
2487
2685
|
}
|
|
2488
2686
|
const messageType = chunk.chunkType === "plan" ? "task" : chunk.chunkType;
|
|
@@ -2590,14 +2788,6 @@ var ACPServerHistoryConverter = class {
|
|
|
2590
2788
|
}
|
|
2591
2789
|
};
|
|
2592
2790
|
|
|
2593
|
-
// src/runtime/types.ts
|
|
2594
|
-
function ensureHandlePrefix(handle) {
|
|
2595
|
-
if (!handle) {
|
|
2596
|
-
return null;
|
|
2597
|
-
}
|
|
2598
|
-
return handle.startsWith("@") ? handle : `@${handle}`;
|
|
2599
|
-
}
|
|
2600
|
-
|
|
2601
2791
|
// src/converters/shared.ts
|
|
2602
2792
|
function asOptionalString(value) {
|
|
2603
2793
|
if (typeof value !== "string") {
|
|
@@ -3436,43 +3626,6 @@ function extractPromptText(prompt) {
|
|
|
3436
3626
|
// src/adapters/tool-calling/ToolCallingAdapter.ts
|
|
3437
3627
|
init_protocols();
|
|
3438
3628
|
|
|
3439
|
-
// src/runtime/formatters.ts
|
|
3440
|
-
function isMetadataMap(value) {
|
|
3441
|
-
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
3442
|
-
}
|
|
3443
|
-
function replaceUuidMentions(content, participants) {
|
|
3444
|
-
if (!content || participants.length === 0) {
|
|
3445
|
-
return content;
|
|
3446
|
-
}
|
|
3447
|
-
let next = content;
|
|
3448
|
-
for (const participant of participants) {
|
|
3449
|
-
const participantId = participant.id;
|
|
3450
|
-
const handle = participant.handle;
|
|
3451
|
-
if (typeof participantId === "string" && typeof handle === "string") {
|
|
3452
|
-
next = next.replaceAll(`@[[${participantId}]]`, ensureHandlePrefix(handle) ?? "");
|
|
3453
|
-
}
|
|
3454
|
-
}
|
|
3455
|
-
return next;
|
|
3456
|
-
}
|
|
3457
|
-
function formatMessageForLlm(message, participants) {
|
|
3458
|
-
const senderType = String(message.sender_type ?? "");
|
|
3459
|
-
const senderName = String(message.sender_name ?? message.name ?? senderType);
|
|
3460
|
-
const content = participants ? replaceUuidMentions(String(message.content ?? ""), participants) : String(message.content ?? "");
|
|
3461
|
-
return {
|
|
3462
|
-
role: senderType === "Agent" ? "assistant" : "user",
|
|
3463
|
-
content,
|
|
3464
|
-
sender_name: senderName,
|
|
3465
|
-
sender_type: senderType,
|
|
3466
|
-
message_type: String(message.message_type ?? "text"),
|
|
3467
|
-
metadata: isMetadataMap(message.metadata) ? message.metadata : {}
|
|
3468
|
-
};
|
|
3469
|
-
}
|
|
3470
|
-
function formatHistoryForLlm(messages, options) {
|
|
3471
|
-
const excludeId = options?.excludeId;
|
|
3472
|
-
const participants = options?.participants;
|
|
3473
|
-
return messages.filter((message) => String(message.id ?? "") !== excludeId).map((message) => formatMessageForLlm(message, participants));
|
|
3474
|
-
}
|
|
3475
|
-
|
|
3476
3629
|
// src/runtime/tools/customTools.ts
|
|
3477
3630
|
var import_zod3 = require("zod");
|
|
3478
3631
|
var import_zod_to_json_schema = require("zod-to-json-schema");
|
|
@@ -5011,18 +5164,28 @@ var GoogleADKAdapter = class extends SimpleAdapter {
|
|
|
5011
5164
|
}
|
|
5012
5165
|
async reportExecutionEvent(sdk, event, tools) {
|
|
5013
5166
|
for (const functionCall of sdk.getFunctionCalls(event)) {
|
|
5014
|
-
await tools.sendEvent(JSON.stringify({
|
|
5167
|
+
const result = await tools.sendEvent(JSON.stringify({
|
|
5015
5168
|
name: functionCall.name ?? "unknown",
|
|
5016
5169
|
args: asToolArgs(functionCall.args),
|
|
5017
5170
|
tool_call_id: functionCall.id ?? ""
|
|
5018
5171
|
}), "tool_call");
|
|
5172
|
+
this.warnOnFailedSend(result, "Google ADK tool_call event send failed", { toolCallId: functionCall.id ?? "" });
|
|
5019
5173
|
}
|
|
5020
5174
|
for (const functionResponse of sdk.getFunctionResponses(event)) {
|
|
5021
|
-
await tools.sendEvent(JSON.stringify({
|
|
5175
|
+
const result = await tools.sendEvent(JSON.stringify({
|
|
5022
5176
|
name: functionResponse.name ?? "unknown",
|
|
5023
5177
|
output: String(functionResponse.response ?? ""),
|
|
5024
5178
|
tool_call_id: functionResponse.id ?? ""
|
|
5025
5179
|
}), "tool_result");
|
|
5180
|
+
this.warnOnFailedSend(result, "Google ADK tool_result event send failed", { toolCallId: functionResponse.id ?? "" });
|
|
5181
|
+
}
|
|
5182
|
+
}
|
|
5183
|
+
warnOnFailedSend(result, message, meta) {
|
|
5184
|
+
if (result.ok === false) {
|
|
5185
|
+
try {
|
|
5186
|
+
this.logger.warn(message, meta);
|
|
5187
|
+
} catch {
|
|
5188
|
+
}
|
|
5026
5189
|
}
|
|
5027
5190
|
}
|
|
5028
5191
|
};
|
|
@@ -9580,29 +9743,6 @@ function delay(ms) {
|
|
|
9580
9743
|
init_errors();
|
|
9581
9744
|
init_schemas();
|
|
9582
9745
|
|
|
9583
|
-
// src/adapters/shared/conversationPrompt.ts
|
|
9584
|
-
function buildConversationPrompt(options) {
|
|
9585
|
-
const parts = [];
|
|
9586
|
-
if (options.isSessionBootstrap && options.history.length > 0) {
|
|
9587
|
-
const historyText = options.history.raw.slice(-(options.maxHistoryMessages ?? 50)).map(formatHistoryLine).join("\n");
|
|
9588
|
-
parts.push(`${options.historyHeader}
|
|
9589
|
-
${historyText}`);
|
|
9590
|
-
}
|
|
9591
|
-
if (options.participantsMessage) {
|
|
9592
|
-
parts.push(`[System]: ${options.participantsMessage}`);
|
|
9593
|
-
}
|
|
9594
|
-
if (options.contactsMessage) {
|
|
9595
|
-
parts.push(`[System]: ${options.contactsMessage}`);
|
|
9596
|
-
}
|
|
9597
|
-
parts.push(options.currentMessage);
|
|
9598
|
-
return parts.join("\n\n");
|
|
9599
|
-
}
|
|
9600
|
-
function formatHistoryLine(entry) {
|
|
9601
|
-
const sender = String(entry.sender_name ?? entry.sender_type ?? "Unknown");
|
|
9602
|
-
const content = String(entry.content ?? "");
|
|
9603
|
-
return `[${sender}]: ${content}`;
|
|
9604
|
-
}
|
|
9605
|
-
|
|
9606
9746
|
// src/converters/claude-sdk.ts
|
|
9607
9747
|
function extractClaudeSessionId(raw) {
|
|
9608
9748
|
const metadata = findLatestTaskMetadata(
|
|
@@ -10626,11 +10766,8 @@ var CodexAdapter = class extends SimpleAdapter {
|
|
|
10626
10766
|
items.push({ type: "text", text: context });
|
|
10627
10767
|
}
|
|
10628
10768
|
}
|
|
10629
|
-
|
|
10630
|
-
items.push({ type: "text", text:
|
|
10631
|
-
}
|
|
10632
|
-
if (input.contactsMessage) {
|
|
10633
|
-
items.push({ type: "text", text: `[System]: ${input.contactsMessage}` });
|
|
10769
|
+
for (const part of systemUpdateParts(input.participantsMessage, input.contactsMessage)) {
|
|
10770
|
+
items.push({ type: "text", text: part });
|
|
10634
10771
|
}
|
|
10635
10772
|
items.push({
|
|
10636
10773
|
type: "text",
|
|
@@ -11058,13 +11195,6 @@ var TURN_STATUS_VALUES = /* @__PURE__ */ new Set([
|
|
|
11058
11195
|
"failed",
|
|
11059
11196
|
"inProgress"
|
|
11060
11197
|
]);
|
|
11061
|
-
function isStructuredToolFailure(value) {
|
|
11062
|
-
if (!value || typeof value !== "object") {
|
|
11063
|
-
return false;
|
|
11064
|
-
}
|
|
11065
|
-
const payload = value;
|
|
11066
|
-
return payload.ok === false && typeof payload.message === "string";
|
|
11067
|
-
}
|
|
11068
11198
|
function isCodexToolOutputError(value) {
|
|
11069
11199
|
return isToolExecutorError(value) || isStructuredToolFailure(value);
|
|
11070
11200
|
}
|
package/dist/adapters.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as A2AAdapter, a as A2AAdapterOptions, K as A2AClientFactory, M as A2AClientLike, b as A2AGatewayAdapter, c as AnthropicAdapter, d as AnthropicAdapterOptions, N as AnthropicClientFactory, Q as AnthropicToolCallingModel, R as AnthropicToolCallingModelOptions, C as CODEX_REASONING_EFFORTS, e as CODEX_REASONING_SUMMARIES, f as CODEX_WEB_SEARCH_MODES, g as ClaudePermissionMode, h as ClaudeSDKAdapter, i as ClaudeSDKAdapterOptions, S as ClaudeSDKQuery, U as ClaudeSDKQueryParams, j as CodexAdapter, k as CodexAdapterConfig, W as CodexAppServerStdioClient, l as CodexApprovalPolicy, X as CodexClientLike, Y as CodexJsonRpcError, m as CodexReasoningEffort, n as CodexReasoningSummary, o as CodexSandboxMode, p as CodexWebSearchMode, Z as DynamicToolCallParams, _ as DynamicToolCallResponse, $ as DynamicToolSpec, G as GeminiAdapter, q as GeminiAdapterOptions, a0 as GeminiClientFactory, a1 as GeminiToolCallingModel, a2 as GeminiToolCallingModelOptions, r as GenericAdapter, s as GenericAdapterHandler, t as GoogleADKAdapter, u as GoogleADKAdapterOptions, a3 as HttpOpencodeClient, a4 as HttpOpencodeClientOptions, a5 as HttpStatusError, L as LangGraphAdapter, v as LangGraphAdapterOptions, w as LangGraphGraph, x as LettaAdapter, y as LettaAdapterOptions, a6 as LettaAgentCreateParams, a7 as LettaClientFactory, a8 as LettaClientLike, a9 as LettaHistoryConverter, aa as LettaMessage, ab as LettaMessageCreateParams, ac as LettaMessages, ad as LettaRequestOptions, ae as LettaResponse, af as LettaResponseMessage, O as OpenAIAdapter, z as OpenAIAdapterOptions, ag as OpenAIClientFactory, ah as OpenAIToolCallingModel, ai as OpenAIToolCallingModelOptions, B as OpencodeAdapter, D as OpencodeAdapterConfig, E as OpencodeApprovalMode, F as OpencodeApprovalReply, aj as OpencodeClientLike, H as OpencodeQuestionMode, P as ParlantAdapter, I as ParlantAdapterOptions, ak as ParlantClientFactory, al as ParlantClientLike, am as ToolCall, an as ToolCallingAdapter, ao as ToolCallingAdapterOptions, T as ToolCallingModel, ap as ToolCallingModelRequest, aq as ToolCallingResponse, ar as ToolResult, as as TurnStartParams, V as VercelAISDKAdapter, J as VercelAISDKAdapterOptions, at as VercelAISDKToolCallingModel, au as VercelAISDKToolCallingModelOptions, av as runSingleToolRound } from './ClaudeSDKAdapter-
|
|
1
|
+
export { A as A2AAdapter, a as A2AAdapterOptions, K as A2AClientFactory, M as A2AClientLike, b as A2AGatewayAdapter, c as AnthropicAdapter, d as AnthropicAdapterOptions, N as AnthropicClientFactory, Q as AnthropicToolCallingModel, R as AnthropicToolCallingModelOptions, C as CODEX_REASONING_EFFORTS, e as CODEX_REASONING_SUMMARIES, f as CODEX_WEB_SEARCH_MODES, g as ClaudePermissionMode, h as ClaudeSDKAdapter, i as ClaudeSDKAdapterOptions, S as ClaudeSDKQuery, U as ClaudeSDKQueryParams, j as CodexAdapter, k as CodexAdapterConfig, W as CodexAppServerStdioClient, l as CodexApprovalPolicy, X as CodexClientLike, Y as CodexJsonRpcError, m as CodexReasoningEffort, n as CodexReasoningSummary, o as CodexSandboxMode, p as CodexWebSearchMode, Z as DynamicToolCallParams, _ as DynamicToolCallResponse, $ as DynamicToolSpec, G as GeminiAdapter, q as GeminiAdapterOptions, a0 as GeminiClientFactory, a1 as GeminiToolCallingModel, a2 as GeminiToolCallingModelOptions, r as GenericAdapter, s as GenericAdapterHandler, t as GoogleADKAdapter, u as GoogleADKAdapterOptions, a3 as HttpOpencodeClient, a4 as HttpOpencodeClientOptions, a5 as HttpStatusError, L as LangGraphAdapter, v as LangGraphAdapterOptions, w as LangGraphGraph, x as LettaAdapter, y as LettaAdapterOptions, a6 as LettaAgentCreateParams, a7 as LettaClientFactory, a8 as LettaClientLike, a9 as LettaHistoryConverter, aa as LettaMessage, ab as LettaMessageCreateParams, ac as LettaMessages, ad as LettaRequestOptions, ae as LettaResponse, af as LettaResponseMessage, O as OpenAIAdapter, z as OpenAIAdapterOptions, ag as OpenAIClientFactory, ah as OpenAIToolCallingModel, ai as OpenAIToolCallingModelOptions, B as OpencodeAdapter, D as OpencodeAdapterConfig, E as OpencodeApprovalMode, F as OpencodeApprovalReply, aj as OpencodeClientLike, H as OpencodeQuestionMode, P as ParlantAdapter, I as ParlantAdapterOptions, ak as ParlantClientFactory, al as ParlantClientLike, am as ToolCall, an as ToolCallingAdapter, ao as ToolCallingAdapterOptions, T as ToolCallingModel, ap as ToolCallingModelRequest, aq as ToolCallingResponse, ar as ToolResult, as as TurnStartParams, V as VercelAISDKAdapter, J as VercelAISDKAdapterOptions, at as VercelAISDKToolCallingModel, au as VercelAISDKToolCallingModelOptions, av as runSingleToolRound } from './ClaudeSDKAdapter-Cx6zhSaG.cjs';
|
|
2
2
|
import * as _agentclientprotocol_sdk from '@agentclientprotocol/sdk';
|
|
3
3
|
import { Client, ClientSideConnection, McpServer, ClientCapabilities, RequestPermissionRequest, SessionMode, AgentSideConnection, SessionModeState, Agent, InitializeResponse, Implementation, Stream, InitializeRequest, LoadSessionRequest, LoadSessionResponse, ListSessionsRequest, ListSessionsResponse, ForkSessionRequest, ForkSessionResponse, ResumeSessionRequest, ResumeSessionResponse, SetSessionModeRequest, SetSessionModeResponse, SetSessionModelRequest, SetSessionModelResponse, SetSessionConfigOptionRequest, SetSessionConfigOptionResponse, AuthenticateRequest, AuthenticateResponse, PromptRequest, PromptResponse } from '@agentclientprotocol/sdk';
|
|
4
4
|
import { A as ACPClientSessionState, a as ACPServerSessionState } from './acp-server-Dlj7D563.cjs';
|
|
@@ -6,7 +6,7 @@ export { G as GatewayHistoryConverter } from './acp-server-Dlj7D563.cjs';
|
|
|
6
6
|
import { S as SimpleAdapter } from './simpleAdapter-BpT4XbZC.cjs';
|
|
7
7
|
import { L as Logger } from './logger-CABQOnlR.cjs';
|
|
8
8
|
import { A as AdapterToolsProtocol, c as MessagingTools } from './protocols-Bz1rxcUg.cjs';
|
|
9
|
-
import { P as PlatformMessage } from './types-
|
|
9
|
+
import { P as PlatformMessage } from './types-BNNtOXu3.cjs';
|
|
10
10
|
import { M as McpToolRegistration } from './sdk-BTciSLRQ.cjs';
|
|
11
11
|
import { R as RestApi } from './types-BgYFd_Yw.cjs';
|
|
12
12
|
import { b as GatewayServerLike, c as GatewayServerOptions } from './opencode-2YdscIc1.cjs';
|
|
@@ -41,6 +41,12 @@ type ACPClientConnectionFactory = (client: Client, options: {
|
|
|
41
41
|
env?: Record<string, string>;
|
|
42
42
|
}) => Promise<ACPClientConnectionHandle>;
|
|
43
43
|
|
|
44
|
+
interface ACPModeRequest {
|
|
45
|
+
roomId: string;
|
|
46
|
+
sessionId: string;
|
|
47
|
+
currentModeId: string;
|
|
48
|
+
modes: readonly SessionMode[];
|
|
49
|
+
}
|
|
44
50
|
interface ACPClientAdapterOptions {
|
|
45
51
|
command: string | string[];
|
|
46
52
|
cwd?: string;
|
|
@@ -54,6 +60,7 @@ interface ACPClientAdapterOptions {
|
|
|
54
60
|
connectionFactory?: ACPClientConnectionFactory;
|
|
55
61
|
resolvePermission?: (request: RequestPermissionRequest, signal: AbortSignal) => Promise<string | undefined>;
|
|
56
62
|
permissionTimeoutMs?: number;
|
|
63
|
+
resolveSessionMode?: (request: ACPModeRequest, signal: AbortSignal) => Promise<string | undefined>;
|
|
57
64
|
logger?: Logger;
|
|
58
65
|
}
|
|
59
66
|
declare class ACPClientAdapter extends SimpleAdapter<ACPClientSessionState, AdapterToolsProtocol> {
|
|
@@ -73,6 +80,7 @@ declare class ACPClientAdapter extends SimpleAdapter<ACPClientSessionState, Adap
|
|
|
73
80
|
private readonly bootstrappedSessions;
|
|
74
81
|
private readonly pendingPermissions;
|
|
75
82
|
private readonly resolvePermission?;
|
|
83
|
+
private readonly resolveSessionMode?;
|
|
76
84
|
private readonly permissionTimeoutMs;
|
|
77
85
|
private readonly logger;
|
|
78
86
|
private backend;
|
|
@@ -86,7 +94,7 @@ declare class ACPClientAdapter extends SimpleAdapter<ACPClientSessionState, Adap
|
|
|
86
94
|
private spawnPromise;
|
|
87
95
|
constructor(options: ACPClientAdapterOptions);
|
|
88
96
|
onStarted(agentName: string, agentDescription: string): Promise<void>;
|
|
89
|
-
onMessage(message: PlatformMessage, tools: AdapterToolsProtocol, history: ACPClientSessionState,
|
|
97
|
+
onMessage(message: PlatformMessage, tools: AdapterToolsProtocol, history: ACPClientSessionState, participantsMessage: string | null, contactsMessage: string | null, context: {
|
|
90
98
|
isSessionBootstrap: boolean;
|
|
91
99
|
roomId: string;
|
|
92
100
|
}): Promise<void>;
|
|
@@ -97,6 +105,8 @@ declare class ACPClientAdapter extends SimpleAdapter<ACPClientSessionState, Adap
|
|
|
97
105
|
private ensureConnection;
|
|
98
106
|
private spawnConnection;
|
|
99
107
|
private getOrCreateSession;
|
|
108
|
+
private configureSessionMode;
|
|
109
|
+
private resolveSessionModeManually;
|
|
100
110
|
private tryRestoreSession;
|
|
101
111
|
private buildSessionMcpServers;
|
|
102
112
|
private getOrCreateBackend;
|
|
@@ -104,6 +114,7 @@ declare class ACPClientAdapter extends SimpleAdapter<ACPClientSessionState, Adap
|
|
|
104
114
|
private buildSystemContext;
|
|
105
115
|
private handlePermissionRequest;
|
|
106
116
|
private toResponse;
|
|
117
|
+
private safeWarn;
|
|
107
118
|
private resolveManually;
|
|
108
119
|
private trackPending;
|
|
109
120
|
private untrackPending;
|