@athenaintel/react 0.24.0 → 0.25.0

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.
Files changed (197) hide show
  1. package/README.md +29 -4
  2. package/dist/assets/AssetPanel.cjs +3 -2
  3. package/dist/assets/AssetPanel.cjs.map +1 -1
  4. package/dist/assets/AssetPanel.js +3 -2
  5. package/dist/assets/AssetPanel.js.map +1 -1
  6. package/dist/assets/AthenaAssetEmbed.cjs +1 -0
  7. package/dist/assets/AthenaAssetEmbed.cjs.map +1 -1
  8. package/dist/assets/AthenaAssetEmbed.js +1 -0
  9. package/dist/assets/AthenaAssetEmbed.js.map +1 -1
  10. package/dist/assets/use-asset-embed.cjs +22 -23
  11. package/dist/assets/use-asset-embed.cjs.map +1 -1
  12. package/dist/assets/use-asset-embed.d.ts +9 -0
  13. package/dist/assets/use-asset-embed.js +22 -23
  14. package/dist/assets/use-asset-embed.js.map +1 -1
  15. package/dist/auth/AthenaAuthProvider.cjs +32 -4
  16. package/dist/auth/AthenaAuthProvider.cjs.map +1 -1
  17. package/dist/auth/AthenaAuthProvider.d.ts +21 -0
  18. package/dist/auth/AthenaAuthProvider.js +33 -5
  19. package/dist/auth/AthenaAuthProvider.js.map +1 -1
  20. package/dist/auth/AthenaCredentialSourceContext.cjs +21 -0
  21. package/dist/auth/AthenaCredentialSourceContext.cjs.map +1 -0
  22. package/dist/auth/AthenaCredentialSourceContext.d.ts +14 -0
  23. package/dist/auth/AthenaCredentialSourceContext.js +21 -0
  24. package/dist/auth/AthenaCredentialSourceContext.js.map +1 -0
  25. package/dist/auth/AthenaSSOProvider.cjs +71 -47
  26. package/dist/auth/AthenaSSOProvider.cjs.map +1 -1
  27. package/dist/auth/AthenaSSOProvider.js +71 -47
  28. package/dist/auth/AthenaSSOProvider.js.map +1 -1
  29. package/dist/auth/credential-source.cjs +120 -0
  30. package/dist/auth/credential-source.cjs.map +1 -0
  31. package/dist/auth/credential-source.d.ts +68 -0
  32. package/dist/auth/credential-source.js +120 -0
  33. package/dist/auth/credential-source.js.map +1 -0
  34. package/dist/auth/types.d.ts +9 -0
  35. package/dist/chat/AthenaChat.cjs +8 -0
  36. package/dist/chat/AthenaChat.cjs.map +1 -1
  37. package/dist/chat/AthenaChat.js +8 -0
  38. package/dist/chat/AthenaChat.js.map +1 -1
  39. package/dist/chat/StatewireApprovalCard.cjs +31 -6
  40. package/dist/chat/StatewireApprovalCard.cjs.map +1 -1
  41. package/dist/chat/StatewireApprovalCard.d.ts +34 -4
  42. package/dist/chat/StatewireApprovalCard.js +33 -8
  43. package/dist/chat/StatewireApprovalCard.js.map +1 -1
  44. package/dist/chat-ui/index.d.ts +1 -1
  45. package/dist/chat-ui/mentions/suggestions/data/api-client.cjs +20 -11
  46. package/dist/chat-ui/mentions/suggestions/data/api-client.cjs.map +1 -1
  47. package/dist/chat-ui/mentions/suggestions/data/api-client.d.ts +11 -2
  48. package/dist/chat-ui/mentions/suggestions/data/api-client.js +20 -11
  49. package/dist/chat-ui/mentions/suggestions/data/api-client.js.map +1 -1
  50. package/dist/chat-ui/statewire.d.ts +1 -1
  51. package/dist/collab/mint.cjs +6 -15
  52. package/dist/collab/mint.cjs.map +1 -1
  53. package/dist/collab/mint.d.ts +8 -0
  54. package/dist/collab/mint.js +6 -15
  55. package/dist/collab/mint.js.map +1 -1
  56. package/dist/collab/presence-mint.cjs +20 -16
  57. package/dist/collab/presence-mint.cjs.map +1 -1
  58. package/dist/collab/presence-mint.js +21 -17
  59. package/dist/collab/presence-mint.js.map +1 -1
  60. package/dist/collab/presence-react.cjs +12 -5
  61. package/dist/collab/presence-react.cjs.map +1 -1
  62. package/dist/collab/presence-react.d.ts +3 -1
  63. package/dist/collab/presence-react.js +12 -5
  64. package/dist/collab/presence-react.js.map +1 -1
  65. package/dist/collab/react.cjs +5 -2
  66. package/dist/collab/react.cjs.map +1 -1
  67. package/dist/collab/react.js +5 -2
  68. package/dist/collab/react.js.map +1 -1
  69. package/dist/dictation/use-athena-dictation-engine.cjs +12 -11
  70. package/dist/dictation/use-athena-dictation-engine.cjs.map +1 -1
  71. package/dist/dictation/use-athena-dictation-engine.d.ts +4 -3
  72. package/dist/dictation/use-athena-dictation-engine.js +12 -11
  73. package/dist/dictation/use-athena-dictation-engine.js.map +1 -1
  74. package/dist/index.cjs +1 -0
  75. package/dist/index.cjs.map +1 -1
  76. package/dist/index.d.ts +3 -3
  77. package/dist/index.js +2 -1
  78. package/dist/packages/agent-runtime/src/conversation-list.cjs.map +1 -1
  79. package/dist/packages/agent-runtime/src/conversation-list.js.map +1 -1
  80. package/dist/packages/agent-runtime/src/generated/runconfig-contract.cjs +1 -0
  81. package/dist/packages/agent-runtime/src/generated/runconfig-contract.cjs.map +1 -1
  82. package/dist/packages/agent-runtime/src/generated/runconfig-contract.js +1 -0
  83. package/dist/packages/agent-runtime/src/generated/runconfig-contract.js.map +1 -1
  84. package/dist/packages/agent-runtime/src/interrupts.cjs +22 -2
  85. package/dist/packages/agent-runtime/src/interrupts.cjs.map +1 -1
  86. package/dist/packages/agent-runtime/src/interrupts.js +22 -2
  87. package/dist/packages/agent-runtime/src/interrupts.js.map +1 -1
  88. package/dist/packages/agent-runtime/src/messages.cjs +2 -1
  89. package/dist/packages/agent-runtime/src/messages.cjs.map +1 -1
  90. package/dist/packages/agent-runtime/src/messages.js +2 -1
  91. package/dist/packages/agent-runtime/src/messages.js.map +1 -1
  92. package/dist/packages/agent-runtime/src/voice-presentation.cjs +6 -0
  93. package/dist/packages/agent-runtime/src/voice-presentation.cjs.map +1 -1
  94. package/dist/packages/agent-runtime/src/voice-presentation.js +6 -0
  95. package/dist/packages/agent-runtime/src/voice-presentation.js.map +1 -1
  96. package/dist/packages/agent-runtime/src/voice-turn-grouping.cjs +68 -0
  97. package/dist/packages/agent-runtime/src/voice-turn-grouping.cjs.map +1 -0
  98. package/dist/packages/agent-runtime/src/voice-turn-grouping.js +68 -0
  99. package/dist/packages/agent-runtime/src/voice-turn-grouping.js.map +1 -0
  100. package/dist/packages/react/package.json.cjs +1 -1
  101. package/dist/packages/react/package.json.js +1 -1
  102. package/dist/provider/AthenaContext.cjs.map +1 -1
  103. package/dist/provider/AthenaContext.d.ts +7 -1
  104. package/dist/provider/AthenaContext.js.map +1 -1
  105. package/dist/provider/AthenaProvider.cjs +24 -2
  106. package/dist/provider/AthenaProvider.cjs.map +1 -1
  107. package/dist/provider/AthenaProvider.js +24 -2
  108. package/dist/provider/AthenaProvider.js.map +1 -1
  109. package/dist/provider/theme-style-context.cjs +12 -0
  110. package/dist/provider/theme-style-context.cjs.map +1 -0
  111. package/dist/provider/theme-style-context.d.ts +8 -0
  112. package/dist/provider/theme-style-context.js +12 -0
  113. package/dist/provider/theme-style-context.js.map +1 -0
  114. package/dist/runtime/auth-refusal-restart.cjs +66 -0
  115. package/dist/runtime/auth-refusal-restart.cjs.map +1 -0
  116. package/dist/runtime/auth-refusal-restart.d.ts +35 -0
  117. package/dist/runtime/auth-refusal-restart.js +66 -0
  118. package/dist/runtime/auth-refusal-restart.js.map +1 -0
  119. package/dist/runtime/auth.cjs +58 -21
  120. package/dist/runtime/auth.cjs.map +1 -1
  121. package/dist/runtime/auth.d.ts +11 -1
  122. package/dist/runtime/auth.js +59 -22
  123. package/dist/runtime/auth.js.map +1 -1
  124. package/dist/runtime/credential-renewal.cjs +29 -0
  125. package/dist/runtime/credential-renewal.cjs.map +1 -0
  126. package/dist/runtime/credential-renewal.d.ts +35 -0
  127. package/dist/runtime/credential-renewal.js +29 -0
  128. package/dist/runtime/credential-renewal.js.map +1 -0
  129. package/dist/search/useAthenaRepoSearch.cjs +3 -5
  130. package/dist/search/useAthenaRepoSearch.cjs.map +1 -1
  131. package/dist/search/useAthenaRepoSearch.d.ts +7 -7
  132. package/dist/search/useAthenaRepoSearch.js +3 -5
  133. package/dist/search/useAthenaRepoSearch.js.map +1 -1
  134. package/dist/styles.css +1 -1
  135. package/dist/threads/SessionList.cjs +87 -16
  136. package/dist/threads/SessionList.cjs.map +1 -1
  137. package/dist/threads/SessionList.js +88 -17
  138. package/dist/threads/SessionList.js.map +1 -1
  139. package/dist/threads/api.cjs +5 -1
  140. package/dist/threads/api.cjs.map +1 -1
  141. package/dist/threads/api.js +5 -1
  142. package/dist/threads/api.js.map +1 -1
  143. package/dist/threads/conversation-list-fetcher.cjs +5 -5
  144. package/dist/threads/conversation-list-fetcher.cjs.map +1 -1
  145. package/dist/threads/conversation-list-fetcher.d.ts +6 -5
  146. package/dist/threads/conversation-list-fetcher.js +5 -5
  147. package/dist/threads/conversation-list-fetcher.js.map +1 -1
  148. package/dist/threads/session-list-model.cjs +13 -5
  149. package/dist/threads/session-list-model.cjs.map +1 -1
  150. package/dist/threads/session-list-model.d.ts +10 -3
  151. package/dist/threads/session-list-model.js +13 -5
  152. package/dist/threads/session-list-model.js.map +1 -1
  153. package/dist/threads/statewire-thread-list.cjs +13 -14
  154. package/dist/threads/statewire-thread-list.cjs.map +1 -1
  155. package/dist/threads/statewire-thread-list.js +13 -14
  156. package/dist/threads/statewire-thread-list.js.map +1 -1
  157. package/dist/threads/use-rest-conversation-history.cjs +6 -2
  158. package/dist/threads/use-rest-conversation-history.cjs.map +1 -1
  159. package/dist/threads/use-rest-conversation-history.d.ts +3 -1
  160. package/dist/threads/use-rest-conversation-history.js +7 -3
  161. package/dist/threads/use-rest-conversation-history.js.map +1 -1
  162. package/dist/threads/use-statewire-conversation-history.cjs +9 -2
  163. package/dist/threads/use-statewire-conversation-history.cjs.map +1 -1
  164. package/dist/threads/use-statewire-conversation-history.d.ts +3 -1
  165. package/dist/threads/use-statewire-conversation-history.js +10 -3
  166. package/dist/threads/use-statewire-conversation-history.js.map +1 -1
  167. package/dist/threads/use-thread-archive.cjs +2 -1
  168. package/dist/threads/use-thread-archive.cjs.map +1 -1
  169. package/dist/threads/use-thread-archive.d.ts +3 -1
  170. package/dist/threads/use-thread-archive.js +2 -1
  171. package/dist/threads/use-thread-archive.js.map +1 -1
  172. package/dist/threads/use-thread-favorite.cjs.map +1 -1
  173. package/dist/threads/use-thread-favorite.d.ts +3 -1
  174. package/dist/threads/use-thread-favorite.js.map +1 -1
  175. package/dist/threads/use-thread-field-override.cjs +2 -1
  176. package/dist/threads/use-thread-field-override.cjs.map +1 -1
  177. package/dist/threads/use-thread-field-override.d.ts +3 -1
  178. package/dist/threads/use-thread-field-override.js +2 -1
  179. package/dist/threads/use-thread-field-override.js.map +1 -1
  180. package/dist/threads/use-thread-rename.cjs.map +1 -1
  181. package/dist/threads/use-thread-rename.d.ts +3 -1
  182. package/dist/threads/use-thread-rename.js.map +1 -1
  183. package/dist/tools/tool-uis.cjs +11 -15
  184. package/dist/tools/tool-uis.cjs.map +1 -1
  185. package/dist/tools/tool-uis.js +11 -15
  186. package/dist/tools/tool-uis.js.map +1 -1
  187. package/dist/ui/popover.cjs +46 -0
  188. package/dist/ui/popover.cjs.map +1 -0
  189. package/dist/ui/popover.d.ts +6 -0
  190. package/dist/ui/popover.js +46 -0
  191. package/dist/ui/popover.js.map +1 -0
  192. package/dist/voice/use-athena-voice-session.cjs +17 -5
  193. package/dist/voice/use-athena-voice-session.cjs.map +1 -1
  194. package/dist/voice/use-athena-voice-session.d.ts +2 -2
  195. package/dist/voice/use-athena-voice-session.js +17 -5
  196. package/dist/voice/use-athena-voice-session.js.map +1 -1
  197. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"AthenaContext.cjs","sources":["../../src/provider/AthenaContext.ts"],"sourcesContent":["import { createContext, useContext } from 'react';\nimport type { AthenaStatewireTokenGetter } from '../runtime/statewire-auth-headers';\nimport type { AthenaProviderConfig } from './config';\nimport type { AthenaCitationLinkOptions, AthenaLinkClickOptions } from './citation-links';\n\nexport interface AthenaConfig extends Pick<AthenaProviderConfig, 'apiKey' | 'token'> {\n backendUrl: string;\n /** The host's live token resolver, for SDK hooks that call agora's REST surface directly. */\n getToken?: AthenaStatewireTokenGetter;\n appUrl: string;\n enabledToolkits: string[];\n linkClicks?: AthenaLinkClickOptions;\n citationLinks?: AthenaCitationLinkOptions;\n}\n\nexport const AthenaContext = createContext<AthenaConfig | null>(null);\n\nexport function useAthenaConfig(): AthenaConfig {\n const ctx = useContext(AthenaContext);\n if (!ctx) {\n throw new Error('[AthenaSDK] useAthenaConfig must be used within <AthenaProvider>');\n }\n return ctx;\n}\n"],"names":["createContext","useContext"],"mappings":";;;AAeO,MAAM,gBAAgBA,MAAAA,cAAmC,IAAI;AAE7D,SAAS,kBAAgC;AAC9C,QAAM,MAAMC,MAAAA,WAAW,aAAa;AACpC,MAAI,CAAC,KAAK;AACR,UAAM,IAAI,MAAM,kEAAkE;AAAA,EACpF;AACA,SAAO;AACT;;;"}
