@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.
Files changed (42) hide show
  1. package/README.md +50 -35
  2. package/dist/generated/client.cjs +734 -6
  3. package/dist/generated/client.d.ts +20380 -2887
  4. package/dist/generated/client.d.ts.map +1 -1
  5. package/dist/generated/client.js +733 -6
  6. package/dist/generated/contract.cjs +115396 -33890
  7. package/dist/generated/contract.d.ts +30 -46113
  8. package/dist/generated/contract.d.ts.map +1 -1
  9. package/dist/generated/contract.js +115396 -33890
  10. package/dist/generated/intent-dispatch.generated.cjs +94 -0
  11. package/dist/generated/intent-dispatch.generated.d.ts +2 -0
  12. package/dist/generated/intent-dispatch.generated.d.ts.map +1 -0
  13. package/dist/generated/intent-dispatch.generated.js +90 -0
  14. package/dist/helpers/format.d.ts +6 -8
  15. package/dist/helpers/format.d.ts.map +1 -1
  16. package/dist/helpers/format.js +5 -8
  17. package/dist/index.cjs +133 -10
  18. package/dist/index.d.ts +76 -10
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +132 -9
  21. package/dist/runtime/process.d.ts +2 -2
  22. package/dist/runtime/process.d.ts.map +1 -1
  23. package/dist/runtime/transport-common.cjs +10 -0
  24. package/dist/runtime/transport-common.d.ts +7 -0
  25. package/dist/runtime/transport-common.d.ts.map +1 -1
  26. package/dist/runtime/transport-common.js +10 -0
  27. package/dist/tools.cjs +148 -286
  28. package/dist/tools.d.ts +37 -93
  29. package/dist/tools.d.ts.map +1 -1
  30. package/dist/tools.js +147 -284
  31. package/package.json +7 -6
  32. package/tools/__pycache__/__init__.cpython-312.pyc +0 -0
  33. package/tools/__pycache__/intent_dispatch_generated.cpython-312.pyc +0 -0
  34. package/tools/catalog.json +4288 -66383
  35. package/tools/intent_dispatch_generated.py +122 -0
  36. package/tools/system-prompt.md +113 -0
  37. package/tools/tools-policy.json +37 -94
  38. package/tools/tools.anthropic.json +4290 -27847
  39. package/tools/tools.generic.json +4357 -64146
  40. package/tools/tools.openai.json +4309 -28991
  41. package/tools/tools.vercel.json +4309 -28991
  42. package/tools/tool-name-map.json +0 -386
