@lvce-editor/chat-view 7.12.0 → 7.14.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.
- package/dist/chatViewWorkerMain.js +61 -10
- package/package.json +1 -1
|
@@ -1290,9 +1290,6 @@ const {
|
|
|
1290
1290
|
const openExternal = async url => {
|
|
1291
1291
|
return invoke$1('Open.openExternal', url);
|
|
1292
1292
|
};
|
|
1293
|
-
const openUrl = async (url, platform) => {
|
|
1294
|
-
return invoke$1('Open.openUrl', url, platform);
|
|
1295
|
-
};
|
|
1296
1293
|
|
|
1297
1294
|
const {
|
|
1298
1295
|
invoke,
|
|
@@ -2368,6 +2365,7 @@ const createDefaultState = () => {
|
|
|
2368
2365
|
authAccessToken: '',
|
|
2369
2366
|
authEnabled: false,
|
|
2370
2367
|
authErrorMessage: '',
|
|
2368
|
+
authUseRedirect: false,
|
|
2371
2369
|
backendUrl: '',
|
|
2372
2370
|
chatFocusContentMaxWidth: 700,
|
|
2373
2371
|
chatHistoryEnabled: true,
|
|
@@ -4386,13 +4384,16 @@ const getEffectiveRedirectUri = async (platform, uid, redirectUri) => {
|
|
|
4386
4384
|
}
|
|
4387
4385
|
return getCurrentHref();
|
|
4388
4386
|
};
|
|
4389
|
-
const
|
|
4387
|
+
const getBackendLoginRequest = async (backendUrl, platform = 0, uid = 0, redirectUri = '') => {
|
|
4390
4388
|
const loginUrl = new URL(getBackendAuthUrl(backendUrl, '/login'));
|
|
4391
4389
|
const effectiveRedirectUri = await getEffectiveRedirectUri(platform, uid, redirectUri);
|
|
4392
4390
|
if (effectiveRedirectUri) {
|
|
4393
4391
|
loginUrl.searchParams.set('redirect_uri', effectiveRedirectUri);
|
|
4394
4392
|
}
|
|
4395
|
-
return
|
|
4393
|
+
return {
|
|
4394
|
+
loginUrl: loginUrl.toString(),
|
|
4395
|
+
redirectUri: effectiveRedirectUri
|
|
4396
|
+
};
|
|
4396
4397
|
};
|
|
4397
4398
|
|
|
4398
4399
|
const getLoggedOutBackendAuthState = (authErrorMessage = '') => {
|
|
@@ -4555,6 +4556,39 @@ const delay = async ms => {
|
|
|
4555
4556
|
await new Promise(resolve => setTimeout(resolve, ms));
|
|
4556
4557
|
};
|
|
4557
4558
|
|
|
4559
|
+
const getBackendNativeExchangeUrl = backendUrl => {
|
|
4560
|
+
return getBackendAuthUrl(backendUrl, '/auth/native/exchange');
|
|
4561
|
+
};
|
|
4562
|
+
|
|
4563
|
+
const getExchangeErrorMessage = async response => {
|
|
4564
|
+
try {
|
|
4565
|
+
const payload = await response.json();
|
|
4566
|
+
if (payload && typeof payload === 'object' && typeof payload.error === 'string' && payload.error) {
|
|
4567
|
+
return payload.error;
|
|
4568
|
+
}
|
|
4569
|
+
} catch {
|
|
4570
|
+
// ignore
|
|
4571
|
+
}
|
|
4572
|
+
return 'Backend authentication failed.';
|
|
4573
|
+
};
|
|
4574
|
+
const exchangeElectronAuthorizationCode = async (backendUrl, code, redirectUri) => {
|
|
4575
|
+
const response = await fetch(getBackendNativeExchangeUrl(backendUrl), {
|
|
4576
|
+
body: JSON.stringify({
|
|
4577
|
+
code,
|
|
4578
|
+
redirectUri
|
|
4579
|
+
}),
|
|
4580
|
+
credentials: 'include',
|
|
4581
|
+
headers: {
|
|
4582
|
+
Accept: 'application/json',
|
|
4583
|
+
'Content-Type': 'application/json'
|
|
4584
|
+
},
|
|
4585
|
+
method: 'POST'
|
|
4586
|
+
});
|
|
4587
|
+
if (!response.ok) {
|
|
4588
|
+
throw new Error(await getExchangeErrorMessage(response));
|
|
4589
|
+
}
|
|
4590
|
+
};
|
|
4591
|
+
|
|
4558
4592
|
const waitForBackendLogin = async (backendUrl, timeoutMs = 30_000, pollIntervalMs = 1000) => {
|
|
4559
4593
|
const deadline = Date.now() + timeoutMs;
|
|
4560
4594
|
let lastErrorMessage = '';
|
|
@@ -4574,7 +4608,7 @@ const waitForBackendLogin = async (backendUrl, timeoutMs = 30_000, pollIntervalM
|
|
|
4574
4608
|
const hasAuthorizationCode = value => {
|
|
4575
4609
|
return typeof value === 'string' && value.length > 0;
|
|
4576
4610
|
};
|
|
4577
|
-
const waitForElectronBackendLogin = async (backendUrl, uid, timeoutMs = 30_000, pollIntervalMs = 1000) => {
|
|
4611
|
+
const waitForElectronBackendLogin = async (backendUrl, uid, redirectUri, timeoutMs = 30_000, pollIntervalMs = 1000) => {
|
|
4578
4612
|
const started = Date.now();
|
|
4579
4613
|
const deadline = started + timeoutMs;
|
|
4580
4614
|
while (Date.now() < deadline) {
|
|
@@ -4582,6 +4616,7 @@ const waitForElectronBackendLogin = async (backendUrl, uid, timeoutMs = 30_000,
|
|
|
4582
4616
|
if (hasAuthorizationCode(authorizationCode)) {
|
|
4583
4617
|
const elapsed = Date.now() - started;
|
|
4584
4618
|
const remainingTime = Math.max(0, timeoutMs - elapsed);
|
|
4619
|
+
await exchangeElectronAuthorizationCode(backendUrl, authorizationCode, redirectUri);
|
|
4585
4620
|
return waitForBackendLogin(backendUrl, remainingTime, pollIntervalMs);
|
|
4586
4621
|
}
|
|
4587
4622
|
await delay(pollIntervalMs);
|
|
@@ -4615,6 +4650,7 @@ const getLoggedInState = (state, response) => {
|
|
|
4615
4650
|
};
|
|
4616
4651
|
const handleClickLogin = async state => {
|
|
4617
4652
|
const {
|
|
4653
|
+
authUseRedirect,
|
|
4618
4654
|
backendUrl,
|
|
4619
4655
|
platform,
|
|
4620
4656
|
uid
|
|
@@ -4654,9 +4690,12 @@ const handleClickLogin = async state => {
|
|
|
4654
4690
|
}
|
|
4655
4691
|
return getLoggedInState(signingInState, response);
|
|
4656
4692
|
}
|
|
4657
|
-
const
|
|
4658
|
-
|
|
4659
|
-
|
|
4693
|
+
const {
|
|
4694
|
+
loginUrl,
|
|
4695
|
+
redirectUri
|
|
4696
|
+
} = await getBackendLoginRequest(backendUrl, platform, uid);
|
|
4697
|
+
await invoke$1('Open.openUrl', loginUrl, platform, authUseRedirect);
|
|
4698
|
+
const authState = platform === PlatformTypeElectron ? await waitForElectronBackendLogin(backendUrl, uid, redirectUri) : await waitForBackendLogin(backendUrl);
|
|
4660
4699
|
return {
|
|
4661
4700
|
...signingInState,
|
|
4662
4701
|
...authState
|
|
@@ -10643,6 +10682,15 @@ const loadAuthEnabled = async () => {
|
|
|
10643
10682
|
}
|
|
10644
10683
|
};
|
|
10645
10684
|
|
|
10685
|
+
const loadAuthUseRedirect = async () => {
|
|
10686
|
+
try {
|
|
10687
|
+
const savedAuthUseRedirect = await get('chat.authUseRedirect');
|
|
10688
|
+
return typeof savedAuthUseRedirect === 'boolean' ? savedAuthUseRedirect : false;
|
|
10689
|
+
} catch {
|
|
10690
|
+
return false;
|
|
10691
|
+
}
|
|
10692
|
+
};
|
|
10693
|
+
|
|
10646
10694
|
const loadBackendUrl = async () => {
|
|
10647
10695
|
try {
|
|
10648
10696
|
const savedBackendUrl = await get('chat.backendUrl');
|
|
@@ -10823,10 +10871,11 @@ const loadVoiceDictationEnabled = async () => {
|
|
|
10823
10871
|
};
|
|
10824
10872
|
|
|
10825
10873
|
const loadPreferences = async () => {
|
|
10826
|
-
const [aiSessionTitleGenerationEnabled, authEnabled, backendUrl, chatHistoryEnabled, composerDropEnabled, openApiApiKey, openRouterApiKey, emitStreamingFunctionCallEvents, reasoningPickerEnabled, scrollDownButtonEnabled, searchEnabled, streamingEnabled, todoListToolEnabled, toolEnablement, passIncludeObfuscation, useChatCoordinatorWorker, useChatMathWorker, useChatNetworkWorkerForRequests, useChatToolWorker, useOwnBackend, voiceDictationEnabled] = await Promise.all([loadAiSessionTitleGenerationEnabled(), loadAuthEnabled(), loadBackendUrl(), loadChatHistoryEnabled(), loadComposerDropEnabled(), loadOpenApiApiKey(), loadOpenRouterApiKey(), loadEmitStreamingFunctionCallEvents(), loadReasoningPickerEnabled(), loadScrollDownButtonEnabled(), loadSearchEnabled(), loadStreamingEnabled(), loadTodoListToolEnabled(), loadToolEnablement(), loadPassIncludeObfuscation(), loadUseChatCoordinatorWorker(), loadUseChatMathWorker(), loadUseChatNetworkWorkerForRequests(), loadUseChatToolWorker(), loadUseOwnBackend(), loadVoiceDictationEnabled()]);
|
|
10874
|
+
const [aiSessionTitleGenerationEnabled, authEnabled, authUseRedirect, backendUrl, chatHistoryEnabled, composerDropEnabled, openApiApiKey, openRouterApiKey, emitStreamingFunctionCallEvents, reasoningPickerEnabled, scrollDownButtonEnabled, searchEnabled, streamingEnabled, todoListToolEnabled, toolEnablement, passIncludeObfuscation, useChatCoordinatorWorker, useChatMathWorker, useChatNetworkWorkerForRequests, useChatToolWorker, useOwnBackend, voiceDictationEnabled] = await Promise.all([loadAiSessionTitleGenerationEnabled(), loadAuthEnabled(), loadAuthUseRedirect(), loadBackendUrl(), loadChatHistoryEnabled(), loadComposerDropEnabled(), loadOpenApiApiKey(), loadOpenRouterApiKey(), loadEmitStreamingFunctionCallEvents(), loadReasoningPickerEnabled(), loadScrollDownButtonEnabled(), loadSearchEnabled(), loadStreamingEnabled(), loadTodoListToolEnabled(), loadToolEnablement(), loadPassIncludeObfuscation(), loadUseChatCoordinatorWorker(), loadUseChatMathWorker(), loadUseChatNetworkWorkerForRequests(), loadUseChatToolWorker(), loadUseOwnBackend(), loadVoiceDictationEnabled()]);
|
|
10827
10875
|
return {
|
|
10828
10876
|
aiSessionTitleGenerationEnabled,
|
|
10829
10877
|
authEnabled,
|
|
10878
|
+
authUseRedirect,
|
|
10830
10879
|
backendUrl,
|
|
10831
10880
|
chatHistoryEnabled,
|
|
10832
10881
|
composerDropEnabled,
|
|
@@ -10899,6 +10948,7 @@ const loadContent = async (state, savedState) => {
|
|
|
10899
10948
|
const {
|
|
10900
10949
|
aiSessionTitleGenerationEnabled,
|
|
10901
10950
|
authEnabled,
|
|
10951
|
+
authUseRedirect,
|
|
10902
10952
|
backendUrl,
|
|
10903
10953
|
chatHistoryEnabled,
|
|
10904
10954
|
composerDropEnabled,
|
|
@@ -10979,6 +11029,7 @@ const loadContent = async (state, savedState) => {
|
|
|
10979
11029
|
authAccessToken: authState.authAccessToken,
|
|
10980
11030
|
authEnabled,
|
|
10981
11031
|
authErrorMessage: authState.authErrorMessage,
|
|
11032
|
+
authUseRedirect,
|
|
10982
11033
|
backendUrl,
|
|
10983
11034
|
chatHistoryEnabled,
|
|
10984
11035
|
chatListScrollTop,
|