@sess.si/sdk 0.1.0-rc.4 → 0.1.0-rc.7
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 +56 -1
- package/NOTICE +18 -0
- package/README.md +102 -30
- package/dist/ask.d.ts +150 -0
- package/dist/ask.d.ts.map +1 -0
- package/dist/ask.js +465 -0
- package/dist/ask.js.map +1 -0
- package/dist/cli/main.d.ts +3 -0
- package/dist/cli/main.d.ts.map +1 -0
- package/dist/cli/main.js +8 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/cli/verify.d.ts +14 -0
- package/dist/cli/verify.d.ts.map +1 -0
- package/dist/cli/verify.js +277 -0
- package/dist/cli/verify.js.map +1 -0
- package/dist/client.d.ts +8 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +10 -0
- package/dist/client.js.map +1 -1
- package/dist/generated/openapi.d.ts +6461 -1009
- package/dist/generated/openapi.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/decode.d.ts.map +1 -1
- package/dist/internal/decode.js +4 -1
- package/dist/internal/decode.js.map +1 -1
- package/dist/polling.d.ts +8 -0
- package/dist/polling.d.ts.map +1 -1
- package/dist/polling.js +32 -1
- package/dist/polling.js.map +1 -1
- package/dist/qr/encoder.d.ts +11 -0
- package/dist/qr/encoder.d.ts.map +1 -0
- package/dist/qr/encoder.js +344 -0
- package/dist/qr/encoder.js.map +1 -0
- package/dist/qr/index.d.ts +56 -0
- package/dist/qr/index.d.ts.map +1 -0
- package/dist/qr/index.js +151 -0
- package/dist/qr/index.js.map +1 -0
- package/dist/receipts/bundle.d.ts +124 -0
- package/dist/receipts/bundle.d.ts.map +1 -0
- package/dist/receipts/bundle.js +424 -0
- package/dist/receipts/bundle.js.map +1 -0
- package/dist/receipts/index.d.ts +2 -0
- package/dist/receipts/index.d.ts.map +1 -1
- package/dist/receipts/index.js +1 -0
- package/dist/receipts/index.js.map +1 -1
- package/dist/sessions.d.ts.map +1 -1
- package/dist/sessions.js +7 -0
- package/dist/sessions.js.map +1 -1
- package/dist/transport.d.ts +2 -0
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +11 -2
- package/dist/transport.js.map +1 -1
- package/dist/types.d.ts +11 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/webhooks/index.js +1 -1
- package/dist/webhooks/index.js.map +1 -1
- package/package.json +12 -4
- package/src/ask.ts +636 -0
- package/src/cli/main.ts +8 -0
- package/src/cli/verify.ts +291 -0
- package/src/client.ts +14 -0
- package/src/generated/openapi.ts +6724 -1163
- package/src/index.ts +1 -0
- package/src/internal/decode.ts +3 -1
- package/src/polling.ts +45 -1
- package/src/qr/encoder.ts +345 -0
- package/src/qr/index.ts +203 -0
- package/src/receipts/bundle.ts +547 -0
- package/src/receipts/index.ts +11 -0
- package/src/sessions.ts +11 -0
- package/src/transport.ts +11 -2
- package/src/types.ts +14 -1
- package/src/webhooks/index.ts +1 -1
package/dist/qr/index.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// `@sess.si/sdk/qr`: draw a Sess link as a QR code, locally, so a person at a laptop can answer on
|
|
2
|
+
// their phone without copying anything. Optional: Sess never sends links, and the agent decides
|
|
3
|
+
// whether a QR helps (a desktop chat window, a dashboard, a kiosk, print) or not (SMS, or a person
|
|
4
|
+
// already on their phone).
|
|
5
|
+
//
|
|
6
|
+
// The link is a private capability: the QR is the same capability in another encoding. Nothing here
|
|
7
|
+
// contacts a service, stores the link or its drawing, or puts the link in an error message.
|
|
8
|
+
import { crc32, deflateSync } from 'node:zlib';
|
|
9
|
+
import { encodeQr } from './encoder.js';
|
|
10
|
+
/** The accessible name of the SVG drawing (its one `title`). */
|
|
11
|
+
export const QR_TITLE = 'QR code for this Sess link';
|
|
12
|
+
/** The line `printQr` prints before the code. */
|
|
13
|
+
export const QR_HEADING = 'Scan to answer on your phone';
|
|
14
|
+
/** Light modules around the code, on every side (ISO/IEC 18004 asks for 4). */
|
|
15
|
+
const QUIET = 4;
|
|
16
|
+
/** PNG pixels per module. */
|
|
17
|
+
const PNG_SCALE = 8;
|
|
18
|
+
function matrixOf(url) {
|
|
19
|
+
// Never echo the link: it is a bearer capability.
|
|
20
|
+
if (typeof url !== 'string' || !URL.canParse(url))
|
|
21
|
+
throw new TypeError('qr: url must be an absolute URL');
|
|
22
|
+
const protocol = new URL(url).protocol;
|
|
23
|
+
if (protocol !== 'https:' && protocol !== 'http:')
|
|
24
|
+
throw new TypeError('qr: url must be an http(s) URL');
|
|
25
|
+
try {
|
|
26
|
+
return encodeQr(url);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
throw new RangeError('qr: url is too long for a QR code (at most 213 bytes)');
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The SVG drawing: exactly one root `svg` (SVG namespace, `viewBox="0 0 N N"`, `role="img"`,
|
|
34
|
+
* `shape-rendering="crispEdges"`) holding one `title` ({@link QR_TITLE}), one white `rect` (the
|
|
35
|
+
* quiet zone and background) and one black `path` of unit squares. No style, script, event
|
|
36
|
+
* attribute, link or external resource; fixed colours, so it scans in either theme.
|
|
37
|
+
*/
|
|
38
|
+
function svgOf(m) {
|
|
39
|
+
const size = m.length + QUIET * 2;
|
|
40
|
+
let d = '';
|
|
41
|
+
m.forEach((row, y) => {
|
|
42
|
+
row.forEach((dark, x) => {
|
|
43
|
+
if (dark)
|
|
44
|
+
d += `M${x + QUIET} ${y + QUIET}h1v1h-1z`;
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
return (`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${size} ${size}" role="img" shape-rendering="crispEdges">` +
|
|
48
|
+
`<title>${QR_TITLE}</title>` +
|
|
49
|
+
`<rect width="${size}" height="${size}" fill="#ffffff"/><path d="${d}" fill="#000000"/></svg>`);
|
|
50
|
+
}
|
|
51
|
+
/** Dark at (x, y) of the code with its quiet zone; outside is light. */
|
|
52
|
+
function darkAt(m, x, y) {
|
|
53
|
+
return m[y - QUIET]?.[x - QUIET] === true;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The terminal drawing: two module rows per text line with Unicode half blocks (▀ ▄ █), quiet zone
|
|
57
|
+
* included, lines joined by "\n" with no trailing newline.
|
|
58
|
+
*/
|
|
59
|
+
function terminalOf(m, color) {
|
|
60
|
+
const size = m.length + QUIET * 2;
|
|
61
|
+
const lines = [];
|
|
62
|
+
for (let y = 0; y < size; y += 2) {
|
|
63
|
+
let line = '';
|
|
64
|
+
for (let x = 0; x < size; x++) {
|
|
65
|
+
const top = darkAt(m, x, y);
|
|
66
|
+
const bottom = y + 1 < size && darkAt(m, x, y + 1);
|
|
67
|
+
line += top ? (bottom ? '█' : '▀') : bottom ? '▄' : ' ';
|
|
68
|
+
}
|
|
69
|
+
// Black text on a bright white background, reset at the end of every line.
|
|
70
|
+
lines.push(color ? `\u001b[30;107m${line}\u001b[0m` : line);
|
|
71
|
+
}
|
|
72
|
+
return lines.join('\n');
|
|
73
|
+
}
|
|
74
|
+
function chunk(type, data) {
|
|
75
|
+
const out = new Uint8Array(12 + data.length);
|
|
76
|
+
const view = new DataView(out.buffer);
|
|
77
|
+
view.setUint32(0, data.length);
|
|
78
|
+
out.set(new TextEncoder().encode(type), 4);
|
|
79
|
+
out.set(data, 8);
|
|
80
|
+
view.setUint32(8 + data.length, crc32(out.subarray(4, 8 + data.length)));
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
83
|
+
/** The PNG image: 1-bit greyscale, {@link PNG_SCALE} pixels per module, quiet zone included. */
|
|
84
|
+
function pngOf(m) {
|
|
85
|
+
const side = (m.length + QUIET * 2) * PNG_SCALE;
|
|
86
|
+
const stride = Math.ceil(side / 8);
|
|
87
|
+
const raw = new Uint8Array((stride + 1) * side);
|
|
88
|
+
for (let py = 0; py < side; py++) {
|
|
89
|
+
const row = py * (stride + 1);
|
|
90
|
+
raw[row] = 0; // filter: none
|
|
91
|
+
for (let px = 0; px < side; px++) {
|
|
92
|
+
// 1 is white in 1-bit greyscale.
|
|
93
|
+
if (!darkAt(m, Math.floor(px / PNG_SCALE), Math.floor(py / PNG_SCALE)))
|
|
94
|
+
raw[row + 1 + (px >> 3)] |= 0x80 >> (px & 7);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const header = new Uint8Array(13);
|
|
98
|
+
const h = new DataView(header.buffer);
|
|
99
|
+
h.setUint32(0, side);
|
|
100
|
+
h.setUint32(4, side);
|
|
101
|
+
header.set([1, 0, 0, 0, 0], 8); // bit depth 1, greyscale, deflate, adaptive filter, no interlace
|
|
102
|
+
const parts = [
|
|
103
|
+
new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]),
|
|
104
|
+
chunk('IHDR', header),
|
|
105
|
+
chunk('IDAT', deflateSync(raw, { level: 9 })),
|
|
106
|
+
chunk('IEND', new Uint8Array(0)),
|
|
107
|
+
];
|
|
108
|
+
const png = new Uint8Array(parts.reduce((n, p) => n + p.length, 0));
|
|
109
|
+
let at = 0;
|
|
110
|
+
for (const p of parts) {
|
|
111
|
+
png.set(p, at);
|
|
112
|
+
at += p.length;
|
|
113
|
+
}
|
|
114
|
+
return png;
|
|
115
|
+
}
|
|
116
|
+
export function qr(url, options) {
|
|
117
|
+
const format = options?.format;
|
|
118
|
+
if (format !== 'svg' && format !== 'png' && format !== 'terminal')
|
|
119
|
+
throw new TypeError('qr: format must be "svg", "png" or "terminal"');
|
|
120
|
+
const m = matrixOf(url);
|
|
121
|
+
if (format === 'svg')
|
|
122
|
+
return svgOf(m);
|
|
123
|
+
if (format === 'png')
|
|
124
|
+
return pngOf(m);
|
|
125
|
+
return terminalOf(m, options.color !== false);
|
|
126
|
+
}
|
|
127
|
+
const set = (v) => v !== undefined && v !== '';
|
|
128
|
+
const isCi = (v) => set(v) && v !== 'false' && v !== '0';
|
|
129
|
+
/**
|
|
130
|
+
* For development: prints "Scan to answer on your phone" and `url` as a terminal QR code, and
|
|
131
|
+
* returns true, only on an interactive terminal. It prints nothing and returns false when the
|
|
132
|
+
* stream is not a TTY (a pipe, a file, a log collector), in CI (`CI` set), in production
|
|
133
|
+
* (`NODE_ENV=production`), with `--no-qr` or with `qr: false`. `NO_COLOR` draws it without colour.
|
|
134
|
+
* Print the link itself as well: the code is a shortcut, not the only way in.
|
|
135
|
+
*/
|
|
136
|
+
export function printQr(url, options = {}) {
|
|
137
|
+
// The link is checked whether or not anything is printed.
|
|
138
|
+
const m = matrixOf(url);
|
|
139
|
+
const stream = options.stream ?? process.stdout;
|
|
140
|
+
const env = options.env ?? process.env;
|
|
141
|
+
const argv = options.argv ?? process.argv;
|
|
142
|
+
if (options.qr === false ||
|
|
143
|
+
argv.includes('--no-qr') ||
|
|
144
|
+
stream.isTTY !== true ||
|
|
145
|
+
isCi(env.CI) ||
|
|
146
|
+
env.NODE_ENV === 'production')
|
|
147
|
+
return false;
|
|
148
|
+
stream.write(`${QR_HEADING}\n${terminalOf(m, !set(env.NO_COLOR))}\n`);
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/qr/index.ts"],"names":[],"mappings":"AAAA,mGAAmG;AACnG,gGAAgG;AAChG,mGAAmG;AACnG,2BAA2B;AAC3B,EAAE;AACF,oGAAoG;AACpG,4FAA4F;AAC5F,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAiB,MAAM,cAAc,CAAC;AAEvD,gEAAgE;AAChE,MAAM,CAAC,MAAM,QAAQ,GAAG,4BAA4B,CAAC;AAErD,iDAAiD;AACjD,MAAM,CAAC,MAAM,UAAU,GAAG,8BAA8B,CAAC;AAEzD,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,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC;IACvC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAC1C,IACE,OAAO,CAAC,EAAE,KAAK,KAAK;QACpB,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC;QACxB,MAAM,CAAC,KAAK,KAAK,IAAI;QACrB,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QACZ,GAAG,CAAC,QAAQ,KAAK,YAAY;QAE7B,OAAO,KAAK,CAAC;IACf,MAAM,CAAC,KAAK,CAAC,GAAG,UAAU,KAAK,UAAU,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC;IACtE,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { type ReceiptKeySet } from './verify.js';
|
|
2
|
+
/** Bounds of a bundle (bundle-v1 §4). A bundle beyond any of them is `oversized`. */
|
|
3
|
+
export declare const BUNDLE_LIMITS: Readonly<{
|
|
4
|
+
/** RFC 8785 canonical UTF-8 bytes of the whole bundle. */
|
|
5
|
+
bytes: 1048576;
|
|
6
|
+
/** Nesting depth of any value (the bundle object itself is depth 1). */
|
|
7
|
+
depth: 32;
|
|
8
|
+
/** Items in any one array. */
|
|
9
|
+
arrayItems: 1000;
|
|
10
|
+
/** Members of any one object. */
|
|
11
|
+
objectMembers: 1000;
|
|
12
|
+
/** JSON values in the whole bundle. */
|
|
13
|
+
nodes: 100000;
|
|
14
|
+
/** Characters of the receipt's compact JWS. */
|
|
15
|
+
receiptChars: 32768;
|
|
16
|
+
/** Public keys in `keys.keys`. */
|
|
17
|
+
keys: 16;
|
|
18
|
+
}>;
|
|
19
|
+
/** One public Ed25519 JWK as disclosed in a bundle. */
|
|
20
|
+
export interface BundleJwk {
|
|
21
|
+
kty: 'OKP';
|
|
22
|
+
crv: 'Ed25519';
|
|
23
|
+
x: string;
|
|
24
|
+
kid: string;
|
|
25
|
+
alg?: 'EdDSA';
|
|
26
|
+
use?: 'sig';
|
|
27
|
+
}
|
|
28
|
+
/** A bundle-v1 object: exactly these members. */
|
|
29
|
+
export interface DecisionBundle {
|
|
30
|
+
type: 'sess.decision-bundle';
|
|
31
|
+
version: 1;
|
|
32
|
+
/** The receipt-v1 compact JWS, exactly as issued. */
|
|
33
|
+
receipt: string;
|
|
34
|
+
/** The accepted record: the normalized Surface document and the validated input, complete. */
|
|
35
|
+
content: {
|
|
36
|
+
surface: Record<string, unknown>;
|
|
37
|
+
input: Record<string, unknown>;
|
|
38
|
+
};
|
|
39
|
+
/** The issuer's public keys. Disclosed for convenience; a verifier never trusts them. */
|
|
40
|
+
keys: {
|
|
41
|
+
keys: BundleJwk[];
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/** Receipt-v1 rejection codes (receipt-v1 §6). */
|
|
45
|
+
type ReceiptV1Rejection = 'malformed' | 'algorithm' | 'missing_kid' | 'unknown_kid' | 'type' | 'signature' | 'issuer' | 'audience' | 'expired' | 'claims';
|
|
46
|
+
/** Why a bundle is invalid: the first check that failed (bundle-v1 §5). */
|
|
47
|
+
export type BundleRejection = 'malformed' | 'oversized' | 'unsupported_version' | 'receipt_malformed' | Exclude<ReceiptV1Rejection, 'malformed'> | 'not_yet_valid' | 'surface_mismatch' | 'input_mismatch' | 'context_mismatch';
|
|
48
|
+
/** Application context from the caller's trusted configuration, never from the bundle. */
|
|
49
|
+
export interface ExpectedBundleContext {
|
|
50
|
+
/** The recipient the caller expects (the receipt's `aud`: the Session's workspace). */
|
|
51
|
+
audience?: string;
|
|
52
|
+
workspaceId?: string;
|
|
53
|
+
sessionId?: string;
|
|
54
|
+
eventId?: string;
|
|
55
|
+
/** The Surface revision the decision must be on. */
|
|
56
|
+
revision?: number;
|
|
57
|
+
actionId?: string;
|
|
58
|
+
}
|
|
59
|
+
/** Context member names as the result reports them (receipt claim paths). */
|
|
60
|
+
export type BundleContextField = 'audience' | 'workspace_id' | 'session_id' | 'event_id' | 'surface.revision' | 'action.id';
|
|
61
|
+
export interface VerifyDecisionBundleOptions {
|
|
62
|
+
/** The issuer the caller trusts (the receipt's `iss`). */
|
|
63
|
+
issuer: string;
|
|
64
|
+
/** The issuer's public verification keys the caller trusts. Keys inside a bundle are never used. */
|
|
65
|
+
trustedKeys: ReceiptKeySet;
|
|
66
|
+
expectedContext?: ExpectedBundleContext;
|
|
67
|
+
/** Defaults to the current time (receipt-v1 current-time expiry). */
|
|
68
|
+
now?: Date;
|
|
69
|
+
}
|
|
70
|
+
/** The verified receipt, presented only when the bundle is valid. */
|
|
71
|
+
export interface VerifiedReceiptSummary {
|
|
72
|
+
key_id: string;
|
|
73
|
+
issuer: string;
|
|
74
|
+
audience: string;
|
|
75
|
+
event_id: string;
|
|
76
|
+
session_id: string;
|
|
77
|
+
workspace_id: string;
|
|
78
|
+
step_id: string;
|
|
79
|
+
surface: {
|
|
80
|
+
revision: number;
|
|
81
|
+
hash: string;
|
|
82
|
+
renderer_version: string;
|
|
83
|
+
};
|
|
84
|
+
action: {
|
|
85
|
+
id: string;
|
|
86
|
+
label: string;
|
|
87
|
+
summary: string;
|
|
88
|
+
};
|
|
89
|
+
input_hash: string;
|
|
90
|
+
accepted_at: string;
|
|
91
|
+
expires_at: string;
|
|
92
|
+
}
|
|
93
|
+
/** The result every face reports (bundle-v1 §6). JSON-serializable. */
|
|
94
|
+
export interface DecisionBundleVerification {
|
|
95
|
+
valid: boolean;
|
|
96
|
+
reason: BundleRejection | null;
|
|
97
|
+
/** The verification time, RFC 3339 UTC. */
|
|
98
|
+
checked_at: string;
|
|
99
|
+
/** Whether the disclosed Surface and input match the receipt's hashes. */
|
|
100
|
+
content: 'verified' | 'mismatch' | 'not_checked';
|
|
101
|
+
context: {
|
|
102
|
+
status: 'verified' | 'incomplete' | 'mismatch' | 'unchecked' | 'not_checked';
|
|
103
|
+
/** The context members the caller supplied, in a fixed order. */
|
|
104
|
+
checked: BundleContextField[];
|
|
105
|
+
mismatches: BundleContextField[];
|
|
106
|
+
};
|
|
107
|
+
/** `matched_caller_context` only when the caller's full context (with audience) matched. */
|
|
108
|
+
application_purpose: 'unchecked' | 'matched_caller_context';
|
|
109
|
+
/** Link possession only: never a named or verified person. Null when invalid. */
|
|
110
|
+
actor: {
|
|
111
|
+
assurance: 'link_holder';
|
|
112
|
+
} | null;
|
|
113
|
+
receipt: VerifiedReceiptSummary | null;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Verifies a bundle-v1 decision bundle offline against the issuer and keys the caller trusts.
|
|
117
|
+
* Every outcome about the bundle is a result, never an exception; only invalid options throw a
|
|
118
|
+
* TypeError. Order (bundle-v1 §5): shape and bounds; the receipt by the receipt-v1 rules; not
|
|
119
|
+
* issued in the future; the disclosed Surface and input against the receipt's hashes; then the
|
|
120
|
+
* caller's expected context.
|
|
121
|
+
*/
|
|
122
|
+
export declare function verifyDecisionBundle(bundle: unknown, options: VerifyDecisionBundleOptions): Promise<DecisionBundleVerification>;
|
|
123
|
+
export {};
|
|
124
|
+
//# sourceMappingURL=bundle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../../src/receipts/bundle.ts"],"names":[],"mappings":"AAYA,OAAO,EAAkB,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAOjE,qFAAqF;AACrF,eAAO,MAAM,aAAa;IACxB,0DAA0D;;IAE1D,wEAAwE;;IAExE,8BAA8B;;IAE9B,iCAAiC;;IAEjC,uCAAuC;;IAEvC,+CAA+C;;IAE/C,kCAAkC;;EAElC,CAAC;AAKH,uDAAuD;AACvD,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,KAAK,CAAC;IACX,GAAG,EAAE,SAAS,CAAC;IACf,CAAC,EAAE,MAAM,CAAC;IACV,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,OAAO,CAAC;I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