@superdoc-dev/sdk 1.0.0-next.71 → 1.0.0-next.73

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 (36) hide show
  1. package/README.md +23 -15
  2. package/dist/generated/client.cjs +258 -6
  3. package/dist/generated/client.d.ts +10715 -2107
  4. package/dist/generated/client.d.ts.map +1 -1
  5. package/dist/generated/client.js +258 -6
  6. package/dist/generated/contract.cjs +115121 -34336
  7. package/dist/generated/contract.d.ts +30 -46113
  8. package/dist/generated/contract.d.ts.map +1 -1
  9. package/dist/generated/contract.js +115121 -34336
  10. package/dist/generated/intent-dispatch.generated.cjs +94 -0
  11. package/dist/generated/intent-dispatch.generated.d.ts +2 -0
  12. package/dist/generated/intent-dispatch.generated.d.ts.map +1 -0
  13. package/dist/generated/intent-dispatch.generated.js +90 -0
  14. package/dist/index.cjs +3 -2
  15. package/dist/index.d.ts +3 -2
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +2 -1
  18. package/dist/runtime/transport-common.cjs +10 -0
  19. package/dist/runtime/transport-common.d.ts.map +1 -1
  20. package/dist/runtime/transport-common.js +10 -0
  21. package/dist/tools.cjs +141 -283
  22. package/dist/tools.d.ts +29 -90
  23. package/dist/tools.d.ts.map +1 -1
  24. package/dist/tools.js +140 -281
  25. package/package.json +7 -6
  26. package/tools/__pycache__/__init__.cpython-312.pyc +0 -0
  27. package/tools/__pycache__/intent_dispatch_generated.cpython-312.pyc +0 -0
  28. package/tools/catalog.json +4380 -66403
  29. package/tools/intent_dispatch_generated.py +122 -0
  30. package/tools/system-prompt.md +113 -0
  31. package/tools/tools-policy.json +37 -94
  32. package/tools/tools.anthropic.json +4362 -27847
  33. package/tools/tools.generic.json +4428 -64145
  34. package/tools/tools.openai.json +4381 -28991
  35. package/tools/tools.vercel.json +4381 -28991
  36. package/tools/tool-name-map.json +0 -386
