@superdoc/sdk 2.25.0 → 2.26.0-next.13
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 +8 -10
- package/dist/embedded-tools.generated.cjs +5 -5
- package/dist/embedded-tools.generated.js +5 -5
- package/dist/generated/client.d.ts +1730 -0
- package/dist/generated/contract.cjs +1 -1
- package/dist/generated/contract.d.ts +0 -10
- package/dist/generated/contract.js +1 -1
- package/dist/runtime/host.cjs +37 -242
- package/dist/runtime/host.d.ts +1 -16
- package/dist/runtime/host.js +36 -241
- package/dist/runtime/process.cjs +0 -26
- package/dist/runtime/process.d.ts +0 -8
- package/dist/runtime/process.js +0 -26
- package/dist/runtime/sdk-policy.d.ts +0 -10
- 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/runtime/transport-common.d.ts +0 -8
- package/package.json +7 -7
- package/tools/catalog.json +40 -0
- package/tools/generation-receipt.json +57 -19
- package/tools/tools-policy.json +1 -1
- package/tools/tools.anthropic.json +40 -0
- package/tools/tools.generic.json +40 -0
- package/tools/tools.openai.json +40 -0
- package/tools/tools.vercel.json +40 -0
- package/dist/runtime/document-rpc.cjs +0 -351
- package/dist/runtime/document-rpc.d.ts +0 -26
- package/dist/runtime/document-rpc.js +0 -333
- package/dist/runtime/embedded-document-host.cjs +0 -28
- package/dist/runtime/embedded-document-host.d.ts +0 -1
- package/dist/runtime/embedded-document-host.js +0 -23
package/tools/tools.vercel.json
CHANGED
|
@@ -272,6 +272,10 @@
|
|
|
272
272
|
"SelectionTarget": {
|
|
273
273
|
"type": "object",
|
|
274
274
|
"properties": {
|
|
275
|
+
"captureState": {
|
|
276
|
+
"type": "string",
|
|
277
|
+
"description": "Opaque browser selection capture state. Preserve it when passing a selection target to comments.create. Changed or unverifiable state is refused before writing."
|
|
278
|
+
},
|
|
275
279
|
"kind": {
|
|
276
280
|
"const": "selection",
|
|
277
281
|
"type": "string"
|
|
@@ -2019,6 +2023,10 @@
|
|
|
2019
2023
|
"SelectionTarget": {
|
|
2020
2024
|
"type": "object",
|
|
2021
2025
|
"properties": {
|
|
2026
|
+
"captureState": {
|
|
2027
|
+
"type": "string",
|
|
2028
|
+
"description": "Opaque browser selection capture state. Preserve it when passing a selection target to comments.create. Changed or unverifiable state is refused before writing."
|
|
2029
|
+
},
|
|
2022
2030
|
"kind": {
|
|
2023
2031
|
"const": "selection",
|
|
2024
2032
|
"type": "string"
|
|
@@ -3577,6 +3585,10 @@
|
|
|
3577
3585
|
"SelectionTarget": {
|
|
3578
3586
|
"type": "object",
|
|
3579
3587
|
"properties": {
|
|
3588
|
+
"captureState": {
|
|
3589
|
+
"type": "string",
|
|
3590
|
+
"description": "Opaque browser selection capture state. Preserve it when passing a selection target to comments.create. Changed or unverifiable state is refused before writing."
|
|
3591
|
+
},
|
|
3580
3592
|
"kind": {
|
|
3581
3593
|
"const": "selection",
|
|
3582
3594
|
"type": "string"
|
|
@@ -5101,6 +5113,10 @@
|
|
|
5101
5113
|
"additionalProperties": true,
|
|
5102
5114
|
"description": "Caller-owned JSON metadata persisted with the comment. Only for action 'create'. Omit for other actions."
|
|
5103
5115
|
},
|
|
5116
|
+
"expectedText": {
|
|
5117
|
+
"type": "string",
|
|
5118
|
+
"description": "Require the exact text currently at target before creating the comment. Pass the text the user selected, such as selection.current({ includeText: true }).text. A mismatch fails with PRECONDITION_FAILED and creates nothing. Only single-paragraph text targets support this guard; it checks the words, so it does not tell repeated identical text apart. Only for action 'create'. Omit for other actions."
|
|
5119
|
+
},
|
|
5104
5120
|
"id": {
|
|
5105
5121
|
"type": "string",
|
|
5106
5122
|
"description": "Required for actions 'delete', 'get'."
|
|
@@ -5285,6 +5301,10 @@
|
|
|
5285
5301
|
"SelectionTarget": {
|
|
5286
5302
|
"type": "object",
|
|
5287
5303
|
"properties": {
|
|
5304
|
+
"captureState": {
|
|
5305
|
+
"type": "string",
|
|
5306
|
+
"description": "Opaque browser selection capture state. Preserve it when passing a selection target to comments.create. Changed or unverifiable state is refused before writing."
|
|
5307
|
+
},
|
|
5288
5308
|
"kind": {
|
|
5289
5309
|
"const": "selection",
|
|
5290
5310
|
"type": "string"
|
|
@@ -5473,6 +5493,10 @@
|
|
|
5473
5493
|
"TextAddress": {
|
|
5474
5494
|
"type": "object",
|
|
5475
5495
|
"properties": {
|
|
5496
|
+
"captureState": {
|
|
5497
|
+
"type": "string",
|
|
5498
|
+
"description": "Opaque browser selection capture state. Preserve it when passing a selection target to comments.create. Changed or unverifiable state is refused before writing."
|
|
5499
|
+
},
|
|
5476
5500
|
"kind": {
|
|
5477
5501
|
"const": "text",
|
|
5478
5502
|
"type": "string"
|
|
@@ -5519,6 +5543,10 @@
|
|
|
5519
5543
|
"TextTarget": {
|
|
5520
5544
|
"type": "object",
|
|
5521
5545
|
"properties": {
|
|
5546
|
+
"captureState": {
|
|
5547
|
+
"type": "string",
|
|
5548
|
+
"description": "Opaque browser selection capture state. Preserve it when passing a selection target to comments.create. Changed or unverifiable state is refused before writing."
|
|
5549
|
+
},
|
|
5522
5550
|
"kind": {
|
|
5523
5551
|
"const": "text",
|
|
5524
5552
|
"type": "string"
|
|
@@ -6183,6 +6211,10 @@
|
|
|
6183
6211
|
"TextTarget": {
|
|
6184
6212
|
"type": "object",
|
|
6185
6213
|
"properties": {
|
|
6214
|
+
"captureState": {
|
|
6215
|
+
"type": "string",
|
|
6216
|
+
"description": "Opaque browser selection capture state. Preserve it when passing a selection target to comments.create. Changed or unverifiable state is refused before writing."
|
|
6217
|
+
},
|
|
6186
6218
|
"kind": {
|
|
6187
6219
|
"const": "text",
|
|
6188
6220
|
"type": "string"
|
|
@@ -9245,6 +9277,10 @@
|
|
|
9245
9277
|
"SelectionTarget": {
|
|
9246
9278
|
"type": "object",
|
|
9247
9279
|
"properties": {
|
|
9280
|
+
"captureState": {
|
|
9281
|
+
"type": "string",
|
|
9282
|
+
"description": "Opaque browser selection capture state. Preserve it when passing a selection target to comments.create. Changed or unverifiable state is refused before writing."
|
|
9283
|
+
},
|
|
9248
9284
|
"kind": {
|
|
9249
9285
|
"const": "selection",
|
|
9250
9286
|
"type": "string"
|
|
@@ -9433,6 +9469,10 @@
|
|
|
9433
9469
|
"TextAddress": {
|
|
9434
9470
|
"type": "object",
|
|
9435
9471
|
"properties": {
|
|
9472
|
+
"captureState": {
|
|
9473
|
+
"type": "string",
|
|
9474
|
+
"description": "Opaque browser selection capture state. Preserve it when passing a selection target to comments.create. Changed or unverifiable state is refused before writing."
|
|
9475
|
+
},
|
|
9436
9476
|
"kind": {
|
|
9437
9477
|
"const": "text",
|
|
9438
9478
|
"type": "string"
|
|
@@ -1,351 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var node_crypto = require('node:crypto');
|
|
4
|
-
var errors = require('./errors.cjs');
|
|
5
|
-
var sdkPolicy = require('./sdk-policy.cjs');
|
|
6
|
-
var trackedSupport = require('./tracked-support.cjs');
|
|
7
|
-
var transportCommon = require('./transport-common.cjs');
|
|
8
|
-
|
|
9
|
-
const DOCUMENT_RPC_FEATURES = sdkPolicy.SDK_POLICY.documentRpcFeatures;
|
|
10
|
-
const DOCUMENT_RPC_REPLACE_FILE_FEATURE = sdkPolicy.SDK_POLICY.features.replaceFile;
|
|
11
|
-
const DOCUMENT_RPC_DEFAULT_CHANGE_MODE_FEATURE = sdkPolicy.SDK_POLICY.features.defaultChangeMode;
|
|
12
|
-
const DOCUMENT_RPC_SOURCE_SAVE_FEATURE = sdkPolicy.SDK_POLICY.features.sourceSave;
|
|
13
|
-
const DOCUMENT_RPC_REQUEST_TIMEOUT_FEATURE = sdkPolicy.SDK_POLICY.features.requestTimeout;
|
|
14
|
-
const DOCUMENT_RPC_OPEN_FIELDS = new Set(sdkPolicy.SDK_POLICY.documentOpenFields);
|
|
15
|
-
const DOCUMENT_RPC_SAVE_FIELDS = new Set(sdkPolicy.SDK_POLICY.documentSaveFields);
|
|
16
|
-
const DOCUMENT_API_OPTION_FIELDS = new Set(sdkPolicy.SDK_POLICY.documentOptionFields);
|
|
17
|
-
const DOCUMENT_API_REVISION_PREFLIGHT_OPERATIONS = new Set(sdkPolicy.SDK_POLICY.revisionPreflightOperations);
|
|
18
|
-
function unsupported(message, operationId) {
|
|
19
|
-
return new errors.SuperDocCliError(message, {
|
|
20
|
-
code: 'DOCUMENT_RPC_INPUT_UNSUPPORTED',
|
|
21
|
-
...(operationId === undefined ? {} : { details: { operationId } }),
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
function buildDocumentAuthor(user) {
|
|
25
|
-
if (user === undefined)
|
|
26
|
-
return undefined;
|
|
27
|
-
if (typeof user !== 'object' || user === null || Array.isArray(user)) {
|
|
28
|
-
throw new errors.SuperDocCliError('user must be an object with a non-empty name.', {
|
|
29
|
-
code: 'INVALID_ARGUMENT',
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
const record = user;
|
|
33
|
-
if (typeof record.name !== 'string' || record.name.trim().length === 0) {
|
|
34
|
-
throw new errors.SuperDocCliError('user.name must be a non-empty string.', {
|
|
35
|
-
code: 'INVALID_ARGUMENT',
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
if (record.email !== undefined && typeof record.email !== 'string') {
|
|
39
|
-
throw new errors.SuperDocCliError('user.email must be a string.', {
|
|
40
|
-
code: 'INVALID_ARGUMENT',
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
return {
|
|
44
|
-
name: record.name,
|
|
45
|
-
...(record.email === undefined ? {} : { email: record.email }),
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
function documentRpcEnabled(env) {
|
|
49
|
-
return (env?.SUPERDOC_SDK_DOCUMENT_RPC ?? process.env.SUPERDOC_SDK_DOCUMENT_RPC) === '1';
|
|
50
|
-
}
|
|
51
|
-
function supportsDocumentRpc(features) {
|
|
52
|
-
return DOCUMENT_RPC_FEATURES.every((feature) => features.has(feature));
|
|
53
|
-
}
|
|
54
|
-
function canOpenWithDocumentRpc(params, options) {
|
|
55
|
-
if (options.stdinBytes !== undefined)
|
|
56
|
-
return false;
|
|
57
|
-
if (options.dryRun !== undefined || options.expectedRevision !== undefined || options.changeMode !== undefined) {
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
if (typeof params.doc !== 'string' || params.doc.trim().length === 0 || params.doc === '-')
|
|
61
|
-
return false;
|
|
62
|
-
if (params.runtime !== undefined && params.runtime !== 'v2')
|
|
63
|
-
return false;
|
|
64
|
-
if (params.sessionId !== undefined && (typeof params.sessionId !== 'string' || params.sessionId.length === 0)) {
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
return Object.entries(params).every(([key, value]) => value === undefined || DOCUMENT_RPC_OPEN_FIELDS.has(key));
|
|
68
|
-
}
|
|
69
|
-
function buildDocumentOpenParams(params, user, defaultChangeMode) {
|
|
70
|
-
const sessionId = typeof params.sessionId === 'string' && params.sessionId.length > 0 ? params.sessionId : node_crypto.randomUUID();
|
|
71
|
-
const author = buildDocumentAuthor(user);
|
|
72
|
-
return {
|
|
73
|
-
sessionId,
|
|
74
|
-
params: {
|
|
75
|
-
sessionId,
|
|
76
|
-
path: params.doc,
|
|
77
|
-
...(author === undefined ? {} : { author }),
|
|
78
|
-
...(defaultChangeMode == null ? {} : { defaultChangeMode }),
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
function mapDocumentOpenResult(response, sessionId, path) {
|
|
83
|
-
if (typeof response !== 'object' || response == null || Array.isArray(response)) {
|
|
84
|
-
throw new errors.SuperDocCliError('Host returned invalid document.open result.', {
|
|
85
|
-
code: 'HOST_PROTOCOL_ERROR',
|
|
86
|
-
details: { result: response },
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
const record = response;
|
|
90
|
-
if (record.sessionId !== sessionId || typeof record.byteLength !== 'number') {
|
|
91
|
-
throw new errors.SuperDocCliError('Host returned invalid document.open session metadata.', {
|
|
92
|
-
code: 'HOST_PROTOCOL_ERROR',
|
|
93
|
-
details: { result: response },
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
return {
|
|
97
|
-
active: true,
|
|
98
|
-
contextId: sessionId,
|
|
99
|
-
runtime: 'v2',
|
|
100
|
-
sessionType: 'local',
|
|
101
|
-
document: { path, source: 'path', byteLength: record.byteLength, revision: 0 },
|
|
102
|
-
dirty: false,
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
function mapDocumentReplaceFileResult(response, sessionId) {
|
|
106
|
-
if (typeof response !== 'object' || response == null || Array.isArray(response)) {
|
|
107
|
-
throw new errors.SuperDocCliError('Host returned invalid document.replaceFile result.', {
|
|
108
|
-
code: 'HOST_PROTOCOL_ERROR',
|
|
109
|
-
details: { result: response },
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
const record = response;
|
|
113
|
-
if (record.sessionId !== sessionId ||
|
|
114
|
-
record.replaced !== true ||
|
|
115
|
-
typeof record.byteLength !== 'number' ||
|
|
116
|
-
typeof record.revision !== 'string') {
|
|
117
|
-
throw new errors.SuperDocCliError('Host returned invalid document.replaceFile session metadata.', {
|
|
118
|
-
code: 'HOST_PROTOCOL_ERROR',
|
|
119
|
-
details: { expectedSessionId: sessionId, result: response },
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
return {
|
|
123
|
-
contextId: sessionId,
|
|
124
|
-
runtime: 'v2',
|
|
125
|
-
replaced: true,
|
|
126
|
-
document: { byteLength: record.byteLength, revision: record.revision },
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
function documentInvokePayload(operation, params, invokeOptions) {
|
|
130
|
-
params = transportCommon.captureMutationPlanAuthor(operation.operationId, params, invokeOptions);
|
|
131
|
-
const normalizedParams = transportCommon.applyOperationParamAliases(operation, params);
|
|
132
|
-
if (invokeOptions.stdinBytes !== undefined) {
|
|
133
|
-
throw unsupported('Structured document RPC does not support stdinBytes.', operation.operationId);
|
|
134
|
-
}
|
|
135
|
-
if (typeof normalizedParams.out === 'string' && normalizedParams.out.length > 0) {
|
|
136
|
-
throw unsupported('Structured document RPC does not support per-operation output paths.', operation.operationId);
|
|
137
|
-
}
|
|
138
|
-
if (normalizedParams.force === true) {
|
|
139
|
-
throw unsupported('Structured document RPC does not support per-operation force.', operation.operationId);
|
|
140
|
-
}
|
|
141
|
-
const input = {};
|
|
142
|
-
const options = {};
|
|
143
|
-
const paramsByName = new Map(operation.params.map((param) => [param.name, param]));
|
|
144
|
-
for (const [name, value] of Object.entries(normalizedParams)) {
|
|
145
|
-
if (value === undefined || name === 'doc' || name === 'sessionId' || name === 'out' || name === 'force')
|
|
146
|
-
continue;
|
|
147
|
-
const param = paramsByName.get(name);
|
|
148
|
-
if (!param) {
|
|
149
|
-
throw unsupported(`Structured document RPC does not support ${operation.operationId} field ${name}.`, operation.operationId);
|
|
150
|
-
}
|
|
151
|
-
if (typeof param.documentApiInputName === 'string' && param.documentApiInputName.length > 0) {
|
|
152
|
-
input[param.documentApiInputName] = value;
|
|
153
|
-
continue;
|
|
154
|
-
}
|
|
155
|
-
if (DOCUMENT_API_OPTION_FIELDS.has(name)) {
|
|
156
|
-
options[name] = value;
|
|
157
|
-
continue;
|
|
158
|
-
}
|
|
159
|
-
throw unsupported(`Structured document RPC does not support ${operation.operationId} field ${name}.`, operation.operationId);
|
|
160
|
-
}
|
|
161
|
-
for (const name of ['expectedRevision', 'changeMode', 'dryRun']) {
|
|
162
|
-
const value = invokeOptions[name];
|
|
163
|
-
if (value === undefined || normalizedParams[name] !== undefined)
|
|
164
|
-
continue;
|
|
165
|
-
const projectedValue = name === 'expectedRevision' ? String(value) : value;
|
|
166
|
-
const param = paramsByName.get(name);
|
|
167
|
-
if (typeof param?.documentApiInputName === 'string' && param.documentApiInputName.length > 0) {
|
|
168
|
-
input[param.documentApiInputName] = projectedValue;
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
options[name] = projectedValue;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
if (options.changeMode !== undefined && !trackedSupport.operationAcceptsTrackedMode(operation)) {
|
|
175
|
-
if (options.changeMode === 'tracked') {
|
|
176
|
-
throw unsupported(`Structured document RPC does not support tracked mode for ${operation.operationId}.`, operation.operationId);
|
|
177
|
-
}
|
|
178
|
-
if (options.changeMode !== 'direct') {
|
|
179
|
-
throw unsupported(`Structured document RPC received an invalid change mode for ${operation.operationId}.`, operation.operationId);
|
|
180
|
-
}
|
|
181
|
-
delete options.changeMode;
|
|
182
|
-
}
|
|
183
|
-
if (options.dryRun !== undefined && operation.supportsDryRun !== true) {
|
|
184
|
-
if (options.dryRun === true) {
|
|
185
|
-
throw unsupported(`Structured document RPC does not support dry run for ${operation.operationId}.`, operation.operationId);
|
|
186
|
-
}
|
|
187
|
-
delete options.dryRun;
|
|
188
|
-
}
|
|
189
|
-
if (options.expectedRevision !== undefined && DOCUMENT_API_REVISION_PREFLIGHT_OPERATIONS.has(operation.operationId)) {
|
|
190
|
-
throw unsupported(`Structured document RPC does not yet support expectedRevision for ${operation.operationId}.`, operation.operationId);
|
|
191
|
-
}
|
|
192
|
-
if (options.expectedRevision !== undefined && operation.mutates !== true) {
|
|
193
|
-
throw unsupported(`Structured document RPC does not support expectedRevision for ${operation.operationId}.`, operation.operationId);
|
|
194
|
-
}
|
|
195
|
-
return {
|
|
196
|
-
input,
|
|
197
|
-
...(Object.keys(options).length === 0 ? {} : { options }),
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
function buildDocumentInvokeParams(sessionId, operation, params, options, hostFeatures) {
|
|
201
|
-
if (operation.operationId === 'doc.save') {
|
|
202
|
-
if (options.stdinBytes !== undefined ||
|
|
203
|
-
options.dryRun !== undefined ||
|
|
204
|
-
options.expectedRevision !== undefined ||
|
|
205
|
-
options.changeMode !== undefined) {
|
|
206
|
-
throw unsupported('Structured document RPC does not support document.save invoke options.', operation.operationId);
|
|
207
|
-
}
|
|
208
|
-
const unknownField = Object.entries(params).find(([name, value]) => value !== undefined && !DOCUMENT_RPC_SAVE_FIELDS.has(name))?.[0];
|
|
209
|
-
if (unknownField !== undefined) {
|
|
210
|
-
throw unsupported(`Structured document RPC does not support doc.save field ${unknownField}.`, operation.operationId);
|
|
211
|
-
}
|
|
212
|
-
if (params.inPlace !== undefined && typeof params.inPlace !== 'boolean') {
|
|
213
|
-
throw unsupported('Structured document RPC requires inPlace to be a boolean.', operation.operationId);
|
|
214
|
-
}
|
|
215
|
-
if (params.inPlace === true && params.out !== undefined) {
|
|
216
|
-
throw unsupported('Structured document RPC requires either inPlace or out, not both.', operation.operationId);
|
|
217
|
-
}
|
|
218
|
-
if (params.out !== undefined && (typeof params.out !== 'string' || params.out.length === 0)) {
|
|
219
|
-
throw unsupported('Structured document RPC requires out to be a non-empty path.', operation.operationId);
|
|
220
|
-
}
|
|
221
|
-
if (params.out === undefined && hostFeatures?.has(DOCUMENT_RPC_SOURCE_SAVE_FEATURE) !== true) {
|
|
222
|
-
throw unsupported('Structured document RPC host does not support source saves.', operation.operationId);
|
|
223
|
-
}
|
|
224
|
-
return {
|
|
225
|
-
method: 'document.save',
|
|
226
|
-
params: {
|
|
227
|
-
sessionId,
|
|
228
|
-
...(params.out === undefined ? {} : { path: params.out }),
|
|
229
|
-
...(params.force === true ? { overwrite: true } : {}),
|
|
230
|
-
...(params.mode === undefined ? {} : { mode: params.mode }),
|
|
231
|
-
},
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
if (operation.operationId === 'doc.close') {
|
|
235
|
-
if (options.stdinBytes !== undefined ||
|
|
236
|
-
options.dryRun !== undefined ||
|
|
237
|
-
options.expectedRevision !== undefined ||
|
|
238
|
-
options.changeMode !== undefined) {
|
|
239
|
-
throw unsupported('Structured document RPC does not support document.close invoke options.', operation.operationId);
|
|
240
|
-
}
|
|
241
|
-
return {
|
|
242
|
-
method: 'document.close',
|
|
243
|
-
params: {
|
|
244
|
-
sessionId,
|
|
245
|
-
...(params.discard === undefined ? {} : { discard: params.discard }),
|
|
246
|
-
},
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
const documentOperation = operation;
|
|
250
|
-
if (typeof documentOperation.documentApiOperationId !== 'string' ||
|
|
251
|
-
documentOperation.documentApiOperationId.length === 0) {
|
|
252
|
-
throw unsupported(`Structured document RPC does not support ${operation.operationId}.`, operation.operationId);
|
|
253
|
-
}
|
|
254
|
-
const payload = documentInvokePayload(documentOperation, params, options);
|
|
255
|
-
return {
|
|
256
|
-
method: 'document.invoke',
|
|
257
|
-
params: {
|
|
258
|
-
sessionId,
|
|
259
|
-
operationId: documentOperation.documentApiOperationId,
|
|
260
|
-
input: payload.input,
|
|
261
|
-
...(payload.options === undefined ? {} : { options: payload.options }),
|
|
262
|
-
},
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
function documentRpcRequestSupportsResponseTimeout(operation, request) {
|
|
266
|
-
if (request.method === 'document.save')
|
|
267
|
-
return false;
|
|
268
|
-
if (request.method !== 'document.invoke')
|
|
269
|
-
return true;
|
|
270
|
-
const documentOperation = operation;
|
|
271
|
-
const requestOptions = typeof request.params.options === 'object' &&
|
|
272
|
-
request.params.options !== null &&
|
|
273
|
-
!Array.isArray(request.params.options)
|
|
274
|
-
? request.params.options
|
|
275
|
-
: undefined;
|
|
276
|
-
if (requestOptions?.dryRun === true)
|
|
277
|
-
return true;
|
|
278
|
-
if (documentOperation.mutates === false)
|
|
279
|
-
return true;
|
|
280
|
-
return documentOperation.idempotency === 'idempotent';
|
|
281
|
-
}
|
|
282
|
-
function mapDocumentLifecycleResult(operationId, response, sessionId, expectedInPlace) {
|
|
283
|
-
if (operationId !== 'doc.save' && operationId !== 'doc.close')
|
|
284
|
-
return response;
|
|
285
|
-
if (typeof response !== 'object' || response == null || Array.isArray(response)) {
|
|
286
|
-
throw new errors.SuperDocCliError(`Host returned invalid ${operationId.slice('doc.'.length)} result.`, {
|
|
287
|
-
code: 'HOST_PROTOCOL_ERROR',
|
|
288
|
-
details: { result: response },
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
const record = response;
|
|
292
|
-
if (record.sessionId !== sessionId) {
|
|
293
|
-
throw new errors.SuperDocCliError('Host returned a result for the wrong document session.', {
|
|
294
|
-
code: 'HOST_PROTOCOL_ERROR',
|
|
295
|
-
details: { expectedSessionId: sessionId, result: response },
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
if (operationId === 'doc.close') {
|
|
299
|
-
if (record.closed !== true || typeof record.discarded !== 'boolean') {
|
|
300
|
-
throw new errors.SuperDocCliError('Host returned invalid document.close result.', {
|
|
301
|
-
code: 'HOST_PROTOCOL_ERROR',
|
|
302
|
-
details: { result: response },
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
return {
|
|
306
|
-
contextId: sessionId,
|
|
307
|
-
runtime: 'v2',
|
|
308
|
-
closed: true,
|
|
309
|
-
saved: false,
|
|
310
|
-
discarded: record.discarded,
|
|
311
|
-
defaultSessionCleared: false,
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
const output = record.output;
|
|
315
|
-
if (record.saved !== true ||
|
|
316
|
-
(typeof record.inPlace !== 'boolean' && !(record.inPlace === undefined && expectedInPlace === false)) ||
|
|
317
|
-
typeof output !== 'object' ||
|
|
318
|
-
output == null ||
|
|
319
|
-
Array.isArray(output) ||
|
|
320
|
-
typeof output.path !== 'string' ||
|
|
321
|
-
typeof output.byteLength !== 'number') {
|
|
322
|
-
throw new errors.SuperDocCliError('Host returned invalid document.save result.', {
|
|
323
|
-
code: 'HOST_PROTOCOL_ERROR',
|
|
324
|
-
details: { result: response },
|
|
325
|
-
});
|
|
326
|
-
}
|
|
327
|
-
return {
|
|
328
|
-
contextId: sessionId,
|
|
329
|
-
runtime: 'v2',
|
|
330
|
-
saved: true,
|
|
331
|
-
inPlace: record.inPlace ?? false,
|
|
332
|
-
mode: record.mode,
|
|
333
|
-
output,
|
|
334
|
-
report: record.report,
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
exports.DOCUMENT_RPC_DEFAULT_CHANGE_MODE_FEATURE = DOCUMENT_RPC_DEFAULT_CHANGE_MODE_FEATURE;
|
|
339
|
-
exports.DOCUMENT_RPC_FEATURES = DOCUMENT_RPC_FEATURES;
|
|
340
|
-
exports.DOCUMENT_RPC_REPLACE_FILE_FEATURE = DOCUMENT_RPC_REPLACE_FILE_FEATURE;
|
|
341
|
-
exports.DOCUMENT_RPC_REQUEST_TIMEOUT_FEATURE = DOCUMENT_RPC_REQUEST_TIMEOUT_FEATURE;
|
|
342
|
-
exports.DOCUMENT_RPC_SOURCE_SAVE_FEATURE = DOCUMENT_RPC_SOURCE_SAVE_FEATURE;
|
|
343
|
-
exports.buildDocumentInvokeParams = buildDocumentInvokeParams;
|
|
344
|
-
exports.buildDocumentOpenParams = buildDocumentOpenParams;
|
|
345
|
-
exports.canOpenWithDocumentRpc = canOpenWithDocumentRpc;
|
|
346
|
-
exports.documentRpcEnabled = documentRpcEnabled;
|
|
347
|
-
exports.documentRpcRequestSupportsResponseTimeout = documentRpcRequestSupportsResponseTimeout;
|
|
348
|
-
exports.mapDocumentLifecycleResult = mapDocumentLifecycleResult;
|
|
349
|
-
exports.mapDocumentOpenResult = mapDocumentOpenResult;
|
|
350
|
-
exports.mapDocumentReplaceFileResult = mapDocumentReplaceFileResult;
|
|
351
|
-
exports.supportsDocumentRpc = supportsDocumentRpc;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { type ChangeMode, type InvokeOptions, type OperationSpec, type UserIdentity } from './transport-common.js';
|
|
2
|
-
export declare const DOCUMENT_RPC_FEATURES: readonly string[];
|
|
3
|
-
export declare const DOCUMENT_RPC_REPLACE_FILE_FEATURE: string;
|
|
4
|
-
export declare const DOCUMENT_RPC_DEFAULT_CHANGE_MODE_FEATURE: string;
|
|
5
|
-
export declare const DOCUMENT_RPC_SOURCE_SAVE_FEATURE: string;
|
|
6
|
-
export declare const DOCUMENT_RPC_REQUEST_TIMEOUT_FEATURE: string;
|
|
7
|
-
type DocumentRpcRequest = {
|
|
8
|
-
readonly method: string;
|
|
9
|
-
readonly params: Record<string, unknown>;
|
|
10
|
-
};
|
|
11
|
-
export declare function documentRpcEnabled(env: Record<string, string | undefined> | undefined): boolean;
|
|
12
|
-
export declare function supportsDocumentRpc(features: ReadonlySet<string>): boolean;
|
|
13
|
-
export declare function canOpenWithDocumentRpc(params: Record<string, unknown>, options: InvokeOptions): boolean;
|
|
14
|
-
export declare function buildDocumentOpenParams(params: Record<string, unknown>, user?: UserIdentity, defaultChangeMode?: ChangeMode): {
|
|
15
|
-
readonly sessionId: string;
|
|
16
|
-
readonly params: Record<string, unknown>;
|
|
17
|
-
};
|
|
18
|
-
export declare function mapDocumentOpenResult(response: unknown, sessionId: string, path: string): Record<string, unknown>;
|
|
19
|
-
export declare function mapDocumentReplaceFileResult(response: unknown, sessionId: string): Record<string, unknown>;
|
|
20
|
-
export declare function buildDocumentInvokeParams(sessionId: string, operation: OperationSpec, params: Record<string, unknown>, options: InvokeOptions, hostFeatures?: ReadonlySet<string>): {
|
|
21
|
-
readonly method: string;
|
|
22
|
-
readonly params: Record<string, unknown>;
|
|
23
|
-
};
|
|
24
|
-
export declare function documentRpcRequestSupportsResponseTimeout(operation: OperationSpec, request: DocumentRpcRequest): boolean;
|
|
25
|
-
export declare function mapDocumentLifecycleResult(operationId: string, response: unknown, sessionId: string, expectedInPlace?: boolean): unknown;
|
|
26
|
-
export {};
|