@absolutejs/ai 0.0.31 → 0.0.33

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.
@@ -0,0 +1,552 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __name = (target, name) => {
5
+ Object.defineProperty(target, "name", {
6
+ value: name,
7
+ enumerable: false,
8
+ configurable: true
9
+ });
10
+ return target;
11
+ };
12
+ var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
13
+ var __typeError = (msg) => {
14
+ throw TypeError(msg);
15
+ };
16
+ var __defNormalProp = (obj, key, value) => (key in obj) ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
17
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
18
+ var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
19
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
20
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
21
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
22
+ var __decoratorStart = (base) => [, , , __create(base?.[__knownSymbol("metadata")] ?? null)];
23
+ var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
24
+ var __expectFn = (fn) => fn !== undefined && typeof fn !== "function" ? __typeError("Function expected") : fn;
25
+ var __decoratorContext = (kind, name, done, metadata, fns) => ({
26
+ kind: __decoratorStrings[kind],
27
+ name,
28
+ metadata,
29
+ addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null))
30
+ });
31
+ var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
32
+ var __runInitializers = (array, flags, self, value) => {
33
+ for (var i = 0, fns = array[flags >> 1], n = fns && fns.length;i < n; i++)
34
+ flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
35
+ return value;
36
+ };
37
+ var __decorateElement = (array, flags, name, decorators, target, extra) => {
38
+ var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
39
+ var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
40
+ var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
41
+ var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : {
42
+ get [name]() {
43
+ return __privateGet(this, extra);
44
+ },
45
+ set [name](x) {
46
+ __privateSet(this, extra, x);
47
+ }
48
+ }, name));
49
+ k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
50
+ for (var i = decorators.length - 1;i >= 0; i--) {
51
+ ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
52
+ if (k) {
53
+ ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => (name in x) };
54
+ if (k ^ 3)
55
+ access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
56
+ if (k > 2)
57
+ access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
58
+ }
59
+ it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? undefined : { get: desc.get, set: desc.set } : target, ctx);
60
+ done._ = 1;
61
+ if (k ^ 4 || it === undefined)
62
+ __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
63
+ else if (typeof it !== "object" || it === null)
64
+ __typeError("Object expected");
65
+ else
66
+ __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
67
+ }
68
+ return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
69
+ };
70
+
71
+ // src/ai/ui/uiCards.ts
72
+ var createUiCards = (definitions) => {
73
+ const byName = new Map(definitions.map((definition) => [definition.name, definition]));
74
+ const tools = Object.fromEntries(definitions.map((definition) => [
75
+ definition.name,
76
+ {
77
+ description: definition.description,
78
+ handler: () => definition.ack,
79
+ input: definition.inputSchema
80
+ }
81
+ ]));
82
+ const collect = (calls) => {
83
+ const events = [];
84
+ for (const call of calls) {
85
+ const definition = byName.get(call.name);
86
+ if (!definition)
87
+ continue;
88
+ const data = definition.parse(call.input);
89
+ if (data !== null)
90
+ events.push({ card: definition.name, data });
91
+ }
92
+ return events;
93
+ };
94
+ return { collect, has: (name) => byName.has(name), tools };
95
+ };
96
+ // src/ai/ui/catalog.ts
97
+ var CHART_TYPES = ["bar", "line", "donut"];
98
+ var CHART_MAX_SERIES = 8;
99
+ var CHART_MAX_POINTS = 24;
100
+ var TABLE_MAX_COLUMNS = 8;
101
+ var TABLE_MAX_ROWS = 30;
102
+ var STAT_TILES_MAX = 6;
103
+ var LABEL_MAX_CHARS = 80;
104
+ var TITLE_MAX_CHARS = 120;
105
+ var CELL_MAX_CHARS = 160;
106
+ var UNIT_MAX_CHARS = 8;
107
+ var isRecord = (value) => typeof value === "object" && value !== null;
108
+ var cleanString = (value, maxChars) => typeof value === "string" && value.trim().length > 0 ? value.trim().slice(0, maxChars) : null;
109
+ var cleanStringArray = (value, maxItems, maxChars) => {
110
+ if (!Array.isArray(value) || value.length === 0)
111
+ return null;
112
+ const cleaned = [];
113
+ for (const entry of value.slice(0, maxItems)) {
114
+ const text = cleanString(entry, maxChars);
115
+ cleaned.push(text ?? "");
116
+ }
117
+ return cleaned;
118
+ };
119
+ var cleanNumberArray = (value, maxItems) => {
120
+ if (!Array.isArray(value) || value.length === 0)
121
+ return null;
122
+ const cleaned = [];
123
+ for (const entry of value.slice(0, maxItems)) {
124
+ if (typeof entry !== "number" || !Number.isFinite(entry))
125
+ return null;
126
+ cleaned.push(entry);
127
+ }
128
+ return cleaned;
129
+ };
130
+ var parseChartSpec = (input) => {
131
+ if (!isRecord(input))
132
+ return null;
133
+ const type = CHART_TYPES.find((entry) => entry === input.type);
134
+ const title = cleanString(input.title, TITLE_MAX_CHARS);
135
+ const labels = cleanStringArray(input.labels, CHART_MAX_POINTS, LABEL_MAX_CHARS);
136
+ if (!type || !title || !labels)
137
+ return null;
138
+ if (!Array.isArray(input.series) || input.series.length === 0)
139
+ return null;
140
+ const series = [];
141
+ for (const raw of input.series.slice(0, CHART_MAX_SERIES)) {
142
+ if (!isRecord(raw))
143
+ return null;
144
+ const name = cleanString(raw.name, LABEL_MAX_CHARS);
145
+ const values = cleanNumberArray(raw.values, CHART_MAX_POINTS);
146
+ if (!name || !values)
147
+ return null;
148
+ if (values.length !== labels.length)
149
+ return null;
150
+ series.push({ name, values });
151
+ }
152
+ if (type === "donut") {
153
+ const [only] = series;
154
+ if (series.length !== 1 || !only)
155
+ return null;
156
+ if (only.values.some((value) => value < 0))
157
+ return null;
158
+ }
159
+ const spec = { labels, series, title, type };
160
+ const unitPrefix = cleanString(input.unitPrefix, UNIT_MAX_CHARS);
161
+ const unitSuffix = cleanString(input.unitSuffix, UNIT_MAX_CHARS);
162
+ if (unitPrefix)
163
+ spec.unitPrefix = unitPrefix;
164
+ if (unitSuffix)
165
+ spec.unitSuffix = unitSuffix;
166
+ return spec;
167
+ };
168
+ var parseTableSpec = (input) => {
169
+ if (!isRecord(input))
170
+ return null;
171
+ const columns = cleanStringArray(input.columns, TABLE_MAX_COLUMNS, LABEL_MAX_CHARS);
172
+ if (!columns)
173
+ return null;
174
+ if (!Array.isArray(input.rows) || input.rows.length === 0)
175
+ return null;
176
+ const rows = [];
177
+ for (const raw of input.rows.slice(0, TABLE_MAX_ROWS)) {
178
+ const cells = cleanStringArray(raw, TABLE_MAX_COLUMNS, CELL_MAX_CHARS);
179
+ if (!cells)
180
+ return null;
181
+ while (cells.length < columns.length)
182
+ cells.push("");
183
+ rows.push(cells.slice(0, columns.length));
184
+ }
185
+ const spec = { columns, rows };
186
+ const title = cleanString(input.title, TITLE_MAX_CHARS);
187
+ if (title)
188
+ spec.title = title;
189
+ return spec;
190
+ };
191
+ var parseStatTilesSpec = (input) => {
192
+ if (!isRecord(input))
193
+ return null;
194
+ if (!Array.isArray(input.tiles) || input.tiles.length === 0)
195
+ return null;
196
+ const tiles = [];
197
+ for (const raw of input.tiles.slice(0, STAT_TILES_MAX)) {
198
+ if (!isRecord(raw))
199
+ return null;
200
+ const label = cleanString(raw.label, LABEL_MAX_CHARS);
201
+ const value = cleanString(raw.value, LABEL_MAX_CHARS);
202
+ if (!label || !value)
203
+ return null;
204
+ const tile = { label, value };
205
+ const delta = cleanString(raw.delta, LABEL_MAX_CHARS);
206
+ if (delta)
207
+ tile.delta = delta;
208
+ if (raw.deltaDirection === "up" || raw.deltaDirection === "down" || raw.deltaDirection === "flat") {
209
+ tile.deltaDirection = raw.deltaDirection;
210
+ }
211
+ tiles.push(tile);
212
+ }
213
+ return { tiles };
214
+ };
215
+ var SERIES_SCHEMA = {
216
+ properties: {
217
+ name: { description: "Series name (shown in the legend)", type: "string" },
218
+ values: {
219
+ description: "One number per label, same order as labels",
220
+ items: { type: "number" },
221
+ type: "array"
222
+ }
223
+ },
224
+ required: ["name", "values"],
225
+ type: "object"
226
+ };
227
+ var chartCard = {
228
+ ack: "(chart rendered inline — do not repeat its numbers as text; add at most a 1-2 line takeaway)",
229
+ description: "Render a real chart inline in the chat from data you have (tool results, the conversation). Use whenever numbers COMPARE or TREND: revenue by partner (bar), pipeline over time (line), share of a whole (donut). Rules: bar/line take up to 8 series aligned to the same labels; donut takes exactly ONE series of non-negative values (one slice per label). Prefer a chart over a wall of numbers, but never invent data for it.",
230
+ inputSchema: {
231
+ properties: {
232
+ labels: {
233
+ description: "Category labels — x-axis for bar/line, slice names for donut (max 24)",
234
+ items: { type: "string" },
235
+ type: "array"
236
+ },
237
+ series: {
238
+ description: "Data series (max 8; donut exactly 1)",
239
+ items: SERIES_SCHEMA,
240
+ type: "array"
241
+ },
242
+ title: { description: "Short chart title", type: "string" },
243
+ type: { enum: [...CHART_TYPES], type: "string" },
244
+ unitPrefix: {
245
+ description: 'Prepended to values, e.g. "$"',
246
+ type: "string"
247
+ },
248
+ unitSuffix: {
249
+ description: 'Appended to values, e.g. "%"',
250
+ type: "string"
251
+ }
252
+ },
253
+ required: ["type", "title", "labels", "series"],
254
+ type: "object"
255
+ },
256
+ name: "render_chart",
257
+ parse: parseChartSpec
258
+ };
259
+ var tableCard = {
260
+ ack: "(table rendered inline — do not repeat its rows as text)",
261
+ description: "Render a compact data table inline in the chat (max 8 columns × 30 rows). Use for structured comparisons the member will scan — matches side by side, deal terms, task lists with dates. All cells are strings; format numbers yourself.",
262
+ inputSchema: {
263
+ properties: {
264
+ columns: {
265
+ description: "Column headers (max 8)",
266
+ items: { type: "string" },
267
+ type: "array"
268
+ },
269
+ rows: {
270
+ description: "Rows of cells, each aligned to columns (max 30)",
271
+ items: { items: { type: "string" }, type: "array" },
272
+ type: "array"
273
+ },
274
+ title: { description: "Optional table title", type: "string" }
275
+ },
276
+ required: ["columns", "rows"],
277
+ type: "object"
278
+ },
279
+ name: "render_table",
280
+ parse: parseTableSpec
281
+ };
282
+ var statTilesCard = {
283
+ ack: "(stat tiles rendered inline — do not repeat the numbers as text)",
284
+ description: "Render a row of headline stat tiles inline in the chat (max 6): a label, a big value, and an optional delta with direction. Use for the 2-4 numbers that ARE the answer — total attributed revenue, pipeline value, credits remaining — instead of burying them in prose.",
285
+ inputSchema: {
286
+ properties: {
287
+ tiles: {
288
+ description: "The tiles (max 6)",
289
+ items: {
290
+ properties: {
291
+ delta: {
292
+ description: 'Optional change note, e.g. "+12% vs last month"',
293
+ type: "string"
294
+ },
295
+ deltaDirection: { enum: ["up", "down", "flat"], type: "string" },
296
+ label: { description: "What the number is", type: "string" },
297
+ value: {
298
+ description: 'The formatted headline value, e.g. "$42,300"',
299
+ type: "string"
300
+ }
301
+ },
302
+ required: ["label", "value"],
303
+ type: "object"
304
+ },
305
+ type: "array"
306
+ }
307
+ },
308
+ required: ["tiles"],
309
+ type: "object"
310
+ },
311
+ name: "render_stat_tiles",
312
+ parse: parseStatTilesSpec
313
+ };
314
+ var BUILTIN_UI_CARDS = [chartCard, tableCard, statTilesCard];
315
+ // src/ai/ui/svg.ts
316
+ var LIGHT_UI_THEME = {
317
+ grid: "#e4e4e0",
318
+ palette: [
319
+ "#2a78d6",
320
+ "#1baf7a",
321
+ "#eda100",
322
+ "#008300",
323
+ "#4a3aa7",
324
+ "#e34948",
325
+ "#e87ba4",
326
+ "#eb6834"
327
+ ],
328
+ surface: "#fcfcfb",
329
+ textPrimary: "#0b0b0b",
330
+ textSecondary: "#52514e"
331
+ };
332
+ var DARK_UI_THEME = {
333
+ grid: "#333331",
334
+ palette: [
335
+ "#3987e5",
336
+ "#199e70",
337
+ "#c98500",
338
+ "#008300",
339
+ "#9085e9",
340
+ "#e66767",
341
+ "#d55181",
342
+ "#d95926"
343
+ ],
344
+ surface: "#1a1a19",
345
+ textPrimary: "#ffffff",
346
+ textSecondary: "#c3c2b7"
347
+ };
348
+ var WIDTH = 640;
349
+ var HEIGHT = 340;
350
+ var MARGIN = { bottom: 42, left: 56, right: 16, top: 64 };
351
+ var BAR_END_RADIUS = 4;
352
+ var MARK_GAP = 2;
353
+ var LINE_WIDTH = 2;
354
+ var MAX_DIRECT_LABELED_SERIES = 4;
355
+ var TICK_TARGET = 4;
356
+ var FONT = "system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif";
357
+ var escapeXml = (value) => value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
358
+ var formatValue = (value, spec) => {
359
+ const sign = value < 0 ? "-" : "";
360
+ const abs = Math.abs(value);
361
+ const compact = abs >= 1e6 ? `${(abs / 1e6).toFixed(1).replace(/\.0$/, "")}M` : abs >= 1e4 ? `${(abs / 1000).toFixed(1).replace(/\.0$/, "")}k` : abs >= 1000 ? abs.toLocaleString("en-US") : `${Number.isInteger(abs) ? abs : abs.toFixed(1)}`;
362
+ return `${sign}${spec.unitPrefix ?? ""}${compact}${spec.unitSuffix ?? ""}`;
363
+ };
364
+ var niceTicks = (min, max) => {
365
+ const span = max - min || 1;
366
+ const rough = span / TICK_TARGET;
367
+ const power = Math.pow(10, Math.floor(Math.log10(rough)));
368
+ const candidates = [1, 2, 5, 10].map((step2) => step2 * power);
369
+ const step = candidates.find((candidate) => candidate >= rough) ?? candidates[candidates.length - 1] ?? rough;
370
+ const start = Math.floor(min / step) * step;
371
+ const ticks = [];
372
+ for (let tick = start;tick <= max + step / 2; tick += step) {
373
+ ticks.push(Math.abs(tick) < step / 1e6 ? 0 : tick);
374
+ }
375
+ return ticks;
376
+ };
377
+ var headerSvg = (spec, frame) => {
378
+ const { theme } = frame;
379
+ const parts = [
380
+ `<text x="${frame.plotLeft}" y="24" fill="${theme.textPrimary}" font-size="15" font-weight="600">${escapeXml(spec.title)}</text>`
381
+ ];
382
+ if (spec.series.length > 1) {
383
+ let x = frame.plotLeft;
384
+ const swatches = spec.series.map((series, index) => {
385
+ const color = theme.palette[index % theme.palette.length];
386
+ const label = escapeXml(series.name);
387
+ const item = `<rect x="${x}" y="38" width="10" height="10" rx="2" fill="${color}"/><text x="${x + 14}" y="47" fill="${theme.textSecondary}" font-size="11">${label}</text>`;
388
+ x += 14 + series.name.length * 6 + 18;
389
+ return item;
390
+ });
391
+ parts.push(...swatches);
392
+ }
393
+ return parts.join("");
394
+ };
395
+ var gridSvg = (ticks, yFor, spec, frame) => ticks.map((tick) => {
396
+ const y = yFor(tick);
397
+ const isZero = tick === 0;
398
+ return `<line x1="${frame.plotLeft}" y1="${y}" x2="${frame.plotRight}" y2="${y}" stroke="${isZero ? frame.theme.textSecondary : frame.theme.grid}" stroke-width="1"/><text x="${frame.plotLeft - 8}" y="${y + 3.5}" fill="${frame.theme.textSecondary}" font-size="10" text-anchor="end">${escapeXml(formatValue(tick, spec))}</text>`;
399
+ }).join("");
400
+ var xLabelsSvg = (spec, xCenter, frame) => {
401
+ const every = Math.ceil(spec.labels.length / 12);
402
+ return spec.labels.map((label, index) => {
403
+ if (index % every !== 0)
404
+ return "";
405
+ const short = label.length > 12 ? `${label.slice(0, 11)}…` : label;
406
+ return `<text x="${xCenter(index)}" y="${frame.plotBottom + 18}" fill="${frame.theme.textSecondary}" font-size="10" text-anchor="middle">${escapeXml(short)}</text>`;
407
+ }).join("");
408
+ };
409
+ var barPath = (x, yValue, yBase, width) => {
410
+ const up = yValue <= yBase;
411
+ const top = Math.min(yValue, yBase);
412
+ const bottom = Math.max(yValue, yBase);
413
+ const radius = Math.min(BAR_END_RADIUS, width / 2, bottom - top);
414
+ if (radius <= 0)
415
+ return "";
416
+ if (up) {
417
+ return `M${x},${bottom} L${x},${top + radius} Q${x},${top} ${x + radius},${top} L${x + width - radius},${top} Q${x + width},${top} ${x + width},${top + radius} L${x + width},${bottom} Z`;
418
+ }
419
+ return `M${x},${top} L${x},${bottom - radius} Q${x},${bottom} ${x + radius},${bottom} L${x + width - radius},${bottom} Q${x + width},${bottom} ${x + width},${bottom - radius} L${x + width},${top} Z`;
420
+ };
421
+ var valueDomain = (spec) => {
422
+ const all = spec.series.flatMap((series) => series.values);
423
+ const min = Math.min(0, ...all);
424
+ const max = Math.max(0, ...all);
425
+ return max === min ? { max: min + 1, min } : { max, min };
426
+ };
427
+ var cartesianSvg = (spec, frame) => {
428
+ const { theme } = frame;
429
+ const domain = valueDomain(spec);
430
+ const ticks = niceTicks(domain.min, domain.max);
431
+ const lo = Math.min(domain.min, ticks[0] ?? domain.min);
432
+ const hi = Math.max(domain.max, ticks[ticks.length - 1] ?? domain.max);
433
+ const yFor = (value) => frame.plotBottom - (value - lo) / (hi - lo) * (frame.plotBottom - frame.plotTop);
434
+ const slot = (frame.plotRight - frame.plotLeft) / spec.labels.length;
435
+ const xCenter = (index) => frame.plotLeft + slot * (index + 0.5);
436
+ const parts = [gridSvg(ticks, yFor, spec, frame)];
437
+ if (spec.type === "bar") {
438
+ const group = Math.min(slot * 0.72, 64);
439
+ const barWidth = Math.max(2, (group - MARK_GAP * (spec.series.length - 1)) / spec.series.length);
440
+ const yBase = yFor(Math.max(lo, Math.min(hi, 0)));
441
+ spec.series.forEach((series, seriesIndex) => {
442
+ const color = theme.palette[seriesIndex % theme.palette.length];
443
+ series.values.forEach((value, index) => {
444
+ const x = xCenter(index) - group / 2 + seriesIndex * (barWidth + MARK_GAP);
445
+ const tooltip = `${escapeXml(series.name)} · ${escapeXml(spec.labels[index] ?? "")}: ${escapeXml(formatValue(value, spec))}`;
446
+ parts.push(`<path d="${barPath(x, yFor(value), yBase, barWidth)}" fill="${color}"><title>${tooltip}</title></path>`);
447
+ });
448
+ });
449
+ const [only] = spec.series;
450
+ if (spec.series.length === 1 && only && spec.labels.length <= 8) {
451
+ only.values.forEach((value, index) => {
452
+ const above = value >= 0;
453
+ parts.push(`<text x="${xCenter(index)}" y="${yFor(value) + (above ? -6 : 14)}" fill="${theme.textSecondary}" font-size="10" text-anchor="middle">${escapeXml(formatValue(value, spec))}</text>`);
454
+ });
455
+ }
456
+ } else {
457
+ spec.series.forEach((series, seriesIndex) => {
458
+ const color = theme.palette[seriesIndex % theme.palette.length];
459
+ const points = series.values.map((value, index) => `${xCenter(index)},${yFor(value)}`);
460
+ parts.push(`<polyline points="${points.join(" ")}" fill="none" stroke="${color}" stroke-width="${LINE_WIDTH}" stroke-linejoin="round" stroke-linecap="round"/>`);
461
+ series.values.forEach((value, index) => {
462
+ const tooltip = `${escapeXml(series.name)} · ${escapeXml(spec.labels[index] ?? "")}: ${escapeXml(formatValue(value, spec))}`;
463
+ parts.push(`<circle cx="${xCenter(index)}" cy="${yFor(value)}" r="4" fill="${color}" stroke="${theme.surface}" stroke-width="2"><title>${tooltip}</title></circle>`);
464
+ });
465
+ const last = series.values[series.values.length - 1];
466
+ if (spec.series.length <= MAX_DIRECT_LABELED_SERIES && last !== undefined) {
467
+ parts.push(`<text x="${frame.plotRight + 4}" y="${yFor(last) + 3.5}" fill="${theme.textSecondary}" font-size="10">${escapeXml(series.name)}</text>`);
468
+ }
469
+ });
470
+ }
471
+ parts.push(xLabelsSvg(spec, xCenter, frame));
472
+ return parts.join("");
473
+ };
474
+ var donutSvg = (spec, frame) => {
475
+ const { theme } = frame;
476
+ const [series] = spec.series;
477
+ if (!series)
478
+ return "";
479
+ const total = series.values.reduce((sum, value) => sum + value, 0);
480
+ if (total <= 0)
481
+ return "";
482
+ const cx = (frame.plotLeft + frame.plotRight) / 2;
483
+ const cy = (frame.plotTop + frame.plotBottom) / 2 + 4;
484
+ const radius = Math.min((frame.plotBottom - frame.plotTop) / 2 - 4, (frame.plotRight - frame.plotLeft) / 4);
485
+ const ring = Math.max(14, radius * 0.34);
486
+ const mid = radius - ring / 2;
487
+ const gapAngle = MARK_GAP / mid;
488
+ const parts = [];
489
+ let angle = -Math.PI / 2;
490
+ series.values.forEach((value, index) => {
491
+ const sweep = value / total * Math.PI * 2;
492
+ const start = angle + gapAngle / 2;
493
+ const end = angle + sweep - gapAngle / 2;
494
+ angle += sweep;
495
+ if (end <= start)
496
+ return;
497
+ const large = end - start > Math.PI ? 1 : 0;
498
+ const x1 = cx + mid * Math.cos(start);
499
+ const y1 = cy + mid * Math.sin(start);
500
+ const x2 = cx + mid * Math.cos(end);
501
+ const y2 = cy + mid * Math.sin(end);
502
+ const color = theme.palette[index % theme.palette.length];
503
+ const share = `${Math.round(value / total * 100)}%`;
504
+ const tooltip = `${escapeXml(spec.labels[index] ?? "")}: ${escapeXml(formatValue(value, spec))} (${share})`;
505
+ parts.push(`<path d="M${x1},${y1} A${mid},${mid} 0 ${large} 1 ${x2},${y2}" fill="none" stroke="${color}" stroke-width="${ring}"><title>${tooltip}</title></path>`);
506
+ });
507
+ parts.push(`<text x="${cx}" y="${cy + 5}" fill="${theme.textPrimary}" font-size="16" font-weight="600" text-anchor="middle">${escapeXml(formatValue(total, spec))}</text>`);
508
+ let x = frame.plotLeft;
509
+ spec.labels.forEach((label, index) => {
510
+ const color = theme.palette[index % theme.palette.length];
511
+ parts.push(`<rect x="${x}" y="38" width="10" height="10" rx="2" fill="${color}"/><text x="${x + 14}" y="47" fill="${theme.textSecondary}" font-size="11">${escapeXml(label)}</text>`);
512
+ x += 14 + label.length * 6 + 18;
513
+ });
514
+ return parts.join("");
515
+ };
516
+ var renderChartSvg = (spec, options = {}) => {
517
+ const base = options.mode === "dark" ? DARK_UI_THEME : LIGHT_UI_THEME;
518
+ const theme = { ...base, ...options.theme };
519
+ const width = options.width ?? WIDTH;
520
+ const height = options.height ?? HEIGHT;
521
+ const frame = {
522
+ plotBottom: height - MARGIN.bottom,
523
+ plotLeft: MARGIN.left,
524
+ plotRight: width - MARGIN.right - (spec.type === "line" ? 64 : 0),
525
+ plotTop: MARGIN.top,
526
+ theme
527
+ };
528
+ const body = spec.type === "donut" ? donutSvg(spec, frame) : cartesianSvg(spec, frame);
529
+ return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${width} ${height}" role="img" aria-label="${escapeXml(spec.title)}" font-family="${FONT}"><rect width="${width}" height="${height}" fill="${theme.surface}" rx="12"/>${spec.type === "donut" ? headerSvg({ ...spec, series: [] }, frame) : headerSvg(spec, frame)}${body}</svg>`;
530
+ };
531
+ export {
532
+ tableCard,
533
+ statTilesCard,
534
+ renderChartSvg,
535
+ parseTableSpec,
536
+ parseStatTilesSpec,
537
+ parseChartSpec,
538
+ createUiCards,
539
+ chartCard,
540
+ TABLE_MAX_ROWS,
541
+ TABLE_MAX_COLUMNS,
542
+ STAT_TILES_MAX,
543
+ LIGHT_UI_THEME,
544
+ DARK_UI_THEME,
545
+ CHART_TYPES,
546
+ CHART_MAX_SERIES,
547
+ CHART_MAX_POINTS,
548
+ BUILTIN_UI_CARDS
549
+ };
550
+
551
+ //# debugId=CFC0242319CEE8E764756E2164756E21
552
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,12 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/ai/ui/uiCards.ts", "../src/ai/ui/catalog.ts", "../src/ai/ui/svg.ts"],
4
+ "sourcesContent": [
5
+ "import type { AIToolMap } from \"../../../types/ai\";\n\n/**\n * UI cards — the generative-UI primitive extracted from onSpark's chat.\n *\n * A \"card\" is a schema-only tool: the model calls it with a structured payload,\n * the handler only ACKNOWLEDGES (steering the model's continuation), and the\n * host watches the executed tool calls to render the payload as a real,\n * host-styled component (a chart, a table, an approval card, a deep link…).\n * No model-written code ever executes: the payload is validated by the card's\n * `parse` before anything renders, so a malformed call simply drops.\n */\nexport type UiCardDefinition<T = unknown> = {\n /** Tool name the model calls, e.g. \"render_chart\". */\n name: string;\n /** Tool description — steer WHEN the model should render this card. */\n description: string;\n /** JSON schema for the tool input. */\n inputSchema: Record<string, unknown>;\n /** Tool-result text fed back to the model (e.g. \"(chart rendered — don't\n * repeat its numbers in text)\"). */\n ack: string;\n /** Validate + narrow the raw model input to the card payload. Return null\n * to reject the call (the card is dropped, the ack still steered). */\n parse: (input: unknown) => T | null;\n};\n\nexport type UiCardEvent = {\n /** The card's tool name. */\n card: string;\n /** The parsed, validated payload. */\n data: unknown;\n};\n\nexport type UiCards = {\n /** AIToolMap entries (ack handlers) — spread into the tools you hand to\n * streamAIWithTools / generateAIWithTools. */\n tools: AIToolMap;\n /** Pull validated card events out of a turn's tool calls, in call order.\n * Invalid payloads and non-card tools are skipped. */\n collect: (\n calls: readonly { name: string; input: unknown }[],\n ) => UiCardEvent[];\n /** Is this tool name one of the registered cards? */\n has: (name: string) => boolean;\n};\n\n/** Build the tool map + collector for a set of UI cards. */\nexport const createUiCards = (\n definitions: readonly UiCardDefinition[],\n): UiCards => {\n const byName = new Map(\n definitions.map((definition) => [definition.name, definition]),\n );\n\n const tools: AIToolMap = Object.fromEntries(\n definitions.map((definition) => [\n definition.name,\n {\n description: definition.description,\n handler: () => definition.ack,\n input: definition.inputSchema,\n },\n ]),\n );\n\n const collect = (calls: readonly { name: string; input: unknown }[]) => {\n const events: UiCardEvent[] = [];\n for (const call of calls) {\n const definition = byName.get(call.name);\n if (!definition) continue;\n const data = definition.parse(call.input);\n if (data !== null) events.push({ card: definition.name, data });\n }\n\n return events;\n };\n\n return { collect, has: (name: string) => byName.has(name), tools };\n};\n",
6
+ "import type { UiCardDefinition } from \"./uiCards\";\n\n/**\n * Built-in UI card catalog: chart, table, stat tiles. Declarative specs the\n * model authors and the host renders — see svg.ts for the dependency-free\n * default renderer. Caps are hard product guards (a model can't render a\n * 400-row table into a chat bubble).\n */\n\nexport const CHART_TYPES = [\"bar\", \"line\", \"donut\"] as const;\nexport type ChartType = (typeof CHART_TYPES)[number];\n\nexport type ChartSeries = { name: string; values: number[] };\n\nexport type ChartSpec = {\n type: ChartType;\n title: string;\n /** Category labels: x-axis (bar/line) or slice names (donut). */\n labels: string[];\n /** ≤ 8 series (fixed hue order). Donut charts use exactly one series. */\n series: ChartSeries[];\n /** Value formatting, e.g. \"$\" / \"%\". */\n unitPrefix?: string;\n unitSuffix?: string;\n};\n\nexport type TableSpec = {\n title?: string;\n columns: string[];\n rows: string[][];\n};\n\nexport type StatTile = {\n label: string;\n value: string;\n /** Optional change annotation, e.g. \"+12% vs last month\". */\n delta?: string;\n deltaDirection?: \"up\" | \"down\" | \"flat\";\n};\n\nexport type StatTilesSpec = { tiles: StatTile[] };\n\n// Hard caps — chat-bubble scale, and the fixed 8-slot categorical order.\nexport const CHART_MAX_SERIES = 8;\nexport const CHART_MAX_POINTS = 24;\nexport const TABLE_MAX_COLUMNS = 8;\nexport const TABLE_MAX_ROWS = 30;\nexport const STAT_TILES_MAX = 6;\nconst LABEL_MAX_CHARS = 80;\nconst TITLE_MAX_CHARS = 120;\nconst CELL_MAX_CHARS = 160;\nconst UNIT_MAX_CHARS = 8;\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null;\n\nconst cleanString = (value: unknown, maxChars: number) =>\n typeof value === \"string\" && value.trim().length > 0\n ? value.trim().slice(0, maxChars)\n : null;\n\nconst cleanStringArray = (\n value: unknown,\n maxItems: number,\n maxChars: number,\n) => {\n if (!Array.isArray(value) || value.length === 0) return null;\n const cleaned: string[] = [];\n for (const entry of value.slice(0, maxItems)) {\n const text = cleanString(entry, maxChars);\n cleaned.push(text ?? \"\");\n }\n\n return cleaned;\n};\n\nconst cleanNumberArray = (value: unknown, maxItems: number) => {\n if (!Array.isArray(value) || value.length === 0) return null;\n const cleaned: number[] = [];\n for (const entry of value.slice(0, maxItems)) {\n if (typeof entry !== \"number\" || !Number.isFinite(entry)) return null;\n cleaned.push(entry);\n }\n\n return cleaned;\n};\n\nexport const parseChartSpec = (input: unknown): ChartSpec | null => {\n if (!isRecord(input)) return null;\n const type = CHART_TYPES.find((entry) => entry === input.type);\n const title = cleanString(input.title, TITLE_MAX_CHARS);\n const labels = cleanStringArray(\n input.labels,\n CHART_MAX_POINTS,\n LABEL_MAX_CHARS,\n );\n if (!type || !title || !labels) return null;\n\n if (!Array.isArray(input.series) || input.series.length === 0) return null;\n const series: ChartSeries[] = [];\n for (const raw of input.series.slice(0, CHART_MAX_SERIES)) {\n if (!isRecord(raw)) return null;\n const name = cleanString(raw.name, LABEL_MAX_CHARS);\n const values = cleanNumberArray(raw.values, CHART_MAX_POINTS);\n if (!name || !values) return null;\n // Every series aligns with the label axis; pad/trim mismatches drop.\n if (values.length !== labels.length) return null;\n series.push({ name, values });\n }\n // Donut: one series, non-negative slices.\n if (type === \"donut\") {\n const [only] = series;\n if (series.length !== 1 || !only) return null;\n if (only.values.some((value) => value < 0)) return null;\n }\n\n const spec: ChartSpec = { labels, series, title, type };\n const unitPrefix = cleanString(input.unitPrefix, UNIT_MAX_CHARS);\n const unitSuffix = cleanString(input.unitSuffix, UNIT_MAX_CHARS);\n if (unitPrefix) spec.unitPrefix = unitPrefix;\n if (unitSuffix) spec.unitSuffix = unitSuffix;\n\n return spec;\n};\n\nexport const parseTableSpec = (input: unknown): TableSpec | null => {\n if (!isRecord(input)) return null;\n const columns = cleanStringArray(\n input.columns,\n TABLE_MAX_COLUMNS,\n LABEL_MAX_CHARS,\n );\n if (!columns) return null;\n if (!Array.isArray(input.rows) || input.rows.length === 0) return null;\n const rows: string[][] = [];\n for (const raw of input.rows.slice(0, TABLE_MAX_ROWS)) {\n const cells = cleanStringArray(raw, TABLE_MAX_COLUMNS, CELL_MAX_CHARS);\n if (!cells) return null;\n // Normalize ragged rows to the header width.\n while (cells.length < columns.length) cells.push(\"\");\n rows.push(cells.slice(0, columns.length));\n }\n\n const spec: TableSpec = { columns, rows };\n const title = cleanString(input.title, TITLE_MAX_CHARS);\n if (title) spec.title = title;\n\n return spec;\n};\n\nexport const parseStatTilesSpec = (input: unknown): StatTilesSpec | null => {\n if (!isRecord(input)) return null;\n if (!Array.isArray(input.tiles) || input.tiles.length === 0) return null;\n const tiles: StatTile[] = [];\n for (const raw of input.tiles.slice(0, STAT_TILES_MAX)) {\n if (!isRecord(raw)) return null;\n const label = cleanString(raw.label, LABEL_MAX_CHARS);\n const value = cleanString(raw.value, LABEL_MAX_CHARS);\n if (!label || !value) return null;\n const tile: StatTile = { label, value };\n const delta = cleanString(raw.delta, LABEL_MAX_CHARS);\n if (delta) tile.delta = delta;\n if (\n raw.deltaDirection === \"up\" ||\n raw.deltaDirection === \"down\" ||\n raw.deltaDirection === \"flat\"\n ) {\n tile.deltaDirection = raw.deltaDirection;\n }\n tiles.push(tile);\n }\n\n return { tiles };\n};\n\nconst SERIES_SCHEMA = {\n properties: {\n name: { description: \"Series name (shown in the legend)\", type: \"string\" },\n values: {\n description: \"One number per label, same order as labels\",\n items: { type: \"number\" },\n type: \"array\",\n },\n },\n required: [\"name\", \"values\"],\n type: \"object\",\n};\n\n/** render_chart — bar / line / donut from data you already have. */\nexport const chartCard: UiCardDefinition<ChartSpec> = {\n ack: \"(chart rendered inline — do not repeat its numbers as text; add at most a 1-2 line takeaway)\",\n description:\n \"Render a real chart inline in the chat from data you have (tool results, the conversation). Use whenever numbers COMPARE or TREND: revenue by partner (bar), pipeline over time (line), share of a whole (donut). Rules: bar/line take up to 8 series aligned to the same labels; donut takes exactly ONE series of non-negative values (one slice per label). Prefer a chart over a wall of numbers, but never invent data for it.\",\n inputSchema: {\n properties: {\n labels: {\n description:\n \"Category labels — x-axis for bar/line, slice names for donut (max 24)\",\n items: { type: \"string\" },\n type: \"array\",\n },\n series: {\n description: \"Data series (max 8; donut exactly 1)\",\n items: SERIES_SCHEMA,\n type: \"array\",\n },\n title: { description: \"Short chart title\", type: \"string\" },\n type: { enum: [...CHART_TYPES], type: \"string\" },\n unitPrefix: {\n description: 'Prepended to values, e.g. \"$\"',\n type: \"string\",\n },\n unitSuffix: {\n description: 'Appended to values, e.g. \"%\"',\n type: \"string\",\n },\n },\n required: [\"type\", \"title\", \"labels\", \"series\"],\n type: \"object\",\n },\n name: \"render_chart\",\n parse: parseChartSpec,\n};\n\n/** render_table — a compact data table. */\nexport const tableCard: UiCardDefinition<TableSpec> = {\n ack: \"(table rendered inline — do not repeat its rows as text)\",\n description:\n \"Render a compact data table inline in the chat (max 8 columns × 30 rows). Use for structured comparisons the member will scan — matches side by side, deal terms, task lists with dates. All cells are strings; format numbers yourself.\",\n inputSchema: {\n properties: {\n columns: {\n description: \"Column headers (max 8)\",\n items: { type: \"string\" },\n type: \"array\",\n },\n rows: {\n description: \"Rows of cells, each aligned to columns (max 30)\",\n items: { items: { type: \"string\" }, type: \"array\" },\n type: \"array\",\n },\n title: { description: \"Optional table title\", type: \"string\" },\n },\n required: [\"columns\", \"rows\"],\n type: \"object\",\n },\n name: \"render_table\",\n parse: parseTableSpec,\n};\n\n/** render_stat_tiles — a row of headline numbers. */\nexport const statTilesCard: UiCardDefinition<StatTilesSpec> = {\n ack: \"(stat tiles rendered inline — do not repeat the numbers as text)\",\n description:\n \"Render a row of headline stat tiles inline in the chat (max 6): a label, a big value, and an optional delta with direction. Use for the 2-4 numbers that ARE the answer — total attributed revenue, pipeline value, credits remaining — instead of burying them in prose.\",\n inputSchema: {\n properties: {\n tiles: {\n description: \"The tiles (max 6)\",\n items: {\n properties: {\n delta: {\n description: 'Optional change note, e.g. \"+12% vs last month\"',\n type: \"string\",\n },\n deltaDirection: { enum: [\"up\", \"down\", \"flat\"], type: \"string\" },\n label: { description: \"What the number is\", type: \"string\" },\n value: {\n description: 'The formatted headline value, e.g. \"$42,300\"',\n type: \"string\",\n },\n },\n required: [\"label\", \"value\"],\n type: \"object\",\n },\n type: \"array\",\n },\n },\n required: [\"tiles\"],\n type: \"object\",\n },\n name: \"render_stat_tiles\",\n parse: parseStatTilesSpec,\n};\n\n/** The built-in catalog, ready for createUiCards. */\nexport const BUILTIN_UI_CARDS = [chartCard, tableCard, statTilesCard] as const;\n",
7
+ "import type { ChartSpec } from \"./catalog\";\n\n/**\n * Dependency-free default chart renderer: a validated ChartSpec in, a\n * self-contained SVG string out. Pure — no DOM — so it runs server-side or in\n * any framework component (call it client-side with the viewer's mode so dark\n * themes get the dark-stepped palette, not an automatic flip).\n *\n * Design method: thin marks with rounded data-ends, 2px surface gaps between\n * adjacent fills, recessive horizontal grid, a legend for ≥2 series plus\n * direct labels, all text in text tokens (never series colors), native <title>\n * hover tooltips per mark. The default palette is the validated reference set\n * (worst adjacent CVD ΔE 24.2 light / 10.3 dark) — override `palette` with\n * your brand's VALIDATED hues, in their fixed slot order.\n */\n\nexport type UiSvgTheme = {\n /** Categorical hues in fixed slot order (series 1..n). */\n palette: string[];\n surface: string;\n textPrimary: string;\n textSecondary: string;\n grid: string;\n};\n\nexport const LIGHT_UI_THEME: UiSvgTheme = {\n grid: \"#e4e4e0\",\n palette: [\n \"#2a78d6\",\n \"#1baf7a\",\n \"#eda100\",\n \"#008300\",\n \"#4a3aa7\",\n \"#e34948\",\n \"#e87ba4\",\n \"#eb6834\",\n ],\n surface: \"#fcfcfb\",\n textPrimary: \"#0b0b0b\",\n textSecondary: \"#52514e\",\n};\n\nexport const DARK_UI_THEME: UiSvgTheme = {\n grid: \"#333331\",\n palette: [\n \"#3987e5\",\n \"#199e70\",\n \"#c98500\",\n \"#008300\",\n \"#9085e9\",\n \"#e66767\",\n \"#d55181\",\n \"#d95926\",\n ],\n surface: \"#1a1a19\",\n textPrimary: \"#ffffff\",\n textSecondary: \"#c3c2b7\",\n};\n\nexport type RenderChartSvgOptions = {\n mode?: \"light\" | \"dark\";\n /** Override any theme slot (e.g. your brand palette / chat-bubble surface). */\n theme?: Partial<UiSvgTheme>;\n width?: number;\n height?: number;\n};\n\nconst WIDTH = 640;\nconst HEIGHT = 340;\nconst MARGIN = { bottom: 42, left: 56, right: 16, top: 64 };\nconst BAR_END_RADIUS = 4;\nconst MARK_GAP = 2;\nconst LINE_WIDTH = 2;\nconst MAX_DIRECT_LABELED_SERIES = 4;\nconst TICK_TARGET = 4;\nconst FONT =\n \"system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif\";\n\nconst escapeXml = (value: string) =>\n value\n .replace(/&/g, \"&amp;\")\n .replace(/</g, \"&lt;\")\n .replace(/>/g, \"&gt;\")\n .replace(/\"/g, \"&quot;\")\n .replace(/'/g, \"&apos;\");\n\nconst formatValue = (value: number, spec: ChartSpec) => {\n // Sign leads the unit (\"-$4k\", not \"$-4000\").\n const sign = value < 0 ? \"-\" : \"\";\n const abs = Math.abs(value);\n const compact =\n abs >= 1_000_000\n ? `${(abs / 1_000_000).toFixed(1).replace(/\\.0$/, \"\")}M`\n : abs >= 10_000\n ? `${(abs / 1_000).toFixed(1).replace(/\\.0$/, \"\")}k`\n : abs >= 1_000\n ? abs.toLocaleString(\"en-US\")\n : `${Number.isInteger(abs) ? abs : abs.toFixed(1)}`;\n\n return `${sign}${spec.unitPrefix ?? \"\"}${compact}${spec.unitSuffix ?? \"\"}`;\n};\n\n// \"Nice\" tick step: 1/2/5 × 10^n covering the domain in ~TICK_TARGET steps.\nconst niceTicks = (min: number, max: number) => {\n const span = max - min || 1;\n const rough = span / TICK_TARGET;\n const power = Math.pow(10, Math.floor(Math.log10(rough)));\n const candidates = [1, 2, 5, 10].map((step) => step * power);\n const step =\n candidates.find((candidate) => candidate >= rough) ??\n candidates[candidates.length - 1] ??\n rough;\n const start = Math.floor(min / step) * step;\n const ticks: number[] = [];\n for (let tick = start; tick <= max + step / 2; tick += step) {\n ticks.push(Math.abs(tick) < step / 1e6 ? 0 : tick);\n }\n\n return ticks;\n};\n\ntype Frame = {\n theme: UiSvgTheme;\n plotLeft: number;\n plotRight: number;\n plotTop: number;\n plotBottom: number;\n};\n\nconst headerSvg = (spec: ChartSpec, frame: Frame) => {\n const { theme } = frame;\n const parts = [\n `<text x=\"${frame.plotLeft}\" y=\"24\" fill=\"${theme.textPrimary}\" font-size=\"15\" font-weight=\"600\">${escapeXml(spec.title)}</text>`,\n ];\n // Legend only when identity needs it: 2+ series (a single series is named\n // by the title). Swatch + name in text ink, never colored text.\n if (spec.series.length > 1) {\n let x = frame.plotLeft;\n const swatches = spec.series.map((series, index) => {\n const color = theme.palette[index % theme.palette.length];\n const label = escapeXml(series.name);\n const item = `<rect x=\"${x}\" y=\"38\" width=\"10\" height=\"10\" rx=\"2\" fill=\"${color}\"/><text x=\"${x + 14}\" y=\"47\" fill=\"${theme.textSecondary}\" font-size=\"11\">${label}</text>`;\n x += 14 + series.name.length * 6 + 18;\n\n return item;\n });\n parts.push(...swatches);\n }\n\n return parts.join(\"\");\n};\n\nconst gridSvg = (\n ticks: number[],\n yFor: (value: number) => number,\n spec: ChartSpec,\n frame: Frame,\n) =>\n ticks\n .map((tick) => {\n const y = yFor(tick);\n const isZero = tick === 0;\n\n return `<line x1=\"${frame.plotLeft}\" y1=\"${y}\" x2=\"${frame.plotRight}\" y2=\"${y}\" stroke=\"${isZero ? frame.theme.textSecondary : frame.theme.grid}\" stroke-width=\"1\"/><text x=\"${frame.plotLeft - 8}\" y=\"${y + 3.5}\" fill=\"${frame.theme.textSecondary}\" font-size=\"10\" text-anchor=\"end\">${escapeXml(formatValue(tick, spec))}</text>`;\n })\n .join(\"\");\n\nconst xLabelsSvg = (\n spec: ChartSpec,\n xCenter: (index: number) => number,\n frame: Frame,\n) => {\n // Thin out crowded label axes instead of colliding.\n const every = Math.ceil(spec.labels.length / 12);\n\n return spec.labels\n .map((label, index) => {\n if (index % every !== 0) return \"\";\n const short = label.length > 12 ? `${label.slice(0, 11)}…` : label;\n\n return `<text x=\"${xCenter(index)}\" y=\"${frame.plotBottom + 18}\" fill=\"${frame.theme.textSecondary}\" font-size=\"10\" text-anchor=\"middle\">${escapeXml(short)}</text>`;\n })\n .join(\"\");\n};\n\n// Bar with a rounded TOP data-end anchored to the baseline (flipped when the\n// value is negative). Radius collapses on very short bars.\nconst barPath = (\n x: number,\n yValue: number,\n yBase: number,\n width: number,\n): string => {\n const up = yValue <= yBase;\n const top = Math.min(yValue, yBase);\n const bottom = Math.max(yValue, yBase);\n const radius = Math.min(BAR_END_RADIUS, width / 2, bottom - top);\n if (radius <= 0) return \"\";\n if (up) {\n return `M${x},${bottom} L${x},${top + radius} Q${x},${top} ${x + radius},${top} L${x + width - radius},${top} Q${x + width},${top} ${x + width},${top + radius} L${x + width},${bottom} Z`;\n }\n\n return `M${x},${top} L${x},${bottom - radius} Q${x},${bottom} ${x + radius},${bottom} L${x + width - radius},${bottom} Q${x + width},${bottom} ${x + width},${bottom - radius} L${x + width},${top} Z`;\n};\n\nconst valueDomain = (spec: ChartSpec) => {\n const all = spec.series.flatMap((series) => series.values);\n const min = Math.min(0, ...all);\n const max = Math.max(0, ...all);\n\n return max === min ? { max: min + 1, min } : { max, min };\n};\n\nconst cartesianSvg = (spec: ChartSpec, frame: Frame) => {\n const { theme } = frame;\n const domain = valueDomain(spec);\n const ticks = niceTicks(domain.min, domain.max);\n const lo = Math.min(domain.min, ticks[0] ?? domain.min);\n const hi = Math.max(domain.max, ticks[ticks.length - 1] ?? domain.max);\n const yFor = (value: number) =>\n frame.plotBottom -\n ((value - lo) / (hi - lo)) * (frame.plotBottom - frame.plotTop);\n const slot = (frame.plotRight - frame.plotLeft) / spec.labels.length;\n const xCenter = (index: number) => frame.plotLeft + slot * (index + 0.5);\n\n const parts: string[] = [gridSvg(ticks, yFor, spec, frame)];\n\n if (spec.type === \"bar\") {\n const group = Math.min(slot * 0.72, 64);\n const barWidth = Math.max(\n 2,\n (group - MARK_GAP * (spec.series.length - 1)) / spec.series.length,\n );\n const yBase = yFor(Math.max(lo, Math.min(hi, 0)));\n spec.series.forEach((series, seriesIndex) => {\n const color = theme.palette[seriesIndex % theme.palette.length];\n series.values.forEach((value, index) => {\n const x =\n xCenter(index) - group / 2 + seriesIndex * (barWidth + MARK_GAP);\n const tooltip = `${escapeXml(series.name)} · ${escapeXml(spec.labels[index] ?? \"\")}: ${escapeXml(formatValue(value, spec))}`;\n\n parts.push(\n `<path d=\"${barPath(x, yFor(value), yBase, barWidth)}\" fill=\"${color}\"><title>${tooltip}</title></path>`,\n );\n });\n });\n // Selective direct labels: single series with few bars gets its values.\n const [only] = spec.series;\n if (spec.series.length === 1 && only && spec.labels.length <= 8) {\n only.values.forEach((value, index) => {\n const above = value >= 0;\n parts.push(\n `<text x=\"${xCenter(index)}\" y=\"${yFor(value) + (above ? -6 : 14)}\" fill=\"${theme.textSecondary}\" font-size=\"10\" text-anchor=\"middle\">${escapeXml(formatValue(value, spec))}</text>`,\n );\n });\n }\n } else {\n spec.series.forEach((series, seriesIndex) => {\n const color = theme.palette[seriesIndex % theme.palette.length];\n const points = series.values.map(\n (value, index) => `${xCenter(index)},${yFor(value)}`,\n );\n parts.push(\n `<polyline points=\"${points.join(\" \")}\" fill=\"none\" stroke=\"${color}\" stroke-width=\"${LINE_WIDTH}\" stroke-linejoin=\"round\" stroke-linecap=\"round\"/>`,\n );\n series.values.forEach((value, index) => {\n const tooltip = `${escapeXml(series.name)} · ${escapeXml(spec.labels[index] ?? \"\")}: ${escapeXml(formatValue(value, spec))}`;\n // ≥8px hover targets with a 2px surface ring where marks may overlap.\n parts.push(\n `<circle cx=\"${xCenter(index)}\" cy=\"${yFor(value)}\" r=\"4\" fill=\"${color}\" stroke=\"${theme.surface}\" stroke-width=\"2\"><title>${tooltip}</title></circle>`,\n );\n });\n // Direct series label at the line's end for small multiples.\n const last = series.values[series.values.length - 1];\n if (\n spec.series.length <= MAX_DIRECT_LABELED_SERIES &&\n last !== undefined\n ) {\n parts.push(\n `<text x=\"${frame.plotRight + 4}\" y=\"${yFor(last) + 3.5}\" fill=\"${theme.textSecondary}\" font-size=\"10\">${escapeXml(series.name)}</text>`,\n );\n }\n });\n }\n parts.push(xLabelsSvg(spec, xCenter, frame));\n\n return parts.join(\"\");\n};\n\nconst donutSvg = (spec: ChartSpec, frame: Frame) => {\n const { theme } = frame;\n const [series] = spec.series;\n if (!series) return \"\";\n const total = series.values.reduce((sum, value) => sum + value, 0);\n if (total <= 0) return \"\";\n const cx = (frame.plotLeft + frame.plotRight) / 2;\n const cy = (frame.plotTop + frame.plotBottom) / 2 + 4;\n const radius = Math.min(\n (frame.plotBottom - frame.plotTop) / 2 - 4,\n (frame.plotRight - frame.plotLeft) / 4,\n );\n const ring = Math.max(14, radius * 0.34);\n const mid = radius - ring / 2;\n // 2px surface gap between segments, expressed as an angle at mid-radius.\n const gapAngle = MARK_GAP / mid;\n\n const parts: string[] = [];\n let angle = -Math.PI / 2;\n series.values.forEach((value, index) => {\n const sweep = (value / total) * Math.PI * 2;\n const start = angle + gapAngle / 2;\n const end = angle + sweep - gapAngle / 2;\n angle += sweep;\n if (end <= start) return;\n const large = end - start > Math.PI ? 1 : 0;\n const x1 = cx + mid * Math.cos(start);\n const y1 = cy + mid * Math.sin(start);\n const x2 = cx + mid * Math.cos(end);\n const y2 = cy + mid * Math.sin(end);\n const color = theme.palette[index % theme.palette.length];\n const share = `${Math.round((value / total) * 100)}%`;\n const tooltip = `${escapeXml(spec.labels[index] ?? \"\")}: ${escapeXml(formatValue(value, spec))} (${share})`;\n parts.push(\n `<path d=\"M${x1},${y1} A${mid},${mid} 0 ${large} 1 ${x2},${y2}\" fill=\"none\" stroke=\"${color}\" stroke-width=\"${ring}\"><title>${tooltip}</title></path>`,\n );\n });\n parts.push(\n `<text x=\"${cx}\" y=\"${cy + 5}\" fill=\"${theme.textPrimary}\" font-size=\"16\" font-weight=\"600\" text-anchor=\"middle\">${escapeXml(formatValue(total, spec))}</text>`,\n );\n // Slice identity lives in the legend row for donuts.\n let x = frame.plotLeft;\n spec.labels.forEach((label, index) => {\n const color = theme.palette[index % theme.palette.length];\n parts.push(\n `<rect x=\"${x}\" y=\"38\" width=\"10\" height=\"10\" rx=\"2\" fill=\"${color}\"/><text x=\"${x + 14}\" y=\"47\" fill=\"${theme.textSecondary}\" font-size=\"11\">${escapeXml(label)}</text>`,\n );\n x += 14 + label.length * 6 + 18;\n });\n\n return parts.join(\"\");\n};\n\n/** Render a validated ChartSpec to a self-contained SVG string. */\nexport const renderChartSvg = (\n spec: ChartSpec,\n options: RenderChartSvgOptions = {},\n) => {\n const base = options.mode === \"dark\" ? DARK_UI_THEME : LIGHT_UI_THEME;\n const theme: UiSvgTheme = { ...base, ...options.theme };\n const width = options.width ?? WIDTH;\n const height = options.height ?? HEIGHT;\n const frame: Frame = {\n plotBottom: height - MARGIN.bottom,\n plotLeft: MARGIN.left,\n plotRight:\n width -\n MARGIN.right -\n // Room for end-of-line direct labels.\n (spec.type === \"line\" ? 64 : 0),\n plotTop: MARGIN.top,\n theme,\n };\n\n const body =\n spec.type === \"donut\" ? donutSvg(spec, frame) : cartesianSvg(spec, frame);\n\n return `<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 ${width} ${height}\" role=\"img\" aria-label=\"${escapeXml(spec.title)}\" font-family=\"${FONT}\"><rect width=\"${width}\" height=\"${height}\" fill=\"${theme.surface}\" r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AM,QAAQ,QAAQ,SAAS;AAAA,EAC/B,MAAM,SAAS,QAAQ,UAAU;AAAA,EACjC,MAAM,QAAe;AAAA,IACnB,YAAY,SAAS,OAAO;AAAA,IAC5B,UAAU,OAAO;AAAA,IACjB,WACE,QACA,OAAO,SAEN,KAAK,SAAS,SAAS,KAAK;AAAA,IAC/B,SAAS,OAAO;AAAA,IAChB;AAAA,EACF;AAAA,EAEA,MAAM,OACJ,KAAK,SAAS,UAAU,SAAS,MAAM,KAAK,IAAI,aAAa,MAAM,KAAK;AAAA,EAE1E,OAAO,wDAAwD,SAAS,kCAAkC,UAAU,KAAK,KAAK,mBAAmB,sBAAsB,kBAAkB,iBAAiB,MAAM,qBAAqB,KAAK,SAAS,UAAU,UAAU,KAAK,MAAM,QAAQ,CAAC,EAAE,GAAG,KAAK,IAAI,UAAU,MAAM,KAAK,IAAI;AAAA;",
10
+ "debugId": "CFC0242319CEE8E764756E2164756E21",
11
+ "names": []
12
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@absolutejs/ai",
3
- "version": "0.0.31",
3
+ "version": "0.0.33",
4
4
  "homepage": "https://github.com/absolutejs/ai",
5
5
  "bugs": {
6
6
  "url": "https://github.com/absolutejs/ai/issues"
@@ -70,6 +70,10 @@
70
70
  "./tools": {
71
71
  "import": "./dist/ai/tools/index.js",
72
72
  "types": "./dist/src/ai/tools/index.d.ts"
73
+ },
74
+ "./ui": {
75
+ "import": "./dist/ai/ui/index.js",
76
+ "types": "./dist/src/ai/ui/index.d.ts"
73
77
  }
74
78
  },
75
79
  "dependencies": {
@@ -136,6 +140,9 @@
136
140
  "client": [
137
141
  "dist/src/ai/client/index.d.ts"
138
142
  ],
143
+ "ui": [
144
+ "dist/src/ai/ui/index.d.ts"
145
+ ],
139
146
  "react": [
140
147
  "dist/src/react/ai/index.d.ts"
141
148
  ],