@athenaintel/react 0.9.21 → 0.9.22

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
@@ -1,6 +1,27 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
3
8
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __copyProps = (to, from2, except, desc) => {
10
+ if (from2 && typeof from2 === "object" || typeof from2 === "function") {
11
+ for (let key of __getOwnPropNames(from2))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from2[key], enumerable: !(desc = __getOwnPropDesc(from2, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
18
+ // If the importer is in node compatibility mode or this is not an ESM
19
+ // file that has been converted to a CommonJS file using a Babel-
20
+ // compatible transform (i.e. "__esModule" has not been set), then set
21
+ // "default" to the CommonJS "module.exports" for node compatibility.
22
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
23
+ mod
24
+ ));
4
25
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
26
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
6
27
  const jsxRuntime = require("react/jsx-runtime");
@@ -16198,7 +16219,7 @@ const useComposerSend = () => {
16198
16219
  return null;
16199
16220
  return send;
16200
16221
  };
16201
- const ComposerPrimitiveSend = createActionButton("ComposerPrimitive.Send", useComposerSend);
16222
+ createActionButton("ComposerPrimitive.Send", useComposerSend);
16202
16223
  const ComposerPrimitiveRoot = React.forwardRef(({ onSubmit, ...rest }, forwardedRef) => {
16203
16224
  const send = useComposerSend();
16204
16225
  const handleSubmit = (e) => {
@@ -24803,6 +24824,53 @@ const themes = {
24803
24824
  radius: "0.625rem"
24804
24825
  }
24805
24826
  };
24827
+ let posthogInstance = null;
24828
+ let initPromise = null;
24829
+ const DEFAULT_HOST = "https://us.i.posthog.com";
24830
+ async function initializePostHog(apiKey, host, debug) {
24831
+ if (posthogInstance) return posthogInstance;
24832
+ if (typeof window === "undefined") return null;
24833
+ try {
24834
+ const posthog = (await import("posthog-js")).default;
24835
+ posthog.init(apiKey, {
24836
+ api_host: host,
24837
+ autocapture: true,
24838
+ capture_pageview: false,
24839
+ session_recording: {
24840
+ recordCrossOriginIframes: true,
24841
+ maskAllInputs: true
24842
+ },
24843
+ loaded: (ph) => {
24844
+ if (debug) {
24845
+ ph.debug(true);
24846
+ }
24847
+ }
24848
+ });
24849
+ posthogInstance = posthog;
24850
+ return posthog;
24851
+ } catch {
24852
+ initPromise = null;
24853
+ return null;
24854
+ }
24855
+ }
24856
+ function getPostHogInstance() {
24857
+ return posthogInstance;
24858
+ }
24859
+ function PostHogProvider({
24860
+ children,
24861
+ config: config2
24862
+ }) {
24863
+ const apiKey = (config2 == null ? void 0 : config2.apiKey) ?? "";
24864
+ const host = (config2 == null ? void 0 : config2.host) ?? DEFAULT_HOST;
24865
+ const debug = (config2 == null ? void 0 : config2.debug) ?? false;
24866
+ React.useEffect(() => {
24867
+ if (!apiKey || typeof window === "undefined") return;
24868
+ if (!initPromise) {
24869
+ initPromise = initializePostHog(apiKey, host, debug);
24870
+ }
24871
+ }, [apiKey, host, debug]);
24872
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
24873
+ }
24806
24874
  const resolveTokenOverride = ({
24807
24875
  config: config2,
24808
24876
  token
@@ -25009,7 +25077,8 @@ function AthenaProvider({
25009
25077
  enableThreadList = false,
25010
25078
  theme,
25011
25079
  linkClicks,
25012
- citationLinks
25080
+ citationLinks,
25081
+ posthog: posthogProp
25013
25082
  }) {
25014
25083
  const frontendToolNames = React.useMemo(() => Object.keys(frontendTools), [frontendTools]);
25015
25084
  const themeStyleVars = React.useMemo(() => theme ? themeToStyleVars(theme) : void 0, [theme]);
@@ -25024,6 +25093,7 @@ function AthenaProvider({
25024
25093
  const configuredBackendUrl = (config2 == null ? void 0 : config2.backendUrl) ?? backendUrl;
25025
25094
  const configuredAppUrl = (config2 == null ? void 0 : config2.appUrl) ?? appUrl;
25026
25095
  const configuredTrustedParentOrigins = config2 == null ? void 0 : config2.trustedParentOrigins;
25096
+ const posthogConfig = (config2 == null ? void 0 : config2.posthog) ?? posthogProp;
25027
25097
  const bridge = useParentBridge({
25028
25098
  trustedOrigins: configuredTrustedParentOrigins
25029
25099
  });
@@ -25083,10 +25153,11 @@ function AthenaProvider({
25083
25153
  }
25084
25154
  );
25085
25155
  }
25156
+ let result = /* @__PURE__ */ jsxRuntime.jsx(PostHogProvider, { config: posthogConfig, children: inner });
25086
25157
  if (themeStyleVars) {
25087
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "athena-themed", style: themeStyleVars, children: inner });
25158
+ result = /* @__PURE__ */ jsxRuntime.jsx("div", { className: "athena-themed", style: themeStyleVars, children: result });
25088
25159
  }
25089
- return inner;
25160
+ return result;
25090
25161
  }
25091
25162
  function OrderedMap(content) {
25092
25163
  this.content = content;
@@ -59314,14 +59385,30 @@ var index_default$1 = Placeholder;
59314
59385
  const EditorCtx = React.createContext(null);
59315
59386
  function ComposerEditorProvider({ children }) {
59316
59387
  const ref = React.useRef(null);
59317
- return /* @__PURE__ */ jsxRuntime.jsx(EditorCtx.Provider, { value: ref, children });
59388
+ const [editorEmpty, setEditorEmpty] = React.useState(true);
59389
+ const value = { editorRef: ref, editorEmpty, setEditorEmpty };
59390
+ return /* @__PURE__ */ jsxRuntime.jsx(EditorCtx.Provider, { value, children });
59318
59391
  }
59319
59392
  function useComposerEditorRef() {
59320
59393
  const ctx = React.useContext(EditorCtx);
59321
59394
  if (!ctx) {
59322
59395
  throw new Error("[AthenaSDK] useComposerEditorRef must be used within <ComposerEditorProvider>");
59323
59396
  }
59324
- return ctx;
59397
+ return ctx.editorRef;
59398
+ }
59399
+ function useComposerEditorEmpty() {
59400
+ const ctx = React.useContext(EditorCtx);
59401
+ if (!ctx) {
59402
+ throw new Error("[AthenaSDK] useComposerEditorEmpty must be used within <ComposerEditorProvider>");
59403
+ }
59404
+ return ctx.editorEmpty;
59405
+ }
59406
+ function useSetComposerEditorEmpty() {
59407
+ const ctx = React.useContext(EditorCtx);
59408
+ if (!ctx) {
59409
+ throw new Error("[AthenaSDK] useSetComposerEditorEmpty must be used within <ComposerEditorProvider>");
59410
+ }
59411
+ return ctx.setEditorEmpty;
59325
59412
  }
59326
59413
  const isMentionPopupActive = (editor) => {
59327
59414
  var _a2, _b;
@@ -61474,6 +61561,7 @@ const TiptapComposer = ({ tools = [] }) => {
61474
61561
  const composerRuntime = useComposerRuntime();
61475
61562
  const editorRef = React.useRef(null);
61476
61563
  const composerEditorRef = useComposerEditorRef();
61564
+ const setEditorEmpty = useSetComposerEditorEmpty();
61477
61565
  const mentionStore = useMentionSuggestions(tools);
61478
61566
  const { attachments, clearAttachments, isUploading } = useAttachments();
61479
61567
  const { quote, clearQuote } = useQuote();
@@ -61519,6 +61607,9 @@ const TiptapComposer = ({ tools = [] }) => {
61519
61607
  handleSubmitRef.current = handleSubmit;
61520
61608
  const editor = useEditor({
61521
61609
  immediatelyRender: true,
61610
+ onUpdate: ({ editor: e }) => {
61611
+ setEditorEmpty(e.isEmpty);
61612
+ },
61522
61613
  extensions: [
61523
61614
  index_default$2.configure({
61524
61615
  codeBlock: {
@@ -65082,10 +65173,12 @@ const ComposerAction = () => /* @__PURE__ */ jsxRuntime.jsxs("div", { className:
65082
65173
  ] });
65083
65174
  const ComposerSendWithQuote = () => {
65084
65175
  const aui = useAui();
65176
+ const composerRuntime = useComposerRuntime();
65085
65177
  const { appUrl } = useAthenaConfig();
65086
65178
  const { quote, clearQuote } = useQuote();
65087
65179
  const { attachments, clearAttachments, isUploading } = useAttachments();
65088
65180
  const editorRef = useComposerEditorRef();
65181
+ const editorEmpty = useComposerEditorEmpty();
65089
65182
  const hasExtras = !!quote || attachments.length > 0;
65090
65183
  const handleSend = React.useCallback(() => {
65091
65184
  var _a2;
@@ -65093,51 +65186,42 @@ const ComposerSendWithQuote = () => {
65093
65186
  const editor = editorRef.current;
65094
65187
  if (!editor && !quote && attachments.length === 0) return;
65095
65188
  const userText = ((_a2 = editor == null ? void 0 : editor.getMarkdown()) == null ? void 0 : _a2.trim()) ?? "";
65096
- const fullMessage = buildComposedMessage({
65097
- attachments,
65098
- quote,
65099
- userText,
65100
- appUrl
65101
- });
65102
- if (!fullMessage) return;
65103
- aui.thread().append({
65104
- role: "user",
65105
- content: [{ type: "text", text: fullMessage }]
65106
- });
65189
+ if (hasExtras) {
65190
+ const fullMessage = buildComposedMessage({
65191
+ attachments,
65192
+ quote,
65193
+ userText,
65194
+ appUrl
65195
+ });
65196
+ if (!fullMessage) return;
65197
+ aui.thread().append({
65198
+ role: "user",
65199
+ content: [{ type: "text", text: fullMessage }]
65200
+ });
65201
+ clearQuote();
65202
+ clearAttachments();
65203
+ } else {
65204
+ if (!userText) return;
65205
+ composerRuntime.setText(userText);
65206
+ composerRuntime.send();
65207
+ }
65107
65208
  editor == null ? void 0 : editor.clear();
65108
- clearQuote();
65109
- clearAttachments();
65110
- }, [aui, quote, attachments, isUploading, clearQuote, clearAttachments, editorRef, appUrl]);
65111
- if (hasExtras) {
65112
- return /* @__PURE__ */ jsxRuntime.jsx(
65113
- TooltipIconButton,
65114
- {
65115
- tooltip: isUploading ? "Upload in progress..." : "Send message",
65116
- side: "bottom",
65117
- type: "button",
65118
- variant: "default",
65119
- size: "icon",
65120
- className: "aui-composer-send size-8 rounded-full",
65121
- "aria-label": "Send message",
65122
- onClick: handleSend,
65123
- disabled: isUploading,
65124
- children: /* @__PURE__ */ jsxRuntime.jsx(ArrowUp, { className: "aui-composer-send-icon size-4" })
65125
- }
65126
- );
65127
- }
65128
- return /* @__PURE__ */ jsxRuntime.jsx(ComposerPrimitiveSend, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
65209
+ }, [aui, composerRuntime, quote, attachments, hasExtras, isUploading, clearQuote, clearAttachments, editorRef, appUrl]);
65210
+ return /* @__PURE__ */ jsxRuntime.jsx(
65129
65211
  TooltipIconButton,
65130
65212
  {
65131
- tooltip: "Send message",
65213
+ tooltip: isUploading ? "Upload in progress..." : "Send message",
65132
65214
  side: "bottom",
65133
- type: "submit",
65215
+ type: "button",
65134
65216
  variant: "default",
65135
65217
  size: "icon",
65136
65218
  className: "aui-composer-send size-8 rounded-full",
65137
65219
  "aria-label": "Send message",
65220
+ onClick: handleSend,
65221
+ disabled: isUploading || editorEmpty && !hasExtras,
65138
65222
  children: /* @__PURE__ */ jsxRuntime.jsx(ArrowUp, { className: "aui-composer-send-icon size-4" })
65139
65223
  }
65140
- ) });
65224
+ );
65141
65225
  };
65142
65226
  const MessageError = () => /* @__PURE__ */ jsxRuntime.jsx(MessagePrimitiveError, { children: /* @__PURE__ */ jsxRuntime.jsxs(ErrorPrimitiveRoot, { className: "aui-message-error-root mt-2 flex items-start gap-2 rounded-md border border-destructive bg-destructive/10 p-3 text-destructive text-sm dark:bg-destructive/5 dark:text-red-200", children: [
65143
65227
  /* @__PURE__ */ jsxRuntime.jsx(CircleAlert, { className: "mt-0.5 size-4 shrink-0" }),
@@ -65850,6 +65934,7 @@ exports.cn = cn;
65850
65934
  exports.createAssetToolUI = createAssetToolUI;
65851
65935
  exports.formatToolName = formatToolName;
65852
65936
  exports.getAssetInfo = getAssetInfo;
65937
+ exports.getPostHogInstance = getPostHogInstance;
65853
65938
  exports.isAthenaCitationUrl = isAthenaCitationUrl;
65854
65939
  exports.normalizeResult = normalizeResult;
65855
65940
  exports.parseAthenaCitationLink = parseAthenaCitationLink;