@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
package/dist/tools.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
|
-
import { readFileSync } from 'node:fs';
|
|
3
2
|
import path from 'node:path';
|
|
4
3
|
import { fileURLToPath } from 'node:url';
|
|
5
|
-
import { CONTRACT } from './generated/contract.js';
|
|
6
4
|
import { SuperDocCliError } from './runtime/errors.js';
|
|
5
|
+
import { dispatchIntentTool } from './generated/intent-dispatch.generated.js';
|
|
7
6
|
// Resolve tools directory relative to package root (works from both src/ and dist/)
|
|
8
7
|
const toolsDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', 'tools');
|
|
9
8
|
const providerFileByName = {
|
|
@@ -12,37 +11,9 @@ const providerFileByName = {
|
|
|
12
11
|
vercel: 'tools.vercel.json',
|
|
13
12
|
generic: 'tools.generic.json',
|
|
14
13
|
};
|
|
15
|
-
let _policyCache = null;
|
|
16
|
-
function loadPolicy() {
|
|
17
|
-
if (_policyCache)
|
|
18
|
-
return _policyCache;
|
|
19
|
-
const raw = readFileSync(path.join(toolsDir, 'tools-policy.json'), 'utf8');
|
|
20
|
-
_policyCache = JSON.parse(raw);
|
|
21
|
-
return _policyCache;
|
|
22
|
-
}
|
|
23
14
|
function isRecord(value) {
|
|
24
15
|
return typeof value === 'object' && value != null && !Array.isArray(value);
|
|
25
16
|
}
|
|
26
|
-
function isPresent(value) {
|
|
27
|
-
if (value == null)
|
|
28
|
-
return false;
|
|
29
|
-
if (Array.isArray(value))
|
|
30
|
-
return value.length > 0;
|
|
31
|
-
return true;
|
|
32
|
-
}
|
|
33
|
-
function extractProviderToolName(tool) {
|
|
34
|
-
// Anthropic / Generic: top-level name
|
|
35
|
-
if (typeof tool.name === 'string')
|
|
36
|
-
return tool.name;
|
|
37
|
-
// OpenAI / Vercel: nested under function.name
|
|
38
|
-
if (isRecord(tool.function) && typeof tool.function.name === 'string') {
|
|
39
|
-
return tool.function.name;
|
|
40
|
-
}
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
function invalidArgument(message, details) {
|
|
44
|
-
throw new SuperDocCliError(message, { code: 'INVALID_ARGUMENT', details });
|
|
45
|
-
}
|
|
46
17
|
async function readJson(fileName) {
|
|
47
18
|
const filePath = path.join(toolsDir, fileName);
|
|
48
19
|
let raw = '';
|
|
@@ -74,105 +45,47 @@ async function readJson(fileName) {
|
|
|
74
45
|
async function loadProviderBundle(provider) {
|
|
75
46
|
return readJson(providerFileByName[provider]);
|
|
76
47
|
}
|
|
77
|
-
async function loadToolNameMap() {
|
|
78
|
-
return readJson('tool-name-map.json');
|
|
79
|
-
}
|
|
80
48
|
async function loadCatalog() {
|
|
81
49
|
return readJson('catalog.json');
|
|
82
50
|
}
|
|
83
|
-
function
|
|
84
|
-
return
|
|
85
|
-
hasTables: Boolean(features?.hasTables),
|
|
86
|
-
hasLists: Boolean(features?.hasLists),
|
|
87
|
-
hasComments: Boolean(features?.hasComments),
|
|
88
|
-
hasTrackedChanges: Boolean(features?.hasTrackedChanges),
|
|
89
|
-
isEmptyDocument: Boolean(features?.isEmptyDocument),
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
function stableSortByPhasePriority(entries, priorityOrder) {
|
|
93
|
-
const priority = new Map(priorityOrder.map((category, index) => [category, index]));
|
|
94
|
-
return [...entries].sort((a, b) => {
|
|
95
|
-
const aPriority = priority.get(a.category) ?? Number.MAX_SAFE_INTEGER;
|
|
96
|
-
const bPriority = priority.get(b.category) ?? Number.MAX_SAFE_INTEGER;
|
|
97
|
-
if (aPriority !== bPriority)
|
|
98
|
-
return aPriority - bPriority;
|
|
99
|
-
return a.toolName.localeCompare(b.toolName);
|
|
100
|
-
});
|
|
51
|
+
export async function getToolCatalog() {
|
|
52
|
+
return loadCatalog();
|
|
101
53
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const
|
|
105
|
-
if (!
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
for (const key of Object.keys(args)) {
|
|
111
|
-
if (!allowedParams.has(key)) {
|
|
112
|
-
invalidArgument(`Unexpected parameter ${key} for ${operationId}.`);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
// Required-param enforcement
|
|
116
|
-
for (const param of operation.params) {
|
|
117
|
-
if ('required' in param && Boolean(param.required) && args[param.name] == null) {
|
|
118
|
-
invalidArgument(`Missing required parameter ${param.name} for ${operationId}.`);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
// Constraint validation (CLI handles schema-level type validation authoritatively)
|
|
122
|
-
const constraints = 'constraints' in operation ? operation.constraints : undefined;
|
|
123
|
-
if (!constraints || !isRecord(constraints))
|
|
124
|
-
return;
|
|
125
|
-
const mutuallyExclusive = Array.isArray(constraints.mutuallyExclusive) ? constraints.mutuallyExclusive : [];
|
|
126
|
-
const requiresOneOf = Array.isArray(constraints.requiresOneOf) ? constraints.requiresOneOf : [];
|
|
127
|
-
const requiredWhen = Array.isArray(constraints.requiredWhen) ? constraints.requiredWhen : [];
|
|
128
|
-
for (const group of mutuallyExclusive) {
|
|
129
|
-
if (!Array.isArray(group))
|
|
130
|
-
continue;
|
|
131
|
-
const present = group.filter((name) => isPresent(args[name]));
|
|
132
|
-
if (present.length > 1) {
|
|
133
|
-
invalidArgument(`Arguments are mutually exclusive for ${operationId}: ${group.join(', ')}`, {
|
|
134
|
-
operationId,
|
|
135
|
-
group,
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
for (const group of requiresOneOf) {
|
|
140
|
-
if (!Array.isArray(group))
|
|
141
|
-
continue;
|
|
142
|
-
const hasAny = group.some((name) => isPresent(args[name]));
|
|
143
|
-
if (!hasAny) {
|
|
144
|
-
invalidArgument(`One of the following arguments is required for ${operationId}: ${group.join(', ')}`, {
|
|
145
|
-
operationId,
|
|
146
|
-
group,
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
for (const rule of requiredWhen) {
|
|
151
|
-
if (!isRecord(rule))
|
|
152
|
-
continue;
|
|
153
|
-
const whenValue = args[rule.whenParam];
|
|
154
|
-
let shouldRequire = false;
|
|
155
|
-
if (Object.prototype.hasOwnProperty.call(rule, 'equals')) {
|
|
156
|
-
shouldRequire = whenValue === rule.equals;
|
|
157
|
-
}
|
|
158
|
-
else if (Object.prototype.hasOwnProperty.call(rule, 'present')) {
|
|
159
|
-
const present = rule.present === true;
|
|
160
|
-
shouldRequire = present ? isPresent(whenValue) : !isPresent(whenValue);
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
shouldRequire = isPresent(whenValue);
|
|
164
|
-
}
|
|
165
|
-
if (shouldRequire && !isPresent(args[rule.param])) {
|
|
166
|
-
invalidArgument(`Argument ${rule.param} is required by constraints for ${operationId}.`, {
|
|
167
|
-
operationId,
|
|
168
|
-
rule,
|
|
169
|
-
});
|
|
170
|
-
}
|
|
54
|
+
export async function listTools(provider) {
|
|
55
|
+
const bundle = await loadProviderBundle(provider);
|
|
56
|
+
const tools = bundle.tools;
|
|
57
|
+
if (!Array.isArray(tools)) {
|
|
58
|
+
throw new SuperDocCliError('Tool provider bundle is missing tools array.', {
|
|
59
|
+
code: 'TOOLS_ASSET_INVALID',
|
|
60
|
+
details: { provider },
|
|
61
|
+
});
|
|
171
62
|
}
|
|
63
|
+
return tools;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Select all intent tools for a specific provider.
|
|
67
|
+
*
|
|
68
|
+
* Returns all intent tools in the requested provider format.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* const { tools } = await chooseTools({ provider: 'openai' });
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export async function chooseTools(input) {
|
|
76
|
+
const bundle = await loadProviderBundle(input.provider);
|
|
77
|
+
const tools = Array.isArray(bundle.tools) ? bundle.tools : [];
|
|
78
|
+
return {
|
|
79
|
+
tools,
|
|
80
|
+
meta: {
|
|
81
|
+
provider: input.provider,
|
|
82
|
+
toolCount: tools.length,
|
|
83
|
+
},
|
|
84
|
+
};
|
|
172
85
|
}
|
|
173
|
-
function resolveDocApiMethod(
|
|
86
|
+
function resolveDocApiMethod(documentHandle, operationId) {
|
|
174
87
|
const tokens = operationId.split('.').slice(1);
|
|
175
|
-
let cursor =
|
|
88
|
+
let cursor = documentHandle;
|
|
176
89
|
for (const token of tokens) {
|
|
177
90
|
if (!isRecord(cursor) || !(token in cursor)) {
|
|
178
91
|
throw new SuperDocCliError(`No SDK doc method found for operation ${operationId}.`, {
|
|
@@ -190,178 +103,128 @@ function resolveDocApiMethod(client, operationId) {
|
|
|
190
103
|
}
|
|
191
104
|
return cursor;
|
|
192
105
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
106
|
+
// Cached catalog instance — loaded once per process.
|
|
107
|
+
let _catalogCache = null;
|
|
108
|
+
async function getCachedCatalog() {
|
|
109
|
+
if (_catalogCache == null) {
|
|
110
|
+
_catalogCache = await loadCatalog();
|
|
111
|
+
}
|
|
112
|
+
return _catalogCache;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Validate tool arguments against the catalog schema.
|
|
116
|
+
*
|
|
117
|
+
* Checks three things in order:
|
|
118
|
+
* 1. No unknown keys (additionalProperties: false in merged schema)
|
|
119
|
+
* 2. All universally-required keys present (merged schema `required`)
|
|
120
|
+
* 3. All action-specific required keys present (per-operation `required`)
|
|
121
|
+
*/
|
|
122
|
+
function validateToolArgs(toolName, args, tool) {
|
|
123
|
+
const schema = tool.inputSchema;
|
|
124
|
+
const properties = isRecord(schema.properties) ? schema.properties : {};
|
|
125
|
+
const required = Array.isArray(schema.required) ? schema.required : [];
|
|
126
|
+
// 1. Reject unknown keys
|
|
127
|
+
const knownKeys = new Set(Object.keys(properties));
|
|
128
|
+
const unknownKeys = Object.keys(args).filter((k) => !knownKeys.has(k));
|
|
129
|
+
if (unknownKeys.length > 0) {
|
|
130
|
+
throw new SuperDocCliError(`Unknown argument(s) for ${toolName}: ${unknownKeys.join(', ')}`, {
|
|
131
|
+
code: 'INVALID_ARGUMENT',
|
|
132
|
+
details: { toolName, unknownKeys, knownKeys: [...knownKeys] },
|
|
213
133
|
});
|
|
214
134
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
if (!isRecord(infoResult)) {
|
|
223
|
-
return {
|
|
224
|
-
hasTables: false,
|
|
225
|
-
hasLists: false,
|
|
226
|
-
hasComments: false,
|
|
227
|
-
hasTrackedChanges: false,
|
|
228
|
-
isEmptyDocument: false,
|
|
229
|
-
};
|
|
135
|
+
// 2. Reject missing universally-required keys
|
|
136
|
+
const missingKeys = required.filter((k) => args[k] == null);
|
|
137
|
+
if (missingKeys.length > 0) {
|
|
138
|
+
throw new SuperDocCliError(`Missing required argument(s) for ${toolName}: ${missingKeys.join(', ')}`, {
|
|
139
|
+
code: 'INVALID_ARGUMENT',
|
|
140
|
+
details: { toolName, missingKeys },
|
|
141
|
+
});
|
|
230
142
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
const indexByToolName = new Map(profileTools.map((tool) => [tool.toolName, tool]));
|
|
265
|
-
let candidates = profileTools.filter((tool) => {
|
|
266
|
-
if (tool.requiredCapabilities.some((capability) => !featureMap[capability])) {
|
|
267
|
-
excluded.push({ toolName: tool.toolName, reason: 'missing-required-capability' });
|
|
268
|
-
return false;
|
|
269
|
-
}
|
|
270
|
-
if (!allowMutatingTools && tool.mutates) {
|
|
271
|
-
excluded.push({ toolName: tool.toolName, reason: 'mutations-disabled' });
|
|
272
|
-
return false;
|
|
273
|
-
}
|
|
274
|
-
if (includeCategories.size > 0 && !includeCategories.has(tool.category)) {
|
|
275
|
-
excluded.push({ toolName: tool.toolName, reason: 'category-not-included' });
|
|
276
|
-
return false;
|
|
277
|
-
}
|
|
278
|
-
if (excludeCategories.has(tool.category)) {
|
|
279
|
-
excluded.push({ toolName: tool.toolName, reason: 'phase-category-excluded' });
|
|
280
|
-
return false;
|
|
281
|
-
}
|
|
282
|
-
return true;
|
|
283
|
-
});
|
|
284
|
-
const forceExclude = new Set(input.policy?.forceExclude ?? []);
|
|
285
|
-
candidates = candidates.filter((tool) => {
|
|
286
|
-
if (!forceExclude.has(tool.toolName))
|
|
287
|
-
return true;
|
|
288
|
-
excluded.push({ toolName: tool.toolName, reason: 'force-excluded' });
|
|
289
|
-
return false;
|
|
290
|
-
});
|
|
291
|
-
// Resolve forceInclude tools — these are guaranteed slots exempt from budget trimming.
|
|
292
|
-
const forcedToolNames = new Set(input.policy?.forceInclude ?? []);
|
|
293
|
-
const forcedTools = [];
|
|
294
|
-
for (const forcedToolName of forcedToolNames) {
|
|
295
|
-
const forced = indexByToolName.get(forcedToolName);
|
|
296
|
-
if (!forced) {
|
|
297
|
-
excluded.push({ toolName: forcedToolName, reason: 'not-in-profile' });
|
|
298
|
-
continue;
|
|
143
|
+
// 3. Reject missing per-operation required keys.
|
|
144
|
+
// For multi-action tools, resolve the operation by action; for single-op
|
|
145
|
+
// tools, use the sole operation entry.
|
|
146
|
+
const action = args.action;
|
|
147
|
+
let op;
|
|
148
|
+
if (typeof action === 'string' && tool.operations.length > 1) {
|
|
149
|
+
op = tool.operations.find((o) => o.intentAction === action);
|
|
150
|
+
}
|
|
151
|
+
else if (tool.operations.length === 1) {
|
|
152
|
+
op = tool.operations[0];
|
|
153
|
+
}
|
|
154
|
+
if (op) {
|
|
155
|
+
validateOperationRequired(toolName, action, args, op);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Check per-operation required constraints.
|
|
160
|
+
*
|
|
161
|
+
* Handles two shapes emitted by the codegen:
|
|
162
|
+
* - `required: string[]` — all listed keys must be present
|
|
163
|
+
* - `requiredOneOf: string[][]` — at least one branch must be fully satisfied
|
|
164
|
+
* (mirrors JSON Schema `oneOf` with per-branch `required` arrays)
|
|
165
|
+
*/
|
|
166
|
+
function validateOperationRequired(toolName, action, args, op) {
|
|
167
|
+
const actionLabel = typeof action === 'string' ? ` action "${action}"` : '';
|
|
168
|
+
if (op.requiredOneOf && op.requiredOneOf.length > 0) {
|
|
169
|
+
const satisfied = op.requiredOneOf.some((branch) => branch.every((k) => args[k] != null));
|
|
170
|
+
if (!satisfied) {
|
|
171
|
+
const options = op.requiredOneOf.map((b) => b.join(' + ')).join(' | ');
|
|
172
|
+
throw new SuperDocCliError(`Missing required argument(s) for ${toolName}${actionLabel}: must provide one of: ${options}`, {
|
|
173
|
+
code: 'INVALID_ARGUMENT',
|
|
174
|
+
details: { toolName, action, requiredOneOf: op.requiredOneOf },
|
|
175
|
+
});
|
|
299
176
|
}
|
|
300
|
-
candidates.push(forced);
|
|
301
|
-
forcedTools.push(forced);
|
|
302
177
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
if (selected.length >= minReadTools || selected.length >= maxTools)
|
|
311
|
-
break;
|
|
312
|
-
selected.push(tool);
|
|
313
|
-
selectedNames.add(tool.toolName);
|
|
314
|
-
}
|
|
315
|
-
const remaining = stableSortByPhasePriority(candidates.filter((tool) => !selectedNames.has(tool.toolName)), phasePolicy.priority);
|
|
316
|
-
for (const tool of remaining) {
|
|
317
|
-
if (selected.length >= maxTools) {
|
|
318
|
-
excluded.push({ toolName: tool.toolName, reason: 'budget-trim' });
|
|
319
|
-
continue;
|
|
178
|
+
else if (op.required && op.required.length > 0) {
|
|
179
|
+
const missingActionKeys = op.required.filter((k) => args[k] == null);
|
|
180
|
+
if (missingActionKeys.length > 0) {
|
|
181
|
+
throw new SuperDocCliError(`Missing required argument(s) for ${toolName}${actionLabel}: ${missingActionKeys.join(', ')}`, {
|
|
182
|
+
code: 'INVALID_ARGUMENT',
|
|
183
|
+
details: { toolName, action, missingKeys: missingActionKeys },
|
|
184
|
+
});
|
|
320
185
|
}
|
|
321
|
-
selected.push(tool);
|
|
322
186
|
}
|
|
323
|
-
const bundle = await loadProviderBundle(input.provider);
|
|
324
|
-
const providerTools = Array.isArray(bundle.profiles[profile]) ? bundle.profiles[profile] : [];
|
|
325
|
-
const providerIndex = new Map(providerTools
|
|
326
|
-
.filter((tool) => isRecord(tool))
|
|
327
|
-
.map((tool) => [extractProviderToolName(tool), tool])
|
|
328
|
-
.filter((entry) => entry[0] !== null));
|
|
329
|
-
const selectedProviderTools = selected
|
|
330
|
-
.map((tool) => providerIndex.get(tool.toolName))
|
|
331
|
-
.filter((tool) => Boolean(tool));
|
|
332
|
-
return {
|
|
333
|
-
tools: selectedProviderTools,
|
|
334
|
-
selected: selected.map((tool) => ({
|
|
335
|
-
operationId: tool.operationId,
|
|
336
|
-
toolName: tool.toolName,
|
|
337
|
-
category: tool.category,
|
|
338
|
-
mutates: tool.mutates,
|
|
339
|
-
profile: tool.profile,
|
|
340
|
-
})),
|
|
341
|
-
excluded,
|
|
342
|
-
selectionMeta: {
|
|
343
|
-
profile,
|
|
344
|
-
phase,
|
|
345
|
-
maxTools,
|
|
346
|
-
minReadTools,
|
|
347
|
-
selectedCount: selected.length,
|
|
348
|
-
decisionVersion: policy.defaults.chooserDecisionVersion,
|
|
349
|
-
provider: input.provider,
|
|
350
|
-
},
|
|
351
|
-
};
|
|
352
187
|
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
188
|
+
/**
|
|
189
|
+
* Dispatch a tool call against a bound document handle.
|
|
190
|
+
*
|
|
191
|
+
* The document handle injects session targeting automatically.
|
|
192
|
+
* Tool arguments should not contain `doc` or `sessionId`.
|
|
193
|
+
*/
|
|
194
|
+
export async function dispatchSuperDocTool(documentHandle, toolName, args = {}, invokeOptions) {
|
|
195
|
+
if (!isRecord(args)) {
|
|
196
|
+
throw new SuperDocCliError(`Tool arguments for ${toolName} must be an object.`, {
|
|
197
|
+
code: 'INVALID_ARGUMENT',
|
|
358
198
|
details: { toolName },
|
|
359
199
|
});
|
|
360
200
|
}
|
|
361
|
-
|
|
362
|
-
|
|
201
|
+
// Validate against the tool schema before dispatch.
|
|
202
|
+
const catalog = await getCachedCatalog();
|
|
203
|
+
const tool = catalog.tools.find((t) => t.toolName === toolName);
|
|
204
|
+
if (tool == null) {
|
|
205
|
+
throw new SuperDocCliError(`Unknown tool: ${toolName}`, {
|
|
206
|
+
code: 'TOOL_DISPATCH_NOT_FOUND',
|
|
207
|
+
details: { toolName },
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
validateToolArgs(toolName, args, tool);
|
|
211
|
+
return dispatchIntentTool(toolName, args, (operationId, input) => {
|
|
212
|
+
const method = resolveDocApiMethod(documentHandle, operationId);
|
|
213
|
+
return method(input, invokeOptions);
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Read the bundled system prompt for intent tools.
|
|
218
|
+
*/
|
|
219
|
+
export async function getSystemPrompt() {
|
|
220
|
+
const promptPath = path.join(toolsDir, 'system-prompt.md');
|
|
221
|
+
try {
|
|
222
|
+
return await readFile(promptPath, 'utf8');
|
|
223
|
+
}
|
|
224
|
+
catch {
|
|
225
|
+
throw new SuperDocCliError('System prompt not found.', {
|
|
226
|
+
code: 'TOOLS_ASSET_NOT_FOUND',
|
|
227
|
+
details: { filePath: promptPath },
|
|
228
|
+
});
|
|
363
229
|
}
|
|
364
|
-
validateDispatchArgs(operationId, args);
|
|
365
|
-
const method = resolveDocApiMethod(client, operationId);
|
|
366
|
-
return method(args, invokeOptions);
|
|
367
230
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superdoc-dev/sdk",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.74",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
+
"bun": "./dist/index.js",
|
|
11
12
|
"types": "./dist/index.d.ts",
|
|
12
13
|
"import": "./dist/index.js",
|
|
13
14
|
"require": "./dist/index.cjs"
|
|
@@ -25,11 +26,11 @@
|
|
|
25
26
|
"typescript": "^5.9.2"
|
|
26
27
|
},
|
|
27
28
|
"optionalDependencies": {
|
|
28
|
-
"@superdoc-dev/sdk-darwin-arm64": "1.0.0-next.
|
|
29
|
-
"@superdoc-dev/sdk-linux-x64": "1.0.0-next.
|
|
30
|
-
"@superdoc-dev/sdk-
|
|
31
|
-
"@superdoc-dev/sdk-
|
|
32
|
-
"@superdoc-dev/sdk-windows-x64": "1.0.0-next.
|
|
29
|
+
"@superdoc-dev/sdk-darwin-arm64": "1.0.0-next.74",
|
|
30
|
+
"@superdoc-dev/sdk-linux-x64": "1.0.0-next.74",
|
|
31
|
+
"@superdoc-dev/sdk-linux-arm64": "1.0.0-next.74",
|
|
32
|
+
"@superdoc-dev/sdk-darwin-x64": "1.0.0-next.74",
|
|
33
|
+
"@superdoc-dev/sdk-windows-x64": "1.0.0-next.74"
|
|
33
34
|
},
|
|
34
35
|
"publishConfig": {
|
|
35
36
|
"access": "public"
|
|
Binary file
|
|
Binary file
|