@openchambery/web 1.19.17-beta.2 → 1.19.17-beta.3

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.
Files changed (128) hide show
  1. package/dist/assets/AgentAvatar-CUDJ3_nZ.js +1 -0
  2. package/dist/assets/AssistantView-CDXE0eTS.js +3 -0
  3. package/dist/assets/DiagramView-BrRV4o5T.js +1 -0
  4. package/dist/assets/FadeInOnReveal-BLSnyG2Z.js +1 -0
  5. package/dist/assets/Icon-C9ZHbwqp.js +1 -0
  6. package/dist/assets/MarkdownRenderer-CAdfUgV1.js +2 -0
  7. package/dist/assets/{MarkdownRendererImpl-BJd1Vjsc.js → MarkdownRendererImpl-D2dIlX0h.js} +2 -2
  8. package/dist/assets/MarkstreamRendererImpl-Drb2Tpv-.js +3 -0
  9. package/dist/assets/MobileDetailNavigation-BgCoDqtp.js +1 -0
  10. package/dist/assets/MobileShareBridge-ZlVURYWR.js +4 -0
  11. package/dist/assets/MobileSurface-DhLOTW0-.js +2 -0
  12. package/dist/assets/MultiRunWindow-BCvcwItK.js +1 -0
  13. package/dist/assets/OnboardingScreen-DSyZtiFS.js +1 -0
  14. package/dist/assets/OverlayScrollbar-C7fAOAKT.js +2 -0
  15. package/dist/assets/SettingsView-D57amZJb.js +25 -0
  16. package/dist/assets/SettingsWindow-B5DqLCkD.js +1 -0
  17. package/dist/assets/TerminalView-2_RFPaVs.js +8 -0
  18. package/dist/assets/{ToolOutputDialog-BQ_oXyS_.js → ToolOutputDialog-CQs_7KYT.js} +4 -4
  19. package/dist/assets/{appThemeRegistry-BDrIDWKH.js → appThemeRegistry-DpLe_jnW.js} +1 -1
  20. package/dist/assets/button-bhVnVYB_.js +1 -0
  21. package/dist/assets/collapsible-CoWJB_Zl.js +1 -0
  22. package/dist/assets/context-menu-gSO0b3sQ.js +1 -0
  23. package/dist/assets/diagram-Dx4UOZUn.js +1 -0
  24. package/dist/assets/dialog-C2Dw0yqA.js +1 -0
  25. package/dist/assets/{es-BQb6I8gl.js → es-Bxd4Lyu9.js} +2 -2
  26. package/dist/assets/{fileMentionTouchSelection-DzdgAvGS.js → fileMentionTouchSelection-CmQthb6Q.js} +2 -2
  27. package/dist/assets/{fr-BjGouC_l.js → fr-DiLDwVZs.js} +2 -2
  28. package/dist/assets/{gitApi-pLkl_IyQ.js → gitApi-8HxdR1zx.js} +3 -3
  29. package/dist/assets/input-8Te_vPwB.js +1 -0
  30. package/dist/assets/insertionBoundaries-Cdv9-1Bg.js +1 -0
  31. package/dist/assets/{ja-Cw9zliYY.js → ja-CWRlmEJM.js} +2 -2
  32. package/dist/assets/{ko-Dyz0Dk9b.js → ko-DmIugkgj.js} +2 -2
  33. package/dist/assets/main-CQY7JUX4.js +169 -0
  34. package/dist/assets/main-Cfru2-qr.js +2 -0
  35. package/dist/assets/{markdownHeightCache-BL8CUQ0M.js → markdownHeightCache-CT2d4yTV.js} +1 -1
  36. package/dist/assets/miniChat-BphFgAb_.js +2 -0
  37. package/dist/assets/mobile-BVRPTuLT.js +2 -0
  38. package/dist/assets/multirun-CYdieVzW.js +4 -0
  39. package/dist/assets/{pl-C7EY-dTH.js → pl-BU9AmdUM.js} +2 -2
  40. package/dist/assets/projectMeta-D8hiy3Dk.js +3 -0
  41. package/dist/assets/{pt-BR-B1uHpjFW.js → pt-BR-DQmEF9QB.js} +2 -2
  42. package/dist/assets/renderElectronMiniChatApp-CVqd3Nmc.js +2 -0
  43. package/dist/assets/renderMobileApp-DgtCGRKP.js +28 -0
  44. package/dist/assets/{runtimeConfig-BD1Fo5N5.js → runtimeConfig-DXXOBrK_.js} +1 -1
  45. package/dist/assets/runtimeEndpointReset-bSVOt7pi.js +147 -0
  46. package/dist/assets/sessionChangeSummary-CfnRZ0gS.js +2 -0
  47. package/dist/assets/sessionLookup-BZuujM6l.js +1 -0
  48. package/dist/assets/sortable-tabs-strip-BmvLnn6O.js +1 -0
  49. package/dist/assets/src-C_Yn9Ylz.css +2 -0
  50. package/dist/assets/{store-ClnJdJSj.js → store-BoixGrYS.js} +3 -3
  51. package/dist/assets/textarea-DRL916s6.js +1 -0
  52. package/dist/assets/tooltip-BLznq5KR.js +1 -0
  53. package/dist/assets/{uk-DgG8v2md.js → uk-Dax66sAC.js} +2 -2
  54. package/dist/assets/{useAppFontEffects-CN_3Jty7.js → useAppFontEffects-DhEfjuPp.js} +43 -43
  55. package/dist/assets/useDesktopWindowControlsLayout-BhNFU2Wd.js +1 -0
  56. package/dist/assets/{useEffectiveDirectory-C5Gg7EvP.js → useEffectiveDirectory-BhhzFJgX.js} +1 -1
  57. package/dist/assets/useMobileNavigationStore-1jdHeA49.js +413 -0
  58. package/dist/assets/useSessionAutoCleanup-C8u2-jrO.js +2 -0
  59. package/dist/assets/{useWorkerHighlightedLines-BSQQkZaO.js → useWorkerHighlightedLines-DFXK66lA.js} +2 -2
  60. package/dist/assets/vendor-zod-Dzk5kdUU.js +39 -0
  61. package/dist/assets/{zh-CN-C6OFKjeT.js → zh-CN-Du4VC8Z0.js} +2 -2
  62. package/dist/assets/{zh-TW-BVP99aMr.js → zh-TW-C0bY-Dso.js} +2 -2
  63. package/dist/index.html +3 -3
  64. package/dist/mini-chat.html +3 -3
  65. package/dist/mobile.html +3 -3
  66. package/package.json +1 -1
  67. package/server/index.js +51 -0
  68. package/server/lib/opencode/DOCUMENTATION.md +1 -0
  69. package/server/lib/opencode/core-routes.js +2 -0
  70. package/server/lib/opencode/feature-routes-runtime.js +20 -0
  71. package/server/lib/opencode/feature-routes-runtime.test.js +10 -0
  72. package/server/lib/opencode/routes.js +14 -1
  73. package/server/lib/opencode/settings-helpers.js +3 -0
  74. package/server/lib/opencode/settings-helpers.test.js +12 -0
  75. package/server/lib/opencode/shutdown-runtime.js +2 -0
  76. package/server/lib/question-auto-delegate/DOCUMENTATION.md +124 -0
  77. package/server/lib/question-auto-delegate/core.d.ts +255 -0
  78. package/server/lib/question-auto-delegate/core.js +1372 -0
  79. package/server/lib/question-auto-delegate/core.test.js +672 -0
  80. package/server/lib/question-auto-delegate/routes.js +223 -0
  81. package/server/lib/question-auto-delegate/routes.test.js +180 -0
  82. package/server/lib/question-auto-delegate/runtime.js +243 -0
  83. package/server/lib/session-goal/DOCUMENTATION.md +12 -2
  84. package/server/lib/session-goal/runtime.js +138 -35
  85. package/server/lib/session-goal/runtime.test.js +192 -0
  86. package/dist/assets/AgentAvatar-m1jNq4bX.js +0 -1
  87. package/dist/assets/AssistantView-DZMTfY1i.js +0 -3
  88. package/dist/assets/DiagramView-Byf2evGV.js +0 -1
  89. package/dist/assets/FadeInOnReveal-UGwClbL_.js +0 -1
  90. package/dist/assets/Icon-D1BcR8Tz.js +0 -1
  91. package/dist/assets/MarkdownRenderer-YMePGw0Z.js +0 -2
  92. package/dist/assets/MarkstreamRendererImpl-2oZKPfgd.js +0 -3
  93. package/dist/assets/MobileDetailNavigation-BeNUCxzK.js +0 -1
  94. package/dist/assets/MobileShareBridge-3tBtXXJJ.js +0 -4
  95. package/dist/assets/MobileSurface-ppn0zIpb.js +0 -2
  96. package/dist/assets/MultiRunWindow-CItY5bZ2.js +0 -1
  97. package/dist/assets/OnboardingScreen-bIWeMLVx.js +0 -1
  98. package/dist/assets/OverlayScrollbar-Bahg_P3r.js +0 -2
  99. package/dist/assets/SettingsView-0-Yqdzh-.js +0 -25
  100. package/dist/assets/SettingsWindow-1jOWzU2A.js +0 -1
  101. package/dist/assets/TerminalView-BLOCPFz9.js +0 -8
  102. package/dist/assets/button-9R-WgVMl.js +0 -1
  103. package/dist/assets/clipboard-GUUNlWIv.js +0 -1
  104. package/dist/assets/collapsible-Bbz9KiJf.js +0 -1
  105. package/dist/assets/context-menu-CSyOhRz8.js +0 -1
  106. package/dist/assets/diagram-NdsZih8P.js +0 -1
  107. package/dist/assets/dialog-DhMGbF_B.js +0 -1
  108. package/dist/assets/input-Cd_1HyQv.js +0 -1
  109. package/dist/assets/insertionBoundaries-DJvMDCJJ.js +0 -1
  110. package/dist/assets/main-B8fZfA3K.js +0 -169
  111. package/dist/assets/main-BGpPyUV2.js +0 -2
  112. package/dist/assets/miniChat-DHjphqgR.js +0 -2
  113. package/dist/assets/mobile-DNMX4u7x.js +0 -2
  114. package/dist/assets/multirun-BINJ2LCE.js +0 -4
  115. package/dist/assets/projectMeta-BMkGWqtz.js +0 -3
  116. package/dist/assets/renderElectronMiniChatApp-BonR3p7C.js +0 -2
  117. package/dist/assets/renderMobileApp-CZqNs2zK.js +0 -28
  118. package/dist/assets/runtimeEndpointReset-Dpx6GB_U.js +0 -147
  119. package/dist/assets/sessionChangeSummary-BG7l2heP.js +0 -2
  120. package/dist/assets/sessionLookup-BZuvc3Aa.js +0 -1
  121. package/dist/assets/sortable-tabs-strip-dYW6SH62.js +0 -1
  122. package/dist/assets/src-CO9q_82J.css +0 -2
  123. package/dist/assets/textarea-B9CmN13Z.js +0 -1
  124. package/dist/assets/tooltip-DSjr26A_.js +0 -1
  125. package/dist/assets/useDesktopWindowControlsLayout-C6kAkizT.js +0 -1
  126. package/dist/assets/useMobileNavigationStore-DDgESrzu.js +0 -413
  127. package/dist/assets/useSessionAutoCleanup-q2lauc7x.js +0 -2
  128. package/dist/assets/utils-2ZK8yboQ.js +0 -1
