ghostykit 0.5.1 → 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
|
|
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}
|
|
@@ -332,7 +332,18 @@ function reduceAgUiEvent(prev, e, now = Date.now()) {
|
|
|
332
332
|
if (str(v.detail)) patch.detail = str(v.detail);
|
|
333
333
|
return upsertTool(s, v.toolCallId, patch);
|
|
334
334
|
}
|
|
335
|
-
if (
|
|
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;
|
|
336
347
|
return patchAssistant(s, (t) => ({ ...t, custom: [...t.custom ?? [], { name: e.name, value: e.value, ...typeof e.timestamp === "number" ? { timestamp: e.timestamp } : {} }] }));
|
|
337
348
|
default:
|
|
338
349
|
return s;
|
|
@@ -356,10 +367,12 @@ function finish(s0, e, now, failed = false) {
|
|
|
356
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) };
|
|
357
368
|
}
|
|
358
369
|
}
|
|
359
|
-
const
|
|
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(
|
|
360
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) }),
|
|
361
373
|
{ used: 0, size: 0, cost: 0 }
|
|
362
374
|
) : null;
|
|
375
|
+
const usage = tokens || costUsd !== void 0 ? { ...tokens ?? { used: 0, size: 0, cost: 0 }, ...costUsd !== void 0 ? { cost: costUsd } : {} } : null;
|
|
363
376
|
const t0 = s.turnStartedAt;
|
|
364
377
|
const seconds = t0 ? Math.max(1, Math.round((now - t0) / 1e3)) : void 0;
|
|
365
378
|
const turns = [...s.turns];
|
package/dist/core/index.js
CHANGED
package/dist/react/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ghostykit",
|
|
3
|
-
"version": "0.5.
|
|
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",
|