@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.
Files changed (107) hide show
  1. package/dist/action-primitives/doc-index.cjs +215 -0
  2. package/dist/action-primitives/doc-index.d.ts +83 -0
  3. package/dist/action-primitives/doc-index.d.ts.map +1 -0
  4. package/dist/action-primitives/doc-index.js +211 -0
  5. package/dist/action-primitives/engine.cjs +204 -0
  6. package/dist/action-primitives/engine.d.ts +71 -0
  7. package/dist/action-primitives/engine.d.ts.map +1 -0
  8. package/dist/action-primitives/engine.js +196 -0
  9. package/dist/action-primitives/receipt.cjs +39 -0
  10. package/dist/action-primitives/receipt.d.ts +49 -0
  11. package/dist/action-primitives/receipt.d.ts.map +1 -0
  12. package/dist/action-primitives/receipt.js +32 -0
  13. package/dist/action-primitives/resolve.cjs +252 -0
  14. package/dist/action-primitives/resolve.d.ts +56 -0
  15. package/dist/action-primitives/resolve.d.ts.map +1 -0
  16. package/dist/action-primitives/resolve.js +246 -0
  17. package/dist/action-primitives/session-cache.cjs +43 -0
  18. package/dist/action-primitives/session-cache.d.ts +19 -0
  19. package/dist/action-primitives/session-cache.d.ts.map +1 -0
  20. package/dist/action-primitives/session-cache.js +37 -0
  21. package/dist/action-primitives/tools/list-transform.cjs +661 -0
  22. package/dist/action-primitives/tools/list-transform.d.ts +98 -0
  23. package/dist/action-primitives/tools/list-transform.d.ts.map +1 -0
  24. package/dist/action-primitives/tools/list-transform.js +656 -0
  25. package/dist/action-primitives/tools/structure-insert.cjs +1343 -0
  26. package/dist/action-primitives/tools/structure-insert.d.ts +183 -0
  27. package/dist/action-primitives/tools/structure-insert.d.ts.map +1 -0
  28. package/dist/action-primitives/tools/structure-insert.js +1338 -0
  29. package/dist/action-primitives/tools/text-transform.cjs +669 -0
  30. package/dist/action-primitives/tools/text-transform.d.ts +64 -0
  31. package/dist/action-primitives/tools/text-transform.d.ts.map +1 -0
  32. package/dist/action-primitives/tools/text-transform.js +664 -0
  33. package/dist/action-primitives/types.d.ts +36 -0
  34. package/dist/action-primitives/types.d.ts.map +1 -0
  35. package/dist/action-primitives/types.js +15 -0
  36. package/dist/agent/actions.cjs +5381 -0
  37. package/dist/agent/actions.d.ts +404 -0
  38. package/dist/agent/actions.d.ts.map +1 -0
  39. package/dist/agent/actions.js +5373 -0
  40. package/dist/agent/catalog.cjs +483 -0
  41. package/dist/agent/catalog.d.ts +103 -0
  42. package/dist/agent/catalog.d.ts.map +1 -0
  43. package/dist/agent/catalog.js +471 -0
  44. package/dist/agent/doc-snapshot.cjs +663 -0
  45. package/dist/agent/doc-snapshot.d.ts +247 -0
  46. package/dist/agent/doc-snapshot.d.ts.map +1 -0
  47. package/dist/agent/doc-snapshot.js +657 -0
  48. package/dist/agent/index.d.ts +16 -0
  49. package/dist/agent/index.d.ts.map +1 -0
  50. package/dist/agent/index.js +15 -0
  51. package/dist/agent/ir.cjs +170 -0
  52. package/dist/agent/ir.d.ts +216 -0
  53. package/dist/agent/ir.d.ts.map +1 -0
  54. package/dist/agent/ir.js +181 -0
  55. package/dist/agent/operation-catalog.cjs +418 -0
  56. package/dist/agent/operation-catalog.d.ts +36 -0
  57. package/dist/agent/operation-catalog.d.ts.map +1 -0
  58. package/dist/agent/operation-catalog.js +446 -0
  59. package/dist/agent/runtime.cjs +501 -0
  60. package/dist/agent/runtime.d.ts +120 -0
  61. package/dist/agent/runtime.d.ts.map +1 -0
  62. package/dist/agent/runtime.js +493 -0
  63. package/dist/embedded-prompts.generated.cjs +13 -0
  64. package/dist/embedded-prompts.generated.d.ts +4 -0
  65. package/dist/embedded-prompts.generated.d.ts.map +1 -0
  66. package/dist/embedded-prompts.generated.js +9 -0
  67. package/dist/generated/client.cjs +18 -20
  68. package/dist/generated/client.d.ts +723 -3223
  69. package/dist/generated/client.d.ts.map +1 -1
  70. package/dist/generated/client.js +18 -20
  71. package/dist/generated/contract.cjs +12898 -18467
  72. package/dist/generated/contract.d.ts.map +1 -1
  73. package/dist/generated/contract.js +12898 -18467
  74. package/dist/generated/intent-dispatch.generated.cjs +0 -1
  75. package/dist/generated/intent-dispatch.generated.d.ts.map +1 -1
  76. package/dist/generated/intent-dispatch.generated.js +0 -1
  77. package/dist/index.cjs +3 -7
  78. package/dist/index.d.ts +8 -6
  79. package/dist/index.d.ts.map +1 -1
  80. package/dist/index.js +2 -8
  81. package/dist/presets/core.cjs +454 -0
  82. package/dist/presets/core.d.ts +20 -0
  83. package/dist/presets/core.d.ts.map +1 -0
  84. package/dist/presets/core.js +447 -0
  85. package/dist/presets.cjs +55 -8
  86. package/dist/presets.d.ts +39 -8
  87. package/dist/presets.d.ts.map +1 -1
  88. package/dist/presets.js +53 -8
  89. package/dist/prompts/mcp-prompt.md +23 -0
  90. package/dist/prompts/system-prompt.md +108 -0
  91. package/dist/runtime/transport-common.cjs +8 -0
  92. package/dist/runtime/transport-common.d.ts.map +1 -1
  93. package/dist/runtime/transport-common.js +8 -0
  94. package/dist/tools.cjs +46 -11
  95. package/dist/tools.d.ts +55 -8
  96. package/dist/tools.d.ts.map +1 -1
  97. package/dist/tools.js +45 -13
  98. package/package.json +9 -8
  99. package/tools/__pycache__/__init__.cpython-312.pyc +0 -0
  100. package/tools/__pycache__/intent_dispatch_generated.cpython-312.pyc +0 -0
  101. package/tools/catalog.json +22 -178
  102. package/tools/intent_dispatch_generated.py +0 -2
  103. package/tools/tools-policy.json +1 -1
  104. package/tools/tools.anthropic.json +22 -158
  105. package/tools/tools.generic.json +23 -160
  106. package/tools/tools.openai.json +22 -158
  107. package/tools/tools.vercel.json +22 -158
