agent-yes 1.97.0 → 1.99.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,520 @@
1
+ function F() {
2
+ return crypto.randomUUID();
3
+ }
4
+ var v = 60000,
5
+ w = 1e4,
6
+ M = 1000,
7
+ u = 120000,
8
+ b = 25000;
9
+ class H {
10
+ opts;
11
+ peerId;
12
+ ws = null;
13
+ closed = !1;
14
+ reconnectDelay = M;
15
+ reconnectTimer = null;
16
+ dormant = !1;
17
+ heartbeat = null;
18
+ stableTimer = null;
19
+ openedAt = 0;
20
+ constructor(z) {
21
+ this.opts = z;
22
+ this.peerId = z.peerId ?? F();
23
+ }
24
+ connect() {
25
+ ((this.closed = !1), this.attachWakeListeners(), this.open());
26
+ }
27
+ onWake = () => {
28
+ if (this.closed) return;
29
+ let z = this.ws?.readyState;
30
+ if (z === 1) return;
31
+ if (z === 0) {
32
+ try {
33
+ this.ws?.close();
34
+ } catch {}
35
+ return;
36
+ }
37
+ if (this.dormant || this.reconnectTimer != null)
38
+ ((this.dormant = !1), this.clearReconnectTimer(), this.open());
39
+ };
40
+ hidden() {
41
+ return globalThis.document?.visibilityState === "hidden";
42
+ }
43
+ attachWakeListeners() {
44
+ globalThis.document?.addEventListener("visibilitychange", this.onWake);
45
+ let K = globalThis.window;
46
+ (K?.addEventListener("focus", this.onWake), K?.addEventListener("online", this.onWake));
47
+ }
48
+ detachWakeListeners() {
49
+ globalThis.document?.removeEventListener("visibilitychange", this.onWake);
50
+ let K = globalThis.window;
51
+ (K?.removeEventListener("focus", this.onWake), K?.removeEventListener("online", this.onWake));
52
+ }
53
+ roomUrl() {
54
+ return `${this.opts.url.replace(/\/+$/, "")}/room/${encodeURIComponent(this.opts.token)}`;
55
+ }
56
+ open() {
57
+ let z = new WebSocket(this.roomUrl());
58
+ this.ws = z;
59
+ let K = setTimeout(() => {
60
+ if (z.readyState === 0)
61
+ try {
62
+ z.close();
63
+ } catch {}
64
+ }, w);
65
+ ((z.onopen = () => {
66
+ (clearTimeout(K),
67
+ (this.openedAt = Date.now()),
68
+ this.clearStableTimer(),
69
+ (this.stableTimer = setTimeout(() => {
70
+ this.reconnectDelay = M;
71
+ }, v)));
72
+ let Q = {
73
+ type: "hello",
74
+ role: this.opts.role,
75
+ peerId: this.peerId,
76
+ ...(this.opts.meta ? { meta: this.opts.meta } : {}),
77
+ };
78
+ (z.send(JSON.stringify(Q)), this.startHeartbeat(), this.opts.onOpen?.());
79
+ }),
80
+ (z.onmessage = (Q) => {
81
+ let Y;
82
+ try {
83
+ Y = JSON.parse(String(Q.data));
84
+ } catch {
85
+ return;
86
+ }
87
+ if (Y.type === "peers") this.opts.onPeers?.(Y.peers);
88
+ else if (Y.type === "signal") this.opts.onSignal?.(Y.from, Y.data);
89
+ }),
90
+ (z.onclose = (Q) => {
91
+ (clearTimeout(K), this.clearStableTimer(), this.stopHeartbeat());
92
+ let Y = this.openedAt ? Date.now() - this.openedAt : 0;
93
+ if (
94
+ ((this.openedAt = 0),
95
+ this.opts.onClose?.({ code: Q?.code ?? 0, reason: Q?.reason ?? "", ms: Y }),
96
+ !this.closed)
97
+ )
98
+ this.scheduleReconnect();
99
+ }),
100
+ (z.onerror = () => {
101
+ try {
102
+ z.close();
103
+ } catch {}
104
+ }));
105
+ }
106
+ startHeartbeat() {
107
+ (this.stopHeartbeat(),
108
+ (this.heartbeat = setInterval(() => {
109
+ try {
110
+ this.ws?.send(JSON.stringify({ type: "ping" }));
111
+ } catch {}
112
+ }, b)));
113
+ }
114
+ stopHeartbeat() {
115
+ if (this.heartbeat != null) (clearInterval(this.heartbeat), (this.heartbeat = null));
116
+ }
117
+ clearStableTimer() {
118
+ if (this.stableTimer != null) (clearTimeout(this.stableTimer), (this.stableTimer = null));
119
+ }
120
+ scheduleReconnect() {
121
+ if (this.hidden()) {
122
+ this.dormant = !0;
123
+ return;
124
+ }
125
+ let z = Math.round(this.reconnectDelay * (0.75 + Math.random() * 0.5));
126
+ ((this.reconnectDelay = Math.min(this.reconnectDelay * 2, u)),
127
+ this.clearReconnectTimer(),
128
+ (this.reconnectTimer = setTimeout(() => {
129
+ if (((this.reconnectTimer = null), this.closed)) return;
130
+ if (this.hidden()) {
131
+ this.dormant = !0;
132
+ return;
133
+ }
134
+ this.open();
135
+ }, z)));
136
+ }
137
+ clearReconnectTimer() {
138
+ if (this.reconnectTimer != null)
139
+ (clearTimeout(this.reconnectTimer), (this.reconnectTimer = null));
140
+ }
141
+ sendSignal(z, K) {
142
+ let Q = { type: "signal", to: z, data: K };
143
+ this.ws?.send(JSON.stringify(Q));
144
+ }
145
+ updateMeta(z) {
146
+ if (((this.opts.meta = z), this.ws?.readyState === 1)) {
147
+ let K = { type: "meta", meta: z };
148
+ this.ws.send(JSON.stringify(K));
149
+ }
150
+ }
151
+ close() {
152
+ ((this.closed = !0),
153
+ (this.dormant = !1),
154
+ this.detachWakeListeners(),
155
+ this.clearReconnectTimer(),
156
+ this.stopHeartbeat(),
157
+ this.clearStableTimer());
158
+ try {
159
+ this.ws?.close();
160
+ } catch {}
161
+ }
162
+ }
163
+ var R = ["stun:stun.l.google.com:19302", "stun:stun1.l.google.com:19302"],
164
+ A = "codehost";
165
+ class x {
166
+ opts;
167
+ pc;
168
+ channel = null;
169
+ constructor(z) {
170
+ this.opts = z;
171
+ ((this.pc = new RTCPeerConnection({ iceServers: R.map((K) => ({ urls: K })) })),
172
+ (this.pc.onicecandidate = (K) => {
173
+ if (K.candidate)
174
+ this.opts.sendSignal({
175
+ kind: "candidate",
176
+ candidate: K.candidate.candidate,
177
+ mid: K.candidate.sdpMid ?? "0",
178
+ });
179
+ }),
180
+ (this.pc.onconnectionstatechange = () => {
181
+ this.opts.onState?.(this.pc.connectionState);
182
+ }));
183
+ }
184
+ async start() {
185
+ let z = this.pc.createDataChannel(A, { ordered: !0 });
186
+ ((z.binaryType = "arraybuffer"),
187
+ (this.channel = z),
188
+ (z.onopen = () => this.opts.onOpen?.(z)),
189
+ (z.onclose = () => this.opts.onClose?.()));
190
+ let K = await this.pc.createOffer();
191
+ (await this.pc.setLocalDescription(K),
192
+ this.opts.sendSignal({ kind: "offer", type: "offer", sdp: K.sdp ?? "" }));
193
+ }
194
+ async handleSignal(z) {
195
+ let K = z;
196
+ if (!K || typeof K !== "object") return;
197
+ if (K.kind === "answer") await this.pc.setRemoteDescription({ type: "answer", sdp: K.sdp });
198
+ else if (K.kind === "candidate")
199
+ try {
200
+ await this.pc.addIceCandidate({ candidate: K.candidate, sdpMid: K.mid });
201
+ } catch (Q) {
202
+ console.error("[rtc] addIceCandidate failed:", Q);
203
+ }
204
+ }
205
+ get dataChannel() {
206
+ return this.channel;
207
+ }
208
+ async selectedPath() {
209
+ try {
210
+ let z = await this.pc.getStats(),
211
+ K = null;
212
+ z.forEach(($) => {
213
+ if ($.type === "transport" && $.selectedCandidatePairId) K = $.selectedCandidatePairId;
214
+ });
215
+ let Q = null;
216
+ if (
217
+ (z.forEach(($) => {
218
+ if (
219
+ K ? $.id === K : $.type === "candidate-pair" && $.state === "succeeded" && $.nominated
220
+ )
221
+ Q = $;
222
+ }),
223
+ !Q)
224
+ )
225
+ return null;
226
+ let { localCandidateId: Y, remoteCandidateId: Z } = Q,
227
+ q = !0,
228
+ X = 0;
229
+ if (
230
+ (z.forEach(($) => {
231
+ if ($.id === Y || $.id === Z) {
232
+ if ((X++, $.candidateType !== "host")) q = !1;
233
+ }
234
+ }),
235
+ X < 2)
236
+ )
237
+ return null;
238
+ return q ? "lan" : "p2p";
239
+ } catch {
240
+ return null;
241
+ }
242
+ }
243
+ close() {
244
+ try {
245
+ this.channel?.close();
246
+ } catch {}
247
+ try {
248
+ this.pc.close();
249
+ } catch {}
250
+ }
251
+ }
252
+ var g = new TextEncoder(),
253
+ N = new TextDecoder();
254
+ function D(z, K, Q) {
255
+ let Y = Q?.byteLength ?? 0,
256
+ Z = new Uint8Array(5 + Y);
257
+ if (((Z[0] = z), new DataView(Z.buffer).setUint32(1, K >>> 0, !1), Q && Y)) Z.set(Q, 5);
258
+ return Z;
259
+ }
260
+ function k(z, K, Q) {
261
+ return D(z, K, g.encode(JSON.stringify(Q)));
262
+ }
263
+ function S(z) {
264
+ let K = z instanceof Uint8Array ? z : new Uint8Array(z),
265
+ Q = K[0],
266
+ Y = new DataView(K.buffer, K.byteOffset, K.byteLength).getUint32(1, !1),
267
+ Z = K.subarray(5);
268
+ return { op: Q, streamId: Y, payload: Z };
269
+ }
270
+ function U(z) {
271
+ return JSON.parse(N.decode(z));
272
+ }
273
+ function T(z) {
274
+ return N.decode(z);
275
+ }
276
+ function* _(z) {
277
+ for (let K = 0; K < z.byteLength; K += 65531) yield z.slice(K, Math.min(K + 65531, z.byteLength));
278
+ }
279
+ function O(z) {
280
+ if (z.length === 1) return z[0];
281
+ let K = z.reduce((Z, q) => Z + q.byteLength, 0),
282
+ Q = new Uint8Array(K),
283
+ Y = 0;
284
+ for (let Z of z) (Q.set(Z, Y), (Y += Z.byteLength));
285
+ return Q;
286
+ }
287
+ function* J(z, K, Q) {
288
+ let Y = 0;
289
+ while (Q.byteLength - Y > 65531) (yield D(13, K, Q.subarray(Y, Y + 65531)), (Y += 65531));
290
+ yield D(z, K, Q.subarray(Y));
291
+ }
292
+ class W {
293
+ pending = new Map();
294
+ cont(z, K) {
295
+ let Q = this.pending.get(z);
296
+ if (Q) Q.push(K.slice());
297
+ else this.pending.set(z, [K.slice()]);
298
+ }
299
+ finish(z, K) {
300
+ let Q = this.pending.get(z);
301
+ if (!Q) return K;
302
+ return (this.pending.delete(z), Q.push(K), O(Q));
303
+ }
304
+ drop(z) {
305
+ this.pending.delete(z);
306
+ }
307
+ }
308
+ class j {
309
+ channel;
310
+ nextStreamId = 1;
311
+ https = new Map();
312
+ wss = new Map();
313
+ wsRx = new W();
314
+ textEncoder = new TextEncoder();
315
+ constructor(z) {
316
+ this.channel = z;
317
+ ((z.binaryType = "arraybuffer"), z.addEventListener("message", (K) => this.onFrame(K.data)));
318
+ }
319
+ allocId() {
320
+ let z = this.nextStreamId;
321
+ return ((this.nextStreamId = (this.nextStreamId + 1) >>> 0 || 1), z);
322
+ }
323
+ onFrame(z) {
324
+ if (typeof z === "string") return;
325
+ let { op: K, streamId: Q, payload: Y } = S(z);
326
+ switch (K) {
327
+ case 4:
328
+ this.https.get(Q)?.onHead(U(Y));
329
+ break;
330
+ case 5:
331
+ this.https.get(Q)?.onBody(Y.slice());
332
+ break;
333
+ case 6:
334
+ (this.https.get(Q)?.onEnd(), this.https.delete(Q));
335
+ break;
336
+ case 12: {
337
+ let Z = this.https.get(Q);
338
+ if (Z) (Z.onError(U(Y).message), this.https.delete(Q));
339
+ break;
340
+ }
341
+ case 8: {
342
+ let Z = U(Y);
343
+ this.wss.get(Q)?.onOpenAck(Z.ok, Z.protocol);
344
+ break;
345
+ }
346
+ case 13:
347
+ this.wsRx.cont(Q, Y);
348
+ break;
349
+ case 9:
350
+ this.wss.get(Q)?.onText(T(this.wsRx.finish(Q, Y)));
351
+ break;
352
+ case 10:
353
+ this.wss.get(Q)?.onBin(this.wsRx.finish(Q, Y).slice());
354
+ break;
355
+ case 11: {
356
+ let Z = U(Y);
357
+ (this.wsRx.drop(Q),
358
+ this.wss.get(Q)?.onClose(Z.code ?? 1000, Z.reason ?? ""),
359
+ this.wss.delete(Q));
360
+ break;
361
+ }
362
+ }
363
+ }
364
+ fetch(z, K, Q, Y) {
365
+ let Z = this.allocId();
366
+ return new Promise((q, X) => {
367
+ let $ = null,
368
+ P = null,
369
+ V = new ReadableStream({
370
+ start: (G) => {
371
+ P = G;
372
+ },
373
+ }),
374
+ C = typeof DecompressionStream < "u" ? { ...Q, "x-codehost-accept-gzip": "1" } : Q;
375
+ if (
376
+ (this.https.set(Z, {
377
+ onHead: (G) => {
378
+ $ = G;
379
+ let B = new Headers(G.headers),
380
+ L = V;
381
+ if (B.get("content-encoding") === "gzip")
382
+ ((L = V.pipeThrough(new DecompressionStream("gzip"))),
383
+ B.delete("content-encoding"),
384
+ B.delete("content-length"));
385
+ q(
386
+ new Response(L, {
387
+ status: G.status === 204 || G.status === 304 ? G.status : G.status,
388
+ statusText: G.statusText,
389
+ headers: B,
390
+ }),
391
+ );
392
+ },
393
+ onBody: (G) => {
394
+ try {
395
+ P?.enqueue(G);
396
+ } catch {}
397
+ },
398
+ onEnd: () => {
399
+ try {
400
+ P?.close();
401
+ } catch {}
402
+ if (!$) X(Error("stream ended before head"));
403
+ },
404
+ onError: (G) => {
405
+ try {
406
+ P?.error(Error(G));
407
+ } catch {}
408
+ if (!$) X(Error(G));
409
+ },
410
+ }),
411
+ this.send(k(1, Z, { method: z, path: K, headers: C })),
412
+ Y && Y.byteLength)
413
+ )
414
+ for (let G of _(Y)) this.send(D(2, Z, G));
415
+ this.send(D(3, Z));
416
+ });
417
+ }
418
+ openWs(z, K, Q) {
419
+ let Y = this.allocId();
420
+ return (
421
+ this.wss.set(Y, Q),
422
+ this.send(k(7, Y, { path: z, protocols: K })),
423
+ {
424
+ sendText: (Z) => {
425
+ for (let q of J(9, Y, this.textEncoder.encode(Z))) this.send(q);
426
+ },
427
+ sendBin: (Z) => {
428
+ for (let q of J(10, Y, Z)) this.send(q);
429
+ },
430
+ close: (Z, q) => {
431
+ (this.send(k(11, Y, { code: Z, reason: q })), this.wss.delete(Y));
432
+ },
433
+ }
434
+ );
435
+ }
436
+ send(z) {
437
+ if (this.channel.readyState === "open") {
438
+ let K = new Uint8Array(z.byteLength);
439
+ (K.set(z), this.channel.send(K.buffer));
440
+ }
441
+ }
442
+ get ready() {
443
+ return this.channel.readyState === "open";
444
+ }
445
+ }
446
+ var f = "wss://signal.codehost.dev",
447
+ y = 1e4;
448
+ class E {
449
+ peers = [];
450
+ signaling;
451
+ rtcs = new Map();
452
+ tunnels = new Map();
453
+ dialFailedAt = new Map();
454
+ closed = !1;
455
+ constructor(z) {
456
+ ((this.signaling = new H({
457
+ url: z.signalUrl ?? f,
458
+ token: z.token,
459
+ role: "viewer",
460
+ onOpen: () => z.onStatus?.(!0),
461
+ onClose: () => z.onStatus?.(!1),
462
+ onPeers: (K) => {
463
+ ((this.peers = K.filter((Q) => Q.role === "server")), z.onPeers?.(this.peers));
464
+ },
465
+ onSignal: (K, Q) => void this.rtcs.get(K)?.handleSignal(Q),
466
+ })),
467
+ this.signaling.connect());
468
+ }
469
+ async fetch(z, K, Q, Y = {}) {
470
+ let Z = await this.dial(z),
471
+ q = typeof Y.body === "string" ? new TextEncoder().encode(Y.body) : Y.body;
472
+ return Z.fetch(K, Q, Y.headers ?? {}, q);
473
+ }
474
+ dial(z) {
475
+ let K = this.tunnels.get(z);
476
+ if (K) return K;
477
+ let Q = this.dialFailedAt.get(z);
478
+ if (Q != null && Date.now() - Q < y)
479
+ return Promise.reject(Error("dial failed recently; cooling down"));
480
+ let Y = () => {
481
+ (this.tunnels.delete(z), this.rtcs.get(z)?.close(), this.rtcs.delete(z));
482
+ },
483
+ Z = new Promise((q, X) => {
484
+ let $ = setTimeout(() => {
485
+ (Y(), X(Error("dial timed out")));
486
+ }, 15000),
487
+ P = new x({
488
+ sendSignal: (V) => this.signaling.sendSignal(z, V),
489
+ onOpen: (V) => {
490
+ (clearTimeout($), this.dialFailedAt.delete(z), q(new j(V)));
491
+ },
492
+ onClose: Y,
493
+ onState: (V) => {
494
+ if (V === "failed" || V === "disconnected") Y();
495
+ },
496
+ });
497
+ (this.rtcs.set(z, P),
498
+ P.start().catch((V) => {
499
+ (clearTimeout($), Y(), X(V));
500
+ }));
501
+ });
502
+ return (
503
+ this.tunnels.set(z, Z),
504
+ Z.catch(() => {
505
+ (this.dialFailedAt.set(z, Date.now()), this.tunnels.delete(z));
506
+ }),
507
+ Z
508
+ );
509
+ }
510
+ close() {
511
+ if (this.closed) return;
512
+ this.closed = !0;
513
+ for (let z of this.rtcs.values()) z.close();
514
+ (this.rtcs.clear(), this.tunnels.clear(), this.signaling.close());
515
+ }
516
+ }
517
+ function a(z) {
518
+ return new E(z);
519
+ }
520
+ export { a as joinRoom, f as DEFAULT_SIGNAL_URL, E as CodehostRoom };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-yes",
3
- "version": "1.97.0",
3
+ "version": "1.99.0",
4
4
  "description": "A wrapper tool that automates interactions with various AI CLI tools by automatically handling common prompts and responses.",
5
5
  "keywords": [
6
6
  "ai",
@@ -54,7 +54,9 @@
54
54
  "scripts",
55
55
  "ts/*.ts",
56
56
  "!dist/**/*.map",
57
- "dist/**/*.js"
57
+ "dist/**/*.js",
58
+ "lab/ui/index.html",
59
+ "lab/ui/room-client.js"
58
60
  ],
59
61
  "type": "module",
60
62
  "module": "ts/index.ts",