@daex-dev/sdk 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.
Files changed (47) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +478 -2
  3. package/dist/client-DVZHOtg6.d.cts +2635 -0
  4. package/dist/client-DVZHOtg6.d.ts +2635 -0
  5. package/dist/connect/browser.cjs +209 -0
  6. package/dist/connect/browser.d.cts +81 -0
  7. package/dist/connect/browser.d.ts +81 -0
  8. package/dist/connect/browser.js +183 -0
  9. package/dist/connect/index.cjs +1954 -0
  10. package/dist/connect/index.d.cts +433 -0
  11. package/dist/connect/index.d.ts +433 -0
  12. package/dist/connect/index.js +1888 -0
  13. package/dist/electron/global.cjs +18 -0
  14. package/dist/electron/global.d.cts +35 -0
  15. package/dist/electron/global.d.ts +35 -0
  16. package/dist/electron/global.js +0 -0
  17. package/dist/electron/index.cjs +1133 -0
  18. package/dist/electron/index.d.cts +510 -0
  19. package/dist/electron/index.d.ts +510 -0
  20. package/dist/electron/index.js +1073 -0
  21. package/dist/electron/preload-auto.cjs +38 -0
  22. package/dist/electron/preload.cjs +66 -0
  23. package/dist/electron/preload.d.cts +46 -0
  24. package/dist/electron/preload.d.ts +46 -0
  25. package/dist/electron/preload.js +43 -0
  26. package/dist/electron/protocol-DXRtliy3.d.cts +904 -0
  27. package/dist/electron/protocol-DXRtliy3.d.ts +904 -0
  28. package/dist/electron/renderer.cjs +631 -0
  29. package/dist/electron/renderer.d.cts +508 -0
  30. package/dist/electron/renderer.d.ts +508 -0
  31. package/dist/electron/renderer.global.js +634 -0
  32. package/dist/electron/renderer.js +608 -0
  33. package/dist/index.cjs +6731 -0
  34. package/dist/index.d.cts +316 -0
  35. package/dist/index.d.ts +316 -0
  36. package/dist/index.js +6661 -0
  37. package/dist/server.cjs +1019 -0
  38. package/dist/server.d.cts +118 -0
  39. package/dist/server.d.ts +118 -0
  40. package/dist/server.js +989 -0
  41. package/dist/testing.cjs +815 -0
  42. package/dist/testing.d.cts +29 -0
  43. package/dist/testing.d.ts +29 -0
  44. package/dist/testing.js +787 -0
  45. package/dist/types-DUGv-9QF.d.cts +166 -0
  46. package/dist/types-DUGv-9QF.d.ts +166 -0
  47. package/package.json +109 -4
