@tiwater/office-mcp 0.17.6 → 0.17.8
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/office/index.mjs
CHANGED
|
@@ -173,7 +173,10 @@ function docxInspectionOutput(tool) {
|
|
|
173
173
|
revision: docxRevision,
|
|
174
174
|
summary: z.object({
|
|
175
175
|
tableCount: z.number().int().nonnegative(),
|
|
176
|
-
|
|
176
|
+
openingParagraphs: z.array(z.object({
|
|
177
|
+
ref: z.string().regex(/^dox1_[0-9a-f]{64}$/),
|
|
178
|
+
textPreview: z.string().min(1).max(240),
|
|
179
|
+
}).strict()).max(6),
|
|
177
180
|
}).strict(),
|
|
178
181
|
}).strict();
|
|
179
182
|
}
|
|
@@ -187,6 +190,19 @@ const docxObjectIdentity = z.object({
|
|
|
187
190
|
verticalMerge: z.string().nullable(),
|
|
188
191
|
}).strict();
|
|
189
192
|
|
|
193
|
+
const docxNestedObjectIdentity = docxObjectIdentity.pick({
|
|
194
|
+
ref: true,
|
|
195
|
+
kind: true,
|
|
196
|
+
textPreview: true,
|
|
197
|
+
}).extend({
|
|
198
|
+
gridSpan: z.number().int().positive().optional(),
|
|
199
|
+
verticalMerge: z.string().optional(),
|
|
200
|
+
}).strict();
|
|
201
|
+
const docxObservationNode = z.lazy(() => z.object({
|
|
202
|
+
object: docxNestedObjectIdentity,
|
|
203
|
+
children: z.array(docxObservationNode).optional(),
|
|
204
|
+
}).strict());
|
|
205
|
+
|
|
190
206
|
const docxObservationReceipt = z.object({
|
|
191
207
|
schema: z.literal('tiwater.docx-observation-receipt/v1'),
|
|
192
208
|
operation: z.enum(['list', 'find', 'read']),
|
|
@@ -219,14 +235,13 @@ const docxFindLiteralOutput = z.object({
|
|
|
219
235
|
|
|
220
236
|
const docxReadObjectOutput = artifactOutput('docx_read_object').extend({
|
|
221
237
|
revision: docxRevision,
|
|
222
|
-
|
|
223
|
-
objects: z.array(docxObjectIdentity).min(1),
|
|
238
|
+
observation: docxObservationNode,
|
|
224
239
|
}).strict();
|
|
225
240
|
|
|
226
241
|
const tools = [
|
|
227
242
|
{
|
|
228
243
|
name: 'docx_inspect',
|
|
229
|
-
description: 'Inspect one current DOCX. The response returns its revision, table count, and
|
|
244
|
+
description: 'Inspect one current DOCX. The response returns its revision, table count, and up to six opening non-empty body paragraphs with native refs for document identification and immediate reuse; use docx_find_literal for other text and docx_list_objects for container children. The complete inspection remains in the evidence artifact.',
|
|
230
245
|
inputSchema: inputContract('docx_inspect'),
|
|
231
246
|
outputSchema: docxInspectionOutput('docx_inspect'),
|
|
232
247
|
annotations: { readOnlyHint: true, idempotentHint: true },
|
|
@@ -493,13 +508,18 @@ function compactDocxInspection(report) {
|
|
|
493
508
|
if (!report?.tables?.revision || !Array.isArray(report.tables.tables) || !Array.isArray(report.flow)) {
|
|
494
509
|
throw new Error('docx-table-inspection-result-invalid');
|
|
495
510
|
}
|
|
496
|
-
const
|
|
497
|
-
.filter(item => item?.type === 'paragraph'
|
|
511
|
+
const openingParagraphs = report.flow
|
|
512
|
+
.filter(item => item?.type === 'paragraph'
|
|
513
|
+
&& /^dox1_[0-9a-f]{64}$/u.test(item.objectRef)
|
|
514
|
+
&& typeof item.text === 'string' && item.text.trim())
|
|
498
515
|
.slice(0, 6)
|
|
499
|
-
.map(item =>
|
|
516
|
+
.map(item => ({
|
|
517
|
+
ref: item.objectRef,
|
|
518
|
+
textPreview: item.text.trim().replace(/\s+/gu, ' ').slice(0, 240),
|
|
519
|
+
}));
|
|
500
520
|
return {
|
|
501
521
|
revision: report.tables.revision,
|
|
502
|
-
summary: { tableCount: report.tables.tables.length,
|
|
522
|
+
summary: { tableCount: report.tables.tables.length, openingParagraphs },
|
|
503
523
|
};
|
|
504
524
|
}
|
|
505
525
|
|
|
@@ -514,15 +534,24 @@ function compactDocxObjectIdentity(object) {
|
|
|
514
534
|
};
|
|
515
535
|
}
|
|
516
536
|
|
|
517
|
-
function
|
|
518
|
-
|
|
519
|
-
function
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
537
|
+
function compactDocxObservation(observation) {
|
|
538
|
+
if (!observation?.object) throw new Error('docx-read-object-missing-observation');
|
|
539
|
+
function compactNode(node) {
|
|
540
|
+
const identity = compactDocxObjectIdentity(node.object);
|
|
541
|
+
const object = {
|
|
542
|
+
ref: identity.ref,
|
|
543
|
+
kind: identity.kind,
|
|
544
|
+
textPreview: identity.textPreview,
|
|
545
|
+
...(identity.gridSpan === null ? {} : { gridSpan: identity.gridSpan }),
|
|
546
|
+
...(identity.verticalMerge === null ? {} : { verticalMerge: identity.verticalMerge }),
|
|
547
|
+
};
|
|
548
|
+
const children = (node.children ?? []).map(compactNode);
|
|
549
|
+
return {
|
|
550
|
+
object,
|
|
551
|
+
...(children.length === 0 ? {} : { children }),
|
|
552
|
+
};
|
|
523
553
|
}
|
|
524
|
-
|
|
525
|
-
return objects;
|
|
554
|
+
return compactNode(observation);
|
|
526
555
|
}
|
|
527
556
|
|
|
528
557
|
async function docxInspect(args) {
|
|
@@ -569,8 +598,7 @@ async function docxReadObject(args) {
|
|
|
569
598
|
source: await fileArtifact(input),
|
|
570
599
|
artifact: await writeJsonArtifact(output, result.json),
|
|
571
600
|
revision: result.json.receipt.revision,
|
|
572
|
-
|
|
573
|
-
objects: compactDocxObservationObjects(result.json.observation),
|
|
601
|
+
observation: compactDocxObservation(result.json.observation),
|
|
574
602
|
};
|
|
575
603
|
});
|
|
576
604
|
}
|