@superdoc-dev/sdk 1.0.0-alpha.44 → 1.0.0-alpha.45
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 +20 -10
- package/dist/generated/client.cjs +3 -0
- package/dist/generated/client.d.ts +1883 -676
- package/dist/generated/client.d.ts.map +1 -1
- package/dist/generated/client.js +3 -0
- package/dist/generated/contract.cjs +18253 -9107
- package/dist/generated/contract.d.ts.map +1 -1
- package/dist/generated/contract.js +18253 -9107
- package/dist/generated/intent-dispatch.generated.cjs +93 -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 +89 -0
- package/dist/index.cjs +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/tools.cjs +135 -211
- package/dist/tools.d.ts +17 -55
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +134 -209
- 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 +3699 -62897
- package/tools/intent_dispatch_generated.py +120 -0
- package/tools/system-prompt.md +94 -0
- package/tools/tools-policy.json +40 -95
- package/tools/tools.anthropic.json +3004 -26458
- package/tools/tools.generic.json +3543 -60785
- package/tools/tools.openai.json +2988 -27393
- package/tools/tools.vercel.json +2988 -27393
- package/tools/tool-name-map.json +0 -327
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
default: throw new Error(`Unknown action for superdoc_format: ${action}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
case 'superdoc_create': {
|
|
39
|
+
const { action, ...rest } = args;
|
|
40
|
+
switch (action) {
|
|
41
|
+
case 'paragraph': return execute('doc.create.paragraph', rest);
|
|
42
|
+
case 'heading': return execute('doc.create.heading', rest);
|
|
43
|
+
default: throw new Error(`Unknown action for superdoc_create: ${action}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
case 'superdoc_list': {
|
|
47
|
+
const { action, ...rest } = args;
|
|
48
|
+
switch (action) {
|
|
49
|
+
case 'insert': return execute('doc.lists.insert', rest);
|
|
50
|
+
case 'create': return execute('doc.lists.create', rest);
|
|
51
|
+
case 'detach': return execute('doc.lists.detach', rest);
|
|
52
|
+
case 'indent': return execute('doc.lists.indent', rest);
|
|
53
|
+
case 'outdent': return execute('doc.lists.outdent', rest);
|
|
54
|
+
case 'set_level': return execute('doc.lists.setLevel', rest);
|
|
55
|
+
case 'set_type': return execute('doc.lists.setType', rest);
|
|
56
|
+
default: throw new Error(`Unknown action for superdoc_list: ${action}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
case 'superdoc_comment': {
|
|
60
|
+
const { action, ...rest } = args;
|
|
61
|
+
switch (action) {
|
|
62
|
+
case 'create': return execute('doc.comments.create', rest);
|
|
63
|
+
case 'update': return execute('doc.comments.patch', rest);
|
|
64
|
+
case 'delete': return execute('doc.comments.delete', rest);
|
|
65
|
+
case 'get': return execute('doc.comments.get', rest);
|
|
66
|
+
case 'list': return execute('doc.comments.list', rest);
|
|
67
|
+
default: throw new Error(`Unknown action for superdoc_comment: ${action}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
case 'superdoc_track_changes': {
|
|
71
|
+
const { action, ...rest } = args;
|
|
72
|
+
switch (action) {
|
|
73
|
+
case 'list': return execute('doc.trackChanges.list', rest);
|
|
74
|
+
case 'decide': return execute('doc.trackChanges.decide', rest);
|
|
75
|
+
default: throw new Error(`Unknown action for superdoc_track_changes: ${action}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
case 'superdoc_search':
|
|
79
|
+
return execute('doc.query.match', args);
|
|
80
|
+
case 'superdoc_mutations': {
|
|
81
|
+
const { action, ...rest } = args;
|
|
82
|
+
switch (action) {
|
|
83
|
+
case 'preview': return execute('doc.mutations.preview', rest);
|
|
84
|
+
case 'apply': return execute('doc.mutations.apply', rest);
|
|
85
|
+
default: throw new Error(`Unknown action for superdoc_mutations: ${action}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
default:
|
|
89
|
+
throw new Error(`Unknown intent tool: ${toolName}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
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,CAuFT"}
|
|
@@ -0,0 +1,89 @@
|
|
|
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
|
+
default: throw new Error(`Unknown action for superdoc_format: ${action}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
case 'superdoc_create': {
|
|
37
|
+
const { action, ...rest } = args;
|
|
38
|
+
switch (action) {
|
|
39
|
+
case 'paragraph': return execute('doc.create.paragraph', rest);
|
|
40
|
+
case 'heading': return execute('doc.create.heading', rest);
|
|
41
|
+
default: throw new Error(`Unknown action for superdoc_create: ${action}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
case 'superdoc_list': {
|
|
45
|
+
const { action, ...rest } = args;
|
|
46
|
+
switch (action) {
|
|
47
|
+
case 'insert': return execute('doc.lists.insert', rest);
|
|
48
|
+
case 'create': return execute('doc.lists.create', rest);
|
|
49
|
+
case 'detach': return execute('doc.lists.detach', rest);
|
|
50
|
+
case 'indent': return execute('doc.lists.indent', rest);
|
|
51
|
+
case 'outdent': return execute('doc.lists.outdent', rest);
|
|
52
|
+
case 'set_level': return execute('doc.lists.setLevel', rest);
|
|
53
|
+
case 'set_type': return execute('doc.lists.setType', rest);
|
|
54
|
+
default: throw new Error(`Unknown action for superdoc_list: ${action}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
case 'superdoc_comment': {
|
|
58
|
+
const { action, ...rest } = args;
|
|
59
|
+
switch (action) {
|
|
60
|
+
case 'create': return execute('doc.comments.create', rest);
|
|
61
|
+
case 'update': return execute('doc.comments.patch', rest);
|
|
62
|
+
case 'delete': return execute('doc.comments.delete', rest);
|
|
63
|
+
case 'get': return execute('doc.comments.get', rest);
|
|
64
|
+
case 'list': return execute('doc.comments.list', rest);
|
|
65
|
+
default: throw new Error(`Unknown action for superdoc_comment: ${action}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
case 'superdoc_track_changes': {
|
|
69
|
+
const { action, ...rest } = args;
|
|
70
|
+
switch (action) {
|
|
71
|
+
case 'list': return execute('doc.trackChanges.list', rest);
|
|
72
|
+
case 'decide': return execute('doc.trackChanges.decide', rest);
|
|
73
|
+
default: throw new Error(`Unknown action for superdoc_track_changes: ${action}`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
case 'superdoc_search':
|
|
77
|
+
return execute('doc.query.match', args);
|
|
78
|
+
case 'superdoc_mutations': {
|
|
79
|
+
const { action, ...rest } = args;
|
|
80
|
+
switch (action) {
|
|
81
|
+
case 'preview': return execute('doc.mutations.preview', rest);
|
|
82
|
+
case 'apply': return execute('doc.mutations.apply', rest);
|
|
83
|
+
default: throw new Error(`Unknown action for superdoc_mutations: ${action}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
default:
|
|
87
|
+
throw new Error(`Unknown intent tool: ${toolName}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
package/dist/index.cjs
CHANGED
|
@@ -4,6 +4,7 @@ var client = require('./generated/client.cjs');
|
|
|
4
4
|
var process = require('./runtime/process.cjs');
|
|
5
5
|
var skills = require('./skills.cjs');
|
|
6
6
|
var tools = require('./tools.cjs');
|
|
7
|
+
var intentDispatch_generated = require('./generated/intent-dispatch.generated.cjs');
|
|
7
8
|
var errors = require('./runtime/errors.cjs');
|
|
8
9
|
|
|
9
10
|
/**
|
|
@@ -36,10 +37,10 @@ exports.installSkill = skills.installSkill;
|
|
|
36
37
|
exports.listSkills = skills.listSkills;
|
|
37
38
|
exports.chooseTools = tools.chooseTools;
|
|
38
39
|
exports.dispatchSuperDocTool = tools.dispatchSuperDocTool;
|
|
39
|
-
exports.
|
|
40
|
+
exports.getSystemPrompt = tools.getSystemPrompt;
|
|
40
41
|
exports.getToolCatalog = tools.getToolCatalog;
|
|
41
42
|
exports.listTools = tools.listTools;
|
|
42
|
-
exports.
|
|
43
|
+
exports.dispatchIntentTool = intentDispatch_generated.dispatchIntentTool;
|
|
43
44
|
exports.SuperDocCliError = errors.SuperDocCliError;
|
|
44
45
|
exports.SuperDocClient = SuperDocClient;
|
|
45
46
|
exports.createSuperDocClient = createSuperDocClient;
|
package/dist/index.d.ts
CHANGED
|
@@ -16,8 +16,9 @@ export declare class SuperDocClient {
|
|
|
16
16
|
}
|
|
17
17
|
export declare function createSuperDocClient(options?: SuperDocClientOptions): SuperDocClient;
|
|
18
18
|
export { getSkill, installSkill, listSkills } from './skills.js';
|
|
19
|
-
export { chooseTools, dispatchSuperDocTool,
|
|
19
|
+
export { chooseTools, dispatchSuperDocTool, getSystemPrompt, getToolCatalog, listTools } from './tools.js';
|
|
20
|
+
export { dispatchIntentTool } from './generated/intent-dispatch.generated.js';
|
|
20
21
|
export { SuperDocCliError } from './runtime/errors.js';
|
|
21
22
|
export type { InvokeOptions, OperationSpec, OperationParamSpec, SuperDocClientOptions } from './runtime/process.js';
|
|
22
|
-
export type { ToolChooserInput,
|
|
23
|
+
export type { ToolChooserInput, ToolProvider } from './tools.js';
|
|
23
24
|
//# 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,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAmB,KAAK,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAEnF;;;;;;GAMG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkB;IAC1C,QAAQ,CAAC,GAAG,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;gBAElC,OAAO,GAAE,qBAA0B;IAKzC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAG/B;AAED,wBAAgB,oBAAoB,CAAC,OAAO,GAAE,qBAA0B,GAAG,cAAc,CAExF;AAED,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAmB,KAAK,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAEnF;;;;;;GAMG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkB;IAC1C,QAAQ,CAAC,GAAG,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;gBAElC,OAAO,GAAE,qBAA0B;IAKzC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAG/B;AAED,wBAAgB,oBAAoB,CAAC,OAAO,GAAE,qBAA0B,GAAG,cAAc,CAExF;AAED,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,eAAe,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC3G,OAAO,EAAE,kBAAkB,EAAE,MAAM,0CAA0C,CAAC;AAC9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AACpH,YAAY,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -25,5 +25,6 @@ export function createSuperDocClient(options = {}) {
|
|
|
25
25
|
return new SuperDocClient(options);
|
|
26
26
|
}
|
|
27
27
|
export { getSkill, installSkill, listSkills } from './skills.js';
|
|
28
|
-
export { chooseTools, dispatchSuperDocTool,
|
|
28
|
+
export { chooseTools, dispatchSuperDocTool, getSystemPrompt, getToolCatalog, listTools } from './tools.js';
|
|
29
|
+
export { dispatchIntentTool } from './generated/intent-dispatch.generated.js';
|
|
29
30
|
export { SuperDocCliError } from './runtime/errors.js';
|
package/dist/tools.cjs
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var promises = require('node:fs/promises');
|
|
4
|
-
var node_fs = require('node:fs');
|
|
5
4
|
var path = require('node:path');
|
|
6
5
|
var node_url = require('node:url');
|
|
7
|
-
var contract = require('./generated/contract.cjs');
|
|
8
6
|
var errors = require('./runtime/errors.cjs');
|
|
7
|
+
var intentDispatch_generated = require('./generated/intent-dispatch.generated.cjs');
|
|
9
8
|
|
|
10
9
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
11
10
|
// Resolve tools directory relative to package root (works from both src/ and dist/)
|
|
@@ -16,37 +15,9 @@ const providerFileByName = {
|
|
|
16
15
|
vercel: 'tools.vercel.json',
|
|
17
16
|
generic: 'tools.generic.json',
|
|
18
17
|
};
|
|
19
|
-
let _policyCache = null;
|
|
20
|
-
function loadPolicy() {
|
|
21
|
-
if (_policyCache)
|
|
22
|
-
return _policyCache;
|
|
23
|
-
const raw = node_fs.readFileSync(path.join(toolsDir, 'tools-policy.json'), 'utf8');
|
|
24
|
-
_policyCache = JSON.parse(raw);
|
|
25
|
-
return _policyCache;
|
|
26
|
-
}
|
|
27
18
|
function isRecord(value) {
|
|
28
19
|
return typeof value === 'object' && value != null && !Array.isArray(value);
|
|
29
20
|
}
|
|
30
|
-
function isPresent(value) {
|
|
31
|
-
if (value == null)
|
|
32
|
-
return false;
|
|
33
|
-
if (Array.isArray(value))
|
|
34
|
-
return value.length > 0;
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
function extractProviderToolName(tool) {
|
|
38
|
-
// Anthropic / Generic: top-level name
|
|
39
|
-
if (typeof tool.name === 'string')
|
|
40
|
-
return tool.name;
|
|
41
|
-
// OpenAI / Vercel: nested under function.name
|
|
42
|
-
if (isRecord(tool.function) && typeof tool.function.name === 'string') {
|
|
43
|
-
return tool.function.name;
|
|
44
|
-
}
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
function invalidArgument(message, details) {
|
|
48
|
-
throw new errors.SuperDocCliError(message, { code: 'INVALID_ARGUMENT', details });
|
|
49
|
-
}
|
|
50
21
|
async function readJson(fileName) {
|
|
51
22
|
const filePath = path.join(toolsDir, fileName);
|
|
52
23
|
let raw = '';
|
|
@@ -78,87 +49,43 @@ async function readJson(fileName) {
|
|
|
78
49
|
async function loadProviderBundle(provider) {
|
|
79
50
|
return readJson(providerFileByName[provider]);
|
|
80
51
|
}
|
|
81
|
-
async function loadToolNameMap() {
|
|
82
|
-
return readJson('tool-name-map.json');
|
|
83
|
-
}
|
|
84
52
|
async function loadCatalog() {
|
|
85
53
|
return readJson('catalog.json');
|
|
86
54
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const policy = loadPolicy();
|
|
90
|
-
return policy.groups;
|
|
55
|
+
async function getToolCatalog() {
|
|
56
|
+
return loadCatalog();
|
|
91
57
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const
|
|
95
|
-
if (!
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
for (const key of Object.keys(args)) {
|
|
101
|
-
if (!allowedParams.has(key)) {
|
|
102
|
-
invalidArgument(`Unexpected parameter ${key} for ${operationId}.`);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
// Required-param enforcement
|
|
106
|
-
for (const param of operation.params) {
|
|
107
|
-
if ('required' in param && Boolean(param.required) && args[param.name] == null) {
|
|
108
|
-
invalidArgument(`Missing required parameter ${param.name} for ${operationId}.`);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
// Constraint validation (CLI handles schema-level type validation authoritatively)
|
|
112
|
-
const constraints = 'constraints' in operation ? operation.constraints : undefined;
|
|
113
|
-
if (!constraints || !isRecord(constraints))
|
|
114
|
-
return;
|
|
115
|
-
const mutuallyExclusive = Array.isArray(constraints.mutuallyExclusive) ? constraints.mutuallyExclusive : [];
|
|
116
|
-
const requiresOneOf = Array.isArray(constraints.requiresOneOf) ? constraints.requiresOneOf : [];
|
|
117
|
-
const requiredWhen = Array.isArray(constraints.requiredWhen) ? constraints.requiredWhen : [];
|
|
118
|
-
for (const group of mutuallyExclusive) {
|
|
119
|
-
if (!Array.isArray(group))
|
|
120
|
-
continue;
|
|
121
|
-
const present = group.filter((name) => isPresent(args[name]));
|
|
122
|
-
if (present.length > 1) {
|
|
123
|
-
invalidArgument(`Arguments are mutually exclusive for ${operationId}: ${group.join(', ')}`, {
|
|
124
|
-
operationId,
|
|
125
|
-
group,
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
for (const group of requiresOneOf) {
|
|
130
|
-
if (!Array.isArray(group))
|
|
131
|
-
continue;
|
|
132
|
-
const hasAny = group.some((name) => isPresent(args[name]));
|
|
133
|
-
if (!hasAny) {
|
|
134
|
-
invalidArgument(`One of the following arguments is required for ${operationId}: ${group.join(', ')}`, {
|
|
135
|
-
operationId,
|
|
136
|
-
group,
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
for (const rule of requiredWhen) {
|
|
141
|
-
if (!isRecord(rule))
|
|
142
|
-
continue;
|
|
143
|
-
const whenValue = args[rule.whenParam];
|
|
144
|
-
let shouldRequire = false;
|
|
145
|
-
if (Object.prototype.hasOwnProperty.call(rule, 'equals')) {
|
|
146
|
-
shouldRequire = whenValue === rule.equals;
|
|
147
|
-
}
|
|
148
|
-
else if (Object.prototype.hasOwnProperty.call(rule, 'present')) {
|
|
149
|
-
const present = rule.present === true;
|
|
150
|
-
shouldRequire = present ? isPresent(whenValue) : !isPresent(whenValue);
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
shouldRequire = isPresent(whenValue);
|
|
154
|
-
}
|
|
155
|
-
if (shouldRequire && !isPresent(args[rule.param])) {
|
|
156
|
-
invalidArgument(`Argument ${rule.param} is required by constraints for ${operationId}.`, {
|
|
157
|
-
operationId,
|
|
158
|
-
rule,
|
|
159
|
-
});
|
|
160
|
-
}
|
|
58
|
+
async function listTools(provider) {
|
|
59
|
+
const bundle = await loadProviderBundle(provider);
|
|
60
|
+
const tools = bundle.tools;
|
|
61
|
+
if (!Array.isArray(tools)) {
|
|
62
|
+
throw new errors.SuperDocCliError('Tool provider bundle is missing tools array.', {
|
|
63
|
+
code: 'TOOLS_ASSET_INVALID',
|
|
64
|
+
details: { provider },
|
|
65
|
+
});
|
|
161
66
|
}
|
|
67
|
+
return tools;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Select all intent tools for a specific provider.
|
|
71
|
+
*
|
|
72
|
+
* Returns all intent tools in the requested provider format.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* const { tools } = await chooseTools({ provider: 'openai' });
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
async function chooseTools(input) {
|
|
80
|
+
const bundle = await loadProviderBundle(input.provider);
|
|
81
|
+
const tools = Array.isArray(bundle.tools) ? bundle.tools : [];
|
|
82
|
+
return {
|
|
83
|
+
tools,
|
|
84
|
+
meta: {
|
|
85
|
+
provider: input.provider,
|
|
86
|
+
toolCount: tools.length,
|
|
87
|
+
},
|
|
88
|
+
};
|
|
162
89
|
}
|
|
163
90
|
function resolveDocApiMethod(client, operationId) {
|
|
164
91
|
const tokens = operationId.split('.').slice(1);
|
|
@@ -180,133 +107,130 @@ function resolveDocApiMethod(client, operationId) {
|
|
|
180
107
|
}
|
|
181
108
|
return cursor;
|
|
182
109
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
const tools = bundle.tools;
|
|
189
|
-
if (!Array.isArray(tools)) {
|
|
190
|
-
throw new errors.SuperDocCliError('Tool provider bundle is missing tools array.', {
|
|
191
|
-
code: 'TOOLS_ASSET_INVALID',
|
|
192
|
-
details: { provider },
|
|
193
|
-
});
|
|
110
|
+
// Cached catalog instance — loaded once per process.
|
|
111
|
+
let _catalogCache = null;
|
|
112
|
+
async function getCachedCatalog() {
|
|
113
|
+
if (_catalogCache == null) {
|
|
114
|
+
_catalogCache = await loadCatalog();
|
|
194
115
|
}
|
|
195
|
-
return
|
|
196
|
-
}
|
|
197
|
-
async function resolveToolOperation(toolName) {
|
|
198
|
-
const map = await loadToolNameMap();
|
|
199
|
-
return typeof map[toolName] === 'string' ? map[toolName] : null;
|
|
116
|
+
return _catalogCache;
|
|
200
117
|
}
|
|
201
118
|
/**
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
* **mode='essential'** (default): Returns only essential tools + discover_tools.
|
|
205
|
-
* Pass `groups` to additionally load all tools from those categories.
|
|
206
|
-
*
|
|
207
|
-
* **mode='all'**: Returns all tools from requested groups (or all groups if
|
|
208
|
-
* `groups` is omitted). No discover_tools included by default.
|
|
119
|
+
* Validate tool arguments against the catalog schema.
|
|
209
120
|
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
* // Essential + all comment tools
|
|
216
|
-
* const { tools } = await chooseTools({ provider: 'openai', groups: ['comments'] });
|
|
217
|
-
*
|
|
218
|
-
* // All tools (old behavior)
|
|
219
|
-
* const { tools } = await chooseTools({ provider: 'openai', mode: 'all' });
|
|
220
|
-
* ```
|
|
121
|
+
* Checks three things in order:
|
|
122
|
+
* 1. No unknown keys (additionalProperties: false in merged schema)
|
|
123
|
+
* 2. All universally-required keys present (merged schema `required`)
|
|
124
|
+
* 3. All action-specific required keys present (per-operation `required`)
|
|
221
125
|
*/
|
|
222
|
-
|
|
223
|
-
const
|
|
224
|
-
const
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
if (essentialNames.has(tool.toolName))
|
|
234
|
-
return true;
|
|
235
|
-
if (requestedGroups && requestedGroups.has(tool.category))
|
|
236
|
-
return true;
|
|
237
|
-
return false;
|
|
126
|
+
function validateToolArgs(toolName, args, tool) {
|
|
127
|
+
const schema = tool.inputSchema;
|
|
128
|
+
const properties = isRecord(schema.properties) ? schema.properties : {};
|
|
129
|
+
const required = Array.isArray(schema.required) ? schema.required : [];
|
|
130
|
+
// 1. Reject unknown keys
|
|
131
|
+
const knownKeys = new Set(Object.keys(properties));
|
|
132
|
+
const unknownKeys = Object.keys(args).filter((k) => !knownKeys.has(k));
|
|
133
|
+
if (unknownKeys.length > 0) {
|
|
134
|
+
throw new errors.SuperDocCliError(`Unknown argument(s) for ${toolName}: ${unknownKeys.join(', ')}`, {
|
|
135
|
+
code: 'INVALID_ARGUMENT',
|
|
136
|
+
details: { toolName, unknownKeys, knownKeys: [...knownKeys] },
|
|
238
137
|
});
|
|
239
138
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
|
|
139
|
+
// 2. Reject missing universally-required keys
|
|
140
|
+
const missingKeys = required.filter((k) => args[k] == null);
|
|
141
|
+
if (missingKeys.length > 0) {
|
|
142
|
+
throw new errors.SuperDocCliError(`Missing required argument(s) for ${toolName}: ${missingKeys.join(', ')}`, {
|
|
143
|
+
code: 'INVALID_ARGUMENT',
|
|
144
|
+
details: { toolName, missingKeys },
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
// 3. Reject missing per-operation required keys.
|
|
148
|
+
// For multi-action tools, resolve the operation by action; for single-op
|
|
149
|
+
// tools, use the sole operation entry.
|
|
150
|
+
const action = args.action;
|
|
151
|
+
let op;
|
|
152
|
+
if (typeof action === 'string' && tool.operations.length > 1) {
|
|
153
|
+
op = tool.operations.find((o) => o.intentAction === action);
|
|
154
|
+
}
|
|
155
|
+
else if (tool.operations.length === 1) {
|
|
156
|
+
op = tool.operations[0];
|
|
157
|
+
}
|
|
158
|
+
if (op) {
|
|
159
|
+
validateOperationRequired(toolName, action, args, op);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Check per-operation required constraints.
|
|
164
|
+
*
|
|
165
|
+
* Handles two shapes emitted by the codegen:
|
|
166
|
+
* - `required: string[]` — all listed keys must be present
|
|
167
|
+
* - `requiredOneOf: string[][]` — at least one branch must be fully satisfied
|
|
168
|
+
* (mirrors JSON Schema `oneOf` with per-branch `required` arrays)
|
|
169
|
+
*/
|
|
170
|
+
function validateOperationRequired(toolName, action, args, op) {
|
|
171
|
+
const actionLabel = typeof action === 'string' ? ` action "${action}"` : '';
|
|
172
|
+
if (op.requiredOneOf && op.requiredOneOf.length > 0) {
|
|
173
|
+
const satisfied = op.requiredOneOf.some((branch) => branch.every((k) => args[k] != null));
|
|
174
|
+
if (!satisfied) {
|
|
175
|
+
const options = op.requiredOneOf.map((b) => b.join(' + ')).join(' | ');
|
|
176
|
+
throw new errors.SuperDocCliError(`Missing required argument(s) for ${toolName}${actionLabel}: must provide one of: ${options}`, {
|
|
177
|
+
code: 'INVALID_ARGUMENT',
|
|
178
|
+
details: { toolName, action, requiredOneOf: op.requiredOneOf },
|
|
179
|
+
});
|
|
249
180
|
}
|
|
250
|
-
selected = catalog.tools.filter((tool) => groups.has(tool.category));
|
|
251
181
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
const selectedProviderTools = selected
|
|
260
|
-
.map((tool) => providerIndex.get(tool.toolName))
|
|
261
|
-
.filter((tool) => Boolean(tool));
|
|
262
|
-
// Append discover_tools if requested
|
|
263
|
-
if (includeDiscover) {
|
|
264
|
-
const discoverTool = providerIndex.get('discover_tools');
|
|
265
|
-
if (discoverTool) {
|
|
266
|
-
selectedProviderTools.push(discoverTool);
|
|
182
|
+
else if (op.required && op.required.length > 0) {
|
|
183
|
+
const missingActionKeys = op.required.filter((k) => args[k] == null);
|
|
184
|
+
if (missingActionKeys.length > 0) {
|
|
185
|
+
throw new errors.SuperDocCliError(`Missing required argument(s) for ${toolName}${actionLabel}: ${missingActionKeys.join(', ')}`, {
|
|
186
|
+
code: 'INVALID_ARGUMENT',
|
|
187
|
+
details: { toolName, action, missingKeys: missingActionKeys },
|
|
188
|
+
});
|
|
267
189
|
}
|
|
268
190
|
}
|
|
269
|
-
const resolvedGroups = mode === 'essential' ? (input.groups ?? []) : (input.groups ?? policy.groups);
|
|
270
|
-
return {
|
|
271
|
-
tools: selectedProviderTools,
|
|
272
|
-
selected: selected.map((tool) => ({
|
|
273
|
-
operationId: tool.operationId,
|
|
274
|
-
toolName: tool.toolName,
|
|
275
|
-
category: tool.category,
|
|
276
|
-
mutates: tool.mutates,
|
|
277
|
-
})),
|
|
278
|
-
meta: {
|
|
279
|
-
provider: input.provider,
|
|
280
|
-
mode,
|
|
281
|
-
groups: [...resolvedGroups],
|
|
282
|
-
selectedCount: selectedProviderTools.length,
|
|
283
|
-
},
|
|
284
|
-
};
|
|
285
191
|
}
|
|
286
192
|
async function dispatchSuperDocTool(client, toolName, args = {}, invokeOptions) {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
code: 'TOOL_NOT_FOUND',
|
|
193
|
+
if (!isRecord(args)) {
|
|
194
|
+
throw new errors.SuperDocCliError(`Tool arguments for ${toolName} must be an object.`, {
|
|
195
|
+
code: 'INVALID_ARGUMENT',
|
|
291
196
|
details: { toolName },
|
|
292
197
|
});
|
|
293
198
|
}
|
|
294
|
-
|
|
295
|
-
|
|
199
|
+
// Validate against the tool schema before dispatch.
|
|
200
|
+
const catalog = await getCachedCatalog();
|
|
201
|
+
const tool = catalog.tools.find((t) => t.toolName === toolName);
|
|
202
|
+
if (tool == null) {
|
|
203
|
+
throw new errors.SuperDocCliError(`Unknown tool: ${toolName}`, {
|
|
204
|
+
code: 'TOOL_DISPATCH_NOT_FOUND',
|
|
205
|
+
details: { toolName },
|
|
206
|
+
});
|
|
296
207
|
}
|
|
208
|
+
validateToolArgs(toolName, args, tool);
|
|
297
209
|
// Strip doc/sessionId — the SDK client manages session targeting after doc.open().
|
|
298
|
-
// Models fill these in because the tool schemas expose them, but passing them
|
|
299
|
-
// alongside an active session causes "stateless input.doc cannot be combined
|
|
300
|
-
// with a session target" errors.
|
|
301
210
|
const { doc: _doc, sessionId: _sid, ...cleanArgs } = args;
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
211
|
+
return intentDispatch_generated.dispatchIntentTool(toolName, cleanArgs, (operationId, input) => {
|
|
212
|
+
const method = resolveDocApiMethod(client, operationId);
|
|
213
|
+
return method(input, invokeOptions);
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Read the bundled system prompt for intent tools.
|
|
218
|
+
*/
|
|
219
|
+
async function getSystemPrompt() {
|
|
220
|
+
const promptPath = path.join(toolsDir, 'system-prompt.md');
|
|
221
|
+
try {
|
|
222
|
+
return await promises.readFile(promptPath, 'utf8');
|
|
223
|
+
}
|
|
224
|
+
catch {
|
|
225
|
+
throw new errors.SuperDocCliError('System prompt not found.', {
|
|
226
|
+
code: 'TOOLS_ASSET_NOT_FOUND',
|
|
227
|
+
details: { filePath: promptPath },
|
|
228
|
+
});
|
|
229
|
+
}
|
|
305
230
|
}
|
|
306
231
|
|
|
307
232
|
exports.chooseTools = chooseTools;
|
|
308
233
|
exports.dispatchSuperDocTool = dispatchSuperDocTool;
|
|
309
|
-
exports.
|
|
234
|
+
exports.getSystemPrompt = getSystemPrompt;
|
|
310
235
|
exports.getToolCatalog = getToolCatalog;
|
|
311
236
|
exports.listTools = listTools;
|
|
312
|
-
exports.resolveToolOperation = resolveToolOperation;
|