@bendyline/docblocks 1.1.2 → 2.1.0
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 +76 -11
- package/dist/chunk-6IYMTYMQ.js +1692 -0
- package/dist/chunk-6IYMTYMQ.js.map +1 -0
- package/dist/chunk-AEHCVWU5.js +25 -0
- package/dist/chunk-AEHCVWU5.js.map +1 -0
- package/dist/chunk-B56KWCSE.js +802 -0
- package/dist/chunk-B56KWCSE.js.map +1 -0
- package/dist/{chunk-ME76RUMR.js → chunk-BNKV7MTO.js} +15 -1
- package/dist/chunk-BNKV7MTO.js.map +1 -0
- package/dist/chunk-BXMF5YQJ.js +149 -0
- package/dist/chunk-BXMF5YQJ.js.map +1 -0
- package/dist/chunk-COYQXQK3.js +1071 -0
- package/dist/chunk-COYQXQK3.js.map +1 -0
- package/dist/chunk-DN7A33LL.js +780 -0
- package/dist/chunk-DN7A33LL.js.map +1 -0
- package/dist/chunk-EZKJZUNJ.js +13 -0
- package/dist/chunk-EZKJZUNJ.js.map +1 -0
- package/dist/chunk-FA7UNOXK.js +20 -0
- package/dist/chunk-FA7UNOXK.js.map +1 -0
- package/dist/chunk-FNW556FN.js +75 -0
- package/dist/chunk-FNW556FN.js.map +1 -0
- package/dist/chunk-GM5YXU4L.js +29 -0
- package/dist/chunk-GM5YXU4L.js.map +1 -0
- package/dist/chunk-JS6XFWQK.js +225 -0
- package/dist/chunk-JS6XFWQK.js.map +1 -0
- package/dist/chunk-MNSZ7EZN.js +111 -0
- package/dist/chunk-MNSZ7EZN.js.map +1 -0
- package/dist/chunk-P3DVZQ6S.js +228 -0
- package/dist/chunk-P3DVZQ6S.js.map +1 -0
- package/dist/chunk-P4WATND4.js +52 -0
- package/dist/chunk-P4WATND4.js.map +1 -0
- package/dist/chunk-RVPGQBWR.js +169 -0
- package/dist/chunk-RVPGQBWR.js.map +1 -0
- package/dist/chunk-U722UUFN.js +9 -0
- package/dist/chunk-U722UUFN.js.map +1 -0
- package/dist/chunk-VTCSF7VS.js +553 -0
- package/dist/chunk-VTCSF7VS.js.map +1 -0
- package/dist/chunk-WJKYY5QR.js +1350 -0
- package/dist/chunk-WJKYY5QR.js.map +1 -0
- package/dist/chunk-XUML3MKV.js +945 -0
- package/dist/chunk-XUML3MKV.js.map +1 -0
- package/dist/document/index.d.ts +358 -0
- package/dist/document/index.js +25 -0
- package/dist/document/index.js.map +1 -0
- package/dist/filesystem/electron.d.ts +73 -0
- package/dist/filesystem/electron.js +17 -0
- package/dist/filesystem/electron.js.map +1 -0
- package/dist/filesystem/index.d.ts +228 -8
- package/dist/filesystem/index.js +133 -6
- package/dist/filesystem/index.js.map +1 -1
- package/dist/filesystem/indexeddb.d.ts +284 -0
- package/dist/filesystem/indexeddb.js +23 -0
- package/dist/filesystem/indexeddb.js.map +1 -0
- package/dist/filesystem/memory.d.ts +152 -0
- package/dist/filesystem/memory.js +13 -0
- package/dist/filesystem/memory.js.map +1 -0
- package/dist/filesystem/native.d.ts +136 -0
- package/dist/filesystem/native.js +28 -0
- package/dist/filesystem/native.js.map +1 -0
- package/dist/host/index.d.ts +32 -6
- package/dist/host/index.js +26 -27
- package/dist/host/index.js.map +1 -1
- package/dist/index.d.ts +14 -9
- package/dist/index.js +204 -8
- package/dist/index.js.map +1 -1
- package/dist/mcp/index.d.ts +33 -0
- package/dist/mcp/index.js +32 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/zod.d.ts +5765 -0
- package/dist/mcp/zod.js +724 -0
- package/dist/mcp/zod.js.map +1 -0
- package/dist/share/index.d.ts +43 -0
- package/dist/share/index.js +13 -0
- package/dist/share/index.js.map +1 -0
- package/dist/types-BEg5SQ1_.d.ts +301 -0
- package/dist/types-CX893hgH.d.ts +468 -0
- package/dist/types-CueK0tvU.d.ts +501 -0
- package/dist/vscode/index.d.ts +220 -0
- package/dist/vscode/index.js +383 -0
- package/dist/vscode/index.js.map +1 -0
- package/dist/workspace/index.d.ts +141 -3
- package/dist/workspace/index.js +28 -1
- package/dist/workspace/index.js.map +1 -1
- package/dist/workspace-path-CWVrcuPL.d.ts +21 -0
- package/package.json +50 -5
- package/dist/chunk-GUNM43XZ.js +0 -63
- package/dist/chunk-GUNM43XZ.js.map +0 -1
- package/dist/chunk-IM7LCQJ6.js +0 -850
- package/dist/chunk-IM7LCQJ6.js.map +0 -1
- package/dist/chunk-ME76RUMR.js.map +0 -1
- package/dist/filesystem/electron-provider.d.ts +0 -32
- package/dist/filesystem/electron-provider.d.ts.map +0 -1
- package/dist/filesystem/electron-provider.js +0 -64
- package/dist/filesystem/electron-provider.js.map +0 -1
- package/dist/filesystem/file-media-provider.d.ts +0 -23
- package/dist/filesystem/file-media-provider.d.ts.map +0 -1
- package/dist/filesystem/file-media-provider.js +0 -85
- package/dist/filesystem/file-media-provider.js.map +0 -1
- package/dist/filesystem/filesystem-content-container.d.ts +0 -24
- package/dist/filesystem/filesystem-content-container.d.ts.map +0 -1
- package/dist/filesystem/filesystem-content-container.js +0 -116
- package/dist/filesystem/filesystem-content-container.js.map +0 -1
- package/dist/filesystem/index.d.ts.map +0 -1
- package/dist/filesystem/indexeddb-content-container.d.ts +0 -20
- package/dist/filesystem/indexeddb-content-container.d.ts.map +0 -1
- package/dist/filesystem/indexeddb-content-container.js +0 -93
- package/dist/filesystem/indexeddb-content-container.js.map +0 -1
- package/dist/filesystem/indexeddb-provider.d.ts +0 -32
- package/dist/filesystem/indexeddb-provider.d.ts.map +0 -1
- package/dist/filesystem/indexeddb-provider.js +0 -295
- package/dist/filesystem/indexeddb-provider.js.map +0 -1
- package/dist/filesystem/native-provider.d.ts +0 -45
- package/dist/filesystem/native-provider.d.ts.map +0 -1
- package/dist/filesystem/native-provider.js +0 -336
- package/dist/filesystem/native-provider.js.map +0 -1
- package/dist/filesystem/types.d.ts +0 -50
- package/dist/filesystem/types.d.ts.map +0 -1
- package/dist/filesystem/types.js +0 -8
- package/dist/filesystem/types.js.map +0 -1
- package/dist/host/index.d.ts.map +0 -1
- package/dist/host/types.d.ts +0 -149
- package/dist/host/types.d.ts.map +0 -1
- package/dist/host/types.js +0 -10
- package/dist/host/types.js.map +0 -1
- package/dist/index-pgBHBQ9G.d.ts +0 -213
- package/dist/index.d.ts.map +0 -1
- package/dist/workspace/index.d.ts.map +0 -1
- package/dist/workspace/types.d.ts +0 -29
- package/dist/workspace/types.d.ts.map +0 -1
- package/dist/workspace/types.js +0 -6
- package/dist/workspace/types.js.map +0 -1
- package/dist/workspace/workspace-manager.d.ts +0 -35
- package/dist/workspace/workspace-manager.d.ts.map +0 -1
- package/dist/workspace/workspace-manager.js +0 -82
- package/dist/workspace/workspace-manager.js.map +0 -1
- package/src/filesystem/electron-provider.ts +0 -88
- package/src/filesystem/file-media-provider.ts +0 -103
- package/src/filesystem/filesystem-content-container.ts +0 -126
- package/src/filesystem/index.ts +0 -24
- package/src/filesystem/indexeddb-content-container.ts +0 -104
- package/src/filesystem/indexeddb-provider.ts +0 -345
- package/src/filesystem/native-provider.ts +0 -384
- package/src/filesystem/types.ts +0 -69
- package/src/host/index.ts +0 -47
- package/src/host/types.ts +0 -153
- package/src/index.ts +0 -9
- package/src/workspace/index.ts +0 -10
- package/src/workspace/types.ts +0 -29
- package/src/workspace/workspace-manager.ts +0 -90
|
@@ -0,0 +1,802 @@
|
|
|
1
|
+
import {
|
|
2
|
+
tryParseWorkspacePath
|
|
3
|
+
} from "./chunk-JS6XFWQK.js";
|
|
4
|
+
|
|
5
|
+
// src/mcp/types.ts
|
|
6
|
+
var DOCBLOCKS_MCP_WIRE_VERSION = 1;
|
|
7
|
+
var DOCBLOCKS_MCP_TOOL_NAMES = [
|
|
8
|
+
"list_roots",
|
|
9
|
+
"get_conversion_report",
|
|
10
|
+
"convert_document",
|
|
11
|
+
"create_document_bundle",
|
|
12
|
+
"save_artifact",
|
|
13
|
+
"inspect_document",
|
|
14
|
+
"validate_document",
|
|
15
|
+
"preview_document",
|
|
16
|
+
"compare_documents",
|
|
17
|
+
"list_templates",
|
|
18
|
+
"describe_template",
|
|
19
|
+
"recommend_templates",
|
|
20
|
+
"describe_theme",
|
|
21
|
+
"infer_theme_from_file",
|
|
22
|
+
"inspect_pptx_layouts",
|
|
23
|
+
"apply_inferred_theme",
|
|
24
|
+
"list_formats",
|
|
25
|
+
"list_themes",
|
|
26
|
+
"list_transform_styles"
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
// src/mcp/wire.ts
|
|
30
|
+
var MCP_WIRE_LIMITS = Object.freeze({
|
|
31
|
+
identifierCharacters: 256,
|
|
32
|
+
formatCharacters: 64,
|
|
33
|
+
mimeTypeCharacters: 256,
|
|
34
|
+
labelCharacters: 1024,
|
|
35
|
+
pathCharacters: 4096,
|
|
36
|
+
uriCharacters: 8192,
|
|
37
|
+
messageCharacters: 4e3,
|
|
38
|
+
excerptCharacters: 4096,
|
|
39
|
+
documentCharacters: 20 * 1024 * 1024,
|
|
40
|
+
artifactBytes: 500 * 1024 * 1024,
|
|
41
|
+
bundleAssets: 256,
|
|
42
|
+
arrayEntries: 1e4,
|
|
43
|
+
previewItems: 1e3,
|
|
44
|
+
imageDimension: 32768
|
|
45
|
+
});
|
|
46
|
+
var IDENTIFIER_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._:-]*$/u;
|
|
47
|
+
var ENGINE_NAME_PATTERN = /^(?:[A-Za-z0-9][A-Za-z0-9._:-]*|@[A-Za-z0-9][A-Za-z0-9._-]*\/[A-Za-z0-9][A-Za-z0-9._-]*)$/u;
|
|
48
|
+
var FORMAT_PATTERN = /^[a-z0-9][a-z0-9.+_-]*$/u;
|
|
49
|
+
var MIME_TYPE_PATTERN = /^[a-z0-9!#$&^_.+-]+\/[a-z0-9!#$&^_.+-]+$/iu;
|
|
50
|
+
var SHA256_PATTERN = /^[a-f0-9]{64}$/u;
|
|
51
|
+
var ISO_TIMESTAMP_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/u;
|
|
52
|
+
function parseArtifactRef(value) {
|
|
53
|
+
if (!isRecord(value) || !hasExactKeys(value, [
|
|
54
|
+
"id",
|
|
55
|
+
"uri",
|
|
56
|
+
"format",
|
|
57
|
+
"mimeType",
|
|
58
|
+
"size",
|
|
59
|
+
"sha256",
|
|
60
|
+
"sourceFormat",
|
|
61
|
+
"sourceSha256",
|
|
62
|
+
"suggestedFilename",
|
|
63
|
+
"appliedOptions",
|
|
64
|
+
"engineVersions",
|
|
65
|
+
"createdAt",
|
|
66
|
+
"expiresAt"
|
|
67
|
+
])) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
const {
|
|
71
|
+
id,
|
|
72
|
+
uri,
|
|
73
|
+
format,
|
|
74
|
+
mimeType,
|
|
75
|
+
size,
|
|
76
|
+
sha256,
|
|
77
|
+
sourceFormat,
|
|
78
|
+
sourceSha256,
|
|
79
|
+
suggestedFilename,
|
|
80
|
+
createdAt,
|
|
81
|
+
expiresAt
|
|
82
|
+
} = value;
|
|
83
|
+
const appliedOptions = parseArray(value.appliedOptions, parseAppliedOption);
|
|
84
|
+
const engineVersions = parseArray(value.engineVersions, parseEngineVersion);
|
|
85
|
+
if (!isIdentifier(id) || !isArtifactUri(uri, id) || !isFormat(format) || !isMimeType(mimeType) || !isBoundedInteger(size, 0, MCP_WIRE_LIMITS.artifactBytes) || !isSha256(sha256) || !(sourceFormat === null || isFormat(sourceFormat)) || !(sourceSha256 === null || isSha256(sourceSha256)) || !isSafeFilename(suggestedFilename) || appliedOptions === null || engineVersions === null || hasDuplicateNames(appliedOptions) || hasDuplicateNames(engineVersions) || !isIsoTimestamp(createdAt) || !(expiresAt === null || isIsoTimestamp(expiresAt)) || expiresAt !== null && Date.parse(expiresAt) <= Date.parse(createdAt)) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
id,
|
|
90
|
+
uri,
|
|
91
|
+
format,
|
|
92
|
+
mimeType,
|
|
93
|
+
size,
|
|
94
|
+
sha256,
|
|
95
|
+
sourceFormat,
|
|
96
|
+
sourceSha256,
|
|
97
|
+
suggestedFilename,
|
|
98
|
+
appliedOptions,
|
|
99
|
+
engineVersions,
|
|
100
|
+
createdAt,
|
|
101
|
+
expiresAt
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function parseDocumentSource(value) {
|
|
105
|
+
if (!isRecord(value) || typeof value.kind !== "string") return null;
|
|
106
|
+
switch (value.kind) {
|
|
107
|
+
case "markdown": {
|
|
108
|
+
if (!hasExactKeys(value, ["kind", "markdown", "name"])) return null;
|
|
109
|
+
const { markdown, name } = value;
|
|
110
|
+
if (!isBoundedString(markdown, MCP_WIRE_LIMITS.documentCharacters) || !isNullableBoundedString(name, MCP_WIRE_LIMITS.labelCharacters)) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
return { kind: "markdown", markdown, name };
|
|
114
|
+
}
|
|
115
|
+
case "file": {
|
|
116
|
+
if (!hasExactKeys(value, ["kind", "rootId", "path", "format"])) return null;
|
|
117
|
+
const { rootId, path, format } = value;
|
|
118
|
+
const parsedPath = parseNonRootWorkspacePath(path);
|
|
119
|
+
if (!isIdentifier(rootId) || parsedPath === null || !(format === null || isFormat(format))) {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
return { kind: "file", rootId, path: parsedPath, format };
|
|
123
|
+
}
|
|
124
|
+
case "artifact": {
|
|
125
|
+
if (!hasExactKeys(value, ["kind", "uri"]) || !isArtifactUri(value.uri)) return null;
|
|
126
|
+
return { kind: "artifact", uri: value.uri };
|
|
127
|
+
}
|
|
128
|
+
case "bundle": {
|
|
129
|
+
if (!hasExactKeys(value, ["kind", "markdown", "assets", "name"])) return null;
|
|
130
|
+
const { markdown, name } = value;
|
|
131
|
+
if (!isBoundedString(markdown, MCP_WIRE_LIMITS.documentCharacters) || !isNullableBoundedString(name, MCP_WIRE_LIMITS.labelCharacters)) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
const assets = parseArray(value.assets, parseBundleAssetRef, MCP_WIRE_LIMITS.bundleAssets);
|
|
135
|
+
if (assets === null || hasDuplicatePaths(assets)) return null;
|
|
136
|
+
return { kind: "bundle", markdown, assets, name };
|
|
137
|
+
}
|
|
138
|
+
default:
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
function parseMcpDiagnostic(value) {
|
|
143
|
+
if (!isRecord(value) || !hasExactKeys(value, [
|
|
144
|
+
"code",
|
|
145
|
+
"severity",
|
|
146
|
+
"stage",
|
|
147
|
+
"format",
|
|
148
|
+
"count",
|
|
149
|
+
"message",
|
|
150
|
+
"remediation",
|
|
151
|
+
"retryable",
|
|
152
|
+
"location"
|
|
153
|
+
])) {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
const { code, severity, stage, format, count, message, remediation, retryable } = value;
|
|
157
|
+
const location = parseNullable(value.location, parseDiagnosticLocation);
|
|
158
|
+
if (!isIdentifier(code) || !isDiagnosticSeverity(severity) || !isDiagnosticStage(stage) || !(format === null || isFormat(format)) || !isBoundedInteger(count, 1, Number.MAX_SAFE_INTEGER) || !isBoundedString(message, MCP_WIRE_LIMITS.messageCharacters, 1) || !isNullableBoundedString(remediation, MCP_WIRE_LIMITS.messageCharacters) || typeof retryable !== "boolean" || location === void 0) {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
return {
|
|
162
|
+
code,
|
|
163
|
+
severity,
|
|
164
|
+
stage,
|
|
165
|
+
format,
|
|
166
|
+
count,
|
|
167
|
+
message,
|
|
168
|
+
remediation,
|
|
169
|
+
retryable,
|
|
170
|
+
location
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
function parseMcpErrorResult(value) {
|
|
174
|
+
if (!isRecord(value) || !hasExactKeys(value, ["version", "kind", "result", "error"]) || value.version !== DOCBLOCKS_MCP_WIRE_VERSION || value.kind !== "error" || value.result !== null || !isRecord(value.error) || !hasExactKeys(value.error, [
|
|
175
|
+
"code",
|
|
176
|
+
"message",
|
|
177
|
+
"stage",
|
|
178
|
+
"format",
|
|
179
|
+
"hint",
|
|
180
|
+
"retryable",
|
|
181
|
+
"operationLoad"
|
|
182
|
+
])) {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
const { code, message, stage, format, hint, retryable, operationLoad } = value.error;
|
|
186
|
+
if (!isIdentifier(code) || !isBoundedString(message, MCP_WIRE_LIMITS.messageCharacters, 1) || !(stage === null || isDiagnosticStage(stage)) || !(format === null || isFormat(format)) || !isNullableBoundedString(hint, MCP_WIRE_LIMITS.messageCharacters) || typeof retryable !== "boolean" || !(operationLoad === null || isRecord(operationLoad) && hasExactKeys(operationLoad, ["active", "capacity"]) && isBoundedInteger(operationLoad.active, 0, 32) && isBoundedInteger(operationLoad.capacity, 1, 32) && operationLoad.active <= operationLoad.capacity)) {
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
return {
|
|
190
|
+
version: DOCBLOCKS_MCP_WIRE_VERSION,
|
|
191
|
+
kind: "error",
|
|
192
|
+
result: null,
|
|
193
|
+
error: {
|
|
194
|
+
code,
|
|
195
|
+
message,
|
|
196
|
+
stage,
|
|
197
|
+
format,
|
|
198
|
+
hint,
|
|
199
|
+
retryable,
|
|
200
|
+
operationLoad: operationLoad === null ? null : {
|
|
201
|
+
active: operationLoad.active,
|
|
202
|
+
capacity: operationLoad.capacity
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
function parseConversionResult(value) {
|
|
208
|
+
if (!isRecord(value) || !hasExactKeys(value, [
|
|
209
|
+
"version",
|
|
210
|
+
"kind",
|
|
211
|
+
"sourceFormat",
|
|
212
|
+
"targetFormat",
|
|
213
|
+
"artifact",
|
|
214
|
+
"fidelity",
|
|
215
|
+
"appliedThemeId",
|
|
216
|
+
"appliedTransformId",
|
|
217
|
+
"sourceAssets",
|
|
218
|
+
"sourceAssetCount",
|
|
219
|
+
"diagnostics"
|
|
220
|
+
]) || value.version !== DOCBLOCKS_MCP_WIRE_VERSION || value.kind !== "conversion" || !isFormat(value.sourceFormat) || !isFormat(value.targetFormat) || !isConversionFidelity(value.fidelity) || !isNullableIdentifier(value.appliedThemeId) || !isNullableIdentifier(value.appliedTransformId) || !isBoundedInteger(value.sourceAssetCount, 0, MCP_WIRE_LIMITS.arrayEntries)) {
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
const artifact = parseArtifactRef(value.artifact);
|
|
224
|
+
const sourceAssets = parseArray(value.sourceAssets, parseAssetSummary);
|
|
225
|
+
const diagnostics = parseArray(value.diagnostics, parseMcpDiagnostic);
|
|
226
|
+
if (artifact === null || sourceAssets === null || diagnostics === null || sourceAssets.length !== value.sourceAssetCount || hasDuplicatePaths(sourceAssets) || artifact.format !== value.targetFormat || artifact.sourceFormat !== null && artifact.sourceFormat !== value.sourceFormat) {
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
return {
|
|
230
|
+
version: DOCBLOCKS_MCP_WIRE_VERSION,
|
|
231
|
+
kind: "conversion",
|
|
232
|
+
sourceFormat: value.sourceFormat,
|
|
233
|
+
targetFormat: value.targetFormat,
|
|
234
|
+
artifact,
|
|
235
|
+
fidelity: value.fidelity,
|
|
236
|
+
appliedThemeId: value.appliedThemeId,
|
|
237
|
+
appliedTransformId: value.appliedTransformId,
|
|
238
|
+
sourceAssets,
|
|
239
|
+
sourceAssetCount: value.sourceAssetCount,
|
|
240
|
+
diagnostics
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
function parseInspectionResult(value) {
|
|
244
|
+
if (!isRecord(value) || !hasExactKeys(value, [
|
|
245
|
+
"version",
|
|
246
|
+
"kind",
|
|
247
|
+
"sourceFormat",
|
|
248
|
+
"metadata",
|
|
249
|
+
"statistics",
|
|
250
|
+
"outline",
|
|
251
|
+
"blocks",
|
|
252
|
+
"blockOffset",
|
|
253
|
+
"nextCursor",
|
|
254
|
+
"tables",
|
|
255
|
+
"links",
|
|
256
|
+
"items",
|
|
257
|
+
"assets",
|
|
258
|
+
"theme",
|
|
259
|
+
"truncated",
|
|
260
|
+
"detailsTruncated",
|
|
261
|
+
"diagnostics"
|
|
262
|
+
]) || value.version !== DOCBLOCKS_MCP_WIRE_VERSION || value.kind !== "inspection" || !isFormat(value.sourceFormat) || !isBoundedInteger(value.blockOffset, 0, MCP_WIRE_LIMITS.arrayEntries) || !isNullableBoundedString(value.nextCursor, MCP_WIRE_LIMITS.identifierCharacters) || typeof value.truncated !== "boolean" || typeof value.detailsTruncated !== "boolean") {
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
const metadata = parseDocumentMetadata(value.metadata);
|
|
266
|
+
const statistics = parseDocumentStatistics(value.statistics);
|
|
267
|
+
const outline = parseArray(value.outline, parseOutlineEntry);
|
|
268
|
+
const blocks = parseArray(value.blocks, parseBlockSummary);
|
|
269
|
+
const tables = parseArray(value.tables, parseTableSummary);
|
|
270
|
+
const links = parseArray(value.links, parseLinkSummary);
|
|
271
|
+
const items = parseArray(value.items, parseDocumentItemSummary);
|
|
272
|
+
const assets = parseArray(value.assets, parseAssetSummary);
|
|
273
|
+
const theme = parseNullable(value.theme, parseThemeSummary);
|
|
274
|
+
const diagnostics = parseArray(value.diagnostics, parseMcpDiagnostic);
|
|
275
|
+
if (metadata === null || statistics === null || outline === null || blocks === null || tables === null || links === null || items === null || assets === null || theme === void 0 || diagnostics === null || statistics.blockCount < value.blockOffset + blocks.length || statistics.assetCount < assets.length || !value.truncated && statistics.blockCount !== value.blockOffset + blocks.length || value.truncated !== (value.nextCursor !== null) || statistics.tableCount < tables.length || statistics.linkCount < links.length || hasDuplicateIds(outline) || hasDuplicateIds(blocks) || hasDuplicateIndexes(tables) || hasDuplicateIndexes(links) || hasDuplicateItemIndexes(items) || hasDuplicatePaths(assets) || outline.some((entry) => entry.blockIndex >= statistics.blockCount) || blocks.some(
|
|
276
|
+
(block) => block.sourceRange !== null && block.sourceRange.end > statistics.characterCount
|
|
277
|
+
)) {
|
|
278
|
+
return null;
|
|
279
|
+
}
|
|
280
|
+
return {
|
|
281
|
+
version: DOCBLOCKS_MCP_WIRE_VERSION,
|
|
282
|
+
kind: "inspection",
|
|
283
|
+
sourceFormat: value.sourceFormat,
|
|
284
|
+
metadata,
|
|
285
|
+
statistics,
|
|
286
|
+
outline,
|
|
287
|
+
blocks,
|
|
288
|
+
blockOffset: value.blockOffset,
|
|
289
|
+
nextCursor: value.nextCursor,
|
|
290
|
+
tables,
|
|
291
|
+
links,
|
|
292
|
+
items,
|
|
293
|
+
assets,
|
|
294
|
+
theme,
|
|
295
|
+
truncated: value.truncated,
|
|
296
|
+
detailsTruncated: value.detailsTruncated,
|
|
297
|
+
diagnostics
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
function parseValidationResult(value) {
|
|
301
|
+
if (!isRecord(value) || !hasExactKeys(value, [
|
|
302
|
+
"version",
|
|
303
|
+
"kind",
|
|
304
|
+
"sourceFormat",
|
|
305
|
+
"targetFormat",
|
|
306
|
+
"valid",
|
|
307
|
+
"summary",
|
|
308
|
+
"diagnostics"
|
|
309
|
+
]) || value.version !== DOCBLOCKS_MCP_WIRE_VERSION || value.kind !== "validation" || !isFormat(value.sourceFormat) || !(value.targetFormat === null || isFormat(value.targetFormat)) || typeof value.valid !== "boolean") {
|
|
310
|
+
return null;
|
|
311
|
+
}
|
|
312
|
+
const summary = parseValidationSummary(value.summary);
|
|
313
|
+
const diagnostics = parseArray(value.diagnostics, parseMcpDiagnostic);
|
|
314
|
+
if (summary === null || diagnostics === null) return null;
|
|
315
|
+
const actualSummary = summarizeDiagnostics(diagnostics);
|
|
316
|
+
if (summary.errorCount !== actualSummary.errorCount || summary.warningCount !== actualSummary.warningCount || summary.infoCount !== actualSummary.infoCount || value.valid !== (summary.errorCount === 0)) {
|
|
317
|
+
return null;
|
|
318
|
+
}
|
|
319
|
+
return {
|
|
320
|
+
version: DOCBLOCKS_MCP_WIRE_VERSION,
|
|
321
|
+
kind: "validation",
|
|
322
|
+
sourceFormat: value.sourceFormat,
|
|
323
|
+
targetFormat: value.targetFormat,
|
|
324
|
+
valid: value.valid,
|
|
325
|
+
summary,
|
|
326
|
+
diagnostics
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
function parsePreviewResult(value) {
|
|
330
|
+
if (!isRecord(value) || !hasExactKeys(value, [
|
|
331
|
+
"version",
|
|
332
|
+
"kind",
|
|
333
|
+
"sourceFormat",
|
|
334
|
+
"previewBasis",
|
|
335
|
+
"totalItems",
|
|
336
|
+
"items",
|
|
337
|
+
"truncated",
|
|
338
|
+
"diagnostics"
|
|
339
|
+
]) || value.version !== DOCBLOCKS_MCP_WIRE_VERSION || value.kind !== "preview" || !isFormat(value.sourceFormat) || !(value.previewBasis === "source-render" || value.previewBasis === "reconstructed-import" || value.previewBasis === "native-extracted") || !isBoundedInteger(value.totalItems, 0, Number.MAX_SAFE_INTEGER) || typeof value.truncated !== "boolean") {
|
|
340
|
+
return null;
|
|
341
|
+
}
|
|
342
|
+
const items = parseArray(value.items, parsePreviewItem, MCP_WIRE_LIMITS.previewItems);
|
|
343
|
+
const diagnostics = parseArray(value.diagnostics, parseMcpDiagnostic);
|
|
344
|
+
if (items === null || diagnostics === null || value.totalItems < items.length || !value.truncated && value.totalItems !== items.length || hasDuplicatePreviewIndexes(items) || items.some(
|
|
345
|
+
(item) => item.artifact.sourceFormat !== null && item.artifact.sourceFormat !== value.sourceFormat
|
|
346
|
+
)) {
|
|
347
|
+
return null;
|
|
348
|
+
}
|
|
349
|
+
return {
|
|
350
|
+
version: DOCBLOCKS_MCP_WIRE_VERSION,
|
|
351
|
+
kind: "preview",
|
|
352
|
+
sourceFormat: value.sourceFormat,
|
|
353
|
+
previewBasis: value.previewBasis,
|
|
354
|
+
totalItems: value.totalItems,
|
|
355
|
+
items,
|
|
356
|
+
truncated: value.truncated,
|
|
357
|
+
diagnostics
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
function parseComparisonResult(value) {
|
|
361
|
+
if (!isRecord(value) || !hasExactKeys(value, [
|
|
362
|
+
"version",
|
|
363
|
+
"kind",
|
|
364
|
+
"leftFormat",
|
|
365
|
+
"rightFormat",
|
|
366
|
+
"equivalent",
|
|
367
|
+
"score",
|
|
368
|
+
"changes",
|
|
369
|
+
"metrics",
|
|
370
|
+
"diagnostics"
|
|
371
|
+
]) || value.version !== DOCBLOCKS_MCP_WIRE_VERSION || value.kind !== "comparison" || !isFormat(value.leftFormat) || !isFormat(value.rightFormat) || typeof value.equivalent !== "boolean" || !isBoundedNumber(value.score, 0, 1)) {
|
|
372
|
+
return null;
|
|
373
|
+
}
|
|
374
|
+
const changes = parseArray(value.changes, parseComparisonChange);
|
|
375
|
+
const metrics = parseArray(value.metrics, parseComparisonMetric);
|
|
376
|
+
const diagnostics = parseArray(value.diagnostics, parseMcpDiagnostic);
|
|
377
|
+
if (changes === null || metrics === null || diagnostics === null || hasDuplicateNames(metrics) || value.equivalent && (value.score !== 1 || changes.some((change) => change.status !== "retained"))) {
|
|
378
|
+
return null;
|
|
379
|
+
}
|
|
380
|
+
return {
|
|
381
|
+
version: DOCBLOCKS_MCP_WIRE_VERSION,
|
|
382
|
+
kind: "comparison",
|
|
383
|
+
leftFormat: value.leftFormat,
|
|
384
|
+
rightFormat: value.rightFormat,
|
|
385
|
+
equivalent: value.equivalent,
|
|
386
|
+
score: value.score,
|
|
387
|
+
changes,
|
|
388
|
+
metrics,
|
|
389
|
+
diagnostics
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
function parseMaterializationOptions(value) {
|
|
393
|
+
if (!isRecord(value) || !hasExactKeys(value, ["rootId", "path", "ifExists", "expectedSha256"]) || !isIdentifier(value.rootId)) {
|
|
394
|
+
return null;
|
|
395
|
+
}
|
|
396
|
+
const path = parseNonRootWorkspacePath(value.path);
|
|
397
|
+
if (path === null) return null;
|
|
398
|
+
if (value.ifExists === "error" && value.expectedSha256 === null) {
|
|
399
|
+
return { rootId: value.rootId, path, ifExists: "error", expectedSha256: null };
|
|
400
|
+
}
|
|
401
|
+
if (value.ifExists === "replace" && isSha256(value.expectedSha256)) {
|
|
402
|
+
return {
|
|
403
|
+
rootId: value.rootId,
|
|
404
|
+
path,
|
|
405
|
+
ifExists: "replace",
|
|
406
|
+
expectedSha256: value.expectedSha256
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
return null;
|
|
410
|
+
}
|
|
411
|
+
function parseBundleAssetRef(value) {
|
|
412
|
+
if (!isRecord(value) || !hasExactKeys(value, ["path", "source", "mimeType", "altText", "credit", "license"])) {
|
|
413
|
+
return null;
|
|
414
|
+
}
|
|
415
|
+
const path = parseNonRootWorkspacePath(value.path);
|
|
416
|
+
const source = parseBundleAssetContentSource(value.source);
|
|
417
|
+
if (path === null || source === null || !(value.mimeType === null || isMimeType(value.mimeType)) || !isNullableBoundedString(value.altText, MCP_WIRE_LIMITS.labelCharacters) || !isNullableBoundedString(value.credit, MCP_WIRE_LIMITS.labelCharacters) || !isNullableBoundedString(value.license, MCP_WIRE_LIMITS.labelCharacters)) {
|
|
418
|
+
return null;
|
|
419
|
+
}
|
|
420
|
+
return {
|
|
421
|
+
path,
|
|
422
|
+
source,
|
|
423
|
+
mimeType: value.mimeType,
|
|
424
|
+
altText: value.altText,
|
|
425
|
+
credit: value.credit,
|
|
426
|
+
license: value.license
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
function parseBundleAssetContentSource(value) {
|
|
430
|
+
if (!isRecord(value) || typeof value.kind !== "string") return null;
|
|
431
|
+
if (value.kind === "file") {
|
|
432
|
+
if (!hasExactKeys(value, ["kind", "rootId", "path"]) || !isIdentifier(value.rootId)) {
|
|
433
|
+
return null;
|
|
434
|
+
}
|
|
435
|
+
const path = parseNonRootWorkspacePath(value.path);
|
|
436
|
+
return path === null ? null : { kind: "file", rootId: value.rootId, path };
|
|
437
|
+
}
|
|
438
|
+
if (value.kind === "artifact") {
|
|
439
|
+
return hasExactKeys(value, ["kind", "uri"]) && isArtifactUri(value.uri) ? { kind: "artifact", uri: value.uri } : null;
|
|
440
|
+
}
|
|
441
|
+
return null;
|
|
442
|
+
}
|
|
443
|
+
function parseDiagnosticLocation(value) {
|
|
444
|
+
if (!isRecord(value) || typeof value.kind !== "string") return null;
|
|
445
|
+
switch (value.kind) {
|
|
446
|
+
case "source":
|
|
447
|
+
return hasExactKeys(value, ["kind", "line", "column"]) && isBoundedInteger(value.line, 1, Number.MAX_SAFE_INTEGER) && isBoundedInteger(value.column, 1, Number.MAX_SAFE_INTEGER) ? { kind: "source", line: value.line, column: value.column } : null;
|
|
448
|
+
case "block":
|
|
449
|
+
return hasExactKeys(value, ["kind", "blockId", "nodeType"]) && isIdentifier(value.blockId) && isIdentifier(value.nodeType) ? { kind: "block", blockId: value.blockId, nodeType: value.nodeType } : null;
|
|
450
|
+
case "asset": {
|
|
451
|
+
if (!hasExactKeys(value, ["kind", "path"])) return null;
|
|
452
|
+
const path = parseNonRootWorkspacePath(value.path);
|
|
453
|
+
return path === null ? null : { kind: "asset", path };
|
|
454
|
+
}
|
|
455
|
+
case "item":
|
|
456
|
+
return hasExactKeys(value, ["kind", "itemKind", "index"]) && isPreviewItemKind(value.itemKind) && isBoundedInteger(value.index, 0, Number.MAX_SAFE_INTEGER) ? { kind: "item", itemKind: value.itemKind, index: value.index } : null;
|
|
457
|
+
default:
|
|
458
|
+
return null;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
function parseAppliedOption(value) {
|
|
462
|
+
if (!isRecord(value) || !hasExactKeys(value, ["name", "value"]) || !isIdentifier(value.name) || !isAppliedOptionValue(value.value)) {
|
|
463
|
+
return null;
|
|
464
|
+
}
|
|
465
|
+
return { name: value.name, value: value.value };
|
|
466
|
+
}
|
|
467
|
+
function parseEngineVersion(value) {
|
|
468
|
+
if (!isRecord(value) || !hasExactKeys(value, ["name", "version"]) || !isEngineName(value.name) || !isBoundedString(value.version, MCP_WIRE_LIMITS.identifierCharacters, 1)) {
|
|
469
|
+
return null;
|
|
470
|
+
}
|
|
471
|
+
return { name: value.name, version: value.version };
|
|
472
|
+
}
|
|
473
|
+
function parseDocumentMetadata(value) {
|
|
474
|
+
if (!isRecord(value) || !hasExactKeys(value, ["title", "author", "description"]) || !isNullableBoundedString(value.title, MCP_WIRE_LIMITS.labelCharacters) || !isNullableBoundedString(value.author, MCP_WIRE_LIMITS.labelCharacters) || !isNullableBoundedString(value.description, MCP_WIRE_LIMITS.messageCharacters)) {
|
|
475
|
+
return null;
|
|
476
|
+
}
|
|
477
|
+
return { title: value.title, author: value.author, description: value.description };
|
|
478
|
+
}
|
|
479
|
+
function parseDocumentStatistics(value) {
|
|
480
|
+
if (!isRecord(value) || !hasExactKeys(value, [
|
|
481
|
+
"blockCount",
|
|
482
|
+
"wordCount",
|
|
483
|
+
"characterCount",
|
|
484
|
+
"tableCount",
|
|
485
|
+
"linkCount",
|
|
486
|
+
"assetCount",
|
|
487
|
+
"pageCount",
|
|
488
|
+
"slideCount",
|
|
489
|
+
"sheetCount"
|
|
490
|
+
]) || !isNonNegativeInteger(value.blockCount) || !isNonNegativeInteger(value.wordCount) || !isNonNegativeInteger(value.characterCount) || !isNonNegativeInteger(value.tableCount) || !isNonNegativeInteger(value.linkCount) || !isNonNegativeInteger(value.assetCount) || !isNullableNonNegativeInteger(value.pageCount) || !isNullableNonNegativeInteger(value.slideCount) || !isNullableNonNegativeInteger(value.sheetCount)) {
|
|
491
|
+
return null;
|
|
492
|
+
}
|
|
493
|
+
return {
|
|
494
|
+
blockCount: value.blockCount,
|
|
495
|
+
wordCount: value.wordCount,
|
|
496
|
+
characterCount: value.characterCount,
|
|
497
|
+
tableCount: value.tableCount,
|
|
498
|
+
linkCount: value.linkCount,
|
|
499
|
+
assetCount: value.assetCount,
|
|
500
|
+
pageCount: value.pageCount,
|
|
501
|
+
slideCount: value.slideCount,
|
|
502
|
+
sheetCount: value.sheetCount
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
function parseOutlineEntry(value) {
|
|
506
|
+
if (!isRecord(value) || !hasExactKeys(value, ["id", "title", "level", "blockIndex"]) || !isIdentifier(value.id) || !isBoundedString(value.title, MCP_WIRE_LIMITS.labelCharacters, 1) || !isBoundedInteger(value.level, 1, 6) || !isNonNegativeInteger(value.blockIndex)) {
|
|
507
|
+
return null;
|
|
508
|
+
}
|
|
509
|
+
return { id: value.id, title: value.title, level: value.level, blockIndex: value.blockIndex };
|
|
510
|
+
}
|
|
511
|
+
function parseBlockSummary(value) {
|
|
512
|
+
if (!isRecord(value) || !hasExactKeys(value, ["id", "type", "text", "wordCount", "templateId", "sourceRange"]) || !isIdentifier(value.id) || !isIdentifier(value.type) || !isBoundedString(value.text, MCP_WIRE_LIMITS.excerptCharacters) || !isNonNegativeInteger(value.wordCount) || !isNullableIdentifier(value.templateId)) {
|
|
513
|
+
return null;
|
|
514
|
+
}
|
|
515
|
+
const sourceRange = parseNullable(value.sourceRange, parseSourceRange);
|
|
516
|
+
if (sourceRange === void 0) return null;
|
|
517
|
+
return {
|
|
518
|
+
id: value.id,
|
|
519
|
+
type: value.type,
|
|
520
|
+
text: value.text,
|
|
521
|
+
wordCount: value.wordCount,
|
|
522
|
+
templateId: value.templateId,
|
|
523
|
+
sourceRange
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
function parseSourceRange(value) {
|
|
527
|
+
if (!isRecord(value) || !hasExactKeys(value, ["start", "end"]) || !isNonNegativeInteger(value.start) || !isNonNegativeInteger(value.end) || value.end < value.start) {
|
|
528
|
+
return null;
|
|
529
|
+
}
|
|
530
|
+
return { start: value.start, end: value.end };
|
|
531
|
+
}
|
|
532
|
+
function parseTableSummary(value) {
|
|
533
|
+
if (!isRecord(value) || !hasExactKeys(value, ["index", "rowCount", "columnCount", "headers"]) || !isNonNegativeInteger(value.index) || !isNonNegativeInteger(value.rowCount) || !isNonNegativeInteger(value.columnCount)) {
|
|
534
|
+
return null;
|
|
535
|
+
}
|
|
536
|
+
const headers = parseArray(
|
|
537
|
+
value.headers,
|
|
538
|
+
(entry) => isBoundedString(entry, MCP_WIRE_LIMITS.labelCharacters) ? entry : null
|
|
539
|
+
);
|
|
540
|
+
if (headers === null || headers.length > value.columnCount) return null;
|
|
541
|
+
return {
|
|
542
|
+
index: value.index,
|
|
543
|
+
rowCount: value.rowCount,
|
|
544
|
+
columnCount: value.columnCount,
|
|
545
|
+
headers
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
function parseLinkSummary(value) {
|
|
549
|
+
if (!isRecord(value) || !hasExactKeys(value, ["index", "text", "target"]) || !isNonNegativeInteger(value.index) || !isBoundedString(value.text, MCP_WIRE_LIMITS.labelCharacters) || !isBoundedString(value.target, MCP_WIRE_LIMITS.uriCharacters, 1)) {
|
|
550
|
+
return null;
|
|
551
|
+
}
|
|
552
|
+
return { index: value.index, text: value.text, target: value.target };
|
|
553
|
+
}
|
|
554
|
+
function parseDocumentItemSummary(value) {
|
|
555
|
+
if (!isRecord(value) || !hasExactKeys(value, ["kind", "index", "label", "blockIds"]) || !isPreviewItemKind(value.kind) || !isNonNegativeInteger(value.index) || !isNullableBoundedString(value.label, MCP_WIRE_LIMITS.labelCharacters)) {
|
|
556
|
+
return null;
|
|
557
|
+
}
|
|
558
|
+
const blockIds = parseArray(value.blockIds, (entry) => isIdentifier(entry) ? entry : null);
|
|
559
|
+
if (blockIds === null || new Set(blockIds).size !== blockIds.length) return null;
|
|
560
|
+
return { kind: value.kind, index: value.index, label: value.label, blockIds };
|
|
561
|
+
}
|
|
562
|
+
function parseAssetSummary(value) {
|
|
563
|
+
if (!isRecord(value) || !hasExactKeys(value, ["path", "mimeType", "size", "sha256", "altText", "credit", "license"])) {
|
|
564
|
+
return null;
|
|
565
|
+
}
|
|
566
|
+
const path = parseNonRootWorkspacePath(value.path);
|
|
567
|
+
if (path === null || !isMimeType(value.mimeType) || !isBoundedInteger(value.size, 0, MCP_WIRE_LIMITS.artifactBytes) || !(value.sha256 === null || isSha256(value.sha256)) || !isNullableBoundedString(value.altText, MCP_WIRE_LIMITS.labelCharacters) || !isNullableBoundedString(value.credit, MCP_WIRE_LIMITS.labelCharacters) || !isNullableBoundedString(value.license, MCP_WIRE_LIMITS.labelCharacters)) {
|
|
568
|
+
return null;
|
|
569
|
+
}
|
|
570
|
+
return {
|
|
571
|
+
path,
|
|
572
|
+
mimeType: value.mimeType,
|
|
573
|
+
size: value.size,
|
|
574
|
+
sha256: value.sha256,
|
|
575
|
+
altText: value.altText,
|
|
576
|
+
credit: value.credit,
|
|
577
|
+
license: value.license
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
function parseThemeSummary(value) {
|
|
581
|
+
if (!isRecord(value) || !hasExactKeys(value, ["id", "name", "source", "layouts"]) || !isIdentifier(value.id) || !isBoundedString(value.name, MCP_WIRE_LIMITS.labelCharacters, 1) || !(value.source === "built-in" || value.source === "document" || value.source === "inferred")) {
|
|
582
|
+
return null;
|
|
583
|
+
}
|
|
584
|
+
const layouts = parseStringArray(value.layouts, MCP_WIRE_LIMITS.labelCharacters);
|
|
585
|
+
if (layouts === null || new Set(layouts).size !== layouts.length) return null;
|
|
586
|
+
return { id: value.id, name: value.name, source: value.source, layouts };
|
|
587
|
+
}
|
|
588
|
+
function parseValidationSummary(value) {
|
|
589
|
+
if (!isRecord(value) || !hasExactKeys(value, ["errorCount", "warningCount", "infoCount"]) || !isNonNegativeInteger(value.errorCount) || !isNonNegativeInteger(value.warningCount) || !isNonNegativeInteger(value.infoCount)) {
|
|
590
|
+
return null;
|
|
591
|
+
}
|
|
592
|
+
return {
|
|
593
|
+
errorCount: value.errorCount,
|
|
594
|
+
warningCount: value.warningCount,
|
|
595
|
+
infoCount: value.infoCount
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
function parsePreviewItem(value) {
|
|
599
|
+
if (!isRecord(value) || !hasExactKeys(value, ["kind", "index", "label", "artifact", "width", "height"]) || !isPreviewItemKind(value.kind) || !isNonNegativeInteger(value.index) || !isNullableBoundedString(value.label, MCP_WIRE_LIMITS.labelCharacters) || !isBoundedInteger(value.width, 1, MCP_WIRE_LIMITS.imageDimension) || !isBoundedInteger(value.height, 1, MCP_WIRE_LIMITS.imageDimension)) {
|
|
600
|
+
return null;
|
|
601
|
+
}
|
|
602
|
+
const artifact = parseArtifactRef(value.artifact);
|
|
603
|
+
if (artifact === null || !artifact.mimeType.startsWith("image/")) return null;
|
|
604
|
+
return {
|
|
605
|
+
kind: value.kind,
|
|
606
|
+
index: value.index,
|
|
607
|
+
label: value.label,
|
|
608
|
+
artifact,
|
|
609
|
+
width: value.width,
|
|
610
|
+
height: value.height
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
function parseComparisonChange(value) {
|
|
614
|
+
if (!isRecord(value) || !hasExactKeys(value, ["category", "status", "path", "message"]) || !isComparisonCategory(value.category) || !isComparisonStatus(value.status) || !isNullableBoundedString(value.path, MCP_WIRE_LIMITS.pathCharacters) || !isBoundedString(value.message, MCP_WIRE_LIMITS.messageCharacters, 1)) {
|
|
615
|
+
return null;
|
|
616
|
+
}
|
|
617
|
+
return {
|
|
618
|
+
category: value.category,
|
|
619
|
+
status: value.status,
|
|
620
|
+
path: value.path,
|
|
621
|
+
message: value.message
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
function parseComparisonMetric(value) {
|
|
625
|
+
if (!isRecord(value) || !hasExactKeys(value, ["name", "leftValue", "rightValue", "similarity"]) || !isIdentifier(value.name) || !isFiniteNumber(value.leftValue) || !isFiniteNumber(value.rightValue) || !isBoundedNumber(value.similarity, 0, 1)) {
|
|
626
|
+
return null;
|
|
627
|
+
}
|
|
628
|
+
return {
|
|
629
|
+
name: value.name,
|
|
630
|
+
leftValue: value.leftValue,
|
|
631
|
+
rightValue: value.rightValue,
|
|
632
|
+
similarity: value.similarity
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
function summarizeDiagnostics(diagnostics) {
|
|
636
|
+
let errorCount = 0;
|
|
637
|
+
let warningCount = 0;
|
|
638
|
+
let infoCount = 0;
|
|
639
|
+
for (const diagnostic of diagnostics) {
|
|
640
|
+
if (diagnostic.severity === "error") errorCount += diagnostic.count;
|
|
641
|
+
else if (diagnostic.severity === "warning") warningCount += diagnostic.count;
|
|
642
|
+
else infoCount += diagnostic.count;
|
|
643
|
+
}
|
|
644
|
+
return { errorCount, warningCount, infoCount };
|
|
645
|
+
}
|
|
646
|
+
function parseArray(value, parser, maximumEntries = MCP_WIRE_LIMITS.arrayEntries) {
|
|
647
|
+
if (!Array.isArray(value) || value.length > maximumEntries) return null;
|
|
648
|
+
const parsed = [];
|
|
649
|
+
for (const entry of value) {
|
|
650
|
+
const result = parser(entry);
|
|
651
|
+
if (result === null) return null;
|
|
652
|
+
parsed.push(result);
|
|
653
|
+
}
|
|
654
|
+
return parsed;
|
|
655
|
+
}
|
|
656
|
+
function parseStringArray(value, maximumCharacters) {
|
|
657
|
+
if (!Array.isArray(value) || value.length > MCP_WIRE_LIMITS.arrayEntries) return null;
|
|
658
|
+
const parsed = [];
|
|
659
|
+
for (const entry of value) {
|
|
660
|
+
if (!isBoundedString(entry, maximumCharacters, 1)) return null;
|
|
661
|
+
parsed.push(entry);
|
|
662
|
+
}
|
|
663
|
+
return parsed;
|
|
664
|
+
}
|
|
665
|
+
function parseNullable(value, parser) {
|
|
666
|
+
if (value === null) return null;
|
|
667
|
+
return parser(value) ?? void 0;
|
|
668
|
+
}
|
|
669
|
+
function parseNonRootWorkspacePath(value) {
|
|
670
|
+
if (!isBoundedString(value, MCP_WIRE_LIMITS.pathCharacters, 1) || value.includes("\\") || value.startsWith("/") || value.endsWith("/") || value.includes("//")) {
|
|
671
|
+
return null;
|
|
672
|
+
}
|
|
673
|
+
const parsed = tryParseWorkspacePath(value);
|
|
674
|
+
return parsed !== null && parsed !== "" && parsed === value ? parsed : null;
|
|
675
|
+
}
|
|
676
|
+
function isArtifactUri(value, expectedId) {
|
|
677
|
+
if (!isBoundedString(value, MCP_WIRE_LIMITS.uriCharacters, 1)) return false;
|
|
678
|
+
try {
|
|
679
|
+
const url = new URL(value);
|
|
680
|
+
if (url.protocol !== "docblocks:" || url.hostname !== "artifacts" || url.username !== "" || url.password !== "" || url.port !== "" || url.search !== "" || url.hash !== "") {
|
|
681
|
+
return false;
|
|
682
|
+
}
|
|
683
|
+
const id = url.pathname.slice(1);
|
|
684
|
+
return !id.includes("/") && isIdentifier(id) && value === `docblocks://artifacts/${id}` && (expectedId === void 0 || id === expectedId);
|
|
685
|
+
} catch {
|
|
686
|
+
return false;
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
function isSafeFilename(value) {
|
|
690
|
+
return isBoundedString(value, MCP_WIRE_LIMITS.labelCharacters, 1) && value !== "." && value !== ".." && !value.includes("/") && !value.includes("\\");
|
|
691
|
+
}
|
|
692
|
+
function isIsoTimestamp(value) {
|
|
693
|
+
if (typeof value !== "string" || !ISO_TIMESTAMP_PATTERN.test(value)) return false;
|
|
694
|
+
const timestamp = Date.parse(value);
|
|
695
|
+
return Number.isFinite(timestamp) && new Date(timestamp).toISOString() === value;
|
|
696
|
+
}
|
|
697
|
+
function isIdentifier(value) {
|
|
698
|
+
return isBoundedString(value, MCP_WIRE_LIMITS.identifierCharacters, 1) && IDENTIFIER_PATTERN.test(value);
|
|
699
|
+
}
|
|
700
|
+
function isEngineName(value) {
|
|
701
|
+
return isBoundedString(value, MCP_WIRE_LIMITS.identifierCharacters, 1) && ENGINE_NAME_PATTERN.test(value);
|
|
702
|
+
}
|
|
703
|
+
function isNullableIdentifier(value) {
|
|
704
|
+
return value === null || isIdentifier(value);
|
|
705
|
+
}
|
|
706
|
+
function isFormat(value) {
|
|
707
|
+
return isBoundedString(value, MCP_WIRE_LIMITS.formatCharacters, 1) && FORMAT_PATTERN.test(value);
|
|
708
|
+
}
|
|
709
|
+
function isMimeType(value) {
|
|
710
|
+
return isBoundedString(value, MCP_WIRE_LIMITS.mimeTypeCharacters, 3) && MIME_TYPE_PATTERN.test(value);
|
|
711
|
+
}
|
|
712
|
+
function isSha256(value) {
|
|
713
|
+
return typeof value === "string" && SHA256_PATTERN.test(value);
|
|
714
|
+
}
|
|
715
|
+
function isAppliedOptionValue(value) {
|
|
716
|
+
return value === null || typeof value === "boolean" || isBoundedString(value, MCP_WIRE_LIMITS.messageCharacters) || isFiniteNumber(value);
|
|
717
|
+
}
|
|
718
|
+
function isDiagnosticSeverity(value) {
|
|
719
|
+
return value === "info" || value === "warning" || value === "error";
|
|
720
|
+
}
|
|
721
|
+
function isDiagnosticStage(value) {
|
|
722
|
+
return value === "resolve" || value === "import" || value === "parse" || value === "inspect" || value === "validate" || value === "transform" || value === "convert" || value === "render" || value === "export" || value === "materialize" || value === "compare";
|
|
723
|
+
}
|
|
724
|
+
function isConversionFidelity(value) {
|
|
725
|
+
return value === "semantic" || value === "editable-native" || value === "rendered-fidelity" || value === "hybrid";
|
|
726
|
+
}
|
|
727
|
+
function isPreviewItemKind(value) {
|
|
728
|
+
return value === "page" || value === "slide" || value === "sheet" || value === "frame";
|
|
729
|
+
}
|
|
730
|
+
function isComparisonCategory(value) {
|
|
731
|
+
return value === "text" || value === "structure" || value === "table" || value === "media" || value === "theme" || value === "layout" || value === "metadata" || value === "timing" || value === "accessibility";
|
|
732
|
+
}
|
|
733
|
+
function isComparisonStatus(value) {
|
|
734
|
+
return value === "retained" || value === "changed" || value === "degraded" || value === "omitted" || value === "added";
|
|
735
|
+
}
|
|
736
|
+
function hasDuplicateNames(values) {
|
|
737
|
+
return new Set(values.map((value) => value.name)).size !== values.length;
|
|
738
|
+
}
|
|
739
|
+
function hasDuplicateIds(values) {
|
|
740
|
+
return new Set(values.map((value) => value.id)).size !== values.length;
|
|
741
|
+
}
|
|
742
|
+
function hasDuplicatePaths(values) {
|
|
743
|
+
return new Set(values.map((value) => value.path)).size !== values.length;
|
|
744
|
+
}
|
|
745
|
+
function hasDuplicateIndexes(values) {
|
|
746
|
+
return new Set(values.map((value) => value.index)).size !== values.length;
|
|
747
|
+
}
|
|
748
|
+
function hasDuplicateItemIndexes(values) {
|
|
749
|
+
return new Set(values.map((value) => `${value.kind}:${value.index}`)).size !== values.length;
|
|
750
|
+
}
|
|
751
|
+
function hasDuplicatePreviewIndexes(values) {
|
|
752
|
+
const keys = values.map((value) => `${value.kind}:${value.index}`);
|
|
753
|
+
return new Set(keys).size !== keys.length;
|
|
754
|
+
}
|
|
755
|
+
function isRecord(value) {
|
|
756
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
757
|
+
}
|
|
758
|
+
function hasExactKeys(value, keys) {
|
|
759
|
+
const actual = Object.keys(value);
|
|
760
|
+
return actual.length === keys.length && keys.every((key) => Object.prototype.hasOwnProperty.call(value, key));
|
|
761
|
+
}
|
|
762
|
+
function isBoundedString(value, maximumCharacters, minimumCharacters = 0) {
|
|
763
|
+
return typeof value === "string" && value.length >= minimumCharacters && value.length <= maximumCharacters && ![...value].some((character) => {
|
|
764
|
+
const codePoint = character.codePointAt(0) ?? 0;
|
|
765
|
+
return codePoint === 0 || codePoint === 127;
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
function isNullableBoundedString(value, maximumCharacters) {
|
|
769
|
+
return value === null || isBoundedString(value, maximumCharacters);
|
|
770
|
+
}
|
|
771
|
+
function isFiniteNumber(value) {
|
|
772
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
773
|
+
}
|
|
774
|
+
function isBoundedNumber(value, minimum, maximum) {
|
|
775
|
+
return isFiniteNumber(value) && value >= minimum && value <= maximum;
|
|
776
|
+
}
|
|
777
|
+
function isBoundedInteger(value, minimum, maximum) {
|
|
778
|
+
return Number.isSafeInteger(value) && typeof value === "number" && value >= minimum && value <= maximum;
|
|
779
|
+
}
|
|
780
|
+
function isNonNegativeInteger(value) {
|
|
781
|
+
return isBoundedInteger(value, 0, Number.MAX_SAFE_INTEGER);
|
|
782
|
+
}
|
|
783
|
+
function isNullableNonNegativeInteger(value) {
|
|
784
|
+
return value === null || isNonNegativeInteger(value);
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
export {
|
|
788
|
+
DOCBLOCKS_MCP_WIRE_VERSION,
|
|
789
|
+
DOCBLOCKS_MCP_TOOL_NAMES,
|
|
790
|
+
MCP_WIRE_LIMITS,
|
|
791
|
+
parseArtifactRef,
|
|
792
|
+
parseDocumentSource,
|
|
793
|
+
parseMcpDiagnostic,
|
|
794
|
+
parseMcpErrorResult,
|
|
795
|
+
parseConversionResult,
|
|
796
|
+
parseInspectionResult,
|
|
797
|
+
parseValidationResult,
|
|
798
|
+
parsePreviewResult,
|
|
799
|
+
parseComparisonResult,
|
|
800
|
+
parseMaterializationOptions
|
|
801
|
+
};
|
|
802
|
+
//# sourceMappingURL=chunk-B56KWCSE.js.map
|