@superdoc/sdk 2.1.0 → 2.2.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.
- package/README.md +13 -136
- package/dist/embedded-tools.generated.cjs +1 -1
- package/dist/embedded-tools.generated.js +1 -1
- package/dist/generated/client.d.ts +12 -0
- package/dist/generated/contract.cjs +56 -0
- package/dist/generated/contract.js +56 -0
- package/package.json +6 -6
- package/tools/tools-policy.json +1 -1
- package/tools/__pycache__/__init__.cpython-312.pyc +0 -0
- package/tools/__pycache__/intent_dispatch_generated.cpython-312.pyc +0 -0
package/README.md
CHANGED
|
@@ -1,155 +1,32 @@
|
|
|
1
|
-
# @superdoc
|
|
1
|
+
# @superdoc/sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Node.js SDK for reading and editing DOCX files with SuperDoc.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install @superdoc
|
|
8
|
+
npm install @superdoc/sdk
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
## Quick start
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
| macOS (Apple Silicon) | `@superdoc-dev/sdk-darwin-arm64` |
|
|
16
|
-
| macOS (Intel) | `@superdoc-dev/sdk-darwin-x64` |
|
|
17
|
-
| Linux (x64) | `@superdoc-dev/sdk-linux-x64` |
|
|
18
|
-
| Linux (ARM64) | `@superdoc-dev/sdk-linux-arm64` |
|
|
19
|
-
| Windows (x64) | `@superdoc-dev/sdk-windows-x64` |
|
|
13
|
+
```js
|
|
14
|
+
import { SuperDocClient } from '@superdoc/sdk';
|
|
20
15
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
Both ESM and CommonJS are supported.
|
|
24
|
-
|
|
25
|
-
```ts
|
|
26
|
-
// ESM
|
|
27
|
-
import { createSuperDocClient } from '@superdoc-dev/sdk';
|
|
28
|
-
|
|
29
|
-
// CJS
|
|
30
|
-
const { createSuperDocClient } = require('@superdoc-dev/sdk');
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
```ts
|
|
34
|
-
import { createSuperDocClient } from '@superdoc-dev/sdk';
|
|
35
|
-
|
|
36
|
-
const client = createSuperDocClient();
|
|
16
|
+
const client = new SuperDocClient();
|
|
37
17
|
await client.connect();
|
|
38
18
|
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
const info = await doc.info();
|
|
42
|
-
console.log(info.counts);
|
|
19
|
+
const document = await client.open({ doc: './contract.docx' });
|
|
20
|
+
const markdown = await document.getMarkdown();
|
|
43
21
|
|
|
44
|
-
|
|
45
|
-
select: { type: 'text', pattern: 'termination' },
|
|
46
|
-
require: 'first',
|
|
47
|
-
});
|
|
22
|
+
console.log(markdown);
|
|
48
23
|
|
|
49
|
-
|
|
50
|
-
if (target) {
|
|
51
|
-
await doc.replace({
|
|
52
|
-
target,
|
|
53
|
-
text: 'expiration',
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
await doc.save({ inPlace: true });
|
|
58
|
-
await doc.close();
|
|
24
|
+
await document.close();
|
|
59
25
|
await client.dispose();
|
|
60
26
|
```
|
|
61
27
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
Pass `password` when opening a password-protected `.docx`:
|
|
65
|
-
|
|
66
|
-
```ts
|
|
67
|
-
const doc = await client.open({ doc: './secret.docx', password: 'mypassword' });
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
The password is forwarded only for the initial open and is not persisted. If the password is missing or wrong, the error includes a machine-readable code (`DOCX_PASSWORD_REQUIRED`, `DOCX_PASSWORD_INVALID`).
|
|
71
|
-
|
|
72
|
-
## API
|
|
73
|
-
|
|
74
|
-
### Client
|
|
75
|
-
|
|
76
|
-
```ts
|
|
77
|
-
import { SuperDocClient, createSuperDocClient } from '@superdoc-dev/sdk';
|
|
78
|
-
|
|
79
|
-
const client = createSuperDocClient(options?);
|
|
80
|
-
await client.connect(); // start the host process
|
|
81
|
-
await client.dispose(); // shut down gracefully
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
Open documents from the client, then operate on the returned handle:
|
|
85
|
-
|
|
86
|
-
```ts
|
|
87
|
-
const doc = await client.open(params)
|
|
88
|
-
await doc.find(params)
|
|
89
|
-
await doc.insert(params)
|
|
90
|
-
await doc.save(params)
|
|
91
|
-
await doc.close(params)
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
### Collaboration sessions
|
|
95
|
-
|
|
96
|
-
The SDK supports collaborative editing with `y-websocket`, `hocuspocus`, and `liveblocks` providers. Pass `collabUrl` for the websocket shorthand or a `collaboration` object for explicit provider config. See the [full collaboration docs](https://docs.superdoc.dev/document-engine/sdks#collaboration-sessions) for examples and all options.
|
|
97
|
-
|
|
98
|
-
### Operations
|
|
99
|
-
|
|
100
|
-
| Category | Operations |
|
|
101
|
-
|----------|-----------|
|
|
102
|
-
| **Query** | `find`, `query.match`, `getNode`, `getNodeById`, `info` |
|
|
103
|
-
| **Mutation** | `insert`, `replace`, `delete` |
|
|
104
|
-
| **Format** | `format.bold`, `format.italic`, `format.underline`, `format.strike` |
|
|
105
|
-
| **Create** | `create.paragraph` |
|
|
106
|
-
| **Lists** | `lists.list`, `lists.get`, `lists.insert`, `lists.create`, `lists.attach`, `lists.detach`, `lists.indent`, `lists.outdent`, `lists.join`, `lists.separate`, `lists.setLevel`, `lists.setValue`, `lists.continuePrevious`, `lists.setLevelRestart`, `lists.convertToText`, `lists.canJoin`, `lists.canContinuePrevious` |
|
|
107
|
-
| **Comments** | `comments.create`, `comments.patch`, `comments.delete`, `comments.get`, `comments.list` |
|
|
108
|
-
| **Track Changes** | `trackChanges.list`, `trackChanges.get`, `trackChanges.decide` |
|
|
109
|
-
| **Lifecycle** | `client.open`, `doc.save`, `doc.close` |
|
|
110
|
-
| **Client** | `client.describe`, `client.describeCommand` |
|
|
111
|
-
|
|
112
|
-
### AI Tool Integration
|
|
113
|
-
|
|
114
|
-
The SDK includes built-in support for exposing grouped intent tools as AI tool definitions:
|
|
115
|
-
|
|
116
|
-
```ts
|
|
117
|
-
import {
|
|
118
|
-
chooseTools,
|
|
119
|
-
dispatchSuperDocTool,
|
|
120
|
-
getToolCatalog,
|
|
121
|
-
} from '@superdoc-dev/sdk';
|
|
122
|
-
|
|
123
|
-
// Get the full grouped tool set for your AI provider
|
|
124
|
-
const { tools, meta } = await chooseTools({
|
|
125
|
-
provider: 'openai', // 'openai' | 'anthropic' | 'vercel' | 'generic'
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
// Optional: inspect the generated tool catalog
|
|
129
|
-
const catalog = await getToolCatalog();
|
|
130
|
-
|
|
131
|
-
// Dispatch a tool call from the AI model
|
|
132
|
-
const doc = await client.open({ doc: './contract.docx' });
|
|
133
|
-
const result = await dispatchSuperDocTool(doc, toolName, args);
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
The current catalog contains 9 grouped tools:
|
|
137
|
-
`superdoc_get_content`, `superdoc_edit`, `superdoc_format`, `superdoc_create`, `superdoc_list`, `superdoc_comment`, `superdoc_track_changes`, `superdoc_search`, and `superdoc_mutations`.
|
|
138
|
-
|
|
139
|
-
Multi-action tools use an `action` field to select the underlying operation. Single-action tools like `superdoc_search` do not require `action`.
|
|
140
|
-
|
|
141
|
-
| Function | Description |
|
|
142
|
-
|----------|-------------|
|
|
143
|
-
| `chooseTools(input)` | Load grouped tool definitions for a provider |
|
|
144
|
-
| `listTools(provider)` | List all tool definitions for a provider |
|
|
145
|
-
| `dispatchSuperDocTool(doc, toolName, args)` | Execute a tool call against a bound document handle |
|
|
146
|
-
| `getToolCatalog()` | Load the grouped tool catalog with metadata |
|
|
147
|
-
| `getSystemPrompt()` | Read the bundled system prompt for intent tools |
|
|
148
|
-
|
|
149
|
-
## Part of SuperDoc
|
|
150
|
-
|
|
151
|
-
This SDK is part of [SuperDoc](https://github.com/superdoc/docx-editor) — open-source DOCX editing and tooling. Renders, edits, and automates .docx in the browser and on the server.
|
|
28
|
+
See the [Node.js SDK guide](https://docs.superdoc.dev/agents/automation/node-sdk) for a complete workflow.
|
|
152
29
|
|
|
153
30
|
## License
|
|
154
31
|
|
|
155
|
-
AGPL-3.0
|
|
32
|
+
AGPL-3.0. Commercial licenses are available from [SuperDoc](https://www.superdoc.dev).
|