@arbidocs/react 0.5.158 → 0.5.160

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.
@@ -5,12 +5,24 @@ function isConversationListKey(queryKey) {
5
5
  const LISTS = {
6
6
  predicate: (query) => isConversationListKey(query.queryKey)
7
7
  };
8
+ function writeList(queryClient, key, next) {
9
+ const staleRead = queryClient.getQueryState(key)?.fetchStatus === "fetching";
10
+ queryClient.setQueryData(key, next);
11
+ if (staleRead) void queryClient.refetchQueries({ queryKey: key, exact: true });
12
+ }
13
+ function patchLists(queryClient, reducer) {
14
+ for (const [key, old] of queryClient.getQueriesData(LISTS)) {
15
+ if (!old) continue;
16
+ const next = reducer(old);
17
+ if (next !== old) writeList(queryClient, key, next);
18
+ }
19
+ }
8
20
  function patchConversationList(queryClient, workspaceId, reducer) {
9
21
  if (!workspaceId) return;
10
22
  const key = arbiQueryKeys.conversations(workspaceId);
11
23
  const current = queryClient.getQueryData(key) ?? [];
12
24
  const next = reducer(current);
13
- if (next !== current) queryClient.setQueryData(key, next);
25
+ if (next !== current) writeList(queryClient, key, next);
14
26
  }
15
27
  function addConversationToList(queryClient, workspaceId, conversation) {
16
28
  patchConversationList(queryClient, workspaceId, (old) => [
@@ -19,17 +31,17 @@ function addConversationToList(queryClient, workspaceId, conversation) {
19
31
  ]);
20
32
  }
21
33
  function patchConversation(queryClient, conversationId, update) {
22
- queryClient.setQueriesData(LISTS, (old) => {
23
- if (!old?.some((c) => c.external_id === conversationId)) return old;
34
+ patchLists(queryClient, (old) => {
35
+ if (!old.some((c) => c.external_id === conversationId)) return old;
24
36
  return old.map(
25
37
  (c) => c.external_id === conversationId ? typeof update === "function" ? update(c) : { ...c, ...update } : c
26
38
  );
27
39
  });
28
40
  }
29
41
  function removeConversationFromLists(queryClient, conversationId) {
30
- queryClient.setQueriesData(
31
- LISTS,
32
- (old) => old?.some((c) => c.external_id === conversationId) ? old.filter((c) => c.external_id !== conversationId) : old
42
+ patchLists(
43
+ queryClient,
44
+ (old) => old.some((c) => c.external_id === conversationId) ? old.filter((c) => c.external_id !== conversationId) : old
33
45
  );
34
46
  }
35
47
  function invalidateConversationLists(queryClient) {
@@ -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;AACj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Y,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/**\n * Write one cached list. A read of it already on its way left before this write: its answer would\n * undo it (a new task gone from the list it was just added to, a task marked done shown to do\n * again). It is cancelled and the list read again, now that the server has the write.\n */\nfunction writeList(queryClient: QueryClient, key: QueryKey, next: ConversationResponse[]): void {\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(\n queryClient: QueryClient,\n reducer: (old: ConversationResponse[]) => ConversationResponse[]\n): 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, 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: (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) writeList(queryClient, 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 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;AAOA,SAAS,UAAU,aAA0B,KAAe,MAAoC;AAC9F,QAAM,YAAY,YAAY,cAAc,GAAG,GAAG,gBAAgB;AAClE,cAAY,aAAa,KAAK,IAAI;AAClC,MAAI,UAAW,MAAK,YAAY,eAAe,EAAE,UAAU,KAAK,OAAO,KAAK,CAAC;AAC/E;AAGA,SAAS,WACP,aACA,SACM;AACN,aAAW,CAAC,KAAK,GAAG,KAAK,YAAY,eAAuC,KAAK,GAAG;AAClF,QAAI,CAAC,IAAK;AACV,UAAM,OAAO,QAAQ,GAAG;AACxB,QAAI,SAAS,IAAK,WAAU,aAAa,KAAK,IAAI;AAAA,EACpD;AAC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