@spearwolf/shadow-objects 0.33.0 → 0.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +350 -61
- package/README.md +66 -13
- package/bundle.js +6 -53
- package/package.json +15 -3
- package/src/ChangeTrailRefusedError.d.ts +27 -0
- package/src/ChangeTrailRefusedError.d.ts.map +1 -0
- package/src/ChangeTrailRefusedError.js +12 -0
- package/src/ChangeTrailRefusedError.js.map +7 -0
- package/src/EntityUuidInUseError.d.ts +19 -0
- package/src/EntityUuidInUseError.d.ts.map +1 -0
- package/src/EntityUuidInUseError.js +11 -0
- package/src/EntityUuidInUseError.js.map +7 -0
- package/src/WorkerTimeoutError.d.ts +26 -0
- package/src/WorkerTimeoutError.d.ts.map +1 -0
- package/src/WorkerTimeoutError.js +12 -0
- package/src/WorkerTimeoutError.js.map +7 -0
- package/src/bundle.d.ts +1 -1
- package/src/bundle.d.ts.map +1 -1
- package/src/bundle.js +1 -1
- package/src/bundle.js.map +2 -2
- package/src/constants.d.ts +13 -2
- package/src/constants.d.ts.map +1 -1
- package/src/constants.js +7 -1
- package/src/constants.js.map +2 -2
- package/src/create-worker.bundle.d.ts +1 -1
- package/src/create-worker.bundle.d.ts.map +1 -1
- package/src/create-worker.bundle.js.map +1 -1
- package/src/create-worker.d.ts +1 -1
- package/src/create-worker.d.ts.map +1 -1
- package/src/create-worker.js.map +1 -1
- package/src/elements/ShaeElement.d.ts +70 -2
- package/src/elements/ShaeElement.d.ts.map +1 -1
- package/src/elements/ShaeElement.js +129 -25
- package/src/elements/ShaeElement.js.map +3 -3
- package/src/elements/ShaeEntElement.d.ts +39 -1
- package/src/elements/ShaeEntElement.d.ts.map +1 -1
- package/src/elements/ShaeEntElement.js +397 -167
- package/src/elements/ShaeEntElement.js.map +2 -2
- package/src/elements/ShaeLifecycleElement.d.ts +71 -0
- package/src/elements/ShaeLifecycleElement.d.ts.map +1 -0
- package/src/elements/ShaeLifecycleElement.js +83 -0
- package/src/elements/ShaeLifecycleElement.js.map +7 -0
- package/src/elements/ShaePropElement.d.ts +61 -2
- package/src/elements/ShaePropElement.d.ts.map +1 -1
- package/src/elements/ShaePropElement.js +264 -219
- package/src/elements/ShaePropElement.js.map +2 -2
- package/src/elements/ShaeWorkerElement.d.ts +59 -5
- package/src/elements/ShaeWorkerElement.d.ts.map +1 -1
- package/src/elements/ShaeWorkerElement.js +271 -73
- package/src/elements/ShaeWorkerElement.js.map +2 -2
- package/src/elements/constants.d.ts +9 -0
- package/src/elements/constants.d.ts.map +1 -1
- package/src/elements/constants.js +18 -0
- package/src/elements/constants.js.map +2 -2
- package/src/elements/deferredTeardown.d.ts +24 -0
- package/src/elements/deferredTeardown.d.ts.map +1 -0
- package/src/elements/deferredTeardown.js +30 -0
- package/src/elements/deferredTeardown.js.map +7 -0
- package/src/elements/displayContentsRule.d.ts +25 -0
- package/src/elements/displayContentsRule.d.ts.map +1 -0
- package/src/elements/displayContentsRule.js +37 -0
- package/src/elements/displayContentsRule.js.map +7 -0
- package/src/elements/events.d.ts +10 -7
- package/src/elements/events.d.ts.map +1 -1
- package/src/elements/forwardCustomEvents.d.ts +19 -0
- package/src/elements/forwardCustomEvents.d.ts.map +1 -0
- package/src/elements/forwardCustomEvents.js +47 -0
- package/src/elements/forwardCustomEvents.js.map +7 -0
- package/src/elements/hostedSlots.d.ts +36 -0
- package/src/elements/hostedSlots.d.ts.map +1 -0
- package/src/elements/hostedSlots.js +118 -0
- package/src/elements/hostedSlots.js.map +7 -0
- package/src/elements/parentRemoval.d.ts +18 -0
- package/src/elements/parentRemoval.d.ts.map +1 -0
- package/src/elements/parentRemoval.js +60 -0
- package/src/elements/parentRemoval.js.map +7 -0
- package/src/elements/propValueConverters.d.ts +3 -0
- package/src/elements/propValueConverters.d.ts.map +1 -0
- package/src/elements/propValueConverters.js +54 -0
- package/src/elements/propValueConverters.js.map +7 -0
- package/src/elements/requestEntAncestor.d.ts +32 -0
- package/src/elements/requestEntAncestor.d.ts.map +1 -0
- package/src/elements/requestEntAncestor.js +16 -0
- package/src/elements/requestEntAncestor.js.map +7 -0
- package/src/elements.js.map +1 -1
- package/src/in-the-dark/Entity.d.ts +143 -3
- package/src/in-the-dark/Entity.d.ts.map +1 -1
- package/src/in-the-dark/Entity.js +330 -63
- package/src/in-the-dark/Entity.js.map +3 -3
- package/src/in-the-dark/Kernel.d.ts +98 -16
- package/src/in-the-dark/Kernel.d.ts.map +1 -1
- package/src/in-the-dark/Kernel.js +466 -379
- package/src/in-the-dark/Kernel.js.map +3 -3
- package/src/in-the-dark/Registry.d.ts +7 -1
- package/src/in-the-dark/Registry.d.ts.map +1 -1
- package/src/in-the-dark/Registry.js +112 -14
- package/src/in-the-dark/Registry.js.map +2 -2
- package/src/in-the-dark/ShadowObject.d.ts.map +1 -1
- package/src/in-the-dark/ShadowObject.js +1 -0
- package/src/in-the-dark/ShadowObject.js.map +2 -2
- package/src/in-the-dark/ShadowObjectCreationScope.d.ts +133 -0
- package/src/in-the-dark/ShadowObjectCreationScope.d.ts.map +1 -0
- package/src/in-the-dark/ShadowObjectCreationScope.js +603 -0
- package/src/in-the-dark/ShadowObjectCreationScope.js.map +7 -0
- package/src/in-the-dark/SignalsPath.d.ts +2 -0
- package/src/in-the-dark/SignalsPath.d.ts.map +1 -1
- package/src/in-the-dark/SignalsPath.js +6 -2
- package/src/in-the-dark/SignalsPath.js.map +2 -2
- package/src/in-the-dark/displayName.d.ts +4 -0
- package/src/in-the-dark/displayName.d.ts.map +1 -0
- package/src/in-the-dark/displayName.js +5 -0
- package/src/in-the-dark/displayName.js.map +7 -0
- package/src/in-the-dark/events.js.map +1 -1
- package/src/in-the-dark/importModule.d.ts +7 -0
- package/src/in-the-dark/importModule.d.ts.map +1 -1
- package/src/in-the-dark/importModule.js +5 -2
- package/src/in-the-dark/importModule.js.map +2 -2
- package/src/index.d.ts +9 -1
- package/src/index.d.ts.map +1 -1
- package/src/index.js +9 -1
- package/src/index.js.map +2 -2
- package/src/inspect/createKernelSnapshot.d.ts +17 -0
- package/src/inspect/createKernelSnapshot.d.ts.map +1 -0
- package/src/inspect/createKernelSnapshot.js +247 -0
- package/src/inspect/createKernelSnapshot.js.map +7 -0
- package/src/inspect/createViewSnapshot.d.ts +10 -0
- package/src/inspect/createViewSnapshot.d.ts.map +1 -0
- package/src/inspect/createViewSnapshot.js +143 -0
- package/src/inspect/createViewSnapshot.js.map +7 -0
- package/src/inspect/normalizeInspectRequest.d.ts +32 -0
- package/src/inspect/normalizeInspectRequest.d.ts.map +1 -0
- package/src/inspect/normalizeInspectRequest.js +55 -0
- package/src/inspect/normalizeInspectRequest.js.map +7 -0
- package/src/inspect/serializeValue.d.ts +13 -0
- package/src/inspect/serializeValue.d.ts.map +1 -0
- package/src/inspect/serializeValue.js +149 -0
- package/src/inspect/serializeValue.js.map +7 -0
- package/src/inspect/types.d.ts +260 -0
- package/src/inspect/types.d.ts.map +1 -0
- package/src/inspect/types.js +1 -0
- package/src/inspect/types.js.map +7 -0
- package/src/model-context/ModelContextLike.d.ts +59 -0
- package/src/model-context/ModelContextLike.d.ts.map +1 -0
- package/src/model-context/ModelContextLike.js +15 -0
- package/src/model-context/ModelContextLike.js.map +7 -0
- package/src/model-context/exposeShadowEnvsToModelContext.d.ts +48 -0
- package/src/model-context/exposeShadowEnvsToModelContext.d.ts.map +1 -0
- package/src/model-context/exposeShadowEnvsToModelContext.js +39 -0
- package/src/model-context/exposeShadowEnvsToModelContext.js.map +7 -0
- package/src/model-context/redactProps.d.ts +14 -0
- package/src/model-context/redactProps.d.ts.map +1 -0
- package/src/model-context/redactProps.js +22 -0
- package/src/model-context/redactProps.js.map +7 -0
- package/src/model-context/sharedExposure.d.ts +32 -0
- package/src/model-context/sharedExposure.d.ts.map +1 -0
- package/src/model-context/sharedExposure.js +108 -0
- package/src/model-context/sharedExposure.js.map +7 -0
- package/src/model-context/toolSupport.d.ts +72 -0
- package/src/model-context/toolSupport.d.ts.map +1 -0
- package/src/model-context/toolSupport.js +145 -0
- package/src/model-context/toolSupport.js.map +7 -0
- package/src/model-context/tools/findEntities.d.ts +15 -0
- package/src/model-context/tools/findEntities.d.ts.map +1 -0
- package/src/model-context/tools/findEntities.js +71 -0
- package/src/model-context/tools/findEntities.js.map +7 -0
- package/src/model-context/tools/getEntity.d.ts +16 -0
- package/src/model-context/tools/getEntity.d.ts.map +1 -0
- package/src/model-context/tools/getEntity.js +65 -0
- package/src/model-context/tools/getEntity.js.map +7 -0
- package/src/model-context/tools/getEntityTree.d.ts +4 -0
- package/src/model-context/tools/getEntityTree.d.ts.map +1 -0
- package/src/model-context/tools/getEntityTree.js +58 -0
- package/src/model-context/tools/getEntityTree.js.map +7 -0
- package/src/model-context/tools/getRegistry.d.ts +14 -0
- package/src/model-context/tools/getRegistry.d.ts.map +1 -0
- package/src/model-context/tools/getRegistry.js +39 -0
- package/src/model-context/tools/getRegistry.js.map +7 -0
- package/src/model-context/tools/index.d.ts +9 -0
- package/src/model-context/tools/index.d.ts.map +1 -0
- package/src/model-context/tools/index.js +16 -0
- package/src/model-context/tools/index.js.map +7 -0
- package/src/model-context/tools/listEnvs.d.ts +33 -0
- package/src/model-context/tools/listEnvs.d.ts.map +1 -0
- package/src/model-context/tools/listEnvs.js +37 -0
- package/src/model-context/tools/listEnvs.js.map +7 -0
- package/src/model-context.d.ts +13 -0
- package/src/model-context.d.ts.map +1 -0
- package/src/model-context.js +15 -0
- package/src/model-context.js.map +7 -0
- package/src/shadow-objects.d.ts +4 -0
- package/src/shadow-objects.d.ts.map +1 -1
- package/src/shadow-objects.js +6 -0
- package/src/shadow-objects.js.map +2 -2
- package/src/shadow-objects.worker.js +0 -1
- package/src/shadow-objects.worker.js.map +2 -2
- package/src/shae-ent.js.map +1 -1
- package/src/shae-prop.js +2 -2
- package/src/shae-prop.js.map +2 -2
- package/src/shae-worker.js.map +1 -1
- package/src/testing/TestEntity.d.ts +79 -0
- package/src/testing/TestEntity.d.ts.map +1 -0
- package/src/testing/TestEntity.js +135 -0
- package/src/testing/TestEntity.js.map +7 -0
- package/src/testing/createTestKernel.d.ts +11 -0
- package/src/testing/createTestKernel.d.ts.map +1 -0
- package/src/testing/createTestKernel.js +132 -0
- package/src/testing/createTestKernel.js.map +7 -0
- package/src/testing/mountShadowObject.d.ts +21 -0
- package/src/testing/mountShadowObject.d.ts.map +1 -0
- package/src/testing/mountShadowObject.js +72 -0
- package/src/testing/mountShadowObject.js.map +7 -0
- package/src/testing/recordKernelErrors.d.ts +21 -0
- package/src/testing/recordKernelErrors.d.ts.map +1 -0
- package/src/testing/recordKernelErrors.js +39 -0
- package/src/testing/recordKernelErrors.js.map +7 -0
- package/src/testing/settle.d.ts +15 -0
- package/src/testing/settle.d.ts.map +1 -0
- package/src/testing/settle.js +19 -0
- package/src/testing/settle.js.map +7 -0
- package/src/testing/types.d.ts +119 -0
- package/src/testing/types.d.ts.map +1 -0
- package/src/testing/types.js +1 -0
- package/src/testing/types.js.map +7 -0
- package/src/testing.d.ts +14 -0
- package/src/testing.d.ts.map +1 -0
- package/src/testing.js +11 -0
- package/src/testing.js.map +7 -0
- package/src/types.d.ts +185 -14
- package/src/types.d.ts.map +1 -1
- package/src/utils/ConsoleLogger.d.ts +45 -10
- package/src/utils/ConsoleLogger.d.ts.map +1 -1
- package/src/utils/ConsoleLogger.js +51 -26
- package/src/utils/ConsoleLogger.js.map +2 -2
- package/src/utils/FrameLoop.d.ts +42 -3
- package/src/utils/FrameLoop.d.ts.map +1 -1
- package/src/utils/FrameLoop.js +71 -10
- package/src/utils/FrameLoop.js.map +2 -2
- package/src/utils/MicrotaskCollector.d.ts +45 -0
- package/src/utils/MicrotaskCollector.d.ts.map +1 -0
- package/src/utils/MicrotaskCollector.js +33 -0
- package/src/utils/MicrotaskCollector.js.map +7 -0
- package/src/utils/MicrotaskGate.d.ts +17 -0
- package/src/utils/MicrotaskGate.d.ts.map +1 -0
- package/src/utils/MicrotaskGate.js +20 -0
- package/src/utils/MicrotaskGate.js.map +7 -0
- package/src/utils/array-utils.js.map +1 -1
- package/src/utils/attr-utils.d.ts +11 -0
- package/src/utils/attr-utils.d.ts.map +1 -1
- package/src/utils/attr-utils.js +5 -1
- package/src/utils/attr-utils.js.map +2 -2
- package/src/utils/constants.js.map +1 -1
- package/src/utils/generateUUID.d.ts +11 -0
- package/src/utils/generateUUID.d.ts.map +1 -1
- package/src/utils/generateUUID.js +31 -266
- package/src/utils/generateUUID.js.map +2 -2
- package/src/utils/props-utils.d.ts +3 -2
- package/src/utils/props-utils.d.ts.map +1 -1
- package/src/utils/props-utils.js +13 -24
- package/src/utils/props-utils.js.map +2 -2
- package/src/utils/runGuarded.d.ts +27 -0
- package/src/utils/runGuarded.d.ts.map +1 -0
- package/src/utils/runGuarded.js +11 -0
- package/src/utils/runGuarded.js.map +7 -0
- package/src/utils/toMaybe.d.ts.map +1 -1
- package/src/utils/toMaybe.js.map +1 -1
- package/src/utils/toNamespace.d.ts.map +1 -1
- package/src/utils/toNamespace.js.map +1 -1
- package/src/utils/toUrlString.d.ts +12 -0
- package/src/utils/toUrlString.d.ts.map +1 -1
- package/src/utils/toUrlString.js.map +2 -2
- package/src/utils/waitForMessageOfType.d.ts +12 -1
- package/src/utils/waitForMessageOfType.d.ts.map +1 -1
- package/src/utils/waitForMessageOfType.js +16 -1
- package/src/utils/waitForMessageOfType.js.map +2 -2
- package/src/view/ComponentChanges.d.ts +88 -1
- package/src/view/ComponentChanges.d.ts.map +1 -1
- package/src/view/ComponentChanges.js +243 -73
- package/src/view/ComponentChanges.js.map +2 -2
- package/src/view/ComponentContext.d.ts +206 -16
- package/src/view/ComponentContext.d.ts.map +1 -1
- package/src/view/ComponentContext.js +548 -91
- package/src/view/ComponentContext.js.map +2 -2
- package/src/view/ComponentMemory.d.ts +3 -3
- package/src/view/ComponentMemory.d.ts.map +1 -1
- package/src/view/ComponentMemory.js.map +1 -1
- package/src/view/IShadowObjectEnvProxy.d.ts +38 -3
- package/src/view/IShadowObjectEnvProxy.d.ts.map +1 -1
- package/src/view/LocalShadowObjectEnv.d.ts +8 -1
- package/src/view/LocalShadowObjectEnv.d.ts.map +1 -1
- package/src/view/LocalShadowObjectEnv.js +23 -7
- package/src/view/LocalShadowObjectEnv.js.map +2 -2
- package/src/view/RemoteWorkerEnv.d.ts +108 -5
- package/src/view/RemoteWorkerEnv.d.ts.map +1 -1
- package/src/view/RemoteWorkerEnv.js +244 -77
- package/src/view/RemoteWorkerEnv.js.map +2 -2
- package/src/view/ShadowEnv.d.ts +79 -2
- package/src/view/ShadowEnv.d.ts.map +1 -1
- package/src/view/ShadowEnv.js +323 -59
- package/src/view/ShadowEnv.js.map +3 -3
- package/src/view/ViewComponent.d.ts +78 -14
- package/src/view/ViewComponent.d.ts.map +1 -1
- package/src/view/ViewComponent.js +90 -14
- package/src/view/ViewComponent.js.map +2 -2
- package/src/view/cloneChangeTrail.js.map +2 -2
- package/src/worker/MessageRouter.d.ts +14 -0
- package/src/worker/MessageRouter.d.ts.map +1 -1
- package/src/worker/MessageRouter.js +98 -15
- package/src/worker/MessageRouter.js.map +2 -2
- package/src/worker/WorkerRuntime.d.ts +22 -1
- package/src/worker/WorkerRuntime.d.ts.map +1 -1
- package/src/worker/WorkerRuntime.js +60 -8
- package/src/worker/WorkerRuntime.js.map +2 -2
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { isSignal, value as readSignal } from "@spearwolf/signalize";
|
|
2
|
+
const SerializeDefaults = Object.freeze({
|
|
3
|
+
maxDepth: 3,
|
|
4
|
+
maxArrayLength: 20,
|
|
5
|
+
maxObjectEntries: 30,
|
|
6
|
+
maxStringLength: 200
|
|
7
|
+
});
|
|
8
|
+
const orDefault = (val, fallback) => val !== void 0 && Number.isFinite(val) ? val : fallback;
|
|
9
|
+
const resolveSerializeLimits = (limits) => ({
|
|
10
|
+
maxDepth: orDefault(limits?.maxDepth, SerializeDefaults.maxDepth),
|
|
11
|
+
maxArrayLength: orDefault(limits?.maxArrayLength, SerializeDefaults.maxArrayLength),
|
|
12
|
+
maxObjectEntries: orDefault(limits?.maxObjectEntries, SerializeDefaults.maxObjectEntries),
|
|
13
|
+
maxStringLength: orDefault(limits?.maxStringLength, SerializeDefaults.maxStringLength)
|
|
14
|
+
});
|
|
15
|
+
const isDomNode = (val) => typeof val.nodeType === "number" && typeof val.nodeName === "string";
|
|
16
|
+
const isPlainObject = (val) => {
|
|
17
|
+
const proto = Object.getPrototypeOf(val);
|
|
18
|
+
return proto === Object.prototype || proto === null;
|
|
19
|
+
};
|
|
20
|
+
const className = (val) => {
|
|
21
|
+
const ctor = val.constructor;
|
|
22
|
+
return typeof ctor === "function" && ctor.name ? ctor.name : "Object";
|
|
23
|
+
};
|
|
24
|
+
const errorEntry = (error) => ({
|
|
25
|
+
$type: "object",
|
|
26
|
+
class: "Error",
|
|
27
|
+
preview: { message: error instanceof Error ? error.message : String(error) }
|
|
28
|
+
});
|
|
29
|
+
const TRUNCATED_KEY = "$truncated";
|
|
30
|
+
function serializeValue(value, limits) {
|
|
31
|
+
return new Serializer(resolveSerializeLimits(limits)).serialize(value, 0, /* @__PURE__ */ new Set());
|
|
32
|
+
}
|
|
33
|
+
class Serializer {
|
|
34
|
+
constructor(limits) {
|
|
35
|
+
this.limits = limits;
|
|
36
|
+
}
|
|
37
|
+
serialize(val, depth, path) {
|
|
38
|
+
switch (typeof val) {
|
|
39
|
+
case "undefined":
|
|
40
|
+
return { $type: "undefined" };
|
|
41
|
+
case "boolean":
|
|
42
|
+
return val;
|
|
43
|
+
case "number":
|
|
44
|
+
return Number.isFinite(val) ? val : String(val);
|
|
45
|
+
case "string":
|
|
46
|
+
return this.string(val);
|
|
47
|
+
case "bigint":
|
|
48
|
+
return { $type: "bigint", value: val.toString() };
|
|
49
|
+
case "symbol":
|
|
50
|
+
return val.description === void 0 ? { $type: "symbol" } : { $type: "symbol", description: val.description };
|
|
51
|
+
case "function":
|
|
52
|
+
try {
|
|
53
|
+
if (isSignal(val)) return this.signal(val, depth, path);
|
|
54
|
+
return { $type: "function", name: val.name };
|
|
55
|
+
} catch (error) {
|
|
56
|
+
return errorEntry(error);
|
|
57
|
+
}
|
|
58
|
+
case "object":
|
|
59
|
+
if (val === null) return null;
|
|
60
|
+
try {
|
|
61
|
+
if (isSignal(val)) return this.signal(val, depth, path);
|
|
62
|
+
return this.object(val, depth, path);
|
|
63
|
+
} catch (error) {
|
|
64
|
+
return errorEntry(error);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
string(val) {
|
|
69
|
+
if (val.length <= this.limits.maxStringLength) return val;
|
|
70
|
+
return { $type: "truncated", reason: "string", original: val.length, preview: val.slice(0, this.limits.maxStringLength) };
|
|
71
|
+
}
|
|
72
|
+
signal(sig, depth, path) {
|
|
73
|
+
if (path.has(sig)) return { $type: "circular" };
|
|
74
|
+
path.add(sig);
|
|
75
|
+
try {
|
|
76
|
+
let current;
|
|
77
|
+
try {
|
|
78
|
+
current = readSignal(sig);
|
|
79
|
+
} catch (error) {
|
|
80
|
+
return errorEntry(error);
|
|
81
|
+
}
|
|
82
|
+
return { $type: "signal", value: this.serialize(current, depth, path) };
|
|
83
|
+
} finally {
|
|
84
|
+
path.delete(sig);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
object(val, depth, path) {
|
|
88
|
+
if (val instanceof Date) return { $type: "date", iso: Number.isNaN(val.getTime()) ? "Invalid Date" : val.toISOString() };
|
|
89
|
+
if (val instanceof ArrayBuffer) return { $type: "array-buffer", byteLength: val.byteLength, class: "ArrayBuffer" };
|
|
90
|
+
if (ArrayBuffer.isView(val)) return { $type: "typed-array", byteLength: val.byteLength, class: className(val) };
|
|
91
|
+
if (isDomNode(val)) {
|
|
92
|
+
return typeof val.id === "string" && val.id ? { $type: "dom", nodeName: val.nodeName, id: val.id } : { $type: "dom", nodeName: val.nodeName };
|
|
93
|
+
}
|
|
94
|
+
if (val instanceof Error) return { $type: "object", class: className(val), preview: { name: val.name, message: val.message } };
|
|
95
|
+
if (depth > this.limits.maxDepth) return { $type: "truncated", reason: "depth" };
|
|
96
|
+
if (path.has(val)) return { $type: "circular" };
|
|
97
|
+
path.add(val);
|
|
98
|
+
try {
|
|
99
|
+
if (Array.isArray(val)) return this.array(val, depth, path);
|
|
100
|
+
if (val instanceof Map) {
|
|
101
|
+
return {
|
|
102
|
+
$type: "object",
|
|
103
|
+
class: "Map",
|
|
104
|
+
preview: { size: val.size, entries: this.array(Array.from(val.entries()), depth, path) }
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
if (val instanceof Set) {
|
|
108
|
+
return { $type: "object", class: "Set", preview: { size: val.size, entries: this.array(Array.from(val), depth, path) } };
|
|
109
|
+
}
|
|
110
|
+
if (isPlainObject(val)) return this.entries(val, depth, path);
|
|
111
|
+
return { $type: "object", class: className(val), preview: this.entries(val, depth, path) };
|
|
112
|
+
} finally {
|
|
113
|
+
path.delete(val);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
array(val, depth, path) {
|
|
117
|
+
const out = [];
|
|
118
|
+
const max = this.limits.maxArrayLength;
|
|
119
|
+
for (let i = 0; i < val.length && i < max; i++) {
|
|
120
|
+
out.push(this.serialize(val[i], depth + 1, path));
|
|
121
|
+
}
|
|
122
|
+
if (val.length > max) out.push({ $type: "truncated", reason: "length", original: val.length });
|
|
123
|
+
return out;
|
|
124
|
+
}
|
|
125
|
+
entries(val, depth, path) {
|
|
126
|
+
const out = {};
|
|
127
|
+
const keys = Object.keys(val);
|
|
128
|
+
const max = this.limits.maxObjectEntries;
|
|
129
|
+
for (let i = 0; i < keys.length && i < max; i++) {
|
|
130
|
+
const key = keys[i];
|
|
131
|
+
let entry;
|
|
132
|
+
try {
|
|
133
|
+
entry = val[key];
|
|
134
|
+
} catch (error) {
|
|
135
|
+
out[key] = errorEntry(error);
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
out[key] = this.serialize(entry, depth + 1, path);
|
|
139
|
+
}
|
|
140
|
+
if (keys.length > max) out[TRUNCATED_KEY] = { $type: "truncated", reason: "entries", original: keys.length };
|
|
141
|
+
return out;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
export {
|
|
145
|
+
SerializeDefaults,
|
|
146
|
+
resolveSerializeLimits,
|
|
147
|
+
serializeValue
|
|
148
|
+
};
|
|
149
|
+
//# sourceMappingURL=serializeValue.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/inspect/serializeValue.ts"],
|
|
4
|
+
"sourcesContent": ["import {isSignal, value as readSignal} from '@spearwolf/signalize';\nimport type {SerializedValue, SerializeLimits} from './types.js';\n\nexport const SerializeDefaults: SerializeLimits = Object.freeze({\n maxDepth: 3,\n maxArrayLength: 20,\n maxObjectEntries: 30,\n maxStringLength: 200,\n});\n\n/** A limit that is not a finite number -- `NaN`, an infinity -- reads as the default. */\nconst orDefault = (val: number | undefined, fallback: number): number =>\n val !== undefined && Number.isFinite(val) ? val : fallback;\n\nexport const resolveSerializeLimits = (limits?: Partial<SerializeLimits>): SerializeLimits => ({\n maxDepth: orDefault(limits?.maxDepth, SerializeDefaults.maxDepth),\n maxArrayLength: orDefault(limits?.maxArrayLength, SerializeDefaults.maxArrayLength),\n maxObjectEntries: orDefault(limits?.maxObjectEntries, SerializeDefaults.maxObjectEntries),\n maxStringLength: orDefault(limits?.maxStringLength, SerializeDefaults.maxStringLength),\n});\n\nconst isDomNode = (val: object): val is {nodeType: number; nodeName: string; id?: unknown} =>\n typeof (val as {nodeType?: unknown}).nodeType === 'number' && typeof (val as {nodeName?: unknown}).nodeName === 'string';\n\nconst isPlainObject = (val: object): boolean => {\n const proto = Object.getPrototypeOf(val);\n return proto === Object.prototype || proto === null;\n};\n\nconst className = (val: object): string => {\n const ctor = (val as {constructor?: unknown}).constructor;\n return typeof ctor === 'function' && ctor.name ? ctor.name : 'Object';\n};\n\nconst errorEntry = (error: unknown): SerializedValue => ({\n $type: 'object',\n class: 'Error',\n preview: {message: error instanceof Error ? error.message : String(error)},\n});\n\n/** Marks the entries cut of an object in its serialized preview. */\nconst TRUNCATED_KEY = '$truncated';\n\n/**\n * Turns any value into plain, JSON-safe data under a set of limits. Never throws, for any value: a\n * getter that throws while it is read, a revoked proxy, a trap that refuses -- whatever inspecting a\n * value costs, the throw becomes an error entry in place of the value.\n *\n * The rules and their order are the ones spec \u00A77 lists. Cycles are detected along the current\n * path, so a sub-object shared between two keys appears twice rather than as `$circular`.\n */\nexport function serializeValue(value: unknown, limits?: Partial<SerializeLimits>): SerializedValue {\n return new Serializer(resolveSerializeLimits(limits)).serialize(value, 0, new Set());\n}\n\nclass Serializer {\n constructor(private readonly limits: SerializeLimits) {}\n\n serialize(val: unknown, depth: number, path: Set<object>): SerializedValue {\n switch (typeof val) {\n case 'undefined':\n return {$type: 'undefined'};\n case 'boolean':\n return val;\n case 'number':\n return Number.isFinite(val) ? val : String(val);\n case 'string':\n return this.string(val);\n case 'bigint':\n return {$type: 'bigint', value: val.toString()};\n case 'symbol':\n return val.description === undefined ? {$type: 'symbol'} : {$type: 'symbol', description: val.description};\n case 'function':\n // a hostile object answers `isSignal` and even `name` with a throw; the entry takes its place\n try {\n if (isSignal(val)) return this.signal(val, depth, path);\n return {$type: 'function', name: val.name};\n } catch (error) {\n return errorEntry(error);\n }\n case 'object':\n if (val === null) return null;\n // a revoked proxy, a throwing trap, an inherited getter -- anything a look at the value\n // costs becomes the error entry in its place, so this function never throws\n try {\n if (isSignal(val)) return this.signal(val, depth, path);\n return this.object(val, depth, path);\n } catch (error) {\n return errorEntry(error);\n }\n }\n }\n\n private string(val: string): SerializedValue {\n if (val.length <= this.limits.maxStringLength) return val;\n return {$type: 'truncated', reason: 'string', original: val.length, preview: val.slice(0, this.limits.maxStringLength)};\n }\n\n private signal(sig: unknown, depth: number, path: Set<object>): SerializedValue {\n // a signal holding itself, or a chain of signals closing on one, ends here instead of on the stack\n if (path.has(sig as object)) return {$type: 'circular'};\n\n path.add(sig as object);\n try {\n let current: unknown;\n try {\n current = readSignal(sig as Parameters<typeof readSignal>[0]);\n } catch (error) {\n return errorEntry(error);\n }\n return {$type: 'signal', value: this.serialize(current, depth, path)};\n } finally {\n path.delete(sig as object);\n }\n }\n\n private object(val: object, depth: number, path: Set<object>): SerializedValue {\n if (val instanceof Date) return {$type: 'date', iso: Number.isNaN(val.getTime()) ? 'Invalid Date' : val.toISOString()};\n if (val instanceof ArrayBuffer) return {$type: 'array-buffer', byteLength: val.byteLength, class: 'ArrayBuffer'};\n if (ArrayBuffer.isView(val)) return {$type: 'typed-array', byteLength: val.byteLength, class: className(val)};\n if (isDomNode(val)) {\n return typeof val.id === 'string' && val.id\n ? {$type: 'dom', nodeName: val.nodeName, id: val.id}\n : {$type: 'dom', nodeName: val.nodeName};\n }\n if (val instanceof Error) return {$type: 'object', class: className(val), preview: {name: val.name, message: val.message}};\n\n if (depth > this.limits.maxDepth) return {$type: 'truncated', reason: 'depth'};\n if (path.has(val)) return {$type: 'circular'};\n\n path.add(val);\n try {\n if (Array.isArray(val)) return this.array(val, depth, path);\n if (val instanceof Map) {\n return {\n $type: 'object',\n class: 'Map',\n preview: {size: val.size, entries: this.array(Array.from(val.entries()), depth, path)},\n };\n }\n if (val instanceof Set) {\n return {$type: 'object', class: 'Set', preview: {size: val.size, entries: this.array(Array.from(val), depth, path)}};\n }\n if (isPlainObject(val)) return this.entries(val, depth, path);\n return {$type: 'object', class: className(val), preview: this.entries(val, depth, path)};\n } finally {\n path.delete(val);\n }\n }\n\n private array(val: unknown[], depth: number, path: Set<object>): SerializedValue[] {\n const out: SerializedValue[] = [];\n const max = this.limits.maxArrayLength;\n for (let i = 0; i < val.length && i < max; i++) {\n out.push(this.serialize(val[i], depth + 1, path));\n }\n if (val.length > max) out.push({$type: 'truncated', reason: 'length', original: val.length});\n return out;\n }\n\n private entries(val: object, depth: number, path: Set<object>): Record<string, SerializedValue> {\n const out: Record<string, SerializedValue> = {};\n const keys = Object.keys(val);\n const max = this.limits.maxObjectEntries;\n for (let i = 0; i < keys.length && i < max; i++) {\n const key = keys[i]!;\n let entry: unknown;\n try {\n entry = (val as Record<string, unknown>)[key];\n } catch (error) {\n out[key] = errorEntry(error);\n continue;\n }\n out[key] = this.serialize(entry, depth + 1, path);\n }\n if (keys.length > max) out[TRUNCATED_KEY] = {$type: 'truncated', reason: 'entries', original: keys.length};\n return out;\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAQ,UAAU,SAAS,kBAAiB;AAGrC,MAAM,oBAAqC,OAAO,OAAO;AAAA,EAC9D,UAAU;AAAA,EACV,gBAAgB;AAAA,EAChB,kBAAkB;AAAA,EAClB,iBAAiB;AACnB,CAAC;AAGD,MAAM,YAAY,CAAC,KAAyB,aAC1C,QAAQ,UAAa,OAAO,SAAS,GAAG,IAAI,MAAM;AAE7C,MAAM,yBAAyB,CAAC,YAAwD;AAAA,EAC7F,UAAU,UAAU,QAAQ,UAAU,kBAAkB,QAAQ;AAAA,EAChE,gBAAgB,UAAU,QAAQ,gBAAgB,kBAAkB,cAAc;AAAA,EAClF,kBAAkB,UAAU,QAAQ,kBAAkB,kBAAkB,gBAAgB;AAAA,EACxF,iBAAiB,UAAU,QAAQ,iBAAiB,kBAAkB,eAAe;AACvF;AAEA,MAAM,YAAY,CAAC,QACjB,OAAQ,IAA6B,aAAa,YAAY,OAAQ,IAA6B,aAAa;AAElH,MAAM,gBAAgB,CAAC,QAAyB;AAC9C,QAAM,QAAQ,OAAO,eAAe,GAAG;AACvC,SAAO,UAAU,OAAO,aAAa,UAAU;AACjD;AAEA,MAAM,YAAY,CAAC,QAAwB;AACzC,QAAM,OAAQ,IAAgC;AAC9C,SAAO,OAAO,SAAS,cAAc,KAAK,OAAO,KAAK,OAAO;AAC/D;AAEA,MAAM,aAAa,CAAC,WAAqC;AAAA,EACvD,OAAO;AAAA,EACP,OAAO;AAAA,EACP,SAAS,EAAC,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,EAAC;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,KAAK,OAAO;AACxB,aAAS,IAAI,GAAG,IAAI,KAAK,UAAU,IAAI,KAAK,KAAK;AAC/C,YAAM,MAAM,KAAK,CAAC;AAClB,UAAI;AACJ,UAAI;AACF,gBAAS,IAAgC,GAAG;AAAA,MAC9C,SAAS,OAAO;AACd,YAAI,GAAG,IAAI,WAAW,KAAK;AAC3B;AAAA,MACF;AACA,UAAI,GAAG,IAAI,KAAK,UAAU,OAAO,QAAQ,GAAG,IAAI;AAAA,IAClD;AACA,QAAI,KAAK,SAAS,IAAK,KAAI,aAAa,IAAI,EAAC,OAAO,aAAa,QAAQ,WAAW,UAAU,KAAK,OAAM;AACzG,WAAO;AAAA,EACT;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import type { RegistryDescription } from '../types.js';
|
|
2
|
+
export type SerializedValue = null | boolean | number | string | SerializedValue[] | {
|
|
3
|
+
[key: string]: SerializedValue;
|
|
4
|
+
} | {
|
|
5
|
+
$type: 'undefined';
|
|
6
|
+
} | {
|
|
7
|
+
$type: 'bigint';
|
|
8
|
+
value: string;
|
|
9
|
+
} | {
|
|
10
|
+
$type: 'symbol';
|
|
11
|
+
description?: string;
|
|
12
|
+
} | {
|
|
13
|
+
$type: 'function';
|
|
14
|
+
name: string;
|
|
15
|
+
} | {
|
|
16
|
+
$type: 'date';
|
|
17
|
+
iso: string;
|
|
18
|
+
} | {
|
|
19
|
+
$type: 'signal';
|
|
20
|
+
value: SerializedValue;
|
|
21
|
+
} | {
|
|
22
|
+
$type: 'object';
|
|
23
|
+
class: string;
|
|
24
|
+
preview?: Record<string, SerializedValue>;
|
|
25
|
+
} | {
|
|
26
|
+
$type: 'dom';
|
|
27
|
+
nodeName: string;
|
|
28
|
+
id?: string;
|
|
29
|
+
} | {
|
|
30
|
+
$type: 'array-buffer' | 'typed-array';
|
|
31
|
+
byteLength: number;
|
|
32
|
+
class: string;
|
|
33
|
+
} | {
|
|
34
|
+
$type: 'circular';
|
|
35
|
+
} | {
|
|
36
|
+
$type: 'redacted';
|
|
37
|
+
} | {
|
|
38
|
+
$type: 'truncated';
|
|
39
|
+
reason: 'depth' | 'length' | 'entries' | 'string';
|
|
40
|
+
original?: number;
|
|
41
|
+
preview?: string;
|
|
42
|
+
};
|
|
43
|
+
export interface SerializeLimits {
|
|
44
|
+
/** How deep nested arrays and objects are followed. Default 3. */
|
|
45
|
+
maxDepth: number;
|
|
46
|
+
/** How many items of an array are kept. Default 20. */
|
|
47
|
+
maxArrayLength: number;
|
|
48
|
+
/** How many entries of an object or preview are kept. Default 30. */
|
|
49
|
+
maxObjectEntries: number;
|
|
50
|
+
/** How many characters of a string are kept. Default 200. */
|
|
51
|
+
maxStringLength: number;
|
|
52
|
+
}
|
|
53
|
+
export type InspectInclude = 'props' | 'shadowObjects' | 'contexts' | 'registry';
|
|
54
|
+
export interface InspectRequest {
|
|
55
|
+
/** What to include per Entity. Default: all four. */
|
|
56
|
+
include?: InspectInclude[];
|
|
57
|
+
/** Descend from these uuids instead of the roots. Unknown uuids are reported under `truncation`, not thrown. */
|
|
58
|
+
rootUuids?: string[];
|
|
59
|
+
/** Tree depth below each root that is walked. Default 4. A non-finite number reads as the maximum, 64. */
|
|
60
|
+
maxDepth?: number;
|
|
61
|
+
/** Total number of nodes across the walk. Default 250. */
|
|
62
|
+
maxNodes?: number;
|
|
63
|
+
values?: Partial<SerializeLimits>;
|
|
64
|
+
/**
|
|
65
|
+
* Search instead of walk: every Entity that meets the filter is listed under `search`, and
|
|
66
|
+
* `roots` stays empty. `maxDepth`, `maxNodes` and `rootUuids` do not apply to a search, and
|
|
67
|
+
* `include` does not restrict what it reads. The View side ignores it.
|
|
68
|
+
*/
|
|
69
|
+
filter?: EntityFilter;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* What an Entity has to meet to be listed by a search. Every given criterion must match; a filter
|
|
73
|
+
* without criteria matches every Entity. `contextName` takes a string name only -- a symbol name
|
|
74
|
+
* cannot be named from outside, and a symbol context is findable through the tree alone.
|
|
75
|
+
*/
|
|
76
|
+
export interface EntityFilter {
|
|
77
|
+
/** The Entity's token, exact. */
|
|
78
|
+
token?: string;
|
|
79
|
+
/** A property name the Entity carries -- set from the View or read by a Shadow Object, with or without a value; the same names its `props` list shows. */
|
|
80
|
+
propName?: string;
|
|
81
|
+
/** The display name of a Shadow Object attached to the Entity. */
|
|
82
|
+
shadowObject?: string;
|
|
83
|
+
/** A string Entity Context name the Entity uses or provides. */
|
|
84
|
+
contextName?: string;
|
|
85
|
+
/** How many matches are carried. Default 50; `total` counts every match regardless. */
|
|
86
|
+
limit?: number;
|
|
87
|
+
}
|
|
88
|
+
export interface EntityMatch {
|
|
89
|
+
uuid: string;
|
|
90
|
+
token: string;
|
|
91
|
+
/** The token chain from the root down to this Entity, its own token last. */
|
|
92
|
+
path: string[];
|
|
93
|
+
}
|
|
94
|
+
/** The answer to a request that carried a `filter`. */
|
|
95
|
+
export interface EntitySearchSnapshot {
|
|
96
|
+
matches: EntityMatch[];
|
|
97
|
+
/** How many Entities matched, before `limit`. */
|
|
98
|
+
total: number;
|
|
99
|
+
}
|
|
100
|
+
/** Where a limit of the request cut a walk short, and how to get the rest. */
|
|
101
|
+
export interface TruncationNote {
|
|
102
|
+
reason: 'max-depth' | 'max-nodes' | 'unknown-root';
|
|
103
|
+
/** The node whose children were not walked, or the root uuid that was not found. */
|
|
104
|
+
uuid?: string;
|
|
105
|
+
message: string;
|
|
106
|
+
}
|
|
107
|
+
/** A string context name as it is; a symbol name as its description, marked as such. */
|
|
108
|
+
export type ContextName = string | {
|
|
109
|
+
symbol: string;
|
|
110
|
+
};
|
|
111
|
+
export interface PropSnapshot {
|
|
112
|
+
name: string;
|
|
113
|
+
value: SerializedValue;
|
|
114
|
+
/** Whether the value counts as truthy for property routing (`Entity.truthyProps()`). */
|
|
115
|
+
routes: boolean;
|
|
116
|
+
}
|
|
117
|
+
export interface ShadowObjectSnapshot {
|
|
118
|
+
/** `ShadowObjectCreationScope.displayName` -- the constructor's `displayName` or `name`. */
|
|
119
|
+
displayName: string;
|
|
120
|
+
/** The tokens the constructor is defined under in this Kernel's Registry. Usually one. */
|
|
121
|
+
definedUnder: string[];
|
|
122
|
+
usesProperties: string[];
|
|
123
|
+
usesContexts: ContextName[];
|
|
124
|
+
usesParentContexts: ContextName[];
|
|
125
|
+
providesContexts: ContextName[];
|
|
126
|
+
providesGlobalContexts: ContextName[];
|
|
127
|
+
/** Which of the four lifecycle hooks the instance implements. */
|
|
128
|
+
hooks: ('onCreate' | 'onDestroy' | 'onParentChanged' | 'onViewEvent')[];
|
|
129
|
+
}
|
|
130
|
+
export type EntityContextSource = {
|
|
131
|
+
kind: 'self';
|
|
132
|
+
} | {
|
|
133
|
+
kind: 'ancestor';
|
|
134
|
+
uuid: string;
|
|
135
|
+
} | {
|
|
136
|
+
kind: 'global';
|
|
137
|
+
} | {
|
|
138
|
+
kind: 'none';
|
|
139
|
+
};
|
|
140
|
+
export interface EntityContextSnapshot {
|
|
141
|
+
name: ContextName;
|
|
142
|
+
/** The value this Entity's own providers wrote, if any. Absent when nothing is provided here. */
|
|
143
|
+
provided?: SerializedValue;
|
|
144
|
+
/** The value inherited from the parent, or from the global chain at a root. Absent when there is none. */
|
|
145
|
+
inherited?: SerializedValue;
|
|
146
|
+
/** What `useContext(name)` on this Entity reads: provided where present, inherited otherwise. */
|
|
147
|
+
effective: SerializedValue;
|
|
148
|
+
/** Display names of the Shadow Objects on this Entity that provide the name. */
|
|
149
|
+
providedBy: string[];
|
|
150
|
+
/** Where the effective value comes from: this Entity, an ancestor by uuid, the global chain, or nowhere. */
|
|
151
|
+
source: EntityContextSource;
|
|
152
|
+
}
|
|
153
|
+
export interface GlobalContextSnapshot {
|
|
154
|
+
name: ContextName;
|
|
155
|
+
value: SerializedValue;
|
|
156
|
+
/** The Entities contributing to the chain, in chain order; the first one holding a value wins. */
|
|
157
|
+
providers: {
|
|
158
|
+
uuid: string;
|
|
159
|
+
providedBy: string[];
|
|
160
|
+
value: SerializedValue;
|
|
161
|
+
}[];
|
|
162
|
+
}
|
|
163
|
+
export interface EntityNodeSnapshot {
|
|
164
|
+
uuid: string;
|
|
165
|
+
token: string;
|
|
166
|
+
order: number;
|
|
167
|
+
parentUuid?: string;
|
|
168
|
+
autoDestructionOnParentRemoval: boolean;
|
|
169
|
+
props?: PropSnapshot[];
|
|
170
|
+
shadowObjects?: ShadowObjectSnapshot[];
|
|
171
|
+
contexts?: EntityContextSnapshot[];
|
|
172
|
+
/** Absent when the depth limit cut the walk here; `childCount` still says how many there are. */
|
|
173
|
+
children?: EntityNodeSnapshot[];
|
|
174
|
+
childCount: number;
|
|
175
|
+
/** Same meaning and shape as in `getEntityGraph()`. */
|
|
176
|
+
omittedChildren?: {
|
|
177
|
+
uuid: string;
|
|
178
|
+
reason: 'already-in-graph' | 'not-in-kernel';
|
|
179
|
+
}[];
|
|
180
|
+
/**
|
|
181
|
+
* Set on a node the request named in `rootUuids`: the chain from the root down to this node's
|
|
182
|
+
* parent, top down, empty for a root. Absent on a walk from the natural roots.
|
|
183
|
+
*/
|
|
184
|
+
ancestors?: {
|
|
185
|
+
uuid: string;
|
|
186
|
+
token: string;
|
|
187
|
+
}[];
|
|
188
|
+
}
|
|
189
|
+
export interface RegistrySnapshot extends RegistryDescription {
|
|
190
|
+
/** Whether this is the default registry shared by every local environment of the thread. */
|
|
191
|
+
isDefault: boolean;
|
|
192
|
+
}
|
|
193
|
+
export interface KernelSnapshot {
|
|
194
|
+
/** `Date.now()` on the thread that built the snapshot. */
|
|
195
|
+
takenAt: number;
|
|
196
|
+
/** The realm the snapshot was built in. */
|
|
197
|
+
thread: 'main' | 'worker';
|
|
198
|
+
counts: {
|
|
199
|
+
entities: number;
|
|
200
|
+
roots: number;
|
|
201
|
+
shadowObjects: number;
|
|
202
|
+
};
|
|
203
|
+
roots: EntityNodeSnapshot[];
|
|
204
|
+
globalContexts: GlobalContextSnapshot[];
|
|
205
|
+
registry?: RegistrySnapshot;
|
|
206
|
+
/** Set when a limit of the request cut the walk short. */
|
|
207
|
+
truncation?: TruncationNote[];
|
|
208
|
+
/** Present when the request carried a `filter`; `roots` is empty then. */
|
|
209
|
+
search?: EntitySearchSnapshot;
|
|
210
|
+
}
|
|
211
|
+
export interface ViewComponentSnapshot {
|
|
212
|
+
uuid: string;
|
|
213
|
+
token?: string;
|
|
214
|
+
order: number;
|
|
215
|
+
parentUuid?: string;
|
|
216
|
+
/** The properties as the Component Memory holds them -- the last committed state, not pending changes. */
|
|
217
|
+
props?: PropSnapshot[];
|
|
218
|
+
/** A CSS selector path to the `<shae-ent>` element carrying this component, where one exists. */
|
|
219
|
+
element?: string;
|
|
220
|
+
children?: ViewComponentSnapshot[];
|
|
221
|
+
childCount: number;
|
|
222
|
+
/** A child the walk had already placed elsewhere; same meaning as the Kernel side's entry of that reason. */
|
|
223
|
+
omittedChildren?: {
|
|
224
|
+
uuid: string;
|
|
225
|
+
reason: 'already-in-graph';
|
|
226
|
+
}[];
|
|
227
|
+
}
|
|
228
|
+
export interface ViewSnapshot {
|
|
229
|
+
takenAt: number;
|
|
230
|
+
counts: {
|
|
231
|
+
components: number;
|
|
232
|
+
roots: number;
|
|
233
|
+
};
|
|
234
|
+
roots: ViewComponentSnapshot[];
|
|
235
|
+
/** Set when a depth or node limit cut the walk short. */
|
|
236
|
+
truncation?: TruncationNote[];
|
|
237
|
+
}
|
|
238
|
+
export interface EnvSnapshot {
|
|
239
|
+
/** The namespace as a string; the global namespace reports its symbol description. Empty while the environment has no view. */
|
|
240
|
+
namespace: string;
|
|
241
|
+
/** Whether the namespace is the global one. */
|
|
242
|
+
isGlobalNamespace: boolean;
|
|
243
|
+
/** `'local'` for a LocalShadowObjectEnv, `'worker'` for a RemoteWorkerEnv, `'custom'` for any other proxy, `'none'` without a proxy. */
|
|
244
|
+
kind: 'local' | 'worker' | 'custom' | 'none';
|
|
245
|
+
state: {
|
|
246
|
+
viewReady: boolean;
|
|
247
|
+
proxyReady: boolean;
|
|
248
|
+
isReady: boolean;
|
|
249
|
+
isDestroyed: boolean;
|
|
250
|
+
};
|
|
251
|
+
/** What the View holds for this namespace. Present while the environment has a view, unless building it threw -- then `error` says why. */
|
|
252
|
+
view?: ViewSnapshot;
|
|
253
|
+
/** What the Kernel holds. Absent while the proxy is not ready, or when the inspection failed -- then `error` says why. */
|
|
254
|
+
kernel?: KernelSnapshot;
|
|
255
|
+
error?: {
|
|
256
|
+
name: string;
|
|
257
|
+
message: string;
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/inspect/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,mBAAmB,EAAC,MAAM,aAAa,CAAC;AAMrD,MAAM,MAAM,eAAe,GACvB,IAAI,GACJ,OAAO,GACP,MAAM,GACN,MAAM,GACN,eAAe,EAAE,GACjB;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,CAAA;CAAC,GAChC;IAAC,KAAK,EAAE,WAAW,CAAA;CAAC,GACpB;IAAC,KAAK,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAC,GAChC;IAAC,KAAK,EAAE,QAAQ,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAC,GACvC;IAAC,KAAK,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAC,GACjC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAC,GAC5B;IAAC,KAAK,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,eAAe,CAAA;CAAC,GACzC;IAAC,KAAK,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;CA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6G;IAC7G,eAAe,CAAC,EAAE;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,kBAAkB,CAAA;KAAC,EAAE,CAAC;CAChE;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAC,CAAC;IAC5C,KAAK,EAAE,qBAAqB,EAAE,CAAC;IAC/B,yDAAyD;IACzD,UAAU,CAAC,EAAE,cAAc,EAAE,CAAC;CAC/B;AAMD,MAAM,WAAW,WAAW;IAC1B,+HAA+H;IAC/H,SAAS,EAAE,MAAM,CAAC;IAClB,+CAA+C;IAC/C,iBAAiB,EAAE,OAAO,CAAC;IAC3B,wIAAwI;IACxI,IAAI,EAAE,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;IAC7C,KAAK,EAAE;QACL,SAAS,EAAE,OAAO,CAAC;QACnB,UAAU,EAAE,OAAO,CAAC;QACpB,OAAO,EAAE,OAAO,CAAC;QACjB,WAAW,EAAE,OAAO,CAAC;KACtB,CAAC;IACF,2IAA2I;IAC3I,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB,0HAA0H;IAC1H,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,KAAK,CAAC,EAAE;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAC,CAAC;CACzC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What this package needs from the platform's model context, named structurally so that the
|
|
3
|
+
* rest of the code never sees `document.modelContext`. WebMCP is a moving specification: the
|
|
4
|
+
* registration method changed name and semantics within six months of this file being written.
|
|
5
|
+
* When it moves again, this file and `findModelContext()` are where the change lands.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* The envelope every tool of this package returns. `content` is the compatibility floor every
|
|
9
|
+
* agent reads; `structuredContent` is the same data for an agent that reads structured results.
|
|
10
|
+
* `isError` marks a refusal the tool could phrase -- an unknown namespace, a missing criterion --
|
|
11
|
+
* so that the wording reaches the agent instead of being flattened into a generic failure.
|
|
12
|
+
*/
|
|
13
|
+
export interface ModelContextToolResult {
|
|
14
|
+
content: {
|
|
15
|
+
type: 'text';
|
|
16
|
+
text: string;
|
|
17
|
+
}[];
|
|
18
|
+
structuredContent?: Record<string, unknown>;
|
|
19
|
+
isError?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface ModelContextToolAnnotations {
|
|
22
|
+
readOnlyHint?: boolean;
|
|
23
|
+
untrustedContentHint?: boolean;
|
|
24
|
+
consequentialHint?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface ModelContextToolLike {
|
|
27
|
+
name: string;
|
|
28
|
+
title?: string;
|
|
29
|
+
description: string;
|
|
30
|
+
/** A JSON Schema object. */
|
|
31
|
+
inputSchema: object;
|
|
32
|
+
annotations?: ModelContextToolAnnotations;
|
|
33
|
+
/** `input` is whatever the platform parsed -- an object for the tools here, but nothing forces that. */
|
|
34
|
+
execute(input: unknown, options?: {
|
|
35
|
+
signal?: AbortSignal;
|
|
36
|
+
}): Promise<unknown> | unknown;
|
|
37
|
+
}
|
|
38
|
+
export interface ModelContextRegisterOptions {
|
|
39
|
+
/** Aborting it takes the tool back. */
|
|
40
|
+
signal?: AbortSignal;
|
|
41
|
+
/** Passed through as the platform defines it; absent means the platform default. */
|
|
42
|
+
exposedTo?: string[];
|
|
43
|
+
}
|
|
44
|
+
export interface ModelContextLike {
|
|
45
|
+
/**
|
|
46
|
+
* `unknown` rather than a promise on purpose: an early Chrome preview returned nothing, the
|
|
47
|
+
* specification returns a promise, and the caller awaits whatever it gets.
|
|
48
|
+
*/
|
|
49
|
+
registerTool(tool: ModelContextToolLike, options?: ModelContextRegisterOptions): Promise<unknown> | unknown;
|
|
50
|
+
}
|
|
51
|
+
export declare const isModelContextLike: (value: unknown) => value is ModelContextLike;
|
|
52
|
+
/**
|
|
53
|
+
* The platform's model context, or `undefined` where there is none: a worker, Node, a browser
|
|
54
|
+
* without WebMCP, an insecure context. `document.modelContext` is the current name and is read
|
|
55
|
+
* first; `navigator.modelContext` is the older one, and reading it where the document carries
|
|
56
|
+
* the object logs a deprecation warning in Chromium, so it is touched only as the fallback.
|
|
57
|
+
*/
|
|
58
|
+
export declare function findModelContext(): ModelContextLike | undefined;
|
|
59
|
+
//# sourceMappingURL=ModelContextLike.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ModelContextLike.d.ts","sourceRoot":"","sources":["../../../src/model-context/ModelContextLike.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;GAKG;AACH,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAC,EAAE,CAAC;IACxC,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC5C,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,2BAA2B;IAC1C,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,4BAA4B;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,2BAA2B,CAAC;IAC1C,wGAAwG;IACxG,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE;QAAC,MAAM,CAAC,EAAE,WAAW,CAAA;KAAC,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;CACvF;AAED,MAAM,WAAW,2BAA2B;IAC1C,uCAAuC;IACvC,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,oFAAoF;IACpF,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,YAAY,CAAC,IAAI,EAAE,oBAAoB,EAAE,OAAO,CAAC,EAAE,2BAA2B,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;CAC7G;AAED,eAAO,MAAM,kBAAkB,UAAW,OAAO,KAAG,KAAK,IAAI,gBAC0D,CAAC;AAExH;;;;;GAKG;AACH,wBAAgB,gBAAgB,IAAI,gBAAgB,GAAG,SAAS,CAQ/D"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const isModelContextLike = (value) => typeof value === "object" && value !== null && typeof value.registerTool === "function";
|
|
2
|
+
function findModelContext() {
|
|
3
|
+
const doc = globalThis.document;
|
|
4
|
+
const fromDocument = doc?.modelContext;
|
|
5
|
+
if (isModelContextLike(fromDocument)) return fromDocument;
|
|
6
|
+
const nav = globalThis.navigator;
|
|
7
|
+
const fromNavigator = nav?.modelContext;
|
|
8
|
+
if (isModelContextLike(fromNavigator)) return fromNavigator;
|
|
9
|
+
return void 0;
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
findModelContext,
|
|
13
|
+
isModelContextLike
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=ModelContextLike.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/model-context/ModelContextLike.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * What this package needs from the platform's model context, named structurally so that the\n * rest of the code never sees `document.modelContext`. WebMCP is a moving specification: the\n * registration method changed name and semantics within six months of this file being written.\n * When it moves again, this file and `findModelContext()` are where the change lands.\n */\n\n/**\n * The envelope every tool of this package returns. `content` is the compatibility floor every\n * agent reads; `structuredContent` is the same data for an agent that reads structured results.\n * `isError` marks a refusal the tool could phrase -- an unknown namespace, a missing criterion --\n * so that the wording reaches the agent instead of being flattened into a generic failure.\n */\nexport interface ModelContextToolResult {\n content: {type: 'text'; text: string}[];\n structuredContent?: Record<string, unknown>;\n isError?: boolean;\n}\n\nexport interface ModelContextToolAnnotations {\n readOnlyHint?: boolean;\n untrustedContentHint?: boolean;\n consequentialHint?: boolean;\n}\n\nexport interface ModelContextToolLike {\n name: string;\n title?: string;\n description: string;\n /** A JSON Schema object. */\n inputSchema: object;\n annotations?: ModelContextToolAnnotations;\n /** `input` is whatever the platform parsed -- an object for the tools here, but nothing forces that. */\n execute(input: unknown, options?: {signal?: AbortSignal}): Promise<unknown> | unknown;\n}\n\nexport interface ModelContextRegisterOptions {\n /** Aborting it takes the tool back. */\n signal?: AbortSignal;\n /** Passed through as the platform defines it; absent means the platform default. */\n exposedTo?: string[];\n}\n\nexport interface ModelContextLike {\n /**\n * `unknown` rather than a promise on purpose: an early Chrome preview returned nothing, the\n * specification returns a promise, and the caller awaits whatever it gets.\n */\n registerTool(tool: ModelContextToolLike, options?: ModelContextRegisterOptions): Promise<unknown> | unknown;\n}\n\nexport const isModelContextLike = (value: unknown): value is ModelContextLike =>\n typeof value === 'object' && value !== null && typeof (value as {registerTool?: unknown}).registerTool === 'function';\n\n/**\n * The platform's model context, or `undefined` where there is none: a worker, Node, a browser\n * without WebMCP, an insecure context. `document.modelContext` is the current name and is read\n * first; `navigator.modelContext` is the older one, and reading it where the document carries\n * the object logs a deprecation warning in Chromium, so it is touched only as the fallback.\n */\nexport function findModelContext(): ModelContextLike | undefined {\n const doc = (globalThis as {document?: {modelContext?: unknown}}).document;\n const fromDocument = doc?.modelContext;\n if (isModelContextLike(fromDocument)) return fromDocument;\n const nav = (globalThis as {navigator?: {modelContext?: unknown}}).navigator;\n const fromNavigator = nav?.modelContext;\n if (isModelContextLike(fromNavigator)) return fromNavigator;\n return undefined;\n}\n"],
|
|
5
|
+
"mappings": "AAmDO,MAAM,qBAAqB,CAAC,UACjC,OAAO,UAAU,YAAY,UAAU,QAAQ,OAAQ,MAAmC,iBAAiB;AAQtG,SAAS,mBAAiD;AAC/D,QAAM,MAAO,WAAqD;AAClE,QAAM,eAAe,KAAK;AAC1B,MAAI,mBAAmB,YAAY,EAAG,QAAO;AAC7C,QAAM,MAAO,WAAsD;AACnE,QAAM,gBAAgB,KAAK;AAC3B,MAAI,mBAAmB,aAAa,EAAG,QAAO;AAC9C,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { InspectRequest } from '../inspect/types.js';
|
|
2
|
+
import { type ModelContextLike } from './ModelContextLike.js';
|
|
3
|
+
import type { RedactRule } from './redactProps.js';
|
|
4
|
+
import type { NamespaceRule } from './toolSupport.js';
|
|
5
|
+
export interface ExposeOptions {
|
|
6
|
+
/** Where to register. Default: `document.modelContext`, then `navigator.modelContext`; neither means "not available". */
|
|
7
|
+
modelContext?: ModelContextLike;
|
|
8
|
+
/** Prefix for every tool name. Default `'shae-'`. Together with `modelContext` it names the registration this call shares. */
|
|
9
|
+
toolPrefix?: string;
|
|
10
|
+
/** Aborting it takes this call's share back; the tools leave with the last share. */
|
|
11
|
+
signal?: AbortSignal;
|
|
12
|
+
/** Passed through to `registerTool()` by the call that opens the registration. Default: not set, so the platform default applies. */
|
|
13
|
+
exposedTo?: string[];
|
|
14
|
+
/** Default limits for every tool call, set by the call that opens the registration; a call's own input wins field by field. */
|
|
15
|
+
limits?: Partial<InspectRequest>;
|
|
16
|
+
/** Property names whose values are replaced by `{$type: 'redacted'}` in every answer, on the Kernel's and the View's side alike. Property values only. Cumulates with every other share of the registration. */
|
|
17
|
+
redactProps?: RedactRule;
|
|
18
|
+
/** Which environments this share exposes: a list of namespaces or a predicate over the namespace an environment is registered under. Default: every environment that holds a namespace. The registration exposes the union over its shares; a namespace outside it is refused like an unknown one. */
|
|
19
|
+
namespaces?: NamespaceRule;
|
|
20
|
+
}
|
|
21
|
+
export interface ExposeHandle {
|
|
22
|
+
/** `false` when no model context was found; then `tools` is empty and nothing was registered. */
|
|
23
|
+
available: boolean;
|
|
24
|
+
/** The tool names of the shared registration, with the prefix. */
|
|
25
|
+
tools: string[];
|
|
26
|
+
/** Takes this call's share back; the tools leave with the last share. Idempotent. The same as aborting `options.signal`. */
|
|
27
|
+
dispose(): void;
|
|
28
|
+
}
|
|
29
|
+
export declare const DefaultToolPrefix = "shae-";
|
|
30
|
+
/**
|
|
31
|
+
* Registers the five read-only inspection tools on the platform's model context, so that an
|
|
32
|
+
* agent can see the Shadow Environments on the page. Nothing is exposed without this call or
|
|
33
|
+
* the `expose-to-model-context` attribute of `<shae-worker>`, which goes through it; every value
|
|
34
|
+
* in every answer is application state, and the docs say what that means before they show the
|
|
35
|
+
* first line of code.
|
|
36
|
+
*
|
|
37
|
+
* One registration per model context and prefix, shared: every call and every element is a
|
|
38
|
+
* share of it, the first opens it, the last to go closes it, and the tools answer from the union
|
|
39
|
+
* of what the shares expose and redact. A second call under the same prefix therefore joins
|
|
40
|
+
* rather than fails.
|
|
41
|
+
*
|
|
42
|
+
* Resolves, never rejects, where the platform has no model context -- the same application code
|
|
43
|
+
* runs in every browser. Rejects with what `registerTool()` rejected with -- a `NotAllowedError`
|
|
44
|
+
* under a Permissions Policy that disables `tools` -- and those are the caller's to handle.
|
|
45
|
+
* Registration is all-or-nothing: a rejection midway takes back what was registered before it.
|
|
46
|
+
*/
|
|
47
|
+
export declare function exposeShadowEnvsToModelContext(options?: ExposeOptions): Promise<ExposeHandle>;
|
|
48
|
+
//# sourceMappingURL=exposeShadowEnvsToModelContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exposeShadowEnvsToModelContext.d.ts","sourceRoot":"","sources":["../../../src/model-context/exposeShadowEnvsToModelContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,qBAAqB,CAAC;AAExD,OAAO,EAAmB,KAAK,gBAAgB,EAAC,MAAM,uBAAuB,CAAC;AAC9E,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAC;AAEjD,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAEpD,MAAM,WAAW,aAAa;IAC5B,yHAAyH;IACzH,YAAY,CAAC,EAAE,gBAAgB,CAAC;IAChC,8HAA8H;IAC9H,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qFAAqF;IACrF,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,qIAAqI;IACrI,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,+HAA+H;IAC/H,MAAM,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC;IACjC,gNAAgN;IAChN,WAAW,CAAC,EAAE,UAAU,CAAC;IACzB,sSAAsS;IACtS,UAAU,CAAC,EAAE,aAAa,CAAC;CAC5B;AAED,MAAM,WAAW,YAAY;IAC3B,iGAAiG;IACjG,SAAS,EAAE,OAAO,CAAC;IACnB,kEAAkE;IAClE,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,4HAA4H;IAC5H,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,eAAO,MAAM,iBAAiB,UAAU,CAAC;AAEzC;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,8BAA8B,CAAC,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,YAAY,CAAC,CAgCvG"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ConsoleLogger } from "../utils/ConsoleLogger.js";
|
|
2
|
+
import { findModelContext } from "./ModelContextLike.js";
|
|
3
|
+
import { joinSharedExposure } from "./sharedExposure.js";
|
|
4
|
+
const DefaultToolPrefix = "shae-";
|
|
5
|
+
async function exposeShadowEnvsToModelContext(options = {}) {
|
|
6
|
+
const modelContext = options.modelContext ?? findModelContext();
|
|
7
|
+
if (modelContext === void 0) {
|
|
8
|
+
new ConsoleLogger("ModelContext").info("no model context on this platform, nothing registered");
|
|
9
|
+
return { available: false, tools: [], dispose() {
|
|
10
|
+
} };
|
|
11
|
+
}
|
|
12
|
+
const { signal } = options;
|
|
13
|
+
if (signal?.aborted) return { available: true, tools: [], dispose() {
|
|
14
|
+
} };
|
|
15
|
+
const settings = { limits: options.limits ?? {}, ...options.exposedTo !== void 0 ? { exposedTo: options.exposedTo } : {} };
|
|
16
|
+
const membership = joinSharedExposure(
|
|
17
|
+
modelContext,
|
|
18
|
+
options.toolPrefix ?? DefaultToolPrefix,
|
|
19
|
+
{ namespaces: options.namespaces, redactProps: options.redactProps },
|
|
20
|
+
settings
|
|
21
|
+
);
|
|
22
|
+
const dispose = () => {
|
|
23
|
+
membership.leave();
|
|
24
|
+
signal?.removeEventListener("abort", dispose);
|
|
25
|
+
};
|
|
26
|
+
signal?.addEventListener("abort", dispose, { once: true });
|
|
27
|
+
try {
|
|
28
|
+
const tools = await membership.tools;
|
|
29
|
+
return { available: true, tools, dispose };
|
|
30
|
+
} catch (error) {
|
|
31
|
+
dispose();
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export {
|
|
36
|
+
DefaultToolPrefix,
|
|
37
|
+
exposeShadowEnvsToModelContext
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=exposeShadowEnvsToModelContext.js.map
|