@sentry/junior-dashboard 0.280.0 → 0.281.0

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 (81) hide show
  1. package/dist/app.js +23 -30
  2. package/dist/client-manifest.json +1 -1
  3. package/dist/index.js +23 -30
  4. package/dist/public/chunks/{AdminPage-YEKZOKH6.js → AdminPage-M5RBVZFN.js} +1 -1
  5. package/dist/public/chunks/{AutomationPage-5GS3IUAK.js → AutomationPage-WALCREDT.js} +1 -1
  6. package/dist/public/chunks/{AutomationRunsPage-IPYEZU4L.js → AutomationRunsPage-CV47E4UX.js} +1 -1
  7. package/dist/public/chunks/{AutomationsPage-HSAYPC3C.js → AutomationsPage-57L3AQVJ.js} +1 -1
  8. package/dist/public/chunks/{CodePage-IPFKXWFB.js → CodePage-XJUYMFJH.js} +1 -1
  9. package/dist/public/chunks/{ConnectionsPage-5XUEK6FS.js → ConnectionsPage-3QQAGYWF.js} +1 -1
  10. package/dist/public/chunks/{LocationDetailPage-27ETUGR6.js → LocationDetailPage-4IL5HQML.js} +1 -1
  11. package/dist/public/chunks/{LocationsPage-WOKMQAGM.js → LocationsPage-D2DUQAHJ.js} +1 -1
  12. package/dist/public/chunks/{PeoplePage-6YQLDOUL.js → PeoplePage-6F5GPQ7C.js} +1 -1
  13. package/dist/public/chunks/{PersonProfilePage-GYMAZFIK.js → PersonProfilePage-SPAYQPTD.js} +1 -1
  14. package/dist/public/chunks/{PersonalTokensPage-4BCR744B.js → PersonalTokensPage-SHAUJ74M.js} +1 -1
  15. package/dist/public/chunks/{PluginUserPage-IP6WL7MD.js → PluginUserPage-64FIWD7M.js} +1 -1
  16. package/dist/public/chunks/{RepositoryPage-TRD44LQ3.js → RepositoryPage-L7IHOXSN.js} +1 -1
  17. package/dist/public/chunks/{SettingsPage-4E3SLQ36.js → SettingsPage-U7WG4FHE.js} +1 -1
  18. package/dist/public/chunks/{SystemPage-C3XBKXKW.js → SystemPage-ZBC43OJH.js} +1 -1
  19. package/dist/public/chunks/{WorkspaceFormPage-2LS2X67Q.js → WorkspaceFormPage-3NVIIZ4P.js} +1 -1
  20. package/dist/public/chunks/{WorkspacesPage-5WB3CUTX.js → WorkspacesPage-G73HPBDD.js} +1 -1
  21. package/dist/public/chunks/{chunk-VFEBNOPX.js → chunk-2J3LGF5Q.js} +1 -1
  22. package/dist/public/chunks/chunk-2NNKHSZE.js +1 -0
  23. package/dist/public/chunks/chunk-4TQSTCIN.js +13 -0
  24. package/dist/public/chunks/chunk-64GPEGGE.js +1 -0
  25. package/dist/public/chunks/{chunk-WZVO3HG4.js → chunk-6FHY65EQ.js} +1 -1
  26. package/dist/public/chunks/{chunk-YYNMZ4WC.js → chunk-DEEO4D4N.js} +1 -1
  27. package/dist/public/chunks/{chunk-SDKV3OID.js → chunk-FSGVY7HB.js} +1 -1
  28. package/dist/public/chunks/chunk-GZBMHYYU.js +1 -0
  29. package/dist/public/chunks/{chunk-NQMDED2R.js → chunk-II4NXLSQ.js} +1 -1
  30. package/dist/public/chunks/{chunk-B6HGRBBX.js → chunk-ILH47V7O.js} +1 -1
  31. package/dist/public/chunks/{chunk-GRMX2HX6.js → chunk-JPL2NRWK.js} +1 -1
  32. package/dist/public/chunks/{chunk-NQOJAZFQ.js → chunk-JVJ5UWIK.js} +1 -1
  33. package/dist/public/chunks/{chunk-V5UDSIRA.js → chunk-K4TYMAA3.js} +1 -1
  34. package/dist/public/chunks/{chunk-EFEREKX4.js → chunk-KDUTK357.js} +1 -1
  35. package/dist/public/chunks/{chunk-RHIXHBS5.js → chunk-LZYAHJVQ.js} +1 -1
  36. package/dist/public/chunks/{chunk-5GZDBGAR.js → chunk-MKKFXRYO.js} +1 -1
  37. package/dist/public/chunks/{chunk-PEQNT5MO.js → chunk-NGQRNS3C.js} +1 -1
  38. package/dist/public/chunks/{chunk-IA6BJDKN.js → chunk-ONDKE72P.js} +1 -1
  39. package/dist/public/chunks/{chunk-WJ3OXMVX.js → chunk-PG7M7L24.js} +1 -1
  40. package/dist/public/chunks/{chunk-6GQL3EVJ.js → chunk-QQUFROWT.js} +1 -1
  41. package/dist/public/chunks/{chunk-UAH6DWNS.js → chunk-RB5FBDEY.js} +1 -1
  42. package/dist/public/chunks/{chunk-A2QWWA7O.js → chunk-RGXXD4DM.js} +1 -1
  43. package/dist/public/chunks/{chunk-AYXSBMWA.js → chunk-TC7TU4GK.js} +1 -1
  44. package/dist/public/chunks/chunk-WLIOZO3W.js +1 -0
  45. package/dist/public/chunks/{chunk-VXT3FIVL.js → chunk-XDUSY26N.js} +11 -11
  46. package/dist/public/client-4OAAOHF4.js +68 -0
  47. package/dist/tailwind.css +1 -1
  48. package/package.json +4 -4
  49. package/src/client/components/BottomSheet.tsx +1 -1
  50. package/src/client/components/DetailsPanel.tsx +2 -1
  51. package/src/client/conversations/ConversationBrief.tsx +129 -65
  52. package/src/client/conversations/ConversationDetails.tsx +13 -14
  53. package/src/client/conversations/ConversationEventLog.tsx +20 -97
  54. package/src/client/conversations/ConversationHeader.tsx +41 -26
  55. package/src/client/conversations/ConversationHeaderActions.tsx +3 -1
  56. package/src/client/conversations/ConversationLinkedWork.tsx +30 -10
  57. package/src/client/conversations/ConversationMeta.tsx +15 -15
  58. package/src/client/conversations/ConversationPage.tsx +31 -7
  59. package/src/client/conversations/ConversationTranscript.tsx +234 -186
  60. package/src/client/conversations/ConversationUsageBreakdown.tsx +142 -64
  61. package/src/client/conversations/DetailsList.tsx +7 -1
  62. package/src/client/conversations/PendingMailboxStack.tsx +88 -44
  63. package/src/client/conversations/TranscriptActivityGroup.tsx +7 -14
  64. package/src/client/conversations/TranscriptEventView.tsx +7 -3
  65. package/src/client/conversations/TranscriptReasoningView.tsx +4 -2
  66. package/src/client/conversations/TranscriptRows.tsx +37 -5
  67. package/src/client/conversations/TranscriptView.tsx +4 -0
  68. package/src/client/conversations/queries.ts +74 -43
  69. package/src/client/conversations/transcriptBottomPinning.ts +13 -5
  70. package/src/client/conversations/transcriptListRows.ts +215 -0
  71. package/src/client/conversations/virtualRows.ts +168 -0
  72. package/src/client/http.ts +6 -5
  73. package/src/client/sentry.ts +53 -3
  74. package/src/conversation-cache.ts +8 -10
  75. package/src/mock-reporting/fixtures.ts +0 -8
  76. package/dist/public/chunks/chunk-GO45RQDL.js +0 -1
  77. package/dist/public/chunks/chunk-N4AONKD3.js +0 -1
  78. package/dist/public/chunks/chunk-QNA7F7QB.js +0 -1
  79. package/dist/public/chunks/chunk-R4ORRE77.js +0 -1
  80. package/dist/public/chunks/chunk-Z2JPRGFT.js +0 -1
  81. package/dist/public/client-TYC7JKRE.js +0 -91
@@ -1,5 +1,6 @@
1
1
  import type { ZodType } from "zod";
2
2
  import { recordDashboardServerVersion } from "./dashboard-version";
3
+ import { readResponseJson } from "./sentry";
3
4
 
4
5
  /** An authenticated dashboard request rejected by the product API. */
5
6
  export class DashboardApiError extends Error {
@@ -91,7 +92,7 @@ export async function patch<T>(
91
92
  });
92
93
  if (response.status === 401) restartDashboardSignIn();
93
94
  if (!response.ok) await throwDashboardApiError(path, response);
94
- return schema.parse(await response.json());
95
+ return readResponseJson(response, schema);
95
96
  }
96
97
 
97
98
  /** Send one authenticated POST request and validate its response. */
@@ -108,7 +109,7 @@ export async function post<T>(
108
109
  });
109
110
  if (response.status === 401) restartDashboardSignIn();
110
111
  if (!response.ok) await throwDashboardApiError(path, response);
111
- return schema.parse(await response.json());
112
+ return readResponseJson(response, schema);
112
113
  }
113
114
 
114
115
  /** Send one authenticated PUT request and validate its response. */
@@ -125,7 +126,7 @@ export async function put<T>(
125
126
  });
126
127
  if (response.status === 401) restartDashboardSignIn();
127
128
  if (!response.ok) await throwDashboardApiError(path, response);
128
- return schema.parse(await response.json());
129
+ return readResponseJson(response, schema);
129
130
  }
130
131
 
131
132
  /** Delete one authenticated dashboard resource. */
@@ -152,7 +153,7 @@ export async function del<T>(
152
153
  });
153
154
  if (response.status === 401) restartDashboardSignIn();
154
155
  if (!response.ok) await throwDashboardApiError(path, response);
155
- return schema.parse(await response.json());
156
+ return readResponseJson(response, schema);
156
157
  }
157
158
 
158
159
  async function fetchDashboard(
@@ -171,7 +172,7 @@ export async function fetchDashboardJson<T>(
171
172
  signal?: AbortSignal,
172
173
  ): Promise<T> {
173
174
  const response = await readDashboardResponse(path, signal);
174
- return schema.parse(await response.json());
175
+ return readResponseJson(response, schema);
175
176
  }
176
177
 
177
178
  /** Read an authenticated response, allowing 304 only for explicit validator headers. */
@@ -1,8 +1,11 @@
1
1
  import {
2
+ BrowserClient,
2
3
  browserTracingIntegration,
4
+ defaultStackParser,
3
5
  getActiveSpan,
4
6
  getRootSpan,
5
- init,
7
+ makeFetchTransport,
8
+ setCurrentClient,
6
9
  spanToJSON,
7
10
  startInactiveSpan,
8
11
  updateSpanName,
@@ -118,6 +121,47 @@ export function recordTranscriptShown(): void {
118
121
  }).end();
119
122
  }
120
123
 
