@superdoc-dev/sdk 1.0.0-alpha.3 → 1.0.0-alpha.4

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.
Files changed (53) hide show
  1. package/dist/generated/client.d.ts +1790 -0
  2. package/dist/generated/client.d.ts.map +1 -0
  3. package/dist/generated/client.js +66 -0
  4. package/dist/generated/contract.d.ts +13676 -0
  5. package/dist/generated/contract.d.ts.map +1 -0
  6. package/dist/generated/contract.js +17809 -0
  7. package/dist/index.d.ts +23 -0
  8. package/dist/index.d.ts.map +1 -0
  9. package/dist/index.js +29 -0
  10. package/dist/runtime/embedded-cli.d.ts +5 -0
  11. package/dist/runtime/embedded-cli.d.ts.map +1 -0
  12. package/dist/runtime/embedded-cli.js +94 -0
  13. package/dist/runtime/errors.d.ts +17 -0
  14. package/dist/runtime/errors.d.ts.map +1 -0
  15. package/dist/runtime/errors.js +18 -0
  16. package/dist/runtime/host.d.ts +36 -0
  17. package/dist/runtime/host.d.ts.map +1 -0
  18. package/dist/runtime/host.js +345 -0
  19. package/dist/runtime/process.d.ts +16 -0
  20. package/dist/runtime/process.d.ts.map +1 -0
  21. package/dist/runtime/process.js +27 -0
  22. package/dist/runtime/transport-common.d.ts +44 -0
  23. package/dist/runtime/transport-common.d.ts.map +1 -0
  24. package/dist/runtime/transport-common.js +65 -0
  25. package/dist/skills.d.ts +25 -0
  26. package/dist/skills.d.ts.map +1 -0
  27. package/dist/skills.js +140 -0
  28. package/dist/tools.d.ts +113 -0
  29. package/dist/tools.d.ts.map +1 -0
  30. package/dist/tools.js +360 -0
  31. package/package.json +19 -10
  32. package/tools/catalog.json +17128 -0
  33. package/tools/tool-name-map.json +96 -0
  34. package/tools/tools-policy.json +100 -0
  35. package/tools/tools.anthropic.json +3275 -0
  36. package/tools/tools.generic.json +16573 -0
  37. package/tools/tools.openai.json +3557 -0
  38. package/tools/tools.vercel.json +3557 -0
  39. package/skills/editing-docx.md +0 -157
  40. package/src/__tests__/skills.test.ts +0 -166
  41. package/src/__tests__/tools.test.ts +0 -96
  42. package/src/generated/client.ts +0 -3643
  43. package/src/generated/contract.ts +0 -15952
  44. package/src/index.ts +0 -87
  45. package/src/runtime/__tests__/process.test.ts +0 -38
  46. package/src/runtime/__tests__/transport-common.test.ts +0 -174
  47. package/src/runtime/embedded-cli.ts +0 -109
  48. package/src/runtime/errors.ts +0 -30
  49. package/src/runtime/host.ts +0 -481
  50. package/src/runtime/process.ts +0 -45
  51. package/src/runtime/transport-common.ts +0 -169
  52. package/src/skills.ts +0 -195
  53. package/src/tools.ts +0 -701
