@arbidocs/react 0.4.27 → 0.4.28

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/index.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var chunkKXIIARRK_cjs = require('./chunk-KXIIARRK.cjs');
4
- var chunkPGLV23SB_cjs = require('./chunk-PGLV23SB.cjs');
3
+ var chunk6BLXIF4R_cjs = require('./chunk-6BLXIF4R.cjs');
4
+ var chunkYSZJCWDD_cjs = require('./chunk-YSZJCWDD.cjs');
5
5
  var chunkVC2I4NST_cjs = require('./chunk-VC2I4NST.cjs');
6
6
  var chunkEOOHRPFM_cjs = require('./chunk-EOOHRPFM.cjs');
7
7
  var chunkOBNTJEEO_cjs = require('./chunk-OBNTJEEO.cjs');
@@ -9,12 +9,12 @@ var chunkS6A6FSG7_cjs = require('./chunk-S6A6FSG7.cjs');
9
9
  var chunkTMPDW7J5_cjs = require('./chunk-TMPDW7J5.cjs');
10
10
  var chunkZMTLGO3K_cjs = require('./chunk-ZMTLGO3K.cjs');
11
11
  var React = require('react');
12
+ var reactQuery = require('@tanstack/react-query');
12
13
  var browser = require('@arbidocs/sdk/browser');
13
14
  var lucideReact = require('lucide-react');
14
15
  var jsxRuntime = require('react/jsx-runtime');
15
16
  var client = require('@arbidocs/client');
16
17
  var zustand = require('zustand');
17
- var reactQuery = require('@tanstack/react-query');
18
18
  var diff = require('diff');
19
19
  var framerMotion = require('framer-motion');
20
20
  var reactDom = require('react-dom');
@@ -29,6 +29,319 @@ var React__default = /*#__PURE__*/_interopDefault(React);
29
29
  var ReactMarkdown__default = /*#__PURE__*/_interopDefault(ReactMarkdown);
30
30
  var Cropper__default = /*#__PURE__*/_interopDefault(Cropper);
31
31
 
