@superdoc/sdk 2.11.0-next.4 → 2.11.0-next.6

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.
@@ -112,6 +112,7 @@ function dispatchIntentTool(toolName, args, execute) {
112
112
  case 'set_row_options': return execute('doc.tables.setRowOptions', rest);
113
113
  case 'insert_column': return execute('doc.tables.insertColumn', rest);
114
114
  case 'delete_column': return execute('doc.tables.deleteColumn', rest);
115
+ case 'move_column': return execute('doc.tables.moveColumn', rest);
115
116
  case 'set_column': return execute('doc.tables.setColumnWidth', rest);
116
117
  case 'merge_cells': return execute('doc.tables.mergeCells', rest);
117
118
  case 'unmerge_cells': return execute('doc.tables.unmergeCells', rest);
@@ -110,6 +110,7 @@ export function dispatchIntentTool(toolName, args, execute) {
110
110
  case 'set_row_options': return execute('doc.tables.setRowOptions', rest);
111
111
  case 'insert_column': return execute('doc.tables.insertColumn', rest);
112
112
  case 'delete_column': return execute('doc.tables.deleteColumn', rest);
113
+ case 'move_column': return execute('doc.tables.moveColumn', rest);
113
114
  case 'set_column': return execute('doc.tables.setColumnWidth', rest);
114
115
  case 'merge_cells': return execute('doc.tables.mergeCells', rest);
115
116
  case 'unmerge_cells': return execute('doc.tables.unmergeCells', rest);
package/dist/index.cjs CHANGED
@@ -10,6 +10,7 @@ var skills = require('./skills.cjs');
10
10
  var tools = require('./tools.cjs');
11
11
  var intentDispatch_generated = require('./generated/intent-dispatch.generated.cjs');
12
12
  var v2PresetCompat = require('./agent/v2-preset-compat.cjs');
13
+ var define = require('./actions/define.cjs');
13
14
  var presets = require('./presets.cjs');
14
15
 
15
16
  // ---------------------------------------------------------------------------
@@ -215,6 +216,7 @@ exports.getToolCatalog = tools.getToolCatalog;
215
216
  exports.listTools = tools.listTools;
216
217
  exports.dispatchIntentTool = intentDispatch_generated.dispatchIntentTool;
217
218
  exports.wrapV2PresetCompat = v2PresetCompat.wrapV2PresetCompat;
219
+ exports.defineAction = define.defineAction;
218
220
  exports.DEFAULT_PRESET = presets.DEFAULT_PRESET;
219
221
  exports.getPreset = presets.getPreset;
220
222
  exports.listPresets = presets.listPresets;
package/dist/index.d.ts CHANGED
@@ -98,6 +98,8 @@ export type { AgentReceipt, AgentApplyArgs, AgentVerifyArgs } from './agent/runt
98
98
  export type { GetSystemPromptOptions, GetToolsOptions, GetToolsResult, PresetDescriptor } from './presets.js';
99
99
  export { createAgentToolkit } from './tools.js';
100
100
  export type { AgentToolkit, CreateAgentToolkitInput } from './tools.js';
101
+ export { defineAction } from './actions/define.js';
102
+ export type { ActionSpec, ActionStep, DefineActionInput, JSONSchemaObject } from './actions/define.js';
101
103
  export { SuperDocCliError } from './runtime/errors.js';
102
104
  export type { CollaborationAuth, DocOpenOptions, InvokeOptions, OperationSpec, OperationParamSpec, RuntimeInvoker, SuperDocClientOptions, } from './runtime/process.js';
103
105
  export type { DocOpenResult } from './generated/client.js';
package/dist/index.js CHANGED
@@ -197,4 +197,7 @@ export { chooseTools, dispatchSuperDocTool, getMcpPrompt, getSystemPrompt, getSy
197
197
  export { dispatchIntentTool } from './generated/intent-dispatch.generated.js';
198
198
  export { wrapV2PresetCompat } from './agent/v2-preset-compat.js';
199
199
  export { createAgentToolkit } from './tools.js';
200
+ // Custom-action authoring kit: `defineAction` builds an ActionSpec (steps or
201
+ // run tier); hand the specs to `createAgentToolkit({ actions })`.
202
+ export { defineAction } from './actions/define.js';
200
203
  export { SuperDocCliError } from './runtime/errors.js';
package/dist/presets.cjs CHANGED
@@ -40,8 +40,8 @@ const BUILTIN_PRESETS = {
40
40
  };
41
41
  /**
42
42
  * Mutable registry, seeded with the built-ins. Customers add their own presets
43
- * via {@link registerPreset} (e.g. one produced by `extendPreset` /
44
- * `composePreset`) so `getPreset`/`chooseTools` can resolve them by id.
43
+ * via {@link registerPreset} so `getPreset`/`chooseTools` can resolve them
44
+ * by id.
45
45
  */
46
46
  const PRESETS = { ...BUILTIN_PRESETS };
47
47
  /** List the IDs of all registered presets. */
package/dist/presets.js CHANGED
@@ -37,8 +37,8 @@ const BUILTIN_PRESETS = {
37
37
  };
38
38
  /**
39
39
  * Mutable registry, seeded with the built-ins. Customers add their own presets
40
- * via {@link registerPreset} (e.g. one produced by `extendPreset` /
41
- * `composePreset`) so `getPreset`/`chooseTools` can resolve them by id.
40
+ * via {@link registerPreset} so `getPreset`/`chooseTools` can resolve them
41
+ * by id.
42
42
  */
43
43
  const PRESETS = { ...BUILTIN_PRESETS };
44
44
  /** List the IDs of all registered presets. */
@@ -3,6 +3,6 @@
3
3
  // AUTO-GENERATED by scripts/embed-version.mjs — DO NOT EDIT.
4
4
  // Source of truth: package.json. Regenerated on every SDK build so the
5
5
  // SDK retains its own version identity when bundled into another package.
6
- const SDK_VERSION = '2.11.0-next.4';
6
+ const SDK_VERSION = '2.11.0-next.6';
7
7
 
8
8
  exports.SDK_VERSION = SDK_VERSION;
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "2.11.0-next.4";
1
+ export declare const SDK_VERSION = "2.11.0-next.6";
@@ -1,4 +1,4 @@
1
1
  // AUTO-GENERATED by scripts/embed-version.mjs — DO NOT EDIT.
2
2
  // Source of truth: package.json. Regenerated on every SDK build so the
3
3
  // SDK retains its own version identity when bundled into another package.
4
- export const SDK_VERSION = '2.11.0-next.4';
4
+ export const SDK_VERSION = '2.11.0-next.6';
package/dist/tools.cjs CHANGED
@@ -1,6 +1,8 @@
1
1
  'use strict';
2
2
 
3
+ var errors = require('./runtime/errors.cjs');
3
4
  var presets = require('./presets.cjs');
5
+ var define = require('./actions/define.cjs');
4
6
 
5
7
  /**
6
8
  * Public LLM-tools API. Thin layer over the preset registry — every call here
@@ -95,6 +97,9 @@ function resolvePromptPresetArg(preset) {
95
97
  }
96
98
  return presets.DEFAULT_PRESET;
97
99
  }
100
+ /** Label for the ephemeral preset built by the one-call `customActions` path. */
101
+ const CUSTOM_TOOLKIT_PRESET_ID = 'custom_superdoc_preset';
102
+ const TOOL_PROVIDERS = new Set(['openai', 'anthropic', 'vercel', 'generic']);
98
103
  /**
99
104
  * One-call agent surface: tools, system prompt, and a pre-bound dispatcher
100
105
  * that are coherent BY CONSTRUCTION — the same preset and `excludeActions`
@@ -106,8 +111,51 @@ function resolvePromptPresetArg(preset) {
106
111
  * matching the standalone functions.
107
112
  */
108
113
  async function createAgentToolkit(input) {
109
- const presetId = input.preset ?? presets.DEFAULT_PRESET;
110
114
  const excludeActions = input.excludeActions ? [...input.excludeActions] : undefined;
115
+ // One-call custom-actions path: define your actions, hand them here as
116
+ // `customActions`, use the
117
+ // returned toolkit. We build an ephemeral extended/composed preset over
118
+ // `base` (default 'core') and drive it directly — no global registerPreset,
119
+ // and nothing for the caller to remember at dispatch time.
120
+ //
121
+ // An explicit `base` selects this path even with an empty actions list —
122
+ // otherwise `{ base: 'core', customActions: [] }` would silently fall through to
123
+ // the default (legacy) preset, a different tool family than the one named.
124
+ if ((input.customActions && input.customActions.length > 0) || input.includeActions != null || input.base != null) {
125
+ // This path builds tools directly (no chooseTools), so it must validate
126
+ // the provider itself; an unknown value would otherwise yield a silently
127
+ // mixed-dialect tool list. Mirrors the Python `create_agent_toolkit` guard.
128
+ if (!TOOL_PROVIDERS.has(input.provider)) {
129
+ throw new errors.SuperDocCliError('provider is required.', {
130
+ code: 'INVALID_ARGUMENT',
131
+ details: { provider: input.provider },
132
+ });
133
+ }
134
+ // `preset` doubles as the base to extend here (so `{ preset: 'core', actions }`
135
+ // reads naturally); `base` wins if both are given. Default base is 'core'.
136
+ const baseId = input.base ?? input.preset ?? 'core';
137
+ const descriptor = define.extendPreset(baseId, {
138
+ id: CUSTOM_TOOLKIT_PRESET_ID,
139
+ actions: input.customActions ?? [],
140
+ ...(input.includeActions != null ? { includeActions: input.includeActions } : {}),
141
+ });
142
+ const { tools, cacheStrategy } = await descriptor.getTools(input.provider, {
143
+ cache: input.cache === true,
144
+ excludeActions,
145
+ });
146
+ const systemPrompt = await descriptor.getSystemPrompt(excludeActions ? { excludeActions } : undefined);
147
+ const dispatch = (documentHandle, toolName, args = {}, invokeOptions) => descriptor.dispatch(documentHandle, toolName, args, {
148
+ ...invokeOptions,
149
+ ...(excludeActions ? { excludeActions } : {}),
150
+ });
151
+ return {
152
+ tools,
153
+ meta: { provider: input.provider, preset: descriptor.id, toolCount: tools.length, cacheStrategy },
154
+ systemPrompt,
155
+ dispatch,
156
+ };
157
+ }
158
+ const presetId = input.preset ?? presets.DEFAULT_PRESET;
111
159
  const { tools, meta } = await chooseTools({ ...input, preset: presetId, excludeActions });
112
160
  const systemPrompt = await getSystemPrompt(presetId, excludeActions ? { excludeActions } : undefined);
113
161
  const dispatch = (documentHandle, toolName, args = {}, invokeOptions) => dispatchSuperDocTool(documentHandle, toolName, args, {
package/dist/tools.d.ts CHANGED
@@ -10,6 +10,7 @@
10
10
  import type { BoundDocApi } from './generated/client.js';
11
11
  import type { InvokeOptions } from './runtime/process.js';
12
12
  import { DEFAULT_PRESET, getPreset, listPresets, registerPreset, unregisterPreset, type CacheStrategy, type GetSystemPromptOptions, type ToolCatalog, type ToolCatalogEntry, type ToolCatalogOperation, type ToolProvider } from './presets.js';
13
+ import { type ActionSpec } from './actions/define.js';
13
14
  export { DEFAULT_PRESET, getPreset, listPresets, registerPreset, unregisterPreset };
14
15
  export type { CacheStrategy, GetSystemPromptOptions, ToolCatalog, ToolCatalogEntry, ToolCatalogOperation, ToolProvider, };
15
16
  export type ToolChooserInput = {
@@ -98,7 +99,23 @@ export declare function dispatchSuperDocTool(documentHandle: BoundDocApi, toolNa
98
99
  * suitable for embedded LLM usage (OpenAI, Anthropic, Vercel APIs). For MCP
99
100
  * server instructions, use {@link getMcpPrompt} instead.
100
101
  */
101
- export type CreateAgentToolkitInput = ToolChooserInput;
102
+ export type CreateAgentToolkitInput = ToolChooserInput & {
103
+ /**
104
+ * Custom actions to expose alongside the base preset's built-ins. When set,
105
+ * the toolkit builds the extended preset FOR YOU — no `registerPreset`, no
106
+ * preset id to invent or thread through later `dispatch` calls. This is the
107
+ * path: define your actions, hand them here, use the returned toolkit.
108
+ */
109
+ customActions?: readonly ActionSpec[];
110
+ /** Base preset to extend on the custom-actions path (default `'core'`). */
111
+ base?: string;
112
+ /**
113
+ * Of the base preset's built-in actions, keep only these (`customActions`
114
+ * are always included; `[]` yields a custom-only surface). See
115
+ * `ExtendPresetOptions.includeActions`.
116
+ */
117
+ includeActions?: readonly string[];
118
+ };
102
119
  export type AgentToolkit = {
103
120
  /** Provider-shaped tool definitions (see {@link chooseTools}). */
104
121
  tools: unknown[];
package/dist/tools.js CHANGED
@@ -7,7 +7,9 @@
7
7
  * "core" tools, prompt-caching variant, lazy-load experiment), register a new
8
8
  * descriptor in `presets.ts` — no changes here required.
9
9
  */
10
+ import { SuperDocCliError } from './runtime/errors.js';
10
11
  import { DEFAULT_PRESET, getPreset, listPresets, registerPreset, unregisterPreset, } from './presets.js';
12
+ import { extendPreset } from './actions/define.js';
11
13
  export { DEFAULT_PRESET, getPreset, listPresets, registerPreset, unregisterPreset };
12
14
  /**
13
15
  * Select tools for a specific provider from a preset.
@@ -93,6 +95,9 @@ function resolvePromptPresetArg(preset) {
93
95
  }
94
96
  return DEFAULT_PRESET;
95
97
  }
98
+ /** Label for the ephemeral preset built by the one-call `customActions` path. */
99
+ const CUSTOM_TOOLKIT_PRESET_ID = 'custom_superdoc_preset';
100
+ const TOOL_PROVIDERS = new Set(['openai', 'anthropic', 'vercel', 'generic']);
96
101
  /**
97
102
  * One-call agent surface: tools, system prompt, and a pre-bound dispatcher
98
103
  * that are coherent BY CONSTRUCTION — the same preset and `excludeActions`
@@ -104,8 +109,51 @@ function resolvePromptPresetArg(preset) {
104
109
  * matching the standalone functions.
105
110
  */
106
111
  export async function createAgentToolkit(input) {
107
- const presetId = input.preset ?? DEFAULT_PRESET;
108
112
  const excludeActions = input.excludeActions ? [...input.excludeActions] : undefined;
113
+ // One-call custom-actions path: define your actions, hand them here as
114
+ // `customActions`, use the
115
+ // returned toolkit. We build an ephemeral extended/composed preset over
116
+ // `base` (default 'core') and drive it directly — no global registerPreset,
117
+ // and nothing for the caller to remember at dispatch time.
118
+ //
119
+ // An explicit `base` selects this path even with an empty actions list —
120
+ // otherwise `{ base: 'core', customActions: [] }` would silently fall through to
121
+ // the default (legacy) preset, a different tool family than the one named.
122
+ if ((input.customActions && input.customActions.length > 0) || input.includeActions != null || input.base != null) {
123
+ // This path builds tools directly (no chooseTools), so it must validate
124
+ // the provider itself; an unknown value would otherwise yield a silently
125
+ // mixed-dialect tool list. Mirrors the Python `create_agent_toolkit` guard.
126
+ if (!TOOL_PROVIDERS.has(input.provider)) {
127
+ throw new SuperDocCliError('provider is required.', {
128
+ code: 'INVALID_ARGUMENT',
129
+ details: { provider: input.provider },
130
+ });
131
+ }
132
+ // `preset` doubles as the base to extend here (so `{ preset: 'core', actions }`
133
+ // reads naturally); `base` wins if both are given. Default base is 'core'.
134
+ const baseId = input.base ?? input.preset ?? 'core';
135
+ const descriptor = extendPreset(baseId, {
136
+ id: CUSTOM_TOOLKIT_PRESET_ID,
137
+ actions: input.customActions ?? [],
138
+ ...(input.includeActions != null ? { includeActions: input.includeActions } : {}),
139
+ });
140
+ const { tools, cacheStrategy } = await descriptor.getTools(input.provider, {
141
+ cache: input.cache === true,
142
+ excludeActions,
143
+ });
144
+ const systemPrompt = await descriptor.getSystemPrompt(excludeActions ? { excludeActions } : undefined);
145
+ const dispatch = (documentHandle, toolName, args = {}, invokeOptions) => descriptor.dispatch(documentHandle, toolName, args, {
146
+ ...invokeOptions,
147
+ ...(excludeActions ? { excludeActions } : {}),
148
+ });
149
+ return {
150
+ tools,
151
+ meta: { provider: input.provider, preset: descriptor.id, toolCount: tools.length, cacheStrategy },
152
+ systemPrompt,
153
+ dispatch,
154
+ };
155
+ }
156
+ const presetId = input.preset ?? DEFAULT_PRESET;
109
157
  const { tools, meta } = await chooseTools({ ...input, preset: presetId, excludeActions });
110
158
  const systemPrompt = await getSystemPrompt(presetId, excludeActions ? { excludeActions } : undefined);
111
159
  const dispatch = (documentHandle, toolName, args = {}, invokeOptions) => dispatchSuperDocTool(documentHandle, toolName, args, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superdoc/sdk",
3
- "version": "2.11.0-next.4",
3
+ "version": "2.11.0-next.6",
4
4
  "description": "Node SDK for SuperDoc, wrapping the SuperDoc CLI to read and edit .docx files from JavaScript and TypeScript.",
5
5
  "private": false,
6
6
  "license": "AGPL-3.0",
@@ -38,11 +38,11 @@
38
38
  "typescript": "^5.9.2"
39
39
  },
40
40
  "optionalDependencies": {
41
- "@superdoc/sdk-darwin-arm64": "2.11.0-next.4",
42
- "@superdoc/sdk-darwin-x64": "2.11.0-next.4",
43
- "@superdoc/sdk-linux-x64": "2.11.0-next.4",
44
- "@superdoc/sdk-linux-arm64": "2.11.0-next.4",
45
- "@superdoc/sdk-windows-x64": "2.11.0-next.4"
41
+ "@superdoc/sdk-darwin-arm64": "2.11.0-next.6",
42
+ "@superdoc/sdk-darwin-x64": "2.11.0-next.6",
43
+ "@superdoc/sdk-linux-x64": "2.11.0-next.6",
44
+ "@superdoc/sdk-linux-arm64": "2.11.0-next.6",
45
+ "@superdoc/sdk-windows-x64": "2.11.0-next.6"
46
46
  },
47
47
  "publishConfig": {
48
48
  "access": "public"
@@ -51,9 +51,9 @@
51
51
  "build": "rm -rf dist && node scripts/embed-version.mjs && node scripts/embed-prompts.mjs && node scripts/embed-tools.mjs && tsc && pnpm run typecheck:consumer && rollup -c rollup.cjs.config.mjs && rm -rf dist/prompts && mkdir -p dist/prompts && cp src/prompts/*.md dist/prompts/ && pnpm run audit:publish",
52
52
  "audit:publish": "node ../../../../scripts/audit-publish-artifact.mjs dist --label sdk-node-dist",
53
53
  "typecheck": "tsc --noEmit",
54
- "typecheck:consumer": "tsc --noEmit --strict --skipLibCheck --target ES2022 --module NodeNext --moduleResolution NodeNext ../../../../tests/consumer-typecheck/src/sdk-per-open-collaboration-auth.mts ../../../../tests/consumer-typecheck/src/sdk-replace-file.mts ../../../../tests/consumer-typecheck/src/sdk-agent-evidence.mts",
55
- "test:agent-actions": "bun test src/__tests__/actions.test.ts src/__tests__/agent-runtime.test.ts",
56
- "test:document-host": "bun test src/runtime/__tests__/host-spawn-args.test.ts src/runtime/__tests__/document-rpc.test.ts src/__tests__/structured-document-rpc.e2e.test.ts src/__tests__/request-timeout-ms.e2e.test.ts src/__tests__/agent-evidence.e2e.test.ts src/__tests__/agent-apply.e2e.test.ts src/__tests__/find-text.e2e.test.ts",
54
+ "typecheck:consumer": "tsc --noEmit --strict --skipLibCheck --target ES2022 --module NodeNext --moduleResolution NodeNext ../../../../tests/consumer-typecheck/src/sdk-per-open-collaboration-auth.mts ../../../../tests/consumer-typecheck/src/sdk-replace-file.mts ../../../../tests/consumer-typecheck/src/sdk-agent-evidence.mts ../../../../tests/consumer-typecheck/src/sdk-custom-actions.mts",
55
+ "test:agent-actions": "bun test src/__tests__/actions.test.ts src/__tests__/agent-runtime.test.ts src/__tests__/custom-actions.test.ts",
56
+ "test:document-host": "bun test src/runtime/__tests__/host-spawn-args.test.ts src/runtime/__tests__/document-rpc.test.ts src/__tests__/structured-document-rpc.e2e.test.ts src/__tests__/request-timeout-ms.e2e.test.ts src/__tests__/agent-evidence.e2e.test.ts src/__tests__/agent-apply.e2e.test.ts src/__tests__/find-text.e2e.test.ts src/__tests__/custom-actions.e2e.test.ts",
57
57
  "smoke:product-action": "node scripts/product-action-smoke.mjs"
58
58
  }
59
59
  }