@shapesos/clay 0.10.0 → 0.12.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.
Files changed (85) hide show
  1. package/README.md +60 -0
  2. package/dist/artifacts.cjs +1467 -0
  3. package/dist/artifacts.cjs.map +1 -0
  4. package/dist/artifacts.d.cts +89 -0
  5. package/dist/artifacts.d.ts +89 -0
  6. package/dist/artifacts.js +33 -0
  7. package/dist/blocks.cjs +1418 -68
  8. package/dist/blocks.cjs.map +1 -1
  9. package/dist/blocks.css +2 -0
  10. package/dist/blocks.d.cts +36 -11
  11. package/dist/blocks.d.ts +36 -11
  12. package/dist/blocks.js +18 -5
  13. package/dist/button.d.cts +2 -2
  14. package/dist/button.d.ts +2 -2
  15. package/dist/chart.cjs +594 -0
  16. package/dist/chart.cjs.map +1 -0
  17. package/dist/chart.d.cts +439 -0
  18. package/dist/chart.d.ts +439 -0
  19. package/dist/chart.js +32 -0
  20. package/dist/chart.js.map +1 -0
  21. package/dist/chat.cjs +1462 -312
  22. package/dist/chat.cjs.map +1 -1
  23. package/dist/chat.d.cts +28 -10
  24. package/dist/chat.d.ts +28 -10
  25. package/dist/chat.js +10 -3
  26. package/dist/{chunk-R3BGPOAM.js → chunk-36CB624W.js} +53 -45
  27. package/dist/chunk-36CB624W.js.map +1 -0
  28. package/dist/chunk-4MZZH3WX.js +93 -0
  29. package/dist/chunk-4MZZH3WX.js.map +1 -0
  30. package/dist/chunk-AQEJRMRN.js +1 -0
  31. package/dist/chunk-AQEJRMRN.js.map +1 -0
  32. package/dist/{chunk-WS4IPADR.js → chunk-FFX3CAOX.js} +41 -109
  33. package/dist/chunk-FFX3CAOX.js.map +1 -0
  34. package/dist/chunk-JGMN6W72.js +12 -0
  35. package/dist/chunk-JGMN6W72.js.map +1 -0
  36. package/dist/{chunk-27GJUWVN.js → chunk-JJUIBBBU.js} +14 -8
  37. package/dist/chunk-JJUIBBBU.js.map +1 -0
  38. package/dist/{chunk-MLCRDVQ2.js → chunk-OBOXCBDL.js} +13 -5
  39. package/dist/chunk-OBOXCBDL.js.map +1 -0
  40. package/dist/chunk-P6GUNIAE.js +11 -0
  41. package/dist/chunk-P6GUNIAE.js.map +1 -0
  42. package/dist/chunk-QXGYMDIA.js +477 -0
  43. package/dist/chunk-QXGYMDIA.js.map +1 -0
  44. package/dist/chunk-Z5JWF24N.js +719 -0
  45. package/dist/chunk-Z5JWF24N.js.map +1 -0
  46. package/dist/icon.cjs +12 -4
  47. package/dist/icon.cjs.map +1 -1
  48. package/dist/icon.d.cts +19 -6
  49. package/dist/icon.d.ts +19 -6
  50. package/dist/icon.js +1 -1
  51. package/dist/index.cjs +1520 -332
  52. package/dist/index.cjs.map +1 -1
  53. package/dist/index.d.cts +7 -4
  54. package/dist/index.d.ts +7 -4
  55. package/dist/index.js +58 -25
  56. package/dist/lottie.d.cts +2 -2
  57. package/dist/lottie.d.ts +2 -2
  58. package/dist/table.cjs +142 -0
  59. package/dist/table.cjs.map +1 -0
  60. package/dist/table.d.cts +44 -0
  61. package/dist/table.d.ts +44 -0
  62. package/dist/table.js +25 -0
  63. package/dist/table.js.map +1 -0
  64. package/dist/text-area.d.cts +2 -2
  65. package/dist/text-area.d.ts +2 -2
  66. package/dist/types-B2aYk82c.d.cts +29 -0
  67. package/dist/types-B2aYk82c.d.ts +29 -0
  68. package/dist/types-C0BvwliI.d.cts +332 -0
  69. package/dist/types-C5bFH4v3.d.ts +332 -0
  70. package/dist/types-DCutaXjZ.d.cts +83 -0
  71. package/dist/types-uPfn67Dc.d.ts +83 -0
  72. package/dist/utils.cjs +14 -7
  73. package/dist/utils.cjs.map +1 -1
  74. package/dist/utils.d.cts +18 -1
  75. package/dist/utils.d.ts +18 -1
  76. package/dist/utils.js +6 -4
  77. package/package.json +41 -4
  78. package/dist/chunk-27GJUWVN.js.map +0 -1
  79. package/dist/chunk-MLCRDVQ2.js.map +0 -1
  80. package/dist/chunk-OKPNST44.js +0 -1
  81. package/dist/chunk-R3BGPOAM.js.map +0 -1
  82. package/dist/chunk-WS4IPADR.js.map +0 -1
  83. package/dist/types-Q9aqd9nq.d.cts +0 -34
  84. package/dist/types-Q9aqd9nq.d.ts +0 -34
  85. /package/dist/{chunk-OKPNST44.js.map → artifacts.js.map} +0 -0
