@athenaintel/react 0.9.20 → 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.d.ts CHANGED
@@ -7,8 +7,10 @@ import { EmptyMessagePartComponent } from '@assistant-ui/react';
7
7
  import { FC } from 'react';
8
8
  import { ForwardRefExoticComponent } from 'react';
9
9
  import { JSX } from 'react/jsx-runtime';
10
+ import { JSXElementConstructor } from 'react';
10
11
  import { PersistOptions } from 'zustand/middleware';
11
12
  import * as React_2 from 'react';
13
+ import { ReactElement } from 'react';
12
14
  import { ReactNode } from 'react';
13
15
  import { ReasoningMessagePartComponent } from '@assistant-ui/react';
14
16
  import { ReasoningMessagePartProps } from '@assistant-ui/react';
@@ -243,7 +245,7 @@ export declare interface AthenaOrg {
243
245
  urlSafeOrgName: string;
244
246
  }
245
247
 
246
- export declare function AthenaProvider({ children, config, apiKey, token: tokenProp, agent, model, tools, frontendTools, apiUrl, backendUrl, appUrl, environment, workbench, knowledgeBase, systemPrompt, threadId: threadIdProp, enableThreadList, theme, linkClicks, citationLinks, }: AthenaProviderProps): JSX.Element | null;
248
+ export declare function AthenaProvider({ children, config, apiKey, token: tokenProp, agent, model, tools, frontendTools, apiUrl, backendUrl, appUrl, environment, workbench, knowledgeBase, systemPrompt, threadId: threadIdProp, enableThreadList, theme, linkClicks, citationLinks, posthog: posthogProp, }: AthenaProviderProps): ReactElement<unknown, string | JSXElementConstructor<any>> | null;
247
249
 
