@arbidocs/react 0.5.160 → 0.5.162
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/artifacts/index.cjs +2 -2
- package/dist/calls/livekit/index.cjs +41 -41
- package/dist/chat/workflow-run-titles.js +6 -1
- package/dist/chat/workflow-run-titles.js.map +2 -2
- package/dist/{chunk-GVU3KYP3.cjs → chunk-42X5ZO7Y.cjs} +11 -82
- package/dist/chunk-42X5ZO7Y.cjs.map +1 -0
- package/dist/{chunk-2MGJXBBJ.cjs → chunk-SUMXDNYG.cjs} +157 -6
- package/dist/chunk-SUMXDNYG.cjs.map +1 -0
- package/dist/conversation-list.js +32 -4
- package/dist/conversation-list.js.map +2 -2
- package/dist/directmessages/chat-cache.js +5 -0
- package/dist/directmessages/chat-cache.js.map +2 -2
- package/dist/hooks.js +7 -1
- package/dist/hooks.js.map +2 -2
- package/dist/index.cjs +625 -603
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +208 -1024
- package/dist/session/conversation-panels.js +41 -0
- package/dist/session/conversation-panels.js.map +7 -0
- package/dist/session/index.js +2 -0
- package/dist/session/index.js.map +2 -2
- package/dist/session/layout.js +7 -3
- package/dist/session/layout.js.map +2 -2
- package/dist/workspaces/switch.js +7 -4
- package/dist/workspaces/switch.js.map +2 -2
- package/package.json +3 -3
- package/dist/chunk-2MGJXBBJ.cjs.map +0 -1
- package/dist/chunk-GVU3KYP3.cjs.map +0 -1
|
@@ -5,7 +5,32 @@ function isConversationListKey(queryKey) {
|
|
|
5
5
|
const LISTS = {
|
|
6
6
|
predicate: (query) => isConversationListKey(query.queryKey)
|
|
7
7
|
};
|
|
8
|
-
|
|
8
|
+
const WRITE_MEMORY_MS = 12e4;
|
|
9
|
+
const writeLogs = /* @__PURE__ */ new WeakMap();
|
|
10
|
+
function writeLog(queryClient, key) {
|
|
11
|
+
let lists = writeLogs.get(queryClient);
|
|
12
|
+
if (!lists) writeLogs.set(queryClient, lists = /* @__PURE__ */ new Map());
|
|
13
|
+
const hash = JSON.stringify(key);
|
|
14
|
+
const now = Date.now();
|
|
15
|
+
const log = (lists.get(hash) ?? []).filter((w) => now - w.at < WRITE_MEMORY_MS);
|
|
16
|
+
lists.set(hash, log);
|
|
17
|
+
return log;
|
|
18
|
+
}
|
|
19
|
+
function withLocalWrites(queryClient, workspaceId, rows, requestedAt) {
|
|
20
|
+
return writeLog(queryClient, arbiQueryKeys.conversations(workspaceId)).filter((w) => w.at >= requestedAt).reduce((list, w) => w.apply(list), rows);
|
|
21
|
+
}
|
|
22
|
+
async function readConversationList(queryClient, workspaceId, read) {
|
|
23
|
+
const requestedAt = Date.now();
|
|
24
|
+
return withLocalWrites(queryClient, workspaceId, await read(), requestedAt);
|
|
25
|
+
}
|
|
26
|
+
function seedConversationList(queryClient, workspaceId, rows, requestedAt) {
|
|
27
|
+
queryClient.setQueryData(
|
|
28
|
+
arbiQueryKeys.conversations(workspaceId),
|
|
29
|
+
withLocalWrites(queryClient, workspaceId, rows, requestedAt)
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
function writeList(queryClient, key, apply, next) {
|
|
33
|
+
writeLog(queryClient, key).push({ at: Date.now(), apply });
|
|
9
34
|
const staleRead = queryClient.getQueryState(key)?.fetchStatus === "fetching";
|
|
10
35
|
queryClient.setQueryData(key, next);
|
|
11
36
|
if (staleRead) void queryClient.refetchQueries({ queryKey: key, exact: true });
|
|
@@ -14,7 +39,7 @@ function patchLists(queryClient, reducer) {
|
|
|
14
39
|
for (const [key, old] of queryClient.getQueriesData(LISTS)) {
|
|
15
40
|
if (!old) continue;
|
|
16
41
|
const next = reducer(old);
|
|
17
|
-
if (next !== old) writeList(queryClient, key, next);
|
|
42
|
+
if (next !== old) writeList(queryClient, key, reducer, next);
|
|
18
43
|
}
|
|
19
44
|
}
|
|
20
45
|
function patchConversationList(queryClient, workspaceId, reducer) {
|
|
@@ -22,7 +47,7 @@ function patchConversationList(queryClient, workspaceId, reducer) {
|
|
|
22
47
|
const key = arbiQueryKeys.conversations(workspaceId);
|
|
23
48
|
const current = queryClient.getQueryData(key) ?? [];
|
|
24
49
|
const next = reducer(current);
|
|
25
|
-
if (next !== current) writeList(queryClient, key, next);
|
|
50
|
+
if (next !== current) writeList(queryClient, key, reducer, next);
|
|
26
51
|
}
|
|
27
52
|
function addConversationToList(queryClient, workspaceId, conversation) {
|
|
28
53
|
patchConversationList(queryClient, workspaceId, (old) => [
|
|
@@ -72,6 +97,9 @@ export {
|
|
|
72
97
|
isConversationShared,
|
|
73
98
|
patchConversation,
|
|
74
99
|
patchConversationList,
|
|
75
|
-
|
|
100
|
+
readConversationList,
|
|
101
|
+
removeConversationFromLists,
|
|
102
|
+
seedConversationList,
|
|
103
|
+
withLocalWrites
|
|
76
104
|
};
|
|
77
105
|
//# sourceMappingURL=conversation-list.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/conversation-list.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * The workspace's conversation list in the query cache (`arbiQueryKeys.conversations(ws)`).\n *\n * The list is kept current by its writers, not by re-reading it: the workspace open seeds it, every\n * write patches the rows it changed (with the server's version when the server returns one), and\n * the workspace's events invalidate it. These are the writers, for every host and kit, so that one\n * list serves the whole app.\n *\n * Conversation ids are unique across workspaces, so a row is patched (or looked up) by its id in\n * every cached list; only adding a row needs to name its workspace.\n */\n\nimport type { QueryClient, QueryKey } from '@tanstack/react-query'\nimport type { ConversationResponse } from '@arbidocs/sdk/browser'\nimport { arbiQueryKeys } from './hooks'\n\n/** Whether a query key is a workspace's conversation list (not its threads, activity or usage). */\nexport function isConversationListKey(queryKey: QueryKey): boolean {\n return queryKey.length === 3 && queryKey[0] === 'arbi' && queryKey[1] === 'conversations'\n}\n\nconst LISTS = {\n predicate: (query: { queryKey: QueryKey }) => isConversationListKey(query.queryKey),\n}\n\n
|
|
5
|
-
"mappings": "AAcA,SAAS,qBAAqB;AAGvB,SAAS,sBAAsB,UAA6B;AACjE,SAAO,SAAS,WAAW,KAAK,SAAS,CAAC,MAAM,UAAU,SAAS,CAAC,MAAM;AAC5E;AAEA,MAAM,QAAQ;AAAA,EACZ,WAAW,CAAC,UAAkC,sBAAsB,MAAM,QAAQ;AACpF;
|
|
4
|
+
"sourcesContent": ["/**\n * The workspace's conversation list in the query cache (`arbiQueryKeys.conversations(ws)`).\n *\n * The list is kept current by its writers, not by re-reading it: the workspace open seeds it, every\n * write patches the rows it changed (with the server's version when the server returns one), and\n * the workspace's events invalidate it. These are the writers, for every host and kit, so that one\n * list serves the whole app.\n *\n * Conversation ids are unique across workspaces, so a row is patched (or looked up) by its id in\n * every cached list; only adding a row needs to name its workspace.\n */\n\nimport type { QueryClient, QueryKey } from '@tanstack/react-query'\nimport type { ConversationResponse } from '@arbidocs/sdk/browser'\nimport { arbiQueryKeys } from './hooks'\n\n/** Whether a query key is a workspace's conversation list (not its threads, activity or usage). */\nexport function isConversationListKey(queryKey: QueryKey): boolean {\n return queryKey.length === 3 && queryKey[0] === 'arbi' && queryKey[1] === 'conversations'\n}\n\nconst LISTS = {\n predicate: (query: { queryKey: QueryKey }) => isConversationListKey(query.queryKey),\n}\n\ntype Reducer = (old: ConversationResponse[]) => ConversationResponse[]\n\n/** How long a local write is kept to replay over a server answer that left before it. */\nconst WRITE_MEMORY_MS = 120_000\n\n/** Per cache, per list: the local writes of the last {@link WRITE_MEMORY_MS}, oldest first. */\nconst writeLogs = new WeakMap<QueryClient, Map<string, { at: number; apply: Reducer }[]>>()\n\nfunction writeLog(queryClient: QueryClient, key: QueryKey): { at: number; apply: Reducer }[] {\n let lists = writeLogs.get(queryClient)\n if (!lists) writeLogs.set(queryClient, (lists = new Map()))\n const hash = JSON.stringify(key)\n const now = Date.now()\n const log = (lists.get(hash) ?? []).filter((w) => now - w.at < WRITE_MEMORY_MS)\n lists.set(hash, log)\n return log\n}\n\n/**\n * A server answer for a list (its read, or a workspace open), with every local write made since\n * the request left replayed over it: an answer prepared before a write never undoes it (a new task\n * gone from the list it was just added to, a task marked done shown to do again).\n */\nexport function withLocalWrites(\n queryClient: QueryClient,\n workspaceId: string,\n rows: ConversationResponse[],\n requestedAt: number\n): ConversationResponse[] {\n return writeLog(queryClient, arbiQueryKeys.conversations(workspaceId))\n .filter((w) => w.at >= requestedAt)\n .reduce((list, w) => w.apply(list), rows)\n}\n\n/** Read a workspace's list from the server, as {@link withLocalWrites} keeps it. */\nexport async function readConversationList(\n queryClient: QueryClient,\n workspaceId: string,\n read: () => Promise<ConversationResponse[]>\n): Promise<ConversationResponse[]> {\n const requestedAt = Date.now()\n return withLocalWrites(queryClient, workspaceId, await read(), requestedAt)\n}\n\n/** Seed a workspace's list from a workspace open sent at `requestedAt`. */\nexport function seedConversationList(\n queryClient: QueryClient,\n workspaceId: string,\n rows: ConversationResponse[],\n requestedAt: number\n): void {\n queryClient.setQueryData(\n arbiQueryKeys.conversations(workspaceId),\n withLocalWrites(queryClient, workspaceId, rows, requestedAt)\n )\n}\n\n/**\n * Write one cached list and remember the write, for an answer already on its way (see\n * {@link withLocalWrites}). A read of the list in flight is also read again, now that the server\n * has the write.\n */\nfunction writeList(\n queryClient: QueryClient,\n key: QueryKey,\n apply: Reducer,\n next: ConversationResponse[]\n): void {\n writeLog(queryClient, key).push({ at: Date.now(), apply })\n const staleRead = queryClient.getQueryState(key)?.fetchStatus === 'fetching'\n queryClient.setQueryData(key, next)\n if (staleRead) void queryClient.refetchQueries({ queryKey: key, exact: true })\n}\n\n/** Apply `reducer` to every cached list (each one it changes is written with {@link writeList}). */\nfunction patchLists(queryClient: QueryClient, reducer: Reducer): void {\n for (const [key, old] of queryClient.getQueriesData<ConversationResponse[]>(LISTS)) {\n if (!old) continue\n const next = reducer(old)\n if (next !== old) writeList(queryClient, key, reducer, next)\n }\n}\n\n/** Apply `reducer` to a workspace's cached list (an absent list counts as empty). */\nexport function patchConversationList(\n queryClient: QueryClient,\n workspaceId: string | null | undefined,\n reducer: Reducer\n): void {\n if (!workspaceId) return\n const key = arbiQueryKeys.conversations(workspaceId)\n const current = queryClient.getQueryData<ConversationResponse[]>(key) ?? []\n const next = reducer(current)\n if (next !== current) writeList(queryClient, key, reducer, next)\n}\n\n/** Put a new conversation at the top of its workspace's list (replacing an earlier copy). */\nexport function addConversationToList(\n queryClient: QueryClient,\n workspaceId: string | null | undefined,\n conversation: ConversationResponse\n): void {\n patchConversationList(queryClient, workspaceId, (old) => [\n conversation,\n ...old.filter((c) => c.external_id !== conversation.external_id),\n ])\n}\n\n/** Change one conversation's row, wherever it is listed. */\nexport function patchConversation(\n queryClient: QueryClient,\n conversationId: string,\n update: Partial<ConversationResponse> | ((row: ConversationResponse) => ConversationResponse)\n): void {\n patchLists(queryClient, (old) => {\n if (!old.some((c) => c.external_id === conversationId)) return old\n return old.map((c) =>\n c.external_id === conversationId\n ? typeof update === 'function'\n ? update(c)\n : { ...c, ...update }\n : c\n )\n })\n}\n\n/** Take a conversation out of every list. */\nexport function removeConversationFromLists(\n queryClient: QueryClient,\n conversationId: string\n): void {\n patchLists(queryClient, (old) =>\n old.some((c) => c.external_id === conversationId)\n ? old.filter((c) => c.external_id !== conversationId)\n : old\n )\n}\n\n/** Read the lists again: a change the cache cannot know (the server shared a thread, a run ended). */\nexport function invalidateConversationLists(queryClient: QueryClient): Promise<void> {\n return queryClient.invalidateQueries(LISTS)\n}\n\n/** A conversation's row, from whichever cached list holds it. */\nexport function findConversation(\n queryClient: QueryClient,\n conversationId: string | null | undefined\n): ConversationResponse | undefined {\n if (!conversationId) return undefined\n for (const [, list] of queryClient.getQueriesData<ConversationResponse[]>(LISTS)) {\n const row = list?.find((c) => c.external_id === conversationId)\n if (row) return row\n }\n return undefined\n}\n\n/** Whether the conversation is shared with the workspace, from the cached lists (false when unknown). */\nexport function isConversationShared(\n queryClient: QueryClient,\n conversationId: string | null | undefined\n): boolean {\n return findConversation(queryClient, conversationId)?.is_shared ?? false\n}\n\n/**\n * Refresh what hangs off one conversation (its activity, usage, pending access): not the lists, and\n * not its threads, which the chat engine and the conversation's events keep current.\n */\nexport function invalidateConversationDetails(\n queryClient: QueryClient,\n conversationId: string\n): Promise<void> {\n return queryClient.invalidateQueries({\n predicate: ({ queryKey }) =>\n queryKey[0] === 'arbi' &&\n queryKey[1] === 'conversations' &&\n queryKey[2] === conversationId &&\n queryKey[3] !== 'threads',\n })\n}\n"],
|
|
5
|
+
"mappings": "AAcA,SAAS,qBAAqB;AAGvB,SAAS,sBAAsB,UAA6B;AACjE,SAAO,SAAS,WAAW,KAAK,SAAS,CAAC,MAAM,UAAU,SAAS,CAAC,MAAM;AAC5E;AAEA,MAAM,QAAQ;AAAA,EACZ,WAAW,CAAC,UAAkC,sBAAsB,MAAM,QAAQ;AACpF;AAKA,MAAM,kBAAkB;AAGxB,MAAM,YAAY,oBAAI,QAAoE;AAE1F,SAAS,SAAS,aAA0B,KAAiD;AAC3F,MAAI,QAAQ,UAAU,IAAI,WAAW;AACrC,MAAI,CAAC,MAAO,WAAU,IAAI,aAAc,QAAQ,oBAAI,IAAI,CAAE;AAC1D,QAAM,OAAO,KAAK,UAAU,GAAG;AAC/B,QAAM,MAAM,KAAK,IAAI;AACrB,QAAM,OAAO,MAAM,IAAI,IAAI,KAAK,CAAC,GAAG,OAAO,CAAC,MAAM,MAAM,EAAE,KAAK,eAAe;AAC9E,QAAM,IAAI,MAAM,GAAG;AACnB,SAAO;AACT;AAOO,SAAS,gBACd,aACA,aACA,MACA,aACwB;AACxB,SAAO,SAAS,aAAa,cAAc,cAAc,WAAW,CAAC,EAClE,OAAO,CAAC,MAAM,EAAE,MAAM,WAAW,EACjC,OAAO,CAAC,MAAM,MAAM,EAAE,MAAM,IAAI,GAAG,IAAI;AAC5C;AAGA,eAAsB,qBACpB,aACA,aACA,MACiC;AACjC,QAAM,cAAc,KAAK,IAAI;AAC7B,SAAO,gBAAgB,aAAa,aAAa,MAAM,KAAK,GAAG,WAAW;AAC5E;AAGO,SAA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,OAAO,WAAW,aAChB,OAAO,CAAC,IACR,EAAE,GAAG,GAAG,GAAG,OAAO,IACpB;AAAA,IACN;AAAA,EACF,CAAC;AACH;AAGO,SAAS,4BACd,aACA,gBACM;AACN;AAAA,IAAW;AAAA,IAAa,CAAC,QACvB,IAAI,KAAK,CAAC,MAAM,EAAE,gBAAgB,cAAc,IAC5C,IAAI,OAAO,CAAC,MAAM,EAAE,gBAAgB,cAAc,IAClD;AAAA,EACN;AACF;AAGO,SAAS,4BAA4B,aAAyC;AACnF,SAAO,YAAY,kBAAkB,KAAK;AAC5C;AAGO,SAAS,iBACd,aACA,gBACkC;AAClC,MAAI,CAAC,eAAgB,QAAO;AAC5B,aAAW,CAAC,EAAE,IAAI,KAAK,YAAY,eAAuC,KAAK,GAAG;AAChF,UAAM,MAAM,MAAM,KAAK,CAAC,MAAM,EAAE,gBAAgB,cAAc;AAC9D,QAAI,IAAK,QAAO;AAAA,EAClB;AACA,SAAO;AACT;AAGO,SAAS,qBACd,aACA,gBACS;AACT,SAAO,iBAAiB,aAAa,cAAc,GAAG,aAAa;AACrE;AAMO,SAAS,8BACd,aACA,gBACe;AACf,SAAO,YAAY,kBAAkB;AAAA,IACnC,WAAW,CAAC,EAAE,SAAS,MACrB,SAAS,CAAC,MAAM,UAChB,SAAS,CAAC,MAAM,mBAChB,SAAS,CAAC,MAAM,kBAChB,SAAS,CAAC,MAAM;AAAA,EACpB,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { chats } from "@arbidocs/sdk/browser";
|
|
2
2
|
import { arbiQueryKeys } from "../hooks.js";
|
|
3
|
+
import { calendarQueryKeys, callQueryKeys } from "../query-keys.js";
|
|
3
4
|
function myChatId(arbi) {
|
|
4
5
|
try {
|
|
5
6
|
return arbi.user.identity()?.externalId ?? null;
|
|
@@ -161,6 +162,10 @@ async function applyChatUpdated(arbi, queryClient, chatExtId, message) {
|
|
|
161
162
|
function applyAgentDmStatus(queryClient, status) {
|
|
162
163
|
if (!["queued", "working", "done", "failed"].includes(status.status)) return;
|
|
163
164
|
queryClient.setQueryData(arbiQueryKeys.agentDmStatus(status.agent_ext_id), status);
|
|
165
|
+
if (status.status === "done" || status.status === "failed") {
|
|
166
|
+
void queryClient.invalidateQueries({ queryKey: calendarQueryKeys.all() });
|
|
167
|
+
void queryClient.invalidateQueries({ queryKey: callQueryKeys.all() });
|
|
168
|
+
}
|
|
164
169
|
}
|
|
165
170
|
async function applyChatEvent(arbi, queryClient, event) {
|
|
166
171
|
const e = event;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/directmessages/chat-cache.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * The one chat cache: my chat list (`arbiQueryKeys.chatList()`, raw \u2014 titles and last messages\n * stay ciphertext) and each open thread (`arbiQueryKeys.chatThread(id)`, decrypted). Every reader\n * (the messenger, unread badges, the DM kit, a call's chat) and every writer (a send, a delete,\n * a WebSocket event) goes through here, so one change shows everywhere at once.\n *\n * Live events: `<ArbiWebSocketProvider>` applies them itself; a host with its own socket passes each\n * chat event to `applyChatEvent`.\n */\n\nimport type { QueryClient } from '@tanstack/react-query'\nimport type { WsAgentDmStatusMessage } from '@arbidocs/client'\nimport { chats, type Arbi } from '@arbidocs/sdk/browser'\nimport { arbiQueryKeys } from '../hooks'\n\nexport type ChatResponse = chats.ChatResponse\nexport type ChatMessageResponse = chats.ChatMessageResponse\nexport type DecryptedChatMessage = chats.DecryptedChatMessage\nexport type ChatAttachmentFile = chats.ChatAttachmentFile\nexport type ChatMemberKey = chats.ChatMemberKey\n\n/** A message in an open thread; an optimistic row carries a local id until the server echoes it. */\nexport type ChatThreadMessage = DecryptedChatMessage & { optimistic?: boolean }\n\n/** An open thread's cache entry: decrypted messages, oldest first. */\nexport interface ChatThreadData {\n messages: ChatThreadMessage[]\n /** False once the oldest page has been loaded. */\n hasMore: boolean\n}\n\n/** The signed-in user's external id, or null when signed out. */\nexport function myChatId(arbi: Arbi): string | null {\n try {\n return arbi.user.identity()?.externalId ?? null\n } catch {\n return null\n }\n}\n\n// \u2500\u2500 The chat open in a messenger \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/** The chat open in a messenger, if any: its new messages do not count as unread. */\nlet openChatExtId: string | null = null\nexport function setOpenChat(chatExtId: string | null): void {\n openChatExtId = chatExtId\n}\nexport function getOpenChat(): string | null {\n return openChatExtId\n}\n\n// \u2500\u2500 Writers \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nfunction byActivity(a: ChatResponse, b: ChatResponse): number {\n const at = Date.parse(a.last_message_at ?? a.created_at)\n const bt = Date.parse(b.last_message_at ?? b.created_at)\n return bt - at\n}\n\n/** My chats as the cache holds them (empty until the list has loaded). */\nexport function cachedChats(queryClient: QueryClient): ChatResponse[] {\n return queryClient.getQueryData<ChatResponse[]>(arbiQueryKeys.chatList()) ?? []\n}\n\n/** One of my chats from the cache, if the list has it. */\nexport function cachedChat(queryClient: QueryClient, chatExtId: string): ChatResponse | undefined {\n return cachedChats(queryClient).find((c) => c.external_id === chatExtId)\n}\n\n/** Put a chat (new or updated) into the list, keeping the list newest first. */\nexport function upsertChat(queryClient: QueryClient, chat: ChatResponse): void {\n queryClient.setQueryData<ChatResponse[]>(arbiQueryKeys.chatList(), (old) => {\n if (!old) return old\n const rest = old.filter((c) => c.external_id !== chat.external_id)\n return [chat, ...rest].sort(byActivity)\n })\n}\n\n/** Drop a chat I left or lost, with its thread. */\nexport function removeChat(queryClient: QueryClient, chatExtId: string): void {\n queryClient.setQueryData<ChatResponse[]>(arbiQueryKeys.chatList(), (old) =>\n old?.filter((c) => c.external_id !== chatExtId)\n )\n queryClient.removeQueries({ queryKey: arbiQueryKeys.chatThread(chatExtId) })\n}\n\n/** Append a message to a loaded thread (deduplicated, replacing its optimistic copy). */\nexport function appendToThread(\n queryClient: QueryClient,\n chatExtId: string,\n message: ChatThreadMessage,\n replaceOptimisticId?: string\n): void {\n queryClient.setQueryData<ChatThreadData>(arbiQueryKeys.chatThread(chatExtId), (old) => {\n if (!old) return old\n const without = old.messages.filter(\n (m) => m.external_id !== message.external_id && m.external_id !== replaceOptimisticId\n )\n return { ...old, messages: [...without, message] }\n })\n}\n\n/** Take a message out of a loaded thread (a failed optimistic send). */\nexport function dropFromThread(queryClient: QueryClient, chatExtId: string, messageExtId: string) {\n queryClient.setQueryData<ChatThreadData>(arbiQueryKeys.chatThread(chatExtId), (old) =>\n old ? { ...old, messages: old.messages.filter((m) => m.external_id !== messageExtId) } : old\n )\n}\n\n/** Replace a message of a loaded thread where it stands (no-op when it is not loaded). */\nfunction replaceInThread(\n queryClient: QueryClient,\n chatExtId: string,\n message: ChatThreadMessage\n): void {\n queryClient.setQueryData<ChatThreadData>(arbiQueryKeys.chatThread(chatExtId), (old) => {\n if (!old || !old.messages.some((m) => m.external_id === message.external_id)) return old\n return {\n ...old,\n messages: old.messages.map((m) => (m.external_id === message.external_id ? message : m)),\n }\n })\n}\n\n/** Swap a chat's `last_message` in the list when it is still `message`. */\nfunction patchLastMessage(\n queryClient: QueryClient,\n chatExtId: string,\n message: ChatMessageResponse\n): void {\n queryClient.setQueryData<ChatResponse[]>(arbiQueryKeys.chatList(), (old) =>\n old?.map((c) =>\n c.external_id === chatExtId && c.last_message?.external_id === message.external_id\n ? { ...c, last_message: message }\n : c\n )\n )\n}\n\n/**\n * Delete one of my messages. The server keeps it in place as a tombstone (`deleted: true`), so\n * the cache marks it the same way at once \u2014 a refetch then returns exactly what is shown. Rolled\n * back (and rethrown) when the delete fails.\n */\nexport async function deleteChatMessage(\n arbi: Arbi,\n queryClient: QueryClient,\n chatExtId: string,\n messageExtId: string\n): Promise<void> {\n const thread = queryClient.getQueryData<ChatThreadData>(arbiQueryKeys.chatThread(chatExtId))\n const before = thread?.messages.find((m) => m.external_id === messageExtId)\n const listed = cachedChat(queryClient, chatExtId)\n const wasLast = listed?.last_message?.external_id === messageExtId ? listed.last_message : null\n if (before) replaceInThread(queryClient, chatExtId, chats.chatMessageTombstone(before))\n if (wasLast) patchLastMessage(queryClient, chatExtId, chats.chatMessageTombstone(wasLast))\n try {\n await arbi.chats.deleteMessage(chatExtId, messageExtId)\n } catch (err) {\n if (before) replaceInThread(queryClient, chatExtId, before)\n if (wasLast) patchLastMessage(queryClient, chatExtId, wasLast)\n throw err\n }\n}\n\n// \u2500\u2500 Live events \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/** A message changed in place (a deleted message's tombstone): update it where it stands. */\nasync function applyChangedMessage(\n arbi: Arbi,\n queryClient: QueryClient,\n chatExtId: string,\n message: ChatMessageResponse\n): Promise<void> {\n if (message.deleted) {\n replaceInThread(queryClient, chatExtId, chats.chatMessageTombstone(message))\n patchLastMessage(queryClient, chatExtId, chats.chatMessageTombstone(message))\n return\n }\n const chat = cachedChat(queryClient, chatExtId)\n if (!chat || !queryClient.getQueryData(arbiQueryKeys.chatThread(chatExtId))) return\n try {\n replaceInThread(queryClient, chatExtId, await arbi.chats.decrypt(chat, message))\n } catch (err) {\n console.error('[chats] could not decrypt a changed message', err)\n }\n}\n\n/** `chat.message`: a new message in one of my chats. */\nexport async function applyChatMessage(\n arbi: Arbi,\n queryClient: QueryClient,\n chatExtId: string,\n message: ChatMessageResponse\n): Promise<void> {\n // Not new: a tombstone replaces the message where it stands (never unread, never the preview).\n if (message.deleted) return applyChangedMessage(arbi, queryClient, chatExtId, message)\n const me = myChatId(arbi)\n const chat = cachedChat(queryClient, chatExtId)\n if (!chat) {\n // A chat I was just added to: fetch the list fresh.\n void queryClient.invalidateQueries({ queryKey: arbiQueryKeys.chatList() })\n return\n }\n const mine = message.sender_ext_id === me\n const isOpen = openChatExtId === chatExtId\n upsertChat(queryClient, {\n ...chat,\n last_message: message,\n last_message_at: message.created_at,\n unread_count: mine ? 0 : isOpen ? chat.unread_count : chat.unread_count + 1,\n members: mine\n ? chat.members.map((m) =>\n m.user.external_id === me ? { ...m, last_read_at: message.created_at } : m\n )\n : chat.members,\n })\n if (queryClient.getQueryData(arbiQueryKeys.chatThread(chatExtId))) {\n try {\n appendToThread(queryClient, chatExtId, await arbi.chats.decrypt(chat, message))\n } catch (err) {\n console.error('[chats] could not decrypt a live message', err)\n }\n }\n}\n\n/** `chat.read`: a member's watermark moved (a read receipt). */\nexport function applyChatRead(\n arbi: Arbi,\n queryClient: QueryClient,\n chatExtId: string,\n userExtId: string,\n lastReadAt: string\n): void {\n const me = myChatId(arbi)\n queryClient.setQueryData<ChatResponse[]>(arbiQueryKeys.chatList(), (old) =>\n old?.map((c) =>\n c.external_id !== chatExtId\n ? c\n : {\n ...c,\n unread_count: userExtId === me ? 0 : c.unread_count,\n members: c.members.map((m) =>\n m.user.external_id === userExtId ? { ...m, last_read_at: lastReadAt } : m\n ),\n }\n )\n )\n}\n\n/**\n * `chat.updated`: members, keys, title or a deleted message changed. Refetch the chat; when it now\n * needs a new epoch and I am still in it, seal one. A changed `message` (a deleted message's\n * tombstone) is applied in place; without one the open thread is reloaded.\n */\nexport async function applyChatUpdated(\n arbi: Arbi,\n queryClient: QueryClient,\n chatExtId: string,\n message?: ChatMessageResponse | null\n): Promise<void> {\n if (message) await applyChangedMessage(arbi, queryClient, chatExtId, message)\n let chat: ChatResponse\n try {\n chat = await arbi.chats.get(chatExtId)\n } catch {\n // Removed from it (or it is gone).\n removeChat(queryClient, chatExtId)\n return\n }\n if (chat.rotation_required) {\n // Best effort: whoever posts next rotates first.\n chat = await arbi.chats.ready(chat).catch(() => chat)\n }\n upsertChat(queryClient, chat)\n // Members, keys or a new epoch: reload the open thread. A changed message is already in place.\n if (!message)\n void queryClient.invalidateQueries({ queryKey: arbiQueryKeys.chatThread(chatExtId) })\n}\n\n/** My own agent's progress on a message I sent it (`agent_dm_status`). */\nexport type AgentDmStatus = WsAgentDmStatusMessage\n\n/** `agent_dm_status`: remember my agent's latest progress (read by `useAgentDmStatus`). */\nexport function applyAgentDmStatus(queryClient: QueryClient, status: AgentDmStatus): void {\n if (!['queued', 'working', 'done', 'failed'].includes(status.status)) return\n queryClient.setQueryData(arbiQueryKeys.agentDmStatus(status.agent_ext_id), status)\n}\n\n/** The chat events of the server's WebSocket, as `applyChatEvent` takes them. */\nexport type ChatEvent =\n | { type: 'chat.message'; chat_ext_id: string; message: ChatMessageResponse }\n | { type: 'chat.read'; chat_ext_id: string; user_ext_id: string; last_read_at: string }\n | { type: 'chat.updated'; chat_ext_id: string; message?: ChatMessageResponse | null }\n | AgentDmStatus\n\n/** Apply one chat event of the server's WebSocket to the cache. Other messages are ignored. */\nexport async function applyChatEvent(\n arbi: Arbi,\n queryClient: QueryClient,\n event: { type: string }\n): Promise<void> {\n const e = event as ChatEvent\n if (e.type === 'chat.message')\n return applyChatMessage(arbi, queryClient, e.chat_ext_id, e.message)\n if (e.type === 'chat.read')\n return applyChatRead(arbi, queryClient, e.chat_ext_id, e.user_ext_id, e.last_read_at)\n if (e.type === 'chat.updated')\n return applyChatUpdated(arbi, queryClient, e.chat_ext_id, e.message)\n if (e.type === 'agent_dm_status') applyAgentDmStatus(queryClient, e)\n}\n"],
|
|
5
|
-
"mappings": "AAYA,SAAS,aAAwB;AACjC,SAAS,qBAAqB;
|
|
4
|
+
"sourcesContent": ["/**\n * The one chat cache: my chat list (`arbiQueryKeys.chatList()`, raw \u2014 titles and last messages\n * stay ciphertext) and each open thread (`arbiQueryKeys.chatThread(id)`, decrypted). Every reader\n * (the messenger, unread badges, the DM kit, a call's chat) and every writer (a send, a delete,\n * a WebSocket event) goes through here, so one change shows everywhere at once.\n *\n * Live events: `<ArbiWebSocketProvider>` applies them itself; a host with its own socket passes each\n * chat event to `applyChatEvent`.\n */\n\nimport type { QueryClient } from '@tanstack/react-query'\nimport type { WsAgentDmStatusMessage } from '@arbidocs/client'\nimport { chats, type Arbi } from '@arbidocs/sdk/browser'\nimport { arbiQueryKeys } from '../hooks'\nimport { calendarQueryKeys, callQueryKeys } from '../query-keys'\n\nexport type ChatResponse = chats.ChatResponse\nexport type ChatMessageResponse = chats.ChatMessageResponse\nexport type DecryptedChatMessage = chats.DecryptedChatMessage\nexport type ChatAttachmentFile = chats.ChatAttachmentFile\nexport type ChatMemberKey = chats.ChatMemberKey\n\n/** A message in an open thread; an optimistic row carries a local id until the server echoes it. */\nexport type ChatThreadMessage = DecryptedChatMessage & { optimistic?: boolean }\n\n/** An open thread's cache entry: decrypted messages, oldest first. */\nexport interface ChatThreadData {\n messages: ChatThreadMessage[]\n /** False once the oldest page has been loaded. */\n hasMore: boolean\n}\n\n/** The signed-in user's external id, or null when signed out. */\nexport function myChatId(arbi: Arbi): string | null {\n try {\n return arbi.user.identity()?.externalId ?? null\n } catch {\n return null\n }\n}\n\n// \u2500\u2500 The chat open in a messenger \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/** The chat open in a messenger, if any: its new messages do not count as unread. */\nlet openChatExtId: string | null = null\nexport function setOpenChat(chatExtId: string | null): void {\n openChatExtId = chatExtId\n}\nexport function getOpenChat(): string | null {\n return openChatExtId\n}\n\n// \u2500\u2500 Writers \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nfunction byActivity(a: ChatResponse, b: ChatResponse): number {\n const at = Date.parse(a.last_message_at ?? a.created_at)\n const bt = Date.parse(b.last_message_at ?? b.created_at)\n return bt - at\n}\n\n/** My chats as the cache holds them (empty until the list has loaded). */\nexport function cachedChats(queryClient: QueryClient): ChatResponse[] {\n return queryClient.getQueryData<ChatResponse[]>(arbiQueryKeys.chatList()) ?? []\n}\n\n/** One of my chats from the cache, if the list has it. */\nexport function cachedChat(queryClient: QueryClient, chatExtId: string): ChatResponse | undefined {\n return cachedChats(queryClient).find((c) => c.external_id === chatExtId)\n}\n\n/** Put a chat (new or updated) into the list, keeping the list newest first. */\nexport function upsertChat(queryClient: QueryClient, chat: ChatResponse): void {\n queryClient.setQueryData<ChatResponse[]>(arbiQueryKeys.chatList(), (old) => {\n if (!old) return old\n const rest = old.filter((c) => c.external_id !== chat.external_id)\n return [chat, ...rest].sort(byActivity)\n })\n}\n\n/** Drop a chat I left or lost, with its thread. */\nexport function removeChat(queryClient: QueryClient, chatExtId: string): void {\n queryClient.setQueryData<ChatResponse[]>(arbiQueryKeys.chatList(), (old) =>\n old?.filter((c) => c.external_id !== chatExtId)\n )\n queryClient.removeQueries({ queryKey: arbiQueryKeys.chatThread(chatExtId) })\n}\n\n/** Append a message to a loaded thread (deduplicated, replacing its optimistic copy). */\nexport function appendToThread(\n queryClient: QueryClient,\n chatExtId: string,\n message: ChatThreadMessage,\n replaceOptimisticId?: string\n): void {\n queryClient.setQueryData<ChatThreadData>(arbiQueryKeys.chatThread(chatExtId), (old) => {\n if (!old) return old\n const without = old.messages.filter(\n (m) => m.external_id !== message.external_id && m.external_id !== replaceOptimisticId\n )\n return { ...old, messages: [...without, message] }\n })\n}\n\n/** Take a message out of a loaded thread (a failed optimistic send). */\nexport function dropFromThread(queryClient: QueryClient, chatExtId: string, messageExtId: string) {\n queryClient.setQueryData<ChatThreadData>(arbiQueryKeys.chatThread(chatExtId), (old) =>\n old ? { ...old, messages: old.messages.filter((m) => m.external_id !== messageExtId) } : old\n )\n}\n\n/** Replace a message of a loaded thread where it stands (no-op when it is not loaded). */\nfunction replaceInThread(\n queryClient: QueryClient,\n chatExtId: string,\n message: ChatThreadMessage\n): void {\n queryClient.setQueryData<ChatThreadData>(arbiQueryKeys.chatThread(chatExtId), (old) => {\n if (!old || !old.messages.some((m) => m.external_id === message.external_id)) return old\n return {\n ...old,\n messages: old.messages.map((m) => (m.external_id === message.external_id ? message : m)),\n }\n })\n}\n\n/** Swap a chat's `last_message` in the list when it is still `message`. */\nfunction patchLastMessage(\n queryClient: QueryClient,\n chatExtId: string,\n message: ChatMessageResponse\n): void {\n queryClient.setQueryData<ChatResponse[]>(arbiQueryKeys.chatList(), (old) =>\n old?.map((c) =>\n c.external_id === chatExtId && c.last_message?.external_id === message.external_id\n ? { ...c, last_message: message }\n : c\n )\n )\n}\n\n/**\n * Delete one of my messages. The server keeps it in place as a tombstone (`deleted: true`), so\n * the cache marks it the same way at once \u2014 a refetch then returns exactly what is shown. Rolled\n * back (and rethrown) when the delete fails.\n */\nexport async function deleteChatMessage(\n arbi: Arbi,\n queryClient: QueryClient,\n chatExtId: string,\n messageExtId: string\n): Promise<void> {\n const thread = queryClient.getQueryData<ChatThreadData>(arbiQueryKeys.chatThread(chatExtId))\n const before = thread?.messages.find((m) => m.external_id === messageExtId)\n const listed = cachedChat(queryClient, chatExtId)\n const wasLast = listed?.last_message?.external_id === messageExtId ? listed.last_message : null\n if (before) replaceInThread(queryClient, chatExtId, chats.chatMessageTombstone(before))\n if (wasLast) patchLastMessage(queryClient, chatExtId, chats.chatMessageTombstone(wasLast))\n try {\n await arbi.chats.deleteMessage(chatExtId, messageExtId)\n } catch (err) {\n if (before) replaceInThread(queryClient, chatExtId, before)\n if (wasLast) patchLastMessage(queryClient, chatExtId, wasLast)\n throw err\n }\n}\n\n// \u2500\u2500 Live events \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/** A message changed in place (a deleted message's tombstone): update it where it stands. */\nasync function applyChangedMessage(\n arbi: Arbi,\n queryClient: QueryClient,\n chatExtId: string,\n message: ChatMessageResponse\n): Promise<void> {\n if (message.deleted) {\n replaceInThread(queryClient, chatExtId, chats.chatMessageTombstone(message))\n patchLastMessage(queryClient, chatExtId, chats.chatMessageTombstone(message))\n return\n }\n const chat = cachedChat(queryClient, chatExtId)\n if (!chat || !queryClient.getQueryData(arbiQueryKeys.chatThread(chatExtId))) return\n try {\n replaceInThread(queryClient, chatExtId, await arbi.chats.decrypt(chat, message))\n } catch (err) {\n console.error('[chats] could not decrypt a changed message', err)\n }\n}\n\n/** `chat.message`: a new message in one of my chats. */\nexport async function applyChatMessage(\n arbi: Arbi,\n queryClient: QueryClient,\n chatExtId: string,\n message: ChatMessageResponse\n): Promise<void> {\n // Not new: a tombstone replaces the message where it stands (never unread, never the preview).\n if (message.deleted) return applyChangedMessage(arbi, queryClient, chatExtId, message)\n const me = myChatId(arbi)\n const chat = cachedChat(queryClient, chatExtId)\n if (!chat) {\n // A chat I was just added to: fetch the list fresh.\n void queryClient.invalidateQueries({ queryKey: arbiQueryKeys.chatList() })\n return\n }\n const mine = message.sender_ext_id === me\n const isOpen = openChatExtId === chatExtId\n upsertChat(queryClient, {\n ...chat,\n last_message: message,\n last_message_at: message.created_at,\n unread_count: mine ? 0 : isOpen ? chat.unread_count : chat.unread_count + 1,\n members: mine\n ? chat.members.map((m) =>\n m.user.external_id === me ? { ...m, last_read_at: message.created_at } : m\n )\n : chat.members,\n })\n if (queryClient.getQueryData(arbiQueryKeys.chatThread(chatExtId))) {\n try {\n appendToThread(queryClient, chatExtId, await arbi.chats.decrypt(chat, message))\n } catch (err) {\n console.error('[chats] could not decrypt a live message', err)\n }\n }\n}\n\n/** `chat.read`: a member's watermark moved (a read receipt). */\nexport function applyChatRead(\n arbi: Arbi,\n queryClient: QueryClient,\n chatExtId: string,\n userExtId: string,\n lastReadAt: string\n): void {\n const me = myChatId(arbi)\n queryClient.setQueryData<ChatResponse[]>(arbiQueryKeys.chatList(), (old) =>\n old?.map((c) =>\n c.external_id !== chatExtId\n ? c\n : {\n ...c,\n unread_count: userExtId === me ? 0 : c.unread_count,\n members: c.members.map((m) =>\n m.user.external_id === userExtId ? { ...m, last_read_at: lastReadAt } : m\n ),\n }\n )\n )\n}\n\n/**\n * `chat.updated`: members, keys, title or a deleted message changed. Refetch the chat; when it now\n * needs a new epoch and I am still in it, seal one. A changed `message` (a deleted message's\n * tombstone) is applied in place; without one the open thread is reloaded.\n */\nexport async function applyChatUpdated(\n arbi: Arbi,\n queryClient: QueryClient,\n chatExtId: string,\n message?: ChatMessageResponse | null\n): Promise<void> {\n if (message) await applyChangedMessage(arbi, queryClient, chatExtId, message)\n let chat: ChatResponse\n try {\n chat = await arbi.chats.get(chatExtId)\n } catch {\n // Removed from it (or it is gone).\n removeChat(queryClient, chatExtId)\n return\n }\n if (chat.rotation_required) {\n // Best effort: whoever posts next rotates first.\n chat = await arbi.chats.ready(chat).catch(() => chat)\n }\n upsertChat(queryClient, chat)\n // Members, keys or a new epoch: reload the open thread. A changed message is already in place.\n if (!message)\n void queryClient.invalidateQueries({ queryKey: arbiQueryKeys.chatThread(chatExtId) })\n}\n\n/** My own agent's progress on a message I sent it (`agent_dm_status`). */\nexport type AgentDmStatus = WsAgentDmStatusMessage\n\n/** `agent_dm_status`: remember my agent's latest progress (read by `useAgentDmStatus`). */\nexport function applyAgentDmStatus(queryClient: QueryClient, status: AgentDmStatus): void {\n if (!['queued', 'working', 'done', 'failed'].includes(status.status)) return\n queryClient.setQueryData(arbiQueryKeys.agentDmStatus(status.agent_ext_id), status)\n // Native actions use the server APIs, so they do not run this browser's mutation callbacks.\n // Refresh the owner's open schedule and call controls after a run, including partial failures.\n if (status.status === 'done' || status.status === 'failed') {\n void queryClient.invalidateQueries({ queryKey: calendarQueryKeys.all() })\n void queryClient.invalidateQueries({ queryKey: callQueryKeys.all() })\n }\n}\n\n/** The chat events of the server's WebSocket, as `applyChatEvent` takes them. */\nexport type ChatEvent =\n | { type: 'chat.message'; chat_ext_id: string; message: ChatMessageResponse }\n | { type: 'chat.read'; chat_ext_id: string; user_ext_id: string; last_read_at: string }\n | { type: 'chat.updated'; chat_ext_id: string; message?: ChatMessageResponse | null }\n | AgentDmStatus\n\n/** Apply one chat event of the server's WebSocket to the cache. Other messages are ignored. */\nexport async function applyChatEvent(\n arbi: Arbi,\n queryClient: QueryClient,\n event: { type: string }\n): Promise<void> {\n const e = event as ChatEvent\n if (e.type === 'chat.message')\n return applyChatMessage(arbi, queryClient, e.chat_ext_id, e.message)\n if (e.type === 'chat.read')\n return applyChatRead(arbi, queryClient, e.chat_ext_id, e.user_ext_id, e.last_read_at)\n if (e.type === 'chat.updated')\n return applyChatUpdated(arbi, queryClient, e.chat_ext_id, e.message)\n if (e.type === 'agent_dm_status') applyAgentDmStatus(queryClient, e)\n}\n"],
|
|
5
|
+
"mappings": "AAYA,SAAS,aAAwB;AACjC,SAAS,qBAAqB;AAC9B,SAAS,mBAAmB,qBAAqB;AAmB1C,SAAS,SAAS,MAA2B;AAClD,MAAI;AACF,WAAO,KAAK,KAAK,SAAS,GAAG,cAAc;AAAA,EAC7C,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAKA,IAAI,gBAA+B;AAC5B,SAAS,YAAY,WAAgC;AAC1D,kBAAgB;AAClB;AACO,SAAS,cAA6B;AAC3C,SAAO;AACT;AAIA,SAAS,WAAW,GAAiB,GAAyB;AAC5D,QAAM,KAAK,KAAK,MAAM,EAAE,mBAAmB,EAAE,UAAU;AACvD,QAAM,KAAK,KAAK,MAAM,EAAE,mBAAmB,EAAE,UAAU;AACvD,SAAO,KAAK;AACd;AAGO,SAAS,YAAY,aAA0C;AACpE,SAAO,YAAY,aAA6B,cAAc,SAAS,CAAC,KAAK,CAAC;AAChF;AAGO,SAAS,WAAW,aAA0B,WAA6C;AAChG,SAAO,YAAY,WAAW,EAAE,KAAK,CAAC,MAAM,EAAE,gBAAgB,SAAS;AACzE;AAGO,SAAS,WAAW,aAA0B,MAA0B;AAC7E,cAAY,aAA6B,cAAc,SAAS,GAAG,CAAC,QAAQ;AAC1E,QAAI,CAAC,IAAK,QAAO;AACjB,UAAM,OAAO,IAAI,OAAO,CAAC,MAAM,EAAE,gBAAgB,KAAK,WAAW;AACjE,WAAO,CAAC,MAAM,GAAG,IAAI,EAAE,KAAK,UAAU;AAAA,EACxC,CAAC;AACH;AAGO,SAAS,WAAW,aAA0B,WAAyB;AAC5E,cAAY;AAAA,IAA6B,cAAc,SAAS;AAAA,IAAG,CAAC,QAClE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K,MAAM,IAAI,SAAS;AAAA,EACvC,QAAQ;AAEN,eAAW,aAAa,SAAS;AACjC;AAAA,EACF;AACA,MAAI,KAAK,mBAAmB;AAE1B,WAAO,MAAM,KAAK,MAAM,MAAM,IAAI,EAAE,MAAM,MAAM,IAAI;AAAA,EACtD;AACA,aAAW,aAAa,IAAI;AAE5B,MAAI,CAAC;AACH,SAAK,YAAY,kBAAkB,EAAE,UAAU,cAAc,WAAW,SAAS,EAAE,CAAC;AACxF;AAMO,SAAS,mBAAmB,aAA0B,QAA6B;AACxF,MAAI,CAAC,CAAC,UAAU,WAAW,QAAQ,QAAQ,EAAE,SAAS,OAAO,MAAM,EAAG;AACtE,cAAY,aAAa,cAAc,cAAc,OAAO,YAAY,GAAG,MAAM;AAGjF,MAAI,OAAO,WAAW,UAAU,OAAO,WAAW,UAAU;AAC1D,SAAK,YAAY,kBAAkB,EAAE,UAAU,kBAAkB,IAAI,EAAE,CAAC;AACxE,SAAK,YAAY,kBAAkB,EAAE,UAAU,cAAc,IAAI,EAAE,CAAC;AAAA,EACtE;AACF;AAUA,eAAsB,eACpB,MACA,aACA,OACe;AACf,QAAM,IAAI;AACV,MAAI,EAAE,SAAS;AACb,WAAO,iBAAiB,MAAM,aAAa,EAAE,aAAa,EAAE,OAAO;AACrE,MAAI,EAAE,SAAS;AACb,WAAO,cAAc,MAAM,aAAa,EAAE,aAAa,EAAE,aAAa,EAAE,YAAY;AACtF,MAAI,EAAE,SAAS;AACb,WAAO,iBAAiB,MAAM,aAAa,EAAE,aAAa,EAAE,OAAO;AACrE,MAAI,EAAE,SAAS,kBAAmB,oBAAmB,aAAa,CAAC;AACrE;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/hooks.js
CHANGED
|
@@ -6,6 +6,7 @@ import { isUsageMetered } from "./usage-metered.js";
|
|
|
6
6
|
import { parseVersionRef } from "./artifacts/versions.js";
|
|
7
7
|
import { arbiQueryKeys, arbiMutationKeys } from "./query-keys.js";
|
|
8
8
|
import { arbiQueryKeys as arbiQueryKeys2 } from "./query-keys.js";
|
|
9
|
+
import { readConversationList } from "./conversation-list.js";
|
|
9
10
|
function useWorkspaces(options) {
|
|
10
11
|
const arbi = useArbi();
|
|
11
12
|
return useQuery({
|
|
@@ -24,11 +25,16 @@ function useDocumentVersionList(docId, options) {
|
|
|
24
25
|
}
|
|
25
26
|
function useConversations(workspaceId, options) {
|
|
26
27
|
const arbi = useArbi();
|
|
28
|
+
const queryClient = useQueryClient();
|
|
27
29
|
const live = options?.live === true;
|
|
28
30
|
return useQuery({
|
|
29
31
|
queryKey: arbiQueryKeys2.conversations(workspaceId ?? ""),
|
|
30
32
|
// The request names the workspace, so a switch while it runs cannot answer for another.
|
|
31
|
-
queryFn: () =>
|
|
33
|
+
queryFn: () => readConversationList(
|
|
34
|
+
queryClient,
|
|
35
|
+
workspaceId,
|
|
36
|
+
() => arbi.conversations.list({ workspaceId })
|
|
37
|
+
),
|
|
32
38
|
enabled: (options?.enabled ?? true) && !!workspaceId && arbi.hasWorkspace,
|
|
33
39
|
placeholderData: (previous) => previous,
|
|
34
40
|
...live ? {
|
package/dist/hooks.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/hooks.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * React Query hooks that use the Arbi instance from context.\n */\n\nimport { useEffect, useMemo, useRef } from 'react'\nimport { useInfiniteQuery, useQuery, useMutation, useQueryClient } from '@tanstack/react-query'\nimport {\n type AskHandlers,\n type AskRequest,\n type SSEStreamResult,\n type TagListQuery,\n type ThreadsResponse,\n} from '@arbidocs/sdk/browser'\nimport type { components } from '@arbidocs/client'\nimport { useArbi } from './useArbi'\nimport { useArbiSessionStore } from './session'\nimport type { ParsedDocument } from './documents/parsed-types'\nimport { isUsageMetered } from './usage-metered'\nimport { parseVersionRef } from './artifacts/versions'\n\n// \u2500\u2500 Query keys \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n// The one key factory (every query and mutation key of the packages and the app): ./query-keys.\nexport { arbiQueryKeys, arbiMutationKeys } from './query-keys'\nimport { arbiQueryKeys } from './query-keys'\n\n// \u2500\u2500 Hooks \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/** List the logged-in user's workspaces. */\nexport function useWorkspaces(options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.workspaces(),\n queryFn: () => arbi.workspaces.list(),\n enabled: (options?.enabled ?? true) && arbi.isLoggedIn,\n })\n}\n\n/** Every version of the document `docId`, oldest first (`is_current` marks the current one). */\nexport function useDocumentVersionList(\n docId: string | null | undefined,\n options?: { enabled?: boolean }\n) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.documentVersions(docId ?? ''),\n queryFn: () => arbi.documents.versions(docId as string),\n enabled: (options?.enabled ?? true) && !!docId && arbi.hasWorkspace,\n })\n}\n\n/**\n * A workspace's conversations (threads and tasks). The list is kept current by its writers and the\n * workspace's events (`conversation-list`), so it is not re-read on every mount; `live` re-reads it\n * on a timer instead, faster while something is generating, for a view that follows runs by itself.\n */\nexport function useConversations(\n workspaceId: string | undefined,\n options?: { enabled?: boolean; live?: boolean }\n) {\n const arbi = useArbi()\n const live = options?.live === true\n return useQuery({\n queryKey: arbiQueryKeys.conversations(workspaceId ?? ''),\n // The request names the workspace, so a switch while it runs cannot answer for another.\n queryFn: () => arbi.conversations.list({ workspaceId: workspaceId as string }),\n enabled: (options?.enabled ?? true) && !!workspaceId && arbi.hasWorkspace,\n placeholderData: (previous) => previous,\n ...(live\n ? {\n refetchInterval: (query: { state: { data?: Array<{ status?: string | null }> } }) =>\n query.state.data?.some((conversation) => conversation.status === 'generating')\n ? 3000\n : 15000,\n }\n : { staleTime: Infinity, refetchOnMount: false, refetchOnReconnect: false }),\n })\n}\n\n/** The backend's built-in slash commands (`/compact`, `/goal`, \u2026), for a slash menu. */\nexport function useBuiltinCommands() {\n const arbi = useArbi()\n const query = useQuery({\n queryKey: arbiQueryKeys.assistantCommands(),\n queryFn: () => arbi.assistant.commands(),\n staleTime: 30 * 1000,\n enabled: arbi.isLoggedIn,\n })\n // Stable identity so a menu's merge and filter memos do not rerun every render.\n const commands = useMemo(() => query.data ?? [], [query.data])\n return { commands, isLoading: query.isLoading }\n}\n\n/** One stored message with everything the server keeps on it (its trace and metadata). */\nexport function useMessageDetails(\n messageId: string | null | undefined,\n options?: { enabled?: boolean }\n) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.messageDetails(messageId ?? ''),\n queryFn: () => arbi.conversations.getMessage(messageId as string),\n enabled: (options?.enabled ?? true) && !!messageId && arbi.isLoggedIn,\n })\n}\n\n/**\n * A conversation's stored threads (each with its message history, citations data included). The\n * chat engine and the conversation's events keep the cache current, so it is re-read only when\n * stale (2 minutes) or when the page is shown again while this tab is not streaming the\n * conversation (a turn sent from another tab never reaches this one's socket). A conversation with\n * no messages yet (a new to-do, a workflow's task before its run) comes back with no threads. A 404\n * is a conversation this user cannot see (gone, or in a workspace they left): an error, never cached\n * as an empty conversation to write into. `live` re-reads it every few seconds.\n */\nexport function useConversationThreads(\n conversationId: string | undefined,\n options?: { enabled?: boolean; live?: boolean }\n) {\n const arbi = useArbi()\n const session = useArbiSessionStore()\n return useQuery({\n queryKey: arbiQueryKeys.conversationThreads(conversationId ?? ''),\n queryFn: (): Promise<ThreadsResponse> =>\n arbi.conversations.getThreads(conversationId as string),\n enabled: (options?.enabled ?? true) && !!conversationId && arbi.hasWorkspace,\n staleTime: 2 * 60 * 1000,\n refetchOnWindowFocus: () =>\n session.getState().generating[conversationId ?? '']?.isGenerating ? false : 'always',\n refetchInterval: options?.live ? 3000 : false,\n })\n}\n\n/** A tag list query as a stable cache key ('' for every tag). */\nconst tagListKey = (query: TagListQuery): string =>\n [\n query.kind ? `kind:${query.kind}` : '',\n query.parentId ? `parent:${query.parentId}` : '',\n query.ids?.length ? `ids:${query.ids.join(',')}` : '',\n query.include?.length ? `include:${query.include.join(',')}` : '',\n query.linksLimit !== undefined ? `links:${query.linksLimit}` : '',\n ]\n .filter(Boolean)\n .join('|')\n\n/**\n * List tags in a workspace (default: the open one) \u2014 all of them, or filtered: `{ kind: 'issue',\n * include: ['links'] }` is every issue with its documents, facts and threads (a table's rows; its\n * columns come from `useTagKindSchema`). `ids: []` asks for nothing.\n *\n * The whole list is read once and then kept current in place: the tag writes patch it\n * (`patchWorkspaceTags`), and an invalidation of the workspace's tags (a WebSocket event, a host\n * refresh) re-reads it. It is never re-read just for being mounted or the window being focused.\n */\nexport function useTags(\n workspaceId?: string | null,\n options?: TagListQuery & { enabled?: boolean }\n) {\n const arbi = useArbi()\n const { enabled, ...query } = options ?? {}\n const workspace = workspaceId ?? (arbi.hasWorkspace ? arbi.getWorkspaceId() : '')\n const key = tagListKey(query)\n return useQuery({\n queryKey: key ? arbiQueryKeys.tagList(workspace, key) : arbiQueryKeys.tags(workspace),\n // The request names the workspace (opened for this session first when it is not the current\n // one), so another workspace's tags can be listed and a switch cannot answer for it. The\n // current workspace's list is also read under the switch guard.\n queryFn: () => {\n const list = () => arbi.tags.list({ ...(key ? query : {}), workspaceId: workspace })\n return workspace === arbi.getWorkspaceId() ? arbi.readInWorkspace(workspace, list) : list()\n },\n enabled:\n (enabled ?? true) &&\n !!workspace &&\n arbi.hasWorkspace &&\n (query.ids === undefined || query.ids.length > 0),\n ...(key ? {} : { staleTime: Infinity }),\n })\n}\n\n/**\n * Batch-fetch first-page thumbnails for a set of documents. Returns a map of\n * doc external id \u2192 `data:image/webp` URI (or `null` when no thumbnail exists).\n * Cached for a few minutes since thumbnails are effectively immutable per doc.\n */\nexport function useThumbnails(docIds: string[], options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.thumbnails(docIds),\n queryFn: () => arbi.documents.getThumbnails(docIds),\n enabled: (options?.enabled ?? true) && docIds.length > 0 && arbi.hasWorkspace,\n staleTime: 5 * 60_000,\n })\n}\n\n/**\n * Fetch a document's parsed content (chunks grouped by page) for the review\n * viewer. `stage` defaults to `final` (fully processed); `marker`/`subchunk`\n * expose earlier pipeline stages. `docId` may be a version reference (`doc-\u2026@v2`).\n */\nexport function useParsedDocument(\n docId: string | undefined,\n stage: string = 'final',\n options?: { enabled?: boolean }\n) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.parsedDoc(docId ?? '', stage),\n queryFn: () => {\n // A version reference (`doc-\u2026@v2`) reads that version's parse.\n const { docId: id, version } = parseVersionRef(docId as string)\n return arbi.documents.getParsedContent(\n id,\n stage,\n version ?? undefined\n ) as unknown as Promise<ParsedDocument>\n },\n enabled: (options?.enabled ?? true) && !!docId && arbi.hasWorkspace,\n })\n}\n\n/**\n * Ask the assistant (`arbi.assistant.ask`) as a mutation: one streaming turn, its frames to\n * `handlers`, resolving with the accumulated result.\n */\nexport function useAssistantQuery() {\n const arbi = useArbi()\n return useMutation<SSEStreamResult, Error, { request: AskRequest; handlers?: AskHandlers }>({\n mutationFn: ({ request, handlers }) => arbi.assistant.ask(request, handlers),\n })\n}\n\n/** List agents owned by the current user. */\nexport function useAgents(options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.agents(),\n queryFn: () => arbi.agents.list(),\n enabled: (options?.enabled ?? true) && arbi.isLoggedIn,\n })\n}\n\n/**\n * Delete agents. Returns a mutation. Refreshes the agent list, the workflow list and the conversation list\n * (a deleted agent's workflows and work go with it), and drops the deleted agents' own config and workspace queries.\n */\nexport function useDeleteAgents() {\n const arbi = useArbi()\n const qc = useQueryClient()\n return useMutation<unknown, Error, { agentExtIds: string[] }>({\n mutationFn: ({ agentExtIds }) => arbi.agents.delete(agentExtIds),\n onSuccess: (_result, { agentExtIds }) => {\n for (const id of agentExtIds) {\n qc.removeQueries({ queryKey: arbiQueryKeys.agentConfig(id) })\n qc.removeQueries({ queryKey: arbiQueryKeys.agentWorkspaces(id) })\n }\n return Promise.all([\n qc.invalidateQueries({ queryKey: arbiQueryKeys.agents() }),\n qc.invalidateQueries({ queryKey: arbiQueryKeys.workflows() }),\n qc.invalidateQueries({ queryKey: arbiQueryKeys.allConversations() }),\n qc.invalidateQueries({ queryKey: arbiQueryKeys.configs() }),\n ])\n },\n })\n}\n\n/** Authorize a delegated session (generates claim code). Returns a mutation. */\n\n/** Check backend health. */\nexport function useHealth(options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.health(),\n queryFn: () => arbi.health.check(),\n enabled: options?.enabled,\n })\n}\n\n/**\n * The deployment's models with their tags (`Standard`, `Premium`), providers and per-token costs,\n * and the default premium model. Static per deployment: read once.\n */\nexport function useAvailableModels(options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.availableModels(),\n queryFn: () => arbi.health.models(),\n staleTime: Infinity,\n enabled: (options?.enabled ?? true) && arbi.isLoggedIn,\n })\n}\n\n// \u2500\u2500 Behaviour-template configs \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/** List the caller's saved agent configurations (behaviour templates). */\nexport function useConfigs(options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.configVersions(),\n queryFn: () => arbi.agentConfig.list(),\n enabled: options?.enabled ?? arbi.isLoggedIn,\n })\n}\n\n/** One saved agent configuration (its models, its tools). Configs change only on a save. */\nexport function useConfig(configId: string | null | undefined, options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.config(configId ?? ''),\n queryFn: () => arbi.agentConfig.get(configId as string),\n staleTime: 10 * 60 * 1000,\n enabled: (options?.enabled ?? true) && !!configId && arbi.isLoggedIn,\n })\n}\n\n// \u2500\u2500 Activity feed \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/**\n * List the caller's durable activity feed, newest first.\n *\n * Activity entries are backend-originated, to-self log lines that are always\n * read \u2014 they are deliberately kept out of the normal notifications/DM feed and\n * never affect the unread badge, so this is a separate, opt-in query.\n */\nexport function useActivity(options?: { enabled?: boolean; limit?: number; offset?: number }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.activity(),\n queryFn: () => arbi.dm.listActivity({ limit: options?.limit, offset: options?.offset }),\n enabled: options?.enabled ?? arbi.isLoggedIn,\n })\n}\n\n/**\n * A workspace's activity feed, newest first, a page at a time: thread history, people posting,\n * uploads, new versions and signatures, workflow runs. Only what the caller can see. The pages\n * are `data.pages`; `fetchNextPage` reads the next one while `hasNextPage`.\n */\nexport function useWorkspaceActivity(\n workspaceId: string | null | undefined,\n options?: {\n enabled?: boolean\n limit?: number\n /** Runs before each page, e.g. to (re)open the workspace so titles and names decrypt. */\n beforeFetch?: () => Promise<unknown>\n }\n) {\n const arbi = useArbi()\n return useInfiniteQuery({\n queryKey: arbiQueryKeys.workspaceActivity(workspaceId ?? '', options?.limit),\n queryFn: async ({ pageParam }) => {\n await options?.beforeFetch?.()\n return arbi.workspaces.activity(workspaceId as string, {\n cursor: pageParam,\n limit: options?.limit,\n })\n },\n initialPageParam: null as string | null,\n getNextPageParam: (page) => page.next_cursor ?? undefined,\n enabled: (options?.enabled ?? true) && !!workspaceId && arbi.isLoggedIn,\n })\n}\n\n// \u2500\u2500 Projects, usage & spend \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/** List the logged-in user's projects (billing accounts). */\nexport function useProjects(options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.projects(),\n queryFn: () => arbi.projects.list(),\n enabled: options?.enabled ?? arbi.isLoggedIn,\n })\n}\n\n/**\n * AI usage breakdown for a project's billing period. `monthsBack` selects the period (0 =\n * current, 1 = previous month, \u2026).\n *\n * The response's `total_spend` / `spend` fields are \u00A3 of AI usage (format with `formatGbp`).\n * `metered` is `false` when the deployment does not record usage (a `dev`-plan project with all\n * zeros): show \"usage is not metered here\" instead of zeros. It is `undefined` until the usage\n * has loaded.\n */\nexport function useProjectUsage(\n projectExtId: string | undefined,\n monthsBack: number = 0,\n options?: { enabled?: boolean }\n) {\n const arbi = useArbi()\n const usage = useQuery({\n queryKey: arbiQueryKeys.projectUsage(projectExtId ?? '', monthsBack),\n queryFn: () => arbi.projects.usage(projectExtId as string, monthsBack),\n enabled: (options?.enabled ?? true) && !!projectExtId && arbi.isLoggedIn,\n })\n const projects = useProjects({ enabled: !!projectExtId && (options?.enabled ?? true) })\n const subscription = projects.data?.find((p) => p.external_id === projectExtId)?.subscription\n const metered = usage.data ? isUsageMetered(usage.data, subscription) : undefined\n return { ...usage, metered }\n}\n\n/** List the Stripe invoices for a project's subscription. */\nexport function useProjectInvoices(\n projectExtId: string | undefined,\n options?: { enabled?: boolean }\n) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.projectInvoices(projectExtId ?? ''),\n queryFn: () => arbi.projects.invoices(projectExtId as string),\n enabled: (options?.enabled ?? true) && !!projectExtId && arbi.isLoggedIn,\n })\n}\n\n/**\n * The signed-in user from `GET /v1/user/me`. Refetched on window focus, so a role granted or\n * removed elsewhere shows up without a reload; invalidate `arbiQueryKeys.currentUser()` after a\n * change you made yourself.\n */\nexport function useCurrentUser(options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.currentUser(),\n queryFn: () => arbi.user.me(),\n enabled: options?.enabled ?? arbi.isLoggedIn,\n refetchOnWindowFocus: true,\n staleTime: 30_000,\n })\n}\n\n/**\n * The firm's pooled monthly \u00A3 of AI usage (Box deployments). A 403 (the caller is not a firm member\n * or Box admin) is not retried: treat an error like `has_pool: false` and show nothing.\n */\nfunction useFirmPool(options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.firmPool(),\n queryFn: () => arbi.firm.pool(),\n enabled: (options?.enabled ?? true) && arbi.isLoggedIn,\n retry: false,\n refetchOnWindowFocus: true,\n staleTime: 60_000,\n })\n}\n\n/**\n * Whether this deployment runs under a Box licence (`isBox`) and whether the user administers it in\n * the ARBI portal (`isBoxAdmin`), from the firm pool. Anyone outside the firm gets a 403 (not\n * retried), read as no Box. The API has no Box-admin flag yet: `can_top_up` is true only for a Box\n * admin of a licence central can bill, so admins of a hand-set licence read as members for now.\n */\nexport function useBoxRole(options: { enabled?: boolean } = {}): {\n isBox: boolean\n isBoxAdmin: boolean\n} {\n const { data, isError } = useFirmPool(options)\n const isBox = !isError && !!data?.has_pool\n return { isBox, isBoxAdmin: isBox && !!data?.can_top_up }\n}\n\n/** Why \"New project\" / \"New workspace\" is unavailable to someone who may not create them. */\nexport const PROJECT_CREATION_DENIED_REASON =\n 'Only members of your firm can create projects and workspaces.'\n\n/** Why the server refuses \"New project\" (`GET /v1/user/me`: `project_creation_refusal`). */\nexport type ProjectCreationRefusal = NonNullable<\n components['schemas']['CurrentUserResponse']['project_creation_refusal']\n>\n\nconst PROJECT_CREATION_REFUSAL_REASONS: Record<ProjectCreationRefusal, string> = {\n external_user: 'External users cannot create projects.',\n not_a_member: PROJECT_CREATION_DENIED_REASON,\n managers_only: 'Only managers can create projects on this deployment.',\n pro_required: 'Upgrade your personal project to Pro to create more projects.',\n}\n\n/** The signed-in user, re-read when their workspace memberships change (a role can change what they may create). */\nfunction useCreationRights() {\n const user = useCurrentUser()\n const { data: workspaces } = useWorkspaces({ enabled: user.isSuccess })\n const membership = workspaces?.map((w) => w.external_id).join(',')\n const { refetch } = user\n const seen = useRef<string | undefined>(undefined)\n useEffect(() => {\n if (membership === undefined || membership === seen.current) return\n const first = seen.current === undefined\n seen.current = membership\n if (!first) void refetch()\n }, [membership, refetch])\n return user.data\n}\n\n/**\n * Whether the signed-in user may create projects. `undefined` while the user is loading: callers\n * should neither offer nor refuse creation until it is known.\n */\nexport function useCanCreateProjects(): boolean | undefined {\n return useCreationRights()?.can_create_projects\n}\n\n/**\n * Why the signed-in user may not create projects, or `undefined` when they may (or while loading).\n * `refusal` is the server's code: `pro_required` on the hosted service means \"upgrade your personal\n * project to Pro\", so hosts can offer the plans instead of a dead button.\n */\nexport function useProjectCreationDenial():\n { refusal: ProjectCreationRefusal | undefined; reason: string } | undefined {\n const me = useCreationRights()\n if (!me || me.can_create_projects) return undefined\n const refusal = me.project_creation_refusal ?? undefined\n return {\n refusal,\n reason: refusal ? PROJECT_CREATION_REFUSAL_REASONS[refusal] : PROJECT_CREATION_DENIED_REASON,\n }\n}\n\n/**\n * Whether the signed-in user may create workspaces (in projects they own). A free hosted user may,\n * though not projects. `undefined` while loading.\n */\nexport function useCanCreateWorkspaces(): boolean | undefined {\n const me = useCreationRights()\n // An older server has no can_create_workspaces: it gated both on can_create_projects.\n return me && (me.can_create_workspaces ?? me.can_create_projects)\n}\n\n/**\n * Today's deployment-wide AI usage (\u00A3, `used_gbp`) for the signed-in user: pair it with a project's\n * `daily_cap_per_user` for a \"\u00A3 used today\" indicator. Re-read on mount and window focus, and when\n * the host invalidates it after the user's own generation; never polled.\n */\nexport function useUserUsageToday(options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.userUsageToday(),\n queryFn: () => arbi.user.usageToday(),\n enabled: (options?.enabled ?? true) && arbi.isLoggedIn,\n refetchOnWindowFocus: true,\n refetchOnMount: 'always',\n staleTime: 15_000,\n })\n}\n"],
|
|
5
|
-
"mappings": "AAIA,SAAS,WAAW,SAAS,cAAc;AAC3C,SAAS,kBAAkB,UAAU,aAAa,sBAAsB;AASxE,SAAS,eAAe;AACxB,SAAS,2BAA2B;AAEpC,SAAS,sBAAsB;AAC/B,SAAS,uBAAuB;AAKhC,SAAS,eAAe,wBAAwB;AAChD,SAAS,iBAAAA,sBAAqB;
|
|
4
|
+
"sourcesContent": ["/**\n * React Query hooks that use the Arbi instance from context.\n */\n\nimport { useEffect, useMemo, useRef } from 'react'\nimport { useInfiniteQuery, useQuery, useMutation, useQueryClient } from '@tanstack/react-query'\nimport {\n type AskHandlers,\n type AskRequest,\n type SSEStreamResult,\n type TagListQuery,\n type ThreadsResponse,\n} from '@arbidocs/sdk/browser'\nimport type { components } from '@arbidocs/client'\nimport { useArbi } from './useArbi'\nimport { useArbiSessionStore } from './session'\nimport type { ParsedDocument } from './documents/parsed-types'\nimport { isUsageMetered } from './usage-metered'\nimport { parseVersionRef } from './artifacts/versions'\n\n// \u2500\u2500 Query keys \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n// The one key factory (every query and mutation key of the packages and the app): ./query-keys.\nexport { arbiQueryKeys, arbiMutationKeys } from './query-keys'\nimport { arbiQueryKeys } from './query-keys'\nimport { readConversationList } from './conversation-list'\n\n// \u2500\u2500 Hooks \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/** List the logged-in user's workspaces. */\nexport function useWorkspaces(options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.workspaces(),\n queryFn: () => arbi.workspaces.list(),\n enabled: (options?.enabled ?? true) && arbi.isLoggedIn,\n })\n}\n\n/** Every version of the document `docId`, oldest first (`is_current` marks the current one). */\nexport function useDocumentVersionList(\n docId: string | null | undefined,\n options?: { enabled?: boolean }\n) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.documentVersions(docId ?? ''),\n queryFn: () => arbi.documents.versions(docId as string),\n enabled: (options?.enabled ?? true) && !!docId && arbi.hasWorkspace,\n })\n}\n\n/**\n * A workspace's conversations (threads and tasks). The list is kept current by its writers and the\n * workspace's events (`conversation-list`), so it is not re-read on every mount; `live` re-reads it\n * on a timer instead, faster while something is generating, for a view that follows runs by itself.\n */\nexport function useConversations(\n workspaceId: string | undefined,\n options?: { enabled?: boolean; live?: boolean }\n) {\n const arbi = useArbi()\n const queryClient = useQueryClient()\n const live = options?.live === true\n return useQuery({\n queryKey: arbiQueryKeys.conversations(workspaceId ?? ''),\n // The request names the workspace, so a switch while it runs cannot answer for another.\n queryFn: () =>\n readConversationList(queryClient, workspaceId as string, () =>\n arbi.conversations.list({ workspaceId: workspaceId as string })\n ),\n enabled: (options?.enabled ?? true) && !!workspaceId && arbi.hasWorkspace,\n placeholderData: (previous) => previous,\n ...(live\n ? {\n refetchInterval: (query: { state: { data?: Array<{ status?: string | null }> } }) =>\n query.state.data?.some((conversation) => conversation.status === 'generating')\n ? 3000\n : 15000,\n }\n : { staleTime: Infinity, refetchOnMount: false, refetchOnReconnect: false }),\n })\n}\n\n/** The backend's built-in slash commands (`/compact`, `/goal`, \u2026), for a slash menu. */\nexport function useBuiltinCommands() {\n const arbi = useArbi()\n const query = useQuery({\n queryKey: arbiQueryKeys.assistantCommands(),\n queryFn: () => arbi.assistant.commands(),\n staleTime: 30 * 1000,\n enabled: arbi.isLoggedIn,\n })\n // Stable identity so a menu's merge and filter memos do not rerun every render.\n const commands = useMemo(() => query.data ?? [], [query.data])\n return { commands, isLoading: query.isLoading }\n}\n\n/** One stored message with everything the server keeps on it (its trace and metadata). */\nexport function useMessageDetails(\n messageId: string | null | undefined,\n options?: { enabled?: boolean }\n) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.messageDetails(messageId ?? ''),\n queryFn: () => arbi.conversations.getMessage(messageId as string),\n enabled: (options?.enabled ?? true) && !!messageId && arbi.isLoggedIn,\n })\n}\n\n/**\n * A conversation's stored threads (each with its message history, citations data included). The\n * chat engine and the conversation's events keep the cache current, so it is re-read only when\n * stale (2 minutes) or when the page is shown again while this tab is not streaming the\n * conversation (a turn sent from another tab never reaches this one's socket). A conversation with\n * no messages yet (a new to-do, a workflow's task before its run) comes back with no threads. A 404\n * is a conversation this user cannot see (gone, or in a workspace they left): an error, never cached\n * as an empty conversation to write into. `live` re-reads it every few seconds.\n */\nexport function useConversationThreads(\n conversationId: string | undefined,\n options?: { enabled?: boolean; live?: boolean }\n) {\n const arbi = useArbi()\n const session = useArbiSessionStore()\n return useQuery({\n queryKey: arbiQueryKeys.conversationThreads(conversationId ?? ''),\n queryFn: (): Promise<ThreadsResponse> =>\n arbi.conversations.getThreads(conversationId as string),\n enabled: (options?.enabled ?? true) && !!conversationId && arbi.hasWorkspace,\n staleTime: 2 * 60 * 1000,\n refetchOnWindowFocus: () =>\n session.getState().generating[conversationId ?? '']?.isGenerating ? false : 'always',\n refetchInterval: options?.live ? 3000 : false,\n })\n}\n\n/** A tag list query as a stable cache key ('' for every tag). */\nconst tagListKey = (query: TagListQuery): string =>\n [\n query.kind ? `kind:${query.kind}` : '',\n query.parentId ? `parent:${query.parentId}` : '',\n query.ids?.length ? `ids:${query.ids.join(',')}` : '',\n query.include?.length ? `include:${query.include.join(',')}` : '',\n query.linksLimit !== undefined ? `links:${query.linksLimit}` : '',\n ]\n .filter(Boolean)\n .join('|')\n\n/**\n * List tags in a workspace (default: the open one) \u2014 all of them, or filtered: `{ kind: 'issue',\n * include: ['links'] }` is every issue with its documents, facts and threads (a table's rows; its\n * columns come from `useTagKindSchema`). `ids: []` asks for nothing.\n *\n * The whole list is read once and then kept current in place: the tag writes patch it\n * (`patchWorkspaceTags`), and an invalidation of the workspace's tags (a WebSocket event, a host\n * refresh) re-reads it. It is never re-read just for being mounted or the window being focused.\n */\nexport function useTags(\n workspaceId?: string | null,\n options?: TagListQuery & { enabled?: boolean }\n) {\n const arbi = useArbi()\n const { enabled, ...query } = options ?? {}\n const workspace = workspaceId ?? (arbi.hasWorkspace ? arbi.getWorkspaceId() : '')\n const key = tagListKey(query)\n return useQuery({\n queryKey: key ? arbiQueryKeys.tagList(workspace, key) : arbiQueryKeys.tags(workspace),\n // The request names the workspace (opened for this session first when it is not the current\n // one), so another workspace's tags can be listed and a switch cannot answer for it. The\n // current workspace's list is also read under the switch guard.\n queryFn: () => {\n const list = () => arbi.tags.list({ ...(key ? query : {}), workspaceId: workspace })\n return workspace === arbi.getWorkspaceId() ? arbi.readInWorkspace(workspace, list) : list()\n },\n enabled:\n (enabled ?? true) &&\n !!workspace &&\n arbi.hasWorkspace &&\n (query.ids === undefined || query.ids.length > 0),\n ...(key ? {} : { staleTime: Infinity }),\n })\n}\n\n/**\n * Batch-fetch first-page thumbnails for a set of documents. Returns a map of\n * doc external id \u2192 `data:image/webp` URI (or `null` when no thumbnail exists).\n * Cached for a few minutes since thumbnails are effectively immutable per doc.\n */\nexport function useThumbnails(docIds: string[], options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.thumbnails(docIds),\n queryFn: () => arbi.documents.getThumbnails(docIds),\n enabled: (options?.enabled ?? true) && docIds.length > 0 && arbi.hasWorkspace,\n staleTime: 5 * 60_000,\n })\n}\n\n/**\n * Fetch a document's parsed content (chunks grouped by page) for the review\n * viewer. `stage` defaults to `final` (fully processed); `marker`/`subchunk`\n * expose earlier pipeline stages. `docId` may be a version reference (`doc-\u2026@v2`).\n */\nexport function useParsedDocument(\n docId: string | undefined,\n stage: string = 'final',\n options?: { enabled?: boolean }\n) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.parsedDoc(docId ?? '', stage),\n queryFn: () => {\n // A version reference (`doc-\u2026@v2`) reads that version's parse.\n const { docId: id, version } = parseVersionRef(docId as string)\n return arbi.documents.getParsedContent(\n id,\n stage,\n version ?? undefined\n ) as unknown as Promise<ParsedDocument>\n },\n enabled: (options?.enabled ?? true) && !!docId && arbi.hasWorkspace,\n })\n}\n\n/**\n * Ask the assistant (`arbi.assistant.ask`) as a mutation: one streaming turn, its frames to\n * `handlers`, resolving with the accumulated result.\n */\nexport function useAssistantQuery() {\n const arbi = useArbi()\n return useMutation<SSEStreamResult, Error, { request: AskRequest; handlers?: AskHandlers }>({\n mutationFn: ({ request, handlers }) => arbi.assistant.ask(request, handlers),\n })\n}\n\n/** List agents owned by the current user. */\nexport function useAgents(options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.agents(),\n queryFn: () => arbi.agents.list(),\n enabled: (options?.enabled ?? true) && arbi.isLoggedIn,\n })\n}\n\n/**\n * Delete agents. Returns a mutation. Refreshes the agent list, the workflow list and the conversation list\n * (a deleted agent's workflows and work go with it), and drops the deleted agents' own config and workspace queries.\n */\nexport function useDeleteAgents() {\n const arbi = useArbi()\n const qc = useQueryClient()\n return useMutation<unknown, Error, { agentExtIds: string[] }>({\n mutationFn: ({ agentExtIds }) => arbi.agents.delete(agentExtIds),\n onSuccess: (_result, { agentExtIds }) => {\n for (const id of agentExtIds) {\n qc.removeQueries({ queryKey: arbiQueryKeys.agentConfig(id) })\n qc.removeQueries({ queryKey: arbiQueryKeys.agentWorkspaces(id) })\n }\n return Promise.all([\n qc.invalidateQueries({ queryKey: arbiQueryKeys.agents() }),\n qc.invalidateQueries({ queryKey: arbiQueryKeys.workflows() }),\n qc.invalidateQueries({ queryKey: arbiQueryKeys.allConversations() }),\n qc.invalidateQueries({ queryKey: arbiQueryKeys.configs() }),\n ])\n },\n })\n}\n\n/** Authorize a delegated session (generates claim code). Returns a mutation. */\n\n/** Check backend health. */\nexport function useHealth(options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.health(),\n queryFn: () => arbi.health.check(),\n enabled: options?.enabled,\n })\n}\n\n/**\n * The deployment's models with their tags (`Standard`, `Premium`), providers and per-token costs,\n * and the default premium model. Static per deployment: read once.\n */\nexport function useAvailableModels(options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.availableModels(),\n queryFn: () => arbi.health.models(),\n staleTime: Infinity,\n enabled: (options?.enabled ?? true) && arbi.isLoggedIn,\n })\n}\n\n// \u2500\u2500 Behaviour-template configs \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/** List the caller's saved agent configurations (behaviour templates). */\nexport function useConfigs(options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.configVersions(),\n queryFn: () => arbi.agentConfig.list(),\n enabled: options?.enabled ?? arbi.isLoggedIn,\n })\n}\n\n/** One saved agent configuration (its models, its tools). Configs change only on a save. */\nexport function useConfig(configId: string | null | undefined, options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.config(configId ?? ''),\n queryFn: () => arbi.agentConfig.get(configId as string),\n staleTime: 10 * 60 * 1000,\n enabled: (options?.enabled ?? true) && !!configId && arbi.isLoggedIn,\n })\n}\n\n// \u2500\u2500 Activity feed \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/**\n * List the caller's durable activity feed, newest first.\n *\n * Activity entries are backend-originated, to-self log lines that are always\n * read \u2014 they are deliberately kept out of the normal notifications/DM feed and\n * never affect the unread badge, so this is a separate, opt-in query.\n */\nexport function useActivity(options?: { enabled?: boolean; limit?: number; offset?: number }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.activity(),\n queryFn: () => arbi.dm.listActivity({ limit: options?.limit, offset: options?.offset }),\n enabled: options?.enabled ?? arbi.isLoggedIn,\n })\n}\n\n/**\n * A workspace's activity feed, newest first, a page at a time: thread history, people posting,\n * uploads, new versions and signatures, workflow runs. Only what the caller can see. The pages\n * are `data.pages`; `fetchNextPage` reads the next one while `hasNextPage`.\n */\nexport function useWorkspaceActivity(\n workspaceId: string | null | undefined,\n options?: {\n enabled?: boolean\n limit?: number\n /** Runs before each page, e.g. to (re)open the workspace so titles and names decrypt. */\n beforeFetch?: () => Promise<unknown>\n }\n) {\n const arbi = useArbi()\n return useInfiniteQuery({\n queryKey: arbiQueryKeys.workspaceActivity(workspaceId ?? '', options?.limit),\n queryFn: async ({ pageParam }) => {\n await options?.beforeFetch?.()\n return arbi.workspaces.activity(workspaceId as string, {\n cursor: pageParam,\n limit: options?.limit,\n })\n },\n initialPageParam: null as string | null,\n getNextPageParam: (page) => page.next_cursor ?? undefined,\n enabled: (options?.enabled ?? true) && !!workspaceId && arbi.isLoggedIn,\n })\n}\n\n// \u2500\u2500 Projects, usage & spend \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/** List the logged-in user's projects (billing accounts). */\nexport function useProjects(options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.projects(),\n queryFn: () => arbi.projects.list(),\n enabled: options?.enabled ?? arbi.isLoggedIn,\n })\n}\n\n/**\n * AI usage breakdown for a project's billing period. `monthsBack` selects the period (0 =\n * current, 1 = previous month, \u2026).\n *\n * The response's `total_spend` / `spend` fields are \u00A3 of AI usage (format with `formatGbp`).\n * `metered` is `false` when the deployment does not record usage (a `dev`-plan project with all\n * zeros): show \"usage is not metered here\" instead of zeros. It is `undefined` until the usage\n * has loaded.\n */\nexport function useProjectUsage(\n projectExtId: string | undefined,\n monthsBack: number = 0,\n options?: { enabled?: boolean }\n) {\n const arbi = useArbi()\n const usage = useQuery({\n queryKey: arbiQueryKeys.projectUsage(projectExtId ?? '', monthsBack),\n queryFn: () => arbi.projects.usage(projectExtId as string, monthsBack),\n enabled: (options?.enabled ?? true) && !!projectExtId && arbi.isLoggedIn,\n })\n const projects = useProjects({ enabled: !!projectExtId && (options?.enabled ?? true) })\n const subscription = projects.data?.find((p) => p.external_id === projectExtId)?.subscription\n const metered = usage.data ? isUsageMetered(usage.data, subscription) : undefined\n return { ...usage, metered }\n}\n\n/** List the Stripe invoices for a project's subscription. */\nexport function useProjectInvoices(\n projectExtId: string | undefined,\n options?: { enabled?: boolean }\n) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.projectInvoices(projectExtId ?? ''),\n queryFn: () => arbi.projects.invoices(projectExtId as string),\n enabled: (options?.enabled ?? true) && !!projectExtId && arbi.isLoggedIn,\n })\n}\n\n/**\n * The signed-in user from `GET /v1/user/me`. Refetched on window focus, so a role granted or\n * removed elsewhere shows up without a reload; invalidate `arbiQueryKeys.currentUser()` after a\n * change you made yourself.\n */\nexport function useCurrentUser(options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.currentUser(),\n queryFn: () => arbi.user.me(),\n enabled: options?.enabled ?? arbi.isLoggedIn,\n refetchOnWindowFocus: true,\n staleTime: 30_000,\n })\n}\n\n/**\n * The firm's pooled monthly \u00A3 of AI usage (Box deployments). A 403 (the caller is not a firm member\n * or Box admin) is not retried: treat an error like `has_pool: false` and show nothing.\n */\nfunction useFirmPool(options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.firmPool(),\n queryFn: () => arbi.firm.pool(),\n enabled: (options?.enabled ?? true) && arbi.isLoggedIn,\n retry: false,\n refetchOnWindowFocus: true,\n staleTime: 60_000,\n })\n}\n\n/**\n * Whether this deployment runs under a Box licence (`isBox`) and whether the user administers it in\n * the ARBI portal (`isBoxAdmin`), from the firm pool. Anyone outside the firm gets a 403 (not\n * retried), read as no Box. The API has no Box-admin flag yet: `can_top_up` is true only for a Box\n * admin of a licence central can bill, so admins of a hand-set licence read as members for now.\n */\nexport function useBoxRole(options: { enabled?: boolean } = {}): {\n isBox: boolean\n isBoxAdmin: boolean\n} {\n const { data, isError } = useFirmPool(options)\n const isBox = !isError && !!data?.has_pool\n return { isBox, isBoxAdmin: isBox && !!data?.can_top_up }\n}\n\n/** Why \"New project\" / \"New workspace\" is unavailable to someone who may not create them. */\nexport const PROJECT_CREATION_DENIED_REASON =\n 'Only members of your firm can create projects and workspaces.'\n\n/** Why the server refuses \"New project\" (`GET /v1/user/me`: `project_creation_refusal`). */\nexport type ProjectCreationRefusal = NonNullable<\n components['schemas']['CurrentUserResponse']['project_creation_refusal']\n>\n\nconst PROJECT_CREATION_REFUSAL_REASONS: Record<ProjectCreationRefusal, string> = {\n external_user: 'External users cannot create projects.',\n not_a_member: PROJECT_CREATION_DENIED_REASON,\n managers_only: 'Only managers can create projects on this deployment.',\n pro_required: 'Upgrade your personal project to Pro to create more projects.',\n}\n\n/** The signed-in user, re-read when their workspace memberships change (a role can change what they may create). */\nfunction useCreationRights() {\n const user = useCurrentUser()\n const { data: workspaces } = useWorkspaces({ enabled: user.isSuccess })\n const membership = workspaces?.map((w) => w.external_id).join(',')\n const { refetch } = user\n const seen = useRef<string | undefined>(undefined)\n useEffect(() => {\n if (membership === undefined || membership === seen.current) return\n const first = seen.current === undefined\n seen.current = membership\n if (!first) void refetch()\n }, [membership, refetch])\n return user.data\n}\n\n/**\n * Whether the signed-in user may create projects. `undefined` while the user is loading: callers\n * should neither offer nor refuse creation until it is known.\n */\nexport function useCanCreateProjects(): boolean | undefined {\n return useCreationRights()?.can_create_projects\n}\n\n/**\n * Why the signed-in user may not create projects, or `undefined` when they may (or while loading).\n * `refusal` is the server's code: `pro_required` on the hosted service means \"upgrade your personal\n * project to Pro\", so hosts can offer the plans instead of a dead button.\n */\nexport function useProjectCreationDenial():\n { refusal: ProjectCreationRefusal | undefined; reason: string } | undefined {\n const me = useCreationRights()\n if (!me || me.can_create_projects) return undefined\n const refusal = me.project_creation_refusal ?? undefined\n return {\n refusal,\n reason: refusal ? PROJECT_CREATION_REFUSAL_REASONS[refusal] : PROJECT_CREATION_DENIED_REASON,\n }\n}\n\n/**\n * Whether the signed-in user may create workspaces (in projects they own). A free hosted user may,\n * though not projects. `undefined` while loading.\n */\nexport function useCanCreateWorkspaces(): boolean | undefined {\n const me = useCreationRights()\n // An older server has no can_create_workspaces: it gated both on can_create_projects.\n return me && (me.can_create_workspaces ?? me.can_create_projects)\n}\n\n/**\n * Today's deployment-wide AI usage (\u00A3, `used_gbp`) for the signed-in user: pair it with a project's\n * `daily_cap_per_user` for a \"\u00A3 used today\" indicator. Re-read on mount and window focus, and when\n * the host invalidates it after the user's own generation; never polled.\n */\nexport function useUserUsageToday(options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.userUsageToday(),\n queryFn: () => arbi.user.usageToday(),\n enabled: (options?.enabled ?? true) && arbi.isLoggedIn,\n refetchOnWindowFocus: true,\n refetchOnMount: 'always',\n staleTime: 15_000,\n })\n}\n"],
|
|
5
|
+
"mappings": "AAIA,SAAS,WAAW,SAAS,cAAc;AAC3C,SAAS,kBAAkB,UAAU,aAAa,sBAAsB;AASxE,S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