@@ -0,0 +1,904 @@
1
+ /**
2
+ * What the provider did with a host-configuration request.
3
+ *
4
+ * Null means one of two things, exactly as `mcpCapability` does: this thread
5
+ * asked for nothing, or it asked and an older runtime reported nothing. The
6
+ * SDK does not invent a level for the second case — an unverified guarantee is
7
+ * reported as unverified.
8
+ */
9
+ type HostConfigCapability = {
10
+ /**
11
+ * Always true on a non-null report: a report exists only for a request that
12
+ * was made. Retained because the field is part of the published shape and
13
+ * because a null report is ambiguous, so code that has a report in hand can
14
+ * still say plainly which of the two cases it is not in.
15
+ */
16
+ requested: boolean;
17
+ level: AgentChatHostConfigLevel;
18
+ /** How the provider implemented it, for logs and support threads. */
19
+ mechanism: string;
20
+ /** Why the level is not `"applied"`, or null when it is. */
21
+ detail: string | null;
22
+ } & Record<string, unknown>;
23
+ type InstructionsCapability = HostConfigCapability & {
24
+ mode: "append" | "replace";
25
+ };
26
+ type SettingSourcesCapability = HostConfigCapability & {
27
+ value: AgentChatSettingSources;
28
+ };
29
+ /**
30
+ * What the provider could actually enforce of a permission policy.
31
+ *
32
+ * `"enforced"` means the provider itself gates every tool call against the
33
+ * policy. `"best-effort"` means DAEX approximated it with the containment and
34
+ * approval knobs the provider does expose, and `residual` names what the policy
35
+ * therefore does not cover. `"unsupported"` means the provider has no gate at
36
+ * all and only the coarse preset applies.
37
+ */
38
+ type PermissionCapability = {
39
+ level: "enforced" | "best-effort" | "unsupported";
40
+ mechanism: string;
41
+ residual: string | null;
42
+ };
43
+
44
+ /**
45
+ * Wire types for the DAEX machine-scoped chat surface.
46
+ *
47
+ * PROVENANCE — every type in this file is a hand-copied subset of DAEX's own
48
+ * shared contracts. The package deliberately does NOT import across the repo
49
+ * boundary (`apps/desktop/src/shared/**`) so it builds and publishes on its
50
+ * own. When the engine contract moves, this file moves with it:
51
+ *
52
+ * - `AgentChatEventEnvelope`, `AgentChatEvent`, `AgentChatSessionSummary`,
53
+ * `AgentChatCreateArgs`, `AgentChatSendArgs`, `AgentChatSteerArgs`,
54
+ * `AgentChatModelCatalog*`, permission-mode unions
55
+ * <- apps/desktop/src/shared/types/chat.ts
56
+ * - the runtime's internal wire shapes (`BufferedEvent`, the
57
+ * `personalChats.call` envelope, `ade/initialize`) live in `wireTypes.ts`
58
+ *
59
+ * The event union in `chat.ts` has ~60 members and grows every release, so it
60
+ * is modelled here as an open record with a `type` discriminant plus narrowed
61
+ * shapes for the members an SDK consumer actually renders. Unknown members
62
+ * pass through untouched rather than being dropped or failing a parse.
63
+ */
64
+
65
+ /** Known provider ids for autocomplete; provider strings remain open for newer runtimes. */
66
+ type DaexProvider = "claude" | "codex" | "cursor" | "droid" | "opencode" | "pi" | "muse" | "qwen" | "kimi" | "grok" | "copilot" | "devin" | "antigravity" | (string & {});
67
+ type AgentChatSessionStatus = "active" | "idle" | "ended";
68
+ type AgentChatPermissionMode = "default" | "auto" | "plan" | "edit" | "full-auto" | "config-toml";
69
+ /**
70
+ * Which on-disk configuration layers a provider loads for a thread.
71
+ *
72
+ * `"none"` is the default for SDK threads and is what every 0.1.x thread got.
73
+ * The four values are sent verbatim; the engine decides what each one means per
74
+ * provider, and reports the answer on {@link AgentChatSessionSummary}.
75
+ */
76
+ type AgentChatSettingSources = "none" | "project" | "user" | "all";
77
+ /**
78
+ * How completely a provider honoured a host configuration request.
79
+ *
80
+ * The same three-value vocabulary the MCP report uses, for the same reason:
81
+ * four of the six providers cannot do the thing exactly, and a report that said
82
+ * only "applied" would be a lie for most embedders.
83
+ *
84
+ * - `"applied"` — the provider received the value through a first-class
85
+ * channel of its own.
86
+ * - `"best-effort"` — DAEX reached the same outcome through a mechanism it
87
+ * already owns (a prompt prefix, a containment root), and `detail` names
88
+ * what that costs.
89
+ * - `"ignored"` — the provider has no switch for it and the value did not
90
+ * reach the model. `detail` says so.
91
+ */
92
+ type AgentChatHostConfigLevel = "applied" | "best-effort" | "ignored";
93
+ /**
94
+ * What the provider could actually do with a caller's MCP request.
95
+ *
96
+ * Mirrors `AgentChatMcpCapability` in chat.ts. Only DAEX's Claude adapter can
97
+ * enforce strict mode outright; the rest are best-effort with a named residual,
98
+ * and Pi has no MCP surface at all (a thread that asks for `mcpServers` on Pi
99
+ * is refused by the runtime rather than silently opened without them).
100
+ *
101
+ * Read `strictRequested` FIRST, then `level`. `level` and `residual` describe
102
+ * strict mode, so they only make a claim when strict mode was requested; on a
103
+ * delivery-only thread (`loadUserMcpServers: true`) the user's own config loads
104
+ * by design and no level value means "only my tools are loaded".
105
+ *
106
+ * Given `strictRequested`, `level` is the field to branch on, and `"enforced"`
107
+ * is the ONLY value that means "nothing but the servers I supplied". Treating
108
+ * `"best-effort"` as a synonym is the mistake this type exists to prevent —
109
+ * four of the six providers report it, so an embedder that branches on
110
+ * truthiness rather than on the level will overpromise for most of its users.
111
+ *
112
+ * Surface `residual` when it is non-null: "your servers are loaded, and so is
113
+ * X" is a materially different guarantee from "only yours". The residual text
114
+ * comes from the provider adapter and names the specific leak, so it is safe
115
+ * to show verbatim.
116
+ */
117
+ type McpCapabilityReport = {
118
+ /**
119
+ * What strict mode achieved — meaningful ONLY when `strictRequested` is true.
120
+ * Read that field first.
121
+ */
122
+ level: "enforced" | "best-effort" | "unsupported";
123
+ /**
124
+ * How the provider implemented the request, for logs and support threads.
125
+ *
126
+ * Describes ENFORCEMENT when `strictRequested` is true, and DELIVERY (how the
127
+ * supplied servers were handed to the provider) when it is false.
128
+ */
129
+ mechanism: string;
130
+ /**
131
+ * What strict mode could NOT exclude, or null when nothing leaked through.
132
+ *
133
+ * Always null when `strictRequested` is false: nothing was asked to be
134
+ * excluded, so nothing leaked.
135
+ */
136
+ residual: string | null;
137
+ /**
138
+ * Whether this thread asked DAEX to withhold the user's and project's own MCP
139
+ * config — i.e. `loadUserMcpServers: false`, explicitly or by supplying
140
+ * `mcpServers` without opting back in.
141
+ *
142
+ * THE FIRST FIELD TO READ. When it is false the caller asked for delivery
143
+ * only: the user's own MCP config loads by design, and `level` makes no
144
+ * isolation claim at all — treating `level === "enforced"` as "only my tools
145
+ * are loaded" on a delivery-only thread would be exactly backwards.
146
+ *
147
+ * An older runtime that predates the field omits it, and the SDK reports
148
+ * false rather than guessing. That is the conservative direction: it
149
+ * understates isolation instead of promising one that was never verified.
150
+ */
151
+ strictRequested: boolean;
152
+ /**
153
+ * False when the provider has no MCP surface and supplied servers were
154
+ * dropped.
155
+ *
156
+ * PREFER `level`. On a current runtime this is effectively always true —
157
+ * `create` refuses the only case that would make it false — so branching on
158
+ * it tells you nothing that `level` does not tell you better. It is retained
159
+ * because it is part of the published shape, not because it is useful.
160
+ *
161
+ * Older runtimes additionally returned false for a strict-only request
162
+ * (strict mode with no servers) that had in fact been enforced, which made
163
+ * `!delivered` read a success as a failure. Anything keyed on this field
164
+ * against a pre-fix runtime is suspect; `level === "unsupported"` is the
165
+ * check that was always correct.
166
+ */
167
+ delivered: boolean;
168
+ };
169
+ /**
170
+ * File attachment reference accepted by `send` and `steer`.
171
+ *
172
+ * Only the path crosses the wire; bytes never do. The runtime reads the file
173
+ * itself, on the host machine, when the provider needs its contents.
174
+ *
175
+ * WHERE THE PATH MAY LIVE. The runtime resolves an attachment against the
176
+ * thread's working directory and refuses an absolute path it cannot place, so
177
+ * a send whose attachment names a file outside what the runtime accepts throws
178
+ * rather than dropping the file quietly. Pass paths the host obtained from its
179
+ * own file dialog or drop handler, not strings a model produced.
180
+ */
181
+ type AgentChatFileRef = {
182
+ path: string;
183
+ name?: string;
184
+ mimeType?: string;
185
+ bytes?: number;
186
+ /**
187
+ * How the provider receives the file.
188
+ *
189
+ * `"image"` sends the bytes as an image the model can see (Claude and Codex
190
+ * both take image input). `"file"` sends a path hint the model can open with
191
+ * its own tools. When absent, the SDK fills it in before sending with the
192
+ * runtime's own rule, exported as `inferAttachmentType(path, mimeType)`: any
193
+ * `image/*` `mimeType` is an image; otherwise the extension of `path`
194
+ * decides (`.bmp .gif .heic .heif .ico .jpeg .jpg .png .svg .tif .tiff
195
+ * .webp` are images), and everything else is `"file"`. Before 0.3 the field
196
+ * did not exist and every image arrived as a path hint.
197
+ */
198
+ type?: "file" | "image";
199
+ /**
200
+ * Whether the runtime may read the file's bytes. Defaults to true.
201
+ *
202
+ * `false` is REFERENCE-ONLY: the runtime never opens the file, never copies
203
+ * it to a staging directory, and hands the model the path alone — even for an
204
+ * image. Use it for files that must not be downloaded as a side effect, such
205
+ * as a macOS File Provider placeholder, where reading the bytes hydrates the
206
+ * whole file from the cloud.
207
+ *
208
+ * An older runtime ignores the field and reads the bytes as before; the SDK
209
+ * cannot detect that from here, so treat reference-only as a request until
210
+ * your runtime is at least the SDK's supported minimum
211
+ * (`SUPPORTED_RUNTIME_RANGE`).
212
+ */
213
+ hydrate?: boolean;
214
+ };
215
+ /**
216
+ * One transcript event. The `type` field is the discriminant; the remaining
217
+ * fields are provider- and type-specific and are preserved verbatim.
218
+ */
219
+ type AgentChatEvent = {
220
+ type: string;
221
+ [key: string]: unknown;
222
+ };
223
+ /**
224
+ * Which provider raised a pending input request.
225
+ *
226
+ * `"acp"` covers all four ACP dialects, because the permission round trip is
227
+ * one method there. `"ade"` is a request DAEX staged itself.
228
+ */
229
+ /**
230
+ * Who raised a pending input. The ACP harnesses (Qwen, Kimi, Grok, Copilot,
231
+ * Devin, Antigravity) all report `"acp"`, not their own name.
232
+ */
233
+ type PendingInputSource = "claude" | "codex" | "cursor" | "droid" | "opencode" | "pi" | "muse" | "acp" | "ade";
234
+ /**
235
+ * What the provider is asking for.
236
+ *
237
+ * `"approval"` and `"permissions"` are the two approval-shaped kinds — a
238
+ * yes/no on an action the model wants to take. The other four want prose or a
239
+ * choice, and `DaexThread.approve` cannot answer them: render them read-only.
240
+ */
241
+ declare const PENDING_INPUT_KINDS: readonly ["approval", "question", "structured_question", "permissions", "plan_approval", "model_selection"];
242
+ type PendingInputKind = (typeof PENDING_INPUT_KINDS)[number];
243
+ type PendingInputOption = {
244
+ label: string;
245
+ value: string;
246
+ description?: string;
247
+ recommended?: boolean;
248
+ preview?: string;
249
+ previewFormat?: "markdown" | "html";
250
+ };
251
+ type PendingInputQuestion = {
252
+ id: string;
253
+ header?: string;
254
+ question: string;
255
+ options?: PendingInputOption[] | null;
256
+ multiSelect?: boolean;
257
+ allowsFreeform?: boolean;
258
+ isSecret?: boolean;
259
+ defaultAssumption?: string | null;
260
+ impact?: string | null;
261
+ };
262
+ /**
263
+ * One unresolved request the provider is blocked on.
264
+ *
265
+ * Mirrors `PendingInputRequest` in chat.ts. Returned by the `pendingInputs`
266
+ * action and mapped to the SDK's {@link ApprovalRequest} shape before it
267
+ * reaches a caller.
268
+ */
269
+ type PendingInputRequest = {
270
+ requestId: string;
271
+ itemId?: string;
272
+ source: PendingInputSource;
273
+ kind: PendingInputKind;
274
+ title?: string | null;
275
+ description?: string | null;
276
+ questions: PendingInputQuestion[];
277
+ allowsFreeform: boolean;
278
+ blocking: boolean;
279
+ canProceedWithoutAnswer: boolean;
280
+ options?: PendingInputOption[];
281
+ providerMetadata?: Record<string, unknown>;
282
+ autoResolutionMs?: number | null;
283
+ turnId?: string | null;
284
+ };
285
+ /** The stop modes personal-chat callers can request. */
286
+ type AgentChatStopMode = "stop_only" | "stop_and_clear" | "stop_and_background" | "stop_and_clear_and_background" | "stop_and_clear_and_children" | "stop_everything_and_children";
287
+ type AgentChatRecoverTurnArgs = {
288
+ sessionId: string;
289
+ turnId: string;
290
+ action: "wait" | "nudge" | "retry_same_runtime" | "restart_resume";
291
+ };
292
+ type AgentChatResolveUnprocessedMessageArgs = {
293
+ sessionId: string;
294
+ steerId: string;
295
+ action: "run_next" | "dismiss";
296
+ };
297
+ type AgentChatRespondToInputArgs = {
298
+ sessionId: string;
299
+ itemId: string;
300
+ decision?: "accept" | "accept_for_session" | "decline" | "cancel";
301
+ answers?: Record<string, string | string[]>;
302
+ responseText?: string | null;
303
+ };
304
+ type AgentChatSlashCommand = {
305
+ name: string;
306
+ description: string;
307
+ argumentHint?: string;
308
+ source: "sdk" | "local";
309
+ kind?: "command" | "skill" | "mcp";
310
+ origin?: "project" | "user" | "plugin" | "provider";
311
+ server?: string;
312
+ };
313
+ type AgentChatRecoverTurnResult = {
314
+ action: AgentChatRecoverTurnArgs["action"];
315
+ turnId: string;
316
+ status: "waiting" | "nudged" | "retrying" | "resumed";
317
+ };
318
+ type AgentChatResolveUnprocessedMessageResult = {
319
+ steerId: string;
320
+ action: AgentChatResolveUnprocessedMessageArgs["action"];
321
+ status: "completed" | "already_completed";
322
+ replacementMessageId?: string;
323
+ };
324
+ type AgentChatSwitchAccountResult = {
325
+ ok: true;
326
+ instanceId: string;
327
+ } | {
328
+ ok: false;
329
+ reason: "busy" | "signed_out" | "failed";
330
+ message: string;
331
+ };
332
+ type AgentChatUsageLimitResult = {
333
+ ok: true;
334
+ turnId: string | null;
335
+ } | {
336
+ ok: true;
337
+ sessionId: string;
338
+ } | {
339
+ ok: false;
340
+ reason: string;
341
+ message: string;
342
+ };
343
+ /** Runtime-derived controls available for a provider. */
344
+ type ProviderCapabilities = {
345
+ permissionModes: AgentChatPermissionMode[];
346
+ reasoningEfforts: string[];
347
+ fastMode: boolean;
348
+ multipleAccounts: boolean;
349
+ signIn: "cli-login" | "device-code" | "api-key" | "none";
350
+ apiKeys: boolean;
351
+ presets: boolean;
352
+ mcp: "full" | "partial" | "none";
353
+ };
354
+ /**
355
+ * A thread's usage-limit state, as the runtime publishes it on
356
+ * `session_meta_updated.usageLimitResume` (a copy of
357
+ * `AgentChatUsageLimitResume`). The runtime republishes the whole value on
358
+ * every transition and sends null when the limit clears.
359
+ */
360
+ type UsageLimitResume = {
361
+ state: "armed" | "resuming" | "paused" | "opted_out" | "no_reset" | (string & {});
362
+ provider: DaexProvider;
363
+ /** When the resume prompt is sent (reset + buffer). Null when unknown. */
364
+ fireAt: string | null;
365
+ /** The reset the provider published. Null when unknown. */
366
+ resetAt: string | null;
367
+ /** Turn that hit the limit. */
368
+ turnId: string | null;
369
+ updatedAt: string;
370
+ /** Another signed-in account with room, chosen by the runtime. */
371
+ alternateAccount?: {
372
+ instanceId: string;
373
+ label: string;
374
+ } | null;
375
+ [key: string]: unknown;
376
+ };
377
+ /** The client `usageLimit` event: one thread's limit state changed. */
378
+ type UsageLimitEvent = {
379
+ /** Thread key; empty when the session is not one this client opened by key. */
380
+ key: string;
381
+ sessionId: string;
382
+ provider: DaexProvider;
383
+ /** The current state, or null when the limit cleared. */
384
+ status: UsageLimitResume | null;
385
+ };
386
+ /**
387
+ * The four capability reports a thread carries, as one object.
388
+ *
389
+ * Returned by `setModel` and carried by `capabilities_changed`. Each report
390
+ * keeps its own null rule — see the matching field on `DaexThread`.
391
+ */
392
+ type ThreadCapabilities = {
393
+ mcpCapability: McpCapabilityReport | null;
394
+ permissionCapability: PermissionCapability | null;
395
+ instructionsCapability: InstructionsCapability | null;
396
+ settingSourcesCapability: SettingSourcesCapability | null;
397
+ };
398
+ /**
399
+ * What a thread's model resolved to, as the runtime reports it.
400
+ *
401
+ * The runtime resolves aliases, CLI-wrapped ids, and ids a CLI update retired,
402
+ * so this can differ from the id the host passed. Render `displayName` rather
403
+ * than the raw id whenever it is non-null.
404
+ */
405
+ type ThreadModelSelection = {
406
+ /** Catalog model id now bound to the thread. */
407
+ modelId: string;
408
+ /** Provider group that id resolved into — authoritative, not inferred. */
409
+ provider: string;
410
+ /** Provider-native model token. */
411
+ model: string;
412
+ /**
413
+ * The catalog's display name for `modelId`, or null when the catalog does
414
+ * not list it (a retired model, or a catalog that has not loaded).
415
+ */
416
+ displayName: string | null;
417
+ };
418
+ /**
419
+ * One page of a thread's durable transcript, newest page first.
420
+ *
421
+ * Returned by `DaexThread.historyPage`. `events` are in transcript order
422
+ * (oldest first) within the page.
423
+ */
424
+ type ThreadHistoryPage = {
425
+ events: AgentChatEventEnvelope[];
426
+ /** True when older events exist before this page. */
427
+ hasMore: boolean;
428
+ /**
429
+ * Pass as `beforeSequence` to read the page before this one. Null when
430
+ * `hasMore` is false — including the case where the transcript's envelopes
431
+ * carry no `sequence`, which cannot be paged by sequence at all.
432
+ */
433
+ nextBeforeSequence: number | null;
434
+ };
435
+ type AgentChatEventEnvelope = {
436
+ sessionId: string;
437
+ timestamp: string;
438
+ event: AgentChatEvent;
439
+ sequence?: number;
440
+ /**
441
+ * Mirrors `AgentChatEventEnvelope["provenance"]` in DAEX's `shared/types/chat.ts`,
442
+ * NARROWED on purpose: only the keys an SDK consumer can act on are named.
443
+ *
444
+ * DAEX stamps more than this — orchestration routing (`targetKind`,
445
+ * `sourceSessionId`, `attemptId`, `stepKey`, `laneId`, `runId`), fork shape
446
+ * (`replayFork`), and other DAEX-only metadata. These describe surfaces this
447
+ * package does not have: a sidecar drives its own thread with the `agent`
448
+ * role, so it is never the orchestrator reading routing keys or DAEX metadata.
449
+ * Naming them here would advertise surfaces that do not exist.
450
+ *
451
+ * The index signature is what makes that narrowing safe rather than lossy:
452
+ * the runtime is downloaded and can be newer than the SDK, so every key DAEX
453
+ * stamps still arrives and still reads, typed `unknown`. Add a key to the
454
+ * named set only when this package grows a use for it.
455
+ */
456
+ provenance?: {
457
+ messageId?: string;
458
+ providerMessageId?: string;
459
+ threadId?: string | null;
460
+ role?: "user" | "orchestrator" | "worker" | "agent" | null;
461
+ [key: string]: unknown;
462
+ };
463
+ };
464
+ /** Flattened, SDK-facing model row. */
465
+ type ModelCatalogEntry = {
466
+ /** Canonical DAEX registry id — this is what `ThreadOpenOptions.model` takes. */
467
+ id: string;
468
+ displayName: string;
469
+ /**
470
+ * The provider group this model belongs to. One of the six
471
+ * {@link DaexProvider} values for every model this SDK can open a thread on;
472
+ * typed open because the runtime's catalog is downloaded and can list a
473
+ * provider group newer than this SDK.
474
+ *
475
+ * Because it is open, `ThreadOpenOptions.provider` (typed `DaexProvider`) will
476
+ * not take it without narrowing. Narrow it with `isSupportedProvider` — an
477
+ * SDK export since 0.4 — rather than a cast:
478
+ *
479
+ * if (!isSupportedProvider(entry.provider)) return;
480
+ * daex.threads.open(key, { provider: entry.provider, model: entry.id });
481
+ */
482
+ provider: DaexProvider | (string & {});
483
+ /** Provider-native model ref DAEX sends under the hood. */
484
+ runtimeModelId: string;
485
+ isDefault: boolean;
486
+ isAvailable: boolean;
487
+ connected: boolean;
488
+ requiresConfiguration: boolean;
489
+ reasoningEfforts: string[];
490
+ defaultReasoningEffort: string | null;
491
+ description: string | null;
492
+ };
493
+ /**
494
+ * Per-provider installation, authentication and availability roll-up.
495
+ *
496
+ * READ `source` FIRST. It is the field that says how much the rest of the
497
+ * record is worth:
498
+ *
499
+ * - `"probed"` — the runtime resolved the binary the provider would actually
500
+ * spawn, ran `--version`, and looked at the credential files the CLI itself
501
+ * uses. `installed`, `binaryPath`, `version` and `authenticated` are real
502
+ * measurements.
503
+ * - `"derived"` — the runtime is older than the `providers.status` RPC, so
504
+ * everything here comes from the model catalog. `installed` is
505
+ * `modelCount > 0`, the three probe fields are null, and a UI should say
506
+ * "not detected" rather than "not installed".
507
+ */
508
+ type ProviderStatus = {
509
+ provider: string;
510
+ displayName: string;
511
+ /**
512
+ * A usable binary or package was found.
513
+ *
514
+ * On a derived record this is `modelCount > 0`, which answers a different
515
+ * question — "does DAEX know models for this provider" — so do not present it
516
+ * as a filesystem fact unless `source` is `"probed"`.
517
+ */
518
+ installed: boolean;
519
+ /** Absolute path the runtime would spawn. Null when not found or derived. */
520
+ binaryPath: string | null;
521
+ /** Verbatim first line of `--version`. Null on a timeout, or when derived. */
522
+ version: string | null;
523
+ /**
524
+ * Credentials the CLI can use were found.
525
+ *
526
+ * On a probed record this is a credential-file check. On a derived one it
527
+ * means "the catalog resolved at least one connected model", which a stale
528
+ * catalog can report after the credential expired — `stale` carries that.
529
+ */
530
+ authenticated: boolean;
531
+ /** How, when the probe could tell: subscription, api-key, oauth, unknown. */
532
+ authMethod?: string | null;
533
+ /** Remediation DAEX supplies. Null on a derived record. */
534
+ installCommand: string | null;
535
+ loginCommand: string | null;
536
+ docsUrl: string | null;
537
+ /** True when at least one model is usable right now. */
538
+ available: boolean;
539
+ /** True when every usable path needs setup first. */
540
+ requiresConfiguration: boolean;
541
+ modelCount: number;
542
+ /**
543
+ * True when something behind this verdict was served from the cache rather
544
+ * than probed on this call: a cached model catalog, or a cached probe record.
545
+ * It does not mean the record is past the runtime's TTL — a record inside the
546
+ * TTL is served from the cache and is stale by this definition.
547
+ */
548
+ stale: boolean;
549
+ /** How this record was produced. Read this before trusting the rest. */
550
+ source: "probed" | "derived";
551
+ /** ISO timestamp of the probe, or of the derivation. */
552
+ checkedAt: string;
553
+ /** Human-readable note from the probe, when it had one. */
554
+ detail?: string | null;
555
+ /** Provider controls, present only when the runtime advertises them. */
556
+ capabilities?: ProviderCapabilities;
557
+ /** Config-home isolation used by this runtime, when it can report it. */
558
+ isolation?: "isolated" | "shared";
559
+ };
560
+ type ThreadSummary = {
561
+ /** Stable caller-chosen key. Null for chats created outside the SDK. */
562
+ key: string | null;
563
+ sessionId: string;
564
+ provider: string;
565
+ model: string;
566
+ title: string | null;
567
+ status: AgentChatSessionStatus;
568
+ startedAt: string;
569
+ lastActivityAt: string;
570
+ /** The same instant as `lastActivityAt`, under the name list UIs sort by. */
571
+ updatedAt: string;
572
+ archived: boolean;
573
+ /**
574
+ * What the thread's model resolved to, with the catalog's display name.
575
+ * Null when the runtime reported no model at all.
576
+ */
577
+ modelSelection: ThreadModelSelection | null;
578
+ };
579
+ type DoctorReport = {
580
+ ok: boolean;
581
+ /**
582
+ * Version of this SDK package. Reported alongside the runtime version
583
+ * because a mismatched pair is the first thing to check when an embedder's
584
+ * chat misbehaves: the two ship on separate cadences, and the SDK is the
585
+ * half that lives inside the embedder's own build.
586
+ */
587
+ sdkVersion: string;
588
+ binary: {
589
+ path: string;
590
+ /** Version string reported by `<binary> --version`, when it answered. */
591
+ version: string | null;
592
+ source: "option" | "path" | "download" | "cache";
593
+ /**
594
+ * Whether THIS client verified the binary against a published SHA256SUMS.
595
+ *
596
+ * False is not an accusation — a caller-supplied `binaryPath`, an `ade`
597
+ * found on PATH, and a reuse of an earlier download are all unverified by
598
+ * this client because it did not fetch them. It is only meaningful as
599
+ * "provenance was checked here", which is what an operator wants to know
600
+ * when auditing where the running binary came from.
601
+ */
602
+ checksumVerified: boolean;
603
+ };
604
+ /**
605
+ * Runtime provenance: which of the five resolution steps produced the binary,
606
+ * where its native modules came from, and whether the OS considers it signed.
607
+ *
608
+ * `binary` above is the 0.1.x view and keeps its four `source` values.
609
+ * `source` and `signature` here are the two fields to put in a support
610
+ * bundle: together they separate "the app is running the runtime we signed
611
+ * and shipped" from "the app quietly downloaded one on this machine", which
612
+ * is the difference an embedder cannot otherwise see.
613
+ */
614
+ runtime: {
615
+ /**
616
+ * `"packaged"` is an explicit runtime whose options came from
617
+ * `resolvePackagedRuntime()` — the copy inside the host's own signed app
618
+ * bundle. `"explicit"` is any other caller-pinned `binaryPath`.
619
+ */
620
+ source: "explicit" | "packaged" | "bundled-package" | "cached-download" | "path" | "downloaded" | "attached";
621
+ binaryPath: string;
622
+ version: string | null;
623
+ /** `ADE_RUNTIME_ROOT` as spawned, or null when the install carries its own. */
624
+ runtimeRoot: string | null;
625
+ /** `ADE_RUNTIME_NODE_MODULES` as spawned. */
626
+ nodeModulesPath: string | null;
627
+ /**
628
+ * macOS and Windows only. Null on Linux, in attach mode, and whenever the
629
+ * check could not run — "not known", never "not signed".
630
+ *
631
+ * `accepted` on macOS is Gatekeeper's verdict on the outermost `.app` the
632
+ * runtime is embedded in (a nested binary assessed alone is always
633
+ * "rejected" as not an app), and null when it cannot be judged. Only
634
+ * `accepted: false` means the OS refused it.
635
+ */
636
+ signature: {
637
+ signed: boolean;
638
+ authority?: string;
639
+ accepted?: boolean | null;
640
+ } | null;
641
+ /** True only when THIS client downloaded a runtime during its lifetime. */
642
+ downloadedThisSession: boolean;
643
+ checksumVerified: boolean;
644
+ /**
645
+ * Whether the runtime's self-reported version is inside the range this SDK
646
+ * supports (`SUPPORTED_RUNTIME_RANGE`).
647
+ *
648
+ * An unsupported runtime still connects: features it lacks are detected
649
+ * and degrade with a logged line. Pass `requireCompatibleRuntime: true` to
650
+ * `createDaexChat` to refuse it instead. A dev build (`0.0.0`, or no version
651
+ * at all) counts as supported and says so in `note`.
652
+ */
653
+ compatibility: RuntimeCompatibility;
654
+ };
655
+ socket: {
656
+ path: string;
657
+ connected: boolean;
658
+ /** Runtime info from the `ade/initialize` result, when the runtime sent it. */
659
+ runtimeVersion: string | null;
660
+ pid: number | null;
661
+ };
662
+ events: {
663
+ mode: "push" | "drain" | "unavailable";
664
+ /** Buffer epoch last observed; a change means the runtime restarted. */
665
+ epoch: string | null;
666
+ gapsRecovered: number;
667
+ };
668
+ providers: Record<string, ProviderStatus>;
669
+ logins: {
670
+ mode: "isolated" | "machine" | "attached";
671
+ perProvider: Record<string, "isolated" | "shared" | "unknown">;
672
+ };
673
+ threads: {
674
+ tracked: number;
675
+ live: number;
676
+ };
677
+ /** Most recent errors the client recorded, newest last. Capped. */
678
+ recentErrors: Array<{
679
+ at: string;
680
+ scope: string;
681
+ message: string;
682
+ }>;
683
+ };
684
+ /** The result of comparing a runtime's version with `SUPPORTED_RUNTIME_RANGE`. */
685
+ type RuntimeCompatibility = {
686
+ supported: boolean;
687
+ /** The range this SDK build supports, e.g. `">=1.2.81 <2.0.0"`. */
688
+ range: string;
689
+ /** What the runtime reported on `ade/initialize`, or null when it sent none. */
690
+ version: string | null;
691
+ /** Why a version counted as supported without being checked, when it did. */
692
+ note: string | null;
693
+ };
694
+ type Unsubscribe = () => void;
695
+
696
+ /**
697
+ * The client-level lifecycle events, in one dependency-free module.
698
+ *
699
+ * Kept apart from `client.ts` so the Electron protocol (which the sandboxed
700
+ * preload bundles) can key its payload type by this map without importing the
701
+ * client, and so the event list exists exactly once: `DaexChatClient.on`
702
+ * validates against it, the Electron bridge subscribes to every name in it,
703
+ * and the IPC payload type is derived from it.
704
+ */
705
+ /**
706
+ * Payloads of the client-level events, by name.
707
+ *
708
+ * These are about the RUNTIME, not about any one thread. A thread learns that
709
+ * its runtime died from the synthetic `status` envelope on its own `status`
710
+ * channel; a host learns it here, once.
711
+ */
712
+ type DaexClientEventMap = {
713
+ /**
714
+ * The runtime process this client spawned exited without `dispose()`.
715
+ * `error` is the tail of its stderr, when it wrote any. Not emitted in attach
716
+ * mode, where the client owns no process — watch `transport` there.
717
+ */
718
+ exit: {
719
+ code: number | null;
720
+ signal: string | null;
721
+ error: string | null;
722
+ };
723
+ /**
724
+ * The socket to the runtime closed unexpectedly (`"closed"`), or an
725
+ * `autoRestart` brought it back (`"reconnected"`).
726
+ */
727
+ transport: {
728
+ state: "closed" | "reconnected";
729
+ error: string | null;
730
+ };
731
+ /**
732
+ * One `autoRestart` attempt finished. `attempt` counts from 1 per outage.
733
+ * `final` is true when no further attempt follows for this outage: the
734
+ * attempt succeeded (`ok: true`), or it failed and was the last one
735
+ * `maxAttempts` allows (the client gave up; the runtime stays down until the
736
+ * host creates a new client). SDK >= 0.4.
737
+ */
738
+ restart: {
739
+ attempt: number;
740
+ ok: boolean;
741
+ error: string | null;
742
+ final: boolean;
743
+ };
744
+ /**
745
+ * A thread left, or came back to, the host's active list through this
746
+ * client: `threads.delete` (`"deleted"`), `threads.archive` (`"archived"`)
747
+ * or `threads.unarchive` (`"unarchived"`). Emitted after the action
748
+ * succeeds, whoever called it: host code in the main process, or a renderer
749
+ * over the Electron bridge. A change made by another client of the same
750
+ * runtime (DAEX desktop) is not reported. SDK >= 0.4.
751
+ */
752
+ threadLifecycle: {
753
+ key: string;
754
+ change: "deleted" | "archived" | "unarchived";
755
+ };
756
+ /** A provider turn stopped because its current account reached a usage limit. */
757
+ usageLimit: UsageLimitEvent;
758
+ };
759
+ /** Every client-level event name, once. See {@link DaexClientEventMap}. */
760
+ declare const DAEX_CLIENT_EVENTS: readonly ["exit", "transport", "restart", "threadLifecycle", "usageLimit"];
761
+ /** The client-level event names. See {@link DaexClientEventMap}. */
762
+ type DaexClientEvent = (typeof DAEX_CLIENT_EVENTS)[number];
763
+
764
+ /**
765
+ * The wire contract shared by the three Electron entry points.
766
+ *
767
+ * NO ELECTRON IMPORT, EVER. This package does not depend on `electron` at
768
+ * build time or at run time, so every Electron object it touches is described
769
+ * here as a structural interface. An embedder passes the real `ipcMain`,
770
+ * `ipcRenderer` and `contextBridge`; TypeScript accepts them because they have
771
+ * the members below, and the SDK never has to agree with the host on an
772
+ * Electron version.
773
+ *
774
+ * This module also has NO VALUE IMPORTS of its own. The preload bundle inlines
775
+ * it, and a preload that runs under `sandbox: true` cannot resolve modules at
776
+ * all, so anything that reaches it must be self-contained.
777
+ */
778
+
779
+ /** Channel namespace. A host that runs two bridges gives each its own prefix. */
780
+ declare const DAEX_DEFAULT_CHANNEL_PREFIX = "ade";
781
+ /** Default `window` key the preload exposes the bridge under. */
782
+ declare const DAEX_DEFAULT_BRIDGE_KEY = "ade";
783
+ /** The `ipcRenderer` members the preload uses. */
784
+ interface IpcRendererLike {
785
+ invoke(channel: string, ...args: any[]): Promise<any>;
786
+ on(channel: string, listener: (event: any, ...args: any[]) => void): unknown;
787
+ removeListener(channel: string, listener: (event: any, ...args: any[]) => void): unknown;
788
+ }
789
+ /** The `contextBridge` members the preload uses. */
790
+ interface ContextBridgeLike {
791
+ exposeInMainWorld(key: string, api: unknown): void;
792
+ }
793
+ /**
794
+ * A failure, flattened so it survives structured clone.
795
+ *
796
+ * `ipcMain.handle` rejections reach the renderer as a plain `Error` whose
797
+ * message has been rewritten, which loses `DaexError.code` — the one field an
798
+ * embedder branches on. So the handler never rejects: it resolves with this
799
+ * envelope and the renderer rebuilds a real `DaexError`.
800
+ */
801
+ type DaexIpcErrorPayload = {
802
+ __adeError: true;
803
+ name: "AdeError";
804
+ code: string;
805
+ message: string;
806
+ };
807
+ type DaexIpcInvokeResponse<T = unknown> = {
808
+ ok: true;
809
+ value: T;
810
+ } | {
811
+ ok: false;
812
+ error: DaexIpcErrorPayload;
813
+ };
814
+ /** A pushed envelope for one thread subscription. */
815
+ type DaexIpcThreadEvent = {
816
+ kind: "thread";
817
+ subscriptionId: string;
818
+ key: string;
819
+ envelope: AgentChatEventEnvelope;
820
+ };
821
+ /** A pushed provider-status snapshot for one `providers.onChange` subscription. */
822
+ type DaexIpcProvidersEvent = {
823
+ kind: "providers";
824
+ subscriptionId: string;
825
+ statuses: Record<string, ProviderStatus>;
826
+ };
827
+ /**
828
+ * A pushed runtime lifecycle event for one `client.subscribe` subscription.
829
+ *
830
+ * `event` and `payload` are exactly what `DaexChatClient.on` delivers in the
831
+ * main process: a union keyed by `DaexClientEventMap`, so narrowing on `event`
832
+ * types `payload`. One subscription carries every event name; the renderer
833
+ * client splits them.
834
+ */
835
+ type DaexIpcClientEvent = {
836
+ [E in DaexClientEvent]: {
837
+ kind: "client";
838
+ subscriptionId: string;
839
+ event: E;
840
+ payload: DaexClientEventMap[E];
841
+ };
842
+ }[DaexClientEvent];
843
+ type DaexIpcEventPayload = DaexIpcThreadEvent | DaexIpcProvidersEvent | DaexIpcClientEvent;
844
+ /**
845
+ * What the preload puts on `window[key]`.
846
+ *
847
+ * Functions and plain data only. Nothing structured-cloned across
848
+ * `contextBridge` keeps its prototype, so the renderer receives an id plus
849
+ * functions and rebuilds every object shape on its own side.
850
+ */
851
+ type DaexBridge = {
852
+ invoke(method: string, args: unknown[]): Promise<DaexIpcInvokeResponse>;
853
+ onEvent(listener: (payload: DaexIpcEventPayload) => void): () => void;
854
+ };
855
+ /**
856
+ * The de-duplication key `@daex-dev/chat-ui` documents.
857
+ *
858
+ * History and the live stream overlap by design — an envelope emitted while
859
+ * `history()` is in flight legitimately appears in both — so both sides key on
860
+ * exactly this string and the overlap collapses instead of double-rendering.
861
+ */
862
+ declare function envelopeDedupeKey(envelope: AgentChatEventEnvelope,
863
+ /**
864
+ * How many earlier envelopes IN THE SAME ARRAY already produced this exact
865
+ * key. Zero, and omitted, for the ordinary case.
866
+ *
867
+ * `sequence` is optional on the wire, and without it two `text` deltas in the
868
+ * same millisecond produce one key and the second is dropped — a hole in the
869
+ * transcript on a fast stream from a runtime that does not number its
870
+ * envelopes. An occurrence index fixes that WITHOUT breaking the overlap
871
+ * collapse this key exists for: history and the live buffer are counted
872
+ * separately, so one envelope appearing in both is the first occurrence in
873
+ * each and the two still meet on one key, while two genuinely distinct
874
+ * deltas inside one array do not.
875
+ *
876
+ * BRIDGE-LOCAL. It means nothing outside the array it was counted in, which
877
+ * is why `@daex-dev/chat-ui`'s mirror of this key does not carry it.
878
+ */
879
+ occurrence?: number): string;
880
+ /**
881
+ * Envelope order: numbered envelopes first, then `sequence`, then `timestamp`.
882
+ *
883
+ * Mirrors `sortEnvelopes` in `@daex-dev/chat-ui`. Provider clocks are not
884
+ * trusted, which is why `sequence` wins whenever an envelope carries one. Two
885
+ * envelopes with neither compare equal and a stable sort leaves them in
886
+ * arrival order.
887
+ */
888
+ declare function compareEnvelopes(a: AgentChatEventEnvelope, b: AgentChatEventEnvelope): number;
889
+ /**
890
+ * Merge a history page with the live envelopes buffered while it was in flight.
891
+ *
892
+ * Each envelope is delivered once, in envelope order. This is the rule the
893
+ * chat-ui README states in prose; keeping it in code means an embedder inherits
894
+ * it instead of re-reading the paragraph.
895
+ */
896
+ declare function mergeHistoryWithBuffer(history: AgentChatEventEnvelope[], buffered: AgentChatEventEnvelope[]): AgentChatEventEnvelope[];
897
+ /** @deprecated Use {@link DAEX_DEFAULT_BRIDGE_KEY}. */
898
+ declare const ADE_DEFAULT_BRIDGE_KEY = "ade";
899
+ /** @deprecated Use {@link DAEX_DEFAULT_CHANNEL_PREFIX}. */
900
+ declare const ADE_DEFAULT_CHANNEL_PREFIX = "ade";
901
+ /** @deprecated Use {@link DaexBridge}. */
902
+ type AdeBridge = DaexBridge;
903
+
904
+ export { type AdeBridge as A, compareEnvelopes as B, type ContextBridgeLike as C, type DaexBridge as D, envelopeDedupeKey as E, mergeHistoryWithBuffer as F, type IpcRendererLike as I, type ModelCatalogEntry as M, type PendingInputKind as P, type SettingSourcesCapability as S, type ThreadModelSelection as T, type Unsubscribe as U, ADE_DEFAULT_BRIDGE_KEY as a, ADE_DEFAULT_CHANNEL_PREFIX as b, DAEX_DEFAULT_BRIDGE_KEY as c, DAEX_DEFAULT_CHANNEL_PREFIX as d, type DaexProvider as e, type PendingInputRequest as f, type AgentChatFileRef as g, type AgentChatStopMode as h, type AgentChatRespondToInputArgs as i, type ThreadCapabilities as j, type ProviderStatus as k, type ProviderCapabilities as l, type McpCapabilityReport as m, type InstructionsCapability as n, type PermissionCapability as o, type AgentChatSlashCommand as p, type AgentChatRecoverTurnResult as q, type AgentChatResolveUnprocessedMessageResult as r, type AgentChatUsageLimitResult as s, type AgentChatSwitchAccountResult as t, type AgentChatEventEnvelope as u, type ThreadHistoryPage as v, type ThreadSummary as w, type DoctorReport as x, type DaexClientEvent as y, type DaexClientEventMap as z };