@getmateo/client 0.0.0-stage → 0.17.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.
Files changed (51) hide show
  1. package/LICENSE +211 -0
  2. package/README.md +43 -2
  3. package/dist/compat/normalize-provider-models.d.ts +11 -0
  4. package/dist/compat/normalize-provider-models.js +51 -0
  5. package/dist/connection/index.d.ts +51 -0
  6. package/dist/connection/index.js +113 -0
  7. package/dist/connection/legacy-workspaces.d.ts +19 -0
  8. package/dist/connection/legacy-workspaces.js +161 -0
  9. package/dist/connection/legacy.d.ts +31 -0
  10. package/dist/connection/legacy.js +245 -0
  11. package/dist/connection/owned.d.ts +36 -0
  12. package/dist/connection/owned.js +210 -0
  13. package/dist/creation/index.d.ts +40 -0
  14. package/dist/creation/index.js +197 -0
  15. package/dist/daemon-client-relay-e2ee-transport.d.ts +10 -0
  16. package/dist/daemon-client-relay-e2ee-transport.js +190 -0
  17. package/dist/daemon-client-runtime-metrics.d.ts +39 -0
  18. package/dist/daemon-client-runtime-metrics.js +173 -0
  19. package/dist/daemon-client-transport-types.d.ts +43 -0
  20. package/dist/daemon-client-transport-types.js +2 -0
  21. package/dist/daemon-client-transport-utils.d.ts +14 -0
  22. package/dist/daemon-client-transport-utils.js +127 -0
  23. package/dist/daemon-client-transport.d.ts +5 -0
  24. package/dist/daemon-client-transport.js +4 -0
  25. package/dist/daemon-client-websocket-transport.d.ts +15 -0
  26. package/dist/daemon-client-websocket-transport.js +183 -0
  27. package/dist/daemon-client.d.ts +1507 -0
  28. package/dist/daemon-client.js +5465 -0
  29. package/dist/fleet/index.d.ts +29 -0
  30. package/dist/fleet/index.js +81 -0
  31. package/dist/hosts/index.d.ts +16 -0
  32. package/dist/hosts/index.js +201 -0
  33. package/dist/index.d.ts +430 -0
  34. package/dist/index.js +583 -0
  35. package/dist/legacy-usage-icons.d.ts +2 -0
  36. package/dist/legacy-usage-icons.js +16 -0
  37. package/dist/node/buffering.d.ts +10 -0
  38. package/dist/node/buffering.js +28 -0
  39. package/dist/node/index.d.ts +17 -0
  40. package/dist/node/index.js +191 -0
  41. package/dist/node/ssh-tunnel.d.ts +9 -0
  42. package/dist/node/ssh-tunnel.js +81 -0
  43. package/dist/provider-snapshots/index.d.ts +21 -0
  44. package/dist/provider-snapshots/index.js +56 -0
  45. package/dist/terminal-stream-router.d.ts +25 -0
  46. package/dist/terminal-stream-router.js +62 -0
  47. package/dist/terminals/index.d.ts +80 -0
  48. package/dist/terminals/index.js +120 -0
  49. package/dist/timeline-subscription/index.d.ts +25 -0
  50. package/dist/timeline-subscription/index.js +56 -0
  51. package/package.json +59 -4