1
+ {"version":3,"file":"AthenaContext.cjs","sources":["../../src/provider/AthenaContext.ts"],"sourcesContent":["import { createContext, useContext } from 'react';\nimport type { AthenaStatewireTokenGetter } from '../runtime/statewire-auth-headers';\nimport type { AthenaProviderConfig } from './config';\nimport type { AthenaCitationLinkOptions, AthenaLinkClickOptions } from './citation-links';\n\nexport interface AthenaConfig extends Pick<AthenaProviderConfig, 'apiKey' | 'token'> {\n backendUrl: string;\n /**\n * The SDK's live token resolver, for SDK hooks that call agora's REST\n * surface directly. Every sign-in mode feeds it (the host's `getToken`, a\n * sign-in provider, the Marathon or parent-window bridge); pass\n * `{ force: true }` after a 401 to renew the token before one resend.\n * Undefined when there is no token to resolve (API key alone).\n */\n getToken?: AthenaStatewireTokenGetter;\n appUrl: string;\n enabledToolkits: string[];\n linkClicks?: AthenaLinkClickOptions;\n citationLinks?: AthenaCitationLinkOptions;\n}\n\nexport const AthenaContext = createContext<AthenaConfig | null>(null);\n\nexport function useAthenaConfig(): AthenaConfig {\n const ctx = useContext(AthenaContext);\n if (!ctx) {\n throw new Error('[AthenaSDK] useAthenaConfig must be used within <AthenaProvider>');\n }\n return ctx;\n}\n"],"names":["createContext","useContext"],"mappings":";;;AAqBO,MAAM,gBAAgBA,MAAAA,cAAmC,IAAI;AAE7D,SAAS,kBAAgC;AAC9C,QAAM,MAAMC,MAAAA,WAAW,aAAa;AACpC,MAAI,CAAC,KAAK;AACR,UAAM,IAAI,MAAM,kEAAkE;AAAA,EACpF;AACA,SAAO;AACT;;;"}
@@ -3,7 +3,13 @@ import type { AthenaProviderConfig } from './config';
3
3
  import type { AthenaCitationLinkOptions, AthenaLinkClickOptions } from './citation-links';
4
4
  export interface AthenaConfig extends Pick<AthenaProviderConfig, 'apiKey' | 'token'> {
5
5
  backendUrl: string;
6
- /** The host's live token resolver, for SDK hooks that call agora's REST surface directly. */
6
+ /**
7
+ * The SDK's live token resolver, for SDK hooks that call agora's REST
8
+ * surface directly. Every sign-in mode feeds it (the host's `getToken`, a
9
+ * sign-in provider, the Marathon or parent-window bridge); pass
10
+ * `{ force: true }` after a 401 to renew the token before one resend.
11
+ * Undefined when there is no token to resolve (API key alone).
12
+ */
7
13
  getToken?: AthenaStatewireTokenGetter;
8
14
  appUrl: string;
9
15
  enabledToolkits: string[];
@@ -1 +1 @@
1
- {"version":3,"file":"AthenaContext.js","sources":["../../src/provider/AthenaContext.ts"],"sourcesContent":["import { createContext, useContext } from 'react';\nimport type { AthenaStatewireTokenGetter } from '../runtime/statewire-auth-headers';\nimport type { AthenaProviderConfig } from './config';\nimport type { AthenaCitationLinkOptions, AthenaLinkClickOptions } from './citation-links';\n\nexport interface AthenaConfig extends Pick<AthenaProviderConfig, 'apiKey' | 'token'> {\n backendUrl: string;\n /** The host's live token resolver, for SDK hooks that call agora's REST surface directly. */\n getToken?: AthenaStatewireTokenGetter;\n appUrl: string;\n enabledToolkits: string[];\n linkClicks?: AthenaLinkClickOptions;\n citationLinks?: AthenaCitationLinkOptions;\n}\n\nexport const AthenaContext = createContext<AthenaConfig | null>(null);\n\nexport function useAthenaConfig(): AthenaConfig {\n const ctx = useContext(AthenaContext);\n if (!ctx) {\n throw new Error('[AthenaSDK] useAthenaConfig must be used within <AthenaProvider>');\n }\n return ctx;\n}\n"],"names":[],"mappings":";AAeO,MAAM,gBAAgB,cAAmC,IAAI;AAE7D,SAAS,kBAAgC;AAC9C,QAAM,MAAM,WAAW,aAAa;AACpC,MAAI,CAAC,KAAK;AACR,UAAM,IAAI,MAAM,kEAAkE;AAAA,EACpF;AACA,SAAO;AACT;"}
1
+ {"version":3,"file":"AthenaContext.js","sources":["../../src/provider/AthenaContext.ts"],"sourcesContent":["import { createContext, useContext } from 'react';\nimport type { AthenaStatewireTokenGetter } from '../runtime/statewire-auth-headers';\nimport type { AthenaProviderConfig } from './config';\nimport type { AthenaCitationLinkOptions, AthenaLinkClickOptions } from './citation-links';\n\nexport interface AthenaConfig extends Pick<AthenaProviderConfig, 'apiKey' | 'token'> {\n backendUrl: string;\n /**\n * The SDK's live token resolver, for SDK hooks that call agora's REST\n * surface directly. Every sign-in mode feeds it (the host's `getToken`, a\n * sign-in provider, the Marathon or parent-window bridge); pass\n * `{ force: true }` after a 401 to renew the token before one resend.\n * Undefined when there is no token to resolve (API key alone).\n */\n getToken?: AthenaStatewireTokenGetter;\n appUrl: string;\n enabledToolkits: string[];\n linkClicks?: AthenaLinkClickOptions;\n citationLinks?: AthenaCitationLinkOptions;\n}\n\nexport const AthenaContext = createContext<AthenaConfig | null>(null);\n\nexport function useAthenaConfig(): AthenaConfig {\n const ctx = useContext(AthenaContext);\n if (!ctx) {\n throw new Error('[AthenaSDK] useAthenaConfig must be used within <AthenaProvider>');\n }\n return ctx;\n}\n"],"names":[],"mappings":";AAqBO,MAAM,gBAAgB,cAAmC,IAAI;AAE7D,SAAS,kBAAgC;AAC9C,QAAM,MAAM,WAAW,aAAa;AACpC,MAAI,CAAC,KAAK;AACR,UAAM,IAAI,MAAM,kEAAkE;AAAA,EACpF;AACA,SAAO;AACT;"}
@@ -7,6 +7,9 @@ const athenaUrls = require("../lib/athena-urls.cjs");
7
7
  const mint = require("../collab/mint.cjs");
8
8
  const auth = require("../runtime/auth.cjs");
9
9
  const AthenaAuthContext = require("../auth/AthenaAuthContext.cjs");
10
+ const AthenaCredentialSourceContext = require("../auth/AthenaCredentialSourceContext.cjs");
11
+ const credentialSource = require("../auth/credential-source.cjs");
12
+ const authRefusalRestart = require("../runtime/auth-refusal-restart.cjs");
10
13
  const useAthenaStatewireRuntime = require("../runtime/useAthenaStatewireRuntime.cjs");
11
14
  const statewireLifecycle = require("../runtime/statewire-lifecycle.cjs");
12
15
  const statewireRunConfig = require("../runtime/statewire-run-config.cjs");
@@ -25,6 +28,7 @@ const threadIdContext = require("../threads/thread-id-context.cjs");
25
28
  const statewireThreadList = require("../threads/statewire-thread-list.cjs");
26
29
  const assetPanelStore = require("../assets/asset-panel-store.cjs");
27
30
  const index = require("../theme/index.cjs");
31
+ const themeStyleContext = require("./theme-style-context.cjs");
28
32
  const PostHogProvider = require("./PostHogProvider.cjs");
29
33
  const threadSnapshotCache = require("../packages/agent-runtime/src/thread-snapshot-cache.cjs");
30
34
  const toolOutputs = require("../packages/agent-runtime/src/tool-outputs.cjs");
@@ -149,6 +153,10 @@ function AthenaStatewireRuntimeMount({
149
153
  dispatchLifecycle({ type: "raw-connection", reconnect: connection.reconnect });
150
154
  }
151
155
  });
