@arbidocs/react 0.5.161 → 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.
@@ -1003,7 +1003,7 @@ function restoreLayout(current, saved) {
1003
1003
  grid: saved.grid
1004
1004
  };
1005
1005
  }
1006
- function openPanelIn(panels, panelId, mode) {
1006
+ function openPanelIn(panels, panelId, mode, options) {
1007
1007
  const leave = (slot) => slot === panelId ? null : slot;
1008
1008
  const next = {
1009
1009
  ...panels,
@@ -1014,7 +1014,8 @@ function openPanelIn(panels, panelId, mode) {
1014
1014
  modes: { ...panels.modes, [panelId]: mode }
1015
1015
  };
1016
1016
  if (mode === "docked") return { ...next, docked: panelId, overlay: null };
1017
- if (mode === "overlay") return { ...next, overlay: panelId, docked: null };
1017
+ if (mode === "overlay")
1018
+ return { ...next, overlay: panelId, docked: options?.preserveDocked ? next.docked : null };
1018
1019
  return { ...next, [mode]: panelId };
1019
1020
  }
1020
1021
  function closePanelIn(panels, panelId) {
@@ -1120,7 +1121,10 @@ function createArbiLayoutStore({
1120
1121
  if (sidebar.pinned !== current.pinned || sidebar.hovering !== current.hovering || sidebar.drawerOpen !== current.drawerOpen)
1121
1122
  shell({ sidebar });
1122
1123
  },
1123
- openPanel: (panelId, mode) => shell({ panels: openPanelIn(layout.shell.panels, panelId, mode), focusedArea: panelId }),
1124
+ openPanel: (panelId, mode, options) => shell({
1125
+ panels: openPanelIn(layout.shell.panels, panelId, mode, options),
1126
+ focusedArea: panelId
1127
+ }),
1124
1128
  closePanel: (panelId) => shell({ panels: closePanelIn(layout.shell.panels, panelId), focusedArea: "main" }),
1125
1129
  setPanelMode: (panelId, mode) => {
1126
1130
  const panels = layout.shell.panels;
@@ -1870,6 +1874,44 @@ function createBrowserStateStorage(databaseName, storeName) {
1870
1874
  return storage;
1871
1875
  }
1872
1876
 
1877
+ // src/session/conversation-panels.ts
1878
+ function createConversationPanels(source, options) {
1879
+ const getLayout = () => typeof source === "function" ? source() : source;
1880
+ const { conversationPanel, agentGalleryPanel, mainAreaPanels, defaultModes } = options;
1881
+ const showPanel = (panelId, show = true) => {
1882
+ const layout = getLayout();
1883
+ if (!show) {
1884
+ layout.closePanel(panelId);
1885
+ return;
1886
+ }
1887
+ const mode = defaultModes[panelId] ?? "docked";
1888
+ const state = layout.getLayout();
1889
+ const preserveDocked = mode === "overlay" && state.shell.panels.docked === conversationPanel && state.tabs.activeDm?.startsWith("agt-");
1890
+ if (preserveDocked) layout.openPanel(panelId, mode, { preserveDocked: true });
1891
+ else layout.openPanel(panelId, mode);
1892
+ };
1893
+ return {
1894
+ showPanel,
1895
+ closeMainAreaPanels() {
1896
+ const layout = getLayout();
1897
+ const state = layout.getLayout();
1898
+ const { main } = state.shell.panels;
1899
+ if (main === conversationPanel && state.tabs.activeDm?.startsWith("agt-"))
1900
+ layout.openPanel(conversationPanel, "docked");
1901
+ else if (main && mainAreaPanels.includes(main)) showPanel(main, false);
1902
+ },
1903
+ openDmTab(recipientId, messageId) {
1904
+ const layout = getLayout();
1905
+ layout.openDmTab(recipientId ?? null, messageId);
1906
+ if (recipientId?.startsWith("agt-")) {
1907
+ showPanel(agentGalleryPanel, false);
1908
+ layout.openPanel(conversationPanel, "docked");
1909
+ } else if (!isPanelOpen(layout.getLayout(), conversationPanel)) showPanel(conversationPanel);
1910
+ layout.setFocusedArea(conversationPanel);
1911
+ }
1912
+ };
1913
+ }
1914
+
1873
1915
  // src/usage-metered.ts
1874
1916
  function isUsageMetered(usage, subscription) {
1875
1917
  const empty = usage.total_spend === 0 && usage.total_tokens === 0 && usage.total_requests === 0;
@@ -1893,11 +1935,16 @@ function useDocumentVersionList(docId, options) {
1893
1935
  }
1894
1936
  function useConversations(workspaceId, options) {
1895
1937
  const arbi = chunkZZBCZRA5_cjs.useArbi();
1938
+ const queryClient = reactQuery.useQueryClient();
1896
1939
  const live = options?.live === true;
1897
1940
  return reactQuery.useQuery({
1898
1941
  queryKey: chunkZZBCZRA5_cjs.arbiQueryKeys.conversations(workspaceId ?? ""),
1899
1942
  // The request names the workspace, so a switch while it runs cannot answer for another.
1900
- queryFn: () => arbi.conversations.list({ workspaceId }),
1943
+ queryFn: () => readConversationList(
1944
+ queryClient,
1945
+ workspaceId,
1946
+ () => arbi.conversations.list({ workspaceId })
1947
+ ),
1901
1948
  enabled: (options?.enabled ?? true) && !!workspaceId && arbi.hasWorkspace,
1902
1949
  placeholderData: (previous) => previous,
1903
1950
  ...live ? {
@@ -2179,6 +2226,97 @@ function useUserUsageToday(options) {
2179
2226
  });
2180
2227
  }
2181
2228
 
2229
+ // src/conversation-list.ts
2230
+ function isConversationListKey(queryKey) {
2231
+ return queryKey.length === 3 && queryKey[0] === "arbi" && queryKey[1] === "conversations";
2232
+ }
2233
+ var LISTS = {
2234
+ predicate: (query) => isConversationListKey(query.queryKey)
2235
+ };
2236
+ var WRITE_MEMORY_MS = 12e4;
2237
+ var writeLogs = /* @__PURE__ */ new WeakMap();
2238
+ function writeLog(queryClient, key) {
2239
+ let lists = writeLogs.get(queryClient);
2240
+ if (!lists) writeLogs.set(queryClient, lists = /* @__PURE__ */ new Map());
2241
+ const hash = JSON.stringify(key);
2242
+ const now = Date.now();
2243
+ const log = (lists.get(hash) ?? []).filter((w) => now - w.at < WRITE_MEMORY_MS);
2244
+ lists.set(hash, log);
2245
+ return log;
2246
+ }
2247
+ function withLocalWrites(queryClient, workspaceId, rows, requestedAt) {
2248
+ return writeLog(queryClient, chunkZZBCZRA5_cjs.arbiQueryKeys.conversations(workspaceId)).filter((w) => w.at >= requestedAt).reduce((list, w) => w.apply(list), rows);
2249
+ }
2250
+ async function readConversationList(queryClient, workspaceId, read) {
2251
+ const requestedAt = Date.now();
2252
+ return withLocalWrites(queryClient, workspaceId, await read(), requestedAt);
2253
+ }
2254
+ function seedConversationList(queryClient, workspaceId, rows, requestedAt) {
2255
+ queryClient.setQueryData(
2256
+ chunkZZBCZRA5_cjs.arbiQueryKeys.conversations(workspaceId),
2257
+ withLocalWrites(queryClient, workspaceId, rows, requestedAt)
2258
+ );
2259
+ }
2260
+ function writeList(queryClient, key, apply, next) {
2261
+ writeLog(queryClient, key).push({ at: Date.now(), apply });
2262
+ const staleRead = queryClient.getQueryState(key)?.fetchStatus === "fetching";
2263
+ queryClient.setQueryData(key, next);
2264
+ if (staleRead) void queryClient.refetchQueries({ queryKey: key, exact: true });
2265
+ }
2266
+ function patchLists(queryClient, reducer) {
2267
+ for (const [key, old] of queryClient.getQueriesData(LISTS)) {
2268
+ if (!old) continue;
2269
+ const next = reducer(old);
2270
+ if (next !== old) writeList(queryClient, key, reducer, next);
2271
+ }
2272
+ }
2273
+ function patchConversationList(queryClient, workspaceId, reducer) {
2274
+ if (!workspaceId) return;
2275
+ const key = chunkZZBCZRA5_cjs.arbiQueryKeys.conversations(workspaceId);
2276
+ const current = queryClient.getQueryData(key) ?? [];
2277
+ const next = reducer(current);
2278
+ if (next !== current) writeList(queryClient, key, reducer, next);
2279
+ }
2280
+ function addConversationToList(queryClient, workspaceId, conversation) {
2281
+ patchConversationList(queryClient, workspaceId, (old) => [
2282
+ conversation,
2283
+ ...old.filter((c) => c.external_id !== conversation.external_id)
2284
+ ]);
2285
+ }
2286
+ function patchConversation(queryClient, conversationId, update) {
2287
+ patchLists(queryClient, (old) => {
2288
+ if (!old.some((c) => c.external_id === conversationId)) return old;
2289
+ return old.map(
2290
+ (c) => c.external_id === conversationId ? typeof update === "function" ? update(c) : { ...c, ...update } : c
2291
+ );
2292
+ });
2293
+ }
2294
+ function removeConversationFromLists(queryClient, conversationId) {
2295
+ patchLists(
2296
+ queryClient,
2297
+ (old) => old.some((c) => c.external_id === conversationId) ? old.filter((c) => c.external_id !== conversationId) : old
2298
+ );
2299
+ }
2300
+ function invalidateConversationLists(queryClient) {
2301
+ return queryClient.invalidateQueries(LISTS);
2302
+ }
2303
+ function findConversation(queryClient, conversationId) {
2304
+ if (!conversationId) return void 0;
2305
+ for (const [, list] of queryClient.getQueriesData(LISTS)) {
2306
+ const row = list?.find((c) => c.external_id === conversationId);
2307
+ if (row) return row;
2308
+ }
2309
+ return void 0;
2310
+ }
2311
+ function isConversationShared(queryClient, conversationId) {
2312
+ return findConversation(queryClient, conversationId)?.is_shared ?? false;
2313
+ }
2314
+ function invalidateConversationDetails(queryClient, conversationId) {
2315
+ return queryClient.invalidateQueries({
2316
+ predicate: ({ queryKey }) => queryKey[0] === "arbi" && queryKey[1] === "conversations" && queryKey[2] === conversationId && queryKey[3] !== "threads"
2317
+ });
2318
+ }
2319
+
2182
2320
  exports.DEFAULT_DOCUMENT_VIEWER_STATE = DEFAULT_DOCUMENT_VIEWER_STATE;
2183
2321
  exports.DOCUMENT_VIEWER_PANEL = DOCUMENT_VIEWER_PANEL;
2184
2322
  exports.EMPTY_CHAT_STATE = EMPTY_CHAT_STATE;
@@ -2189,6 +2327,7 @@ exports.MIN_QUEUED_MESSAGE_VISIBILITY_MS = MIN_QUEUED_MESSAGE_VISIBILITY_MS;
2189
2327
  exports.PROJECT_CREATION_DENIED_REASON = PROJECT_CREATION_DENIED_REASON;
2190
2328
  exports.WORKSPACE_LAST_OPENED_KEY = WORKSPACE_LAST_OPENED_KEY;
2191
2329
  exports.WORKSPACE_STORAGE_KEY = WORKSPACE_STORAGE_KEY;
2330
+ exports.addConversationToList = addConversationToList;
2192
2331
  exports.agentControl = agentControl;
2193
2332
  exports.browserWorkspaceStorage = browserWorkspaceStorage;
2194
2333
  exports.clearSealedDrafts = clearSealedDrafts;
@@ -2201,13 +2340,19 @@ exports.createArbiLayoutStore = createArbiLayoutStore;
2201
2340
  exports.createArbiSessionStore = createArbiSessionStore;
2202
2341
  exports.createArbiWorkspaceStore = createArbiWorkspaceStore;
2203
2342
  exports.createBrowserStateStorage = createBrowserStateStorage;
2343
+ exports.createConversationPanels = createConversationPanels;
2204
2344
  exports.createDebouncedWriter = createDebouncedWriter;
2205
2345
  exports.createSealedDraftStorage = createSealedDraftStorage;
2206
2346
  exports.createStoragePersist = createStoragePersist;
2207
2347
  exports.createUiStateStorage = createUiStateStorage;
2208
2348
  exports.defaultLayoutState = defaultLayoutState;
2209
2349
  exports.dmTabId = dmTabId;
2350
+ exports.findConversation = findConversation;
2210
2351
  exports.flushOnPageExit = flushOnPageExit;
2352
+ exports.invalidateConversationDetails = invalidateConversationDetails;
2353
+ exports.invalidateConversationLists = invalidateConversationLists;
2354
+ exports.isConversationListKey = isConversationListKey;
2355
+ exports.isConversationShared = isConversationShared;
2211
2356
  exports.isPanelOpen = isPanelOpen;
2212
2357
  exports.isUsageMetered = isUsageMetered;
2213
2358
  exports.layoutActionsOf = layoutActionsOf;
@@ -2217,13 +2362,18 @@ exports.panelPlace = panelPlace;
2217
2362
  exports.parseSavedChat = parseSavedChat;
2218
2363
  exports.parseSavedDocuments = parseSavedDocuments;
2219
2364
  exports.parseSavedLayout = parseSavedLayout;
2365
+ exports.patchConversation = patchConversation;
2366
+ exports.patchConversationList = patchConversationList;
2220
2367
  exports.queuedMessages = queuedMessages;
2368
+ exports.readConversationList = readConversationList;
2221
2369
  exports.readWorkspaceLastOpened = readWorkspaceLastOpened;
2370
+ exports.removeConversationFromLists = removeConversationFromLists;
2222
2371
  exports.restoreLayout = restoreLayout;
2223
2372
  exports.restoreSavedDocuments = restoreSavedDocuments;
2224
2373
  exports.savedChatOf = savedChatOf;
2225
2374
  exports.savedDocumentsOf = savedDocumentsOf;
2226
2375
  exports.savedLayoutOf = savedLayoutOf;
2376
+ exports.seedConversationList = seedConversationList;
2227
2377
  exports.selectDraft = selectDraft;
2228
2378
  exports.selectIsGenerating = selectIsGenerating;
2229
2379
  exports.selectViewingDocumentId = selectViewingDocumentId;
@@ -2262,5 +2412,6 @@ exports.useTransientView = useTransientView;
2262
2412
  exports.useUserUsageToday = useUserUsageToday;
2263
2413
  exports.useWorkspaceActivity = useWorkspaceActivity;
2264
2414
  exports.useWorkspaces = useWorkspaces;
2265
- //# sourceMappingURL=chunk-2MGJXBBJ.cjs.map
2266
- //# sourceMappingURL=chunk-2MGJXBBJ.cjs.map
2415
+ exports.withLocalWrites = withLocalWrites;
2416
+ //# sourceMappingURL=chunk-SUMXDNYG.cjs.map
2417
+ //# sourceMappingURL=chunk-SUMXDNYG.cjs.map