@ofrnsb/whiteboard 0.0.0-stage → 0.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 +70 -2
- package/dist/boards-ykaNj5ns.d.ts +540 -0
- package/dist/chunk-ORDEALPW.js +1981 -0
- package/dist/chunk-ORDEALPW.js.map +1 -0
- package/dist/cli/index.js +2272 -0
- package/dist/core/index.d.ts +1495 -0
- package/dist/core/index.js +809 -0
- package/dist/core/index.js.map +1 -0
- package/dist/index.d.ts +78 -0
- package/dist/index.js +3745 -0
- package/dist/index.js.map +1 -0
- package/dist/style.css +794 -0
- package/package.json +70 -4
|
@@ -0,0 +1,809 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BOARD,
|
|
3
|
+
BOARD_ARGS,
|
|
4
|
+
BOARD_CHATS_KEPT,
|
|
5
|
+
BOARD_EDITS_KEPT,
|
|
6
|
+
BOARD_HISTORY,
|
|
7
|
+
BRUSHES,
|
|
8
|
+
COL_TYPES,
|
|
9
|
+
COUNT,
|
|
10
|
+
ERR,
|
|
11
|
+
FORMS,
|
|
12
|
+
ILLUSTRATIONS,
|
|
13
|
+
LABEL_CHAR,
|
|
14
|
+
LEN,
|
|
15
|
+
LINE_ICONS,
|
|
16
|
+
LOOSE_NOTES,
|
|
17
|
+
MAX_COLS,
|
|
18
|
+
MAX_LAYER,
|
|
19
|
+
MAX_NOTES,
|
|
20
|
+
MAX_ROWS,
|
|
21
|
+
NOTE_COLORS,
|
|
22
|
+
NOTE_H,
|
|
23
|
+
NOTE_W,
|
|
24
|
+
OUTLINED,
|
|
25
|
+
PENS,
|
|
26
|
+
POLYGONS,
|
|
27
|
+
ROUTES,
|
|
28
|
+
SECTION_NOTE_INSET,
|
|
29
|
+
SHAPES,
|
|
30
|
+
TEXT_SIZES,
|
|
31
|
+
TONES,
|
|
32
|
+
WIRE,
|
|
33
|
+
WORDS,
|
|
34
|
+
applyOps,
|
|
35
|
+
autoWires,
|
|
36
|
+
blockHeight,
|
|
37
|
+
boardAt,
|
|
38
|
+
boardText,
|
|
39
|
+
cellValue,
|
|
40
|
+
colorFor,
|
|
41
|
+
columnTotal,
|
|
42
|
+
contentOf,
|
|
43
|
+
drawOps,
|
|
44
|
+
evalFormula,
|
|
45
|
+
extendTimelineOps,
|
|
46
|
+
foldIntoBase,
|
|
47
|
+
formulaRefs,
|
|
48
|
+
frameAt,
|
|
49
|
+
freeSpot,
|
|
50
|
+
historyOf,
|
|
51
|
+
isIllustration,
|
|
52
|
+
isLineIcon,
|
|
53
|
+
isPolygon,
|
|
54
|
+
labelSize,
|
|
55
|
+
labelSpot,
|
|
56
|
+
layFree,
|
|
57
|
+
layoutOps,
|
|
58
|
+
markStrokes,
|
|
59
|
+
minSize,
|
|
60
|
+
nextOrigin,
|
|
61
|
+
noEmoji,
|
|
62
|
+
noteHeight,
|
|
63
|
+
obstacles,
|
|
64
|
+
opKeys,
|
|
65
|
+
overlaps,
|
|
66
|
+
pasteOps,
|
|
67
|
+
pendingBatchOf,
|
|
68
|
+
planOf,
|
|
69
|
+
polygonPad,
|
|
70
|
+
polygonPoints,
|
|
71
|
+
rangeTsv,
|
|
72
|
+
routeWires,
|
|
73
|
+
smoothPoints,
|
|
74
|
+
stepsOf,
|
|
75
|
+
tabRows,
|
|
76
|
+
taskBoardOps,
|
|
77
|
+
taskShape,
|
|
78
|
+
tidyOps,
|
|
79
|
+
uid,
|
|
80
|
+
validIcon,
|
|
81
|
+
wireBoxes,
|
|
82
|
+
wireLabel,
|
|
83
|
+
wrapLines
|
|
84
|
+
} from "../chunk-ORDEALPW.js";
|
|
85
|
+
|
|
86
|
+
// src/core/service.ts
|
|
87
|
+
import { z } from "zod";
|
|
88
|
+
|
|
89
|
+
// src/core/agent-copy.ts
|
|
90
|
+
var TK_BOARDS = {
|
|
91
|
+
agent: "Agent",
|
|
92
|
+
sheetKind: "sheet",
|
|
93
|
+
boardKind: "whiteboard",
|
|
94
|
+
sheetShort: "sheet",
|
|
95
|
+
boardShort: "board",
|
|
96
|
+
tasksKind: "task board",
|
|
97
|
+
/** The card title field of a task board the agent makes. */
|
|
98
|
+
taskTitle: "Task",
|
|
99
|
+
tasksShort: "tasks",
|
|
100
|
+
arg: {
|
|
101
|
+
why: `one line in the user's language (English by default): why this change, grounded in the business rule or the data behind it (e.g. "Day 21 added: at most 1 reminder per 7 days"). It is read out when the board's history is replayed.`,
|
|
102
|
+
noteOwner: "person responsible, by name",
|
|
103
|
+
noteDue: "due date as the user would read it, e.g. 14 Nov",
|
|
104
|
+
options: "choices for a select column",
|
|
105
|
+
formula: "computed column, e.g. {Qty} * {Price}; refers to other columns by name in braces",
|
|
106
|
+
total: "footer total for this column",
|
|
107
|
+
itemKey: "your name for this item, to connect it",
|
|
108
|
+
shape: "note (sticky card, default in grid, row, timeline, matrix), box (default in stack, flow, diagram), text, ellipse, cloud (an outside service), cylinder (a database), sticker (a big illustration on its own: its name in icon, an optional caption in text)",
|
|
109
|
+
itemTitle: "bold first line, e.g. Agent core",
|
|
110
|
+
color: "paper (default box), ink = the one highlighted element, red = needs action, outline = not built yet, new = new in this step; tints yellow, blue, green, pink, purple, gray group things; sand, peach, orange are the warm card tones of a timeline (picked for you)",
|
|
111
|
+
icon: `a drawing for this item, by name. Line drawings for a marker sketch: ${LINE_ICONS.join(", ")}. Full-colour illustrations for a sticker or a sticky note: ${ILLUSTRATIONS.join(", ")}. Never an emoji.`,
|
|
112
|
+
when: "timeline only: the milestone on the road, e.g. Day 7, Week 2, 14 Nov",
|
|
113
|
+
cell: 'matrix only: [column, row] by header name or number, e.g. ["Wednesday", "Week 2"]',
|
|
114
|
+
across: "matrix only: column headers left to right, e.g. Monday\u2026Friday",
|
|
115
|
+
down: "matrix only: row headers top to bottom, e.g. Week 1\u20264, or owners",
|
|
116
|
+
heading: "big title and one-line subtitle with the concrete scope and numbers; icon is one illustration (by name) shown as a sticker beside the title",
|
|
117
|
+
at: "diagram layout only: [column, row]",
|
|
118
|
+
box: "[x, y, width, height]. Lay the story out left to right, then start a new row below; keep each beat's items together and leave 30 to 60 between neighbours. A block of 260 to 360 wide holds a title and one line; a wide block (500+) with size l or xl is for the one thing that must be seen; text notes 300 to 500 wide",
|
|
119
|
+
tone: "what kind of thing it is, which sets its colour everywhere: fact (black), problem (red, what goes wrong), action (green, what we do), insight (purple, what it means), person (blue, a person, team or desk), system (orange, a system or data store)",
|
|
120
|
+
freeKey: 'a short name for this item, unique on the board, used by links ("calls", "no-offer", "mb-787860")',
|
|
121
|
+
itemX: "where the item's left edge goes, in pixels from the left of the drawing space; the board is as wide as you need (3,000 to 5,000 is normal)",
|
|
122
|
+
itemY: "where the item's top goes, in pixels from the top of the drawing space under the headline",
|
|
123
|
+
form: "the item's shape: rect (default), square, circle, ellipse, diamond (a decision or a question), triangle (a warning or a peak), pentagon, hexagon (a process step), parallelogram (an input or a record), cylinder (a system or data store), cloud (outside the company), pill (a short tag), sticky (a yellow note in your voice), text (bare lettering: a caption, a heading over a group)",
|
|
124
|
+
itemW: "width in pixels; leave out for the size's normal width (s 240, m 300, l 380, xl 480). For a horizontal bar chart, make each bar's width proportional to its value, scaled so the smallest bar is at least 150 wide (never narrower: its words must fit)",
|
|
125
|
+
itemH: "height in pixels, at least what the words need (it grows to fit them). For a vertical bar chart, give every bar the same width (150 or more), its height proportional to its value, all on one baseline; a bar's own words are only its label and figure (the explanation goes in a text item or note beside the chart), so even a short bar keeps its true height",
|
|
126
|
+
layer: "how deep in the explanation this item sits: 0 the main flow (the story's spine), 1 what a main item breaks down into, 2 what that breaks down into, and so on to 9. Wires take a colour per layer (black along the main flow), so a reader can follow one level of detail across the board",
|
|
127
|
+
qWhy: "why it is so: the cause, the rule or the reason, with the evidence",
|
|
128
|
+
qWho: "who: the customer, agent, desk, team or owner, by name",
|
|
129
|
+
qWhen: "when: the date, period, deadline or how often",
|
|
130
|
+
qWhere: "where: the desk, channel, branch, system or step it happens in",
|
|
131
|
+
qHow: "how: the method, the source of the figure (system, table, filter) or the steps taken",
|
|
132
|
+
qHowMuch: "how much or how many: the amount, count, rate or cost, with its unit",
|
|
133
|
+
qAssumes: "what this figure or claim rests on that the data does not prove: a past rate that still holds, a price from the catalogue, a definition you chose, a period you picked",
|
|
134
|
+
freeTitle: 'what this is, with its number when it has one ("950 eligible callers"). Short: it is lettered in capitals',
|
|
135
|
+
itemText: 'what it means in plain words, the line a newcomer needs ("asked for a product, do not hold it, no complaint open on the call")',
|
|
136
|
+
linkFrom: "key of the item the wire starts at (drawn in this beat or an earlier one)",
|
|
137
|
+
linkTo: "key of the item the wire ends at, with the arrowhead",
|
|
138
|
+
linkLabel: 'a few words on the wire saying what happens along it ("603 of them", "because", "hands over to")',
|
|
139
|
+
beatItems: "the items drawn while saying this beat's sentence",
|
|
140
|
+
beatLinks: "the wires drawn in this beat, each between two keyed items",
|
|
141
|
+
nodeNote: "a remark you would make out loud about this thing, stuck beside it as a yellow sticky note (the so-what, a caution, the source)",
|
|
142
|
+
say: 'what you would say aloud while drawing this beat, one sentence a listener could follow with their eyes closed ("Of those 1,147, only 950 can actually be offered something")',
|
|
143
|
+
size: "lettering size: s for fine print and definitions, m normal, l for what matters, xl for the one number the board is about",
|
|
144
|
+
itemLine: "the line under the title: the figure and what it means in plain words",
|
|
145
|
+
beatConnectors: "arrows drawn in this beat, between keyed items (from this beat or an earlier one), each with a label saying what happens on it: how many move on, how many drop and why, who hands over to whom",
|
|
146
|
+
pen: "the marker this item is drawn in (black, blue, green, red, purple, orange): its outline, words and drawing take that colour. Use colour to carry meaning across the board (one colour per idea or side), not decoration",
|
|
147
|
+
dashed: "draw the outline as dashes: something optional, planned, not there yet, or a loose group around other items",
|
|
148
|
+
marks: "what a person does with a marker to make a point: ring (circle an item), underline, highlight (yellow marker through it), cross (strike it out), tick. Give the item's key; the board draws the mark properly round it",
|
|
149
|
+
strokes: "free layout only: lines you draw by hand over the items, each a list of [x, y] points in the same space: an underline under the key figure, a bracket, a divider between two halves, an axis, a curved arrow; three or four points are enough, the board smooths them into one flowing line. To circle or underline an item use marks instead. marker true for a thick highlighter",
|
|
150
|
+
layout: "always free",
|
|
151
|
+
beside: "place right of the previous section instead of below",
|
|
152
|
+
route: "elbow (default), straight, or curve (default between matrix items)",
|
|
153
|
+
sectionSubtitle: "one line under the section title saying what goes in it",
|
|
154
|
+
noteTitle: "bold first line of the sticky (at most 4 words)",
|
|
155
|
+
board: "board ref (WB-\u2026/SH-\u2026) or id, from create_*, list_boards or the user's message"
|
|
156
|
+
},
|
|
157
|
+
notFound: (key) => `Board ${key} is not in this team. Find it with list_boards.`,
|
|
158
|
+
wrongKind: (ref, kind) => `${ref} is a ${kind}; use the tools for that kind.`,
|
|
159
|
+
badFormula: (name) => `The formula in column ${name} is not valid: use {Column name}, numbers, + - * / and brackets.`,
|
|
160
|
+
formulaMissing: (name, refs) => `The formula in column ${name} refers to columns that do not exist: ${refs}.`,
|
|
161
|
+
sheetSummary: (tabs, rows) => `${tabs} tabs, ${rows} rows`,
|
|
162
|
+
tasksSummary: (lanes, cards) => `${cards} cards in lanes ${lanes}`,
|
|
163
|
+
boardSummary: (sections, notes) => `${sections} sections, ${notes} notes`,
|
|
164
|
+
listSep: ", ",
|
|
165
|
+
problemSep: "; ",
|
|
166
|
+
skipped: (problems) => ` Skipped: ${problems}.`,
|
|
167
|
+
createWhiteboard: {
|
|
168
|
+
description: "Make a sticky-note board the team edits with you: a heading, then sections (frames) with a one-line description, of big square sticky notes coloured by meaning (green went well, pink a problem, blue an idea, purple a risk). Use for retros, brainstorms and risk or stakeholder maps. For a plan, rollout, timeline, schedule or any explanation use draw_whiteboard. Write each note as a short title and one line. Show it with present: whiteboard block and the ref.",
|
|
169
|
+
layout: "columns: sections side by side; timeline: phases left to right joined by arrows; grid: many sections in rows. A plan or explanation over time is drawn with draw_whiteboard instead",
|
|
170
|
+
running: (title) => `Building board ${title}`,
|
|
171
|
+
done: (title) => `Board ${title} built`,
|
|
172
|
+
result: (id2, ref, title, summary2) => `ref=${id2} board ${ref} "${title}": ${summary2}. Show it with present (whiteboard, this ref). The team can add notes; read it again with read_board.`
|
|
173
|
+
},
|
|
174
|
+
createSheet: {
|
|
175
|
+
description: "Make a spreadsheet the team edits with you: tabs, typed columns (text, number, money, date, select with options, check), formulas between columns ({Qty} * {Price}) and footer totals. Fill rows yourself, or from a rows result with from_ref (its columns come along). Use only when the user asks for a sheet or wants something the team will keep filling in: trackers, budgets, checklists with owners. Never to answer a question: a ranking, a comparison, rates or totals from the data are shown as a built screen with present (figures, rings, bars), not as a sheet. Show it with present: sheet block and the ref.",
|
|
176
|
+
rows: "values in column order (formula columns skipped), or objects keyed by column name",
|
|
177
|
+
fromRef: "fill this tab from a rows result: its columns and rows",
|
|
178
|
+
running: (title) => `Building sheet ${title}`,
|
|
179
|
+
done: (title) => `Sheet ${title} built`,
|
|
180
|
+
result: (id2, ref, title, summary2) => `ref=${id2} sheet ${ref} "${title}": ${summary2}. Show it with present (sheet, this ref).`
|
|
181
|
+
},
|
|
182
|
+
createTaskboard: {
|
|
183
|
+
description: "Make a task board the team works on with you: lanes in process order (any process: To do, In progress, Done; Lead, Qualified, Won; Admitted, Ward, Discharged), cards with a title and fields (owner, due date, priority, anything the work needs). People drag cards between lanes themselves; you move, add and assign them with update_taskboard. Use when the user wants to track work, a pipeline or a queue the team keeps moving. For records that live in a company system, show them as a board block instead: those moves are writes.",
|
|
184
|
+
lane: "name of the lane field, in the team's words (Status, Stage, Tahap)",
|
|
185
|
+
lanes: "the lanes, in process order",
|
|
186
|
+
fields: "card fields beside the title and lane: owner, due date, priority...",
|
|
187
|
+
cards: "objects keyed by field name: the title field, the lane field (one of the lanes), and any other field",
|
|
188
|
+
running: (title) => `Building task board ${title}`,
|
|
189
|
+
done: (title) => `Task board ${title} built`,
|
|
190
|
+
result: (id2, ref, title, summary2) => `ref=${id2} task board ${ref} "${title}": ${summary2}. Show it with present (taskboard, this ref).`
|
|
191
|
+
},
|
|
192
|
+
updateTaskboard: {
|
|
193
|
+
description: "Change a task board: move cards to another lane (one or many at once), add cards, set card fields (owner, due date...), remove cards, add or rename lanes. Cards are found by their id from read_board, their title, or their 1-based number. Every change is kept in the board's history and the team sees it live.",
|
|
194
|
+
move: "cards to move: card (id, title or number) and the lane to put it in",
|
|
195
|
+
running: "Updating the task board",
|
|
196
|
+
done: "Task board updated",
|
|
197
|
+
noLane: (lane, lanes) => `no lane "${lane}" (lanes: ${lanes})`,
|
|
198
|
+
noCard: (card) => `no card "${card}"`,
|
|
199
|
+
noField: (field) => `no field "${field}"`,
|
|
200
|
+
notTasks: (ref) => `${ref} is not a task board`,
|
|
201
|
+
edit: "updated the task board",
|
|
202
|
+
result: (id2, ref, summary2, skipped) => `ref=${id2} task board ${ref}: ${summary2}.${skipped} Show it with present (taskboard, this ref).`
|
|
203
|
+
},
|
|
204
|
+
draw: {
|
|
205
|
+
description: "Explain something on a whiteboard the way a sharp colleague does standing at one, or the way an investigator pins up an evidence wall, so that someone who was not there understands all of it without asking anything. You compose the board yourself: what goes where, in which shape, how big, and what joins what. Give a headline (the finding in one line), context (period, source, how many, what the terms mean) and beats in the order you would explain them. Each beat has say (the sentence you speak while drawing it; it is pinned up as a sticky note beside that beat), the items you draw in it, and the links you draw in it. Each item has a key, x and y (where its top-left goes, in board pixels, from the top-left of the space under the headline), a form (rect, square, circle, ellipse, diamond, triangle, pentagon, hexagon, parallelogram, cylinder, cloud, pill, sticky, text: whatever suits the thing), a title and text, a layer (0 the main flow, 1 to 9 each level of detail below it), and answers why, who, when, where, how and how much wherever they have an answer (nearly always). Always explain everything in full detail, whether or not the person asked for detail: a board full of detail is the point, not a problem; a reader should never need to ask anything. Say what the board assumes: on each item whose figure rests on an assumption (assumes), and in a closing group of the board headed Assumptions and open questions (its items wired with dashed links to what they underpin). Charts are drawn the same way: bars are rect items sized in proportion to their values (w for horizontal bars, h for vertical bars on one baseline), each labelled with its figure. Put the main finding where the eye lands first, group what belongs together, spread causes around their effect, chain a process along a line, branch a breakdown out from its whole, and drill every part down to the actual calls or records, up to ten layers deep (the part the story is about the deepest). Leave room for wires between things (about 120 to 200 pixels). The board keeps your picture clean: an item that would cover another moves to the nearest free spot, wires are routed around every item, never through one, and their labels sit where the wire still shows. Query your data down to the depth you draw before drawing. tone sets meaning and colour: fact, problem, action, insight, person, system. Use real names, numbers and dates from your tools. No emoji. Leave board out to start a new board with title; pass board to continue an existing one.",
|
|
206
|
+
headline: 'the finding in one line, as you would write it across the top ("2 in 3 callers who ask never hear an offer")',
|
|
207
|
+
context: "one or two lines under the headline: the period, the source, how many, and what a term in the headline means",
|
|
208
|
+
beats: "the explanation in the order you would give it, 4 to 12 beats: each beat is what you draw while saying one sentence (one to eight items and the links between them)",
|
|
209
|
+
skippedKeys: (keys) => ` Not drawn, keys repeated or not found: ${keys.join(", ")}.`,
|
|
210
|
+
board: "existing board ref or id; leave out to make a new board",
|
|
211
|
+
title: "title of a new board",
|
|
212
|
+
running: "Drawing on the board",
|
|
213
|
+
writing: "Planning the board",
|
|
214
|
+
done: "Board drawn",
|
|
215
|
+
needTarget: "Give title for a new board, or board to add to an existing one.",
|
|
216
|
+
result: (id2, ref, summary2, missing) => `ref=${id2} board ${ref}: ${summary2}.${missing.length ? ` Connectors skipped, keys not found: ${missing.join(", ")}.` : ""} Show it with present (whiteboard, this ref).`
|
|
217
|
+
},
|
|
218
|
+
read: {
|
|
219
|
+
description: "Read a whiteboard (sections and notes with their ids, owners, due dates and who wrote them, including the team's own notes) or a sheet (tabs, columns and rows with formulas computed). Pass note_ids to read only a selection the user asked about.",
|
|
220
|
+
running: "Reading the board",
|
|
221
|
+
done: "Board read",
|
|
222
|
+
head: (ref, title, kind, summary2, by) => `${ref} "${title}" (${kind}, ${summary2}, last changed by ${by}).`
|
|
223
|
+
},
|
|
224
|
+
updateWhiteboard: {
|
|
225
|
+
description: "Change a whiteboard: extend a timeline road with new milestones (extend_timeline), add sections or notes (a note without a section sits on its own), move notes between sections (to group by theme: add the theme sections, move each note, then remove the emptied ones), edit (text, owner, due, colour) or remove notes, rename or remove sections, draw or remove arrows between notes or sections (dependencies, flow, cause and effect). Read it first with read_board for the ids. The board tidies itself after moves. Show it again with present (whiteboard) and the returned ref.",
|
|
226
|
+
extendTimeline: "carry a timeline road on with new milestones (when, title, text, icon), in order, after the last one: the road is drawn further and each item gets its milestone and card on the right side. Use this, never loose notes, to add steps, phases or dates to a timeline. road: the track id from read_board when the board has more than one road",
|
|
227
|
+
extendWhat: "Extending the timeline",
|
|
228
|
+
noRoad: "This board has no timeline to extend yet; add one with draw_whiteboard (layout timeline).",
|
|
229
|
+
noteSection: "section id or title; leave out for a note on its own",
|
|
230
|
+
updateLinks: "restyle arrows: elbow or straight, dashed, label, arrowheads",
|
|
231
|
+
removeSections: "section ids or titles; their notes stay on the board unless also removed",
|
|
232
|
+
addLinks: "arrows; from and to are note ids, section ids or section titles",
|
|
233
|
+
removeLinks: "arrow ids from read_board",
|
|
234
|
+
running: "Updating the board",
|
|
235
|
+
done: "Board updated",
|
|
236
|
+
addSections: "adding sections",
|
|
237
|
+
edit: "updating the board",
|
|
238
|
+
noSection: (s) => `section "${s}" does not exist`,
|
|
239
|
+
noNote: (id2) => `note ${id2} does not exist`,
|
|
240
|
+
noEnds: (from, to) => `arrow ${from} \u2192 ${to}: an end does not exist`,
|
|
241
|
+
noLink: (id2) => `arrow ${id2} does not exist`,
|
|
242
|
+
result: (id2, ref, summary2, skipped) => `ref=${id2} board ${ref}: ${summary2}.${skipped}`
|
|
243
|
+
},
|
|
244
|
+
updateSheet: {
|
|
245
|
+
description: "Change a sheet: set cells (row by id from read_board or by 1-based number; column by name), add or remove rows, add, change (type, options, formula, total) or remove columns, add tabs or rename the tab. The team sees your changes outlined. Read it first with read_board. Show it again with present (sheet) and the returned ref.",
|
|
246
|
+
tab: "tab name or id; the first tab when left out",
|
|
247
|
+
removeRows: "row ids from read_board or 1-based row numbers",
|
|
248
|
+
removeColumns: "column names or ids",
|
|
249
|
+
renameTab: "new name for the tab",
|
|
250
|
+
running: "Updating the sheet",
|
|
251
|
+
done: "Sheet updated",
|
|
252
|
+
addTabs: "adding tabs",
|
|
253
|
+
noTab: (tab, tabs) => `Tab ${tab} does not exist. Tabs available: ${tabs}.`,
|
|
254
|
+
addColumns: "adding columns",
|
|
255
|
+
noColumn: (c) => `column ${c} does not exist`,
|
|
256
|
+
invalidFormula: "(invalid formula)",
|
|
257
|
+
formulaRefs: (name, refs) => `formula ${name} refers to ${refs}`,
|
|
258
|
+
noCell: (row, col2) => `cell ${row}/${col2} does not exist`,
|
|
259
|
+
formulaCol: (name) => `${name} is a formula column`,
|
|
260
|
+
noRow: (key) => `row ${key} does not exist`,
|
|
261
|
+
usedBy: (name, users) => `column ${name} is used by formula ${users}`,
|
|
262
|
+
edit: "updating the sheet",
|
|
263
|
+
result: (id2, ref, summary2, skipped) => `ref=${id2} sheet ${ref}: ${summary2}.${skipped}`
|
|
264
|
+
},
|
|
265
|
+
open: {
|
|
266
|
+
description: "Open an existing whiteboard, sheet or task board of the team so you can show it with present (the returned ref).",
|
|
267
|
+
running: "Opening the board",
|
|
268
|
+
done: "Board opened",
|
|
269
|
+
result: (id2, ref, title, summary2, mode) => `ref=${id2} ${ref} "${title}" (${summary2}). Show it with present (${mode}, this ref).`
|
|
270
|
+
},
|
|
271
|
+
list: {
|
|
272
|
+
description: "List the team's whiteboards, sheets and task boards, newest change first, with refs, to find one the user mentions.",
|
|
273
|
+
running: "Finding the team's boards",
|
|
274
|
+
done: "Team boards found",
|
|
275
|
+
line: (ref, kind, title, summary2, day, by) => `${ref} ${kind} "${title}", ${summary2}, changed ${day} by ${by}`,
|
|
276
|
+
none: "This team has no whiteboards, sheets or task boards yet."
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
var BOARD_STEPS = {
|
|
280
|
+
frame: "Laying out the title and frame",
|
|
281
|
+
road: "Drawing the road",
|
|
282
|
+
marks: "Placing milestones",
|
|
283
|
+
marksRange: (from, to) => `${from} to ${to}`,
|
|
284
|
+
cards: (titles) => titles.length ? `Cards: ${titles.join(", ")}` : "Placing cards",
|
|
285
|
+
changes: "Tidying up",
|
|
286
|
+
links: "Connecting steps",
|
|
287
|
+
stickers: "Placing illustrations",
|
|
288
|
+
what: { frame: "laying out the frame", road: "drawing the road", marks: "placing milestones", cards: "placing cards", changes: "tidying up", links: "connecting steps", stickers: "placing illustrations" },
|
|
289
|
+
restoreWhat: "restored a version",
|
|
290
|
+
restoreWhy: (v) => `Restored to version ${v}`,
|
|
291
|
+
undoWhat: "undid the agent's work",
|
|
292
|
+
undoWhy: (what) => `Undone: ${what}`,
|
|
293
|
+
reading: "reading the board",
|
|
294
|
+
editing: "editing the board"
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
// src/core/service.ts
|
|
298
|
+
var maxEdits = (b) => b.mode === "whiteboard" ? BOARD_HISTORY.whiteboardEdits : BOARD_EDITS_KEPT;
|
|
299
|
+
var keepable = (ops) => ops.length <= BOARD_HISTORY.opsMax && JSON.stringify(ops).length <= BOARD_HISTORY.opsBytes;
|
|
300
|
+
function withEdit(prev, next, e, ops, more = {}) {
|
|
301
|
+
const kept = keepable(ops);
|
|
302
|
+
let base = kept ? prev.base ?? contentOf(prev) : contentOf(next);
|
|
303
|
+
const edits = [...prev.edits, { ...e, version: next.version, ...more.why ? { why: more.why.slice(0, LEN.line) } : {}, ...more.batch ? { batch: more.batch } : {}, ...more.told ? { told: true } : {}, ...kept ? { ops } : {} }];
|
|
304
|
+
const shell = { ...next, edits: [] };
|
|
305
|
+
while (edits.length > maxEdits(next)) base = foldIntoBase(base, edits.shift(), shell);
|
|
306
|
+
const activity = more.activity === null ? void 0 : more.activity ? { ...more.activity, at: next.updatedAt } : prev.activity;
|
|
307
|
+
return { ...next, edits, base, activity };
|
|
308
|
+
}
|
|
309
|
+
var newBatch = () => `bt_${crypto.randomUUID().replace(/-/g, "").slice(0, 10)}`;
|
|
310
|
+
var newRef = (mode) => {
|
|
311
|
+
const d = /* @__PURE__ */ new Date();
|
|
312
|
+
return `${mode === "sheet" ? "SH" : mode === "tasks" ? "TB" : "WB"}-${String(d.getFullYear()).slice(2)}${String(d.getMonth() + 1).padStart(2, "0")}-${crypto.randomUUID().slice(0, 4).toUpperCase()}`;
|
|
313
|
+
};
|
|
314
|
+
var RANK = { read: 0, edited: 1, created: 2 };
|
|
315
|
+
function withChat(b, via, what, at = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
316
|
+
if (!via) return b;
|
|
317
|
+
const prev = b.chats?.find((c) => c.chatId === via.chatId);
|
|
318
|
+
const kept = { chatId: via.chatId, userId: via.userId, at, what: prev && RANK[prev.what] > RANK[what] ? prev.what : what };
|
|
319
|
+
return { ...b, chats: [kept, ...(b.chats ?? []).filter((c) => c.chatId !== via.chatId)].slice(0, BOARD_CHATS_KEPT) };
|
|
320
|
+
}
|
|
321
|
+
function createBoard(owner, input, ops, agent, by, via, more = {}) {
|
|
322
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
323
|
+
const mode = input.mode ?? "whiteboard";
|
|
324
|
+
const who = agent ? WORDS.agent : by;
|
|
325
|
+
const empty = {
|
|
326
|
+
id: input.id ?? `brd_${crypto.randomUUID().replace(/-/g, "").slice(0, 12)}`,
|
|
327
|
+
ref: input.ref ?? newRef(mode),
|
|
328
|
+
tenantId: owner.tenantId,
|
|
329
|
+
unitId: owner.unitId ?? owner.tenantId,
|
|
330
|
+
projectId: owner.projectId ?? null,
|
|
331
|
+
title: input.title.trim().slice(0, LEN.title) || WORDS.untitled,
|
|
332
|
+
mode,
|
|
333
|
+
createdBy: by,
|
|
334
|
+
createdAt: now,
|
|
335
|
+
updatedAt: now,
|
|
336
|
+
updatedBy: who,
|
|
337
|
+
version: 0,
|
|
338
|
+
frames: [],
|
|
339
|
+
notes: [],
|
|
340
|
+
links: [],
|
|
341
|
+
tabs: [],
|
|
342
|
+
edits: []
|
|
343
|
+
};
|
|
344
|
+
const b = applyOps(empty, ops, who, now);
|
|
345
|
+
const made = withEdit(empty, b, { at: now, by: who, agent, what: agent ? ERR.membuatPapan : WORDS.created, keys: [] }, ops, more);
|
|
346
|
+
return withChat({ ...made, base: made.base ?? contentOf(empty) }, via, "created", now);
|
|
347
|
+
}
|
|
348
|
+
function editBoard(board, ops, agent, by, what, keys = opKeys(ops), via, more = {}) {
|
|
349
|
+
if (!ops.length) return board;
|
|
350
|
+
const who = agent ? WORDS.agent : by;
|
|
351
|
+
const next = applyOps(board, ops, who);
|
|
352
|
+
const done = withEdit(board, next, { at: next.updatedAt, by: who, agent, what, keys: [...new Set(keys)].slice(0, 400) }, ops, more);
|
|
353
|
+
return withChat(done, via, "edited", next.updatedAt);
|
|
354
|
+
}
|
|
355
|
+
function setActivity(board, activity) {
|
|
356
|
+
return { ...board, activity: activity ? { ...activity, at: (/* @__PURE__ */ new Date()).toISOString() } : void 0 };
|
|
357
|
+
}
|
|
358
|
+
function liveActivity(board, now = Date.now()) {
|
|
359
|
+
const a = board.activity;
|
|
360
|
+
return a && now - Date.parse(a.at) < BOARD_HISTORY.activityMs ? a : null;
|
|
361
|
+
}
|
|
362
|
+
function publicBoard(b) {
|
|
363
|
+
const { base: _base, activity: _a, ...rest } = b;
|
|
364
|
+
const activity = liveActivity(b);
|
|
365
|
+
return { ...rest, edits: b.edits.map(({ ops: _ops, ...e }) => e), ...activity ? { activity } : {}, pendingBatch: pendingBatchOf(b) };
|
|
366
|
+
}
|
|
367
|
+
function snapshot(b, since) {
|
|
368
|
+
return since === b.version ? { same: true, version: b.version, activity: liveActivity(b), pendingBatch: pendingBatchOf(b) } : { board: publicBoard(b) };
|
|
369
|
+
}
|
|
370
|
+
var STEP_WHY = {
|
|
371
|
+
frame: () => BOARD_STEPS.frame,
|
|
372
|
+
road: () => BOARD_STEPS.road,
|
|
373
|
+
marks: (s) => {
|
|
374
|
+
const labels = s.ops.flatMap((o) => o.op === "note.add" && o.note.shape === "pill" && o.note.text ? [o.note.text] : []);
|
|
375
|
+
return labels.length > 1 ? BOARD_STEPS.marksRange(labels[0], labels[labels.length - 1]) : BOARD_STEPS.marks;
|
|
376
|
+
},
|
|
377
|
+
cards: (s) => BOARD_STEPS.cards(s.ops.flatMap((o) => o.op === "note.add" ? [o.note.title || o.note.text] : []).filter(Boolean).slice(0, 3)),
|
|
378
|
+
changes: () => BOARD_STEPS.changes,
|
|
379
|
+
links: () => BOARD_STEPS.links,
|
|
380
|
+
stickers: () => BOARD_STEPS.stickers
|
|
381
|
+
};
|
|
382
|
+
var gap = (n2) => n2 > 1 ? Math.min(BOARD_HISTORY.stepMs, Math.floor(BOARD_HISTORY.stepsTotalMs / (n2 - 1))) : 0;
|
|
383
|
+
function buildSteps(ops, batch, via, what, why2, planFirst = false) {
|
|
384
|
+
const steps = stepsOf(ops, BOARD_HISTORY.cardsPerStep);
|
|
385
|
+
const plan = planOf(ops, BOARD_HISTORY.planMax);
|
|
386
|
+
const pauseMs = gap(steps.length);
|
|
387
|
+
return steps.map((s, i) => ({
|
|
388
|
+
ops: s.ops,
|
|
389
|
+
what: i === 0 && what ? what : BOARD_STEPS.what[s.kind],
|
|
390
|
+
why: i === 0 && why2 ? why2 : STEP_WHY[s.kind](s),
|
|
391
|
+
activity: { by: WORDS.agent, agent: true, what: BOARD_STEPS.what[s.kind], ...via ? { chatId: via.chatId } : {}, keys: opKeys(s.ops).slice(0, 60), plan, batch },
|
|
392
|
+
pauseMs,
|
|
393
|
+
...i === 0 && planFirst && plan.length ? { planFirst: true } : {}
|
|
394
|
+
}));
|
|
395
|
+
}
|
|
396
|
+
function toldSteps(beats, batch, via, why2) {
|
|
397
|
+
const P = BOARD_HISTORY.beat;
|
|
398
|
+
return beats.map((bt, i) => ({
|
|
399
|
+
ops: bt.ops,
|
|
400
|
+
what: bt.say.slice(0, P.sayChars),
|
|
401
|
+
why: i === 0 ? why2?.trim() || bt.say : bt.say,
|
|
402
|
+
activity: { by: WORDS.agent, agent: true, what: bt.say.slice(0, P.sayChars), ...via ? { chatId: via.chatId } : {}, keys: opKeys(bt.ops).slice(0, 60), plan: planOf(bt.ops, BOARD_HISTORY.planMax), batch },
|
|
403
|
+
told: true,
|
|
404
|
+
pauseMs: Math.min(P.maxMs, P.baseMs + P.perItemMs * bt.ops.length)
|
|
405
|
+
}));
|
|
406
|
+
}
|
|
407
|
+
var planActivity = (ops, what, batch, via) => {
|
|
408
|
+
const plan = planOf(ops, BOARD_HISTORY.planMax);
|
|
409
|
+
return { by: WORDS.agent, agent: true, what, ...via ? { chatId: via.chatId } : {}, keys: plan.map((p) => p.id).slice(0, 60), plan, batch };
|
|
410
|
+
};
|
|
411
|
+
function applyStep(owner, target, step, via) {
|
|
412
|
+
const more = { why: step.why, activity: step.activity, batch: step.activity.batch, told: step.told };
|
|
413
|
+
if ("edits" in target) return editBoard(target, step.ops, true, WORDS.agent, step.what, void 0, via, more);
|
|
414
|
+
return createBoard(owner, target, step.ops, true, WORDS.agent, via, more);
|
|
415
|
+
}
|
|
416
|
+
var decide = (b, batch, by, how, at = (/* @__PURE__ */ new Date()).toISOString()) => ({ ...b, edits: b.edits.map((e) => e.batch === batch ? { ...e, decided: { by, at, how } } : e) });
|
|
417
|
+
function keepBatch(board, batch, by) {
|
|
418
|
+
if (!board.edits.some((e) => e.batch === batch)) return { error: ERR.batchNotFound };
|
|
419
|
+
return decide(board, batch, by, "kept");
|
|
420
|
+
}
|
|
421
|
+
function undoBatch(board, batch, by) {
|
|
422
|
+
const mine = board.edits.filter((e) => e.batch === batch);
|
|
423
|
+
const first = mine[0];
|
|
424
|
+
if (!first?.version) return { error: ERR.batchNotFound };
|
|
425
|
+
const after = board.edits.filter((e) => (e.version ?? 0) > first.version && e.batch !== batch && e.ops?.length !== 0);
|
|
426
|
+
const others = [...new Set(after.map((e) => e.by === by ? WORDS.you : e.by))];
|
|
427
|
+
if (others.length) return { error: ERR.batchChangedSince(others), conflict: true };
|
|
428
|
+
const then = boardAt(board, first.version - 1);
|
|
429
|
+
if (!then) return { error: ERR.versionNotKept(first.version - 1) };
|
|
430
|
+
const back = editBoard(board, [{ op: "restore", to: contentOf(then) }], false, by, BOARD_STEPS.undoWhat, [], void 0, { why: BOARD_STEPS.undoWhy(first.why || first.what), activity: null });
|
|
431
|
+
return decide(back, batch, by, "undone");
|
|
432
|
+
}
|
|
433
|
+
function restoreBoard(board, version, by) {
|
|
434
|
+
const then = boardAt(board, version);
|
|
435
|
+
if (!then) return { error: ERR.versionNotKept(version) };
|
|
436
|
+
return editBoard(board, [{ op: "restore", to: contentOf(then) }], false, by, BOARD_STEPS.restoreWhat, [], void 0, { why: BOARD_STEPS.restoreWhy(version), activity: null });
|
|
437
|
+
}
|
|
438
|
+
var id = z.string().min(1).max(LEN.id);
|
|
439
|
+
var n = z.number().finite();
|
|
440
|
+
var color = z.enum(NOTE_COLORS);
|
|
441
|
+
var cell = z.union([z.string().max(LEN.text), z.number().finite(), z.boolean(), z.null()]);
|
|
442
|
+
var col = z.object({ id, name: z.string().max(LEN.name), type: z.enum(COL_TYPES), options: z.array(z.string().max(LEN.label)).max(COUNT.wide).optional(), formula: z.string().max(LEN.line).optional(), total: z.enum(["sum", "avg", "count"]).nullable().optional(), width: n.optional() });
|
|
443
|
+
var notePatch = z.object({
|
|
444
|
+
text: z.string().max(BOARD.maxText),
|
|
445
|
+
x: n,
|
|
446
|
+
y: n,
|
|
447
|
+
w: n,
|
|
448
|
+
h: n,
|
|
449
|
+
color,
|
|
450
|
+
frame: z.string().max(LEN.id).nullable(),
|
|
451
|
+
owner: z.string().max(LEN.label),
|
|
452
|
+
due: z.string().max(LEN.id),
|
|
453
|
+
shape: z.enum(SHAPES),
|
|
454
|
+
title: z.string().max(LEN.title),
|
|
455
|
+
size: z.enum(TEXT_SIZES),
|
|
456
|
+
points: z.array(n).max(COUNT.points),
|
|
457
|
+
icon: z.string().max(LEN.short),
|
|
458
|
+
pen: z.enum(PENS),
|
|
459
|
+
dashed: z.boolean(),
|
|
460
|
+
pressure: z.array(n).max(COUNT.points),
|
|
461
|
+
brush: z.enum(BRUSHES),
|
|
462
|
+
weight: n
|
|
463
|
+
}).partial();
|
|
464
|
+
var framePatch = z.object({ title: z.string().max(LEN.title), subtitle: z.string().max(LEN.line), x: n, y: n, w: n, h: n }).partial();
|
|
465
|
+
var linkPatch = z.object({ label: z.string().max(LEN.name), route: z.enum(ROUTES), dashed: z.boolean(), arrow: z.enum(["end", "both", "none"]) }).partial();
|
|
466
|
+
var OpSchema = z.discriminatedUnion("op", [
|
|
467
|
+
z.object({ op: z.literal("title"), title: z.string().max(LEN.title) }),
|
|
468
|
+
z.object({ op: z.literal("note.add"), note: notePatch.extend({ id, text: z.string().max(BOARD.maxText), x: n, y: n }) }),
|
|
469
|
+
z.object({ op: z.literal("note.update"), id, patch: notePatch }),
|
|
470
|
+
z.object({ op: z.literal("note.remove"), id }),
|
|
471
|
+
z.object({ op: z.literal("frame.add"), frame: framePatch.extend({ id, title: z.string().max(LEN.title), x: n, y: n }) }),
|
|
472
|
+
z.object({ op: z.literal("frame.update"), id, patch: framePatch }),
|
|
473
|
+
z.object({ op: z.literal("frame.move"), id, dx: n, dy: n }),
|
|
474
|
+
z.object({ op: z.literal("frame.remove"), id, keepNotes: z.boolean().optional() }),
|
|
475
|
+
z.object({ op: z.literal("link.add"), link: linkPatch.extend({ id, from: id, to: id }) }),
|
|
476
|
+
z.object({ op: z.literal("link.update"), id, patch: linkPatch }),
|
|
477
|
+
z.object({ op: z.literal("link.remove"), id }),
|
|
478
|
+
z.object({ op: z.literal("tab.add"), tab: z.object({ id, name: z.string().max(LEN.name), columns: z.array(col).max(COUNT.wide).optional() }) }),
|
|
479
|
+
z.object({ op: z.literal("tab.rename"), tab: id, name: z.string().max(LEN.name) }),
|
|
480
|
+
z.object({ op: z.literal("tab.remove"), tab: id }),
|
|
481
|
+
z.object({ op: z.literal("col.add"), tab: id, col, at: z.number().int().min(0).optional() }),
|
|
482
|
+
z.object({ op: z.literal("col.update"), tab: id, id, patch: col.omit({ id: true }).partial() }),
|
|
483
|
+
z.object({ op: z.literal("col.remove"), tab: id, id }),
|
|
484
|
+
z.object({ op: z.literal("row.add"), tab: id, row: z.object({ id, cells: z.record(z.string(), cell) }), at: z.number().int().min(0).optional() }),
|
|
485
|
+
z.object({ op: z.literal("row.remove"), tab: id, id }),
|
|
486
|
+
z.object({ op: z.literal("cell.set"), tab: id, row: id, col: id, value: cell })
|
|
487
|
+
]);
|
|
488
|
+
var PatchInput = z.object({ ops: z.array(OpSchema).min(1).max(COUNT.bulk) });
|
|
489
|
+
|
|
490
|
+
// src/core/agent.ts
|
|
491
|
+
import { z as z2 } from "zod";
|
|
492
|
+
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
493
|
+
var icon = z2.string().trim().max(BOARD_ARGS.ref).optional().describe(TK_BOARDS.arg.icon);
|
|
494
|
+
var heading = z2.object({ title: z2.string().trim().min(1).max(BOARD_ARGS.headingTitle), subtitle: z2.string().trim().max(BOARD_ARGS.headingSubtitle).optional(), icon }).describe(TK_BOARDS.arg.heading);
|
|
495
|
+
var note = z2.object({
|
|
496
|
+
text: z2.string().trim().min(1).max(BOARD_ARGS.noteText),
|
|
497
|
+
title: z2.string().trim().max(BOARD_ARGS.itemTitle).optional().describe(TK_BOARDS.arg.noteTitle),
|
|
498
|
+
icon,
|
|
499
|
+
owner: z2.string().trim().max(BOARD_ARGS.owner).optional().describe(TK_BOARDS.arg.noteOwner),
|
|
500
|
+
due: z2.string().trim().max(BOARD_ARGS.due).optional().describe(TK_BOARDS.arg.noteDue),
|
|
501
|
+
color: z2.enum(NOTE_COLORS).optional()
|
|
502
|
+
});
|
|
503
|
+
var section = z2.object({ title: z2.string().trim().min(1).max(BOARD_ARGS.sectionTitle), subtitle: z2.string().trim().max(BOARD_ARGS.subtitle).optional().describe(TK_BOARDS.arg.sectionSubtitle), notes: z2.array(note).max(BOARD_ARGS.sectionNotes).default([]) });
|
|
504
|
+
var FREE = BOARD.draw.free;
|
|
505
|
+
var drawItem = z2.object({
|
|
506
|
+
key: z2.string().trim().min(1).max(BOARD_ARGS.ref).optional().describe(TK_BOARDS.arg.itemKey),
|
|
507
|
+
shape: z2.enum(["box", "note", "ellipse", "pill", "cloud", "cylinder", "text", "sticker", "dot"]).optional().describe(TK_BOARDS.arg.shape),
|
|
508
|
+
pen: z2.enum(PENS).optional().describe(TK_BOARDS.arg.pen),
|
|
509
|
+
dashed: z2.boolean().optional().describe(TK_BOARDS.arg.dashed),
|
|
510
|
+
title: z2.string().trim().max(BOARD_ARGS.itemTitle).optional().describe(TK_BOARDS.arg.itemTitle),
|
|
511
|
+
text: z2.string().trim().max(BOARD_ARGS.itemText).optional(),
|
|
512
|
+
icon,
|
|
513
|
+
when: z2.string().trim().max(BOARD_ARGS.linkLabel).optional().describe(TK_BOARDS.arg.when),
|
|
514
|
+
color: z2.enum(NOTE_COLORS).optional().describe(TK_BOARDS.arg.color),
|
|
515
|
+
size: z2.enum(TEXT_SIZES).optional(),
|
|
516
|
+
owner: z2.string().trim().max(BOARD_ARGS.owner).optional(),
|
|
517
|
+
due: z2.string().trim().max(BOARD_ARGS.due).optional()
|
|
518
|
+
});
|
|
519
|
+
var boardArg = z2.string().trim().min(1).max(BOARD_ARGS.ref).describe(TK_BOARDS.arg.board);
|
|
520
|
+
var answer = z2.string().trim().max(BOARD_ARGS.answer).optional();
|
|
521
|
+
var qa = { why: answer.describe(TK_BOARDS.arg.qWhy), who: answer.describe(TK_BOARDS.arg.qWho), when: answer.describe(TK_BOARDS.arg.qWhen), where: answer.describe(TK_BOARDS.arg.qWhere), how: answer.describe(TK_BOARDS.arg.qHow), howMuch: answer.describe(TK_BOARDS.arg.qHowMuch), assumes: answer.describe(TK_BOARDS.arg.qAssumes) };
|
|
522
|
+
var freeItem = z2.object({
|
|
523
|
+
key: z2.string().trim().min(1).max(BOARD_ARGS.ref).describe(TK_BOARDS.arg.freeKey),
|
|
524
|
+
x: z2.number().finite().min(0).max(BOARD_ARGS.freeSpan).describe(TK_BOARDS.arg.itemX),
|
|
525
|
+
y: z2.number().finite().min(0).max(BOARD_ARGS.freeSpan).describe(TK_BOARDS.arg.itemY),
|
|
526
|
+
form: z2.enum(FORMS).optional().describe(TK_BOARDS.arg.form),
|
|
527
|
+
size: z2.enum(["s", "m", "l", "xl"]).optional().describe(TK_BOARDS.arg.size),
|
|
528
|
+
w: z2.number().finite().min(BOARD.minSize.shape.w).max(FREE.w).optional().describe(TK_BOARDS.arg.itemW),
|
|
529
|
+
h: z2.number().finite().min(BOARD.minSize.shape.h).max(FREE.w).optional().describe(TK_BOARDS.arg.itemH),
|
|
530
|
+
layer: z2.number().int().min(0).max(9).optional().describe(TK_BOARDS.arg.layer),
|
|
531
|
+
title: z2.string().trim().max(BOARD_ARGS.itemTitle).optional().describe(TK_BOARDS.arg.freeTitle),
|
|
532
|
+
text: z2.string().trim().max(BOARD_ARGS.itemText).optional().describe(TK_BOARDS.arg.itemText),
|
|
533
|
+
tone: z2.enum(TONES).optional().describe(TK_BOARDS.arg.tone),
|
|
534
|
+
icon,
|
|
535
|
+
...qa,
|
|
536
|
+
note: z2.string().trim().max(BOARD_ARGS.say).optional().describe(TK_BOARDS.arg.nodeNote)
|
|
537
|
+
});
|
|
538
|
+
var freeLink = z2.object({
|
|
539
|
+
from: z2.string().trim().min(1).max(BOARD_ARGS.ref).describe(TK_BOARDS.arg.linkFrom),
|
|
540
|
+
to: z2.string().trim().min(1).max(BOARD_ARGS.ref).describe(TK_BOARDS.arg.linkTo),
|
|
541
|
+
label: z2.string().trim().max(BOARD_ARGS.linkLabel).optional().describe(TK_BOARDS.arg.linkLabel),
|
|
542
|
+
dashed: z2.boolean().optional().describe(TK_BOARDS.arg.dashed)
|
|
543
|
+
});
|
|
544
|
+
var freeBeat = z2.object({
|
|
545
|
+
say: z2.string().trim().min(1).max(BOARD_ARGS.say).describe(TK_BOARDS.arg.say),
|
|
546
|
+
items: z2.array(freeItem).max(BOARD_ARGS.beatItems).optional().describe(TK_BOARDS.arg.beatItems),
|
|
547
|
+
links: z2.array(freeLink).max(BOARD_ARGS.beatItems).optional().describe(TK_BOARDS.arg.beatLinks)
|
|
548
|
+
});
|
|
549
|
+
var why = z2.string().trim().max(BOARD_ARGS.why).optional().describe(TK_BOARDS.arg.why);
|
|
550
|
+
var CreateWhiteboardInput = z2.object({
|
|
551
|
+
title: z2.string().trim().min(BOARD_ARGS.title.min).max(BOARD_ARGS.title.max),
|
|
552
|
+
layout: z2.enum(["columns", "timeline", "grid"]).default("columns").describe(TK_BOARDS.createWhiteboard.layout),
|
|
553
|
+
heading: heading.optional(),
|
|
554
|
+
sections: z2.array(section).min(1).max(BOARD_ARGS.sections),
|
|
555
|
+
why
|
|
556
|
+
});
|
|
557
|
+
var DrawWhiteboardInput = z2.object({
|
|
558
|
+
board: z2.string().trim().min(1).max(BOARD_ARGS.ref).optional().describe(TK_BOARDS.draw.board),
|
|
559
|
+
title: z2.string().trim().min(BOARD_ARGS.title.min).max(BOARD_ARGS.title.max).optional().describe(TK_BOARDS.draw.title),
|
|
560
|
+
headline: z2.string().trim().min(1).max(BOARD_ARGS.headingTitle).optional().describe(TK_BOARDS.draw.headline),
|
|
561
|
+
context: z2.string().trim().max(BOARD_ARGS.headingSubtitle).optional().describe(TK_BOARDS.draw.context),
|
|
562
|
+
icon,
|
|
563
|
+
beats: z2.array(freeBeat).min(1).max(BOARD_ARGS.beats).describe(TK_BOARDS.draw.beats),
|
|
564
|
+
why
|
|
565
|
+
});
|
|
566
|
+
var UpdateWhiteboardInput = z2.object({
|
|
567
|
+
board: boardArg,
|
|
568
|
+
add_sections: z2.array(section).max(BOARD_ARGS.sections).optional(),
|
|
569
|
+
add_notes: z2.array(note.extend({ section: z2.string().trim().min(1).max(BOARD_ARGS.sectionTitle).optional().describe(TK_BOARDS.updateWhiteboard.noteSection) })).max(BOARD_ARGS.addNotes).optional(),
|
|
570
|
+
move_notes: z2.array(z2.object({ note_id: z2.string().min(1).max(BOARD_ARGS.ref), section: z2.string().trim().min(1).max(BOARD_ARGS.sectionTitle) })).max(BOARD_ARGS.moveNotes).optional(),
|
|
571
|
+
update_notes: z2.array(note.partial().extend({ note_id: z2.string().min(1).max(BOARD_ARGS.ref), title: z2.string().trim().max(BOARD_ARGS.itemTitle).optional(), shape: z2.enum(SHAPES).optional(), size: z2.enum(TEXT_SIZES).optional() })).max(BOARD_ARGS.updates).optional(),
|
|
572
|
+
update_links: z2.array(z2.object({ link_id: z2.string().min(1).max(BOARD_ARGS.ref), label: z2.string().trim().max(BOARD_ARGS.linkLabel).optional(), route: z2.enum(ROUTES).optional(), dashed: z2.boolean().optional(), arrow: z2.enum(["end", "both", "none"]).optional() })).max(BOARD_ARGS.updates).optional().describe(TK_BOARDS.updateWhiteboard.updateLinks),
|
|
573
|
+
remove_notes: z2.array(z2.string().min(1).max(BOARD_ARGS.ref)).max(BOARD_ARGS.moveNotes).optional(),
|
|
574
|
+
rename_sections: z2.array(z2.object({ section: z2.string().trim().min(1).max(BOARD_ARGS.sectionTitle), title: z2.string().trim().min(1).max(BOARD_ARGS.sectionTitle) })).max(BOARD_ARGS.sections).optional(),
|
|
575
|
+
remove_sections: z2.array(z2.string().trim().min(1).max(BOARD_ARGS.sectionTitle)).max(BOARD_ARGS.sections).optional().describe(TK_BOARDS.updateWhiteboard.removeSections),
|
|
576
|
+
add_links: z2.array(z2.object({ from: z2.string().trim().min(1).max(BOARD_ARGS.sectionTitle), to: z2.string().trim().min(1).max(BOARD_ARGS.sectionTitle), label: z2.string().trim().max(BOARD_ARGS.linkLabel).optional() })).max(BOARD_ARGS.addLinks).optional().describe(TK_BOARDS.updateWhiteboard.addLinks),
|
|
577
|
+
remove_links: z2.array(z2.string().min(1).max(BOARD_ARGS.ref)).max(BOARD_ARGS.updates).optional().describe(TK_BOARDS.updateWhiteboard.removeLinks),
|
|
578
|
+
extend_timeline: z2.object({ road: z2.string().trim().min(1).max(BOARD_ARGS.ref).optional(), items: z2.array(drawItem).min(1).max(BOARD_ARGS.sectionNotes) }).optional().describe(TK_BOARDS.updateWhiteboard.extendTimeline),
|
|
579
|
+
why
|
|
580
|
+
});
|
|
581
|
+
var ReadBoardInput = z2.object({ board: boardArg, note_ids: z2.array(z2.string().min(1).max(BOARD_ARGS.ref)).max(BOARD_ARGS.noteIds).optional() });
|
|
582
|
+
var DEFAULT_NAMES = { create: "create_whiteboard", draw: "draw_whiteboard", update: "update_whiteboard", read: "read_board", list: "list_boards" };
|
|
583
|
+
var hostWords = (text, names, show) => text.replace(/\s*Show it (again )?with present[^.]*\.?/g, "").replace(/\bcreate_whiteboard\b/g, names.create).replace(/\bdraw_whiteboard\b/g, names.draw).replace(/\bupdate_whiteboard\b/g, names.update).replace(/\bread_board\b/g, names.read).replace(/\blist_boards\b/g, names.list).trim();
|
|
584
|
+
function toolSpecs(show, names = DEFAULT_NAMES) {
|
|
585
|
+
const spec = (name, description, schema, shows = true) => ({
|
|
586
|
+
name,
|
|
587
|
+
description: `${hostWords(description, names, show)}${shows && show ? ` ${show}` : ""}`,
|
|
588
|
+
parameters: zodToJsonSchema(schema, { $refStrategy: "none" })
|
|
589
|
+
});
|
|
590
|
+
return [
|
|
591
|
+
spec(names.create, TK_BOARDS.createWhiteboard.description, CreateWhiteboardInput),
|
|
592
|
+
spec(names.draw, TK_BOARDS.draw.description, DrawWhiteboardInput),
|
|
593
|
+
spec(names.update, TK_BOARDS.updateWhiteboard.description, UpdateWhiteboardInput),
|
|
594
|
+
spec(names.read, TK_BOARDS.read.description, ReadBoardInput, false)
|
|
595
|
+
];
|
|
596
|
+
}
|
|
597
|
+
var summary = (b) => TK_BOARDS.boardSummary(b.frames.length, b.notes.length);
|
|
598
|
+
function planCreate(raw, via, batch = newBatch()) {
|
|
599
|
+
const i = CreateWhiteboardInput.parse(raw);
|
|
600
|
+
const ops = layoutOps(i.sections, i.layout, void 0, void 0, i.heading ?? { title: i.title }).ops;
|
|
601
|
+
return { create: { title: i.title, mode: "whiteboard" }, steps: buildSteps(ops, batch, via, void 0, i.why), problems: [] };
|
|
602
|
+
}
|
|
603
|
+
function planDraw(raw, target, via, batch = newBatch()) {
|
|
604
|
+
const i = DrawWhiteboardInput.parse(raw);
|
|
605
|
+
if (!target && !i.title) throw new Error(TK_BOARDS.draw.needTarget);
|
|
606
|
+
const story = { headline: i.headline ?? i.title ?? target.title, ...i.context ? { context: i.context } : {}, ...i.icon ? { icon: i.icon } : {}, beats: i.beats };
|
|
607
|
+
const { steps, skipped } = layFree(story, target ? nextOrigin(target) : { x: 0, y: 0 }, target ?? void 0);
|
|
608
|
+
return { ...target ? {} : { create: { title: i.title, mode: "whiteboard" } }, steps: toldSteps(steps, batch, via, i.why), problems: [], skippedKeys: skipped };
|
|
609
|
+
}
|
|
610
|
+
var sectionOf = (b, key) => b.frames.find((f) => f.id === key) ?? b.frames.find((f) => f.title.toLowerCase() === key.trim().toLowerCase());
|
|
611
|
+
function planUpdate(raw, board, via, batch = newBatch()) {
|
|
612
|
+
const i = UpdateWhiteboardInput.parse(raw);
|
|
613
|
+
let b = board;
|
|
614
|
+
const steps = [];
|
|
615
|
+
const problems = [];
|
|
616
|
+
const stage = (s) => {
|
|
617
|
+
for (const step of s) b = applyOps(b, step.ops, TK_BOARDS.agent);
|
|
618
|
+
steps.push(...s);
|
|
619
|
+
};
|
|
620
|
+
if (i.extend_timeline) {
|
|
621
|
+
const ext = extendTimelineOps(b, i.extend_timeline.items, i.extend_timeline.road);
|
|
622
|
+
if (!ext) problems.push(TK_BOARDS.updateWhiteboard.noRoad);
|
|
623
|
+
else stage(buildSteps(ext.ops, batch, via, TK_BOARDS.updateWhiteboard.extendWhat, i.why, true));
|
|
624
|
+
}
|
|
625
|
+
if (i.add_sections?.length) {
|
|
626
|
+
const added = layoutOps(i.add_sections, "columns", nextOrigin(b)).ops;
|
|
627
|
+
stage([{ ops: added, what: TK_BOARDS.updateWhiteboard.addSections, why: i.why ?? TK_BOARDS.updateWhiteboard.addSections, activity: planActivity(added, TK_BOARDS.updateWhiteboard.addSections, batch, via), pauseMs: 0, planFirst: true }]);
|
|
628
|
+
}
|
|
629
|
+
const ops = [];
|
|
630
|
+
let loose = 0;
|
|
631
|
+
const free = nextOrigin(b);
|
|
632
|
+
for (const n2 of i.add_notes ?? []) {
|
|
633
|
+
const f = n2.section ? sectionOf(b, n2.section) : null;
|
|
634
|
+
if (n2.section && !f) {
|
|
635
|
+
problems.push(TK_BOARDS.updateWhiteboard.noSection(n2.section));
|
|
636
|
+
continue;
|
|
637
|
+
}
|
|
638
|
+
const at = f ? { x: f.x + SECTION_NOTE_INSET, y: f.y + f.h } : { x: free.x + loose % LOOSE_NOTES.perRow * LOOSE_NOTES.dx, y: free.y + Math.floor(loose++ / LOOSE_NOTES.perRow) * LOOSE_NOTES.dy };
|
|
639
|
+
ops.push({ op: "note.add", note: { id: uid("n"), text: n2.text, ...at, frame: f?.id ?? null, ...n2.owner ? { owner: n2.owner } : {}, ...n2.due ? { due: n2.due } : {}, ...n2.color ? { color: n2.color } : {} } });
|
|
640
|
+
}
|
|
641
|
+
for (const m of i.move_notes ?? []) {
|
|
642
|
+
const f = sectionOf(b, m.section);
|
|
643
|
+
if (!f) problems.push(TK_BOARDS.updateWhiteboard.noSection(m.section));
|
|
644
|
+
else if (!b.notes.some((x) => x.id === m.note_id)) problems.push(TK_BOARDS.updateWhiteboard.noNote(m.note_id));
|
|
645
|
+
else ops.push({ op: "note.update", id: m.note_id, patch: { frame: f.id } });
|
|
646
|
+
}
|
|
647
|
+
for (const u of i.update_notes ?? []) {
|
|
648
|
+
if (!b.notes.some((x) => x.id === u.note_id)) {
|
|
649
|
+
problems.push(TK_BOARDS.updateWhiteboard.noNote(u.note_id));
|
|
650
|
+
continue;
|
|
651
|
+
}
|
|
652
|
+
const { note_id, ...patch } = u;
|
|
653
|
+
ops.push({ op: "note.update", id: note_id, patch });
|
|
654
|
+
}
|
|
655
|
+
for (const id2 of i.remove_notes ?? []) ops.push({ op: "note.remove", id: id2 });
|
|
656
|
+
for (const r of i.rename_sections ?? []) {
|
|
657
|
+
const f = sectionOf(b, r.section);
|
|
658
|
+
if (f) ops.push({ op: "frame.update", id: f.id, patch: { title: r.title } });
|
|
659
|
+
else problems.push(TK_BOARDS.updateWhiteboard.noSection(r.section));
|
|
660
|
+
}
|
|
661
|
+
for (const s of i.remove_sections ?? []) {
|
|
662
|
+
const f = sectionOf(b, s);
|
|
663
|
+
if (f) ops.push({ op: "frame.remove", id: f.id });
|
|
664
|
+
else problems.push(TK_BOARDS.updateWhiteboard.noSection(s));
|
|
665
|
+
}
|
|
666
|
+
const endOf = (key) => b.notes.find((x) => x.id === key)?.id ?? sectionOf(b, key)?.id;
|
|
667
|
+
for (const l of i.add_links ?? []) {
|
|
668
|
+
const from = endOf(l.from), to = endOf(l.to);
|
|
669
|
+
if (!from || !to) {
|
|
670
|
+
problems.push(TK_BOARDS.updateWhiteboard.noEnds(l.from, l.to));
|
|
671
|
+
continue;
|
|
672
|
+
}
|
|
673
|
+
if (from === to || b.links.some((x) => x.from === from && x.to === to)) continue;
|
|
674
|
+
const auto = b.links.some((x) => x.route === "auto") || b.edits.some((e) => e.told);
|
|
675
|
+
ops.push({ op: "link.add", link: { id: uid("l"), from, to, ...auto ? { route: "auto" } : {}, ...l.label ? { label: l.label } : {} } });
|
|
676
|
+
}
|
|
677
|
+
for (const u of i.update_links ?? []) {
|
|
678
|
+
const { link_id, ...patch } = u;
|
|
679
|
+
if (b.links.some((x) => x.id === link_id)) ops.push({ op: "link.update", id: link_id, patch });
|
|
680
|
+
else problems.push(TK_BOARDS.updateWhiteboard.noLink(link_id));
|
|
681
|
+
}
|
|
682
|
+
for (const id2 of i.remove_links ?? []) {
|
|
683
|
+
if (b.links.some((x) => x.id === id2)) ops.push({ op: "link.remove", id: id2 });
|
|
684
|
+
else problems.push(TK_BOARDS.updateWhiteboard.noLink(id2));
|
|
685
|
+
}
|
|
686
|
+
const tidy = i.move_notes?.length || i.add_notes?.some((n2) => n2.section) || i.remove_sections?.length ? tidyOps(applyOps(b, ops, TK_BOARDS.agent)) : [];
|
|
687
|
+
if (ops.length) {
|
|
688
|
+
const all = [...ops, ...tidy];
|
|
689
|
+
steps.push({ ops: all, what: TK_BOARDS.updateWhiteboard.edit, why: i.why ?? TK_BOARDS.updateWhiteboard.edit, activity: { ...planActivity(ops, TK_BOARDS.updateWhiteboard.edit, batch, via), keys: opKeys(ops).slice(0, 60) }, pauseMs: 0, planFirst: true });
|
|
690
|
+
}
|
|
691
|
+
return { steps, problems };
|
|
692
|
+
}
|
|
693
|
+
function readBoard(raw, board) {
|
|
694
|
+
const i = ReadBoardInput.parse(raw);
|
|
695
|
+
const last = board.edits.at(-1);
|
|
696
|
+
return `${TK_BOARDS.read.head(board.ref, board.title, TK_BOARDS.boardKind, summary(board), last?.by ?? board.updatedBy)}
|
|
697
|
+
${boardText(board, i.note_ids ? new Set(i.note_ids) : void 0)}`;
|
|
698
|
+
}
|
|
699
|
+
function resultText(board, plan, show) {
|
|
700
|
+
const problems = plan.problems.length ? TK_BOARDS.skipped(plan.problems.join(TK_BOARDS.problemSep)) : "";
|
|
701
|
+
const keys = plan.skippedKeys?.length ? TK_BOARDS.draw.skippedKeys(plan.skippedKeys) : "";
|
|
702
|
+
return `Board ${board.ref} "${board.title}": ${summary(board)}.${problems}${keys} ${show}`.trim();
|
|
703
|
+
}
|
|
704
|
+
export {
|
|
705
|
+
BOARD,
|
|
706
|
+
BOARD_STEPS,
|
|
707
|
+
BRUSHES,
|
|
708
|
+
COL_TYPES,
|
|
709
|
+
CreateWhiteboardInput,
|
|
710
|
+
DEFAULT_NAMES,
|
|
711
|
+
DrawWhiteboardInput,
|
|
712
|
+
FORMS,
|
|
713
|
+
ILLUSTRATIONS,
|
|
714
|
+
LABEL_CHAR,
|
|
715
|
+
LEN,
|
|
716
|
+
LINE_ICONS,
|
|
717
|
+
MAX_COLS,
|
|
718
|
+
MAX_LAYER,
|
|
719
|
+
MAX_NOTES,
|
|
720
|
+
MAX_ROWS,
|
|
721
|
+
NOTE_COLORS,
|
|
722
|
+
NOTE_H,
|
|
723
|
+
NOTE_W,
|
|
724
|
+
OUTLINED,
|
|
725
|
+
OpSchema,
|
|
726
|
+
PENS,
|
|
727
|
+
POLYGONS,
|
|
728
|
+
PatchInput,
|
|
729
|
+
ROUTES,
|
|
730
|
+
ReadBoardInput,
|
|
731
|
+
SHAPES,
|
|
732
|
+
TEXT_SIZES,
|
|
733
|
+
TONES,
|
|
734
|
+
UpdateWhiteboardInput,
|
|
735
|
+
WIRE,
|
|
736
|
+
applyOps,
|
|
737
|
+
applyStep,
|
|
738
|
+
autoWires,
|
|
739
|
+
blockHeight,
|
|
740
|
+
boardAt,
|
|
741
|
+
boardText,
|
|
742
|
+
buildSteps,
|
|
743
|
+
cellValue,
|
|
744
|
+
colorFor,
|
|
745
|
+
columnTotal,
|
|
746
|
+
contentOf,
|
|
747
|
+
createBoard,
|
|
748
|
+
drawOps,
|
|
749
|
+
editBoard,
|
|
750
|
+
evalFormula,
|
|
751
|
+
extendTimelineOps,
|
|
752
|
+
foldIntoBase,
|
|
753
|
+
formulaRefs,
|
|
754
|
+
frameAt,
|
|
755
|
+
freeSpot,
|
|
756
|
+
historyOf,
|
|
757
|
+
isIllustration,
|
|
758
|
+
isLineIcon,
|
|
759
|
+
isPolygon,
|
|
760
|
+
keepBatch,
|
|
761
|
+
labelSize,
|
|
762
|
+
labelSpot,
|
|
763
|
+
layFree,
|
|
764
|
+
layoutOps,
|
|
765
|
+
liveActivity,
|
|
766
|
+
markStrokes,
|
|
767
|
+
minSize,
|
|
768
|
+
newBatch,
|
|
769
|
+
newRef,
|
|
770
|
+
nextOrigin,
|
|
771
|
+
noEmoji,
|
|
772
|
+
noteHeight,
|
|
773
|
+
obstacles,
|
|
774
|
+
opKeys,
|
|
775
|
+
overlaps,
|
|
776
|
+
pasteOps,
|
|
777
|
+
pendingBatchOf,
|
|
778
|
+
planActivity,
|
|
779
|
+
planCreate,
|
|
780
|
+
planDraw,
|
|
781
|
+
planOf,
|
|
782
|
+
planUpdate,
|
|
783
|
+
polygonPad,
|
|
784
|
+
polygonPoints,
|
|
785
|
+
publicBoard,
|
|
786
|
+
rangeTsv,
|
|
787
|
+
readBoard,
|
|
788
|
+
restoreBoard,
|
|
789
|
+
resultText,
|
|
790
|
+
routeWires,
|
|
791
|
+
setActivity,
|
|
792
|
+
smoothPoints,
|
|
793
|
+
snapshot,
|
|
794
|
+
stepsOf,
|
|
795
|
+
tabRows,
|
|
796
|
+
taskBoardOps,
|
|
797
|
+
taskShape,
|
|
798
|
+
tidyOps,
|
|
799
|
+
toldSteps,
|
|
800
|
+
toolSpecs,
|
|
801
|
+
uid,
|
|
802
|
+
undoBatch,
|
|
803
|
+
validIcon,
|
|
804
|
+
wireBoxes,
|
|
805
|
+
wireLabel,
|
|
806
|
+
withChat,
|
|
807
|
+
wrapLines
|
|
808
|
+
};
|
|
809
|
+
//# sourceMappingURL=index.js.map
|