@athenaintel/react 0.10.28 → 0.10.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { jsx, Fragment as Fragment$1, jsxs } from "react/jsx-runtime";
2
- import { bindExternalStoreMessage, getExternalStoreMessages, INTERNAL, useAssistantTransportRuntime, useAuiState, useAssistantRuntime, useThread, useThreadList, unstable_useRemoteThreadListRuntime, Tools, useAui, AssistantRuntimeProvider, useComposerRuntime, MessagePartPrimitive, MessagePrimitive, useScrollLock, ActionBarPrimitive, AuiIf, ActionBarMorePrimitive, ThreadPrimitive, ComposerPrimitive, ErrorPrimitive, ThreadListPrimitive, ThreadListItemPrimitive } from "@assistant-ui/react";
2
+ import { bindExternalStoreMessage, getExternalStoreMessages, INTERNAL, useAssistantTransportRuntime, useAuiState, useAssistantRuntime, useThread, useThreadList, useRemoteThreadListRuntime, Tools, useAui, AssistantRuntimeProvider, useComposerRuntime, MessagePartPrimitive, MessagePrimitive, useScrollLock, ActionBarPrimitive, AuiIf, ActionBarMorePrimitive, ThreadPrimitive, ComposerPrimitive, ErrorPrimitive, ThreadListPrimitive, ThreadListItemPrimitive } from "@assistant-ui/react";
3
3
  import * as React from "react";
4
4
  import React__default, { useMemo, useState, useRef, useEffect, useLayoutEffect, useContext, createContext, useCallback, useDebugValue, forwardRef, createRef, memo, createElement, version as version$1, useImperativeHandle } from "react";
5
5
  import { A as AthenaAuthContext } from "./AthenaAuthContext-DQsdayH2.js";
@@ -129,6 +129,10 @@ function isTrustedOrigin({
129
129
  }
130
130
  }
131
131
  const BRIDGE_TIMEOUT_MS = 2e3;
132
+ const TOKEN_REFRESH_BUFFER_MS = 5 * 60 * 1e3;
133
+ const TOKEN_REFRESH_RETRY_BASE_MS = 60 * 1e3;
134
+ const TOKEN_REFRESH_RETRY_MAX_MS = 5 * 60 * 1e3;
135
+ const DEFAULT_TOKEN_REFRESH_MS = 55 * 60 * 1e3;
132
136
  const EMPTY_TRUSTED_ORIGINS = [];