156
+ authRefusalRestart.useRestartAfterAuthRefusal({
157
+ connection: lifecycle.connection,
158
+ reconnect: lifecycle.reconnect
159
+ });
152
160
  const dismissError = react.useCallback(
153
161
  () => dispatchLifecycle({ type: "error", error: null }),
154
162
  []
@@ -413,6 +421,20 @@ function AthenaProvider({
413
421
  [composerHandoff$1]
414
422
  );
415
423
  const effectiveToken = configuredToken !== void 0 ? configuredToken : authProviderToken ?? bridge.token;
424
+ const authProviderGetToken = authContext == null ? void 0 : authContext.getToken;
425
+ const credentialInputsRef = react.useRef({ token: null });
426
+ credentialInputsRef.current = {
427
+ hostGetToken: configuredGetToken,
428
+ token: effectiveToken,
429
+ renew: configuredToken !== void 0 ? void 0 : authProviderToken !== null ? authProviderGetToken ? async ({ force }) => await authProviderGetToken({ force }) ?? null : void 0 : bridge.token !== null ? bridge.renewToken : void 0
430
+ };
431
+ const [credentials] = react.useState(
432
+ () => credentialSource.createAthenaCredentialSource(() => credentialInputsRef.current)
433
+ );
434
+ react.useEffect(() => {
435
+ credentials.notifyTokenChanged();
436
+ }, [credentials, effectiveToken]);
437
+ const credentialGetToken = configuredGetToken !== void 0 || effectiveToken ? credentials.getToken : void 0;
416
438
  const effectiveApiUrl = configuredApiUrl ?? environmentUrls.apiUrl;
417
439
  const effectiveBackendUrl = mint.getAthenaApiBaseUrl(
418
440
  configuredBackendUrl ?? bridge.backendBaseUrl ?? environmentUrls.backendUrl
@@ -438,7 +460,7 @@ function AthenaProvider({
438
460
  appUrl: effectiveAppUrl,
439
461
  apiKey: configuredApiKey,
440
462
  token: effectiveToken,
441
- getToken: configuredGetToken,
463
+ getToken: credentialGetToken,
442
464
  model,
443
465
  agent,
444
466
  channel,
@@ -469,7 +491,7 @@ function AthenaProvider({
469
491
  {
470
492
  className: themeStyleVars ? "athena-sdk athena-themed" : "athena-sdk",
471
493
  style: themeStyleVars,
472
- children: /* @__PURE__ */ jsxRuntime.jsx(PostHogProvider.PostHogProvider, { config: posthogConfig, children: /* @__PURE__ */ jsxRuntime.jsx(composerHandoff.ComposerHandoffContext.Provider, { value: composerHandoff$1, children: inner }) })
494
+ children: /* @__PURE__ */ jsxRuntime.jsx(PostHogProvider.PostHogProvider, { config: posthogConfig, children: /* @__PURE__ */ jsxRuntime.jsx(composerHandoff.ComposerHandoffContext.Provider, { value: composerHandoff$1, children: /* @__PURE__ */ jsxRuntime.jsx(themeStyleContext.AthenaThemeStyleContext.Provider, { value: themeStyleVars, children: /* @__PURE__ */ jsxRuntime.jsx(AthenaCredentialSourceContext.AthenaCredentialSourceContext.Provider, { value: credentials, children: inner }) }) }) })
473
495
  }
474
496
  );
475
497
  }
@@ -1 +1 @@
1
- {"version":3,"file":"AthenaProvider.cjs","sources":["../../src/provider/AthenaProvider.tsx"],"sourcesContent":["import { AuiProvider, useAui } from '@assistant-ui/react';\nimport {\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useMemo,\n useReducer,\n useRef,\n useState,\n type ReactNode,\n} from 'react';\nimport type { AssistantClient, Toolkit } from '@assistant-ui/react';\nimport {\n createDeepAgentThreadSnapshotCache,\n createDeepAgentToolOutputStore,\n DeepAgentConnectionContext,\n type DeepAgentThreadSnapshotCache,\n type DeepAgentToolOutputStore,\n} from '@athenaintel/agent-runtime';\nimport {\n assertHostMintedStatewireMount,\n deriveAthenaAppUrl,\n getAthenaEnvironmentUrls,\n resolveStatewireSyncUrl,\n type AthenaEnvironment,\n} from '../lib/athena-urls';\nimport { getAthenaApiBaseUrl } from '../collab/mint';\nimport { useParentBridge } from '../runtime/auth';\nimport { AthenaAuthContext } from '../auth/AthenaAuthContext';\nimport {\n useAthenaStatewireRuntime,\n useStatewireClientTools,\n} from '../runtime/useAthenaStatewireRuntime';\nimport {\n athenaStatewireErrorNotice,\n type AthenaStatewireLifecycleState,\n initialStatewireLifecycle,\n statewireLifecycleReducer,\n} from '../runtime/statewire-lifecycle';\nimport type { AthenaStatewireTokenGetter } from '../runtime/statewire-auth-headers';\nimport { resolveAgentProp } from '../runtime/statewire-run-config';\nimport { mintThreadId } from '../threads/mint-thread-id';\nimport { AthenaStatewireLifecycleContext } from './statewire-lifecycle-context';\nimport {\n ComposerHandoffContext,\n clearComposerHandoff,\n createComposerHandoffStore,\n drainComposerHandoff,\n useComposerHandoffStore,\n useComposerReady,\n} from '../composer/composer-handoff';\nimport { StatewireToolOutputsContext } from './statewire-window-context';\nimport { StatewireClientToolBridge } from '../chat/StatewireClientToolBridge';\nimport {\n athenaDiagnostics,\n debugPropToDiagnosticsConfig,\n installAthenaDiagnosticsGlobal,\n type AthenaDiagnosticEvent,\n type AthenaDiagnosticLevel,\n type AthenaDiagnosticsConfig,\n} from '../diagnostics/athena-diagnostics';\nimport { AthenaSdkError } from '../diagnostics/errors';\nimport {\n backendDeclaredFrontendToolIds,\n resolveClientToolSurface,\n} from '../chat/statewire-client-tools';\nimport { TooltipProvider } from '../ui/tooltip';\nimport { DEFAULT_AUTO_OPEN_TOOLS } from '../tools/auto-open-tools';\nimport { AthenaContext, type AthenaConfig } from './AthenaContext';\nimport type { AthenaProviderConfig } from './config';\nimport type {\n AthenaCitationLinkOptions,\n AthenaLinkClickOptions,\n} from './citation-links';\nimport {\n AthenaStatewireThreadIdContext,\n AthenaThreadIdContext,\n useAthenaStatewireThreadId,\n} from '../threads/thread-id-context';\nimport {\n AthenaStatewireThreadListProvider,\n StatewireThreadTitlePoller,\n useAthenaStatewireThreadList,\n} from '../threads/statewire-thread-list';\nimport { useAssetPanelStore } from '../assets/asset-panel-store';\nimport { themeToStyleVars, type AthenaTheme } from '../theme';\nimport { PostHogProvider, type PostHogConfig } from './PostHogProvider';\n\nexport interface AthenaProviderProps {\n children: ReactNode;\n\n /** Preferred structured config for auth and Athena endpoint settings. */\n config?: AthenaProviderConfig;\n\n /** @deprecated Prefer `config.apiKey`. API key for authentication in standalone mode. */\n apiKey?: string;\n\n /** @deprecated Prefer `config.token`. PropelAuth token. If provided, takes priority over apiKey. If omitted, the SDK\n * will automatically listen for a token from the parent window via PostMessage. */\n token?: string | null;\n\n /** Run the thread AS a published collab agent. The only accepted shape is\n * `collab_agent:<asset_id>`: the thread then uses that agent's prompt,\n * tools, and model default, and the caller must have view access to the\n * agent asset. Omit it (or pass a blank string) to run the Athena deep agent.\n *\n * Any other non-blank value throws at render — the statewire host cannot\n * honour named agents, and a selector that is silently dropped would let a\n * misconfigured deployment answer as the wrong agent. */\n agent?: string;\n\n /** Collab-agent channel id — a built-in channel (`email`, `sms`, …) or a\n * user-defined custom channel id from the agent's Channels tab. Selects\n * that channel's configuration overrides and stamps the session's origin.\n * Only meaningful together with a `collab_agent:<asset_id>` `agent`; sent\n * as `collab_channel_id`. An unknown or disabled channel rejects the run\n * with a structured, teaching error. */\n channel?: string;\n\n /** LLM model identifier. Defaults to the deep-agent default model\n * (`DEFAULT_STATEWIRE_MODEL`) — or, when a collab agent is selected, to\n * the model its author configured. */\n model?: string;\n\n /** Backend toolkit IDs to enable (e.g. 'document_toolkit', 'web_search_browse_toolkit'). */\n tools?: string[];\n\n /** Frontend tools that execute in the browser. The agent can invoke these.\n * Merged on top of the SDK's default auto-open tools; entries here take\n * precedence over defaults with the same name. Tools with a local\n * `execute` are declared to the backend as `client_tools` and run through\n * the statewire client-tool bridge. */\n frontendTools?: Toolkit;\n\n /** Disable the SDK's default auto-open behavior for created/touched assets. */\n disableAutoOpen?: boolean;\n\n /** @deprecated Prefer `config.apiUrl`. URL on the Iris host fronting the\n * deployment; its origin derives the statewire sync mount when\n * `statewireSyncUrl` is not set. */\n apiUrl?: string;\n\n /** @deprecated Prefer `config.backendUrl`. URL for the Athena backend API. */\n backendUrl?: string;\n\n /** @deprecated Prefer `config.appUrl`. URL for the Athena frontend app origin. */\n appUrl?: string;\n\n /** @deprecated Prefer `config.environment`. Athena environment preset used when URLs are not explicitly provided. */\n environment?: AthenaEnvironment;\n\n /** Resolve the latest auth token immediately before a request (for\n * expiring clients). Takes priority over `token` when it resolves.\n * Prefer `config.getToken` (see its `force` contract for refused\n * credentials). */\n getToken?: AthenaStatewireTokenGetter;\n\n /** Additional fields merged into runConfig.custom. Prefer\n * `config.extraRunConfig`. */\n extraRunConfig?: Record<string, unknown>;\n\n /** Statewire sync base URL override (the `…/v2/threads` mount). Defaults to\n * the mount a Marathon host mints, then the effective `apiUrl` host +\n * `/v2/threads`. Prefer `config.statewireSyncUrl`. */\n statewireSyncUrl?: string;\n\n /** Asset IDs to include in the workbench. */\n workbench?: string[];\n\n /** Knowledge base IDs for RAG context. */\n knowledgeBase?: string[];\n\n /** System prompt override. */\n systemPrompt?: string;\n\n /** Client app identifier for session filtering.\n * Sessions created with this ID can be filtered in the thread list.\n * E.g. \"olympus\", \"athena-app\", or a computer asset ID like \"asset_<uuid>\". */\n appId?: string;\n\n /** Thread ID override. Auto-generated if not provided. */\n threadId?: string;\n\n /** Enable thread list management (sidebar thread switching). */\n enableThreadList?: boolean;\n\n /** Ask the thread list for live pull-request state on each session\n * (`include_pull_requests`), which `SessionList` renders as chips.\n * Defaults to `true` in thread-list mode; turn it off in a host that never\n * shows them to spare the server the lookup. */\n threadListIncludePullRequests?: boolean;\n\n /** Theme configuration. Pass a preset from `themes` or a custom `AthenaTheme` object.\n * Injects CSS variables on a wrapper element — no CSS files needed.\n *\n * @example\n * import { themes } from '@athenaintel/react';\n * <AthenaProvider theme={themes.dark}>\n *\n * @example\n * <AthenaProvider theme={{ primary: '#8b5cf6', radius: '1rem' }}>\n *\n * @example\n * <AthenaProvider theme={{ ...themes.dark, primary: '#22c55e' }}>\n */\n theme?: AthenaTheme;\n\n /** Customize how rendered chat links behave. */\n linkClicks?: AthenaLinkClickOptions;\n\n /** @deprecated Prefer `linkClicks`. Customize how Athena citation links rendered in chat messages behave. */\n citationLinks?: AthenaCitationLinkOptions;\n\n /** PostHog analytics configuration. When omitted or keys are missing, PostHog is silently disabled.\n * Prefer `config.posthog` for structured configuration. */\n posthog?: PostHogConfig;\n\n /** SDK diagnostics.\n *\n * - `true` / a level: echo structured `[AthenaSDK]` events to the console\n * at that level (`true` = 'debug').\n * - An object: full diagnostics config (console level, PostHog timing\n * forwarding, buffer size).\n *\n * Independent of the prop, `localStorage.setItem('athena:debug','debug')`\n * (or `window.__ATHENA_SDK__.diagnostics.enableConsole()`) turns console\n * echo on at runtime without a rebuild. Errors log once even when off. */\n debug?: boolean | AthenaDiagnosticLevel | Partial<AthenaDiagnosticsConfig>;\n\n /** Receives every diagnostics event (timings, warnings, errors) — the hook\n * for shipping SDK telemetry to the host app's own pipeline. */\n onDiagnostic?: (event: AthenaDiagnosticEvent) => void;\n\n /** Receives every SDK error as a typed `AthenaSdkError` (stable `code`,\n * `hint`, structured server `detail`). Fires in addition to the UI's own\n * error handling, so integrations never fail silently. */\n onError?: (error: AthenaSdkError, event: AthenaDiagnosticEvent) => void;\n}\n\nconst resolveTokenOverride = ({\n config,\n token,\n}: {\n config?: AthenaProviderConfig;\n token?: string | null;\n}): string | null | undefined => {\n if (config?.token !== undefined) {\n return config.token;\n }\n return token;\n};\n\nconst useAthenaConfigValue = ({\n backendUrl,\n appUrl,\n apiKey,\n token,\n getToken,\n enabledToolkits,\n linkClicks,\n citationLinks,\n}: {\n backendUrl: string;\n appUrl: string;\n apiKey?: string;\n token?: string | null;\n getToken?: AthenaStatewireTokenGetter;\n enabledToolkits: string[];\n linkClicks?: AthenaLinkClickOptions;\n citationLinks?: AthenaCitationLinkOptions;\n}): AthenaConfig => {\n const linkClicksRef = useRef(linkClicks);\n linkClicksRef.current = linkClicks;\n const citationLinksRef = useRef(citationLinks);\n citationLinksRef.current = citationLinks;\n // Keep token in a ref so its value can update without invalidating the\n // config object identity. PropelAuth rotates tokens on window focus —\n // if token were a memo dep, every rotation would publish a new config\n // object to context and force every consumer (e.g. AssetIframe) to\n // re-render, causing asset panel flicker.\n const tokenRef = useRef(token);\n tokenRef.current = token;\n const getTokenRef = useRef(getToken);\n getTokenRef.current = getToken;\n\n return useMemo(\n () => ({\n backendUrl,\n appUrl,\n apiKey,\n enabledToolkits,\n get token() {\n return tokenRef.current;\n },\n get getToken() {\n return getTokenRef.current;\n },\n get linkClicks() {\n return linkClicksRef.current;\n },\n get citationLinks() {\n return citationLinksRef.current;\n },\n }),\n [backendUrl, appUrl, apiKey, enabledToolkits],\n );\n};\n\n/**\n * Delivers composer writes that were made before this mount was ready\n * (`useAppendToComposer` / `useSendMessage` queue them in the provider-level\n * store, which outlives the keyed per-thread mount). Lives under the\n * `AuiProvider` so it can read the thread's own loading state.\n */\nfunction ComposerHandoffDrain(): null {\n const aui = useAui();\n const store = useComposerHandoffStore();\n const threadId = useContext(AthenaStatewireThreadIdContext);\n const ready = useComposerReady();\n useEffect(() => {\n if (!ready || !store) return;\n // Writes bound to another thread are dropped here, not applied.\n drainComposerHandoff({ store, target: aui, threadId });\n }, [aui, ready, store, threadId]);\n return null;\n}\n\n// ─── Standalone Mode ──────────────────────────────────────────────────\n\n/** Everything the per-thread runtime needs to attach and run a thread. */\ninterface AthenaStatewireRuntimeProps {\n syncUrl: string;\n apiKey?: string;\n token?: string | null;\n getToken?: AthenaStatewireTokenGetter;\n model?: string;\n agent?: string;\n channel?: string;\n tools: string[];\n frontendToolIds: string[];\n frontendTools: Toolkit;\n workbench?: string[];\n knowledgeBase?: string[];\n systemPrompt?: string;\n appId?: string;\n extraRunConfig?: Record<string, unknown>;\n /** The provider-owned snapshot cache (see `AthenaProvider`). */\n snapshotCache: DeepAgentThreadSnapshotCache;\n /** The provider-owned store of fetched-back cut tool outputs (see `AthenaProvider`). */\n toolOutputs: DeepAgentToolOutputStore;\n}\n\ninterface AthenaStatewireStandaloneProps extends AthenaStatewireRuntimeProps {\n children: ReactNode;\n backendUrl: string;\n appUrl: string;\n threadId?: string;\n /**\n * Thread-list mode. The list owns the active id and alone knows whether the\n * backend has listed it yet: `isNewChat` overrides the \"new chat\"\n * derivation (the list mints ids for brand-new chats, which must still load\n * as new), and the scope publishes `AthenaThreadIdContext` — the backend id,\n * withheld while the chat is unpersisted. Absent outside thread-list mode,\n * where that context stays untouched.\n */\n threadList?: { isNewChat: boolean };\n linkClicks?: AthenaLinkClickOptions;\n citationLinks?: AthenaCitationLinkOptions;\n}\n\n/**\n * What one per-thread runtime mount hands to the stable scope around the\n * host's children: the assistant client attached to `threadId` and the\n * transport lifecycle observed on that attach. Published as ONE value so the\n * scope can never pair a thread's id with another thread's client.\n */\ninterface AthenaStatewireRuntimeSnapshot {\n threadId: string;\n isNewChat: boolean;\n client: AssistantClient;\n lifecycle: AthenaStatewireLifecycleState;\n}\n\n/**\n * The per-thread half of the statewire lane: owns the runtime hook (statewire\n * client, pending-message lane, `useAui` client) and the lifecycle reducer\n * behind the connection/error banners, and renders nothing itself. Mounted\n * under `key={threadId}` so a switch — or a new chat — gets a fresh instance\n * of everything here, exactly as when the whole provider subtree was keyed,\n * without remounting the host's UI.\n *\n * An assistant client's readable state only advances when its tap fibers\n * commit (in effects), so an in-place `threadId` change on one mounted hook\n * would leave a commit in which the new id is published but `useAuiState`\n * still reads the previous thread's committed state; a fresh mount publishes\n * its own state on its first render. That is why the runtime is remounted per\n * thread rather than switched in place.\n *\n * The snapshot is published from a layout effect: React flushes the state\n * update a layout effect schedules synchronously, before the browser paints,\n * so the scope re-renders against this client in the same task as this\n * mount's commit — the previous client is never painted under the new id.\n */\nfunction AthenaStatewireRuntimeMount({\n threadId,\n isNewChat,\n onPublish,\n syncUrl,\n apiKey,\n token,\n getToken,\n model,\n agent,\n channel,\n tools,\n frontendToolIds,\n frontendTools,\n workbench,\n knowledgeBase,\n systemPrompt,\n appId,\n extraRunConfig,\n snapshotCache,\n toolOutputs,\n}: AthenaStatewireRuntimeProps & {\n threadId: string;\n isNewChat: boolean;\n onPublish: (snapshot: AthenaStatewireRuntimeSnapshot) => void;\n}): null {\n const [lifecycle, dispatchLifecycle] = useReducer(\n statewireLifecycleReducer,\n initialStatewireLifecycle,\n );\n\n const client = useAthenaStatewireRuntime({\n syncUrl,\n threadId,\n isNewChat,\n apiKey,\n token,\n getToken,\n model,\n agent,\n channel,\n tools,\n frontendToolIds,\n frontendToolkit: frontendTools,\n workbench,\n knowledgeBase,\n systemPrompt,\n appId,\n extraRunConfig,\n snapshotCache,\n toolOutputs,\n // The runtime already records every transport error on the diagnostics\n // bus (with the channel-teardown split), so this layer only maps it to\n // the banner notice.\n onError: (error) => {\n const notice = athenaStatewireErrorNotice(error);\n if (notice) dispatchLifecycle({ type: 'error', error: notice });\n },\n onConnectionChange: (connection) => {\n dispatchLifecycle({ type: 'connection', connection });\n },\n onRawConnectionChange: (connection) => {\n dispatchLifecycle({ type: 'raw-connection', reconnect: connection.reconnect });\n },\n });\n\n const dismissError = useCallback(\n () => dispatchLifecycle({ type: 'error', error: null }),\n [],\n );\n const lifecycleValue = useMemo<AthenaStatewireLifecycleState>(\n () => ({\n connection: lifecycle.connection,\n error: lifecycle.error,\n reconnect: lifecycle.reconnect,\n dismissError,\n }),\n [lifecycle, dismissError],\n );\n\n const snapshot = useMemo<AthenaStatewireRuntimeSnapshot>(\n () => ({ threadId, isNewChat, client, lifecycle: lifecycleValue }),\n [threadId, isNewChat, client, lifecycleValue],\n );\n useLayoutEffect(() => {\n onPublish(snapshot);\n }, [onPublish, snapshot]);\n\n return null;\n}\n\n/**\n * The stable half of the statewire lane: the scope around the host's\n * `children`. It mounts one `AthenaStatewireRuntimeMount` per thread beside\n * them and provides whatever that mount last published — client, thread ids,\n * lifecycle — so a thread switch swaps the client under the host's UI instead\n * of remounting it. Until the first mount has published, the children are\n * withheld: they need a client, and the first publication lands in the same\n * task as the mount's commit.\n *\n * A server render runs no effects, so it would withhold the children too.\n * That changes nothing today: `AthenaProvider` renders `null` until the parent\n * bridge reports ready, which only ever happens in an effect (`useParentBridge`\n * starts `ready: false`), so the SDK has never server-rendered the host UI —\n * it hydrates it. A future SSR-ready bridge would need the first publication\n * to happen in render as well.\n */\nfunction AthenaStatewireStandalone({\n children,\n backendUrl,\n appUrl,\n threadId: threadIdProp,\n threadList,\n linkClicks,\n citationLinks,\n ...runtimeProps\n}: AthenaStatewireStandaloneProps) {\n // Statewire attaches to `${syncUrl}/${threadId}`, so a thread ID must exist\n // up front. An auto-generated ID is by definition a never-started local chat.\n const generatedIdRef = useRef<string | null>(null);\n if (generatedIdRef.current === null) {\n generatedIdRef.current = mintThreadId();\n }\n const threadId = threadIdProp ?? generatedIdRef.current;\n const isNewChat = threadList?.isNewChat ?? !threadIdProp;\n\n const [published, setPublished] = useState<AthenaStatewireRuntimeSnapshot | null>(null);\n\n const clientTools = useStatewireClientTools(runtimeProps.frontendTools);\n\n // The runtime binds `client_tools` only for a recognised `app_id`; with none\n // it drops every declaration without telling the client, and the model then\n // sees \"not a valid tool\". Say so here, once per configuration, as an error\n // so it reaches `onError` and the console even with diagnostics off.\n const clientToolNamesKey = clientTools.map((tool) => tool.definition.name).join(',');\n const clientToolAppId = runtimeProps.appId;\n useEffect(() => {\n if (clientTools.length === 0 || resolveClientToolSurface(clientToolAppId) !== null) return;\n athenaDiagnostics.emit('sdk.config.warning', {\n level: 'error',\n error: new AthenaSdkError({\n code: 'config_invalid',\n message: `frontendTools with an execute() need a recognised appId; ${clientTools.length} tool(s) will not be bound.`,\n hint:\n \"Pass appId={publicAppId} on <AthenaProvider> (a computer-asset app reads it from athena-public-config.json as computer_asset_<uuid>). Without it the deep-agent runtime drops every client tool.\",\n context: { appId: clientToolAppId ?? null, tools: clientToolNamesKey.split(',') },\n }),\n data: { appId: clientToolAppId ?? null, tools: clientToolNamesKey.split(',') },\n });\n // clientToolNamesKey is the value-stable form of the tool list.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [clientToolAppId, clientToolNamesKey]);\n\n const athenaConfig = useAthenaConfigValue({\n backendUrl,\n appUrl,\n apiKey: runtimeProps.apiKey,\n token: runtimeProps.token,\n getToken: runtimeProps.getToken,\n enabledToolkits: runtimeProps.tools,\n linkClicks,\n citationLinks,\n });\n\n const scope = published && (\n <AuiProvider value={published.client}>\n <AthenaContext.Provider value={athenaConfig}>\n <AthenaStatewireThreadIdContext.Provider value={published.threadId}>\n <AthenaStatewireLifecycleContext.Provider value={published.lifecycle}>\n <DeepAgentConnectionContext.Provider value={published.lifecycle.connection}>\n <StatewireToolOutputsContext.Provider value={runtimeProps.toolOutputs}>\n <TooltipProvider>\n <StatewireClientToolBridge tools={clientTools} threadId={published.threadId} />\n <ComposerHandoffDrain />\n {children}\n </TooltipProvider>\n </StatewireToolOutputsContext.Provider>\n </DeepAgentConnectionContext.Provider>\n </AthenaStatewireLifecycleContext.Provider>\n </AthenaStatewireThreadIdContext.Provider>\n </AthenaContext.Provider>\n </AuiProvider>\n );\n\n return (\n <>\n <AthenaStatewireRuntimeMount\n key={threadId}\n threadId={threadId}\n isNewChat={isNewChat}\n onPublish={setPublished}\n {...runtimeProps}\n />\n {/* The backend id rides the same snapshot as the client, so\n history-gated UI (e.g. the loading overlay) never judges one thread\n by another's state; it is undefined for a never-started chat, which\n must not read as pending history. */}\n {threadList && published ? (\n <AthenaThreadIdContext.Provider\n value={published.isNewChat ? undefined : published.threadId}\n >\n {scope}\n </AthenaThreadIdContext.Provider>\n ) : (\n scope\n )}\n </>\n );\n}\n\n// ─── Thread List Mode ─────────────────────────────────────────────────\n\nfunction AthenaStatewireWithThreadList({\n children,\n backendUrl,\n syncUrl,\n appId,\n apiKey,\n token,\n getToken,\n initialThreadId,\n includePullRequests,\n ...standaloneProps\n}: Omit<AthenaStatewireStandaloneProps, 'threadId' | 'threadList'> & {\n initialThreadId?: string;\n includePullRequests?: boolean;\n}) {\n return (\n <AthenaStatewireThreadListProvider\n backendUrl={backendUrl}\n syncUrl={syncUrl}\n apiKey={apiKey}\n token={token}\n getToken={getToken}\n appId={appId}\n initialThreadId={initialThreadId}\n includePullRequests={includePullRequests}\n // The list's hover prefetch warms the same cache the active-thread\n // mount seeds from, so a hovered-then-selected session paints at once.\n snapshotCache={standaloneProps.snapshotCache}\n >\n <AthenaStatewireActiveThreadHost\n backendUrl={backendUrl}\n syncUrl={syncUrl}\n appId={appId}\n apiKey={apiKey}\n token={token}\n getToken={getToken}\n {...standaloneProps}\n >\n {children}\n </AthenaStatewireActiveThreadHost>\n </AthenaStatewireThreadListProvider>\n );\n}\n\nfunction AthenaStatewireActiveThreadHost({\n children,\n ...standaloneProps\n}: Omit<AthenaStatewireStandaloneProps, 'threadId' | 'threadList'>) {\n const list = useAthenaStatewireThreadList();\n if (!list) return null;\n\n // Not keyed: the scope keeps the host's children mounted across a switch\n // and remounts only its per-thread runtime against the new\n // `…/v2/threads/{id}` URL (see `AthenaStatewireStandalone`).\n return (\n <AthenaStatewireStandalone\n threadId={list.activeThreadId}\n threadList={{ isNewChat: list.isNewChat }}\n {...standaloneProps}\n >\n <StatewireThreadTitlePoller />\n <AssetPanelThreadSync />\n {children}\n </AthenaStatewireStandalone>\n );\n}\n\n/**\n * Syncs the active thread ID into the asset panel store so that open asset\n * tabs are scoped per-thread automatically.\n *\n * Scoped by the attached thread's minted id from creation onward — NOT by\n * `useAthenaThreadManager().activeThreadId`, which is deliberately `null`\n * while a new chat is unpersisted (so URL sync never names it). The minted id\n * is the id the thread persists under, so tabs opened in a brand-new chat\n * stay put when the backend first lists it instead of being left behind in a\n * `null` scope the store never restores. Read from the statewire scope (the\n * id published with its client) rather than the list's selection, which runs\n * one commit ahead of the client during a switch.\n */\nfunction AssetPanelThreadSync() {\n const threadId = useAthenaStatewireThreadId();\n const setCurrentThread = useAssetPanelStore((s) => s.setCurrentThread);\n\n useEffect(() => {\n setCurrentThread(threadId);\n }, [threadId, setCurrentThread]);\n\n return null;\n}\n\n// ─── Main Provider ────────────────────────────────────────────────────\n\nexport function AthenaProvider({\n children,\n config,\n apiKey,\n token: tokenProp,\n agent,\n channel,\n model,\n tools = [],\n frontendTools = {},\n disableAutoOpen = false,\n apiUrl,\n backendUrl,\n appUrl,\n environment,\n statewireSyncUrl,\n getToken,\n extraRunConfig,\n workbench,\n knowledgeBase,\n systemPrompt,\n appId,\n threadId: threadIdProp,\n enableThreadList = false,\n threadListIncludePullRequests = true,\n theme,\n linkClicks,\n citationLinks,\n posthog: posthogProp,\n debug,\n onDiagnostic,\n onError,\n}: AthenaProviderProps) {\n // Fail loud before any effect, bridge wait, or network call: an `agent`\n // outside the collab_agent namespace can never apply, so a misconfigured\n // deployment must die at first render rather than answer as the wrong agent.\n resolveAgentProp({ agent });\n\n // Diagnostics wiring first, so everything below is observable. Callbacks\n // ride refs: a per-render closure must not re-register the consumer. Each\n // provider registers its OWN consumer (additive, cleaned up on unmount), so\n // two mounted providers never clobber each other's onDiagnostic/onError —\n // only the console/PostHog/buffer settings are global (last writer wins).\n const onDiagnosticRef = useRef(onDiagnostic);\n onDiagnosticRef.current = onDiagnostic;\n const onErrorRef = useRef(onError);\n onErrorRef.current = onError;\n useEffect(() => {\n installAthenaDiagnosticsGlobal();\n return athenaDiagnostics.addConsumer({\n onEvent: (event) => onDiagnosticRef.current?.(event),\n onError: (error, event) => onErrorRef.current?.(error, event),\n });\n }, []);\n const debugKey = JSON.stringify(debugPropToDiagnosticsConfig(debug));\n useEffect(() => {\n athenaDiagnostics.configure(debugPropToDiagnosticsConfig(debug));\n // debugKey is the value-stable form of `debug` (consumers pass literals).\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [debugKey]);\n // Only declarations WITHOUT a local `execute` ride `enabled_tools`: they name\n // registry tools the backend binds itself. Executable tools are declared\n // through `client_tools` instead — listing them here too would switch on a\n // backend toolkit owning a tool of the same name, and the backend wins that\n // collision (the client tool is silently dropped).\n const frontendToolNames = useMemo(\n () => backendDeclaredFrontendToolIds(frontendTools),\n [frontendTools],\n );\n // Merge SDK auto-open defaults under the consumer's frontendTools. Consumer\n // entries win on name collision; auto-open tool names are NOT added to\n // frontendToolIds (they are already backend-advertised by their toolkits).\n const effectiveFrontendTools = useMemo<Toolkit>(\n () => (disableAutoOpen ? frontendTools : { ...DEFAULT_AUTO_OPEN_TOOLS, ...frontendTools }),\n [disableAutoOpen, frontendTools],\n );\n const themeStyleVars = useMemo(() => theme ? themeToStyleVars(theme) : undefined, [theme]);\n const configuredEnvironment = config?.environment ?? environment;\n const environmentUrls = useMemo(\n () => getAthenaEnvironmentUrls({ environment: configuredEnvironment }),\n [configuredEnvironment],\n );\n const configuredApiKey = config?.apiKey ?? apiKey;\n const configuredToken = resolveTokenOverride({ config, token: tokenProp });\n const configuredApiUrl = config?.apiUrl ?? apiUrl;\n const configuredBackendUrl = config?.backendUrl ?? backendUrl;\n const configuredAppUrl = config?.appUrl ?? appUrl;\n const configuredStatewireSyncUrl = config?.statewireSyncUrl ?? statewireSyncUrl;\n const configuredGetToken = config?.getToken ?? getToken;\n const configuredExtraRunConfig = config?.extraRunConfig ?? extraRunConfig;\n const configuredTrustedParentOrigins = config?.trustedParentOrigins;\n const posthogConfig: PostHogConfig | undefined = config?.posthog ?? posthogProp;\n\n // Statewire is the SDK's only chat transport; the gauge/event stay on the\n // diagnostics contract so dashboards keyed on them keep reading a value.\n useEffect(() => {\n athenaDiagnostics.gauge('sdk.transport', 'statewire');\n athenaDiagnostics.emit('sdk.transport', {\n level: 'debug',\n data: { transport: 'statewire', thread_list: enableThreadList },\n });\n }, [enableThreadList]);\n\n const bridge = useParentBridge({\n trustedOrigins: configuredTrustedParentOrigins,\n });\n\n // If an AthenaAuthProvider is present above us, use its access token automatically.\n const authContext = useContext(AthenaAuthContext);\n const authProviderToken = authContext?.accessToken ?? null;\n\n // Per-provider snapshot cache: a switch back to a recently-visited thread\n // mounts with its last-known snapshot instead of a loading spinner. Owned\n // here, above the per-thread keyed mount, so it survives switches; cleared\n // when the acting identity changes so a snapshot captured under one account\n // never seeds a mount under another.\n const [snapshotCache] = useState(() => createDeepAgentThreadSnapshotCache());\n // Composer writes that arrive before the per-thread mount is ready wait\n // here, above that mount, so a thread-list remount cannot drop them.\n const [composerHandoff] = useState(createComposerHandoffStore);\n // The windowed wire's fetched-back tool outputs, owned alongside the cache\n // for the same reasons: shared across the provider's thread switches (a\n // tool message id is unique across threads), dropped with the identity.\n const [toolOutputs] = useState(() => createDeepAgentToolOutputStore());\n const principal = authContext?.user?.userId ?? '';\n useEffect(() => {\n snapshotCache.clear();\n toolOutputs.clear();\n // A draft or send queued under the previous identity must never land in\n // this one's composer.\n clearComposerHandoff({ store: composerHandoff, reason: 'the signed-in identity changed' });\n }, [snapshotCache, toolOutputs, composerHandoff, principal, configuredApiKey]);\n // Nothing drains after the provider is gone: settle what still waits so no\n // `useSendMessage` caller hangs.\n useEffect(\n () => () => clearComposerHandoff({ store: composerHandoff, reason: 'the chat provider unmounted' }),\n [composerHandoff],\n );\n\n const effectiveToken = configuredToken !== undefined\n ? configuredToken\n : authProviderToken ?? bridge.token;\n // Explicit config wins. A Marathon host mints the statewire mount, the bare\n // Agora base and the app origin outright (`/_athena/auth`, or a trusted\n // parent's `athena-config`); the environment preset is the last resort, and\n // the sync mount derives from the `apiUrl` host when no host minted one.\n const effectiveApiUrl = configuredApiUrl ?? environmentUrls.apiUrl;\n // Published as the bare Agora base: a historical `…/api/assistant-ui` value\n // is trimmed here once rather than by each REST helper.\n const effectiveBackendUrl = getAthenaApiBaseUrl(\n configuredBackendUrl ?? bridge.backendBaseUrl ?? environmentUrls.backendUrl,\n );\n const hostStatewireSyncUrl = configuredStatewireSyncUrl ?? bridge.statewireSyncUrl ?? undefined;\n const effectiveAppUrl = configuredAppUrl\n ?? bridge.appUrl\n ?? deriveAthenaAppUrl({ apiUrl: effectiveApiUrl, backendUrl: effectiveBackendUrl })\n ?? environmentUrls.appUrl;\n\n // Wait for the parent bridge to deliver config/auth before rendering.\n // This prevents the thread list from fetching with wrong URLs or no token.\n // Falls back after a short timeout (2s) if no bridge responds.\n if (!bridge.ready) {\n return null;\n }\n\n // Both throw on an unresolvable configuration instead of falling back to an\n // Athena default — a custom deployment's credentials must never be sent to\n // a host the consumer didn't configure. A host that answered the bridge\n // without minting the statewire mount is that case: its token would\n // otherwise ride the environment preset.\n assertHostMintedStatewireMount({\n hostAnswered: bridge.hostAnswered,\n hostStatewireSyncUrl: bridge.statewireSyncUrl,\n statewireSyncUrl: configuredStatewireSyncUrl,\n apiUrl: configuredApiUrl,\n });\n const effectiveStatewireSyncUrl = resolveStatewireSyncUrl({\n statewireSyncUrl: hostStatewireSyncUrl,\n apiUrl: effectiveApiUrl,\n });\n\n const statewireProps = {\n syncUrl: effectiveStatewireSyncUrl,\n backendUrl: effectiveBackendUrl,\n appUrl: effectiveAppUrl,\n apiKey: configuredApiKey,\n token: effectiveToken,\n getToken: configuredGetToken,\n model,\n agent,\n channel,\n tools,\n frontendToolIds: frontendToolNames,\n frontendTools: effectiveFrontendTools,\n workbench,\n knowledgeBase,\n systemPrompt,\n appId,\n extraRunConfig: configuredExtraRunConfig,\n snapshotCache,\n toolOutputs,\n linkClicks,\n citationLinks,\n };\n\n const inner: ReactNode = enableThreadList ? (\n <AthenaStatewireWithThreadList\n {...statewireProps}\n initialThreadId={threadIdProp}\n includePullRequests={threadListIncludePullRequests}\n >\n {children}\n </AthenaStatewireWithThreadList>\n ) : (\n <AthenaStatewireStandalone {...statewireProps} threadId={threadIdProp}>\n {children}\n </AthenaStatewireStandalone>\n );\n\n // The .athena-sdk wrapper (display: contents) anchors the SDK's design\n // tokens and scoped preflight from styles.css, so the stylesheet works\n // in hosts without their own Tailwind build. PostHog gracefully no-ops\n // when its config is missing.\n return (\n <div\n className={themeStyleVars ? \"athena-sdk athena-themed\" : \"athena-sdk\"}\n style={themeStyleVars as React.CSSProperties | undefined}\n >\n <PostHogProvider config={posthogConfig}>\n <ComposerHandoffContext.Provider value={composerHandoff}>\n {inner}\n </ComposerHandoffContext.Provider>\n </PostHogProvider>\n </div>\n );\n}\n"],"names":["useRef","useMemo","useAui","useComposerHandoffStore","useContext","AthenaStatewireThreadIdContext","useComposerReady","useEffect","drainComposerHandoff","toolOutputs","useReducer","statewireLifecycleReducer","initialStatewireLifecycle","useAthenaStatewireRuntime","athenaStatewireErrorNotice","useCallback","useLayoutEffect","mintThreadId","useState","useStatewireClientTools","resolveClientToolSurface","athenaDiagnostics","AthenaSdkError","jsx","AuiProvider","AthenaContext","AthenaStatewireLifecycleContext","DeepAgentConnectionContext","StatewireToolOutputsContext","TooltipProvider","StatewireClientToolBridge","jsxs","Fragment","AthenaThreadIdContext","AthenaStatewireThreadListProvider","useAthenaStatewireThreadList","StatewireThreadTitlePoller","useAthenaStatewireThreadId","useAssetPanelStore","resolveAgentProp","installAthenaDiagnosticsGlobal","_a","debugPropToDiagnosticsConfig","backendDeclaredFrontendToolIds","DEFAULT_AUTO_OPEN_TOOLS","themeToStyleVars","getAthenaEnvironmentUrls","useParentBridge","AthenaAuthContext","createDeepAgentThreadSnapshotCache","composerHandoff","createComposerHandoffStore","createDeepAgentToolOutputStore","clearComposerHandoff","getAthenaApiBaseUrl","deriveAthenaAppUrl","assertHostMintedStatewireMount","resolveStatewireSyncUrl","PostHogProvider","ComposerHandoffContext"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgPA,MAAM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A,IACA;AAAA,IACA,iBAAiB;AAAA,IACjB,eAAe;AAAA,IACf;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,gBAAgB;AAAA,IAChB;AAAA,IAAA,aACAhD;AAAAA,IACA;AAAA,IACA;AAAA,EAAA;AAGF,QAAM,QAAmB,mBACvBc,2BAAAA;AAAAA,IAAC;AAAA,IAAA;AAAA,MACE,GAAG;AAAA,MACJ,iBAAiB;AAAA,MACjB,qBAAqB;AAAA,MAEpB;AAAA,IAAA;AAAA,EAAA,IAGHA,2BAAAA,IAAC,2BAAA,EAA2B,GAAG,gBAAgB,UAAU,cACtD,UACH;AAOF,SACEA,2BAAAA;AAAAA,IAAC;AAAA,IAAA;AAAA,MACC,WAAW,iBAAiB,6BAA6B;AAAA,MACzD,OAAO;AAAA,MAEP,UAAAA,2BAAAA,IAACmC,gBAAAA,iBAAA,EAAgB,QAAQ,eACvB,UAAAnC,2BAAAA,IAACoC,gBAAAA,uBAAuB,UAAvB,EAAgC,OAAOT,mBACrC,UAAA,MAAA,CACH,EAAA,CACF;AAAA,IAAA;AAAA,EAAA;AAGN;;"}
1
+ {"version":3,"file":"AthenaProvider.cjs","sources":["../../src/provider/AthenaProvider.tsx"],"sourcesContent":["import { AuiProvider, useAui } from '@assistant-ui/react';\nimport {\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useMemo,\n useReducer,\n useRef,\n useState,\n type ReactNode,\n} from 'react';\nimport type { AssistantClient, Toolkit } from '@assistant-ui/react';\nimport {\n createDeepAgentThreadSnapshotCache,\n createDeepAgentToolOutputStore,\n DeepAgentConnectionContext,\n type DeepAgentThreadSnapshotCache,\n type DeepAgentToolOutputStore,\n} from '@athenaintel/agent-runtime';\nimport {\n assertHostMintedStatewireMount,\n deriveAthenaAppUrl,\n getAthenaEnvironmentUrls,\n resolveStatewireSyncUrl,\n type AthenaEnvironment,\n} from '../lib/athena-urls';\nimport { getAthenaApiBaseUrl } from '../collab/mint';\nimport { useParentBridge } from '../runtime/auth';\nimport { AthenaAuthContext } from '../auth/AthenaAuthContext';\nimport { AthenaCredentialSourceContext } from '../auth/AthenaCredentialSourceContext';\nimport {\n createAthenaCredentialSource,\n type AthenaCredentialInputs,\n} from '../auth/credential-source';\nimport { useRestartAfterAuthRefusal } from '../runtime/auth-refusal-restart';\nimport {\n useAthenaStatewireRuntime,\n useStatewireClientTools,\n} from '../runtime/useAthenaStatewireRuntime';\nimport {\n athenaStatewireErrorNotice,\n type AthenaStatewireLifecycleState,\n initialStatewireLifecycle,\n statewireLifecycleReducer,\n} from '../runtime/statewire-lifecycle';\nimport type { AthenaStatewireTokenGetter } from '../runtime/statewire-auth-headers';\nimport { resolveAgentProp } from '../runtime/statewire-run-config';\nimport { mintThreadId } from '../threads/mint-thread-id';\nimport { AthenaStatewireLifecycleContext } from './statewire-lifecycle-context';\nimport {\n ComposerHandoffContext,\n clearComposerHandoff,\n createComposerHandoffStore,\n drainComposerHandoff,\n useComposerHandoffStore,\n useComposerReady,\n} from '../composer/composer-handoff';\nimport { StatewireToolOutputsContext } from './statewire-window-context';\nimport { StatewireClientToolBridge } from '../chat/StatewireClientToolBridge';\nimport {\n athenaDiagnostics,\n debugPropToDiagnosticsConfig,\n installAthenaDiagnosticsGlobal,\n type AthenaDiagnosticEvent,\n type AthenaDiagnosticLevel,\n type AthenaDiagnosticsConfig,\n} from '../diagnostics/athena-diagnostics';\nimport { AthenaSdkError } from '../diagnostics/errors';\nimport {\n backendDeclaredFrontendToolIds,\n resolveClientToolSurface,\n} from '../chat/statewire-client-tools';\nimport { TooltipProvider } from '../ui/tooltip';\nimport { DEFAULT_AUTO_OPEN_TOOLS } from '../tools/auto-open-tools';\nimport { AthenaContext, type AthenaConfig } from './AthenaContext';\nimport type { AthenaProviderConfig } from './config';\nimport type {\n AthenaCitationLinkOptions,\n AthenaLinkClickOptions,\n} from './citation-links';\nimport {\n AthenaStatewireThreadIdContext,\n AthenaThreadIdContext,\n useAthenaStatewireThreadId,\n} from '../threads/thread-id-context';\nimport {\n AthenaStatewireThreadListProvider,\n StatewireThreadTitlePoller,\n useAthenaStatewireThreadList,\n} from '../threads/statewire-thread-list';\nimport { useAssetPanelStore } from '../assets/asset-panel-store';\nimport { themeToStyleVars, type AthenaTheme } from '../theme';\nimport { AthenaThemeStyleContext } from './theme-style-context';\nimport { PostHogProvider, type PostHogConfig } from './PostHogProvider';\n\nexport interface AthenaProviderProps {\n children: ReactNode;\n\n /** Preferred structured config for auth and Athena endpoint settings. */\n config?: AthenaProviderConfig;\n\n /** @deprecated Prefer `config.apiKey`. API key for authentication in standalone mode. */\n apiKey?: string;\n\n /** @deprecated Prefer `config.token`. PropelAuth token. If provided, takes priority over apiKey. If omitted, the SDK\n * will automatically listen for a token from the parent window via PostMessage. */\n token?: string | null;\n\n /** Run the thread AS a published collab agent. The only accepted shape is\n * `collab_agent:<asset_id>`: the thread then uses that agent's prompt,\n * tools, and model default, and the caller must have view access to the\n * agent asset. Omit it (or pass a blank string) to run the Athena deep agent.\n *\n * Any other non-blank value throws at render — the statewire host cannot\n * honour named agents, and a selector that is silently dropped would let a\n * misconfigured deployment answer as the wrong agent. */\n agent?: string;\n\n /** Collab-agent channel id — a built-in channel (`email`, `sms`, …) or a\n * user-defined custom channel id from the agent's Channels tab. Selects\n * that channel's configuration overrides and stamps the session's origin.\n * Only meaningful together with a `collab_agent:<asset_id>` `agent`; sent\n * as `collab_channel_id`. An unknown or disabled channel rejects the run\n * with a structured, teaching error. */\n channel?: string;\n\n /** LLM model identifier. Defaults to the deep-agent default model\n * (`DEFAULT_STATEWIRE_MODEL`) — or, when a collab agent is selected, to\n * the model its author configured. */\n model?: string;\n\n /** Backend toolkit IDs to enable (e.g. 'document_toolkit', 'web_search_browse_toolkit'). */\n tools?: string[];\n\n /** Frontend tools that execute in the browser. The agent can invoke these.\n * Merged on top of the SDK's default auto-open tools; entries here take\n * precedence over defaults with the same name. Tools with a local\n * `execute` are declared to the backend as `client_tools` and run through\n * the statewire client-tool bridge. */\n frontendTools?: Toolkit;\n\n /** Disable the SDK's default auto-open behavior for created/touched assets. */\n disableAutoOpen?: boolean;\n\n /** @deprecated Prefer `config.apiUrl`. URL on the Iris host fronting the\n * deployment; its origin derives the statewire sync mount when\n * `statewireSyncUrl` is not set. */\n apiUrl?: string;\n\n /** @deprecated Prefer `config.backendUrl`. URL for the Athena backend API. */\n backendUrl?: string;\n\n /** @deprecated Prefer `config.appUrl`. URL for the Athena frontend app origin. */\n appUrl?: string;\n\n /** @deprecated Prefer `config.environment`. Athena environment preset used when URLs are not explicitly provided. */\n environment?: AthenaEnvironment;\n\n /** Resolve the latest auth token immediately before a request (for\n * expiring clients). Takes priority over `token` when it resolves.\n * Prefer `config.getToken` (see its `force` contract for refused\n * credentials). */\n getToken?: AthenaStatewireTokenGetter;\n\n /** Additional fields merged into runConfig.custom. Prefer\n * `config.extraRunConfig`. */\n extraRunConfig?: Record<string, unknown>;\n\n /** Statewire sync base URL override (the `…/v2/threads` mount). Defaults to\n * the mount a Marathon host mints, then the effective `apiUrl` host +\n * `/v2/threads`. Prefer `config.statewireSyncUrl`. */\n statewireSyncUrl?: string;\n\n /** Asset IDs to include in the workbench. */\n workbench?: string[];\n\n /** Knowledge base IDs for RAG context. */\n knowledgeBase?: string[];\n\n /** System prompt override. */\n systemPrompt?: string;\n\n /** Client app identifier for session filtering.\n * Sessions created with this ID can be filtered in the thread list.\n * E.g. \"olympus\", \"athena-app\", or a computer asset ID like \"asset_<uuid>\". */\n appId?: string;\n\n /** Thread ID override. Auto-generated if not provided. */\n threadId?: string;\n\n /** Enable thread list management (sidebar thread switching). */\n enableThreadList?: boolean;\n\n /** Ask the thread list for live pull-request state on each session\n * (`include_pull_requests`), which `SessionList` renders as chips.\n * Defaults to `true` in thread-list mode; turn it off in a host that never\n * shows them to spare the server the lookup. */\n threadListIncludePullRequests?: boolean;\n\n /** Theme configuration. Pass a preset from `themes` or a custom `AthenaTheme` object.\n * Injects CSS variables on a wrapper element — no CSS files needed.\n *\n * @example\n * import { themes } from '@athenaintel/react';\n * <AthenaProvider theme={themes.dark}>\n *\n * @example\n * <AthenaProvider theme={{ primary: '#8b5cf6', radius: '1rem' }}>\n *\n * @example\n * <AthenaProvider theme={{ ...themes.dark, primary: '#22c55e' }}>\n */\n theme?: AthenaTheme;\n\n /** Customize how rendered chat links behave. */\n linkClicks?: AthenaLinkClickOptions;\n\n /** @deprecated Prefer `linkClicks`. Customize how Athena citation links rendered in chat messages behave. */\n citationLinks?: AthenaCitationLinkOptions;\n\n /** PostHog analytics configuration. When omitted or keys are missing, PostHog is silently disabled.\n * Prefer `config.posthog` for structured configuration. */\n posthog?: PostHogConfig;\n\n /** SDK diagnostics.\n *\n * - `true` / a level: echo structured `[AthenaSDK]` events to the console\n * at that level (`true` = 'debug').\n * - An object: full diagnostics config (console level, PostHog timing\n * forwarding, buffer size).\n *\n * Independent of the prop, `localStorage.setItem('athena:debug','debug')`\n * (or `window.__ATHENA_SDK__.diagnostics.enableConsole()`) turns console\n * echo on at runtime without a rebuild. Errors log once even when off. */\n debug?: boolean | AthenaDiagnosticLevel | Partial<AthenaDiagnosticsConfig>;\n\n /** Receives every diagnostics event (timings, warnings, errors) — the hook\n * for shipping SDK telemetry to the host app's own pipeline. */\n onDiagnostic?: (event: AthenaDiagnosticEvent) => void;\n\n /** Receives every SDK error as a typed `AthenaSdkError` (stable `code`,\n * `hint`, structured server `detail`). Fires in addition to the UI's own\n * error handling, so integrations never fail silently. */\n onError?: (error: AthenaSdkError, event: AthenaDiagnosticEvent) => void;\n}\n\nconst resolveTokenOverride = ({\n config,\n token,\n}: {\n config?: AthenaProviderConfig;\n token?: string | null;\n}): string | null | undefined => {\n if (config?.token !== undefined) {\n return config.token;\n }\n return token;\n};\n\nconst useAthenaConfigValue = ({\n backendUrl,\n appUrl,\n apiKey,\n token,\n getToken,\n enabledToolkits,\n linkClicks,\n citationLinks,\n}: {\n backendUrl: string;\n appUrl: string;\n apiKey?: string;\n token?: string | null;\n getToken?: AthenaStatewireTokenGetter;\n enabledToolkits: string[];\n linkClicks?: AthenaLinkClickOptions;\n citationLinks?: AthenaCitationLinkOptions;\n}): AthenaConfig => {\n const linkClicksRef = useRef(linkClicks);\n linkClicksRef.current = linkClicks;\n const citationLinksRef = useRef(citationLinks);\n citationLinksRef.current = citationLinks;\n // Keep token in a ref so its value can update without invalidating the\n // config object identity. PropelAuth rotates tokens on window focus —\n // if token were a memo dep, every rotation would publish a new config\n // object to context and force every consumer (e.g. AssetIframe) to\n // re-render, causing asset panel flicker.\n const tokenRef = useRef(token);\n tokenRef.current = token;\n const getTokenRef = useRef(getToken);\n getTokenRef.current = getToken;\n\n return useMemo(\n () => ({\n backendUrl,\n appUrl,\n apiKey,\n enabledToolkits,\n get token() {\n return tokenRef.current;\n },\n get getToken() {\n return getTokenRef.current;\n },\n get linkClicks() {\n return linkClicksRef.current;\n },\n get citationLinks() {\n return citationLinksRef.current;\n },\n }),\n [backendUrl, appUrl, apiKey, enabledToolkits],\n );\n};\n\n/**\n * Delivers composer writes that were made before this mount was ready\n * (`useAppendToComposer` / `useSendMessage` queue them in the provider-level\n * store, which outlives the keyed per-thread mount). Lives under the\n * `AuiProvider` so it can read the thread's own loading state.\n */\nfunction ComposerHandoffDrain(): null {\n const aui = useAui();\n const store = useComposerHandoffStore();\n const threadId = useContext(AthenaStatewireThreadIdContext);\n const ready = useComposerReady();\n useEffect(() => {\n if (!ready || !store) return;\n // Writes bound to another thread are dropped here, not applied.\n drainComposerHandoff({ store, target: aui, threadId });\n }, [aui, ready, store, threadId]);\n return null;\n}\n\n// ─── Standalone Mode ──────────────────────────────────────────────────\n\n/** Everything the per-thread runtime needs to attach and run a thread. */\ninterface AthenaStatewireRuntimeProps {\n syncUrl: string;\n apiKey?: string;\n token?: string | null;\n getToken?: AthenaStatewireTokenGetter;\n model?: string;\n agent?: string;\n channel?: string;\n tools: string[];\n frontendToolIds: string[];\n frontendTools: Toolkit;\n workbench?: string[];\n knowledgeBase?: string[];\n systemPrompt?: string;\n appId?: string;\n extraRunConfig?: Record<string, unknown>;\n /** The provider-owned snapshot cache (see `AthenaProvider`). */\n snapshotCache: DeepAgentThreadSnapshotCache;\n /** The provider-owned store of fetched-back cut tool outputs (see `AthenaProvider`). */\n toolOutputs: DeepAgentToolOutputStore;\n}\n\ninterface AthenaStatewireStandaloneProps extends AthenaStatewireRuntimeProps {\n children: ReactNode;\n backendUrl: string;\n appUrl: string;\n threadId?: string;\n /**\n * Thread-list mode. The list owns the active id and alone knows whether the\n * backend has listed it yet: `isNewChat` overrides the \"new chat\"\n * derivation (the list mints ids for brand-new chats, which must still load\n * as new), and the scope publishes `AthenaThreadIdContext` — the backend id,\n * withheld while the chat is unpersisted. Absent outside thread-list mode,\n * where that context stays untouched.\n */\n threadList?: { isNewChat: boolean };\n linkClicks?: AthenaLinkClickOptions;\n citationLinks?: AthenaCitationLinkOptions;\n}\n\n/**\n * What one per-thread runtime mount hands to the stable scope around the\n * host's children: the assistant client attached to `threadId` and the\n * transport lifecycle observed on that attach. Published as ONE value so the\n * scope can never pair a thread's id with another thread's client.\n */\ninterface AthenaStatewireRuntimeSnapshot {\n threadId: string;\n isNewChat: boolean;\n client: AssistantClient;\n lifecycle: AthenaStatewireLifecycleState;\n}\n\n/**\n * The per-thread half of the statewire lane: owns the runtime hook (statewire\n * client, pending-message lane, `useAui` client) and the lifecycle reducer\n * behind the connection/error banners, and renders nothing itself. Mounted\n * under `key={threadId}` so a switch — or a new chat — gets a fresh instance\n * of everything here, exactly as when the whole provider subtree was keyed,\n * without remounting the host's UI.\n *\n * An assistant client's readable state only advances when its tap fibers\n * commit (in effects), so an in-place `threadId` change on one mounted hook\n * would leave a commit in which the new id is published but `useAuiState`\n * still reads the previous thread's committed state; a fresh mount publishes\n * its own state on its first render. That is why the runtime is remounted per\n * thread rather than switched in place.\n *\n * The snapshot is published from a layout effect: React flushes the state\n * update a layout effect schedules synchronously, before the browser paints,\n * so the scope re-renders against this client in the same task as this\n * mount's commit — the previous client is never painted under the new id.\n */\nfunction AthenaStatewireRuntimeMount({\n threadId,\n isNewChat,\n onPublish,\n syncUrl,\n apiKey,\n token,\n getToken,\n model,\n agent,\n channel,\n tools,\n frontendToolIds,\n frontendTools,\n workbench,\n knowledgeBase,\n systemPrompt,\n appId,\n extraRunConfig,\n snapshotCache,\n toolOutputs,\n}: AthenaStatewireRuntimeProps & {\n threadId: string;\n isNewChat: boolean;\n onPublish: (snapshot: AthenaStatewireRuntimeSnapshot) => void;\n}): null {\n const [lifecycle, dispatchLifecycle] = useReducer(\n statewireLifecycleReducer,\n initialStatewireLifecycle,\n );\n\n const client = useAthenaStatewireRuntime({\n syncUrl,\n threadId,\n isNewChat,\n apiKey,\n token,\n getToken,\n model,\n agent,\n channel,\n tools,\n frontendToolIds,\n frontendToolkit: frontendTools,\n workbench,\n knowledgeBase,\n systemPrompt,\n appId,\n extraRunConfig,\n snapshotCache,\n toolOutputs,\n // The runtime already records every transport error on the diagnostics\n // bus (with the channel-teardown split), so this layer only maps it to\n // the banner notice.\n onError: (error) => {\n const notice = athenaStatewireErrorNotice(error);\n if (notice) dispatchLifecycle({ type: 'error', error: notice });\n },\n onConnectionChange: (connection) => {\n dispatchLifecycle({ type: 'connection', connection });\n },\n onRawConnectionChange: (connection) => {\n dispatchLifecycle({ type: 'raw-connection', reconnect: connection.reconnect });\n },\n });\n\n // A thread the host stopped for refusing its credential reconnects as soon\n // as a new token exists, instead of waiting for a retry click.\n useRestartAfterAuthRefusal({\n connection: lifecycle.connection,\n reconnect: lifecycle.reconnect,\n });\n\n const dismissError = useCallback(\n () => dispatchLifecycle({ type: 'error', error: null }),\n [],\n );\n const lifecycleValue = useMemo<AthenaStatewireLifecycleState>(\n () => ({\n connection: lifecycle.connection,\n error: lifecycle.error,\n reconnect: lifecycle.reconnect,\n dismissError,\n }),\n [lifecycle, dismissError],\n );\n\n const snapshot = useMemo<AthenaStatewireRuntimeSnapshot>(\n () => ({ threadId, isNewChat, client, lifecycle: lifecycleValue }),\n [threadId, isNewChat, client, lifecycleValue],\n );\n useLayoutEffect(() => {\n onPublish(snapshot);\n }, [onPublish, snapshot]);\n\n return null;\n}\n\n/**\n * The stable half of the statewire lane: the scope around the host's\n * `children`. It mounts one `AthenaStatewireRuntimeMount` per thread beside\n * them and provides whatever that mount last published — client, thread ids,\n * lifecycle — so a thread switch swaps the client under the host's UI instead\n * of remounting it. Until the first mount has published, the children are\n * withheld: they need a client, and the first publication lands in the same\n * task as the mount's commit.\n *\n * A server render runs no effects, so it would withhold the children too.\n * That changes nothing today: `AthenaProvider` renders `null` until the parent\n * bridge reports ready, which only ever happens in an effect (`useParentBridge`\n * starts `ready: false`), so the SDK has never server-rendered the host UI —\n * it hydrates it. A future SSR-ready bridge would need the first publication\n * to happen in render as well.\n */\nfunction AthenaStatewireStandalone({\n children,\n backendUrl,\n appUrl,\n threadId: threadIdProp,\n threadList,\n linkClicks,\n citationLinks,\n ...runtimeProps\n}: AthenaStatewireStandaloneProps) {\n // Statewire attaches to `${syncUrl}/${threadId}`, so a thread ID must exist\n // up front. An auto-generated ID is by definition a never-started local chat.\n const generatedIdRef = useRef<string | null>(null);\n if (generatedIdRef.current === null) {\n generatedIdRef.current = mintThreadId();\n }\n const threadId = threadIdProp ?? generatedIdRef.current;\n const isNewChat = threadList?.isNewChat ?? !threadIdProp;\n\n const [published, setPublished] = useState<AthenaStatewireRuntimeSnapshot | null>(null);\n\n const clientTools = useStatewireClientTools(runtimeProps.frontendTools);\n\n // The runtime binds `client_tools` only for a recognised `app_id`; with none\n // it drops every declaration without telling the client, and the model then\n // sees \"not a valid tool\". Say so here, once per configuration, as an error\n // so it reaches `onError` and the console even with diagnostics off.\n const clientToolNamesKey = clientTools.map((tool) => tool.definition.name).join(',');\n const clientToolAppId = runtimeProps.appId;\n useEffect(() => {\n if (clientTools.length === 0 || resolveClientToolSurface(clientToolAppId) !== null) return;\n athenaDiagnostics.emit('sdk.config.warning', {\n level: 'error',\n error: new AthenaSdkError({\n code: 'config_invalid',\n message: `frontendTools with an execute() need a recognised appId; ${clientTools.length} tool(s) will not be bound.`,\n hint:\n \"Pass appId={publicAppId} on <AthenaProvider> (a computer-asset app reads it from athena-public-config.json as computer_asset_<uuid>). Without it the deep-agent runtime drops every client tool.\",\n context: { appId: clientToolAppId ?? null, tools: clientToolNamesKey.split(',') },\n }),\n data: { appId: clientToolAppId ?? null, tools: clientToolNamesKey.split(',') },\n });\n // clientToolNamesKey is the value-stable form of the tool list.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [clientToolAppId, clientToolNamesKey]);\n\n const athenaConfig = useAthenaConfigValue({\n backendUrl,\n appUrl,\n apiKey: runtimeProps.apiKey,\n token: runtimeProps.token,\n getToken: runtimeProps.getToken,\n enabledToolkits: runtimeProps.tools,\n linkClicks,\n citationLinks,\n });\n\n const scope = published && (\n <AuiProvider value={published.client}>\n <AthenaContext.Provider value={athenaConfig}>\n <AthenaStatewireThreadIdContext.Provider value={published.threadId}>\n <AthenaStatewireLifecycleContext.Provider value={published.lifecycle}>\n <DeepAgentConnectionContext.Provider value={published.lifecycle.connection}>\n <StatewireToolOutputsContext.Provider value={runtimeProps.toolOutputs}>\n <TooltipProvider>\n <StatewireClientToolBridge tools={clientTools} threadId={published.threadId} />\n <ComposerHandoffDrain />\n {children}\n </TooltipProvider>\n </StatewireToolOutputsContext.Provider>\n </DeepAgentConnectionContext.Provider>\n </AthenaStatewireLifecycleContext.Provider>\n </AthenaStatewireThreadIdContext.Provider>\n </AthenaContext.Provider>\n </AuiProvider>\n );\n\n return (\n <>\n <AthenaStatewireRuntimeMount\n key={threadId}\n threadId={threadId}\n isNewChat={isNewChat}\n onPublish={setPublished}\n {...runtimeProps}\n />\n {/* The backend id rides the same snapshot as the client, so\n history-gated UI (e.g. the loading overlay) never judges one thread\n by another's state; it is undefined for a never-started chat, which\n must not read as pending history. */}\n {threadList && published ? (\n <AthenaThreadIdContext.Provider\n value={published.isNewChat ? undefined : published.threadId}\n >\n {scope}\n </AthenaThreadIdContext.Provider>\n ) : (\n scope\n )}\n </>\n );\n}\n\n// ─── Thread List Mode ─────────────────────────────────────────────────\n\nfunction AthenaStatewireWithThreadList({\n children,\n backendUrl,\n syncUrl,\n appId,\n apiKey,\n token,\n getToken,\n initialThreadId,\n includePullRequests,\n ...standaloneProps\n}: Omit<AthenaStatewireStandaloneProps, 'threadId' | 'threadList'> & {\n initialThreadId?: string;\n includePullRequests?: boolean;\n}) {\n return (\n <AthenaStatewireThreadListProvider\n backendUrl={backendUrl}\n syncUrl={syncUrl}\n apiKey={apiKey}\n token={token}\n getToken={getToken}\n appId={appId}\n initialThreadId={initialThreadId}\n includePullRequests={includePullRequests}\n // The list's hover prefetch warms the same cache the active-thread\n // mount seeds from, so a hovered-then-selected session paints at once.\n snapshotCache={standaloneProps.snapshotCache}\n >\n <AthenaStatewireActiveThreadHost\n backendUrl={backendUrl}\n syncUrl={syncUrl}\n appId={appId}\n apiKey={apiKey}\n token={token}\n getToken={getToken}\n {...standaloneProps}\n >\n {children}\n </AthenaStatewireActiveThreadHost>\n </AthenaStatewireThreadListProvider>\n );\n}\n\nfunction AthenaStatewireActiveThreadHost({\n children,\n ...standaloneProps\n}: Omit<AthenaStatewireStandaloneProps, 'threadId' | 'threadList'>) {\n const list = useAthenaStatewireThreadList();\n if (!list) return null;\n\n // Not keyed: the scope keeps the host's children mounted across a switch\n // and remounts only its per-thread runtime against the new\n // `…/v2/threads/{id}` URL (see `AthenaStatewireStandalone`).\n return (\n <AthenaStatewireStandalone\n threadId={list.activeThreadId}\n threadList={{ isNewChat: list.isNewChat }}\n {...standaloneProps}\n >\n <StatewireThreadTitlePoller />\n <AssetPanelThreadSync />\n {children}\n </AthenaStatewireStandalone>\n );\n}\n\n/**\n * Syncs the active thread ID into the asset panel store so that open asset\n * tabs are scoped per-thread automatically.\n *\n * Scoped by the attached thread's minted id from creation onward — NOT by\n * `useAthenaThreadManager().activeThreadId`, which is deliberately `null`\n * while a new chat is unpersisted (so URL sync never names it). The minted id\n * is the id the thread persists under, so tabs opened in a brand-new chat\n * stay put when the backend first lists it instead of being left behind in a\n * `null` scope the store never restores. Read from the statewire scope (the\n * id published with its client) rather than the list's selection, which runs\n * one commit ahead of the client during a switch.\n */\nfunction AssetPanelThreadSync() {\n const threadId = useAthenaStatewireThreadId();\n const setCurrentThread = useAssetPanelStore((s) => s.setCurrentThread);\n\n useEffect(() => {\n setCurrentThread(threadId);\n }, [threadId, setCurrentThread]);\n\n return null;\n}\n\n// ─── Main Provider ────────────────────────────────────────────────────\n\nexport function AthenaProvider({\n children,\n config,\n apiKey,\n token: tokenProp,\n agent,\n channel,\n model,\n tools = [],\n frontendTools = {},\n disableAutoOpen = false,\n apiUrl,\n backendUrl,\n appUrl,\n environment,\n statewireSyncUrl,\n getToken,\n extraRunConfig,\n workbench,\n knowledgeBase,\n systemPrompt,\n appId,\n threadId: threadIdProp,\n enableThreadList = false,\n threadListIncludePullRequests = true,\n theme,\n linkClicks,\n citationLinks,\n posthog: posthogProp,\n debug,\n onDiagnostic,\n onError,\n}: AthenaProviderProps) {\n // Fail loud before any effect, bridge wait, or network call: an `agent`\n // outside the collab_agent namespace can never apply, so a misconfigured\n // deployment must die at first render rather than answer as the wrong agent.\n resolveAgentProp({ agent });\n\n // Diagnostics wiring first, so everything below is observable. Callbacks\n // ride refs: a per-render closure must not re-register the consumer. Each\n // provider registers its OWN consumer (additive, cleaned up on unmount), so\n // two mounted providers never clobber each other's onDiagnostic/onError —\n // only the console/PostHog/buffer settings are global (last writer wins).\n const onDiagnosticRef = useRef(onDiagnostic);\n onDiagnosticRef.current = onDiagnostic;\n const onErrorRef = useRef(onError);\n onErrorRef.current = onError;\n useEffect(() => {\n installAthenaDiagnosticsGlobal();\n return athenaDiagnostics.addConsumer({\n onEvent: (event) => onDiagnosticRef.current?.(event),\n onError: (error, event) => onErrorRef.current?.(error, event),\n });\n }, []);\n const debugKey = JSON.stringify(debugPropToDiagnosticsConfig(debug));\n useEffect(() => {\n athenaDiagnostics.configure(debugPropToDiagnosticsConfig(debug));\n // debugKey is the value-stable form of `debug` (consumers pass literals).\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [debugKey]);\n // Only declarations WITHOUT a local `execute` ride `enabled_tools`: they name\n // registry tools the backend binds itself. Executable tools are declared\n // through `client_tools` instead — listing them here too would switch on a\n // backend toolkit owning a tool of the same name, and the backend wins that\n // collision (the client tool is silently dropped).\n const frontendToolNames = useMemo(\n () => backendDeclaredFrontendToolIds(frontendTools),\n [frontendTools],\n );\n // Merge SDK auto-open defaults under the consumer's frontendTools. Consumer\n // entries win on name collision; auto-open tool names are NOT added to\n // frontendToolIds (they are already backend-advertised by their toolkits).\n const effectiveFrontendTools = useMemo<Toolkit>(\n () => (disableAutoOpen ? frontendTools : { ...DEFAULT_AUTO_OPEN_TOOLS, ...frontendTools }),\n [disableAutoOpen, frontendTools],\n );\n const themeStyleVars = useMemo(() => theme ? themeToStyleVars(theme) : undefined, [theme]);\n const configuredEnvironment = config?.environment ?? environment;\n const environmentUrls = useMemo(\n () => getAthenaEnvironmentUrls({ environment: configuredEnvironment }),\n [configuredEnvironment],\n );\n const configuredApiKey = config?.apiKey ?? apiKey;\n const configuredToken = resolveTokenOverride({ config, token: tokenProp });\n const configuredApiUrl = config?.apiUrl ?? apiUrl;\n const configuredBackendUrl = config?.backendUrl ?? backendUrl;\n const configuredAppUrl = config?.appUrl ?? appUrl;\n const configuredStatewireSyncUrl = config?.statewireSyncUrl ?? statewireSyncUrl;\n const configuredGetToken = config?.getToken ?? getToken;\n const configuredExtraRunConfig = config?.extraRunConfig ?? extraRunConfig;\n const configuredTrustedParentOrigins = config?.trustedParentOrigins;\n const posthogConfig: PostHogConfig | undefined = config?.posthog ?? posthogProp;\n\n // Statewire is the SDK's only chat transport; the gauge/event stay on the\n // diagnostics contract so dashboards keyed on them keep reading a value.\n useEffect(() => {\n athenaDiagnostics.gauge('sdk.transport', 'statewire');\n athenaDiagnostics.emit('sdk.transport', {\n level: 'debug',\n data: { transport: 'statewire', thread_list: enableThreadList },\n });\n }, [enableThreadList]);\n\n const bridge = useParentBridge({\n trustedOrigins: configuredTrustedParentOrigins,\n });\n\n // If an AthenaAuthProvider is present above us, use its access token automatically.\n const authContext = useContext(AthenaAuthContext);\n const authProviderToken = authContext?.accessToken ?? null;\n\n // Per-provider snapshot cache: a switch back to a recently-visited thread\n // mounts with its last-known snapshot instead of a loading spinner. Owned\n // here, above the per-thread keyed mount, so it survives switches; cleared\n // when the acting identity changes so a snapshot captured under one account\n // never seeds a mount under another.\n const [snapshotCache] = useState(() => createDeepAgentThreadSnapshotCache());\n // Composer writes that arrive before the per-thread mount is ready wait\n // here, above that mount, so a thread-list remount cannot drop them.\n const [composerHandoff] = useState(createComposerHandoffStore);\n // The windowed wire's fetched-back tool outputs, owned alongside the cache\n // for the same reasons: shared across the provider's thread switches (a\n // tool message id is unique across threads), dropped with the identity.\n const [toolOutputs] = useState(() => createDeepAgentToolOutputStore());\n const principal = authContext?.user?.userId ?? '';\n useEffect(() => {\n snapshotCache.clear();\n toolOutputs.clear();\n // A draft or send queued under the previous identity must never land in\n // this one's composer.\n clearComposerHandoff({ store: composerHandoff, reason: 'the signed-in identity changed' });\n }, [snapshotCache, toolOutputs, composerHandoff, principal, configuredApiKey]);\n // Nothing drains after the provider is gone: settle what still waits so no\n // `useSendMessage` caller hangs.\n useEffect(\n () => () => clearComposerHandoff({ store: composerHandoff, reason: 'the chat provider unmounted' }),\n [composerHandoff],\n );\n\n const effectiveToken = configuredToken !== undefined\n ? configuredToken\n : authProviderToken ?? bridge.token;\n\n // One credential source for every network path below: it presents the\n // token chosen above and renews it the way its origin can. A host's own\n // `getToken` owns renewal; a host's static `token` never renews; a sign-in\n // provider's token renews through its getter (PropelAuth, SSO); a host\n // bridge token through the bridge (a Marathon re-mint, or the parent\n // window's next `athena-auth`).\n const authProviderGetToken = authContext?.getToken;\n const credentialInputsRef = useRef<AthenaCredentialInputs>({ token: null });\n credentialInputsRef.current = {\n hostGetToken: configuredGetToken,\n token: effectiveToken,\n renew:\n configuredToken !== undefined\n ? undefined\n : authProviderToken !== null\n ? authProviderGetToken\n ? async ({ force }) => (await authProviderGetToken({ force })) ?? null\n : undefined\n : bridge.token !== null\n ? bridge.renewToken\n : undefined,\n };\n const [credentials] = useState(() =>\n createAthenaCredentialSource(() => credentialInputsRef.current),\n );\n useEffect(() => {\n credentials.notifyTokenChanged();\n }, [credentials, effectiveToken]);\n // Only a provider that holds a token (or a host getter) hands one out, so\n // \"has credentials\" checks downstream keep meaning what they did.\n const credentialGetToken =\n configuredGetToken !== undefined || effectiveToken ? credentials.getToken : undefined;\n // Explicit config wins. A Marathon host mints the statewire mount, the bare\n // Agora base and the app origin outright (`/_athena/auth`, or a trusted\n // parent's `athena-config`); the environment preset is the last resort, and\n // the sync mount derives from the `apiUrl` host when no host minted one.\n const effectiveApiUrl = configuredApiUrl ?? environmentUrls.apiUrl;\n // Published as the bare Agora base: a historical `…/api/assistant-ui` value\n // is trimmed here once rather than by each REST helper.\n const effectiveBackendUrl = getAthenaApiBaseUrl(\n configuredBackendUrl ?? bridge.backendBaseUrl ?? environmentUrls.backendUrl,\n );\n const hostStatewireSyncUrl = configuredStatewireSyncUrl ?? bridge.statewireSyncUrl ?? undefined;\n const effectiveAppUrl = configuredAppUrl\n ?? bridge.appUrl\n ?? deriveAthenaAppUrl({ apiUrl: effectiveApiUrl, backendUrl: effectiveBackendUrl })\n ?? environmentUrls.appUrl;\n\n // Wait for the parent bridge to deliver config/auth before rendering.\n // This prevents the thread list from fetching with wrong URLs or no token.\n // Falls back after a short timeout (2s) if no bridge responds.\n if (!bridge.ready) {\n return null;\n }\n\n // Both throw on an unresolvable configuration instead of falling back to an\n // Athena default — a custom deployment's credentials must never be sent to\n // a host the consumer didn't configure. A host that answered the bridge\n // without minting the statewire mount is that case: its token would\n // otherwise ride the environment preset.\n assertHostMintedStatewireMount({\n hostAnswered: bridge.hostAnswered,\n hostStatewireSyncUrl: bridge.statewireSyncUrl,\n statewireSyncUrl: configuredStatewireSyncUrl,\n apiUrl: configuredApiUrl,\n });\n const effectiveStatewireSyncUrl = resolveStatewireSyncUrl({\n statewireSyncUrl: hostStatewireSyncUrl,\n apiUrl: effectiveApiUrl,\n });\n\n const statewireProps = {\n syncUrl: effectiveStatewireSyncUrl,\n backendUrl: effectiveBackendUrl,\n appUrl: effectiveAppUrl,\n apiKey: configuredApiKey,\n token: effectiveToken,\n getToken: credentialGetToken,\n model,\n agent,\n channel,\n tools,\n frontendToolIds: frontendToolNames,\n frontendTools: effectiveFrontendTools,\n workbench,\n knowledgeBase,\n systemPrompt,\n appId,\n extraRunConfig: configuredExtraRunConfig,\n snapshotCache,\n toolOutputs,\n linkClicks,\n citationLinks,\n };\n\n const inner: ReactNode = enableThreadList ? (\n <AthenaStatewireWithThreadList\n {...statewireProps}\n initialThreadId={threadIdProp}\n includePullRequests={threadListIncludePullRequests}\n >\n {children}\n </AthenaStatewireWithThreadList>\n ) : (\n <AthenaStatewireStandalone {...statewireProps} threadId={threadIdProp}>\n {children}\n </AthenaStatewireStandalone>\n );\n\n // The .athena-sdk wrapper (display: contents) anchors the SDK's design\n // tokens and scoped preflight from styles.css, so the stylesheet works\n // in hosts without their own Tailwind build. PostHog gracefully no-ops\n // when its config is missing.\n return (\n <div\n className={themeStyleVars ? \"athena-sdk athena-themed\" : \"athena-sdk\"}\n style={themeStyleVars as React.CSSProperties | undefined}\n >\n <PostHogProvider config={posthogConfig}>\n <ComposerHandoffContext.Provider value={composerHandoff}>\n <AthenaThemeStyleContext.Provider value={themeStyleVars}>\n <AthenaCredentialSourceContext.Provider value={credentials}>\n {inner}\n </AthenaCredentialSourceContext.Provider>\n </AthenaThemeStyleContext.Provider>\n </ComposerHandoffContext.Provider>\n </PostHogProvider>\n </div>\n );\n}\n"],"names":["useRef","useMemo","useAui","useComposerHandoffStore","useContext","AthenaStatewireThreadIdContext","useComposerReady","useEffect","drainComposerHandoff","toolOutputs","useReducer","statewireLifecycleReducer","initialStatewireLifecycle","useAthenaStatewireRuntime","athenaStatewireErrorNotice","useRestartAfterAuthRefusal","useCallback","useLayoutEffect","mintThreadId","useState","useStatewireClientTools","resolveClientToolSurface","athenaDiagnostics","AthenaSdkError","jsx","AuiProvider","AthenaContext","AthenaStatewireLifecycleContext","DeepAgentConnectionContext","StatewireToolOutputsContext","TooltipProvider","StatewireClientToolBridge","jsxs","Fragment","AthenaThreadIdContext","AthenaStatewireThreadListProvider","useAthenaStatewireThreadList","StatewireThreadTitlePoller","useAthenaStatewireThreadId","useAssetPanelStore","resolveAgentProp","installAthenaDiagnosticsGlobal","_a","debugPropToDiagnosticsConfig","backendDeclaredFrontendToolIds","DEFAULT_AUTO_OPEN_TOOLS","themeToStyleVars","getAthenaEnvironmentUrls","useParentBridge","AthenaAuthContext","createDeepAgentThreadSnapshotCache","composerHandoff","createComposerHandoffStore","createDeepAgentToolOutputStore","clearComposerHandoff","createAthenaCredentialSource","getAthenaApiBaseUrl","deriveAthenaAppUrl","assertHostMintedStatewireMount","resolveStatewireSyncUrl","PostHogProvider","ComposerHandoffContext","AthenaThemeStyleContext","AthenaCredentialSourceContext"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuPA,MAAM,uBAAuB,CAAC;AAAA,EAC5B;AAAA,EACA;AACF,MAGiC;AAC/B,OAAI,iCAAQ,WAAU,QAAW;AAC/B,WAAO,OAAO;AAAA,EAChB;AACA,SAAO;AACT;AAEA,MAAM,uBAAuB,CAAC;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MASoB;AAClB,QAAM,gBAAgBA,MAAAA,OAAO,UAAU;AACvC,gBAAc,UAAU;AACxB,QAAM,mBAAmBA,MAAAA,OAAO,aAAa;AAC7C,mBAAiB,UAAU;AAM3B,QAAM,WAAWA,MAAAA,OAAO,KAAK;AAC7B,WAAS,UAAU;AACnB,QAAM,cAAcA,MAAAA,OAAO,QA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,CACT;AAED,QAAM,iBAAiB;AAAA,IACrB,SAAS;AAAA,IACT,YAAY;AAAA,IACZ,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,iBAAiB;AAAA,IACjB,eAAe;AAAA,IACf;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,gBAAgB;AAAA,IAChB;AAAA,IAAA,aACAlD;AAAAA,IACA;AAAA,IACA;AAAA,EAAA;AAGF,QAAM,QAAmB,mBACvBe,2BAAAA;AAAAA,IAAC;AAAA,IAAA;AAAA,MACE,GAAG;AAAA,MACJ,iBAAiB;AAAA,MACjB,qBAAqB;AAAA,MAEpB;AAAA,IAAA;AAAA,EAAA,IAGHA,2BAAAA,IAAC,2BAAA,EAA2B,GAAG,gBAAgB,UAAU,cACtD,UACH;AAOF,SACEA,2BAAAA;AAAAA,IAAC;AAAA,IAAA;AAAA,MACC,WAAW,iBAAiB,6BAA6B;AAAA,MACzD,OAAO;AAAA,MAEP,UAAAA,2BAAAA,IAACoC,gBAAAA,iBAAA,EAAgB,QAAQ,eACvB,UAAApC,2BAAAA,IAACqC,gBAAAA,uBAAuB,UAAvB,EAAgC,OAAOV,mBACtC,UAAA3B,2BAAAA,IAACsC,kBAAAA,wBAAwB,UAAxB,EAAiC,OAAO,gBACvC,UAAAtC,2BAAAA,IAACuC,8BAAAA,8BAA8B,UAA9B,EAAuC,OAAO,aAC5C,UAAA,MAAA,CACH,EAAA,CACF,EAAA,CACF,EAAA,CACF;AAAA,IAAA;AAAA,EAAA;AAGN;;"}
@@ -5,6 +5,9 @@ import { getAthenaEnvironmentUrls, deriveAthenaAppUrl, assertHostMintedStatewire
5
5
  import { getAthenaApiBaseUrl } from "../collab/mint.js";
6
6
  import { useParentBridge } from "../runtime/auth.js";
7
7
  import { AthenaAuthContext } from "../auth/AthenaAuthContext.js";
8
+ import { AthenaCredentialSourceContext } from "../auth/AthenaCredentialSourceContext.js";
9
+ import { createAthenaCredentialSource } from "../auth/credential-source.js";
10
+ import { useRestartAfterAuthRefusal } from "../runtime/auth-refusal-restart.js";
8
11
  import { useStatewireClientTools, useAthenaStatewireRuntime } from "../runtime/useAthenaStatewireRuntime.js";
9
12
  import { statewireLifecycleReducer, initialStatewireLifecycle, athenaStatewireErrorNotice } from "../runtime/statewire-lifecycle.js";
10
13
  import { resolveAgentProp } from "../runtime/statewire-run-config.js";
@@ -23,6 +26,7 @@ import { AthenaStatewireThreadIdContext, AthenaThreadIdContext, useAthenaStatewi
23
26
  import { AthenaStatewireThreadListProvider, useAthenaStatewireThreadList, StatewireThreadTitlePoller } from "../threads/statewire-thread-list.js";
24
27
  import { useAssetPanelStore } from "../assets/asset-panel-store.js";
25
28
  import { themeToStyleVars } from "../theme/index.js";
29
+ import { AthenaThemeStyleContext } from "./theme-style-context.js";
26
30
  import { PostHogProvider } from "./PostHogProvider.js";
27
31
  import { createDeepAgentThreadSnapshotCache } from "../packages/agent-runtime/src/thread-snapshot-cache.js";
28
32
  import { createDeepAgentToolOutputStore } from "../packages/agent-runtime/src/tool-outputs.js";
@@ -147,6 +151,10 @@ function AthenaStatewireRuntimeMount({
147
151
  dispatchLifecycle({ type: "raw-connection", reconnect: connection.reconnect });
148
152
  }
149
153
  });
154
+ useRestartAfterAuthRefusal({
155
+ connection: lifecycle.connection,
156
+ reconnect: lifecycle.reconnect
157
+ });
150
158
  const dismissError = useCallback(
151
159
  () => dispatchLifecycle({ type: "error", error: null }),
152
160
  []
@@ -411,6 +419,20 @@ function AthenaProvider({
411
419
  [composerHandoff]
412
420
  );
413
421
  const effectiveToken = configuredToken !== void 0 ? configuredToken : authProviderToken ?? bridge.token;
422
+ const authProviderGetToken = authContext == null ? void 0 : authContext.getToken;
423
+ const credentialInputsRef = useRef({ token: null });
424
+ credentialInputsRef.current = {
425
+ hostGetToken: configuredGetToken,
426
+ token: effectiveToken,
427
+ renew: configuredToken !== void 0 ? void 0 : authProviderToken !== null ? authProviderGetToken ? async ({ force }) => await authProviderGetToken({ force }) ?? null : void 0 : bridge.token !== null ? bridge.renewToken : void 0
428
+ };
429
+ const [credentials] = useState(
430
+ () => createAthenaCredentialSource(() => credentialInputsRef.current)
431
+ );
432
+ useEffect(() => {
433
+ credentials.notifyTokenChanged();
434
+ }, [credentials, effectiveToken]);
435
+ const credentialGetToken = configuredGetToken !== void 0 || effectiveToken ? credentials.getToken : void 0;
414
436
  const effectiveApiUrl = configuredApiUrl ?? environmentUrls.apiUrl;
415
437
  const effectiveBackendUrl = getAthenaApiBaseUrl(
416
438
  configuredBackendUrl ?? bridge.backendBaseUrl ?? environmentUrls.backendUrl
@@ -436,7 +458,7 @@ function AthenaProvider({
436
458
  appUrl: effectiveAppUrl,
437
459
  apiKey: configuredApiKey,
438
460
  token: effectiveToken,
439
- getToken: configuredGetToken,
461
+ getToken: credentialGetToken,
440
462
  model,
441
463
  agent,
442
464
  channel,
@@ -467,7 +489,7 @@ function AthenaProvider({
467
489
  {
468
490
  className: themeStyleVars ? "athena-sdk athena-themed" : "athena-sdk",
469
491
  style: themeStyleVars,
470
- children: /* @__PURE__ */ jsx(PostHogProvider, { config: posthogConfig, children: /* @__PURE__ */ jsx(ComposerHandoffContext.Provider, { value: composerHandoff, children: inner }) })
492
+ children: /* @__PURE__ */ jsx(PostHogProvider, { config: posthogConfig, children: /* @__PURE__ */ jsx(ComposerHandoffContext.Provider, { value: composerHandoff, children: /* @__PURE__ */ jsx(AthenaThemeStyleContext.Provider, { value: themeStyleVars, children: /* @__PURE__ */ jsx(AthenaCredentialSourceContext.Provider, { value: credentials, children: inner }) }) }) })
471
493
  }
472
494
  );
473
495
  }