package/dist/index.js CHANGED
@@ -1,29 +1,152 @@
1
- import { createDocApi } from './generated/client.js';
2
- import { SuperDocRuntime } from './runtime/process.js';
1
+ import { createDocApi, createBoundDocApi, } from './generated/client.js';
2
+ import { CONTRACT } from './generated/contract.js';
3
+ import { SuperDocRuntime, } from './runtime/process.js';
4
+ import { SuperDocCliError } from './runtime/errors.js';
5
+ // ---------------------------------------------------------------------------
6
+ // Session-bound runtime wrapper
7
+ // ---------------------------------------------------------------------------
3
8
  /**
4
- * High-level client for interacting with SuperDoc documents via the CLI.
9
+ * Wraps a raw runtime and injects a fixed sessionId into every invoke call.
10
+ * Implements RuntimeInvoker so generated code can use it directly.
5
11
  *
6
- * Provides a typed `doc` API for opening, querying, and mutating documents.
7
- * Call {@link connect} before operations and {@link dispose} when finished
8
- * to manage the host process lifecycle.
12
+ * @internal
13
+ */
14
+ class BoundRuntime {
15
+ runtime;
16
+ sessionId;
17
+ closed = false;
18
+ constructor(runtime, sessionId) {
19
+ this.runtime = runtime;
20
+ this.sessionId = sessionId;
21
+ }
22
+ async invoke(operation, params = {}, options = {}) {
23
+ if (this.closed) {
24
+ throw new SuperDocCliError('Document handle is closed.', {
25
+ code: 'DOCUMENT_CLOSED',
26
+ details: { sessionId: this.sessionId },
27
+ });
28
+ }
29
+ return this.runtime.invoke(operation, { ...params, sessionId: this.sessionId }, options);
30
+ }
31
+ markClosed() {
32
+ this.closed = true;
33
+ }
34
+ }
35
+ // ---------------------------------------------------------------------------
36
+ // Document handle
37
+ // ---------------------------------------------------------------------------
38
+ /**
39
+ * Bound document handle. All document operations are available as typed methods.
40
+ * The handle injects its session id automatically — callers never pass
41
+ * doc or sessionId.
42
+ */
43
+ class SuperDocDocumentCore {
44
+ boundRuntime;
45
+ _sessionId;
46
+ _openResult;
47
+ client;
48
+ /** @internal */
49
+ constructor(boundRuntime, sessionId, openResult, client) {
50
+ this.boundRuntime = boundRuntime;
51
+ this._sessionId = sessionId;
52
+ this._openResult = openResult;
53
+ this.client = client;
54
+ attachBoundDocApi(this, createBoundDocApi(this.boundRuntime));
55
+ }
56
+ get sessionId() {
57
+ return this._sessionId;
58
+ }
59
+ /** Read-only snapshot of the initial doc.open response metadata. */
60
+ get openResult() {
61
+ return this._openResult;
62
+ }
63
+ async save(params = {}, options = {}) {
64
+ return this.boundRuntime.invoke(CONTRACT.operations['doc.save'], params, options);
65
+ }
66
+ async close(params = {}, options = {}) {
67
+ const result = await this.boundRuntime.invoke(CONTRACT.operations['doc.close'], params, options);
68
+ this.boundRuntime.markClosed();
69
+ this.client.removeHandle(this._sessionId);
70
+ return result;
71
+ }
72
+ /** @internal */
73
+ markClosed() {
74
+ this.boundRuntime.markClosed();
75
+ }
76
+ }
77
+ function attachBoundDocApi(target, api) {
78
+ const { save: _save, close: _close, ...boundMethods } = api;
79
+ Object.assign(target, boundMethods);
80
+ }
81
+ export const SuperDocDocument = SuperDocDocumentCore;
82
+ /**
83
+ * SuperDoc client — transport manager and document factory.
84
+ *
85
+ * Use `client.open()` to get bound document handles. Each handle is
86
+ * independently session-scoped and safe for concurrent use.
87
+ *
88
+ * const client = new SuperDocClient({ user: { name: 'bot' } });
89
+ * await client.connect();
90
+ * const doc = await client.open({ doc: './file.docx' });
91
+ * const markdown = await doc.getMarkdown();
92
+ * await doc.close();
93
+ * await client.dispose();
9
94
  */
10
95
  export class SuperDocClient {
11
96
  runtime;
12
- doc;
97
+ rawApi;
98
+ handles = new Map();
13
99
  constructor(options = {}) {
14
100
  this.runtime = new SuperDocRuntime(options);
15
- this.doc = createDocApi(this.runtime);
101
+ this.rawApi = createDocApi(this.runtime);
16
102
  }
17
103
  async connect() {
18
104
  await this.runtime.connect();
19
105
  }
106
+ /**
107
+ * Open a document and return a bound document handle.
108
+ *
109
+ * The returned handle injects its session id into every operation
110
+ * automatically. The same file can be opened multiple times with
111
+ * different session ids (useful for diff workflows).
112
+ */
113
+ async open(params, options) {
114
+ const explicitSessionId = params.sessionId;
115
+ if (typeof explicitSessionId === 'string' && this.handles.has(explicitSessionId)) {
116
+ throw new SuperDocCliError(`Session id already open in this client: ${explicitSessionId}`, {
117
+ code: 'SESSION_ALREADY_OPEN',
118
+ details: { sessionId: explicitSessionId },
119
+ });
120
+ }
121
+ const result = (await this.rawApi.open(params, options));
122
+ const contextId = result.contextId;
123
+ const boundRuntime = new BoundRuntime(this.runtime, contextId);
124
+ const handle = new SuperDocDocument(boundRuntime, contextId, result, this);
125
+ this.handles.set(contextId, handle);
126
+ return handle;
127
+ }
128
+ async describe(params = {}, options) {
129
+ return this.rawApi.describe(params, options);
130
+ }
131
+ async describeCommand(params, options) {
132
+ return this.rawApi.describeCommand(params, options);
133
+ }
20
134
  async dispose() {
135
+ for (const handle of this.handles.values()) {
136
+ handle.markClosed();
137
+ }
138
+ this.handles.clear();
21
139
  await this.runtime.dispose();
22
140
  }
141
+ /** @internal */
142
+ removeHandle(sessionId) {
143
+ this.handles.delete(sessionId);
144
+ }
23
145
  }
