@daex-dev/chat-ui 0.0.0-stage → 0.8.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.
@@ -0,0 +1,2296 @@
1
+ import * as react from 'react';
2
+ import { ReactNode } from 'react';
3
+ import { AgentChatFileRef, ProviderStatus as ProviderStatus$1, ModelCatalogEntry, DaexThread as DaexThread$1 } from '@daex-dev/sdk';
4
+ export { ProviderStatus as SdkProviderStatus } from '@daex-dev/sdk';
5
+
6
+ /**
7
+ * Public SDK surface that `@daex-dev/chat-ui` renders against.
8
+ *
9
+ * PROVENANCE: the event shapes below are a hand-trimmed subset of
10
+ * `apps/desktop/src/shared/types/chat.ts` (`AgentChatEvent`,
11
+ * `AgentChatEventEnvelope`), reduced to the card set this package draws:
12
+ * user text, assistant text, reasoning, tool call/result, error, status, and
13
+ * the two approval events. DAEX-internal event kinds (subagent lifecycle,
14
+ * scheduled work, plans, todo updates, delegation, ade_card, work-log grouping)
15
+ * are deliberately absent — this package has no DAEX dev concepts in it.
16
+ *
17
+ * Approvals are the exception to "internal", because they are not a DAEX dev
18
+ * concept at all: they are the provider asking the person at the keyboard for
19
+ * permission, and the turn stays blocked until someone answers.
20
+ *
21
+ * This file is a *copy*, not an import: the package is standalone and takes
22
+ * `@daex-dev/sdk` only as an optional peer. `@daex-dev/sdk` is being built in parallel to
23
+ * exactly this contract; the assumptions it must honour are listed in
24
+ * README.md under "SDK contract assumptions".
25
+ */
26
+ /** Stable identifier for an agent provider, e.g. `"claude"`, `"codex"`. */
27
+ type ProviderId = string;
28
+ /** Lifecycle status of a single provider's CLI/credentials. */
29
+ type ProviderStatus = {
30
+ id: ProviderId;
31
+ /** Human label. Falls back to `id` when omitted. */
32
+ displayName?: string;
33
+ /**
34
+ * Provider binary/runtime is present.
35
+ *
36
+ * Read this together with `source`. A runtime that probes the filesystem
37
+ * reports it directly (`source: "probed"`), and `installed: false` then means
38
+ * "looked, found nothing". A runtime that cannot probe leaves the adapter to
39
+ * derive it from the model catalog (`source: "derived"`), where the same
40
+ * `false` only means "DAEX knows no models for it" — which is why the card
41
+ * says "Not detected" rather than "Not installed" in that case.
42
+ */
43
+ installed: boolean;
44
+ /** Credentials are present and usable. */
45
+ authenticated: boolean;
46
+ /** Absolute path of the binary the runtime would spawn. Probed hosts only. */
47
+ binaryPath?: string;
48
+ /** Version string the provider reported, verbatim. Probed hosts only. */
49
+ version?: string;
50
+ /** How `installed`, `binaryPath` and `version` were established. */
51
+ source?: "probed" | "derived";
52
+ /** ISO-8601 time the status was established. */
53
+ checkedAt?: string;
54
+ /** Shell command that authenticates this provider. Rendered copyable. */
55
+ loginCommand?: string;
56
+ /** Shell command that installs this provider. Rendered copyable. */
57
+ installCommand?: string;
58
+ /** Short human explanation for the current state (e.g. "Token expired"). */
59
+ detail?: string;
60
+ docsUrl?: string;
61
+ };
62
+ /** One selectable model. */
63
+ type ModelDescriptor = {
64
+ id: string;
65
+ providerId: ProviderId;
66
+ displayName: string;
67
+ shortName?: string;
68
+ /** Secondary grouping inside a provider (e.g. a hosting vendor). */
69
+ subProvider?: string;
70
+ aliases?: string[];
71
+ description?: string;
72
+ /**
73
+ * Explicitly false marks a model the host knows is unusable even when its
74
+ * provider is authenticated. Undefined means "usable if the provider is".
75
+ */
76
+ available?: boolean;
77
+ /**
78
+ * Reasoning-effort levels this model accepts, in the order to offer them
79
+ * (e.g. `["low", "medium", "high"]`). Absent or empty means the model takes
80
+ * no effort setting, and `<ModelPicker>` draws no effort control for it.
81
+ */
82
+ reasoningEfforts?: string[];
83
+ /** The effort the runtime uses when none is chosen. */
84
+ defaultReasoningEffort?: string | null;
85
+ };
86
+ /**
87
+ * The model a thread is actually bound to, as the runtime resolved it.
88
+ *
89
+ * This can differ from the id the host asked for: a runtime resolves a retired
90
+ * id forward to its successor, so `modelId` here may not be in the catalog the
91
+ * picker shows. `displayName` is the runtime's name for it, and a UI should
92
+ * prefer it over printing a raw id. Mirrors the type of the same name in
93
+ * `@daex-dev/sdk` >= 0.3; every field past `modelId` is optional so an older
94
+ * SDK or a proxy that forwards less still fits.
95
+ */
96
+ type ThreadModelSelection = {
97
+ modelId: string;
98
+ displayName?: string | null;
99
+ provider?: string;
100
+ };
101
+ /** Running state of a thread, as reported by `thread.on("status")`. */
102
+ type ThreadStatus = {
103
+ state: "idle" | "running" | "error";
104
+ turnId?: string | null;
105
+ message?: string;
106
+ };
107
+ /** Token accounting, as reported by `thread.on("usage")`. */
108
+ type ThreadUsage = {
109
+ inputTokens?: number;
110
+ outputTokens?: number;
111
+ totalTokens?: number;
112
+ contextWindow?: number;
113
+ };
114
+ /**
115
+ * An attachment handed to `send`/`steer`. Opaque to this package.
116
+ *
117
+ * `id` is the attachment's identity: the composer de-duplicates its staged
118
+ * list by it, and it is the React key the chips render under. Two different
119
+ * files must not share one.
120
+ */
121
+ type ChatAttachment = {
122
+ id: string;
123
+ name: string;
124
+ mimeType?: string;
125
+ /** Local path or URL — whichever the host's SDK client understands. */
126
+ uri?: string;
127
+ sizeBytes?: number;
128
+ /**
129
+ * How the runtime should hand the file to the model. `"image"` sends the
130
+ * bytes as an image; `"file"` sends a path hint. Omit it and `adaptSdkClient`
131
+ * infers it with the runtime's rule (`inferAttachmentType`): an `image/*`
132
+ * `mimeType`, else an image extension on `uri` (bmp, gif, heic, heif, ico,
133
+ * jpeg, jpg, png, svg, tif, tiff, webp), else `"file"`.
134
+ */
135
+ type?: "file" | "image";
136
+ /**
137
+ * `false` makes the attachment reference-only: the runtime never reads its
138
+ * bytes (no staging copy, no download of a cloud placeholder) and the model
139
+ * gets the path. An image sent this way arrives as a path, not as pixels.
140
+ * Omitted means the runtime default (read the file). Needs a DAEX runtime
141
+ * that understands the flag; an older one ignores it and reads the file.
142
+ */
143
+ hydrate?: boolean;
144
+ };
145
+ type SendInput = {
146
+ text: string;
147
+ attachments?: ChatAttachment[];
148
+ };
149
+ type ThreadOpenOptions = {
150
+ modelId?: string;
151
+ providerId?: ProviderId;
152
+ /** Resume an existing provider-side thread rather than starting fresh. */
153
+ resume?: boolean;
154
+ };
155
+ type ToolCallStatus = "running" | "completed" | "failed" | "interrupted";
156
+ /** What the provider wants confirmed. */
157
+ type ApprovalKind = "command" | "file_change" | "tool_call";
158
+ /**
159
+ * The three answers this package can send.
160
+ *
161
+ * `accept_always` is the one that makes approvals bearable over a long session:
162
+ * it settles this request and stops the provider asking again for the same
163
+ * thing. The client maps these onto whatever its runtime spells them.
164
+ */
165
+ type ApprovalDecision = "accept" | "accept_always" | "reject";
166
+ /** An outstanding approval, as `thread.pendingApprovals()` reports one. */
167
+ type ApprovalRequest = {
168
+ itemId: string;
169
+ /** SDK request id used by `thread.respond`; defaults to `itemId`. */
170
+ requestId?: string;
171
+ logicalItemId?: string;
172
+ kind: ApprovalKind;
173
+ requestKind?: string;
174
+ description: string;
175
+ title?: string | null;
176
+ source?: string;
177
+ questions?: PendingInputQuestion[];
178
+ options?: PendingInputOption[];
179
+ allowsFreeform?: boolean;
180
+ canProceedWithoutAnswer?: boolean;
181
+ providerMetadata?: Record<string, unknown>;
182
+ turnId?: string;
183
+ detail?: unknown;
184
+ /**
185
+ * Optional on purpose: the SDK always knows which provider raised a request,
186
+ * but a proxy that only forwards the chat surface may not, and this package
187
+ * renders the same card either way.
188
+ */
189
+ provider?: ProviderId;
190
+ };
191
+ /** One option in a provider's structured question. */
192
+ type PendingInputOption = {
193
+ label: string;
194
+ value: string;
195
+ description?: string;
196
+ recommended?: boolean;
197
+ preview?: string;
198
+ previewFormat?: "markdown" | "html";
199
+ };
200
+ /** A question the provider is waiting for the host to answer. */
201
+ type PendingInputQuestion = {
202
+ id: string;
203
+ header?: string;
204
+ question: string;
205
+ options?: PendingInputOption[] | null;
206
+ multiSelect?: boolean;
207
+ allowsFreeform?: boolean;
208
+ isSecret?: boolean;
209
+ defaultAssumption?: string | null;
210
+ impact?: string | null;
211
+ };
212
+ /** Decision values accepted by the runtime's respondToInput action. */
213
+ type PendingInputDecision = "accept" | "accept_for_session" | "decline" | "cancel";
214
+ /** Answer payload for one pending question or plan request. */
215
+ type PendingInputResponse = {
216
+ answers?: Record<string, string | string[]>;
217
+ decision?: PendingInputDecision;
218
+ responseText?: string | null;
219
+ };
220
+ /** One message waiting in the SDK steer queue. */
221
+ type QueuedMessage = {
222
+ id: string;
223
+ text: string;
224
+ /** The files sent with it, as the SDK's file references. */
225
+ attachments?: ReadonlyArray<{
226
+ path: string;
227
+ type?: "file" | "image";
228
+ }>;
229
+ createdAt?: string;
230
+ dispatched?: boolean;
231
+ };
232
+ /** Queue methods are optional so older SDK clients remain usable. */
233
+ type ThreadQueue = {
234
+ list?(): Promise<readonly QueuedMessage[]>;
235
+ cancel?(id: string): Promise<void>;
236
+ edit?(id: string, text: string): Promise<void>;
237
+ move?(id: string, index: number): Promise<void>;
238
+ dispatch?(id: string): Promise<void>;
239
+ cancelDispatched?(id: string): Promise<void>;
240
+ restore?(): Promise<void>;
241
+ };
242
+ /** One quota window of an account ("5-hour", "Weekly", …). */
243
+ type AccountUsageWindow = {
244
+ type: string;
245
+ label: string;
246
+ percentLeft: number;
247
+ resetsAt: string | null;
248
+ unlimited?: boolean;
249
+ /** Exact request meter, for providers that count requests. */
250
+ countLeft?: number;
251
+ countTotal?: number;
252
+ };
253
+ /** Runtime-reported usage room for one provider account. */
254
+ type AccountUsage = {
255
+ /** `ok` is a fresh reading; the others say why the numbers are old or missing. */
256
+ state: "ok" | "stale" | "expired" | "signed_out" | "no_reading" | "error" | (string & {});
257
+ readAt: string | null;
258
+ /** Why the state is not `ok`, in a few words. */
259
+ note: string | null;
260
+ windows: AccountUsageWindow[];
261
+ };
262
+ /** Public account summary. Secret values are never part of this shape. */
263
+ type AccountInfo = {
264
+ id: string;
265
+ provider: ProviderId;
266
+ label: string;
267
+ email?: string;
268
+ plan?: string;
269
+ signedIn: boolean;
270
+ isDefault: boolean;
271
+ loginBroken?: boolean;
272
+ usage?: AccountUsage;
273
+ };
274
+ /** A provider sign-in's status, as `@daex-dev/sdk`'s `SignInStatus` reports it. */
275
+ type SignInUpdate = {
276
+ loginId?: string;
277
+ state: "running" | "verifying" | "succeeded" | "failed" | "cancelled" | "expired" | (string & {});
278
+ /** The link to finish signing in, once the provider printed it. */
279
+ url?: string | null;
280
+ /** True while the provider waits for a code pasted back from the browser. */
281
+ awaitingCode?: boolean;
282
+ /** A device code to enter on the provider's page, when it uses one. */
283
+ deviceCode?: string;
284
+ message?: string;
285
+ };
286
+ interface SignInHandle {
287
+ on(event: "update", cb: (update: SignInUpdate) => void): Unsubscribe;
288
+ submitCode(code: string): Promise<void>;
289
+ cancel(): Promise<void>;
290
+ done: Promise<AccountInfo>;
291
+ }
292
+ /** Non-secret credential metadata. The API key is deliberately absent. */
293
+ type ApiCredentialInfo = {
294
+ credentialId: string;
295
+ provider: ProviderId;
296
+ label: string;
297
+ /** The last few characters of the key, so a person can tell keys apart. */
298
+ maskedTail?: string;
299
+ createdAt?: string;
300
+ };
301
+ type ProviderCapabilities = {
302
+ permissionModes?: string[];
303
+ reasoningEfforts?: string[];
304
+ fastMode?: boolean;
305
+ multipleAccounts?: boolean;
306
+ signIn?: "cli-login" | "device-code" | "api-key" | "none";
307
+ apiKeys?: boolean;
308
+ presets?: boolean;
309
+ mcp?: "full" | "partial" | "none";
310
+ };
311
+ /** Client-level notification: one thread's usage-limit state changed. */
312
+ type UsageLimitEvent = {
313
+ /** Thread key. */
314
+ key: string;
315
+ sessionId?: string;
316
+ provider?: ProviderId;
317
+ /** Null when the limit cleared. */
318
+ status: UsageLimitStatus | null;
319
+ };
320
+ /** Host-agnostic subset of the runtime's live usage-limit resume status. */
321
+ type UsageLimitStatus = {
322
+ state: "armed" | "resuming" | "paused" | "opted_out" | "no_reset" | "limited" | (string & {});
323
+ provider?: ProviderId;
324
+ fireAt?: string | null;
325
+ resetAt?: string | null;
326
+ turnId?: string | null;
327
+ alternateAccount?: {
328
+ instanceId: string;
329
+ label: string;
330
+ } | null;
331
+ alternateAccounts?: Array<{
332
+ id: string;
333
+ label: string;
334
+ }>;
335
+ };
336
+ type SlashCommand = {
337
+ name: string;
338
+ description?: string;
339
+ argumentHint?: string;
340
+ };
341
+ type AccountManagement = {
342
+ list?(provider?: ProviderId): Promise<readonly AccountInfo[]>;
343
+ add?(provider: ProviderId, options?: {
344
+ label?: string;
345
+ }): Promise<AccountInfo>;
346
+ remove?(id: string): Promise<unknown>;
347
+ rename?(id: string, label: string): Promise<AccountInfo | void>;
348
+ setDefault?(id: string): Promise<unknown>;
349
+ signOut?(id: string): Promise<unknown>;
350
+ refresh?(): Promise<readonly AccountInfo[]>;
351
+ signIn?(id: string, options?: {
352
+ deviceAuth?: boolean;
353
+ }): Promise<SignInHandle>;
354
+ };
355
+ type CredentialManagement = {
356
+ list?(provider?: ProviderId): Promise<readonly ApiCredentialInfo[]>;
357
+ add?(input: {
358
+ provider: ProviderId;
359
+ key: string;
360
+ label?: string;
361
+ }): Promise<ApiCredentialInfo>;
362
+ remove?(credentialId: string, provider?: ProviderId): Promise<unknown>;
363
+ verify?(provider: ProviderId): Promise<unknown>;
364
+ };
365
+ type ChatEventUserMessage = {
366
+ type: "user_message";
367
+ text: string;
368
+ displayText?: string;
369
+ messageId?: string;
370
+ turnId?: string;
371
+ attachments?: ChatAttachment[];
372
+ };
373
+ type ChatEventText = {
374
+ type: "text";
375
+ text: string;
376
+ messageId?: string;
377
+ turnId?: string;
378
+ itemId?: string;
379
+ };
380
+ type ChatEventReasoning = {
381
+ type: "reasoning";
382
+ text: string;
383
+ turnId?: string;
384
+ itemId?: string;
385
+ summaryIndex?: number;
386
+ };
387
+ /**
388
+ * The MCP identity a runtime attaches to a tool event when it knows it (Codex
389
+ * does, as `mcp: { server, tool }`). Preferred over parsing the tool string.
390
+ */
391
+ type ChatEventMcpSource = {
392
+ server?: string;
393
+ tool?: string;
394
+ };
395
+ type ChatEventToolCall = {
396
+ type: "tool_call";
397
+ tool: string;
398
+ args: unknown;
399
+ itemId: string;
400
+ logicalItemId?: string;
401
+ turnId?: string;
402
+ mcp?: ChatEventMcpSource;
403
+ };
404
+ /**
405
+ * An MCP `resource_link` content item a tool returned, carried as data rather
406
+ * than left inside the result text. The runtime fills it when the provider
407
+ * reports structured tool content.
408
+ */
409
+ type AgentChatResourceLink = {
410
+ uri: string;
411
+ name?: string;
412
+ title?: string;
413
+ mimeType?: string;
414
+ };
415
+ type ChatEventToolResult = {
416
+ type: "tool_result";
417
+ tool: string;
418
+ result: unknown;
419
+ itemId: string;
420
+ logicalItemId?: string;
421
+ turnId?: string;
422
+ status?: ToolCallStatus;
423
+ mcp?: ChatEventMcpSource;
424
+ /** Structured MCP `resource_link` items, when the runtime passes them on. */
425
+ resourceLinks?: AgentChatResourceLink[];
426
+ };
427
+ type ChatEventError = {
428
+ type: "error";
429
+ message: string;
430
+ detail?: string;
431
+ turnId?: string;
432
+ itemId?: string;
433
+ };
434
+ type ChatEventStatus = {
435
+ type: "status";
436
+ turnStatus: "started" | "completed" | "interrupted" | "failed";
437
+ turnId?: string;
438
+ message?: string;
439
+ /**
440
+ * Set only on the SDK's own `"failed"` status for a runtime that went away
441
+ * mid-turn (`@daex-dev/sdk` >= 0.3); the runtime never sends it. It ends the
442
+ * turn like any `"failed"`.
443
+ */
444
+ synthetic?: true;
445
+ };
446
+ /**
447
+ * The provider is blocked on a person answering. The turn does not proceed
448
+ * until `thread.approve()` settles it or `thread.interrupt()` ends the turn, so
449
+ * a host that receives one and draws nothing looks frozen.
450
+ */
451
+ type ChatEventApprovalRequest = {
452
+ type: "approval_request";
453
+ itemId: string;
454
+ /** Stable across a provider renumbering items; preferred for matching. */
455
+ logicalItemId?: string;
456
+ /** The shape of the thing being confirmed. */
457
+ kind: ApprovalKind;
458
+ /**
459
+ * The finer request type. `kind` has no word for a question, so a provider
460
+ * asking for prose rides this event with `requestKind: "question"`. Those
461
+ * cannot be answered with accept/reject and render read-only here.
462
+ */
463
+ requestKind?: string;
464
+ description: string;
465
+ turnId?: string;
466
+ /** Provider payload: the command string, the patch, the tool input. */
467
+ detail?: unknown;
468
+ };
469
+ /** An `approval_request` reached a decision — by this host or by another one. */
470
+ type ChatEventPendingInputResolved = {
471
+ type: "pending_input_resolved";
472
+ itemId: string;
473
+ /** Matched when `itemId` finds no card, for a provider that renumbers items. */
474
+ logicalItemId?: string;
475
+ resolution: "accepted" | "declined" | "cancelled";
476
+ turnId?: string;
477
+ };
478
+ /** The event kinds this package draws. Everything else is dropped. */
479
+ type RenderedChatEvent = ChatEventUserMessage | ChatEventText | ChatEventReasoning | ChatEventToolCall | ChatEventToolResult | ChatEventError | ChatEventStatus | ChatEventApprovalRequest | ChatEventPendingInputResolved;
480
+ /**
481
+ * Any other event kind, carried but not drawn.
482
+ *
483
+ * DAEX's own event union has ~60 members and grows every release, and `@daex-dev/sdk`
484
+ * models it as exactly this open record. Closing it here would make an SDK
485
+ * envelope unassignable to this one — a compile error for every embedder — and
486
+ * would invite a runtime cast at the boundary. Open instead: the renderer
487
+ * narrows with `RENDERED_TYPES` and ignores what it does not recognise, so a
488
+ * newer runtime adds event kinds without breaking an older `@daex-dev/chat-ui`.
489
+ */
490
+ type UnknownChatEvent = {
491
+ type: string;
492
+ [key: string]: unknown;
493
+ };
494
+ type AgentChatEvent = RenderedChatEvent | UnknownChatEvent;
495
+ type AgentChatEventEnvelope = {
496
+ sessionId: string;
497
+ /** ISO-8601. Ordering is envelope-based, never provider-clock based. */
498
+ timestamp: string;
499
+ event: AgentChatEvent;
500
+ sequence?: number;
501
+ };
502
+ /** Unsubscribe handle returned by every `on*` registration. */
503
+ type Unsubscribe = () => void;
504
+ /** Options for one `historyPage` read. */
505
+ type HistoryPageOptions = {
506
+ /** Return envelopes strictly older than this sequence. Omit for the newest page. */
507
+ beforeSequence?: number;
508
+ /** Page size. The runtime caps it. */
509
+ limit?: number;
510
+ };
511
+ /** One page of transcript history, oldest envelope first. */
512
+ type ThreadHistoryPage = {
513
+ events: AgentChatEventEnvelope[];
514
+ /** More envelopes exist before this page. */
515
+ hasMore: boolean;
516
+ /**
517
+ * Pass as `beforeSequence` to read the next older page. Null or absent when
518
+ * the runtime gave none; the hook then pages from the oldest sequence it holds.
519
+ */
520
+ nextBeforeSequence?: number | null;
521
+ };
522
+ /** A change to an open thread's settings (`DaexThread.update`). */
523
+ type ThreadUpdatePatch = {
524
+ /** New title. `null` clears the host title. */
525
+ title?: string | null;
526
+ /** Reasoning effort for later turns. `null` returns to the model default. */
527
+ reasoningEffort?: string | null;
528
+ /** Provider fast mode, where the provider has one. */
529
+ fastMode?: boolean;
530
+ };
531
+ /**
532
+ * What `DaexThread.update` resolves to. An SDK thread resolves `{ title, model }`;
533
+ * only `model` is read, and a client may resolve nothing.
534
+ */
535
+ type ThreadUpdateReply = {
536
+ model?: unknown;
537
+ } | null | void;
538
+ /** The runtime lifecycle events a client can report (`DaexChatClient.on`). */
539
+ type DaexChatClientEventMap = {
540
+ /**
541
+ * One automatic runtime restart attempt finished (`@daex-dev/sdk`
542
+ * `autoRestart`). `ok: true` means the runtime is back and open threads were
543
+ * reattached. `attempt` counts from 1 per outage.
544
+ */
545
+ restart: {
546
+ attempt: number;
547
+ ok: boolean;
548
+ error: string | null;
549
+ final?: boolean;
550
+ };
551
+ usageLimit: UsageLimitEvent;
552
+ };
553
+ interface DaexThread {
554
+ readonly key: string;
555
+ send(input: SendInput | string): Promise<void>;
556
+ /**
557
+ * Deliver a message into an already-running turn.
558
+ *
559
+ * Attachments on `input` are forwarded, and an attachment-only steer (empty
560
+ * text) is valid. Both need `@daex-dev/sdk` >= 0.3: an older SDK thread's
561
+ * `steer(text)` ignores the attachments, and refuses an empty text.
562
+ */
563
+ steer(input: SendInput | string): Promise<void>;
564
+ interrupt(): Promise<void>;
565
+ /**
566
+ * Switch this thread's model mid-conversation, crossing providers if the id
567
+ * resolves to a different one. The conversation continues — the engine
568
+ * replays the transcript rather than starting over.
569
+ *
570
+ * OPTIONAL on purpose. Making it required would break every hand-written
571
+ * client implementing this interface, including hosts outside this repo, for
572
+ * a capability their runtime may not have. `ThreadState.canSetModel` reports
573
+ * its presence so a picker can be disabled with a reason rather than
574
+ * accepting a click that silently does nothing.
575
+ */
576
+ setModel?(modelId: string): Promise<unknown>;
577
+ /**
578
+ * Answer an approval the thread emitted.
579
+ *
580
+ * OPTIONAL for the same reason as `setModel`: a client whose runtime has no
581
+ * answer path must be able to say so, and `ThreadState.canApprove` reports
582
+ * its presence so the card renders read-only instead of offering a button
583
+ * that would throw. Resolves once the runtime accepts the decision, not once
584
+ * the tool has run.
585
+ */
586
+ approve?(itemId: string, decision: ApprovalDecision, responseText?: string): Promise<void>;
587
+ /** Outstanding requests, so a host re-rendering after a reload restores cards. */
588
+ pendingApprovals?(): Promise<readonly ApprovalRequest[]>;
589
+ /** Answer a question or plan request. Older clients render those cards read-only. */
590
+ respond?(requestId: string, response: PendingInputResponse): Promise<void>;
591
+ /** Optional steer queue operations. */
592
+ queue?: ThreadQueue;
593
+ /** Available provider slash commands, when the runtime exposes them. */
594
+ slashCommands?(): Promise<readonly SlashCommand[]>;
595
+ /** Per-thread usage-limit controls. */
596
+ usageLimit?: {
597
+ /** Answers `{ ok: false, message }` when the runtime refuses. */
598
+ resumeNow?(): Promise<unknown>;
599
+ continueOnAlternate?(): Promise<unknown>;
600
+ };
601
+ /** Switch this thread to another signed-in provider account. */
602
+ switchAccount?(instanceId: string): Promise<unknown>;
603
+ history(): Promise<AgentChatEventEnvelope[]>;
604
+ /**
605
+ * Read one page of history, newest first by page (each page oldest-first).
606
+ *
607
+ * OPTIONAL: `useDaexThread` uses it when present — the newest page on open,
608
+ * older pages on demand — and falls back to one `history()` read otherwise.
609
+ * A client without it (an SDK before 0.3, a proxy) loads the whole window.
610
+ */
611
+ historyPage?(request?: HistoryPageOptions): Promise<ThreadHistoryPage>;
612
+ /**
613
+ * The model the runtime has this thread on, resolved (see `ThreadModelSelection`).
614
+ *
615
+ * OPTIONAL: read after `open` and after every `setModel`. Absent or null on a
616
+ * client that does not report it, and the UI then names the model from the
617
+ * catalog alone.
618
+ */
619
+ readonly model?: ThreadModelSelection | null;
620
+ /**
621
+ * Change the thread's title, reasoning effort or fast mode
622
+ * (`@daex-dev/sdk` >= 0.3 `thread.update`).
623
+ *
624
+ * OPTIONAL for the same reason as `setModel`. `ThreadState.canUpdate`
625
+ * reports its presence. A reasoning or fast-mode change is refused while a
626
+ * turn runs (`DaexError` code `turn_in_flight` on `@daex-dev/sdk` >= 0.4).
627
+ */
628
+ update?(patch: ThreadUpdatePatch): Promise<ThreadUpdateReply>;
629
+ /**
630
+ * Run the last user message again (`@daex-dev/sdk` >= 0.4 `thread.retry`).
631
+ * The runtime rolls the provider conversation back to before that message,
632
+ * removes the old turn from the transcript, and sends the message again.
633
+ * Files the old turn changed are not restored.
634
+ *
635
+ * OPTIONAL like `setModel`; `ThreadState.canRetry` reports its presence. A
636
+ * provider that cannot roll back (only Claude and Codex can) rejects with
637
+ * code `unsupported`, and a running turn with `turn_in_flight`.
638
+ */
639
+ retry?(): Promise<unknown>;
640
+ /**
641
+ * Like `retry`, with new text for the last user message. `attachments`
642
+ * replaces the original message's attachments; an empty list removes them,
643
+ * and leaving it out keeps them.
644
+ */
645
+ editLast?(input: SendInput | string): Promise<unknown>;
646
+ on(type: "event", cb: (envelope: AgentChatEventEnvelope) => void): Unsubscribe;
647
+ on(type: "usage", cb: (usage: ThreadUsage) => void): Unsubscribe;
648
+ on(type: "status", cb: (status: ThreadStatus) => void): Unsubscribe;
649
+ }
650
+ interface DaexChatClient {
651
+ providers: {
652
+ status(): Promise<ProviderStatus[]>;
653
+ onChange(cb: (statuses: ProviderStatus[]) => void): Unsubscribe;
654
+ /**
655
+ * Re-probe now, bypassing whatever cache the runtime keeps.
656
+ *
657
+ * OPTIONAL: a client that derives statuses from a catalog has nothing to
658
+ * re-probe. A host renders a "Check again" button only when it is present.
659
+ */
660
+ refresh?(): Promise<ProviderStatus[]>;
661
+ capabilities?(provider: ProviderId): Promise<ProviderCapabilities | null>;
662
+ };
663
+ models: {
664
+ list(): Promise<ModelDescriptor[]>;
665
+ };
666
+ threads: {
667
+ open(key: string, opts?: ThreadOpenOptions): Promise<DaexThread>;
668
+ };
669
+ /** Account management is optional and disabled for untrusted renderers by default. */
670
+ accounts?: AccountManagement;
671
+ /** Credential operations accept a key but never return one. */
672
+ credentials?: CredentialManagement;
673
+ /**
674
+ * Runtime lifecycle events.
675
+ *
676
+ * OPTIONAL: a client without a runtime it can restart has nothing to report.
677
+ * `useDaexThread` subscribes to `restart` and, after a successful restart,
678
+ * re-opens the thread and re-reads its history, so the transcript shows what
679
+ * the runtime has rather than what this view held before the outage.
680
+ */
681
+ on?<E extends keyof DaexChatClientEventMap>(event: E, cb: (payload: DaexChatClientEventMap[E]) => void): Unsubscribe;
682
+ }
683
+ /** @deprecated Use {@link DaexChatClient}. */
684
+ type AdeChatClient = DaexChatClient;
685
+ /** @deprecated Use {@link DaexChatClientEventMap}. */
686
+ type AdeChatClientEventMap = DaexChatClientEventMap;
687
+ /** @deprecated Use {@link DaexThread}. */
688
+ type AdeThread = DaexThread;
689
+
690
+ /**
691
+ * Merge `incoming` into `current`, keyed by `id`.
692
+ *
693
+ * An id already staged is replaced in place (newer metadata, same position);
694
+ * a new id is appended; duplicate ids inside either list collapse to their
695
+ * last occurrence's data at their first occurrence's position. The result
696
+ * never holds one id twice.
697
+ */
698
+ declare function mergeAttachments(current: readonly ChatAttachment[], incoming?: readonly ChatAttachment[]): ChatAttachment[];
699
+ type ComposerProps = {
700
+ /**
701
+ * Start a new turn. Resolve `false` to decline: the composer puts the draft
702
+ * and the staged attachments back, with no error shown. Any other result
703
+ * leaves the composer cleared.
704
+ */
705
+ onSend: (input: SendInput) => unknown;
706
+ /**
707
+ * Deliver into a running turn. Omit to disable steering entirely.
708
+ *
709
+ * Receives the staged attachments exactly like `onSend`, and is called with
710
+ * empty text when only attachments are staged. The composer clears its
711
+ * staged files when the steer is handed off and puts them back if it throws.
712
+ */
713
+ onSteer?: (input: SendInput) => void | Promise<void>;
714
+ /** Stop the running turn. Omit to hide the stop control. */
715
+ onInterrupt?: () => void | Promise<void>;
716
+ status?: ThreadStatus["state"];
717
+ /** False while the thread handle is still resolving. */
718
+ ready?: boolean;
719
+ disabled?: boolean;
720
+ /** Uncontrolled by default; pass both to control the draft. */
721
+ value?: string;
722
+ onValueChange?: (value: string) => void;
723
+ placeholder?: string;
724
+ /** Enter sends (default). False swaps to Cmd/Ctrl+Enter. */
725
+ sendOnEnter?: boolean;
726
+ autoFocus?: boolean;
727
+ /** Grow up to this many rows before scrolling. */
728
+ maxRows?: number;
729
+ /**
730
+ * Invoked when the attachment button is pressed. Resolve with the
731
+ * attachments to stage, or null to cancel. Omit to hide the button.
732
+ *
733
+ * The composer stages what this returns itself — do NOT also add the
734
+ * returned items to a controlled `attachments` list, or they are merged a
735
+ * second time (harmlessly, since ids de-duplicate, but pointlessly). See
736
+ * `attachments` for the merge rule.
737
+ */
738
+ onRequestAttachment?: () => Promise<ChatAttachment[] | null> | ChatAttachment[] | null;
739
+ /**
740
+ * Controlled attachment list; omit to let the composer manage its own.
741
+ *
742
+ * MERGE RULE. `onAttachmentsChange` is always called with the COMPLETE next
743
+ * list; replace your state with it, never append it. The composer computes
744
+ * that list as follows:
745
+ * - Picker (`onRequestAttachment`): once the picker resolves, the returned
746
+ * items are merged into the LATEST `attachments` value (read after the
747
+ * await), so anything the host staged while the picker was open — a
748
+ * drop, a paste — is kept.
749
+ * - Merge is by `id`: an id already staged is replaced in place, a new id
750
+ * is appended. Duplicate ids in the list you pass are shown once.
751
+ * - Remove (the × on a chip) drops that one id and keeps everything else.
752
+ * - Submit sends the list and then calls `onAttachmentsChange([])`; a
753
+ * failed send or steer restores the sent items merged with whatever was
754
+ * staged meanwhile.
755
+ * A host adding its own items (drag-and-drop, paste) merges them into its
756
+ * state by `id` the same way (`mergeAttachments` is exported for this).
757
+ */
758
+ attachments?: ChatAttachment[];
759
+ /** Called with the complete next attachment list. See `attachments`. */
760
+ onAttachmentsChange?: (attachments: ChatAttachment[]) => void;
761
+ /** Slot for the model rail (typically `<ModelPicker>` in a trigger). */
762
+ modelRail?: ReactNode;
763
+ /** Extra controls, rendered after the rail. */
764
+ actions?: ReactNode;
765
+ /** Errors from a failed send, surfaced under the input. */
766
+ error?: string | null;
767
+ /** Runtime commands for slash autocomplete. Omit when unsupported. */
768
+ slashCommands?: readonly SlashCommand[] | null;
769
+ slashCommandsLoading?: boolean;
770
+ slashCommandsError?: string | null;
771
+ onRetrySlashCommands?: () => void | Promise<void>;
772
+ className?: string;
773
+ };
774
+ declare function Composer({ onSend, onSteer, onInterrupt, status, ready, disabled, value, onValueChange, placeholder, sendOnEnter, autoFocus, maxRows, onRequestAttachment, attachments, onAttachmentsChange, modelRail, actions, error, slashCommands, slashCommandsLoading, slashCommandsError, onRetrySlashCommands, className, }: ComposerProps): react.JSX.Element;
775
+
776
+ /**
777
+ * One tool name, four spellings.
778
+ *
779
+ * The same MCP tool reaches a host under different names depending on who
780
+ * produced the string: Claude's transcript says `mcp__versic__search`, a
781
+ * permission policy says `mcp:versic:search`, Codex and several ACP dialects
782
+ * say `versic:search`, and a built-in is bare (`Bash`). A host that labels
783
+ * tool chips or matches its own rules had to list every tool three times and
784
+ * keep a private matcher in step with this package. This is that matcher.
785
+ */
786
+ /** A tool name split into the server that owns it and the tool itself. */
787
+ type ToolIdentity = {
788
+ /** The MCP server, or null for a built-in or a name with no server part. */
789
+ server: string | null;
790
+ /** The tool name on that server, or the whole name when there is none. */
791
+ tool: string;
792
+ };
793
+ /**
794
+ * Split a tool name into `{ server, tool }`.
795
+ *
796
+ * Accepts, in this order:
797
+ * - `mcp__<server>__<tool>` — Claude's spelling. The server is the segment
798
+ * up to the next `__`; everything after it is the tool, so a tool whose
799
+ * own name contains `__` survives intact.
800
+ * - `mcp:<server>:<tool>` — the permission-policy spelling. `*` is a valid
801
+ * tool here and is returned as-is.
802
+ * - `<server>:<tool>` — Codex and ACP dialects.
803
+ * - `<tool>` — a built-in. `server` is null.
804
+ *
805
+ * Never throws. Surrounding whitespace is trimmed. A name that starts with
806
+ * an `mcp__` or `mcp:` prefix but has an empty server or tool segment
807
+ * (`mcp__srv`, `mcp:srv`, `srv:`) is returned whole as a bare tool rather than
808
+ * split into an invented server: a half-formed MCP name is not evidence of
809
+ * which server owns it.
810
+ *
811
+ * A verbatim copy of `parseToolIdentity` in `@daex-dev/sdk` (>= 0.3,
812
+ * `packages/sdk/src/toolIdentity.ts`), so the two files diff cleanly. It is a
813
+ * copy, not an import, because the SDK is an optional peer and this runs in a
814
+ * browser; change the two together.
815
+ */
816
+ declare function parseToolIdentity(name: string): ToolIdentity;
817
+
818
+ /**
819
+ * Transcript row collapsing and grouping.
820
+ *
821
+ * PROVENANCE: ported from
822
+ * `apps/desktop/src/renderer/components/chat/chatTranscriptRows.ts` (DAEX
823
+ * desktop renderer). That module is dependency-free by design; this is a
824
+ * trimmed copy carrying over only the row kinds `@daex-dev/chat-ui` renders.
825
+ *
826
+ * Kept from the original, with behaviour intact:
827
+ * - `mergeStreamingText` (prefix-aware streaming append)
828
+ * - `getTextIdentity` / `turnAndItemMatch` / `shouldMergeTextRows`
829
+ * - `buildRenderKey` / `buildTextRenderKey` / `buildCollapseKey`
830
+ * - tool call → tool result upgrade-in-place keyed on `logicalItemId ?? itemId`
831
+ * (the same template drives approval request → decision)
832
+ * - consecutive-reasoning merge (same turn, deduped through
833
+ * `mergeReasoningTextFragments`) and consecutive-status dedupe from
834
+ * `groupConsecutiveWorkLogRows`
835
+ * - `formatStructuredValue`, `eventHasPayload`, `readRecord`
836
+ *
837
+ * Deliberately dropped (DAEX-internal, unsupported here): work-log entries and
838
+ * work-log groups, activity bundles, subagent spawn/result/stopped rows,
839
+ * background job lines, scheduled-wake dividers, plan and todo rows,
840
+ * `ade_card` merging, localhost URL extraction, and diff stats.
841
+ *
842
+ * Incremental building: `TranscriptRowBuilder` holds the collapse state
843
+ * between calls, so a live envelope patches the tail (or the one earlier row it
844
+ * settles) instead of re-collapsing the whole history. `collapseTranscriptEvents`
845
+ * and `buildTranscriptRows` are the same builder run once over a full list.
846
+ */
847
+
848
+ /** A tool call and its eventual result, collapsed into one chip row. */
849
+ type ToolChipRow = {
850
+ type: "tool_chip";
851
+ /** Stable id across the call/result pair. */
852
+ id: string;
853
+ /** The tool name as the provider spelled it (or its payload title). */
854
+ tool: string;
855
+ /**
856
+ * `{ server, tool }` for this call, one shape whatever the provider's
857
+ * spelling (`mcp__srv__x`, `srv:x`, `mcp:srv:x`). Taken from the event's own
858
+ * `mcp` field when the runtime sent one, else parsed from `tool`.
859
+ */
860
+ identity: ToolIdentity;
861
+ args: unknown;
862
+ result?: unknown;
863
+ /**
864
+ * MCP `resource_link` items the tool returned, as data (`{ uri, name?,
865
+ * title?, mimeType? }`). Present only when the runtime passed them on; a host
866
+ * builds "open this" actions from these rather than scraping the result text.
867
+ */
868
+ resourceLinks?: AgentChatResourceLink[];
869
+ status: ToolCallStatus;
870
+ turnId: string | null;
871
+ };
872
+ /**
873
+ * How far an approval has got.
874
+ *
875
+ * `expired` is this package's word for "the turn ended without an answer" — the
876
+ * request can no longer be answered, but the card stays on screen, because a
877
+ * card that vanishes is indistinguishable from one that was never answered.
878
+ *
879
+ * `accepted_always` never comes out of `collapseTranscriptEvents`:
880
+ * `pending_input_resolved` reports only `accepted`, so the runtime cannot tell
881
+ * a one-off allow from a session-wide one. The card remembers which button was
882
+ * pressed and shows the distinction for the reader who pressed it.
883
+ */
884
+ type ApprovalRowState = "pending" | "accepted" | "accepted_always" | "rejected" | "cancelled" | "expired";
885
+ /** An approval request and its eventual decision, collapsed into one card row. */
886
+ type ApprovalRow = {
887
+ type: "approval";
888
+ /** The request's `itemId`. Stable across the request/resolution pair. */
889
+ id: string;
890
+ kind: ApprovalKind;
891
+ requestKind?: string;
892
+ description: string;
893
+ detail?: unknown;
894
+ requestId?: string;
895
+ title?: string | null;
896
+ source?: string;
897
+ questions?: PendingInputQuestion[];
898
+ options?: PendingInputOption[];
899
+ allowsFreeform?: boolean;
900
+ canProceedWithoutAnswer?: boolean;
901
+ providerMetadata?: Record<string, unknown>;
902
+ turnId: string | null;
903
+ state: ApprovalRowState;
904
+ };
905
+ type TranscriptRowEvent = ChatEventUserMessage | ChatEventText | ChatEventReasoning | ChatEventError | ChatEventStatus | ToolChipRow | ApprovalRow;
906
+ type TranscriptRow = {
907
+ key: string;
908
+ timestamp: string;
909
+ event: TranscriptRowEvent;
910
+ };
911
+ declare function eventHasPayload(value: unknown): boolean;
912
+ declare function formatStructuredValue(value: unknown): string;
913
+ /**
914
+ * Providers stream text either as growing snapshots or as deltas. A snapshot
915
+ * that starts with what we already have replaces it; anything else appends.
916
+ */
917
+ declare function mergeStreamingText(existing: string, incoming: string): string;
918
+ /**
919
+ * Two adjacent `text` events belong in one bubble when they carry the same
920
+ * message identity, or (identity-free) the same turn+item, or when neither
921
+ * carries any identity at all.
922
+ */
923
+ declare function shouldMergeTextRows(previous: ChatEventText, next: ChatEventText): boolean;
924
+ /** Prefer a payload-supplied title when the provider only said "tool". */
925
+ declare function resolveToolName(tool: string, payload: unknown): string;
926
+ /**
927
+ * Fold a raw envelope stream into render rows: streaming text merges into one
928
+ * bubble, a `tool_result` upgrades its `tool_call` chip in place, and event
929
+ * kinds this package does not draw are dropped.
930
+ */
931
+ declare function collapseTranscriptEvents(envelopes: readonly AgentChatEventEnvelope[],
932
+ /**
933
+ * Requests the runtime is still blocked on, from `thread.pendingApprovals()`.
934
+ *
935
+ * Passed as data rather than as synthesized `approval_request` envelopes. A
936
+ * reload drops the live events that carried the originals, and `history()`
937
+ * may not reach back far enough to replay them — without these a blocked
938
+ * thread comes back looking merely silent, with nothing on screen able to
939
+ * unblock it. Any request already drawn from the envelope stream is skipped,
940
+ * so a replayed one is never drawn twice.
941
+ */
942
+ pendingApprovals?: readonly ApprovalRequest[],
943
+ /**
944
+ * When `pendingApprovals` was read, as an ISO timestamp.
945
+ *
946
+ * The restored rows sort into the transcript at this instant instead of being
947
+ * appended, so a message that streams in afterwards renders BELOW them. The
948
+ * caller captures it once, when it restores, and passes the same value on
949
+ * every rebuild — deriving it per rebuild would walk the card down the
950
+ * transcript as new envelopes arrive. Omitted, the rows land at the tail as
951
+ * they did before.
952
+ */
953
+ restoredAt?: string): TranscriptRow[];
954
+ /**
955
+ * Second pass: merge consecutive reasoning from the same turn into one
956
+ * collapsible row and drop repeated identical status rows.
957
+ */
958
+ declare function groupTranscriptRows(rows: readonly TranscriptRow[]): TranscriptRow[];
959
+ /** Collapse then group, in the order the renderer needs. */
960
+ declare function buildTranscriptRows(envelopes: readonly AgentChatEventEnvelope[], pendingApprovals?: readonly ApprovalRequest[], restoredAt?: string): TranscriptRow[];
961
+ /**
962
+ * `buildTranscriptRows`, incrementally.
963
+ *
964
+ * Feed it the history once, then each live envelope as it lands: an append
965
+ * re-collapses nothing and re-groups only from the group that holds the lowest
966
+ * row it changed — the tail, for a streamed delta or a new message; an earlier
967
+ * chip, for a tool result; an earlier card, for an approval decision. `rows`
968
+ * is a new array after any change and the SAME array otherwise, and rows that
969
+ * did not change keep their object identity, so a memoised row view skips them.
970
+ *
971
+ * Equivalent to `buildTranscriptRows` over the same envelopes with one caveat,
972
+ * both for restored approvals only: a live `approval_request` for a restored
973
+ * card settles it where it was restored (a single pass would draw it at the
974
+ * envelope's position), and a live envelope stamped earlier than `restoredAt`
975
+ * lands below the restored card. Prepending older history is not an append:
976
+ * start a new builder over the full list for that.
977
+ */
978
+ declare class TranscriptRowBuilder {
979
+ private readonly collapser;
980
+ private readonly grouped;
981
+ private readonly starts;
982
+ private snapshot;
983
+ /** The grouped rows, as a stable array until the next change. */
984
+ get rows(): TranscriptRow[];
985
+ /** Fold envelopes onto the end. Returns `rows`. */
986
+ append(envelopes: readonly AgentChatEventEnvelope[]): TranscriptRow[];
987
+ /**
988
+ * Add the approvals the runtime is still blocked on (see
989
+ * `collapseTranscriptEvents`). Call once, after the history append.
990
+ */
991
+ restore(pendingApprovals: readonly ApprovalRequest[], restoredAt?: string): TranscriptRow[];
992
+ private flush;
993
+ }
994
+
995
+ /**
996
+ * Activity labels: how a raw agent event is named for an end user.
997
+ *
998
+ * The host embedding this chat does not want "Bash(rg -n invoice)" in front of
999
+ * its customers. It wants "Searching your invoices…". This module turns an
1000
+ * event into that string, entirely from configuration.
1001
+ *
1002
+ * Resolution order for a given key (first hit wins):
1003
+ * 1. `resolve(event)` — full escape hatch, may return null to fall through
1004
+ * 2. exact `map` entry e.g. "server.tool"
1005
+ * 3. longest matching wildcard e.g. "server.*" then "*"
1006
+ * 4. `null` — the caller falls back to the raw tool name
1007
+ *
1008
+ * MCP tool keys are matched on the tool's identity, not its spelling (see
1009
+ * `matchLabelKey`): `mcp:versic:*`, `versic:search`, `mcp__versic__search` and
1010
+ * a bare `search` all reach a Claude `mcp__versic__search` and a Codex
1011
+ * `versic:search` alike. A tool reported by its bare name (`search`) with an
1012
+ * MCP source naming `versic` is matched as `versic`'s tool too.
1013
+ */
1014
+
1015
+ /** The phase a label is being rendered for. */
1016
+ type ActivityPhase = "running" | "done" | "error";
1017
+ /**
1018
+ * A map entry is either one string (used for the running phase only — done and
1019
+ * error fall back to the raw name) or an explicit per-phase set.
1020
+ */
1021
+ type ActivityLabelEntry = string | {
1022
+ running?: string;
1023
+ done?: string;
1024
+ error?: string;
1025
+ };
1026
+ type ActivityLabelSource = {
1027
+ kind: "tool";
1028
+ tool: string;
1029
+ phase: ActivityPhase;
1030
+ event: ToolChipRow;
1031
+ } | {
1032
+ kind: "error";
1033
+ tool: null;
1034
+ phase: "error";
1035
+ event: Extract<AgentChatEvent, {
1036
+ type: "error";
1037
+ }>;
1038
+ } | {
1039
+ kind: "thinking";
1040
+ tool: null;
1041
+ phase: "running";
1042
+ event: null;
1043
+ };
1044
+ type ActivityLabelConfig = {
1045
+ /**
1046
+ * Keyed by tool name. Supports trailing `*` wildcards and a bare `"*"`.
1047
+ *
1048
+ * MCP tools may be keyed in any spelling — the policy form `mcp:srv:tool` /
1049
+ * `mcp:srv:*`, Claude's `mcp__srv__tool`, Codex's `srv:tool`, or the bare
1050
+ * `tool` — and one key matches the tool under every provider. A
1051
+ * server-qualified key beats a bare one for the same tool.
1052
+ *
1053
+ * A server-qualified key matches a tool the provider reported by its bare
1054
+ * name only when the event carries an MCP source naming that server
1055
+ * (`tool_call.mcp.server`, surfaced as `ToolChipRow.identity`). A bare name
1056
+ * with no MCP source has no server, so only a bare key (`tool`, `tool*`)
1057
+ * matches it — and that happens whenever a provider's event does not name
1058
+ * the server for a tool your host injected. The matcher does not guess a
1059
+ * server from the name: a bare name is not evidence of who owns it.
1060
+ *
1061
+ * A bare key is compared with the tool's OWN name, so the bare key to write is
1062
+ * the name your providers report. A host whose injected tools carry a family
1063
+ * prefix needs one wildcard, not one entry per tool:
1064
+ * `{ "versic_*": "Checking your projects…" }` matches a tool reported bare as
1065
+ * `versic_projects`, and also `mcp__versic__versic_projects` (the tool name
1066
+ * there is `versic_projects`). It does NOT match a tool reported as a bare
1067
+ * `search` that belongs to the `versic` server, because that name starts with
1068
+ * `search`, not `versic_` — only `*`, or an exact `search` key, matches that.
1069
+ */
1070
+ map?: Record<string, ActivityLabelEntry>;
1071
+ /** Runs before `map`. Return null to fall through to the map. */
1072
+ resolve?: (source: ActivityLabelSource) => string | null;
1073
+ /** Keyed the same way as `map`, including wildcards. */
1074
+ icons?: Record<string, unknown>;
1075
+ /** Shown while a turn is running and no tool is active. */
1076
+ thinkingLabel?: string;
1077
+ /**
1078
+ * Elapsed-time suffix appears once a phase has been running this long.
1079
+ * Locked default: 3s.
1080
+ */
1081
+ elapsedAfterMs?: number;
1082
+ };
1083
+ declare const DEFAULT_ELAPSED_AFTER_MS = 3000;
1084
+ declare const DEFAULT_THINKING_LABEL = "Working\u2026";
1085
+ /**
1086
+ * The best map key for a tool name, or null.
1087
+ *
1088
+ * Specificity, highest first:
1089
+ * 1. the key spelled exactly like the candidate
1090
+ * 2. a server-qualified key for the same server and tool, in any spelling
1091
+ * (`mcp:srv:tool`, `mcp__srv__tool`, `srv:tool`)
1092
+ * 3. a bare key equal to the tool name without its server (`tool`)
1093
+ * 4. wildcards — server-qualified (`mcp:srv:*`) before bare, then the longest
1094
+ * prefix; a bare `"*"` last. On a tie the later key wins.
1095
+ *
1096
+ * This is the one matcher: labels, icons and hosts' own lookups all use it, so
1097
+ * a tool never has to be listed once per provider spelling.
1098
+ *
1099
+ * `identity` is the tool's known `{ server, tool }` when the event says which
1100
+ * MCP server ran it (`ToolChipRow.identity`, from the event's `mcp` source).
1101
+ * Pass it: some providers report an MCP tool by its bare name (`search`), and
1102
+ * only the event's MCP source tells the matcher that a server-qualified key
1103
+ * (`mcp:srv:search`, `mcp:srv:*`) applies. Without it the identity is parsed
1104
+ * from `candidate`, so a bare name has no server and matches only bare keys.
1105
+ */
1106
+ declare function matchLabelKey(keys: readonly string[], candidate: string, identity?: ToolIdentity): string | null;
1107
+ /** Resolve the display label for one activity source. Null means "no override". */
1108
+ declare function resolveActivityLabel(source: ActivityLabelSource, config: ActivityLabelConfig | undefined): string | null;
1109
+ /** Resolve a configured icon for a tool key, honouring the same wildcards. */
1110
+ declare function resolveActivityIcon(tool: string | null, config: ActivityLabelConfig | undefined, identity?: ToolIdentity): unknown;
1111
+ /** Map a chip's status onto the phase its label should use. */
1112
+ declare function phaseForToolStatus(status: ToolChipRow["status"]): ActivityPhase;
1113
+ /**
1114
+ * Elapsed suffix. Under the threshold this returns null so short activities
1115
+ * never flash a timer. Seconds under a minute, then `m s`.
1116
+ */
1117
+ declare function formatElapsed(elapsedMs: number, elapsedAfterMs?: number): string | null;
1118
+ /**
1119
+ * Full label for a tool chip, including the elapsed suffix when it applies.
1120
+ * `fallback` is used when nothing in the config matches — normally the raw
1121
+ * tool name.
1122
+ */
1123
+ declare function describeToolActivity(input: {
1124
+ chip: ToolChipRow;
1125
+ config?: ActivityLabelConfig;
1126
+ elapsedMs?: number;
1127
+ }): {
1128
+ label: string;
1129
+ elapsed: string | null;
1130
+ icon: unknown;
1131
+ };
1132
+
1133
+ type DaexChatContextValue = {
1134
+ client: DaexChatClient | null;
1135
+ labels?: ActivityLabelConfig;
1136
+ };
1137
+ type DaexChatProviderProps = {
1138
+ client: DaexChatClient;
1139
+ /** Activity label configuration shared by transcript, chips and indicator. */
1140
+ labels?: ActivityLabelConfig;
1141
+ children: ReactNode;
1142
+ };
1143
+ declare function DaexChatProvider({ client, labels, children }: DaexChatProviderProps): react.JSX.Element;
1144
+ declare function useDaexChatContext(): DaexChatContextValue;
1145
+ /** The client from context, or the one passed explicitly. Throws if neither. */
1146
+ declare function useDaexChatClient(explicit?: DaexChatClient): DaexChatClient;
1147
+ type ProvidersState = {
1148
+ statuses: ProviderStatus[];
1149
+ models: ModelDescriptor[];
1150
+ loading: boolean;
1151
+ error: Error | null;
1152
+ refresh: () => void;
1153
+ };
1154
+ /**
1155
+ * Provider statuses and the model catalog, kept live via
1156
+ * `client.providers.onChange`.
1157
+ */
1158
+ declare function useDaexProviders(explicitClient?: DaexChatClient): ProvidersState;
1159
+ type ThreadState = {
1160
+ thread: DaexThread | null;
1161
+ ready: boolean;
1162
+ rows: TranscriptRow[];
1163
+ status: ThreadStatus;
1164
+ usage: ThreadUsage | null;
1165
+ error: Error | null;
1166
+ send: (input: SendInput | string) => Promise<void>;
1167
+ steer: (input: SendInput | string) => Promise<void>;
1168
+ interrupt: () => Promise<void>;
1169
+ /** Switch the open thread's model in place. No-op when already bound to it. */
1170
+ setModel: (modelId: string) => Promise<void>;
1171
+ /**
1172
+ * Change the open thread's title, reasoning effort or fast mode. Rejects
1173
+ * with the thread's own error (a reasoning change mid-turn is refused with
1174
+ * code `turn_in_flight`). No-op on a thread without `update`; check
1175
+ * `canUpdate`.
1176
+ */
1177
+ update: (patch: ThreadUpdatePatch) => Promise<void>;
1178
+ /**
1179
+ * Run the last user message again, or with new text (`editLast`). The
1180
+ * transcript reloads when the runtime reports the old turn removed, so the
1181
+ * message shows once. Rejects with the thread's error (`turn_in_flight`,
1182
+ * `unsupported`). No-op on a thread without them; check `canRetry`.
1183
+ */
1184
+ retry: () => Promise<void>;
1185
+ editLast: (input: SendInput | string) => Promise<void>;
1186
+ /** Answer an approval. No-op on a thread that cannot answer them. */
1187
+ approve: (itemId: string, decision: ApprovalDecision, responseText?: string) => Promise<void>;
1188
+ /** Outstanding approvals, or `[]` on a thread that cannot report them. */
1189
+ pendingApprovals: () => Promise<readonly ApprovalRequest[]>;
1190
+ /**
1191
+ * Whether the open thread can switch models at all. False for a client whose
1192
+ * thread predates `setModel`, so a host can disable its picker with a reason
1193
+ * instead of accepting a click that would do nothing.
1194
+ */
1195
+ canSetModel: boolean;
1196
+ /**
1197
+ * Whether the open thread can answer approvals at all. False for a client
1198
+ * whose thread predates `approve`, so the card renders read-only with a
1199
+ * reason instead of offering a button whose click would throw.
1200
+ */
1201
+ canApprove: boolean;
1202
+ /** Whether the open thread has `update` (an SDK >= 0.3 thread does). */
1203
+ canUpdate: boolean;
1204
+ /** Whether the open thread has `retry` and `editLast` (an SDK >= 0.4 thread does). */
1205
+ canRetry: boolean;
1206
+ /** Answer pending questions and plan approvals when `thread.respond` exists. */
1207
+ respond: (requestId: string, response: PendingInputResponse) => Promise<void>;
1208
+ canRespond: boolean;
1209
+ /** Slash commands; null means not yet loaded, undefined means unsupported. */
1210
+ slashCommands: readonly SlashCommand[] | null | undefined;
1211
+ slashCommandsLoading: boolean;
1212
+ slashCommandsError: string | null;
1213
+ reloadSlashCommands: () => Promise<void>;
1214
+ /**
1215
+ * The model the runtime has the thread on, as it resolved it — which can be
1216
+ * a successor of the id the host asked for. Read on open and after every
1217
+ * successful `setModel`. Null when the client does not report one (an SDK
1218
+ * before 0.3, a proxy), and a UI then names the model from its catalog.
1219
+ */
1220
+ model: ThreadModelSelection | null;
1221
+ /**
1222
+ * Older history exists that is not loaded yet. Only ever true on a client
1223
+ * with `historyPage`; a client that reads history in one `history()` call has
1224
+ * nothing further to page.
1225
+ */
1226
+ hasOlder: boolean;
1227
+ /** A `loadOlder()` read is in flight. */
1228
+ loadingOlder: boolean;
1229
+ /**
1230
+ * Load the next older history page and fold it in above the current rows.
1231
+ * A no-op when `hasOlder` is false or a load is already running. A failed
1232
+ * read leaves `hasOlder` true so the caller can retry; it never throws.
1233
+ */
1234
+ loadOlder: () => Promise<void>;
1235
+ };
1236
+ /** Envelopes read per `historyPage` call when the host does not say. */
1237
+ declare const DEFAULT_HISTORY_PAGE_SIZE = 200;
1238
+ /**
1239
+ * Open a thread and keep its transcript current.
1240
+ *
1241
+ * History is loaded on open — the newest page when the thread has
1242
+ * `historyPage`, else the whole `history()` window — and older pages load on
1243
+ * `loadOlder()`. Live events append through a `TranscriptRowBuilder`, so each
1244
+ * one patches the tail rather than rebuilding every row; the collapse rules
1245
+ * (streaming text merge, tool call→result upgrade) are the same code for
1246
+ * replayed and live events. Loading an older page rebuilds once.
1247
+ *
1248
+ * After the client reports a successful runtime restart (`client.on("restart")`
1249
+ * with `ok: true`), the thread is re-opened and its history re-read. The old
1250
+ * rows stay on screen until the new history replaces them.
1251
+ */
1252
+ declare function useDaexThread(key: string, options?: ThreadOpenOptions & {
1253
+ client?: DaexChatClient;
1254
+ /**
1255
+ * Hold the thread closed while this is false.
1256
+ *
1257
+ * A host that has not resolved its model yet would otherwise open with no
1258
+ * `modelId`, which a real SDK client rejects — and the user reads the
1259
+ * resulting developer-facing error before the chat has done anything.
1260
+ * Defaults to true.
1261
+ */
1262
+ enabled?: boolean;
1263
+ /**
1264
+ * Envelopes per `historyPage` read (the first page and each older one).
1265
+ * Ignored by a client without `historyPage`. Default
1266
+ * `DEFAULT_HISTORY_PAGE_SIZE`. A streamed reply is many envelopes, so a
1267
+ * page holds fewer messages than this number suggests.
1268
+ */
1269
+ historyPageSize?: number;
1270
+ }): ThreadState;
1271
+ /** @deprecated Use {@link DaexChatContextValue}. */
1272
+ type AdeChatContextValue = DaexChatContextValue;
1273
+ /** @deprecated Use {@link DaexChatProvider}. */
1274
+ declare const AdeChatProvider: typeof DaexChatProvider;
1275
+ /** @deprecated Use {@link DaexChatProviderProps}. */
1276
+ type AdeChatProviderProps = DaexChatProviderProps;
1277
+ /** @deprecated Use {@link useDaexChatClient}. */
1278
+ declare const useAdeChatClient: typeof useDaexChatClient;
1279
+ /** @deprecated Use {@link useDaexChatContext}. */
1280
+ declare const useAdeChatContext: typeof useDaexChatContext;
1281
+ /** @deprecated Use {@link useDaexProviders}. */
1282
+ declare const useAdeProviders: typeof useDaexProviders;
1283
+ /** @deprecated Use {@link useDaexThread}. */
1284
+ declare const useAdeThread: typeof useDaexThread;
1285
+
1286
+ type ModelPickerProps = {
1287
+ /** Selected model id. */
1288
+ value?: string | null;
1289
+ onChange: (model: ModelDescriptor) => void;
1290
+ /** Supply data directly; omit to read from the client/context. */
1291
+ models?: readonly ModelDescriptor[];
1292
+ providers?: readonly ProviderStatus[];
1293
+ /** Used only when `models`/`providers` are omitted. */
1294
+ client?: DaexChatClient;
1295
+ /** Hide the search field. */
1296
+ searchable?: boolean;
1297
+ /** Rendered under a provider group that cannot be selected from. */
1298
+ renderProviderNotice?: (status: ProviderStatus | null, providerId: string) => React.ReactNode;
1299
+ /**
1300
+ * The selected reasoning effort for the selected model. Null or omitted
1301
+ * shows the model's `defaultReasoningEffort` as selected.
1302
+ */
1303
+ reasoningEffort?: string | null;
1304
+ /**
1305
+ * Called when the person picks an effort level. The control is drawn only
1306
+ * when this is set AND the selected model (`value`) lists
1307
+ * `reasoningEfforts`; a model without them shows no control. The picker does
1308
+ * not apply the effort anywhere — the host sends it to its thread.
1309
+ */
1310
+ onReasoningEffortChange?: (effort: string, model: ModelDescriptor) => void;
1311
+ className?: string;
1312
+ };
1313
+ declare function ModelPicker(props: ModelPickerProps): react.JSX.Element;
1314
+
1315
+ /**
1316
+ * Theming is CSS custom properties and nothing else. No Tailwind, no class
1317
+ * names to override, no runtime style objects to thread through props: the
1318
+ * host sets `--adechat-*` on any ancestor and every component follows.
1319
+ *
1320
+ * `createTheme` exists so a host only has to pick an accent and a background;
1321
+ * hovers, borders and subtle tints are derived from those.
1322
+ */
1323
+ /** Every token this package reads. Nothing else is styleable. */
1324
+ declare const DAEX_CHAT_TOKENS: readonly ["--adechat-root-bg", "--adechat-bg", "--adechat-bg-subtle", "--adechat-bg-raised", "--adechat-fg", "--adechat-muted", "--adechat-accent", "--adechat-accent-fg", "--adechat-accent-subtle", "--adechat-border", "--adechat-border-strong", "--adechat-hover", "--adechat-danger", "--adechat-danger-subtle", "--adechat-success", "--adechat-radius", "--adechat-radius-sm", "--adechat-font", "--adechat-font-mono", "--adechat-font-size", "--adechat-space"];
1325
+ type DaexChatToken = (typeof DAEX_CHAT_TOKENS)[number];
1326
+ type DaexChatTheme = Record<DaexChatToken, string>;
1327
+ type CreateThemeInput = {
1328
+ /** Any CSS color. Hex (3/6/8 digit) unlocks derived tints. */
1329
+ accent?: string;
1330
+ /**
1331
+ * The chat's background. Any CSS color, or `"transparent"` to let the host
1332
+ * surface show through the root and the composer bar.
1333
+ *
1334
+ * With `"transparent"`, `--adechat-root-bg` is `transparent` and
1335
+ * `--adechat-bg` (inset surfaces, and the base the subtle/raised tints are
1336
+ * derived from) falls back to the scheme default. Nothing can be inferred
1337
+ * from a transparent background, so pass `scheme` to match the host; it
1338
+ * defaults to `"dark"`.
1339
+ */
1340
+ background?: string;
1341
+ foreground?: string;
1342
+ muted?: string;
1343
+ danger?: string;
1344
+ success?: string;
1345
+ /** Number is treated as px. */
1346
+ radius?: string | number;
1347
+ fontFamily?: string;
1348
+ monoFontFamily?: string;
1349
+ fontSize?: string | number;
1350
+ /** Base spacing unit. */
1351
+ space?: string | number;
1352
+ /**
1353
+ * Drives whether derived surfaces lighten or darken. Inferred from
1354
+ * `background` when it is a hex color.
1355
+ */
1356
+ scheme?: "light" | "dark";
1357
+ };
1358
+ /**
1359
+ * Build the full token set from a handful of inputs. Every token is always
1360
+ * present, so the result can be spread straight onto a `style` prop.
1361
+ */
1362
+ declare function createTheme(input?: CreateThemeInput): DaexChatTheme;
1363
+ /** The dark default, useful as a baseline to spread and override. */
1364
+ declare const defaultTheme: DaexChatTheme;
1365
+ /** Serialize a theme for a `<style>` block or a stylesheet string. */
1366
+ declare function themeToCss(theme: DaexChatTheme, selector?: string): string;
1367
+ /** @deprecated Use {@link DAEX_CHAT_TOKENS}. */
1368
+ declare const ADE_CHAT_TOKENS: readonly ["--adechat-root-bg", "--adechat-bg", "--adechat-bg-subtle", "--adechat-bg-raised", "--adechat-fg", "--adechat-muted", "--adechat-accent", "--adechat-accent-fg", "--adechat-accent-subtle", "--adechat-border", "--adechat-border-strong", "--adechat-hover", "--adechat-danger", "--adechat-danger-subtle", "--adechat-success", "--adechat-radius", "--adechat-radius-sm", "--adechat-font", "--adechat-font-mono", "--adechat-font-size", "--adechat-space"];
1369
+ /** @deprecated Use {@link DaexChatTheme}. */
1370
+ type AdeChatTheme = DaexChatTheme;
1371
+ /** @deprecated Use {@link DaexChatToken}. */
1372
+ type AdeChatToken = DaexChatToken;
1373
+
1374
+ /** Button and title wording, so a host can speak its own product's language. */
1375
+ type ApprovalLabels = {
1376
+ title?: (request: ApprovalRequest) => string;
1377
+ accept?: string;
1378
+ acceptAlways?: string;
1379
+ reject?: string;
1380
+ };
1381
+ type ApprovalUiOptions = {
1382
+ /** Replace the built-in card entirely. Omit to use it. */
1383
+ render?: (request: ApprovalRequest, respond: (decision: ApprovalDecision) => void) => ReactNode;
1384
+ labels?: ApprovalLabels;
1385
+ };
1386
+ type ApprovalRespond = (itemId: string, decision: ApprovalDecision) => void | Promise<void>;
1387
+ type ApprovalCardProps = {
1388
+ row: ApprovalRow;
1389
+ /**
1390
+ * Omit when the thread has no `approve`. The card then renders read-only with
1391
+ * a line saying why, rather than offering a button that would throw.
1392
+ */
1393
+ onApprove?: ApprovalRespond;
1394
+ options?: ApprovalUiOptions;
1395
+ };
1396
+ declare const NO_APPROVE_NOTICE = "This host cannot answer approvals.";
1397
+ declare const UNANSWERABLE_NOTICE = "The assistant is waiting for an answer this UI cannot provide.";
1398
+ /** The row, back in the shape a host's own `render` and `labels` receive. */
1399
+ declare function approvalRequestFromRow(row: ApprovalRow): ApprovalRequest;
1400
+ /**
1401
+ * The command a `kind: "command"` request is asking about.
1402
+ *
1403
+ * Providers disagree on where it sits: some put it at the top of `detail`,
1404
+ * others nest it under the tool input. Both are read, and a request whose
1405
+ * payload has neither simply shows its description.
1406
+ */
1407
+ declare function readApprovalCommand(detail: unknown): string | null;
1408
+ /** The path a `kind: "file_change"` request is asking about, and its root. */
1409
+ declare function readApprovalPaths(detail: unknown): {
1410
+ path?: string;
1411
+ grantRoot?: string;
1412
+ };
1413
+ declare function ApprovalCard({ row, onApprove, options }: ApprovalCardProps): react.JSX.Element;
1414
+
1415
+ type PendingInputRespond = (requestId: string, response: PendingInputResponse) => void | Promise<void>;
1416
+ type PendingInputCardProps = {
1417
+ row: ApprovalRow;
1418
+ onRespond?: PendingInputRespond;
1419
+ };
1420
+ declare function PendingInputCard({ row, onRespond }: PendingInputCardProps): react.JSX.Element;
1421
+
1422
+ /** Where a link was drawn. */
1423
+ type DaexLinkSource =
1424
+ /** A link in rendered assistant markdown (model-written text). */
1425
+ "markdown"
1426
+ /** The "Documentation" link on a provider card (`ProviderStatus.docsUrl`). */
1427
+ | "provider-docs";
1428
+ type DaexLinkClickInfo = {
1429
+ source: DaexLinkSource;
1430
+ /** The visible link text. For a bare URL it equals `href`. */
1431
+ text: string;
1432
+ };
1433
+ /**
1434
+ * Called instead of the browser default when the person activates a link.
1435
+ * chat-ui has already called `preventDefault()`: nothing opens unless the
1436
+ * handler opens it. `href` has passed `safeHref` (http, https, mailto, tel,
1437
+ * `#`, or a relative path) and is never `javascript:` or `data:`.
1438
+ */
1439
+ type DaexLinkClickHandler = (href: string, info: DaexLinkClickInfo) => void;
1440
+ /** Supplies `onLinkClick` to every `<DaexLink>` below it. */
1441
+ declare function DaexLinkHandlerProvider({ onLinkClick, children, }: {
1442
+ onLinkClick: DaexLinkClickHandler | undefined;
1443
+ children: ReactNode;
1444
+ }): react.JSX.Element;
1445
+ declare function DaexLink({ href, source, className, children, }: {
1446
+ href: string;
1447
+ source: DaexLinkSource;
1448
+ className?: string;
1449
+ children: ReactNode;
1450
+ }): react.JSX.Element;
1451
+ /** @deprecated Use {@link DaexLink}. */
1452
+ declare const AdeLink: typeof DaexLink;
1453
+ /** @deprecated Use {@link DaexLinkClickHandler}. */
1454
+ type AdeLinkClickHandler = DaexLinkClickHandler;
1455
+ /** @deprecated Use {@link DaexLinkClickInfo}. */
1456
+ type AdeLinkClickInfo = DaexLinkClickInfo;
1457
+ /** @deprecated Use {@link DaexLinkHandlerProvider}. */
1458
+ declare const AdeLinkHandlerProvider: typeof DaexLinkHandlerProvider;
1459
+ /** @deprecated Use {@link DaexLinkSource}. */
1460
+ type AdeLinkSource = DaexLinkSource;
1461
+
1462
+ /** One host action drawn on a tool chip (e.g. "Open in Versic"). */
1463
+ type ToolChipAction = {
1464
+ /** Button text. Also the React key, so keep labels unique per chip. */
1465
+ label: string;
1466
+ onSelect: () => void;
1467
+ };
1468
+ type ToolChipProps = {
1469
+ chip: ToolChipRow;
1470
+ /**
1471
+ * Buttons drawn under the chip's head, always visible (not inside the
1472
+ * collapsible body). Empty or omitted draws nothing.
1473
+ */
1474
+ actions?: readonly ToolChipAction[];
1475
+ labels?: ActivityLabelConfig;
1476
+ /** When the call started, for the elapsed suffix. */
1477
+ startedAt?: number | undefined;
1478
+ /** Force the expanded state; omit for uncontrolled. */
1479
+ expanded?: boolean;
1480
+ onToggle?: (expanded: boolean) => void;
1481
+ };
1482
+ declare function ToolChip({ chip, labels, startedAt, expanded, onToggle, actions }: ToolChipProps): react.JSX.Element;
1483
+
1484
+ type TranscriptProps = {
1485
+ rows: readonly TranscriptRow[];
1486
+ /** Drives the inline live activity indicator at the tail. */
1487
+ status?: ThreadStatus["state"];
1488
+ labels?: ActivityLabelConfig;
1489
+ /** Hide tool chips entirely. Reasoning and text are unaffected. */
1490
+ hideToolCalls?: boolean;
1491
+ /** Hide reasoning rows entirely. */
1492
+ hideReasoning?: boolean;
1493
+ /** Reasoning starts collapsed; set true to start open. */
1494
+ expandReasoning?: boolean;
1495
+ /** Replace the built-in markdown renderer. */
1496
+ renderMarkdown?: (text: string) => ReactNode;
1497
+ /**
1498
+ * Decide what a link in assistant text does (see `DaexLinkClickHandler`).
1499
+ * Without it a link opens with `target="_blank"`. In Electron that is a new,
1500
+ * chrome-less app window showing a URL a model wrote, so an Electron host
1501
+ * should pass this and open allowed URLs with `shell.openExternal`. A custom
1502
+ * `renderMarkdown` draws its own links; this applies only to the built-in
1503
+ * renderer (and to anything that renders `<DaexLink>`).
1504
+ */
1505
+ onLinkClick?: DaexLinkClickHandler;
1506
+ /**
1507
+ * Answer an approval. Omit when the thread has no `approve`: approval cards
1508
+ * then render read-only with a line saying why.
1509
+ */
1510
+ onApprove?: ApprovalRespond;
1511
+ /** Answer structured questions and plan approvals; omitted clients render read-only cards. */
1512
+ onRespond?: PendingInputRespond;
1513
+ /** Custom approval card renderer and button wording. */
1514
+ approvals?: ApprovalUiOptions;
1515
+ /**
1516
+ * Extra content drawn under a tool chip — a preview, a result card, links
1517
+ * built from `row.resourceLinks`. Called for every tool chip row, running
1518
+ * ones included (check `row.status`); return null to draw nothing. Pure
1519
+ * rendering: it runs on every render of that row.
1520
+ */
1521
+ renderToolResult?: (row: ToolChipRow) => ReactNode;
1522
+ /**
1523
+ * Buttons on a tool chip (e.g. "Open in Versic" from `row.resourceLinks` or
1524
+ * `row.identity`). Called for every tool chip row; return `[]` for none.
1525
+ * Labels must be unique within one chip.
1526
+ */
1527
+ toolChipActions?: (row: ToolChipRow) => readonly ToolChipAction[];
1528
+ /** Older history exists (see `ThreadState.hasOlder`). Shows the load control. */
1529
+ hasOlder?: boolean;
1530
+ /** An older page is loading; the control is disabled meanwhile. */
1531
+ loadingOlder?: boolean;
1532
+ /**
1533
+ * Load the next older page. Called from the top control and when the reader
1534
+ * scrolls to the top while `hasOlder` is true and nothing is loading.
1535
+ */
1536
+ onLoadOlder?: () => void | Promise<void>;
1537
+ /**
1538
+ * Row count above which only the rows in view (plus `overscan`) are mounted.
1539
+ * Default 150. `Infinity` turns windowing off. A row scrolled out of the
1540
+ * window unmounts, so its local UI state (an expanded reasoning block or
1541
+ * tool chip) resets when it scrolls back in.
1542
+ */
1543
+ windowThreshold?: number;
1544
+ /** Rows mounted beyond each edge of the viewport when windowed. Default 8. */
1545
+ overscan?: number;
1546
+ /** Shown when there are no rows. */
1547
+ emptyState?: ReactNode;
1548
+ className?: string;
1549
+ };
1550
+ /**
1551
+ * Replaces the thinking label while an approval sits unanswered at the tail.
1552
+ *
1553
+ * "Working…" under a card that is waiting on the reader is a lie, and the
1554
+ * reason a blocked turn reads as a hung one.
1555
+ */
1556
+ declare const DEFAULT_APPROVAL_WAITING_LABEL = "Waiting for your approval\u2026";
1557
+ declare function Transcript({ rows, status, labels, hideToolCalls, hideReasoning, expandReasoning, renderMarkdown, onLinkClick, onApprove, onRespond, approvals, renderToolResult, toolChipActions, hasOlder, loadingOlder, onLoadOlder, windowThreshold, overscan, emptyState, className, }: TranscriptProps): react.JSX.Element;
1558
+ /** Inline "the agent is working" line, shown at the tail of a running turn. */
1559
+ declare function ActivityIndicator({ labels, label: labelOverride, }: {
1560
+ labels?: ActivityLabelConfig | undefined;
1561
+ /** Replaces the resolved label outright (the approval wait uses this). */
1562
+ label?: string | undefined;
1563
+ }): react.JSX.Element;
1564
+ declare function usePrefersReducedMotion(): boolean;
1565
+
1566
+ /** What `DaexChatProps.onSend` may return. See `onSend`. */
1567
+ type DaexChatSendResult = void | boolean | "handled";
1568
+ type DaexChatProps = {
1569
+ client: DaexChatClient;
1570
+ /** Thread key. Changing it opens a different conversation. */
1571
+ threadKey: string;
1572
+ /** Uncontrolled initial selection; pass `modelId` to control it. */
1573
+ defaultModelId?: string;
1574
+ modelId?: string;
1575
+ onModelChange?: (model: ModelDescriptor) => void;
1576
+ labels?: ActivityLabelConfig;
1577
+ /** Token overrides, typically from `createTheme()`. */
1578
+ theme?: Partial<DaexChatTheme>;
1579
+ /** Skip the injected stylesheet if the host bundles its own copy. */
1580
+ disableStyles?: boolean;
1581
+ placeholder?: ComposerProps["placeholder"];
1582
+ sendOnEnter?: ComposerProps["sendOnEnter"];
1583
+ /**
1584
+ * Controlled draft text, passed to the internal `<Composer>`. Pass with
1585
+ * `onValueChange` to fill the composer from outside (prompt cards, a
1586
+ * "retry with edits" flow). Omit both to let the composer own the draft.
1587
+ */
1588
+ value?: ComposerProps["value"];
1589
+ /** Called with the next draft text. See `value`. */
1590
+ onValueChange?: ComposerProps["onValueChange"];
1591
+ /**
1592
+ * Called when the person sends a new message, before it reaches the thread.
1593
+ * What it returns (or resolves) decides what happens next:
1594
+ * - `false` cancels: nothing is sent, and the composer keeps the draft and
1595
+ * the staged attachments (a confirmation or a validation step);
1596
+ * - `"handled"` means the host sent the message itself (for example with
1597
+ * `thread.send` and other text): nothing more is sent, and the composer
1598
+ * stays cleared;
1599
+ * - anything else sends the message as usual.
1600
+ * A throw is shown under the composer as a failed send, and the draft is
1601
+ * restored. Steering a running turn does not call this. `thread` is the
1602
+ * live thread state (see `children`).
1603
+ */
1604
+ onSend?: (input: SendInput, thread: ThreadState) => DaexChatSendResult | Promise<DaexChatSendResult>;
1605
+ /**
1606
+ * Render prop drawn between the transcript and the composer, with the live
1607
+ * thread state: rows, status, `send`, `update`, the resolved model. Use it
1608
+ * for prompt cards, a retry bar, or a status line. Return null to draw
1609
+ * nothing there.
1610
+ */
1611
+ children?: (thread: ThreadState) => ReactNode;
1612
+ /**
1613
+ * Receives the live thread state on every render (null before mount and
1614
+ * after unmount), for host code outside the render tree: a toolbar "Retry"
1615
+ * button, a title set after the first reply.
1616
+ */
1617
+ threadRef?: {
1618
+ current: ThreadState | null;
1619
+ };
1620
+ onRequestAttachment?: ComposerProps["onRequestAttachment"];
1621
+ /**
1622
+ * Controlled staged attachments, passed straight to the internal
1623
+ * `<Composer>`. Pass with `onAttachmentsChange` to stage files from outside
1624
+ * the picker (drag-and-drop, paste). Follow the Composer's merge rule:
1625
+ * `onAttachmentsChange` gets the COMPLETE next list — replace your state with
1626
+ * it, never append — and items are keyed by `id` (see
1627
+ * `ComposerProps["attachments"]`). Omit both to let the composer own the list.
1628
+ */
1629
+ attachments?: ComposerProps["attachments"];
1630
+ /** Called with the complete next attachment list. See `attachments`. */
1631
+ onAttachmentsChange?: ComposerProps["onAttachmentsChange"];
1632
+ /**
1633
+ * Replaces the built-in model picker in the composer rail. Pass any node (a
1634
+ * host model chip, a status pill); `null` renders an empty rail. When set,
1635
+ * `hideModelPicker`, `reasoningEffort` and `onReasoningEffortChange` do
1636
+ * nothing, and model switching is the host's job.
1637
+ */
1638
+ modelRail?: ComposerProps["modelRail"];
1639
+ /** Extra composer controls, rendered after the rail (the Composer's `actions`). */
1640
+ actions?: ComposerProps["actions"];
1641
+ /**
1642
+ * Selected reasoning effort, shown by the built-in picker for a model that
1643
+ * lists `reasoningEfforts`. Controlled: pair with `onReasoningEffortChange`.
1644
+ */
1645
+ reasoningEffort?: ModelPickerProps["reasoningEffort"];
1646
+ /**
1647
+ * Called when the person picks an effort in the built-in picker. The effort
1648
+ * control is drawn only when this is set. Applying it to the thread (for
1649
+ * example `thread.update({ reasoningEffort })` on `@daex-dev/sdk` >= 0.3) is the
1650
+ * host's job; this component does not call the runtime for it.
1651
+ */
1652
+ onReasoningEffortChange?: ModelPickerProps["onReasoningEffortChange"];
1653
+ hideToolCalls?: TranscriptProps["hideToolCalls"];
1654
+ hideReasoning?: TranscriptProps["hideReasoning"];
1655
+ renderMarkdown?: TranscriptProps["renderMarkdown"];
1656
+ /**
1657
+ * Decide what a link in the transcript does. See
1658
+ * `TranscriptProps["onLinkClick"]`; an Electron host should pass it.
1659
+ */
1660
+ onLinkClick?: TranscriptProps["onLinkClick"];
1661
+ /**
1662
+ * Approval card wording, or a replacement card.
1663
+ *
1664
+ * The card itself is not opt-in: a provider that asks for permission blocks
1665
+ * its turn until someone answers, so a host that drew nothing would show a
1666
+ * conversation that has silently stopped. This only changes how it looks.
1667
+ */
1668
+ approvals?: TranscriptProps["approvals"];
1669
+ /** Extra content under a tool chip. See `TranscriptProps["renderToolResult"]`. */
1670
+ renderToolResult?: TranscriptProps["renderToolResult"];
1671
+ /** Action buttons on a tool chip. See `TranscriptProps["toolChipActions"]`. */
1672
+ toolChipActions?: TranscriptProps["toolChipActions"];
1673
+ /**
1674
+ * Envelopes per history page on a client with `historyPage`; older pages load
1675
+ * when the reader scrolls to the top. See `useDaexThread`.
1676
+ */
1677
+ historyPageSize?: number;
1678
+ /**
1679
+ * CSP nonce for the injected stylesheet, so a host whose `style-src` has no
1680
+ * `'unsafe-inline'` can still use the built-in styles. Ignored with
1681
+ * `disableStyles`. Only the first injection per document applies it.
1682
+ */
1683
+ styleNonce?: string;
1684
+ emptyState?: ReactNode;
1685
+ /** Hide the model rail when the host pins a model. */
1686
+ hideModelPicker?: boolean;
1687
+ className?: string;
1688
+ };
1689
+ declare function DaexChat(props: DaexChatProps): react.JSX.Element;
1690
+ /** @deprecated Use {@link DaexChat}. */
1691
+ declare const AdeChat: typeof DaexChat;
1692
+ /** @deprecated Use {@link DaexChatProps}. */
1693
+ type AdeChatProps = DaexChatProps;
1694
+ /** @deprecated Use {@link DaexChatSendResult}. */
1695
+ type AdeChatSendResult = DaexChatSendResult;
1696
+
1697
+ type QueueStripProps = {
1698
+ queue?: ThreadQueue;
1699
+ /** Refresh after a thread action or status transition. */
1700
+ refreshKey?: unknown;
1701
+ };
1702
+ declare function QueueStrip({ queue, refreshKey }: QueueStripProps): react.JSX.Element | null;
1703
+
1704
+ /**
1705
+ * Composer send/steer decision logic, kept pure so it can be tested without a
1706
+ * DOM and reused by hosts building their own composer.
1707
+ *
1708
+ * The rule the plan locks: submitting while a turn is running is a *steer*, not
1709
+ * a queued second turn. Interrupt is a separate, explicit control.
1710
+ */
1711
+
1712
+ type ComposerAction =
1713
+ /** Start a new turn. */
1714
+ {
1715
+ kind: "send";
1716
+ text: string;
1717
+ }
1718
+ /** Deliver into the turn already running. */
1719
+ | {
1720
+ kind: "steer";
1721
+ text: string;
1722
+ }
1723
+ /** Nothing to do. `reason` is safe to show as a hint. */
1724
+ | {
1725
+ kind: "blocked";
1726
+ reason: ComposerBlockReason;
1727
+ };
1728
+ type ComposerBlockReason = "empty" | "disabled" | "no_thread" | "steer_unsupported";
1729
+ type ComposerStateInput = {
1730
+ draft: string;
1731
+ status: ThreadStatus["state"];
1732
+ /** False while the thread handle is still resolving. */
1733
+ ready: boolean;
1734
+ /** Host-level disable (read-only embed, quota exhausted, …). */
1735
+ disabled?: boolean;
1736
+ /** Host may opt out of steering; submits are then blocked mid-turn. */
1737
+ allowSteer?: boolean;
1738
+ /** Attachments alone are a valid submission. */
1739
+ hasAttachments?: boolean;
1740
+ };
1741
+ type ComposerState = {
1742
+ action: ComposerAction;
1743
+ /** The primary button is actionable. */
1744
+ canSubmit: boolean;
1745
+ /** Show the stop control instead of relying on the send button. */
1746
+ canInterrupt: boolean;
1747
+ running: boolean;
1748
+ /** Label for the primary button. */
1749
+ submitLabel: string;
1750
+ };
1751
+ declare function resolveComposerAction(input: ComposerStateInput): ComposerAction;
1752
+ declare function resolveComposerState(input: ComposerStateInput): ComposerState;
1753
+ /** Human hint for a blocked submit. Null when the block needs no explanation. */
1754
+ declare function blockedHint(reason: ComposerBlockReason): string | null;
1755
+ type KeyIntent = "submit" | "newline" | "interrupt" | "none";
1756
+ /**
1757
+ * Keyboard contract, matching the desktop composer:
1758
+ * Enter submits, Shift+Enter is a newline (inverted by `sendOnEnter: false`,
1759
+ * where Cmd/Ctrl+Enter submits instead). Escape interrupts a running turn.
1760
+ * IME composition never submits.
1761
+ */
1762
+ declare function resolveKeyIntent(input: {
1763
+ key: string;
1764
+ shiftKey: boolean;
1765
+ metaKey: boolean;
1766
+ ctrlKey: boolean;
1767
+ isComposing: boolean;
1768
+ sendOnEnter: boolean;
1769
+ running: boolean;
1770
+ hasDraft: boolean;
1771
+ }): KeyIntent;
1772
+
1773
+ /**
1774
+ * A deliberately small markdown renderer.
1775
+ *
1776
+ * The package ships zero runtime dependencies, so assistant text is parsed
1777
+ * here rather than by `marked`/`react-markdown`. It covers what agents
1778
+ * actually emit: fenced code, headings, lists, blockquotes, rules, and inline
1779
+ * code/bold/italic/links. Everything is rendered as React elements — no
1780
+ * `dangerouslySetInnerHTML` anywhere, so raw HTML in a model response is text,
1781
+ * not markup.
1782
+ *
1783
+ * Hosts that want full CommonMark pass their own `renderMarkdown` to
1784
+ * `<Transcript>`.
1785
+ */
1786
+
1787
+ type Block = {
1788
+ kind: "code";
1789
+ language: string | null;
1790
+ text: string;
1791
+ } | {
1792
+ kind: "heading";
1793
+ level: 1 | 2 | 3;
1794
+ text: string;
1795
+ } | {
1796
+ kind: "list";
1797
+ ordered: boolean;
1798
+ items: string[];
1799
+ } | {
1800
+ kind: "quote";
1801
+ text: string;
1802
+ } | {
1803
+ kind: "rule";
1804
+ } | {
1805
+ kind: "paragraph";
1806
+ text: string;
1807
+ };
1808
+ declare function parseMarkdownBlocks(source: string): Block[];
1809
+ type InlineToken = {
1810
+ kind: "text";
1811
+ value: string;
1812
+ } | {
1813
+ kind: "code";
1814
+ value: string;
1815
+ } | {
1816
+ kind: "strong";
1817
+ value: string;
1818
+ } | {
1819
+ kind: "em";
1820
+ value: string;
1821
+ } | {
1822
+ kind: "link";
1823
+ value: string;
1824
+ href: string;
1825
+ };
1826
+ declare function parseInline(source: string): InlineToken[];
1827
+ /**
1828
+ * `javascript:` and `data:` hrefs never reach the DOM. Anything not obviously
1829
+ * safe renders as plain text.
1830
+ */
1831
+ declare function safeHref(href: string): string | null;
1832
+ /** Render markdown text as React nodes. The default for assistant messages. */
1833
+ declare function renderMarkdown(source: string): ReactNode;
1834
+
1835
+ type ProviderCardProps = {
1836
+ status: ProviderStatus;
1837
+ /** Replace the copy button (e.g. to open a terminal instead). */
1838
+ renderAction?: (command: string, kind: "install" | "login") => ReactNode;
1839
+ /** Override the clipboard write; defaults to `navigator.clipboard`. */
1840
+ onCopy?: (command: string) => void | Promise<void>;
1841
+ /**
1842
+ * Show the probed version and binary path. Off by default: most hosts read a
1843
+ * filesystem path as noise, and the ones building a setup screen need it.
1844
+ */
1845
+ showDetail?: boolean;
1846
+ /**
1847
+ * Handle the "Documentation" link yourself (see `DaexLinkClickHandler`).
1848
+ * Without it the link opens with `target="_blank"`, which in Electron is a
1849
+ * new app window; an Electron host should pass this.
1850
+ */
1851
+ onLinkClick?: DaexLinkClickHandler;
1852
+ className?: string;
1853
+ };
1854
+ /**
1855
+ * What the card calls a provider it does not have.
1856
+ *
1857
+ * "Not installed" is a claim about the filesystem, and only a runtime that
1858
+ * probed one may make it. When the status was derived from the model catalog
1859
+ * nobody looked, so the card says "Not detected" — the honest report of an
1860
+ * absence of evidence rather than evidence of an absence.
1861
+ */
1862
+ declare function resolveStateCopy(status: ProviderStatus): string;
1863
+ /**
1864
+ * Shorten a binary path while keeping the part that identifies it.
1865
+ *
1866
+ * The basename is never cut: "…/claude" tells the reader which binary this is,
1867
+ * where a head-first truncation ("/usr/local/lib/node_modules/@anthr…") tells
1868
+ * them nothing. Windows separators are handled, because the same card renders
1869
+ * there.
1870
+ */
1871
+ declare function truncateBinaryPath(value: string, maxLength?: number): string;
1872
+ declare function ProviderCard({ status, renderAction, onCopy, showDetail, onLinkClick, className, }: ProviderCardProps): react.JSX.Element;
1873
+ type ProviderCardsProps = {
1874
+ /** Supply statuses directly; omit to read from the client/context. */
1875
+ statuses?: readonly ProviderStatus[];
1876
+ client?: DaexChatClient;
1877
+ /**
1878
+ * Show only providers that need attention. Default true. Pass `false` for a
1879
+ * settings page that lists every provider: a ready provider then renders as
1880
+ * a one-line card (status dot, name, "Ready"), with no command.
1881
+ */
1882
+ onlyNeedsAttention?: boolean;
1883
+ renderAction?: ProviderCardProps["renderAction"];
1884
+ onCopy?: ProviderCardProps["onCopy"];
1885
+ /** Forwarded to every card. Off by default. */
1886
+ showDetail?: ProviderCardProps["showDetail"];
1887
+ /** Forwarded to every card. See `ProviderCardProps["onLinkClick"]`. */
1888
+ onLinkClick?: ProviderCardProps["onLinkClick"];
1889
+ className?: string;
1890
+ };
1891
+ /** Convenience list of the providers that need the user to do something. */
1892
+ declare function ProviderCards(props: ProviderCardsProps): react.JSX.Element;
1893
+
1894
+ /**
1895
+ * Model search scoring.
1896
+ *
1897
+ * PROVENANCE: ported from
1898
+ * `apps/desktop/src/renderer/components/shared/ModelPicker/modelPickerSearch.ts`.
1899
+ * The scoring behaviour (exact > prefix > word-boundary > substring > fuzzy
1900
+ * subsequence, per-field bases, multi-token AND) is carried over unchanged; the
1901
+ * only edits are dropping the DAEX `ProviderFamily` import in favour of a plain
1902
+ * provider id, and dropping the favourites boost (this package has no
1903
+ * favourites store).
1904
+ */
1905
+
1906
+ type SearchableModel = {
1907
+ displayName: string;
1908
+ shortName?: string;
1909
+ subProvider?: string;
1910
+ aliases?: string[];
1911
+ providerId: string;
1912
+ providerDisplayName?: string;
1913
+ };
1914
+ /** Lower is better. Null means "no match" — every token must hit some field. */
1915
+ declare function scoreModelSearch(item: SearchableModel, query: string): number | null;
1916
+ type ProviderModelGroup = {
1917
+ providerId: string;
1918
+ providerLabel: string;
1919
+ status: ProviderStatus | null;
1920
+ /** False when the provider is not installed or not authenticated. */
1921
+ enabled: boolean;
1922
+ models: ModelDescriptor[];
1923
+ };
1924
+ /** A provider can be selected from only when it is installed and authed. */
1925
+ declare function isProviderUsable(status: ProviderStatus | null | undefined): boolean;
1926
+ /** Model rows are disabled when their provider is unusable or `available: false`. */
1927
+ declare function isModelSelectable(model: ModelDescriptor, status: ProviderStatus | null | undefined): boolean;
1928
+ /**
1929
+ * Group models by provider, filtering and ordering by search score. Providers
1930
+ * keep a stable order (the order they appear in `statuses`, then any provider
1931
+ * seen only in the model list), so the rail does not reshuffle as you type.
1932
+ */
1933
+ declare function groupModelsByProvider(input: {
1934
+ models: readonly ModelDescriptor[];
1935
+ statuses: readonly ProviderStatus[];
1936
+ query?: string;
1937
+ }): ProviderModelGroup[];
1938
+
1939
+ /**
1940
+ * Adapter from an `@daex-dev/sdk` client to the `DaexChatClient` this package renders.
1941
+ *
1942
+ * WHY THIS EXISTS. The two packages were designed against each other but do not
1943
+ * meet structurally, and every difference is deliberate on both sides:
1944
+ *
1945
+ * | concern | `@daex-dev/sdk` | `@daex-dev/chat-ui` |
1946
+ * |--------------------|-----------------------------------|------------------------------|
1947
+ * | provider statuses | `Record<string, …>` keyed by id | an array of `{ id, … }` |
1948
+ * | provider fields | `available` / `requiresConfiguration` | `installed` / `loginCommand` |
1949
+ * | model rows | `{ provider, isAvailable }` | `{ providerId, available }` |
1950
+ * | open options | `{ provider, model }` | `{ providerId, modelId }` |
1951
+ * | `send` | `(text, { attachments })` | `(SendInput \| string)` |
1952
+ * | `on("status")` | a raw event envelope | `{ state, turnId, message }` |
1953
+ * | `on("usage")` | a raw event envelope | `{ inputTokens, … }` |
1954
+ *
1955
+ * The SDK is envelope-faithful on purpose (it must not lose fields it does not
1956
+ * understand) and this package is view-shaped on purpose (it renders a state,
1957
+ * not a stream). Without this function every embedder writes the same ~150
1958
+ * lines of glue, and each one gets the tool-status and token mapping subtly
1959
+ * different. It lives here rather than in `@daex-dev/sdk` because it produces THIS
1960
+ * package's contract and must stay browser-safe. The SDK is imported for its
1961
+ * TYPES only, so it contributes nothing to the bundle and stays an optional
1962
+ * peer: an app that proxies its SDK client over IPC or a socket can adapt the
1963
+ * proxy just as well as the real object.
1964
+ *
1965
+ * import { adaptSdkClient } from "@daex-dev/chat-ui";
1966
+ *
1967
+ * const client = adaptSdkClient(sdkClient, {
1968
+ * defaults: { provider: "claude", model: "anthropic/claude-haiku-5-5" },
1969
+ * });
1970
+ */
1971
+
1972
+ /**
1973
+ * A provider status record as this adapter reads one.
1974
+ *
1975
+ * The catalog half is picked from the SDK's own type, so a rename over there is
1976
+ * a compile error here. The probe half is restated as OPTIONAL, and that is the
1977
+ * whole point: `@daex-dev/sdk` 0.2 always fills those fields (deriving them when
1978
+ * the runtime cannot probe), but a 0.1 client, a WebSocket proxy, or a test
1979
+ * double sends a record without them. Requiring them would reject clients that
1980
+ * work perfectly well, and this adapter already has an honest answer for their
1981
+ * absence — `source: "derived"`.
1982
+ */
1983
+ type SdkProviderStatusRecord = Pick<ProviderStatus$1, "provider" | "displayName" | "authenticated" | "available" | "requiresConfiguration" | "modelCount" | "stale"> & Partial<{
1984
+ installed: boolean;
1985
+ binaryPath: string | null;
1986
+ version: string | null;
1987
+ authMethod: string | null;
1988
+ installCommand: string | null;
1989
+ loginCommand: string | null;
1990
+ docsUrl: string | null;
1991
+ source: "probed" | "derived";
1992
+ checkedAt: string;
1993
+ detail: string | null;
1994
+ }>;
1995
+ /**
1996
+ * The SDK's attachment reference, under this adapter's name.
1997
+ *
1998
+ * `type` and `hydrate` are restated rather than read off the SDK type because
1999
+ * an SDK before 0.3 has neither: the adapter always sets `type`, and an older
2000
+ * SDK forwards the extra field to a runtime that already reads it.
2001
+ */
2002
+ type SdkFileRef = AgentChatFileRef & {
2003
+ type?: "file" | "image";
2004
+ hydrate?: boolean;
2005
+ };
2006
+ /**
2007
+ * A catalog row as this adapter reads one.
2008
+ *
2009
+ * Everything past the three fields it actually maps is optional: an older
2010
+ * runtime, or a proxy that forwards only what the picker needs, omits fields
2011
+ * this package never looks at, and requiring them would reject a client that
2012
+ * works perfectly well.
2013
+ */
2014
+ type SdkModelCatalogEntry = Pick<ModelCatalogEntry, "id" | "displayName" | "provider"> & Partial<ModelCatalogEntry>;
2015
+ /**
2016
+ * A thread this adapter can wrap.
2017
+ *
2018
+ * `setModel` is optional because an older `@daex-dev/sdk` has none — see
2019
+ * `DaexThread.setModel` for why that is reported rather than assumed. `id` and
2020
+ * `mcpCapability` are optional because nothing here reads them, and demanding
2021
+ * them would reject a proxy that forwards only the chat surface.
2022
+ */
2023
+ type SdkLikeThread = Pick<DaexThread$1, "key" | "send" | "interrupt" | "history" | "on"> & Partial<Pick<DaexThread$1, "id" | "mcpCapability">> & {
2024
+ /**
2025
+ * Restated rather than picked: `@daex-dev/sdk` 0.3 resolves it to the
2026
+ * selection plus the new capability reports, 0.2 and the Electron bridge to
2027
+ * the selection alone. The adapter reads the result only as an optional
2028
+ * `ThreadModelSelection`, so every generation fits.
2029
+ */
2030
+ setModel?(modelId: string): Promise<unknown>;
2031
+ /**
2032
+ * Restated so both SDK generations fit: 0.3 takes `(text, { attachments })`
2033
+ * and accepts an empty text with attachments; 0.2 and a chat-only proxy take
2034
+ * `(text)` only. The adapter always passes the options, which an older
2035
+ * thread ignores.
2036
+ */
2037
+ steer(text: string, opts?: {
2038
+ attachments?: SdkFileRef[];
2039
+ }): Promise<void>;
2040
+ /**
2041
+ * Paged history (`@daex-dev/sdk` >= 0.3). OPTIONAL; forwarded only when
2042
+ * present, so `useDaexThread` can tell a paging client from one that loads
2043
+ * the whole window in one `history()` read.
2044
+ */
2045
+ historyPage?(request?: HistoryPageOptions): Promise<{
2046
+ events: AgentChatEventEnvelope[];
2047
+ hasMore: boolean;
2048
+ nextBeforeSequence?: number | null;
2049
+ }>;
2050
+ /**
2051
+ * The resolved model (`@daex-dev/sdk` >= 0.3 `ThreadModelSelection`). Read as a
2052
+ * live property, never cached: the SDK updates it after `setModel`.
2053
+ */
2054
+ readonly model?: {
2055
+ modelId: string;
2056
+ displayName?: string | null;
2057
+ provider?: string;
2058
+ } | null;
2059
+ /**
2060
+ * Declared structurally rather than picked from the SDK thread, for the
2061
+ * same reason as the probe fields above: an older `@daex-dev/sdk`, a fake,
2062
+ * or a proxy that forwards only the chat surface has no answer path, and
2063
+ * this adapter reports its absence instead of assuming it.
2064
+ */
2065
+ approve?(itemId: string, decision: ApprovalDecision, responseText?: string): Promise<void>;
2066
+ pendingApprovals?(): Promise<readonly ApprovalRequest[]>;
2067
+ respond?(requestId: string, response: PendingInputResponse): Promise<void>;
2068
+ queue?: ThreadQueue;
2069
+ slashCommands?(): Promise<readonly SlashCommand[]>;
2070
+ usageLimit?: {
2071
+ resumeNow?(): Promise<unknown>;
2072
+ continueOnAlternate?(): Promise<unknown>;
2073
+ };
2074
+ switchAccount?(instanceId: string): Promise<unknown>;
2075
+ /** `@daex-dev/sdk` >= 0.3 `thread.update`. Forwarded only when present. */
2076
+ update?(patch: ThreadUpdatePatch): Promise<ThreadUpdateReply>;
2077
+ /** `@daex-dev/sdk` >= 0.4 `thread.retry` / `thread.editLast`. Forwarded only when present. */
2078
+ retry?(): Promise<unknown>;
2079
+ editLast?(text: string, opts?: {
2080
+ attachments?: SdkFileRef[];
2081
+ }): Promise<unknown>;
2082
+ };
2083
+ /**
2084
+ * A client this adapter can wrap.
2085
+ *
2086
+ * `threads.open` takes a loose record because `openOptionsFor` merges arbitrary
2087
+ * host defaults into it, and it resolves to `SdkLikeThread` so a proxy's thread
2088
+ * qualifies too. `list`, `doctor`, `dispose` and `exportThread` are the host's
2089
+ * business and are deliberately not required.
2090
+ */
2091
+ interface SdkLikeChatClient {
2092
+ /**
2093
+ * Restated rather than picked from `SdkChatClient["providers"]`, for the
2094
+ * relaxations only: the records are `SdkProviderStatusRecord` (see above) and
2095
+ * `refresh` is OPTIONAL, because a 0.1 client and a chat-only proxy have
2096
+ * nothing to re-probe. A real client satisfies both, and the assignability
2097
+ * test in `test/sdkClient.test.ts` is what keeps that true.
2098
+ */
2099
+ providers: {
2100
+ status(): Promise<Record<string, SdkProviderStatusRecord>>;
2101
+ onChange(cb: (statuses: Record<string, SdkProviderStatusRecord>) => void): Unsubscribe;
2102
+ refresh?(): Promise<Record<string, SdkProviderStatusRecord>>;
2103
+ capabilities?(provider: string): Promise<ProviderCapabilities | null>;
2104
+ };
2105
+ models: {
2106
+ list(): Promise<SdkModelCatalogEntry[]>;
2107
+ };
2108
+ threads: {
2109
+ open(key: string, opts?: Record<string, unknown>): Promise<SdkLikeThread>;
2110
+ };
2111
+ accounts?: AccountManagement;
2112
+ credentials?: CredentialManagement;
2113
+ /**
2114
+ * Client events (`@daex-dev/sdk` >= 0.3 `client.on`, and the Electron
2115
+ * renderer client). OPTIONAL: clients without this surface report neither
2116
+ * restarts nor usage-limit updates.
2117
+ */
2118
+ on?(event: "restart", cb: (payload: DaexChatClientEventMap["restart"]) => void): Unsubscribe;
2119
+ }
2120
+ /**
2121
+ * Per-provider shell commands, as an OVERRIDE of what the runtime reports.
2122
+ *
2123
+ * A runtime that probes providers already knows how to install and sign in to
2124
+ * each one, and those strings arrive on the status record. Use this to change
2125
+ * DAEX's wording — not to supply it. A hint always wins over the record, so a
2126
+ * host that set these in 0.1.x keeps the exact copy it had.
2127
+ */
2128
+ type ProviderCommandHints = Record<string, {
2129
+ installCommand?: string;
2130
+ loginCommand?: string;
2131
+ docsUrl?: string;
2132
+ }>;
2133
+ type AdaptSdkClientOptions = {
2134
+ /**
2135
+ * Create-time arguments merged into every `threads.open` this package makes.
2136
+ *
2137
+ * `<DaexChat>` only ever supplies a `modelId`, so the provider, MCP servers,
2138
+ * permission preset and title all have to come from the host. When the picked
2139
+ * model is in the catalog its provider wins over `defaults.provider`.
2140
+ *
2141
+ * Over the `@daex-dev/sdk` >= 0.3 Electron bridge, the main process drops every
2142
+ * renderer open option except `provider`, `model`, `title` and
2143
+ * `reasoningEffort` unless the host registered an `openOptions` hook, so MCP
2144
+ * servers, permissions, cwd and instructions set here have no effect there.
2145
+ * Set them in the main process instead.
2146
+ */
2147
+ defaults?: Record<string, unknown> & {
2148
+ provider?: string;
2149
+ model?: string;
2150
+ };
2151
+ /** Install/login commands rendered on `<ProviderCard>`. */
2152
+ commandHints?: ProviderCommandHints;
2153
+ /** Restrict the picker and the cards to these providers, in this order. */
2154
+ providerFilter?: readonly string[];
2155
+ };
2156
+ /**
2157
+ * Envelope -> `ThreadStatus`, or null when the envelope says nothing about the
2158
+ * running state.
2159
+ *
2160
+ * Returning null matters: mapping an unrecognised status event to `idle` would
2161
+ * drop the composer out of its running state mid-turn and re-enable Send.
2162
+ */
2163
+ declare function threadStatusFromEnvelope(envelope: AgentChatEventEnvelope): ThreadStatus | null;
2164
+ /**
2165
+ * Envelope -> `ThreadUsage`, or null when there are no numbers in it.
2166
+ *
2167
+ * Three event types carry tokens (`tokens`, `context_usage`,
2168
+ * `codex_token_usage`) with different field names, and `context_usage` nests
2169
+ * everything under `usage`. All three are read here so the caller never has to.
2170
+ */
2171
+ declare function threadUsageFromEnvelope(envelope: AgentChatEventEnvelope): ThreadUsage | null;
2172
+ declare function providerStatusesFromSdk(statuses: Record<string, SdkProviderStatusRecord>, options?: AdaptSdkClientOptions): ProviderStatus[];
2173
+ declare function modelDescriptorsFromSdk(models: SdkModelCatalogEntry[], options?: AdaptSdkClientOptions): ModelDescriptor[];
2174
+ /**
2175
+ * `"image"` or `"file"` for one attachment, by the runtime's rule.
2176
+ *
2177
+ * Any `image/*` mime type means image. Otherwise — including for a non-image
2178
+ * mime type, which does NOT force `"file"` — the path's extension decides:
2179
+ * `.bmp .gif .heic .heif .ico .jpeg .jpg .png .svg .tif .tiff .webp` are
2180
+ * images, everything else is a file. Same name, signature and answer as the
2181
+ * runtime's `inferAttachmentType`.
2182
+ */
2183
+ declare function inferAttachmentType(filePath: string, mimeType?: string | null): "file" | "image";
2184
+ /**
2185
+ * `"image"` or `"file"` for one attachment: an explicit `type` wins, else
2186
+ * `inferAttachmentType` on its `uri` — the path the runtime receives, so the
2187
+ * runtime would infer the same — with its `mimeType`. `name` stands in only
2188
+ * for an attachment with no `uri`, which is never sent.
2189
+ */
2190
+ declare function attachmentKind(attachment: ChatAttachment): "file" | "image";
2191
+ /** Wrap an `@daex-dev/sdk` client (or a proxy of one) as an `DaexChatClient`. */
2192
+ declare function adaptSdkClient(sdk: SdkLikeChatClient, options?: AdaptSdkClientOptions): DaexChatClient;
2193
+
2194
+ /**
2195
+ * Renders the package stylesheet once per document.
2196
+ *
2197
+ * `<DaexChat>` mounts this automatically. Hosts assembling the components
2198
+ * themselves render it once near the root, or call `injectDaexChatStyles()`.
2199
+ */
2200
+ type DaexChatStylesProps = {
2201
+ /** CSP nonce for the injected `<style>`. See `InjectDaexChatStylesOptions`. */
2202
+ nonce?: string;
2203
+ };
2204
+ declare function DaexChatStyles({ nonce }?: DaexChatStylesProps): null;
2205
+ /** @deprecated Use {@link DaexChatStyles}. */
2206
+ declare const AdeChatStyles: typeof DaexChatStyles;
2207
+ /** @deprecated Use {@link DaexChatStylesProps}. */
2208
+ type AdeChatStylesProps = DaexChatStylesProps;
2209
+
2210
+ /**
2211
+ * The package's entire stylesheet, as a string.
2212
+ *
2213
+ * It is plain CSS against `--adechat-*` tokens — no Tailwind, no CSS modules,
2214
+ * no build-step CSS import for consumers to wire up. Hosts either render
2215
+ * `<DaexChatStyles />` (the default, and what `<DaexChat>` does for you) or call
2216
+ * `injectDaexChatStyles()` once at startup.
2217
+ *
2218
+ * Class names are prefixed `adechat-` and are not a public API; theme with
2219
+ * tokens, not by overriding these rules.
2220
+ */
2221
+ declare const daexChatCss: string;
2222
+ /**
2223
+ * Insert the stylesheet once per document. Safe to call repeatedly and in SSR
2224
+ * (it no-ops without a document).
2225
+ */
2226
+ type InjectDaexChatStylesOptions = {
2227
+ /**
2228
+ * CSP nonce set on the injected `<style>`, so a host whose `style-src` lists
2229
+ * `'nonce-…'` instead of `'unsafe-inline'` can load the sheet. Applied only
2230
+ * by the call that creates the element: a sheet already in the document is
2231
+ * left as it is.
2232
+ */
2233
+ nonce?: string;
2234
+ };
2235
+ declare function injectDaexChatStyles(target?: Document, options?: InjectDaexChatStylesOptions): void;
2236
+ /** @deprecated Use {@link InjectDaexChatStylesOptions}. */
2237
+ type InjectAdeChatStylesOptions = InjectDaexChatStylesOptions;
2238
+ /** @deprecated Use {@link daexChatCss}. */
2239
+ declare const adeChatCss: string;
2240
+ /** @deprecated Use {@link injectDaexChatStyles}. */
2241
+ declare const injectAdeChatStyles: typeof injectDaexChatStyles;
2242
+
2243
+ type UsageLimitNoticeProps = {
2244
+ status: UsageLimitStatus | null;
2245
+ onResumeNow?: () => void | Promise<void>;
2246
+ onContinueOnAlternate?: () => void | Promise<void>;
2247
+ };
2248
+ declare function UsageLimitNotice({ status, onResumeNow, onContinueOnAlternate }: UsageLimitNoticeProps): react.JSX.Element | null;
2249
+
2250
+ type AccountListProps = {
2251
+ client?: DaexChatClient;
2252
+ accounts?: readonly AccountInfo[];
2253
+ onSelect?: (account: AccountInfo) => void | Promise<void>;
2254
+ className?: string;
2255
+ };
2256
+ declare function AccountList({ client, accounts: supplied, onSelect, className }: AccountListProps): react.JSX.Element;
2257
+
2258
+ type AccountSwitcherProps = {
2259
+ accounts: readonly AccountInfo[];
2260
+ currentAccountId?: string | null;
2261
+ thread?: Pick<DaexThread, "switchAccount"> | null;
2262
+ onSwitch?: (instanceId: string) => void | Promise<void>;
2263
+ className?: string;
2264
+ };
2265
+ declare function AccountSwitcher({ accounts, currentAccountId, thread, onSwitch, className }: AccountSwitcherProps): react.JSX.Element | null;
2266
+
2267
+ type ApiKeyFormProps = {
2268
+ provider: ProviderId;
2269
+ client?: DaexChatClient;
2270
+ onSubmit?: (input: {
2271
+ provider: ProviderId;
2272
+ key: string;
2273
+ label?: string;
2274
+ }) => unknown | Promise<unknown>;
2275
+ className?: string;
2276
+ };
2277
+ /** The form accepts a new key and never receives or renders a stored key. */
2278
+ declare function ApiKeyForm({ provider, client, onSubmit, className }: ApiKeyFormProps): react.JSX.Element | null;
2279
+
2280
+ type SignInCardProps = {
2281
+ handle?: SignInHandle | null;
2282
+ onStart?: () => SignInHandle | Promise<SignInHandle>;
2283
+ onComplete?: (account: AccountInfo) => void;
2284
+ className?: string;
2285
+ };
2286
+ declare function SignInCard({ handle: providedHandle, onStart, onComplete, className }: SignInCardProps): react.JSX.Element;
2287
+
2288
+ type UsageMeterProps = {
2289
+ usage: AccountUsage;
2290
+ label?: string;
2291
+ className?: string;
2292
+ };
2293
+ /** One bar per quota window, filled by the share still left. */
2294
+ declare function UsageMeter({ usage, label, className }: UsageMeterProps): react.JSX.Element;
2295
+
2296
+ export { ADE_CHAT_TOKENS, type AccountInfo, AccountList, type AccountListProps, type AccountManagement, AccountSwitcher, type AccountSwitcherProps, type AccountUsage, type AccountUsageWindow, ActivityIndicator, type ActivityLabelConfig, type ActivityLabelEntry, type ActivityLabelSource, type ActivityPhase, type AdaptSdkClientOptions, AdeChat, type AdeChatClient, type AdeChatClientEventMap, type AdeChatContextValue, type AdeChatProps, AdeChatProvider, type AdeChatProviderProps, type AdeChatSendResult, AdeChatStyles, type AdeChatStylesProps, type AdeChatTheme, type AdeChatToken, AdeLink, type AdeLinkClickHandler, type AdeLinkClickInfo, AdeLinkHandlerProvider, type AdeLinkSource, type AdeThread, type AgentChatEvent, type AgentChatEventEnvelope, type AgentChatResourceLink, type ApiCredentialInfo, ApiKeyForm, type ApiKeyFormProps, ApprovalCard, type ApprovalCardProps, type ApprovalDecision, type ApprovalKind, type ApprovalLabels, type ApprovalRequest, type ApprovalRespond, type ApprovalRow, type ApprovalRowState, type ApprovalUiOptions, type ChatAttachment, type ChatEventMcpSource, Composer, type ComposerAction, type ComposerBlockReason, type ComposerProps, type ComposerState, type ComposerStateInput, type CreateThemeInput, type CredentialManagement, DAEX_CHAT_TOKENS, DEFAULT_APPROVAL_WAITING_LABEL, DEFAULT_ELAPSED_AFTER_MS, DEFAULT_HISTORY_PAGE_SIZE, DEFAULT_THINKING_LABEL, DaexChat, type DaexChatClient, type DaexChatClientEventMap, type DaexChatContextValue, type DaexChatProps, DaexChatProvider, type DaexChatProviderProps, type DaexChatSendResult, DaexChatStyles, type DaexChatStylesProps, type DaexChatTheme, type DaexChatToken, DaexLink, type DaexLinkClickHandler, type DaexLinkClickInfo, DaexLinkHandlerProvider, type DaexLinkSource, type DaexThread, type HistoryPageOptions, type InjectAdeChatStylesOptions, type InjectDaexChatStylesOptions, type KeyIntent, type ModelDescriptor, ModelPicker, type ModelPickerProps, NO_APPROVE_NOTICE, PendingInputCard, type PendingInputCardProps, type PendingInputDecision, type PendingInputOption, type PendingInputQuestion, type PendingInputRespond, type PendingInputResponse, type ProviderCapabilities, ProviderCard, type ProviderCardProps, ProviderCards, type ProviderCardsProps, type ProviderCommandHints, type ProviderId, type ProviderModelGroup, type ProviderStatus, type ProvidersState, QueueStrip, type QueueStripProps, type QueuedMessage, type SdkFileRef, type SdkLikeChatClient, type SdkLikeThread, type SdkModelCatalogEntry, type SdkProviderStatusRecord, type SearchableModel, type SendInput, SignInCard, type SignInCardProps, type SignInHandle, type SignInUpdate, type SlashCommand, type ThreadHistoryPage, type ThreadModelSelection, type ThreadOpenOptions, type ThreadQueue, type ThreadState, type ThreadStatus, type ThreadUpdatePatch, type ThreadUpdateReply, type ThreadUsage, type ToolCallStatus, ToolChip, type ToolChipAction, type ToolChipProps, type ToolChipRow, type ToolIdentity, Transcript, type TranscriptProps, type TranscriptRow, TranscriptRowBuilder, type TranscriptRowEvent, UNANSWERABLE_NOTICE, type Unsubscribe, type UsageLimitEvent, UsageLimitNotice, type UsageLimitNoticeProps, type UsageLimitStatus, UsageMeter, type UsageMeterProps, adaptSdkClient, adeChatCss, approvalRequestFromRow, attachmentKind, blockedHint, buildTranscriptRows, collapseTranscriptEvents, createTheme, daexChatCss, defaultTheme, describeToolActivity, eventHasPayload, formatElapsed, formatStructuredValue, groupModelsByProvider, groupTranscriptRows, inferAttachmentType, injectAdeChatStyles, injectDaexChatStyles, isModelSelectable, isProviderUsable, matchLabelKey, mergeAttachments, mergeStreamingText, modelDescriptorsFromSdk, parseInline, parseMarkdownBlocks, parseToolIdentity, phaseForToolStatus, providerStatusesFromSdk, readApprovalCommand, readApprovalPaths, renderMarkdown, resolveActivityIcon, resolveActivityLabel, resolveComposerAction, resolveComposerState, resolveKeyIntent, resolveStateCopy, resolveToolName, safeHref, scoreModelSearch, shouldMergeTextRows, themeToCss, threadStatusFromEnvelope, threadUsageFromEnvelope, truncateBinaryPath, useAdeChatClient, useAdeChatContext, useAdeProviders, useAdeThread, useDaexChatClient, useDaexChatContext, useDaexProviders, useDaexThread, usePrefersReducedMotion };