@superdoc/sdk 2.15.1-next.5 → 2.16.0-next.1
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 +65 -0
- package/dist/generated/client.cjs +2 -0
- package/dist/generated/client.d.ts +311 -1
- package/dist/generated/client.js +2 -0
- package/dist/generated/contract.cjs +1 -1
- package/dist/generated/contract.js +1 -1
- package/dist/index.cjs +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/runtime/sdk-version.generated.cjs +1 -1
- package/dist/runtime/sdk-version.generated.d.ts +1 -1
- package/dist/runtime/sdk-version.generated.js +1 -1
- package/dist/tracked-review-route.cjs +75 -0
- package/dist/tracked-review-route.d.ts +39 -0
- package/dist/tracked-review-route.js +70 -0
- package/package.json +8 -8
- package/tools/tools-policy.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -13,6 +13,7 @@ var v2PresetCompat = require('./agent/v2-preset-compat.cjs');
|
|
|
13
13
|
var actions = require('./agent/actions.cjs');
|
|
14
14
|
var operationCatalog = require('./agent/operation-catalog.cjs');
|
|
15
15
|
var define = require('./actions/define.cjs');
|
|
16
|
+
var trackedReviewRoute = require('./tracked-review-route.cjs');
|
|
16
17
|
var presets = require('./presets.cjs');
|
|
17
18
|
|
|
18
19
|
// ---------------------------------------------------------------------------
|
|
@@ -221,6 +222,7 @@ exports.wrapV2PresetCompat = v2PresetCompat.wrapV2PresetCompat;
|
|
|
221
222
|
exports.getActionDispositions = actions.getActionDispositions;
|
|
222
223
|
exports.getOperationInputAliases = operationCatalog.getOperationInputAliases;
|
|
223
224
|
exports.defineAction = define.defineAction;
|
|
225
|
+
exports.runTrackedComparisonReview = trackedReviewRoute.runTrackedComparisonReview;
|
|
224
226
|
exports.DEFAULT_PRESET = presets.DEFAULT_PRESET;
|
|
225
227
|
exports.getPreset = presets.getPreset;
|
|
226
228
|
exports.listPresets = presets.listPresets;
|
package/dist/index.d.ts
CHANGED
|
@@ -103,5 +103,7 @@ export type { AgentToolkit, CreateAgentToolkitInput } from './tools.js';
|
|
|
103
103
|
export { defineAction } from './actions/define.js';
|
|
104
104
|
export type { ActionSpec, ActionStep, DefineActionInput, JSONSchemaObject } from './actions/define.js';
|
|
105
105
|
export { SuperDocCliError } from './runtime/errors.js';
|
|
106
|
+
export { runTrackedComparisonReview } from './tracked-review-route.js';
|
|
107
|
+
export type { TrackedReviewSession, TrackedComparisonReviewInput } from './tracked-review-route.js';
|
|
106
108
|
export type { CollaborationAuth, DocOpenOptions, InvokeOptions, OperationSpec, OperationParamSpec, RuntimeInvoker, SuperDocClientOptions, } from './runtime/process.js';
|
|
107
109
|
export type { DocOpenResult } from './generated/client.js';
|
package/dist/index.js
CHANGED
|
@@ -203,3 +203,4 @@ export { createAgentToolkit } from './tools.js';
|
|
|
203
203
|
// run tier); hand the specs to `createAgentToolkit({ actions })`.
|
|
204
204
|
export { defineAction } from './actions/define.js';
|
|
205
205
|
export { SuperDocCliError } from './runtime/errors.js';
|
|
206
|
+
export { runTrackedComparisonReview } from './tracked-review-route.js';
|
|
@@ -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.
|
|
6
|
+
const SDK_VERSION = '2.16.0-next.1';
|
|
7
7
|
|
|
8
8
|
exports.SDK_VERSION = SDK_VERSION;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "2.
|
|
1
|
+
export declare const SDK_VERSION = "2.16.0-next.1";
|
|
@@ -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.
|
|
4
|
+
export const SDK_VERSION = '2.16.0-next.1';
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var promises = require('node:fs/promises');
|
|
4
|
+
var os = require('node:os');
|
|
5
|
+
var path = require('node:path');
|
|
6
|
+
var errors = require('./runtime/errors.cjs');
|
|
7
|
+
|
|
8
|
+
async function runTrackedComparisonReview(input) {
|
|
9
|
+
if (!(input.baseBytes instanceof Uint8Array) ||
|
|
10
|
+
!(input.targetBytes instanceof Uint8Array) ||
|
|
11
|
+
input.baseBytes.byteLength === 0 ||
|
|
12
|
+
input.targetBytes.byteLength === 0) {
|
|
13
|
+
throw new errors.SuperDocCliError('Tracked review requires the exact base and target DOCX bytes.', {
|
|
14
|
+
code: 'INVALID_ARGUMENT',
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
if (!input.documentId ||
|
|
18
|
+
!input.actor ||
|
|
19
|
+
input.reviewSession.documentId !== input.documentId ||
|
|
20
|
+
input.reviewSession.actor !== input.actor) {
|
|
21
|
+
throw new errors.SuperDocCliError('The versioned review session is bound to another document or actor.', {
|
|
22
|
+
code: 'REVIEW_SESSION_MISMATCH',
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
const current = await input.currentReviewDocument(input.documentId);
|
|
26
|
+
if (current.version !== input.reviewSession.boundVersion ||
|
|
27
|
+
!Buffer.from(current.bytes).equals(Buffer.from(input.baseBytes))) {
|
|
28
|
+
throw new errors.SuperDocCliError('The exact base DOCX does not match the versioned review baseline.', {
|
|
29
|
+
code: 'REVIEW_BASE_MISMATCH',
|
|
30
|
+
details: {
|
|
31
|
+
documentId: input.documentId,
|
|
32
|
+
boundVersion: input.reviewSession.boundVersion,
|
|
33
|
+
currentVersion: current.version,
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
let stagingRoot;
|
|
38
|
+
let baseDocument;
|
|
39
|
+
let targetDocument;
|
|
40
|
+
let diff = null;
|
|
41
|
+
let comparisonError;
|
|
42
|
+
try {
|
|
43
|
+
stagingRoot = await promises.mkdtemp(path.join(os.tmpdir(), 'superdoc-tracked-review-'));
|
|
44
|
+
const basePath = path.join(stagingRoot, 'base.docx');
|
|
45
|
+
const targetPath = path.join(stagingRoot, 'target.docx');
|
|
46
|
+
await promises.writeFile(basePath, input.baseBytes, { flag: 'wx', mode: 0o600 });
|
|
47
|
+
await promises.writeFile(targetPath, input.targetBytes, { flag: 'wx', mode: 0o600 });
|
|
48
|
+
baseDocument = await input.client.open({ doc: basePath, runtime: 'v2' });
|
|
49
|
+
targetDocument = await input.client.open({ doc: targetPath, runtime: 'v2' });
|
|
50
|
+
const snapshot = await targetDocument.diff.capture({}, input.options);
|
|
51
|
+
diff = await baseDocument.diff.compare({ targetSnapshot: snapshot }, input.options);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
comparisonError = { message: error instanceof Error ? error.message : String(error) };
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
const closes = await Promise.allSettled([targetDocument?.close(), baseDocument?.close()]);
|
|
58
|
+
if (stagingRoot)
|
|
59
|
+
await promises.rm(stagingRoot, { recursive: true, force: true });
|
|
60
|
+
const failed = closes.find((result) => result.status === 'rejected');
|
|
61
|
+
if (failed?.status === 'rejected') {
|
|
62
|
+
const message = failed.reason instanceof Error ? failed.reason.message : String(failed.reason);
|
|
63
|
+
comparisonError = {
|
|
64
|
+
message: comparisonError ? `${comparisonError.message}; SDK close: ${message}` : `SDK close: ${message}`,
|
|
65
|
+
};
|
|
66
|
+
diff = null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const result = await input.reviewSession.applyTarget(input.targetBytes, 'tracked');
|
|
70
|
+
return comparisonError
|
|
71
|
+
? { kind: 'versioned-review', diff: null, comparisonError, result }
|
|
72
|
+
: { kind: 'versioned-review', diff, result };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
exports.runTrackedComparisonReview = runTrackedComparisonReview;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { DocDiffCompareResult } from './generated/client.js';
|
|
2
|
+
import type { InvokeOptions } from './runtime/process.js';
|
|
3
|
+
import type { SuperDocClient } from './index.js';
|
|
4
|
+
export interface TrackedReviewSession<TResult extends {
|
|
5
|
+
kind: string;
|
|
6
|
+
}> {
|
|
7
|
+
readonly boundVersion: string;
|
|
8
|
+
readonly documentId: string;
|
|
9
|
+
readonly actor: string;
|
|
10
|
+
applyTarget(targetBytes: Uint8Array, changeMode: 'tracked'): Promise<TResult>;
|
|
11
|
+
}
|
|
12
|
+
export interface TrackedComparisonReviewInput<TResult extends {
|
|
13
|
+
kind: string;
|
|
14
|
+
}> {
|
|
15
|
+
readonly client: Pick<SuperDocClient, 'open'>;
|
|
16
|
+
readonly baseBytes: Uint8Array;
|
|
17
|
+
readonly targetBytes: Uint8Array;
|
|
18
|
+
readonly documentId: string;
|
|
19
|
+
readonly actor: string;
|
|
20
|
+
readonly currentReviewDocument: (documentId: string) => Promise<{
|
|
21
|
+
version: string;
|
|
22
|
+
bytes: Uint8Array;
|
|
23
|
+
}>;
|
|
24
|
+
readonly reviewSession: TrackedReviewSession<TResult>;
|
|
25
|
+
readonly options?: InvokeOptions;
|
|
26
|
+
}
|
|
27
|
+
export interface TrackedComparisonReviewResult<TResult extends {
|
|
28
|
+
kind: string;
|
|
29
|
+
}> {
|
|
30
|
+
readonly kind: 'versioned-review';
|
|
31
|
+
readonly diff: DocDiffCompareResult | null;
|
|
32
|
+
readonly comparisonError?: {
|
|
33
|
+
readonly message: string;
|
|
34
|
+
};
|
|
35
|
+
readonly result: TResult;
|
|
36
|
+
}
|
|
37
|
+
export declare function runTrackedComparisonReview<TResult extends {
|
|
38
|
+
kind: string;
|
|
39
|
+
}>(input: TrackedComparisonReviewInput<TResult>): Promise<TrackedComparisonReviewResult<TResult>>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { mkdtemp, rm, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { SuperDocCliError } from './runtime/errors.js';
|
|
5
|
+
export async function runTrackedComparisonReview(input) {
|
|
6
|
+
if (!(input.baseBytes instanceof Uint8Array) ||
|
|
7
|
+
!(input.targetBytes instanceof Uint8Array) ||
|
|
8
|
+
input.baseBytes.byteLength === 0 ||
|
|
9
|
+
input.targetBytes.byteLength === 0) {
|
|
10
|
+
throw new SuperDocCliError('Tracked review requires the exact base and target DOCX bytes.', {
|
|
11
|
+
code: 'INVALID_ARGUMENT',
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
if (!input.documentId ||
|
|
15
|
+
!input.actor ||
|
|
16
|
+
input.reviewSession.documentId !== input.documentId ||
|
|
17
|
+
input.reviewSession.actor !== input.actor) {
|
|
18
|
+
throw new SuperDocCliError('The versioned review session is bound to another document or actor.', {
|
|
19
|
+
code: 'REVIEW_SESSION_MISMATCH',
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
const current = await input.currentReviewDocument(input.documentId);
|
|
23
|
+
if (current.version !== input.reviewSession.boundVersion ||
|
|
24
|
+
!Buffer.from(current.bytes).equals(Buffer.from(input.baseBytes))) {
|
|
25
|
+
throw new SuperDocCliError('The exact base DOCX does not match the versioned review baseline.', {
|
|
26
|
+
code: 'REVIEW_BASE_MISMATCH',
|
|
27
|
+
details: {
|
|
28
|
+
documentId: input.documentId,
|
|
29
|
+
boundVersion: input.reviewSession.boundVersion,
|
|
30
|
+
currentVersion: current.version,
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
let stagingRoot;
|
|
35
|
+
let baseDocument;
|
|
36
|
+
let targetDocument;
|
|
37
|
+
let diff = null;
|
|
38
|
+
let comparisonError;
|
|
39
|
+
try {
|
|
40
|
+
stagingRoot = await mkdtemp(join(tmpdir(), 'superdoc-tracked-review-'));
|
|
41
|
+
const basePath = join(stagingRoot, 'base.docx');
|
|
42
|
+
const targetPath = join(stagingRoot, 'target.docx');
|
|
43
|
+
await writeFile(basePath, input.baseBytes, { flag: 'wx', mode: 0o600 });
|
|
44
|
+
await writeFile(targetPath, input.targetBytes, { flag: 'wx', mode: 0o600 });
|
|
45
|
+
baseDocument = await input.client.open({ doc: basePath, runtime: 'v2' });
|
|
46
|
+
targetDocument = await input.client.open({ doc: targetPath, runtime: 'v2' });
|
|
47
|
+
const snapshot = await targetDocument.diff.capture({}, input.options);
|
|
48
|
+
diff = await baseDocument.diff.compare({ targetSnapshot: snapshot }, input.options);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
comparisonError = { message: error instanceof Error ? error.message : String(error) };
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
const closes = await Promise.allSettled([targetDocument?.close(), baseDocument?.close()]);
|
|
55
|
+
if (stagingRoot)
|
|
56
|
+
await rm(stagingRoot, { recursive: true, force: true });
|
|
57
|
+
const failed = closes.find((result) => result.status === 'rejected');
|
|
58
|
+
if (failed?.status === 'rejected') {
|
|
59
|
+
const message = failed.reason instanceof Error ? failed.reason.message : String(failed.reason);
|
|
60
|
+
comparisonError = {
|
|
61
|
+
message: comparisonError ? `${comparisonError.message}; SDK close: ${message}` : `SDK close: ${message}`,
|
|
62
|
+
};
|
|
63
|
+
diff = null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const result = await input.reviewSession.applyTarget(input.targetBytes, 'tracked');
|
|
67
|
+
return comparisonError
|
|
68
|
+
? { kind: 'versioned-review', diff: null, comparisonError, result }
|
|
69
|
+
: { kind: 'versioned-review', diff, result };
|
|
70
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superdoc/sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.16.0-next.1",
|
|
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.
|
|
42
|
-
"@superdoc/sdk-darwin-x64": "2.
|
|
43
|
-
"@superdoc/sdk-linux-x64": "2.
|
|
44
|
-
"@superdoc/sdk-linux-arm64": "2.
|
|
45
|
-
"@superdoc/sdk-windows-x64": "2.
|
|
41
|
+
"@superdoc/sdk-darwin-arm64": "2.16.0-next.1",
|
|
42
|
+
"@superdoc/sdk-darwin-x64": "2.16.0-next.1",
|
|
43
|
+
"@superdoc/sdk-linux-x64": "2.16.0-next.1",
|
|
44
|
+
"@superdoc/sdk-linux-arm64": "2.16.0-next.1",
|
|
45
|
+
"@superdoc/sdk-windows-x64": "2.16.0-next.1"
|
|
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 ../../../../tests/consumer-typecheck/src/sdk-custom-actions.mts ../../../../tests/consumer-typecheck/src/sd4807-sdk-inspect.mts ../../../../tests/consumer-typecheck/src/sdk-tracked-only-policy.mts",
|
|
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 ../../../../tests/consumer-typecheck/src/sd4807-sdk-inspect.mts ../../../../tests/consumer-typecheck/src/sdk-tracked-only-policy.mts ../../../../tests/consumer-typecheck/src/sdk-tracked-review-route.mts",
|
|
55
55
|
"test:agent-actions": "bun test src/__tests__/actions.test.ts src/__tests__/agent-runtime.test.ts src/__tests__/custom-actions.test.ts src/__tests__/textbox-snapshot.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",
|
|
56
|
+
"test:document-host": "bun test src/runtime/__tests__/host-spawn-args.test.ts src/runtime/__tests__/document-rpc.test.ts src/__tests__/tracked-review-route.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
|
}
|
package/tools/tools-policy.json
CHANGED