@band-ai/sdk 0.4.0 → 0.4.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/README.md +1 -1
- package/dist/{CopilotACPAdapter-BCpbHFB0.d.ts → CopilotACPAdapter-Bj6NRdqd.d.ts} +86 -2
- package/dist/{CopilotACPAdapter-D4VWg8lJ.d.cts → CopilotACPAdapter-HRvat7CP.d.cts} +86 -2
- package/dist/adapters.cjs +290 -53
- package/dist/adapters.d.cts +1 -1
- package/dist/adapters.d.ts +1 -1
- package/dist/adapters.js +9 -1
- package/dist/{chunk-YF7K4UB3.js → chunk-KXLV645N.js} +286 -53
- package/dist/index.cjs +292 -53
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +10 -2
- package/package.json +8 -2
package/dist/index.cjs
CHANGED
|
@@ -1058,6 +1058,7 @@ __export(src_exports, {
|
|
|
1058
1058
|
A2AAdapter: () => A2AAdapter,
|
|
1059
1059
|
A2AGatewayAdapter: () => A2AGatewayAdapter,
|
|
1060
1060
|
ACPClientAdapter: () => ACPClientAdapter,
|
|
1061
|
+
AcpSessionConfigError: () => AcpSessionConfigError,
|
|
1061
1062
|
Agent: () => Agent,
|
|
1062
1063
|
AgentFailure: () => import_band_sdk_core13.AgentFailure,
|
|
1063
1064
|
AgentRuntime: () => AgentRuntime,
|
|
@@ -1073,6 +1074,7 @@ __export(src_exports, {
|
|
|
1073
1074
|
DEFAULT_OMP_ACP_COMMAND: () => DEFAULT_OMP_ACP_COMMAND,
|
|
1074
1075
|
DefaultPreprocessor: () => DefaultPreprocessor,
|
|
1075
1076
|
DeliveryFailedError: () => DeliveryFailedError,
|
|
1077
|
+
FAILURE_CODE_SESSION_CONFIG: () => FAILURE_CODE_SESSION_CONFIG,
|
|
1076
1078
|
FAILURE_EVENT_TYPE: () => FAILURE_EVENT_TYPE,
|
|
1077
1079
|
FAILURE_METADATA_KEY: () => FAILURE_METADATA_KEY,
|
|
1078
1080
|
GeminiAdapter: () => GeminiAdapter,
|
|
@@ -1082,6 +1084,7 @@ __export(src_exports, {
|
|
|
1082
1084
|
LettaAdapter: () => LettaAdapter,
|
|
1083
1085
|
MCP_SERVER_NAME: () => MCP_SERVER_NAME,
|
|
1084
1086
|
MCP_TOOL_PREFIX: () => MCP_TOOL_PREFIX,
|
|
1087
|
+
MISSING_CONFIG_OPTIONS_REASON: () => MISSING_CONFIG_OPTIONS_REASON,
|
|
1085
1088
|
OmpACPAdapter: () => OmpACPAdapter,
|
|
1086
1089
|
OpenAIAdapter: () => OpenAIAdapter,
|
|
1087
1090
|
OpencodeAdapter: () => OpencodeAdapter,
|
|
@@ -1094,6 +1097,7 @@ __export(src_exports, {
|
|
|
1094
1097
|
VercelAISDKAdapter: () => VercelAISDKAdapter,
|
|
1095
1098
|
WebSocketDisconnectError: () => WebSocketDisconnectError,
|
|
1096
1099
|
agentFailure: () => agentFailure,
|
|
1100
|
+
applySessionConfigSelections: () => applySessionConfigSelections,
|
|
1097
1101
|
deliverReply: () => deliverReply,
|
|
1098
1102
|
deriveDefaultRestUrl: () => deriveDefaultRestUrl,
|
|
1099
1103
|
isDirectExecution: () => isDirectExecution,
|
|
@@ -17103,6 +17107,151 @@ var ACPClientHistoryConverter = class {
|
|
|
17103
17107
|
|
|
17104
17108
|
// src/adapters/acp/ACPClientAdapter.ts
|
|
17105
17109
|
init_errors();
|
|
17110
|
+
|
|
17111
|
+
// src/adapters/acp/sessionConfigReconciliation.ts
|
|
17112
|
+
var FAILURE_CODE_SESSION_CONFIG = "session_config";
|
|
17113
|
+
var MISSING_CONFIG_OPTIONS_REASON = "missing_config_options";
|
|
17114
|
+
var AcpSessionConfigTimeoutError = class extends Error {
|
|
17115
|
+
};
|
|
17116
|
+
var AcpSessionConfigError = class extends Error {
|
|
17117
|
+
provider;
|
|
17118
|
+
sessionId;
|
|
17119
|
+
optionId;
|
|
17120
|
+
selectedValue;
|
|
17121
|
+
acpCode;
|
|
17122
|
+
detail;
|
|
17123
|
+
timedOut;
|
|
17124
|
+
constructor(input) {
|
|
17125
|
+
super(input.message, input.cause !== void 0 ? { cause: input.cause } : void 0);
|
|
17126
|
+
this.name = "AcpSessionConfigError";
|
|
17127
|
+
this.provider = input.provider;
|
|
17128
|
+
this.sessionId = input.sessionId;
|
|
17129
|
+
this.optionId = input.optionId;
|
|
17130
|
+
this.selectedValue = input.selectedValue;
|
|
17131
|
+
this.acpCode = input.acpCode;
|
|
17132
|
+
this.detail = input.detail;
|
|
17133
|
+
this.timedOut = input.timedOut ?? false;
|
|
17134
|
+
}
|
|
17135
|
+
toAgentFailure() {
|
|
17136
|
+
return agentFailure(
|
|
17137
|
+
this.provider,
|
|
17138
|
+
this.message,
|
|
17139
|
+
this.acpCode !== void 0 ? String(this.acpCode) : FAILURE_CODE_SESSION_CONFIG,
|
|
17140
|
+
{
|
|
17141
|
+
sessionId: this.sessionId,
|
|
17142
|
+
optionId: this.optionId,
|
|
17143
|
+
selectedValue: this.selectedValue,
|
|
17144
|
+
detail: this.detail
|
|
17145
|
+
}
|
|
17146
|
+
);
|
|
17147
|
+
}
|
|
17148
|
+
};
|
|
17149
|
+
async function applySessionConfigSelections(input) {
|
|
17150
|
+
let catalog = input.catalog;
|
|
17151
|
+
for (const { configId, value: selectedValue } of sessionConfigSelectionEntries(input.selections)) {
|
|
17152
|
+
if (selectedValue === void 0) {
|
|
17153
|
+
continue;
|
|
17154
|
+
}
|
|
17155
|
+
const option = catalog.find((entry) => entry?.id === configId);
|
|
17156
|
+
if (!option || !isSessionConfigSelect(option)) {
|
|
17157
|
+
throw new AcpSessionConfigError({
|
|
17158
|
+
provider: input.provider,
|
|
17159
|
+
sessionId: input.sessionId,
|
|
17160
|
+
optionId: configId,
|
|
17161
|
+
selectedValue,
|
|
17162
|
+
message: `Session config option "${configId}" is not available after prior selections.`
|
|
17163
|
+
});
|
|
17164
|
+
}
|
|
17165
|
+
if (selectedValue === option.currentValue) {
|
|
17166
|
+
continue;
|
|
17167
|
+
}
|
|
17168
|
+
const availableValues = flattenConfigSelectOptions(option.options).map((entry) => entry.value);
|
|
17169
|
+
if (!availableValues.includes(selectedValue)) {
|
|
17170
|
+
throw new AcpSessionConfigError({
|
|
17171
|
+
provider: input.provider,
|
|
17172
|
+
sessionId: input.sessionId,
|
|
17173
|
+
optionId: configId,
|
|
17174
|
+
selectedValue,
|
|
17175
|
+
message: `Session config value "${selectedValue}" is not advertised for option "${configId}".`,
|
|
17176
|
+
detail: { availableValues }
|
|
17177
|
+
});
|
|
17178
|
+
}
|
|
17179
|
+
const timeoutMessage = `setSessionConfigOption did not respond within ${input.timeoutMs}ms`;
|
|
17180
|
+
try {
|
|
17181
|
+
const response = await withTimeout(
|
|
17182
|
+
input.setOption({ sessionId: input.sessionId, configId, value: selectedValue }),
|
|
17183
|
+
input.timeoutMs,
|
|
17184
|
+
() => new AcpSessionConfigTimeoutError(timeoutMessage)
|
|
17185
|
+
);
|
|
17186
|
+
if (!Array.isArray(response?.configOptions)) {
|
|
17187
|
+
throw new AcpSessionConfigError({
|
|
17188
|
+
provider: input.provider,
|
|
17189
|
+
sessionId: input.sessionId,
|
|
17190
|
+
optionId: configId,
|
|
17191
|
+
selectedValue,
|
|
17192
|
+
message: `Session config option "${configId}" response did not include a refreshed catalog.`,
|
|
17193
|
+
detail: { reason: MISSING_CONFIG_OPTIONS_REASON }
|
|
17194
|
+
});
|
|
17195
|
+
}
|
|
17196
|
+
catalog = response.configOptions;
|
|
17197
|
+
} catch (error) {
|
|
17198
|
+
if (error instanceof AcpSessionConfigError) {
|
|
17199
|
+
throw error;
|
|
17200
|
+
}
|
|
17201
|
+
const acpError = asAcpJsonRpcError(error);
|
|
17202
|
+
throw new AcpSessionConfigError({
|
|
17203
|
+
provider: input.provider,
|
|
17204
|
+
sessionId: input.sessionId,
|
|
17205
|
+
optionId: configId,
|
|
17206
|
+
selectedValue,
|
|
17207
|
+
acpCode: acpError?.code,
|
|
17208
|
+
detail: acpError?.data,
|
|
17209
|
+
message: acpError?.message ?? asErrorMessage(error),
|
|
17210
|
+
cause: error,
|
|
17211
|
+
timedOut: error instanceof AcpSessionConfigTimeoutError
|
|
17212
|
+
});
|
|
17213
|
+
}
|
|
17214
|
+
}
|
|
17215
|
+
return { catalog };
|
|
17216
|
+
}
|
|
17217
|
+
function sessionConfigSelectionEntries(selections) {
|
|
17218
|
+
if (isOrderedSessionConfigSelections(selections)) {
|
|
17219
|
+
return selections;
|
|
17220
|
+
}
|
|
17221
|
+
return Object.keys(selections).map((configId) => ({ configId, value: selections[configId] }));
|
|
17222
|
+
}
|
|
17223
|
+
function isOrderedSessionConfigSelections(selections) {
|
|
17224
|
+
return Array.isArray(selections);
|
|
17225
|
+
}
|
|
17226
|
+
function isSessionConfigSelect(option) {
|
|
17227
|
+
return option?.type === "select";
|
|
17228
|
+
}
|
|
17229
|
+
function flattenConfigSelectOptions(options) {
|
|
17230
|
+
if (!Array.isArray(options)) {
|
|
17231
|
+
return [];
|
|
17232
|
+
}
|
|
17233
|
+
return options.flatMap((entry) => {
|
|
17234
|
+
if (!asOptionalRecord2(entry)) {
|
|
17235
|
+
return [];
|
|
17236
|
+
}
|
|
17237
|
+
if ("group" in entry) {
|
|
17238
|
+
return Array.isArray(entry.options) ? entry.options : [];
|
|
17239
|
+
}
|
|
17240
|
+
return [entry];
|
|
17241
|
+
});
|
|
17242
|
+
}
|
|
17243
|
+
function isAcpErrorResponse(error) {
|
|
17244
|
+
return typeof error === "object" && error !== null && typeof error.code === "number" && typeof error.message === "string";
|
|
17245
|
+
}
|
|
17246
|
+
function asAcpJsonRpcError(error) {
|
|
17247
|
+
if (isAcpErrorResponse(error)) {
|
|
17248
|
+
return error;
|
|
17249
|
+
}
|
|
17250
|
+
const nested = asOptionalRecord2(error)?.error;
|
|
17251
|
+
return isAcpErrorResponse(nested) ? nested : void 0;
|
|
17252
|
+
}
|
|
17253
|
+
|
|
17254
|
+
// src/adapters/acp/ACPClientAdapter.ts
|
|
17106
17255
|
init_chatEvents();
|
|
17107
17256
|
init_schemas();
|
|
17108
17257
|
|
|
@@ -17361,6 +17510,13 @@ var acpModule = new LazyAsyncValue({
|
|
|
17361
17510
|
});
|
|
17362
17511
|
|
|
17363
17512
|
// src/adapters/acp/ACPClientAdapter.ts
|
|
17513
|
+
function createConnectionRetirement() {
|
|
17514
|
+
let reject = () => void 0;
|
|
17515
|
+
const promise = new Promise((_resolve, rejectPromise) => {
|
|
17516
|
+
reject = rejectPromise;
|
|
17517
|
+
});
|
|
17518
|
+
return { promise, reject };
|
|
17519
|
+
}
|
|
17364
17520
|
var DEFAULT_PERMISSION_TIMEOUT_MS = 5 * 6e4;
|
|
17365
17521
|
var DEFAULT_TURN_TIMEOUT_MS = 60 * 6e4;
|
|
17366
17522
|
var SET_SESSION_CONFIG_TIMEOUT_MS = 1e4;
|
|
@@ -17414,9 +17570,11 @@ var ACPClientAdapter = class extends SimpleAdapter {
|
|
|
17414
17570
|
resolvePermission;
|
|
17415
17571
|
resolveSessionMode;
|
|
17416
17572
|
resolveSessionModel;
|
|
17573
|
+
resolveSessionConfig;
|
|
17417
17574
|
permissionTimeoutMs;
|
|
17418
17575
|
turnTimeoutMs;
|
|
17419
17576
|
logger;
|
|
17577
|
+
customSection;
|
|
17420
17578
|
backend = null;
|
|
17421
17579
|
backendPromise = null;
|
|
17422
17580
|
client = null;
|
|
@@ -17427,6 +17585,7 @@ var ACPClientAdapter = class extends SimpleAdapter {
|
|
|
17427
17585
|
started = false;
|
|
17428
17586
|
systemPrompt = "";
|
|
17429
17587
|
spawnPromise = null;
|
|
17588
|
+
connectionRetirements = /* @__PURE__ */ new WeakMap();
|
|
17430
17589
|
// Bumped by `stop()` and on every successful spawn install. Cleanup/timeout
|
|
17431
17590
|
// and permission maps key by this plus session id so a stale generation
|
|
17432
17591
|
// cannot alias a same-id session on a newer connection.
|
|
@@ -17451,12 +17610,14 @@ var ACPClientAdapter = class extends SimpleAdapter {
|
|
|
17451
17610
|
this.resolvePermission = options.resolvePermission;
|
|
17452
17611
|
this.resolveSessionMode = options.resolveSessionMode;
|
|
17453
17612
|
this.resolveSessionModel = options.resolveSessionModel;
|
|
17613
|
+
this.resolveSessionConfig = options.resolveSessionConfig;
|
|
17454
17614
|
this.logger = resolveLogger(options.logger);
|
|
17615
|
+
this.customSection = options.customSection;
|
|
17455
17616
|
this.permissionTimeoutMs = options.permissionTimeoutMs ?? DEFAULT_PERMISSION_TIMEOUT_MS;
|
|
17456
|
-
if ((this.resolvePermission || this.resolveSessionMode || this.resolveSessionModel) && (!Number.isFinite(this.permissionTimeoutMs) || this.permissionTimeoutMs <= 0)) {
|
|
17617
|
+
if ((this.resolvePermission || this.resolveSessionMode || this.resolveSessionModel || this.resolveSessionConfig) && (!Number.isFinite(this.permissionTimeoutMs) || this.permissionTimeoutMs <= 0)) {
|
|
17457
17618
|
throw new ValidationError(`permissionTimeoutMs must be a positive finite number, got ${options.permissionTimeoutMs}`);
|
|
17458
17619
|
}
|
|
17459
|
-
if (this.resolvePermission || this.resolveSessionMode || this.resolveSessionModel) {
|
|
17620
|
+
if (this.resolvePermission || this.resolveSessionMode || this.resolveSessionModel || this.resolveSessionConfig) {
|
|
17460
17621
|
assertWithinSetTimeoutBound(
|
|
17461
17622
|
`permissionTimeoutMs must be at most ${MAX_SETTIMEOUT_DELAY_MS}, got ${options.permissionTimeoutMs}`,
|
|
17462
17623
|
this.permissionTimeoutMs
|
|
@@ -17483,7 +17644,8 @@ var ACPClientAdapter = class extends SimpleAdapter {
|
|
|
17483
17644
|
this.systemPrompt = renderSystemPrompt({
|
|
17484
17645
|
agentName,
|
|
17485
17646
|
agentDescription,
|
|
17486
|
-
includeBaseInstructions: false
|
|
17647
|
+
includeBaseInstructions: false,
|
|
17648
|
+
customSection: this.customSection
|
|
17487
17649
|
});
|
|
17488
17650
|
await this.ensureConnection();
|
|
17489
17651
|
}
|
|
@@ -17516,13 +17678,17 @@ var ACPClientAdapter = class extends SimpleAdapter {
|
|
|
17516
17678
|
|
|
17517
17679
|
${messageWithContext}`;
|
|
17518
17680
|
this.bootstrappedSessions.add(sessionKey);
|
|
17519
|
-
const response = await withTimeout(
|
|
17520
|
-
|
|
17521
|
-
|
|
17522
|
-
|
|
17523
|
-
|
|
17524
|
-
|
|
17525
|
-
|
|
17681
|
+
const response = await withTimeout(
|
|
17682
|
+
this.raceAgainstConnectionRetirement(connection, connection.prompt({
|
|
17683
|
+
sessionId,
|
|
17684
|
+
prompt: [{
|
|
17685
|
+
type: "text",
|
|
17686
|
+
text: promptText
|
|
17687
|
+
}]
|
|
17688
|
+
})),
|
|
17689
|
+
this.turnTimeoutMs,
|
|
17690
|
+
() => new AcpTurnTimeoutError()
|
|
17691
|
+
);
|
|
17526
17692
|
await this.flushChunks({
|
|
17527
17693
|
client,
|
|
17528
17694
|
tools,
|
|
@@ -17563,12 +17729,17 @@ ${messageWithContext}`;
|
|
|
17563
17729
|
}
|
|
17564
17730
|
}
|
|
17565
17731
|
}
|
|
17566
|
-
const
|
|
17732
|
+
const configError = error instanceof AcpSessionConfigError ? error : void 0;
|
|
17733
|
+
const acpError = configError ? void 0 : asAcpJsonRpcError(error);
|
|
17567
17734
|
await reportTurnFailure(
|
|
17568
17735
|
tools,
|
|
17569
|
-
isTimeout ? agentFailure(this.provider, "ACP turn timed out.", FAILURE_CODE_TIMEOUT) : acpError ? agentFailure(this.provider, acpError.message, String(acpError.code), acpError.data) : agentFailure(this.provider, asErrorMessage(error)),
|
|
17736
|
+
isTimeout ? agentFailure(this.provider, "ACP turn timed out.", FAILURE_CODE_TIMEOUT) : configError ? configError.toAgentFailure() : acpError ? agentFailure(this.provider, acpError.message, String(acpError.code), acpError.data) : agentFailure(this.provider, asErrorMessage(error)),
|
|
17570
17737
|
this.logger,
|
|
17571
|
-
{
|
|
17738
|
+
{
|
|
17739
|
+
roomId: context.roomId,
|
|
17740
|
+
sessionId: configError?.sessionId ?? sessionId,
|
|
17741
|
+
...configError ? { optionId: configError.optionId, selectedValue: configError.selectedValue } : {}
|
|
17742
|
+
}
|
|
17572
17743
|
);
|
|
17573
17744
|
}
|
|
17574
17745
|
}
|
|
@@ -17587,17 +17758,12 @@ ${messageWithContext}`;
|
|
|
17587
17758
|
// would risk blocking this room's turn lock forever on the very process
|
|
17588
17759
|
// that just proved it can hang.
|
|
17589
17760
|
async abandonTimedOutTurn(connection, sessionId, generation) {
|
|
17590
|
-
|
|
17591
|
-
|
|
17592
|
-
|
|
17593
|
-
|
|
17594
|
-
|
|
17595
|
-
|
|
17596
|
-
}
|
|
17597
|
-
abandon(
|
|
17598
|
-
() => connection.cancel({ sessionId }),
|
|
17599
|
-
(error) => this.safeWarn("acp_client.cancel_failed", { sessionId, error: asErrorMessage(error) })
|
|
17600
|
-
);
|
|
17761
|
+
this.evictAbandonedSession(sessionId, generation, connection, () => {
|
|
17762
|
+
const owner = [...this.roomToSession.entries()].find(([, value]) => value.sessionId === sessionId && value.generation === generation);
|
|
17763
|
+
if (owner) {
|
|
17764
|
+
this.unlinkOwner(owner[0], owner[1]);
|
|
17765
|
+
}
|
|
17766
|
+
});
|
|
17601
17767
|
}
|
|
17602
17768
|
// A per-room async mutex: `fn` for a given `roomId` never overlaps another
|
|
17603
17769
|
// call for that same room, while different rooms stay fully concurrent.
|
|
@@ -17723,6 +17889,11 @@ ${messageWithContext}`;
|
|
|
17723
17889
|
void connection.closed.then(() => reject(new Error("ACP connection closed while a session operation was still in flight")));
|
|
17724
17890
|
return Promise.race([operation, closedRejection]);
|
|
17725
17891
|
}
|
|
17892
|
+
raceAgainstConnectionRetirement(connection, operation) {
|
|
17893
|
+
const retirement = this.connectionRetirements.get(connection) ?? createConnectionRetirement();
|
|
17894
|
+
this.connectionRetirements.set(connection, retirement);
|
|
17895
|
+
return Promise.race([operation, retirement.promise]);
|
|
17896
|
+
}
|
|
17726
17897
|
unlinkRoom(roomId) {
|
|
17727
17898
|
const owner = this.roomToSession.get(roomId);
|
|
17728
17899
|
if (owner) {
|
|
@@ -17867,7 +18038,10 @@ ${messageWithContext}`;
|
|
|
17867
18038
|
this.activeSessions.add(restoredKey);
|
|
17868
18039
|
this.bootstrappedSessions.add(restoredKey);
|
|
17869
18040
|
await this.configureSessionMode(roomId, existingSessionId, restored.modes, connection);
|
|
17870
|
-
await this.
|
|
18041
|
+
await this.configureSessionConfig(roomId, existingSessionId, restored.configOptions, connection, connectionGeneration, client);
|
|
18042
|
+
if (!this.resolveSessionConfig) {
|
|
18043
|
+
await this.configureSessionModel(roomId, existingSessionId, restored.configOptions, connection);
|
|
18044
|
+
}
|
|
17871
18045
|
return existingSessionId;
|
|
17872
18046
|
}
|
|
17873
18047
|
}
|
|
@@ -17878,9 +18052,97 @@ ${messageWithContext}`;
|
|
|
17878
18052
|
this.linkOrAbandon(roomId, created.sessionId, generation, connectionGeneration, client);
|
|
17879
18053
|
this.activeSessions.add(this.sessionKey(connectionGeneration, created.sessionId));
|
|
17880
18054
|
await this.configureSessionMode(roomId, created.sessionId, created.modes, connection);
|
|
17881
|
-
await this.
|
|
18055
|
+
await this.configureSessionConfig(roomId, created.sessionId, created.configOptions, connection, connectionGeneration, client);
|
|
18056
|
+
if (!this.resolveSessionConfig) {
|
|
18057
|
+
await this.configureSessionModel(roomId, created.sessionId, created.configOptions, connection);
|
|
18058
|
+
}
|
|
17882
18059
|
return created.sessionId;
|
|
17883
18060
|
}
|
|
18061
|
+
async configureSessionConfig(roomId, sessionId, configOptions, connection, connectionGeneration, client) {
|
|
18062
|
+
if (!this.resolveSessionConfig || !Array.isArray(configOptions) || configOptions.length === 0) {
|
|
18063
|
+
return;
|
|
18064
|
+
}
|
|
18065
|
+
const advertisedOptions = configOptions;
|
|
18066
|
+
const selections = await this.resolveManualSelection(
|
|
18067
|
+
"resolveSessionConfig",
|
|
18068
|
+
(signal) => this.resolveSessionConfig({ roomId, sessionId, configOptions: advertisedOptions }, signal),
|
|
18069
|
+
connection.signal
|
|
18070
|
+
);
|
|
18071
|
+
if (!selections) {
|
|
18072
|
+
return;
|
|
18073
|
+
}
|
|
18074
|
+
try {
|
|
18075
|
+
await applySessionConfigSelections({
|
|
18076
|
+
provider: this.provider,
|
|
18077
|
+
sessionId,
|
|
18078
|
+
catalog: advertisedOptions,
|
|
18079
|
+
selections,
|
|
18080
|
+
setOption: (params) => connection.setSessionConfigOption(params),
|
|
18081
|
+
timeoutMs: SET_SESSION_CONFIG_TIMEOUT_MS
|
|
18082
|
+
});
|
|
18083
|
+
} catch (error) {
|
|
18084
|
+
this.abandonFailedConfigSession(
|
|
18085
|
+
roomId,
|
|
18086
|
+
sessionId,
|
|
18087
|
+
connectionGeneration,
|
|
18088
|
+
client,
|
|
18089
|
+
connection,
|
|
18090
|
+
error instanceof AcpSessionConfigError && error.timedOut
|
|
18091
|
+
);
|
|
18092
|
+
throw error;
|
|
18093
|
+
}
|
|
18094
|
+
}
|
|
18095
|
+
// A config failure mid-establish must not leave a half-applied session
|
|
18096
|
+
// active for the room: the next turn needs a fresh `newSession` catalog.
|
|
18097
|
+
abandonFailedConfigSession(roomId, sessionId, connectionGeneration, client, connection, retireConnection) {
|
|
18098
|
+
const key = this.sessionKey(connectionGeneration, sessionId);
|
|
18099
|
+
this.bootstrappedSessions.delete(key);
|
|
18100
|
+
client.resetChunks(sessionId);
|
|
18101
|
+
this.evictAbandonedSession(sessionId, connectionGeneration, connection, () => {
|
|
18102
|
+
const owner = this.roomToSession.get(roomId);
|
|
18103
|
+
if (owner && owner.sessionId === sessionId && owner.generation === connectionGeneration) {
|
|
18104
|
+
this.unlinkOwner(roomId, owner);
|
|
18105
|
+
}
|
|
18106
|
+
});
|
|
18107
|
+
if (retireConnection) {
|
|
18108
|
+
this.retireConnection(connection, connectionGeneration);
|
|
18109
|
+
}
|
|
18110
|
+
}
|
|
18111
|
+
// Common half of timeout and config-failure abandon: mark the session
|
|
18112
|
+
// unusable for restore, unlink ownership, and best-effort cancel.
|
|
18113
|
+
evictAbandonedSession(sessionId, connectionGeneration, connection, unlink) {
|
|
18114
|
+
const key = this.sessionKey(connectionGeneration, sessionId);
|
|
18115
|
+
const wasActive = this.activeSessions.delete(key);
|
|
18116
|
+
if (wasActive) {
|
|
18117
|
+
this.abandonedSessions.add(key);
|
|
18118
|
+
}
|
|
18119
|
+
unlink();
|
|
18120
|
+
abandon(
|
|
18121
|
+
() => connection.cancel({ sessionId }),
|
|
18122
|
+
(error) => this.safeWarn("acp_client.cancel_failed", { sessionId, error: asErrorMessage(error) })
|
|
18123
|
+
);
|
|
18124
|
+
}
|
|
18125
|
+
// A timed-out config RPC means this transport has already failed to answer
|
|
18126
|
+
// one request. Retire it so the next turn cannot wait forever on another.
|
|
18127
|
+
retireConnection(connection, generation) {
|
|
18128
|
+
if (this.connection !== connection || this.connectionGeneration !== generation) {
|
|
18129
|
+
return;
|
|
18130
|
+
}
|
|
18131
|
+
const handle = this.connectionHandle;
|
|
18132
|
+
this.connectionGeneration++;
|
|
18133
|
+
this.connection = null;
|
|
18134
|
+
this.connectionHandle = null;
|
|
18135
|
+
this.connectionState = null;
|
|
18136
|
+
this.client = null;
|
|
18137
|
+
this.pruneConnectionGeneration(generation);
|
|
18138
|
+
this.connectionRetirements.get(connection)?.reject(new Error("ACP connection retired after a config timeout"));
|
|
18139
|
+
if (handle) {
|
|
18140
|
+
abandon(
|
|
18141
|
+
() => handle.stop(),
|
|
18142
|
+
(error) => this.safeWarn("acp_client.handle_stop_after_config_timeout", { error: asErrorMessage(error) })
|
|
18143
|
+
);
|
|
18144
|
+
}
|
|
18145
|
+
}
|
|
17884
18146
|
// The single gate an establishment must pass before it's allowed to claim
|
|
17885
18147
|
// the room: it must still be the room's current generation (not
|
|
17886
18148
|
// superseded by a teardown or a fresher establishment while this one was
|
|
@@ -18492,39 +18754,12 @@ async function createTcpConnection(client, endpoint, signal) {
|
|
|
18492
18754
|
};
|
|
18493
18755
|
}
|
|
18494
18756
|
var MODEL_CONFIG_OPTION_KEY = "model";
|
|
18495
|
-
function isSessionConfigSelect(option) {
|
|
18496
|
-
return option?.type === "select";
|
|
18497
|
-
}
|
|
18498
18757
|
function isModelConfigOption(option) {
|
|
18499
18758
|
return isSessionConfigSelect(option) && option.category === MODEL_CONFIG_OPTION_KEY;
|
|
18500
18759
|
}
|
|
18501
18760
|
function isModelConfigOptionById(option) {
|
|
18502
18761
|
return isSessionConfigSelect(option) && option.id === MODEL_CONFIG_OPTION_KEY;
|
|
18503
18762
|
}
|
|
18504
|
-
function flattenConfigSelectOptions(options) {
|
|
18505
|
-
if (!Array.isArray(options)) {
|
|
18506
|
-
return [];
|
|
18507
|
-
}
|
|
18508
|
-
return options.flatMap((entry) => {
|
|
18509
|
-
if (!asOptionalRecord2(entry)) {
|
|
18510
|
-
return [];
|
|
18511
|
-
}
|
|
18512
|
-
if ("group" in entry) {
|
|
18513
|
-
return Array.isArray(entry.options) ? entry.options : [];
|
|
18514
|
-
}
|
|
18515
|
-
return [entry];
|
|
18516
|
-
});
|
|
18517
|
-
}
|
|
18518
|
-
function isAcpErrorResponse(error) {
|
|
18519
|
-
return typeof error === "object" && error !== null && typeof error.code === "number" && typeof error.message === "string";
|
|
18520
|
-
}
|
|
18521
|
-
function asAcpJsonRpcError(error) {
|
|
18522
|
-
if (isAcpErrorResponse(error)) {
|
|
18523
|
-
return error;
|
|
18524
|
-
}
|
|
18525
|
-
const nested = asOptionalRecord2(error)?.error;
|
|
18526
|
-
return isAcpErrorResponse(nested) ? nested : void 0;
|
|
18527
|
-
}
|
|
18528
18763
|
|
|
18529
18764
|
// src/adapters/acp/ACPServer.ts
|
|
18530
18765
|
var import_node_stream2 = require("stream");
|
|
@@ -18581,6 +18816,7 @@ init_schemas();
|
|
|
18581
18816
|
A2AAdapter,
|
|
18582
18817
|
A2AGatewayAdapter,
|
|
18583
18818
|
ACPClientAdapter,
|
|
18819
|
+
AcpSessionConfigError,
|
|
18584
18820
|
Agent,
|
|
18585
18821
|
AgentFailure,
|
|
18586
18822
|
AgentRuntime,
|
|
@@ -18596,6 +18832,7 @@ init_schemas();
|
|
|
18596
18832
|
DEFAULT_OMP_ACP_COMMAND,
|
|
18597
18833
|
DefaultPreprocessor,
|
|
18598
18834
|
DeliveryFailedError,
|
|
18835
|
+
FAILURE_CODE_SESSION_CONFIG,
|
|
18599
18836
|
FAILURE_EVENT_TYPE,
|
|
18600
18837
|
FAILURE_METADATA_KEY,
|
|
18601
18838
|
GeminiAdapter,
|
|
@@ -18605,6 +18842,7 @@ init_schemas();
|
|
|
18605
18842
|
LettaAdapter,
|
|
18606
18843
|
MCP_SERVER_NAME,
|
|
18607
18844
|
MCP_TOOL_PREFIX,
|
|
18845
|
+
MISSING_CONFIG_OPTIONS_REASON,
|
|
18608
18846
|
OmpACPAdapter,
|
|
18609
18847
|
OpenAIAdapter,
|
|
18610
18848
|
OpencodeAdapter,
|
|
@@ -18617,6 +18855,7 @@ init_schemas();
|
|
|
18617
18855
|
VercelAISDKAdapter,
|
|
18618
18856
|
WebSocketDisconnectError,
|
|
18619
18857
|
agentFailure,
|
|
18858
|
+
applySessionConfigSelections,
|
|
18620
18859
|
deliverReply,
|
|
18621
18860
|
deriveDefaultRestUrl,
|
|
18622
18861
|
isDirectExecution,
|
package/dist/index.d.cts
CHANGED
|
@@ -9,7 +9,7 @@ import { P as PlatformMessage } from './types-DtcOLALn.cjs';
|
|
|
9
9
|
export { A as AgentConfig, a as AgentInput, C as ContactEvent, b as ContactEventCallback, c as ContactEventConfig, d as ContactEventStrategy, e as ConversationContext, H as HistoryProvider, M as MessageHandler, f as PlatformEvent, R as ReconnectedEvent, S as SessionConfig } from './types-DtcOLALn.cjs';
|
|
10
10
|
export { W as WebSocketConflictPolicy, a as WebSocketDisconnectError, b as WebSocketDisconnectReason } from './disconnectReason-Cctmg1SN.cjs';
|
|
11
11
|
export { C as CustomToolDef } from './customTools-Bfecd0mJ.cjs';
|
|
12
|
-
export { A as A2AAdapter, a as A2AAdapterOptions, b as A2AGatewayAdapter, c as ACPClientAdapter, d as ACPClientAdapterBaseOptions, e as ACPClientAdapterOptions, f as ACPClientStdioOptions, g as ACPClientTcpOptions, h as
|
|
12
|
+
export { A as A2AAdapter, a as A2AAdapterOptions, b as A2AGatewayAdapter, c as ACPClientAdapter, d as ACPClientAdapterBaseOptions, e as ACPClientAdapterOptions, f as ACPClientStdioOptions, g as ACPClientTcpOptions, h as ACPConfigRequest, i as ACPConfigSelections, j as AcpSessionConfigError, k as AnthropicAdapter, l as AnthropicAdapterOptions, C as CODEX_REASONING_EFFORTS, m as CODEX_REASONING_SUMMARIES, n as CODEX_WEB_SEARCH_MODES, o as ClaudePermissionMode, p as ClaudeSDKAdapter, q as ClaudeSDKAdapterOptions, r as CodexAdapter, s as CodexAdapterConfig, t as CodexApprovalPolicy, u as CodexReasoningEffort, v as CodexReasoningSummary, w as CodexSandboxMode, x as CodexWebSearchMode, y as CopilotACPAdapter, z as CopilotACPAdapterOptions, B as CopilotACPStdioOptions, D as CopilotACPTcpOptions, E as DEFAULT_COPILOT_ACP_COMMAND, F as DEFAULT_OMP_ACP_COMMAND, G as FAILURE_CODE_SESSION_CONFIG, H as GeminiAdapter, I as GeminiAdapterOptions, J as GenericAdapter, K as GenericAdapterHandler, L as GoogleADKAdapter, M as GoogleADKAdapterOptions, N as LangGraphAdapter, O as LangGraphAdapterOptions, P as LangGraphGraph, Q as LettaAdapter, R as LettaAdapterOptions, S as MISSING_CONFIG_OPTIONS_REASON, T as OmpACPAdapter, U as OmpACPAdapterOptions, V as OpenAIAdapter, W as OpenAIAdapterOptions, X as OpencodeAdapter, Y as OpencodeAdapterConfig, Z as OpencodeApprovalMode, _ as OpencodeApprovalReply, $ as OpencodeQuestionMode, a0 as ParlantAdapter, a1 as ParlantAdapterOptions, a2 as ToolCallingModel, a3 as VercelAISDKAdapter, a4 as VercelAISDKAdapterOptions, a5 as applySessionConfigSelections } from './CopilotACPAdapter-HRvat7CP.cjs';
|
|
13
13
|
export { S as SimpleAdapter } from './simpleAdapter-D75rcz9n.cjs';
|
|
14
14
|
export { A as A2AAuth, a as A2AGatewayAdapterOptions } from './acp-client-D-I_5lK-.cjs';
|
|
15
15
|
export { AgentFailure } from '@band-ai/band-sdk-core';
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { P as PlatformMessage } from './types-CKU1N0SK.js';
|
|
|
9
9
|
export { A as AgentConfig, a as AgentInput, C as ContactEvent, b as ContactEventCallback, c as ContactEventConfig, d as ContactEventStrategy, e as ConversationContext, H as HistoryProvider, M as MessageHandler, f as PlatformEvent, R as ReconnectedEvent, S as SessionConfig } from './types-CKU1N0SK.js';
|
|
10
10
|
export { W as WebSocketConflictPolicy, a as WebSocketDisconnectError, b as WebSocketDisconnectReason } from './disconnectReason-Cctmg1SN.js';
|
|
11
11
|
export { C as CustomToolDef } from './customTools-Bfecd0mJ.js';
|
|
12
|
-
export { A as A2AAdapter, a as A2AAdapterOptions, b as A2AGatewayAdapter, c as ACPClientAdapter, d as ACPClientAdapterBaseOptions, e as ACPClientAdapterOptions, f as ACPClientStdioOptions, g as ACPClientTcpOptions, h as
|
|
12
|
+
export { A as A2AAdapter, a as A2AAdapterOptions, b as A2AGatewayAdapter, c as ACPClientAdapter, d as ACPClientAdapterBaseOptions, e as ACPClientAdapterOptions, f as ACPClientStdioOptions, g as ACPClientTcpOptions, h as ACPConfigRequest, i as ACPConfigSelections, j as AcpSessionConfigError, k as AnthropicAdapter, l as AnthropicAdapterOptions, C as CODEX_REASONING_EFFORTS, m as CODEX_REASONING_SUMMARIES, n as CODEX_WEB_SEARCH_MODES, o as ClaudePermissionMode, p as ClaudeSDKAdapter, q as ClaudeSDKAdapterOptions, r as CodexAdapter, s as CodexAdapterConfig, t as CodexApprovalPolicy, u as CodexReasoningEffort, v as CodexReasoningSummary, w as CodexSandboxMode, x as CodexWebSearchMode, y as CopilotACPAdapter, z as CopilotACPAdapterOptions, B as CopilotACPStdioOptions, D as CopilotACPTcpOptions, E as DEFAULT_COPILOT_ACP_COMMAND, F as DEFAULT_OMP_ACP_COMMAND, G as FAILURE_CODE_SESSION_CONFIG, H as GeminiAdapter, I as GeminiAdapterOptions, J as GenericAdapter, K as GenericAdapterHandler, L as GoogleADKAdapter, M as GoogleADKAdapterOptions, N as LangGraphAdapter, O as LangGraphAdapterOptions, P as LangGraphGraph, Q as LettaAdapter, R as LettaAdapterOptions, S as MISSING_CONFIG_OPTIONS_REASON, T as OmpACPAdapter, U as OmpACPAdapterOptions, V as OpenAIAdapter, W as OpenAIAdapterOptions, X as OpencodeAdapter, Y as OpencodeAdapterConfig, Z as OpencodeApprovalMode, _ as OpencodeApprovalReply, $ as OpencodeQuestionMode, a0 as ParlantAdapter, a1 as ParlantAdapterOptions, a2 as ToolCallingModel, a3 as VercelAISDKAdapter, a4 as VercelAISDKAdapterOptions, a5 as applySessionConfigSelections } from './CopilotACPAdapter-Bj6NRdqd.js';
|
|
13
13
|
export { S as SimpleAdapter } from './simpleAdapter-eLvsAQNo.js';
|
|
14
14
|
export { A as A2AAuth, a as A2AGatewayAdapterOptions } from './acp-client-DUXyczlF.js';
|
|
15
15
|
export { AgentFailure } from '@band-ai/band-sdk-core';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ACPClientAdapter,
|
|
3
|
+
AcpSessionConfigError,
|
|
3
4
|
AnthropicAdapter,
|
|
4
5
|
CODEX_REASONING_EFFORTS,
|
|
5
6
|
CODEX_REASONING_SUMMARIES,
|
|
@@ -9,16 +10,19 @@ import {
|
|
|
9
10
|
CopilotACPAdapter,
|
|
10
11
|
DEFAULT_COPILOT_ACP_COMMAND,
|
|
11
12
|
DEFAULT_OMP_ACP_COMMAND,
|
|
13
|
+
FAILURE_CODE_SESSION_CONFIG,
|
|
12
14
|
GeminiAdapter,
|
|
13
15
|
GenericAdapter,
|
|
14
16
|
GoogleADKAdapter,
|
|
15
17
|
LangGraphAdapter,
|
|
16
18
|
LettaAdapter,
|
|
19
|
+
MISSING_CONFIG_OPTIONS_REASON,
|
|
17
20
|
OmpACPAdapter,
|
|
18
21
|
OpenAIAdapter,
|
|
19
22
|
OpencodeAdapter,
|
|
20
|
-
VercelAISDKAdapter
|
|
21
|
-
|
|
23
|
+
VercelAISDKAdapter,
|
|
24
|
+
applySessionConfigSelections
|
|
25
|
+
} from "./chunk-KXLV645N.js";
|
|
22
26
|
import "./chunk-UL3Y5C4J.js";
|
|
23
27
|
import "./chunk-JDW5WSGF.js";
|
|
24
28
|
import {
|
|
@@ -267,6 +271,7 @@ export {
|
|
|
267
271
|
A2AAdapter,
|
|
268
272
|
A2AGatewayAdapter,
|
|
269
273
|
ACPClientAdapter,
|
|
274
|
+
AcpSessionConfigError,
|
|
270
275
|
Agent,
|
|
271
276
|
AgentFailure,
|
|
272
277
|
AgentRuntime,
|
|
@@ -282,6 +287,7 @@ export {
|
|
|
282
287
|
DEFAULT_OMP_ACP_COMMAND,
|
|
283
288
|
DefaultPreprocessor,
|
|
284
289
|
DeliveryFailedError,
|
|
290
|
+
FAILURE_CODE_SESSION_CONFIG,
|
|
285
291
|
FAILURE_EVENT_TYPE,
|
|
286
292
|
FAILURE_METADATA_KEY,
|
|
287
293
|
GeminiAdapter,
|
|
@@ -291,6 +297,7 @@ export {
|
|
|
291
297
|
LettaAdapter,
|
|
292
298
|
MCP_SERVER_NAME,
|
|
293
299
|
MCP_TOOL_PREFIX,
|
|
300
|
+
MISSING_CONFIG_OPTIONS_REASON,
|
|
294
301
|
OmpACPAdapter,
|
|
295
302
|
OpenAIAdapter,
|
|
296
303
|
OpencodeAdapter,
|
|
@@ -303,6 +310,7 @@ export {
|
|
|
303
310
|
VercelAISDKAdapter,
|
|
304
311
|
WebSocketDisconnectError,
|
|
305
312
|
agentFailure,
|
|
313
|
+
applySessionConfigSelections,
|
|
306
314
|
deliverReply,
|
|
307
315
|
deriveDefaultRestUrl,
|
|
308
316
|
isDirectExecution,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@band-ai/sdk",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "Band TypeScript SDK core runtime",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -82,7 +82,13 @@
|
|
|
82
82
|
"lint": "eslint .",
|
|
83
83
|
"clean": "rm -rf dist",
|
|
84
84
|
"dev:linear": "tsx --env-file-if-exists=.env.local examples/linear-band/linear-band-bridge-server.ts",
|
|
85
|
-
"start:linear": "tsx examples/linear-band/linear-band-bridge-server.ts"
|
|
85
|
+
"start:linear": "tsx examples/linear-band/linear-band-bridge-server.ts",
|
|
86
|
+
"examples:config": "python3 scripts/generate-agent-config-for-examples.py",
|
|
87
|
+
"examples:a2a-stub": "node scripts/a2a-stub-server.mjs",
|
|
88
|
+
"examples:discover": "node scripts/examples-discover.mjs",
|
|
89
|
+
"examples:smoke": "node scripts/examples-smoke-startup.mjs --env-file ../../.env.test",
|
|
90
|
+
"examples:run-plan": "tsx --env-file ../../.env.test scripts/example-runner.ts",
|
|
91
|
+
"examples:tom-jerry": "tsx --env-file ../../.env.test scripts/tom-jerry-cross-room.ts"
|
|
86
92
|
},
|
|
87
93
|
"engines": {
|
|
88
94
|
"node": ">=22.12"
|