@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.
Files changed (127) hide show
  1. package/LICENSE +205 -0
  2. package/README.md +253 -0
  3. package/dist/capabilities.d.ts +29 -0
  4. package/dist/capabilities.d.ts.map +1 -0
  5. package/dist/capabilities.js +188 -0
  6. package/dist/capabilities.js.map +1 -0
  7. package/dist/cli.d.ts +13 -0
  8. package/dist/cli.d.ts.map +1 -0
  9. package/dist/cli.js +64 -0
  10. package/dist/cli.js.map +1 -0
  11. package/dist/config.d.ts +65 -0
  12. package/dist/config.d.ts.map +1 -0
  13. package/dist/config.js +189 -0
  14. package/dist/config.js.map +1 -0
  15. package/dist/errors.d.ts +66 -0
  16. package/dist/errors.d.ts.map +1 -0
  17. package/dist/errors.js +96 -0
  18. package/dist/errors.js.map +1 -0
  19. package/dist/index.d.ts +25 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +20 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/sandbox.d.ts +86 -0
  24. package/dist/sandbox.d.ts.map +1 -0
  25. package/dist/sandbox.js +224 -0
  26. package/dist/sandbox.js.map +1 -0
  27. package/dist/server.d.ts +22 -0
  28. package/dist/server.d.ts.map +1 -0
  29. package/dist/server.js +66 -0
  30. package/dist/server.js.map +1 -0
  31. package/dist/tools/archive-read.d.ts +31 -0
  32. package/dist/tools/archive-read.d.ts.map +1 -0
  33. package/dist/tools/archive-read.js +315 -0
  34. package/dist/tools/archive-read.js.map +1 -0
  35. package/dist/tools/archive-write.d.ts +9 -0
  36. package/dist/tools/archive-write.d.ts.map +1 -0
  37. package/dist/tools/archive-write.js +219 -0
  38. package/dist/tools/archive-write.js.map +1 -0
  39. package/dist/tools/chart.d.ts +93 -0
  40. package/dist/tools/chart.d.ts.map +1 -0
  41. package/dist/tools/chart.js +263 -0
  42. package/dist/tools/chart.js.map +1 -0
  43. package/dist/tools/doc-convert.d.ts +13 -0
  44. package/dist/tools/doc-convert.d.ts.map +1 -0
  45. package/dist/tools/doc-convert.js +209 -0
  46. package/dist/tools/doc-convert.js.map +1 -0
  47. package/dist/tools/doc-paginate.d.ts +14 -0
  48. package/dist/tools/doc-paginate.d.ts.map +1 -0
  49. package/dist/tools/doc-paginate.js +153 -0
  50. package/dist/tools/doc-paginate.js.map +1 -0
  51. package/dist/tools/doc-read.d.ts +14 -0
  52. package/dist/tools/doc-read.d.ts.map +1 -0
  53. package/dist/tools/doc-read.js +175 -0
  54. package/dist/tools/doc-read.js.map +1 -0
  55. package/dist/tools/doc-review.d.ts +17 -0
  56. package/dist/tools/doc-review.d.ts.map +1 -0
  57. package/dist/tools/doc-review.js +249 -0
  58. package/dist/tools/doc-review.js.map +1 -0
  59. package/dist/tools/doc-search.d.ts +20 -0
  60. package/dist/tools/doc-search.d.ts.map +1 -0
  61. package/dist/tools/doc-search.js +268 -0
  62. package/dist/tools/doc-search.js.map +1 -0
  63. package/dist/tools/doc-write.d.ts +11 -0
  64. package/dist/tools/doc-write.d.ts.map +1 -0
  65. package/dist/tools/doc-write.js +81 -0
  66. package/dist/tools/doc-write.js.map +1 -0
  67. package/dist/tools/document.d.ts +74 -0
  68. package/dist/tools/document.d.ts.map +1 -0
  69. package/dist/tools/document.js +157 -0
  70. package/dist/tools/document.js.map +1 -0
  71. package/dist/tools/form-fill.d.ts +20 -0
  72. package/dist/tools/form-fill.d.ts.map +1 -0
  73. package/dist/tools/form-fill.js +270 -0
  74. package/dist/tools/form-fill.js.map +1 -0
  75. package/dist/tools/formula-evaluate.d.ts +14 -0
  76. package/dist/tools/formula-evaluate.d.ts.map +1 -0
  77. package/dist/tools/formula-evaluate.js +192 -0
  78. package/dist/tools/formula-evaluate.js.map +1 -0
  79. package/dist/tools/fs-helpers.d.ts +106 -0
  80. package/dist/tools/fs-helpers.d.ts.map +1 -0
  81. package/dist/tools/fs-helpers.js +257 -0
  82. package/dist/tools/fs-helpers.js.map +1 -0
  83. package/dist/tools/help.d.ts +227 -0
  84. package/dist/tools/help.d.ts.map +1 -0
  85. package/dist/tools/help.js +262 -0
  86. package/dist/tools/help.js.map +1 -0
  87. package/dist/tools/index.d.ts +33 -0
  88. package/dist/tools/index.d.ts.map +1 -0
  89. package/dist/tools/index.js +78 -0
  90. package/dist/tools/index.js.map +1 -0
  91. package/dist/tools/inspect.d.ts +14 -0
  92. package/dist/tools/inspect.d.ts.map +1 -0
  93. package/dist/tools/inspect.js +463 -0
  94. package/dist/tools/inspect.js.map +1 -0
  95. package/dist/tools/pdf-edit.d.ts +26 -0
  96. package/dist/tools/pdf-edit.d.ts.map +1 -0
  97. package/dist/tools/pdf-edit.js +390 -0
  98. package/dist/tools/pdf-edit.js.map +1 -0
  99. package/dist/tools/result.d.ts +25 -0
  100. package/dist/tools/result.d.ts.map +1 -0
  101. package/dist/tools/result.js +43 -0
  102. package/dist/tools/result.js.map +1 -0
  103. package/dist/tools/sheet-edit.d.ts +16 -0
  104. package/dist/tools/sheet-edit.d.ts.map +1 -0
  105. package/dist/tools/sheet-edit.js +325 -0
  106. package/dist/tools/sheet-edit.js.map +1 -0
  107. package/dist/tools/sheet-read.d.ts +10 -0
  108. package/dist/tools/sheet-read.d.ts.map +1 -0
  109. package/dist/tools/sheet-read.js +139 -0
  110. package/dist/tools/sheet-read.js.map +1 -0
  111. package/dist/tools/sheet-write.d.ts +15 -0
  112. package/dist/tools/sheet-write.d.ts.map +1 -0
  113. package/dist/tools/sheet-write.js +290 -0
  114. package/dist/tools/sheet-write.js.map +1 -0
  115. package/dist/tools/spreadsheet.d.ts +100 -0
  116. package/dist/tools/spreadsheet.d.ts.map +1 -0
  117. package/dist/tools/spreadsheet.js +210 -0
  118. package/dist/tools/spreadsheet.js.map +1 -0
  119. package/dist/tools/template.d.ts +18 -0
  120. package/dist/tools/template.d.ts.map +1 -0
  121. package/dist/tools/template.js +209 -0
  122. package/dist/tools/template.js.map +1 -0
  123. package/dist/tools/types.d.ts +79 -0
  124. package/dist/tools/types.d.ts.map +1 -0
  125. package/dist/tools/types.js +18 -0
  126. package/dist/tools/types.js.map +1 -0
  127. package/package.json +74 -0
