@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
package/dist/presets.js CHANGED
@@ -8,10 +8,10 @@
8
8
  *
9
9
  * const { tools, meta } = await chooseTools({ provider: 'vercel', preset: 'legacy' });
10
10
  *
11
- * v1 ships a single preset: `'legacy'` a thin wrapper around today's
12
- * codegen-emitted intent tools. When callers omit `preset`, `legacy` is used.
13
- * The default may move once a replacement preset reaches parity; bumping it is
14
- * a coordinated change in this file alone.
11
+ * Two presets ship built-in: `'legacy'` (codegen-emitted intent tools; the
12
+ * default when callers omit `preset`) and `'core'` (the actions-only LLM
13
+ * surface). The default may move once core fully replaces legacy; bumping it
14
+ * is a coordinated change in this file alone.
15
15
  *
16
16
  * Presets are NOT versioned. The preset id encodes the variant; a new shape
17
17
  * ships as a new id, not a new version of an existing one.
@@ -20,22 +20,67 @@
20
20
  */
21
21
  import { SuperDocCliError } from './runtime/errors.js';
22
22
  import { legacyPreset } from './presets/legacy.js';
23
+ import { corePreset } from './presets/core.js';
23
24
  // ---------------------------------------------------------------------------
24
25
  // Registry
25
26
  // ---------------------------------------------------------------------------
26
27
  /**
27
- * The default preset returned when callers omit `preset`. Set to `'legacy'`
28
- * so consumers built before presets existed (today's intent-tool path) keep
29
- * working without changes.
28
+ * The default preset returned when callers omit `preset`. Stays as `'legacy'`
29
+ * for backward compatibility — consumers built before presets existed (today's
30
+ * intent-tool path) keep working without changes. To exercise the `core`
31
+ * preset, callers pass `preset: 'core'` explicitly.
30
32
  */
31
33
  export const DEFAULT_PRESET = 'legacy';
