@nodetool-ai/runtime-core 0.0.0-stage → 0.8.9-beta.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 +8 -2
- package/dist/.nodetool-build-stamp +1 -0
- package/dist/context.d.ts +20 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +32 -0
- package/dist/context.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/prefixed-storage-adapter.d.ts +33 -0
- package/dist/prefixed-storage-adapter.d.ts.map +1 -0
- package/dist/prefixed-storage-adapter.js +70 -0
- package/dist/prefixed-storage-adapter.js.map +1 -0
- package/dist/safe-url.d.ts +70 -0
- package/dist/safe-url.d.ts.map +1 -0
- package/dist/safe-url.js +286 -0
- package/dist/safe-url.js.map +1 -0
- package/dist/storage-workspace.d.ts +62 -0
- package/dist/storage-workspace.d.ts.map +1 -0
- package/dist/storage-workspace.js +423 -0
- package/dist/storage-workspace.js.map +1 -0
- package/dist/text-provider.d.ts +40 -0
- package/dist/text-provider.d.ts.map +1 -0
- package/dist/text-provider.js +52 -0
- package/dist/text-provider.js.map +1 -0
- package/dist/tracing.d.ts +3 -0
- package/dist/tracing.d.ts.map +1 -0
- package/dist/tracing.js +19 -0
- package/dist/tracing.js.map +1 -0
- package/dist/workspace.d.ts +119 -0
- package/dist/workspace.d.ts.map +1 -0
- package/dist/workspace.js +112 -0
- package/dist/workspace.js.map +1 -0
- package/package.json +65 -4
package/README.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Runtime core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Execution contracts, cancellable runs, the shared workspace implementation,
|
|
4
|
+
URL egress policy and an OpenAI-compatible text streaming adapter. This package
|
|
5
|
+
does not load media codecs, browser automation or local inference.
|
|
6
|
+
|
|
7
|
+
Install `@nodetool-ai/runtime-core` to use `OpenAITextProvider`,
|
|
8
|
+
`createLocalWorkspace` and `RunCancellation`. Hosts supply the authenticated
|
|
9
|
+
owner, secret resolver and usage accounting through `ExecutionContext`.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2026-10-31T09:10:53.990Z
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Workspace } from "./workspace.js";
|
|
2
|
+
import type { TextProvider, TextUsage } from "./text-provider.js";
|
|
3
|
+
/** Services available to execution without media, agents or local inference. */
|
|
4
|
+
export interface ExecutionContext {
|
|
5
|
+
readonly userId: string;
|
|
6
|
+
readonly signal: AbortSignal;
|
|
7
|
+
readonly workspace: Workspace;
|
|
8
|
+
readonly textProvider: TextProvider;
|
|
9
|
+
readonly resolveSecret: (name: string) => Promise<string | undefined>;
|
|
10
|
+
readonly trackUsage: (usage: TextUsage) => void;
|
|
11
|
+
}
|
|
12
|
+
/** Owns cancellable runs without retaining finished controllers. */
|
|
13
|
+
export declare class RunCancellation {
|
|
14
|
+
private readonly runs;
|
|
15
|
+
start(id: string, owner: string): AbortSignal;
|
|
16
|
+
cancel(id: string, owner: string): boolean;
|
|
17
|
+
finish(id: string, owner: string): void;
|
|
18
|
+
close(): void;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAElE,gFAAgF;AAChF,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;IACpC,QAAQ,CAAC,aAAa,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IACtE,QAAQ,CAAC,UAAU,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;CACjD;AAED,oEAAoE;AACpE,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAqE;IAE1F,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,WAAW,CAO5C;IAED,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAOzC;IAED,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAItC;IAED,KAAK,IAAI,IAAI,CAKZ;CACF"}
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** Owns cancellable runs without retaining finished controllers. */
|
|
2
|
+
export class RunCancellation {
|
|
3
|
+
runs = new Map();
|
|
4
|
+
start(id, owner) {
|
|
5
|
+
if (this.runs.has(id)) {
|
|
6
|
+
throw new Error(`Run ${id} already exists`);
|
|
7
|
+
}
|
|
8
|
+
const controller = new AbortController();
|
|
9
|
+
this.runs.set(id, { owner, controller });
|
|
10
|
+
return controller.signal;
|
|
11
|
+
}
|
|
12
|
+
cancel(id, owner) {
|
|
13
|
+
const run = this.runs.get(id);
|
|
14
|
+
if (!run || run.owner !== owner) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
run.controller.abort();
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
finish(id, owner) {
|
|
21
|
+
if (this.runs.get(id)?.owner === owner) {
|
|
22
|
+
this.runs.delete(id);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
close() {
|
|
26
|
+
for (const run of this.runs.values()) {
|
|
27
|
+
run.controller.abort();
|
|
28
|
+
}
|
|
29
|
+
this.runs.clear();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAaA,oEAAoE;AACpE,MAAM,OAAO,eAAe;IACT,IAAI,GAAG,IAAI,GAAG,EAA0D,CAAC;IAE1F,KAAK,CAAC,EAAU,EAAE,KAAa;QAC7B,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;QAC9C,CAAC;QACD,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;QACzC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC;QACzC,OAAO,UAAU,CAAC,MAAM,CAAC;IAC3B,CAAC;IAED,MAAM,CAAC,EAAU,EAAE,KAAa;QAC9B,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAC9B,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,KAAK,KAAK,EAAE,CAAC;YAChC,OAAO,KAAK,CAAC;QACf,CAAC;QACD,GAAG,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;QACvB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,CAAC,EAAU,EAAE,KAAa;QAC9B,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,KAAK,KAAK,KAAK,EAAE,CAAC;YACvC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;IAED,KAAK;QACH,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;YACrC,GAAG,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;QACzB,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,wBAAwB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type StorageAdapter, type StorageListResult, type StorageStat } from "@nodetool-ai/storage";
|
|
2
|
+
/**
|
|
3
|
+
* A `StorageAdapter` that carves a key prefix out of another one.
|
|
4
|
+
*
|
|
5
|
+
* Cloud deployments keep one bucket. Giving each user a workspace inside it
|
|
6
|
+
* means their keys have to be namespaced, and the namespacing has to be
|
|
7
|
+
* invisible to whatever holds the adapter — a caller that stores `notes.md`
|
|
8
|
+
* must read it back as `notes.md`, not as `workspaces/u1/notes.md`. Every key
|
|
9
|
+
* going in gains the prefix and every key coming out loses it again.
|
|
10
|
+
*
|
|
11
|
+
* The prefix is applied to *keys*, never to URIs: a URI is opaque and already
|
|
12
|
+
* carries the full key, so it passes through untouched.
|
|
13
|
+
*/
|
|
14
|
+
export declare class PrefixedStorageAdapter implements StorageAdapter {
|
|
15
|
+
private readonly inner;
|
|
16
|
+
/** Normalized prefix with no trailing slash. */
|
|
17
|
+
readonly prefix: string;
|
|
18
|
+
constructor(inner: StorageAdapter, prefix: string);
|
|
19
|
+
private scope;
|
|
20
|
+
/** Strip the prefix from a key the inner adapter reported. */
|
|
21
|
+
private unscope;
|
|
22
|
+
store(key: string, data: Uint8Array, contentType?: string): Promise<string>;
|
|
23
|
+
retrieve(uri: string): Promise<Uint8Array | null>;
|
|
24
|
+
exists(uri: string): Promise<boolean>;
|
|
25
|
+
uriForKey(key: string): string;
|
|
26
|
+
list(prefix: string, opts?: {
|
|
27
|
+
delimiter?: string;
|
|
28
|
+
}): Promise<StorageListResult>;
|
|
29
|
+
delete(uri: string): Promise<boolean>;
|
|
30
|
+
stat(uri: string): Promise<StorageStat | null>;
|
|
31
|
+
localPath(uri: string): Promise<string | null>;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=prefixed-storage-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefixed-storage-adapter.d.ts","sourceRoot":"","sources":["../src/prefixed-storage-adapter.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,WAAW,EACjB,MAAM,sBAAsB,CAAC;AAE9B;;;;;;;;;;;GAWG;AACH,qBAAa,sBAAuB,YAAW,cAAc;IAKzD,OAAO,CAAC,QAAQ,CAAC,KAAK;IAJxB,gDAAgD;IAChD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,YACmB,KAAK,EAAE,cAAc,EACtC,MAAM,EAAE,MAAM,EAGf;IAED,OAAO,CAAC,KAAK;IAIb,8DAA8D;IAC9D,OAAO,CAAC,OAAO;IAKf,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAE1E;IAED,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAEhD;IAED,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAEpC;IAED,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7B;IAEK,IAAI,CACR,MAAM,EAAE,MAAM,EACd,IAAI,GAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAO,GAChC,OAAO,CAAC,iBAAiB,CAAC,CAe5B;IAED,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAEpC;IAEK,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAKnD;IAED,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAE7C;CACF"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { normalizeStorageKey } from "@nodetool-ai/storage/storage-keys";
|
|
2
|
+
/**
|
|
3
|
+
* A `StorageAdapter` that carves a key prefix out of another one.
|
|
4
|
+
*
|
|
5
|
+
* Cloud deployments keep one bucket. Giving each user a workspace inside it
|
|
6
|
+
* means their keys have to be namespaced, and the namespacing has to be
|
|
7
|
+
* invisible to whatever holds the adapter — a caller that stores `notes.md`
|
|
8
|
+
* must read it back as `notes.md`, not as `workspaces/u1/notes.md`. Every key
|
|
9
|
+
* going in gains the prefix and every key coming out loses it again.
|
|
10
|
+
*
|
|
11
|
+
* The prefix is applied to *keys*, never to URIs: a URI is opaque and already
|
|
12
|
+
* carries the full key, so it passes through untouched.
|
|
13
|
+
*/
|
|
14
|
+
export class PrefixedStorageAdapter {
|
|
15
|
+
inner;
|
|
16
|
+
/** Normalized prefix with no trailing slash. */
|
|
17
|
+
prefix;
|
|
18
|
+
constructor(inner, prefix) {
|
|
19
|
+
this.inner = inner;
|
|
20
|
+
this.prefix = normalizeStorageKey(prefix);
|
|
21
|
+
}
|
|
22
|
+
scope(key) {
|
|
23
|
+
return `${this.prefix}/${normalizeStorageKey(key)}`;
|
|
24
|
+
}
|
|
25
|
+
/** Strip the prefix from a key the inner adapter reported. */
|
|
26
|
+
unscope(key) {
|
|
27
|
+
const head = `${this.prefix}/`;
|
|
28
|
+
return key.startsWith(head) ? key.slice(head.length) : null;
|
|
29
|
+
}
|
|
30
|
+
store(key, data, contentType) {
|
|
31
|
+
return this.inner.store(this.scope(key), data, contentType);
|
|
32
|
+
}
|
|
33
|
+
retrieve(uri) {
|
|
34
|
+
return this.inner.retrieve(uri);
|
|
35
|
+
}
|
|
36
|
+
exists(uri) {
|
|
37
|
+
return this.inner.exists(uri);
|
|
38
|
+
}
|
|
39
|
+
uriForKey(key) {
|
|
40
|
+
return this.inner.uriForKey(this.scope(key));
|
|
41
|
+
}
|
|
42
|
+
async list(prefix, opts = {}) {
|
|
43
|
+
// An empty prefix means "everything in the workspace", which is the
|
|
44
|
+
// adapter's own prefix rather than the bucket root.
|
|
45
|
+
const scoped = prefix ? this.scope(prefix) : this.prefix;
|
|
46
|
+
const result = await this.inner.list(scoped, opts);
|
|
47
|
+
const head = `${this.prefix}/`;
|
|
48
|
+
return {
|
|
49
|
+
entries: result.entries.flatMap((entry) => {
|
|
50
|
+
const key = this.unscope(entry.key);
|
|
51
|
+
return key ? [{ ...entry, key }] : [];
|
|
52
|
+
}),
|
|
53
|
+
commonPrefixes: result.commonPrefixes.flatMap((p) => p.startsWith(head) ? [p.slice(head.length)] : [])
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
delete(uri) {
|
|
57
|
+
return this.inner.delete(uri);
|
|
58
|
+
}
|
|
59
|
+
async stat(uri) {
|
|
60
|
+
const st = await this.inner.stat(uri);
|
|
61
|
+
if (!st)
|
|
62
|
+
return null;
|
|
63
|
+
const key = this.unscope(st.key);
|
|
64
|
+
return key ? { ...st, key } : st;
|
|
65
|
+
}
|
|
66
|
+
localPath(uri) {
|
|
67
|
+
return this.inner.localPath(uri);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=prefixed-storage-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefixed-storage-adapter.js","sourceRoot":"","sources":["../src/prefixed-storage-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAOxE;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,sBAAsB;IAKd,KAAK;IAJxB,gDAAgD;IACvC,MAAM,CAAS;IAExB,YACmB,KAAqB,EACtC,MAAc;qBADG,KAAK;QAGtB,IAAI,CAAC,MAAM,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC;IAC5C,CAAC;IAEO,KAAK,CAAC,GAAW;QACvB,OAAO,GAAG,IAAI,CAAC,MAAM,IAAI,mBAAmB,CAAC,GAAG,CAAC,EAAE,CAAC;IACtD,CAAC;IAED,8DAA8D;IACtD,OAAO,CAAC,GAAW;QACzB,MAAM,IAAI,GAAG,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC;QAC/B,OAAO,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC9D,CAAC;IAED,KAAK,CAAC,GAAW,EAAE,IAAgB,EAAE,WAAoB;QACvD,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;IAC9D,CAAC;IAED,QAAQ,CAAC,GAAW;QAClB,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IAClC,CAAC;IAED,MAAM,CAAC,GAAW;QAChB,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAChC,CAAC;IAED,SAAS,CAAC,GAAW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AAC,GAAG,CAAC,CAAC;QACtC,IAAI,CAAC,EAAE;YAAE,OAAO,IAAI,CAAC;QACrB,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;QACjC,OAAO,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACnC,CAAC;IAED,SAAS,CAAC,GAAW;QACnB,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC;CACF"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SSRF guard for outbound fetches of caller-supplied URLs, and the one address
|
|
3
|
+
* table every screening surface in the repo reads.
|
|
4
|
+
*
|
|
5
|
+
* Image/video providers (FAL, Replicate, …) return result URLs that the server
|
|
6
|
+
* then `fetch`es to download the generated bytes. Those URLs originate from the
|
|
7
|
+
* provider's response, so without validation a compromised or misbehaving
|
|
8
|
+
* provider — or a response coerced via a crafted prompt — could point the
|
|
9
|
+
* server at internal services (`http://169.254.169.254/...`,
|
|
10
|
+
* `http://localhost:6379/...`, RFC1918 hosts, …). The same is true of a media
|
|
11
|
+
* ref a workflow carries and of a URL a model hands a tool.
|
|
12
|
+
*
|
|
13
|
+
* Two things live here, and the split matters. {@link isBlockedIpLiteral} is
|
|
14
|
+
* the **address table** — which literals are internal — shared with the sandbox
|
|
15
|
+
* fetch bridge (`packages/agents/src/network-guard.ts`), which allows plain
|
|
16
|
+
* http and an opt-in private mode that this module never does.
|
|
17
|
+
* {@link isSafePublicHttpsUrl} is NodeTool's **default policy** on top of it:
|
|
18
|
+
* https only, to an apparently-public host. A predicate is not a protected
|
|
19
|
+
* fetch, though — only {@link safeFetch} validates every redirect hop, so an
|
|
20
|
+
* operation that actually goes out calls that.
|
|
21
|
+
*
|
|
22
|
+
* The check is conservative: unparseable URLs, non-https schemes, and literal
|
|
23
|
+
* IP addresses in loopback / link-local / RFC1918 / CGNAT / benchmarking ranges
|
|
24
|
+
* (including IPv4-mapped IPv6 literals and IPv4 embedded in 6to4 / NAT64
|
|
25
|
+
* transition addresses) are refused. Alternate IPv4 spellings — decimal, hex,
|
|
26
|
+
* octal, short form — are normalized by the WHATWG URL parser before the table
|
|
27
|
+
* sees them.
|
|
28
|
+
*
|
|
29
|
+
* **DNS rebinding is out of scope here, deliberately.** A public name that
|
|
30
|
+
* resolves to a private address passes: this process does not control which
|
|
31
|
+
* address `fetch` connects to, and pinning one would break TLS and virtual
|
|
32
|
+
* hosting. Two answers exist and the inventory records which each surface uses
|
|
33
|
+
* — `assertResolvedHostAllowed` (a resolve-and-check pass, for a URL handed to
|
|
34
|
+
* a separate process that opens its own sockets), and the deployment's egress
|
|
35
|
+
* control as the security boundary for everything in-process. See
|
|
36
|
+
* `docs/url-egress-inventory.md`.
|
|
37
|
+
*/
|
|
38
|
+
/**
|
|
39
|
+
* True when `host` is a literal IPv4/IPv6 address in a loopback, link-local,
|
|
40
|
+
* private, CGNAT or benchmarking range — including the IPv6 spellings that
|
|
41
|
+
* carry an IPv4 inside them (IPv4-mapped, IPv4-compatible, 6to4, NAT64).
|
|
42
|
+
*
|
|
43
|
+
* This is the address table, not a policy: it says nothing about schemes,
|
|
44
|
+
* hostnames or redirects, and a caller that allows private networks on purpose
|
|
45
|
+
* (the sandbox fetch bridge under `allowPrivateNetwork`) skips it rather than
|
|
46
|
+
* reimplementing it. A hostname that is not a literal is not this function's
|
|
47
|
+
* question — it answers `false`, and what the name *resolves* to is decided by
|
|
48
|
+
* the surface's DNS-rebinding policy (see the module comment).
|
|
49
|
+
*/
|
|
50
|
+
export declare function isBlockedIpLiteral(host: string): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Return `true` when `url` is an https URL whose host is not a loopback,
|
|
53
|
+
* link-local, or RFC1918 private address. NodeTool's default egress policy.
|
|
54
|
+
*/
|
|
55
|
+
export declare function isSafePublicHttpsUrl(url: string): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Throw if `url` is not a safe public https URL (see {@link isSafePublicHttpsUrl}).
|
|
58
|
+
* Use before `fetch`ing any provider-supplied download URL.
|
|
59
|
+
*/
|
|
60
|
+
export declare function assertSafePublicHttpsUrl(url: string): void;
|
|
61
|
+
/**
|
|
62
|
+
* `fetch` a provider-supplied URL with SSRF protection. The initial URL and
|
|
63
|
+
* every redirect hop are validated with {@link assertSafePublicHttpsUrl}, so a
|
|
64
|
+
* public host cannot redirect into an internal/loopback target or downgrade to
|
|
65
|
+
* http. Redirects are followed manually up to `maxRedirects`. When a redirect
|
|
66
|
+
* crosses to a different origin, auth headers and the request body are stripped
|
|
67
|
+
* so they are never leaked to the redirect target.
|
|
68
|
+
*/
|
|
69
|
+
export declare function safeFetch(url: string, init?: RequestInit, maxRedirects?: number, fetchImpl?: typeof fetch): Promise<Response>;
|
|
70
|
+
//# sourceMappingURL=safe-url.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safe-url.d.ts","sourceRoot":"","sources":["../src/safe-url.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAgEH;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAwCxD;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CA8BzD;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAM1D;AAyBD;;;;;;;GAOG;AACH,wBAAsB,SAAS,CAC7B,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,WAAW,EAClB,YAAY,SAAI,EAKhB,SAAS,GAAE,OAAO,KAAa,GAC9B,OAAO,CAAC,QAAQ,CAAC,CA6BnB"}
|
package/dist/safe-url.js
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SSRF guard for outbound fetches of caller-supplied URLs, and the one address
|
|
3
|
+
* table every screening surface in the repo reads.
|
|
4
|
+
*
|
|
5
|
+
* Image/video providers (FAL, Replicate, …) return result URLs that the server
|
|
6
|
+
* then `fetch`es to download the generated bytes. Those URLs originate from the
|
|
7
|
+
* provider's response, so without validation a compromised or misbehaving
|
|
8
|
+
* provider — or a response coerced via a crafted prompt — could point the
|
|
9
|
+
* server at internal services (`http://169.254.169.254/...`,
|
|
10
|
+
* `http://localhost:6379/...`, RFC1918 hosts, …). The same is true of a media
|
|
11
|
+
* ref a workflow carries and of a URL a model hands a tool.
|
|
12
|
+
*
|
|
13
|
+
* Two things live here, and the split matters. {@link isBlockedIpLiteral} is
|
|
14
|
+
* the **address table** — which literals are internal — shared with the sandbox
|
|
15
|
+
* fetch bridge (`packages/agents/src/network-guard.ts`), which allows plain
|
|
16
|
+
* http and an opt-in private mode that this module never does.
|
|
17
|
+
* {@link isSafePublicHttpsUrl} is NodeTool's **default policy** on top of it:
|
|
18
|
+
* https only, to an apparently-public host. A predicate is not a protected
|
|
19
|
+
* fetch, though — only {@link safeFetch} validates every redirect hop, so an
|
|
20
|
+
* operation that actually goes out calls that.
|
|
21
|
+
*
|
|
22
|
+
* The check is conservative: unparseable URLs, non-https schemes, and literal
|
|
23
|
+
* IP addresses in loopback / link-local / RFC1918 / CGNAT / benchmarking ranges
|
|
24
|
+
* (including IPv4-mapped IPv6 literals and IPv4 embedded in 6to4 / NAT64
|
|
25
|
+
* transition addresses) are refused. Alternate IPv4 spellings — decimal, hex,
|
|
26
|
+
* octal, short form — are normalized by the WHATWG URL parser before the table
|
|
27
|
+
* sees them.
|
|
28
|
+
*
|
|
29
|
+
* **DNS rebinding is out of scope here, deliberately.** A public name that
|
|
30
|
+
* resolves to a private address passes: this process does not control which
|
|
31
|
+
* address `fetch` connects to, and pinning one would break TLS and virtual
|
|
32
|
+
* hosting. Two answers exist and the inventory records which each surface uses
|
|
33
|
+
* — `assertResolvedHostAllowed` (a resolve-and-check pass, for a URL handed to
|
|
34
|
+
* a separate process that opens its own sockets), and the deployment's egress
|
|
35
|
+
* control as the security boundary for everything in-process. See
|
|
36
|
+
* `docs/url-egress-inventory.md`.
|
|
37
|
+
*/
|
|
38
|
+
/**
|
|
39
|
+
* Expand an IPv6 literal (already stripped of brackets, lower-cased) into its 8
|
|
40
|
+
* 16-bit hextets, handling `::` compression and a trailing dotted-quad. Returns
|
|
41
|
+
* `null` if `host` is not a well-formed IPv6 literal.
|
|
42
|
+
*/
|
|
43
|
+
function expandIpv6(host) {
|
|
44
|
+
if (!host.includes(":"))
|
|
45
|
+
return null;
|
|
46
|
+
// Rewrite a trailing dotted-quad (`...:a.b.c.d`) into two hex hextets so the
|
|
47
|
+
// rest of the parse only deals with `:`-separated groups.
|
|
48
|
+
const body = host.replace(/((?:\d{1,3}\.){3}\d{1,3})$/, (m) => {
|
|
49
|
+
const oct = m.split(".").map((n) => parseInt(n, 10));
|
|
50
|
+
if (oct.some((n) => n > 255))
|
|
51
|
+
return "\0"; // sentinel → fails group parse
|
|
52
|
+
const hex = (n) => n.toString(16).padStart(2, "0");
|
|
53
|
+
return `${hex(oct[0])}${hex(oct[1])}:${hex(oct[2])}${hex(oct[3])}`;
|
|
54
|
+
});
|
|
55
|
+
const halves = body.split("::");
|
|
56
|
+
if (halves.length > 2)
|
|
57
|
+
return null;
|
|
58
|
+
const parseGroup = (s) => {
|
|
59
|
+
if (s === "")
|
|
60
|
+
return [];
|
|
61
|
+
const out = [];
|
|
62
|
+
for (const p of s.split(":")) {
|
|
63
|
+
if (!/^[0-9a-f]{1,4}$/.test(p))
|
|
64
|
+
return null;
|
|
65
|
+
out.push(parseInt(p, 16));
|
|
66
|
+
}
|
|
67
|
+
return out;
|
|
68
|
+
};
|
|
69
|
+
const head = parseGroup(halves[0]);
|
|
70
|
+
if (head === null)
|
|
71
|
+
return null;
|
|
72
|
+
let hextets;
|
|
73
|
+
if (halves.length === 2) {
|
|
74
|
+
const rest = parseGroup(halves[1]);
|
|
75
|
+
if (rest === null)
|
|
76
|
+
return null;
|
|
77
|
+
const middle = 8 - head.length - rest.length;
|
|
78
|
+
if (middle < 0)
|
|
79
|
+
return null;
|
|
80
|
+
hextets = [...head, ...new Array(middle).fill(0), ...rest];
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
hextets = head;
|
|
84
|
+
}
|
|
85
|
+
if (hextets.length !== 8)
|
|
86
|
+
return null;
|
|
87
|
+
return hextets;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* True for IPv4 octet pairs in loopback / RFC1918 / link-local / CGNAT /
|
|
91
|
+
* benchmarking ranges.
|
|
92
|
+
*/
|
|
93
|
+
function isPrivateIpv4(a, b) {
|
|
94
|
+
// 0.0.0.0/8, 10.0.0.0/8, 127.0.0.0/8
|
|
95
|
+
if (a === 0 || a === 10 || a === 127)
|
|
96
|
+
return true;
|
|
97
|
+
// 169.254.0.0/16 (link-local, incl. the 169.254.169.254 metadata service)
|
|
98
|
+
if (a === 169 && b === 254)
|
|
99
|
+
return true;
|
|
100
|
+
// 172.16.0.0/12
|
|
101
|
+
if (a === 172 && b >= 16 && b <= 31)
|
|
102
|
+
return true;
|
|
103
|
+
// 192.168.0.0/16
|
|
104
|
+
if (a === 192 && b === 168)
|
|
105
|
+
return true;
|
|
106
|
+
// 100.64.0.0/10 (CGNAT)
|
|
107
|
+
if (a === 100 && b >= 64 && b <= 127)
|
|
108
|
+
return true;
|
|
109
|
+
// 198.18.0.0/15 (benchmarking)
|
|
110
|
+
if (a === 198 && (b === 18 || b === 19))
|
|
111
|
+
return true;
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* True when `host` is a literal IPv4/IPv6 address in a loopback, link-local,
|
|
116
|
+
* private, CGNAT or benchmarking range — including the IPv6 spellings that
|
|
117
|
+
* carry an IPv4 inside them (IPv4-mapped, IPv4-compatible, 6to4, NAT64).
|
|
118
|
+
*
|
|
119
|
+
* This is the address table, not a policy: it says nothing about schemes,
|
|
120
|
+
* hostnames or redirects, and a caller that allows private networks on purpose
|
|
121
|
+
* (the sandbox fetch bridge under `allowPrivateNetwork`) skips it rather than
|
|
122
|
+
* reimplementing it. A hostname that is not a literal is not this function's
|
|
123
|
+
* question — it answers `false`, and what the name *resolves* to is decided by
|
|
124
|
+
* the surface's DNS-rebinding policy (see the module comment).
|
|
125
|
+
*/
|
|
126
|
+
export function isBlockedIpLiteral(host) {
|
|
127
|
+
// Strip IPv6 brackets and any zone id (`fe80::1%eth0`), lower-case for the
|
|
128
|
+
// hex comparisons.
|
|
129
|
+
const h = host
|
|
130
|
+
.replace(/^\[|\]$/g, "")
|
|
131
|
+
.split("%")[0]
|
|
132
|
+
.toLowerCase();
|
|
133
|
+
// IPv4 in dotted form, standalone or as an IPv6 tail (`::ffff:127.0.0.1`).
|
|
134
|
+
const dotted = h.match(/(?:^|:)((?:\d{1,3}\.){3}\d{1,3})$/);
|
|
135
|
+
if (dotted) {
|
|
136
|
+
const [a, b] = dotted[1].split(".").map((n) => parseInt(n, 10));
|
|
137
|
+
return isPrivateIpv4(a, b);
|
|
138
|
+
}
|
|
139
|
+
if (!h.includes(":"))
|
|
140
|
+
return false;
|
|
141
|
+
if (h === "::" || h === "::1")
|
|
142
|
+
return true; // unspecified / loopback
|
|
143
|
+
if (h.startsWith("fc") || h.startsWith("fd"))
|
|
144
|
+
return true; // ULA fc00::/7
|
|
145
|
+
// link-local fe80::/10 — the first hextet spans fe80–febf, so the first three
|
|
146
|
+
// hex digits are fe8/fe9/fea/feb; "fe80" alone is too narrow.
|
|
147
|
+
if (/^fe[89ab]/.test(h))
|
|
148
|
+
return true;
|
|
149
|
+
// IPv4 embedded in a hex-serialized IPv6 literal. The WHATWG parser rewrites
|
|
150
|
+
// `::ffff:127.0.0.1` to `::ffff:7f00:1`, which the dotted regex above no
|
|
151
|
+
// longer matches, and the transition prefixes hide an IPv4 in the same way:
|
|
152
|
+
// IPv4-mapped/-compatible and NAT64 (64:ff9b::/96) in the low 32 bits, 6to4
|
|
153
|
+
// (2002:WWXX:YYZZ::/16) in the second and third hextets.
|
|
154
|
+
const hextets = expandIpv6(h);
|
|
155
|
+
if (!hextets)
|
|
156
|
+
return false;
|
|
157
|
+
const isZero = (from, to) => hextets.slice(from, to).every((n) => n === 0);
|
|
158
|
+
let embedded = null;
|
|
159
|
+
if (hextets[0] === 0x2002) {
|
|
160
|
+
embedded = hextets[1];
|
|
161
|
+
}
|
|
162
|
+
else if (isZero(0, 5) && hextets[5] === 0xffff) {
|
|
163
|
+
embedded = hextets[6]; // ::ffff:a.b.c.d
|
|
164
|
+
}
|
|
165
|
+
else if (isZero(0, 6)) {
|
|
166
|
+
embedded = hextets[6]; // ::a.b.c.d (IPv4-compatible, deprecated)
|
|
167
|
+
}
|
|
168
|
+
else if (hextets[0] === 0x64 && hextets[1] === 0xff9b && isZero(2, 6)) {
|
|
169
|
+
embedded = hextets[6]; // 64:ff9b::/96
|
|
170
|
+
}
|
|
171
|
+
if (embedded === null)
|
|
172
|
+
return false;
|
|
173
|
+
return isPrivateIpv4((embedded >> 8) & 0xff, embedded & 0xff);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Return `true` when `url` is an https URL whose host is not a loopback,
|
|
177
|
+
* link-local, or RFC1918 private address. NodeTool's default egress policy.
|
|
178
|
+
*/
|
|
179
|
+
export function isSafePublicHttpsUrl(url) {
|
|
180
|
+
let parsed;
|
|
181
|
+
try {
|
|
182
|
+
parsed = new URL(url);
|
|
183
|
+
}
|
|
184
|
+
catch {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
if (parsed.protocol !== "https:") {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
// Normalise: strip IPv6 brackets (WHATWG URL may include them depending on
|
|
191
|
+
// the runtime) and any trailing dot (`localhost.` resolves the same as
|
|
192
|
+
// `localhost` but would dodge the exact/suffix checks below). The dots are
|
|
193
|
+
// trimmed with a loop: `/\.+$/` backtracks quadratically on a long dot run.
|
|
194
|
+
const bare = parsed.hostname.toLowerCase().replace(/^\[|\]$/g, "");
|
|
195
|
+
let end = bare.length;
|
|
196
|
+
while (end > 0 && bare[end - 1] === ".")
|
|
197
|
+
end -= 1;
|
|
198
|
+
const host = bare.slice(0, end);
|
|
199
|
+
if (!host)
|
|
200
|
+
return false;
|
|
201
|
+
if (host === "localhost" ||
|
|
202
|
+
host === "ip6-localhost" ||
|
|
203
|
+
host === "ip6-loopback" ||
|
|
204
|
+
host.endsWith(".localhost") ||
|
|
205
|
+
host.endsWith(".local") ||
|
|
206
|
+
host.endsWith(".internal")) {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
return !isBlockedIpLiteral(host);
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Throw if `url` is not a safe public https URL (see {@link isSafePublicHttpsUrl}).
|
|
213
|
+
* Use before `fetch`ing any provider-supplied download URL.
|
|
214
|
+
*/
|
|
215
|
+
export function assertSafePublicHttpsUrl(url) {
|
|
216
|
+
if (!isSafePublicHttpsUrl(url)) {
|
|
217
|
+
throw new Error(`Refusing to fetch unsafe URL (must be https to a public host): ${url}`);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/** Request headers that must not cross an origin boundary on a redirect. */
|
|
221
|
+
const CROSS_ORIGIN_SENSITIVE_HEADERS = [
|
|
222
|
+
"authorization",
|
|
223
|
+
"cookie",
|
|
224
|
+
"proxy-authorization",
|
|
225
|
+
"x-goog-api-key",
|
|
226
|
+
"x-api-key"
|
|
227
|
+
];
|
|
228
|
+
/**
|
|
229
|
+
* Return a copy of `init` with credentials and body stripped, for replay
|
|
230
|
+
* against a different origin. Mirrors browser behaviour: a cross-origin
|
|
231
|
+
* redirect must not forward `Authorization`/`Cookie` headers or the request
|
|
232
|
+
* body, both of which may carry secrets meant only for the original host.
|
|
233
|
+
*/
|
|
234
|
+
function stripCrossOriginCredentials(init) {
|
|
235
|
+
const headers = new Headers(init.headers ?? undefined);
|
|
236
|
+
for (const name of CROSS_ORIGIN_SENSITIVE_HEADERS)
|
|
237
|
+
headers.delete(name);
|
|
238
|
+
const next = { ...init, headers };
|
|
239
|
+
delete next.body;
|
|
240
|
+
return next;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* `fetch` a provider-supplied URL with SSRF protection. The initial URL and
|
|
244
|
+
* every redirect hop are validated with {@link assertSafePublicHttpsUrl}, so a
|
|
245
|
+
* public host cannot redirect into an internal/loopback target or downgrade to
|
|
246
|
+
* http. Redirects are followed manually up to `maxRedirects`. When a redirect
|
|
247
|
+
* crosses to a different origin, auth headers and the request body are stripped
|
|
248
|
+
* so they are never leaked to the redirect target.
|
|
249
|
+
*/
|
|
250
|
+
export async function safeFetch(url, init, maxRedirects = 5,
|
|
251
|
+
// The underlying fetch implementation. Defaults to the global fetch; callers
|
|
252
|
+
// that inject a fetch (e.g. providers with a testable `fetchFn`) can pass it
|
|
253
|
+
// here so the SSRF URL validation still runs on every hop while the actual
|
|
254
|
+
// request goes through their implementation.
|
|
255
|
+
fetchImpl = fetch) {
|
|
256
|
+
let current = url;
|
|
257
|
+
let currentInit = { ...init };
|
|
258
|
+
let currentOrigin = new URL(url).origin;
|
|
259
|
+
for (let hop = 0; hop <= maxRedirects; hop++) {
|
|
260
|
+
assertSafePublicHttpsUrl(current);
|
|
261
|
+
const res = await fetchImpl(current, { ...currentInit, redirect: "manual" });
|
|
262
|
+
// A real Response always has headers; tolerate minimal fetch mocks/polyfills
|
|
263
|
+
// that omit them (treated as no redirect).
|
|
264
|
+
const location = res.headers?.get?.("location") ?? null;
|
|
265
|
+
if (res.status >= 300 && res.status < 400 && location) {
|
|
266
|
+
const method = (currentInit.method ?? "GET").toUpperCase();
|
|
267
|
+
if (((res.status === 301 || res.status === 302) && method === "POST") ||
|
|
268
|
+
(res.status === 303 && method !== "GET" && method !== "HEAD")) {
|
|
269
|
+
const headers = new Headers(currentInit.headers);
|
|
270
|
+
for (const name of ["content-encoding", "content-language", "content-location", "content-type", "content-length"])
|
|
271
|
+
headers.delete(name);
|
|
272
|
+
currentInit = { ...currentInit, method: "GET", body: undefined, headers };
|
|
273
|
+
}
|
|
274
|
+
const next = new URL(location, current);
|
|
275
|
+
if (next.origin !== currentOrigin) {
|
|
276
|
+
currentInit = stripCrossOriginCredentials(currentInit);
|
|
277
|
+
}
|
|
278
|
+
current = next.toString();
|
|
279
|
+
currentOrigin = next.origin;
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
return res;
|
|
283
|
+
}
|
|
284
|
+
throw new Error(`Too many redirects while fetching: ${url}`);
|
|
285
|
+
}
|
|
286
|
+
//# sourceMappingURL=safe-url.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safe-url.js","sourceRoot":"","sources":["../src/safe-url.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH;;;;GAIG;AACH,SAAS,UAAU,CAAC,IAAY;IAC9B,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IACrC,6EAA6E;IAC7E,0DAA0D;IAC1D,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,4BAA4B,EAAE,CAAC,CAAC,EAAE,EAAE;QAC5D,MAAM,GAAG,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;QACrD,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC;YAAE,OAAO,IAAI,CAAC,CAAC,+BAA+B;QAC1E,MAAM,GAAG,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ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