@w3kits/sdk 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 +29 -0
- package/dist/app-file.d.ts +39 -0
- package/dist/app-file.d.ts.map +1 -0
- package/dist/app-file.js +81 -0
- package/dist/app-file.js.map +1 -0
- package/dist/browser.d.ts +12 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +12 -0
- package/dist/browser.js.map +1 -0
- package/dist/container.d.ts +36 -0
- package/dist/container.d.ts.map +1 -0
- package/dist/container.js +125 -0
- package/dist/container.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/local-cache.d.ts +207 -0
- package/dist/local-cache.d.ts.map +1 -0
- package/dist/local-cache.js +187 -0
- package/dist/local-cache.js.map +1 -0
- package/dist/path-mapping.d.ts +79 -0
- package/dist/path-mapping.d.ts.map +1 -0
- package/dist/path-mapping.js +156 -0
- package/dist/path-mapping.js.map +1 -0
- package/dist/plugin.d.ts +34 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +124 -0
- package/dist/plugin.js.map +1 -0
- package/dist/profile-app-file.d.ts +202 -0
- package/dist/profile-app-file.d.ts.map +1 -0
- package/dist/profile-app-file.js +352 -0
- package/dist/profile-app-file.js.map +1 -0
- package/dist/r2-client.d.ts +76 -0
- package/dist/r2-client.d.ts.map +1 -0
- package/dist/r2-client.js +56 -0
- package/dist/r2-client.js.map +1 -0
- package/dist/storage/index.d.ts +67 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +111 -0
- package/dist/storage/index.js.map +1 -0
- package/package.json +73 -0
package/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# @w3kits/sdk
|
|
2
|
+
|
|
3
|
+
Client-first W3Kits SDK for browser, plugin, container, storage, visible path,
|
|
4
|
+
local cache, R2 capability, and `.app` file semantics.
|
|
5
|
+
|
|
6
|
+
## Entry Points
|
|
7
|
+
|
|
8
|
+
- `@w3kits/sdk`
|
|
9
|
+
- `@w3kits/sdk/browser`
|
|
10
|
+
- `@w3kits/sdk/plugin`
|
|
11
|
+
- `@w3kits/sdk/container`
|
|
12
|
+
- `@w3kits/sdk/storage`
|
|
13
|
+
- `@w3kits/sdk/path-mapping`
|
|
14
|
+
- `@w3kits/sdk/local-cache`
|
|
15
|
+
- `@w3kits/sdk/r2-client`
|
|
16
|
+
- `@w3kits/sdk/app-file`
|
|
17
|
+
- `@w3kits/sdk/profile-app-file`
|
|
18
|
+
|
|
19
|
+
The `profile-app-file` entry point owns the shared profile `.app` descriptor
|
|
20
|
+
helpers used by Core, Web installed-app projection, and the independent
|
|
21
|
+
marketplace frontend.
|
|
22
|
+
|
|
23
|
+
## Release Check
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
pnpm --filter @w3kits/sdk typecheck
|
|
27
|
+
pnpm --filter @w3kits/sdk test
|
|
28
|
+
pnpm --filter @w3kits/sdk pack:check
|
|
29
|
+
```
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export declare const W3KITS_APP_FILE_SCHEMA_VERSION = 1;
|
|
2
|
+
export declare const W3KITS_APP_FILE_CONTENT_TYPE = "application/vnd.w3kits.app+json";
|
|
3
|
+
export type W3KitsAppFile = {
|
|
4
|
+
schemaVersion: typeof W3KITS_APP_FILE_SCHEMA_VERSION;
|
|
5
|
+
kind: "w3kits.app";
|
|
6
|
+
userId: string;
|
|
7
|
+
profileId: string;
|
|
8
|
+
pluginSlug: string;
|
|
9
|
+
title: string;
|
|
10
|
+
entryUrl: string;
|
|
11
|
+
iconUrl?: string;
|
|
12
|
+
runtime?: Record<string, unknown>;
|
|
13
|
+
configRoot: string;
|
|
14
|
+
installedAt: string;
|
|
15
|
+
updatedAt: string;
|
|
16
|
+
};
|
|
17
|
+
export type CreateAppFileInput = {
|
|
18
|
+
userId: string;
|
|
19
|
+
profileId?: string | null;
|
|
20
|
+
pluginSlug: string;
|
|
21
|
+
title: string;
|
|
22
|
+
entryUrl: string;
|
|
23
|
+
iconUrl?: string;
|
|
24
|
+
runtime?: Record<string, unknown>;
|
|
25
|
+
now?: string;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Builds the visible .app path for a plugin.
|
|
29
|
+
*/
|
|
30
|
+
export declare function w3kitsAppFilePath(pluginSlug: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* Creates a W3Kits .app file descriptor.
|
|
33
|
+
*/
|
|
34
|
+
export declare function createW3KitsAppFile(input: CreateAppFileInput): W3KitsAppFile;
|
|
35
|
+
/**
|
|
36
|
+
* Parses a W3Kits .app file, returning null for malformed or mismatched files.
|
|
37
|
+
*/
|
|
38
|
+
export declare function parseW3KitsAppFile(source: string, expected?: Partial<Pick<W3KitsAppFile, "userId" | "profileId" | "pluginSlug">>): W3KitsAppFile | null;
|
|
39
|
+
//# sourceMappingURL=app-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-file.d.ts","sourceRoot":"","sources":["../src/app-file.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,8BAA8B,IAAI,CAAC;AAChD,eAAO,MAAM,4BAA4B,oCAAoC,CAAC;AAE9E,MAAM,MAAM,aAAa,GAAG;IAC1B,aAAa,EAAE,OAAO,8BAA8B,CAAC;IACrD,IAAI,EAAE,YAAY,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,kBAAkB,GAAG,aAAa,CAiB5E;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,EACd,QAAQ,GAAE,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,QAAQ,GAAG,WAAW,GAAG,YAAY,CAAC,CAAM,GACjF,aAAa,GAAG,IAAI,CA6BtB"}
|
package/dist/app-file.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines SDK .app file helpers for installed plugin launchers.
|
|
3
|
+
* @owner w3kits-sdk
|
|
4
|
+
* @module sdk
|
|
5
|
+
* @boundary app-file
|
|
6
|
+
*/
|
|
7
|
+
import { appFilePath, pluginConfigRoot, normalizePluginSlug, normalizeProfileId, normalizeUserId, } from "./path-mapping.js";
|
|
8
|
+
export const W3KITS_APP_FILE_SCHEMA_VERSION = 1;
|
|
9
|
+
export const W3KITS_APP_FILE_CONTENT_TYPE = "application/vnd.w3kits.app+json";
|
|
10
|
+
/**
|
|
11
|
+
* Builds the visible .app path for a plugin.
|
|
12
|
+
*/
|
|
13
|
+
export function w3kitsAppFilePath(pluginSlug) {
|
|
14
|
+
return appFilePath(pluginSlug);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Creates a W3Kits .app file descriptor.
|
|
18
|
+
*/
|
|
19
|
+
export function createW3KitsAppFile(input) {
|
|
20
|
+
const now = input.now ?? new Date().toISOString();
|
|
21
|
+
const pluginSlug = normalizePluginSlug(input.pluginSlug);
|
|
22
|
+
return {
|
|
23
|
+
schemaVersion: W3KITS_APP_FILE_SCHEMA_VERSION,
|
|
24
|
+
kind: "w3kits.app",
|
|
25
|
+
userId: normalizeUserId(input.userId),
|
|
26
|
+
profileId: normalizeProfileId(input.profileId),
|
|
27
|
+
pluginSlug,
|
|
28
|
+
title: input.title,
|
|
29
|
+
entryUrl: input.entryUrl,
|
|
30
|
+
iconUrl: input.iconUrl,
|
|
31
|
+
runtime: input.runtime,
|
|
32
|
+
configRoot: pluginConfigRoot(pluginSlug),
|
|
33
|
+
installedAt: now,
|
|
34
|
+
updatedAt: now,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Parses a W3Kits .app file, returning null for malformed or mismatched files.
|
|
39
|
+
*/
|
|
40
|
+
export function parseW3KitsAppFile(source, expected = {}) {
|
|
41
|
+
let value;
|
|
42
|
+
try {
|
|
43
|
+
value = JSON.parse(source);
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
if (!isRecord(value))
|
|
49
|
+
return null;
|
|
50
|
+
if (value.schemaVersion !== W3KITS_APP_FILE_SCHEMA_VERSION)
|
|
51
|
+
return null;
|
|
52
|
+
if (value.kind !== "w3kits.app")
|
|
53
|
+
return null;
|
|
54
|
+
if (typeof value.userId !== "string" ||
|
|
55
|
+
typeof value.profileId !== "string" ||
|
|
56
|
+
typeof value.pluginSlug !== "string" ||
|
|
57
|
+
typeof value.title !== "string" ||
|
|
58
|
+
typeof value.entryUrl !== "string" ||
|
|
59
|
+
typeof value.configRoot !== "string" ||
|
|
60
|
+
typeof value.installedAt !== "string" ||
|
|
61
|
+
typeof value.updatedAt !== "string") {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
const appFile = value;
|
|
65
|
+
if (expected.userId && appFile.userId !== expected.userId)
|
|
66
|
+
return null;
|
|
67
|
+
if (expected.profileId && appFile.profileId !== expected.profileId)
|
|
68
|
+
return null;
|
|
69
|
+
if (expected.pluginSlug && appFile.pluginSlug !== expected.pluginSlug)
|
|
70
|
+
return null;
|
|
71
|
+
if (appFile.configRoot !== pluginConfigRoot(appFile.pluginSlug))
|
|
72
|
+
return null;
|
|
73
|
+
return appFile;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Checks whether a value is a plain record.
|
|
77
|
+
*/
|
|
78
|
+
function isRecord(value) {
|
|
79
|
+
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=app-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-file.js","sourceRoot":"","sources":["../src/app-file.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,GAChB,MAAM,mBAAmB,CAAC;AAE3B,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,CAAC;AAChD,MAAM,CAAC,MAAM,4BAA4B,GAAG,iCAAiC,CAAC;AA4B9E;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,UAAkB;IAClD,OAAO,WAAW,CAAC,UAAU,CAAC,CAAC;AACjC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAyB;IAC3D,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAClD,MAAM,UAAU,GAAG,mBAAmB,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACzD,OAAO;QACL,aAAa,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AAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,OAAO,GAAG,KAAsB,CAAC;IACvC,IAAI,QAAQ,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IACvE,IAAI,QAAQ,CAAC,SAAS,IAAI,OAAO,CAAC,SAAS,KAAK,QAAQ,CAAC,SAAS;QAAE,OAAO,IAAI,CAAC;IAChF,IAAI,QAAQ,CAAC,UAAU,IAAI,OAAO,CAAC,UAAU,KAAK,QAAQ,CAAC,UAAU;QAAE,OAAO,IAAI,CAAC;IACnF,IAAI,OAAO,CAAC,UAAU,KAAK,gBAAgB,CAAC,OAAO,CAAC,UAAU,CAAC;QAAE,OAAO,IAAI,CAAC;IAC7E,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;GAEG;AACH,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;AAC9E,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser SDK entrypoint.
|
|
3
|
+
* @owner w3kits-sdk
|
|
4
|
+
* @module sdk
|
|
5
|
+
*/
|
|
6
|
+
export * from "./path-mapping.js";
|
|
7
|
+
export * from "./local-cache.js";
|
|
8
|
+
export * from "./app-file.js";
|
|
9
|
+
export * from "./profile-app-file.js";
|
|
10
|
+
export * from "./storage/index.js";
|
|
11
|
+
export * from "./r2-client.js";
|
|
12
|
+
//# sourceMappingURL=browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC"}
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser SDK entrypoint.
|
|
3
|
+
* @owner w3kits-sdk
|
|
4
|
+
* @module sdk
|
|
5
|
+
*/
|
|
6
|
+
export * from "./path-mapping.js";
|
|
7
|
+
export * from "./local-cache.js";
|
|
8
|
+
export * from "./app-file.js";
|
|
9
|
+
export * from "./profile-app-file.js";
|
|
10
|
+
export * from "./storage/index.js";
|
|
11
|
+
export * from "./r2-client.js";
|
|
12
|
+
//# sourceMappingURL=browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Container SDK entrypoint.
|
|
3
|
+
* @owner w3kits-sdk
|
|
4
|
+
* @module sdk
|
|
5
|
+
*/
|
|
6
|
+
import { VISIBLE_HOME_ROOT } from "./path-mapping.js";
|
|
7
|
+
import { type R2DataPlaneDescriptor, type W3KitsStorageCapabilityDescriptor } from "./r2-client.js";
|
|
8
|
+
export * from "./path-mapping.js";
|
|
9
|
+
export * from "./storage/index.js";
|
|
10
|
+
export * from "./r2-client.js";
|
|
11
|
+
export type W3KitsContainerStorage = {
|
|
12
|
+
descriptor: W3KitsStorageCapabilityDescriptor;
|
|
13
|
+
visibleRoot: typeof VISIBLE_HOME_ROOT;
|
|
14
|
+
capability: W3KitsStorageCapabilityDescriptor["capability"];
|
|
15
|
+
r2: R2DataPlaneDescriptor;
|
|
16
|
+
authHeader: "x-w3kits-runtime-session";
|
|
17
|
+
sessionFile: "/home/agent/.cache/w3kits-storage/session.json";
|
|
18
|
+
r2KeyForVisiblePath(visiblePath: string): string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Represents container storage descriptor validation failures.
|
|
22
|
+
*/
|
|
23
|
+
export declare class W3KitsContainerStorageError extends Error {
|
|
24
|
+
readonly code: "legacy_storage_descriptor" | "invalid_storage_descriptor" | "invalid_storage_descriptor_version" | "legacy_fake_credentials" | "permanent_r2_credentials" | "descriptor_scope_mismatch" | "path_outside_capability";
|
|
25
|
+
/**
|
|
26
|
+
* Initializes a container storage error with a stable code.
|
|
27
|
+
*/
|
|
28
|
+
constructor(code: "legacy_storage_descriptor" | "invalid_storage_descriptor" | "invalid_storage_descriptor_version" | "legacy_fake_credentials" | "permanent_r2_credentials" | "descriptor_scope_mismatch" | "path_outside_capability", message: string);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Validates and initializes runtime-scoped container storage descriptors.
|
|
32
|
+
*/
|
|
33
|
+
export declare function initializeW3KitsContainerStorage(input: {
|
|
34
|
+
descriptor: unknown;
|
|
35
|
+
}): W3KitsContainerStorage;
|
|
36
|
+
//# sourceMappingURL=container.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"container.d.ts","sourceRoot":"","sources":["../src/container.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAsB,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,EAEL,KAAK,qBAAqB,EAC1B,KAAK,iCAAiC,EACvC,MAAM,gBAAgB,CAAC;AAExB,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAI/B,MAAM,MAAM,sBAAsB,GAAG;IACnC,UAAU,EAAE,iCAAiC,CAAC;IAC9C,WAAW,EAAE,OAAO,iBAAiB,CAAC;IACtC,UAAU,EAAE,iCAAiC,CAAC,YAAY,CAAC,CAAC;IAC5D,EAAE,EAAE,qBAAqB,CAAC;IAC1B,UAAU,EAAE,0BAA0B,CAAC;IACvC,WAAW,EAAE,gDAAgD,CAAC;IAC9D,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAAC;CAClD,CAAC;AAEF;;GAEG;AACH,qBAAa,2BAA4B,SAAQ,KAAK;aAKlC,IAAI,EAChB,2BAA2B,GAC3B,4BAA4B,GAC5B,oCAAoC,GACpC,yBAAyB,GACzB,0BAA0B,GAC1B,2BAA2B,GAC3B,yBAAyB;IAX/B;;OAEG;gBAEe,IAAI,EAChB,2BAA2B,GAC3B,4BAA4B,GAC5B,oCAAoC,GACpC,yBAAyB,GACzB,0BAA0B,GAC1B,2BAA2B,GAC3B,yBAAyB,EAC7B,OAAO,EAAE,MAAM;CAKlB;AAED;;GAEG;AACH,wBAAgB,gCAAgC,CAAC,KAAK,EAAE;IACtD,UAAU,EAAE,OAAO,CAAC;CACrB,GAAG,sBAAsB,CA6CzB"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Container SDK entrypoint.
|
|
3
|
+
* @owner w3kits-sdk
|
|
4
|
+
* @module sdk
|
|
5
|
+
*/
|
|
6
|
+
import { mapVisiblePathToR2, VISIBLE_HOME_ROOT } from "./path-mapping.js";
|
|
7
|
+
import { W3KITS_STORAGE_CAPABILITY_DESCRIPTOR_VERSION, } from "./r2-client.js";
|
|
8
|
+
export * from "./path-mapping.js";
|
|
9
|
+
export * from "./storage/index.js";
|
|
10
|
+
export * from "./r2-client.js";
|
|
11
|
+
const LEGACY_OBJECT_FACADE_PATH = `/${["api", "vfs", "objects"].join("/")}`;
|
|
12
|
+
/**
|
|
13
|
+
* Represents container storage descriptor validation failures.
|
|
14
|
+
*/
|
|
15
|
+
export class W3KitsContainerStorageError extends Error {
|
|
16
|
+
code;
|
|
17
|
+
/**
|
|
18
|
+
* Initializes a container storage error with a stable code.
|
|
19
|
+
*/
|
|
20
|
+
constructor(code, message) {
|
|
21
|
+
super(message);
|
|
22
|
+
this.code = code;
|
|
23
|
+
this.name = "W3KitsContainerStorageError";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Validates and initializes runtime-scoped container storage descriptors.
|
|
28
|
+
*/
|
|
29
|
+
export function initializeW3KitsContainerStorage(input) {
|
|
30
|
+
const descriptor = assertContainerStorageDescriptor(input.descriptor);
|
|
31
|
+
if (descriptor.visibleRoot !== VISIBLE_HOME_ROOT) {
|
|
32
|
+
throw new W3KitsContainerStorageError("descriptor_scope_mismatch", "Container storage descriptors must be scoped to /home/agent");
|
|
33
|
+
}
|
|
34
|
+
const expectedPrefix = mapVisiblePathToR2(descriptor.visibleRoot, {
|
|
35
|
+
userId: descriptor.capability.userId,
|
|
36
|
+
profileId: descriptor.capability.profileId,
|
|
37
|
+
}).r2Key;
|
|
38
|
+
if (descriptor.r2.prefix !== expectedPrefix) {
|
|
39
|
+
throw new W3KitsContainerStorageError("descriptor_scope_mismatch", "Container storage descriptor R2 prefix does not match /home/agent");
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
descriptor,
|
|
43
|
+
visibleRoot: VISIBLE_HOME_ROOT,
|
|
44
|
+
capability: descriptor.capability,
|
|
45
|
+
r2: descriptor.r2,
|
|
46
|
+
authHeader: descriptor.auth.header,
|
|
47
|
+
sessionFile: "/home/agent/.cache/w3kits-storage/session.json",
|
|
48
|
+
r2KeyForVisiblePath(visiblePath) {
|
|
49
|
+
let mapping;
|
|
50
|
+
try {
|
|
51
|
+
mapping = mapVisiblePathToR2(visiblePath, descriptor.capability);
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
throw new W3KitsContainerStorageError("path_outside_capability", "Visible path is outside the container storage capability");
|
|
55
|
+
}
|
|
56
|
+
if (!r2KeyWithinPrefix(mapping.r2Key, descriptor.r2.prefix)) {
|
|
57
|
+
throw new W3KitsContainerStorageError("path_outside_capability", "Visible path is outside the container storage capability");
|
|
58
|
+
}
|
|
59
|
+
return mapping.r2Key;
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Asserts the descriptor shape used by the container storage agent.
|
|
65
|
+
*/
|
|
66
|
+
function assertContainerStorageDescriptor(value) {
|
|
67
|
+
const descriptor = record(value, "invalid_storage_descriptor");
|
|
68
|
+
if (descriptor.type === "w3kits-vfs-object-facade" ||
|
|
69
|
+
descriptor.endpoint === LEGACY_OBJECT_FACADE_PATH) {
|
|
70
|
+
throw new W3KitsContainerStorageError("legacy_storage_descriptor", "Legacy VFS object-facade descriptors are not accepted by the SDK container bridge");
|
|
71
|
+
}
|
|
72
|
+
if (descriptor.version !== W3KITS_STORAGE_CAPABILITY_DESCRIPTOR_VERSION) {
|
|
73
|
+
throw new W3KitsContainerStorageError("invalid_storage_descriptor_version", "Unsupported W3Kits storage descriptor version");
|
|
74
|
+
}
|
|
75
|
+
const capability = record(descriptor.capability, "invalid_storage_descriptor");
|
|
76
|
+
const r2 = record(descriptor.r2, "invalid_storage_descriptor");
|
|
77
|
+
const auth = record(descriptor.auth, "invalid_storage_descriptor");
|
|
78
|
+
if (typeof descriptor.visibleRoot !== "string" ||
|
|
79
|
+
descriptor.visibleRoot !== capability.root ||
|
|
80
|
+
typeof capability.userId !== "string" ||
|
|
81
|
+
typeof capability.profileId !== "string" ||
|
|
82
|
+
!Array.isArray(capability.actions) ||
|
|
83
|
+
typeof capability.expiresAt !== "string" ||
|
|
84
|
+
typeof capability.credentialMode !== "string" ||
|
|
85
|
+
typeof r2.bucket !== "string" ||
|
|
86
|
+
typeof r2.endpoint !== "string" ||
|
|
87
|
+
r2.region !== "auto" ||
|
|
88
|
+
r2.forcePathStyle !== true ||
|
|
89
|
+
typeof r2.prefix !== "string" ||
|
|
90
|
+
!Array.isArray(r2.actions) ||
|
|
91
|
+
auth.mode !== "runtime-session" ||
|
|
92
|
+
auth.header !== "x-w3kits-runtime-session") {
|
|
93
|
+
throw new W3KitsContainerStorageError("invalid_storage_descriptor", "Invalid W3Kits container storage descriptor");
|
|
94
|
+
}
|
|
95
|
+
if (r2.credentials !== undefined) {
|
|
96
|
+
const credentials = record(r2.credentials, "invalid_storage_descriptor");
|
|
97
|
+
if (credentials.accessKeyId === "w3kits" ||
|
|
98
|
+
credentials.secretAccessKey === "w3kits-runtime-session") {
|
|
99
|
+
throw new W3KitsContainerStorageError("legacy_fake_credentials", "Legacy fake S3 credentials are not accepted by the SDK container bridge");
|
|
100
|
+
}
|
|
101
|
+
if (typeof credentials.accessKeyId !== "string" ||
|
|
102
|
+
typeof credentials.secretAccessKey !== "string" ||
|
|
103
|
+
typeof credentials.expiresAt !== "string") {
|
|
104
|
+
throw new W3KitsContainerStorageError("permanent_r2_credentials", "Container storage descriptors may only include expiring R2 credentials");
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return descriptor;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Narrows an unknown descriptor fragment to a non-array object.
|
|
111
|
+
*/
|
|
112
|
+
function record(value, code) {
|
|
113
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
114
|
+
throw new W3KitsContainerStorageError(code, "Invalid W3Kits container storage descriptor");
|
|
115
|
+
}
|
|
116
|
+
return value;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Checks whether a mapped R2 key remains inside the descriptor prefix.
|
|
120
|
+
*/
|
|
121
|
+
function r2KeyWithinPrefix(key, prefix) {
|
|
122
|
+
const cleanPrefix = prefix.replace(/\/+$/u, "");
|
|
123
|
+
return key === cleanPrefix || key.startsWith(`${cleanPrefix}/`);
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=container.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"container.js","sourceRoot":"","sources":["../src/container.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO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AAW,CAAC,SAAS,KAAK,QAAQ,EACzC,CAAC;YACD,MAAM,IAAI,2BAA2B,CACnC,0BAA0B,EAC1B,wEAAwE,CACzE,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO,UAA+C,CAAC;AACzD,CAAC;AAED;;GAEG;AACH,SAAS,MAAM,CACb,KAAc,EACd,IAAyC;IAEzC,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAChE,MAAM,IAAI,2BAA2B,CACnC,IAAI,EACJ,6CAA6C,CAC9C,CAAC;IACJ,CAAC;IACD,OAAO,KAAgC,CAAC;AAC1C,CAAC;AAED;;GAEG;AACH,SAAS,iBAAiB,CAAC,GAAW,EAAE,MAAc;IACpD,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAChD,OAAO,GAAG,KAAK,WAAW,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,WAAW,GAAG,CAAC,CAAC;AAClE,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* W3Kits SDK root entrypoint.
|
|
3
|
+
* @owner w3kits-sdk
|
|
4
|
+
* @module sdk
|
|
5
|
+
*/
|
|
6
|
+
export * from "./path-mapping.js";
|
|
7
|
+
export * from "./local-cache.js";
|
|
8
|
+
export * from "./app-file.js";
|
|
9
|
+
export * from "./profile-app-file.js";
|
|
10
|
+
export * from "./storage/index.js";
|
|
11
|
+
export * from "./r2-client.js";
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* W3Kits SDK root entrypoint.
|
|
3
|
+
* @owner w3kits-sdk
|
|
4
|
+
* @module sdk
|
|
5
|
+
*/
|
|
6
|
+
export * from "./path-mapping.js";
|
|
7
|
+
export * from "./local-cache.js";
|
|
8
|
+
export * from "./app-file.js";
|
|
9
|
+
export * from "./profile-app-file.js";
|
|
10
|
+
export * from "./storage/index.js";
|
|
11
|
+
export * from "./r2-client.js";
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines SDK-owned local-first cache model and operation log helpers.
|
|
3
|
+
* @owner w3kits-sdk
|
|
4
|
+
* @module sdk
|
|
5
|
+
* @boundary local-cache
|
|
6
|
+
*/
|
|
7
|
+
export type LocalFirstVfsSyncState = "local" | "queued" | "syncing" | "synced" | "failed" | "conflicted";
|
|
8
|
+
export type LocalFirstVfsBodyStorageKind = "indexeddb" | "opfs";
|
|
9
|
+
export interface LocalFirstVfsObject {
|
|
10
|
+
id: string;
|
|
11
|
+
scopeId: string;
|
|
12
|
+
userId: string;
|
|
13
|
+
cacheGeneration: string;
|
|
14
|
+
bucket: string;
|
|
15
|
+
key: string;
|
|
16
|
+
kind: "file" | "directory";
|
|
17
|
+
size: number;
|
|
18
|
+
contentType?: string;
|
|
19
|
+
etag: string;
|
|
20
|
+
revision: string;
|
|
21
|
+
remoteRevision?: string;
|
|
22
|
+
bodyRef?: string;
|
|
23
|
+
bodyStorage?: LocalFirstVfsBodyStorageKind;
|
|
24
|
+
syncState: LocalFirstVfsSyncState;
|
|
25
|
+
updatedAt: string;
|
|
26
|
+
deletedAt?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface LocalFirstVfsOperation {
|
|
29
|
+
operationId: string;
|
|
30
|
+
scopeId: string;
|
|
31
|
+
type: "put" | "delete" | "move" | "mkdir";
|
|
32
|
+
bucket: string;
|
|
33
|
+
key: string;
|
|
34
|
+
sourceBucket?: string;
|
|
35
|
+
sourceKey?: string;
|
|
36
|
+
bodyRef?: string;
|
|
37
|
+
contentType?: string;
|
|
38
|
+
status: "queued" | "syncing" | "synced" | "failed" | "superseded";
|
|
39
|
+
attempts: number;
|
|
40
|
+
lastError?: string;
|
|
41
|
+
nextAttemptAt?: string;
|
|
42
|
+
createdAt: string;
|
|
43
|
+
updatedAt: string;
|
|
44
|
+
}
|
|
45
|
+
export interface StoredBody {
|
|
46
|
+
bodyRef: string;
|
|
47
|
+
scopeId: string;
|
|
48
|
+
storage: LocalFirstVfsBodyStorageKind;
|
|
49
|
+
body?: ArrayBuffer;
|
|
50
|
+
opfsPath?: string;
|
|
51
|
+
size: number;
|
|
52
|
+
contentType?: string;
|
|
53
|
+
createdAt: string;
|
|
54
|
+
lastAccessedAt: string;
|
|
55
|
+
}
|
|
56
|
+
export interface ManifestGenerationRecord {
|
|
57
|
+
scopeId: string;
|
|
58
|
+
userId: string;
|
|
59
|
+
cacheGeneration: string;
|
|
60
|
+
createdAt: string;
|
|
61
|
+
updatedAt: string;
|
|
62
|
+
}
|
|
63
|
+
export interface LocalFirstVfsRemote {
|
|
64
|
+
put(input: {
|
|
65
|
+
bucket: string;
|
|
66
|
+
key: string;
|
|
67
|
+
body: Uint8Array;
|
|
68
|
+
contentType?: string;
|
|
69
|
+
operationId: string;
|
|
70
|
+
}): Promise<{
|
|
71
|
+
revision?: string;
|
|
72
|
+
}>;
|
|
73
|
+
delete(input: {
|
|
74
|
+
bucket: string;
|
|
75
|
+
key: string;
|
|
76
|
+
operationId: string;
|
|
77
|
+
}): Promise<{
|
|
78
|
+
revision?: string;
|
|
79
|
+
}>;
|
|
80
|
+
move(input: {
|
|
81
|
+
sourceBucket: string;
|
|
82
|
+
sourceKey: string;
|
|
83
|
+
bucket: string;
|
|
84
|
+
key: string;
|
|
85
|
+
operationId: string;
|
|
86
|
+
}): Promise<{
|
|
87
|
+
revision?: string;
|
|
88
|
+
}>;
|
|
89
|
+
mkdir?(input: {
|
|
90
|
+
bucket: string;
|
|
91
|
+
key: string;
|
|
92
|
+
operationId: string;
|
|
93
|
+
}): Promise<{
|
|
94
|
+
revision?: string;
|
|
95
|
+
}>;
|
|
96
|
+
list?(input: {
|
|
97
|
+
bucket: string;
|
|
98
|
+
prefix: string;
|
|
99
|
+
}): Promise<{
|
|
100
|
+
objects: Array<{
|
|
101
|
+
key: string;
|
|
102
|
+
kind?: "file" | "directory";
|
|
103
|
+
size?: number;
|
|
104
|
+
contentType?: string;
|
|
105
|
+
etag?: string;
|
|
106
|
+
revision?: string;
|
|
107
|
+
updatedAt?: string;
|
|
108
|
+
}>;
|
|
109
|
+
}>;
|
|
110
|
+
}
|
|
111
|
+
export interface LocalFirstVfsClientOptions {
|
|
112
|
+
userId: string;
|
|
113
|
+
cacheGeneration: string;
|
|
114
|
+
remote?: LocalFirstVfsRemote;
|
|
115
|
+
bodyStore?: "auto" | "indexeddb" | "opfs";
|
|
116
|
+
inlineBodyBytes?: number;
|
|
117
|
+
retryBaseDelayMs?: number;
|
|
118
|
+
maxRetryDelayMs?: number;
|
|
119
|
+
}
|
|
120
|
+
export declare const DB_NAME = "w3kits-local-first-vfs";
|
|
121
|
+
export declare const DB_VERSION = 2;
|
|
122
|
+
export declare const OBJECT_STORE = "objects";
|
|
123
|
+
export declare const BODY_STORE = "bodies";
|
|
124
|
+
export declare const OPERATION_STORE = "operations";
|
|
125
|
+
export declare const GENERATION_STORE = "generations";
|
|
126
|
+
export declare const OPFS_ROOT = "w3kits-local-first-vfs-v1";
|
|
127
|
+
export declare const OPEN_DB_TIMEOUT_MS = 2500;
|
|
128
|
+
export declare const DEFAULT_INLINE_BODY_BYTES: number;
|
|
129
|
+
export declare const DEFAULT_RETRY_BASE_DELAY_MS = 1000;
|
|
130
|
+
export declare const DEFAULT_MAX_RETRY_DELAY_MS = 30000;
|
|
131
|
+
/**
|
|
132
|
+
* Converts local-first body input to a standalone ArrayBuffer.
|
|
133
|
+
*/
|
|
134
|
+
export declare function toArrayBuffer(body: Uint8Array | ArrayBuffer | string): ArrayBuffer;
|
|
135
|
+
/**
|
|
136
|
+
* Normalizes an object key and rejects path escapes/control characters.
|
|
137
|
+
*/
|
|
138
|
+
export declare function normalizeKey(input: string, options?: {
|
|
139
|
+
allowRoot?: boolean;
|
|
140
|
+
}): string;
|
|
141
|
+
/**
|
|
142
|
+
* Builds the local-first cache scope id.
|
|
143
|
+
*/
|
|
144
|
+
export declare function scopeIdFor(userId: string, cacheGeneration: string): string;
|
|
145
|
+
/**
|
|
146
|
+
* Builds the stable local-first object row id.
|
|
147
|
+
*/
|
|
148
|
+
export declare function objectId(scopeId: string, bucket: string, key: string): string;
|
|
149
|
+
/**
|
|
150
|
+
* Creates a local operation id.
|
|
151
|
+
*/
|
|
152
|
+
export declare function createOperationId(): string;
|
|
153
|
+
/**
|
|
154
|
+
* Returns the current ISO timestamp for local-first records.
|
|
155
|
+
*/
|
|
156
|
+
export declare function nowIso(): string;
|
|
157
|
+
/**
|
|
158
|
+
* Computes bounded exponential retry delay for failed local-first operations.
|
|
159
|
+
*/
|
|
160
|
+
export declare function retryDelayMs(options: LocalFirstVfsClientOptions, attempts: number): number;
|
|
161
|
+
/**
|
|
162
|
+
* Computes the next retry timestamp for a failed local-first operation.
|
|
163
|
+
*/
|
|
164
|
+
export declare function nextAttemptIso(options: LocalFirstVfsClientOptions, attempts: number): string;
|
|
165
|
+
/**
|
|
166
|
+
* Encodes an OPFS-safe path segment.
|
|
167
|
+
*/
|
|
168
|
+
export declare function safeOpfsSegment(value: string): string;
|
|
169
|
+
/**
|
|
170
|
+
* Decides whether a body should try OPFS storage before IndexedDB storage.
|
|
171
|
+
*/
|
|
172
|
+
export declare function shouldTryOpfs(options: LocalFirstVfsClientOptions, bodySize: number): boolean;
|
|
173
|
+
/**
|
|
174
|
+
* Filters local-first objects by scope, bucket, and prefix.
|
|
175
|
+
*/
|
|
176
|
+
export declare function filterLocalFirstListRows(rows: LocalFirstVfsObject[], scopeId: string, bucket: string, prefix: string): LocalFirstVfsObject[];
|
|
177
|
+
/**
|
|
178
|
+
* Creates an operation log row with normalized fields.
|
|
179
|
+
*/
|
|
180
|
+
export declare function createQueuedOperation(input: Omit<LocalFirstVfsOperation, "operationId" | "status" | "attempts" | "createdAt" | "updatedAt"> & Partial<Pick<LocalFirstVfsOperation, "operationId" | "status" | "attempts" | "createdAt" | "updatedAt">>): LocalFirstVfsOperation;
|
|
181
|
+
/**
|
|
182
|
+
* Marks a queued operation as failed because auth/capability refresh is required.
|
|
183
|
+
*/
|
|
184
|
+
export declare function markQueuedAuthFailure(operation: LocalFirstVfsOperation, options: LocalFirstVfsClientOptions): LocalFirstVfsOperation;
|
|
185
|
+
/**
|
|
186
|
+
* In-memory operation log used by browser tests and non-persistent SDK adapters.
|
|
187
|
+
*/
|
|
188
|
+
export declare class InMemoryOperationLog {
|
|
189
|
+
private readonly operations;
|
|
190
|
+
/**
|
|
191
|
+
* Enqueues an operation and returns the stored row.
|
|
192
|
+
*/
|
|
193
|
+
enqueue(input: Parameters<typeof createQueuedOperation>[0]): LocalFirstVfsOperation;
|
|
194
|
+
/**
|
|
195
|
+
* Lists operations that still need remote flush attempts.
|
|
196
|
+
*/
|
|
197
|
+
pending(): LocalFirstVfsOperation[];
|
|
198
|
+
/**
|
|
199
|
+
* Replaces one operation row.
|
|
200
|
+
*/
|
|
201
|
+
update(operation: LocalFirstVfsOperation): LocalFirstVfsOperation;
|
|
202
|
+
/**
|
|
203
|
+
* Returns all operations in insertion order.
|
|
204
|
+
*/
|
|
205
|
+
all(): LocalFirstVfsOperation[];
|
|
206
|
+
}
|
|
207
|
+
//# sourceMappingURL=local-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-cache.d.ts","sourceRoot":"","sources":["../src/local-cache.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,MAAM,sBAAsB,GAC9B,OAAO,GACP,QAAQ,GACR,SAAS,GACT,QAAQ,GACR,QAAQ,GACR,YAAY,CAAC;AACjB,MAAM,MAAM,4BAA4B,GAAG,WAAW,GAAG,MAAM,CAAC;AAEhE,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,4BAA4B,CAAC;IAC3C,SAAS,EAAE,sBAAsB,CAAC;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,sBAAsB;IACrC,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;IAC1C,MAAM,EAAE,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