@arbidocs/react 0.5.171 → 0.5.172
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.
|
@@ -11,11 +11,12 @@ import {
|
|
|
11
11
|
removeChat,
|
|
12
12
|
upsertChat
|
|
13
13
|
} from "./chat-cache.js";
|
|
14
|
-
function useAgentDmProgress(responseId) {
|
|
14
|
+
function useAgentDmProgress(responseId, workspaceId) {
|
|
15
15
|
const arbi = useArbi();
|
|
16
16
|
return useQuery({
|
|
17
17
|
queryKey: arbiQueryKeys.agentDmProgress(myChatId(arbi) ?? "", responseId ?? ""),
|
|
18
|
-
|
|
18
|
+
// The run is in the agent's Home workspace: opened first, so its output reads at once.
|
|
19
|
+
queryFn: () => arbi.assistant.getResponse(responseId, { workspaceId: workspaceId ?? void 0 }),
|
|
19
20
|
enabled: !!responseId,
|
|
20
21
|
refetchInterval: 1500,
|
|
21
22
|
retry: false
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/directmessages/useChats.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Chat hooks on the one chat cache (`chat-cache.ts`): my chats, unread totals, decrypted list\n * previews, one open thread, and the writes (send, delete, read, groups). Everything runs on the\n * SDK's end-to-end encrypted `arbi.chats`; nothing here touches keys or ciphertext.\n */\n\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react'\nimport { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'\nimport { chats as chatOps } from '@arbidocs/sdk/browser'\nimport { useArbi } from '../useArbi'\nimport { arbiQueryKeys } from '../hooks'\nimport {\n appendToThread,\n deleteChatMessage,\n dropFromThread,\n myChatId,\n removeChat,\n upsertChat,\n type AgentDmStatus,\n type ChatMemberKey,\n type ChatResponse,\n type ChatThreadData,\n type ChatThreadMessage,\n} from './chat-cache'\n\n/** Observe an existing Home run without changing the selected workspace. */\nexport function useAgentDmProgress(responseId: string | null | undefined) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.agentDmProgress(myChatId(arbi) ?? '', responseId ?? ''),\n queryFn: () => arbi.assistant.getResponse(responseId!),\n enabled: !!responseId,\n refetchInterval: 1500,\n retry: false,\n })\n}\n\n/** My chats (raw), most recently active first. */\nexport function useChats(options: { enabled?: boolean } = {}) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.chatList(),\n queryFn: () => arbi.chats.list(),\n enabled: (options.enabled ?? true) && arbi.isLoggedIn,\n })\n}\n\n/** My own agent's latest progress on a message I sent it, live from the chat events. */\nexport function useAgentDmStatus(agentExtId: string | null | undefined): AgentDmStatus | undefined {\n const { data } = useQuery<AgentDmStatus | null>({\n queryKey: arbiQueryKeys.agentDmStatus(agentExtId ?? ''),\n // Written by the events only: nothing to fetch.\n queryFn: () => null,\n enabled: false,\n staleTime: Infinity,\n })\n return agentExtId ? (data ?? undefined) : undefined\n}\n\n/** Unread messages across all my chats (the badge on the messages entry points). */\nexport function useChatUnreadTotal(): number {\n const { data = [] } = useChats()\n return useMemo(() => data.reduce((sum, c) => sum + (c.unread_count ?? 0), 0), [data])\n}\n\n/** Unread count per direct-chat peer (`usr-`/`agt-` id), for per-person badges and filters. */\nexport function useUnreadByPeer(): Map<string, number> {\n const arbi = useArbi()\n const { data = [] } = useChats()\n const me = myChatId(arbi)\n return useMemo(() => {\n const out = new Map<string, number>()\n for (const c of data) {\n if (c.kind !== 'direct' || !c.unread_count) continue\n const peer = c.members.find((m) => m.user.external_id !== me)?.user.external_id ?? me\n if (peer) out.set(peer, (out.get(peer) ?? 0) + c.unread_count)\n }\n return out\n }, [data, me])\n}\n\nexport interface ChatSummary {\n /** Decrypted group title (null for direct chats or one that does not open). */\n title: string | null\n /** Decrypted last message, one line. */\n preview: string | null\n}\n\n/**\n * Decrypted titles and last-message previews for a list of chats. Only the newest message of\n * each chat is decrypted \u2014 a thread decrypts in full when it is opened, and its copy is used.\n */\nexport function useChatSummaries(chats: ChatResponse[]): Record<string, ChatSummary> {\n const arbi = useArbi()\n const queryClient = useQueryClient()\n const [summaries, setSummaries] = useState<Record<string, ChatSummary>>({})\n const runId = useRef(0)\n const key = chats\n .map(\n (c) =>\n `${c.external_id}:${c.key_version}:${c.title ?? ''}:${c.last_message?.external_id ?? ''}:${c.last_message?.deleted ? 'x' : ''}`\n )\n .join('|')\n\n useEffect(() => {\n if (!chats.length || !arbi.isLoggedIn) return\n const id = ++runId.current\n void (async () => {\n const next: Record<string, ChatSummary> = {}\n for (const chat of chats) {\n const title = await arbi.chats.title(chat).catch(() => null)\n // A tombstone is never a preview (nor decrypted): the refetched chat brings the one before.\n const last = chat.last_message?.deleted ? null : chat.last_message\n let preview: string | null = null\n // The open thread's copy: my own post reaches the list already decrypted (as the send\n // returns it), and plaintext does not decrypt.\n const open = queryClient\n .getQueryData<ChatThreadData>(arbiQueryKeys.chatThread(chat.external_id))\n ?.messages.find((m) => m.external_id === last?.external_id)\n if (open) preview = chatOps.chatMessagePreview(open)\n else if (last) {\n preview = await arbi.chats\n .decrypt(chat, last)\n .then(chatOps.chatMessagePreview)\n .catch(() => chatOps.ENCRYPTED_PREVIEW)\n }\n next[chat.external_id] = { title, preview }\n }\n if (id === runId.current) setSummaries(next)\n })()\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [key, arbi])\n\n return summaries\n}\n\n/**\n * One open thread: the newest page decrypted (oldest first), kept live by the chat events, with\n * `loadOlder` paging backwards.\n */\nexport function useChatThread(chat: ChatResponse | null) {\n const arbi = useArbi()\n const queryClient = useQueryClient()\n const chatExtId = chat?.external_id ?? ''\n const chatRef = useRef(chat)\n chatRef.current = chat\n const query = useQuery<ChatThreadData>({\n queryKey: arbiQueryKeys.chatThread(chatExtId),\n queryFn: () => arbi.chats.page(chatRef.current!),\n enabled: !!chat && arbi.isLoggedIn,\n staleTime: Infinity,\n })\n const [loadingOlder, setLoadingOlder] = useState(false)\n\n const loadOlder = useCallback(async () => {\n const key = arbiQueryKeys.chatThread(chatExtId)\n const current = queryClient.getQueryData<ChatThreadData>(key)\n const oldest = current?.messages.find((m) => !m.optimistic)\n if (!chatRef.current || !current?.hasMore || !oldest) return\n setLoadingOlder(true)\n try {\n const page = await arbi.chats.page(chatRef.current, { before: oldest.external_id })\n queryClient.setQueryData<ChatThreadData>(key, (old) =>\n old\n ? {\n hasMore: page.hasMore,\n messages: [\n ...page.messages.filter(\n (m) => !old.messages.some((o) => o.external_id === m.external_id)\n ),\n ...old.messages,\n ],\n }\n : old\n )\n } finally {\n setLoadingOlder(false)\n }\n }, [arbi, queryClient, chatExtId])\n\n return {\n messages: query.data?.messages ?? [],\n hasMore: query.data?.hasMore ?? false,\n isLoading: query.isLoading && !!chat,\n loadOlder,\n loadingOlder,\n }\n}\n\n/** What to post: text, files and (PA chat only) the agent's workspace or a context note. */\nexport interface ChatPost {\n text: string\n files?: File[]\n /** PA chat only: the workspace my agent acts in. */\n workspaceExtId?: string\n /** PA chat only: a note the agent records without replying. */\n contextOnly?: boolean\n}\n\n/**\n * Post to a chat, rendering an optimistic copy at once and swapping in the server's row. With no\n * chat yet, `peerExtId`'s direct chat is opened (created) first. Files are encrypted with their\n * own keys and travel in a manifest under the chat key. A failure drops the optimistic row,\n * refreshes the list (a stale epoch re-keys on the next try) and rethrows.\n */\nexport function useChatPost() {\n const arbi = useArbi()\n const queryClient = useQueryClient()\n return useCallback(\n async (\n target: { chat: ChatResponse | null; peerExtId?: string | null },\n post: ChatPost\n ): Promise<{ chat: ChatResponse; message: chatOps.DecryptedChatMessage }> => {\n const me = myChatId(arbi)\n if (!me) throw new Error('No active session')\n let chat = target.chat\n if (!chat) {\n if (!target.peerExtId) throw new Error('Could not resolve the conversation')\n chat = await arbi.chats.openDirect(target.peerExtId)\n upsertChat(queryClient, chat)\n queryClient.setQueryData<ChatThreadData>(\n arbiQueryKeys.chatThread(chat.external_id),\n (old) => old ?? { messages: [], hasMore: false }\n )\n }\n const files = post.files ?? []\n const optimisticId = `optimistic-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`\n const now = new Date().toISOString()\n const optimistic: ChatThreadMessage = {\n external_id: optimisticId,\n chat_ext_id: chat.external_id,\n sender_ext_id: me,\n kind: 'text',\n content: post.text,\n key_version: chat.key_version,\n deleted: false,\n context_only: !!post.contextOnly,\n workspace_ext_id: post.workspaceExtId ?? null,\n created_at: now,\n updated_at: now,\n optimistic: true,\n }\n appendToThread(queryClient, chat.external_id, optimistic)\n try {\n let attachments: chatOps.ChatAttachmentFile[] = []\n if (files.length) {\n // Refuse before reading any file into memory.\n chatOps.checkChatAttachmentLimits(files)\n attachments = await arbi.chats.uploadAttachments(\n await Promise.all(\n files.map(async (file) => ({\n name: file.name,\n type: file.type,\n bytes: new Uint8Array(await file.arrayBuffer()),\n }))\n )\n )\n }\n const message = await arbi.chats.send(chat, post.text, {\n attachments,\n ...(post.workspaceExtId ? { workspaceExtId: post.workspaceExtId } : {}),\n contextOnly: !!post.contextOnly,\n })\n appendToThread(queryClient, chat.external_id, message, optimisticId)\n upsertChat(queryClient, {\n ...chat,\n last_message: message,\n last_message_at: message.created_at,\n })\n return { chat, message }\n } catch (err) {\n dropFromThread(queryClient, chat.external_id, optimisticId)\n void queryClient.invalidateQueries({ queryKey: arbiQueryKeys.chatList() })\n throw err\n }\n },\n [arbi, queryClient]\n )\n}\n\n/** Delete one of my messages: a tombstone in place at once, rolled back if the delete fails. */\nexport function useDeleteChatMessage() {\n const arbi = useArbi()\n const queryClient = useQueryClient()\n return useCallback(\n (chatExtId: string, messageExtId: string) =>\n deleteChatMessage(arbi, queryClient, chatExtId, messageExtId),\n [arbi, queryClient]\n )\n}\n\n/**\n * Move my read watermark in a chat to a message (or to now). The list shows it read at once; a\n * failure is ignored (the next open tries again).\n */\nexport function useMarkChatRead() {\n const arbi = useArbi()\n const queryClient = useQueryClient()\n return useCallback(\n (chat: ChatResponse, messageExtId?: string) => {\n upsertChat(queryClient, { ...chat, unread_count: 0 })\n return arbi.chats.markRead(chat.external_id, messageExtId).then(\n () => undefined,\n () => undefined\n )\n },\n [arbi, queryClient]\n )\n}\n\n/** Create a group (members need encryption keys; agents are refused) and add it to the list. */\nexport function useCreateGroupChat() {\n const arbi = useArbi()\n const queryClient = useQueryClient()\n return useMutation({\n mutationFn: (params: { title?: string | null; members: ChatMemberKey[] }) =>\n arbi.chats.createGroup(params),\n onSuccess: (chat) => upsertChat(queryClient, chat),\n })\n}\n\n/** Rename a group (the title is encrypted under the current epoch). */\nexport function useRenameChat() {\n const arbi = useArbi()\n const queryClient = useQueryClient()\n return useMutation({\n mutationFn: (vars: { chat: ChatResponse; title: string | null }) =>\n arbi.chats.rename(vars.chat, vars.title),\n onSuccess: (chat) => upsertChat(queryClient, chat),\n })\n}\n\n/** Add people to a group, or to a meeting chat with its call key (`callKey`). */\nexport function useAddChatMembers() {\n const arbi = useArbi()\n const queryClient = useQueryClient()\n return useMutation({\n mutationFn: (vars: {\n chat: ChatResponse\n members: ChatMemberKey[]\n callKey?: Uint8Array | null\n }) => arbi.chats.addMembers(vars.chat, vars.members, { callKey: vars.callKey }),\n onSuccess: (chat) => upsertChat(queryClient, chat),\n })\n}\n\n/**\n * Remove someone from a group (owner) or leave it (my own id). Leaving drops the chat at once;\n * a removal refreshes the list (the chat now has a new epoch).\n */\nexport function useRemoveChatMember() {\n const arbi = useArbi()\n const queryClient = useQueryClient()\n return useMutation({\n mutationFn: (vars: { chat: ChatResponse; userExtId: string }) =>\n arbi.chats.removeMember(vars.chat, vars.userExtId),\n onSuccess: (_data, vars) => {\n if (vars.userExtId === myChatId(arbi)) removeChat(queryClient, vars.chat.external_id)\n else return queryClient.invalidateQueries({ queryKey: arbiQueryKeys.chatList() })\n },\n })\n}\n"],
|
|
5
|
-
"mappings": "AAMA,SAAS,aAAa,WAAW,SAAS,QAAQ,gBAAgB;AAClE,SAAS,aAAa,UAAU,sBAAsB;AACtD,SAAS,SAAS,eAAe;AACjC,SAAS,eAAe;AACxB,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAMK;AAGA,SAAS,
|
|
4
|
+
"sourcesContent": ["/**\n * Chat hooks on the one chat cache (`chat-cache.ts`): my chats, unread totals, decrypted list\n * previews, one open thread, and the writes (send, delete, read, groups). Everything runs on the\n * SDK's end-to-end encrypted `arbi.chats`; nothing here touches keys or ciphertext.\n */\n\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react'\nimport { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'\nimport { chats as chatOps } from '@arbidocs/sdk/browser'\nimport { useArbi } from '../useArbi'\nimport { arbiQueryKeys } from '../hooks'\nimport {\n appendToThread,\n deleteChatMessage,\n dropFromThread,\n myChatId,\n removeChat,\n upsertChat,\n type AgentDmStatus,\n type ChatMemberKey,\n type ChatResponse,\n type ChatThreadData,\n type ChatThreadMessage,\n} from './chat-cache'\n\n/** Observe an existing Home run without changing the selected workspace. */\nexport function useAgentDmProgress(\n responseId: string | null | undefined,\n workspaceId?: string | null\n) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.agentDmProgress(myChatId(arbi) ?? '', responseId ?? ''),\n // The run is in the agent's Home workspace: opened first, so its output reads at once.\n queryFn: () =>\n arbi.assistant.getResponse(responseId!, { workspaceId: workspaceId ?? undefined }),\n enabled: !!responseId,\n refetchInterval: 1500,\n retry: false,\n })\n}\n\n/** My chats (raw), most recently active first. */\nexport function useChats(options: { enabled?: boolean } = {}) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.chatList(),\n queryFn: () => arbi.chats.list(),\n enabled: (options.enabled ?? true) && arbi.isLoggedIn,\n })\n}\n\n/** My own agent's latest progress on a message I sent it, live from the chat events. */\nexport function useAgentDmStatus(agentExtId: string | null | undefined): AgentDmStatus | undefined {\n const { data } = useQuery<AgentDmStatus | null>({\n queryKey: arbiQueryKeys.agentDmStatus(agentExtId ?? ''),\n // Written by the events only: nothing to fetch.\n queryFn: () => null,\n enabled: false,\n staleTime: Infinity,\n })\n return agentExtId ? (data ?? undefined) : undefined\n}\n\n/** Unread messages across all my chats (the badge on the messages entry points). */\nexport function useChatUnreadTotal(): number {\n const { data = [] } = useChats()\n return useMemo(() => data.reduce((sum, c) => sum + (c.unread_count ?? 0), 0), [data])\n}\n\n/** Unread count per direct-chat peer (`usr-`/`agt-` id), for per-person badges and filters. */\nexport function useUnreadByPeer(): Map<string, number> {\n const arbi = useArbi()\n const { data = [] } = useChats()\n const me = myChatId(arbi)\n return useMemo(() => {\n const out = new Map<string, number>()\n for (const c of data) {\n if (c.kind !== 'direct' || !c.unread_count) continue\n const peer = c.members.find((m) => m.user.external_id !== me)?.user.external_id ?? me\n if (peer) out.set(peer, (out.get(peer) ?? 0) + c.unread_count)\n }\n return out\n }, [data, me])\n}\n\nexport interface ChatSummary {\n /** Decrypted group title (null for direct chats or one that does not open). */\n title: string | null\n /** Decrypted last message, one line. */\n preview: string | null\n}\n\n/**\n * Decrypted titles and last-message previews for a list of chats. Only the newest message of\n * each chat is decrypted \u2014 a thread decrypts in full when it is opened, and its copy is used.\n */\nexport function useChatSummaries(chats: ChatResponse[]): Record<string, ChatSummary> {\n const arbi = useArbi()\n const queryClient = useQueryClient()\n const [summaries, setSummaries] = useState<Record<string, ChatSummary>>({})\n const runId = useRef(0)\n const key = chats\n .map(\n (c) =>\n `${c.external_id}:${c.key_version}:${c.title ?? ''}:${c.last_message?.external_id ?? ''}:${c.last_message?.deleted ? 'x' : ''}`\n )\n .join('|')\n\n useEffect(() => {\n if (!chats.length || !arbi.isLoggedIn) return\n const id = ++runId.current\n void (async () => {\n const next: Record<string, ChatSummary> = {}\n for (const chat of chats) {\n const title = await arbi.chats.title(chat).catch(() => null)\n // A tombstone is never a preview (nor decrypted): the refetched chat brings the one before.\n const last = chat.last_message?.deleted ? null : chat.last_message\n let preview: string | null = null\n // The open thread's copy: my own post reaches the list already decrypted (as the send\n // returns it), and plaintext does not decrypt.\n const open = queryClient\n .getQueryData<ChatThreadData>(arbiQueryKeys.chatThread(chat.external_id))\n ?.messages.find((m) => m.external_id === last?.external_id)\n if (open) preview = chatOps.chatMessagePreview(open)\n else if (last) {\n preview = await arbi.chats\n .decrypt(chat, last)\n .then(chatOps.chatMessagePreview)\n .catch(() => chatOps.ENCRYPTED_PREVIEW)\n }\n next[chat.external_id] = { title, preview }\n }\n if (id === runId.current) setSummaries(next)\n })()\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [key, arbi])\n\n return summaries\n}\n\n/**\n * One open thread: the newest page decrypted (oldest first), kept live by the chat events, with\n * `loadOlder` paging backwards.\n */\nexport function useChatThread(chat: ChatResponse | null) {\n const arbi = useArbi()\n const queryClient = useQueryClient()\n const chatExtId = chat?.external_id ?? ''\n const chatRef = useRef(chat)\n chatRef.current = chat\n const query = useQuery<ChatThreadData>({\n queryKey: arbiQueryKeys.chatThread(chatExtId),\n queryFn: () => arbi.chats.page(chatRef.current!),\n enabled: !!chat && arbi.isLoggedIn,\n staleTime: Infinity,\n })\n const [loadingOlder, setLoadingOlder] = useState(false)\n\n const loadOlder = useCallback(async () => {\n const key = arbiQueryKeys.chatThread(chatExtId)\n const current = queryClient.getQueryData<ChatThreadData>(key)\n const oldest = current?.messages.find((m) => !m.optimistic)\n if (!chatRef.current || !current?.hasMore || !oldest) return\n setLoadingOlder(true)\n try {\n const page = await arbi.chats.page(chatRef.current, { before: oldest.external_id })\n queryClient.setQueryData<ChatThreadData>(key, (old) =>\n old\n ? {\n hasMore: page.hasMore,\n messages: [\n ...page.messages.filter(\n (m) => !old.messages.some((o) => o.external_id === m.external_id)\n ),\n ...old.messages,\n ],\n }\n : old\n )\n } finally {\n setLoadingOlder(false)\n }\n }, [arbi, queryClient, chatExtId])\n\n return {\n messages: query.data?.messages ?? [],\n hasMore: query.data?.hasMore ?? false,\n isLoading: query.isLoading && !!chat,\n loadOlder,\n loadingOlder,\n }\n}\n\n/** What to post: text, files and (PA chat only) the agent's workspace or a context note. */\nexport interface ChatPost {\n text: string\n files?: File[]\n /** PA chat only: the workspace my agent acts in. */\n workspaceExtId?: string\n /** PA chat only: a note the agent records without replying. */\n contextOnly?: boolean\n}\n\n/**\n * Post to a chat, rendering an optimistic copy at once and swapping in the server's row. With no\n * chat yet, `peerExtId`'s direct chat is opened (created) first. Files are encrypted with their\n * own keys and travel in a manifest under the chat key. A failure drops the optimistic row,\n * refreshes the list (a stale epoch re-keys on the next try) and rethrows.\n */\nexport function useChatPost() {\n const arbi = useArbi()\n const queryClient = useQueryClient()\n return useCallback(\n async (\n target: { chat: ChatResponse | null; peerExtId?: string | null },\n post: ChatPost\n ): Promise<{ chat: ChatResponse; message: chatOps.DecryptedChatMessage }> => {\n const me = myChatId(arbi)\n if (!me) throw new Error('No active session')\n let chat = target.chat\n if (!chat) {\n if (!target.peerExtId) throw new Error('Could not resolve the conversation')\n chat = await arbi.chats.openDirect(target.peerExtId)\n upsertChat(queryClient, chat)\n queryClient.setQueryData<ChatThreadData>(\n arbiQueryKeys.chatThread(chat.external_id),\n (old) => old ?? { messages: [], hasMore: false }\n )\n }\n const files = post.files ?? []\n const optimisticId = `optimistic-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`\n const now = new Date().toISOString()\n const optimistic: ChatThreadMessage = {\n external_id: optimisticId,\n chat_ext_id: chat.external_id,\n sender_ext_id: me,\n kind: 'text',\n content: post.text,\n key_version: chat.key_version,\n deleted: false,\n context_only: !!post.contextOnly,\n workspace_ext_id: post.workspaceExtId ?? null,\n created_at: now,\n updated_at: now,\n optimistic: true,\n }\n appendToThread(queryClient, chat.external_id, optimistic)\n try {\n let attachments: chatOps.ChatAttachmentFile[] = []\n if (files.length) {\n // Refuse before reading any file into memory.\n chatOps.checkChatAttachmentLimits(files)\n attachments = await arbi.chats.uploadAttachments(\n await Promise.all(\n files.map(async (file) => ({\n name: file.name,\n type: file.type,\n bytes: new Uint8Array(await file.arrayBuffer()),\n }))\n )\n )\n }\n const message = await arbi.chats.send(chat, post.text, {\n attachments,\n ...(post.workspaceExtId ? { workspaceExtId: post.workspaceExtId } : {}),\n contextOnly: !!post.contextOnly,\n })\n appendToThread(queryClient, chat.external_id, message, optimisticId)\n upsertChat(queryClient, {\n ...chat,\n last_message: message,\n last_message_at: message.created_at,\n })\n return { chat, message }\n } catch (err) {\n dropFromThread(queryClient, chat.external_id, optimisticId)\n void queryClient.invalidateQueries({ queryKey: arbiQueryKeys.chatList() })\n throw err\n }\n },\n [arbi, queryClient]\n )\n}\n\n/** Delete one of my messages: a tombstone in place at once, rolled back if the delete fails. */\nexport function useDeleteChatMessage() {\n const arbi = useArbi()\n const queryClient = useQueryClient()\n return useCallback(\n (chatExtId: string, messageExtId: string) =>\n deleteChatMessage(arbi, queryClient, chatExtId, messageExtId),\n [arbi, queryClient]\n )\n}\n\n/**\n * Move my read watermark in a chat to a message (or to now). The list shows it read at once; a\n * failure is ignored (the next open tries again).\n */\nexport function useMarkChatRead() {\n const arbi = useArbi()\n const queryClient = useQueryClient()\n return useCallback(\n (chat: ChatResponse, messageExtId?: string) => {\n upsertChat(queryClient, { ...chat, unread_count: 0 })\n return arbi.chats.markRead(chat.external_id, messageExtId).then(\n () => undefined,\n () => undefined\n )\n },\n [arbi, queryClient]\n )\n}\n\n/** Create a group (members need encryption keys; agents are refused) and add it to the list. */\nexport function useCreateGroupChat() {\n const arbi = useArbi()\n const queryClient = useQueryClient()\n return useMutation({\n mutationFn: (params: { title?: string | null; members: ChatMemberKey[] }) =>\n arbi.chats.createGroup(params),\n onSuccess: (chat) => upsertChat(queryClient, chat),\n })\n}\n\n/** Rename a group (the title is encrypted under the current epoch). */\nexport function useRenameChat() {\n const arbi = useArbi()\n const queryClient = useQueryClient()\n return useMutation({\n mutationFn: (vars: { chat: ChatResponse; title: string | null }) =>\n arbi.chats.rename(vars.chat, vars.title),\n onSuccess: (chat) => upsertChat(queryClient, chat),\n })\n}\n\n/** Add people to a group, or to a meeting chat with its call key (`callKey`). */\nexport function useAddChatMembers() {\n const arbi = useArbi()\n const queryClient = useQueryClient()\n return useMutation({\n mutationFn: (vars: {\n chat: ChatResponse\n members: ChatMemberKey[]\n callKey?: Uint8Array | null\n }) => arbi.chats.addMembers(vars.chat, vars.members, { callKey: vars.callKey }),\n onSuccess: (chat) => upsertChat(queryClient, chat),\n })\n}\n\n/**\n * Remove someone from a group (owner) or leave it (my own id). Leaving drops the chat at once;\n * a removal refreshes the list (the chat now has a new epoch).\n */\nexport function useRemoveChatMember() {\n const arbi = useArbi()\n const queryClient = useQueryClient()\n return useMutation({\n mutationFn: (vars: { chat: ChatResponse; userExtId: string }) =>\n arbi.chats.removeMember(vars.chat, vars.userExtId),\n onSuccess: (_data, vars) => {\n if (vars.userExtId === myChatId(arbi)) removeChat(queryClient, vars.chat.external_id)\n else return queryClient.invalidateQueries({ queryKey: arbiQueryKeys.chatList() })\n },\n })\n}\n"],
|
|
5
|
+
"mappings": "AAMA,SAAS,aAAa,WAAW,SAAS,QAAQ,gBAAgB;AAClE,SAAS,aAAa,UAAU,sBAAsB;AACtD,SAAS,SAAS,eAAe;AACjC,SAAS,eAAe;AACxB,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAMK;AAGA,SAAS,mBACd,YACA,aACA;AACA,QAAM,OAAO,QAAQ;AACrB,SAAO,SAAS;AAAA,IACd,UAAU,cAAc,gBAAgB,SAAS,IAAI,KAAK,IAAI,cAAc,EAAE;AAAA;AAAA,IAE9E,SAAS,MACP,KAAK,UAAU,YAAY,YAAa,EAAE,aAAa,eAAe,OAAU,CAAC;AAAA,IACnF,SAAS,CAAC,CAAC;AAAA,IACX,iBAAiB;AAAA,IACjB,OAAO;AAAA,EACT,CAAC;AACH;AAGO,SAAS,SAAS,UAAiC,CAAC,GAAG;AAC5D,QAAM,OAAO,QAAQ;AACrB,SAAO,SAAS;AAAA,IACd,UAAU,cAAc,SAAS;AAAA,IACjC,SAAS,M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,gBAAgB;AAC9B,QAAM,OAAO,QAAQ;AACrB,QAAM,cAAc,eAAe;AACnC,SAAO,YAAY;AAAA,IACjB,YAAY,CAAC,SACX,KAAK,MAAM,OAAO,KAAK,MAAM,KAAK,KAAK;AAAA,IACzC,WAAW,CAAC,SAAS,WAAW,aAAa,IAAI;AAAA,EACnD,CAAC;AACH;AAGO,SAAS,oBAAoB;AAClC,QAAM,OAAO,QAAQ;AACrB,QAAM,cAAc,eAAe;AACnC,SAAO,YAAY;AAAA,IACjB,YAAY,CAAC,SAIP,KAAK,MAAM,WAAW,KAAK,MAAM,KAAK,SAAS,EAAE,SAAS,KAAK,QAAQ,CAAC;AAAA,IAC9E,WAAW,CAAC,SAAS,WAAW,aAAa,IAAI;AAAA,EACnD,CAAC;AACH;AAMO,SAAS,sBAAsB;AACpC,QAAM,OAAO,QAAQ;AACrB,QAAM,cAAc,eAAe;AACnC,SAAO,YAAY;AAAA,IACjB,YAAY,CAAC,SACX,KAAK,MAAM,aAAa,KAAK,MAAM,KAAK,SAAS;AAAA,IACnD,WAAW,CAAC,OAAO,SAAS;AAC1B,UAAI,KAAK,cAAc,SAAS,IAAI,EAAG,YAAW,aAAa,KAAK,KAAK,WAAW;AAAA,UAC/E,QAAO,YAAY,kBAAkB,EAAE,UAAU,cAAc,SAAS,EAAE,CAAC;AAAA,IAClF;AAAA,EACF,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -12568,9 +12568,7 @@ function createIDBPersister() {
|
|
|
12568
12568
|
if (!persisted) return persisted;
|
|
12569
12569
|
const isOffline = typeof navigator !== "undefined" && navigator.onLine === false;
|
|
12570
12570
|
if (isOffline) return persisted;
|
|
12571
|
-
persisted.clientState.queries = persisted.clientState.queries.filter(
|
|
12572
|
-
(q) => isRestorableArbiQueryOnline(q.queryKey, q.state.data)
|
|
12573
|
-
);
|
|
12571
|
+
persisted.clientState.queries = persisted.clientState.queries.filter((q) => isRestorableArbiQueryOnline(q.queryKey, q.state.data)).map((q) => ({ ...q, state: { ...q.state, dataUpdatedAt: 0 } }));
|
|
12574
12572
|
return persisted;
|
|
12575
12573
|
},
|
|
12576
12574
|
removeClient: () => {
|
|
@@ -17908,11 +17906,12 @@ function DmComposer({
|
|
|
17908
17906
|
}
|
|
17909
17907
|
);
|
|
17910
17908
|
}
|
|
17911
|
-
function useAgentDmProgress(responseId) {
|
|
17909
|
+
function useAgentDmProgress(responseId, workspaceId) {
|
|
17912
17910
|
const arbi = chunk5QOZLKAY_cjs.useArbi();
|
|
17913
17911
|
return reactQuery.useQuery({
|
|
17914
17912
|
queryKey: chunk5QOZLKAY_cjs.arbiQueryKeys.agentDmProgress(chunkC5O4BH7B_cjs.myChatId(arbi) ?? "", responseId ?? ""),
|
|
17915
|
-
|
|
17913
|
+
// The run is in the agent's Home workspace: opened first, so its output reads at once.
|
|
17914
|
+
queryFn: () => arbi.assistant.getResponse(responseId, { workspaceId: workspaceId ?? void 0 }),
|
|
17916
17915
|
enabled: !!responseId,
|
|
17917
17916
|
refetchInterval: 1500,
|
|
17918
17917
|
retry: false
|