32
+ function useUpdateConversation() {
33
+ const arbi = chunkZMTLGO3K_cjs.useArbi();
34
+ const qc = reactQuery.useQueryClient();
35
+ return reactQuery.useMutation({
36
+ mutationFn: ({
37
+ conversationId,
38
+ patch
39
+ }) => arbi.conversations.update(conversationId, patch),
40
+ onSuccess: () => qc.invalidateQueries({ queryKey: chunk6BLXIF4R_cjs.arbiQueryKeys.allConversations() })
41
+ });
42
+ }
43
+ function useCreateWork() {
44
+ const arbi = chunkZMTLGO3K_cjs.useArbi();
45
+ const qc = reactQuery.useQueryClient();
46
+ return reactQuery.useMutation({
47
+ mutationFn: (body) => arbi.conversations.createWork(body),
48
+ onSuccess: () => qc.invalidateQueries({ queryKey: chunk6BLXIF4R_cjs.arbiQueryKeys.allConversations() })
49
+ });
50
+ }
51
+ function useRunConversation() {
52
+ const arbi = chunkZMTLGO3K_cjs.useArbi();
53
+ const qc = reactQuery.useQueryClient();
54
+ return reactQuery.useMutation({
55
+ mutationFn: (conversationId) => arbi.conversations.runWithAuth(conversationId),
56
+ onSuccess: () => qc.invalidateQueries({ queryKey: chunk6BLXIF4R_cjs.arbiQueryKeys.allConversations() })
57
+ });
58
+ }
59
+ function useReviewConversation() {
60
+ const arbi = chunkZMTLGO3K_cjs.useArbi();
61
+ const qc = reactQuery.useQueryClient();
62
+ return reactQuery.useMutation({
63
+ mutationFn: ({
64
+ conversationId,
65
+ review
66
+ }) => arbi.conversations.review(conversationId, review),
67
+ onSuccess: () => qc.invalidateQueries({ queryKey: chunk6BLXIF4R_cjs.arbiQueryKeys.allConversations() })
68
+ });
69
+ }
70
+ function useRequestConversationApproval() {
71
+ const arbi = chunkZMTLGO3K_cjs.useArbi();
72
+ const qc = reactQuery.useQueryClient();
73
+ return reactQuery.useMutation({
74
+ mutationFn: ({
75
+ conversationId,
76
+ request
77
+ }) => arbi.conversations.requestApproval(conversationId, request),
78
+ onSuccess: () => qc.invalidateQueries({ queryKey: chunk6BLXIF4R_cjs.arbiQueryKeys.allConversations() })
79
+ });
80
+ }
81
+ function usePlanWork() {
82
+ const arbi = chunkZMTLGO3K_cjs.useArbi();
83
+ return reactQuery.useMutation({
84
+ mutationFn: (body) => arbi.conversations.plan(body)
85
+ });
86
+ }
87
+ function useConversationPendingAuth(conversationId, options) {
88
+ const arbi = chunkZMTLGO3K_cjs.useArbi();
89
+ return reactQuery.useQuery({
90
+ queryKey: [...chunk6BLXIF4R_cjs.arbiQueryKeys.allConversations(), conversationId ?? "", "pending-auth"],
91
+ queryFn: () => arbi.conversations.pendingAuth(conversationId),
92
+ enabled: (options?.enabled ?? true) && !!conversationId && arbi.isLoggedIn,
93
+ retry: false
94
+ });
95
+ }
96
+ function useConversationActivity(conversationId, options) {
97
+ const arbi = chunkZMTLGO3K_cjs.useArbi();
98
+ return reactQuery.useQuery({
99
+ queryKey: [...chunk6BLXIF4R_cjs.arbiQueryKeys.allConversations(), conversationId ?? "", "activity"],
100
+ queryFn: () => arbi.conversations.activity(conversationId),
101
+ enabled: (options?.enabled ?? true) && !!conversationId && arbi.isLoggedIn,
102
+ refetchInterval: options?.live ? 2500 : false
103
+ });
104
+ }
105
+ function useWorkflows(options) {
106
+ const arbi = chunkZMTLGO3K_cjs.useArbi();
107
+ return reactQuery.useQuery({
108
+ queryKey: chunk6BLXIF4R_cjs.arbiQueryKeys.workflows(),
109
+ queryFn: () => arbi.workflows.list(),
110
+ refetchInterval: options?.live ? 15e3 : false,
111
+ enabled: options?.enabled ?? arbi.isLoggedIn
112
+ });
113
+ }
114
+ function useCreateWorkflow() {
115
+ const arbi = chunkZMTLGO3K_cjs.useArbi();
116
+ const qc = reactQuery.useQueryClient();
117
+ return reactQuery.useMutation({
118
+ mutationFn: (body) => arbi.workflows.create(body),
119
+ onSuccess: () => qc.invalidateQueries({ queryKey: chunk6BLXIF4R_cjs.arbiQueryKeys.workflows() })
120
+ });
121
+ }
122
+ function useUpdateWorkflow() {
123
+ const arbi = chunkZMTLGO3K_cjs.useArbi();
124
+ const qc = reactQuery.useQueryClient();
125
+ return reactQuery.useMutation({
126
+ mutationFn: ({
127
+ workflowId,
128
+ patch
129
+ }) => arbi.workflows.update(workflowId, patch),
130
+ onSuccess: () => qc.invalidateQueries({ queryKey: chunk6BLXIF4R_cjs.arbiQueryKeys.workflows() })
131
+ });
132
+ }
133
+ function useDeleteWorkflow() {
134
+ const arbi = chunkZMTLGO3K_cjs.useArbi();
135
+ const qc = reactQuery.useQueryClient();
136
+ return reactQuery.useMutation({
137
+ mutationFn: (workflowId) => arbi.workflows.delete(workflowId),
138
+ onSuccess: () => qc.invalidateQueries({ queryKey: chunk6BLXIF4R_cjs.arbiQueryKeys.workflows() })
139
+ });
140
+ }
141
+ function useRunWorkflow() {
142
+ const arbi = chunkZMTLGO3K_cjs.useArbi();
143
+ const qc = reactQuery.useQueryClient();
144
+ return reactQuery.useMutation({
145
+ mutationFn: (workflowId) => arbi.workflows.run(workflowId),
146
+ onSuccess: () => Promise.all([
147
+ qc.invalidateQueries({ queryKey: chunk6BLXIF4R_cjs.arbiQueryKeys.workflows() }),
148
+ qc.invalidateQueries({ queryKey: chunk6BLXIF4R_cjs.arbiQueryKeys.allConversations() })
149
+ ])
150
+ });
151
+ }
152
+ function useCreateAgent() {
153
+ const arbi = chunkZMTLGO3K_cjs.useArbi();
154
+ const qc = reactQuery.useQueryClient();
155
+ return reactQuery.useMutation({
156
+ mutationFn: (name) => arbi.agents.create(name),
157
+ onSuccess: () => qc.invalidateQueries({ queryKey: chunk6BLXIF4R_cjs.arbiQueryKeys.agents() })
158
+ });
159
+ }
160
+ function useAgentConfig(agentExtId, options) {
161
+ const arbi = chunkZMTLGO3K_cjs.useArbi();
162
+ return reactQuery.useQuery({
163
+ queryKey: chunk6BLXIF4R_cjs.arbiQueryKeys.agentConfig(agentExtId),
164
+ queryFn: async () => agentExtId ? await arbi.agents.getConfig(agentExtId) : await arbi.agentConfig.get("default"),
165
+ enabled: (options?.enabled ?? true) && arbi.isLoggedIn
166
+ });
167
+ }
168
+ function useAgentModels(options) {
169
+ const arbi = chunkZMTLGO3K_cjs.useArbi();
170
+ return reactQuery.useQuery({
171
+ queryKey: chunk6BLXIF4R_cjs.arbiQueryKeys.models(),
172
+ queryFn: async () => (await arbi.agentConfig.getModels()).models.map((m) => m.model_name),
173
+ enabled: (options?.enabled ?? true) && arbi.isLoggedIn
174
+ });
175
+ }
176
+ function useSaveAgentConfig() {
177
+ const arbi = chunkZMTLGO3K_cjs.useArbi();
178
+ const qc = reactQuery.useQueryClient();
179
+ return reactQuery.useMutation({
180
+ mutationFn: async ({ agentExtId, title, sections }) => {
181
+ const pinned = await arbi.agents.getConfig(agentExtId);
182
+ const base = pinned ?? await arbi.agentConfig.get("default");
183
+ const merged = structuredClone(base);
184
+ for (const [section, params] of Object.entries(sections)) {
185
+ merged[section] = { ...merged[section] ?? {}, ...params };
186
+ }
187
+ return arbi.agentConfig.save({
188
+ ...merged,
189
+ agent_ext_id: agentExtId,
190
+ title: title ?? `agent-${agentExtId}`
191
+ });
192
+ },
193
+ onSuccess: (_saved, { agentExtId }) => Promise.all([
194
+ qc.invalidateQueries({ queryKey: chunk6BLXIF4R_cjs.arbiQueryKeys.configs() }),
195
+ qc.invalidateQueries({ queryKey: chunk6BLXIF4R_cjs.arbiQueryKeys.agentConfig(agentExtId) }),
196
+ // The agent list shows the pinned persona/model, so it refreshes too.
197
+ qc.invalidateQueries({ queryKey: chunk6BLXIF4R_cjs.arbiQueryKeys.agents() })
198
+ ])
199
+ });
200
+ }
201
+ function useAgentWorkspaces(agentExtId, options) {
202
+ const arbi = chunkZMTLGO3K_cjs.useArbi();
203
+ return reactQuery.useQuery({
204
+ queryKey: chunk6BLXIF4R_cjs.arbiQueryKeys.agentWorkspaces(agentExtId ?? ""),
205
+ queryFn: () => arbi.agents.listWorkspaces(agentExtId),
206
+ enabled: (options?.enabled ?? true) && !!agentExtId && arbi.isLoggedIn
207
+ });
208
+ }
209
+ function useGrantAgentAccess() {
210
+ const arbi = chunkZMTLGO3K_cjs.useArbi();
211
+ const qc = reactQuery.useQueryClient();
212
+ return reactQuery.useMutation({
213
+ mutationFn: async ({
214
+ agentExtId,
215
+ workspaceId,
216
+ mode = { kind: "standing" }
217
+ }) => {
218
+ if (mode.kind === "temporary") {
219
+ return arbi.agents.grantTemporaryAccess(agentExtId, workspaceId, mode.ttlSeconds);
220
+ }
221
+ const agent = (await arbi.agents.list()).find((a) => a.external_id === agentExtId);
222
+ if (!agent?.email) throw new Error("The agent's address is unknown.");
223
+ return arbi.workspaces.grantAccess({ workspaceId, emails: [agent.email] });
224
+ },
225
+ onSuccess: (_res, { agentExtId }) => qc.invalidateQueries({ queryKey: chunk6BLXIF4R_cjs.arbiQueryKeys.agentWorkspaces(agentExtId) })
226
+ });
227
+ }
228
+ function useRevokeAgentAccess() {
229
+ const arbi = chunkZMTLGO3K_cjs.useArbi();
230
+ const qc = reactQuery.useQueryClient();
231
+ return reactQuery.useMutation({
232
+ mutationFn: async ({
233
+ agentExtId,
234
+ workspaceId
235
+ }) => {
236
+ const previous = arbi.hasWorkspace ? arbi.getWorkspaceId() : null;
237
+ await arbi.selectWorkspace(workspaceId);
238
+ try {
239
+ await arbi.workspaces.removeUsers([agentExtId]);
240
+ } finally {
241
+ if (previous && previous !== workspaceId) await arbi.selectWorkspace(previous);
242
+ }
243
+ },
244
+ onSuccess: (_res, { agentExtId }) => qc.invalidateQueries({ queryKey: chunk6BLXIF4R_cjs.arbiQueryKeys.agentWorkspaces(agentExtId) })
245
+ });
246
+ }
247
+ function useSkills(options) {
248
+ const arbi = chunkZMTLGO3K_cjs.useArbi();
249
+ return reactQuery.useQuery({
250
+ queryKey: [...chunk6BLXIF4R_cjs.arbiQueryKeys.skills(), options?.includeHidden ?? false],
251
+ queryFn: () => arbi.assistant.listSkills({ includeHidden: options?.includeHidden }),
252
+ refetchInterval: options?.live ? 5e3 : false,
253
+ enabled: (options?.enabled ?? true) && arbi.isLoggedIn,
254
+ staleTime: 3e4
255
+ });
256
+ }
257
+ function useUploadSkillFiles() {
258
+ const arbi = chunkZMTLGO3K_cjs.useArbi();
259
+ const qc = reactQuery.useQueryClient();
260
+ return reactQuery.useMutation({
261
+ mutationFn: async (entries) => {
262
+ if (!entries.length) throw new Error("Choose at least one skill file.");
263
+ for (const entry of entries) {
264
+ if (!/^skills\/[a-z0-9][a-z0-9_-]*(?:\/[^/]+)*$/.test(entry.folder) || entry.folder.split("/").some((segment) => segment === ".." || segment === "."))
265
+ throw new Error("Skill files need a folder under skills/<name>.");
266
+ }
267
+ const results = [];
268
+ for (const entry of entries) {
269
+ const result = await arbi.documents.uploadFile(entry.content, entry.fileName, {
270
+ folder: entry.folder,
271
+ wpType: "skill"
272
+ });
273
+ if (result.skipped?.length)
274
+ throw new Error(
275
+ result.skipped.map((file) => `${file.file_name}: ${file.reason}`).join("; ")
276
+ );
277
+ results.push(result);
278
+ }
279
+ return results;
280
+ },
281
+ onSuccess: () => qc.invalidateQueries({ queryKey: chunk6BLXIF4R_cjs.arbiQueryKeys.skills() })
282
+ });
283
+ }
284
+ function useStartWorkQuery() {
285
+ const arbi = chunkZMTLGO3K_cjs.useArbi();
286
+ const qc = reactQuery.useQueryClient();
287
+ return reactQuery.useMutation({
288
+ mutationFn: async ({
289
+ question,
290
+ ...options
291
+ }) => {
292
+ const response = await arbi.assistant.submit(question, options);
293
+ for (let attempt = 0; attempt < 30; attempt++) {
294
+ if (attempt) await new Promise((resolve) => setTimeout(resolve, 500));
295
+ try {
296
+ const message = await arbi.conversations.getMessage(response.id);
297
+ if (message.conversation_ext_id)
298
+ return { conversationId: message.conversation_ext_id, responseId: response.id };
299
+ } catch (error) {
300
+ if (!(error && typeof error === "object" && "status" in error && error.status === 404))
301
+ throw error;
302
+ }
303
+ }
304
+ throw new Error(
305
+ `The run ${response.id} started, but its thread is not available yet. Do not submit it again.`
306
+ );
307
+ },
308
+ onSuccess: () => qc.invalidateQueries({ queryKey: chunk6BLXIF4R_cjs.arbiQueryKeys.allConversations() })
309
+ });
310
+ }
311
+ function useAgentSession(agentId, options) {
312
+ const arbi = chunkZMTLGO3K_cjs.useArbi();
313
+ return reactQuery.useQuery({
314
+ queryKey: ["arbi", "agent-session", agentId],
315
+ queryFn: () => arbi.agents.getSession(agentId),
316
+ enabled: !!agentId && arbi.isLoggedIn && (options?.enabled ?? true),
317
+ refetchInterval: 5e3
318
+ });
319
+ }
320
+ function useAgentChats(agentId) {
321
+ const arbi = chunkZMTLGO3K_cjs.useArbi();
322
+ return reactQuery.useQuery({
323
+ queryKey: ["arbi", "agent-chats", agentId],
324
+ queryFn: () => arbi.agents.listChats(agentId),
325
+ enabled: !!agentId && arbi.isLoggedIn,
326
+ refetchInterval: 5e3
327
+ });
328
+ }
329
+ function useStartAgentSession() {
330
+ const arbi = chunkZMTLGO3K_cjs.useArbi();
331
+ const cache = reactQuery.useQueryClient();
332
+ return reactQuery.useMutation({
333
+ mutationFn: ({ agentId, workspaceId }) => arbi.agents.startSession(agentId, workspaceId),
334
+ onSuccess: () => cache.invalidateQueries({ queryKey: ["arbi", "agent-session"] })
335
+ });
336
+ }
337
+ function useCloseAgentSession() {
338
+ const arbi = chunkZMTLGO3K_cjs.useArbi();
339
+ const cache = reactQuery.useQueryClient();
340
+ return reactQuery.useMutation({
341
+ mutationFn: (agentId) => arbi.agents.closeSession(agentId),
342
+ onSuccess: () => cache.invalidateQueries({ queryKey: ["arbi", "agent-session"] })
343
+ });
344
+ }
32
345
  function previewText(content) {
33
346
  return content.replace(/\s+/g, " ").trim().replace(/^(?:(?:[-*•>]|#{1,6})\s+)+/, "");
34
347
  }
@@ -78,26 +391,50 @@ var UNFINISHED_STATUSES = /* @__PURE__ */ new Set(["failed", "in_progress", "que
78
391
  var FAILED_MESSAGE = "The assistant request failed.";
79
392
  var UNFINISHED_MESSAGE = "The answer did not finish. Try again.";
80
393
  var isUnfinished = (m) => UNFINISHED_STATUSES.has(m.status);
81
- function messagesFromHistory(history) {
394
+ function messagesFromHistory(history, live = false) {
82
395
  return history.filter(
83
- (m) => m.role !== "system" && (m.content.trim() !== "" || m.role === "assistant" && isUnfinished(m))
396
+ (m) => m.role !== "system" && (m.content.trim() !== "" || m.role === "assistant" && (isUnfinished(m) || m.status === "cancelled"))
84
397
  ).map((m) => {
85
398
  if (m.role === "user") {
86
- return { id: m.external_id, role: "user", content: m.content, status: "complete" };
399
+ return {
400
+ id: m.external_id,
401
+ role: "user",
402
+ content: m.content,
403
+ status: "complete",
404
+ ...m.created_by_ext_id ? { authorId: m.created_by_ext_id } : {},
405
+ ...m.mentions?.length ? { mentions: m.mentions } : {}
406
+ };
87
407
  }
88
408
  const citations = toChatCitations({ tools: m.tools });
89
409
  const unfinished = isUnfinished(m);
410
+ const runningElsewhere = live && (m.status === "in_progress" || m.status === "queued");
90
411
  return {
91
412
  id: m.external_id,
92
413
  role: "assistant",
93
414
  content: m.content,
94
- status: unfinished ? "error" : "complete",
95
- ...unfinished ? { error: m.status === "failed" ? FAILED_MESSAGE : UNFINISHED_MESSAGE } : {},
415
+ status: runningElsewhere ? "streaming" : unfinished ? "error" : "complete",
416
+ ...m.status === "cancelled" ? { stopped: true } : {},
417
+ ...unfinished && !runningElsewhere ? { error: m.status === "failed" ? FAILED_MESSAGE : UNFINISHED_MESSAGE } : {},
96
418
  ...unfinished ? {} : { responseId: m.external_id },
97
419
  ...citations.length > 0 ? { citations } : {}
98
420
  };
99
421
  });
100
422
  }
423
+ function mergeHistory(history, local) {
424
+ const merged = [...history];
425
+ for (const message of local) {
426
+ if (!message.pendingHistory) continue;
427
+ const question = local.find((candidate) => candidate.id === message.questionId);
428
+ const pending = question?.storedId && history.some((stored) => stored.id === question.storedId) ? { ...message, questionId: question.storedId } : message;
429
+ const storedId = message.storedId ?? message.responseId ?? message.id;
430
+ const index = merged.findIndex((stored) => stored.id === storedId);
431
+ if (index < 0) merged.push(pending);
432
+ else if (message.role === "assistant" && merged[index].status === "streaming") {
433
+ merged[index] = pending;
434
+ }
435
+ }
436
+ return merged;
437
+ }
101
438
  function chainId(messages) {
102
439
  for (let i = messages.length - 1; i >= 0; i--) {
103
440
  const m = messages[i];
@@ -118,43 +455,61 @@ var messageOf = (e, fallback) => e instanceof Error ? e.message : fallback;
118
455
  var isAbort = (e) => e instanceof DOMException && e.name === "AbortError";
119
456
  var TITLE_REFRESH_DELAYS_MS = [2500, 6e3, 12e3];
120
457
  function useArbiChat(options = {}) {
121
- const { workspaceId, model, titleLength = 48, streamRecovery } = options;
458
+ const { workspaceId, agentId, model, titleLength = 48, streamRecovery } = options;
122
459
  const recoveryIntervalMs = streamRecovery?.intervalMs ?? 3e3;
123
460
  const recoveryTimeoutMs = streamRecovery?.timeoutMs ?? 12e4;
124
461
  const arbi = chunkZMTLGO3K_cjs.useArbi();
125
- const { data: docs = [], isLoading: isLoadingDocuments, refetch } = chunkKXIIARRK_cjs.useDocuments(workspaceId);
126
- const {
127
- data: stored = [],
128
- isLoading: isLoadingThreads,
129
- refetch: refetchConversations
130
- } = chunkKXIIARRK_cjs.useConversations(workspaceId);
131
- const query = chunkKXIIARRK_cjs.useAssistantQuery();
462
+ const { data: docs = [], isLoading: isLoadingDocuments, refetch } = chunk6BLXIF4R_cjs.useDocuments(workspaceId);
463
+ const ordinaryHistory = chunk6BLXIF4R_cjs.useConversations(workspaceId, { enabled: !agentId, live: true });
464
+ const agentHistory = useAgentChats(agentId);
465
+ const stored = React.useMemo(
466
+ () => agentId ? (agentHistory.data ?? []).filter((chat) => chat.workspace_ext_id === workspaceId).map((chat) => ({
467
+ external_id: chat.conversation_ext_id,
468
+ title: chat.title,
469
+ updated_at: chat.updated_at,
470
+ message_count: 1,
471
+ status: null,
472
+ assistant_mode: "always"
473
+ })) : ordinaryHistory.data ?? [],
474
+ [agentId, agentHistory.data, ordinaryHistory.data, workspaceId]
475
+ );
476
+ const isLoadingThreads = agentId ? agentHistory.isLoading : ordinaryHistory.isLoading;
477
+ const refetchConversations = agentId ? agentHistory.refetch : ordinaryHistory.refetch;
478
+ const query = chunk6BLXIF4R_cjs.useAssistantQuery();
132
479
  const { mutateAsync } = query;
480
+ const [stagedFiles, setStagedFiles] = React.useState([]);
133
481
  const [threads, setThreads] = React.useState(() => [emptyThread()]);
134
482
  const [activeKey, setActiveKey] = React.useState(() => threads[0].key);
135
483
  const [deselected, setDeselected] = React.useState(/* @__PURE__ */ new Set());
136
484
  const [isRunning, setIsRunning] = React.useState(false);
485
+ const [isPostingComment, setIsPostingComment] = React.useState(false);
486
+ const [isUpdatingAssistantMode, setIsUpdatingAssistantMode] = React.useState(false);
137
487
  const [isUploading, setIsUploading] = React.useState(false);
138
488
  const [uploadError, setUploadError] = React.useState(null);
139
489
  const [historyError, setHistoryError] = React.useState(null);
140
490
  const abortRef = React.useRef(null);
491
+ const runIdRef = React.useRef(null);
492
+ const stopRequestedRef = React.useRef(false);
141
493
  const timersRef = React.useRef([]);
142
494
  React.useEffect(() => {
143
495
  const timers = timersRef.current;
144
496
  return () => timers.forEach(clearTimeout);
145
497
  }, []);
146
- const scopeRef = React.useRef(workspaceId);
498
+ const chatScope = `${workspaceId ?? ""}:${agentId ?? ""}`;
499
+ const scopeRef = React.useRef(chatScope);
147
500
  React.useEffect(() => {
148
- if (scopeRef.current === workspaceId) return;
149
- scopeRef.current = workspaceId;
501
+ if (scopeRef.current === chatScope) return;
502
+ scopeRef.current = chatScope;
503
+ setStagedFiles([]);
150
504
  const fresh = emptyThread();
151
505
  setThreads([fresh]);
152
506
  setActiveKey(fresh.key);
153
507
  setDeselected(/* @__PURE__ */ new Set());
154
508
  setUploadError(null);
155
509
  setHistoryError(null);
156
- }, [workspaceId]);
510
+ }, [chatScope]);
157
511
  const active = threads.find((t) => t.key === activeKey) ?? threads[0];
512
+ const assistantMode = active.assistantMode ?? stored.find((c) => c.external_id === active.conversationId)?.assistant_mode ?? "always";
158
513
  const threadEntries = React.useMemo(() => {
159
514
  const storedIds = new Set(stored.map((c) => c.external_id));
160
515
  const byConversation = new Map(
@@ -162,7 +517,7 @@ function useArbiChat(options = {}) {
162
517
  );
163
518
  const fresh = threads.filter((t) => !t.conversationId);
164
519
  const justSaved = threads.filter((t) => t.conversationId && !storedIds.has(t.conversationId));
165
- const persisted = [...stored].filter((c) => c.message_count > 0 || byConversation.has(c.external_id)).sort((a, b) => b.updated_at.localeCompare(a.updated_at)).map((c) => {
520
+ const persisted = [...stored].filter((c) => c.status != null || c.message_count > 0 || byConversation.has(c.external_id)).sort((a, b) => b.updated_at.localeCompare(a.updated_at)).map((c) => {
166
521
  const local = byConversation.get(c.external_id);
167
522
  return {
168
523
  key: local?.key ?? c.external_id,
@@ -176,41 +531,71 @@ function useArbiChat(options = {}) {
176
531
  ...persisted
177
532
  ];
178
533
  }, [threads, stored]);
534
+ const liveHistory = assistantMode === "mentioned" || stored.some(
535
+ (conversation) => conversation.external_id === active.conversationId && conversation.status === "generating"
536
+ ) || active.messages.some((message) => message.status === "streaming");
179
537
  const needsLoad = !!active.conversationId && !active.isLoaded;
180
- const loaded = chunkKXIIARRK_cjs.useConversationThreads(workspaceId, active.conversationId ?? void 0, {
181
- enabled: needsLoad
538
+ const loaded = chunk6BLXIF4R_cjs.useConversationThreads(workspaceId, active.conversationId ?? void 0, {
539
+ enabled: needsLoad || liveHistory && !isRunning && !isPostingComment,
540
+ live: liveHistory
182
541
  });
542
+ const refetchThread = loaded.refetch;
543
+ const selectedStored = stored.find(
544
+ (conversation) => conversation.external_id === active.conversationId
545
+ );
546
+ const historyRevision = selectedStored ? `${selectedStored.external_id}:${selectedStored.updated_at}:${selectedStored.message_count}:${selectedStored.status}` : void 0;
547
+ const observedHistoryRevision = React.useRef(void 0);
548
+ React.useEffect(() => {
549
+ const previous = observedHistoryRevision.current;
550
+ observedHistoryRevision.current = historyRevision;
551
+ if (previous && previous !== historyRevision && active.isLoaded && !isRunning && !isPostingComment)
552
+ void refetchThread();
553
+ }, [historyRevision, active.isLoaded, isRunning, isPostingComment, refetchThread]);
183
554
  React.useEffect(() => {
184
555
  const data = loaded.data;
185
- if (!needsLoad || !data || data.conversation_ext_id !== active.conversationId) return;
556
+ if (isRunning || isPostingComment || !data || data.conversation_ext_id !== active.conversationId)
557
+ return;
186
558
  const primary = [...data.threads].sort((a, b) => b.history.length - a.history.length)[0];
187
- const messages = messagesFromHistory(primary?.history ?? []);
559
+ const messages = messagesFromHistory(primary?.history ?? [], liveHistory);
188
560
  setThreads(
189
561
  (all) => all.map(
190
- (t) => t.key === active.key ? {
191
- ...t,
192
- isLoaded: true,
193
- messages,
194
- responseId: chainId(messages)
195
- } : t
562
+ (t) => t.key === active.key ? (() => {
563
+ const merged = mergeHistory(messages, t.messages);
564
+ return {
565
+ ...t,
566
+ isLoaded: true,
567
+ assistantMode: data.assistant_mode,
568
+ messages: merged,
569
+ responseId: chainId(merged)
570
+ };
571
+ })() : t
196
572
  )
197
573
  );
198
- }, [loaded.data, needsLoad, active.conversationId, active.key]);
574
+ }, [
575
+ loaded.data,
576
+ liveHistory,
577
+ needsLoad,
578
+ active.conversationId,
579
+ active.key,
580
+ assistantMode,
581
+ isRunning,
582
+ isPostingComment
583
+ ]);
199
584
  React.useEffect(() => {
200
585
  if (loaded.error)
201
586
  setHistoryError(messageOf(loaded.error, "The conversation could not be loaded."));
202
587
  }, [loaded.error]);
203
588
  const selectedIds = React.useMemo(
204
- () => docs.map((d) => d.external_id).filter((id) => !!id && !deselected.has(id)),
205
- [docs, deselected]
589
+ () => (agentId ? [] : docs).map((d) => d.external_id).filter((id) => !!id && !deselected.has(id)),
590
+ [docs, deselected, agentId]
206
591
  );
207
592
  const documents = React.useMemo(
208
- () => docs.filter((d) => !!d.external_id).map((d) => ({
593
+ () => agentId ? stagedFiles.map((file) => ({ ...file, isSelected: !deselected.has(file.id) })) : docs.filter((d) => !!d.external_id).map((d) => ({
209
594
  id: d.external_id,
210
595
  name: d.file_name ?? d.external_id,
211
596
  isSelected: !deselected.has(d.external_id)
212
597
  })),
213
- [docs, deselected]
598
+ [docs, deselected, agentId, stagedFiles]
214
599
  );
215
600
  const patchThread = React.useCallback(
216
601
  (key, patch) => setThreads((all) => all.map((t) => t.key === key ? patch(t) : t)),
@@ -253,15 +638,31 @@ function useArbiChat(options = {}) {
253
638
  },
254
639
  [arbi, recoveryIntervalMs, recoveryTimeoutMs]
255
640
  );
641
+ const cancelNativeRun = React.useCallback(
642
+ async (responseId, controller) => {
643
+ try {
644
+ await arbi.assistant.cancelRun(responseId);
645
+ if (abortRef.current === controller) controller.abort();
646
+ } catch (error2) {
647
+ stopRequestedRef.current = false;
648
+ setHistoryError(messageOf(error2, "The agent run could not be stopped."));
649
+ }
650
+ },
651
+ [arbi]
652
+ );
256
653
  const ask = React.useCallback(
257
- async (thread, text) => {
654
+ async (thread, text, mentions) => {
258
655
  const userMessage = {
656
+ pendingHistory: true,
657
+ ...mentions?.length ? { mentions } : {},
259
658
  id: nextId("msg"),
260
659
  role: "user",
261
660
  content: text,
262
661
  status: "complete"
263
662
  };
264
663
  const answer = {
664
+ pendingHistory: true,
665
+ questionId: userMessage.id,
265
666
  id: nextId("msg"),
266
667
  role: "assistant",
267
668
  content: "",
@@ -274,6 +675,8 @@ function useArbiChat(options = {}) {
274
675
  }));
275
676
  const controller = new AbortController();
276
677
  abortRef.current = controller;
678
+ runIdRef.current = null;
679
+ stopRequestedRef.current = false;
277
680
  setIsRunning(true);
278
681
  let buffer = "";
279
682
  let steps = 0;
@@ -290,15 +693,25 @@ function useArbiChat(options = {}) {
290
693
  revertChain();
291
694
  };
292
695
  try {
696
+ const lastMessage2 = thread.messages[thread.messages.length - 1];
697
+ const parentId = lastMessage2?.role === "user" && (lastMessage2.storedId || !lastMessage2.pendingHistory) ? lastMessage2.storedId ?? lastMessage2.id : thread.responseId;
293
698
  const result = await mutateAsync({
294
- question: text,
699
+ question: agentId && stagedFiles.some((file) => !deselected.has(file.id)) ? text + "\n\nSource files staged in your sandbox:\n" + stagedFiles.filter((file) => !deselected.has(file.id)).map((file) => `${file.name}: ${file.id}`).join("\n") : text,
700
+ ...agentId ? { agentId, workspaceId } : {},
295
701
  docIds: selectedIds,
296
- previousResponseId: thread.responseId,
702
+ previousResponseId: parentId,
703
+ ...thread.conversationId ? { conversationId: thread.conversationId } : {},
704
+ ...!thread.conversationId && thread.assistantMode === "mentioned" ? { assistantMode: "mentioned" } : {},
705
+ ...mentions?.length ? { mentions } : {},
297
706
  model,
298
707
  signal: controller.signal,
299
708
  onStreamStart: (data) => {
300
709
  if (data.assistant_message_ext_id) {
301
710
  backendMessageId = data.assistant_message_ext_id;
711
+ runIdRef.current = backendMessageId;
712
+ if (agentId && stopRequestedRef.current)
713
+ void cancelNativeRun(backendMessageId, controller);
714
+ patchMessage(thread.key, answer.id, { storedId: backendMessageId });
302
715
  patchThread(thread.key, (t) => ({
303
716
  ...t,
304
717
  responseId: data.assistant_message_ext_id ?? t.responseId
@@ -307,6 +720,7 @@ function useArbiChat(options = {}) {
307
720
  },
308
721
  onUserMessage: (ev) => {
309
722
  conversationId = conversationId ?? ev.conversation_ext_id;
723
+ patchMessage(thread.key, userMessage.id, { storedId: ev.external_id });
310
724
  patchThread(thread.key, (t) => ({
311
725
  ...t,
312
726
  conversationId: t.conversationId ?? ev.conversation_ext_id
@@ -395,30 +809,132 @@ function useArbiChat(options = {}) {
395
809
  recoverStoredAnswer,
396
810
  selectedIds,
397
811
  model,
398
- titleLength
812
+ titleLength,
813
+ agentId,
814
+ cancelNativeRun,
815
+ workspaceId,
816
+ stagedFiles,
817
+ deselected
399
818
  ]
400
819
  );
401
820
  const send = React.useCallback(
402
- async (text) => {
821
+ async (text, options2) => {
403
822
  const trimmed = text.trim();
404
- if (!trimmed || isRunning || !active.isLoaded) return;
405
- await ask(active, trimmed);
823
+ if (!trimmed || isRunning || isPostingComment || isUpdatingAssistantMode || !active.isLoaded)
824
+ return;
825
+ setHistoryError(null);
826
+ if (assistantMode === "mentioned" && !options2?.mentions?.some((m) => m.type === "assistant")) {
827
+ setIsPostingComment(true);
828
+ setHistoryError(null);
829
+ try {
830
+ const saved = await arbi.conversations.postMessage({
831
+ content: trimmed,
832
+ assistant_mode: "mentioned",
833
+ mentions: options2?.mentions ?? [],
834
+ ...active.conversationId ? { conversation_ext_id: active.conversationId } : {}
835
+ });
836
+ patchThread(active.key, (t) => ({
837
+ ...t,
838
+ conversationId: saved.conversation_ext_id,
839
+ title: t.title || titleFromQuestion(trimmed, titleLength),
840
+ assistantMode: "mentioned",
841
+ responseId: saved.external_id,
842
+ messages: [
843
+ ...t.messages,
844
+ {
845
+ pendingHistory: true,
846
+ id: saved.external_id,
847
+ role: "user",
848
+ content: saved.content,
849
+ status: "complete",
850
+ ...saved.created_by_ext_id ? { authorId: saved.created_by_ext_id } : {}
851
+ }
852
+ ]
853
+ }));
854
+ await refetchConversations();
855
+ if (active.conversationId) await refetchThread();
856
+ } catch (e) {
857
+ setHistoryError(messageOf(e, "The comment could not be posted."));
858
+ throw e;
859
+ } finally {
860
+ setIsPostingComment(false);
861
+ }
862
+ return;
863
+ }
864
+ if (active.messages.some((message) => message.status === "streaming")) {
865
+ const message = "An assistant reply is already running in this thread. You can still post a comment.";
866
+ setHistoryError(message);
867
+ throw new Error(message);
868
+ }
869
+ await ask(active, trimmed, options2?.mentions);
406
870
  },
407
- [active, ask, isRunning]
871
+ [
872
+ active,
873
+ ask,
874
+ isRunning,
875
+ isPostingComment,
876
+ isUpdatingAssistantMode,
877
+ assistantMode,
878
+ arbi,
879
+ patchThread,
880
+ titleLength,
881
+ refetchConversations,
882
+ refetchThread
883
+ ]
408
884
  );
409
- const stop = React.useCallback(() => abortRef.current?.abort(), []);
885
+ const setAssistantMode = React.useCallback(
886
+ async (mode) => {
887
+ if (isRunning || isPostingComment || isUpdatingAssistantMode) return;
888
+ setIsUpdatingAssistantMode(true);
889
+ setHistoryError(null);
890
+ try {
891
+ if (active.conversationId) {
892
+ await arbi.conversations.setAssistantMode(active.conversationId, mode);
893
+ await refetchThread();
894
+ }
895
+ patchThread(active.key, (t) => ({ ...t, assistantMode: mode }));
896
+ await refetchConversations();
897
+ } catch (e) {
898
+ setHistoryError(messageOf(e, "The assistant mode could not be changed."));
899
+ } finally {
900
+ setIsUpdatingAssistantMode(false);
901
+ }
902
+ },
903
+ [
904
+ active,
905
+ arbi,
906
+ patchThread,
907
+ refetchConversations,
908
+ refetchThread,
909
+ isRunning,
910
+ isPostingComment,
911
+ isUpdatingAssistantMode
912
+ ]
913
+ );
914
+ const stop = React.useCallback(() => {
915
+ const controller = abortRef.current;
916
+ if (!controller) return;
917
+ if (!agentId) {
918
+ controller.abort();
919
+ return;
920
+ }
921
+ stopRequestedRef.current = true;
922
+ if (runIdRef.current) void cancelNativeRun(runIdRef.current, controller);
923
+ }, [agentId, cancelNativeRun]);
410
924
  const lastMessage = active.messages[active.messages.length - 1];
411
925
  const error = lastMessage?.status === "error" ? lastMessage.error ?? null : null;
412
926
  const retry = React.useCallback(async () => {
413
927
  if (isRunning) return;
414
928
  const messages = active.messages;
415
929
  const failed = messages[messages.length - 1];
416
- const question = messages[messages.length - 2];
930
+ const question = failed?.questionId ? messages.find((message) => message.id === failed.questionId) : messages[messages.length - 2];
417
931
  if (failed?.status !== "error" || question?.role !== "user") return;
418
- const rest = messages.slice(0, -2);
932
+ const rest = messages.filter(
933
+ (message) => message.id !== failed.id && message.id !== question.id
934
+ );
419
935
  const trimmed = { ...active, messages: rest, responseId: chainId(rest) };
420
936
  patchThread(active.key, () => trimmed);
421
- await ask(trimmed, question.content);
937
+ await ask(trimmed, question.content, question.mentions);
422
938
  }, [active, ask, isRunning, patchThread]);
423
939
  const newThread = React.useCallback(() => {
424
940
  setHistoryError(null);
@@ -481,17 +997,29 @@ function useArbiChat(options = {}) {
481
997
  setIsUploading(true);
482
998
  setUploadError(null);
483
999
  try {
484
- for (const file of files) await arbi.documents.uploadFile(file, file.name);
485
- await refetch();
1000
+ for (const file of files) {
1001
+ if (agentId) {
1002
+ const staged = await arbi.agents.stageFile(agentId, file, file.name);
1003
+ setStagedFiles((all) => [
1004
+ ...all.filter((existing) => existing.id !== staged.path),
1005
+ { id: staged.path, name: staged.name }
1006
+ ]);
1007
+ } else await arbi.documents.uploadFile(file, file.name);
1008
+ }
1009
+ if (!agentId) await refetch();
486
1010
  } catch (e) {
487
1011
  setUploadError(messageOf(e, "The upload failed."));
488
1012
  } finally {
489
1013
  setIsUploading(false);
490
1014
  }
491
1015
  },
492
- [arbi, refetch]
1016
+ [arbi, refetch, agentId]
493
1017
  );
494
1018
  return {
1019
+ assistantMode,
1020
+ isUpdatingAssistantMode,
1021
+ isPostingComment,
1022
+ setAssistantMode,
495
1023
  threads: threadEntries.map(({ id, title }) => ({ id, title })),
496
1024
  activeThreadId: publicId(active),
497
1025
  messages: active.messages,
@@ -784,14 +1312,14 @@ function useArbiDocumentSync(workspaceId) {
784
1312
  if (!workspaceId) return;
785
1313
  if (client.isMessageType(msg, "batch_complete")) {
786
1314
  if (msg.workspace_ext_id !== workspaceId) return;
787
- void queryClient.invalidateQueries({ queryKey: chunkKXIIARRK_cjs.arbiQueryKeys.documents(workspaceId) });
788
- void queryClient.invalidateQueries({ queryKey: chunkKXIIARRK_cjs.arbiQueryKeys.tags(workspaceId) });
1315
+ void queryClient.invalidateQueries({ queryKey: chunk6BLXIF4R_cjs.arbiQueryKeys.documents(workspaceId) });
1316
+ void queryClient.invalidateQueries({ queryKey: chunk6BLXIF4R_cjs.arbiQueryKeys.tags(workspaceId) });
789
1317
  return;
790
1318
  }
791
1319
  if (client.isMessageType(msg, "task_update")) {
792
1320
  if (msg.workspace_ext_id !== workspaceId) return;
793
1321
  if (TERMINAL_STATUSES.has(msg.status)) {
794
- void queryClient.invalidateQueries({ queryKey: chunkKXIIARRK_cjs.arbiQueryKeys.documents(workspaceId) });
1322
+ void queryClient.invalidateQueries({ queryKey: chunk6BLXIF4R_cjs.arbiQueryKeys.documents(workspaceId) });
795
1323
  }
796
1324
  }
797
1325
  });
@@ -920,7 +1448,7 @@ function useShellWorkspaces(options) {
920
1448
  }
921
1449
  function useArbiShellWorkspaces(options = {}) {
922
1450
  const arbi = chunkZMTLGO3K_cjs.useArbi();
923
- const query = chunkKXIIARRK_cjs.useWorkspaces();
1451
+ const query = chunk6BLXIF4R_cjs.useWorkspaces();
924
1452
  const { select, ...rest } = options;
925
1453
  const defaultSelect = React.useCallback(
926
1454
  (workspace) => arbi.selectWorkspace(workspace.id),
@@ -934,233 +1462,10 @@ function useArbiShellWorkspaces(options = {}) {
934
1462
  select: select ?? defaultSelect
935
1463
  });
936
1464
  }
937
- function useUpdateConversation() {
938
- const arbi = chunkZMTLGO3K_cjs.useArbi();
939
- const qc = reactQuery.useQueryClient();
940
- return reactQuery.useMutation({
941
- mutationFn: ({
942
- conversationId,
943
- patch
944
- }) => arbi.conversations.update(conversationId, patch),
945
- onSuccess: () => qc.invalidateQueries({ queryKey: chunkKXIIARRK_cjs.arbiQueryKeys.allConversations() })
946
- });
947
- }
948
- function useCreateWork() {
949
- const arbi = chunkZMTLGO3K_cjs.useArbi();
950
- const qc = reactQuery.useQueryClient();
951
- return reactQuery.useMutation({
952
- mutationFn: (body) => arbi.conversations.createWork(body),
953
- onSuccess: () => qc.invalidateQueries({ queryKey: chunkKXIIARRK_cjs.arbiQueryKeys.allConversations() })
954
- });
955
- }
956
- function useRunConversation() {
957
- const arbi = chunkZMTLGO3K_cjs.useArbi();
958
- const qc = reactQuery.useQueryClient();
959
- return reactQuery.useMutation({
960
- mutationFn: (conversationId) => arbi.conversations.runWithAuth(conversationId),
961
- onSuccess: () => qc.invalidateQueries({ queryKey: chunkKXIIARRK_cjs.arbiQueryKeys.allConversations() })
962
- });
963
- }
964
- function useReviewConversation() {
965
- const arbi = chunkZMTLGO3K_cjs.useArbi();
966
- const qc = reactQuery.useQueryClient();
967
- return reactQuery.useMutation({
968
- mutationFn: ({
969
- conversationId,
970
- review
971
- }) => arbi.conversations.review(conversationId, review),
972
- onSuccess: () => qc.invalidateQueries({ queryKey: chunkKXIIARRK_cjs.arbiQueryKeys.allConversations() })
973
- });
974
- }
975
- function useRequestConversationApproval() {
976
- const arbi = chunkZMTLGO3K_cjs.useArbi();
977
- const qc = reactQuery.useQueryClient();
978
- return reactQuery.useMutation({
979
- mutationFn: ({
980
- conversationId,
981
- request
982
- }) => arbi.conversations.requestApproval(conversationId, request),
983
- onSuccess: () => qc.invalidateQueries({ queryKey: chunkKXIIARRK_cjs.arbiQueryKeys.allConversations() })
984
- });
985
- }
986
- function usePlanWork() {
987
- const arbi = chunkZMTLGO3K_cjs.useArbi();
988
- return reactQuery.useMutation({
989
- mutationFn: (body) => arbi.conversations.plan(body)
990
- });
991
- }
992
- function useConversationPendingAuth(conversationId, options) {
993
- const arbi = chunkZMTLGO3K_cjs.useArbi();
994
- return reactQuery.useQuery({
995
- queryKey: [...chunkKXIIARRK_cjs.arbiQueryKeys.allConversations(), conversationId ?? "", "pending-auth"],
996
- queryFn: () => arbi.conversations.pendingAuth(conversationId),
997
- enabled: (options?.enabled ?? true) && !!conversationId && arbi.isLoggedIn,
998
- retry: false
999
- });
1000
- }
1001
- function useConversationActivity(conversationId, options) {
1002
- const arbi = chunkZMTLGO3K_cjs.useArbi();
1003
- return reactQuery.useQuery({
1004
- queryKey: [...chunkKXIIARRK_cjs.arbiQueryKeys.allConversations(), conversationId ?? "", "activity"],
1005
- queryFn: () => arbi.conversations.activity(conversationId),
1006
- enabled: (options?.enabled ?? true) && !!conversationId && arbi.isLoggedIn,
1007
- refetchInterval: options?.live ? 2500 : false
1008
- });
1009
- }
1010
- function useWorkflows(options) {
1011
- const arbi = chunkZMTLGO3K_cjs.useArbi();
1012
- return reactQuery.useQuery({
1013
- queryKey: chunkKXIIARRK_cjs.arbiQueryKeys.workflows(),
1014
- queryFn: () => arbi.workflows.list(),
1015
- enabled: options?.enabled ?? arbi.isLoggedIn
1016
- });
1017
- }
1018
- function useCreateWorkflow() {
1019
- const arbi = chunkZMTLGO3K_cjs.useArbi();
1020
- const qc = reactQuery.useQueryClient();
1021
- return reactQuery.useMutation({
1022
- mutationFn: (body) => arbi.workflows.create(body),
1023
- onSuccess: () => qc.invalidateQueries({ queryKey: chunkKXIIARRK_cjs.arbiQueryKeys.workflows() })
1024
- });
1025
- }
1026
- function useUpdateWorkflow() {
1027
- const arbi = chunkZMTLGO3K_cjs.useArbi();
1028
- const qc = reactQuery.useQueryClient();
1029
- return reactQuery.useMutation({
1030
- mutationFn: ({
1031
- workflowId,
1032
- patch
1033
- }) => arbi.workflows.update(workflowId, patch),
1034
- onSuccess: () => qc.invalidateQueries({ queryKey: chunkKXIIARRK_cjs.arbiQueryKeys.workflows() })
1035
- });
1036
- }
1037
- function useDeleteWorkflow() {
1038
- const arbi = chunkZMTLGO3K_cjs.useArbi();
1039
- const qc = reactQuery.useQueryClient();
1040
- return reactQuery.useMutation({
1041
- mutationFn: (workflowId) => arbi.workflows.delete(workflowId),
1042
- onSuccess: () => qc.invalidateQueries({ queryKey: chunkKXIIARRK_cjs.arbiQueryKeys.workflows() })
1043
- });
1044
- }
1045
- function useRunWorkflow() {
1046
- const arbi = chunkZMTLGO3K_cjs.useArbi();
1047
- const qc = reactQuery.useQueryClient();
1048
- return reactQuery.useMutation({
1049
- mutationFn: (workflowId) => arbi.workflows.run(workflowId),
1050
- onSuccess: () => Promise.all([
1051
- qc.invalidateQueries({ queryKey: chunkKXIIARRK_cjs.arbiQueryKeys.workflows() }),
1052
- qc.invalidateQueries({ queryKey: chunkKXIIARRK_cjs.arbiQueryKeys.allConversations() })
1053
- ])
1054
- });
1055
- }
1056
- function useCreateAgent() {
1057
- const arbi = chunkZMTLGO3K_cjs.useArbi();
1058
- const qc = reactQuery.useQueryClient();
1059
- return reactQuery.useMutation({
1060
- mutationFn: (name) => arbi.agents.create(name),
1061
- onSuccess: () => qc.invalidateQueries({ queryKey: chunkKXIIARRK_cjs.arbiQueryKeys.agents() })
1062
- });
1063
- }
1064
- function useAgentConfig(agentExtId, options) {
1065
- const arbi = chunkZMTLGO3K_cjs.useArbi();
1066
- return reactQuery.useQuery({
1067
- queryKey: chunkKXIIARRK_cjs.arbiQueryKeys.agentConfig(agentExtId),
1068
- queryFn: async () => agentExtId ? await arbi.agents.getConfig(agentExtId) : await arbi.agentConfig.get("default"),
1069
- enabled: (options?.enabled ?? true) && arbi.isLoggedIn
1070
- });
1071
- }
1072
- function useAgentModels(options) {
1073
- const arbi = chunkZMTLGO3K_cjs.useArbi();
1074
- return reactQuery.useQuery({
1075
- queryKey: chunkKXIIARRK_cjs.arbiQueryKeys.models(),
1076
- queryFn: async () => (await arbi.agentConfig.getModels()).models.map((m) => m.model_name),
1077
- enabled: (options?.enabled ?? true) && arbi.isLoggedIn
1078
- });
1079
- }
1080
- function useSaveAgentConfig() {
1081
- const arbi = chunkZMTLGO3K_cjs.useArbi();
1082
- const qc = reactQuery.useQueryClient();
1083
- return reactQuery.useMutation({
1084
- mutationFn: async ({ agentExtId, title, sections }) => {
1085
- const pinned = await arbi.agents.getConfig(agentExtId);
1086
- const base = pinned ?? await arbi.agentConfig.get("default");
1087
- const merged = structuredClone(base);
1088
- for (const [section, params] of Object.entries(sections)) {
1089
- merged[section] = { ...merged[section] ?? {}, ...params };
1090
- }
1091
- return arbi.agentConfig.save({
1092
- ...merged,
1093
- agent_ext_id: agentExtId,
1094
- title: title ?? `agent-${agentExtId}`
1095
- });
1096
- },
1097
- onSuccess: (_saved, { agentExtId }) => Promise.all([
1098
- qc.invalidateQueries({ queryKey: chunkKXIIARRK_cjs.arbiQueryKeys.configs() }),
1099
- qc.invalidateQueries({ queryKey: chunkKXIIARRK_cjs.arbiQueryKeys.agentConfig(agentExtId) }),
1100
- // The agent list shows the pinned persona/model, so it refreshes too.
1101
- qc.invalidateQueries({ queryKey: chunkKXIIARRK_cjs.arbiQueryKeys.agents() })
1102
- ])
1103
- });
1104
- }
1105
- function useAgentWorkspaces(agentExtId, options) {
1106
- const arbi = chunkZMTLGO3K_cjs.useArbi();
1107
- return reactQuery.useQuery({
1108
- queryKey: chunkKXIIARRK_cjs.arbiQueryKeys.agentWorkspaces(agentExtId ?? ""),
1109
- queryFn: () => arbi.agents.listWorkspaces(agentExtId),
1110
- enabled: (options?.enabled ?? true) && !!agentExtId && arbi.isLoggedIn
1111
- });
1112
- }
1113
- function useGrantAgentAccess() {
1114
- const arbi = chunkZMTLGO3K_cjs.useArbi();
1115
- const qc = reactQuery.useQueryClient();
1116
- return reactQuery.useMutation({
1117
- mutationFn: async ({
1118
- agentExtId,
1119
- workspaceId,
1120
- mode = { kind: "standing" }
1121
- }) => {
1122
- if (mode.kind === "temporary") {
1123
- return arbi.agents.grantTemporaryAccess(agentExtId, workspaceId, mode.ttlSeconds);
1124
- }
1125
- const agent = (await arbi.agents.list()).find((a) => a.external_id === agentExtId);
1126
- if (!agent?.email) throw new Error("The agent's address is unknown.");
1127
- return arbi.workspaces.grantAccess({ workspaceId, emails: [agent.email] });
1128
- },
1129
- onSuccess: (_res, { agentExtId }) => qc.invalidateQueries({ queryKey: chunkKXIIARRK_cjs.arbiQueryKeys.agentWorkspaces(agentExtId) })
1130
- });
1131
- }
1132
- function useRevokeAgentAccess() {
1133
- const arbi = chunkZMTLGO3K_cjs.useArbi();
1134
- const qc = reactQuery.useQueryClient();
1135
- return reactQuery.useMutation({
1136
- mutationFn: async ({
1137
- agentExtId,
1138
- workspaceId
1139
- }) => {
1140
- const previous = arbi.hasWorkspace ? arbi.getWorkspaceId() : null;
1141
- await arbi.selectWorkspace(workspaceId);
1142
- try {
1143
- await arbi.workspaces.removeUsers([agentExtId]);
1144
- } finally {
1145
- if (previous && previous !== workspaceId) await arbi.selectWorkspace(previous);
1146
- }
1147
- },
1148
- onSuccess: (_res, { agentExtId }) => qc.invalidateQueries({ queryKey: chunkKXIIARRK_cjs.arbiQueryKeys.agentWorkspaces(agentExtId) })
1149
- });
1150
- }
1151
- function useSkills(options) {
1152
- const arbi = chunkZMTLGO3K_cjs.useArbi();
1153
- return reactQuery.useQuery({
1154
- queryKey: [...chunkKXIIARRK_cjs.arbiQueryKeys.skills(), options?.includeHidden ?? false],
1155
- queryFn: () => arbi.assistant.listSkills({ includeHidden: options?.includeHidden }),
1156
- enabled: (options?.enabled ?? true) && arbi.isLoggedIn,
1157
- staleTime: 3e4
1158
- });
1159
- }
1160
1465
  function useContacts(options) {
1161
1466
  const arbi = chunkZMTLGO3K_cjs.useArbi();
1162
1467
  return reactQuery.useQuery({
1163
- queryKey: chunkKXIIARRK_cjs.arbiQueryKeys.contacts(),
1468
+ queryKey: chunk6BLXIF4R_cjs.arbiQueryKeys.contacts(),
1164
1469
  queryFn: () => arbi.contacts.list(),
1165
1470
  enabled: (options?.enabled ?? true) && arbi.isLoggedIn
1166
1471
  });
@@ -1180,7 +1485,7 @@ function useAddContacts() {
1180
1485
  const qc = reactQuery.useQueryClient();
1181
1486
  return reactQuery.useMutation({
1182
1487
  mutationFn: (emails) => arbi.contacts.add(emails),
1183
- onSuccess: () => qc.invalidateQueries({ queryKey: chunkKXIIARRK_cjs.arbiQueryKeys.contacts() })
1488
+ onSuccess: () => qc.invalidateQueries({ queryKey: chunk6BLXIF4R_cjs.arbiQueryKeys.contacts() })
1184
1489
  });
1185
1490
  }
1186
1491
  function useRemoveContacts() {
@@ -1188,7 +1493,7 @@ function useRemoveContacts() {
1188
1493
  const qc = reactQuery.useQueryClient();
1189
1494
  return reactQuery.useMutation({
1190
1495
  mutationFn: (contactIds) => arbi.contacts.remove(contactIds),
1191
- onSuccess: () => qc.invalidateQueries({ queryKey: chunkKXIIARRK_cjs.arbiQueryKeys.contacts() })
1496
+ onSuccess: () => qc.invalidateQueries({ queryKey: chunk6BLXIF4R_cjs.arbiQueryKeys.contacts() })
1192
1497
  });
1193
1498
  }
1194
1499
  function toProfileView(profile) {
@@ -1200,7 +1505,7 @@ function toProfileView(profile) {
1200
1505
  function useProfile(options) {
1201
1506
  const arbi = chunkZMTLGO3K_cjs.useArbi();
1202
1507
  return reactQuery.useQuery({
1203
- queryKey: chunkKXIIARRK_cjs.arbiQueryKeys.profile(),
1508
+ queryKey: chunk6BLXIF4R_cjs.arbiQueryKeys.profile(),
1204
1509
  queryFn: () => {
1205
1510
  const profile = arbi.user.profile();
1206
1511
  return profile ? toProfileView(profile) : null;
@@ -1223,8 +1528,8 @@ function useUpdateProfile() {
1223
1528
  return profile ? toProfileView(profile) : null;
1224
1529
  },
1225
1530
  onSuccess: (profile) => {
1226
- qc.setQueryData(chunkKXIIARRK_cjs.arbiQueryKeys.profile(), profile);
1227
- return qc.invalidateQueries({ queryKey: chunkKXIIARRK_cjs.arbiQueryKeys.workspaces() });
1531
+ qc.setQueryData(chunk6BLXIF4R_cjs.arbiQueryKeys.profile(), profile);
1532
+ return qc.invalidateQueries({ queryKey: chunk6BLXIF4R_cjs.arbiQueryKeys.workspaces() });
1228
1533
  }
1229
1534
  });
1230
1535
  }
@@ -1309,7 +1614,7 @@ function useConfirmEmailChange() {
1309
1614
  mutationFn: ({ newEmail, code }) => arbi.account.confirmEmailChange(newEmail, code),
1310
1615
  onSuccess: () => {
1311
1616
  const profile = arbi.user.profile();
1312
- qc.setQueryData(chunkKXIIARRK_cjs.arbiQueryKeys.profile(), profile ? toProfileView(profile) : null);
1617
+ qc.setQueryData(chunk6BLXIF4R_cjs.arbiQueryKeys.profile(), profile ? toProfileView(profile) : null);
1313
1618
  }
1314
1619
  });
1315
1620
  }
@@ -1478,7 +1783,7 @@ function toNotificationPreferences(stored, keys) {
1478
1783
  function useUserSettings(options) {
1479
1784
  const arbi = chunkZMTLGO3K_cjs.useArbi();
1480
1785
  return reactQuery.useQuery({
1481
- queryKey: chunkKXIIARRK_cjs.arbiQueryKeys.userSettings(),
1786
+ queryKey: chunk6BLXIF4R_cjs.arbiQueryKeys.userSettings(),
1482
1787
  queryFn: () => arbi.settings.get(),
1483
1788
  enabled: (options?.enabled ?? true) && arbi.isLoggedIn
1484
1789
  });
@@ -1491,18 +1796,18 @@ function useNotificationPreferences(keys, options) {
1491
1796
  const save = reactQuery.useMutation({
1492
1797
  mutationFn: (patch) => arbi.settings.update({ email_notifications: patch }),
1493
1798
  onMutate: async (patch) => {
1494
- await qc.cancelQueries({ queryKey: chunkKXIIARRK_cjs.arbiQueryKeys.userSettings() });
1495
- const previous = qc.getQueryData(chunkKXIIARRK_cjs.arbiQueryKeys.userSettings());
1799
+ await qc.cancelQueries({ queryKey: chunk6BLXIF4R_cjs.arbiQueryKeys.userSettings() });
1800
+ const previous = qc.getQueryData(chunk6BLXIF4R_cjs.arbiQueryKeys.userSettings());
1496
1801
  qc.setQueryData(
1497
- chunkKXIIARRK_cjs.arbiQueryKeys.userSettings(),
1802
+ chunk6BLXIF4R_cjs.arbiQueryKeys.userSettings(),
1498
1803
  (old) => old ? { ...old, email_notifications: { ...old.email_notifications, ...patch } } : old
1499
1804
  );
1500
1805
  return { previous };
1501
1806
  },
1502
1807
  onError: (_err, _patch, context) => {
1503
- qc.setQueryData(chunkKXIIARRK_cjs.arbiQueryKeys.userSettings(), context?.previous);
1808
+ qc.setQueryData(chunk6BLXIF4R_cjs.arbiQueryKeys.userSettings(), context?.previous);
1504
1809
  },
1505
- onSettled: () => qc.invalidateQueries({ queryKey: chunkKXIIARRK_cjs.arbiQueryKeys.userSettings() })
1810
+ onSettled: () => qc.invalidateQueries({ queryKey: chunk6BLXIF4R_cjs.arbiQueryKeys.userSettings() })
1506
1811
  });
1507
1812
  const model = React.useMemo(() => toNotificationPreferences(stored, keys), [stored, keys]);
1508
1813
  const setAll = React.useCallback(
@@ -1528,7 +1833,7 @@ function useTerminateSession() {
1528
1833
  const qc = reactQuery.useQueryClient();
1529
1834
  return reactQuery.useMutation({
1530
1835
  mutationFn: (sessionId) => arbi.sessions.terminate(sessionId),
1531
- onSuccess: () => qc.invalidateQueries({ queryKey: chunkKXIIARRK_cjs.arbiQueryKeys.sessions() })
1836
+ onSuccess: () => qc.invalidateQueries({ queryKey: chunk6BLXIF4R_cjs.arbiQueryKeys.sessions() })
1532
1837
  });
1533
1838
  }
1534
1839
  function useLogoutAllSessions() {
@@ -1604,7 +1909,7 @@ function useDeleteAccountFlow({
1604
1909
  };
1605
1910
  }
1606
1911
  function useWorkspaceDocs(workspaceId) {
1607
- const { data: docs = [], isLoading, isError } = chunkKXIIARRK_cjs.useDocuments(workspaceId);
1912
+ const { data: docs = [], isLoading, isError } = chunk6BLXIF4R_cjs.useDocuments(workspaceId);
1608
1913
  const docIds = React.useMemo(
1609
1914
  () => docs.map((d) => d.external_id).filter((id) => !!id),
1610
1915
  [docs]
@@ -1612,7 +1917,7 @@ function useWorkspaceDocs(workspaceId) {
1612
1917
  return { wsId: workspaceId, docs, docIds, isLoading, isError, ready: docIds.length > 0 };
1613
1918
  }
1614
1919
  function useAiTask() {
1615
- const mutation = chunkKXIIARRK_cjs.useAssistantQuery();
1920
+ const mutation = chunk6BLXIF4R_cjs.useAssistantQuery();
1616
1921
  const [status, setStatus] = React.useState("idle");
1617
1922
  const [text, setText] = React.useState("");
1618
1923
  const [stepCount, setStepCount] = React.useState(0);
@@ -2205,8 +2510,8 @@ function DocumentReview({
2205
2510
  onClose,
2206
2511
  className
2207
2512
  }) {
2208
- const parsedQuery = chunkKXIIARRK_cjs.useParsedDocument(docId, stage);
2209
- const tagsQuery = chunkKXIIARRK_cjs.useTags(workspaceId);
2513
+ const parsedQuery = chunk6BLXIF4R_cjs.useParsedDocument(docId, stage);
2514
+ const tagsQuery = chunk6BLXIF4R_cjs.useTags(workspaceId);
2210
2515
  const tagNameById = React__default.default.useMemo(() => {
2211
2516
  const map = /* @__PURE__ */ new Map();
2212
2517
  for (const t of tagsQuery.data ?? []) {
@@ -2437,7 +2742,7 @@ function SemanticSearch({
2437
2742
  const { results, status, error, search, isRunning, query } = useSemanticSearch(docIds);
2438
2743
  const [value, setValue] = React.useState("");
2439
2744
  const [selected, setSelected] = React.useState(null);
2440
- const { data: docs = [] } = chunkKXIIARRK_cjs.useDocuments(workspaceId, { enabled: !!workspaceId });
2745
+ const { data: docs = [] } = chunk6BLXIF4R_cjs.useDocuments(workspaceId, { enabled: !!workspaceId });
2441
2746
  const docMap = React.useMemo(() => {
2442
2747
  const map = /* @__PURE__ */ new Map();
2443
2748
  for (const d of docs) if (d.external_id) map.set(d.external_id, d);
@@ -3723,7 +4028,7 @@ function ActivityFeed({
3723
4028
  enabled,
3724
4029
  "data-testid": testId = "activity-feed"
3725
4030
  }) {
3726
- const { data, isLoading, isError } = chunkKXIIARRK_cjs.useActivity({ limit, enabled });
4031
+ const { data, isLoading, isError } = chunk6BLXIF4R_cjs.useActivity({ limit, enabled });
3727
4032
  if (isLoading) {
3728
4033
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: chunkS6A6FSG7_cjs.cn("space-y-2", className), "data-testid": testId, "aria-busy": "true", children: Array.from({ length: 3 }).map((_, i) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-3 py-1.5", children: [
3729
4034
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "h-4 w-4 shrink-0 animate-pulse rounded-full bg-muted" }),
@@ -3764,6 +4069,34 @@ function ActivityFeed({
3764
4069
  );
3765
4070
  }) });
3766
4071
  }
4072
+ var workTypes = [
4073
+ "mention",
4074
+ "workspace_access_request",
4075
+ "conversation_ready_for_review",
4076
+ "conversation_approval_request",
4077
+ "conversation_done",
4078
+ "workflow_failed"
4079
+ ];
4080
+ function useWorkNotifications(options) {
4081
+ const arbi = chunkZMTLGO3K_cjs.useArbi();
4082
+ const queries = reactQuery.useQueryClient();
4083
+ const queryKey = ["work-notifications", options.apiUrl, options.userId];
4084
+ const query = reactQuery.useQuery({
4085
+ queryKey,
4086
+ queryFn: async () => (await Promise.all(workTypes.map((type) => arbi.notifications.list(type)))).flat(),
4087
+ enabled: options.enabled && Boolean(options.userId),
4088
+ refetchInterval: 3e4
4089
+ });
4090
+ useArbiWebSocket((message) => {
4091
+ if (workTypes.some((type) => type === message.type))
4092
+ void queries.invalidateQueries({ queryKey });
4093
+ });
4094
+ const receipt = reactQuery.useMutation({
4095
+ mutationFn: (ids) => arbi.notifications.markRead(ids),
4096
+ onSuccess: () => queries.invalidateQueries({ queryKey })
4097
+ });
4098
+ return { ...query, markRead: receipt.mutateAsync };
4099
+ }
3767
4100
 
3768
4101
  // src/directmessages/utils.ts
3769
4102
  function userInitials(user) {
@@ -3847,7 +4180,7 @@ function useDirectMessages(options) {
3847
4180
  enabled
3848
4181
  });
3849
4182
  const contactsQuery = reactQuery.useQuery({
3850
- queryKey: chunkKXIIARRK_cjs.arbiQueryKeys.contacts(),
4183
+ queryKey: chunk6BLXIF4R_cjs.arbiQueryKeys.contacts(),
3851
4184
  queryFn: () => arbi.contacts.list(),
3852
4185
  enabled
3853
4186
  });
@@ -4024,7 +4357,7 @@ function ConversationList({
4024
4357
  children: c.subtitle ?? preview
4025
4358
  }
4026
4359
  ),
4027
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "shrink-0 text-xs text-muted-foreground", children: lastMessage ? chunkPGLV23SB_cjs.formatRelativeTime(lastMessage.createdAt) : "" })
4360
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "shrink-0 text-xs text-muted-foreground", children: lastMessage ? chunkYSZJCWDD_cjs.formatRelativeTime(lastMessage.createdAt) : "" })
4028
4361
  ] })
4029
4362
  ] })
4030
4363
  ] });
@@ -4115,7 +4448,7 @@ function MessageBubble({
4115
4448
  isLastOfRun,
4116
4449
  senderName: message.isMine ? "You" : userDisplayName(message.sender),
4117
4450
  classNames,
4118
- formatTimestamp: chunkPGLV23SB_cjs.formatRelativeTime
4451
+ formatTimestamp: chunkYSZJCWDD_cjs.formatRelativeTime
4119
4452
  }
4120
4453
  );
4121
4454
  }
@@ -4882,10 +5215,10 @@ function DocumentTable({
4882
5215
  extraColumns,
4883
5216
  className
4884
5217
  }) {
4885
- const query = chunkKXIIARRK_cjs.useDocuments(workspaceId, { enabled: !documents });
5218
+ const query = chunk6BLXIF4R_cjs.useDocuments(workspaceId, { enabled: !documents });
4886
5219
  const rows = documents ?? query.data ?? [];
4887
5220
  const isLoading = !documents && query.isLoading;
4888
- const tagsQuery = chunkKXIIARRK_cjs.useTags(workspaceId);
5221
+ const tagsQuery = chunk6BLXIF4R_cjs.useTags(workspaceId);
4889
5222
  const tagNameById = React__default.default.useMemo(() => {
4890
5223
  const map = /* @__PURE__ */ new Map();
4891
5224
  for (const t of tagsQuery.data ?? []) {
@@ -5066,7 +5399,7 @@ function DocumentCardMenu({
5066
5399
  const invalidateDocuments = () => {
5067
5400
  const workspaceId = arbi.getWorkspaceId();
5068
5401
  if (workspaceId) {
5069
- void queryClient.invalidateQueries({ queryKey: chunkKXIIARRK_cjs.arbiQueryKeys.documents(workspaceId) });
5402
+ void queryClient.invalidateQueries({ queryKey: chunk6BLXIF4R_cjs.arbiQueryKeys.documents(workspaceId) });
5070
5403
  }
5071
5404
  };
5072
5405
  const download = reactQuery.useMutation({
@@ -5165,10 +5498,10 @@ function DocumentGallery({
5165
5498
  minTileWidth = 148,
5166
5499
  className
5167
5500
  }) {
5168
- const query = chunkKXIIARRK_cjs.useDocuments(workspaceId, { enabled: !documents });
5501
+ const query = chunk6BLXIF4R_cjs.useDocuments(workspaceId, { enabled: !documents });
5169
5502
  const rows = documents ?? query.data ?? [];
5170
5503
  const isLoading = !documents && query.isLoading;
5171
- const tagsQuery = chunkKXIIARRK_cjs.useTags(workspaceId);
5504
+ const tagsQuery = chunk6BLXIF4R_cjs.useTags(workspaceId);
5172
5505
  const tagNameById = React__default.default.useMemo(() => {
5173
5506
  const map = /* @__PURE__ */ new Map();
5174
5507
  for (const t of tagsQuery.data ?? []) {
@@ -5180,7 +5513,7 @@ function DocumentGallery({
5180
5513
  () => rows.map((d) => d.external_id).filter((id) => !!id),
5181
5514
  [rows]
5182
5515
  );
5183
- const thumbsQuery = chunkKXIIARRK_cjs.useThumbnails(docIds);
5516
+ const thumbsQuery = chunk6BLXIF4R_cjs.useThumbnails(docIds);
5184
5517
  const thumbs = thumbsQuery.data ?? {};
5185
5518
  const storeSelected = useArbiUiStore((s) => s.selectedDocIds);
5186
5519
  const storeSetSelected = useArbiUiStore((s) => s.setSelectedDocIds);
@@ -5216,7 +5549,7 @@ function DocumentGallery({
5216
5549
  setRenamingId(null);
5217
5550
  const activeWorkspace = workspaceId ?? arbi.getWorkspaceId();
5218
5551
  if (activeWorkspace) {
5219
- void queryClient.invalidateQueries({ queryKey: chunkKXIIARRK_cjs.arbiQueryKeys.documents(activeWorkspace) });
5552
+ void queryClient.invalidateQueries({ queryKey: chunk6BLXIF4R_cjs.arbiQueryKeys.documents(activeWorkspace) });
5220
5553
  }
5221
5554
  }
5222
5555
  });
@@ -5834,171 +6167,175 @@ function hasVideoTrack(blob) {
5834
6167
 
5835
6168
  Object.defineProperty(exports, "DEFAULT_USD_PER_CREDIT", {
5836
6169
  enumerable: true,
5837
- get: function () { return chunkKXIIARRK_cjs.DEFAULT_USD_PER_CREDIT; }
6170
+ get: function () { return chunk6BLXIF4R_cjs.DEFAULT_USD_PER_CREDIT; }
5838
6171
  });
5839
6172
  Object.defineProperty(exports, "arbiQueryKeys", {
5840
6173
  enumerable: true,
5841
- get: function () { return chunkKXIIARRK_cjs.arbiQueryKeys; }
6174
+ get: function () { return chunk6BLXIF4R_cjs.arbiQueryKeys; }
5842
6175
  });
5843
6176
  Object.defineProperty(exports, "cleanDraftMarkdown", {
5844
6177
  enumerable: true,
5845
- get: function () { return chunkKXIIARRK_cjs.cleanDraftMarkdown; }
6178
+ get: function () { return chunk6BLXIF4R_cjs.cleanDraftMarkdown; }
5846
6179
  });
5847
6180
  Object.defineProperty(exports, "cleanDraftWithReport", {
5848
6181
  enumerable: true,
5849
- get: function () { return chunkKXIIARRK_cjs.cleanDraftWithReport; }
6182
+ get: function () { return chunk6BLXIF4R_cjs.cleanDraftWithReport; }
5850
6183
  });
5851
6184
  Object.defineProperty(exports, "creditsToUsd", {
5852
6185
  enumerable: true,
5853
- get: function () { return chunkKXIIARRK_cjs.creditsToUsd; }
6186
+ get: function () { return chunk6BLXIF4R_cjs.creditsToUsd; }
5854
6187
  });
5855
6188
  Object.defineProperty(exports, "formatCredits", {
5856
6189
  enumerable: true,
5857
- get: function () { return chunkKXIIARRK_cjs.formatCredits; }
6190
+ get: function () { return chunk6BLXIF4R_cjs.formatCredits; }
5858
6191
  });
5859
6192
  Object.defineProperty(exports, "isUsageMetered", {
5860
6193
  enumerable: true,
5861
- get: function () { return chunkKXIIARRK_cjs.isUsageMetered; }
6194
+ get: function () { return chunk6BLXIF4R_cjs.isUsageMetered; }
5862
6195
  });
5863
6196
  Object.defineProperty(exports, "promoteBoldTitle", {
5864
6197
  enumerable: true,
5865
- get: function () { return chunkKXIIARRK_cjs.promoteBoldTitle; }
6198
+ get: function () { return chunk6BLXIF4R_cjs.promoteBoldTitle; }
5866
6199
  });
5867
6200
  Object.defineProperty(exports, "repairParsedStructure", {
5868
6201
  enumerable: true,
5869
- get: function () { return chunkKXIIARRK_cjs.repairParsedStructure; }
6202
+ get: function () { return chunk6BLXIF4R_cjs.repairParsedStructure; }
5870
6203
  });
5871
6204
  Object.defineProperty(exports, "repairParsedTitle", {
5872
6205
  enumerable: true,
5873
- get: function () { return chunkKXIIARRK_cjs.repairParsedTitle; }
6206
+ get: function () { return chunk6BLXIF4R_cjs.repairParsedTitle; }
5874
6207
  });
5875
6208
  Object.defineProperty(exports, "stripAgentPreamble", {
5876
6209
  enumerable: true,
5877
- get: function () { return chunkKXIIARRK_cjs.stripAgentPreamble; }
6210
+ get: function () { return chunk6BLXIF4R_cjs.stripAgentPreamble; }
5878
6211
  });
5879
6212
  Object.defineProperty(exports, "unescapeMarkdown", {
5880
6213
  enumerable: true,
5881
- get: function () { return chunkKXIIARRK_cjs.unescapeMarkdown; }
6214
+ get: function () { return chunk6BLXIF4R_cjs.unescapeMarkdown; }
5882
6215
  });
5883
6216
  Object.defineProperty(exports, "unwrapCitationLinks", {
5884
6217
  enumerable: true,
5885
- get: function () { return chunkKXIIARRK_cjs.unwrapCitationLinks; }
6218
+ get: function () { return chunk6BLXIF4R_cjs.unwrapCitationLinks; }
5886
6219
  });
5887
6220
  Object.defineProperty(exports, "useActivity", {
5888
6221
  enumerable: true,
5889
- get: function () { return chunkKXIIARRK_cjs.useActivity; }
6222
+ get: function () { return chunk6BLXIF4R_cjs.useActivity; }
5890
6223
  });
5891
6224
  Object.defineProperty(exports, "useAgents", {
5892
6225
  enumerable: true,
5893
- get: function () { return chunkKXIIARRK_cjs.useAgents; }
6226
+ get: function () { return chunk6BLXIF4R_cjs.useAgents; }
5894
6227
  });
5895
6228
  Object.defineProperty(exports, "useAssistantQuery", {
5896
6229
  enumerable: true,
5897
- get: function () { return chunkKXIIARRK_cjs.useAssistantQuery; }
6230
+ get: function () { return chunk6BLXIF4R_cjs.useAssistantQuery; }
5898
6231
  });
5899
6232
  Object.defineProperty(exports, "useConfigs", {
5900
6233
  enumerable: true,
5901
- get: function () { return chunkKXIIARRK_cjs.useConfigs; }
6234
+ get: function () { return chunk6BLXIF4R_cjs.useConfigs; }
5902
6235
  });
5903
6236
  Object.defineProperty(exports, "useConversationThreads", {
5904
6237
  enumerable: true,
5905
- get: function () { return chunkKXIIARRK_cjs.useConversationThreads; }
6238
+ get: function () { return chunk6BLXIF4R_cjs.useConversationThreads; }
5906
6239
  });
5907
6240
  Object.defineProperty(exports, "useConversations", {
5908
6241
  enumerable: true,
5909
- get: function () { return chunkKXIIARRK_cjs.useConversations; }
6242
+ get: function () { return chunk6BLXIF4R_cjs.useConversations; }
5910
6243
  });
5911
6244
  Object.defineProperty(exports, "useDeleteAgents", {
5912
6245
  enumerable: true,
5913
- get: function () { return chunkKXIIARRK_cjs.useDeleteAgents; }
6246
+ get: function () { return chunk6BLXIF4R_cjs.useDeleteAgents; }
5914
6247
  });
5915
6248
  Object.defineProperty(exports, "useDocuments", {
5916
6249
  enumerable: true,
5917
- get: function () { return chunkKXIIARRK_cjs.useDocuments; }
6250
+ get: function () { return chunk6BLXIF4R_cjs.useDocuments; }
5918
6251
  });
5919
6252
  Object.defineProperty(exports, "useFacts", {
5920
6253
  enumerable: true,
5921
- get: function () { return chunkKXIIARRK_cjs.useFacts; }
6254
+ get: function () { return chunk6BLXIF4R_cjs.useFacts; }
5922
6255
  });
5923
6256
  Object.defineProperty(exports, "useHealth", {
5924
6257
  enumerable: true,
5925
- get: function () { return chunkKXIIARRK_cjs.useHealth; }
6258
+ get: function () { return chunk6BLXIF4R_cjs.useHealth; }
5926
6259
  });
5927
6260
  Object.defineProperty(exports, "useParsedDocument", {
5928
6261
  enumerable: true,
5929
- get: function () { return chunkKXIIARRK_cjs.useParsedDocument; }
6262
+ get: function () { return chunk6BLXIF4R_cjs.useParsedDocument; }
5930
6263
  });
5931
6264
  Object.defineProperty(exports, "useProjectInvoices", {
5932
6265
  enumerable: true,
5933
- get: function () { return chunkKXIIARRK_cjs.useProjectInvoices; }
6266
+ get: function () { return chunk6BLXIF4R_cjs.useProjectInvoices; }
5934
6267
  });
5935
6268
  Object.defineProperty(exports, "useProjectUsage", {
5936
6269
  enumerable: true,
5937
- get: function () { return chunkKXIIARRK_cjs.useProjectUsage; }
6270
+ get: function () { return chunk6BLXIF4R_cjs.useProjectUsage; }
5938
6271
  });
5939
6272
  Object.defineProperty(exports, "useProjects", {
5940
6273
  enumerable: true,
5941
- get: function () { return chunkKXIIARRK_cjs.useProjects; }
6274
+ get: function () { return chunk6BLXIF4R_cjs.useProjects; }
5942
6275
  });
5943
6276
  Object.defineProperty(exports, "useProjectsUsage", {
5944
6277
  enumerable: true,
5945
- get: function () { return chunkKXIIARRK_cjs.useProjectsUsage; }
6278
+ get: function () { return chunk6BLXIF4R_cjs.useProjectsUsage; }
5946
6279
  });
5947
6280
  Object.defineProperty(exports, "useSessions", {
5948
6281
  enumerable: true,
5949
- get: function () { return chunkKXIIARRK_cjs.useSessions; }
6282
+ get: function () { return chunk6BLXIF4R_cjs.useSessions; }
5950
6283
  });
5951
6284
  Object.defineProperty(exports, "useTags", {
5952
6285
  enumerable: true,
5953
- get: function () { return chunkKXIIARRK_cjs.useTags; }
6286
+ get: function () { return chunk6BLXIF4R_cjs.useTags; }
5954
6287
  });
5955
6288
  Object.defineProperty(exports, "useThumbnails", {
5956
6289
  enumerable: true,
5957
- get: function () { return chunkKXIIARRK_cjs.useThumbnails; }
6290
+ get: function () { return chunk6BLXIF4R_cjs.useThumbnails; }
5958
6291
  });
5959
6292
  Object.defineProperty(exports, "useUserUsageToday", {
5960
6293
  enumerable: true,
5961
- get: function () { return chunkKXIIARRK_cjs.useUserUsageToday; }
6294
+ get: function () { return chunk6BLXIF4R_cjs.useUserUsageToday; }
6295
+ });
6296
+ Object.defineProperty(exports, "useWorkspaceUsers", {
6297
+ enumerable: true,
6298
+ get: function () { return chunk6BLXIF4R_cjs.useWorkspaceUsers; }
5962
6299
  });
5963
6300
  Object.defineProperty(exports, "useWorkspaces", {
5964
6301
  enumerable: true,
5965
- get: function () { return chunkKXIIARRK_cjs.useWorkspaces; }
6302
+ get: function () { return chunk6BLXIF4R_cjs.useWorkspaces; }
5966
6303
  });
5967
6304
  Object.defineProperty(exports, "DEFAULT_NOTIFY_TONE", {
5968
6305
  enumerable: true,
5969
- get: function () { return chunkPGLV23SB_cjs.DEFAULT_NOTIFY_TONE; }
6306
+ get: function () { return chunkYSZJCWDD_cjs.DEFAULT_NOTIFY_TONE; }
5970
6307
  });
5971
6308
  Object.defineProperty(exports, "NotificationBell", {
5972
6309
  enumerable: true,
5973
- get: function () { return chunkPGLV23SB_cjs.NotificationBell; }
6310
+ get: function () { return chunkYSZJCWDD_cjs.NotificationBell; }
5974
6311
  });
5975
6312
  Object.defineProperty(exports, "Toaster", {
5976
6313
  enumerable: true,
5977
- get: function () { return chunkPGLV23SB_cjs.Toaster; }
6314
+ get: function () { return chunkYSZJCWDD_cjs.Toaster; }
5978
6315
  });
5979
6316
  Object.defineProperty(exports, "formatRelativeTime", {
5980
6317
  enumerable: true,
5981
- get: function () { return chunkPGLV23SB_cjs.formatRelativeTime; }
6318
+ get: function () { return chunkYSZJCWDD_cjs.formatRelativeTime; }
5982
6319
  });
5983
6320
  Object.defineProperty(exports, "notify", {
5984
6321
  enumerable: true,
5985
- get: function () { return chunkPGLV23SB_cjs.notify; }
6322
+ get: function () { return chunkYSZJCWDD_cjs.notify; }
5986
6323
  });
5987
6324
  Object.defineProperty(exports, "seedNotifications", {
5988
6325
  enumerable: true,
5989
- get: function () { return chunkPGLV23SB_cjs.seedNotifications; }
6326
+ get: function () { return chunkYSZJCWDD_cjs.seedNotifications; }
5990
6327
  });
5991
6328
  Object.defineProperty(exports, "selectUnread", {
5992
6329
  enumerable: true,
5993
- get: function () { return chunkPGLV23SB_cjs.selectUnread; }
6330
+ get: function () { return chunkYSZJCWDD_cjs.selectUnread; }
5994
6331
  });
5995
6332
  Object.defineProperty(exports, "toast", {
5996
6333
  enumerable: true,
5997
- get: function () { return chunkPGLV23SB_cjs.toast; }
6334
+ get: function () { return chunkYSZJCWDD_cjs.toast; }
5998
6335
  });
5999
6336
  Object.defineProperty(exports, "useNotify", {
6000
6337
  enumerable: true,
6001
- get: function () { return chunkPGLV23SB_cjs.useNotify; }
6338
+ get: function () { return chunkYSZJCWDD_cjs.useNotify; }
6002
6339
  });
6003
6340
  Object.defineProperty(exports, "AgentBadge", {
6004
6341
  enumerable: true,
@@ -6733,8 +7070,10 @@ exports.toProfileView = toProfileView;
6733
7070
  exports.toRedlineMarkdown = toRedlineMarkdown;
6734
7071
  exports.toShellWorkspace = toShellWorkspace;
6735
7072
  exports.useAddContacts = useAddContacts;
7073
+ exports.useAgentChats = useAgentChats;
6736
7074
  exports.useAgentConfig = useAgentConfig;
6737
7075
  exports.useAgentModels = useAgentModels;
7076
+ exports.useAgentSession = useAgentSession;
6738
7077
  exports.useAgentWorkspaces = useAgentWorkspaces;
6739
7078
  exports.useAiTask = useAiTask;
6740
7079
  exports.useArbiChat = useArbiChat;
@@ -6751,6 +7090,7 @@ exports.useArbiWsTask = useArbiWsTask;
6751
7090
  exports.useArbiWsTasks = useArbiWsTasks;
6752
7091
  exports.useAvatarCrop = useAvatarCrop;
6753
7092
  exports.useCameraStream = useCameraStream;
7093
+ exports.useCloseAgentSession = useCloseAgentSession;
6754
7094
  exports.useCommandPalette = useCommandPalette;
6755
7095
  exports.useConfirmEmailChange = useConfirmEmailChange;
6756
7096
  exports.useContacts = useContacts;
@@ -6785,12 +7125,16 @@ exports.useSaveAgentConfig = useSaveAgentConfig;
6785
7125
  exports.useSemanticSearch = useSemanticSearch;
6786
7126
  exports.useShellWorkspaces = useShellWorkspaces;
6787
7127
  exports.useSkills = useSkills;
7128
+ exports.useStartAgentSession = useStartAgentSession;
7129
+ exports.useStartWorkQuery = useStartWorkQuery;
6788
7130
  exports.useTerminateSession = useTerminateSession;
6789
7131
  exports.useUpdateConversation = useUpdateConversation;
6790
7132
  exports.useUpdateProfile = useUpdateProfile;
6791
7133
  exports.useUpdateWorkflow = useUpdateWorkflow;
7134
+ exports.useUploadSkillFiles = useUploadSkillFiles;
6792
7135
  exports.useUserSettings = useUserSettings;
6793
7136
  exports.useVideoRecorder = useVideoRecorder;
7137
+ exports.useWorkNotifications = useWorkNotifications;
6794
7138
  exports.useWorkflows = useWorkflows;
6795
7139
  exports.useWorkspaceDocs = useWorkspaceDocs;
6796
7140
  exports.userDisplayName = userDisplayName;