You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: apps/docs/document-api/reference/mutations/apply.mdx
+18-3Lines changed: 18 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -946,6 +946,16 @@ The runtime capability snapshot also exposes this allowlist at `planEngine.suppo
946
946
"args": {
947
947
"additionalProperties": false,
948
948
"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
+
},
949
959
"inline": {
950
960
"additionalProperties": false,
951
961
"minProperties": 1,
@@ -1754,11 +1764,16 @@ The runtime capability snapshot also exposes this allowlist at `planEngine.suppo
1754
1764
}
1755
1765
},
1756
1766
"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\".",
Copy file name to clipboardExpand all lines: apps/docs/document-api/reference/mutations/preview.mdx
+18-3Lines changed: 18 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -932,6 +932,16 @@ The runtime capability snapshot also exposes this allowlist at `planEngine.suppo
932
932
"args": {
933
933
"additionalProperties": false,
934
934
"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
+
},
935
945
"inline": {
936
946
"additionalProperties": false,
937
947
"minProperties": 1,
@@ -1740,11 +1750,16 @@ The runtime capability snapshot also exposes this allowlist at `planEngine.suppo
1740
1750
}
1741
1751
},
1742
1752
"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\".",
Copy file name to clipboardExpand all lines: packages/sdk/langs/browser/src/system-prompt.ts
+38-4Lines changed: 38 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -24,9 +24,9 @@ Every editing tool needs a **target** telling the API *where* to apply the chang
24
24
25
25
- **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).
26
26
- **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.
28
28
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.
30
30
31
31
## Common workflows
32
32
@@ -134,9 +134,43 @@ Use preset "disc" for bullets, "decimal" for numbered. WARNING: the range conver
134
134
135
135
3. To change a bullet list to numbered: \`superdoc_list({action: "set_type", target: {kind: "block", nodeType: "listItem", nodeId: "<anyItemId>"}, kind: "ordered"})\`
136
136
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.
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:
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
+
137
171
### Batch multiple text edits atomically
138
172
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:
140
174
141
175
\`\`\`
142
176
superdoc_mutations({
@@ -149,7 +183,7 @@ superdoc_mutations({
149
183
})
150
184
\`\`\`
151
185
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.
153
187
154
188
Never create two steps targeting overlapping text in the same block. Combine them into a single text.rewrite instead.
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`
18
49
19
50
## Tools overview
20
51
@@ -36,9 +67,9 @@ Every editing tool needs a **target** telling the API *where* to apply the chang
36
67
37
68
-**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).
38
69
-**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.
40
71
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.
42
73
43
74
## Common workflows
44
75
@@ -146,9 +177,43 @@ Use preset "disc" for bullets, "decimal" for numbered. WARNING: the range conver
146
177
147
178
3. To change a bullet list to numbered: `superdoc_list({action: "set_type", target: {kind: "block", nodeType: "listItem", nodeId: "<anyItemId>"}, kind: "ordered"})`
148
179
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.
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:
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
+
149
214
### Batch multiple text edits atomically
150
215
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:
152
217
153
218
```
154
219
superdoc_mutations({
@@ -161,7 +226,7 @@ superdoc_mutations({
161
226
})
162
227
```
163
228
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.
165
230
166
231
Never create two steps targeting overlapping text in the same block. Combine them into a single text.rewrite instead.
0 commit comments