Skip to content

Commit c3395d6

Browse files
committed
chore: regenerate SDK artifacts and docs from updated contract
1 parent 64cab87 commit c3395d6

6 files changed

Lines changed: 189 additions & 26 deletions

File tree

apps/docs/document-api/reference/_generated-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1016,5 +1016,5 @@
10161016
}
10171017
],
10181018
"marker": "{/* GENERATED FILE: DO NOT EDIT. Regenerate via `pnpm run docapi:sync`. */}",
1019-
"sourceHash": "4a3601ee0f28a73c712fbe06e8b4913a9ae882a71152f9f6e892ea51137fc5e8"
1019+
"sourceHash": "a77f6a56704f39dcdc2d65ef8192ea4fffc0c8fb797bf13f516a949557d6e0ec"
10201020
}

apps/docs/document-api/reference/mutations/apply.mdx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,16 @@ The runtime capability snapshot also exposes this allowlist at `planEngine.suppo
946946
"args": {
947947
"additionalProperties": false,
948948
"properties": {
949+
"alignment": {
950+
"description": "Set paragraph alignment on the target block(s). Can be combined with inline formatting in the same step.",
951+
"enum": [
952+
"left",
953+
"center",
954+
"right",
955+
"justify"
956+
],
957+
"type": "string"
958+
},
949959
"inline": {
950960
"additionalProperties": false,
951961
"minProperties": 1,
@@ -1754,11 +1764,16 @@ The runtime capability snapshot also exposes this allowlist at `planEngine.suppo
17541764
}
17551765
},
17561766
"type": "object"
1767+
},
1768+
"scope": {
1769+
"description": "When \"block\", inline formatting expands to cover the entire parent paragraph(s), not just the matched text. Use \"block\" after markdown inserts to format whole paragraphs with a short identifying pattern. Default: \"match\".",
1770+
"enum": [
1771+
"match",
1772+
"block"
1773+
],
1774+
"type": "string"
17571775
}
17581776
},
1759-
"required": [
1760-
"inline"
1761-
],
17621777
"type": "object"
17631778
},
17641779
"id": {

apps/docs/document-api/reference/mutations/preview.mdx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,16 @@ The runtime capability snapshot also exposes this allowlist at `planEngine.suppo
932932
"args": {
933933
"additionalProperties": false,
934934
"properties": {
935+
"alignment": {
936+
"description": "Set paragraph alignment on the target block(s). Can be combined with inline formatting in the same step.",
937+
"enum": [
938+
"left",
939+
"center",
940+
"right",
941+
"justify"
942+
],
943+
"type": "string"
944+
},
935945
"inline": {
936946
"additionalProperties": false,
937947
"minProperties": 1,
@@ -1740,11 +1750,16 @@ The runtime capability snapshot also exposes this allowlist at `planEngine.suppo
17401750
}
17411751
},
17421752
"type": "object"
1753+
},
1754+
"scope": {
1755+
"description": "When \"block\", inline formatting expands to cover the entire parent paragraph(s), not just the matched text. Use \"block\" after markdown inserts to format whole paragraphs with a short identifying pattern. Default: \"match\".",
1756+
"enum": [
1757+
"match",
1758+
"block"
1759+
],
1760+
"type": "string"
17431761
}
17441762
},
1745-
"required": [
1746-
"inline"
1747-
],
17481763
"type": "object"
17491764
},
17501765
"id": {

packages/sdk/langs/browser/src/system-prompt.ts

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ Every editing tool needs a **target** telling the API *where* to apply the chang
2424
2525
- **From blocks data**: Each block has a \`ref\` (pass directly to superdoc_edit or superdoc_format) and a \`nodeId\` (for building \`at\` positions with superdoc_create).
2626
- **From superdoc_search**: Returns \`handle.ref\` covering the matched text. Use search when you need to find text patterns, not when you already know which block to target.
27-
- **From superdoc_create**: Returns \`nodeId\` for chaining creates and building block targets. Re-fetch blocks after create to get a fresh ref before formatting.
27+
- **From superdoc_create**: Returns \`nodeId\` and \`ref\`. The ref is valid for one immediate format call. For subsequent operations, re-fetch blocks to get fresh refs.
2828
29-
**Refs expire after any mutation.** Always re-search or re-read blocks before the next operation.
29+
**Refs expire after any mutation** between separate tool calls. Within a superdoc_mutations batch, selectors resolve automatically — no manual re-searching between steps.
3030
3131
## Common workflows
3232
@@ -134,9 +134,43 @@ Use preset "disc" for bullets, "decimal" for numbered. WARNING: the range conver
134134
135135
3. To change a bullet list to numbered: \`superdoc_list({action: "set_type", target: {kind: "block", nodeType: "listItem", nodeId: "<anyItemId>"}, kind: "ordered"})\`
136136
137+
### Insert content into a document (new or existing)
138+
139+
Markdown insert creates block structure but uses default formatting. You MUST follow up with formatting to match the document's existing style.
140+
141+
**Step 1: Read existing formatting** from the initial get_content blocks response. Pay special attention to:
142+
- **Nearby headings/titles**: look at their fontFamily, fontSize, bold, underline, alignment (especially center vs justify vs left). Your new headings must match these exactly.
143+
- **Body paragraphs**: note fontFamily, fontSize, color, alignment. Your new paragraphs must match.
144+
- Match the style of the nearest similar element, not arbitrary values.
145+
146+
**Step 2: Insert content with markdown:**
147+
148+
\`\`\`
149+
superdoc_edit({action: "insert", type: "markdown",
150+
target: {kind: "block", nodeType: "paragraph", nodeId: "<first-block-nodeId>"},
151+
placement: "before",
152+
value: "# Executive Summary\\n\\nThis agreement sets forth the principal terms..."})
153+
\`\`\`
154+
155+
**Step 3: Apply ALL formatting in a SINGLE superdoc_mutations call.** Each format.apply step accepts \`inline\` (text styles), \`alignment\` (paragraph alignment), and \`scope\` — combine them all in one step per block.
156+
157+
ALWAYS use \`scope: "block"\` after markdown inserts. This makes the formatting cover the entire paragraph, not just the matched text pattern. The pattern only needs to uniquely identify which paragraph — a short prefix is enough.
158+
159+
Example: if the document has centered, underlined, 12pt headings and justified 12pt body text:
160+
\`\`\`
161+
superdoc_mutations({action: "apply", atomic: true, steps: [
162+
{id: "f1", op: "format.apply", where: {by: "select", select: {type: "text", pattern: "Executive Summary"}, require: "first"}, args: {inline: {fontFamily: "Times New Roman, serif", fontSize: 12, underline: true}, alignment: "center", scope: "block"}},
163+
{id: "f2", op: "format.apply", where: {by: "select", select: {type: "text", pattern: "This agreement sets forth"}, require: "first"}, args: {inline: {fontFamily: "Times New Roman, serif", fontSize: 12, color: "#000000"}, alignment: "justify", scope: "block"}}
164+
]})
165+
\`\`\`
166+
167+
CRITICAL: Do NOT guess formatting values. Copy them from the existing document blocks you read in step 1. Use \`scope: "block"\` so the formatting covers the ENTIRE paragraph, not just the matched text.
168+
169+
Total: 3 calls (read + insert + format-all-in-one-batch). Never more.
170+
137171
### Batch multiple text edits atomically
138172
139-
Use superdoc_mutations when you need 2+ text changes that must succeed or fail together:
173+
Use superdoc_mutations for 2+ text changes, format changes, or a combination:
140174
141175
\`\`\`
142176
superdoc_mutations({
@@ -149,7 +183,7 @@ superdoc_mutations({
149183
})
150184
\`\`\`
151185
152-
Split mutations by phase: text mutations (text.rewrite, text.insert, text.delete) in one call, then formatting (format.apply) in a separate call with fresh refs from a new superdoc_search.
186+
Selectors resolve at compile time (before execution). This means format.apply steps CANNOT target content created by create steps in the same batch — the new content does not exist yet when selectors compile. Split creates and formatting into separate batches.
153187
154188
Never create two steps targeting overlapping text in the same block. Combine them into a single text.rewrite instead.
155189

packages/sdk/tools/system-prompt-mcp.md

Lines changed: 76 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,46 @@ These tools handle the OOXML format correctly and preserve document structure.
66

77
## Session lifecycle
88

9-
Every interaction requires a session. Follow this workflow:
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, edit, format the document using the tools below.
12+
4. `superdoc_save({session_id})` — writes changes to disk.
13+
5. `superdoc_close({session_id})` — releases the session. Always close when done.
1014

11-
1. `superdoc_open({file: "/path/to/file.docx"})` — returns `session_id`
12-
2. Pass `session_id` to every subsequent tool call
13-
3. Use intent tools (superdoc_search, superdoc_edit, etc.) to read and modify content
14-
4. `superdoc_save({session_id})` — writes changes to disk (optional `out` for save-as)
15-
5. `superdoc_close({session_id})` — releases the session
15+
## Efficient patterns (use these instead of calling tools one at a time)
1616

17-
Opening a non-existent path creates a blank document. Always close sessions when done.
17+
**Creating headings and paragraphs — ALWAYS use markdown insert (one call):**
18+
```
19+
superdoc_edit({action: "insert", type: "markdown",
20+
value: "# Section Title\n\nParagraph content.\n\n# Another Section\n\nMore content with **bold**."})
21+
```
22+
This creates proper Heading styles from # markers. One call replaces many superdoc_create calls.
23+
24+
**Inserting at a specific position — use target + placement:**
25+
```
26+
superdoc_edit({action: "insert", type: "markdown",
27+
target: {kind: "block", nodeType: "paragraph", nodeId: "<nodeId>"},
28+
placement: "before",
29+
value: "# Executive Summary\n\nThis agreement sets forth the principal terms..."})
30+
```
31+
Valid placements: "before", "after", "insideStart", "insideEnd". Without target, content appends at document end.
32+
33+
**Formatting — use `scope: "block"` to format entire paragraphs after markdown insert:**
34+
```
35+
superdoc_mutations({action: "apply", atomic: true, steps: [
36+
{id: "f1", op: "format.apply", where: {by: "select", select: {type: "text", pattern: "Executive Summary"}, require: "first"}, args: {inline: {fontFamily: "Times New Roman, serif", fontSize: 12, underline: true}, alignment: "center", scope: "block"}},
37+
{id: "f2", op: "format.apply", where: {by: "select", select: {type: "text", pattern: "This agreement sets forth"}, require: "first"}, args: {inline: {fontFamily: "Times New Roman, serif", fontSize: 12}, alignment: "justify", scope: "block"}}
38+
]})
39+
```
40+
One format.apply step per block. Combine `inline`, `alignment`, and `scope: "block"` in each step. The pattern only needs to identify which paragraph — `scope: "block"` formats the entire paragraph, not just the matched text.
41+
42+
**When to use which tool:**
43+
- Creating headings, paragraphs, or any block content → `superdoc_edit` with type "markdown" (preferred, even for a single heading + paragraph)
44+
- Creating one block only when markdown is insufficient → `superdoc_create`
45+
- ALL formatting after insert → `superdoc_mutations` with format.apply (inline + alignment in one step per block)
46+
- Single quick format (no insert before it) → `superdoc_format`
47+
- Multiple text edits → `superdoc_mutations`
48+
- Single text edit → `superdoc_edit`
1849

1950
## Tools overview
2051

@@ -36,9 +67,9 @@ Every editing tool needs a **target** telling the API *where* to apply the chang
3667

3768
- **From blocks data**: Each block has a `ref` (pass directly to superdoc_edit or superdoc_format) and a `nodeId` (for building `at` positions with superdoc_create).
3869
- **From superdoc_search**: Returns `handle.ref` covering the matched text. Use search when you need to find text patterns, not when you already know which block to target.
39-
- **From superdoc_create**: Returns `nodeId` for chaining creates and building block targets. Re-fetch blocks after create to get a fresh ref before formatting.
70+
- **From superdoc_create**: Returns `nodeId` and `ref`. The ref is valid for one immediate format call. For subsequent operations, re-fetch blocks to get fresh refs.
4071

41-
**Refs expire after any mutation.** Always re-search or re-read blocks before the next operation.
72+
**Refs expire after any mutation** between separate tool calls. Within a superdoc_mutations batch, selectors resolve automatically — no manual re-searching between steps.
4273

4374
## Common workflows
4475

@@ -146,9 +177,43 @@ Use preset "disc" for bullets, "decimal" for numbered. WARNING: the range conver
146177

147178
3. To change a bullet list to numbered: `superdoc_list({action: "set_type", target: {kind: "block", nodeType: "listItem", nodeId: "<anyItemId>"}, kind: "ordered"})`
148179

180+
### Insert content into a document (new or existing)
181+
182+
Markdown insert creates block structure but uses default formatting. You MUST follow up with formatting to match the document's existing style.
183+
184+
**Step 1: Read existing formatting** from the initial get_content blocks response. Pay special attention to:
185+
- **Nearby headings/titles**: look at their fontFamily, fontSize, bold, underline, alignment (especially center vs justify vs left). Your new headings must match these exactly.
186+
- **Body paragraphs**: note fontFamily, fontSize, color, alignment. Your new paragraphs must match.
187+
- Match the style of the nearest similar element, not arbitrary values.
188+
189+
**Step 2: Insert content with markdown:**
190+
191+
```
192+
superdoc_edit({action: "insert", type: "markdown",
193+
target: {kind: "block", nodeType: "paragraph", nodeId: "<first-block-nodeId>"},
194+
placement: "before",
195+
value: "# Executive Summary\n\nThis agreement sets forth the principal terms..."})
196+
```
197+
198+
**Step 3: Apply ALL formatting in a SINGLE superdoc_mutations call.** Each format.apply step accepts `inline` (text styles), `alignment` (paragraph alignment), and `scope` — combine them all in one step per block.
199+
200+
ALWAYS use `scope: "block"` after markdown inserts. This makes the formatting cover the entire paragraph, not just the matched text pattern. The pattern only needs to uniquely identify which paragraph — a short prefix is enough.
201+
202+
Example: if the document has centered, underlined, 12pt headings and justified 12pt body text:
203+
```
204+
superdoc_mutations({action: "apply", atomic: true, steps: [
205+
{id: "f1", op: "format.apply", where: {by: "select", select: {type: "text", pattern: "Executive Summary"}, require: "first"}, args: {inline: {fontFamily: "Times New Roman, serif", fontSize: 12, underline: true}, alignment: "center", scope: "block"}},
206+
{id: "f2", op: "format.apply", where: {by: "select", select: {type: "text", pattern: "This agreement sets forth"}, require: "first"}, args: {inline: {fontFamily: "Times New Roman, serif", fontSize: 12, color: "#000000"}, alignment: "justify", scope: "block"}}
207+
]})
208+
```
209+
210+
CRITICAL: Do NOT guess formatting values. Copy them from the existing document blocks you read in step 1. Use `scope: "block"` so the formatting covers the ENTIRE paragraph, not just the matched text.
211+
212+
Total: 3 calls (read + insert + format-all-in-one-batch). Never more.
213+
149214
### Batch multiple text edits atomically
150215

151-
Use superdoc_mutations when you need 2+ text changes that must succeed or fail together:
216+
Use superdoc_mutations for 2+ text changes, format changes, or a combination:
152217

153218
```
154219
superdoc_mutations({
@@ -161,7 +226,7 @@ superdoc_mutations({
161226
})
162227
```
163228

164-
Split mutations by phase: text mutations (text.rewrite, text.insert, text.delete) in one call, then formatting (format.apply) in a separate call with fresh refs from a new superdoc_search.
229+
Selectors resolve at compile time (before execution). This means format.apply steps CANNOT target content created by create steps in the same batch — the new content does not exist yet when selectors compile. Split creates and formatting into separate batches.
165230

166231
Never create two steps targeting overlapping text in the same block. Combine them into a single text.rewrite instead.
167232

0 commit comments

Comments
 (0)