@burdenoff/fe-libs 2026.926.5 → 2026.927.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/shared/assistant/conversation.d.ts +91 -3
- package/dist/shared/assistant/conversation.d.ts.map +1 -1
- package/dist/shared/assistant/gatewayClient.d.ts +15 -0
- package/dist/shared/assistant/gatewayClient.d.ts.map +1 -1
- package/dist/shared/assistant/gatewayClient.js +1 -1
- package/dist/shared/assistant/guardedStorage.d.ts +4 -2
- package/dist/shared/assistant/guardedStorage.d.ts.map +1 -1
- package/dist/shared/assistant/guardedStorage.js +1 -1
- package/dist/shared/assistant/history/historyApi.d.ts +38 -0
- package/dist/shared/assistant/history/historyApi.d.ts.map +1 -0
- package/dist/shared/assistant/history/historyApi.js +153 -0
- package/dist/shared/assistant/history/historyEngine.d.ts +96 -0
- package/dist/shared/assistant/history/historyEngine.d.ts.map +1 -0
- package/dist/shared/assistant/history/historyEngine.js +774 -0
- package/dist/shared/assistant/history/historyErrors.d.ts +72 -0
- package/dist/shared/assistant/history/historyErrors.d.ts.map +1 -0
- package/dist/shared/assistant/history/historyErrors.js +74 -0
- package/dist/shared/assistant/history/historyList.d.ts +115 -0
- package/dist/shared/assistant/history/historyList.d.ts.map +1 -0
- package/dist/shared/assistant/history/historyList.js +116 -0
- package/dist/shared/assistant/history/historyMapping.d.ts +65 -0
- package/dist/shared/assistant/history/historyMapping.d.ts.map +1 -0
- package/dist/shared/assistant/history/historyMapping.js +383 -0
- package/dist/shared/assistant/history/historyMerge.d.ts +65 -0
- package/dist/shared/assistant/history/historyMerge.d.ts.map +1 -0
- package/dist/shared/assistant/history/historyMerge.js +97 -0
- package/dist/shared/assistant/history/historyOperations.d.ts +24 -0
- package/dist/shared/assistant/history/historyOperations.d.ts.map +1 -0
- package/dist/shared/assistant/history/historyOperations.js +125 -0
- package/dist/shared/assistant/history/historyResume.d.ts +56 -0
- package/dist/shared/assistant/history/historyResume.d.ts.map +1 -0
- package/dist/shared/assistant/history/historyResume.js +55 -0
- package/dist/shared/assistant/history/historyStatus.d.ts +76 -0
- package/dist/shared/assistant/history/historyStatus.d.ts.map +1 -0
- package/dist/shared/assistant/history/historyStatus.js +47 -0
- package/dist/shared/assistant/history/historyStore.d.ts +192 -0
- package/dist/shared/assistant/history/historyStore.d.ts.map +1 -0
- package/dist/shared/assistant/history/historyStore.js +503 -0
- package/dist/shared/assistant/history/historyTimestamps.d.ts +11 -0
- package/dist/shared/assistant/history/historyTimestamps.d.ts.map +1 -0
- package/dist/shared/assistant/history/historyTimestamps.js +9 -0
- package/dist/shared/assistant/history/historyTypes.d.ts +256 -0
- package/dist/shared/assistant/history/historyTypes.d.ts.map +1 -0
- package/dist/shared/assistant/history/historyTypes.js +20 -0
- package/dist/shared/assistant/history/profileBoundStorage.d.ts +36 -0
- package/dist/shared/assistant/history/profileBoundStorage.d.ts.map +1 -0
- package/dist/shared/assistant/history/profileBoundStorage.js +74 -0
- package/dist/shared/assistant/history/stampRegistry.d.ts +84 -0
- package/dist/shared/assistant/history/stampRegistry.d.ts.map +1 -0
- package/dist/shared/assistant/history/stampRegistry.js +58 -0
- package/dist/shared/assistant/history/useAssistantServerHistory.d.ts +18 -0
- package/dist/shared/assistant/history/useAssistantServerHistory.d.ts.map +1 -0
- package/dist/shared/assistant/history/useAssistantServerHistory.js +12 -0
- package/dist/shared/assistant/i18nManifest.d.ts +18 -0
- package/dist/shared/assistant/i18nManifest.d.ts.map +1 -1
- package/dist/shared/assistant/i18nManifest.js +18 -0
- package/dist/shared/assistant/index.d.ts +16 -0
- package/dist/shared/assistant/index.d.ts.map +1 -1
- package/dist/shared/assistant/liveTurns.d.ts +7 -0
- package/dist/shared/assistant/liveTurns.d.ts.map +1 -1
- package/dist/shared/assistant/liveTurns.js +35 -32
- package/dist/shared/assistant/spokenTurns.d.ts +20 -0
- package/dist/shared/assistant/spokenTurns.d.ts.map +1 -1
- package/dist/shared/assistant/spokenTurns.js +13 -8
- package/dist/shared/assistant/store.d.ts +35 -1
- package/dist/shared/assistant/store.d.ts.map +1 -1
- package/dist/shared/assistant/store.js +93 -24
- package/dist/shared/assistant/ui/AIAssistantPanel.d.ts +16 -0
- package/dist/shared/assistant/ui/AIAssistantPanel.d.ts.map +1 -1
- package/dist/shared/assistant/ui/AIAssistantPanel.js +63 -60
- package/dist/shared/assistant/ui/AssistantChatArea.d.ts.map +1 -1
- package/dist/shared/assistant/ui/AssistantChatArea.js +730 -672
- package/dist/shared/assistant/ui/AssistantConversationList.d.ts +17 -0
- package/dist/shared/assistant/ui/AssistantConversationList.d.ts.map +1 -1
- package/dist/shared/assistant/ui/AssistantConversationList.js +252 -145
- package/dist/shared/assistant/ui/AssistantHistoryNotices.d.ts +36 -0
- package/dist/shared/assistant/ui/AssistantHistoryNotices.d.ts.map +1 -0
- package/dist/shared/assistant/ui/AssistantHistoryNotices.js +103 -0
- package/dist/shared/assistant/ui/AssistantOverlay.d.ts +4 -0
- package/dist/shared/assistant/ui/AssistantOverlay.d.ts.map +1 -1
- package/dist/shared/assistant/ui/AssistantOverlay.js +97 -94
- package/dist/shared/assistant/ui/AssistantSpokenTurnsNotice.d.ts +5 -3
- package/dist/shared/assistant/ui/AssistantSpokenTurnsNotice.d.ts.map +1 -1
- package/dist/shared/assistant/ui/composer/AssistantComposer.d.ts +6 -0
- package/dist/shared/assistant/ui/composer/AssistantComposer.d.ts.map +1 -1
- package/dist/shared/assistant/ui/composer/AssistantComposer.js +54 -54
- package/dist/shared/assistant/ui/voice/VoiceTranscriptDrawer.d.ts +9 -0
- package/dist/shared/assistant/ui/voice/VoiceTranscriptDrawer.d.ts.map +1 -1
- package/dist/shared/assistant/ui/voice/VoiceTranscriptDrawer.js +37 -32
- package/dist/shared/assistant/voice/turnVisibility.d.ts +7 -5
- package/dist/shared/assistant/voice/turnVisibility.d.ts.map +1 -1
- package/dist/shared/assistant/voice/voiceTranscript.d.ts +3 -2
- package/dist/shared/assistant/voice/voiceTranscript.d.ts.map +1 -1
- package/dist/shared-assistant.js +153 -137
- package/package.json +1 -1
|
@@ -0,0 +1,503 @@
|
|
|
1
|
+
import { createProfileBoundStorage as e } from "./profileBoundStorage.js";
|
|
2
|
+
import { create as t } from "zustand";
|
|
3
|
+
import { persist as n } from "zustand/middleware";
|
|
4
|
+
//#region src/shared/assistant/history/historyStore.ts
|
|
5
|
+
var r = "hb-ai-assistant-history", i = 300, a = 1e3, o = 10080 * 60 * 1e3, s = 720 * 60 * 60 * 1e3;
|
|
6
|
+
function c() {
|
|
7
|
+
return {
|
|
8
|
+
v: 1,
|
|
9
|
+
scopes: {},
|
|
10
|
+
outbox: [],
|
|
11
|
+
doneItemIds: {},
|
|
12
|
+
tombstones: {}
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function l(e = 0) {
|
|
16
|
+
return {
|
|
17
|
+
...e > 0 ? { gen: e } : {},
|
|
18
|
+
cursor: null,
|
|
19
|
+
cursorRev: 0,
|
|
20
|
+
headers: {}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
var u = (e) => e?.gen ?? 0;
|
|
24
|
+
function d(e) {
|
|
25
|
+
return typeof e == "object" && !!e && !Array.isArray(e);
|
|
26
|
+
}
|
|
27
|
+
function f(e) {
|
|
28
|
+
return d(e) && typeof e.serverId == "string" && (e.clientConversationId === null || typeof e.clientConversationId == "string") && (e.title === null || typeof e.title == "string") && typeof e.legacy == "boolean" && typeof e.revision == "number" && typeof e.lastMessageSeq == "number" && typeof e.createdAt == "string" && typeof e.updatedAt == "string" && (e.gone === void 0 || e.gone === !0);
|
|
29
|
+
}
|
|
30
|
+
var p = (e) => new Set(Object.keys(e)), m = p({
|
|
31
|
+
gen: !0,
|
|
32
|
+
cursor: !0,
|
|
33
|
+
cursorRev: !0,
|
|
34
|
+
headers: !0,
|
|
35
|
+
hasOlderHeaders: !0,
|
|
36
|
+
pulledAt: !0,
|
|
37
|
+
resetAt: !0,
|
|
38
|
+
rescanning: !0
|
|
39
|
+
}), h = p({
|
|
40
|
+
scopeKey: !0,
|
|
41
|
+
at: !0,
|
|
42
|
+
confirmed: !0,
|
|
43
|
+
serverId: !0
|
|
44
|
+
}), g = p({
|
|
45
|
+
serverId: !0,
|
|
46
|
+
clientConversationId: !0,
|
|
47
|
+
title: !0,
|
|
48
|
+
legacy: !0,
|
|
49
|
+
revision: !0,
|
|
50
|
+
lastMessageSeq: !0,
|
|
51
|
+
createdAt: !0,
|
|
52
|
+
updatedAt: !0,
|
|
53
|
+
gone: !0
|
|
54
|
+
}), _ = p({
|
|
55
|
+
id: !0,
|
|
56
|
+
type: !0,
|
|
57
|
+
scopeKey: !0,
|
|
58
|
+
convKey: !0,
|
|
59
|
+
kind: !0,
|
|
60
|
+
entries: !0,
|
|
61
|
+
attempts: !0,
|
|
62
|
+
nextAttemptAt: !0,
|
|
63
|
+
parked: !0
|
|
64
|
+
}), v = p({
|
|
65
|
+
id: !0,
|
|
66
|
+
type: !0,
|
|
67
|
+
scopeKey: !0,
|
|
68
|
+
convKey: !0,
|
|
69
|
+
serverId: !0,
|
|
70
|
+
legacy: !0,
|
|
71
|
+
attempts: !0,
|
|
72
|
+
nextAttemptAt: !0
|
|
73
|
+
});
|
|
74
|
+
function y(e, t) {
|
|
75
|
+
let n = {};
|
|
76
|
+
for (let [r, i] of Object.entries(e)) t.has(r) || (n[r] = i);
|
|
77
|
+
return n;
|
|
78
|
+
}
|
|
79
|
+
function b(e, t, n) {
|
|
80
|
+
let r = y(t, n), i = Object.assign({}, e, r);
|
|
81
|
+
for (let t of Object.keys(e)) !n.has(t) && !Object.hasOwn(r, t) && Reflect.deleteProperty(i, t);
|
|
82
|
+
return i;
|
|
83
|
+
}
|
|
84
|
+
function x(e) {
|
|
85
|
+
if (!d(e)) return {};
|
|
86
|
+
let t = {};
|
|
87
|
+
for (let [n, r] of Object.entries(e)) {
|
|
88
|
+
if (!d(r)) continue;
|
|
89
|
+
let e = {};
|
|
90
|
+
if (d(r.headers)) for (let [t, n] of Object.entries(r.headers)) f(n) && (e[t] = n);
|
|
91
|
+
let i = typeof r.gen == "number" && Number.isSafeInteger(r.gen) ? r.gen : 0;
|
|
92
|
+
t[n] = Object.assign(y(r, m), {
|
|
93
|
+
...i > 0 ? { gen: i } : {},
|
|
94
|
+
cursor: typeof r.cursor == "string" ? r.cursor : null,
|
|
95
|
+
cursorRev: typeof r.cursorRev == "number" ? r.cursorRev : 0,
|
|
96
|
+
headers: e,
|
|
97
|
+
...r.hasOlderHeaders === !0 ? { hasOlderHeaders: !0 } : {},
|
|
98
|
+
...typeof r.pulledAt == "number" ? { pulledAt: r.pulledAt } : {},
|
|
99
|
+
...typeof r.resetAt == "number" ? { resetAt: r.resetAt } : {},
|
|
100
|
+
...r.rescanning === !0 ? { rescanning: !0 } : {}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
return t;
|
|
104
|
+
}
|
|
105
|
+
function S(e) {
|
|
106
|
+
return !d(e) || !(typeof e.id == "string" && typeof e.scopeKey == "string" && typeof e.convKey == "string" && typeof e.attempts == "number") ? !1 : e.type === "save" ? (e.kind === "TURN" || e.kind === "LOCAL_COMMAND" || e.kind === "NOTE") && Array.isArray(e.entries) : e.type === "delete" && typeof e.legacy == "boolean";
|
|
107
|
+
}
|
|
108
|
+
function C(e) {
|
|
109
|
+
if (!d(e)) return {};
|
|
110
|
+
let t = {};
|
|
111
|
+
for (let [n, r] of Object.entries(e)) d(r) && typeof r.scopeKey == "string" && typeof r.at == "number" && typeof r.confirmed == "boolean" && (t[n] = Object.assign(y(r, h), {
|
|
112
|
+
scopeKey: r.scopeKey,
|
|
113
|
+
at: r.at,
|
|
114
|
+
confirmed: r.confirmed,
|
|
115
|
+
...typeof r.serverId == "string" ? { serverId: r.serverId } : {}
|
|
116
|
+
}));
|
|
117
|
+
return t;
|
|
118
|
+
}
|
|
119
|
+
function w(e) {
|
|
120
|
+
return d(e) ? Object.fromEntries(Object.entries(e).filter((e) => typeof e[1] == "number")) : {};
|
|
121
|
+
}
|
|
122
|
+
function T(e) {
|
|
123
|
+
return !d(e) || e.v !== 1 ? c() : M({
|
|
124
|
+
v: 1,
|
|
125
|
+
scopes: x(e.scopes),
|
|
126
|
+
outbox: Array.isArray(e.outbox) ? e.outbox.filter(S) : [],
|
|
127
|
+
doneItemIds: w(e.doneItemIds),
|
|
128
|
+
tombstones: C(e.tombstones)
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
function E(e, t) {
|
|
132
|
+
return t.revision === e.revision ? t.gone && !e.gone ? t : e : t.revision > e.revision ? t : e;
|
|
133
|
+
}
|
|
134
|
+
function D(e, t, n) {
|
|
135
|
+
let r = E(e, t);
|
|
136
|
+
return n === "stored" && e.revision === t.revision ? b(r, t, g) : r;
|
|
137
|
+
}
|
|
138
|
+
function O(e, t, n, r) {
|
|
139
|
+
return r === "stored" ? y(t, n) : {
|
|
140
|
+
...y(t, n),
|
|
141
|
+
...y(e, n)
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
function k(e, t = 300) {
|
|
145
|
+
let n = Object.entries(e.headers);
|
|
146
|
+
return n.length <= t ? e : (n.sort(([e, t], [n, r]) => t.updatedAt === r.updatedAt ? e < n ? -1 : Number(e > n) : t.updatedAt < r.updatedAt ? 1 : -1), {
|
|
147
|
+
...e,
|
|
148
|
+
headers: Object.fromEntries(n.slice(0, t)),
|
|
149
|
+
hasOlderHeaders: !0
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
function A(e, t, n) {
|
|
153
|
+
if (!e) return t ?? l();
|
|
154
|
+
if (!t) return e;
|
|
155
|
+
if (u(e) !== u(t)) return u(e) > u(t) ? e : t;
|
|
156
|
+
let r = { ...e.headers };
|
|
157
|
+
for (let [e, i] of Object.entries(t.headers)) {
|
|
158
|
+
let t = r[e];
|
|
159
|
+
r[e] = t ? D(t, i, n) : i;
|
|
160
|
+
}
|
|
161
|
+
let i = t.cursorRev > e.cursorRev ? t : e, a = Math.max(e.pulledAt ?? 0, t.pulledAt ?? 0), o = u(e), s = e.resetAt !== void 0 && t.resetAt !== void 0 ? Math.min(e.resetAt, t.resetAt) : void 0;
|
|
162
|
+
return Object.assign(O(e, t, m, n), {
|
|
163
|
+
...o > 0 ? { gen: o } : {},
|
|
164
|
+
cursor: i.cursor,
|
|
165
|
+
cursorRev: i.cursorRev,
|
|
166
|
+
headers: r,
|
|
167
|
+
...e.hasOlderHeaders || t.hasOlderHeaders ? { hasOlderHeaders: !0 } : {},
|
|
168
|
+
...a > 0 ? { pulledAt: a } : {},
|
|
169
|
+
...s === void 0 ? {} : { resetAt: s },
|
|
170
|
+
...i.rescanning ? { rescanning: !0 } : {}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
function j(e, t, n) {
|
|
174
|
+
if (!e) return t;
|
|
175
|
+
let r = e.serverId ?? t.serverId;
|
|
176
|
+
return Object.assign(O(e, t, h, n), {
|
|
177
|
+
scopeKey: e.scopeKey,
|
|
178
|
+
at: Math.min(e.at, t.at),
|
|
179
|
+
confirmed: e.confirmed || t.confirmed,
|
|
180
|
+
...r ? { serverId: r } : {}
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
function M(e) {
|
|
184
|
+
let t = e.outbox.filter((t) => !(t.id in e.doneItemIds) && !(t.type === "save" && t.convKey in e.tombstones)), n = e.scopes;
|
|
185
|
+
for (let [t, r] of Object.entries(e.tombstones)) {
|
|
186
|
+
let e = n[r.scopeKey];
|
|
187
|
+
if (!e || !(t in e.headers)) continue;
|
|
188
|
+
let i = { ...e.headers };
|
|
189
|
+
delete i[t], n = {
|
|
190
|
+
...n,
|
|
191
|
+
[r.scopeKey]: {
|
|
192
|
+
...e,
|
|
193
|
+
headers: i
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
return t.length === e.outbox.length && n === e.scopes ? e : {
|
|
198
|
+
...e,
|
|
199
|
+
outbox: t,
|
|
200
|
+
scopes: n
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
function N(e, t, n) {
|
|
204
|
+
let r = {};
|
|
205
|
+
for (let i of new Set([...Object.keys(e.scopes), ...Object.keys(t.scopes)])) r[i] = k(A(e.scopes[i], t.scopes[i], n));
|
|
206
|
+
let i = { ...e.doneItemIds };
|
|
207
|
+
for (let [e, n] of Object.entries(t.doneItemIds)) i[e] = Math.max(i[e] ?? 0, n);
|
|
208
|
+
let a = { ...e.tombstones };
|
|
209
|
+
for (let [e, r] of Object.entries(t.tombstones)) a[e] = j(a[e], r, n);
|
|
210
|
+
let o = /* @__PURE__ */ new Map();
|
|
211
|
+
for (let n of [...e.outbox, ...t.outbox]) {
|
|
212
|
+
let e = o.get(n.id);
|
|
213
|
+
(!e || n.attempts > e.attempts) && o.set(n.id, n);
|
|
214
|
+
}
|
|
215
|
+
if (n === "stored") for (let e of t.outbox) {
|
|
216
|
+
let t = o.get(e.id);
|
|
217
|
+
if (!t || t === e) continue;
|
|
218
|
+
let n = t.type === "save" ? _ : v;
|
|
219
|
+
o.set(e.id, b(t, e, n));
|
|
220
|
+
}
|
|
221
|
+
return M({
|
|
222
|
+
v: 1,
|
|
223
|
+
scopes: r,
|
|
224
|
+
outbox: [...o.values()],
|
|
225
|
+
doneItemIds: i,
|
|
226
|
+
tombstones: a
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
function P(e) {
|
|
230
|
+
return N(e.memory, e.stored, "stored");
|
|
231
|
+
}
|
|
232
|
+
function F(e, t) {
|
|
233
|
+
return N(e, t, "either");
|
|
234
|
+
}
|
|
235
|
+
function I(e, t) {
|
|
236
|
+
let n = Object.fromEntries(Object.entries(e.doneItemIds).filter(([, e]) => t - e < o)), r = Object.entries(e.tombstones).filter(([, e]) => !e.confirmed || t - e.at < 2592e6);
|
|
237
|
+
if (r.length > 1e3) {
|
|
238
|
+
let e = r.filter(([, e]) => !e.confirmed), t = r.filter(([, e]) => e.confirmed).sort(([e, t], [n, r]) => r.at - t.at || (e < n ? -1 : Number(e > n))).slice(0, Math.max(0, a - e.length));
|
|
239
|
+
r = [...e, ...t];
|
|
240
|
+
}
|
|
241
|
+
return {
|
|
242
|
+
...e,
|
|
243
|
+
doneItemIds: n,
|
|
244
|
+
tombstones: Object.fromEntries(r)
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
function L(e) {
|
|
248
|
+
if (e === null) return null;
|
|
249
|
+
try {
|
|
250
|
+
let t = JSON.parse(e);
|
|
251
|
+
return d(t) && d(t.state) ? t.state : null;
|
|
252
|
+
} catch {
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
function R(e) {
|
|
257
|
+
return d(e) && typeof e.v == "number" && e.v > 1;
|
|
258
|
+
}
|
|
259
|
+
function z(e, t) {
|
|
260
|
+
if (e.v !== 1) return { ...t };
|
|
261
|
+
let n = Array.isArray(e.outbox) ? e.outbox : [], r = (e) => d(e) && typeof e.id == "string" && e.id in t.doneItemIds, i = new Set(t.outbox.map((e) => e.id)), a = /* @__PURE__ */ new Map(), o = null;
|
|
262
|
+
for (let e of n) {
|
|
263
|
+
if (S(e)) {
|
|
264
|
+
i.has(e.id) && (o = e.id);
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
r(e) || a.set(o, [...a.get(o) ?? [], e]);
|
|
268
|
+
}
|
|
269
|
+
if (a.size === 0) return {
|
|
270
|
+
...e,
|
|
271
|
+
...t
|
|
272
|
+
};
|
|
273
|
+
let s = [...a.get(null) ?? []];
|
|
274
|
+
for (let e of t.outbox) s.push(e, ...a.get(e.id) ?? []);
|
|
275
|
+
return {
|
|
276
|
+
...e,
|
|
277
|
+
...t,
|
|
278
|
+
outbox: s
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
function B(e, t, n, r) {
|
|
282
|
+
return {
|
|
283
|
+
getItem(t) {
|
|
284
|
+
let n = L(e.getItem(t));
|
|
285
|
+
return r.newer = R(n), n === null || r.newer ? null : {
|
|
286
|
+
state: T(n),
|
|
287
|
+
version: 0
|
|
288
|
+
};
|
|
289
|
+
},
|
|
290
|
+
setItem(i, a) {
|
|
291
|
+
let o = L(e.peekItem(i));
|
|
292
|
+
if (R(o)) {
|
|
293
|
+
r.newer = !0;
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
let s = o ? T(o) : null, c = I(s ? P({
|
|
297
|
+
memory: a.state,
|
|
298
|
+
stored: s
|
|
299
|
+
}) : a.state, t());
|
|
300
|
+
e.setItem(i, JSON.stringify({
|
|
301
|
+
state: o ? z(o, c) : c,
|
|
302
|
+
version: 0
|
|
303
|
+
})), e.isCurrent(i) && n(e.lastWriteFailed());
|
|
304
|
+
},
|
|
305
|
+
removeItem(t) {
|
|
306
|
+
e.removeItem(t);
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
function V(e) {
|
|
311
|
+
return {
|
|
312
|
+
v: 1,
|
|
313
|
+
scopes: e.scopes,
|
|
314
|
+
outbox: e.outbox,
|
|
315
|
+
doneItemIds: e.doneItemIds,
|
|
316
|
+
tombstones: e.tombstones
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
function H(e, t, n) {
|
|
320
|
+
let r = { ...e.headers };
|
|
321
|
+
for (let [e, i] of Object.entries(t)) {
|
|
322
|
+
if (e in n) continue;
|
|
323
|
+
let t = r[e];
|
|
324
|
+
r[e] = t ? E(t, i) : i;
|
|
325
|
+
}
|
|
326
|
+
return k({
|
|
327
|
+
...e,
|
|
328
|
+
headers: r
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
function U(e, i, a, o) {
|
|
332
|
+
return t()(n((e, t) => ({
|
|
333
|
+
...c(),
|
|
334
|
+
enqueueHistoryItem: (t) => e((e) => t.id in e.doneItemIds || e.outbox.some((e) => e.id === t.id) || t.type === "save" && t.convKey in e.tombstones ? {} : { outbox: [...e.outbox, t] }),
|
|
335
|
+
updateHistoryItem: (t, n) => e((e) => {
|
|
336
|
+
let r = e.outbox.findIndex((e) => e.id === t), i = e.outbox[r];
|
|
337
|
+
if (!i) return {};
|
|
338
|
+
let a = n(i);
|
|
339
|
+
if (a.id !== i.id || a.type !== i.type) return {};
|
|
340
|
+
let o = [...e.outbox];
|
|
341
|
+
return o[r] = a, { outbox: o };
|
|
342
|
+
}),
|
|
343
|
+
completeHistoryItems: (t, n) => e((e) => {
|
|
344
|
+
if (t.length === 0) return {};
|
|
345
|
+
let r = { ...e.doneItemIds };
|
|
346
|
+
for (let e of t) r[e] = n;
|
|
347
|
+
return M({
|
|
348
|
+
...V(e),
|
|
349
|
+
doneItemIds: r
|
|
350
|
+
});
|
|
351
|
+
}),
|
|
352
|
+
dropHistoryItems: (t, n, r) => e((e) => {
|
|
353
|
+
let i = e.outbox.filter((e) => e.convKey === t && n(e)).map((e) => e.id);
|
|
354
|
+
if (i.length === 0) return {};
|
|
355
|
+
let a = { ...e.doneItemIds };
|
|
356
|
+
for (let e of i) a[e] = r;
|
|
357
|
+
return M({
|
|
358
|
+
...V(e),
|
|
359
|
+
doneItemIds: a
|
|
360
|
+
});
|
|
361
|
+
}),
|
|
362
|
+
recordHistoryDelete: (t, n, r) => e((e) => {
|
|
363
|
+
let i = r && !(r.id in e.doneItemIds) && !e.outbox.some((e) => e.id === r.id);
|
|
364
|
+
return M({
|
|
365
|
+
...V(e),
|
|
366
|
+
outbox: i ? [...e.outbox, r] : e.outbox,
|
|
367
|
+
tombstones: {
|
|
368
|
+
...e.tombstones,
|
|
369
|
+
[t]: j(e.tombstones[t], n, "either")
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
}),
|
|
373
|
+
recordHistoryTombstone: (t, n) => e((e) => M({
|
|
374
|
+
...V(e),
|
|
375
|
+
tombstones: {
|
|
376
|
+
...e.tombstones,
|
|
377
|
+
[t]: j(e.tombstones[t], n, "either")
|
|
378
|
+
}
|
|
379
|
+
})),
|
|
380
|
+
applyHistoryFeedPage: (n, r) => {
|
|
381
|
+
let i = t().scopes[n];
|
|
382
|
+
return u(i) === r.gen ? (e((e) => {
|
|
383
|
+
let t = e.scopes[n] ?? l(r.gen), i = { ...e.tombstones };
|
|
384
|
+
for (let [e, { serverId: t }] of Object.entries(r.deleted)) i[e] = j(i[e], {
|
|
385
|
+
scopeKey: n,
|
|
386
|
+
at: r.at,
|
|
387
|
+
confirmed: !0,
|
|
388
|
+
serverId: t
|
|
389
|
+
}, "either");
|
|
390
|
+
let a = r.cursorRev >= t.cursorRev, o = {
|
|
391
|
+
...H(t, r.headers, i),
|
|
392
|
+
...a ? {
|
|
393
|
+
cursor: r.cursor,
|
|
394
|
+
cursorRev: r.cursorRev
|
|
395
|
+
} : {},
|
|
396
|
+
pulledAt: r.at
|
|
397
|
+
};
|
|
398
|
+
return r.last && delete o.rescanning, M({
|
|
399
|
+
...V(e),
|
|
400
|
+
scopes: {
|
|
401
|
+
...e.scopes,
|
|
402
|
+
[n]: o
|
|
403
|
+
},
|
|
404
|
+
tombstones: i
|
|
405
|
+
});
|
|
406
|
+
}), !0) : !1;
|
|
407
|
+
},
|
|
408
|
+
applyHistoryHeaders: (t, n) => e((e) => {
|
|
409
|
+
let r = e.scopes[t] ?? l();
|
|
410
|
+
return { scopes: {
|
|
411
|
+
...e.scopes,
|
|
412
|
+
[t]: H(r, n, e.tombstones)
|
|
413
|
+
} };
|
|
414
|
+
}),
|
|
415
|
+
markHistoryHeaderGone: (t, n) => e((e) => {
|
|
416
|
+
let r = e.scopes[t], i = r?.headers[n];
|
|
417
|
+
return !r || !i || i.gone ? {} : { scopes: {
|
|
418
|
+
...e.scopes,
|
|
419
|
+
[t]: {
|
|
420
|
+
...r,
|
|
421
|
+
headers: {
|
|
422
|
+
...r.headers,
|
|
423
|
+
[n]: {
|
|
424
|
+
...i,
|
|
425
|
+
gone: !0
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
} };
|
|
430
|
+
}),
|
|
431
|
+
resetHistoryScope: (n, r) => {
|
|
432
|
+
let i = u(t().scopes[n]) + 1;
|
|
433
|
+
return e((e) => ({ scopes: {
|
|
434
|
+
...e.scopes,
|
|
435
|
+
[n]: {
|
|
436
|
+
...l(i),
|
|
437
|
+
resetAt: r,
|
|
438
|
+
rescanning: !0
|
|
439
|
+
}
|
|
440
|
+
} })), i;
|
|
441
|
+
},
|
|
442
|
+
pruneHistory: (t) => e((e) => I(V(e), t))
|
|
443
|
+
}), {
|
|
444
|
+
name: r,
|
|
445
|
+
storage: B(e, i, a, o),
|
|
446
|
+
partialize: (e) => V(e),
|
|
447
|
+
skipHydration: !0,
|
|
448
|
+
merge: (e, t) => ({
|
|
449
|
+
...t,
|
|
450
|
+
...P({
|
|
451
|
+
memory: V(t),
|
|
452
|
+
stored: T(e)
|
|
453
|
+
})
|
|
454
|
+
})
|
|
455
|
+
}));
|
|
456
|
+
}
|
|
457
|
+
function W(e, t = {}) {
|
|
458
|
+
let n = null, i = !1, a = (e) => {
|
|
459
|
+
if (!(!n || e && i)) {
|
|
460
|
+
if (!e) {
|
|
461
|
+
n(!1);
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
i = !0;
|
|
465
|
+
try {
|
|
466
|
+
n(!0);
|
|
467
|
+
} catch {} finally {
|
|
468
|
+
i = !1;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
}, o = { newer: !1 }, s = U(e, t.now ?? Date.now, a, o);
|
|
472
|
+
return {
|
|
473
|
+
useStore: s,
|
|
474
|
+
boundKey: () => e.boundKey(),
|
|
475
|
+
isBoundToActiveProfile: () => e.isCurrent("hb-ai-assistant-history") && !o.newer,
|
|
476
|
+
heldByNewerBuild: () => e.isCurrent("hb-ai-assistant-history") && o.newer,
|
|
477
|
+
activeProfileKey: () => e.activeKey(r),
|
|
478
|
+
async rebind() {
|
|
479
|
+
e.unbind(), o.newer = !1, s.setState(c()), await s.persist.rehydrate();
|
|
480
|
+
},
|
|
481
|
+
handleStorageEvent(t) {
|
|
482
|
+
t === null || t !== e.boundKey() || e.isCurrent("hb-ai-assistant-history") && s.persist.rehydrate();
|
|
483
|
+
},
|
|
484
|
+
persistFailing: () => e.lastWriteFailed(),
|
|
485
|
+
flush() {
|
|
486
|
+
if (!e.isCurrent("hb-ai-assistant-history") || o.newer) return !1;
|
|
487
|
+
let t = s.persist.getOptions().storage;
|
|
488
|
+
return t ? (t.setItem(r, {
|
|
489
|
+
state: V(s.getState()),
|
|
490
|
+
version: 0
|
|
491
|
+
}), !o.newer && !e.lastWriteFailed()) : !1;
|
|
492
|
+
},
|
|
493
|
+
setWriteListener(e) {
|
|
494
|
+
n = e;
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
var G = W(e({ onRefused: (e, t) => {
|
|
499
|
+
e !== "unbound" && console.warn(`[assistant] history not saved on this device (${e})`, t ?? "");
|
|
500
|
+
} })), K = G.useStore;
|
|
501
|
+
typeof window < "u" && typeof window.addEventListener == "function" && window.addEventListener("storage", (e) => G.handleStorageEvent(e.key));
|
|
502
|
+
//#endregion
|
|
503
|
+
export { o as ASSISTANT_HISTORY_DONE_TTL_MS, i as ASSISTANT_HISTORY_MAX_HEADERS, a as ASSISTANT_HISTORY_MAX_TOMBSTONES, r as ASSISTANT_HISTORY_STORAGE_NAME, s as ASSISTANT_HISTORY_TOMBSTONE_TTL_MS, G as assistantHistoryStore, k as boundAssistantHistoryHeaders, W as createAssistantHistoryStore, c as emptyAssistantHistoryPersisted, l as emptyAssistantHistoryScopeState, R as isNewerAssistantHistoryFormat, F as mergeAssistantHistoryPersisted, P as mergeAssistantHistoryWithStored, I as pruneAssistantHistoryPersisted, T as readAssistantHistoryPersisted, M as settleAssistantHistory, K as useAssistantHistoryStore };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Timestamps as server history carries them (BOFF-7335).
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* A GraphQL `DateTime` as an ISO string. The service registers no scalar
|
|
6
|
+
* resolver, so the wire form is whatever its runtime serialised — an ISO
|
|
7
|
+
* string today, but an epoch number (or its string) is accepted rather than
|
|
8
|
+
* trusted to never happen.
|
|
9
|
+
*/
|
|
10
|
+
export declare function historyTimestampToIso(value: unknown): string | null;
|
|
11
|
+
//# sourceMappingURL=historyTimestamps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"historyTimestamps.d.ts","sourceRoot":"","sources":["../../../../src/shared/assistant/history/historyTimestamps.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAOnE"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/shared/assistant/history/historyTimestamps.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
if (typeof e == "number" && Number.isFinite(e)) return new Date(e).toISOString();
|
|
4
|
+
if (typeof e != "string" || e.length === 0) return null;
|
|
5
|
+
let t = /^\d+$/.test(e) ? Number(e) : Date.parse(e);
|
|
6
|
+
return Number.isFinite(t) ? new Date(t).toISOString() : null;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { e as historyTimestampToIso };
|