@burdenoff/microfe-bigconsole 2026.713.7 → 2026.714.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.
@@ -1,22 +1,23 @@
1
- import { createAssistantSandbox as e, createAssistantSession as t, deleteAssistantSession as n, extendAssistantSandboxTTL as r, findExistingSandbox as i, getAssistantMessages as a, listAssistantSessions as o, sendAssistantPromptAsync as s, waitForAssistantServiceReady as c, waitForSandboxReady as l } from "./assistantApi.js";
2
- import { gatherPageContext as u } from "./pageContext.js";
1
+ import { createAssistantSandbox as e, createAssistantSession as t, extendAssistantSandboxTTL as n, findExistingSandbox as r, getAssistantMessages as i, sendAssistantPromptAsync as a, waitForAssistantServiceReady as o, waitForSandboxReady as s } from "./assistantApi.js";
2
+ import { deleteAssistantConversation as c, getAssistantConversationMessages as l, listAssistantConversations as u, saveAssistantTurn as ee } from "./conversationHistoryApi.js";
3
+ import { gatherPageContext as te } from "./pageContext.js";
3
4
  import { useCallback as d, useMemo as f, useRef as p } from "react";
4
5
  import { useAuthToken as m } from "@burdenoff/fe-libs/shared/providers/shell";
5
6
  //#region src/bigconsole/assistant/createSandboxAssistantTransport.ts
