@athenaintel/react 0.10.2 → 0.10.4

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
@@ -1399,8 +1399,8 @@ const createStoreImpl = (createState) => {
1399
1399
  return api;
1400
1400
  };
1401
1401
  const createStore = ((createState) => createState ? createStoreImpl(createState) : createStoreImpl);
1402
- const identity = (arg) => arg;
1403
- function useStore$1(api, selector = identity) {
1402
+ const identity$1 = (arg) => arg;
1403
+ function useStore$1(api, selector = identity$1) {
1404
1404
  const slice2 = React.useSyncExternalStore(
1405
1405
  api.subscribe,
1406
1406
  React.useCallback(() => selector(api.getState()), [api, selector]),
@@ -9610,6 +9610,72 @@ const AssistantRuntimeProviderImpl = ({ children, aui, runtime }) => {
9610
9610
  return jsxRuntime.jsxs(AssistantProviderBase, { runtime, aui: aui ?? null, children: [jsxRuntime.jsx(DevToolsRegistration, {}), jsxRuntime.jsx(ThreadPrimitiveViewportProvider, { children })] });
9611
9611
  };
9612
9612
  const AssistantRuntimeProvider = React.memo(AssistantRuntimeProviderImpl);
9613
+ const debugVerifyPrototype = (runtime, prototype) => {
9614
+ const unboundMethods = Object.getOwnPropertyNames(prototype).filter((methodStr) => {
9615
+ const descriptor = Object.getOwnPropertyDescriptor(prototype, methodStr);
9616
+ const isMethod = descriptor && typeof descriptor.value === "function";
9617
+ if (!isMethod)
9618
+ return false;
9619
+ const methodName = methodStr;
9620
+ return isMethod && !methodName.startsWith("_") && methodName !== "constructor" && prototype[methodName] === runtime[methodName];
9621
+ });
9622
+ if (unboundMethods.length > 0) {
9623
+ throw new Error(`The following methods are not bound: ${JSON.stringify(unboundMethods)}`);
9624
+ }
9625
+ const prototypePrototype = Object.getPrototypeOf(prototype);
9626
+ if (prototypePrototype && prototypePrototype !== Object.prototype) {
9627
+ debugVerifyPrototype(runtime, prototypePrototype);
9628
+ }
9629
+ };
9630
+ const ensureBinding = (r2) => {
9631
+ var _a2;
9632
+ const runtime = r2;
9633
+ if (runtime.__isBound)
9634
+ return;
9635
+ (_a2 = runtime.__internal_bindMethods) == null ? void 0 : _a2.call(runtime);
9636
+ runtime.__isBound = true;
9637
+ if (process.env.NODE_ENV !== "production") {
9638
+ debugVerifyPrototype(runtime, Object.getPrototypeOf(runtime));
9639
+ }
9640
+ };
9641
+ function useRuntimeStateInternal(runtime, selector = identity) {
9642
+ ensureBinding(runtime);
9643
+ const slice2 = React.useSyncExternalStore(runtime.subscribe, () => selector(runtime.getState()), () => selector(runtime.getState()));
9644
+ React.useDebugValue(slice2);
9645
+ return slice2;
9646
+ }
9647
+ const identity = (arg) => arg;
9648
+ function createStateHookForRuntime(useRuntime) {
9649
+ function useStoreHook(param) {
9650
+ let optional = false;
9651
+ let selector;
9652
+ if (typeof param === "function") {
9653
+ selector = param;
9654
+ } else if (param) {
9655
+ optional = !!param.optional;
9656
+ selector = param.selector;
9657
+ }
9658
+ const store = useRuntime({ optional });
9659
+ if (!store)
9660
+ return null;
9661
+ return useRuntimeStateInternal(store, selector);
9662
+ }
9663
+ return useStoreHook;
9664
+ }
9665
+ function useAssistantRuntime(options) {
9666
+ var _a2, _b;
9667
+ const aui = useAui();
9668
+ const runtime = ((_b = (_a2 = aui.threads()).__internal_getAssistantRuntime) == null ? void 0 : _b.call(_a2)) ?? null;
9669
+ if (!runtime && !(options == null ? void 0 : options.optional)) {
9670
+ throw new Error("AssistantRuntime is not available");
9671
+ }
9672
+ return runtime;
9673
+ }
9674
+ const useThreadListRuntime = (opt) => {
9675
+ var _a2;
9676
+ return ((_a2 = useAssistantRuntime(opt)) == null ? void 0 : _a2.threads) ?? null;
9677
+ };
9678
+ const useThreadList = createStateHookForRuntime(useThreadListRuntime);
9613
9679
  function useComposerRuntime(options) {
9614
9680
  const aui = useAui();
9615
9681
  const runtime = useAuiState(() => {
@@ -9621,6 +9687,18 @@ function useComposerRuntime(options) {
9621
9687
  }
9622
9688
  return runtime;
9623
9689
  }
9690
+ function useThreadRuntime(options) {
9691
+ const aui = useAui();
9692
+ const runtime = useAuiState(() => {
9693
+ var _a2, _b;
9694
+ return aui.thread.source ? ((_b = (_a2 = aui.thread()).__internal_getRuntime) == null ? void 0 : _b.call(_a2)) ?? null : null;
9695
+ });
9696
+ if (!runtime && !(options == null ? void 0 : options.optional)) {
9697
+ throw new Error("ThreadRuntime is not available");
9698
+ }
9699
+ return runtime;
9700
+ }
9701
+ const useThread = createStateHookForRuntime(useThreadRuntime);
9624
9702
  function setRef(ref, value) {
9625
9703
  if (typeof ref === "function") {
9626
9704
  return ref(value);
@@ -24996,6 +25074,7 @@ function AthenaWithThreadList({
24996
25074
  linkClicks,
24997
25075
  citationLinks
24998
25076
  }) {
25077
+ var _a2;
24999
25078
  const adapter = useAthenaThreadListAdapter({
25000
25079
  backendUrl,
25001
25080
  apiKey,
@@ -25038,15 +25117,17 @@ function AthenaWithThreadList({
25038
25117
  adapter
25039
25118
  });
25040
25119
  const handleRefresh = React.useCallback(() => {
25041
- var _a2;
25042
- const core = (_a2 = runtime == null ? void 0 : runtime._core) == null ? void 0 : _a2.threads;
25120
+ var _a3;
25121
+ const core = (_a3 = runtime == null ? void 0 : runtime._core) == null ? void 0 : _a3.threads;
25043
25122
  if (core) {
25044
25123
  core._loadThreadsPromise = void 0;
25045
25124
  core.__internal_load();
25046
25125
  }
25047
25126
  }, [runtime]);
25048
25127
  const previousAuthRefreshKeyRef = React.useRef(null);
25049
- const authRefreshKey = `${backendUrl}::${apiKey ?? ""}::${token ?? ""}`;
25128
+ const authContext = React.useContext(AthenaAuthContext.AthenaAuthContext);
25129
+ const authUserId = ((_a2 = authContext == null ? void 0 : authContext.user) == null ? void 0 : _a2.userId) ?? "";
25130
+ const authRefreshKey = `${backendUrl}::${apiKey ?? ""}::${authUserId}`;
25050
25131
  React.useEffect(() => {
25051
25132
  const previousAuthRefreshKey = previousAuthRefreshKeyRef.current;
25052
25133
  previousAuthRefreshKeyRef.current = authRefreshKey;
@@ -64865,11 +64946,24 @@ function highlightSql(code2) {
64865
64946
  i += str.length;
64866
64947
  continue;
64867
64948
  }
64949
+ if (code2.slice(i, i + 2) === "/*") {
64950
+ const end = code2.indexOf("*/", i + 2);
64951
+ const str = end >= 0 ? code2.slice(i, end + 2) : code2.slice(i);
64952
+ result += `<span style="color:var(--aui-syn-comment, #6a9955)">${escapeHtml(str)}</span>`;
64953
+ i += str.length;
64954
+ continue;
64955
+ }
64868
64956
  if (code2[i] === "'" || code2[i] === '"') {
64869
64957
  const q = code2[i];
64870
64958
  let j = i + 1;
64871
- while (j < code2.length && code2[j] !== q) {
64872
- if (code2[j] === "\\") j++;
64959
+ while (j < code2.length) {
64960
+ if (code2[j] === q) {
64961
+ if (j + 1 < code2.length && code2[j + 1] === q) {
64962
+ j += 2;
64963
+ continue;
64964
+ }
64965
+ break;
64966
+ }
64873
64967
  j++;
64874
64968
  }
64875
64969
  const str = code2.slice(i, j + 1);
@@ -65018,9 +65112,11 @@ const RunSqlToolUIImpl = ({
65018
65112
  i
65019
65113
  )) })
65020
65114
  ] }) }),
65021
- parsed.rows.length > 50 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "border-t border-border/30 px-4 py-1.5 text-[10px] text-muted-foreground", children: [
65022
- "Showing first 50 of ",
65023
- parsed.rows.length,
65115
+ (parsed.rows.length > 50 || parsed.rowCount !== null && parsed.rowCount > parsed.rows.length) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "border-t border-border/30 px-4 py-1.5 text-[10px] text-muted-foreground", children: [
65116
+ "Showing first ",
65117
+ Math.min(50, parsed.rows.length),
65118
+ " of ",
65119
+ parsed.rowCount ?? parsed.rows.length,
65024
65120
  " rows"
65025
65121
  ] })
65026
65122
  ] }),
@@ -66529,6 +66625,21 @@ function ThreadListItem() {
66529
66625
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex-1 truncate text-left", children: /* @__PURE__ */ jsxRuntime.jsx(ThreadListItemPrimitiveTitle, { fallback: "Untitled" }) })
66530
66626
  ] }) });
