@superdoc-dev/sdk 1.19.1 → 1.20.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/dist/action-primitives/doc-index.cjs +215 -0
- package/dist/action-primitives/doc-index.d.ts +83 -0
- package/dist/action-primitives/doc-index.d.ts.map +1 -0
- package/dist/action-primitives/doc-index.js +211 -0
- package/dist/action-primitives/engine.cjs +204 -0
- package/dist/action-primitives/engine.d.ts +71 -0
- package/dist/action-primitives/engine.d.ts.map +1 -0
- package/dist/action-primitives/engine.js +196 -0
- package/dist/action-primitives/receipt.cjs +39 -0
- package/dist/action-primitives/receipt.d.ts +49 -0
- package/dist/action-primitives/receipt.d.ts.map +1 -0
- package/dist/action-primitives/receipt.js +32 -0
- package/dist/action-primitives/resolve.cjs +252 -0
- package/dist/action-primitives/resolve.d.ts +56 -0
- package/dist/action-primitives/resolve.d.ts.map +1 -0
- package/dist/action-primitives/resolve.js +246 -0
- package/dist/action-primitives/session-cache.cjs +43 -0
- package/dist/action-primitives/session-cache.d.ts +19 -0
- package/dist/action-primitives/session-cache.d.ts.map +1 -0
- package/dist/action-primitives/session-cache.js +37 -0
- package/dist/action-primitives/tools/list-transform.cjs +661 -0
- package/dist/action-primitives/tools/list-transform.d.ts +98 -0
- package/dist/action-primitives/tools/list-transform.d.ts.map +1 -0
- package/dist/action-primitives/tools/list-transform.js +656 -0
- package/dist/action-primitives/tools/structure-insert.cjs +1343 -0
- package/dist/action-primitives/tools/structure-insert.d.ts +183 -0
- package/dist/action-primitives/tools/structure-insert.d.ts.map +1 -0
- package/dist/action-primitives/tools/structure-insert.js +1338 -0
- package/dist/action-primitives/tools/text-transform.cjs +669 -0
- package/dist/action-primitives/tools/text-transform.d.ts +64 -0
- package/dist/action-primitives/tools/text-transform.d.ts.map +1 -0
- package/dist/action-primitives/tools/text-transform.js +664 -0
- package/dist/action-primitives/types.d.ts +36 -0
- package/dist/action-primitives/types.d.ts.map +1 -0
- package/dist/action-primitives/types.js +15 -0
- package/dist/agent/actions.cjs +5381 -0
- package/dist/agent/actions.d.ts +404 -0
- package/dist/agent/actions.d.ts.map +1 -0
- package/dist/agent/actions.js +5373 -0
- package/dist/agent/catalog.cjs +483 -0
- package/dist/agent/catalog.d.ts +103 -0
- package/dist/agent/catalog.d.ts.map +1 -0
- package/dist/agent/catalog.js +471 -0
- package/dist/agent/doc-snapshot.cjs +663 -0
- package/dist/agent/doc-snapshot.d.ts +247 -0
- package/dist/agent/doc-snapshot.d.ts.map +1 -0
- package/dist/agent/doc-snapshot.js +657 -0
- package/dist/agent/index.d.ts +16 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +15 -0
- package/dist/agent/ir.cjs +170 -0
- package/dist/agent/ir.d.ts +216 -0
- package/dist/agent/ir.d.ts.map +1 -0
- package/dist/agent/ir.js +181 -0
- package/dist/agent/operation-catalog.cjs +418 -0
- package/dist/agent/operation-catalog.d.ts +36 -0
- package/dist/agent/operation-catalog.d.ts.map +1 -0
- package/dist/agent/operation-catalog.js +446 -0
- package/dist/agent/runtime.cjs +501 -0
- package/dist/agent/runtime.d.ts +120 -0
- package/dist/agent/runtime.d.ts.map +1 -0
- package/dist/agent/runtime.js +493 -0
- package/dist/embedded-prompts.generated.cjs +13 -0
- package/dist/embedded-prompts.generated.d.ts +4 -0
- package/dist/embedded-prompts.generated.d.ts.map +1 -0
- package/dist/embedded-prompts.generated.js +9 -0
- package/dist/generated/client.cjs +18 -20
- package/dist/generated/client.d.ts +723 -3223
- package/dist/generated/client.d.ts.map +1 -1
- package/dist/generated/client.js +18 -20
- package/dist/generated/contract.cjs +12898 -18467
- package/dist/generated/contract.d.ts.map +1 -1
- package/dist/generated/contract.js +12898 -18467
- package/dist/generated/intent-dispatch.generated.cjs +0 -1
- package/dist/generated/intent-dispatch.generated.d.ts.map +1 -1
- package/dist/generated/intent-dispatch.generated.js +0 -1
- package/dist/index.cjs +3 -7
- package/dist/index.d.ts +8 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -8
- package/dist/presets/core.cjs +454 -0
- package/dist/presets/core.d.ts +20 -0
- package/dist/presets/core.d.ts.map +1 -0
- package/dist/presets/core.js +447 -0
- package/dist/presets.cjs +55 -8
- package/dist/presets.d.ts +39 -8
- package/dist/presets.d.ts.map +1 -1
- package/dist/presets.js +53 -8
- package/dist/prompts/mcp-prompt.md +23 -0
- package/dist/prompts/system-prompt.md +108 -0
- package/dist/runtime/transport-common.cjs +8 -0
- package/dist/runtime/transport-common.d.ts.map +1 -1
- package/dist/runtime/transport-common.js +8 -0
- package/dist/tools.cjs +46 -11
- package/dist/tools.d.ts +55 -8
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +45 -13
- package/package.json +9 -8
- package/tools/__pycache__/__init__.cpython-312.pyc +0 -0
- package/tools/__pycache__/intent_dispatch_generated.cpython-312.pyc +0 -0
- package/tools/catalog.json +22 -178
- package/tools/intent_dispatch_generated.py +0 -2
- package/tools/tools-policy.json +1 -1
- package/tools/tools.anthropic.json +22 -158
- package/tools/tools.generic.json +23 -160
- package/tools/tools.openai.json +22 -158
- package/tools/tools.vercel.json +22 -158
|
@@ -103,7 +103,6 @@ function dispatchIntentTool(toolName, args, execute) {
|
|
|
103
103
|
case 'set_layout': return execute('doc.tables.setLayout', rest);
|
|
104
104
|
case 'insert_row': return execute('doc.tables.insertRow', rest);
|
|
105
105
|
case 'delete_row': return execute('doc.tables.deleteRow', rest);
|
|
106
|
-
case 'move_row': return execute('doc.tables.moveRow', rest);
|
|
107
106
|
case 'set_row': return execute('doc.tables.setRowHeight', rest);
|
|
108
107
|
case 'set_row_options': return execute('doc.tables.setRowOptions', rest);
|
|
109
108
|
case 'insert_column': return execute('doc.tables.insertColumn', rest);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intent-dispatch.generated.d.ts","sourceRoot":"","sources":["../../src/generated/intent-dispatch.generated.ts"],"names":[],"mappings":"AAEA,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,GACxE,OAAO,
|
|
1
|
+
{"version":3,"file":"intent-dispatch.generated.d.ts","sourceRoot":"","sources":["../../src/generated/intent-dispatch.generated.ts"],"names":[],"mappings":"AAEA,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,GACxE,OAAO,CAyHT"}
|
|
@@ -101,7 +101,6 @@ export function dispatchIntentTool(toolName, args, execute) {
|
|
|
101
101
|
case 'set_layout': return execute('doc.tables.setLayout', rest);
|
|
102
102
|
case 'insert_row': return execute('doc.tables.insertRow', rest);
|
|
103
103
|
case 'delete_row': return execute('doc.tables.deleteRow', rest);
|
|
104
|
-
case 'move_row': return execute('doc.tables.moveRow', rest);
|
|
105
104
|
case 'set_row': return execute('doc.tables.setRowHeight', rest);
|
|
106
105
|
case 'set_row_options': return execute('doc.tables.setRowOptions', rest);
|
|
107
106
|
case 'insert_column': return execute('doc.tables.insertColumn', rest);
|
package/dist/index.cjs
CHANGED
|
@@ -80,13 +80,6 @@ class SuperDocDocumentCore {
|
|
|
80
80
|
markClosed() {
|
|
81
81
|
this.boundRuntime.markClosed();
|
|
82
82
|
}
|
|
83
|
-
async formatRange(params, options = {}) {
|
|
84
|
-
const { properties, ...rest } = params;
|
|
85
|
-
return this.boundRuntime.invoke(contract.CONTRACT.operations['doc.format.apply'], {
|
|
86
|
-
...rest,
|
|
87
|
-
inline: properties,
|
|
88
|
-
}, options);
|
|
89
|
-
}
|
|
90
83
|
}
|
|
91
84
|
function attachBoundDocApi(target, api) {
|
|
92
85
|
const { save: _save, close: _close, ...boundMethods } = api;
|
|
@@ -166,6 +159,7 @@ exports.getSkill = skills.getSkill;
|
|
|
166
159
|
exports.installSkill = skills.installSkill;
|
|
167
160
|
exports.listSkills = skills.listSkills;
|
|
168
161
|
exports.chooseTools = tools.chooseTools;
|
|
162
|
+
exports.createAgentToolkit = tools.createAgentToolkit;
|
|
169
163
|
exports.dispatchSuperDocTool = tools.dispatchSuperDocTool;
|
|
170
164
|
exports.getMcpPrompt = tools.getMcpPrompt;
|
|
171
165
|
exports.getSystemPrompt = tools.getSystemPrompt;
|
|
@@ -176,6 +170,8 @@ exports.dispatchIntentTool = intentDispatch_generated.dispatchIntentTool;
|
|
|
176
170
|
exports.DEFAULT_PRESET = presets.DEFAULT_PRESET;
|
|
177
171
|
exports.getPreset = presets.getPreset;
|
|
178
172
|
exports.listPresets = presets.listPresets;
|
|
173
|
+
exports.registerPreset = presets.registerPreset;
|
|
174
|
+
exports.unregisterPreset = presets.unregisterPreset;
|
|
179
175
|
exports.SuperDocClient = SuperDocClient;
|
|
180
176
|
exports.SuperDocDocument = SuperDocDocument;
|
|
181
177
|
exports.createSuperDocClient = createSuperDocClient;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type BoundDocApi, type DocCloseBoundParams, type DocCloseResult, type
|
|
1
|
+
import { type BoundDocApi, type DocCloseBoundParams, type DocCloseResult, type DocOpenParams as GeneratedDocOpenParams, type DocOpenResult, type DocSaveBoundParams, type DocSaveResult } from './generated/client.js';
|
|
2
2
|
import { SuperDocRuntime, type SuperDocClientOptions, type InvokeOptions, type OperationSpec, type RuntimeInvoker } from './runtime/process.js';
|
|
3
3
|
/**
|
|
4
4
|
* Wraps a raw runtime and injects a fixed sessionId into every invoke call.
|
|
@@ -14,9 +14,6 @@ declare class BoundRuntime implements RuntimeInvoker {
|
|
|
14
14
|
invoke<TData = unknown>(operation: OperationSpec, params?: Record<string, unknown>, options?: InvokeOptions): Promise<TData>;
|
|
15
15
|
markClosed(): void;
|
|
16
16
|
}
|
|
17
|
-
export interface DocFormatRangeBoundParams extends Omit<DocFormatApplyBoundParams, 'inline'> {
|
|
18
|
-
properties: NonNullable<DocFormatApplyBoundParams['inline']>;
|
|
19
|
-
}
|
|
20
17
|
/**
|
|
21
18
|
* Bound document handle. All document operations are available as typed methods.
|
|
22
19
|
* The handle injects its session id automatically — callers never pass
|
|
@@ -36,7 +33,6 @@ declare class SuperDocDocumentCore {
|
|
|
36
33
|
close(params?: DocCloseBoundParams, options?: InvokeOptions): Promise<DocCloseResult>;
|
|
37
34
|
/** @internal */
|
|
38
35
|
markClosed(): void;
|
|
39
|
-
formatRange(params: DocFormatRangeBoundParams, options?: InvokeOptions): Promise<DocFormatApplyResult>;
|
|
40
36
|
}
|
|
41
37
|
type SuperDocDocumentInstance = SuperDocDocumentCore & BoundDocApi;
|
|
42
38
|
export declare const SuperDocDocument: new (boundRuntime: BoundRuntime, sessionId: string, openResult: DocOpenResult, client: SuperDocClient) => SuperDocDocumentInstance;
|
|
@@ -81,9 +77,15 @@ export declare class SuperDocClient {
|
|
|
81
77
|
}
|
|
82
78
|
export declare function createSuperDocClient(options?: SuperDocClientOptions): SuperDocClient;
|
|
83
79
|
export { getSkill, installSkill, listSkills } from './skills.js';
|
|
84
|
-
export { chooseTools, dispatchSuperDocTool, getMcpPrompt, getSystemPrompt, getSystemPromptForProvider, getToolCatalog, listTools, DEFAULT_PRESET, getPreset, listPresets, } from './tools.js';
|
|
80
|
+
export { chooseTools, dispatchSuperDocTool, getMcpPrompt, getSystemPrompt, getSystemPromptForProvider, getToolCatalog, listTools, DEFAULT_PRESET, getPreset, listPresets, registerPreset, unregisterPreset, } from './tools.js';
|
|
85
81
|
export type { AnthropicSystemPrompt, CacheStrategy, SystemPromptForProviderResult, ToolCatalog, ToolCatalogEntry, ToolCatalogOperation, ToolChooserInput, ToolProvider, } from './tools.js';
|
|
86
82
|
export { dispatchIntentTool } from './generated/intent-dispatch.generated.js';
|
|
83
|
+
export type { BoundDocApi } from './generated/client.js';
|
|
84
|
+
export type { ActionName } from './agent/actions.js';
|
|
85
|
+
export type { AgentReceipt } from './agent/runtime.js';
|
|
86
|
+
export type { GetSystemPromptOptions, GetToolsOptions, GetToolsResult, PresetDescriptor } from './presets.js';
|
|
87
|
+
export { createAgentToolkit } from './tools.js';
|
|
88
|
+
export type { AgentToolkit, CreateAgentToolkitInput } from './tools.js';
|
|
87
89
|
export { SuperDocCliError } from './runtime/errors.js';
|
|
88
90
|
export type { InvokeOptions, OperationSpec, OperationParamSpec, RuntimeInvoker, SuperDocClientOptions, } from './runtime/process.js';
|
|
89
91
|
export type { DocOpenResult } from './generated/client.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,WAAW,EAChB,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACnB,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"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"}
|
package/dist/index.js
CHANGED
|
@@ -73,13 +73,6 @@ class SuperDocDocumentCore {
|
|
|
73
73
|
markClosed() {
|
|
74
74
|
this.boundRuntime.markClosed();
|
|
75
75
|
}
|
|
76
|
-
async formatRange(params, options = {}) {
|
|
77
|
-
const { properties, ...rest } = params;
|
|
78
|
-
return this.boundRuntime.invoke(CONTRACT.operations['doc.format.apply'], {
|
|
79
|
-
...rest,
|
|
80
|
-
inline: properties,
|
|
81
|
-
}, options);
|
|
82
|
-
}
|
|
83
76
|
}
|
|
84
77
|
function attachBoundDocApi(target, api) {
|
|
85
78
|
const { save: _save, close: _close, ...boundMethods } = api;
|
|
@@ -154,6 +147,7 @@ export function createSuperDocClient(options = {}) {
|
|
|
154
147
|
return new SuperDocClient(options);
|
|
155
148
|
}
|
|
156
149
|
export { getSkill, installSkill, listSkills } from './skills.js';
|
|
157
|
-
export { chooseTools, dispatchSuperDocTool, getMcpPrompt, getSystemPrompt, getSystemPromptForProvider, getToolCatalog, listTools, DEFAULT_PRESET, getPreset, listPresets, } from './tools.js';
|
|
150
|
+
export { chooseTools, dispatchSuperDocTool, getMcpPrompt, getSystemPrompt, getSystemPromptForProvider, getToolCatalog, listTools, DEFAULT_PRESET, getPreset, listPresets, registerPreset, unregisterPreset, } from './tools.js';
|
|
158
151
|
export { dispatchIntentTool } from './generated/intent-dispatch.generated.js';
|
|
152
|
+
export { createAgentToolkit } from './tools.js';
|
|
159
153
|
export { SuperDocCliError } from './runtime/errors.js';
|
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var promises = require('node:fs/promises');
|
|
4
|
+
var path = require('node:path');
|
|
5
|
+
var node_url = require('node:url');
|
|
6
|
+
var errors = require('../runtime/errors.cjs');
|
|
7
|
+
var catalog = require('../agent/catalog.cjs');
|
|
8
|
+
var runtime = require('../agent/runtime.cjs');
|
|
9
|
+
var actions = require('../agent/actions.cjs');
|
|
10
|
+
var embeddedPrompts_generated = require('../embedded-prompts.generated.cjs');
|
|
11
|
+
|
|
12
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
13
|
+
/**
|
|
14
|
+
* `core` preset — actions-only LLM-facing surface.
|
|
15
|
+
*
|
|
16
|
+
* Two advertised tools: superdoc_inspect (read-only deterministic snapshots)
|
|
17
|
+
* and superdoc_perform_action (named, statically validated, deterministic edit
|
|
18
|
+
* verbs — the action registry in agent/actions.ts).
|
|
19
|
+
*
|
|
20
|
+
* superdoc_execute_code (model-authored JS against a synchronous in-host doc)
|
|
21
|
+
* is WIP: dispatchable for SDK callers, NOT advertised and NOT in the served
|
|
22
|
+
* system prompt until it ships behind a safety flag. The agent_apply /
|
|
23
|
+
* agent_verify / agent_operation tools are likewise dispatchable but never
|
|
24
|
+
* advertised.
|
|
25
|
+
*
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
// Prompts ship as <dist>/prompts/*.md. Resolve relative to the compiled
|
|
29
|
+
// module, but the module's depth differs by build: in the SDK package this
|
|
30
|
+
// file is dist/presets/core.js (so prompts are at ../prompts), while the
|
|
31
|
+
// bundled CLI inlines it into dist/index.js (so prompts are at ./prompts).
|
|
32
|
+
// Try both so getSystemPrompt works through the SDK AND the CLI host (the
|
|
33
|
+
// path the Python SDK proxies through).
|
|
34
|
+
const MODULE_DIR = path.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('presets/core.cjs', document.baseURI).href))));
|
|
35
|
+
const PROMPT_DIR_CANDIDATES = [path.resolve(MODULE_DIR, '..', 'prompts'), path.resolve(MODULE_DIR, 'prompts')];
|
|
36
|
+
let _actionsOnlyPromptCache = null;
|
|
37
|
+
let _mcpPromptCache = null;
|
|
38
|
+
/** Exported for unit tests; production callers use the default candidates. */
|
|
39
|
+
async function readPromptFile(fileName, label, candidateDirs = PROMPT_DIR_CANDIDATES) {
|
|
40
|
+
const tried = [];
|
|
41
|
+
let lastIoError;
|
|
42
|
+
for (const dir of candidateDirs) {
|
|
43
|
+
const promptPath = path.join(dir, fileName);
|
|
44
|
+
tried.push(promptPath);
|
|
45
|
+
try {
|
|
46
|
+
return await promises.readFile(promptPath, 'utf8');
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
const ioError = err;
|
|
50
|
+
if (ioError?.code !== 'ENOENT') {
|
|
51
|
+
// Permission/IO failures are not "asset missing" — remember the real
|
|
52
|
+
// cause, but still try the other layout candidate.
|
|
53
|
+
lastIoError = ioError;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// Filesystem candidates exhausted. Native binaries (bun --compile) resolve
|
|
58
|
+
// MODULE_DIR inside bun's virtual filesystem where the .md assets don't
|
|
59
|
+
// exist — fall back to the compiled-in copies (identical content by
|
|
60
|
+
// construction; a drift test enforces it).
|
|
61
|
+
const embedded = embeddedPrompts_generated.EMBEDDED_PROMPTS[fileName];
|
|
62
|
+
if (typeof embedded === 'string') {
|
|
63
|
+
return embedded;
|
|
64
|
+
}
|
|
65
|
+
if (lastIoError) {
|
|
66
|
+
throw new errors.SuperDocCliError(`${label} could not be read: ${lastIoError.message}`, {
|
|
67
|
+
code: 'TOOLS_ASSET_UNREADABLE',
|
|
68
|
+
details: { triedPaths: tried, cause: `${lastIoError.code ?? lastIoError.name}: ${lastIoError.message}` },
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
throw new errors.SuperDocCliError(`${label} not found.`, {
|
|
72
|
+
code: 'TOOLS_ASSET_NOT_FOUND',
|
|
73
|
+
details: { triedPaths: tried },
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
function isRecord(value) {
|
|
77
|
+
return typeof value === 'object' && value != null && !Array.isArray(value);
|
|
78
|
+
}
|
|
79
|
+
function isObviouslyCorruptedToolArgKey(key) {
|
|
80
|
+
const trimmed = key.trim();
|
|
81
|
+
return trimmed.length === 0 || !/[\p{L}\p{N}]/u.test(trimmed);
|
|
82
|
+
}
|
|
83
|
+
function stripCorruptedToolArgKeys(value) {
|
|
84
|
+
if (Array.isArray(value)) {
|
|
85
|
+
return value.map((item) => stripCorruptedToolArgKeys(item));
|
|
86
|
+
}
|
|
87
|
+
if (!isRecord(value))
|
|
88
|
+
return value;
|
|
89
|
+
const clean = {};
|
|
90
|
+
for (const [key, entryValue] of Object.entries(value)) {
|
|
91
|
+
if (isObviouslyCorruptedToolArgKey(key))
|
|
92
|
+
continue;
|
|
93
|
+
clean[key] = stripCorruptedToolArgKeys(entryValue);
|
|
94
|
+
}
|
|
95
|
+
return clean;
|
|
96
|
+
}
|
|
97
|
+
function validateAgentToolArgs(toolName, args) {
|
|
98
|
+
const definition = catalog.AGENT_TOOL_DEFINITIONS.find((entry) => entry.name === toolName);
|
|
99
|
+
if (definition == null)
|
|
100
|
+
return;
|
|
101
|
+
const schema = definition.inputSchema;
|
|
102
|
+
const properties = isRecord(schema.properties) ? schema.properties : {};
|
|
103
|
+
const required = Array.isArray(schema.required) ? schema.required : [];
|
|
104
|
+
const knownKeys = new Set(Object.keys(properties));
|
|
105
|
+
const unknownKeys = Object.keys(args).filter((key) => !knownKeys.has(key));
|
|
106
|
+
if (unknownKeys.length > 0) {
|
|
107
|
+
throw new errors.SuperDocCliError(`Unknown argument(s) for ${toolName}: ${unknownKeys.join(', ')}`, {
|
|
108
|
+
code: 'INVALID_ARGUMENT',
|
|
109
|
+
details: { toolName, unknownKeys, knownKeys: [...knownKeys] },
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
const missingKeys = required.filter((key) => args[key] == null);
|
|
113
|
+
if (missingKeys.length > 0) {
|
|
114
|
+
throw new errors.SuperDocCliError(`Missing required argument(s) for ${toolName}: ${missingKeys.join(', ')}`, {
|
|
115
|
+
code: 'INVALID_ARGUMENT',
|
|
116
|
+
details: { toolName, missingKeys },
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// ---------------------------------------------------------------------------
|
|
121
|
+
// Compaction helpers — keep agent receipts tight in the tool-result payload
|
|
122
|
+
// ---------------------------------------------------------------------------
|
|
123
|
+
/**
|
|
124
|
+
* Max entries for per-item receipt lists (executedOperations, selectedTargets).
|
|
125
|
+
* Receipts live in the conversation and are re-billed as prompt tokens on every
|
|
126
|
+
* subsequent turn; unbounded lists (one op per formatted range/paragraph) made
|
|
127
|
+
* single receipts cost thousands of tokens. 8 keeps enough shape to audit while
|
|
128
|
+
* the accompanying *Count field preserves the true total.
|
|
129
|
+
*/
|
|
130
|
+
const RECEIPT_LIST_CAP = 8;
|
|
131
|
+
function compactCountMap(counts) {
|
|
132
|
+
const compact = {};
|
|
133
|
+
for (const [key, value] of Object.entries(counts)) {
|
|
134
|
+
if (typeof value === 'number' && value !== 0)
|
|
135
|
+
compact[key] = value;
|
|
136
|
+
}
|
|
137
|
+
if (Object.keys(compact).length === 0 && typeof counts.blocks === 'number') {
|
|
138
|
+
compact.blocks = counts.blocks;
|
|
139
|
+
}
|
|
140
|
+
return compact;
|
|
141
|
+
}
|
|
142
|
+
function pickScalarFields(value, keys, limit = 6) {
|
|
143
|
+
if (!isRecord(value))
|
|
144
|
+
return {};
|
|
145
|
+
const entries = keys
|
|
146
|
+
? keys.filter((key) => key in value).map((key) => [key, value[key]])
|
|
147
|
+
: Object.entries(value);
|
|
148
|
+
const compact = {};
|
|
149
|
+
for (const [key, entryValue] of entries) {
|
|
150
|
+
if (typeof entryValue === 'string' ||
|
|
151
|
+
typeof entryValue === 'number' ||
|
|
152
|
+
typeof entryValue === 'boolean' ||
|
|
153
|
+
entryValue == null) {
|
|
154
|
+
compact[key] = entryValue ?? null;
|
|
155
|
+
}
|
|
156
|
+
if (Object.keys(compact).length >= limit)
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
return compact;
|
|
160
|
+
}
|
|
161
|
+
function compactOperationResult(result) {
|
|
162
|
+
if (result == null || typeof result === 'string' || typeof result === 'number' || typeof result === 'boolean') {
|
|
163
|
+
return result;
|
|
164
|
+
}
|
|
165
|
+
if (Array.isArray(result))
|
|
166
|
+
return { itemCount: result.length };
|
|
167
|
+
if (!isRecord(result))
|
|
168
|
+
return { kind: typeof result };
|
|
169
|
+
const compact = {
|
|
170
|
+
...pickScalarFields(result, ['success', 'status', 'count', 'total', 'applied', 'created', 'deleted']),
|
|
171
|
+
};
|
|
172
|
+
if (isRecord(result.revision)) {
|
|
173
|
+
const revision = pickScalarFields(result.revision, ['before', 'after', 'current']);
|
|
174
|
+
if (Object.keys(revision).length > 0)
|
|
175
|
+
compact.revision = revision;
|
|
176
|
+
}
|
|
177
|
+
if (Array.isArray(result.steps)) {
|
|
178
|
+
compact.stepCount = result.steps.length;
|
|
179
|
+
compact.steps = result.steps
|
|
180
|
+
.slice(0, 4)
|
|
181
|
+
.map((step) => (isRecord(step) ? pickScalarFields(step, ['stepId', 'op', 'effect', 'matchCount'], 4) : {}));
|
|
182
|
+
}
|
|
183
|
+
if (Array.isArray(result.items))
|
|
184
|
+
compact.itemCount = result.items.length;
|
|
185
|
+
if (Array.isArray(result.changes))
|
|
186
|
+
compact.changeCount = result.changes.length;
|
|
187
|
+
if (Array.isArray(result.matches))
|
|
188
|
+
compact.matchCount = result.matches.length;
|
|
189
|
+
if (Object.keys(compact).length === 0)
|
|
190
|
+
return { kind: 'object' };
|
|
191
|
+
return compact;
|
|
192
|
+
}
|
|
193
|
+
function compactAgentReceipt(receipt) {
|
|
194
|
+
// Compact the known heavy fields; pass every action-specific evidence field
|
|
195
|
+
// (editsApplied, marker, placement, revertHint, recovery, …) through
|
|
196
|
+
// verbatim — truth-telling receipts are only useful if the model sees them.
|
|
197
|
+
const { status, intent, preSnapshot, postSnapshot, selectedTargets, executedOperations, verification, saveReopen, errors, ...evidence } = receipt;
|
|
198
|
+
return {
|
|
199
|
+
status,
|
|
200
|
+
intent,
|
|
201
|
+
...(preSnapshot
|
|
202
|
+
? {
|
|
203
|
+
preSnapshot: {
|
|
204
|
+
revision: preSnapshot.revision,
|
|
205
|
+
...(preSnapshot.counts ? { counts: compactCountMap(preSnapshot.counts) } : {}),
|
|
206
|
+
},
|
|
207
|
+
}
|
|
208
|
+
: {}),
|
|
209
|
+
...(postSnapshot
|
|
210
|
+
? {
|
|
211
|
+
postSnapshot: {
|
|
212
|
+
revision: postSnapshot.revision,
|
|
213
|
+
...(postSnapshot.counts ? { counts: compactCountMap(postSnapshot.counts) } : {}),
|
|
214
|
+
},
|
|
215
|
+
}
|
|
216
|
+
: {}),
|
|
217
|
+
...(selectedTargets
|
|
218
|
+
? {
|
|
219
|
+
// Cap per-item lists: batch actions (add_comments selectors[],
|
|
220
|
+
// whole-body formatting) can select hundreds of targets, and the
|
|
221
|
+
// receipt is re-sent in conversation history on EVERY later turn.
|
|
222
|
+
// The count carries the evidence; the head carries the shape.
|
|
223
|
+
selectedTargets: selectedTargets.slice(0, RECEIPT_LIST_CAP).map((target) => ({
|
|
224
|
+
selector: target.selector,
|
|
225
|
+
matchedCount: target.matched.length,
|
|
226
|
+
})),
|
|
227
|
+
...(selectedTargets.length > RECEIPT_LIST_CAP ? { selectedTargetCount: selectedTargets.length } : {}),
|
|
228
|
+
}
|
|
229
|
+
: {}),
|
|
230
|
+
...(executedOperations
|
|
231
|
+
? {
|
|
232
|
+
// Same cap: per-range/per-item actions (format_text on every
|
|
233
|
+
// occurrence, whole-body set_font_family) execute one op per item —
|
|
234
|
+
// an uncapped list dominates the token cost of the receipt.
|
|
235
|
+
executedOperations: executedOperations.slice(0, RECEIPT_LIST_CAP).map((operation) => ({
|
|
236
|
+
operationId: operation.operationId,
|
|
237
|
+
...(operation.rationale ? { rationale: operation.rationale } : {}),
|
|
238
|
+
...(operation.result !== undefined ? { result: compactOperationResult(operation.result) } : {}),
|
|
239
|
+
})),
|
|
240
|
+
...(executedOperations.length > RECEIPT_LIST_CAP
|
|
241
|
+
? { executedOperationCount: executedOperations.length }
|
|
242
|
+
: {}),
|
|
243
|
+
}
|
|
244
|
+
: {}),
|
|
245
|
+
...(verification
|
|
246
|
+
? {
|
|
247
|
+
verificationPassed: verification.every((entry) => entry.passed),
|
|
248
|
+
verification: verification.map((entry) => ({
|
|
249
|
+
check: pickScalarFields(entry.check, undefined, 6),
|
|
250
|
+
passed: entry.passed,
|
|
251
|
+
...(entry.detail ? { detail: entry.detail } : {}),
|
|
252
|
+
})),
|
|
253
|
+
}
|
|
254
|
+
: {}),
|
|
255
|
+
...(saveReopen ? { saveReopen } : {}),
|
|
256
|
+
...(errors ? { errors } : {}),
|
|
257
|
+
...evidence,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
// ---------------------------------------------------------------------------
|
|
261
|
+
// superdoc_execute_code — in-host dispatch for the CLI/SDK-only `doc.executeCode` op
|
|
262
|
+
// ---------------------------------------------------------------------------
|
|
263
|
+
const EXECUTE_CODE_SPEC = {
|
|
264
|
+
operationId: 'doc.executeCode',
|
|
265
|
+
commandTokens: ['execute', 'code'],
|
|
266
|
+
params: [
|
|
267
|
+
{ name: 'sessionId', kind: 'flag', flag: 'session', type: 'string' },
|
|
268
|
+
{ name: 'code', kind: 'flag', flag: 'code', type: 'string' },
|
|
269
|
+
],
|
|
270
|
+
};
|
|
271
|
+
function asRawOperationCapable(documentHandle) {
|
|
272
|
+
const candidate = documentHandle;
|
|
273
|
+
if (typeof candidate.invokeRawOperation !== 'function') {
|
|
274
|
+
throw new errors.SuperDocCliError('superdoc_execute_code requires a session-bound document handle from client.open(); the provided handle cannot dispatch CLI/SDK-only operations.', {
|
|
275
|
+
code: 'TOOL_DISPATCH_NOT_FOUND',
|
|
276
|
+
details: { toolName: 'superdoc_execute_code' },
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
return candidate;
|
|
280
|
+
}
|
|
281
|
+
async function dispatchExecuteCode(documentHandle, args, invokeOptions) {
|
|
282
|
+
const code = typeof args.code === 'string' ? args.code : '';
|
|
283
|
+
// The generated bound client exposes doc.executeCode directly — use it.
|
|
284
|
+
// The invokeRawOperation path predates that binding and no handle produced
|
|
285
|
+
// by client.open() implements it; it remains only for callers that inject
|
|
286
|
+
// their own raw-capable handle.
|
|
287
|
+
const direct = documentHandle.executeCode;
|
|
288
|
+
if (typeof direct === 'function') {
|
|
289
|
+
return direct.call(documentHandle, { code }, invokeOptions);
|
|
290
|
+
}
|
|
291
|
+
const runner = asRawOperationCapable(documentHandle);
|
|
292
|
+
return runner.invokeRawOperation(EXECUTE_CODE_SPEC, { code }, invokeOptions);
|
|
293
|
+
}
|
|
294
|
+
// ---------------------------------------------------------------------------
|
|
295
|
+
// Dispatcher
|
|
296
|
+
// ---------------------------------------------------------------------------
|
|
297
|
+
async function dispatchAgentTool(documentHandle, toolName, args, invokeOptions) {
|
|
298
|
+
switch (toolName) {
|
|
299
|
+
case 'superdoc_inspect':
|
|
300
|
+
return runtime.agentInspect(documentHandle, args);
|
|
301
|
+
case 'agent_apply':
|
|
302
|
+
return compactAgentReceipt(await runtime.agentApply(documentHandle, args));
|
|
303
|
+
case 'agent_verify':
|
|
304
|
+
return compactAgentReceipt(await runtime.agentVerify(documentHandle, args));
|
|
305
|
+
case 'agent_operation':
|
|
306
|
+
return runtime.agentOperation(documentHandle, args);
|
|
307
|
+
case 'superdoc_perform_action':
|
|
308
|
+
return compactAgentReceipt(await actions.superdocPerformAction(documentHandle, args));
|
|
309
|
+
case 'superdoc_execute_code':
|
|
310
|
+
return dispatchExecuteCode(documentHandle, args, invokeOptions);
|
|
311
|
+
}
|
|
312
|
+
throw new errors.SuperDocCliError(`Unknown agent tool: ${toolName}`, {
|
|
313
|
+
code: 'TOOL_DISPATCH_NOT_FOUND',
|
|
314
|
+
details: { toolName },
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
// ---------------------------------------------------------------------------
|
|
318
|
+
// Provider cache markers — mirrors the legacy preset
|
|
319
|
+
// ---------------------------------------------------------------------------
|
|
320
|
+
function applyCacheMarkers(tools, provider, cacheRequested) {
|
|
321
|
+
if (!cacheRequested)
|
|
322
|
+
return { tools, cacheStrategy: 'disabled' };
|
|
323
|
+
if (provider === 'anthropic') {
|
|
324
|
+
if (tools.length === 0)
|
|
325
|
+
return { tools, cacheStrategy: 'explicit' };
|
|
326
|
+
const next = tools.slice(0, -1);
|
|
327
|
+
const last = {
|
|
328
|
+
...tools[tools.length - 1],
|
|
329
|
+
cache_control: { type: 'ephemeral' },
|
|
330
|
+
};
|
|
331
|
+
next.push(last);
|
|
332
|
+
return { tools: next, cacheStrategy: 'explicit' };
|
|
333
|
+
}
|
|
334
|
+
if (provider === 'openai')
|
|
335
|
+
return { tools, cacheStrategy: 'automatic' };
|
|
336
|
+
return { tools, cacheStrategy: 'unsupported' };
|
|
337
|
+
}
|
|
338
|
+
// ---------------------------------------------------------------------------
|
|
339
|
+
// PresetDescriptor surface
|
|
340
|
+
// ---------------------------------------------------------------------------
|
|
341
|
+
async function coreGetTools(provider, options) {
|
|
342
|
+
const tools = catalog.listAgentTools(provider, { excludeActions: options?.excludeActions });
|
|
343
|
+
return applyCacheMarkers(tools, provider, options?.cache === true);
|
|
344
|
+
}
|
|
345
|
+
async function coreGetCatalog() {
|
|
346
|
+
// Synthetic catalog — describes the advertised LLM-facing tools.
|
|
347
|
+
const publicSet = new Set(catalog.PUBLIC_AGENT_TOOL_NAMES);
|
|
348
|
+
const tools = catalog.AGENT_TOOL_DEFINITIONS.filter((d) => publicSet.has(d.name)).map((d) => ({
|
|
349
|
+
toolName: d.name,
|
|
350
|
+
description: d.description,
|
|
351
|
+
inputSchema: d.inputSchema,
|
|
352
|
+
mutates: d.name !== 'superdoc_inspect',
|
|
353
|
+
operations: [],
|
|
354
|
+
}));
|
|
355
|
+
return {
|
|
356
|
+
contractVersion: 'core/v2',
|
|
357
|
+
generatedAt: null,
|
|
358
|
+
toolCount: tools.length,
|
|
359
|
+
tools,
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Drop the per-action documentation lines for excluded actions. Entries render
|
|
364
|
+
* as single "- name: ..." lines (the drift-guard test enforces the format), so
|
|
365
|
+
* line-level filtering is deterministic. Prose cross-references elsewhere in
|
|
366
|
+
* the prompt are left alone — a mention costs a few tokens; a full per-action
|
|
367
|
+
* manual for an uncallable action teaches the model to call it.
|
|
368
|
+
*/
|
|
369
|
+
function stripExcludedActionLines(prompt, excludedActions) {
|
|
370
|
+
if (excludedActions.size === 0)
|
|
371
|
+
return prompt;
|
|
372
|
+
return prompt
|
|
373
|
+
.split('\n')
|
|
374
|
+
.filter((line) => {
|
|
375
|
+
const match = /^- ([a-z_]+)(?: \/ ([a-z_]+))?:/.exec(line);
|
|
376
|
+
if (!match)
|
|
377
|
+
return true;
|
|
378
|
+
const names = [match[1], match[2]].filter((n) => Boolean(n));
|
|
379
|
+
// Drop the line only when EVERY action it documents is excluded (the
|
|
380
|
+
// paired accept/reject line survives if one side remains callable).
|
|
381
|
+
return !names.every((name) => excludedActions.has(name));
|
|
382
|
+
})
|
|
383
|
+
.join('\n');
|
|
384
|
+
}
|
|
385
|
+
async function coreGetSystemPrompt(options) {
|
|
386
|
+
const { excludedActions } = catalog.validateExclusions({ excludeActions: options?.excludeActions });
|
|
387
|
+
// The core preset is ACTIONS-ONLY: superdoc_execute_code is WIP and not
|
|
388
|
+
// advertised, and the prompt documents only the action surface (this exact
|
|
389
|
+
// prompt is what the eval suite validates). Code-execution guidance will be
|
|
390
|
+
// added when the safety-flag work ships that tool.
|
|
391
|
+
if (_actionsOnlyPromptCache == null) {
|
|
392
|
+
_actionsOnlyPromptCache = await readPromptFile('system-prompt.md', 'Core system prompt');
|
|
393
|
+
}
|
|
394
|
+
return stripExcludedActionLines(_actionsOnlyPromptCache, excludedActions);
|
|
395
|
+
}
|
|
396
|
+
async function coreGetMcpPrompt() {
|
|
397
|
+
if (_mcpPromptCache == null) {
|
|
398
|
+
_mcpPromptCache = await readPromptFile('mcp-prompt.md', 'MCP system prompt');
|
|
399
|
+
}
|
|
400
|
+
return _mcpPromptCache;
|
|
401
|
+
}
|
|
402
|
+
async function coreDispatch(documentHandle, toolName, args, invokeOptions) {
|
|
403
|
+
if (!isRecord(args)) {
|
|
404
|
+
throw new errors.SuperDocCliError(`Tool arguments for ${toolName} must be an object.`, {
|
|
405
|
+
code: 'INVALID_ARGUMENT',
|
|
406
|
+
details: { toolName },
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
const sanitizedArgs = stripCorruptedToolArgKeys(args);
|
|
410
|
+
if (!isRecord(sanitizedArgs)) {
|
|
411
|
+
throw new errors.SuperDocCliError(`Tool arguments for ${toolName} must be an object.`, {
|
|
412
|
+
code: 'INVALID_ARGUMENT',
|
|
413
|
+
details: { toolName },
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
// Defense-in-depth for exclusion configs: a host that narrowed the advertised
|
|
417
|
+
// surface (getTools excludeActions) can pass the same list here so a
|
|
418
|
+
// guessed/injected call to an excluded action is refused, not run.
|
|
419
|
+
const exclusionOptions = invokeOptions;
|
|
420
|
+
if (toolName === 'superdoc_perform_action' &&
|
|
421
|
+
typeof sanitizedArgs.action === 'string' &&
|
|
422
|
+
exclusionOptions?.excludeActions?.includes(sanitizedArgs.action)) {
|
|
423
|
+
throw new errors.SuperDocCliError(`Action ${sanitizedArgs.action} is excluded by configuration.`, {
|
|
424
|
+
code: 'INVALID_ARGUMENT',
|
|
425
|
+
details: { toolName, action: sanitizedArgs.action, excluded: true },
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
let forwardOptions = invokeOptions;
|
|
429
|
+
if (exclusionOptions && 'excludeActions' in exclusionOptions) {
|
|
430
|
+
const { excludeActions: _ea, ...rest } = exclusionOptions;
|
|
431
|
+
forwardOptions = rest;
|
|
432
|
+
}
|
|
433
|
+
if (catalog.isAgentToolName(toolName)) {
|
|
434
|
+
validateAgentToolArgs(toolName, sanitizedArgs);
|
|
435
|
+
return dispatchAgentTool(documentHandle, toolName, sanitizedArgs, forwardOptions);
|
|
436
|
+
}
|
|
437
|
+
throw new errors.SuperDocCliError(`Unknown tool: ${toolName}`, {
|
|
438
|
+
code: 'TOOL_DISPATCH_NOT_FOUND',
|
|
439
|
+
details: { toolName, preset: 'core' },
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
const corePreset = {
|
|
443
|
+
id: 'core',
|
|
444
|
+
description: 'Actions-only LLM surface: superdoc_inspect (reads) and superdoc_perform_action (named, deterministic edit verbs). superdoc_execute_code exists but is WIP — dispatchable, not advertised.',
|
|
445
|
+
supportsCacheControl: true,
|
|
446
|
+
getTools: coreGetTools,
|
|
447
|
+
getCatalog: coreGetCatalog,
|
|
448
|
+
getSystemPrompt: coreGetSystemPrompt,
|
|
449
|
+
getMcpPrompt: coreGetMcpPrompt,
|
|
450
|
+
dispatch: coreDispatch,
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
exports.corePreset = corePreset;
|
|
454
|
+
exports.readPromptFile = readPromptFile;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `core` preset — actions-only LLM-facing surface.
|
|
3
|
+
*
|
|
4
|
+
* Two advertised tools: superdoc_inspect (read-only deterministic snapshots)
|
|
5
|
+
* and superdoc_perform_action (named, statically validated, deterministic edit
|
|
6
|
+
* verbs — the action registry in agent/actions.ts).
|
|
7
|
+
*
|
|
8
|
+
* superdoc_execute_code (model-authored JS against a synchronous in-host doc)
|
|
9
|
+
* is WIP: dispatchable for SDK callers, NOT advertised and NOT in the served
|
|
10
|
+
* system prompt until it ships behind a safety flag. The agent_apply /
|
|
11
|
+
* agent_verify / agent_operation tools are likewise dispatchable but never
|
|
12
|
+
* advertised.
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
import type { PresetDescriptor } from '../presets.js';
|
|
17
|
+
/** Exported for unit tests; production callers use the default candidates. */
|
|
18
|
+
export declare function readPromptFile(fileName: string, label: string, candidateDirs?: readonly string[]): Promise<string>;
|
|
19
|
+
export declare const corePreset: PresetDescriptor;
|
|
20
|
+
//# sourceMappingURL=core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/presets/core.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAkBH,OAAO,KAAK,EAKV,gBAAgB,EAIjB,MAAM,eAAe,CAAC;AAevB,8EAA8E;AAC9E,wBAAsB,cAAc,CAClC,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,aAAa,GAAE,SAAS,MAAM,EAA0B,GACvD,OAAO,CAAC,MAAM,CAAC,CAmCjB;AAuaD,eAAO,MAAM,UAAU,EAAE,gBAWxB,CAAC"}
|