@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,446 @@
1
+ /**
2
+ * Operation catalog derived from the generated contract.
3
+ *
4
+ * This module turns every `doc.*` operation in `generated/contract.ts` into a
5
+ * row classified by domain, mutating vs read, target shape, change-mode
6
+ * support, dry-run support, atomicity, verification hints, exposure status,
7
+ * and action eligibility. The classification is built deterministically from
8
+ * the contract so the catalog cannot silently drift out of sync.
9
+ *
10
+ * The catalog is the source of truth used by:
11
+ * - the IR validator (every IR operation must resolve to a catalog row)
12
+ * - anti-overfit gates (tests that assert every generated operation is
13
+ * classified)
14
+ * - holdout-style conformance checks
15
+ *
16
+ * Do not hand-classify operations here. Add rules to the derivation pass.
17
+ */
18
+ import { CONTRACT } from '../generated/contract.js';
19
+ const MUTATING_VERBS = new Set([
20
+ 'insert',
21
+ 'create',
22
+ 'delete',
23
+ 'remove',
24
+ 'patch',
25
+ 'update',
26
+ 'set',
27
+ 'apply',
28
+ 'replace',
29
+ 'rewrite',
30
+ 'merge',
31
+ 'split',
32
+ 'attach',
33
+ 'detach',
34
+ 'rebuild',
35
+ 'configure',
36
+ 'rename',
37
+ 'clear',
38
+ 'clearcontent',
39
+ 'append',
40
+ 'appendcontent',
41
+ 'indent',
42
+ 'outdent',
43
+ 'decide',
44
+ 'continueprevious',
45
+ 'setlevel',
46
+ 'setvalue',
47
+ 'settype',
48
+ 'setstate',
49
+ 'undo',
50
+ 'redo',
51
+ 'insertlinebreak',
52
+ 'inserttab',
53
+ 'mutations',
54
+ 'commit',
55
+ 'rollback',
56
+ 'transact',
57
+ ]);
58
+ const READ_VERBS = new Set([
59
+ 'get',
60
+ 'list',
61
+ 'find',
62
+ 'info',
63
+ 'capabilities',
64
+ 'extract',
65
+ 'gettext',
66
+ 'gethtml',
67
+ 'getmarkdown',
68
+ 'getnode',
69
+ 'getnodebyid',
70
+ 'diff',
71
+ 'history',
72
+ 'describe',
73
+ 'describecommand',
74
+ 'status',
75
+ 'query',
76
+ 'markdowntofragment',
77
+ 'getstate',
78
+ ]);
79
+ const SESSION_OP_IDS = new Set(['doc.open', 'doc.close', 'doc.save', 'doc.session']);
80
+ const META_OP_IDS = new Set(['doc.describe', 'doc.describeCommand', 'doc.capabilities.get', 'doc.status']);
81
+ const BENCHMARK_ONLY_HINTS = [
82
+ // Anything we explicitly mark as not for product-default coverage. Empty
83
+ // for now — concrete benchmark surfaces live in profile config, not the
84
+ // contract-derived catalog.
85
+ ];
86
+ function tokensFromOperationId(operationId) {
87
+ return operationId.split('.').slice(1);
88
+ }
89
+ function lastToken(operationId) {
90
+ const tokens = tokensFromOperationId(operationId);
91
+ return (tokens[tokens.length - 1] ?? '').toLowerCase();
92
+ }
93
+ function deriveDomain(operationId) {
94
+ const tokens = tokensFromOperationId(operationId);
95
+ const first = (tokens[0] ?? '').toLowerCase();
96
+ switch (first) {
97
+ case 'open':
98
+ case 'close':
99
+ case 'save':
100
+ case 'session':
101
+ return 'session';
102
+ case 'describe':
103
+ case 'describecommand':
104
+ case 'capabilities':
105
+ case 'status':
106
+ return 'meta';
107
+ case 'gettext':
108
+ case 'getmarkdown':
109
+ case 'gethtml':
110
+ case 'getnode':
111
+ case 'getnodebyid':
112
+ case 'info':
113
+ case 'extract':
114
+ case 'find':
115
+ case 'markdowntofragment':
116
+ return 'document-read';
117
+ case 'create':
118
+ // create.* domain-specific; classify by sub-domain
119
+ switch ((tokens[1] ?? '').toLowerCase()) {
120
+ case 'table':
121
+ return 'tables';
122
+ case 'image':
123
+ return 'images';
124
+ case 'paragraph':
125
+ case 'heading':
126
+ case 'sectionbreak':
127
+ case 'tableofcontents':
128
+ return 'blocks';
129
+ default:
130
+ return 'document-write';
131
+ }
132
+ case 'blocks':
133
+ return 'blocks';
134
+ case 'text':
135
+ case 'replace':
136
+ case 'delete':
137
+ case 'insert':
138
+ case 'insertlinebreak':
139
+ case 'inserttab':
140
+ case 'clearcontent':
141
+ return 'text';
142
+ case 'format':
143
+ return 'format';
144
+ case 'styles':
145
+ return 'styles';
146
+ case 'lists':
147
+ return 'lists';
148
+ case 'tables':
149
+ return 'tables';
150
+ case 'images':
151
+ return 'images';
152
+ case 'comments':
153
+ return 'comments';
154
+ case 'trackchanges':
155
+ return 'tracked-changes';
156
+ case 'sections':
157
+ return 'sections';
158
+ case 'fields':
159
+ return 'fields';
160
+ case 'hyperlinks':
161
+ return 'hyperlinks';
162
+ case 'bookmarks':
163
+ return 'bookmarks';
164
+ case 'crossrefs':
165
+ return 'cross-refs';
166
+ case 'footnotes':
167
+ return 'footnotes';
168
+ case 'headerfooters':
169
+ return 'header-footer';
170
+ case 'contentcontrols':
171
+ return 'content-controls';
172
+ case 'permissionranges':
173
+ return 'permission-ranges';
174
+ case 'protection':
175
+ return 'protection';
176
+ case 'toc':
177
+ return 'toc';
178
+ case 'authorities':
179
+ return 'authorities';
180
+ case 'captions':
181
+ return 'captions';
182
+ case 'citations':
183
+ return 'citations';
184
+ case 'mutations':
185
+ return 'mutations';
186
+ case 'selection':
187
+ return 'selection';
188
+ case 'history':
189
+ return 'history';
190
+ case 'index':
191
+ return 'index';
192
+ case 'query':
193
+ return 'query';
194
+ case 'ranges':
195
+ return 'ranges';
196
+ case 'diff':
197
+ return 'diff';
198
+ case 'get':
199
+ return 'document-read';
200
+ default:
201
+ return 'document-write';
202
+ }
203
+ }
204
+ function deriveMode(operationId, entry) {
205
+ if (SESSION_OP_IDS.has(operationId))
206
+ return 'session';
207
+ const last = lastToken(operationId);
208
+ if (READ_VERBS.has(last))
209
+ return 'read';
210
+ if (entry?.mutates === true)
211
+ return 'write';
212
+ if (MUTATING_VERBS.has(last))
213
+ return 'write';
214
+ // Operations that don't end with a mutating verb but still mutate (e.g.
215
+ // doc.replace, doc.delete) are caught by the verb sets above or by the
216
+ // generated contract's `mutates` flag; the rest default to read.
217
+ if (last === 'replace' || last === 'delete' || last === 'insert')
218
+ return 'write';
219
+ return 'read';
220
+ }
221
+ function deriveTargetShape(operationId) {
222
+ const tokens = tokensFromOperationId(operationId).map((t) => t.toLowerCase());
223
+ if (tokens.length === 0)
224
+ return 'document';
225
+ if (tokens[0] === 'blocks')
226
+ return 'block';
227
+ if (tokens[0] === 'tables')
228
+ return 'table';
229
+ if (tokens[0] === 'lists')
230
+ return 'list';
231
+ if (tokens[0] === 'images')
232
+ return 'image';
233
+ if (tokens[0] === 'comments')
234
+ return 'comment';
235
+ if (tokens[0] === 'sections' || tokens[0] === 'headerfooters')
236
+ return 'document';
237
+ if (tokens[0] === 'find' || tokens[0] === 'query')
238
+ return 'range';
239
+ if (tokens[0] === 'selection' || tokens[0] === 'ranges')
240
+ return 'range';
241
+ if (tokens[0] === 'mutations')
242
+ return 'mixed';
243
+ if (tokens[0] === 'create')
244
+ return 'document';
245
+ if (tokens[0] === 'trackchanges' ||
246
+ tokens[0] === 'bookmarks' ||
247
+ tokens[0] === 'hyperlinks' ||
248
+ tokens[0] === 'crossrefs' ||
249
+ tokens[0] === 'footnotes' ||
250
+ tokens[0] === 'fields' ||
251
+ tokens[0] === 'permissionranges' ||
252
+ tokens[0] === 'contentcontrols' ||
253
+ tokens[0] === 'captions' ||
254
+ tokens[0] === 'authorities' ||
255
+ tokens[0] === 'citations') {
256
+ return 'entity';
257
+ }
258
+ if (tokens[0] === 'format' || tokens[0] === 'styles')
259
+ return 'range';
260
+ if (tokens[0] === 'index')
261
+ return 'document';
262
+ return 'none';
263
+ }
264
+ function hasParam(params, name) {
265
+ if (!params)
266
+ return false;
267
+ return params.some((p) => p?.name === name);
268
+ }
269
+ function deriveSupportsChangeMode(entry) {
270
+ return hasParam(entry.params, 'changeMode');
271
+ }
272
+ function deriveSupportsDryRun(entry) {
273
+ return hasParam(entry.params, 'dryRun');
274
+ }
275
+ function deriveAtomic(operationId, entry) {
276
+ // All mutating operations are atomic by contract: each operation either
277
+ // succeeds end-to-end or fails. doc.mutations.apply is the only batched
278
+ // form and is explicitly atomic when its `atomic` flag is set.
279
+ if (operationId === 'doc.mutations.apply')
280
+ return hasParam(entry.params, 'atomic');
281
+ return deriveMode(operationId, entry) === 'write';
282
+ }
283
+ function deriveVerificationHints(operationId) {
284
+ const domain = deriveDomain(operationId);
285
+ const hints = [];
286
+ switch (domain) {
287
+ case 'blocks':
288
+ case 'text':
289
+ hints.push('reread-block-text', 'verify-revision');
290
+ break;
291
+ case 'tables':
292
+ hints.push('reread-table-shape', 'verify-cell-text');
293
+ break;
294
+ case 'lists':
295
+ hints.push('reread-list-items', 'verify-list-count');
296
+ break;
297
+ case 'images':
298
+ hints.push('reread-image-anchor', 'verify-image-id');
299
+ break;
300
+ case 'comments':
301
+ hints.push('list-comments', 'verify-anchor-text');
302
+ break;
303
+ case 'tracked-changes':
304
+ hints.push('list-tracked-changes', 'verify-counts');
305
+ break;
306
+ case 'format':
307
+ case 'styles':
308
+ hints.push('reread-resolved-style', 'verify-revision');
309
+ break;
310
+ case 'sections':
311
+ case 'header-footer':
312
+ hints.push('reread-section-shape', 'save-reopen');
313
+ break;
314
+ case 'protection':
315
+ case 'permission-ranges':
316
+ hints.push('save-reopen', 'verify-xml-shape');
317
+ break;
318
+ case 'document-write':
319
+ case 'mutations':
320
+ hints.push('verify-revision', 'verify-text-snapshot');
321
+ break;
322
+ default:
323
+ hints.push('verify-revision');
324
+ }
325
+ return hints;
326
+ }
327
+ function deriveStoryHints(entry) {
328
+ const hints = [];
329
+ if (hasParam(entry.params, 'in'))
330
+ hints.push('story-scoped');
331
+ if (hasParam(entry.params, 'story'))
332
+ hints.push('story-scoped');
333
+ if (hasParam(entry.params, 'sectionId'))
334
+ hints.push('section-scoped');
335
+ return hints;
336
+ }
337
+ function deriveDomainHints(entry) {
338
+ const hints = new Set();
339
+ for (const param of entry.params ?? []) {
340
+ if (!param?.name)
341
+ continue;
342
+ if (param.name === 'changeMode')
343
+ hints.add('change-mode');
344
+ if (param.name === 'dryRun')
345
+ hints.add('dry-run');
346
+ if (param.name === 'atomic')
347
+ hints.add('atomic-batch');
348
+ if (param.name === 'force')
349
+ hints.add('force-allowed');
350
+ if (param.name === 'preserveStyle')
351
+ hints.add('preserve-style');
352
+ if (param.name === 'caseSensitive')
353
+ hints.add('case-sensitive');
354
+ }
355
+ if (typeof entry.category === 'string') {
356
+ hints.add(`category:${entry.category}`);
357
+ }
358
+ return [...hints];
359
+ }
360
+ function deriveExposure(operationId) {
361
+ if (META_OP_IDS.has(operationId))
362
+ return 'internal';
363
+ if (BENCHMARK_ONLY_HINTS.includes(operationId))
364
+ return 'benchmark-only';
365
+ if (operationId.startsWith('doc.session.'))
366
+ return 'internal';
367
+ return 'stable';
368
+ }
369
+ function deriveActionEligible(operationId) {
370
+ if (SESSION_OP_IDS.has(operationId))
371
+ return false;
372
+ if (META_OP_IDS.has(operationId))
373
+ return false;
374
+ if (deriveExposure(operationId) === 'internal')
375
+ return false;
376
+ return true;
377
+ }
378
+ function classifyEntry(operationId, entry) {
379
+ const mode = deriveMode(operationId, entry);
380
+ return {
381
+ operationId,
382
+ domain: deriveDomain(operationId),
383
+ mode,
384
+ isMutating: mode === 'write',
385
+ targetShape: deriveTargetShape(operationId),
386
+ storyHints: deriveStoryHints(entry),
387
+ domainHints: deriveDomainHints(entry),
388
+ supportsChangeMode: deriveSupportsChangeMode(entry),
389
+ supportsDryRun: deriveSupportsDryRun(entry),
390
+ atomic: deriveAtomic(operationId, entry),
391
+ verificationHints: deriveVerificationHints(operationId),
392
+ exposure: deriveExposure(operationId),
393
+ actionEligible: deriveActionEligible(operationId),
394
+ description: typeof entry.description === 'string'
395
+ ? entry.description
396
+ : '',
397
+ };
398
+ }
399
+ function buildCatalog() {
400
+ const entries = [];
401
+ for (const [operationId, entry] of Object.entries(CONTRACT.operations)) {
402
+ entries.push(classifyEntry(operationId, entry));
403
+ }
404
+ entries.sort((a, b) => a.operationId.localeCompare(b.operationId));
405
+ return entries;
406
+ }
407
+ /** Full operation catalog derived from the generated contract. */
408
+ export const OPERATION_CATALOG = Object.freeze(buildCatalog());
409
+ const CATALOG_BY_ID = new Map(OPERATION_CATALOG.map((entry) => [entry.operationId, entry]));
410
+ export function getOperationCatalogEntry(operationId) {
411
+ return CATALOG_BY_ID.get(operationId);
412
+ }
413
+ export function listOperationsByDomain(domain) {
414
+ return OPERATION_CATALOG.filter((entry) => entry.domain === domain);
415
+ }
416
+ export function listMutatingOperations() {
417
+ return OPERATION_CATALOG.filter((entry) => entry.isMutating);
418
+ }
419
+ /** Returns operations that are classified but have no specific verification hint other than verify-revision. */
420
+ export function listOperationsMissingStructuralVerification() {
421
+ return OPERATION_CATALOG.filter((entry) => entry.isMutating && entry.verificationHints.length === 1 && entry.verificationHints[0] === 'verify-revision');
422
+ }
423
+ export function getOperationCatalogSummary() {
424
+ const byDomain = {};
425
+ const byMode = {};
426
+ const byExposure = {};
427
+ let mutatingCount = 0;
428
+ let actionEligibleCount = 0;
429
+ for (const entry of OPERATION_CATALOG) {
430
+ byDomain[entry.domain] = (byDomain[entry.domain] ?? 0) + 1;
431
+ byMode[entry.mode] = (byMode[entry.mode] ?? 0) + 1;
432
+ byExposure[entry.exposure] = (byExposure[entry.exposure] ?? 0) + 1;
433
+ if (entry.isMutating)
434
+ mutatingCount += 1;
435
+ if (entry.actionEligible)
436
+ actionEligibleCount += 1;
437
+ }
438
+ return {
439
+ total: OPERATION_CATALOG.length,
440
+ byDomain,
441
+ byMode,
442
+ byExposure,
443
+ mutatingCount,
444
+ actionEligibleCount,
445
+ };
446
+ }