@arbidocs/react 0.5.158 → 0.5.159

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.
@@ -10,7 +10,10 @@ function patchConversationList(queryClient, workspaceId, reducer) {
10
10
  const key = arbiQueryKeys.conversations(workspaceId);
11
11
  const current = queryClient.getQueryData(key) ?? [];
12
12
  const next = reducer(current);
13
- if (next !== current) queryClient.setQueryData(key, next);
13
+ if (next === current) return;
14
+ const staleRead = queryClient.getQueryState(key)?.fetchStatus === "fetching";
15
+ queryClient.setQueryData(key, next);
16
+ if (staleRead) void queryClient.refetchQueries({ queryKey: key, exact: true });
14
17
  }
15
18
  function addConversationToList(queryClient, workspaceId, conversation) {
16
19
  patchConversationList(queryClient, workspaceId, (old) => [
@@ -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/** 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: (old: ConversationResponse[]) => ConversationResponse[]\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) queryClient.setQueryData(key, 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 queryClient.setQueriesData<ConversationResponse[]>(LISTS, (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 queryClient.setQueriesData<ConversationResponse[]>(LISTS, (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;AAGO,SAAS,sBACd,aACA,aACA,SACM;AACN,MAAI,CAAC,YAAa;AAClB,QAAM,MAAM,cAAc,cAAc,WAAW;AACnD,QAAM,UAAU,YAAY,aAAqC,GAAG,KAAK,CAAC;AAC1E,QAAM,OAAO,QAAQ,OAAO;AAC5B,MAAI,SAAS,QAAS,aAAY,aAAa,KAAK,IAAI;AAC1D;AAGO,SAAS,sBACd,aACA,aACA,cACM;AACN,wBAAsB,aAAa,aAAa,CAAC,QAAQ;AAAA,IACvD;AAAA,IACA,GAAG,IAAI,OAAO,CAAC,MAAM,EAAE,gBAAgB,aAAa,WAAW;AAAA,EACjE,CAAC;AACH;AAGO,SAAS,kBACd,aACA,gBACA,QACM;AACN,cAAY,eAAuC,OAAO,CAAC,QAAQ;AACjE,QAAI,CAAC,KAAK,KAAK,CAAC,MAAM,EAAE,gBAAgB,cAAc,EAAG,QAAO;AAChE,WAAO,IAAI;AAAA,MAAI,CAAC,MACd,EAAE,gBAAgB,iBACd,OAAO,WAAW,aAChB,OAAO,CAAC,IACR,EAAE,GAAG,GAAG,GAAG,OAAO,IACpB;AAAA,IACN;AAAA,EACF,CAAC;AACH;AAGO,SAAS,4BACd,aACA,gBACM;AACN,cAAY;AAAA,IAAuC;AAAA,IAAO,CAAC,QACzD,KAAK,KAAK,CAAC,MAAM,EAAE,gBAAgB,cAAc,IAC7C,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;",
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/** 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: (old: ConversationResponse[]) => ConversationResponse[]\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) return\n // A read of the list already on its way left before this write: its answer would undo it (a new\n // task gone from the list it was just added to). It is cancelled and the list read again, now\n // that the server has the write.\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/** 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 queryClient.setQueriesData<ConversationResponse[]>(LISTS, (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 queryClient.setQueriesData<ConversationResponse[]>(LISTS, (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;AAGO,SAAS,sBACd,aACA,aACA,SACM;AACN,MAAI,CAAC,YAAa;AAClB,QAAM,MAAM,cAAc,cAAc,WAAW;AACnD,QAAM,UAAU,YAAY,aAAqC,GAAG,KAAK,CAAC;AAC1E,QAAM,OAAO,QAAQ,OAAO;AAC5B,MAAI,SAAS,QAAS;AAItB,QAAM,YAAY,YAAY,cAAc,GAAG,GAAG,gBAAgB;AAClE,cAAY,aAAa,KAAK,IAAI;AAClC,MAAI,UAAW,MAAK,YAAY,eAAe,EA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