@timbal-ai/timbal-react 0.5.4 → 0.6.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 (44) hide show
  1. package/README.md +128 -4
  2. package/dist/app.cjs +5311 -0
  3. package/dist/app.d.cts +29 -0
  4. package/dist/app.d.ts +29 -0
  5. package/dist/app.esm.js +81 -0
  6. package/dist/chart-artifact-C71dk4xI.d.ts +329 -0
  7. package/dist/chart-artifact-CPEpOmtV.d.cts +329 -0
  8. package/dist/chat-CWtQWDtJ.d.cts +650 -0
  9. package/dist/chat-CWtQWDtJ.d.ts +650 -0
  10. package/dist/chat.cjs +4162 -0
  11. package/dist/chat.d.cts +13 -0
  12. package/dist/chat.d.ts +13 -0
  13. package/dist/chat.esm.js +51 -0
  14. package/dist/chunk-4TCJQSIX.esm.js +565 -0
  15. package/dist/chunk-IYENDIRY.esm.js +119 -0
  16. package/dist/chunk-KC5QLVUG.esm.js +22 -0
  17. package/dist/chunk-M4V6Q6XO.esm.js +1082 -0
  18. package/dist/chunk-OFHLFNJH.esm.js +138 -0
  19. package/dist/chunk-OVHR7J3J.esm.js +1574 -0
  20. package/dist/chunk-WLTW56MC.esm.js +66 -0
  21. package/dist/chunk-YJQLLFKP.esm.js +3672 -0
  22. package/dist/index.cjs +1823 -359
  23. package/dist/index.d.cts +15 -931
  24. package/dist/index.d.ts +15 -931
  25. package/dist/index.esm.js +187 -5578
  26. package/dist/layout-B9VayJhZ.d.cts +75 -0
  27. package/dist/layout-CQWngNQ7.d.ts +75 -0
  28. package/dist/studio.cjs +5734 -0
  29. package/dist/studio.d.cts +15 -0
  30. package/dist/studio.d.ts +15 -0
  31. package/dist/studio.esm.js +27 -0
  32. package/dist/styles.css +52 -2
  33. package/dist/timbal-v2-button-F4-z7m33.d.cts +40 -0
  34. package/dist/timbal-v2-button-F4-z7m33.d.ts +40 -0
  35. package/dist/ui.cjs +720 -0
  36. package/dist/ui.d.cts +74 -0
  37. package/dist/ui.d.ts +74 -0
  38. package/dist/ui.esm.js +44 -0
  39. package/dist/welcome--80i_O0p.d.cts +190 -0
  40. package/dist/welcome-BOizSp5h.d.ts +190 -0
  41. package/package.json +35 -3
  42. package/scripts/dev-linked.mjs +66 -0
  43. package/vite/local-dev.d.ts +4 -0
  44. package/vite/local-dev.mjs +71 -0
