@silverprotocol/core 0.12.5 → 1.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -9
- package/dist/agjson.d.ts +594 -594
- package/dist/agjson.d.ts.map +1 -1
- package/dist/agjson.js +25 -14
- package/dist/agjson.js.map +1 -1
- package/dist/atomic-push.js.map +1 -1
- package/dist/copy-json.d.ts +27 -4
- package/dist/copy-json.d.ts.map +1 -1
- package/dist/copy-json.js +111 -1
- package/dist/copy-json.js.map +1 -1
- package/dist/depth.d.ts +0 -8
- package/dist/depth.d.ts.map +1 -1
- package/dist/depth.js +0 -9
- package/dist/depth.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/ingest.d.ts +2 -2
- package/dist/ingest.js +4 -4
- package/dist/ingest.js.map +1 -1
- package/dist/json-patch.d.ts.map +1 -1
- package/dist/json-patch.js +5 -1
- package/dist/json-patch.js.map +1 -1
- package/dist/persist.js.map +1 -1
- package/dist/record.js +2 -2
- package/dist/record.js.map +1 -1
- package/dist/reduce.d.ts +1 -1
- package/dist/reduce.d.ts.map +1 -1
- package/dist/reduce.js +277 -113
- package/dist/reduce.js.map +1 -1
- package/dist/stream-assembler.d.ts +6 -7
- package/dist/stream-assembler.d.ts.map +1 -1
- package/dist/stream-assembler.js +21 -18
- package/dist/stream-assembler.js.map +1 -1
- package/dist/wire.d.ts +21 -3
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +34 -5
- package/dist/wire.js.map +1 -1
- package/package.json +1 -1
- package/src/agjson.ts +36 -25
- package/src/atomic-push.ts +2 -2
- package/src/copy-json.ts +107 -4
- package/src/depth.ts +0 -10
- package/src/index.ts +1 -0
- package/src/ingest.ts +4 -4
- package/src/json-patch.ts +5 -1
- package/src/record.ts +2 -2
- package/src/reduce.ts +256 -112
- package/src/stream-assembler.ts +21 -18
- package/src/wire.ts +36 -6
package/dist/wire.js
CHANGED
|
@@ -29,6 +29,22 @@ export const JSON_SAFE_MAX_DEPTH_MARK = "[MaxDepth]";
|
|
|
29
29
|
* @beta
|
|
30
30
|
*/
|
|
31
31
|
export const JSON_SAFE_MAX_DEPTH = 1000;
|
|
32
|
+
/**
|
|
33
|
+
* The levels an event's own members may add above a carried value that
|
|
34
|
+
* {@link toJsonValueSafe} capped at {@link JSON_SAFE_MAX_DEPTH}.
|
|
35
|
+
*
|
|
36
|
+
* @beta
|
|
37
|
+
*/
|
|
38
|
+
export const AG_EVENT_DEPTH_ALLOWANCE = 16;
|
|
39
|
+
/**
|
|
40
|
+
* The deepest node an event may hold, counted from the event root: the root is
|
|
41
|
+
* at depth 0 and a node's depth is the number of containers above it.
|
|
42
|
+
* {@link JSON_SAFE_MAX_DEPTH} plus {@link AG_EVENT_DEPTH_ALLOWANCE}. A consuming
|
|
43
|
+
* ingest rejects a deeper event, and a reducer parks on one.
|
|
44
|
+
*
|
|
45
|
+
* @beta
|
|
46
|
+
*/
|
|
47
|
+
export const AG_EVENT_MAX_DEPTH = JSON_SAFE_MAX_DEPTH + AG_EVENT_DEPTH_ALLOWANCE;
|
|
32
48
|
/**
|
|
33
49
|
* True when `v` is ALREADY a plain JSON value, i.e. exactly what a JSON
|
|
34
50
|
* round-trip of it would produce: `null`, a string, a boolean, a finite
|
|
@@ -41,6 +57,15 @@ export const JSON_SAFE_MAX_DEPTH = 1000;
|
|
|
41
57
|
* @beta
|
|
42
58
|
*/
|
|
43
59
|
export function isJsonValue(v) {
|
|
60
|
+
return jsonWalk(v, false);
|
|
61
|
+
}
|
|
62
|
+
/** {@link isJsonValue} where every object also has the ordinary prototype
|
|
63
|
+
* (`Object.prototype`, or `Array.prototype` for an array): no null-prototype
|
|
64
|
+
* node. The fast path of {@link toJsonValueSafeWithIssues} uses it. */
|
|
65
|
+
function isOrdinaryJsonValue(v) {
|
|
66
|
+
return jsonWalk(v, true);
|
|
67
|
+
}
|
|
68
|
+
function jsonWalk(v, ordinaryOnly) {
|
|
44
69
|
const ancestors = [];
|
|
45
70
|
const walk = (x, depth) => {
|
|
46
71
|
if (x === null)
|
|
@@ -62,6 +87,8 @@ export function isJsonValue(v) {
|
|
|
62
87
|
ancestors.push(o);
|
|
63
88
|
try {
|
|
64
89
|
if (Array.isArray(o)) {
|
|
90
|
+
if (ordinaryOnly && Object.getPrototypeOf(o) !== Array.prototype)
|
|
91
|
+
return false;
|
|
65
92
|
for (let i = 0; i < o.length; i++) {
|
|
66
93
|
if (!(i in o) || !walk(o[i], depth + 1))
|
|
67
94
|
return false;
|
|
@@ -69,7 +96,7 @@ export function isJsonValue(v) {
|
|
|
69
96
|
return true;
|
|
70
97
|
}
|
|
71
98
|
const proto = Object.getPrototypeOf(o);
|
|
72
|
-
if (proto !== Object.prototype && proto !== null)
|
|
99
|
+
if (proto !== Object.prototype && (ordinaryOnly || proto !== null))
|
|
73
100
|
return false;
|
|
74
101
|
if (typeof o.toJSON === "function")
|
|
75
102
|
return false;
|
|
@@ -107,8 +134,10 @@ export function isJsonValue(v) {
|
|
|
107
134
|
* Normalizer MUST NOT throw out of `push()` (SPEC.md §8.0). Keep
|
|
108
135
|
* `JsonValue.parse` for validating data that is already JSON.
|
|
109
136
|
*
|
|
110
|
-
* Plain JSON input (see {@link isJsonValue})
|
|
111
|
-
*
|
|
137
|
+
* Plain JSON input (see {@link isJsonValue}) whose every object has the
|
|
138
|
+
* ordinary prototype is returned UNCHANGED, as the same reference, with no
|
|
139
|
+
* copy. Anything else, a null-prototype node included, is rebuilt as a fresh
|
|
140
|
+
* value whose every object has the ordinary prototype and that
|
|
112
141
|
* applies `JSON.stringify`'s own rules per node, so for JSON-able input the
|
|
113
142
|
* result serializes identically to `toJsonValue(v)`:
|
|
114
143
|
* - `toJSON` is honoured once per node, with the member key (a `Date` becomes
|
|
@@ -179,7 +208,7 @@ function isErrorObject(o) {
|
|
|
179
208
|
* @beta
|
|
180
209
|
*/
|
|
181
210
|
export function toJsonValueSafeWithIssues(v) {
|
|
182
|
-
if (
|
|
211
|
+
if (isOrdinaryJsonValue(v))
|
|
183
212
|
return { value: v, issues: [] };
|
|
184
213
|
const issues = [];
|
|
185
214
|
const ancestors = [];
|
|
@@ -234,7 +263,7 @@ export function toJsonValueSafeWithIssues(v) {
|
|
|
234
263
|
return JSON_SAFE_MAX_DEPTH_MARK;
|
|
235
264
|
}
|
|
236
265
|
if (isErrorObject(obj)) {
|
|
237
|
-
// Deliberate extension beyond JSON (
|
|
266
|
+
// Deliberate extension beyond JSON (ruled 2026-09-24): an Error's
|
|
238
267
|
// `name` and `message` are not enumerable own data, so JSON drops them
|
|
239
268
|
// and a live error part loses its text. Map it to {name, message, …own
|
|
240
269
|
// enumerable props}, and NEVER `stack` (it holds local file paths).
|
package/dist/wire.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wire.js","sourceRoot":"","sources":["../src/wire.ts"],"names":[],"mappings":"AAUA,MAAM,UAAU,MAAM,CAAC,CAAU;IAC/B,MAAM,CAAC,GAAc,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;IACnD,OAAO,CAAC,CAAC;AACX,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,CAAU;IACpC,MAAM,CAAC,GAAc,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;IACnD,OAAO,CAAC,CAAC;AACX,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,YAAY,CAAC;AAC/C;;;;GAIG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,YAAY,CAAC;AACrD;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"wire.js","sourceRoot":"","sources":["../src/wire.ts"],"names":[],"mappings":"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EAAE,CAAC,CAAC,CAAC;IACnC,OAAO,EAAE,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,CAAC;AACtD,CAAC"}
|
package/package.json
CHANGED
package/src/agjson.ts
CHANGED
|
@@ -121,7 +121,7 @@ export type AgSource = z.infer<typeof AgSource>;
|
|
|
121
121
|
|
|
122
122
|
// Grounding-source payload union (spec §2/§4): the §4 `source` event's payload
|
|
123
123
|
// union, extracted here so it can be reused verbatim by BOTH the event arm and
|
|
124
|
-
// AgTurnRecord.sources[] — one definition, DRY, cast-free
|
|
124
|
+
// AgTurnRecord.sources[] — one definition, DRY, cast-free.
|
|
125
125
|
export const AgSourcePayload = z.union([
|
|
126
126
|
AgSource,
|
|
127
127
|
z.object({ url: z.string(), title: z.string().optional() }),
|
|
@@ -532,7 +532,7 @@ export type AgBlock =
|
|
|
532
532
|
toolMetadata?: AgMeta; // per-tool metadata bag (Vercel)
|
|
533
533
|
dynamic?: boolean; // Vercel dynamic-vs-static tool distinction
|
|
534
534
|
pendingInput?: AgPendingInput; // MCP MRTR carrier when outcome==="input_required"
|
|
535
|
-
preliminary?: boolean; // set when the result is partial/kept-open (tool.done.more:true); cleared by the final tool.done
|
|
535
|
+
preliminary?: boolean; // set when the result is partial/kept-open (tool.done.more:true); cleared by the final tool.done
|
|
536
536
|
isError?: boolean; // MCP-frozen field, kept verbatim (derived: outcome==="error")
|
|
537
537
|
providerMetadata?: AgProviderMeta;
|
|
538
538
|
annotations?: AgAnnotations;
|
|
@@ -555,7 +555,7 @@ const blockAnno = {
|
|
|
555
555
|
};
|
|
556
556
|
|
|
557
557
|
/**
|
|
558
|
-
* The resource-link block (draft.5
|
|
558
|
+
* The resource-link block (draft.5): MCP's ResourceLink members,
|
|
559
559
|
* each optional beside the required `uri`. `size` is an integer, as ruled.
|
|
560
560
|
* It is exported so a normalizer can check each native member against
|
|
561
561
|
* core's own schema (`AgResourceLinkBlock.shape.<member>.safeParse(v)`), and
|
|
@@ -671,7 +671,7 @@ export const AgBlock: z.ZodType<AgBlock> = z.lazy(() =>
|
|
|
671
671
|
// (HITL) arm: the turn parks on one or more asks; `result` MAY accompany a pause
|
|
672
672
|
// (a partial value emitted before parking). `{type:"aborted"}` is turn.abort's
|
|
673
673
|
// dedicated marker (symmetric with the error arm) — taskState is verbatim-A2A
|
|
674
|
-
// only and is NEVER reducer-invented
|
|
674
|
+
// only and is NEVER reducer-invented.
|
|
675
675
|
export const AgOutcome = z.discriminatedUnion("type", [
|
|
676
676
|
z.object({ type: z.literal("success"), result: JsonValue.optional() }),
|
|
677
677
|
// retriable (draft.5): the producer's judgement, recorded from turn.error; absent = unstated, not false.
|
|
@@ -794,17 +794,17 @@ export const AgTurnRecord = z.object({
|
|
|
794
794
|
sourceIds: z.array(z.string()).optional(),
|
|
795
795
|
sources: z.array(z.object({
|
|
796
796
|
sourceId: z.string(),
|
|
797
|
-
source: AgSourcePayload, // the §4 source arm's payload union, landed verbatim
|
|
797
|
+
source: AgSourcePayload, // the §4 source arm's payload union, landed verbatim
|
|
798
798
|
chunkIndex: z.number().optional(),
|
|
799
799
|
providerMetadata: AgProviderMeta.optional(),
|
|
800
|
-
})).optional(), // grounding sources folded from source events
|
|
800
|
+
})).optional(), // grounding sources folded from source events; sourceIds stays as the derived index
|
|
801
801
|
promptBlocked: z.object({
|
|
802
802
|
reason: z.enum(["safety", "blocklist", "prohibited", "other"]), // mirrors the §4 prompt.blocked reason enum exactly
|
|
803
803
|
reasonRaw: z.string().optional(), // folded from prompt.blocked.reasonRaw verbatim (draft.8)
|
|
804
804
|
safety: z.array(AgSafety).optional(),
|
|
805
|
-
}).optional(),
|
|
805
|
+
}).optional(),
|
|
806
806
|
asks: z.array(AgPausedAsk).optional(),
|
|
807
|
-
taskState: z.string().optional(), // verbatim A2A TaskState (never reducer-invented
|
|
807
|
+
taskState: z.string().optional(), // verbatim A2A TaskState (never reducer-invented); no outcome-target mapping
|
|
808
808
|
displayRequired: z.array(AgDisplayRequired).optional(),
|
|
809
809
|
trigger: AgTrigger.optional(), // what triggered this turn (A2-additive)
|
|
810
810
|
guardrails: z.array(z.object({
|
|
@@ -949,7 +949,7 @@ export type AgRunConfig = z.infer<typeof AgRunConfig>;
|
|
|
949
949
|
|
|
950
950
|
// The spec version this SDK implements (SPEC.md status line + §12). Consumers
|
|
951
951
|
// reject a MAJOR mismatch and accept any same-major version (§12 negotiation).
|
|
952
|
-
export const AGJSON_VERSION = "1.0.0-
|
|
952
|
+
export const AGJSON_VERSION = "1.0.0-rc.1";
|
|
953
953
|
|
|
954
954
|
const agjsonWireVersion = z
|
|
955
955
|
.string()
|
|
@@ -1010,18 +1010,29 @@ const surfaceEnvelope = {
|
|
|
1010
1010
|
|
|
1011
1011
|
// A2UI v1.0 client→server `action` (A2UI-frozen names VERBATIM, §0.4). `context`
|
|
1012
1012
|
// = the A2UI resolved data-bindings — the SOLE sanctioned Record<string, unknown>
|
|
1013
|
-
// (map shape known: string keys; each value opaque per §0.1).
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1013
|
+
// (map shape known: string keys; each value opaque per §0.1). `actionId` is
|
|
1014
|
+
// REQUIRED when `wantResponse` is true (§3).
|
|
1015
|
+
export const AgA2uiSurfaceAction = z
|
|
1016
|
+
.object({
|
|
1017
|
+
...surfaceEnvelope,
|
|
1018
|
+
surface: z.literal("a2ui"),
|
|
1019
|
+
a2uiMessage: z.literal("action"),
|
|
1020
|
+
name: z.string(),
|
|
1021
|
+
sourceComponentId: z.string(),
|
|
1022
|
+
timestamp: z.string(),
|
|
1023
|
+
context: z.record(z.string(), z.unknown()),
|
|
1024
|
+
wantResponse: z.boolean().optional(),
|
|
1025
|
+
actionId: z.string().optional(),
|
|
1026
|
+
})
|
|
1027
|
+
.superRefine((v, ctx) => {
|
|
1028
|
+
if (v.wantResponse === true && v.actionId === undefined) {
|
|
1029
|
+
ctx.addIssue({
|
|
1030
|
+
code: "custom",
|
|
1031
|
+
message: "wantResponse: true requires actionId (A2UI v1.0 action)",
|
|
1032
|
+
path: ["actionId"],
|
|
1033
|
+
});
|
|
1034
|
+
}
|
|
1035
|
+
});
|
|
1025
1036
|
export type AgA2uiSurfaceAction = z.infer<typeof AgA2uiSurfaceAction>;
|
|
1026
1037
|
|
|
1027
1038
|
// A2UI v1.0 client→server `functionResponse` (inbound leg of the server
|
|
@@ -1146,7 +1157,7 @@ export type AgOpenAiWidgetAction = z.infer<typeof AgOpenAiWidgetAction>;
|
|
|
1146
1157
|
// (a2uiMessage / method), so a validation issue names the member that is
|
|
1147
1158
|
// actually wrong: a plain z.union let every non-matching branch report its
|
|
1148
1159
|
// own `surface` literal, and the input check (input-check.ts) misclassified
|
|
1149
|
-
// e.g. an mcp-app ui/open-link with a non-string url
|
|
1160
|
+
// e.g. an mcp-app ui/open-link with a non-string url. Same members,
|
|
1150
1161
|
// same literals, same accepted values; only the failure path is exact.
|
|
1151
1162
|
export const AgSurfaceInteraction = z.discriminatedUnion("surface", [
|
|
1152
1163
|
z.discriminatedUnion("a2uiMessage", [AgA2uiSurfaceAction, AgA2uiFunctionResponse, AgA2uiError]),
|
|
@@ -1307,7 +1318,7 @@ export const AgClosedEvent = z.discriminatedUnion("type", [
|
|
|
1307
1318
|
id: z.string(),
|
|
1308
1319
|
phase: z.string().optional(), // draft.4: REPLACES the start value when present
|
|
1309
1320
|
providerMetadata: AgProviderMeta.optional(),
|
|
1310
|
-
// STREAMED-text citations carrier
|
|
1321
|
+
// STREAMED-text citations carrier: citations for a streamed text
|
|
1311
1322
|
// block arrive here (not as a duplicate id-less supplement block) and attach
|
|
1312
1323
|
// to the sealed block named by `id` (spec §5 text.end row).
|
|
1313
1324
|
citations: z.array(AgCitation).optional(),
|
|
@@ -1553,7 +1564,7 @@ export const AgClosedEvent = z.discriminatedUnion("type", [
|
|
|
1553
1564
|
artifacts: z.array(AgArtifact).optional(),
|
|
1554
1565
|
memory: z.array(AgMemoryRecord).optional(),
|
|
1555
1566
|
}),
|
|
1556
|
-
// ── HOST DISPLAY/RUNTIME HINT ── live-only; `capabilities` here = HOST surface render hint
|
|
1567
|
+
// ── HOST DISPLAY/RUNTIME HINT ── live-only; `capabilities` here = HOST surface render hint.
|
|
1557
1568
|
z.object({
|
|
1558
1569
|
...base,
|
|
1559
1570
|
type: z.literal("host.context"),
|
|
@@ -1601,7 +1612,7 @@ export const AgClosedEvent = z.discriminatedUnion("type", [
|
|
|
1601
1612
|
...base,
|
|
1602
1613
|
type: z.literal("ui.display-mode"),
|
|
1603
1614
|
mode: AgDisplayMode,
|
|
1604
|
-
granted: AgDisplayMode.optional(), // authoritative reply leg
|
|
1615
|
+
granted: AgDisplayMode.optional(), // authoritative reply leg
|
|
1605
1616
|
surfaceId: z.string().optional(),
|
|
1606
1617
|
toolCallId: z.string().optional(),
|
|
1607
1618
|
}),
|
package/src/atomic-push.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* atomic-push.ts — per-native atomicity for a Normalizer (the
|
|
3
|
-
* ruling, 2026-09-24, binding
|
|
2
|
+
* atomic-push.ts — per-native atomicity for a Normalizer (the no-throw guard
|
|
3
|
+
* ruling, 2026-09-24, binding: option B).
|
|
4
4
|
*
|
|
5
5
|
* A Normalizer MUST NOT throw out of push() (SPEC.md §8.0). When handling
|
|
6
6
|
* one native throws anyway, the events it had already produced must be
|
package/src/copy-json.ts
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* copy-json.ts
|
|
2
|
+
* copy-json.ts
|
|
3
3
|
*
|
|
4
4
|
* The one own-property deep copy every consumer-side reader in core uses, so
|
|
5
|
-
* the §13 rule on `__proto__` has a single code path: stage-1 ingest
|
|
5
|
+
* the §13.7 rule on `__proto__` has a single code path: stage-1 ingest
|
|
6
6
|
* (ingest.ts), the stored-record readers (record.ts) and the input check
|
|
7
|
-
* (input-check.ts).
|
|
7
|
+
* (input-check.ts). `copyJson` is exported for hosts that seed a fold from
|
|
8
|
+
* their own store. The two walks below apply the same omission on the fold's
|
|
9
|
+
* and the emitter's own paths.
|
|
8
10
|
*/
|
|
9
11
|
import type { JsonValue } from "./agjson.js";
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
|
-
* Own-property deep copy of a JSON value, dropping `__proto__` at
|
|
14
|
+
* Own-property deep copy of a JSON value, dropping an own `__proto__` member at
|
|
15
|
+
* every depth. Every object and array in the copy has the ordinary prototype.
|
|
16
|
+
* A host that seeds a fold from its own store copies the stored value with it.
|
|
13
17
|
* The copy is iterative, so no nesting depth overflows the stack; a node
|
|
14
18
|
* reached twice is copied once.
|
|
19
|
+
*
|
|
20
|
+
* @beta
|
|
15
21
|
*/
|
|
16
22
|
export function copyJson(v: JsonValue): JsonValue {
|
|
17
23
|
type Node = JsonValue[] | { [k: string]: JsonValue };
|
|
@@ -48,3 +54,100 @@ export function copyJson(v: JsonValue): JsonValue {
|
|
|
48
54
|
}
|
|
49
55
|
return root;
|
|
50
56
|
}
|
|
57
|
+
|
|
58
|
+
const PROTO = "__proto__";
|
|
59
|
+
|
|
60
|
+
/** True for an object this module treats as a JSON node: an array or a plain-or-null-prototype object. */
|
|
61
|
+
function isPlainNode(v: object): boolean {
|
|
62
|
+
if (Array.isArray(v)) return true;
|
|
63
|
+
const proto: unknown = Object.getPrototypeOf(v);
|
|
64
|
+
return proto === Object.prototype || proto === null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* INTERNAL. Removes an own `__proto__` member at every depth of a value the
|
|
69
|
+
* caller owns (a structuredClone copy). `delete` removes own members only, so
|
|
70
|
+
* a node without one is untouched. The walk is iterative and visits each
|
|
71
|
+
* object once, so neither nesting depth nor a cycle bounds it.
|
|
72
|
+
*/
|
|
73
|
+
export function deleteOwnProtoMember(v: unknown): void {
|
|
74
|
+
const seen = new WeakSet<object>();
|
|
75
|
+
const stack: unknown[] = [v];
|
|
76
|
+
while (stack.length > 0) {
|
|
77
|
+
const x = stack.pop();
|
|
78
|
+
if (x === null || typeof x !== "object" || seen.has(x)) continue;
|
|
79
|
+
seen.add(x);
|
|
80
|
+
if (Array.isArray(x)) {
|
|
81
|
+
for (let i = 0; i < x.length; i++) stack.push(x[i]);
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const o = x as Record<string, unknown>;
|
|
85
|
+
if (Object.hasOwn(o, PROTO)) delete o[PROTO];
|
|
86
|
+
for (const k in o) if (Object.hasOwn(o, k)) stack.push(o[k]);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* INTERNAL. A copy of `v` without an own `__proto__` member at any depth that
|
|
92
|
+
* never mutates `v`: when any node holds the member, its arrays and plain (or
|
|
93
|
+
* null-prototype) objects are rebuilt with the ordinary prototype, members DEFINED, never
|
|
94
|
+
* assigned; any other value (a function, a class instance) is carried by
|
|
95
|
+
* reference. Returns `v` itself when no node holds the member, so the common
|
|
96
|
+
* case allocates nothing. Both walks are iterative and visit each object once:
|
|
97
|
+
* a node reached twice is copied once, and a cycle is copied as a cycle.
|
|
98
|
+
*/
|
|
99
|
+
export function withoutOwnProtoMember<T>(v: T): T {
|
|
100
|
+
return (hasOwnProtoMember(v) ? rebuild(v) : v) as T;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function hasOwnProtoMember(v: unknown): boolean {
|
|
104
|
+
const seen = new WeakSet<object>();
|
|
105
|
+
const stack: unknown[] = [v];
|
|
106
|
+
while (stack.length > 0) {
|
|
107
|
+
const x = stack.pop();
|
|
108
|
+
if (x === null || typeof x !== "object" || seen.has(x) || !isPlainNode(x)) continue;
|
|
109
|
+
seen.add(x);
|
|
110
|
+
if (Array.isArray(x)) {
|
|
111
|
+
for (let i = 0; i < x.length; i++) stack.push(x[i]);
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
const o = x as Record<string, unknown>;
|
|
115
|
+
if (Object.hasOwn(o, PROTO)) return true;
|
|
116
|
+
for (const k in o) if (Object.hasOwn(o, k)) stack.push(o[k]);
|
|
117
|
+
}
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function rebuild(v: unknown): unknown {
|
|
122
|
+
const copies = new Map<object, unknown[] | Record<string, unknown>>();
|
|
123
|
+
const pending: object[] = [];
|
|
124
|
+
const copyOf = (x: unknown): unknown => {
|
|
125
|
+
if (x === null || typeof x !== "object" || !isPlainNode(x)) return x;
|
|
126
|
+
let c = copies.get(x);
|
|
127
|
+
if (c === undefined) {
|
|
128
|
+
c = Array.isArray(x) ? new Array<unknown>(x.length) : {};
|
|
129
|
+
copies.set(x, c);
|
|
130
|
+
pending.push(x);
|
|
131
|
+
}
|
|
132
|
+
return c;
|
|
133
|
+
};
|
|
134
|
+
const root = copyOf(v);
|
|
135
|
+
while (pending.length > 0) {
|
|
136
|
+
const x = pending.pop()!;
|
|
137
|
+
const c = copies.get(x)!;
|
|
138
|
+
if (Array.isArray(x)) {
|
|
139
|
+
for (let i = 0; i < x.length; i++) if (i in x) (c as unknown[])[i] = copyOf(x[i]);
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
for (const k of Object.keys(x)) {
|
|
143
|
+
if (k === PROTO) continue;
|
|
144
|
+
Object.defineProperty(c, k, {
|
|
145
|
+
value: copyOf((x as Record<string, unknown>)[k]),
|
|
146
|
+
enumerable: true,
|
|
147
|
+
writable: true,
|
|
148
|
+
configurable: true,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return root;
|
|
153
|
+
}
|
package/src/depth.ts
CHANGED
|
@@ -7,16 +7,6 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import type { JsonValue } from "./agjson.js";
|
|
10
|
-
import { JSON_SAFE_MAX_DEPTH } from "./wire.js";
|
|
11
|
-
|
|
12
|
-
/** The levels an event's own members may add above a carried value that toJsonValueSafe capped at JSON_SAFE_MAX_DEPTH. */
|
|
13
|
-
export const AG_EVENT_DEPTH_ALLOWANCE = 16;
|
|
14
|
-
/**
|
|
15
|
-
* The deepest node an event may hold, counted from the event root: the root is
|
|
16
|
-
* at depth 0 and a node's depth is the number of containers above it.
|
|
17
|
-
* JSON_SAFE_MAX_DEPTH plus AG_EVENT_DEPTH_ALLOWANCE.
|
|
18
|
-
*/
|
|
19
|
-
export const AG_EVENT_MAX_DEPTH = JSON_SAFE_MAX_DEPTH + AG_EVENT_DEPTH_ALLOWANCE;
|
|
20
10
|
|
|
21
11
|
/** What one scan of a value found: a node past the bound, and an own `__proto__` member. */
|
|
22
12
|
export interface DepthScan {
|
package/src/index.ts
CHANGED
package/src/ingest.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Consumer-ingestion posture (SPEC §0.2 / §12
|
|
2
|
+
* Consumer-ingestion posture (SPEC §0.2 / §12).
|
|
3
3
|
*
|
|
4
4
|
* A consumer validating incoming events MUST parse-known-else-skip and pass
|
|
5
5
|
* unknown fields through, so additive-minor spec revisions survive. This is
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
* typed ext event: it never folds, but a Reducer counts its `seq` slot,
|
|
33
33
|
* so an ignored event can no longer open a false gap. `raw` is the
|
|
34
34
|
* original frame (same copy rules) and is LIVE-ONLY: never persist it.
|
|
35
|
-
* An envelope holding a node deeper than
|
|
35
|
+
* An envelope holding a node deeper than AG_EVENT_MAX_DEPTH becomes the
|
|
36
36
|
* same stub without being parsed, since the schema parse's recursion
|
|
37
37
|
* would overflow on it; its `raw` is the frame as toJsonValueSafe
|
|
38
38
|
* renders it, cut off at JSON_SAFE_MAX_DEPTH, so the stub itself stays
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
*/
|
|
45
45
|
import { AgEvent, type JsonValue } from "./agjson.js";
|
|
46
46
|
import { copyJson } from "./copy-json.js";
|
|
47
|
-
import {
|
|
48
|
-
import { JSON_SAFE_MAX_DEPTH_MARK, toJsonValueSafe } from "./wire.js";
|
|
47
|
+
import { exceedsDepth } from "./depth.js";
|
|
48
|
+
import { AG_EVENT_MAX_DEPTH, JSON_SAFE_MAX_DEPTH_MARK, toJsonValueSafe } from "./wire.js";
|
|
49
49
|
|
|
50
50
|
/** Why an input is not a well-formed envelope (draft.4 §0.2). */
|
|
51
51
|
export type AgIngestRejectReason = "not-object" | "type-not-string" | "seq-not-number";
|
package/src/json-patch.ts
CHANGED
|
@@ -16,6 +16,7 @@ import type { JsonValue } from "./agjson.js";
|
|
|
16
16
|
// RFC-6901 pointer parsing:
|
|
17
17
|
// • split on "/"; unescape "~1" → "/" then "~0" → "~" (ORDER MATTERS).
|
|
18
18
|
// • "" (empty pointer) = the whole document (root replacement).
|
|
19
|
+
// • A reference token "__proto__" fails the operation (path or from).
|
|
19
20
|
//
|
|
20
21
|
// Member resolution: a token names an object member only when the object holds
|
|
21
22
|
// it as its OWN member; an inherited name (toString, constructor, …) is absent.
|
|
@@ -61,10 +62,13 @@ function isJsonArray(v: JsonValue): v is JsonValue[] {
|
|
|
61
62
|
function parsePointer(ptr: string): string[] | null {
|
|
62
63
|
if (ptr === "") return [];
|
|
63
64
|
if (!ptr.startsWith("/")) return null; // malformed — must start with "/"
|
|
64
|
-
|
|
65
|
+
const tokens = ptr
|
|
65
66
|
.slice(1)
|
|
66
67
|
.split("/")
|
|
67
68
|
.map((tok) => tok.replace(/~1/g, "/").replace(/~0/g, "~"));
|
|
69
|
+
// A "__proto__" token never names a member: the operation fails.
|
|
70
|
+
if (tokens.includes("__proto__")) return null;
|
|
71
|
+
return tokens;
|
|
68
72
|
}
|
|
69
73
|
|
|
70
74
|
/** The object's OWN member `tok`, or undefined when it holds none (inherited names included). */
|
package/src/record.ts
CHANGED
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
*/
|
|
37
37
|
import { AgBlock, AgMemoryRecord, AgMessage, type JsonValue } from "./agjson.js";
|
|
38
38
|
import { copyJson } from "./copy-json.js";
|
|
39
|
-
import { toJsonValueSafe } from "./wire.js";
|
|
40
|
-
import {
|
|
39
|
+
import { AG_EVENT_DEPTH_ALLOWANCE, AG_EVENT_MAX_DEPTH, toJsonValueSafe } from "./wire.js";
|
|
40
|
+
import { isJsonValueWithin } from "./depth.js";
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* The deepest node a stored record may hold, from its root. The fold places a
|