133
137
  const normalizeOrigin = (value) => {
134
138
  try {
@@ -137,6 +141,20 @@ const normalizeOrigin = (value) => {
137
141
  return null;
138
142
  }
139
143
  };
144
+ const getTokenRefreshDelay = (expiresAt, nowMs) => {
145
+ if (typeof expiresAt !== "string") {
146
+ return DEFAULT_TOKEN_REFRESH_MS;
147
+ }
148
+ const expiresAtMs = Date.parse(expiresAt);
149
+ if (!Number.isFinite(expiresAtMs)) {
150
+ return DEFAULT_TOKEN_REFRESH_MS;
151
+ }
152
+ return Math.max(TOKEN_REFRESH_RETRY_BASE_MS, expiresAtMs - nowMs - TOKEN_REFRESH_BUFFER_MS);
153
+ };
154
+ const getAuthRetryDelay = (retryAttempt) => {
155
+ const safeAttempt = Number.isFinite(retryAttempt) ? Math.max(0, Math.floor(retryAttempt)) : 0;
156
+ return Math.min(TOKEN_REFRESH_RETRY_MAX_MS, TOKEN_REFRESH_RETRY_BASE_MS * 2 ** safeAttempt);
157
+ };
140
158
  function useParentBridge({
141
159
  trustedOrigins = EMPTY_TRUSTED_ORIGINS
142
160
  } = {}) {
@@ -159,8 +177,7 @@ function useParentBridge({
159
177
  apiUrl: null,
160
178
  backendUrl: null,
161
179
  appUrl: null,
162
- // If not in an iframe, we're ready immediately (standalone mode)
163
- ready: !isInIframe
180
+ ready: false
164
181
  });
165
182
  const readySignalSent = useRef(false);
166
183
  const configReceived = useRef(false);
@@ -187,7 +204,6 @@ function useParentBridge({
187
204
  setState((prev) => ({
188
205
  ...prev,
189
206
  token: event.data.token,
190
- // If we got a token, we're ready even without config
191
207
  ready: true
192
208
  }));
193
209
  }
@@ -205,6 +221,105 @@ function useParentBridge({
205
221
  clearTimeout(timer);
206
222
  };
207
223
  }, [isInIframe, runtimeTrustedOrigins]);
224
+ useEffect(() => {
225
+ if (isInIframe) return;
226
+ if (typeof window === "undefined") return;
227
+ let cancelled = false;
228
+ let requestTimer = null;
229
+ let refreshTimer = null;
230
+ let controller = null;
231
+ let retryAttempt = 0;
232
+ const clearRequestTimer = () => {
233
+ if (requestTimer) {
234
+ clearTimeout(requestTimer);
235
+ requestTimer = null;
236
+ }
237
+ };
238
+ const clearRefreshTimer = () => {
239
+ if (refreshTimer) {
240
+ clearTimeout(refreshTimer);
241
+ refreshTimer = null;
242
+ }
243
+ };
244
+ const markReady = () => {
245
+ if (cancelled) return;
246
+ setState((prev) => prev.ready ? prev : { ...prev, ready: true });
247
+ };
248
+ const scheduleRefresh = (expiresAt) => {
249
+ clearRefreshTimer();
250
+ retryAttempt = 0;
251
+ const delay = getTokenRefreshDelay(expiresAt, Date.now());
252
+ refreshTimer = setTimeout(() => {
253
+ void fetchAuth({ markReadyOnFailure: false });
254
+ }, delay);
255
+ };
256
+ const scheduleRetry = () => {
257
+ clearRefreshTimer();
258
+ const delay = getAuthRetryDelay(retryAttempt);
259
+ retryAttempt += 1;
260
+ refreshTimer = setTimeout(() => {
261
+ void fetchAuth({ markReadyOnFailure: false });
262
+ }, delay);
263
+ };
264
+ const fetchAuth = async ({
265
+ markReadyOnFailure
266
+ }) => {
267
+ controller == null ? void 0 : controller.abort();
268
+ controller = new AbortController();
269
+ clearRequestTimer();
270
+ requestTimer = setTimeout(() => {
271
+ controller == null ? void 0 : controller.abort();
272
+ if (markReadyOnFailure) {
273
+ markReady();
274
+ }
275
+ }, BRIDGE_TIMEOUT_MS);
276
+ try {
277
+ const resp = await fetch("/_athena/auth", {
278
+ credentials: "include",
279
+ headers: { Accept: "application/json" },
280
+ signal: controller.signal
281
+ });
282
+ if (cancelled) return;
283
+ if (!resp.ok) {
284
+ if (resp.status === 404) {
285
+ markReady();
286
+ } else if (markReadyOnFailure) {
287
+ markReady();
288
+ scheduleRetry();
289
+ } else {
290
+ scheduleRetry();
291
+ }
292
+ return;
293
+ }
294
+ const data = await resp.json();
295
+ if (cancelled) return;
296
+ setState({
297
+ token: typeof data.token === "string" ? data.token : null,
298
+ apiUrl: typeof data.apiUrl === "string" ? data.apiUrl : null,
299
+ backendUrl: typeof data.backendUrl === "string" ? data.backendUrl : null,
300
+ appUrl: typeof data.appUrl === "string" ? data.appUrl : null,
301
+ ready: true
302
+ });
303
+ scheduleRefresh(data.expires_at);
304
+ } catch {
305
+ if (markReadyOnFailure) {
306
+ markReady();
307
+ }
308
+ if (!cancelled) {
309
+ scheduleRetry();
310
+ }
311
+ } finally {
312
+ clearRequestTimer();
313
+ }
314
+ };
315
+ void fetchAuth({ markReadyOnFailure: true });
316
+ return () => {
317
+ cancelled = true;
318
+ controller == null ? void 0 : controller.abort();
319
+ clearRequestTimer();
320
+ clearRefreshTimer();
321
+ };
322
+ }, [isInIframe]);
208
323
  return state;
209
324
  }
210
325
  function useParentAuth() {
@@ -3893,7 +4008,7 @@ const twMerge = /* @__PURE__ */ createTailwindMerge(getDefaultConfig);
3893
4008
  function cn(...inputs) {
3894
4009
  return twMerge(clsx(inputs));
3895
4010
  }
3896
- function isRecord(value) {
4011
+ function isRecord$1(value) {
3897
4012
  return typeof value === "object" && value !== null && !Array.isArray(value);
3898
4013
  }
3899
4014
  function $constructor(name, initializer2, params) {
@@ -8277,10 +8392,10 @@ const autoCloseInFlightSubgraphMessages = (msgs) => {
8277
8392
  const beginIds = /* @__PURE__ */ new Set();
8278
8393
  const endIds = /* @__PURE__ */ new Set();
8279
8394
  for (const message of msgs) {
8280
- if (!isRecord(message)) continue;
8395
+ if (!isRecord$1(message)) continue;
8281
8396
  if (message.type === "ai" && Array.isArray(message.tool_calls)) {
8282
8397
  for (const toolCall of message.tool_calls) {
8283
- if (!isRecord(toolCall)) continue;
8398
+ if (!isRecord$1(toolCall)) continue;
8284
8399
  const id = toolCall.id;
8285
8400
  if (typeof id === "string") beginIds.add(id);
8286
8401
  }
@@ -8346,7 +8461,7 @@ const contentToParts = (content) => {
8346
8461
  const getNumberAtPath = (value, path) => {
8347
8462
  let current = value;
8348
8463
  for (const segment of path) {
8349
- if (!isRecord(current)) {
8464
+ if (!isRecord$1(current)) {
8350
8465
  return void 0;
8351
8466
  }
8352
8467
  current = current[segment];
@@ -8367,7 +8482,7 @@ const buildCustomMetadata = ({
8367
8482
  }) => {
8368
8483
  const customMetadata = additionalKwargs ? { ...additionalKwargs } : {};
8369
8484
  const reasoningTokens = extractReasoningTokens({ usageMetadata, responseMetadata });
8370
- const existingAthenaMetadata = isRecord(customMetadata._athena) ? customMetadata._athena : void 0;
8485
+ const existingAthenaMetadata = isRecord$1(customMetadata._athena) ? customMetadata._athena : void 0;
8371
8486
  const athenaMetadata = {
8372
8487
  ...existingAthenaMetadata ?? {}
8373
8488
  };
@@ -8386,9 +8501,9 @@ const buildCustomMetadata = ({
8386
8501
  return Object.keys(customMetadata).length > 0 ? customMetadata : void 0;
8387
8502
  };
8388
8503
  const getSubgraphMessages = (artifact) => {
8389
- if (!isRecord(artifact)) return void 0;
8504
+ if (!isRecord$1(artifact)) return void 0;
8390
8505
  const subgraphState = artifact.subgraph_state;
8391
- if (!isRecord(subgraphState)) return void 0;
8506
+ if (!isRecord$1(subgraphState)) return void 0;
8392
8507
  const messages = subgraphState.messages;
8393
8508
  return Array.isArray(messages) && messages.length > 0 ? messages : void 0;
8394
8509
  };
@@ -9044,7 +9159,7 @@ const useAthenaRuntime = (config2) => {
9044
9159
  if (status.isRunning) {
9045
9160
  try {
9046
9161
  const lastMessageId = ((_b = runtime.thread.getState().messages.at(-1)) == null ? void 0 : _b.id) ?? null;
9047
- runtime.thread.unstable_resumeRun({ parentId: lastMessageId });
9162
+ runtime.thread.resumeRun({ parentId: lastMessageId });
9048
9163
  } catch (resumeErr) {
9049
9164
  if (IS_DEV) {
9050
9165
  console.error("[AthenaSDK] Failed to resume running thread:", resumeErr);
@@ -9097,12 +9212,12 @@ function useComposedRefs(...refs) {
9097
9212
  return React.useCallback(composeRefs(...refs), refs);
9098
9213
  }
9099
9214
  // @__NO_SIDE_EFFECTS__
9100
- function createSlot$7(ownerName) {
9101
- const SlotClone = /* @__PURE__ */ createSlotClone$7(ownerName);
9215
+ function createSlot(ownerName) {
9216
+ const SlotClone = /* @__PURE__ */ createSlotClone(ownerName);
9102
9217
  const Slot2 = React.forwardRef((props, forwardedRef) => {
9103
9218
  const { children, ...slotProps } = props;
9104
9219
  const childrenArray = React.Children.toArray(children);
9105
- const slottable = childrenArray.find(isSlottable$7);
9220
+ const slottable = childrenArray.find(isSlottable);
9106
9221
  if (slottable) {
9107
9222
  const newElement = slottable.props.children;
9108
9223
  const newChildren = childrenArray.map((child) => {
@@ -9120,13 +9235,14 @@ function createSlot$7(ownerName) {
9120
9235
  Slot2.displayName = `${ownerName}.Slot`;
9121
9236
  return Slot2;
9122
9237
  }
9238
+ var Slot = /* @__PURE__ */ createSlot("Slot");
9123
9239
  // @__NO_SIDE_EFFECTS__
9124
- function createSlotClone$7(ownerName) {
9240
+ function createSlotClone(ownerName) {
9125
9241
  const SlotClone = React.forwardRef((props, forwardedRef) => {
9126
9242
  const { children, ...slotProps } = props;
9127
9243
  if (React.isValidElement(children)) {
9128
- const childrenRef = getElementRef$8(children);
9129
- const props2 = mergeProps$7(slotProps, children.props);
9244
+ const childrenRef = getElementRef$1(children);
9245
+ const props2 = mergeProps(slotProps, children.props);
9130
9246
  if (children.type !== React.Fragment) {
9131
9247
  props2.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
9132
9248
  }
@@ -9137,11 +9253,21 @@ function createSlotClone$7(ownerName) {
9137
9253
  SlotClone.displayName = `${ownerName}.SlotClone`;
9138
9254
  return SlotClone;
9139
9255
  }
9140
- var SLOTTABLE_IDENTIFIER$7 = Symbol("radix.slottable");
9141
- function isSlottable$7(child) {
9142
- return React.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER$7;
9256
+ var SLOTTABLE_IDENTIFIER = Symbol("radix.slottable");
9257
+ // @__NO_SIDE_EFFECTS__
9258
+ function createSlottable(ownerName) {
9259
+ const Slottable2 = ({ children }) => {
9260
+ return /* @__PURE__ */ jsx(Fragment$1, { children });
9261
+ };
9262
+ Slottable2.displayName = `${ownerName}.Slottable`;
9263
+ Slottable2.__radixId = SLOTTABLE_IDENTIFIER;
9264
+ return Slottable2;
9265
+ }
9266
+ var Slottable$1 = /* @__PURE__ */ createSlottable("Slottable");
9267
+ function isSlottable(child) {
9268
+ return React.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER;
9143
9269
  }
9144
- function mergeProps$7(slotProps, childProps) {
9270
+ function mergeProps(slotProps, childProps) {
9145
9271
  const overrideProps = { ...childProps };
9146
9272
  for (const propName in childProps) {
9147
9273
  const slotPropValue = slotProps[propName];
@@ -9165,7 +9291,7 @@ function mergeProps$7(slotProps, childProps) {
9165
9291
  }
9166
9292
  return { ...slotProps, ...overrideProps };
9167
9293
  }
9168
- function getElementRef$8(element) {
9294
+ function getElementRef$1(element) {
9169
9295
  var _a2, _b;
9170
9296
  let getter = (_a2 = Object.getOwnPropertyDescriptor(element.props, "ref")) == null ? void 0 : _a2.get;
9171
9297
  let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
@@ -9199,7 +9325,7 @@ var NODES$6 = [
9199
9325
  "ul"
9200
9326
  ];
9201
9327
  var Primitive$6 = NODES$6.reduce((primitive, node) => {
9202
- const Slot2 = /* @__PURE__ */ createSlot$7(`Primitive.${node}`);
9328
+ const Slot2 = /* @__PURE__ */ createSlot(`Primitive.${node}`);
9203
9329
  const Node4 = React.forwardRef((props, forwardedRef) => {
9204
9330
  const { asChild, ...primitiveProps } = props;
9205
9331
  const Comp = asChild ? Slot2 : node;
@@ -9374,89 +9500,6 @@ function composeContextScopes$2(...scopes) {
9374
9500
  createScope.scopeName = baseScope.scopeName;
9375
9501
  return createScope;
9376
9502
  }
9377
- // @__NO_SIDE_EFFECTS__
9378
- function createSlot$6(ownerName) {
9379
- const SlotClone = /* @__PURE__ */ createSlotClone$6(ownerName);
9380
- const Slot2 = React.forwardRef((props, forwardedRef) => {
9381
- const { children, ...slotProps } = props;
9382
- const childrenArray = React.Children.toArray(children);
9383
- const slottable = childrenArray.find(isSlottable$6);
9384
- if (slottable) {
9385
- const newElement = slottable.props.children;
9386
- const newChildren = childrenArray.map((child) => {
9387
- if (child === slottable) {
9388
- if (React.Children.count(newElement) > 1) return React.Children.only(null);
9389
- return React.isValidElement(newElement) ? newElement.props.children : null;
9390
- } else {
9391
- return child;
9392
- }
9393
- });
9394
- return /* @__PURE__ */ jsx(SlotClone, { ...slotProps, ref: forwardedRef, children: React.isValidElement(newElement) ? React.cloneElement(newElement, void 0, newChildren) : null });
9395
- }
9396
- return /* @__PURE__ */ jsx(SlotClone, { ...slotProps, ref: forwardedRef, children });
9397
- });
9398
- Slot2.displayName = `${ownerName}.Slot`;
9399
- return Slot2;
9400
- }
9401
- // @__NO_SIDE_EFFECTS__
9402
- function createSlotClone$6(ownerName) {
9403
- const SlotClone = React.forwardRef((props, forwardedRef) => {
9404
- const { children, ...slotProps } = props;
9405
- if (React.isValidElement(children)) {
9406
- const childrenRef = getElementRef$7(children);
9407
- const props2 = mergeProps$6(slotProps, children.props);
9408
- if (children.type !== React.Fragment) {
9409
- props2.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
9410
- }
9411
- return React.cloneElement(children, props2);
9412
- }
9413
- return React.Children.count(children) > 1 ? React.Children.only(null) : null;
9414
- });
9415
- SlotClone.displayName = `${ownerName}.SlotClone`;
9416
- return SlotClone;
9417
- }
9418
- var SLOTTABLE_IDENTIFIER$6 = Symbol("radix.slottable");
9419
- function isSlottable$6(child) {
9420
- return React.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER$6;
9421
- }
9422
- function mergeProps$6(slotProps, childProps) {
9423
- const overrideProps = { ...childProps };
9424
- for (const propName in childProps) {
9425
- const slotPropValue = slotProps[propName];
9426
- const childPropValue = childProps[propName];
9427
- const isHandler = /^on[A-Z]/.test(propName);
9428
- if (isHandler) {
9429
- if (slotPropValue && childPropValue) {
9430
- overrideProps[propName] = (...args) => {
9431
- const result = childPropValue(...args);
9432
- slotPropValue(...args);
9433
- return result;
9434
- };
9435
- } else if (slotPropValue) {
9436
- overrideProps[propName] = slotPropValue;
9437
- }
9438
- } else if (propName === "style") {
9439
- overrideProps[propName] = { ...slotPropValue, ...childPropValue };
9440
- } else if (propName === "className") {
9441
- overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
9442
- }
9443
- }
9444
- return { ...slotProps, ...overrideProps };
9445
- }
9446
- function getElementRef$7(element) {
9447
- var _a2, _b;
9448
- let getter = (_a2 = Object.getOwnPropertyDescriptor(element.props, "ref")) == null ? void 0 : _a2.get;
9449
- let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
9450
- if (mayWarn) {
9451
- return element.ref;
9452
- }
9453
- getter = (_b = Object.getOwnPropertyDescriptor(element, "ref")) == null ? void 0 : _b.get;
9454
- mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
9455
- if (mayWarn) {
9456
- return element.props.ref;
9457
- }
9458
- return element.props.ref || element.ref;
9459
- }
9460
9503
  var NODES$5 = [
9461
9504
  "a",
9462
9505
  "button",
@@ -9477,7 +9520,7 @@ var NODES$5 = [
9477
9520
  "ul"
9478
9521
  ];
9479
9522
  var Primitive$5 = NODES$5.reduce((primitive, node) => {
9480
- const Slot2 = /* @__PURE__ */ createSlot$6(`Primitive.${node}`);
9523
+ const Slot2 = /* @__PURE__ */ createSlot(`Primitive.${node}`);
9481
9524
  const Node4 = React.forwardRef((props, forwardedRef) => {
9482
9525
  const { asChild, ...primitiveProps } = props;
9483
9526
  const Comp = asChild ? Slot2 : node;
@@ -9499,7 +9542,7 @@ var Presence = (props) => {
9499
9542
  const { present, children } = props;
9500
9543
  const presence = usePresence(present);
9501
9544
  const child = typeof children === "function" ? children({ present: presence.isPresent }) : React.Children.only(children);
9502
- const ref = useComposedRefs(presence.ref, getElementRef$6(child));
9545
+ const ref = useComposedRefs(presence.ref, getElementRef(child));
9503
9546
  const forceMount = typeof children === "function";
9504
9547
  return forceMount || presence.isPresent ? React.cloneElement(child, { ref }) : null;
9505
9548
  };
@@ -9598,7 +9641,7 @@ function usePresence(present) {
9598
9641
  function getAnimationName(styles) {
9599
9642
  return (styles == null ? void 0 : styles.animationName) || "none";
9600
9643
  }
9601
- function getElementRef$6(element) {
9644
+ function getElementRef(element) {
9602
9645
  var _a2, _b;
9603
9646
  let getter = (_a2 = Object.getOwnPropertyDescriptor(element.props, "ref")) == null ? void 0 : _a2.get;
9604
9647
  let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
@@ -9751,89 +9794,6 @@ function getState(open) {
9751
9794
  return open ? "open" : "closed";
9752
9795
  }
9753
9796
  var Root$1 = Collapsible$1;
9754
- // @__NO_SIDE_EFFECTS__
9755
- function createSlot$5(ownerName) {
9756
- const SlotClone = /* @__PURE__ */ createSlotClone$5(ownerName);
9757
- const Slot2 = React.forwardRef((props, forwardedRef) => {
9758
- const { children, ...slotProps } = props;
9759
- const childrenArray = React.Children.toArray(children);
9760
- const slottable = childrenArray.find(isSlottable$5);
9761
- if (slottable) {
9762
- const newElement = slottable.props.children;
9763
- const newChildren = childrenArray.map((child) => {
9764
- if (child === slottable) {
9765
- if (React.Children.count(newElement) > 1) return React.Children.only(null);
9766
- return React.isValidElement(newElement) ? newElement.props.children : null;
9767
- } else {
9768
- return child;
9769
- }
9770
- });
9771
- return /* @__PURE__ */ jsx(SlotClone, { ...slotProps, ref: forwardedRef, children: React.isValidElement(newElement) ? React.cloneElement(newElement, void 0, newChildren) : null });
9772
- }
9773
- return /* @__PURE__ */ jsx(SlotClone, { ...slotProps, ref: forwardedRef, children });
9774
- });
9775
- Slot2.displayName = `${ownerName}.Slot`;
9776
- return Slot2;
9777
- }
9778
- // @__NO_SIDE_EFFECTS__
9779
- function createSlotClone$5(ownerName) {
9780
- const SlotClone = React.forwardRef((props, forwardedRef) => {
9781
- const { children, ...slotProps } = props;
9782
- if (React.isValidElement(children)) {
9783
- const childrenRef = getElementRef$5(children);
9784
- const props2 = mergeProps$5(slotProps, children.props);
9785
- if (children.type !== React.Fragment) {
9786
- props2.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
9787
- }
9788
- return React.cloneElement(children, props2);
9789
- }
9790
- return React.Children.count(children) > 1 ? React.Children.only(null) : null;
9791
- });
9792
- SlotClone.displayName = `${ownerName}.SlotClone`;
9793
- return SlotClone;
9794
- }
9795
- var SLOTTABLE_IDENTIFIER$5 = Symbol("radix.slottable");
9796
- function isSlottable$5(child) {
9797
- return React.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER$5;
9798
- }
9799
- function mergeProps$5(slotProps, childProps) {
9800
- const overrideProps = { ...childProps };
9801
- for (const propName in childProps) {
9802
- const slotPropValue = slotProps[propName];
9803
- const childPropValue = childProps[propName];
9804
- const isHandler = /^on[A-Z]/.test(propName);
9805
- if (isHandler) {
9806
- if (slotPropValue && childPropValue) {
9807
- overrideProps[propName] = (...args) => {
9808
- const result = childPropValue(...args);
9809
- slotPropValue(...args);
9810
- return result;
9811
- };
9812
- } else if (slotPropValue) {
9813
- overrideProps[propName] = slotPropValue;
9814
- }
9815
- } else if (propName === "style") {
9816
- overrideProps[propName] = { ...slotPropValue, ...childPropValue };
9817
- } else if (propName === "className") {
9818
- overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
9819
- }
9820
- }
9821
- return { ...slotProps, ...overrideProps };
9822
- }
9823
- function getElementRef$5(element) {
9824
- var _a2, _b;
9825
- let getter = (_a2 = Object.getOwnPropertyDescriptor(element.props, "ref")) == null ? void 0 : _a2.get;
9826
- let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
9827
- if (mayWarn) {
9828
- return element.ref;
9829
- }
9830
- getter = (_b = Object.getOwnPropertyDescriptor(element, "ref")) == null ? void 0 : _b.get;
9831
- mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
9832
- if (mayWarn) {
9833
- return element.props.ref;
9834
- }
9835
- return element.props.ref || element.ref;
9836
- }
9837
9797
  var NODES$4 = [
9838
9798
  "a",
9839
9799
  "button",
@@ -9854,7 +9814,7 @@ var NODES$4 = [
9854
9814
  "ul"
9855
9815
  ];
9856
9816
  var Primitive$4 = NODES$4.reduce((primitive, node) => {
9857
- const Slot2 = /* @__PURE__ */ createSlot$5(`Primitive.${node}`);
9817
+ const Slot2 = /* @__PURE__ */ createSlot(`Primitive.${node}`);
9858
9818
  const Node4 = React.forwardRef((props, forwardedRef) => {
9859
9819
  const { asChild, ...primitiveProps } = props;
9860
9820
  const Comp = asChild ? Slot2 : node;
@@ -10092,89 +10052,6 @@ function handleAndDispatchCustomEvent(name, handler, detail, { discrete }) {
10092
10052
  target.dispatchEvent(event);
10093
10053
  }
10094
10054
  }
10095
- // @__NO_SIDE_EFFECTS__
10096
- function createSlot$4(ownerName) {
10097
- const SlotClone = /* @__PURE__ */ createSlotClone$4(ownerName);
10098
- const Slot2 = React.forwardRef((props, forwardedRef) => {
10099
- const { children, ...slotProps } = props;
10100
- const childrenArray = React.Children.toArray(children);
10101
- const slottable = childrenArray.find(isSlottable$4);
10102
- if (slottable) {
10103
- const newElement = slottable.props.children;
10104
- const newChildren = childrenArray.map((child) => {
10105
- if (child === slottable) {
10106
- if (React.Children.count(newElement) > 1) return React.Children.only(null);
10107
- return React.isValidElement(newElement) ? newElement.props.children : null;
10108
- } else {
10109
- return child;
10110
- }
10111
- });
10112
- return /* @__PURE__ */ jsx(SlotClone, { ...slotProps, ref: forwardedRef, children: React.isValidElement(newElement) ? React.cloneElement(newElement, void 0, newChildren) : null });
10113
- }
10114
- return /* @__PURE__ */ jsx(SlotClone, { ...slotProps, ref: forwardedRef, children });
10115
- });
10116
- Slot2.displayName = `${ownerName}.Slot`;
10117
- return Slot2;
10118
- }
10119
- // @__NO_SIDE_EFFECTS__
10120
- function createSlotClone$4(ownerName) {
10121
- const SlotClone = React.forwardRef((props, forwardedRef) => {
10122
- const { children, ...slotProps } = props;
10123
- if (React.isValidElement(children)) {
10124
- const childrenRef = getElementRef$4(children);
10125
- const props2 = mergeProps$4(slotProps, children.props);
10126
- if (children.type !== React.Fragment) {
10127
- props2.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
10128
- }
10129
- return React.cloneElement(children, props2);
10130
- }
10131
- return React.Children.count(children) > 1 ? React.Children.only(null) : null;
10132
- });
10133
- SlotClone.displayName = `${ownerName}.SlotClone`;
10134
- return SlotClone;
10135
- }
10136
- var SLOTTABLE_IDENTIFIER$4 = Symbol("radix.slottable");
10137
- function isSlottable$4(child) {
10138
- return React.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER$4;
10139
- }
10140
- function mergeProps$4(slotProps, childProps) {
10141
- const overrideProps = { ...childProps };
10142
- for (const propName in childProps) {
10143
- const slotPropValue = slotProps[propName];
10144
- const childPropValue = childProps[propName];
10145
- const isHandler = /^on[A-Z]/.test(propName);
10146
- if (isHandler) {
10147
- if (slotPropValue && childPropValue) {
10148
- overrideProps[propName] = (...args) => {
10149
- const result = childPropValue(...args);
10150
- slotPropValue(...args);
10151
- return result;
10152
- };
10153
- } else if (slotPropValue) {
10154
- overrideProps[propName] = slotPropValue;
10155
- }
10156
- } else if (propName === "style") {
10157
- overrideProps[propName] = { ...slotPropValue, ...childPropValue };
10158
- } else if (propName === "className") {
10159
- overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
10160
- }
10161
- }
10162
- return { ...slotProps, ...overrideProps };
10163
- }
10164
- function getElementRef$4(element) {
10165
- var _a2, _b;
10166
- let getter = (_a2 = Object.getOwnPropertyDescriptor(element.props, "ref")) == null ? void 0 : _a2.get;
10167
- let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
10168
- if (mayWarn) {
10169
- return element.ref;
10170
- }
10171
- getter = (_b = Object.getOwnPropertyDescriptor(element, "ref")) == null ? void 0 : _b.get;
10172
- mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
10173
- if (mayWarn) {
10174
- return element.props.ref;
10175
- }
10176
- return element.props.ref || element.ref;
10177
- }
10178
10055
  var NODES$3 = [
10179
10056
  "a",
10180
10057
  "button",
@@ -10195,7 +10072,7 @@ var NODES$3 = [
10195
10072
  "ul"
10196
10073
  ];
10197
10074
  var Primitive$3 = NODES$3.reduce((primitive, node) => {
10198
- const Slot2 = /* @__PURE__ */ createSlot$4(`Primitive.${node}`);
10075
+ const Slot2 = /* @__PURE__ */ createSlot(`Primitive.${node}`);
10199
10076
  const Node4 = React.forwardRef((props, forwardedRef) => {
10200
10077
  const { asChild, ...primitiveProps } = props;
10201
10078
  const Comp = asChild ? Slot2 : node;
@@ -10217,100 +10094,6 @@ var Portal$1 = React.forwardRef((props, forwardedRef) => {
10217
10094
  return container ? ReactDOM__default.createPortal(/* @__PURE__ */ jsx(Primitive$3.div, { ...portalProps, ref: forwardedRef }), container) : null;
10218
10095
  });
10219
10096
  Portal$1.displayName = PORTAL_NAME$1;
10220
- // @__NO_SIDE_EFFECTS__
10221
- function createSlot$3(ownerName) {
10222
- const SlotClone = /* @__PURE__ */ createSlotClone$3(ownerName);
10223
- const Slot2 = React.forwardRef((props, forwardedRef) => {
10224
- const { children, ...slotProps } = props;
10225
- const childrenArray = React.Children.toArray(children);
10226
- const slottable = childrenArray.find(isSlottable$3);
10227
- if (slottable) {
10228
- const newElement = slottable.props.children;
10229
- const newChildren = childrenArray.map((child) => {
10230
- if (child === slottable) {
10231
- if (React.Children.count(newElement) > 1) return React.Children.only(null);
10232
- return React.isValidElement(newElement) ? newElement.props.children : null;
10233
- } else {
10234
- return child;
10235
- }
10236
- });
10237
- return /* @__PURE__ */ jsx(SlotClone, { ...slotProps, ref: forwardedRef, children: React.isValidElement(newElement) ? React.cloneElement(newElement, void 0, newChildren) : null });
10238
- }
10239
- return /* @__PURE__ */ jsx(SlotClone, { ...slotProps, ref: forwardedRef, children });
10240
- });
10241
- Slot2.displayName = `${ownerName}.Slot`;
10242
- return Slot2;
10243
- }
10244
- var Slot = /* @__PURE__ */ createSlot$3("Slot");
10245
- // @__NO_SIDE_EFFECTS__
10246
- function createSlotClone$3(ownerName) {
10247
- const SlotClone = React.forwardRef((props, forwardedRef) => {
10248
- const { children, ...slotProps } = props;
10249
- if (React.isValidElement(children)) {
10250
- const childrenRef = getElementRef$3(children);
10251
- const props2 = mergeProps$3(slotProps, children.props);
10252
- if (children.type !== React.Fragment) {
10253
- props2.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
10254
- }
10255
- return React.cloneElement(children, props2);
10256
- }
10257
- return React.Children.count(children) > 1 ? React.Children.only(null) : null;
10258
- });
10259
- SlotClone.displayName = `${ownerName}.SlotClone`;
10260
- return SlotClone;
10261
- }
10262
- var SLOTTABLE_IDENTIFIER$3 = Symbol("radix.slottable");
10263
- // @__NO_SIDE_EFFECTS__
10264
- function createSlottable$1(ownerName) {
10265
- const Slottable2 = ({ children }) => {
10266
- return /* @__PURE__ */ jsx(Fragment$1, { children });
10267
- };
10268
- Slottable2.displayName = `${ownerName}.Slottable`;
10269
- Slottable2.__radixId = SLOTTABLE_IDENTIFIER$3;
10270
- return Slottable2;
10271
- }
10272
- var Slottable$1 = /* @__PURE__ */ createSlottable$1("Slottable");
10273
- function isSlottable$3(child) {
10274
- return React.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER$3;
10275
- }
10276
- function mergeProps$3(slotProps, childProps) {
10277
- const overrideProps = { ...childProps };
10278
- for (const propName in childProps) {
10279
- const slotPropValue = slotProps[propName];
10280
- const childPropValue = childProps[propName];
10281
- const isHandler = /^on[A-Z]/.test(propName);
10282
- if (isHandler) {
10283
- if (slotPropValue && childPropValue) {
10284
- overrideProps[propName] = (...args) => {
10285
- const result = childPropValue(...args);
10286
- slotPropValue(...args);
10287
- return result;
10288
- };
10289
- } else if (slotPropValue) {
10290
- overrideProps[propName] = slotPropValue;
10291
- }
10292
- } else if (propName === "style") {
10293
- overrideProps[propName] = { ...slotPropValue, ...childPropValue };
10294
- } else if (propName === "className") {
10295
- overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
10296
- }
10297
- }
10298
- return { ...slotProps, ...overrideProps };
10299
- }
10300
- function getElementRef$3(element) {
10301
- var _a2, _b;
10302
- let getter = (_a2 = Object.getOwnPropertyDescriptor(element.props, "ref")) == null ? void 0 : _a2.get;
10303
- let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
10304
- if (mayWarn) {
10305
- return element.ref;
10306
- }
10307
- getter = (_b = Object.getOwnPropertyDescriptor(element, "ref")) == null ? void 0 : _b.get;
10308
- mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
10309
- if (mayWarn) {
10310
- return element.props.ref;
10311
- }
10312
- return element.props.ref || element.ref;
10313
- }
10314
10097
  var shim$1 = { exports: {} };
10315
10098
  var useSyncExternalStoreShim_production = {};
10316
10099
  /**
@@ -12403,89 +12186,6 @@ const arrow$2 = (options, deps) => {
12403
12186
  options: [options, deps]
12404
12187
  };
12405
12188
  };
12406
- // @__NO_SIDE_EFFECTS__
12407
- function createSlot$2(ownerName) {
12408
- const SlotClone = /* @__PURE__ */ createSlotClone$2(ownerName);
12409
- const Slot2 = React.forwardRef((props, forwardedRef) => {
12410
- const { children, ...slotProps } = props;
12411
- const childrenArray = React.Children.toArray(children);
12412
- const slottable = childrenArray.find(isSlottable$2);
12413
- if (slottable) {
12414
- const newElement = slottable.props.children;
12415
- const newChildren = childrenArray.map((child) => {
12416
- if (child === slottable) {
12417
- if (React.Children.count(newElement) > 1) return React.Children.only(null);
12418
- return React.isValidElement(newElement) ? newElement.props.children : null;
12419
- } else {
12420
- return child;
12421
- }
12422
- });
12423
- return /* @__PURE__ */ jsx(SlotClone, { ...slotProps, ref: forwardedRef, children: React.isValidElement(newElement) ? React.cloneElement(newElement, void 0, newChildren) : null });
12424
- }
12425
- return /* @__PURE__ */ jsx(SlotClone, { ...slotProps, ref: forwardedRef, children });
12426
- });
12427
- Slot2.displayName = `${ownerName}.Slot`;
12428
- return Slot2;
12429
- }
12430
- // @__NO_SIDE_EFFECTS__
12431
- function createSlotClone$2(ownerName) {
12432
- const SlotClone = React.forwardRef((props, forwardedRef) => {
12433
- const { children, ...slotProps } = props;
12434
- if (React.isValidElement(children)) {
12435
- const childrenRef = getElementRef$2(children);
12436
- const props2 = mergeProps$2(slotProps, children.props);
12437
- if (children.type !== React.Fragment) {
12438
- props2.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
12439
- }
12440
- return React.cloneElement(children, props2);
12441
- }
12442
- return React.Children.count(children) > 1 ? React.Children.only(null) : null;
12443
- });
12444
- SlotClone.displayName = `${ownerName}.SlotClone`;
12445
- return SlotClone;
12446
- }
12447
- var SLOTTABLE_IDENTIFIER$2 = Symbol("radix.slottable");
12448
- function isSlottable$2(child) {
12449
- return React.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER$2;
12450
- }
12451
- function mergeProps$2(slotProps, childProps) {
12452
- const overrideProps = { ...childProps };
12453
- for (const propName in childProps) {
12454
- const slotPropValue = slotProps[propName];
12455
- const childPropValue = childProps[propName];
12456
- const isHandler = /^on[A-Z]/.test(propName);
12457
- if (isHandler) {
12458
- if (slotPropValue && childPropValue) {
12459
- overrideProps[propName] = (...args) => {
12460
- const result = childPropValue(...args);
12461
- slotPropValue(...args);
12462
- return result;
12463
- };
12464
- } else if (slotPropValue) {
12465
- overrideProps[propName] = slotPropValue;
12466
- }
12467
- } else if (propName === "style") {
12468
- overrideProps[propName] = { ...slotPropValue, ...childPropValue };
12469
- } else if (propName === "className") {
12470
- overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
12471
- }
12472
- }
12473
- return { ...slotProps, ...overrideProps };
12474
- }
12475
- function getElementRef$2(element) {
12476
- var _a2, _b;
12477
- let getter = (_a2 = Object.getOwnPropertyDescriptor(element.props, "ref")) == null ? void 0 : _a2.get;
12478
- let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
12479
- if (mayWarn) {
12480
- return element.ref;
12481
- }
12482
- getter = (_b = Object.getOwnPropertyDescriptor(element, "ref")) == null ? void 0 : _b.get;
12483
- mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
12484
- if (mayWarn) {
12485
- return element.props.ref;
12486
- }
12487
- return element.props.ref || element.ref;
12488
- }
12489
12189
  var NODES$2 = [
12490
12190
  "a",
12491
12191
  "button",
@@ -12506,7 +12206,7 @@ var NODES$2 = [
12506
12206
  "ul"
12507
12207
  ];
12508
12208
  var Primitive$2 = NODES$2.reduce((primitive, node) => {
12509
- const Slot2 = /* @__PURE__ */ createSlot$2(`Primitive.${node}`);
12209
+ const Slot2 = /* @__PURE__ */ createSlot(`Primitive.${node}`);
12510
12210
  const Node4 = React.forwardRef((props, forwardedRef) => {
12511
12211
  const { asChild, ...primitiveProps } = props;
12512
12212
  const Comp = asChild ? Slot2 : node;
@@ -12595,89 +12295,6 @@ function composeContextScopes$1(...scopes) {
12595
12295
  createScope.scopeName = baseScope.scopeName;
12596
12296
  return createScope;
12597
12297
  }
12598
- // @__NO_SIDE_EFFECTS__
12599
- function createSlot$1(ownerName) {
12600
- const SlotClone = /* @__PURE__ */ createSlotClone$1(ownerName);
12601
- const Slot2 = React.forwardRef((props, forwardedRef) => {
12602
- const { children, ...slotProps } = props;
12603
- const childrenArray = React.Children.toArray(children);
12604
- const slottable = childrenArray.find(isSlottable$1);
12605
- if (slottable) {
12606
- const newElement = slottable.props.children;
12607
- const newChildren = childrenArray.map((child) => {
12608
- if (child === slottable) {
12609
- if (React.Children.count(newElement) > 1) return React.Children.only(null);
12610
- return React.isValidElement(newElement) ? newElement.props.children : null;
12611
- } else {
12612
- return child;
12613
- }
12614
- });
12615
- return /* @__PURE__ */ jsx(SlotClone, { ...slotProps, ref: forwardedRef, children: React.isValidElement(newElement) ? React.cloneElement(newElement, void 0, newChildren) : null });
12616
- }
12617
- return /* @__PURE__ */ jsx(SlotClone, { ...slotProps, ref: forwardedRef, children });
12618
- });
12619
- Slot2.displayName = `${ownerName}.Slot`;
12620
- return Slot2;
12621
- }
12622
- // @__NO_SIDE_EFFECTS__
12623
- function createSlotClone$1(ownerName) {
12624
- const SlotClone = React.forwardRef((props, forwardedRef) => {
12625
- const { children, ...slotProps } = props;
12626
- if (React.isValidElement(children)) {
12627
- const childrenRef = getElementRef$1(children);
12628
- const props2 = mergeProps$1(slotProps, children.props);
12629
- if (children.type !== React.Fragment) {
12630
- props2.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
12631
- }
12632
- return React.cloneElement(children, props2);
12633
- }
12634
- return React.Children.count(children) > 1 ? React.Children.only(null) : null;
12635
- });
12636
- SlotClone.displayName = `${ownerName}.SlotClone`;
12637
- return SlotClone;
12638
- }
12639
- var SLOTTABLE_IDENTIFIER$1 = Symbol("radix.slottable");
12640
- function isSlottable$1(child) {
12641
- return React.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER$1;
12642
- }
12643
- function mergeProps$1(slotProps, childProps) {
12644
- const overrideProps = { ...childProps };
12645
- for (const propName in childProps) {
12646
- const slotPropValue = slotProps[propName];
12647
- const childPropValue = childProps[propName];
12648
- const isHandler = /^on[A-Z]/.test(propName);
12649
- if (isHandler) {
12650
- if (slotPropValue && childPropValue) {
12651
- overrideProps[propName] = (...args) => {
12652
- const result = childPropValue(...args);
12653
- slotPropValue(...args);
12654
- return result;
12655
- };
12656
- } else if (slotPropValue) {
12657
- overrideProps[propName] = slotPropValue;
12658
- }
12659
- } else if (propName === "style") {
12660
- overrideProps[propName] = { ...slotPropValue, ...childPropValue };
12661
- } else if (propName === "className") {
12662
- overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
12663
- }
12664
- }
12665
- return { ...slotProps, ...overrideProps };
12666
- }
12667
- function getElementRef$1(element) {
12668
- var _a2, _b;
12669
- let getter = (_a2 = Object.getOwnPropertyDescriptor(element.props, "ref")) == null ? void 0 : _a2.get;
12670
- let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
12671
- if (mayWarn) {
12672
- return element.ref;
12673
- }
12674
- getter = (_b = Object.getOwnPropertyDescriptor(element, "ref")) == null ? void 0 : _b.get;
12675
- mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
12676
- if (mayWarn) {
12677
- return element.props.ref;
12678
- }
12679
- return element.props.ref || element.ref;
12680
- }
12681
12298
  var NODES$1 = [
12682
12299
  "a",
12683
12300
  "button",
@@ -12698,7 +12315,7 @@ var NODES$1 = [
12698
12315
  "ul"
12699
12316
  ];
12700
12317
  var Primitive$1 = NODES$1.reduce((primitive, node) => {
12701
- const Slot2 = /* @__PURE__ */ createSlot$1(`Primitive.${node}`);
12318
+ const Slot2 = /* @__PURE__ */ createSlot(`Primitive.${node}`);
12702
12319
  const Node4 = React.forwardRef((props, forwardedRef) => {
12703
12320
  const { asChild, ...primitiveProps } = props;
12704
12321
  const Comp = asChild ? Slot2 : node;
@@ -13040,98 +12657,6 @@ function composeContextScopes(...scopes) {
13040
12657
  createScope.scopeName = baseScope.scopeName;
13041
12658
  return createScope;
13042
12659
  }
13043
- // @__NO_SIDE_EFFECTS__
13044
- function createSlot(ownerName) {
13045
- const SlotClone = /* @__PURE__ */ createSlotClone(ownerName);
13046
- const Slot2 = React.forwardRef((props, forwardedRef) => {
13047
- const { children, ...slotProps } = props;
13048
- const childrenArray = React.Children.toArray(children);
13049
- const slottable = childrenArray.find(isSlottable);
13050
- if (slottable) {
13051
- const newElement = slottable.props.children;
13052
- const newChildren = childrenArray.map((child) => {
13053
- if (child === slottable) {
13054
- if (React.Children.count(newElement) > 1) return React.Children.only(null);
13055
- return React.isValidElement(newElement) ? newElement.props.children : null;
13056
- } else {
13057
- return child;
13058
- }
13059
- });
13060
- return /* @__PURE__ */ jsx(SlotClone, { ...slotProps, ref: forwardedRef, children: React.isValidElement(newElement) ? React.cloneElement(newElement, void 0, newChildren) : null });
13061
- }
13062
- return /* @__PURE__ */ jsx(SlotClone, { ...slotProps, ref: forwardedRef, children });
13063
- });
13064
- Slot2.displayName = `${ownerName}.Slot`;
13065
- return Slot2;
13066
- }
13067
- // @__NO_SIDE_EFFECTS__
13068
- function createSlotClone(ownerName) {
13069
- const SlotClone = React.forwardRef((props, forwardedRef) => {
13070
- const { children, ...slotProps } = props;
13071
- if (React.isValidElement(children)) {
13072
- const childrenRef = getElementRef(children);
13073
- const props2 = mergeProps(slotProps, children.props);
13074
- if (children.type !== React.Fragment) {
13075
- props2.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
13076
- }
13077
- return React.cloneElement(children, props2);
13078
- }
13079
- return React.Children.count(children) > 1 ? React.Children.only(null) : null;
13080
- });
13081
- SlotClone.displayName = `${ownerName}.SlotClone`;
13082
- return SlotClone;
13083
- }
13084
- var SLOTTABLE_IDENTIFIER = Symbol("radix.slottable");
13085
- // @__NO_SIDE_EFFECTS__
13086
- function createSlottable(ownerName) {
13087
- const Slottable2 = ({ children }) => {
13088
- return /* @__PURE__ */ jsx(Fragment$1, { children });
13089
- };
13090
- Slottable2.displayName = `${ownerName}.Slottable`;
13091
- Slottable2.__radixId = SLOTTABLE_IDENTIFIER;
13092
- return Slottable2;
13093
- }
13094
- function isSlottable(child) {
13095
- return React.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER;
13096
- }
13097
- function mergeProps(slotProps, childProps) {
13098
- const overrideProps = { ...childProps };
13099
- for (const propName in childProps) {
13100
- const slotPropValue = slotProps[propName];
13101
- const childPropValue = childProps[propName];
13102
- const isHandler = /^on[A-Z]/.test(propName);
13103
- if (isHandler) {
13104
- if (slotPropValue && childPropValue) {
13105
- overrideProps[propName] = (...args) => {
13106
- const result = childPropValue(...args);
13107
- slotPropValue(...args);
13108
- return result;
13109
- };
13110
- } else if (slotPropValue) {
13111
- overrideProps[propName] = slotPropValue;
13112
- }
13113
- } else if (propName === "style") {
13114
- overrideProps[propName] = { ...slotPropValue, ...childPropValue };
13115
- } else if (propName === "className") {
13116
- overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
13117
- }
13118
- }
13119
- return { ...slotProps, ...overrideProps };
13120
- }
13121
- function getElementRef(element) {
13122
- var _a2, _b;
13123
- let getter = (_a2 = Object.getOwnPropertyDescriptor(element.props, "ref")) == null ? void 0 : _a2.get;
13124
- let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
13125
- if (mayWarn) {
13126
- return element.ref;
13127
- }
13128
- getter = (_b = Object.getOwnPropertyDescriptor(element, "ref")) == null ? void 0 : _b.get;
13129
- mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
13130
- if (mayWarn) {
13131
- return element.props.ref;
13132
- }
13133
- return element.props.ref || element.ref;
13134
- }
13135
12660
  var NODES = [
13136
12661
  "a",
13137
12662
  "button",
@@ -13673,190 +13198,6 @@ function TooltipContent({
13673
13198
  }
13674
13199
  ) });
13675
13200
  }
13676
- const AthenaContext = createContext(null);
13677
- function useAthenaConfig() {
13678
- const ctx = useContext(AthenaContext);
13679
- if (!ctx) {
13680
- throw new Error("[AthenaSDK] useAthenaConfig must be used within <AthenaProvider>");
13681
- }
13682
- return ctx;
13683
- }
13684
- const AthenaThreadIdContext = createContext(void 0);
13685
- function useAthenaThreadId() {
13686
- return useContext(AthenaThreadIdContext);
13687
- }
13688
- function useAthenaThreadListAdapter(config2) {
13689
- const configRef = useRef(config2);
13690
- configRef.current = config2;
13691
- const auth = useMemo(
13692
- () => ({ apiKey: config2.apiKey, token: config2.token }),
13693
- [config2.apiKey, config2.token]
13694
- );
13695
- const unstable_Provider = useCallback(
13696
- function AthenaThreadProvider({ children }) {
13697
- const remoteId = useAuiState(
13698
- (s) => {
13699
- var _a2;
13700
- return (_a2 = s.threadListItem) == null ? void 0 : _a2.remoteId;
13701
- }
13702
- );
13703
- return /* @__PURE__ */ jsx(AthenaThreadIdContext.Provider, { value: remoteId, children });
13704
- },
13705
- []
13706
- );
13707
- return useMemo(() => ({
13708
- async list() {
13709
- if (!auth.token && !auth.apiKey) {
13710
- return { threads: [] };
13711
- }
13712
- try {
13713
- const { threads } = await listThreads(configRef.current.backendUrl, auth, {
13714
- ...configRef.current.appId ? { app_id: configRef.current.appId } : {}
13715
- });
13716
- return {
13717
- threads: threads.map((t) => ({
13718
- status: "regular",
13719
- remoteId: t.thread_id,
13720
- title: t.title || void 0
13721
- }))
13722
- };
13723
- } catch (err) {
13724
- console.error("[AthenaSDK] adapter.list() failed:", err);
13725
- return { threads: [] };
13726
- }
13727
- },
13728
- async initialize(_threadId) {
13729
- const remoteId = typeof crypto !== "undefined" && "randomUUID" in crypto ? crypto.randomUUID() : `thread_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`;
13730
- return { remoteId, externalId: void 0 };
13731
- },
13732
- async rename(_remoteId, _newTitle) {
13733
- },
13734
- async archive(remoteId) {
13735
- await archiveThread(configRef.current.backendUrl, auth, remoteId);
13736
- },
13737
- async unarchive(_remoteId) {
13738
- },
13739
- async delete(remoteId) {
13740
- await archiveThread(configRef.current.backendUrl, auth, remoteId);
13741
- },
13742
- async generateTitle(_remoteId, _messages) {
13743
- return new ReadableStream({ start(c) {
13744
- c.close();
13745
- } });
13746
- },
13747
- async fetch(remoteId) {
13748
- return {
13749
- status: "regular",
13750
- remoteId
13751
- };
13752
- },
13753
- unstable_Provider
13754
- }), [auth, unstable_Provider]);
13755
- }
13756
- const ThreadListRefreshContext = createContext(null);
13757
- function useRefreshThreadList() {
13758
- return useContext(ThreadListRefreshContext);
13759
- }
13760
- const LOCAL_ID_PREFIX = "__LOCALID_";
13761
- const isLocalPlaceholder = (id) => !!id && id.startsWith(LOCAL_ID_PREFIX);
13762
- function useAthenaThreadManager() {
13763
- const runtime = useAssistantRuntime({ optional: true });
13764
- const remoteId = useThread({
13765
- optional: true,
13766
- selector: (s) => {
13767
- var _a2;
13768
- const id = (_a2 = s.metadata) == null ? void 0 : _a2.remoteId;
13769
- return isLocalPlaceholder(id) ? void 0 : id;
13770
- }
13771
- });
13772
- const isThreadLoading = useThread({ optional: true, selector: (s) => s.isLoading }) ?? false;
13773
- const isListLoading = useThreadList({ optional: true, selector: (s) => s.isLoading });
13774
- const runtimeRef = useRef(runtime);
13775
- runtimeRef.current = runtime;
13776
- const switchToThread = useCallback(
13777
- (id) => runtimeRef.current.threads.switchToThread(id),
13778
- []
13779
- );
13780
- const switchToNewThread = useCallback(
13781
- () => runtimeRef.current.threads.switchToNewThread(),
13782
- []
13783
- );
13784
- const activeThreadId = remoteId ?? null;
13785
- return useMemo(() => {
13786
- if (!runtime || isListLoading == null) {
13787
- return null;
13788
- }
13789
- return {
13790
- activeThreadId,
13791
- isListLoading,
13792
- isThreadLoading,
13793
- switchToThread,
13794
- switchToNewThread
13795
- };
13796
- }, [runtime, activeThreadId, isListLoading, isThreadLoading, switchToThread, switchToNewThread]);
13797
- }
13798
- const POLL_DELAY_MS = 5e3;
13799
- const POLL_INTERVAL_MS = 1e3;
13800
- const POLL_MAX_DURATION_MS = 6e4;
13801
- function useThreadTitlePolling(refresh) {
13802
- const threadKey = useThread({
13803
- optional: true,
13804
- selector: (s) => {
13805
- var _a2, _b;
13806
- return ((_a2 = s.metadata) == null ? void 0 : _a2.remoteId) ?? ((_b = s.metadata) == null ? void 0 : _b.id) ?? s.threadId;
13807
- }
13808
- }) ?? null;
13809
- const hasMessages = useThread({
13810
- optional: true,
13811
- selector: (s) => s.messages.length > 0
13812
- }) ?? false;
13813
- const currentTitle = useThreadList({
13814
- optional: true,
13815
- selector: (s) => {
13816
- const main = s.threadItems[s.mainThreadId];
13817
- return (main == null ? void 0 : main.title) ?? "";
13818
- }
13819
- }) ?? "";
13820
- const hasTitle = currentTitle.trim().length > 0;
13821
- const polledThreadsRef = useRef(/* @__PURE__ */ new Set());
13822
- const refreshRef = useRef(refresh);
13823
- refreshRef.current = refresh;
13824
- useEffect(() => {
13825
- if (!threadKey || hasTitle || !hasMessages) {
13826
- return;
13827
- }
13828
- if (polledThreadsRef.current.has(threadKey)) {
13829
- return;
13830
- }
13831
- polledThreadsRef.current.add(threadKey);
13832
- let stopped = false;
13833
- let intervalId = null;
13834
- let maxTimeoutId = null;
13835
- const stop = () => {
13836
- stopped = true;
13837
- if (intervalId !== null) {
13838
- clearInterval(intervalId);
13839
- intervalId = null;
13840
- }
13841
- if (maxTimeoutId !== null) {
13842
- clearTimeout(maxTimeoutId);
13843
- maxTimeoutId = null;
13844
- }
13845
- };
13846
- const startTimeoutId = setTimeout(() => {
13847
- if (stopped) return;
13848
- refreshRef.current();
13849
- intervalId = setInterval(() => {
13850
- refreshRef.current();
13851
- }, POLL_INTERVAL_MS);
13852
- maxTimeoutId = setTimeout(stop, POLL_MAX_DURATION_MS - POLL_DELAY_MS);
13853
- }, POLL_DELAY_MS);
13854
- return () => {
13855
- clearTimeout(startTimeoutId);
13856
- stop();
13857
- };
13858
- }, [threadKey, hasTitle, hasMessages]);
13859
- }
13860
13201
  const createStoreImpl = (createState) => {
13861
13202
  let state;
13862
13203
  const listeners = /* @__PURE__ */ new Set();
@@ -14199,6 +13540,398 @@ const useAssetPanelStore = create()(
14199
13540
  }
14200
13541
  )
14201
13542
  );
13543
+ function getAssetInfo(assetId) {
13544
+ return { name: assetId || "Document", icon: "doc" };
13545
+ }
13546
+ function tryParseJson$2(text2) {
13547
+ try {
13548
+ const p = JSON.parse(text2);
13549
+ return typeof p === "object" && p !== null ? p : null;
13550
+ } catch {
13551
+ return null;
13552
+ }
13553
+ }
13554
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
13555
+ const normalizeResult$2 = (result) => {
13556
+ if (!result) return null;
13557
+ if (typeof result === "string") {
13558
+ const parsed = tryParseJson$2(result);
13559
+ if (isRecord(parsed)) return parsed;
13560
+ return null;
13561
+ }
13562
+ if (isRecord(result)) {
13563
+ const inner = result.result;
13564
+ if (typeof inner === "string") {
13565
+ const parsed = tryParseJson$2(inner);
13566
+ if (isRecord(parsed)) return parsed;
13567
+ } else if (isRecord(inner)) {
13568
+ return inner;
13569
+ }
13570
+ return result;
13571
+ }
13572
+ return null;
13573
+ };
13574
+ const pickAssetId = (...candidates) => {
13575
+ for (const candidate of candidates) {
13576
+ if (typeof candidate === "string" && candidate.startsWith("asset_")) {
13577
+ return candidate;
13578
+ }
13579
+ }
13580
+ return null;
13581
+ };
13582
+ const pickNumber = (...candidates) => {
13583
+ for (const candidate of candidates) {
13584
+ if (typeof candidate === "number" && Number.isFinite(candidate)) {
13585
+ return candidate;
13586
+ }
13587
+ }
13588
+ return void 0;
13589
+ };
13590
+ const autoOpen = (assetId, options = {}) => {
13591
+ const store = useAssetPanelStore.getState();
13592
+ if (!store.markAutoOpened(assetId)) return;
13593
+ const existing = store.tabs.find((tab) => tab.id === assetId);
13594
+ const keepCurrentSlide = options.preserveExistingSlide && existing;
13595
+ store.openAsset(assetId, {
13596
+ type: options.type ?? "unknown",
13597
+ ...keepCurrentSlide || options.slideNumber === void 0 ? {} : { slideNumber: options.slideNumber }
13598
+ });
13599
+ };
13600
+ const openOnResult = (type, extra) => ({
13601
+ streamCall: async (reader) => {
13602
+ const { result } = await reader.response.get();
13603
+ const data = normalizeResult$2(result);
13604
+ const assetId = pickAssetId(
13605
+ data == null ? void 0 : data.asset_id,
13606
+ data == null ? void 0 : data.assetId,
13607
+ data == null ? void 0 : data.id
13608
+ );
13609
+ if (!assetId) return;
13610
+ let slideNumber;
13611
+ if ((extra == null ? void 0 : extra.slideNumberFrom) !== "args") {
13612
+ slideNumber = pickNumber(
13613
+ data == null ? void 0 : data.slide_number,
13614
+ data == null ? void 0 : data.slideNumber,
13615
+ data == null ? void 0 : data.targetSlideNumber,
13616
+ data == null ? void 0 : data.target_slide_number
13617
+ );
13618
+ }
13619
+ if (slideNumber === void 0 && (extra == null ? void 0 : extra.slideNumberFrom) !== "result") {
13620
+ const args = await reader.args.get().catch(() => null);
13621
+ slideNumber = pickNumber(
13622
+ args == null ? void 0 : args.slide_number,
13623
+ args == null ? void 0 : args.slideNumber,
13624
+ args == null ? void 0 : args.targetSlideNumber,
13625
+ args == null ? void 0 : args.target_slide_number
13626
+ );
13627
+ }
13628
+ autoOpen(assetId, {
13629
+ type,
13630
+ slideNumber,
13631
+ preserveExistingSlide: extra == null ? void 0 : extra.preserveExistingSlide
13632
+ });
13633
+ }
13634
+ });
13635
+ const openFromArgs = (type) => ({
13636
+ streamCall: async (reader) => {
13637
+ await reader.response.get();
13638
+ const args = await reader.args.get().catch(() => null);
13639
+ const assetId = pickAssetId(args == null ? void 0 : args.asset_id, args == null ? void 0 : args.assetId);
13640
+ if (!assetId) return;
13641
+ autoOpen(assetId, { type });
13642
+ }
13643
+ });
13644
+ const DEFAULT_AUTO_OPEN_TOOLS = {
13645
+ // Top-level asset creators
13646
+ create_new_document: openOnResult("document"),
13647
+ create_document_from_markdown: openOnResult("document"),
13648
+ create_new_sheet: openOnResult("spreadsheet"),
13649
+ create_powerpoint_deck: openOnResult("presentation"),
13650
+ create_new_notebook: openOnResult("notebook"),
13651
+ // Open / read existing assets
13652
+ open_asset_in_workspace: openFromArgs("unknown"),
13653
+ // Code execution that lands on a deck/slide
13654
+ execute_presentation_code: openOnResult("presentation"),
13655
+ // Media capture
13656
+ capture_moment: openOnResult("unknown"),
13657
+ // Studio PTC sub-calls (nested SDK commands)
13658
+ CreateWorkbook: openOnResult("spreadsheet"),
13659
+ AddSheet: openOnResult("spreadsheet"),
13660
+ OpenWorkbook: openOnResult("spreadsheet"),
13661
+ CreatePresentation: openOnResult("presentation"),
13662
+ OpenPresentation: openOnResult("presentation", { preserveExistingSlide: true }),
13663
+ AddSlide: openOnResult("presentation"),
13664
+ CreateDocument: openOnResult("document"),
13665
+ CreateParagraph: openOnResult("document"),
13666
+ OpenDocument: openOnResult("document")
13667
+ };
13668
+ const AthenaContext = createContext(null);
13669
+ function useAthenaConfig() {
13670
+ const ctx = useContext(AthenaContext);
13671
+ if (!ctx) {
13672
+ throw new Error("[AthenaSDK] useAthenaConfig must be used within <AthenaProvider>");
13673
+ }
13674
+ return ctx;
13675
+ }
13676
+ const AthenaThreadIdContext = createContext(void 0);
13677
+ function selectThreadListItemRemoteId(state) {
13678
+ var _a2;
13679
+ return (_a2 = state.threadListItem) == null ? void 0 : _a2.remoteId;
13680
+ }
13681
+ function useAthenaAuiThreadRemoteId() {
13682
+ return useAuiState(selectThreadListItemRemoteId);
13683
+ }
13684
+ function useAthenaThreadId() {
13685
+ return useContext(AthenaThreadIdContext);
13686
+ }
13687
+ function useAthenaThreadListAdapter(config2) {
13688
+ const configRef = useRef(config2);
13689
+ configRef.current = config2;
13690
+ const auth = useMemo(
13691
+ () => ({ apiKey: config2.apiKey, token: config2.token }),
13692
+ [config2.apiKey, config2.token]
13693
+ );
13694
+ const unstable_Provider = useCallback(
13695
+ function AthenaThreadProvider({ children }) {
13696
+ const remoteId = useAthenaAuiThreadRemoteId();
13697
+ return /* @__PURE__ */ jsx(AthenaThreadIdContext.Provider, { value: remoteId, children });
13698
+ },
13699
+ []
13700
+ );
13701
+ return useMemo(() => ({
13702
+ async list() {
13703
+ if (!auth.token && !auth.apiKey) {
13704
+ return { threads: [] };
13705
+ }
13706
+ try {
13707
+ const { threads } = await listThreads(configRef.current.backendUrl, auth, {
13708
+ ...configRef.current.appId ? { app_id: configRef.current.appId } : {}
13709
+ });
13710
+ return {
13711
+ threads: threads.map((t) => ({
13712
+ status: "regular",
13713
+ remoteId: t.thread_id,
13714
+ title: t.title || void 0
13715
+ }))
13716
+ };
13717
+ } catch (err) {
13718
+ console.error("[AthenaSDK] adapter.list() failed:", err);
13719
+ return { threads: [] };
13720
+ }
13721
+ },
13722
+ async initialize(_threadId) {
13723
+ const remoteId = typeof crypto !== "undefined" && "randomUUID" in crypto ? crypto.randomUUID() : `thread_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`;
13724
+ return { remoteId, externalId: void 0 };
13725
+ },
13726
+ async rename(_remoteId, _newTitle) {
13727
+ },
13728
+ async archive(remoteId) {
13729
+ await archiveThread(configRef.current.backendUrl, auth, remoteId);
13730
+ },
13731
+ async unarchive(_remoteId) {
13732
+ },
13733
+ async delete(remoteId) {
13734
+ await archiveThread(configRef.current.backendUrl, auth, remoteId);
13735
+ },
13736
+ async generateTitle(_remoteId, _messages) {
13737
+ return new ReadableStream({ start(c) {
13738
+ c.close();
13739
+ } });
13740
+ },
13741
+ async fetch(remoteId) {
13742
+ return {
13743
+ status: "regular",
13744
+ remoteId
13745
+ };
13746
+ },
13747
+ unstable_Provider
13748
+ }), [auth, unstable_Provider]);
13749
+ }
13750
+ const ThreadListRefreshContext = createContext(null);
13751
+ function useRefreshThreadList() {
13752
+ return useContext(ThreadListRefreshContext);
13753
+ }
13754
+ const LOCAL_ID_PREFIX$1 = "__LOCALID_";
13755
+ const isLocalPlaceholder$1 = (id) => !!id && id.startsWith(LOCAL_ID_PREFIX$1);
13756
+ const selectHydratableThreadId = (state) => {
13757
+ var _a2;
13758
+ const remoteId = ((_a2 = state.metadata) == null ? void 0 : _a2.remoteId) ?? state.threadId;
13759
+ return isLocalPlaceholder$1(remoteId) ? null : remoteId;
13760
+ };
13761
+ const createHydrationKey = ({
13762
+ backendUrl,
13763
+ threadId,
13764
+ apiKey,
13765
+ token
13766
+ }) => {
13767
+ const authMode = token ? "bearer" : apiKey ? "api-key" : "none";
13768
+ return `${backendUrl}::${authMode}::${threadId}`;
13769
+ };
13770
+ function useActiveThreadStateHydration({
13771
+ backendUrl,
13772
+ apiKey,
13773
+ token
13774
+ }) {
13775
+ const runtime = useAssistantRuntime({ optional: true });
13776
+ const threadId = useThread({
13777
+ optional: true,
13778
+ selector: selectHydratableThreadId
13779
+ }) ?? null;
13780
+ const messageCount = useThread({
13781
+ optional: true,
13782
+ selector: (state) => state.messages.length
13783
+ }) ?? 0;
13784
+ const isRunning = useThread({
13785
+ optional: true,
13786
+ selector: (state) => state.isRunning
13787
+ }) ?? false;
13788
+ const activeThreadIdRef = useRef(threadId);
13789
+ activeThreadIdRef.current = threadId;
13790
+ const hydratedKeysRef = useRef(/* @__PURE__ */ new Set());
13791
+ useEffect(() => {
13792
+ if (!runtime || !threadId || isRunning || messageCount > 0) {
13793
+ return;
13794
+ }
13795
+ if (!token && !apiKey) {
13796
+ return;
13797
+ }
13798
+ const hydrationKey = createHydrationKey({
13799
+ backendUrl,
13800
+ threadId,
13801
+ apiKey,
13802
+ token
13803
+ });
13804
+ if (hydratedKeysRef.current.has(hydrationKey)) {
13805
+ return;
13806
+ }
13807
+ let cancelled = false;
13808
+ (async () => {
13809
+ try {
13810
+ const state = await getThreadState(backendUrl, { apiKey, token }, threadId);
13811
+ if (cancelled || activeThreadIdRef.current !== threadId) {
13812
+ return;
13813
+ }
13814
+ if (runtime.thread.getState().messages.length > 0) {
13815
+ return;
13816
+ }
13817
+ runtime.thread.importExternalState(state);
13818
+ hydratedKeysRef.current.add(hydrationKey);
13819
+ } catch (error2) {
13820
+ console.warn("[AthenaSDK] Failed to hydrate active thread state:", error2);
13821
+ }
13822
+ })();
13823
+ return () => {
13824
+ cancelled = true;
13825
+ };
13826
+ }, [apiKey, backendUrl, isRunning, messageCount, runtime, threadId, token]);
13827
+ }
13828
+ const LOCAL_ID_PREFIX = "__LOCALID_";
13829
+ const isLocalPlaceholder = (id) => !!id && id.startsWith(LOCAL_ID_PREFIX);
13830
+ const selectActiveThreadRemoteId = (state) => {
13831
+ const { mainThreadId, threadItems } = state;
13832
+ if (!mainThreadId) {
13833
+ return null;
13834
+ }
13835
+ const item = threadItems[mainThreadId];
13836
+ const remoteId = item ? item.remoteId ?? null : mainThreadId;
13837
+ return isLocalPlaceholder(remoteId) ? null : remoteId;
13838
+ };
13839
+ function useAthenaThreadManager() {
13840
+ const runtime = useAssistantRuntime({ optional: true });
13841
+ const activeThreadId = useThreadList({
13842
+ optional: true,
13843
+ selector: selectActiveThreadRemoteId
13844
+ }) ?? null;
13845
+ const isThreadLoading = useThread({ optional: true, selector: (s) => s.isLoading }) ?? false;
13846
+ const isListLoading = useThreadList({
13847
+ optional: true,
13848
+ selector: (s) => s.isLoading
13849
+ });
13850
+ const runtimeRef = useRef(runtime);
13851
+ runtimeRef.current = runtime;
13852
+ const switchToThread = useCallback(
13853
+ (id) => runtimeRef.current.threads.switchToThread(id),
13854
+ []
13855
+ );
13856
+ const switchToNewThread = useCallback(
13857
+ () => runtimeRef.current.threads.switchToNewThread(),
13858
+ []
13859
+ );
13860
+ return useMemo(() => {
13861
+ if (!runtime || isListLoading == null) {
13862
+ return null;
13863
+ }
13864
+ return {
13865
+ activeThreadId,
13866
+ isListLoading,
13867
+ isThreadLoading,
13868
+ switchToThread,
13869
+ switchToNewThread
13870
+ };
13871
+ }, [runtime, activeThreadId, isListLoading, isThreadLoading, switchToThread, switchToNewThread]);
13872
+ }
13873
+ const POLL_DELAY_MS = 5e3;
13874
+ const POLL_INTERVAL_MS = 1e3;
13875
+ const POLL_MAX_DURATION_MS = 6e4;
13876
+ function useThreadTitlePolling(refresh) {
13877
+ const threadKey = useThread({
13878
+ optional: true,
13879
+ selector: (s) => {
13880
+ var _a2, _b;
13881
+ return ((_a2 = s.metadata) == null ? void 0 : _a2.remoteId) ?? ((_b = s.metadata) == null ? void 0 : _b.id) ?? s.threadId;
13882
+ }
13883
+ }) ?? null;
13884
+ const hasMessages = useThread({
13885
+ optional: true,
13886
+ selector: (s) => s.messages.length > 0
13887
+ }) ?? false;
13888
+ const currentTitle = useThreadList({
13889
+ optional: true,
13890
+ selector: (s) => {
13891
+ const main = s.threadItems[s.mainThreadId];
13892
+ return (main == null ? void 0 : main.title) ?? "";
13893
+ }
13894
+ }) ?? "";
13895
+ const hasTitle = currentTitle.trim().length > 0;
13896
+ const polledThreadsRef = useRef(/* @__PURE__ */ new Set());
13897
+ const refreshRef = useRef(refresh);
13898
+ refreshRef.current = refresh;
13899
+ useEffect(() => {
13900
+ if (!threadKey || hasTitle || !hasMessages) {
13901
+ return;
13902
+ }
13903
+ if (polledThreadsRef.current.has(threadKey)) {
13904
+ return;
13905
+ }
13906
+ polledThreadsRef.current.add(threadKey);
13907
+ let stopped = false;
13908
+ let intervalId = null;
13909
+ let maxTimeoutId = null;
13910
+ const stop = () => {
13911
+ stopped = true;
13912
+ if (intervalId !== null) {
13913
+ clearInterval(intervalId);
13914
+ intervalId = null;
13915
+ }
13916
+ if (maxTimeoutId !== null) {
13917
+ clearTimeout(maxTimeoutId);
13918
+ maxTimeoutId = null;
13919
+ }
13920
+ };
13921
+ const startTimeoutId = setTimeout(() => {
13922
+ if (stopped) return;
13923
+ refreshRef.current();
13924
+ intervalId = setInterval(() => {
13925
+ refreshRef.current();
13926
+ }, POLL_INTERVAL_MS);
13927
+ maxTimeoutId = setTimeout(stop, POLL_MAX_DURATION_MS - POLL_DELAY_MS);
13928
+ }, POLL_DELAY_MS);
13929
+ return () => {
13930
+ clearTimeout(startTimeoutId);
13931
+ stop();
13932
+ };
13933
+ }, [threadKey, hasTitle, hasMessages]);
13934
+ }
14202
13935
  const THEME_TO_CSS = {
14203
13936
  primary: "--primary",
14204
13937
  primaryForeground: "--primary-foreground",
@@ -14517,7 +14250,7 @@ function AthenaStandalone({
14517
14250
  return /* @__PURE__ */ jsx(AssistantRuntimeProvider, { aui, runtime, children: /* @__PURE__ */ jsx(AthenaContext.Provider, { value: athenaConfig, children: /* @__PURE__ */ jsx(TooltipProvider, { children }) }) });
14518
14251
  }
14519
14252
  function useAthenaRuntimeHook(config2) {
14520
- const remoteId = useAthenaThreadId();
14253
+ const remoteId = useAthenaAuiThreadRemoteId();
14521
14254
  return useAthenaRuntime({
14522
14255
  apiUrl: config2.apiUrl,
14523
14256
  backendUrl: config2.backendUrl,
@@ -14596,7 +14329,7 @@ function AthenaWithThreadList({
14596
14329
  () => useAthenaRuntimeHook(runtimeConfigRef.current),
14597
14330
  []
14598
14331
  );
14599
- const runtime = unstable_useRemoteThreadListRuntime({
14332
+ const runtime = useRemoteThreadListRuntime({
14600
14333
  runtimeHook,
14601
14334
  adapter
14602
14335
  });
@@ -14632,11 +14365,27 @@ function AthenaWithThreadList({
14632
14365
  citationLinks
14633
14366
  });
14634
14367
  return /* @__PURE__ */ jsx(AssistantRuntimeProvider, { aui, runtime, children: /* @__PURE__ */ jsx(AthenaContext.Provider, { value: athenaConfig, children: /* @__PURE__ */ jsx(ThreadListRefreshContext.Provider, { value: handleRefresh, children: /* @__PURE__ */ jsxs(TooltipProvider, { children: [
14368
+ /* @__PURE__ */ jsx(
14369
+ ActiveThreadStateHydrator,
14370
+ {
14371
+ backendUrl,
14372
+ apiKey,
14373
+ token
14374
+ }
14375
+ ),
14635
14376
  /* @__PURE__ */ jsx(AssetPanelThreadSync, {}),
14636
14377
  /* @__PURE__ */ jsx(ThreadTitlePoller, { refresh: handleRefresh }),
14637
14378
  children
14638
14379
  ] }) }) }) });
14639
14380
  }
14381
+ function ActiveThreadStateHydrator({
14382
+ backendUrl,
14383
+ apiKey,
14384
+ token
14385
+ }) {
14386
+ useActiveThreadStateHydration({ backendUrl, apiKey, token });
14387
+ return null;
14388
+ }
14640
14389
  function AssetPanelThreadSync() {
14641
14390
  const threads = useAthenaThreadManager();
14642
14391
  const setCurrentThread = useAssetPanelStore((s) => s.setCurrentThread);
@@ -14659,6 +14408,7 @@ function AthenaProvider({
14659
14408
  model,
14660
14409
  tools = [],
14661
14410
  frontendTools = {},
14411
+ disableAutoOpen = false,
14662
14412
  apiUrl,
14663
14413
  backendUrl,
14664
14414
  appUrl,
@@ -14676,6 +14426,10 @@ function AthenaProvider({
14676
14426
  posthog: posthogProp
14677
14427
  }) {
14678
14428
  const frontendToolNames = useMemo(() => Object.keys(frontendTools), [frontendTools]);
14429
+ const effectiveFrontendTools = useMemo(
14430
+ () => disableAutoOpen ? frontendTools : { ...DEFAULT_AUTO_OPEN_TOOLS, ...frontendTools },
14431
+ [disableAutoOpen, frontendTools]
14432
+ );
14679
14433
  const themeStyleVars = useMemo(() => theme ? themeToStyleVars(theme) : void 0, [theme]);
14680
14434
  const configuredEnvironment = (config2 == null ? void 0 : config2.environment) ?? environment;
14681
14435
  const environmentUrls = useMemo(
@@ -14715,7 +14469,7 @@ function AthenaProvider({
14715
14469
  agent: agent2,
14716
14470
  tools,
14717
14471
  frontendToolIds: frontendToolNames,
14718
- frontendTools,
14472
+ frontendTools: effectiveFrontendTools,
14719
14473
  workbench,
14720
14474
  knowledgeBase,
14721
14475
  systemPrompt,
@@ -14739,7 +14493,7 @@ function AthenaProvider({
14739
14493
  agent: agent2,
14740
14494
  tools,
14741
14495
  frontendToolIds: frontendToolNames,
14742
- frontendTools,
14496
+ frontendTools: effectiveFrontendTools,
14743
14497
  workbench,
14744
14498
  knowledgeBase,
14745
14499
  systemPrompt,
@@ -45262,51 +45016,51 @@ const createLucideIcon = (iconName, iconNode) => {
45262
45016
  * This source code is licensed under the ISC license.
45263
45017
  * See the LICENSE file in the root directory of this source tree.
45264
45018
  */
45265
- const __iconNode$18 = [
45019
+ const __iconNode$19 = [
45266
45020
  ["path", { d: "M12 5v14", key: "s699le" }],
45267
45021
  ["path", { d: "m19 12-7 7-7-7", key: "1idqje" }]
45268
45022
  ];
45269
- const ArrowDown = createLucideIcon("arrow-down", __iconNode$18);
45023
+ const ArrowDown = createLucideIcon("arrow-down", __iconNode$19);
45270
45024
  /**
45271
45025
  * @license lucide-react v0.575.0 - ISC
45272
45026
  *
45273
45027
  * This source code is licensed under the ISC license.
45274
45028
  * See the LICENSE file in the root directory of this source tree.
45275
45029
  */
45276
- const __iconNode$17 = [
45030
+ const __iconNode$18 = [
45277
45031
  ["path", { d: "m12 19-7-7 7-7", key: "1l729n" }],
45278
45032
  ["path", { d: "M19 12H5", key: "x3x0zl" }]
45279
45033
  ];
45280
- const ArrowLeft = createLucideIcon("arrow-left", __iconNode$17);
45034
+ const ArrowLeft = createLucideIcon("arrow-left", __iconNode$18);
45281
45035
  /**
45282
45036
  * @license lucide-react v0.575.0 - ISC
45283
45037
  *
45284
45038
  * This source code is licensed under the ISC license.
45285
45039
  * See the LICENSE file in the root directory of this source tree.
45286
45040
  */
45287
- const __iconNode$16 = [
45041
+ const __iconNode$17 = [
45288
45042
  ["path", { d: "M5 12h14", key: "1ays0h" }],
45289
45043
  ["path", { d: "m12 5 7 7-7 7", key: "xquz4c" }]
45290
45044
  ];
45291
- const ArrowRight = createLucideIcon("arrow-right", __iconNode$16);
45045
+ const ArrowRight = createLucideIcon("arrow-right", __iconNode$17);
45292
45046
  /**
45293
45047
  * @license lucide-react v0.575.0 - ISC
45294
45048
  *
45295
45049
  * This source code is licensed under the ISC license.
45296
45050
  * See the LICENSE file in the root directory of this source tree.
45297
45051
  */
45298
- const __iconNode$15 = [
45052
+ const __iconNode$16 = [
45299
45053
  ["path", { d: "m5 12 7-7 7 7", key: "hav0vg" }],
45300
45054
  ["path", { d: "M12 19V5", key: "x0mq9r" }]
45301
45055
  ];
45302
- const ArrowUp = createLucideIcon("arrow-up", __iconNode$15);
45056
+ const ArrowUp = createLucideIcon("arrow-up", __iconNode$16);
45303
45057
  /**
45304
45058
  * @license lucide-react v0.575.0 - ISC
45305
45059
  *
45306
45060
  * This source code is licensed under the ISC license.
45307
45061
  * See the LICENSE file in the root directory of this source tree.
45308
45062
  */
45309
- const __iconNode$14 = [
45063
+ const __iconNode$15 = [
45310
45064
  ["path", { d: "M12 7v14", key: "1akyts" }],
45311
45065
  [
45312
45066
  "path",
@@ -45316,14 +45070,14 @@ const __iconNode$14 = [
45316
45070
  }
45317
45071
  ]
45318
45072
  ];
45319
- const BookOpen = createLucideIcon("book-open", __iconNode$14);
45073
+ const BookOpen = createLucideIcon("book-open", __iconNode$15);
45320
45074
  /**
45321
45075
  * @license lucide-react v0.575.0 - ISC
45322
45076
  *
45323
45077
  * This source code is licensed under the ISC license.
45324
45078
  * See the LICENSE file in the root directory of this source tree.
45325
45079
  */
45326
- const __iconNode$13 = [
45080
+ const __iconNode$14 = [
45327
45081
  [
45328
45082
  "path",
45329
45083
  {
@@ -45355,14 +45109,14 @@ const __iconNode$13 = [
45355
45109
  ["path", { d: "m12 8 4.74-2.85", key: "3rx089" }],
45356
45110
  ["path", { d: "M12 13.5V8", key: "1io7kd" }]
45357
45111
  ];
45358
- const Boxes = createLucideIcon("boxes", __iconNode$13);
45112
+ const Boxes = createLucideIcon("boxes", __iconNode$14);
45359
45113
  /**
45360
45114
  * @license lucide-react v0.575.0 - ISC
45361
45115
  *
45362
45116
  * This source code is licensed under the ISC license.
45363
45117
  * See the LICENSE file in the root directory of this source tree.
45364
45118
  */
45365
- const __iconNode$12 = [
45119
+ const __iconNode$13 = [
45366
45120
  ["path", { d: "M12 18V5", key: "adv99a" }],
45367
45121
  ["path", { d: "M15 13a4.17 4.17 0 0 1-3-4 4.17 4.17 0 0 1-3 4", key: "1e3is1" }],
45368
45122
  ["path", { d: "M17.598 6.5A3 3 0 1 0 12 5a3 3 0 1 0-5.598 1.5", key: "1gqd8o" }],
@@ -45372,27 +45126,27 @@ const __iconNode$12 = [
45372
45126
  ["path", { d: "M6 18a4 4 0 0 1-2-7.464", key: "k1g0md" }],
45373
45127
  ["path", { d: "M6.003 5.125a4 4 0 0 0-2.526 5.77", key: "q97ue3" }]
45374
45128
  ];
45375
- const Brain = createLucideIcon("brain", __iconNode$12);
45129
+ const Brain = createLucideIcon("brain", __iconNode$13);
45376
45130
  /**
45377
45131
  * @license lucide-react v0.575.0 - ISC
45378
45132
  *
45379
45133
  * This source code is licensed under the ISC license.
45380
45134
  * See the LICENSE file in the root directory of this source tree.
45381
45135
  */
45382
- const __iconNode$11 = [
45136
+ const __iconNode$12 = [
45383
45137
  ["path", { d: "M12 12h.01", key: "1mp3jc" }],
45384
45138
  ["path", { d: "M16 6V4a2 2 0 0 0-2-2h-4a2 2 0 0 0-2 2v2", key: "1ksdt3" }],
45385
45139
  ["path", { d: "M22 13a18.15 18.15 0 0 1-20 0", key: "12hx5q" }],
45386
45140
  ["rect", { width: "20", height: "14", x: "2", y: "6", rx: "2", key: "i6l2r4" }]
45387
45141
  ];
45388
- const BriefcaseBusiness = createLucideIcon("briefcase-business", __iconNode$11);
45142
+ const BriefcaseBusiness = createLucideIcon("briefcase-business", __iconNode$12);
45389
45143
  /**
45390
45144
  * @license lucide-react v0.575.0 - ISC
45391
45145
  *
45392
45146
  * This source code is licensed under the ISC license.
45393
45147
  * See the LICENSE file in the root directory of this source tree.
45394
45148
  */
45395
- const __iconNode$10 = [
45149
+ const __iconNode$11 = [
45396
45150
  [
45397
45151
  "path",
45398
45152
  { d: "M17 19a1 1 0 0 1-1-1v-2a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2v2a1 1 0 0 1-1 1z", key: "trhst0" }
@@ -45407,27 +45161,27 @@ const __iconNode$10 = [
45407
45161
  ],
45408
45162
  ["path", { d: "M7 5V3", key: "1t1388" }]
45409
45163
  ];
45410
- const Cable = createLucideIcon("cable", __iconNode$10);
45164
+ const Cable = createLucideIcon("cable", __iconNode$11);
45411
45165
  /**
45412
45166
  * @license lucide-react v0.575.0 - ISC
45413
45167
  *
45414
45168
  * This source code is licensed under the ISC license.
45415
45169
  * See the LICENSE file in the root directory of this source tree.
45416
45170
  */
45417
- const __iconNode$$ = [
45171
+ const __iconNode$10 = [
45418
45172
  ["path", { d: "M8 2v4", key: "1cmpym" }],
45419
45173
  ["path", { d: "M16 2v4", key: "4m81vk" }],
45420
45174
  ["rect", { width: "18", height: "18", x: "3", y: "4", rx: "2", key: "1hopcy" }],
45421
45175
  ["path", { d: "M3 10h18", key: "8toen8" }]
45422
45176
  ];
45423
- const Calendar = createLucideIcon("calendar", __iconNode$$);
45177
+ const Calendar = createLucideIcon("calendar", __iconNode$10);
45424
45178
  /**
45425
45179
  * @license lucide-react v0.575.0 - ISC
45426
45180
  *
45427
45181
  * This source code is licensed under the ISC license.
45428
45182
  * See the LICENSE file in the root directory of this source tree.
45429
45183
  */
45430
- const __iconNode$_ = [
45184
+ const __iconNode$$ = [
45431
45185
  [
45432
45186
  "path",
45433
45187
  {
@@ -45437,57 +45191,65 @@ const __iconNode$_ = [
45437
45191
  ],
45438
45192
  ["circle", { cx: "12", cy: "13", r: "3", key: "1vg3eu" }]
45439
45193
  ];
45440
- const Camera = createLucideIcon("camera", __iconNode$_);
45194
+ const Camera = createLucideIcon("camera", __iconNode$$);
45441
45195
  /**
45442
45196
  * @license lucide-react v0.575.0 - ISC
45443
45197
  *
45444
45198
  * This source code is licensed under the ISC license.
45445
45199
  * See the LICENSE file in the root directory of this source tree.
45446
45200
  */
45447
- const __iconNode$Z = [
45201
+ const __iconNode$_ = [
45448
45202
  ["path", { d: "M3 3v16a2 2 0 0 0 2 2h16", key: "c24i48" }],
45449
45203
  ["path", { d: "M7 16h8", key: "srdodz" }],
45450
45204
  ["path", { d: "M7 11h12", key: "127s9w" }],
45451
45205
  ["path", { d: "M7 6h3", key: "w9rmul" }]
45452
45206
  ];
45453
- const ChartBar = createLucideIcon("chart-bar", __iconNode$Z);
45207
+ const ChartBar = createLucideIcon("chart-bar", __iconNode$_);
45454
45208
  /**
45455
45209
  * @license lucide-react v0.575.0 - ISC
45456
45210
  *
45457
45211
  * This source code is licensed under the ISC license.
45458
45212
  * See the LICENSE file in the root directory of this source tree.
45459
45213
  */
45460
- const __iconNode$Y = [
45214
+ const __iconNode$Z = [
45461
45215
  ["path", { d: "M3 3v16a2 2 0 0 0 2 2h16", key: "c24i48" }],
45462
45216
  ["path", { d: "M18 17V9", key: "2bz60n" }],
45463
45217
  ["path", { d: "M13 17V5", key: "1frdt8" }],
45464
45218
  ["path", { d: "M8 17v-3", key: "17ska0" }]
45465
45219
  ];
45466
- const ChartColumn = createLucideIcon("chart-column", __iconNode$Y);
45220
+ const ChartColumn = createLucideIcon("chart-column", __iconNode$Z);
45221
+ /**
45222
+ * @license lucide-react v0.575.0 - ISC
45223
+ *
45224
+ * This source code is licensed under the ISC license.
45225
+ * See the LICENSE file in the root directory of this source tree.
45226
+ */
45227
+ const __iconNode$Y = [["path", { d: "M20 6 9 17l-5-5", key: "1gmf2c" }]];
45228
+ const Check = createLucideIcon("check", __iconNode$Y);
45467
45229
  /**
45468
45230
  * @license lucide-react v0.575.0 - ISC
45469
45231
  *
45470
45232
  * This source code is licensed under the ISC license.
45471
45233
  * See the LICENSE file in the root directory of this source tree.
45472
45234
  */
45473
- const __iconNode$X = [["path", { d: "M20 6 9 17l-5-5", key: "1gmf2c" }]];
45474
- const Check = createLucideIcon("check", __iconNode$X);
45235
+ const __iconNode$X = [["path", { d: "m6 9 6 6 6-6", key: "qrunsl" }]];
45236
+ const ChevronDown = createLucideIcon("chevron-down", __iconNode$X);
45475
45237
  /**
45476
45238
  * @license lucide-react v0.575.0 - ISC
45477
45239
  *
45478
45240
  * This source code is licensed under the ISC license.
45479
45241
  * See the LICENSE file in the root directory of this source tree.
45480
45242
  */
45481
- const __iconNode$W = [["path", { d: "m6 9 6 6 6-6", key: "qrunsl" }]];
45482
- const ChevronDown = createLucideIcon("chevron-down", __iconNode$W);
45243
+ const __iconNode$W = [["path", { d: "m9 18 6-6-6-6", key: "mthhwq" }]];
45244
+ const ChevronRight = createLucideIcon("chevron-right", __iconNode$W);
45483
45245
  /**
45484
45246
  * @license lucide-react v0.575.0 - ISC
45485
45247
  *
45486
45248
  * This source code is licensed under the ISC license.
45487
45249
  * See the LICENSE file in the root directory of this source tree.
45488
45250
  */
45489
- const __iconNode$V = [["path", { d: "m9 18 6-6-6-6", key: "mthhwq" }]];
45490
- const ChevronRight = createLucideIcon("chevron-right", __iconNode$V);
45251
+ const __iconNode$V = [["path", { d: "m18 15-6-6-6 6", key: "153udz" }]];
45252
+ const ChevronUp = createLucideIcon("chevron-up", __iconNode$V);
45491
45253
  /**
45492
45254
  * @license lucide-react v0.575.0 - ISC
45493
45255
  *
@@ -46362,7 +46124,7 @@ const DEFAULT_PILL_STYLE = "border-gray-300 bg-gray-50 text-gray-800 dark:border
46362
46124
  function MentionNodeView({ node }) {
46363
46125
  const { type, name, params } = node.attrs;
46364
46126
  const config2 = getMentionConfig(type);
46365
- const icon = isRecord(params) && typeof params.icon === "string" ? params.icon : (config2 == null ? void 0 : config2.style.icon) ?? "📎";
46127
+ const icon = isRecord$1(params) && typeof params.icon === "string" ? params.icon : (config2 == null ? void 0 : config2.style.icon) ?? "📎";
46366
46128
  const pillStyle = PILL_STYLES[type] ?? DEFAULT_PILL_STYLE;
46367
46129
  return /* @__PURE__ */ jsx(NodeViewWrapper, { as: "span", children: /* @__PURE__ */ jsxs(
46368
46130
  "span",
@@ -49628,7 +49390,7 @@ function getToolMeta(toolName) {
49628
49390
  const displayName = toolName.replace(/_/g, " ").replace(/\b\w/g, (c) => c.toUpperCase());
49629
49391
  return { displayName, icon: Wrench };
49630
49392
  }
49631
- function tryParseJson$2(text2) {
49393
+ function tryParseJson$1(text2) {
49632
49394
  try {
49633
49395
  const parsed = JSON.parse(text2);
49634
49396
  if (typeof parsed === "object" && parsed !== null) return parsed;
@@ -49638,7 +49400,7 @@ function tryParseJson$2(text2) {
49638
49400
  }
49639
49401
  function extractResultMessage(result) {
49640
49402
  if (typeof result === "string") {
49641
- const parsed = tryParseJson$2(result);
49403
+ const parsed = tryParseJson$1(result);
49642
49404
  if (parsed && typeof parsed.message === "string") return parsed.message;
49643
49405
  return null;
49644
49406
  }
@@ -49650,7 +49412,7 @@ function extractResultMessage(result) {
49650
49412
  }
49651
49413
  function isResultSuccess(result) {
49652
49414
  if (typeof result === "string") {
49653
- const parsed = tryParseJson$2(result);
49415
+ const parsed = tryParseJson$1(result);
49654
49416
  if (parsed) return parsed.success === true;
49655
49417
  }
49656
49418
  if (typeof result === "object" && result !== null) {
@@ -49672,7 +49434,7 @@ function extractAssetId$1(result) {
49672
49434
  }
49673
49435
  function extractAssetIdFromArgs(argsText) {
49674
49436
  if (!argsText) return null;
49675
- const parsed = tryParseJson$2(argsText);
49437
+ const parsed = tryParseJson$1(argsText);
49676
49438
  if (!parsed) return null;
49677
49439
  const id = parsed.asset_id ?? parsed.assetId;
49678
49440
  if (typeof id === "string" && id.startsWith("asset_")) return id;
@@ -49702,7 +49464,7 @@ function isAssetTool(toolName, result) {
49702
49464
  }
49703
49465
  function extractTitle(argsText, result) {
49704
49466
  if (argsText) {
49705
- const args = tryParseJson$2(argsText);
49467
+ const args = tryParseJson$1(argsText);
49706
49468
  if (args) {
49707
49469
  const t = args.title ?? args.name ?? args.filename ?? args.sheet_name;
49708
49470
  if (t) return t;
@@ -49783,7 +49545,7 @@ function ToolFallbackTrigger({
49783
49545
  const success = isComplete && isResultSuccess(result);
49784
49546
  const summary = useMemo(() => {
49785
49547
  if (isRunning || !meta.describer || !argsText) return null;
49786
- const parsed = tryParseJson$2(argsText);
49548
+ const parsed = tryParseJson$1(argsText);
49787
49549
  if (!parsed) return null;
49788
49550
  const desc = meta.describer(parsed);
49789
49551
  return desc || null;
@@ -49892,7 +49654,7 @@ function ToolFallbackArgs({
49892
49654
  ...props
49893
49655
  }) {
49894
49656
  if (!argsText) return null;
49895
- const parsed = tryParseJson$2(argsText);
49657
+ const parsed = tryParseJson$1(argsText);
49896
49658
  if (!parsed) {
49897
49659
  return /* @__PURE__ */ jsx("div", { className: cn("px-3", className), ...props, children: /* @__PURE__ */ jsx("pre", { className: "whitespace-pre-wrap text-xs text-muted-foreground", children: argsText }) });
49898
49660
  }
@@ -49916,7 +49678,7 @@ function ToolFallbackResult({
49916
49678
  const displayValue = useMemo(() => {
49917
49679
  if (result === void 0) return "";
49918
49680
  if (typeof result === "string") {
49919
- const parsed = tryParseJson$2(result);
49681
+ const parsed = tryParseJson$1(result);
49920
49682
  return parsed ? JSON.stringify(parsed, null, 2) : result;
49921
49683
  }
49922
49684
  return JSON.stringify(result, null, 2);
@@ -49960,12 +49722,12 @@ function CopyToolSpec({
49960
49722
  const handleCopy = useCallback(() => {
49961
49723
  const spec = { tool_name: toolName };
49962
49724
  if (argsText) {
49963
- const parsed = tryParseJson$2(argsText);
49725
+ const parsed = tryParseJson$1(argsText);
49964
49726
  spec.arguments = parsed ?? argsText;
49965
49727
  }
49966
49728
  if (result !== void 0) {
49967
49729
  if (typeof result === "string") {
49968
- const parsed = tryParseJson$2(result);
49730
+ const parsed = tryParseJson$1(result);
49969
49731
  spec.result = parsed ?? result;
49970
49732
  } else {
49971
49733
  spec.result = result;
@@ -50154,17 +49916,6 @@ ToolFallback.Content = ToolFallbackContent;
50154
49916
  ToolFallback.Args = ToolFallbackArgs;
50155
49917
  ToolFallback.Result = ToolFallbackResult;
50156
49918
  ToolFallback.Error = ToolFallbackError;
50157
- function getAssetInfo(assetId) {
50158
- return { name: assetId || "Document", icon: "doc" };
50159
- }
50160
- function tryParseJson$1(text2) {
50161
- try {
50162
- const p = JSON.parse(text2);
50163
- return typeof p === "object" && p !== null ? p : null;
50164
- } catch {
50165
- return null;
50166
- }
50167
- }
50168
49919
  const markdownPreviewExtensions = [
50169
49920
  StarterKit.configure({
50170
49921
  codeBlock: {
@@ -50213,10 +49964,10 @@ const AppendDocumentToolUIImpl = ({
50213
49964
  const typedArgs = args;
50214
49965
  const resultData = useMemo(() => {
50215
49966
  if (!result) return null;
50216
- if (typeof result === "string") return tryParseJson$1(result);
49967
+ if (typeof result === "string") return tryParseJson$2(result);
50217
49968
  if (typeof result === "object") {
50218
49969
  const obj = result;
50219
- if (typeof obj.result === "string") return tryParseJson$1(obj.result) ?? obj;
49970
+ if (typeof obj.result === "string") return tryParseJson$2(obj.result) ?? obj;
50220
49971
  return obj;
50221
49972
  }
50222
49973
  return null;
@@ -50298,11 +50049,11 @@ const AppendDocumentToolUI = memo(
50298
50049
  );
50299
50050
  AppendDocumentToolUI.displayName = "AppendDocumentToolUI";
50300
50051
  function normalizeResult$1(result) {
50301
- if (typeof result === "string") return tryParseJson$1(result) ?? result;
50052
+ if (typeof result === "string") return tryParseJson$2(result) ?? result;
50302
50053
  if (typeof result === "object" && result !== null) {
50303
50054
  const obj = result;
50304
50055
  if (typeof obj.result === "string")
50305
- return tryParseJson$1(obj.result) ?? obj.result;
50056
+ return tryParseJson$2(obj.result) ?? obj.result;
50306
50057
  return obj;
50307
50058
  }
50308
50059
  return result;
@@ -52939,6 +52690,480 @@ const TOOL_UI_REGISTRY = {
52939
52690
  run_database_sql: RunSqlToolUI,
52940
52691
  run_sql_query_tool: RunSqlToolUI
52941
52692
  };
52693
+ const TOOLKIT_THEMES = {
52694
+ Web: { color: "#7BCCFA" },
52695
+ Document: { color: "#4586F9" },
52696
+ "Document (Word)": { color: "#4586F9" },
52697
+ Notebook: { color: "#FFAB00" },
52698
+ Python: { color: "#00A76F" },
52699
+ Spreadsheet: { color: "#00A76F" },
52700
+ Email: { color: "#B584FF" },
52701
+ AOP: { color: "#336DFF" },
52702
+ App: { color: "#7336F5" },
52703
+ "Presentation (PowerPoint)": { color: "#F56B36" },
52704
+ Presentation: { color: "#F56B36" },
52705
+ "User Interface": { color: "#7336F5" },
52706
+ Canvas: { color: "#002542" },
52707
+ Computer: { color: "#3E0042" },
52708
+ Database: { color: "#7336F5" }
52709
+ };
52710
+ const DEFAULT_THEME = { color: "#919EAB" };
52711
+ const CollapsibleGroup = ({ groupKey, indices, children }) => {
52712
+ const isMessageRunning = useAuiState((s) => {
52713
+ var _a2;
52714
+ return ((_a2 = s.message.status) == null ? void 0 : _a2.type) === "running";
52715
+ });
52716
+ const [userOpened, setOpen] = useState();
52717
+ const open = userOpened ?? isMessageRunning;
52718
+ const toolCallCount = useAuiState((s) => {
52719
+ if (s.message.role !== "assistant") return 0;
52720
+ const parts = s.message.content;
52721
+ if (!parts) return 0;
52722
+ return indices.reduce((acc, idx) => {
52723
+ const part = parts[idx];
52724
+ return (part == null ? void 0 : part.type) === "tool-call" ? acc + 1 : acc;
52725
+ }, 0);
52726
+ });
52727
+ const theme = useMemo(
52728
+ () => groupKey ? TOOLKIT_THEMES[groupKey] ?? DEFAULT_THEME : DEFAULT_THEME,
52729
+ [groupKey]
52730
+ );
52731
+ if (!groupKey || indices.length <= 1) return /* @__PURE__ */ jsx(Fragment$1, { children });
52732
+ return /* @__PURE__ */ jsxs(
52733
+ "div",
52734
+ {
52735
+ className: "my-4 rounded-2xl border shadow-sm",
52736
+ style: {
52737
+ borderColor: `${theme.color}33`,
52738
+ background: `linear-gradient(to right, ${theme.color}0d, transparent, ${theme.color}0d)`
52739
+ },
52740
+ children: [
52741
+ /* @__PURE__ */ jsxs(
52742
+ "button",
52743
+ {
52744
+ type: "button",
52745
+ onClick: () => setOpen(!open),
52746
+ className: "flex w-full items-center justify-between gap-3 rounded-2xl px-5 py-3 transition-colors hover:bg-black/5 dark:hover:bg-white/5",
52747
+ "aria-expanded": open,
52748
+ children: [
52749
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 text-foreground/90", children: [
52750
+ /* @__PURE__ */ jsx(
52751
+ "span",
52752
+ {
52753
+ className: "inline-block size-2 rounded-full",
52754
+ style: { backgroundColor: theme.color },
52755
+ "aria-hidden": "true"
52756
+ }
52757
+ ),
52758
+ /* @__PURE__ */ jsxs("span", { className: "text-sm font-semibold", children: [
52759
+ isMessageRunning ? "Using " : "Used ",
52760
+ groupKey,
52761
+ " Toolkit"
52762
+ ] })
52763
+ ] }),
52764
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
52765
+ /* @__PURE__ */ jsxs("span", { className: "text-xs font-medium text-muted-foreground", children: [
52766
+ toolCallCount,
52767
+ " tool ",
52768
+ toolCallCount === 1 ? "call" : "calls"
52769
+ ] }),
52770
+ open ? /* @__PURE__ */ jsx(ChevronUp, { size: 16 }) : /* @__PURE__ */ jsx(ChevronDown, { size: 16 })
52771
+ ] })
52772
+ ]
52773
+ }
52774
+ ),
52775
+ /* @__PURE__ */ jsx(
52776
+ "div",
52777
+ {
52778
+ className: cn(
52779
+ "grid overflow-hidden border-t transition-[grid-template-rows] duration-200 ease-in-out",
52780
+ open ? "grid-rows-[1fr]" : "grid-rows-[0fr]"
52781
+ ),
52782
+ style: { borderColor: `${theme.color}33` },
52783
+ children: /* @__PURE__ */ jsx("div", { className: "overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "space-y-2 px-5 py-4", children }) })
52784
+ }
52785
+ )
52786
+ ]
52787
+ }
52788
+ );
52789
+ };
52790
+ const createToolBasedGroupingFunction = (getToolGroupKey) => (parts) => {
52791
+ const groups = [];
52792
+ let currentGroup = null;
52793
+ for (let idx = 0; idx < parts.length; idx++) {
52794
+ const part = parts[idx];
52795
+ if ((part == null ? void 0 : part.type) === "reasoning") {
52796
+ if (currentGroup) {
52797
+ currentGroup.indices.push(idx);
52798
+ } else {
52799
+ groups.push({ groupKey: void 0, indices: [idx] });
52800
+ }
52801
+ continue;
52802
+ }
52803
+ let key;
52804
+ if ((part == null ? void 0 : part.type) === "tool-call" && part.toolName) {
52805
+ key = getToolGroupKey(part.toolName);
52806
+ } else if ((part == null ? void 0 : part.type) === "text") {
52807
+ const prevKey = currentGroup == null ? void 0 : currentGroup.groupKey;
52808
+ let nextKey;
52809
+ for (let lookIdx = idx + 1; lookIdx < parts.length; lookIdx++) {
52810
+ const lookPart = parts[lookIdx];
52811
+ if ((lookPart == null ? void 0 : lookPart.type) === "reasoning" || (lookPart == null ? void 0 : lookPart.type) === "text") continue;
52812
+ if ((lookPart == null ? void 0 : lookPart.type) === "tool-call" && lookPart.toolName) {
52813
+ nextKey = getToolGroupKey(lookPart.toolName);
52814
+ }
52815
+ break;
52816
+ }
52817
+ if (prevKey && nextKey && prevKey === nextKey) {
52818
+ key = prevKey;
52819
+ }
52820
+ }
52821
+ if (currentGroup && currentGroup.groupKey === key) {
52822
+ currentGroup.indices.push(idx);
52823
+ } else {
52824
+ if (currentGroup) groups.push(currentGroup);
52825
+ currentGroup = { groupKey: key, indices: [idx] };
52826
+ }
52827
+ }
52828
+ if (currentGroup) groups.push(currentGroup);
52829
+ return groups;
52830
+ };
52831
+ const TOOL_STATUS_LABELS = {
52832
+ // Document tools
52833
+ read_asset: { running: "Reviewing asset content", complete: "Asset content reviewed" },
52834
+ read_full_asset: { running: "Reviewing asset content", complete: "Asset content reviewed" },
52835
+ create_new_document: { running: "Creating document", complete: "Created document" },
52836
+ create_document_from_markdown: { running: "Creating document", complete: "Created document" },
52837
+ append_markdown_to_athena_document: { running: "Updating document", complete: "Updated document" },
52838
+ replace_markdown_in_athena_document: { running: "Updating document", complete: "Updated document" },
52839
+ convert_athena_doc_to_pdf: { running: "Converting to PDF", complete: "Converted to PDF" },
52840
+ convert_to_pdf: { running: "Converting to PDF", complete: "Converted to PDF" },
52841
+ // Spreadsheet tools
52842
+ create_new_sheet: { running: "Creating spreadsheet", complete: "Created spreadsheet" },
52843
+ update_sheet_range: { running: "Updating spreadsheet", complete: "Updated spreadsheet" },
52844
+ format_sheet_range: { running: "Formatting spreadsheet", complete: "Formatted spreadsheet" },
52845
+ bulk_format_sheet_range: { running: "Formatting spreadsheet ranges", complete: "Formatted spreadsheet ranges" },
52846
+ create_table: { running: "Creating table", complete: "Created table" },
52847
+ update_table: { running: "Updating table", complete: "Updated table" },
52848
+ create_chart: { running: "Creating chart", complete: "Created chart" },
52849
+ update_chart: { running: "Updating chart", complete: "Updated chart" },
52850
+ // Web / search
52851
+ search: { running: "Searching the web", complete: "Web search complete" },
52852
+ browse: { running: "Reading webpage", complete: "Read webpage" },
52853
+ web_search: { running: "Searching the web", complete: "Web search complete" },
52854
+ search_web: { running: "Searching the web", complete: "Web search complete" },
52855
+ web_scrape: { running: "Reading webpage", complete: "Read webpage" },
52856
+ scrape_web: { running: "Reading webpage", complete: "Read webpage" },
52857
+ open_asset_in_workspace: { running: "Opening in workspace", complete: "Opened in workspace" },
52858
+ // Email / calendar
52859
+ create_email_draft: { running: "Drafting email", complete: "Email drafted" },
52860
+ send_email: { running: "Sending email", complete: "Email sent" },
52861
+ unified_email_create_draft: { running: "Drafting email", complete: "Email drafted" },
52862
+ unified_email_send: { running: "Sending email", complete: "Email sent" },
52863
+ unified_email_edit_draft: { running: "Editing email draft", complete: "Draft updated" },
52864
+ search_email: { running: "Searching email", complete: "Email search complete" },
52865
+ unified_email_search: { running: "Searching email", complete: "Email search complete" },
52866
+ // Python / code execution
52867
+ run_python: { running: "Running Python code", complete: "Python execution complete" },
52868
+ run_python_code: { running: "Running Python code", complete: "Python execution complete" },
52869
+ run_sql: { running: "Running database query", complete: "Query complete" },
52870
+ execute_sql: { running: "Running database query", complete: "Query complete" },
52871
+ run_database_sql: { running: "Running database query", complete: "Query complete" },
52872
+ run_sql_query_tool: { running: "Running database query", complete: "Query complete" },
52873
+ // Presentation
52874
+ create_powerpoint_deck: { running: "Creating presentation", complete: "Created presentation" },
52875
+ execute_presentation_code: { running: "Updating presentation", complete: "Updated presentation" },
52876
+ capture_slide_screenshot: { running: "Capturing slide", complete: "Slide captured" },
52877
+ // Notebook
52878
+ create_new_notebook: { running: "Creating notebook", complete: "Created notebook" },
52879
+ run_notebook_cell: { running: "Running notebook cell", complete: "Cell execution complete" },
52880
+ // Media capture
52881
+ capture_moment: { running: "Capturing moment", complete: "Moment captured" }
52882
+ };
52883
+ function getToolStatusLabel(toolName, status) {
52884
+ const entry = TOOL_STATUS_LABELS[toolName];
52885
+ if (entry) return status === "complete" ? entry.complete : entry.running;
52886
+ const formatted = formatToolName(toolName);
52887
+ return status === "complete" ? formatted : `Running ${formatted.toLowerCase()}`;
52888
+ }
52889
+ const DEFAULT_TOOL_TO_TOOLKIT = {
52890
+ // Web
52891
+ search: "Web",
52892
+ browse: "Web",
52893
+ web_search: "Web",
52894
+ search_web: "Web",
52895
+ web_scrape: "Web",
52896
+ scrape_web: "Web",
52897
+ // Document
52898
+ create_new_document: "Document",
52899
+ create_document_from_markdown: "Document",
52900
+ append_markdown_to_athena_document: "Document",
52901
+ replace_markdown_in_athena_document: "Document",
52902
+ delete_blocks_from_athena_document: "Document",
52903
+ convert_athena_doc_to_pdf: "Document",
52904
+ convert_to_pdf: "Document",
52905
+ // Word document (Studio)
52906
+ CreateDocument: "Document (Word)",
52907
+ CreateParagraph: "Document (Word)",
52908
+ OpenDocument: "Document (Word)",
52909
+ execute_word_commands: "Document (Word)",
52910
+ create_new_word_document: "Document (Word)",
52911
+ // Spreadsheet
52912
+ create_new_sheet: "Spreadsheet",
52913
+ update_sheet_range: "Spreadsheet",
52914
+ format_sheet_range: "Spreadsheet",
52915
+ bulk_format_sheet_range: "Spreadsheet",
52916
+ create_table: "Spreadsheet",
52917
+ update_table: "Spreadsheet",
52918
+ create_chart: "Spreadsheet",
52919
+ update_chart: "Spreadsheet",
52920
+ // Studio sheet PTC
52921
+ CreateWorkbook: "Spreadsheet",
52922
+ AddSheet: "Spreadsheet",
52923
+ OpenWorkbook: "Spreadsheet",
52924
+ // Presentation
52925
+ create_powerpoint_deck: "Presentation (PowerPoint)",
52926
+ execute_presentation_code: "Presentation (PowerPoint)",
52927
+ capture_slide_screenshot: "Presentation (PowerPoint)",
52928
+ // Studio presentation PTC
52929
+ CreatePresentation: "Presentation (PowerPoint)",
52930
+ OpenPresentation: "Presentation (PowerPoint)",
52931
+ AddSlide: "Presentation (PowerPoint)",
52932
+ // Notebook
52933
+ create_new_notebook: "Notebook",
52934
+ run_notebook_cell: "Notebook",
52935
+ // Python / code execution
52936
+ run_python_code: "Python",
52937
+ run_python: "Python",
52938
+ // Database
52939
+ run_sql: "Database",
52940
+ run_database_sql: "Database",
52941
+ run_sql_query_tool: "Database",
52942
+ execute_sql: "Database",
52943
+ describe_database: "Database",
52944
+ list_database_tables: "Database",
52945
+ get_database_table_schema: "Database",
52946
+ // Email / calendar
52947
+ search_email: "Email",
52948
+ unified_email_search: "Email",
52949
+ // Media
52950
+ capture_moment: "Computer"
52951
+ };
52952
+ const UNGROUPED_TOOLS = [
52953
+ "read_asset",
52954
+ "read_full_asset",
52955
+ "open_asset_in_workspace",
52956
+ "create_email_draft",
52957
+ "unified_email_create_draft",
52958
+ "unified_email_send",
52959
+ "unified_email_edit_draft"
52960
+ ];
52961
+ const defaultGetToolGroupKey = (toolName) => {
52962
+ if (UNGROUPED_TOOLS.includes(toolName)) return void 0;
52963
+ return DEFAULT_TOOL_TO_TOOLKIT[toolName];
52964
+ };
52965
+ const MAX_VISIBLE_STATUSES = 5;
52966
+ const EMPTY_STATUSES = [];
52967
+ function PulsingDots() {
52968
+ return /* @__PURE__ */ jsxs("span", { className: "inline-flex items-center gap-[3px]", "aria-hidden": "true", children: [
52969
+ /* @__PURE__ */ jsx("span", { className: "h-[5px] w-[5px] rounded-full bg-gray-800 animate-[aui-sg-pulse-dot_1.4s_ease-in-out_infinite]" }),
52970
+ /* @__PURE__ */ jsx("span", { className: "h-[5px] w-[5px] rounded-full bg-gray-800 animate-[aui-sg-pulse-dot_1.4s_ease-in-out_0.2s_infinite]" }),
52971
+ /* @__PURE__ */ jsx("span", { className: "h-[5px] w-[5px] rounded-full bg-gray-800 animate-[aui-sg-pulse-dot_1.4s_ease-in-out_0.4s_infinite]" }),
52972
+ /* @__PURE__ */ jsx("style", { children: `
52973
+ @keyframes aui-sg-pulse-dot {
52974
+ 0%, 80%, 100% { opacity: 0.2; transform: scale(0.8); }
52975
+ 40% { opacity: 1; transform: scale(1); }
52976
+ }
52977
+ @keyframes aui-sg-shimmer-bar {
52978
+ 0% { transform: translateX(-100%); }
52979
+ 100% { transform: translateX(400%); }
52980
+ }
52981
+ ` })
52982
+ ] });
52983
+ }
52984
+ const SuperGroupingFinalText = memo(function SuperGroupingFinalText2({
52985
+ TextComponent
52986
+ }) {
52987
+ const messageContent = useAuiState((s) => s.message.content);
52988
+ const isRunning = useAuiState((s) => {
52989
+ var _a2;
52990
+ return ((_a2 = s.message.status) == null ? void 0 : _a2.type) === "running";
52991
+ });
52992
+ const finalText = useMemo(() => {
52993
+ if (!(messageContent == null ? void 0 : messageContent.length)) return null;
52994
+ let lastToolIdx = -1;
52995
+ for (let i = messageContent.length - 1; i >= 0; i--) {
52996
+ if (messageContent[i].type === "tool-call") {
52997
+ lastToolIdx = i;
52998
+ break;
52999
+ }
53000
+ }
53001
+ if (lastToolIdx === -1) return null;
53002
+ const texts = [];
53003
+ for (let i = lastToolIdx + 1; i < messageContent.length; i++) {
53004
+ const part = messageContent[i];
53005
+ if (part.type === "text" && part.text) texts.push(part.text);
53006
+ }
53007
+ return texts.length > 0 ? texts.join("\n\n") : null;
53008
+ }, [messageContent]);
53009
+ if (isRunning || !finalText) return null;
53010
+ return /* @__PURE__ */ jsx(TextComponent, { type: "text", text: finalText, status: { type: "complete" } });
53011
+ });
53012
+ const SuperGroupingCard = memo(function SuperGroupingCard2({
53013
+ toolUIs,
53014
+ TextComponent,
53015
+ ReasoningComponent,
53016
+ getToolGroupKey = defaultGetToolGroupKey
53017
+ }) {
53018
+ const [showDetails, setShowDetails] = useState(false);
53019
+ const handleToggleDetails = useCallback(() => setShowDetails((p) => !p), []);
53020
+ const handleHideDetails = useCallback(() => setShowDetails(false), []);
53021
+ const messageStatus = useAuiState((s) => {
53022
+ var _a2;
53023
+ return (_a2 = s.message.status) == null ? void 0 : _a2.type;
53024
+ });
53025
+ const isRunning = messageStatus === "running";
53026
+ const isError = messageStatus === "incomplete";
53027
+ const isComplete = !isRunning && !isError;
53028
+ const groupingFunction = useMemo(() => {
53029
+ const inner = createToolBasedGroupingFunction(getToolGroupKey);
53030
+ return (parts) => {
53031
+ const lastToolIdx = parts.findLastIndex((p) => (p == null ? void 0 : p.type) === "tool-call");
53032
+ return inner(parts).map((g) => ({
53033
+ ...g,
53034
+ indices: g.indices.filter((i) => {
53035
+ var _a2;
53036
+ return ((_a2 = parts[i]) == null ? void 0 : _a2.type) !== "text" || i <= lastToolIdx;
53037
+ })
53038
+ })).filter((g) => g.indices.length > 0);
53039
+ };
53040
+ }, [getToolGroupKey]);
53041
+ const messageContent = useAuiState((s) => s.message.content);
53042
+ const toolStatuses = useMemo(() => {
53043
+ if (!messageContent) return EMPTY_STATUSES;
53044
+ const statuses = [];
53045
+ for (const part of messageContent) {
53046
+ if (part.type === "tool-call") {
53047
+ const isToolComplete = part.result !== void 0;
53048
+ statuses.push({
53049
+ toolName: part.toolName,
53050
+ label: getToolStatusLabel(part.toolName, isToolComplete ? "complete" : "running"),
53051
+ isComplete: isToolComplete
53052
+ });
53053
+ }
53054
+ }
53055
+ return statuses.length > 0 ? statuses : EMPTY_STATUSES;
53056
+ }, [messageContent]);
53057
+ const hasToolCalls = toolStatuses.length > 0;
53058
+ const visibleStatuses = useMemo(
53059
+ () => toolStatuses.length <= MAX_VISIBLE_STATUSES ? toolStatuses : toolStatuses.slice(-MAX_VISIBLE_STATUSES),
53060
+ [toolStatuses]
53061
+ );
53062
+ const hiddenCount = toolStatuses.length - visibleStatuses.length;
53063
+ const latestStatusLine = useMemo(() => {
53064
+ var _a2;
53065
+ if (!hasToolCalls) return "Planning approach";
53066
+ return ((_a2 = toolStatuses[toolStatuses.length - 1]) == null ? void 0 : _a2.label) ?? "Working";
53067
+ }, [toolStatuses, hasToolCalls]);
53068
+ const detailsPanel = /* @__PURE__ */ jsxs("div", { className: "space-y-2 border-t border-border/60 bg-background/80 px-4 py-4", children: [
53069
+ /* @__PURE__ */ jsx(
53070
+ MessagePrimitive.Unstable_PartsGrouped,
53071
+ {
53072
+ groupingFunction,
53073
+ components: {
53074
+ tools: { by_name: toolUIs, Fallback: ToolFallback },
53075
+ Text: TextComponent,
53076
+ ...ReasoningComponent ? { Reasoning: ReasoningComponent } : {},
53077
+ Group: CollapsibleGroup
53078
+ }
53079
+ }
53080
+ ),
53081
+ /* @__PURE__ */ jsxs(
53082
+ "button",
53083
+ {
53084
+ type: "button",
53085
+ onClick: handleHideDetails,
53086
+ className: "mx-auto mt-3 flex items-center gap-1 rounded-md px-3 py-1.5 text-[11px] font-medium text-muted-foreground transition-colors hover:bg-muted/40 hover:text-foreground",
53087
+ children: [
53088
+ /* @__PURE__ */ jsx(ChevronUp, { className: "size-3" }),
53089
+ "Hide details"
53090
+ ]
53091
+ }
53092
+ )
53093
+ ] });
53094
+ if (isComplete && hasToolCalls) {
53095
+ return /* @__PURE__ */ jsxs("section", { className: "my-3 overflow-hidden rounded-2xl border border-border/60 bg-muted/10", children: [
53096
+ /* @__PURE__ */ jsxs(
53097
+ "button",
53098
+ {
53099
+ type: "button",
53100
+ onClick: handleToggleDetails,
53101
+ "aria-expanded": showDetails,
53102
+ className: "flex w-full items-center justify-between px-4 py-3 text-left transition-colors hover:bg-muted/30",
53103
+ children: [
53104
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
53105
+ /* @__PURE__ */ jsx("span", { className: "flex size-4 items-center justify-center text-emerald-500", "aria-hidden": "true", children: /* @__PURE__ */ jsx("svg", { width: "10", height: "10", viewBox: "0 0 12 12", fill: "none", children: /* @__PURE__ */ jsx("path", { d: "M10 3L4.5 8.5L2 6", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) }) }),
53106
+ /* @__PURE__ */ jsxs("span", { className: "text-[12px] text-muted-foreground", children: [
53107
+ "Used ",
53108
+ toolStatuses.length,
53109
+ " ",
53110
+ toolStatuses.length === 1 ? "tool" : "tools"
53111
+ ] })
53112
+ ] }),
53113
+ showDetails ? /* @__PURE__ */ jsx(ChevronDown, { className: "size-3.5 text-muted-foreground/70" }) : /* @__PURE__ */ jsx(ChevronRight, { className: "size-3.5 text-muted-foreground/70" })
53114
+ ]
53115
+ }
53116
+ ),
53117
+ showDetails && detailsPanel
53118
+ ] });
53119
+ }
53120
+ if (isComplete) return null;
53121
+ return /* @__PURE__ */ jsxs(
53122
+ "section",
53123
+ {
53124
+ "aria-busy": isRunning ? "true" : "false",
53125
+ "aria-describedby": "aui-sg-status",
53126
+ className: cn(
53127
+ "my-3 overflow-hidden rounded-2xl border transition-colors duration-200",
53128
+ isError ? "border-destructive/30 bg-destructive/5" : "border-border/70 bg-muted/10"
53129
+ ),
53130
+ children: [
53131
+ /* @__PURE__ */ jsx("div", { className: "px-4 pt-4 pb-2", children: /* @__PURE__ */ jsx("div", { className: "flex items-center justify-between", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
53132
+ /* @__PURE__ */ jsx("h3", { className: "text-[13px] font-semibold text-foreground", children: isError ? "Something went wrong" : "Athena is working" }),
53133
+ isRunning && !isError && /* @__PURE__ */ jsx(PulsingDots, {})
53134
+ ] }) }) }),
53135
+ isRunning && /* @__PURE__ */ jsx("div", { className: "px-4 pb-1", children: /* @__PURE__ */ jsx("div", { className: "h-[2px] w-full overflow-hidden rounded-full bg-muted/40", children: /* @__PURE__ */ jsx("div", { className: "h-full w-1/3 rounded-full bg-gradient-to-r from-blue-400 to-indigo-400 animate-[aui-sg-shimmer-bar_1.5s_ease-in-out_infinite]" }) }) }),
53136
+ /* @__PURE__ */ jsx("output", { id: "aui-sg-status", "aria-live": "polite", "aria-atomic": "true", className: "sr-only", children: latestStatusLine }),
53137
+ hasToolCalls && /* @__PURE__ */ jsxs("ul", { className: "space-y-1 px-4 pt-1.5 pb-1", "aria-label": "Work status updates", children: [
53138
+ hiddenCount > 0 && /* @__PURE__ */ jsxs("li", { className: "pl-[22px] text-[11px] text-muted-foreground/70", children: [
53139
+ hiddenCount,
53140
+ " earlier ",
53141
+ hiddenCount === 1 ? "step" : "steps"
53142
+ ] }),
53143
+ visibleStatuses.map((s, i) => /* @__PURE__ */ jsxs("li", { className: "flex items-center gap-2 text-[12px]", children: [
53144
+ s.isComplete ? /* @__PURE__ */ jsx("span", { className: "flex size-3.5 items-center justify-center text-emerald-500", "aria-hidden": "true", children: /* @__PURE__ */ jsx("svg", { width: "10", height: "10", viewBox: "0 0 12 12", fill: "none", children: /* @__PURE__ */ jsx("path", { d: "M10 3L4.5 8.5L2 6", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) }) }) : /* @__PURE__ */ jsx("span", { className: "flex size-3.5 items-center justify-center", "aria-hidden": "true", children: /* @__PURE__ */ jsx("span", { className: "size-1.5 animate-pulse rounded-full bg-blue-500" }) }),
53145
+ /* @__PURE__ */ jsx("span", { className: cn("leading-relaxed", s.isComplete ? "text-muted-foreground/70" : "text-foreground/80"), children: s.label })
53146
+ ] }, `${s.toolName}-${i}`))
53147
+ ] }),
53148
+ !hasToolCalls && /* @__PURE__ */ jsx("div", { className: "px-4 pt-1 pb-2", children: /* @__PURE__ */ jsx("span", { className: "shimmer text-[12px] text-muted-foreground", children: "Planning approach..." }) }),
53149
+ /* @__PURE__ */ jsx("div", { className: "px-4 pb-3 pt-0.5", children: /* @__PURE__ */ jsxs(
53150
+ "button",
53151
+ {
53152
+ type: "button",
53153
+ onClick: handleToggleDetails,
53154
+ "aria-expanded": showDetails,
53155
+ className: "flex items-center gap-1 text-[11px] font-medium text-muted-foreground transition-colors hover:text-foreground",
53156
+ children: [
53157
+ showDetails ? /* @__PURE__ */ jsx(ChevronDown, { className: "size-3" }) : /* @__PURE__ */ jsx(ChevronRight, { className: "size-3" }),
53158
+ showDetails ? "Hide details" : "Show details"
53159
+ ]
53160
+ }
53161
+ ) }),
53162
+ showDetails && detailsPanel
53163
+ ]
53164
+ }
53165
+ );
53166
+ });
52942
53167
  const falsyToString = (value) => typeof value === "boolean" ? `${value}` : value === 0 ? "0" : value;
52943
53168
  const cx = clsx;
52944
53169
  const cva = (base2, config2) => (props) => {
@@ -53544,7 +53769,7 @@ const useAthenaChatDefaultComponents = () => {
53544
53769
  return value;
53545
53770
  };
53546
53771
  const AthenaDefaultAssistantMessage = () => {
53547
- const { toolUIs, TextComponent, ReasoningComponent, EmptyComponent: EmptyComponent2, ActionBarComponent } = useAthenaChatDefaultComponents();
53772
+ const { toolUIs, TextComponent, ReasoningComponent, EmptyComponent: EmptyComponent2, ActionBarComponent, groupToolCalls } = useAthenaChatDefaultComponents();
53548
53773
  return /* @__PURE__ */ jsx(
53549
53774
  AthenaAssistantMessage,
53550
53775
  {
@@ -53552,7 +53777,8 @@ const AthenaDefaultAssistantMessage = () => {
53552
53777
  TextComponent,
53553
53778
  ReasoningComponent,
53554
53779
  EmptyComponent: EmptyComponent2,
53555
- ActionBarComponent
53780
+ ActionBarComponent,
53781
+ groupToolCalls
53556
53782
  }
53557
53783
  );
53558
53784
  };
@@ -53561,15 +53787,15 @@ const AthenaDefaultUserMessage = () => {
53561
53787
  return /* @__PURE__ */ jsx(AthenaUserMessage, { TextComponent });
53562
53788
  };
53563
53789
  const getReasoningTokensFromMetadata = (metadata) => {
53564
- if (!isRecord(metadata)) {
53790
+ if (!isRecord$1(metadata)) {
53565
53791
  return void 0;
53566
53792
  }
53567
53793
  const customMetadata = metadata.custom;
53568
- if (!isRecord(customMetadata)) {
53794
+ if (!isRecord$1(customMetadata)) {
53569
53795
  return void 0;
53570
53796
  }
53571
53797
  const athenaMetadata = customMetadata._athena;
53572
- if (!isRecord(athenaMetadata)) {
53798
+ if (!isRecord$1(athenaMetadata)) {
53573
53799
  return void 0;
53574
53800
  }
53575
53801
  const reasoningTokens = athenaMetadata.reasoningTokens;
@@ -53618,7 +53844,8 @@ const AthenaChat = ({
53618
53844
  toolUIs,
53619
53845
  mentionTools,
53620
53846
  welcomeSuggestions = DEFAULT_SUGGESTIONS,
53621
- components
53847
+ components,
53848
+ groupToolCalls = false
53622
53849
  }) => {
53623
53850
  var _a2, _b, _c;
53624
53851
  const athenaConfig = useAthenaConfig();
@@ -53656,9 +53883,10 @@ const AthenaChat = ({
53656
53883
  TextComponent: textComponent,
53657
53884
  ReasoningComponent: reasoningComponent,
53658
53885
  EmptyComponent: emptyComponent,
53659
- ActionBarComponent: actionBarComponent
53886
+ ActionBarComponent: actionBarComponent,
53887
+ groupToolCalls
53660
53888
  }),
53661
- [actionBarComponent, emptyComponent, mergedToolUIs, reasoningComponent, textComponent]
53889
+ [actionBarComponent, emptyComponent, groupToolCalls, mergedToolUIs, reasoningComponent, textComponent]
53662
53890
  );
53663
53891
  const AssistantMessageComponent = (components == null ? void 0 : components.AssistantMessage) ?? AthenaDefaultAssistantMessage;
53664
53892
  const UserMessageComponent = (components == null ? void 0 : components.UserMessage) ?? AthenaDefaultUserMessage;
@@ -53862,6 +54090,17 @@ const AthenaAssistantMessageEmpty = ({ status }) => {
53862
54090
  if ((status == null ? void 0 : status.type) !== "running") return null;
53863
54091
  return /* @__PURE__ */ jsx("span", { className: "shimmer text-[13px] text-muted-foreground", children: "Thinking..." });
53864
54092
  };
54093
+ const AthenaMessageEmptyIndicator = ({
54094
+ EmptyComponent: EmptyComponent2
54095
+ }) => {
54096
+ const hasParts = useAuiState((s) => s.message.parts.length > 0);
54097
+ const isRunning = useAuiState((s) => {
54098
+ var _a2;
54099
+ return ((_a2 = s.message.status) == null ? void 0 : _a2.type) === "running";
54100
+ });
54101
+ if (hasParts || !isRunning) return null;
54102
+ return /* @__PURE__ */ jsx(EmptyComponent2, { status: { type: "running" } });
54103
+ };
53865
54104
  const AthenaReasoningPart = ({
53866
54105
  text: text2,
53867
54106
  status,
@@ -53932,17 +54171,19 @@ const AthenaReasoningPart = ({
53932
54171
  ]
53933
54172
  }
53934
54173
  ) }),
53935
- /* @__PURE__ */ jsx(CollapsibleContent, { className: "pt-3", children: isRunning && !hasText ? /* @__PURE__ */ jsx("span", { className: "shimmer text-[13px] text-muted-foreground", children: "Analyzing..." }) : isRunning ? /* @__PURE__ */ jsx("div", { className: "whitespace-pre-wrap break-words text-[13px] leading-relaxed text-foreground", children: text2 }) : /* @__PURE__ */ jsx("div", { className: "aui-assistant-reasoning-body text-[13px] leading-relaxed", children: /* @__PURE__ */ jsx(EffectiveTextComponent, { ...reasoningTextProps }) }) })
54174
+ /* @__PURE__ */ jsx(CollapsibleContent, { className: "pt-3", children: isRunning && !hasText ? /* @__PURE__ */ jsx("span", { className: "shimmer text-[13px] text-muted-foreground", children: "Analyzing..." }) : /* @__PURE__ */ jsx("div", { className: "aui-assistant-reasoning-body text-[13px] leading-relaxed", children: /* @__PURE__ */ jsx(EffectiveTextComponent, { ...reasoningTextProps }) }) })
53936
54175
  ]
53937
54176
  }
53938
54177
  );
53939
54178
  };
54179
+ const noToolGrouping = () => null;
53940
54180
  const AthenaAssistantMessage = ({
53941
54181
  toolUIs,
53942
54182
  TextComponent = TiptapText,
53943
54183
  ReasoningComponent,
53944
54184
  EmptyComponent: EmptyComponent2 = AthenaAssistantMessageEmpty,
53945
- ActionBarComponent = AthenaAssistantActionBar
54185
+ ActionBarComponent = AthenaAssistantActionBar,
54186
+ groupToolCalls = false
53946
54187
  }) => {
53947
54188
  const effectiveReasoningComponent = ReasoningComponent ?? AthenaReasoningPart;
53948
54189
  const toolUIsWithNestedMessages = useMemo(() => {
@@ -53952,7 +54193,7 @@ const AthenaAssistantMessage = ({
53952
54193
  }
53953
54194
  return wrappedToolUIs;
53954
54195
  }, [toolUIs]);
53955
- const partsComponents = useMemo(
54196
+ const nestedPtcComponents = useMemo(
53956
54197
  () => ({
53957
54198
  Text: TextComponent,
53958
54199
  Reasoning: effectiveReasoningComponent,
@@ -53971,7 +54212,42 @@ const AthenaAssistantMessage = ({
53971
54212
  "data-role": "assistant",
53972
54213
  children: [
53973
54214
  /* @__PURE__ */ jsx(AthenaReasoningTextComponentContext.Provider, { value: TextComponent, children: /* @__PURE__ */ jsxs("div", { className: "aui-assistant-message-content wrap-break-word px-2 text-foreground leading-relaxed", children: [
53974
- /* @__PURE__ */ jsx(NestedPtcComponentsProvider, { components: partsComponents, children: /* @__PURE__ */ jsx(MessagePrimitive.Parts, { components: partsComponents }) }),
54215
+ /* @__PURE__ */ jsx(NestedPtcComponentsProvider, { components: nestedPtcComponents, children: groupToolCalls ? /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-2", children: [
54216
+ /* @__PURE__ */ jsx(
54217
+ SuperGroupingCard,
54218
+ {
54219
+ toolUIs: toolUIsWithNestedMessages,
54220
+ TextComponent,
54221
+ ReasoningComponent: effectiveReasoningComponent
54222
+ }
54223
+ ),
54224
+ /* @__PURE__ */ jsx(SuperGroupingFinalText, { TextComponent })
54225
+ ] }) : /* @__PURE__ */ jsxs(Fragment$1, { children: [
54226
+ /* @__PURE__ */ jsx(AthenaMessageEmptyIndicator, { EmptyComponent: EmptyComponent2 }),
54227
+ /* @__PURE__ */ jsx(MessagePrimitive.GroupedParts, { groupBy: noToolGrouping, children: ({ part }) => {
54228
+ var _a2;
54229
+ switch (part.type) {
54230
+ case "tool-call": {
54231
+ const ToolUI = toolUIsWithNestedMessages[part.toolName];
54232
+ const toolProps = part;
54233
+ return ToolUI ? /* @__PURE__ */ jsx(ToolUI, { ...toolProps }) : /* @__PURE__ */ jsx(ToolFallback, { ...toolProps });
54234
+ }
54235
+ case "reasoning": {
54236
+ const ReasoningRenderer = effectiveReasoningComponent;
54237
+ return /* @__PURE__ */ jsx(ReasoningRenderer, { ...part });
54238
+ }
54239
+ case "text": {
54240
+ const textPart = part;
54241
+ if (textPart.text === "" && ((_a2 = textPart.status) == null ? void 0 : _a2.type) === "running") {
54242
+ return /* @__PURE__ */ jsx(EmptyComponent2, { status: textPart.status });
54243
+ }
54244
+ return /* @__PURE__ */ jsx(TextComponent, { ...textPart });
54245
+ }
54246
+ default:
54247
+ return null;
54248
+ }
54249
+ } })
54250
+ ] }) }),
53975
54251
  /* @__PURE__ */ jsx(MessageError, {})
53976
54252
  ] }) }),
53977
54253
  /* @__PURE__ */ jsx("div", { className: "aui-assistant-message-footer mt-1 ml-2 flex", children: /* @__PURE__ */ jsx(ActionBarComponent, {}) })
@@ -54164,7 +54440,7 @@ function buildPresentationNavigationMessage({
54164
54440
  assetType,
54165
54441
  slideNumber
54166
54442
  }) {
54167
- if (assetType !== "presentation" || typeof slideNumber !== "number" || !Number.isInteger(slideNumber) || slideNumber < 1) {
54443
+ if (!assetId.trim() || assetType !== "presentation" || typeof slideNumber !== "number" || !Number.isInteger(slideNumber) || slideNumber < 1) {
54168
54444
  return null;
54169
54445
  }
54170
54446
  return {
@@ -54191,13 +54467,24 @@ const AssetIframe = memo(
54191
54467
  apiKey,
54192
54468
  token
54193
54469
  });
54470
+ const initialSlideRef = useRef({
54471
+ assetId: tab.id,
54472
+ slideNumber: tab.slideNumber
54473
+ });
54474
+ if (initialSlideRef.current.assetId !== tab.id) {
54475
+ initialSlideRef.current = {
54476
+ assetId: tab.id,
54477
+ slideNumber: tab.slideNumber
54478
+ };
54479
+ }
54480
+ const initialSlideNumber = initialSlideRef.current.slideNumber;
54194
54481
  const iframeSrc = useMemo(
54195
54482
  () => embedUrl ? buildAssetIframeSrc({
54196
54483
  embedUrl,
54197
54484
  assetType: tab.type,
54198
- slideNumber: tab.slideNumber
54485
+ slideNumber: initialSlideNumber
54199
54486
  }) : null,
54200
- [embedUrl, tab.slideNumber, tab.type]
54487
+ [embedUrl, initialSlideNumber, tab.type]
54201
54488
  );
54202
54489
  const navigationMessage = useMemo(
54203
54490
  () => buildPresentationNavigationMessage({
@@ -54207,11 +54494,22 @@ const AssetIframe = memo(
54207
54494
  }),
54208
54495
  [tab.id, tab.slideNumber, tab.type]
54209
54496
  );
54497
+ const navigationTargetOrigin = useMemo(() => {
54498
+ if (!iframeSrc) return null;
54499
+ try {
54500
+ return new URL(iframeSrc, window.location.href).origin;
54501
+ } catch {
54502
+ return null;
54503
+ }
54504
+ }, [iframeSrc]);
54210
54505
  const postNavigationMessage = useCallback(() => {
54211
54506
  var _a2, _b;
54212
- if (!navigationMessage) return;
54213
- (_b = (_a2 = iframeRef.current) == null ? void 0 : _a2.contentWindow) == null ? void 0 : _b.postMessage(navigationMessage, "*");
54214
- }, [navigationMessage]);
54507
+ if (!navigationMessage || !navigationTargetOrigin) return;
54508
+ (_b = (_a2 = iframeRef.current) == null ? void 0 : _a2.contentWindow) == null ? void 0 : _b.postMessage(
54509
+ navigationMessage,
54510
+ navigationTargetOrigin
54511
+ );
54512
+ }, [navigationMessage, navigationTargetOrigin]);
54215
54513
  useEffect(() => {
54216
54514
  postNavigationMessage();
54217
54515
  }, [postNavigationMessage]);
@@ -54567,6 +54865,7 @@ export {
54567
54865
  CreateSheetToolUI,
54568
54866
  DEFAULT_API_URL,
54569
54867
  DEFAULT_APP_URL,
54868
+ DEFAULT_AUTO_OPEN_TOOLS,
54570
54869
  DEFAULT_BACKEND_URL,
54571
54870
  DescribeDatabaseToolUI,
54572
54871
  EmailSearchToolUI,
@@ -54620,7 +54919,7 @@ export {
54620
54919
  themeToStyleVars,
54621
54920
  themes,
54622
54921
  truncate,
54623
- tryParseJson$1 as tryParseJson,
54922
+ tryParseJson$2 as tryParseJson,
54624
54923
  useAppendToComposer,
54625
54924
  useAssetEmbed,
54626
54925
  useAssetPanelStore,