@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.
- package/LICENSE +21 -0
- package/README.md +417 -3
- package/dist/client-C0KQKP8O.d.cts +2621 -0
- package/dist/client-C0KQKP8O.d.ts +2621 -0
- package/dist/electron/global.cjs +18 -0
- package/dist/electron/global.d.cts +35 -0
- package/dist/electron/global.d.ts +35 -0
- package/dist/electron/global.js +0 -0
- package/dist/electron/index.cjs +1133 -0
- package/dist/electron/index.d.cts +510 -0
- package/dist/electron/index.d.ts +510 -0
- package/dist/electron/index.js +1073 -0
- package/dist/electron/preload-auto.cjs +38 -0
- package/dist/electron/preload.cjs +66 -0
- package/dist/electron/preload.d.cts +46 -0
- package/dist/electron/preload.d.ts +46 -0
- package/dist/electron/preload.js +43 -0
- package/dist/electron/protocol-DXRtliy3.d.cts +904 -0
- package/dist/electron/protocol-DXRtliy3.d.ts +904 -0
- package/dist/electron/renderer.cjs +631 -0
- package/dist/electron/renderer.d.cts +508 -0
- package/dist/electron/renderer.d.ts +508 -0
- package/dist/electron/renderer.global.js +634 -0
- package/dist/electron/renderer.js +608 -0
- package/dist/index.cjs +6681 -0
- package/dist/index.d.cts +313 -0
- package/dist/index.d.ts +313 -0
- package/dist/index.js +6611 -0
- package/dist/server.cjs +1019 -0
- package/dist/server.d.cts +118 -0
- package/dist/server.d.ts +118 -0
- package/dist/server.js +989 -0
- package/dist/testing.cjs +815 -0
- package/dist/testing.d.cts +29 -0
- package/dist/testing.d.ts +29 -0
- package/dist/testing.js +787 -0
- package/package.json +93 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Arul Sharma
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,417 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# @daex-dev/sdk
|
|
2
|
+
|
|
3
|
+
Typed Node / Electron-main client that spawns a slim DAEX runtime as a sidecar
|
|
4
|
+
and exposes chat as durable named threads.
|
|
5
|
+
|
|
6
|
+
Formerly `@ade-dev/sdk`. To move, change your imports to `@daex-dev/sdk`; the
|
|
7
|
+
`Ade*` names (`createAdeChat`, `AdeError`, ...) still work as deprecated aliases
|
|
8
|
+
of the `DAEX*` names.
|
|
9
|
+
|
|
10
|
+
**Docs:** [DAEX SDK](https://ade-app.dev/docs/sdk/overview) — install, threads, MCP honesty table, chat UI, runtime, and API reference.
|
|
11
|
+
|
|
12
|
+
| Page | What it covers |
|
|
13
|
+
|---|---|
|
|
14
|
+
| [Threads](https://ade-app.dev/docs/sdk/threads) | Lifecycle, attachments, paged history, configuration and model switching |
|
|
15
|
+
| [Accounts](https://ade-app.dev/docs/sdk/accounts) | Isolated sign-in, provider accounts, credentials, endpoint presets and usage limits |
|
|
16
|
+
| [MCP servers](https://ade-app.dev/docs/sdk/mcp) | Injected tools, credentials that change, resource links, and the strict-mode honesty table |
|
|
17
|
+
| [Permissions](https://ade-app.dev/docs/sdk/permissions) | The policy object, per-provider enforcement, answering approvals |
|
|
18
|
+
| [Accounts](https://ade-app.dev/docs/sdk/accounts) | Isolated sign-in, provider accounts, stored credentials, presets and usage limits |
|
|
19
|
+
| [Chat UI](https://ade-app.dev/docs/sdk/chat-ui) | `@daex-dev/chat-ui`, theming, approval cards, provider cards |
|
|
20
|
+
| [Electron](https://ade-app.dev/docs/sdk/electron) | The main / preload / renderer bridge under `sandbox: true` |
|
|
21
|
+
| [WebSocket server](https://ade-app.dev/docs/sdk/server) | Authorized server bridge and browser remote client |
|
|
22
|
+
| [Testing](https://ade-app.dev/docs/sdk/testing) | Mock clients and transcript replay without a runtime or provider tokens |
|
|
23
|
+
| [Bundling](https://ade-app.dev/docs/sdk/bundling) | Platform packages, `codesign`, entitlements, electron-builder |
|
|
24
|
+
| [Runtime](https://ade-app.dev/docs/sdk/runtime) | The sidecar, exit events and `autoRestart`, version compatibility, and `doctor().runtime` provenance |
|
|
25
|
+
| [Reference](https://ade-app.dev/docs/sdk/reference) | Every option, shape, and error code |
|
|
26
|
+
| [License](https://ade-app.dev/docs/sdk/license) | What each artifact is licensed under |
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install @daex-dev/sdk
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Requires Node 22.13 or newer. The sidecar is a guest: isolated `home`, sync off, no
|
|
33
|
+
machine-brain authority. It dies with your process.
|
|
34
|
+
|
|
35
|
+
SDK 0.7 supports runtime `>=1.2.82 <2.0.0` (`SUPPORTED_RUNTIME_RANGE`). The
|
|
36
|
+
lower bound did not move in 0.5 or 0.6, so a host on runtime 1.2.82 keeps
|
|
37
|
+
working. On an older runtime, MCP tool filters are refused before they are
|
|
38
|
+
sent (they need `capabilities.personalChats.mcpToolFilters`), and a mid-turn
|
|
39
|
+
`updateMcpServers` is refused with `turn_in_flight` instead of queued; the
|
|
40
|
+
header refresh needs nothing new. An older or newer runtime still
|
|
41
|
+
connects, logs one warning, and degrades feature by feature. Pass
|
|
42
|
+
`requireCompatibleRuntime: true` to refuse it with
|
|
43
|
+
`runtime_incompatible`. `doctor().runtime.compatibility` reports the verdict.
|
|
44
|
+
|
|
45
|
+
## Quickstart
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { createDaexChat } from "@daex-dev/sdk";
|
|
49
|
+
|
|
50
|
+
const daex = await createDaexChat({ home: "./.ade-embed" });
|
|
51
|
+
const thread = await daex.threads.open("support", {
|
|
52
|
+
provider: "claude",
|
|
53
|
+
model: "claude-sonnet-4-5",
|
|
54
|
+
});
|
|
55
|
+
thread.on("event", (envelope) => console.log(envelope.event.type));
|
|
56
|
+
await thread.send("Summarise today's incidents");
|
|
57
|
+
console.log(thread.usage());
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
`thread.usage()` reports cumulative token totals and provider-reported cost.
|
|
61
|
+
Pass `budget: { maxTokens, maxCostUsd }` when creating a thread to interrupt it
|
|
62
|
+
when a reported limit is reached. Budgets persist with the thread key.
|
|
63
|
+
|
|
64
|
+
Use `daex.run(prompt, { provider, model, schema })` for a temporary one-shot
|
|
65
|
+
thread. A schema response is parsed and checked locally, retried once when it
|
|
66
|
+
does not match, then rejected with `InvalidOutputError` carrying `rawText`.
|
|
67
|
+
|
|
68
|
+
Reopening `"support"` after a restart resumes the same conversation. Call
|
|
69
|
+
`daex.dispose()` when the host shuts down.
|
|
70
|
+
|
|
71
|
+
## Provider auth
|
|
72
|
+
|
|
73
|
+
The sidecar reuses the provider CLIs and logins already on the machine
|
|
74
|
+
(`claude`, `codex`, `cursor`, …). DAEX state under `home` is isolated; Claude /
|
|
75
|
+
Codex / Cursor credentials still live in those tools' own config homes
|
|
76
|
+
(`~/.claude`, `~/.codex`, `~/.cursor`). If the host user can already run that
|
|
77
|
+
provider in a terminal, the sidecar can too. SDK 0.7 defaults to isolated
|
|
78
|
+
provider logins. **BREAKING from SDK 0.6:** pass
|
|
79
|
+
`useMachineLogin: true` to keep relying on the host machine's Claude or Codex
|
|
80
|
+
login, or sign the user in through `daex.accounts.signIn()` (see
|
|
81
|
+
[Accounts](https://ade-app.dev/docs/sdk/accounts)).
|
|
82
|
+
|
|
83
|
+
`daex.providers.status()` reports, per provider, whether a binary was found, at
|
|
84
|
+
which path and version, and whether credentials are present. Read `source`
|
|
85
|
+
first: `"probed"` means the runtime looked at the filesystem, `"derived"` means
|
|
86
|
+
it is an older runtime inferring from the model catalog. `daex.providers.refresh()`
|
|
87
|
+
bypasses the runtime's 60-second probe cache.
|
|
88
|
+
|
|
89
|
+
`daex.doctor()` is the structured health check: binary path and provenance,
|
|
90
|
+
socket, event transport, providers, and known threads.
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
const report = await daex.doctor();
|
|
94
|
+
if (!report.ok) console.error(report);
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Pin a specific DAEX build with `binaryPath`, or let the client download a
|
|
98
|
+
release. Downloads are fail-closed against that release's `SHA256SUMS`.
|
|
99
|
+
|
|
100
|
+
## Threads
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
const thread = await daex.threads.open("support", {
|
|
104
|
+
provider: "claude",
|
|
105
|
+
model: "claude-sonnet-4-5",
|
|
106
|
+
permissions: "always-allow",
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
await thread.send("What changed?");
|
|
110
|
+
await thread.steer("Focus on the outage"); // mid-turn follow-up
|
|
111
|
+
await thread.steer("", { attachments: [{ path: "/abs/path/log.txt" }] });
|
|
112
|
+
await thread.interrupt();
|
|
113
|
+
await thread.setModel("claude-opus-4"); // see setModel below
|
|
114
|
+
await thread.update({ title: "Outage review" });
|
|
115
|
+
|
|
116
|
+
const page = await thread.historyPage({ limit: 200 }); // newest page
|
|
117
|
+
const rows = await daex.threads.list(); // title, archived, updatedAt, modelSelection
|
|
118
|
+
await daex.threads.archive("support"); // or unarchive / delete
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
`threads.open(key)` is open-or-resume by key stored under `home`. Keys survive
|
|
122
|
+
host restarts. `exportThread(key)` returns the transcript as one JSON envelope
|
|
123
|
+
per line. `thread.title` and `thread.model` (with `displayName`) are on the
|
|
124
|
+
handle.
|
|
125
|
+
|
|
126
|
+
`threads.delete(key)` removes the runtime session, the transcript and the key.
|
|
127
|
+
`archive` keeps both. Each interrupts a running turn first.
|
|
128
|
+
|
|
129
|
+
`thread.update({ title, reasoningEffort, fastMode }, { force })` renames at any
|
|
130
|
+
time. The other two fields are refused mid-turn unless `{ force: true }`.
|
|
131
|
+
|
|
132
|
+
Attachments are `{ path, name?, mimeType?, type?, hydrate? }` refs. `type`
|
|
133
|
+
(`"file"` or `"image"`) is inferred from the MIME type or extension when
|
|
134
|
+
absent, so an image reaches the model as an image. `hydrate: false` sends the
|
|
135
|
+
path only and the runtime never reads the bytes. An absolute path must be
|
|
136
|
+
inside the chat's `cwd`, `<home>/personal-chats/state`, or a directory in the
|
|
137
|
+
thread's `attachmentRoots` (0.4, runtime 1.2.82). See
|
|
138
|
+
[Attachments](https://ade-app.dev/docs/sdk/threads#attachments) for the
|
|
139
|
+
size limits.
|
|
140
|
+
|
|
141
|
+
One refused `attachmentRoots` entry fails the whole open, and a host normally
|
|
142
|
+
sends the same roots every time. Test a candidate with `checkAttachmentRoot`,
|
|
143
|
+
or prepare the whole list with `filterAttachmentRoots`, which drops a bad entry
|
|
144
|
+
and reports why (both 0.5). A list identical to the one already in use is not
|
|
145
|
+
sent again, so a repeated list costs no update call.
|
|
146
|
+
|
|
147
|
+
`thread.retry()` and `thread.editLast(text)` (0.4, runtime 1.2.82) roll the
|
|
148
|
+
provider back and run the last user message again, and the transcript shows it
|
|
149
|
+
once. Claude and Codex only; another provider throws `unsupported`, and a
|
|
150
|
+
running turn throws `turn_in_flight`. The rollback covers the conversation, not
|
|
151
|
+
the disk: files the old turn wrote stay, and the result does not report them.
|
|
152
|
+
If you allow writes, inspect the events at or after `retractedFromSequence` in
|
|
153
|
+
your own history copy and warn the user.
|
|
154
|
+
|
|
155
|
+
`models.defaultModel({ prefer })` (0.5) takes your own ranking inside one
|
|
156
|
+
provider's models. Return a number above zero to prefer a model — the highest
|
|
157
|
+
score wins — so a host that wants the newest Sonnet, not the provider's
|
|
158
|
+
default, states it here instead of keeping its own copy of the rule. A model
|
|
159
|
+
nobody scores falls back to `isDefault`, then to catalog order.
|
|
160
|
+
|
|
161
|
+
Host configuration applies on **create only**. A resume re-applies what the key
|
|
162
|
+
was created with and ignores the `cwd`, `instructions`, `settingSources`,
|
|
163
|
+
`permissions`, `mcpServers` and `loadUserMcpServers` passed to that call,
|
|
164
|
+
logging one line per option it ignored. Open a different key to run under
|
|
165
|
+
different configuration — do not assume a tighter policy took effect because you
|
|
166
|
+
passed one. The one exception is `refresh.mcpServers` (see below).
|
|
167
|
+
|
|
168
|
+
When the runtime lost a key's session, the SDK **recreates** it from the stored
|
|
169
|
+
record. The record wins for `provider`, `model`, `cwd`, `instructions`,
|
|
170
|
+
`settingSources`, `permissions`, `mcpServers` and `loadUserMcpServers`; the
|
|
171
|
+
call's options only fill a field the record lacks. Before 0.3 the call's
|
|
172
|
+
options won. A recreate changes `thread.id`, so key your state on `key`.
|
|
173
|
+
|
|
174
|
+
`setModel` returns the resolved model with `displayName` and the four
|
|
175
|
+
capability reports on the new provider, and emits `capabilities_changed` on the
|
|
176
|
+
`status` channel.
|
|
177
|
+
|
|
178
|
+
`setModel` refuses while a turn is in flight — call `interrupt()` first, or
|
|
179
|
+
pass `{ force: true }` to accept losing the turn. `dispose()` is not guarded
|
|
180
|
+
that way: a shutdown that can refuse is worse than a truncated reply. The
|
|
181
|
+
transcript is durable either way.
|
|
182
|
+
|
|
183
|
+
## MCP servers and strict mode
|
|
184
|
+
|
|
185
|
+
```ts
|
|
186
|
+
const thread = await daex.threads.open("ops", {
|
|
187
|
+
provider: "claude",
|
|
188
|
+
model: "claude-sonnet-4-5",
|
|
189
|
+
mcpServers: {
|
|
190
|
+
docs: { type: "http", url: "https://mcp.example/mcp" },
|
|
191
|
+
},
|
|
192
|
+
// default: withhold the user's own MCP config
|
|
193
|
+
// loadUserMcpServers: true // opt back in
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
if (thread.mcpCapability?.strictRequested && thread.mcpCapability.level !== "enforced") {
|
|
197
|
+
console.warn(thread.mcpCapability.residual);
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
Supplying `mcpServers` turns on strict mode unless you set
|
|
202
|
+
`loadUserMcpServers: true`. **False is not a uniform guarantee.** Only Claude
|
|
203
|
+
can enforce it. Everywhere else DAEX applies the strongest mechanism that
|
|
204
|
+
provider exposes, and Pi has no MCP surface at all (injected servers are
|
|
205
|
+
refused rather than opening a tool-less thread):
|
|
206
|
+
|
|
207
|
+
| Provider | Strict mode | What still loads under strict |
|
|
208
|
+
|---|---|---|
|
|
209
|
+
| claude | enforced | nothing MCP-wise (user rules/commands/output styles still load — they are not MCP) |
|
|
210
|
+
| codex | best-effort | servers contributed by a Codex *plugin* |
|
|
211
|
+
| cursor | best-effort | user-layer servers (`~/.cursor`; DAEX's own preToolUse hook lives there) |
|
|
212
|
+
| droid | best-effort | tools that appear only after the first disable pass |
|
|
213
|
+
| opencode | best-effort | the global OpenCode config directory (for auth) |
|
|
214
|
+
| pi | unsupported | n/a — create refuses injected servers |
|
|
215
|
+
|
|
216
|
+
The server shape is checked against the selected provider before launch. Codex
|
|
217
|
+
does not support `sse`, so a Codex request containing an SSE entry is rejected.
|
|
218
|
+
Server names `computer_use` and `daex-cto` are reserved (so is `ade-cto`, its
|
|
219
|
+
name before the DAEX rename), and a request may contain at most 32 servers.
|
|
220
|
+
|
|
221
|
+
Read `thread.mcpCapability` after open. `strictRequested` first, then `level`.
|
|
222
|
+
`"enforced"` is the only value that means "nothing but the servers I supplied".
|
|
223
|
+
Do not tell your users "only your tools are loaded" without checking that.
|
|
224
|
+
|
|
225
|
+
### Credentials that change
|
|
226
|
+
|
|
227
|
+
The SDK never writes MCP header values to disk. The thread store keeps header
|
|
228
|
+
names only, and a pre-0.3 store is migrated on first read. The runtime does the
|
|
229
|
+
same. So supply current values in one of three ways:
|
|
230
|
+
|
|
231
|
+
```ts
|
|
232
|
+
const daex = await createDaexChat({
|
|
233
|
+
home,
|
|
234
|
+
mcpHeaders: (key, server) => (server === "app" ? { Authorization: `Bearer ${token()}` } : undefined),
|
|
235
|
+
});
|
|
236
|
+
await daex.threads.open("support", { refresh: { mcpServers: { app: { type: "http", url, headers } } } });
|
|
237
|
+
await thread.updateMcpServers({ app: { type: "http", url: newUrl, headers: newHeaders } });
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
`refresh.mcpServers` replaces the servers on a resume or a recreate.
|
|
241
|
+
`thread.updateMcpServers()` replaces them on a live thread, for the next turn;
|
|
242
|
+
mid-turn the runtime queues them for the end of the turn, and a runtime before
|
|
243
|
+
1.2.81 refuses. Without any of the three, a server connects without its
|
|
244
|
+
headers and the SDK logs a line.
|
|
245
|
+
|
|
246
|
+
`mcpHeaders` may be async, and it runs before every `send`, `retry` and
|
|
247
|
+
`editLast` of a thread with remote servers: a token that changed (an OAuth
|
|
248
|
+
access token that expired) is pushed before the turn, and the provider resumes
|
|
249
|
+
the same conversation with it. `thread.refreshMcpHeaders()` does the same on
|
|
250
|
+
demand, right after you rotate a token.
|
|
251
|
+
|
|
252
|
+
Each server can also carry `allowedTools` / `disallowedTools` (bare tool
|
|
253
|
+
names). Codex enforces both; Claude enforces `disallowedTools` only; other
|
|
254
|
+
providers refuse both rather than ignore them. URL query
|
|
255
|
+
strings and stdio `env` values are still stored; do not put secrets there.
|
|
256
|
+
|
|
257
|
+
Tool results carry MCP `resource_link` items as `event.resourceLinks` on Codex
|
|
258
|
+
and on Claude (MCP tools only). Other providers do not pass them.
|
|
259
|
+
|
|
260
|
+
## Shaping the session
|
|
261
|
+
|
|
262
|
+
`threads.open` takes four options beyond the provider and model. Each one is
|
|
263
|
+
optional, each persists on the thread record, and omitting all four reproduces
|
|
264
|
+
0.1.x behavior exactly.
|
|
265
|
+
|
|
266
|
+
```ts
|
|
267
|
+
const thread = await daex.threads.open("assistant", {
|
|
268
|
+
provider: "claude",
|
|
269
|
+
model: "claude-sonnet-4-5",
|
|
270
|
+
instructions: { mode: "replace", text: "You are Ada, MyApp's assistant." },
|
|
271
|
+
cwd: "/Users/me/Library/Application Support/MyApp/work",
|
|
272
|
+
settingSources: "project",
|
|
273
|
+
permissions: {
|
|
274
|
+
allowedTools: ["mcp:catalog:*", "Read"],
|
|
275
|
+
deniedTools: ["Bash"],
|
|
276
|
+
fallback: "deny",
|
|
277
|
+
},
|
|
278
|
+
});
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
- **`instructions`** — your own system instructions, never a hidden first
|
|
282
|
+
message. A bare string means append. See [Threads](https://ade-app.dev/docs/sdk/threads).
|
|
283
|
+
- **`cwd`** — the absolute directory the provider runs in. Defaults to a scratch
|
|
284
|
+
workspace under `home`. Relative paths and `~` are refused.
|
|
285
|
+
- **`settingSources`** — which on-disk config the provider loads. `"none"` is the
|
|
286
|
+
default and is what every 0.1.x thread got.
|
|
287
|
+
- **`permissions`** — a policy object is the third form, alongside `"default"`
|
|
288
|
+
and `"always-allow"`. `fallback` is required. See
|
|
289
|
+
[Permissions](https://ade-app.dev/docs/sdk/permissions).
|
|
290
|
+
|
|
291
|
+
Each one reports back what the provider actually did, the same way
|
|
292
|
+
`mcpCapability` does. Read `thread.instructionsCapability`,
|
|
293
|
+
`thread.settingSourcesCapability` and `thread.permissionCapability`, and branch
|
|
294
|
+
on `level` — the presence of a report is never itself a guarantee.
|
|
295
|
+
|
|
296
|
+
An approval blocks the turn until it is answered. Handle `approval_request` with
|
|
297
|
+
`thread.approve(itemId, decision)`, restore cards after a reload with
|
|
298
|
+
`thread.pendingApprovals()`, or pass `fallback: "deny"` so nothing ever asks.
|
|
299
|
+
`approvalTimeoutMs` on the policy (opt-in, enforced by the SDK) declines an
|
|
300
|
+
approval-shaped request that this client saw and nobody answered in time.
|
|
301
|
+
|
|
302
|
+
On Codex, every MCP tool call raises an approval, and the policy judges it as
|
|
303
|
+
`mcp:<server>:<tool>`: `deniedTools`, then `allowedTools` /
|
|
304
|
+
`autoApproveMcpServers`, then `fallback`. `accept_always` remembers the answer
|
|
305
|
+
for the session only. On Codex, `sandboxRoot` still decides command and file
|
|
306
|
+
escapes, and the tool fields do not.
|
|
307
|
+
|
|
308
|
+
The CTO's own tool server is `daex-cto`. `ade-cto`, its name before the DAEX
|
|
309
|
+
rename, is a deprecated alias: `mcp:ade-cto:*` (or `ade-cto` in
|
|
310
|
+
`autoApproveMcpServers`) still matches the server, in allow and deny rules
|
|
311
|
+
alike. Write `daex-cto` in new policies.
|
|
312
|
+
|
|
313
|
+
On Claude (Agent SDK 0.3.280), `canUseTool` fires for MCP tools and for
|
|
314
|
+
commands that change things, not for commands Claude Code classifies as
|
|
315
|
+
read-only. `fallback: "ask"` stays `best-effort` for that reason.
|
|
316
|
+
|
|
317
|
+
On Claude a deny fallback does more than skip the prompt. It removes every
|
|
318
|
+
mutating built-in the policy does not name from the model's catalog, and scopes
|
|
319
|
+
MCP to the servers the policy names — including servers you injected yourself,
|
|
320
|
+
so name those in the policy too. `sandboxRoot` is not applied in that mode: an
|
|
321
|
+
unnamed tool is refused outright rather than contained. Read
|
|
322
|
+
`thread.permissionCapability.residual`, and see
|
|
323
|
+
[Permissions](https://ade-app.dev/docs/sdk/permissions).
|
|
324
|
+
|
|
325
|
+
## Electron
|
|
326
|
+
|
|
327
|
+
Run this from the main process, not the renderer. Spawn owns a child process
|
|
328
|
+
and a socket / named pipe.
|
|
329
|
+
|
|
330
|
+
```ts
|
|
331
|
+
const daex = await createDaexChat({
|
|
332
|
+
home: path.join(app.getPath("userData"), "ade"),
|
|
333
|
+
});
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
Do not write the bridge yourself. `@daex-dev/sdk/electron`,
|
|
337
|
+
`@daex-dev/sdk/electron/preload` and `@daex-dev/sdk/electron/renderer` ship one
|
|
338
|
+
function per process, with listener teardown on reload and the history-and-live
|
|
339
|
+
ordering rule already in code. None of the three depends on `electron`.
|
|
340
|
+
`@daex-dev/sdk/electron/global` types `window.ade`. For a `sandbox: true`
|
|
341
|
+
preload, point `webPreferences.preload` at
|
|
342
|
+
`require.resolve("@daex-dev/sdk/electron/preload-auto")` (default key and
|
|
343
|
+
prefix), copy the ten-line preload from the docs, or bundle `exposeDaexBridge`
|
|
344
|
+
into one file. `@daex-dev/sdk/electron/preload` alone only exports the function
|
|
345
|
+
and exposes nothing. See
|
|
346
|
+
[Electron](https://ade-app.dev/docs/sdk/electron).
|
|
347
|
+
|
|
348
|
+
The renderer does not configure threads. Pass `openOptions: (key, rendererOptions) => ThreadOpenOptions`
|
|
349
|
+
to `registerDaexIpc` and main decides; without it, only `provider`, `model`,
|
|
350
|
+
`title` and `reasoningEffort` cross (breaking in 0.3). `allowModel` gates model
|
|
351
|
+
choice. `registerDaexIpc` also accepts `() => client`, for a host that replaces
|
|
352
|
+
its client per account.
|
|
353
|
+
|
|
354
|
+
`onThreadRemoved(key, kind)` (0.5) fires for every delete and archive the served
|
|
355
|
+
client reports, whether the renderer or your own main-process code made it, so
|
|
356
|
+
your chat list stays exact. It follows a client swapped per account as soon as
|
|
357
|
+
the bridge serves a call. Refuse `threads.delete` or `threads.archive` in
|
|
358
|
+
`authorize` to stop the renderer from making them at all — there is no separate
|
|
359
|
+
deny list.
|
|
360
|
+
|
|
361
|
+
To ship the runtime inside a signed app instead of downloading it, install
|
|
362
|
+
`@ade-dev/runtime`, copy it into your resources, and pass
|
|
363
|
+
`...resolvePackagedRuntime(process.resourcesPath)` with `allowDownload: false`.
|
|
364
|
+
`doctor().runtime.source` then reports `"packaged"`. See
|
|
365
|
+
[Bundling](https://ade-app.dev/docs/sdk/bundling).
|
|
366
|
+
|
|
367
|
+
## Runtime exits
|
|
368
|
+
|
|
369
|
+
```ts
|
|
370
|
+
const daex = await createDaexChat({ home, autoRestart: true });
|
|
371
|
+
daex.on("exit", ({ code, signal, error }) => {});
|
|
372
|
+
daex.on("transport", ({ state }) => {}); // "closed" | "reconnected"
|
|
373
|
+
daex.on("restart", ({ attempt, ok }) => {});
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
When the runtime exits, each live thread gets a synthetic
|
|
377
|
+
`{ type: "status", turnStatus: "failed", message, synthetic: true }` envelope.
|
|
378
|
+
`autoRestart` (off by default; `true` = 5 attempts, 1 s doubling backoff)
|
|
379
|
+
respawns the runtime and re-opens every live thread. The client object stays
|
|
380
|
+
the same. A turn in flight is not resumed. See
|
|
381
|
+
[Runtime](https://ade-app.dev/docs/sdk/runtime#when-the-runtime-exits).
|
|
382
|
+
|
|
383
|
+
## The live seam test
|
|
384
|
+
|
|
385
|
+
`npm test` runs against an in-process fake runtime, so it can only prove the SDK
|
|
386
|
+
agrees with itself. `test/live.integration.test.ts` boots a real DAEX runtime and
|
|
387
|
+
checks that both sides agree on the wire. It is opt-in and skips itself when the
|
|
388
|
+
binary is not named.
|
|
389
|
+
|
|
390
|
+
Build the runtime first, then point the test at it:
|
|
391
|
+
|
|
392
|
+
```sh
|
|
393
|
+
cd apps/ade-cli && npm run build
|
|
394
|
+
cd packages/sdk
|
|
395
|
+
ADE_SDK_LIVE_BINARY=../../apps/ade-cli/dist/cli.cjs npm run test:live
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
That run spends no provider tokens. It covers the advertised capabilities, the
|
|
399
|
+
`providers.status` probe, the host configuration on the raw session summary,
|
|
400
|
+
the cwd refusals on both sides, `pendingApprovals()`, and a cold resume.
|
|
401
|
+
|
|
402
|
+
Add `ADE_SDK_LIVE_SPEND=1` to also run the cases that need a model turn. They
|
|
403
|
+
need a provider that is installed and logged in, and they cost a few cents on
|
|
404
|
+
the cheapest model in the catalog:
|
|
405
|
+
|
|
406
|
+
```sh
|
|
407
|
+
ADE_SDK_LIVE_BINARY=../../apps/ade-cli/dist/cli.cjs ADE_SDK_LIVE_SPEND=1 npm run test:live
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
Read the header of `test/live.integration.test.ts` before you trust a green
|
|
411
|
+
spending run. Claude's own permission default can accept every tool without
|
|
412
|
+
asking, and on a machine configured that way the approval cases record that
|
|
413
|
+
fact instead of proving the round trip.
|
|
414
|
+
|
|
415
|
+
## License
|
|
416
|
+
|
|
417
|
+
MIT. See [LICENSE](./LICENSE). DAEX (formerly ADE) itself remains AGPL-3.0-only; see the [ADE Runtime Embedding Exception](https://github.com/arul28/ADE/blob/main/RUNTIME-EMBEDDING-EXCEPTION.md) for shipping the runtime binary in your app.
|