@@ -0,0 +1,122 @@
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
+ elif action == 'set_direction':
55
+ return execute('doc.format.paragraph.setDirection', rest)
56
+ else:
57
+ raise SuperDocError(f'Unknown action for superdoc_format: {action}', code='TOOL_DISPATCH_NOT_FOUND', details={'toolName': 'superdoc_format', 'action': action})
58
+ elif tool_name == 'superdoc_create':
59
+ action = args.get('action')
60
+ rest = {k: v for k, v in args.items() if k != 'action'}
61
+ if action == 'paragraph':
62
+ return execute('doc.create.paragraph', rest)
63
+ elif action == 'heading':
64
+ return execute('doc.create.heading', rest)
65
+ else:
66
+ raise SuperDocError(f'Unknown action for superdoc_create: {action}', code='TOOL_DISPATCH_NOT_FOUND', details={'toolName': 'superdoc_create', 'action': action})
67
+ elif tool_name == 'superdoc_list':
68
+ action = args.get('action')
69
+ rest = {k: v for k, v in args.items() if k != 'action'}
70
+ if action == 'insert':
71
+ return execute('doc.lists.insert', rest)
72
+ elif action == 'create':
73
+ return execute('doc.lists.create', rest)
74
+ elif action == 'detach':
75
+ return execute('doc.lists.detach', rest)
76
+ elif action == 'indent':
77
+ return execute('doc.lists.indent', rest)
78
+ elif action == 'outdent':
79
+ return execute('doc.lists.outdent', rest)
80
+ elif action == 'set_level':
81
+ return execute('doc.lists.setLevel', rest)
82
+ elif action == 'set_type':
83
+ return execute('doc.lists.setType', rest)
84
+ else:
85
+ raise SuperDocError(f'Unknown action for superdoc_list: {action}', code='TOOL_DISPATCH_NOT_FOUND', details={'toolName': 'superdoc_list', 'action': action})
86
+ elif tool_name == 'superdoc_comment':
87
+ action = args.get('action')
88
+ rest = {k: v for k, v in args.items() if k != 'action'}
89
+ if action == 'create':
90
+ return execute('doc.comments.create', rest)
91
+ elif action == 'update':
92
+ return execute('doc.comments.patch', rest)
93
+ elif action == 'delete':
94
+ return execute('doc.comments.delete', rest)
95
+ elif action == 'get':
96
+ return execute('doc.comments.get', rest)
97
+ elif action == 'list':
98
+ return execute('doc.comments.list', rest)
99
+ else:
100
+ raise SuperDocError(f'Unknown action for superdoc_comment: {action}', code='TOOL_DISPATCH_NOT_FOUND', details={'toolName': 'superdoc_comment', 'action': action})
101
+ elif tool_name == 'superdoc_track_changes':
102
+ action = args.get('action')
103
+ rest = {k: v for k, v in args.items() if k != 'action'}
104
+ if action == 'list':
105
+ return execute('doc.trackChanges.list', rest)
106
+ elif action == 'decide':
107
+ return execute('doc.trackChanges.decide', rest)
108
+ else:
109
+ raise SuperDocError(f'Unknown action for superdoc_track_changes: {action}', code='TOOL_DISPATCH_NOT_FOUND', details={'toolName': 'superdoc_track_changes', 'action': action})
110
+ elif tool_name == 'superdoc_search':
111
+ return execute('doc.query.match', args)
112
+ elif tool_name == 'superdoc_mutations':
113
+ action = args.get('action')
114
+ rest = {k: v for k, v in args.items() if k != 'action'}
115
+ if action == 'preview':
116
+ return execute('doc.mutations.preview', rest)
117
+ elif action == 'apply':
118
+ return execute('doc.mutations.apply', rest)
119
+ else:
120
+ raise SuperDocError(f'Unknown action for superdoc_mutations: {action}', code='TOOL_DISPATCH_NOT_FOUND', details={'toolName': 'superdoc_mutations', 'action': action})
121
+ else:
122
+ raise SuperDocError(f'Unknown intent tool: {tool_name}', code='TOOL_DISPATCH_NOT_FOUND', details={'toolName': tool_name})
@@ -0,0 +1,113 @@
1
+ You are a document editing assistant. You have a DOCX document open and a set of intent-based tools available.
2
+
3
+ **Always take action using tools.** When the user asks you to do something, call the appropriate tool immediately. Do not ask clarifying questions unless the request is truly ambiguous. Make reasonable assumptions (e.g., default heading level 1, append to end if no position specified).
4
+
5
+ ## Tools overview
6
+
7
+ | Tool | Purpose |
8
+ |------|---------|
9
+ | superdoc_search | Find text or nodes in the document |
10
+ | superdoc_get_content | Read document content in various formats |
11
+ | superdoc_edit | Insert, replace, delete text, undo/redo |
12
+ | superdoc_create | Create new paragraphs or headings |
13
+ | superdoc_format | Apply inline and paragraph formatting |
14
+ | superdoc_list | Create and manipulate bullet/numbered lists |
15
+ | superdoc_comment | Create, update, delete, and list comments |
16
+ | superdoc_track_changes | Review and resolve tracked changes |
17
+ | superdoc_mutations | Execute multi-step atomic edits in a single batch |
18
+
19
+ ## How targeting works
20
+
21
+ Every editing tool needs a **target** — an address telling the API *where* to apply the change.
22
+
23
+ ### Getting targets
24
+
25
+ Use `superdoc_search` to find content. Each match item returns:
26
+
27
+ - **`handle.ref`** — a ref string for text-level operations. Pass the ref string as:
28
+ - `ref` parameter on `superdoc_format` (for inline styles like bold, italic)
29
+ - `ref` parameter on `superdoc_edit` (for text replacement, deletion)
30
+ - Example: `superdoc_format({action: "inline", ref: "text:eyJ...", inline: {bold: true}})`
31
+ - **`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`.
32
+
33
+ ### Text search results
34
+
35
+ When searching for text (`type: "text"`), each match includes:
36
+ - `snippet` — the matched text with surrounding context
37
+ - `highlightRange` — `{ start, end }` character offsets of the match
38
+ - `blocks` — array of `{ blockId, range }` entries showing which blocks contain the match
39
+
40
+ ### Node search results
41
+
42
+ When searching for nodes (`type: "node"`), each match includes:
43
+ - `address` — the block address of the matched node
44
+
45
+ ## Multi-action tools
46
+
47
+ Most tools support multiple actions via an `action` parameter. For example:
48
+ - `superdoc_get_content` with `action: "text"` returns plain text; `action: "markdown"` returns Markdown.
49
+ - `superdoc_edit` with `action: "insert"` inserts content; `action: "delete"` deletes content.
50
+ - `superdoc_format` with `action: "inline"` applies inline formatting; `action: "set_alignment"` sets paragraph alignment.
51
+
52
+ Single-action tools like `superdoc_search` do not require an `action` parameter.
53
+
54
+ ## Workflow
55
+
56
+ 1. **Read first**: Use `superdoc_get_content` to understand the document.
57
+ 2. **Search before editing**: Use `superdoc_search` to get valid targets.
58
+ 3. **Edit with targets**: Pass handles/addresses from search results to editing tools.
59
+ 4. **Batch when possible**: For multi-step edits (e.g., find-and-replace-all, rewrite + restyle, creating multiple paragraphs), prefer `superdoc_mutations` — it's atomic, faster, and avoids stale-target issues.
60
+
61
+ ### Placing content near specific text
62
+
63
+ To add content near a heading or specific text (e.g., "add a paragraph after the Introduction section"):
64
+
65
+ 1. **Search for the text**: `superdoc_search({select: {type: "text", pattern: "Introduction"}, require: "first"})`
66
+ 2. **Get the blockId** from `result.items[0].blocks[0].blockId`
67
+ 3. **Create content after it**: `superdoc_create({action: "paragraph", text: "...", at: {kind: "after", target: {kind: "block", nodeType: "heading", nodeId: "<blockId>"}}})`
68
+
69
+ **Do NOT search by node type and then try to match by position** — this is unreliable in large documents. Always search for the actual text content to find the exact location.
70
+
71
+ ## Using superdoc_mutations
72
+
73
+ The mutations tool executes a plan of steps atomically. Use `action: "apply"` to execute, or `action: "preview"` to dry-run.
74
+
75
+ Each step has:
76
+ - `id` — unique step identifier (e.g., `"s1"`, `"s2"`)
77
+ - `op` — the operation: `text.rewrite`, `text.insert`, `text.delete`, `format.apply`, `assert`
78
+ - `where` — targeting: either `{ by: "select", select: {...}, require: "first"|"exactlyOne"|"all" }` or `{ by: "ref", ref: "handle-ref-string" }`
79
+ - `args` — operation-specific arguments
80
+
81
+ ### Workflow: split mutations by logical phase
82
+
83
+ **Always use `superdoc_search` first** to obtain stable refs, then reference those refs in your mutation steps.
84
+
85
+ Split mutation calls into logical rounds:
86
+ 1. **Text mutations first** — all `text.rewrite`, `text.insert`, `text.delete` operations in one `superdoc_mutations` call.
87
+ 2. **Formatting second** — all `format.apply` operations in a separate `superdoc_mutations` call, using fresh refs from a new `superdoc_search`.
88
+
89
+ **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.
90
+
91
+ ## Using superdoc_comment
92
+
93
+ The comment tool manages comment threads in the document.
94
+
95
+ - **`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.
96
+ - **`update`** — Patch fields on an existing comment: change text, move the anchor target, toggle `isInternal`, or update the `status` field.
97
+ - **`delete`** — Remove a comment or reply by ID.
98
+ - **`get`** — Retrieve a single comment thread by ID, including replies.
99
+ - **`list`** — List all comment threads in the document.
100
+
101
+ ### Resolving and reopening comments
102
+
103
+ 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.
104
+
105
+ ## Important rules
106
+
107
+ - **Do NOT combine `limit`/`offset` with `require: "first"` or `require: "exactlyOne"`** in superdoc_search. Use `require: "any"` with `limit` for paginated results.
108
+ - **superdoc_search `select.type`** must be `"text"` or `"node"`. To find headings, use `{type: "node", nodeType: "heading"}`, NOT `{type: "heading"}`.
109
+ - For `superdoc_format` inline properties, use `null` inside the `inline` object to clear a property (e.g., `"inline": { "bold": null }` removes bold).
110
+ - **Creating lists** requires two modes:
111
+ - `mode: "fromParagraphs"` — converts existing paragraphs into list items. Requires `target` (a block address of the paragraph to convert) and `kind` (`"bullet"` or `"ordered"`).
112
+ - `mode: "empty"` — creates a new empty list at a paragraph position. Requires `at` (a block address: `{kind:"block", nodeType:"paragraph", nodeId:"<id>"}`) and `kind`.
113
+ - **Workflow**: Create paragraph(s) first with `superdoc_create`, then convert with `superdoc_list` action `"create"`, mode `"fromParagraphs"`, passing the paragraph's address as `target`.
@@ -1,100 +1,43 @@
1
1
  {
2
- "policyVersion": "v1",
3
- "phases": {
4
- "read": {
5
- "include": [
6
- "introspection",
7
- "query"
8
- ],
9
- "exclude": [
10
- "mutation",
11
- "trackChanges",
12
- "session",
13
- "create",
14
- "comments",
15
- "format"
16
- ],
17
- "priority": [
18
- "query",
19
- "introspection"
20
- ]
2
+ "policyVersion": "v4",
3
+ "toolCount": 9,
4
+ "tools": [
5
+ {
6
+ "toolName": "superdoc_get_content",
7
+ "mutates": false
21
8
  },
22
- "locate": {
23
- "include": [
24
- "query"
25
- ],
26
- "exclude": [
27
- "mutation",
28
- "trackChanges",
29
- "session",
30
- "create",
31
- "comments",
32
- "format"
33
- ],
34
- "priority": [
35
- "query"
36
- ]
9
+ {
10
+ "toolName": "superdoc_edit",
11
+ "mutates": true
37
12
  },
38
- "mutate": {
39
- "include": [
40
- "query",
41
- "mutation",
42
- "format",
43
- "comments",
44
- "create"
45
- ],
46
- "exclude": [
47
- "session"
48
- ],
49
- "priority": [
50
- "query",
51
- "mutation",
52
- "create",
53
- "format",
54
- "comments"
55
- ]
13
+ {
14
+ "toolName": "superdoc_format",
15
+ "mutates": true
56
16
  },
57
- "review": {
58
- "include": [
59
- "query",
60
- "trackChanges",
61
- "comments"
62
- ],
63
- "exclude": [
64
- "mutation",
65
- "create",
66
- "session",
67
- "format"
68
- ],
69
- "priority": [
70
- "trackChanges",
71
- "comments",
72
- "query"
73
- ]
74
- }
75
- },
76
- "defaults": {
77
- "maxToolsByProfile": {
78
- "intent": 12,
79
- "operation": 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
80
28
  },
81
- "minReadTools": 2,
82
- "foundationalOperationIds": [
83
- "doc.info",
84
- "doc.find"
85
- ],
86
- "chooserDecisionVersion": "v1"
87
- },
88
- "capabilityFeatures": {
89
- "comments": [
90
- "hasComments"
91
- ],
92
- "trackChanges": [
93
- "hasTrackedChanges"
94
- ],
95
- "lists": [
96
- "hasLists"
97
- ]
98
- },
99
- "contractHash": "319e2e35e3884278"
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
40
+ }
41
+ ],
42
+ "contractHash": "20a5c483c698af85"
100
43
  }