@athenaintel/react 0.10.27 → 0.10.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -169,6 +169,10 @@ function isTrustedOrigin({
169
169
  }
170
170
  }
171
171
  const BRIDGE_TIMEOUT_MS = 2e3;
172
+ const TOKEN_REFRESH_BUFFER_MS = 5 * 60 * 1e3;
173
+ const TOKEN_REFRESH_RETRY_BASE_MS = 60 * 1e3;
174
+ const TOKEN_REFRESH_RETRY_MAX_MS = 5 * 60 * 1e3;
175
+ const DEFAULT_TOKEN_REFRESH_MS = 55 * 60 * 1e3;
172
176
  const EMPTY_TRUSTED_ORIGINS = [];
173
177
  const normalizeOrigin = (value) => {
174
178
  try {
@@ -177,6 +181,20 @@ const normalizeOrigin = (value) => {
177
181
  return null;
178
182
  }
179
183
  };
184
+ const getTokenRefreshDelay = (expiresAt, nowMs) => {
185
+ if (typeof expiresAt !== "string") {
186
+ return DEFAULT_TOKEN_REFRESH_MS;
187
+ }
188
+ const expiresAtMs = Date.parse(expiresAt);
189
+ if (!Number.isFinite(expiresAtMs)) {
190
+ return DEFAULT_TOKEN_REFRESH_MS;
191
+ }
192
+ return Math.max(TOKEN_REFRESH_RETRY_BASE_MS, expiresAtMs - nowMs - TOKEN_REFRESH_BUFFER_MS);
193
+ };
194
+ const getAuthRetryDelay = (retryAttempt) => {
195
+ const safeAttempt = Number.isFinite(retryAttempt) ? Math.max(0, Math.floor(retryAttempt)) : 0;
196
+ return Math.min(TOKEN_REFRESH_RETRY_MAX_MS, TOKEN_REFRESH_RETRY_BASE_MS * 2 ** safeAttempt);
197
+ };
180
198
  function useParentBridge({
181
199
  trustedOrigins = EMPTY_TRUSTED_ORIGINS
182
200
  } = {}) {
@@ -199,8 +217,7 @@ function useParentBridge({
199
217
  apiUrl: null,
200
218
  backendUrl: null,
201
219
  appUrl: null,
202
- // If not in an iframe, we're ready immediately (standalone mode)
203
- ready: !isInIframe
220
+ ready: false
204
221
  });
205
222
  const readySignalSent = React.useRef(false);
206
223
  const configReceived = React.useRef(false);
@@ -227,7 +244,6 @@ function useParentBridge({
227
244
  setState((prev) => ({
228
245
  ...prev,
229
246
  token: event.data.token,
230
- // If we got a token, we're ready even without config
231
247
  ready: true
232
248
  }));
233
249
  }
@@ -245,6 +261,105 @@ function useParentBridge({
245
261
  clearTimeout(timer);
246
262
  };
247
263
  }, [isInIframe, runtimeTrustedOrigins]);
264
+ React.useEffect(() => {
265
+ if (isInIframe) return;
266
+ if (typeof window === "undefined") return;
267
+ let cancelled = false;
268
+ let requestTimer = null;
269
+ let refreshTimer = null;
270
+ let controller = null;
271
+ let retryAttempt = 0;
272
+ const clearRequestTimer = () => {
273
+ if (requestTimer) {
274
+ clearTimeout(requestTimer);
275
+ requestTimer = null;
276
+ }
277
+ };
278
+ const clearRefreshTimer = () => {
279
+ if (refreshTimer) {
280
+ clearTimeout(refreshTimer);
281
+ refreshTimer = null;
282
+ }
283
+ };
284
+ const markReady = () => {
285
+ if (cancelled) return;
286
+ setState((prev) => prev.ready ? prev : { ...prev, ready: true });
287
+ };
288
+ const scheduleRefresh = (expiresAt) => {
289
+ clearRefreshTimer();
290
+ retryAttempt = 0;
291
+ const delay = getTokenRefreshDelay(expiresAt, Date.now());
292
+ refreshTimer = setTimeout(() => {
293
+ void fetchAuth({ markReadyOnFailure: false });
294
+ }, delay);
295
+ };
296
+ const scheduleRetry = () => {
297
+ clearRefreshTimer();
298
+ const delay = getAuthRetryDelay(retryAttempt);
299
+ retryAttempt += 1;
300
+ refreshTimer = setTimeout(() => {
301
+ void fetchAuth({ markReadyOnFailure: false });
302
+ }, delay);
303
+ };
304
+ const fetchAuth = async ({
305
+ markReadyOnFailure
306
+ }) => {
307
+ controller == null ? void 0 : controller.abort();
308
+ controller = new AbortController();
309
+ clearRequestTimer();
310
+ requestTimer = setTimeout(() => {
311
+ controller == null ? void 0 : controller.abort();
312
+ if (markReadyOnFailure) {
313
+ markReady();
314
+ }
315
+ }, BRIDGE_TIMEOUT_MS);
316
+ try {
317
+ const resp = await fetch("/_athena/auth", {
318
+ credentials: "include",
319
+ headers: { Accept: "application/json" },
320
+ signal: controller.signal
321
+ });
322
+ if (cancelled) return;
323
+ if (!resp.ok) {
324
+ if (resp.status === 404) {
325
+ markReady();
326
+ } else if (markReadyOnFailure) {
327
+ markReady();
328
+ scheduleRetry();
329
+ } else {
330
+ scheduleRetry();
331
+ }
332
+ return;
333
+ }
334
+ const data = await resp.json();
335
+ if (cancelled) return;
336
+ setState({
337
+ token: typeof data.token === "string" ? data.token : null,
338
+ apiUrl: typeof data.apiUrl === "string" ? data.apiUrl : null,
339
+ backendUrl: typeof data.backendUrl === "string" ? data.backendUrl : null,
340
+ appUrl: typeof data.appUrl === "string" ? data.appUrl : null,
341
+ ready: true
342
+ });
343
+ scheduleRefresh(data.expires_at);
344
+ } catch {
345
+ if (markReadyOnFailure) {
346
+ markReady();
347
+ }
348
+ if (!cancelled) {
349
+ scheduleRetry();
350
+ }
351
+ } finally {
352
+ clearRequestTimer();
353
+ }
354
+ };
355
+ void fetchAuth({ markReadyOnFailure: true });
356
+ return () => {
357
+ cancelled = true;
358
+ controller == null ? void 0 : controller.abort();
359
+ clearRequestTimer();
360
+ clearRefreshTimer();
361
+ };
362
+ }, [isInIframe]);
248
363
  return state;
249
364
  }
250
365
  function useParentAuth() {
@@ -3933,7 +4048,7 @@ const twMerge = /* @__PURE__ */ createTailwindMerge(getDefaultConfig);
3933
4048
  function cn(...inputs) {
3934
4049
  return twMerge(clsx(inputs));
3935
4050
  }
3936
- function isRecord(value) {
4051
+ function isRecord$1(value) {
3937
4052
  return typeof value === "object" && value !== null && !Array.isArray(value);
3938
4053
  }
3939
4054
  function $constructor(name, initializer2, params) {
@@ -8317,10 +8432,10 @@ const autoCloseInFlightSubgraphMessages = (msgs) => {
8317
8432
  const beginIds = /* @__PURE__ */ new Set();
8318
8433
  const endIds = /* @__PURE__ */ new Set();
8319
8434
  for (const message of msgs) {
8320
- if (!isRecord(message)) continue;
8435
+ if (!isRecord$1(message)) continue;
8321
8436
  if (message.type === "ai" && Array.isArray(message.tool_calls)) {
8322
8437
  for (const toolCall of message.tool_calls) {
8323
- if (!isRecord(toolCall)) continue;
8438
+ if (!isRecord$1(toolCall)) continue;
8324
8439
  const id = toolCall.id;
8325
8440
  if (typeof id === "string") beginIds.add(id);
8326
8441
  }
@@ -8386,7 +8501,7 @@ const contentToParts = (content) => {
8386
8501
  const getNumberAtPath = (value, path) => {
8387
8502
  let current = value;
8388
8503
  for (const segment of path) {
8389
- if (!isRecord(current)) {
8504
+ if (!isRecord$1(current)) {
8390
8505
  return void 0;
8391
8506
  }
8392
8507
  current = current[segment];
@@ -8407,7 +8522,7 @@ const buildCustomMetadata = ({
8407
8522
  }) => {
8408
8523
  const customMetadata = additionalKwargs ? { ...additionalKwargs } : {};
8409
8524
  const reasoningTokens = extractReasoningTokens({ usageMetadata, responseMetadata });
8410
- const existingAthenaMetadata = isRecord(customMetadata._athena) ? customMetadata._athena : void 0;
8525
+ const existingAthenaMetadata = isRecord$1(customMetadata._athena) ? customMetadata._athena : void 0;
8411
8526
  const athenaMetadata = {
8412
8527
  ...existingAthenaMetadata ?? {}
8413
8528
  };
@@ -8426,9 +8541,9 @@ const buildCustomMetadata = ({
8426
8541
  return Object.keys(customMetadata).length > 0 ? customMetadata : void 0;
8427
8542
  };
8428
8543
  const getSubgraphMessages = (artifact) => {
8429
- if (!isRecord(artifact)) return void 0;
8544
+ if (!isRecord$1(artifact)) return void 0;
8430
8545
  const subgraphState = artifact.subgraph_state;
8431
- if (!isRecord(subgraphState)) return void 0;
8546
+ if (!isRecord$1(subgraphState)) return void 0;
8432
8547
  const messages = subgraphState.messages;
8433
8548
  return Array.isArray(messages) && messages.length > 0 ? messages : void 0;
8434
8549
  };
@@ -9084,7 +9199,7 @@ const useAthenaRuntime = (config2) => {
9084
9199
  if (status.isRunning) {
9085
9200
  try {
9086
9201
  const lastMessageId = ((_b = runtime.thread.getState().messages.at(-1)) == null ? void 0 : _b.id) ?? null;
9087
- runtime.thread.unstable_resumeRun({ parentId: lastMessageId });
9202
+ runtime.thread.resumeRun({ parentId: lastMessageId });
9088
9203
  } catch (resumeErr) {
9089
9204
  if (IS_DEV) {
9090
9205
  console.error("[AthenaSDK] Failed to resume running thread:", resumeErr);
@@ -9137,12 +9252,12 @@ function useComposedRefs(...refs) {
9137
9252
  return React__namespace.useCallback(composeRefs(...refs), refs);
9138
9253
  }
9139
9254
  // @__NO_SIDE_EFFECTS__
9140
- function createSlot$7(ownerName) {
9141
- const SlotClone = /* @__PURE__ */ createSlotClone$7(ownerName);
9255
+ function createSlot(ownerName) {
9256
+ const SlotClone = /* @__PURE__ */ createSlotClone(ownerName);
9142
9257
  const Slot2 = React__namespace.forwardRef((props, forwardedRef) => {
9143
9258
  const { children, ...slotProps } = props;
9144
9259
  const childrenArray = React__namespace.Children.toArray(children);
9145
- const slottable = childrenArray.find(isSlottable$7);
9260
+ const slottable = childrenArray.find(isSlottable);
9146
9261
  if (slottable) {
9147
9262
  const newElement = slottable.props.children;
9148
9263
  const newChildren = childrenArray.map((child) => {
@@ -9160,13 +9275,14 @@ function createSlot$7(ownerName) {
9160
9275
  Slot2.displayName = `${ownerName}.Slot`;
9161
9276
  return Slot2;
9162
9277
  }
9278
+ var Slot = /* @__PURE__ */ createSlot("Slot");
9163
9279
  // @__NO_SIDE_EFFECTS__
9164
- function createSlotClone$7(ownerName) {
9280
+ function createSlotClone(ownerName) {
9165
9281
  const SlotClone = React__namespace.forwardRef((props, forwardedRef) => {
9166
9282
  const { children, ...slotProps } = props;
9167
9283
  if (React__namespace.isValidElement(children)) {
9168
- const childrenRef = getElementRef$8(children);
9169
- const props2 = mergeProps$7(slotProps, children.props);
9284
+ const childrenRef = getElementRef$1(children);
9285
+ const props2 = mergeProps(slotProps, children.props);
9170
9286
  if (children.type !== React__namespace.Fragment) {
9171
9287
  props2.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
9172
9288
  }
@@ -9177,11 +9293,21 @@ function createSlotClone$7(ownerName) {
9177
9293
  SlotClone.displayName = `${ownerName}.SlotClone`;
9178
9294
  return SlotClone;
9179
9295
  }
9180
- var SLOTTABLE_IDENTIFIER$7 = Symbol("radix.slottable");
9181
- function isSlottable$7(child) {
9182
- return React__namespace.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER$7;
9296
+ var SLOTTABLE_IDENTIFIER = Symbol("radix.slottable");
9297
+ // @__NO_SIDE_EFFECTS__
9298
+ function createSlottable(ownerName) {
9299
+ const Slottable2 = ({ children }) => {
9300
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
9301
+ };
9302
+ Slottable2.displayName = `${ownerName}.Slottable`;
9303
+ Slottable2.__radixId = SLOTTABLE_IDENTIFIER;
9304
+ return Slottable2;
9305
+ }
9306
+ var Slottable$1 = /* @__PURE__ */ createSlottable("Slottable");
9307
+ function isSlottable(child) {
9308
+ return React__namespace.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER;
9183
9309
  }
9184
- function mergeProps$7(slotProps, childProps) {
9310
+ function mergeProps(slotProps, childProps) {
9185
9311
  const overrideProps = { ...childProps };
9186
9312
  for (const propName in childProps) {
9187
9313
  const slotPropValue = slotProps[propName];
@@ -9205,7 +9331,7 @@ function mergeProps$7(slotProps, childProps) {
9205
9331
  }
9206
9332
  return { ...slotProps, ...overrideProps };
9207
9333
  }
9208
- function getElementRef$8(element) {
9334
+ function getElementRef$1(element) {
9209
9335
  var _a2, _b;
9210
9336
  let getter = (_a2 = Object.getOwnPropertyDescriptor(element.props, "ref")) == null ? void 0 : _a2.get;
9211
9337
  let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
@@ -9239,7 +9365,7 @@ var NODES$6 = [
9239
9365
  "ul"
9240
9366
  ];
9241
9367
  var Primitive$6 = NODES$6.reduce((primitive, node) => {
9242
- const Slot2 = /* @__PURE__ */ createSlot$7(`Primitive.${node}`);
9368
+ const Slot2 = /* @__PURE__ */ createSlot(`Primitive.${node}`);
9243
9369
  const Node4 = React__namespace.forwardRef((props, forwardedRef) => {
9244
9370
  const { asChild, ...primitiveProps } = props;
9245
9371
  const Comp = asChild ? Slot2 : node;
@@ -9414,89 +9540,6 @@ function composeContextScopes$2(...scopes) {
9414
9540
  createScope.scopeName = baseScope.scopeName;
9415
9541
  return createScope;
9416
9542
  }
9417
- // @__NO_SIDE_EFFECTS__
9418
- function createSlot$6(ownerName) {
9419
- const SlotClone = /* @__PURE__ */ createSlotClone$6(ownerName);
9420
- const Slot2 = React__namespace.forwardRef((props, forwardedRef) => {
9421
- const { children, ...slotProps } = props;
9422
- const childrenArray = React__namespace.Children.toArray(children);
9423
- const slottable = childrenArray.find(isSlottable$6);
9424
- if (slottable) {
9425
- const newElement = slottable.props.children;
9426
- const newChildren = childrenArray.map((child) => {
9427
- if (child === slottable) {
9428
- if (React__namespace.Children.count(newElement) > 1) return React__namespace.Children.only(null);
9429
- return React__namespace.isValidElement(newElement) ? newElement.props.children : null;
9430
- } else {
9431
- return child;
9432
- }
9433
- });
9434
- return /* @__PURE__ */ jsxRuntime.jsx(SlotClone, { ...slotProps, ref: forwardedRef, children: React__namespace.isValidElement(newElement) ? React__namespace.cloneElement(newElement, void 0, newChildren) : null });
9435
- }
9436
- return /* @__PURE__ */ jsxRuntime.jsx(SlotClone, { ...slotProps, ref: forwardedRef, children });
9437
- });
9438
- Slot2.displayName = `${ownerName}.Slot`;
9439
- return Slot2;
9440
- }
9441
- // @__NO_SIDE_EFFECTS__
9442
- function createSlotClone$6(ownerName) {
9443
- const SlotClone = React__namespace.forwardRef((props, forwardedRef) => {
9444
- const { children, ...slotProps } = props;
9445
- if (React__namespace.isValidElement(children)) {
9446
- const childrenRef = getElementRef$7(children);
9447
- const props2 = mergeProps$6(slotProps, children.props);
9448
- if (children.type !== React__namespace.Fragment) {
9449
- props2.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
9450
- }
9451
- return React__namespace.cloneElement(children, props2);
9452
- }
9453
- return React__namespace.Children.count(children) > 1 ? React__namespace.Children.only(null) : null;
9454
- });
9455
- SlotClone.displayName = `${ownerName}.SlotClone`;
9456
- return SlotClone;
9457
- }
9458
- var SLOTTABLE_IDENTIFIER$6 = Symbol("radix.slottable");
9459
- function isSlottable$6(child) {
9460
- return React__namespace.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER$6;
9461
- }
9462
- function mergeProps$6(slotProps, childProps) {
9463
- const overrideProps = { ...childProps };
9464
- for (const propName in childProps) {
9465
- const slotPropValue = slotProps[propName];
9466
- const childPropValue = childProps[propName];
9467
- const isHandler = /^on[A-Z]/.test(propName);
9468
- if (isHandler) {
9469
- if (slotPropValue && childPropValue) {
9470
- overrideProps[propName] = (...args) => {
9471
- const result = childPropValue(...args);
9472
- slotPropValue(...args);
9473
- return result;
9474
- };
9475
- } else if (slotPropValue) {
9476
- overrideProps[propName] = slotPropValue;
9477
- }
9478
- } else if (propName === "style") {
9479
- overrideProps[propName] = { ...slotPropValue, ...childPropValue };
9480
- } else if (propName === "className") {
9481
- overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
9482
- }
9483
- }
9484
- return { ...slotProps, ...overrideProps };
9485
- }
9486
- function getElementRef$7(element) {
9487
- var _a2, _b;
9488
- let getter = (_a2 = Object.getOwnPropertyDescriptor(element.props, "ref")) == null ? void 0 : _a2.get;
9489
- let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
9490
- if (mayWarn) {
9491
- return element.ref;
9492
- }
9493
- getter = (_b = Object.getOwnPropertyDescriptor(element, "ref")) == null ? void 0 : _b.get;
9494
- mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
9495
- if (mayWarn) {
9496
- return element.props.ref;
9497
- }
9498
- return element.props.ref || element.ref;
9499
- }
9500
9543
  var NODES$5 = [
9501
9544
  "a",
9502
9545
  "button",
@@ -9517,7 +9560,7 @@ var NODES$5 = [
9517
9560
  "ul"
9518
9561
  ];
9519
9562
  var Primitive$5 = NODES$5.reduce((primitive, node) => {
9520
- const Slot2 = /* @__PURE__ */ createSlot$6(`Primitive.${node}`);
9563
+ const Slot2 = /* @__PURE__ */ createSlot(`Primitive.${node}`);
9521
9564
  const Node4 = React__namespace.forwardRef((props, forwardedRef) => {
9522
9565
  const { asChild, ...primitiveProps } = props;
9523
9566
  const Comp = asChild ? Slot2 : node;
@@ -9539,7 +9582,7 @@ var Presence = (props) => {
9539
9582
  const { present, children } = props;
9540
9583
  const presence = usePresence(present);
9541
9584
  const child = typeof children === "function" ? children({ present: presence.isPresent }) : React__namespace.Children.only(children);
9542
- const ref = useComposedRefs(presence.ref, getElementRef$6(child));
9585
+ const ref = useComposedRefs(presence.ref, getElementRef(child));
9543
9586
  const forceMount = typeof children === "function";
9544
9587
  return forceMount || presence.isPresent ? React__namespace.cloneElement(child, { ref }) : null;
9545
9588
  };
@@ -9638,7 +9681,7 @@ function usePresence(present) {
9638
9681
  function getAnimationName(styles) {
9639
9682
  return (styles == null ? void 0 : styles.animationName) || "none";
9640
9683
  }
9641
- function getElementRef$6(element) {
9684
+ function getElementRef(element) {
9642
9685
  var _a2, _b;
9643
9686
  let getter = (_a2 = Object.getOwnPropertyDescriptor(element.props, "ref")) == null ? void 0 : _a2.get;
9644
9687
  let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
@@ -9791,89 +9834,6 @@ function getState(open) {
9791
9834
  return open ? "open" : "closed";
9792
9835
  }
9793
9836
  var Root$1 = Collapsible$1;
9794
- // @__NO_SIDE_EFFECTS__
9795
- function createSlot$5(ownerName) {
9796
- const SlotClone = /* @__PURE__ */ createSlotClone$5(ownerName);
9797
- const Slot2 = React__namespace.forwardRef((props, forwardedRef) => {
9798
- const { children, ...slotProps } = props;
9799
- const childrenArray = React__namespace.Children.toArray(children);
9800
- const slottable = childrenArray.find(isSlottable$5);
9801
- if (slottable) {
9802
- const newElement = slottable.props.children;
9803
- const newChildren = childrenArray.map((child) => {
9804
- if (child === slottable) {
9805
- if (React__namespace.Children.count(newElement) > 1) return React__namespace.Children.only(null);
9806
- return React__namespace.isValidElement(newElement) ? newElement.props.children : null;
9807
- } else {
9808
- return child;
9809
- }
9810
- });
9811
- return /* @__PURE__ */ jsxRuntime.jsx(SlotClone, { ...slotProps, ref: forwardedRef, children: React__namespace.isValidElement(newElement) ? React__namespace.cloneElement(newElement, void 0, newChildren) : null });
9812
- }
9813
- return /* @__PURE__ */ jsxRuntime.jsx(SlotClone, { ...slotProps, ref: forwardedRef, children });
9814
- });
9815
- Slot2.displayName = `${ownerName}.Slot`;
9816
- return Slot2;
9817
- }
9818
- // @__NO_SIDE_EFFECTS__
9819
- function createSlotClone$5(ownerName) {
9820
- const SlotClone = React__namespace.forwardRef((props, forwardedRef) => {
9821
- const { children, ...slotProps } = props;
9822
- if (React__namespace.isValidElement(children)) {
9823
- const childrenRef = getElementRef$5(children);
9824
- const props2 = mergeProps$5(slotProps, children.props);
9825
- if (children.type !== React__namespace.Fragment) {
9826
- props2.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
9827
- }
9828
- return React__namespace.cloneElement(children, props2);
9829
- }
9830
- return React__namespace.Children.count(children) > 1 ? React__namespace.Children.only(null) : null;
9831
- });
9832
- SlotClone.displayName = `${ownerName}.SlotClone`;
9833
- return SlotClone;
9834
- }
9835
- var SLOTTABLE_IDENTIFIER$5 = Symbol("radix.slottable");
9836
- function isSlottable$5(child) {
9837
- return React__namespace.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER$5;
9838
- }
9839
- function mergeProps$5(slotProps, childProps) {
9840
- const overrideProps = { ...childProps };
9841
- for (const propName in childProps) {
9842
- const slotPropValue = slotProps[propName];
9843
- const childPropValue = childProps[propName];
9844
- const isHandler = /^on[A-Z]/.test(propName);
9845
- if (isHandler) {
9846
- if (slotPropValue && childPropValue) {
9847
- overrideProps[propName] = (...args) => {
9848
- const result = childPropValue(...args);
9849
- slotPropValue(...args);
9850
- return result;
9851
- };
9852
- } else if (slotPropValue) {
9853
- overrideProps[propName] = slotPropValue;
9854
- }
9855
- } else if (propName === "style") {
9856
- overrideProps[propName] = { ...slotPropValue, ...childPropValue };
9857
- } else if (propName === "className") {
9858
- overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
9859
- }
9860
- }
9861
- return { ...slotProps, ...overrideProps };
9862
- }
9863
- function getElementRef$5(element) {
9864
- var _a2, _b;
9865
- let getter = (_a2 = Object.getOwnPropertyDescriptor(element.props, "ref")) == null ? void 0 : _a2.get;
9866
- let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
9867
- if (mayWarn) {
9868
- return element.ref;
9869
- }
9870
- getter = (_b = Object.getOwnPropertyDescriptor(element, "ref")) == null ? void 0 : _b.get;
9871
- mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
9872
- if (mayWarn) {
9873
- return element.props.ref;
9874
- }
9875
- return element.props.ref || element.ref;
9876
- }
9877
9837
  var NODES$4 = [
9878
9838
  "a",
9879
9839
  "button",
@@ -9894,7 +9854,7 @@ var NODES$4 = [
9894
9854
  "ul"
9895
9855
  ];
9896
9856
  var Primitive$4 = NODES$4.reduce((primitive, node) => {
9897
- const Slot2 = /* @__PURE__ */ createSlot$5(`Primitive.${node}`);
9857
+ const Slot2 = /* @__PURE__ */ createSlot(`Primitive.${node}`);
9898
9858
  const Node4 = React__namespace.forwardRef((props, forwardedRef) => {
9899
9859
  const { asChild, ...primitiveProps } = props;
9900
9860
  const Comp = asChild ? Slot2 : node;
@@ -10132,89 +10092,6 @@ function handleAndDispatchCustomEvent(name, handler, detail, { discrete }) {
10132
10092
  target.dispatchEvent(event);
10133
10093
  }
10134
10094
  }
10135
- // @__NO_SIDE_EFFECTS__
10136
- function createSlot$4(ownerName) {
10137
- const SlotClone = /* @__PURE__ */ createSlotClone$4(ownerName);
10138
- const Slot2 = React__namespace.forwardRef((props, forwardedRef) => {
10139
- const { children, ...slotProps } = props;
10140
- const childrenArray = React__namespace.Children.toArray(children);
10141
- const slottable = childrenArray.find(isSlottable$4);
10142
- if (slottable) {
10143
- const newElement = slottable.props.children;
10144
- const newChildren = childrenArray.map((child) => {
10145
- if (child === slottable) {
10146
- if (React__namespace.Children.count(newElement) > 1) return React__namespace.Children.only(null);
10147
- return React__namespace.isValidElement(newElement) ? newElement.props.children : null;
10148
- } else {
10149
- return child;
10150
- }
10151
- });
10152
- return /* @__PURE__ */ jsxRuntime.jsx(SlotClone, { ...slotProps, ref: forwardedRef, children: React__namespace.isValidElement(newElement) ? React__namespace.cloneElement(newElement, void 0, newChildren) : null });
10153
- }
10154
- return /* @__PURE__ */ jsxRuntime.jsx(SlotClone, { ...slotProps, ref: forwardedRef, children });
10155
- });
10156
- Slot2.displayName = `${ownerName}.Slot`;
10157
- return Slot2;
10158
- }
10159
- // @__NO_SIDE_EFFECTS__
10160
- function createSlotClone$4(ownerName) {
10161
- const SlotClone = React__namespace.forwardRef((props, forwardedRef) => {
10162
- const { children, ...slotProps } = props;
10163
- if (React__namespace.isValidElement(children)) {
10164
- const childrenRef = getElementRef$4(children);
10165
- const props2 = mergeProps$4(slotProps, children.props);
10166
- if (children.type !== React__namespace.Fragment) {
10167
- props2.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
10168
- }
10169
- return React__namespace.cloneElement(children, props2);
10170
- }
10171
- return React__namespace.Children.count(children) > 1 ? React__namespace.Children.only(null) : null;
10172
- });
10173
- SlotClone.displayName = `${ownerName}.SlotClone`;
10174
- return SlotClone;
10175
- }
10176
- var SLOTTABLE_IDENTIFIER$4 = Symbol("radix.slottable");
10177
- function isSlottable$4(child) {
10178
- return React__namespace.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER$4;
10179
- }
10180
- function mergeProps$4(slotProps, childProps) {
10181
- const overrideProps = { ...childProps };
10182
- for (const propName in childProps) {
10183
- const slotPropValue = slotProps[propName];
10184
- const childPropValue = childProps[propName];
10185
- const isHandler = /^on[A-Z]/.test(propName);
10186
- if (isHandler) {
10187
- if (slotPropValue && childPropValue) {
10188
- overrideProps[propName] = (...args) => {
10189
- const result = childPropValue(...args);
10190
- slotPropValue(...args);
10191
- return result;
10192
- };
10193
- } else if (slotPropValue) {
10194
- overrideProps[propName] = slotPropValue;
10195
- }
10196
- } else if (propName === "style") {
10197
- overrideProps[propName] = { ...slotPropValue, ...childPropValue };
10198
- } else if (propName === "className") {
10199
- overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
10200
- }
10201
- }
10202
- return { ...slotProps, ...overrideProps };
10203
- }
10204
- function getElementRef$4(element) {
10205
- var _a2, _b;
10206
- let getter = (_a2 = Object.getOwnPropertyDescriptor(element.props, "ref")) == null ? void 0 : _a2.get;
10207
- let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
10208
- if (mayWarn) {
10209
- return element.ref;
10210
- }
10211
- getter = (_b = Object.getOwnPropertyDescriptor(element, "ref")) == null ? void 0 : _b.get;
10212
- mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
10213
- if (mayWarn) {
10214
- return element.props.ref;
10215
- }
10216
- return element.props.ref || element.ref;
10217
- }
10218
10095
  var NODES$3 = [
10219
10096
  "a",
10220
10097
  "button",
@@ -10235,7 +10112,7 @@ var NODES$3 = [
10235
10112
  "ul"
10236
10113
  ];
10237
10114
  var Primitive$3 = NODES$3.reduce((primitive, node) => {
10238
- const Slot2 = /* @__PURE__ */ createSlot$4(`Primitive.${node}`);
10115
+ const Slot2 = /* @__PURE__ */ createSlot(`Primitive.${node}`);
10239
10116
  const Node4 = React__namespace.forwardRef((props, forwardedRef) => {
10240
10117
  const { asChild, ...primitiveProps } = props;
10241
10118
  const Comp = asChild ? Slot2 : node;
@@ -10257,100 +10134,6 @@ var Portal$1 = React__namespace.forwardRef((props, forwardedRef) => {
10257
10134
  return container ? ReactDOM.createPortal(/* @__PURE__ */ jsxRuntime.jsx(Primitive$3.div, { ...portalProps, ref: forwardedRef }), container) : null;
10258
10135
  });
10259
10136
  Portal$1.displayName = PORTAL_NAME$1;
10260
- // @__NO_SIDE_EFFECTS__
10261
- function createSlot$3(ownerName) {
10262
- const SlotClone = /* @__PURE__ */ createSlotClone$3(ownerName);
10263
- const Slot2 = React__namespace.forwardRef((props, forwardedRef) => {
10264
- const { children, ...slotProps } = props;
10265
- const childrenArray = React__namespace.Children.toArray(children);
10266
- const slottable = childrenArray.find(isSlottable$3);
10267
- if (slottable) {
10268
- const newElement = slottable.props.children;
10269
- const newChildren = childrenArray.map((child) => {
10270
- if (child === slottable) {
10271
- if (React__namespace.Children.count(newElement) > 1) return React__namespace.Children.only(null);
10272
- return React__namespace.isValidElement(newElement) ? newElement.props.children : null;
10273
- } else {
10274
- return child;
10275
- }
10276
- });
10277
- return /* @__PURE__ */ jsxRuntime.jsx(SlotClone, { ...slotProps, ref: forwardedRef, children: React__namespace.isValidElement(newElement) ? React__namespace.cloneElement(newElement, void 0, newChildren) : null });
10278
- }
10279
- return /* @__PURE__ */ jsxRuntime.jsx(SlotClone, { ...slotProps, ref: forwardedRef, children });
10280
- });
10281
- Slot2.displayName = `${ownerName}.Slot`;
10282
- return Slot2;
10283
- }
10284
- var Slot = /* @__PURE__ */ createSlot$3("Slot");
10285
- // @__NO_SIDE_EFFECTS__
10286
- function createSlotClone$3(ownerName) {
10287
- const SlotClone = React__namespace.forwardRef((props, forwardedRef) => {
10288
- const { children, ...slotProps } = props;
10289
- if (React__namespace.isValidElement(children)) {
10290
- const childrenRef = getElementRef$3(children);
10291
- const props2 = mergeProps$3(slotProps, children.props);
10292
- if (children.type !== React__namespace.Fragment) {
10293
- props2.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
10294
- }
10295
- return React__namespace.cloneElement(children, props2);
10296
- }
10297
- return React__namespace.Children.count(children) > 1 ? React__namespace.Children.only(null) : null;
10298
- });
10299
- SlotClone.displayName = `${ownerName}.SlotClone`;
10300
- return SlotClone;
10301
- }
10302
- var SLOTTABLE_IDENTIFIER$3 = Symbol("radix.slottable");
10303
- // @__NO_SIDE_EFFECTS__
10304
- function createSlottable$1(ownerName) {
10305
- const Slottable2 = ({ children }) => {
10306
- return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
10307
- };
10308
- Slottable2.displayName = `${ownerName}.Slottable`;
10309
- Slottable2.__radixId = SLOTTABLE_IDENTIFIER$3;
10310
- return Slottable2;
10311
- }
10312
- var Slottable$1 = /* @__PURE__ */ createSlottable$1("Slottable");
10313
- function isSlottable$3(child) {
10314
- return React__namespace.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER$3;
10315
- }
10316
- function mergeProps$3(slotProps, childProps) {
10317
- const overrideProps = { ...childProps };
10318
- for (const propName in childProps) {
10319
- const slotPropValue = slotProps[propName];
10320
- const childPropValue = childProps[propName];
10321
- const isHandler = /^on[A-Z]/.test(propName);
10322
- if (isHandler) {
10323
- if (slotPropValue && childPropValue) {
10324
- overrideProps[propName] = (...args) => {
10325
- const result = childPropValue(...args);
10326
- slotPropValue(...args);
10327
- return result;
10328
- };
10329
- } else if (slotPropValue) {
10330
- overrideProps[propName] = slotPropValue;
10331
- }
10332
- } else if (propName === "style") {
10333
- overrideProps[propName] = { ...slotPropValue, ...childPropValue };
10334
- } else if (propName === "className") {
10335
- overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
10336
- }
10337
- }
10338
- return { ...slotProps, ...overrideProps };
10339
- }
10340
- function getElementRef$3(element) {
10341
- var _a2, _b;
10342
- let getter = (_a2 = Object.getOwnPropertyDescriptor(element.props, "ref")) == null ? void 0 : _a2.get;
10343
- let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
10344
- if (mayWarn) {
10345
- return element.ref;
10346
- }
10347
- getter = (_b = Object.getOwnPropertyDescriptor(element, "ref")) == null ? void 0 : _b.get;
10348
- mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
10349
- if (mayWarn) {
10350
- return element.props.ref;
10351
- }
10352
- return element.props.ref || element.ref;
10353
- }
10354
10137
  var shim$1 = { exports: {} };
10355
10138
  var useSyncExternalStoreShim_production = {};
10356
10139
  /**
@@ -12443,89 +12226,6 @@ const arrow$2 = (options, deps) => {
12443
12226
  options: [options, deps]
12444
12227
  };
12445
12228
  };
12446
- // @__NO_SIDE_EFFECTS__
12447
- function createSlot$2(ownerName) {
12448
- const SlotClone = /* @__PURE__ */ createSlotClone$2(ownerName);
12449
- const Slot2 = React__namespace.forwardRef((props, forwardedRef) => {
12450
- const { children, ...slotProps } = props;
12451
- const childrenArray = React__namespace.Children.toArray(children);
12452
- const slottable = childrenArray.find(isSlottable$2);
12453
- if (slottable) {
12454
- const newElement = slottable.props.children;
12455
- const newChildren = childrenArray.map((child) => {
12456
- if (child === slottable) {
12457
- if (React__namespace.Children.count(newElement) > 1) return React__namespace.Children.only(null);
12458
- return React__namespace.isValidElement(newElement) ? newElement.props.children : null;
12459
- } else {
12460
- return child;
12461
- }
12462
- });
12463
- return /* @__PURE__ */ jsxRuntime.jsx(SlotClone, { ...slotProps, ref: forwardedRef, children: React__namespace.isValidElement(newElement) ? React__namespace.cloneElement(newElement, void 0, newChildren) : null });
12464
- }
12465
- return /* @__PURE__ */ jsxRuntime.jsx(SlotClone, { ...slotProps, ref: forwardedRef, children });
12466
- });
12467
- Slot2.displayName = `${ownerName}.Slot`;
12468
- return Slot2;
12469
- }
12470
- // @__NO_SIDE_EFFECTS__
12471
- function createSlotClone$2(ownerName) {
12472
- const SlotClone = React__namespace.forwardRef((props, forwardedRef) => {
12473
- const { children, ...slotProps } = props;
12474
- if (React__namespace.isValidElement(children)) {
12475
- const childrenRef = getElementRef$2(children);
12476
- const props2 = mergeProps$2(slotProps, children.props);
12477
- if (children.type !== React__namespace.Fragment) {
12478
- props2.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
12479
- }
12480
- return React__namespace.cloneElement(children, props2);
12481
- }
12482
- return React__namespace.Children.count(children) > 1 ? React__namespace.Children.only(null) : null;
12483
- });
12484
- SlotClone.displayName = `${ownerName}.SlotClone`;
12485
- return SlotClone;
12486
- }
12487
- var SLOTTABLE_IDENTIFIER$2 = Symbol("radix.slottable");
12488
- function isSlottable$2(child) {
12489
- return React__namespace.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER$2;
12490
- }
12491
- function mergeProps$2(slotProps, childProps) {
12492
- const overrideProps = { ...childProps };
12493
- for (const propName in childProps) {
12494
- const slotPropValue = slotProps[propName];
12495
- const childPropValue = childProps[propName];
12496
- const isHandler = /^on[A-Z]/.test(propName);
12497
- if (isHandler) {
12498
- if (slotPropValue && childPropValue) {
12499
- overrideProps[propName] = (...args) => {
12500
- const result = childPropValue(...args);
12501
- slotPropValue(...args);
12502
- return result;
12503
- };
12504
- } else if (slotPropValue) {
12505
- overrideProps[propName] = slotPropValue;
12506
- }
12507
- } else if (propName === "style") {
12508
- overrideProps[propName] = { ...slotPropValue, ...childPropValue };
12509
- } else if (propName === "className") {
12510
- overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
12511
- }
12512
- }
12513
- return { ...slotProps, ...overrideProps };
12514
- }
12515
- function getElementRef$2(element) {
12516
- var _a2, _b;
12517
- let getter = (_a2 = Object.getOwnPropertyDescriptor(element.props, "ref")) == null ? void 0 : _a2.get;
12518
- let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
12519
- if (mayWarn) {
12520
- return element.ref;
12521
- }
12522
- getter = (_b = Object.getOwnPropertyDescriptor(element, "ref")) == null ? void 0 : _b.get;
12523
- mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
12524
- if (mayWarn) {
12525
- return element.props.ref;
12526
- }
12527
- return element.props.ref || element.ref;
12528
- }
12529
12229
  var NODES$2 = [
12530
12230
  "a",
12531
12231
  "button",
@@ -12546,7 +12246,7 @@ var NODES$2 = [
12546
12246
  "ul"
12547
12247
  ];
12548
12248
  var Primitive$2 = NODES$2.reduce((primitive, node) => {
12549
- const Slot2 = /* @__PURE__ */ createSlot$2(`Primitive.${node}`);
12249
+ const Slot2 = /* @__PURE__ */ createSlot(`Primitive.${node}`);
12550
12250
  const Node4 = React__namespace.forwardRef((props, forwardedRef) => {
12551
12251
  const { asChild, ...primitiveProps } = props;
12552
12252
  const Comp = asChild ? Slot2 : node;
@@ -12635,89 +12335,6 @@ function composeContextScopes$1(...scopes) {
12635
12335
  createScope.scopeName = baseScope.scopeName;
12636
12336
  return createScope;
12637
12337
  }
12638
- // @__NO_SIDE_EFFECTS__
12639
- function createSlot$1(ownerName) {
12640
- const SlotClone = /* @__PURE__ */ createSlotClone$1(ownerName);
12641
- const Slot2 = React__namespace.forwardRef((props, forwardedRef) => {
12642
- const { children, ...slotProps } = props;
12643
- const childrenArray = React__namespace.Children.toArray(children);
12644
- const slottable = childrenArray.find(isSlottable$1);
12645
- if (slottable) {
12646
- const newElement = slottable.props.children;
12647
- const newChildren = childrenArray.map((child) => {
12648
- if (child === slottable) {
12649
- if (React__namespace.Children.count(newElement) > 1) return React__namespace.Children.only(null);
12650
- return React__namespace.isValidElement(newElement) ? newElement.props.children : null;
12651
- } else {
12652
- return child;
12653
- }
12654
- });
12655
- return /* @__PURE__ */ jsxRuntime.jsx(SlotClone, { ...slotProps, ref: forwardedRef, children: React__namespace.isValidElement(newElement) ? React__namespace.cloneElement(newElement, void 0, newChildren) : null });
12656
- }
12657
- return /* @__PURE__ */ jsxRuntime.jsx(SlotClone, { ...slotProps, ref: forwardedRef, children });
12658
- });
12659
- Slot2.displayName = `${ownerName}.Slot`;
12660
- return Slot2;
12661
- }
12662
- // @__NO_SIDE_EFFECTS__
12663
- function createSlotClone$1(ownerName) {
12664
- const SlotClone = React__namespace.forwardRef((props, forwardedRef) => {
12665
- const { children, ...slotProps } = props;
12666
- if (React__namespace.isValidElement(children)) {
12667
- const childrenRef = getElementRef$1(children);
12668
- const props2 = mergeProps$1(slotProps, children.props);
12669
- if (children.type !== React__namespace.Fragment) {
12670
- props2.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
12671
- }
12672
- return React__namespace.cloneElement(children, props2);
12673
- }
12674
- return React__namespace.Children.count(children) > 1 ? React__namespace.Children.only(null) : null;
12675
- });
12676
- SlotClone.displayName = `${ownerName}.SlotClone`;
12677
- return SlotClone;
12678
- }
12679
- var SLOTTABLE_IDENTIFIER$1 = Symbol("radix.slottable");
12680
- function isSlottable$1(child) {
12681
- return React__namespace.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER$1;
12682
- }
12683
- function mergeProps$1(slotProps, childProps) {
12684
- const overrideProps = { ...childProps };
12685
- for (const propName in childProps) {
12686
- const slotPropValue = slotProps[propName];
12687
- const childPropValue = childProps[propName];
12688
- const isHandler = /^on[A-Z]/.test(propName);
12689
- if (isHandler) {
12690
- if (slotPropValue && childPropValue) {
12691
- overrideProps[propName] = (...args) => {
12692
- const result = childPropValue(...args);
12693
- slotPropValue(...args);
12694
- return result;
12695
- };
12696
- } else if (slotPropValue) {
12697
- overrideProps[propName] = slotPropValue;
12698
- }
12699
- } else if (propName === "style") {
12700
- overrideProps[propName] = { ...slotPropValue, ...childPropValue };
12701
- } else if (propName === "className") {
12702
- overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
12703
- }
12704
- }
12705
- return { ...slotProps, ...overrideProps };
12706
- }
12707
- function getElementRef$1(element) {
12708
- var _a2, _b;
12709
- let getter = (_a2 = Object.getOwnPropertyDescriptor(element.props, "ref")) == null ? void 0 : _a2.get;
12710
- let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
12711
- if (mayWarn) {
12712
- return element.ref;
12713
- }
12714
- getter = (_b = Object.getOwnPropertyDescriptor(element, "ref")) == null ? void 0 : _b.get;
12715
- mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
12716
- if (mayWarn) {
12717
- return element.props.ref;
12718
- }
12719
- return element.props.ref || element.ref;
12720
- }
12721
12338
  var NODES$1 = [
12722
12339
  "a",
12723
12340
  "button",
@@ -12738,7 +12355,7 @@ var NODES$1 = [
12738
12355
  "ul"
12739
12356
  ];
12740
12357
  var Primitive$1 = NODES$1.reduce((primitive, node) => {
12741
- const Slot2 = /* @__PURE__ */ createSlot$1(`Primitive.${node}`);
12358
+ const Slot2 = /* @__PURE__ */ createSlot(`Primitive.${node}`);
12742
12359
  const Node4 = React__namespace.forwardRef((props, forwardedRef) => {
12743
12360
  const { asChild, ...primitiveProps } = props;
12744
12361
  const Comp = asChild ? Slot2 : node;
@@ -13080,98 +12697,6 @@ function composeContextScopes(...scopes) {
13080
12697
  createScope.scopeName = baseScope.scopeName;
13081
12698
  return createScope;
13082
12699
  }
13083
- // @__NO_SIDE_EFFECTS__
13084
- function createSlot(ownerName) {
13085
- const SlotClone = /* @__PURE__ */ createSlotClone(ownerName);
13086
- const Slot2 = React__namespace.forwardRef((props, forwardedRef) => {
13087
- const { children, ...slotProps } = props;
13088
- const childrenArray = React__namespace.Children.toArray(children);
13089
- const slottable = childrenArray.find(isSlottable);
13090
- if (slottable) {
13091
- const newElement = slottable.props.children;
13092
- const newChildren = childrenArray.map((child) => {
13093
- if (child === slottable) {
13094
- if (React__namespace.Children.count(newElement) > 1) return React__namespace.Children.only(null);
13095
- return React__namespace.isValidElement(newElement) ? newElement.props.children : null;
13096
- } else {
13097
- return child;
13098
- }
13099
- });
13100
- return /* @__PURE__ */ jsxRuntime.jsx(SlotClone, { ...slotProps, ref: forwardedRef, children: React__namespace.isValidElement(newElement) ? React__namespace.cloneElement(newElement, void 0, newChildren) : null });
13101
- }
13102
- return /* @__PURE__ */ jsxRuntime.jsx(SlotClone, { ...slotProps, ref: forwardedRef, children });
13103
- });
13104
- Slot2.displayName = `${ownerName}.Slot`;
13105
- return Slot2;
13106
- }
13107
- // @__NO_SIDE_EFFECTS__
13108
- function createSlotClone(ownerName) {
13109
- const SlotClone = React__namespace.forwardRef((props, forwardedRef) => {
13110
- const { children, ...slotProps } = props;
13111
- if (React__namespace.isValidElement(children)) {
13112
- const childrenRef = getElementRef(children);
13113
- const props2 = mergeProps(slotProps, children.props);
13114
- if (children.type !== React__namespace.Fragment) {
13115
- props2.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
13116
- }
13117
- return React__namespace.cloneElement(children, props2);
13118
- }
13119
- return React__namespace.Children.count(children) > 1 ? React__namespace.Children.only(null) : null;
13120
- });
13121
- SlotClone.displayName = `${ownerName}.SlotClone`;
13122
- return SlotClone;
13123
- }
13124
- var SLOTTABLE_IDENTIFIER = Symbol("radix.slottable");
13125
- // @__NO_SIDE_EFFECTS__
13126
- function createSlottable(ownerName) {
13127
- const Slottable2 = ({ children }) => {
13128
- return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
13129
- };
13130
- Slottable2.displayName = `${ownerName}.Slottable`;
13131
- Slottable2.__radixId = SLOTTABLE_IDENTIFIER;
13132
- return Slottable2;
13133
- }
13134
- function isSlottable(child) {
13135
- return React__namespace.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER;
13136
- }
13137
- function mergeProps(slotProps, childProps) {
13138
- const overrideProps = { ...childProps };
13139
- for (const propName in childProps) {
13140
- const slotPropValue = slotProps[propName];
13141
- const childPropValue = childProps[propName];
13142
- const isHandler = /^on[A-Z]/.test(propName);
13143
- if (isHandler) {
13144
- if (slotPropValue && childPropValue) {
13145
- overrideProps[propName] = (...args) => {
13146
- const result = childPropValue(...args);
13147
- slotPropValue(...args);
13148
- return result;
13149
- };
13150
- } else if (slotPropValue) {
13151
- overrideProps[propName] = slotPropValue;
13152
- }
13153
- } else if (propName === "style") {
13154
- overrideProps[propName] = { ...slotPropValue, ...childPropValue };
13155
- } else if (propName === "className") {
13156
- overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
13157
- }
13158
- }
13159
- return { ...slotProps, ...overrideProps };
13160
- }
13161
- function getElementRef(element) {
13162
- var _a2, _b;
13163
- let getter = (_a2 = Object.getOwnPropertyDescriptor(element.props, "ref")) == null ? void 0 : _a2.get;
13164
- let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
13165
- if (mayWarn) {
13166
- return element.ref;
13167
- }
13168
- getter = (_b = Object.getOwnPropertyDescriptor(element, "ref")) == null ? void 0 : _b.get;
13169
- mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
13170
- if (mayWarn) {
13171
- return element.props.ref;
13172
- }
13173
- return element.props.ref || element.ref;
13174
- }
13175
12700
  var NODES = [
13176
12701
  "a",
13177
12702
  "button",
@@ -13713,190 +13238,6 @@ function TooltipContent({
13713
13238
  }
13714
13239
  ) });
13715
13240
  }
13716
- const AthenaContext = React.createContext(null);
13717
- function useAthenaConfig() {
13718
- const ctx = React.useContext(AthenaContext);
13719
- if (!ctx) {
13720
- throw new Error("[AthenaSDK] useAthenaConfig must be used within <AthenaProvider>");
13721
- }
13722
- return ctx;
13723
- }
13724
- const AthenaThreadIdContext = React.createContext(void 0);
13725
- function useAthenaThreadId() {
13726
- return React.useContext(AthenaThreadIdContext);
13727
- }
13728
- function useAthenaThreadListAdapter(config2) {
13729
- const configRef = React.useRef(config2);
13730
- configRef.current = config2;
13731
- const auth = React.useMemo(
13732
- () => ({ apiKey: config2.apiKey, token: config2.token }),
13733
- [config2.apiKey, config2.token]
13734
- );
13735
- const unstable_Provider = React.useCallback(
13736
- function AthenaThreadProvider({ children }) {
13737
- const remoteId = react$1.useAuiState(
13738
- (s) => {
13739
- var _a2;
13740
- return (_a2 = s.threadListItem) == null ? void 0 : _a2.remoteId;
13741
- }
13742
- );
13743
- return /* @__PURE__ */ jsxRuntime.jsx(AthenaThreadIdContext.Provider, { value: remoteId, children });
13744
- },
13745
- []
13746
- );
13747
- return React.useMemo(() => ({
13748
- async list() {
13749
- if (!auth.token && !auth.apiKey) {
13750
- return { threads: [] };
13751
- }
13752
- try {
13753
- const { threads } = await listThreads(configRef.current.backendUrl, auth, {
13754
- ...configRef.current.appId ? { app_id: configRef.current.appId } : {}
13755
- });
13756
- return {
13757
- threads: threads.map((t) => ({
13758
- status: "regular",
13759
- remoteId: t.thread_id,
13760
- title: t.title || void 0
13761
- }))
13762
- };
13763
- } catch (err) {
13764
- console.error("[AthenaSDK] adapter.list() failed:", err);
13765
- return { threads: [] };
13766
- }
13767
- },
13768
- async initialize(_threadId) {
13769
- const remoteId = typeof crypto !== "undefined" && "randomUUID" in crypto ? crypto.randomUUID() : `thread_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`;
13770
- return { remoteId, externalId: void 0 };
13771
- },
13772
- async rename(_remoteId, _newTitle) {
13773
- },
13774
- async archive(remoteId) {
13775
- await archiveThread(configRef.current.backendUrl, auth, remoteId);
13776
- },
13777
- async unarchive(_remoteId) {
13778
- },
13779
- async delete(remoteId) {
13780
- await archiveThread(configRef.current.backendUrl, auth, remoteId);
13781
- },
13782
- async generateTitle(_remoteId, _messages) {
13783
- return new ReadableStream({ start(c) {
13784
- c.close();
13785
- } });
13786
- },
13787
- async fetch(remoteId) {
13788
- return {
13789
- status: "regular",
13790
- remoteId
13791
- };
13792
- },
13793
- unstable_Provider
13794
- }), [auth, unstable_Provider]);
13795
- }
13796
- const ThreadListRefreshContext = React.createContext(null);
13797
- function useRefreshThreadList() {
13798
- return React.useContext(ThreadListRefreshContext);
13799
- }
13800
- const LOCAL_ID_PREFIX = "__LOCALID_";
13801
- const isLocalPlaceholder = (id) => !!id && id.startsWith(LOCAL_ID_PREFIX);
13802
- function useAthenaThreadManager() {
13803
- const runtime = react$1.useAssistantRuntime({ optional: true });
13804
- const remoteId = react$1.useThread({
13805
- optional: true,
13806
- selector: (s) => {
13807
- var _a2;
13808
- const id = (_a2 = s.metadata) == null ? void 0 : _a2.remoteId;
13809
- return isLocalPlaceholder(id) ? void 0 : id;
13810
- }
13811
- });
13812
- const isThreadLoading = react$1.useThread({ optional: true, selector: (s) => s.isLoading }) ?? false;
13813
- const isListLoading = react$1.useThreadList({ optional: true, selector: (s) => s.isLoading });
13814
- const runtimeRef = React.useRef(runtime);
13815
- runtimeRef.current = runtime;
13816
- const switchToThread = React.useCallback(
13817
- (id) => runtimeRef.current.threads.switchToThread(id),
13818
- []
13819
- );
13820
- const switchToNewThread = React.useCallback(
13821
- () => runtimeRef.current.threads.switchToNewThread(),
13822
- []
13823
- );
13824
- const activeThreadId = remoteId ?? null;
13825
- return React.useMemo(() => {
13826
- if (!runtime || isListLoading == null) {
13827
- return null;
13828
- }
13829
- return {
13830
- activeThreadId,
13831
- isListLoading,
13832
- isThreadLoading,
13833
- switchToThread,
13834
- switchToNewThread
13835
- };
13836
- }, [runtime, activeThreadId, isListLoading, isThreadLoading, switchToThread, switchToNewThread]);
13837
- }
13838
- const POLL_DELAY_MS = 5e3;
13839
- const POLL_INTERVAL_MS = 1e3;
13840
- const POLL_MAX_DURATION_MS = 6e4;
13841
- function useThreadTitlePolling(refresh) {
13842
- const threadKey = react$1.useThread({
13843
- optional: true,
13844
- selector: (s) => {
13845
- var _a2, _b;
13846
- return ((_a2 = s.metadata) == null ? void 0 : _a2.remoteId) ?? ((_b = s.metadata) == null ? void 0 : _b.id) ?? s.threadId;
13847
- }
13848
- }) ?? null;
13849
- const hasMessages = react$1.useThread({
13850
- optional: true,
13851
- selector: (s) => s.messages.length > 0
13852
- }) ?? false;
13853
- const currentTitle = react$1.useThreadList({
13854
- optional: true,
13855
- selector: (s) => {
13856
- const main = s.threadItems[s.mainThreadId];
13857
- return (main == null ? void 0 : main.title) ?? "";
13858
- }
13859
- }) ?? "";
13860
- const hasTitle = currentTitle.trim().length > 0;
13861
- const polledThreadsRef = React.useRef(/* @__PURE__ */ new Set());
13862
- const refreshRef = React.useRef(refresh);
13863
- refreshRef.current = refresh;
13864
- React.useEffect(() => {
13865
- if (!threadKey || hasTitle || !hasMessages) {
13866
- return;
13867
- }
13868
- if (polledThreadsRef.current.has(threadKey)) {
13869
- return;
13870
- }
13871
- polledThreadsRef.current.add(threadKey);
13872
- let stopped = false;
13873
- let intervalId = null;
13874
- let maxTimeoutId = null;
13875
- const stop = () => {
13876
- stopped = true;
13877
- if (intervalId !== null) {
13878
- clearInterval(intervalId);
13879
- intervalId = null;
13880
- }
13881
- if (maxTimeoutId !== null) {
13882
- clearTimeout(maxTimeoutId);
13883
- maxTimeoutId = null;
13884
- }
13885
- };
13886
- const startTimeoutId = setTimeout(() => {
13887
- if (stopped) return;
13888
- refreshRef.current();
13889
- intervalId = setInterval(() => {
13890
- refreshRef.current();
13891
- }, POLL_INTERVAL_MS);
13892
- maxTimeoutId = setTimeout(stop, POLL_MAX_DURATION_MS - POLL_DELAY_MS);
13893
- }, POLL_DELAY_MS);
13894
- return () => {
13895
- clearTimeout(startTimeoutId);
13896
- stop();
13897
- };
13898
- }, [threadKey, hasTitle, hasMessages]);
13899
- }
13900
13241
  const createStoreImpl = (createState) => {
13901
13242
  let state;
13902
13243
  const listeners = /* @__PURE__ */ new Set();
@@ -14156,7 +13497,7 @@ const useAssetPanelStore = create()(
14156
13497
  ...t,
14157
13498
  name: meta.name ?? t.name,
14158
13499
  type: meta.type ?? t.type,
14159
- slideNumber: meta.slideNumber ?? t.slideNumber
13500
+ slideNumber: "slideNumber" in meta ? meta.slideNumber : t.slideNumber
14160
13501
  } : t
14161
13502
  ) : s.tabs;
14162
13503
  return { isOpen: true, tabs, activeTabId: assetId };
@@ -14239,6 +13580,398 @@ const useAssetPanelStore = create()(
14239
13580
  }
14240
13581
  )
14241
13582
  );
13583
+ function getAssetInfo(assetId) {
13584
+ return { name: assetId || "Document", icon: "doc" };
13585
+ }
13586
+ function tryParseJson$2(text2) {
13587
+ try {
13588
+ const p = JSON.parse(text2);
13589
+ return typeof p === "object" && p !== null ? p : null;
13590
+ } catch {
13591
+ return null;
13592
+ }
13593
+ }
13594
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
13595
+ const normalizeResult$2 = (result) => {
13596
+ if (!result) return null;
13597
+ if (typeof result === "string") {
13598
+ const parsed = tryParseJson$2(result);
13599
+ if (isRecord(parsed)) return parsed;
13600
+ return null;
13601
+ }
13602
+ if (isRecord(result)) {
13603
+ const inner = result.result;
13604
+ if (typeof inner === "string") {
13605
+ const parsed = tryParseJson$2(inner);
13606
+ if (isRecord(parsed)) return parsed;
13607
+ } else if (isRecord(inner)) {
13608
+ return inner;
13609
+ }
13610
+ return result;
13611
+ }
13612
+ return null;
13613
+ };
13614
+ const pickAssetId = (...candidates) => {
13615
+ for (const candidate of candidates) {
13616
+ if (typeof candidate === "string" && candidate.startsWith("asset_")) {
13617
+ return candidate;
13618
+ }
13619
+ }
13620
+ return null;
13621
+ };
13622
+ const pickNumber = (...candidates) => {
13623
+ for (const candidate of candidates) {
13624
+ if (typeof candidate === "number" && Number.isFinite(candidate)) {
13625
+ return candidate;
13626
+ }
13627
+ }
13628
+ return void 0;
13629
+ };
13630
+ const autoOpen = (assetId, options = {}) => {
13631
+ const store = useAssetPanelStore.getState();
13632
+ if (!store.markAutoOpened(assetId)) return;
13633
+ const existing = store.tabs.find((tab) => tab.id === assetId);
13634
+ const keepCurrentSlide = options.preserveExistingSlide && existing;
13635
+ store.openAsset(assetId, {
13636
+ type: options.type ?? "unknown",
13637
+ ...keepCurrentSlide || options.slideNumber === void 0 ? {} : { slideNumber: options.slideNumber }
13638
+ });
13639
+ };
13640
+ const openOnResult = (type, extra) => ({
13641
+ streamCall: async (reader) => {
13642
+ const { result } = await reader.response.get();
13643
+ const data = normalizeResult$2(result);
13644
+ const assetId = pickAssetId(
13645
+ data == null ? void 0 : data.asset_id,
13646
+ data == null ? void 0 : data.assetId,
13647
+ data == null ? void 0 : data.id
13648
+ );
13649
+ if (!assetId) return;
13650
+ let slideNumber;
13651
+ if ((extra == null ? void 0 : extra.slideNumberFrom) !== "args") {
13652
+ slideNumber = pickNumber(
13653
+ data == null ? void 0 : data.slide_number,
13654
+ data == null ? void 0 : data.slideNumber,
13655
+ data == null ? void 0 : data.targetSlideNumber,
13656
+ data == null ? void 0 : data.target_slide_number
13657
+ );
13658
+ }
13659
+ if (slideNumber === void 0 && (extra == null ? void 0 : extra.slideNumberFrom) !== "result") {
13660
+ const args = await reader.args.get().catch(() => null);
13661
+ slideNumber = pickNumber(
13662
+ args == null ? void 0 : args.slide_number,
13663
+ args == null ? void 0 : args.slideNumber,
13664
+ args == null ? void 0 : args.targetSlideNumber,
13665
+ args == null ? void 0 : args.target_slide_number
13666
+ );
13667
+ }
13668
+ autoOpen(assetId, {
13669
+ type,
13670
+ slideNumber,
13671
+ preserveExistingSlide: extra == null ? void 0 : extra.preserveExistingSlide
13672
+ });
13673
+ }
13674
+ });
13675
+ const openFromArgs = (type) => ({
13676
+ streamCall: async (reader) => {
13677
+ await reader.response.get();
13678
+ const args = await reader.args.get().catch(() => null);
13679
+ const assetId = pickAssetId(args == null ? void 0 : args.asset_id, args == null ? void 0 : args.assetId);
13680
+ if (!assetId) return;
13681
+ autoOpen(assetId, { type });
13682
+ }
13683
+ });
13684
+ const DEFAULT_AUTO_OPEN_TOOLS = {
13685
+ // Top-level asset creators
13686
+ create_new_document: openOnResult("document"),
13687
+ create_document_from_markdown: openOnResult("document"),
13688
+ create_new_sheet: openOnResult("spreadsheet"),
13689
+ create_powerpoint_deck: openOnResult("presentation"),
13690
+ create_new_notebook: openOnResult("notebook"),
13691
+ // Open / read existing assets
13692
+ open_asset_in_workspace: openFromArgs("unknown"),
13693
+ // Code execution that lands on a deck/slide
13694
+ execute_presentation_code: openOnResult("presentation"),
13695
+ // Media capture
13696
+ capture_moment: openOnResult("unknown"),
13697
+ // Studio PTC sub-calls (nested SDK commands)
13698
+ CreateWorkbook: openOnResult("spreadsheet"),
13699
+ AddSheet: openOnResult("spreadsheet"),
13700
+ OpenWorkbook: openOnResult("spreadsheet"),
13701
+ CreatePresentation: openOnResult("presentation"),
13702
+ OpenPresentation: openOnResult("presentation", { preserveExistingSlide: true }),
13703
+ AddSlide: openOnResult("presentation"),
13704
+ CreateDocument: openOnResult("document"),
13705
+ CreateParagraph: openOnResult("document"),
13706
+ OpenDocument: openOnResult("document")
13707
+ };
13708
+ const AthenaContext = React.createContext(null);
13709
+ function useAthenaConfig() {
13710
+ const ctx = React.useContext(AthenaContext);
13711
+ if (!ctx) {
13712
+ throw new Error("[AthenaSDK] useAthenaConfig must be used within <AthenaProvider>");
13713
+ }
13714
+ return ctx;
13715
+ }
13716
+ const AthenaThreadIdContext = React.createContext(void 0);
13717
+ function selectThreadListItemRemoteId(state) {
13718
+ var _a2;
13719
+ return (_a2 = state.threadListItem) == null ? void 0 : _a2.remoteId;
13720
+ }
13721
+ function useAthenaAuiThreadRemoteId() {
13722
+ return react$1.useAuiState(selectThreadListItemRemoteId);
13723
+ }
13724
+ function useAthenaThreadId() {
13725
+ return React.useContext(AthenaThreadIdContext);
13726
+ }
13727
+ function useAthenaThreadListAdapter(config2) {
13728
+ const configRef = React.useRef(config2);
13729
+ configRef.current = config2;
13730
+ const auth = React.useMemo(
13731
+ () => ({ apiKey: config2.apiKey, token: config2.token }),
13732
+ [config2.apiKey, config2.token]
13733
+ );
13734
+ const unstable_Provider = React.useCallback(
13735
+ function AthenaThreadProvider({ children }) {
13736
+ const remoteId = useAthenaAuiThreadRemoteId();
13737
+ return /* @__PURE__ */ jsxRuntime.jsx(AthenaThreadIdContext.Provider, { value: remoteId, children });
13738
+ },
13739
+ []
13740
+ );
13741
+ return React.useMemo(() => ({
13742
+ async list() {
13743
+ if (!auth.token && !auth.apiKey) {
13744
+ return { threads: [] };
13745
+ }
13746
+ try {
13747
+ const { threads } = await listThreads(configRef.current.backendUrl, auth, {
13748
+ ...configRef.current.appId ? { app_id: configRef.current.appId } : {}
13749
+ });
13750
+ return {
13751
+ threads: threads.map((t) => ({
13752
+ status: "regular",
13753
+ remoteId: t.thread_id,
13754
+ title: t.title || void 0
13755
+ }))
13756
+ };
13757
+ } catch (err) {
13758
+ console.error("[AthenaSDK] adapter.list() failed:", err);
13759
+ return { threads: [] };
13760
+ }
13761
+ },
13762
+ async initialize(_threadId) {
13763
+ const remoteId = typeof crypto !== "undefined" && "randomUUID" in crypto ? crypto.randomUUID() : `thread_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`;
13764
+ return { remoteId, externalId: void 0 };
13765
+ },
13766
+ async rename(_remoteId, _newTitle) {
13767
+ },
13768
+ async archive(remoteId) {
13769
+ await archiveThread(configRef.current.backendUrl, auth, remoteId);
13770
+ },
13771
+ async unarchive(_remoteId) {
13772
+ },
13773
+ async delete(remoteId) {
13774
+ await archiveThread(configRef.current.backendUrl, auth, remoteId);
13775
+ },
13776
+ async generateTitle(_remoteId, _messages) {
13777
+ return new ReadableStream({ start(c) {
13778
+ c.close();
13779
+ } });
13780
+ },
13781
+ async fetch(remoteId) {
13782
+ return {
13783
+ status: "regular",
13784
+ remoteId
13785
+ };
13786
+ },
13787
+ unstable_Provider
13788
+ }), [auth, unstable_Provider]);
13789
+ }
13790
+ const ThreadListRefreshContext = React.createContext(null);
13791
+ function useRefreshThreadList() {
13792
+ return React.useContext(ThreadListRefreshContext);
13793
+ }
13794
+ const LOCAL_ID_PREFIX$1 = "__LOCALID_";
13795
+ const isLocalPlaceholder$1 = (id) => !!id && id.startsWith(LOCAL_ID_PREFIX$1);
13796
+ const selectHydratableThreadId = (state) => {
13797
+ var _a2;
13798
+ const remoteId = ((_a2 = state.metadata) == null ? void 0 : _a2.remoteId) ?? state.threadId;
13799
+ return isLocalPlaceholder$1(remoteId) ? null : remoteId;
13800
+ };
13801
+ const createHydrationKey = ({
13802
+ backendUrl,
13803
+ threadId,
13804
+ apiKey,
13805
+ token
13806
+ }) => {
13807
+ const authMode = token ? "bearer" : apiKey ? "api-key" : "none";
13808
+ return `${backendUrl}::${authMode}::${threadId}`;
13809
+ };
13810
+ function useActiveThreadStateHydration({
13811
+ backendUrl,
13812
+ apiKey,
13813
+ token
13814
+ }) {
13815
+ const runtime = react$1.useAssistantRuntime({ optional: true });
13816
+ const threadId = react$1.useThread({
13817
+ optional: true,
13818
+ selector: selectHydratableThreadId
13819
+ }) ?? null;
13820
+ const messageCount = react$1.useThread({
13821
+ optional: true,
13822
+ selector: (state) => state.messages.length
13823
+ }) ?? 0;
13824
+ const isRunning = react$1.useThread({
13825
+ optional: true,
13826
+ selector: (state) => state.isRunning
13827
+ }) ?? false;
13828
+ const activeThreadIdRef = React.useRef(threadId);
13829
+ activeThreadIdRef.current = threadId;
13830
+ const hydratedKeysRef = React.useRef(/* @__PURE__ */ new Set());
13831
+ React.useEffect(() => {
13832
+ if (!runtime || !threadId || isRunning || messageCount > 0) {
13833
+ return;
13834
+ }
13835
+ if (!token && !apiKey) {
13836
+ return;
13837
+ }
13838
+ const hydrationKey = createHydrationKey({
13839
+ backendUrl,
13840
+ threadId,
13841
+ apiKey,
13842
+ token
13843
+ });
13844
+ if (hydratedKeysRef.current.has(hydrationKey)) {
13845
+ return;
13846
+ }
13847
+ let cancelled = false;
13848
+ (async () => {
13849
+ try {
13850
+ const state = await getThreadState(backendUrl, { apiKey, token }, threadId);
13851
+ if (cancelled || activeThreadIdRef.current !== threadId) {
13852
+ return;
13853
+ }
13854
+ if (runtime.thread.getState().messages.length > 0) {
13855
+ return;
13856
+ }
13857
+ runtime.thread.importExternalState(state);
13858
+ hydratedKeysRef.current.add(hydrationKey);
13859
+ } catch (error2) {
13860
+ console.warn("[AthenaSDK] Failed to hydrate active thread state:", error2);
13861
+ }
13862
+ })();
13863
+ return () => {
13864
+ cancelled = true;
13865
+ };
13866
+ }, [apiKey, backendUrl, isRunning, messageCount, runtime, threadId, token]);
13867
+ }
13868
+ const LOCAL_ID_PREFIX = "__LOCALID_";
13869
+ const isLocalPlaceholder = (id) => !!id && id.startsWith(LOCAL_ID_PREFIX);
13870
+ const selectActiveThreadRemoteId = (state) => {
13871
+ const { mainThreadId, threadItems } = state;
13872
+ if (!mainThreadId) {
13873
+ return null;
13874
+ }
13875
+ const item = threadItems[mainThreadId];
13876
+ const remoteId = item ? item.remoteId ?? null : mainThreadId;
13877
+ return isLocalPlaceholder(remoteId) ? null : remoteId;
13878
+ };
13879
+ function useAthenaThreadManager() {
13880
+ const runtime = react$1.useAssistantRuntime({ optional: true });
13881
+ const activeThreadId = react$1.useThreadList({
13882
+ optional: true,
13883
+ selector: selectActiveThreadRemoteId
13884
+ }) ?? null;
13885
+ const isThreadLoading = react$1.useThread({ optional: true, selector: (s) => s.isLoading }) ?? false;
13886
+ const isListLoading = react$1.useThreadList({
13887
+ optional: true,
13888
+ selector: (s) => s.isLoading
13889
+ });
13890
+ const runtimeRef = React.useRef(runtime);
13891
+ runtimeRef.current = runtime;
13892
+ const switchToThread = React.useCallback(
13893
+ (id) => runtimeRef.current.threads.switchToThread(id),
13894
+ []
13895
+ );
13896
+ const switchToNewThread = React.useCallback(
13897
+ () => runtimeRef.current.threads.switchToNewThread(),
13898
+ []
13899
+ );
13900
+ return React.useMemo(() => {
13901
+ if (!runtime || isListLoading == null) {
13902
+ return null;
13903
+ }
13904
+ return {
13905
+ activeThreadId,
13906
+ isListLoading,
13907
+ isThreadLoading,
13908
+ switchToThread,
13909
+ switchToNewThread
13910
+ };
13911
+ }, [runtime, activeThreadId, isListLoading, isThreadLoading, switchToThread, switchToNewThread]);
13912
+ }
13913
+ const POLL_DELAY_MS = 5e3;
13914
+ const POLL_INTERVAL_MS = 1e3;
13915
+ const POLL_MAX_DURATION_MS = 6e4;
13916
+ function useThreadTitlePolling(refresh) {
13917
+ const threadKey = react$1.useThread({
13918
+ optional: true,
13919
+ selector: (s) => {
13920
+ var _a2, _b;
13921
+ return ((_a2 = s.metadata) == null ? void 0 : _a2.remoteId) ?? ((_b = s.metadata) == null ? void 0 : _b.id) ?? s.threadId;
13922
+ }
13923
+ }) ?? null;
13924
+ const hasMessages = react$1.useThread({
13925
+ optional: true,
13926
+ selector: (s) => s.messages.length > 0
13927
+ }) ?? false;
13928
+ const currentTitle = react$1.useThreadList({
13929
+ optional: true,
13930
+ selector: (s) => {
13931
+ const main = s.threadItems[s.mainThreadId];
13932
+ return (main == null ? void 0 : main.title) ?? "";
13933
+ }
13934
+ }) ?? "";
13935
+ const hasTitle = currentTitle.trim().length > 0;
13936
+ const polledThreadsRef = React.useRef(/* @__PURE__ */ new Set());
13937
+ const refreshRef = React.useRef(refresh);
13938
+ refreshRef.current = refresh;
13939
+ React.useEffect(() => {
13940
+ if (!threadKey || hasTitle || !hasMessages) {
13941
+ return;
13942
+ }
13943
+ if (polledThreadsRef.current.has(threadKey)) {
13944
+ return;
13945
+ }
13946
+ polledThreadsRef.current.add(threadKey);
13947
+ let stopped = false;
13948
+ let intervalId = null;
13949
+ let maxTimeoutId = null;
13950
+ const stop = () => {
13951
+ stopped = true;
13952
+ if (intervalId !== null) {
13953
+ clearInterval(intervalId);
13954
+ intervalId = null;
13955
+ }
13956
+ if (maxTimeoutId !== null) {
13957
+ clearTimeout(maxTimeoutId);
13958
+ maxTimeoutId = null;
13959
+ }
13960
+ };
13961
+ const startTimeoutId = setTimeout(() => {
13962
+ if (stopped) return;
13963
+ refreshRef.current();
13964
+ intervalId = setInterval(() => {
13965
+ refreshRef.current();
13966
+ }, POLL_INTERVAL_MS);
13967
+ maxTimeoutId = setTimeout(stop, POLL_MAX_DURATION_MS - POLL_DELAY_MS);
13968
+ }, POLL_DELAY_MS);
13969
+ return () => {
13970
+ clearTimeout(startTimeoutId);
13971
+ stop();
13972
+ };
13973
+ }, [threadKey, hasTitle, hasMessages]);
13974
+ }
14242
13975
  const THEME_TO_CSS = {
14243
13976
  primary: "--primary",
14244
13977
  primaryForeground: "--primary-foreground",
@@ -14557,7 +14290,7 @@ function AthenaStandalone({
14557
14290
  return /* @__PURE__ */ jsxRuntime.jsx(react$1.AssistantRuntimeProvider, { aui, runtime, children: /* @__PURE__ */ jsxRuntime.jsx(AthenaContext.Provider, { value: athenaConfig, children: /* @__PURE__ */ jsxRuntime.jsx(TooltipProvider, { children }) }) });
14558
14291
  }
14559
14292
  function useAthenaRuntimeHook(config2) {
14560
- const remoteId = useAthenaThreadId();
14293
+ const remoteId = useAthenaAuiThreadRemoteId();
14561
14294
  return useAthenaRuntime({
14562
14295
  apiUrl: config2.apiUrl,
14563
14296
  backendUrl: config2.backendUrl,
@@ -14636,7 +14369,7 @@ function AthenaWithThreadList({
14636
14369
  () => useAthenaRuntimeHook(runtimeConfigRef.current),
14637
14370
  []
14638
14371
  );
14639
- const runtime = react$1.unstable_useRemoteThreadListRuntime({
14372
+ const runtime = react$1.useRemoteThreadListRuntime({
14640
14373
  runtimeHook,
14641
14374
  adapter
14642
14375
  });
@@ -14672,11 +14405,27 @@ function AthenaWithThreadList({
14672
14405
  citationLinks
14673
14406
  });
14674
14407
  return /* @__PURE__ */ jsxRuntime.jsx(react$1.AssistantRuntimeProvider, { aui, runtime, children: /* @__PURE__ */ jsxRuntime.jsx(AthenaContext.Provider, { value: athenaConfig, children: /* @__PURE__ */ jsxRuntime.jsx(ThreadListRefreshContext.Provider, { value: handleRefresh, children: /* @__PURE__ */ jsxRuntime.jsxs(TooltipProvider, { children: [
14408
+ /* @__PURE__ */ jsxRuntime.jsx(
14409
+ ActiveThreadStateHydrator,
14410
+ {
14411
+ backendUrl,
14412
+ apiKey,
14413
+ token
14414
+ }
14415
+ ),
14675
14416
  /* @__PURE__ */ jsxRuntime.jsx(AssetPanelThreadSync, {}),
14676
14417
  /* @__PURE__ */ jsxRuntime.jsx(ThreadTitlePoller, { refresh: handleRefresh }),
14677
14418
  children
14678
14419
  ] }) }) }) });
14679
14420
  }
14421
+ function ActiveThreadStateHydrator({
14422
+ backendUrl,
14423
+ apiKey,
14424
+ token
14425
+ }) {
14426
+ useActiveThreadStateHydration({ backendUrl, apiKey, token });
14427
+ return null;
14428
+ }
14680
14429
  function AssetPanelThreadSync() {
14681
14430
  const threads = useAthenaThreadManager();
14682
14431
  const setCurrentThread = useAssetPanelStore((s) => s.setCurrentThread);
@@ -14699,6 +14448,7 @@ function AthenaProvider({
14699
14448
  model,
14700
14449
  tools = [],
14701
14450
  frontendTools = {},
14451
+ disableAutoOpen = false,
14702
14452
  apiUrl,
14703
14453
  backendUrl,
14704
14454
  appUrl,
@@ -14716,6 +14466,10 @@ function AthenaProvider({
14716
14466
  posthog: posthogProp
14717
14467
  }) {
14718
14468
  const frontendToolNames = React.useMemo(() => Object.keys(frontendTools), [frontendTools]);
14469
+ const effectiveFrontendTools = React.useMemo(
14470
+ () => disableAutoOpen ? frontendTools : { ...DEFAULT_AUTO_OPEN_TOOLS, ...frontendTools },
14471
+ [disableAutoOpen, frontendTools]
14472
+ );
14719
14473
  const themeStyleVars = React.useMemo(() => theme ? themeToStyleVars(theme) : void 0, [theme]);
14720
14474
  const configuredEnvironment = (config2 == null ? void 0 : config2.environment) ?? environment;
14721
14475
  const environmentUrls = React.useMemo(
@@ -14755,7 +14509,7 @@ function AthenaProvider({
14755
14509
  agent: agent2,
14756
14510
  tools,
14757
14511
  frontendToolIds: frontendToolNames,
14758
- frontendTools,
14512
+ frontendTools: effectiveFrontendTools,
14759
14513
  workbench,
14760
14514
  knowledgeBase,
14761
14515
  systemPrompt,
@@ -14779,7 +14533,7 @@ function AthenaProvider({
14779
14533
  agent: agent2,
14780
14534
  tools,
14781
14535
  frontendToolIds: frontendToolNames,
14782
- frontendTools,
14536
+ frontendTools: effectiveFrontendTools,
14783
14537
  workbench,
14784
14538
  knowledgeBase,
14785
14539
  systemPrompt,
@@ -46402,7 +46156,7 @@ const DEFAULT_PILL_STYLE = "border-gray-300 bg-gray-50 text-gray-800 dark:border
46402
46156
  function MentionNodeView({ node }) {
46403
46157
  const { type, name, params } = node.attrs;
46404
46158
  const config2 = getMentionConfig(type);
46405
- const icon = isRecord(params) && typeof params.icon === "string" ? params.icon : (config2 == null ? void 0 : config2.style.icon) ?? "📎";
46159
+ const icon = isRecord$1(params) && typeof params.icon === "string" ? params.icon : (config2 == null ? void 0 : config2.style.icon) ?? "📎";
46406
46160
  const pillStyle = PILL_STYLES[type] ?? DEFAULT_PILL_STYLE;
46407
46161
  return /* @__PURE__ */ jsxRuntime.jsx(NodeViewWrapper, { as: "span", children: /* @__PURE__ */ jsxRuntime.jsxs(
46408
46162
  "span",
@@ -49668,7 +49422,7 @@ function getToolMeta(toolName) {
49668
49422
  const displayName = toolName.replace(/_/g, " ").replace(/\b\w/g, (c) => c.toUpperCase());
49669
49423
  return { displayName, icon: Wrench };
49670
49424
  }
49671
- function tryParseJson$2(text2) {
49425
+ function tryParseJson$1(text2) {
49672
49426
  try {
49673
49427
  const parsed = JSON.parse(text2);
49674
49428
  if (typeof parsed === "object" && parsed !== null) return parsed;
@@ -49678,7 +49432,7 @@ function tryParseJson$2(text2) {
49678
49432
  }
49679
49433
  function extractResultMessage(result) {
49680
49434
  if (typeof result === "string") {
49681
- const parsed = tryParseJson$2(result);
49435
+ const parsed = tryParseJson$1(result);
49682
49436
  if (parsed && typeof parsed.message === "string") return parsed.message;
49683
49437
  return null;
49684
49438
  }
@@ -49690,7 +49444,7 @@ function extractResultMessage(result) {
49690
49444
  }
49691
49445
  function isResultSuccess(result) {
49692
49446
  if (typeof result === "string") {
49693
- const parsed = tryParseJson$2(result);
49447
+ const parsed = tryParseJson$1(result);
49694
49448
  if (parsed) return parsed.success === true;
49695
49449
  }
49696
49450
  if (typeof result === "object" && result !== null) {
@@ -49712,7 +49466,7 @@ function extractAssetId$1(result) {
49712
49466
  }
49713
49467
  function extractAssetIdFromArgs(argsText) {
49714
49468
  if (!argsText) return null;
49715
- const parsed = tryParseJson$2(argsText);
49469
+ const parsed = tryParseJson$1(argsText);
49716
49470
  if (!parsed) return null;
49717
49471
  const id = parsed.asset_id ?? parsed.assetId;
49718
49472
  if (typeof id === "string" && id.startsWith("asset_")) return id;
@@ -49742,7 +49496,7 @@ function isAssetTool(toolName, result) {
49742
49496
  }
49743
49497
  function extractTitle(argsText, result) {
49744
49498
  if (argsText) {
49745
- const args = tryParseJson$2(argsText);
49499
+ const args = tryParseJson$1(argsText);
49746
49500
  if (args) {
49747
49501
  const t = args.title ?? args.name ?? args.filename ?? args.sheet_name;
49748
49502
  if (t) return t;
@@ -49823,7 +49577,7 @@ function ToolFallbackTrigger({
49823
49577
  const success = isComplete && isResultSuccess(result);
49824
49578
  const summary = React.useMemo(() => {
49825
49579
  if (isRunning || !meta.describer || !argsText) return null;
49826
- const parsed = tryParseJson$2(argsText);
49580
+ const parsed = tryParseJson$1(argsText);
49827
49581
  if (!parsed) return null;
49828
49582
  const desc = meta.describer(parsed);
49829
49583
  return desc || null;
@@ -49932,7 +49686,7 @@ function ToolFallbackArgs({
49932
49686
  ...props
49933
49687
  }) {
49934
49688
  if (!argsText) return null;
49935
- const parsed = tryParseJson$2(argsText);
49689
+ const parsed = tryParseJson$1(argsText);
49936
49690
  if (!parsed) {
49937
49691
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("px-3", className), ...props, children: /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "whitespace-pre-wrap text-xs text-muted-foreground", children: argsText }) });
49938
49692
  }
@@ -49956,7 +49710,7 @@ function ToolFallbackResult({
49956
49710
  const displayValue = React.useMemo(() => {
49957
49711
  if (result === void 0) return "";
49958
49712
  if (typeof result === "string") {
49959
- const parsed = tryParseJson$2(result);
49713
+ const parsed = tryParseJson$1(result);
49960
49714
  return parsed ? JSON.stringify(parsed, null, 2) : result;
49961
49715
  }
49962
49716
  return JSON.stringify(result, null, 2);
@@ -50000,12 +49754,12 @@ function CopyToolSpec({
50000
49754
  const handleCopy = React.useCallback(() => {
50001
49755
  const spec = { tool_name: toolName };
50002
49756
  if (argsText) {
50003
- const parsed = tryParseJson$2(argsText);
49757
+ const parsed = tryParseJson$1(argsText);
50004
49758
  spec.arguments = parsed ?? argsText;
50005
49759
  }
50006
49760
  if (result !== void 0) {
50007
49761
  if (typeof result === "string") {
50008
- const parsed = tryParseJson$2(result);
49762
+ const parsed = tryParseJson$1(result);
50009
49763
  spec.result = parsed ?? result;
50010
49764
  } else {
50011
49765
  spec.result = result;
@@ -50047,18 +49801,6 @@ function AssetToolCard({
50047
49801
  const assetId = extractAssetId$1(result);
50048
49802
  const title = extractTitle(argsText, result);
50049
49803
  const assetType = toolMetaToAssetType(toolName);
50050
- const wasCompleteAtMount = React.useRef(isComplete);
50051
- React.useEffect(() => {
50052
- if (isComplete && !isCancelled && assetId && !wasCompleteAtMount.current) {
50053
- const store = useAssetPanelStore.getState();
50054
- if (store.markAutoOpened(assetId)) {
50055
- store.openAsset(assetId, {
50056
- name: title ?? void 0,
50057
- type: assetType
50058
- });
50059
- }
50060
- }
50061
- }, [isComplete, isCancelled, assetId, title, assetType]);
50062
49804
  const success = isComplete && isResultSuccess(result);
50063
49805
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn(
50064
49806
  "aui-tool-fallback-root my-3 w-full rounded-xl border border-border/60 bg-background py-2.5 shadow-sm",
@@ -50206,17 +49948,6 @@ ToolFallback.Content = ToolFallbackContent;
50206
49948
  ToolFallback.Args = ToolFallbackArgs;
50207
49949
  ToolFallback.Result = ToolFallbackResult;
50208
49950
  ToolFallback.Error = ToolFallbackError;
50209
- function getAssetInfo(assetId) {
50210
- return { name: assetId || "Document", icon: "doc" };
50211
- }
50212
- function tryParseJson$1(text2) {
50213
- try {
50214
- const p = JSON.parse(text2);
50215
- return typeof p === "object" && p !== null ? p : null;
50216
- } catch {
50217
- return null;
50218
- }
50219
- }
50220
49951
  const markdownPreviewExtensions = [
50221
49952
  StarterKit.configure({
50222
49953
  codeBlock: {
@@ -50265,10 +49996,10 @@ const AppendDocumentToolUIImpl = ({
50265
49996
  const typedArgs = args;
50266
49997
  const resultData = React.useMemo(() => {
50267
49998
  if (!result) return null;
50268
- if (typeof result === "string") return tryParseJson$1(result);
49999
+ if (typeof result === "string") return tryParseJson$2(result);
50269
50000
  if (typeof result === "object") {
50270
50001
  const obj = result;
50271
- if (typeof obj.result === "string") return tryParseJson$1(obj.result) ?? obj;
50002
+ if (typeof obj.result === "string") return tryParseJson$2(obj.result) ?? obj;
50272
50003
  return obj;
50273
50004
  }
50274
50005
  return null;
@@ -50350,11 +50081,11 @@ const AppendDocumentToolUI = React.memo(
50350
50081
  );
50351
50082
  AppendDocumentToolUI.displayName = "AppendDocumentToolUI";
50352
50083
  function normalizeResult$1(result) {
50353
- if (typeof result === "string") return tryParseJson$1(result) ?? result;
50084
+ if (typeof result === "string") return tryParseJson$2(result) ?? result;
50354
50085
  if (typeof result === "object" && result !== null) {
50355
50086
  const obj = result;
50356
50087
  if (typeof obj.result === "string")
50357
- return tryParseJson$1(obj.result) ?? obj.result;
50088
+ return tryParseJson$2(obj.result) ?? obj.result;
50358
50089
  return obj;
50359
50090
  }
50360
50091
  return result;
@@ -50620,6 +50351,32 @@ function normalizeResult(result) {
50620
50351
  function truncate(text2, max2) {
50621
50352
  return text2.length > max2 ? `${text2.slice(0, max2)}...` : text2;
50622
50353
  }
50354
+ function isSdkToolDebugEnabled() {
50355
+ var _a2, _b;
50356
+ try {
50357
+ const hostname = (_a2 = globalThis.location) == null ? void 0 : _a2.hostname;
50358
+ if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "::1") {
50359
+ return true;
50360
+ }
50361
+ return ((_b = globalThis.localStorage) == null ? void 0 : _b.getItem("athena:sdk:debug")) === "1";
50362
+ } catch {
50363
+ return false;
50364
+ }
50365
+ }
50366
+ function stringifyDebugPayload(payload) {
50367
+ return JSON.stringify(payload, (_key, value) => {
50368
+ if (typeof value === "string" && value.length > 800) {
50369
+ return `${value.slice(0, 800)}... [truncated ${value.length - 800} chars]`;
50370
+ }
50371
+ return value;
50372
+ });
50373
+ }
50374
+ function logDebugPayload(label, payload) {
50375
+ if (!isSdkToolDebugEnabled()) {
50376
+ return;
50377
+ }
50378
+ console.info(`${label} ${stringifyDebugPayload(payload)}`);
50379
+ }
50623
50380
  function formatToolName(name) {
50624
50381
  return name.replace(/_/g, " ").replace(/\b\w/g, (c) => c.toUpperCase());
50625
50382
  }
@@ -50930,6 +50687,20 @@ function getNumberField(source, keys2) {
50930
50687
  }
50931
50688
  return null;
50932
50689
  }
50690
+ const PRESENTATION_CODE_SLIDE_NUMBER_KEYS = [
50691
+ "slideNumber",
50692
+ "slide_number",
50693
+ "targetSlideNumber",
50694
+ "target_slide_number",
50695
+ "targetSlide",
50696
+ "target_slide"
50697
+ ];
50698
+ const PRESENTATION_CODE_SLIDE_INDEX_KEYS = [
50699
+ "slideIndex",
50700
+ "slide_index",
50701
+ "targetSlideIndex",
50702
+ "target_slide_index"
50703
+ ];
50933
50704
  function getStudioAssetId({
50934
50705
  args,
50935
50706
  result
@@ -50937,41 +50708,42 @@ function getStudioAssetId({
50937
50708
  const id = getStringField(result, ["asset_id", "assetId", "id"]) ?? getStringField(args, ["asset_id", "assetId", "id"]);
50938
50709
  return (id == null ? void 0 : id.startsWith("asset_")) ? id : null;
50939
50710
  }
50940
- function getSlideNumber(args) {
50941
- const explicit = getNumberField(args, ["slideNumber", "slide_number"]);
50711
+ function getPresentationCodeDeckId(code2) {
50712
+ const match2 = code2.match(/\bdeck_id\s*=\s*["']([^"']+)["']/);
50713
+ const deckId = match2 == null ? void 0 : match2[1];
50714
+ return (deckId == null ? void 0 : deckId.startsWith("asset_")) ? deckId : null;
50715
+ }
50716
+ function getPresentationCodeSlideNumberFromFields(source) {
50717
+ const explicit = getNumberField(source, PRESENTATION_CODE_SLIDE_NUMBER_KEYS);
50942
50718
  if (explicit != null && Number.isInteger(explicit) && explicit >= 1) {
50943
50719
  return explicit;
50944
50720
  }
50945
- const zeroBasedIndex = getNumberField(args, ["index", "slideIndex", "slide_index"]);
50721
+ const zeroBasedIndex = getNumberField(source, PRESENTATION_CODE_SLIDE_INDEX_KEYS);
50946
50722
  if (zeroBasedIndex != null && Number.isInteger(zeroBasedIndex) && zeroBasedIndex >= 0) {
50947
50723
  return zeroBasedIndex + 1;
50948
50724
  }
50949
50725
  return void 0;
50950
50726
  }
50951
- const completedStudioToolEffects = /* @__PURE__ */ new Set();
50952
- const MAX_COMPLETED_STUDIO_TOOL_EFFECTS = 500;
50953
- function markStudioToolEffect(key) {
50954
- if (completedStudioToolEffects.has(key)) {
50955
- return false;
50956
- }
50957
- if (completedStudioToolEffects.size >= MAX_COMPLETED_STUDIO_TOOL_EFFECTS) {
50958
- const oldest = completedStudioToolEffects.values().next().value;
50959
- if (oldest) completedStudioToolEffects.delete(oldest);
50727
+ function getPresentationCodeSlideNumberFromText(text2) {
50728
+ const match2 = text2 == null ? void 0 : text2.match(/\bslide\s*(?:#|number\s*)?(\d+)\b/i);
50729
+ if (!match2) {
50730
+ return void 0;
50960
50731
  }
50961
- completedStudioToolEffects.add(key);
50962
- return true;
50732
+ const slideNumber = Number.parseInt(match2[1] ?? "", 10);
50733
+ return Number.isInteger(slideNumber) && slideNumber >= 1 ? slideNumber : void 0;
50963
50734
  }
50964
- function dispatchPresentationNavigate(assetId, slideNumber) {
50965
- const targetSlide = slideNumber;
50966
- if (typeof targetSlide !== "number" || !Number.isInteger(targetSlide) || targetSlide < 1) {
50967
- return;
50968
- }
50969
- window.dispatchEvent(
50970
- new CustomEvent("pptx-studio-navigate", {
50971
- detail: { assetId, slideNumber: targetSlide }
50972
- })
50735
+ function getPresentationCodeSlideNumber({
50736
+ args,
50737
+ result
50738
+ }) {
50739
+ return getPresentationCodeSlideNumberFromFields(args) ?? getPresentationCodeSlideNumberFromFields(result) ?? getPresentationCodeSlideNumberFromText(
50740
+ getStringField(args, ["summary", "title", "description"])
50973
50741
  );
50974
50742
  }
50743
+ function getAddSlideNumber(args) {
50744
+ const index2 = getNumberField(args, ["index"]);
50745
+ return index2 != null && Number.isInteger(index2) && index2 >= 0 ? index2 + 1 : void 0;
50746
+ }
50975
50747
  function CreateAssetToolUIImpl({
50976
50748
  icon: Icon2,
50977
50749
  assetType,
@@ -50992,18 +50764,6 @@ function CreateAssetToolUIImpl({
50992
50764
  const isCancelled = (status == null ? void 0 : status.type) === "incomplete" && status.reason === "cancelled";
50993
50765
  const errorMsg = (status == null ? void 0 : status.type) === "incomplete" ? status.error : null;
50994
50766
  const openAsset = useAssetPanelStore((s) => s.openAsset);
50995
- const wasCompleteAtMount = React.useRef(isComplete);
50996
- React.useEffect(() => {
50997
- if (isComplete && !isCancelled && assetId && !wasCompleteAtMount.current) {
50998
- const store = useAssetPanelStore.getState();
50999
- if (store.markAutoOpened(assetId)) {
51000
- store.openAsset(assetId, {
51001
- name: createdName || name || void 0,
51002
- type: assetType
51003
- });
51004
- }
51005
- }
51006
- }, [isComplete, isCancelled, assetId, createdName, name, assetType]);
51007
50767
  const handleOpen = () => {
51008
50768
  if (assetId) {
51009
50769
  openAsset(assetId, {
@@ -51081,10 +50841,23 @@ const CreatePresentationToolUI = React.memo(
51081
50841
  CreatePresentationToolUIImpl
51082
50842
  );
51083
50843
  CreatePresentationToolUI.displayName = "CreatePresentationToolUI";
50844
+ function openStudioAsset({
50845
+ assetId,
50846
+ assetType,
50847
+ slideNumber,
50848
+ preserveExistingSlide
50849
+ }) {
50850
+ const store = useAssetPanelStore.getState();
50851
+ const existing = store.tabs.find((tab) => tab.id === assetId);
50852
+ const shouldKeepCurrentSlide = preserveExistingSlide && existing;
50853
+ store.openAsset(assetId, {
50854
+ type: assetType,
50855
+ ...!shouldKeepCurrentSlide && slideNumber !== void 0 ? { slideNumber } : {}
50856
+ });
50857
+ }
51084
50858
  function StudioPtcToolUI({
51085
50859
  config: config2,
51086
50860
  toolName,
51087
- toolCallId,
51088
50861
  args,
51089
50862
  result,
51090
50863
  status
@@ -51099,42 +50872,57 @@ function StudioPtcToolUI({
51099
50872
  const isComplete = (status == null ? void 0 : status.type) === "complete" || !status;
51100
50873
  const isCancelled = (status == null ? void 0 : status.type) === "incomplete" && status.reason === "cancelled";
51101
50874
  const errorMsg = (status == null ? void 0 : status.type) === "incomplete" ? String(status.error ?? status.reason ?? "Tool failed") : null;
51102
- const openAsset = useAssetPanelStore((s) => s.openAsset);
51103
50875
  const handleOpen = React.useCallback(() => {
51104
50876
  if (!assetId) return;
51105
- openAsset(assetId, {
51106
- type: config2.assetType,
51107
- slideNumber
51108
- });
51109
- if (config2.assetType === "presentation") {
51110
- dispatchPresentationNavigate(assetId, slideNumber);
50877
+ if (toolName === "AddSlide") {
50878
+ logDebugPayload("[Athena SDK AddSlide] manual open", {
50879
+ args: typedArgs,
50880
+ parsedResult: data,
50881
+ rawResult: result,
50882
+ assetId,
50883
+ slideNumber
50884
+ });
51111
50885
  }
51112
- }, [assetId, config2.assetType, openAsset, slideNumber]);
50886
+ openStudioAsset({
50887
+ assetId,
50888
+ assetType: config2.assetType,
50889
+ slideNumber,
50890
+ preserveExistingSlide: config2.preserveExistingSlide
50891
+ });
50892
+ }, [
50893
+ assetId,
50894
+ config2.assetType,
50895
+ config2.preserveExistingSlide,
50896
+ data,
50897
+ result,
50898
+ slideNumber,
50899
+ toolName,
50900
+ typedArgs
50901
+ ]);
51113
50902
  React.useEffect(() => {
51114
- if (!config2.autoOpen || !isComplete || isCancelled || !assetId) {
51115
- return;
51116
- }
51117
- const effectKey = toolCallId ?? `${toolName ?? "studio-tool"}:${assetId}:${slideNumber ?? "asset"}`;
51118
- if (!markStudioToolEffect(effectKey)) {
50903
+ if (toolName !== "AddSlide") {
51119
50904
  return;
51120
50905
  }
51121
- const store = useAssetPanelStore.getState();
51122
- store.openAsset(assetId, {
51123
- type: config2.assetType,
51124
- slideNumber
50906
+ logDebugPayload("[Athena SDK AddSlide] tool state", {
50907
+ args: typedArgs,
50908
+ parsedResult: data,
50909
+ rawResult: result,
50910
+ status,
50911
+ assetId,
50912
+ slideNumber,
50913
+ isComplete,
50914
+ isCancelled
51125
50915
  });
51126
- if (config2.assetType === "presentation") {
51127
- dispatchPresentationNavigate(assetId, slideNumber);
51128
- }
51129
50916
  }, [
51130
50917
  assetId,
51131
- config2.assetType,
51132
- config2.autoOpen,
50918
+ data,
51133
50919
  isCancelled,
51134
50920
  isComplete,
50921
+ result,
51135
50922
  slideNumber,
51136
- toolCallId,
51137
- toolName
50923
+ status,
50924
+ toolName,
50925
+ typedArgs
51138
50926
  ]);
51139
50927
  return /* @__PURE__ */ jsxRuntime.jsx(
51140
50928
  ToolCard,
@@ -51192,8 +50980,7 @@ const StudioCreateWorkbookToolUI = createStudioPtcToolUI(
51192
50980
  },
51193
50981
  doneLabel: () => "Workbook created",
51194
50982
  getSubtitle: getNameSubtitle,
51195
- openLabel: () => "Open workbook",
51196
- autoOpen: true
50983
+ openLabel: () => "Open workbook"
51197
50984
  }
51198
50985
  );
51199
50986
  const StudioAddSheetToolUI = createStudioPtcToolUI(
@@ -51211,8 +50998,7 @@ const StudioAddSheetToolUI = createStudioPtcToolUI(
51211
50998
  return name ? `Sheet added: ${name}` : "Sheet added";
51212
50999
  },
51213
51000
  getSubtitle: (args) => getStringField(args, ["name", "sheetName", "sheet_name"]) ?? void 0,
51214
- openLabel: () => "Open workbook",
51215
- autoOpen: true
51001
+ openLabel: () => "Open workbook"
51216
51002
  }
51217
51003
  );
51218
51004
  const StudioOpenWorkbookToolUI = createStudioPtcToolUI(
@@ -51223,8 +51009,7 @@ const StudioOpenWorkbookToolUI = createStudioPtcToolUI(
51223
51009
  badge: "Sheet",
51224
51010
  runningLabel: () => "Opening workbook...",
51225
51011
  doneLabel: () => "Workbook opened",
51226
- openLabel: () => "Open workbook",
51227
- autoOpen: true
51012
+ openLabel: () => "Open workbook"
51228
51013
  }
51229
51014
  );
51230
51015
  const StudioCreatePresentationToolUI = createStudioPtcToolUI(
@@ -51240,8 +51025,7 @@ const StudioCreatePresentationToolUI = createStudioPtcToolUI(
51240
51025
  doneLabel: () => "Presentation created",
51241
51026
  getSubtitle: getNameSubtitle,
51242
51027
  getSlideNumber: () => 1,
51243
- openLabel: () => "Open presentation",
51244
- autoOpen: true
51028
+ openLabel: () => "Open presentation"
51245
51029
  }
51246
51030
  );
51247
51031
  const StudioOpenPresentationToolUI = createStudioPtcToolUI(
@@ -51255,7 +51039,7 @@ const StudioOpenPresentationToolUI = createStudioPtcToolUI(
51255
51039
  getSlideNumber: () => 1,
51256
51040
  getSubtitle: (_args, _result, slideNumber) => slideNumber ? `Slide ${slideNumber}` : void 0,
51257
51041
  openLabel: () => "Open presentation",
51258
- autoOpen: true
51042
+ preserveExistingSlide: true
51259
51043
  }
51260
51044
  );
51261
51045
  const StudioAddSlideToolUI = createStudioPtcToolUI(
@@ -51267,9 +51051,8 @@ const StudioAddSlideToolUI = createStudioPtcToolUI(
51267
51051
  runningLabel: () => "Adding slide...",
51268
51052
  doneLabel: (_args, slideNumber) => slideNumber ? `Slide ${slideNumber} added` : "Slide added",
51269
51053
  getSubtitle: getSlideSubtitle,
51270
- getSlideNumber,
51271
- openLabel: (slideNumber) => slideNumber ? `Open slide ${slideNumber}` : "Open presentation",
51272
- autoOpen: true
51054
+ getSlideNumber: (args) => getAddSlideNumber(args) ?? 1,
51055
+ openLabel: (slideNumber) => slideNumber ? `Open slide ${slideNumber}` : "Open presentation"
51273
51056
  }
51274
51057
  );
51275
51058
  const StudioCreateDocumentToolUI = createStudioPtcToolUI(
@@ -51284,8 +51067,7 @@ const StudioCreateDocumentToolUI = createStudioPtcToolUI(
51284
51067
  },
51285
51068
  doneLabel: () => "Document created",
51286
51069
  getSubtitle: getNameSubtitle,
51287
- openLabel: () => "Open document",
51288
- autoOpen: true
51070
+ openLabel: () => "Open document"
51289
51071
  }
51290
51072
  );
51291
51073
  const StudioCreateParagraphToolUI = createStudioPtcToolUI(
@@ -51297,8 +51079,7 @@ const StudioCreateParagraphToolUI = createStudioPtcToolUI(
51297
51079
  runningLabel: () => "Adding paragraph...",
51298
51080
  doneLabel: () => "Paragraph added",
51299
51081
  getSubtitle: getParagraphSubtitle,
51300
- openLabel: () => "Open document",
51301
- autoOpen: true
51082
+ openLabel: () => "Open document"
51302
51083
  }
51303
51084
  );
51304
51085
  const StudioOpenDocumentToolUI = createStudioPtcToolUI(
@@ -51309,8 +51090,7 @@ const StudioOpenDocumentToolUI = createStudioPtcToolUI(
51309
51090
  badge: "Doc",
51310
51091
  runningLabel: () => "Opening document...",
51311
51092
  doneLabel: () => "Document opened",
51312
- openLabel: () => "Open document",
51313
- autoOpen: true
51093
+ openLabel: () => "Open document"
51314
51094
  }
51315
51095
  );
51316
51096
  const CreateEmailDraftToolUIImpl = ({
@@ -51818,7 +51598,7 @@ const ExecutePresentationCodeToolUIImpl = ({
51818
51598
  const typedArgs = args;
51819
51599
  const code2 = (typedArgs == null ? void 0 : typedArgs.code) ?? "";
51820
51600
  const summary = (typedArgs == null ? void 0 : typedArgs.summary) ?? null;
51821
- const deckIdFromArgs = typeof (typedArgs == null ? void 0 : typedArgs.deck_id) === "string" ? typedArgs.deck_id : null;
51601
+ const deckIdFromArgs = getStringField(typedArgs, ["deck_id", "deckId", "asset_id", "assetId"]) ?? getPresentationCodeDeckId(code2);
51822
51602
  const isRunning = (status == null ? void 0 : status.type) === "running";
51823
51603
  const isComplete = (status == null ? void 0 : status.type) === "complete";
51824
51604
  const errorMsg = (status == null ? void 0 : status.type) === "incomplete" ? status.error : null;
@@ -51826,21 +51606,55 @@ const ExecutePresentationCodeToolUIImpl = ({
51826
51606
  () => isComplete ? parsePythonResult(result) : null,
51827
51607
  [result, isComplete]
51828
51608
  );
51609
+ const resultData = React.useMemo(() => normalizeResult(result), [result]);
51829
51610
  const outputText = parsed ? getExecutionTextOutput(parsed) : null;
51830
- const assetId = (parsed == null ? void 0 : parsed.assetId) ?? null;
51611
+ const targetSlideNumber = getPresentationCodeSlideNumber({
51612
+ args: typedArgs,
51613
+ result: resultData
51614
+ });
51831
51615
  const deckId = (parsed == null ? void 0 : parsed.deckId) ?? deckIdFromArgs;
51616
+ const assetId = (parsed == null ? void 0 : parsed.assetId) ?? ((deckId == null ? void 0 : deckId.startsWith("asset_")) ? deckId : null);
51832
51617
  const hasError = parsed && (parsed.error || parsed.exception);
51833
51618
  const openAsset = useAssetPanelStore((s) => s.openAsset);
51834
- const wasCompleteAtMount = React.useRef(isComplete);
51835
51619
  React.useEffect(() => {
51836
- if (!isComplete || !assetId || wasCompleteAtMount.current) {
51620
+ if (!isComplete) {
51837
51621
  return;
51838
51622
  }
51839
- const store = useAssetPanelStore.getState();
51840
- if (store.markAutoOpened(assetId)) {
51841
- store.openAsset(assetId, { type: "presentation" });
51623
+ logDebugPayload("[Athena SDK execute_presentation_code] tool state", {
51624
+ args: typedArgs,
51625
+ parsedResult: resultData,
51626
+ status,
51627
+ assetId,
51628
+ deckId,
51629
+ targetSlideNumber,
51630
+ outputText
51631
+ });
51632
+ }, [
51633
+ assetId,
51634
+ deckId,
51635
+ isComplete,
51636
+ outputText,
51637
+ resultData,
51638
+ status,
51639
+ targetSlideNumber,
51640
+ typedArgs
51641
+ ]);
51642
+ const openPresentation = React.useCallback(() => {
51643
+ if (!assetId) {
51644
+ return;
51842
51645
  }
51843
- }, [assetId, isComplete]);
51646
+ logDebugPayload("[Athena SDK execute_presentation_code] open deck", {
51647
+ args: typedArgs,
51648
+ parsedResult: resultData,
51649
+ assetId,
51650
+ deckId,
51651
+ targetSlideNumber
51652
+ });
51653
+ openAsset(assetId, {
51654
+ type: "presentation",
51655
+ ...targetSlideNumber !== void 0 ? { slideNumber: targetSlideNumber } : {}
51656
+ });
51657
+ }, [assetId, deckId, openAsset, resultData, targetSlideNumber, typedArgs]);
51844
51658
  return /* @__PURE__ */ jsxRuntime.jsxs(
51845
51659
  ToolCard,
51846
51660
  {
@@ -51863,11 +51677,11 @@ const ExecutePresentationCodeToolUIImpl = ({
51863
51677
  "button",
51864
51678
  {
51865
51679
  type: "button",
51866
- onClick: () => openAsset(assetId, { type: "presentation" }),
51680
+ onClick: openPresentation,
51867
51681
  className: "flex shrink-0 items-center gap-1.5 rounded-md border border-border/60 px-3 py-1.5 text-xs font-medium text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground",
51868
51682
  children: [
51869
51683
  /* @__PURE__ */ jsxRuntime.jsx(ExternalLink, { className: "size-3" }),
51870
- "Open deck"
51684
+ targetSlideNumber ? `Open slide ${targetSlideNumber}` : "Open deck"
51871
51685
  ]
51872
51686
  }
51873
51687
  )
@@ -51926,15 +51740,6 @@ const OpenAssetToolUIImpl = ({
51926
51740
  const isCancelled = (status == null ? void 0 : status.type) === "incomplete" && status.reason === "cancelled";
51927
51741
  const errorMsg = (status == null ? void 0 : status.type) === "incomplete" ? status.error : null;
51928
51742
  const openAsset = useAssetPanelStore((s) => s.openAsset);
51929
- const wasCompleteAtMount = React.useRef(isComplete);
51930
- React.useEffect(() => {
51931
- if (isComplete && !isCancelled && assetId && !wasCompleteAtMount.current) {
51932
- const store = useAssetPanelStore.getState();
51933
- if (store.markAutoOpened(assetId)) {
51934
- store.openAsset(assetId);
51935
- }
51936
- }
51937
- }, [isComplete, isCancelled, assetId]);
51938
51743
  return /* @__PURE__ */ jsxRuntime.jsx(
51939
51744
  ToolCard,
51940
51745
  {
@@ -52673,18 +52478,6 @@ const CaptureMomentToolUIImpl = ({
52673
52478
  const isComplete = (status == null ? void 0 : status.type) === "complete" || !status;
52674
52479
  const isCancelled = (status == null ? void 0 : status.type) === "incomplete" && status.reason === "cancelled";
52675
52480
  const openAsset = useAssetPanelStore((s) => s.openAsset);
52676
- const wasCompleteAtMount = React.useRef(isComplete);
52677
- React.useEffect(() => {
52678
- if (isComplete && !isCancelled && createdAssetId && !wasCompleteAtMount.current) {
52679
- const store = useAssetPanelStore.getState();
52680
- if (store.markAutoOpened(createdAssetId)) {
52681
- store.openAsset(createdAssetId, {
52682
- name: void 0,
52683
- type: "unknown"
52684
- });
52685
- }
52686
- }
52687
- }, [isComplete, isCancelled, createdAssetId, resultType]);
52688
52481
  const handleOpen = () => {
52689
52482
  if (createdAssetId) {
52690
52483
  openAsset(createdAssetId, {
@@ -52744,6 +52537,153 @@ const CaptureMomentToolUI = React.memo(
52744
52537
  CaptureMomentToolUIImpl
52745
52538
  );
52746
52539
  CaptureMomentToolUI.displayName = "CaptureMomentToolUI";
52540
+ function normalizeContentResult(result) {
52541
+ if (Array.isArray(result)) {
52542
+ return result;
52543
+ }
52544
+ if (typeof result === "string") {
52545
+ try {
52546
+ const parsed = JSON.parse(result);
52547
+ return normalizeContentResult(parsed);
52548
+ } catch {
52549
+ return [];
52550
+ }
52551
+ }
52552
+ if (result && typeof result === "object") {
52553
+ const obj = result;
52554
+ if (Array.isArray(obj.result)) {
52555
+ return obj.result;
52556
+ }
52557
+ if (typeof obj.result === "string") {
52558
+ return normalizeContentResult(obj.result);
52559
+ }
52560
+ if (Array.isArray(obj.content)) {
52561
+ return obj.content;
52562
+ }
52563
+ }
52564
+ return [];
52565
+ }
52566
+ function getSlideScreenshotResult(result) {
52567
+ let text2 = null;
52568
+ let imageUrl = null;
52569
+ let mediaType = null;
52570
+ let s3Key = null;
52571
+ for (const item of normalizeContentResult(result)) {
52572
+ if (!item || typeof item !== "object") {
52573
+ continue;
52574
+ }
52575
+ const part = item;
52576
+ if (!text2 && part.type === "text" && typeof part.text === "string") {
52577
+ text2 = part.text;
52578
+ continue;
52579
+ }
52580
+ if (part.type !== "image") {
52581
+ continue;
52582
+ }
52583
+ const source = part.source && typeof part.source === "object" ? part.source : {};
52584
+ if (!imageUrl) {
52585
+ imageUrl = getStringField(source, ["presigned_url", "url"]) ?? getStringField(part, ["url", "image_url"]);
52586
+ }
52587
+ if (!mediaType) {
52588
+ mediaType = getStringField(source, ["media_type", "mime_type"]) ?? getStringField(part, ["media_type", "mime_type"]);
52589
+ }
52590
+ if (!s3Key) {
52591
+ s3Key = getStringField(source, ["data", "s3_key"]);
52592
+ }
52593
+ }
52594
+ return { text: text2, imageUrl, mediaType, s3Key };
52595
+ }
52596
+ const CaptureSlideScreenshotToolUIImpl = ({
52597
+ toolName,
52598
+ args,
52599
+ result,
52600
+ status
52601
+ }) => {
52602
+ const typedArgs = args;
52603
+ const assetId = getStringField(typedArgs, ["asset_id", "assetId"]);
52604
+ const slideNumber = getNumberField(typedArgs, ["slide_number", "slideNumber"]) ?? void 0;
52605
+ const { text: text2, imageUrl, mediaType } = React.useMemo(
52606
+ () => getSlideScreenshotResult(result),
52607
+ [result]
52608
+ );
52609
+ const isRunning = (status == null ? void 0 : status.type) === "running";
52610
+ const isComplete = (status == null ? void 0 : status.type) === "complete" || !status;
52611
+ const isCancelled = (status == null ? void 0 : status.type) === "incomplete" && status.reason === "cancelled";
52612
+ const errorMsg = (status == null ? void 0 : status.type) === "incomplete" ? String(status.error ?? status.reason ?? "Capture failed") : null;
52613
+ const openAsset = useAssetPanelStore((s) => s.openAsset);
52614
+ const handleOpenSlide = React.useCallback(() => {
52615
+ if (!assetId) {
52616
+ return;
52617
+ }
52618
+ openAsset(assetId, {
52619
+ type: "presentation",
52620
+ ...slideNumber ? { slideNumber } : {}
52621
+ });
52622
+ }, [assetId, openAsset, slideNumber]);
52623
+ const subtitle = [
52624
+ slideNumber ? `Slide ${slideNumber}` : null,
52625
+ assetId ? truncate(assetId, 34) : null
52626
+ ].filter((value) => Boolean(value)).join(" · ");
52627
+ return /* @__PURE__ */ jsxRuntime.jsxs(
52628
+ ToolCard,
52629
+ {
52630
+ icon: Camera,
52631
+ status: (status == null ? void 0 : status.type) ?? "complete",
52632
+ title: isRunning ? "Capturing slide screenshot..." : errorMsg ? "Slide screenshot failed" : "Slide screenshot captured",
52633
+ subtitle: subtitle || void 0,
52634
+ badge: slideNumber ? `Slide ${slideNumber}` : mediaType ?? void 0,
52635
+ toolName,
52636
+ args: typedArgs,
52637
+ result,
52638
+ error: errorMsg,
52639
+ children: [
52640
+ isComplete && !isCancelled && imageUrl && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "border-t border-border/40 p-3", children: [
52641
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-hidden rounded-lg border border-border/50 bg-muted/20", children: /* @__PURE__ */ jsxRuntime.jsx(
52642
+ "img",
52643
+ {
52644
+ src: imageUrl,
52645
+ alt: slideNumber ? `Slide ${slideNumber} screenshot` : "Slide screenshot",
52646
+ className: "aspect-video w-full object-contain",
52647
+ loading: "lazy"
52648
+ }
52649
+ ) }),
52650
+ text2 && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-2 text-[11px] leading-relaxed text-muted-foreground", children: truncate(text2, 160) })
52651
+ ] }),
52652
+ isComplete && !isCancelled && assetId && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap gap-2 border-t border-border/40 px-4 py-2", children: [
52653
+ /* @__PURE__ */ jsxRuntime.jsxs(
52654
+ "button",
52655
+ {
52656
+ type: "button",
52657
+ onClick: handleOpenSlide,
52658
+ className: "flex items-center gap-1.5 rounded-md border border-border/60 px-3 py-1.5 text-xs font-medium text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground",
52659
+ children: [
52660
+ /* @__PURE__ */ jsxRuntime.jsx(ExternalLink, { className: "size-3" }),
52661
+ slideNumber ? `Open slide ${slideNumber}` : "Open presentation"
52662
+ ]
52663
+ }
52664
+ ),
52665
+ imageUrl && /* @__PURE__ */ jsxRuntime.jsxs(
52666
+ "a",
52667
+ {
52668
+ href: imageUrl,
52669
+ target: "_blank",
52670
+ rel: "noreferrer",
52671
+ className: "flex items-center gap-1.5 rounded-md border border-border/60 px-3 py-1.5 text-xs font-medium text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground",
52672
+ children: [
52673
+ /* @__PURE__ */ jsxRuntime.jsx(Image, { className: "size-3" }),
52674
+ "Open image"
52675
+ ]
52676
+ }
52677
+ )
52678
+ ] })
52679
+ ]
52680
+ }
52681
+ );
52682
+ };
52683
+ const CaptureSlideScreenshotToolUI = React.memo(
52684
+ CaptureSlideScreenshotToolUIImpl
52685
+ );
52686
+ CaptureSlideScreenshotToolUI.displayName = "CaptureSlideScreenshotToolUI";
52747
52687
  const TOOL_UI_REGISTRY = {
52748
52688
  search: WebSearchToolUI,
52749
52689
  browse: BrowseToolUI,
@@ -52771,6 +52711,7 @@ const TOOL_UI_REGISTRY = {
52771
52711
  open_asset_in_workspace: OpenAssetToolUI,
52772
52712
  // Media capture
52773
52713
  capture_moment: CaptureMomentToolUI,
52714
+ capture_slide_screenshot: CaptureSlideScreenshotToolUI,
52774
52715
  // Spreadsheet toolkit
52775
52716
  update_sheet_range: UpdateSheetRangeToolUI,
52776
52717
  // Database toolkit
@@ -53386,7 +53327,7 @@ const useAthenaChatDefaultComponents = () => {
53386
53327
  return value;
53387
53328
  };
53388
53329
  const AthenaDefaultAssistantMessage = () => {
53389
- const { toolUIs, TextComponent, ReasoningComponent, EmptyComponent: EmptyComponent2, ActionBarComponent } = useAthenaChatDefaultComponents();
53330
+ const { toolUIs, TextComponent, ReasoningComponent, EmptyComponent: EmptyComponent2, ActionBarComponent, groupToolCalls } = useAthenaChatDefaultComponents();
53390
53331
  return /* @__PURE__ */ jsxRuntime.jsx(
53391
53332
  AthenaAssistantMessage,
53392
53333
  {
@@ -53394,7 +53335,8 @@ const AthenaDefaultAssistantMessage = () => {
53394
53335
  TextComponent,
53395
53336
  ReasoningComponent,
53396
53337
  EmptyComponent: EmptyComponent2,
53397
- ActionBarComponent
53338
+ ActionBarComponent,
53339
+ groupToolCalls
53398
53340
  }
53399
53341
  );
53400
53342
  };
@@ -53403,15 +53345,15 @@ const AthenaDefaultUserMessage = () => {
53403
53345
  return /* @__PURE__ */ jsxRuntime.jsx(AthenaUserMessage, { TextComponent });
53404
53346
  };
53405
53347
  const getReasoningTokensFromMetadata = (metadata) => {
53406
- if (!isRecord(metadata)) {
53348
+ if (!isRecord$1(metadata)) {
53407
53349
  return void 0;
53408
53350
  }
53409
53351
  const customMetadata = metadata.custom;
53410
- if (!isRecord(customMetadata)) {
53352
+ if (!isRecord$1(customMetadata)) {
53411
53353
  return void 0;
53412
53354
  }
53413
53355
  const athenaMetadata = customMetadata._athena;
53414
- if (!isRecord(athenaMetadata)) {
53356
+ if (!isRecord$1(athenaMetadata)) {
53415
53357
  return void 0;
53416
53358
  }
53417
53359
  const reasoningTokens = athenaMetadata.reasoningTokens;
@@ -53460,7 +53402,8 @@ const AthenaChat = ({
53460
53402
  toolUIs,
53461
53403
  mentionTools,
53462
53404
  welcomeSuggestions = DEFAULT_SUGGESTIONS,
53463
- components
53405
+ components,
53406
+ groupToolCalls = false
53464
53407
  }) => {
53465
53408
  var _a2, _b, _c;
53466
53409
  const athenaConfig = useAthenaConfig();
@@ -53498,9 +53441,10 @@ const AthenaChat = ({
53498
53441
  TextComponent: textComponent,
53499
53442
  ReasoningComponent: reasoningComponent,
53500
53443
  EmptyComponent: emptyComponent,
53501
- ActionBarComponent: actionBarComponent
53444
+ ActionBarComponent: actionBarComponent,
53445
+ groupToolCalls
53502
53446
  }),
53503
- [actionBarComponent, emptyComponent, mergedToolUIs, reasoningComponent, textComponent]
53447
+ [actionBarComponent, emptyComponent, groupToolCalls, mergedToolUIs, reasoningComponent, textComponent]
53504
53448
  );
53505
53449
  const AssistantMessageComponent = (components == null ? void 0 : components.AssistantMessage) ?? AthenaDefaultAssistantMessage;
53506
53450
  const UserMessageComponent = (components == null ? void 0 : components.UserMessage) ?? AthenaDefaultUserMessage;
@@ -53774,17 +53718,20 @@ const AthenaReasoningPart = ({
53774
53718
  ]
53775
53719
  }
53776
53720
  ) }),
53777
- /* @__PURE__ */ jsxRuntime.jsx(CollapsibleContent, { className: "pt-3", children: isRunning && !hasText ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "shimmer text-[13px] text-muted-foreground", children: "Analyzing..." }) : isRunning ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "whitespace-pre-wrap break-words text-[13px] leading-relaxed text-foreground", children: text2 }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "aui-assistant-reasoning-body text-[13px] leading-relaxed", children: /* @__PURE__ */ jsxRuntime.jsx(EffectiveTextComponent, { ...reasoningTextProps }) }) })
53721
+ /* @__PURE__ */ jsxRuntime.jsx(CollapsibleContent, { className: "pt-3", children: isRunning && !hasText ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "shimmer text-[13px] text-muted-foreground", children: "Analyzing..." }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "aui-assistant-reasoning-body text-[13px] leading-relaxed", children: /* @__PURE__ */ jsxRuntime.jsx(EffectiveTextComponent, { ...reasoningTextProps }) }) })
53778
53722
  ]
53779
53723
  }
53780
53724
  );
53781
53725
  };
53726
+ const groupAdjacentToolCalls = (part) => part.type === "tool-call" ? ["group-tool"] : null;
53727
+ const noToolGrouping = () => null;
53782
53728
  const AthenaAssistantMessage = ({
53783
53729
  toolUIs,
53784
53730
  TextComponent = TiptapText,
53785
53731
  ReasoningComponent,
53786
53732
  EmptyComponent: EmptyComponent2 = AthenaAssistantMessageEmpty,
53787
- ActionBarComponent = AthenaAssistantActionBar
53733
+ ActionBarComponent = AthenaAssistantActionBar,
53734
+ groupToolCalls = false
53788
53735
  }) => {
53789
53736
  const effectiveReasoningComponent = ReasoningComponent ?? AthenaReasoningPart;
53790
53737
  const toolUIsWithNestedMessages = React.useMemo(() => {
@@ -53794,7 +53741,7 @@ const AthenaAssistantMessage = ({
53794
53741
  }
53795
53742
  return wrappedToolUIs;
53796
53743
  }, [toolUIs]);
53797
- const partsComponents = React.useMemo(
53744
+ const nestedPtcComponents = React.useMemo(
53798
53745
  () => ({
53799
53746
  Text: TextComponent,
53800
53747
  Reasoning: effectiveReasoningComponent,
@@ -53813,7 +53760,31 @@ const AthenaAssistantMessage = ({
53813
53760
  "data-role": "assistant",
53814
53761
  children: [
53815
53762
  /* @__PURE__ */ jsxRuntime.jsx(AthenaReasoningTextComponentContext.Provider, { value: TextComponent, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "aui-assistant-message-content wrap-break-word px-2 text-foreground leading-relaxed", children: [
53816
- /* @__PURE__ */ jsxRuntime.jsx(NestedPtcComponentsProvider, { components: partsComponents, children: /* @__PURE__ */ jsxRuntime.jsx(react$1.MessagePrimitive.Parts, { components: partsComponents }) }),
53763
+ /* @__PURE__ */ jsxRuntime.jsx(NestedPtcComponentsProvider, { components: nestedPtcComponents, children: /* @__PURE__ */ jsxRuntime.jsx(react$1.MessagePrimitive.GroupedParts, { groupBy: groupToolCalls ? groupAdjacentToolCalls : noToolGrouping, children: ({ part, children }) => {
53764
+ var _a2, _b;
53765
+ switch (part.type) {
53766
+ case "group-tool":
53767
+ return /* @__PURE__ */ jsxRuntime.jsx(AthenaToolGroup, { count: ((_a2 = part.indices) == null ? void 0 : _a2.length) ?? 0, children });
53768
+ case "tool-call": {
53769
+ const ToolUI = toolUIsWithNestedMessages[part.toolName];
53770
+ const toolProps = part;
53771
+ return ToolUI ? /* @__PURE__ */ jsxRuntime.jsx(ToolUI, { ...toolProps }) : /* @__PURE__ */ jsxRuntime.jsx(ToolFallback, { ...toolProps });
53772
+ }
53773
+ case "reasoning": {
53774
+ const ReasoningRenderer = effectiveReasoningComponent;
53775
+ return /* @__PURE__ */ jsxRuntime.jsx(ReasoningRenderer, { ...part });
53776
+ }
53777
+ case "text": {
53778
+ const textPart = part;
53779
+ if (textPart.text === "" && ((_b = textPart.status) == null ? void 0 : _b.type) === "running") {
53780
+ return /* @__PURE__ */ jsxRuntime.jsx(EmptyComponent2, { status: textPart.status });
53781
+ }
53782
+ return /* @__PURE__ */ jsxRuntime.jsx(TextComponent, { ...textPart });
53783
+ }
53784
+ default:
53785
+ return null;
53786
+ }
53787
+ } }) }),
53817
53788
  /* @__PURE__ */ jsxRuntime.jsx(MessageError, {})
53818
53789
  ] }) }),
53819
53790
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "aui-assistant-message-footer mt-1 ml-2 flex", children: /* @__PURE__ */ jsxRuntime.jsx(ActionBarComponent, {}) })
@@ -53821,6 +53792,38 @@ const AthenaAssistantMessage = ({
53821
53792
  }
53822
53793
  );
53823
53794
  };
53795
+ const AthenaToolGroup = ({ children, count: count2 }) => {
53796
+ const [expanded, setExpanded] = React.useState(false);
53797
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "my-3 w-full overflow-hidden rounded-xl border border-border/60 bg-background shadow-sm", children: [
53798
+ /* @__PURE__ */ jsxRuntime.jsxs(
53799
+ "button",
53800
+ {
53801
+ type: "button",
53802
+ onClick: () => setExpanded((v) => !v),
53803
+ className: "flex w-full items-center gap-3 px-4 py-3 text-left transition-colors hover:bg-muted/20",
53804
+ "aria-expanded": expanded,
53805
+ children: [
53806
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex size-8 shrink-0 items-center justify-center rounded-lg bg-muted/60 text-muted-foreground", children: /* @__PURE__ */ jsxRuntime.jsx(Layers, { className: "size-4" }) }),
53807
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "min-w-0 flex-1", children: /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-[13px] font-medium text-foreground", children: [
53808
+ count2,
53809
+ " tool ",
53810
+ count2 === 1 ? "call" : "calls"
53811
+ ] }) }),
53812
+ /* @__PURE__ */ jsxRuntime.jsx(
53813
+ ChevronDown,
53814
+ {
53815
+ className: cn(
53816
+ "size-4 shrink-0 text-muted-foreground transition-transform duration-200",
53817
+ !expanded && "-rotate-90"
53818
+ )
53819
+ }
53820
+ )
53821
+ ]
53822
+ }
53823
+ ),
53824
+ expanded && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "border-t border-border/40 bg-muted/5 px-3 pt-1 pb-2 [&>*]:my-2", children })
53825
+ ] });
53826
+ };
53824
53827
  const AthenaAssistantActionBar = ({ className }) => {
53825
53828
  const threadId = useAthenaThreadId();
53826
53829
  const { appUrl } = useAthenaConfig();
@@ -53880,10 +53883,37 @@ const AthenaUserMessage = ({
53880
53883
  }
53881
53884
  );
53882
53885
  const embedCache = /* @__PURE__ */ new Map();
53886
+ function resolveAssetEmbedUrl({
53887
+ embedUrl,
53888
+ appUrl
53889
+ }) {
53890
+ if (!appUrl) {
53891
+ return embedUrl;
53892
+ }
53893
+ try {
53894
+ const resolvedEmbedUrl = new URL(embedUrl);
53895
+ const resolvedAppUrl = new URL(appUrl);
53896
+ if (!resolvedEmbedUrl.pathname.startsWith("/embed/")) {
53897
+ return embedUrl;
53898
+ }
53899
+ resolvedEmbedUrl.protocol = resolvedAppUrl.protocol;
53900
+ resolvedEmbedUrl.host = resolvedAppUrl.host;
53901
+ return resolvedEmbedUrl.toString();
53902
+ } catch {
53903
+ return embedUrl;
53904
+ }
53905
+ }
53883
53906
  function useAssetEmbed(assetId, options = {
53884
53907
  backendUrl: ""
53885
53908
  }) {
53886
- const { readOnly = false, expiresInSeconds = 60 * 60 * 24 * 30, backendUrl, apiKey, token } = options;
53909
+ const {
53910
+ readOnly = false,
53911
+ expiresInSeconds = 60 * 60 * 24 * 30,
53912
+ backendUrl,
53913
+ appUrl,
53914
+ apiKey,
53915
+ token
53916
+ } = options;
53887
53917
  const [embedUrl, setEmbedUrl] = React.useState(null);
53888
53918
  const [isLoading, setIsLoading] = React.useState(false);
53889
53919
  const [error2, setError] = React.useState(null);
@@ -53900,7 +53930,7 @@ function useAssetEmbed(assetId, options = {
53900
53930
  return;
53901
53931
  }
53902
53932
  const authContext = hasToken ? "token" : apiKey ?? "anon";
53903
- const cacheKey = `${assetId}:${readOnly}:${authContext}`;
53933
+ const cacheKey = `${assetId}:${readOnly}:${authContext}:${appUrl ?? ""}`;
53904
53934
  const cached2 = embedCache.get(cacheKey);
53905
53935
  if (cached2 && cached2.expiresAt > Date.now() / 1e3) {
53906
53936
  setEmbedUrl(cached2.url);
@@ -53938,8 +53968,12 @@ function useAssetEmbed(assetId, options = {
53938
53968
  }
53939
53969
  return res.json();
53940
53970
  }).then((data) => {
53941
- embedCache.set(cacheKey, { url: data.embed_url, expiresAt: data.expires_at });
53942
- setEmbedUrl(data.embed_url);
53971
+ const resolvedEmbedUrl = resolveAssetEmbedUrl({
53972
+ embedUrl: data.embed_url,
53973
+ appUrl
53974
+ });
53975
+ embedCache.set(cacheKey, { url: resolvedEmbedUrl, expiresAt: data.expires_at });
53976
+ setEmbedUrl(resolvedEmbedUrl);
53943
53977
  setIsLoading(false);
53944
53978
  }).catch((err) => {
53945
53979
  if (err.name === "AbortError") return;
@@ -53947,7 +53981,7 @@ function useAssetEmbed(assetId, options = {
53947
53981
  setIsLoading(false);
53948
53982
  });
53949
53983
  return () => controller.abort();
53950
- }, [assetId, readOnly, expiresInSeconds, backendUrl, apiKey, hasToken]);
53984
+ }, [assetId, readOnly, expiresInSeconds, backendUrl, appUrl, apiKey, hasToken]);
53951
53985
  return { embedUrl, isLoading, error: error2 };
53952
53986
  }
53953
53987
  const ABSOLUTE_URL_PATTERN = /^[a-zA-Z][a-zA-Z\d+\-.]*:/;
@@ -53970,6 +54004,21 @@ function buildAssetIframeSrc({
53970
54004
  return `${embedUrl}${separator}slide=${targetSlide}`;
53971
54005
  }
53972
54006
  }
54007
+ function buildPresentationNavigationMessage({
54008
+ assetId,
54009
+ assetType,
54010
+ slideNumber
54011
+ }) {
54012
+ if (!assetId.trim() || assetType !== "presentation" || typeof slideNumber !== "number" || !Number.isInteger(slideNumber) || slideNumber < 1) {
54013
+ return null;
54014
+ }
54015
+ return {
54016
+ type: "NAVIGATE_TO_SLIDE",
54017
+ assetId,
54018
+ deckId: assetId,
54019
+ slideNumber
54020
+ };
54021
+ }
53973
54022
  const ASSET_TYPE_CONFIG = {
53974
54023
  presentation: { icon: Presentation, label: "Presentation" },
53975
54024
  spreadsheet: { icon: FileSpreadsheet, label: "Spreadsheet" },
@@ -53979,20 +54028,60 @@ const ASSET_TYPE_CONFIG = {
53979
54028
  };
53980
54029
  const AssetIframe = React.memo(
53981
54030
  ({ tab }) => {
53982
- const { backendUrl, apiKey, token } = useAthenaConfig();
54031
+ const iframeRef = React.useRef(null);
54032
+ const { backendUrl, appUrl, apiKey, token } = useAthenaConfig();
53983
54033
  const { embedUrl, isLoading, error: error2 } = useAssetEmbed(tab.id, {
53984
54034
  backendUrl,
54035
+ appUrl,
53985
54036
  apiKey,
53986
54037
  token
53987
54038
  });
54039
+ const initialSlideRef = React.useRef({
54040
+ assetId: tab.id,
54041
+ slideNumber: tab.slideNumber
54042
+ });
54043
+ if (initialSlideRef.current.assetId !== tab.id) {
54044
+ initialSlideRef.current = {
54045
+ assetId: tab.id,
54046
+ slideNumber: tab.slideNumber
54047
+ };
54048
+ }
54049
+ const initialSlideNumber = initialSlideRef.current.slideNumber;
53988
54050
  const iframeSrc = React.useMemo(
53989
54051
  () => embedUrl ? buildAssetIframeSrc({
53990
54052
  embedUrl,
53991
54053
  assetType: tab.type,
53992
- slideNumber: tab.slideNumber
54054
+ slideNumber: initialSlideNumber
53993
54055
  }) : null,
53994
- [embedUrl, tab.slideNumber, tab.type]
54056
+ [embedUrl, initialSlideNumber, tab.type]
53995
54057
  );
54058
+ const navigationMessage = React.useMemo(
54059
+ () => buildPresentationNavigationMessage({
54060
+ assetId: tab.id,
54061
+ assetType: tab.type,
54062
+ slideNumber: tab.slideNumber
54063
+ }),
54064
+ [tab.id, tab.slideNumber, tab.type]
54065
+ );
54066
+ const navigationTargetOrigin = React.useMemo(() => {
54067
+ if (!iframeSrc) return null;
54068
+ try {
54069
+ return new URL(iframeSrc, window.location.href).origin;
54070
+ } catch {
54071
+ return null;
54072
+ }
54073
+ }, [iframeSrc]);
54074
+ const postNavigationMessage = React.useCallback(() => {
54075
+ var _a2, _b;
54076
+ if (!navigationMessage || !navigationTargetOrigin) return;
54077
+ (_b = (_a2 = iframeRef.current) == null ? void 0 : _a2.contentWindow) == null ? void 0 : _b.postMessage(
54078
+ navigationMessage,
54079
+ navigationTargetOrigin
54080
+ );
54081
+ }, [navigationMessage, navigationTargetOrigin]);
54082
+ React.useEffect(() => {
54083
+ postNavigationMessage();
54084
+ }, [postNavigationMessage]);
53996
54085
  if (isLoading) {
53997
54086
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex h-full items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-center", children: [
53998
54087
  /* @__PURE__ */ jsxRuntime.jsx(LoaderCircle, { className: "mx-auto size-6 animate-spin text-muted-foreground" }),
@@ -54010,16 +54099,19 @@ const AssetIframe = React.memo(
54010
54099
  return /* @__PURE__ */ jsxRuntime.jsx(
54011
54100
  "iframe",
54012
54101
  {
54102
+ ref: iframeRef,
54013
54103
  src: iframeSrc,
54014
54104
  width: "100%",
54015
54105
  height: "100%",
54016
54106
  frameBorder: "0",
54017
54107
  allow: "fullscreen",
54018
54108
  title: tab.name ?? `Asset ${tab.id}`,
54019
- className: "h-full w-full"
54109
+ className: "h-full w-full",
54110
+ onLoad: postNavigationMessage
54020
54111
  }
54021
54112
  );
54022
- }
54113
+ },
54114
+ (prev, next) => prev.tab.id === next.tab.id && prev.tab.name === next.tab.name && prev.tab.type === next.tab.type && prev.tab.slideNumber === next.tab.slideNumber
54023
54115
  );
54024
54116
  AssetIframe.displayName = "AssetIframe";
54025
54117
  const PanelContent = ({
@@ -54341,6 +54433,7 @@ exports.CreatePresentationToolUI = CreatePresentationToolUI;
54341
54433
  exports.CreateSheetToolUI = CreateSheetToolUI;
54342
54434
  exports.DEFAULT_API_URL = DEFAULT_API_URL;
54343
54435
  exports.DEFAULT_APP_URL = DEFAULT_APP_URL;
54436
+ exports.DEFAULT_AUTO_OPEN_TOOLS = DEFAULT_AUTO_OPEN_TOOLS;
54344
54437
  exports.DEFAULT_BACKEND_URL = DEFAULT_BACKEND_URL;
54345
54438
  exports.DescribeDatabaseToolUI = DescribeDatabaseToolUI;
54346
54439
  exports.EmailSearchToolUI = EmailSearchToolUI;
@@ -54394,7 +54487,7 @@ exports.resetAssetAutoOpen = resetAssetAutoOpen;
54394
54487
  exports.themeToStyleVars = themeToStyleVars;
54395
54488
  exports.themes = themes;
54396
54489
  exports.truncate = truncate;
54397
- exports.tryParseJson = tryParseJson$1;
54490
+ exports.tryParseJson = tryParseJson$2;
54398
54491
  exports.useAppendToComposer = useAppendToComposer;
54399
54492
  exports.useAssetEmbed = useAssetEmbed;
54400
54493
  exports.useAssetPanelStore = useAssetPanelStore;