@@ -0,0 +1,650 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode, FC, ComponentType, Dispatch } from 'react';
3
+ import { AttachmentAdapter } from '@assistant-ui/react';
4
+
5
+ interface ComposerProps {
6
+ /** Placeholder shown in the textarea. Default: "Send a message..." */
7
+ placeholder?: string;
8
+ /**
9
+ * Show the file-attach button and dropzone. Default: follow the runtime
10
+ * (`attachments` on `TimbalChat`). Pass `false` to hide even when uploads
11
+ * are enabled; pass `true` to show only when an attachment adapter is active.
12
+ */
13
+ showAttachments?: boolean;
14
+ /** Extra content rendered inside the toolbar, left of the send button. */
15
+ toolbar?: ReactNode;
16
+ /** Tooltip shown on the send button. Default: "Send message". */
17
+ sendTooltip?: string;
18
+ /** Disable autofocus on mount. Default: false. */
19
+ noAutoFocus?: boolean;
20
+ /** Extra className applied to the outer composer wrapper. */
21
+ className?: string;
22
+ }
23
+ /**
24
+ * Default chat composer — auto-resizing textarea with Enter-to-send,
25
+ * Shift+Enter for newline, attach pill on the left, and a circular send /
26
+ * cancel button on the right. Wraps `ComposerPrimitive` so consumers can
27
+ * override individual slots without losing the Studio chrome.
28
+ */
29
+ declare const Composer: FC<ComposerProps>;
30
+
31
+ interface ThreadSuggestion {
32
+ /** Title shown on the row. Also sent verbatim as the user message. */
33
+ title: string;
34
+ /** Optional secondary line. */
35
+ description?: string;
36
+ /** Optional leading icon. */
37
+ icon?: ReactNode;
38
+ /**
39
+ * Override the prompt sent when the row is clicked. Useful when the row
40
+ * label is short ("Weekly recap") but the prompt should be longer.
41
+ */
42
+ prompt?: string;
43
+ }
44
+ /**
45
+ * Suggestions can be passed as a static array, a thunk that returns an
46
+ * array, or an async function for dynamic / per-user suggestions.
47
+ */
48
+ type SuggestionsSource = ThreadSuggestion[] | (() => ThreadSuggestion[] | Promise<ThreadSuggestion[]>);
49
+ interface ThreadSuggestionsProps {
50
+ suggestions?: SuggestionsSource;
51
+ className?: string;
52
+ }
53
+ /**
54
+ * Render suggestions as a stacked column of full-width rows. Each row reads
55
+ * like a list item rather than a chip, matching the Studio playground.
56
+ *
57
+ * On click the row's `prompt` (or `title` if no prompt) is appended as a
58
+ * user message via the thread runtime.
59
+ */
60
+ declare const Suggestions: FC<ThreadSuggestionsProps>;
61
+ /**
62
+ * Resolve a `SuggestionsSource` to an array. Re-runs when the source
63
+ * identity changes. Sync arrays / sync functions resolve immediately;
64
+ * async functions stream in once the promise settles.
65
+ */
66
+ declare function useResolvedSuggestions(source?: SuggestionsSource): ThreadSuggestion[] | undefined;
67
+ interface SuggestionsSlotProps {
68
+ suggestions?: SuggestionsSource;
69
+ className?: string;
70
+ }
71
+ type SuggestionsComponent = ComponentType<SuggestionsSlotProps>;
72
+
73
+ /** A value that is either a literal or a binding into local state. */
74
+ type UiBindable<T> = T | {
75
+ $bind: string;
76
+ };
77
+ interface UiArtifact {
78
+ type: "ui";
79
+ title?: string;
80
+ /** Initial values for `$bind` references. */
81
+ initialState?: Record<string, unknown>;
82
+ /** Root of the node tree. */
83
+ root: UiNode;
84
+ }
85
+ interface UiNodeBase {
86
+ id?: string;
87
+ className?: string;
88
+ }
89
+ interface UiBoxNode extends UiNodeBase {
90
+ kind: "box";
91
+ /** Flex direction. Default: "col". */
92
+ direction?: "row" | "col";
93
+ /** Tailwind spacing units (gap = `gap * 0.25rem`). */
94
+ gap?: number;
95
+ align?: "start" | "center" | "end" | "stretch";
96
+ justify?: "start" | "center" | "end" | "between" | "around";
97
+ wrap?: boolean;
98
+ padding?: number;
99
+ children?: UiNode[];
100
+ }
101
+ interface UiTextNode extends UiNodeBase {
102
+ kind: "text";
103
+ value: UiBindable<string | number>;
104
+ muted?: boolean;
105
+ size?: "xs" | "sm" | "base" | "lg";
106
+ weight?: "normal" | "medium" | "semibold" | "bold";
107
+ }
108
+ interface UiHeadingNode extends UiNodeBase {
109
+ kind: "heading";
110
+ value: UiBindable<string>;
111
+ level?: 1 | 2 | 3 | 4;
112
+ }
113
+ interface UiBadgeNode extends UiNodeBase {
114
+ kind: "badge";
115
+ value: UiBindable<string>;
116
+ tone?: "default" | "primary" | "success" | "warn" | "danger";
117
+ }
118
+ interface UiButtonNode extends UiNodeBase {
119
+ kind: "button";
120
+ label: UiBindable<string>;
121
+ variant?: "default" | "outline" | "ghost" | "secondary" | "destructive" | "link";
122
+ size?: "sm" | "default" | "lg";
123
+ disabled?: UiBindable<boolean>;
124
+ onClick?: UiAction | UiAction[];
125
+ }
126
+ /**
127
+ * Two-state toggle. `binding` is a dotted state path; clicking flips the
128
+ * stored boolean. Optional `onChange` fires *after* the state flip.
129
+ */
130
+ interface UiToggleNode extends UiNodeBase {
131
+ kind: "toggle";
132
+ label?: UiBindable<string>;
133
+ binding: string;
134
+ onChange?: UiAction | UiAction[];
135
+ }
136
+ /**
137
+ * Numeric range input. `binding` is a dotted state path; the slider reads and
138
+ * writes the stored number. Optional `onChange` fires after each commit.
139
+ */
140
+ interface UiSliderNode extends UiNodeBase {
141
+ kind: "slider";
142
+ binding: string;
143
+ min?: number;
144
+ max?: number;
145
+ step?: number;
146
+ label?: UiBindable<string>;
147
+ /** Show the current value next to the slider. Default: true. */
148
+ showValue?: boolean;
149
+ onChange?: UiAction | UiAction[];
150
+ }
151
+ interface UiTooltipNode extends UiNodeBase {
152
+ kind: "tooltip";
153
+ content: UiBindable<string>;
154
+ side?: "top" | "bottom" | "left" | "right";
155
+ child: UiNode;
156
+ }
157
+ /**
158
+ * Wrap any node to make it draggable. Drag is purely visual — release fires
159
+ * `onDragEnd`. If `snapBack` (default) the child returns to its origin.
160
+ */
161
+ interface UiDraggableNode extends UiNodeBase {
162
+ kind: "draggable";
163
+ child: UiNode;
164
+ axis?: "x" | "y" | "both";
165
+ snapBack?: boolean;
166
+ onDragEnd?: UiAction | UiAction[];
167
+ }
168
+ /**
169
+ * Escape hatch: a host-app-registered component. The host registers a
170
+ * renderer by name via `UiCustomNodeRegistryProvider`; props are passed
171
+ * through after binding resolution and children render recursively.
172
+ */
173
+ interface UiCustomNode extends UiNodeBase {
174
+ kind: "custom";
175
+ name: string;
176
+ props?: Record<string, unknown>;
177
+ children?: UiNode[];
178
+ }
179
+ type UiNode = UiBoxNode | UiTextNode | UiHeadingNode | UiBadgeNode | UiButtonNode | UiToggleNode | UiSliderNode | UiTooltipNode | UiDraggableNode | UiCustomNode;
180
+ type UiAction =
181
+ /** Append a user message to the active thread. */
182
+ {
183
+ kind: "message";
184
+ text: UiBindable<string>;
185
+ }
186
+ /** Set a path in local state to a (possibly bound) value. */
187
+ | {
188
+ kind: "set";
189
+ path: string;
190
+ value: UiBindable<unknown>;
191
+ }
192
+ /** Flip a boolean at the given local-state path. */
193
+ | {
194
+ kind: "toggle";
195
+ path: string;
196
+ }
197
+ /** Bubble a named event to the host app via `UiEventProvider`. */
198
+ | {
199
+ kind: "emit";
200
+ name: string;
201
+ payload?: unknown;
202
+ };
203
+ declare function isUiBinding(value: unknown): value is {
204
+ $bind: string;
205
+ };
206
+
207
+ interface ChartArtifact {
208
+ type: "chart";
209
+ /** Chart kind. Renderer maps these to the underlying lib (e.g. recharts). */
210
+ chartType?: "bar" | "line" | "area" | "pie";
211
+ /** Optional title rendered above the chart. */
212
+ title?: string;
213
+ /** Array of data points. Keys map to series via `dataKey` / `xKey`. */
214
+ data: Array<Record<string, unknown>>;
215
+ /** Field name on each data point used for the X axis / category. */
216
+ xKey?: string;
217
+ /** Field name(s) used for series. Defaults to all keys except `xKey`. */
218
+ dataKey?: string | string[];
219
+ /** Optional unit label appended to numeric axis ticks. */
220
+ unit?: string;
221
+ }
222
+ interface QuestionOption {
223
+ id: string;
224
+ label: string;
225
+ description?: string;
226
+ }
227
+ /**
228
+ * Question artifact — renders an in-thread choice widget. When the user picks
229
+ * an option, the renderer calls back into the runtime with the selected
230
+ * label as a new user message. Agents should treat the user response as the
231
+ * answer.
232
+ */
233
+ interface QuestionArtifact {
234
+ type: "question";
235
+ /** Optional prompt shown above the options. Falls back to the message text. */
236
+ prompt?: string;
237
+ options: QuestionOption[];
238
+ /** Allow selecting more than one option. Default: false. */
239
+ multi?: boolean;
240
+ }
241
+ /** HTML/CSS/JS rendered in an iframe. See {@link HtmlArtifactView}. */
242
+ interface HtmlArtifact {
243
+ type: "html";
244
+ content: string;
245
+ /**
246
+ * When true (default) the HTML renders inside a sandboxed iframe. The
247
+ * sandbox allows scripts, forms, and modals but still isolates the
248
+ * document from the host page. Set to `false` for fully unrestricted
249
+ * inline HTML (scripts, external CDN assets, etc.) — trusted content only.
250
+ */
251
+ sandboxed?: boolean;
252
+ /** Optional title rendered above the iframe. */
253
+ title?: string;
254
+ /** Iframe height in CSS pixels or any valid CSS length. Default: "320px". */
255
+ height?: string;
256
+ }
257
+ interface JsonArtifact {
258
+ type: "json";
259
+ title?: string;
260
+ data: unknown;
261
+ }
262
+ interface TableArtifact {
263
+ type: "table";
264
+ title?: string;
265
+ columns?: Array<{
266
+ key: string;
267
+ label?: string;
268
+ }>;
269
+ rows: Array<Record<string, unknown>>;
270
+ }
271
+
272
+ type TimbalArtifact = ChartArtifact | QuestionArtifact | HtmlArtifact | JsonArtifact | TableArtifact | UiArtifact;
273
+ type AnyArtifact = TimbalArtifact | {
274
+ type: string;
275
+ [key: string]: unknown;
276
+ };
277
+ /**
278
+ * Type guard for artifact-shaped objects. Anything with a string `type` field
279
+ * is considered a candidate; specific renderers narrow further.
280
+ */
281
+ declare function isArtifact(value: unknown): value is AnyArtifact;
282
+
283
+ interface ArtifactRendererProps<T extends AnyArtifact = AnyArtifact> {
284
+ artifact: T;
285
+ }
286
+ type ArtifactRenderer<T extends AnyArtifact = AnyArtifact> = ComponentType<ArtifactRendererProps<T>>;
287
+ type ArtifactRegistry = Record<string, ArtifactRenderer<AnyArtifact>>;
288
+ declare const defaultArtifactRenderers: ArtifactRegistry;
289
+ /**
290
+ * Provide a custom artifact registry to the subtree. Custom renderers are
291
+ * merged on top of the defaults — pass `override: true` to replace.
292
+ */
293
+ declare const ArtifactRegistryProvider: FC<{
294
+ renderers?: ArtifactRegistry;
295
+ override?: boolean;
296
+ children: ReactNode;
297
+ }>;
298
+ declare function useArtifactRegistry(): ArtifactRegistry;
299
+ /**
300
+ * Render an artifact using the closest registry. Falls back to the JSON
301
+ * renderer when no entry matches the artifact's `type`.
302
+ */
303
+ declare const ArtifactView: FC<{
304
+ artifact: AnyArtifact;
305
+ }>;
306
+
307
+ type UiState = Record<string, unknown>;
308
+ type UiStateAction = {
309
+ type: "set";
310
+ path: string;
311
+ value: unknown;
312
+ } | {
313
+ type: "toggle";
314
+ path: string;
315
+ } | {
316
+ type: "replace";
317
+ state: UiState;
318
+ };
319
+ /** Read a dotted path from a state object. Returns undefined when missing. */
320
+ declare function getPath(state: UiState, path: string): unknown;
321
+ /**
322
+ * Set a dotted path on a state object, returning a new object. Intermediate
323
+ * objects are cloned (or created when missing) so the result is safe to use
324
+ * directly with React state without further copying.
325
+ */
326
+ declare function setPath(state: UiState, path: string, value: unknown): UiState;
327
+ /** Resolve a UiBindable into its concrete value against the given state. */
328
+ declare function resolveBindable<T>(value: UiBindable<T>, state: UiState): T;
329
+
330
+ declare function useUiState(): UiState;
331
+ declare function useUiDispatch(): Dispatch<UiStateAction>;
332
+ interface UiEventEnvelope {
333
+ name: string;
334
+ payload?: unknown;
335
+ }
336
+ /**
337
+ * Subscribe the host app to `emit`-kind actions fired from any UiArtifact in
338
+ * the subtree. Wrap your runtime / chat root once.
339
+ */
340
+ declare const UiEventProvider: FC<{
341
+ onEvent: (event: UiEventEnvelope) => void;
342
+ children: ReactNode;
343
+ }>;
344
+ declare function useUiEventEmitter(): ((event: UiEventEnvelope) => void) | null;
345
+ interface UiCustomNodeProps {
346
+ /** Already binding-resolved props from the artifact. */
347
+ props: Record<string, unknown>;
348
+ /** Recursively rendered children. */
349
+ children?: ReactNode;
350
+ }
351
+ type UiCustomNodeRenderer = ComponentType<UiCustomNodeProps>;
352
+ /**
353
+ * Register named renderers for `{ kind: "custom", name: "..." }` nodes. Lets
354
+ * host apps extend the palette without forking the package.
355
+ */
356
+ declare const UiCustomNodeRegistryProvider: FC<{
357
+ renderers: Record<string, UiCustomNodeRenderer>;
358
+ children: ReactNode;
359
+ }>;
360
+ declare function useUiCustomNodeRegistry(): Record<string, UiCustomNodeRenderer>;
361
+
362
+ type ThreadVariant = "default" | "panel";
363
+
364
+ interface ThreadWelcomeConfig {
365
+ heading?: string;
366
+ subheading?: string;
367
+ /**
368
+ * Optional brand icon rendered above the heading. Pass any ReactNode — the
369
+ * SDK no longer ships a default sparkle icon so apps can drop in their
370
+ * own logo or stay minimal.
371
+ */
372
+ icon?: ReactNode;
373
+ }
374
+ interface ThreadWelcomeProps {
375
+ config?: ThreadWelcomeConfig;
376
+ suggestions?: SuggestionsSource;
377
+ /**
378
+ * The resolved `Suggestions` component (default or user-overridden via
379
+ * `components.Suggestions`). Custom Welcome implementations should render
380
+ * this and pass their `suggestions` source through.
381
+ */
382
+ Suggestions?: SuggestionsComponent;
383
+ }
384
+ interface ThreadComponents {
385
+ /** Replace the user message bubble. Access content via `MessagePrimitive.Parts`. */
386
+ UserMessage?: ComponentType;
387
+ /** Replace the assistant message bubble. Access content via `MessagePrimitive.Parts`. */
388
+ AssistantMessage?: ComponentType;
389
+ /** Replace the inline edit composer. */
390
+ EditComposer?: ComponentType;
391
+ /** Replace the composer (input bar). Receives all `ComposerProps` from the parent. */
392
+ Composer?: ComponentType<ComposerProps>;
393
+ /** Replace the welcome / empty state. Renders only while the thread is empty. */
394
+ Welcome?: ComponentType<ThreadWelcomeProps>;
395
+ /** Replace the suggestion list (rendered inside Welcome). */
396
+ Suggestions?: SuggestionsComponent;
397
+ /** Replace the scroll-to-bottom button. */
398
+ ScrollToBottom?: ComponentType;
399
+ }
400
+ interface ThreadArtifactsConfig {
401
+ /** Custom artifact renderers, merged on top of the built-in defaults. */
402
+ renderers?: ArtifactRegistry;
403
+ /** Replace the built-in renderers entirely instead of merging. */
404
+ override?: boolean;
405
+ }
406
+
407
+ interface ThreadProps {
408
+ className?: string;
409
+ /**
410
+ * `panel` — side column / narrow copilot: full width, compact welcome, tighter padding.
411
+ * `default` — centered chat page.
412
+ */
413
+ variant?: ThreadVariant;
414
+ /** Max width of the message column. Default: `44rem` or `100%` when `variant="panel"`. */
415
+ maxWidth?: string;
416
+ /** Welcome screen text + optional brand icon. */
417
+ welcome?: ThreadWelcomeConfig;
418
+ /**
419
+ * Welcome-screen suggestion rows. Accepts a static array, a thunk, or an
420
+ * async function for per-user suggestions.
421
+ */
422
+ suggestions?: SuggestionsSource;
423
+ /** Composer input placeholder. Default: "Send a message...". */
424
+ composerPlaceholder?: string;
425
+ /** Override individual UI slots while keeping the rest as defaults. */
426
+ components?: ThreadComponents;
427
+ /**
428
+ * Configure how rich tool/artifact results render. Pass `renderers` to add
429
+ * support for custom artifact `type` values. Built-in types (`chart`,
430
+ * `question`, `html`, `json`, `table`, `ui`) are always available unless
431
+ * `override: true` is set.
432
+ */
433
+ artifacts?: ThreadArtifactsConfig;
434
+ /**
435
+ * Called when a `ui` artifact fires an `{ kind: "emit" }` action. Use this
436
+ * to react to slider commits, drag gestures, or other host-side logic
437
+ * beyond the built-in `message` action (which already appends a user
438
+ * message).
439
+ */
440
+ onArtifactEvent?: (event: UiEventEnvelope) => void;
441
+ }
442
+ declare const Thread: FC<ThreadProps>;
443
+
444
+ type UploadFetchFn = (url: string, options?: RequestInit) => Promise<Response>;
445
+ interface CreateDefaultAttachmentAdapterOptions {
446
+ /**
447
+ * API base path used to derive the upload URL when {@link uploadUrl} is
448
+ * omitted. Trailing slashes are stripped. Defaults to `""` (relative
449
+ * `/files/upload`).
450
+ */
451
+ baseUrl?: string;
452
+ /**
453
+ * Absolute or relative URL the adapter `POST`s the multipart upload to.
454
+ * Defaults to `${baseUrl}/files/upload`.
455
+ */
456
+ uploadUrl?: string;
457
+ /**
458
+ * Custom fetch used for the upload. Defaults to {@link authFetch}. Do not
459
+ * set `Content-Type` on multipart uploads — the boundary must be automatic.
460
+ */
461
+ fetch?: UploadFetchFn;
462
+ /**
463
+ * MIME / extension `accept` string for the file picker.
464
+ */
465
+ accept?: string;
466
+ }
467
+ /** @deprecated Use {@link CreateDefaultAttachmentAdapterOptions}. */
468
+ type CreateUploadAttachmentAdapterOptions = CreateDefaultAttachmentAdapterOptions;
469
+ declare const DEFAULT_UPLOAD_ACCEPT = "image/*,application/pdf,text/*,.md,.json,.csv,.tsv,.xlsx,.docx";
470
+ /**
471
+ * Build an `AttachmentAdapter` that uploads each file to a Timbal-style
472
+ * `/files/upload` endpoint and returns a `CompleteAttachment` whose
473
+ * `content[]` references the returned URL.
474
+ */
475
+ declare function createDefaultAttachmentAdapter({ baseUrl, uploadUrl, fetch: fetchFn, accept, }?: CreateDefaultAttachmentAdapterOptions): AttachmentAdapter;
476
+ /** @deprecated Alias of {@link createDefaultAttachmentAdapter}. */
477
+ declare const createUploadAttachmentAdapter: typeof createDefaultAttachmentAdapter;
478
+
479
+ /** Tweaks for the built-in upload adapter (see {@link createDefaultAttachmentAdapter}). */
480
+ type TimbalAttachmentsConfig = {
481
+ uploadUrl?: string;
482
+ accept?: string;
483
+ };
484
+ /**
485
+ * Enable or customise composer attachments.
486
+ *
487
+ * - `true` — built-in adapter posting to `${baseUrl}/files/upload`
488
+ * - `{ uploadUrl?, accept? }` — same adapter with overrides
489
+ * - `AttachmentAdapter` — fully custom (e.g. presigned S3)
490
+ * - `null` — disable attachments (no `+` button / dropzone wiring)
491
+ * - `undefined` — off unless legacy `attachmentsUploadUrl` / `attachmentsAccept` are set
492
+ */
493
+ type TimbalAttachmentsProp = boolean | TimbalAttachmentsConfig | AttachmentAdapter | null;
494
+ interface ResolveAttachmentAdapterOptions {
495
+ baseUrl?: string;
496
+ fetch?: CreateDefaultAttachmentAdapterOptions["fetch"];
497
+ /** @deprecated Prefer `attachments={{ uploadUrl }}` */
498
+ uploadUrl?: string;
499
+ /** @deprecated Prefer `attachments={{ accept }}` */
500
+ accept?: string;
501
+ }
502
+ /**
503
+ * Resolve the `AttachmentAdapter` (if any) for {@link TimbalRuntimeProvider}.
504
+ */
505
+ declare function resolveAttachmentAdapter(attachments: TimbalAttachmentsProp | undefined, options?: ResolveAttachmentAdapterOptions): AttachmentAdapter | undefined;
506
+
507
+ interface TextContentPart {
508
+ type: "text";
509
+ text: string;
510
+ }
511
+ interface ThinkingContentPart {
512
+ type: "thinking";
513
+ text: string;
514
+ }
515
+ /**
516
+ * A tool invocation. `argsText` accumulates from streaming `tool_use_delta`
517
+ * events; `result` is set once the matching `tool_result` arrives in the
518
+ * `OUTPUT` event.
519
+ *
520
+ * `result` is always a JSON-serializable value (string, number, object, array)
521
+ * — the runtime preserves whatever the agent returns. `resultText` is the
522
+ * text representation of the result blocks from `tool_result.content`, useful
523
+ * as a quick fallback when callers don't want to walk the structured result.
524
+ */
525
+ interface ToolCallContentPart {
526
+ type: "tool-call";
527
+ toolCallId: string;
528
+ toolName: string;
529
+ argsText: string;
530
+ result?: unknown;
531
+ resultText?: string;
532
+ status?: "running" | "complete" | "error";
533
+ }
534
+ type ContentPart = TextContentPart | ThinkingContentPart | ToolCallContentPart;
535
+ type MessageRole = "user" | "assistant";
536
+ /**
537
+ * A file attached to a user message. We carry a single `dataUrl` field
538
+ * (despite the name, it may be either a `data:<mime>;base64,<bytes>` URL
539
+ * or a real `https://...` URL returned by an upload adapter) and project
540
+ * it both onto the wire (`{type:"file", file: dataUrl}`) and onto the
541
+ * assistant-ui display layer (`ImageMessagePart` / `FileMessagePart`
542
+ * inside `attachments[].content`).
543
+ *
544
+ * Both forms are accepted by Timbal's `FileContent` factory, so the same
545
+ * field works whether the attachment was inlined as base64 or uploaded
546
+ * to object storage.
547
+ */
548
+ interface ChatAttachment {
549
+ id: string;
550
+ type: "image" | "document" | "file";
551
+ name?: string;
552
+ contentType?: string;
553
+ /**
554
+ * Either a `data:<mime>;base64,<bytes>` URL (inline) or a remote
555
+ * `https://...` URL produced by an upload-style {@link AttachmentAdapter}.
556
+ */
557
+ dataUrl: string;
558
+ }
559
+ interface ChatMessage {
560
+ id: string;
561
+ role: MessageRole;
562
+ content: ContentPart[];
563
+ /** Files attached to a user message. Empty/undefined for assistant messages. */
564
+ attachments?: ChatAttachment[];
565
+ /** Run id stamped from the top-level `START` SSE event. */
566
+ runId?: string;
567
+ }
568
+
569
+ type FetchFn = (url: string, options?: RequestInit) => Promise<Response>;
570
+ interface UseTimbalStreamOptions {
571
+ workforceId: string;
572
+ baseUrl?: string;
573
+ fetch?: FetchFn;
574
+ /**
575
+ * When true, every parsed SSE event is `console.debug`-ed with a
576
+ * `[timbal]` prefix. Useful for diagnosing tool/artifact rendering issues
577
+ * without screen-sharing. Default: `false`.
578
+ */
579
+ debug?: boolean;
580
+ }
581
+ interface SendOptions {
582
+ attachments?: ChatAttachment[];
583
+ /** Override the parent run id resolution. Pass `null` to start a new thread. */
584
+ parentId?: string | null;
585
+ }
586
+ interface TimbalStreamApi {
587
+ messages: ChatMessage[];
588
+ isRunning: boolean;
589
+ send: (input: string, options?: SendOptions) => Promise<void>;
590
+ reload: (messageId?: string | null) => Promise<void>;
591
+ cancel: () => void;
592
+ clear: () => void;
593
+ }
594
+ /**
595
+ * Lower-level streaming hook for callers that don't want the full `<Thread>`
596
+ * UI. Exposes the internal message state plus `send`, `reload`, `cancel`, and
597
+ * `clear` actions. Use this to build custom chat surfaces while reusing the
598
+ * Timbal SSE wire format and auth-aware fetching.
599
+ */
600
+ declare function useTimbalStream({ workforceId, baseUrl, fetch: fetchFn, debug, }: UseTimbalStreamOptions): TimbalStreamApi;
601
+ /**
602
+ * Access the underlying `useTimbalStream` API from inside a component tree
603
+ * wrapped by `<TimbalRuntimeProvider>` (or `<TimbalChat>`). Useful for custom
604
+ * UIs that need direct access to messages, send, or cancel without going
605
+ * through the assistant-ui runtime.
606
+ */
607
+ declare function useTimbalRuntime(): TimbalStreamApi;
608
+ interface TimbalRuntimeProviderProps {
609
+ workforceId: string;
610
+ children: ReactNode;
611
+ /**
612
+ * Base URL for API calls. Defaults to `/api`.
613
+ * The provider will POST to `{baseUrl}/workforce/{workforceId}/stream`.
614
+ */
615
+ baseUrl?: string;
616
+ /**
617
+ * Custom fetch function for API calls. Defaults to `authFetch` which
618
+ * attaches Bearer tokens from localStorage and auto-refreshes on 401.
619
+ */
620
+ fetch?: FetchFn;
621
+ /**
622
+ * Enable composer attachments. `true` or `{ uploadUrl?, accept? }` uses
623
+ * the built-in upload adapter (`POST` to `${baseUrl}/files/upload` by
624
+ * default). Pass a custom {@link AttachmentAdapter} for full control, or
625
+ * `null` to disable. Omitted = off (back-compat with pre-attachment chats).
626
+ */
627
+ attachments?: TimbalAttachmentsProp;
628
+ /**
629
+ * Shorthand to enable the default upload adapter with a custom endpoint.
630
+ * Equivalent to `attachments={{ uploadUrl }}` when `attachments` is omitted.
631
+ */
632
+ attachmentsUploadUrl?: string;
633
+ /**
634
+ * Shorthand MIME `accept` for the default upload adapter when `attachments`
635
+ * is omitted or `true`.
636
+ */
637
+ attachmentsAccept?: string;
638
+ /**
639
+ * Forwarded to {@link useTimbalStream}. When `true`, every parsed SSE
640
+ * event is logged via `console.debug` with a `[timbal]` prefix.
641
+ */
642
+ debug?: boolean;
643
+ }
644
+ declare function TimbalRuntimeProvider({ workforceId, children, baseUrl, fetch: fetchFn, attachments, attachmentsUploadUrl, attachmentsAccept, debug, }: TimbalRuntimeProviderProps): react_jsx_runtime.JSX.Element;
645
+
646
+ interface TimbalChatProps extends Omit<TimbalRuntimeProviderProps, "children">, ThreadProps {
647
+ }
648
+ declare function TimbalChat({ workforceId, baseUrl, fetch, attachments, attachmentsUploadUrl, attachmentsAccept, debug, ...threadProps }: TimbalChatProps): react_jsx_runtime.JSX.Element;
649
+
650
+ export { UiCustomNodeRegistryProvider as $, useTimbalRuntime as A, useTimbalStream as B, type ChartArtifact as C, type UiArtifact as D, type UiNode as E, type AnyArtifact as F, type TableArtifact as G, type HtmlArtifact as H, type ArtifactRegistry as I, type JsonArtifact as J, ArtifactRegistryProvider as K, type ArtifactRenderer as L, type ArtifactRendererProps as M, ArtifactView as N, type CreateDefaultAttachmentAdapterOptions as O, type CreateUploadAttachmentAdapterOptions as P, type QuestionArtifact as Q, DEFAULT_UPLOAD_ACCEPT as R, type SendOptions as S, type ThreadVariant as T, type UseTimbalStreamOptions as U, type QuestionOption as V, type ResolveAttachmentAdapterOptions as W, type TimbalArtifact as X, type TimbalAttachmentsConfig as Y, type TimbalAttachmentsProp as Z, type UiAction as _, TimbalChat as a, type UiEventEnvelope as a0, UiEventProvider as a1, type UploadFetchFn as a2, createDefaultAttachmentAdapter as a3, createUploadAttachmentAdapter as a4, defaultArtifactRenderers as a5, getPath as a6, isArtifact as a7, isUiBinding as a8, resolveAttachmentAdapter as a9, resolveBindable as aa, setPath as ab, useArtifactRegistry as ac, useUiCustomNodeRegistry as ad, useUiDispatch as ae, useUiEventEmitter as af, useUiState as ag, type TimbalChatProps as b, type ChatAttachment as c, type ChatMessage as d, Composer as e, type ComposerProps as f, type ContentPart as g, Suggestions as h, type SuggestionsComponent as i, type SuggestionsSlotProps as j, type SuggestionsSource as k, type TextContentPart as l, type ThinkingContentPart as m, Thread as n, type ThreadArtifactsConfig as o, type ThreadComponents as p, type ThreadProps as q, type ThreadSuggestion as r, type ThreadSuggestionsProps as s, type ThreadWelcomeConfig as t, type ThreadWelcomeProps as u, TimbalRuntimeProvider as v, type TimbalRuntimeProviderProps as w, type TimbalStreamApi as x, type ToolCallContentPart as y, useResolvedSuggestions as z };