@athenaintel/react 0.9.16 → 0.9.17

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
@@ -19867,14 +19867,20 @@ const joinExternalMessages = (messages) => {
19867
19867
  )
19868
19868
  );
19869
19869
  }
19870
+ const { messages: existingMessages, ...toolCallRest } = toolCall;
19870
19871
  const updatedToolCall = {
19871
- ...toolCall,
19872
+ ...toolCallRest,
19872
19873
  result: output.result,
19873
19874
  artifact: output.artifact,
19874
19875
  isError: output.isError,
19875
- messages: output.messages
19876
+ ...(output.messages ?? existingMessages) !== void 0 && {
19877
+ messages: output.messages ?? existingMessages
19878
+ }
19876
19879
  };
19877
- bindExternalStoreMessage(updatedToolCall, [...getExternalStoreMessages(toolCall), output]);
19880
+ bindExternalStoreMessage(updatedToolCall, [
19881
+ ...getExternalStoreMessages(toolCallRest),
19882
+ output
19883
+ ]);
19878
19884
  assistantMessage.content[toolCallIdx] = updatedToolCall;
19879
19885
  } else {
19880
19886
  console.warn(
@@ -19883,10 +19889,14 @@ const joinExternalMessages = (messages) => {
19883
19889
  }
19884
19890
  } else {
19885
19891
  const role = output.role;
19886
- const content = (typeof output.content === "string" ? [{ type: "text", text: output.content }] : output.content).map((c) => {
19892
+ const rawContent = typeof output.content === "string" ? [{ type: "text", text: output.content }] : Array.isArray(output.content) ? output.content : [];
19893
+ const content = rawContent.flatMap((c) => {
19894
+ if (!c || typeof c !== "object") {
19895
+ return [];
19896
+ }
19887
19897
  const mapped = { ...c };
19888
19898
  bindExternalStoreMessage(mapped, output);
19889
- return mapped;
19899
+ return [mapped];
19890
19900
  });
19891
19901
  switch (role) {
19892
19902
  case "system":
@@ -20017,7 +20027,13 @@ const convertExternalMessages = (messages, callback, isRunning, metadata) => {
20017
20027
  const callbackResults = [];
20018
20028
  for (const message of messages) {
20019
20029
  const output = callback(message, metadata);
20020
- const outputs = Array.isArray(output) ? output : [output];
20030
+ const rawOutputs = Array.isArray(output) ? output : [output];
20031
+ const outputs = rawOutputs.filter(
20032
+ (candidate) => candidate != null
20033
+ );
20034
+ if (outputs.length === 0) {
20035
+ continue;
20036
+ }
20021
20037
  const result = { input: message, outputs };
20022
20038
  callbackResults.push(result);
20023
20039
  }
@@ -20040,37 +20056,40 @@ const warnForUnknownMessagePartType = (type) => {
20040
20056
  };
20041
20057
  const contentToParts = (content) => {
20042
20058
  if (typeof content === "string") return [{ type: "text", text: content }];
20043
- return content.map((part) => {
20059
+ return content.flatMap((part) => {
20060
+ if (!part || typeof part !== "object" || !("type" in part)) {
20061
+ return [];
20062
+ }
20044
20063
  const type = part.type;
20045
20064
  switch (type) {
20046
20065
  case "text":
20047
- return { type: "text", text: part.text };
20066
+ return [{ type: "text", text: part.text }];
20048
20067
  case "text_delta":
20049
- return { type: "text", text: part.text };
20068
+ return [{ type: "text", text: part.text }];
20050
20069
  case "image_url":
20051
20070
  if (typeof part.image_url === "string") {
20052
- return { type: "image", image: part.image_url };
20071
+ return [{ type: "image", image: part.image_url }];
20053
20072
  }
20054
- return {
20073
+ return [{
20055
20074
  type: "image",
20056
20075
  image: part.image_url.url
20057
- };
20076
+ }];
20058
20077
  case "thinking":
20059
- return { type: "reasoning", text: part.thinking };
20078
+ return [{ type: "reasoning", text: part.thinking }];
20060
20079
  case "reasoning":
20061
- return {
20080
+ return [{
20062
20081
  type: "reasoning",
20063
20082
  text: part.summary.map((s) => s.text).join("\n\n\n")
20064
- };
20083
+ }];
20065
20084
  case "tool_use":
20066
- return null;
20085
+ return [];
20067
20086
  case "input_json_delta":
20068
- return null;
20087
+ return [];
20069
20088
  default:
20070
20089
  warnForUnknownMessagePartType(type);
20071
- return null;
20090
+ return [];
20072
20091
  }
20073
- }).filter((a) => a !== null);
20092
+ });
20074
20093
  };
20075
20094
  const getNumberAtPath = (value, path) => {
20076
20095
  let current = value;
@@ -20175,7 +20194,7 @@ const convertLangChainMessage = (message) => {
20175
20194
  (_b = message.additional_kwargs) == null ? void 0 : _b.reasoning,
20176
20195
  ...normalizedContent,
20177
20196
  ...((_c = message.additional_kwargs) == null ? void 0 : _c.tool_outputs) ?? []
20178
- ].filter((c) => c !== void 0);
20197
+ ].filter((c) => c != null);
20179
20198
  return {
20180
20199
  role: "assistant",
20181
20200
  id: message.id,
@@ -20198,6 +20217,8 @@ const convertLangChainMessage = (message) => {
20198
20217
  isError: message.status === "error"
20199
20218
  };
20200
20219
  }
20220
+ default:
20221
+ return null;
20201
20222
  }
20202
20223
  };
20203
20224
  const convertLangChainToThreadMessages = (messages, isRunning = false, metadata = {}) => {
@@ -58875,20 +58896,14 @@ const useAssetPanelStore = create()(
58875
58896
  const existing = s.tabs.find((t) => t.id === assetId);
58876
58897
  if (existing) {
58877
58898
  const tabs = meta ? s.tabs.map(
58878
- (t) => t.id === assetId ? {
58879
- ...t,
58880
- name: meta.name ?? t.name,
58881
- type: meta.type ?? t.type,
58882
- embedSearchParams: meta.embedSearchParams ?? t.embedSearchParams
58883
- } : t
58899
+ (t) => t.id === assetId ? { ...t, name: meta.name ?? t.name, type: meta.type ?? t.type } : t
58884
58900
  ) : s.tabs;
58885
58901
  return { isOpen: true, tabs, activeTabId: assetId };
58886
58902
  }
58887
58903
  const newTab = {
58888
58904
  id: assetId,
58889
58905
  name: (meta == null ? void 0 : meta.name) ?? null,
58890
- type: (meta == null ? void 0 : meta.type) ?? "unknown",
58891
- embedSearchParams: (meta == null ? void 0 : meta.embedSearchParams) ?? null
58906
+ type: (meta == null ? void 0 : meta.type) ?? "unknown"
58892
58907
  };
58893
58908
  return { isOpen: true, tabs: [...s.tabs, newTab], activeTabId: assetId };
58894
58909
  }),
@@ -58949,43 +58964,13 @@ const ASSET_TYPE_ALIASES = {
58949
58964
  super_document: "document"
58950
58965
  };
58951
58966
  const isAthenaSpacesPath = (url) => url.pathname.replace(/\/+$/, "") === "/dashboard/spaces";
58952
- const normalizeAssetType$1 = (value) => {
58967
+ const normalizeAssetType = (value) => {
58953
58968
  if (!value) {
58954
58969
  return null;
58955
58970
  }
58956
58971
  const normalizedValue = value.trim().replace(/^athena\//, "").toLowerCase().replace(/-/g, "_");
58957
58972
  return ASSET_TYPE_ALIASES[normalizedValue] ?? null;
58958
58973
  };
58959
- const isLikelyAssetId = (value) => !!value && /^(asset|thread|project|collection)_[a-z0-9-]+$/i.test(value.trim());
58960
- const sanitizeDisplayName = (value) => {
58961
- if (!value) {
58962
- return null;
58963
- }
58964
- const trimmedValue = value.trim();
58965
- if (!trimmedValue) {
58966
- return null;
58967
- }
58968
- if (trimmedValue.startsWith('"') && trimmedValue.endsWith('"') || trimmedValue.startsWith("'") && trimmedValue.endsWith("'")) {
58969
- return trimmedValue.slice(1, -1).trim() || null;
58970
- }
58971
- return trimmedValue;
58972
- };
58973
- const getCitationDisplayName = ({
58974
- assetName,
58975
- linkText
58976
- }) => {
58977
- const sanitizedAssetName = sanitizeDisplayName(assetName);
58978
- const sanitizedLinkText = sanitizeDisplayName(linkText);
58979
- const genericLinkTextPattern = /^(this|that|the)\s+asset$/i;
58980
- if (sanitizedAssetName && !isLikelyAssetId(sanitizedAssetName)) {
58981
- return sanitizedAssetName;
58982
- }
58983
- if (sanitizedLinkText && !genericLinkTextPattern.test(sanitizedLinkText)) {
58984
- return sanitizedLinkText;
58985
- }
58986
- return sanitizedAssetName ?? sanitizedLinkText;
58987
- };
58988
- const getEmbedSearchParams = (url) => Object.fromEntries(url.searchParams.entries());
58989
58974
  const getOrigin = (value) => {
58990
58975
  if (!value) {
58991
58976
  return null;
@@ -59067,11 +59052,7 @@ const parseAthenaCitationLink = ({
59067
59052
  url,
59068
59053
  assetId,
59069
59054
  assetIds,
59070
- assetType: normalizeAssetType$1(
59071
- url.searchParams.get("asset_type") ?? url.searchParams.get("assetType") ?? url.searchParams.get("type")
59072
- ),
59073
- assetName: sanitizeDisplayName(url.searchParams.get("name")),
59074
- embedSearchParams: getEmbedSearchParams(url)
59055
+ assetType: normalizeAssetType(url.searchParams.get("asset_type") ?? url.searchParams.get("type"))
59075
59056
  };
59076
59057
  };
59077
59058
  const isAthenaCitationUrl = ({
@@ -59119,19 +59100,12 @@ const useAthenaLinkClickHandler = () => {
59119
59100
  const citationMetadata = citationLink ? {
59120
59101
  assetId: citationLink.assetId,
59121
59102
  assetIds: citationLink.assetIds,
59122
- assetType: citationLink.assetType,
59123
- assetName: citationLink.assetName,
59124
- embedSearchParams: citationLink.embedSearchParams
59103
+ assetType: citationLink.assetType
59125
59104
  } : null;
59126
59105
  const openInAssetPanel = citationLink ? () => {
59127
- const displayName = getCitationDisplayName({
59128
- assetName: citationLink.assetName,
59129
- linkText: trimmedLinkText
59130
- });
59131
59106
  openAsset(citationLink.assetId, {
59132
- name: displayName ?? void 0,
59133
- type: citationLink.assetType ?? void 0,
59134
- embedSearchParams: citationLink.embedSearchParams
59107
+ name: trimmedLinkText ?? void 0,
59108
+ type: citationLink.assetType ?? void 0
59135
59109
  });
59136
59110
  } : void 0;
59137
59111
  const context2 = {
@@ -63571,12 +63545,6 @@ function extractAssetId(result) {
63571
63545
  if (typeof id === "string" && id.startsWith("asset_")) return id;
63572
63546
  return null;
63573
63547
  }
63574
- function extractAssetTitle(result) {
63575
- const data = normalizeResult(result);
63576
- if (!data) return null;
63577
- const title = data.assetTitle ?? data.asset_title ?? data.title ?? data.name;
63578
- return typeof title === "string" && title.trim().length > 0 ? title.trim() : null;
63579
- }
63580
63548
  function resetAssetAutoOpen() {
63581
63549
  useAssetPanelStore.getState().resetAutoOpen();
63582
63550
  }
@@ -64296,7 +64264,6 @@ const OpenAssetToolUIImpl = ({
64296
64264
  const typedArgs = args;
64297
64265
  const argsAssetId = (typedArgs == null ? void 0 : typedArgs.asset_id) ?? (typedArgs == null ? void 0 : typedArgs.assetId) ?? "";
64298
64266
  const resultAssetId = extractAssetId(result);
64299
- const resultAssetTitle = extractAssetTitle(result);
64300
64267
  const assetId = resultAssetId ?? (argsAssetId.startsWith("asset_") ? argsAssetId : null);
64301
64268
  const isRunning = (status == null ? void 0 : status.type) === "running";
64302
64269
  const isComplete = (status == null ? void 0 : status.type) === "complete" || !status;
@@ -64308,10 +64275,10 @@ const OpenAssetToolUIImpl = ({
64308
64275
  if (isComplete && !isCancelled && assetId && !wasCompleteAtMount.current) {
64309
64276
  const store = useAssetPanelStore.getState();
64310
64277
  if (store.markAutoOpened(assetId)) {
64311
- store.openAsset(assetId, { name: resultAssetTitle ?? void 0 });
64278
+ store.openAsset(assetId);
64312
64279
  }
64313
64280
  }
64314
- }, [isComplete, isCancelled, assetId, resultAssetTitle]);
64281
+ }, [isComplete, isCancelled, assetId]);
64315
64282
  return /* @__PURE__ */ jsxRuntime.jsx(
64316
64283
  ToolCard,
64317
64284
  {
@@ -64327,7 +64294,7 @@ const OpenAssetToolUIImpl = ({
64327
64294
  "button",
64328
64295
  {
64329
64296
  type: "button",
64330
- onClick: () => openAsset(assetId, { name: resultAssetTitle ?? void 0 }),
64297
+ onClick: () => openAsset(assetId),
64331
64298
  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",
64332
64299
  children: [
64333
64300
  /* @__PURE__ */ jsxRuntime.jsx(ExternalLink, { className: "size-3" }),
@@ -65252,58 +65219,14 @@ const AthenaUserMessage = ({
65252
65219
  children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "aui-user-message-content wrap-break-word rounded-2xl bg-muted px-4 py-2.5 text-foreground", children: /* @__PURE__ */ jsxRuntime.jsx(MessagePrimitiveParts, { components: { Text: TextComponent } }) })
65253
65220
  }
65254
65221
  );
65255
- const EMBED_ASSET_TYPE_ALIASES = {
65256
- document: "document",
65257
- image: "document",
65258
- notebook: "notebook",
65259
- pdf: "document",
65260
- powerpoint_deck: "presentation",
65261
- presentation: "presentation",
65262
- puck_presentation: "presentation",
65263
- sheet: "spreadsheet",
65264
- spreadsheet: "spreadsheet",
65265
- super_document: "document"
65266
- };
65267
65222
  const embedCache = /* @__PURE__ */ new Map();
65268
- const normalizeAssetType = (value) => {
65269
- if (!value) {
65270
- return null;
65271
- }
65272
- const normalizedValue = value.trim().replace(/^athena\//, "").toLowerCase().replace(/-/g, "_");
65273
- return EMBED_ASSET_TYPE_ALIASES[normalizedValue] ?? null;
65274
- };
65275
- const appendEmbedSearchParams = ({
65276
- embedUrl,
65277
- embedSearchParams
65278
- }) => {
65279
- if (!embedSearchParams || Object.keys(embedSearchParams).length === 0) {
65280
- return embedUrl;
65281
- }
65282
- const url = new URL(embedUrl);
65283
- for (const [key, value] of Object.entries(embedSearchParams)) {
65284
- if (!value) {
65285
- continue;
65286
- }
65287
- url.searchParams.set(key, value);
65288
- }
65289
- return url.toString();
65290
- };
65291
65223
  function useAssetEmbed(assetId, options = {
65292
65224
  backendUrl: ""
65293
65225
  }) {
65294
- const {
65295
- readOnly = false,
65296
- expiresInSeconds = 60 * 60 * 24 * 30,
65297
- backendUrl,
65298
- apiKey,
65299
- token,
65300
- embedSearchParams
65301
- } = options;
65226
+ const { readOnly = false, expiresInSeconds = 60 * 60 * 24 * 30, backendUrl, apiKey, token } = options;
65302
65227
  const [embedUrl, setEmbedUrl] = React.useState(null);
65303
65228
  const [isLoading, setIsLoading] = React.useState(false);
65304
65229
  const [error2, setError] = React.useState(null);
65305
- const [assetTitle, setAssetTitle] = React.useState(null);
65306
- const [assetType, setAssetType] = React.useState(null);
65307
65230
  const abortRef = React.useRef(null);
65308
65231
  React.useEffect(() => {
65309
65232
  var _a2;
@@ -65311,18 +65234,14 @@ function useAssetEmbed(assetId, options = {
65311
65234
  setEmbedUrl(null);
65312
65235
  setIsLoading(false);
65313
65236
  setError(null);
65314
- setAssetTitle(null);
65315
- setAssetType(null);
65316
65237
  return;
65317
65238
  }
65318
- const cacheKey = `${assetId}:${readOnly}:${token ?? apiKey ?? "anon"}:${JSON.stringify(embedSearchParams ?? {})}`;
65239
+ const cacheKey = `${assetId}:${readOnly}:${token ?? apiKey ?? "anon"}`;
65319
65240
  const cached = embedCache.get(cacheKey);
65320
65241
  if (cached && cached.expiresAt > Date.now() / 1e3) {
65321
65242
  setEmbedUrl(cached.url);
65322
65243
  setIsLoading(false);
65323
65244
  setError(null);
65324
- setAssetTitle(cached.assetTitle);
65325
- setAssetType(cached.assetType);
65326
65245
  return;
65327
65246
  }
65328
65247
  const apiBaseUrl = backendUrl.replace(/\/api\/assistant-ui\/?$/, "");
@@ -65330,14 +65249,11 @@ function useAssetEmbed(assetId, options = {
65330
65249
  (_a2 = abortRef.current) == null ? void 0 : _a2.abort();
65331
65250
  const controller = new AbortController();
65332
65251
  abortRef.current = controller;
65333
- setEmbedUrl(null);
65334
65252
  setIsLoading(true);
65335
65253
  setError(null);
65336
- setAssetTitle(null);
65337
- setAssetType(null);
65338
65254
  const headers = { "Content-Type": "application/json" };
65339
65255
  if (token) {
65340
- headers.Authorization = `Bearer ${token}`;
65256
+ headers["Authorization"] = `Bearer ${token}`;
65341
65257
  } else if (apiKey) {
65342
65258
  headers["X-API-KEY"] = apiKey;
65343
65259
  }
@@ -65357,31 +65273,17 @@ function useAssetEmbed(assetId, options = {
65357
65273
  }
65358
65274
  return res.json();
65359
65275
  }).then((data) => {
65360
- const resolvedAssetType = normalizeAssetType(data.athena_converted_type) ?? normalizeAssetType(data.athena_original_type);
65361
- const resolvedEmbedUrl = appendEmbedSearchParams({
65362
- embedUrl: data.embed_url,
65363
- embedSearchParams
65364
- });
65365
- embedCache.set(cacheKey, {
65366
- url: resolvedEmbedUrl,
65367
- expiresAt: data.expires_at,
65368
- assetTitle: data.title ?? null,
65369
- assetType: resolvedAssetType
65370
- });
65371
- setEmbedUrl(resolvedEmbedUrl);
65372
- setAssetTitle(data.title ?? null);
65373
- setAssetType(resolvedAssetType);
65276
+ embedCache.set(`${assetId}:${readOnly}:${token ?? apiKey ?? "anon"}`, { url: data.embed_url, expiresAt: data.expires_at });
65277
+ setEmbedUrl(data.embed_url);
65374
65278
  setIsLoading(false);
65375
65279
  }).catch((err) => {
65376
- if (err.name === "AbortError") {
65377
- return;
65378
- }
65280
+ if (err.name === "AbortError") return;
65379
65281
  setError(err.message);
65380
65282
  setIsLoading(false);
65381
65283
  });
65382
65284
  return () => controller.abort();
65383
- }, [assetId, readOnly, expiresInSeconds, backendUrl, apiKey, token, embedSearchParams]);
65384
- return { embedUrl, isLoading, error: error2, assetTitle, assetType };
65285
+ }, [assetId, readOnly, expiresInSeconds, backendUrl, apiKey, token]);
65286
+ return { embedUrl, isLoading, error: error2 };
65385
65287
  }
65386
65288
  const ASSET_TYPE_CONFIG = {
65387
65289
  presentation: { icon: Presentation, label: "Presentation" },
@@ -65391,28 +65293,13 @@ const ASSET_TYPE_CONFIG = {
65391
65293
  unknown: { icon: File$1, label: "Asset" }
65392
65294
  };
65393
65295
  const AssetIframe = React.memo(
65394
- ({ tabId, tabName, tabType, embedSearchParams }) => {
65296
+ ({ tabId, tabName }) => {
65395
65297
  const { backendUrl, apiKey, token } = useAthenaConfig();
65396
- const { embedUrl, isLoading, error: error2, assetTitle, assetType } = useAssetEmbed(tabId, {
65298
+ const { embedUrl, isLoading, error: error2 } = useAssetEmbed(tabId, {
65397
65299
  backendUrl,
65398
65300
  apiKey,
65399
- token,
65400
- embedSearchParams
65301
+ token
65401
65302
  });
65402
- React.useEffect(() => {
65403
- if (!assetTitle && !assetType) {
65404
- return;
65405
- }
65406
- const nextName = assetTitle ?? tabName;
65407
- const nextType = assetType ?? tabType;
65408
- if (nextName === tabName && nextType === tabType) {
65409
- return;
65410
- }
65411
- useAssetPanelStore.getState().openAsset(tabId, {
65412
- name: nextName ?? void 0,
65413
- type: nextType
65414
- });
65415
- }, [assetTitle, assetType, tabId, tabName, tabType]);
65416
65303
  if (isLoading) {
65417
65304
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex h-full items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-center", children: [
65418
65305
  /* @__PURE__ */ jsxRuntime.jsx(LoaderCircle, { className: "mx-auto size-6 animate-spin text-muted-foreground" }),
@@ -65497,15 +65384,7 @@ const PanelContent = ({
65497
65384
  }
65498
65385
  )
65499
65386
  ] }),
65500
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx(
65501
- AssetIframe,
65502
- {
65503
- tabId: tab.id,
65504
- tabName: tab.name,
65505
- tabType: tab.type,
65506
- embedSearchParams: tab.embedSearchParams
65507
- }
65508
- ) })
65387
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx(AssetIframe, { tabId: tab.id, tabName: tab.name }) })
65509
65388
  ]
65510
65389
  },
65511
65390
  tab.id
@@ -65515,15 +65394,7 @@ const PanelContent = ({
65515
65394
  "div",
65516
65395
  {
65517
65396
  className: isActive2 ? "h-full w-full" : "hidden",
65518
- children: /* @__PURE__ */ jsxRuntime.jsx(
65519
- AssetIframe,
65520
- {
65521
- tabId: tab.id,
65522
- tabName: tab.name,
65523
- tabType: tab.type,
65524
- embedSearchParams: tab.embedSearchParams
65525
- }
65526
- )
65397
+ children: /* @__PURE__ */ jsxRuntime.jsx(AssetIframe, { tabId: tab.id, tabName: tab.name })
65527
65398
  },
65528
65399
  tab.id
65529
65400
  );