@@ -306,6 +306,19 @@ export const createSessionGoalRuntime = ({
306
306
  idleQuietMs = IDLE_QUIET_MS,
307
307
  kickoffQuietMs = KICKOFF_QUIET_MS,
308
308
  maxAutoTurns = MAX_AUTO_TURNS,
309
+ /**
310
+ * When true, question.asked only clears the idle timer (blocks continuation)
311
+ * without writing goal status=paused — used while question auto-delegate will answer.
312
+ * User takeover / disable still call pauseForQuestion explicitly.
313
+ */
314
+ shouldKeepGoalActiveForQuestion,
315
+ /** When true at tick time, skip continuation (pending auto-delegated question). */
316
+ isQuestionBlockingGoal,
317
+ /**
318
+ * Reverse path: when a goal is paused/aborted, pause related question auto-delegate
319
+ * timers for the session tree (root + descendants).
320
+ */
321
+ onGoalPaused,
309
322
  }) => {
310
323
  const timers = new Map();
311
324
  const inflight = new Set();
@@ -509,6 +522,12 @@ export const createSessionGoalRuntime = ({
509
522
  const tick = async (sessionId, directory) => {
510
523
  if (!isSessionGoalEnabled()) return;
511
524
 
525
+ // Pending auto-delegated questions (this session or known descendants) must
526
+ // block continuation without permanently pausing the goal.
527
+ if (typeof isQuestionBlockingGoal === 'function' && isQuestionBlockingGoal(sessionId) === true) {
528
+ return;
529
+ }
530
+
512
531
  const session = await openCodeFetch(`/session/${encodeURIComponent(sessionId)}`, { directory })
513
532
  .catch((error) => {
514
533
  console.warn(`[session-goal] session fetch failed: ${error?.message || error}`);
@@ -726,6 +745,12 @@ export const createSessionGoalRuntime = ({
726
745
  return;
727
746
  }
728
747
 
748
+ // Re-check question blockers immediately before dispatch (uncertain included).
749
+ if (typeof isQuestionBlockingGoal === 'function' && isQuestionBlockingGoal(sessionId) === true) {
750
+ console.log('[session-goal] question still blocking, dropping continuation');
751
+ return;
752
+ }
753
+
729
754
  console.log(`[session-goal] continuing ${sessionId} (turn ${written.turnsUsed}/${maxAutoTurns}, tokens ${written.tokensUsed}${written.tokenBudget ? `/${written.tokenBudget}` : ''})`);
730
755
  await sendContinuation({ sessionId, directory, goal: { ...written, objective: effectiveObjective }, lastAssistantInfo: executionInfo ?? lastAssistantInfo });
731
756
  };
@@ -748,42 +773,100 @@ export const createSessionGoalRuntime = ({
748
773
  timers.set(sessionId, { timer, armedAt: Date.now() });
749
774
  };
750
775
 
776
+ /** Walk parentID chain to the root owner session (multi-level subagent/grandchild). */
777
+ const resolveGoalOwner = async (sessionId, directory) => {
778
+ const seen = new Set();
779
+ let currentId = sessionId;
780
+ let currentDirectory = directory;
781
+ let current = null;
782
+ while (currentId && !seen.has(currentId)) {
783
+ seen.add(currentId);
784
+ current = await openCodeFetch(`/session/${encodeURIComponent(currentId)}`, { directory: currentDirectory })
785
+ .catch(() => null);
786
+ if (!current || typeof current !== 'object') {
787
+ return { sessionId: currentId, directory: currentDirectory, session: null };
788
+ }
789
+ const parentId = typeof current.parentID === 'string' ? current.parentID.trim() : '';
790
+ if (!parentId) {
791
+ return {
792
+ sessionId: currentId,
793
+ directory: typeof current.directory === 'string' && current.directory
794
+ ? current.directory
795
+ : currentDirectory,
796
+ session: current,
797
+ };
798
+ }
799
+ clearTimer(parentId);
800
+ currentDirectory = typeof current.directory === 'string' && current.directory
801
+ ? current.directory
802
+ : currentDirectory;
803
+ currentId = parentId;
804
+ }
805
+ return { sessionId: currentId || sessionId, directory: currentDirectory, session: current };
806
+ };
807
+
808
+ const notifyGoalPaused = (sessionId, directory) => {
809
+ if (typeof onGoalPaused !== 'function') return;
810
+ try {
811
+ const result = onGoalPaused(sessionId, directory);
812
+ if (result && typeof result.then === 'function') {
813
+ result.catch((error) => {
814
+ console.warn('[session-goal] onGoalPaused failed:', error?.message || error);
815
+ });
816
+ }
817
+ } catch (error) {
818
+ console.warn('[session-goal] onGoalPaused failed:', error?.message || error);
819
+ }
820
+ };
821
+
822
+ /** Question-driven pauses must keep auto-delegate timers; user/abort pauses cancel them. */
823
+ const isQuestionDrivenPause = (goal) => (
824
+ typeof goal?.statusReason === 'string'
825
+ && goal.statusReason === 'paused for question'
826
+ );
827
+
751
828
  // Immediate event path for a user abort: pause the active goal right away,
752
829
  // BEFORE any idle tick could send a continuation over the user's explicit
753
830
  // "stop". Messages the user sends afterwards leave the paused goal alone;
754
831
  // Resume re-arms the loop (and kicks off immediately on an idle session).
832
+ //
833
+ // UI races: metadata may land as paused before the abort event. When the goal
834
+ // is already paused for a non-question reason, still notify so question
835
+ // auto-delegate timers are cancelled (abort path used to no-op on non-active).
755
836
  const pauseAfterAbort = async (sessionId, directory) => {
756
- const session = await openCodeFetch(`/session/${encodeURIComponent(sessionId)}`, { directory })
757
- .catch(() => null);
758
- const goal = parseGoalMetadata(session);
759
- if (!goal || goal.status !== 'active') return;
760
- await writeGoal(sessionId, directory, goal.id, () => ({
837
+ const owner = await resolveGoalOwner(sessionId, directory);
838
+ const goal = parseGoalMetadata(owner.session);
839
+ if (!goal) return;
840
+ if (goal.status === 'paused') {
841
+ if (!isQuestionDrivenPause(goal)) {
842
+ notifyGoalPaused(owner.sessionId, owner.directory);
843
+ }
844
+ return;
845
+ }
846
+ if (goal.status !== 'active') return;
847
+ await writeGoal(owner.sessionId, owner.directory, goal.id, () => ({
761
848
  status: 'paused',
762
849
  statusReason: 'paused after abort',
763
850
  }));
764
- console.log(`[session-goal] ${sessionId} paused after user abort`);
851
+ console.log(`[session-goal] ${owner.sessionId} paused after user abort`);
852
+ notifyGoalPaused(owner.sessionId, owner.directory);
765
853
  };
766
854
 
767
855
  // Pause the active goal when the agent asks a question — without aborting
768
856
  // the current turn. Aborting would kill the pending question. A question
769
- // from a child/sub-agent session pauses the parent session's goal.
857
+ // from a child/sub-agent (any depth) pauses the root owner session's goal.
770
858
  const pauseForQuestion = async (sessionId, directory) => {
771
- const session = await openCodeFetch(`/session/${encodeURIComponent(sessionId)}`, { directory })
772
- .catch(() => null);
773
- if (!session || typeof session !== 'object') return;
774
- const parentId = typeof session.parentID === 'string' ? session.parentID.trim() : '';
775
- const targetId = parentId || sessionId;
776
- if (parentId) clearTimer(parentId);
777
- const target = parentId
778
- ? await openCodeFetch(`/session/${encodeURIComponent(targetId)}`, { directory }).catch(() => null)
779
- : session;
780
- const goal = parseGoalMetadata(target);
859
+ const owner = await resolveGoalOwner(sessionId, directory);
860
+ if (!owner.session) return;
861
+ clearTimer(owner.sessionId);
862
+ const goal = parseGoalMetadata(owner.session);
781
863
  if (!goal || goal.status !== 'active') return;
782
- await writeGoal(targetId, directory, goal.id, () => ({
864
+ await writeGoal(owner.sessionId, owner.directory, goal.id, () => ({
783
865
  status: 'paused',
784
866
  statusReason: 'paused for question',
785
867
  }));
786
- console.log(`[session-goal] ${targetId} paused for question`);
868
+ console.log(`[session-goal] ${owner.sessionId} paused for question`);
869
+ // Takeover path already pauses questions; still notify for abort-style symmetry.
787
870
  };
788
871
 
789
872
  const processPayload = (payload, directoryHint = '') => {
@@ -808,6 +891,11 @@ export const createSessionGoalRuntime = ({
808
891
  const asked = extractQuestionAsked(payload, directoryHint);
809
892
  if (asked) {
810
893
  clearTimer(asked.sessionId);
894
+ // Auto-delegate keeps the goal active (status stays active) so a successful
895
+ // auto-reply can continue on the next idle. User takeover/disable still pause.
896
+ const keepActive = typeof shouldKeepGoalActiveForQuestion === 'function'
897
+ && shouldKeepGoalActiveForQuestion(asked.sessionId, asked.directory || directoryHint) === true;
898
+ if (keepActive) return;
811
899
  if (!inflight.has(asked.sessionId)) {
812
900
  inflight.add(asked.sessionId);
813
901
  pauseForQuestion(asked.sessionId, asked.directory || directoryHint)
@@ -831,22 +919,32 @@ export const createSessionGoalRuntime = ({
831
919
  return;
832
920
  }
833
921
 
834
- // Kickoff path: a goal set (or resumed the UI stamps statusReason
835
- // 'resumed') while the session is already idle emits no status
836
- // transition, only session.updated. Arm a short timer; the tick's
837
- // quiescence check keeps this safe if the session is actually busy.
922
+ // session.updated carries goal create/resume/pause without a status event.
838
923
  const update = extractSessionUpdate(payload);
839
- if (
840
- update
841
- && !update.parentID
842
- && update.goal
843
- && update.goal.status === 'active'
844
- && (update.goal.turnsUsed === 0 || update.goal.statusReason === 'resumed')
845
- && !timers.has(update.sessionId)
846
- && !inflight.has(update.sessionId)
847
- ) {
848
- const quiet = update.goal.statusReason === 'resumed' ? RESUME_KICKOFF_MS : kickoffQuietMs;
849
- armTimer(update.sessionId, update.directory || directoryHint, quiet);
924
+ if (update && !update.parentID && update.goal) {
925
+ // Explicit UI/user pause (not question-driven): cancel goal timer and
926
+ // reverse-pause related question auto-delegate timers. Question pauses
927
+ // keep auto-delegate counting so the agent can continue after auto-reply.
928
+ if (update.goal.status === 'paused') {
929
+ clearTimer(update.sessionId);
930
+ if (!isQuestionDrivenPause(update.goal)) {
931
+ notifyGoalPaused(update.sessionId, update.directory || directoryHint);
932
+ }
933
+ return;
934
+ }
935
+
936
+ // Kickoff path: a goal set (or resumed — the UI stamps statusReason
937
+ // 'resumed') while the session is already idle. Arm a short timer; the
938
+ // tick's quiescence check keeps this safe if the session is actually busy.
939
+ if (
940
+ update.goal.status === 'active'
941
+ && (update.goal.turnsUsed === 0 || update.goal.statusReason === 'resumed')
942
+ && !timers.has(update.sessionId)
943
+ && !inflight.has(update.sessionId)
944
+ ) {
945
+ const quiet = update.goal.statusReason === 'resumed' ? RESUME_KICKOFF_MS : kickoffQuietMs;
946
+ armTimer(update.sessionId, update.directory || directoryHint, quiet);
947
+ }
850
948
  }
851
949
  };
852
950
 
@@ -858,5 +956,10 @@ export const createSessionGoalRuntime = ({
858
956
  timers.clear();
859
957
  };
860
958
 
861
- return { processPayload, stop };
959
+ return {
960
+ processPayload,
961
+ stop,
962
+ /** Used by question auto-delegate user takeover / disable paths. */
963
+ pauseForQuestion: (sessionId, directory) => pauseForQuestion(sessionId, directory),
964
+ };
862
965
  };
@@ -448,4 +448,196 @@ describe('session-goal runtime — pause for question', () => {
448
448
  runtime.stop();
449
449
  });
450
450
  });
451
+
452
+ it('keeps the goal active when question auto-delegate will handle the ask', async () => {
453
+ const patches = [];
454
+ const session = buildSession('active');
455
+ const fetchImpl = async (input, init = {}) => {
456
+ const path = String(input).split('?')[0];
457
+ if (path.endsWith('/session/ses-goal') && init.method === 'PATCH') {
458
+ patches.push(JSON.parse(init.body || '{}'));
459
+ }
460
+ return new Response(JSON.stringify(session), { status: 200 });
461
+ };
462
+
463
+ await withFetch(fetchImpl, async () => {
464
+ const runtime = createSessionGoalRuntime({
465
+ buildOpenCodeUrl: (pathname) => `http://opencode${pathname}`,
466
+ getOpenCodeAuthHeaders: () => ({}),
467
+ getSmallModelService: async () => ({
468
+ generateSmallModelText: async () => ({ text: '{"verdict":"continue","note":"in progress"}' }),
469
+ }),
470
+ idleQuietMs: 1_000_000,
471
+ kickoffQuietMs: 1,
472
+ shouldKeepGoalActiveForQuestion: () => true,
473
+ });
474
+ runtime.processPayload(questionAskedPayload(), '/repo');
475
+ await flushQuestionPause();
476
+ expect(patches.length).toBe(0);
477
+ expect(session.metadata.openchamber.goal.status).toBe('active');
478
+ runtime.stop();
479
+ });
480
+ });
481
+
482
+ it('pauses the root owner goal when a grandchild session asks a question', async () => {
483
+ const patches = [];
484
+ const grand = { id: 'ses-grand', parentID: 'ses-child', directory: '/repo/wt' };
485
+ const child = { id: 'ses-child', parentID: 'ses-goal', directory: '/repo/wt' };
486
+ const parent = buildSession('active');
487
+ parent.directory = '/repo';
488
+ const fetchImpl = async (input, init = {}) => {
489
+ const path = String(input).split('?')[0];
490
+ if (path.endsWith('/session/ses-grand')) {
491
+ return new Response(JSON.stringify(grand), { status: 200 });
492
+ }
493
+ if (path.endsWith('/session/ses-child')) {
494
+ return new Response(JSON.stringify(child), { status: 200 });
495
+ }
496
+ if (path.endsWith('/session/ses-goal')) {
497
+ if (init.method === 'PATCH') {
498
+ const body = JSON.parse(init.body || '{}');
499
+ patches.push(body);
500
+ parent.metadata = body.metadata;
501
+ }
502
+ return new Response(JSON.stringify(parent), { status: 200 });
503
+ }
504
+ return new Response(JSON.stringify(parent), { status: 200 });
505
+ };
506
+
507
+ await withFetch(fetchImpl, async () => {
508
+ const runtime = makeRuntime();
509
+ runtime.processPayload(questionAskedPayload('ses-grand'), '/repo/wt');
510
+ await flushQuestionPause();
511
+ expect(patches.length).toBe(1);
512
+ expect(patches[0].metadata.openchamber.goal.status).toBe('paused');
513
+ runtime.stop();
514
+ });
515
+ });
516
+
517
+ it('notifies onGoalPaused after abort so question timers can reverse-pause', async () => {
518
+ const paused = [];
519
+ const session = buildSession('active');
520
+ const fetchImpl = async (input, init = {}) => {
521
+ const path = String(input).split('?')[0];
522
+ if (path.endsWith('/session/ses-goal') && init.method === 'PATCH') {
523
+ const body = JSON.parse(init.body || '{}');
524
+ session.metadata = body.metadata;
525
+ }
526
+ return new Response(JSON.stringify(session), { status: 200 });
527
+ };
528
+
529
+ await withFetch(fetchImpl, async () => {
530
+ const runtime = createSessionGoalRuntime({
531
+ buildOpenCodeUrl: (pathname) => `http://opencode${pathname}`,
532
+ getOpenCodeAuthHeaders: () => ({}),
533
+ getSmallModelService: async () => ({
534
+ generateSmallModelText: async () => ({ text: '{"verdict":"continue","note":"x"}' }),
535
+ }),
536
+ idleQuietMs: 1_000_000,
537
+ kickoffQuietMs: 1,
538
+ onGoalPaused: (sessionId, directory) => {
539
+ paused.push({ sessionId, directory });
540
+ },
541
+ });
542
+ runtime.processPayload({
543
+ type: 'message.updated',
544
+ properties: {
545
+ info: {
546
+ role: 'assistant',
547
+ sessionID: 'ses-goal',
548
+ error: { name: 'MessageAbortedError' },
549
+ },
550
+ },
551
+ }, '/repo');
552
+ await flushQuestionPause();
553
+ expect(session.metadata.openchamber.goal.status).toBe('paused');
554
+ expect(paused).toEqual([{ sessionId: 'ses-goal', directory: '/repo' }]);
555
+ runtime.stop();
556
+ });
557
+ });
558
+
559
+ it('notifies onGoalPaused when metadata lands paused before abort (UI race)', async () => {
560
+ const paused = [];
561
+ const session = buildSession('paused');
562
+ session.metadata.openchamber.goal.statusReason = 'paused by user';
563
+ const fetchImpl = async () => new Response(JSON.stringify(session), { status: 200 });
564
+
565
+ await withFetch(fetchImpl, async () => {
566
+ const runtime = createSessionGoalRuntime({
567
+ buildOpenCodeUrl: (pathname) => `http://opencode${pathname}`,
568
+ getOpenCodeAuthHeaders: () => ({}),
569
+ getSmallModelService: async () => ({
570
+ generateSmallModelText: async () => ({ text: '{"verdict":"continue","note":"x"}' }),
571
+ }),
572
+ idleQuietMs: 1_000_000,
573
+ kickoffQuietMs: 1,
574
+ onGoalPaused: (sessionId, directory) => {
575
+ paused.push({ sessionId, directory });
576
+ },
577
+ });
578
+ // Abort arrives after UI already wrote paused metadata — must still notify.
579
+ runtime.processPayload({
580
+ type: 'message.updated',
581
+ properties: {
582
+ info: {
583
+ role: 'assistant',
584
+ sessionID: 'ses-goal',
585
+ error: { name: 'MessageAbortedError' },
586
+ },
587
+ },
588
+ }, '/repo');
589
+ await flushQuestionPause();
590
+ expect(paused).toEqual([{ sessionId: 'ses-goal', directory: '/repo' }]);
591
+ runtime.stop();
592
+ });
593
+ });
594
+
595
+ it('session.updated paused-by-user notifies onGoalPaused; question pause does not', async () => {
596
+ const paused = [];
597
+ const userPaused = buildSession('paused');
598
+ userPaused.metadata.openchamber.goal.statusReason = 'paused by user';
599
+ const questionPaused = buildSession('paused');
600
+ questionPaused.metadata.openchamber.goal.statusReason = 'paused for question';
601
+
602
+ const makeRuntime = (session) => createSessionGoalRuntime({
603
+ buildOpenCodeUrl: (pathname) => `http://opencode${pathname}`,
604
+ getOpenCodeAuthHeaders: () => ({}),
605
+ getSmallModelService: async () => ({
606
+ generateSmallModelText: async () => ({ text: '{"verdict":"continue","note":"x"}' }),
607
+ }),
608
+ idleQuietMs: 1_000_000,
609
+ kickoffQuietMs: 1,
610
+ onGoalPaused: (sessionId, directory) => {
611
+ paused.push({ sessionId, directory, reason: session.metadata.openchamber.goal.statusReason });
612
+ },
613
+ });
614
+
615
+ await withFetch(async () => new Response(JSON.stringify(userPaused), { status: 200 }), async () => {
616
+ const runtime = makeRuntime(userPaused);
617
+ runtime.processPayload({
618
+ type: 'session.updated',
619
+ properties: { info: userPaused },
620
+ }, '/repo');
621
+ await flushQuestionPause();
622
+ expect(paused).toEqual([{
623
+ sessionId: 'ses-goal',
624
+ directory: '/repo',
625
+ reason: 'paused by user',
626
+ }]);
627
+ runtime.stop();
628
+ });
629
+
630
+ paused.length = 0;
631
+ await withFetch(async () => new Response(JSON.stringify(questionPaused), { status: 200 }), async () => {
632
+ const runtime = makeRuntime(questionPaused);
633
+ runtime.processPayload({
634
+ type: 'session.updated',
635
+ properties: { info: questionPaused },
636
+ }, '/repo');
637
+ await flushQuestionPause();
638
+ // Question-driven pause must preserve auto-delegate timers.
639
+ expect(paused).toEqual([]);
640
+ runtime.stop();
641
+ });
642
+ });
451
643
  });
@@ -1 +0,0 @@
1
- import"./rolldown-runtime-C0FnF6B9.js";import{nt as e,rt as t}from"./vendor-base-ui-CnHfUmDN.js";import{n}from"./vendor-react-DLPElpoQ.js";import{c as r,l as i}from"./dialog-DhMGbF_B.js";import{t as a}from"./utils-2ZK8yboQ.js";var o=n();t();var s=e(),c=e=>{let t=(0,o.c)(32),{name:n,emoji:c,size:u,shape:d,className:f,label:p}=e,m=u===void 0?16:u,h=d===void 0?`rounded`:d,g,_,v;if(t[0]!==f||t[1]!==c||t[2]!==n||t[3]!==h){g=i(n);let e;t[7]===n?e=t[8]:(e=r(n),t[7]=n,t[8]=e),_=e,v=a(`inline-flex aspect-square shrink-0 overflow-hidden`,h===`circle`?`rounded-full`:`rounded-sm`,c&&`items-center justify-center select-none`,g.class,f),t[0]=f,t[1]=c,t[2]=n,t[3]=h,t[4]=g,t[5]=_,t[6]=v}else g=t[4],_=t[5],v=t[6];let y=`calc(${m}px * var(--dpt-n, 1))`,b=`calc(${m}px * var(--dpt-n, 1))`,x=`calc(${m}px * var(--dpt-n, 1))`,S=`calc(${m}px * var(--dpt-n, 1))`,C=`calc(${m}px * var(--dpt-n, 1))`,w=`calc(${m}px * var(--dpt-n, 1))`,T=`var(${g.var})`,E;t[9]===c?E=t[10]:(E=c?{display:`inline-flex`,alignItems:`center`,justifyContent:`center`}:null,t[9]=c,t[10]=E);let D;t[11]!==T||t[12]!==E||t[13]!==y||t[14]!==b||t[15]!==x||t[16]!==S||t[17]!==C||t[18]!==w?(D={width:y,minWidth:b,maxWidth:x,height:S,minHeight:C,maxHeight:w,color:T,...E},t[11]=T,t[12]=E,t[13]=y,t[14]=b,t[15]=x,t[16]=S,t[17]=C,t[18]=w,t[19]=D):D=t[19];let O=p?`img`:void 0,k=!p||void 0,A;t[20]!==c||t[21]!==_||t[22]!==m?(A=c?(0,s.jsx)(`span`,{"aria-hidden":`true`,className:`flex h-full w-full items-center justify-center leading-none`,style:{fontSize:`calc(${m*.75}px * var(--dpt-n, 1))`,lineHeight:1,transform:`translateY(0.06em)`},children:c}):(0,s.jsxs)(`svg`,{width:m,height:m,viewBox:`0 0 5 5`,shapeRendering:`crispEdges`,className:`oc-agent-avatar block h-full w-full`,"aria-hidden":`true`,children:[(0,s.jsx)(`rect`,{width:`5`,height:`5`,fill:`currentColor`,opacity:.14}),_.map(l)]}),t[20]=c,t[21]=_,t[22]=m,t[23]=A):A=t[23];let j;return t[24]!==p||t[25]!==h||t[26]!==D||t[27]!==O||t[28]!==k||t[29]!==A||t[30]!==v?(j=(0,s.jsx)(`span`,{className:v,style:D,"data-agent-avatar":``,"data-agent-avatar-shape":h,role:O,"aria-label":p,"aria-hidden":k,children:A}),t[24]=p,t[25]=h,t[26]=D,t[27]=O,t[28]=k,t[29]=A,t[30]=v,t[31]=j):j=t[31],j};function l(e,t){return e.map((e,n)=>e?(0,s.jsx)(`rect`,{x:n,y:t,width:`1`,height:`1`,fill:`currentColor`},`${n}-${t}`):null)}export{c as t};
@@ -1,3 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ToolOutputDialog-BQ_oXyS_.js","assets/rolldown-runtime-C0FnF6B9.js","assets/runtime-fetch-zIalUnbb.js","assets/runtime-auth-D66yq6ie.js","assets/runtime-switch-LvWDU-SL.js","assets/vendor-base-ui-CnHfUmDN.js","assets/useUIStore-CxOoCv7B.js","assets/vendor-zustand-B4dlGEM2.js","assets/vendor-react-DLPElpoQ.js","assets/vendor-pierre-diffs-DX7XTPG3.js","assets/vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js","assets/vendor-hast-util-to-html-B0p1k5Xa.js","assets/vendor-character-entities-legacy-Wut6vMuj.js","assets/vendor-character-entities-html4-DlN_yAFd.js","assets/vendor-ccount-CyGsA0u7.js","assets/vendor-comma-separated-tokens-B9ouxNNS.js","assets/vendor-oniguruma-to-es-CrHzjjSU.js","assets/vendor-oniguruma-parser-D2DIvhSP.js","assets/vendor-diff-Dq7CZNim.js","assets/vendor-lru_map-DpDied8H.js","assets/vendor-reactuses-core-BnW6GxJt.js","assets/vendor-lodash-es-DfLbG5Af.js","assets/vendor-js-cookie-hSOiFTtX.js","assets/clipboard-GUUNlWIv.js","assets/persistence-DwRBC4zl.js","assets/vendor-pathe-vBmvQE8f.js","assets/vendor-tanstack-query-core-BWz0ose6.js","assets/store-ClnJdJSj.js","assets/dialog-DhMGbF_B.js","assets/utils-2ZK8yboQ.js","assets/vendor-class-variance-authority-BLUaYARZ.js","assets/vendor-tailwind-merge-BicNWLTg.js","assets/Icon-D1BcR8Tz.js","assets/button-9R-WgVMl.js","assets/useThemeSystem-DMzWVJaW.js","assets/markdownTheme-DOfGg-A7.js","assets/appThemeRegistry-BDrIDWKH.js","assets/platform-DQ5_LNKO.js","assets/vendor-opencode-sdk-C07HQypa.js","assets/useMobileNavigationStore-DDgESrzu.js","assets/vendor-tanstack-react-query-D7pys_c9.js","assets/vendor-sonner-DVzioF3d.js","assets/useAssistantUIStore-CLPCNoj_.js","assets/vendor-fuse.js-DB5wDJbI.js","assets/MarkdownRenderer-YMePGw0Z.js","assets/markdownHeightCache-BL8CUQ0M.js","assets/dualLimitLru-D8Sphgua.js","assets/markdown-worker-CptoICmq.js","assets/useEffectiveDirectory-C5Gg7EvP.js","assets/imageSource-BlAJJUEI.js","assets/relay-image-stream-DM7atqJs.js","assets/useWorkerHighlightedLines-BSQQkZaO.js","assets/tooltip-DSjr26A_.js","assets/vendor-tanstack-react-virtual-tlDgH6PG.js"])))=>i.map(i=>d[i]);
2
- import{o as e,r as t}from"./rolldown-runtime-C0FnF6B9.js";import{c as n,i as r,n as i}from"./runtime-switch-LvWDU-SL.js";import{B as a,J as o,V as s,W as c,Y as l,Z as u,nt as d,q as f,ut as p}from"./persistence-DwRBC4zl.js";import{a as m}from"./vendor-zustand-B4dlGEM2.js";import{nt as h,rt as g}from"./vendor-base-ui-CnHfUmDN.js";import{n as _,r as v}from"./platform-DQ5_LNKO.js";import{t as y}from"./useUIStore-CxOoCv7B.js";import{o as b}from"./vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js";import{n as x}from"./vendor-react-DLPElpoQ.js";import{s as S}from"./vendor-tanstack-react-query-D7pys_c9.js";import{r as C}from"./vendor-sonner-DVzioF3d.js";import{a as w,d as ee,i as T,n as E,r as D,u as O}from"./vendor-reactuses-core-BnW6GxJt.js";import{n as k}from"./clipboard-GUUNlWIv.js";import{a as A,n as j}from"./MobileShareBridge-3tBtXXJJ.js";import{C as M,_ as N,a as P,f as F,g as I,j as L,k as R,l as z,n as te,r as B,s as V,t as H,u as U,y as ne}from"./MobileDetailNavigation-BeNUCxzK.js";import{dr as re,fr as ie,ko as ae,ot as oe,qt as W,r as se,vn as G}from"./useMobileNavigationStore-DDgESrzu.js";import{i as K,n as ce,r as le}from"./useAssistantUIStore-CLPCNoj_.js";import{a as q,i as J,n as ue,o as Y,r as de,t as fe}from"./dialog-DhMGbF_B.js";import{t as pe}from"./utils-2ZK8yboQ.js";import{t as me}from"./AgentAvatar-m1jNq4bX.js";import{n as X}from"./Icon-D1BcR8Tz.js";import{t as Z}from"./button-9R-WgVMl.js";import{i as he}from"./OverlayScrollbar-Bahg_P3r.js";import{a as ge,n as _e,r as ve,t as ye}from"./fileMentionTouchSelection-DzdgAvGS.js";import{o as be,t as xe}from"./MarkdownRenderer-YMePGw0Z.js";import{n as Se}from"./textarea-B9CmN13Z.js";import{c as Ce,s as we}from"./imageSource-BlAJJUEI.js";import{D as Te,S as Ee,T as De,a as Oe,c as ke,d as Ae,f as je,i as Me,l as Ne,m as Pe,n as Fe,o as Ie,p as Le,r as Re,t as ze,u as Be}from"./sessionChangeSummary-BG7l2heP.js";import{a as Ve,t as He}from"./sessionLookup-BZuvc3Aa.js";import{a as Ue,i as We,n as Ge,r as Ke,t as qe}from"./context-menu-CSyOhRz8.js";import{i as Je,n as Ye,r as Xe}from"./assistant-attachment-cache-C0aRnFkj.js";var Ze=x();function Qe(e){return[...e].sort((e,t)=>{let n=e.latestMessagePreview?.createdAt??-1/0,r=t.latestMessagePreview?.createdAt??-1/0;return n===r?0:r-n})}var Q=e(g(),1),$=h();function $e({snapshot:e,rowClassName:t}){let{t:n}=k(),[r,i]=Q.useState(!1),a=Q.useRef(!1),o=E(async()=>{if(!a.current){a.current=!0,i(!0);try{(await z(e)).failed&&C.error(n(`assistants.unread.markAllFailed`))}catch{C.error(n(`assistants.unread.markAllFailed`))}finally{a.current=!1,i(!1)}}});return e.assistants.some(e=>(e.unreadCount??0)>0)?(0,$.jsx)(`div`,{className:t,children:(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`xs`,onClick:o,className:`max-w-full whitespace-normal text-right`,disabled:r||!e.assistants.some(e=>(e.unreadCount??0)>0&&e.readTip),"aria-busy":r,children:n(`assistants.unread.markAll`)})}):null}var et=e=>{let t=(0,Ze.c)(17),{name:n,emoji:r,size:i,label:a,working:o,className:s}=e,c=i===void 0?24:i,l=o!==void 0&&o,{t:u}=k(),d=`calc(${c}px * var(--dpt-n, 1))`,f;t[0]===s?f=t[1]:(f=pe(`relative inline-block shrink-0 align-middle leading-none`,s),t[0]=s,t[1]=f);let p;t[2]===d?p=t[3]:(p={width:d,height:d},t[2]=d,t[3]=p);let m;t[4]!==r||t[5]!==a||t[6]!==n||t[7]!==c?(m=(0,$.jsx)(me,{name:n,emoji:r,size:c,label:a,shape:`circle`}),t[4]=r,t[5]=a,t[6]=n,t[7]=c,t[8]=m):m=t[8];let h;t[9]!==u||t[10]!==l?(h=l?(0,$.jsx)(`span`,{className:`pointer-events-none absolute right-0 bottom-0 size-2.5 translate-x-0.5 translate-y-0.5 rounded-full bg-[var(--status-success)] ring-2 ring-background`,"data-assistant-working-dot":``,"aria-label":u(`assistants.contact.working`)}):null,t[9]=u,t[10]=l,t[11]=h):h=t[11];let g;return t[12]!==f||t[13]!==p||t[14]!==m||t[15]!==h?(g=(0,$.jsxs)(`span`,{className:f,style:p,"data-assistant-working-avatar":``,children:[m,h]}),t[12]=f,t[13]=p,t[14]=m,t[15]=h,t[16]=g):g=t[16],g},tt=m(e=>({workingByID:{},setWorking:(t,n)=>e(e=>({workingByID:{...e.workingByID,[t]:n}}))})),nt=({sending:e=!1,processing:t=!1,serverWorking:n=!1})=>e||t||n,rt=(e,t)=>{let n=(0,Ze.c)(5),r=t!==void 0&&t,i;n[0]===e?i=n[1]:(i=t=>!!t.workingByID[e],n[0]=e,n[1]=i);let a=tt(i),o;return n[2]!==a||n[3]!==r?(o=nt({processing:a,serverWorking:r}),n[2]=a,n[3]=r,n[4]=o):o=n[4],o};function it(e){let t=(0,Ze.c)(12),{assistantID:n,position:a}=e,o=Q.useRef(null),s=Q.useRef(!1),c;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(c={busy:!1,done:!1,retryAt:0},t[0]=c):c=t[0];let l=Q.useRef(c),[u]=Q.useState(ut),d;t[1]!==n||t[2]!==a||t[3]!==u?(d=()=>{let e=o.current;if(!e||!s.current||l.current.busy||l.current.done||Date.now()<l.current.retryAt||u.transport!==r()||u.generation!==i()||document.visibilityState!==`visible`||(_()?!document.documentElement.classList.contains(`oc-native-app-active`):!document.hasFocus())||e.parentElement?.closest(`[inert], [aria-hidden="true"]`))return;let t=e.closest(`[data-assistant-contact-transcript]`);if(!t||t.scrollHeight-t.scrollTop-t.clientHeight>2)return;let c=e.getBoundingClientRect(),d=t.getBoundingClientRect(),f=window.visualViewport,p=f?.offsetTop??0,m=p+(f?.height??window.innerHeight);c.height<=0||c.width<=0||c.bottom>Math.min(d.bottom,m)||c.top<Math.max(d.top,p)||c.right<=Math.max(d.left,0)||c.left>=Math.min(d.right,window.innerWidth)||(l.current.busy=!0,U(n,a).then(()=>{l.current.done=!0}).catch(()=>{l.current.retryAt=Date.now()+15e3}).finally(()=>{l.current.busy=!1}))},t[1]=n,t[2]=a,t[3]=u,t[4]=d):d=t[4];let f=E(d),p;t[5]===f?p=t[6]:(p=e=>{s.current=e.some(lt),f()},t[5]=f,t[6]=p);let m;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(m={threshold:1},t[7]=m):m=t[7],T(o,E(p),m),D(`visibilitychange`,f,ct),D(`focus`,f,st),D(`resize`,f,ot);let h,g;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(h=()=>o.current?.closest(`[data-assistant-contact-transcript]`),g={passive:!0},t[8]=h,t[9]=g):(h=t[8],g=t[9]),D(`scroll`,f,h,g);let v;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(v={attributes:!0,attributeFilter:[`class`]},t[10]=v):v=t[10],O(f,at,v),w(f,15e3);let y;return t[11]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,$.jsx)(`span`,{ref:o,"aria-hidden":`true`,className:`block h-px w-px shrink-0`,"data-assistant-read-marker":``}),t[11]=y):y=t[11],y}function at(){return document.documentElement}function ot(){return window.visualViewport}function st(){return window}function ct(){return document}function lt(e){return e.isIntersecting&&e.intersectionRatio===1}function ut(){return{transport:r(),generation:i()}}var dt=e=>e?.directories.flatMap(({directory:e,sessions:t})=>e?t.filter(e=>!e.time.archived).map(t=>({...t,directory:e})):[])??null,ft=Q.forwardRef(({query:e,isMobile:t,listId:n,onHighlightChange:r,onSelect:i,onClose:a},o)=>{let{t:s}=k(),c=Ce(),l=S({...ie(c),select:dt}),u=Q.useMemo(()=>oe({sessions:l.data??[],currentSessionId:null,searchQuery:e}),[l.data,e]),[d,f]=Q.useState({query:e,index:0}),p=Math.min(d.query===e?d.index:0,Math.max(0,u.length-1)),m=Q.useRef(null),h=Q.useRef([]),g=Q.useMemo(ye,[]);D(`pointerdown`,e=>{e.target instanceof Node&&!m.current?.contains(e.target)&&a()},void 0,{capture:!0}),Q.useLayoutEffect(()=>{h.current[p]?.scrollIntoView?.({block:`nearest`})},[p]),Q.useLayoutEffect(()=>{r(u.length?`${n}-${p}`:void 0)},[p,n,u.length,r]);let _=E(t=>{if(t===`Escape`){a();return}u.length&&(t===`ArrowDown`&&f({query:e,index:(p+1)%u.length}),t===`ArrowUp`&&f({query:e,index:(p-1+u.length)%u.length}),(t===`Enter`||t===`Tab`)&&i(u[p]))});return Q.useImperativeHandle(o,()=>({keyDown:_}),[_]),(0,$.jsxs)(_e,{ref:m,isMobile:t,className:`max-w-[640px] max-h-64`,children:[(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 px-3 py-1`,children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 text-[length:calc(var(--text-meta)*0.875)] leading-4 text-muted-foreground`,children:s(`assistants.contact.sessionMention.scope`)}),(0,$.jsx)(Z,{type:`button`,size:`xs`,variant:`ghost`,"aria-label":s(`dialog.common.actions.close`),onClick:a,children:(0,$.jsx)(X,{name:`close`,className:`size-4`})})]}),l.isPending?(0,$.jsx)(`p`,{role:`status`,className:`px-3 py-2 typography-meta text-muted-foreground`,children:s(`common.loading`)}):null,l.isError?(0,$.jsxs)(`div`,{role:`alert`,className:`px-3 py-2 typography-meta text-[var(--status-error)]`,children:[s(`assistants.contact.sessionMention.loadFailed`),(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>void l.refetch(),children:s(`chat.history.retry`)})]}):null,l.isSuccess&&!u.length?(0,$.jsx)(`p`,{role:`status`,className:`px-3 py-2 typography-meta text-muted-foreground`,children:s(l.data===null?`common.unavailable`:`sessions.sidebar.empty.noMatches.title`)}):null,(0,$.jsx)(Se,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0`,children:(0,$.jsx)(`div`,{id:n,role:`listbox`,"aria-label":s(`chat.fileMentionAutocomplete.groups.sessions`),className:`p-1.5`,children:u.map((r,a)=>(0,$.jsxs)(`div`,{id:`${n}-${a}`,role:`option`,"aria-selected":a===p,ref:e=>{h.current[a]=e},className:pe(`flex min-h-10 cursor-pointer items-center gap-2 rounded-md px-1.5 py-1 typography-ui-label`,ve(t,a===p)),onMouseDown:e=>e.preventDefault(),onMouseMove:()=>f({query:e,index:a}),onPointerDown:e=>{e.pointerType===`touch`&&g.pointerDown(e.clientX,e.clientY)},onPointerMove:e=>{e.pointerType===`touch`&&g.pointerMove(e.clientX,e.clientY)},onPointerUp:e=>{e.pointerType===`touch`&&g.pointerUp(()=>i(r))&&(e.preventDefault(),e.stopPropagation())},onPointerCancel:()=>g.pointerCancel(),onClick:()=>g.click(()=>i(r)),children:[(0,$.jsx)(X,{name:`chat-thread`,className:`size-4 shrink-0 text-muted-foreground`}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`div`,{className:`truncate font-medium leading-5`,title:r.title,children:r.title||s(`chat.fileMentionAutocomplete.untitledSession`)}),(0,$.jsx)(`div`,{className:`truncate text-[length:calc(var(--text-meta)*0.875)] leading-4 text-muted-foreground`,title:r.directory,children:r.directory})]})]},`${r.directory}:${r.id}`))})}),t?null:(0,$.jsx)(`div`,{className:`mx-1.5 shrink-0 border-t px-1.5 py-1 text-[length:calc(var(--text-meta)*0.875)] leading-4 text-muted-foreground`,children:s(`chat.autocomplete.keyboardHint`)})]})}),pt=e=>{let t=(0,Ze.c)(87),n,r,i,u;t[0]===e?(n=t[1],r=t[2],i=t[3],u=t[4]):({active:n,working:u,onChange:r,...i}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=u);let d=u!==void 0&&u,{t:m}=k(),h;t[5]===i.value?h=t[6]:(h=()=>({canonical:i.value,document:c(i.value,new Map)}),t[5]=i.value,t[6]=h);let[g,_]=Q.useState(h),v;t[7]!==g.canonical||t[8]!==g.document||t[9]!==i.value?(v=g.canonical===i.value?g.document:c(i.value,new Map),t[7]=g.canonical,t[8]=g.document,t[9]=i.value,t[10]=v):v=t[10];let y=v,[b,x]=Q.useState(0),[S,C]=Q.useState(!0),[w,ee]=Q.useState(!1),[T,D]=Q.useState(),O=Q.useRef(null),A=Q.useRef(null),j=Q.useRef(null),M=Q.useRef(null),N;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(N=Ne(),t[11]=N):N=t[11];let P=Q.useRef(N),F=Q.useId(),I;t[12]!==n||t[13]!==w||t[14]!==b||t[15]!==S||t[16]!==y.text||t[17]!==i.disabled||t[18]!==i.pending?(I=n&&!i.pending&&!i.disabled&&!S&&!w?ge({text:y.text,cursor:b}):null,t[12]=n,t[13]=w,t[14]=b,t[15]=S,t[16]=y.text,t[17]=i.disabled,t[18]=i.pending,t[19]=I):I=t[19];let L=I,R=L?.kind===`mention`?L:null,z;t[20]===Symbol.for(`react.memo_cache_sentinel`)?(z=()=>{M.current!==null&&(O.current?.focus({preventScroll:!0}),O.current?.setSelectionRange(M.current,M.current),M.current=null)},t[20]=z):z=t[20];let te;t[21]===y?te=t[22]:(te=[y],t[21]=y,t[22]=te),Q.useLayoutEffect(z,te);let B;t[23]===Symbol.for(`react.memo_cache_sentinel`)?(B=()=>C(!0),t[23]=B):B=t[23];let V=E(B),H;t[24]!==w||t[25]!==b||t[26]!==y||t[27]!==r?(H=(e,t,n)=>{let i=n===void 0||n,a=l(e);a.ok&&(i&&(P.current=Be(P.current,{before:ke(y,[],{start:O.current?.selectionStart??b,end:O.current?.selectionEnd??b}),after:ke(e,[],{start:t,end:t})})),w||(M.current=t),x(t),_({canonical:a.text,document:e}),r(a.text))},t[24]=w,t[25]=b,t[26]=y,t[27]=r,t[28]=H):H=t[28];let U=E(H),ne;t[29]!==U||t[30]!==y||t[31]!==R||t[32]!==m?(ne=e=>{if(!R)return;let t=e.title||m(`chat.fileMentionAutocomplete.untitledSession`),n=s(y,R.tokenStart,R.tokenEnd,{id:`session:${e.id}:${crypto.randomUUID()}`,kind:`session`,sessionId:e.id,display:p({trigger:`@`,icon:`chat-thread`,label:t})},{inlineBoundaries:!0,padDocumentEdges:!0}),r=n.caret+ +(n.document.text[n.caret]===` `);C(!0),U(n.document,r)},t[29]=U,t[30]=y,t[31]=R,t[32]=m,t[33]=ne):ne=t[33];let re=E(ne),ie;t[34]!==U||t[35]!==y?(ie=(e,t)=>{let n=e.currentTarget;if(n.selectionStart===n.selectionEnd||!e.clipboardData||!y.references.some(e=>e.start<n.selectionEnd&&e.end>n.selectionStart))return;let r=a(n.selectionStart,n.selectionEnd,y.references)??{start:n.selectionStart,end:n.selectionEnd},i=l({text:y.text.slice(r.start,r.end),references:y.references.filter(e=>e.start>=r.start&&e.end<=r.end).map(e=>({...e,start:e.start-r.start,end:e.end-r.start}))});if(i.ok&&(e.preventDefault(),e.clipboardData.setData(`text/plain`,i.text),t)){let e=f(y,y.text.slice(0,r.start)+y.text.slice(r.end),r.start,r.start);U(e.document,e.caret)}},t[34]=U,t[35]=y,t[36]=ie):ie=t[36];let ae=E(ie),oe;t[37]!==y.references||t[38]!==y.text?(oe=Pe(y.text,y.references.map(mt))?.map(ht),t[37]=y.references,t[38]=y.text,t[39]=oe):oe=t[39];let W=oe,se=y.text,G=i.pending||d,K=i.pending===!0,ce=i.layout===`inline`?`py-3 leading-6`:`pt-4 pb-2`,le;t[40]!==i.textLayoutClassName||t[41]!==ce?(le=pe(`whitespace-pre-wrap break-words overflow-hidden px-3 typography-markdown md:typography-ui-label`,ce,i.textLayoutClassName),t[40]=i.textLayoutClassName,t[41]=ce,t[42]=le):le=t[42];let q;t[43]!==U||t[44]!==y?(q=(e,t)=>{let n=f(y,e,t?.target.selectionStart??e.length,t?.target.selectionEnd??e.length);U(n.document,n.caret),C(t?.nativeEvent?.inputType===`insertFromPaste`)},t[43]=U,t[44]=y,t[45]=q):q=t[45];let J=R?F:void 0,ue=R?T:void 0,Y;t[46]===i.textareaProps?Y=t[47]:(Y=e=>{i.textareaProps?.onScroll?.(e),A.current&&(A.current.scrollTop=e.currentTarget.scrollTop,A.current.scrollLeft=e.currentTarget.scrollLeft)},t[46]=i.textareaProps,t[47]=Y);let de,fe;t[48]!==ae||t[49]!==i.textareaProps?(de=e=>{i.textareaProps?.onCopy?.(e),e.defaultPrevented||ae(e,!1)},fe=e=>{i.textareaProps?.onCut?.(e),e.defaultPrevented||ae(e,!0)},t[48]=ae,t[49]=i.textareaProps,t[50]=de,t[51]=fe):(de=t[50],fe=t[51]);let me;t[52]===i.textareaProps?me=t[53]:(me=e=>{x(e.currentTarget.selectionStart),i.textareaProps?.onSelect?.(e)},t[52]=i.textareaProps,t[53]=me);let X,Z;t[54]===Symbol.for(`react.memo_cache_sentinel`)?(X=()=>{ee(!0)},Z=e=>{ee(!1),x(e.currentTarget.selectionStart)},t[54]=X,t[55]=Z):(X=t[54],Z=t[55]);let he;t[56]!==U||t[57]!==w||t[58]!==y||t[59]!==R||t[60]!==i.textareaProps?(he=e=>{if(i.textareaProps?.onKeyDown?.(e),!(e.defaultPrevented||De(e))){if(w){e.key===`Enter`&&e.preventDefault();return}if((e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`z`){let t=e.shiftKey?Ae(P.current,y):je(P.current,y);t&&(e.preventDefault(),P.current=t.history,U(t.snapshot.document,t.snapshot.selection.end,!1),C(!0));return}if(e.key===`Backspace`||e.key===`Delete`){let t=o(y,{key:e.key,selectionStart:e.currentTarget.selectionStart,selectionEnd:e.currentTarget.selectionEnd,altKey:e.altKey});if(t){e.preventDefault(),U(t.document,t.caret),C(!0);return}}R&&[`ArrowDown`,`ArrowUp`,`Enter`,`Tab`,`Escape`].includes(e.key)&&(e.preventDefault(),e.stopPropagation(),j.current?.keyDown(e.key))}},t[56]=U,t[57]=w,t[58]=y,t[59]=R,t[60]=i.textareaProps,t[61]=he):he=t[61];let _e;t[62]!==i.textareaProps||t[63]!==J||t[64]!==ue||t[65]!==Y||t[66]!==de||t[67]!==fe||t[68]!==me||t[69]!==he?(_e={...i.textareaProps,"aria-controls":J,"aria-activedescendant":ue,"aria-autocomplete":`list`,onScroll:Y,onCopy:de,onCut:fe,onSelect:me,onCompositionStart:X,onCompositionEnd:Z,onKeyDown:he},t[62]=i.textareaProps,t[63]=J,t[64]=ue,t[65]=Y,t[66]=de,t[67]=fe,t[68]=me,t[69]=he,t[70]=_e):_e=t[70];let ve;t[71]!==V||t[72]!==F||t[73]!==R||t[74]!==i.isMobile||t[75]!==re?(ve=R?(0,$.jsx)(ft,{ref:j,query:R.query,isMobile:i.isMobile??!1,listId:F,onHighlightChange:D,onSelect:re,onClose:V}):null,t[71]=V,t[72]=F,t[73]=R,t[74]=i.isMobile,t[75]=re,t[76]=ve):ve=t[76];let ye;return t[77]!==y.text||t[78]!==W||t[79]!==i||t[80]!==G||t[81]!==K||t[82]!==le||t[83]!==q||t[84]!==_e||t[85]!==ve?(ye=(0,$.jsx)(Ee,{...i,value:se,pending:G,disableInputWhilePending:K,inputRef:O,highlightedContent:W,highlightRef:A,textLayoutClassName:le,onChange:q,textareaProps:_e,children:ve}),t[77]=y.text,t[78]=W,t[79]=i,t[80]=G,t[81]=K,t[82]=le,t[83]=q,t[84]=_e,t[85]=ve,t[86]=ye):ye=t[86],ye};function mt(e){return{start:e.start,end:e.end,priority:103,...u(e)}}function ht(e,t){return(0,$.jsx)(`span`,{className:e.className,children:e.visual?(0,$.jsx)(Le,{visual:e.visual,text:e.text}):e.text},`${t}-${e.text.length}`)}var gt=`max-h-72 max-w-full rounded-[1.35rem] border border-border/40 object-contain cursor-zoom-in`;function _t({assistantID:e,descriptor:t,onShowPopup:n}){let{t:r}=k(),i=Ce(),{attachmentID:a,sha256:o,size:s,mime:c,filename:l}=t,u=Q.useMemo(()=>({type:`file`,attachmentID:a,sha256:o,size:s,mime:c,filename:l}),[a,o,s,c,l]),d=c.startsWith(`image/`),[f,p]=Q.useState(0),[m,h]=Q.useState(``),[g,_]=Q.useState(!1),[v,y]=Q.useState(!1),b=Q.useRef(null),x=Q.useRef([]);Q.useEffect(()=>{h(``),_(!1);let t=new AbortController,n;return d&&Xe(e,u,{signal:t.signal}).then(e=>{if(t.signal.aborted){e.release();return}n=e.release,h(e.url)}).catch(()=>{t.signal.aborted||_(!0)}),()=>{t.abort(),n?.()}},[e,u,i,d,f]),Q.useEffect(()=>()=>{b.current?.abort(),x.current.forEach(e=>URL.revokeObjectURL(e)),x.current=[]},[e,u,i]);let S=E(async()=>{if(b.current)return;let t=new AbortController;b.current=t,y(!0),_(!1);try{let n=await Ye(e,u,{signal:t.signal});if(t.signal.aborted)return;x.current.forEach(e=>URL.revokeObjectURL(e));let i=URL.createObjectURL(n);x.current=[i];let a=document.createElement(`a`);a.href=i,a.download=l||r(`assistants.contact.attachment.file`),document.body.appendChild(a),a.click(),a.remove()}catch{t.signal.aborted||_(!0)}finally{b.current===t&&(b.current=null),t.signal.aborted||y(!1)}}),C=l||r(d?`assistants.contact.attachment.image`:`assistants.contact.attachment.file`),w=E(()=>{!n||!m||n({open:!0,title:C,content:``,metadata:{tool:`image-preview`,filename:C,mime:c},image:{url:m,mimeType:c,filename:C,size:s,gallery:[{url:m,mimeType:c,filename:C,size:s}],index:0}})});return d&&m&&!g?(0,$.jsx)(`img`,{src:m,alt:C,className:gt,onError:()=>_(!0),onClick:w,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),w())},role:`button`,tabIndex:0,"data-assistant-contact-image":``}):(0,$.jsxs)(`div`,{className:`flex max-w-full flex-col gap-1 rounded-[1.25rem] bg-[var(--surface-muted)] px-3.5 py-2.5 ring-1 ring-inset ring-[var(--surface-subtle)]`,"data-assistant-contact-file":``,children:[(0,$.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2.5`,children:[(0,$.jsx)(X,{name:`file-text`,className:`size-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`truncate typography-ui`,children:C})]}),g?(0,$.jsx)(`p`,{role:`alert`,className:`typography-micro text-[var(--status-error)]`,children:r(`assistants.contact.attachment.loadFailed`)}):null,d&&!g||v?(0,$.jsx)(`span`,{role:`status`,className:`typography-micro text-muted-foreground`,children:r(`common.loading`)}):(0,$.jsx)(Z,{type:`button`,size:`sm`,variant:`ghost`,onClick:d?()=>p(e=>e+1):()=>void S(),children:r(g?`chat.history.retry`:`assistants.contact.attachment.download`)})]})}function vt(e){let t=(0,Ze.c)(27),{part:n,onShowPopup:r}=e,{t:i}=k(),a=/^(?:https?:|data:|blob:)/i.test(n.url)?n.url:``,o=we(a,``),[s,c]=Q.useState(!1),l;t[0]!==n.filename||t[1]!==i?(l=n.filename||i(`assistants.contact.attachment.image`),t[0]=n.filename,t[1]=i,t[2]=l):l=t[2];let u=l,d;t[3]!==u||t[4]!==r||t[5]!==o?(d=()=>{!r||!o||r({open:!0,title:u,content:``,metadata:{tool:`image-preview`,filename:u},image:{url:o,filename:u,gallery:[{url:o,filename:u}],index:0}})},t[3]=u,t[4]=r,t[5]=o,t[6]=d):d=t[6];let f=E(d);if(n.mime.startsWith(`image/`)&&o&&!s){let e;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(e=()=>c(!0),t[7]=e):e=t[7];let n;t[8]===f?n=t[9]:(n=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),f())},t[8]=f,t[9]=n);let r;return t[10]!==u||t[11]!==f||t[12]!==o||t[13]!==n?(r=(0,$.jsx)(`img`,{src:o,alt:u,className:gt,onError:e,onClick:f,onKeyDown:n,role:`button`,tabIndex:0,"data-assistant-contact-image":``}),t[10]=u,t[11]=f,t[12]=o,t[13]=n,t[14]=r):r=t[14],r}let p;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsx)(X,{name:`file-text`,className:`size-4 shrink-0 text-muted-foreground`}),t[15]=p):p=t[15];let m;t[16]!==n.filename||t[17]!==i?(m=n.filename||i(`assistants.contact.attachment.file`),t[16]=n.filename,t[17]=i,t[18]=m):m=t[18];let h;t[19]===m?h=t[20]:(h=(0,$.jsx)(`span`,{className:`truncate typography-ui`,children:m}),t[19]=m,t[20]=h);let g;t[21]!==s||t[22]!==i?(g=s?(0,$.jsx)(Z,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>c(!1),children:i(`chat.history.retry`)}):null,t[21]=s,t[22]=i,t[23]=g):g=t[23];let _;return t[24]!==h||t[25]!==g?(_=(0,$.jsxs)(`div`,{className:`flex max-w-full items-center gap-2.5 rounded-[1.25rem] bg-[var(--surface-muted)] px-3.5 py-2.5`,"data-assistant-contact-file":``,children:[p,h,g]}),t[24]=h,t[25]=g,t[26]=_):_=t[26],_}function yt(e){let t=(0,Ze.c)(5),{assistantID:n,part:r,onShowPopup:i}=e,a=Ce(),o;return t[0]!==n||t[1]!==i||t[2]!==r||t[3]!==a?(o=`attachmentID`in r?(0,$.jsx)(_t,{assistantID:n,descriptor:r,onShowPopup:i},`${a}:${n}:${r.attachmentID}:${r.sha256}`):(0,$.jsx)(vt,{part:r,onShowPopup:i},`${a}:${r.url}`),t[0]=n,t[1]=i,t[2]=r,t[3]=a,t[4]=o):o=t[4],o}var bt=[],xt=e=>e.flatMap(e=>e.type===`text`&&e.text.trim()?[e.text]:[]).join(`
3
- `),St=(e,t,n,r=Date.now())=>({assistantID:e,messageID:t,parts:n,status:`sending`,createdAt:r}),Ct=(e,t)=>{let n=e.filter(e=>e.assistantID===t);return n.length===e.length?e:n},wt=(e,t)=>{let n=e.filter(e=>e.assistantID===t);return n.length===e.length?e:n},Tt=(e,t,n,r)=>({messageID:t?`${e.turnID}:preview:${t.bubbleIndex}`:`${e.turnID}:preview:${r}`,assistantID:e.assistantID,role:`assistant`,turnID:e.turnID,bubbleIndex:t?.bubbleIndex??0,createdAt:t?.occurredAt??e.occurredAt,ordinal:n,status:r,fromAssistantID:null,fromAssistantName:null,parts:t?[{type:`text`,text:t.text}]:[],text:t?.text??``,cards:[]}),Et=(e,t,n)=>{let r=e.bubbles.filter(e=>!t.has(e.bubbleIndex)).map((t,r)=>Tt(e,t,n+r,t.done?`complete`:`streaming`));return e.status===`failed`?[...r,Tt(e,null,n+r.length,`failed`)]:e.status===`admitted`||e.status===`streaming`?[...r,Tt(e,null,n+r.length,`admitted`)]:r},Dt=(e,t,n,r=[])=>{let i=new Set(e.map(e=>e.messageID)),a=t.flatMap((t,r)=>t.assistantID!==n||i.has(t.messageID)?[]:[{messageID:t.messageID,assistantID:n,role:`user`,turnID:t.messageID,bubbleIndex:0,createdAt:t.createdAt,ordinal:e.length+r,status:t.status,fromAssistantID:null,fromAssistantName:null,parts:[...t.parts],text:xt(t.parts),cards:[]}]),o=a.length===0?e:[...e,...a],s=r.filter(e=>e.assistantID===n);if(s.length===0)return o;let c=new Map,l=new Map;o.forEach((e,t)=>{if(c.set(e.turnID,t),e.role!==`assistant`||e.messageID.includes(`:preview:`))return;let n=l.get(e.turnID)??new Set;n.add(e.bubbleIndex),l.set(e.turnID,n)});let u=new Map,d=[];for(let e of s){let t=Et(e,l.get(e.turnID)??new Set,o.length+d.length);if(t.length===0)continue;let n=c.get(e.turnID);if(n===void 0){if(e.status===`failed`&&o.some(t=>t.turnID!==e.turnID))continue;d.push(...t);continue}let r=u.get(n)??[];r.push(...t),u.set(n,r)}return u.size===0&&d.length===0?o:o.flatMap((e,t)=>[e,...u.get(t)??[]]).concat(d)},Ot=(e,t)=>{let n=new Set(t.map(e=>e.messageID)),r=e.filter(e=>!n.has(e.messageID));return r.length===e.length?e:r},kt=(e,t)=>e.map(e=>e.messageID===t?{...e,status:`admitted`}:e),At=(e,t,n,r=Date.now())=>{let i=e.filter(e=>e.assistantID!==t||e.status!==`failed`||e.turnID===n);return i.some(e=>e.assistantID===t&&e.turnID===n)?i.length===e.length?e:i:[...i,{assistantID:t,turnID:n,status:`admitted`,bubbles:[],occurredAt:r}]},jt=(e,t,n)=>!t?.turnID||!t.assistantID||n?.has(t.turnID)?e:At(e,t.assistantID,t.turnID,t.admittedAt),Mt=(e,t)=>{let n=t.assistantID,r=t.pendingSendTurnIDs??new Set,i=t.settledTurnIDs??new Set,a=typeof t.snapshotRevision==`number`&&Number.isFinite(t.snapshotRevision)?t.snapshotRevision:null,o=t.admissionRevisionByTurnID instanceof Map?t.admissionRevisionByTurnID:new Map(Object.entries(t.admissionRevisionByTurnID??{}).map(([e,t])=>[e,Number(t)])),s=t.occurredAt??Date.now(),c=t.activeContactTurn&&t.activeContactTurn.turnID?t.activeContactTurn:null,l=!!(t.serverWorking||c),u=jt(e,c?{assistantID:n,turnID:c.turnID,admittedAt:c.admittedAt}:null,i),d=Array.isArray(t.messages)?t.messages:[];for(let e of d)e.role===`assistant`&&e.status===`error`&&(r.has(e.turnID)||i.has(e.turnID)||(u=Pt(u,{assistantID:n,turnID:e.turnID,status:`error`,error:e.text||`upstream_error`,occurredAt:s})));if(u=Ft(u,d),l){let t=u.filter(e=>{if(e.assistantID!==n||e.status!==`admitted`&&e.status!==`streaming`||r.has(e.turnID)||c&&e.turnID===c.turnID)return!0;let t=o.get(e.turnID);return typeof t==`number`&&a!=null&&a<t?!0:typeof t==`number`&&a!=null&&a>=t&&e.turnID!==c?.turnID?!1:!c||e.turnID===c.turnID});return t.length===e.length&&t.every((t,n)=>t===e[n])?e:t}if(a==null)return u.length===e.length&&u.every((t,n)=>t===e[n])?e:u;let f=u.filter(e=>{if(e.assistantID!==n||e.status!==`admitted`&&e.status!==`streaming`||r.has(e.turnID))return!0;if(i.has(e.turnID))return!1;let t=o.get(e.turnID);return typeof t==`number`&&a<t});return f.length===e.length&&f.every((t,n)=>t===e[n])?e:f.length===u.length?u:f},Nt=(e,t)=>At(e,t.assistantID,t.turnID,t.occurredAt).map(e=>{if(e.assistantID!==t.assistantID||e.turnID!==t.turnID||e.status===`failed`||e.status===`complete`)return e;let n=e.bubbles.find(e=>e.bubbleIndex===t.bubbleIndex);if(n?.done)return e;let r=n?{...n,text:`${n.text}${t.delta}`,done:t.done,occurredAt:t.occurredAt}:{bubbleIndex:t.bubbleIndex,text:t.delta,done:t.done,occurredAt:t.occurredAt},i=n?e.bubbles.map(e=>e.bubbleIndex===t.bubbleIndex?r:e):[...e.bubbles,r].sort((e,t)=>e.bubbleIndex-t.bubbleIndex);return{...e,status:`streaming`,bubbles:i}}),Pt=(e,t,n={})=>n.requireExisting&&!e.some(e=>e.assistantID===t.assistantID&&e.turnID===t.turnID)?e:At(e,t.assistantID,t.turnID,t.occurredAt).map(e=>e.assistantID!==t.assistantID||e.turnID!==t.turnID||e.status===`complete`||e.status===`failed`?e:{...e,status:t.status===`error`?`failed`:`complete`,...t.error?{error:t.error}:{}}),Ft=(e,t)=>{let n=new Set(t.map(e=>e.turnID).filter(Boolean)),r=t.length>0?t[t.length-1]?.turnID??null:null,i=[...e].reverse().find(e=>e.status===`admitted`||e.status===`streaming`)?.turnID??r,a=new Set(t.flatMap(e=>e.role===`assistant`?[e.turnID]:[])),o=e.filter(e=>e.status===`admitted`||e.status===`streaming`||!(e.status===`complete`&&a.has(e.turnID)||!n.has(e.turnID)||e.status===`failed`&&(i&&i!==e.turnID||r&&r!==e.turnID)));return o.length===e.length?e:o},It=(e,t,n)=>e.map(e=>e.messageID===t?{...e,status:`failed`,error:n}:e),Lt=(e,t)=>{if(e instanceof R){if(e.code===`no_provider`)return t.noProvider;if(e.code===`admission_timeout`||e.code===`generate_timeout`)return t.timedOut;if(e.message&&e.message!==e.code)return e.message}return L(e)?t.timedOut:t.sendFailed},Rt=()=>{let e=!1;return{tryAcquire:()=>!e&&(e=!0,!0),release:()=>{e=!1}}},zt=e=>{let t=e.text.trim();if(e.sending||!t&&e.attachments.length===0||!e.gate.tryAcquire())return{ok:!1};let n=[...t?[{type:`text`,text:t}]:[],...e.attachments.map(e=>({type:`file`,mime:e.mime,url:e.url,filename:e.name}))],r=e.createMessageID();return{ok:!0,messageID:r,parts:n,turn:St(e.assistantID,r,n,e.createdAt)}},Bt=e=>e.some(e=>e.status===`sending`),Vt=e=>e.some(e=>e.status===`admitted`||e.status===`streaming`),Ht=[`cursor-pointer rounded-[1.35rem] bg-[var(--surface-elevated)] ring-1 ring-inset ring-[var(--surface-subtle)]`,`px-3.5 py-3 text-left transition-[background-color,box-shadow,transform] duration-200 ease-out motion-reduce:transition-none`,`hover:-translate-y-px hover:bg-interactive-hover/45 hover:shadow-sm active:translate-y-0 motion-reduce:hover:translate-y-0`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]`].join(` `),Ut=`${Ht} w-fit min-w-0 max-w-[min(100%,15rem)]`,Wt=`${Ht} w-fit min-w-0 max-w-[min(100%,20rem)]`;function Gt(e,t){(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),t())}var Kt=e=>{let t=(0,Ze.c)(26),{card:n}=e,{t:r}=k(),i=Te(),a;t[0]===i?a=t[1]:(a=i&&!v(),t[0]=i,t[1]=a);let o=!!a,s=n.name,c=`${n.providerID}/${n.modelID}`,l;t[2]!==n.mode||t[3]!==c?(l=[c,n.mode].filter(Boolean),t[2]=n.mode,t[3]=c,t[4]=l):l=t[4];let u=l,d;t[5]!==n.assistantID||t[6]!==o?(d=()=>{if(o){se.getState().openAssistant(n.assistantID);return}ce(n.assistantID)},t[5]=n.assistantID,t[6]=o,t[7]=d):d=t[7];let f=E(d),p;t[8]===f?p=t[9]:(p=e=>{Gt(e,f)},t[8]=f,t[9]=p);let m=E(p),h;t[10]!==r||t[11]!==s?(h=r(`assistants.contact.card.assistant.aria`,{name:s}),t[10]=r,t[11]=s,t[12]=h):h=t[12];let g;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,$.jsx)(`span`,{className:`relative inline-block size-6 shrink-0 leading-none`,children:(0,$.jsx)(`span`,{className:`flex size-6 items-center justify-center rounded-lg bg-[var(--surface-muted)] text-muted-foreground`,children:(0,$.jsx)(X,{name:`robot-2`,className:`size-3`})})}),t[13]=g):g=t[13];let _;t[14]===s?_=t[15]:(_=(0,$.jsx)(`h3`,{className:`min-w-0 truncate typography-ui-label font-medium text-foreground`,children:s}),t[14]=s,t[15]=_);let y;t[16]===u?y=t[17]:(y=u.length>0?(0,$.jsx)(`p`,{className:`truncate typography-micro text-muted-foreground`,children:u.join(` · `)}):null,t[16]=u,t[17]=y);let b;t[18]!==_||t[19]!==y?(b=(0,$.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[g,(0,$.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-1`,children:[_,y]})]}),t[18]=_,t[19]=y,t[20]=b):b=t[20];let x;return t[21]!==m||t[22]!==f||t[23]!==b||t[24]!==h?(x=(0,$.jsx)(`article`,{className:Ut,role:`button`,tabIndex:0,"aria-label":h,"data-assistant-contact-card":`assistant`,onClick:f,onKeyDown:m,children:b}),t[21]=m,t[22]=f,t[23]=b,t[24]=h,t[25]=x):x=t[25],x},qt=e=>{let t=(0,Ze.c)(25),{card:n}=e,{t:r}=k(),i=n.name,a;t[0]!==n.kind||t[1]!==n.time||t[2]!==n.timezone?(a=[n.kind,n.time,n.timezone].filter(Boolean),t[0]=n.kind,t[1]=n.time,t[2]=n.timezone,t[3]=a):a=t[3];let o=a.join(` `),s;t[4]!==n.prompt||t[5]!==o?(s=o.trim()||(typeof n.prompt==`string`?n.prompt.trim():``),t[4]=n.prompt,t[5]=o,t[6]=s):s=t[6];let c=s,l=E(Jt),u;t[7]===l?u=t[8]:(u=e=>{Gt(e,l)},t[7]=l,t[8]=u);let d=E(u),f;t[9]!==r||t[10]!==i?(f=r(`assistants.contact.card.schedule.aria`,{name:i}),t[9]=r,t[10]=i,t[11]=f):f=t[11];let p;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsx)(`span`,{className:`relative inline-block size-6 shrink-0 leading-none`,children:(0,$.jsx)(`span`,{className:`flex size-6 items-center justify-center rounded-lg bg-[var(--surface-muted)] text-muted-foreground`,children:(0,$.jsx)(X,{name:`calendar`,className:`size-3`})})}),t[12]=p):p=t[12];let m;t[13]===i?m=t[14]:(m=(0,$.jsx)(`h3`,{className:`min-w-0 truncate typography-ui-label font-medium text-foreground`,children:i}),t[13]=i,t[14]=m);let h;t[15]===c?h=t[16]:(h=c?(0,$.jsx)(`p`,{className:`truncate typography-micro text-muted-foreground`,children:c}):null,t[15]=c,t[16]=h);let g;t[17]!==m||t[18]!==h?(g=(0,$.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[p,(0,$.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-1`,children:[m,h]})]}),t[17]=m,t[18]=h,t[19]=g):g=t[19];let _;return t[20]!==d||t[21]!==l||t[22]!==f||t[23]!==g?(_=(0,$.jsx)(`article`,{className:Ut,role:`button`,tabIndex:0,"aria-label":f,"data-assistant-contact-card":`schedule`,onClick:l,onKeyDown:d,children:g}),t[20]=d,t[21]=l,t[22]=f,t[23]=g,t[24]=_):_=t[24],_};function Jt(){y.getState().setActiveMainTab(`schedule`),y.getState().setScheduledTasksDialogOpen(!0)}var Yt=(e,t)=>t===`cancelled`?t:e===`busy`||e===`retry`?e:t===`error`||t===`question`||t===`complete`?t:e===`idle`?`complete`:t===`busy`||t===`retry`||t===`idle`?t:t||`busy`,Xt=e=>e===`cancelled`?`assistants.contact.card.session.status.cancelled`:e===`busy`?`assistants.contact.card.session.status.busy`:e===`retry`?`assistants.contact.card.session.status.retry`:e===`idle`?`assistants.contact.card.session.status.idle`:e===`complete`?`assistants.contact.card.session.status.complete`:e===`error`?`assistants.contact.card.session.status.error`:e===`question`?`assistants.contact.card.session.status.question`:null,Zt=e=>e===`busy`?`bg-[var(--status-info)]/10 text-[var(--status-info)]`:e===`retry`||e===`question`?`bg-[var(--status-warning)]/10 text-[var(--status-warning)]`:e===`error`?`bg-[var(--status-error)]/10 text-[var(--status-error)]`:e===`idle`||e===`complete`?`bg-[var(--status-success)]/10 text-[var(--status-success)]`:`bg-[var(--surface-muted)] text-muted-foreground`,Qt=e=>e.split(/[/\\]/u).filter(Boolean).at(-1)||e,$t=e=>{let t=(0,Ze.c)(35),{card:n}=e,{t:r}=k(),i=Te(),a;t[0]===i?a=t[1]:(a=i&&!v(),t[0]=i,t[1]=a);let o=!!a,s;t[2]===n.sessionID?s=t[3]:(s=e=>e.activeSessions.find(e=>e.id===n.sessionID)??e.archivedSessions.find(e=>e.id===n.sessionID)??null,t[2]=n.sessionID,t[3]=s);let c=re(s),l=W(n.sessionID),u=(typeof c?.title==`string`&&c.title.trim()?c.title.trim():null)||n.title||r(`assistants.contact.card.session.untitled`),d=Yt(l?.type,n.status),f=Xt(d),p=d===`busy`||d===`retry`,m=Qt(typeof c?.directory==`string`&&c.directory.trim()?c.directory.trim():n.directory),h=Fe(c)||n.branch,g=Me(c),_=Re(c),b=ze(_),x=[m,g,h].filter(en),S;t[4]!==n.directory||t[5]!==n.sessionID||t[6]!==o?(S=()=>{let e=He(n.sessionID)?.directory||n.directory;G(n.sessionID,e,{phoneShell:o,switchToChat:!0}),o||y.getState().setActiveMainTab(`chat`)},t[4]=n.directory,t[5]=n.sessionID,t[6]=o,t[7]=S):S=t[7];let C=E(S),w;t[8]===C?w=t[9]:(w=e=>{Gt(e,C)},t[8]=C,t[9]=w);let ee=E(w),T=Wt,D=r(`assistants.contact.card.session.aria`,{title:u}),O;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,$.jsx)(`span`,{className:`flex size-6 items-center justify-center rounded-lg bg-[var(--surface-muted)] text-muted-foreground`,children:(0,$.jsx)(X,{name:`chat-3`,className:`size-3`})}),t[10]=O):O=t[10];let A;t[11]===p?A=t[12]:(A=p?(0,$.jsx)(`span`,{className:`pointer-events-none absolute right-0 bottom-0 size-2.5 translate-x-0.5 translate-y-0.5 rounded-full bg-[var(--status-success)] ring-2 ring-[var(--surface-elevated)]`,"data-assistant-working-dot":``,"aria-hidden":!0}):null,t[11]=p,t[12]=A);let j;t[13]===A?j=t[14]:(j=(0,$.jsxs)(`span`,{className:`relative inline-block size-6 shrink-0 leading-none`,children:[O,A]}),t[13]=A,t[14]=j);let M;t[15]===u?M=t[16]:(M=(0,$.jsx)(`h3`,{className:`min-w-0 flex-1 truncate typography-ui-label font-medium text-foreground`,children:u}),t[15]=u,t[16]=M);let N=f?(0,$.jsx)(`span`,{className:pe(`shrink-0 rounded-full px-1.5 py-0.5 typography-micro leading-none`,Zt(d)),children:r(f)}):null,P;t[17]!==M||t[18]!==N?(P=(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[M,N]}),t[17]=M,t[18]=N,t[19]=P):P=t[19];let F;t[20]===x?F=t[21]:(F=x.length>0?(0,$.jsx)(`p`,{className:`truncate typography-micro text-muted-foreground`,children:x.join(` · `)}):null,t[20]=x,t[21]=F);let I=b||_?.files!==void 0&&_.files>0?(0,$.jsxs)(`p`,{className:`flex flex-wrap items-baseline gap-x-1.5 typography-micro tabular-nums`,children:[_?.additions===void 0?null:(0,$.jsxs)(`span`,{className:`text-[var(--status-success)]`,children:[`+`,_.additions]}),_?.deletions===void 0?null:(0,$.jsxs)(`span`,{className:`text-[var(--status-error)]`,children:[`−`,_.deletions]}),_?.files===void 0?null:(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:_.files===1?r(`assistants.contact.card.session.changes.filesSingle`,{count:_.files}):r(`assistants.contact.card.session.changes.filesPlural`,{count:_.files})})]}):null,L;t[22]!==P||t[23]!==F||t[24]!==I?(L=(0,$.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-1`,children:[P,F,I]}),t[22]=P,t[23]=F,t[24]=I,t[25]=L):L=t[25];let R;t[26]!==j||t[27]!==L?(R=(0,$.jsxs)(`div`,{className:`flex items-start gap-2.5`,children:[j,L]}),t[26]=j,t[27]=L,t[28]=R):R=t[28];let z;return t[29]!==ee||t[30]!==C||t[31]!==R||t[32]!==T||t[33]!==D?(z=(0,$.jsx)(`article`,{className:T,role:`button`,tabIndex:0,"aria-label":D,"data-assistant-contact-card":`session`,onClick:C,onKeyDown:ee,children:R}),t[29]=ee,t[30]=C,t[31]=R,t[32]=T,t[33]=D,t[34]=z):z=t[34],z};function en(e){return!!(e&&e.trim())}var tn=2,nn=1500,rn=e=>({scrollTop:e.scrollTop,scrollHeight:e.scrollHeight,clientHeight:e.clientHeight}),an=e=>e.scrollHeight-e.scrollTop-e.clientHeight,on=e=>an(e)<=tn,sn=(e,t)=>{let n=t instanceof Element?t:t instanceof Node?t.parentElement:null;for(;n&&n!==e;){if(n instanceof HTMLElement&&n.scrollHeight>n.clientHeight+1&&n.scrollTop+n.clientHeight<n.scrollHeight-1)return!0;n=n.parentElement}return!1},cn=e=>e.altKey||e.ctrlKey||e.metaKey?!1:e.key===`ArrowDown`||e.key===`PageDown`||e.key===`End`,ln=({active:e,assistantID:t,contentRevision:n,onLoadEarlier:r})=>{let i=Q.useRef(null),[a,o]=Q.useState(null),[s,c]=Q.useState(null),l=Q.useRef(!0),u=Q.useRef(null),d=Q.useRef(null),f=Q.useRef(null),p=Q.useRef(0),m=Q.useRef(null),h=Q.useRef(null),g=Q.useRef(e);g.current=e;let _=Q.useMemo(()=>e=>{i.current=e,o(t=>t===e?t:e)},[]),v=Q.useMemo(()=>e=>{c(t=>t===e?t:e)},[]),y=E(()=>{let e=i.current;if(!e||!g.current||l.current)return;let t=e.getBoundingClientRect().top,n=Array.from(e.querySelectorAll(`[data-message-id]`)).find(e=>e.getBoundingClientRect().bottom>t);u.current=n?{id:n.dataset.messageId,offset:n.getBoundingClientRect().top-t}:null}),b=E(()=>{let e=i.current,t=u.current;if(!e||!t||!g.current||l.current)return;if(Math.abs(e.scrollTop-p.current)>.5){p.current=e.scrollTop,y();return}let n=Array.from(e.querySelectorAll(`[data-message-id]`)).find(e=>e.dataset.messageId===t.id);if(!n){y();return}let r=n.getBoundingClientRect().top-e.getBoundingClientRect().top-t.offset;Math.abs(r)>.5&&(e.scrollTop+=r),p.current=e.scrollTop}),x=E(()=>{l.current=!1,p.current=i.current?.scrollTop??0,y()}),S=E(()=>{if(!g.current||!l.current)return!1;let e=i.current;if(!e)return!1;let t=rn(e),n=Math.min(p.current,Math.max(0,t.scrollHeight-t.clientHeight));return t.scrollTop<n-.5?(l.current=!1,p.current=t.scrollTop,y(),!1):on(t)?(p.current=t.scrollTop,!1):(e.scrollTop=e.scrollHeight,p.current=e.scrollTop,!0)}),C=E(e=>{h.current={direction:e,expiresAt:performance.now()+nn}}),w=E(()=>{let e=h.current;return e?performance.now()>e.expiresAt?(h.current=null,null):e.direction:null}),T=E(()=>{l.current=!1,y()}),O=E(()=>{if(!g.current)return;let e=i.current;if(!e)return;let t=rn(e),n=t.scrollTop>p.current,a=Math.min(p.current,Math.max(0,t.scrollHeight-t.clientHeight));if(p.current=t.scrollTop,l.current){t.scrollTop<a-.5&&T();return}let o=w();y(),t.scrollTop<=80&&o===`up`&&r?.(),n&&on(t)&&(o===`down`||o===`scrollbar`)&&(l.current=!0)}),k=E(e=>{let t=i.current;if(!(!t||e.deltaY===0)){if(e.deltaY<0){if(Ie(t,e.target))return;C(`up`),T(),t.scrollTop<=80&&r?.();return}sn(t,e.target)||C(`down`)}}),A=E(e=>{h.current=null;let t=e.touches.item(0);m.current=t?{x:t.clientX,y:t.clientY,deltaX:0,deltaY:0}:null}),j=E(e=>{let t=i.current,n=e.touches.item(0);if(!t||!n){m.current=null;return}let a=m.current;if(!a)return;let o=n.clientY-a.y,s=o*a.deltaY<0,c=(s?0:a.deltaX)+n.clientX-a.x,l=(s?0:a.deltaY)+o;if(m.current={x:n.clientX,y:n.clientY,deltaX:c,deltaY:l},!(Math.abs(c)>=Math.abs(l))){if(l>0&&Ie(t,e.target)||l<0&&sn(t,e.target)){m.current.deltaX=0,m.current.deltaY=0;return}C(l>0?`up`:`down`),l>2&&(T(),t.scrollTop<=80&&r?.())}}),M=E(()=>{m.current=null}),N=E(e=>{if(Oe(e)){C(`up`),T(),(i.current?.scrollTop??1/0)<=80&&r?.();return}cn(e)&&C(`down`)}),P=E(e=>{let t=i.current;e.pointerType===`mouse`&&e.target===t&&C(`scrollbar`)});Q.useLayoutEffect(()=>{let n=e?t:null,r=i.current;(d.current!==n||f.current!==r)&&(d.current=n,f.current=r,l.current=!0,u.current=null,h.current=null,m.current=null,p.current=r?.scrollTop??0),e&&(S(),b())},[e,t,n,a]);let F=Q.useMemo(()=>()=>void 0,[]),I=e&&a?a:F,L=Q.useMemo(()=>({passive:!0}),[]);D(`scroll`,O,I,L),D(`wheel`,k,I,L),D(`touchstart`,A,I,L),D(`touchmove`,j,I,L),D(`touchend`,M,I,L),D(`touchcancel`,M,I,L),D(`keydown`,N,I),D(`pointerdown`,P,I,L);let R=E(()=>{S(),b()});return ee(typeof ResizeObserver<`u`&&e?s:null,R),{scrollRef:_,contentRef:v,preparePrepend:x}},un=64,dn=e=>{if(!e)return[];let t=Array.from(e.files||[]);return t.length>0?t:Array.from(e.items||[]).filter(e=>e.kind===`file`).map(e=>e.getAsFile()).filter(e=>e instanceof File)},fn=e=>Array.from(e?.files||[]),pn=async(e,t=d)=>{let n=[],r=0;for(let i of Array.from(e||[])){if(!i||i.size<=0)continue;if(i.size>26214400){r+=1;continue}let e=URL.createObjectURL(i);n.push({id:t(),url:e,name:i.name.trim()||`attachment`,mime:i.type.trim()||`application/octet-stream`,file:i})}return{attachments:n,skippedTooLarge:r}},mn=(e,t)=>{let n=[...e,...t];for(let e of n.slice(un))e.url.startsWith(`blob:`)&&URL.revokeObjectURL(e.url);return n.slice(0,un)},hn=be(()=>b(()=>import(`./ToolOutputDialog-BQ_oXyS_.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53]))),gn=e=>e.trim().startsWith(`oc.settle.`),_n=({assistant:e,warning:t,active:n,overlayHeader:r=!1})=>{let{t:i}=k(),a=Ce(),o=y(e=>e.isMobile),s=I(),c=ne(),l=N(e.id,n),u=y(e=>e.isSettingsDialogOpen),f=n&&!u&&!l.hasMessageGap?M(e,l.data):null,p=A(e.name),m=p.displayName||e.name,h=(e,t)=>{let n=e?c.data?.assistants.find(t=>t.id===e):void 0;return n?A(n.name).displayName||n.name:t||i(`assistants.contact.peer.unknown`)},[g,_]=Q.useState(``),[v,b]=Q.useState([]),x=Q.useRef(null),S=Q.useRef(new Map),C=Q.useRef(new AbortController);Q.useEffect(()=>{let e=new AbortController;return C.current=e,()=>e.abort()},[e.id,a]);let w=Q.useRef(new Set);Q.useEffect(()=>{let e=new Set(v.map(e=>e.url));for(let t of w.current)e.has(t)||URL.revokeObjectURL(t);w.current=e},[v]),Q.useEffect(()=>()=>{for(let e of w.current)URL.revokeObjectURL(e)},[]);let[ee,T]=Q.useState([]),[D,O]=Q.useState([]),[P,L]=Q.useState(null),[z,V]=Q.useState({open:!1,title:``,content:``}),H=y(e=>e.setImagePreviewOpen),U=E(e=>{(e.image||e.mermaid)&&(V(e),H(!0))}),re=E(e=>{V(t=>({...t,open:e})),H(e)});Q.useEffect(()=>()=>{H(!1)},[H]);let ie=Q.useRef(!1);Q.useEffect(()=>{S.current.clear(),x.current=null,T([]),O([]),L(null)},[a]);let oe=Q.useMemo(()=>Rt(),[]),W=Q.useRef(new Set),se=Q.useRef(new Map),G=tt(e=>e.setWorking),K=l.data?.messages??bt,ce=Ct(ee,e.id),le=wt(D,e.id),q=Dt(K,ce,e.id,le).filter(e=>{let t=Array.isArray(e.parts)?e.parts:[];return t.length===0||t.some(e=>!(e.type===`text`&&gn(e.text)))}),J=Bt(ce),ue=Vt(le),Y=!!(e.working||e.activeContactTurn),de=c.data?.revision??null,fe=le.reduce((e,t)=>e+t.bubbles.reduce((e,t)=>e+t.text.length,0),0),me=new Map(le.map(e=>[e.turnID,e])),he=Q.useRef(!1),ge=E(async(e=!1)=>{if(!(!n||he.current||l.isFetchingPreviousPage||l.isFillingMessageGap)&&!(e&&l.previousPageError)&&!(!l.hasPreviousPage&&!l.hasMessageGap)){he.current=!0,ye();try{l.hasMessageGap?await l.retryMessageGap():await l.fetchPreviousPage()}catch{}finally{he.current=!1}}}),{scrollRef:_e,contentRef:ve,preparePrepend:ye}=ln({active:n,assistantID:e.id,contentRevision:`${q[0]?.messageID}:${q.length}:${fe}:${l.isFetchingPreviousPage}:${l.hasPreviousPage}:${l.isFillingMessageGap}`,onLoadEarlier:()=>{ge(!0)}});Q.useEffect(()=>{L(null),W.current.clear(),se.current=new Map,T(t=>Ct(t,e.id)),O(t=>wt(t,e.id)),V({open:!1,title:``,content:``}),H(!1)},[e.id,H]),Q.useEffect(()=>{T(e=>Ot(e,K))},[K]),Q.useEffect(()=>{let t=new Set(ce.filter(e=>e.status===`sending`).map(e=>e.messageID));O(n=>Mt(n,{assistantID:e.id,activeContactTurn:e.activeContactTurn?{turnID:e.activeContactTurn.turnID,admittedAt:e.activeContactTurn.admittedAt}:null,serverWorking:Y,snapshotRevision:de,admissionRevisionByTurnID:se.current,pendingSendTurnIDs:t,messages:K,settledTurnIDs:W.current}))},[e.activeContactTurn,e.id,K,ce,Y,de]),Q.useEffect(()=>{G(e.id,J||ue||Y)},[e.id,ue,J,Y,G]),Q.useEffect(()=>{let t=e.id;return()=>{G(t,!1)}},[e.id,G]);let be=E(t=>{if(!(!(`assistantID`in t)||t.assistantID!==e.id)){if(t.type===`contact-turn-start`){W.current.delete(t.turnID),O(e=>At(e,t.assistantID,t.turnID,t.occurredAt));return}if(t.type===`contact-bubble-delta`){if(W.current.has(t.turnID))return;O(e=>Nt(e,t));return}t.type===`contact-turn-end`&&(W.current.add(t.turnID),O(e=>Ft(Pt(e,t,{requireExisting:!0}),K)))}});Q.useEffect(()=>{if(n)return ae(be)},[n,e.id]);let Se=E(async e=>{if(J)return;let t=C.current,n=await pn(e);if(t.signal.aborted){n.attachments.forEach(e=>URL.revokeObjectURL(e.url));return}n.skippedTooLarge>0&&L(i(`assistants.contact.attachment.tooLarge`)),n.attachments.length!==0&&b(e=>mn(e,n.attachments))}),we=E(e=>{let t=dn(e.clipboardData);t.length!==0&&(e.preventDefault(),Se(t))}),Te=E(e=>{Array.from(e.dataTransfer?.types??[]).includes(`Files`)&&(e.preventDefault(),e.dataTransfer.dropEffect=`copy`)}),Ee=E(e=>{let t=fn(e.dataTransfer);t.length!==0&&(e.preventDefault(),Se(t))}),De=E(async()=>{let t=C.current,n=g,r=v,a=e.id,o=x.current,c=o?.assistantID===a&&o.text===n&&o.attachments===r?o.messageID:null,l=zt({gate:oe,sending:Bt(ce),text:n,attachments:r,assistantID:a,createMessageID:()=>c||`oc_contact_${d()}`});if(!l.ok)return;x.current={assistantID:a,text:n,attachments:r,messageID:l.messageID},T(e=>[...e.filter(e=>e.messageID!==l.messageID),l.turn]),L(null);let u=()=>{_(e=>e===n?``:e),b(e=>e.filter(e=>!r.includes(e))),r.forEach(e=>S.current.delete(`${a}:${e.id}`)),x.current=null};try{let e=[];for(let n of r){let r=`${a}:${n.id}`,i=S.current.get(r);if(!i){if(i=await Je(a,n.file,n.id,t.signal),t.signal.aborted)return;S.current.set(r,i)}e.push(i)}if(t.signal.aborted)return;let n=[...l.parts.filter(e=>e.type===`text`),...e];T(e=>e.map(e=>e.messageID===l.messageID?{...e,parts:n}:e));let i=await F(a,l.messageID,{parts:n});if(t.signal.aborted)return;u(),typeof i.revision==`number`&&se.current.set(l.messageID,i.revision),T(e=>kt(e,l.messageID)),W.current.has(l.messageID)||O(e=>At(e,a,l.messageID)),s.data?.serverInstanceID&&j({serverInstanceID:s.data.serverInstanceID,assistantID:a,name:m,avatarSeed:a,...p.avatarEmoji?{avatarEmoji:p.avatarEmoji}:{}}).catch(()=>void 0)}catch(e){if(t.signal.aborted)return;if(e instanceof R&&e.code===`admission_timeout`)try{let e=await B(a,l.messageID);if(t.signal.aborted)return;if(e){u(),typeof e.revision==`number`&&se.current.set(l.messageID,e.revision),T(e=>kt(e,l.messageID)),W.current.has(l.messageID)||O(e=>At(e,a,l.messageID));return}}catch{}let n=Lt(e,{noProvider:i(`assistants.contact.noProvider`),sendFailed:i(`assistants.contact.sendFailed`),timedOut:i(`assistants.contact.timedOut`)});T(e=>It(e,l.messageID,n)),L(n)}finally{oe.release()}}),Oe=E(async()=>{if(ie.current)return;ie.current=!0;let t=C.current;L(null);try{await te(e.id,e)}catch(e){t.signal.aborted||L(e instanceof Error?e.message:i(`settings.mcp.page.toast.unexpectedError`))}finally{ie.current=!1}}),ke=l.isError&&q.length===0,Ae=l.isSuccess&&q.length===0,je=new Map(ce.map(e=>[e.messageID,e]));return(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col bg-background`,children:[(0,$.jsxs)(`div`,{ref:_e,className:pe(`min-h-0 flex-1 overflow-x-hidden overflow-y-auto px-4 pb-9 sm:px-8 sm:pb-12`,r?`pt-[calc(max(0.625rem,var(--oc-safe-area-top,0px))+var(--oc-mobile-detail-navigation-height)+1.25rem)]`:`pt-5 sm:pt-7`),style:{overflowAnchor:`none`,overscrollBehavior:`contain`,overscrollBehaviorY:`contain`},"data-assistant-contact-transcript":``,children:[t?(0,$.jsx)(`p`,{className:`mb-3 typography-micro text-[var(--status-warning)]`,children:t}):null,ke?(0,$.jsxs)(`div`,{ref:ve,className:`mx-auto flex h-full min-h-56 max-w-xs flex-col items-center justify-center pb-16 text-center`,"data-assistant-contact-error":``,children:[(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(et,{name:e.id,emoji:p.avatarEmoji,size:44,label:m}),(0,$.jsx)(`span`,{"aria-hidden":!0,className:`absolute -right-1 -bottom-1 flex size-5 items-center justify-center rounded-full bg-[var(--surface-elevated)] text-[var(--status-error)] ring-2 ring-background`,children:(0,$.jsx)(X,{name:`error-warning`,className:`size-3`})})]}),(0,$.jsx)(`p`,{className:`mt-4 typography-ui-label font-medium text-foreground`,children:m}),(0,$.jsx)(`p`,{className:`mt-1.5 typography-ui leading-6 text-muted-foreground`,children:i(`assistants.contact.loadFailed`)}),(0,$.jsx)(Z,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>void l.refetch(),children:i(`chat.history.retry`)})]}):Ae?(0,$.jsxs)(`div`,{ref:ve,className:`mx-auto flex h-full min-h-56 max-w-sm flex-col items-center justify-center pb-16 text-center`,"data-assistant-contact-empty":``,children:[(0,$.jsx)(et,{name:e.id,emoji:p.avatarEmoji,size:48,label:m,className:`opacity-90`}),(0,$.jsx)(`p`,{className:`mt-5 typography-ui-header font-medium tracking-[-0.01em] text-foreground`,children:i(`assistants.conversation.emptyTitle`,{name:m})}),(0,$.jsx)(`p`,{className:`mt-2 max-w-xs typography-ui leading-6 text-muted-foreground/80`,children:i(`assistants.contact.empty`)})]}):(0,$.jsxs)(`div`,{ref:ve,className:`mx-auto flex w-full max-w-[42rem] flex-col`,children:[l.isPending?(0,$.jsx)(`p`,{role:`status`,className:`py-3 text-center typography-micro text-muted-foreground`,children:i(`common.loading`)}):null,l.hasPreviousPage||l.hasMessageGap?(0,$.jsxs)(`div`,{className:`mb-3 flex flex-col items-center gap-1`,"data-assistant-contact-pagination":``,"aria-busy":l.isFetchingPreviousPage||l.isFillingMessageGap,children:[l.previousPageError?(0,$.jsx)(`p`,{role:`alert`,className:`typography-micro text-[var(--status-error)]`,children:i(`chat.history.loadOlderFailed`)}):null,l.hasMessageGap?(0,$.jsx)(`p`,{role:`status`,className:`typography-micro text-muted-foreground`,children:i(`assistants.contact.history.gap`)}):null,(0,$.jsx)(Z,{type:`button`,size:`sm`,variant:`ghost`,disabled:l.isFetchingPreviousPage||l.isFillingMessageGap,onClick:()=>void ge(),children:i(l.isFetchingPreviousPage||l.isFillingMessageGap?`chat.history.loadingMore`:l.previousPageError||l.hasMessageGap?`chat.history.retry`:`chat.history.loadOlder`)})]}):null,q.map((t,n)=>{let r=n>0?q[n-1]:null,o=t.role===`user`,s=t.role===`peer`,l=t.role===`assistant`&&r?.role===`assistant`&&r.turnID===t.turnID,u=r?.turnID!==t.turnID,d=!o&&(s||!l),p=s?h(t.fromAssistantID,t.fromAssistantName):m,g=s&&t.fromAssistantID?c.data?.assistants.find(e=>e.id===t.fromAssistantID):e,_=g?A(g.name):null,v=je.get(t.messageID),y=me.get(t.turnID),b=t.status===`admitted`&&t.messageID.endsWith(`:preview:admitted`),x=t.status===`failed`&&t.messageID.endsWith(`:preview:failed`);return t.status===`error`||x?(0,$.jsxs)(`div`,{"data-message-id":t.messageID,"data-assistant-contact-error":``,className:`mt-3 px-1`,children:[(0,$.jsx)(`p`,{role:`alert`,className:`whitespace-pre-wrap typography-micro text-[var(--status-error)] [overflow-wrap:anywhere]`,children:t.text||y?.error||i(`assistants.contact.sendFailed`)}),f?.messageID===t.messageID?(0,$.jsx)(it,{assistantID:e.id,position:f},`${a}:${e.id}:${f.generation}:${f.ordinal}`):null]},t.messageID):(0,$.jsxs)(`div`,{"data-message-id":t.messageID,className:pe(`flex w-full`,o?`justify-end`:`justify-start`,u?`mt-6 first:mt-0`:l?`mt-1.5`:`mt-3`),"data-assistant-contact-role":t.role,"data-assistant-contact-turn-status":v?.status??t.status,"data-assistant-contact-run-start":t.role===`assistant`&&!l?``:void 0,children:[o?null:(0,$.jsx)(`div`,{className:`mr-2.5 flex w-8 shrink-0 justify-center pt-0.5`,children:d?(0,$.jsx)(et,{name:g?.id||t.fromAssistantID||e.id,emoji:_?.avatarEmoji,size:28,label:p}):(0,$.jsx)(`span`,{className:`size-7`,"aria-hidden":!0})}),(0,$.jsxs)(`div`,{className:pe(`flex min-w-0 flex-col gap-1.5`,o?`max-w-[min(82%,30rem)] items-end`:`max-w-[min(84%,34rem)] items-start`),children:[s?(0,$.jsx)(`span`,{className:`mb-0.5 px-1 typography-micro text-muted-foreground/75`,children:i(`assistants.contact.peer.from`,{name:p})}):null,b?(0,$.jsxs)(`div`,{role:`status`,"aria-label":i(`assistants.contact.processing`),className:`inline-flex w-fit items-center gap-1 rounded-full bg-[var(--surface-muted)] px-3.5 py-2.5 text-muted-foreground/70`,"data-assistant-contact-processing":``,children:[(0,$.jsx)(`span`,{"aria-hidden":!0,className:`size-1.5 animate-pulse rounded-full bg-current [animation-delay:-0.45s] [animation-duration:1.4s] motion-reduce:animate-none`}),(0,$.jsx)(`span`,{"aria-hidden":!0,className:`size-1.5 animate-pulse rounded-full bg-current [animation-delay:-0.22s] [animation-duration:1.4s] motion-reduce:animate-none`}),(0,$.jsx)(`span`,{"aria-hidden":!0,className:`size-1.5 animate-pulse rounded-full bg-current [animation-duration:1.4s] motion-reduce:animate-none`})]}):null,t.parts.map((n,r)=>{if(n.type===`card`&&n.cardType===`session`)return(0,$.jsx)($t,{card:n},`${t.messageID}:card:${r}`);if(n.type===`card`&&n.cardType===`assistant`)return(0,$.jsx)(Kt,{card:n},`${t.messageID}:card:${r}`);if(n.type===`card`&&n.cardType===`schedule`)return(0,$.jsx)(qt,{card:n},`${t.messageID}:card:${r}`);if(n.type===`file`)return(0,$.jsx)(yt,{assistantID:e.id,part:n,onShowPopup:U},`${t.messageID}:file:${r}`);if(n.type===`text`&&gn(n.text))return null;if(n.type===`text`&&(n.text.trim()||t.status===`streaming`)){let e=!o;return(0,$.jsxs)(`div`,{"aria-label":s?i(`assistants.contact.peer.aria`,{name:p}):void 0,"data-assistant-contact-text":``,className:pe(`min-w-0 max-w-full [overflow-wrap:anywhere] rounded-[1.35rem] px-4 py-2.5 typography-markdown leading-6`,e?null:`whitespace-pre-wrap`,o?`rounded-[1.15rem] rounded-br-lg bg-[var(--primary-base)]/90 text-[var(--primary-foreground)]`:s?`rounded-[1.25rem] border border-dashed border-border/50 bg-[var(--surface-muted)]/70 text-foreground`:pe(`bg-[var(--surface-muted)] text-foreground`,l&&`rounded-tl-lg`)),children:[e?(0,$.jsx)(xe,{content:n.text,messageId:t.messageID,isAnimated:!1,isStreaming:t.status===`streaming`,variant:`assistant`,enableFileReferences:!1,onShowPopup:U,className:`w-full min-w-0 [overflow-wrap:anywhere]`}):n.text,t.status===`streaming`&&r===t.parts.length-1?(0,$.jsx)(`span`,{"aria-hidden":!0,className:`ml-0.5 inline-block h-[1em] w-px translate-y-[0.12em] animate-pulse bg-current opacity-45 [animation-duration:1.1s] motion-reduce:animate-none`,"data-assistant-contact-streaming-caret":``}):null]},`${t.messageID}:text:${r}`)}return null}),v?.status===`sending`?(0,$.jsx)(`p`,{className:`px-1 typography-micro text-muted-foreground/75`,children:i(`assistants.contact.sending`)}):null,v?.status===`failed`?(0,$.jsx)(`p`,{className:`px-1 typography-micro text-[var(--status-error)]`,children:v.error||i(`assistants.contact.sendFailed`)}):null,f?.messageID===t.messageID?(0,$.jsx)(it,{assistantID:e.id,position:f},`${a}:${e.id}:${f.generation}:${f.ordinal}`):null]})]},t.messageID)})]})]}),(0,$.jsxs)(`footer`,{className:`relative z-10 shrink-0 bg-background pt-1`,"data-assistant-contact-composer":``,children:[P?(0,$.jsxs)(`div`,{className:`chat-input-column mb-2 flex items-center gap-2`,children:[(0,$.jsx)(`p`,{role:`alert`,className:`typography-micro text-[var(--status-error)]`,children:P}),x.current?(0,$.jsx)(Z,{type:`button`,size:`sm`,variant:`ghost`,disabled:J,onClick:()=>void De(),children:i(`chat.history.retry`)}):null]}):null,(0,$.jsx)(`form`,{className:pe(`relative w-full pt-1.5 pb-4`,o&&`bottom-safe-area oc-mobile-composer`),onSubmit:e=>{e.preventDefault(),De()},onDragOver:Te,onDrop:Ee,children:(0,$.jsx)(`div`,{className:`chat-input-column relative overflow-visible`,children:(0,$.jsx)(pt,{active:n,layout:`inline`,value:g,attachments:v,pending:J,working:ue||Y,onStop:ue||Y?()=>{Oe()}:void 0,stopLabel:i(`chat.chatInput.actions.stopGeneratingAria`),isMobile:o,placeholder:i(`assistants.contact.placeholder`,{name:m}),sendLabel:i(`assistants.contact.send`),addFilesLabel:i(`assistants.contact.addFiles`),removeAttachmentLabel:i(`assistants.contact.removeAttachment`),fileAccept:`*/*`,onChange:e=>_(e),onSubmit:()=>{De()},onAddFiles:e=>{Se(e)},onRemoveAttachment:t=>{J||(S.current.delete(`${e.id}:${t}`),x.current=null,b(e=>e.filter(e=>e.id!==t)))},onPaste:we,onDragOver:Te,onDrop:Ee,className:pe(`relative z-10`,o&&`oc-mobile-composer-surface`),style:{borderRadius:`1.5rem`},"data-assistant-contact-composer-surface":``,textareaProps:{"aria-label":i(`assistants.contact.placeholder`,{name:m})}},`${a}:${e.id}`)})})]}),z.open?(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(hn,{popup:z,onOpenChange:re,isMobile:o})}):null]})};async function vn(e){await P(e);let t=K.getState().defaultShareAssistant;if(t?.assistantID!==e.id)return;let n=await V();n.serverInstanceID&&t.serverInstanceID===n.serverInstanceID&&K.getState().setDefaultShareAssistant(null)}function yn({assistant:e,open:t,onOpenChange:n,onDeleted:r}){let{t:i}=k(),[a,o]=Q.useState(!1),s=e?A(e.name).displayName||e.name:``,c=E(e=>{a&&!e||n(e)}),l=E(()=>{a||n(!1)}),u=E(async()=>{if(!(!e||a)){o(!0);try{await vn(e),r?.(e.id),n(!1),C.success(i(`assistants.settings.toast.deleted`))}catch{C.error(i(`assistants.settings.toast.deleteFailed`))}finally{o(!1)}}});return(0,$.jsx)(fe,{open:t&&e!==null,onOpenChange:c,children:(0,$.jsxs)(ue,{className:`max-w-md`,children:[(0,$.jsxs)(q,{children:[(0,$.jsx)(Y,{children:i(`assistants.settings.delete`)}),(0,$.jsx)(de,{children:i(`assistants.settings.deleteConfirm`,{name:s})})]}),(0,$.jsxs)(J,{children:[(0,$.jsx)(Z,{size:`sm`,variant:`ghost`,onClick:l,disabled:a,children:i(`settings.common.actions.cancel`)}),(0,$.jsx)(Z,{size:`sm`,variant:`destructive`,onClick:u,disabled:a,children:i(`settings.common.actions.delete`)})]})]})})}var bn=`line-clamp-2 min-w-0 max-w-full overflow-clip whitespace-normal [overflow-wrap:anywhere] typography-micro text-muted-foreground`,xn={image:`assistants.contact.attachment.image`,file:`assistants.contact.attachment.file`,session:`assistants.contact.card.session.untitled`,assistant:`assistants.title`,schedule:`assistants.settings.scheduledTasks.title`};function Sn(e,t){return e?.text.replace(/\s+/gu,` `).trim()||t(e?.fallbackKind?xn[e.fallbackKind]:`assistants.contact.empty`)}var Cn=e=>e.capabilityPending?`loading`:e.capabilityError||e.supported!==!0||e.capabilityEnabled!==!0?`unavailable`:e.snapshotPending?`loading`:e.snapshotEnabled===!0?e.assistantCount===0?`onboarding`:e.hasAssistant?`ready`:e.snapshotSettled?`unavailable`:`loading`:`unavailable`,wn=t({AssistantView:()=>Dn}),Tn=e=>{let t=(0,Ze.c)(22),{assistant:n,onBack:r,onOpenSettings:i}=e,{t:a}=k(),o=Te(),s;t[0]===n?s=t[1]:(s=n?A(n.name):null,t[0]=n,t[1]=s);let c=s,l=n&&c?c.displayName||n.name:``,u;t[2]!==n||t[3]!==o||t[4]!==i?(u=()=>{if(n){if(i){i(n.id);return}le(n.id,o?{openMobileSettings:o.openSettings}:void 0)}},t[2]=n,t[3]=o,t[4]=i,t[5]=u):u=t[5];let d=E(u),f;t[6]!==n||t[7]!==l||t[8]!==c?.avatarEmoji||t[9]!==a?(f=n?(0,$.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-2.5`,children:[(0,$.jsx)(et,{name:n.id,emoji:c?.avatarEmoji,size:28,label:l}),(0,$.jsx)(`span`,{className:`truncate font-medium tracking-[-0.01em]`,children:l||a(`assistants.title`)})]}):l||a(`assistants.title`),t[6]=n,t[7]=l,t[8]=c?.avatarEmoji,t[9]=a,t[10]=f):f=t[10];let p;t[11]===a?p=t[12]:(p=a(`assistants.actions.backToChat`),t[11]=a,t[12]=p);let m;t[13]!==n||t[14]!==d||t[15]!==a?(m=n?[{icon:`settings-3`,ariaLabel:a(`assistants.conversation.openSettings`),onClick:d}]:[],t[13]=n,t[14]=d,t[15]=a,t[16]=m):m=t[16];let h;return t[17]!==r||t[18]!==f||t[19]!==p||t[20]!==m?(h=(0,$.jsx)(H,{title:f,backAriaLabel:p,onBack:r,actions:m,overlay:!0}),t[17]=r,t[18]=f,t[19]=p,t[20]=m,t[21]=h):h=t[21],h},En=e=>{let t=(0,Ze.c)(50),{unreadCount:n,summary:r,assistantID:i,displayName:a,avatarEmoji:o,selected:s,enabled:c,editLabel:l,deleteLabel:u,onSelect:d,onEdit:f,onDelete:p,serverWorking:m}=e,h=rt(i,m!==void 0&&m),[g,_]=Q.useState(!1),v;t[0]===d?v=t[1]:(v=()=>d(),t[0]=d,t[1]=v);let y=E(v),b;t[2]===f?b=t[3]:(b=()=>{_(!1),f()},t[2]=f,t[3]=b);let x=E(b),S;t[4]===p?S=t[5]:(S=()=>{_(!1),p()},t[4]=p,t[5]=S);let C=E(S),w;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(w=e=>{e.preventDefault(),_(!0)},t[6]=w):w=t[6];let ee=s?`border-border/50 bg-[var(--surface-elevated)]`:`border-transparent hover:bg-interactive-hover`,T=!c&&`opacity-65`,D;t[7]!==ee||t[8]!==T?(D=pe(`flex w-full min-h-11 items-center gap-3 rounded-xl border px-3 py-3 text-left outline-none transition-[background-color,border-color,opacity] duration-150 ease-out active:bg-interactive-active focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] motion-reduce:transition-none`,ee,T),t[7]=ee,t[8]=T,t[9]=D):D=t[9];let O;t[10]!==y||t[11]!==s||t[12]!==D?(O=(0,$.jsx)(`button`,{type:`button`,role:`option`,"aria-selected":s,onClick:y,onContextMenu:w,className:D}),t[10]=y,t[11]=s,t[12]=D,t[13]=O):O=t[13];let k;t[14]!==i||t[15]!==o||t[16]!==a||t[17]!==h?(k=(0,$.jsx)(et,{name:i,emoji:o,size:24,label:a,working:h}),t[14]=i,t[15]=o,t[16]=a,t[17]=h,t[18]=k):k=t[18];let A;t[19]===a?A=t[20]:(A=(0,$.jsx)(`span`,{className:`block truncate typography-ui-label font-medium`,children:a}),t[19]=a,t[20]=A);let j;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(j=pe(bn,`mt-1.5`),t[21]=j):j=t[21];let M;t[22]===r?M=t[23]:(M=(0,$.jsx)(`span`,{className:j,children:r}),t[22]=r,t[23]=M);let N;t[24]!==A||t[25]!==M?(N=(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[A,M]}),t[24]=A,t[25]=M,t[26]=N):N=t[26];let P;t[27]===n?P=t[28]:(P=(0,$.jsx)(Ve,{count:n}),t[27]=n,t[28]=P);let F;t[29]!==k||t[30]!==N||t[31]!==P||t[32]!==O?(F=(0,$.jsxs)(Ue,{render:O,children:[k,N,P]}),t[29]=k,t[30]=N,t[31]=P,t[32]=O,t[33]=F):F=t[33];let I;t[34]===Symbol.for(`react.memo_cache_sentinel`)?(I=(0,$.jsx)(X,{name:`edit`,className:`size-4`}),t[34]=I):I=t[34];let L;t[35]!==l||t[36]!==x?(L=(0,$.jsxs)(Ke,{onClick:x,children:[I,l]}),t[35]=l,t[36]=x,t[37]=L):L=t[37];let R;t[38]===Symbol.for(`react.memo_cache_sentinel`)?(R=(0,$.jsx)(We,{}),t[38]=R):R=t[38];let z;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(z=(0,$.jsx)(X,{name:`delete-bin`,className:`size-4`}),t[39]=z):z=t[39];let te;t[40]!==u||t[41]!==C?(te=(0,$.jsxs)(Ke,{onClick:C,className:`text-[var(--status-error)] focus:text-[var(--status-error)] data-[highlighted]:text-[var(--status-error)] [&_svg]:text-[var(--status-error)]`,children:[z,u]}),t[40]=u,t[41]=C,t[42]=te):te=t[42];let B;t[43]!==L||t[44]!==te?(B=(0,$.jsxs)(Ge,{className:`min-w-[10rem]`,children:[L,R,te]}),t[43]=L,t[44]=te,t[45]=B):B=t[45];let V;return t[46]!==g||t[47]!==F||t[48]!==B?(V=(0,$.jsxs)(qe,{open:g,onOpenChange:_,children:[F,B]}),t[46]=g,t[47]=F,t[48]=B,t[49]=V):V=t[49],V},Dn=e=>{let t=(0,Ze.c)(118),{activeOverride:i,onMobileBack:a,onMobileOpenSettings:o}=e,{t:s}=k(),{isMobile:c}=he(),l=Te(),u=Q.useSyncExternalStore(n,r,r),d=y(On),f=i??d,p=y(kn),m=c||p,h=I(),g=ne(),_=g.data;_?.assistants;let v;t[0]===_?.assistants?v=t[1]:(v=_?.assistants??[],t[0]=_?.assistants,t[1]=v);let b;t[2]===v?b=t[3]:(b=Qe(v),t[2]=v,t[3]=b);let x=b,S;t[4]===u?S=t[5]:(S=e=>e.assistantByTransport[u]??null,t[4]=u,t[5]=S);let C=K(S),w=K(An),ee=K(jn),T;t[6]!==C||t[7]!==_?.assistants?(T=_?.assistants.find(e=>e.id===C)??null,t[6]=C,t[7]=_?.assistants,t[8]=T):T=t[8];let D=T,O;t[9]!==w||t[10]!==C||t[11]!==_?(O=()=>{!C&&_?.assistants[0]&&w(_.assistants[0].id)},t[9]=w,t[10]=C,t[11]=_,t[12]=O):O=t[12];let j=_?.assistants,M;t[13]!==w||t[14]!==C||t[15]!==j?(M=[w,C,j],t[13]=w,t[14]=C,t[15]=j,t[16]=M):M=t[16],Q.useEffect(O,M);let N;t[17]!==D||t[18]!==w||t[19]!==C||t[20]!==_?.assistants||t[21]!==g.isSuccess?(N=()=>{g.isSuccess&&C&&!D&&w(_?.assistants[0]?.id??null)},t[17]=D,t[18]=w,t[19]=C,t[20]=_?.assistants,t[21]=g.isSuccess,t[22]=N):N=t[22];let P=_?.assistants,F;t[23]!==D||t[24]!==w||t[25]!==C||t[26]!==g.isSuccess||t[27]!==P?(F=[D,w,C,P,g.isSuccess],t[23]=D,t[24]=w,t[25]=C,t[26]=g.isSuccess,t[27]=P,t[28]=F):F=t[28],Q.useEffect(N,F);let L;t[29]!==l||t[30]!==ee?(L=()=>{if(ee(),l){l.openSettings();return}let e=y.getState();e.setSettingsPage(`assistants`),e.setSettingsDialogOpen(!0)},t[29]=l,t[30]=ee,t[31]=L):L=t[31];let R=E(L),z;t[32]===l?z=t[33]:(z=e=>{le(e,l?{openMobileSettings:l.openSettings}:void 0)},t[32]=l,t[33]=z);let te=E(z),B;t[34]!==D||t[35]!==l?(B=()=>{D&&le(D.id,l?{openMobileSettings:l.openSettings}:void 0)},t[34]=D,t[35]=l,t[36]=B):B=t[36];let V=E(B),[H,U]=Q.useState(null),re;t[37]===Symbol.for(`react.memo_cache_sentinel`)?(re=e=>{U(e)},t[37]=re):re=t[37];let ie=E(re),ae;t[38]===Symbol.for(`react.memo_cache_sentinel`)?(ae=e=>{e||U(null)},t[38]=ae):ae=t[38];let oe=E(ae),W=E(Mn),se;t[39]!==a||t[40]!==W?(se=()=>{if(a){a();return}W()},t[39]=a,t[40]=W,t[41]=se):se=t[41];let G=E(se),ce=Cn({capabilityPending:h.isPending,snapshotPending:g.isPending,capabilityError:h.isError,supported:h.data?.supported,capabilityEnabled:h.data?.enabled,snapshotEnabled:_?.enabled,snapshotSettled:g.isSuccess,assistantCount:_?.assistants.length??0,hasAssistant:!!D}),q;t[42]!==D||t[43]!==G||t[44]!==m||t[45]!==o?(q=(e,t,n,r)=>(0,$.jsxs)(`div`,{className:`relative flex h-full min-h-0 flex-col`,children:[m?(0,$.jsx)(Tn,{assistant:D,onBack:G,onOpenSettings:o}):null,(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col items-center justify-center px-6 pt-[calc(max(0.25rem,var(--oc-safe-area-top,0px))+var(--oc-mobile-detail-navigation-height,3.5rem))] text-center`,children:[(0,$.jsx)(X,{name:e,className:`size-6 text-muted-foreground`}),(0,$.jsx)(`h1`,{className:`mt-4 typography-ui-header font-semibold`,children:t}),n?(0,$.jsx)(`p`,{className:`mt-2 max-w-md typography-ui text-muted-foreground`,children:n}):null,r?(0,$.jsx)(`div`,{className:`mt-5`,children:r}):null]})]}),t[42]=D,t[43]=G,t[44]=m,t[45]=o,t[46]=q):q=t[46];let J=q;if(ce===`loading`){let e;t[47]!==D||t[48]!==G||t[49]!==m||t[50]!==o?(e=m?(0,$.jsx)(Tn,{assistant:D,onBack:G,onOpenSettings:o}):null,t[47]=D,t[48]=G,t[49]=m,t[50]=o,t[51]=e):e=t[51];let n;t[52]===s?n=t[53]:(n=s(`common.loading`),t[52]=s,t[53]=n);let r;t[54]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,$.jsx)(X,{name:`loader-4`,className:`size-6 animate-spin text-muted-foreground`}),t[54]=r):r=t[54];let i;t[55]===n?i=t[56]:(i=(0,$.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col items-center justify-center px-6 pt-[calc(max(0.25rem,var(--oc-safe-area-top,0px))+var(--oc-mobile-detail-navigation-height,3.5rem))] text-center`,"aria-busy":`true`,"aria-label":n,"data-assistant-workspace-loading":``,children:r}),t[55]=n,t[56]=i);let a;return t[57]!==e||t[58]!==i?(a=(0,$.jsxs)(`div`,{className:`relative flex h-full min-h-0 flex-col`,children:[e,i]}),t[57]=e,t[58]=i,t[59]=a):a=t[59],a}if(ce===`unavailable`){let e;return t[60]!==J||t[61]!==s?(e=J(`cloud-off`,s(`assistants.state.unavailable`)),t[60]=J,t[61]=s,t[62]=e):e=t[62],e}if(ce===`onboarding`){let e;if(t[63]!==R||t[64]!==J||t[65]!==s){let n=s(`assistants.onboarding.title`),r=s(`assistants.onboarding.description`),i;t[67]===s?i=t[68]:(i=s(`assistants.onboarding.action`),t[67]=s,t[68]=i);let a;t[69]!==R||t[70]!==i?(a=(0,$.jsx)(Z,{onClick:R,children:i}),t[69]=R,t[70]=i,t[71]=a):a=t[71],e=J(`ai-agent`,n,r,a),t[63]=R,t[64]=J,t[65]=s,t[66]=e}else e=t[66];return e}if(!_||!D){let e;return t[72]!==J||t[73]!==s?(e=J(`cloud-off`,s(`assistants.state.unavailable`)),t[72]=J,t[73]=s,t[74]=e):e=t[74],e}let ue;t[75]===D.name?ue=t[76]:(ue=A(D.name),t[75]=D.name,t[76]=ue);let Y=ue,de;t[77]!==D.enabled||t[78]!==g.isError||t[79]!==s?(de=D.enabled?g.isError?s(`assistants.state.staleSnapshot`):null:s(`assistants.state.assistantDisabled`),t[77]=D.enabled,t[78]=g.isError,t[79]=s,t[80]=de):de=t[80];let fe=de,me;t[81]!==x||t[82]!==m||t[83]!==R||t[84]!==te||t[85]!==ie||t[86]!==w||t[87]!==C||t[88]!==_||t[89]!==s?(me=m?null:(0,$.jsxs)(`section`,{className:`flex h-full min-h-0 w-[clamp(16rem,22vw,20rem)] shrink-0 flex-col overflow-hidden`,children:[(0,$.jsxs)(`header`,{className:`flex shrink-0 items-center gap-3 px-4 pb-3 pt-4 sm:px-5`,children:[(0,$.jsx)(`h1`,{className:`min-w-0 flex-1 truncate typography-ui-label font-semibold text-foreground`,children:s(`assistants.title`)}),(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":s(`assistants.settings.create`),onClick:R,children:(0,$.jsx)(X,{name:`add`,className:`size-4`})})]}),(0,$.jsx)($e,{snapshot:_,rowClassName:`flex justify-end px-4 pb-2 sm:px-5`}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-3 pb-4 sm:px-4`,role:`listbox`,"aria-label":s(`assistants.listAria`),children:(0,$.jsx)(`div`,{className:`flex flex-col gap-1 border-t border-border/40 pt-3`,children:x.map(e=>{let t=e.id===C,n=A(e.name);return(0,$.jsx)(En,{assistantID:e.id,unreadCount:e.unreadCount??0,summary:Sn(e.latestMessagePreview,s),displayName:n.displayName,avatarEmoji:n.avatarEmoji??void 0,selected:t,enabled:e.enabled,editLabel:s(`assistants.menu.edit`),deleteLabel:s(`assistants.settings.delete`),assignedSessionIDs:e.assignedSessionIDs,serverWorking:e.working,onSelect:()=>w(e.id),onEdit:()=>te(e.id),onDelete:()=>ie(e)},e.id)})})})]}),t[81]=x,t[82]=m,t[83]=R,t[84]=te,t[85]=ie,t[86]=w,t[87]=C,t[88]=_,t[89]=s,t[90]=me):me=t[90];let ge=H!==null,_e;t[91]!==H||t[92]!==oe||t[93]!==ge?(_e=(0,$.jsx)(yn,{assistant:H,open:ge,onOpenChange:oe}),t[91]=H,t[92]=oe,t[93]=ge,t[94]=_e):_e=t[94];let ve=!m&&`border-l border-[var(--surface-subtle)]`,ye;t[95]===ve?ye=t[96]:(ye=pe(`relative flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden bg-background`,ve),t[95]=ve,t[96]=ye);let be;t[97]!==D||t[98]!==G||t[99]!==m||t[100]!==o||t[101]!==V||t[102]!==Y||t[103]!==s?(be=m?(0,$.jsx)(Tn,{assistant:D,onBack:G,onOpenSettings:o}):(0,$.jsxs)(`header`,{className:`flex h-16 shrink-0 items-center gap-3.5 border-b border-[var(--surface-subtle)]/70 px-5 sm:px-7`,children:[(0,$.jsx)(et,{name:D.id,emoji:Y.avatarEmoji,size:30,label:Y.displayName||D.name}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`div`,{className:`truncate typography-ui-label font-semibold tracking-[-0.01em] text-foreground`,children:Y.displayName}),(0,$.jsx)(`div`,{className:`mt-1 truncate typography-micro leading-none text-muted-foreground/55`,children:s(`assistants.conversation.contactHint`)})]}),(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`icon`,className:`size-8 shrink-0 rounded-full text-muted-foreground/65 transition-colors hover:text-foreground`,onClick:V,"aria-label":s(`assistants.conversation.openSettings`),children:(0,$.jsx)(X,{name:`settings-3`,className:`size-4`})})]}),t[97]=D,t[98]=G,t[99]=m,t[100]=o,t[101]=V,t[102]=Y,t[103]=s,t[104]=be):be=t[104];let xe;t[105]!==f||t[106]!==D||t[107]!==m||t[108]!==fe?(xe=(0,$.jsx)(_n,{assistant:D,warning:fe,active:f,overlayHeader:m}),t[105]=f,t[106]=D,t[107]=m,t[108]=fe,t[109]=xe):xe=t[109];let Se;t[110]!==ye||t[111]!==be||t[112]!==xe?(Se=(0,$.jsxs)(`div`,{className:ye,children:[be,xe]}),t[110]=ye,t[111]=be,t[112]=xe,t[113]=Se):Se=t[113];let Ce;return t[114]!==me||t[115]!==_e||t[116]!==Se?(Ce=(0,$.jsxs)(`div`,{className:`relative flex h-full min-h-0 overflow-hidden bg-background`,"data-presentation":`workspace`,children:[me,_e,Se]}),t[114]=me,t[115]=_e,t[116]=Se,t[117]=Ce):Ce=t[117],Ce};function On(e){return e.activeMainTab===`assistant`}function kn(e){return e.isMobile}function An(e){return e.selectAssistant}function jn(e){return e.requestCreate}function Mn(){y.getState().setActiveMainTab(`chat`)}export{yn as a,$e as c,Sn as i,Qe as l,wn as n,rt as o,bn as r,et as s,Dn as t};
@@ -1 +0,0 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{i as t}from"./runtime-switch-LvWDU-SL.js";import{nt as n,rt as r}from"./vendor-base-ui-CnHfUmDN.js";import{t as i}from"./useUIStore-CxOoCv7B.js";import{l as a}from"./vendor-tanstack-react-query-D7pys_c9.js";import{r as o}from"./vendor-sonner-DVzioF3d.js";import{n as s}from"./clipboard-GUUNlWIv.js";import{n as c}from"./Icon-D1BcR8Tz.js";import{n as l}from"./useRuntimeAPIs-DSLXJybW.js";import{n as u}from"./useEffectiveDirectory-C5Gg7EvP.js";import{n as d,r as f,t as p}from"./fileQueries-B_s_B-fH.js";import{t as m}from"./diagram-NdsZih8P.js";var h=e(r(),1),g=n();function _(){let{t:e}=s(),{files:n}=l(),r=a(),_=u()??null,v=t(),[y,b]=h.useState(null),[x,S]=h.useState(``),C=h.useRef(null),w=h.useRef(!1),T=h.useRef(null),E=h.useRef(0),D=h.useRef(Promise.resolve()),O=i(e=>e.pendingDiagramFile),k=f({scopeDirectory:_,path:y},{enabled:!!y});if(y&&(T.current?.path!==y||T.current.transport!==v||T.current.scopeDirectory!==_)){let e=E.current+1;E.current=e,T.current={path:y,generation:e,transport:v,scopeDirectory:_}}h.useEffect(()=>(w.current=!0,()=>{w.current=!1,E.current+=1}),[]),h.useEffect(()=>{if(!O)return;let e=i.getState().consumePendingDiagramFile();if(e){let t=E.current+1;E.current=t,T.current={path:e,generation:t,transport:v,scopeDirectory:_},b(e)}},[_,O,v]),h.useEffect(()=>{let e=T.current;if(!(!e||e.path!==y||e.transport!==v||e.scopeDirectory!==_)){if(k.data!==void 0){S(k.data);return}k.isError&&S(``)}},[_,y,k.data,k.isError,v]);let A=h.useCallback(async()=>{let t=C.current?.getXml(),i=T.current,a=n?.writeFile;if(!y||!a||!t||t===x||i?.path!==y)return;let{path:s,generation:c,scopeDirectory:l,transport:u}=i,f=D.current.then(async()=>{try{if(!(await a(s,t))?.success)throw Error(e(`filesView.toast.writeFileFailed`));let n={scopeDirectory:l,path:s};await r.cancelQueries({queryKey:p(n,u),exact:!0}),d(r,n,u,t);let i=T.current;w.current&&i?.path===s&&i.generation===c&&i.transport===u&&i.scopeDirectory===l&&S(t)}catch(t){o.error(t instanceof Error?t.message:e(`filesView.toast.saveFailed`))}});D.current=f.catch(()=>void 0),await f},[y,n,r,e,x]),j=y?y.split(`/`).pop()||y:``;return y?k.isPending?(0,g.jsx)(`div`,{className:`flex h-full items-center justify-center p-3`,children:(0,g.jsx)(c,{name:`loader-4`,className:`size-4 animate-spin`})}):(0,g.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,g.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border/30 px-3 py-1.5`,children:[(0,g.jsx)(c,{name:`file`,className:`size-4 shrink-0 text-muted-foreground`}),(0,g.jsx)(`span`,{className:`typography-ui text-muted-foreground truncate flex-1`,children:j}),(0,g.jsx)(`button`,{type:`button`,onClick:()=>void A(),className:`size-6 flex items-center justify-center rounded-md text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`,title:e(`filesView.diagram.saveDiagram`),children:(0,g.jsx)(c,{name:`save-3`,className:`size-4`})}),(0,g.jsx)(`button`,{type:`button`,onClick:()=>i.getState().setActiveMainTab(`chat`),className:`size-6 flex items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`,title:e(`filesView.diagram.closeDiagramView`),children:(0,g.jsx)(c,{name:`close`,className:`size-4`})})]}),(0,g.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,g.jsx)(m,{ref:C,xml:x,className:`h-full`})})]}):(0,g.jsx)(`div`,{className:`flex h-full items-center justify-center p-3`,children:(0,g.jsx)(`div`,{className:`typography-ui text-muted-foreground`,children:e(`filesView.editor.pickFileFromTree`)})})}export{_ as DiagramView};