@daex-dev/sdk 0.0.0-stage → 0.7.1

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,510 @@
1
+ import { A as AgentChatEventEnvelope, P as ProviderStatus, D as DaexClientEvent, a as DaexClientEventMap, T as ThreadModelSelection, M as McpCapabilityReport, I as InstructionsCapability, S as SettingSourcesCapability, b as PermissionCapability, c as DaexChatClient, d as ThreadSummary, e as ThreadOpenOptions, f as ThreadResumeOptions } from '../client-C0KQKP8O.js';
2
+ export { g as AdeError, h as AdeErrorCode, i as DaexError, j as DaexErrorCode } from '../client-C0KQKP8O.js';
3
+
4
+ /**
5
+ * The wire contract shared by the three Electron entry points.
6
+ *
7
+ * NO ELECTRON IMPORT, EVER. This package does not depend on `electron` at
8
+ * build time or at run time, so every Electron object it touches is described
9
+ * here as a structural interface. An embedder passes the real `ipcMain`,
10
+ * `ipcRenderer` and `contextBridge`; TypeScript accepts them because they have
11
+ * the members below, and the SDK never has to agree with the host on an
12
+ * Electron version.
13
+ *
14
+ * This module also has NO VALUE IMPORTS of its own. The preload bundle inlines
15
+ * it, and a preload that runs under `sandbox: true` cannot resolve modules at
16
+ * all, so anything that reaches it must be self-contained.
17
+ */
18
+
19
+ /** Channel namespace. A host that runs two bridges gives each its own prefix. */
20
+ declare const DAEX_DEFAULT_CHANNEL_PREFIX = "ade";
21
+ /** Default `window` key the preload exposes the bridge under. */
22
+ declare const DAEX_DEFAULT_BRIDGE_KEY = "ade";
23
+ /** `<prefix>:invoke` — one `ipcMain.handle` for every method. */
24
+ declare function invokeChannel(prefix: string): string;
25
+ /** `<prefix>:event` — main pushes here, to the owning `webContents` only. */
26
+ declare function eventChannel(prefix: string): string;
27
+ /**
28
+ * The `webContents` members the bridge uses.
29
+ *
30
+ * Listener parameters are `any[]` on purpose: Electron types `on` and `once` as
31
+ * a large overload set of literal event names, and a narrower structural type
32
+ * here would reject the real object rather than describe it.
33
+ */
34
+ interface WebContentsLike {
35
+ readonly id: number;
36
+ send(channel: string, ...args: any[]): void;
37
+ on(event: string, listener: (...args: any[]) => void): unknown;
38
+ once(event: string, listener: (...args: any[]) => void): unknown;
39
+ removeListener?(event: string, listener: (...args: any[]) => void): unknown;
40
+ off?(event: string, listener: (...args: any[]) => void): unknown;
41
+ isDestroyed(): boolean;
42
+ }
43
+ /** The `IpcMainInvokeEvent` members the bridge uses. */
44
+ interface IpcMainInvokeEventLike {
45
+ readonly sender: WebContentsLike;
46
+ }
47
+ /** The `ipcMain` members the bridge uses. */
48
+ interface IpcMainLike {
49
+ handle(channel: string, listener: (event: any, ...args: any[]) => unknown): void;
50
+ removeHandler(channel: string): void;
51
+ }
52
+ /** The `ipcRenderer` members the preload uses. */
53
+ interface IpcRendererLike {
54
+ invoke(channel: string, ...args: any[]): Promise<any>;
55
+ on(channel: string, listener: (event: any, ...args: any[]) => void): unknown;
56
+ removeListener(channel: string, listener: (event: any, ...args: any[]) => void): unknown;
57
+ }
58
+ /** The `contextBridge` members the preload uses. */
59
+ interface ContextBridgeLike {
60
+ exposeInMainWorld(key: string, api: unknown): void;
61
+ }
62
+ /** One call from a renderer. `args` is positional, matching the SDK method. */
63
+ type DaexIpcInvokeRequest = {
64
+ method: string;
65
+ args: unknown[];
66
+ };
67
+ /**
68
+ * A failure, flattened so it survives structured clone.
69
+ *
70
+ * `ipcMain.handle` rejections reach the renderer as a plain `Error` whose
71
+ * message has been rewritten, which loses `DaexError.code` — the one field an
72
+ * embedder branches on. So the handler never rejects: it resolves with this
73
+ * envelope and the renderer rebuilds a real `DaexError`.
74
+ */
75
+ type DaexIpcErrorPayload = {
76
+ __adeError: true;
77
+ name: "AdeError";
78
+ code: string;
79
+ message: string;
80
+ };
81
+ type DaexIpcInvokeResponse<T = unknown> = {
82
+ ok: true;
83
+ value: T;
84
+ } | {
85
+ ok: false;
86
+ error: DaexIpcErrorPayload;
87
+ };
88
+ /** A pushed envelope for one thread subscription. */
89
+ type DaexIpcThreadEvent = {
90
+ kind: "thread";
91
+ subscriptionId: string;
92
+ key: string;
93
+ envelope: AgentChatEventEnvelope;
94
+ };
95
+ /** A pushed provider-status snapshot for one `providers.onChange` subscription. */
96
+ type DaexIpcProvidersEvent = {
97
+ kind: "providers";
98
+ subscriptionId: string;
99
+ statuses: Record<string, ProviderStatus>;
100
+ };
101
+ /**
102
+ * A pushed runtime lifecycle event for one `client.subscribe` subscription.
103
+ *
104
+ * `event` and `payload` are exactly what `DaexChatClient.on` delivers in the
105
+ * main process: a union keyed by `DaexClientEventMap`, so narrowing on `event`
106
+ * types `payload`. One subscription carries every event name; the renderer
107
+ * client splits them.
108
+ */
109
+ type DaexIpcClientEvent = {
110
+ [E in DaexClientEvent]: {
111
+ kind: "client";
112
+ subscriptionId: string;
113
+ event: E;
114
+ payload: DaexClientEventMap[E];
115
+ };
116
+ }[DaexClientEvent];
117
+ type DaexIpcEventPayload = DaexIpcThreadEvent | DaexIpcProvidersEvent | DaexIpcClientEvent;
118
+ /**
119
+ * What the preload puts on `window[key]`.
120
+ *
121
+ * Functions and plain data only. Nothing structured-cloned across
122
+ * `contextBridge` keeps its prototype, so the renderer receives an id plus
123
+ * functions and rebuilds every object shape on its own side.
124
+ */
125
+ type DaexBridge = {
126
+ invoke(method: string, args: unknown[]): Promise<DaexIpcInvokeResponse>;
127
+ onEvent(listener: (payload: DaexIpcEventPayload) => void): () => void;
128
+ };
129
+ /**
130
+ * What `threads.open` returns across the bridge.
131
+ *
132
+ * The capability reports are read-only snapshots taken at open, typed with the
133
+ * SDK's own report types. They are plain serializable objects that the main
134
+ * side has ALREADY normalized (`hostConfig.ts`), so there is nothing left for
135
+ * the renderer to validate — and typing them `unknown` here only moved four
136
+ * unchecked casts to the far side of the wire. Forward compatibility is carried
137
+ * by the report types themselves, which are open where it matters
138
+ * (`HostConfigCapability` intersects `Record<string, unknown>`).
139
+ *
140
+ * Types only: this module still has no value import of its own.
141
+ */
142
+ type DaexIpcThreadSnapshot = {
143
+ id: string;
144
+ key: string;
145
+ /** The thread's title at open (or after the last `thread.update`). */
146
+ title: string | null;
147
+ /** What the thread's model resolved to, with the catalog display name. */
148
+ model: ThreadModelSelection | null;
149
+ mcpCapability: McpCapabilityReport | null;
150
+ instructionsCapability: InstructionsCapability | null;
151
+ settingSourcesCapability: SettingSourcesCapability | null;
152
+ permissionCapability: PermissionCapability | null;
153
+ };
154
+ /** `{ subscriptionId }`, returned by every subscribe method. */
155
+ type DaexIpcSubscription = {
156
+ subscriptionId: string;
157
+ };
158
+ /**
159
+ * Every method a renderer may call.
160
+ *
161
+ * NOT on this list, deliberately: `thread.updateMcpServers`. MCP servers carry
162
+ * credentials and choose the agent's tool surface, so only the host's main
163
+ * process may change them — through `thread.updateMcpServers`, or through the
164
+ * bridge's `openOptions` hook returning `refresh.mcpServers`.
165
+ */
166
+ declare const DAEX_IPC_METHODS: readonly ["providers.status", "providers.refresh", "providers.capabilities", "providers.subscribe", "providers.unsubscribe", "models.list", "doctor", "client.subscribe", "client.unsubscribe", "threads.open", "threads.list", "threads.get", "threads.delete", "threads.archive", "threads.unarchive", "thread.export", "thread.update", "thread.retry", "thread.editLast", "thread.historyPage", "thread.send", "thread.steer", "thread.interrupt", "thread.respond", "thread.queue.list", "thread.queue.cancel", "thread.queue.edit", "thread.queue.move", "thread.queue.dispatch", "thread.queue.cancelDispatched", "thread.queue.restore", "thread.stopTask", "thread.slashCommands", "thread.recover", "thread.resolveUnprocessed", "thread.usageLimit.resumeNow", "thread.usageLimit.continueOnAlternate", "thread.switchAccount", "thread.history", "thread.setModel", "thread.approve", "thread.pendingApprovals", "accounts.list", "accounts.add", "accounts.remove", "accounts.rename", "accounts.setDefault", "accounts.signOut", "accounts.refresh", "accounts.signIn", "accounts.signInStatus", "accounts.signInSubmitCode", "accounts.signInCancel", "credentials.list", "credentials.add", "credentials.remove", "credentials.verify", "presets.list", "presets.add", "presets.update", "presets.remove", "thread.subscribe", "thread.unsubscribe"];
167
+ type DaexIpcMethod = (typeof DAEX_IPC_METHODS)[number];
168
+ /**
169
+ * Methods whose first argument is a thread key, so `allowThreadKey` can gate
170
+ * them without the dispatch table restating the rule per method.
171
+ */
172
+ declare const DAEX_IPC_THREAD_KEY_METHODS: ReadonlySet<DaexIpcMethod>;
173
+ /**
174
+ * The de-duplication key `@daex-dev/chat-ui` documents.
175
+ *
176
+ * History and the live stream overlap by design — an envelope emitted while
177
+ * `history()` is in flight legitimately appears in both — so both sides key on
178
+ * exactly this string and the overlap collapses instead of double-rendering.
179
+ */
180
+ declare function envelopeDedupeKey(envelope: AgentChatEventEnvelope,
181
+ /**
182
+ * How many earlier envelopes IN THE SAME ARRAY already produced this exact
183
+ * key. Zero, and omitted, for the ordinary case.
184
+ *
185
+ * `sequence` is optional on the wire, and without it two `text` deltas in the
186
+ * same millisecond produce one key and the second is dropped — a hole in the
187
+ * transcript on a fast stream from a runtime that does not number its
188
+ * envelopes. An occurrence index fixes that WITHOUT breaking the overlap
189
+ * collapse this key exists for: history and the live buffer are counted
190
+ * separately, so one envelope appearing in both is the first occurrence in
191
+ * each and the two still meet on one key, while two genuinely distinct
192
+ * deltas inside one array do not.
193
+ *
194
+ * BRIDGE-LOCAL. It means nothing outside the array it was counted in, which
195
+ * is why `@daex-dev/chat-ui`'s mirror of this key does not carry it.
196
+ */
197
+ occurrence?: number): string;
198
+ /**
199
+ * Envelope order: numbered envelopes first, then `sequence`, then `timestamp`.
200
+ *
201
+ * Mirrors `sortEnvelopes` in `@daex-dev/chat-ui`. Provider clocks are not
202
+ * trusted, which is why `sequence` wins whenever an envelope carries one. Two
203
+ * envelopes with neither compare equal and a stable sort leaves them in
204
+ * arrival order.
205
+ */
206
+ declare function compareEnvelopes(a: AgentChatEventEnvelope, b: AgentChatEventEnvelope): number;
207
+ /**
208
+ * Merge a history page with the live envelopes buffered while it was in flight.
209
+ *
210
+ * Each envelope is delivered once, in envelope order. This is the rule the
211
+ * chat-ui README states in prose; keeping it in code means an embedder inherits
212
+ * it instead of re-reading the paragraph.
213
+ */
214
+ declare function mergeHistoryWithBuffer(history: AgentChatEventEnvelope[], buffered: AgentChatEventEnvelope[]): AgentChatEventEnvelope[];
215
+ /** @deprecated Use {@link DAEX_DEFAULT_BRIDGE_KEY}. */
216
+ declare const ADE_DEFAULT_BRIDGE_KEY = "ade";
217
+ /** @deprecated Use {@link DAEX_DEFAULT_CHANNEL_PREFIX}. */
218
+ declare const ADE_DEFAULT_CHANNEL_PREFIX = "ade";
219
+ /** @deprecated Use {@link DAEX_IPC_METHODS}. */
220
+ declare const ADE_IPC_METHODS: readonly ["providers.status", "providers.refresh", "providers.capabilities", "providers.subscribe", "providers.unsubscribe", "models.list", "doctor", "client.subscribe", "client.unsubscribe", "threads.open", "threads.list", "threads.get", "threads.delete", "threads.archive", "threads.unarchive", "thread.export", "thread.update", "thread.retry", "thread.editLast", "thread.historyPage", "thread.send", "thread.steer", "thread.interrupt", "thread.respond", "thread.queue.list", "thread.queue.cancel", "thread.queue.edit", "thread.queue.move", "thread.queue.dispatch", "thread.queue.cancelDispatched", "thread.queue.restore", "thread.stopTask", "thread.slashCommands", "thread.recover", "thread.resolveUnprocessed", "thread.usageLimit.resumeNow", "thread.usageLimit.continueOnAlternate", "thread.switchAccount", "thread.history", "thread.setModel", "thread.approve", "thread.pendingApprovals", "accounts.list", "accounts.add", "accounts.remove", "accounts.rename", "accounts.setDefault", "accounts.signOut", "accounts.refresh", "accounts.signIn", "accounts.signInStatus", "accounts.signInSubmitCode", "accounts.signInCancel", "credentials.list", "credentials.add", "credentials.remove", "credentials.verify", "presets.list", "presets.add", "presets.update", "presets.remove", "thread.subscribe", "thread.unsubscribe"];
221
+ /** @deprecated Use {@link DAEX_IPC_THREAD_KEY_METHODS}. */
222
+ declare const ADE_IPC_THREAD_KEY_METHODS: ReadonlySet<"threads.open" | "threads.get" | "threads.delete" | "threads.archive" | "threads.unarchive" | "thread.export" | "thread.update" | "thread.retry" | "thread.editLast" | "thread.history" | "thread.historyPage" | "thread.send" | "thread.steer" | "thread.interrupt" | "thread.setModel" | "thread.approve" | "thread.pendingApprovals" | "thread.respond" | "thread.queue.list" | "thread.queue.cancel" | "thread.queue.edit" | "thread.queue.move" | "thread.queue.dispatch" | "thread.queue.cancelDispatched" | "thread.queue.restore" | "thread.stopTask" | "thread.slashCommands" | "thread.recover" | "thread.resolveUnprocessed" | "thread.usageLimit.resumeNow" | "thread.usageLimit.continueOnAlternate" | "thread.switchAccount" | "providers.status" | "providers.refresh" | "models.list" | "doctor" | "threads.list" | "providers.capabilities" | "accounts.list" | "accounts.add" | "accounts.remove" | "accounts.rename" | "accounts.setDefault" | "accounts.signOut" | "accounts.refresh" | "accounts.signIn" | "accounts.signInStatus" | "accounts.signInSubmitCode" | "accounts.signInCancel" | "credentials.list" | "credentials.add" | "credentials.remove" | "credentials.verify" | "presets.list" | "presets.add" | "presets.update" | "presets.remove" | "providers.subscribe" | "providers.unsubscribe" | "client.subscribe" | "client.unsubscribe" | "thread.subscribe" | "thread.unsubscribe">;
223
+ /** @deprecated Use {@link DaexBridge}. */
224
+ type AdeBridge = DaexBridge;
225
+ /** @deprecated Use {@link DaexIpcClientEvent}. */
226
+ type AdeIpcClientEvent = DaexIpcClientEvent;
227
+ /** @deprecated Use {@link DaexIpcErrorPayload}. */
228
+ type AdeIpcErrorPayload = DaexIpcErrorPayload;
229
+ /** @deprecated Use {@link DaexIpcEventPayload}. */
230
+ type AdeIpcEventPayload = DaexIpcEventPayload;
231
+ /** @deprecated Use {@link DaexIpcInvokeRequest}. */
232
+ type AdeIpcInvokeRequest = DaexIpcInvokeRequest;
233
+ /** @deprecated Use {@link DaexIpcInvokeResponse}. */
234
+ type AdeIpcInvokeResponse<T = unknown> = DaexIpcInvokeResponse<T>;
235
+ /** @deprecated Use {@link DaexIpcMethod}. */
236
+ type AdeIpcMethod = DaexIpcMethod;
237
+ /** @deprecated Use {@link DaexIpcProvidersEvent}. */
238
+ type AdeIpcProvidersEvent = DaexIpcProvidersEvent;
239
+ /** @deprecated Use {@link DaexIpcSubscription}. */
240
+ type AdeIpcSubscription = DaexIpcSubscription;
241
+ /** @deprecated Use {@link DaexIpcThreadEvent}. */
242
+ type AdeIpcThreadEvent = DaexIpcThreadEvent;
243
+ /** @deprecated Use {@link DaexIpcThreadSnapshot}. */
244
+ type AdeIpcThreadSnapshot = DaexIpcThreadSnapshot;
245
+
246
+ /**
247
+ * `@daex-dev/sdk/electron` — the main-process half of the Electron bridge.
248
+ *
249
+ * `@daex-dev/sdk` spawns a child process and speaks over a Unix socket, so it
250
+ * lives in the main process. `@daex-dev/chat-ui` is React and lives in the
251
+ * renderer. They cannot share an object, and the glue between them is not
252
+ * application logic — it is object-lifetime bookkeeping across a process
253
+ * boundary, and it is the same in every app.
254
+ *
255
+ * THE LEAK THIS EXISTS TO PREVENT. `providers.onChange` and `thread.on` return
256
+ * an `Unsubscribe` that only the main process can call. A renderer that reloads
257
+ * (a React fast-refresh loop reloads it constantly) drops its side and leaves
258
+ * main's listener attached. Nothing fails; the transcript simply starts showing
259
+ * every envelope twice, then three times. So the registry below is keyed by
260
+ * `webContents.id` and is torn down on `destroyed` AND on a real navigation.
261
+ *
262
+ * WHAT TEARDOWN DOES AND DOES NOT DO. It drops listeners and forgets the
263
+ * bridge's handles. It does not end the conversation: the SDK's own
264
+ * `liveSessions` keeps the thread, so the renderer reopens the same key and
265
+ * resumes the same transcript.
266
+ *
267
+ * WHAT A RENDERER MAY CHOOSE. A thread key carries a tool surface, a policy
268
+ * and a working directory, and the renderer is the least trusted process in
269
+ * the app. So the renderer never configures a thread: either the host's
270
+ * `openOptions` hook decides everything, or the bridge forwards only
271
+ * `provider`, `model`, `title` and `reasoningEffort` and drops the rest.
272
+ */
273
+
274
+ /**
275
+ * The removals the bridge reports to a host: a thread that is gone, or one that
276
+ * was archived. An unarchive is not one — the thread is back, not removed.
277
+ */
278
+ type ThreadRemovalKind = "deleted" | "archived";
279
+ type RegisterDaexIpcOptions = {
280
+ /** Channel namespace. Defaults to `"ade"`, giving `ade:invoke` and `ade:event`. */
281
+ channelPrefix?: string;
282
+ /**
283
+ * Gate every call before the SDK sees it.
284
+ *
285
+ * Runs first, on every method, with the raw positional arguments. Return
286
+ * false and the renderer receives `DaexError("unauthorized")` and the SDK is
287
+ * not called at all. This is where a host checks the sender frame and its own
288
+ * sign-in state.
289
+ */
290
+ authorize?: (event: IpcMainInvokeEventLike, method: string, args: unknown[]) => boolean | Promise<boolean>;
291
+ /**
292
+ * Restrict which thread keys a renderer may name.
293
+ *
294
+ * A thread key carries MCP servers, a permission policy and a working
295
+ * directory, so a compromised renderer that can open an arbitrary key can
296
+ * choose its own tool surface. Return false and the call is rejected with
297
+ * `DaexError("unauthorized")`.
298
+ *
299
+ * May be async (SDK >= 0.4), so a host whose truth lives in the runtime can
300
+ * answer from `client.threads.get(key)` instead of a hand-synced copy. It
301
+ * runs on every keyed call, so keep an async gate cheap.
302
+ */
303
+ allowThreadKey?: (key: string) => boolean | Promise<boolean>;
304
+ /**
305
+ * Enable account, credential and preset management from renderers. Without
306
+ * this explicit host gate, every such call is refused. A callback can make
307
+ * the decision per renderer and method.
308
+ */
309
+ allowAccountManagement?: boolean | ((event: IpcMainInvokeEventLike, method: string, args: unknown[]) => boolean | Promise<boolean>);
310
+ /**
311
+ * The host decides how a thread is opened. Recommended for every host.
312
+ *
313
+ * Called for every renderer `threads.open`, with the key and whatever
314
+ * options the renderer sent (for reading, never for trusting). Its result is
315
+ * what the SDK opens with, and the renderer's options are ignored entirely.
316
+ * Return undefined to reopen a key with its stored record and no options —
317
+ * which fails with `invalid_option` for a key this home has never seen.
318
+ *
319
+ * `context` (SDK >= 0.4) says whether the runtime still has a session for
320
+ * the key (`exists`) and gives its summary (`threads.get`). Use it to tell a
321
+ * resume from a create: for `exists: true` return `{ refresh }` alone (or
322
+ * undefined), and the stored provider, model and policy apply without one
323
+ * "ignored field" log line per option; for `exists: false` return the full
324
+ * create options (provider, model, the locked policy). `exists: false` also
325
+ * covers a known key whose session the runtime lost, which the SDK then
326
+ * recreates with these options.
327
+ *
328
+ * Put credentials here too: return `refresh: { mcpServers }` with the
329
+ * current token and every renderer-driven open pushes it onto the thread.
330
+ *
331
+ * When this hook is NOT set, the bridge forwards only `provider`, `model`,
332
+ * `title` and `reasoningEffort` from the renderer and logs one line per
333
+ * field it dropped. Before 0.3 it forwarded everything, so a compromised
334
+ * renderer could open an allowed key with `permissions: "always-allow"`,
335
+ * its own MCP servers, or its own `cwd`.
336
+ */
337
+ openOptions?: (key: string, rendererOptions: Record<string, unknown> | undefined, context: DaexIpcOpenContext) => ThreadOpenOptions | ThreadResumeOptions | undefined | Promise<ThreadOpenOptions | ThreadResumeOptions | undefined>;
338
+ /**
339
+ * Gate the models a renderer may pick.
340
+ *
341
+ * Called for `thread.setModel`, and for a renderer-supplied `model` on
342
+ * `threads.open` when there is no `openOptions` hook. Return false and the
343
+ * call fails with `DaexError("unauthorized")`. Without it any model id the
344
+ * catalog resolves is accepted — including one on a provider the host never
345
+ * meant to offer. May be async (SDK >= 0.4).
346
+ */
347
+ allowModel?: (key: string, selection: {
348
+ modelId: string;
349
+ }) => boolean | Promise<boolean>;
350
+ /**
351
+ * Called for every delete or archive the bridge's client reports, whoever
352
+ * made it: a renderer over the bridge, or main code calling
353
+ * `client.threads.delete` / `client.threads.archive` (SDK 0.5).
354
+ *
355
+ * It runs from the bridge's own `threadLifecycle` subscription, so a client
356
+ * that does not emit that event — an SDK older than 0.4, or a test double —
357
+ * never calls it.
358
+ *
359
+ * `kind` is `"deleted"` or `"archived"`. An unarchive is not reported: the
360
+ * thread is back, not gone. On a delete the bridge has already released the
361
+ * renderer's handles for the key by the time this runs, so your own list can
362
+ * drop the key; an archive releases nothing, because an archived thread may
363
+ * still be open.
364
+ *
365
+ * To STOP a renderer from deleting or archiving at all, refuse the method in
366
+ * `authorize` — return false for `method === "threads.delete"` (or
367
+ * `"threads.archive"`). There is deliberately no separate deny list.
368
+ *
369
+ * A callback that throws is logged and ignored; it does not fail the delete.
370
+ */
371
+ onThreadRemoved?: (key: string, kind: ThreadRemovalKind) => void;
372
+ /** Optional line logger, matching the SDK's own `logger` option. */
373
+ logger?: (line: string) => void;
374
+ };
375
+ /** What the `openOptions` hook learns about the key being opened. */
376
+ type DaexIpcOpenContext = {
377
+ /** The runtime has a session for the key: this open is a resume. */
378
+ exists: boolean;
379
+ /** That session's summary (`client.threads.get`), or null when `exists` is false. */
380
+ summary: ThreadSummary | null;
381
+ };
382
+ /**
383
+ * `registerDaexIpc`'s result: call it to dispose the bridge (the pre-0.4
384
+ * contract), and use `forget` to release a key's handles by hand.
385
+ */
386
+ type DaexIpcBridgeHandle = (() => void) & {
387
+ /**
388
+ * Release every renderer's handles and subscriptions for `key`. The bridge
389
+ * already does this for a delete made through the client it serves (by the
390
+ * renderer, or by main code calling `client.threads.delete`); call it for a
391
+ * key you removed some other way. The conversation is not touched. SDK >= 0.4.
392
+ */
393
+ forget(key: string): void;
394
+ };
395
+ /**
396
+ * The client a bridge serves, or a function returning the current one.
397
+ *
398
+ * The function form is for a host that replaces its client — one per signed-in
399
+ * account, disposed on sign-out. The bridge re-reads it on every call, and on
400
+ * the first call after it changed it moves each renderer across before that
401
+ * call runs (a call that overlaps the move waits for it):
402
+ * - every key the renderer had open is checked again against
403
+ * `allowThreadKey` and reopened on the new client with options from the
404
+ * `openOptions` hook run AGAIN for the new client (or, without a hook, the
405
+ * renderer's own options filtered again) — never with options resolved for
406
+ * the old client. A key refused or failing there is dropped, with one log
407
+ * line, and its subscriptions end;
408
+ * - every subscription — thread, client-event and provider-status — is
409
+ * re-attached under the SAME id, so the renderer's handles keep working.
410
+ * Events a replaced client would have pushed between the swap and that first
411
+ * call are not replayed. A client with `autoRestart` never changes identity and
412
+ * needs none of this.
413
+ */
414
+ type DaexChatClientSource = DaexChatClient | (() => DaexChatClient | null | undefined);
415
+ /**
416
+ * Read an `DaexError` code without `instanceof`.
417
+ *
418
+ * The Electron entries are separate bundles, so `DaexError` from
419
+ * `@daex-dev/sdk` and `DaexError` from `@daex-dev/sdk/electron` are two classes
420
+ * with one name. An `instanceof` check here would silently flatten every SDK
421
+ * error to `rpc_error` — exactly the field this whole envelope exists to carry
422
+ * — so the shape is read instead of the prototype.
423
+ */
424
+ declare function daexErrorCodeOf(error: unknown): string | null;
425
+ /**
426
+ * Decide whether a navigation event means "this renderer's world is gone".
427
+ *
428
+ * A hash change and an iframe navigation both raise `did-start-navigation`, and
429
+ * neither destroys the renderer's JavaScript context. Tearing down on those
430
+ * would silently kill a live transcript on an in-page route change. Electron
431
+ * has passed these arguments two different ways across versions — a details
432
+ * object in recent releases, four positional arguments before that — so both
433
+ * shapes are read rather than assumed.
434
+ */
435
+ declare function navigationEndsRendererWorld(args: unknown[]): boolean;
436
+ /**
437
+ * Attach the DAEX chat surface to an `ipcMain`.
438
+ *
439
+ * Returns a disposer that removes the handler and tears down every renderer's
440
+ * subscriptions. Call it before `client.dispose()` so no push races a closing
441
+ * runtime. The disposer also carries `forget(key)` (see `DaexIpcBridgeHandle`).
442
+ *
443
+ * `clientSource` is the client, or a function returning the current one — see
444
+ * {@link DaexChatClientSource} for what a swap does.
445
+ */
446
+ declare function registerDaexIpc(ipcMain: IpcMainLike, clientSource: DaexChatClientSource, opts?: RegisterDaexIpcOptions): DaexIpcBridgeHandle;
447
+ /** @deprecated Use {@link DaexChatClientSource}. */
448
+ type AdeChatClientSource = DaexChatClientSource;
449
+ /** @deprecated Use {@link RegisterDaexIpcOptions}. */
450
+ type RegisterAdeIpcOptions = RegisterDaexIpcOptions;
451
+ /** @deprecated Use {@link daexErrorCodeOf}. */
452
+ declare const adeErrorCodeOf: typeof daexErrorCodeOf;
453
+ /** @deprecated Use {@link registerDaexIpc}. */
454
+ declare const registerAdeIpc: typeof registerDaexIpc;
455
+ /** @deprecated Use {@link DaexIpcBridgeHandle}. */
456
+ type AdeIpcBridgeHandle = DaexIpcBridgeHandle;
457
+ /** @deprecated Use {@link DaexIpcOpenContext}. */
458
+ type AdeIpcOpenContext = DaexIpcOpenContext;
459
+
460
+ /**
461
+ * What a renderer may put in the options of a bridge call.
462
+ *
463
+ * The renderer is the least trusted process in an Electron app, and a thread
464
+ * key carries a tool surface, a policy and a working directory. So the bridge
465
+ * rebuilds every renderer option object field by field and drops the rest,
466
+ * with one log line per dropped field.
467
+ */
468
+
469
+ /** The renderer `threads.open` fields the bridge forwards without an `openOptions` hook. */
470
+ declare const DAEX_IPC_RENDERER_OPEN_FIELDS: readonly ["provider", "model", "title", "reasoningEffort"];
471
+ /** @deprecated Use {@link DAEX_IPC_RENDERER_OPEN_FIELDS}. */
472
+ declare const ADE_IPC_RENDERER_OPEN_FIELDS: readonly ["provider", "model", "title", "reasoningEffort"];
473
+
474
+ /**
475
+ * Check a hand-written preload bridge against the one this SDK version ships.
476
+ *
477
+ * `@daex-dev/sdk/electron/preload-auto` must be `webPreferences.preload`
478
+ * itself, so a host with its own preload either bundles `exposeDaexBridge` into
479
+ * it or copies it by hand. A hand copy can drift from the SDK (a channel name,
480
+ * the payload shape) with no compile error and no runtime error: the bridge
481
+ * simply never answers. Run this in the host's test suite, in Node, against the
482
+ * function that exposes the copy.
483
+ */
484
+
485
+ type CheckDaexBridgeOptions = {
486
+ /** The `window` key the copy should expose. Defaults to `"ade"`. */
487
+ key?: string;
488
+ /** The channel namespace the main process uses. Defaults to `"ade"`. */
489
+ channelPrefix?: string;
490
+ };
491
+ /**
492
+ * Run `expose` with a fake `contextBridge` and `ipcRenderer`, and check that
493
+ * what it exposes behaves like `exposeDaexBridge` from this SDK version:
494
+ * - one object on `window[key]` with `invoke` and `onEvent`;
495
+ * - `invoke(method, args)` calls `ipcRenderer.invoke(<prefix>:invoke,
496
+ * { method, args })` and resolves to its result unchanged;
497
+ * - `onEvent(listener)` listens on `<prefix>:event`, passes each payload
498
+ * through unchanged, and its return value removes that same listener.
499
+ *
500
+ * Resolves when the copy matches. Rejects with `DaexError("invalid_option")`
501
+ * naming the first difference. `expose` is typically
502
+ * `(contextBridge, ipcRenderer) => { ...your preload's bridge code... }`.
503
+ */
504
+ declare function checkDaexBridge(expose: (contextBridge: ContextBridgeLike, ipcRenderer: IpcRendererLike) => void, opts?: CheckDaexBridgeOptions): Promise<void>;
505
+ /** @deprecated Use {@link CheckDaexBridgeOptions}. */
506
+ type CheckAdeBridgeOptions = CheckDaexBridgeOptions;
507
+ /** @deprecated Use {@link checkDaexBridge}. */
508
+ declare const checkAdeBridge: typeof checkDaexBridge;
509
+
510
+ export { ADE_DEFAULT_BRIDGE_KEY, ADE_DEFAULT_CHANNEL_PREFIX, ADE_IPC_METHODS, ADE_IPC_RENDERER_OPEN_FIELDS, ADE_IPC_THREAD_KEY_METHODS, type AdeBridge, type AdeChatClientSource, type AdeIpcBridgeHandle, type AdeIpcClientEvent, type AdeIpcErrorPayload, type AdeIpcEventPayload, type AdeIpcInvokeRequest, type AdeIpcInvokeResponse, type AdeIpcMethod, type AdeIpcOpenContext, type AdeIpcProvidersEvent, type AdeIpcSubscription, type AdeIpcThreadEvent, type AdeIpcThreadSnapshot, type CheckAdeBridgeOptions, type CheckDaexBridgeOptions, type ContextBridgeLike, DAEX_DEFAULT_BRIDGE_KEY, DAEX_DEFAULT_CHANNEL_PREFIX, DAEX_IPC_METHODS, DAEX_IPC_RENDERER_OPEN_FIELDS, DAEX_IPC_THREAD_KEY_METHODS, type DaexBridge, type DaexChatClientSource, type DaexIpcBridgeHandle, type DaexIpcClientEvent, type DaexIpcErrorPayload, type DaexIpcEventPayload, type DaexIpcInvokeRequest, type DaexIpcInvokeResponse, type DaexIpcMethod, type DaexIpcOpenContext, type DaexIpcProvidersEvent, type DaexIpcSubscription, type DaexIpcThreadEvent, type DaexIpcThreadSnapshot, type IpcMainInvokeEventLike, type IpcMainLike, type IpcRendererLike, type RegisterAdeIpcOptions, type RegisterDaexIpcOptions, type ThreadRemovalKind, type WebContentsLike, adeErrorCodeOf, checkAdeBridge, checkDaexBridge, compareEnvelopes, daexErrorCodeOf, envelopeDedupeKey, eventChannel, invokeChannel, mergeHistoryWithBuffer, navigationEndsRendererWorld, registerAdeIpc, registerDaexIpc };