@8wave/ai-elements 0.124.0-beta.9 → 0.125.0-beta.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.
- package/dist/_chunks/{PkFilePreview-D_piCsAW.js → PkFilePreview-BwHe4-m1.js} +368 -346
- package/dist/_chunks/PkFilePreview-BwHe4-m1.js.map +1 -0
- package/dist/_chunks/{PkFilePreviewDialog-Bq0ipzrJ.js → PkFilePreviewDialog-LWxNgkzk.js} +2 -2
- package/dist/_chunks/{PkFilePreviewDialog-Bq0ipzrJ.js.map → PkFilePreviewDialog-LWxNgkzk.js.map} +1 -1
- package/dist/_chunks/{PkStreamingMarkdown-CHwrLP75.js → PkStreamingMarkdown-BvgO6aHe.js} +2 -2
- package/dist/_chunks/{PkStreamingMarkdown-CHwrLP75.js.map → PkStreamingMarkdown-BvgO6aHe.js.map} +1 -1
- package/dist/_chunks/{PkToolChatFile-DO4zjMJr.js → PkToolChatFile-OuaeZTxw.js} +62 -54
- package/dist/_chunks/PkToolChatFile-OuaeZTxw.js.map +1 -0
- package/dist/_chunks/{PkToolShowArtifact-B2-3-k2F.js → PkToolShowArtifact-BqgW3E6D.js} +2 -2
- package/dist/_chunks/{PkToolShowArtifact-B2-3-k2F.js.map → PkToolShowArtifact-BqgW3E6D.js.map} +1 -1
- package/dist/_chunks/{PkToolShowContactForm-DbOZHB_G.js → PkToolShowContactForm-DDDXopZp.js} +2 -2
- package/dist/_chunks/{PkToolShowContactForm-DbOZHB_G.js.map → PkToolShowContactForm-DDDXopZp.js.map} +1 -1
- package/dist/_chunks/{PkToolShowForm-o2LuWDNq.js → PkToolShowForm-D2LZ8Kkl.js} +3 -3
- package/dist/_chunks/{PkToolShowForm-o2LuWDNq.js.map → PkToolShowForm-D2LZ8Kkl.js.map} +1 -1
- package/dist/_chunks/{PkToolShowSources-CUNneZCp.js → PkToolShowSources-DA4SOt-H.js} +2 -2
- package/dist/_chunks/{PkToolShowSources-CUNneZCp.js.map → PkToolShowSources-DA4SOt-H.js.map} +1 -1
- package/dist/_chunks/excelNumberFormat-CIbRUEwQ.js +543 -0
- package/dist/_chunks/excelNumberFormat-CIbRUEwQ.js.map +1 -0
- package/dist/_chunks/{utils-BHvRrCzW.js → utils-euH8esYP.js} +7 -6
- package/dist/_chunks/utils-euH8esYP.js.map +1 -0
- package/dist/ai-elements.es.js +8 -8
- package/dist-vue/PkChatbot.js +1 -1
- package/dist-vue/PkChatbotEmptyState.js +1 -1
- package/dist-vue/PkChatbotInput.js +1 -1
- package/dist-vue/PkChatbotMessages.js +1 -1
- package/dist-vue/PkChatbotStepPayload.js +1 -1
- package/dist-vue/PkChatbotStepToolDetail.js +1 -1
- package/dist-vue/PkChatbotSteps.js +1 -1
- package/dist-vue/PkChatbotViewChat.js +1 -1
- package/dist-vue/PkChatbotViewConversations.js +1 -1
- package/dist-vue/_chunks/{PkChatbot-DQssgXm3.js → PkChatbot-BRttF7Lo.js} +5 -5
- package/dist-vue/_chunks/{PkChatbot-DQssgXm3.js.map → PkChatbot-BRttF7Lo.js.map} +1 -1
- package/dist-vue/_chunks/{PkChatbotEmptyState-B6qxJAPT.js → PkChatbotEmptyState-CLOH5Z2d.js} +2 -2
- package/dist-vue/_chunks/{PkChatbotEmptyState-B6qxJAPT.js.map → PkChatbotEmptyState-CLOH5Z2d.js.map} +1 -1
- package/dist-vue/_chunks/{PkChatbotInput-Bk8OS1xU.js → PkChatbotInput-BK7f1jFE.js} +2 -2
- package/dist-vue/_chunks/{PkChatbotInput-Bk8OS1xU.js.map → PkChatbotInput-BK7f1jFE.js.map} +1 -1
- package/dist-vue/_chunks/{PkChatbotMessages-D4LJZxv7.js → PkChatbotMessages-Ck0ofhtK.js} +14 -14
- package/dist-vue/_chunks/{PkChatbotMessages-D4LJZxv7.js.map → PkChatbotMessages-Ck0ofhtK.js.map} +1 -1
- package/dist-vue/_chunks/{PkChatbotStepPayload-_0WRbSR6.js → PkChatbotStepPayload-D682n3VR.js} +2 -2
- package/dist-vue/_chunks/{PkChatbotStepPayload-_0WRbSR6.js.map → PkChatbotStepPayload-D682n3VR.js.map} +1 -1
- package/dist-vue/_chunks/{PkChatbotStepToolDetail-DiaervF2.js → PkChatbotStepToolDetail-D5c8rqj9.js} +3 -3
- package/dist-vue/_chunks/{PkChatbotStepToolDetail-DiaervF2.js.map → PkChatbotStepToolDetail-D5c8rqj9.js.map} +1 -1
- package/dist-vue/_chunks/{PkChatbotSteps-BqL-ClgI.js → PkChatbotSteps-CtKRHqaG.js} +5 -5
- package/dist-vue/_chunks/{PkChatbotSteps-BqL-ClgI.js.map → PkChatbotSteps-CtKRHqaG.js.map} +1 -1
- package/dist-vue/_chunks/{PkChatbotViewChat-BfVLCU_j.js → PkChatbotViewChat-D8depeWQ.js} +6 -6
- package/dist-vue/_chunks/{PkChatbotViewChat-BfVLCU_j.js.map → PkChatbotViewChat-D8depeWQ.js.map} +1 -1
- package/dist-vue/_chunks/{PkChatbotViewConversations-C32O6SsT.js → PkChatbotViewConversations-B-dmLi-8.js} +2 -2
- package/dist-vue/_chunks/{PkChatbotViewConversations-C32O6SsT.js.map → PkChatbotViewConversations-B-dmLi-8.js.map} +1 -1
- package/dist-vue/_chunks/PkFilePreview-B54Dp_Rs.js +1149 -0
- package/dist-vue/_chunks/PkFilePreview-B54Dp_Rs.js.map +1 -0
- package/dist-vue/_chunks/{PkFilePreviewDialog-BSvgiM9A.js → PkFilePreviewDialog-QDPoZh1v.js} +2 -2
- package/dist-vue/_chunks/{PkFilePreviewDialog-BSvgiM9A.js.map → PkFilePreviewDialog-QDPoZh1v.js.map} +1 -1
- package/dist-vue/_chunks/{PkStreamingMarkdown-Dk3iXhTm.js → PkStreamingMarkdown-qnKwvrCg.js} +2 -2
- package/dist-vue/_chunks/{PkStreamingMarkdown-Dk3iXhTm.js.map → PkStreamingMarkdown-qnKwvrCg.js.map} +1 -1
- package/dist-vue/_chunks/PkToolChatFile-i0rHgFxB.js +227 -0
- package/dist-vue/_chunks/PkToolChatFile-i0rHgFxB.js.map +1 -0
- package/dist-vue/_chunks/{PkToolShowArtifact-BtCGilTJ.js → PkToolShowArtifact-Dh4ogn6A.js} +2 -2
- package/dist-vue/_chunks/{PkToolShowArtifact-BtCGilTJ.js.map → PkToolShowArtifact-Dh4ogn6A.js.map} +1 -1
- package/dist-vue/_chunks/{PkToolShowContactForm-BZNIeJpf.js → PkToolShowContactForm-BGTI1sio.js} +2 -2
- package/dist-vue/_chunks/{PkToolShowContactForm-BZNIeJpf.js.map → PkToolShowContactForm-BGTI1sio.js.map} +1 -1
- package/dist-vue/_chunks/{PkToolShowDiagram-KD4MfVkP.js → PkToolShowDiagram-xef3wJb0.js} +2 -2
- package/dist-vue/_chunks/{PkToolShowDiagram-KD4MfVkP.js.map → PkToolShowDiagram-xef3wJb0.js.map} +1 -1
- package/dist-vue/_chunks/{PkToolShowForm-Dtfpi58S.js → PkToolShowForm-Crg4Kl6v.js} +3 -3
- package/dist-vue/_chunks/{PkToolShowForm-Dtfpi58S.js.map → PkToolShowForm-Crg4Kl6v.js.map} +1 -1
- package/dist-vue/_chunks/{PkToolShowImageGallery-DnS04nTs.js → PkToolShowImageGallery-D9hdGBHK.js} +2 -2
- package/dist-vue/_chunks/{PkToolShowImageGallery-DnS04nTs.js.map → PkToolShowImageGallery-D9hdGBHK.js.map} +1 -1
- package/dist-vue/_chunks/{PkToolShowProductList-BlFKAtqQ.js → PkToolShowProductList-SC5aKDCw.js} +2 -2
- package/dist-vue/_chunks/{PkToolShowProductList-BlFKAtqQ.js.map → PkToolShowProductList-SC5aKDCw.js.map} +1 -1
- package/dist-vue/_chunks/{PkToolShowSources-DM177ZlR.js → PkToolShowSources-Bf9_JwFL.js} +2 -2
- package/dist-vue/_chunks/{PkToolShowSources-DM177ZlR.js.map → PkToolShowSources-Bf9_JwFL.js.map} +1 -1
- package/dist-vue/_chunks/{PkToolShowVideo-DQdVpaWT.js → PkToolShowVideo-C2ITZDNo.js} +2 -2
- package/dist-vue/_chunks/{PkToolShowVideo-DQdVpaWT.js.map → PkToolShowVideo-C2ITZDNo.js.map} +1 -1
- package/dist-vue/_chunks/{PkToolShowWebPages-Cx2Ft_wN.js → PkToolShowWebPages-BrefGxKQ.js} +2 -2
- package/dist-vue/_chunks/{PkToolShowWebPages-Cx2Ft_wN.js.map → PkToolShowWebPages-BrefGxKQ.js.map} +1 -1
- package/dist-vue/_chunks/excelNumberFormat-COn5tHoH.js +543 -0
- package/dist-vue/_chunks/excelNumberFormat-COn5tHoH.js.map +1 -0
- package/dist-vue/_chunks/{utils-BuxgMuKv.js → utils-B0PnU1Rk.js} +7 -6
- package/dist-vue/_chunks/utils-B0PnU1Rk.js.map +1 -0
- package/dist-vue/composables.js +1 -1
- package/dist-vue/index.js +21 -21
- package/dist-vue/index.js.map +1 -1
- package/dist-vue/packages/components/src/chat/excelNumberFormat.d.ts +34 -0
- package/dist-vue/packages/components/src/chat/useChatFilePreview.d.ts +20 -0
- package/dist-vue/packages/components/src/chat/utils.d.ts +2 -0
- package/dist-vue/packages/models/src/schema/SpreadsheetPreview.d.ts +26 -0
- package/dist-vue/packages/models/src/schema/WordPreview.d.ts +11 -0
- package/package.json +1 -1
- package/dist/_chunks/PkFilePreview-D_piCsAW.js.map +0 -1
- package/dist/_chunks/PkToolChatFile-DO4zjMJr.js.map +0 -1
- package/dist/_chunks/utils-BHvRrCzW.js.map +0 -1
- package/dist-vue/_chunks/PkFilePreview-jeqvHDm7.js +0 -1127
- package/dist-vue/_chunks/PkFilePreview-jeqvHDm7.js.map +0 -1
- package/dist-vue/_chunks/PkToolChatFile-Bnj-YFLh.js +0 -219
- package/dist-vue/_chunks/PkToolChatFile-Bnj-YFLh.js.map +0 -1
- package/dist-vue/_chunks/utils-BuxgMuKv.js.map +0 -1
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
import { t as e } from "./rolldown-runtime-CGnMp29N.js";
|
|
2
|
-
import { E as t, M as n } from "./Agent-DQl-tv4S.js";
|
|
3
|
-
import { c as r } from "./utils-BuxgMuKv.js";
|
|
4
|
-
import { t as i } from "./PkChatbotFilePreview-KxVpL0UT.js";
|
|
5
|
-
import { VvIcon as a } from "@volverjs/ui-vue/components";
|
|
6
|
-
import { Fragment as o, computed as s, createCommentVNode as c, createElementBlock as l, createElementVNode as u, createTextVNode as d, createVNode as f, defineComponent as p, openBlock as m, ref as h, renderList as g, toDisplayString as _, unref as v } from "vue";
|
|
7
|
-
import { useI18n as y } from "vue-i18n";
|
|
8
|
-
// ../../packages/components/src/chat/PkToolChatFile.vue?vue&type=script&setup=true&lang.ts
|
|
9
|
-
var b = {
|
|
10
|
-
key: 0,
|
|
11
|
-
class: "pk-tool-chat-file"
|
|
12
|
-
}, x = {
|
|
13
|
-
key: 0,
|
|
14
|
-
class: "pk-tool-chat-file__changes mt-xs"
|
|
15
|
-
}, S = { class: "pk-tool-chat-file__summary" }, C = {
|
|
16
|
-
key: 0,
|
|
17
|
-
class: "pk-tool-chat-file__scroll"
|
|
18
|
-
}, w = {
|
|
19
|
-
key: 0,
|
|
20
|
-
class: "pk-tool-chat-file__table"
|
|
21
|
-
}, T = {
|
|
22
|
-
scope: "col",
|
|
23
|
-
class: "pk-tool-chat-file__cell"
|
|
24
|
-
}, ee = { scope: "col" }, te = { scope: "col" }, E = {
|
|
25
|
-
colspan: "3",
|
|
26
|
-
scope: "rowgroup",
|
|
27
|
-
class: "pk-tool-chat-file__sheet"
|
|
28
|
-
}, D = {
|
|
29
|
-
key: 0,
|
|
30
|
-
colspan: "3",
|
|
31
|
-
class: "pk-tool-chat-file__after"
|
|
32
|
-
}, O = { class: "pk-tool-chat-file__cell" }, k = { class: "pk-tool-chat-file__before" }, A = { class: "pk-tool-chat-file__after" }, j = {
|
|
33
|
-
key: 1,
|
|
34
|
-
class: "pk-tool-chat-file__paragraphs"
|
|
35
|
-
}, M = { class: "pk-tool-chat-file__what" }, N = { class: "pk-tool-chat-file__text" }, P = {
|
|
36
|
-
key: 0,
|
|
37
|
-
class: "pk-tool-chat-file__removed"
|
|
38
|
-
}, F = {
|
|
39
|
-
key: 1,
|
|
40
|
-
class: "pk-tool-chat-file__added"
|
|
41
|
-
}, I = { key: 2 }, L = {
|
|
42
|
-
key: 2,
|
|
43
|
-
class: "pk-tool-chat-file__note"
|
|
44
|
-
}, R = ["aria-expanded"], z = {
|
|
45
|
-
key: 1,
|
|
46
|
-
class: "text-12 text-word-3 mt-xs mb-0"
|
|
47
|
-
}, B = 3, V = /*@__PURE__*/ p({
|
|
48
|
-
__name: "PkToolChatFile",
|
|
49
|
-
props: {
|
|
50
|
-
part: {},
|
|
51
|
-
fileUrl: { type: Function },
|
|
52
|
-
preview: { type: Function },
|
|
53
|
-
latestVersions: {},
|
|
54
|
-
restore: { type: Function }
|
|
55
|
-
},
|
|
56
|
-
setup(e) {
|
|
57
|
-
let p = /* @__PURE__ */ new Set(["tool-editWordDocument", "tool-createWordDocument"]), V = e, { t: H } = y({ useScope: "global" }), U = h(!1), W = (e) => e?.replace(/… \(\d+ characters\)$/, "…"), G = (e, t, n) => {
|
|
58
|
-
let r = e.split(/(\s+)/).filter(Boolean);
|
|
59
|
-
return r.length <= (t && n ? 24 : 12) ? e : t && n ? `${r.slice(0, 12).join("")}… ${r.slice(-12).join("")}` : n ? `…${r.slice(-12).join("")}` : `${r.slice(0, 12).join("")}…`;
|
|
60
|
-
}, K = (e, t) => {
|
|
61
|
-
let n = e.split(/(\s+)/).filter(Boolean), r = t.split(/(\s+)/).filter(Boolean), i = Array.from({ length: n.length + 1 }, () => Array(r.length + 1).fill(0));
|
|
62
|
-
for (let e = n.length - 1; e >= 0; e--) for (let t = r.length - 1; t >= 0; t--) i[e][t] = n[e] === r[t] ? i[e + 1][t + 1] + 1 : Math.max(i[e + 1][t], i[e][t + 1]);
|
|
63
|
-
let a = [], o = (e, t) => {
|
|
64
|
-
let n = a[a.length - 1];
|
|
65
|
-
n?.kind === t ? n.text += e : a.push({
|
|
66
|
-
text: e,
|
|
67
|
-
kind: t
|
|
68
|
-
});
|
|
69
|
-
}, s = 0, c = 0;
|
|
70
|
-
for (; s < n.length || c < r.length;) s < n.length && c < r.length && n[s] === r[c] ? (o(n[s++], "same"), c++) : c >= r.length || s < n.length && i[s + 1][c] >= i[s][c + 1] ? o(n[s++], "removed") : o(r[c++], "added");
|
|
71
|
-
return a.map((e, t) => e.kind === "same" ? {
|
|
72
|
-
...e,
|
|
73
|
-
text: G(e.text, t > 0, t < a.length - 1)
|
|
74
|
-
} : e);
|
|
75
|
-
}, q = (e) => {
|
|
76
|
-
switch (e) {
|
|
77
|
-
case "insertParagraphs": return H("messagePart.chatFileParagraphAdded");
|
|
78
|
-
case "deleteParagraphs": return H("messagePart.chatFileParagraphDeleted");
|
|
79
|
-
case "insertTableRow": return H("messagePart.chatFileTableRowAdded");
|
|
80
|
-
case "deleteTableRow": return H("messagePart.chatFileTableRowDeleted");
|
|
81
|
-
case "acceptRevisions": return H("messagePart.chatFileRevisionAccepted");
|
|
82
|
-
case "rejectRevisions": return H("messagePart.chatFileRevisionRejected");
|
|
83
|
-
default: return H("messagePart.chatFileParagraphChanged");
|
|
84
|
-
}
|
|
85
|
-
}, J = (e) => {
|
|
86
|
-
let t = W(e.before), n = W(e.after);
|
|
87
|
-
return {
|
|
88
|
-
what: q(e.op),
|
|
89
|
-
segments: t && n ? K(t, n) : [t ? {
|
|
90
|
-
text: t,
|
|
91
|
-
kind: "removed"
|
|
92
|
-
} : {
|
|
93
|
-
text: n ?? "",
|
|
94
|
-
kind: "same"
|
|
95
|
-
}]
|
|
96
|
-
};
|
|
97
|
-
}, Y = (e) => {
|
|
98
|
-
let t = e.cell ?? "", n = e.before ? void 0 : /^new sheet, (\d+) row\(s\)$/.exec(e.after ?? "")?.[1], r = e.newSheetRows ?? (n ? Number(n) : void 0);
|
|
99
|
-
if (r !== void 0) return {
|
|
100
|
-
sheet: t,
|
|
101
|
-
newSheet: H("messagePart.chatFileNewSheet", r)
|
|
102
|
-
};
|
|
103
|
-
let i = t.lastIndexOf("!"), a = t.slice(i + 1), o = /^A(\d+):[A-Z]+(\d+)$/.exec(a);
|
|
104
|
-
return {
|
|
105
|
-
sheet: t.slice(0, Math.max(i, 0)),
|
|
106
|
-
cell: o && o[1] === o[2] ? H("messagePart.chatFileRow", { row: o[1] }) : a,
|
|
107
|
-
before: W(e.before) || void 0,
|
|
108
|
-
after: W(e.after) || void 0
|
|
109
|
-
};
|
|
110
|
-
}, X = s(() => {
|
|
111
|
-
let e = V.part;
|
|
112
|
-
if (e.state !== "output-available" || !e.output?.storedFileName) return;
|
|
113
|
-
let r = e.output, i = p.has(e.type ?? ""), a;
|
|
114
|
-
i && r.changedParagraphs !== void 0 ? a = r.tracked ? H("messagePart.editWordDocumentRevisions", r.changedParagraphs) : H("messagePart.editWordDocumentParagraphs", r.changedParagraphs) : !i && r.changedCells !== void 0 && (a = H("messagePart.editSpreadsheetCells", r.changedCells));
|
|
115
|
-
let o = a ? r.changes ?? [] : [], s = [];
|
|
116
|
-
r.stalePivots && s.push(H("messagePart.chatFileRefreshPivots")), r.staleTableOfContents && s.push(H("messagePart.chatFileUpdateTableOfContents"));
|
|
117
|
-
let c = a && r.version ? H("messagePart.chatFileVersionSummary", {
|
|
118
|
-
version: r.version,
|
|
119
|
-
changed: a
|
|
120
|
-
}) : a;
|
|
121
|
-
return r.restoredFrom && (c = H("messagePart.chatFileRestored", {
|
|
122
|
-
version: r.version,
|
|
123
|
-
restored: r.restoredFrom
|
|
124
|
-
})), {
|
|
125
|
-
output: r,
|
|
126
|
-
mediaType: i ? n : t,
|
|
127
|
-
summary: c,
|
|
128
|
-
cells: i ? [] : o.map(Y),
|
|
129
|
-
paragraphs: i ? o.map(J) : [],
|
|
130
|
-
count: o.length,
|
|
131
|
-
more: r.moreChanges ?? 0,
|
|
132
|
-
reminders: s
|
|
133
|
-
};
|
|
134
|
-
}), Z = (e) => U.value ? e ?? [] : (e ?? []).slice(0, B), ne = s(() => Z(X.value?.paragraphs)), re = s(() => {
|
|
135
|
-
let e = /* @__PURE__ */ new Map();
|
|
136
|
-
for (let t of Z(X.value?.cells)) {
|
|
137
|
-
let n = e.get(t.sheet);
|
|
138
|
-
n ? n.rows.push(t) : e.set(t.sheet, {
|
|
139
|
-
sheet: t.sheet,
|
|
140
|
-
rows: [t]
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
return [...e.values()];
|
|
144
|
-
}), Q = s(() => (X.value?.count ?? 0) - B), $ = s(() => {
|
|
145
|
-
let e = X.value?.output, t = e?.fileId ? V.latestVersions?.get(e.fileId) : void 0;
|
|
146
|
-
return e?.fileId && e.version && t && e.version < t ? {
|
|
147
|
-
fileId: e.fileId,
|
|
148
|
-
version: e.version,
|
|
149
|
-
filename: r(e.filename ?? e.storedFileName, e.version)
|
|
150
|
-
} : void 0;
|
|
151
|
-
}), ie = () => {
|
|
152
|
-
$.value && V.restore?.($.value);
|
|
153
|
-
}, ae = () => {
|
|
154
|
-
let e = X.value?.output;
|
|
155
|
-
e && V.preview && V.preview({
|
|
156
|
-
kind: X.value?.mediaType === "application/vnd.openxmlformats-officedocument.wordprocessingml.document" ? "word" : "spreadsheet",
|
|
157
|
-
storedFileName: e.storedFileName,
|
|
158
|
-
filename: r(e.filename ?? e.storedFileName, e.version),
|
|
159
|
-
version: e.version,
|
|
160
|
-
fileId: e.fileId
|
|
161
|
-
});
|
|
162
|
-
};
|
|
163
|
-
return (t, n) => {
|
|
164
|
-
let r = a;
|
|
165
|
-
return X.value ? (m(), l("div", b, [f(i, {
|
|
166
|
-
"media-type": X.value.mediaType,
|
|
167
|
-
url: e.fileUrl(X.value.output.storedFileName),
|
|
168
|
-
filename: X.value.output.filename,
|
|
169
|
-
size: X.value.output.sizeBytes,
|
|
170
|
-
"show-download": "",
|
|
171
|
-
"on-preview": e.preview ? ae : void 0,
|
|
172
|
-
"on-restore": e.restore && $.value ? ie : void 0
|
|
173
|
-
}, null, 8, [
|
|
174
|
-
"media-type",
|
|
175
|
-
"url",
|
|
176
|
-
"filename",
|
|
177
|
-
"size",
|
|
178
|
-
"on-preview",
|
|
179
|
-
"on-restore"
|
|
180
|
-
]), X.value.count || X.value.output.restoredFrom ? (m(), l("section", x, [
|
|
181
|
-
u("h4", S, _(X.value.summary), 1),
|
|
182
|
-
X.value.count ? (m(), l("div", C, [X.value.cells.length ? (m(), l("table", w, [u("thead", null, [u("tr", null, [
|
|
183
|
-
u("th", T, _(v(H)("messagePart.chatFileCell")), 1),
|
|
184
|
-
u("th", ee, _(v(H)("messagePart.chatFileBefore")), 1),
|
|
185
|
-
u("th", te, _(v(H)("messagePart.chatFileAfter")), 1)
|
|
186
|
-
])]), (m(!0), l(o, null, g(re.value, (e, t) => (m(), l("tbody", { key: t }, [u("tr", null, [u("th", E, _(v(H)("messagePart.chatFileSheet", { name: e.sheet })), 1)]), (m(!0), l(o, null, g(e.rows, (e, t) => (m(), l("tr", { key: t }, [e.newSheet ? (m(), l("td", D, _(e.newSheet), 1)) : (m(), l(o, { key: 1 }, [
|
|
187
|
-
u("td", O, _(e.cell), 1),
|
|
188
|
-
u("td", k, _(e.before), 1),
|
|
189
|
-
u("td", A, _(e.after), 1)
|
|
190
|
-
], 64))]))), 128))]))), 128))])) : (m(), l("ul", j, [(m(!0), l(o, null, g(ne.value, (e, t) => (m(), l("li", {
|
|
191
|
-
key: t,
|
|
192
|
-
class: "pk-tool-chat-file__paragraph"
|
|
193
|
-
}, [u("span", M, _(e.what), 1), u("span", N, [(m(!0), l(o, null, g(e.segments, (e, t) => (m(), l(o, { key: t }, [e.kind === "removed" ? (m(), l("del", P, _(e.text), 1)) : e.kind === "added" ? (m(), l("ins", F, _(e.text), 1)) : (m(), l("span", I, _(e.text), 1))], 64))), 128))])]))), 128))])), U.value && X.value.more ? (m(), l("p", L, _(v(H)("messagePart.chatFileMoreChanges", X.value.more)), 1)) : c("", !0)])) : c("", !0),
|
|
194
|
-
Q.value > 0 ? (m(), l("button", {
|
|
195
|
-
key: 1,
|
|
196
|
-
type: "button",
|
|
197
|
-
class: "pk-tool-chat-file__more",
|
|
198
|
-
"aria-expanded": U.value,
|
|
199
|
-
onClick: n[0] ||= (e) => U.value = !U.value
|
|
200
|
-
}, [f(r, {
|
|
201
|
-
name: U.value ? "ri:arrow-up-s-line" : "ri:arrow-down-s-line",
|
|
202
|
-
class: "text-16",
|
|
203
|
-
"aria-hidden": "true"
|
|
204
|
-
}, null, 8, ["name"]), d(" " + _(U.value ? v(H)("action.showLess") : v(H)("action.showMore", { count: Q.value })), 1)], 8, R)) : c("", !0),
|
|
205
|
-
(m(!0), l(o, null, g(X.value.reminders, (e) => (m(), l("p", {
|
|
206
|
-
key: e,
|
|
207
|
-
class: "pk-tool-chat-file__reminder"
|
|
208
|
-
}, [f(r, {
|
|
209
|
-
name: "ri:information-line",
|
|
210
|
-
class: "pk-tool-chat-file__reminder-icon",
|
|
211
|
-
"aria-hidden": "true"
|
|
212
|
-
}), d(" " + _(e), 1)]))), 128))
|
|
213
|
-
])) : X.value.summary ? (m(), l("p", z, _(X.value.summary), 1)) : c("", !0)])) : c("", !0);
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
}), H = /* @__PURE__ */ e({ default: () => U }), U = V;
|
|
217
|
-
export { H as n, U as t };
|
|
218
|
-
|
|
219
|
-
//# sourceMappingURL=PkToolChatFile-Bnj-YFLh.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PkToolChatFile-Bnj-YFLh.js","names":["__unplugin_components_0","_openBlock","_createElementBlock","_createVNode","PkChatbotFilePreview","_createElementVNode","_toDisplayString","_unref","_Fragment","_renderList","_createCommentVNode","_createTextVNode","_sfc_main","__exportAll","SPREADSHEET_MIME_TYPE","WORD_MIME_TYPE","chatFileName","PkChatbotFilePreview_default","_hoisted_1","_hoisted_2","_hoisted_3","_hoisted_4","_hoisted_5","_hoisted_6","_hoisted_7","_hoisted_8","_hoisted_9","_hoisted_10","_hoisted_11","_hoisted_12","_hoisted_13","_hoisted_14","_hoisted_15","_hoisted_16","_hoisted_17","_hoisted_18","_hoisted_19","_hoisted_20","_hoisted_21","_hoisted_22","SHOWN_CHANGES","PkToolChatFile_vue_vue_type_script_setup_true_lang_default","WORD_TOOL_PARTS","props","__props","$t","useI18n","showAll","ref","withoutLength","text","contextOf","runs","before","after","excerptOf","a","b","common","i","j","push","last","kind","run","k","wordChangeLabel","op","paragraphRow","change","cellRow","legacy","rows","bang","cell","appended","file","computed","part","output","word","changed","changes","reminders","summary","shown","shownParagraphs","shownSheets","groups","row","group","hiddenRows","olderVersion","latest","restoreThis","openPreview","_component_VvIcon","VvIcon","openBlock","createElementBlock","createVNode","createElementVNode","toDisplayString","unref","Fragment","renderList","g","index","s","segment","createCommentVNode","_cache","createTextVNode","reminder","PkToolChatFile_exports","PkToolChatFile_default"],"sources":["../../../../packages/components/src/chat/PkToolChatFile.vue","../../../../packages/components/src/chat/PkToolChatFile.vue"],"sourcesContent":["<script setup lang=\"ts\">\n import { computed, ref } from 'vue'\n import { useI18n } from 'vue-i18n'\n import { SPREADSHEET_MIME_TYPE, WORD_MIME_TYPE } from 'models'\n import PkChatbotFilePreview from './PkChatbotFilePreview.vue'\n import {\n chatFileName,\n type ChatFilePreviewTarget,\n type ChatFileRestoreTarget,\n } from './utils'\n\n /**\n * One entry of `changes`: a cell (or an appended row, or a new sheet) of\n * `editSpreadsheet`, a paragraph or a table row of `editWordDocument`.\n */\n type ChatFileChange = {\n cell?: string\n op?: string\n before?: string\n after?: string\n newSheetRows?: number\n }\n\n /** What the four file tools return that the card shows. */\n type ChatFileOutput = {\n /** The file every version of it answers to. */\n fileId?: string\n storedFileName: string\n filename?: string\n sizeBytes?: number\n version?: number\n changedCells?: number\n changedParagraphs?: number\n changes?: ChatFileChange[]\n moreChanges?: number\n /** Of a Word edit: the changes are revisions. */\n tracked?: boolean\n stalePivots?: true\n staleTableOfContents?: true\n /** Of a restore: the version this one writes again. */\n restoredFrom?: number\n }\n\n /** A run of an excerpt: text kept, taken away or put in. */\n type Segment = { text: string; kind: 'same' | 'removed' | 'added' }\n\n /**\n * A changed cell as a row of the table: its value before and after, or\n * the line that stands for a new sheet.\n */\n type CellRow = {\n sheet: string\n cell?: string\n before?: string\n after?: string\n newSheet?: string\n }\n\n /** The rows of one sheet, under its name. */\n type SheetGroup = { sheet: string; rows: CellRow[] }\n\n /** A changed paragraph or table row: what happened, and its words. */\n type ParagraphRow = { what: string; segments: Segment[] }\n\n /** The tools whose output is a Word document; the others write a spreadsheet. */\n const WORD_TOOL_PARTS = new Set([\n 'tool-editWordDocument',\n 'tool-createWordDocument',\n ])\n\n /** Rows shown before \"View more\": most edits are one to three changes. */\n const SHOWN_CHANGES = 3\n /** Words of context kept on each side of a change in a paragraph. */\n const CONTEXT_WORDS = 6\n\n /**\n * The file a call of `editSpreadsheet`, `editWordDocument`,\n * `createSpreadsheet` or `createWordDocument` wrote, a new version or a\n * new file, to download. Drawn once the call has an output: while it runs,\n * the feed's activity indicator names it, and a refused call is explained\n * by the answer. Under an edit, a frame says what changed, its first\n * rows shown: a table of cells for a spreadsheet, the changed words of\n * each paragraph for a Word document, and what is left to do in Office.\n */\n const props = defineProps<{\n part: unknown\n /** The authenticated download URL of a file stored in this chat. */\n fileUrl: (storedFileName: string) => string\n /** Opens the preview of the file, where the chat has one. */\n preview?: (file: ChatFilePreviewTarget) => void\n /** The latest version of each file the conversation shows, by fileId. */\n latestVersions?: ReadonlyMap<string, number>\n /**\n * Asks the agent to write an earlier version again as the newest one,\n * where the chat can send a message.\n */\n restore?: (file: ChatFileRestoreTarget) => void\n }>()\n\n const { t: $t } = useI18n({ useScope: 'global' })\n\n const showAll = ref(false)\n\n /**\n * The services cut a long text for the model and give its length\n * (`… (523 characters)`, the marker of every tool result, written by\n * `wordDocument.service.ts` and `spreadsheet.service.ts`): the card keeps\n * the ellipsis only.\n */\n const withoutLength = (text: string | undefined) =>\n text?.replace(/… \\(\\d+ characters\\)$/, '…')\n\n /**\n * A run of unchanged words cut to a few words on the side of each change\n * it touches: the head of the text keeps its end, the tail its start, a\n * run between two changes both, with an ellipsis where words went.\n */\n const contextOf = (text: string, before: boolean, after: boolean) => {\n const runs = text.split(/(\\s+)/).filter(Boolean)\n // Every word is followed by its space: twice as many runs.\n const keep = CONTEXT_WORDS * 2\n if (runs.length <= (before && after ? keep * 2 : keep)) {\n return text\n }\n if (before && after) {\n return `${runs.slice(0, keep).join('')}… ${runs.slice(-keep).join('')}`\n }\n return after\n ? `…${runs.slice(-keep).join('')}`\n : `${runs.slice(0, keep).join('')}…`\n }\n\n /**\n * The words of `before` and `after` that differ, word by word, so the\n * words two changes share between them stay plain. An echoed paragraph\n * is at most a few hundred characters, a few dozen words for the table.\n */\n const excerptOf = (before: string, after: string): Segment[] => {\n const a = before.split(/(\\s+)/).filter(Boolean)\n const b = after.split(/(\\s+)/).filter(Boolean)\n // Longest common subsequence, from the end\n const common = Array.from({ length: a.length + 1 }, () =>\n new Array<number>(b.length + 1).fill(0),\n )\n for (let i = a.length - 1; i >= 0; i--) {\n for (let j = b.length - 1; j >= 0; j--) {\n common[i][j] =\n a[i] === b[j]\n ? common[i + 1][j + 1] + 1\n : Math.max(common[i + 1][j], common[i][j + 1])\n }\n }\n const runs: Segment[] = []\n const push = (text: string, kind: Segment['kind']) => {\n const last = runs[runs.length - 1]\n if (last?.kind === kind) {\n last.text += text\n } else {\n runs.push({ text, kind })\n }\n }\n let i = 0\n let j = 0\n while (i < a.length || j < b.length) {\n if (i < a.length && j < b.length && a[i] === b[j]) {\n push(a[i++], 'same')\n j++\n } else if (\n j >= b.length ||\n (i < a.length && common[i + 1][j] >= common[i][j + 1])\n ) {\n push(a[i++], 'removed')\n } else {\n push(b[j++], 'added')\n }\n }\n return runs.map((run, k) =>\n run.kind === 'same'\n ? {\n ...run,\n text: contextOf(run.text, k > 0, k < runs.length - 1),\n }\n : run,\n )\n }\n\n /** What a Word operation did, as the row says it. */\n const wordChangeLabel = (op: string | undefined) => {\n switch (op) {\n case 'insertParagraphs':\n return $t('messagePart.chatFileParagraphAdded')\n case 'deleteParagraphs':\n return $t('messagePart.chatFileParagraphDeleted')\n case 'insertTableRow':\n return $t('messagePart.chatFileTableRowAdded')\n case 'deleteTableRow':\n return $t('messagePart.chatFileTableRowDeleted')\n case 'acceptRevisions':\n return $t('messagePart.chatFileRevisionAccepted')\n case 'rejectRevisions':\n return $t('messagePart.chatFileRevisionRejected')\n default:\n return $t('messagePart.chatFileParagraphChanged')\n }\n }\n\n /**\n * A paragraph marked as Word marks a revision, struck where words went\n * and underlined where they came. A paragraph only added or only removed\n * is said by its label: the text added stays plain, the text removed\n * stays struck.\n */\n const paragraphRow = (change: ChatFileChange): ParagraphRow => {\n const before = withoutLength(change.before)\n const after = withoutLength(change.after)\n return {\n what: wordChangeLabel(change.op),\n segments:\n before && after\n ? excerptOf(before, after)\n : [\n before\n ? { text: before, kind: 'removed' }\n : { text: after ?? '', kind: 'same' },\n ],\n }\n }\n\n /**\n * A cell as a person reads it: its sheet heads the group of its rows, so\n * the row says `C5` and not Excel's `Listino!C5`, and a row the edit\n * appended says \"Row 10\" and not `A10:F10`.\n */\n const cellRow = (change: ChatFileChange): CellRow => {\n const ref = change.cell ?? ''\n // A new sheet is named alone, with no cell. An edit made before the\n // card read `newSheetRows` said it only in the model's words.\n const legacy = change.before\n ? undefined\n : /^new sheet, (\\d+) row\\(s\\)$/.exec(change.after ?? '')?.[1]\n const rows =\n change.newSheetRows ?? (legacy ? Number(legacy) : undefined)\n if (rows !== undefined) {\n return {\n sheet: ref,\n newSheet: $t('messagePart.chatFileNewSheet', rows),\n }\n }\n\n const bang = ref.lastIndexOf('!')\n const cell = ref.slice(bang + 1)\n const appended = /^A(\\d+):[A-Z]+(\\d+)$/.exec(cell)\n return {\n sheet: ref.slice(0, Math.max(bang, 0)),\n cell:\n appended && appended[1] === appended[2]\n ? $t('messagePart.chatFileRow', { row: appended[1] })\n : cell,\n before: withoutLength(change.before) || undefined,\n after: withoutLength(change.after) || undefined,\n }\n }\n\n const file = computed(() => {\n const part = props.part as {\n type?: string\n state?: string\n output?: Partial<ChatFileOutput>\n }\n if (part.state !== 'output-available' || !part.output?.storedFileName) {\n return undefined\n }\n const output = part.output as ChatFileOutput\n const word = WORD_TOOL_PARTS.has(part.type ?? '')\n // A new file has no count of changes. Each key is written out in its\n // own call: the widget ships only the keys it finds that way.\n let changed: string | undefined\n if (word && output.changedParagraphs !== undefined) {\n changed = output.tracked\n ? $t(\n 'messagePart.editWordDocumentRevisions',\n output.changedParagraphs,\n )\n : $t(\n 'messagePart.editWordDocumentParagraphs',\n output.changedParagraphs,\n )\n } else if (!word && output.changedCells !== undefined) {\n changed = $t(\n 'messagePart.editSpreadsheetCells',\n output.changedCells,\n )\n }\n const changes = changed ? (output.changes ?? []) : []\n const reminders: string[] = []\n if (output.stalePivots) {\n reminders.push($t('messagePart.chatFileRefreshPivots'))\n }\n if (output.staleTableOfContents) {\n reminders.push($t('messagePart.chatFileUpdateTableOfContents'))\n }\n let summary =\n changed && output.version\n ? $t('messagePart.chatFileVersionSummary', {\n version: output.version,\n changed,\n })\n : changed\n if (output.restoredFrom) {\n summary = $t('messagePart.chatFileRestored', {\n version: output.version,\n restored: output.restoredFrom,\n })\n }\n return {\n output,\n mediaType: word ? WORD_MIME_TYPE : SPREADSHEET_MIME_TYPE,\n summary,\n cells: word ? [] : changes.map(cellRow),\n paragraphs: word ? changes.map(paragraphRow) : [],\n count: changes.length,\n more: output.moreChanges ?? 0,\n reminders,\n }\n })\n\n const shown = <T,>(rows: T[] | undefined): T[] =>\n showAll.value ? (rows ?? []) : (rows ?? []).slice(0, SHOWN_CHANGES)\n const shownParagraphs = computed(() => shown(file.value?.paragraphs))\n /** The rows shown, a group per sheet in the order the edit reached it. */\n const shownSheets = computed(() => {\n const groups = new Map<string, SheetGroup>()\n for (const row of shown(file.value?.cells)) {\n const group = groups.get(row.sheet)\n if (group) {\n group.rows.push(row)\n } else {\n groups.set(row.sheet, { sheet: row.sheet, rows: [row] })\n }\n }\n return [...groups.values()]\n })\n const hiddenRows = computed(() => (file.value?.count ?? 0) - SHOWN_CHANGES)\n\n /**\n * The version this card wrote, when a later one of the same file is in\n * the conversation: the one the user can ask to have back.\n */\n const olderVersion = computed(() => {\n const output = file.value?.output\n const latest = output?.fileId\n ? props.latestVersions?.get(output.fileId)\n : undefined\n return output?.fileId &&\n output.version &&\n latest &&\n output.version < latest\n ? {\n fileId: output.fileId,\n version: output.version,\n filename: chatFileName(\n output.filename ?? output.storedFileName,\n output.version,\n ),\n }\n : undefined\n })\n\n /** Asks the agent for this version back. */\n const restoreThis = () => {\n if (olderVersion.value) {\n props.restore?.(olderVersion.value)\n }\n }\n\n /** Opens this version in the chat's viewer. */\n const openPreview = () => {\n const output = file.value?.output\n if (!output || !props.preview) {\n return\n }\n props.preview({\n kind:\n file.value?.mediaType === WORD_MIME_TYPE\n ? 'word'\n : 'spreadsheet',\n storedFileName: output.storedFileName,\n filename: chatFileName(\n output.filename ?? output.storedFileName,\n output.version,\n ),\n version: output.version,\n fileId: output.fileId,\n })\n }\n</script>\n\n<template>\n <div v-if=\"file\" class=\"pk-tool-chat-file\">\n <!-- Restore and open live in the file, beside its download: a\n bordered button under it weighed more than the file and the\n answer it belongs to -->\n <PkChatbotFilePreview\n :media-type=\"file.mediaType\"\n :url=\"fileUrl(file.output.storedFileName)\"\n :filename=\"file.output.filename\"\n :size=\"file.output.sizeBytes\"\n show-download\n :on-preview=\"preview ? openPreview : undefined\"\n :on-restore=\"restore && olderVersion ? restoreThis : undefined\" />\n <section\n v-if=\"file.count || file.output.restoredFrom\"\n class=\"pk-tool-chat-file__changes mt-xs\">\n <h4 class=\"pk-tool-chat-file__summary\">\n {{ file.summary }}\n </h4>\n <div v-if=\"file.count\" class=\"pk-tool-chat-file__scroll\">\n <table\n v-if=\"file.cells.length\"\n class=\"pk-tool-chat-file__table\">\n <thead>\n <tr>\n <th scope=\"col\" class=\"pk-tool-chat-file__cell\">\n {{ $t('messagePart.chatFileCell') }}\n </th>\n <th scope=\"col\">\n {{ $t('messagePart.chatFileBefore') }}\n </th>\n <th scope=\"col\">\n {{ $t('messagePart.chatFileAfter') }}\n </th>\n </tr>\n </thead>\n <tbody v-for=\"(group, g) in shownSheets\" :key=\"g\">\n <tr>\n <th\n colspan=\"3\"\n scope=\"rowgroup\"\n class=\"pk-tool-chat-file__sheet\">\n {{\n $t('messagePart.chatFileSheet', {\n name: group.sheet,\n })\n }}\n </th>\n </tr>\n <tr v-for=\"(row, index) in group.rows\" :key=\"index\">\n <td\n v-if=\"row.newSheet\"\n colspan=\"3\"\n class=\"pk-tool-chat-file__after\">\n {{ row.newSheet }}\n </td>\n <template v-else>\n <td class=\"pk-tool-chat-file__cell\">\n {{ row.cell }}\n </td>\n <td class=\"pk-tool-chat-file__before\">\n {{ row.before }}\n </td>\n <td class=\"pk-tool-chat-file__after\">\n {{ row.after }}\n </td>\n </template>\n </tr>\n </tbody>\n </table>\n <ul v-else class=\"pk-tool-chat-file__paragraphs\">\n <li\n v-for=\"(row, index) in shownParagraphs\"\n :key=\"index\"\n class=\"pk-tool-chat-file__paragraph\">\n <span class=\"pk-tool-chat-file__what\">\n {{ row.what }}\n </span>\n <span class=\"pk-tool-chat-file__text\">\n <template\n v-for=\"(segment, s) in row.segments\"\n :key=\"s\">\n <del\n v-if=\"segment.kind === 'removed'\"\n class=\"pk-tool-chat-file__removed\">\n {{ segment.text }}\n </del>\n <ins\n v-else-if=\"segment.kind === 'added'\"\n class=\"pk-tool-chat-file__added\">\n {{ segment.text }}\n </ins>\n <span v-else>{{ segment.text }}</span>\n </template>\n </span>\n </li>\n </ul>\n <p v-if=\"showAll && file.more\" class=\"pk-tool-chat-file__note\">\n {{ $t('messagePart.chatFileMoreChanges', file.more) }}\n </p>\n </div>\n <button\n v-if=\"hiddenRows > 0\"\n type=\"button\"\n class=\"pk-tool-chat-file__more\"\n :aria-expanded=\"showAll\"\n @click=\"showAll = !showAll\">\n <VvIcon\n :name=\"\n showAll ? 'ri:arrow-up-s-line' : 'ri:arrow-down-s-line'\n \"\n class=\"text-16\"\n aria-hidden=\"true\" />\n {{\n showAll\n ? $t('action.showLess')\n : $t('action.showMore', { count: hiddenRows })\n }}\n </button>\n <p\n v-for=\"reminder in file.reminders\"\n :key=\"reminder\"\n class=\"pk-tool-chat-file__reminder\">\n <VvIcon\n name=\"ri:information-line\"\n class=\"pk-tool-chat-file__reminder-icon\"\n aria-hidden=\"true\" />\n {{ reminder }}\n </p>\n </section>\n <p v-else-if=\"file.summary\" class=\"text-12 text-word-3 mt-xs mb-0\">\n {{ file.summary }}\n </p>\n </div>\n</template>\n\n<style lang=\"scss\">\n // One frame (DESIGN.md, principle 4): a hairline at surface-3, rounded-lg,\n // a solid ground over the dots of the chat, as wide as a short paragraph\n // while the file above keeps its 280px. Inside it every divider is one\n // hairline at surface-2.\n .pk-tool-chat-file__changes {\n max-width: 36rem;\n overflow: hidden;\n border: var(--border) solid var(--color-surface-3);\n border-radius: var(--rounded-lg);\n background-color: var(--color-surface);\n font-size: var(--text-12);\n }\n\n .pk-tool-chat-file__summary {\n margin: 0;\n padding: var(--spacing-8) var(--spacing-12);\n border-bottom: var(--border) solid var(--color-surface-3);\n color: var(--color-word-2);\n font-size: var(--text-12);\n font-weight: var(--font-medium);\n\n // A restore says only what it wrote back\n &:last-child {\n border-bottom: 0;\n }\n }\n\n // Bounded, so fifty changes scroll inside the frame\n .pk-tool-chat-file__scroll {\n max-height: 20rem;\n overflow-y: auto;\n }\n\n .pk-tool-chat-file__table {\n width: 100%;\n border-collapse: collapse;\n\n th,\n td {\n padding: var(--spacing-8) var(--spacing-12);\n border-bottom: var(--border) solid var(--color-surface-2);\n text-align: start;\n vertical-align: top;\n overflow-wrap: anywhere;\n }\n\n // Told apart by its weight and colour, no heavier rule\n th {\n color: var(--color-word-3);\n font-weight: var(--font-medium);\n }\n\n tbody:last-child tr:last-child td {\n border-bottom: 0;\n }\n }\n\n // The name of a sheet heads its rows, one step of surface under it\n .pk-tool-chat-file__table .pk-tool-chat-file__sheet {\n padding-block: var(--spacing-6);\n background-color: var(--color-surface-1);\n color: var(--color-word-2);\n }\n\n .pk-tool-chat-file__cell {\n width: 1%;\n color: var(--color-word-2);\n font-variant-numeric: tabular-nums;\n white-space: nowrap;\n }\n\n .pk-tool-chat-file__before {\n width: 50%;\n color: var(--color-word-3);\n }\n\n .pk-tool-chat-file__after {\n width: 50%;\n color: var(--color-word-1);\n }\n\n .pk-tool-chat-file__paragraphs {\n margin: 0;\n padding: 0;\n list-style: none;\n }\n\n .pk-tool-chat-file__paragraph {\n display: grid;\n grid-template-columns: minmax(4rem, max-content) 1fr;\n gap: var(--spacing-4) var(--spacing-md);\n padding: var(--spacing-8) var(--spacing-12);\n border-bottom: var(--border) solid var(--color-surface-2);\n\n &:last-child {\n border-bottom: 0;\n }\n }\n\n .pk-tool-chat-file__what {\n color: var(--color-word-3);\n white-space: nowrap;\n }\n\n .pk-tool-chat-file__text {\n min-width: 0;\n color: var(--color-word-2);\n overflow-wrap: anywhere;\n }\n\n // Marked as Word marks a revision, struck where words went and\n // underlined where they came, in the red and green of a comparison: the\n // change is what the row exists to report, the verdict exception of\n // DESIGN.md (principle 2). The readable text tokens hold the contrast in\n // both themes. The base styles take the line off `del`.\n .pk-tool-chat-file__removed {\n color: var(--u-danger-text);\n text-decoration: line-through;\n }\n\n .pk-tool-chat-file__added {\n color: var(--u-success-text);\n font-weight: var(--font-medium);\n text-decoration: underline;\n text-underline-offset: 0.2em;\n }\n\n .pk-tool-chat-file__removed + .pk-tool-chat-file__added {\n margin-inline-start: var(--spacing-4);\n }\n\n .pk-tool-chat-file__note {\n margin: 0;\n padding: var(--spacing-8) var(--spacing-12);\n border-top: var(--border) solid var(--color-surface-2);\n color: var(--color-word-3);\n }\n\n .pk-tool-chat-file__more {\n display: flex;\n align-items: center;\n justify-content: center;\n gap: var(--spacing-4);\n width: 100%;\n padding: var(--spacing-8) var(--spacing-12);\n border: 0;\n border-top: var(--border) solid var(--color-surface-2);\n background: none;\n color: var(--color-word-2);\n font: inherit;\n cursor: pointer;\n transition: background-color var(--duration-150) var(--ease-out);\n\n &:hover {\n background-color: var(--color-surface-1);\n }\n\n &:focus-visible {\n outline: var(--spacing-2) solid var(--input-focus-color);\n outline-offset: calc(var(--spacing-2) * -1);\n }\n }\n\n .pk-tool-chat-file__reminder {\n display: flex;\n align-items: flex-start;\n gap: var(--spacing-8);\n margin: 0;\n padding: var(--spacing-8) var(--spacing-12);\n border-top: var(--border) solid var(--color-surface-2);\n color: var(--color-word-2);\n }\n\n .pk-tool-chat-file__reminder-icon {\n flex-shrink: 0;\n margin-top: var(--spacing-2);\n color: var(--color-word-3);\n font-size: var(--text-14);\n }\n</style>\n","<script setup lang=\"ts\">\n import { computed, ref } from 'vue'\n import { useI18n } from 'vue-i18n'\n import { SPREADSHEET_MIME_TYPE, WORD_MIME_TYPE } from 'models'\n import PkChatbotFilePreview from './PkChatbotFilePreview.vue'\n import {\n chatFileName,\n type ChatFilePreviewTarget,\n type ChatFileRestoreTarget,\n } from './utils'\n\n /**\n * One entry of `changes`: a cell (or an appended row, or a new sheet) of\n * `editSpreadsheet`, a paragraph or a table row of `editWordDocument`.\n */\n type ChatFileChange = {\n cell?: string\n op?: string\n before?: string\n after?: string\n newSheetRows?: number\n }\n\n /** What the four file tools return that the card shows. */\n type ChatFileOutput = {\n /** The file every version of it answers to. */\n fileId?: string\n storedFileName: string\n filename?: string\n sizeBytes?: number\n version?: number\n changedCells?: number\n changedParagraphs?: number\n changes?: ChatFileChange[]\n moreChanges?: number\n /** Of a Word edit: the changes are revisions. */\n tracked?: boolean\n stalePivots?: true\n staleTableOfContents?: true\n /** Of a restore: the version this one writes again. */\n restoredFrom?: number\n }\n\n /** A run of an excerpt: text kept, taken away or put in. */\n type Segment = { text: string; kind: 'same' | 'removed' | 'added' }\n\n /**\n * A changed cell as a row of the table: its value before and after, or\n * the line that stands for a new sheet.\n */\n type CellRow = {\n sheet: string\n cell?: string\n before?: string\n after?: string\n newSheet?: string\n }\n\n /** The rows of one sheet, under its name. */\n type SheetGroup = { sheet: string; rows: CellRow[] }\n\n /** A changed paragraph or table row: what happened, and its words. */\n type ParagraphRow = { what: string; segments: Segment[] }\n\n /** The tools whose output is a Word document; the others write a spreadsheet. */\n const WORD_TOOL_PARTS = new Set([\n 'tool-editWordDocument',\n 'tool-createWordDocument',\n ])\n\n /** Rows shown before \"View more\": most edits are one to three changes. */\n const SHOWN_CHANGES = 3\n /** Words of context kept on each side of a change in a paragraph. */\n const CONTEXT_WORDS = 6\n\n /**\n * The file a call of `editSpreadsheet`, `editWordDocument`,\n * `createSpreadsheet` or `createWordDocument` wrote, a new version or a\n * new file, to download. Drawn once the call has an output: while it runs,\n * the feed's activity indicator names it, and a refused call is explained\n * by the answer. Under an edit, a frame says what changed, its first\n * rows shown: a table of cells for a spreadsheet, the changed words of\n * each paragraph for a Word document, and what is left to do in Office.\n */\n const props = defineProps<{\n part: unknown\n /** The authenticated download URL of a file stored in this chat. */\n fileUrl: (storedFileName: string) => string\n /** Opens the preview of the file, where the chat has one. */\n preview?: (file: ChatFilePreviewTarget) => void\n /** The latest version of each file the conversation shows, by fileId. */\n latestVersions?: ReadonlyMap<string, number>\n /**\n * Asks the agent to write an earlier version again as the newest one,\n * where the chat can send a message.\n */\n restore?: (file: ChatFileRestoreTarget) => void\n }>()\n\n const { t: $t } = useI18n({ useScope: 'global' })\n\n const showAll = ref(false)\n\n /**\n * The services cut a long text for the model and give its length\n * (`… (523 characters)`, the marker of every tool result, written by\n * `wordDocument.service.ts` and `spreadsheet.service.ts`): the card keeps\n * the ellipsis only.\n */\n const withoutLength = (text: string | undefined) =>\n text?.replace(/… \\(\\d+ characters\\)$/, '…')\n\n /**\n * A run of unchanged words cut to a few words on the side of each change\n * it touches: the head of the text keeps its end, the tail its start, a\n * run between two changes both, with an ellipsis where words went.\n */\n const contextOf = (text: string, before: boolean, after: boolean) => {\n const runs = text.split(/(\\s+)/).filter(Boolean)\n // Every word is followed by its space: twice as many runs.\n const keep = CONTEXT_WORDS * 2\n if (runs.length <= (before && after ? keep * 2 : keep)) {\n return text\n }\n if (before && after) {\n return `${runs.slice(0, keep).join('')}… ${runs.slice(-keep).join('')}`\n }\n return after\n ? `…${runs.slice(-keep).join('')}`\n : `${runs.slice(0, keep).join('')}…`\n }\n\n /**\n * The words of `before` and `after` that differ, word by word, so the\n * words two changes share between them stay plain. An echoed paragraph\n * is at most a few hundred characters, a few dozen words for the table.\n */\n const excerptOf = (before: string, after: string): Segment[] => {\n const a = before.split(/(\\s+)/).filter(Boolean)\n const b = after.split(/(\\s+)/).filter(Boolean)\n // Longest common subsequence, from the end\n const common = Array.from({ length: a.length + 1 }, () =>\n new Array<number>(b.length + 1).fill(0),\n )\n for (let i = a.length - 1; i >= 0; i--) {\n for (let j = b.length - 1; j >= 0; j--) {\n common[i][j] =\n a[i] === b[j]\n ? common[i + 1][j + 1] + 1\n : Math.max(common[i + 1][j], common[i][j + 1])\n }\n }\n const runs: Segment[] = []\n const push = (text: string, kind: Segment['kind']) => {\n const last = runs[runs.length - 1]\n if (last?.kind === kind) {\n last.text += text\n } else {\n runs.push({ text, kind })\n }\n }\n let i = 0\n let j = 0\n while (i < a.length || j < b.length) {\n if (i < a.length && j < b.length && a[i] === b[j]) {\n push(a[i++], 'same')\n j++\n } else if (\n j >= b.length ||\n (i < a.length && common[i + 1][j] >= common[i][j + 1])\n ) {\n push(a[i++], 'removed')\n } else {\n push(b[j++], 'added')\n }\n }\n return runs.map((run, k) =>\n run.kind === 'same'\n ? {\n ...run,\n text: contextOf(run.text, k > 0, k < runs.length - 1),\n }\n : run,\n )\n }\n\n /** What a Word operation did, as the row says it. */\n const wordChangeLabel = (op: string | undefined) => {\n switch (op) {\n case 'insertParagraphs':\n return $t('messagePart.chatFileParagraphAdded')\n case 'deleteParagraphs':\n return $t('messagePart.chatFileParagraphDeleted')\n case 'insertTableRow':\n return $t('messagePart.chatFileTableRowAdded')\n case 'deleteTableRow':\n return $t('messagePart.chatFileTableRowDeleted')\n case 'acceptRevisions':\n return $t('messagePart.chatFileRevisionAccepted')\n case 'rejectRevisions':\n return $t('messagePart.chatFileRevisionRejected')\n default:\n return $t('messagePart.chatFileParagraphChanged')\n }\n }\n\n /**\n * A paragraph marked as Word marks a revision, struck where words went\n * and underlined where they came. A paragraph only added or only removed\n * is said by its label: the text added stays plain, the text removed\n * stays struck.\n */\n const paragraphRow = (change: ChatFileChange): ParagraphRow => {\n const before = withoutLength(change.before)\n const after = withoutLength(change.after)\n return {\n what: wordChangeLabel(change.op),\n segments:\n before && after\n ? excerptOf(before, after)\n : [\n before\n ? { text: before, kind: 'removed' }\n : { text: after ?? '', kind: 'same' },\n ],\n }\n }\n\n /**\n * A cell as a person reads it: its sheet heads the group of its rows, so\n * the row says `C5` and not Excel's `Listino!C5`, and a row the edit\n * appended says \"Row 10\" and not `A10:F10`.\n */\n const cellRow = (change: ChatFileChange): CellRow => {\n const ref = change.cell ?? ''\n // A new sheet is named alone, with no cell. An edit made before the\n // card read `newSheetRows` said it only in the model's words.\n const legacy = change.before\n ? undefined\n : /^new sheet, (\\d+) row\\(s\\)$/.exec(change.after ?? '')?.[1]\n const rows =\n change.newSheetRows ?? (legacy ? Number(legacy) : undefined)\n if (rows !== undefined) {\n return {\n sheet: ref,\n newSheet: $t('messagePart.chatFileNewSheet', rows),\n }\n }\n\n const bang = ref.lastIndexOf('!')\n const cell = ref.slice(bang + 1)\n const appended = /^A(\\d+):[A-Z]+(\\d+)$/.exec(cell)\n return {\n sheet: ref.slice(0, Math.max(bang, 0)),\n cell:\n appended && appended[1] === appended[2]\n ? $t('messagePart.chatFileRow', { row: appended[1] })\n : cell,\n before: withoutLength(change.before) || undefined,\n after: withoutLength(change.after) || undefined,\n }\n }\n\n const file = computed(() => {\n const part = props.part as {\n type?: string\n state?: string\n output?: Partial<ChatFileOutput>\n }\n if (part.state !== 'output-available' || !part.output?.storedFileName) {\n return undefined\n }\n const output = part.output as ChatFileOutput\n const word = WORD_TOOL_PARTS.has(part.type ?? '')\n // A new file has no count of changes. Each key is written out in its\n // own call: the widget ships only the keys it finds that way.\n let changed: string | undefined\n if (word && output.changedParagraphs !== undefined) {\n changed = output.tracked\n ? $t(\n 'messagePart.editWordDocumentRevisions',\n output.changedParagraphs,\n )\n : $t(\n 'messagePart.editWordDocumentParagraphs',\n output.changedParagraphs,\n )\n } else if (!word && output.changedCells !== undefined) {\n changed = $t(\n 'messagePart.editSpreadsheetCells',\n output.changedCells,\n )\n }\n const changes = changed ? (output.changes ?? []) : []\n const reminders: string[] = []\n if (output.stalePivots) {\n reminders.push($t('messagePart.chatFileRefreshPivots'))\n }\n if (output.staleTableOfContents) {\n reminders.push($t('messagePart.chatFileUpdateTableOfContents'))\n }\n let summary =\n changed && output.version\n ? $t('messagePart.chatFileVersionSummary', {\n version: output.version,\n changed,\n })\n : changed\n if (output.restoredFrom) {\n summary = $t('messagePart.chatFileRestored', {\n version: output.version,\n restored: output.restoredFrom,\n })\n }\n return {\n output,\n mediaType: word ? WORD_MIME_TYPE : SPREADSHEET_MIME_TYPE,\n summary,\n cells: word ? [] : changes.map(cellRow),\n paragraphs: word ? changes.map(paragraphRow) : [],\n count: changes.length,\n more: output.moreChanges ?? 0,\n reminders,\n }\n })\n\n const shown = <T,>(rows: T[] | undefined): T[] =>\n showAll.value ? (rows ?? []) : (rows ?? []).slice(0, SHOWN_CHANGES)\n const shownParagraphs = computed(() => shown(file.value?.paragraphs))\n /** The rows shown, a group per sheet in the order the edit reached it. */\n const shownSheets = computed(() => {\n const groups = new Map<string, SheetGroup>()\n for (const row of shown(file.value?.cells)) {\n const group = groups.get(row.sheet)\n if (group) {\n group.rows.push(row)\n } else {\n groups.set(row.sheet, { sheet: row.sheet, rows: [row] })\n }\n }\n return [...groups.values()]\n })\n const hiddenRows = computed(() => (file.value?.count ?? 0) - SHOWN_CHANGES)\n\n /**\n * The version this card wrote, when a later one of the same file is in\n * the conversation: the one the user can ask to have back.\n */\n const olderVersion = computed(() => {\n const output = file.value?.output\n const latest = output?.fileId\n ? props.latestVersions?.get(output.fileId)\n : undefined\n return output?.fileId &&\n output.version &&\n latest &&\n output.version < latest\n ? {\n fileId: output.fileId,\n version: output.version,\n filename: chatFileName(\n output.filename ?? output.storedFileName,\n output.version,\n ),\n }\n : undefined\n })\n\n /** Asks the agent for this version back. */\n const restoreThis = () => {\n if (olderVersion.value) {\n props.restore?.(olderVersion.value)\n }\n }\n\n /** Opens this version in the chat's viewer. */\n const openPreview = () => {\n const output = file.value?.output\n if (!output || !props.preview) {\n return\n }\n props.preview({\n kind:\n file.value?.mediaType === WORD_MIME_TYPE\n ? 'word'\n : 'spreadsheet',\n storedFileName: output.storedFileName,\n filename: chatFileName(\n output.filename ?? output.storedFileName,\n output.version,\n ),\n version: output.version,\n fileId: output.fileId,\n })\n }\n</script>\n\n<template>\n <div v-if=\"file\" class=\"pk-tool-chat-file\">\n <!-- Restore and open live in the file, beside its download: a\n bordered button under it weighed more than the file and the\n answer it belongs to -->\n <PkChatbotFilePreview\n :media-type=\"file.mediaType\"\n :url=\"fileUrl(file.output.storedFileName)\"\n :filename=\"file.output.filename\"\n :size=\"file.output.sizeBytes\"\n show-download\n :on-preview=\"preview ? openPreview : undefined\"\n :on-restore=\"restore && olderVersion ? restoreThis : undefined\" />\n <section\n v-if=\"file.count || file.output.restoredFrom\"\n class=\"pk-tool-chat-file__changes mt-xs\">\n <h4 class=\"pk-tool-chat-file__summary\">\n {{ file.summary }}\n </h4>\n <div v-if=\"file.count\" class=\"pk-tool-chat-file__scroll\">\n <table\n v-if=\"file.cells.length\"\n class=\"pk-tool-chat-file__table\">\n <thead>\n <tr>\n <th scope=\"col\" class=\"pk-tool-chat-file__cell\">\n {{ $t('messagePart.chatFileCell') }}\n </th>\n <th scope=\"col\">\n {{ $t('messagePart.chatFileBefore') }}\n </th>\n <th scope=\"col\">\n {{ $t('messagePart.chatFileAfter') }}\n </th>\n </tr>\n </thead>\n <tbody v-for=\"(group, g) in shownSheets\" :key=\"g\">\n <tr>\n <th\n colspan=\"3\"\n scope=\"rowgroup\"\n class=\"pk-tool-chat-file__sheet\">\n {{\n $t('messagePart.chatFileSheet', {\n name: group.sheet,\n })\n }}\n </th>\n </tr>\n <tr v-for=\"(row, index) in group.rows\" :key=\"index\">\n <td\n v-if=\"row.newSheet\"\n colspan=\"3\"\n class=\"pk-tool-chat-file__after\">\n {{ row.newSheet }}\n </td>\n <template v-else>\n <td class=\"pk-tool-chat-file__cell\">\n {{ row.cell }}\n </td>\n <td class=\"pk-tool-chat-file__before\">\n {{ row.before }}\n </td>\n <td class=\"pk-tool-chat-file__after\">\n {{ row.after }}\n </td>\n </template>\n </tr>\n </tbody>\n </table>\n <ul v-else class=\"pk-tool-chat-file__paragraphs\">\n <li\n v-for=\"(row, index) in shownParagraphs\"\n :key=\"index\"\n class=\"pk-tool-chat-file__paragraph\">\n <span class=\"pk-tool-chat-file__what\">\n {{ row.what }}\n </span>\n <span class=\"pk-tool-chat-file__text\">\n <template\n v-for=\"(segment, s) in row.segments\"\n :key=\"s\">\n <del\n v-if=\"segment.kind === 'removed'\"\n class=\"pk-tool-chat-file__removed\">\n {{ segment.text }}\n </del>\n <ins\n v-else-if=\"segment.kind === 'added'\"\n class=\"pk-tool-chat-file__added\">\n {{ segment.text }}\n </ins>\n <span v-else>{{ segment.text }}</span>\n </template>\n </span>\n </li>\n </ul>\n <p v-if=\"showAll && file.more\" class=\"pk-tool-chat-file__note\">\n {{ $t('messagePart.chatFileMoreChanges', file.more) }}\n </p>\n </div>\n <button\n v-if=\"hiddenRows > 0\"\n type=\"button\"\n class=\"pk-tool-chat-file__more\"\n :aria-expanded=\"showAll\"\n @click=\"showAll = !showAll\">\n <VvIcon\n :name=\"\n showAll ? 'ri:arrow-up-s-line' : 'ri:arrow-down-s-line'\n \"\n class=\"text-16\"\n aria-hidden=\"true\" />\n {{\n showAll\n ? $t('action.showLess')\n : $t('action.showMore', { count: hiddenRows })\n }}\n </button>\n <p\n v-for=\"reminder in file.reminders\"\n :key=\"reminder\"\n class=\"pk-tool-chat-file__reminder\">\n <VvIcon\n name=\"ri:information-line\"\n class=\"pk-tool-chat-file__reminder-icon\"\n aria-hidden=\"true\" />\n {{ reminder }}\n </p>\n </section>\n <p v-else-if=\"file.summary\" class=\"text-12 text-word-3 mt-xs mb-0\">\n {{ file.summary }}\n </p>\n </div>\n</template>\n\n<style lang=\"scss\">\n // One frame (DESIGN.md, principle 4): a hairline at surface-3, rounded-lg,\n // a solid ground over the dots of the chat, as wide as a short paragraph\n // while the file above keeps its 280px. Inside it every divider is one\n // hairline at surface-2.\n .pk-tool-chat-file__changes {\n max-width: 36rem;\n overflow: hidden;\n border: var(--border) solid var(--color-surface-3);\n border-radius: var(--rounded-lg);\n background-color: var(--color-surface);\n font-size: var(--text-12);\n }\n\n .pk-tool-chat-file__summary {\n margin: 0;\n padding: var(--spacing-8) var(--spacing-12);\n border-bottom: var(--border) solid var(--color-surface-3);\n color: var(--color-word-2);\n font-size: var(--text-12);\n font-weight: var(--font-medium);\n\n // A restore says only what it wrote back\n &:last-child {\n border-bottom: 0;\n }\n }\n\n // Bounded, so fifty changes scroll inside the frame\n .pk-tool-chat-file__scroll {\n max-height: 20rem;\n overflow-y: auto;\n }\n\n .pk-tool-chat-file__table {\n width: 100%;\n border-collapse: collapse;\n\n th,\n td {\n padding: var(--spacing-8) var(--spacing-12);\n border-bottom: var(--border) solid var(--color-surface-2);\n text-align: start;\n vertical-align: top;\n overflow-wrap: anywhere;\n }\n\n // Told apart by its weight and colour, no heavier rule\n th {\n color: var(--color-word-3);\n font-weight: var(--font-medium);\n }\n\n tbody:last-child tr:last-child td {\n border-bottom: 0;\n }\n }\n\n // The name of a sheet heads its rows, one step of surface under it\n .pk-tool-chat-file__table .pk-tool-chat-file__sheet {\n padding-block: var(--spacing-6);\n background-color: var(--color-surface-1);\n color: var(--color-word-2);\n }\n\n .pk-tool-chat-file__cell {\n width: 1%;\n color: var(--color-word-2);\n font-variant-numeric: tabular-nums;\n white-space: nowrap;\n }\n\n .pk-tool-chat-file__before {\n width: 50%;\n color: var(--color-word-3);\n }\n\n .pk-tool-chat-file__after {\n width: 50%;\n color: var(--color-word-1);\n }\n\n .pk-tool-chat-file__paragraphs {\n margin: 0;\n padding: 0;\n list-style: none;\n }\n\n .pk-tool-chat-file__paragraph {\n display: grid;\n grid-template-columns: minmax(4rem, max-content) 1fr;\n gap: var(--spacing-4) var(--spacing-md);\n padding: var(--spacing-8) var(--spacing-12);\n border-bottom: var(--border) solid var(--color-surface-2);\n\n &:last-child {\n border-bottom: 0;\n }\n }\n\n .pk-tool-chat-file__what {\n color: var(--color-word-3);\n white-space: nowrap;\n }\n\n .pk-tool-chat-file__text {\n min-width: 0;\n color: var(--color-word-2);\n overflow-wrap: anywhere;\n }\n\n // Marked as Word marks a revision, struck where words went and\n // underlined where they came, in the red and green of a comparison: the\n // change is what the row exists to report, the verdict exception of\n // DESIGN.md (principle 2). The readable text tokens hold the contrast in\n // both themes. The base styles take the line off `del`.\n .pk-tool-chat-file__removed {\n color: var(--u-danger-text);\n text-decoration: line-through;\n }\n\n .pk-tool-chat-file__added {\n color: var(--u-success-text);\n font-weight: var(--font-medium);\n text-decoration: underline;\n text-underline-offset: 0.2em;\n }\n\n .pk-tool-chat-file__removed + .pk-tool-chat-file__added {\n margin-inline-start: var(--spacing-4);\n }\n\n .pk-tool-chat-file__note {\n margin: 0;\n padding: var(--spacing-8) var(--spacing-12);\n border-top: var(--border) solid var(--color-surface-2);\n color: var(--color-word-3);\n }\n\n .pk-tool-chat-file__more {\n display: flex;\n align-items: center;\n justify-content: center;\n gap: var(--spacing-4);\n width: 100%;\n padding: var(--spacing-8) var(--spacing-12);\n border: 0;\n border-top: var(--border) solid var(--color-surface-2);\n background: none;\n color: var(--color-word-2);\n font: inherit;\n cursor: pointer;\n transition: background-color var(--duration-150) var(--ease-out);\n\n &:hover {\n background-color: var(--color-surface-1);\n }\n\n &:focus-visible {\n outline: var(--spacing-2) solid var(--input-focus-color);\n outline-offset: calc(var(--spacing-2) * -1);\n }\n }\n\n .pk-tool-chat-file__reminder {\n display: flex;\n align-items: flex-start;\n gap: var(--spacing-8);\n margin: 0;\n padding: var(--spacing-8) var(--spacing-12);\n border-top: var(--border) solid var(--color-surface-2);\n color: var(--color-word-2);\n }\n\n .pk-tool-chat-file__reminder-icon {\n flex-shrink: 0;\n margin-top: var(--spacing-2);\n color: var(--color-word-3);\n font-size: var(--text-14);\n }\n</style>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;A,GAuEUwC,IAAgB,G;;;;;;;;;;EANtB,IAAME,oBAAkB,IAAI,IAAI,CAC5B,yBACA,yBACJ,CAAC,GAgBKC,IAAQC,GAeR,EAAE,GAAGC,MAAOC,EAAQ,EAAE,UAAU,SAAS,CAAC,GAE1CC,IAAUC,EAAI,EAAK,GAQnBC,KAAiB,MACnBC,GAAM,QAAQ,yBAAyB,GAAG,GAOxCC,KAAa,GAAc,GAAiB,MAAmB;GACjE,IAAMC,IAAOF,EAAK,MAAM,OAAO,CAAC,CAAC,OAAO,OAAO;GAS/C,OANIE,EAAK,WAAWC,KAAUC,IAAQ,KAAW,MACtCJ,IAEPG,KAAUC,IACH,GAAGF,EAAK,MAAM,GAAG,EAAI,CAAC,CAAC,KAAK,EAAE,EAAE,IAAIA,EAAK,MAAM,GAAK,CAAC,CAAC,KAAK,EAAE,MAEjEE,IACD,IAAIF,EAAK,MAAM,GAAK,CAAC,CAAC,KAAK,EAAE,MAC7B,GAAGA,EAAK,MAAM,GAAG,EAAI,CAAC,CAAC,KAAK,EAAE,EAAE;EAC1C,GAOMG,KAAa,GAAgB,MAA6B;GAC5D,IAAMC,IAAIH,EAAO,MAAM,OAAO,CAAC,CAAC,OAAO,OAAO,GACxCI,IAAIH,EAAM,MAAM,OAAO,CAAC,CAAC,OAAO,OAAO,GAEvCI,IAAS,MAAM,KAAK,EAAE,QAAQF,EAAE,SAAS,EAAE,SACzC,MAAcC,EAAE,SAAS,CAAC,CAAC,CAAC,K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KAGvC,OAAM;KACN,eAAY;I,uBAASpC,EAAA,MACzBL,EACIyC,EAAA,QAAkCxC,EAAAsC,CAAA,CAAE,CAAA,iBAAA,IAA8CtC,EAAAsC,CAAA,CAAE,CAAA,mBAAA,EAAA,OAA6B8C,EAAA,MAAU,CAAA,CAAA,GAAA,CAAA,C;KAKnI1F,EAAA,EAAA,GAAAC,EASIM,GAAA,MAAAC,EARmBmE,EAAA,MAAK,YAAjB,OADX3E,EAAA,GAAAC,EASI,KAAA;KAPC,KAAK+G;KACN,OAAM;I,IACN9G,EAGyB6F,GAAA;KAFrB,MAAK;KACL,OAAM;KACN,eAAY;I,IAASrF,EAAA,MACzBL,EAAG2G,CAAQ,GAAA,CAAA,C;G,MAGLrC,EAAA,MAAK,WAAnB3E,EAAA,GAAAC,EAEI,KAFJqC,GAEIjC,EADGsE,EAAA,MAAK,OAAO,GAAA,CAAA,K"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils-BuxgMuKv.js","names":["SUBAGENT_TOOL_PREFIX","MCP_TOOL_PREFIX","isHostToolPart","WEB_SEARCH_TOOL_KEYS","API_TOOL_PREFIX","isPresentationTool","isReasoningPart","getToolPartName","isTextPart","isToolPart","removeAccents","str","fromAnyCase","toKebabCase","toSnakeCase","capitalizeFirstLetter","mergeConsecutiveTextParts","merged","part","parts","prev","isWidgetPart","dropCorrectedWidgetErrors","lastDrawn","index","isStreamingPart","FILE_OUTPUT_PARTS","moveFileOutputsLast","files","feedPartKey","toolCallId","getHostCallPart","PAGE_TOOL_STEPS","HOST_STEP_TITLES","FORM_TOOL_STEP","pageToolStep","host","isHostActionPart","LIVE_REASONING_TAIL_LENGTH","FENCE_LINE","getMarkdownTail","markdown","maxLength","from","limit","boundary","length","cut","openFence","match","marker","rest","TOOL_APPROVAL_STATES","isToolApprovalPart","CONFIRM_TOOL_NAME","isToolConfirmPart","isConfirmationCardPart","getToolApprovalId","getPartState","isLoadingState","state","getContrast","hex","hexcolor","char","r","g","b","linearize","c","isAchromaticColor","channels","at","channelsToHex","value","readCssColor","expression","computed","probe","srgb","rgb","resolveGlowTints","readGlowTints","source","mainColor","sourceHex","neutral","middle","color","hueShift","first","second","secondColor","tones","resolveContrastColor","textColor","agentThemeStyle","contrastColor","formatDuration","ms","$n","stringifyPayload","json","hasPayload","formAnswerAsSpoken","input","answer","question","questionById","step","said","id","formStepOptions","option","formAnswerSlots","slots","output","steps","assign","list","WEB_SEARCH_TOOL_TYPES","key","RICH_DETAIL_TOOL_TYPES","hasRichToolDetail","asRecord","pickString","keys","record","getToolPartSummary","queries","valid","query","sheet","range","getPartIcon","TOOL_KEY_PREFIXES","toolLabel","te","name","prefix","p","PART_TYPE_LABELS","t","getPartTypeLabel","translator","label","PROVIDER_NAMES","providerLabel","slug","localizeSummaryLabels","summary","labels","colon","getToolPartLabel","live","hostStepTitles","page","$t","WORD_FONT_STACKS","WORD_LINE_FACTORS","wordLineFactor","font","wordFontStack","WORD_PREVIEW_IMAGES","wordPictureSrc","src","images","ref","wordPageAnchorCss","anchor","picture","wordPicturePlacement","wordKeptRuns","runs","mode","hasWordText","wordFlowItems","out","breakPending","sectionPending","push","opens","section","row","breakBefore","skip","blocks","block","breaks","cell","cells","wordPageAnchors","run","chatFileName","version","filename"],"sources":["../../../../packages/utils/src/text.ts","../../../../packages/components/src/chat/utils.ts"],"sourcesContent":["export const removeAccents = (str: string) =>\n str.normalize('NFD').replace(/[\\u0300-\\u036f]/g, '')\n\nexport const toCamelCase = <T extends string>(str?: string): T => {\n if (!str) {\n return '' as unknown as T\n }\n return removeAccents(str)\n .replace(/[^a-zA-Z0-9]+(.)?/g, (_, c) => (c ? c.toUpperCase() : ''))\n .replace(/^(.)/, (match) => match.toLowerCase()) as unknown as T\n}\n\nexport const fromCamelCase = (str?: string): string => {\n if (!str) {\n return ''\n }\n return str.replace(/([a-z0-9])([A-Z])/g, '$1 $2')\n}\n\nexport const fromAnyCase = (str?: string): string => {\n if (!str) {\n return ''\n }\n return str\n .replace(/([a-z0-9])([A-Z])/g, '$1 $2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')\n .replace(/[-_]+/g, ' ')\n}\n\nexport const toPascalCase = <T extends string>(str?: string): T => {\n if (!str) {\n return '' as unknown as T\n }\n return removeAccents(str)\n .replace(/[^a-zA-Z0-9]+(.)?/g, (_, c) => (c ? c.toUpperCase() : ''))\n .replace(/^(.)/, (match) => match.toUpperCase()) as unknown as T\n}\n\nexport const toKebabCase = <T extends string>(str?: string): T => {\n if (!str) {\n return '' as unknown as T\n }\n return removeAccents(str)\n .replace(/([a-z0-9])([A-Z])/g, '$1-$2')\n .replace(/[^a-zA-Z0-9]+/g, '-')\n .toLowerCase() as unknown as T\n}\n\nexport const fromKebabCase = (str?: string): string => {\n if (!str) {\n return ''\n }\n return str.replace(/-/g, ' ')\n}\n\nexport const toSnakeCase = <T extends string>(str?: string): T => {\n if (!str) {\n return '' as unknown as T\n }\n return removeAccents(str)\n .replace(/([a-z0-9])([A-Z])/g, '$1_$2')\n .replace(/[^a-zA-Z0-9]+/g, '_')\n .toLowerCase() as unknown as T\n}\n\nexport const capitalizeFirstLetter = (str?: string) => {\n if (!str) {\n return ''\n }\n return str.charAt(0).toUpperCase() + str.slice(1)\n}\n\nexport const lowercaseFirstLetter = (str?: string) => {\n if (!str) {\n return ''\n }\n return str.charAt(0).toLowerCase() + str.slice(1)\n}\n","import type { UIMessage } from 'ai'\nimport type { CSSProperties, InjectionKey, Ref } from 'vue'\nimport {\n API_TOOL_PREFIX,\n MCP_TOOL_PREFIX,\n SUBAGENT_TOOL_PREFIX,\n WEB_SEARCH_TOOL_KEYS,\n isHostToolPart,\n isPresentationTool,\n type WordPreviewBlock,\n type WordPreviewPage,\n type WordPreviewPicture,\n type WordPreviewRun,\n} from 'models'\nimport {\n isTextPart,\n isFilePart,\n isToolPart,\n isReasoningPart,\n hasPartText,\n hasTextPart,\n getTextPart,\n getMessageText,\n getToolPartName,\n capitalizeFirstLetter,\n fromAnyCase,\n} from 'utils'\n\nexport {\n isTextPart,\n isFilePart,\n isToolPart,\n isReasoningPart,\n hasPartText,\n hasTextPart,\n getTextPart,\n getMessageText,\n}\n\n/**\n * Merges consecutive text parts into a single text part.\n * Claude (and other models) often produce multiple text parts during streaming\n * that should logically be a single block of text.\n */\nexport function mergeConsecutiveTextParts(\n parts: UIMessage['parts'],\n): UIMessage['parts'] {\n const merged: UIMessage['parts'] = []\n for (const part of parts) {\n if (!isTextPart(part)) {\n merged.push(part)\n continue\n }\n const prev = merged[merged.length - 1]\n if (prev && isTextPart(prev)) {\n merged[merged.length - 1] = { ...prev, text: prev.text + part.text }\n } else {\n merged.push(part)\n }\n }\n return merged\n}\n\nconst isWidgetPart = (\n part: UIMessage['parts'][number],\n): part is Extract<UIMessage['parts'][number], { type: `tool-${string}` }> =>\n isToolPart(part) && isPresentationTool(getToolPartName(part))\n\n/**\n * Drops a widget call refused for its arguments when a later call of the same\n * widget in the message was drawn: the turn corrected it (the backend's\n * `correctableInputRefusals`), and the refusal would sit next to the working\n * widget, `showForm` drawing its render error above the form. A refusal with\n * nothing drawn after it stays. Only the feed reads this: the steps timeline\n * keeps every call, the refused one included.\n */\nexport function dropCorrectedWidgetErrors(\n parts: UIMessage['parts'],\n): UIMessage['parts'] {\n const lastDrawn = new Map<string, number>()\n for (const [index, part] of parts.entries()) {\n if (\n isWidgetPart(part) &&\n part.state !== 'output-error' &&\n !isStreamingPart(part)\n ) {\n lastDrawn.set(part.type, index)\n }\n }\n return parts.filter(\n (part, index) =>\n !(\n isWidgetPart(part) &&\n part.state === 'output-error' &&\n (lastDrawn.get(part.type) ?? -1) > index\n ),\n )\n}\n\n/**\n * Tool calls whose output is a file for the user to download. The feed draws\n * them after the answer, where the reader arrives, wherever in the message the\n * model made the call: a version written before a long answer sat above it,\n * out of sight.\n */\nconst FILE_OUTPUT_PARTS: ReadonlySet<string> = new Set([\n 'tool-editSpreadsheet',\n 'tool-shareDocument',\n 'tool-editWordDocument',\n 'tool-createSpreadsheet',\n 'tool-createWordDocument',\n])\n\n/** The parts with the file outputs moved last, in their own order. */\nexport function moveFileOutputsLast(\n parts: UIMessage['parts'],\n): UIMessage['parts'] {\n const files = parts.filter((part) => FILE_OUTPUT_PARTS.has(part.type))\n return files.length > 0\n ? [\n ...parts.filter((part) => !FILE_OUTPUT_PARTS.has(part.type)),\n ...files,\n ]\n : parts\n}\n\n/**\n * The key of a part in the feed. Its position, except for a file output: that\n * one is always last, so its position moves as the answer grows, and keyed by\n * it the card would be redrawn at every new part.\n */\nexport function feedPartKey(\n part: UIMessage['parts'][number],\n index: number,\n): string | number {\n const toolCallId = (part as { toolCallId?: string }).toolCallId\n return FILE_OUTPUT_PARTS.has(part.type) && toolCallId\n ? `file-${toolCallId}`\n : index\n}\n\n/** A call the embedding page runs, as the backend stamped it (spec `host-tools.md`). */\ninterface HostCallPart {\n toolCallId?: string\n toolName: string\n title?: string\n state?: string\n errorText?: string\n toolMetadata?: { readOnly?: boolean; provider?: 'app' | 'page' }\n}\n\nexport function getHostCallPart(\n part: UIMessage['parts'][number] | null | undefined,\n): HostCallPart | undefined {\n return isHostToolPart(part) ? (part as unknown as HostCallPart) : undefined\n}\n\n/**\n * The page tools of the widget (spec `page-tools.md`): defined by the backend,\n * so their step is ours to name, in the user's language. A tool the app\n * registered is named by its own `title`.\n */\nconst PAGE_TOOL_STEPS: Record<string, { icon: string; label: string }> = {\n page_snapshot: {\n icon: 'ri:pages-line',\n label: 'messagePart.pageTool.snapshot',\n },\n page_read: {\n icon: 'ri:file-text-line',\n label: 'messagePart.pageTool.read',\n },\n page_click: { icon: 'ri:cursor-line', label: 'messagePart.pageTool.click' },\n page_fill: { icon: 'ri:edit-line', label: 'messagePart.pageTool.fill' },\n page_scroll: {\n icon: 'ri:arrow-up-down-line',\n label: 'messagePart.pageTool.scroll',\n },\n page_find: { icon: 'ri:search-line', label: 'messagePart.pageTool.find' },\n page_wait: { icon: 'ri:time-line', label: 'messagePart.pageTool.wait' },\n page_hover: {\n icon: 'ri:cursor-line',\n label: 'messagePart.pageTool.hover',\n },\n page_press: {\n icon: 'ri:keyboard-line',\n label: 'messagePart.pageTool.press',\n },\n page_back: {\n icon: 'ri:arrow-go-back-line',\n label: 'messagePart.pageTool.back',\n },\n page_navigate: {\n icon: 'ri:links-line',\n label: 'messagePart.pageTool.navigate',\n },\n}\n\n/**\n * The titles the widget gave this page's steps, by call, naming what each\n * acts on (spec `page-tools-improvements.md`, M8): provided by the chat view\n * from its store, read by the views that list the steps.\n */\nexport const HOST_STEP_TITLES: InjectionKey<Ref<Record<string, string>>> =\n Symbol('hostStepTitles')\n\n/** A form the site annotated for agents: its tool is named `form_<toolname>`. */\nconst FORM_TOOL_STEP = {\n icon: 'ri:survey-line',\n label: 'messagePart.pageTool.form',\n}\n\nconst pageToolStep = (host: HostCallPart) =>\n host.toolMetadata?.provider === 'page'\n ? (PAGE_TOOL_STEPS[host.toolName] ??\n (host.toolName.startsWith('form_') ? FORM_TOOL_STEP : undefined))\n : undefined\n\n/**\n * A host call that changes something in the app or on the page: the feed\n * shows it even without the steps timeline, because what it did stays done.\n */\nexport function isHostActionPart(\n part: UIMessage['parts'][number] | null | undefined,\n): boolean {\n return getHostCallPart(part)?.toolMetadata?.readOnly === false\n}\n\nexport function isStreamingPart(\n part: UIMessage['parts'][number] | null | undefined,\n): part is Extract<UIMessage['parts'][number], { streaming?: boolean }> {\n if (!part) {\n return false\n }\n if ('state' in part) {\n return part.state === 'streaming' || part.state === 'input-streaming'\n }\n return false\n}\n\n/**\n * How much of a reasoning still being written its live box renders. The box is\n * a few lines tall and follows the bottom, while the reasoning of one turn runs\n * to tens of kilobytes: chat `st0Eg8iG0zUX0HQN` wrote 92KB, and parsing all of\n * it at every delta froze the tab. Four thousand characters leave a few screens\n * to scroll back through, and a finished step renders all of it.\n */\nexport const LIVE_REASONING_TAIL_LENGTH = 4000\n\n// A fence opener or closer, also inside a list item or a quote, whose markers\n// and indentation are skipped. The rest of the line tells them apart: a\n// closing fence carries no info string.\nconst FENCE_LINE =\n /^[ \\t]*(?:(?:[-*+]|\\d{1,9}[.)])[ \\t]+|>[ \\t]?)*(`{3,}|~{3,})(.*)$/gm\n\n/**\n * The end of a markdown text, at most `maxLength` characters long, cut on a\n * blank line (a line break when there is none) so it does not open on half a\n * paragraph. A table or a formula can still be cut in two. An ellipsis marks\n * the cut. A cut inside a fenced code block reopens the fence, or the rest of\n * the text would render as code and the code as prose.\n */\nexport function getMarkdownTail(markdown: string, maxLength: number): string {\n if (markdown.length <= maxLength) {\n return markdown\n }\n const from = markdown.length - maxLength\n // The boundary is looked for in the first half of the window only: the one\n // blank line of the window can be the last thing written, and cutting there\n // would leave nothing to render.\n const limit = from + maxLength / 2\n const boundary = (index: number, length: number) =>\n index !== -1 && index < limit ? index + length : undefined\n const cut =\n boundary(markdown.indexOf('\\n\\n', from), 2) ??\n boundary(markdown.indexOf('\\n', from), 1) ??\n from\n let openFence: string | undefined\n for (const match of markdown.matchAll(FENCE_LINE)) {\n if (match.index >= cut) {\n break\n }\n const [, marker, rest] = match\n if (!openFence) {\n // A backtick in a backtick fence's info string makes it inline\n // code, not a fence.\n if (marker[0] === '`' && rest.includes('`')) {\n continue\n }\n openFence = marker\n } else if (\n marker[0] === openFence[0] &&\n marker.length >= openFence.length &&\n !rest.trim()\n ) {\n openFence = undefined\n }\n }\n const reopen = openFence ? `${openFence}\\n` : ''\n return `…\\n\\n${reopen}${markdown.slice(cut)}`\n}\n\n/**\n * States a tool part goes through when it needs the user's approval. They are\n * rendered by `PkToolApprovalCard` whatever the tool is, so the decision (and\n * its outcome) stays visible in the transcript.\n */\nconst TOOL_APPROVAL_STATES = new Set([\n 'approval-requested',\n 'approval-responded',\n 'output-denied',\n])\n\nexport function isToolApprovalPart(\n part: UIMessage['parts'][number] | null | undefined,\n): boolean {\n if (!isToolPart(part)) {\n return false\n }\n if (TOOL_APPROVAL_STATES.has(part.state)) {\n return true\n }\n // An executed (or errored) call that went through the gate keeps its\n // verdict in `approval`: the card stays in the transcript, so the user's\n // decision remains visible in the chat and in the log viewers (parity\n // with requestConfirm, whose 'confirmed' output is persisted).\n return (part as { approval?: unknown }).approval != null\n}\n\n/**\n * The client-side tool the model uses to have an action it described approved.\n * It predates the SDK's approval gate and keeps its own round-trip (it resolves\n * through `addToolOutput`), but it asks the user the very same question, so it\n * shares `PkToolApprovalCard` instead of having a card of its own.\n */\nexport const CONFIRM_TOOL_NAME = 'requestConfirm'\n\nexport function isToolConfirmPart(\n part: UIMessage['parts'][number] | null | undefined,\n): boolean {\n return isToolPart(part) && part.type === `tool-${CONFIRM_TOOL_NAME}`\n}\n\n/** True for any part the confirmation card is responsible for. */\nexport function isConfirmationCardPart(\n part: UIMessage['parts'][number] | null | undefined,\n): boolean {\n return isToolApprovalPart(part) || isToolConfirmPart(part)\n}\n\n/** The id of the pending approval request on a tool part, if any. */\nexport function getToolApprovalId(\n part: UIMessage['parts'][number] | null | undefined,\n): string | undefined {\n if (!isToolPart(part)) {\n return undefined\n }\n return (part as { approval?: { id?: string } }).approval?.id\n}\n\nexport function getPartState(\n part: UIMessage['parts'][number] | null | undefined,\n): string | undefined {\n if (!part) {\n return undefined\n }\n if ('state' in part) {\n return part.state\n }\n return undefined\n}\n\nexport function isLoadingState(state?: string): boolean {\n if (!state) {\n return false\n }\n return ['streaming'].includes(state)\n}\n\nexport function getContrast(hexcolor: string = '000000'): 'black' | 'white' {\n let hex = hexcolor.replace('#', '')\n\n // Expand 3-character hex to 6-character (e.g., #ccc -> #cccccc)\n if (hex.length === 3) {\n hex = hex\n .split('')\n .map((char) => char + char)\n .join('')\n }\n\n // WCAG relative luminance\n const r = parseInt(hex.substring(0, 2), 16) / 255\n const g = parseInt(hex.substring(2, 4), 16) / 255\n const b = parseInt(hex.substring(4, 6), 16) / 255\n\n const linearize = (c: number) =>\n c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4\n\n const luminance =\n 0.2126 * linearize(r) + 0.7152 * linearize(g) + 0.0722 * linearize(b)\n\n return luminance > 0.179 ? 'black' : 'white'\n}\n\n/**\n * True for a hex color with almost no hue: black, white and the grays between.\n * Anything else, a color the function cannot read included, counts as colored.\n */\nexport function isAchromaticColor(hexcolor: string | undefined): boolean {\n let hex = hexcolor?.trim().replace('#', '') ?? ''\n if (/^[0-9a-f]{3}$/i.test(hex)) {\n hex = hex\n .split('')\n .map((char) => char + char)\n .join('')\n }\n if (!/^[0-9a-f]{6}$/i.test(hex)) {\n return false\n }\n const channels = [0, 2, 4].map((at) =>\n parseInt(hex.substring(at, at + 2), 16),\n )\n return Math.max(...channels) - Math.min(...channels) < 32\n}\n\n/** A color as the glow's shader takes it: three channels, 0-255. */\nexport type RgbChannels = [number, number, number]\n\n/** The two tints of the empty chat's glow, and whether the second shows. */\nexport type GlowTints = {\n first: RgbChannels\n second: RgbChannels\n duo: boolean\n}\n\n/** `#rrggbb` from three 0-255 channels. */\nexport const channelsToHex = (channels: RgbChannels) =>\n `#${channels.map((value) => value.toString(16).padStart(2, '0')).join('')}`\n\n/**\n * The color a CSS expression resolves to where `probe` sits. Mixed into sRGB\n * first, it computes to `color(srgb r g b)` whatever syntax it was written in\n * (the design system's tokens derive with the relative color syntax). A\n * browser without `color-mix()` would drop the mix and leave the inherited\n * color for every expression: it reads the bare one, which computes to `rgb()`.\n */\nfunction readCssColor(\n probe: HTMLElement,\n expression: string,\n): RgbChannels | null {\n probe.style.color = CSS.supports(\n 'color',\n 'color-mix(in srgb, red 100%, transparent)',\n )\n ? `color-mix(in srgb, ${expression} 100%, transparent)`\n : expression\n const computed = getComputedStyle(probe).color\n probe.style.color = ''\n const srgb = computed.match(/^color\\(srgb ([^\\s)]+) ([^\\s)]+) ([^\\s)]+)/)\n const rgb = computed.match(/rgba?\\(([\\d.]+)[,\\s]+([\\d.]+)[,\\s]+([\\d.]+)/)\n if (srgb) {\n return [srgb[1], srgb[2], srgb[3]].map((value) =>\n Math.round(Math.min(1, Math.max(0, Number(value))) * 255),\n ) as RgbChannels\n }\n if (rgb) {\n return [rgb[1], rgb[2], rgb[3]].map((value) =>\n Math.round(Number(value)),\n ) as RgbChannels\n }\n return null\n}\n\n/**\n * The two tints of the glow behind the empty chat's input. A color without a\n * hue (black, the default, white, a gray) drew a grey smudge on the light\n * theme and nothing on the dark one: the platform's accent lights it instead,\n * with its info color as the second tone, as the working beam does. Any other\n * color gives its neighbour 40° along the hue wheel as the second tone,\n * unless the agent chose one. Every tone is held to a middle lightness, like\n * the beam's, so a chosen second color that matches the one shown keeps the\n * glow as it was. `auto` shows the second tone only for a color without a hue.\n *\n * The colors resolve where `host` sits (its tokens, its theme); without\n * `mainColor` the glow starts from the host's own color. Null when the\n * browser cannot read them.\n */\nexport function resolveGlowTints(\n host: HTMLElement,\n {\n mainColor,\n tones = 'auto',\n secondColor,\n }: {\n mainColor?: string\n tones?: 'auto' | 'one' | 'two'\n secondColor?: string\n },\n): GlowTints | null {\n // A throwaway child inherits the host's color and custom properties, and\n // reading through it leaves the host's own style alone\n const probe = document.createElement('span')\n probe.hidden = true\n host.append(probe)\n try {\n return readGlowTints(probe, { mainColor, tones, secondColor })\n } finally {\n probe.remove()\n }\n}\n\nfunction readGlowTints(\n probe: HTMLElement,\n {\n mainColor,\n tones,\n secondColor,\n }: {\n mainColor?: string\n tones: 'auto' | 'one' | 'two'\n secondColor?: string\n },\n): GlowTints | null {\n const source = readCssColor(probe, mainColor ?? 'currentcolor')\n if (!source) {\n return null\n }\n const sourceHex = channelsToHex(source)\n const neutral = isAchromaticColor(sourceHex)\n // Where the browser can derive it; the color as it is otherwise\n const middle = (color: string, hueShift = 0) =>\n CSS.supports('color', 'oklch(from red l c h)')\n ? `oklch(from ${color} clamp(0.55, l, 0.75) c calc(h + ${hueShift}))`\n : color\n const first = readCssColor(\n probe,\n middle(neutral ? 'var(--color-accent)' : sourceHex),\n )\n const second = readCssColor(\n probe,\n secondColor\n ? middle(secondColor)\n : neutral\n ? middle('var(--color-info)')\n : middle(sourceHex, 40),\n )\n if (!first || !second) {\n return null\n }\n return {\n first,\n second,\n duo: tones === 'two' || (tones === 'auto' && neutral),\n }\n}\n\n/**\n * Resolves the contrast color based on the user's `textColor` preference.\n * Falls back to WCAG auto-detection via `getContrast` when set to `'auto'` or `undefined`.\n */\nexport function resolveContrastColor(\n textColor: 'auto' | 'white' | 'black' | undefined,\n mainColor: string | undefined,\n): 'black' | 'white' {\n if (textColor === 'white' || textColor === 'black') {\n return textColor\n }\n return getContrast(mainColor)\n}\n\n/**\n * The style of a chat root (PkChatbot, the widget's shell): the agent's color\n * as the brand. Volver derives every role of the brand (graphic, readable,\n * contrast, tinted surface) on any element with `.theme`, which both roots\n * carry, so the focus ring, the primary buttons, the links and the checkboxes\n * take the agent's color with the contrast each theme needs, instead of the\n * platform's purple. The fields' focus takes the brand's graphic role in both\n * themes, since the dark theme's accent is the platform's too.\n */\nexport function agentThemeStyle(\n mainColor: string | undefined,\n contrastColor: 'black' | 'white',\n): Record<string, string> | undefined {\n if (!mainColor) {\n return undefined\n }\n return {\n '--chatbot-main-color': mainColor,\n '--chatbot-contrast-color': contrastColor,\n '--color-brand': mainColor,\n '--color-brand-contrast': contrastColor,\n '--input-focus-color': 'var(--color-brand-graphic)',\n }\n}\n\n/**\n * Formats a duration in milliseconds using the i18n `seconds` number format\n * (e.g. \"12,4 secondi\" / \"12.4 seconds\"). Returns undefined for durations\n * that would render as \"0 seconds\" (less than 0.05s).\n */\nexport function formatDuration(\n $n: (value: number, format: string) => string,\n ms?: number,\n): string | undefined {\n if (ms === undefined || ms < 50) {\n return undefined\n }\n return $n(ms / 1000, 'seconds')\n}\n\n/**\n * Stringifies a tool payload for the raw fallback view. Returns undefined for\n * empty values so the caller can skip rendering the block entirely.\n */\nexport function stringifyPayload(value: unknown): string | undefined {\n if (value === undefined) {\n return undefined\n }\n if (typeof value === 'string') {\n return value.trim() || undefined\n }\n try {\n const json = JSON.stringify(value, null, 2)\n return json === '{}' || json === '[]' ? undefined : json\n } catch {\n return undefined\n }\n}\n\n/**\n * True when a tool payload carries something worth rendering, so a caller can\n * skip the block without stringifying the value twice.\n */\nexport function hasPayload(value: unknown): boolean {\n return stringifyPayload(value) !== undefined\n}\n\n/**\n * Turns the answers of a form into the sentence the caller would have said.\n *\n * On a call the tool loop is over by the time the form is on screen, so the\n * answers go back to the agent as a user message (see `sendUserMessage` in\n * `useVoiceSession`). Each answer is paired with its question, because that is\n * how a person would say it and because the agent hears it with no widget\n * attached.\n */\nexport function formAnswerAsSpoken(\n part: unknown,\n answer: string | { answers: { id: string; value: unknown }[] },\n): string {\n const input = (\n part as {\n input?: {\n steps?: { id: string; question?: string }[]\n question?: string\n }\n }\n )?.input\n\n if (typeof answer === 'string') {\n const question = input?.question ?? input?.steps?.[0]?.question\n return question ? `${question} ${answer}` : answer\n }\n\n const questionById = new Map(\n (input?.steps ?? []).map((step) => [step.id, step.question]),\n )\n const lines = answer.answers\n .filter(\n ({ value }) =>\n value !== null &&\n value !== '' &&\n !(Array.isArray(value) && !value.length),\n )\n .map(({ id, value }) => {\n const said = Array.isArray(value) ? value.join(', ') : String(value)\n const question = questionById.get(id)\n return question ? `${question} ${said}` : said\n })\n\n return lines.join('. ')\n}\n\n/**\n * The choices of a form step, as the radio and checkbox editors take them.\n *\n * The `value` is the LABEL and not the position, because it is what travels\n * back to the model as the answer: it reads the words it wrote, not an index.\n * Nothing here caps the list, and nothing should: the number of options an\n * agent configures is advice to the model, so a step can legitimately carry\n * more (see `showForm.tool.ts`).\n */\nexport function formStepOptions(\n step: { options?: { label: string; description?: string }[] } | undefined,\n): { label: string; value: string; description?: string }[] {\n if (!step?.options) {\n return []\n }\n return step.options.map((option) => ({\n label: option.label,\n value: option.label,\n description: option.description,\n }))\n}\n\n/**\n * Spreads the answers a form comes back with onto one slot PER STEP.\n *\n * A form's answers travel paired with step ids, and the tool schema does not\n * enforce that those ids are unique: a `.refine()` there would refuse the whole\n * form over a duplicate, which is the failure the schema was just cured of (see\n * the gotchas entry \"A configurable cap does not belong in an inputSchema\").\n * So the duplicate has to be survivable here. Keyed by id, two steps sharing\n * one collapsed onto a single answer: the second question showed the first\n * one's reply, and submitting sent that reply twice. Keyed by position, each\n * step keeps its own.\n *\n * A duplicated id restores the same incoming value to every step claiming it,\n * which is as much as the payload allows: the ids are all it says.\n */\nexport function formAnswerSlots(\n steps: { id: string }[],\n output: unknown,\n): Record<number, unknown> {\n const slots: Record<number, unknown> = {}\n if (output === undefined || output === null) {\n return slots\n }\n // A legacy single-choice answer is the plain string, and it can only\n // belong to a single-step form.\n if (typeof output === 'string') {\n if (steps.length === 1) {\n slots[0] = output\n }\n return slots\n }\n const assign = (id: string, value: unknown) => {\n steps.forEach((step, index) => {\n if (step.id === id) {\n slots[index] = value\n }\n })\n }\n const list = (output as { answers?: unknown }).answers\n if (Array.isArray(list)) {\n for (const answer of list as { id?: unknown; value?: unknown }[]) {\n if (typeof answer?.id === 'string') {\n assign(answer.id, answer.value)\n }\n }\n return slots\n }\n // Forms answered on a platform channel (the Teams modal) come back as a\n // flat record keyed by step id.\n for (const [id, value] of Object.entries(\n output as Record<string, unknown>,\n )) {\n if (value !== undefined) {\n assign(id, value)\n }\n }\n return slots\n}\n\n// Web search tool part types, gateway and provider-native\nexport const WEB_SEARCH_TOOL_TYPES: string[] = WEB_SEARCH_TOOL_KEYS.map(\n (key) => `tool-${key}`,\n)\n\n// Tool part types with a dedicated rich rendering in PkChatbotStepToolDetail\nconst RICH_DETAIL_TOOL_TYPES = new Set([\n 'tool-searchInKnowledgeBase',\n 'tool-retrieveRevisedAnswers',\n 'tool-expandChunkContext',\n 'tool-readDocumentFile',\n 'tool-getWeather',\n 'tool-geocode',\n 'tool-recallUserMemory',\n 'tool-saveUserMemory',\n ...WEB_SEARCH_TOOL_TYPES,\n])\n\nexport function hasRichToolDetail(\n part?: UIMessage['parts'][number] | null,\n): boolean {\n return isToolPart(part) && RICH_DETAIL_TOOL_TYPES.has(part.type)\n}\n\nconst asRecord = (value: unknown): Record<string, unknown> | undefined =>\n value && typeof value === 'object' && !Array.isArray(value)\n ? (value as Record<string, unknown>)\n : undefined\n\nconst pickString = (\n record: Record<string, unknown> | undefined,\n ...keys: string[]\n): string | undefined => {\n for (const key of keys) {\n const value = record?.[key]\n if (typeof value === 'string' && value.trim()) {\n return value\n }\n }\n return undefined\n}\n\n/**\n * Returns a short inline summary for a tool part (search queries, location,\n * document name, ...) to be shown next to the step label without expanding\n * the step body.\n */\nexport function getToolPartSummary(\n part?: UIMessage['parts'][number] | null,\n): string | undefined {\n if (!isToolPart(part)) {\n return undefined\n }\n const input = asRecord('input' in part ? part.input : undefined)\n const output = asRecord('output' in part ? part.output : undefined)\n if (\n part.type === 'tool-searchInKnowledgeBase' ||\n WEB_SEARCH_TOOL_TYPES.includes(part.type)\n ) {\n const queries = input?.queries\n if (Array.isArray(queries)) {\n const valid = queries.filter(\n (query): query is string =>\n typeof query === 'string' && Boolean(query.trim()),\n )\n return valid.length ? valid.join(' · ') : undefined\n }\n return pickString(input, 'query', 'objective')\n }\n if (part.type === 'tool-retrieveRevisedAnswers') {\n return pickString(input, 'query')\n }\n if (part.type === 'tool-getWeather') {\n return (\n pickString(output, 'location') ?? pickString(input, 'locationName')\n )\n }\n if (part.type === 'tool-geocode') {\n return pickString(input, 'locationName')\n }\n if (part.type === 'tool-expandChunkContext') {\n return pickString(output, 'documentName')\n }\n if (\n part.type === 'tool-readDocumentFile' ||\n part.type === 'tool-readChatAttachment' ||\n part.type === 'tool-sendChatFile' ||\n part.type === 'tool-shareDocument'\n ) {\n return pickString(output, 'name')\n }\n if (part.type === 'tool-readSpreadsheet') {\n const sheet = pickString(input, 'sheet')\n const range = pickString(input, 'range')\n return sheet && range ? `${sheet}!${range}` : sheet\n }\n if (part.type === 'tool-editSpreadsheet') {\n return pickString(output, 'filename')\n }\n if (part.type === 'tool-readWordDocument') {\n return pickString(input, 'search') ?? pickString(input, 'from')\n }\n if (part.type === 'tool-editWordDocument') {\n return pickString(output, 'filename')\n }\n if (\n part.type === 'tool-createSpreadsheet' ||\n part.type === 'tool-createWordDocument'\n ) {\n // The name the file got, or while the call runs the one asked for.\n return pickString(output, 'filename') ?? pickString(input, 'filename')\n }\n if (part.type === 'tool-querySpreadsheet') {\n // The file when the step asked for the schema; a query has no name.\n return pickString(output, 'file')\n }\n if (part.type === 'tool-recallUserMemory') {\n return pickString(input, 'query')\n }\n if (part.type === 'tool-saveUserMemory') {\n return pickString(input, 'content', 'query')\n }\n return undefined\n}\n\n// Get part icon\nexport function getPartIcon(\n part?: UIMessage['parts'][number] | null,\n): string | undefined {\n const host = getHostCallPart(part)\n if (host) {\n return pageToolStep(host)?.icon ?? 'ri:apps-line'\n }\n if (isToolPart(part)) {\n if (part.type.includes('tool-subagent')) {\n return 'ri:robot-2-line'\n }\n if (part.type === 'tool-runWorker') {\n return 'ri:flow-chart'\n }\n if (part.type === 'tool-scheduleWakeup') {\n return 'ri:alarm-line'\n }\n if (part.type === 'tool-fetchTeamsChannelHistory') {\n return 'ri:chat-history-line'\n }\n if (part.type === 'tool-readEarlierMessages') {\n return 'ri:history-line'\n }\n if (part.type === 'tool-readChatAttachment') {\n return 'ri:attachment-line'\n }\n if (part.type === 'tool-sendChatFile') {\n return 'ri:send-plane-line'\n }\n if (part.type === 'tool-enableTools') {\n return 'ri:toggle-line'\n }\n if (part.type.includes('tool-mcp')) {\n return 'mcp'\n }\n if (part.type === 'tool-retrieveRevisedAnswers') {\n return 'ri:file-edit-line'\n }\n if (part.type === 'tool-searchInKnowledgeBase') {\n return 'ri:search-line'\n }\n if (part.type === 'tool-expandChunkContext') {\n return 'ri:file-search-line'\n }\n if (part.type === 'tool-readDocumentFile') {\n return 'ri:file-text-line'\n }\n if (part.type === 'tool-readSpreadsheet') {\n return 'ri:table-line'\n }\n if (\n part.type === 'tool-editSpreadsheet' ||\n part.type === 'tool-createSpreadsheet'\n ) {\n return 'ri:file-excel-2-line'\n }\n if (part.type === 'tool-shareDocument') {\n return 'ri:file-download-line'\n }\n if (part.type === 'tool-readWordDocument') {\n return 'ri:file-text-line'\n }\n if (\n part.type === 'tool-editWordDocument' ||\n part.type === 'tool-createWordDocument'\n ) {\n return 'ri:file-word-2-line'\n }\n if (part.type === 'tool-querySpreadsheet') {\n return 'ri:database-2-line'\n }\n if (part.type === 'tool-geocode') {\n return 'ri:map-2-line'\n }\n if (part.type === 'tool-getWeather') {\n return 'ri:sun-cloudy-line'\n }\n if (part.type === 'tool-recallUserMemory') {\n return 'ri:brain-line'\n }\n if (part.type === 'tool-saveUserMemory') {\n return 'ri:save-3-line'\n }\n if (part.type === 'tool-showWeather') {\n return 'ri:sun-line'\n }\n if (part.type === 'tool-showDiagram') {\n return 'ri:flow-chart'\n }\n if (part.type === 'tool-showSources') {\n return 'ri:book-2-line'\n }\n if (part.type === 'tool-showForm') {\n return 'ri:survey-line'\n }\n if (part.type === 'tool-showMultipleChoice') {\n return 'ri:checkbox-multiple-line'\n }\n if (part.type === 'tool-showArtifact') {\n return 'ri:file-code-line'\n }\n if (part.type === 'tool-showEmail') {\n return 'ri:mail-line'\n }\n if (part.type === 'tool-showMessage') {\n return 'ri:chat-1-line'\n }\n if (part.type === 'tool-showWebPages') {\n return 'ri:pages-line'\n }\n if (part.type === 'tool-showProductList') {\n return 'ri:shopping-bag-line'\n }\n if (part.type === 'tool-showContactForm') {\n return 'ri:send-plane-2-line'\n }\n if (part.type === 'tool-showCalendarEvent') {\n return 'ri:calendar-event-line'\n }\n if (part.type === 'tool-showComparison') {\n return 'ri:scales-line'\n }\n if (part.type === 'tool-showLocation') {\n return 'ri:map-pin-line'\n }\n if (part.type === 'tool-showQrCode') {\n return 'ri:qr-code-line'\n }\n if (part.type === 'tool-showImageGallery') {\n return 'ri:image-line'\n }\n if (part.type === 'tool-showVideo') {\n return 'ri:film-line'\n }\n if (part.type === 'tool-showSuggestedReply') {\n return 'ri:corner-down-right-line'\n }\n if (part.type === 'tool-requestGeolocation') {\n return 'ri:map-pin-user-line'\n }\n if (part.type === 'tool-disconnectOAuthConnection') {\n return 'ri:link-unlink'\n }\n if (part.type === 'tool-requestAccountLink') {\n return 'ri:link'\n }\n if (part.type === 'tool-unlinkAccount') {\n return 'ri:link-unlink'\n }\n if (WEB_SEARCH_TOOL_TYPES.includes(part.type)) {\n return 'ri:global-line'\n }\n return 'ri:tools-line'\n }\n if (isReasoningPart(part)) {\n return 'ri:lightbulb-line'\n }\n if (isTextPart(part)) {\n return 'ri:double-quotes-r'\n }\n return undefined\n}\n\n/** What `toolLabel` and `getPartTypeLabel` need from vue-i18n. */\nexport interface LabelTranslator {\n t: (key: string) => string\n te: (key: string) => boolean\n}\n\nconst TOOL_KEY_PREFIXES = [\n API_TOOL_PREFIX,\n MCP_TOOL_PREFIX,\n SUBAGENT_TOOL_PREFIX,\n] as const\n\n/**\n * The name a person reads for a tool of the turn: the translated label of a\n * built-in tool, otherwise the name the agent configured, without its\n * tool-set prefix and in words (`api-festivita_nazionali` reads \"Festivita\n * nazionali\"). Never the raw key, and never an i18n key with no translation,\n * which vue-i18n would print as the key itself.\n */\nexport function toolLabel(name: string, { t, te }: LabelTranslator): string {\n if (te(`agent.tool.${name}`)) {\n return t(`agent.tool.${name}`)\n }\n const prefix = TOOL_KEY_PREFIXES.find((p) => name.startsWith(p))\n const bare = prefix ? name.slice(prefix.length) : name\n return capitalizeFirstLetter(fromAnyCase(bare).trim().toLowerCase())\n}\n\n/**\n * The kinds of message part a person can meet, each with its label. Written\n * as literal keys so the widget's library build, which keeps only the keys it\n * finds written out (apps/web-component/vite-plugins/chatLocales.ts), ships\n * them too.\n */\nconst PART_TYPE_LABELS: Record<string, (t: LabelTranslator['t']) => string> = {\n custom: (t) => t('messagePart.type.custom'),\n data: (t) => t('messagePart.type.data'),\n file: (t) => t('messagePart.type.file'),\n reasoning: (t) => t('messagePart.type.reasoning'),\n 'source-document': (t) => t('messagePart.type.sourceDocument'),\n 'source-url': (t) => t('messagePart.type.sourceUrl'),\n 'step-start': (t) => t('messagePart.type.stepStart'),\n text: (t) => t('messagePart.type.text'),\n}\n\n/**\n * The label of a message part in the message details: the tool for a tool\n * call, the translated kind otherwise (text, reasoning, provider data...),\n * and the kind in words for one the catalog does not know yet.\n */\nexport function getPartTypeLabel(\n part: UIMessage['parts'][number],\n translator: LabelTranslator,\n): string {\n if (isToolPart(part)) {\n return toolLabel(getToolPartName(part), translator)\n }\n if (part.type === 'dynamic-tool') {\n return toolLabel(part.toolName, translator)\n }\n const kind = part.type.startsWith('data-') ? 'data' : part.type\n const label = PART_TYPE_LABELS[kind]\n return label\n ? label(translator.t)\n : capitalizeFirstLetter(fromAnyCase(part.type))\n}\n\n/**\n * The commercial name of a provider the gateway routed a turn through, from\n * its slug (`anthropic`, `bedrock`): proper nouns, so no translation. A slug\n * not listed here shows with a capital, never as the bare id.\n */\nconst PROVIDER_NAMES: Record<string, string> = {\n alibaba: 'Alibaba Cloud',\n anthropic: 'Anthropic',\n azure: 'Microsoft Azure',\n baseten: 'Baseten',\n bedrock: 'Amazon Bedrock',\n cerebras: 'Cerebras',\n cohere: 'Cohere',\n deepinfra: 'DeepInfra',\n deepseek: 'DeepSeek',\n fireworks: 'Fireworks AI',\n google: 'Google',\n groq: 'Groq',\n mistral: 'Mistral AI',\n moonshotai: 'Moonshot AI',\n openai: 'OpenAI',\n perplexity: 'Perplexity',\n togetherai: 'Together AI',\n vertex: 'Google Vertex AI',\n xai: 'xAI',\n zai: 'Z.ai',\n}\n\n/** The name of a provider slug, see `PROVIDER_NAMES`. */\nexport function providerLabel(slug: string): string {\n return (\n PROVIDER_NAMES[slug.toLowerCase()] ??\n capitalizeFirstLetter(fromAnyCase(slug))\n )\n}\n\n/**\n * The conversation summary in the reader's language. The analysis asks the\n * model for four bold labels (`SUMMARY_FORMAT` in\n * apps/backend/src/prompts/analysis.prompt.ts) and the model copies them in\n * English whatever the conversation's language, so every stored summary\n * holds them: they are translated where a summary is read. An empty summary\n * comes back as it is, so a `??` fallback after it still works.\n */\nexport function localizeSummaryLabels<T extends string | null | undefined>(\n summary: T,\n t: (key: string) => string,\n): T {\n if (!summary) {\n return summary\n }\n const labels: Record<string, string> = {\n Intent: t('conversationSummary.intent'),\n 'Topics covered': t('conversationSummary.topicsCovered'),\n 'Key facts': t('conversationSummary.keyFacts'),\n 'Open questions': t('conversationSummary.openQuestions'),\n }\n return summary.replace(\n /\\*\\*(Intent|Topics covered|Key facts|Open questions)(:?)\\*\\*/g,\n (_, label: string, colon: string) => `**${labels[label]}${colon}**`,\n ) as T\n}\n\n// Get part label\nexport function getToolPartLabel(\n $t: (key: string) => string,\n part?: UIMessage['parts'][number] | null,\n /** The live titles of the page's steps, by call: they win when present. */\n hostStepTitles?: Record<string, string>,\n): string | undefined {\n const host = getHostCallPart(part)\n if (host) {\n const live = host.toolCallId\n ? hostStepTitles?.[host.toolCallId]\n : undefined\n if (live) {\n return live\n }\n const page = pageToolStep(host)\n return page ? $t(page.label) : host.title || host.toolName\n }\n if (isToolPart(part)) {\n if (part.type.includes('tool-subagent')) {\n return $t(`messagePart.runSubagent`)\n }\n if (part.type === 'tool-runWorker') {\n return $t(`messagePart.runWorker`)\n }\n if (part.type === 'tool-scheduleWakeup') {\n return $t(`messagePart.scheduleWakeup`)\n }\n if (part.type === 'tool-fetchTeamsChannelHistory') {\n return $t(`messagePart.fetchTeamsChannelHistory`)\n }\n if (part.type === 'tool-readEarlierMessages') {\n return $t(`messagePart.readEarlierMessages`)\n }\n if (part.type === 'tool-readChatAttachment') {\n return $t(`messagePart.readChatAttachment`)\n }\n if (part.type === 'tool-sendChatFile') {\n return $t(`messagePart.sendChatFile`)\n }\n if (part.type === 'tool-enableTools') {\n return $t(`messagePart.enableTools`)\n }\n if (part.type === 'tool-retrieveRevisedAnswers') {\n return $t(`messagePart.revisedAnswers`)\n }\n if (part.type === 'tool-searchInKnowledgeBase') {\n return $t(`messagePart.searchingDocuments`)\n }\n if (part.type === 'tool-expandChunkContext') {\n return $t(`messagePart.expandChunkContext`)\n }\n if (part.type === 'tool-readDocumentFile') {\n return $t(`messagePart.readDocumentFile`)\n }\n if (part.type === 'tool-readSpreadsheet') {\n return $t(`messagePart.readSpreadsheet`)\n }\n if (part.type === 'tool-editSpreadsheet') {\n return $t(`messagePart.editSpreadsheet`)\n }\n if (part.type === 'tool-shareDocument') {\n return $t(`messagePart.shareDocument`)\n }\n if (part.type === 'tool-readWordDocument') {\n return $t(`messagePart.readWordDocument`)\n }\n if (part.type === 'tool-editWordDocument') {\n return $t(`messagePart.editWordDocument`)\n }\n if (part.type === 'tool-createSpreadsheet') {\n return $t(`messagePart.createSpreadsheet`)\n }\n if (part.type === 'tool-createWordDocument') {\n return $t(`messagePart.createWordDocument`)\n }\n if (part.type === 'tool-querySpreadsheet') {\n return $t(`messagePart.querySpreadsheet`)\n }\n if (part.type === 'tool-geocode') {\n return $t(`messagePart.geocode`)\n }\n if (part.type === 'tool-getWeather') {\n return $t(`messagePart.getWeather`)\n }\n if (part.type === 'tool-recallUserMemory') {\n return $t(`messagePart.recallUserMemory`)\n }\n if (part.type === 'tool-saveUserMemory') {\n return $t(`messagePart.saveUserMemory`)\n }\n if (part.type === 'tool-showWeather') {\n return $t(`messagePart.showWeather`)\n }\n if (part.type === 'tool-showForm') {\n return $t(`messagePart.showForm`)\n }\n if (part.type === 'tool-showDiagram') {\n return $t(`messagePart.showDiagram`)\n }\n if (part.type === 'tool-showSources') {\n return $t(`messagePart.showSources`)\n }\n if (part.type === 'tool-showMultipleChoice') {\n return $t(`messagePart.showMultipleChoice`)\n }\n if (part.type === 'tool-showArtifact') {\n return $t(`messagePart.showArtifact`)\n }\n if (part.type === 'tool-showEmail') {\n return $t(`messagePart.showEmail`)\n }\n if (part.type === 'tool-showMessage') {\n return $t(`messagePart.showMessage`)\n }\n if (part.type === 'tool-showWebPages') {\n return $t(`messagePart.showWebPages`)\n }\n if (part.type === 'tool-showProducts') {\n return $t(`messagePart.showProducts`)\n }\n if (part.type === 'tool-showContactForm') {\n return $t(`messagePart.showContactForm`)\n }\n if (part.type === 'tool-showCalendarEvent') {\n return $t(`messagePart.showCalendarEvent`)\n }\n if (part.type === 'tool-showComparison') {\n return $t(`messagePart.showComparison`)\n }\n if (part.type === 'tool-showLocation') {\n return $t(`messagePart.showLocation`)\n }\n if (part.type === 'tool-showQrCode') {\n return $t(`messagePart.showQrCode`)\n }\n if (part.type === 'tool-showImageGallery') {\n return $t(`messagePart.showImageGallery`)\n }\n if (part.type === 'tool-showVideo') {\n return $t(`messagePart.showVideo`)\n }\n if (part.type === 'tool-showSuggestedReply') {\n return $t(`messagePart.showSuggestedReply`)\n }\n if (part.type === 'tool-requestGeolocation') {\n return $t(`messagePart.requestGeolocation`)\n }\n if (part.type === 'tool-disconnectOAuthConnection') {\n return $t(`messagePart.disconnectOAuthConnection`)\n }\n if (part.type === 'tool-requestAccountLink') {\n return $t(`messagePart.requestAccountLink`)\n }\n if (part.type === 'tool-unlinkAccount') {\n return $t(`messagePart.unlinkAccount`)\n }\n if (WEB_SEARCH_TOOL_TYPES.includes(part.type)) {\n return $t(`messagePart.webSearch`)\n }\n return $t(`messagePart.tool`)\n }\n if (isReasoningPart(part)) {\n return $t(`messagePart.reasoning`)\n }\n return $t(`messagePart.streaming`)\n}\n\n/** The version of a file stored in the chat that a preview opens. */\nexport type ChatFilePreviewTarget = {\n kind: 'word' | 'spreadsheet'\n storedFileName: string\n /** The name of the file, not of its version. */\n filename: string\n version?: number\n /** The file all its versions belong to, as the agent names it. */\n fileId?: string\n}\n\n/**\n * How the viewer draws a Word document's tracked changes: marked as Word\n * marks them, as if accepted, or as before them.\n */\nexport type WordPreviewMode = 'markup' | 'accepted' | 'original'\n\n/**\n * The fonts that stand in for Office's where the reader's system lacks them:\n * the metric-compatible ones of Linux and Chrome OS first, so the lines break\n * where Word breaks them, then the closest common ones.\n */\nconst WORD_FONT_STACKS: Record<string, string> = {\n calibri: 'Calibri, Carlito, \"Segoe UI\", Arial, sans-serif',\n 'calibri light':\n '\"Calibri Light\", Calibri, Carlito, \"Segoe UI\", sans-serif',\n aptos: 'Aptos, Calibri, Carlito, \"Segoe UI\", Arial, sans-serif',\n 'aptos display': '\"Aptos Display\", Aptos, Calibri, Carlito, sans-serif',\n cambria: 'Cambria, Caladea, Georgia, serif',\n 'times new roman':\n '\"Times New Roman\", Tinos, \"Liberation Serif\", Times, serif',\n arial: 'Arial, Arimo, \"Liberation Sans\", Helvetica, sans-serif',\n helvetica: 'Helvetica, Arial, Arimo, sans-serif',\n 'courier new': '\"Courier New\", Cousine, \"Liberation Mono\", monospace',\n garamond: 'Garamond, \"EB Garamond\", Georgia, serif',\n georgia: 'Georgia, serif',\n verdana: 'Verdana, \"DejaVu Sans\", sans-serif',\n tahoma: 'Tahoma, Verdana, sans-serif',\n}\n\n/**\n * Word's single line as a multiple of the font size, from the font's ascent,\n * descent and line gap: the lines keep the height of the document's font\n * where another font stands in for it.\n */\nconst WORD_LINE_FACTORS: Record<string, number> = {\n calibri: 1.22,\n 'calibri light': 1.22,\n cambria: 1.17,\n 'times new roman': 1.15,\n arial: 1.15,\n helvetica: 1.15,\n 'courier new': 1.13,\n georgia: 1.14,\n verdana: 1.22,\n tahoma: 1.21,\n}\n\n/** Word's single line for a font a Word document names. */\nexport const wordLineFactor = (font: string): number =>\n WORD_LINE_FACTORS[font.toLowerCase()] ?? 1.17\n\n/** The CSS font stack for a font a Word document names. */\nexport const wordFontStack = (font: string): string =>\n WORD_FONT_STACKS[font.toLowerCase()] ??\n `\"${font.replace(/\"/g, '')}\", ${\n /roman|garamond|cambria|georgia|serif|book|times/i.test(font)\n ? 'Georgia, serif'\n : 'Calibri, Carlito, \"Segoe UI\", Arial, sans-serif'\n }`\n\n/**\n * The images of the Word document in the viewer, by reference, which its\n * runs draw (`PkWordPreview` provides them).\n */\nexport const WORD_PREVIEW_IMAGES: InjectionKey<\n Ref<Record<string, string> | undefined>\n> = Symbol('wordPreviewImages')\n\n/**\n * The image a run draws, only a WebP the server wrote: anything else in the\n * map is not drawn.\n */\nexport const wordPictureSrc = (\n images: Record<string, string> | undefined,\n ref: string,\n): string | undefined => {\n const src = images?.[ref]\n return src?.startsWith('data:image/webp;base64,') ? src : undefined\n}\n\n/** The numbers the page number fields of a page show. */\nexport type WordPageNumbers = {\n page: number\n pages: number\n sectionPages: number\n}\n\n/**\n * Where an image Word positions on the page sits on it: from the page's top\n * left corner, in points, under the text or over it.\n */\nexport const wordPageAnchorCss = (\n picture: WordPreviewPicture,\n page: WordPreviewPage,\n): CSSProperties => {\n const anchor = picture.anchor!\n return {\n left: `${anchor.xFrom === 'page' ? anchor.x : page.margins.left + anchor.x}pt`,\n top: `${anchor.yFrom === 'page' ? anchor.y : page.margins.top + anchor.y}pt`,\n width: `${picture.width}pt`,\n height: `${picture.height}pt`,\n zIndex: anchor.wrap === 'behind' ? -1 : 1,\n }\n}\n\n/**\n * How an image of a run is placed: in the text, beside the text of its\n * paragraph, on a line of its own, from its paragraph, or on the page,\n * which the page draws.\n */\nexport const wordPicturePlacement = (\n picture: WordPreviewPicture,\n): 'inline' | 'around' | 'block' | 'paragraph' | 'page' => {\n const anchor = picture.anchor\n return !anchor\n ? 'inline'\n : anchor.wrap === 'around'\n ? 'around'\n : anchor.wrap === 'block'\n ? 'block'\n : anchor.yFrom === 'paragraph'\n ? 'paragraph'\n : 'page'\n}\n\n/** The runs a mode keeps: a deletion is gone once accepted. */\nexport const wordKeptRuns = (\n runs: WordPreviewRun[],\n mode: WordPreviewMode,\n): WordPreviewRun[] =>\n runs.filter((r) =>\n mode === 'accepted'\n ? r.change !== 'deleted'\n : mode === 'original'\n ? r.change !== 'inserted'\n : true,\n )\n\nconst hasWordText = (runs: WordPreviewRun[]) =>\n runs.some((r) => r.image || r.text.trim())\n\n/** A piece of a Word document's flow: a paragraph or a table row. */\nexport type WordFlowItem = {\n key: string\n block: number\n row?: number\n breakBefore: boolean\n /** The section it opens. */\n section?: number\n}\n\n/**\n * The pieces of `blocks` in order, as the pages hold them. A paragraph or a\n * table row a mode empties is gone (a row inserted, as the original); one\n * empty in the document stays, a blank line as in Word. A section a gone\n * piece opened, with its page break, passes to the next one.\n */\nexport const wordFlowItems = (\n blocks: WordPreviewBlock[],\n mode: WordPreviewMode,\n): WordFlowItem[] => {\n const out: WordFlowItem[] = []\n let breakPending = false\n let sectionPending: number | undefined\n const push = (\n key: string,\n block: number,\n row: number | undefined,\n breakBefore: boolean,\n section: number | undefined,\n ) => {\n const opens = section ?? sectionPending\n out.push({\n key,\n block,\n ...(row !== undefined ? { row } : {}),\n breakBefore: breakBefore || breakPending,\n ...(opens !== undefined ? { section: opens } : {}),\n })\n breakPending = false\n sectionPending = undefined\n }\n // A gone piece's own page break goes with it; a section's start stays\n const skip = (breakBefore: boolean, section: number | undefined) => {\n breakPending ||= breakBefore && section !== undefined\n sectionPending = section ?? sectionPending\n }\n blocks.forEach((block, b) => {\n if (block.kind === 'table') {\n // The table's break and section go with its first row shown\n let breaks = !!block.pageBreakBefore\n let opens = block.section\n block.rows.forEach((cells, r) => {\n const filled = cells.some((cell) => cell.runs.length)\n if (\n filled &&\n !cells.some((cell) =>\n hasWordText(wordKeptRuns(cell.runs, mode)),\n )\n ) {\n return\n }\n push(`${b}:${r}`, b, r, breaks, opens)\n breaks = false\n opens = undefined\n })\n skip(breaks, opens)\n } else if (\n !block.runs.length ||\n hasWordText(wordKeptRuns(block.runs, mode))\n ) {\n push(\n `${b}`,\n b,\n undefined,\n !!block.style?.pageBreakBefore,\n block.section,\n )\n } else {\n skip(!!block.style?.pageBreakBefore, block.section)\n }\n })\n return out\n}\n\n/** The images Word positions on the page among the paragraphs of `blocks`. */\nexport const wordPageAnchors = (\n blocks: WordPreviewBlock[],\n mode: WordPreviewMode,\n): WordPreviewPicture[] =>\n blocks.flatMap((block) =>\n block.kind === 'table'\n ? []\n : wordKeptRuns(block.runs, mode).flatMap((run) =>\n run.picture && wordPicturePlacement(run.picture) === 'page'\n ? [run.picture]\n : [],\n ),\n )\n\n/** An earlier version of a file of the chat, for the agent to restore. */\nexport type ChatFileRestoreTarget = {\n /** The id the agent names the file with: the stored name of version 1. */\n fileId: string\n version: number\n filename: string\n}\n\n/**\n * The name of a file, not of its version: `listino (v2).xlsx` is version 2\n * of `listino.xlsx`.\n */\nexport const chatFileName = (filename: string, version?: number): string =>\n version\n ? filename.replace(new RegExp(` \\\\(v${version}\\\\)(\\\\.\\\\w+)$`), '$1')\n : filename\n\n/**\n * Whether a chat stands in front of the place of the bar that shows the\n * agent acting on the page (`PkPageControlBar`): the top centre of the\n * window, from the bar's `top` of 48px to about its 44px of height below.\n * There the bar would only cover the chat's header, and the chat shows the\n * steps and their stop itself.\n */\nexport function chatCoversPageControlBar(\n chat: Pick<DOMRect, 'left' | 'right' | 'top' | 'bottom'>,\n windowWidth: number,\n): boolean {\n const center = windowWidth / 2\n return (\n chat.left <= center &&\n chat.right >= center &&\n chat.top <= 92 &&\n chat.bottom >= 48\n )\n}\n"],"mappings":";;;;;AAAA,IAAaU,KAAiB,MAC1BC,EAAI,UAAU,KAAK,CAAC,CAAC,QAAQ,oBAAoB,EAAE,GAkB1CC,KAAe,MACnBD,IAGEA,EACF,QAAQ,sBAAsB,OAAO,CAAC,CACtC,QAAQ,yBAAyB,OAAO,CAAC,CACzC,QAAQ,UAAU,GAAG,IALf,IAiBFE,KAAiC,MACrCF,IAGED,EAAcC,CAAG,CAAC,CACpB,QAAQ,sBAAsB,OAAO,CAAC,CACtC,QAAQ,kBAAkB,GAAG,CAAC,CAC9B,YAAY,IALN,IAeFG,MAAiC,MACrCH,IAGED,EAAcC,CAAG,CAAC,CACpB,QAAQ,sBAAsB,OAAO,CAAC,CACtC,QAAQ,kBAAkB,GAAG,CAAC,CAC9B,YAAY,IALN,IAQFI,KAAyB,MAC7BJ,IAGEA,EAAI,OAAO,CAAC,CAAC,CAAC,YAAY,IAAIA,EAAI,MAAM,CAAC,IAFrC;;ACvBf,SAAgBK,EACZ,GACkB;CAClB,IAAMC,IAA6B,CAAC;CACpC,KAAK,IAAMC,KAAQC,GAAO;EACtB,IAAI,CAACX,EAAWU,CAAI,GAA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