6
- var h = "api-calls", g = 42e4, _ = 1500, v = 3e4, y = 200, b = 15, x = 8, S = "bc-assistant-sandbox-id", C = "bc-assistant-session-id";
7
- function w(e) {
7
+ var h = "api-calls", ne = 42e4, re = 1500, ie = 3e4, g = 200, _ = 25, v = 6e3, y = "bc-assistant-sandbox-id", b = "bc-assistant-session-id", x = "bc-assistant-conversation-id";
8
+ function S(e) {
8
9
  try {
9
10
  return window.sessionStorage.getItem(e);
10
11
  } catch {
11
12
  return null;
12
13
  }
13
14
  }
14
- function T(e, t) {
15
+ function C(e, t) {
15
16
  try {
16
17
  t ? window.sessionStorage.setItem(e, t) : window.sessionStorage.removeItem(e);
17
18
  } catch {}
18
19
  }
19
- function E(e) {
20
+ function w(e) {
20
21
  try {
21
22
  let t = e === "workspaceId" ? "burdenoff-active-context-workspace" : "burdenoff-active-context-organization", n = localStorage.getItem(t);
22
23
  if (n) return n;
@@ -28,16 +29,16 @@ function E(e) {
28
29
  return "";
29
30
  }
30
31
  }
31
- function D(e) {
32
- return new URLSearchParams(window.location.search).get("workspace") ?? E("workspaceId") ?? e ?? "";
32
+ function T(e) {
33
+ return new URLSearchParams(window.location.search).get("workspace") ?? w("workspaceId") ?? e ?? "";
33
34
  }
34
- function O() {
35
- return new URLSearchParams(window.location.search).get("org") ?? E("organizationId");
35
+ function E() {
36
+ return new URLSearchParams(window.location.search).get("org") ?? w("organizationId");
36
37
  }
37
- function k(e) {
38
+ function D(e) {
38
39
  return e.info?.role ?? e.role;
39
40
  }
40
- function A(e) {
41
+ function O(e) {
41
42
  let t = e.info?.time?.created;
42
43
  if (t !== void 0) return t;
43
44
  let n = e.createdAt;
@@ -48,7 +49,7 @@ function A(e) {
48
49
  }
49
50
  return n;
50
51
  }
51
- function j(e) {
52
+ function k(e) {
52
53
  let t = e.info?.time?.completed;
53
54
  if (t !== void 0) return t;
54
55
  let n = e.completedAt;
@@ -60,10 +61,10 @@ function j(e) {
60
61
  return n;
61
62
  }
62
63
  }
63
- function M(e) {
64
+ function A(e) {
64
65
  return (e.parts ?? [] ?? []).filter((e) => e.type === "text" && typeof e.text == "string").map((e) => e.text?.trim() ?? "").filter(Boolean).join("\n") || (typeof e.content == "string" ? e.content.trim() : "");
65
66
  }
66
- var N = {
67
+ var j = {
67
68
  bash: "Running a command",
68
69
  webfetch: "Fetching a page",
69
70
  "file.read": "Reading files",
@@ -74,39 +75,39 @@ var N = {
74
75
  todowrite: "Planning the steps",
75
76
  todoread: "Reviewing the plan"
76
77
  };
77
- function P(e) {
78
+ function M(e) {
78
79
  return typeof e == "object" && e ? e : void 0;
79
80
  }
80
- function F(e) {
81
- let t = e.tool ?? "tool", n = P(e.state?.input), r = n?.description;
81
+ function N(e) {
82
+ let t = e.tool ?? "tool", n = M(e.state?.input), r = n?.description;
82
83
  if (typeof r == "string" && r.trim()) return r.trim();
83
84
  let i = n?.todos;
84
85
  if (Array.isArray(i)) {
85
- let e = P(i.find((e) => P(e)?.status === "in_progress") ?? i[0])?.content;
86
+ let e = M(i.find((e) => M(e)?.status === "in_progress") ?? i[0])?.content;
86
87
  if (typeof e == "string" && e.trim()) return e.trim();
87
88
  }
88
- return N[t] ?? `Running ${t}`;
89
+ return j[t] ?? `Running ${t}`;
89
90
  }
90
- function I(e) {
91
+ function P(e) {
91
92
  return (e.parts ?? []).filter((e) => e.type === "tool" && e.tool).map((e) => {
92
- let t = e.state?.status ?? "running", n = F(e);
93
+ let t = e.state?.status ?? "running", n = N(e);
93
94
  return t === "completed" ? `✓ ${n}` : t === "failed" ? `⚠ ${n}` : `⏳ ${n}…`;
94
95
  });
95
96
  }
96
- function L(e, t, n, r) {
97
- let i = e.filter((e) => k(e) === "assistant" && A(e) >= t).sort((e, t) => A(e) - A(t));
97
+ function F(e, t, n, r) {
98
+ let i = e.filter((e) => D(e) === "assistant" && O(e) >= t).sort((e, t) => O(e) - O(t));
98
99
  i.length === 0 && e.length > 0 && console.log("[BigConsole-Assistant] buildProgress: no relevant messages", {
99
100
  totalMessages: e.length,
100
101
  sinceMs: t,
101
- messageRoles: e.map((e) => k(e)),
102
- messageTimestamps: e.map((e) => A(e))
102
+ messageRoles: e.map((e) => D(e)),
103
+ messageTimestamps: e.map((e) => O(e))
103
104
  });
104
105
  let a, o;
105
106
  if (i.length === 0) a = "", o = n === a && r !== void 0 && Date.now() - r >= 15e3;
106
107
  else {
107
- let e = i[i.length - 1], t = i.map(M).filter(Boolean), s = I(e);
108
+ let e = i[i.length - 1], t = i.map(A).filter(Boolean), s = P(e);
108
109
  a = [...t, ...s].join("\n\n");
109
- let c = !!j(e) && a.length > 0, l = (e.parts ?? []).some((e) => e.type === "tool" && e.state?.status !== "completed" && e.state?.status !== "failed"), u = !c && !l && n === a && r !== void 0 && Date.now() - r >= 45e3;
110
+ let c = !!k(e) && a.length > 0, l = (e.parts ?? []).some((e) => e.type === "tool" && e.state?.status !== "completed" && e.state?.status !== "failed"), u = !c && !l && n === a && r !== void 0 && Date.now() - r >= 45e3;
110
111
  o = c || u;
111
112
  }
112
113
  return {
@@ -114,56 +115,10 @@ function L(e, t, n, r) {
114
115
  done: o
115
116
  };
116
117
  }
117
- function R(e) {
118
- return e.info?.id ?? e.id;
119
- }
120
- var z = ["[Context file:", "User's current context:"];
121
- function B(e) {
122
- let t = e.trimStart();
123
- return z.some((e) => t.startsWith(e));
124
- }
125
- function V(e) {
126
- let t = [...e].sort((e, t) => A(e) - A(t)), n = [], r = null, i = [], a = () => {
127
- let e = r;
128
- e && (n.push({
129
- id: e.id,
130
- role: "user",
131
- content: e.content
132
- }), i.length > 0 && n.push({
133
- id: `${e.id}:reply`,
134
- role: "assistant",
135
- content: G(i.join("\n\n"))
136
- }), r = null, i = []);
137
- };
138
- for (let e of t) {
139
- let t = k(e), o = M(e);
140
- if (t === "user") {
141
- if (!o || B(o)) continue;
142
- a(), r = {
143
- id: R(e) ?? `user-${String(n.length)}`,
144
- content: o
145
- };
146
- } else t === "assistant" && r && o && i.push(o);
147
- }
148
- return a(), n;
149
- }
150
- var H = /^AI Assistant\s*[—-]/i, U = 60;
151
- async function W(e, t, n, r) {
152
- let i = n.title?.trim();
153
- if (i && !H.test(i)) return i;
154
- try {
155
- let i = [...await a(e, t, n.id, r, x)].sort((e, t) => A(e) - A(t)).filter((e) => k(e) === "user").map(M).find((e) => e && !B(e));
156
- if (!i) return "New chat";
157
- let o = i.replace(/\s+/g, " ").trim();
158
- return o.length > U ? `${o.slice(0, U - 1)}…` : o;
159
- } catch {
160
- return i || "Untitled chat";
161
- }
162
- }
163
- function G(e) {
118
+ function I(e) {
164
119
  return e.replace(/(Authorization\s*:\s*Bearer\s+)[^\s\n]+/gi, "$1[REDACTED]").replace(/(X-Workspace-Authorization\s*:\s*Bearer\s+)[^\s\n]+/gi, "$1[REDACTED]").replace(/\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9._-]+\.[A-Za-z0-9._-]+\b/g, "[REDACTED_JWT]").replace(/\bsk-ant-[A-Za-z0-9-]+\b/g, "[REDACTED_API_KEY]");
165
120
  }
166
- function K(e) {
121
+ function ae(e) {
167
122
  let t = e instanceof Error ? e.message.toLowerCase() : String(e).toLowerCase();
168
123
  return t.includes("rate limit exceeded") || t.includes("unauthorized") || t.includes("k8s api error 401") ? !1 : [
169
124
  "sandbox not found",
@@ -184,232 +139,233 @@ function K(e) {
184
139
  "unexpected error"
185
140
  ].some((e) => t.includes(e));
186
141
  }
187
- function q() {
188
- let { getAccessToken: x, getWorkspaceToken: E, userId: j, workspaceId: M } = m(), [N, P] = f(() => [w(S), w(C)], []), F = p(N), I = p(P), R = p(/* @__PURE__ */ new Map()), z = d((e) => {
189
- F.current = e, T(S, e);
190
- }, []), B = d((e) => {
191
- I.current = e, T(C, e);
192
- }, []), H = d(async (n, r) => {
193
- let a = F.current;
142
+ function L() {
143
+ let { getAccessToken: w, getWorkspaceToken: k, userId: A, workspaceId: j } = m(), [M, N, P] = f(() => [
144
+ S(y),
145
+ S(b),
146
+ S(x)
147
+ ], []), L = p(M), R = p(N), z = p(P), B = p(null), V = d((e) => {
148
+ L.current = e, C(y, e);
149
+ }, []), H = d((e) => {
150
+ R.current = e, C(b, e);
151
+ }, []), U = d((e) => {
152
+ z.current = e, C(x, e);
153
+ }, []), W = d(async (n, i) => {
154
+ let a = L.current;
194
155
  if (console.log("[BigConsole-Assistant] ensureRuntime start", {
195
156
  sandboxId: a,
196
157
  workspaceId: n
197
158
  }), !a) {
198
- if (!x()) throw Error("The assistant requires an authenticated session. Please sign in again.");
199
- if (console.log("[BigConsole-Assistant] findExistingSandbox called"), a = await i(n, h, r), console.log("[BigConsole-Assistant] findExistingSandbox result", { sandboxId: a }), a) try {
200
- console.log("[BigConsole-Assistant] waitForSandboxReady called (reused)", { sandboxId: a }), await l(a, n, r), console.log("[BigConsole-Assistant] waitForSandboxReady done (reused)", { sandboxId: a }), console.log("[BigConsole-Assistant] waitForAssistantServiceReady called (reused)", { sandboxId: a }), await c(a, n, h, r), console.log("[BigConsole-Assistant] waitForAssistantServiceReady done (reused)", { sandboxId: a });
159
+ if (!w()) throw Error("The assistant requires an authenticated session. Please sign in again.");
160
+ if (console.log("[BigConsole-Assistant] findExistingSandbox called"), a = await r(n, h, i), console.log("[BigConsole-Assistant] findExistingSandbox result", { sandboxId: a }), a) try {
161
+ console.log("[BigConsole-Assistant] waitForSandboxReady called (reused)", { sandboxId: a }), await s(a, n, i), console.log("[BigConsole-Assistant] waitForSandboxReady done (reused)", { sandboxId: a }), console.log("[BigConsole-Assistant] waitForAssistantServiceReady called (reused)", { sandboxId: a }), await o(a, n, h, i), console.log("[BigConsole-Assistant] waitForAssistantServiceReady done (reused)", { sandboxId: a });
201
162
  } catch (e) {
202
163
  console.warn("[BigConsole-Assistant] existing sandbox unusable, falling back to fresh sandbox", {
203
164
  sandboxId: a,
204
165
  error: e instanceof Error ? e.message : String(e)
205
166
  }), a = null;
206
167
  }
207
- a || (console.log("[BigConsole-Assistant] createAssistantSandbox called"), a = await e(h, n, r), console.log("[BigConsole-Assistant] createAssistantSandbox result", { sandboxId: a }), console.log("[BigConsole-Assistant] waitForSandboxReady called (fresh)", { sandboxId: a }), await l(a, n, r), console.log("[BigConsole-Assistant] waitForSandboxReady done (fresh)", { sandboxId: a }), console.log("[BigConsole-Assistant] waitForAssistantServiceReady called (fresh)", { sandboxId: a }), await c(a, n, h, r), console.log("[BigConsole-Assistant] waitForAssistantServiceReady done (fresh)", { sandboxId: a })), z(a);
168
+ a || (console.log("[BigConsole-Assistant] createAssistantSandbox called"), a = await e(h, n, i), console.log("[BigConsole-Assistant] createAssistantSandbox result", { sandboxId: a }), console.log("[BigConsole-Assistant] waitForSandboxReady called (fresh)", { sandboxId: a }), await s(a, n, i), console.log("[BigConsole-Assistant] waitForSandboxReady done (fresh)", { sandboxId: a }), console.log("[BigConsole-Assistant] waitForAssistantServiceReady called (fresh)", { sandboxId: a }), await o(a, n, h, i), console.log("[BigConsole-Assistant] waitForAssistantServiceReady done (fresh)", { sandboxId: a })), V(a);
208
169
  }
209
- let o = I.current;
170
+ let c = R.current;
210
171
  return console.log("[BigConsole-Assistant] session check", {
211
- sessionId: o,
172
+ sessionId: c,
212
173
  sandboxId: a
213
- }), o || (console.log("[BigConsole-Assistant] createAssistantSession called", {
174
+ }), c || (console.log("[BigConsole-Assistant] createAssistantSession called", {
214
175
  sandboxId: a,
215
176
  workspaceId: n
216
- }), o = (await t(a, n, h, r)).sessionId, B(o)), {
177
+ }), c = (await t(a, n, h, i)).sessionId, H(c)), {
217
178
  sandboxId: a,
218
- sessionId: o
179
+ sessionId: c
219
180
  };
220
- }, [x]), U = d(async ({ prompt: e, onProgress: t, signal: n }) => {
221
- let i = D(M);
181
+ }, [w]), G = d(async ({ prompt: e, onProgress: t, signal: r }) => {
182
+ let o = T(j);
222
183
  if (console.log("[BigConsole-Assistant] sendPrompt called", {
223
184
  promptLength: e.length,
224
- workspaceId: i,
225
- hasCtxWorkspaceId: !!M,
185
+ workspaceId: o,
186
+ hasCtxWorkspaceId: !!j,
226
187
  authContextKeys: {
227
- hasAccessToken: !!x(),
228
- hasWorkspaceToken: !!E(),
229
- hasUserId: !!j
188
+ hasAccessToken: !!w(),
189
+ hasWorkspaceToken: !!k(),
190
+ hasUserId: !!A
230
191
  },
231
192
  locationSearch: window.location.search
232
- }), !i) throw Error("The assistant needs an active workspace. Open a workspace and try again.");
233
- let o = {
234
- accessToken: x(),
235
- workspaceToken: E(),
236
- userId: j,
237
- organizationId: O()
193
+ }), !o) throw Error("The assistant needs an active workspace. Open a workspace and try again.");
194
+ let s = {
195
+ accessToken: w(),
196
+ workspaceToken: k(),
197
+ userId: A,
198
+ organizationId: E()
238
199
  };
239
200
  console.log("[BigConsole-Assistant] authContext prepared", {
240
- hasAccessToken: !!o.accessToken,
241
- hasWorkspaceToken: !!o.workspaceToken,
242
- hasUserId: !!o.userId,
243
- hasOrgId: !!o.organizationId
201
+ hasAccessToken: !!s.accessToken,
202
+ hasWorkspaceToken: !!s.workspaceToken,
203
+ hasUserId: !!s.userId,
204
+ hasOrgId: !!s.organizationId
244
205
  });
245
206
  let c = async (l) => {
246
207
  try {
247
208
  console.log("[BigConsole-Assistant] run attempt", l);
248
- let { sandboxId: c, sessionId: d } = await H(i, o);
209
+ let { sandboxId: c, sessionId: u } = await W(o, s);
249
210
  console.log("[BigConsole-Assistant] ensureRuntime resolved", {
250
211
  sandboxId: c,
251
- sessionId: d
212
+ sessionId: u
252
213
  });
253
- let f = Date.now();
214
+ let d = B.current, f = d ? `${d}\n\n---\n\n${e}` : e, p = Date.now();
254
215
  console.log("[BigConsole-Assistant] calling sendAssistantPromptAsync", {
255
216
  sandboxId: c,
256
- workspaceId: i,
257
- sessionId: d,
258
- promptLength: e.length
259
- }), await s(c, i, d, e, h, u(), o);
260
- let p = Date.now() + g, m = Date.now(), y = "", b = Date.now(), x = L([], f);
261
- for (; Date.now() < p;) {
262
- if (n.aborted) throw Error("Cancelled");
263
- let e = await a(c, i, d, o, 50);
217
+ workspaceId: o,
218
+ sessionId: u,
219
+ promptLength: f.length,
220
+ replayed: !!d
221
+ }), await a(c, o, u, f, h, te(), s);
222
+ let m = Date.now() + ne, g = Date.now(), _ = "", v = Date.now(), y = F([], p);
223
+ for (; Date.now() < m;) {
224
+ if (r.aborted) throw Error("Cancelled");
225
+ let e = await i(c, o, u, s, 50);
264
226
  if (console.log("[BigConsole-Assistant] poll", {
265
- elapsedMs: Date.now() - f,
227
+ elapsedMs: Date.now() - p,
266
228
  messageCount: e.length,
267
- firstFewRoles: e.slice(0, 3).map((e) => k(e)),
268
- firstFewTimestamps: e.slice(0, 3).map((e) => A(e))
269
- }), x = L(e, f, y, b), console.log("[BigConsole-Assistant] progress", {
270
- contentPreview: x.content.slice(0, 100),
271
- done: x.done,
272
- lastContentChangeAt: Date.now() - b
273
- }), x.content !== y && (y = x.content, b = Date.now()), t(G(x.content)), x.done) {
229
+ firstFewRoles: e.slice(0, 3).map((e) => D(e)),
230
+ firstFewTimestamps: e.slice(0, 3).map((e) => O(e))
231
+ }), y = F(e, p, _, v), console.log("[BigConsole-Assistant] progress", {
232
+ contentPreview: y.content.slice(0, 100),
233
+ done: y.done,
234
+ lastContentChangeAt: Date.now() - v
235
+ }), y.content !== _ && (_ = y.content, v = Date.now()), t(I(y.content)), y.done) {
274
236
  console.log("[BigConsole-Assistant] progress.done=true, breaking poll loop");
275
237
  break;
276
238
  }
277
- Date.now() - m > v && (await r(c, i, 600, o).catch(() => void 0), m = Date.now()), await new Promise((e) => setTimeout(e, _));
239
+ Date.now() - g > ie && (await n(c, o, 600, s).catch(() => void 0), g = Date.now()), await new Promise((e) => setTimeout(e, re));
240
+ }
241
+ if (!y.done) throw Error("I stopped waiting for a reply, but I may still be working — anything I already created will be there. Check your dashboards and data sinks before asking again, so you do not end up with duplicates.");
242
+ let b = I(y.content);
243
+ B.current = null;
244
+ try {
245
+ U((await ee({
246
+ conversationId: z.current,
247
+ prompt: e,
248
+ reply: b,
249
+ agentSessionId: u
250
+ }, o, s)).id);
251
+ } catch (e) {
252
+ console.warn("[BigConsole-Assistant] could not save turn to history", { error: e instanceof Error ? e.message : String(e) });
278
253
  }
279
- if (!x.done) throw Error("I stopped waiting for a reply, but I may still be working — anything I already created will be there. Check your dashboards and data sinks before asking again, so you do not end up with duplicates.");
280
- return { text: G(x.content) };
254
+ return { text: b };
281
255
  } catch (e) {
282
256
  if (console.error("[BigConsole-Assistant] run error", {
283
257
  attempt: l,
284
258
  error: e instanceof Error ? e.message : String(e),
285
259
  stack: e instanceof Error ? e.stack : void 0,
286
- sandboxId: F.current,
287
- sessionId: I.current
288
- }), l === 1 && K(e)) return z(null), B(null), c(2);
260
+ sandboxId: L.current,
261
+ sessionId: R.current
262
+ }), l === 1 && ae(e)) return V(null), H(null), c(2);
289
263
  throw e;
290
264
  }
291
265
  };
292
266
  return c(1);
293
267
  }, [
294
- M,
295
- H,
296
- x,
297
- E,
298
268
  j,
299
- z,
300
- B
301
- ]), q = d(async (e, t) => {
302
- if (F.current) return F.current;
303
- try {
304
- let n = await i(e, h, t);
305
- return n && z(n), n;
306
- } catch {
307
- return null;
308
- }
309
- }, [z]), J = d(async () => {
310
- let e = D(M);
311
- if (!e || !x()) return [];
312
- let t = {
313
- accessToken: x(),
314
- workspaceToken: E(),
315
- userId: j,
316
- organizationId: O()
317
- }, n = await q(e, t);
318
- if (!n) return [];
319
- let r = I.current;
320
- if (!r) try {
321
- let i = [...await o(n, e, t)].sort((e, t) => (t.time?.updated ?? t.time?.created ?? 0) - (e.time?.updated ?? e.time?.created ?? 0))[0];
322
- if (!i) return [];
323
- r = i.id, B(r);
324
- } catch {
325
- return [];
326
- }
269
+ W,
270
+ w,
271
+ k,
272
+ A,
273
+ V,
274
+ H,
275
+ U
276
+ ]), K = d(() => ({
277
+ accessToken: w(),
278
+ workspaceToken: k(),
279
+ userId: A,
280
+ organizationId: E()
281
+ }), [
282
+ w,
283
+ k,
284
+ A
285
+ ]), q = d((e) => e.length === 0 ? null : [
286
+ "You are resuming an earlier conversation. What follows is what was said in it — treat it as your own memory and continue seamlessly. Do not mention this replay, and do not redo work that was already completed.",
287
+ "--- earlier in this conversation ---",
288
+ e.map((e) => `${e.role === "user" ? "User" : "Assistant"}: ${e.content}`).join("\n\n").slice(-v),
289
+ "--- end ---"
290
+ ].join("\n\n"), []), J = d((e) => e.map((e) => ({
291
+ id: e.id,
292
+ role: e.role === "ASSISTANT" ? "assistant" : "user",
293
+ content: I(e.content)
294
+ })), []), Y = d(async (e, t, n) => {
295
+ let r = J(await l(e.id, t, n, g));
296
+ return U(e.id), e.agentSessionId ? (H(e.agentSessionId), B.current = null) : (H(null), B.current = q(r)), r;
297
+ }, [
298
+ J,
299
+ U,
300
+ H,
301
+ q
302
+ ]), X = d(async () => {
303
+ let e = T(j);
304
+ if (!e || !w()) return [];
305
+ let t = K();
327
306
  try {
328
- return V(await a(n, e, r, t, y));
307
+ let n = await u(e, t, _), r = z.current, i = n.find((e) => e.id === r) ?? n[0];
308
+ return i ? await Y(i, e, t) : [];
329
309
  } catch (e) {
330
- return console.warn("[BigConsole-Assistant] could not restore history; starting fresh", {
331
- sandboxId: n,
332
- sessionId: r,
333
- error: e instanceof Error ? e.message : String(e)
334
- }), z(null), B(null), [];
310
+ return console.warn("[BigConsole-Assistant] could not restore history", { error: e instanceof Error ? e.message : String(e) }), [];
335
311
  }
336
312
  }, [
337
- M,
338
- x,
339
- E,
340
313
  j,
341
- z,
342
- B,
343
- q
344
- ]), Y = d(() => ({
345
- accessToken: x(),
346
- workspaceToken: E(),
347
- userId: j,
348
- organizationId: O()
349
- }), [
350
- x,
351
- E,
352
- j
353
- ]), X = d(async () => {
354
- let e = D(M);
355
- if (!e) return [];
356
- let t = Y(), n = await q(e, t);
357
- if (!n) return [];
314
+ w,
315
+ K,
316
+ Y
317
+ ]), Z = d(async () => {
318
+ let e = T(j);
319
+ if (!e || !w()) return [];
358
320
  try {
359
- let r = (await o(n, e, t)).map((e) => ({
360
- session: e,
361
- updatedAt: e.time?.updated ?? e.time?.created
362
- })).sort((e, t) => (t.updatedAt ?? 0) - (e.updatedAt ?? 0)).slice(0, b);
363
- return await Promise.all(r.map(async ({ session: r, updatedAt: i }) => {
364
- let a = R.current.get(r.id), o = a ?? await W(n, e, r, t);
365
- return !a && o !== "New chat" && R.current.set(r.id, o), {
366
- id: r.id,
367
- title: o,
368
- updatedAt: i,
369
- active: r.id === I.current
370
- };
321
+ return (await u(e, K(), _)).map((e) => ({
322
+ id: e.id,
323
+ title: e.title?.trim() || "New chat",
324
+ updatedAt: Date.parse(e.updatedAt) || void 0,
325
+ active: e.id === z.current
371
326
  }));
372
327
  } catch {
373
328
  return [];
374
329
  }
375
330
  }, [
376
- M,
377
- Y,
378
- q
379
- ]), Z = d(async () => (B(null), Promise.resolve()), [B]), Q = d(async (e) => {
380
- let t = F.current, r = D(M);
381
- !t || !r || (await n(t, r, e, Y()), R.current.delete(e), I.current === e && B(null));
331
+ j,
332
+ w,
333
+ K
334
+ ]), Q = d(async () => (U(null), H(null), B.current = null, Promise.resolve()), [U, H]), $ = d(async (e) => {
335
+ let t = T(j);
336
+ t && (await c(e, t, K()), z.current === e && (U(null), H(null), B.current = null));
382
337
  }, [
383
- M,
384
- Y,
385
- B
386
- ]), $ = d(async (e) => {
387
- let t = F.current, n = D(M);
388
- if (!t || !n) return [];
389
- let r = await a(t, n, e, Y(), y);
390
- return B(e), V(r);
338
+ j,
339
+ K,
340
+ U,
341
+ H
342
+ ]), oe = d(async (e) => {
343
+ let t = T(j);
344
+ if (!t) return [];
345
+ let n = K(), r = (await u(t, n, _)).find((t) => t.id === e);
346
+ return r ? Y(r, t, n) : [];
391
347
  }, [
392
- M,
393
- Y,
394
- B
348
+ j,
349
+ K,
350
+ Y
395
351
  ]);
396
352
  return f(() => ({
397
- sendPrompt: U,
398
- loadHistory: J,
399
- listSessions: X,
400
- newSession: Z,
401
- deleteSession: Q,
402
- selectSession: $
353
+ sendPrompt: G,
354
+ loadHistory: X,
355
+ listSessions: Z,
356
+ newSession: Q,
357
+ deleteSession: $,
358
+ selectSession: oe
403
359
  }), [
404
- U,
405
- J,
360
+ G,
406
361
  X,
407
362
  Z,
408
363
  Q,
409
- $
364
+ $,
365
+ oe
410
366
  ]);
411
367
  }
412
368
  //#endregion
413
- export { q as useSandboxAssistantTransport };
369
+ export { L as useSandboxAssistantTransport };
414
370
 
415
371
  //# sourceMappingURL=createSandboxAssistantTransport.js.map