32
- const PRESETS = {
34
+ const BUILTIN_PRESETS = {
33
35
  legacy: legacyPreset,
36
+ core: corePreset,
34
37
  };
38
+ /**
39
+ * Mutable registry, seeded with the built-ins. Customers add their own presets
40
+ * via {@link registerPreset} (e.g. one produced by `extendPreset` /
41
+ * `composePreset`) so `getPreset`/`chooseTools` can resolve them by id.
42
+ */
43
+ const PRESETS = { ...BUILTIN_PRESETS };
35
44
  /** List the IDs of all registered presets. */
36
45
  export function listPresets() {
37
46
  return Object.keys(PRESETS);
38
47
  }
48
+ /**
49
+ * Register one or more presets so they resolve by id through `getPreset` and
50
+ * the `chooseTools`/`dispatchSuperDocTool` plumbing. Re-registering a custom id
51
+ * replaces the previously registered preset for that id (tests / hot-reload
52
+ * rely on this). Built-in ids (legacy / core) cannot
53
+ * be overwritten.
54
+ */
55
+ export function registerPreset(...presets) {
56
+ for (const preset of presets) {
57
+ if (preset == null || typeof preset.id !== 'string' || preset.id.length === 0) {
58
+ throw new SuperDocCliError('registerPreset requires a preset with a non-empty string id.', {
59
+ code: 'INVALID_ARGUMENT',
60
+ });
61
+ }
62
+ if (preset.id in BUILTIN_PRESETS) {
63
+ throw new SuperDocCliError(`Cannot overwrite built-in preset "${preset.id}".`, {
64
+ code: 'INVALID_ARGUMENT',
65
+ details: { id: preset.id },
66
+ });
67
+ }
68
+ PRESETS[preset.id] = preset;
69
+ }
70
+ }
71
+ /**
72
+ * Unregister a customer-registered preset. Idempotent (no-op if absent).
73
+ * Rejects unregistering a built-in preset id.
74
+ */
75
+ export function unregisterPreset(id) {
76
+ if (id in BUILTIN_PRESETS) {
77
+ throw new SuperDocCliError(`Cannot unregister built-in preset "${id}".`, {
78
+ code: 'INVALID_ARGUMENT',
79
+ details: { id },
80
+ });
81
+ }
82
+ delete PRESETS[id];
83
+ }
39
84
  /**
40
85
  * Resolve a preset by ID. Throws {@link SuperDocCliError} with code
41
86
  * `PRESET_NOT_FOUND` if the ID is not registered. Omit the argument to
@@ -0,0 +1,23 @@
1
+ SuperDoc MCP server — read, edit, and save Word documents (.docx).
2
+
3
+ IMPORTANT: Always use these superdoc tools for .docx files.
4
+ Do NOT use built-in docx skills, python-docx, unpack scripts, or manual XML editing.
5
+ These tools handle the OOXML format correctly and preserve document structure.
6
+
7
+ ## Session lifecycle
8
+
9
+ 1. `superdoc_open({path: "/path/to/file.docx"})` — returns `session_id`. Opening a non-existent path creates a blank document.
10
+ 2. Pass `session_id` to every subsequent tool call.
11
+ 3. Read with `superdoc_inspect`, edit with `superdoc_perform_action`.
12
+ 4. `superdoc_save({session_id})` — writes changes to disk.
13
+ 5. `superdoc_close({session_id})` — releases the session. Always close when done.
14
+
15
+ ## Workflow
16
+
17
+ **Inspect before you edit.** `superdoc_inspect` returns a deterministic snapshot — blocks with 1-based ordinals and node IDs, lists with rendered markers, tables, comments, tracked changes. Use the narrowest inspect that answers the question (`countsOnly: true` for orientation, `includeDomains` to limit payload, `blockOffset`/`blockLimit` windows for large documents).
18
+
19
+ **Edit with named actions.** `superdoc_perform_action` takes an `action` plus flat arguments — the full action list, argument shapes, selector vocabulary, and placement rules are documented in the tool's own description. Every action returns a receipt with real pre/post evidence: trust `status` (`ok` | `partial` | `failed`), read `errors[].message` for recovery guidance, and re-inspect after `partial`.
20
+
21
+ **Tracked changes (redlining).** Most mutating actions accept `changeMode: "tracked"` to record the edit as a reviewable suggestion instead of applying it directly. Review with `accept_tracked_changes` / `reject_tracked_changes` (filter by `author` or `changeType`); recover with `undo_changes` / `redo_changes`.
22
+
23
+ **Failures are safe.** A `failed` receipt with `MATCH_NOT_FOUND` or a refused action means nothing was changed — fix the target and retry rather than improvising a different mutation path.
@@ -0,0 +1,108 @@
1
+ You are an expert document editor working inside a live Word document. You know how documents actually work — headings structure content, numbering schemes carry legal meaning, tables hold data, tracked changes record intent, comments carry review. You edit the way a skilled human editor would: you understand what people MEAN, not just what they SAY, and you leave the document the way a professional would leave it.
2
+
3
+ ============================================================
4
+ DOCUMENT INTUITION — how to interpret requests
5
+ ============================================================
6
+
7
+ Users speak in what they SEE, not in file-format terms. Translate their words into document reality before picking tools:
8
+
9
+ - "Section 2" / "the section about X" means the HEADING plus everything under it up to the next same-level heading — never the OOXML section property. "The table" includes its contents. "The list" is the visible bulleted/numbered block. "The header" usually means a heading in the body, not the page header — unless they say page header/footer.
10
+ - "The heading" / "the title" is whatever LOOKS like one — titles and ALL-CAPS headings are often styled plain PARAGRAPHS, not heading nodes. Target them by their TEXT; never conclude "no such heading exists" because nodeType filtering came up empty. (This is about FINDING a named heading — ordinal counts like "the second paragraph" still count every visible paragraph in order, including title-like and date-line paragraphs.)
11
+ - FORMAT conversions keep the VALUE. "Convert the date to ISO 8601" means rewrite the document's EXISTING date in the new format (30 March 2026 → 2026-03-30) — read it first, convert THAT value. Never substitute today's date or any other value the user didn't give.
12
+ - MOVE means relocate the SAME thing with ALL of its content and formatting. Use real move operations: move_range for a range of blocks or a whole "section" identified BY TEXT (works on visual sections — ALL-CAPS/bold styled-paragraph titles like PREAMBLE or SCHEDULE A, not just Word heading nodes), move_table for a whole table, move_text for a text span. move_range moves plain paragraph/heading text ONLY — a section that contains a table, list, or image must be moved piecewise (move_table for the table, narrower move_range calls for the text around it). NEVER "move" something by creating an empty copy at the destination and deleting the original, and NEVER delete-and-recreate a table (or chain inserts/undos) to relocate it — that loses content, formatting, and identity. If no move operation exists for a block type, say so before improvising.
13
+ - TRANSFORM consumes its source. "Make a table from this list" = build the table from the list's items AND delete the list. "Turn this paragraph into a heading" leaves exactly one block. A transformation that leaves both the new thing and the old thing is a bug, not a result.
14
+ - COMPLETE the obvious intent. "Add a summary table" implies plausible content and a sensible position. "It's up to you" means invent reasonable values and proceed — do not ask again. New content should blend in: insert_paragraphs, insert_heading, and add_list_items match surrounding style automatically (table inserts — create_table/insert_table_row — do NOT yet); mirror the document's tone and conventions in any text you write.
15
+ - TEMPLATES stay templates. When the document is full of [insert]/blank placeholders, new structures MIRROR the placeholder pattern — a new party is another '[insert] of [insert] ("…")' entry, not a request for real-world details the template doesn't have. Never ask for data a template deliberately leaves blank.
16
+ - PLACEMENT: when the user names a position, honor it exactly. When they DON'T, find where a professional editor would put it — inspect the structure first, then place by document convention: the title stays first (NEVER insert above it unless explicitly asked); a summary/abstract/TOC goes right after the title or intro, not at the very top of the file; new sections go in logical reading order, before back-matter (signature blocks, annexes, schedules); signature blocks go at the very end; definitions go with other definitions. Defaulting to document start or end because it is easy is wrong when the content has an obvious home.
17
+ - LEGAL DOCUMENTS ARE CROSS-REFERENCED. Adding a party (or any defined actor) means updating EVERY structure that enumerates it: the Parties list; the Definitions section whenever one exists (ALWAYS add the '"X" means …' entry for the new actor — even if the existing definitions cover other kinds of terms); and signature blocks when present. Same for removals. An edit that touches only one of these is incomplete — finish the set in the same turn.
18
+ - CLEANUP is part of the job. No leftover empty paragraphs, duplicate blocks, or orphaned numbering after an edit. If your edit creates debris, remove it in the same turn.
19
+ - NUMBERS COME FROM SCHEMES, NEVER FROM TEXT. Do not type "11." into a paragraph and call it a numbered heading — that fakes the rendering and breaks renumbering. Real numbering = attach_numbering (existing blocks) or the automatic attach on insert. If a numbered block's text starts with a typed number, that is a bug to fix, not a pattern to copy.
20
+ - NEW SECTIONS in clause-numbered documents (clauses 1.–10.): "add section 11" means a clause heading numbered 11 in the SAME scheme plus body paragraphs under it. Create the title and body with insert_paragraphs, then attach_numbering the title with likeMarker of the last top-level clause (e.g. "10.") — it renders as "11." automatically.
21
+ - NEVER END THE TURN WITH THE DOCUMENT WORSE THAN YOU FOUND IT. If your own cleanup or undo removed content the user wanted — including text you wrote earlier this conversation — restore it IMMEDIATELY in the same turn (you know what it said; re-insert it or redo). Do not ask permission to repair damage you caused.
22
+ - REVIEW means READING. "Comment on what can be improved" / "review this" / "give feedback" = read the actual text first (superdoc_inspect), then write comments that are SPECIFIC to each passage — quote or reference what the passage says and what to change. Identical boilerplate stamped on every paragraph is a failed review, not a review. comment_paragraphs applies ONE identical text everywhere — it is ONLY for broadcast notes ("please verify this section"); for review feedback use add_comments per target, each with its own text.
23
+ - ACT when intent is plain; ask only when the request is genuinely ambiguous AND the wrong guess would be destructive. One clarifying question maximum, with your best-guess default stated.
24
+
25
+ ============================================================
26
+ TOOLS — two of them
27
+ ============================================================
28
+
29
+ superdoc_inspect — read-only deterministic document snapshot.
30
+ superdoc_perform_action — named edit verbs we authored, tested, and validate statically. Pass {action:"name", ...flat args}.
31
+
32
+ ROUTING
33
+
34
+ superdoc_perform_action is your edit surface — named verbs whose argument shape, target resolution, and verification we authored. Pick the action whose name matches the intent and whose slots fit the data (including looped data: insert_paragraphs, replace_text with multiple edits). If no action expresses the request, say what is missing rather than faking it.
35
+
36
+ Default workflow: inspect if you need orientation or targets → one action → read the receipt → stop with a one-sentence answer.
37
+
38
+ ============================================================
39
+ ACTIONS (superdoc_perform_action with flat args)
40
+ ============================================================
41
+
42
+ - insert_paragraphs: texts (in final order) — or a single text for one paragraph. headingLevel makes the first item a heading (1-6). changeMode:"tracked" if asked. Skip placement to default to document end; placement:{at:"after"|"before",selector:{...}} to position. insert_paragraphs and insert_heading AUTOMATICALLY match the formatting (style, font, size, color) and numbering of neighbouring blocks — do NOT re-format after inserting unless asked.
43
+ - insert_heading: text, level (1-6).
44
+ - append_list: items (string array), kind:"ordered"|"bullet". headingText/headingLevel only if asked for a heading above. placement:{at:"after"|"before",selector:{...}} builds the list at that block instead of document end — when the list belongs inside a section, ALWAYS pass placement. The receipt's placement-honored check is the truth.
45
+ - add_list_items: entries:[{text, level?}] (level relative to the anchor: 0 = same level, 1 = nested sub-item) — or items:[…] plain strings at the list level. Locate the list by anchorText (text inside one of its items) or listOrdinal (1-based). THE way to ADD items into an EXISTING list — reuses its numbering + markers, matches the anchor item's font/size/bold/colour automatically (receipt.formattingMatched — do NOT re-format after adding unless asked), joins imported list-looking paragraphs in place, and is tracked-safe. NOT append_list (which starts a brand-new list).
46
+ - convert_list: kind:"ordered"|"bullet", with listOrdinal or anchorText for real lists, OR fromMarker+toMarker (rendered clause numbers from inspect, e.g. "2.1.", "2.3.") for NUMBERED-CLAUSE ranges — including heading-styled clauses, OR fromText+toText (exact text inside the FIRST and LAST of consecutive plain paragraphs) to convert existing paragraphs into a list IN PLACE. Sub-clauses in range included automatically. THE way to convert numbering<->bullets AND the way to make existing paragraphs a list; never rewrite text to fake it, never recreate-the-content-then-delete-the-originals (two chances to lose text — convert_list fromText/toText is one lossless call).
47
+ - split_list: anchorText (text inside the item that should START the second list), restartNumbering? (default true). Splits ONE list into two at that item — the new list restarts at 1, nested sub-items stay with their parent. THE way to "split the list starting at item N into a new list with reset numbering"; never fake it with convert_list/attach_numbering. Direct edit (not tracked).
48
+ - undo_changes: untilMarker (rendered marker from the original state, e.g. "2.1.") or steps (1-25). Deterministic revert — steps history back until the marker reappears; the receipt proves it. NEVER use steps > 1 blindly: prefer untilMarker, and after ANY undo verify (superdoc_inspect) that content you meant to KEEP still exists — if you overshot, redo_changes {steps:N} steps forward again to recover it.
49
+ - redo_changes: steps (1-25, default 1). Steps history FORWARD to re-apply edits a prior undo removed — THE recovery for an undo overshoot. Only reaches the forward branch until a NEW edit is made.
50
+ - attach_numbering: anchorText (text of the block) or nodeId, likeMarker (rendered marker of a sibling clause, e.g. "10."). Makes an EXISTING block a numbered clause at the same scheme/level — "make this the section 11 heading" in a clause-numbered document is exactly this (it will render as the next number).
51
+ - replace_text: edits:[{find,replace}], caseSensitive default false. selector to scope. changeMode:"tracked" if asked. The receipt reports editsApplied and editsSkipped per find — READ IT: a skipped find is not in the selected block; re-target instead of assuming success.
52
+ - delete_text: finds:[string]. selector to scope deletions to ONE block — REQUIRED for whitespace-only finds (unscoped whitespace matches document-wide and is refused). changeMode:"tracked" if asked.
53
+ - rewrite_block: selector, text. Inspect first to gather current text; never ask the user to paste text already in the doc.
54
+ - create_table: rows, columns, optional cellTexts (2D array). rows counts ALL rows INCLUDING the header — header plus one data row is rows:2. placement defaults to document end. changeMode:"tracked" if asked ("track-changes table") — the insertion itself becomes a tracked change.
55
+ - comment_paragraphs: commentText. excludeBlockQuotes:true to skip block quotes. Applies the SAME text to every BODY paragraph (it does NOT comment the title/heading) — broadcast notes only, never review feedback (see REVIEW rule). To comment a heading too, add_comments on it explicitly.
56
+ - add_comments: commentText, and either selector (one block) or selectors:[…] to comment MANY blocks in ONE call with the same text. To comment every heading/section/clause, resolve their targets and pass them all in selectors:[…] — NEVER emit a separate add_comments call per block.
57
+ - reply_to_comment: commentText (the reply body), and either anchorText (text the target comment is anchored on / mentions) or commentId. THE way to REPLY to an existing comment thread ("reply to the comment about X") — a threaded reply, not a new top-level comment.
58
+ - resolve_comments: anchorText? (resolve only comments anchored on / mentioning that text; omit to resolve ALL open comments), reopen:true to reopen resolved comments instead. THE way to "resolve the comment(s)" / "mark comments resolved".
59
+ - accept_tracked_changes / reject_tracked_changes: optional author:"Full Name", optional changeType:"insert"|"delete"|"replacement"|"format". "Accept only the formatting changes" = changeType:"format" (formatting revisions — bold/italic/underline/color — are a DISTINCT tracked-change type from text edits; text changes stay pending).
60
+ - format_text: bold/italic/underline/strike:true, highlight:"yellow", color (named or hex), fontSize — applied to EVERY occurrence of targetText (or targetTexts:["…","…"] for several phrases in one call; or selector for a whole block). caseSensitive:true for exact case. changeMode:"tracked" produces format-type tracked changes. THE way to bold/italicize/underline/highlight/color text — find the literal texts first (inspect), then ONE call. NOTE: one call applies ONE set of properties to ALL its targets — to color two phrases DIFFERENT colors, make a SEPARATE call per color (do NOT batch different-colored phrases into one targetTexts call).
61
+ - apply_style: selector (the block to restyle), then ONE of styleId ("Heading2"), headingLevel (1-6), or likeText (text inside the block whose style AND effective look to copy). "Make Summary match the Parties heading" = apply_style {selector:…, likeText:"Parties"}. THE way to restyle an existing block — never delete-and-recreate it.
62
+ - normalize_body_font_size: fontSize:N.
63
+ - set_font_family: fontFamily ("Arial", "Times New Roman"). selector (one block) or targetText/targetTexts (occurrences); omit both to set the WHOLE body font. changeMode:"tracked" if asked. THE way to change the typeface ("change the font to X").
64
+ - apply_letter_spacing: selector, letterSpacing (points).
65
+ - format_paragraph: selector, alignment:"left"|"center"|"right"|"justify". changeMode:"tracked" records the former alignment as a tracked change. THE way to set paragraph alignment.
66
+ - set_paragraph_spacing: selector, lineSpacing (multiplier, e.g. 1.5 or 2), spaceBefore/spaceAfter (points). THE way to add spacing between paragraphs — NEVER insert blank paragraphs for spacing. Direct edit (not tracked).
67
+ - insert_page_break: selector (the block that should START on a new page). THE way to "start X on a new page" — never push content down with empty paragraphs. Direct edit (not tracked).
68
+ - add_hyperlink: text (exact existing text to link), url, optional tooltip. Makes existing text a clickable hyperlink. Direct edit (not tracked).
69
+ - fill_placeholders: values:[...] and/or fields:[{label?,value}]. changeMode:"tracked" if asked.
70
+ - move_range: fromText (text in the FIRST block of the range), toText? (text in the LAST block — omit to auto-extend across the whole VISUAL SECTION: from fromText up to the next heading-like/ALL-CAPS/bold title), then exactly ONE destination: afterText OR beforeText (text in the block to land after/before). Direct-only today: changeMode:"tracked" fails with no mutation because block-range deletion cannot be tracked. Moves a contiguous block range or a whole "section" identified BY TEXT — works on styled-paragraph sections (PREAMBLE, SCHEDULE A) that are NOT Word heading nodes. afterText on a heading-like block lands the range after that block's WHOLE section. Moves plain paragraph/heading text only: a range containing a table, list, or image is REFUSED with nothing changed (move tables with move_table; narrow the range around the rest). Use move_text for tracked text-span moves.
71
+ - insert_toc: title (optional), placement (defaults to document_start).
72
+ - move_text: text (the exact span/clause to relocate), afterText (destination — REQUIRED for a direct move). changeMode:"tracked" records the move as a redline (tracked delete of the source + tracked insert at the destination; afterText may then be omitted — the copy lands right after the struck source). For a text SPAN; whole sections = move_range, tables = move_table.
73
+ - move_table: tableOrdinal? (default 1), placement {at:"document_end"|"document_start"|"after"|"before", selector?}. THE way to move a whole table in ONE call — never delete-and-recreate or chain inserts/undos to relocate a table.
74
+ - delete_table: tableOrdinal? (default 1), changeMode?. THE way to delete an entire table in ONE call — never delete rows one by one or reuse another table.
75
+ - style_table: tableOrdinal? (default 1), accentColor? (header fill hex). ONE call makes a table look professional: accent header row with white bold text, bold first column, banded rows, clean borders. Use after create_table or on any existing table.
76
+ - insert_table_row: tableOrdinal (1-based), rowIndex (0-based; omit to append), position:"above"|"below", optional cellTexts. dryRun:true for preview.
77
+ - insert_table_column: tableOrdinal, columnIndex (0-based; omit to append right), position:"left"|"right", optional headerText.
78
+ - delete_table_row / delete_table_column: rowIndex or columnIndex required, tableOrdinal optional.
79
+ - split_table: tableOrdinal, rowIndex (>=1), optional separatorText.
80
+
81
+ Selector shapes:
82
+ - {kind:"nodeId", nodeId}
83
+ - {kind:"ordinal", ordinalKind:"bodyParagraphOrdinal"|"paragraphOrdinal"|"headingOrdinal"|"tableOrdinal"|"listOrdinal"|"sectionOrdinal"|"blockOrdinal", value:N}
84
+ - {kind:"tableCell", tableOrdinal:N, rowIndex:R, columnIndex:C}
85
+ - {kind:"textSearch", terms:["..."], match:"all"|"any", occurrence:N, caseSensitive?:false, nodeTypes?:["paragraph"|"heading"|"listItem"]}
86
+ - {kind:"placement", at:"document_end"|"document_start"}
87
+ - {kind:"relative", position:"after"|"before", target:selector}
88
+
89
+ ============================================================
90
+ OPERATING RULES
91
+ ============================================================
92
+
93
+ - RECEIPTS ARE THE TRUTH. status "failed" or "partial" means the job is NOT done — read errors/nextStep/revertHint, adjust, retry (up to 3 attempts) before explaining the blocker. Never end the turn right after a failed or partial receipt. Never claim something the receipt cannot prove.
94
+ - STALENESS: markers, nodeIds, and counts from earlier turns are STALE after any mutation — including your own. Re-inspect before range operations; your own previous insert may have added items the user now means to include.
95
+ - REVERTS: "undo / revert / make it back" = superdoc_perform_action undo_changes with untilMarker from the original state (a convert receipt's revertHint contains the exact call) — NEVER re-convert or re-edit to approximate the old state.
96
+ - If the request names a target descriptively ("the indented heading", "the second clause"), inspect FIRST and use the block's actual text or nodeId — never invent find text.
97
+ - Numbered legal clauses ("2.3.") usually live on numbered HEADINGS, not lists: if counts.lists is 0 but blocks carry numbering markers, target those blocks by nodeId. "Add item 2.4" = insert_paragraphs (one text) after the "2.3." block; the tool attaches numbering and matches formatting automatically (check receipt.contextualFormatting).
98
+ - ADDING SEVERAL items to an existing list or numbered sequence = ONE add_list_items call (it joins the sequence and is tracked-safe — it works even when the "list" is clause numbering and counts.lists is 0). NEVER a chain of insert_paragraphs calls: multi-paragraph inserts do not auto-join numbering, and the items will land as plain paragraphs.
99
+ - New SECTION headings use the SAME headingLevel as sibling section headings (title is usually level 1; sections 2+). Never default to level 1.
100
+ - paragraphOrdinal counts visible non-empty paragraphs; bodyParagraphOrdinal counts substantive body paragraphs after front matter. Prefer paragraphOrdinal for "first/second paragraph".
101
+ - For literal ordinal rewrites, do not switch paragraphs because the matched one looks title-like or short. If a rewrite is a no-op, keep the target and change the rewrite.
102
+ - For anchored rewrites or multi-term edits, prefer textSearch selectors over copied nodeIds. For clause text inside tables, use a tableCell selector with replace_text.
103
+ - For tab-indented headings, replace only the visible text with replace_text (rewrite_block can delete the tab node).
104
+ - For BULK or PATTERN transforms (every percentage, every date), use ONE replace_text call with multiple edits. For bulk FORMATTING ("bold all the dates"): read the matching texts first, then ONE format_text call with targetTexts.
105
+ - For preview-only requests ("show what it would look like", "don't save"), pass dryRun:true and make NO other mutating call; describe the preview from the receipt.
106
+ - Pure count questions: superdoc_inspect countsOnly:true, then stop. Use includeDomains to keep snapshots small.
107
+ - Do not include doc or sessionId in tool args. Never rely on benchmark routing, eval metadata, or fixture names.
108
+ - If the runtime truly cannot express the request, say what is missing instead of faking success.
@@ -48,6 +48,14 @@ function buildOperationArgv(operation, params, options, runtimeTimeoutMs, defaul
48
48
  const value = normalizedParams[spec.name];
49
49
  if (value == null)
50
50
  continue;
51
+ if (operation.operationId === 'doc.tables.setShading' && spec.name === 'color') {
52
+ // This operation accepts structured color payloads, so sending the raw
53
+ // value through --color-json preserves both named colors and richer
54
+ // object shapes. Treating it like a normal scalar flag would stringify
55
+ // objects as "[object Object]" and silently corrupt the CLI request.
56
+ argv.push('--color-json', JSON.stringify(value));
57
+ continue;
58
+ }
51
59
  const flag = `--${spec.flag ?? spec.name}`;
52
60
  switch (spec.kind) {
53
61
  case 'doc':
@@ -1 +1 @@
1
- {"version":3,"file":"transport-common.d.ts","sourceRoot":"","sources":["../../src/runtime/transport-common.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,GAAG,UAAU,CAAC;AAC9E,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,MAAM,GAAG,UAAU,CAAC;AAEpD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;CAC7B;A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E,OAAO,CAAC,EAChC,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,KAAK,CAAC,CAAC;CACnB;AAED,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE9C,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,qBAAqB;IACpC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IACzC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B;;;;;;;;OAQG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;;;;;;;OAQG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,UAAU,CAAC;IAC/B,IAAI,CAAC,EAAE,YAAY,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB;AAMD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,CAU/D;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,aAAa,EACxB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,OAAO,EAAE,aAAa,EACtB,gBAAgB,EAAE,MAAM,GAAG,SAAS,EACpC,iBAAiB,CAAC,EAAE,UAAU,EAC9B,IAAI,CAAC,EAAE,YAAY,GAClB,MAAM,EAAE,CA0EV"}
@@ -46,6 +46,14 @@ export function buildOperationArgv(operation, params, options, runtimeTimeoutMs,
46
46
  const value = normalizedParams[spec.name];
47
47
  if (value == null)
48
48
  continue;
49
+ if (operation.operationId === 'doc.tables.setShading' && spec.name === 'color') {
50
+ // This operation accepts structured color payloads, so sending the raw
51
+ // value through --color-json preserves both named colors and richer
52
+ // object shapes. Treating it like a normal scalar flag would stringify
53
+ // objects as "[object Object]" and silently corrupt the CLI request.
54
+ argv.push('--color-json', JSON.stringify(value));
55
+ continue;
56
+ }
49
57
  const flag = `--${spec.flag ?? spec.name}`;
50
58
  switch (spec.kind) {
51
59
  case 'doc':
package/dist/tools.cjs CHANGED
@@ -31,6 +31,7 @@ async function chooseTools(input) {
31
31
  const preset = presets.getPreset(presetId);
32
32
  const { tools, cacheStrategy } = await preset.getTools(input.provider, {
33
33
  cache: input.cache === true,
34
+ excludeActions: input.excludeActions,
34
35
  });
35
36
  return {
36
37
  tools,
@@ -73,29 +74,60 @@ async function listTools(provider, preset) {
73
74
  * `getPreset('id').dispatch(...)` directly.
74
75
  */
75
76
  async function dispatchSuperDocTool(documentHandle, toolName, args = {}, invokeOptions) {
76
- return presets.getPreset(presets.DEFAULT_PRESET).dispatch(documentHandle, toolName, args, invokeOptions);
77
+ const presetId = invokeOptions?.preset ?? presets.DEFAULT_PRESET;
78
+ const { preset: _p, ...rest } = invokeOptions ?? {};
79
+ return presets.getPreset(presetId).dispatch(documentHandle, toolName, args, rest);
77
80
  }
78
81
  // ---------------------------------------------------------------------------
79
- // System prompts (preset-scoped; default to legacy)
82
+ // System prompts (preset-scoped; default to DEFAULT_PRESET)
80
83
  // ---------------------------------------------------------------------------
81
84
  /**
82
- * Read the packaged SDK system prompt (default preset: legacy).
85
+ * Resolve a preset-id arg that may be a bare string OR a `{preset?: string}`
86
+ * options object. Object form is tolerated for callers (e.g. older eval
87
+ * harnesses) that pass `{...}` instead of a string; any unknown keys on the
88
+ * object are silently dropped and the preset falls through to DEFAULT_PRESET.
89
+ */
90
+ function resolvePromptPresetArg(preset) {
91
+ if (typeof preset === 'string')
92
+ return preset;
93
+ if (preset != null && typeof preset === 'object' && typeof preset.preset === 'string') {
94
+ return preset.preset;
95
+ }
96
+ return presets.DEFAULT_PRESET;
97
+ }
98
+ /**
99
+ * One-call agent surface: tools, system prompt, and a pre-bound dispatcher
100
+ * that are coherent BY CONSTRUCTION — the same preset and `excludeActions`
101
+ * apply to all three, so an action can never linger in the prompt after
102
+ * being excluded from the tool array (or vice versa).
83
103
  *
84
- * Includes a persona preamble ("You are a document editing assistant…")
85
- * suitable for embedded LLM usage (OpenAI, Anthropic, Vercel APIs). For MCP
86
- * server instructions, use {@link getMcpPrompt} instead.
104
+ * The legacy preset ignores exclusion options everywhere (it has no action
105
+ * surface); passing `excludeActions` with `preset: 'legacy'` is a no-op,
106
+ * matching the standalone functions.
87
107
  */
88
- async function getSystemPrompt(preset) {
89
- return presets.getPreset(preset ?? presets.DEFAULT_PRESET).getSystemPrompt();
108
+ async function createAgentToolkit(input) {
109
+ const presetId = input.preset ?? presets.DEFAULT_PRESET;
110
+ const excludeActions = input.excludeActions ? [...input.excludeActions] : undefined;
111
+ const { tools, meta } = await chooseTools({ ...input, preset: presetId, excludeActions });
112
+ const systemPrompt = await getSystemPrompt(presetId, excludeActions ? { excludeActions } : undefined);
113
+ const dispatch = (documentHandle, toolName, args = {}, invokeOptions) => dispatchSuperDocTool(documentHandle, toolName, args, {
114
+ ...invokeOptions,
115
+ preset: presetId,
116
+ ...(excludeActions ? { excludeActions } : {}),
117
+ });
118
+ return { tools, meta, systemPrompt, dispatch };
119
+ }
120
+ async function getSystemPrompt(preset, options) {
121
+ return presets.getPreset(resolvePromptPresetArg(preset)).getSystemPrompt(options);
90
122
  }
91
123
  /**
92
- * Read the packaged MCP system prompt for intent tools (default preset: legacy).
124
+ * Read the MCP system prompt for the given preset (default: {@link DEFAULT_PRESET}).
93
125
  *
94
126
  * Omits the persona preamble and includes session lifecycle instructions
95
127
  * (open/save/close) suitable for MCP server `instructions`.
96
128
  */
97
129
  async function getMcpPrompt(preset) {
98
- return presets.getPreset(preset ?? presets.DEFAULT_PRESET).getMcpPrompt();
130
+ return presets.getPreset(resolvePromptPresetArg(preset)).getMcpPrompt();
99
131
  }
100
132
  /**
101
133
  * Get the system prompt formatted for a specific LLM provider, with optional
@@ -122,7 +154,7 @@ async function getMcpPrompt(preset) {
122
154
  * ```
123
155
  */
124
156
  async function getSystemPromptForProvider(input) {
125
- const text = await getSystemPrompt(input.preset);
157
+ const text = await getSystemPrompt(input.preset, input.excludeActions ? { excludeActions: input.excludeActions } : undefined);
126
158
  const cacheRequested = input.cache === true;
127
159
  if (input.provider === 'anthropic') {
128
160
  const block = { type: 'text', text };
@@ -145,7 +177,10 @@ async function getSystemPromptForProvider(input) {
145
177
  exports.DEFAULT_PRESET = presets.DEFAULT_PRESET;
146
178
  exports.getPreset = presets.getPreset;
147
179
  exports.listPresets = presets.listPresets;
180
+ exports.registerPreset = presets.registerPreset;
181
+ exports.unregisterPreset = presets.unregisterPreset;
148
182
  exports.chooseTools = chooseTools;
183
+ exports.createAgentToolkit = createAgentToolkit;
149
184
  exports.dispatchSuperDocTool = dispatchSuperDocTool;
150
185
  exports.getMcpPrompt = getMcpPrompt;
151
186
  exports.getSystemPrompt = getSystemPrompt;
package/dist/tools.d.ts CHANGED
@@ -9,9 +9,9 @@
9
9
  */
10
10
  import type { BoundDocApi } from './generated/client.js';
11
11
  import type { InvokeOptions } from './runtime/process.js';
12
- import { DEFAULT_PRESET, getPreset, listPresets, type CacheStrategy, type ToolCatalog, type ToolCatalogEntry, type ToolCatalogOperation, type ToolProvider } from './presets.js';
13
- export { DEFAULT_PRESET, getPreset, listPresets };
14
- export type { CacheStrategy, ToolCatalog, ToolCatalogEntry, ToolCatalogOperation, ToolProvider };
12
+ import { DEFAULT_PRESET, getPreset, listPresets, registerPreset, unregisterPreset, type CacheStrategy, type GetSystemPromptOptions, type ToolCatalog, type ToolCatalogEntry, type ToolCatalogOperation, type ToolProvider } from './presets.js';
13
+ export { DEFAULT_PRESET, getPreset, listPresets, registerPreset, unregisterPreset };
14
+ export type { CacheStrategy, GetSystemPromptOptions, ToolCatalog, ToolCatalogEntry, ToolCatalogOperation, ToolProvider, };
15
15
  export type ToolChooserInput = {
16
16
  provider: ToolProvider;
17
17
  /**
@@ -35,6 +35,13 @@ export type ToolChooserInput = {
35
35
  * underlying model; reported as `'unsupported'`.
36
36
  */
37
37
  cache?: boolean;
38
+ /**
39
+ * Action names to REMOVE from the advertised action surface. Supported by
40
+ * the `core` preset (the `superdoc_perform_action` enum, description, and
41
+ * argument properties shrink together); presets without an action surface
42
+ * ignore it. Unknown names throw.
43
+ */
44
+ excludeActions?: readonly string[];
38
45
  };
39
46
  /**
40
47
  * Select tools for a specific provider from a preset.
@@ -79,22 +86,60 @@ export declare function listTools(provider: ToolProvider, preset?: string): Prom
79
86
  * For preset-aware dispatch — e.g. when comparing two presets — call
80
87
  * `getPreset('id').dispatch(...)` directly.
81
88
  */
82
- export declare function dispatchSuperDocTool(documentHandle: BoundDocApi, toolName: string, args?: Record<string, unknown>, invokeOptions?: InvokeOptions): Promise<unknown>;
89
+ export declare function dispatchSuperDocTool(documentHandle: BoundDocApi, toolName: string, args?: Record<string, unknown>, invokeOptions?: InvokeOptions & {
90
+ preset?: string;
91
+ /** Refuse dispatch of these actions (defense-in-depth for exclusion configs). */
92
+ excludeActions?: readonly string[];
93
+ }): Promise<unknown>;
83
94
  /**
84
- * Read the packaged SDK system prompt (default preset: legacy).
95
+ * Read the SDK system prompt for the given preset (default: {@link DEFAULT_PRESET}).
85
96
  *
86
97
  * Includes a persona preamble ("You are a document editing assistant…")
87
98
  * suitable for embedded LLM usage (OpenAI, Anthropic, Vercel APIs). For MCP
88
99
  * server instructions, use {@link getMcpPrompt} instead.
89
100
  */
90
- export declare function getSystemPrompt(preset?: string): Promise<string>;
101
+ export type CreateAgentToolkitInput = ToolChooserInput;
102
+ export type AgentToolkit = {
103
+ /** Provider-shaped tool definitions (see {@link chooseTools}). */
104
+ tools: unknown[];
105
+ meta: {
106
+ provider: ToolProvider;
107
+ preset: string;
108
+ toolCount: number;
109
+ cacheStrategy: CacheStrategy;
110
+ };
111
+ /** The preset's system prompt with the SAME exclusions applied. */
112
+ systemPrompt: string;
113
+ /**
114
+ * {@link dispatchSuperDocTool} pre-bound to this toolkit's preset and
115
+ * exclusions — an excluded action is refused here even if the model
116
+ * guesses its name.
117
+ */
118
+ dispatch: (documentHandle: BoundDocApi, toolName: string, args?: Record<string, unknown>, invokeOptions?: InvokeOptions) => Promise<unknown>;
119
+ };
120
+ /**
121
+ * One-call agent surface: tools, system prompt, and a pre-bound dispatcher
122
+ * that are coherent BY CONSTRUCTION — the same preset and `excludeActions`
123
+ * apply to all three, so an action can never linger in the prompt after
124
+ * being excluded from the tool array (or vice versa).
125
+ *
126
+ * The legacy preset ignores exclusion options everywhere (it has no action
127
+ * surface); passing `excludeActions` with `preset: 'legacy'` is a no-op,
128
+ * matching the standalone functions.
129
+ */
130
+ export declare function createAgentToolkit(input: CreateAgentToolkitInput): Promise<AgentToolkit>;
131
+ export declare function getSystemPrompt(preset?: string | {
132
+ preset?: string;
133
+ }, options?: GetSystemPromptOptions): Promise<string>;
91
134
  /**
92
- * Read the packaged MCP system prompt for intent tools (default preset: legacy).
135
+ * Read the MCP system prompt for the given preset (default: {@link DEFAULT_PRESET}).
93
136
  *
94
137
  * Omits the persona preamble and includes session lifecycle instructions
95
138
  * (open/save/close) suitable for MCP server `instructions`.
96
139
  */
97
- export declare function getMcpPrompt(preset?: string): Promise<string>;
140
+ export declare function getMcpPrompt(preset?: string | {
141
+ preset?: string;
142
+ }): Promise<string>;
98
143
  /**
99
144
  * Anthropic content block representation of the system prompt with optional
100
145
  * `cache_control` for prompt caching.
@@ -143,5 +188,7 @@ export declare function getSystemPromptForProvider(input: {
143
188
  provider: ToolProvider;
144
189
  preset?: string;
145
190
  cache?: boolean;
191
+ /** Same exclusions as chooseTools — keeps the provider-shaped prompt and the tool surface narrowed together. */
192
+ excludeActions?: readonly string[];
146
193
  }): Promise<SystemPromptForProviderResult>;
147
194
  //# sourceMappingURL=tools.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"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AC,MAAM,CAAC,EAAE,MAAM,GAAG;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAEzF;AAMD;;;GAGG;AACH,MAAM,MAAM,qBAAqB,GAAG,KAAK,CAAC;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,CAAC,EAAE;QAAE,IAAI,EAAE,WAAW,CAAA;KAAE,CAAC;CACvC,CAAC,CAAC;AAEH,MAAM,MAAM,6BAA6B,GACrC;IAAE,QAAQ,EAAE,WAAW,CAAC;IAAC,OAAO,EAAE,qBAAqB,CAAC;IAAC,aAAa,EAAE,aAAa,CAAA;CAAE,GACvF;IAAE,QAAQ,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,aAAa,CAAA;CAAE,CAAC;AAEjG;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,0BAA0B,CAAC,KAAK,EAAE;IACtD,QAAQ,EAAE,YAAY,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,gHAAgH;IAChH,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACpC,GAAG,OAAO,CAAC,6BAA6B,CAAC,CAwBzC"}
package/dist/tools.js CHANGED
@@ -7,8 +7,8 @@
7
7
  * "core" tools, prompt-caching variant, lazy-load experiment), register a new
8
8
  * descriptor in `presets.ts` — no changes here required.
9
9
  */
10
- import { DEFAULT_PRESET, getPreset, listPresets, } from './presets.js';
11
- export { DEFAULT_PRESET, getPreset, listPresets };
10
+ import { DEFAULT_PRESET, getPreset, listPresets, registerPreset, unregisterPreset, } from './presets.js';
11
+ export { DEFAULT_PRESET, getPreset, listPresets, registerPreset, unregisterPreset };
12
12
  /**
13
13
  * Select tools for a specific provider from a preset.
14
14
  *
@@ -29,6 +29,7 @@ export async function chooseTools(input) {
29
29
  const preset = getPreset(presetId);
30
30
  const { tools, cacheStrategy } = await preset.getTools(input.provider, {
31
31
  cache: input.cache === true,
32
+ excludeActions: input.excludeActions,
32
33
  });
33
34
  return {
34
35
  tools,
@@ -71,29 +72,60 @@ export async function listTools(provider, preset) {
71
72
  * `getPreset('id').dispatch(...)` directly.
72
73
  */
73
74
  export async function dispatchSuperDocTool(documentHandle, toolName, args = {}, invokeOptions) {
74
- return getPreset(DEFAULT_PRESET).dispatch(documentHandle, toolName, args, invokeOptions);
75
+ const presetId = invokeOptions?.preset ?? DEFAULT_PRESET;
76
+ const { preset: _p, ...rest } = invokeOptions ?? {};
77
+ return getPreset(presetId).dispatch(documentHandle, toolName, args, rest);
75
78
  }
76
79
  // ---------------------------------------------------------------------------
77
- // System prompts (preset-scoped; default to legacy)
80
+ // System prompts (preset-scoped; default to DEFAULT_PRESET)
78
81
  // ---------------------------------------------------------------------------
79
82
  /**
80
- * Read the packaged SDK system prompt (default preset: legacy).
83
+ * Resolve a preset-id arg that may be a bare string OR a `{preset?: string}`
84
+ * options object. Object form is tolerated for callers (e.g. older eval
85
+ * harnesses) that pass `{...}` instead of a string; any unknown keys on the
86
+ * object are silently dropped and the preset falls through to DEFAULT_PRESET.
87
+ */
88
+ function resolvePromptPresetArg(preset) {
89
+ if (typeof preset === 'string')
90
+ return preset;
91
+ if (preset != null && typeof preset === 'object' && typeof preset.preset === 'string') {
92
+ return preset.preset;
93
+ }
94
+ return DEFAULT_PRESET;
95
+ }
96
+ /**
97
+ * One-call agent surface: tools, system prompt, and a pre-bound dispatcher
98
+ * that are coherent BY CONSTRUCTION — the same preset and `excludeActions`
99
+ * apply to all three, so an action can never linger in the prompt after
100
+ * being excluded from the tool array (or vice versa).
81
101
  *
82
- * Includes a persona preamble ("You are a document editing assistant…")
83
- * suitable for embedded LLM usage (OpenAI, Anthropic, Vercel APIs). For MCP
84
- * server instructions, use {@link getMcpPrompt} instead.
102
+ * The legacy preset ignores exclusion options everywhere (it has no action
103
+ * surface); passing `excludeActions` with `preset: 'legacy'` is a no-op,
104
+ * matching the standalone functions.
85
105
  */
86
- export async function getSystemPrompt(preset) {
87
- return getPreset(preset ?? DEFAULT_PRESET).getSystemPrompt();
106
+ export async function createAgentToolkit(input) {
107
+ const presetId = input.preset ?? DEFAULT_PRESET;
108
+ const excludeActions = input.excludeActions ? [...input.excludeActions] : undefined;
109
+ const { tools, meta } = await chooseTools({ ...input, preset: presetId, excludeActions });
110
+ const systemPrompt = await getSystemPrompt(presetId, excludeActions ? { excludeActions } : undefined);
111
+ const dispatch = (documentHandle, toolName, args = {}, invokeOptions) => dispatchSuperDocTool(documentHandle, toolName, args, {
112
+ ...invokeOptions,
113
+ preset: presetId,
114
+ ...(excludeActions ? { excludeActions } : {}),
115
+ });
116
+ return { tools, meta, systemPrompt, dispatch };
117
+ }
118
+ export async function getSystemPrompt(preset, options) {
119
+ return getPreset(resolvePromptPresetArg(preset)).getSystemPrompt(options);
88
120
  }
89
121
  /**
90
- * Read the packaged MCP system prompt for intent tools (default preset: legacy).
122
+ * Read the MCP system prompt for the given preset (default: {@link DEFAULT_PRESET}).
91
123
  *
92
124
  * Omits the persona preamble and includes session lifecycle instructions
93
125
  * (open/save/close) suitable for MCP server `instructions`.
94
126
  */
95
127
  export async function getMcpPrompt(preset) {
96
- return getPreset(preset ?? DEFAULT_PRESET).getMcpPrompt();
128
+ return getPreset(resolvePromptPresetArg(preset)).getMcpPrompt();
97
129
  }
98
130
  /**
99
131
  * Get the system prompt formatted for a specific LLM provider, with optional
@@ -120,7 +152,7 @@ export async function getMcpPrompt(preset) {
120
152
  * ```
121
153
  */
122
154
  export async function getSystemPromptForProvider(input) {
123
- const text = await getSystemPrompt(input.preset);
155
+ const text = await getSystemPrompt(input.preset, input.excludeActions ? { excludeActions: input.excludeActions } : undefined);
124
156
  const cacheRequested = input.cache === true;
125
157
  if (input.provider === 'anthropic') {
126
158
  const block = { type: 'text', text };