124
+ /**
125
+ * Read, parse, and validate a dashboard API response body. While a pageload
126
+ * or navigation is open, a span times it from the response headers to the
127
+ * validated value. The `http.client` span ends at the headers, so it holds
128
+ * none of this work.
129
+ */
130
+ export async function readResponseJson<T>(
131
+ response: Response,
132
+ schema: { parse: (value: unknown) => T },
133
+ ): Promise<T> {
134
+ const routeSpan = activeRouteSpan();
135
+ if (!routeSpan) return schema.parse(await response.json());
136
+ const span = startInactiveSpan({
137
+ attributes: {
138
+ "url.path": response.url ? new URL(response.url).pathname : undefined,
139
+ },
140
+ name: "Read API response",
141
+ op: "deserialize",
142
+ parentSpan: routeSpan,
143
+ });
144
+ try {
145
+ const text = await response.text();
146
+ const downloadedAt = performance.now();
147
+ const json: unknown = JSON.parse(text);
148
+ const parsedAt = performance.now();
149
+ const value = schema.parse(json);
150
+ span.setAttributes({
151
+ "app.dashboard.response.chars": text.length,
152
+ "app.dashboard.response.json_parse_ms": Math.round(
153
+ parsedAt - downloadedAt,
154
+ ),
155
+ "app.dashboard.response.schema_parse_ms": Math.round(
156
+ performance.now() - parsedAt,
157
+ ),
158
+ });
159
+ return value;
160
+ } finally {
161
+ span.end();
162
+ }
163
+ }
164
+
121
165
  /**
122
166
  * Send dashboard performance spans to the server's Sentry project when the
123
167
  * server provides a DSN. Only tracing is enabled: error events and
@@ -126,10 +170,14 @@ export function recordTranscriptShown(): void {
126
170
  export function initDashboardSentry(): void {
127
171
  const config = window.__JUNIOR_DASHBOARD_SENTRY__;
128
172
  if (!config) return;
129
- init({
173
+ // `init()` bundles every default integration (about 24 KB of error,
174
+ // breadcrumb, and session code), even with `defaultIntegrations: false`.
175
+ // A client built directly bundles only browser tracing.
176
+ const client = new BrowserClient({
130
177
  ...config,
131
178
  beforeSendSpan: scrubSpan,
132
- defaultIntegrations: false,
179
+ stackParser: defaultStackParser,
180
+ transport: makeFetchTransport,
133
181
  integrations: [
134
182
  browserTracingIntegration({
135
183
  beforeStartSpan: (options) =>
@@ -145,4 +193,6 @@ export function initDashboardSentry(): void {
145
193
  }),
146
194
  ],
147
195
  });
196
+ setCurrentClient(client);
197
+ client.init();
148
198
  }
@@ -14,20 +14,18 @@ export const revalidateConversation: MiddlewareHandler = async (
14
14
  // The same route pattern also matches /conversations/stats.
15
15
  if (typeof report.conversationId !== "string") return;
16
16
  // generatedAt is the read time, not a change to the Conversation. The mailbox
17
- // has its own live watermark, and a read that asks for it never gets a 304.
17
+ // has its own live watermark, so a poll that asks for it gets it alone.
18
18
  const { generatedAt: _generatedAt, mailbox, ...content } = report;
19
19
  const version = createHash("sha256")
20
20
  .update(JSON.stringify(content))
21
21
  .digest("hex");
22
22
  context.header("cache-control", "private, no-store");
23
23
  context.header(CONVERSATION_DETAIL_VERSION_HEADER, version);
24
- if (
25
- !mailbox &&
26
- context.req.header(CONVERSATION_DETAIL_VERSION_HEADER) === version
27
- ) {
28
- context.res = new Response(null, {
29
- status: 304,
30
- headers: context.res.headers,
31
- });
32
- }
24
+ if (context.req.header(CONVERSATION_DETAIL_VERSION_HEADER) !== version)
25
+ return;
26
+ context.res = mailbox
27
+ ? new Response(JSON.stringify({ mailbox, unchanged: true }), {
28
+ headers: context.res.headers,
29
+ })
30
+ : new Response(null, { status: 304, headers: context.res.headers });
33
31
  };
@@ -316,14 +316,6 @@ function mockBrief(
316
316
  kind: "confirmed",
317
317
  },
318
318
  ],
319
- openDecisions: live
320
- ? [
321
- {
322
- text: "Roll back payments-v42 or patch the serializer path.",
323
- owner: "Morgan Lee",
324
- },
325
- ]
326
- : [],
327
319
  facts: live
328
320
  ? [
329
321
  "Checkout p95 increased from 210ms to 890ms.",
@@ -1 +0,0 @@
1
- import{a as F,b as He}from"./chunk-YPMUHXYT.js";import{c as E}from"./chunk-7SZRL6FY.js";var vt={setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:e=>clearTimeout(e),setInterval:(e,t)=>setInterval(e,t),clearInterval:e=>clearInterval(e)},gt=class{#t=vt;#e=!1;setTimeoutProvider(e){this.#t=e}setTimeout(e,t){return this.#t.setTimeout(e,t)}clearTimeout(e){this.#t.clearTimeout(e)}setInterval(e,t){return this.#t.setInterval(e,t)}clearInterval(e){this.#t.clearInterval(e)}},C=new gt;function Ke(e){setTimeout(e,0)}var Qe=typeof window>"u"||"Deno"in globalThis;function g(){}function Ve(e,t){return typeof e=="function"?e(t):e}function X(e){return typeof e=="number"&&e>=0&&e!==1/0}function ce(e,t){return Math.max(e+(t||0)-Date.now(),0)}function P(e,t){return typeof e=="function"?e(t):e}function R(e,t){return typeof e=="function"?e(t):e}function he(e,t){let{type:s="all",exact:r,fetchStatus:i,predicate:n,queryKey:o,stale:c}=e;if(o){if(r){if(t.queryHash!==Y(o,t.options))return!1}else if(!H(t.queryKey,o))return!1}if(s!=="all"){let a=t.isActive();if(s==="active"&&!a||s==="inactive"&&a)return!1}return!(typeof c=="boolean"&&t.isStale()!==c||i&&i!==t.state.fetchStatus||n&&!n(t))}function le(e,t){let{exact:s,status:r,predicate:i,mutationKey:n}=e;if(n){if(!t.options.mutationKey)return!1;if(s){if(Q(t.options.mutationKey)!==Q(n))return!1}else if(!H(t.options.mutationKey,n))return!1}return!(r&&t.state.status!==r||i&&!i(t))}function Y(e,t){return(t?.queryKeyHashFn||Q)(e)}function Q(e){return JSON.stringify(e,(t,s)=>Ce(s)?Object.keys(s).sort().reduce((r,i)=>(r[i]=s[i],r),{}):s)}function H(e,t){return e===t?!0:typeof e!=typeof t?!1:e&&t&&typeof e=="object"&&typeof t=="object"?Object.keys(t).every(s=>H(e[s],t[s])):!1}var bt=Object.prototype.hasOwnProperty;function K(e,t,s=0){if(e===t)return e;if(s>500)return t;let r=Le(e)&&Le(t);if(!r&&!(Ce(e)&&Ce(t)))return t;let n=(r?e:Object.keys(e)).length,o=r?t:Object.keys(t),c=o.length,a=r?new Array(c):{},p=0;for(let u=0;u<c;u++){let f=r?u:o[u],l=e[f],b=t[f];if(l===b){a[f]=l,(r?u<n:bt.call(e,f))&&p++;continue}if(l===null||b===null||typeof l!="object"||typeof b!="object"){a[f]=b;continue}let m=K(l,b,s+1);a[f]=m,m===l&&p++}return n===c&&p===n?e:a}function j(e,t){if(!t||Object.keys(e).length!==Object.keys(t).length)return!1;for(let s in e)if(e[s]!==t[s])return!1;return!0}function Le(e){return Array.isArray(e)&&e.length===Object.keys(e).length}function Ce(e){if(!Be(e))return!1;let t=e.constructor;if(t===void 0)return!0;let s=t.prototype;return!(!Be(s)||!s.hasOwnProperty("isPrototypeOf")||Object.getPrototypeOf(e)!==Object.prototype)}function Be(e){return Object.prototype.toString.call(e)==="[object Object]"}function Ge(e){return new Promise(t=>{C.setTimeout(t,e)})}function ee(e,t,s){return typeof s.structuralSharing=="function"?s.structuralSharing(e,t):s.structuralSharing!==!1?K(e,t):t}function Rt(e){return e}function $e(e,t,s=0){let r=[...e,t];return s&&r.length>s?r.slice(1):r}function ze(e,t,s=0){let r=[t,...e];return s&&r.length>s?r.slice(0,-1):r}var B=Symbol();function fe(e,t){return!e.queryFn&&t?.initialPromise?()=>t.initialPromise:!e.queryFn||e.queryFn===B?()=>Promise.reject(new Error(`Missing queryFn: '${e.queryHash}'`)):e.queryFn}function V(e,t){return typeof e=="function"?e(...t):!!e}function Je(e,t,s){let r=!1,i;return Object.defineProperty(e,"signal",{enumerable:!0,get:()=>(i??=t(),r||(r=!0,i.aborted?s():i.addEventListener("abort",s,{once:!0})),i)}),e}var We=Ke;function Ot(){let e=[],t=0,s=c=>{c()},r=c=>{c()},i=We,n=c=>{t?e.push(c):i(()=>{s(c)})},o=()=>{let c=e;e=[],c.length&&i(()=>{r(()=>{c.forEach(a=>{s(a)})})})};return{batch:c=>{let a;t++;try{a=c()}finally{t--,t||o()}return a},batchCalls:c=>(...a)=>{n(()=>{c(...a)})},schedule:n,setNotifyFunction:c=>{s=c},setBatchNotifyFunction:c=>{r=c},setScheduler:c=>{i=c}}}var d=Ot();var O=class{constructor(){this.listeners=new Set,this.subscribe=this.subscribe.bind(this)}subscribe(e){return this.listeners.add(e),this.onSubscribe(),()=>{this.listeners.delete(e),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}};var wt=class extends O{#t;#e;#s;constructor(){super(),this.#s=e=>{if(typeof window<"u"&&window.addEventListener){let t=()=>e();return window.addEventListener("visibilitychange",t,!1),()=>{window.removeEventListener("visibilitychange",t)}}}}onSubscribe(){this.#e||this.setEventListener(this.#s)}onUnsubscribe(){this.hasListeners()||(this.#e?.(),this.#e=void 0)}setEventListener(e){this.#s=e,this.#e?.(),this.#e=e(t=>{typeof t=="boolean"?this.setFocused(t):this.onFocus()})}setFocused(e){this.#t!==e&&(this.#t=e,this.onFocus())}onFocus(){let e=this.isFocused();this.listeners.forEach(t=>{t(e)})}isFocused(){return typeof this.#t=="boolean"?this.#t:globalThis.document?.visibilityState!=="hidden"}},G=new wt;var St=class extends O{#t=!0;#e;#s;constructor(){super(),this.#s=e=>{if(typeof window<"u"&&window.addEventListener){let t=()=>e(!0),s=()=>e(!1);return window.addEventListener("online",t,!1),window.addEventListener("offline",s,!1),()=>{window.removeEventListener("online",t),window.removeEventListener("offline",s)}}}}onSubscribe(){this.#e||this.setEventListener(this.#s)}onUnsubscribe(){this.hasListeners()||(this.#e?.(),this.#e=void 0)}setEventListener(e){this.#s=e,this.#e?.(),this.#e=e(this.setOnline.bind(this))}setOnline(e){this.#t!==e&&(this.#t=e,this.listeners.forEach(s=>{s(e)}))}isOnline(){return this.#t}},L=new St;function te(){let e,t,s=new Promise((i,n)=>{e=i,t=n});s.status="pending",s.catch(()=>{});function r(i){Object.assign(s,i),delete s.resolve,delete s.reject}return s.resolve=i=>{r({status:"fulfilled",value:i}),e(i)},s.reject=i=>{r({status:"rejected",reason:i}),t(i)},s}var M=(()=>{let e=()=>Qe;return{isServer(){return e()},setIsServer(t){e=t}}})();function Et(e){return Math.min(1e3*2**e,3e4)}function Me(e){return(e??"online")==="online"?L.isOnline():!0}var de=class extends Error{constructor(e){super("CancelledError"),this.revert=e?.revert,this.silent=e?.silent}};function pe(e){let t=!1,s=0,r,i=te(),n=()=>i.status!=="pending",o=h=>{if(!n()){let y=new de(h);l(y),e.onCancel?.(y)}},c=()=>{t=!0},a=()=>{t=!1},p=()=>G.isFocused()&&(e.networkMode==="always"||L.isOnline())&&e.canRun(),u=()=>Me(e.networkMode)&&e.canRun(),f=h=>{n()||(r?.(),i.resolve(h))},l=h=>{n()||(r?.(),i.reject(h))},b=()=>new Promise(h=>{r=y=>{(n()||p())&&h(y)},e.onPause?.()}).then(()=>{r=void 0,n()||e.onContinue?.()}),m=()=>{if(n())return;let h,y=s===0?e.initialPromise:void 0;try{h=y??e.fn()}catch(v){h=Promise.reject(v)}Promise.resolve(h).then(f).catch(v=>{if(n())return;let w=e.retry??(M.isServer()?0:3),T=e.retryDelay??Et,_=typeof T=="function"?T(s,v):T,U=w===!0||typeof w=="number"&&s<w||typeof w=="function"&&w(s,v);if(t||!U){l(v);return}s++,e.onFail?.(s,v),Ge(_).then(()=>p()?void 0:b()).then(()=>{t?l(v):m()})})};return{promise:i,status:()=>i.status,cancel:o,continue:()=>(r?.(),i),cancelRetry:c,continueRetry:a,canStart:u,start:()=>(u()?m():b().then(m),i)}}var me=class{#t;destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),X(this.gcTime)&&(this.#t=C.setTimeout(()=>{this.optionalRemove()},this.gcTime))}updateGcTime(e){this.gcTime=Math.max(this.gcTime||0,e??(M.isServer()?1/0:300*1e3))}clearGcTimeout(){this.#t!==void 0&&(C.clearTimeout(this.#t),this.#t=void 0)}};function Ze(e){return{onFetch:(t,s)=>{let r=t.options,i=t.fetchOptions?.meta?.fetchMore?.direction,n=t.state.data?.pages||[],o=t.state.data?.pageParams||[],c={pages:[],pageParams:[]},a=0,p=async()=>{let u=!1,f=m=>{Je(m,()=>t.signal,()=>u=!0)},l=fe(t.options,t.fetchOptions),b=async(m,h,y)=>{if(u)return Promise.reject(t.signal.reason);if(h==null&&m.pages.length)return Promise.resolve(m);let w=(()=>{let Pe={client:t.client,queryKey:t.queryKey,pageParam:h,direction:y?"backward":"forward",meta:t.options.meta};return f(Pe),Pe})(),T=await l(w),{maxPages:_}=t.options,U=y?ze:$e;return{pages:U(m.pages,T,_),pageParams:U(m.pageParams,h,_)}};if(i&&n.length){let m=i==="backward",h=m?Xe:xe,y={pages:n,pageParams:o},v=h(r,y);c=await b(y,v,m)}else{let m=e??n.length;do{let h=a===0?o[0]??r.initialPageParam:xe(r,c);if(a>0&&h==null)break;c=await b(c,h),a++}while(a<m)}return c};t.options.persister?t.fetchFn=()=>t.options.persister?.(p,{client:t.client,queryKey:t.queryKey,meta:t.options.meta,signal:t.signal},s):t.fetchFn=p}}}function xe(e,{pages:t,pageParams:s}){let r=t.length-1;return t.length>0?e.getNextPageParam(t[r],t,s[r],s):void 0}function Xe(e,{pages:t,pageParams:s}){return t.length>0?e.getPreviousPageParam?.(t[0],t,s[0],s):void 0}function Ye(e,t){return t?xe(e,t)!=null:!1}function et(e,t){return!t||!e.getPreviousPageParam?!1:Xe(e,t)!=null}var rt=class extends me{#t;#e;#s;#r;#i;#n;#a;#o;constructor(e){super(),this.#o=!1,this.#a=e.defaultOptions,this.setOptions(e.options),this.observers=[],this.#i=e.client,this.#r=this.#i.getQueryCache(),this.queryKey=e.queryKey,this.queryHash=e.queryHash,this.#e=st(this.options),this.state=e.state??this.#e,this.scheduleGc()}get meta(){return this.options.meta}get queryType(){return this.#t}get promise(){return this.#n?.promise}setOptions(e){if(this.options={...this.#a,...e},e?._type&&(this.#t=e._type),this.updateGcTime(this.options.gcTime),this.state&&this.state.data===void 0){let t=st(this.options);t.data!==void 0&&(this.setState(tt(t.data,t.dataUpdatedAt)),this.#e=t)}}optionalRemove(){!this.observers.length&&this.state.fetchStatus==="idle"&&this.#r.remove(this)}setData(e,t){let s=ee(this.state.data,e,this.options);return this.#u({data:s,type:"success",dataUpdatedAt:t?.updatedAt,manual:t?.manual}),s}setState(e){this.#u({type:"setState",state:e})}cancel(e){let t=this.#n?.promise;return this.#n?.cancel(e),t?t.then(g).catch(g):Promise.resolve()}destroy(){super.destroy(),this.cancel({silent:!0})}get resetState(){return this.#e}reset(){this.destroy(),this.setState(this.resetState)}isActive(){return this.observers.some(e=>R(e.options.enabled,this)!==!1)}isDisabled(){return this.getObserversCount()>0?!this.isActive():this.options.queryFn===B||!this.isFetched()}isFetched(){return this.state.dataUpdateCount+this.state.errorUpdateCount>0}isStatic(){return this.getObserversCount()>0?this.observers.some(e=>P(e.options.staleTime,this)==="static"):!1}isStale(){return this.getObserversCount()>0?this.observers.some(e=>e.getCurrentResult().isStale):this.state.data===void 0||this.state.isInvalidated}isStaleByTime(e=0){return this.state.data===void 0?!0:e==="static"?!1:this.state.isInvalidated?!0:!ce(this.state.dataUpdatedAt,e)}onFocus(){this.observers.find(t=>t.shouldFetchOnWindowFocus())?.refetch({cancelRefetch:!1}),this.#n?.continue()}onOnline(){this.observers.find(t=>t.shouldFetchOnReconnect())?.refetch({cancelRefetch:!1}),this.#n?.continue()}addObserver(e){this.observers.includes(e)||(this.observers.push(e),this.clearGcTimeout(),this.#r.notify({type:"observerAdded",query:this,observer:e}))}removeObserver(e){this.observers.includes(e)&&(this.observers=this.observers.filter(t=>t!==e),this.observers.length||(this.#n&&(this.#o||this.#h()?this.#n.cancel({revert:!0}):this.#n.cancelRetry()),this.scheduleGc()),this.#r.notify({type:"observerRemoved",query:this,observer:e}))}getObserversCount(){return this.observers.length}#h(){return this.state.fetchStatus==="paused"&&this.state.status==="pending"}invalidate(){this.state.isInvalidated||this.#u({type:"invalidate"})}async fetch(e,t){if(this.state.fetchStatus!=="idle"&&this.#n?.status()!=="rejected"){if(this.state.data!==void 0&&t?.cancelRefetch)this.cancel({silent:!0});else if(this.#n)return this.#n.continueRetry(),this.#n.promise}if(e&&this.setOptions(e),!this.options.queryFn){let a=this.observers.find(p=>p.options.queryFn);a&&this.setOptions(a.options)}let s=new AbortController,r=a=>{Object.defineProperty(a,"signal",{enumerable:!0,get:()=>(this.#o=!0,s.signal)})},i=()=>{let a=fe(this.options,t),u=(()=>{let f={client:this.#i,queryKey:this.queryKey,meta:this.meta};return r(f),f})();return this.#o=!1,this.options.persister?this.options.persister(a,u,this):a(u)},o=(()=>{let a={fetchOptions:t,options:this.options,queryKey:this.queryKey,client:this.#i,state:this.state,fetchFn:i};return r(a),a})();(this.#t==="infinite"?Ze(this.options.pages):this.options.behavior)?.onFetch(o,this),this.#s=this.state,(this.state.fetchStatus==="idle"||this.state.fetchMeta!==o.fetchOptions?.meta)&&this.#u({type:"fetch",meta:o.fetchOptions?.meta}),this.#n=pe({initialPromise:t?.initialPromise,fn:o.fetchFn,onCancel:a=>{a instanceof de&&a.revert&&this.setState({...this.#s,fetchStatus:"idle"}),s.abort()},onFail:(a,p)=>{this.#u({type:"failed",failureCount:a,error:p})},onPause:()=>{this.#u({type:"pause"})},onContinue:()=>{this.#u({type:"continue"})},retry:o.options.retry,retryDelay:o.options.retryDelay,networkMode:o.options.networkMode,canRun:()=>!0});try{let a=await this.#n.start();if(a===void 0)throw new Error(`${this.queryHash} data is undefined`);return this.setData(a),this.#r.config.onSuccess?.(a,this),this.#r.config.onSettled?.(a,this.state.error,this),a}catch(a){if(a instanceof de){if(a.silent)return this.#n.promise;if(a.revert){if(this.state.data===void 0)throw a;return this.state.data}}throw this.#u({type:"error",error:a}),this.#r.config.onError?.(a,this),this.#r.config.onSettled?.(this.state.data,a,this),a}finally{this.scheduleGc()}}#u(e){let t=s=>{switch(e.type){case"failed":return{...s,fetchFailureCount:e.failureCount,fetchFailureReason:e.error};case"pause":return{...s,fetchStatus:"paused"};case"continue":return{...s,fetchStatus:"fetching"};case"fetch":return{...s,...Te(s.data,this.options),fetchMeta:e.meta??null};case"success":let r={...s,...tt(e.data,e.dataUpdatedAt),dataUpdateCount:s.dataUpdateCount+1,...!e.manual&&{fetchStatus:"idle",fetchFailureCount:0,fetchFailureReason:null}};return this.#s=e.manual?r:void 0,r;case"error":let i=e.error;return{...s,error:i,errorUpdateCount:s.errorUpdateCount+1,errorUpdatedAt:Date.now(),fetchFailureCount:s.fetchFailureCount+1,fetchFailureReason:i,fetchStatus:"idle",status:"error",isInvalidated:!0};case"invalidate":return{...s,isInvalidated:!0};case"setState":return{...s,...e.state}}};this.state=t(this.state),d.batch(()=>{this.observers.forEach(s=>{s.onQueryUpdate()}),this.#r.notify({query:this,type:"updated",action:e})})}};function Te(e,t){return{fetchFailureCount:0,fetchFailureReason:null,fetchStatus:Me(t.networkMode)?"fetching":"paused",...e===void 0&&{error:null,status:"pending"}}}function tt(e,t){return{data:e,dataUpdatedAt:t??Date.now(),error:null,isInvalidated:!1,status:"success"}}function st(e){let t=typeof e.initialData=="function"?e.initialData():e.initialData,s=t!==void 0,r=s?typeof e.initialDataUpdatedAt=="function"?e.initialDataUpdatedAt():e.initialDataUpdatedAt:0;return{data:t,dataUpdateCount:0,dataUpdatedAt:s?r??Date.now():0,error:null,errorUpdateCount:0,errorUpdatedAt:0,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:null,isInvalidated:!1,status:s?"success":"pending",fetchStatus:"idle"}}var it=class extends O{constructor(e={}){super(),this.config=e,this.#t=new Map}#t;build(e,t,s){let r=t.queryKey,i=t.queryHash??Y(r,t),n=this.get(i);return n||(n=new rt({client:e,queryKey:r,queryHash:i,options:e.defaultQueryOptions(t),state:s,defaultOptions:e.getQueryDefaults(r)}),this.add(n)),n}add(e){this.#t.has(e.queryHash)||(this.#t.set(e.queryHash,e),this.notify({type:"added",query:e}))}remove(e){let t=this.#t.get(e.queryHash);t&&(e.destroy(),t===e&&this.#t.delete(e.queryHash),this.notify({type:"removed",query:e}))}clear(){d.batch(()=>{this.getAll().forEach(e=>{this.remove(e)})})}get(e){return this.#t.get(e)}getAll(){return[...this.#t.values()]}find(e){let t={exact:!0,...e};return this.getAll().find(s=>he(t,s))}findAll(e={}){let t=this.getAll();return Object.keys(e).length>0?t.filter(s=>he(e,s)):t}notify(e){d.batch(()=>{this.listeners.forEach(t=>{t(e)})})}onFocus(){d.batch(()=>{this.getAll().forEach(e=>{e.onFocus()})})}onOnline(){d.batch(()=>{this.getAll().forEach(e=>{e.onOnline()})})}};var nt=class extends me{#t;#e;#s;#r;constructor(e){super(),this.#t=e.client,this.mutationId=e.mutationId,this.#s=e.mutationCache,this.#e=[],this.state=e.state||Fe(),this.setOptions(e.options),this.scheduleGc()}setOptions(e){this.options=e,this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(e){this.#e.includes(e)||(this.#e.push(e),this.clearGcTimeout(),this.#s.notify({type:"observerAdded",mutation:this,observer:e}))}removeObserver(e){this.#e=this.#e.filter(t=>t!==e),this.scheduleGc(),this.#s.notify({type:"observerRemoved",mutation:this,observer:e})}optionalRemove(){this.#e.length||(this.state.status==="pending"?this.scheduleGc():this.#s.remove(this))}continue(){return this.#r?.continue()??this.execute(this.state.variables)}async execute(e){let t=()=>{this.#i({type:"continue"})},s={client:this.#t,meta:this.options.meta,mutationKey:this.options.mutationKey};this.#r=pe({fn:()=>this.options.mutationFn?this.options.mutationFn(e,s):Promise.reject(new Error("No mutationFn found")),onFail:(n,o)=>{this.#i({type:"failed",failureCount:n,error:o})},onPause:()=>{this.#i({type:"pause"})},onContinue:t,retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode,canRun:()=>this.#s.canRun(this)});let r=this.state.status==="pending",i=!this.#r.canStart();try{if(r)t();else{this.#i({type:"pending",variables:e,isPaused:i}),this.#s.config.onMutate&&await this.#s.config.onMutate(e,this,s);let o=await this.options.onMutate?.(e,s);o!==this.state.context&&this.#i({type:"pending",context:o,variables:e,isPaused:i})}let n=await this.#r.start();return await this.#s.config.onSuccess?.(n,e,this.state.context,this,s),await this.options.onSuccess?.(n,e,this.state.context,s),await this.#s.config.onSettled?.(n,null,this.state.variables,this.state.context,this,s),await this.options.onSettled?.(n,null,e,this.state.context,s),this.#i({type:"success",data:n}),n}catch(n){try{await this.#s.config.onError?.(n,e,this.state.context,this,s)}catch(o){Promise.reject(o)}try{await this.options.onError?.(n,e,this.state.context,s)}catch(o){Promise.reject(o)}try{await this.#s.config.onSettled?.(void 0,n,this.state.variables,this.state.context,this,s)}catch(o){Promise.reject(o)}try{await this.options.onSettled?.(void 0,n,e,this.state.context,s)}catch(o){Promise.reject(o)}throw this.#i({type:"error",error:n}),n}finally{this.#s.runNext(this)}}#i(e){let t=s=>{switch(e.type){case"failed":return{...s,failureCount:e.failureCount,failureReason:e.error};case"pause":return{...s,isPaused:!0};case"continue":return{...s,isPaused:!1};case"pending":return{...s,context:e.context,data:void 0,failureCount:0,failureReason:null,error:null,isPaused:e.isPaused,status:"pending",variables:e.variables,submittedAt:Date.now()};case"success":return{...s,data:e.data,failureCount:0,failureReason:null,error:null,status:"success",isPaused:!1};case"error":return{...s,data:void 0,error:e.error,failureCount:s.failureCount+1,failureReason:e.error,isPaused:!1,status:"error"}}};this.state=t(this.state),d.batch(()=>{this.#e.forEach(s=>{s.onMutationUpdate(e)}),this.#s.notify({mutation:this,type:"updated",action:e})})}};function Fe(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0}}var ot=class extends O{constructor(e={}){super(),this.config=e,this.#t=new Set,this.#e=new Map,this.#s=0}#t;#e;#s;build(e,t,s){let r=new nt({client:e,mutationCache:this,mutationId:++this.#s,options:e.defaultMutationOptions(t),state:s});return this.add(r),r}add(e){this.#t.add(e);let t=ye(e);if(typeof t=="string"){let s=this.#e.get(t);s?s.push(e):this.#e.set(t,[e])}this.notify({type:"added",mutation:e})}remove(e){if(this.#t.delete(e)){let t=ye(e);if(typeof t=="string"){let s=this.#e.get(t);if(s)if(s.length>1){let r=s.indexOf(e);r!==-1&&s.splice(r,1)}else s[0]===e&&this.#e.delete(t)}}this.notify({type:"removed",mutation:e})}canRun(e){let t=ye(e);if(typeof t=="string"){let r=this.#e.get(t)?.find(i=>i.state.status==="pending");return!r||r===e}else return!0}runNext(e){let t=ye(e);return typeof t=="string"?this.#e.get(t)?.find(r=>r!==e&&r.state.isPaused)?.continue()??Promise.resolve():Promise.resolve()}clear(){d.batch(()=>{this.#t.forEach(e=>{this.notify({type:"removed",mutation:e})}),this.#t.clear(),this.#e.clear()})}getAll(){return Array.from(this.#t)}find(e){let t={exact:!0,...e};return this.getAll().find(s=>le(t,s))}findAll(e={}){return this.getAll().filter(t=>le(e,t))}notify(e){d.batch(()=>{this.listeners.forEach(t=>{t(e)})})}resumePausedMutations(){let e=this.getAll().filter(t=>t.state.isPaused);return d.batch(()=>Promise.all(e.map(t=>t.continue().catch(g))))}};function ye(e){return e.options.scope?.id}var Pt=class{#t;#e;#s;#r;#i;#n;#a;#o;constructor(e={}){this.#t=e.queryCache||new it,this.#e=e.mutationCache||new ot,this.#s=e.defaultOptions||{},this.#r=new Map,this.#i=new Map,this.#n=0}mount(){this.#n++,this.#n===1&&(this.#a=G.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#t.onFocus())}),this.#o=L.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#t.onOnline())}))}unmount(){this.#n--,this.#n===0&&(this.#a?.(),this.#a=void 0,this.#o?.(),this.#o=void 0)}isFetching(e){return this.#t.findAll({...e,fetchStatus:"fetching"}).length}isMutating(e){return this.#e.findAll({...e,status:"pending"}).length}getQueryData(e){let t=this.defaultQueryOptions({queryKey:e});return this.#t.get(t.queryHash)?.state.data}ensureQueryData(e){let t=this.defaultQueryOptions(e),s=this.#t.build(this,t),r=s.state.data;return r===void 0?this.fetchQuery(e):(e.revalidateIfStale&&s.isStaleByTime(P(t.staleTime,s))&&this.prefetchQuery(t),Promise.resolve(r))}getQueriesData(e){return this.#t.findAll(e).map(({queryKey:t,state:s})=>{let r=s.data;return[t,r]})}setQueryData(e,t,s){let r=this.defaultQueryOptions({queryKey:e}),n=this.#t.get(r.queryHash)?.state.data,o=Ve(t,n);if(o!==void 0)return this.#t.build(this,r).setData(o,{...s,manual:!0})}setQueriesData(e,t,s){return d.batch(()=>this.#t.findAll(e).map(({queryKey:r})=>[r,this.setQueryData(r,t,s)]))}getQueryState(e){let t=this.defaultQueryOptions({queryKey:e});return this.#t.get(t.queryHash)?.state}removeQueries(e){let t=this.#t;d.batch(()=>{t.findAll(e).forEach(s=>{t.remove(s)})})}resetQueries(e,t){let s=this.#t;return d.batch(()=>(s.findAll(e).forEach(r=>{r.reset()}),this.refetchQueries({type:"active",...e},t)))}cancelQueries(e,t={}){let s={revert:!0,...t},r=d.batch(()=>this.#t.findAll(e).map(i=>i.cancel(s)));return Promise.all(r).then(g).catch(g)}invalidateQueries(e,t={}){return d.batch(()=>(this.#t.findAll(e).forEach(s=>{s.invalidate()}),e?.refetchType==="none"?Promise.resolve():this.refetchQueries({...e,type:e?.refetchType??e?.type??"active"},t)))}refetchQueries(e,t={}){let s={...t,cancelRefetch:t.cancelRefetch??!0},r=d.batch(()=>this.#t.findAll(e).filter(i=>!i.isDisabled()&&!i.isStatic()).map(i=>{let n=i.fetch(void 0,s);return s.throwOnError||(n=n.catch(g)),i.state.fetchStatus==="paused"?Promise.resolve():n}));return Promise.all(r).then(g)}fetchQuery(e){let t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);let s=this.#t.build(this,t);return s.isStaleByTime(P(t.staleTime,s))?s.fetch(t):Promise.resolve(s.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(g).catch(g)}fetchInfiniteQuery(e){return e._type="infinite",this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(g).catch(g)}ensureInfiniteQueryData(e){return e._type="infinite",this.ensureQueryData(e)}resumePausedMutations(){return L.isOnline()?this.#e.resumePausedMutations():Promise.resolve()}getQueryCache(){return this.#t}getMutationCache(){return this.#e}getDefaultOptions(){return this.#s}setDefaultOptions(e){this.#s=e}setQueryDefaults(e,t){this.#r.set(Q(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){let t=[...this.#r.values()],s={};return t.forEach(r=>{H(e,r.queryKey)&&Object.assign(s,r.defaultOptions)}),s}setMutationDefaults(e,t){this.#i.set(Q(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){let t=[...this.#i.values()],s={};return t.forEach(r=>{H(e,r.mutationKey)&&Object.assign(s,r.defaultOptions)}),s}defaultQueryOptions(e){if(e._defaulted)return e;let t={...this.#s.queries,...this.getQueryDefaults(e.queryKey),...e,_defaulted:!0};return t.queryHash||(t.queryHash=Y(t.queryKey,t)),t.refetchOnReconnect===void 0&&(t.refetchOnReconnect=t.networkMode!=="always"),t.throwOnError===void 0&&(t.throwOnError=!!t.suspense),!t.networkMode&&t.persister&&(t.networkMode="offlineFirst"),t.queryFn===B&&(t.enabled=!1),t}defaultMutationOptions(e){return e?._defaulted?e:{...this.#s.mutations,...e?.mutationKey&&this.getMutationDefaults(e.mutationKey),...e,_defaulted:!0}}clear(){this.#t.clear(),this.#e.clear()}};var D=class extends O{constructor(e,t){super(),this.options=t,this.#t=e,this.#o=null,this.#a=te(),this.bindMethods(),this.setOptions(t)}#t;#e=void 0;#s=void 0;#r=void 0;#i;#n;#a;#o;#h;#u;#d;#l;#p;#c;#m=new Set;bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){this.listeners.size===1&&(this.#e.addObserver(this),at(this.#e,this.options)?this.#f():this.updateResult(),this.#b())}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return De(this.#e,this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return De(this.#e,this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,this.#R(),this.#O(),this.#e.removeObserver(this)}setOptions(e){let t=this.options,s=this.#e;if(this.options=this.#t.defaultQueryOptions(e),this.options.enabled!==void 0&&typeof this.options.enabled!="boolean"&&typeof this.options.enabled!="function"&&typeof R(this.options.enabled,this.#e)!="boolean")throw new Error("Expected enabled to be a boolean or a callback that returns a boolean");this.#w(),this.#e.setOptions(this.options),t._defaulted&&!j(this.options,t)&&this.#t.getQueryCache().notify({type:"observerOptionsUpdated",query:this.#e,observer:this});let r=this.hasListeners();r&&ut(this.#e,s,this.options,t)&&this.#f(),this.updateResult(),r&&(this.#e!==s||R(this.options.enabled,this.#e)!==R(t.enabled,this.#e)||P(this.options.staleTime,this.#e)!==P(t.staleTime,this.#e))&&this.#y();let i=this.#v();r&&(this.#e!==s||R(this.options.enabled,this.#e)!==R(t.enabled,this.#e)||i!==this.#c)&&this.#g(i)}getOptimisticResult(e){let t=this.#t.getQueryCache().build(this.#t,e),s=this.createResult(t,e);return Qt(this,s)&&(this.#r=s,this.#n=this.options,this.#i=this.#e.state),s}getCurrentResult(){return this.#r}trackResult(e,t){return new Proxy(e,{get:(s,r)=>(this.trackProp(r),t?.(r),r==="promise"&&(this.trackProp("data"),!this.options.experimental_prefetchInRender&&this.#a.status==="pending"&&this.#a.reject(new Error("experimental_prefetchInRender feature flag is not enabled"))),Reflect.get(s,r))})}trackProp(e){this.#m.add(e)}getCurrentQuery(){return this.#e}refetch({...e}={}){return this.fetch({...e})}fetchOptimistic(e){let t=this.#t.defaultQueryOptions(e),s=this.#t.getQueryCache().build(this.#t,t);return s.fetch().then(()=>this.createResult(s,t))}fetch(e){return this.#f({...e,cancelRefetch:e.cancelRefetch??!0}).then(()=>(this.updateResult(),this.#r))}#f(e){this.#w();let t=this.#e.fetch(this.options,e);return e?.throwOnError||(t=t.catch(g)),t}#y(){this.#R();let e=P(this.options.staleTime,this.#e);if(M.isServer()||this.#r.isStale||!X(e))return;let s=ce(this.#r.dataUpdatedAt,e)+1;this.#l=C.setTimeout(()=>{this.#r.isStale||this.updateResult()},s)}#v(){return(typeof this.options.refetchInterval=="function"?this.options.refetchInterval(this.#e):this.options.refetchInterval)??!1}#g(e){this.#O(),this.#c=e,!(M.isServer()||R(this.options.enabled,this.#e)===!1||!X(this.#c)||this.#c===0)&&(this.#p=C.setInterval(()=>{(this.options.refetchIntervalInBackground||G.isFocused())&&this.#f()},this.#c))}#b(){this.#y(),this.#g(this.#v())}#R(){this.#l!==void 0&&(C.clearTimeout(this.#l),this.#l=void 0)}#O(){this.#p!==void 0&&(C.clearInterval(this.#p),this.#p=void 0)}createResult(e,t){let s=this.#e,r=this.options,i=this.#r,n=this.#i,o=this.#n,a=e!==s?e.state:this.#s,{state:p}=e,u={...p},f=!1,l;if(t._optimisticResults){let S=this.hasListeners(),Z=!S&&at(e,t),oe=S&&ut(e,s,t,r);(Z||oe)&&(u={...u,...Te(p.data,e.options)}),t._optimisticResults==="isRestoring"&&(u.fetchStatus="idle")}let{error:b,errorUpdatedAt:m,status:h}=u;l=u.data;let y=!1;if(t.placeholderData!==void 0&&l===void 0&&h==="pending"){let S;i?.isPlaceholderData&&t.placeholderData===o?.placeholderData?(S=i.data,y=!0):S=typeof t.placeholderData=="function"?t.placeholderData(this.#d?.state.data,this.#d):t.placeholderData,S!==void 0&&(h="success",l=ee(i?.data,S,t),f=!0)}if(t.select&&l!==void 0&&!y)if(i&&l===n?.data&&t.select===this.#h)l=this.#u;else try{this.#h=t.select,l=t.select(l),l=ee(i?.data,l,t),this.#u=l,this.#o=null}catch(S){this.#o=S}this.#o&&(b=this.#o,l=this.#u,m=Date.now(),h="error");let v=u.fetchStatus==="fetching",w=h==="pending",T=h==="error",_=w&&v,U=l!==void 0,k={status:h,fetchStatus:u.fetchStatus,isPending:w,isSuccess:h==="success",isError:T,isInitialLoading:_,isLoading:_,data:l,dataUpdatedAt:u.dataUpdatedAt,error:b,errorUpdatedAt:m,failureCount:u.fetchFailureCount,failureReason:u.fetchFailureReason,errorUpdateCount:u.errorUpdateCount,isFetched:e.isFetched(),isFetchedAfterMount:u.dataUpdateCount>a.dataUpdateCount||u.errorUpdateCount>a.errorUpdateCount,isFetching:v,isRefetching:v&&!w,isLoadingError:T&&!U,isPaused:u.fetchStatus==="paused",isPlaceholderData:f,isRefetchError:T&&U,isStale:Ie(e,t),refetch:this.refetch,promise:this.#a,isEnabled:R(t.enabled,e)!==!1};if(this.options.experimental_prefetchInRender){let S=k.data!==void 0,Z=k.status==="error"&&!S,oe=ue=>{Z?ue.reject(k.error):S&&ue.resolve(k.data)},Ue=()=>{let ue=this.#a=k.promise=te();oe(ue)},ae=this.#a;switch(ae.status){case"pending":e.queryHash===s.queryHash&&oe(ae);break;case"fulfilled":(Z||k.data!==ae.value)&&Ue();break;case"rejected":(!Z||k.error!==ae.reason)&&Ue();break}}return k}updateResult(){let e=this.#r,t=this.createResult(this.#e,this.options);if(this.#i=this.#e.state,this.#n=this.options,this.#i.data!==void 0&&(this.#d=this.#e),j(t,e))return;this.#r=t;let s=()=>{if(!e)return!0;let{notifyOnChangeProps:r}=this.options,i=typeof r=="function"?r():r;if(i==="all"||!i&&!this.#m.size)return!0;let n=new Set(i??this.#m);return this.options.throwOnError&&n.add("error"),Object.keys(this.#r).some(o=>{let c=o;return this.#r[c]!==e[c]&&n.has(c)})};this.#S({listeners:s()})}#w(){let e=this.#t.getQueryCache().build(this.#t,this.options);if(e===this.#e)return;let t=this.#e;this.#e=e,this.#s=e.state,this.hasListeners()&&(t?.removeObserver(this),e.addObserver(this))}onQueryUpdate(){this.updateResult(),this.hasListeners()&&this.#b()}#S(e){d.batch(()=>{e.listeners&&this.listeners.forEach(t=>{t(this.#r)}),this.#t.getQueryCache().notify({query:this.#e,type:"observerResultsUpdated"})})}};function Ct(e,t){return R(t.enabled,e)!==!1&&e.state.data===void 0&&!(e.state.status==="error"&&R(t.retryOnMount,e)===!1)}function at(e,t){return Ct(e,t)||e.state.data!==void 0&&De(e,t,t.refetchOnMount)}function De(e,t,s){if(R(t.enabled,e)!==!1&&P(t.staleTime,e)!=="static"){let r=typeof s=="function"?s(e):s;return r==="always"||r!==!1&&Ie(e,t)}return!1}function ut(e,t,s,r){return(e!==t||R(r.enabled,e)===!1)&&(!s.suspense||e.state.status!=="error")&&Ie(e,s)}function Ie(e,t){return R(t.enabled,e)!==!1&&e.isStaleByTime(P(t.staleTime,e))}function Qt(e,t){return!j(e.getCurrentResult(),t)}var Ae=class extends D{constructor(e,t){super(e,t)}bindMethods(){super.bindMethods(),this.fetchNextPage=this.fetchNextPage.bind(this),this.fetchPreviousPage=this.fetchPreviousPage.bind(this)}setOptions(e){e._type="infinite",super.setOptions(e)}getOptimisticResult(e){return e._type="infinite",super.getOptimisticResult(e)}fetchNextPage(e){return this.fetch({...e,meta:{fetchMore:{direction:"forward"}}})}fetchPreviousPage(e){return this.fetch({...e,meta:{fetchMore:{direction:"backward"}}})}createResult(e,t){let{state:s}=e,r=super.createResult(e,t),{isFetching:i,isRefetching:n,isError:o,isRefetchError:c}=r,a=s.fetchMeta?.fetchMore?.direction,p=o&&a==="forward",u=i&&a==="forward",f=o&&a==="backward",l=i&&a==="backward";return{...r,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:Ye(t,s.data),hasPreviousPage:et(t,s.data),isFetchNextPageError:p,isFetchingNextPage:u,isFetchPreviousPageError:f,isFetchingPreviousPage:l,isRefetchError:c&&!p&&!f,isRefetching:n&&!u&&!l}}};var qe=class extends O{#t;#e=void 0;#s;#r;constructor(e,t){super(),this.#t=e,this.setOptions(t),this.bindMethods(),this.#i()}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(e){let t=this.options;this.options=this.#t.defaultMutationOptions(e),j(this.options,t)||this.#t.getMutationCache().notify({type:"observerOptionsUpdated",mutation:this.#s,observer:this}),t?.mutationKey&&this.options.mutationKey&&Q(t.mutationKey)!==Q(this.options.mutationKey)?this.reset():this.#s?.state.status==="pending"&&this.#s.setOptions(this.options)}onUnsubscribe(){this.hasListeners()||this.#s?.removeObserver(this)}onMutationUpdate(e){this.#i(),this.#n(e)}getCurrentResult(){return this.#e}reset(){this.#s?.removeObserver(this),this.#s=void 0,this.#i(),this.#n()}mutate(e,t){return this.#r=t,this.#s?.removeObserver(this),this.#s=this.#t.getMutationCache().build(this.#t,this.options),this.#s.addObserver(this),this.#s.execute(e)}#i(){let e=this.#s?.state??Fe();this.#e={...e,isPending:e.status==="pending",isSuccess:e.status==="success",isError:e.status==="error",isIdle:e.status==="idle",mutate:this.mutate,reset:this.reset}}#n(e){d.batch(()=>{if(this.#r&&this.hasListeners()){let t=this.#e.variables,s=this.#e.context,r={client:this.#t,meta:this.options.meta,mutationKey:this.options.mutationKey};if(e?.type==="success"){try{this.#r.onSuccess?.(e.data,t,s,r)}catch(i){Promise.reject(i)}try{this.#r.onSettled?.(e.data,null,t,s,r)}catch(i){Promise.reject(i)}}else if(e?.type==="error"){try{this.#r.onError?.(e.error,t,s,r)}catch(i){Promise.reject(i)}try{this.#r.onSettled?.(void 0,e.error,t,s,r)}catch(i){Promise.reject(i)}}}this.listeners.forEach(t=>{t(this.#e)})})}};function ct(e,t){let s=new Set(t);return e.filter(r=>!s.has(r))}function Mt(e,t,s){let r=e.slice(0);return r[t]=s,r}var ke=class extends O{#t;#e;#s;#r;#i;#n;#a;#o;#h;#u=[];constructor(e,t,s){super(),this.#t=e,this.#r=s,this.#s=[],this.#i=[],this.#e=[],this.setQueries(t)}onSubscribe(){this.listeners.size===1&&this.#i.forEach(e=>{e.subscribe(t=>{this.#m(e,t)})})}onUnsubscribe(){this.listeners.size||this.destroy()}destroy(){this.listeners=new Set,this.#i.forEach(e=>{e.destroy()})}setQueries(e,t){this.#s=e,this.#r=t,d.batch(()=>{let s=this.#i,r=this.#c(this.#s);r.forEach(u=>u.observer.setOptions(u.defaultedQueryOptions));let i=r.map(u=>u.observer),n=i.map(u=>u.getCurrentResult()),o=s.length!==i.length,c=i.some((u,f)=>u!==s[f]),a=o||c,p=a?!0:n.some((u,f)=>{let l=this.#e[f];return!l||!j(u,l)});!a&&!p||(a&&(this.#u=r,this.#i=i),this.#e=n,this.hasListeners()&&(a&&(ct(s,i).forEach(u=>{u.destroy()}),ct(i,s).forEach(u=>{u.subscribe(f=>{this.#m(u,f)})})),this.#f()))})}getCurrentResult(){return this.#e}getQueries(){return this.#i.map(e=>e.getCurrentQuery())}getObservers(){return this.#i}getOptimisticResult(e,t){let s=this.#c(e),r=s.map(n=>n.observer.getOptimisticResult(n.defaultedQueryOptions)),i=s.map(n=>n.defaultedQueryOptions.queryHash);return[r,n=>this.#l(n??r,t,i),()=>this.#d(r,s)]}#d(e,t){return t.map((s,r)=>{let i=e[r];return s.defaultedQueryOptions.notifyOnChangeProps?i:s.observer.trackResult(i,n=>{t.forEach(o=>{o.observer.trackProp(n)})})})}#l(e,t,s){if(t){let r=this.#h,i=s!==void 0&&r!==void 0&&(r.length!==s.length||s.some((n,o)=>n!==r[o]));return(!this.#n||this.#e!==this.#o||i||t!==this.#a)&&(this.#a=t,this.#o=this.#e,s!==void 0&&(this.#h=s),this.#n=K(this.#n,t(e))),this.#n}return e}#p(){return this.#r?.combine!==void 0&&this.#i.some((e,t)=>e.options.suspense&&this.#e[t]?.data===void 0)}#c(e){let t=new Map;this.#i.forEach(r=>{let i=r.options.queryHash;if(!i)return;let n=t.get(i);n?n.push(r):t.set(i,[r])});let s=[];return e.forEach(r=>{let i=this.#t.defaultQueryOptions(r),o=t.get(i.queryHash)?.shift()??new D(this.#t,i);s.push({defaultedQueryOptions:i,observer:o})}),s}#m(e,t){let s=this.#i.indexOf(e);s!==-1&&(this.#e=Mt(this.#e,s,t),this.#f())}#f(){if(this.hasListeners()){let e=this.#d(this.#e,this.#u),t=this.#p(),s=this.#n,r=t?s:this.#l(e,this.#r?.combine);(t||s!==r)&&d.batch(()=>{this.listeners.forEach(i=>{i(this.#e)})})}}};var $=E(F(),1),ht=E(He(),1),je=$.createContext(void 0),I=e=>{let t=$.useContext(je);if(e)return e;if(!t)throw new Error("No QueryClient set, use QueryClientProvider to set one");return t},xt=({client:e,children:t})=>($.useEffect(()=>(e.mount(),()=>{e.unmount()}),[e]),(0,ht.jsx)(je.Provider,{value:e,children:t}));var N=E(F(),1);var se=E(F(),1),Tt=E(He(),1);function Ft(){let e=!1;return{clearReset:()=>{e=!1},reset:()=>{e=!0},isReset:()=>e}}var Dt=se.createContext(Ft()),ve=()=>se.useContext(Dt);var lt=E(F(),1);var ge=(e,t,s)=>{let r=s?.state.error&&typeof e.throwOnError=="function"?V(e.throwOnError,[s.state.error,s]):e.throwOnError;(e.suspense||e.experimental_prefetchInRender||r)&&(t.isReset()||(e.retryOnMount=!1))},be=e=>{lt.useEffect(()=>{e.clearReset()},[e])},Re=({result:e,errorResetBoundary:t,throwOnError:s,query:r,suspense:i})=>e.isError&&!t.isReset()&&!e.isFetching&&r&&(i&&e.data===void 0||V(s,[e.error,r]));var Oe=E(F(),1),ft=Oe.createContext(!1),we=()=>Oe.useContext(ft),qr=ft.Provider;var Se=e=>{if(e.suspense){let s=i=>i==="static"?i:Math.max(i??1e3,1e3),r=e.staleTime;e.staleTime=typeof r=="function"?(...i)=>s(r(...i)):s(r),typeof e.gcTime=="number"&&(e.gcTime=Math.max(e.gcTime,1e3))}},dt=(e,t)=>e.isLoading&&e.isFetching&&!t,re=(e,t)=>e?.suspense&&t.isPending,ie=(e,t,s)=>t.fetchOptimistic(e).catch(()=>{s.clearReset()});function Ee(e,t,s){let r=we(),i=ve(),n=I(s),o=n.defaultQueryOptions(e);n.getDefaultOptions().queries?._experimental_beforeQuery?.(o);let c=n.getQueryCache().get(o.queryHash),a=e.subscribed!==!1;o._optimisticResults=r?"isRestoring":a?"optimistic":void 0,Se(o),ge(o,i,c),be(i);let p=!n.getQueryCache().get(o.queryHash),[u]=N.useState(()=>new t(n,o)),f=u.getOptimisticResult(o),l=!r&&a;if(N.useSyncExternalStore(N.useCallback(b=>{let m=l?u.subscribe(d.batchCalls(b)):g;return u.updateResult(),m},[u,l]),()=>u.getCurrentResult(),()=>u.getCurrentResult()),N.useEffect(()=>{u.setOptions(o)},[o,u]),re(o,f))throw ie(o,u,i);if(Re({result:f,errorResetBoundary:i,throwOnError:o.throwOnError,query:c,suspense:o.suspense}))throw f.error;return n.getDefaultOptions().queries?._experimental_afterQuery?.(o,f),o.experimental_prefetchInRender&&!M.isServer()&&dt(f,r)&&(p?ie(o,u,i):c?.promise)?.catch(g).finally(()=>{u.updateResult()}),o.notifyOnChangeProps?f:u.trackResult(f)}function It(e,t){return Ee(e,D,t)}var A=E(F(),1);function At(e,t){let s=I(t),[r]=A.useState(()=>new qe(s,e));A.useEffect(()=>{r.setOptions(e)},[r,e]);let i=A.useSyncExternalStore(A.useCallback(o=>r.subscribe(d.batchCalls(o)),[r]),()=>r.getCurrentResult(),()=>r.getCurrentResult()),n=A.useCallback((o,c)=>{r.mutate(o,c).catch(g)},[r]);if(i.error&&V(r.options.throwOnError,[i.error]))throw i.error;return{...i,mutate:n,mutateAsync:i.mutate}}var x=E(F(),1);function qt({queries:e,...t},s){let r=I(s),i=we(),n=ve(),o=x.useMemo(()=>e.map(h=>{let y=r.defaultQueryOptions(h);return y._optimisticResults=i?"isRestoring":"optimistic",y}),[e,r,i]);o.forEach(h=>{Se(h);let y=r.getQueryCache().get(h.queryHash);ge(h,n,y)}),be(n);let[c]=x.useState(()=>new ke(r,o,t)),[a,p,u]=c.getOptimisticResult(o,t.combine),f=!i&&t.subscribed!==!1;x.useSyncExternalStore(x.useCallback(h=>f?c.subscribe(d.batchCalls(h)):g,[c,f]),()=>c.getCurrentResult(),()=>c.getCurrentResult()),x.useEffect(()=>{c.setQueries(o,t)},[o,t,c]);let b=a.some((h,y)=>re(o[y],h))?a.flatMap((h,y)=>{let v=o[y];if(v&&re(v,h)){let w=new D(r,v);return ie(v,w,n)}return[]}):[];if(b.length>0)throw Promise.all(b);let m=a.find((h,y)=>{let v=o[y];return v&&Re({result:h,errorResetBoundary:n,throwOnError:v.throwOnError,query:r.getQueryCache().get(v.queryHash),suspense:v.suspense})});if(m?.error)throw m.error;return p(u())}var q=E(F(),1);function pt(e,t){return e.findAll(t.filters).map(s=>t.select?t.select(s):s.state)}function kt(e={},t){let s=I(t).getMutationCache(),r=q.useRef(e),i=q.useRef(null);return i.current===null&&(i.current=pt(s,e)),q.useEffect(()=>{r.current=e}),q.useSyncExternalStore(q.useCallback(n=>s.subscribe(()=>{let o=K(i.current,pt(s,r.current));i.current!==o&&(i.current=o,d.schedule(n))}),[s]),()=>i.current,()=>i.current)}function jt(e,t){return Ee(e,Ae,t)}var ne=E(F(),1);var mt="x-junior-version";var Ne="junior:dashboard-version";function yt(e){let t=e.headers.get(mt)?.trim();!t||typeof window>"u"||window.dispatchEvent(new CustomEvent(Ne,{detail:t}))}function wi(e){let[t,s]=(0,ne.useState)(e);return(0,ne.useEffect)(()=>{e&&s(e)},[e]),(0,ne.useEffect)(()=>{let r=i=>{s(i.detail)};return window.addEventListener(Ne,r),()=>window.removeEventListener(Ne,r)},[]),t}var _e=class extends Error{status;fields;code;apiError;constructor(t,s,r,i){super(`${t} returned ${s}`),this.status=s,this.fields=i?.fields,this.code=i?.code,r?.trim()&&(this.apiError=r.trim())}};async function z(e,t){let s,r,i;try{let n=await t.json();typeof n.error=="string"&&(s=n.error),typeof n.code=="string"&&(i=n.code),n.fields&&typeof n.fields=="object"&&(r=Object.fromEntries(Object.entries(n.fields).filter(o=>Array.isArray(o[1])&&o[1].every(c=>typeof c=="string"))))}catch{}throw new _e(e,t.status,s,{fields:r,code:i})}function J(){if(typeof window>"u")return;let e=window.__JUNIOR_DASHBOARD_BASE_PATH__??"/",t=e==="/"?"/auth/login":`${e}/auth/login`;if(window.location.pathname!==t){let s=`${window.location.pathname}${window.location.search||""}`,r=new URLSearchParams;s!=="/"&&r.set("next",s);let i=r.toString();window.location.assign(i?`${t}?${i}`:t)}}async function Pi(e,t,s){let r=await W(t,{body:JSON.stringify(s),credentials:"same-origin",headers:{"content-type":"application/json"},method:"PATCH"});return r.status===401&&J(),r.ok||await z(t,r),e.parse(await r.json())}async function Ci(e,t,s){let r=await W(t,{body:JSON.stringify(s),credentials:"same-origin",headers:{"content-type":"application/json"},method:"POST"});return r.status===401&&J(),r.ok||await z(t,r),e.parse(await r.json())}async function Qi(e,t,s){let r=await W(t,{body:JSON.stringify(s),credentials:"same-origin",headers:{"content-type":"application/json"},method:"PUT"});return r.status===401&&J(),r.ok||await z(t,r),e.parse(await r.json())}async function Mi(e){let t=await W(e,{credentials:"same-origin",method:"DELETE"});t.status===401&&J(),t.ok||await z(e,t)}async function xi(e,t,s={}){let r=await W(t,{body:JSON.stringify(s),credentials:"same-origin",headers:{"content-type":"application/json"},method:"DELETE"});return r.status===401&&J(),r.ok||await z(t,r),e.parse(await r.json())}async function W(e,t){let s=await fetch(e,t);return yt(s),s}async function Ti(e,t,s){let r=await Nt(t,s);return e.parse(await r.json())}async function Nt(e,t,s){let r=await W(e,{credentials:"same-origin",...t?{signal:t}:void 0,...s?{cache:"no-store",headers:s}:void 0});return r.status===401&&J(),!r.ok&&!(s&&r.status===304)&&await z(e,r),r}export{Rt as a,L as b,Pt as c,I as d,xt as e,qt as f,It as g,kt as h,At as i,jt as j,wi as k,_e as l,Pi as m,Ci as n,Qi as o,Mi as p,xi as q,Ti as r,Nt as s};
@@ -1 +0,0 @@
1
- import{H as At,l as E,m as Ct,n as Nt,o as wt,w as St}from"./chunk-R4ORRE77.js";import{a as pe}from"./chunk-5ZA674OU.js";import{a as yt,c as xt,d as kt}from"./chunk-FVX42XAD.js";import{l as se}from"./chunk-A2QWWA7O.js";import{a as R}from"./chunk-EFEREKX4.js";import{a as ie,b as re,c as Rt}from"./chunk-LKW7MULF.js";import{e as Tt}from"./chunk-564V7YHG.js";import{B as ge,D as bt,F as q,G as ht,H as oe,I as gt,O as pt,f as _,g as ae,k as dt,r as z,t as V,u as ut,v as mt,x as G,y as ft,z as vt}from"./chunk-NQMDED2R.js";import{i as U,j as L,l as P,m as tt}from"./chunk-GMZIELFU.js";import{a as st,b as lt,c as ct}from"./chunk-MTBUV2GJ.js";import{d as X,g as Pe,h as ve,i as _e,m as it,r as rt}from"./chunk-GO45RQDL.js";import{fa as at,i as te,j as nt,la as ot}from"./chunk-VXT3FIVL.js";import{d as ze,f as Ee,o as W}from"./chunk-6PHJZPWD.js";import{b as je}from"./chunk-CR2ICLSH.js";import{Db as We,Fb as Ve,Fc as Xe,Gc as Je,Ib as Ge,Jb as ee,Jc as Ze,Kb as qe,Lc as et,Qa as Oe,Rc as u,Tc as he,Ua as J,Va as $e,Vb as He,Wb as K,Wc as ne,a as k,b as f,bb as Fe,hc as Ye,kb as F,mb as Ke,ob as Qe,qb as Z,rc as be,tb as Be}from"./chunk-YPMUHXYT.js";import{c}from"./chunk-7SZRL6FY.js";var An={key:"pinned",label:"Pinned",order:-2},Tn={key:"attention",label:"Needs attention",order:-1};function Dt(e,t){let n=Ut(t.nowMs,t.timeZone),a=new Map,o=[...e].sort((i,r)=>ye(r)-ye(i));for(let i of o){let r=i.pinnedAt?An:t.attentionIds?.has(i.id)?Tn:kn(ye(i),n,t.nowMs,t.timeZone),d=a.get(r.key);d?d.conversations.push(i):a.set(r.key,{...r,conversations:[i]})}return[...a.values()].sort((i,r)=>i.order-r.order).map(({order:i,...r})=>r)}function Mt(e,t){return new Set([...e,...t])}function ya(e,t){let n=a=>a.pinnedAt?0:t.has(a.id)?1:2;return[...e].sort((a,o)=>n(a)-n(o))}function ye(e){let t=Date.parse(e.lastSeenAt);return Number.isFinite(t)?t:Number.NEGATIVE_INFINITY}function kn(e,t,n,a){if(!Number.isFinite(e))return{key:"older",label:"Older",order:Number.POSITIVE_INFINITY};let o=Math.max(0,Math.round((t-Ut(e,a))/864e5));if(o===0)return{key:"today",label:"Today",order:0};if(o===1)return{key:"yesterday",label:"Yesterday",order:1};if(o<=7)return{key:"previous-7-days",label:"Previous 7 days",order:2};if(o<=30)return{key:"previous-30-days",label:"Previous 30 days",order:3};let i=It(e,a),r=It(n,a);return{key:`month-${i.year}-${i.month}`,label:new Intl.DateTimeFormat("en-US",{month:"long",timeZone:a,...i.year===r.year?void 0:{year:"numeric"}}).format(e),order:4+(r.year-i.year)*12+(r.month-i.month)}}function It(e,t){let n=new Intl.DateTimeFormat("en-US",{month:"numeric",timeZone:t,year:"numeric"}).formatToParts(e),a=new Map(n.map(o=>[o.type,Number(o.value)]));return{month:a.get("month")??1,year:a.get("year")??0}}function Ut(e,t){let n=new Intl.DateTimeFormat("en-US",{day:"numeric",month:"numeric",timeZone:t,year:"numeric"}).formatToParts(e),a=new Map(n.map(o=>[o.type,Number(o.value)]));return Date.UTC(a.get("year")??0,(a.get("month")??1)-1,a.get("day")??1)}var xe=c(f(),1),Rn={neutral:"text-dashboard-text-muted",success:"text-emerald-500",danger:"text-rose-500",warning:"text-amber-500",info:"text-cyan-500",accent:"text-violet-400"};function O(e){let t=te(e),n=[t.label,e.status].filter(Boolean).join(": ");return(0,xe.jsx)("svg",{"aria-hidden":e.decorative?!0:void 0,"aria-label":e.decorative?void 0:n,role:e.decorative?void 0:"img",className:u("inline-block shrink-0 align-middle",Rn[t.tone],e.className),width:e.size??16,height:e.size??16,viewBox:"0 0 16 16",fill:"currentColor",children:nt[t.icon].map(a=>(0,xe.jsx)("path",{d:a},a))})}var Zt=c(k(),1);var Ce=c(f(),1);function j(e){if(!e.active&&!e.className&&!e["aria-label"])return e.children;let t=u(e.active&&"shimmer",e.className);return e.as==="strong"?(0,Ce.jsx)("strong",{"aria-label":e["aria-label"],className:t,children:e.children}):(0,Ce.jsx)("span",{"aria-label":e["aria-label"],className:t,children:e.children})}var h=c(f(),1);function In(e){return(0,h.jsx)("span",{className:"grid min-w-0 self-start grid-cols-[minmax(0,1fr)_auto] content-start gap-x-3 gap-y-1.5",children:e.lines.map((t,n)=>(0,h.jsxs)("span",{className:t.label?"contents":u("col-span-2 block min-w-0 break-words text-dashboard-text",t.valueStyle==="heading"&&"font-sans tabular-nums font-semibold text-dashboard-text",t.valueStyle==="heading"&&n>0&&"mt-1 border-t border-dashboard-border-strong pt-2"),children:[t.label?(0,h.jsx)("span",{className:u("min-w-0 break-words font-medium text-dashboard-text-muted",t.labelStyle==="code"&&"break-all font-mono text-xs text-dashboard-text"),children:t.label}):null,t.label?(0,h.jsx)("span",{className:"whitespace-nowrap text-right text-dashboard-text",children:t.value}):(0,h.jsxs)(h.Fragment,{children:[t.value,t.live?(0,h.jsxs)("span",{className:"ml-2 inline-flex items-center gap-1.5 font-sans text-xs font-normal tracking-wide text-dashboard-text-muted",children:[(0,h.jsx)("span",{"aria-hidden":"true",children:"\xB7"}),(0,h.jsx)(j,{active:!0,children:"in progress"})]}):null]})]},`${n}-${t.label??""}-${t.value}-${t.live?"live":""}`))})}function H(e){let t=e.tooltip?.filter(n=>n.value.trim());return!e.tooltipCard&&!t?.length?(0,h.jsx)("span",{className:e.className,children:e.children}):(0,h.jsxs)(U,{children:[(0,h.jsx)(L,{render:(0,h.jsx)("span",{className:u("inline-flex border-b border-dotted border-dashboard-border-interactive outline-none transition-colors hover:border-dashboard-border-heavy focus-visible:border-dashboard-border-heavy",e.className),tabIndex:0,children:e.children})}),(0,h.jsx)(P,{align:e.align==="left"?"start":e.align==="right"?"end":"center",className:u("w-[calc(100vw-2rem)] max-w-80 rounded-lg bg-dashboard-bg text-left font-normal shadow-xl shadow-black/35",e.tooltipCard?"p-3 leading-snug":"px-3 py-2 leading-relaxed"),side:e.tooltipPlacement==="above"?"top":"bottom",children:e.tooltipCard?(0,h.jsx)("span",{className:"block max-h-[min(30rem,var(--available-height,30rem))] overflow-y-auto",children:e.tooltipCard}):t?(0,h.jsx)("span",{className:"block max-h-72 overflow-y-auto",children:(0,h.jsx)(In,{lines:t})}):null})]})}var m=c(f(),1),Lt="bg-dashboard-focus/80",Pt="bg-dashboard-focus/30";function _t(e){return(0,m.jsx)("span",{"aria-hidden":"true",className:u("size-2 shrink-0 rounded-xs",e.className)})}function Ne(e){let t=Math.min(100,Math.max(0,(e.split?.selfShare??1)*100));return(0,m.jsxs)("span",{className:"grid gap-3",children:[(0,m.jsxs)("span",{className:u("grid gap-2.5",e.sections.length>0&&"border-b border-dashboard-border pb-3"),children:[(0,m.jsxs)("span",{className:"flex items-baseline justify-between gap-3",children:[(0,m.jsxs)("span",{className:"min-w-0 truncate font-medium text-dashboard-text",children:[e.title,e.note?(0,m.jsxs)("span",{className:"text-dashboard-text-faint",children:[" \xB7 ",e.note]}):null]}),(0,m.jsx)("span",{className:"whitespace-nowrap text-base font-semibold tabular-nums text-dashboard-text",children:e.total})]}),e.split?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsxs)("span",{"aria-hidden":"true",className:"flex h-1.5 overflow-hidden rounded-full bg-dashboard-fill-hover",children:[(0,m.jsx)("span",{className:Lt,style:{width:`${t}%`}}),(0,m.jsx)("span",{className:Pt,style:{width:`${100-t}%`}})]}),(0,m.jsxs)("span",{className:"flex flex-wrap justify-between gap-x-3 gap-y-1 tabular-nums",children:[(0,m.jsxs)("span",{className:"inline-flex items-center gap-1.5 whitespace-nowrap",children:[(0,m.jsx)(_t,{className:Lt}),"this agent",(0,m.jsx)("span",{className:"font-medium text-dashboard-text",children:e.split.self})]}),(0,m.jsxs)("span",{className:"inline-flex items-center gap-1.5 whitespace-nowrap",children:[(0,m.jsx)(_t,{className:Pt}),e.split.count," subagent",e.split.count===1?"":"s",(0,m.jsx)("span",{className:"font-medium text-dashboard-text",children:e.split.subagents})]})]})]}):null]}),e.sections.map(n=>(0,m.jsxs)("span",{className:"grid grid-cols-[minmax(0,1fr)_auto] gap-x-3 gap-y-2",children:[(0,m.jsxs)("span",{className:"col-span-2 font-sans font-medium text-dashboard-text-faint",children:[n.title,n.total?` \xB7 ${n.total}`:null]}),n.rows.map(a=>(0,m.jsxs)("span",{className:"contents",children:[(0,m.jsxs)("span",{className:u("flex min-w-0 items-baseline gap-2",a.code&&"font-mono"),children:[(0,m.jsx)("span",{className:"min-w-0 truncate",title:a.label,children:a.label}),a.live?(0,m.jsx)("span",{className:"shrink-0 font-sans text-2xs text-dashboard-text-muted",children:(0,m.jsx)(j,{active:!0,children:"in progress"})}):null]}),(0,m.jsx)("span",{className:"whitespace-nowrap text-right tabular-nums text-dashboard-text",children:a.value})]},a.label)),n.more?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsxs)("span",{className:"text-dashboard-text-faint",children:[n.more.count," more"]}),(0,m.jsx)("span",{className:"whitespace-nowrap text-right tabular-nums",children:n.more.value})]}):null]},n.title))]})}var I=c(f(),1);function Ae(e,t){return`${z(t)} ${e}${t===1?"":"s"}`}function Dn(e){return!!e}function Mn(e){return[["input",e.inputTokens],["output",e.outputTokens],["cached",e.cachedInputTokens],["cache write",e.cacheCreationTokens],["reasoning",e.reasoningTokens]].flatMap(([t,n])=>n?[{label:t,value:z(n)}]:[])}function Et(e){return{cost:(G(e?.cumulativeUsage)?.total??0)+(e?.auxiliaryCostUsd??0),tokens:V(e?.cumulativeUsage)?.totalTokens??0}}function Ot(e,t){return Math.min(Math.max(0,e),Math.max(0,t))}function Un(e,t,n,a){if(!e)return[];let o=Ot(n,t);return[{value:"By agent",valueStyle:"heading"},{label:"this agent",value:a(t-o)},{label:Ae("subagent",e.count),value:a(o)}]}function we(e){return e.split("/").at(-1)??e}function Ln(e,t){return{live:e===t,value:we(e),valueStyle:"heading"}}var jt=4,Pn=3;function Se(e,t,n){if(e.length<=t+1)return{rows:e};let a=e.slice(t);return{more:{count:a.length,value:n(a.reduce((o,i)=>o+i.amount,0))},rows:e.slice(0,t)}}function $t(e,t,n,a,o){let i=(e??[]).flatMap(r=>{let d=n(r.usage);return d?[{amount:a(d),modelId:r.modelId}]:[]}).sort((r,d)=>d.amount-r.amount).map(r=>({amount:r.amount,code:!0,label:we(r.modelId),live:r.modelId===t,value:o(r.amount)}));return t&&!i.some(r=>r.live)&&i.unshift({amount:0,code:!0,label:we(t),live:!0,value:"\u2026"}),i}function Ft(e,t,n,a){if(!e)return;let o=Ot(n,t);return{count:e.count,self:a(t-o),selfShare:t>0?(t-o)/t:1,subagents:a(o)}}function zt(e){return new Intl.NumberFormat("en-US",{currency:"USD",maximumFractionDigits:e,minimumFractionDigits:e,style:"currency"})}function _n(e){let t=e>=10?2:e>=1?3:4,n=zt(t),a=zt(4);return o=>o>0&&o<.5*10**-t?a.format(o):n.format(o)}function zn(e,t,n,a,o){let i=$t(t,a,V,r=>r.totalTokens,z);return{note:n?Ae("compaction",n):void 0,sections:i.length?[{title:"By model",...Se(i,jt,z)}]:[{rows:Mn(e),title:"By type"}].filter(r=>r.rows.length),split:Ft(o,e.totalTokens,Et(o).tokens,z),title:"Tokens",total:z(e.totalTokens)}}function En(e,t){return[["input",e.input],["output",e.output],["cache read",e.cacheRead],["cache write",e.cacheWrite]].flatMap(([n,a])=>a===void 0?[]:[{label:n,value:t(a)}])}function On(e,t,n,a,o){let i=ge(e,n);if(!i)return;let r=_n(i.total),d=$t(t,a,G,p=>p.total,r),y=[...n?.operations??[]].sort((p,C)=>C.costUsd-p.costUsd).map(p=>({amount:p.costUsd,label:jn(p),value:r(p.costUsd)})),x=[];if(d.length)x.push({title:"By model",...Se(d,jt,r)});else if(e){let p=En(e,r);p.length&&x.push({rows:p,title:"By type"})}return n&&y.length&&x.push({title:"Auxiliary",total:r(n.costUsd),...Se(y,Pn,r)}),{sections:x,split:Ft(o,i.total,Et(o).cost,r),title:"Estimated cost",total:r(i.total)}}function jn(e){let t={"junior/guardian_action_reviewed":"Guardian","junior/passive_reply_routed":"Passive reply routing","junior/turn_routed":"Thinking routing","memory/memories_captured":"Memory extraction","memory/memories_recalled":"Memory recall","memory/task_model_called":"Memory extraction","memory/user_prompt_model_called":"Memory recall"},n=`${e.namespace}/${e.name}`;return t[n]??`${e.namespace} \xB7 ${e.name.replaceAll("_"," ")}`}function Kt(e){let t=ft(e.modelUsage)??e.summary,n=ge(t,e.auxiliaryCosts);if(!n&&!e.live)return null;let a=!!e.live,o=n?`${vt(n)}${a?"+":""}`:"$\u2026",i=On(t,e.modelUsage,e.auxiliaryCosts,e.liveModelId,e.childAgentTotals);return(0,I.jsx)(H,{align:e.align,tooltipPlacement:e.tooltipPlacement??"above",tooltip:!i&&e.liveModelId?[Ln(e.liveModelId,e.liveModelId)]:void 0,tooltipCard:i?(0,I.jsx)(Ne,{...i}):void 0,children:(0,I.jsx)(j,{active:a,children:o})})}function Qt(e){return e.summary?(0,I.jsx)(H,{align:e.align,tooltipCard:(0,I.jsx)(Ne,{...zn(e.summary,e.modelUsage,e.compactionCount,e.liveModelId,e.childAgentTotals)}),children:(0,I.jsx)(j,{active:e.live,children:mt(e.summary)})}):null}function Bt(e){if(!e.label||e.label==="none")return null;let n=[e.startedAt?{label:"started",value:_(e.startedAt)}:void 0,e.endedAt?{label:"ended",value:_(e.endedAt)}:void 0,...Un(e.childAgentTotals,e.durationMs??0,e.childAgentTotals?.cumulativeDurationMs??0,a=>dt(a)||"0s")].filter(Dn);return(0,I.jsx)(H,{align:e.align,tooltip:n,children:e.label})}function Wt(e){if(!e.childAgentTotals)return null;let t=Ae("subagent",e.childAgentTotals.count);return(0,I.jsx)(H,{tooltip:[{value:`Tokens, cost, and runtime include ${t} at any depth.`}],children:t})}function $n(e){let t=new Map,n=[];for(let a of e){let o=t.get(a.label);if(!o){t.set(a.label,[a]),n.push(a.label);continue}o.push(a)}return n.map(a=>({label:a,annotations:t.get(a)??[]}))}function Vt(e){let t=$n(e);return{groups:t,labeledGroups:t.slice(0,2),overflowGroupCount:Math.max(0,t.length-2)}}var qt=c(k(),1);var b=c(f(),1);function Ka(e){return(0,b.jsxs)("section",{"aria-label":e.label,className:"grid min-w-0 gap-2.5 rounded-lg border border-dashboard-border-subtle bg-dashboard-surface-panel p-3",children:[e.title?(0,b.jsxs)("h3",{className:"m-0 flex min-w-0 items-center gap-1.5 break-words font-sans text-xs font-medium text-dashboard-text-muted",children:[e.title,e.count?(0,b.jsx)("span",{className:"tabular-nums text-dashboard-text-faint",children:e.count.toLocaleString("en-US")}):null]}):null,(0,b.jsx)("div",{className:"min-w-0 break-words font-sans text-xs leading-relaxed text-dashboard-text-muted",children:e.children})]})}var Gt=3;function le(e){let[t,n]=(0,qt.useState)(!1),a=e.items.length-Gt,o=t||a<=0?e.items:e.items.slice(0,Gt);return(0,b.jsxs)("ul",{className:"-mx-1.5 -mb-1.5 -mt-1 grid list-none gap-0.5 p-0",children:[o.map(i=>(0,b.jsx)("li",{children:e.renderItem(i)},e.itemKey(i))),a>0?(0,b.jsx)("li",{children:(0,b.jsxs)("button",{"aria-expanded":t,className:"group flex min-h-8 w-full items-center gap-2.5 rounded-md px-1.5 py-1.5 text-left text-xs font-medium leading-4 text-dashboard-text-muted transition-colors hover:bg-dashboard-surface-hover hover:text-dashboard-text focus-visible:outline focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-dashboard-focus",onClick:()=>n(i=>!i),type:"button",children:[(0,b.jsx)("span",{className:"grid size-5 shrink-0 place-items-center",children:(0,b.jsx)(F,{"aria-hidden":"true",className:ne})}),t?"Show fewer":`Show ${a} more`]})}):null]})}function Y(e){let t=e.href!==void 0||e.disclosure===!0,n=u("grid w-full min-w-0 grid-cols-[auto_minmax(0,1fr)_auto] items-start gap-x-2.5 gap-y-1 rounded-md px-1.5 py-1.5 text-left text-inherit no-underline",t&&"group transition-colors hover:bg-dashboard-surface-hover focus-visible:outline focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-dashboard-focus"),a=(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)("span",{className:"grid size-5 shrink-0 place-items-center text-dashboard-text-muted",children:e.icon}),(0,b.jsx)("span",{className:"min-w-0 truncate text-sm font-medium leading-5 text-dashboard-text",children:e.title}),(0,b.jsx)("span",{className:"shrink-0 text-xs leading-5 tabular-nums text-dashboard-text-muted",children:e.meta}),e.children]});return e.href?(0,b.jsx)("a",{className:n,href:e.href,rel:"noreferrer",target:"_blank",title:e.tooltip,children:a}):e.disclosure?(0,b.jsx)(re,{className:n,title:e.tooltip,children:a}):(0,b.jsx)("div",{className:n,title:e.tooltip,children:a})}function Ht(e){return(0,b.jsx)("div",{className:u("col-start-2 col-end-4 min-w-0 text-xs leading-4 text-dashboard-text-muted",e.className),children:e.children})}var v=c(f(),1);function eo(e){return Pe({queryFn:({signal:t})=>rt(ot,`/api/conversations/${encodeURIComponent(e)}/watches`,t),queryKey:Ct(e,"watches"),retry:!1})}function to(e){return(0,v.jsx)(le,{itemKey:t=>t.id,items:e.watches,renderItem:t=>(0,v.jsx)(Kn,{watch:t})})}var Fn={channel:qe,deployment:be,deployment_source:be,issue:Z,pull_request:ee,release_source:Xe,repository:Ve,team:et,timer:Je,workspace_snapshot:Ye};function Kn(e){let{watch:t}=e,n=t.redacted?K:Fn[t.resourceType]??We,a=`${t.namespace} ${t.resourceType.replaceAll("_"," ")}`,o=(0,v.jsx)(n,{"aria-hidden":"true",className:"size-3.5"}),i=t.label??`Private ${a}`;return(0,v.jsxs)(ie,{className:"min-w-0",children:[t.url?(0,v.jsx)(Te,{label:i,children:(0,v.jsx)(Y,{href:t.url,icon:o,title:i})}):(0,v.jsx)(Y,{disclosure:!0,icon:o,meta:(0,v.jsx)(Xt,{}),title:i}),(0,v.jsx)(ke,{watches:[t]})]})}function Te(e){return(0,v.jsxs)("div",{className:"flex min-w-0 items-start gap-0.5",children:[(0,v.jsx)("div",{className:"min-w-0 flex-1",children:e.children}),(0,v.jsx)(re,{"aria-label":`Details for ${e.label}`,className:"group grid size-8 shrink-0 place-items-center rounded-md text-dashboard-text-muted transition-colors hover:bg-dashboard-surface-hover hover:text-dashboard-text focus-visible:outline focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-dashboard-focus",children:(0,v.jsx)(Xt,{})})]})}function Xt(){return(0,v.jsx)("span",{className:"grid size-5 place-items-center",children:(0,v.jsx)(F,{"aria-hidden":"true",className:ne})})}function ke(e){return(0,v.jsx)(Rt,{className:"grid min-w-0 gap-3 pb-2 pl-9 pr-1.5 pt-0.5 text-xs leading-4 text-dashboard-text-muted",children:e.watches.map(t=>(0,v.jsx)(Qn,{watch:t},t.id))})}function Qn(e){let{watch:t}=e,n=t.firesAt?[]:t.events,a=Object.entries(t.match??{});return(0,v.jsxs)("div",{className:"grid min-w-0 gap-1.5",children:[t.intent?(0,v.jsx)("p",{className:"m-0 break-words",children:(0,v.jsx)(se,{inline:!0,text:t.intent})}):null,t.firesAt?(0,v.jsxs)("p",{className:"m-0",children:["Fires"," ",(0,v.jsx)("time",{dateTime:t.firesAt,children:_(t.firesAt,{dateStyle:"medium",timeStyle:"short"})})]}):null,n.length>0||a.length>0?(0,v.jsxs)("div",{className:"flex flex-wrap items-center gap-1",children:[n.map(o=>(0,v.jsx)(Yt,{children:Bn(o,t.resourceType)},o)),a.map(([o,i])=>(0,v.jsxs)(Yt,{filter:!0,children:[o.replaceAll("_"," "),": ",[i].flat().join(", ")]},`match:${o}`))]}):null,t.childAgent?(0,v.jsxs)("p",{className:"m-0 flex min-w-0 items-center gap-1",children:[(0,v.jsx)(Fe,{"aria-hidden":"true",className:"size-3 shrink-0"}),(0,v.jsxs)("span",{className:"truncate",children:["via ",t.childAgent.name??"subagent"]})]}):null]})}function Yt(e){return(0,v.jsx)("span",{className:e.filter?"min-w-0 truncate rounded-md border border-dashed border-dashboard-border px-1.5 py-px text-xs leading-4 text-dashboard-text-muted":"min-w-0 truncate rounded-md bg-dashboard-fill-soft px-1.5 py-px text-xs leading-4 text-dashboard-text-subtle",children:e.children})}function Bn(e,t){let n=e.split(".");return(n[0]===t&&n.length>1?n.slice(1):n).join(" ").replaceAll("_"," ")}var N=c(f(),1),Wn={closed:"Closed",draft:"Draft",merged:"Merged",open:"Open",warning:"Needs attention"};function Re(e){return e?Wn[e]??e.charAt(0).toUpperCase()+e.slice(1):""}function so(e){return(e?.annotations??[]).flatMap(t=>{if(!t.url)return[];let n=t.objectType??e?.sidebarAnnotations?.find(o=>o.key===t.key)?.objectType??"item",a=t.kind==="object"&&t.title!==t.label?t.title:t.description;return[{...a?{description:a}:void 0,...t.kind==="object"&&t.facts?{facts:t.facts}:void 0,key:`${t.plugin}:${t.key}`,label:t.label,objectType:n,plugin:t.plugin,...t.status?{status:t.status}:void 0,url:t.url}]})}function lo(e){return(0,N.jsx)(le,{itemKey:t=>t.key,items:e.links,renderItem:t=>{let n=(0,N.jsx)(Gn,{link:t}),a=e.watchesByUrl.get(t.url);return a?(0,N.jsxs)(ie,{className:"min-w-0",children:[(0,N.jsx)(Te,{label:t.label,children:n}),(0,N.jsx)(ke,{watches:a})]}):e.watchesByUrl.size>0?(0,N.jsx)(Vn,{children:n}):n}})}function Vn(e){return(0,N.jsxs)("div",{className:"flex min-w-0 items-start gap-0.5",children:[(0,N.jsx)("div",{className:"min-w-0 flex-1",children:e.children}),(0,N.jsx)("span",{"aria-hidden":"true",className:"size-8 shrink-0"})]})}function Gn(e){let{link:t}=e,n=Re(t.status);return(0,N.jsx)(Y,{href:t.url,icon:(0,N.jsx)(O,{decorative:!0,facts:t.facts,objectType:t.objectType,size:14,status:t.status}),meta:n,title:t.label,tooltip:[t.label,t.plugin,n,t.description].filter(Boolean).join(" \xB7 "),children:t.description?(0,N.jsx)(Ht,{className:"line-clamp-2 break-words",children:t.description}):null})}var l=c(f(),1),on=c(k(),1),Jt="(max-width: 767px)";function Co(e){return(0,l.jsxs)("div",{className:"mb-2 rounded-lg border border-dashboard-accent/20 bg-dashboard-accent/[0.07] px-3 py-2.5 font-sans text-sm text-dashboard-text",children:[(0,l.jsx)("a",{className:"font-medium text-dashboard-accent-text underline decoration-dashboard-accent/40 underline-offset-2 hover:text-dashboard-accent-text",href:e.authorization.authorizationUrl,rel:"noreferrer",target:"_blank",children:e.authorization.label}),(0,l.jsx)("p",{className:"mb-0 mt-1 text-xs text-dashboard-text-muted",children:e.authorization.completionText})]})}function No(e){if(e.visibility!=="private")return null;let t="Private conversation. Only members of this conversation can see this transcript.";return(0,l.jsxs)("span",{className:"inline-flex items-center text-dashboard-text-muted",role:"note",title:t,children:[(0,l.jsx)(K,{"aria-hidden":"true",className:"size-3.5 shrink-0"}),(0,l.jsx)("span",{className:"sr-only",children:t})]})}function en(e){let t=e.annotations,n=Xn();if(!t?.length)return null;let a=t.map(d=>Jn(d)),o=Vt(t),i=n&&o.groups.length>1,r=i?o.groups.flatMap(d=>d.annotations):[];return(0,l.jsxs)(U,{children:[(0,l.jsx)(L,{render:(0,l.jsx)("span",{"aria-label":`Linked work, newest first: ${a.join(", ")}`,className:"inline-flex min-w-0 max-w-full items-center",children:i?(0,l.jsx)(qn,{annotations:r,cutoutColor:"var(--color-dashboard-surface-panel)"}):(0,l.jsxs)("span",{className:"inline-flex min-w-0 items-center gap-1",children:[o.labeledGroups.map(d=>(0,l.jsx)(Hn,{group:d},d.label)),o.overflowGroupCount>0?(0,l.jsxs)("span",{className:"inline-flex h-5 min-w-7 shrink-0 items-center justify-center rounded-full border border-dashboard-border-strong bg-dashboard-control px-1.5 font-sans text-2xs tabular-nums leading-none text-dashboard-text-muted",children:["+",o.overflowGroupCount]}):null]})})}),(0,l.jsxs)(P,{align:"start",children:[(0,l.jsx)(tt,{children:"Linked work"}),(0,l.jsx)("ul",{className:"m-0 list-none space-y-1 p-0",children:t.map((d,y)=>(0,l.jsxs)("li",{className:"flex min-w-0 items-center gap-1.5",children:[d.objectType?(0,l.jsx)(O,{...d,objectType:d.objectType,size:14}):d.icon?(0,l.jsx)(Ie,{icon:d.icon}):null,(0,l.jsx)("span",{className:"min-w-0 truncate",children:a[y]})]},`${d.key}:${y}`))})]})]})}function qn(e){return(0,l.jsx)("span",{className:u("relative isolate inline-flex h-[18px] items-center pr-0.5",e.className),children:e.annotations.map((t,n)=>(0,l.jsx)(Yn,{annotation:t,cutoutColor:e.cutoutColor,stacked:n>0,zIndex:n+1},t.key))})}function Hn(e){return(0,l.jsxs)("span",{className:"inline-flex h-5 min-w-0 max-w-60 shrink-0 items-center gap-1 truncate rounded-full border border-dashboard-border-strong bg-dashboard-control px-1.5 font-sans text-2xs leading-none text-dashboard-text-muted",children:[e.group.annotations.map(t=>t.objectType?(0,on.createElement)(O,{...t,objectType:t.objectType,key:t.key,decorative:!0,size:14}):t.icon?(0,l.jsx)(Ie,{decorative:!0,icon:t.icon,size:11},t.key):null),(0,l.jsx)("span",{className:"min-w-0 truncate whitespace-nowrap",children:e.group.label})]})}function Yn(e){let t=e.annotation.icon?tn[e.annotation.icon]:void 0;return(0,l.jsx)("span",{"aria-hidden":"true",className:u("relative box-border inline-flex size-[18px] shrink-0 items-center justify-center rounded-full border border-dashboard-border-strong bg-dashboard-control",e.stacked&&"-ml-1"),style:{boxShadow:`0 0 0 2px ${e.cutoutColor}`,zIndex:e.zIndex},title:t?.label,children:e.annotation.objectType?(0,l.jsx)(O,{...e.annotation,objectType:e.annotation.objectType,decorative:!0,size:12}):e.annotation.icon?(0,l.jsx)(Ie,{decorative:!0,icon:e.annotation.icon,size:11}):(0,l.jsx)("span",{className:"font-sans text-2xs font-semibold leading-none text-dashboard-text-muted",children:e.annotation.label.slice(0,1)})})}function Xn(){return(0,Zt.useSyncExternalStore)(e=>{if(typeof window>"u")return()=>{};let t=window.matchMedia(Jt);return t.addEventListener("change",e),()=>t.removeEventListener("change",e)},()=>typeof window<"u"&&window.matchMedia(Jt).matches,()=>!1)}function Jn(e){let t=e.objectType?[te({objectType:e.objectType}).label,e.status].filter(Boolean).join(": "):"",n=e.key.includes("/")||e.key.includes("#")?e.key:e.label;return[t,n].filter(Boolean).join(" \xB7 ")}var tn={"circle-dot":{className:"text-[#3fb950] light:text-[#1a7f37]",Icon:Z,label:"Open"},"circle-dashed":{className:"text-[#8c959f] light:text-[#59636e]",Icon:Qe,label:"Draft"},"circle-x":{className:"text-[#f85149] light:text-[#cf222e]",Icon:Be,label:"Closed"},"git-merge":{className:"text-[#a371f7] light:text-[#8250df]",Icon:Ge,label:"Merged"},"git-pull-request":{className:"text-[#3fb950] light:text-[#1a7f37]",Icon:ee,label:"Open pull request"},"triangle-alert":{className:"text-[#d29922] light:text-[#9a6700]",Icon:Ze,label:"Needs attention"}};function Ie(e){let t=tn[e.icon],n=e.size??11;return(0,l.jsxs)("span",{"aria-hidden":e.decorative?!0:void 0,className:u("inline-flex shrink-0 items-center justify-center leading-none",t.className),style:{width:n,height:n},title:e.decorative?void 0:t.label,children:[(0,l.jsx)(t.Icon,{"aria-hidden":"true",className:"block",size:n,strokeWidth:2.25}),e.decorative?null:(0,l.jsx)("span",{className:"sr-only",children:t.label})]})}function wo(e){return(0,l.jsx)("div",{className:"flex gap-x-4 gap-y-2 overflow-x-auto",children:e.links.map(t=>(0,l.jsxs)("a",{className:"inline-flex min-w-0 max-w-full shrink-0 items-center gap-2 rounded-md px-1 py-0.5 font-sans text-xs leading-snug text-dashboard-text no-underline transition-colors hover:text-dashboard-accent-text focus-visible:outline focus-visible:outline-2 focus-visible:outline-dashboard-focus",href:t.url,rel:"noreferrer",target:"_blank",title:[t.label,t.plugin,Re(t.status),t.description].filter(Boolean).join(" \xB7 "),children:[(0,l.jsx)(O,{facts:t.facts,objectType:t.objectType,size:16,status:t.status}),(0,l.jsx)("span",{className:"min-w-0 break-words",children:t.label})]},t.key))})}function Zn(e){return e.locationUrl?(0,l.jsx)("a",{className:he,href:e.locationUrl,rel:"noreferrer",target:"_blank",children:e.label}):e.label}function ea(e){let t=e.sourceTask.id?.trim(),n=e.sourceTask.title?.trim(),a=n?`Automation: ${n}`:"Automation";return t?(0,l.jsx)(W,{className:he,to:pt(t),children:a}):(0,l.jsx)("span",{children:a})}function nn(e){if(!e)return;let t=new Set,n;for(let a of e.events){let o=a.data;if(o.type==="turn_lifecycle"){o.state==="started"?t.add(o.turnId):t.delete(o.turnId),t.size===0&&(n=void 0);continue}t.size>0&&a.model&&(n=a.model.modelId)}return t.size>0?n:void 0}function So(e){return an(e).length>0}function Ao(e){let t=an(e);return t.length===0?null:(0,l.jsx)("dl",{className:"m-0 grid min-w-0 gap-2 text-xs leading-snug",children:t.map(n=>(0,l.jsxs)("div",{className:u("flex min-w-0 items-baseline justify-between gap-4",n.mobileOnly&&"md:hidden"),children:[(0,l.jsx)("dt",{className:"shrink-0 text-dashboard-text-muted",children:n.label}),(0,l.jsx)("dd",{className:"m-0 min-w-0 break-words text-right tabular-nums text-dashboard-text",children:n.content})]},n.key))})}function ta(e,t){if(!e)return null;let n=oe(e,{includeId:!1});return n?(0,l.jsx)(Zn,{label:n,locationUrl:t?.locationUrl??e.locationUrl}):null}function na(e,t,n){if(!e)return null;let a=G(t?.cumulativeUsage??e.cumulativeUsage),o=t?.auxiliaryCosts??e.auxiliaryCosts,i=(t?.status??e.status)==="active";return!a&&!o&&!i?null:(0,l.jsx)(Kt,{auxiliaryCosts:o,childAgentTotals:t?.childAgentTotals??e.childAgentTotals,live:i,liveModelId:nn(t),modelUsage:t?.modelUsage,summary:a,tooltipPlacement:n})}function an(e){if(!e.conversation)return[];let t=e.detail?.previousCursor?void 0:e.detail,n=e.detail?.cumulativeUsage??e.conversation.cumulativeUsage,a=ut(e.detail?.modelUsage)??V(n),o=bt(e.conversation),i=(e.detail?.status??e.conversation.status)==="active",r=nn(e.detail),d=e.detail?.sourceTask,y=e.detail?.childAgentTotals??e.conversation.childAgentTotals,x=e.conversation.lastSeenAt,p=ta(e.conversation,e.detail),C=na(e.conversation,e.detail);return[p?{content:p,key:"location",label:"Location",mobileOnly:!0}:void 0,d?{content:(0,l.jsx)(ea,{sourceTask:d}),key:"source-task",label:"Source"}:void 0,x?{content:(0,l.jsx)("time",{dateTime:x,title:_(x,{dateStyle:"medium",timeStyle:"short"}),children:ae(x)}),key:"last-activity",label:"Last activity"}:void 0,o!=="none"?{content:(0,l.jsx)(Bt,{childAgentTotals:y,durationMs:e.conversation.cumulativeDurationMs,endedAt:e.conversation.lastSeenAt,label:o,startedAt:e.conversation.startedAt}),key:"duration",label:"Runtime"}:void 0,a?{content:(0,l.jsx)(Qt,{childAgentTotals:y,compactionCount:t?t.events.filter(S=>S.data.type==="compaction").length:void 0,live:i,liveModelId:r,modelUsage:e.detail?.modelUsage,summary:a}),key:"tokens",label:"Tokens"}:void 0,C?{content:C,key:"cost",label:"Cost",mobileOnly:!0}:void 0,y?{content:(0,l.jsx)(Wt,{childAgentTotals:y}),key:"subagents",label:"Subagents"}:void 0].filter(S=>S!==void 0)}var sn=c(f(),1);function rn({className:e,...t}){return(0,sn.jsx)(He,{"data-slot":"spinner",role:"status","aria-label":"Loading",className:Oe("size-4 animate-spin motion-reduce:animate-none",e),...t})}var $=c(f(),1);function ln(e){return e.waitingOnViewer?(0,$.jsx)("span",{"aria-label":"Waiting on you",className:"size-2 shrink-0 rounded-full bg-violet-300 shadow-[0_0_6px_rgba(196,181,253,0.7)]",role:"img"}):e.status==="active"?(0,$.jsx)(rn,{"aria-label":"Running",className:"size-3 text-emerald-300"}):e.finishedSinceSeen?(0,$.jsx)("span",{"aria-label":"Finished since last viewed",className:"size-1.5 shrink-0 rounded-full bg-orange-300",role:"img"}):e.isPrivate?(0,$.jsx)(K,{"aria-label":"Private conversation",className:u("size-3 shrink-0",e.status==="failed"&&"text-rose-300",e.status==="idle"&&"text-dashboard-text-muted")}):e.status==="failed"?(0,$.jsx)("span",{"aria-label":"Failed",className:"size-1.5 shrink-0 rounded-full bg-rose-300",role:"img"}):(0,$.jsx)("span",{"aria-hidden":"true",className:"size-1.5 shrink-0 rounded-full bg-dashboard-text-faint"})}var D=c(k(),1);var g=c(f(),1),cn=3;function De(e){return e.fullName?.trim()||e.slackUserName?.trim()||e.email?.trim()||e.slackUserId?.trim()||"Unknown actor"}function ce(e){let t=De(e),n=e.email?.trim();return n&&n!==t?`${t}, ${n}`:t}function dn(e,t){return e.email?.trim().toLowerCase()||e.slackUserId?.trim()||e.slackUserName?.trim()||`${ht(e)??"actor"}:${t}`}function aa(e){let t=De(e.participant),n=e.participant.email?.trim();return(0,g.jsxs)("span",{className:"grid gap-0.5 font-sans",children:[(0,g.jsx)("span",{className:"font-semibold text-dashboard-text",children:t}),n&&n!==t?(0,g.jsx)("span",{className:"font-sans text-dashboard-text-muted",children:n}):null]})}function oa(e){let t=ce(e.participant);return(0,g.jsxs)(U,{children:[(0,g.jsx)(L,{render:(0,g.jsx)("span",{"aria-label":t,role:"img",className:"relative -ml-1 inline-flex rounded-full first:ml-0 pointer-events-none focus-visible:z-10 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-dashboard-focus [@media(hover:hover)_and_(pointer:fine)]:pointer-events-auto",onKeyDown:n=>n.stopPropagation(),tabIndex:0,children:(0,g.jsx)(kt,{imageUrl:e.participant.avatarUrl,name:De(e.participant),size:e.size})})}),(0,g.jsx)(P,{children:(0,g.jsx)(aa,{participant:e.participant})})]})}function un(e){return e?.participants?.length?e.participants:e?.actorIdentity?[e.actorIdentity]:[]}function mn(e){if(e.participants.length===0)return null;let t=e.participants.slice(0,cn),n=e.participants.slice(cn),a=e.participants.map(ce).join("; ");return(0,g.jsxs)("span",{"aria-label":`Conversation participants: ${a}`,className:"inline-flex items-center",role:"group",children:[t.map((o,i)=>(0,g.jsx)(oa,{participant:o,size:e.size},dn(o,i))),n.length>0?(0,g.jsxs)(U,{children:[(0,g.jsx)(L,{render:(0,g.jsx)(yt,{"aria-label":`${n.length} more participants: ${n.map(ce).join("; ")}`,className:"-ml-1 pointer-events-none bg-dashboard-surface-active shadow-none focus-visible:z-10 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-dashboard-focus [@media(hover:hover)_and_(pointer:fine)]:pointer-events-auto",onKeyDown:o=>o.stopPropagation(),size:e.size==="list"?"sm":"default",tabIndex:0,children:(0,g.jsxs)(xt,{className:"tabular-nums tracking-normal text-dashboard-text-muted",children:["+",n.length]})})}),(0,g.jsx)(P,{children:(0,g.jsx)("span",{className:"grid gap-1 font-sans",children:n.map((o,i)=>(0,g.jsx)("span",{children:ce(o)},dn(o,i)))})})]}):null]})}var bn=c(k(),1);var A=c(f(),1);function Me({action:e,children:t,detail:n,icon:a,title:o,tone:i="default"}){let r=i==="error";return(0,A.jsxs)(st,{className:"block gap-0 overflow-hidden rounded-xl p-0 shadow-[0_16px_40px_rgba(0,0,0,0.5)]",role:r?"alert":"status",variant:r?"destructive":"default",children:[(0,A.jsxs)("div",{className:"flex min-w-0 items-center gap-3 px-3 py-3",children:[a?(0,A.jsx)("div",{className:u("grid size-8 shrink-0 place-items-center rounded-lg",r?"bg-rose-300/15 text-rose-100":"bg-dashboard-accent/10 text-dashboard-accent-text/80"),children:(0,A.jsx)(a,{"aria-hidden":"true",size:16})}):null,(0,A.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,A.jsxs)(lt,{className:"font-display text-sm leading-snug",children:[o,n?" ":null]}),n?(0,A.jsx)(ct,{className:u("mt-0.5 truncate font-sans text-xs",r&&"text-rose-100/70"),children:n}):null]}),e]}),t]})}function Ue({className:e,tone:t="default",...n}){return(0,A.jsx)(je,{...n,className:u("h-auto shrink-0 rounded-lg border-0 px-3 py-1.5 text-xs leading-normal",t==="error"?"bg-rose-200/15 text-rose-50 hover:bg-rose-200/25 hover:text-rose-50 focus-visible:outline-rose-300/55 data-disabled:hover:bg-rose-200/15 data-disabled:hover:text-rose-50":"bg-dashboard-accent/10 text-dashboard-accent-text hover:bg-dashboard-accent/20 hover:text-dashboard-accent-text data-disabled:hover:bg-dashboard-accent/10 data-disabled:hover:text-dashboard-accent-text",e)})}function fn(e){return["dashboard","archived-conversation",e]}function ia(e){let t=e[e.length-1];return t==="active"||t==="archived"?t:void 0}var Le=["dashboard","archive-conversation"];function Go(){return ve({filters:{mutationKey:Le,status:"pending"},select:e=>{let t=e.state.variables,n=e.state.context,a=e.options.mutationKey?.[2];return{archived:t.archived,conversation:n?.archivedSnapshot?.conversation,conversationId:typeof a=="string"?a:""}}})}function vn(e){let t=ve({filters:{exact:!0,mutationKey:[...Le,e]},select:n=>n.state.status});return e?t.at(-1):void 0}function de(e,t){let n=X();return _e({mutationKey:[...Le,e],mutationFn:a=>it(at,`/api/conversations/${encodeURIComponent(e)}/archive`,a),onMutate:async a=>{let o={queryKey:["dashboard","conversations"]},i=E(e),r=fn(e);await Promise.all([n.cancelQueries(o),n.cancelQueries({queryKey:i})]);let d=n.getQueriesData(o),y=n.getQueryData(i),x=n.getQueryData(r),p=a.archived?new Date().toISOString():null,C=a.archived?{archivedAt:p,pinnedAt:null}:{archivedAt:p},w=ra(d,e)??x;return d.forEach(([S,B])=>{if(!B)return;let Cn=B.conversations.some(M=>M.conversationId===e),Nn=ia(S),wn=!a.archived&&!Cn&&!!w&&Nn!=="archived"?[...B.conversations,{...w.conversation,archivedAt:null,pinnedAt:null}].sort((M,Sn)=>Sn.lastSeenAt.localeCompare(M.lastSeenAt)):B.conversations.map(M=>M.conversationId===e?{...M,...C}:M);n.setQueryData(S,{...B,conversations:wn})}),n.setQueryData(i,S=>S&&{...S,...C,detailEtag:void 0}),w&&n.setQueryData(r,w),{archivedQueryKey:r,archivedSnapshot:w,detailQueryKey:i,previousArchivedSnapshot:x,previousDetail:y,previousFeeds:d}},onError:(a,o,i)=>{i?.previousFeeds.forEach(([r,d])=>{n.setQueryData(r,d)}),i&&(n.setQueryData(i.detailQueryKey,i.previousDetail),i.previousArchivedSnapshot?n.setQueryData(i.archivedQueryKey,i.previousArchivedSnapshot):n.removeQueries({exact:!0,queryKey:i.archivedQueryKey})),t?.onError?.()},onSuccess:(a,o)=>{n.setQueryData(E(e),i=>i&&{...i,archivedAt:a.archivedAt,detailEtag:void 0}),o.archived||n.removeQueries({exact:!0,queryKey:fn(e)}),t?.onSuccess?.(a.archivedAt)},onSettled:async()=>{await Promise.all([n.invalidateQueries({queryKey:["dashboard","conversations"]}),n.invalidateQueries({queryKey:["dashboard","locations"]}),n.invalidateQueries({queryKey:["dashboard","people"]}),n.invalidateQueries({exact:!0,queryKey:E(e)})])}})}function ra(e,t){let n,a=[];for(let[o,i]of e){let r=i?.conversations.find(d=>d.conversationId===t);r&&(n??=r,a.push(JSON.stringify(o)))}return n?{conversation:n,feedQueryHashes:a}:void 0}var T=c(f(),1);function hn(e){return!e.archivedConversation&&!e.archiveError?null:(0,T.jsxs)("div",{className:u("grid gap-2",e.className),children:[e.archiveError?(0,T.jsx)(sa,{conversation:e.archiveError.conversation,onDismiss:e.onDismissError,wasArchiving:e.archiveError.wasArchiving}):null,e.archivedConversation?(0,T.jsx)(la,{conversation:e.archivedConversation,onRestored:e.onRestored},e.archivedConversation.id):null]})}function sa(e){let t=q(e.conversation);return(0,T.jsx)(Me,{action:(0,T.jsx)(Ue,{onClick:e.onDismiss,title:"Dismiss",tone:"error",children:"Dismiss"}),detail:t,icon:Ke,title:e.wasArchiving?"Could not archive":"Could not restore",tone:"error"})}function la(e){let t=de(e.conversation.id,{onSuccess:a=>{a||e.onRestored()}}),n=q(e.conversation);return(0,bn.useEffect)(()=>{if(t.isPending||t.error)return;let a=window.setTimeout(e.onRestored,6e3);return()=>window.clearTimeout(a)},[e.conversation.id,e.onRestored,t.error,t.isPending]),(0,T.jsx)(Me,{action:(0,T.jsx)(Ue,{"aria-label":`Undo archive for ${n}`,disabled:t.isPending,onClick:()=>t.mutate({archived:!1,lastSeenAt:e.conversation.lastSeenAt}),title:`Undo archive for ${n}`,children:t.isPending?"Restoring\u2026":"Undo"}),detail:n,icon:J,title:"Conversation archived",children:t.error?(0,T.jsx)("div",{className:"border-t border-rose-300/25 bg-rose-400/[0.12] px-3 py-2 font-sans text-xs text-rose-50/85",role:"alert",children:"Could not restore the conversation."}):null})}var Q=c(f(),1);function gn(e){return(0,Q.jsx)("h3",{className:u("m-0 font-sans text-xs font-medium text-dashboard-text-muted",e.className),id:e.id,children:(0,Q.jsxs)("button",{"aria-expanded":!e.collapsed,className:"flex cursor-pointer items-center gap-1 rounded-sm border-0 bg-transparent p-0 font-[inherit] text-inherit transition-colors hover:text-dashboard-text focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-dashboard-focus",onClick:e.onToggle,type:"button",children:[(0,Q.jsx)(F,{"aria-hidden":"true",className:u("size-3 shrink-0 transition-transform motion-reduce:transition-none",!e.collapsed&&"rotate-90")}),e.label,e.collapsed?(0,Q.jsx)("span",{className:"tabular-nums text-dashboard-text-faint",children:e.count}):null]})})}var ue=c(k(),1);var ca=150;function da(e,t){e.getQueryCache().find({exact:!0,queryKey:E(t)})?.getObserversCount()||e.prefetchQuery({...wt(t),queryFn:async({signal:a})=>{let o=await St(t,a,void 0,{mailbox:!0,unreadPage:At()==="unread"});return Nt(e,t,e.getQueryData(E(t)),o),{...o,prefetchedAtMs:Date.now()}}})}function pn(e){let t=X(),n=(0,ue.useRef)(void 0);(0,ue.useEffect)(()=>()=>clearTimeout(n.current),[]);let a=()=>{clearTimeout(n.current),n.current=setTimeout(()=>da(t,e),ca)},o=()=>clearTimeout(n.current);return{onBlur:o,onFocus:a,onPointerEnter:i=>{i.pointerType!=="touch"&&a()},onPointerLeave:o}}var me=c(k(),1),yn="junior:conversation-collapsed-sections";function xn(){let[e,t]=(0,me.useState)(ua),n=(0,me.useCallback)(a=>{t(o=>{let i=new Set(o);return i.delete(a)||i.add(a),ma(i),i})},[]);return{collapsedKeys:e,toggle:n}}function ua(){if(typeof window>"u")return new Set;try{let e=JSON.parse(window.localStorage.getItem(yn)??"[]");return Array.isArray(e)?new Set(e.filter(t=>typeof t=="string")):new Set}catch{return new Set}}function ma(e){if(!(typeof window>"u"))try{window.localStorage.setItem(yn,JSON.stringify([...e]))}catch{}}var s=c(f(),1);function Ti(e){let{collapsedKeys:t,toggle:n}=xn(),[a,o]=(0,D.useState)(),[i,r]=(0,D.useState)(),d=(0,D.useCallback)((C,w)=>{r({conversation:C,wasArchiving:w})},[]),y=(0,D.useCallback)(C=>{r(w=>w?.conversation.id===C.id?void 0:w),o(C)},[]);fa(y,d);let x=(0,s.jsx)(hn,{archivedConversation:a,archiveError:i,className:"fixed bottom-[max(0.75rem,env(safe-area-inset-bottom))] left-3 right-3 z-30 sm:left-auto sm:w-96",onDismissError:()=>r(void 0),onRestored:()=>o(void 0)});if(e.loading&&e.conversations.length===0)return(0,s.jsx)(va,{label:"Loading conversations"});if(e.conversations.length===0)return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"rounded-lg border border-dashboard-border-subtle bg-dashboard-fill-faint p-4",children:(0,s.jsx)(Tt,{children:e.emptyLabel??"No conversations match this view."})}),x]});let p=Dt(e.conversations,{attentionIds:Mt(e.waitingConversationIds,e.finishedConversationIds),nowMs:Date.now(),timeZone:e.timeZone});return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{"aria-label":"Your conversations",className:"grid gap-5",role:"list",children:p.map(C=>(0,s.jsx)(ha,{collapsed:t.has(C.key),finishedConversationIds:e.finishedConversationIds,onArchiveError:d,onArchived:y,onToggle:()=>n(C.key),waitingConversationIds:e.waitingConversationIds,section:C},C.key))}),x]})}function fa(e,t){let n=ze(),a=Ee(),o=n.state?.archivedConversation,i=vn(o?.id);(0,D.useEffect)(()=>{!o||i!=="success"&&i!=="error"||(i==="success"?e(o):t(o,!0),a({hash:n.hash,search:n.search},{replace:!0,state:null}))},[o,n.hash,n.search,a,t,e,i])}function va(e){return(0,s.jsxs)("div",{"aria-busy":e.label?"true":void 0,"aria-live":e.label?"polite":void 0,className:"grid gap-5",role:e.label?"status":void 0,children:[e.label?(0,s.jsx)("span",{className:"sr-only",children:e.label}):null,[3,2].map((t,n)=>(0,s.jsxs)("div",{children:[(0,s.jsx)(R,{className:u("mb-2 ml-1 h-3",n===0?"w-16":"w-12")}),(0,s.jsx)("div",{className:"grid gap-2",children:Array.from({length:t},(a,o)=>(0,s.jsx)(ba,{index:o+n*3},o))})]},t))]})}function ba(e){return(0,s.jsxs)("div",{className:"grid min-w-0 gap-2 rounded-lg border border-dashboard-border-subtle bg-dashboard-fill-faint px-4 py-4 md:px-5",children:[(0,s.jsxs)("div",{className:"grid min-w-0 grid-cols-[minmax(0,1fr)_max-content] items-start gap-3",children:[(0,s.jsxs)("div",{className:"flex min-w-0 items-start gap-2.5",children:[(0,s.jsx)(R,{className:"mt-1.5 size-3 shrink-0 rounded-full"}),(0,s.jsx)(R,{className:u("h-4",e.index%2===0?"w-56 max-w-4/5":"w-44 max-w-3/5")})]}),(0,s.jsxs)("div",{className:"flex items-start gap-3",children:[(0,s.jsx)(R,{className:"h-3 w-16 opacity-70"}),(0,s.jsx)(R,{className:"size-4"})]})]}),(0,s.jsxs)("div",{className:"grid gap-1.5",children:[(0,s.jsx)(R,{className:"h-3 w-full max-w-3xl opacity-70"}),e.index%2===0?(0,s.jsx)(R,{className:"h-3 w-2/3 max-w-xl opacity-70"}):null]}),(0,s.jsx)(R,{className:"h-3 w-64 max-w-4/5 opacity-70"})]})}function ha(e){return(0,s.jsxs)("section",{"aria-labelledby":`conversation-section-${e.section.key}`,children:[(0,s.jsx)(gn,{className:u("px-1",!e.collapsed&&"mb-2"),collapsed:e.collapsed,count:e.section.conversations.length,id:`conversation-section-${e.section.key}`,label:e.section.label,onToggle:e.onToggle}),e.collapsed?null:(0,s.jsx)("div",{className:"grid gap-2",children:e.section.conversations.map(t=>(0,s.jsx)(ga,{conversation:t,finishedSinceSeen:e.finishedConversationIds.has(t.id),onArchiveError:e.onArchiveError,onArchived:e.onArchived,waitingOnViewer:e.waitingConversationIds.has(t.id)},t.id))})]})}function ga(e){let t=e.conversation,n=de(t.id,{onError:()=>e.onArchiveError(t,n.variables?.archived??!0),onSuccess:x=>{x&&e.onArchived(t)}}),a=gt(t),o=q(t),i=oe(t,{includeId:!1}),r=un(t),d=t.visibility==="private",y=pn(t.id);return(0,s.jsxs)("article",{...y,className:"group relative grid min-w-0 gap-2 rounded-lg border border-dashboard-border-subtle bg-dashboard-fill-faint px-4 py-4 transition-colors hover:border-dashboard-border hover:bg-dashboard-fill-soft md:px-5",role:"listitem",children:[(0,s.jsx)(W,{"aria-label":`Open ${o}`,className:"absolute inset-0 z-0 rounded-lg focus:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-dashboard-focus",to:pe(t.id)}),(0,s.jsxs)("div",{className:"relative z-[1] grid min-w-0 grid-cols-[minmax(0,1fr)_max-content] items-start gap-3 pointer-events-none",children:[(0,s.jsxs)("div",{className:"flex min-w-0 items-start gap-2.5",children:[(0,s.jsx)("span",{className:"mt-1.5 grid size-3 shrink-0 place-items-center",children:(0,s.jsx)(ln,{finishedSinceSeen:e.finishedSinceSeen,isPrivate:d,status:a,waitingOnViewer:e.waitingOnViewer})}),(0,s.jsx)("h4",{className:"m-0 truncate font-display text-base font-medium leading-snug text-dashboard-text",children:o})]}),(0,s.jsxs)("div",{className:"flex items-start gap-3",children:[(0,s.jsx)(W,{className:"pointer-events-auto whitespace-nowrap font-sans text-xs tabular-nums text-dashboard-text-muted hover:text-dashboard-text focus:outline-none focus:ring-2 focus:ring-dashboard-focus",to:pe(t.id),children:ae(t.lastSeenAt)}),(0,s.jsx)("button",{"aria-label":`${t.archivedAt?"Restore":"Archive"} ${o}`,className:"pointer-events-auto relative shrink-0 cursor-pointer border-0 bg-transparent p-0 text-dashboard-text-muted transition before:absolute before:-inset-2 hover:text-dashboard-text focus:outline-none focus:ring-2 focus:ring-dashboard-focus focus:ring-offset-2 focus:ring-offset-dashboard-canvas disabled:cursor-not-allowed disabled:opacity-50",disabled:n.isPending,onClick:()=>n.mutate({archived:!t.archivedAt,lastSeenAt:t.lastSeenAt}),type:"button",children:t.archivedAt?(0,s.jsx)(J,{"aria-hidden":"true",size:15}):(0,s.jsx)($e,{"aria-hidden":"true",size:15})})]})]}),t.activityPreview?(0,s.jsx)("p",{className:"relative z-[1] m-0 line-clamp-2 font-sans text-sm leading-relaxed text-dashboard-text-subtle pointer-events-none",children:(0,s.jsx)(se,{inline:!0,mentions:t.activityPreview.mentions,text:t.activityPreview.text})}):(0,s.jsx)("p",{className:"relative z-[1] m-0 font-sans text-sm leading-relaxed text-dashboard-text-muted pointer-events-none",children:a==="active"?"Working\u2026":"No recent message"}),(0,s.jsxs)("div",{className:"relative z-[1] flex min-w-0 flex-wrap items-center gap-x-1.5 gap-y-1 font-sans text-xs text-dashboard-text-muted pointer-events-none",children:[i?(0,s.jsx)("span",{className:"truncate",children:i}):null,i&&r.length>0?(0,s.jsx)("span",{"aria-hidden":"true",children:"\xB7"}):null,r.length>0?(0,s.jsx)(mn,{participants:r,size:"list"}):null,(0,s.jsx)(en,{annotations:t.sidebarAnnotations})]})]})}var fe=c(k(),1);function Ri(e,t=250){let[n,a]=(0,fe.useState)(e);return(0,fe.useEffect)(()=>{let o=window.setTimeout(()=>a(e),t);return()=>window.clearTimeout(o)},[t,e]),n}export{Go as a,de as b,Me as c,Ue as d,Dt as e,Mt as f,ya as g,gn as h,pn as i,xn as j,rn as k,De as l,oa as m,un as n,mn as o,O as p,j as q,Mn as r,Et as s,Ot as t,we as u,_n as v,jn as w,Ka as x,le as y,Y as z,eo as A,to as B,so as C,lo as D,Co as E,No as F,en as G,wo as H,nn as I,So as J,Ao as K,na as L,ln as M,Ti as N,va as O,Ri as P};
@@ -1 +0,0 @@
1
- import{b as A,c as C,d as B}from"./chunk-B6HGRBBX.js";import{a as i,g as a,r}from"./chunk-GO45RQDL.js";import{F as d,Ia as K,N as l,P as y,Q as f,R as m,S as h,Y as D,Z as b,_ as p,ia as R,ma as q,na as S,oa as g,sa as P,t as c,ta as x,ua as v,va as F,wa as _}from"./chunk-VXT3FIVL.js";var u=5*6e4;function U(){if(typeof window>"u")return;let e=window.__JUNIOR_DASHBOARD_BOOTSTRAP__;delete window.__JUNIOR_DASHBOARD_BOOTSTRAP__;let o=B.safeParse(e);return o.success?o.data:void 0}var w=1e4;function L(){return{queryKey:["dashboard","core"],queryFn:async({signal:e})=>{let[o,t]=await Promise.all([r(A,"/api/me",e),r(C,"/api/config",e)]);return{config:t,me:o}},initialData:U,initialDataUpdatedAt:()=>performance.timeOrigin,retry:!1,staleTime:u}}function W(){return a(L())}function $(){return a({queryKey:["dashboard","plugins"],queryFn:({signal:e})=>r(D,"/api/plugins",e),retry:!1,staleTime:u})}function z(){return a({queryKey:["dashboard","plugin-user-pages"],queryFn:({signal:e})=>r(c,"/api/user-pages",e),retry:!1,staleTime:u})}function G(e=""){return a({queryKey:["dashboard","conversations","viewer",{search:e}],queryFn:({signal:o})=>r(d,`/api/conversations${e?`?q=${encodeURIComponent(e)}`:""}`,o),placeholderData:i,refetchInterval:o=>o.state.data?.conversations.some(t=>t.status==="active")?1e4:!1,retry:!1})}function X(){return a({queryKey:["dashboard","code"],queryFn:({signal:e})=>r(q,"/api/code",e),retry:!1})}function Y(e){return a({enabled:!!e,queryKey:["dashboard","code","repositories",e],queryFn:({signal:o})=>r(S,`/api/code/repositories/${encodeURIComponent(e)}`,o),retry:!1})}function Z(e,o=""){return a({enabled:!!e,queryKey:["dashboard","conversations","code-repository",{repositoryId:e,search:o}],queryFn:({signal:t})=>{let n=new URLSearchParams({codeRepositoryId:e});return o&&n.set("q",o),r(d,`/api/conversations?${n.toString()}`,t)},placeholderData:i,retry:!1})}function ee(e,o){return a({enabled:e,queryKey:["dashboard","automations",o],queryFn:({signal:t})=>r(y,`/api/automations${o?`?${o}`:""}`,t),placeholderData:i,retry:!1})}function oe(e,o){return a({enabled:e&&!!o,queryKey:["dashboard","automations","detail",o],queryFn:({signal:t})=>r(l,`/api/automations/${encodeURIComponent(o)}`,t),retry:!1})}function re(e){return a({enabled:e,queryKey:["dashboard","automations","runs"],queryFn:({signal:o})=>r(m,"/api/automations/runs",o),retry:!1})}function ae(e,o){return a({enabled:e&&!!o,queryKey:["dashboard","automations",o,"executions"],queryFn:({signal:t})=>r(f,`/api/automations/${encodeURIComponent(o)}/executions`,t),retry:!1})}function te(e,o){return a({enabled:e&&!!o,queryKey:["dashboard","automations",o,"versions"],queryFn:({signal:t})=>r(h,`/api/automations/${encodeURIComponent(o)}/versions`,t),retry:!1})}function ne(){return a({queryKey:["dashboard","people"],queryFn:({signal:e})=>r(v,"/api/people",e),retry:!1})}function se(e){return a({enabled:!!e,queryKey:["dashboard","people",e],queryFn:async({signal:o})=>r(F,`/api/people/${encodeURIComponent(e)}`,o),retry:!1})}function ie(e){return a({enabled:!!e,queryKey:["dashboard","people",e,"plugin-reports"],queryFn:({signal:o})=>r(p,`/api/people/${encodeURIComponent(e)}/plugin-reports`,o),retry:!1})}function ue(e){return a({enabled:!!e,queryKey:["dashboard","people",e,"code"],queryFn:({signal:o})=>r(g,`/api/people/${encodeURIComponent(e)}/code`,o),retry:!1})}function de(e){return a({enabled:e,queryKey:["dashboard","personal-spend"],queryFn:({signal:o})=>r(_,"/api/people/me/spend",o),refetchInterval:w,retry:!1,staleTime:0})}function pe(){return a({queryKey:["dashboard","locations"],queryFn:({signal:e})=>r(P,"/api/locations",e),retry:!1})}function ce(e){return a({enabled:!!e,queryKey:["dashboard","locations",e],queryFn:async({signal:o})=>r(x,`/api/locations/${encodeURIComponent(e)}`,o),retry:!1})}function T(){return a({queryKey:["dashboard","skills"],queryFn:({signal:e})=>r(b,"/api/skills",e),retry:!1,staleTime:u})}function k(){return a({queryKey:["dashboard","plugin-reports"],queryFn:({signal:e})=>r(p,"/api/plugin-reports",e),retry:!1})}function le(){return a({queryKey:["dashboard","stats"],queryFn:({signal:e})=>r(K,"/api/stats",e),retry:!1})}function ye(e){let o=$(),t=a({queryKey:["dashboard","conversation-stats"],queryFn:({signal:O})=>r(R,"/api/conversations/stats",O),retry:!1}),n=T(),s=k();return{data:o.data&&n.data?{...e,conversationStatsError:!!t.error,...t.data?{conversationStats:t.data}:void 0,conversationStatsLoading:t.isPending,pluginReportsError:!!s.error,...s.data?{pluginReports:s.data}:void 0,pluginReportsLoading:s.isPending,plugins:o.data,skills:n.data}:void 0,error:o.error??n.error,isPending:o.isPending||n.isPending}}export{W as a,z as b,G as c,X as d,Y as e,Z as f,ee as g,oe as h,re as i,ae as j,te as k,ne as l,se as m,ie as n,ue as o,de as p,pe as q,ce as r,le as s,ye as t};
@@ -1 +0,0 @@
1
- import{E as Xe}from"./chunk-NQMDED2R.js";import{a as Oe,d as _,f as De,g as z,i as U,j as fe,l as ze,n as W,o as We,q as Ye,r as Q,s as Je}from"./chunk-GO45RQDL.js";import{$ as ke,A as pe,B as He,C as _e,Ca as Me,D as Ee,Da as Ve,E as ge,Ea as je,Fa as $e,I as Ne,P as Ue,aa as Be,ba as Ke,ca as Qe,ja as Fe,z as qe}from"./chunk-VXT3FIVL.js";import{a as ae}from"./chunk-YPMUHXYT.js";import{c as se}from"./chunk-7SZRL6FY.js";var k=se(ae(),1);function et(e,t){window.dispatchEvent(new StorageEvent("storage",{key:e,newValue:t}))}var Ge=(e,t)=>{let n=JSON.stringify(t);window.localStorage.setItem(e,n),et(e,n)},Tt=e=>{window.localStorage.removeItem(e),et(e,null)},Ze=e=>window.localStorage.getItem(e),Pt=e=>(window.addEventListener("storage",e),()=>window.removeEventListener("storage",e)),Lt=()=>{throw Error("useLocalStorage is a client-only hook")};function tt(e,t){let o=k.useSyncExternalStore(Pt,()=>Ze(e),Lt),r=k.useCallback(s=>{try{let a=typeof s=="function"?s(JSON.parse(o)):s;a==null?Tt(e):Ge(e,a)}catch(a){console.warn(a)}},[e,o]);return k.useEffect(()=>{Ze(e)===null&&typeof t<"u"&&Ge(e,t)},[e,t]),[o?JSON.parse(o):t,r]}var B=se(ae(),1);var R=se(ae(),1);var me=se(ae(),1);var ee=["dashboard","review-items"],nt=6e4;function hn(e){let t=new URLSearchParams;e.conversationId&&t.set("conversationId",e.conversationId),e.forViewer&&t.set("for","viewer"),e.q&&t.set("q",e.q);let n=t.toString(),o=fe({initialPageParam:void 0,queryKey:[...ee,"list",n],queryFn:({pageParam:a,signal:l})=>{let d=new URLSearchParams(n);return a&&d.set("cursor",a),Q(Ve,`/api/review-items?${d.toString()}`,l)},getNextPageParam:a=>a.nextCursor,placeholderData:Oe,retry:!1}),r=o.data?.pages;return{items:(0,me.useMemo)(()=>(r??[]).flatMap(a=>a.items),[r]),moreArchived:!!r?.[0]?.moreArchived,query:o}}function bn(e){return z({enabled:!!e,queryKey:[...ee,"detail",e],queryFn:({signal:t})=>Q(Me,`/api/review-items/${encodeURIComponent(e)}`,t),retry:!1})}function Cn(e){return De({queries:e.map(t=>({queryKey:["dashboard","conversation-title",t],queryFn:async({signal:n})=>Xe(await Q(ge,`/api/conversations/${encodeURIComponent(t)}?limit=1`,n))??null,retry:!1,staleTime:5*6e4}))}).map(t=>t.data??void 0)}function wn(e){return z({enabled:e,queryKey:[...ee,"count"],queryFn:({signal:t})=>Q(je,"/api/review-items/count",t),refetchInterval:nt,retry:!1})}function Sn(e){return z({enabled:e,queryKey:["dashboard","automations","scope=mine&state=blocked"],queryFn:({signal:t})=>Q(Ue,"/api/automations?scope=mine&state=blocked&pageSize=100",t),retry:!1})}function Rn(){let e=_();return U({mutationFn:t=>W(Me,`/api/review-items/${encodeURIComponent(t.id)}/actions`,t.body),onSettled:()=>e.invalidateQueries({queryKey:ee})})}var It=new Map;function At(){let t=z({queryKey:[...ee,"waiting-conversations"],queryFn:({signal:n})=>Q($e,"/api/review-items/waiting-conversations",n),refetchInterval:nt,retry:!1}).data?.conversations;return(0,me.useMemo)(()=>t?new Map(t.map(({conversationId:n,count:o,title:r})=>[n,{count:o,title:r}])):It,[t])}function En(){let e=At();return(0,me.useMemo)(()=>new Set(e.keys()),[e])}function ve(e){let t=e.getQueryData(["dashboard","core"])?.me.user;if(t?.email)return{...t.avatarUrl?{avatarUrl:t.avatarUrl}:void 0,email:t.email,fullName:t.name||void 0}}function J(e){return["conversation",e,"outbox"]}function ye(e){let t=e.now??new Date().toISOString();return{actorIdentity:e.actorIdentity,createdAt:t,idempotencyKey:e.idempotencyKey,...e.inline?{inline:!0}:void 0,message:e.message,...e.images?.length?{images:e.images}:void 0,messageId:e.messageId,status:"sending"}}function ot(e){return{actorIdentity:e.actorIdentity,clientStatus:e.status,createdAt:e.createdAt,delivery:"defer",idempotencyKey:e.idempotencyKey,inboundMessageId:e.messageId,messageId:e.messageId,receivedAt:e.createdAt,role:"user",source:"web",text:e.message,...e.images?.length?{images:e.images}:void 0}}function rt(e,t,n){let o=e??[],r=t??[],s=o;if(r.length>0){let a=new Set(o.map(d=>d.messageId)),l=r.filter(d=>!a.has(d.messageId)).map(ot);l.length>0&&(s=[...o,...l])}return he(n,s)}function he(e,t){if(!e)return t;if(e===t)return e;if(e.length!==t.length)return t;for(let n=0;n<e.length;n+=1)if(!Ot(e[n],t[n]))return t;return e}function Ot(e,t){return e.inboundMessageId===t.inboundMessageId&&e.messageId===t.messageId&&e.clientStatus===t.clientStatus&&e.delivery===t.delivery&&e.text===t.text&&e.images===t.images&&JSON.stringify(e.attachments)===JSON.stringify(t.attachments)&&e.redacted===t.redacted&&e.source===t.source&&e.role===t.role&&e.createdAt===t.createdAt&&e.receivedAt===t.receivedAt&&e.idempotencyKey===t.idempotencyKey&&st(e.actorIdentity,t.actorIdentity)&&Dt(e.mentions,t.mentions)}function Dt(e,t){return e===t?!0:!e||!t||e.length!==t.length?!1:e.every((n,o)=>st(n,t[o]))}function st(e,t){return e===t?!0:!e||!t?!1:e.avatarUrl===t.avatarUrl&&e.email===t.email&&e.fullName===t.fullName&&e.slackUserId===t.slackUserId&&e.slackUserName===t.slackUserName}function xe(e){return!!e.inline&&e.status!=="failed"}function at(e,t,n){let o=n.filter(xe);if(o.length===0)return{inline:[],queued:e};let r=new Set(o.map(a=>a.messageId)),s=new Map((t??[]).map(a=>[a.messageId,a]));return{inline:o.map(a=>s.get(a.messageId)??ot(a)),queued:e.filter(a=>!r.has(a.messageId))}}function be(e,t){let n=e??[],o=n.findIndex(s=>s.idempotencyKey===t.idempotencyKey);if(o<0)return[...n,t];let r=n.slice();return r[o]=t,r}function it(e,t,n){return(e??[]).map(o=>o.idempotencyKey===t?{...o,messageId:n,status:"accepted"}:o)}function ut(e,t){return(e??[]).map(n=>n.idempotencyKey===t?{...n,status:"failed"}:n)}function Te(e,t){let n=vt(e,t);return n||(t.length===0?e:{...e,events:mt([...t.flatMap(o=>o.events),...e.events]),previousCursor:Ce(e.previousCursor,t)??(t.length?Pe(t):e.previousCursor)})}function Tn(e,t,n){let o=vt(e,t);return o||{...e,events:mt([...t.flatMap(r=>r.events),...n]),previousCursor:Pe(t)}}async function lt(e){let t=new Map(e.historyPages.map(s=>[s.requestedBefore,s])),n=[],o=new Set,r=e.detail.previousCursor;for(;r;){if(o.has(r))throw new Error("Conversation history cursor did not advance");o.add(r);let s=t.get(r)??{...await e.readPage(r),requestedBefore:r};n.push(s),r=s.previousCursor}return Te(e.detail,n)}function dt(e){let t=gt(e);return t===void 0?"empty":String(t)}function ft(e,t){return Ce(e,t)??Pe(t)}function Ce(e,t){if(!e)return;let n=new Map(t.map(a=>[a.requestedBefore,a])),o=new Set,r=new Set,s=e;for(;s;){if(r.has(s))return;r.add(s);let a=n.get(s);if(!a)return o.size>0&&o.size===t.length?void 0:s;o.add(a);let l=gt(o),d=qt(t.filter(M=>!o.has(M)));if(l!==void 0&&d!==void 0&&l<=d+1)return;s=a.previousCursor}}function pt(e,t){return t.some(n=>n.eventHistory.status!==e.eventHistory.status)}function gt(e){let t;for(let n of e){let o=n.events[0]?.seq;o!==void 0&&(t===void 0||o<t)&&(t=o)}return t}function qt(e){let t;for(let n of e){let o=n.events.at(-1)?.seq;o!==void 0&&(t===void 0||o>t)&&(t=o)}return t}function Pe(e){let t;for(let n of e){let o=n.events[0]?.seq,r=t?.events[0]?.seq;o!==void 0&&(r===void 0||o<r)&&(t=n)}return t?.previousCursor}function mt(e){return[...new Map(e.map(t=>[t.seq,t])).values()].sort((t,n)=>t.seq-n.seq)}function vt(e,t){if(e.eventHistory.status!=="available")return ct(e);let n=t.find(o=>o.eventHistory.status!=="available");if(n)return ct({...e,eventHistory:n.eventHistory,events:n.events,previousCursor:n.previousCursor})}function ct(e){let{modelUsage:t,...n}=e;return n}function yt(e,t){if(!e)return t;let n=Ht(e.events,t.events)?e.events:t.events,o=JSON.stringify(e.annotations)===JSON.stringify(t.annotations)?e.annotations:t.annotations,r=JSON.stringify(e.authors)===JSON.stringify(t.authors)?e.authors:t.authors;return n===t.events&&o===t.annotations&&r===t.authors?t:{...t,events:n,annotations:o,authors:r}}function Ht(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1){let o=e[n],r=t[n];if(o.seq!==r.seq||o.createdAt!==r.createdAt||o.data.type==="message"&&r.data.type==="message"&&JSON.stringify(o.data.attachments)!==JSON.stringify(r.data.attachments))return!1}return!0}function Pn(e){if(e?.status!=="active")return!1;for(let t=e.events.length-1;t>=0;t-=1){let n=e.events[t].data;if(n.type==="turn_lifecycle")return n.state==="started"}return!!e.previousCursor}function E(e){return["conversation",e,"detail"]}var _t=500,Nt=6e3,Ut=3e4;function kt(e,t){let n=E(t),o=e.getQueryState(n);if(!o?.data?.prefetchedAtMs)return;let{prefetchedAtMs:r,...s}=o.data;e.setQueryData(n,s,{updatedAt:o.dataUpdatedAt})}function Bt(e){return!!(e?.prefetchedAtMs&&Date.now()-e.prefetchedAtMs<Ut)}async function Kt(e,t,n,o){if(!n)return ht(e,t,void 0,{mailbox:!0,unreadPage:o});let r=await zt(e,t);return{...await ht(e,t,n,{unreadPage:o}),mailbox:r}}var Qt=["agents","memories","watches"];function Ft(e,t){return["conversation",e,t]}function Vt(e,t,n,o){if(!(!n?.detailEtag||!o.detailEtag||n.detailEtag===o.detailEtag)){for(let r of Qt)e.invalidateQueries({queryKey:Ft(t,r)});e.invalidateQueries({queryKey:ee})}}function jt(e,t){return{enabled:!!e,queryKey:E(e),queryFn:async({signal:n,client:o})=>{let r=o.getQueryData(E(e)),s=await Kt(e,n,r,t?.unreadPage);return Vt(o,e,r,s),s},structuralSharing:(n,o)=>!o||typeof o!="object"||!n||typeof n!="object"?o:$t(n,yt(n,o)),refetchInterval:n=>t?.fastPollUntilMs&&Date.now()<t.fastPollUntilMs?_t:t?.awaitingMessage||n.state.data?.status==="active"||n.state.data?.mailbox?.messages.length||n.state.data?.mailbox?.authorization?2e3:1e4,retry:!1}}function $t(e,t){let n=e.readPosition;if(!n||(t.readPosition?.lastReadSeq??-1)>=n.lastReadSeq)return t;let{unreadCursor:o,unreadPage:r,...s}=t;return{...s,readPosition:n,...e.unreadCursor?{unreadCursor:e.unreadCursor,unreadPage:e.unreadPage}:void 0}}function Nn(){let e=_();return U({mutationFn:t=>W(pe,"/api/conversations",t),onSuccess:(t,n)=>{e.setQueryData(J(t.conversationId),o=>be(o,{...ye({...n,actorIdentity:ve(e),inline:!0,messageId:t.messageId}),status:"accepted"})),e.invalidateQueries({queryKey:["dashboard","conversations"]}),e.invalidateQueries({exact:!0,queryKey:E(t.conversationId)})}})}function Un(e){let t=_();return U({mutationFn:async n=>{let o=await W(He,`/api/conversations/${encodeURIComponent(e)}/forks`,{messageId:n.messageId,idempotencyKey:n.idempotencyKey});return W(pe,`/api/conversations/${encodeURIComponent(o.conversationId)}/messages`,{idempotencyKey:n.idempotencyKey,message:n.message})},onSuccess:(n,o)=>{t.setQueryData(J(n.conversationId),r=>be(r,{...ye({idempotencyKey:o.idempotencyKey,message:o.message,actorIdentity:ve(t),inline:!0,messageId:n.messageId}),status:"accepted"})),t.invalidateQueries({queryKey:["dashboard","conversations"]})}})}function kn(e){let t=_(),n=J(e);return U({mutationFn:({inline:o,...r})=>W(pe,`/api/conversations/${encodeURIComponent(e)}/messages`,r),onMutate:async o=>{let r=await Ne({conversationId:e,idempotencyKey:o.idempotencyKey}),s=ye({...o,actorIdentity:ve(t),messageId:r});t.setQueryData(n,a=>be(a,s))},onError:(o,r)=>{t.setQueryData(n,s=>ut(s,r.idempotencyKey))},onSuccess:(o,r)=>{t.setQueryData(n,s=>it(s,r.idempotencyKey,o.messageId)),t.invalidateQueries({queryKey:["dashboard","conversations"]}),t.invalidateQueries({exact:!0,queryKey:E(e)})}})}function Bn(e){let t=_();return U({mutationFn:n=>Ye(Ke,`/api/conversations/${encodeURIComponent(e)}/pending-messages`,n),onMutate:async n=>{await t.cancelQueries({exact:!0,queryKey:E(e)});let o=t.getQueryData(E(e));return o?.mailbox&&t.setQueryData(E(e),{...o,mailbox:{...o.mailbox,messages:o.mailbox.messages.filter(r=>!n.inboundMessageIds.includes(r.inboundMessageId))}}),{previousPending:o}},onError:(n,o,r)=>{r?.previousPending&&t.setQueryData(E(e),s=>s&&{...s,mailbox:r.previousPending?.mailbox})},onSettled:async()=>{await Promise.all([t.invalidateQueries({queryKey:["dashboard","conversations"]}),t.invalidateQueries({exact:!0,queryKey:E(e)})])}})}function Kn(e){let t=_();return U({mutationFn:n=>W(Qe,`/api/conversations/${encodeURIComponent(e)}/pending-messages/steer`,n),onSuccess:async n=>{let o=new Set(n.steeredInboundMessageIds);o.size!==0&&(await t.cancelQueries({exact:!0,queryKey:E(e)}),t.setQueryData(E(e),r=>r?.mailbox?{...r,mailbox:{...r.mailbox,messages:r.mailbox.messages.map(s=>o.has(s.inboundMessageId)?{...s,delivery:"interrupt"}:s)}}:r))},onSettled:async()=>{await t.invalidateQueries({exact:!0,queryKey:E(e)})}})}function Le(e){return["conversation",e,"stopped-messages"]}function Qn(e){let t=_();return U({mutationFn:()=>W(Fe,`/api/conversations/${encodeURIComponent(e)}/stop`,{}),onSuccess:n=>{let o=n.stoppedInboundMessageIds;o.length&&(t.setQueryData(Le(e),r=>[...r??[],...o]),t.setQueryData(J(e),r=>r?.filter(s=>!o.includes(s.messageId))))},onSettled:async()=>{await t.invalidateQueries({exact:!0,queryKey:E(e)})}})}function Fn(e,t){let n=_(),o=()=>{let g=Bt(n.getQueryData(E(e)));return{conversationId:e,fetched:g,prefetched:g}},[r,s]=(0,R.useState)(o);r.conversationId!==e&&s(o());let a=r.conversationId===e&&r.fetched,l=r.conversationId===e&&r.prefetched,d=z({enabled:!!e,queryFn:async()=>n.getQueryData(J(e))??[],queryKey:J(e),initialData:[],staleTime:1/0,gcTime:1/0}),M=z({enabled:!!e,queryFn:async()=>n.getQueryData(Le(e))??[],queryKey:Le(e),initialData:[],staleTime:1/0,gcTime:1/0}),K=d.data.filter(g=>g.status!=="failed"),F=Math.max(0,...K.map(g=>Date.parse(g.createdAt))),b=z({...jt(e,{awaitingMessage:K.length>0,fastPollUntilMs:F?F+Nt:void 0,unreadPage:!!t?.unreadPageAtOpen&&!a})}),q=b.refetch;(0,R.useEffect)(()=>{if(e)return q({cancelRefetch:!1}),()=>kt(n,e)},[e,n,q]),!a&&b.isFetchedAfterMount&&!b.isFetching&&s({conversationId:e,fetched:!0,prefetched:l});let V=(0,R.useDeferredValue)(b.data),v=V&&V.conversationId===e?V:b.data,x=v?.mailbox;(0,R.useEffect)(()=>{if(!x||!v)return;let g=new Set(x.messages.map(y=>y.messageId)),S=new Set;for(let y of v.events)y.data.type==="message"&&S.add(y.data.messageId);n.setQueryData(J(e),y=>{let $=y?.filter(P=>!S.has(P.messageId)&&(xe(P)||!g.has(P.messageId)));return $?.length===y?.length?y:$})},[e,v,x,d.data,n]);let j=b.data?.displayTitle,m=b.dataUpdatedAt;(0,R.useEffect)(()=>{if(!e||!j)return;let g=n.getQueryCache().findAll({queryKey:["dashboard","conversations"]});for(let S of g){let y=S.state.data;!y||S.state.dataUpdatedAt>m||!y.conversations.some(P=>P.conversationId===e&&P.displayTitle!==j)||n.setQueryData(S.queryKey,{...y,conversations:y.conversations.map(P=>P.conversationId===e?{...P,displayTitle:j}:P)})}},[e,m,j,n]);let h=v?.eventHistory.status,T=(0,R.useMemo)(()=>["conversation",e,"history",h],[e,h]),p=fe({enabled:!1,queryKey:T,queryFn:async({pageParam:g,signal:S})=>({...await bt(e,g,S),requestedBefore:g}),initialPageParam:v?.previousCursor??"",getNextPageParam:(g,S)=>ft(v?.previousCursor,S),retry:!1}),X=p.data?.pages,ce=(0,R.useMemo)(()=>v?Te(v,X??[]):void 0,[v,X]),I=(0,R.useRef)(void 0),le=(0,R.useRef)(void 0),{inlineMessages:de,pendingMessages:Y}=(0,R.useMemo)(()=>{let g=M.data,S=g.length?x?.messages.filter(i=>!g.includes(i.inboundMessageId)):x?.messages,y=g.length?d.data.filter(i=>!g.includes(i.messageId)):d.data,$=at(rt(S,y),S,y),P=he(I.current,$.queued),c=he(le.current,$.inline);return I.current=P,le.current=c,{inlineMessages:c,pendingMessages:P}},[d.data,x?.messages,M.data]),f=Wt(p.error),H=!!(v&&(pt(v,X??[])||f)),te=f?null:p.error,G=!!(v?.previousCursor&&p.data&&Ce(v.previousCursor,p.data.pages)&&!H&&!p.error&&!p.isFetchingNextPage),Z=p.isFetchingNextPage||G;(0,R.useEffect)(()=>{H&&q()},[q,H]),(0,R.useEffect)(()=>{f&&n.resetQueries({exact:!0,queryKey:T})},[T,f,n]);let N=p.fetchNextPage;return(0,R.useEffect)(()=>{G&&N({cancelRefetch:!1})},[N,G]),{data:ce,latest:b.data,error:b.error,historyError:te,historyVersion:dt(X??[]),hasPreviousPage:p.data?p.hasNextPage:!!v?.previousCursor,isPending:b.isPending,fetchedAtOpen:a,fetchedDetail:l||b.isFetchedAfterMount&&!b.isFetching?b.data:void 0,isLoadingPreviousPage:Z,pendingAuthorization:x?.authorization,pendingGeneratedAt:x?.generatedAt,inlineMessages:de,pendingMessages:Y,loadCompleteTranscript:()=>{if(!e||!v)throw new Error("Cannot load a conversation without an id");return lt({detail:v,historyPages:p.data?.pages??[],readPage:g=>bt(e,g)})},loadPreviousPage:()=>{let g=p.data?p.hasNextPage:!!v?.previousCursor;e&&g&&p.fetchNextPage({cancelRefetch:!1})}}}async function ht(e,t,n,o){let r=new URLSearchParams;o?.unreadPage&&r.set("unreadPage","true"),o?.mailbox&&r.set("mailbox","true");let s=r.size?`?${r}`:"",a=await Je(`/api/conversations/${encodeURIComponent(e)}${s}`,t,n?.detailEtag?{[Ee]:n.detailEtag}:void 0);return a.status===304&&n?n:{...(o?.mailbox?Be:ge).parse(await a.json()),detailEtag:a.headers.get(Ee)??void 0}}function zt(e,t){return Q(ke,`/api/conversations/${encodeURIComponent(e)}/pending-messages`,t)}function bt(e,t,n){let o=new URLSearchParams({before:t});return Q(_e,`/api/conversations/${encodeURIComponent(e)}/events?${o}`,n).then(r=>{if(r.previousCursor===t)throw new Error("Conversation history cursor did not advance");return r})}function Wt(e){return e instanceof ze&&e.status===400}var u=se(ae(),1);var we="data-scroll-anchor";function Yt(e,t,n){let o=0,r=e;for(;o<r;){let s=o+r>>1;t(s).bottom<=n.top?o=s+1:r=s}return o>=e?null:t(o).top>=n.top?o:o+1<e&&t(o+1).top<n.bottom?o+1:o}function Ct(e,t){let n=e.querySelectorAll(`[${we}]`),o=new Map,r=l=>{let d=o.get(l);return d||(d=n[l].getBoundingClientRect(),o.set(l,d)),d},s=Yt(n.length,r,t);if(s===null)return null;let a=n[s];return{element:a,key:a.getAttribute(we)??"",offset:r(s).top-t.top}}function wt(e,t,n){let o=n.element.isConnected?n.element:Jt(e,n.key);return o?o.getBoundingClientRect().top-t.top-n.offset:null}function Jt(e,t){for(let n of e.querySelectorAll(`[${we}]`))if(n.getAttribute(we)===t)return n;return null}var Xt=96,St=600,Rt=2,Gt=48,Ae="data-transcript-pin-start",Zt=16;function zn(e){return{[Ae]:e}}var ie=typeof window>"u"?u.useEffect:u.useLayoutEffect;function ue(e,t=Xt){return e.scrollHeight-e.scrollTop-e.clientHeight<=t}function Wn(e){if(!e)return"empty";for(let t=e.events.length-1;t>=0;t-=1){let n=e.events[t],o=n.data;if(o.type==="message"&&o.role==="assistant")return[n.seq,n.createdAt,o.messageId,o.redacted?"redacted":o.text?.length??0].join(":");if(o.type==="assistant_message"&&o.parts.length>0){let r=o.parts.at(-1);return[n.seq,n.createdAt,o.parts.length,r?.redacted?"redacted":r?.text?.length??0].join(":")}}return"empty"}function Yn(e,t="rich"){if(!e)return"empty";let n;for(let o=e.events.length-1;o>=0;o-=1){let r=e.events[o];if(!(t==="rich"&&!en(r))){n=r;break}}return[e.conversationId,e.status,n?.seq??"",n?.createdAt??"",tn(n)].join("|")}function en(e){let t=e.data;return t.type==="turn_lifecycle"?t.state==="failed":t.type==="message"||t.type==="assistant_message"&&t.parts.length>0||t.type==="tool_calls"||t.type==="subagent"||t.type==="structured_event"||t.type==="attachments_delivered"||t.type==="compaction"}function tn(e){if(!e)return"";let t=e.data;switch(t.type){case"message":return[t.type,t.role,t.messageId,t.redacted?"redacted":t.text?.length??0,t.eventType??""].join(":");case"assistant_message":{let n=t.parts,o=n.at(-1);return[t.type,n.length,o?.redacted?"redacted":o?.text?.length??0].join(":")}case"tool_calls":{let n=t.calls.at(-1);return[t.type,t.calls.length,n?.toolCallId??"",n?.name??"",n?.status??"",n?.output===void 0?"":"output"].join(":")}case"subagent":return[t.type,t.childConversationId,t.status,t.subagentKind,t.parentToolCallId??""].join(":");case"turn_lifecycle":return[t.type,t.turnId,t.state,"failureCode"in t?t.failureCode:"","failureReason"in t?t.failureReason??"":""].join(":");case"structured_event":return[t.type,t.namespace,t.name,t.version,t.presentation.title,t.presentation.preview?.length??0].join(":");case"message_handled":return[t.type,t.messageId].join(":");case"attachments_delivered":return[t.type,t.attachments.length,...t.attachments.map(n=>`${n.id}:${n.filename}:${n.bytes}`)].join(":");case"compaction":return[t.type,t.summary?.length??0,e.createdAt].join(":");case"guardian_action_reviewed":return[t.type,t.turnId,t.toolCallId,t.decision].join(":");case"turn_context":return[t.type,t.turnId,t.pluginName,t.kind,t.version].join(":");default:return`${t.type??"unknown"}:${e.seq}`}}function nn(e){return e.enabled&&e.following}function on(e){if(e.enabled)return{pending:!1,pin:!1};let t=e.pending||e.wasEnabled&&!e.enabled&&e.following;return t&&e.juniorMessageChanged?{pending:!1,pin:!0}:{pending:t,pin:!1}}function rn(e){return!e.following&&(e.endsAtLatest===!1||!!e.openedAtUnread||e.enabled&&e.hasPendingUpdate)}function sn(e){return e.source==="scroll"&&e.previousScrollTop!=null&&e.snapshot.scrollTop<e.previousScrollTop-Rt?"pause":e.source==="scroll"&&ue(e.snapshot)?"follow":"preserve"}function an(e){return e.intent==="pause"&&!ue(e.snapshot)?"pause":"ignore"}function Jn(e){let t=(0,u.useRef)(null),n=(0,u.useRef)(null),o=(0,u.useRef)(e.enabled),r=(0,u.useRef)(!0);r.current=e.endsAtLatest??!0;let s=(0,u.useRef)(!1),a=(0,u.useRef)(!1),l=(0,u.useRef)(null),d=(0,u.useRef)(null),M=(0,u.useRef)(null),K=(0,u.useRef)(null),F=(0,u.useRef)(e.pinRequestVersion??0),b=(0,u.useRef)(e.juniorMessageVersion),q=(0,u.useRef)(e.enabled),V=(0,u.useRef)(!1),v=(0,u.useRef)(e.versions),x=(0,u.useRef)(0),j=(0,u.useRef)(new Set),[m,h]=(0,u.useState)(!1),[T,p]=(0,u.useState)(!1),[X,ce]=(0,u.useState)(!1),[I,le]=(0,u.useState)(null),de=(0,u.useCallback)(c=>{n.current=c,le(c)},[]);(0,u.useEffect)(()=>{o.current=e.enabled,e.enabled||p(!1)},[e.enabled]);let Y=(0,u.useRef)(!1),f=(0,u.useCallback)(c=>{s.current=c,h(c),c?ce(!1):Y.current=!1},[]),H=(0,u.useCallback)(()=>{let c=n.current,i=D(c);!c||!i||(K.current=Ct(c,Ie(i)))},[]),te=(0,u.useCallback)(()=>{let c=n.current,i=D(c),C=K.current;if(!c||!i)return;let L=C?wt(c,Ie(i),C):null;if(L!==null&&Math.abs(L)>=1){let w=O(i).scrollTop+L;Se(i,w);let A=O(i).scrollTop;d.current=A,M.current=A}H()},[H]),G=(0,u.useCallback)(()=>{if(!s.current)return;let c=D(n.current);!c||O(c).scrollTop<=0||(x.current=0,f(!1))},[f]),Z=(0,u.useCallback)(c=>{let i=D(n.current);if(!i)return;c==="scroll"&&H();let C=O(i),L=d.current;if(d.current=C.scrollTop,c==="scroll"){let A=M.current;if(M.current=null,A!==null&&Math.abs(C.scrollTop-A)<1)return}let w=sn({previousScrollTop:L,snapshot:C,source:c});if(c==="scroll"&&x.current>0){an({intent:w,snapshot:C})==="pause"&&(x.current=0,f(!1));return}if(w==="follow"){if(!r.current)return;f(!0),p(!1);return}w==="pause"&&f(!1)},[H,f]),N=(0,u.useCallback)(c=>{let i=D(n.current);if(!i)return;let C=un(i,n.current,j.current);C!==null&&f(!1);let L=C!==null||s.current,w=L?++x.current:0;Se(i,C??O(i).scrollHeight,c);let A=()=>{if(L&&x.current!==w)return;L&&(x.current=0);let oe=O(i);d.current=oe.scrollTop,o.current&&s.current&&ue(oe)&&(f(!0),p(!1))};if(c==="smooth"){window.setTimeout(A,400);return}requestAnimationFrame(()=>{requestAnimationFrame(A)})},[f]),g=(0,u.useCallback)(()=>{let c=n.current,i=D(c),C=c?.querySelector("[data-transcript-unread-marker]");if(!i||!C)return!1;Y.current=!1;let L=C.getBoundingClientRect().top-Ie(i).top;Se(i,Math.max(0,O(i).scrollTop+L-Gt));let w=O(i);d.current=w.scrollTop;let A=r.current&&ue(w);return f(A),ce(!A),H(),!0},[H,f]);ie(()=>{if(!I||!e.conversationId)return;let c=`${e.conversationId}:${e.startAtLink?"link":"start"}`;if(l.current===c)return;let i=D(I);if(i){if(l.current=c,p(!1),e.startAtLink){d.current=O(i).scrollTop,f(!1);return}e.startAtUnread&&g()||(Se(i,O(i).scrollHeight),d.current=O(i).scrollTop,f(!0),Y.current=!!e.startAtUnread)}},[I,e.conversationId,e.startAtLink,e.startAtUnread,g,f]);let S=(0,u.useCallback)(()=>{if(!(Y.current&&g())){if(!r.current){f(!1),te();return}N("auto")}},[g,te,N,f]),y=(0,u.useCallback)(()=>{if(s.current){S();return}te(),Z("measure")},[S,Z,te]);ie(()=>{y()},[e.historyVersion,y]),ie(()=>{let c=v.current[e.view]!==e.versions[e.view];v.current=e.versions;let i=o.current;if(a.current&&!c&&i===e.enabled)return;let C=e.enabled||i;if(o.current=e.enabled,!C)return;let L=a.current;if(a.current||(a.current=!0),e.enabled&&!i){let w=D(n.current);w&&f(ue(O(w)))}if(nn({enabled:e.enabled,following:s.current})){S(),p(!1);return}e.enabled&&L&&p(!0)},[e.enabled,e.view,e.versions.rich,e.versions.raw,S,f]),(0,u.useEffect)(()=>{if(typeof window>"u"||!I)return;let c=D(I);if(!c)return;let i=c,C=()=>Z("scroll"),L=re=>{re.deltaY<0&&G()},w=null,A=re=>{w=re.touches[0]?.clientY??null},oe=re=>{let Re=re.touches[0]?.clientY;Re===void 0||w===null||(Re>w+Rt&&G(),w=Math.min(w,Re))};return Z("measure"),H(),i.addEventListener("scroll",C,{passive:!0}),i.addEventListener("wheel",L,{passive:!0}),i.addEventListener("touchstart",A,{passive:!0}),i.addEventListener("touchmove",oe,{passive:!0}),window.addEventListener("resize",y),()=>{i.removeEventListener("scroll",C),i.removeEventListener("wheel",L),i.removeEventListener("touchstart",A),i.removeEventListener("touchmove",oe),window.removeEventListener("resize",y)}},[I,G,Z,H,y]),(0,u.useEffect)(()=>{if(typeof ResizeObserver>"u"||!I)return;let c=new ResizeObserver(()=>{y()});c.observe(I);let i=D(I);return i&&!ne(i)&&c.observe(i),()=>c.disconnect()},[I,y]);let $=(0,u.useCallback)(()=>{Y.current=!1,f(!0),p(!1),N(cn())},[N,f]);ie(()=>{let c=b.current!==e.juniorMessageVersion;b.current=e.juniorMessageVersion;let i=on({enabled:e.enabled,following:s.current,juniorMessageChanged:c,pending:V.current,wasEnabled:q.current});q.current=e.enabled,V.current=i.pending,i.pin&&(f(!0),p(!1),N("auto"))},[e.enabled,e.juniorMessageVersion,N,f]),ie(()=>{let c=e.pinRequestVersion??0;c!==F.current&&(F.current=c,Y.current=!1,f(!0),p(!1),N("auto"))},[e.pinRequestVersion,N,f]);let P=(0,u.useCallback)(()=>K.current?.key,[]);return(0,u.useMemo)(()=>({anchorRef:t,contentElement:I,contentRef:de,hasPendingUpdate:T,jumpToBottom:$,scrollAnchorKey:P,showJumpToLatest:rn({enabled:e.enabled,endsAtLatest:e.endsAtLatest,following:m,hasPendingUpdate:T,openedAtUnread:X})}),[I,de,m,T,e.enabled,e.endsAtLatest,$,X,P])}var Xn=(0,u.createContext)(void 0);function Gn(e){let[t,n]=(0,u.useState)(null),o=(0,u.useRef)(e.onLoad);return o.current=e.onLoad,(0,u.useEffect)(()=>{if(!e.enabled||!t||typeof IntersectionObserver>"u")return;let r=D(t),s=new IntersectionObserver(a=>{a.some(l=>l.isIntersecting)&&(s.disconnect(),o.current())},{root:r&&!ne(r)?r:null,rootMargin:e.edge==="top"?`${St}px 0px 0px 0px`:`0px 0px ${St}px 0px`});return s.observe(t),()=>s.disconnect()},[e.edge,e.enabled,e.historyVersion,t]),n}function D(e){if(typeof window>"u")return null;if(!e)return window;let t=e.parentElement;for(;t&&t!==document.body;){let n=window.getComputedStyle(t);if(/(auto|scroll|overlay)/.test(n.overflowY))return t;t=t.parentElement}return window}function un(e,t,n){let o=t?Array.from(t.querySelectorAll(`[${Ae}]`)).at(-1):void 0,r=o?.getAttribute(Ae);if(!o||!r||n.has(r))return null;let s=o.getBoundingClientRect();if(s.height===0)return null;n.add(r);let a=O(e),l=a.scrollTop-(ne(e)?0:e.getBoundingClientRect().top),d=s.top+l-Zt,M=a.scrollHeight-a.clientHeight;return d>=M||s.bottom+l<=M?null:Math.max(0,d)}function O(e){if(ne(e)){let t=document.scrollingElement??document.documentElement;return{clientHeight:window.innerHeight,scrollHeight:t.scrollHeight,scrollTop:window.scrollY||t.scrollTop}}return{clientHeight:e.clientHeight,scrollHeight:e.scrollHeight,scrollTop:e.scrollTop}}function Se(e,t,n="auto"){if(ne(e)){window.scrollTo({behavior:n,top:t});return}e.scrollTo({behavior:n,top:t})}function Ie(e){if(ne(e))return{bottom:window.innerHeight,top:0};let t=e.getBoundingClientRect().top;return{bottom:t+e.clientHeight,top:t}}function ne(e){return e===window}function cn(){return typeof window>"u"||typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches?"auto":"smooth"}var ln=750,Mt="data-transcript-seq",Et=`[${Mt}]`,xt="junior:conversation:start-position";function ao(){return tt(xt,"unread")}function io(){if(typeof window>"u")return"unread";try{let e=window.localStorage.getItem(xt);return e&&JSON.parse(e)==="latest"?"latest":"unread"}catch{return"unread"}}function uo(e,t){let[n,o]=(0,B.useState)(),[r,s]=(0,B.useState)(),a=n??(e?{lastReadSeq:e.readPosition?.lastReadSeq}:void 0);!n&&a&&o(a);let l=r??(t?{throughSeq:t.events.at(-1)?.seq,unreadCursor:t.unreadCursor,unreadPage:t.unreadPage}:void 0);return!r&&l&&s(l),{...dn(a?.lastReadSeq,l?l.throughSeq:e?.events.at(-1)?.seq),...l?.unreadCursor?{unreadCursor:l.unreadCursor,unreadPage:l.unreadPage}:void 0}}function dn(e,t){return e===void 0?{}:t===void 0||t<=e?{lastReadSeq:e}:{lastReadSeq:e,unread:{afterSeq:e,throughSeq:t}}}function fn(e,t){let n=e.events[0]?.seq;if(!e.unreadCursor||n!==void 0&&t.lastReadSeq+1<n)return{...e,readPosition:t};let{unreadCursor:o,unreadPage:r,...s}=e;return{...s,readPosition:t}}function co(e){let t=_(),{mutate:n}=U({mutationFn:o=>We(qe,`/api/conversations/${encodeURIComponent(e)}/read-position`,{lastReadSeq:o}),onSuccess:o=>{t.setQueryData(E(e),r=>r&&fn(r,o))}});return(0,B.useCallback)(o=>{let r=t.getQueryData(E(e))?.readPosition?.lastReadSeq;r!==void 0&&o<=r||n(o)},[e,n,t])}function lo(e){let t=(0,B.useRef)(e.onRead);t.current=e.onRead;let n=(0,B.useRef)(e.paused);n.current=e.paused;let o=(0,B.useRef)(e.lastReadSeq??-1),r=!!e.onRead;(0,B.useEffect)(()=>{let s=e.content,a=D(s);if(!r||!s||!a||typeof IntersectionObserver>"u")return;let l=new Set,d,M=null,K=()=>{d!==void 0&&window.clearTimeout(d),d=void 0;let m=M;M=null,!(m===null||m<=o.current)&&(o.current=m,t.current?.(m))},F=()=>{if(!(n.current||document.visibilityState!=="visible")){for(let m of l){let h=Number(m.dataset.transcriptSeq);Number.isSafeInteger(h)&&(M=Math.max(M??-1,h))}M!==null&&(d??=window.setTimeout(K,ln))}},b=()=>{document.visibilityState==="visible"?F():K()},q=new IntersectionObserver(m=>{for(let h of m){let T=h.target;h.isIntersecting&&T.isConnected?l.add(T):l.delete(T)}F()},{root:a===window?null:a}),V=m=>{if(!(m instanceof HTMLElement))return[];let h=[...m.querySelectorAll(Et)];return m.matches(Et)?[m,...h]:h},v=m=>{for(let h of V(m))q.observe(h)},x=m=>{for(let h of V(m))q.unobserve(h),l.delete(h)},j=new MutationObserver(m=>{let h=!1;for(let T of m)if(T.addedNodes.forEach(v),T.removedNodes.forEach(x),T.type==="attributes"){let p=T.target;q.observe(p),h||=l.has(p)}h&&F()});return j.observe(s,{attributeFilter:[Mt],childList:!0,subtree:!0}),v(s),document.addEventListener("visibilitychange",b),()=>{K(),q.disconnect(),j.disconnect(),document.removeEventListener("visibilitychange",b)}},[r,e.content])}export{hn as a,bn as b,Cn as c,wn as d,Sn as e,Rn as f,At as g,En as h,Tn as i,dt as j,Pn as k,E as l,Ft as m,Vt as n,jt as o,Nn as p,Un as q,kn as r,Bn as s,Kn as t,Qn as u,Fn as v,ht as w,bt as x,tt as y,zn as z,Wn as A,Yn as B,Jn as C,Xn as D,Gn as E,D as F,ao as G,io as H,uo as I,co as J,lo as K};
@@ -1 +0,0 @@
1
- import{g as y}from"./chunk-NQOJAZFQ.js";import{b as v}from"./chunk-CR2ICLSH.js";import{Oc as w,a as h,b as i}from"./chunk-YPMUHXYT.js";import{c as o}from"./chunk-7SZRL6FY.js";var r=o(h(),1);var l=o(h(),1),s=o(i(),1),N=(0,l.lazy)(()=>import("./DrawerContent-RYYS57ZH.js").then(e=>({default:e.DrawerContent})));function g(e){return(0,s.jsx)(l.Suspense,{fallback:null,children:(0,s.jsx)(N,{...e},e.openKey)})}var t=o(i(),1),D="(min-width: 1280px)";function x(e){let a=window.matchMedia(D);return a.addEventListener("change",e),()=>a.removeEventListener("change",e)}function S(){return window.matchMedia(D).matches}function C(){return(0,r.useSyncExternalStore)(x,S,()=>!1)}function B(e){let{onClose:a,overlay:d}=e,m=`Close ${e.label.toLowerCase()}`,n=C(),u=(0,r.useRef)(null),f=(0,r.useRef)(n);return(0,r.useEffect)(()=>{n&&!f.current&&!document.querySelector("[data-dashboard-modal]")&&u.current?.focus({preventScroll:!0}),f.current=n},[n]),(0,r.useEffect)(()=>{if(!n||d)return;function b(c){c.key==="Escape"&&!c.defaultPrevented&&!document.querySelector("[data-dashboard-modal]")&&(c.preventDefault(),a())}return document.addEventListener("keydown",b),()=>document.removeEventListener("keydown",b)},[n,d,a]),n?d?(0,t.jsx)(g,{actions:e.actions,closeLabel:m,header:e.title,label:e.label,onClose:a,openKey:e.label,width:"wide",children:e.children}):(0,t.jsxs)("aside",{"aria-label":e.label,className:"grid min-h-0 min-w-0 grid-rows-[auto_minmax(0,1fr)] border-l border-dashboard-border bg-dashboard-bg-elevated",children:[(0,t.jsxs)("header",{className:"flex items-center justify-between gap-3 border-b border-dashboard-border py-2 pl-5 pr-3",children:[(0,t.jsx)("div",{className:"min-w-0 flex-1",children:e.title}),(0,t.jsxs)("div",{className:"flex shrink-0 items-center gap-0.5",children:[e.actions,(0,t.jsx)(v,{ref:u,"aria-label":m,onClick:a,size:"icon",children:(0,t.jsx)(w,{"aria-hidden":"true",size:15})})]})]}),(0,t.jsx)("div",{className:"thin-scrollbar min-h-0 overflow-y-auto overscroll-contain",children:e.children})]}):(0,t.jsx)(y,{label:e.label,title:e.sheetTitle,onClose:a,children:e.actions?(0,t.jsxs)("div",{className:"grid h-full min-h-0 grid-rows-[minmax(0,1fr)_auto]",children:[(0,t.jsx)("div",{className:"min-h-0",children:e.children}),(0,t.jsx)("div",{className:"flex justify-end gap-1 border-t border-dashboard-border px-4 py-2",children:e.actions})]}):e.children})}export{g as a,C as b,B as c};