@superdoc-dev/sdk 1.0.0-next.72 → 1.0.0-next.74
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 +50 -35
- package/dist/generated/client.cjs +734 -6
- package/dist/generated/client.d.ts +20380 -2887
- package/dist/generated/client.d.ts.map +1 -1
- package/dist/generated/client.js +733 -6
- package/dist/generated/contract.cjs +115396 -33890
- package/dist/generated/contract.d.ts +30 -46113
- package/dist/generated/contract.d.ts.map +1 -1
- package/dist/generated/contract.js +115396 -33890
- package/dist/generated/intent-dispatch.generated.cjs +94 -0
- package/dist/generated/intent-dispatch.generated.d.ts +2 -0
- package/dist/generated/intent-dispatch.generated.d.ts.map +1 -0
- package/dist/generated/intent-dispatch.generated.js +90 -0
- package/dist/helpers/format.d.ts +6 -8
- package/dist/helpers/format.d.ts.map +1 -1
- package/dist/helpers/format.js +5 -8
- package/dist/index.cjs +133 -10
- package/dist/index.d.ts +76 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +132 -9
- package/dist/runtime/process.d.ts +2 -2
- package/dist/runtime/process.d.ts.map +1 -1
- package/dist/runtime/transport-common.cjs +10 -0
- package/dist/runtime/transport-common.d.ts +7 -0
- package/dist/runtime/transport-common.d.ts.map +1 -1
- package/dist/runtime/transport-common.js +10 -0
- package/dist/tools.cjs +148 -286
- package/dist/tools.d.ts +37 -93
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +147 -284
- package/package.json +7 -6
- package/tools/__pycache__/__init__.cpython-312.pyc +0 -0
- package/tools/__pycache__/intent_dispatch_generated.cpython-312.pyc +0 -0
- package/tools/catalog.json +4288 -66383
- package/tools/intent_dispatch_generated.py +122 -0
- package/tools/system-prompt.md +113 -0
- package/tools/tools-policy.json +37 -94
- package/tools/tools.anthropic.json +4290 -27847
- package/tools/tools.generic.json +4357 -64146
- package/tools/tools.openai.json +4309 -28991
- package/tools/tools.vercel.json +4309 -28991
- package/tools/tool-name-map.json +0 -386
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Auto-generated by generate-intent-tools.mjs — do not edit
|
|
4
|
+
function dispatchIntentTool(toolName, args, execute) {
|
|
5
|
+
switch (toolName) {
|
|
6
|
+
case 'superdoc_get_content': {
|
|
7
|
+
const { action, ...rest } = args;
|
|
8
|
+
switch (action) {
|
|
9
|
+
case 'text': return execute('doc.getText', rest);
|
|
10
|
+
case 'markdown': return execute('doc.getMarkdown', rest);
|
|
11
|
+
case 'html': return execute('doc.getHtml', rest);
|
|
12
|
+
case 'info': return execute('doc.info', rest);
|
|
13
|
+
default: throw new Error(`Unknown action for superdoc_get_content: ${action}`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
case 'superdoc_edit': {
|
|
17
|
+
const { action, ...rest } = args;
|
|
18
|
+
switch (action) {
|
|
19
|
+
case 'insert': return execute('doc.insert', rest);
|
|
20
|
+
case 'replace': return execute('doc.replace', rest);
|
|
21
|
+
case 'delete': return execute('doc.delete', rest);
|
|
22
|
+
case 'undo': return execute('doc.history.undo', rest);
|
|
23
|
+
case 'redo': return execute('doc.history.redo', rest);
|
|
24
|
+
default: throw new Error(`Unknown action for superdoc_edit: ${action}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
case 'superdoc_format': {
|
|
28
|
+
const { action, ...rest } = args;
|
|
29
|
+
switch (action) {
|
|
30
|
+
case 'inline': return execute('doc.format.apply', rest);
|
|
31
|
+
case 'set_style': return execute('doc.styles.paragraph.setStyle', rest);
|
|
32
|
+
case 'set_alignment': return execute('doc.format.paragraph.setAlignment', rest);
|
|
33
|
+
case 'set_indentation': return execute('doc.format.paragraph.setIndentation', rest);
|
|
34
|
+
case 'set_spacing': return execute('doc.format.paragraph.setSpacing', rest);
|
|
35
|
+
case 'set_direction': return execute('doc.format.paragraph.setDirection', rest);
|
|
36
|
+
default: throw new Error(`Unknown action for superdoc_format: ${action}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
case 'superdoc_create': {
|
|
40
|
+
const { action, ...rest } = args;
|
|
41
|
+
switch (action) {
|
|
42
|
+
case 'paragraph': return execute('doc.create.paragraph', rest);
|
|
43
|
+
case 'heading': return execute('doc.create.heading', rest);
|
|
44
|
+
default: throw new Error(`Unknown action for superdoc_create: ${action}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
case 'superdoc_list': {
|
|
48
|
+
const { action, ...rest } = args;
|
|
49
|
+
switch (action) {
|
|
50
|
+
case 'insert': return execute('doc.lists.insert', rest);
|
|
51
|
+
case 'create': return execute('doc.lists.create', rest);
|
|
52
|
+
case 'detach': return execute('doc.lists.detach', rest);
|
|
53
|
+
case 'indent': return execute('doc.lists.indent', rest);
|
|
54
|
+
case 'outdent': return execute('doc.lists.outdent', rest);
|
|
55
|
+
case 'set_level': return execute('doc.lists.setLevel', rest);
|
|
56
|
+
case 'set_type': return execute('doc.lists.setType', rest);
|
|
57
|
+
default: throw new Error(`Unknown action for superdoc_list: ${action}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
case 'superdoc_comment': {
|
|
61
|
+
const { action, ...rest } = args;
|
|
62
|
+
switch (action) {
|
|
63
|
+
case 'create': return execute('doc.comments.create', rest);
|
|
64
|
+
case 'update': return execute('doc.comments.patch', rest);
|
|
65
|
+
case 'delete': return execute('doc.comments.delete', rest);
|
|
66
|
+
case 'get': return execute('doc.comments.get', rest);
|
|
67
|
+
case 'list': return execute('doc.comments.list', rest);
|
|
68
|
+
default: throw new Error(`Unknown action for superdoc_comment: ${action}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
case 'superdoc_track_changes': {
|
|
72
|
+
const { action, ...rest } = args;
|
|
73
|
+
switch (action) {
|
|
74
|
+
case 'list': return execute('doc.trackChanges.list', rest);
|
|
75
|
+
case 'decide': return execute('doc.trackChanges.decide', rest);
|
|
76
|
+
default: throw new Error(`Unknown action for superdoc_track_changes: ${action}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
case 'superdoc_search':
|
|
80
|
+
return execute('doc.query.match', args);
|
|
81
|
+
case 'superdoc_mutations': {
|
|
82
|
+
const { action, ...rest } = args;
|
|
83
|
+
switch (action) {
|
|
84
|
+
case 'preview': return execute('doc.mutations.preview', rest);
|
|
85
|
+
case 'apply': return execute('doc.mutations.apply', rest);
|
|
86
|
+
default: throw new Error(`Unknown action for superdoc_mutations: ${action}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
default:
|
|
90
|
+
throw new Error(`Unknown intent tool: ${toolName}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
exports.dispatchIntentTool = dispatchIntentTool;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intent-dispatch.generated.d.ts","sourceRoot":"","sources":["../../src/generated/intent-dispatch.generated.ts"],"names":[],"mappings":"AAEA,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,GACxE,OAAO,CAwFT"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// Auto-generated by generate-intent-tools.mjs — do not edit
|
|
2
|
+
export function dispatchIntentTool(toolName, args, execute) {
|
|
3
|
+
switch (toolName) {
|
|
4
|
+
case 'superdoc_get_content': {
|
|
5
|
+
const { action, ...rest } = args;
|
|
6
|
+
switch (action) {
|
|
7
|
+
case 'text': return execute('doc.getText', rest);
|
|
8
|
+
case 'markdown': return execute('doc.getMarkdown', rest);
|
|
9
|
+
case 'html': return execute('doc.getHtml', rest);
|
|
10
|
+
case 'info': return execute('doc.info', rest);
|
|
11
|
+
default: throw new Error(`Unknown action for superdoc_get_content: ${action}`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
case 'superdoc_edit': {
|
|
15
|
+
const { action, ...rest } = args;
|
|
16
|
+
switch (action) {
|
|
17
|
+
case 'insert': return execute('doc.insert', rest);
|
|
18
|
+
case 'replace': return execute('doc.replace', rest);
|
|
19
|
+
case 'delete': return execute('doc.delete', rest);
|
|
20
|
+
case 'undo': return execute('doc.history.undo', rest);
|
|
21
|
+
case 'redo': return execute('doc.history.redo', rest);
|
|
22
|
+
default: throw new Error(`Unknown action for superdoc_edit: ${action}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
case 'superdoc_format': {
|
|
26
|
+
const { action, ...rest } = args;
|
|
27
|
+
switch (action) {
|
|
28
|
+
case 'inline': return execute('doc.format.apply', rest);
|
|
29
|
+
case 'set_style': return execute('doc.styles.paragraph.setStyle', rest);
|
|
30
|
+
case 'set_alignment': return execute('doc.format.paragraph.setAlignment', rest);
|
|
31
|
+
case 'set_indentation': return execute('doc.format.paragraph.setIndentation', rest);
|
|
32
|
+
case 'set_spacing': return execute('doc.format.paragraph.setSpacing', rest);
|
|
33
|
+
case 'set_direction': return execute('doc.format.paragraph.setDirection', rest);
|
|
34
|
+
default: throw new Error(`Unknown action for superdoc_format: ${action}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
case 'superdoc_create': {
|
|
38
|
+
const { action, ...rest } = args;
|
|
39
|
+
switch (action) {
|
|
40
|
+
case 'paragraph': return execute('doc.create.paragraph', rest);
|
|
41
|
+
case 'heading': return execute('doc.create.heading', rest);
|
|
42
|
+
default: throw new Error(`Unknown action for superdoc_create: ${action}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
case 'superdoc_list': {
|
|
46
|
+
const { action, ...rest } = args;
|
|
47
|
+
switch (action) {
|
|
48
|
+
case 'insert': return execute('doc.lists.insert', rest);
|
|
49
|
+
case 'create': return execute('doc.lists.create', rest);
|
|
50
|
+
case 'detach': return execute('doc.lists.detach', rest);
|
|
51
|
+
case 'indent': return execute('doc.lists.indent', rest);
|
|
52
|
+
case 'outdent': return execute('doc.lists.outdent', rest);
|
|
53
|
+
case 'set_level': return execute('doc.lists.setLevel', rest);
|
|
54
|
+
case 'set_type': return execute('doc.lists.setType', rest);
|
|
55
|
+
default: throw new Error(`Unknown action for superdoc_list: ${action}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
case 'superdoc_comment': {
|
|
59
|
+
const { action, ...rest } = args;
|
|
60
|
+
switch (action) {
|
|
61
|
+
case 'create': return execute('doc.comments.create', rest);
|
|
62
|
+
case 'update': return execute('doc.comments.patch', rest);
|
|
63
|
+
case 'delete': return execute('doc.comments.delete', rest);
|
|
64
|
+
case 'get': return execute('doc.comments.get', rest);
|
|
65
|
+
case 'list': return execute('doc.comments.list', rest);
|
|
66
|
+
default: throw new Error(`Unknown action for superdoc_comment: ${action}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
case 'superdoc_track_changes': {
|
|
70
|
+
const { action, ...rest } = args;
|
|
71
|
+
switch (action) {
|
|
72
|
+
case 'list': return execute('doc.trackChanges.list', rest);
|
|
73
|
+
case 'decide': return execute('doc.trackChanges.decide', rest);
|
|
74
|
+
default: throw new Error(`Unknown action for superdoc_track_changes: ${action}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
case 'superdoc_search':
|
|
78
|
+
return execute('doc.query.match', args);
|
|
79
|
+
case 'superdoc_mutations': {
|
|
80
|
+
const { action, ...rest } = args;
|
|
81
|
+
switch (action) {
|
|
82
|
+
case 'preview': return execute('doc.mutations.preview', rest);
|
|
83
|
+
case 'apply': return execute('doc.mutations.apply', rest);
|
|
84
|
+
default: throw new Error(`Unknown action for superdoc_mutations: ${action}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
default:
|
|
88
|
+
throw new Error(`Unknown intent tool: ${toolName}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
package/dist/helpers/format.d.ts
CHANGED
|
@@ -12,21 +12,20 @@
|
|
|
12
12
|
*
|
|
13
13
|
* const client = createSuperDocClient();
|
|
14
14
|
* await client.connect();
|
|
15
|
+
* const doc = await client.open({ doc: './file.docx' });
|
|
15
16
|
*
|
|
16
17
|
* // Apply bold ON:
|
|
17
|
-
* await formatBold(
|
|
18
|
+
* await formatBold(doc.format.apply, { target: { kind: 'text', blockId: 'p1', range: { start: 0, end: 5 } } });
|
|
18
19
|
*
|
|
19
20
|
* // Apply explicit bold OFF (override style inheritance):
|
|
20
|
-
* await unformatBold(
|
|
21
|
+
* await unformatBold(doc.format.apply, { blockId: 'p1', start: 0, end: 5 });
|
|
21
22
|
*
|
|
22
23
|
* // Clear direct bold formatting (inherit from style cascade):
|
|
23
|
-
* await clearBold(
|
|
24
|
+
* await clearBold(doc.format.apply, { blockId: 'p1', start: 0, end: 5 });
|
|
24
25
|
* ```
|
|
25
26
|
*/
|
|
26
27
|
import type { InvokeOptions, OperationSpec } from '../runtime/transport-common.js';
|
|
27
28
|
export interface FormatHelperParams {
|
|
28
|
-
doc?: string;
|
|
29
|
-
sessionId?: string;
|
|
30
29
|
target?: {
|
|
31
30
|
kind: 'text';
|
|
32
31
|
blockId: string;
|
|
@@ -46,9 +45,8 @@ export interface FormatHelperParams {
|
|
|
46
45
|
expectedRevision?: string;
|
|
47
46
|
}
|
|
48
47
|
/**
|
|
49
|
-
* Generic invoke function that works with
|
|
50
|
-
*
|
|
51
|
-
* but helpers call the runtime directly for forward-compatibility.
|
|
48
|
+
* Generic invoke function that works with a bound document handle runtime.
|
|
49
|
+
* Accepts the same signature as SuperDocRuntime.invoke.
|
|
52
50
|
*/
|
|
53
51
|
type RuntimeInvokeFn = <T = unknown>(operation: OperationSpec, params?: Record<string, unknown>, options?: InvokeOptions) => Promise<T>;
|
|
54
52
|
/** Apply bold ON. Equivalent to `format.apply` with `inline: { bold: 'on' }`. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/helpers/format.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/helpers/format.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAoBnF,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,GAAG,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC;IAClF,2EAA2E;IAC3E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,+EAA+E;IAC/E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,6EAA6E;IAC7E,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;IAClC,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;GAGG;AACH,KAAK,eAAe,GAAG,CAAC,CAAC,GAAG,OAAO,EACjC,SAAS,EAAE,aAAa,EACxB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,OAAO,CAAC,EAAE,aAAa,KACpB,OAAO,CAAC,CAAC,CAAC,CAAC;AA0BhB,iFAAiF;AACjF,wBAAgB,UAAU,CAAC,MAAM,EAAE,eAAe,EAAE,MAAM,GAAE,kBAAuB,EAAE,OAAO,CAAC,EAAE,aAAa,oBAE3G;AAED,qFAAqF;AACrF,wBAAgB,YAAY,CAAC,MAAM,EAAE,eAAe,EAAE,MAAM,GAAE,kBAAuB,EAAE,OAAO,CAAC,EAAE,aAAa,oBAE7G;AAED,2FAA2F;AAC3F,wBAAgB,eAAe,CAAC,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|
@@ -12,31 +12,28 @@
|
|
|
12
12
|
*
|
|
13
13
|
* const client = createSuperDocClient();
|
|
14
14
|
* await client.connect();
|
|
15
|
+
* const doc = await client.open({ doc: './file.docx' });
|
|
15
16
|
*
|
|
16
17
|
* // Apply bold ON:
|
|
17
|
-
* await formatBold(
|
|
18
|
+
* await formatBold(doc.format.apply, { target: { kind: 'text', blockId: 'p1', range: { start: 0, end: 5 } } });
|
|
18
19
|
*
|
|
19
20
|
* // Apply explicit bold OFF (override style inheritance):
|
|
20
|
-
* await unformatBold(
|
|
21
|
+
* await unformatBold(doc.format.apply, { blockId: 'p1', start: 0, end: 5 });
|
|
21
22
|
*
|
|
22
23
|
* // Clear direct bold formatting (inherit from style cascade):
|
|
23
|
-
* await clearBold(
|
|
24
|
+
* await clearBold(doc.format.apply, { blockId: 'p1', start: 0, end: 5 });
|
|
24
25
|
* ```
|
|
25
26
|
*/
|
|
26
27
|
/**
|
|
27
28
|
* Minimal operation spec for `format.apply`. Used to invoke the canonical
|
|
28
29
|
* operation through the runtime without depending on generated code.
|
|
29
30
|
*
|
|
30
|
-
*
|
|
31
|
-
* start, end) are accepted via FormatHelperParams and normalized into
|
|
32
|
-
* a `target` object before invoke.
|
|
31
|
+
* doc and sessionId are omitted — the bound document handle injects them.
|
|
33
32
|
*/
|
|
34
33
|
const FORMAT_APPLY_SPEC = {
|
|
35
34
|
operationId: 'doc.format.apply',
|
|
36
35
|
commandTokens: ['format', 'apply'],
|
|
37
36
|
params: [
|
|
38
|
-
{ name: 'doc', kind: 'doc', type: 'string' },
|
|
39
|
-
{ name: 'sessionId', kind: 'doc', flag: 'session', type: 'string' },
|
|
40
37
|
{ name: 'target', kind: 'jsonFlag', type: 'json' },
|
|
41
38
|
{ name: 'inline', kind: 'jsonFlag', type: 'json' },
|
|
42
39
|
{ name: 'dryRun', kind: 'flag', type: 'boolean' },
|
package/dist/index.cjs
CHANGED
|
@@ -1,45 +1,168 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var client = require('./generated/client.cjs');
|
|
4
|
+
var contract = require('./generated/contract.cjs');
|
|
4
5
|
var process = require('./runtime/process.cjs');
|
|
6
|
+
var errors = require('./runtime/errors.cjs');
|
|
5
7
|
var skills = require('./skills.cjs');
|
|
6
8
|
var tools = require('./tools.cjs');
|
|
7
|
-
var
|
|
9
|
+
var intentDispatch_generated = require('./generated/intent-dispatch.generated.cjs');
|
|
8
10
|
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
// Session-bound runtime wrapper
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
9
14
|
/**
|
|
10
|
-
*
|
|
15
|
+
* Wraps a raw runtime and injects a fixed sessionId into every invoke call.
|
|
16
|
+
* Implements RuntimeInvoker so generated code can use it directly.
|
|
11
17
|
*
|
|
12
|
-
*
|
|
13
|
-
|
|
14
|
-
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
class BoundRuntime {
|
|
21
|
+
runtime;
|
|
22
|
+
sessionId;
|
|
23
|
+
closed = false;
|
|
24
|
+
constructor(runtime, sessionId) {
|
|
25
|
+
this.runtime = runtime;
|
|
26
|
+
this.sessionId = sessionId;
|
|
27
|
+
}
|
|
28
|
+
async invoke(operation, params = {}, options = {}) {
|
|
29
|
+
if (this.closed) {
|
|
30
|
+
throw new errors.SuperDocCliError('Document handle is closed.', {
|
|
31
|
+
code: 'DOCUMENT_CLOSED',
|
|
32
|
+
details: { sessionId: this.sessionId },
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return this.runtime.invoke(operation, { ...params, sessionId: this.sessionId }, options);
|
|
36
|
+
}
|
|
37
|
+
markClosed() {
|
|
38
|
+
this.closed = true;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// ---------------------------------------------------------------------------
|
|
42
|
+
// Document handle
|
|
43
|
+
// ---------------------------------------------------------------------------
|
|
44
|
+
/**
|
|
45
|
+
* Bound document handle. All document operations are available as typed methods.
|
|
46
|
+
* The handle injects its session id automatically — callers never pass
|
|
47
|
+
* doc or sessionId.
|
|
48
|
+
*/
|
|
49
|
+
class SuperDocDocumentCore {
|
|
50
|
+
boundRuntime;
|
|
51
|
+
_sessionId;
|
|
52
|
+
_openResult;
|
|
53
|
+
client;
|
|
54
|
+
/** @internal */
|
|
55
|
+
constructor(boundRuntime, sessionId, openResult, client$1) {
|
|
56
|
+
this.boundRuntime = boundRuntime;
|
|
57
|
+
this._sessionId = sessionId;
|
|
58
|
+
this._openResult = openResult;
|
|
59
|
+
this.client = client$1;
|
|
60
|
+
attachBoundDocApi(this, client.createBoundDocApi(this.boundRuntime));
|
|
61
|
+
}
|
|
62
|
+
get sessionId() {
|
|
63
|
+
return this._sessionId;
|
|
64
|
+
}
|
|
65
|
+
/** Read-only snapshot of the initial doc.open response metadata. */
|
|
66
|
+
get openResult() {
|
|
67
|
+
return this._openResult;
|
|
68
|
+
}
|
|
69
|
+
async save(params = {}, options = {}) {
|
|
70
|
+
return this.boundRuntime.invoke(contract.CONTRACT.operations['doc.save'], params, options);
|
|
71
|
+
}
|
|
72
|
+
async close(params = {}, options = {}) {
|
|
73
|
+
const result = await this.boundRuntime.invoke(contract.CONTRACT.operations['doc.close'], params, options);
|
|
74
|
+
this.boundRuntime.markClosed();
|
|
75
|
+
this.client.removeHandle(this._sessionId);
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
/** @internal */
|
|
79
|
+
markClosed() {
|
|
80
|
+
this.boundRuntime.markClosed();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function attachBoundDocApi(target, api) {
|
|
84
|
+
const { save: _save, close: _close, ...boundMethods } = api;
|
|
85
|
+
Object.assign(target, boundMethods);
|
|
86
|
+
}
|
|
87
|
+
const SuperDocDocument = SuperDocDocumentCore;
|
|
88
|
+
/**
|
|
89
|
+
* SuperDoc client — transport manager and document factory.
|
|
90
|
+
*
|
|
91
|
+
* Use `client.open()` to get bound document handles. Each handle is
|
|
92
|
+
* independently session-scoped and safe for concurrent use.
|
|
93
|
+
*
|
|
94
|
+
* const client = new SuperDocClient({ user: { name: 'bot' } });
|
|
95
|
+
* await client.connect();
|
|
96
|
+
* const doc = await client.open({ doc: './file.docx' });
|
|
97
|
+
* const markdown = await doc.getMarkdown();
|
|
98
|
+
* await doc.close();
|
|
99
|
+
* await client.dispose();
|
|
15
100
|
*/
|
|
16
101
|
class SuperDocClient {
|
|
17
102
|
runtime;
|
|
18
|
-
|
|
103
|
+
rawApi;
|
|
104
|
+
handles = new Map();
|
|
19
105
|
constructor(options = {}) {
|
|
20
106
|
this.runtime = new process.SuperDocRuntime(options);
|
|
21
|
-
this.
|
|
107
|
+
this.rawApi = client.createDocApi(this.runtime);
|
|
22
108
|
}
|
|
23
109
|
async connect() {
|
|
24
110
|
await this.runtime.connect();
|
|
25
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* Open a document and return a bound document handle.
|
|
114
|
+
*
|
|
115
|
+
* The returned handle injects its session id into every operation
|
|
116
|
+
* automatically. The same file can be opened multiple times with
|
|
117
|
+
* different session ids (useful for diff workflows).
|
|
118
|
+
*/
|
|
119
|
+
async open(params, options) {
|
|
120
|
+
const explicitSessionId = params.sessionId;
|
|
121
|
+
if (typeof explicitSessionId === 'string' && this.handles.has(explicitSessionId)) {
|
|
122
|
+
throw new errors.SuperDocCliError(`Session id already open in this client: ${explicitSessionId}`, {
|
|
123
|
+
code: 'SESSION_ALREADY_OPEN',
|
|
124
|
+
details: { sessionId: explicitSessionId },
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
const result = (await this.rawApi.open(params, options));
|
|
128
|
+
const contextId = result.contextId;
|
|
129
|
+
const boundRuntime = new BoundRuntime(this.runtime, contextId);
|
|
130
|
+
const handle = new SuperDocDocument(boundRuntime, contextId, result, this);
|
|
131
|
+
this.handles.set(contextId, handle);
|
|
132
|
+
return handle;
|
|
133
|
+
}
|
|
134
|
+
async describe(params = {}, options) {
|
|
135
|
+
return this.rawApi.describe(params, options);
|
|
136
|
+
}
|
|
137
|
+
async describeCommand(params, options) {
|
|
138
|
+
return this.rawApi.describeCommand(params, options);
|
|
139
|
+
}
|
|
26
140
|
async dispose() {
|
|
141
|
+
for (const handle of this.handles.values()) {
|
|
142
|
+
handle.markClosed();
|
|
143
|
+
}
|
|
144
|
+
this.handles.clear();
|
|
27
145
|
await this.runtime.dispose();
|
|
28
146
|
}
|
|
147
|
+
/** @internal */
|
|
148
|
+
removeHandle(sessionId) {
|
|
149
|
+
this.handles.delete(sessionId);
|
|
150
|
+
}
|
|
29
151
|
}
|
|
30
152
|
function createSuperDocClient(options = {}) {
|
|
31
153
|
return new SuperDocClient(options);
|
|
32
154
|
}
|
|
33
155
|
|
|
156
|
+
exports.SuperDocCliError = errors.SuperDocCliError;
|
|
34
157
|
exports.getSkill = skills.getSkill;
|
|
35
158
|
exports.installSkill = skills.installSkill;
|
|
36
159
|
exports.listSkills = skills.listSkills;
|
|
37
160
|
exports.chooseTools = tools.chooseTools;
|
|
38
161
|
exports.dispatchSuperDocTool = tools.dispatchSuperDocTool;
|
|
162
|
+
exports.getSystemPrompt = tools.getSystemPrompt;
|
|
39
163
|
exports.getToolCatalog = tools.getToolCatalog;
|
|
40
|
-
exports.inferDocumentFeatures = tools.inferDocumentFeatures;
|
|
41
164
|
exports.listTools = tools.listTools;
|
|
42
|
-
exports.
|
|
43
|
-
exports.SuperDocCliError = errors.SuperDocCliError;
|
|
165
|
+
exports.dispatchIntentTool = intentDispatch_generated.dispatchIntentTool;
|
|
44
166
|
exports.SuperDocClient = SuperDocClient;
|
|
167
|
+
exports.SuperDocDocument = SuperDocDocument;
|
|
45
168
|
exports.createSuperDocClient = createSuperDocClient;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,23 +1,89 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { type SuperDocClientOptions } from './runtime/process.js';
|
|
1
|
+
import { type BoundDocApi, type DocCloseBoundParams, type DocCloseResult, type DocSaveBoundParams, type DocSaveResult } from './generated/client.js';
|
|
2
|
+
import { SuperDocRuntime, type SuperDocClientOptions, type InvokeOptions, type OperationSpec, type RuntimeInvoker } from './runtime/process.js';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Wraps a raw runtime and injects a fixed sessionId into every invoke call.
|
|
5
|
+
* Implements RuntimeInvoker so generated code can use it directly.
|
|
5
6
|
*
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
declare class BoundRuntime implements RuntimeInvoker {
|
|
10
|
+
private readonly runtime;
|
|
11
|
+
private readonly sessionId;
|
|
12
|
+
private closed;
|
|
13
|
+
constructor(runtime: SuperDocRuntime, sessionId: string);
|
|
14
|
+
invoke<TData = unknown>(operation: OperationSpec, params?: Record<string, unknown>, options?: InvokeOptions): Promise<TData>;
|
|
15
|
+
markClosed(): void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Bound document handle. All document operations are available as typed methods.
|
|
19
|
+
* The handle injects its session id automatically — callers never pass
|
|
20
|
+
* doc or sessionId.
|
|
21
|
+
*/
|
|
22
|
+
declare class SuperDocDocumentCore {
|
|
23
|
+
private readonly boundRuntime;
|
|
24
|
+
private readonly _sessionId;
|
|
25
|
+
private readonly _openResult;
|
|
26
|
+
private readonly client;
|
|
27
|
+
/** @internal */
|
|
28
|
+
constructor(boundRuntime: BoundRuntime, sessionId: string, openResult: Record<string, unknown>, client: SuperDocClient);
|
|
29
|
+
get sessionId(): string;
|
|
30
|
+
/** Read-only snapshot of the initial doc.open response metadata. */
|
|
31
|
+
get openResult(): Record<string, unknown>;
|
|
32
|
+
save(params?: DocSaveBoundParams, options?: InvokeOptions): Promise<DocSaveResult>;
|
|
33
|
+
close(params?: DocCloseBoundParams, options?: InvokeOptions): Promise<DocCloseResult>;
|
|
34
|
+
/** @internal */
|
|
35
|
+
markClosed(): void;
|
|
36
|
+
}
|
|
37
|
+
type SuperDocDocumentInstance = SuperDocDocumentCore & BoundDocApi;
|
|
38
|
+
export declare const SuperDocDocument: new (boundRuntime: BoundRuntime, sessionId: string, openResult: Record<string, unknown>, client: SuperDocClient) => SuperDocDocumentInstance;
|
|
39
|
+
export type SuperDocDocument = SuperDocDocumentInstance;
|
|
40
|
+
export interface DocOpenParams {
|
|
41
|
+
doc?: string;
|
|
42
|
+
sessionId?: string;
|
|
43
|
+
[key: string]: unknown;
|
|
44
|
+
}
|
|
45
|
+
export interface DocDescribeCommandParams {
|
|
46
|
+
operationId: string;
|
|
47
|
+
[key: string]: unknown;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* SuperDoc client — transport manager and document factory.
|
|
51
|
+
*
|
|
52
|
+
* Use `client.open()` to get bound document handles. Each handle is
|
|
53
|
+
* independently session-scoped and safe for concurrent use.
|
|
54
|
+
*
|
|
55
|
+
* const client = new SuperDocClient({ user: { name: 'bot' } });
|
|
56
|
+
* await client.connect();
|
|
57
|
+
* const doc = await client.open({ doc: './file.docx' });
|
|
58
|
+
* const markdown = await doc.getMarkdown();
|
|
59
|
+
* await doc.close();
|
|
60
|
+
* await client.dispose();
|
|
9
61
|
*/
|
|
10
62
|
export declare class SuperDocClient {
|
|
11
63
|
private readonly runtime;
|
|
12
|
-
readonly
|
|
64
|
+
private readonly rawApi;
|
|
65
|
+
private readonly handles;
|
|
13
66
|
constructor(options?: SuperDocClientOptions);
|
|
14
67
|
connect(): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Open a document and return a bound document handle.
|
|
70
|
+
*
|
|
71
|
+
* The returned handle injects its session id into every operation
|
|
72
|
+
* automatically. The same file can be opened multiple times with
|
|
73
|
+
* different session ids (useful for diff workflows).
|
|
74
|
+
*/
|
|
75
|
+
open(params: DocOpenParams, options?: InvokeOptions): Promise<SuperDocDocument>;
|
|
76
|
+
describe(params?: Record<string, unknown>, options?: InvokeOptions): Promise<unknown>;
|
|
77
|
+
describeCommand(params: DocDescribeCommandParams, options?: InvokeOptions): Promise<unknown>;
|
|
15
78
|
dispose(): Promise<void>;
|
|
79
|
+
/** @internal */
|
|
80
|
+
removeHandle(sessionId: string): void;
|
|
16
81
|
}
|
|
17
82
|
export declare function createSuperDocClient(options?: SuperDocClientOptions): SuperDocClient;
|
|
18
83
|
export { getSkill, installSkill, listSkills } from './skills.js';
|
|
19
|
-
export { chooseTools, dispatchSuperDocTool,
|
|
84
|
+
export { chooseTools, dispatchSuperDocTool, getSystemPrompt, getToolCatalog, listTools } from './tools.js';
|
|
85
|
+
export { dispatchIntentTool } from './generated/intent-dispatch.generated.js';
|
|
20
86
|
export { SuperDocCliError } from './runtime/errors.js';
|
|
21
|
-
export type { InvokeOptions, OperationSpec, OperationParamSpec, SuperDocClientOptions } from './runtime/process.js';
|
|
22
|
-
export type {
|
|
87
|
+
export type { InvokeOptions, OperationSpec, OperationParamSpec, RuntimeInvoker, SuperDocClientOptions, } from './runtime/process.js';
|
|
88
|
+
export type { ToolChooserInput, ToolProvider } from './tools.js';
|
|
23
89
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,WAAW,EAChB,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EACnB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,eAAe,EACf,KAAK,qBAAqB,EAC1B,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,cAAc,EACpB,MAAM,sBAAsB,CAAC;AAO9B;;;;;GAKG;AACH,cAAM,YAAa,YAAW,cAAc;IAC1C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkB;IAC1C,OAAO,CAAC,QAAQ,CAA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