@milaboratories/pl-mcp-server 54.0.0 → 55.0.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 +15 -25
- package/dist/_virtual/_rolldown/runtime.cjs +22 -0
- package/dist/agent-tables.cjs +116 -0
- package/dist/agent-tables.cjs.map +1 -0
- package/dist/agent-tables.js +115 -0
- package/dist/agent-tables.js.map +1 -0
- package/dist/instructions.cjs +15 -12
- package/dist/instructions.cjs.map +1 -1
- package/dist/instructions.js +15 -12
- package/dist/instructions.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/dist/project-holds.cjs +58 -8
- package/dist/project-holds.cjs.map +1 -1
- package/dist/project-holds.js +58 -8
- package/dist/project-holds.js.map +1 -1
- package/dist/project-list.cjs +16 -0
- package/dist/project-list.cjs.map +1 -0
- package/dist/project-list.js +16 -0
- package/dist/project-list.js.map +1 -0
- package/dist/server-log.cjs +40 -18
- package/dist/server-log.cjs.map +1 -1
- package/dist/server-log.js +40 -19
- package/dist/server-log.js.map +1 -1
- package/dist/server.cjs +48 -18
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.ts +21 -20
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +48 -18
- package/dist/server.js.map +1 -1
- package/dist/tools/agent-tables.cjs +424 -0
- package/dist/tools/agent-tables.cjs.map +1 -0
- package/dist/tools/agent-tables.js +417 -0
- package/dist/tools/agent-tables.js.map +1 -0
- package/dist/tools/await.cjs +216 -73
- package/dist/tools/await.cjs.map +1 -1
- package/dist/tools/await.js +212 -75
- package/dist/tools/await.js.map +1 -1
- package/dist/tools/block-action-context.cjs +3 -0
- package/dist/tools/block-action-context.cjs.map +1 -1
- package/dist/tools/block-action-context.js +3 -0
- package/dist/tools/block-action-context.js.map +1 -1
- package/dist/tools/block-api.cjs +17 -2
- package/dist/tools/block-api.cjs.map +1 -1
- package/dist/tools/block-api.js +17 -3
- package/dist/tools/block-api.js.map +1 -1
- package/dist/tools/block-params.cjs +272 -4
- package/dist/tools/block-params.cjs.map +1 -1
- package/dist/tools/block-params.js +270 -6
- package/dist/tools/block-params.js.map +1 -1
- package/dist/tools/block-state.cjs +323 -42
- package/dist/tools/block-state.cjs.map +1 -1
- package/dist/tools/block-state.js +317 -46
- package/dist/tools/block-state.js.map +1 -1
- package/dist/tools/block-storage.cjs +153 -0
- package/dist/tools/block-storage.cjs.map +1 -0
- package/dist/tools/block-storage.js +147 -0
- package/dist/tools/block-storage.js.map +1 -0
- package/dist/tools/block-updates.cjs +405 -0
- package/dist/tools/block-updates.cjs.map +1 -0
- package/dist/tools/block-updates.js +397 -0
- package/dist/tools/block-updates.js.map +1 -0
- package/dist/tools/blocks.cjs +183 -70
- package/dist/tools/blocks.cjs.map +1 -1
- package/dist/tools/blocks.js +177 -70
- package/dist/tools/blocks.js.map +1 -1
- package/dist/tools/data-query.cjs +451 -113
- package/dist/tools/data-query.cjs.map +1 -1
- package/dist/tools/data-query.js +446 -118
- package/dist/tools/data-query.js.map +1 -1
- package/dist/tools/errors.cjs +21 -0
- package/dist/tools/errors.cjs.map +1 -0
- package/dist/tools/errors.js +20 -0
- package/dist/tools/errors.js.map +1 -0
- package/dist/tools/files.cjs +643 -0
- package/dist/tools/files.cjs.map +1 -0
- package/dist/tools/files.js +613 -0
- package/dist/tools/files.js.map +1 -0
- package/dist/tools/ids.cjs +56 -0
- package/dist/tools/ids.cjs.map +1 -1
- package/dist/tools/ids.js +51 -2
- package/dist/tools/ids.js.map +1 -1
- package/dist/tools/imports.cjs +195 -0
- package/dist/tools/imports.cjs.map +1 -0
- package/dist/tools/imports.js +186 -0
- package/dist/tools/imports.js.map +1 -0
- package/dist/tools/logs.cjs +98 -19
- package/dist/tools/logs.cjs.map +1 -1
- package/dist/tools/logs.js +95 -20
- package/dist/tools/logs.js.map +1 -1
- package/dist/tools/paging.cjs +27 -0
- package/dist/tools/paging.cjs.map +1 -0
- package/dist/tools/paging.js +26 -0
- package/dist/tools/paging.js.map +1 -0
- package/dist/tools/params-merge.cjs +106 -0
- package/dist/tools/params-merge.cjs.map +1 -0
- package/dist/tools/params-merge.js +106 -0
- package/dist/tools/params-merge.js.map +1 -0
- package/dist/tools/project-template.cjs +75 -0
- package/dist/tools/project-template.cjs.map +1 -0
- package/dist/tools/project-template.js +72 -0
- package/dist/tools/project-template.js.map +1 -0
- package/dist/tools/projects.cjs +66 -19
- package/dist/tools/projects.cjs.map +1 -1
- package/dist/tools/projects.js +66 -20
- package/dist/tools/projects.js.map +1 -1
- package/dist/tools/readiness.cjs +104 -0
- package/dist/tools/readiness.cjs.map +1 -0
- package/dist/tools/readiness.js +99 -0
- package/dist/tools/readiness.js.map +1 -0
- package/dist/tools/result-pool.cjs +260 -0
- package/dist/tools/result-pool.cjs.map +1 -0
- package/dist/tools/result-pool.js +252 -0
- package/dist/tools/result-pool.js.map +1 -0
- package/dist/tools/sandbox.cjs +112 -14
- package/dist/tools/sandbox.cjs.map +1 -1
- package/dist/tools/sandbox.js +110 -15
- package/dist/tools/sandbox.js.map +1 -1
- package/dist/tools/sdk-types.cjs +24 -0
- package/dist/tools/sdk-types.cjs.map +1 -0
- package/dist/tools/sdk-types.js +24 -0
- package/dist/tools/sdk-types.js.map +1 -0
- package/dist/tools/settle.cjs +155 -0
- package/dist/tools/settle.cjs.map +1 -0
- package/dist/tools/settle.js +148 -0
- package/dist/tools/settle.js.map +1 -0
- package/dist/tools/tokens.cjs +49 -8
- package/dist/tools/tokens.cjs.map +1 -1
- package/dist/tools/tokens.js +45 -9
- package/dist/tools/tokens.js.map +1 -1
- package/dist/tools/types.cjs +62 -11
- package/dist/tools/types.cjs.map +1 -1
- package/dist/tools/types.js +60 -12
- package/dist/tools/types.js.map +1 -1
- package/dist/tools/value-outline.cjs +119 -0
- package/dist/tools/value-outline.cjs.map +1 -0
- package/dist/tools/value-outline.js +117 -0
- package/dist/tools/value-outline.js.map +1 -0
- package/package.json +9 -8
- package/src/agent-tables.test.ts +246 -0
- package/src/agent-tables.ts +145 -0
- package/src/instructions.ts +15 -12
- package/src/project-holds.test.ts +179 -0
- package/src/project-holds.ts +114 -12
- package/src/project-list.test.ts +38 -0
- package/src/project-list.ts +25 -0
- package/src/server-log.test.ts +54 -1
- package/src/server-log.ts +49 -27
- package/src/server.logging.test.ts +38 -46
- package/src/server.test.ts +151 -17
- package/src/server.ts +62 -34
- package/src/tools/agent-tables.test.ts +650 -0
- package/src/tools/agent-tables.ts +673 -0
- package/src/tools/await.test.ts +287 -0
- package/src/tools/await.ts +393 -123
- package/src/tools/block-action-context.ts +3 -0
- package/src/tools/block-api.ts +19 -4
- package/src/tools/block-params.test.ts +828 -0
- package/src/tools/block-params.ts +623 -8
- package/src/tools/block-state.test.ts +480 -0
- package/src/tools/block-state.ts +659 -66
- package/src/tools/block-storage.test.ts +270 -0
- package/src/tools/block-storage.ts +195 -0
- package/src/tools/block-updates.test.ts +605 -0
- package/src/tools/block-updates.ts +751 -0
- package/src/tools/blocks.test.ts +169 -22
- package/src/tools/blocks.ts +336 -105
- package/src/tools/data-query.test.ts +641 -0
- package/src/tools/data-query.ts +807 -157
- package/src/tools/errors.test.ts +33 -0
- package/src/tools/errors.ts +23 -0
- package/src/tools/files.test.ts +842 -0
- package/src/tools/files.ts +990 -0
- package/src/tools/ids.test.ts +87 -0
- package/src/tools/ids.ts +67 -0
- package/src/tools/imports.ts +304 -0
- package/src/tools/logs.test.ts +70 -0
- package/src/tools/logs.ts +130 -21
- package/src/tools/paging.test.ts +39 -0
- package/src/tools/paging.ts +39 -0
- package/src/tools/params-merge.test.ts +274 -0
- package/src/tools/params-merge.ts +149 -0
- package/src/tools/project-template.test.ts +230 -0
- package/src/tools/project-template.ts +135 -0
- package/src/tools/projects.test.ts +122 -0
- package/src/tools/projects.ts +135 -25
- package/src/tools/readiness.test.ts +195 -0
- package/src/tools/readiness.ts +189 -0
- package/src/tools/result-pool.test.ts +377 -0
- package/src/tools/result-pool.ts +483 -0
- package/src/tools/sandbox.test.ts +128 -10
- package/src/tools/sandbox.ts +132 -18
- package/src/tools/sdk-types.ts +54 -0
- package/src/tools/settle.test.ts +340 -0
- package/src/tools/settle.ts +312 -0
- package/src/tools/tokens.ts +74 -9
- package/src/tools/types.ts +77 -12
- package/src/tools/value-outline.ts +143 -0
- package/dist/tools/screenshot.cjs +0 -44
- package/dist/tools/screenshot.cjs.map +0 -1
- package/dist/tools/screenshot.js +0 -44
- package/dist/tools/screenshot.js.map +0 -1
- package/dist/tools/ui-interaction.cjs +0 -140
- package/dist/tools/ui-interaction.cjs.map +0 -1
- package/dist/tools/ui-interaction.js +0 -140
- package/dist/tools/ui-interaction.js.map +0 -1
- package/src/tools/screenshot.ts +0 -61
- package/src/tools/ui-interaction.ts +0 -184
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
const require_value_outline = require("./value-outline.cjs");
|
|
2
|
+
const require_ids = require("./ids.cjs");
|
|
3
|
+
const require_tokens = require("./tokens.cjs");
|
|
4
|
+
const require_imports = require("./imports.cjs");
|
|
5
|
+
let _milaboratories_helpers = require("@milaboratories/helpers");
|
|
6
|
+
let node_util = require("node:util");
|
|
7
|
+
let _platforma_sdk_model = require("@platforma-sdk/model");
|
|
8
|
+
/** The most characters of a value a reported change carries; a larger one is given by its size. */
|
|
9
|
+
const CHANGE_VALUE_CHARS = 200;
|
|
10
|
+
/** The stored `__dataVersion` of `entry`. */
|
|
11
|
+
function dataVersionOf(entry) {
|
|
12
|
+
if (!(0, _milaboratories_helpers.isPlainObject)(entry)) return void 0;
|
|
13
|
+
const version = entry.__dataVersion;
|
|
14
|
+
return typeof version === "string" || typeof version === "number" ? version : void 0;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Reads a block's raw storage (`blockStorage` of the block state) through the SDK's
|
|
18
|
+
* `normalizeBlockStorage`: the data, and the data of every plugin the block registers. Storage in
|
|
19
|
+
* another format (a block that has not written any yet) is read as the data itself, as the SDK
|
|
20
|
+
* does, with no version. Data versions are read as stored ({@link DataVersion}).
|
|
21
|
+
*/
|
|
22
|
+
function readStorageView(rawStorage) {
|
|
23
|
+
if (!(0, _platforma_sdk_model.isBlockStorage)(rawStorage)) return {
|
|
24
|
+
dataVersion: void 0,
|
|
25
|
+
data: rawStorage,
|
|
26
|
+
plugins: {}
|
|
27
|
+
};
|
|
28
|
+
const storage = (0, _platforma_sdk_model.normalizeBlockStorage)(rawStorage);
|
|
29
|
+
const stored = new Map(Object.entries(storage.__plugins ?? {}));
|
|
30
|
+
const plugins = Object.fromEntries(Object.entries(storage.__pluginRegistry ?? {}).map(([handle, name]) => {
|
|
31
|
+
const entry = stored.get(handle);
|
|
32
|
+
const plugin = {
|
|
33
|
+
name: require_ids.asPluginName(String(name)),
|
|
34
|
+
dataVersion: dataVersionOf(entry),
|
|
35
|
+
data: (0, _milaboratories_helpers.isPlainObject)(entry) ? entry.__data : void 0
|
|
36
|
+
};
|
|
37
|
+
return [require_ids.asPluginHandle(handle), plugin];
|
|
38
|
+
}));
|
|
39
|
+
return {
|
|
40
|
+
dataVersion: dataVersionOf(rawStorage),
|
|
41
|
+
data: storage.__data,
|
|
42
|
+
plugins
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* `obj[key]` when `key` is a key of `obj` itself; `undefined` for a key it only inherits
|
|
47
|
+
* (`toString`, `constructor`, `__proto__`), so a name an agent gives never finds one of those.
|
|
48
|
+
*/
|
|
49
|
+
function ownValue(obj, key) {
|
|
50
|
+
return Object.hasOwn(obj, key) ? obj[key] : void 0;
|
|
51
|
+
}
|
|
52
|
+
/** The plugin `handle` of a block's storage; `undefined` when the block registers no such plugin. */
|
|
53
|
+
function pluginOf(storage, handle) {
|
|
54
|
+
return Object.hasOwn(storage.plugins, handle) ? storage.plugins[handle] : void 0;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The shared block view: data, plugin data, the output summary and, when the outputs carry import
|
|
58
|
+
* progress, the imports summary. Built from stored fields; nothing is run.
|
|
59
|
+
*
|
|
60
|
+
* @param state the block state: its raw storage and outputs
|
|
61
|
+
*/
|
|
62
|
+
function blockView(state) {
|
|
63
|
+
const rawOutputs = (0, _milaboratories_helpers.isPlainObject)(state.outputs) ? state.outputs : void 0;
|
|
64
|
+
const outputs = require_tokens.outputsView(rawOutputs);
|
|
65
|
+
const imports = require_imports.importsOf(rawOutputs);
|
|
66
|
+
const storage = readStorageView(state.blockStorage);
|
|
67
|
+
const view = {
|
|
68
|
+
dataVersion: storage.dataVersion,
|
|
69
|
+
data: storage.data,
|
|
70
|
+
...outputs,
|
|
71
|
+
...imports !== void 0 ? { imports } : {}
|
|
72
|
+
};
|
|
73
|
+
const plugins = Object.entries(storage.plugins);
|
|
74
|
+
if (plugins.length > 0) view.plugins = Object.fromEntries(plugins.map(([handle, p]) => [handle, {
|
|
75
|
+
name: p.name,
|
|
76
|
+
dataVersion: p.dataVersion,
|
|
77
|
+
data: p.data
|
|
78
|
+
}]));
|
|
79
|
+
return view;
|
|
80
|
+
}
|
|
81
|
+
/** The top-level keys of `before` that `after` does not have. Both are read as JSON objects. */
|
|
82
|
+
function missingTopLevelKeys(before, after) {
|
|
83
|
+
if (!(0, _milaboratories_helpers.isPlainObject)(before)) return [];
|
|
84
|
+
const kept = (0, _milaboratories_helpers.isPlainObject)(after) ? after : {};
|
|
85
|
+
return Object.keys(before).filter((k) => before[k] !== void 0 && ownValue(kept, k) === void 0);
|
|
86
|
+
}
|
|
87
|
+
const IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
88
|
+
/** The path of `key` under `path`, in the form of {@link ValueChange.path}. */
|
|
89
|
+
function childPath(path, key) {
|
|
90
|
+
if (IDENTIFIER.test(key)) return path === "" ? key : `${path}.${key}`;
|
|
91
|
+
return `${path}[${JSON.stringify(key)}]`;
|
|
92
|
+
}
|
|
93
|
+
function small(value) {
|
|
94
|
+
const chars = require_value_outline.jsonChars(value);
|
|
95
|
+
return chars <= CHANGE_VALUE_CHARS ? value : { chars };
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The paths where `after` differs from `before`, down to the leaves: objects key by key, arrays
|
|
99
|
+
* index by index. Reports at most `limit` paths and counts the rest.
|
|
100
|
+
*/
|
|
101
|
+
function diffValues(before, after, limit = 50) {
|
|
102
|
+
const changes = [];
|
|
103
|
+
let more = 0;
|
|
104
|
+
const push = (change) => {
|
|
105
|
+
if (changes.length < limit) changes.push({
|
|
106
|
+
...change,
|
|
107
|
+
path: change.path || "(root)"
|
|
108
|
+
});
|
|
109
|
+
else more++;
|
|
110
|
+
};
|
|
111
|
+
function walk(path, a, b) {
|
|
112
|
+
if ((0, node_util.isDeepStrictEqual)(a, b)) return;
|
|
113
|
+
if (a === void 0) return push({
|
|
114
|
+
path,
|
|
115
|
+
op: "add",
|
|
116
|
+
to: small(b)
|
|
117
|
+
});
|
|
118
|
+
if (b === void 0) return push({
|
|
119
|
+
path,
|
|
120
|
+
op: "remove",
|
|
121
|
+
from: small(a)
|
|
122
|
+
});
|
|
123
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
124
|
+
for (let i = 0; i < Math.max(a.length, b.length); i++) walk(`${path}[${i}]`, i < a.length ? a[i] : void 0, i < b.length ? b[i] : void 0);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if ((0, _milaboratories_helpers.isPlainObject)(a) && (0, _milaboratories_helpers.isPlainObject)(b)) {
|
|
128
|
+
const keys = /* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)]);
|
|
129
|
+
for (const key of keys) walk(childPath(path, key), ownValue(a, key), ownValue(b, key));
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
push({
|
|
133
|
+
path,
|
|
134
|
+
op: "replace",
|
|
135
|
+
from: small(a),
|
|
136
|
+
to: small(b)
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
walk("", before, after);
|
|
140
|
+
return more > 0 ? {
|
|
141
|
+
changes,
|
|
142
|
+
moreChanges: more
|
|
143
|
+
} : { changes };
|
|
144
|
+
}
|
|
145
|
+
exports.blockView = blockView;
|
|
146
|
+
exports.childPath = childPath;
|
|
147
|
+
exports.diffValues = diffValues;
|
|
148
|
+
exports.missingTopLevelKeys = missingTopLevelKeys;
|
|
149
|
+
exports.ownValue = ownValue;
|
|
150
|
+
exports.pluginOf = pluginOf;
|
|
151
|
+
exports.readStorageView = readStorageView;
|
|
152
|
+
|
|
153
|
+
//# sourceMappingURL=block-storage.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block-storage.cjs","names":["isPlainObject","isBlockStorage","normalizeBlockStorage","asPluginName","asPluginHandle","outputsView","importsOf","jsonChars","isDeepStrictEqual"],"sources":["../../src/tools/block-storage.ts"],"sourcesContent":["import { isDeepStrictEqual } from \"node:util\";\nimport type { PluginHandle, PluginName } from \"@platforma-sdk/model\";\nimport { isBlockStorage, normalizeBlockStorage } from \"@platforma-sdk/model\";\nimport { isPlainObject } from \"@milaboratories/helpers\";\nimport { importsOf, type ImportsSummary } from \"./imports\";\nimport { outputsView, type OutputsView } from \"./tokens\";\nimport { jsonChars } from \"./value-outline\";\nimport { asPluginHandle, asPluginName } from \"./ids\";\n\n/** The most changed paths a write reports. */\nexport const MAX_CHANGES = 50;\n\n/** The most characters of a value a reported change carries; a larger one is given by its size. */\nconst CHANGE_VALUE_CHARS = 200;\n\n/**\n * The version of a block's or a plugin's data model, as stored: a string; a number in storage\n * written by early SDK releases, shown as it is (the SDK's `normalizeBlockStorage` replaces it\n * with its legacy marker, which says less).\n */\nexport type DataVersion = string | number | undefined;\n\n/** The stored `__dataVersion` of `entry`. */\nfunction dataVersionOf(entry: unknown): DataVersion {\n if (!isPlainObject(entry)) return undefined;\n const version = entry.__dataVersion;\n return typeof version === \"string\" || typeof version === \"number\" ? version : undefined;\n}\n\n/** The data of one plugin of a block. */\nexport type PluginStorage = {\n /** The plugin type (its globally unique name). */\n name: PluginName;\n dataVersion: DataVersion;\n data: unknown;\n};\n\n/** What a block keeps in its storage, read without running its model. */\nexport type StorageView = {\n dataVersion: DataVersion;\n data: unknown;\n /** Plugin handle → its data; plugins the block registers, nothing else. */\n plugins: Record<PluginHandle, PluginStorage>;\n};\n\n/**\n * Reads a block's raw storage (`blockStorage` of the block state) through the SDK's\n * `normalizeBlockStorage`: the data, and the data of every plugin the block registers. Storage in\n * another format (a block that has not written any yet) is read as the data itself, as the SDK\n * does, with no version. Data versions are read as stored ({@link DataVersion}).\n */\nexport function readStorageView(rawStorage: unknown): StorageView {\n if (!isBlockStorage(rawStorage)) return { dataVersion: undefined, data: rawStorage, plugins: {} };\n const storage = normalizeBlockStorage(rawStorage);\n const stored = new Map<string, unknown>(Object.entries(storage.__plugins ?? {}));\n // `Object.fromEntries` defines own keys, so a handle such as `__proto__` stays a key.\n const plugins: Record<PluginHandle, PluginStorage> = Object.fromEntries(\n Object.entries(storage.__pluginRegistry ?? {}).map(([handle, name]) => {\n const entry = stored.get(handle);\n const plugin: PluginStorage = {\n name: asPluginName(String(name)),\n dataVersion: dataVersionOf(entry),\n data: isPlainObject(entry) ? entry.__data : undefined,\n };\n return [asPluginHandle(handle), plugin];\n }),\n );\n return { dataVersion: dataVersionOf(rawStorage), data: storage.__data, plugins };\n}\n\n/**\n * `obj[key]` when `key` is a key of `obj` itself; `undefined` for a key it only inherits\n * (`toString`, `constructor`, `__proto__`), so a name an agent gives never finds one of those.\n */\nexport function ownValue(obj: Record<string, unknown>, key: string): unknown {\n return Object.hasOwn(obj, key) ? obj[key] : undefined;\n}\n\n/** The plugin `handle` of a block's storage; `undefined` when the block registers no such plugin. */\nexport function pluginOf(storage: StorageView, handle: PluginHandle): PluginStorage | undefined {\n return Object.hasOwn(storage.plugins, handle) ? storage.plugins[handle] : undefined;\n}\n\n/** One block as every block tool shows it. */\nexport type BlockView = {\n dataVersion: DataVersion;\n data: unknown;\n plugins?: Record<string, { name: string; dataVersion: DataVersion; data: unknown }>;\n /** The files the block imports, when its outputs carry import progress. */\n imports?: ImportsSummary;\n} & OutputsView;\n\n/**\n * The shared block view: data, plugin data, the output summary and, when the outputs carry import\n * progress, the imports summary. Built from stored fields; nothing is run.\n *\n * @param state the block state: its raw storage and outputs\n */\nexport function blockView(state: { blockStorage: unknown; outputs?: unknown }): BlockView {\n const rawOutputs = isPlainObject(state.outputs) ? state.outputs : undefined;\n const outputs = outputsView(rawOutputs);\n const imports = importsOf(rawOutputs);\n const storage = readStorageView(state.blockStorage);\n const view: BlockView = {\n dataVersion: storage.dataVersion,\n data: storage.data,\n ...outputs,\n ...(imports !== undefined ? { imports } : {}),\n };\n const plugins = Object.entries(storage.plugins);\n if (plugins.length > 0)\n view.plugins = Object.fromEntries(\n plugins.map(([handle, p]) => [\n handle,\n { name: p.name, dataVersion: p.dataVersion, data: p.data },\n ]),\n );\n return view;\n}\n\n/** The top-level keys of `before` that `after` does not have. Both are read as JSON objects. */\nexport function missingTopLevelKeys(before: unknown, after: unknown): string[] {\n if (!isPlainObject(before)) return [];\n const kept = isPlainObject(after) ? after : {};\n return Object.keys(before).filter(\n (k) => before[k] !== undefined && ownValue(kept, k) === undefined,\n );\n}\n\n/** One changed path of a write. */\nexport type ValueChange = {\n /**\n * `a.b[2].c`; keys that are not identifiers in brackets: `a[\"key with space\"]`; `(root)` for the\n * value as a whole.\n */\n path: string;\n op: \"add\" | \"remove\" | \"replace\";\n /** The old value, when it is small; otherwise its size as `{chars: N}`. */\n from?: unknown;\n /** The new value, when it is small; otherwise its size as `{chars: N}`. */\n to?: unknown;\n};\n\n/** The changes between two values, at most `limit` of them. */\nexport type ValueDiff = {\n changes: ValueChange[];\n /** How many more changed paths there are past `changes`. */\n moreChanges?: number;\n};\n\nconst IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;\n\n/** The path of `key` under `path`, in the form of {@link ValueChange.path}. */\nexport function childPath(path: string, key: string): string {\n if (IDENTIFIER.test(key)) return path === \"\" ? key : `${path}.${key}`;\n return `${path}[${JSON.stringify(key)}]`;\n}\n\nfunction small(value: unknown): unknown {\n const chars = jsonChars(value);\n return chars <= CHANGE_VALUE_CHARS ? value : { chars };\n}\n\n/**\n * The paths where `after` differs from `before`, down to the leaves: objects key by key, arrays\n * index by index. Reports at most `limit` paths and counts the rest.\n */\nexport function diffValues(before: unknown, after: unknown, limit = MAX_CHANGES): ValueDiff {\n const changes: ValueChange[] = [];\n let more = 0;\n const push = (change: ValueChange) => {\n if (changes.length < limit) changes.push({ ...change, path: change.path || \"(root)\" });\n else more++;\n };\n\n function walk(path: string, a: unknown, b: unknown): void {\n if (isDeepStrictEqual(a, b)) return;\n if (a === undefined) return push({ path, op: \"add\", to: small(b) });\n if (b === undefined) return push({ path, op: \"remove\", from: small(a) });\n if (Array.isArray(a) && Array.isArray(b)) {\n for (let i = 0; i < Math.max(a.length, b.length); i++)\n walk(`${path}[${i}]`, i < a.length ? a[i] : undefined, i < b.length ? b[i] : undefined);\n return;\n }\n if (isPlainObject(a) && isPlainObject(b)) {\n const keys = new Set([...Object.keys(a), ...Object.keys(b)]);\n for (const key of keys) walk(childPath(path, key), ownValue(a, key), ownValue(b, key));\n return;\n }\n push({ path, op: \"replace\", from: small(a), to: small(b) });\n }\n\n walk(\"\", before, after);\n return more > 0 ? { changes, moreChanges: more } : { changes };\n}\n"],"mappings":";;;;;;;;AAaA,MAAM,qBAAqB;;AAU3B,SAAS,cAAc,OAA6B;CAClD,IAAI,EAAA,GAACA,wBAAAA,cAAAA,CAAc,KAAK,GAAG,OAAO,KAAA;CAClC,MAAM,UAAU,MAAM;CACtB,OAAO,OAAO,YAAY,YAAY,OAAO,YAAY,WAAW,UAAU,KAAA;AAChF;;;;;;;AAwBA,SAAgB,gBAAgB,YAAkC;CAChE,IAAI,EAAA,GAACC,qBAAAA,eAAAA,CAAe,UAAU,GAAG,OAAO;EAAE,aAAa,KAAA;EAAW,MAAM;EAAY,SAAS,CAAC;CAAE;CAChG,MAAM,WAAA,GAAUC,qBAAAA,sBAAAA,CAAsB,U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;GAAU,MAAM,MAAM,CAAC;EAAE,CAAC;EACvE,IAAI,MAAM,QAAQ,CAAC,KAAK,MAAM,QAAQ,CAAC,GAAG;GACxC,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,KAChD,KAAK,GAAG,KAAK,GAAG,EAAE,IAAI,IAAI,EAAE,SAAS,EAAE,KAAK,KAAA,GAAW,IAAI,EAAE,SAAS,EAAE,KAAK,KAAA,CAAS;GACxF;EACF;EACA,KAAA,GAAIR,wBAAAA,cAAAA,CAAc,CAAC,MAAA,GAAKA,wBAAAA,cAAAA,CAAc,CAAC,GAAG;GACxC,MAAM,uBAAO,IAAI,IAAI,CAAC,GAAG,OAAO,KAAK,CAAC,GAAG,GAAG,OAAO,KAAK,CAAC,CAAC,CAAC;GAC3D,KAAK,MAAM,OAAO,MAAM,KAAK,UAAU,MAAM,GAAG,GAAG,SAAS,GAAG,GAAG,GAAG,SAAS,GAAG,GAAG,CAAC;GACrF;EACF;EACA,KAAK;GAAE;GAAM,IAAI;GAAW,MAAM,MAAM,CAAC;GAAG,IAAI,MAAM,CAAC;EAAE,CAAC;CAC5D;CAEA,KAAK,IAAI,QAAQ,KAAK;CACtB,OAAO,OAAO,IAAI;EAAE;EAAS,aAAa;CAAK,IAAI,EAAE,QAAQ;AAC/D"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { jsonChars } from "./value-outline.js";
|
|
2
|
+
import { asPluginHandle, asPluginName } from "./ids.js";
|
|
3
|
+
import { outputsView } from "./tokens.js";
|
|
4
|
+
import { importsOf } from "./imports.js";
|
|
5
|
+
import { isPlainObject } from "@milaboratories/helpers";
|
|
6
|
+
import { isDeepStrictEqual } from "node:util";
|
|
7
|
+
import { isBlockStorage, normalizeBlockStorage } from "@platforma-sdk/model";
|
|
8
|
+
/** The most characters of a value a reported change carries; a larger one is given by its size. */
|
|
9
|
+
const CHANGE_VALUE_CHARS = 200;
|
|
10
|
+
/** The stored `__dataVersion` of `entry`. */
|
|
11
|
+
function dataVersionOf(entry) {
|
|
12
|
+
if (!isPlainObject(entry)) return void 0;
|
|
13
|
+
const version = entry.__dataVersion;
|
|
14
|
+
return typeof version === "string" || typeof version === "number" ? version : void 0;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Reads a block's raw storage (`blockStorage` of the block state) through the SDK's
|
|
18
|
+
* `normalizeBlockStorage`: the data, and the data of every plugin the block registers. Storage in
|
|
19
|
+
* another format (a block that has not written any yet) is read as the data itself, as the SDK
|
|
20
|
+
* does, with no version. Data versions are read as stored ({@link DataVersion}).
|
|
21
|
+
*/
|
|
22
|
+
function readStorageView(rawStorage) {
|
|
23
|
+
if (!isBlockStorage(rawStorage)) return {
|
|
24
|
+
dataVersion: void 0,
|
|
25
|
+
data: rawStorage,
|
|
26
|
+
plugins: {}
|
|
27
|
+
};
|
|
28
|
+
const storage = normalizeBlockStorage(rawStorage);
|
|
29
|
+
const stored = new Map(Object.entries(storage.__plugins ?? {}));
|
|
30
|
+
const plugins = Object.fromEntries(Object.entries(storage.__pluginRegistry ?? {}).map(([handle, name]) => {
|
|
31
|
+
const entry = stored.get(handle);
|
|
32
|
+
const plugin = {
|
|
33
|
+
name: asPluginName(String(name)),
|
|
34
|
+
dataVersion: dataVersionOf(entry),
|
|
35
|
+
data: isPlainObject(entry) ? entry.__data : void 0
|
|
36
|
+
};
|
|
37
|
+
return [asPluginHandle(handle), plugin];
|
|
38
|
+
}));
|
|
39
|
+
return {
|
|
40
|
+
dataVersion: dataVersionOf(rawStorage),
|
|
41
|
+
data: storage.__data,
|
|
42
|
+
plugins
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* `obj[key]` when `key` is a key of `obj` itself; `undefined` for a key it only inherits
|
|
47
|
+
* (`toString`, `constructor`, `__proto__`), so a name an agent gives never finds one of those.
|
|
48
|
+
*/
|
|
49
|
+
function ownValue(obj, key) {
|
|
50
|
+
return Object.hasOwn(obj, key) ? obj[key] : void 0;
|
|
51
|
+
}
|
|
52
|
+
/** The plugin `handle` of a block's storage; `undefined` when the block registers no such plugin. */
|
|
53
|
+
function pluginOf(storage, handle) {
|
|
54
|
+
return Object.hasOwn(storage.plugins, handle) ? storage.plugins[handle] : void 0;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The shared block view: data, plugin data, the output summary and, when the outputs carry import
|
|
58
|
+
* progress, the imports summary. Built from stored fields; nothing is run.
|
|
59
|
+
*
|
|
60
|
+
* @param state the block state: its raw storage and outputs
|
|
61
|
+
*/
|
|
62
|
+
function blockView(state) {
|
|
63
|
+
const rawOutputs = isPlainObject(state.outputs) ? state.outputs : void 0;
|
|
64
|
+
const outputs = outputsView(rawOutputs);
|
|
65
|
+
const imports = importsOf(rawOutputs);
|
|
66
|
+
const storage = readStorageView(state.blockStorage);
|
|
67
|
+
const view = {
|
|
68
|
+
dataVersion: storage.dataVersion,
|
|
69
|
+
data: storage.data,
|
|
70
|
+
...outputs,
|
|
71
|
+
...imports !== void 0 ? { imports } : {}
|
|
72
|
+
};
|
|
73
|
+
const plugins = Object.entries(storage.plugins);
|
|
74
|
+
if (plugins.length > 0) view.plugins = Object.fromEntries(plugins.map(([handle, p]) => [handle, {
|
|
75
|
+
name: p.name,
|
|
76
|
+
dataVersion: p.dataVersion,
|
|
77
|
+
data: p.data
|
|
78
|
+
}]));
|
|
79
|
+
return view;
|
|
80
|
+
}
|
|
81
|
+
/** The top-level keys of `before` that `after` does not have. Both are read as JSON objects. */
|
|
82
|
+
function missingTopLevelKeys(before, after) {
|
|
83
|
+
if (!isPlainObject(before)) return [];
|
|
84
|
+
const kept = isPlainObject(after) ? after : {};
|
|
85
|
+
return Object.keys(before).filter((k) => before[k] !== void 0 && ownValue(kept, k) === void 0);
|
|
86
|
+
}
|
|
87
|
+
const IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
88
|
+
/** The path of `key` under `path`, in the form of {@link ValueChange.path}. */
|
|
89
|
+
function childPath(path, key) {
|
|
90
|
+
if (IDENTIFIER.test(key)) return path === "" ? key : `${path}.${key}`;
|
|
91
|
+
return `${path}[${JSON.stringify(key)}]`;
|
|
92
|
+
}
|
|
93
|
+
function small(value) {
|
|
94
|
+
const chars = jsonChars(value);
|
|
95
|
+
return chars <= CHANGE_VALUE_CHARS ? value : { chars };
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The paths where `after` differs from `before`, down to the leaves: objects key by key, arrays
|
|
99
|
+
* index by index. Reports at most `limit` paths and counts the rest.
|
|
100
|
+
*/
|
|
101
|
+
function diffValues(before, after, limit = 50) {
|
|
102
|
+
const changes = [];
|
|
103
|
+
let more = 0;
|
|
104
|
+
const push = (change) => {
|
|
105
|
+
if (changes.length < limit) changes.push({
|
|
106
|
+
...change,
|
|
107
|
+
path: change.path || "(root)"
|
|
108
|
+
});
|
|
109
|
+
else more++;
|
|
110
|
+
};
|
|
111
|
+
function walk(path, a, b) {
|
|
112
|
+
if (isDeepStrictEqual(a, b)) return;
|
|
113
|
+
if (a === void 0) return push({
|
|
114
|
+
path,
|
|
115
|
+
op: "add",
|
|
116
|
+
to: small(b)
|
|
117
|
+
});
|
|
118
|
+
if (b === void 0) return push({
|
|
119
|
+
path,
|
|
120
|
+
op: "remove",
|
|
121
|
+
from: small(a)
|
|
122
|
+
});
|
|
123
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
124
|
+
for (let i = 0; i < Math.max(a.length, b.length); i++) walk(`${path}[${i}]`, i < a.length ? a[i] : void 0, i < b.length ? b[i] : void 0);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (isPlainObject(a) && isPlainObject(b)) {
|
|
128
|
+
const keys = /* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)]);
|
|
129
|
+
for (const key of keys) walk(childPath(path, key), ownValue(a, key), ownValue(b, key));
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
push({
|
|
133
|
+
path,
|
|
134
|
+
op: "replace",
|
|
135
|
+
from: small(a),
|
|
136
|
+
to: small(b)
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
walk("", before, after);
|
|
140
|
+
return more > 0 ? {
|
|
141
|
+
changes,
|
|
142
|
+
moreChanges: more
|
|
143
|
+
} : { changes };
|
|
144
|
+
}
|
|
145
|
+
export { blockView, childPath, diffValues, missingTopLevelKeys, ownValue, pluginOf, readStorageView };
|
|
146
|
+
|
|
147
|
+
//# sourceMappingURL=block-storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block-storage.js","names":[],"sources":["../../src/tools/block-storage.ts"],"sourcesContent":["import { isDeepStrictEqual } from \"node:util\";\nimport type { PluginHandle, PluginName } from \"@platforma-sdk/model\";\nimport { isBlockStorage, normalizeBlockStorage } from \"@platforma-sdk/model\";\nimport { isPlainObject } from \"@milaboratories/helpers\";\nimport { importsOf, type ImportsSummary } from \"./imports\";\nimport { outputsView, type OutputsView } from \"./tokens\";\nimport { jsonChars } from \"./value-outline\";\nimport { asPluginHandle, asPluginName } from \"./ids\";\n\n/** The most changed paths a write reports. */\nexport const MAX_CHANGES = 50;\n\n/** The most characters of a value a reported change carries; a larger one is given by its size. */\nconst CHANGE_VALUE_CHARS = 200;\n\n/**\n * The version of a block's or a plugin's data model, as stored: a string; a number in storage\n * written by early SDK releases, shown as it is (the SDK's `normalizeBlockStorage` replaces it\n * with its legacy marker, which says less).\n */\nexport type DataVersion = string | number | undefined;\n\n/** The stored `__dataVersion` of `entry`. */\nfunction dataVersionOf(entry: unknown): DataVersion {\n if (!isPlainObject(entry)) return undefined;\n const version = entry.__dataVersion;\n return typeof version === \"string\" || typeof version === \"number\" ? version : undefined;\n}\n\n/** The data of one plugin of a block. */\nexport type PluginStorage = {\n /** The plugin type (its globally unique name). */\n name: PluginName;\n dataVersion: DataVersion;\n data: unknown;\n};\n\n/** What a block keeps in its storage, read without running its model. */\nexport type StorageView = {\n dataVersion: DataVersion;\n data: unknown;\n /** Plugin handle → its data; plugins the block registers, nothing else. */\n plugins: Record<PluginHandle, PluginStorage>;\n};\n\n/**\n * Reads a block's raw storage (`blockStorage` of the block state) through the SDK's\n * `normalizeBlockStorage`: the data, and the data of every plugin the block registers. Storage in\n * another format (a block that has not written any yet) is read as the data itself, as the SDK\n * does, with no version. Data versions are read as stored ({@link DataVersion}).\n */\nexport function readStorageView(rawStorage: unknown): StorageView {\n if (!isBlockStorage(rawStorage)) return { dataVersion: undefined, data: rawStorage, plugins: {} };\n const storage = normalizeBlockStorage(rawStorage);\n const stored = new Map<string, unknown>(Object.entries(storage.__plugins ?? {}));\n // `Object.fromEntries` defines own keys, so a handle such as `__proto__` stays a key.\n const plugins: Record<PluginHandle, PluginStorage> = Object.fromEntries(\n Object.entries(storage.__pluginRegistry ?? {}).map(([handle, name]) => {\n const entry = stored.get(handle);\n const plugin: PluginStorage = {\n name: asPluginName(String(name)),\n dataVersion: dataVersionOf(entry),\n data: isPlainObject(entry) ? entry.__data : undefined,\n };\n return [asPluginHandle(handle), plugin];\n }),\n );\n return { dataVersion: dataVersionOf(rawStorage), data: storage.__data, plugins };\n}\n\n/**\n * `obj[key]` when `key` is a key of `obj` itself; `undefined` for a key it only inherits\n * (`toString`, `constructor`, `__proto__`), so a name an agent gives never finds one of those.\n */\nexport function ownValue(obj: Record<string, unknown>, key: string): unknown {\n return Object.hasOwn(obj, key) ? obj[key] : undefined;\n}\n\n/** The plugin `handle` of a block's storage; `undefined` when the block registers no such plugin. */\nexport function pluginOf(storage: StorageView, handle: PluginHandle): PluginStorage | undefined {\n return Object.hasOwn(storage.plugins, handle) ? storage.plugins[handle] : undefined;\n}\n\n/** One block as every block tool shows it. */\nexport type BlockView = {\n dataVersion: DataVersion;\n data: unknown;\n plugins?: Record<string, { name: string; dataVersion: DataVersion; data: unknown }>;\n /** The files the block imports, when its outputs carry import progress. */\n imports?: ImportsSummary;\n} & OutputsView;\n\n/**\n * The shared block view: data, plugin data, the output summary and, when the outputs carry import\n * progress, the imports summary. Built from stored fields; nothing is run.\n *\n * @param state the block state: its raw storage and outputs\n */\nexport function blockView(state: { blockStorage: unknown; outputs?: unknown }): BlockView {\n const rawOutputs = isPlainObject(state.outputs) ? state.outputs : undefined;\n const outputs = outputsView(rawOutputs);\n const imports = importsOf(rawOutputs);\n const storage = readStorageView(state.blockStorage);\n const view: BlockView = {\n dataVersion: storage.dataVersion,\n data: storage.data,\n ...outputs,\n ...(imports !== undefined ? { imports } : {}),\n };\n const plugins = Object.entries(storage.plugins);\n if (plugins.length > 0)\n view.plugins = Object.fromEntries(\n plugins.map(([handle, p]) => [\n handle,\n { name: p.name, dataVersion: p.dataVersion, data: p.data },\n ]),\n );\n return view;\n}\n\n/** The top-level keys of `before` that `after` does not have. Both are read as JSON objects. */\nexport function missingTopLevelKeys(before: unknown, after: unknown): string[] {\n if (!isPlainObject(before)) return [];\n const kept = isPlainObject(after) ? after : {};\n return Object.keys(before).filter(\n (k) => before[k] !== undefined && ownValue(kept, k) === undefined,\n );\n}\n\n/** One changed path of a write. */\nexport type ValueChange = {\n /**\n * `a.b[2].c`; keys that are not identifiers in brackets: `a[\"key with space\"]`; `(root)` for the\n * value as a whole.\n */\n path: string;\n op: \"add\" | \"remove\" | \"replace\";\n /** The old value, when it is small; otherwise its size as `{chars: N}`. */\n from?: unknown;\n /** The new value, when it is small; otherwise its size as `{chars: N}`. */\n to?: unknown;\n};\n\n/** The changes between two values, at most `limit` of them. */\nexport type ValueDiff = {\n changes: ValueChange[];\n /** How many more changed paths there are past `changes`. */\n moreChanges?: number;\n};\n\nconst IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;\n\n/** The path of `key` under `path`, in the form of {@link ValueChange.path}. */\nexport function childPath(path: string, key: string): string {\n if (IDENTIFIER.test(key)) return path === \"\" ? key : `${path}.${key}`;\n return `${path}[${JSON.stringify(key)}]`;\n}\n\nfunction small(value: unknown): unknown {\n const chars = jsonChars(value);\n return chars <= CHANGE_VALUE_CHARS ? value : { chars };\n}\n\n/**\n * The paths where `after` differs from `before`, down to the leaves: objects key by key, arrays\n * index by index. Reports at most `limit` paths and counts the rest.\n */\nexport function diffValues(before: unknown, after: unknown, limit = MAX_CHANGES): ValueDiff {\n const changes: ValueChange[] = [];\n let more = 0;\n const push = (change: ValueChange) => {\n if (changes.length < limit) changes.push({ ...change, path: change.path || \"(root)\" });\n else more++;\n };\n\n function walk(path: string, a: unknown, b: unknown): void {\n if (isDeepStrictEqual(a, b)) return;\n if (a === undefined) return push({ path, op: \"add\", to: small(b) });\n if (b === undefined) return push({ path, op: \"remove\", from: small(a) });\n if (Array.isArray(a) && Array.isArray(b)) {\n for (let i = 0; i < Math.max(a.length, b.length); i++)\n walk(`${path}[${i}]`, i < a.length ? a[i] : undefined, i < b.length ? b[i] : undefined);\n return;\n }\n if (isPlainObject(a) && isPlainObject(b)) {\n const keys = new Set([...Object.keys(a), ...Object.keys(b)]);\n for (const key of keys) walk(childPath(path, key), ownValue(a, key), ownValue(b, key));\n return;\n }\n push({ path, op: \"replace\", from: small(a), to: small(b) });\n }\n\n walk(\"\", before, after);\n return more > 0 ? { changes, moreChanges: more } : { changes };\n}\n"],"mappings":";;;;;;;;AAaA,MAAM,qBAAqB;;AAU3B,SAAS,cAAc,OAA6B;CAClD,IAAI,CAAC,cAAc,KAAK,GAAG,OAAO,KAAA;CAClC,MAAM,UAAU,MAAM;CACtB,OAAO,OAAO,YAAY,YAAY,OAAO,YAAY,WAAW,UAAU,KAAA;AAChF;;;;;;;AAwBA,SAAgB,gBAAgB,YAAkC;CAChE,IAAI,CAAC,eAAe,UAAU,GAAG,OAAO;EAAE,aAAa,KAAA;EAAW,MAAM;EAAY,SAAS,CAAC;CAAE;CAChG,MAAM,UAAU,sBAAsB,UAAU;CAChD,MAAM,SAAS,IAAI,IAAqB,OAAO,QAAQ,QAAQ,aAAa,CAAC,CAAC,CAAC;CAE/E,MAAM,UAA+C,OAAO,YAC1D,OAA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