@arbidocs/react 0.5.130 → 0.5.132

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/contacts.js CHANGED
@@ -11,6 +11,16 @@ function useContacts(options) {
11
11
  staleTime: 3e4
12
12
  });
13
13
  }
14
+ function useReferralSummary(currentUserExtId) {
15
+ const arbi = useArbi();
16
+ return useQuery({
17
+ queryKey: [...arbiQueryKeys.contacts(), "referrals", currentUserExtId],
18
+ queryFn: () => arbi.contacts.referrals(),
19
+ enabled: arbi.isLoggedIn,
20
+ retry: false,
21
+ staleTime: 3e4
22
+ });
23
+ }
14
24
  function useInvalidateContacts() {
15
25
  const qc = useQueryClient();
16
26
  return () => qc.invalidateQueries({ queryKey: arbiQueryKeys.contacts() });
@@ -94,6 +104,7 @@ export {
94
104
  useImportContacts,
95
105
  useInviteContacts,
96
106
  useLinkContact,
107
+ useReferralSummary,
97
108
  useSearchContacts,
98
109
  useUpdateContact
99
110
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/contacts.ts"],
4
- "sourcesContent": ["/**\n * Contacts: one address book \u2014 people on ARBI, invitations still out, and plain cards.\n *\n * Shares `arbiQueryKeys.contacts()` with the messenger's people, so a change made here refreshes\n * the conversation rail on its own. The parts that turn an email list into a request and the backend\n * outcome into a sentence live in `@arbidocs/blocks/collaboration` (`AddContactsForm`).\n */\n\nimport { useEffect, useState } from 'react'\nimport { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'\nimport type { contacts as contactsOps } from '@arbidocs/sdk/browser'\nimport { useArbi } from './useArbi'\nimport { arbiQueryKeys } from './hooks'\n\n/** Every contact: registered, invited and plain cards. */\nexport function useContacts(options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.contacts(),\n queryFn: () => arbi.contacts.list(),\n enabled: (options?.enabled ?? true) && arbi.isLoggedIn,\n staleTime: 30_000,\n })\n}\n\nfunction useInvalidateContacts() {\n const qc = useQueryClient()\n return () => qc.invalidateQueries({ queryKey: arbiQueryKeys.contacts() })\n}\n\n/**\n * Invite (or link) people by email. An address not yet on ARBI gets an invitation. Resolves with one\n * row per address (`outcome`, `status`); map it with `toAddContactsRows` from `@arbidocs/blocks/collaboration`.\n */\nexport function useInviteContacts() {\n const arbi = useArbi()\n const invalidate = useInvalidateContacts()\n return useMutation({\n mutationFn: (emails: string[]) => arbi.contacts.invite(emails),\n onSuccess: () => invalidate(),\n })\n}\n\n/** Create a card, optionally linking `email` and inviting it (`invite: true`). */\nexport function useCreateContact() {\n const arbi = useArbi()\n const invalidate = useInvalidateContacts()\n return useMutation({\n mutationFn: (body: contactsOps.ContactCreate) => arbi.contacts.create(body),\n onSuccess: () => invalidate(),\n })\n}\n\n/** Replace a contact's card details. */\nexport function useUpdateContact() {\n const arbi = useArbi()\n const invalidate = useInvalidateContacts()\n return useMutation({\n mutationFn: ({ id, card }: { id: string; card: contactsOps.ContactCardWrite }) =>\n arbi.contacts.update(id, card),\n onSuccess: () => invalidate(),\n })\n}\n\n/**\n * Invite a contact to ARBI by `email`: a card-only contact is linked in place (its row and card kept);\n * without an id a new card is created and invited. Rejects with `DuplicateContactError` when `email`\n * already belongs to another contact. The list refreshes either way.\n */\nexport function useLinkContact() {\n const arbi = useArbi()\n const invalidate = useInvalidateContacts()\n return useMutation({\n mutationFn: ({\n contact,\n email,\n card,\n }: {\n contact: Pick<contactsOps.Contact, 'external_id'>\n email: string\n card: contactsOps.ContactCardWrite\n }) =>\n contact.external_id\n ? arbi.contacts.link(contact.external_id, email, card)\n : arbi.contacts.create({ email, card, invite: true }),\n onSettled: () => invalidate(),\n })\n}\n\n/** Import one .vcf file (Pro: 403 `pro_required` otherwise); the list refreshes after each file. */\nexport function useImportContacts() {\n const arbi = useArbi()\n const invalidate = useInvalidateContacts()\n return useMutation({\n mutationFn: (file: Blob) => arbi.contacts.import(file),\n onSettled: () => invalidate(),\n })\n}\n\n/** Delete a contact, or withdraw its invitation, by contact id. */\nexport function useDeleteContact() {\n const arbi = useArbi()\n const invalidate = useInvalidateContacts()\n return useMutation({\n mutationFn: (contactId: string) => arbi.contacts.delete(contactId),\n onSuccess: () => invalidate(),\n })\n}\n\n/**\n * People matching `q` (your contacts and the registered people you share a workspace with), for a\n * picker: debounced, nothing fetched for an empty query, the previous matches kept while typing.\n */\nexport function useSearchContacts(q: string, { debounceMs = 200 }: { debounceMs?: number } = {}) {\n const arbi = useArbi()\n const term = useDebounced(q.trim(), debounceMs)\n return useQuery({\n queryKey: [...arbiQueryKeys.contacts(), 'search', term] as const,\n queryFn: () => arbi.contacts.search(term),\n enabled: term.length > 0 && arbi.isLoggedIn,\n staleTime: 60_000,\n placeholderData: (previous) => previous,\n retry: false,\n })\n}\n\nfunction useDebounced<T>(value: T, ms: number): T {\n const [debounced, setDebounced] = useState(value)\n useEffect(() => {\n const t = setTimeout(() => setDebounced(value), ms)\n return () => clearTimeout(t)\n }, [value, ms])\n return debounced\n}\n"],
5
- "mappings": "AAQA,SAAS,WAAW,gBAAgB;AACpC,SAAS,aAAa,UAAU,sBAAsB;AAEtD,SAAS,eAAe;AACxB,SAAS,qBAAqB;AAGvB,SAAS,YAAY,SAAiC;AAC3D,QAAM,OAAO,QAAQ;AACrB,SAAO,SAAS;AAAA,IACd,UAAU,cAAc,SAAS;AAAA,IACjC,SAAS,MAAM,KAAK,SAAS,KAAK;AAAA,IAClC,UAAU,SAAS,WAAW,SAAS,KAAK;AAAA,IAC5C,WAAW;AAAA,EACb,CAAC;AACH;AAEA,SAAS,wBAAwB;AAC/B,QAAM,KAAK,eAAe;AAC1B,SAAO,MAAM,GAAG,kBAAkB,EAAE,UAAU,cAAc,SAAS,EAAE,CAAC;AAC1E;AAMO,SAAS,oBAAoB;AAClC,QAAM,OAAO,QAAQ;AACrB,QAAM,aAAa,sBAAsB;AACzC,SAAO,YAAY;AAAA,IACjB,YAAY,CAAC,WAAqB,KAAK,SAAS,OAAO,MA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BAAkB,GAAW,EAAE,aAAa,IAAI,IAA6B,CAAC,GAAG;AAC/F,QAAM,OAAO,QAAQ;AACrB,QAAM,OAAO,aAAa,EAAE,KAAK,GAAG,UAAU;AAC9C,SAAO,SAAS;AAAA,IACd,UAAU,CAAC,GAAG,cAAc,SAAS,GAAG,UAAU,IAAI;AAAA,IACtD,SAAS,MAAM,KAAK,SAAS,OAAO,IAAI;AAAA,IACxC,SAAS,KAAK,SAAS,KAAK,KAAK;AAAA,IACjC,WAAW;AAAA,IACX,iBAAiB,CAAC,aAAa;AAAA,IAC/B,OAAO;AAAA,EACT,CAAC;AACH;AAEA,SAAS,aAAgB,OAAU,IAAe;AAChD,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,KAAK;AAChD,YAAU,MAAM;AACd,UAAM,IAAI,WAAW,MAAM,aAAa,KAAK,GAAG,EAAE;AAClD,WAAO,MAAM,aAAa,CAAC;AAAA,EAC7B,GAAG,CAAC,OAAO,EAAE,CAAC;AACd,SAAO;AACT;",
4
+ "sourcesContent": ["/**\n * Contacts: one address book \u2014 people on ARBI, invitations still out, and plain cards.\n *\n * Shares `arbiQueryKeys.contacts()` with the messenger's people, so a change made here refreshes\n * the conversation rail on its own. The parts that turn an email list into a request and the backend\n * outcome into a sentence live in `@arbidocs/blocks/collaboration` (`AddContactsForm`).\n */\n\nimport { useEffect, useState } from 'react'\nimport { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'\nimport type { contacts as contactsOps } from '@arbidocs/sdk/browser'\nimport { useArbi } from './useArbi'\nimport { arbiQueryKeys } from './hooks'\n\n/** Every contact: registered, invited and plain cards. */\nexport function useContacts(options?: { enabled?: boolean }) {\n const arbi = useArbi()\n return useQuery({\n queryKey: arbiQueryKeys.contacts(),\n queryFn: () => arbi.contacts.list(),\n enabled: (options?.enabled ?? true) && arbi.isLoggedIn,\n staleTime: 30_000,\n })\n}\n\n/** Referral progress for the signed-in owner's contact invitations. */\nexport function useReferralSummary(currentUserExtId: string) {\n const arbi = useArbi()\n return useQuery({\n queryKey: [...arbiQueryKeys.contacts(), 'referrals', currentUserExtId],\n queryFn: () => arbi.contacts.referrals(),\n enabled: arbi.isLoggedIn,\n retry: false,\n staleTime: 30_000,\n })\n}\n\nfunction useInvalidateContacts() {\n const qc = useQueryClient()\n return () => qc.invalidateQueries({ queryKey: arbiQueryKeys.contacts() })\n}\n\n/**\n * Invite (or link) people by email. An address not yet on ARBI gets an invitation. Resolves with one\n * row per address (`outcome`, `status`); map it with `toAddContactsRows` from `@arbidocs/blocks/collaboration`.\n */\nexport function useInviteContacts() {\n const arbi = useArbi()\n const invalidate = useInvalidateContacts()\n return useMutation({\n mutationFn: (emails: string[]) => arbi.contacts.invite(emails),\n onSuccess: () => invalidate(),\n })\n}\n\n/** Create a card, optionally linking `email` and inviting it (`invite: true`). */\nexport function useCreateContact() {\n const arbi = useArbi()\n const invalidate = useInvalidateContacts()\n return useMutation({\n mutationFn: (body: contactsOps.ContactCreate) => arbi.contacts.create(body),\n onSuccess: () => invalidate(),\n })\n}\n\n/** Replace a contact's card details. */\nexport function useUpdateContact() {\n const arbi = useArbi()\n const invalidate = useInvalidateContacts()\n return useMutation({\n mutationFn: ({ id, card }: { id: string; card: contactsOps.ContactCardWrite }) =>\n arbi.contacts.update(id, card),\n onSuccess: () => invalidate(),\n })\n}\n\n/**\n * Invite a contact to ARBI by `email`: a card-only contact is linked in place (its row and card kept);\n * without an id a new card is created and invited. Rejects with `DuplicateContactError` when `email`\n * already belongs to another contact. The list refreshes either way.\n */\nexport function useLinkContact() {\n const arbi = useArbi()\n const invalidate = useInvalidateContacts()\n return useMutation({\n mutationFn: ({\n contact,\n email,\n card,\n }: {\n contact: Pick<contactsOps.Contact, 'external_id'>\n email: string\n card: contactsOps.ContactCardWrite\n }) =>\n contact.external_id\n ? arbi.contacts.link(contact.external_id, email, card)\n : arbi.contacts.create({ email, card, invite: true }),\n onSettled: () => invalidate(),\n })\n}\n\n/** Import one .vcf file (Pro: 403 `pro_required` otherwise); the list refreshes after each file. */\nexport function useImportContacts() {\n const arbi = useArbi()\n const invalidate = useInvalidateContacts()\n return useMutation({\n mutationFn: (file: Blob) => arbi.contacts.import(file),\n onSettled: () => invalidate(),\n })\n}\n\n/** Delete a contact, or withdraw its invitation, by contact id. */\nexport function useDeleteContact() {\n const arbi = useArbi()\n const invalidate = useInvalidateContacts()\n return useMutation({\n mutationFn: (contactId: string) => arbi.contacts.delete(contactId),\n onSuccess: () => invalidate(),\n })\n}\n\n/**\n * People matching `q` (your contacts and the registered people you share a workspace with), for a\n * picker: debounced, nothing fetched for an empty query, the previous matches kept while typing.\n */\nexport function useSearchContacts(q: string, { debounceMs = 200 }: { debounceMs?: number } = {}) {\n const arbi = useArbi()\n const term = useDebounced(q.trim(), debounceMs)\n return useQuery({\n queryKey: [...arbiQueryKeys.contacts(), 'search', term] as const,\n queryFn: () => arbi.contacts.search(term),\n enabled: term.length > 0 && arbi.isLoggedIn,\n staleTime: 60_000,\n placeholderData: (previous) => previous,\n retry: false,\n })\n}\n\nfunction useDebounced<T>(value: T, ms: number): T {\n const [debounced, setDebounced] = useState(value)\n useEffect(() => {\n const t = setTimeout(() => setDebounced(value), ms)\n return () => clearTimeout(t)\n }, [value, ms])\n return debounced\n}\n"],
5
+ "mappings": "AAQA,SAAS,WAAW,gBAAgB;AACpC,SAAS,aAAa,UAAU,sBAAsB;AAEtD,SAAS,eAAe;AACxB,SAAS,qBAAqB;AAGvB,SAAS,YAAY,SAAiC;AAC3D,QAAM,OAAO,QAAQ;AACrB,SAAO,SAAS;AAAA,IACd,UAAU,cAAc,SAAS;AAAA,IACjC,SAAS,MAAM,KAAK,SAAS,KAAK;AAAA,IAClC,UAAU,SAAS,WAAW,SAAS,KAAK;AAAA,IAC5C,WAAW;AAAA,EACb,CAAC;AACH;AAGO,SAAS,mBAAmB,kBAA0B;AAC3D,QAAM,OAAO,QAAQ;AACrB,SAAO,SAAS;AAAA,IACd,UAAU,CAAC,GAAG,cAAc,SAAS,GAA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AS,oBAAoB;AAClC,QAAM,OAAO,QAAQ;AACrB,QAAM,aAAa,sBAAsB;AACzC,SAAO,YAAY;AAAA,IACjB,YAAY,CAAC,SAAe,KAAK,SAAS,OAAO,IAAI;AAAA,IACrD,WAAW,MAAM,WAAW;AAAA,EAC9B,CAAC;AACH;AAGO,SAAS,mBAAmB;AACjC,QAAM,OAAO,QAAQ;AACrB,QAAM,aAAa,sBAAsB;AACzC,SAAO,YAAY;AAAA,IACjB,YAAY,CAAC,cAAsB,KAAK,SAAS,OAAO,SAAS;AAAA,IACjE,WAAW,MAAM,WAAW;AAAA,EAC9B,CAAC;AACH;AAMO,SAAS,kBAAkB,GAAW,EAAE,aAAa,IAAI,IAA6B,CAAC,GAAG;AAC/F,QAAM,OAAO,QAAQ;AACrB,QAAM,OAAO,aAAa,EAAE,KAAK,GAAG,UAAU;AAC9C,SAAO,SAAS;AAAA,IACd,UAAU,CAAC,GAAG,cAAc,SAAS,GAAG,UAAU,IAAI;AAAA,IACtD,SAAS,MAAM,KAAK,SAAS,OAAO,IAAI;AAAA,IACxC,SAAS,KAAK,SAAS,KAAK,KAAK;AAAA,IACjC,WAAW;AAAA,IACX,iBAAiB,CAAC,aAAa;AAAA,IAC/B,OAAO;AAAA,EACT,CAAC;AACH;AAEA,SAAS,aAAgB,OAAU,IAAe;AAChD,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,KAAK;AAChD,YAAU,MAAM;AACd,UAAM,IAAI,WAAW,MAAM,aAAa,KAAK,GAAG,EAAE;AAClD,WAAO,MAAM,aAAa,CAAC;AAAA,EAC7B,GAAG,CAAC,OAAO,EAAE,CAAC;AACd,SAAO;AACT;",
6
6
  "names": []
7
7
  }
package/dist/hooks.js CHANGED
@@ -262,7 +262,13 @@ function useBoxRole(options = {}) {
262
262
  return { isBox, isBoxAdmin: isBox && !!data?.can_top_up };
263
263
  }
264
264
  const PROJECT_CREATION_DENIED_REASON = "Only members of your firm can create projects and workspaces.";
265
- function useCanCreateProjects() {
265
+ const PROJECT_CREATION_REFUSAL_REASONS = {
266
+ external_user: "External users cannot create projects.",
267
+ not_a_member: PROJECT_CREATION_DENIED_REASON,
268
+ managers_only: "Only managers can create projects on this deployment.",
269
+ pro_required: "Upgrade your personal project to Pro to create more projects."
270
+ };
271
+ function useCreationRights() {
266
272
  const user = useCurrentUser();
267
273
  const { data: workspaces } = useWorkspaces({ enabled: user.isSuccess });
268
274
  const membership = workspaces?.map((w) => w.external_id).join(",");
@@ -274,7 +280,23 @@ function useCanCreateProjects() {
274
280
  seen.current = membership;
275
281
  if (!first) void refetch();
276
282
  }, [membership, refetch]);
277
- return user.data?.can_create_projects;
283
+ return user.data;
284
+ }
285
+ function useCanCreateProjects() {
286
+ return useCreationRights()?.can_create_projects;
287
+ }
288
+ function useProjectCreationDenial() {
289
+ const me = useCreationRights();
290
+ if (!me || me.can_create_projects) return void 0;
291
+ const refusal = me.project_creation_refusal ?? void 0;
292
+ return {
293
+ refusal,
294
+ reason: refusal ? PROJECT_CREATION_REFUSAL_REASONS[refusal] : PROJECT_CREATION_DENIED_REASON
295
+ };
296
+ }
297
+ function useCanCreateWorkspaces() {
298
+ const me = useCreationRights();
299
+ return me && (me.can_create_workspaces ?? me.can_create_projects);
278
300
  }
279
301
  function useUserUsageToday(options) {
280
302
  const arbi = useArbi();
@@ -298,6 +320,7 @@ export {
298
320
  useBoxRole,
299
321
  useBuiltinCommands,
300
322
  useCanCreateProjects,
323
+ useCanCreateWorkspaces,
301
324
  useConfig,
302
325
  useConfigs,
303
326
  useConversationThreads,
@@ -308,6 +331,7 @@ export {
308
331
  useHealth,
309
332
  useMessageDetails,
310
333
  useParsedDocument,
334
+ useProjectCreationDenial,
311
335
  useProjectInvoices,
312
336
  useProjectUsage,
313
337
  useProjects,
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 { 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/**\n * Whether the signed-in user may create projects and workspaces. `undefined` while the user is\n * loading: callers should neither offer nor refuse creation until it is known.\n */\nexport function useCanCreateProjects(): boolean | undefined {\n const user = useCurrentUser()\n // A role granted or removed in a workspace can change it: re-read when the memberships do.\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?.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;AAQxE,SAAS,eAAe;AACxB,SAAS,2BAA2B;AAEpC,SAAS,sBAAsB;AAC/B,SAAS,uBAAuB;AAKhC,SAAS,eAAe,wBAAwB;AAChD,SAAS,iBAAAA,sBAAqB;AAKvB,SAAS,cAAc,SAAiC;AAC7D,QAAM,OAAO,QAAQ;AACrB,SAAO,SAAS;AAAA,IACd,UAAUA,eAAc,WAAW;AAAA,IACnC,SAAS,MAAM,KAAK,WAAW,KAAK;AAAA,IACpC,UAAU,SAAS,WAAW,SAAS,KAAK;AAAA,EAC9C,CAAC;AACH;AAGO,SAAS,uBACd,OACA,SACA;AACA,QAAM,OAAO,QAAQ;AACrB,SAAO,SAAS;AAAA,IACd,UAAUA,eAAc,iBAAiB,SAAS,EAAE;AAAA,IACpD,SAAS,MAAM,KAAK,UAAU,SAAS,KAAe;AAAA,IACtD,UAAU,SAAS,WAAW,SAAS,CAAC,CAAC,SAAS,KAAK;AAAA,EACzD,CAAC;AACH;AAOO,SAAS,iBACd,aACA,SACA;AACA,QAAM,OAAO,QAAQ;AACrB,QAAM,OAAO,SAAS,SAAS;AAC/B,SAAO,SAAS;AAAA,IACd,UAAUA,eAAc,cAAc,eAAe,EAAE;AAAA;AAAA,IAEvD,SAAS,MAAM,KAAK,cAAc,KAAK,EAAE,YAAmC,CAAC;AAAA,IAC7E,UAAU,SAAS,WAAW,SAAS,CAAC,C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iCACX;AAMK,SAAS,uBAA4C;AAC1D,QAAM,OAAO,eAAe;AAE5B,QAAM,EAAE,MAAM,WAAW,IAAI,cAAc,EAAE,SAAS,KAAK,UAAU,CAAC;AACtE,QAAM,aAAa,YAAY,IAAI,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,GAAG;AACjE,QAAM,EAAE,QAAQ,IAAI;AACpB,QAAM,OAAO,OAA2B,MAAS;AACjD,YAAU,MAAM;AACd,QAAI,eAAe,UAAa,eAAe,KAAK,QAAS;AAC7D,UAAM,QAAQ,KAAK,YAAY;AAC/B,SAAK,UAAU;AACf,QAAI,CAAC,MAAO,MAAK,QAAQ;AAAA,EAC3B,GAAG,CAAC,YAAY,OAAO,CAAC;AACxB,SAAO,KAAK,MAAM;AACpB;AAOO,SAAS,kBAAkB,SAAiC;AACjE,QAAM,OAAO,QAAQ;AACrB,SAAO,SAAS;AAAA,IACd,UAAUA,eAAc,eAAe;AAAA,IACvC,SAAS,MAAM,KAAK,KAAK,WAAW;AAAA,IACpC,UAAU,SAAS,WAAW,SAAS,KAAK;AAAA,IAC5C,sBAAsB;AAAA,IACtB,gBAAgB;AAAA,IAChB,WAAW;AAAA,EACb,CAAC;AACH;",
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;AAKvB,SAAS,cAAc,SAAiC;AAC7D,QAAM,OAAO,QAAQ;AACrB,SAAO,SAAS;AAAA,IACd,UAAUA,eAAc,WAAW;AAAA,IACnC,SAAS,MAAM,KAAK,WAAW,KAAK;AAAA,IACpC,UAAU,SAAS,WAAW,SAAS,KAAK;AAAA,EAC9C,CAAC;AACH;AAGO,SAAS,uBACd,OACA,SACA;AACA,QAAM,OAAO,QAAQ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