package/dist/index.js ADDED
@@ -0,0 +1,583 @@
1
+ import { parentAddressLabels } from "@getmateo/protocol/agent-labels";
2
+ import { createHostActions } from "./hosts/index.js";
3
+ export { enrollFleet, fleetConnection, removeFleetMember, FleetEnrollmentError, } from "./fleet/index.js";
4
+ import { DaemonClient } from "./daemon-client.js";
5
+ import { createTerminalActions, } from "./terminals/index.js";
6
+ /**
7
+ * Coding turns routinely run for minutes, so the handle waits far longer than
8
+ * the transport's own conservative default.
9
+ */
10
+ const DEFAULT_WAIT_FOR_FINISH_MS = 10 * 60000;
11
+ export function createMateoClient(config) {
12
+ const daemonClient = new DaemonClient({
13
+ ...config,
14
+ clientId: config.clientId ?? createGeneratedClientId(),
15
+ clientType: "cli",
16
+ });
17
+ const api = createMateoApi(daemonClient);
18
+ return {
19
+ ...api,
20
+ connect: () => daemonClient.connect(),
21
+ close: async () => {
22
+ try {
23
+ await api.dispose();
24
+ }
25
+ finally {
26
+ await daemonClient.close();
27
+ }
28
+ },
29
+ ensureConnected: () => daemonClient.ensureConnected(),
30
+ getConnectionState: () => daemonClient.getConnectionState(),
31
+ };
32
+ }
33
+ function toDaemonAgentCreateOptions(options, placement, serverId) {
34
+ const { config: agentConfig, cwd, parent, title, prompt, ...requestOptions } = options;
35
+ const { provider: providerModel, options: providerOptions, ...runtimeConfig } = agentConfig;
36
+ const { provider, model } = parseProviderModel(providerModel);
37
+ const relationship = parent ? encodeParent(parent, serverId) : {};
38
+ return {
39
+ ...requestOptions,
40
+ config: {
41
+ ...runtimeConfig,
42
+ provider,
43
+ model,
44
+ cwd: placement?.cwd ?? cwd,
45
+ ...(title !== undefined ? { title } : {}),
46
+ ...(providerOptions !== undefined ? { providerOptions } : {}),
47
+ },
48
+ ...(placement ? { workspaceId: placement.workspaceId } : {}),
49
+ ...(parent
50
+ ? {
51
+ ...relationship,
52
+ labels: { ...requestOptions.labels, ...relationship.labels },
53
+ }
54
+ : {}),
55
+ ...(prompt !== undefined ? { initialPrompt: prompt } : {}),
56
+ };
57
+ }
58
+ export function createMateoApi(daemonClient, scopeOptions) {
59
+ const handles = new Set();
60
+ const agentListeners = new Set();
61
+ const workspaceListeners = new Set();
62
+ const lifetime = new AbortController();
63
+ const own = (create) => {
64
+ if (lifetime.signal.aborted)
65
+ throw new Error("Mateo API is disposed");
66
+ const handle = create();
67
+ handles.add(handle);
68
+ const release = handle.release.bind(handle);
69
+ handle.release = async () => {
70
+ await release();
71
+ handles.delete(handle);
72
+ };
73
+ return handle;
74
+ };
75
+ const listenAgents = (handler) => {
76
+ if (lifetime.signal.aborted)
77
+ throw new Error("Mateo API is disposed");
78
+ agentListeners.add(handler);
79
+ return () => {
80
+ agentListeners.delete(handler);
81
+ };
82
+ };
83
+ const listenWorkspaces = (handler) => {
84
+ if (lifetime.signal.aborted)
85
+ throw new Error("Mateo API is disposed");
86
+ workspaceListeners.add(handler);
87
+ return () => {
88
+ workspaceListeners.delete(handler);
89
+ };
90
+ };
91
+ const createAgentHandle = createAgentHandleFactory(daemonClient, listenAgents, (agentId, handler) => own(() => daemonClient.subscribeAgentTimeline(agentId, handler)));
92
+ const createAgent = async (options, placement) => {
93
+ const agent = await daemonClient.createAgent(toDaemonAgentCreateOptions(options, placement, daemonClient.getLastServerInfoMessage()?.serverId));
94
+ return createAgentHandle(agent);
95
+ };
96
+ const terminals = createTerminalActions(daemonClient, async (workspaceId) => {
97
+ const workspace = await createWorkspaceHandle(workspaceId).refresh();
98
+ if (!workspace?.workspaceDirectory) {
99
+ throw new Error(`Workspace ${workspaceId} is not active or has no available directory`);
100
+ }
101
+ return workspace.workspaceDirectory;
102
+ });
103
+ const createWorkspaceHandle = createWorkspaceHandleFactory(daemonClient, createAgent, terminals, listenWorkspaces);
104
+ let disposal = null;
105
+ const dispose = () => {
106
+ if (disposal)
107
+ return disposal;
108
+ lifetime.abort();
109
+ scopeOptions?.signal?.removeEventListener("abort", abort);
110
+ agentListeners.clear();
111
+ workspaceListeners.clear();
112
+ disposal = Promise.allSettled([...handles].map((handle) => handle.release())).then((results) => {
113
+ handles.clear();
114
+ const failures = results.flatMap((result) => result.status === "rejected" ? [result.reason] : []);
115
+ if (failures.length)
116
+ throw new AggregateError(failures, "Failed to release API subscriptions");
117
+ return undefined;
118
+ });
119
+ return disposal;
120
+ };
121
+ const abort = () => {
122
+ void dispose().catch((error) => console.error("API subscription cleanup failed", error));
123
+ };
124
+ if (scopeOptions?.signal?.aborted)
125
+ abort();
126
+ else
127
+ scopeOptions?.signal?.addEventListener("abort", abort, { once: true });
128
+ const observeEvents = (events, options) => own(() => daemonClient.observeEvents(events, options));
129
+ const subscribeEvent = (event, update) => {
130
+ const observation = observeEvents([event]);
131
+ observation.subscribe({ snapshot: () => { }, update });
132
+ return () => {
133
+ void observation
134
+ .release()
135
+ .catch((error) => console.error("Event subscription cleanup failed", error));
136
+ };
137
+ };
138
+ async function listWorkspaces(options) {
139
+ if (!options?.subscribe)
140
+ return daemonClient.fetchWorkspaces(options);
141
+ if (options.subscribe.subscriptionId !== undefined)
142
+ throw new Error("Subscription IDs are assigned by the host");
143
+ const subscription = own(() => daemonClient.observeWorkspaces(options));
144
+ subscription.subscribe({
145
+ snapshot: () => { },
146
+ update: (message) => {
147
+ if (message.type === "workspace_update")
148
+ for (const listener of workspaceListeners)
149
+ listener(message.payload);
150
+ },
151
+ });
152
+ return { ...(await subscription.ready), subscription };
153
+ }
154
+ async function listAgents(options) {
155
+ if (!options?.subscribe)
156
+ return daemonClient.fetchAgents(options);
157
+ if (options.subscribe.subscriptionId !== undefined)
158
+ throw new Error("Subscription IDs are assigned by the host");
159
+ const subscription = own(() => daemonClient.observeAgents(options));
160
+ subscription.subscribe({
161
+ snapshot: () => { },
162
+ update: (message) => {
163
+ if (message.type === "agent_update")
164
+ for (const listener of agentListeners)
165
+ listener(message.payload);
166
+ },
167
+ });
168
+ return { ...(await subscription.ready), subscription };
169
+ }
170
+ return {
171
+ dispose,
172
+ hosts: createHostActions(daemonClient, { own, signal: lifetime.signal, api: createMateoApi }),
173
+ observeEvents,
174
+ terminals,
175
+ checkouts: { status: (cwd, options) => daemonClient.getCheckoutStatus(cwd, options) },
176
+ projects: {
177
+ add: async ({ path, requestId }) => {
178
+ const result = await daemonClient.addProject(path, requestId);
179
+ if (result.error || !result.project) {
180
+ throw new Error(result.error ?? "The daemon did not add a project");
181
+ }
182
+ return result.project;
183
+ },
184
+ list: (options) => daemonClient.listProjects(options),
185
+ subscribe: (handler) => {
186
+ return subscribeEvent("project.update", (message) => {
187
+ if (message.type === "project.update")
188
+ handler(message.payload);
189
+ });
190
+ },
191
+ },
192
+ workspaces: {
193
+ mergeProject: (input) => daemonClient.mergeWorkspaceProject(input),
194
+ list: listWorkspaces,
195
+ ref: (workspace) => createWorkspaceHandle(workspace),
196
+ open: (input, requestId) => openWorkspace(daemonClient, createWorkspaceHandle, input, requestId),
197
+ create: async ({ requestId, agent, ...options }) => {
198
+ const result = await daemonClient.createWorkspace({
199
+ ...options,
200
+ ...(agent
201
+ ? {
202
+ agent: toDaemonAgentCreateOptions(agent, undefined, daemonClient.getLastServerInfoMessage()?.serverId),
203
+ }
204
+ : {}),
205
+ }, requestId);
206
+ if (result.error || !result.workspace) {
207
+ throw new Error(result.error ?? "The daemon did not create a workspace");
208
+ }
209
+ return createWorkspaceHandle(result.workspace);
210
+ },
211
+ archive: (workspace, requestId) => daemonClient.archiveWorkspace(resolveWorkspaceId(workspace), requestId),
212
+ subscribe: listenWorkspaces,
213
+ },
214
+ agents: {
215
+ list: listAgents,
216
+ ref: (agent) => createAgentHandle(agent),
217
+ create: (options) => createAgent(options),
218
+ subscribe: listenAgents,
219
+ },
220
+ providers: {
221
+ listModels: (provider, options) => daemonClient.listProviderModels(provider, options),
222
+ listModes: (provider, options) => daemonClient.listProviderModes(provider, options),
223
+ listFeatures: ({ provider: providerModel, ...draftConfig }, options) => {
224
+ const { provider, model } = parseProviderModel(providerModel);
225
+ return daemonClient.listProviderFeatures({ ...draftConfig, provider, model }, options);
226
+ },
227
+ listAvailable: (options) => daemonClient.listAvailableProviders(options),
228
+ snapshot: (options) => daemonClient.getProvidersSnapshot(options),
229
+ waitForReady: (options) => waitForProvidersReady(daemonClient, observeEvents(["providers_snapshot_update"]), lifetime.signal, options),
230
+ refresh: (options) => daemonClient.refreshProvidersSnapshot(options),
231
+ diagnostic: (provider, options) => daemonClient.getProviderDiagnostic(provider, options),
232
+ listUsage: (options) => listProviderUsage(daemonClient, options),
233
+ subscribe: (handler) => {
234
+ return subscribeEvent("providers_snapshot_update", (message) => {
235
+ if (message.type === "providers_snapshot_update")
236
+ handler(message.payload);
237
+ });
238
+ },
239
+ },
240
+ config: {
241
+ get: (requestId) => daemonClient.getDaemonConfig(requestId),
242
+ patch: (patch, requestId) => daemonClient.patchDaemonConfig(patch, requestId),
243
+ },
244
+ };
245
+ }
246
+ function createWorkspaceHandleFactory(daemonClient, createAgent, terminals, listen) {
247
+ return (workspace) => {
248
+ const id = typeof workspace === "string" ? workspace : workspace.id;
249
+ let current = typeof workspace === "string" ? null : workspace;
250
+ const refresh = async (options) => {
251
+ let cursor;
252
+ let requestId = options?.requestId;
253
+ // A ref addresses one workspace by id, so a background one resolves too.
254
+ const filter = daemonClient.supportsBackgroundWorkspaces() ? { includeBackground: true } : {};
255
+ do {
256
+ const result = await daemonClient.fetchWorkspaces({
257
+ requestId,
258
+ filter,
259
+ page: { limit: 200, ...(cursor ? { cursor } : {}) },
260
+ });
261
+ const match = result.entries.find((entry) => entry.id === id);
262
+ if (match) {
263
+ current = match;
264
+ return current;
265
+ }
266
+ cursor = result.pageInfo.nextCursor ?? undefined;
267
+ requestId = undefined;
268
+ } while (cursor);
269
+ current = null;
270
+ return current;
271
+ };
272
+ return {
273
+ id,
274
+ get projectId() {
275
+ return current?.projectId ?? null;
276
+ },
277
+ get directory() {
278
+ return current?.workspaceDirectory ?? null;
279
+ },
280
+ get name() {
281
+ return current?.name ?? null;
282
+ },
283
+ get status() {
284
+ return current?.status ?? null;
285
+ },
286
+ agents: {
287
+ create: async (options) => {
288
+ const snapshot = current ?? (await refresh());
289
+ if (!snapshot?.workspaceDirectory) {
290
+ throw new Error(`Workspace ${id} has no available directory`);
291
+ }
292
+ return createAgent({ ...options, cwd: snapshot.workspaceDirectory }, { workspaceId: id, cwd: snapshot.workspaceDirectory });
293
+ },
294
+ },
295
+ terminals: {
296
+ create: (options) => terminals.create({ ...options, workspaceId: id }),
297
+ list: (options) => terminals.list({ ...options, workspaceId: id }),
298
+ },
299
+ current: () => current,
300
+ refresh,
301
+ setTitle: (title, requestId) => daemonClient.setWorkspaceTitle(id, title, requestId),
302
+ archive: async (requestId) => {
303
+ const result = await daemonClient.archiveWorkspace(id, requestId);
304
+ if (current) {
305
+ current = { ...current, archivingAt: result.archivedAt };
306
+ }
307
+ return result;
308
+ },
309
+ subscribe: (handler) => listen((update) => {
310
+ if (update.kind === "upsert" && update.workspace.id === id) {
311
+ current = update.workspace;
312
+ handler(update);
313
+ }
314
+ if (update.kind === "remove" && update.id === id) {
315
+ handler(update);
316
+ }
317
+ }),
318
+ };
319
+ };
320
+ }
321
+ function createAgentHandleFactory(daemonClient, listen, subscribeTimeline) {
322
+ return (agent) => {
323
+ const id = typeof agent === "string" ? agent : agent.id;
324
+ let current = typeof agent === "string" ? null : agent;
325
+ let serverId = daemonClient.getLastServerInfoMessage()?.serverId;
326
+ const handle = {
327
+ id,
328
+ get address() {
329
+ serverId ?? (serverId = daemonClient.getLastServerInfoMessage()?.serverId);
330
+ if (!serverId)
331
+ throw new Error("Connect to a host before obtaining an agent address");
332
+ return { serverId, agentId: id };
333
+ },
334
+ timeline: {
335
+ append: (item) => daemonClient.appendAgentTimelineItem(id, item),
336
+ refetch: async (options) => {
337
+ const result = await daemonClient.fetchAgentTimeline(id, options);
338
+ if (result.agent) {
339
+ current = result.agent;
340
+ }
341
+ return result;
342
+ },
343
+ subscribe: (handler) => subscribeTimeline(id, (message) => {
344
+ switch (message.type) {
345
+ case "agent_stream":
346
+ return handler(message.payload);
347
+ case "agent.timeline.subscription_restored":
348
+ return handler({
349
+ agentId: id,
350
+ subscriptionId: message.payload.subscriptionId,
351
+ event: { type: "subscription_restored" },
352
+ });
353
+ case "agent.timeline.error":
354
+ return handler({
355
+ agentId: id,
356
+ event: { type: "error", error: message.payload.error },
357
+ });
358
+ case "agent.timeline.replacement":
359
+ return handler({
360
+ agentId: id,
361
+ event: { type: "replacement", epoch: message.payload.epoch },
362
+ });
363
+ }
364
+ }),
365
+ },
366
+ get workspaceId() {
367
+ return current?.workspaceId ?? null;
368
+ },
369
+ get cwd() {
370
+ return current?.cwd ?? null;
371
+ },
372
+ get status() {
373
+ return current?.status ?? null;
374
+ },
375
+ get capabilities() {
376
+ return current?.capabilities ?? null;
377
+ },
378
+ get availableModes() {
379
+ return current?.availableModes ?? null;
380
+ },
381
+ get pendingPermissions() {
382
+ return current?.pendingPermissions ?? null;
383
+ },
384
+ get activeTurn() {
385
+ return current?.activeTurn ?? null;
386
+ },
387
+ get lastUsage() {
388
+ return current?.lastUsage ?? null;
389
+ },
390
+ get lastError() {
391
+ return current?.lastError ?? null;
392
+ },
393
+ get features() {
394
+ return current?.features ?? null;
395
+ },
396
+ get runtimeInfo() {
397
+ return current?.runtimeInfo ?? null;
398
+ },
399
+ get archivedAt() {
400
+ return current?.archivedAt ?? null;
401
+ },
402
+ current: () => current,
403
+ refresh: async (requestId) => {
404
+ const result = await daemonClient.fetchAgent({ agentId: id, requestId });
405
+ current = result?.agent ?? null;
406
+ return result;
407
+ },
408
+ send: async (text, options) => {
409
+ await daemonClient.sendAgentMessage(id, text, options);
410
+ },
411
+ respondToPermission: async ({ requestId, response }) => {
412
+ await daemonClient.respondToPermission(id, requestId, response);
413
+ },
414
+ run: async (text, options) => {
415
+ const { timeoutMs, ...sendOptions } = options ?? {};
416
+ await daemonClient.sendAgentMessage(id, text, sendOptions);
417
+ const result = await daemonClient.waitForFinish(id, timeoutMs ?? DEFAULT_WAIT_FOR_FINISH_MS);
418
+ if (result.final) {
419
+ current = result.final;
420
+ }
421
+ return result;
422
+ },
423
+ waitForFinish: async (timeoutMs) => {
424
+ const result = await daemonClient.waitForFinish(id, timeoutMs ?? DEFAULT_WAIT_FOR_FINISH_MS);
425
+ if (result.final) {
426
+ current = result.final;
427
+ }
428
+ return result;
429
+ },
430
+ commands: (options) => daemonClient.listCommands({ agentId: id, ...options }),
431
+ archive: async () => {
432
+ const result = await daemonClient.archiveAgent(id);
433
+ if (current) {
434
+ current = { ...current, archivedAt: result.archivedAt };
435
+ }
436
+ return result;
437
+ },
438
+ detach: async () => {
439
+ await daemonClient.detachAgent(id);
440
+ },
441
+ subscribe: (handler) => listen((update) => {
442
+ if (update.kind === "upsert" && update.agent.id === id) {
443
+ current = update.agent;
444
+ handler(update);
445
+ }
446
+ if (update.kind === "remove" && update.agentId === id) {
447
+ handler(update);
448
+ }
449
+ }),
450
+ };
451
+ return handle;
452
+ };
453
+ }
454
+ async function openWorkspace(daemonClient, createWorkspaceHandle, input, requestId) {
455
+ const options = typeof input === "string" ? { cwd: input, requestId } : input;
456
+ const result = await daemonClient.openProject(options.cwd, options.requestId);
457
+ if (result.error || !result.workspace) {
458
+ throw new Error(result.error ?? `The daemon did not open a workspace for ${options.cwd}`);
459
+ }
460
+ return createWorkspaceHandle(result.workspace);
461
+ }
462
+ function resolveWorkspaceId(workspace) {
463
+ return typeof workspace === "string" ? workspace : workspace.id;
464
+ }
465
+ /** A parent on another host is recorded by address only; the destination cannot resolve it locally. */
466
+ function encodeParent(parent, serverId) {
467
+ if (typeof parent === "string")
468
+ return { callerAgentId: parent };
469
+ const address = "address" in parent ? parent.address : parent;
470
+ if (!serverId)
471
+ throw new Error("Connect to a host before creating a child");
472
+ return address.serverId === serverId
473
+ ? { callerAgentId: address.agentId, labels: parentAddressLabels(address) }
474
+ : { labels: parentAddressLabels(address) };
475
+ }
476
+ function parseProviderModel(selection) {
477
+ const separator = selection.indexOf("/");
478
+ if (separator <= 0 || separator === selection.length - 1) {
479
+ throw new Error('Expected config.provider in "provider/model" format');
480
+ }
481
+ return {
482
+ provider: selection.slice(0, separator),
483
+ model: selection.slice(separator + 1),
484
+ };
485
+ }
486
+ function listProviderUsage(daemonClient, options) {
487
+ // COMPAT(providerUsageList): added in v0.1.98, remove after 2027-02-28 once daemon floor >= v0.1.98.
488
+ if (daemonClient.getLastServerInfoMessage()?.features?.providerUsageList !== true) {
489
+ return Promise.reject(new Error("Update the host to list provider usage."));
490
+ }
491
+ return daemonClient.listProviderUsage(options);
492
+ }
493
+ async function waitForProvidersReady(daemonClient, observation, signal, options = {}) {
494
+ const { timeoutMs = 60000, ...snapshotOptions } = options;
495
+ try {
496
+ await observation.ready;
497
+ if (signal.aborted)
498
+ throw new Error("Mateo API is disposed");
499
+ return await new Promise((resolve, reject) => {
500
+ let settled = false;
501
+ let requestId = null;
502
+ let snapshotCwd;
503
+ const pendingUpdates = new Map();
504
+ let latestEntries = [];
505
+ const cleanup = () => {
506
+ clearTimeout(timeout);
507
+ unsubscribe();
508
+ signal.removeEventListener("abort", abort);
509
+ };
510
+ const finish = (snapshot) => {
511
+ if (settled)
512
+ return;
513
+ settled = true;
514
+ cleanup();
515
+ resolve(snapshot);
516
+ };
517
+ const fail = (error) => {
518
+ if (settled)
519
+ return;
520
+ settled = true;
521
+ cleanup();
522
+ reject(error instanceof Error ? error : new Error(String(error)));
523
+ };
524
+ const updateMatches = (update) => update.cwd === snapshotCwd;
525
+ const unsubscribe = observation.subscribe({
526
+ snapshot: () => { },
527
+ update: (message) => {
528
+ if (message.type !== "providers_snapshot_update")
529
+ return;
530
+ const update = message.payload;
531
+ if (!requestId) {
532
+ pendingUpdates.set(update.cwd, update);
533
+ return;
534
+ }
535
+ if (!updateMatches(update))
536
+ return;
537
+ latestEntries = update.entries;
538
+ if (update.entries.some((entry) => entry.status === "loading"))
539
+ return;
540
+ finish({ ...update, requestId });
541
+ },
542
+ });
543
+ const abort = () => fail(new Error("Mateo API is disposed"));
544
+ signal.addEventListener("abort", abort, { once: true });
545
+ const timeout = setTimeout(() => {
546
+ const loading = latestEntries
547
+ .filter((entry) => entry.status === "loading")
548
+ .map((entry) => entry.provider)
549
+ .join(", ");
550
+ fail(new Error(loading
551
+ ? `Timed out waiting for providers: ${loading}`
552
+ : "Timed out waiting for provider discovery"));
553
+ }, timeoutMs);
554
+ void daemonClient
555
+ .getProvidersSnapshot(snapshotOptions)
556
+ .then((snapshot) => {
557
+ requestId = snapshot.requestId;
558
+ snapshotCwd = snapshot.cwd;
559
+ latestEntries = snapshot.entries;
560
+ if (!snapshot.entries.some((entry) => entry.status === "loading")) {
561
+ finish(snapshot);
562
+ return;
563
+ }
564
+ const pendingUpdate = pendingUpdates.get(snapshotCwd);
565
+ if (pendingUpdate && !pendingUpdate.entries.some((entry) => entry.status === "loading")) {
566
+ finish({ ...pendingUpdate, requestId });
567
+ }
568
+ return undefined;
569
+ })
570
+ .catch(fail);
571
+ });
572
+ }
573
+ finally {
574
+ await observation.release();
575
+ }
576
+ }
577
+ function createGeneratedClientId() {
578
+ const randomId = typeof globalThis.crypto?.randomUUID === "function"
579
+ ? globalThis.crypto.randomUUID()
580
+ : Math.random().toString(36).slice(2);
581
+ return `mateo-sdk-${randomId}`;
582
+ }
583
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,2 @@
1
+ export declare function legacyUsageIcon(sourceId: string): string | undefined;
2
+ //# sourceMappingURL=legacy-usage-icons.d.ts.map
@@ -0,0 +1,16 @@
1
+ // COMPAT(providerUsageList): added in v0.1.98, remove after 2027-03-26.
2
+ // Released hosts omit source icons. Delete these copies with the list conversion.
3
+ const ICONS = {
4
+ claude: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M4.709 15.955l4.72-2.647.08-.23-.08-.128H9.2l-.79-.048-2.698-.073-2.339-.097-2.266-.122-.571-.121L0 11.784l.055-.352.48-.321.686.06 1.52.103 2.278.158 1.652.097 2.449.255h.389l.055-.157-.134-.098-.103-.097-2.358-1.596-2.552-1.688-1.336-.972-.724-.491-.364-.462-.158-1.008.656-.722.881.06.225.061.893.686 1.908 1.476 2.491 1.833.365.304.145-.103.019-.073-.164-.274-1.355-2.446-1.446-2.49-.644-1.032-.17-.619a2.97 2.97 0 01-.104-.729L6.283.134 6.696 0l.996.134.42.364.62 1.414 1.002 2.229 1.555 3.03.456.898.243.832.091.255h.158V9.01l.128-1.706.237-2.095.23-2.695.08-.76.376-.91.747-.492.584.28.48.685-.067.444-.286 1.851-.559 2.903-.364 1.942h.212l.243-.242.985-1.306 1.652-2.064.73-.82.85-.904.547-.431h1.033l.76 1.129-.34 1.166-1.064 1.347-.881 1.142-1.264 1.7-.79 1.36.073.11.188-.02 2.856-.606 1.543-.28 1.841-.315.833.388.091.395-.328.807-1.969.486-2.309.462-3.439.813-.042.03.049.061 1.549.146.662.036h1.622l3.02.225.79.522.474.638-.079.485-1.215.62-1.64-.389-3.829-.91-1.312-.329h-.182v.11l1.093 1.068 2.006 1.81 2.509 2.33.127.578-.322.455-.34-.049-2.205-1.657-.851-.747-1.926-1.62h-.128v.17l.444.649 2.345 3.521.122 1.08-.17.353-.608.213-.668-.122-1.374-1.925-1.415-2.167-1.143-1.943-.14.08-.674 7.254-.316.37-.729.28-.607-.461-.322-.747.322-1.476.389-1.924.315-1.53.286-1.9.17-.632-.012-.042-.14.018-1.434 1.967-2.18 2.945-1.726 1.845-.414.164-.717-.37.067-.662.401-.589 2.388-3.036 1.44-1.882.93-1.086-.006-.158h-.055L4.132 18.56l-1.13.146-.487-.456.061-.746.231-.243 1.908-1.312-.006.006z"/></svg>\n',
5
+ codex: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" fill-rule="evenodd"><path d="M21.55 10.004a5.416 5.416 0 00-.478-4.501c-1.217-2.09-3.662-3.166-6.05-2.66A5.59 5.59 0 0010.831 1C8.39.995 6.224 2.546 5.473 4.838A5.553 5.553 0 001.76 7.496a5.487 5.487 0 00.691 6.5 5.416 5.416 0 00.477 4.502c1.217 2.09 3.662 3.165 6.05 2.66A5.586 5.586 0 0013.168 23c2.443.006 4.61-1.546 5.361-3.84a5.553 5.553 0 003.715-2.66 5.488 5.488 0 00-.693-6.497v.001zm-8.381 11.558a4.199 4.199 0 01-2.675-.954c.034-.018.093-.05.132-.074l4.44-2.53a.71.71 0 00.364-.623v-6.176l1.877 1.069c.02.01.033.029.036.05v5.115c-.003 2.274-1.87 4.118-4.174 4.123zM4.192 17.78a4.059 4.059 0 01-.498-2.763c.032.02.09.055.131.078l4.44 2.53c.225.13.504.13.73 0l5.42-3.088v2.138a.068.068 0 01-.027.057L9.9 19.288c-1.999 1.136-4.552.46-5.707-1.51h-.001zM3.023 8.216A4.15 4.15 0 015.198 6.41l-.002.151v5.06a.711.711 0 00.364.624l5.42 3.087-1.876 1.07a.067.067 0 01-.063.005l-4.489-2.559c-1.995-1.14-2.679-3.658-1.53-5.63h.001zm15.417 3.54l-5.42-3.088L14.896 7.6a.067.067 0 01.063-.006l4.489 2.557c1.998 1.14 2.683 3.662 1.529 5.633a4.163 4.163 0 01-2.174 1.807V12.38a.71.71 0 00-.363-.623zm1.867-2.773a6.04 6.04 0 00-.132-.078l-4.44-2.53a.731.731 0 00-.729 0l-5.42 3.088V7.325a.068.068 0 01.027-.057L14.1 4.713c2-1.137 4.555-.46 5.707 1.513.487.833.664 1.809.499 2.757h.001zm-11.741 3.81l-1.877-1.068a.065.065 0 01-.036-.051V6.559c.001-2.277 1.873-4.122 4.181-4.12.976 0 1.92.338 2.671.954-.034.018-.092.05-.131.073l-4.44 2.53a.71.71 0 00-.365.623l-.003 6.173v.002zm1.02-2.168L12 9.25l2.414 1.375v2.75L12 14.75l-2.415-1.375v-2.75z"/></svg>\n',
6
+ copilot: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 416" fill="currentColor"><path d="M181.33 266.143c0-11.497 9.32-20.818 20.818-20.818 11.498 0 20.819 9.321 20.819 20.818v38.373c0 11.497-9.321 20.818-20.819 20.818-11.497 0-20.818-9.32-20.818-20.818v-38.373zM308.807 245.325c-11.477 0-20.798 9.321-20.798 20.818v38.373c0 11.497 9.32 20.818 20.798 20.818 11.497 0 20.818-9.32 20.818-20.818v-38.373c0-11.497-9.32-20.818-20.818-20.818z"\n fill-rule="nonzero"/><path d="M512.002 246.393v57.384c-.02 7.411-3.696 14.638-9.67 19.011C431.767 374.444 344.695 416 256 416c-98.138 0-196.379-56.542-246.33-93.21-5.975-4.374-9.65-11.6-9.671-19.012v-57.384a35.347 35.347 0 016.857-20.922l15.583-21.085c8.336-11.312 20.757-14.31 33.98-14.31 4.988-56.953 16.794-97.604 45.024-127.354C155.194 5.77 226.56 0 256 0c29.441 0 100.807 5.77 154.557 62.722 28.19 29.75 40.036 70.401 45.025 127.354 13.263 0 25.602 2.936 33.958 14.31l15.583 21.127c4.476 6.077 6.878 13.345 6.878 20.88zm-97.666-26.075c-.677-13.058-11.292-18.19-22.338-21.824-11.64 7.309-25.848 10.183-39.46 10.183-14.454 0-41.432-3.47-63.872-25.869-5.667-5.625-9.527-14.454-12.155-24.247a212.902 212.902 0 00-20.469-1.088c-6.098 0-13.099.349-20.551 1.088-2.628 9.793-6.509 18.622-12.155 24.247-22.4 22.4-49.418 25.87-63.872 25.87-13.612 0-27.86-2.855-39.501-10.184-11.005 3.613-21.558 8.828-22.277 21.824-1.17 24.555-1.272 49.11-1.375 73.645-.041 12.318-.082 24.658-.288 36.976.062 7.166 4.374 13.818 10.882 16.774 52.97 24.124 103.045 36.278 149.137 36.278 46.01 0 96.085-12.154 149.014-36.278 6.508-2.956 10.84-9.608 10.881-16.774.637-36.832.124-73.809-1.642-110.62h.041zM107.521 168.97c8.643 8.623 24.966 14.392 42.56 14.392 13.448 0 39.03-2.874 60.156-24.329 9.28-8.951 15.05-31.35 14.413-54.079-.657-18.231-5.769-33.28-13.448-39.665-8.315-7.371-27.203-10.574-48.33-8.644-22.399 2.238-41.267 9.588-50.875 19.833-20.798 22.728-16.323 80.317-4.476 92.492zm130.556-56.008c.637 3.51.965 7.35 1.273 11.517 0 2.875 0 5.77-.308 8.952 6.406-.636 11.847-.636 16.959-.636s10.553 0 16.959.636c-.329-3.182-.329-6.077-.329-8.952.329-4.167.657-8.007 1.294-11.517-6.735-.637-12.812-.965-17.924-.965s-11.21.328-17.924.965zm49.275-8.008c-.637 22.728 5.133 45.128 14.413 54.08 21.105 21.454 46.708 24.328 60.155 24.328 17.596 0 33.918-5.769 42.561-14.392 11.847-12.175 16.322-69.764-4.476-92.492-9.608-10.245-28.476-17.595-50.875-19.833-21.127-1.93-40.015 1.273-48.33 8.644-7.679 6.385-12.791 21.434-13.448 39.665z"/></svg>\n',
7
+ cursor: '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 466.73 532.09">\n <path fill="currentColor" d="M457.43,125.94L244.42,2.96c-6.84-3.95-15.28-3.95-22.12,0L9.3,125.94c-5.75,3.32-9.3,9.46-9.3,16.11v247.99c0,6.65,3.55,12.79,9.3,16.11l213.01,122.98c6.84,3.95,15.28,3.95,22.12,0l213.01-122.98c5.75-3.32,9.3-9.46,9.3-16.11v-247.99c0-6.65-3.55-12.79-9.3-16.11h-.01ZM444.05,151.99l-205.63,356.16c-1.39,2.4-5.06,1.42-5.06-1.36v-233.21c0-4.66-2.49-8.97-6.53-11.31L24.87,145.67c-2.4-1.39-1.42-5.06,1.36-5.06h411.26c5.84,0,9.49,6.33,6.57,11.39h-.01Z"/>\n</svg>\n',
8
+ zai: '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="currentColor" fill-rule="evenodd"><title>Z.ai</title><path d="M8.07 1.333L6.618 3.302H.435L1.887 1.333h6.184zM15.503 12.699L14.052 14.667h-6.161l1.449-1.968h6.163zM16 1.333L6.176 14.667H0L9.824 1.333H16z"/></svg>\n',
9
+ grok: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 8V4H8"/><rect width="16" height="12" x="4" y="8" rx="2"/><path d="M2 14h2M20 14h2M9 13v2M15 13v2"/></svg>\n',
10
+ kimi: '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24">\n <path fill="currentColor" d="M19.514 7.342C19.711 7.862 19.814 8.413 19.816 8.969C19.816 12.494 15.998 14.697 12.946 12.934C11.529 12.116 10.657 10.605 10.657 8.969C10.657 5.646 14.085 3.431 17.115 4.793C15.26 3.373 12.99 2.607 10.655 2.612C4.772 2.614 0.005 7.381 0 13.265C0.002 19.148 4.772 23.918 10.655 23.92C16.538 23.916 21.306 19.147 21.31 13.265C21.312 11.155 20.687 9.095 19.514 7.342ZM14.841 4.666C14.841 8.191 18.657 10.395 21.709 8.632C23.127 7.814 24 6.302 24 4.666C24 1.14 20.184-1.061 17.13 0.699C15.714 1.519 14.841 3.03 14.841 4.666"/>\n</svg>\n',
11
+ minimax: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M16.278 2c1.156 0 2.093.927 2.093 2.07v12.501a.74.74 0 00.744.709.74.74 0 00.743-.709V9.099a2.06 2.06 0 012.071-2.049A2.06 2.06 0 0124 9.1v6.561a.649.649 0 01-.652.645.649.649 0 01-.653-.645V9.1a.762.762 0 00-.766-.758.762.762 0 00-.766.758v7.472a2.037 2.037 0 01-2.048 2.026 2.037 2.037 0 01-2.048-2.026v-12.5a.785.785 0 00-.788-.753.785.785 0 00-.789.752l-.001 15.904A2.037 2.037 0 0113.441 22a2.037 2.037 0 01-2.048-2.026V18.04c0-.356.292-.645.652-.645.36 0 .652.289.652.645v1.934c0 .263.142.506.372.638.23.131.514.131.744 0a.734.734 0 00.372-.638V4.07c0-1.143.937-2.07 2.093-2.07zm-5.674 0c1.156 0 2.093.927 2.093 2.07v11.523a.648.648 0 01-.652.645.648.648 0 01-.652-.645V4.07a.785.785 0 00-.789-.78.785.785 0 00-.789.78v14.013a2.06 2.06 0 01-2.07 2.048 2.06 2.06 0 01-2.071-2.048V9.1a.762.762 0 00-.766-.758.762.762 0 00-.766.758v3.8a2.06 2.06 0 01-2.071 2.049A2.06 2.06 0 010 12.9v-1.378c0-.357.292-.646.652-.646.36 0 .653.29.653.646V12.9c0 .418.343.757.766.757s.766-.339.766-.757V9.099a2.06 2.06 0 012.07-2.048 2.06 2.06 0 012.071 2.048v8.984c0 .419.343.758.767.758.423 0 .766-.339.766-.758V4.07c0-1.143.937-2.07 2.093-2.07z"/></svg>\n',
12
+ };
13
+ export function legacyUsageIcon(sourceId) {
14
+ return Object.hasOwn(ICONS, sourceId) ? ICONS[sourceId] : undefined;
15
+ }
16
+ //# sourceMappingURL=legacy-usage-icons.js.map
@@ -0,0 +1,10 @@
1
+ /** Counts bytes until the socket's send callback, shared by all links owned by a daemon. */
2
+ export declare class HostTransportBudget {
3
+ readonly limit: number;
4
+ private used;
5
+ constructor(limit?: number);
6
+ get bufferedBytes(): number;
7
+ assertCapacity(bytes: number): void;
8
+ reserve(bytes: number): () => void;
9
+ }
10
+ //# sourceMappingURL=buffering.d.ts.map
@@ -0,0 +1,28 @@
1
+ /** Counts bytes until the socket's send callback, shared by all links owned by a daemon. */
2
+ export class HostTransportBudget {
3
+ constructor(limit = 256 * 1024 * 1024) {
4
+ this.limit = limit;
5
+ this.used = 0;
6
+ }
7
+ get bufferedBytes() {
8
+ return this.used;
9
+ }
10
+ assertCapacity(bytes) {
11
+ if (bytes > this.limit - this.used)
12
+ throw Object.assign(new Error("Connected host buffer limit reached"), {
13
+ code: "resource_limit",
14
+ });
15
+ }
16
+ reserve(bytes) {
17
+ this.assertCapacity(bytes);
18
+ this.used += bytes;
19
+ let released = false;
20
+ return () => {
21
+ if (!released) {
22
+ released = true;
23
+ this.used -= bytes;
24
+ }
25
+ };
26
+ }
27
+ }
28
+ //# sourceMappingURL=buffering.js.map
@@ -0,0 +1,17 @@
1
+ export { createHostChannelTransport } from "../hosts/index.js";
2
+ import { HostTransportBudget } from "./buffering.js";
3
+ export { HostTransportBudget } from "./buffering.js";
4
+ import type { Agent } from "node:http";
5
+ import { parseHostTarget } from "@getmateo/protocol/host-target";
6
+ import type { DaemonTransportFactory } from "../daemon-client-transport-types.js";
7
+ import { DaemonClient, type DaemonClientConfig } from "../daemon-client.js";
8
+ export { parseHostTarget };
9
+ export type { SshTunnel } from "./ssh-tunnel.js";
10
+ export { createSshTunnel, resolveSshFailureDetail } from "./ssh-tunnel.js";
11
+ export interface HostTransportOptions {
12
+ webSocketAgent?: (url: string) => Agent | undefined;
13
+ }
14
+ /** A factory owns one attempt, including a fresh SSH process and its teardown. */
15
+ export declare function createHostTransportFactory(connection: string, budget?: HostTransportBudget, options?: HostTransportOptions): DaemonTransportFactory;
16
+ export declare function createHostClient(connection: string, config: Omit<DaemonClientConfig, "url"> & HostTransportOptions, budget?: HostTransportBudget): DaemonClient;
17
+ //# sourceMappingURL=index.d.ts.map