@superdoc-dev/sdk 1.0.0-alpha.44 → 1.0.0-alpha.46

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.
@@ -0,0 +1,120 @@
1
+ # Auto-generated by generate-intent-tools.mjs — do not edit
2
+
3
+ from typing import Any, Callable, Dict
4
+
5
+ from ..errors import SuperDocError
6
+
7
+
8
+ def dispatch_intent_tool(
9
+ tool_name: str,
10
+ args: Dict[str, Any],
11
+ execute: Callable[[str, Dict[str, Any]], Any],
12
+ ) -> Any:
13
+ if tool_name == 'superdoc_get_content':
14
+ action = args.get('action')
15
+ rest = {k: v for k, v in args.items() if k != 'action'}
16
+ if action == 'text':
17
+ return execute('doc.getText', rest)
18
+ elif action == 'markdown':
19
+ return execute('doc.getMarkdown', rest)
20
+ elif action == 'html':
21
+ return execute('doc.getHtml', rest)
22
+ elif action == 'info':
23
+ return execute('doc.info', rest)
24
+ else:
25
+ raise SuperDocError(f'Unknown action for superdoc_get_content: {action}', code='TOOL_DISPATCH_NOT_FOUND', details={'toolName': 'superdoc_get_content', 'action': action})
26
+ elif tool_name == 'superdoc_edit':
27
+ action = args.get('action')
28
+ rest = {k: v for k, v in args.items() if k != 'action'}
29
+ if action == 'insert':
30
+ return execute('doc.insert', rest)
31
+ elif action == 'replace':
32
+ return execute('doc.replace', rest)
33
+ elif action == 'delete':
34
+ return execute('doc.delete', rest)
35
+ elif action == 'undo':
36
+ return execute('doc.history.undo', rest)
37
+ elif action == 'redo':
38
+ return execute('doc.history.redo', rest)
39
+ else:
40
+ raise SuperDocError(f'Unknown action for superdoc_edit: {action}', code='TOOL_DISPATCH_NOT_FOUND', details={'toolName': 'superdoc_edit', 'action': action})
41
+ elif tool_name == 'superdoc_format':
42
+ action = args.get('action')
43
+ rest = {k: v for k, v in args.items() if k != 'action'}
44
+ if action == 'inline':
45
+ return execute('doc.format.apply', rest)
46
+ elif action == 'set_style':
47
+ return execute('doc.styles.paragraph.setStyle', rest)
48
+ elif action == 'set_alignment':
49
+ return execute('doc.format.paragraph.setAlignment', rest)
50
+ elif action == 'set_indentation':
51
+ return execute('doc.format.paragraph.setIndentation', rest)
52
+ elif action == 'set_spacing':
53
+ return execute('doc.format.paragraph.setSpacing', rest)
54
+ else:
55
+ raise SuperDocError(f'Unknown action for superdoc_format: {action}', code='TOOL_DISPATCH_NOT_FOUND', details={'toolName': 'superdoc_format', 'action': action})
56
+ elif tool_name == 'superdoc_create':
57
+ action = args.get('action')
58
+ rest = {k: v for k, v in args.items() if k != 'action'}
59
+ if action == 'paragraph':
60
+ return execute('doc.create.paragraph', rest)
61
+ elif action == 'heading':
62
+ return execute('doc.create.heading', rest)
63
+ else:
64
+ raise SuperDocError(f'Unknown action for superdoc_create: {action}', code='TOOL_DISPATCH_NOT_FOUND', details={'toolName': 'superdoc_create', 'action': action})
65
+ elif tool_name == 'superdoc_list':
66
+ action = args.get('action')
67
+ rest = {k: v for k, v in args.items() if k != 'action'}
68
+ if action == 'insert':
69
+ return execute('doc.lists.insert', rest)
70
+ elif action == 'create':
71
+ return execute('doc.lists.create', rest)
72
+ elif action == 'detach':
73
+ return execute('doc.lists.detach', rest)
74
+ elif action == 'indent':
75
+ return execute('doc.lists.indent', rest)
76
+ elif action == 'outdent':
77
+ return execute('doc.lists.outdent', rest)
78
+ elif action == 'set_level':
79
+ return execute('doc.lists.setLevel', rest)
80
+ elif action == 'set_type':
81
+ return execute('doc.lists.setType', rest)
82
+ else:
83
+ raise SuperDocError(f'Unknown action for superdoc_list: {action}', code='TOOL_DISPATCH_NOT_FOUND', details={'toolName': 'superdoc_list', 'action': action})
84
+ elif tool_name == 'superdoc_comment':
85
+ action = args.get('action')
86
+ rest = {k: v for k, v in args.items() if k != 'action'}
87
+ if action == 'create':
88
+ return execute('doc.comments.create', rest)
89
+ elif action == 'update':
90
+ return execute('doc.comments.patch', rest)
91
+ elif action == 'delete':
92
+ return execute('doc.comments.delete', rest)
93
+ elif action == 'get':
94
+ return execute('doc.comments.get', rest)
95
+ elif action == 'list':
96
+ return execute('doc.comments.list', rest)
97
+ else:
98
+ raise SuperDocError(f'Unknown action for superdoc_comment: {action}', code='TOOL_DISPATCH_NOT_FOUND', details={'toolName': 'superdoc_comment', 'action': action})
99
+ elif tool_name == 'superdoc_track_changes':
100
+ action = args.get('action')
101
+ rest = {k: v for k, v in args.items() if k != 'action'}
102
+ if action == 'list':
103
+ return execute('doc.trackChanges.list', rest)
104
+ elif action == 'decide':
105
+ return execute('doc.trackChanges.decide', rest)
106
+ else:
107
+ raise SuperDocError(f'Unknown action for superdoc_track_changes: {action}', code='TOOL_DISPATCH_NOT_FOUND', details={'toolName': 'superdoc_track_changes', 'action': action})
108
+ elif tool_name == 'superdoc_search':
109
+ return execute('doc.query.match', args)
110
+ elif tool_name == 'superdoc_mutations':
111
+ action = args.get('action')
112
+ rest = {k: v for k, v in args.items() if k != 'action'}
113
+ if action == 'preview':
114
+ return execute('doc.mutations.preview', rest)
115
+ elif action == 'apply':
116
+ return execute('doc.mutations.apply', rest)
117
+ else:
118
+ raise SuperDocError(f'Unknown action for superdoc_mutations: {action}', code='TOOL_DISPATCH_NOT_FOUND', details={'toolName': 'superdoc_mutations', 'action': action})
119
+ else:
120
+ raise SuperDocError(f'Unknown intent tool: {tool_name}', code='TOOL_DISPATCH_NOT_FOUND', details={'toolName': tool_name})
@@ -0,0 +1,94 @@
1
+ You are a document editing assistant. You have a DOCX document open and a set of intent-based tools available.
2
+
3
+ ## Tools overview
4
+
5
+ | Tool | Purpose |
6
+ |------|---------|
7
+ | superdoc_search | Find text or nodes in the document |
8
+ | superdoc_get_content | Read document content in various formats |
9
+ | superdoc_edit | Insert, replace, delete text, undo/redo |
10
+ | superdoc_create | Create new paragraphs or headings |
11
+ | superdoc_format | Apply inline and paragraph formatting |
12
+ | superdoc_list | Create and manipulate bullet/numbered lists |
13
+ | superdoc_comment | Create, update, delete, and list comments |
14
+ | superdoc_track_changes | Review and resolve tracked changes |
15
+ | superdoc_mutations | Execute multi-step atomic edits in a single batch |
16
+
17
+ ## How targeting works
18
+
19
+ Every editing tool needs a **target** — an address telling the API *where* to apply the change.
20
+
21
+ ### Getting targets
22
+
23
+ Use `superdoc_search` to find content. Each match item returns:
24
+
25
+ - **`handle`** — an opaque reference for text-level operations. Pass it directly as `target` to `superdoc_edit` and `superdoc_format` (for inline styles like bold, italic, etc.).
26
+ - **`address`** — a block-level address like `{ "kind": "block", "nodeType": "paragraph", "nodeId": "abc123" }`. Pass it as `target` to `superdoc_format` (for paragraph-level properties like alignment, spacing), `superdoc_list`, and `superdoc_create`.
27
+
28
+ ### Text search results
29
+
30
+ When searching for text (`type: "text"`), each match includes:
31
+ - `snippet` — the matched text with surrounding context
32
+ - `highlightRange` — `{ start, end }` character offsets of the match
33
+ - `blocks` — array of `{ blockId, range }` entries showing which blocks contain the match
34
+
35
+ ### Node search results
36
+
37
+ When searching for nodes (`type: "node"`), each match includes:
38
+ - `address` — the block address of the matched node
39
+
40
+ ## Multi-action tools
41
+
42
+ Most tools support multiple actions via an `action` parameter. For example:
43
+ - `superdoc_get_content` with `action: "text"` returns plain text; `action: "markdown"` returns Markdown.
44
+ - `superdoc_edit` with `action: "insert"` inserts content; `action: "delete"` deletes content.
45
+ - `superdoc_format` with `action: "inline"` applies inline formatting; `action: "set_alignment"` sets paragraph alignment.
46
+
47
+ Single-action tools like `superdoc_search` do not require an `action` parameter.
48
+
49
+ ## Workflow
50
+
51
+ 1. **Read first**: Use `superdoc_get_content` to understand the document.
52
+ 2. **Search before editing**: Use `superdoc_search` to get valid targets.
53
+ 3. **Edit with targets**: Pass handles/addresses from search results to editing tools.
54
+ 4. **Batch when possible**: For multi-step edits (e.g., find-and-replace-all, rewrite + restyle), prefer `superdoc_mutations` — it's atomic, faster, and avoids stale-target issues.
55
+
56
+ ## Using superdoc_mutations
57
+
58
+ The mutations tool executes a plan of steps atomically. Use `action: "apply"` to execute, or `action: "preview"` to dry-run.
59
+
60
+ Each step has:
61
+ - `id` — unique step identifier (e.g., `"s1"`, `"s2"`)
62
+ - `op` — the operation: `text.rewrite`, `text.insert`, `text.delete`, `format.apply`, `assert`
63
+ - `where` — targeting: either `{ by: "select", select: {...}, require: "first"|"exactlyOne"|"all" }` or `{ by: "ref", ref: "handle-ref-string" }`
64
+ - `args` — operation-specific arguments
65
+
66
+ ### Workflow: split mutations by logical phase
67
+
68
+ **Always use `superdoc_search` first** to obtain stable refs, then reference those refs in your mutation steps.
69
+
70
+ Split mutation calls into logical rounds:
71
+ 1. **Text mutations first** — all `text.rewrite`, `text.insert`, `text.delete` operations in one `superdoc_mutations` call.
72
+ 2. **Formatting second** — all `format.apply` operations in a separate `superdoc_mutations` call, using fresh refs from a new `superdoc_search`.
73
+
74
+ **Why**: Text edits change content and invalidate addresses. If you interleave text edits and formatting in the same batch, formatting steps may target stale positions. By splitting into rounds and re-searching between them, every ref points to the correct content.
75
+
76
+ ## Using superdoc_comment
77
+
78
+ The comment tool manages comment threads in the document.
79
+
80
+ - **`create`** — Create a new comment thread anchored to a target range. To reply to an existing thread, pass `parentCommentId` with the parent comment's ID.
81
+ - **`update`** — Patch fields on an existing comment: change text, move the anchor target, toggle `isInternal`, or update the `status` field.
82
+ - **`delete`** — Remove a comment or reply by ID.
83
+ - **`get`** — Retrieve a single comment thread by ID, including replies.
84
+ - **`list`** — List all comment threads in the document.
85
+
86
+ ### Resolving and reopening comments
87
+
88
+ To resolve a comment, use `action: "update"` with `{ commentId: "<id>", status: "resolved" }`. To reopen it, use `status: "open"`. There is no separate resolve action — it's a status field on the `update` action.
89
+
90
+ ## Important rules
91
+
92
+ - **Do NOT combine `limit`/`offset` with `require: "first"` or `require: "exactlyOne"`** in superdoc_search. Use `require: "any"` with `limit` for paginated results.
93
+ - For `superdoc_format` inline properties, use `null` inside the `inline` object to clear a property (e.g., `"inline": { "bold": null }` removes bold).
94
+ - For `superdoc_list` create action: this converts existing paragraphs into list items. Create the paragraph first with `superdoc_create`, then convert it with `superdoc_list` action `create`.
@@ -1,98 +1,43 @@
1
1
  {
2
- "policyVersion": "v3",
3
- "groups": [
4
- "core",
5
- "format",
6
- "create",
7
- "tables",
8
- "sections",
9
- "lists",
10
- "comments",
11
- "trackChanges",
12
- "toc",
13
- "history",
14
- "session"
15
- ],
16
- "groupDescriptions": {
17
- "core": "Core operations: read nodes, get text, insert/replace/delete content, mutations",
18
- "format": "Text formatting, paragraph styles, alignment, spacing, borders, shading",
19
- "create": "Create structural elements: headings, paragraphs, tables, sections, TOC",
20
- "tables": "Table creation, manipulation, formatting, borders, and cell operations",
21
- "sections": "Page layout, margins, columns, headers/footers, page numbering",
22
- "lists": "Bullet and numbered lists, indentation, list types",
23
- "comments": "Comment threads — create, edit, delete, list",
24
- "trackChanges": "Track changes — list, inspect, accept/reject",
25
- "toc": "Table of contents — create, configure, update, manage entries",
26
- "history": "Undo, redo, history inspection",
27
- "session": "Session management — open, close, save, list sessions"
28
- },
29
- "defaults": {
30
- "mode": "essential",
31
- "maxTools": 20,
32
- "alwaysInclude": [
33
- "core"
34
- ],
35
- "foundationalOperationIds": [
36
- "doc.info",
37
- "doc.query.match"
38
- ]
39
- },
40
- "capabilityFeatures": {
41
- "comments": [
42
- "hasComments"
43
- ],
44
- "trackChanges": [
45
- "hasTrackedChanges"
46
- ],
47
- "lists": [
48
- "hasLists"
49
- ],
50
- "tables": [
51
- "hasTables"
52
- ],
53
- "toc": [
54
- "hasToc"
55
- ]
56
- },
57
- "essentialTools": [
58
- "get_node_by_id",
59
- "get_document_text",
60
- "blocks_list",
61
- "query_match",
62
- "apply_mutations",
63
- "undo"
64
- ],
65
- "discoverTool": {
66
- "name": "discover_tools",
67
- "description": "Load additional tool groups when you need capabilities beyond the essential set. Call this BEFORE attempting to use tools from a specific group.\n\nAvailable groups:\n - core: Core operations: read nodes, get text, insert/replace/delete content, mutations\n - format: Text formatting, paragraph styles, alignment, spacing, borders, shading\n - create: Create structural elements: headings, paragraphs, tables, sections, TOC\n - tables: Table creation, manipulation, formatting, borders, and cell operations\n - sections: Page layout, margins, columns, headers/footers, page numbering\n - lists: Bullet and numbered lists, indentation, list types\n - comments: Comment threads — create, edit, delete, list\n - trackChanges: Track changes — list, inspect, accept/reject\n - toc: Table of contents — create, configure, update, manage entries\n - history: Undo, redo, history inspection\n - session: Session management — open, close, save, list sessions",
68
- "schema": {
69
- "type": "object",
70
- "properties": {
71
- "groups": {
72
- "type": "array",
73
- "items": {
74
- "type": "string",
75
- "enum": [
76
- "core",
77
- "format",
78
- "create",
79
- "tables",
80
- "sections",
81
- "lists",
82
- "comments",
83
- "trackChanges",
84
- "toc",
85
- "history",
86
- "session"
87
- ]
88
- },
89
- "description": "Which tool groups to load. You can request multiple at once."
90
- }
91
- },
92
- "required": [
93
- "groups"
94
- ]
2
+ "policyVersion": "v4",
3
+ "toolCount": 9,
4
+ "tools": [
5
+ {
6
+ "toolName": "superdoc_get_content",
7
+ "mutates": false
8
+ },
9
+ {
10
+ "toolName": "superdoc_edit",
11
+ "mutates": true
12
+ },
13
+ {
14
+ "toolName": "superdoc_format",
15
+ "mutates": true
16
+ },
17
+ {
18
+ "toolName": "superdoc_create",
19
+ "mutates": true
20
+ },
21
+ {
22
+ "toolName": "superdoc_list",
23
+ "mutates": true
24
+ },
25
+ {
26
+ "toolName": "superdoc_comment",
27
+ "mutates": true
28
+ },
29
+ {
30
+ "toolName": "superdoc_track_changes",
31
+ "mutates": true
32
+ },
33
+ {
34
+ "toolName": "superdoc_search",
35
+ "mutates": false
36
+ },
37
+ {
38
+ "toolName": "superdoc_mutations",
39
+ "mutates": true
95
40
  }
96
- },
97
- "contractHash": "a352150e32ad347a"
41
+ ],
42
+ "contractHash": "f095fb10203af04f"
98
43
  }