24
146
  export function createSuperDocClient(options = {}) {
25
147
  return new SuperDocClient(options);
26
148
  }
27
149
  export { getSkill, installSkill, listSkills } from './skills.js';
28
- export { chooseTools, dispatchSuperDocTool, getToolCatalog, inferDocumentFeatures, listTools, resolveToolOperation, } from './tools.js';
150
+ export { chooseTools, dispatchSuperDocTool, getSystemPrompt, getToolCatalog, listTools } from './tools.js';
151
+ export { dispatchIntentTool } from './generated/intent-dispatch.generated.js';
29
152
  export { SuperDocCliError } from './runtime/errors.js';
@@ -1,4 +1,4 @@
1
- import type { InvokeOptions, OperationParamSpec, OperationSpec, SuperDocClientOptions } from './transport-common.js';
1
+ import type { InvokeOptions, OperationParamSpec, OperationSpec, RuntimeInvoker, SuperDocClientOptions } from './transport-common.js';
2
2
  /**
3
3
  * Internal runtime that delegates CLI invocations to a persistent host transport.
4
4
  *
@@ -12,5 +12,5 @@ export declare class SuperDocRuntime {
12
12
  dispose(): Promise<void>;
13
13
  invoke<TData = unknown>(operation: OperationSpec, params?: Record<string, unknown>, options?: InvokeOptions): Promise<TData>;
14
14
  }
15
- export type { InvokeOptions, OperationParamSpec, OperationSpec, SuperDocClientOptions };
15
+ export type { InvokeOptions, OperationParamSpec, OperationSpec, RuntimeInvoker, SuperDocClientOptions };
16
16
  //# sourceMappingURL=process.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"process.d.ts","sourceRoot":"","sources":["../../src/runtime/process.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAErH;;;;;GAKG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAgB;gBAE9B,OAAO,GAAE,qBAA0B;IASzC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB,MAAM,CAAC,KAAK,GAAG,OAAO,EAC1B,SAAS,EAAE,aAAa,EACxB,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,EACpC,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,KAAK,CAAC;CAGlB;AAED,YAAY,EAAE,aAAa,EAAE,kBAAkB,EAAE,aAAa,EAAE,qBAAqB,EAAE,CAAC"}
1
+ {"version":3,"file":"process.d.ts","sourceRoot":"","sources":["../../src/runtime/process.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,aAAa,EACb,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,qBAAqB,EACtB,MAAM,uBAAuB,CAAC;AAE/B;;;;;GAKG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAgB;gBAE9B,OAAO,GAAE,qBAA0B;IASzC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB,MAAM,CAAC,KAAK,GAAG,OAAO,EAC1B,SAAS,EAAE,aAAa,EACxB,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,EACpC,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,KAAK,CAAC;CAGlB;AAED,YAAY,EAAE,aAAa,EAAE,kBAAkB,EAAE,aAAa,EAAE,cAAc,EAAE,qBAAqB,EAAE,CAAC"}
@@ -35,6 +35,14 @@ function buildOperationArgv(operation, params, options, runtimeTimeoutMs, defaul
35
35
  normalizedParams = { ...normalizedParams, userEmail: user.email };
36
36
  }
37
37
  }
38
+ // Legacy alias: tables.split renamed atRowIndex → rowIndex (SD-2132).
39
+ if (operation.operationId === 'doc.tables.split' && normalizedParams.atRowIndex !== undefined) {
40
+ if (normalizedParams.rowIndex !== undefined && normalizedParams.rowIndex !== normalizedParams.atRowIndex) {
41
+ throw new Error('tables.split: cannot provide both rowIndex and atRowIndex with different values.');
42
+ }
43
+ const { atRowIndex, ...rest } = normalizedParams;
44
+ normalizedParams = { ...rest, rowIndex: atRowIndex };
45
+ }
38
46
  const argv = [...operation.commandTokens];
39
47
  for (const spec of operation.params) {
40
48
  const value = normalizedParams[spec.name];
@@ -61,6 +69,8 @@ function buildOperationArgv(operation, params, options, runtimeTimeoutMs, defaul
61
69
  }
62
70
  break;
63
71
  case 'jsonFlag':
72
+ // CLI always parses --*-json values via JSON.parse, so even scalar
73
+ // strings must be serialized as JSON string literals.
64
74
  argv.push(flag, JSON.stringify(value));
65
75
  break;
66
76
  }
@@ -16,6 +16,13 @@ export interface InvokeOptions {
16
16
  timeoutMs?: number;
17
17
  stdinBytes?: Uint8Array;
18
18
  }
19
+ /**
20
+ * Minimal invoke interface that both SuperDocRuntime and BoundRuntime satisfy.
21
+ * Generated code depends on this interface, not on the concrete runtime class.
22
+ */
23
+ export interface RuntimeInvoker {
24
+ invoke<TData = unknown>(operation: OperationSpec, params?: Record<string, unknown>, options?: InvokeOptions): Promise<TData>;
25
+ }
19
26
  export type ChangeMode = 'direct' | 'tracked';
