ghostykit 0.5.0 → 0.5.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.
@@ -114,7 +114,7 @@ function createPilotState(turns = []) {
114
114
  effects: []
115
115
  };
116
116
  }
117
- var PROTOCOL_CUSTOM = /* @__PURE__ */ new Set(["ghosty.title", "ghosty.injected", "ghosty.history"]);
117
+ var NOT_IN_TURN = /* @__PURE__ */ new Set(["ghosty.title", "ghosty.injected", "ghosty.history", "ghosty.tool", "ghosty.replace", "ghosty.page"]);
118
118
  function patchAssistant(s, patch) {
119
119
  const turns = [...s.turns];
120
120
  const last = turns[turns.length - 1];
@@ -199,7 +199,7 @@ function messagesToTurns(messages) {
199
199
  } else if (m.role === "assistant") {
200
200
  const t = assistant();
201
201
  if (!t.id && m.id) t.id = m.id;
202
- const custom = m.custom;
202
+ const custom = m.metadata?.custom;
203
203
  if (Array.isArray(custom) && custom.length) t.custom = [...t.custom ?? [], ...custom.filter((c) => c && typeof c.name === "string")];
204
204
  const text = m.content ?? "";
205
205
  if (text) t.text = t.text ? `${t.text}
@@ -321,7 +321,29 @@ function reduceAgUiEvent(prev, e, now = Date.now()) {
321
321
  case "CUSTOM":
322
322
  if (e.name === "ghosty.title") return { ...s, effects: [{ type: "title", title: e.value?.title }] };
323
323
  if (e.name === "ghosty.history") return { ...s, historyNext: toHistory(e.value) };
324
- if (typeof e.name !== "string" || PROTOCOL_CUSTOM.has(e.name)) return s;
324
+ if (e.name === "ghosty.tool") {
325
+ const v = e.value ?? {};
326
+ if (typeof v.toolCallId !== "string") return s;
327
+ const str = (x) => typeof x === "string" && x ? x : void 0;
328
+ const patch = {};
329
+ if (str(v.title)) patch.label = str(v.title);
330
+ if (str(v.kind)) patch.kind = str(v.kind);
331
+ if (str(v.path)) patch.path = str(v.path);
332
+ if (str(v.detail)) patch.detail = str(v.detail);
333
+ return upsertTool(s, v.toolCallId, patch);
334
+ }
335
+ if (e.name === "ghosty.replace") {
336
+ const content = e.value?.content;
337
+ if (typeof content !== "string") return s;
338
+ return patchAssistant(s, (t) => {
339
+ const cut = t.cuts?.length ? t.cuts[t.cuts.length - 1] : 0;
340
+ const head = t.text.slice(0, cut);
341
+ return { ...t, text: head.trim() ? `${head}
342
+
343
+ ${content}` : content };
344
+ });
345
+ }
346
+ if (typeof e.name !== "string" || NOT_IN_TURN.has(e.name)) return s;
325
347
  return patchAssistant(s, (t) => ({ ...t, custom: [...t.custom ?? [], { name: e.name, value: e.value, ...typeof e.timestamp === "number" ? { timestamp: e.timestamp } : {} }] }));
326
348
  default:
327
349
  return s;
@@ -345,10 +367,12 @@ function finish(s0, e, now, failed = false) {
345
367
  s = { ...s, turns: s.turns.map((t) => t.tools?.some((x) => waiting.has(x.id)) ? { ...t, tools: t.tools.map((x) => waiting.has(x.id) && x.status !== "completed" ? { ...x, status: "pending" } : x) } : t) };
346
368
  }
347
369
  }
348
- const usage = Array.isArray(e.usage) && e.usage.length ? e.usage.reduce(
370
+ const costUsd = typeof e.metadata?.costUsd === "number" ? e.metadata.costUsd : void 0;
371
+ const tokens = Array.isArray(e.usage) && e.usage.length ? e.usage.reduce(
349
372
  (a, u) => ({ ...a, used: a.used + (u.totalTokens ?? (u.inputTokens ?? 0) + (u.outputTokens ?? 0)), input: (a.input ?? 0) + (u.inputTokens ?? 0), output: (a.output ?? 0) + (u.outputTokens ?? 0) }),
350
373
  { used: 0, size: 0, cost: 0 }
351
374
  ) : null;
375
+ const usage = tokens || costUsd !== void 0 ? { ...tokens ?? { used: 0, size: 0, cost: 0 }, ...costUsd !== void 0 ? { cost: costUsd } : {} } : null;
352
376
  const t0 = s.turnStartedAt;
353
377
  const seconds = t0 ? Math.max(1, Math.round((now - t0) / 1e3)) : void 0;
354
378
  const turns = [...s.turns];
@@ -504,6 +528,7 @@ function namedVerb(t, verbs) {
504
528
  return null;
505
529
  }
506
530
  function stepLabel(t, verbs, fallback = "Paso") {
531
+ if (t.label) return t.label;
507
532
  const named = namedVerb(t, verbs);
508
533
  if (named) return isRunning(t) && named.verb.running ? named.verb.running : named.verb.one;
509
534
  return t.title ?? t.kind ?? fallback;
@@ -27,7 +27,7 @@ import {
27
27
  toPermission,
28
28
  toolName,
29
29
  toolNames
30
- } from "../chunks/chunk-VK54J63C.js";
30
+ } from "../chunks/chunk-3XDAYARB.js";
31
31
  import {
32
32
  applyReferences,
33
33
  cleanUserText,
@@ -14,6 +14,8 @@ export interface ToolEntry {
14
14
  id: string;
15
15
  /** El nombre de la herramienta (`toolCallName`): es la llave de los verbos de la app. */
16
16
  title?: string;
17
+ /** El rótulo que puso el servidor (`CUSTOM ghosty.tool`): gana sobre los verbos de la app. */
18
+ label?: string;
17
19
  kind?: string;
18
20
  /** `in_progress` mientras corre; `completed` | `failed` con su resultado; `pending` = espera
19
21
  * aprobación; `cancelled` = el run se detuvo antes de que terminara. */
@@ -27,7 +27,7 @@ import {
27
27
  toPermission,
28
28
  toolName,
29
29
  toolNames
30
- } from "../chunks/chunk-VK54J63C.js";
30
+ } from "../chunks/chunk-3XDAYARB.js";
31
31
  import {
32
32
  PilotHttpError,
33
33
  createAgUiTransport,
@@ -887,7 +887,7 @@ var STRINGS_ES = {
887
887
  linkOpen: "Abrir",
888
888
  close: "Cerrar",
889
889
  goToLatest: "Ir al \xFAltimo mensaje",
890
- steps: { waking: "Despertando al agente\u2026", session: "Preparando la sesi\xF3n\u2026" },
890
+ steps: { waking: "Despertando al agente\u2026", session: "Preparando la sesi\xF3n\u2026", compacting: "Resumiendo la conversaci\xF3n\u2026" },
891
891
  loadOlder: "Cargar mensajes anteriores",
892
892
  loadingOlder: "Cargando\u2026",
893
893
  confirmTitle: "Necesito tu permiso para",
@@ -955,7 +955,7 @@ var STRINGS_EN = {
955
955
  linkOpen: "Open",
956
956
  close: "Close",
957
957
  goToLatest: "Go to latest message",
958
- steps: { waking: "Waking the agent\u2026", session: "Starting the session\u2026" },
958
+ steps: { waking: "Waking the agent\u2026", session: "Starting the session\u2026", compacting: "Compacting the conversation\u2026" },
959
959
  loadOlder: "Load earlier messages",
960
960
  loadingOlder: "Loading\u2026",
961
961
  confirmTitle: "I need your permission to",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ghostykit",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "Ghosty Autopilot \u2014 the autopilot chat for your React app, on AG-UI: works with LangGraph, Mastra, CrewAI or any AG-UI agent. Streaming text, agent steps, human approval cards (interrupt/resume), attachments and voice.",
5
5
  "type": "module",
6
6
  "main": "./dist/core/index.js",