248
250
  export declare interface AthenaProviderConfig {
249
251
  /** API key for standalone authentication when no token is provided. */
@@ -260,6 +262,8 @@ export declare interface AthenaProviderConfig {
260
262
  trustedParentOrigins?: string[];
261
263
  /** Athena environment preset used when URLs are not explicitly provided. */
262
264
  environment?: AthenaEnvironment;
265
+ /** PostHog analytics configuration. When omitted or keys are missing, PostHog is disabled. */
266
+ posthog?: PostHogConfig;
263
267
  }
264
268
 
265
269
  export declare interface AthenaProviderProps {
@@ -315,6 +319,9 @@ export declare interface AthenaProviderProps {
315
319
  linkClicks?: AthenaLinkClickOptions;
316
320
  /** @deprecated Prefer `linkClicks`. Customize how Athena citation links rendered in chat messages behave. */
317
321
  citationLinks?: AthenaCitationLinkOptions;
322
+ /** PostHog analytics configuration. When omitted or keys are missing, PostHog is silently disabled.
323
+ * Prefer `config.posthog` for structured configuration. */
324
+ posthog?: PostHogConfig;
318
325
  }
319
326
 
320
327
  export declare const AthenaReasoningPart: FC<AthenaReasoningPartProps>;
@@ -591,6 +598,8 @@ export declare function getAssetInfo(assetId: string): {
591
598
  icon: AssetIconType;
592
599
  };
593
600
 
601
+ export declare function getPostHogInstance<TClient = unknown>(): TClient | null;
602
+
594
603
  export declare const isAthenaCitationUrl: ({ href, appUrl, }: {
595
604
  href: string;
596
605
  appUrl?: string | null;
@@ -670,6 +679,15 @@ export declare interface ParsedAthenaCitationLink {
670
679
  assetType: AssetType | null;
671
680
  }
672
681
 
682
+ export declare interface PostHogConfig {
683
+ /** PostHog API key. When falsy, PostHog is disabled and the provider is a no-op. */
684
+ apiKey?: string;
685
+ /** PostHog ingestion host. Defaults to 'https://us.i.posthog.com'. */
686
+ host?: string;
687
+ /** Enable debug mode (logs PostHog internals to the console). */
688
+ debug?: boolean;
689
+ }
690
+
673
691
  declare interface QuoteContextValue {
674
692
  quote: QuoteData | null;
675
693
  setQuote: (quote: QuoteData | null) => void;
package/dist/index.js CHANGED
@@ -16180,7 +16180,7 @@ const useComposerSend = () => {
16180
16180
  return null;
16181
16181
  return send;
16182
16182
  };
16183
- const ComposerPrimitiveSend = createActionButton("ComposerPrimitive.Send", useComposerSend);
16183
+ createActionButton("ComposerPrimitive.Send", useComposerSend);
16184
16184
  const ComposerPrimitiveRoot = forwardRef(({ onSubmit, ...rest }, forwardedRef) => {
16185
16185
  const send = useComposerSend();
16186
16186
  const handleSubmit = (e) => {
@@ -16582,6 +16582,7 @@ function isTrustedOrigin({
16582
16582
  }
16583
16583
  }
16584
16584
  const BRIDGE_TIMEOUT_MS = 2e3;
16585
+ const EMPTY_TRUSTED_ORIGINS = [];
16585
16586
  const normalizeOrigin = (value) => {
16586
16587
  try {
16587
16588
  return new URL(value).origin;
@@ -16590,17 +16591,13 @@ const normalizeOrigin = (value) => {
16590
16591
  }
16591
16592
  };
16592
16593
  function useParentBridge({
16593
- trustedOrigins = []
16594
+ trustedOrigins = EMPTY_TRUSTED_ORIGINS
16594
16595
  } = {}) {
16595
16596
  const isInIframe = typeof window !== "undefined" && window.parent !== window;
16596
16597
  const runtimeTrustedOrigins = useMemo(() => {
16597
16598
  const origins = /* @__PURE__ */ new Set();
16598
16599
  if (typeof window !== "undefined") {
16599
16600
  origins.add(window.location.origin);
16600
- const referrerOrigin = normalizeOrigin(document.referrer);
16601
- if (referrerOrigin) {
16602
- origins.add(referrerOrigin);
16603
- }
16604
16601
  }
16605
16602
  for (const trustedOrigin of trustedOrigins) {
16606
16603
  const normalizedOrigin = normalizeOrigin(trustedOrigin);
@@ -24788,6 +24785,53 @@ const themes = {
24788
24785
  radius: "0.625rem"
24789
24786
  }
24790
24787
  };
24788
+ let posthogInstance = null;
24789
+ let initPromise = null;
24790
+ const DEFAULT_HOST = "https://us.i.posthog.com";
24791
+ async function initializePostHog(apiKey, host, debug) {
24792
+ if (posthogInstance) return posthogInstance;
24793
+ if (typeof window === "undefined") return null;
24794
+ try {
24795
+ const posthog = (await import("posthog-js")).default;
24796
+ posthog.init(apiKey, {
24797
+ api_host: host,
24798
+ autocapture: true,
24799
+ capture_pageview: false,
24800
+ session_recording: {
24801
+ recordCrossOriginIframes: true,
24802
+ maskAllInputs: true
24803
+ },
24804
+ loaded: (ph) => {
24805
+ if (debug) {
24806
+ ph.debug(true);
24807
+ }
24808
+ }
24809
+ });
24810
+ posthogInstance = posthog;
24811
+ return posthog;
24812
+ } catch {
24813
+ initPromise = null;
24814
+ return null;
24815
+ }
24816
+ }
24817
+ function getPostHogInstance() {
24818
+ return posthogInstance;
24819
+ }
24820
+ function PostHogProvider({
24821
+ children,
24822
+ config: config2
24823
+ }) {
24824
+ const apiKey = (config2 == null ? void 0 : config2.apiKey) ?? "";
24825
+ const host = (config2 == null ? void 0 : config2.host) ?? DEFAULT_HOST;
24826
+ const debug = (config2 == null ? void 0 : config2.debug) ?? false;
24827
+ useEffect(() => {
24828
+ if (!apiKey || typeof window === "undefined") return;
24829
+ if (!initPromise) {
24830
+ initPromise = initializePostHog(apiKey, host, debug);
24831
+ }
24832
+ }, [apiKey, host, debug]);
24833
+ return /* @__PURE__ */ jsx(Fragment$2, { children });
24834
+ }
24791
24835
  const resolveTokenOverride = ({
24792
24836
  config: config2,
24793
24837
  token
@@ -24994,7 +25038,8 @@ function AthenaProvider({
24994
25038
  enableThreadList = false,
24995
25039
  theme,
24996
25040
  linkClicks,
24997
- citationLinks
25041
+ citationLinks,
25042
+ posthog: posthogProp
24998
25043
  }) {
24999
25044
  const frontendToolNames = useMemo(() => Object.keys(frontendTools), [frontendTools]);
25000
25045
  const themeStyleVars = useMemo(() => theme ? themeToStyleVars(theme) : void 0, [theme]);
@@ -25009,6 +25054,7 @@ function AthenaProvider({
25009
25054
  const configuredBackendUrl = (config2 == null ? void 0 : config2.backendUrl) ?? backendUrl;
25010
25055
  const configuredAppUrl = (config2 == null ? void 0 : config2.appUrl) ?? appUrl;
25011
25056
  const configuredTrustedParentOrigins = config2 == null ? void 0 : config2.trustedParentOrigins;
25057
+ const posthogConfig = (config2 == null ? void 0 : config2.posthog) ?? posthogProp;
25012
25058
  const bridge = useParentBridge({
25013
25059
  trustedOrigins: configuredTrustedParentOrigins
25014
25060
  });
@@ -25068,10 +25114,11 @@ function AthenaProvider({
25068
25114
  }
25069
25115
  );
25070
25116
  }
25117
+ let result = /* @__PURE__ */ jsx(PostHogProvider, { config: posthogConfig, children: inner });
25071
25118
  if (themeStyleVars) {
25072
- return /* @__PURE__ */ jsx("div", { className: "athena-themed", style: themeStyleVars, children: inner });
25119
+ result = /* @__PURE__ */ jsx("div", { className: "athena-themed", style: themeStyleVars, children: result });
25073
25120
  }
25074
- return inner;
25121
+ return result;
25075
25122
  }
25076
25123
  function OrderedMap(content) {
25077
25124
  this.content = content;
@@ -59299,14 +59346,30 @@ var index_default$1 = Placeholder;
59299
59346
  const EditorCtx = createContext(null);
59300
59347
  function ComposerEditorProvider({ children }) {
59301
59348
  const ref = useRef(null);
59302
- return /* @__PURE__ */ jsx(EditorCtx.Provider, { value: ref, children });
59349
+ const [editorEmpty, setEditorEmpty] = useState(true);
59350
+ const value = { editorRef: ref, editorEmpty, setEditorEmpty };
59351
+ return /* @__PURE__ */ jsx(EditorCtx.Provider, { value, children });
59303
59352
  }
59304
59353
  function useComposerEditorRef() {
59305
59354
  const ctx = useContext(EditorCtx);
59306
59355
  if (!ctx) {
59307
59356
  throw new Error("[AthenaSDK] useComposerEditorRef must be used within <ComposerEditorProvider>");
59308
59357
  }
59309
- return ctx;
59358
+ return ctx.editorRef;
59359
+ }
59360
+ function useComposerEditorEmpty() {
59361
+ const ctx = useContext(EditorCtx);
59362
+ if (!ctx) {
59363
+ throw new Error("[AthenaSDK] useComposerEditorEmpty must be used within <ComposerEditorProvider>");
59364
+ }
59365
+ return ctx.editorEmpty;
59366
+ }
59367
+ function useSetComposerEditorEmpty() {
59368
+ const ctx = useContext(EditorCtx);
59369
+ if (!ctx) {
59370
+ throw new Error("[AthenaSDK] useSetComposerEditorEmpty must be used within <ComposerEditorProvider>");
59371
+ }
59372
+ return ctx.setEditorEmpty;
59310
59373
  }
59311
59374
  const isMentionPopupActive = (editor) => {
59312
59375
  var _a2, _b;
@@ -61459,6 +61522,7 @@ const TiptapComposer = ({ tools = [] }) => {
61459
61522
  const composerRuntime = useComposerRuntime();
61460
61523
  const editorRef = useRef(null);
61461
61524
  const composerEditorRef = useComposerEditorRef();
61525
+ const setEditorEmpty = useSetComposerEditorEmpty();
61462
61526
  const mentionStore = useMentionSuggestions(tools);
61463
61527
  const { attachments, clearAttachments, isUploading } = useAttachments();
61464
61528
  const { quote, clearQuote } = useQuote();
@@ -61504,6 +61568,9 @@ const TiptapComposer = ({ tools = [] }) => {
61504
61568
  handleSubmitRef.current = handleSubmit;
61505
61569
  const editor = useEditor({
61506
61570
  immediatelyRender: true,
61571
+ onUpdate: ({ editor: e }) => {
61572
+ setEditorEmpty(e.isEmpty);
61573
+ },
61507
61574
  extensions: [
61508
61575
  index_default$2.configure({
61509
61576
  codeBlock: {
@@ -65067,10 +65134,12 @@ const ComposerAction = () => /* @__PURE__ */ jsxs("div", { className: "aui-compo
65067
65134
  ] });
65068
65135
  const ComposerSendWithQuote = () => {
65069
65136
  const aui = useAui();
65137
+ const composerRuntime = useComposerRuntime();
65070
65138
  const { appUrl } = useAthenaConfig();
65071
65139
  const { quote, clearQuote } = useQuote();
65072
65140
  const { attachments, clearAttachments, isUploading } = useAttachments();
65073
65141
  const editorRef = useComposerEditorRef();
65142
+ const editorEmpty = useComposerEditorEmpty();
65074
65143
  const hasExtras = !!quote || attachments.length > 0;
65075
65144
  const handleSend = useCallback(() => {
65076
65145
  var _a2;
@@ -65078,51 +65147,42 @@ const ComposerSendWithQuote = () => {
65078
65147
  const editor = editorRef.current;
65079
65148
  if (!editor && !quote && attachments.length === 0) return;
65080
65149
  const userText = ((_a2 = editor == null ? void 0 : editor.getMarkdown()) == null ? void 0 : _a2.trim()) ?? "";
65081
- const fullMessage = buildComposedMessage({
65082
- attachments,
65083
- quote,
65084
- userText,
65085
- appUrl
65086
- });
65087
- if (!fullMessage) return;
65088
- aui.thread().append({
65089
- role: "user",
65090
- content: [{ type: "text", text: fullMessage }]
65091
- });
65150
+ if (hasExtras) {
65151
+ const fullMessage = buildComposedMessage({
65152
+ attachments,
65153
+ quote,
65154
+ userText,
65155
+ appUrl
65156
+ });
65157
+ if (!fullMessage) return;
65158
+ aui.thread().append({
65159
+ role: "user",
65160
+ content: [{ type: "text", text: fullMessage }]
65161
+ });
65162
+ clearQuote();
65163
+ clearAttachments();
65164
+ } else {
65165
+ if (!userText) return;
65166
+ composerRuntime.setText(userText);
65167
+ composerRuntime.send();
65168
+ }
65092
65169
  editor == null ? void 0 : editor.clear();
65093
- clearQuote();
65094
- clearAttachments();
65095
- }, [aui, quote, attachments, isUploading, clearQuote, clearAttachments, editorRef, appUrl]);
65096
- if (hasExtras) {
65097
- return /* @__PURE__ */ jsx(
65098
- TooltipIconButton,
65099
- {
65100
- tooltip: isUploading ? "Upload in progress..." : "Send message",
65101
- side: "bottom",
65102
- type: "button",
65103
- variant: "default",
65104
- size: "icon",
65105
- className: "aui-composer-send size-8 rounded-full",
65106
- "aria-label": "Send message",
65107
- onClick: handleSend,
65108
- disabled: isUploading,
65109
- children: /* @__PURE__ */ jsx(ArrowUp, { className: "aui-composer-send-icon size-4" })
65110
- }
65111
- );
65112
- }
65113
- return /* @__PURE__ */ jsx(ComposerPrimitiveSend, { asChild: true, children: /* @__PURE__ */ jsx(
65170
+ }, [aui, composerRuntime, quote, attachments, hasExtras, isUploading, clearQuote, clearAttachments, editorRef, appUrl]);
65171
+ return /* @__PURE__ */ jsx(
65114
65172
  TooltipIconButton,
65115
65173
  {
65116
- tooltip: "Send message",
65174
+ tooltip: isUploading ? "Upload in progress..." : "Send message",
65117
65175
  side: "bottom",
65118
- type: "submit",
65176
+ type: "button",
65119
65177
  variant: "default",
65120
65178
  size: "icon",
65121
65179
  className: "aui-composer-send size-8 rounded-full",
65122
65180
  "aria-label": "Send message",
65181
+ onClick: handleSend,
65182
+ disabled: isUploading || editorEmpty && !hasExtras,
65123
65183
  children: /* @__PURE__ */ jsx(ArrowUp, { className: "aui-composer-send-icon size-4" })
65124
65184
  }
65125
- ) });
65185
+ );
65126
65186
  };
65127
65187
  const MessageError = () => /* @__PURE__ */ jsx(MessagePrimitiveError, { children: /* @__PURE__ */ 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: [
65128
65188
  /* @__PURE__ */ jsx(CircleAlert, { className: "mt-0.5 size-4 shrink-0" }),
@@ -65836,6 +65896,7 @@ export {
65836
65896
  createAssetToolUI,
65837
65897
  formatToolName,
65838
65898
  getAssetInfo,
65899
+ getPostHogInstance,
65839
65900
  isAthenaCitationUrl,
65840
65901
  normalizeResult,
65841
65902
  parseAthenaCitationLink,