@ts-pf/message-client 0.1.5 → 0.2.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/LICENSE +21 -0
- package/README.md +48 -2
- package/dist/call.d.ts +59 -0
- package/dist/call.d.ts.map +1 -0
- package/dist/call.js +269 -0
- package/dist/call.js.map +1 -0
- package/dist/duplex.d.ts +30 -0
- package/dist/duplex.d.ts.map +1 -0
- package/dist/duplex.js +108 -0
- package/dist/duplex.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/port.d.ts +3 -2
- package/dist/port.d.ts.map +1 -1
- package/dist/port.js +9 -18
- package/dist/port.js.map +1 -1
- package/dist/shared.d.ts +19 -9
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +33 -323
- package/dist/shared.js.map +1 -1
- package/dist/stdio.d.ts +3 -2
- package/dist/stdio.d.ts.map +1 -1
- package/dist/stdio.js +10 -18
- package/dist/stdio.js.map +1 -1
- package/dist/ws.d.ts +8 -2
- package/dist/ws.d.ts.map +1 -1
- package/dist/ws.js +33 -60
- package/dist/ws.js.map +1 -1
- package/package.json +12 -7
- package/skills/ts-pf-message-client/SKILL.md +32 -3
- package/dist/is-async-iterable.d.ts +0 -2
- package/dist/is-async-iterable.d.ts.map +0 -1
- package/dist/is-async-iterable.js +0 -12
- package/dist/is-async-iterable.js.map +0 -1
- package/dist/push-queue.d.ts +0 -7
- package/dist/push-queue.d.ts.map +0 -1
- package/dist/push-queue.js +0 -74
- package/dist/push-queue.js.map +0 -1
package/dist/ws.js
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import { createWsDuplex,
|
|
2
|
-
import {
|
|
1
|
+
import { createWsDuplex, resolveBackpressure, } from '@ts-pf/message';
|
|
2
|
+
import { localFailure } from '@ts-pf/protocol';
|
|
3
|
+
import { DuplexLink } from './duplex.js';
|
|
4
|
+
import { awaitWithAbort } from './shared.js';
|
|
3
5
|
const WS_OPEN = 1;
|
|
4
6
|
const WS_CLOSING = 2;
|
|
5
7
|
const WS_CLOSED = 3;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
/**
|
|
9
|
+
* `DuplexLink` over `createWsDuplex`, started once the socket is open.
|
|
10
|
+
* Calls made before that wait for the connect; `close()` also closes the
|
|
11
|
+
* socket. `backpressure.highWaterMark` is the `bufferedAmount` the socket may
|
|
12
|
+
* hold before an input stream's producer pauses.
|
|
13
|
+
*/
|
|
11
14
|
export class WsLink {
|
|
12
15
|
socket;
|
|
13
|
-
|
|
16
|
+
highWaterMark;
|
|
17
|
+
link;
|
|
14
18
|
connected;
|
|
15
19
|
closed = false;
|
|
16
20
|
settleConnect;
|
|
@@ -21,6 +25,8 @@ export class WsLink {
|
|
|
21
25
|
if ((socketOpt !== undefined) === (urlOpt !== undefined)) {
|
|
22
26
|
throw new TypeError('WsLink requires exactly one of socket or url');
|
|
23
27
|
}
|
|
28
|
+
// validated here: the DuplexLink is only built once the socket is open
|
|
29
|
+
this.highWaterMark = resolveBackpressure(opts.backpressure).highWaterMark;
|
|
24
30
|
if (urlOpt !== undefined) {
|
|
25
31
|
const Ctor = opts.WebSocket ?? globalThis.WebSocket;
|
|
26
32
|
if (typeof Ctor !== 'function') {
|
|
@@ -37,17 +43,20 @@ export class WsLink {
|
|
|
37
43
|
void this.connected.catch(() => {
|
|
38
44
|
// connect / hello failures reject ready; call() re-awaits the same promise
|
|
39
45
|
});
|
|
40
|
-
const
|
|
46
|
+
const linkOpts = {};
|
|
41
47
|
if (opts.meta !== undefined) {
|
|
42
|
-
|
|
48
|
+
linkOpts.meta = opts.meta;
|
|
43
49
|
}
|
|
44
50
|
if (opts.maxFrameBytes !== undefined) {
|
|
45
|
-
|
|
51
|
+
linkOpts.maxFrameBytes = opts.maxFrameBytes;
|
|
46
52
|
}
|
|
47
53
|
if (opts.helloTimeoutMs !== undefined) {
|
|
48
|
-
|
|
54
|
+
linkOpts.helloTimeoutMs = opts.helloTimeoutMs;
|
|
55
|
+
}
|
|
56
|
+
if (opts.backpressure !== undefined) {
|
|
57
|
+
linkOpts.backpressure = opts.backpressure;
|
|
49
58
|
}
|
|
50
|
-
this.boot(
|
|
59
|
+
this.boot(linkOpts);
|
|
51
60
|
}
|
|
52
61
|
call(path, input, signal) {
|
|
53
62
|
return this.callInner(path, input, signal);
|
|
@@ -59,7 +68,7 @@ export class WsLink {
|
|
|
59
68
|
this.closed = true;
|
|
60
69
|
this.unsubConnect?.();
|
|
61
70
|
this.unsubConnect = undefined;
|
|
62
|
-
this.
|
|
71
|
+
this.link?.close();
|
|
63
72
|
this.failConnect(localFailure('Connection closed'));
|
|
64
73
|
try {
|
|
65
74
|
this.socket.close(1000);
|
|
@@ -106,20 +115,14 @@ export class WsLink {
|
|
|
106
115
|
if (this.closed) {
|
|
107
116
|
return;
|
|
108
117
|
}
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if (opts.helloTimeoutMs !== undefined) {
|
|
118
|
-
attach.helloTimeoutMs = opts.helloTimeoutMs;
|
|
119
|
-
}
|
|
120
|
-
const attached = attachClient(attach);
|
|
121
|
-
this.attached = attached;
|
|
122
|
-
this.settleConnect?.resolve(attached);
|
|
118
|
+
const link = new DuplexLink({
|
|
119
|
+
duplex: createWsDuplex(this.socket, {
|
|
120
|
+
highWaterMark: this.highWaterMark,
|
|
121
|
+
}),
|
|
122
|
+
...opts,
|
|
123
|
+
});
|
|
124
|
+
this.link = link;
|
|
125
|
+
this.settleConnect?.resolve(link);
|
|
123
126
|
this.settleConnect = undefined;
|
|
124
127
|
}
|
|
125
128
|
failConnect(error) {
|
|
@@ -130,38 +133,8 @@ export class WsLink {
|
|
|
130
133
|
this.settleConnect = undefined;
|
|
131
134
|
}
|
|
132
135
|
async callInner(path, input, signal) {
|
|
133
|
-
const
|
|
134
|
-
return
|
|
135
|
-
}
|
|
136
|
-
waitConnected(signal) {
|
|
137
|
-
if (signal === undefined) {
|
|
138
|
-
return this.connected;
|
|
139
|
-
}
|
|
140
|
-
if (signal.aborted) {
|
|
141
|
-
return Promise.reject(abortedFailure(signal));
|
|
142
|
-
}
|
|
143
|
-
return new Promise((resolve, reject) => {
|
|
144
|
-
const onAbort = () => {
|
|
145
|
-
signal.removeEventListener('abort', onAbort);
|
|
146
|
-
reject(abortedFailure(signal));
|
|
147
|
-
};
|
|
148
|
-
signal.addEventListener('abort', onAbort);
|
|
149
|
-
this.connected.then((attached) => {
|
|
150
|
-
signal.removeEventListener('abort', onAbort);
|
|
151
|
-
if (signal.aborted) {
|
|
152
|
-
reject(abortedFailure(signal));
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
resolve(attached);
|
|
156
|
-
}, (error) => {
|
|
157
|
-
signal.removeEventListener('abort', onAbort);
|
|
158
|
-
if (signal.aborted) {
|
|
159
|
-
reject(abortedFailure(signal));
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
reject(error);
|
|
163
|
-
});
|
|
164
|
-
});
|
|
136
|
+
const link = await awaitWithAbort(this.connected, signal);
|
|
137
|
+
return link.call(path, input, signal);
|
|
165
138
|
}
|
|
166
139
|
}
|
|
167
140
|
//# sourceMappingURL=ws.js.map
|
package/dist/ws.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ws.js","sourceRoot":"","sources":["../src/ws.ts"],"names":[],"mappings":"AACA,OAAO,EACL,cAAc,EACd,
|
|
1
|
+
{"version":3,"file":"ws.js","sourceRoot":"","sources":["../src/ws.ts"],"names":[],"mappings":"AACA,OAAO,EACL,cAAc,EACd,mBAAmB,GAEpB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,U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AC,CAAA;QACzD,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,CAAA;IACvC,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ts-pf/message-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Opt-in PortLink, WsLink, and StdioLink",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ts-pf",
|
|
@@ -16,6 +16,9 @@
|
|
|
16
16
|
"client"
|
|
17
17
|
],
|
|
18
18
|
"license": "MIT",
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=22"
|
|
21
|
+
},
|
|
19
22
|
"repository": {
|
|
20
23
|
"type": "git",
|
|
21
24
|
"url": "git+https://github.com/crobinson42/ts-pf.git",
|
|
@@ -51,14 +54,16 @@
|
|
|
51
54
|
"lint": "biome check src tests"
|
|
52
55
|
},
|
|
53
56
|
"dependencies": {
|
|
54
|
-
"@ts-pf/client": "0.
|
|
55
|
-
"@ts-pf/message": "0.
|
|
57
|
+
"@ts-pf/client": "0.2.0",
|
|
58
|
+
"@ts-pf/message": "0.2.0",
|
|
59
|
+
"@ts-pf/protocol": "0.2.0"
|
|
56
60
|
},
|
|
57
61
|
"devDependencies": {
|
|
58
|
-
"@ts-pf/contract": "0.
|
|
59
|
-
"@ts-pf/message-server": "0.
|
|
60
|
-
"@ts-pf/server": "0.
|
|
61
|
-
"@ts-pf/stream": "0.
|
|
62
|
+
"@ts-pf/contract": "0.2.0",
|
|
63
|
+
"@ts-pf/message-server": "0.3.0",
|
|
64
|
+
"@ts-pf/server": "0.4.0",
|
|
65
|
+
"@ts-pf/stream": "0.2.0",
|
|
66
|
+
"@types/node": "^22.15.0",
|
|
62
67
|
"typebox": "^1.3.24",
|
|
63
68
|
"zod": "^4.0.0"
|
|
64
69
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: ts-pf-message-client
|
|
3
|
-
description: Use when calling ts-pf over MessagePort, WebSocket, or
|
|
3
|
+
description: Use when calling ts-pf over MessagePort, WebSocket, stdio, or your own Duplex with PortLink, WsLink, StdioLink, or DuplexLink. Triggers: @ts-pf/message-client, PortLink, WsLink, StdioLink, DuplexLink.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# @ts-pf/message-client
|
|
7
7
|
|
|
8
|
-
`PortLink` / `WsLink` / `StdioLink` for the same `createClient(link)` as `FetchLink`.
|
|
8
|
+
`PortLink` / `WsLink` / `StdioLink` / `DuplexLink` for the same `createClient(link)` as `FetchLink`.
|
|
9
9
|
|
|
10
10
|
Install: `npm i @ts-pf/message-client`
|
|
11
11
|
|
|
@@ -25,17 +25,44 @@ new WsLink({ url: 'wss://example.com/rpc', WebSocket }) // or { socket }
|
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
```ts
|
|
28
|
+
import { spawn } from 'node:child_process'
|
|
28
29
|
import { StdioLink } from '@ts-pf/message-client/stdio'
|
|
29
30
|
|
|
30
31
|
const child = spawn(cmd, { stdio: ['pipe', 'pipe', 'inherit'] })
|
|
31
32
|
new StdioLink({ input: child.stdout, output: child.stdin })
|
|
32
33
|
```
|
|
33
34
|
|
|
35
|
+
Bring your own duplex for any other pipe (Electron IPC, Chrome runtime port, WebTransport, Unix socket). Implement `Duplex` from `@ts-pf/message` — four functions that move JSON text — and hand it to `DuplexLink`, which owns the handshake, ids, multiplexing, and cancel; `PortLink` / `WsLink` / `StdioLink` are this over their built-in adapters. Same `LinkOptions` (`meta`, `maxFrameBytes`, `helloTimeoutMs`, `backpressure`); `close()` closes the duplex. Return a promise from `send` while your pipe is above its write mark (it must settle on close) and implement `pause` / `resume` if it can stop receiving; a duplex that does neither gets no slow-peer protection on that pipe:
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { createClient } from '@ts-pf/client'
|
|
39
|
+
import type { Duplex } from '@ts-pf/message'
|
|
40
|
+
import { DuplexLink } from '@ts-pf/message-client'
|
|
41
|
+
|
|
42
|
+
declare const ipc: {
|
|
43
|
+
send(text: string): void
|
|
44
|
+
on(event: 'message' | 'close', handler: (text: string) => void): () => void
|
|
45
|
+
close(): void
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const duplex: Duplex = {
|
|
49
|
+
send: (text) => ipc.send(text),
|
|
50
|
+
onMessage: (handler) => ipc.on('message', handler),
|
|
51
|
+
onClose: (handler) => ipc.on('close', handler),
|
|
52
|
+
close: () => ipc.close(),
|
|
53
|
+
}
|
|
54
|
+
const link = new DuplexLink({ duplex, meta: { token: 'abc' } })
|
|
55
|
+
const client = createClient<typeof contract>(link)
|
|
56
|
+
link.close()
|
|
57
|
+
```
|
|
58
|
+
|
|
34
59
|
User owns listen / upgrade / spawn / Worker bootstrap. Impls may have `close()`; do not add `close()` to `Link`.
|
|
35
60
|
|
|
61
|
+
Slow servers are handled by default (`LinkOptions.backpressure`, the same `{ highWaterMark?, drainTimeout?, onStall? }` as the server; 1 MiB / 30 s / one `console.warn` on `aborted` only, and a throwing `onStall` is swallowed): an `AsyncIterable` input is pumped one item at a time and parked while the duplex is over its mark; after `drainTimeout` the call fails locally (`isLocalFailure` from `@ts-pf/client` is true; `Peer did not drain within 30000 ms`), `cancel` goes out, and the input iterator's `return()` runs once. Output streams you read are bounded by the same mark (frame text length) — the link pauses reads (connection-wide) while your `for await` lags, where the pipe can pause. A server that gives up on a slow reader ends the stream with `INTERNAL` / `Peer did not drain within …` after the buffered items; that one is not local. `drainTimeout: 0` waits forever; `highWaterMark: Infinity` disables the receive-queue bound and the WebSocket `bufferedAmount` mark (stdio's write mark is the `Writable`'s own); `onStall: false` silences; a bad value throws from the constructor.
|
|
62
|
+
|
|
36
63
|
## API
|
|
37
64
|
|
|
38
|
-
- `PortLink`, `WsLink`, `LinkOptions`, `WebSocketLike`
|
|
65
|
+
- `DuplexLink`, `PortLink`, `WsLink`, `LinkOptions`, `BackpressureOptions`, `StallInfo`, `WebSocketLike`
|
|
39
66
|
- `StdioLink` from `./stdio` only
|
|
40
67
|
|
|
41
68
|
## Pair with
|
|
@@ -48,3 +75,5 @@ User owns listen / upgrade / spawn / Worker bootstrap. Impls may have `close()`;
|
|
|
48
75
|
|
|
49
76
|
- Depend on the `ws` npm package — inject a `WebSocket` constructor.
|
|
50
77
|
- Reconstruct HTTP status from `error.code`.
|
|
78
|
+
- Copy the multiplexer for a new pipe — write a `Duplex` and use `DuplexLink`.
|
|
79
|
+
- Retry a `Peer did not drain` failure blindly — the server stopped reading; fix the consumer or raise `drainTimeout`.
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"is-async-iterable.d.ts","sourceRoot":"","sources":["../src/is-async-iterable.ts"],"names":[],"mappings":"AAAA,wBAAgB,eAAe,CAC7B,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,aAAa,CAAC,OAAO,CAAC,CAcjC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export function isAsyncIterable(value) {
|
|
2
|
-
if (typeof ReadableStream !== 'undefined' &&
|
|
3
|
-
value instanceof ReadableStream) {
|
|
4
|
-
return false;
|
|
5
|
-
}
|
|
6
|
-
return (typeof value === 'object' &&
|
|
7
|
-
value !== null &&
|
|
8
|
-
Symbol.asyncIterator in value &&
|
|
9
|
-
typeof value[Symbol.asyncIterator] ===
|
|
10
|
-
'function');
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=is-async-iterable.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"is-async-iterable.js","sourceRoot":"","sources":["../src/is-async-iterable.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,eAAe,CAC7B,KAAc;IAEd,IACE,OAAO,cAAc,KAAK,WAAW;QACrC,KAAK,YAAY,cAAc,EAC/B,CAAC;QACD,OAAO,KAAK,CAAA;IACd,CAAC;IACD,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,MAAM,CAAC,aAAa,IAAI,KAAK;QAC7B,OAAQ,KAAgC,CAAC,MAAM,CAAC,aAAa,CAAC;YAC5D,UAAU,CACb,CAAA;AACH,CAAC"}
|
package/dist/push-queue.d.ts
DELETED
package/dist/push-queue.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"push-queue.d.ts","sourceRoot":"","sources":["../src/push-queue.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,aAAa,CAAC,CAAC,CAAC,GAAG;IAC5C,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,CAAA;IACpB,GAAG,IAAI,IAAI,CAAA;IACX,IAAI,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAAA;CAC3B,CAAA;AAED,wBAAgB,eAAe,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,CA+EjD"}
|
package/dist/push-queue.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
export function createPushQueue() {
|
|
2
|
-
const values = [];
|
|
3
|
-
let pending;
|
|
4
|
-
let closed;
|
|
5
|
-
function settleWaiter() {
|
|
6
|
-
if (pending === undefined) {
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
if (values.length > 0) {
|
|
10
|
-
const value = values.shift();
|
|
11
|
-
const resolve = pending.resolve;
|
|
12
|
-
pending = undefined;
|
|
13
|
-
resolve({ done: false, value });
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
if (closed === undefined) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
if (closed.ok) {
|
|
20
|
-
const resolve = pending.resolve;
|
|
21
|
-
pending = undefined;
|
|
22
|
-
resolve({ done: true, value: undefined });
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
const reject = pending.reject;
|
|
26
|
-
pending = undefined;
|
|
27
|
-
reject(closed.error);
|
|
28
|
-
}
|
|
29
|
-
return {
|
|
30
|
-
push(value) {
|
|
31
|
-
if (closed !== undefined) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
values.push(value);
|
|
35
|
-
settleWaiter();
|
|
36
|
-
},
|
|
37
|
-
end() {
|
|
38
|
-
if (closed !== undefined) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
closed = { ok: true };
|
|
42
|
-
settleWaiter();
|
|
43
|
-
},
|
|
44
|
-
fail(error) {
|
|
45
|
-
if (closed !== undefined) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
closed = { ok: false, error };
|
|
49
|
-
settleWaiter();
|
|
50
|
-
},
|
|
51
|
-
[Symbol.asyncIterator]() {
|
|
52
|
-
return {
|
|
53
|
-
next() {
|
|
54
|
-
if (values.length > 0) {
|
|
55
|
-
return Promise.resolve({
|
|
56
|
-
done: false,
|
|
57
|
-
value: values.shift(),
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
if (closed !== undefined) {
|
|
61
|
-
if (closed.ok) {
|
|
62
|
-
return Promise.resolve({ done: true, value: undefined });
|
|
63
|
-
}
|
|
64
|
-
return Promise.reject(closed.error);
|
|
65
|
-
}
|
|
66
|
-
return new Promise((resolve, reject) => {
|
|
67
|
-
pending = { resolve, reject };
|
|
68
|
-
});
|
|
69
|
-
},
|
|
70
|
-
};
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
//# sourceMappingURL=push-queue.js.map
|
package/dist/push-queue.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"push-queue.js","sourceRoot":"","sources":["../src/push-queue.ts"],"names":[],"mappings":"AAMA,MAAM,UAAU,eAAe;IAC7B,MAAM,MAAM,GAAQ,EAAE,CAAA;IACtB,IAAI,OAKS,CAAA;IACb,IAAI,MAAgE,CAAA;IAEpE,SAAS,YAAY;QACnB,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,OAAM;Q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