@tangle-network/agent-interface 5.10.25 → 5.10.27

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.
@@ -12,6 +12,7 @@ export declare function sha256Bytes(value: Uint8Array): Sha256Digest;
12
12
  /** RFC 8785 serialization used by every candidate-producing package. */
13
13
  export declare function canonicalCandidateJson(value: unknown): string;
14
14
  export declare function canonicalCandidateBytes(value: unknown): Uint8Array;
15
+ /** The digest of {@link canonicalCandidateBytes}, hashed piece by piece: memory stays near the value's own size, not several times its encoding. */
15
16
  export declare function canonicalCandidateDigest(value: unknown): Sha256Digest;
16
17
  export declare function omitTopLevelDigest<T extends {
17
18
  digest: Sha256Digest;
@@ -36,40 +36,65 @@ export function sha256Utf8(value) {
36
36
  return sha256Bytes(new TextEncoder().encode(value));
37
37
  }
38
38
  export function sha256Bytes(value) {
39
- const bytes = sha256(value);
40
- const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
41
- return `sha256:${hex}`;
39
+ return digestHex(sha256(value));
40
+ }
41
+ function digestHex(bytes) {
42
+ return `sha256:${Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("")}`;
42
43
  }
43
44
  /** RFC 8785 serialization used by every candidate-producing package. */
44
45
  export function canonicalCandidateJson(value) {
45
- if (!isCanonicalJsonValue(value)) {
46
- throw new Error("candidate document must be finite, acyclic RFC 8785 JSON");
47
- }
48
- return serializeCanonicalCandidate(value);
46
+ const parts = [];
47
+ writeCanonicalCandidate(value, (part) => parts.push(part));
48
+ return parts.join("");
49
49
  }
50
50
  export function canonicalCandidateBytes(value) {
51
51
  return new TextEncoder().encode(canonicalCandidateJson(value));
52
52
  }
53
+ /** The digest of {@link canonicalCandidateBytes}, hashed piece by piece: memory stays near the value's own size, not several times its encoding. */
53
54
  export function canonicalCandidateDigest(value) {
54
- return sha256Bytes(canonicalCandidateBytes(value));
55
+ const hash = sha256.create();
56
+ const encoder = new TextEncoder();
57
+ let pending = "";
58
+ writeCanonicalCandidate(value, (part) => {
59
+ pending += part;
60
+ if (pending.length >= 65_536) {
61
+ hash.update(encoder.encode(pending));
62
+ pending = "";
63
+ }
64
+ });
65
+ return digestHex(hash.update(encoder.encode(pending)).digest());
55
66
  }
56
67
  export function omitTopLevelDigest(value) {
57
68
  const { digest: _digest, ...material } = value;
58
69
  return material;
59
70
  }
60
- function serializeCanonicalCandidate(value) {
61
- if (value === null || typeof value === "boolean" || typeof value === "number") {
62
- return JSON.stringify(value);
63
- }
64
- if (typeof value === "string")
65
- return JSON.stringify(value);
66
- if (Array.isArray(value)) {
67
- return `[${value.map(serializeCanonicalCandidate).join(",")}]`;
71
+ function writeCanonicalCandidate(value, write) {
72
+ if (!isCanonicalJsonValue(value)) {
73
+ throw new Error("candidate document must be finite, acyclic RFC 8785 JSON");
68
74
  }
69
- return `{${Object.keys(value)
70
- .sort()
71
- .map((key) => `${JSON.stringify(key)}:${serializeCanonicalCandidate(value[key])}`)
72
- .join(",")}}`;
75
+ const walk = (item) => {
76
+ if (item === null || typeof item !== "object") {
77
+ write(JSON.stringify(item));
78
+ }
79
+ else if (Array.isArray(item)) {
80
+ write("[");
81
+ item.forEach((member, index) => {
82
+ if (index > 0)
83
+ write(",");
84
+ walk(member);
85
+ });
86
+ write("]");
87
+ }
88
+ else {
89
+ write("{");
90
+ Object.keys(item).sort().forEach((key, index) => {
91
+ write(`${index > 0 ? "," : ""}${JSON.stringify(key)}:`);
92
+ walk(item[key]);
93
+ });
94
+ write("}");
95
+ }
96
+ };
97
+ walk(value);
73
98
  }
74
99
  export function isWellFormedUnicode(value) {
75
100
  for (let index = 0; index < value.length; index++) {
@@ -1600,6 +1600,8 @@ export interface AgentEnvironmentCapabilities {
1600
1600
  resize: boolean;
1601
1601
  stop: boolean;
1602
1602
  };
1603
+ /** True when the stream reports a served-model reroute when it happens, as the CLI Bridge does. */
1604
+ modelReroutes?: boolean;
1603
1605
  }
1604
1606
  /** Strict runtime validator for provider capability negotiation. */
1605
1607
  export declare const AgentEnvironmentCapabilitiesSchema: z.ZodObject<{
@@ -1790,6 +1792,7 @@ export declare const AgentEnvironmentCapabilitiesSchema: z.ZodObject<{
1790
1792
  resize: z.ZodBoolean;
1791
1793
  stop: z.ZodBoolean;
1792
1794
  }, z.core.$strict>>;
1795
+ modelReroutes: z.ZodOptional<z.ZodBoolean>;
1793
1796
  }, z.core.$strict>;
1794
1797
  export interface CreateAgentEnvironmentInput extends AgentEnvironmentLifetime {
1795
1798
  profile: AgentProfileRef;
@@ -287,6 +287,7 @@ export const AgentEnvironmentCapabilitiesSchema = z
287
287
  stop: z.boolean(),
288
288
  })
289
289
  .optional(),
290
+ modelReroutes: z.boolean().optional(),
290
291
  })
291
292
  .superRefine((capabilities, refinement) => {
292
293
  if (capabilities.retainedControl !== undefined &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/agent-interface",
3
- "version": "5.10.25",
3
+ "version": "5.10.27",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "license": "MIT",