@@ -0,0 +1,471 @@
1
+ import { SuperDocCliError } from '../runtime/errors.js';
2
+ import { ACTION_NAMES_LIST, ACTION_HINTS, ACTION_GROUPS, ACTION_ARGS } from './actions.js';
3
+ export const AGENT_TOOL_NAMES = [
4
+ 'superdoc_inspect',
5
+ 'superdoc_perform_action',
6
+ 'agent_apply',
7
+ 'agent_verify',
8
+ 'agent_operation',
9
+ 'superdoc_execute_code',
10
+ ];
11
+ /**
12
+ * The LLM-facing tool surface — exactly the tools shown to the model in
13
+ * `chooseTools(...)` / `listTools(...)`. All other `AGENT_TOOL_NAMES` remain
14
+ * dispatchable via `dispatchSuperDocTool` for SDK callers but are NOT
15
+ * advertised to the LLM.
16
+ */
17
+ export const PUBLIC_AGENT_TOOL_NAMES = [
18
+ 'superdoc_inspect',
19
+ 'superdoc_perform_action',
20
+ // superdoc_execute_code is deliberately NOT advertised: code execution is
21
+ // WIP and will return behind a safety flag. It remains dispatchable for SDK
22
+ // callers via dispatchSuperDocTool / preset.dispatch.
23
+ ];
24
+ export const SELECTOR_SCHEMA = {
25
+ type: 'object',
26
+ description: 'Deterministic selector. Examples: {kind:"nodeId",nodeId:"n12"}, {kind:"ordinal",ordinalKind:"bodyParagraphOrdinal",value:2}, {kind:"textSearch",terms:["Lender","Company"],match:"all"}, {kind:"placement",at:"document_end"}, {kind:"ref",ref:"selectedBlock"}.',
27
+ additionalProperties: true,
28
+ properties: {
29
+ kind: { type: 'string' },
30
+ },
31
+ };
32
+ /**
33
+ * Per-argument JSON schema for every `superdoc_perform_action` argument EXCEPT `action`.
34
+ * The single source of truth for each arg's JSON schema. ACTION_ARG_PROPERTIES
35
+ * selects the entries some action declares in ACTION_ARGS; the `superdoc_perform_action`
36
+ * tool advertises those after `action`.
37
+ */
38
+ export const ACTION_ARG_SCHEMA = {
39
+ text: { type: 'string' },
40
+ texts: { type: 'array', items: { type: 'string' } },
41
+ level: { type: 'number' },
42
+ headingText: { type: 'string' },
43
+ headingLevel: { type: 'number' },
44
+ kind: { type: 'string', enum: ['ordered', 'bullet'] },
45
+ items: { type: 'array', items: { type: 'string' } },
46
+ listOrdinal: { type: 'number' },
47
+ rows: { type: 'number' },
48
+ columns: { type: 'number' },
49
+ cellTexts: { type: 'array', items: {} },
50
+ edits: {
51
+ type: 'array',
52
+ items: {
53
+ type: 'object',
54
+ properties: { find: { type: 'string' }, replace: { type: 'string' } },
55
+ required: ['find'],
56
+ },
57
+ },
58
+ finds: { type: 'array', items: { type: 'string' } },
59
+ caseSensitive: { type: 'boolean' },
60
+ changeMode: { type: 'string', enum: ['direct', 'tracked'] },
61
+ placement: { type: 'object', additionalProperties: true, properties: {} },
62
+ selector: SELECTOR_SCHEMA,
63
+ selectors: { type: 'array', items: SELECTOR_SCHEMA },
64
+ commentText: { type: 'string' },
65
+ scope: { type: 'string', enum: ['all', 'body'] },
66
+ excludeBlockQuotes: { type: 'boolean' },
67
+ author: { type: 'string' },
68
+ changeType: { type: 'string', enum: ['insert', 'delete', 'replacement', 'format'] },
69
+ fontSize: { type: 'number' },
70
+ fontFamily: { type: 'string' },
71
+ color: { type: 'string' },
72
+ targetText: { type: 'string' },
73
+ letterSpacing: { type: 'number' },
74
+ values: { type: 'array', items: { type: 'string' } },
75
+ fields: {
76
+ type: 'array',
77
+ items: {
78
+ type: 'object',
79
+ properties: {
80
+ label: { type: 'string' },
81
+ value: { type: 'string' },
82
+ },
83
+ required: ['value'],
84
+ },
85
+ },
86
+ title: { type: 'string' },
87
+ tableOrdinal: { type: 'number' },
88
+ rowIndex: { type: 'number' },
89
+ columnIndex: { type: 'number' },
90
+ position: { type: 'string' },
91
+ dryRun: { type: 'boolean' },
92
+ headerText: { type: 'string' },
93
+ separatorText: { type: 'string' },
94
+ anchorText: { type: 'string' },
95
+ targetTexts: { type: 'array', items: { type: 'string' } },
96
+ bold: { type: 'boolean' },
97
+ italic: { type: 'boolean' },
98
+ underline: { type: 'boolean' },
99
+ strike: { type: 'boolean' },
100
+ highlight: { type: 'string' },
101
+ styleId: { type: 'string' },
102
+ likeText: { type: 'string' },
103
+ fromMarker: { type: 'string' },
104
+ toMarker: { type: 'string' },
105
+ fromText: { type: 'string' },
106
+ toText: { type: 'string' },
107
+ untilMarker: { type: 'string' },
108
+ steps: { type: 'number' },
109
+ likeMarker: { type: 'string' },
110
+ nodeId: { type: 'string' },
111
+ alignment: { type: 'string', enum: ['left', 'center', 'right', 'justify'] },
112
+ afterText: { type: 'string' },
113
+ beforeText: { type: 'string' },
114
+ accentColor: { type: 'string' },
115
+ entries: {
116
+ type: 'array',
117
+ items: {
118
+ type: 'object',
119
+ properties: { text: { type: 'string' }, level: { type: 'number' } },
120
+ required: ['text'],
121
+ },
122
+ },
123
+ lineSpacing: { type: 'number' },
124
+ spaceBefore: { type: 'number' },
125
+ spaceAfter: { type: 'number' },
126
+ url: { type: 'string' },
127
+ tooltip: { type: 'string' },
128
+ reopen: { type: 'boolean' },
129
+ commentId: { type: 'string' },
130
+ restartNumbering: { type: 'boolean' },
131
+ };
132
+ /**
133
+ * The args the `superdoc_perform_action` tool advertises for a given action
134
+ * set, GENERATED from the registry: a property appears iff some INCLUDED
135
+ * action declares it in `ACTION_ARGS`. This makes `ACTION_ARGS` the authority
136
+ * (the schema can no longer drift from what actions actually accept) and
137
+ * guards both directions:
138
+ * - a declared arg with no schema entry throws (caught in CI/build),
139
+ * - a schema entry no included action uses is pruned (dead args can't
140
+ * accumulate, and excluding actions also drops their private args).
141
+ * Order follows ACTION_ARG_SCHEMA so the advertised tool stays stable.
142
+ */
143
+ function buildActionArgProperties(includedActions) {
144
+ const declared = new Set(includedActions.flatMap((name) => ACTION_ARGS[name] ?? []));
145
+ for (const arg of declared) {
146
+ if (!(arg in ACTION_ARG_SCHEMA)) {
147
+ throw new Error(`ACTION_ARGS declares "${arg}" but ACTION_ARG_SCHEMA has no schema for it.`);
148
+ }
149
+ }
150
+ const props = {};
151
+ for (const [arg, schema] of Object.entries(ACTION_ARG_SCHEMA)) {
152
+ if (declared.has(arg))
153
+ props[arg] = schema;
154
+ }
155
+ return props;
156
+ }
157
+ const VERIFICATION_CHECK_SCHEMA = {
158
+ type: 'object',
159
+ description: 'Verification check. Examples: {kind:"revision-changed"}, {kind:"block-text-contains",nodeId:"n12",text:"Hello"}, {kind:"table-shape",nodeId:"tbl-1",rows:2,columns:2}.',
160
+ additionalProperties: true,
161
+ properties: {
162
+ kind: { type: 'string' },
163
+ },
164
+ };
165
+ const PLAN_STEP_SCHEMA = {
166
+ type: 'object',
167
+ description: 'IR step. Supported kinds: inspect, select, apply, verify. Apply steps use a generated doc.* operation id in operationId plus args.',
168
+ additionalProperties: true,
169
+ properties: {
170
+ kind: { type: 'string' },
171
+ operationId: { type: 'string' },
172
+ args: {
173
+ type: 'object',
174
+ additionalProperties: true,
175
+ properties: {},
176
+ description: 'Operation arguments. Do not include doc or sessionId. Use exact generated operation arguments for doc.* calls.',
177
+ },
178
+ selector: SELECTOR_SCHEMA,
179
+ checks: {
180
+ type: 'array',
181
+ items: VERIFICATION_CHECK_SCHEMA,
182
+ },
183
+ bind: { type: 'string' },
184
+ requireUnique: { type: 'boolean' },
185
+ rationale: { type: 'string' },
186
+ changeMode: { type: 'string', enum: ['direct', 'tracked'] },
187
+ atomic: { type: 'boolean' },
188
+ saveReopen: { type: 'boolean' },
189
+ },
190
+ };
191
+ /**
192
+ * Render the superdoc_perform_action description from the action registry
193
+ * (ACTION_NAMES_LIST + ACTION_HINTS + ACTION_GROUPS in actions.ts). The
194
+ * registry is the single source of truth — adding a action there is the whole
195
+ * job; this string and the schema enum follow automatically.
196
+ *
197
+ * `included` (optional) narrows the description to a subset of actions —
198
+ * groups whose actions are all excluded disappear entirely.
199
+ */
200
+ function buildActionDescription(included) {
201
+ const grouped = ACTION_GROUPS.map((group) => {
202
+ const actions = included ? group.actions.filter((name) => included.has(name)) : [...group.actions];
203
+ if (actions.length === 0)
204
+ return null;
205
+ return `${group.label}: ${actions.map((name) => `${name} (${ACTION_HINTS[name]})`).join(', ')}.`;
206
+ })
207
+ .filter((entry) => entry != null)
208
+ .join(' ');
209
+ return ('High-level deterministic document edit. Pick a action and pass flat product-facing arguments. ' +
210
+ 'Actions wrap the most common doc.* operations and return real pre/post evidence and verification. ' +
211
+ grouped +
212
+ ' placement: {at:"document_end"|"document_start"|"after"|"before", selector?}.' +
213
+ ' selector: {kind:"nodeId",nodeId} | {kind:"ordinal",ordinalKind:"bodyParagraphOrdinal"|"paragraphOrdinal"|"headingOrdinal"|"tableOrdinal"|"listOrdinal"|"sectionOrdinal"|"blockOrdinal",value:N} | {kind:"tableCell",tableOrdinal,rowIndex,columnIndex} | {kind:"textSearch",terms:[...],match?:"all"|"any",occurrence?:N,nodeTypes?:["paragraph"|"heading"|"listItem"]} | {kind:"placement",at:"document_end"|"document_start"} | {kind:"relative",position:"after"|"before",target:selector}.');
214
+ }
215
+ /**
216
+ * Build the `superdoc_perform_action` tool definition for a given action set.
217
+ * The default (all actions) is what `AGENT_TOOL_DEFINITIONS` carries; callers
218
+ * excluding actions get a coherently narrowed definition: enum, grouped
219
+ * description, AND the advertised argument properties all shrink together
220
+ * (an arg no remaining action declares is not advertised).
221
+ */
222
+ function buildPerformActionDefinition(includedActions) {
223
+ const included = new Set(includedActions);
224
+ return {
225
+ name: 'superdoc_perform_action',
226
+ description: buildActionDescription(included.size === ACTION_NAMES_LIST.length ? undefined : included),
227
+ inputSchema: {
228
+ type: 'object',
229
+ additionalProperties: true,
230
+ required: ['action'],
231
+ properties: {
232
+ action: {
233
+ type: 'string',
234
+ enum: [...includedActions],
235
+ },
236
+ ...buildActionArgProperties(includedActions),
237
+ },
238
+ },
239
+ };
240
+ }
241
+ export const AGENT_TOOL_DEFINITIONS = [
242
+ {
243
+ name: 'superdoc_inspect',
244
+ description: 'Build a deterministic document snapshot. Prefer the narrowest inspect that answers the question: countsOnly for pure counts, includeDomains to limit which domains are returned, and blockNodeTypes when only specific block types matter. For LARGE documents, read in windows: blockOffset/blockLimit return a contiguous slice of blocks (ordinals are absolute, so windows line up), and omitEmptyBlocks/dropTextPreview trim payload for a reading pass.',
245
+ inputSchema: {
246
+ type: 'object',
247
+ additionalProperties: false,
248
+ properties: {
249
+ countsOnly: { type: 'boolean' },
250
+ blockOffset: { type: 'number', minimum: 0 },
251
+ blockLimit: { type: 'number', minimum: 1 },
252
+ omitEmptyBlocks: { type: 'boolean' },
253
+ dropTextPreview: { type: 'boolean' },
254
+ includeDomains: {
255
+ type: 'array',
256
+ items: {
257
+ type: 'string',
258
+ enum: [
259
+ 'blocks',
260
+ 'lists',
261
+ 'tables',
262
+ 'comments',
263
+ 'trackedChanges',
264
+ 'sections',
265
+ 'headerFooters',
266
+ 'styles',
267
+ 'contentControls',
268
+ 'fields',
269
+ 'hyperlinks',
270
+ 'bookmarks',
271
+ 'permissionRanges',
272
+ 'images',
273
+ ],
274
+ },
275
+ },
276
+ blockNodeTypes: {
277
+ type: 'array',
278
+ items: { type: 'string' },
279
+ },
280
+ blockTextLimit: { type: 'number', minimum: 1 },
281
+ listLimit: { type: 'number', minimum: 1 },
282
+ tableLimit: { type: 'number', minimum: 1 },
283
+ commentLimit: { type: 'number', minimum: 1 },
284
+ trackedChangeLimit: { type: 'number', minimum: 1 },
285
+ },
286
+ },
287
+ },
288
+ // Generated from the action registry (ACTION_NAMES_LIST + ACTION_ARGS):
289
+ // enum, description, and advertised args all derive from the same source,
290
+ // so the schema can no longer drift from what actions accept.
291
+ buildPerformActionDefinition(ACTION_NAMES_LIST),
292
+ {
293
+ name: 'agent_apply',
294
+ description: 'Execute a validated inspect/select/apply/verify IR plan. Use this for most document edits. Returns pre/post evidence, selected targets, executed operations, verification results, and save evidence when required.',
295
+ inputSchema: {
296
+ type: 'object',
297
+ additionalProperties: false,
298
+ required: ['plan'],
299
+ properties: {
300
+ plan: {
301
+ type: 'object',
302
+ additionalProperties: false,
303
+ required: ['intent', 'steps'],
304
+ properties: {
305
+ intent: { type: 'string' },
306
+ steps: {
307
+ type: 'array',
308
+ minItems: 1,
309
+ items: PLAN_STEP_SCHEMA,
310
+ },
311
+ preconditions: { type: 'array', items: { type: 'string' } },
312
+ postconditions: { type: 'array', items: { type: 'string' } },
313
+ atomic: { type: 'boolean' },
314
+ expectedDiff: {
315
+ type: 'object',
316
+ additionalProperties: false,
317
+ properties: {
318
+ blocksAdded: { type: 'number' },
319
+ blocksRemoved: { type: 'number' },
320
+ textReplacements: { type: 'number' },
321
+ commentsAdded: { type: 'number' },
322
+ trackedChangesAdded: { type: 'number' },
323
+ },
324
+ },
325
+ },
326
+ },
327
+ },
328
+ },
329
+ },
330
+ {
331
+ name: 'agent_verify',
332
+ description: 'Run verification checks against the current document state. Use for explicit postcondition proof or save/reopen verification.',
333
+ inputSchema: {
334
+ type: 'object',
335
+ additionalProperties: false,
336
+ required: ['checks'],
337
+ properties: {
338
+ checks: {
339
+ type: 'array',
340
+ minItems: 1,
341
+ items: VERIFICATION_CHECK_SCHEMA,
342
+ },
343
+ saveReopen: { type: 'boolean' },
344
+ },
345
+ },
346
+ },
347
+ {
348
+ name: 'agent_operation',
349
+ description: 'Controlled escape hatch for a single generated doc.* operation. Prefer agent_apply first; use this when you need an exact generated operation id.',
350
+ inputSchema: {
351
+ type: 'object',
352
+ additionalProperties: false,
353
+ required: ['operationId'],
354
+ properties: {
355
+ operationId: {
356
+ type: 'string',
357
+ description: 'Exact generated operation id such as doc.replace or doc.comments.create.',
358
+ },
359
+ args: {
360
+ type: 'object',
361
+ additionalProperties: true,
362
+ properties: {},
363
+ description: 'Operation arguments. Do not include doc or sessionId.',
364
+ },
365
+ readOnly: { type: 'boolean' },
366
+ },
367
+ },
368
+ },
369
+ {
370
+ // superdoc_execute_code: in-host JS escape hatch for COMPLEX / MULTI-STEP workflows
371
+ // (loops, per-item branching, extract-then-generate). Dispatches to the
372
+ // CLI/SDK-only `doc.executeCode` session op, which runs the model's code
373
+ // against the live SYNCHRONOUS editor.doc. Schema mirrors the hybrid-agent
374
+ // EXECUTE_CODE_TOOL ({ code: string }, required). See dispatchSuperDocTool.
375
+ name: 'superdoc_execute_code',
376
+ description: 'Run a JavaScript snippet against the live SuperDoc Document API for a complex or multi-step workflow (loops, per-item branching, extract-then-generate). Use this instead of unrolling many action calls. The code runs IN-HOST against a SYNCHRONOUS `doc` — do NOT await doc.* calls; they return their receipt directly. Two globals are injected: `doc` (synchronous Document API) and `console`. `return` a short summary. Do NOT call doc.save/close.',
377
+ inputSchema: {
378
+ type: 'object',
379
+ additionalProperties: false,
380
+ required: ['code'],
381
+ properties: {
382
+ code: {
383
+ type: 'string',
384
+ description: 'JavaScript body executed as an async function IN-HOST. Has access to `doc` (SYNCHRONOUS — do NOT await doc.* calls) and `console`. Return a short summary value.',
385
+ },
386
+ },
387
+ },
388
+ },
389
+ ];
390
+ const AGENT_TOOL_NAME_SET = new Set(AGENT_TOOL_NAMES);
391
+ function toOpenAiTool(definition) {
392
+ return {
393
+ type: 'function',
394
+ function: {
395
+ name: definition.name,
396
+ description: definition.description,
397
+ parameters: definition.inputSchema,
398
+ },
399
+ };
400
+ }
401
+ function toAnthropicTool(definition) {
402
+ return {
403
+ name: definition.name,
404
+ description: definition.description,
405
+ input_schema: definition.inputSchema,
406
+ };
407
+ }
408
+ function toGenericTool(definition) {
409
+ return {
410
+ name: definition.name,
411
+ description: definition.description,
412
+ parameters: definition.inputSchema,
413
+ };
414
+ }
415
+ function toVercelTool(definition) {
416
+ return {
417
+ name: definition.name,
418
+ description: definition.description,
419
+ inputSchema: definition.inputSchema,
420
+ };
421
+ }
422
+ function toProviderTool(provider, definition) {
423
+ if (provider === 'anthropic')
424
+ return toAnthropicTool(definition);
425
+ if (provider === 'generic')
426
+ return toGenericTool(definition);
427
+ // AI SDK dialect: flat {name, description, inputSchema} for tool()/jsonSchema().
428
+ if (provider === 'vercel')
429
+ return toVercelTool(definition);
430
+ return toOpenAiTool(definition);
431
+ }
432
+ export function validateExclusions(options) {
433
+ const excludedActions = new Set(options?.excludeActions ?? []);
434
+ const knownActions = new Set(ACTION_NAMES_LIST);
435
+ for (const name of excludedActions) {
436
+ if (!knownActions.has(name)) {
437
+ throw new SuperDocCliError(`excludeActions: unknown action "${name}".`, {
438
+ code: 'INVALID_ARGUMENT',
439
+ details: { unknownAction: name, knownActions: [...knownActions] },
440
+ });
441
+ }
442
+ }
443
+ return { excludedActions };
444
+ }
445
+ /**
446
+ * Tools advertised to the LLM. Only PUBLIC_AGENT_TOOL_NAMES (currently
447
+ * superdoc_inspect + superdoc_perform_action) are returned; the remaining
448
+ * AGENT_TOOL_NAMES (agent_apply, agent_verify, agent_operation,
449
+ * superdoc_execute_code) stay dispatchable but invisible to the model.
450
+ *
451
+ * `options.excludeActions` narrows the action surface for customers who
452
+ * don't want the model to see certain capabilities.
453
+ */
454
+ export function listAgentTools(provider, options) {
455
+ const { excludedActions } = validateExclusions(options);
456
+ const publicSet = new Set(PUBLIC_AGENT_TOOL_NAMES);
457
+ const includedActions = ACTION_NAMES_LIST.filter((name) => !excludedActions.has(name));
458
+ return AGENT_TOOL_DEFINITIONS.filter((d) => publicSet.has(d.name))
459
+ .flatMap((definition) => {
460
+ if (definition.name !== 'superdoc_perform_action' || excludedActions.size === 0)
461
+ return [definition];
462
+ // Every action excluded → the tool has nothing to offer; drop it.
463
+ if (includedActions.length === 0)
464
+ return [];
465
+ return [buildPerformActionDefinition(includedActions)];
466
+ })
467
+ .map((definition) => toProviderTool(provider, definition));
468
+ }
469
+ export function isAgentToolName(toolName) {
470
+ return AGENT_TOOL_NAME_SET.has(toolName);
471
+ }