@agentdocumentformat/cli 0.7.2

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 (117) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +45 -0
  3. package/dist/adf.mjs +162 -0
  4. package/dist/chunks/APEv2Parser-2CNNHMXV.mjs +22 -0
  5. package/dist/chunks/AiffParser-7BR4RL6G.mjs +162 -0
  6. package/dist/chunks/App-L5L37JI5.mjs +16747 -0
  7. package/dist/chunks/AsfParser-VVRSLFOM.mjs +538 -0
  8. package/dist/chunks/DsdiffParser-CMD4AX7A.mjs +156 -0
  9. package/dist/chunks/DsfParser-UOGZDS2M.mjs +94 -0
  10. package/dist/chunks/FlacParser-HB3T3CD4.mjs +23 -0
  11. package/dist/chunks/MP4Parser-66HBRUSX.mjs +973 -0
  12. package/dist/chunks/MatroskaParser-J3HUIMEW.mjs +579 -0
  13. package/dist/chunks/MpegParser-YW6LIUEW.mjs +442 -0
  14. package/dist/chunks/MusepackParser-PAUSXP7D.mjs +252 -0
  15. package/dist/chunks/OggParser-NUBV3GWC.mjs +359 -0
  16. package/dist/chunks/WavPackParser-WQAGT7TC.mjs +171 -0
  17. package/dist/chunks/WaveParser-EWLQVDX4.mjs +238 -0
  18. package/dist/chunks/adf-schema-JRU2BTOG.mjs +62 -0
  19. package/dist/chunks/build-QF5W473T.mjs +60 -0
  20. package/dist/chunks/chatgpt-subscription-BQGWYZXE.mjs +23 -0
  21. package/dist/chunks/chunk-2DIECGFL.mjs +6 -0
  22. package/dist/chunks/chunk-2NAP2ZF7.mjs +60 -0
  23. package/dist/chunks/chunk-3AT7IIP7.mjs +25696 -0
  24. package/dist/chunks/chunk-3GNIDM53.mjs +35 -0
  25. package/dist/chunks/chunk-3M4ZPOA3.mjs +1477 -0
  26. package/dist/chunks/chunk-4MQPTCXY.mjs +510 -0
  27. package/dist/chunks/chunk-5PO5PKRV.mjs +366 -0
  28. package/dist/chunks/chunk-5QU5VY7N.mjs +52 -0
  29. package/dist/chunks/chunk-5W7KES6P.mjs +436 -0
  30. package/dist/chunks/chunk-62NE4LG4.mjs +61 -0
  31. package/dist/chunks/chunk-64OKE4X3.mjs +45 -0
  32. package/dist/chunks/chunk-6GJ4QHRI.mjs +1278 -0
  33. package/dist/chunks/chunk-6VQEXLE2.mjs +144 -0
  34. package/dist/chunks/chunk-6XUV6EK6.mjs +41 -0
  35. package/dist/chunks/chunk-776TSXEP.mjs +43 -0
  36. package/dist/chunks/chunk-7CV2SA3H.mjs +285 -0
  37. package/dist/chunks/chunk-7MTRVW2U.mjs +3103 -0
  38. package/dist/chunks/chunk-7N2R2VCG.mjs +1434 -0
  39. package/dist/chunks/chunk-7T2YMTWL.mjs +374 -0
  40. package/dist/chunks/chunk-7XYNI52E.mjs +149 -0
  41. package/dist/chunks/chunk-APHX6HSV.mjs +7731 -0
  42. package/dist/chunks/chunk-APRU6PHC.mjs +40 -0
  43. package/dist/chunks/chunk-AUYKRQPJ.mjs +499 -0
  44. package/dist/chunks/chunk-DXWDD5XJ.mjs +136 -0
  45. package/dist/chunks/chunk-EWL5FG4I.mjs +39 -0
  46. package/dist/chunks/chunk-EYX2YLJW.mjs +117 -0
  47. package/dist/chunks/chunk-F5ELW46V.mjs +27 -0
  48. package/dist/chunks/chunk-G426FACA.mjs +49 -0
  49. package/dist/chunks/chunk-GEKSJHIV.mjs +2472 -0
  50. package/dist/chunks/chunk-HBUENVQL.mjs +570 -0
  51. package/dist/chunks/chunk-HPVFJYXR.mjs +112 -0
  52. package/dist/chunks/chunk-HWLWPXQ7.mjs +721 -0
  53. package/dist/chunks/chunk-I2HJYHFT.mjs +665 -0
  54. package/dist/chunks/chunk-I3UYSITV.mjs +68 -0
  55. package/dist/chunks/chunk-IC4JDZCI.mjs +3864 -0
  56. package/dist/chunks/chunk-IHDDCZBS.mjs +112 -0
  57. package/dist/chunks/chunk-IIGMZHQQ.mjs +10416 -0
  58. package/dist/chunks/chunk-KWFOS5WC.mjs +41 -0
  59. package/dist/chunks/chunk-LAZIXV2F.mjs +5290 -0
  60. package/dist/chunks/chunk-LFMB4PAA.mjs +10814 -0
  61. package/dist/chunks/chunk-M2RX3S2T.mjs +49 -0
  62. package/dist/chunks/chunk-M3WPIJYM.mjs +65 -0
  63. package/dist/chunks/chunk-NBTUWMGP.mjs +263 -0
  64. package/dist/chunks/chunk-NGK6PVSF.mjs +2676 -0
  65. package/dist/chunks/chunk-NZ7JTHEO.mjs +85 -0
  66. package/dist/chunks/chunk-OQN33RGQ.mjs +52 -0
  67. package/dist/chunks/chunk-RIX34QHC.mjs +2935 -0
  68. package/dist/chunks/chunk-SGUTYISF.mjs +16 -0
  69. package/dist/chunks/chunk-SLJ5L7PY.mjs +1473 -0
  70. package/dist/chunks/chunk-SLUKGXKH.mjs +68 -0
  71. package/dist/chunks/chunk-TMT32MXT.mjs +419 -0
  72. package/dist/chunks/chunk-UYY5M2PB.mjs +151 -0
  73. package/dist/chunks/chunk-VAUOM3IN.mjs +298 -0
  74. package/dist/chunks/chunk-VMHTYDH4.mjs +172 -0
  75. package/dist/chunks/chunk-VZS54AA5.mjs +200 -0
  76. package/dist/chunks/chunk-WFQUVXML.mjs +295 -0
  77. package/dist/chunks/chunk-X34PDRUH.mjs +809 -0
  78. package/dist/chunks/chunk-XNPZBLYL.mjs +33 -0
  79. package/dist/chunks/chunk-XX7OSWTO.mjs +157 -0
  80. package/dist/chunks/chunk-XYTWGHFS.mjs +600 -0
  81. package/dist/chunks/chunk-XYV3VCIX.mjs +336 -0
  82. package/dist/chunks/chunk-Y5ZLKFLE.mjs +1469 -0
  83. package/dist/chunks/chunk-ZJKXHM4Q.mjs +230 -0
  84. package/dist/chunks/cli-TCMBNZF6.mjs +1030 -0
  85. package/dist/chunks/commands-DTEKM4ZL.mjs +20 -0
  86. package/dist/chunks/daemon-ZC3FZ2P4.mjs +112449 -0
  87. package/dist/chunks/daemon-control-WDX7PMTC.mjs +300 -0
  88. package/dist/chunks/daemon-token-WRSULP7G.mjs +23 -0
  89. package/dist/chunks/devtools-H7CI2ZVG.mjs +85 -0
  90. package/dist/chunks/discord-IWDQJA7A.mjs +70588 -0
  91. package/dist/chunks/dist-C57KYFS2.mjs +4952 -0
  92. package/dist/chunks/dist-I3XBAGDL.mjs +11 -0
  93. package/dist/chunks/email-V4Q4VJON.mjs +58679 -0
  94. package/dist/chunks/environment-NX277MQG.mjs +15 -0
  95. package/dist/chunks/grok-subscription-4PYX7TBF.mjs +19 -0
  96. package/dist/chunks/layout-EPJQNFAI.mjs +22 -0
  97. package/dist/chunks/lib-N7FCZWKH.mjs +4038 -0
  98. package/dist/chunks/open-OTQDGDH5.mjs +36 -0
  99. package/dist/chunks/parser-JVY2PWSM.mjs +19 -0
  100. package/dist/chunks/pipeline-executor-BHBSJX2K.mjs +19 -0
  101. package/dist/chunks/react-IUIDQ5LX.mjs +11 -0
  102. package/dist/chunks/screen-54BUTYCW.mjs +27 -0
  103. package/dist/chunks/slack-3L5QTDZX.mjs +8113 -0
  104. package/dist/chunks/store-WR7TZJZS.mjs +32 -0
  105. package/dist/chunks/telegram-5ISVFBV3.mjs +14918 -0
  106. package/dist/chunks/terminal-O5WO7C5U.mjs +48 -0
  107. package/dist/chunks/theme-NORU4J74.mjs +20 -0
  108. package/dist/chunks/themes-F2FKU7CP.mjs +23 -0
  109. package/dist/chunks/token-6G3HCMNX.mjs +54 -0
  110. package/dist/chunks/token-util-UXYSDQIW.mjs +12 -0
  111. package/dist/chunks/tui-ODVYUIMT.mjs +197 -0
  112. package/dist/chunks/welcome-XHXFV7SH.mjs +32 -0
  113. package/dist/chunks/whatsapp-XSAMNGPJ.mjs +85412 -0
  114. package/dist/chunks/xterm-headless-YF53XWXE.mjs +3353 -0
  115. package/package.json +53 -0
  116. package/resources/wasm/coreutils.LICENSE +18 -0
  117. package/resources/wasm/coreutils.wasm +0 -0
