@merit-systems/echo-react-sdk 1.0.19 → 1.0.20
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/echo-react-sdk.umd.js +2 -2
- package/dist/echo-react-sdk.umd.js.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +24 -9
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -29444,11 +29444,20 @@ function echoFetch(originalFetch, getTokenFn, onInsufficientFunds) {
|
|
|
29444
29444
|
const token = await getTokenFn();
|
|
29445
29445
|
if (init)
|
|
29446
29446
|
init.headers = { ...init.headers, Authorization: `Bearer ${token}` };
|
|
29447
|
-
|
|
29447
|
+
let response = await originalFetch(input, init);
|
|
29448
|
+
if (response.status === 401) {
|
|
29449
|
+
const token2 = await getTokenFn();
|
|
29450
|
+
if (init)
|
|
29451
|
+
init.headers = {
|
|
29452
|
+
...init.headers,
|
|
29453
|
+
...token2 && { Authorization: `Bearer ${token2}` }
|
|
29454
|
+
};
|
|
29455
|
+
const newResponse = await originalFetch(input, init);
|
|
29456
|
+
response = newResponse;
|
|
29457
|
+
}
|
|
29448
29458
|
if (response.status === 402) {
|
|
29449
29459
|
onInsufficientFunds == null ? void 0 : onInsufficientFunds();
|
|
29450
29460
|
}
|
|
29451
|
-
if (response.status === 401) ;
|
|
29452
29461
|
return response;
|
|
29453
29462
|
};
|
|
29454
29463
|
}
|
|
@@ -29661,9 +29670,12 @@ function EchoProviderInternal({ config: config2, children }) {
|
|
|
29661
29670
|
}
|
|
29662
29671
|
}, [auth.removeUser]);
|
|
29663
29672
|
const getToken = useCallback(async () => {
|
|
29664
|
-
var _a15;
|
|
29665
|
-
|
|
29666
|
-
|
|
29673
|
+
var _a15, _b2, _c2;
|
|
29674
|
+
if ((_a15 = auth.user) == null ? void 0 : _a15.expired) {
|
|
29675
|
+
return ((_b2 = await auth.signinSilent()) == null ? void 0 : _b2.access_token) || null;
|
|
29676
|
+
}
|
|
29677
|
+
return ((_c2 = auth.user) == null ? void 0 : _c2.access_token) || null;
|
|
29678
|
+
}, [(_b = auth.user) == null ? void 0 : _b.access_token, auth.signinSilent]);
|
|
29667
29679
|
const combinedError = ((_c = auth.error) == null ? void 0 : _c.message) || balanceError || paymentError || userError || null;
|
|
29668
29680
|
const isInitialAuthLoading = auth.isLoading && !auth.isAuthenticated;
|
|
29669
29681
|
const isTokenRefreshing = auth.isLoading && auth.isAuthenticated;
|
|
@@ -32345,21 +32357,24 @@ function useEchoOpenAI(options = {}) {
|
|
|
32345
32357
|
};
|
|
32346
32358
|
}
|
|
32347
32359
|
const useEchoModelProviders = () => {
|
|
32348
|
-
const {
|
|
32360
|
+
const { getToken, config: config2, setIsInsufficientFunds } = useEcho();
|
|
32349
32361
|
const onInsufficientFunds = () => setIsInsufficientFunds(true);
|
|
32350
32362
|
return useMemo(() => {
|
|
32351
32363
|
const baseConfig = {
|
|
32352
32364
|
appId: config2.appId,
|
|
32353
32365
|
baseRouterUrl: config2.baseRouterUrl
|
|
32354
32366
|
};
|
|
32355
|
-
const getToken = async () => token;
|
|
32356
32367
|
return {
|
|
32357
32368
|
openai: createEchoOpenAI(baseConfig, getToken, onInsufficientFunds),
|
|
32358
32369
|
anthropic: createEchoAnthropic(baseConfig, getToken, onInsufficientFunds),
|
|
32359
32370
|
google: createEchoGoogle(baseConfig, getToken, onInsufficientFunds),
|
|
32360
|
-
openrouter: createEchoOpenRouter(
|
|
32371
|
+
openrouter: createEchoOpenRouter(
|
|
32372
|
+
baseConfig,
|
|
32373
|
+
getToken,
|
|
32374
|
+
onInsufficientFunds
|
|
32375
|
+
)
|
|
32361
32376
|
};
|
|
32362
|
-
}, [
|
|
32377
|
+
}, [getToken, config2.appId, config2.baseRouterUrl, setIsInsufficientFunds]);
|
|
32363
32378
|
};
|
|
32364
32379
|
const EchoChatConfigContext = createContext(null);
|
|
32365
32380
|
function EchoChatProvider({
|