20
27
  export interface UserIdentity {
21
28
  name: string;
@@ -1 +1 @@
1
- {"version":3,"file":"transport-common.d.ts","sourceRoot":"","sources":["../../src/runtime/transport-common.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,GAAG,UAAU,CAAC;AAC9E,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,MAAM,GAAG,UAAU,CAAC;AAEpD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1C,QAAQ,CAAC,MAAM,EAAE,SAAS,kBAAkB,EAAE,CAAC;CAChD;AAED,MAAM,WAAW,aAAa;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB;AAED,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE9C,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,qBAAqB;IACpC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IACzC,gBAAgB,CAAC,EAAE,MAAM,CAAC;I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AAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,OAAO,EAAE,aAAa,EACtB,gBAAgB,EAAE,MAAM,GAAG,SAAS,EACpC,iBAAiB,CAAC,EAAE,UAAU,EAC9B,IAAI,CAAC,EAAE,YAAY,GAClB,MAAM,EAAE,CAiEV"}
@@ -33,6 +33,14 @@ export function buildOperationArgv(operation, params, options, runtimeTimeoutMs,
33
33
  normalizedParams = { ...normalizedParams, userEmail: user.email };
34
34
  }
35
35
  }
36
+ // Legacy alias: tables.split renamed atRowIndex → rowIndex (SD-2132).
37
+ if (operation.operationId === 'doc.tables.split' && normalizedParams.atRowIndex !== undefined) {
38
+ if (normalizedParams.rowIndex !== undefined && normalizedParams.rowIndex !== normalizedParams.atRowIndex) {
39
+ throw new Error('tables.split: cannot provide both rowIndex and atRowIndex with different values.');
40
+ }
41
+ const { atRowIndex, ...rest } = normalizedParams;
42
+ normalizedParams = { ...rest, rowIndex: atRowIndex };
43
+ }
36
44
  const argv = [...operation.commandTokens];
37
45
  for (const spec of operation.params) {
38
46
  const value = normalizedParams[spec.name];
@@ -59,6 +67,8 @@ export function buildOperationArgv(operation, params, options, runtimeTimeoutMs,
59
67
  }
60
68
  break;
61
69
  case 'jsonFlag':
70
+ // CLI always parses --*-json values via JSON.parse, so even scalar
71
+ // strings must be serialized as JSON string literals.
62
72
  argv.push(flag, JSON.stringify(value));
63
73
  break;
64
74
  }