@axiom-lattice/react-sdk 2.1.68 → 2.1.70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -408,16 +408,22 @@ function AxiomLatticeProvider({
408
408
  }) {
409
409
  const authContext = (0, import_react2.useContext)(AuthContext);
410
410
  const tenantId = authContext?.currentTenant?.id;
411
+ const effectiveApiKey = (0, import_react2.useMemo)(() => {
412
+ if (authContext?.isAuthenticated) {
413
+ return sessionStorage.getItem("lattice_token") || config.apiKey;
414
+ }
415
+ return config.apiKey;
416
+ }, [authContext?.isAuthenticated, authContext?.currentTenant?.id, config.apiKey]);
411
417
  const clientCacheRef = (0, import_react2.useRef)(/* @__PURE__ */ new Map());
412
418
  const baseConfig = (0, import_react2.useMemo)(
413
419
  () => ({
414
420
  baseURL: config.baseURL,
415
- apiKey: config.apiKey,
421
+ apiKey: effectiveApiKey,
416
422
  assistantId: "__BASE__",
417
423
  // 占位符,不会被直接使用
418
424
  transport: config.transport
419
425
  }),
420
- [config.baseURL, config.apiKey, config.transport]
426
+ [config.baseURL, effectiveApiKey, config.transport]
421
427
  );
422
428
  const baseClient = (0, import_react2.useMemo)(() => {
423
429
  const client = new import_client_sdk.Client(baseConfig);
@@ -18919,7 +18925,7 @@ var useWorkspaceContext = () => {
18919
18925
  var WorkspaceContextProvider = ({
18920
18926
  children
18921
18927
  }) => {
18922
- const { currentTenant } = useAuth();
18928
+ const { currentTenant, isAuthenticated } = useAuth();
18923
18929
  const tenantId = currentTenant?.id || "";
18924
18930
  const { config } = useLatticeChatShellContext();
18925
18931
  const axiomClient = useClient("__GLOBAL__");
@@ -18952,13 +18958,14 @@ var WorkspaceContextProvider = ({
18952
18958
  const [loading, setLoading] = (0, import_react61.useState)(false);
18953
18959
  const [error, setError] = (0, import_react61.useState)(null);
18954
18960
  const client = import_react61.default.useMemo(() => {
18961
+ const authApiKey = isAuthenticated ? sessionStorage.getItem("lattice_token") || config.apiKey || "" : config.apiKey || "";
18955
18962
  return new import_client_sdk6.WorkspaceClient({
18956
18963
  baseURL: config.baseURL,
18957
- apiKey: config.apiKey || "",
18964
+ apiKey: authApiKey,
18958
18965
  assistantId: "",
18959
18966
  transport: "sse"
18960
18967
  }, tenantId);
18961
- }, [config.baseURL, config.apiKey, tenantId]);
18968
+ }, [config.baseURL, config.apiKey, tenantId, isAuthenticated]);
18962
18969
  const resetSelectedWorkspace = (0, import_react61.useCallback)(() => {
18963
18970
  setProjects([]);
18964
18971
  setWorkspaceId(null);