66531
66627
  }
66628
+ function useAthenaThreadManager() {
66629
+ const runtime = useAssistantRuntime({ optional: true });
66630
+ const threadId = useThread({ optional: true, selector: (s) => s.threadId });
66631
+ const threadList = useThreadList({ optional: true });
66632
+ if (!runtime || !threadList) {
66633
+ return null;
66634
+ }
66635
+ return {
66636
+ activeThreadId: threadId ?? null,
66637
+ threadIds: threadList.threadIds,
66638
+ isLoading: threadList.isLoading,
66639
+ switchToThread: (id) => runtime.threads.switchToThread(id),
66640
+ switchToNewThread: () => runtime.threads.switchToNewThread()
66641
+ };
66642
+ }
66532
66643
  function useAppendToComposer() {
66533
66644
  const aui = useAui();
66534
66645
  return React.useCallback(
@@ -66706,6 +66817,7 @@ exports.useAthenaCitationLinkHandler = useAthenaCitationLinkHandler;
66706
66817
  exports.useAthenaConfig = useAthenaConfig;
66707
66818
  exports.useAthenaLinkClickHandler = useAthenaLinkClickHandler;
66708
66819
  exports.useAthenaRuntime = useAthenaRuntime;
66820
+ exports.useAthenaThreadManager = useAthenaThreadManager;
66709
66821
  exports.useComposerAttachment = useComposerAttachment;
66710
66822
  exports.useFileUpload = useFileUpload;
66711
66823
  exports.useMentionSuggestions = useMentionSuggestions;