@@ -0,0 +1,332 @@
1
+ import { ComponentType } from 'react';
2
+ import { C as ChartSeries } from './types-B2aYk82c.cjs';
3
+
4
+ /**
5
+ * Shared artifact primitives — the discriminator constant and the cross-variant `ArtifactBase`
6
+ * shape that every concrete artifact record extends.
7
+ *
8
+ * Pulled into its own file so the per-type `types.ts` files (`table-artifact/types.ts`,
9
+ * `chart-artifact/types.ts`) and the union assembler (`artifacts/types.ts`) can all depend on
10
+ * one canonical source without creating a circular module graph between them.
11
+ */
12
+ /**
13
+ * Artifact-type discriminator constants. Uppercase to match the server-side `artifactTypes`
14
+ * constant — io-server stores `artifact.type === "TABLE"` (aligned with the GraphQL enum).
15
+ */
16
+ declare const artifactTypes: {
17
+ readonly TABLE: "TABLE";
18
+ readonly CHART: "CHART";
19
+ };
20
+ /** Discriminator for artifact types. Additive — new types extend this union. */
21
+ type ArtifactType = (typeof artifactTypes)[keyof typeof artifactTypes];
22
+ /** Common shape every artifact record carries. Discriminated by `type`. */
23
+ interface ArtifactBase<TType extends ArtifactType, TConfig> {
24
+ /** Artifact-type discriminator. */
25
+ type: TType;
26
+ /** Human-readable label. Nullable when the artifact has no title. */
27
+ title: string | null;
28
+ /** Rendering config — shape varies per artifact type. */
29
+ config: TConfig;
30
+ /** Protected-asset metadata pointing to the underlying data payload. Null while the asset is unavailable. */
31
+ protectedAsset: {
32
+ /** Time-limited URL the renderer fetches the artifact's data from. */
33
+ presignedUrl: string;
34
+ } | null;
35
+ }
36
+ /**
37
+ * A row inside an artifact's parsed CSV. Every cell is the raw string from the CSV (or `null`
38
+ * for the empty string). Used by every artifact kind whose data wire is a CSV (`TABLE`, `CHART`).
39
+ * The renderer never coerces — type-aware formatting is a server concern (the CSV's contents
40
+ * are what the user sees).
41
+ */
42
+ type ArtifactDataRow = Record<string, string | null>;
43
+
44
+ /**
45
+ * Rendering config for a `BAR` chart. `xKey` selects the categorical axis; each series
46
+ * contributes one `<Bar>`. `stacked` collapses all series onto a single stack-id (so they sum
47
+ * vertically); when false / omitted bars are grouped side-by-side per x-tick.
48
+ */
49
+ interface BarChartConfig extends ChartConfigBase {
50
+ variant: "BAR";
51
+ /** CSV column key used as the x-axis. */
52
+ xKey: string;
53
+ /** When true, stack all series on one stack-id. When false / omitted, group bars side-by-side. */
54
+ stacked?: boolean;
55
+ }
56
+
57
+ /**
58
+ * Rendering config for a `LINE` chart. `xKey` selects the categorical/temporal axis from the
59
+ * CSV; each series contributes one `<Line>` overlaid against that axis.
60
+ */
61
+ interface LineChartConfig extends ChartConfigBase {
62
+ variant: "LINE";
63
+ /** CSV column key used as the x-axis. */
64
+ xKey: string;
65
+ }
66
+
67
+ /**
68
+ * Rendering config for a `PIE` chart. `categoryKey` names the slice; `valueKey` carries the
69
+ * slice's numeric magnitude. One row of CSV becomes one slice. The base's `series` array is
70
+ * always empty for pie — colors are resolved by row index from the palette.
71
+ */
72
+ interface PieChartConfig extends ChartConfigBase {
73
+ variant: "PIE";
74
+ /** CSV column key used as the slice label. */
75
+ categoryKey: string;
76
+ /** CSV column key used as the slice numeric value. */
77
+ valueKey: string;
78
+ }
79
+
80
+ /**
81
+ * Discriminated union of all supported chart variant configs. Assembled here (not in the parent
82
+ * `types.ts`) because the union depends on each variant service file as its single source of
83
+ * truth for that variant's config type.
84
+ *
85
+ * Extension pattern: add a new variant by creating one `*-chart-variant-service.ts` file and
86
+ * extending this union + the `ChartVariantServices` map below. No edits to the dispatcher.
87
+ */
88
+ type ChartConfig = LineChartConfig | BarChartConfig | PieChartConfig;
89
+
90
+ /**
91
+ * Optional stats embedded in `ChartConfig` so clients can pre-render UI before fetching the
92
+ * actual CSV (e.g. a skeleton sized to the eventual row count). Mirrors `TableStats`.
93
+ */
94
+ interface ChartStats {
95
+ /** Total number of rows in the materialised CSV. */
96
+ rowCount: number;
97
+ }
98
+ /**
99
+ * Cross-variant base for `ChartConfig`. Carries the fields every variant shares — series
100
+ * descriptors and optional stats. Per-variant config interfaces (in `chart-variant-services/`)
101
+ * extend this with their own required fields.
102
+ *
103
+ * Note: `series` is always present on the wire (matching the GraphQL `[ChartSeries!]!` shape)
104
+ * even for PIE — PIE just receives an empty array. Keeping it on the base mirrors the wire shape
105
+ * exactly and avoids TS object-literal freshness errors for callers that explicitly set
106
+ * `series: []` on a pie config.
107
+ */
108
+ interface ChartConfigBase {
109
+ /** Series descriptors in render order. LINE/BAR consume these; PIE ignores in favour of `categoryKey`+`valueKey`. */
110
+ series: ChartSeries[];
111
+ /** Optional metadata describing the underlying data — used for loading-state UI. */
112
+ stats?: ChartStats;
113
+ }
114
+ /** Concrete chart artifact record. */
115
+ type ChartArtifactRecord = ArtifactBase<typeof artifactTypes.CHART, ChartConfig>;
116
+ /**
117
+ * Localized labels for the `CHART` artifact's user-facing strings. Covers action buttons AND
118
+ * status messages — see `TableArtifactLabels` for the same shape philosophy. Extends as the
119
+ * chart artifact grows its action set (e.g. future `copyAsPng`); optional keys document
120
+ * anticipated additions without forcing every consumer to provide them today.
121
+ */
122
+ interface ChartArtifactLabels {
123
+ /** Tooltip + aria-label on the Download CSV button in the chart artifact header. */
124
+ download: string;
125
+ /** Status message shown when no presigned URL is available or the chart config is malformed. */
126
+ unavailable: string;
127
+ /** Status message shown when the fetch / parse fails at runtime. */
128
+ loadError: string;
129
+ /** Status message shown while the CSV is being fetched. */
130
+ loading: string;
131
+ /** Status message shown when the fetched CSV has zero data rows. */
132
+ empty: string;
133
+ /**
134
+ * Category labels treated as the "Others" bucket in pie charts (case-insensitive). Matching
135
+ * slices are pinned to the end of the sweep and rendered in neutral grey. The agent writes a
136
+ * translated bucket name in non-English UIs (e.g. "אחרים", "Otros") — consumer passes the
137
+ * localized list here so clay can detect the bucket regardless of language. English fallback
138
+ * is `["Others", "Other"]`. Pass `[]` to disable Others detection (every slice from the palette).
139
+ */
140
+ othersCategoryLabels: readonly string[];
141
+ }
142
+ /** English fallback for `ChartArtifactLabels`. Used when the consumer hasn't passed `labels`. */
143
+ declare const DEFAULT_CHART_ARTIFACT_LABELS: ChartArtifactLabels;
144
+ /**
145
+ * Consumer-supplied side-effect callbacks for actions on the chart artifact. Mirrors
146
+ * `ChartArtifactLabels`'s shape philosophy: one entry per action this artifact exposes
147
+ * (download today; future "Copy as PNG" etc.). Every callback is optional — consumers wire
148
+ * only the actions they care about. The artifact passes its own `ChartArtifactRecord` as the
149
+ * only argument so consumers can derive analytics context (title, config.variant, etc.) without
150
+ * a per-block closure at every render site.
151
+ *
152
+ * The callback fires alongside the default browser behaviour (e.g. `onDownload` does not
153
+ * prevent the anchor's download navigation) — it's purely for analytics / observability hooks.
154
+ */
155
+ interface ChartArtifactCallbacks {
156
+ /** Fires when the Download CSV button is clicked. Browser-native download still happens. */
157
+ onDownload?: (artifact: ChartArtifactRecord) => void;
158
+ }
159
+
160
+ /**
161
+ * A single column descriptor for a `TableArtifact`. Carries the ORDER and LABEL for the
162
+ * rendered table — `key` selects a column from the CSV header; `label` overrides the rendered
163
+ * header text. The CSV is always the source of truth for the data shape; clay never coerces,
164
+ * reformats, or interprets cell values.
165
+ */
166
+ interface TableColumn {
167
+ /** Matches a header in the CSV. Required. Used to project + order the CSV's columns. */
168
+ key: string;
169
+ /** Human-readable header text. Required. */
170
+ label: string;
171
+ /**
172
+ * Accepted in the wire payload but not consulted by the renderer — every cell is rendered as
173
+ * the raw CSV string (or empty for null). Format conversion is a server concern; if a column
174
+ * needs to be "Yes/No" instead of "true/false", the server should emit it that way in the CSV.
175
+ * Kept in the interface so callers that pass `type` (e.g. io-client) don't get a type error.
176
+ */
177
+ type?: "string" | "number" | "date" | "boolean";
178
+ /**
179
+ * Accepted in the wire payload but not consulted by the renderer — every column is left-aligned
180
+ * by design. Kept in the interface for forward-compat; restore per-column alignment by editing
181
+ * `table-artifact-content.tsx` if a future use case justifies it.
182
+ */
183
+ align?: "left" | "center" | "right";
184
+ }
185
+ /**
186
+ * Optional stats embedded in `TableConfig` so clients can pre-render UI before fetching the
187
+ * actual data payload (e.g. N loading shimmers sized to the eventual row count).
188
+ *
189
+ * Backward-compat: optional everywhere — older artifacts persisted before this field shipped
190
+ * still validate. The renderer falls back to a single status-message line when `stats` is absent.
191
+ */
192
+ interface TableStats {
193
+ /** Total number of rows in the materialised CSV. Lets the loading branch render shimmers. */
194
+ rowCount: number;
195
+ }
196
+ /** Rendering config for a table artifact, stored at `artifact.config` (JSONB on the server). */
197
+ interface TableConfig {
198
+ /** Column descriptors in render order. */
199
+ columns: TableColumn[];
200
+ /** Optional metadata describing the underlying data — used for loading-state UI. */
201
+ stats?: TableStats;
202
+ }
203
+ /** Alias retained for callers typed against the table-specific name. */
204
+ type TableRow = ArtifactDataRow;
205
+ /** Concrete table artifact record. */
206
+ type TableArtifactRecord = ArtifactBase<typeof artifactTypes.TABLE, TableConfig>;
207
+ /**
208
+ * Localized labels for the `TABLE` artifact's user-facing strings. Covers both action buttons
209
+ * (download today; future "Copy as CSV", etc.) AND status messages (loading / error / empty /
210
+ * unavailable). Consumer passes the bag from their i18n layer; clay falls back to English
211
+ * defaults when omitted (per-key Partial merge).
212
+ */
213
+ interface TableArtifactLabels {
214
+ /** Tooltip + aria-label on the Download CSV button in the table artifact header. */
215
+ download: string;
216
+ /**
217
+ * Status message shown when no presigned URL is available (permanent server-side absence) or
218
+ * the artifact config is malformed. Both states reduce to "the underlying file isn't usable".
219
+ */
220
+ unavailable: string;
221
+ /** Status message shown when the fetch / parse fails at runtime (transient). */
222
+ loadError: string;
223
+ /** Status message shown while the CSV is being fetched and `stats.rowCount` is not known. */
224
+ loading: string;
225
+ /** Empty-state row inside the table body when the fetched CSV has zero data rows. */
226
+ empty: string;
227
+ }
228
+ /** English fallback for `TableArtifactLabels`. Used when the consumer hasn't passed `labels`. */
229
+ declare const DEFAULT_TABLE_ARTIFACT_LABELS: TableArtifactLabels;
230
+ /**
231
+ * Consumer-supplied side-effect callbacks for actions on the table artifact. Mirrors
232
+ * `ChartArtifactCallbacks` — see that interface for the shape philosophy. Every callback is
233
+ * optional; the artifact passes its own `TableArtifactRecord` as the only argument so consumers
234
+ * can derive analytics context without a per-block closure at every render site.
235
+ */
236
+ interface TableArtifactCallbacks {
237
+ /** Fires when the Download CSV button is clicked. Browser-native download still happens. */
238
+ onDownload?: (artifact: TableArtifactRecord) => void;
239
+ }
240
+
241
+ /**
242
+ * Artifact-domain types — wire-protocol shapes shared between artifact components, block-services,
243
+ * and consumers. Splits responsibilities across three layers so each artifact kind owns its own
244
+ * `types.ts` and this file assembles the cross-type union + service contract:
245
+ *
246
+ * 1. **`artifact-base.ts`** — discriminator (`artifactTypes`), `ArtifactBase<TType, TConfig>`, and
247
+ * `ArtifactDataRow`. Pulled out so each per-type `types.ts` and this assembler can depend on
248
+ * one canonical base without a circular module graph.
249
+ * 2. **`<type>-artifact/types.ts`** — per-artifact-type records, configs, labels, and defaults.
250
+ * Variant-specific types (e.g. `LineChartConfig`) live in even deeper per-variant service files.
251
+ * 3. **This file** — the cross-type `ArtifactRecord` union, the labels map keyed by artifact type,
252
+ * and the `ArtifactService<TArtifact, TLabels>` registry contract used by the dispatcher.
253
+ *
254
+ * Mirrored from the agent / io-server contract — see the `chat-typed-content-blocks-and-artifacts`
255
+ * plan, §6.4 (table contract).
256
+ */
257
+
258
+ /**
259
+ * Per-artifact-type labels map. Lets a consumer pass labels for every artifact kind in a single
260
+ * bag at the block layer (`<ArtifactRefBlock>` payload); the dispatcher routes the matching slice
261
+ * (`labels[artifact.type]`) to the concrete artifact component.
262
+ *
263
+ * Extension pattern: add a new field here when adding a new artifact type. Keep the field
264
+ * optional so older consumers don't break on upgrade.
265
+ */
266
+ interface ArtifactLabelsMap {
267
+ TABLE: TableArtifactLabels;
268
+ CHART: ChartArtifactLabels;
269
+ }
270
+ /**
271
+ * Per-artifact-type callbacks map. Sibling to `ArtifactLabelsMap` — consumer passes a single
272
+ * bag at the block layer covering every artifact type's action callbacks (today: `onDownload`).
273
+ * Used for analytics / observability hooks — every callback is optional and fires alongside
274
+ * the default browser behaviour (it does NOT replace it).
275
+ *
276
+ * Each callback receives its artifact-type's `ArtifactBase`-derived record so consumers can
277
+ * derive analytics context (title, config, etc.) from one wiring at the chat-surface level
278
+ * instead of per-block closures.
279
+ */
280
+ interface ArtifactCallbacksMap {
281
+ TABLE: TableArtifactCallbacks;
282
+ CHART: ChartArtifactCallbacks;
283
+ }
284
+ /**
285
+ * Discriminated union of all supported artifacts. Extension pattern: add the new branch here AND
286
+ * in the `ArtifactServices` map (single source of truth for the type→component mapping). Older
287
+ * clay versions that don't know about a new type silently render nothing — see `ArtifactRefBlock`
288
+ * guard.
289
+ */
290
+ type ArtifactRecord = TableArtifactRecord | ChartArtifactRecord;
291
+ /**
292
+ * Props every concrete artifact component receives from the dispatcher.
293
+ *
294
+ * `labels` is the FULL `ArtifactLabelsMap` bag — every artifact component receives the same
295
+ * shape and reads its own slice internally (`labels?.TABLE`, `labels?.CHART`). One uniform prop
296
+ * type across all artifact components keeps the block-layer dispatcher a generic forward — no
297
+ * per-type branch, no cast, no map-key extraction at the seam.
298
+ */
299
+ interface ArtifactServiceProps<TArtifact extends ArtifactRecord = ArtifactRecord> {
300
+ /** The artifact metadata (config + presigned URL). */
301
+ artifact: TArtifact;
302
+ /**
303
+ * Optional localized labels keyed by artifact type. Each artifact component reads only its
304
+ * own slice (`labels?.TABLE` or `labels?.CHART`); anything omitted falls back to the English
305
+ * default (per-key `Partial` merge against `DEFAULT_*_ARTIFACT_LABELS`).
306
+ */
307
+ labels?: Partial<ArtifactLabelsMap>;
308
+ /**
309
+ * Optional side-effect callbacks keyed by artifact type — for analytics / observability hooks
310
+ * (e.g. tracking a download event). Each artifact component reads only its own slice
311
+ * (`callbacks?.TABLE`, `callbacks?.CHART`). Callbacks fire alongside the default browser
312
+ * behaviour and do not replace it.
313
+ */
314
+ callbacks?: Partial<ArtifactCallbacksMap>;
315
+ }
316
+ /** Per-artifact-type service — registry entry that pairs a discriminator with its concrete component. */
317
+ interface ArtifactService<TArtifact extends ArtifactRecord = ArtifactRecord> {
318
+ /** Discriminator value this service handles. */
319
+ type: (typeof artifactTypes)[keyof typeof artifactTypes];
320
+ /** React component that renders an artifact of this type — composes ai-elements primitives
321
+ * (`Artifact`, `ArtifactHeader`, `ArtifactTitle`, `ArtifactActions`, `ArtifactContent`) directly. */
322
+ Component: ComponentType<ArtifactServiceProps<TArtifact>>;
323
+ /**
324
+ * Returns a plain-text / markdown string suitable for clipboard copy.
325
+ *
326
+ * Called by `ArtifactRefBlockService.toClipboardText` when the user copies a message that
327
+ * contains this artifact. Must be pure and synchronous.
328
+ */
329
+ toClipboardText: (artifact: TArtifact) => string;
330
+ }
331
+
332
+ export { type ArtifactDataRow as A, type BarChartConfig as B, type ChartArtifactLabels as C, DEFAULT_CHART_ARTIFACT_LABELS as D, type LineChartConfig as L, type PieChartConfig as P, type TableArtifactLabels as T, type ArtifactLabelsMap as a, type ArtifactRecord as b, type ArtifactService as c, type ArtifactServiceProps as d, type ArtifactType as e, type ChartArtifactRecord as f, type ChartConfig as g, type ChartStats as h, DEFAULT_TABLE_ARTIFACT_LABELS as i, type TableArtifactRecord as j, type TableColumn as k, type TableConfig as l, type TableRow as m, type TableStats as n, artifactTypes as o, type ArtifactCallbacksMap as p };
@@ -0,0 +1,332 @@
1
+ import { ComponentType } from 'react';
2
+ import { C as ChartSeries } from './types-B2aYk82c.js';
3
+
4
+ /**
5
+ * Shared artifact primitives — the discriminator constant and the cross-variant `ArtifactBase`
6
+ * shape that every concrete artifact record extends.
7
+ *
8
+ * Pulled into its own file so the per-type `types.ts` files (`table-artifact/types.ts`,
9
+ * `chart-artifact/types.ts`) and the union assembler (`artifacts/types.ts`) can all depend on
10
+ * one canonical source without creating a circular module graph between them.
11
+ */
12
+ /**
13
+ * Artifact-type discriminator constants. Uppercase to match the server-side `artifactTypes`
14
+ * constant — io-server stores `artifact.type === "TABLE"` (aligned with the GraphQL enum).
15
+ */
16
+ declare const artifactTypes: {
17
+ readonly TABLE: "TABLE";
18
+ readonly CHART: "CHART";
19
+ };
20
+ /** Discriminator for artifact types. Additive — new types extend this union. */
21
+ type ArtifactType = (typeof artifactTypes)[keyof typeof artifactTypes];
22
+ /** Common shape every artifact record carries. Discriminated by `type`. */
23
+ interface ArtifactBase<TType extends ArtifactType, TConfig> {
24
+ /** Artifact-type discriminator. */
25
+ type: TType;
26
+ /** Human-readable label. Nullable when the artifact has no title. */
27
+ title: string | null;
28
+ /** Rendering config — shape varies per artifact type. */
29
+ config: TConfig;
30
+ /** Protected-asset metadata pointing to the underlying data payload. Null while the asset is unavailable. */
31
+ protectedAsset: {
32
+ /** Time-limited URL the renderer fetches the artifact's data from. */
33
+ presignedUrl: string;
34
+ } | null;
35
+ }
36
+ /**
37
+ * A row inside an artifact's parsed CSV. Every cell is the raw string from the CSV (or `null`
38
+ * for the empty string). Used by every artifact kind whose data wire is a CSV (`TABLE`, `CHART`).
39
+ * The renderer never coerces — type-aware formatting is a server concern (the CSV's contents
40
+ * are what the user sees).
41
+ */
42
+ type ArtifactDataRow = Record<string, string | null>;
43
+
44
+ /**
45
+ * Rendering config for a `BAR` chart. `xKey` selects the categorical axis; each series
46
+ * contributes one `<Bar>`. `stacked` collapses all series onto a single stack-id (so they sum
47
+ * vertically); when false / omitted bars are grouped side-by-side per x-tick.
48
+ */
49
+ interface BarChartConfig extends ChartConfigBase {
50
+ variant: "BAR";
51
+ /** CSV column key used as the x-axis. */
52
+ xKey: string;
53
+ /** When true, stack all series on one stack-id. When false / omitted, group bars side-by-side. */
54
+ stacked?: boolean;
55
+ }
56
+
57
+ /**
58
+ * Rendering config for a `LINE` chart. `xKey` selects the categorical/temporal axis from the
59
+ * CSV; each series contributes one `<Line>` overlaid against that axis.
60
+ */
61
+ interface LineChartConfig extends ChartConfigBase {
62
+ variant: "LINE";
63
+ /** CSV column key used as the x-axis. */
64
+ xKey: string;
65
+ }
66
+
67
+ /**
68
+ * Rendering config for a `PIE` chart. `categoryKey` names the slice; `valueKey` carries the
69
+ * slice's numeric magnitude. One row of CSV becomes one slice. The base's `series` array is
70
+ * always empty for pie — colors are resolved by row index from the palette.
71
+ */
72
+ interface PieChartConfig extends ChartConfigBase {
73
+ variant: "PIE";
74
+ /** CSV column key used as the slice label. */
75
+ categoryKey: string;
76
+ /** CSV column key used as the slice numeric value. */
77
+ valueKey: string;
78
+ }
79
+
80
+ /**
81
+ * Discriminated union of all supported chart variant configs. Assembled here (not in the parent
82
+ * `types.ts`) because the union depends on each variant service file as its single source of
83
+ * truth for that variant's config type.
84
+ *
85
+ * Extension pattern: add a new variant by creating one `*-chart-variant-service.ts` file and
86
+ * extending this union + the `ChartVariantServices` map below. No edits to the dispatcher.
87
+ */
88
+ type ChartConfig = LineChartConfig | BarChartConfig | PieChartConfig;
89
+
90
+ /**
91
+ * Optional stats embedded in `ChartConfig` so clients can pre-render UI before fetching the
92
+ * actual CSV (e.g. a skeleton sized to the eventual row count). Mirrors `TableStats`.
93
+ */
94
+ interface ChartStats {
95
+ /** Total number of rows in the materialised CSV. */
96
+ rowCount: number;
97
+ }
98
+ /**
99
+ * Cross-variant base for `ChartConfig`. Carries the fields every variant shares — series
100
+ * descriptors and optional stats. Per-variant config interfaces (in `chart-variant-services/`)
101
+ * extend this with their own required fields.
102
+ *
103
+ * Note: `series` is always present on the wire (matching the GraphQL `[ChartSeries!]!` shape)
104
+ * even for PIE — PIE just receives an empty array. Keeping it on the base mirrors the wire shape
105
+ * exactly and avoids TS object-literal freshness errors for callers that explicitly set
106
+ * `series: []` on a pie config.
107
+ */
108
+ interface ChartConfigBase {
109
+ /** Series descriptors in render order. LINE/BAR consume these; PIE ignores in favour of `categoryKey`+`valueKey`. */
110
+ series: ChartSeries[];
111
+ /** Optional metadata describing the underlying data — used for loading-state UI. */
112
+ stats?: ChartStats;
113
+ }
114
+ /** Concrete chart artifact record. */
115
+ type ChartArtifactRecord = ArtifactBase<typeof artifactTypes.CHART, ChartConfig>;
116
+ /**
117
+ * Localized labels for the `CHART` artifact's user-facing strings. Covers action buttons AND
118
+ * status messages — see `TableArtifactLabels` for the same shape philosophy. Extends as the
119
+ * chart artifact grows its action set (e.g. future `copyAsPng`); optional keys document
120
+ * anticipated additions without forcing every consumer to provide them today.
121
+ */
122
+ interface ChartArtifactLabels {
123
+ /** Tooltip + aria-label on the Download CSV button in the chart artifact header. */
124
+ download: string;
125
+ /** Status message shown when no presigned URL is available or the chart config is malformed. */
126
+ unavailable: string;
127
+ /** Status message shown when the fetch / parse fails at runtime. */
128
+ loadError: string;
129
+ /** Status message shown while the CSV is being fetched. */
130
+ loading: string;
131
+ /** Status message shown when the fetched CSV has zero data rows. */
132
+ empty: string;
133
+ /**
134
+ * Category labels treated as the "Others" bucket in pie charts (case-insensitive). Matching
135
+ * slices are pinned to the end of the sweep and rendered in neutral grey. The agent writes a
136
+ * translated bucket name in non-English UIs (e.g. "אחרים", "Otros") — consumer passes the
137
+ * localized list here so clay can detect the bucket regardless of language. English fallback
138
+ * is `["Others", "Other"]`. Pass `[]` to disable Others detection (every slice from the palette).
139
+ */
140
+ othersCategoryLabels: readonly string[];
141
+ }
142
+ /** English fallback for `ChartArtifactLabels`. Used when the consumer hasn't passed `labels`. */
143
+ declare const DEFAULT_CHART_ARTIFACT_LABELS: ChartArtifactLabels;
144
+ /**
145
+ * Consumer-supplied side-effect callbacks for actions on the chart artifact. Mirrors
146
+ * `ChartArtifactLabels`'s shape philosophy: one entry per action this artifact exposes
147
+ * (download today; future "Copy as PNG" etc.). Every callback is optional — consumers wire
148
+ * only the actions they care about. The artifact passes its own `ChartArtifactRecord` as the
149
+ * only argument so consumers can derive analytics context (title, config.variant, etc.) without
150
+ * a per-block closure at every render site.
151
+ *
152
+ * The callback fires alongside the default browser behaviour (e.g. `onDownload` does not
153
+ * prevent the anchor's download navigation) — it's purely for analytics / observability hooks.
154
+ */
155
+ interface ChartArtifactCallbacks {
156
+ /** Fires when the Download CSV button is clicked. Browser-native download still happens. */
157
+ onDownload?: (artifact: ChartArtifactRecord) => void;
158
+ }
159
+
160
+ /**
161
+ * A single column descriptor for a `TableArtifact`. Carries the ORDER and LABEL for the
162
+ * rendered table — `key` selects a column from the CSV header; `label` overrides the rendered
163
+ * header text. The CSV is always the source of truth for the data shape; clay never coerces,
164
+ * reformats, or interprets cell values.
165
+ */
166
+ interface TableColumn {
167
+ /** Matches a header in the CSV. Required. Used to project + order the CSV's columns. */
168
+ key: string;
169
+ /** Human-readable header text. Required. */
170
+ label: string;
171
+ /**
172
+ * Accepted in the wire payload but not consulted by the renderer — every cell is rendered as
173
+ * the raw CSV string (or empty for null). Format conversion is a server concern; if a column
174
+ * needs to be "Yes/No" instead of "true/false", the server should emit it that way in the CSV.
175
+ * Kept in the interface so callers that pass `type` (e.g. io-client) don't get a type error.
176
+ */
177
+ type?: "string" | "number" | "date" | "boolean";
178
+ /**
179
+ * Accepted in the wire payload but not consulted by the renderer — every column is left-aligned
180
+ * by design. Kept in the interface for forward-compat; restore per-column alignment by editing
181
+ * `table-artifact-content.tsx` if a future use case justifies it.
182
+ */
183
+ align?: "left" | "center" | "right";
184
+ }
185
+ /**
186
+ * Optional stats embedded in `TableConfig` so clients can pre-render UI before fetching the
187
+ * actual data payload (e.g. N loading shimmers sized to the eventual row count).
188
+ *
189
+ * Backward-compat: optional everywhere — older artifacts persisted before this field shipped
190
+ * still validate. The renderer falls back to a single status-message line when `stats` is absent.
191
+ */
192
+ interface TableStats {
193
+ /** Total number of rows in the materialised CSV. Lets the loading branch render shimmers. */
194
+ rowCount: number;
195
+ }
196
+ /** Rendering config for a table artifact, stored at `artifact.config` (JSONB on the server). */
197
+ interface TableConfig {
198
+ /** Column descriptors in render order. */
199
+ columns: TableColumn[];
200
+ /** Optional metadata describing the underlying data — used for loading-state UI. */
201
+ stats?: TableStats;
202
+ }
203
+ /** Alias retained for callers typed against the table-specific name. */
204
+ type TableRow = ArtifactDataRow;
205
+ /** Concrete table artifact record. */
206
+ type TableArtifactRecord = ArtifactBase<typeof artifactTypes.TABLE, TableConfig>;
207
+ /**
208
+ * Localized labels for the `TABLE` artifact's user-facing strings. Covers both action buttons
209
+ * (download today; future "Copy as CSV", etc.) AND status messages (loading / error / empty /
210
+ * unavailable). Consumer passes the bag from their i18n layer; clay falls back to English
211
+ * defaults when omitted (per-key Partial merge).
212
+ */
213
+ interface TableArtifactLabels {
214
+ /** Tooltip + aria-label on the Download CSV button in the table artifact header. */
215
+ download: string;
216
+ /**
217
+ * Status message shown when no presigned URL is available (permanent server-side absence) or
218
+ * the artifact config is malformed. Both states reduce to "the underlying file isn't usable".
219
+ */
220
+ unavailable: string;
221
+ /** Status message shown when the fetch / parse fails at runtime (transient). */
222
+ loadError: string;
223
+ /** Status message shown while the CSV is being fetched and `stats.rowCount` is not known. */
224
+ loading: string;
225
+ /** Empty-state row inside the table body when the fetched CSV has zero data rows. */
226
+ empty: string;
227
+ }
228
+ /** English fallback for `TableArtifactLabels`. Used when the consumer hasn't passed `labels`. */
229
+ declare const DEFAULT_TABLE_ARTIFACT_LABELS: TableArtifactLabels;
230
+ /**
231
+ * Consumer-supplied side-effect callbacks for actions on the table artifact. Mirrors
232
+ * `ChartArtifactCallbacks` — see that interface for the shape philosophy. Every callback is
233
+ * optional; the artifact passes its own `TableArtifactRecord` as the only argument so consumers
234
+ * can derive analytics context without a per-block closure at every render site.
235
+ */
236
+ interface TableArtifactCallbacks {
237
+ /** Fires when the Download CSV button is clicked. Browser-native download still happens. */
238
+ onDownload?: (artifact: TableArtifactRecord) => void;
239
+ }
240
+
241
+ /**
242
+ * Artifact-domain types — wire-protocol shapes shared between artifact components, block-services,
243
+ * and consumers. Splits responsibilities across three layers so each artifact kind owns its own
244
+ * `types.ts` and this file assembles the cross-type union + service contract:
245
+ *
246
+ * 1. **`artifact-base.ts`** — discriminator (`artifactTypes`), `ArtifactBase<TType, TConfig>`, and
247
+ * `ArtifactDataRow`. Pulled out so each per-type `types.ts` and this assembler can depend on
248
+ * one canonical base without a circular module graph.
249
+ * 2. **`<type>-artifact/types.ts`** — per-artifact-type records, configs, labels, and defaults.
250
+ * Variant-specific types (e.g. `LineChartConfig`) live in even deeper per-variant service files.
251
+ * 3. **This file** — the cross-type `ArtifactRecord` union, the labels map keyed by artifact type,
252
+ * and the `ArtifactService<TArtifact, TLabels>` registry contract used by the dispatcher.
253
+ *
254
+ * Mirrored from the agent / io-server contract — see the `chat-typed-content-blocks-and-artifacts`
255
+ * plan, §6.4 (table contract).
256
+ */
257
+
258
+ /**
259
+ * Per-artifact-type labels map. Lets a consumer pass labels for every artifact kind in a single
260
+ * bag at the block layer (`<ArtifactRefBlock>` payload); the dispatcher routes the matching slice
261
+ * (`labels[artifact.type]`) to the concrete artifact component.
262
+ *
263
+ * Extension pattern: add a new field here when adding a new artifact type. Keep the field
264
+ * optional so older consumers don't break on upgrade.
265
+ */
266
+ interface ArtifactLabelsMap {
267
+ TABLE: TableArtifactLabels;
268
+ CHART: ChartArtifactLabels;
269
+ }
270
+ /**
271
+ * Per-artifact-type callbacks map. Sibling to `ArtifactLabelsMap` — consumer passes a single
272
+ * bag at the block layer covering every artifact type's action callbacks (today: `onDownload`).
273
+ * Used for analytics / observability hooks — every callback is optional and fires alongside
274
+ * the default browser behaviour (it does NOT replace it).
275
+ *
276
+ * Each callback receives its artifact-type's `ArtifactBase`-derived record so consumers can
277
+ * derive analytics context (title, config, etc.) from one wiring at the chat-surface level
278
+ * instead of per-block closures.
279
+ */
280
+ interface ArtifactCallbacksMap {
281
+ TABLE: TableArtifactCallbacks;
282
+ CHART: ChartArtifactCallbacks;
283
+ }
284
+ /**
285
+ * Discriminated union of all supported artifacts. Extension pattern: add the new branch here AND
286
+ * in the `ArtifactServices` map (single source of truth for the type→component mapping). Older
287
+ * clay versions that don't know about a new type silently render nothing — see `ArtifactRefBlock`
288
+ * guard.
289
+ */
290
+ type ArtifactRecord = TableArtifactRecord | ChartArtifactRecord;
291
+ /**
292
+ * Props every concrete artifact component receives from the dispatcher.
293
+ *
294
+ * `labels` is the FULL `ArtifactLabelsMap` bag — every artifact component receives the same
295
+ * shape and reads its own slice internally (`labels?.TABLE`, `labels?.CHART`). One uniform prop
296
+ * type across all artifact components keeps the block-layer dispatcher a generic forward — no
297
+ * per-type branch, no cast, no map-key extraction at the seam.
298
+ */
299
+ interface ArtifactServiceProps<TArtifact extends ArtifactRecord = ArtifactRecord> {
300
+ /** The artifact metadata (config + presigned URL). */
301
+ artifact: TArtifact;
302
+ /**
303
+ * Optional localized labels keyed by artifact type. Each artifact component reads only its
304
+ * own slice (`labels?.TABLE` or `labels?.CHART`); anything omitted falls back to the English
305
+ * default (per-key `Partial` merge against `DEFAULT_*_ARTIFACT_LABELS`).
306
+ */
307
+ labels?: Partial<ArtifactLabelsMap>;
308
+ /**
309
+ * Optional side-effect callbacks keyed by artifact type — for analytics / observability hooks
310
+ * (e.g. tracking a download event). Each artifact component reads only its own slice
311
+ * (`callbacks?.TABLE`, `callbacks?.CHART`). Callbacks fire alongside the default browser
312
+ * behaviour and do not replace it.
313
+ */
314
+ callbacks?: Partial<ArtifactCallbacksMap>;
315
+ }
316
+ /** Per-artifact-type service — registry entry that pairs a discriminator with its concrete component. */
317
+ interface ArtifactService<TArtifact extends ArtifactRecord = ArtifactRecord> {
318
+ /** Discriminator value this service handles. */
319
+ type: (typeof artifactTypes)[keyof typeof artifactTypes];
320
+ /** React component that renders an artifact of this type — composes ai-elements primitives
321
+ * (`Artifact`, `ArtifactHeader`, `ArtifactTitle`, `ArtifactActions`, `ArtifactContent`) directly. */
322
+ Component: ComponentType<ArtifactServiceProps<TArtifact>>;
323
+ /**
324
+ * Returns a plain-text / markdown string suitable for clipboard copy.
325
+ *
326
+ * Called by `ArtifactRefBlockService.toClipboardText` when the user copies a message that
327
+ * contains this artifact. Must be pure and synchronous.
328
+ */
329
+ toClipboardText: (artifact: TArtifact) => string;
330
+ }
331
+
332
+ export { type ArtifactDataRow as A, type BarChartConfig as B, type ChartArtifactLabels as C, DEFAULT_CHART_ARTIFACT_LABELS as D, type LineChartConfig as L, type PieChartConfig as P, type TableArtifactLabels as T, type ArtifactLabelsMap as a, type ArtifactRecord as b, type ArtifactService as c, type ArtifactServiceProps as d, type ArtifactType as e, type ChartArtifactRecord as f, type ChartConfig as g, type ChartStats as h, DEFAULT_TABLE_ARTIFACT_LABELS as i, type TableArtifactRecord as j, type TableColumn as k, type TableConfig as l, type TableRow as m, type TableStats as n, artifactTypes as o, type ArtifactCallbacksMap as p };