@deepseek-ai/dsh-session-persistence-jsonl 0.2.1-rc.5 → 0.2.2-alpha.3
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.i18n.yaml +2 -2
- package/README.md +1 -1
- package/README.zh.md +1 -1
- package/lib/index.js +12 -4
- package/lib/types/zstd.d.ts +1 -1
- package/lib/worker.cjs +1049 -920
- package/locale/de.json +6 -0
- package/locale/es.json +6 -0
- package/locale/fr.json +6 -0
- package/locale/ja.json +6 -0
- package/locale/pt.json +6 -0
- package/locale/ru.json +6 -0
- package/package.json +13 -13
package/lib/worker.cjs
CHANGED
|
@@ -680,110 +680,95 @@ function enumerableStringKeys(value) {
|
|
|
680
680
|
function walkJsonValue(value, detach) {
|
|
681
681
|
const ancestors = /* @__PURE__ */ new Set();
|
|
682
682
|
let root;
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
if (
|
|
686
|
-
|
|
687
|
-
else
|
|
683
|
+
let parent;
|
|
684
|
+
const assign = (item) => {
|
|
685
|
+
if (parent === void 0) {
|
|
686
|
+
if (detach) root = item;
|
|
687
|
+
} else if (parent.kind === "array") {
|
|
688
|
+
if (parent.target !== void 0) parent.target[parent.key] = item;
|
|
689
|
+
} else if (parent.target !== void 0) Object.defineProperty(parent.target, parent.key, {
|
|
688
690
|
value: item,
|
|
689
691
|
enumerable: true,
|
|
690
692
|
configurable: true,
|
|
691
693
|
writable: true
|
|
692
694
|
});
|
|
693
695
|
};
|
|
694
|
-
const
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
if (
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
696
|
+
const frames = [];
|
|
697
|
+
let current = value;
|
|
698
|
+
for (;;) {
|
|
699
|
+
if (current === null) assign(null);
|
|
700
|
+
else if (typeof current === "boolean" || typeof current === "string") assign(current);
|
|
701
|
+
else if (typeof current === "number") {
|
|
702
|
+
if (!Number.isFinite(current) || Object.is(current, -0)) return void 0;
|
|
703
|
+
assign(current);
|
|
704
|
+
} else {
|
|
705
|
+
if (typeof current !== "object") return void 0;
|
|
706
|
+
if (ancestors.has(current)) return void 0;
|
|
707
|
+
if (Array.isArray(current)) {
|
|
708
|
+
if (!hasPlainArrayPrototype(current)) return void 0;
|
|
709
|
+
const length = current.length;
|
|
710
|
+
if (Reflect.ownKeys(current).length !== length + 1) return void 0;
|
|
711
|
+
const target = detach ? [] : void 0;
|
|
712
|
+
if (target !== void 0) assign(target);
|
|
713
|
+
let indices;
|
|
714
|
+
if (!Number.isInteger(length)) {
|
|
715
|
+
indices = [];
|
|
716
|
+
for (let index = length - 1; index >= 0; index--) indices.push(index);
|
|
717
|
+
}
|
|
718
|
+
frames.push({
|
|
710
719
|
kind: "array",
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
720
|
+
source: current,
|
|
721
|
+
length: indices?.length ?? length,
|
|
722
|
+
index: 0,
|
|
723
|
+
key: 0,
|
|
724
|
+
indices,
|
|
725
|
+
target
|
|
726
|
+
});
|
|
727
|
+
} else {
|
|
728
|
+
if (!hasPlainObjectPrototype(current)) return void 0;
|
|
729
|
+
const keys = enumerableStringKeys(current);
|
|
730
|
+
if (keys === void 0) return void 0;
|
|
731
|
+
const target = detach ? {} : void 0;
|
|
732
|
+
if (target !== void 0) assign(target);
|
|
733
|
+
frames.push({
|
|
722
734
|
kind: "object",
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
if (current === null) {
|
|
731
|
-
assign(task.destination, null);
|
|
732
|
-
continue;
|
|
733
|
-
}
|
|
734
|
-
if (typeof current === "boolean" || typeof current === "string") {
|
|
735
|
-
assign(task.destination, current);
|
|
736
|
-
continue;
|
|
737
|
-
}
|
|
738
|
-
if (typeof current === "number") {
|
|
739
|
-
if (!Number.isFinite(current) || Object.is(current, -0)) return void 0;
|
|
740
|
-
assign(task.destination, current);
|
|
741
|
-
continue;
|
|
742
|
-
}
|
|
743
|
-
if (typeof current !== "object") return void 0;
|
|
744
|
-
if (ancestors.has(current)) return void 0;
|
|
745
|
-
if (Array.isArray(current)) {
|
|
746
|
-
if (!hasPlainArrayPrototype(current)) return void 0;
|
|
747
|
-
const length = current.length;
|
|
748
|
-
if (Reflect.ownKeys(current).length !== length + 1) return void 0;
|
|
749
|
-
const target = detach ? [] : void 0;
|
|
750
|
-
if (target !== void 0) assign(task.destination, target);
|
|
735
|
+
source: current,
|
|
736
|
+
keys,
|
|
737
|
+
index: 0,
|
|
738
|
+
key: "",
|
|
739
|
+
target
|
|
740
|
+
});
|
|
741
|
+
}
|
|
751
742
|
ancestors.add(current);
|
|
752
|
-
tasks.push({
|
|
753
|
-
kind: "leave",
|
|
754
|
-
source: current
|
|
755
|
-
});
|
|
756
|
-
for (let index = length - 1; index >= 0; index--) tasks.push({
|
|
757
|
-
kind: "array-item",
|
|
758
|
-
source: current,
|
|
759
|
-
index,
|
|
760
|
-
...target === void 0 ? {} : { target }
|
|
761
|
-
});
|
|
762
|
-
continue;
|
|
763
743
|
}
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
key
|
|
782
|
-
|
|
783
|
-
|
|
744
|
+
for (;;) {
|
|
745
|
+
const frame = frames.at(-1);
|
|
746
|
+
if (frame === void 0) return detach ? root : true;
|
|
747
|
+
const length = frame.kind === "array" ? frame.length : frame.keys.length;
|
|
748
|
+
if (frame.index >= length) {
|
|
749
|
+
ancestors.delete(frame.source);
|
|
750
|
+
frames.pop();
|
|
751
|
+
continue;
|
|
752
|
+
}
|
|
753
|
+
const index = frame.index++;
|
|
754
|
+
parent = frame;
|
|
755
|
+
if (frame.kind === "array") {
|
|
756
|
+
const key = frame.indices === void 0 ? index : frame.indices[frame.indices.length - index - 1];
|
|
757
|
+
/* v8 ignore next -- the loop is bounded by the captured index count. */
|
|
758
|
+
if (key === void 0) return void 0;
|
|
759
|
+
if (!Object.prototype.hasOwnProperty.call(frame.source, key)) return void 0;
|
|
760
|
+
frame.key = key;
|
|
761
|
+
current = frame.source[key];
|
|
762
|
+
} else {
|
|
763
|
+
const key = frame.keys[index];
|
|
764
|
+
/* v8 ignore next -- the loop is bounded by the captured key count. */
|
|
765
|
+
if (key === void 0) return void 0;
|
|
766
|
+
frame.key = key;
|
|
767
|
+
current = frame.source[key];
|
|
768
|
+
}
|
|
769
|
+
break;
|
|
784
770
|
}
|
|
785
771
|
}
|
|
786
|
-
return detach ? root : true;
|
|
787
772
|
}
|
|
788
773
|
/**
|
|
789
774
|
* Validate and detach lossless JSON in one read per property.
|
|
@@ -1275,6 +1260,7 @@ var DisposableList = class {
|
|
|
1275
1260
|
/** Shared symbols used to avoid public property-name collisions. */
|
|
1276
1261
|
const symbols = {
|
|
1277
1262
|
shadow: Symbol.for("cordis.shadow"),
|
|
1263
|
+
caller: Symbol.for("cordis.caller"),
|
|
1278
1264
|
receiver: Symbol.for("cordis.receiver"),
|
|
1279
1265
|
original: Symbol.for("cordis.original"),
|
|
1280
1266
|
metadata: Symbol.for("cordis.metadata"),
|
|
@@ -1349,11 +1335,12 @@ function withProp(target, prop, value) {
|
|
|
1349
1335
|
writable: false
|
|
1350
1336
|
}));
|
|
1351
1337
|
}
|
|
1352
|
-
function createShadow(
|
|
1338
|
+
function createShadow(useSite, target, property, receiver) {
|
|
1353
1339
|
if (!property) return receiver;
|
|
1354
|
-
const
|
|
1355
|
-
if (!
|
|
1356
|
-
|
|
1340
|
+
const value = getPropertyDescriptor(target, property)?.value;
|
|
1341
|
+
if (!value) return receiver;
|
|
1342
|
+
const defSite = value[symbols.shadow] ?? value;
|
|
1343
|
+
return withProp(receiver, property, useSite.extend({ [symbols.shadow]: defSite }));
|
|
1357
1344
|
}
|
|
1358
1345
|
function createShadowMethod(ctx, value, outer, shadow) {
|
|
1359
1346
|
return new Proxy(value, { apply: (target, thisArg, args) => {
|
|
@@ -1362,37 +1349,40 @@ function createShadowMethod(ctx, value, outer, shadow) {
|
|
|
1362
1349
|
} });
|
|
1363
1350
|
}
|
|
1364
1351
|
function createTraceable(ctx, value, tracker) {
|
|
1365
|
-
|
|
1352
|
+
const defSite = ctx[symbols.shadow] ?? ctx;
|
|
1353
|
+
const useSite = ctx[symbols.shadow] ? Object.getPrototypeOf(ctx) : ctx;
|
|
1366
1354
|
const proxy = new Proxy(value, {
|
|
1367
1355
|
get: (target, prop, receiver) => {
|
|
1368
1356
|
if (prop === symbols.original) return target;
|
|
1369
|
-
if (prop ===
|
|
1357
|
+
if (prop === symbols.caller) return defSite;
|
|
1358
|
+
if (prop === tracker.property) return useSite;
|
|
1370
1359
|
if (typeof prop === "symbol") return Reflect.get(target, prop, receiver);
|
|
1371
|
-
if (tracker.associate &&
|
|
1360
|
+
if (tracker.associate && useSite.reflect.props[`${tracker.associate}.${prop}`]) return Reflect.get(ctx, `${tracker.associate}.${prop}`, withProp(ctx, symbols.receiver, receiver));
|
|
1372
1361
|
let shadow, innerValue;
|
|
1373
1362
|
const desc = getPropertyDescriptor(target, prop);
|
|
1374
1363
|
if (desc && "value" in desc) innerValue = desc.value;
|
|
1375
1364
|
else {
|
|
1376
|
-
shadow = createShadow(
|
|
1365
|
+
shadow = createShadow(useSite, target, tracker.property, receiver);
|
|
1377
1366
|
innerValue = Reflect.get(target, prop, shadow);
|
|
1378
1367
|
}
|
|
1379
1368
|
const innerTracker = innerValue?.[symbols.tracker];
|
|
1380
|
-
if (innerTracker) return createTraceable(
|
|
1369
|
+
if (innerTracker) return createTraceable(useSite, innerValue, innerTracker);
|
|
1381
1370
|
else if (!tracker.noShadow && typeof innerValue === "function") {
|
|
1382
|
-
shadow ??= createShadow(
|
|
1383
|
-
return createShadowMethod(
|
|
1371
|
+
shadow ??= createShadow(useSite, target, tracker.property, receiver);
|
|
1372
|
+
return createShadowMethod(useSite, innerValue, receiver, shadow);
|
|
1384
1373
|
} else return innerValue;
|
|
1385
1374
|
},
|
|
1386
1375
|
set: (target, prop, value, receiver) => {
|
|
1387
1376
|
if (prop === symbols.original) return false;
|
|
1377
|
+
if (prop === symbols.caller) return false;
|
|
1388
1378
|
if (prop === tracker.property) return false;
|
|
1389
1379
|
if (typeof prop === "symbol") return Reflect.set(target, prop, value, receiver);
|
|
1390
|
-
if (tracker.associate &&
|
|
1391
|
-
const shadow = createShadow(
|
|
1380
|
+
if (tracker.associate && useSite.reflect.props[`${tracker.associate}.${prop}`]) return Reflect.set(ctx, `${tracker.associate}.${prop}`, value, withProp(ctx, symbols.receiver, receiver));
|
|
1381
|
+
const shadow = createShadow(useSite, target, tracker.property, receiver);
|
|
1392
1382
|
return Reflect.set(target, prop, value, shadow);
|
|
1393
1383
|
},
|
|
1394
1384
|
apply: (target, thisArg, args) => {
|
|
1395
|
-
return applyTraceable(proxy, target, thisArg, args);
|
|
1385
|
+
return applyTraceable(tracker.noShadow ? proxy : createShadow(useSite, target, tracker.property, proxy), target, thisArg, args);
|
|
1396
1386
|
}
|
|
1397
1387
|
});
|
|
1398
1388
|
return proxy;
|
|
@@ -1404,7 +1394,8 @@ function applyTraceable(proxy, value, thisArg, args) {
|
|
|
1404
1394
|
/** Create a callable service object that dispatches through `symbols.invoke`. */
|
|
1405
1395
|
function createCallable(name, proto, tracker) {
|
|
1406
1396
|
const self = function(...args) {
|
|
1407
|
-
|
|
1397
|
+
const proxy = createTraceable(self["ctx"], self, tracker);
|
|
1398
|
+
return Reflect.apply(proxy, this, args);
|
|
1408
1399
|
};
|
|
1409
1400
|
defineProperty(self, "name", name);
|
|
1410
1401
|
return Object.setPrototypeOf(self, proto);
|
|
@@ -1450,649 +1441,215 @@ function buildOuterStack(offset = 0) {
|
|
|
1450
1441
|
return () => outerError.stack.split("\n").slice(3 + offset);
|
|
1451
1442
|
}
|
|
1452
1443
|
//#endregion
|
|
1453
|
-
//#region ../../../vendor/cordis/src/
|
|
1444
|
+
//#region ../../../vendor/cordis/src/fiber.ts
|
|
1445
|
+
const kValidationError$1 = Symbol.for("ValidationError");
|
|
1446
|
+
/** Error raised when plugin configuration fails standard-schema validation. */
|
|
1447
|
+
var ValidationError$1 = class extends TypeError {
|
|
1448
|
+
name = "ValidationError";
|
|
1449
|
+
/**
|
|
1450
|
+
* Build the aggregated message from schema issues.
|
|
1451
|
+
*
|
|
1452
|
+
* @param issues — the standard-schema issues, one message line each.
|
|
1453
|
+
*/
|
|
1454
|
+
constructor(issues) {
|
|
1455
|
+
super(`invalid config:\n` + issues.map((issue) => {
|
|
1456
|
+
if (issue.path) return ` - ${issue.message} (at ${issue.path.join(".")})`;
|
|
1457
|
+
else return ` - ${issue.message}`;
|
|
1458
|
+
}).join("\n"));
|
|
1459
|
+
}
|
|
1460
|
+
};
|
|
1461
|
+
Object.defineProperty(ValidationError$1.prototype, kValidationError$1, { value: true });
|
|
1454
1462
|
/**
|
|
1455
|
-
*
|
|
1463
|
+
* Validate and normalize config for a plugin runtime before it starts.
|
|
1456
1464
|
*
|
|
1457
|
-
* @param
|
|
1458
|
-
* @
|
|
1465
|
+
* @param runtime — the plugin runtime whose `Config` schema to apply.
|
|
1466
|
+
* @param config — the raw user config.
|
|
1467
|
+
* @returns the validated config, or `config` unchanged if the runtime has no schema.
|
|
1468
|
+
* @throws {ValidationError} when validation reports issues.
|
|
1459
1469
|
*/
|
|
1460
|
-
function
|
|
1461
|
-
|
|
1470
|
+
function resolveConfig(runtime, config) {
|
|
1471
|
+
if (!runtime.Config) return config;
|
|
1472
|
+
const result = runtime.Config["~standard"].validate(config);
|
|
1473
|
+
if ("then" in result) throw new TypeError("Async config validation is not supported");
|
|
1474
|
+
if (result.issues) throw new ValidationError$1(result.issues);
|
|
1475
|
+
else return result.value;
|
|
1476
|
+
}
|
|
1477
|
+
const effectInertia = /* @__PURE__ */ new WeakMap();
|
|
1478
|
+
function runDisposable(dispose) {
|
|
1479
|
+
const result = dispose();
|
|
1480
|
+
return effectInertia.get(dispose)?.() ?? result;
|
|
1481
|
+
}
|
|
1482
|
+
/** Notify plugin teardown without allowing one observer to break ownership cleanup. */
|
|
1483
|
+
function emitPluginDisposed(context, fiber) {
|
|
1484
|
+
const args = ["internal/plugin", fiber];
|
|
1485
|
+
let callbacks;
|
|
1486
|
+
try {
|
|
1487
|
+
callbacks = context.events.dispatch("emit", args);
|
|
1488
|
+
} catch (error) {
|
|
1489
|
+
context.logger.error(error);
|
|
1490
|
+
return;
|
|
1491
|
+
}
|
|
1492
|
+
for (const callback of callbacks) try {
|
|
1493
|
+
const returned = callback(...args);
|
|
1494
|
+
Promise.resolve(returned).catch((error) => context.logger.error(error));
|
|
1495
|
+
} catch (error) {
|
|
1496
|
+
context.logger.error(error);
|
|
1497
|
+
}
|
|
1462
1498
|
}
|
|
1499
|
+
/** Framework error with a stable machine-readable code. */
|
|
1500
|
+
var CordisError = class CordisError extends Error {
|
|
1501
|
+
code;
|
|
1502
|
+
/**
|
|
1503
|
+
* @param code — the stable error code; also the default message.
|
|
1504
|
+
* @param message — optional human-readable override.
|
|
1505
|
+
*/
|
|
1506
|
+
constructor(code, message) {
|
|
1507
|
+
super(message ?? CordisError.Code[code]);
|
|
1508
|
+
this.code = code;
|
|
1509
|
+
}
|
|
1510
|
+
};
|
|
1511
|
+
(function(_CordisError) {
|
|
1512
|
+
_CordisError.Code = { INACTIVE_EFFECT: "cannot create effect on inactive context" };
|
|
1513
|
+
})(CordisError || (CordisError = {}));
|
|
1514
|
+
const INACTIVE = "__INACTIVE__";
|
|
1463
1515
|
/**
|
|
1464
|
-
*
|
|
1516
|
+
* Runtime instance of one plugin application.
|
|
1465
1517
|
*
|
|
1466
|
-
*
|
|
1467
|
-
*
|
|
1518
|
+
* A fiber tracks dependency state, raw and effective config, lifecycle effects, and
|
|
1519
|
+
* cleanup for the plugin context returned by `ctx.plugin()`.
|
|
1468
1520
|
*/
|
|
1469
|
-
var
|
|
1521
|
+
var Fiber = class {
|
|
1522
|
+
parent;
|
|
1523
|
+
inject;
|
|
1524
|
+
runtime;
|
|
1525
|
+
/** Unique id within the registry; 0 for the root fiber, `null` once disposed. */
|
|
1526
|
+
uid;
|
|
1527
|
+
/** The context this fiber's plugin runs in (extends the parent context). */
|
|
1470
1528
|
ctx;
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1529
|
+
/** Raw plugin input retained for the next activation. */
|
|
1530
|
+
config;
|
|
1531
|
+
/** Current lifecycle state; transitions emit `internal/status`. */
|
|
1532
|
+
state = 0;
|
|
1533
|
+
/** Dispose this fiber: unload the plugin, then settle once cleanup finished. */
|
|
1534
|
+
dispose;
|
|
1535
|
+
/** Required implementations retained through dependent teardown. */
|
|
1536
|
+
committed;
|
|
1537
|
+
/** Service implementations owned by this fiber, including isolated provisions. */
|
|
1538
|
+
provisions = /* @__PURE__ */ new Set();
|
|
1539
|
+
/** The in-flight load/unload transition, if one is currently running. */
|
|
1540
|
+
inertia;
|
|
1541
|
+
_hooks = Object.create(null);
|
|
1542
|
+
_disposables = new DisposableList();
|
|
1543
|
+
context;
|
|
1544
|
+
_error;
|
|
1545
|
+
_revision = 0;
|
|
1546
|
+
_configRevision = 0;
|
|
1547
|
+
_effectiveConfig;
|
|
1548
|
+
_runner;
|
|
1549
|
+
_store = Object.create(null);
|
|
1550
|
+
_release;
|
|
1492
1551
|
/**
|
|
1493
|
-
*
|
|
1552
|
+
* Create a fiber. Plugin authors normally obtain fibers from `ctx.plugin()`
|
|
1553
|
+
* rather than constructing them directly.
|
|
1494
1554
|
*
|
|
1495
|
-
* @param
|
|
1496
|
-
* @param
|
|
1497
|
-
* @
|
|
1555
|
+
* @param parent — the context the plugin was loaded from.
|
|
1556
|
+
* @param config — raw config, validated against the runtime's schema.
|
|
1557
|
+
* @param inject — resolved dependency map (service name → intercept config).
|
|
1558
|
+
* @param runtime — the shared plugin runtime, or `null` for the root fiber.
|
|
1559
|
+
* @param getOuterStack — captures the caller stack for effect diagnostics.
|
|
1498
1560
|
*/
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1561
|
+
constructor(parent, config, inject, runtime, getOuterStack) {
|
|
1562
|
+
this.parent = parent;
|
|
1563
|
+
this.inject = inject;
|
|
1564
|
+
this.runtime = runtime;
|
|
1565
|
+
this.config = config;
|
|
1566
|
+
const collect = (dispose) => {
|
|
1567
|
+
this._disposables.push(dispose);
|
|
1568
|
+
};
|
|
1569
|
+
if (runtime) {
|
|
1570
|
+
this.uid = parent.registry.counter;
|
|
1571
|
+
this.ctx = this.context = parent.extend({ fiber: this });
|
|
1572
|
+
const injectEntries = Object.entries(this.inject);
|
|
1573
|
+
if (injectEntries.length) {
|
|
1574
|
+
this.ctx[Context.intercept] = Object.create(parent[Context.intercept]);
|
|
1575
|
+
for (const [name, config] of injectEntries) {
|
|
1576
|
+
if (isNullable(config)) continue;
|
|
1577
|
+
this.ctx[Context.intercept][name] = config;
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
this._runner = {
|
|
1581
|
+
epoch: INACTIVE,
|
|
1582
|
+
getOuterStack,
|
|
1583
|
+
execute: function() {
|
|
1584
|
+
const config = this.resolveConfig(this.config);
|
|
1585
|
+
this._effectiveConfig = config;
|
|
1586
|
+
if (isConstructor(runtime.callback)) {
|
|
1587
|
+
const instance = new runtime.callback(this.ctx, config);
|
|
1588
|
+
for (const hook of instance?.[symbols.initHooks] ?? []) hook();
|
|
1589
|
+
return instance?.[symbols.init]?.();
|
|
1590
|
+
} else return runtime.callback(this.ctx, config);
|
|
1591
|
+
},
|
|
1592
|
+
collect
|
|
1593
|
+
};
|
|
1594
|
+
this.dispose = parent.fiber.effect(() => {
|
|
1595
|
+
const remove = runtime.fibers.push(this);
|
|
1596
|
+
return async () => {
|
|
1597
|
+
this.uid = null;
|
|
1598
|
+
emitPluginDisposed(this.context, this);
|
|
1599
|
+
if (this.ctx.registry.has(runtime.callback)) {
|
|
1600
|
+
remove();
|
|
1601
|
+
if (!runtime.fibers.length) this.ctx.registry.delete(runtime.callback);
|
|
1602
|
+
}
|
|
1603
|
+
this._setEpoch(INACTIVE);
|
|
1604
|
+
if (!this.inertia) this._updateState(() => {
|
|
1605
|
+
this.inertia = this._unload();
|
|
1606
|
+
return 5;
|
|
1607
|
+
});
|
|
1608
|
+
while (this.inertia) await this.inertia;
|
|
1609
|
+
};
|
|
1610
|
+
}, "ctx.plugin()");
|
|
1611
|
+
try {
|
|
1612
|
+
this.context.emit("internal/plugin", this);
|
|
1613
|
+
} catch (error) {
|
|
1614
|
+
Promise.resolve(this.dispose()).catch((reason) => this.ctx.logger.error(reason));
|
|
1615
|
+
throw error;
|
|
1616
|
+
}
|
|
1617
|
+
if (this.uid !== null && parent.fiber.state !== 5) {
|
|
1618
|
+
for (const name of Object.keys(this.inject)) this._checkImpl(name);
|
|
1619
|
+
this._refresh();
|
|
1620
|
+
}
|
|
1621
|
+
} else {
|
|
1622
|
+
this.uid = 0;
|
|
1623
|
+
this.ctx = this.context = parent;
|
|
1624
|
+
this.state = 2;
|
|
1625
|
+
this.committed = Object.create(null);
|
|
1626
|
+
this._runner = {
|
|
1627
|
+
epoch: "0",
|
|
1628
|
+
getOuterStack,
|
|
1629
|
+
execute: () => {},
|
|
1630
|
+
collect
|
|
1631
|
+
};
|
|
1632
|
+
this.dispose = () => this.restart();
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
/** The plugin's display name, inherited from the nearest named ancestor, else `'root'`. */
|
|
1636
|
+
get name() {
|
|
1637
|
+
let fiber = this;
|
|
1638
|
+
do {
|
|
1639
|
+
if (fiber.runtime?.name) return fiber.runtime.name;
|
|
1640
|
+
fiber = fiber.parent.fiber;
|
|
1641
|
+
} while (fiber !== fiber.parent.fiber);
|
|
1642
|
+
return "root";
|
|
1505
1643
|
}
|
|
1506
1644
|
/**
|
|
1507
|
-
*
|
|
1645
|
+
* Throw if the fiber has already been disposed.
|
|
1508
1646
|
*
|
|
1509
|
-
* @
|
|
1510
|
-
* @
|
|
1647
|
+
* @returns nothing when the fiber is still active.
|
|
1648
|
+
* @throws {CordisError} `INACTIVE_EFFECT` when the fiber's uid has been cleared.
|
|
1511
1649
|
*/
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
}
|
|
1516
|
-
/**
|
|
1517
|
-
* Run listeners synchronously without waiting for returned promises.
|
|
1518
|
-
*
|
|
1519
|
-
* @param args — optional `this`, the event name, then listener arguments.
|
|
1520
|
-
*/
|
|
1521
|
-
emit(...args) {
|
|
1522
|
-
this.dispatch("emit", args).map((cb) => cb(...args));
|
|
1523
|
-
}
|
|
1524
|
-
/**
|
|
1525
|
-
* Run listeners in order, awaiting each, until one returns a bail value.
|
|
1526
|
-
*
|
|
1527
|
-
* @param args — optional `this`, the event name, then listener arguments.
|
|
1528
|
-
* @returns the first bail value (see {@link isBailed}), if any.
|
|
1529
|
-
*/
|
|
1530
|
-
async serial(...args) {
|
|
1531
|
-
for (const cb of this.dispatch("serial", args)) {
|
|
1532
|
-
const result = await cb(...args);
|
|
1533
|
-
if (isBailed(result)) return result;
|
|
1534
|
-
}
|
|
1535
|
-
}
|
|
1536
|
-
/**
|
|
1537
|
-
* Run listeners synchronously until one returns a bail value.
|
|
1538
|
-
*
|
|
1539
|
-
* @param args — optional `this`, the event name, then listener arguments.
|
|
1540
|
-
* @returns the first bail value (see {@link isBailed}), if any.
|
|
1541
|
-
*/
|
|
1542
|
-
bail(...args) {
|
|
1543
|
-
for (const cb of this.dispatch("bail", args)) {
|
|
1544
|
-
const result = cb(...args);
|
|
1545
|
-
if (isBailed(result)) return result;
|
|
1546
|
-
}
|
|
1547
|
-
}
|
|
1548
|
-
/**
|
|
1549
|
-
* Compose listeners around the final `next` callback.
|
|
1550
|
-
*
|
|
1551
|
-
* The last dispatch argument is treated as the innermost `next`. Listeners
|
|
1552
|
-
* run outermost-first; a listener that does not call `next()` vetoes the
|
|
1553
|
-
* rest of the chain, including the built-in behavior.
|
|
1554
|
-
*
|
|
1555
|
-
* @param args — optional `this`, the event name, listener arguments, then `next`.
|
|
1556
|
-
* @returns the outermost listener's return value.
|
|
1557
|
-
*/
|
|
1558
|
-
waterfall(...args) {
|
|
1559
|
-
const cbs = this.dispatch("waterfall", args);
|
|
1560
|
-
const inner = args.pop();
|
|
1561
|
-
const next = () => {
|
|
1562
|
-
return (cbs.shift() ?? inner)(...args);
|
|
1563
|
-
};
|
|
1564
|
-
args.push(next);
|
|
1565
|
-
return next();
|
|
1566
|
-
}
|
|
1567
|
-
/**
|
|
1568
|
-
* Store a listener record as an effect on the current fiber.
|
|
1569
|
-
*
|
|
1570
|
-
* @param label — effect label shown in fiber diagnostics.
|
|
1571
|
-
* @param hooks — the listener list for one event.
|
|
1572
|
-
* @param callback — the listener to store.
|
|
1573
|
-
* @param options — placement and filtering options.
|
|
1574
|
-
* @returns a disposer that unregisters the listener.
|
|
1575
|
-
*/
|
|
1576
|
-
register(label, hooks, callback, options) {
|
|
1577
|
-
const method = options.prepend ? "unshift" : "push";
|
|
1578
|
-
return this.ctx.fiber.effect(() => {
|
|
1579
|
-
hooks[method]({
|
|
1580
|
-
ctx: this.ctx,
|
|
1581
|
-
callback,
|
|
1582
|
-
...options
|
|
1583
|
-
});
|
|
1584
|
-
return () => this.unregister(hooks, callback);
|
|
1585
|
-
}, label);
|
|
1586
|
-
}
|
|
1587
|
-
/**
|
|
1588
|
-
* Remove a stored listener record.
|
|
1589
|
-
*
|
|
1590
|
-
* @param hooks — the listener list for one event.
|
|
1591
|
-
* @param callback — the listener to remove.
|
|
1592
|
-
* @returns `true` if the listener was found and removed.
|
|
1593
|
-
*/
|
|
1594
|
-
unregister(hooks, callback) {
|
|
1595
|
-
const index = hooks.findIndex((hook) => hook.callback === callback);
|
|
1596
|
-
if (index >= 0) {
|
|
1597
|
-
hooks.splice(index, 1);
|
|
1598
|
-
return true;
|
|
1599
|
-
}
|
|
1600
|
-
}
|
|
1601
|
-
/**
|
|
1602
|
-
* Register an event listener owned by the current fiber.
|
|
1603
|
-
*
|
|
1604
|
-
* The listener is removed automatically when the fiber unloads. Throws
|
|
1605
|
-
* `CordisError('INACTIVE_EFFECT')` if the fiber is already disposed.
|
|
1606
|
-
*
|
|
1607
|
-
* @param name — the event name to listen for.
|
|
1608
|
-
* @param listener — called with the dispatch arguments.
|
|
1609
|
-
* @param options — listener options; a boolean is shorthand for `prepend`.
|
|
1610
|
-
* @returns a disposer removing the listener; `true` if it was still registered.
|
|
1611
|
-
*/
|
|
1612
|
-
on(name, listener, options) {
|
|
1613
|
-
if (typeof options !== "object") options = { prepend: options };
|
|
1614
|
-
this.ctx.fiber.assertActive();
|
|
1615
|
-
listener = this.ctx.reflect.bind(listener);
|
|
1616
|
-
const result = this.bail(this.ctx, "internal/listener", name, listener, options);
|
|
1617
|
-
if (result) return result;
|
|
1618
|
-
const hooks = this._hooks[name] ||= [];
|
|
1619
|
-
const label = `ctx.on(${typeof name === "string" ? JSON.stringify(name) : name.toString()})`;
|
|
1620
|
-
return this.register(label, hooks, listener, options);
|
|
1621
|
-
}
|
|
1622
|
-
/**
|
|
1623
|
-
* Register an event listener that disposes itself after the first call.
|
|
1624
|
-
*
|
|
1625
|
-
* @param name — the event name to listen for.
|
|
1626
|
-
* @param listener — called at most once with the dispatch arguments.
|
|
1627
|
-
* @param options — listener options; a boolean is shorthand for `prepend`.
|
|
1628
|
-
* @returns a disposer removing the listener; `true` if it was still registered.
|
|
1629
|
-
*/
|
|
1630
|
-
once(name, listener, options) {
|
|
1631
|
-
const dispose = this.on(name, function(...args) {
|
|
1632
|
-
dispose();
|
|
1633
|
-
return listener.apply(this, args);
|
|
1634
|
-
}, options);
|
|
1635
|
-
return dispose;
|
|
1636
|
-
}
|
|
1637
|
-
};
|
|
1638
|
-
//#endregion
|
|
1639
|
-
//#region ../../../vendor/cordis/src/logger.ts
|
|
1640
|
-
/** Built-in placeholder formatters used by `Logger.format()`. */
|
|
1641
|
-
const defaultFormatters = {
|
|
1642
|
-
s: (value) => String(value),
|
|
1643
|
-
d: (value) => Math.trunc(Number(value)),
|
|
1644
|
-
i: (value) => Math.trunc(Number(value)),
|
|
1645
|
-
f: (value) => Number(value),
|
|
1646
|
-
o: (value) => JSON.stringify(value),
|
|
1647
|
-
O: (value) => JSON.stringify(value),
|
|
1648
|
-
c: () => "",
|
|
1649
|
-
C: (value, exporter, message) => {
|
|
1650
|
-
return Logger.color(exporter, Logger.code(message.name, exporter.colors), value);
|
|
1651
|
-
}
|
|
1652
|
-
};
|
|
1653
|
-
function isAggregateError(error) {
|
|
1654
|
-
return error instanceof Error && Array.isArray(error["errors"]);
|
|
1655
|
-
}
|
|
1656
|
-
/** Logger facade for one named subsystem. */
|
|
1657
|
-
var Logger = class {
|
|
1658
|
-
service;
|
|
1659
|
-
static color(exporter, code, value, decoration = "") {
|
|
1660
|
-
if (!exporter.colors) return "" + value;
|
|
1661
|
-
return `\u001b[3${code < 8 ? code : "8;5;" + code}${exporter.colors >= 2 ? decoration : ""}m${value}\u001b[0m`;
|
|
1662
|
-
}
|
|
1663
|
-
static code(name, level) {
|
|
1664
|
-
let hash = 0;
|
|
1665
|
-
for (let i = 0; i < name.length; i++) {
|
|
1666
|
-
hash = (hash << 3) - hash + name.charCodeAt(i) + 13;
|
|
1667
|
-
hash |= 0;
|
|
1668
|
-
}
|
|
1669
|
-
const colors = !level ? [] : level >= 2 ? c256 : c16;
|
|
1670
|
-
return colors[Math.abs(hash) % colors.length];
|
|
1671
|
-
}
|
|
1672
|
-
static format(exporter, message) {
|
|
1673
|
-
const args = message.args.slice();
|
|
1674
|
-
if (args[0] instanceof Error) {
|
|
1675
|
-
args[0] = args[0].stack || args[0].message;
|
|
1676
|
-
args.unshift("%s");
|
|
1677
|
-
} else if (typeof args[0] !== "string") args.unshift("%o");
|
|
1678
|
-
let format = args.shift();
|
|
1679
|
-
format = format.replace(/%([a-zA-Z%])/g, (match, char) => {
|
|
1680
|
-
if (match === "%%") return "%";
|
|
1681
|
-
const formatter = exporter.formatters?.[char] ?? defaultFormatters[char];
|
|
1682
|
-
if (typeof formatter === "function") return formatter(args.shift(), exporter, message);
|
|
1683
|
-
return match;
|
|
1684
|
-
});
|
|
1685
|
-
const oFormatter = exporter.formatters?.o ?? defaultFormatters.o;
|
|
1686
|
-
for (let arg of args) {
|
|
1687
|
-
if (typeof arg === "object" && arg) arg = oFormatter(arg, exporter, message);
|
|
1688
|
-
format += " " + arg;
|
|
1689
|
-
}
|
|
1690
|
-
const { maxLength = 10240 } = exporter;
|
|
1691
|
-
return format.split(/\r?\n/g).map((line) => {
|
|
1692
|
-
return line.slice(0, maxLength) + (line.length > maxLength ? "..." : "");
|
|
1693
|
-
}).join("\n");
|
|
1694
|
-
}
|
|
1695
|
-
constructor(options, service) {
|
|
1696
|
-
this.service = service;
|
|
1697
|
-
Object.assign(this, options);
|
|
1698
|
-
this.error = this._method("error", 0);
|
|
1699
|
-
this.info = this._method("info", 1);
|
|
1700
|
-
this.warn = this._method("warn", 2);
|
|
1701
|
-
this.debug = this._method("debug", 3);
|
|
1702
|
-
}
|
|
1703
|
-
_method(type, level) {
|
|
1704
|
-
return (...args) => {
|
|
1705
|
-
if (args.length === 1 && args[0] instanceof Error) {
|
|
1706
|
-
if (args[0].cause) this[type](args[0].cause);
|
|
1707
|
-
else if (isAggregateError(args[0])) {
|
|
1708
|
-
args[0].errors.forEach((error) => this[type](error));
|
|
1709
|
-
return;
|
|
1710
|
-
}
|
|
1711
|
-
}
|
|
1712
|
-
const sn = ++this.service._snMessage;
|
|
1713
|
-
const ts = Date.now();
|
|
1714
|
-
for (const exporter of this.service.exporters.values()) {
|
|
1715
|
-
if ((exporter.levels?.[this.name] ?? exporter.levels?.default ?? this.level ?? 1) < level) continue;
|
|
1716
|
-
const message = {
|
|
1717
|
-
sn,
|
|
1718
|
-
ts,
|
|
1719
|
-
type,
|
|
1720
|
-
level,
|
|
1721
|
-
name: this.name,
|
|
1722
|
-
...this.meta,
|
|
1723
|
-
args
|
|
1724
|
-
};
|
|
1725
|
-
exporter.export(message);
|
|
1726
|
-
}
|
|
1727
|
-
};
|
|
1728
|
-
}
|
|
1729
|
-
};
|
|
1730
|
-
/** ANSI 16-color palette indexes used for logger name coloring. */
|
|
1731
|
-
const c16 = [
|
|
1732
|
-
6,
|
|
1733
|
-
2,
|
|
1734
|
-
3,
|
|
1735
|
-
4,
|
|
1736
|
-
5,
|
|
1737
|
-
1
|
|
1738
|
-
];
|
|
1739
|
-
/** ANSI 256-color palette indexes used for logger name coloring. */
|
|
1740
|
-
const c256 = [
|
|
1741
|
-
20,
|
|
1742
|
-
21,
|
|
1743
|
-
26,
|
|
1744
|
-
27,
|
|
1745
|
-
32,
|
|
1746
|
-
33,
|
|
1747
|
-
38,
|
|
1748
|
-
39,
|
|
1749
|
-
40,
|
|
1750
|
-
41,
|
|
1751
|
-
42,
|
|
1752
|
-
43,
|
|
1753
|
-
44,
|
|
1754
|
-
45,
|
|
1755
|
-
56,
|
|
1756
|
-
57,
|
|
1757
|
-
62,
|
|
1758
|
-
63,
|
|
1759
|
-
68,
|
|
1760
|
-
69,
|
|
1761
|
-
74,
|
|
1762
|
-
75,
|
|
1763
|
-
76,
|
|
1764
|
-
77,
|
|
1765
|
-
78,
|
|
1766
|
-
79,
|
|
1767
|
-
80,
|
|
1768
|
-
81,
|
|
1769
|
-
92,
|
|
1770
|
-
93,
|
|
1771
|
-
98,
|
|
1772
|
-
99,
|
|
1773
|
-
112,
|
|
1774
|
-
113,
|
|
1775
|
-
129,
|
|
1776
|
-
134,
|
|
1777
|
-
135,
|
|
1778
|
-
148,
|
|
1779
|
-
149,
|
|
1780
|
-
160,
|
|
1781
|
-
161,
|
|
1782
|
-
162,
|
|
1783
|
-
163,
|
|
1784
|
-
164,
|
|
1785
|
-
165,
|
|
1786
|
-
166,
|
|
1787
|
-
167,
|
|
1788
|
-
168,
|
|
1789
|
-
169,
|
|
1790
|
-
170,
|
|
1791
|
-
171,
|
|
1792
|
-
172,
|
|
1793
|
-
173,
|
|
1794
|
-
178,
|
|
1795
|
-
179,
|
|
1796
|
-
184,
|
|
1797
|
-
185,
|
|
1798
|
-
196,
|
|
1799
|
-
197,
|
|
1800
|
-
198,
|
|
1801
|
-
199,
|
|
1802
|
-
200,
|
|
1803
|
-
201,
|
|
1804
|
-
202,
|
|
1805
|
-
203,
|
|
1806
|
-
204,
|
|
1807
|
-
205,
|
|
1808
|
-
206,
|
|
1809
|
-
207,
|
|
1810
|
-
208,
|
|
1811
|
-
209,
|
|
1812
|
-
214,
|
|
1813
|
-
215,
|
|
1814
|
-
220,
|
|
1815
|
-
221
|
|
1816
|
-
];
|
|
1817
|
-
/**
|
|
1818
|
-
* Built-in logging service.
|
|
1819
|
-
*
|
|
1820
|
-
* Call `ctx.logger()` to create a named logger, or call `ctx.logger.info()`
|
|
1821
|
-
* directly to log with the current fiber-derived name.
|
|
1822
|
-
*/
|
|
1823
|
-
var LoggerService = class LoggerService {
|
|
1824
|
-
bufferSize = 1e3;
|
|
1825
|
-
buffer = [];
|
|
1826
|
-
ctx;
|
|
1827
|
-
_snMessage = 0;
|
|
1828
|
-
_snExporter = 0;
|
|
1829
|
-
exporters = /* @__PURE__ */ new Map();
|
|
1830
|
-
constructor(ctx) {
|
|
1831
|
-
const tracker = {
|
|
1832
|
-
property: "ctx",
|
|
1833
|
-
noShadow: true
|
|
1834
|
-
};
|
|
1835
|
-
const self = createCallable("logger", joinPrototype(Object.getPrototypeOf(this), Function.prototype), tracker);
|
|
1836
|
-
Object.assign(self, this);
|
|
1837
|
-
self.ctx = ctx;
|
|
1838
|
-
defineProperty(self, symbols.tracker, tracker);
|
|
1839
|
-
self.exporter({
|
|
1840
|
-
colors: 3,
|
|
1841
|
-
export: (message) => {
|
|
1842
|
-
self.buffer.push(message);
|
|
1843
|
-
if (self.buffer.length > self.bufferSize) self.buffer = self.buffer.slice(-self.bufferSize);
|
|
1844
|
-
}
|
|
1845
|
-
});
|
|
1846
|
-
return self;
|
|
1847
|
-
}
|
|
1848
|
-
/**
|
|
1849
|
-
* Register an exporter and dispose it with the current fiber.
|
|
1850
|
-
*
|
|
1851
|
-
* @param exporter — the sink that receives structured log messages.
|
|
1852
|
-
* @returns a disposer that removes the exporter.
|
|
1853
|
-
*/
|
|
1854
|
-
exporter(exporter) {
|
|
1855
|
-
return this.ctx.effect(() => {
|
|
1856
|
-
const id = ++this._snExporter;
|
|
1857
|
-
this.exporters.set(id, exporter);
|
|
1858
|
-
return () => this.exporters.delete(id);
|
|
1859
|
-
}, "ctx.logger.exporter()");
|
|
1860
|
-
}
|
|
1861
|
-
_resolveConfig() {
|
|
1862
|
-
let intercept = this.ctx[symbols.intercept];
|
|
1863
|
-
const configs = [];
|
|
1864
|
-
while ("logger" in intercept) {
|
|
1865
|
-
if (Object.hasOwn(intercept, "logger")) configs.unshift(intercept["logger"]);
|
|
1866
|
-
intercept = Object.getPrototypeOf(intercept);
|
|
1867
|
-
}
|
|
1868
|
-
return Object.assign({}, ...configs);
|
|
1869
|
-
}
|
|
1870
|
-
[symbols.invoke](name) {
|
|
1871
|
-
const config = this._resolveConfig();
|
|
1872
|
-
const fiber = (this.ctx[symbols.shadow] ?? this.ctx).fiber;
|
|
1873
|
-
name ??= config.name;
|
|
1874
|
-
name ??= hyphenate(fiber.name);
|
|
1875
|
-
return new Logger({
|
|
1876
|
-
name,
|
|
1877
|
-
level: config.level,
|
|
1878
|
-
meta: { fiber: new WeakRef(fiber) }
|
|
1879
|
-
}, this);
|
|
1880
|
-
}
|
|
1881
|
-
static {
|
|
1882
|
-
for (const type of [
|
|
1883
|
-
"error",
|
|
1884
|
-
"info",
|
|
1885
|
-
"warn",
|
|
1886
|
-
"debug"
|
|
1887
|
-
]) LoggerService.prototype[type] = function(...args) {
|
|
1888
|
-
return this()[type](...args);
|
|
1889
|
-
};
|
|
1890
|
-
}
|
|
1891
|
-
};
|
|
1892
|
-
//#endregion
|
|
1893
|
-
//#region ../../../vendor/cordis/src/fiber.ts
|
|
1894
|
-
const kValidationError$1 = Symbol.for("ValidationError");
|
|
1895
|
-
/** Error raised when plugin configuration fails standard-schema validation. */
|
|
1896
|
-
var ValidationError$1 = class extends TypeError {
|
|
1897
|
-
name = "ValidationError";
|
|
1898
|
-
/**
|
|
1899
|
-
* Build the aggregated message from schema issues.
|
|
1900
|
-
*
|
|
1901
|
-
* @param issues — the standard-schema issues, one message line each.
|
|
1902
|
-
*/
|
|
1903
|
-
constructor(issues) {
|
|
1904
|
-
super(`invalid config:\n` + issues.map((issue) => {
|
|
1905
|
-
if (issue.path) return ` - ${issue.message} (at ${issue.path.join(".")})`;
|
|
1906
|
-
else return ` - ${issue.message}`;
|
|
1907
|
-
}).join("\n"));
|
|
1908
|
-
}
|
|
1909
|
-
};
|
|
1910
|
-
Object.defineProperty(ValidationError$1.prototype, kValidationError$1, { value: true });
|
|
1911
|
-
/**
|
|
1912
|
-
* Validate and normalize config for a plugin runtime before it starts.
|
|
1913
|
-
*
|
|
1914
|
-
* @param runtime — the plugin runtime whose `Config` schema to apply.
|
|
1915
|
-
* @param config — the raw user config.
|
|
1916
|
-
* @returns the validated config, or `config` unchanged if the runtime has no schema.
|
|
1917
|
-
* @throws {ValidationError} when validation reports issues.
|
|
1918
|
-
*/
|
|
1919
|
-
function resolveConfig(runtime, config) {
|
|
1920
|
-
if (!runtime.Config) return config;
|
|
1921
|
-
const result = runtime.Config["~standard"].validate(config);
|
|
1922
|
-
if ("then" in result) throw new TypeError("Async config validation is not supported");
|
|
1923
|
-
if (result.issues) throw new ValidationError$1(result.issues);
|
|
1924
|
-
else return result.value;
|
|
1925
|
-
}
|
|
1926
|
-
const effectInertia = /* @__PURE__ */ new WeakMap();
|
|
1927
|
-
function runDisposable(dispose) {
|
|
1928
|
-
const result = dispose();
|
|
1929
|
-
return effectInertia.get(dispose)?.() ?? result;
|
|
1930
|
-
}
|
|
1931
|
-
/** Notify plugin teardown without allowing one observer to break ownership cleanup. */
|
|
1932
|
-
function emitPluginDisposed(context, fiber) {
|
|
1933
|
-
const args = ["internal/plugin", fiber];
|
|
1934
|
-
let callbacks;
|
|
1935
|
-
try {
|
|
1936
|
-
callbacks = context.events.dispatch("emit", args);
|
|
1937
|
-
} catch (error) {
|
|
1938
|
-
context.logger.error(error);
|
|
1939
|
-
return;
|
|
1940
|
-
}
|
|
1941
|
-
for (const callback of callbacks) try {
|
|
1942
|
-
const returned = callback(...args);
|
|
1943
|
-
Promise.resolve(returned).catch((error) => context.logger.error(error));
|
|
1944
|
-
} catch (error) {
|
|
1945
|
-
context.logger.error(error);
|
|
1946
|
-
}
|
|
1947
|
-
}
|
|
1948
|
-
/** Framework error with a stable machine-readable code. */
|
|
1949
|
-
var CordisError = class CordisError extends Error {
|
|
1950
|
-
code;
|
|
1951
|
-
/**
|
|
1952
|
-
* @param code — the stable error code; also the default message.
|
|
1953
|
-
* @param message — optional human-readable override.
|
|
1954
|
-
*/
|
|
1955
|
-
constructor(code, message) {
|
|
1956
|
-
super(message ?? CordisError.Code[code]);
|
|
1957
|
-
this.code = code;
|
|
1958
|
-
}
|
|
1959
|
-
};
|
|
1960
|
-
(function(_CordisError) {
|
|
1961
|
-
_CordisError.Code = { INACTIVE_EFFECT: "cannot create effect on inactive context" };
|
|
1962
|
-
})(CordisError || (CordisError = {}));
|
|
1963
|
-
const INACTIVE = "__INACTIVE__";
|
|
1964
|
-
/**
|
|
1965
|
-
* Runtime instance of one plugin application.
|
|
1966
|
-
*
|
|
1967
|
-
* A fiber tracks dependency state, validated config, lifecycle effects, and
|
|
1968
|
-
* cleanup for the plugin context returned by `ctx.plugin()`.
|
|
1969
|
-
*/
|
|
1970
|
-
var Fiber = class {
|
|
1971
|
-
parent;
|
|
1972
|
-
inject;
|
|
1973
|
-
runtime;
|
|
1974
|
-
/** Unique id within the registry; 0 for the root fiber, `null` once disposed. */
|
|
1975
|
-
uid;
|
|
1976
|
-
/** The context this fiber's plugin runs in (extends the parent context). */
|
|
1977
|
-
ctx;
|
|
1978
|
-
/** The validated plugin config (updated by `update()`). */
|
|
1979
|
-
config;
|
|
1980
|
-
/** The raw plugin config, re-resolved before each activation. */
|
|
1981
|
-
_config;
|
|
1982
|
-
/** Current lifecycle state; transitions emit `internal/status`. */
|
|
1983
|
-
state = 0;
|
|
1984
|
-
/** Dispose this fiber: unload the plugin, then settle once cleanup finished. */
|
|
1985
|
-
dispose;
|
|
1986
|
-
/** Snapshot of required service implementations while loaded; `undefined` otherwise. */
|
|
1987
|
-
store;
|
|
1988
|
-
/** The in-flight load/unload transition, if one is currently running. */
|
|
1989
|
-
inertia;
|
|
1990
|
-
_hooks = Object.create(null);
|
|
1991
|
-
_disposables = new DisposableList();
|
|
1992
|
-
context;
|
|
1993
|
-
_error;
|
|
1994
|
-
_runner;
|
|
1995
|
-
_store = Object.create(null);
|
|
1996
|
-
/**
|
|
1997
|
-
* Create a fiber. Plugin authors normally obtain fibers from `ctx.plugin()`
|
|
1998
|
-
* rather than constructing them directly.
|
|
1999
|
-
*
|
|
2000
|
-
* @param parent — the context the plugin was loaded from.
|
|
2001
|
-
* @param config — raw config, validated against the runtime's schema.
|
|
2002
|
-
* @param inject — resolved dependency map (service name → intercept config).
|
|
2003
|
-
* @param runtime — the shared plugin runtime, or `null` for the root fiber.
|
|
2004
|
-
* @param getOuterStack — captures the caller stack for effect diagnostics.
|
|
2005
|
-
*/
|
|
2006
|
-
constructor(parent, config, inject, runtime, getOuterStack) {
|
|
2007
|
-
this.parent = parent;
|
|
2008
|
-
this.inject = inject;
|
|
2009
|
-
this.runtime = runtime;
|
|
2010
|
-
this._config = config;
|
|
2011
|
-
const collect = (dispose) => {
|
|
2012
|
-
this._disposables.push(dispose);
|
|
2013
|
-
};
|
|
2014
|
-
if (runtime) {
|
|
2015
|
-
this.uid = parent.registry.counter;
|
|
2016
|
-
this.ctx = this.context = parent.extend({ fiber: this });
|
|
2017
|
-
const injectEntries = Object.entries(this.inject);
|
|
2018
|
-
if (injectEntries.length) {
|
|
2019
|
-
this.ctx[Context.intercept] = Object.create(parent[Context.intercept]);
|
|
2020
|
-
for (const [name, config] of injectEntries) {
|
|
2021
|
-
if (isNullable(config)) continue;
|
|
2022
|
-
this.ctx[Context.intercept][name] = config;
|
|
2023
|
-
}
|
|
2024
|
-
}
|
|
2025
|
-
this._runner = {
|
|
2026
|
-
epoch: INACTIVE,
|
|
2027
|
-
getOuterStack,
|
|
2028
|
-
execute: function() {
|
|
2029
|
-
if (isConstructor(runtime.callback)) {
|
|
2030
|
-
const instance = new runtime.callback(this.ctx, this.config);
|
|
2031
|
-
for (const hook of instance?.[symbols.initHooks] ?? []) hook();
|
|
2032
|
-
return instance?.[symbols.init]?.();
|
|
2033
|
-
} else return runtime.callback(this.ctx, this.config);
|
|
2034
|
-
},
|
|
2035
|
-
collect
|
|
2036
|
-
};
|
|
2037
|
-
this.dispose = parent.fiber.effect(() => {
|
|
2038
|
-
const remove = runtime.fibers.push(this);
|
|
2039
|
-
return async () => {
|
|
2040
|
-
this.uid = null;
|
|
2041
|
-
emitPluginDisposed(this.context, this);
|
|
2042
|
-
if (this.ctx.registry.has(runtime.callback)) {
|
|
2043
|
-
remove();
|
|
2044
|
-
if (!runtime.fibers.length) this.ctx.registry.delete(runtime.callback);
|
|
2045
|
-
}
|
|
2046
|
-
this._setEpoch(INACTIVE);
|
|
2047
|
-
if (!this.inertia) this._updateState(() => {
|
|
2048
|
-
this.inertia = this._unload();
|
|
2049
|
-
return 5;
|
|
2050
|
-
});
|
|
2051
|
-
while (this.inertia) await this.inertia;
|
|
2052
|
-
};
|
|
2053
|
-
}, "ctx.plugin()");
|
|
2054
|
-
try {
|
|
2055
|
-
this.context.emit("internal/plugin", this);
|
|
2056
|
-
} catch (error) {
|
|
2057
|
-
Promise.resolve(this.dispose()).catch((reason) => this.ctx.logger.error(reason));
|
|
2058
|
-
throw error;
|
|
2059
|
-
}
|
|
2060
|
-
if (this.uid !== null && parent.fiber.state !== 5) {
|
|
2061
|
-
for (const name of Object.keys(this.inject)) this._checkImpl(name);
|
|
2062
|
-
this._refresh();
|
|
2063
|
-
}
|
|
2064
|
-
} else {
|
|
2065
|
-
this.uid = 0;
|
|
2066
|
-
this.ctx = this.context = parent;
|
|
2067
|
-
this.state = 2;
|
|
2068
|
-
this.store = Object.create(null);
|
|
2069
|
-
this._runner = {
|
|
2070
|
-
epoch: "",
|
|
2071
|
-
getOuterStack,
|
|
2072
|
-
execute: () => {},
|
|
2073
|
-
collect
|
|
2074
|
-
};
|
|
2075
|
-
this.dispose = () => this.restart();
|
|
2076
|
-
}
|
|
2077
|
-
}
|
|
2078
|
-
/** The plugin's display name, inherited from the nearest named ancestor, else `'root'`. */
|
|
2079
|
-
get name() {
|
|
2080
|
-
let fiber = this;
|
|
2081
|
-
do {
|
|
2082
|
-
if (fiber.runtime?.name) return fiber.runtime.name;
|
|
2083
|
-
fiber = fiber.parent.fiber;
|
|
2084
|
-
} while (fiber !== fiber.parent.fiber);
|
|
2085
|
-
return "root";
|
|
2086
|
-
}
|
|
2087
|
-
/**
|
|
2088
|
-
* Throw if the fiber has already been disposed.
|
|
2089
|
-
*
|
|
2090
|
-
* @returns nothing when the fiber is still active.
|
|
2091
|
-
* @throws {CordisError} `INACTIVE_EFFECT` when the fiber's uid has been cleared.
|
|
2092
|
-
*/
|
|
2093
|
-
assertActive() {
|
|
2094
|
-
if (this.uid !== null) return;
|
|
2095
|
-
throw new CordisError("INACTIVE_EFFECT");
|
|
1650
|
+
assertActive() {
|
|
1651
|
+
if (this.uid !== null) return;
|
|
1652
|
+
throw new CordisError("INACTIVE_EFFECT");
|
|
2096
1653
|
}
|
|
2097
1654
|
_execute(runner) {
|
|
2098
1655
|
const oldEpoch = runner.epoch;
|
|
@@ -2234,173 +1791,667 @@ var Fiber = class {
|
|
|
2234
1791
|
runner.epoch = false;
|
|
2235
1792
|
return finalizeDisposal(dispose);
|
|
2236
1793
|
};
|
|
2237
|
-
wrapper.then = async (onFulfilled, onRejected) => {
|
|
2238
|
-
return Promise.resolve(task).then(() => disposeAsync).then(onFulfilled, onRejected);
|
|
1794
|
+
wrapper.then = async (onFulfilled, onRejected) => {
|
|
1795
|
+
return Promise.resolve(task).then(() => disposeAsync).then(onFulfilled, onRejected);
|
|
1796
|
+
};
|
|
1797
|
+
return wrapper;
|
|
1798
|
+
}
|
|
1799
|
+
/**
|
|
1800
|
+
* Return metadata for currently registered effects.
|
|
1801
|
+
*
|
|
1802
|
+
* @returns one {@link EffectMeta} tree per labeled live effect.
|
|
1803
|
+
*/
|
|
1804
|
+
getEffects() {
|
|
1805
|
+
return [...this._disposables].map((dispose) => dispose[symbols.effect]).filter(Boolean);
|
|
1806
|
+
}
|
|
1807
|
+
_getState() {
|
|
1808
|
+
if (this.uid === null) return 4;
|
|
1809
|
+
if (this._error) return 3;
|
|
1810
|
+
if (this._runner.epoch !== INACTIVE) return 2;
|
|
1811
|
+
return 0;
|
|
1812
|
+
}
|
|
1813
|
+
_updateState(callback) {
|
|
1814
|
+
const oldState = this.state;
|
|
1815
|
+
this.state = callback() ?? this._getState();
|
|
1816
|
+
if (oldState === this.state) return;
|
|
1817
|
+
this.context.emit("internal/status", this, oldState);
|
|
1818
|
+
if (oldState !== 2 && this.state !== 2) return;
|
|
1819
|
+
for (const key of Reflect.ownKeys(this.ctx.reflect.store)) {
|
|
1820
|
+
const impl = this.ctx.reflect.store[key];
|
|
1821
|
+
if (impl.ctx.fiber !== this) continue;
|
|
1822
|
+
this.ctx.isolate(impl.name, impl.isolate).reflect.notify([impl.name]);
|
|
1823
|
+
}
|
|
1824
|
+
}
|
|
1825
|
+
_checkImpl(name) {
|
|
1826
|
+
const impl = this.ctx.reflect._getImpl(name, true);
|
|
1827
|
+
if (!impl) return delete this._store[name];
|
|
1828
|
+
try {
|
|
1829
|
+
if (impl.check && !impl.check.call(getTraceable(this.ctx, impl.value))) return delete this._store[name];
|
|
1830
|
+
} catch (error) {
|
|
1831
|
+
impl.ctx.logger.error(error);
|
|
1832
|
+
return delete this._store[name];
|
|
1833
|
+
}
|
|
1834
|
+
this._store[name] = impl;
|
|
1835
|
+
}
|
|
1836
|
+
_refresh() {
|
|
1837
|
+
let epoch = `${this._revision}`;
|
|
1838
|
+
for (const name of Object.keys(this.inject)) {
|
|
1839
|
+
const impl = this._store[name];
|
|
1840
|
+
if (!impl) {
|
|
1841
|
+
epoch = INACTIVE;
|
|
1842
|
+
break;
|
|
1843
|
+
}
|
|
1844
|
+
epoch += ":" + impl.uid;
|
|
1845
|
+
}
|
|
1846
|
+
this._setEpoch(epoch);
|
|
1847
|
+
}
|
|
1848
|
+
_setEpoch(epoch) {
|
|
1849
|
+
const oldEpoch = this._runner.epoch;
|
|
1850
|
+
if (epoch === oldEpoch) return;
|
|
1851
|
+
if (this._error) return;
|
|
1852
|
+
this._runner.epoch = epoch;
|
|
1853
|
+
if (this.inertia) return;
|
|
1854
|
+
this._updateState(() => {
|
|
1855
|
+
if (epoch !== INACTIVE && oldEpoch === INACTIVE) {
|
|
1856
|
+
this.inertia = this._reload();
|
|
1857
|
+
return 1;
|
|
1858
|
+
} else {
|
|
1859
|
+
this.inertia = this._unload();
|
|
1860
|
+
return 5;
|
|
1861
|
+
}
|
|
1862
|
+
});
|
|
1863
|
+
}
|
|
1864
|
+
/** Raw input retained for the next activation, without evaluating expressions or validating it. */
|
|
1865
|
+
get rawConfig() {
|
|
1866
|
+
return this.ctx.fiber.config;
|
|
1867
|
+
}
|
|
1868
|
+
/** Retain raw input without changing the running config or triggering an update. */
|
|
1869
|
+
set rawConfig(config) {
|
|
1870
|
+
this.ctx.fiber.config = config;
|
|
1871
|
+
this.ctx.fiber._configRevision++;
|
|
1872
|
+
}
|
|
1873
|
+
/**
|
|
1874
|
+
* The object passed to plugin activation or the latest successful update that retained the instance.
|
|
1875
|
+
* Candidate resolution does not publish it; volatile updates retain its references.
|
|
1876
|
+
* Undefined before activation and readable after unload; callers requiring a live instance check `state`.
|
|
1877
|
+
*/
|
|
1878
|
+
get effectiveConfig() {
|
|
1879
|
+
return this.ctx.fiber._effectiveConfig;
|
|
1880
|
+
}
|
|
1881
|
+
/**
|
|
1882
|
+
* Evaluate and validate a candidate using this fiber's `internal/config` hooks and runtime schema.
|
|
1883
|
+
* Does not publish the result, replace raw input, or commit running volatile references.
|
|
1884
|
+
* Required injections must be available when a hook uses them.
|
|
1885
|
+
* @param config Raw candidate input.
|
|
1886
|
+
* @returns The candidate's resolved config, retaining the schema's result identity.
|
|
1887
|
+
* @throws {ValidationError} when the runtime schema rejects the candidate; hook errors propagate.
|
|
1888
|
+
*/
|
|
1889
|
+
resolveConfig(config) {
|
|
1890
|
+
const fiber = this.ctx.fiber;
|
|
1891
|
+
return fiber.context.waterfall("internal/config", fiber, () => config);
|
|
1892
|
+
}
|
|
1893
|
+
async _reload() {
|
|
1894
|
+
this.committed = { ...this._store };
|
|
1895
|
+
for (const impl of Object.values(this.committed)) {
|
|
1896
|
+
if (impl.ctx.fiber === this) continue;
|
|
1897
|
+
impl.dependents.add(this);
|
|
1898
|
+
}
|
|
1899
|
+
const oldEpoch = this._runner.epoch;
|
|
1900
|
+
try {
|
|
1901
|
+
await Promise.resolve();
|
|
1902
|
+
if (this._runner.epoch === oldEpoch) await this._execute(this._runner);
|
|
1903
|
+
} catch (reason) {
|
|
1904
|
+
this.ctx.logger.error(reason);
|
|
1905
|
+
if (this._runner.epoch === oldEpoch) {
|
|
1906
|
+
this._error = reason;
|
|
1907
|
+
this._runner.epoch = INACTIVE;
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1910
|
+
this._updateState(() => {
|
|
1911
|
+
if (this._runner.epoch === oldEpoch) this.inertia = void 0;
|
|
1912
|
+
else {
|
|
1913
|
+
this.inertia = this._unload();
|
|
1914
|
+
return 5;
|
|
1915
|
+
}
|
|
1916
|
+
});
|
|
1917
|
+
}
|
|
1918
|
+
async _unload() {
|
|
1919
|
+
while ([...this.provisions].some((impl) => impl.dependents.size)) await new Promise((resolve) => this._release = resolve);
|
|
1920
|
+
this._release = void 0;
|
|
1921
|
+
await Promise.all(this._disposables.clear().map(async (dispose) => {
|
|
1922
|
+
try {
|
|
1923
|
+
await composeError(async (info) => {
|
|
1924
|
+
await Promise.resolve();
|
|
1925
|
+
info.error = /* @__PURE__ */ new Error();
|
|
1926
|
+
await runDisposable(dispose);
|
|
1927
|
+
}, this._runner.getOuterStack);
|
|
1928
|
+
} catch (reason) {
|
|
1929
|
+
this.ctx.logger.error(reason);
|
|
1930
|
+
}
|
|
1931
|
+
}));
|
|
1932
|
+
for (const impl of Object.values(this.committed ?? {})) {
|
|
1933
|
+
if (!impl.dependents.delete(this) || impl.dependents.size) continue;
|
|
1934
|
+
impl.release?.();
|
|
1935
|
+
impl.ctx.fiber._release?.();
|
|
1936
|
+
}
|
|
1937
|
+
this.committed = void 0;
|
|
1938
|
+
this._updateState(() => {
|
|
1939
|
+
if (this._runner.epoch === INACTIVE) this.inertia = void 0;
|
|
1940
|
+
else {
|
|
1941
|
+
this.inertia = this._reload();
|
|
1942
|
+
return 1;
|
|
1943
|
+
}
|
|
1944
|
+
});
|
|
1945
|
+
}
|
|
1946
|
+
/**
|
|
1947
|
+
* Wait for current lifecycle work and rethrow startup errors.
|
|
1948
|
+
*
|
|
1949
|
+
* @returns this fiber, once it has settled into a stable state.
|
|
1950
|
+
* @throws the config-validation or plugin-startup error, if any.
|
|
1951
|
+
*/
|
|
1952
|
+
async await() {
|
|
1953
|
+
while (this.inertia) await this.inertia;
|
|
1954
|
+
if (this._error) throw this._error;
|
|
1955
|
+
return this;
|
|
1956
|
+
}
|
|
1957
|
+
/**
|
|
1958
|
+
* Dispose and immediately reload this plugin with its current config.
|
|
1959
|
+
*
|
|
1960
|
+
* @returns a promise resolving once the reload settled.
|
|
1961
|
+
* @throws {CordisError} `INACTIVE_EFFECT` when the fiber is already disposed.
|
|
1962
|
+
*/
|
|
1963
|
+
async restart() {
|
|
1964
|
+
const fiber = this.ctx.fiber;
|
|
1965
|
+
fiber.assertActive();
|
|
1966
|
+
fiber._revision++;
|
|
1967
|
+
fiber._refresh();
|
|
1968
|
+
await fiber.await();
|
|
1969
|
+
}
|
|
1970
|
+
/**
|
|
1971
|
+
* Resolve a candidate, retain its raw config and apply it through the update waterfall.
|
|
1972
|
+
* @param config Raw config; pending fibers defer resolution until activation.
|
|
1973
|
+
* @param noSave Suppress the persistence notification when true.
|
|
1974
|
+
* @returns The awaited update/restart result, or undefined when a synchronous listener handles it.
|
|
1975
|
+
* @throws {ValidationError} when an active fiber's candidate is invalid.
|
|
1976
|
+
*/
|
|
1977
|
+
update(config, noSave = false) {
|
|
1978
|
+
const fiber = this.ctx.fiber;
|
|
1979
|
+
fiber.assertActive();
|
|
1980
|
+
const loaded = fiber._runner.epoch !== INACTIVE;
|
|
1981
|
+
const resolved = loaded ? fiber.resolveConfig(config) : void 0;
|
|
1982
|
+
if (!noSave) fiber.context.emit("internal/commit", fiber, config);
|
|
1983
|
+
fiber.config = config;
|
|
1984
|
+
fiber._error = void 0;
|
|
1985
|
+
const configRevision = ++fiber._configRevision;
|
|
1986
|
+
const epoch = fiber._runner.epoch;
|
|
1987
|
+
const committed = fiber.committed;
|
|
1988
|
+
let restarted = false;
|
|
1989
|
+
const restart = () => {
|
|
1990
|
+
restarted = true;
|
|
1991
|
+
return fiber.restart();
|
|
1992
|
+
};
|
|
1993
|
+
const publish = () => {
|
|
1994
|
+
if (!restarted && fiber.uid !== null && fiber._configRevision === configRevision && fiber._runner.epoch === epoch && fiber.committed === committed) fiber._effectiveConfig = resolved;
|
|
2239
1995
|
};
|
|
2240
|
-
|
|
1996
|
+
const result = loaded ? fiber.context.waterfall(fiber, "internal/update", resolved, restart) : restart();
|
|
1997
|
+
if (result === void 0) {
|
|
1998
|
+
publish();
|
|
1999
|
+
return;
|
|
2000
|
+
}
|
|
2001
|
+
const task = Promise.resolve(result).then(publish);
|
|
2002
|
+
task.catch(() => {});
|
|
2003
|
+
return task;
|
|
2004
|
+
}
|
|
2005
|
+
};
|
|
2006
|
+
//#endregion
|
|
2007
|
+
//#region ../../../vendor/cordis/src/events.ts
|
|
2008
|
+
/**
|
|
2009
|
+
* Return whether an event result should stop a bail-style dispatch.
|
|
2010
|
+
*
|
|
2011
|
+
* @param value — a listener's return value.
|
|
2012
|
+
* @returns `true` unless `value` is `null`, `false`, or `undefined`.
|
|
2013
|
+
*/
|
|
2014
|
+
function isBailed(value) {
|
|
2015
|
+
return value !== null && value !== false && value !== void 0;
|
|
2016
|
+
}
|
|
2017
|
+
/**
|
|
2018
|
+
* Event bus installed as `ctx.events` and mixed into every context.
|
|
2019
|
+
*
|
|
2020
|
+
* The service supports concurrent, synchronous, serial, bail, and waterfall
|
|
2021
|
+
* dispatch and automatically disposes listeners with their owning fiber.
|
|
2022
|
+
*/
|
|
2023
|
+
var EventsService = class {
|
|
2024
|
+
ctx;
|
|
2025
|
+
_hooks = Object.create(null);
|
|
2026
|
+
constructor(ctx) {
|
|
2027
|
+
this.ctx = ctx;
|
|
2028
|
+
defineProperty(this, symbols.tracker, {
|
|
2029
|
+
property: "ctx",
|
|
2030
|
+
noShadow: true
|
|
2031
|
+
});
|
|
2032
|
+
this.on("internal/listener", function(name, listener, options) {
|
|
2033
|
+
if (name === "internal/update" && !options.global) {
|
|
2034
|
+
const hooks = this.fiber._hooks["internal/update"] ??= new DisposableList();
|
|
2035
|
+
const method = options.prepend ? "unshift" : "push";
|
|
2036
|
+
return this.fiber.effect(() => hooks[method](listener), "ctx.on(\"internal/update\")");
|
|
2037
|
+
}
|
|
2038
|
+
});
|
|
2039
|
+
this.on("internal/update", function(config, next) {
|
|
2040
|
+
const cbs = [...this._hooks["internal/update"] || []];
|
|
2041
|
+
const _next = () => {
|
|
2042
|
+
return (cbs.shift() ?? next).call(this, config, _next);
|
|
2043
|
+
};
|
|
2044
|
+
return _next();
|
|
2045
|
+
}, {
|
|
2046
|
+
global: true,
|
|
2047
|
+
prepend: true
|
|
2048
|
+
});
|
|
2049
|
+
this.on("internal/config", (fiber, next) => {
|
|
2050
|
+
const config = next();
|
|
2051
|
+
return fiber.runtime ? resolveConfig(fiber.runtime, config) : config;
|
|
2052
|
+
});
|
|
2053
|
+
}
|
|
2054
|
+
_resolve(type, args) {
|
|
2055
|
+
const thisArg = typeof args[0] === "object" || typeof args[0] === "function" ? args.shift() : null;
|
|
2056
|
+
const name = args.shift();
|
|
2057
|
+
if ((typeof name !== "string" || !name.startsWith("internal/")) && this._hooks["internal/dispatch"]?.length) this.emit("internal/dispatch", type, name, args, thisArg);
|
|
2058
|
+
const filter = thisArg?.[Context.filter];
|
|
2059
|
+
return [thisArg, (this._hooks[name] || []).filter((hook) => hook.global || !filter || filter.call(thisArg, hook.ctx)).map((hook) => hook.callback)];
|
|
2241
2060
|
}
|
|
2242
2061
|
/**
|
|
2243
|
-
*
|
|
2062
|
+
* Resolve bound callbacks using the event's context filter.
|
|
2063
|
+
* @param type Dispatch mode reported to observers.
|
|
2064
|
+
* @param args Dispatch arguments, consumed through the event name.
|
|
2065
|
+
* @returns Matching callbacks bound to the dispatch receiver.
|
|
2066
|
+
* DSH retains callback enumeration for per-listener error containment.
|
|
2067
|
+
*/
|
|
2068
|
+
dispatch(type, args) {
|
|
2069
|
+
const [thisArg, callbacks] = this._resolve(type, args);
|
|
2070
|
+
return callbacks.map((callback) => callback.bind(thisArg));
|
|
2071
|
+
}
|
|
2072
|
+
/**
|
|
2073
|
+
* Run listeners concurrently and wait for all of them.
|
|
2244
2074
|
*
|
|
2245
|
-
* @
|
|
2075
|
+
* @param args — optional `this`, the event name, then listener arguments.
|
|
2076
|
+
* @returns a promise resolving once every listener has settled.
|
|
2246
2077
|
*/
|
|
2247
|
-
|
|
2248
|
-
|
|
2078
|
+
async parallel(...args) {
|
|
2079
|
+
const [thisArg, callbacks] = this._resolve("parallel", args);
|
|
2080
|
+
const errors = (await Promise.allSettled(callbacks.map(async (callback) => Reflect.apply(callback, thisArg, args)))).filter((result) => result.status === "rejected");
|
|
2081
|
+
if (errors.length) throw new AggregateError(errors.map((error) => error.reason));
|
|
2249
2082
|
}
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2083
|
+
/**
|
|
2084
|
+
* Run listeners synchronously without waiting for returned promises.
|
|
2085
|
+
*
|
|
2086
|
+
* @param args — optional `this`, the event name, then listener arguments.
|
|
2087
|
+
*/
|
|
2088
|
+
emit(...args) {
|
|
2089
|
+
const [thisArg, callbacks] = this._resolve("emit", args);
|
|
2090
|
+
for (const callback of callbacks) Reflect.apply(callback, thisArg, args);
|
|
2255
2091
|
}
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2092
|
+
/**
|
|
2093
|
+
* Run listeners in order, awaiting each, until one returns a bail value.
|
|
2094
|
+
*
|
|
2095
|
+
* @param args — optional `this`, the event name, then listener arguments.
|
|
2096
|
+
* @returns the first bail value (see {@link isBailed}), if any.
|
|
2097
|
+
*/
|
|
2098
|
+
async serial(...args) {
|
|
2099
|
+
const [thisArg, callbacks] = this._resolve("serial", args);
|
|
2100
|
+
for (const callback of callbacks) {
|
|
2101
|
+
const result = await Reflect.apply(callback, thisArg, args);
|
|
2102
|
+
if (isBailed(result)) return result;
|
|
2266
2103
|
}
|
|
2267
2104
|
}
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2105
|
+
/**
|
|
2106
|
+
* Run listeners synchronously until one returns a bail value.
|
|
2107
|
+
*
|
|
2108
|
+
* @param args — optional `this`, the event name, then listener arguments.
|
|
2109
|
+
* @returns the first bail value (see {@link isBailed}), if any.
|
|
2110
|
+
*/
|
|
2111
|
+
bail(...args) {
|
|
2112
|
+
const [thisArg, callbacks] = this._resolve("bail", args);
|
|
2113
|
+
for (const callback of callbacks) {
|
|
2114
|
+
const result = Reflect.apply(callback, thisArg, args);
|
|
2115
|
+
if (isBailed(result)) return result;
|
|
2276
2116
|
}
|
|
2277
|
-
this._store[name] = impl;
|
|
2278
2117
|
}
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2118
|
+
/**
|
|
2119
|
+
* Compose listeners around the final `next` callback.
|
|
2120
|
+
*
|
|
2121
|
+
* The last dispatch argument is treated as the innermost `next`. Listeners
|
|
2122
|
+
* run outermost-first; a listener that does not call `next()` vetoes the
|
|
2123
|
+
* rest of the chain, including the built-in behavior.
|
|
2124
|
+
*
|
|
2125
|
+
* @param args — optional `this`, the event name, listener arguments, then `next`.
|
|
2126
|
+
* @returns the outermost listener's return value.
|
|
2127
|
+
*/
|
|
2128
|
+
waterfall(...args) {
|
|
2129
|
+
const [thisArg, callbacks] = this._resolve("waterfall", args);
|
|
2130
|
+
const inner = args.pop();
|
|
2131
|
+
const dispatch = () => {
|
|
2132
|
+
const callback = callbacks.shift();
|
|
2133
|
+
if (!callback) return inner();
|
|
2134
|
+
let called = false;
|
|
2135
|
+
const next = () => {
|
|
2136
|
+
if (called) throw new Error("next() called multiple times");
|
|
2137
|
+
called = true;
|
|
2138
|
+
return dispatch();
|
|
2139
|
+
};
|
|
2140
|
+
return Reflect.apply(callback, thisArg, [...args, next]);
|
|
2141
|
+
};
|
|
2142
|
+
return dispatch();
|
|
2143
|
+
}
|
|
2144
|
+
register(label, name, callback, options) {
|
|
2145
|
+
const method = options.prepend ? "unshift" : "push";
|
|
2146
|
+
return this.ctx.fiber.effect(() => {
|
|
2147
|
+
(this._hooks[name] ??= [])[method]({
|
|
2148
|
+
ctx: this.ctx,
|
|
2149
|
+
callback,
|
|
2150
|
+
...options
|
|
2151
|
+
});
|
|
2152
|
+
return () => this.unregister(name, callback);
|
|
2153
|
+
}, label);
|
|
2154
|
+
}
|
|
2155
|
+
unregister(name, callback) {
|
|
2156
|
+
const hooks = this._hooks[name];
|
|
2157
|
+
if (!hooks) return;
|
|
2158
|
+
const index = hooks.findIndex((hook) => hook.callback === callback);
|
|
2159
|
+
if (index >= 0) {
|
|
2160
|
+
hooks.splice(index, 1);
|
|
2161
|
+
if (!hooks.length) delete this._hooks[name];
|
|
2162
|
+
return true;
|
|
2289
2163
|
}
|
|
2290
|
-
this._setEpoch(epoch);
|
|
2291
2164
|
}
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2165
|
+
/**
|
|
2166
|
+
* Register an event listener owned by the current fiber.
|
|
2167
|
+
*
|
|
2168
|
+
* The listener is removed automatically when the fiber unloads. Throws
|
|
2169
|
+
* `CordisError('INACTIVE_EFFECT')` if the fiber is already disposed.
|
|
2170
|
+
*
|
|
2171
|
+
* @param name — the event name to listen for.
|
|
2172
|
+
* @param listener — called with the dispatch arguments.
|
|
2173
|
+
* @param options — listener options; a boolean is shorthand for `prepend`.
|
|
2174
|
+
* @returns a disposer removing the listener; `true` if it was still registered.
|
|
2175
|
+
*/
|
|
2176
|
+
on(name, listener, options) {
|
|
2177
|
+
if (typeof options !== "object") options = { prepend: options };
|
|
2178
|
+
this.ctx.fiber.assertActive();
|
|
2179
|
+
listener = this.ctx.reflect.bind(listener);
|
|
2180
|
+
const result = this.bail(this.ctx, "internal/listener", name, listener, options);
|
|
2181
|
+
if (result) return result;
|
|
2182
|
+
const label = `ctx.on(${typeof name === "string" ? JSON.stringify(name) : name.toString()})`;
|
|
2183
|
+
return this.register(label, name, listener, options);
|
|
2184
|
+
}
|
|
2185
|
+
/**
|
|
2186
|
+
* Register an event listener that disposes itself after the first call.
|
|
2187
|
+
*
|
|
2188
|
+
* @param name — the event name to listen for.
|
|
2189
|
+
* @param listener — called at most once with the dispatch arguments.
|
|
2190
|
+
* @param options — listener options; a boolean is shorthand for `prepend`.
|
|
2191
|
+
* @returns a disposer removing the listener; `true` if it was still registered.
|
|
2192
|
+
*/
|
|
2193
|
+
once(name, listener, options) {
|
|
2194
|
+
const dispose = this.on(name, function(...args) {
|
|
2195
|
+
dispose();
|
|
2196
|
+
return listener.apply(this, args);
|
|
2197
|
+
}, options);
|
|
2198
|
+
return dispose;
|
|
2199
|
+
}
|
|
2200
|
+
};
|
|
2201
|
+
//#endregion
|
|
2202
|
+
//#region ../../../vendor/cordis/src/logger.ts
|
|
2203
|
+
/** Built-in placeholder formatters used by `Logger.format()`. */
|
|
2204
|
+
const defaultFormatters = {
|
|
2205
|
+
s: (value) => String(value),
|
|
2206
|
+
d: (value) => Math.trunc(Number(value)),
|
|
2207
|
+
i: (value) => Math.trunc(Number(value)),
|
|
2208
|
+
f: (value) => Number(value),
|
|
2209
|
+
o: (value) => JSON.stringify(value),
|
|
2210
|
+
O: (value) => JSON.stringify(value),
|
|
2211
|
+
c: () => "",
|
|
2212
|
+
C: (value, exporter, message) => {
|
|
2213
|
+
return Logger.color(exporter, Logger.code(message.name, exporter.colors), value);
|
|
2214
|
+
}
|
|
2215
|
+
};
|
|
2216
|
+
function isAggregateError(error) {
|
|
2217
|
+
return error instanceof Error && Array.isArray(error["errors"]);
|
|
2218
|
+
}
|
|
2219
|
+
/** Logger facade for one named subsystem. */
|
|
2220
|
+
var Logger = class {
|
|
2221
|
+
service;
|
|
2222
|
+
static color(exporter, code, value, decoration = "") {
|
|
2223
|
+
if (!exporter.colors) return "" + value;
|
|
2224
|
+
return `\u001b[3${code < 8 ? code : "8;5;" + code}${exporter.colors >= 2 ? decoration : ""}m${value}\u001b[0m`;
|
|
2225
|
+
}
|
|
2226
|
+
static code(name, level) {
|
|
2227
|
+
let hash = 0;
|
|
2228
|
+
for (let i = 0; i < name.length; i++) {
|
|
2229
|
+
hash = (hash << 3) - hash + name.charCodeAt(i) + 13;
|
|
2230
|
+
hash |= 0;
|
|
2231
|
+
}
|
|
2232
|
+
const colors = !level ? [] : level >= 2 ? c256 : c16;
|
|
2233
|
+
return colors[Math.abs(hash) % colors.length];
|
|
2234
|
+
}
|
|
2235
|
+
static format(exporter, message) {
|
|
2236
|
+
const args = message.args.slice();
|
|
2237
|
+
if (args[0] instanceof Error) {
|
|
2238
|
+
args[0] = args[0].stack || args[0].message;
|
|
2239
|
+
args.unshift("%s");
|
|
2240
|
+
} else if (typeof args[0] !== "string") args.unshift("%o");
|
|
2241
|
+
let format = args.shift();
|
|
2242
|
+
format = format.replace(/%([a-zA-Z%])/g, (match, char) => {
|
|
2243
|
+
if (match === "%%") return "%";
|
|
2244
|
+
const formatter = exporter.formatters?.[char] ?? defaultFormatters[char];
|
|
2245
|
+
if (typeof formatter === "function") return formatter(args.shift(), exporter, message);
|
|
2246
|
+
return match;
|
|
2305
2247
|
});
|
|
2248
|
+
const oFormatter = exporter.formatters?.o ?? defaultFormatters.o;
|
|
2249
|
+
for (let arg of args) {
|
|
2250
|
+
if (typeof arg === "object" && arg) arg = oFormatter(arg, exporter, message);
|
|
2251
|
+
format += " " + arg;
|
|
2252
|
+
}
|
|
2253
|
+
const { maxLength = 10240 } = exporter;
|
|
2254
|
+
return format.split(/\r?\n/g).map((line) => {
|
|
2255
|
+
return line.slice(0, maxLength) + (line.length > maxLength ? "..." : "");
|
|
2256
|
+
}).join("\n");
|
|
2306
2257
|
}
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2258
|
+
constructor(options, service) {
|
|
2259
|
+
this.service = service;
|
|
2260
|
+
Object.assign(this, options);
|
|
2261
|
+
this.error = this._method("error", 0);
|
|
2262
|
+
this.info = this._method("info", 2);
|
|
2263
|
+
this.warn = this._method("warn", 1);
|
|
2264
|
+
this.debug = this._method("debug", 3);
|
|
2310
2265
|
}
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
this._error = void 0;
|
|
2266
|
+
_method(type, level) {
|
|
2267
|
+
return (...args) => {
|
|
2268
|
+
if (args.length === 1 && args[0] instanceof Error) {
|
|
2269
|
+
if (args[0].cause) this[type](args[0].cause);
|
|
2270
|
+
else if (isAggregateError(args[0])) {
|
|
2271
|
+
args[0].errors.forEach((error) => this[type](error));
|
|
2272
|
+
return;
|
|
2273
|
+
}
|
|
2320
2274
|
}
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
this.
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2275
|
+
const sn = ++this.service._snMessage;
|
|
2276
|
+
const ts = Date.now();
|
|
2277
|
+
for (const exporter of this.service.exporters.values()) {
|
|
2278
|
+
if ((exporter.levels?.[this.name] ?? exporter.levels?.default ?? this.level ?? 2) < level) continue;
|
|
2279
|
+
const message = {
|
|
2280
|
+
sn,
|
|
2281
|
+
ts,
|
|
2282
|
+
type,
|
|
2283
|
+
level,
|
|
2284
|
+
name: this.name,
|
|
2285
|
+
...this.meta,
|
|
2286
|
+
args
|
|
2287
|
+
};
|
|
2288
|
+
exporter.export(message);
|
|
2331
2289
|
}
|
|
2332
|
-
}
|
|
2290
|
+
};
|
|
2333
2291
|
}
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2292
|
+
};
|
|
2293
|
+
/** ANSI 16-color palette indexes used for logger name coloring. */
|
|
2294
|
+
const c16 = [
|
|
2295
|
+
6,
|
|
2296
|
+
2,
|
|
2297
|
+
3,
|
|
2298
|
+
4,
|
|
2299
|
+
5,
|
|
2300
|
+
1
|
|
2301
|
+
];
|
|
2302
|
+
/** ANSI 256-color palette indexes used for logger name coloring. */
|
|
2303
|
+
const c256 = [
|
|
2304
|
+
20,
|
|
2305
|
+
21,
|
|
2306
|
+
26,
|
|
2307
|
+
27,
|
|
2308
|
+
32,
|
|
2309
|
+
33,
|
|
2310
|
+
38,
|
|
2311
|
+
39,
|
|
2312
|
+
40,
|
|
2313
|
+
41,
|
|
2314
|
+
42,
|
|
2315
|
+
43,
|
|
2316
|
+
44,
|
|
2317
|
+
45,
|
|
2318
|
+
56,
|
|
2319
|
+
57,
|
|
2320
|
+
62,
|
|
2321
|
+
63,
|
|
2322
|
+
68,
|
|
2323
|
+
69,
|
|
2324
|
+
74,
|
|
2325
|
+
75,
|
|
2326
|
+
76,
|
|
2327
|
+
77,
|
|
2328
|
+
78,
|
|
2329
|
+
79,
|
|
2330
|
+
80,
|
|
2331
|
+
81,
|
|
2332
|
+
92,
|
|
2333
|
+
93,
|
|
2334
|
+
98,
|
|
2335
|
+
99,
|
|
2336
|
+
112,
|
|
2337
|
+
113,
|
|
2338
|
+
129,
|
|
2339
|
+
134,
|
|
2340
|
+
135,
|
|
2341
|
+
148,
|
|
2342
|
+
149,
|
|
2343
|
+
160,
|
|
2344
|
+
161,
|
|
2345
|
+
162,
|
|
2346
|
+
163,
|
|
2347
|
+
164,
|
|
2348
|
+
165,
|
|
2349
|
+
166,
|
|
2350
|
+
167,
|
|
2351
|
+
168,
|
|
2352
|
+
169,
|
|
2353
|
+
170,
|
|
2354
|
+
171,
|
|
2355
|
+
172,
|
|
2356
|
+
173,
|
|
2357
|
+
178,
|
|
2358
|
+
179,
|
|
2359
|
+
184,
|
|
2360
|
+
185,
|
|
2361
|
+
196,
|
|
2362
|
+
197,
|
|
2363
|
+
198,
|
|
2364
|
+
199,
|
|
2365
|
+
200,
|
|
2366
|
+
201,
|
|
2367
|
+
202,
|
|
2368
|
+
203,
|
|
2369
|
+
204,
|
|
2370
|
+
205,
|
|
2371
|
+
206,
|
|
2372
|
+
207,
|
|
2373
|
+
208,
|
|
2374
|
+
209,
|
|
2375
|
+
214,
|
|
2376
|
+
215,
|
|
2377
|
+
220,
|
|
2378
|
+
221
|
|
2379
|
+
];
|
|
2380
|
+
/**
|
|
2381
|
+
* Built-in logging service.
|
|
2382
|
+
*
|
|
2383
|
+
* Call `ctx.logger()` to create a named logger, or call `ctx.logger.info()`
|
|
2384
|
+
* directly to log with the current fiber-derived name.
|
|
2385
|
+
*/
|
|
2386
|
+
var LoggerService = class LoggerService {
|
|
2387
|
+
bufferSize = 1e3;
|
|
2388
|
+
buffer = [];
|
|
2389
|
+
ctx;
|
|
2390
|
+
_snMessage = 0;
|
|
2391
|
+
_snExporter = 0;
|
|
2392
|
+
exporters = /* @__PURE__ */ new Map();
|
|
2393
|
+
constructor(ctx) {
|
|
2394
|
+
const tracker = {
|
|
2395
|
+
property: "ctx",
|
|
2396
|
+
noShadow: true
|
|
2397
|
+
};
|
|
2398
|
+
const self = createCallable("logger", joinPrototype(Object.getPrototypeOf(this), Function.prototype), tracker);
|
|
2399
|
+
Object.assign(self, this);
|
|
2400
|
+
self.ctx = ctx;
|
|
2401
|
+
defineProperty(self, symbols.tracker, tracker);
|
|
2402
|
+
self.exporter({
|
|
2403
|
+
colors: 3,
|
|
2404
|
+
export: (message) => {
|
|
2405
|
+
self.buffer.push(message);
|
|
2406
|
+
const overflow = self.buffer.length - self.bufferSize;
|
|
2407
|
+
if (overflow === 1) self.buffer.shift();
|
|
2408
|
+
else if (overflow > 1) self.buffer.splice(0, overflow);
|
|
2352
2409
|
}
|
|
2353
2410
|
});
|
|
2411
|
+
return self;
|
|
2354
2412
|
}
|
|
2355
2413
|
/**
|
|
2356
|
-
*
|
|
2357
|
-
*
|
|
2358
|
-
* @returns this fiber, once it has settled into a stable state.
|
|
2359
|
-
* @throws the config-validation or plugin-startup error, if any.
|
|
2360
|
-
*/
|
|
2361
|
-
async await() {
|
|
2362
|
-
while (this.inertia) await this.inertia;
|
|
2363
|
-
if (this._error) throw this._error;
|
|
2364
|
-
return this;
|
|
2365
|
-
}
|
|
2366
|
-
/**
|
|
2367
|
-
* Dispose and immediately reload this plugin with its current config.
|
|
2414
|
+
* Register an exporter and dispose it with the current fiber.
|
|
2368
2415
|
*
|
|
2369
|
-
* @
|
|
2370
|
-
* @
|
|
2416
|
+
* @param exporter — the sink that receives structured log messages.
|
|
2417
|
+
* @returns a disposer that removes the exporter.
|
|
2371
2418
|
*/
|
|
2372
|
-
|
|
2373
|
-
this.
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2419
|
+
exporter(exporter) {
|
|
2420
|
+
return this.ctx.effect(() => {
|
|
2421
|
+
const id = ++this._snExporter;
|
|
2422
|
+
this.exporters.set(id, exporter);
|
|
2423
|
+
return () => this.exporters.delete(id);
|
|
2424
|
+
}, "ctx.logger.exporter()");
|
|
2377
2425
|
}
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
* @param config — the new raw config; validated before anything restarts.
|
|
2385
|
-
* @param noSave — hint for persistence hooks not to write the change back.
|
|
2386
|
-
* @returns nothing; the restart runs behind the `internal/update` waterfall.
|
|
2387
|
-
* @throws {ValidationError} when the new config fails validation.
|
|
2388
|
-
*/
|
|
2389
|
-
update(config, noSave = false) {
|
|
2390
|
-
this.assertActive();
|
|
2391
|
-
this._config = config;
|
|
2392
|
-
if (this.state !== 2) {
|
|
2393
|
-
this._error = void 0;
|
|
2394
|
-
this._setEpoch(INACTIVE);
|
|
2395
|
-
this._refresh();
|
|
2396
|
-
return;
|
|
2426
|
+
_resolveConfig() {
|
|
2427
|
+
let intercept = this.ctx[symbols.intercept];
|
|
2428
|
+
const configs = [];
|
|
2429
|
+
while ("logger" in intercept) {
|
|
2430
|
+
if (Object.hasOwn(intercept, "logger")) configs.unshift(intercept["logger"]);
|
|
2431
|
+
intercept = Object.getPrototypeOf(intercept);
|
|
2397
2432
|
}
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2433
|
+
return Object.assign({}, ...configs);
|
|
2434
|
+
}
|
|
2435
|
+
[symbols.invoke](name) {
|
|
2436
|
+
const config = this._resolveConfig();
|
|
2437
|
+
const fiber = (this[symbols.caller] ?? this.ctx).fiber;
|
|
2438
|
+
name ??= config.name;
|
|
2439
|
+
name ??= hyphenate(fiber.name);
|
|
2440
|
+
return new Logger({
|
|
2441
|
+
name,
|
|
2442
|
+
level: config.level,
|
|
2443
|
+
meta: { fiber: new WeakRef(fiber) }
|
|
2444
|
+
}, this);
|
|
2445
|
+
}
|
|
2446
|
+
static {
|
|
2447
|
+
for (const type of [
|
|
2448
|
+
"error",
|
|
2449
|
+
"info",
|
|
2450
|
+
"warn",
|
|
2451
|
+
"debug"
|
|
2452
|
+
]) LoggerService.prototype[type] = function(...args) {
|
|
2453
|
+
return this()[type](...args);
|
|
2454
|
+
};
|
|
2404
2455
|
}
|
|
2405
2456
|
};
|
|
2406
2457
|
//#endregion
|
|
@@ -2432,12 +2483,14 @@ var ReflectService = class {
|
|
|
2432
2483
|
try {
|
|
2433
2484
|
const def = target.reflect.props[prop];
|
|
2434
2485
|
if (def?.type === "accessor") return def.get.call(ctx, ctx[symbols.receiver], error);
|
|
2435
|
-
|
|
2486
|
+
const defSite = ctx[symbols.shadow] ?? ctx;
|
|
2487
|
+
if (!defSite.fiber.runtime) return ctx.reflect.get(prop, false);
|
|
2436
2488
|
return ctx.events.waterfall("internal/get", ctx, prop, error, () => {
|
|
2437
|
-
const key =
|
|
2438
|
-
let fiber =
|
|
2489
|
+
const key = defSite[symbols.isolate][prop];
|
|
2490
|
+
let fiber = defSite.fiber;
|
|
2439
2491
|
while (true) {
|
|
2440
|
-
|
|
2492
|
+
let impl = fiber.committed?.[prop];
|
|
2493
|
+
for (const provision of fiber.provisions) if (provision.name === prop && provision.ctx[symbols.isolate][prop] === key) impl = provision;
|
|
2441
2494
|
if (impl) return getTraceable(ctx, impl.value);
|
|
2442
2495
|
if (prop in fiber.inject) {
|
|
2443
2496
|
error.message = `cannot get required service "${prop}" in inactive context`;
|
|
@@ -2482,6 +2535,7 @@ var ReflectService = class {
|
|
|
2482
2535
|
store = Object.create(null);
|
|
2483
2536
|
/** Declared context properties (services and accessors), by name. */
|
|
2484
2537
|
props = Object.create(null);
|
|
2538
|
+
_implCounter = 0;
|
|
2485
2539
|
constructor(ctx) {
|
|
2486
2540
|
this.ctx = ctx;
|
|
2487
2541
|
defineProperty(this, symbols.tracker, {
|
|
@@ -2522,7 +2576,7 @@ var ReflectService = class {
|
|
|
2522
2576
|
const key = this.ctx[symbols.isolate][name];
|
|
2523
2577
|
const impl = key && this.store[key];
|
|
2524
2578
|
if (!impl) return;
|
|
2525
|
-
if (strict && impl.fiber.state !== 2) return;
|
|
2579
|
+
if (strict && impl.ctx.fiber.state !== 2) return;
|
|
2526
2580
|
return impl;
|
|
2527
2581
|
}
|
|
2528
2582
|
/**
|
|
@@ -2538,7 +2592,7 @@ var ReflectService = class {
|
|
|
2538
2592
|
const key = this.ctx[symbols.isolate][name];
|
|
2539
2593
|
const impl = this.store[key];
|
|
2540
2594
|
if (!impl) throw new Error(`cannot set property "${name}" without provide`);
|
|
2541
|
-
if (impl.fiber !== this.ctx.fiber) throw new Error(`cannot set property "${name}" in multiple fibers`);
|
|
2595
|
+
if (impl.ctx.fiber !== this.ctx.fiber) throw new Error(`cannot set property "${name}" in multiple fibers`);
|
|
2542
2596
|
impl.value = value;
|
|
2543
2597
|
return true;
|
|
2544
2598
|
}
|
|
@@ -2560,20 +2614,27 @@ var ReflectService = class {
|
|
|
2560
2614
|
this.ctx.root[symbols.isolate][name] ??= Symbol(name);
|
|
2561
2615
|
const key = this.ctx[symbols.isolate][name];
|
|
2562
2616
|
const impl = {
|
|
2617
|
+
uid: ++this._implCounter,
|
|
2563
2618
|
name,
|
|
2564
2619
|
value,
|
|
2565
|
-
|
|
2566
|
-
check
|
|
2620
|
+
ctx: this.ctx,
|
|
2621
|
+
check,
|
|
2622
|
+
isolate: key,
|
|
2623
|
+
dependents: /* @__PURE__ */ new Set()
|
|
2567
2624
|
};
|
|
2568
|
-
if (this.store[key]) throw new Error(`service "${name}" has been registered at <${this.store[key].fiber.name}>`);
|
|
2625
|
+
if (this.store[key]) throw new Error(`service "${name}" has been registered at <${this.store[key].ctx.fiber.name}>`);
|
|
2569
2626
|
this.store[key] = impl;
|
|
2570
|
-
this.ctx.fiber.
|
|
2627
|
+
this.ctx.fiber.provisions.add(impl);
|
|
2571
2628
|
if (this.ctx.fiber.state === 2) this.notify([name]);
|
|
2572
2629
|
return async () => {
|
|
2573
|
-
delete this.store[
|
|
2574
|
-
|
|
2575
|
-
await Promise
|
|
2576
|
-
|
|
2630
|
+
if (this.store[impl.isolate] === impl) delete this.store[impl.isolate];
|
|
2631
|
+
this.ctx.isolate(name, impl.isolate).reflect.notify([name]);
|
|
2632
|
+
await new Promise((resolve) => {
|
|
2633
|
+
impl.release = resolve;
|
|
2634
|
+
if (!impl.dependents.size) resolve();
|
|
2635
|
+
});
|
|
2636
|
+
impl.release = void 0;
|
|
2637
|
+
this.ctx.fiber.provisions.delete(impl);
|
|
2577
2638
|
};
|
|
2578
2639
|
}, `ctx.provide(${JSON.stringify(name)})`);
|
|
2579
2640
|
}
|
|
@@ -2582,10 +2643,8 @@ var ReflectService = class {
|
|
|
2582
2643
|
*
|
|
2583
2644
|
* @param names — the service names that changed.
|
|
2584
2645
|
* @param filter — restricts notification to matching isolation scopes.
|
|
2585
|
-
* @returns the fibers whose dependency state was refreshed.
|
|
2586
2646
|
*/
|
|
2587
2647
|
notify(names, filter = (ctx, name) => ctx[symbols.isolate][name] === this.ctx[symbols.isolate][name]) {
|
|
2588
|
-
const fibers = [];
|
|
2589
2648
|
for (const runtime of this.ctx.registry.values()) for (const fiber of runtime.fibers) {
|
|
2590
2649
|
let hasUpdate = false;
|
|
2591
2650
|
for (const name of names) {
|
|
@@ -2596,14 +2655,12 @@ var ReflectService = class {
|
|
|
2596
2655
|
}
|
|
2597
2656
|
if (!hasUpdate) continue;
|
|
2598
2657
|
fiber._refresh();
|
|
2599
|
-
fibers.push(fiber);
|
|
2600
2658
|
}
|
|
2601
2659
|
for (const name of names) {
|
|
2602
2660
|
const self = Object.create(this.ctx);
|
|
2603
2661
|
self[symbols.filter] = (target) => filter(target, name);
|
|
2604
2662
|
this.ctx.events.emit(self, "internal/service", name, this._getImpl(name, false)?.value);
|
|
2605
2663
|
}
|
|
2606
|
-
return fibers;
|
|
2607
2664
|
}
|
|
2608
2665
|
/**
|
|
2609
2666
|
* Define a computed context property backed by get/set hooks.
|
|
@@ -5737,12 +5794,17 @@ var LlmError = class extends HarnessError {
|
|
|
5737
5794
|
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 LlmError(`adapter returned invalid or duplicate model metadata for provider "${provider}"`, "INVALID_CATALOG");
|
|
5738
5795
|
seen.add(model.id);
|
|
5739
5796
|
const inputModalities = this.detachedModalities(model.inputModalities);
|
|
5797
|
+
const badge = model.badge;
|
|
5740
5798
|
return {
|
|
5741
5799
|
provider: model.provider,
|
|
5742
5800
|
id: model.id,
|
|
5743
5801
|
name: model.name,
|
|
5744
5802
|
...model.description === void 0 ? {} : { description: model.description },
|
|
5745
|
-
...inputModalities === void 0 ? {} : { inputModalities }
|
|
5803
|
+
...inputModalities === void 0 ? {} : { inputModalities },
|
|
5804
|
+
...badge === void 0 ? {} : { badge: {
|
|
5805
|
+
text: typeof badge.text === "string" ? badge.text : { ...badge.text },
|
|
5806
|
+
tone: badge.tone
|
|
5807
|
+
} }
|
|
5746
5808
|
};
|
|
5747
5809
|
});
|
|
5748
5810
|
}
|
|
@@ -6373,7 +6435,7 @@ function invokeContainedSessionObservers(ctx, name, id, args, callbacks) {
|
|
|
6373
6435
|
ctx.logger.warn(`session "${id}": ${name} listener threw: ${String(error)}`);
|
|
6374
6436
|
}
|
|
6375
6437
|
}
|
|
6376
|
-
/** Store
|
|
6438
|
+
/** Store-owned Sessions retain a null entry while unentered; absent keys are independent. */
|
|
6377
6439
|
const attachments = /* @__PURE__ */ new WeakMap();
|
|
6378
6440
|
/**
|
|
6379
6441
|
* Grammar of a {@link PluginRecordType}: `plugin:` followed by
|
|
@@ -6572,6 +6634,9 @@ var Session = class Session {
|
|
|
6572
6634
|
* the log, the append is committed: observer failures are logged and
|
|
6573
6635
|
* contained per listener, so they do not change the return value or prevent
|
|
6574
6636
|
* later listeners from observing the same accepted event.
|
|
6637
|
+
* Independent Sessions append without notifying store observers. Once a store
|
|
6638
|
+
* prepares or enters the instance, writes require a completed creation
|
|
6639
|
+
* announcement and remain disabled after removal.
|
|
6575
6640
|
*
|
|
6576
6641
|
* @param type - The event type (key of {@link SessionEventMap}).
|
|
6577
6642
|
* @param data - The event payload; must be JSON-serializable.
|
|
@@ -6587,7 +6652,9 @@ var Session = class Session {
|
|
|
6587
6652
|
* @returns the logged event — its assigned `seq`/`time` plus the SNAPSHOT of
|
|
6588
6653
|
* `data` that entered the log, so reading `event.data` back sees the logged
|
|
6589
6654
|
* value, never the caller's still-mutable input.
|
|
6590
|
-
* @throws if
|
|
6655
|
+
* @throws if a store-owned Session is unentered or its creation announcement
|
|
6656
|
+
* has not completed, or if `data` or surface
|
|
6657
|
+
* metadata is not losslessly JSON-serializable
|
|
6591
6658
|
* (BigInt, function, symbol, undefined, negative zero, non-finite number,
|
|
6592
6659
|
* circular reference, sparse array, or an exotic object such as
|
|
6593
6660
|
* Map/Set/Date/class instance), or when the candidate violates the
|
|
@@ -6603,6 +6670,7 @@ var Session = class Session {
|
|
|
6603
6670
|
* rejects before the log changes.
|
|
6604
6671
|
*/
|
|
6605
6672
|
append(type, data, ...opts) {
|
|
6673
|
+
this.publicationEntry();
|
|
6606
6674
|
const surfaceOpts = opts[0];
|
|
6607
6675
|
const surfaceMetadata = {
|
|
6608
6676
|
...surfaceOpts?.sourceEventSeqs === void 0 ? {} : { sourceEventSeqs: surfaceOpts.sourceEventSeqs },
|
|
@@ -6632,6 +6700,7 @@ var Session = class Session {
|
|
|
6632
6700
|
* @returns the record's sequence number.
|
|
6633
6701
|
*/
|
|
6634
6702
|
#appendRecord(type, data) {
|
|
6703
|
+
this.publicationEntry();
|
|
6635
6704
|
const dataSnapshot = snapshotJsonValue(data);
|
|
6636
6705
|
if (dataSnapshot === void 0) throw new Error(`plugin record "${type}" carries non-JSON-serializable data`);
|
|
6637
6706
|
const entry = this.publicationEntry();
|
|
@@ -6647,12 +6716,13 @@ var Session = class Session {
|
|
|
6647
6716
|
return record.seq;
|
|
6648
6717
|
}
|
|
6649
6718
|
/**
|
|
6650
|
-
*
|
|
6651
|
-
*
|
|
6652
|
-
* @returns the attachment, or undefined for a detached Session.
|
|
6719
|
+
* Require announced membership for store-owned Sessions and refuse reentrant publication.
|
|
6720
|
+
* @returns the current store attachment, or undefined for an independent Session.
|
|
6653
6721
|
*/
|
|
6654
6722
|
publicationEntry() {
|
|
6655
6723
|
const entry = attachments.get(this);
|
|
6724
|
+
if (entry === null) throw new Error(`session "${this.id}" cannot append outside a SessionStore`);
|
|
6725
|
+
if (entry !== void 0 && entry.announcement !== "complete") throw new Error(`session "${this.id}" cannot append before session/created completes`);
|
|
6656
6726
|
if (entry?.appending) throw new Error("session append cannot reenter while another append is being published");
|
|
6657
6727
|
return entry;
|
|
6658
6728
|
}
|
|
@@ -6666,20 +6736,19 @@ var Session = class Session {
|
|
|
6666
6736
|
this.surfaceManager.validateNext(event);
|
|
6667
6737
|
if (entry !== void 0) entry.appending = true;
|
|
6668
6738
|
try {
|
|
6669
|
-
let callbacks;
|
|
6670
6739
|
const callbackArgs = [this, event];
|
|
6671
|
-
|
|
6740
|
+
const callbacks = entry === void 0 ? void 0 : collectSessionCallbacks(entry.emitCtx, [
|
|
6672
6741
|
entry.carrier,
|
|
6673
6742
|
"session/event",
|
|
6674
6743
|
...callbackArgs
|
|
6675
6744
|
]);
|
|
6676
6745
|
this.log.push(event);
|
|
6677
6746
|
this.eventsSnapshot = void 0;
|
|
6678
|
-
if (
|
|
6747
|
+
if (entry !== void 0 && callbacks !== void 0) invokeContainedSessionObservers(entry.emitCtx, "session/event", entry.id, callbackArgs, callbacks);
|
|
6679
6748
|
} finally {
|
|
6680
6749
|
if (entry !== void 0) {
|
|
6681
6750
|
entry.appending = false;
|
|
6682
|
-
if (entry.detachRequested &&
|
|
6751
|
+
if (entry.detachRequested && entry.announcement !== "dispatching") entry.detach();
|
|
6683
6752
|
}
|
|
6684
6753
|
}
|
|
6685
6754
|
}
|
|
@@ -7514,11 +7583,8 @@ const RELEASED_V0_EVENT_DISPOSITIONS = Object.freeze({
|
|
|
7514
7583
|
]),
|
|
7515
7584
|
"step/end": disposition(["turn", "step"]),
|
|
7516
7585
|
"step/start": disposition(["turn", "step"]),
|
|
7517
|
-
"subagent/descriptor": disposition([
|
|
7586
|
+
"subagent/descriptor": disposition(["version", "provider"], [
|
|
7518
7587
|
"mode",
|
|
7519
|
-
"version",
|
|
7520
|
-
"provider"
|
|
7521
|
-
], [
|
|
7522
7588
|
"label",
|
|
7523
7589
|
"agentProvider",
|
|
7524
7590
|
"agentModel",
|
|
@@ -7606,6 +7672,43 @@ const RELEASED_V0_EVENT_DISPOSITIONS = Object.freeze({
|
|
|
7606
7672
|
});
|
|
7607
7673
|
Object.freeze(Object.keys(RELEASED_V0_EVENT_DISPOSITIONS).sort((left, right) => left.localeCompare(right, "en")));
|
|
7608
7674
|
//#endregion
|
|
7675
|
+
//#region ../../util/time/src/instant.ts
|
|
7676
|
+
/** Inclusive lower epoch-millisecond bound of a four-digit-year RFC 3339 UTC instant. */
|
|
7677
|
+
const MIN_FOUR_DIGIT_YEAR_MS = Date.parse("0001-01-01T00:00:00.000Z");
|
|
7678
|
+
/** Inclusive upper epoch-millisecond bound of a four-digit-year RFC 3339 UTC instant. */
|
|
7679
|
+
const MAX_FOUR_DIGIT_YEAR_MS = Date.parse("9999-12-31T23:59:59.999Z");
|
|
7680
|
+
/** Canonical four-digit-year RFC 3339 UTC instant with mandatory milliseconds. */
|
|
7681
|
+
const UTC_INSTANT = /^(?!0000)\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])T(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d\.\d{3}Z$/;
|
|
7682
|
+
new RegExp(String.raw`^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})` + String.raw`T(?<hour>\d{2}):(?<minute>\d{2}):(?<second>\d{2})` + String.raw`(?:\.(?<fraction>\d{1,3}))?(?<zone>Z|(?<sign>[+-])` + String.raw`(?<offsetHour>\d{2}):(?<offsetMinute>\d{2}))$`);
|
|
7683
|
+
/** Reject with one stable reason. */
|
|
7684
|
+
function rejected(reason) {
|
|
7685
|
+
return Object.freeze({
|
|
7686
|
+
kind: "rejected",
|
|
7687
|
+
reason
|
|
7688
|
+
});
|
|
7689
|
+
}
|
|
7690
|
+
/** Whether an integral epoch is inside the four-digit-year range. */
|
|
7691
|
+
function inFourDigitYearRange(epoch) {
|
|
7692
|
+
return Number.isSafeInteger(epoch) && epoch >= MIN_FOUR_DIGIT_YEAR_MS && epoch <= MAX_FOUR_DIGIT_YEAR_MS;
|
|
7693
|
+
}
|
|
7694
|
+
/**
|
|
7695
|
+
* Validate one canonical four-digit-year RFC 3339 UTC instant.
|
|
7696
|
+
*
|
|
7697
|
+
* The accepted profile carries exactly three fractional digits and a `Z`, and
|
|
7698
|
+
* every year from 0001 through 9999 whose calendar date exists is representable.
|
|
7699
|
+
* @param value - Untrusted candidate instant.
|
|
7700
|
+
* @returns The epoch milliseconds, or the reason the text is not the canonical profile.
|
|
7701
|
+
*/
|
|
7702
|
+
function fourDigitYearEpoch(value) {
|
|
7703
|
+
if (!UTC_INSTANT.test(value)) return rejected("not_rfc3339");
|
|
7704
|
+
const epoch = Date.parse(value);
|
|
7705
|
+
if (!Number.isFinite(epoch) || !inFourDigitYearRange(epoch) || new Date(epoch).toISOString() !== value) return rejected("not_a_calendar_date");
|
|
7706
|
+
return Object.freeze({
|
|
7707
|
+
kind: "accepted",
|
|
7708
|
+
epoch
|
|
7709
|
+
});
|
|
7710
|
+
}
|
|
7711
|
+
//#endregion
|
|
7609
7712
|
//#region ../session-format-v0-to-v1/src/validation-helpers.ts
|
|
7610
7713
|
/**
|
|
7611
7714
|
* Require one plain JSON object.
|
|
@@ -8638,7 +8741,7 @@ function scheduleIdValue(value, label) {
|
|
|
8638
8741
|
if (value.trim() !== value) throw new SessionFormatError(`${label} must not have surrounding whitespace`);
|
|
8639
8742
|
}
|
|
8640
8743
|
function instantValue(value, label) {
|
|
8641
|
-
if (typeof value !== "string" ||
|
|
8744
|
+
if (typeof value !== "string" || fourDigitYearEpoch(value).kind !== "accepted") throw new SessionFormatError(`${label} must be a canonical UTC instant`);
|
|
8642
8745
|
}
|
|
8643
8746
|
function titleSourceValue(value, label) {
|
|
8644
8747
|
const source = releasedV0Record(value, label);
|
|
@@ -8656,10 +8759,27 @@ function modelRouteValue(value, label) {
|
|
|
8656
8759
|
nonEmptyString(route["provider"], `${label} provider`);
|
|
8657
8760
|
nonEmptyString(route["model"], `${label} model`);
|
|
8658
8761
|
}
|
|
8762
|
+
/** `subagent/descriptor` versions that format v0 logs contain. */
|
|
8763
|
+
const SUBAGENT_DESCRIPTOR_VERSIONS = [
|
|
8764
|
+
1,
|
|
8765
|
+
2,
|
|
8766
|
+
3
|
|
8767
|
+
];
|
|
8659
8768
|
function subagentDescriptorValue(data, label) {
|
|
8660
|
-
literalValue(data["version"],
|
|
8769
|
+
literalValue(data["version"], SUBAGENT_DESCRIPTOR_VERSIONS, `${label} version`);
|
|
8661
8770
|
nonEmptyString(data["provider"], `${label} provider`);
|
|
8662
|
-
|
|
8771
|
+
const composition = [
|
|
8772
|
+
"agentProvider",
|
|
8773
|
+
"agentModel",
|
|
8774
|
+
"persona",
|
|
8775
|
+
"toolFilter"
|
|
8776
|
+
];
|
|
8777
|
+
if (data["version"] === 1) assertReleasedV0Keys(data, [
|
|
8778
|
+
"version",
|
|
8779
|
+
"provider",
|
|
8780
|
+
"label"
|
|
8781
|
+
], composition, `${label} data`);
|
|
8782
|
+
else if (data["mode"] === "one-shot") {
|
|
8663
8783
|
assertReleasedV0Keys(data, [
|
|
8664
8784
|
"mode",
|
|
8665
8785
|
"version",
|
|
@@ -8667,21 +8787,30 @@ function subagentDescriptorValue(data, label) {
|
|
|
8667
8787
|
], ["label"], `${label} data`);
|
|
8668
8788
|
if (data["label"] !== void 0) stringValue(data["label"], `${label} label`);
|
|
8669
8789
|
return;
|
|
8790
|
+
} else {
|
|
8791
|
+
literalValue(data["mode"], ["continuable"], `${label} mode`);
|
|
8792
|
+
assertReleasedV0Keys(data, [
|
|
8793
|
+
"mode",
|
|
8794
|
+
"version",
|
|
8795
|
+
"provider",
|
|
8796
|
+
"label"
|
|
8797
|
+
], data["version"] === 3 ? [...composition, "agentReasoningEffort"] : composition, `${label} data`);
|
|
8670
8798
|
}
|
|
8671
|
-
|
|
8672
|
-
nonEmptyString
|
|
8799
|
+
const strict = data["version"] === 3;
|
|
8800
|
+
const stringField = strict ? nonEmptyString : stringValue;
|
|
8801
|
+
stringField(data["label"], `${label} label`);
|
|
8673
8802
|
for (const key of [
|
|
8674
8803
|
"agentProvider",
|
|
8675
8804
|
"agentModel",
|
|
8676
8805
|
"agentReasoningEffort",
|
|
8677
8806
|
"persona"
|
|
8678
|
-
]) if (data[key] !== void 0)
|
|
8679
|
-
if (data["agentProvider"] === void 0 !== (data["agentModel"] === void 0)) throw new SessionFormatError(`${label} agentProvider and agentModel must be paired`);
|
|
8807
|
+
]) if (data[key] !== void 0) stringField(data[key], `${label} ${key}`);
|
|
8808
|
+
if (strict && data["agentProvider"] === void 0 !== (data["agentModel"] === void 0)) throw new SessionFormatError(`${label} agentProvider and agentModel must be paired`);
|
|
8680
8809
|
if (data["toolFilter"] !== void 0) {
|
|
8681
8810
|
const filter = exactRecord(data["toolFilter"], `${label} toolFilter`, [], ["allow", "deny"]);
|
|
8682
8811
|
if (filter["allow"] === void 0 && filter["deny"] === void 0) throw new SessionFormatError(`${label} toolFilter requires allow or deny`);
|
|
8683
|
-
if (filter["allow"] !== void 0) arrayValue(filter["allow"], `${label} allow`,
|
|
8684
|
-
if (filter["deny"] !== void 0) arrayValue(filter["deny"], `${label} deny`,
|
|
8812
|
+
if (filter["allow"] !== void 0) arrayValue(filter["allow"], `${label} allow`, stringField);
|
|
8813
|
+
if (filter["deny"] !== void 0) arrayValue(filter["deny"], `${label} deny`, stringField);
|
|
8685
8814
|
}
|
|
8686
8815
|
}
|
|
8687
8816
|
function allowedModelsValue(value, label) {
|
|
@@ -8881,7 +9010,7 @@ function assertReleasedEventPayload(event, version) {
|
|
|
8881
9010
|
/* v8 ignore next -- artifact coordinate validation admits only the frozen inventory before payload validation. */
|
|
8882
9011
|
if (disposition === void 0) throw new SessionFormatUnsupportedMigrationError(`format v0 contains unknown historical event type ${JSON.stringify(event.type)} at seq ${event.seq}; migration refuses unknown historical events even when ignorable`);
|
|
8883
9012
|
const data = releasedV0Record(event.data, `${event.type} ${event.seq} data`);
|
|
8884
|
-
if (event.type === "subagent/descriptor" && data["version"]
|
|
9013
|
+
if (event.type === "subagent/descriptor" && !SUBAGENT_DESCRIPTOR_VERSIONS.some((known) => known === data["version"])) {
|
|
8885
9014
|
const descriptorVersion = sessionFormatCount(data["version"], `${event.type} ${event.seq} version`);
|
|
8886
9015
|
if (version === 0) throw new SessionFormatUnsupportedMigrationError(`${event.type} ${event.seq} uses unsupported descriptor version ${descriptorVersion}`);
|
|
8887
9016
|
return;
|
|
@@ -12421,7 +12550,7 @@ function assertReleasedV4Relationships(artifact, knownEventTypes) {
|
|
|
12421
12550
|
assertV4DeveloperData(event);
|
|
12422
12551
|
assertV4MessageSources(event);
|
|
12423
12552
|
const deliveryId = validateDeliveryAccepted(event, 4);
|
|
12424
|
-
if (deliveryId !== void 0 &&
|
|
12553
|
+
if (deliveryId !== void 0 && event.seq >= artifact.inheritedEventCount && deliveryId !== artifact.header.id) throw new SessionFormatError("current-generation delivery marker names the wrong Session");
|
|
12425
12554
|
if (event.type === "subagent/catalog" && event.seq >= artifact.inheritedEventCount) {
|
|
12426
12555
|
const id = catalogFact(event.data)["childId"];
|
|
12427
12556
|
if (ids.has(id)) throw new SessionFormatError(`duplicate catalog child ${id}`);
|
|
@@ -12982,7 +13111,7 @@ function privateZstdStream(stream) {
|
|
|
12982
13111
|
const candidate = stream;
|
|
12983
13112
|
const handle = candidate._handle;
|
|
12984
13113
|
const errorKey = Reflect.ownKeys(stream).find((key) => typeof key === "symbol" && key.description === "kError");
|
|
12985
|
-
/* v8 ignore next -- one test runtime exposes one Node-private shape; the Node
|
|
13114
|
+
/* v8 ignore next -- one test runtime exposes one Node-private shape; the Node 24/26 matrix checks compatibility. */
|
|
12986
13115
|
if (typeof handle !== "object" || handle === null || typeof handle.writeSync !== "function" || !(candidate._writeState instanceof Uint32Array) || candidate._writeState.length < 2 || typeof candidate._defaultFlushFlag !== "number" || errorKey === void 0 || candidate[errorKey] !== null) return void 0;
|
|
12987
13116
|
return {
|
|
12988
13117
|
stream,
|
|
@@ -13211,7 +13340,7 @@ async function compressZstdFrame(input) {
|
|
|
13211
13340
|
return zstdCompressAsync(input, CHECKSUM_OPTIONS);
|
|
13212
13341
|
}
|
|
13213
13342
|
/**
|
|
13214
|
-
* Select the shared private decoder when the running Node
|
|
13343
|
+
* Select the shared private decoder when the running Node 24/26 shape is
|
|
13215
13344
|
* compatible, otherwise preserve correctness with the public one-shot API.
|
|
13216
13345
|
* @returns a synchronous decoder with an implementation-independent lifecycle.
|
|
13217
13346
|
*/
|