@documonster/mcp 0.8.0-canary.sha.09791dab
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/LICENSE +205 -0
- package/README.md +253 -0
- package/dist/capabilities.d.ts +29 -0
- package/dist/capabilities.d.ts.map +1 -0
- package/dist/capabilities.js +188 -0
- package/dist/capabilities.js.map +1 -0
- package/dist/cli.d.ts +13 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +64 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +65 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +189 -0
- package/dist/config.js.map +1 -0
- package/dist/errors.d.ts +66 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +96 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/sandbox.d.ts +86 -0
- package/dist/sandbox.d.ts.map +1 -0
- package/dist/sandbox.js +224 -0
- package/dist/sandbox.js.map +1 -0
- package/dist/server.d.ts +22 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +66 -0
- package/dist/server.js.map +1 -0
- package/dist/tools/archive-read.d.ts +31 -0
- package/dist/tools/archive-read.d.ts.map +1 -0
- package/dist/tools/archive-read.js +315 -0
- package/dist/tools/archive-read.js.map +1 -0
- package/dist/tools/archive-write.d.ts +9 -0
- package/dist/tools/archive-write.d.ts.map +1 -0
- package/dist/tools/archive-write.js +219 -0
- package/dist/tools/archive-write.js.map +1 -0
- package/dist/tools/chart.d.ts +93 -0
- package/dist/tools/chart.d.ts.map +1 -0
- package/dist/tools/chart.js +263 -0
- package/dist/tools/chart.js.map +1 -0
- package/dist/tools/doc-convert.d.ts +13 -0
- package/dist/tools/doc-convert.d.ts.map +1 -0
- package/dist/tools/doc-convert.js +209 -0
- package/dist/tools/doc-convert.js.map +1 -0
- package/dist/tools/doc-paginate.d.ts +14 -0
- package/dist/tools/doc-paginate.d.ts.map +1 -0
- package/dist/tools/doc-paginate.js +153 -0
- package/dist/tools/doc-paginate.js.map +1 -0
- package/dist/tools/doc-read.d.ts +14 -0
- package/dist/tools/doc-read.d.ts.map +1 -0
- package/dist/tools/doc-read.js +175 -0
- package/dist/tools/doc-read.js.map +1 -0
- package/dist/tools/doc-review.d.ts +17 -0
- package/dist/tools/doc-review.d.ts.map +1 -0
- package/dist/tools/doc-review.js +249 -0
- package/dist/tools/doc-review.js.map +1 -0
- package/dist/tools/doc-search.d.ts +20 -0
- package/dist/tools/doc-search.d.ts.map +1 -0
- package/dist/tools/doc-search.js +268 -0
- package/dist/tools/doc-search.js.map +1 -0
- package/dist/tools/doc-write.d.ts +11 -0
- package/dist/tools/doc-write.d.ts.map +1 -0
- package/dist/tools/doc-write.js +81 -0
- package/dist/tools/doc-write.js.map +1 -0
- package/dist/tools/document.d.ts +74 -0
- package/dist/tools/document.d.ts.map +1 -0
- package/dist/tools/document.js +157 -0
- package/dist/tools/document.js.map +1 -0
- package/dist/tools/form-fill.d.ts +20 -0
- package/dist/tools/form-fill.d.ts.map +1 -0
- package/dist/tools/form-fill.js +270 -0
- package/dist/tools/form-fill.js.map +1 -0
- package/dist/tools/formula-evaluate.d.ts +14 -0
- package/dist/tools/formula-evaluate.d.ts.map +1 -0
- package/dist/tools/formula-evaluate.js +192 -0
- package/dist/tools/formula-evaluate.js.map +1 -0
- package/dist/tools/fs-helpers.d.ts +106 -0
- package/dist/tools/fs-helpers.d.ts.map +1 -0
- package/dist/tools/fs-helpers.js +257 -0
- package/dist/tools/fs-helpers.js.map +1 -0
- package/dist/tools/help.d.ts +227 -0
- package/dist/tools/help.d.ts.map +1 -0
- package/dist/tools/help.js +262 -0
- package/dist/tools/help.js.map +1 -0
- package/dist/tools/index.d.ts +33 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +78 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/inspect.d.ts +14 -0
- package/dist/tools/inspect.d.ts.map +1 -0
- package/dist/tools/inspect.js +463 -0
- package/dist/tools/inspect.js.map +1 -0
- package/dist/tools/pdf-edit.d.ts +26 -0
- package/dist/tools/pdf-edit.d.ts.map +1 -0
- package/dist/tools/pdf-edit.js +390 -0
- package/dist/tools/pdf-edit.js.map +1 -0
- package/dist/tools/result.d.ts +25 -0
- package/dist/tools/result.d.ts.map +1 -0
- package/dist/tools/result.js +43 -0
- package/dist/tools/result.js.map +1 -0
- package/dist/tools/sheet-edit.d.ts +16 -0
- package/dist/tools/sheet-edit.d.ts.map +1 -0
- package/dist/tools/sheet-edit.js +325 -0
- package/dist/tools/sheet-edit.js.map +1 -0
- package/dist/tools/sheet-read.d.ts +10 -0
- package/dist/tools/sheet-read.d.ts.map +1 -0
- package/dist/tools/sheet-read.js +139 -0
- package/dist/tools/sheet-read.js.map +1 -0
- package/dist/tools/sheet-write.d.ts +15 -0
- package/dist/tools/sheet-write.d.ts.map +1 -0
- package/dist/tools/sheet-write.js +290 -0
- package/dist/tools/sheet-write.js.map +1 -0
- package/dist/tools/spreadsheet.d.ts +100 -0
- package/dist/tools/spreadsheet.d.ts.map +1 -0
- package/dist/tools/spreadsheet.js +210 -0
- package/dist/tools/spreadsheet.js.map +1 -0
- package/dist/tools/template.d.ts +18 -0
- package/dist/tools/template.d.ts.map +1 -0
- package/dist/tools/template.js +209 -0
- package/dist/tools/template.js.map +1 -0
- package/dist/tools/types.d.ts +79 -0
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tools/types.js +18 -0
- package/dist/tools/types.js.map +1 -0
- package/package.json +74 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chart and data-source helpers shared by the spreadsheet write tools.
|
|
3
|
+
*
|
|
4
|
+
* The chart schema exposed to a model is deliberately much smaller than the
|
|
5
|
+
* library's. Two reasons:
|
|
6
|
+
*
|
|
7
|
+
* 1. **Reference construction is where a model fails.** A series wants
|
|
8
|
+
* `'My Sheet'!$B$2:$B$4`; asked for that, a model produces `B2:B4`,
|
|
9
|
+
* `Sheet1!B2:B4`, or a quoted name it forgot to escape. So the tool takes
|
|
10
|
+
* plain `A2:A4` ranges and builds the qualified form itself.
|
|
11
|
+
* 2. **Schema is context.** `AddChartOptions` has scores of fields —
|
|
12
|
+
* trendlines, error bars, 3-D scenes, manual layout. Exposing them would
|
|
13
|
+
* cost thousands of tokens on every request to serve a rare case. What
|
|
14
|
+
* actually changes whether a report is useful is type, data, title, legend.
|
|
15
|
+
*/
|
|
16
|
+
import { z } from "zod";
|
|
17
|
+
import { type SheetHandle } from "./spreadsheet.js";
|
|
18
|
+
/** Chart kinds worth offering. Deliberately not all 24 the library supports. */
|
|
19
|
+
export declare const CHART_TYPES: readonly ["column", "bar", "line", "area", "pie", "doughnut", "scatter", "radar"];
|
|
20
|
+
export declare const chartSchema: z.ZodObject<{
|
|
21
|
+
type: z.ZodEnum<{
|
|
22
|
+
area: "area";
|
|
23
|
+
bar: "bar";
|
|
24
|
+
column: "column";
|
|
25
|
+
doughnut: "doughnut";
|
|
26
|
+
line: "line";
|
|
27
|
+
pie: "pie";
|
|
28
|
+
radar: "radar";
|
|
29
|
+
scatter: "scatter";
|
|
30
|
+
}>;
|
|
31
|
+
title: z.ZodOptional<z.ZodString>;
|
|
32
|
+
categories: z.ZodString;
|
|
33
|
+
values: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
|
|
34
|
+
seriesNames: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
35
|
+
anchor: z.ZodOptional<z.ZodString>;
|
|
36
|
+
legend: z.ZodOptional<z.ZodEnum<{
|
|
37
|
+
bottom: "bottom";
|
|
38
|
+
left: "left";
|
|
39
|
+
none: "none";
|
|
40
|
+
right: "right";
|
|
41
|
+
top: "top";
|
|
42
|
+
}>>;
|
|
43
|
+
}, z.core.$strip>;
|
|
44
|
+
export type ChartSpec = z.infer<typeof chartSchema>;
|
|
45
|
+
/**
|
|
46
|
+
* Add one chart to a worksheet.
|
|
47
|
+
*
|
|
48
|
+
* @returns A human description of what was added.
|
|
49
|
+
*/
|
|
50
|
+
export declare function addChart(ws: SheetHandle, spec: ChartSpec): string;
|
|
51
|
+
/**
|
|
52
|
+
* Synthetic-data generation.
|
|
53
|
+
*
|
|
54
|
+
* A genuinely high-leverage capability: a few dozen tokens of column definitions
|
|
55
|
+
* produce megabytes of plausible rows. A model asked for 5 000 test rows would
|
|
56
|
+
* otherwise have to emit them itself, which is both ruinously expensive and
|
|
57
|
+
* worse data.
|
|
58
|
+
*/
|
|
59
|
+
export declare const generateSchema: z.ZodObject<{
|
|
60
|
+
rows: z.ZodNumber;
|
|
61
|
+
columns: z.ZodArray<z.ZodObject<{
|
|
62
|
+
name: z.ZodString;
|
|
63
|
+
type: z.ZodEnum<{
|
|
64
|
+
bool: "bool";
|
|
65
|
+
date: "date";
|
|
66
|
+
datetime: "datetime";
|
|
67
|
+
email: "email";
|
|
68
|
+
firstName: "firstName";
|
|
69
|
+
float: "float";
|
|
70
|
+
hex: "hex";
|
|
71
|
+
index: "index";
|
|
72
|
+
int: "int";
|
|
73
|
+
ip: "ip";
|
|
74
|
+
lastName: "lastName";
|
|
75
|
+
name: "name";
|
|
76
|
+
phone: "phone";
|
|
77
|
+
sentence: "sentence";
|
|
78
|
+
string: "string";
|
|
79
|
+
url: "url";
|
|
80
|
+
uuid: "uuid";
|
|
81
|
+
word: "word";
|
|
82
|
+
}>;
|
|
83
|
+
min: z.ZodOptional<z.ZodNumber>;
|
|
84
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
85
|
+
length: z.ZodOptional<z.ZodNumber>;
|
|
86
|
+
values: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
|
|
87
|
+
nullable: z.ZodOptional<z.ZodNumber>;
|
|
88
|
+
}, z.core.$strip>>;
|
|
89
|
+
}, z.core.$strip>;
|
|
90
|
+
export type GenerateSpec = z.infer<typeof generateSchema>;
|
|
91
|
+
/** Generate rows and write them into a worksheet, header included. */
|
|
92
|
+
export declare function writeGenerated(ws: SheetHandle, spec: GenerateSpec): string;
|
|
93
|
+
//# sourceMappingURL=chart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chart.d.ts","sourceRoot":"","sources":["../../src/tools/chart.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAKL,KAAK,WAAW,EACjB,MAAM,kBAAkB,CAAC;AAE1B,gFAAgF;AAChF,eAAO,MAAM,WAAW,YACtB,QAAQ,EACR,KAAK,EACL,MAAM,EACN,MAAM,EACN,KAAK,EACL,UAAU,EACV,SAAS,EACT,OAAO,CACC,CAAC;AAEX,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;iBA2BtB,CAAC;AAEH,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAEpD;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,GAAG,MAAM,CAoFjE;AAwED;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAqDzB,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAE1D,sEAAsE;AACtE,wBAAgB,cAAc,CAAC,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,YAAY,GAAG,MAAM,CAwB1E"}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chart and data-source helpers shared by the spreadsheet write tools.
|
|
3
|
+
*
|
|
4
|
+
* The chart schema exposed to a model is deliberately much smaller than the
|
|
5
|
+
* library's. Two reasons:
|
|
6
|
+
*
|
|
7
|
+
* 1. **Reference construction is where a model fails.** A series wants
|
|
8
|
+
* `'My Sheet'!$B$2:$B$4`; asked for that, a model produces `B2:B4`,
|
|
9
|
+
* `Sheet1!B2:B4`, or a quoted name it forgot to escape. So the tool takes
|
|
10
|
+
* plain `A2:A4` ranges and builds the qualified form itself.
|
|
11
|
+
* 2. **Schema is context.** `AddChartOptions` has scores of fields —
|
|
12
|
+
* trendlines, error bars, 3-D scenes, manual layout. Exposing them would
|
|
13
|
+
* cost thousands of tokens on every request to serve a rare case. What
|
|
14
|
+
* actually changes whether a report is useful is type, data, title, legend.
|
|
15
|
+
*/
|
|
16
|
+
import { Csv } from "documonster/csv";
|
|
17
|
+
import { Address, Chart, Worksheet } from "documonster/excel";
|
|
18
|
+
import { z } from "zod";
|
|
19
|
+
import { toolError } from "../errors.js";
|
|
20
|
+
import { MAX_EXCEL_COLUMNS, MAX_EXCEL_ROWS, parseRange, sheetName } from "./spreadsheet.js";
|
|
21
|
+
/** Chart kinds worth offering. Deliberately not all 24 the library supports. */
|
|
22
|
+
export const CHART_TYPES = [
|
|
23
|
+
"column",
|
|
24
|
+
"bar",
|
|
25
|
+
"line",
|
|
26
|
+
"area",
|
|
27
|
+
"pie",
|
|
28
|
+
"doughnut",
|
|
29
|
+
"scatter",
|
|
30
|
+
"radar"
|
|
31
|
+
];
|
|
32
|
+
export const chartSchema = z.object({
|
|
33
|
+
type: z.enum(CHART_TYPES).describe("Chart kind."),
|
|
34
|
+
title: z.string().optional().describe("Chart title."),
|
|
35
|
+
categories: z
|
|
36
|
+
.string()
|
|
37
|
+
.describe('Range holding the axis labels, e.g. "A2:A13". Plain A1 notation — no sheet name. For a scatter chart this is the numeric X range instead of labels.'),
|
|
38
|
+
values: z
|
|
39
|
+
.union([z.string(), z.array(z.string()).min(1)])
|
|
40
|
+
.describe('Range(s) holding the numbers, e.g. "B2:B13" or ["B2:B13","C2:C13"] for two series.'),
|
|
41
|
+
seriesNames: z
|
|
42
|
+
.array(z.string())
|
|
43
|
+
.optional()
|
|
44
|
+
.describe('Header cell for each series, e.g. ["B1","C1"], so the legend reads properly.'),
|
|
45
|
+
anchor: z
|
|
46
|
+
.string()
|
|
47
|
+
.optional()
|
|
48
|
+
.describe('Where to place it, as a range, e.g. "E2:L20". Defaults to a block right of the data.'),
|
|
49
|
+
legend: z
|
|
50
|
+
.enum(["right", "bottom", "top", "left", "none"])
|
|
51
|
+
.optional()
|
|
52
|
+
.describe("Legend position. Defaults to right when there is more than one series, otherwise none.")
|
|
53
|
+
});
|
|
54
|
+
/**
|
|
55
|
+
* Add one chart to a worksheet.
|
|
56
|
+
*
|
|
57
|
+
* @returns A human description of what was added.
|
|
58
|
+
*/
|
|
59
|
+
export function addChart(ws, spec) {
|
|
60
|
+
const name = sheetName(ws);
|
|
61
|
+
const valueRanges = typeof spec.values === "string" ? [spec.values] : spec.values;
|
|
62
|
+
if (spec.seriesNames !== undefined && spec.seriesNames.length !== valueRanges.length) {
|
|
63
|
+
throw toolError.invalidInput(`seriesNames has ${spec.seriesNames.length} entr(y/ies) but there are ${valueRanges.length} value range(s)`, "Give one name cell per series, or omit seriesNames entirely.");
|
|
64
|
+
}
|
|
65
|
+
const axis = qualify(name, spec.categories, "categories");
|
|
66
|
+
const axisCount = rangeLength(spec.categories);
|
|
67
|
+
const series = valueRanges.map((range, index) => {
|
|
68
|
+
if (rangeLength(range) !== axisCount) {
|
|
69
|
+
throw toolError.invalidInput(`values range ${JSON.stringify(range)} has ${rangeLength(range)} cells but categories has ${axisCount}`, "Every series and the category/X range must cover the same number of cells.");
|
|
70
|
+
}
|
|
71
|
+
const nameCell = spec.seriesNames?.[index];
|
|
72
|
+
return {
|
|
73
|
+
// `{ formula }`, not a bare string: the chart API treats a string as the
|
|
74
|
+
// literal legend text, so passing the reference would put
|
|
75
|
+
// `'Sales'!$B$1` in the legend instead of the header cell's value.
|
|
76
|
+
...(nameCell === undefined
|
|
77
|
+
? {}
|
|
78
|
+
: { name: { formula: qualify(name, nameCell, "seriesNames") } }),
|
|
79
|
+
values: qualify(name, range, "values"),
|
|
80
|
+
// A scatter series plots numbers against numbers, so the same range is
|
|
81
|
+
// its X values rather than category labels. The engine rejects
|
|
82
|
+
// `categories` there, so the distinction cannot be papered over.
|
|
83
|
+
...(spec.type === "scatter" ? { xValues: axis } : { categories: axis })
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
const anchor = spec.anchor ?? defaultAnchor(ws, valueRanges.length);
|
|
87
|
+
const legend = spec.legend ?? (series.length > 1 ? "right" : "none");
|
|
88
|
+
const options = {
|
|
89
|
+
...(spec.title === undefined ? {} : { title: spec.title }),
|
|
90
|
+
series,
|
|
91
|
+
// The API takes `showLegend` + `legendPosition`. A `legend: { position }`
|
|
92
|
+
// object is silently ignored, so "none" would still render a legend and a
|
|
93
|
+
// requested position would fall back to the default.
|
|
94
|
+
showLegend: legend !== "none",
|
|
95
|
+
...(legend === "none" ? {} : { legendPosition: legendCode(legend) })
|
|
96
|
+
};
|
|
97
|
+
try {
|
|
98
|
+
switch (spec.type) {
|
|
99
|
+
case "column":
|
|
100
|
+
Chart.addColumn(ws, options, anchor);
|
|
101
|
+
break;
|
|
102
|
+
case "bar":
|
|
103
|
+
Chart.addBar(ws, options, anchor);
|
|
104
|
+
break;
|
|
105
|
+
case "line":
|
|
106
|
+
Chart.addLine(ws, options, anchor);
|
|
107
|
+
break;
|
|
108
|
+
case "area":
|
|
109
|
+
Chart.addArea(ws, options, anchor);
|
|
110
|
+
break;
|
|
111
|
+
case "pie":
|
|
112
|
+
Chart.addPie(ws, options, anchor);
|
|
113
|
+
break;
|
|
114
|
+
case "doughnut":
|
|
115
|
+
Chart.addDoughnut(ws, options, anchor);
|
|
116
|
+
break;
|
|
117
|
+
case "scatter":
|
|
118
|
+
Chart.addScatter(ws, options, anchor);
|
|
119
|
+
break;
|
|
120
|
+
case "radar":
|
|
121
|
+
Chart.addRadar(ws, options, anchor);
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
catch (cause) {
|
|
126
|
+
throw toolError.invalidInput(`could not add the ${spec.type} chart: ${cause instanceof Error ? cause.message : String(cause)}`, "Check that `categories` and each `values` range cover the same number of cells.", { cause });
|
|
127
|
+
}
|
|
128
|
+
return `added a ${spec.type} chart${spec.title === undefined ? "" : ` titled ${JSON.stringify(spec.title)}`} with ${series.length} series at ${anchor}`;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Turn `B2:B13` into `'Sheet name'!$B$2:$B$13`.
|
|
132
|
+
*
|
|
133
|
+
* Quoting and absolute markers are added here rather than asked of the model,
|
|
134
|
+
* because a wrong reference produces a chart that renders empty — which looks
|
|
135
|
+
* like a library failure rather than a bad argument.
|
|
136
|
+
*/
|
|
137
|
+
function qualify(sheet, range, field) {
|
|
138
|
+
const trimmed = range.trim().toUpperCase().replace(/\$/g, "");
|
|
139
|
+
if (!/^[A-Z]{1,3}[1-9][0-9]*(?::[A-Z]{1,3}[1-9][0-9]*)?$/.test(trimmed)) {
|
|
140
|
+
throw toolError.invalidInput(`${field} value ${JSON.stringify(range)} is not a plain A1 range`, 'Use A1 notation without a sheet name, e.g. "B2:B13".');
|
|
141
|
+
}
|
|
142
|
+
// Validates Excel's row/column limits and rejects a backwards rectangle.
|
|
143
|
+
parseRange(trimmed);
|
|
144
|
+
const absolute = trimmed
|
|
145
|
+
.split(":")
|
|
146
|
+
.map(part => part.replace(/^([A-Z]+)([0-9]+)$/, "$$$1$$$2"))
|
|
147
|
+
.join(":");
|
|
148
|
+
return `${Address.quoteSheetName(sheet)}!${absolute}`;
|
|
149
|
+
}
|
|
150
|
+
/** Place a chart clear of the data when the caller does not choose. */
|
|
151
|
+
function defaultAnchor(ws, seriesCount) {
|
|
152
|
+
const dimensions = Worksheet.dimensions(ws);
|
|
153
|
+
const height = Math.max(15, seriesCount * 6);
|
|
154
|
+
const roomOnRight = dimensions.right + 8 <= MAX_EXCEL_COLUMNS;
|
|
155
|
+
const left = roomOnRight ? Math.max(1, dimensions.right + 2) : 1;
|
|
156
|
+
const top = roomOnRight ? 2 : Math.max(2, dimensions.bottom + 2);
|
|
157
|
+
if (top + height > MAX_EXCEL_ROWS) {
|
|
158
|
+
throw toolError.invalidInput("there is no room to place a chart beside or below the used range", "Pass an explicit `anchor` inside the worksheet, or put the chart on a separate sheet.");
|
|
159
|
+
}
|
|
160
|
+
return `${Address.encodeCell({ r: top - 1, c: left - 1 })}:${Address.encodeCell({ r: top + height - 1, c: left + 6 })}`;
|
|
161
|
+
}
|
|
162
|
+
/** Number of cells in a one-dimensional category/series range. */
|
|
163
|
+
function rangeLength(range) {
|
|
164
|
+
const window = parseRange(range);
|
|
165
|
+
const rows = window.bottom - window.top + 1;
|
|
166
|
+
const columns = window.right - window.left + 1;
|
|
167
|
+
if (rows > 1 && columns > 1) {
|
|
168
|
+
throw toolError.invalidInput(`chart range ${JSON.stringify(range)} is two-dimensional`, "Categories and series values must each be one row or one column.");
|
|
169
|
+
}
|
|
170
|
+
return rows * columns;
|
|
171
|
+
}
|
|
172
|
+
function legendCode(position) {
|
|
173
|
+
switch (position) {
|
|
174
|
+
case "right":
|
|
175
|
+
return "r";
|
|
176
|
+
case "bottom":
|
|
177
|
+
return "b";
|
|
178
|
+
case "top":
|
|
179
|
+
return "t";
|
|
180
|
+
case "left":
|
|
181
|
+
return "l";
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Synthetic-data generation.
|
|
186
|
+
*
|
|
187
|
+
* A genuinely high-leverage capability: a few dozen tokens of column definitions
|
|
188
|
+
* produce megabytes of plausible rows. A model asked for 5 000 test rows would
|
|
189
|
+
* otherwise have to emit them itself, which is both ruinously expensive and
|
|
190
|
+
* worse data.
|
|
191
|
+
*/
|
|
192
|
+
export const generateSchema = z.object({
|
|
193
|
+
rows: z
|
|
194
|
+
.number()
|
|
195
|
+
.int()
|
|
196
|
+
.positive()
|
|
197
|
+
.max(20_000)
|
|
198
|
+
.describe("How many data rows to generate (maximum 20,000)."),
|
|
199
|
+
columns: z
|
|
200
|
+
.array(z.object({
|
|
201
|
+
name: z.string().min(1).describe("Column header."),
|
|
202
|
+
type: z
|
|
203
|
+
.enum([
|
|
204
|
+
"string",
|
|
205
|
+
"int",
|
|
206
|
+
"float",
|
|
207
|
+
"bool",
|
|
208
|
+
"date",
|
|
209
|
+
"datetime",
|
|
210
|
+
"uuid",
|
|
211
|
+
"email",
|
|
212
|
+
"name",
|
|
213
|
+
"firstName",
|
|
214
|
+
"lastName",
|
|
215
|
+
"word",
|
|
216
|
+
"sentence",
|
|
217
|
+
"phone",
|
|
218
|
+
"url",
|
|
219
|
+
"ip",
|
|
220
|
+
"hex",
|
|
221
|
+
"index"
|
|
222
|
+
])
|
|
223
|
+
.describe("What kind of value to generate."),
|
|
224
|
+
min: z.number().optional().describe("For int/float."),
|
|
225
|
+
max: z.number().optional().describe("For int/float."),
|
|
226
|
+
length: z.number().int().positive().optional().describe("For string/hex."),
|
|
227
|
+
values: z
|
|
228
|
+
.array(z.union([z.string(), z.number(), z.boolean()]))
|
|
229
|
+
.optional()
|
|
230
|
+
.describe("Pick from this set instead of generating — use it for categories like regions."),
|
|
231
|
+
nullable: z
|
|
232
|
+
.number()
|
|
233
|
+
.min(0)
|
|
234
|
+
.max(1)
|
|
235
|
+
.optional()
|
|
236
|
+
.describe("Probability of a blank, 0–1. Useful for testing how code handles gaps.")
|
|
237
|
+
}))
|
|
238
|
+
.min(1)
|
|
239
|
+
.max(100)
|
|
240
|
+
.describe("Column definitions, left to right.")
|
|
241
|
+
});
|
|
242
|
+
/** Generate rows and write them into a worksheet, header included. */
|
|
243
|
+
export function writeGenerated(ws, spec) {
|
|
244
|
+
const cells = spec.rows * spec.columns.length;
|
|
245
|
+
if (cells > 2_000_000) {
|
|
246
|
+
throw toolError.tooLarge(`generation would create ${cells.toLocaleString()} cells, over the 2,000,000 limit`, "Reduce the rows or columns. Synthetic data is materialised in memory before the workbook is written.");
|
|
247
|
+
}
|
|
248
|
+
const generated = Csv.generate({
|
|
249
|
+
rows: spec.rows,
|
|
250
|
+
columns: spec.columns.map(column => ({
|
|
251
|
+
type: column.type,
|
|
252
|
+
name: column.name,
|
|
253
|
+
...(column.min === undefined ? {} : { min: column.min }),
|
|
254
|
+
...(column.max === undefined ? {} : { max: column.max }),
|
|
255
|
+
...(column.length === undefined ? {} : { length: column.length }),
|
|
256
|
+
...(column.values === undefined ? {} : { values: [...column.values] }),
|
|
257
|
+
...(column.nullable === undefined ? {} : { nullable: column.nullable })
|
|
258
|
+
}))
|
|
259
|
+
});
|
|
260
|
+
Worksheet.addAoa(ws, [generated.headers, ...generated.data]);
|
|
261
|
+
return `generated ${spec.rows} row(s) × ${spec.columns.length} column(s) server-side`;
|
|
262
|
+
}
|
|
263
|
+
//# sourceMappingURL=chart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chart.js","sourceRoot":"","sources":["../../src/tools/chart.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,UAAU,EACV,SAAS,EAEV,MAAM,kBAAkB,CAAC;AAE1B,gFAAgF;AAChF,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,QAAQ;IACR,KAAK;IACL,MAAM;IACN,MAAM;IACN,KAAK;IACL,UAAU;IACV,SAAS;IACT,OAAO;CACC,CAAC;AAEX,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC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AU,CAAC,CAAC;IAEvF,OAAO,aAAa,IAAI,CAAC,IAAI,aAAa,IAAI,CAAC,OAAO,CAAC,MAAM,wBAAwB,CAAC;AACxF,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `doc_convert` — convert a document between formats.
|
|
3
|
+
*
|
|
4
|
+
* The highest-leverage tool per line of code: "this is the wrong format" is the
|
|
5
|
+
* most common friction a user hits, and one call with two paths solves it. The
|
|
6
|
+
* routing table below is the whole tool.
|
|
7
|
+
*
|
|
8
|
+
* Deliberately excluded: anything lossy in a way the caller cannot see. PDF is
|
|
9
|
+
* a terminal format here — there is no PDF-to-Word, because a faithful one does
|
|
10
|
+
* not exist and a bad one silently destroys the document.
|
|
11
|
+
*/
|
|
12
|
+
export declare const docConvertTool: import("./types.js").AnyToolDefinition;
|
|
13
|
+
//# sourceMappingURL=doc-convert.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doc-convert.d.ts","sourceRoot":"","sources":["../../src/tools/doc-convert.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAyCH,eAAO,MAAM,cAAc,wCAqEzB,CAAC"}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `doc_convert` — convert a document between formats.
|
|
3
|
+
*
|
|
4
|
+
* The highest-leverage tool per line of code: "this is the wrong format" is the
|
|
5
|
+
* most common friction a user hits, and one call with two paths solves it. The
|
|
6
|
+
* routing table below is the whole tool.
|
|
7
|
+
*
|
|
8
|
+
* Deliberately excluded: anything lossy in a way the caller cannot see. PDF is
|
|
9
|
+
* a terminal format here — there is no PDF-to-Word, because a faithful one does
|
|
10
|
+
* not exist and a bad one silently destroys the document.
|
|
11
|
+
*/
|
|
12
|
+
import { readFile, stat } from "node:fs/promises";
|
|
13
|
+
import { Workbook, Worksheet } from "documonster/excel";
|
|
14
|
+
import { readCsvFile, writeCsvFile } from "documonster/excel/csv";
|
|
15
|
+
import { calculateFormulas } from "documonster/excel/formula";
|
|
16
|
+
import { Pdf } from "documonster/pdf";
|
|
17
|
+
import { Convert, Io } from "documonster/word";
|
|
18
|
+
import { renderToHtml } from "documonster/word/html";
|
|
19
|
+
import { markdownToDocx, renderToMarkdown } from "documonster/word/markdown";
|
|
20
|
+
import { z } from "zod";
|
|
21
|
+
import { toolError } from "../errors.js";
|
|
22
|
+
import { assertWritable, outputDisplay, resolveInRoot, resolveOutputPath } from "../sandbox.js";
|
|
23
|
+
import { assertNonMacroOutput, requireFormat } from "./document.js";
|
|
24
|
+
import { assertReadableSize, replaceAtomically, writeFileAtomic, writeWithPolicy } from "./fs-helpers.js";
|
|
25
|
+
import { formatBytes, textResult } from "./result.js";
|
|
26
|
+
import { requireSheet, sheetName } from "./spreadsheet.js";
|
|
27
|
+
import { defineTool } from "./types.js";
|
|
28
|
+
/**
|
|
29
|
+
* Supported conversions, as `from -> to[]`.
|
|
30
|
+
*
|
|
31
|
+
* Published to the model in the tool description and used to reject the rest
|
|
32
|
+
* with a message that lists what *is* possible — so an unsupported request
|
|
33
|
+
* costs one turn, not a retry loop.
|
|
34
|
+
*/
|
|
35
|
+
const ROUTES = {
|
|
36
|
+
docx: ["md", "html", "pdf", "txt", "odt"],
|
|
37
|
+
odt: ["docx", "md", "pdf"],
|
|
38
|
+
md: ["docx", "pdf"],
|
|
39
|
+
xlsx: ["csv", "pdf"],
|
|
40
|
+
csv: ["xlsx"]
|
|
41
|
+
};
|
|
42
|
+
export const docConvertTool = defineTool({
|
|
43
|
+
name: "doc_convert",
|
|
44
|
+
group: ["word", "pdf", "excel"],
|
|
45
|
+
title: "Convert a document",
|
|
46
|
+
description: "Convert a document between formats: docx→md/html/pdf/txt/odt, odt→docx/md/pdf, md→docx/pdf, xlsx→csv/pdf, csv→xlsx. The output extension chooses the target. PDF is a terminal format — there is no PDF→Word, because no faithful conversion exists.",
|
|
47
|
+
inputSchema: {
|
|
48
|
+
from: z.string().min(1).describe("Source path, relative to the server root."),
|
|
49
|
+
to: z
|
|
50
|
+
.string()
|
|
51
|
+
.min(1)
|
|
52
|
+
.describe("Destination path below --output-root. Its extension selects the target format; the result is returned as @output/<path>."),
|
|
53
|
+
sheet: z
|
|
54
|
+
.union([z.string(), z.number().int().positive()])
|
|
55
|
+
.optional()
|
|
56
|
+
.describe("xlsx→csv only: which sheet to export. Defaults to the first."),
|
|
57
|
+
overwrite: z
|
|
58
|
+
.boolean()
|
|
59
|
+
.optional()
|
|
60
|
+
.describe("Replace the destination if it exists. Defaults to false.")
|
|
61
|
+
},
|
|
62
|
+
annotations: {
|
|
63
|
+
readOnlyHint: false,
|
|
64
|
+
destructiveHint: false,
|
|
65
|
+
idempotentHint: true,
|
|
66
|
+
openWorldHint: false
|
|
67
|
+
},
|
|
68
|
+
mutates: true,
|
|
69
|
+
handler: async (args, context) => {
|
|
70
|
+
const { config } = context;
|
|
71
|
+
assertWritable(config);
|
|
72
|
+
const source = await resolveInRoot(config, args.from, { mustExist: true });
|
|
73
|
+
await assertReadableSize(config, source, args.from);
|
|
74
|
+
const target = await resolveOutputPath(config, args.to);
|
|
75
|
+
const fromFormat = requireFormat(args.from, "from");
|
|
76
|
+
const toFormat = requireFormat(args.to, "to");
|
|
77
|
+
assertNonMacroOutput(args.to);
|
|
78
|
+
const allowed = ROUTES[fromFormat];
|
|
79
|
+
if (allowed === undefined || !allowed.includes(toFormat)) {
|
|
80
|
+
throw toolError.unsupported(`cannot convert ${fromFormat} to ${toFormat}`, allowed === undefined
|
|
81
|
+
? `Nothing converts from ${fromFormat}. Supported sources: ${Object.keys(ROUTES).join(", ")}.`
|
|
82
|
+
: `From ${fromFormat} you can produce: ${allowed.join(", ")}.`);
|
|
83
|
+
}
|
|
84
|
+
let note = [];
|
|
85
|
+
await writeWithPolicy(target, args.overwrite === true, async (temporary) => {
|
|
86
|
+
note = await convert(fromFormat, toFormat, source, temporary, args);
|
|
87
|
+
});
|
|
88
|
+
const size = (await stat(target)).size;
|
|
89
|
+
return textResult(config, [
|
|
90
|
+
`Converted **${args.from}** → **${outputDisplay(args.to)}** (${fromFormat} → ${toFormat}, ${formatBytes(size)}).`,
|
|
91
|
+
...note,
|
|
92
|
+
"",
|
|
93
|
+
toFormat === "pdf" || toFormat === "html"
|
|
94
|
+
? "Verify by opening it, or read the source back — this tool cannot read its own PDF output structurally."
|
|
95
|
+
: "Read it back with doc_read or sheet_read to verify."
|
|
96
|
+
].join("\n"));
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
/** Perform one conversion, returning notes worth telling the caller. */
|
|
100
|
+
async function convert(from, to, source, target, args) {
|
|
101
|
+
if (from === "docx") {
|
|
102
|
+
const doc = await readWord(source);
|
|
103
|
+
switch (to) {
|
|
104
|
+
case "md":
|
|
105
|
+
await writeFileAtomic(target, renderToMarkdown(doc));
|
|
106
|
+
return ["- headings, lists and tables preserved as Markdown"];
|
|
107
|
+
case "html": {
|
|
108
|
+
// renderToHtml returns { html, warnings, images } — not a string.
|
|
109
|
+
const rendered = renderToHtml(doc);
|
|
110
|
+
await writeFileAtomic(target, rendered.html);
|
|
111
|
+
return rendered.warnings.length > 0
|
|
112
|
+
? [
|
|
113
|
+
`- ${rendered.warnings.length} rendering warning(s): ${rendered.warnings.slice(0, 3).join("; ")}`
|
|
114
|
+
]
|
|
115
|
+
: ["- semantic HTML5 with inline styles"];
|
|
116
|
+
}
|
|
117
|
+
case "txt": {
|
|
118
|
+
const { Query } = await import("documonster/word");
|
|
119
|
+
await writeFileAtomic(target, Query.extractText(doc));
|
|
120
|
+
return ["- **formatting discarded** — plain text only"];
|
|
121
|
+
}
|
|
122
|
+
case "pdf": {
|
|
123
|
+
await writeFileAtomic(target, await Pdf.fromDocx(doc));
|
|
124
|
+
return ["- paginated by the Word layout engine, so page breaks are real"];
|
|
125
|
+
}
|
|
126
|
+
case "odt": {
|
|
127
|
+
await writeFileAtomic(target, await Convert.writeOdt(doc));
|
|
128
|
+
return ["- OpenDocument Text, readable by LibreOffice and Word"];
|
|
129
|
+
}
|
|
130
|
+
default:
|
|
131
|
+
throw unreachable(from, to);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (from === "odt") {
|
|
135
|
+
const doc = await Convert.readOdt(new Uint8Array(await readFile(source))).catch((cause) => {
|
|
136
|
+
throw toolError.unsupported("could not read the source as an OpenDocument Text file", "Run doc_inspect to confirm the file type.", { cause });
|
|
137
|
+
});
|
|
138
|
+
if (to === "docx") {
|
|
139
|
+
await replaceAtomically(target, temporary => Io.writeFile(doc, temporary));
|
|
140
|
+
return ["- OpenDocument mapped to WordprocessingML"];
|
|
141
|
+
}
|
|
142
|
+
if (to === "md") {
|
|
143
|
+
await writeFileAtomic(target, renderToMarkdown(doc));
|
|
144
|
+
return ["- structure preserved as Markdown"];
|
|
145
|
+
}
|
|
146
|
+
if (to === "pdf") {
|
|
147
|
+
await writeFileAtomic(target, await Pdf.fromDocx(doc));
|
|
148
|
+
return ["- rendered via the Word layout engine"];
|
|
149
|
+
}
|
|
150
|
+
throw unreachable(from, to);
|
|
151
|
+
}
|
|
152
|
+
if (from === "md") {
|
|
153
|
+
const markdown = await readFile(source, "utf8");
|
|
154
|
+
const doc = await markdownToDocx(markdown);
|
|
155
|
+
if (to === "docx") {
|
|
156
|
+
await replaceAtomically(target, temporary => Io.writeFile(doc, temporary));
|
|
157
|
+
return ["- Markdown structure mapped to Word styles"];
|
|
158
|
+
}
|
|
159
|
+
if (to === "pdf") {
|
|
160
|
+
await writeFileAtomic(target, await Pdf.fromDocx(doc));
|
|
161
|
+
return ["- rendered via Word layout, so pagination is real"];
|
|
162
|
+
}
|
|
163
|
+
throw unreachable(from, to);
|
|
164
|
+
}
|
|
165
|
+
if (from === "xlsx") {
|
|
166
|
+
const wb = Workbook.create();
|
|
167
|
+
await Workbook.readFile(wb, source).catch((cause) => {
|
|
168
|
+
throw toolError.unsupported(`could not read the source as a workbook`, "Run doc_inspect to confirm the file type.", { cause });
|
|
169
|
+
});
|
|
170
|
+
if (to === "csv") {
|
|
171
|
+
// writeCsvFile takes the workbook and selects the sheet by name — passing
|
|
172
|
+
// a worksheet handle does not type-check and would not work.
|
|
173
|
+
const ws = requireSheet(wb, args.sheet);
|
|
174
|
+
await replaceAtomically(target, temporary => writeCsvFile(wb, temporary, { sheetName: sheetName(ws) }));
|
|
175
|
+
return [
|
|
176
|
+
`- exported sheet ${JSON.stringify(sheetName(ws))} of ${Workbook.getWorksheets(wb).length}`,
|
|
177
|
+
"- **only one sheet** — CSV has no concept of multiple sheets",
|
|
178
|
+
"- formulas exported as their cached values"
|
|
179
|
+
];
|
|
180
|
+
}
|
|
181
|
+
if (to === "pdf") {
|
|
182
|
+
// Inject the calculation engine so stale cached values are not printed.
|
|
183
|
+
await writeFileAtomic(target, await Pdf.fromExcel(wb, { recalculate: calculateFormulas }));
|
|
184
|
+
return [
|
|
185
|
+
`- all ${Workbook.getWorksheets(wb).length} sheet(s) rendered, honouring each sheet's print setup`,
|
|
186
|
+
"- formulas recalculated before rendering"
|
|
187
|
+
];
|
|
188
|
+
}
|
|
189
|
+
throw unreachable(from, to);
|
|
190
|
+
}
|
|
191
|
+
if (from === "csv" && to === "xlsx") {
|
|
192
|
+
const wb = Workbook.create();
|
|
193
|
+
const ws = await readCsvFile(wb, source);
|
|
194
|
+
Worksheet.setModel(ws, { ...Worksheet.getModel(ws), name: "Sheet1" });
|
|
195
|
+
await replaceAtomically(target, temporary => Workbook.writeFile(wb, temporary));
|
|
196
|
+
return [`- ${Worksheet.actualRowCount(ws)} row(s) imported into sheet "Sheet1"`];
|
|
197
|
+
}
|
|
198
|
+
throw unreachable(from, to);
|
|
199
|
+
}
|
|
200
|
+
async function readWord(source) {
|
|
201
|
+
return await Io.readFile(source).catch((cause) => {
|
|
202
|
+
throw toolError.unsupported("could not read the source as a Word document", "A CFB container is either a legacy .doc or an encrypted .docx; neither is supported here. Run doc_inspect.", { cause });
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
/** The route table and the switch cannot disagree, but say so if they do. */
|
|
206
|
+
function unreachable(from, to) {
|
|
207
|
+
return toolError.unsupported(`conversion ${from} → ${to} is listed as supported but not implemented`, "This is a server bug; report it.");
|
|
208
|
+
}
|
|
209
|
+
//# sourceMappingURL=doc-convert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doc-convert.js","sourceRoot":"","sources":["../../src/tools/doc-convert.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAChG,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAkB,MAAM,eAAe,CAAC;AACpF,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,eAAe,EAChB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC3D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AK,KAAK,IAAI,EAAE,KAAK,MAAM,EAAE,CAAC;QACpC,MAAM,EAAE,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC;QAC7B,MAAM,EAAE,GAAG,MAAM,WAAW,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;QACzC,SAAS,CAAC,QAAQ,CAAC,EAAE,EAAE,EAAE,GAAG,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;QACtE,MAAM,iBAAiB,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC;QAChF,OAAO,CAAC,KAAK,SAAS,CAAC,cAAc,CAAC,EAAE,CAAC,sCAAsC,CAAC,CAAC;IACnF,CAAC;IAED,MAAM,WAAW,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AAC9B,CAAC;AAED,KAAK,UAAU,QAAQ,CAAC,MAAc;IACpC,OAAO,MAAM,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;QACxD,MAAM,SAAS,CAAC,WAAW,CACzB,8CAA8C,EAC9C,4GAA4G,EAC5G,EAAE,KAAK,EAAE,CACV,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAED,6EAA6E;AAC7E,SAAS,WAAW,CAAC,IAAe,EAAE,EAAa;IACjD,OAAO,SAAS,CAAC,WAAW,CAC1B,cAAc,IAAI,MAAM,EAAE,6CAA6C,EACvE,kCAAkC,CACnC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `doc_paginate` — compute a Word document's real page layout.
|
|
3
|
+
*
|
|
4
|
+
* The capability nothing else here can substitute for. "How many pages is this?"
|
|
5
|
+
* and "which page is that heading on?" normally require Microsoft Word: the
|
|
6
|
+
* answer depends on line breaking, font metrics, widow/orphan control and table
|
|
7
|
+
* cell heights. This runs the layout engine and answers without Office
|
|
8
|
+
* installed, and without a rasteriser.
|
|
9
|
+
*
|
|
10
|
+
* It also updates computed field values — PAGE, NUMPAGES, PAGEREF, TOC entries —
|
|
11
|
+
* which otherwise only refresh when a human presses F9 in Word.
|
|
12
|
+
*/
|
|
13
|
+
export declare const docPaginateTool: import("./types.js").AnyToolDefinition;
|
|
14
|
+
//# sourceMappingURL=doc-paginate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doc-paginate.d.ts","sourceRoot":"","sources":["../../src/tools/doc-paginate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAuBH,eAAO,MAAM,eAAe,wCAkI1B,CAAC"}
|