@ghostystudio/cli 0.42.0 → 0.42.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 (2) hide show
  1. package/dist/index.js +57 -22
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -8422,7 +8422,7 @@ async function postLong(path, body, timeoutMs = 9e5) {
8422
8422
  const req = httpsRequest(`${base}${path}`, {
8423
8423
  method: "POST",
8424
8424
  timeout: timeoutMs,
8425
- headers: { authorization: `Bearer ${token}`, "user-agent": `ghosty-cli/${"0.42.0"}`, "content-type": "application/json", "content-length": Buffer.byteLength(data) }
8425
+ headers: { authorization: `Bearer ${token}`, "user-agent": `ghosty-cli/${"0.42.1"}`, "content-type": "application/json", "content-length": Buffer.byteLength(data) }
8426
8426
  }, (res) => {
8427
8427
  let buf = "";
8428
8428
  res.on("data", (c) => buf += c);
@@ -8464,7 +8464,7 @@ async function request(path, opts = {}, retried = false) {
8464
8464
  method: opts.method ?? (opts.body !== void 0 || opts.raw !== void 0 ? "POST" : "GET"),
8465
8465
  headers: {
8466
8466
  authorization: `Bearer ${token}`,
8467
- "user-agent": `ghosty-cli/${"0.42.0"}`,
8467
+ "user-agent": `ghosty-cli/${"0.42.1"}`,
8468
8468
  "accept-language": lang(),
8469
8469
  ...opts.body !== void 0 ? { "content-type": "application/json" } : {},
8470
8470
  ...opts.headers
@@ -9273,26 +9273,61 @@ async function turn(agent, sid, text, first, images = []) {
9273
9273
  let answer = "";
9274
9274
  let usageData;
9275
9275
  let ours = false;
9276
+ let terminado = false;
9277
+ let stream = res;
9276
9278
  try {
9277
9279
  await sent;
9278
- for await (const ev of readSse(res.body)) {
9279
- const d = parseData(ev);
9280
- if (d.turnId) ours = d.turnId === turnId;
9281
- if (!ours) continue;
9282
- if (ev.event === "chunk" && d.text) {
9283
- answer += d.text;
9284
- if (globals.json) process.stdout.write(JSON.stringify({ event: "chunk", text: d.text }) + "\n");
9285
- else process.stdout.write(d.text);
9286
- } else if (ev.event === "tool" && d.title) {
9287
- if (globals.json) process.stdout.write(JSON.stringify({ event: "tool", ...d }) + "\n");
9288
- else if (!d.status || d.status === "pending" || d.status === "in_progress") info(dim(` \u2699 ${serverText(d.title)}`));
9289
- } else if (ev.event === "usage") {
9290
- usageData = d;
9291
- } else if (ev.event === "error") {
9292
- throw new CliError(d.message ? serverText(d.message) : t("The turn failed.", "El turno fall\xF3."), EXIT.API);
9293
- } else if (ev.event === "done") {
9294
- break;
9280
+ for (let intento = 0; ; intento++) {
9281
+ let recibido = "";
9282
+ try {
9283
+ for await (const ev of readSse(stream.body)) {
9284
+ const d = parseData(ev);
9285
+ if (intento > 0 && ev.event === "done" && d.reposo) {
9286
+ if (d.interrumpido?.turnId === turnId) throw new CliError(serverText(d.interrumpido.motivo ?? t("The turn was cut off.", "El turno se cort\xF3.")), EXIT.API);
9287
+ if (d.ultimo?.turnId === turnId && d.ultimo.text) recibido = d.ultimo.text;
9288
+ else if (!ours) {
9289
+ terminado = true;
9290
+ break;
9291
+ }
9292
+ }
9293
+ if (d.turnId) ours = d.turnId === turnId;
9294
+ if (!ours && !(intento > 0 && ev.event === "done" && d.reposo)) continue;
9295
+ if (ev.event === "chunk" && d.text) recibido += d.text;
9296
+ if (ev.event === "reemplazo" && d.text) {
9297
+ answer = recibido = d.text;
9298
+ continue;
9299
+ }
9300
+ if ((ev.event === "chunk" || ev.event === "done") && recibido.length > answer.length && recibido.startsWith(answer)) {
9301
+ const nuevo = recibido.slice(answer.length);
9302
+ answer = recibido;
9303
+ if (globals.json) process.stdout.write(JSON.stringify({ event: "chunk", text: nuevo }) + "\n");
9304
+ else process.stdout.write(nuevo);
9305
+ }
9306
+ if (ev.event === "tool" && d.title) {
9307
+ if (globals.json) process.stdout.write(JSON.stringify({ event: "tool", ...d }) + "\n");
9308
+ else if (!d.status || d.status === "pending" || d.status === "in_progress") info(dim(` \u2699 ${serverText(d.title)}`));
9309
+ } else if (ev.event === "usage") {
9310
+ usageData = d;
9311
+ } else if (ev.event === "error") {
9312
+ throw new CliError(d.message ? serverText(d.message) : t("The turn failed.", "El turno fall\xF3."), EXIT.API);
9313
+ } else if (ev.event === "done") {
9314
+ terminado = true;
9315
+ break;
9316
+ }
9317
+ }
9318
+ } catch (e) {
9319
+ if (e instanceof CliError || cancelled) throw e;
9320
+ }
9321
+ if (terminado || cancelled) break;
9322
+ if (intento >= 5) {
9323
+ throw new CliError(
9324
+ t(`Lost the connection to the turn; it may still be running. Check: ghosty conversations show ${agent} ${sid}`, `Se perdi\xF3 la conexi\xF3n con el turno; puede seguir corriendo. Revisa: ghosty conversations show ${agent} ${sid}`),
9325
+ EXIT.API
9326
+ );
9295
9327
  }
9328
+ await new Promise((r) => setTimeout(r, Math.min(5e3, 1e3 * (intento + 1))));
9329
+ if (!globals.json) info(dim(t("(reconnecting\u2026)", "(reconectando\u2026)")));
9330
+ stream = await request(convPath(agent, `/${enc3(sid)}/events`), { signal: ctrl.signal, headers: { accept: "text/event-stream" } });
9296
9331
  }
9297
9332
  } finally {
9298
9333
  process.off("SIGINT", onSigint);
@@ -9681,7 +9716,7 @@ async function call(path, v, init = {}) {
9681
9716
  "x-ghosty-ts": ts,
9682
9717
  "x-ghosty-sig": sig,
9683
9718
  "content-type": "application/json",
9684
- "user-agent": `ghosty-cli/${"0.42.0"}`
9719
+ "user-agent": `ghosty-cli/${"0.42.1"}`
9685
9720
  },
9686
9721
  body: method === "GET" ? void 0 : raw
9687
9722
  });
@@ -13490,7 +13525,7 @@ async function main() {
13490
13525
  const tokens = splitTokens(pos, v);
13491
13526
  globals.token = tokens.session;
13492
13527
  globals.profile = v.profile;
13493
- if (v.version) return out({ version: "0.42.0" }, () => "0.42.0");
13528
+ if (v.version) return out({ version: "0.42.1" }, () => "0.42.1");
13494
13529
  for (const n of normalizeArgs(pos, v)) if (!globals.json) info(dim(n));
13495
13530
  const context = (await readConfig()).workspace;
13496
13531
  if (!explicitToken()?.startsWith("gat_")) {
@@ -13643,7 +13678,7 @@ async function main() {
13643
13678
  throw unknown(cmd, cmd, COMMANDS, "ghosty --help");
13644
13679
  }
13645
13680
  }
13646
- var notice = updateNotice("0.42.0").catch(() => null);
13681
+ var notice = updateNotice("0.42.1").catch(() => null);
13647
13682
  main().then(
13648
13683
  async () => {
13649
13684
  const n = await notice;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ghostystudio/cli",
3
- "version": "0.42.0",
3
+ "version": "0.42.1",
4
4
  "description": "Official Ghosty Studio CLI — configure, test and chat with your agents from the terminal. Built for humans and coding agents.",
5
5
  "type": "module",
6
6
  "bin": {