@@ -0,0 +1,290 @@
1
+ /**
2
+ * `sheet_write` — create a workbook from a declarative spec.
3
+ *
4
+ * Declarative rather than incremental for two reasons. A model driving twenty
5
+ * `set_cell` calls burns twenty round trips and has to hold the intermediate
6
+ * state; and `fromCsv` lets a source file be referenced by path so the rows
7
+ * never pass through the model's context at all — which is the difference
8
+ * between summarising three 4000-row CSVs and running out of budget trying.
9
+ *
10
+ * The schema is deliberately shallow. Every field here is sent to the model on
11
+ * every request, so styling is limited to the handful of options that actually
12
+ * change a report's usefulness; the deep option trees stay in `documonster_help`.
13
+ */
14
+ import { Cell, Workbook, Worksheet } from "documonster/excel";
15
+ import { readCsvFile } from "documonster/excel/csv";
16
+ import { calculateFormulas } from "documonster/excel/formula";
17
+ import { z } from "zod";
18
+ import { toolError } from "../errors.js";
19
+ import { assertWritable, outputDisplay, resolveInRoot, resolveOutputPath } from "../sandbox.js";
20
+ import { addChart, chartSchema, generateSchema, writeGenerated } from "./chart.js";
21
+ import { assertNonMacroOutput } from "./document.js";
22
+ import { writeWithPolicy } from "./fs-helpers.js";
23
+ import { textResult } from "./result.js";
24
+ import { normalizeFormula, parseRange, toArgb } from "./spreadsheet.js";
25
+ import { defineTool } from "./types.js";
26
+ /** A single cell value in `rows`. `null` writes a blank. */
27
+ const cellValueSchema = z.union([z.string(), z.number(), z.boolean(), z.null()]);
28
+ const styleSchema = z
29
+ .object({
30
+ bold: z.boolean().optional(),
31
+ italic: z.boolean().optional(),
32
+ fontColor: z.string().optional().describe('Hex RGB without "#", e.g. "C00000".'),
33
+ fillColor: z
34
+ .string()
35
+ .optional()
36
+ .describe('Solid background, hex RGB without "#", e.g. "FFEB3B".'),
37
+ numFmt: z
38
+ .string()
39
+ .optional()
40
+ .describe('Excel number format, e.g. "#,##0.00" or "0.0%" or "yyyy-mm-dd".')
41
+ })
42
+ .describe("Formatting applied to a range.");
43
+ const sheetSchema = z.object({
44
+ name: z.string().min(1).max(31).describe("Sheet name (Excel allows at most 31 characters)."),
45
+ fromCsv: z
46
+ .string()
47
+ .optional()
48
+ .describe("Path to a CSV to load as this sheet's contents, resolved on the server. Prefer this over `rows` for existing data: the rows never enter your context."),
49
+ csvDelimiter: z
50
+ .string()
51
+ .length(1)
52
+ .optional()
53
+ .describe("Delimiter for fromCsv. Omit to use a comma; doc_inspect reports the real one."),
54
+ generate: generateSchema
55
+ .optional()
56
+ .describe("Generate synthetic rows server-side instead of supplying them. Use this for test data — a few lines of column definitions beat emitting thousands of rows yourself."),
57
+ rows: z
58
+ .array(z.array(cellValueSchema))
59
+ .optional()
60
+ .describe("Row-major literal data, written from A1. Combine with fromCsv only if you mean to overwrite."),
61
+ cells: z
62
+ .record(z.string(), cellValueSchema)
63
+ .optional()
64
+ .describe('Individual cells by address, e.g. { "D1": "Total" }. Applied after rows.'),
65
+ formulas: z
66
+ .record(z.string(), z.string())
67
+ .optional()
68
+ .describe('Formulas by address, e.g. { "B10": "=SUM(B2:B9)" }. A leading "=" is optional. Cross-sheet references work.'),
69
+ columnWidths: z
70
+ .array(z.number().positive())
71
+ .optional()
72
+ .describe("Column widths in characters, left to right."),
73
+ freezeRows: z
74
+ .number()
75
+ .int()
76
+ .nonnegative()
77
+ .optional()
78
+ .describe("Freeze this many top rows — use 1 when row 1 is a header."),
79
+ merges: z.array(z.string()).optional().describe('Ranges to merge, e.g. ["A1:D1"].'),
80
+ styles: z
81
+ .array(z.object({ range: z.string(), style: styleSchema }))
82
+ .optional()
83
+ .describe('Formatting per range, e.g. [{ range: "A1:D1", style: { bold: true } }].'),
84
+ charts: z
85
+ .array(chartSchema)
86
+ .optional()
87
+ .describe("Charts to place on this sheet. Ranges are plain A1 — the sheet qualification is added for you.")
88
+ });
89
+ export const sheetWriteTool = defineTool({
90
+ name: "sheet_write",
91
+ group: "excel",
92
+ title: "Write a spreadsheet",
93
+ description: "Create an .xlsx from a declarative spec: one call describes every sheet, its data, formulas, widths, freeze panes, merges and formatting. Use `fromCsv` to pull existing data in server-side instead of copying rows through your reply. Formulas are evaluated before saving unless recalculate is false.",
94
+ inputSchema: {
95
+ path: z
96
+ .string()
97
+ .min(1)
98
+ .describe("Output .xlsx path below --output-root; returned as @output/<path>."),
99
+ sheets: z.array(sheetSchema).min(1).describe("One entry per worksheet, in order."),
100
+ overwrite: z
101
+ .boolean()
102
+ .optional()
103
+ .describe("Replace the file if it already exists. Defaults to false so existing work is never lost silently."),
104
+ recalculate: z
105
+ .boolean()
106
+ .optional()
107
+ .describe("Evaluate formulas and store their results so other tools can read values. Defaults to true.")
108
+ },
109
+ annotations: {
110
+ readOnlyHint: false,
111
+ destructiveHint: false,
112
+ idempotentHint: false,
113
+ openWorldHint: false
114
+ },
115
+ mutates: true,
116
+ handler: async (args, context) => {
117
+ const { config } = context;
118
+ assertWritable(config);
119
+ assertNonMacroOutput(args.path);
120
+ const target = await resolveOutputPath(config, args.path);
121
+ for (const sheet of args.sheets) {
122
+ assertLegalSheetName(sheet.name);
123
+ }
124
+ assertUniqueNames(args.sheets.map(sheet => sheet.name));
125
+ const wb = Workbook.create();
126
+ const report = [];
127
+ for (const spec of args.sheets) {
128
+ const ws = await buildSheet(wb, spec, config, report);
129
+ applyLayout(ws, spec, report);
130
+ }
131
+ const recalculate = args.recalculate ?? true;
132
+ let formulaNote = "formulas not evaluated (recalculate: false)";
133
+ if (recalculate) {
134
+ try {
135
+ calculateFormulas(wb);
136
+ formulaNote = "formulas evaluated";
137
+ }
138
+ catch (cause) {
139
+ // A bad formula must not lose the whole document — save it and say so,
140
+ // which leaves the model a file it can inspect and repair.
141
+ formulaNote = `formula evaluation failed: ${cause instanceof Error ? cause.message : String(cause)}`;
142
+ }
143
+ }
144
+ // Written to a sibling and renamed, so a failure part-way through cannot
145
+ // leave a truncated workbook where a valid one used to be. `ensureParent`
146
+ // is handled by the atomic writer, since a model writes "out/report.xlsx"
147
+ // without checking that "out" exists.
148
+ await writeWithPolicy(target, args.overwrite === true, temporary => Workbook.writeFile(wb, temporary));
149
+ return textResult(config, [
150
+ `Wrote **${outputDisplay(args.path)}** (${args.sheets.length} sheet(s)): ${args.sheets.map(sheet => JSON.stringify(sheet.name)).join(", ")}`,
151
+ `- ${formulaNote}`,
152
+ ...report,
153
+ "",
154
+ "Read the returned @output path with sheet_read to verify before reporting success."
155
+ ].join("\n"));
156
+ }
157
+ });
158
+ /** Create one worksheet and fill it from CSV and/or literal data. */
159
+ async function buildSheet(wb, spec, config, report) {
160
+ let ws;
161
+ if (spec.fromCsv !== undefined) {
162
+ const source = await resolveInRoot(config, spec.fromCsv, { mustExist: true });
163
+ // readCsvFile appends a new sheet named after the file, so rename it to the
164
+ // requested name afterwards rather than creating a second, empty sheet.
165
+ ws = await readCsvFile(wb, source, spec.csvDelimiter === undefined ? undefined : { delimiter: spec.csvDelimiter });
166
+ Worksheet.setModel(ws, { ...Worksheet.getModel(ws), name: spec.name });
167
+ report.push(`- sheet ${JSON.stringify(spec.name)}: loaded ${Worksheet.actualRowCount(ws)} row(s) from ${spec.fromCsv} server-side`);
168
+ }
169
+ else {
170
+ ws = Workbook.addWorksheet(wb, spec.name);
171
+ }
172
+ if (spec.generate !== undefined) {
173
+ report.push(`- sheet ${JSON.stringify(spec.name)}: ${writeGenerated(ws, spec.generate)}`);
174
+ }
175
+ if (spec.rows !== undefined && spec.rows.length > 0) {
176
+ // addAoa intentionally skips nulls, which is useful for sparse imports but
177
+ // violates this schema's "null writes a blank" contract when rows overlay
178
+ // fromCsv/generated data. Write the matrix explicitly so null clears the
179
+ // previous value.
180
+ for (const [rowOffset, row] of spec.rows.entries()) {
181
+ for (const [columnOffset, value] of row.entries()) {
182
+ Cell.setValue(ws, rowOffset + 1, columnOffset + 1, value);
183
+ }
184
+ }
185
+ }
186
+ for (const [address, value] of Object.entries(spec.cells ?? {})) {
187
+ Cell.setValue(ws, normalizeAddress(address), value);
188
+ }
189
+ for (const [address, formula] of Object.entries(spec.formulas ?? {})) {
190
+ // Strip the leading "=" — the core stores formula text without it, and
191
+ // leaving it in makes every function resolve to #NAME?.
192
+ Cell.setValue(ws, normalizeAddress(address), { formula: normalizeFormula(formula) });
193
+ }
194
+ return ws;
195
+ }
196
+ /** Apply widths, freeze panes, merges and styles. */
197
+ function applyLayout(ws, spec, report) {
198
+ if (spec.columnWidths !== undefined && spec.columnWidths.length > 0) {
199
+ Worksheet.setColumns(ws, spec.columnWidths.map(width => ({ width })));
200
+ }
201
+ if (spec.freezeRows !== undefined && spec.freezeRows > 0) {
202
+ ws.views = [{ state: "frozen", ySplit: spec.freezeRows }];
203
+ }
204
+ for (const range of spec.merges ?? []) {
205
+ try {
206
+ Worksheet.merge(ws, range);
207
+ }
208
+ catch (cause) {
209
+ throw toolError.invalidInput(`could not merge ${JSON.stringify(range)} on sheet ${JSON.stringify(spec.name)}`, "Merges must not overlap each other.", { cause });
210
+ }
211
+ }
212
+ for (const entry of spec.styles ?? []) {
213
+ applyStyle(ws, entry.range, entry.style);
214
+ }
215
+ // Charts last, so a default anchor sees the sheet's final used area.
216
+ for (const chart of spec.charts ?? []) {
217
+ report.push(`- sheet ${JSON.stringify(spec.name)}: ${addChart(ws, chart)}`);
218
+ }
219
+ }
220
+ /**
221
+ * Cells one `styles` entry may touch.
222
+ *
223
+ * Styling is applied cell by cell, so an unbounded range like `A1:XFD1048576`
224
+ * would hang the server. A model that wants a whole-column look can restrict
225
+ * itself to the rows that actually hold data.
226
+ */
227
+ const MAX_STYLED_CELLS = 100_000;
228
+ /** Apply one style to every cell of a range. */
229
+ function applyStyle(ws, range, style) {
230
+ const window = parseRange(range);
231
+ const cells = (window.bottom - window.top + 1) * (window.right - window.left + 1);
232
+ if (cells > MAX_STYLED_CELLS) {
233
+ throw toolError.tooLarge(`style range ${JSON.stringify(range)} covers ${cells} cells, over the ${MAX_STYLED_CELLS} limit`, "Style only the rows that hold data, e.g. the header row plus the populated range.");
234
+ }
235
+ for (let row = window.top; row <= window.bottom; row += 1) {
236
+ for (let column = window.left; column <= window.right; column += 1) {
237
+ if (style.bold !== undefined || style.italic !== undefined || style.fontColor !== undefined) {
238
+ Cell.setFont(ws, row, column, {
239
+ ...(Cell.getFont(ws, row, column) ?? {}),
240
+ ...(style.bold === undefined ? {} : { bold: style.bold }),
241
+ ...(style.italic === undefined ? {} : { italic: style.italic }),
242
+ ...(style.fontColor === undefined ? {} : { color: { argb: toArgb(style.fontColor) } })
243
+ });
244
+ }
245
+ if (style.fillColor !== undefined) {
246
+ Cell.setFill(ws, row, column, {
247
+ type: "pattern",
248
+ pattern: "solid",
249
+ fgColor: { argb: toArgb(style.fillColor) }
250
+ });
251
+ }
252
+ if (style.numFmt !== undefined) {
253
+ Cell.setNumFmt(ws, row, column, style.numFmt);
254
+ }
255
+ }
256
+ }
257
+ }
258
+ function normalizeAddress(address) {
259
+ const upper = address.trim().toUpperCase();
260
+ if (!/^[A-Z]{1,3}[1-9][0-9]*$/.test(upper)) {
261
+ throw toolError.invalidInput(`${JSON.stringify(address)} is not a cell address`, 'Use A1 notation for a single cell, e.g. "B10".');
262
+ }
263
+ return upper;
264
+ }
265
+ /**
266
+ * Characters Excel forbids in a sheet name.
267
+ *
268
+ * Writing one produces a package Excel refuses to open, which the model would
269
+ * see as a mysterious "corrupt file" much later — so reject it at the source.
270
+ */
271
+ const ILLEGAL_SHEET_NAME = /[[\]:*?/\\]/;
272
+ function assertLegalSheetName(name) {
273
+ if (ILLEGAL_SHEET_NAME.test(name)) {
274
+ throw toolError.invalidInput(`sheet name ${JSON.stringify(name)} contains a character Excel forbids`, "Sheet names may not contain any of : \\ / ? * [ ]");
275
+ }
276
+ if (name.startsWith("'") || name.endsWith("'")) {
277
+ throw toolError.invalidInput(`sheet name ${JSON.stringify(name)} may not start or end with an apostrophe`);
278
+ }
279
+ }
280
+ function assertUniqueNames(names) {
281
+ const seen = new Set();
282
+ for (const name of names) {
283
+ const key = name.toLowerCase();
284
+ if (seen.has(key)) {
285
+ throw toolError.invalidInput(`duplicate sheet name ${JSON.stringify(name)}`, "Excel sheet names must be unique, ignoring case.");
286
+ }
287
+ seen.add(key);
288
+ }
289
+ }
290
+ //# sourceMappingURL=sheet-write.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sheet-write.js","sourceRoot":"","sources":["../../src/tools/sheet-write.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAChG,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACnF,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACL,gBAAgB,EAChB,UAAU,EACV,MAAM,EAIP,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,4DAA4D;AAC5D,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;AAEjF,MAAM,WAAW,GAAG,CAAC;KAClB,MAAM,C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GAAG,CAAC,EAAE,CAAC;QAC/C,MAAM,SAAS,CAAC,YAAY,CAC1B,cAAc,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,0CAA0C,CAC7E,CAAC;IACJ,CAAC;AACH,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAwB;IACjD,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QAC/B,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAClB,MAAM,SAAS,CAAC,YAAY,CAC1B,wBAAwB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,EAC9C,kDAAkD,CACnD,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAChB,CAAC;AACH,CAAC"}
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Shared spreadsheet helpers.
3
+ *
4
+ * Three concerns that every spreadsheet tool needs and must not re-derive:
5
+ * grid geometry, formula normalization, and rendering a grid as a table a model
6
+ * can address by cell reference.
7
+ */
8
+ import { Workbook } from "documonster/excel";
9
+ /** A workbook handle, as the public API hands it back. */
10
+ export type WorkbookHandle = ReturnType<typeof Workbook.create>;
11
+ /** A worksheet handle. */
12
+ export type SheetHandle = ReturnType<typeof Workbook.addWorksheet>;
13
+ /** 1-based inclusive grid window, matching `Worksheet.dimensions`. */
14
+ export interface GridWindow {
15
+ readonly top: number;
16
+ readonly left: number;
17
+ readonly bottom: number;
18
+ readonly right: number;
19
+ }
20
+ /** Excel worksheet limits (ECMA-376 / modern Excel). */
21
+ export declare const MAX_EXCEL_ROWS = 1048576;
22
+ export declare const MAX_EXCEL_COLUMNS = 16384;
23
+ /**
24
+ * Read a worksheet's name.
25
+ *
26
+ * The handle has no public `name` property — `ws.name` is `undefined` — so the
27
+ * model record is the only public route. Verified empirically; do not "simplify"
28
+ * this to `ws.name`.
29
+ */
30
+ export declare function sheetName(ws: SheetHandle): string;
31
+ /** Every worksheet name in workbook order. */
32
+ export declare function sheetNames(wb: WorkbookHandle): string[];
33
+ /**
34
+ * Resolve a sheet by name or 1-based index, failing with a list of what does
35
+ * exist — a model that picked the wrong name can then correct itself in one
36
+ * step instead of guessing again.
37
+ */
38
+ export declare function requireSheet(wb: WorkbookHandle, sheet: string | number | undefined): SheetHandle;
39
+ /**
40
+ * Parse an A1 range into a 1-based window.
41
+ *
42
+ * `Address.decodeRange` returns 0-based `{ s, e }`; `Worksheet.dimensions`
43
+ * returns 1-based `{ top, left, bottom, right }`. Mixing the two is the easiest
44
+ * off-by-one in this package, so the conversion happens exactly here.
45
+ */
46
+ export declare function parseRange(range: string): GridWindow;
47
+ /**
48
+ * The used area of a sheet, as a 1-based window. Empty sheets yield `undefined`.
49
+ *
50
+ * An empty sheet reports `{ top: 0, left: 0, bottom: 0, right: 0 }` — verified
51
+ * empirically, both freshly created and after a file round-trip. That satisfies
52
+ * `bottom >= top`, so checking only for an inverted rectangle lets zeroes through
53
+ * and the first `columnLetter(0)` then throws `ColumnOutOfBoundsError`. Hence the
54
+ * explicit `>= 1` checks.
55
+ */
56
+ export declare function usedWindow(ws: SheetHandle): GridWindow | undefined;
57
+ /**
58
+ * Strip a leading `=` from a formula.
59
+ *
60
+ * Essential, not cosmetic: the core stores formula text WITHOUT the `=`, and
61
+ * passing `"=SUM(A1:A2)"` makes every function resolve to `#NAME?` — including
62
+ * plain arithmetic, so the failure does not even look like a formula problem.
63
+ * Verified empirically. A model will always write the Excel-looking form with
64
+ * the `=`, so normalizing here is what makes the tools usable at all.
65
+ */
66
+ export declare function normalizeFormula(formula: string): string;
67
+ /** Column letter for a 1-based column index. */
68
+ export declare function columnLetter(column: number): string;
69
+ /** `"B7"` for 1-based row/column. */
70
+ export declare function cellRef(row: number, column: number): string;
71
+ /** How a cell should be rendered into the output table. */
72
+ export type CellMode = "values" | "formulas" | "both";
73
+ /**
74
+ * Render one cell as table text.
75
+ *
76
+ * Uses `Cell.getDisplayText`, which applies the cell's number format — so a
77
+ * currency cell reads `1,234.50` rather than `1234.5`, matching what the user
78
+ * sees in Excel and what they will quote back to the model.
79
+ */
80
+ export declare function renderCell(ws: SheetHandle, row: number, column: number, mode: CellMode): string;
81
+ /**
82
+ * Render a grid window as a Markdown table with spreadsheet coordinates.
83
+ *
84
+ * The column-letter header row and row-number first column are the point: they
85
+ * let the model answer "which cell is that" and reference `D7` in its next call.
86
+ * A bare table without them forces it to count columns, which it gets wrong.
87
+ */
88
+ export declare function renderGrid(ws: SheetHandle, window: GridWindow, mode: CellMode): string;
89
+ /** Inclusive integer range as an array. */
90
+ export declare function rangeOf(from: number, to: number): number[];
91
+ /** `"A1:C10"` for a window. */
92
+ export declare function describeWindow(window: GridWindow): string;
93
+ /**
94
+ * Convert a hex colour to the ARGB string Excel styles use.
95
+ *
96
+ * Accepts `RGB` or `AARRGGBB`, with or without a leading `#`, because a model
97
+ * writes all three.
98
+ */
99
+ export declare function toArgb(color: string): string;
100
+ //# sourceMappingURL=spreadsheet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spreadsheet.d.ts","sourceRoot":"","sources":["../../src/tools/spreadsheet.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAiB,QAAQ,EAAa,MAAM,mBAAmB,CAAC;AAIvE,0DAA0D;AAC1D,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC;AAEhE,0BAA0B;AAC1B,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,QAAQ,CAAC,YAAY,CAAC,CAAC;AAEnE,sEAAsE;AACtE,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,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,MAAM,CAatF;AAED,2CAA2C;AAC3C,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,CAM1D;AAED,+BAA+B;AAC/B,wBAAgB,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAEzD;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAY5C"}
@@ -0,0 +1,210 @@
1
+ /**
2
+ * Shared spreadsheet helpers.
3
+ *
4
+ * Three concerns that every spreadsheet tool needs and must not re-derive:
5
+ * grid geometry, formula normalization, and rendering a grid as a table a model
6
+ * can address by cell reference.
7
+ */
8
+ import { Address, Cell, Workbook, Worksheet } from "documonster/excel";
9
+ import { toolError } from "../errors.js";
10
+ /** Excel worksheet limits (ECMA-376 / modern Excel). */
11
+ export const MAX_EXCEL_ROWS = 1_048_576;
12
+ export const MAX_EXCEL_COLUMNS = 16_384; // XFD
13
+ /**
14
+ * Read a worksheet's name.
15
+ *
16
+ * The handle has no public `name` property — `ws.name` is `undefined` — so the
17
+ * model record is the only public route. Verified empirically; do not "simplify"
18
+ * this to `ws.name`.
19
+ */
20
+ export function sheetName(ws) {
21
+ return Worksheet.getModel(ws).name;
22
+ }
23
+ /** Every worksheet name in workbook order. */
24
+ export function sheetNames(wb) {
25
+ return Workbook.getWorksheets(wb).map(sheetName);
26
+ }
27
+ /**
28
+ * Resolve a sheet by name or 1-based index, failing with a list of what does
29
+ * exist — a model that picked the wrong name can then correct itself in one
30
+ * step instead of guessing again.
31
+ */
32
+ export function requireSheet(wb, sheet) {
33
+ const names = sheetNames(wb);
34
+ if (sheet === undefined) {
35
+ const first = Workbook.getWorksheets(wb)[0];
36
+ if (first === undefined) {
37
+ throw toolError.invalidInput("this workbook has no worksheets");
38
+ }
39
+ return first;
40
+ }
41
+ if (typeof sheet === "number") {
42
+ const found = Workbook.getWorksheets(wb)[sheet - 1];
43
+ if (found === undefined) {
44
+ throw toolError.invalidInput(`sheet index ${sheet} is out of range (workbook has ${names.length})`, `Available sheets: ${names.map(name => JSON.stringify(name)).join(", ")}`);
45
+ }
46
+ return found;
47
+ }
48
+ const found = Workbook.getWorksheet(wb, sheet);
49
+ if (found === undefined) {
50
+ throw toolError.invalidInput(`no sheet named ${JSON.stringify(sheet)}`, `Available sheets: ${names.map(name => JSON.stringify(name)).join(", ")}`);
51
+ }
52
+ return found;
53
+ }
54
+ /**
55
+ * Parse an A1 range into a 1-based window.
56
+ *
57
+ * `Address.decodeRange` returns 0-based `{ s, e }`; `Worksheet.dimensions`
58
+ * returns 1-based `{ top, left, bottom, right }`. Mixing the two is the easiest
59
+ * off-by-one in this package, so the conversion happens exactly here.
60
+ */
61
+ export function parseRange(range) {
62
+ const trimmed = range.trim();
63
+ if (trimmed.length === 0) {
64
+ throw toolError.invalidInput("range must not be empty");
65
+ }
66
+ let decoded;
67
+ try {
68
+ decoded = Address.decodeRange(trimmed.toUpperCase());
69
+ }
70
+ catch (cause) {
71
+ throw toolError.invalidInput(`could not parse range ${JSON.stringify(range)}`, 'Use A1 notation, e.g. "B2:D10" or "A1".', { cause });
72
+ }
73
+ const window = {
74
+ top: decoded.s.r + 1,
75
+ left: decoded.s.c + 1,
76
+ bottom: decoded.e.r + 1,
77
+ right: decoded.e.c + 1
78
+ };
79
+ if (!Number.isFinite(window.top) ||
80
+ !Number.isFinite(window.left) ||
81
+ window.top < 1 ||
82
+ window.left < 1 ||
83
+ window.bottom < window.top ||
84
+ window.right < window.left ||
85
+ window.bottom > MAX_EXCEL_ROWS ||
86
+ window.right > MAX_EXCEL_COLUMNS) {
87
+ throw toolError.invalidInput(`range ${JSON.stringify(range)} is not a valid rectangle`, 'Use A1 notation with the top-left cell first, within A1:XFD1048576, e.g. "B2:D10".');
88
+ }
89
+ return window;
90
+ }
91
+ /**
92
+ * The used area of a sheet, as a 1-based window. Empty sheets yield `undefined`.
93
+ *
94
+ * An empty sheet reports `{ top: 0, left: 0, bottom: 0, right: 0 }` — verified
95
+ * empirically, both freshly created and after a file round-trip. That satisfies
96
+ * `bottom >= top`, so checking only for an inverted rectangle lets zeroes through
97
+ * and the first `columnLetter(0)` then throws `ColumnOutOfBoundsError`. Hence the
98
+ * explicit `>= 1` checks.
99
+ */
100
+ export function usedWindow(ws) {
101
+ const dimensions = Worksheet.dimensions(ws);
102
+ if (dimensions.top < 1 ||
103
+ dimensions.left < 1 ||
104
+ dimensions.bottom < dimensions.top ||
105
+ dimensions.right < dimensions.left) {
106
+ return undefined;
107
+ }
108
+ return {
109
+ top: dimensions.top,
110
+ left: dimensions.left,
111
+ bottom: dimensions.bottom,
112
+ right: dimensions.right
113
+ };
114
+ }
115
+ /**
116
+ * Strip a leading `=` from a formula.
117
+ *
118
+ * Essential, not cosmetic: the core stores formula text WITHOUT the `=`, and
119
+ * passing `"=SUM(A1:A2)"` makes every function resolve to `#NAME?` — including
120
+ * plain arithmetic, so the failure does not even look like a formula problem.
121
+ * Verified empirically. A model will always write the Excel-looking form with
122
+ * the `=`, so normalizing here is what makes the tools usable at all.
123
+ */
124
+ export function normalizeFormula(formula) {
125
+ const trimmed = formula.trim();
126
+ return trimmed.startsWith("=") ? trimmed.slice(1).trim() : trimmed;
127
+ }
128
+ /** Column letter for a 1-based column index. */
129
+ export function columnLetter(column) {
130
+ return Address.encodeCol(column - 1);
131
+ }
132
+ /** `"B7"` for 1-based row/column. */
133
+ export function cellRef(row, column) {
134
+ return Address.encodeCell({ r: row - 1, c: column - 1 });
135
+ }
136
+ /**
137
+ * Render one cell as table text.
138
+ *
139
+ * Uses `Cell.getDisplayText`, which applies the cell's number format — so a
140
+ * currency cell reads `1,234.50` rather than `1234.5`, matching what the user
141
+ * sees in Excel and what they will quote back to the model.
142
+ */
143
+ export function renderCell(ws, row, column, mode) {
144
+ const formula = Cell.getFormula(ws, row, column);
145
+ if (mode === "formulas") {
146
+ return formula === undefined
147
+ ? escapeCell(Cell.getDisplayText(ws, row, column))
148
+ : escapeCell(`=${formula}`);
149
+ }
150
+ const display = escapeCell(Cell.getDisplayText(ws, row, column));
151
+ if (mode === "both" && formula !== undefined) {
152
+ return `${display} \`=${escapeCell(formula)}\``;
153
+ }
154
+ return display;
155
+ }
156
+ /**
157
+ * Escape a value for a Markdown table cell.
158
+ *
159
+ * A raw `|` would silently split one cell into two and shift every subsequent
160
+ * column, which the model has no way to detect.
161
+ */
162
+ function escapeCell(text) {
163
+ return text.replace(/\|/g, "\\|").replace(/\r?\n/g, " ");
164
+ }
165
+ /**
166
+ * Render a grid window as a Markdown table with spreadsheet coordinates.
167
+ *
168
+ * The column-letter header row and row-number first column are the point: they
169
+ * let the model answer "which cell is that" and reference `D7` in its next call.
170
+ * A bare table without them forces it to count columns, which it gets wrong.
171
+ */
172
+ export function renderGrid(ws, window, mode) {
173
+ const header = ["", ...rangeOf(window.left, window.right).map(columnLetter)];
174
+ const divider = header.map(() => "---");
175
+ const lines = [`| ${header.join(" | ")} |`, `| ${divider.join(" | ")} |`];
176
+ for (const row of rangeOf(window.top, window.bottom)) {
177
+ const cells = rangeOf(window.left, window.right).map(column => renderCell(ws, row, column, mode));
178
+ lines.push(`| ${[String(row), ...cells].join(" | ")} |`);
179
+ }
180
+ return lines.join("\n");
181
+ }
182
+ /** Inclusive integer range as an array. */
183
+ export function rangeOf(from, to) {
184
+ const out = [];
185
+ for (let value = from; value <= to; value += 1) {
186
+ out.push(value);
187
+ }
188
+ return out;
189
+ }
190
+ /** `"A1:C10"` for a window. */
191
+ export function describeWindow(window) {
192
+ return `${cellRef(window.top, window.left)}:${cellRef(window.bottom, window.right)}`;
193
+ }
194
+ /**
195
+ * Convert a hex colour to the ARGB string Excel styles use.
196
+ *
197
+ * Accepts `RGB` or `AARRGGBB`, with or without a leading `#`, because a model
198
+ * writes all three.
199
+ */
200
+ export function toArgb(color) {
201
+ const hex = color.replace(/^#/, "").toUpperCase();
202
+ if (/^[0-9A-F]{8}$/.test(hex)) {
203
+ return hex;
204
+ }
205
+ if (/^[0-9A-F]{6}$/.test(hex)) {
206
+ return `FF${hex}`;
207
+ }
208
+ throw toolError.invalidInput(`${JSON.stringify(color)} is not a hex colour`, 'Use RRGGBB or AARRGGBB, e.g. "C00000".');
209
+ }
210
+ //# sourceMappingURL=spreadsheet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spreadsheet.js","sourceRoot":"","sources":["../../src/tools/spreadsheet.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEvE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAgBzC,wDAAwD;AACxD,MAAM,CAAC,MAAM,cAAc,GAAG,SAAS,CAAC;AACxC,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,CAAC,MAAM;AAE/C;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAC,EAAe;IACvC,OAAO,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC;AACrC,CAAC;AAED,8CAA8C;AAC9C,MAAM,UAAU,UAAU,CAAC,EAAkB;IAC3C,OAAO,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;AACnD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,EAAkB,EAAE,KAAkC;IACjF,MAAM,KAAK,GAAG,UAAU,CAAC,EAAE,CAAC,CAAC;IAE7B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,MAAM,KAAK,GAAG,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5C,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,MAAM,SAAS,CAAC,YAAY,CAAC,iCAAiC,CAAC,CAAC;QAClE,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED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BAAsB,EAC9C,wCAAwC,CACzC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * `template_inspect` and `template_fill` — Word templating.
3
+ *
4
+ * The best-shaped pair of tools in this server, because the model's job is
5
+ * reduced to supplying data:
6
+ *
7
+ * template_inspect → "this template wants client.name, items[], signature"
8
+ * template_fill → here is that data as JSON
9
+ *
10
+ * `listTemplateTags` is effectively a self-describing schema, so nothing about
11
+ * the document's internals has to enter the model's context, and the styling,
12
+ * fonts, headers and numbering are whatever the template author set — the model
13
+ * cannot break them. Compared with generating a document from scratch, the
14
+ * surface for error is an order of magnitude smaller.
15
+ */
16
+ export declare const templateInspectTool: import("./types.js").AnyToolDefinition;
17
+ export declare const templateFillTool: import("./types.js").AnyToolDefinition;
18
+ //# sourceMappingURL=template.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../../src/tools/template.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAgBH,eAAO,MAAM,mBAAmB,wCAkE9B,CAAC;AAEH,eAAO,MAAM,gBAAgB,wCA6G3B,CAAC"}