@arbidocs/react 0.5.95 → 0.5.97

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/index.cjs CHANGED
@@ -5378,6 +5378,46 @@ function useAttachRun(conversationId, responseId) {
5378
5378
  };
5379
5379
  }, [conversationId, responseId, queryClient, session]);
5380
5380
  }
5381
+ function workflowRunTitle(workflowName, createdAt) {
5382
+ const day2 = new Date(createdAt).toLocaleDateString(void 0, { day: "numeric", month: "short" });
5383
+ return `${workflowName} \u2014 ${day2}`;
5384
+ }
5385
+ function useWorkflowRunTitles(conversations, openId, workspaceId) {
5386
+ const hasUntitledRun = conversations.some((c) => !c.title && c.workflow_ext_id && c.created_at);
5387
+ const { data: workflows } = useWorkflows({ enabled: hasUntitledRun });
5388
+ const titles = React.useMemo(() => {
5389
+ const names = new Map((workflows ?? []).map((w) => [w.external_id, w.name]));
5390
+ const out = {};
5391
+ for (const c of conversations) {
5392
+ const name = !c.title && c.workflow_ext_id ? names.get(c.workflow_ext_id) : void 0;
5393
+ if (name && c.created_at) out[c.external_id] = workflowRunTitle(name, c.created_at);
5394
+ }
5395
+ return out;
5396
+ }, [workflows, conversations]);
5397
+ const arbi = chunkBRFRQWAY_cjs.useArbi();
5398
+ const queryClient = reactQuery.useQueryClient();
5399
+ const canEditShared = useCanEditShared();
5400
+ const { mutateAsync: rename } = useUpdateConversation();
5401
+ const titled = React.useRef(/* @__PURE__ */ new Set());
5402
+ const open = openId ? conversations.find((c) => c.external_id === openId) : void 0;
5403
+ const openTitle = openId ? titles[openId] : void 0;
5404
+ const mayEdit = !!open && (open.is_owner === true || open.is_shared === true && canEditShared);
5405
+ React.useEffect(() => {
5406
+ if (!openId || !openTitle || !mayEdit || !workspaceId || titled.current.has(openId)) return;
5407
+ titled.current.add(openId);
5408
+ void (async () => {
5409
+ const fresh = await queryClient.fetchQuery({
5410
+ queryKey: chunkBRFRQWAY_cjs.arbiQueryKeys.conversations(workspaceId),
5411
+ queryFn: () => arbi.conversations.list({ workspaceId }),
5412
+ staleTime: 0
5413
+ });
5414
+ if (fresh.find((c) => c.external_id === openId)?.title) return;
5415
+ await rename({ conversationId: openId, patch: { title: openTitle } });
5416
+ })().catch(() => {
5417
+ });
5418
+ }, [openId, openTitle, mayEdit, workspaceId, arbi, queryClient, rename]);
5419
+ return titles;
5420
+ }
5381
5421
 
5382
5422
  // src/chat/useConversation.ts
5383
5423
  function workflowStepOf(tools) {
@@ -5395,6 +5435,7 @@ function titleFromQuestion(question, maxLength = 48) {
5395
5435
  var FAILED_MESSAGE = "The assistant request failed.";
5396
5436
  var UNFINISHED_MESSAGE = "The answer did not finish. Try again.";
5397
5437
  var NEW = "new";
5438
+ var NO_ROWS = [];
5398
5439
  var messageOf = (e, fallback) => e instanceof Error ? e.message : fallback;
5399
5440
  function signedInUserId2(arbi) {
5400
5441
  try {
@@ -5476,6 +5517,11 @@ function useConversation(options = {}) {
5476
5517
  [agentId, agentHistory.data, ordinaryHistory.data, workspaceId]
5477
5518
  );
5478
5519
  const isLoadingThreads = agentId ? agentHistory.isLoading : ordinaryHistory.isLoading;
5520
+ const runTitles = useWorkflowRunTitles(
5521
+ agentId ? NO_ROWS : ordinaryHistory.data ?? NO_ROWS,
5522
+ conversationId,
5523
+ workspaceId
5524
+ );
5479
5525
  const data = useConversationData();
5480
5526
  const {
5481
5527
  messageHistory,
@@ -5535,14 +5581,14 @@ function useConversation(options = {}) {
5535
5581
  const localTitle = firstQuestion ? titleFromQuestion(firstQuestion, titleLength) : "";
5536
5582
  const persisted = [...stored].filter((c) => c.status != null || c.message_count > 0 || c.external_id === conversationId).sort((a, b) => b.updated_at.localeCompare(a.updated_at)).map((c) => ({
5537
5583
  id: c.external_id,
5538
- title: c.title || (c.external_id === conversationId ? localTitle : "")
5584
+ title: c.title || runTitles[c.external_id] || (c.external_id === conversationId ? localTitle : "")
5539
5585
  }));
5540
5586
  const isListed = persisted.some((t) => t.id === conversationId);
5541
5587
  return [
5542
5588
  ...conversationId === null ? [{ id: NEW, title: localTitle }] : isListed ? [] : [{ id: conversationId, title: localTitle }],
5543
5589
  ...persisted
5544
5590
  ];
5545
- }, [stored, conversationId, messages, titleLength]);
5591
+ }, [stored, conversationId, messages, titleLength, runTitles]);
5546
5592
  const selectedIds = React.useMemo(
5547
5593
  () => (agentId ? [] : docs).map((d) => d.external_id).filter((id) => !!id && !deselected.has(id)),
5548
5594
  [docs, deselected, agentId]
@@ -19326,6 +19372,7 @@ exports.waitForResponseId = waitForResponseId;
19326
19372
  exports.wipeCalendarOffline = wipeCalendarOffline;
19327
19373
  exports.wipeOfflineDocuments = wipeOfflineDocuments;
19328
19374
  exports.withRelativePath = withRelativePath;
19375
+ exports.workflowRunTitle = workflowRunTitle;
19329
19376
  exports.workflowStepOf = workflowStepOf;
19330
19377
  exports.workspaceHouseTemplateId = workspaceHouseTemplateId;
19331
19378
  //# sourceMappingURL=index.cjs.map