package/src/index.ts DELETED
@@ -1,87 +0,0 @@
1
- import { createDocApi } from './generated/client';
2
- import { SuperDocRuntime, type SuperDocClientOptions } from './runtime/process';
3
-
4
- /**
5
- * High-level client for interacting with SuperDoc documents via the CLI.
6
- *
7
- * Provides a typed `doc` API for opening, querying, and mutating documents.
8
- * Call {@link connect} before operations and {@link dispose} when finished
9
- * to manage the host process lifecycle.
10
- *
11
- * @example
12
- * ```typescript
13
- * const client = new SuperDocClient();
14
- * await client.connect();
15
- * const result = await client.doc.find({ doc: 'report.docx', type: 'text', pattern: 'hello' });
16
- * await client.dispose();
17
- * ```
18
- */
19
- export class SuperDocClient {
20
- private readonly runtime: SuperDocRuntime;
21
- readonly doc: ReturnType<typeof createDocApi>;
22
-
23
- /**
24
- * @param options - Client configuration including environment overrides.
25
- */
26
- constructor(options: SuperDocClientOptions = {}) {
27
- this.runtime = new SuperDocRuntime(options);
28
- this.doc = createDocApi(this.runtime);
29
- }
30
-
31
- /**
32
- * Establish the connection to the CLI host process.
33
- * Can be called eagerly; otherwise the host starts lazily on the first command.
34
- */
35
- async connect(): Promise<void> {
36
- await this.runtime.connect();
37
- }
38
-
39
- /**
40
- * Shut down the CLI host process and release resources.
41
- */
42
- async dispose(): Promise<void> {
43
- await this.runtime.dispose();
44
- }
45
- }
46
-
47
- /**
48
- * Create a new {@link SuperDocClient} instance.
49
- *
50
- * @param options - Client configuration.
51
- * @returns A configured client ready for document operations.
52
- *
53
- * @example
54
- * ```typescript
55
- * const client = createSuperDocClient();
56
- * await client.connect();
57
- * const info = await client.doc.info({ doc: 'report.docx' });
58
- * await client.dispose();
59
- * ```
60
- */
61
- export function createSuperDocClient(options: SuperDocClientOptions = {}): SuperDocClient {
62
- return new SuperDocClient(options);
63
- }
64
-
65
- export { getSkill, installSkill, listSkills } from './skills';
66
- export {
67
- chooseTools,
68
- dispatchSuperDocTool,
69
- getToolCatalog,
70
- inferDocumentFeatures,
71
- listTools,
72
- resolveToolOperation,
73
- } from './tools';
74
- export { SuperDocCliError } from './runtime/errors';
75
- export type {
76
- InvokeOptions,
77
- OperationSpec,
78
- OperationParamSpec,
79
- SuperDocClientOptions,
80
- } from './runtime/process';
81
- export type {
82
- DocumentFeatures,
83
- ToolChooserInput,
84
- ToolPhase,
85
- ToolProfile,
86
- ToolProvider,
87
- } from './tools';
@@ -1,38 +0,0 @@
1
- import { afterEach, describe, expect, test } from 'bun:test';
2
- import { SuperDocRuntime } from '../process';
3
-
4
- const ORIGINAL_SUPERDOC_CLI_BIN = process.env.SUPERDOC_CLI_BIN;
5
-
6
- function runtimeCliBin(runtime: SuperDocRuntime): string {
7
- return (runtime as unknown as { transport: { cliBin: string } }).transport.cliBin;
8
- }
9
-
10
- afterEach(() => {
11
- if (ORIGINAL_SUPERDOC_CLI_BIN == null) {
12
- delete process.env.SUPERDOC_CLI_BIN;
13
- return;
14
- }
15
- process.env.SUPERDOC_CLI_BIN = ORIGINAL_SUPERDOC_CLI_BIN;
16
- });
17
-
18
- describe('SuperDocRuntime', () => {
19
- test('prefers SUPERDOC_CLI_BIN from client options env over process env', () => {
20
- process.env.SUPERDOC_CLI_BIN = '/process/env/superdoc';
21
-
22
- const runtime = new SuperDocRuntime({
23
- env: {
24
- SUPERDOC_CLI_BIN: '/options/env/superdoc',
25
- },
26
- });
27
-
28
- expect(runtimeCliBin(runtime)).toBe('/options/env/superdoc');
29
- });
30
-
31
- test('uses process env SUPERDOC_CLI_BIN when client options env does not provide one', () => {
32
- process.env.SUPERDOC_CLI_BIN = '/process/env/superdoc';
33
-
34
- const runtime = new SuperDocRuntime();
35
-
36
- expect(runtimeCliBin(runtime)).toBe('/process/env/superdoc');
37
- });
38
- });
@@ -1,174 +0,0 @@
1
- import { describe, expect, test } from 'bun:test';
2
- import { buildOperationArgv, resolveInvocation, type OperationSpec } from '../transport-common';
3
-
4
- describe('resolveInvocation', () => {
5
- test('resolves .js files via node', () => {
6
- const result = resolveInvocation('/path/to/cli.js');
7
- expect(result).toEqual({ command: 'node', prefixArgs: ['/path/to/cli.js'] });
8
- });
9
-
10
- test('resolves .ts files via bun', () => {
11
- const result = resolveInvocation('/path/to/cli.ts');
12
- expect(result).toEqual({ command: 'bun', prefixArgs: ['/path/to/cli.ts'] });
13
- });
14
-
15
- test('resolves plain binaries directly', () => {
16
- const result = resolveInvocation('/usr/bin/superdoc');
17
- expect(result).toEqual({ command: '/usr/bin/superdoc', prefixArgs: [] });
18
- });
19
-
20
- test('extension check is case-insensitive', () => {
21
- expect(resolveInvocation('/path/CLI.JS').command).toBe('node');
22
- expect(resolveInvocation('/path/CLI.TS').command).toBe('bun');
23
- });
24
- });
25
-
26
- describe('buildOperationArgv', () => {
27
- const baseOperation: OperationSpec = {
28
- id: 'test.op',
29
- command: ['test', 'run'],
30
- params: [],
31
- };
32
-
33
- test('starts with command segments', () => {
34
- const args = buildOperationArgv(baseOperation, {}, {}, undefined, false, undefined);
35
- expect(args).toEqual(['test', 'run']);
36
- });
37
-
38
- test('appends --output json when includeOutputFlag is true', () => {
39
- const args = buildOperationArgv(baseOperation, {}, {}, undefined, true, undefined);
40
- expect(args).toEqual(['test', 'run', '--output', 'json']);
41
- });
42
-
43
- test('encodes string flag parameters', () => {
44
- const op: OperationSpec = {
45
- ...baseOperation,
46
- params: [{ name: 'session', kind: 'flag', flag: 'session', type: 'string' }],
47
- };
48
- const args = buildOperationArgv(op, { session: 'my-session' }, {}, undefined, false, undefined);
49
- expect(args).toEqual(['test', 'run', '--session', 'my-session']);
50
- });
51
-
52
- test('encodes boolean flag parameters as presence-only', () => {
53
- const op: OperationSpec = {
54
- ...baseOperation,
55
- params: [{ name: 'force', kind: 'flag', flag: 'force', type: 'boolean' }],
56
- };
57
- const trueArgs = buildOperationArgv(op, { force: true }, {}, undefined, false, undefined);
58
- expect(trueArgs).toEqual(['test', 'run', '--force']);
59
-
60
- const falseArgs = buildOperationArgv(op, { force: false }, {}, undefined, false, undefined);
61
- expect(falseArgs).toEqual(['test', 'run']);
62
- });
63
-
64
- test('encodes number flag parameters', () => {
65
- const op: OperationSpec = {
66
- ...baseOperation,
67
- params: [{ name: 'limit', kind: 'flag', flag: 'limit', type: 'number' }],
68
- };
69
- const args = buildOperationArgv(op, { limit: 10 }, {}, undefined, false, undefined);
70
- expect(args).toEqual(['test', 'run', '--limit', '10']);
71
- });
72
-
73
- test('encodes json flag parameters as JSON strings', () => {
74
- const op: OperationSpec = {
75
- ...baseOperation,
76
- params: [{ name: 'query', kind: 'jsonFlag', flag: 'query-json', type: 'json' }],
77
- };
78
- const args = buildOperationArgv(op, { query: { type: 'text' } }, {}, undefined, false, undefined);
79
- expect(args).toEqual(['test', 'run', '--query-json', '{"type":"text"}']);
80
- });
81
-
82
- test('encodes doc positional parameters', () => {
83
- const op: OperationSpec = {
84
- ...baseOperation,
85
- params: [{ name: 'doc', kind: 'doc', type: 'string' }],
86
- };
87
- const args = buildOperationArgv(op, { doc: '/path/to/file.docx' }, {}, undefined, false, undefined);
88
- expect(args).toEqual(['test', 'run', '/path/to/file.docx']);
89
- });
90
-
91
- test('encodes string[] flag parameters as repeated flags', () => {
92
- const op: OperationSpec = {
93
- ...baseOperation,
94
- params: [{ name: 'include', kind: 'flag', flag: 'include', type: 'string[]' }],
95
- };
96
- const args = buildOperationArgv(op, { include: ['a', 'b'] }, {}, undefined, false, undefined);
97
- expect(args).toEqual(['test', 'run', '--include', 'a', '--include', 'b']);
98
- });
99
-
100
- test('skips null/undefined optional parameters', () => {
101
- const op: OperationSpec = {
102
- ...baseOperation,
103
- params: [{ name: 'session', kind: 'flag', flag: 'session', type: 'string' }],
104
- };
105
- const args = buildOperationArgv(op, {}, {}, undefined, false, undefined);
106
- expect(args).toEqual(['test', 'run']);
107
- });
108
-
109
- test('throws on missing required parameters', () => {
110
- const op: OperationSpec = {
111
- ...baseOperation,
112
- params: [{ name: 'doc', kind: 'doc', type: 'string', required: true }],
113
- };
114
- expect(() => buildOperationArgv(op, {}, {}, undefined, false, undefined)).toThrow('Missing required parameter: doc');
115
- });
116
-
117
- test('throws on non-array value for string[] parameter', () => {
118
- const op: OperationSpec = {
119
- ...baseOperation,
120
- params: [{ name: 'include', kind: 'flag', flag: 'include', type: 'string[]' }],
121
- };
122
- expect(() => buildOperationArgv(op, { include: 'not-an-array' }, {}, undefined, false, undefined)).toThrow(
123
- 'must be an array',
124
- );
125
- });
126
-
127
- test('appends timeout from invoke options', () => {
128
- const args = buildOperationArgv(baseOperation, {}, { timeoutMs: 5000 }, undefined, false, undefined);
129
- expect(args).toEqual(['test', 'run', '--timeout-ms', '5000']);
130
- });
131
-
132
- test('invoke timeout takes precedence over runtime timeout', () => {
133
- const args = buildOperationArgv(baseOperation, {}, { timeoutMs: 3000 }, 10000, false, undefined);
134
- expect(args).toContain('3000');
135
- expect(args).not.toContain('10000');
136
- });
137
-
138
- test('falls back to runtime timeout when invoke timeout is absent', () => {
139
- const args = buildOperationArgv(baseOperation, {}, {}, 7000, false, undefined);
140
- expect(args).toEqual(['test', 'run', '--timeout-ms', '7000']);
141
- });
142
-
143
- test('uses flag name as fallback when flag property is undefined', () => {
144
- const op: OperationSpec = {
145
- ...baseOperation,
146
- params: [{ name: 'mode', kind: 'flag', type: 'string' }],
147
- };
148
- const args = buildOperationArgv(op, { mode: 'fast' }, {}, undefined, false, undefined);
149
- expect(args).toEqual(['test', 'run', '--mode', 'fast']);
150
- });
151
-
152
- test('injects default change mode when operation supports changeMode and params omit it', () => {
153
- const op: OperationSpec = {
154
- ...baseOperation,
155
- params: [{ name: 'changeMode', kind: 'flag', flag: 'change-mode', type: 'string' }],
156
- };
157
- const args = buildOperationArgv(op, {}, {}, undefined, false, 'tracked');
158
- expect(args).toEqual(['test', 'run', '--change-mode', 'tracked']);
159
- });
160
-
161
- test('does not inject default change mode when operation does not support changeMode', () => {
162
- const args = buildOperationArgv(baseOperation, {}, {}, undefined, false, 'tracked');
163
- expect(args).toEqual(['test', 'run']);
164
- });
165
-
166
- test('explicit changeMode parameter overrides default change mode', () => {
167
- const op: OperationSpec = {
168
- ...baseOperation,
169
- params: [{ name: 'changeMode', kind: 'flag', flag: 'change-mode', type: 'string' }],
170
- };
171
- const args = buildOperationArgv(op, { changeMode: 'direct' }, {}, undefined, false, 'tracked');
172
- expect(args).toEqual(['test', 'run', '--change-mode', 'direct']);
173
- });
174
- });
@@ -1,109 +0,0 @@
1
- import { chmodSync, existsSync } from 'node:fs';
2
- import { createRequire } from 'node:module';
3
- import path from 'node:path';
4
- import { fileURLToPath } from 'node:url';
5
- import { SuperDocCliError } from './errors';
6
-
7
- const require = createRequire(import.meta.url);
8
-
9
- type SupportedTarget = 'darwin-arm64' | 'darwin-x64' | 'linux-x64' | 'linux-arm64' | 'windows-x64';
10
-
11
- const TARGET_TO_PACKAGE: Record<SupportedTarget, string> = {
12
- 'darwin-arm64': '@superdoc-dev/sdk-darwin-arm64',
13
- 'darwin-x64': '@superdoc-dev/sdk-darwin-x64',
14
- 'linux-x64': '@superdoc-dev/sdk-linux-x64',
15
- 'linux-arm64': '@superdoc-dev/sdk-linux-arm64',
16
- 'windows-x64': '@superdoc-dev/sdk-windows-x64',
17
- };
18
-
19
- const TARGET_TO_DIR: Record<SupportedTarget, string> = {
20
- 'darwin-arm64': 'sdk-darwin-arm64',
21
- 'darwin-x64': 'sdk-darwin-x64',
22
- 'linux-x64': 'sdk-linux-x64',
23
- 'linux-arm64': 'sdk-linux-arm64',
24
- 'windows-x64': 'sdk-windows-x64',
25
- };
26
-
27
- function resolveTarget(): SupportedTarget | null {
28
- const platform = process.platform;
29
- const arch = process.arch;
30
-
31
- if (platform === 'darwin' && arch === 'arm64') return 'darwin-arm64';
32
- if (platform === 'darwin' && arch === 'x64') return 'darwin-x64';
33
- if (platform === 'linux' && arch === 'x64') return 'linux-x64';
34
- if (platform === 'linux' && arch === 'arm64') return 'linux-arm64';
35
- if (platform === 'win32' && arch === 'x64') return 'windows-x64';
36
-
37
- return null;
38
- }
39
-
40
- function binaryNameForTarget(target: SupportedTarget): string {
41
- return target === 'windows-x64' ? 'superdoc.exe' : 'superdoc';
42
- }
43
-
44
- function ensureExecutable(binaryPath: string): void {
45
- if (process.platform === 'win32') return;
46
- try {
47
- chmodSync(binaryPath, 0o755);
48
- } catch {
49
- // Non-fatal: if chmod fails, spawn() will surface the real execution error.
50
- }
51
- }
52
-
53
- function resolveFromPlatformPackage(target: SupportedTarget): string | null {
54
- const pkg = TARGET_TO_PACKAGE[target];
55
- const binaryName = binaryNameForTarget(target);
56
-
57
- try {
58
- return require.resolve(`${pkg}/bin/${binaryName}`);
59
- } catch {
60
- return null;
61
- }
62
- }
63
-
64
- function resolveFromWorkspaceFallback(target: SupportedTarget): string | null {
65
- const binaryName = binaryNameForTarget(target);
66
- const dirName = TARGET_TO_DIR[target];
67
- const filePath = path.resolve(fileURLToPath(new URL('../../platforms', import.meta.url)), dirName, 'bin', binaryName);
68
- if (!existsSync(filePath)) return null;
69
- return filePath;
70
- }
71
-
72
- /**
73
- * Resolve the path to the embedded SuperDoc CLI binary for the current platform.
74
- *
75
- * Checks platform-specific npm packages first, then falls back to a workspace
76
- * `platforms/` directory. Ensures the binary is executable before returning.
77
- *
78
- * @returns Absolute path to the CLI binary.
79
- * @throws {SuperDocCliError} With code `UNSUPPORTED_PLATFORM` if the current OS/arch is not supported.
80
- * @throws {SuperDocCliError} With code `CLI_BINARY_MISSING` if no binary is found.
81
- */
82
- export function resolveEmbeddedCliBinary(): string {
83
- const target = resolveTarget();
84
- if (!target) {
85
- throw new SuperDocCliError('No embedded SuperDoc CLI binary is available for this platform.', {
86
- code: 'UNSUPPORTED_PLATFORM',
87
- details: {
88
- platform: process.platform,
89
- arch: process.arch,
90
- },
91
- });
92
- }
93
-
94
- const platformPackagePath = resolveFromPlatformPackage(target);
95
- const resolvedPath = platformPackagePath ?? resolveFromWorkspaceFallback(target);
96
-
97
- if (!resolvedPath) {
98
- throw new SuperDocCliError('Embedded SuperDoc CLI binary is missing for this platform.', {
99
- code: 'CLI_BINARY_MISSING',
100
- details: {
101
- target,
102
- packageName: TARGET_TO_PACKAGE[target],
103
- },
104
- });
105
- }
106
-
107
- ensureExecutable(resolvedPath);
108
- return resolvedPath;
109
- }
@@ -1,30 +0,0 @@
1
- /**
2
- * Error thrown by the SuperDoc SDK when a CLI operation fails.
3
- *
4
- * Includes a machine-readable `code` for programmatic error handling
5
- * and optional `details` with structured diagnostic context.
6
- *
7
- * @example
8
- * ```typescript
9
- * try {
10
- * await client.doc.open({ doc: 'missing.docx' });
11
- * } catch (error) {
12
- * if (error instanceof SuperDocCliError) {
13
- * console.error(error.code, error.message);
14
- * }
15
- * }
16
- * ```
17
- */
18
- export class SuperDocCliError extends Error {
19
- readonly code: string;
20
- readonly details?: unknown;
21
- readonly exitCode?: number;
22
-
23
- constructor(message: string, options: { code: string; details?: unknown; exitCode?: number }) {
24
- super(message);
25
- this.name = 'SuperDocCliError';
26
- this.code = options.code;
27
- this.details = options.details;
28
- this.exitCode = options.exitCode;
29
- }
30
- }