@@ -0,0 +1,809 @@
1
+ import { createRequire as __adfCreateRequire } from 'node:module';
2
+ import { fileURLToPath as __adfFileURLToPath } from 'node:url';
3
+ import { dirname as __adfDirname } from 'node:path';
4
+ const require = __adfCreateRequire(import.meta.url);
5
+ const __filename = __adfFileURLToPath(import.meta.url);
6
+ const __dirname = __adfDirname(__filename);
7
+ import {
8
+ DaemonError,
9
+ MAIN_LOOP
10
+ } from "./chunk-XNPZBLYL.mjs";
11
+ import {
12
+ cjs
13
+ } from "./chunk-SGUTYISF.mjs";
14
+ import {
15
+ daemon_url_exports
16
+ } from "./chunk-G426FACA.mjs";
17
+
18
+ // src/main/tui/api/sse.ts
19
+ var EventStream = class {
20
+ options;
21
+ fetchImpl;
22
+ controller = null;
23
+ closed = !1;
24
+ started = !1;
25
+ attempt = 0;
26
+ hasOpened = !1;
27
+ lastCursor;
28
+ seen = /* @__PURE__ */ new Set();
29
+ seenOrder = [];
30
+ idleTimer = null;
31
+ retryTimer = null;
32
+ info = { state: "idle", attempt: 0 };
33
+ constructor(options) {
34
+ this.options = options, this.fetchImpl = options.fetch ?? globalThis.fetch.bind(globalThis), this.lastCursor = options.since ?? -1;
35
+ }
36
+ get cursor() {
37
+ return this.lastCursor;
38
+ }
39
+ get connection() {
40
+ return this.info;
41
+ }
42
+ start() {
43
+ return this.started ? this : (this.started = !0, this.connect(), this);
44
+ }
45
+ close() {
46
+ this.closed = !0, this.retryTimer && clearTimeout(this.retryTimer), this.clearIdle(), this.controller?.abort(), this.setState({ state: "closed", attempt: this.attempt });
47
+ }
48
+ /** Drop the current connection and reconnect now (e.g. user-requested). */
49
+ reconnect() {
50
+ if (!this.closed) {
51
+ if (this.retryTimer) {
52
+ clearTimeout(this.retryTimer), this.retryTimer = null, this.connect();
53
+ return;
54
+ }
55
+ this.controller?.abort();
56
+ }
57
+ }
58
+ setState(info) {
59
+ this.info = info;
60
+ try {
61
+ this.options.onState?.(info);
62
+ } catch {
63
+ }
64
+ }
65
+ buildUrl() {
66
+ let params = new URLSearchParams();
67
+ this.options.agentId && params.set("agentId", this.options.agentId), this.lastCursor >= 0 ? params.set("since", String(this.lastCursor)) : this.options.replay || params.set("since", String(Number.MAX_SAFE_INTEGER));
68
+ let qs = params.toString();
69
+ return `${this.options.baseUrl}/events${qs ? `?${qs}` : ""}`;
70
+ }
71
+ async connect() {
72
+ if (this.closed) return;
73
+ this.retryTimer = null;
74
+ let resumed = this.hasOpened;
75
+ this.setState({ state: this.hasOpened || this.attempt > 0 ? "reconnecting" : "connecting", attempt: this.attempt });
76
+ let controller = new AbortController();
77
+ this.controller = controller;
78
+ let failure;
79
+ try {
80
+ let response = await this.fetchImpl(this.buildUrl(), {
81
+ headers: { Accept: "text/event-stream", ...typeof this.options.headers == "function" ? this.options.headers() : this.options.headers ?? {} },
82
+ signal: controller.signal
83
+ });
84
+ if (!response.ok || !response.body)
85
+ throw new Error(`HTTP ${response.status} ${response.statusText}`.trim());
86
+ this.attempt = 0, this.hasOpened = !0, this.setState({ state: "open", attempt: 0, resumed }), this.armIdle(), await this.read(response.body, controller), failure = "stream ended";
87
+ } catch (err) {
88
+ failure = controller.signal.aborted && this.closed ? void 0 : errorMessage(err);
89
+ } finally {
90
+ this.clearIdle();
91
+ }
92
+ if (this.closed) return;
93
+ this.attempt += 1;
94
+ let delay = this.backoff();
95
+ this.setState({ state: "reconnecting", attempt: this.attempt, error: failure, retryInMs: delay }), this.retryTimer = setTimeout(() => {
96
+ this.connect();
97
+ }, delay);
98
+ }
99
+ backoff() {
100
+ let min = this.options.minBackoffMs ?? 500, max = this.options.maxBackoffMs ?? 1e4, exp = Math.min(max, min * 2 ** Math.max(0, this.attempt - 1));
101
+ return Math.round(exp / 2 + Math.random() * (exp / 2));
102
+ }
103
+ armIdle() {
104
+ this.clearIdle();
105
+ let timeout = this.options.idleTimeoutMs ?? 75e3;
106
+ this.idleTimer = setTimeout(() => this.controller?.abort(new Error("idle timeout")), timeout);
107
+ }
108
+ clearIdle() {
109
+ this.idleTimer && clearTimeout(this.idleTimer), this.idleTimer = null;
110
+ }
111
+ async read(body, controller) {
112
+ let reader = body.getReader(), decoder = new TextDecoder(), buffer = "", abort = () => {
113
+ reader.cancel().catch(() => {
114
+ });
115
+ };
116
+ controller.signal.addEventListener("abort", abort, { once: !0 });
117
+ try {
118
+ for (; ; ) {
119
+ let { value, done } = await reader.read();
120
+ if (done) break;
121
+ this.armIdle(), buffer += decoder.decode(value, { stream: !0 }).replace(/\r\n?/g, `
122
+ `);
123
+ let boundary = buffer.indexOf(`
124
+
125
+ `);
126
+ for (; boundary >= 0; ) {
127
+ let block = buffer.slice(0, boundary);
128
+ buffer = buffer.slice(boundary + 2), this.handleBlock(block), boundary = buffer.indexOf(`
129
+
130
+ `);
131
+ }
132
+ }
133
+ } finally {
134
+ controller.signal.removeEventListener("abort", abort);
135
+ }
136
+ if (controller.signal.aborted) throw controller.signal.reason instanceof Error ? controller.signal.reason : new Error("aborted");
137
+ }
138
+ handleBlock(block) {
139
+ let data = [];
140
+ for (let line of block.split(`
141
+ `)) {
142
+ if (!line || line.startsWith(":")) continue;
143
+ let colon = line.indexOf(":"), field = colon < 0 ? line : line.slice(0, colon), value = colon < 0 ? "" : line.slice(colon + 1).replace(/^ /, "");
144
+ field === "data" && data.push(value);
145
+ }
146
+ if (data.length === 0) return;
147
+ let frame;
148
+ try {
149
+ frame = JSON.parse(data.join(`
150
+ `));
151
+ } catch {
152
+ return;
153
+ }
154
+ if (!frame || typeof frame != "object" || !frame.event) return;
155
+ typeof frame.cursor == "number" && (frame.cursor < this.lastCursor && this.forgetCursorKeys(), this.lastCursor = frame.cursor);
156
+ let key = dedupeKey(frame);
157
+ if (key) {
158
+ if (this.seen.has(key)) return;
159
+ this.remember(key);
160
+ }
161
+ try {
162
+ this.options.onEvent(frame);
163
+ } catch {
164
+ }
165
+ }
166
+ remember(key) {
167
+ this.seen.add(key), this.seenOrder.push(key);
168
+ let cap = this.options.dedupeWindow ?? 5e3;
169
+ for (; this.seenOrder.length > cap; ) {
170
+ let old = this.seenOrder.shift();
171
+ old && this.seen.delete(old);
172
+ }
173
+ }
174
+ forgetCursorKeys() {
175
+ for (let i = this.seenOrder.length - 1; i >= 0; i--) {
176
+ let key = this.seenOrder[i];
177
+ key.startsWith("c:") && (this.seen.delete(key), this.seenOrder.splice(i, 1));
178
+ }
179
+ }
180
+ };
181
+ function dedupeKey(frame) {
182
+ let { event } = frame;
183
+ return event.agent_id && typeof event.seq == "number" && event.seq > 0 ? `a:${event.agent_id}:${event.seq}` : typeof frame.cursor == "number" ? `c:${frame.cursor}` : null;
184
+ }
185
+ function errorMessage(err) {
186
+ if (err instanceof Error) {
187
+ let cause = err.cause;
188
+ return cause instanceof Error && cause.message ? cause.message : err.message;
189
+ }
190
+ return String(err);
191
+ }
192
+
193
+ // src/main/tui/api/normalize.ts
194
+ var obj = (v) => v && typeof v == "object" && !Array.isArray(v) ? v : {}, arr = (v) => Array.isArray(v) ? v : [], num = (v) => typeof v == "number" && Number.isFinite(v) ? v : 0;
195
+ function normalizeRuntime(raw) {
196
+ let r = obj(raw), daemon = obj(r.daemon), providers = obj(r.providers), network = obj(r.network), mesh = obj(network.mesh), websocket = obj(network.websocket);
197
+ return {
198
+ ...r,
199
+ daemon: { ...daemon, pid: num(daemon.pid), uptime: num(daemon.uptime) },
200
+ settings: obj(r.settings),
201
+ providers: { ...providers, providers: arr(providers.providers) },
202
+ auth: obj(r.auth),
203
+ mcp: obj(r.mcp),
204
+ adapters: obj(r.adapters),
205
+ network: { ...network, mesh: { ...mesh, status: mesh.status ?? null }, agents: arr(network.agents), websocket: { ...websocket, activeConnections: num(websocket.activeConnections) } },
206
+ compute: r.compute && typeof r.compute == "object" ? r.compute : null,
207
+ agents: arr(r.agents)
208
+ };
209
+ }
210
+
211
+ // src/main/tui/api/client.ts
212
+ var { localDaemonToken, resolveDaemonToken, resolveDaemonUrl } = cjs(daemon_url_exports), enc = encodeURIComponent;
213
+ function sameOrigin(a, b) {
214
+ try {
215
+ return new URL(a).origin === new URL(b).origin;
216
+ } catch {
217
+ return !1;
218
+ }
219
+ }
220
+ var DaemonClient = class _DaemonClient {
221
+ baseUrl;
222
+ token;
223
+ fetchImpl;
224
+ timeoutMs;
225
+ options;
226
+ constructor(options = {}) {
227
+ this.baseUrl = resolveDaemonUrl(options.baseUrl), this.token = resolveDaemonToken(options.token, options.env ?? process.env, options.localToken ? this.baseUrl : void 0), this.fetchImpl = options.fetch ?? globalThis.fetch.bind(globalThis), this.timeoutMs = options.timeoutMs ?? 15e3, this.options = options;
228
+ }
229
+ /**
230
+ * Same transport (fetch, timeout) against another daemon. The current token
231
+ * is carried over only to the same origin; another origin gets `token`, or
232
+ * ADF_DAEMON_TOKEN, or none — never this daemon's bearer token.
233
+ */
234
+ withBaseUrl(baseUrl, token) {
235
+ let carried = sameOrigin(this.baseUrl, resolveDaemonUrl(baseUrl)) ? this.token : void 0;
236
+ return new _DaemonClient({ ...this.options, baseUrl, token: token ?? carried });
237
+ }
238
+ /** Whether requests carry a bearer token. */
239
+ get hasToken() {
240
+ return !!this.token;
241
+ }
242
+ // --- transport ------------------------------------------------------------
243
+ url(path, query) {
244
+ let qs = query ? buildQuery(query) : "";
245
+ return `${this.baseUrl}${path}${qs}`;
246
+ }
247
+ headers(extra = {}) {
248
+ return {
249
+ Accept: "application/json",
250
+ ...this.token ? { Authorization: `Bearer ${this.token}` } : {},
251
+ ...extra
252
+ };
253
+ }
254
+ /**
255
+ * The daemon answered 401: with `localToken` and no explicit token, pick up
256
+ * a token file that appeared or changed since (daemon first start). True
257
+ * when the token changed, so the request is worth one retry.
258
+ */
259
+ refreshLocalToken() {
260
+ if (!this.options.localToken || this.options.token) return !1;
261
+ let env = this.options.env ?? process.env;
262
+ if (env.ADF_DAEMON_TOKEN) return !1;
263
+ let fresh = localDaemonToken(this.baseUrl, env);
264
+ return !fresh || fresh === this.token ? !1 : (this.token = fresh, !0);
265
+ }
266
+ async request(method, path, options = {}, retried = !1) {
267
+ let controller = new AbortController(), timeoutMs = options.timeoutMs ?? this.timeoutMs, timer = setTimeout(() => controller.abort(new Error("timeout")), timeoutMs), onAbort = () => controller.abort(options.signal?.reason);
268
+ options.signal?.addEventListener("abort", onAbort, { once: !0 });
269
+ let response;
270
+ try {
271
+ response = await this.fetchImpl(this.url(path, options.query), {
272
+ method,
273
+ headers: this.headers(options.body !== void 0 ? { "Content-Type": "application/json" } : {}),
274
+ body: options.body !== void 0 ? JSON.stringify(options.body) : void 0,
275
+ signal: controller.signal
276
+ });
277
+ } catch (err) {
278
+ let reason = controller.signal.aborted && !options.signal?.aborted ? `timed out after ${timeoutMs}ms` : errorMessage2(err);
279
+ throw new DaemonError(`Cannot reach daemon at ${this.baseUrl}: ${reason}`, null);
280
+ } finally {
281
+ clearTimeout(timer), options.signal?.removeEventListener("abort", onAbort);
282
+ }
283
+ let text = await response.text(), body = null;
284
+ if (text.trim())
285
+ try {
286
+ body = JSON.parse(text);
287
+ } catch {
288
+ body = text;
289
+ }
290
+ if (!response.ok) {
291
+ if (response.status === 401 && !retried && this.refreshLocalToken()) return this.request(method, path, options, !0);
292
+ let message = isRecord(body) && typeof body.error == "string" ? body.error : `HTTP ${response.status} ${response.statusText}`;
293
+ throw new DaemonError(message, response.status, body);
294
+ }
295
+ return body;
296
+ }
297
+ get(path, query) {
298
+ return this.request("GET", path, { query });
299
+ }
300
+ post(path, body, query) {
301
+ return this.request("POST", path, { body, query });
302
+ }
303
+ put(path, body, query) {
304
+ return this.request("PUT", path, { body, query });
305
+ }
306
+ patch(path, body) {
307
+ return this.request("PATCH", path, { body });
308
+ }
309
+ del(path, query) {
310
+ return this.request("DELETE", path, { query });
311
+ }
312
+ /** Live umbilical events (SSE) with auto-reconnect. Call `.start()` on the result. */
313
+ events(options) {
314
+ return new EventStream({ ...options, baseUrl: this.baseUrl, headers: () => this.headers({ Accept: "text/event-stream" }), fetch: this.fetchImpl });
315
+ }
316
+ // --- daemon ---------------------------------------------------------------
317
+ health() {
318
+ return this.get("/health");
319
+ }
320
+ /** GET /runtime, normalized: a partial or older daemon's response has every section the views read. */
321
+ async runtime() {
322
+ return normalizeRuntime(await this.get("/runtime"));
323
+ }
324
+ providers() {
325
+ return this.get("/runtime/providers");
326
+ }
327
+ authStatus() {
328
+ return this.get("/runtime/auth");
329
+ }
330
+ runtimeSettings() {
331
+ return this.get("/runtime/settings");
332
+ }
333
+ runtimeMcp() {
334
+ return this.get("/runtime/mcp");
335
+ }
336
+ runtimeAdapters() {
337
+ return this.get("/runtime/adapters");
338
+ }
339
+ network() {
340
+ return this.get("/runtime/network");
341
+ }
342
+ usage() {
343
+ return this.get("/runtime/usage");
344
+ }
345
+ models(provider, agentId) {
346
+ return this.get("/runtime/models", { provider, agentId });
347
+ }
348
+ settings() {
349
+ return this.get("/settings");
350
+ }
351
+ setting(key) {
352
+ return this.get(`/settings/${enc(key)}`);
353
+ }
354
+ putSetting(key, value) {
355
+ return this.put(`/settings/${enc(key)}`, { value });
356
+ }
357
+ /** Add an API-key provider. The key goes to the daemon secret store; the reply never carries it. */
358
+ addProvider(input) {
359
+ return this.post("/runtime/providers", input);
360
+ }
361
+ removeProvider(id) {
362
+ return this.del(`/runtime/providers/${enc(id)}`);
363
+ }
364
+ // --- compute (containers) and the mesh --------------------------------------
365
+ // Shapes are the daemon services' own; the Runtime view renders them as trees.
366
+ computeStatus() {
367
+ return this.get("/compute/status");
368
+ }
369
+ computeContainers() {
370
+ return this.get("/compute/containers");
371
+ }
372
+ meshStatus() {
373
+ return this.get("/network/mesh");
374
+ }
375
+ setMesh(enabled) {
376
+ return this.post(`/network/mesh/${enabled ? "enable" : "disable"}`);
377
+ }
378
+ meshServer() {
379
+ return this.get("/network/server");
380
+ }
381
+ meshServerAction(action) {
382
+ return this.post(`/network/server/${action}`);
383
+ }
384
+ /** `{ addresses: { hostname, addresses: [{ iface, address, family }] } }` (web/model `parseLan`). */
385
+ lanAddresses() {
386
+ return this.get("/network/mesh/lan-addresses");
387
+ }
388
+ // --- subscription provider sign-in (ChatGPT, Grok) ------------------------
389
+ // Sign-in flows themselves (browser, callback server, polling) live in
390
+ // cli/auth-flow.ts over `request`; these are the plain reads and sign-out.
391
+ subscriptionStatus(provider) {
392
+ return this.get(`/auth/${provider}/status`);
393
+ }
394
+ logoutSubscription(provider) {
395
+ return this.post(`/auth/${provider}/logout`);
396
+ }
397
+ // --- owner identity + agent creation --------------------------------------
398
+ // create / restore / unlock answer loopback callers only (403 loopback_only).
399
+ // Nothing here logs or keeps a request or response body.
400
+ identity() {
401
+ return this.get("/identity");
402
+ }
403
+ /** 201 with the 12 words, returned this once. `passphrase` only for file storage. */
404
+ createIdentity(passphrase) {
405
+ return this.post("/identity/create", passphrase ? { passphrase } : {});
406
+ }
407
+ restoreIdentity(mnemonic, passphrase) {
408
+ return this.post("/identity/restore", { mnemonic, ...passphrase ? { passphrase } : {} });
409
+ }
410
+ unlockIdentity(passphrase) {
411
+ return this.post("/identity/unlock", { passphrase });
412
+ }
413
+ lockIdentity() {
414
+ return this.post("/identity/lock");
415
+ }
416
+ confirmIdentityBackup() {
417
+ return this.post("/identity/confirm-backup");
418
+ }
419
+ templates() {
420
+ return this.get("/templates");
421
+ }
422
+ /** Studio's "new agent", headless. 409 identity_not_ready / name_taken, 422 template_*. */
423
+ createAgent(input = {}) {
424
+ return this.post("/agents/create", input);
425
+ }
426
+ // --- agents ---------------------------------------------------------------
427
+ agents() {
428
+ return this.get("/agents");
429
+ }
430
+ agent(agentId) {
431
+ return this.get(`/agents/${enc(agentId)}`);
432
+ }
433
+ status(agentId) {
434
+ return this.get(`/agents/${enc(agentId)}/status`);
435
+ }
436
+ agentUsage(agentId) {
437
+ return this.get(`/agents/${enc(agentId)}/usage`);
438
+ }
439
+ /** Load an .adf file from disk. Direct loads bypass review unless `requireReview`. */
440
+ load(filePath, requireReview = !1) {
441
+ return this.post("/agents/load", { filePath, requireReview });
442
+ }
443
+ review(filePath) {
444
+ return this.get("/agents/review", { filePath });
445
+ }
446
+ acceptReview(filePath) {
447
+ return this.post("/agents/review/accept", { filePath });
448
+ }
449
+ start(agentId) {
450
+ return this.post(`/agents/${enc(agentId)}/start`);
451
+ }
452
+ stop(agentId) {
453
+ return this.post(`/agents/${enc(agentId)}/stop`);
454
+ }
455
+ unload(agentId) {
456
+ return this.post(`/agents/${enc(agentId)}/unload`);
457
+ }
458
+ /**
459
+ * End one loop's running turn (default main) and leave it idle; the agent
460
+ * keeps accepting chats, triggers and timers. What Esc does.
461
+ */
462
+ interrupt(agentId, loop) {
463
+ return this.post(`/agents/${enc(agentId)}/interrupt`, void 0, loop && loop !== MAIN_LOOP ? { loop } : void 0);
464
+ }
465
+ /**
466
+ * Hard abort of one loop's turn (default main): the daemon leaves that
467
+ * executor stopped until the agent is reloaded. Prefer `interrupt`.
468
+ */
469
+ abort(agentId, loop) {
470
+ return this.post(`/agents/${enc(agentId)}/abort`, void 0, loop && loop !== MAIN_LOOP ? { loop } : void 0);
471
+ }
472
+ /** Scan directories and start every reviewed agent configured for autostart. */
473
+ autostart(trackedDirs, maxDepth) {
474
+ return this.post("/agents/autostart", { trackedDirs, ...maxDepth !== void 0 ? { maxDepth } : {} });
475
+ }
476
+ /** Compact one loop's history now. 409 while that loop is mid-turn. */
477
+ compact(agentId, loop) {
478
+ return this.post(`/agents/${enc(agentId)}/compact`, void 0, loop && loop !== MAIN_LOOP ? { loop } : void 0);
479
+ }
480
+ setState(agentId, state) {
481
+ return this.post(`/agents/${enc(agentId)}/state`, { state });
482
+ }
483
+ // --- conversation (loop-aware; absent loop = main) --------------------------
484
+ /** Owner chat into a loop. Unknown loop: 404, disabled loop: 409 — before any turn is queued. */
485
+ chat(agentId, text, loop) {
486
+ return this.post(`/agents/${enc(agentId)}/chat`, { text, ...loop && loop !== MAIN_LOOP ? { loop } : {} });
487
+ }
488
+ chatHistory(agentId, options = {}) {
489
+ return this.get(`/agents/${enc(agentId)}/chat`, { loop: options.loop, limit: options.limit });
490
+ }
491
+ clearChat(agentId, loop) {
492
+ return this.del(`/agents/${enc(agentId)}/chat`, { loop });
493
+ }
494
+ /** Raw persisted loop rows. Default page is the newest `limit` (50) rows. */
495
+ loopHistory(agentId, options = {}) {
496
+ return this.get(`/agents/${enc(agentId)}/loop`, { loop: options.loop, limit: options.limit, offset: options.offset });
497
+ }
498
+ trigger(agentId, dispatch) {
499
+ return this.post(`/agents/${enc(agentId)}/trigger`, dispatch);
500
+ }
501
+ // --- loops ----------------------------------------------------------------
502
+ loops(agentId) {
503
+ return this.get(`/agents/${enc(agentId)}/loops`);
504
+ }
505
+ loop(agentId, name) {
506
+ return this.get(`/agents/${enc(agentId)}/loops/${enc(name)}`);
507
+ }
508
+ createLoop(agentId, input) {
509
+ return this.post(`/agents/${enc(agentId)}/loops`, input);
510
+ }
511
+ updateLoop(agentId, name, patch) {
512
+ return this.patch(`/agents/${enc(agentId)}/loops/${enc(name)}`, patch);
513
+ }
514
+ setLoopEnabled(agentId, name, enabled) {
515
+ return this.updateLoop(agentId, name, { enabled });
516
+ }
517
+ /** Stops the loop, archives its stream to adf_audit, then removes it. */
518
+ deleteLoop(agentId, name) {
519
+ return this.del(`/agents/${enc(agentId)}/loops/${enc(name)}`);
520
+ }
521
+ // --- config / document / mind ---------------------------------------------
522
+ config(agentId) {
523
+ return this.get(`/agents/${enc(agentId)}/config`);
524
+ }
525
+ putConfig(agentId, config) {
526
+ return this.put(`/agents/${enc(agentId)}/config`, config);
527
+ }
528
+ document(agentId) {
529
+ return this.get(`/agents/${enc(agentId)}/document`);
530
+ }
531
+ putDocument(agentId, content) {
532
+ return this.put(`/agents/${enc(agentId)}/document`, { content });
533
+ }
534
+ mind(agentId) {
535
+ return this.get(`/agents/${enc(agentId)}/mind`);
536
+ }
537
+ putMind(agentId, content) {
538
+ return this.put(`/agents/${enc(agentId)}/mind`, { content });
539
+ }
540
+ // --- files ----------------------------------------------------------------
541
+ files(agentId) {
542
+ return this.get(`/agents/${enc(agentId)}/files`);
543
+ }
544
+ file(agentId, path) {
545
+ return this.get(`/agents/${enc(agentId)}/files/content`, { path });
546
+ }
547
+ writeFile(agentId, path, input) {
548
+ return this.put(`/agents/${enc(agentId)}/files/content`, input, { path });
549
+ }
550
+ deleteFile(agentId, path) {
551
+ return this.del(`/agents/${enc(agentId)}/files/content`, { path });
552
+ }
553
+ renameFile(agentId, oldPath, newPath) {
554
+ return this.post(`/agents/${enc(agentId)}/files/rename`, { oldPath, newPath });
555
+ }
556
+ renameFolder(agentId, oldPrefix, newPrefix) {
557
+ return this.post(`/agents/${enc(agentId)}/files/rename-folder`, { oldPrefix, newPrefix });
558
+ }
559
+ setFileProtection(agentId, path, protection) {
560
+ return this.patch(`/agents/${enc(agentId)}/files/protection`, { path, protection });
561
+ }
562
+ setFileAuthorized(agentId, path, authorized) {
563
+ return this.patch(`/agents/${enc(agentId)}/files/authorized`, { path, authorized });
564
+ }
565
+ // --- mesh messaging -------------------------------------------------------
566
+ inbox(agentId, status) {
567
+ return this.get(`/agents/${enc(agentId)}/inbox`, { status });
568
+ }
569
+ clearInbox(agentId) {
570
+ return this.del(`/agents/${enc(agentId)}/inbox`);
571
+ }
572
+ outbox(agentId, status) {
573
+ return this.get(`/agents/${enc(agentId)}/outbox`, { status });
574
+ }
575
+ // --- timers (a timer's `loop` is how an inner loop runs on a schedule) -----
576
+ timers(agentId) {
577
+ return this.get(`/agents/${enc(agentId)}/timers`);
578
+ }
579
+ createTimer(agentId, input) {
580
+ return this.post(`/agents/${enc(agentId)}/timers`, input);
581
+ }
582
+ /** `loop` present moves the timer to that loop (daemons before loop-aware timers ignore it). */
583
+ updateTimer(agentId, timerId, input) {
584
+ return this.put(`/agents/${enc(agentId)}/timers/${timerId}`, input);
585
+ }
586
+ deleteTimer(agentId, timerId) {
587
+ return this.del(`/agents/${enc(agentId)}/timers/${timerId}`);
588
+ }
589
+ // --- meta / identity (metadata only; secret values are never listed) ------
590
+ meta(agentId) {
591
+ return this.get(`/agents/${enc(agentId)}/meta`);
592
+ }
593
+ setMeta(agentId, key, value, protection) {
594
+ return this.put(`/agents/${enc(agentId)}/meta/${enc(key)}`, { value, ...protection ? { protection } : {} });
595
+ }
596
+ deleteMeta(agentId, key) {
597
+ return this.del(`/agents/${enc(agentId)}/meta/${enc(key)}`);
598
+ }
599
+ identities(agentId) {
600
+ return this.get(`/agents/${enc(agentId)}/identities`);
601
+ }
602
+ // --- logs / tables / umbilical replay -------------------------------------
603
+ logs(agentId, options = {}) {
604
+ return this.get(`/agents/${enc(agentId)}/logs`, options);
605
+ }
606
+ logsAfter(agentId, afterId) {
607
+ return this.get(`/agents/${enc(agentId)}/logs/after`, { afterId });
608
+ }
609
+ tables(agentId) {
610
+ return this.get(`/agents/${enc(agentId)}/tables`);
611
+ }
612
+ table(agentId, table, options = {}) {
613
+ return this.get(`/agents/${enc(agentId)}/tables/${enc(table)}`, options);
614
+ }
615
+ umbilicalReplay(agentId, options = {}) {
616
+ return this.get(`/agents/${enc(agentId)}/umbilical/events`, { since_seq: options.sinceSeq, limit: options.limit });
617
+ }
618
+ // --- HIL: tasks (approvals), asks, suspend --------------------------------
619
+ tasks(agentId, options = {}) {
620
+ return this.get(`/agents/${enc(agentId)}/tasks`, options);
621
+ }
622
+ task(agentId, taskId) {
623
+ return this.get(`/agents/${enc(agentId)}/tasks/${enc(taskId)}`);
624
+ }
625
+ resolveTask(agentId, taskId, input) {
626
+ return this.post(`/agents/${enc(agentId)}/tasks/${enc(taskId)}/resolve`, input);
627
+ }
628
+ /** Approve ▸ Always approve: un-restricts the pending request's tool on the
629
+ * host config, then approves it. DaemonError status 409 when the request is
630
+ * a protection override / one-shot approval / locked declaration. */
631
+ alwaysApproveTask(agentId, taskId) {
632
+ return this.post(`/agents/${enc(agentId)}/tasks/${enc(taskId)}/always-approve`, {});
633
+ }
634
+ /** Approve every pending gated approval (all loops, or just `loop`); protection overrides are skipped. */
635
+ approveAllTasks(agentId, loop) {
636
+ return this.post(`/agents/${enc(agentId)}/tasks/approve-all`, loop ? { loop } : {});
637
+ }
638
+ // --- tracked agent folders (Studio's tracked directories) -----------------
639
+ trackedDirs() {
640
+ return this.get("/tracked-dirs");
641
+ }
642
+ /** Track an absolute folder now and autostart its agents (review gate applies). 409 when already tracked. */
643
+ trackDir(path) {
644
+ return this.post("/tracked-dirs", { path });
645
+ }
646
+ /** Stop tracking (files are never deleted). `unload` also unloads the agents loaded from under it. */
647
+ untrackDir(path, options = {}) {
648
+ return this.del("/tracked-dirs", { path, unload: options.unload });
649
+ }
650
+ /** The agents in one tracked folder and where each stands (loaded, needs review, not autostart, stopped + load error). */
651
+ folderAgents(path) {
652
+ return this.get("/tracked-dirs/agents", { path });
653
+ }
654
+ /**
655
+ * Every tracked folder with its agents (GET /tracked-dirs/agents/all). On a
656
+ * daemon without that route: GET /tracked-dirs, then each folder's agents.
657
+ */
658
+ async trackedAgents() {
659
+ try {
660
+ return await this.get("/tracked-dirs/agents/all");
661
+ } catch (err) {
662
+ if (!(err instanceof DaemonError) || err.status !== 404) throw err;
663
+ }
664
+ let list = await this.trackedDirs(), folders = await Promise.all(list.directories.map(async (entry) => {
665
+ let agents = entry.exists ? await this.folderAgents(entry.path).then((r) => r.agents, () => []) : [];
666
+ return { ...entry, agents };
667
+ }));
668
+ return { maxDepth: list.maxDepth, folders };
669
+ }
670
+ asks(agentId) {
671
+ return this.get(`/agents/${enc(agentId)}/asks`);
672
+ }
673
+ /** `loop` picks the asking loop when request ids repeat across loops. */
674
+ answerAsk(agentId, requestId, answer, loop) {
675
+ return this.post(`/agents/${enc(agentId)}/asks/${enc(requestId)}/respond`, { answer, ...loop ? { loop } : {} });
676
+ }
677
+ respondSuspend(agentId, resume) {
678
+ return this.post(`/agents/${enc(agentId)}/suspend/respond`, { resume });
679
+ }
680
+ // --- per-agent runtime diagnostics ----------------------------------------
681
+ agentRuntime(agentId) {
682
+ return this.get(`/agents/${enc(agentId)}/runtime`);
683
+ }
684
+ agentTriggers(agentId) {
685
+ return this.get(`/agents/${enc(agentId)}/runtime/triggers`);
686
+ }
687
+ agentMcp(agentId) {
688
+ return this.get(`/agents/${enc(agentId)}/runtime/mcp`);
689
+ }
690
+ agentAdapters(agentId) {
691
+ return this.get(`/agents/${enc(agentId)}/runtime/adapters`);
692
+ }
693
+ // --- MCP servers (per agent) ------------------------------------------------
694
+ /** Add a server to the agent config (it connects on start, or with restartMcpServer now). */
695
+ attachMcpServer(agentId, server) {
696
+ return this.post(`/agents/${enc(agentId)}/mcp/servers`, { server });
697
+ }
698
+ /** Remove it and delete its stored credentials (`mcp:<namespace>:*`; the package, else the server name). */
699
+ detachMcpServer(agentId, serverName, credentialNamespace) {
700
+ return this.request("DELETE", `/agents/${enc(agentId)}/mcp/servers/${enc(serverName)}`, { query: { credentialNamespace } });
701
+ }
702
+ /** (Re)connect one server of a running agent now; the outcome carries tools found or the error. */
703
+ restartMcpServer(agentId, serverName) {
704
+ return this.request("POST", `/agents/${enc(agentId)}/mcp/servers/${enc(serverName)}/restart`, { timeoutMs: 18e4 });
705
+ }
706
+ /** Store one env value for an MCP server in the agent's identity store (`mcp:<namespace>:<key>`, sealed). */
707
+ setMcpCredential(agentId, namespace, envKey, value, opts = {}) {
708
+ return this.put(`/agents/${enc(agentId)}/mcp/credentials`, { npmPackage: namespace, envKey, value, ...opts.replace ? { replace: !0 } : {} });
709
+ }
710
+ /** What is stored for an MCP server's env keys: metadata only, never values. */
711
+ mcpCredentials(agentId, namespace) {
712
+ return this.get(`/agents/${enc(agentId)}/mcp/credentials`, { npmPackage: namespace });
713
+ }
714
+ /** Install an MCP server package on the daemon host (npm or Python). Synchronous: can take a minute. */
715
+ installMcpPackage(kind, pkg) {
716
+ return this.request("POST", `/admin/mcp/packages/${kind}`, { body: { package: pkg }, timeoutMs: 6e5 });
717
+ }
718
+ // --- messaging adapters (per agent) -----------------------------------------
719
+ /** Store one adapter credential in the agent's identity keystore (sealed under the owner identity). */
720
+ setAdapterCredential(agentId, adapterType, envKey, value, opts = {}) {
721
+ return this.put(`/agents/${enc(agentId)}/adapters/credentials`, { adapterType, envKey, value, ...opts.replace ? { replace: !0 } : {} });
722
+ }
723
+ /** What is stored for a channel's credentials: metadata only, never values. */
724
+ adapterCredentials(agentId, adapterType) {
725
+ return this.get(`/agents/${enc(agentId)}/adapters/credentials`, { adapterType });
726
+ }
727
+ /** Enable an adapter in the agent config; a running agent starts it. */
728
+ attachAdapter(agentId, adapterType, config) {
729
+ return this.post(`/agents/${enc(agentId)}/adapters`, { adapterType, config });
730
+ }
731
+ /** Remove the adapter from the config and delete its stored credentials. */
732
+ detachAdapter(agentId, adapterType) {
733
+ return this.del(`/agents/${enc(agentId)}/adapters/${enc(adapterType)}`);
734
+ }
735
+ agentWs(agentId) {
736
+ return this.get(`/agents/${enc(agentId)}/runtime/ws`);
737
+ }
738
+ // --- agent templates (/templates; the list is `templates()`) — owner: src/main/tui/templates ---
739
+ /** Summary + contents (config, seed files, extra files) + whether it is the default. */
740
+ templateDetail(id) {
741
+ return this.get(`/templates/${enc(id)}`);
742
+ }
743
+ /** Blank, or a duplicate of `fromId`. 201 `{ id, template }`. */
744
+ createTemplate(input) {
745
+ return this.post("/templates", input);
746
+ }
747
+ /** Rename and/or notes (`''` clears one). A rename moves the file: use the returned id. */
748
+ updateTemplate(id, patch) {
749
+ return this.patch(`/templates/${enc(id)}`, patch);
750
+ }
751
+ /** Moves the file to the daemon's templates-trash folder (never a hard delete). */
752
+ deleteTemplate(id) {
753
+ return this.del(`/templates/${enc(id)}`);
754
+ }
755
+ setDefaultTemplate(id) {
756
+ return this.post(`/templates/${enc(id)}/default`);
757
+ }
758
+ /** Shipped templates only: back to the shipped version. */
759
+ resetTemplate(id) {
760
+ return this.post(`/templates/${enc(id)}/reset`);
761
+ }
762
+ templateReview(id) {
763
+ return this.get(`/templates/${enc(id)}/review`);
764
+ }
765
+ /** Claims the file under this owner. 400 password_required / 403 wrong_password / 409 identity_not_ready. */
766
+ acceptTemplateReview(id, password) {
767
+ return this.post(`/templates/${enc(id)}/review/accept`, password ? { password } : {});
768
+ }
769
+ putTemplateConfig(id, config) {
770
+ return this.put(`/templates/${enc(id)}/config`, { config });
771
+ }
772
+ putTemplateFile(id, path, content) {
773
+ return this.put(`/templates/${enc(id)}/files`, { path, content });
774
+ }
775
+ removeTemplateFile(id, path) {
776
+ return this.del(`/templates/${enc(id)}/files`, { path });
777
+ }
778
+ // --- agent tool catalog (Inspect › Settings, /tools) -----------------------
779
+ /** Built-in + MCP + declared tools with declared state and descriptions (read-only; write via putConfig). */
780
+ agentTools(agentId) {
781
+ return this.get(`/agents/${enc(agentId)}/tools`);
782
+ }
783
+ // --- context usage (/context) ------------------------------------------------
784
+ /** One loop's context breakdown: categories (biggest `items` per category), compact threshold, total. */
785
+ agentContext(agentId, loop, items) {
786
+ return this.get(`/agents/${enc(agentId)}/context`, { loop: loop && loop !== MAIN_LOOP ? loop : void 0, items });
787
+ }
788
+ };
789
+ function buildQuery(query) {
790
+ let params = new URLSearchParams();
791
+ for (let [key, value] of Object.entries(query))
792
+ value == null || value === "" || params.set(key, String(value));
793
+ let qs = params.toString();
794
+ return qs ? `?${qs}` : "";
795
+ }
796
+ function isRecord(value) {
797
+ return typeof value == "object" && value !== null && !Array.isArray(value);
798
+ }
799
+ function errorMessage2(err) {
800
+ if (err instanceof Error) {
801
+ let cause = err.cause;
802
+ return cause instanceof Error && cause.message ? cause.message : err.message;
803
+ }
804
+ return String(err);
805
+ }
806
+
807
+ export {
808
+ DaemonClient
809
+ };