@crazyhappyone/dsh-tui 0.1.0-alpha.53 → 0.1.0-alpha.55
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/CHANGELOG.md +29 -0
- package/README.md +15 -17
- package/README.zh.md +15 -17
- package/dist/index.js +1885 -1646
- package/dist/schedule.js +121 -1179
- package/dist/zen-proxy.js +1 -1
- package/package.json +48 -40
- package/src/launcher.js +2 -2
package/dist/schedule.js
CHANGED
|
@@ -3543,6 +3543,62 @@ function scopeTarget(base, key) {
|
|
|
3543
3543
|
return carrier;
|
|
3544
3544
|
}
|
|
3545
3545
|
|
|
3546
|
+
// packages/core/agent/src/consumed-work.ts
|
|
3547
|
+
function accountsForClaim(reason) {
|
|
3548
|
+
switch (reason.kind) {
|
|
3549
|
+
case "completed":
|
|
3550
|
+
return false;
|
|
3551
|
+
case "blocked":
|
|
3552
|
+
case "aborted":
|
|
3553
|
+
case "interrupted":
|
|
3554
|
+
case "error":
|
|
3555
|
+
return true;
|
|
3556
|
+
/* v8 ignore next 5 -- unreachable: `max-tokens` requires a step and short-circuits
|
|
3557
|
+
* before this call; `forked` exists only in constructor seed history, while production
|
|
3558
|
+
* callers fold an operation-owned suffix. `TurnEndReasonMap` is merge-extensible, so a
|
|
3559
|
+
* backend-added variant cannot be listed; an unnameable ending over consumed input must
|
|
3560
|
+
* not read as success. */
|
|
3561
|
+
default:
|
|
3562
|
+
return true;
|
|
3563
|
+
}
|
|
3564
|
+
}
|
|
3565
|
+
function foldConsumedWork(events) {
|
|
3566
|
+
const stepped = /* @__PURE__ */ new Set();
|
|
3567
|
+
const claimed = /* @__PURE__ */ new Set();
|
|
3568
|
+
let open;
|
|
3569
|
+
let end;
|
|
3570
|
+
let droppedUnrun = false;
|
|
3571
|
+
for (const event of events) {
|
|
3572
|
+
switch (event.type) {
|
|
3573
|
+
case "turn/start":
|
|
3574
|
+
open = event.data.turn;
|
|
3575
|
+
break;
|
|
3576
|
+
case "step/start":
|
|
3577
|
+
stepped.add(event.data.turn);
|
|
3578
|
+
break;
|
|
3579
|
+
case "agent/inbox/spliced": {
|
|
3580
|
+
const { removedCount, outcome, inserted } = event.data;
|
|
3581
|
+
if (removedCount === void 0) break;
|
|
3582
|
+
if (outcome === "canceled") droppedUnrun ||= inserted.length === 0;
|
|
3583
|
+
else if (open !== void 0) claimed.add(open);
|
|
3584
|
+
break;
|
|
3585
|
+
}
|
|
3586
|
+
case "turn/end": {
|
|
3587
|
+
const { turn, reason } = event.data;
|
|
3588
|
+
open = void 0;
|
|
3589
|
+
if (stepped.delete(turn) || claimed.delete(turn) && accountsForClaim(reason)) {
|
|
3590
|
+
end = event;
|
|
3591
|
+
droppedUnrun = false;
|
|
3592
|
+
}
|
|
3593
|
+
break;
|
|
3594
|
+
}
|
|
3595
|
+
default:
|
|
3596
|
+
break;
|
|
3597
|
+
}
|
|
3598
|
+
}
|
|
3599
|
+
return { ...end === void 0 ? {} : { end }, droppedUnrun };
|
|
3600
|
+
}
|
|
3601
|
+
|
|
3546
3602
|
// packages/typert/protocol/src/remote-error.ts
|
|
3547
3603
|
var RemoteError = class extends Error {
|
|
3548
3604
|
/**
|
|
@@ -3562,6 +3618,12 @@ var RemoteError = class extends Error {
|
|
|
3562
3618
|
/** Structural marker: cross-realm/bundle identification never uses instanceof. */
|
|
3563
3619
|
isDSHRemoteError = true;
|
|
3564
3620
|
};
|
|
3621
|
+
function remoteErrorOf(value) {
|
|
3622
|
+
if (typeof value === "object" && value !== null && value.isDSHRemoteError === true && typeof value.code === "string") {
|
|
3623
|
+
return value;
|
|
3624
|
+
}
|
|
3625
|
+
return void 0;
|
|
3626
|
+
}
|
|
3565
3627
|
|
|
3566
3628
|
// packages/typert/protocol/src/principal.ts
|
|
3567
3629
|
function principalOf(invocation) {
|
|
@@ -3653,9 +3715,9 @@ function readRemoteMethodDescriptor(prototype) {
|
|
|
3653
3715
|
if (descriptor === null || typeof descriptor !== "object") {
|
|
3654
3716
|
throw new TypeError("typert-protocol: Remote method descriptor must be an object");
|
|
3655
3717
|
}
|
|
3656
|
-
const
|
|
3657
|
-
if (
|
|
3658
|
-
throw new TypeError(`typert-protocol: unsupported Remote method descriptor version ${String(
|
|
3718
|
+
const version3 = Reflect.get(descriptor, "version");
|
|
3719
|
+
if (version3 !== 1) {
|
|
3720
|
+
throw new TypeError(`typert-protocol: unsupported Remote method descriptor version ${String(version3)}`);
|
|
3659
3721
|
}
|
|
3660
3722
|
const methods = Reflect.get(descriptor, "methods");
|
|
3661
3723
|
if (!Array.isArray(methods)) {
|
|
@@ -6315,7 +6377,7 @@ function detachDirectoryEntry(entry) {
|
|
|
6315
6377
|
};
|
|
6316
6378
|
}
|
|
6317
6379
|
|
|
6318
|
-
// packages/core/agent/
|
|
6380
|
+
// packages/core/agent/src/model-selection.ts
|
|
6319
6381
|
function sameRoute(left, right) {
|
|
6320
6382
|
return left.provider === right.provider && left.model === right.model;
|
|
6321
6383
|
}
|
|
@@ -6352,30 +6414,34 @@ function installModelSelection(agentCtx, selection) {
|
|
|
6352
6414
|
}
|
|
6353
6415
|
};
|
|
6354
6416
|
});
|
|
6355
|
-
const disposeRequest = agentCtx.on(
|
|
6356
|
-
|
|
6357
|
-
|
|
6358
|
-
|
|
6359
|
-
|
|
6360
|
-
|
|
6361
|
-
...withoutInheritedEffort
|
|
6362
|
-
|
|
6363
|
-
|
|
6364
|
-
|
|
6365
|
-
|
|
6366
|
-
|
|
6367
|
-
|
|
6368
|
-
|
|
6369
|
-
|
|
6370
|
-
|
|
6371
|
-
|
|
6372
|
-
|
|
6373
|
-
|
|
6374
|
-
|
|
6375
|
-
|
|
6376
|
-
|
|
6377
|
-
|
|
6378
|
-
|
|
6417
|
+
const disposeRequest = agentCtx.on(
|
|
6418
|
+
"agent/request",
|
|
6419
|
+
async (_payload, next) => {
|
|
6420
|
+
const resolved = await next();
|
|
6421
|
+
const selected = selection.assembled;
|
|
6422
|
+
if (selected === void 0) return resolved;
|
|
6423
|
+
const { reasoningEffort: _inheritedEffort, ...withoutInheritedEffort } = resolved;
|
|
6424
|
+
return {
|
|
6425
|
+
...withoutInheritedEffort,
|
|
6426
|
+
provider: selected.provider,
|
|
6427
|
+
model: selected.model,
|
|
6428
|
+
...selected.reasoningEffort === void 0 ? {} : { reasoningEffort: selected.reasoningEffort }
|
|
6429
|
+
};
|
|
6430
|
+
}
|
|
6431
|
+
);
|
|
6432
|
+
const disposeNotice = agentCtx.on(
|
|
6433
|
+
"agent/pre-step",
|
|
6434
|
+
async ({ agent, messages, signal, step }, next) => {
|
|
6435
|
+
const decision = await next();
|
|
6436
|
+
if (decision.kind === "reject" || signal.aborted) return decision;
|
|
6437
|
+
if (decision.messages.length === 0 && (step === 1 || messages.length > 0)) return decision;
|
|
6438
|
+
const selected = selection.assembled;
|
|
6439
|
+
const previous = agent.session.requestHeader()?.config;
|
|
6440
|
+
if (selected === void 0 || previous === void 0 || sameRoute(selected, previous)) return decision;
|
|
6441
|
+
return { ...decision, messages: [...decision.messages, modelSwitchNotice(previous, selected)] };
|
|
6442
|
+
},
|
|
6443
|
+
{ prepend: true }
|
|
6444
|
+
);
|
|
6379
6445
|
return () => {
|
|
6380
6446
|
disposeAssembly();
|
|
6381
6447
|
disposeRequest();
|
|
@@ -6383,1053 +6449,6 @@ function installModelSelection(agentCtx, selection) {
|
|
|
6383
6449
|
};
|
|
6384
6450
|
}
|
|
6385
6451
|
|
|
6386
|
-
// packages/util/brand/lib/index.js
|
|
6387
|
-
function brandString2(value) {
|
|
6388
|
-
return value;
|
|
6389
|
-
}
|
|
6390
|
-
|
|
6391
|
-
// packages/llm/llm/lib/index.js
|
|
6392
|
-
import { createRequire as createRequire2 } from "node:module";
|
|
6393
|
-
function freezeMessage2(message) {
|
|
6394
|
-
return deepFreeze(structuredClone(message));
|
|
6395
|
-
}
|
|
6396
|
-
var HarnessError2 = class extends Error {
|
|
6397
|
-
/** Stable machine-routable failure class (e.g. `RATE_LIMIT`); route on this, never by parsing `message`. */
|
|
6398
|
-
code;
|
|
6399
|
-
constructor(message, code, options) {
|
|
6400
|
-
super(message, options);
|
|
6401
|
-
this.code = code;
|
|
6402
|
-
this.name = new.target.name;
|
|
6403
|
-
}
|
|
6404
|
-
};
|
|
6405
|
-
var EMPTY_RESPONSE_CODE2 = "EMPTY_RESPONSE";
|
|
6406
|
-
var STRUCTURED_CONTEXT_OVERFLOW2 = new RegExp(String.raw`(?:^|[^a-z0-9])context[\s_-](?:length|window)[\s_-]` + String.raw`(?:exceed(?:ed|s)?|overflow(?:ed)?|limit[\s_-]exceeded)(?:$|[^a-z0-9])`, "i");
|
|
6407
|
-
var TOO_LARGE_FOR_CONTEXT2 = new RegExp(String.raw`\b(?:request|prompt|input|messages?)\s+(?:is\s+|are\s+)?` + String.raw`too\s+(?:large|long)\s+for\s+(?:(?:this|the)\s+)?` + String.raw`(?:model(?:'s)?\s+)?context(?:\s+window)?\b`, "i");
|
|
6408
|
-
var EXCEEDS_MODEL_CONTEXT2 = new RegExp(String.raw`\b(?:input|prompt|request|messages?)\b.{0,40}` + String.raw`\b(?:exceed(?:s|ed)?|overflows?|is\s+larger\s+than)\b.{0,40}` + String.raw`\b(?:the\s+)?(?:model(?:'s)?\s+)?context(?:\s+(?:length|window))?\b`, "i");
|
|
6409
|
-
var DEFAULT_MAX_RETRIES2 = 5;
|
|
6410
|
-
var DEFAULT_INITIAL_DELAY_MS2 = 500;
|
|
6411
|
-
var DEFAULT_MAX_DELAY_MS2 = 1e4;
|
|
6412
|
-
var DEFAULT_JITTER_RATIO2 = 0.1;
|
|
6413
|
-
var DEFAULT_RETRYABLE_CODES2 = Object.freeze([
|
|
6414
|
-
EMPTY_RESPONSE_CODE2,
|
|
6415
|
-
"RATE_LIMIT",
|
|
6416
|
-
"SERVER",
|
|
6417
|
-
"TIMEOUT",
|
|
6418
|
-
"TRANSPORT"
|
|
6419
|
-
]);
|
|
6420
|
-
var backoffSchema2 = src_default.object({
|
|
6421
|
-
initialDelayMs: src_default.number().max(MAX_TIMER_DELAY_MS).default(DEFAULT_INITIAL_DELAY_MS2),
|
|
6422
|
-
maxDelayMs: src_default.number().max(MAX_TIMER_DELAY_MS).default(DEFAULT_MAX_DELAY_MS2),
|
|
6423
|
-
jitterRatio: src_default.number().min(0).max(1).default(DEFAULT_JITTER_RATIO2)
|
|
6424
|
-
});
|
|
6425
|
-
var normalPolicySchema2 = src_default.object({
|
|
6426
|
-
mode: src_default.const("normal").required(),
|
|
6427
|
-
maxRetries: src_default.number().step(1).min(0).max(Number.MAX_SAFE_INTEGER).default(DEFAULT_MAX_RETRIES2),
|
|
6428
|
-
retryableCodes: src_default.array(src_default.string()).default([...DEFAULT_RETRYABLE_CODES2]),
|
|
6429
|
-
backoff: backoffSchema2
|
|
6430
|
-
});
|
|
6431
|
-
var alwaysPolicySchema2 = src_default.object({
|
|
6432
|
-
mode: src_default.const("always").required(),
|
|
6433
|
-
backoff: backoffSchema2
|
|
6434
|
-
});
|
|
6435
|
-
var RetryPolicySchema2 = src_default.union([normalPolicySchema2, alwaysPolicySchema2]);
|
|
6436
|
-
var NORMAL_POLICY_KEYS2 = /* @__PURE__ */ new Set([
|
|
6437
|
-
"mode",
|
|
6438
|
-
"maxRetries",
|
|
6439
|
-
"retryableCodes",
|
|
6440
|
-
"backoff"
|
|
6441
|
-
]);
|
|
6442
|
-
var ALWAYS_POLICY_KEYS2 = /* @__PURE__ */ new Set([
|
|
6443
|
-
"mode",
|
|
6444
|
-
"maxRetries",
|
|
6445
|
-
"retryableCodes",
|
|
6446
|
-
"backoff"
|
|
6447
|
-
]);
|
|
6448
|
-
var BACKOFF_KEYS2 = /* @__PURE__ */ new Set([
|
|
6449
|
-
"initialDelayMs",
|
|
6450
|
-
"maxDelayMs",
|
|
6451
|
-
"jitterRatio"
|
|
6452
|
-
]);
|
|
6453
|
-
function validateKeys2(value, allowed, path) {
|
|
6454
|
-
for (const key of Object.keys(value)) if (!allowed.has(key)) throw new Error(`${path}: unknown key "${key}"`);
|
|
6455
|
-
}
|
|
6456
|
-
function resolveBackoff2(config2, path) {
|
|
6457
|
-
if (config2 !== void 0) validateKeys2(config2, BACKOFF_KEYS2, path);
|
|
6458
|
-
const initialDelayMs = config2?.initialDelayMs ?? DEFAULT_INITIAL_DELAY_MS2;
|
|
6459
|
-
const maxDelayMs = config2?.maxDelayMs ?? DEFAULT_MAX_DELAY_MS2;
|
|
6460
|
-
const jitterRatio = config2?.jitterRatio ?? DEFAULT_JITTER_RATIO2;
|
|
6461
|
-
if (!Number.isFinite(initialDelayMs) || initialDelayMs <= 0 || initialDelayMs > MAX_TIMER_DELAY_MS) throw new Error(`${path}.initialDelayMs must be a positive finite number no greater than ${MAX_TIMER_DELAY_MS}`);
|
|
6462
|
-
if (!Number.isFinite(maxDelayMs) || maxDelayMs <= 0 || maxDelayMs > MAX_TIMER_DELAY_MS) throw new Error(`${path}.maxDelayMs must be a positive finite number no greater than ${MAX_TIMER_DELAY_MS}`);
|
|
6463
|
-
if (initialDelayMs > maxDelayMs) throw new Error(`${path}.initialDelayMs must be less than or equal to maxDelayMs`);
|
|
6464
|
-
if (!Number.isFinite(jitterRatio) || jitterRatio < 0 || jitterRatio > 1) throw new Error(`${path}.jitterRatio must be between 0 and 1`);
|
|
6465
|
-
return Object.freeze({
|
|
6466
|
-
initialDelayMs,
|
|
6467
|
-
maxDelayMs,
|
|
6468
|
-
jitterRatio
|
|
6469
|
-
});
|
|
6470
|
-
}
|
|
6471
|
-
function resolveRetryPolicy2(config2, path) {
|
|
6472
|
-
if (config2 === void 0) return Object.freeze({
|
|
6473
|
-
mode: "normal",
|
|
6474
|
-
maxRetries: DEFAULT_MAX_RETRIES2,
|
|
6475
|
-
retryableCodes: DEFAULT_RETRYABLE_CODES2,
|
|
6476
|
-
...resolveBackoff2(void 0, `${path}.backoff`)
|
|
6477
|
-
});
|
|
6478
|
-
switch (config2.mode) {
|
|
6479
|
-
case "normal": {
|
|
6480
|
-
validateKeys2(config2, NORMAL_POLICY_KEYS2, path);
|
|
6481
|
-
const maxRetries = config2.maxRetries ?? DEFAULT_MAX_RETRIES2;
|
|
6482
|
-
const retryableCodes = config2.retryableCodes ?? [...DEFAULT_RETRYABLE_CODES2];
|
|
6483
|
-
if (!Number.isSafeInteger(maxRetries) || maxRetries < 0) throw new Error(`${path}.maxRetries must be a non-negative safe integer`);
|
|
6484
|
-
if (retryableCodes.length === 0) throw new Error(`${path}.retryableCodes must not be empty`);
|
|
6485
|
-
if (retryableCodes.some((code) => typeof code !== "string" || code.length === 0)) throw new Error(`${path}.retryableCodes must contain only non-empty strings`);
|
|
6486
|
-
if (new Set(retryableCodes).size !== retryableCodes.length) throw new Error(`${path}.retryableCodes must not contain duplicates`);
|
|
6487
|
-
return Object.freeze({
|
|
6488
|
-
mode: "normal",
|
|
6489
|
-
maxRetries,
|
|
6490
|
-
retryableCodes: Object.freeze([...retryableCodes]),
|
|
6491
|
-
...resolveBackoff2(config2.backoff, `${path}.backoff`)
|
|
6492
|
-
});
|
|
6493
|
-
}
|
|
6494
|
-
case "always":
|
|
6495
|
-
validateKeys2(config2, ALWAYS_POLICY_KEYS2, path);
|
|
6496
|
-
return Object.freeze({
|
|
6497
|
-
mode: "always",
|
|
6498
|
-
...resolveBackoff2(config2.backoff, `${path}.backoff`)
|
|
6499
|
-
});
|
|
6500
|
-
default:
|
|
6501
|
-
throw new Error(`${path}.mode must be "normal" or "always"`);
|
|
6502
|
-
}
|
|
6503
|
-
}
|
|
6504
|
-
function callConfigEquals2(a2, b2) {
|
|
6505
|
-
if (a2.provider !== b2.provider || a2.model !== b2.model || a2.reasoningEffort !== b2.reasoningEffort || a2.temperature !== b2.temperature || a2.maxTokens !== b2.maxTokens) return false;
|
|
6506
|
-
if (a2.stop === void 0 || b2.stop === void 0) return a2.stop === b2.stop;
|
|
6507
|
-
return a2.stop.length === b2.stop.length && a2.stop.every((s2, i2) => s2 === b2.stop?.[i2]);
|
|
6508
|
-
}
|
|
6509
|
-
function normalizeLlmFailure2(value) {
|
|
6510
|
-
const error51 = value instanceof Error ? value : new HarnessError2(thrownMessage2(value), "UNKNOWN", { cause: value });
|
|
6511
|
-
const carried = ownFailureSnapshot2(error51);
|
|
6512
|
-
if (carried !== void 0 && carried.code === ownErrorCode2(error51)) return carried;
|
|
6513
|
-
return Object.freeze({
|
|
6514
|
-
message: errorMessage2(error51),
|
|
6515
|
-
code: harnessErrorCode2(error51)
|
|
6516
|
-
});
|
|
6517
|
-
}
|
|
6518
|
-
function thrownMessage2(value) {
|
|
6519
|
-
try {
|
|
6520
|
-
const message = String(value);
|
|
6521
|
-
return message.length > 0 ? message : "LLM adapter failed";
|
|
6522
|
-
} catch (_hostileThrownValue) {
|
|
6523
|
-
return "LLM adapter failed";
|
|
6524
|
-
}
|
|
6525
|
-
}
|
|
6526
|
-
function ownErrorCode2(error51) {
|
|
6527
|
-
try {
|
|
6528
|
-
const descriptor = Object.getOwnPropertyDescriptor(error51, "code");
|
|
6529
|
-
return descriptor !== void 0 && "value" in descriptor ? descriptor.value : void 0;
|
|
6530
|
-
} catch (_sdkPropertyTrap) {
|
|
6531
|
-
return;
|
|
6532
|
-
}
|
|
6533
|
-
}
|
|
6534
|
-
function ownFailureSnapshot2(error51) {
|
|
6535
|
-
try {
|
|
6536
|
-
const descriptor = Object.getOwnPropertyDescriptor(error51, "failure");
|
|
6537
|
-
return descriptor !== void 0 && "value" in descriptor ? failureSnapshot2(descriptor.value) : void 0;
|
|
6538
|
-
} catch (_sdkPropertyTrap) {
|
|
6539
|
-
return;
|
|
6540
|
-
}
|
|
6541
|
-
}
|
|
6542
|
-
function failureSnapshot2(value) {
|
|
6543
|
-
if (typeof value !== "object" || value === null) return void 0;
|
|
6544
|
-
try {
|
|
6545
|
-
const candidate = value;
|
|
6546
|
-
const message = candidate.message;
|
|
6547
|
-
const code = candidate.code;
|
|
6548
|
-
const status = candidate.status;
|
|
6549
|
-
const providerRetryAfterMs = candidate.providerRetryAfterMs;
|
|
6550
|
-
const requestId = candidate.requestId;
|
|
6551
|
-
const offloadImages = candidate.offloadImages;
|
|
6552
|
-
if (typeof message !== "string" || message.length === 0 || typeof code !== "string" || code.length === 0 || status !== void 0 && (!Number.isInteger(status) || status < 100 || status > 599) || providerRetryAfterMs !== void 0 && (!Number.isFinite(providerRetryAfterMs) || providerRetryAfterMs <= 0) || requestId !== void 0 && (typeof requestId !== "string" || requestId.length === 0) || offloadImages !== void 0 && (!Number.isSafeInteger(offloadImages) || offloadImages <= 0)) return void 0;
|
|
6553
|
-
return Object.freeze({
|
|
6554
|
-
message,
|
|
6555
|
-
code,
|
|
6556
|
-
...status === void 0 ? {} : { status },
|
|
6557
|
-
...providerRetryAfterMs === void 0 ? {} : { providerRetryAfterMs },
|
|
6558
|
-
...requestId === void 0 ? {} : { requestId },
|
|
6559
|
-
...offloadImages === void 0 ? {} : { offloadImages }
|
|
6560
|
-
});
|
|
6561
|
-
} catch (_sdkFailureGetter) {
|
|
6562
|
-
return;
|
|
6563
|
-
}
|
|
6564
|
-
}
|
|
6565
|
-
function errorMessage2(error51) {
|
|
6566
|
-
try {
|
|
6567
|
-
const message = error51.message;
|
|
6568
|
-
if (typeof message === "string" && message.length > 0) return message;
|
|
6569
|
-
} catch (_sdkMessageGetter) {
|
|
6570
|
-
}
|
|
6571
|
-
return "LLM adapter failed";
|
|
6572
|
-
}
|
|
6573
|
-
function harnessErrorCode2(error51) {
|
|
6574
|
-
return error51 instanceof HarnessError2 ? error51.code : "UNKNOWN";
|
|
6575
|
-
}
|
|
6576
|
-
function quoted2(value) {
|
|
6577
|
-
return JSON.stringify(value);
|
|
6578
|
-
}
|
|
6579
|
-
function textOnlyImageText2(ref) {
|
|
6580
|
-
return `[image omitted because this model accepts text only; attachment sha256:${String(ref.attachmentId).slice(7, 15)}]`;
|
|
6581
|
-
}
|
|
6582
|
-
function contentHasImage2(content) {
|
|
6583
|
-
return content.some((block) => block.type === "image");
|
|
6584
|
-
}
|
|
6585
|
-
function contentHasFile2(content) {
|
|
6586
|
-
for (const block of content) if (block.type === "file") return true;
|
|
6587
|
-
return false;
|
|
6588
|
-
}
|
|
6589
|
-
function fileHandleText2(ref, readonlyPath) {
|
|
6590
|
-
const digest = String(ref.attachmentId).slice(7, 15);
|
|
6591
|
-
const identity = `File ${quoted2(ref.name)} (${ref.bytes} bytes, sha256:${digest})`;
|
|
6592
|
-
if (readonlyPath === void 0) return `[${identity} was uploaded, but the current execution environment cannot access a readable path. Report that limitation if its contents are needed; do not claim to have read it.]`;
|
|
6593
|
-
return `[${identity}: verbatim read-only copy saved at ${quoted2(readonlyPath)}. Read that path with your file tools when its contents are needed; copy it to a writable location before modifying it. When delegating file work, include this saved path in the delegation prompt; only subagents sharing this execution environment can read it.]`;
|
|
6594
|
-
}
|
|
6595
|
-
function replaceFilesWithHandles2(blocks, resolvePath) {
|
|
6596
|
-
let next;
|
|
6597
|
-
for (const [index, block] of blocks.entries()) {
|
|
6598
|
-
if (block.type === "file") {
|
|
6599
|
-
next ??= blocks.slice(0, index);
|
|
6600
|
-
next.push({
|
|
6601
|
-
type: "text",
|
|
6602
|
-
text: fileHandleText2(block.attachment, resolvePath(block.attachment))
|
|
6603
|
-
});
|
|
6604
|
-
continue;
|
|
6605
|
-
}
|
|
6606
|
-
next?.push(block);
|
|
6607
|
-
}
|
|
6608
|
-
return next ?? blocks;
|
|
6609
|
-
}
|
|
6610
|
-
function projectFilesToText2(messages, resolvePath) {
|
|
6611
|
-
if (!messages.some((message) => contentHasFile2(message.content))) return messages;
|
|
6612
|
-
return messages.map((message) => {
|
|
6613
|
-
const content = replaceFilesWithHandles2(message.content, resolvePath);
|
|
6614
|
-
return content === message.content ? message : {
|
|
6615
|
-
...message,
|
|
6616
|
-
content
|
|
6617
|
-
};
|
|
6618
|
-
});
|
|
6619
|
-
}
|
|
6620
|
-
function replaceImagesForTextModel2(blocks) {
|
|
6621
|
-
let next;
|
|
6622
|
-
for (const [index, block] of blocks.entries()) {
|
|
6623
|
-
if (block.type === "image") {
|
|
6624
|
-
next ??= blocks.slice(0, index);
|
|
6625
|
-
next.push({
|
|
6626
|
-
type: "text",
|
|
6627
|
-
text: textOnlyImageText2(block.attachment)
|
|
6628
|
-
});
|
|
6629
|
-
continue;
|
|
6630
|
-
}
|
|
6631
|
-
next?.push(block);
|
|
6632
|
-
}
|
|
6633
|
-
return next ?? blocks;
|
|
6634
|
-
}
|
|
6635
|
-
function projectImagesForTextModel2(messages) {
|
|
6636
|
-
if (!messages.some((message) => contentHasImage2(message.content))) return messages;
|
|
6637
|
-
return messages.map((message) => {
|
|
6638
|
-
const content = replaceImagesForTextModel2(message.content);
|
|
6639
|
-
return content === message.content ? message : {
|
|
6640
|
-
...message,
|
|
6641
|
-
content
|
|
6642
|
-
};
|
|
6643
|
-
});
|
|
6644
|
-
}
|
|
6645
|
-
function withoutDeveloperMessages2(messages) {
|
|
6646
|
-
const retained = messages.filter((message) => message.role !== "developer");
|
|
6647
|
-
return retained.length === messages.length ? messages : retained;
|
|
6648
|
-
}
|
|
6649
|
-
function toolDeclarations2(tools, mode, history) {
|
|
6650
|
-
const declarations = new Map(history.tools.map((tool) => [tool.name, tool]));
|
|
6651
|
-
for (const update of history.updates) for (const tool of update.additions) if (!declarations.has(tool.name)) declarations.set(tool.name, {
|
|
6652
|
-
...tool,
|
|
6653
|
-
deferLoading: true
|
|
6654
|
-
});
|
|
6655
|
-
switch (mode) {
|
|
6656
|
-
case "in-history":
|
|
6657
|
-
return declarations;
|
|
6658
|
-
case "addition-only": {
|
|
6659
|
-
const activeNames = new Set(tools?.map((tool) => tool.name));
|
|
6660
|
-
for (const name2 of declarations.keys()) if (!activeNames.has(name2)) declarations.delete(name2);
|
|
6661
|
-
return declarations;
|
|
6662
|
-
}
|
|
6663
|
-
/* v8 ignore next 2 -- closed-union exhaustiveness guard */
|
|
6664
|
-
default:
|
|
6665
|
-
return assertNever(mode);
|
|
6666
|
-
}
|
|
6667
|
-
}
|
|
6668
|
-
function projectToolUpdates2(messages, tools, toolUpdate, history) {
|
|
6669
|
-
if (toolUpdate === void 0) {
|
|
6670
|
-
let immediateTools = tools;
|
|
6671
|
-
if (tools?.some((tool) => tool.deferLoading === true)) immediateTools = tools.map(({ deferLoading: _loading, ...tool }) => tool);
|
|
6672
|
-
return {
|
|
6673
|
-
messages: withoutDeveloperMessages2(messages),
|
|
6674
|
-
tools: immediateTools
|
|
6675
|
-
};
|
|
6676
|
-
}
|
|
6677
|
-
if (history === void 0) return {
|
|
6678
|
-
messages: withoutDeveloperMessages2(messages),
|
|
6679
|
-
tools
|
|
6680
|
-
};
|
|
6681
|
-
const messageIds = new Set(messages.flatMap((message) => message.role === "developer" ? [message.id] : []));
|
|
6682
|
-
if (history.updates.some((update) => !messageIds.has(update.messageId))) return {
|
|
6683
|
-
messages: withoutDeveloperMessages2(messages),
|
|
6684
|
-
tools
|
|
6685
|
-
};
|
|
6686
|
-
const declarations = toolDeclarations2(tools, toolUpdate, history);
|
|
6687
|
-
const updateIds = new Set(history.updates.map((update) => update.messageId));
|
|
6688
|
-
const offered = new Set(history.tools.filter((tool) => !tool.deferLoading).map((tool) => tool.name));
|
|
6689
|
-
const projectedMessages = [];
|
|
6690
|
-
for (const message of messages) {
|
|
6691
|
-
if (message.role !== "developer") {
|
|
6692
|
-
projectedMessages.push(message);
|
|
6693
|
-
continue;
|
|
6694
|
-
}
|
|
6695
|
-
if (!updateIds.has(message.id)) continue;
|
|
6696
|
-
const content = message.content.filter((block) => {
|
|
6697
|
-
switch (block.type) {
|
|
6698
|
-
case "tool-addition":
|
|
6699
|
-
if (!declarations.has(block.toolName) || offered.has(block.toolName)) return false;
|
|
6700
|
-
offered.add(block.toolName);
|
|
6701
|
-
return true;
|
|
6702
|
-
case "tool-removal":
|
|
6703
|
-
if (toolUpdate !== "in-history") return false;
|
|
6704
|
-
return offered.delete(block.toolName);
|
|
6705
|
-
default:
|
|
6706
|
-
return true;
|
|
6707
|
-
}
|
|
6708
|
-
});
|
|
6709
|
-
if (content.length === 0) continue;
|
|
6710
|
-
if (content.length === message.content.length) projectedMessages.push(message);
|
|
6711
|
-
else projectedMessages.push({
|
|
6712
|
-
...message,
|
|
6713
|
-
content
|
|
6714
|
-
});
|
|
6715
|
-
}
|
|
6716
|
-
return {
|
|
6717
|
-
messages: projectedMessages.length === messages.length && projectedMessages.every((message, index) => message === messages[index]) ? messages : projectedMessages,
|
|
6718
|
-
tools: [...declarations.values()]
|
|
6719
|
-
};
|
|
6720
|
-
}
|
|
6721
|
-
var { version: version2 } = createRequire2(import.meta.url)("../package.json");
|
|
6722
|
-
function ReasoningEffortId2(id) {
|
|
6723
|
-
return brandString(id);
|
|
6724
|
-
}
|
|
6725
|
-
var __runInitializers2 = function(thisArg, initializers, value) {
|
|
6726
|
-
var useValue = arguments.length > 2;
|
|
6727
|
-
for (var i2 = 0; i2 < initializers.length; i2++) value = useValue ? initializers[i2].call(thisArg, value) : initializers[i2].call(thisArg);
|
|
6728
|
-
return useValue ? value : void 0;
|
|
6729
|
-
};
|
|
6730
|
-
var __esDecorate = function(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
6731
|
-
function accept(f2) {
|
|
6732
|
-
if (f2 !== void 0 && typeof f2 !== "function") throw new TypeError("Function expected");
|
|
6733
|
-
return f2;
|
|
6734
|
-
}
|
|
6735
|
-
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
6736
|
-
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
6737
|
-
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
6738
|
-
var _2, done = false;
|
|
6739
|
-
for (var i2 = decorators.length - 1; i2 >= 0; i2--) {
|
|
6740
|
-
var context = {};
|
|
6741
|
-
for (var p2 in contextIn) context[p2] = p2 === "access" ? {} : contextIn[p2];
|
|
6742
|
-
for (var p2 in contextIn.access) context.access[p2] = contextIn.access[p2];
|
|
6743
|
-
context.addInitializer = function(f2) {
|
|
6744
|
-
if (done) throw new TypeError("Cannot add initializers after decoration has completed");
|
|
6745
|
-
extraInitializers.push(accept(f2 || null));
|
|
6746
|
-
};
|
|
6747
|
-
var result = (0, decorators[i2])(kind === "accessor" ? {
|
|
6748
|
-
get: descriptor.get,
|
|
6749
|
-
set: descriptor.set
|
|
6750
|
-
} : descriptor[key], context);
|
|
6751
|
-
if (kind === "accessor") {
|
|
6752
|
-
if (result === void 0) continue;
|
|
6753
|
-
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
6754
|
-
if (_2 = accept(result.get)) descriptor.get = _2;
|
|
6755
|
-
if (_2 = accept(result.set)) descriptor.set = _2;
|
|
6756
|
-
if (_2 = accept(result.init)) initializers.unshift(_2);
|
|
6757
|
-
} else if (_2 = accept(result)) if (kind === "field") initializers.unshift(_2);
|
|
6758
|
-
else descriptor[key] = _2;
|
|
6759
|
-
}
|
|
6760
|
-
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
6761
|
-
done = true;
|
|
6762
|
-
};
|
|
6763
|
-
var LlmError2 = class extends HarnessError2 {
|
|
6764
|
-
/** Serializable facts retained beside this live Error. */
|
|
6765
|
-
failure;
|
|
6766
|
-
/**
|
|
6767
|
-
* @param message - non-empty human-readable failure summary.
|
|
6768
|
-
* @param code - non-empty stable provider-neutral machine code.
|
|
6769
|
-
* @param options - optional cause and validated serializable provider facts.
|
|
6770
|
-
*/
|
|
6771
|
-
constructor(message, code, options) {
|
|
6772
|
-
if (typeof message !== "string" || message.length === 0) throw new Error("LlmError message must be a non-empty string");
|
|
6773
|
-
if (typeof code !== "string" || code.length === 0) throw new Error("LlmError code must be a non-empty string");
|
|
6774
|
-
if (options?.status !== void 0 && (!Number.isInteger(options.status) || options.status < 100 || options.status > 599)) throw new Error("LlmError status must be an integer from 100 through 599");
|
|
6775
|
-
if (options?.providerRetryAfterMs !== void 0 && (!Number.isFinite(options.providerRetryAfterMs) || options.providerRetryAfterMs <= 0)) throw new Error("LlmError providerRetryAfterMs must be a positive finite number");
|
|
6776
|
-
if (options?.requestId !== void 0 && (typeof options.requestId !== "string" || options.requestId.length === 0)) throw new Error("LlmError requestId must be a non-empty string");
|
|
6777
|
-
super(message, code, options);
|
|
6778
|
-
this.name = "LlmError";
|
|
6779
|
-
this.failure = Object.freeze({
|
|
6780
|
-
message,
|
|
6781
|
-
code,
|
|
6782
|
-
...options?.status === void 0 ? {} : { status: options.status },
|
|
6783
|
-
...options?.providerRetryAfterMs === void 0 ? {} : { providerRetryAfterMs: options.providerRetryAfterMs },
|
|
6784
|
-
...options?.requestId === void 0 ? {} : { requestId: options.requestId },
|
|
6785
|
-
...options?.offloadImages === void 0 ? {} : { offloadImages: options.offloadImages }
|
|
6786
|
-
});
|
|
6787
|
-
}
|
|
6788
|
-
};
|
|
6789
|
-
var LlmRuntime2 = (() => {
|
|
6790
|
-
let _classSuper = TypertRemoteService;
|
|
6791
|
-
let _instanceExtraInitializers = [];
|
|
6792
|
-
let _listProviders_decorators;
|
|
6793
|
-
let _listConfigurableProviders_decorators;
|
|
6794
|
-
let _remoteDiscoverModels_decorators;
|
|
6795
|
-
return class LlmRuntime extends _classSuper {
|
|
6796
|
-
static {
|
|
6797
|
-
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
6798
|
-
_listProviders_decorators = [Remote];
|
|
6799
|
-
_listConfigurableProviders_decorators = [Remote];
|
|
6800
|
-
_remoteDiscoverModels_decorators = [Remote("discoverModels")];
|
|
6801
|
-
__esDecorate(this, null, _listProviders_decorators, {
|
|
6802
|
-
kind: "method",
|
|
6803
|
-
name: "listProviders",
|
|
6804
|
-
static: false,
|
|
6805
|
-
private: false,
|
|
6806
|
-
access: {
|
|
6807
|
-
has: (obj) => "listProviders" in obj,
|
|
6808
|
-
get: (obj) => obj.listProviders
|
|
6809
|
-
},
|
|
6810
|
-
metadata: _metadata
|
|
6811
|
-
}, null, _instanceExtraInitializers);
|
|
6812
|
-
__esDecorate(this, null, _listConfigurableProviders_decorators, {
|
|
6813
|
-
kind: "method",
|
|
6814
|
-
name: "listConfigurableProviders",
|
|
6815
|
-
static: false,
|
|
6816
|
-
private: false,
|
|
6817
|
-
access: {
|
|
6818
|
-
has: (obj) => "listConfigurableProviders" in obj,
|
|
6819
|
-
get: (obj) => obj.listConfigurableProviders
|
|
6820
|
-
},
|
|
6821
|
-
metadata: _metadata
|
|
6822
|
-
}, null, _instanceExtraInitializers);
|
|
6823
|
-
__esDecorate(this, null, _remoteDiscoverModels_decorators, {
|
|
6824
|
-
kind: "method",
|
|
6825
|
-
name: "remoteDiscoverModels",
|
|
6826
|
-
static: false,
|
|
6827
|
-
private: false,
|
|
6828
|
-
access: {
|
|
6829
|
-
has: (obj) => "remoteDiscoverModels" in obj,
|
|
6830
|
-
get: (obj) => obj.remoteDiscoverModels
|
|
6831
|
-
},
|
|
6832
|
-
metadata: _metadata
|
|
6833
|
-
}, null, _instanceExtraInitializers);
|
|
6834
|
-
if (_metadata) Object.defineProperty(this, Symbol.metadata, {
|
|
6835
|
-
enumerable: true,
|
|
6836
|
-
configurable: true,
|
|
6837
|
-
writable: true,
|
|
6838
|
-
value: _metadata
|
|
6839
|
-
});
|
|
6840
|
-
}
|
|
6841
|
-
adapters = (__runInitializers2(this, _instanceExtraInitializers), /* @__PURE__ */ new Map());
|
|
6842
|
-
directory = /* @__PURE__ */ new Map();
|
|
6843
|
-
discoveries = /* @__PURE__ */ new Map();
|
|
6844
|
-
constructor(ctx) {
|
|
6845
|
-
super(ctx, "llm");
|
|
6846
|
-
}
|
|
6847
|
-
/** Notify topology observers without letting one broken listener veto the commit. */
|
|
6848
|
-
emitAdaptersUpdated() {
|
|
6849
|
-
for (const listener of this.ctx.events.dispatch("emit", ["llm/adapters-updated"])) try {
|
|
6850
|
-
const returned = listener();
|
|
6851
|
-
if (returned != null && typeof returned.then === "function") Promise.resolve(returned).then(void 0, (error51) => {
|
|
6852
|
-
this.warnAdaptersListenerFailure(error51);
|
|
6853
|
-
});
|
|
6854
|
-
} catch (error51) {
|
|
6855
|
-
this.warnAdaptersListenerFailure(error51);
|
|
6856
|
-
}
|
|
6857
|
-
}
|
|
6858
|
-
/** Contained-listener diagnostic shared by the sync and async failure paths. */
|
|
6859
|
-
warnAdaptersListenerFailure(error51) {
|
|
6860
|
-
this.ctx.logger.warn("llm: an llm/adapters-updated listener failed");
|
|
6861
|
-
this.ctx.logger.warn(error51);
|
|
6862
|
-
}
|
|
6863
|
-
/**
|
|
6864
|
-
* Register an adapter for the given provider routes. Throws `LlmError` with code
|
|
6865
|
-
* `DUPLICATE_ADAPTER` if any provider already has an adapter (all-or-nothing).
|
|
6866
|
-
* Disposed with the fiber.
|
|
6867
|
-
* @param providers - every provider route this adapter should serve.
|
|
6868
|
-
* @param adapter - the adapter that streams calls for those providers.
|
|
6869
|
-
* @returns the disposer, carrying {@link AdapterRegistrationHandle.replace}.
|
|
6870
|
-
*/
|
|
6871
|
-
registerAdapter(providers, adapter) {
|
|
6872
|
-
const owned = /* @__PURE__ */ new Set();
|
|
6873
|
-
let released = false;
|
|
6874
|
-
const dispose = this.ctx.effect(function* () {
|
|
6875
|
-
if (providers.length === 0) throw new LlmError2("an adapter must register at least one provider", "INVALID_ADAPTER");
|
|
6876
|
-
this.commitRoutes(owned, this.prepareRoutes(providers, adapter, owned));
|
|
6877
|
-
yield () => {
|
|
6878
|
-
released = true;
|
|
6879
|
-
for (const provider of owned) this.adapters.delete(provider);
|
|
6880
|
-
owned.clear();
|
|
6881
|
-
this.emitAdaptersUpdated();
|
|
6882
|
-
};
|
|
6883
|
-
}.bind(this), "llm.registerAdapter()");
|
|
6884
|
-
const handle = (() => void dispose());
|
|
6885
|
-
handle.replace = (next) => {
|
|
6886
|
-
if (released) throw new LlmError2("a disposed adapter registration cannot replace its routes", "REGISTRATION_DISPOSED");
|
|
6887
|
-
this.commitRoutes(owned, this.prepareRoutes(next, adapter, owned));
|
|
6888
|
-
};
|
|
6889
|
-
return handle;
|
|
6890
|
-
}
|
|
6891
|
-
/**
|
|
6892
|
-
* Validate one candidate route set for `adapter`, treating routes this
|
|
6893
|
-
* registration already holds as available. Nothing is mutated: a rejected
|
|
6894
|
-
* candidate leaves the registry exactly as it was.
|
|
6895
|
-
*/
|
|
6896
|
-
prepareRoutes(providers, adapter, owned) {
|
|
6897
|
-
const unique = /* @__PURE__ */ new Set();
|
|
6898
|
-
const registrations = [];
|
|
6899
|
-
for (const provider of providers) {
|
|
6900
|
-
if (provider.length === 0) throw new LlmError2("adapter provider names must be non-empty", "INVALID_ADAPTER");
|
|
6901
|
-
if (unique.has(provider) || this.adapters.has(provider) && !owned.has(provider)) throw new LlmError2(`an adapter for provider "${provider}" is already registered`, "DUPLICATE_ADAPTER");
|
|
6902
|
-
const info = adapter.providerInfo(provider);
|
|
6903
|
-
if (typeof info.id !== "string" || info.id !== provider || typeof info.name !== "string" || info.name.length === 0) throw new LlmError2(`adapter metadata for provider "${provider}" must preserve its id and have a non-empty name`, "INVALID_ADAPTER");
|
|
6904
|
-
unique.add(provider);
|
|
6905
|
-
const retryPolicy = adapter.providerRetryPolicy(provider) ?? resolveRetryPolicy2(void 0, `llm: provider "${provider}" retryPolicy`);
|
|
6906
|
-
registrations.push({
|
|
6907
|
-
adapter,
|
|
6908
|
-
provider: {
|
|
6909
|
-
id: info.id,
|
|
6910
|
-
name: info.name
|
|
6911
|
-
},
|
|
6912
|
-
retryPolicy
|
|
6913
|
-
});
|
|
6914
|
-
}
|
|
6915
|
-
return registrations;
|
|
6916
|
-
}
|
|
6917
|
-
/**
|
|
6918
|
-
* Swap this registration's routes for the prepared ones in one synchronous
|
|
6919
|
-
* section, so no observer can see the registry between the release and the
|
|
6920
|
-
* re-registration. The route set's one mutation point is also where
|
|
6921
|
-
* `llm/adapters-updated` is published, so a `replace` announces itself
|
|
6922
|
-
* exactly like a first registration.
|
|
6923
|
-
*/
|
|
6924
|
-
commitRoutes(owned, registrations) {
|
|
6925
|
-
for (const provider of owned) this.adapters.delete(provider);
|
|
6926
|
-
owned.clear();
|
|
6927
|
-
for (const registration of registrations) {
|
|
6928
|
-
this.adapters.set(registration.provider.id, registration);
|
|
6929
|
-
owned.add(registration.provider.id);
|
|
6930
|
-
}
|
|
6931
|
-
this.emitAdaptersUpdated();
|
|
6932
|
-
}
|
|
6933
|
-
/**
|
|
6934
|
-
* Describe provider routes with a registered adapter.
|
|
6935
|
-
* @returns detached provider metadata in registration order.
|
|
6936
|
-
*/
|
|
6937
|
-
listProviders() {
|
|
6938
|
-
return [...this.adapters.values()].map(({ provider }) => ({ ...provider }));
|
|
6939
|
-
}
|
|
6940
|
-
/**
|
|
6941
|
-
* Declare provider routes an adapter plugin can activate through
|
|
6942
|
-
* configuration. Registration is all-or-nothing: an empty list, invalid
|
|
6943
|
-
* entry, or a provider already declared by any registration throws
|
|
6944
|
-
* `LlmError` without registering the rest. Disposed with the fiber.
|
|
6945
|
-
* @param entries - every configurable provider this plugin owns.
|
|
6946
|
-
* @returns a handle that withdraws all of them, and can atomically replace them.
|
|
6947
|
-
*/
|
|
6948
|
-
registerConfigurableProviders(entries) {
|
|
6949
|
-
let held = [];
|
|
6950
|
-
let disposed = false;
|
|
6951
|
-
const commit = (candidates) => {
|
|
6952
|
-
const detached = [];
|
|
6953
|
-
const own = new Set(held.map((entry) => entry.provider));
|
|
6954
|
-
for (const entry of candidates) {
|
|
6955
|
-
if (entry.provider.length === 0 || entry.displayName.length === 0 || entry.settingsNs.length === 0) throw new LlmError2("configurable providers need a non-empty provider, displayName, and settingsNs", "INVALID_DIRECTORY");
|
|
6956
|
-
if (entry.settingsPath.some((segment) => segment.length === 0)) throw new LlmError2(`configurable provider "${entry.provider}" has an empty settingsPath segment`, "INVALID_DIRECTORY");
|
|
6957
|
-
if (this.directory.has(entry.provider) && !own.has(entry.provider) || detached.some((seen) => seen.provider === entry.provider)) throw new LlmError2(`configurable provider "${entry.provider}" is already declared`, "DUPLICATE_DIRECTORY");
|
|
6958
|
-
detached.push({
|
|
6959
|
-
...entry,
|
|
6960
|
-
settingsPath: [...entry.settingsPath]
|
|
6961
|
-
});
|
|
6962
|
-
}
|
|
6963
|
-
for (const entry of held) this.directory.delete(entry.provider);
|
|
6964
|
-
for (const entry of detached) this.directory.set(entry.provider, entry);
|
|
6965
|
-
held = detached;
|
|
6966
|
-
this.emitAdaptersUpdated();
|
|
6967
|
-
};
|
|
6968
|
-
const dispose = this.ctx.effect(function* () {
|
|
6969
|
-
if (entries.length === 0) throw new LlmError2("a configurable-provider registration must declare at least one provider", "INVALID_DIRECTORY");
|
|
6970
|
-
commit(entries);
|
|
6971
|
-
yield () => {
|
|
6972
|
-
disposed = true;
|
|
6973
|
-
for (const entry of held) this.directory.delete(entry.provider);
|
|
6974
|
-
held = [];
|
|
6975
|
-
this.emitAdaptersUpdated();
|
|
6976
|
-
};
|
|
6977
|
-
}.bind(this), "llm.registerConfigurableProviders()");
|
|
6978
|
-
const handle = (() => void dispose());
|
|
6979
|
-
handle.replace = (next) => {
|
|
6980
|
-
if (disposed) throw new LlmError2("this configurable-provider registration was disposed", "REGISTRATION_DISPOSED");
|
|
6981
|
-
commit(next);
|
|
6982
|
-
};
|
|
6983
|
-
return handle;
|
|
6984
|
-
}
|
|
6985
|
-
/**
|
|
6986
|
-
* List every declared configurable provider, registered or dormant.
|
|
6987
|
-
* @returns detached directory entries in declaration order.
|
|
6988
|
-
*/
|
|
6989
|
-
listConfigurableProviders() {
|
|
6990
|
-
return [...this.directory.values()].map((entry) => ({
|
|
6991
|
-
...entry,
|
|
6992
|
-
settingsPath: [...entry.settingsPath]
|
|
6993
|
-
}));
|
|
6994
|
-
}
|
|
6995
|
-
/**
|
|
6996
|
-
* Offer to interrogate provider endpoints on behalf of the settings
|
|
6997
|
-
* namespace this plugin owns. The namespace is the key because that is what
|
|
6998
|
-
* a configuration surface already holds from the configurable-provider
|
|
6999
|
-
* directory, and because a provider being *added* has no route to name yet.
|
|
7000
|
-
* Disposed with the fiber.
|
|
7001
|
-
* @param settingsNs - the namespace whose profiles this discovery serves.
|
|
7002
|
-
* @param discover - interrogates one endpoint and must honor the supplied signal.
|
|
7003
|
-
* @returns the disposer that withdraws the offer.
|
|
7004
|
-
*/
|
|
7005
|
-
registerModelDiscovery(settingsNs, discover) {
|
|
7006
|
-
const dispose = this.ctx.effect(function* () {
|
|
7007
|
-
if (settingsNs.length === 0) throw new LlmError2("model discovery needs a non-empty settings namespace", "INVALID_DISCOVERY");
|
|
7008
|
-
if (this.discoveries.has(settingsNs)) throw new LlmError2(`model discovery for "${settingsNs}" is already registered`, "DUPLICATE_DISCOVERY");
|
|
7009
|
-
this.discoveries.set(settingsNs, discover);
|
|
7010
|
-
yield () => {
|
|
7011
|
-
this.discoveries.delete(settingsNs);
|
|
7012
|
-
};
|
|
7013
|
-
}.bind(this), "llm.registerModelDiscovery()");
|
|
7014
|
-
return () => void dispose();
|
|
7015
|
-
}
|
|
7016
|
-
/**
|
|
7017
|
-
* Interrogate one provider endpoint for the models it advertises. The
|
|
7018
|
-
* request describes a draft, not a stored route, so nothing here reads or
|
|
7019
|
-
* writes settings or credentials — the caller owns both, and the reply is
|
|
7020
|
-
* candidate metadata a surface may offer for adoption.
|
|
7021
|
-
* @param settingsNs - namespace whose registered discovery serves this draft.
|
|
7022
|
-
* @param request - the endpoint, protocol, and one-shot credential to use.
|
|
7023
|
-
* @param signal - caller cancellation.
|
|
7024
|
-
* @returns the advertised models, deduplicated in endpoint order.
|
|
7025
|
-
*/
|
|
7026
|
-
async discoverModels(settingsNs, request, signal) {
|
|
7027
|
-
const discover = this.discoveries.get(settingsNs);
|
|
7028
|
-
if (discover === void 0) throw new LlmError2(`no model discovery is registered for "${settingsNs}"`, "NO_DISCOVERY");
|
|
7029
|
-
if ((request.provider ?? "").length === 0 && (request.baseURL ?? "").length === 0) throw new LlmError2("model discovery needs a provider route or a baseURL", "INVALID_DISCOVERY");
|
|
7030
|
-
const discovered = signal === void 0 ? await discover(request) : await discover(request, signal);
|
|
7031
|
-
const seen = /* @__PURE__ */ new Set();
|
|
7032
|
-
const models = [];
|
|
7033
|
-
for (const model of discovered) {
|
|
7034
|
-
if (typeof model.id !== "string" || model.id.length === 0 || seen.has(model.id)) continue;
|
|
7035
|
-
seen.add(model.id);
|
|
7036
|
-
models.push({
|
|
7037
|
-
id: model.id,
|
|
7038
|
-
...model.name === void 0 ? {} : { name: model.name },
|
|
7039
|
-
...model.contextWindow === void 0 ? {} : { contextWindow: model.contextWindow },
|
|
7040
|
-
...model.maxTokens === void 0 ? {} : { maxTokens: model.maxTokens },
|
|
7041
|
-
...model.inputModalities === void 0 ? {} : { inputModalities: [...model.inputModalities] }
|
|
7042
|
-
});
|
|
7043
|
-
}
|
|
7044
|
-
return models;
|
|
7045
|
-
}
|
|
7046
|
-
/**
|
|
7047
|
-
* Remote adapter for one draft provider interrogation.
|
|
7048
|
-
* @param settingsNs - namespace whose registered discovery serves this draft.
|
|
7049
|
-
* @param request - endpoint, protocol, and one-shot credential to use.
|
|
7050
|
-
* @param signal - caller cancellation supplied by the Remote carrier.
|
|
7051
|
-
* @returns advertised models in endpoint order.
|
|
7052
|
-
* @throws RemoteError with `llm/model-discovery-rejected` when discovery refuses or fails.
|
|
7053
|
-
*/
|
|
7054
|
-
async remoteDiscoverModels(settingsNs, request, signal) {
|
|
7055
|
-
try {
|
|
7056
|
-
return await this.discoverModels(settingsNs, request, signal);
|
|
7057
|
-
} catch (error51) {
|
|
7058
|
-
throw new RemoteError("llm/model-discovery-rejected", error51 instanceof Error ? error51.message : String(error51), {
|
|
7059
|
-
settingsNs,
|
|
7060
|
-
...request.baseURL === void 0 ? {} : { baseURL: request.baseURL }
|
|
7061
|
-
}, { cause: error51 });
|
|
7062
|
-
}
|
|
7063
|
-
}
|
|
7064
|
-
/**
|
|
7065
|
-
* Resolve the retry policy captured when one provider route was registered.
|
|
7066
|
-
* @param provider - registered provider route to inspect.
|
|
7067
|
-
* @returns the provider-owned policy, with normal defaults already resolved.
|
|
7068
|
-
*/
|
|
7069
|
-
providerRetryPolicy(provider) {
|
|
7070
|
-
return this.registration(provider).retryPolicy;
|
|
7071
|
-
}
|
|
7072
|
-
/**
|
|
7073
|
-
* Resolve provider-side request-image pricing for one exact route, or
|
|
7074
|
-
* `undefined` when the provider is unregistered or declares none. Unknown
|
|
7075
|
-
* providers degrade to `undefined` rather than throwing because callers
|
|
7076
|
-
* price durable history whose route may no longer be mounted.
|
|
7077
|
-
* @param provider - provider route named by a request header.
|
|
7078
|
-
* @param model - exact model id named by the same header.
|
|
7079
|
-
* @returns the owning adapter's image pricing for the route, when declared.
|
|
7080
|
-
*/
|
|
7081
|
-
imageRequestPricing(provider, model) {
|
|
7082
|
-
return this.adapters.get(provider)?.adapter.imageRequestPricing(provider, model);
|
|
7083
|
-
}
|
|
7084
|
-
/**
|
|
7085
|
-
* Resolve the exact text one durable file occurrence contributes to every
|
|
7086
|
-
* provider request in the current execution environment.
|
|
7087
|
-
* @param ref - durable verbatim file reference from model history.
|
|
7088
|
-
* @returns the same deterministic handle text used at adapter dispatch.
|
|
7089
|
-
*/
|
|
7090
|
-
fileRequestText(ref) {
|
|
7091
|
-
return fileHandleText2(ref, this.fileReadPath(ref));
|
|
7092
|
-
}
|
|
7093
|
-
/** Detach typed adapter-owned modality metadata. */
|
|
7094
|
-
detachedModalities(modalities) {
|
|
7095
|
-
return modalities === void 0 ? void 0 : [...modalities];
|
|
7096
|
-
}
|
|
7097
|
-
/**
|
|
7098
|
-
* Discover models advertised by one registered provider. Catalog membership
|
|
7099
|
-
* does not constrain core routing. Catalog-driven entry points may restrict
|
|
7100
|
-
* selection and submission to the advertised models.
|
|
7101
|
-
* @param provider - registered provider route to inspect.
|
|
7102
|
-
* @returns detached model metadata in adapter-preferred order.
|
|
7103
|
-
*/
|
|
7104
|
-
async listModels(provider) {
|
|
7105
|
-
const models = await this.registration(provider).adapter.listModels(provider);
|
|
7106
|
-
const seen = /* @__PURE__ */ new Set();
|
|
7107
|
-
return models.map((model) => {
|
|
7108
|
-
if (typeof model.provider !== "string" || model.provider !== provider || typeof model.id !== "string" || model.id.length === 0 || typeof model.name !== "string" || model.name.length === 0 || model.description !== void 0 && typeof model.description !== "string" || seen.has(model.id)) throw new LlmError2(`adapter returned invalid or duplicate model metadata for provider "${provider}"`, "INVALID_CATALOG");
|
|
7109
|
-
seen.add(model.id);
|
|
7110
|
-
const inputModalities = this.detachedModalities(model.inputModalities);
|
|
7111
|
-
return {
|
|
7112
|
-
provider: model.provider,
|
|
7113
|
-
id: model.id,
|
|
7114
|
-
name: model.name,
|
|
7115
|
-
...model.description === void 0 ? {} : { description: model.description },
|
|
7116
|
-
...inputModalities === void 0 ? {} : { inputModalities }
|
|
7117
|
-
};
|
|
7118
|
-
});
|
|
7119
|
-
}
|
|
7120
|
-
/**
|
|
7121
|
-
* Resolve and validate all metadata from the adapter that owns one exact
|
|
7122
|
-
* route. The result is detached from adapter-owned objects; catalog
|
|
7123
|
-
* membership remains advisory and does not control request routing.
|
|
7124
|
-
* @param provider - registered provider route to inspect.
|
|
7125
|
-
* @param model - exact model id passed to the adapter.
|
|
7126
|
-
* @param signal - optional cancellation for adapter-owned asynchronous lookup.
|
|
7127
|
-
* @returns exact model identity plus available context and reasoning metadata.
|
|
7128
|
-
*/
|
|
7129
|
-
async resolveModelInfo(provider, model, signal) {
|
|
7130
|
-
return this.resolveModelInfoFor(this.registration(provider), model, signal);
|
|
7131
|
-
}
|
|
7132
|
-
async resolveModelInfoFor(registration, model, signal) {
|
|
7133
|
-
const resolved = await registration.adapter.resolveModel(registration.provider.id, model, signal);
|
|
7134
|
-
return this.normalizeModelInfo(registration, model, resolved);
|
|
7135
|
-
}
|
|
7136
|
-
/** Validate and detach one adapter-returned exact model result. */
|
|
7137
|
-
normalizeModelInfo(registration, model, resolved) {
|
|
7138
|
-
const provider = registration.provider.id;
|
|
7139
|
-
if (typeof resolved.provider !== "string" || resolved.provider !== provider || typeof resolved.id !== "string" || resolved.id !== model || typeof resolved.name !== "string" || resolved.name.length === 0 || resolved.description !== void 0 && typeof resolved.description !== "string") throw new LlmError2(`adapter returned invalid exact model metadata for provider "${provider}" model "${model}"`, "INVALID_MODEL_INFO");
|
|
7140
|
-
const context = resolved.context;
|
|
7141
|
-
if (context !== void 0 && (!Number.isInteger(context.contextWindow) || context.contextWindow <= 0)) throw new LlmError2(`adapter returned invalid context metadata for provider "${provider}" model "${model}"`, "INVALID_MODEL_CONTEXT");
|
|
7142
|
-
const inputModalities = this.detachedModalities(resolved.inputModalities);
|
|
7143
|
-
const systemPromptUpdate = resolved.systemPromptUpdate;
|
|
7144
|
-
if (systemPromptUpdate !== void 0 && systemPromptUpdate !== "in-history") throw new LlmError2(`adapter returned invalid system prompt update mode for provider "${provider}" model "${model}"`, "INVALID_MODEL_INFO");
|
|
7145
|
-
const toolUpdate = resolved.toolUpdate;
|
|
7146
|
-
if (toolUpdate !== void 0 && toolUpdate !== "in-history" && toolUpdate !== "addition-only") throw new LlmError2(`adapter returned invalid tool update mode for provider "${provider}" model "${model}"`, "INVALID_MODEL_INFO");
|
|
7147
|
-
const defaultMaxTokens = resolved.defaultMaxTokens;
|
|
7148
|
-
if (defaultMaxTokens !== void 0 && (!Number.isSafeInteger(defaultMaxTokens) || defaultMaxTokens <= 0)) throw new LlmError2(`adapter returned invalid default maxTokens for provider "${provider}" model "${model}"`, "INVALID_MODEL_MAX_TOKENS");
|
|
7149
|
-
const info = {
|
|
7150
|
-
provider,
|
|
7151
|
-
id: model,
|
|
7152
|
-
name: resolved.name,
|
|
7153
|
-
...resolved.description === void 0 ? {} : { description: resolved.description },
|
|
7154
|
-
...inputModalities === void 0 ? {} : { inputModalities },
|
|
7155
|
-
...context === void 0 ? {} : { context: { contextWindow: context.contextWindow } },
|
|
7156
|
-
...defaultMaxTokens === void 0 ? {} : { defaultMaxTokens },
|
|
7157
|
-
...resolved.systemPromptUpdate === void 0 ? {} : { systemPromptUpdate: resolved.systemPromptUpdate },
|
|
7158
|
-
...resolved.toolUpdate === void 0 ? {} : { toolUpdate: resolved.toolUpdate }
|
|
7159
|
-
};
|
|
7160
|
-
const reasoning = resolved.reasoning;
|
|
7161
|
-
if (reasoning === void 0) return info;
|
|
7162
|
-
if (reasoning.efforts.length === 0) throw new LlmError2(`adapter returned invalid reasoning metadata for provider "${provider}" model "${model}"`, "INVALID_MODEL_REASONING");
|
|
7163
|
-
const seen = /* @__PURE__ */ new Set();
|
|
7164
|
-
const efforts = reasoning.efforts.map((effort) => {
|
|
7165
|
-
if (typeof effort.id !== "string" || effort.id.length === 0 || typeof effort.name !== "string" || effort.name.length === 0 || effort.description !== void 0 && typeof effort.description !== "string" || seen.has(effort.id)) throw new LlmError2(`adapter returned invalid or duplicate reasoning effort metadata for provider "${provider}" model "${model}"`, "INVALID_MODEL_REASONING");
|
|
7166
|
-
seen.add(effort.id);
|
|
7167
|
-
return {
|
|
7168
|
-
id: effort.id,
|
|
7169
|
-
name: effort.name,
|
|
7170
|
-
...effort.description === void 0 ? {} : { description: effort.description }
|
|
7171
|
-
};
|
|
7172
|
-
});
|
|
7173
|
-
if (reasoning.defaultEffort !== void 0 && !seen.has(reasoning.defaultEffort)) throw new LlmError2(`adapter returned an unknown default reasoning effort for provider "${provider}" model "${model}"`, "INVALID_MODEL_REASONING");
|
|
7174
|
-
return {
|
|
7175
|
-
...info,
|
|
7176
|
-
reasoning: {
|
|
7177
|
-
efforts,
|
|
7178
|
-
...reasoning.defaultEffort === void 0 ? {} : { defaultEffort: reasoning.defaultEffort }
|
|
7179
|
-
}
|
|
7180
|
-
};
|
|
7181
|
-
}
|
|
7182
|
-
/**
|
|
7183
|
-
* Validate a conversation call config against its exact model capability and
|
|
7184
|
-
* materialize adapter-configured defaults. Unsupported explicit efforts
|
|
7185
|
-
* reject before provider I/O; no clamping or aliasing is performed. This
|
|
7186
|
-
* standalone query does not bind a later dispatch; use {@link prepareCall}
|
|
7187
|
-
* when logging and streaming must share one adapter registration.
|
|
7188
|
-
* @param config - provider/model route and optional request controls.
|
|
7189
|
-
* @param signal - optional cancellation for adapter-owned capability lookup.
|
|
7190
|
-
* @returns a detached config only when a default must be materialized.
|
|
7191
|
-
*/
|
|
7192
|
-
async resolveCallConfig(config2, signal) {
|
|
7193
|
-
return (await this.resolveCallFor(this.registration(config2.provider), config2, signal)).config;
|
|
7194
|
-
}
|
|
7195
|
-
async resolveCallFor(registration, config2, signal) {
|
|
7196
|
-
const info = await this.resolveModelInfoFor(registration, config2.model, signal);
|
|
7197
|
-
return this.resolveCallWithInfo(config2, info);
|
|
7198
|
-
}
|
|
7199
|
-
/** Validate request controls against one already-bound exact model result. */
|
|
7200
|
-
resolveCallWithInfo(config2, info) {
|
|
7201
|
-
const defaulted = config2.maxTokens === void 0 && info.defaultMaxTokens !== void 0 ? {
|
|
7202
|
-
...config2,
|
|
7203
|
-
maxTokens: info.defaultMaxTokens
|
|
7204
|
-
} : config2;
|
|
7205
|
-
const reasoning = info.reasoning;
|
|
7206
|
-
const requested = defaulted.reasoningEffort;
|
|
7207
|
-
let resolvedConfig = defaulted;
|
|
7208
|
-
if (reasoning === void 0) {
|
|
7209
|
-
if (requested !== void 0) throw new LlmError2(`provider "${config2.provider}" model "${config2.model}" does not support reasoning effort "${requested}"`, "UNSUPPORTED_REASONING_EFFORT");
|
|
7210
|
-
} else {
|
|
7211
|
-
const effective = requested ?? reasoning.defaultEffort;
|
|
7212
|
-
if (effective !== void 0) {
|
|
7213
|
-
if (!reasoning.efforts.some((effort) => effort.id === effective)) throw new LlmError2(`provider "${config2.provider}" model "${config2.model}" does not support reasoning effort "${effective}"`, "UNSUPPORTED_REASONING_EFFORT");
|
|
7214
|
-
if (requested !== effective) resolvedConfig = {
|
|
7215
|
-
...defaulted,
|
|
7216
|
-
reasoningEffort: effective
|
|
7217
|
-
};
|
|
7218
|
-
}
|
|
7219
|
-
}
|
|
7220
|
-
return {
|
|
7221
|
-
config: resolvedConfig,
|
|
7222
|
-
...info.context === void 0 ? {} : { context: info.context },
|
|
7223
|
-
modelInfo: info
|
|
7224
|
-
};
|
|
7225
|
-
}
|
|
7226
|
-
/**
|
|
7227
|
-
* Resolve one call under its current adapter registration. The returned
|
|
7228
|
-
* one-shot handle keeps that registration across header logging and dispatch,
|
|
7229
|
-
* so HMR cannot combine one adapter's capability result with another adapter.
|
|
7230
|
-
* An optional synchronous callback selects concrete controls using captured
|
|
7231
|
-
* model metadata. Defaults and validation apply to its result. Callback
|
|
7232
|
-
* failures and cancellation reject preparation before dispatch.
|
|
7233
|
-
* @param config - provider/model route and optional concrete request controls.
|
|
7234
|
-
* @param signal - optional cancellation for adapter-owned capability lookup.
|
|
7235
|
-
* @param configure - pure control selection, called once before defaults and validation.
|
|
7236
|
-
* @returns a prepared config and its registration-bound stream entry point.
|
|
7237
|
-
*/
|
|
7238
|
-
async prepareCall(config2, signal, configure) {
|
|
7239
|
-
signal?.throwIfAborted();
|
|
7240
|
-
const { provider, model, ...controls } = config2;
|
|
7241
|
-
const registration = this.registration(provider);
|
|
7242
|
-
const adapterCall = await registration.adapter.prepareCall(provider, model, signal);
|
|
7243
|
-
signal?.throwIfAborted();
|
|
7244
|
-
const modelInfo = this.normalizeModelInfo(registration, model, adapterCall.model);
|
|
7245
|
-
const proposed = configure === void 0 ? config2 : {
|
|
7246
|
-
...configure(deepFreeze(structuredClone(controls)), deepFreeze(modelInfo)),
|
|
7247
|
-
provider,
|
|
7248
|
-
model
|
|
7249
|
-
};
|
|
7250
|
-
signal?.throwIfAborted();
|
|
7251
|
-
const resolved = this.resolveCallWithInfo(proposed, modelInfo);
|
|
7252
|
-
const resolvedConfig = deepFreeze(structuredClone(resolved.config));
|
|
7253
|
-
const context = resolved.context === void 0 ? void 0 : deepFreeze(structuredClone(resolved.context));
|
|
7254
|
-
const adapterDefaults = deepFreeze({
|
|
7255
|
-
...proposed.reasoningEffort === void 0 && resolvedConfig.reasoningEffort !== void 0 ? { reasoningEffort: true } : {},
|
|
7256
|
-
...proposed.maxTokens === void 0 && resolvedConfig.maxTokens !== void 0 ? { maxTokens: true } : {}
|
|
7257
|
-
});
|
|
7258
|
-
let dispatched = false;
|
|
7259
|
-
return Object.freeze({
|
|
7260
|
-
config: resolvedConfig,
|
|
7261
|
-
retryPolicy: registration.retryPolicy,
|
|
7262
|
-
adapterDefaults,
|
|
7263
|
-
...context === void 0 ? {} : { context },
|
|
7264
|
-
...modelInfo.inputModalities === void 0 ? {} : { inputModalities: Object.freeze([...modelInfo.inputModalities]) },
|
|
7265
|
-
...modelInfo.systemPromptUpdate === void 0 ? {} : { systemPromptUpdate: modelInfo.systemPromptUpdate },
|
|
7266
|
-
...modelInfo.toolUpdate === void 0 ? {} : { toolUpdate: modelInfo.toolUpdate },
|
|
7267
|
-
stream: (options) => {
|
|
7268
|
-
if (dispatched) throw new LlmError2("a prepared LLM call can only be dispatched once", "INVALID_PREPARED_CALL");
|
|
7269
|
-
if (!callConfigEquals2(options, resolvedConfig)) throw new LlmError2("prepared LLM call config changed before adapter dispatch", "INVALID_PREPARED_CALL");
|
|
7270
|
-
dispatched = true;
|
|
7271
|
-
return this.streamWithRegistration(options, {
|
|
7272
|
-
registration,
|
|
7273
|
-
config: resolvedConfig,
|
|
7274
|
-
modelInfo,
|
|
7275
|
-
dispatch: (options2) => adapterCall.stream(options2)
|
|
7276
|
-
});
|
|
7277
|
-
}
|
|
7278
|
-
});
|
|
7279
|
-
}
|
|
7280
|
-
registration(provider) {
|
|
7281
|
-
const registration = this.adapters.get(provider);
|
|
7282
|
-
if (!registration) throw new LlmError2(`no adapter registered for provider "${provider}"`, "NO_ADAPTER");
|
|
7283
|
-
return registration;
|
|
7284
|
-
}
|
|
7285
|
-
/** Remove replay state whose historical route is owned by another adapter. */
|
|
7286
|
-
forAdapter(options, adapter) {
|
|
7287
|
-
const messages = options.messages.map((message) => {
|
|
7288
|
-
if (message.role !== "assistant") return message;
|
|
7289
|
-
const source = message.source;
|
|
7290
|
-
if (source.replayState === void 0) return message;
|
|
7291
|
-
if (this.adapters.get(source.provider)?.adapter === adapter) return message;
|
|
7292
|
-
return freezeMessage2({
|
|
7293
|
-
...message,
|
|
7294
|
-
source: {
|
|
7295
|
-
kind: "model",
|
|
7296
|
-
provider: source.provider,
|
|
7297
|
-
model: source.model
|
|
7298
|
-
}
|
|
7299
|
-
});
|
|
7300
|
-
});
|
|
7301
|
-
if (messages.every((message, index) => message === options.messages[index])) return options;
|
|
7302
|
-
const filtered = {
|
|
7303
|
-
...options,
|
|
7304
|
-
messages
|
|
7305
|
-
};
|
|
7306
|
-
return Object.isFrozen(options) ? deepFreeze(filtered) : filtered;
|
|
7307
|
-
}
|
|
7308
|
-
/**
|
|
7309
|
-
* Resolve the current execution-world read path of one durable file
|
|
7310
|
-
* reference through the mounted attachment and filesystem providers.
|
|
7311
|
-
*/
|
|
7312
|
-
fileReadPath(ref) {
|
|
7313
|
-
let hostPath;
|
|
7314
|
-
try {
|
|
7315
|
-
hostPath = this.ctx.get("attachments")?.fileHostPath(ref);
|
|
7316
|
-
} catch {
|
|
7317
|
-
return;
|
|
7318
|
-
}
|
|
7319
|
-
if (hostPath === void 0) return void 0;
|
|
7320
|
-
return this.ctx.get("fs")?.processPathFromHostPath(hostPath);
|
|
7321
|
-
}
|
|
7322
|
-
/**
|
|
7323
|
-
* Final adapter boundary. Adapter selection, dispatch, iterator construction,
|
|
7324
|
-
* and iteration failures become one terminal failure chunk. Middleware and
|
|
7325
|
-
* downstream consumer failures remain thrown plugin or consumer errors.
|
|
7326
|
-
*/
|
|
7327
|
-
async *adapterStream(options, prepared) {
|
|
7328
|
-
let iterator;
|
|
7329
|
-
try {
|
|
7330
|
-
const registration = prepared?.registration ?? this.registration(options.provider);
|
|
7331
|
-
const adapter = registration.adapter;
|
|
7332
|
-
let modelInfo;
|
|
7333
|
-
let resolvedConfig;
|
|
7334
|
-
let dispatch;
|
|
7335
|
-
if (prepared === void 0) {
|
|
7336
|
-
const adapterCall = await adapter.prepareCall(options.provider, options.model, options.signal);
|
|
7337
|
-
modelInfo = this.normalizeModelInfo(registration, options.model, adapterCall.model);
|
|
7338
|
-
resolvedConfig = this.resolveCallWithInfo(options, modelInfo).config;
|
|
7339
|
-
dispatch = (options2) => adapterCall.stream(options2);
|
|
7340
|
-
} else {
|
|
7341
|
-
modelInfo = prepared.modelInfo;
|
|
7342
|
-
resolvedConfig = prepared.config;
|
|
7343
|
-
dispatch = prepared.dispatch;
|
|
7344
|
-
}
|
|
7345
|
-
if (prepared !== void 0 && !callConfigEquals2(options, resolvedConfig)) throw new LlmError2("prepared LLM call config changed before adapter dispatch", "INVALID_PREPARED_CALL");
|
|
7346
|
-
const resolvedOptions = callConfigEquals2(options, resolvedConfig) ? options : Object.isFrozen(options) ? deepFreeze({
|
|
7347
|
-
...options,
|
|
7348
|
-
...resolvedConfig
|
|
7349
|
-
}) : {
|
|
7350
|
-
...options,
|
|
7351
|
-
...resolvedConfig
|
|
7352
|
-
};
|
|
7353
|
-
let projectedMessages = resolvedOptions.messages;
|
|
7354
|
-
if (projectedMessages.some((message) => contentHasFile2(message.content))) projectedMessages = projectFilesToText2(projectedMessages, (ref) => this.fileReadPath(ref));
|
|
7355
|
-
if (modelInfo.inputModalities !== void 0 && !modelInfo.inputModalities.includes("image") && projectedMessages.some((message) => contentHasImage2(message.content))) projectedMessages = projectImagesForTextModel2(projectedMessages);
|
|
7356
|
-
const projectedTools = projectToolUpdates2(projectedMessages, resolvedOptions.tools, modelInfo.toolUpdate, resolvedOptions.toolHistory);
|
|
7357
|
-
projectedMessages = projectedTools.messages;
|
|
7358
|
-
let projectedOptions = resolvedOptions;
|
|
7359
|
-
if (projectedMessages !== resolvedOptions.messages || projectedTools.tools !== resolvedOptions.tools) {
|
|
7360
|
-
projectedOptions = {
|
|
7361
|
-
...resolvedOptions,
|
|
7362
|
-
messages: projectedMessages,
|
|
7363
|
-
...projectedTools.tools === void 0 ? {} : { tools: projectedTools.tools }
|
|
7364
|
-
};
|
|
7365
|
-
if (Object.isFrozen(resolvedOptions)) deepFreeze(projectedOptions);
|
|
7366
|
-
}
|
|
7367
|
-
iterator = dispatch(this.forAdapter(projectedOptions, adapter))[Symbol.asyncIterator]();
|
|
7368
|
-
} catch (error51) {
|
|
7369
|
-
yield adapterFailureChunk2(error51, options.signal);
|
|
7370
|
-
return;
|
|
7371
|
-
}
|
|
7372
|
-
let completed = false;
|
|
7373
|
-
try {
|
|
7374
|
-
while (true) {
|
|
7375
|
-
let item;
|
|
7376
|
-
try {
|
|
7377
|
-
const next = await iterator.next();
|
|
7378
|
-
item = next.done ? { done: true } : {
|
|
7379
|
-
done: false,
|
|
7380
|
-
value: next.value
|
|
7381
|
-
};
|
|
7382
|
-
} catch (error51) {
|
|
7383
|
-
completed = true;
|
|
7384
|
-
yield adapterFailureChunk2(error51, options.signal);
|
|
7385
|
-
return;
|
|
7386
|
-
}
|
|
7387
|
-
if (item.done) {
|
|
7388
|
-
completed = true;
|
|
7389
|
-
return;
|
|
7390
|
-
}
|
|
7391
|
-
yield item.value;
|
|
7392
|
-
}
|
|
7393
|
-
} finally {
|
|
7394
|
-
if (!completed) {
|
|
7395
|
-
const close = iterator.return?.bind(iterator);
|
|
7396
|
-
if (close) await close();
|
|
7397
|
-
}
|
|
7398
|
-
}
|
|
7399
|
-
}
|
|
7400
|
-
/**
|
|
7401
|
-
* Stream one model call as raw chunks (token-level deltas). Replay state is
|
|
7402
|
-
* retained only when the same adapter instance owns its historical provider
|
|
7403
|
-
* and the target provider. Final adapter selection remains fixed through
|
|
7404
|
-
* asynchronous exact-model resolution and dispatch. Adapter selection,
|
|
7405
|
-
* dispatch, and iteration failures become terminal `error` or `aborted`
|
|
7406
|
-
* finish chunks; middleware, nested-call, cleanup, and consumer failures
|
|
7407
|
-
* remain thrown.
|
|
7408
|
-
* @param options - the full request; `options.provider` selects the adapter.
|
|
7409
|
-
* @returns the chunk stream, possibly wrapped by `llm/stream` listeners.
|
|
7410
|
-
*/
|
|
7411
|
-
stream(options) {
|
|
7412
|
-
return this.streamWithRegistration(options);
|
|
7413
|
-
}
|
|
7414
|
-
streamWithRegistration(options, prepared) {
|
|
7415
|
-
return this.ctx.waterfall(this, "llm/stream", options, () => this.adapterStream(options, prepared));
|
|
7416
|
-
}
|
|
7417
|
-
};
|
|
7418
|
-
})();
|
|
7419
|
-
function adapterFailureChunk2(error51, signal) {
|
|
7420
|
-
const failure = normalizeLlmFailure2(error51);
|
|
7421
|
-
return {
|
|
7422
|
-
type: "finish",
|
|
7423
|
-
reason: signal?.aborted || failure.code === "ABORTED" ? {
|
|
7424
|
-
kind: "aborted",
|
|
7425
|
-
failure
|
|
7426
|
-
} : {
|
|
7427
|
-
kind: "error",
|
|
7428
|
-
failure
|
|
7429
|
-
}
|
|
7430
|
-
};
|
|
7431
|
-
}
|
|
7432
|
-
|
|
7433
6452
|
// packages/core/session/src/index.ts
|
|
7434
6453
|
import { isAbsolute } from "node:path";
|
|
7435
6454
|
|
|
@@ -9164,7 +8183,7 @@ __export(core_exports2, {
|
|
|
9164
8183
|
toJSONSchema: () => toJSONSchema,
|
|
9165
8184
|
treeifyError: () => treeifyError,
|
|
9166
8185
|
util: () => util_exports,
|
|
9167
|
-
version: () =>
|
|
8186
|
+
version: () => version2
|
|
9168
8187
|
});
|
|
9169
8188
|
|
|
9170
8189
|
// node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/core.js
|
|
@@ -10239,10 +9258,10 @@ var nanoid = /^[a-zA-Z0-9_-]{21}$/;
|
|
|
10239
9258
|
var duration = /^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;
|
|
10240
9259
|
var extendedDuration = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/;
|
|
10241
9260
|
var guid = /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/;
|
|
10242
|
-
var uuid = (
|
|
10243
|
-
if (!
|
|
9261
|
+
var uuid = (version3) => {
|
|
9262
|
+
if (!version3)
|
|
10244
9263
|
return /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/;
|
|
10245
|
-
return new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${
|
|
9264
|
+
return new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${version3}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`);
|
|
10246
9265
|
};
|
|
10247
9266
|
var uuid4 = /* @__PURE__ */ uuid(4);
|
|
10248
9267
|
var uuid6 = /* @__PURE__ */ uuid(6);
|
|
@@ -10911,7 +9930,7 @@ var Doc = class {
|
|
|
10911
9930
|
};
|
|
10912
9931
|
|
|
10913
9932
|
// node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/versions.js
|
|
10914
|
-
var
|
|
9933
|
+
var version2 = {
|
|
10915
9934
|
major: 4,
|
|
10916
9935
|
minor: 4,
|
|
10917
9936
|
patch: 3
|
|
@@ -10923,7 +9942,7 @@ var $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
|
|
|
10923
9942
|
inst ?? (inst = {});
|
|
10924
9943
|
inst._zod.def = def;
|
|
10925
9944
|
inst._zod.bag = inst._zod.bag || {};
|
|
10926
|
-
inst._zod.version =
|
|
9945
|
+
inst._zod.version = version2;
|
|
10927
9946
|
const checks = [...inst._zod.def.checks ?? []];
|
|
10928
9947
|
if (inst._zod.traits.has("$ZodCheck")) {
|
|
10929
9948
|
checks.unshift(inst);
|
|
@@ -23118,10 +22137,10 @@ function fromJSONSchema(schema, params) {
|
|
|
23118
22137
|
} catch {
|
|
23119
22138
|
throw new Error("fromJSONSchema input is not valid JSON (possibly cyclic); use $defs/$ref for recursive schemas");
|
|
23120
22139
|
}
|
|
23121
|
-
const
|
|
22140
|
+
const version3 = detectVersion(normalized, params?.defaultTarget);
|
|
23122
22141
|
const defs = normalized.$defs || normalized.definitions || {};
|
|
23123
22142
|
const ctx = {
|
|
23124
|
-
version:
|
|
22143
|
+
version: version3,
|
|
23125
22144
|
defs,
|
|
23126
22145
|
refs: /* @__PURE__ */ new Map(),
|
|
23127
22146
|
processing: /* @__PURE__ */ new Set(),
|
|
@@ -23758,36 +22777,15 @@ var SessionTitleService = class extends Service {
|
|
|
23758
22777
|
}
|
|
23759
22778
|
};
|
|
23760
22779
|
|
|
23761
|
-
// packages/session-query/session-query/
|
|
22780
|
+
// packages/session-query/session-query/src/config.ts
|
|
23762
22781
|
var SessionQueryError = class extends HarnessError {
|
|
22782
|
+
// The base stores the value; this signature narrows its open string code.
|
|
22783
|
+
// oxlint-disable-next-line typescript/no-useless-constructor
|
|
23763
22784
|
constructor(message, code, options) {
|
|
23764
22785
|
super(message, code, options);
|
|
23765
22786
|
}
|
|
23766
22787
|
};
|
|
23767
22788
|
|
|
23768
|
-
// packages/typert/protocol/lib/index.js
|
|
23769
|
-
var RemoteError2 = class extends Error {
|
|
23770
|
-
code;
|
|
23771
|
-
details;
|
|
23772
|
-
/** Structural marker: cross-realm/bundle identification never uses instanceof. */
|
|
23773
|
-
isDSHRemoteError = true;
|
|
23774
|
-
/**
|
|
23775
|
-
* @param code - stable failure code declared in {@link RemoteErrorDetailsMap}.
|
|
23776
|
-
* @param message - human diagnostic carried across the wire.
|
|
23777
|
-
* @param details - structured payload typed by the code.
|
|
23778
|
-
* @param options - standard Error options (`cause` survives in-process only).
|
|
23779
|
-
*/
|
|
23780
|
-
constructor(code, message, details, options) {
|
|
23781
|
-
super(message, options);
|
|
23782
|
-
this.code = code;
|
|
23783
|
-
this.details = details;
|
|
23784
|
-
this.name = "RemoteError";
|
|
23785
|
-
}
|
|
23786
|
-
};
|
|
23787
|
-
function remoteErrorOf2(value) {
|
|
23788
|
-
if (typeof value === "object" && value !== null && value.isDSHRemoteError === true && typeof value.code === "string") return value;
|
|
23789
|
-
}
|
|
23790
|
-
|
|
23791
22789
|
// packages/api/session-controller/src/agent.ts
|
|
23792
22790
|
var ApiSessionNotFound = class extends Error {
|
|
23793
22791
|
};
|
|
@@ -23831,7 +22829,7 @@ function hasApiSessionSubagentOwner(ctx, session, agent) {
|
|
|
23831
22829
|
return parent !== void 0 && ctx.agents.isOwnedBy(agent.id, parent);
|
|
23832
22830
|
}
|
|
23833
22831
|
function apiSessionSubagentOwnershipError(sessionId) {
|
|
23834
|
-
return new
|
|
22832
|
+
return new RemoteError(
|
|
23835
22833
|
"session/agent-busy",
|
|
23836
22834
|
`session "${sessionId}" is owned by subagent routing`,
|
|
23837
22835
|
{ reason: "use subagent delivery for this child session" }
|
|
@@ -23898,7 +22896,7 @@ var ApiSessionAgentController = class {
|
|
|
23898
22896
|
return published ?? { agent };
|
|
23899
22897
|
} catch (error51) {
|
|
23900
22898
|
if (error51 instanceof ApiSessionNotFound) {
|
|
23901
|
-
return { error: new
|
|
22899
|
+
return { error: new RemoteError("session/not-found", error51.message, { sessionId }) };
|
|
23902
22900
|
}
|
|
23903
22901
|
if (error51 instanceof ApiSessionSubagentOwnership) {
|
|
23904
22902
|
return { error: apiSessionSubagentOwnershipError(error51.sessionId) };
|
|
@@ -23910,10 +22908,10 @@ var ApiSessionAgentController = class {
|
|
|
23910
22908
|
return { error: apiSessionSubagentOwnershipError(sessionId) };
|
|
23911
22909
|
}
|
|
23912
22910
|
if (error51 instanceof Error && error51.name === "SessionAlreadyOwnedError") {
|
|
23913
|
-
return { error: new
|
|
22911
|
+
return { error: new RemoteError("session/writer-held", error51.message, { sessionId }) };
|
|
23914
22912
|
}
|
|
23915
22913
|
return {
|
|
23916
|
-
error: new
|
|
22914
|
+
error: new RemoteError(
|
|
23917
22915
|
"gateway/internal",
|
|
23918
22916
|
`resume failed for session "${sessionId}": ${String(error51)}`,
|
|
23919
22917
|
{}
|
|
@@ -24163,7 +23161,7 @@ var ApiSessionAgentController = class {
|
|
|
24163
23161
|
try {
|
|
24164
23162
|
await presets.select(live, target);
|
|
24165
23163
|
} catch (error51) {
|
|
24166
|
-
if (
|
|
23164
|
+
if (remoteErrorOf(error51)?.code !== "agent-preset/locked") throw error51;
|
|
24167
23165
|
return void 0;
|
|
24168
23166
|
}
|
|
24169
23167
|
return live;
|
|
@@ -24194,7 +23192,7 @@ var ApiSessionAgentController = class {
|
|
|
24194
23192
|
return { agent, agentPreset: this.presetForSession(agent.session) };
|
|
24195
23193
|
}
|
|
24196
23194
|
createMinted(cwd, composition) {
|
|
24197
|
-
return this.createAgent(
|
|
23195
|
+
return this.createAgent(brandString(`session-${randomUUID2()}`), cwd, composition);
|
|
24198
23196
|
}
|
|
24199
23197
|
async createAgent(sessionId, cwd, composition) {
|
|
24200
23198
|
try {
|
|
@@ -24235,7 +23233,7 @@ function agentModelSelection(selection) {
|
|
|
24235
23233
|
return {
|
|
24236
23234
|
provider: selection.provider,
|
|
24237
23235
|
model: selection.model,
|
|
24238
|
-
...selection.reasoningEffort === void 0 ? {} : { reasoningEffort:
|
|
23236
|
+
...selection.reasoningEffort === void 0 ? {} : { reasoningEffort: ReasoningEffortId(selection.reasoningEffort) }
|
|
24239
23237
|
};
|
|
24240
23238
|
}
|
|
24241
23239
|
|
|
@@ -26193,7 +25191,7 @@ var ToolOutputError = class extends HarnessError {
|
|
|
26193
25191
|
}
|
|
26194
25192
|
};
|
|
26195
25193
|
function projectionError(toolName, projector, error51) {
|
|
26196
|
-
return new ToolOutputError(toolName, [`output.${projector} failed: ${
|
|
25194
|
+
return new ToolOutputError(toolName, [`output.${projector} failed: ${errorMessage2(error51)}`]);
|
|
26197
25195
|
}
|
|
26198
25196
|
function snapshotProjection(toolName, projector, candidate) {
|
|
26199
25197
|
try {
|
|
@@ -26214,10 +25212,10 @@ function snapshotToolValue(toolName, candidate) {
|
|
|
26214
25212
|
return detached;
|
|
26215
25213
|
} catch (error51) {
|
|
26216
25214
|
if (error51 instanceof ToolOutputError) throw error51;
|
|
26217
|
-
throw new ToolOutputError(toolName, [`value snapshot failed: ${
|
|
25215
|
+
throw new ToolOutputError(toolName, [`value snapshot failed: ${errorMessage2(error51)}`]);
|
|
26218
25216
|
}
|
|
26219
25217
|
}
|
|
26220
|
-
function
|
|
25218
|
+
function errorMessage2(error51) {
|
|
26221
25219
|
try {
|
|
26222
25220
|
if (error51 instanceof Error) return error51.message;
|
|
26223
25221
|
if (typeof error51 === "object" && error51 !== null && "message" in error51 && typeof error51.message === "string") {
|
|
@@ -26754,7 +25752,7 @@ var ToolRuntime = class extends Service {
|
|
|
26754
25752
|
() => Promise.resolve(dispatch.content)
|
|
26755
25753
|
);
|
|
26756
25754
|
} catch (error51) {
|
|
26757
|
-
this.ctx.logger.warn(`tools: ptc-dispatch-log listener failed for ${dispatch.name}: ${
|
|
25755
|
+
this.ctx.logger.warn(`tools: ptc-dispatch-log listener failed for ${dispatch.name}: ${errorMessage2(error51)}; logging the original settled content`);
|
|
26758
25756
|
return dispatch.content;
|
|
26759
25757
|
}
|
|
26760
25758
|
}
|
|
@@ -27062,7 +26060,7 @@ var ToolRuntime = class extends Service {
|
|
|
27062
26060
|
Object.freeze(exec);
|
|
27063
26061
|
const { name: toolName, callId } = exec;
|
|
27064
26062
|
const reportFailure = (error51) => {
|
|
27065
|
-
this.ctx.logger.warn(`tool "${toolName}" (${callId}): tools/result observer failed: ${
|
|
26063
|
+
this.ctx.logger.warn(`tool "${toolName}" (${callId}): tools/result observer failed: ${errorMessage2(error51)}`);
|
|
27066
26064
|
};
|
|
27067
26065
|
const callbacks = this.ctx.events.dispatch("emit", [
|
|
27068
26066
|
scopeTarget(this, exec.agent),
|
|
@@ -27270,7 +26268,7 @@ function createExecutionToken() {
|
|
|
27270
26268
|
}
|
|
27271
26269
|
function toolErrorResult(error51) {
|
|
27272
26270
|
const info = errorInfo(error51);
|
|
27273
|
-
const message =
|
|
26271
|
+
const message = errorMessage2(error51);
|
|
27274
26272
|
return {
|
|
27275
26273
|
content: [{ type: "text", text: `Error: ${message}` }],
|
|
27276
26274
|
isError: true,
|
|
@@ -27487,62 +26485,6 @@ function assertSubagentMaxDepth(maxDepth) {
|
|
|
27487
26485
|
// packages/subagent/subagent/src/lifecycle.ts
|
|
27488
26486
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
27489
26487
|
|
|
27490
|
-
// packages/core/agent/src/consumed-work.ts
|
|
27491
|
-
function accountsForClaim(reason) {
|
|
27492
|
-
switch (reason.kind) {
|
|
27493
|
-
case "completed":
|
|
27494
|
-
return false;
|
|
27495
|
-
case "blocked":
|
|
27496
|
-
case "aborted":
|
|
27497
|
-
case "interrupted":
|
|
27498
|
-
case "error":
|
|
27499
|
-
return true;
|
|
27500
|
-
/* v8 ignore next 5 -- unreachable: `max-tokens` requires a step and short-circuits
|
|
27501
|
-
* before this call; `forked` exists only in constructor seed history, while production
|
|
27502
|
-
* callers fold an operation-owned suffix. `TurnEndReasonMap` is merge-extensible, so a
|
|
27503
|
-
* backend-added variant cannot be listed; an unnameable ending over consumed input must
|
|
27504
|
-
* not read as success. */
|
|
27505
|
-
default:
|
|
27506
|
-
return true;
|
|
27507
|
-
}
|
|
27508
|
-
}
|
|
27509
|
-
function foldConsumedWork(events) {
|
|
27510
|
-
const stepped = /* @__PURE__ */ new Set();
|
|
27511
|
-
const claimed = /* @__PURE__ */ new Set();
|
|
27512
|
-
let open;
|
|
27513
|
-
let end;
|
|
27514
|
-
let droppedUnrun = false;
|
|
27515
|
-
for (const event of events) {
|
|
27516
|
-
switch (event.type) {
|
|
27517
|
-
case "turn/start":
|
|
27518
|
-
open = event.data.turn;
|
|
27519
|
-
break;
|
|
27520
|
-
case "step/start":
|
|
27521
|
-
stepped.add(event.data.turn);
|
|
27522
|
-
break;
|
|
27523
|
-
case "agent/inbox/spliced": {
|
|
27524
|
-
const { removedCount, outcome, inserted } = event.data;
|
|
27525
|
-
if (removedCount === void 0) break;
|
|
27526
|
-
if (outcome === "canceled") droppedUnrun ||= inserted.length === 0;
|
|
27527
|
-
else if (open !== void 0) claimed.add(open);
|
|
27528
|
-
break;
|
|
27529
|
-
}
|
|
27530
|
-
case "turn/end": {
|
|
27531
|
-
const { turn, reason } = event.data;
|
|
27532
|
-
open = void 0;
|
|
27533
|
-
if (stepped.delete(turn) || claimed.delete(turn) && accountsForClaim(reason)) {
|
|
27534
|
-
end = event;
|
|
27535
|
-
droppedUnrun = false;
|
|
27536
|
-
}
|
|
27537
|
-
break;
|
|
27538
|
-
}
|
|
27539
|
-
default:
|
|
27540
|
-
break;
|
|
27541
|
-
}
|
|
27542
|
-
}
|
|
27543
|
-
return { ...end === void 0 ? {} : { end }, droppedUnrun };
|
|
27544
|
-
}
|
|
27545
|
-
|
|
27546
26488
|
// packages/subagent/subagent/src/types.ts
|
|
27547
26489
|
function SubagentRunId(id) {
|
|
27548
26490
|
return id;
|
|
@@ -27874,11 +26816,11 @@ function parseSubagentDescriptor(value) {
|
|
|
27874
26816
|
if (!isRecord2(value)) {
|
|
27875
26817
|
throw new Error("persisted subagent descriptor payload must be an object");
|
|
27876
26818
|
}
|
|
27877
|
-
const
|
|
27878
|
-
if (typeof
|
|
26819
|
+
const version3 = value["version"];
|
|
26820
|
+
if (typeof version3 !== "number") {
|
|
27879
26821
|
throw new Error("persisted subagent descriptor version must be a number");
|
|
27880
26822
|
}
|
|
27881
|
-
if (
|
|
26823
|
+
if (version3 !== SUBAGENT_DESCRIPTOR_VERSION) return void 0;
|
|
27882
26824
|
const mode = value["mode"];
|
|
27883
26825
|
if (mode !== "one-shot" && mode !== "continuable") {
|
|
27884
26826
|
throw new Error('persisted subagent descriptor mode must be "one-shot" or "continuable"');
|