@akai-workflow-builder/cli-sdk 0.0.1 → 0.1.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/README.md +8 -4
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +1 -1
- package/dist/ctx/build-ctx.d.ts +8 -0
- package/dist/ctx/build-ctx.d.ts.map +1 -1
- package/dist/ctx/build-ctx.js +9 -0
- package/dist/ctx/write-file.d.ts +25 -0
- package/dist/ctx/write-file.d.ts.map +1 -0
- package/dist/ctx/write-file.js +40 -0
- package/dist/manifest/to-schema.js +1 -0
- package/dist/manifest/types.d.ts +2 -0
- package/dist/manifest/types.d.ts.map +1 -1
- package/dist/tool.d.ts.map +1 -1
- package/dist/tool.js +4 -0
- package/dist/types.d.ts +17 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ A small, opinionated SDK for defining CLIs that an agent runtime invokes. Each t
|
|
|
11
11
|
## Installation
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
|
-
npm install @akai/cli zod
|
|
14
|
+
npm install @akai-workflow-builder/cli-sdk zod
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
## Requirements
|
|
@@ -28,7 +28,7 @@ npm install @akai/cli zod
|
|
|
28
28
|
## Quickstart
|
|
29
29
|
|
|
30
30
|
```ts
|
|
31
|
-
import { tool, defineCLI } from '@akai/cli';
|
|
31
|
+
import { tool, defineCLI } from '@akai-workflow-builder/cli-sdk';
|
|
32
32
|
import { z } from 'zod';
|
|
33
33
|
|
|
34
34
|
// Define the response shape once; reuse for `jsonOutput` and runtime parsing.
|
|
@@ -152,7 +152,7 @@ Underscores and camelCase are still accepted so existing tools keep working, but
|
|
|
152
152
|
|
|
153
153
|
### The `ctx` contract
|
|
154
154
|
|
|
155
|
-
Tool handlers receive a frozen `ctx` with
|
|
155
|
+
Tool handlers receive a frozen `ctx` with these members:
|
|
156
156
|
|
|
157
157
|
```ts
|
|
158
158
|
interface ToolCtx<S extends string, P extends string> {
|
|
@@ -162,6 +162,8 @@ interface ToolCtx<S extends string, P extends string> {
|
|
|
162
162
|
logger: ToolLogger;
|
|
163
163
|
signal: AbortSignal;
|
|
164
164
|
workdir: string;
|
|
165
|
+
safePath: (userPath: string) => string;
|
|
166
|
+
readFile: (value: string) => Promise<Buffer>;
|
|
165
167
|
}
|
|
166
168
|
```
|
|
167
169
|
|
|
@@ -173,6 +175,8 @@ interface ToolCtx<S extends string, P extends string> {
|
|
|
173
175
|
- `logger` — structured logger; writes to stderr. stdout is reserved for the tool's result.
|
|
174
176
|
- `signal` — request `AbortSignal`. Forward it to `ctx.fetch` for cancellation and timeouts.
|
|
175
177
|
- `workdir` — writable scratch directory scoped to this invocation.
|
|
178
|
+
- `safePath` — resolve an agent-supplied path under the tool's allowed roots (default: `workdir` + `os.tmpdir()`); strips `file://`, follows symlinks on every existing parent segment, and throws `AkaiPathError` on escape.
|
|
179
|
+
- `readFile` — read a local path (resolved via `safePath`) or an `http(s)://` URL; pairs with `filePath()` from the SDK so handlers transparently support cross-pod file delivery.
|
|
176
180
|
|
|
177
181
|
**What `ctx` deliberately omits**
|
|
178
182
|
|
|
@@ -367,4 +371,4 @@ Every error extends `AkaiError`; the runtime maps each to a structured error env
|
|
|
367
371
|
|
|
368
372
|
## License
|
|
369
373
|
|
|
370
|
-
|
|
374
|
+
MIT — see [`LICENSE`](./LICENSE).
|
package/dist/cli.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export declare function loadCli(packagePath: string): Promise<CLIDef>;
|
|
|
27
27
|
* Uses `cli.toSchema()` (the instance method attached at `defineCLI`
|
|
28
28
|
* time) rather than this SDK's imported `toSchema(cli)`, so the target
|
|
29
29
|
* package's bundled SDK version wins. Per-tenant CLIs may ship with a
|
|
30
|
-
* different
|
|
30
|
+
* different SDK version than the one running the binary — calling the
|
|
31
31
|
* instance method emits the manifest shape that package was authored
|
|
32
32
|
* against.
|
|
33
33
|
*/
|
package/dist/cli.js
CHANGED
|
@@ -107,7 +107,7 @@ export async function loadCli(packagePath) {
|
|
|
107
107
|
* Uses `cli.toSchema()` (the instance method attached at `defineCLI`
|
|
108
108
|
* time) rather than this SDK's imported `toSchema(cli)`, so the target
|
|
109
109
|
* package's bundled SDK version wins. Per-tenant CLIs may ship with a
|
|
110
|
-
* different
|
|
110
|
+
* different SDK version than the one running the binary — calling the
|
|
111
111
|
* instance method emits the manifest shape that package was authored
|
|
112
112
|
* against.
|
|
113
113
|
*/
|
package/dist/ctx/build-ctx.d.ts
CHANGED
|
@@ -22,6 +22,14 @@ export interface BuildCtxParams {
|
|
|
22
22
|
* `DT_SAFE_PATH_ROOTS` here for parity with the rest of its CLI tree.
|
|
23
23
|
*/
|
|
24
24
|
readonly extraSafePathRoots?: readonly string[];
|
|
25
|
+
/**
|
|
26
|
+
* Per-invocation output staging directory for `ctx.writeFile`. The host
|
|
27
|
+
* runtime creates it, passes it here for tools declaring
|
|
28
|
+
* `options.producesFiles`, and after the handler returns collects whatever
|
|
29
|
+
* was written to deliver back to the caller. When omitted, `ctx.writeFile`
|
|
30
|
+
* throws (no output channel provisioned).
|
|
31
|
+
*/
|
|
32
|
+
readonly outputDir?: string;
|
|
25
33
|
}
|
|
26
34
|
/**
|
|
27
35
|
* Assemble a frozen {@link ToolCtx} for one tool invocation: resolves
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-ctx.d.ts","sourceRoot":"","sources":["../../src/ctx/build-ctx.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,KAAK,cAAc,EACnB,KAAK,YAAY,EAClB,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"build-ctx.d.ts","sourceRoot":"","sources":["../../src/ctx/build-ctx.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,KAAK,cAAc,EACnB,KAAK,YAAY,EAClB,MAAM,cAAc,CAAC;AAGtB,OAAO,KAAK,EAAc,MAAM,EAAiB,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAG1F;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,6GAA6G;IAC7G,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;IACpC,sGAAsG;IACtG,QAAQ,CAAC,cAAc,CAAC,EAAE,cAAc,CAAC;IACzC,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B;;;;OAIG;IACH,QAAQ,CAAC,kBAAkB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAChD;;;;;;OAMG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AA4CD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAsDxD"}
|
package/dist/ctx/build-ctx.js
CHANGED
|
@@ -3,6 +3,7 @@ import { createSafeFetch } from './safe-fetch.js';
|
|
|
3
3
|
import { createSafePath } from './safe-path.js';
|
|
4
4
|
import { buildScopedProperties, buildScopedSecrets, } from './secrets.js';
|
|
5
5
|
import { createReadFile } from './read-file.js';
|
|
6
|
+
import { createWriteFile, unavailableWriteFile } from './write-file.js';
|
|
6
7
|
import { AkaiSpecError } from '../errors.js';
|
|
7
8
|
function resolveTool(cli, toolName) {
|
|
8
9
|
const t = cli.tools[toolName];
|
|
@@ -70,6 +71,13 @@ export function buildCtx(params) {
|
|
|
70
71
|
...(params.extraSafePathRoots ?? []),
|
|
71
72
|
]);
|
|
72
73
|
const readFile = createReadFile({ safePath, signal: params.signal });
|
|
74
|
+
// `ctx.writeFile` is wired only when the host provisioned an output channel
|
|
75
|
+
// (outputDir). Tools declaring `options.producesFiles` get a real writer;
|
|
76
|
+
// everything else gets a throwing stub so an undeclared write surfaces
|
|
77
|
+
// clearly instead of leaking files onto a stray path.
|
|
78
|
+
const writeFile = params.outputDir !== undefined
|
|
79
|
+
? createWriteFile({ outputDir: params.outputDir })
|
|
80
|
+
: unavailableWriteFile();
|
|
73
81
|
return Object.freeze({
|
|
74
82
|
fetch,
|
|
75
83
|
secrets,
|
|
@@ -79,5 +87,6 @@ export function buildCtx(params) {
|
|
|
79
87
|
workdir: params.workdir,
|
|
80
88
|
safePath,
|
|
81
89
|
readFile,
|
|
90
|
+
writeFile,
|
|
82
91
|
});
|
|
83
92
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface CreateWriteFileOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Per-invocation output staging directory. Files the handler writes here are
|
|
4
|
+
* collected by the host runtime after the handler returns and delivered to
|
|
5
|
+
* the caller's workdir (e.g. uploaded to a presigned URL → extracted by the
|
|
6
|
+
* worker). The host creates and owns this directory.
|
|
7
|
+
*/
|
|
8
|
+
readonly outputDir: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Build a `ctx.writeFile(name, data)` that stages an output file under the
|
|
12
|
+
* invocation's output directory. `name` is a relative path that must stay
|
|
13
|
+
* inside `outputDir`: absolute paths and `..` traversal are rejected with
|
|
14
|
+
* `AkaiPathError`. Parent directories are created as needed. Pairs with
|
|
15
|
+
* `options.producesFiles: true`, which tells the host to provision this
|
|
16
|
+
* channel before invoking the tool.
|
|
17
|
+
*/
|
|
18
|
+
export declare function createWriteFile(opts: CreateWriteFileOptions): (name: string, data: Buffer | Uint8Array | string) => Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Stub installed on `ctx.writeFile` when the host runtime provided no output
|
|
21
|
+
* channel (the tool did not declare `options.producesFiles`). Calling it is a
|
|
22
|
+
* tool-author error — surface it clearly rather than writing to a stray path.
|
|
23
|
+
*/
|
|
24
|
+
export declare function unavailableWriteFile(): (name: string, data: unknown) => Promise<void>;
|
|
25
|
+
//# sourceMappingURL=write-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write-file.d.ts","sourceRoot":"","sources":["../../src/ctx/write-file.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,sBAAsB;IACrC;;;;;OAKG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,sBAAsB,GAC3B,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAkBrE;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAQrF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { mkdir, writeFile as fsWriteFile } from 'node:fs/promises';
|
|
2
|
+
import { dirname, isAbsolute, relative, resolve } from 'node:path';
|
|
3
|
+
import { AkaiPathError } from '../errors.js';
|
|
4
|
+
/**
|
|
5
|
+
* Build a `ctx.writeFile(name, data)` that stages an output file under the
|
|
6
|
+
* invocation's output directory. `name` is a relative path that must stay
|
|
7
|
+
* inside `outputDir`: absolute paths and `..` traversal are rejected with
|
|
8
|
+
* `AkaiPathError`. Parent directories are created as needed. Pairs with
|
|
9
|
+
* `options.producesFiles: true`, which tells the host to provision this
|
|
10
|
+
* channel before invoking the tool.
|
|
11
|
+
*/
|
|
12
|
+
export function createWriteFile(opts) {
|
|
13
|
+
const root = resolve(opts.outputDir);
|
|
14
|
+
return async function writeFile(name, data) {
|
|
15
|
+
if (typeof name !== 'string' || name.length === 0) {
|
|
16
|
+
throw new Error('ctx.writeFile: name must be a non-empty string');
|
|
17
|
+
}
|
|
18
|
+
if (isAbsolute(name)) {
|
|
19
|
+
throw new AkaiPathError(`ctx.writeFile: name must be relative, got absolute path "${name}"`);
|
|
20
|
+
}
|
|
21
|
+
const target = resolve(root, name);
|
|
22
|
+
const rel = relative(root, target);
|
|
23
|
+
if (rel === '' || rel === '..' || rel.startsWith(`..`) || isAbsolute(rel)) {
|
|
24
|
+
throw new AkaiPathError(`ctx.writeFile: name escapes the output directory: "${name}"`);
|
|
25
|
+
}
|
|
26
|
+
await mkdir(dirname(target), { recursive: true });
|
|
27
|
+
const bytes = typeof data === 'string' ? Buffer.from(data, 'utf8') : data;
|
|
28
|
+
await fsWriteFile(target, bytes);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Stub installed on `ctx.writeFile` when the host runtime provided no output
|
|
33
|
+
* channel (the tool did not declare `options.producesFiles`). Calling it is a
|
|
34
|
+
* tool-author error — surface it clearly rather than writing to a stray path.
|
|
35
|
+
*/
|
|
36
|
+
export function unavailableWriteFile() {
|
|
37
|
+
return function writeFile() {
|
|
38
|
+
return Promise.reject(new AkaiPathError('ctx.writeFile is unavailable: declare options.producesFiles: true so the host runtime provisions an output channel'));
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -49,6 +49,7 @@ function toToolManifest(id, t) {
|
|
|
49
49
|
name: t.name ?? null,
|
|
50
50
|
description: t.description ?? null,
|
|
51
51
|
isReadonly: t.options.isReadonly,
|
|
52
|
+
producesFiles: t.options.producesFiles === true,
|
|
52
53
|
secretKeys: [...t.options.secretKeys],
|
|
53
54
|
propertyKeys: [...t.options.propertyKeys],
|
|
54
55
|
inputSchema: tryJsonSchema(t.input),
|
package/dist/manifest/types.d.ts
CHANGED
|
@@ -43,6 +43,8 @@ interface BaseToolManifest {
|
|
|
43
43
|
/** Human description, or `null` when omitted. */
|
|
44
44
|
readonly description: string | null;
|
|
45
45
|
readonly isReadonly: boolean;
|
|
46
|
+
/** True when the tool emits output files via `ctx.writeFile` (host provisions an output channel). Absent = false. */
|
|
47
|
+
readonly producesFiles?: boolean;
|
|
46
48
|
readonly secretKeys: readonly string[];
|
|
47
49
|
readonly propertyKeys: readonly string[];
|
|
48
50
|
/** JSON Schema for the tool's input, or `null` if conversion failed. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/manifest/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEpD,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC5B;AAED;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC5B;AAED;;;;;GAKG;AACH,UAAU,gBAAgB;IACxB,+DAA+D;IAC/D,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,kDAAkD;IAClD,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,iDAAiD;IACjD,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;IACvC,QAAQ,CAAC,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;IACzC,wEAAwE;IACxE,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AS,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAkD3E"}
|
package/dist/tool.js
CHANGED
|
@@ -63,6 +63,9 @@ const ToolOptionsShape = z.object({
|
|
|
63
63
|
? 'isReadonly is required — no default. Mark true for reads, false for writes; the flag drives the runtime approval gate.'
|
|
64
64
|
: `isReadonly must be a boolean (got ${typeof issue.input})`,
|
|
65
65
|
}),
|
|
66
|
+
producesFiles: z
|
|
67
|
+
.boolean({ error: 'options.producesFiles must be a boolean if provided' })
|
|
68
|
+
.optional(),
|
|
66
69
|
});
|
|
67
70
|
const TransportShape = z
|
|
68
71
|
.enum(['http', 'native'], { error: 'transport must be "http" or "native" if provided' })
|
|
@@ -198,6 +201,7 @@ export function tool(spec) {
|
|
|
198
201
|
secretKeys: [...(v.options.secretKeys ?? [])],
|
|
199
202
|
propertyKeys: [...(v.options.propertyKeys ?? [])],
|
|
200
203
|
isReadonly: v.options.isReadonly,
|
|
204
|
+
producesFiles: v.options.producesFiles === true,
|
|
201
205
|
},
|
|
202
206
|
handler: v.handler,
|
|
203
207
|
};
|
package/dist/types.d.ts
CHANGED
|
@@ -58,6 +58,13 @@ export interface ToolOptions<TSecrets extends string = string, TProperties exten
|
|
|
58
58
|
/** Keys (matching `CLIDef.properties[].key`) that this tool needs at runtime. */
|
|
59
59
|
readonly propertyKeys: readonly TProperties[];
|
|
60
60
|
readonly isReadonly: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* When true, the handler emits one or more output files via `ctx.writeFile`.
|
|
63
|
+
* Host runtimes read this to provision an output channel (e.g. pre-mint an
|
|
64
|
+
* upload URL) before invoking the tool, then deliver the written files back
|
|
65
|
+
* to the caller's workdir. Defaults to false.
|
|
66
|
+
*/
|
|
67
|
+
readonly producesFiles?: boolean;
|
|
61
68
|
}
|
|
62
69
|
/** Structured logger handed to tool handlers. Writes to stderr; stdout is reserved for handler output. */
|
|
63
70
|
export interface ToolLogger {
|
|
@@ -104,6 +111,15 @@ export interface ToolCtx<S extends string = string, P extends string = string> {
|
|
|
104
111
|
* to gain transparent support for cross-pod file delivery.
|
|
105
112
|
*/
|
|
106
113
|
readFile: (value: string) => Promise<Buffer>;
|
|
114
|
+
/**
|
|
115
|
+
* Write an output file the host runtime delivers back to the caller's
|
|
116
|
+
* workdir. `name` is a relative path under the invocation's output staging
|
|
117
|
+
* area (no absolute path, no `..` segments). Use for tools that produce
|
|
118
|
+
* files — downloads, exports; declare `options.producesFiles: true` so the
|
|
119
|
+
* host provisions the output channel. Throws if the host did not provide an
|
|
120
|
+
* output channel (i.e. the tool did not declare `producesFiles`).
|
|
121
|
+
*/
|
|
122
|
+
writeFile: (name: string, data: Buffer | Uint8Array | string) => Promise<void>;
|
|
107
123
|
}
|
|
108
124
|
/** A built tool. Opaque to consumers, introspectable by the SDK. */
|
|
109
125
|
export interface ToolDef<TInput = unknown, TOutput = unknown, TSecrets extends string = string, TProperties extends string = string> {
|
|
@@ -190,6 +206,7 @@ export interface ToolSpec<I extends ZodType, J extends ZodType | undefined = und
|
|
|
190
206
|
secretKeys?: readonly S[];
|
|
191
207
|
propertyKeys?: readonly P[];
|
|
192
208
|
isReadonly: boolean;
|
|
209
|
+
producesFiles?: boolean;
|
|
193
210
|
};
|
|
194
211
|
handler: (args: {
|
|
195
212
|
input: ZInfer<I>;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,KAAK,IAAI,MAAM,EAAE,MAAM,KAAK,CAAC;AACpD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAE9D,uEAAuE;AACvE,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAA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