@lvce-editor/chat-view 7.7.0 → 7.9.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 +248 -61
- package/package.json +1 -1
|
@@ -1290,6 +1290,9 @@ 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
|
+
};
|
|
1293
1296
|
|
|
1294
1297
|
const {
|
|
1295
1298
|
invoke,
|
|
@@ -2402,6 +2405,7 @@ const createDefaultState = () => {
|
|
|
2402
2405
|
gitBranchPickerVisible: false,
|
|
2403
2406
|
headerHeight: 50,
|
|
2404
2407
|
height: 0,
|
|
2408
|
+
useOwnBackend: false,
|
|
2405
2409
|
...responsivePickerState,
|
|
2406
2410
|
initial: true,
|
|
2407
2411
|
inputSource: 'script',
|
|
@@ -4361,8 +4365,24 @@ const getBackendAuthUrl = (backendUrl, path) => {
|
|
|
4361
4365
|
return `${trimTrailingSlashes(backendUrl)}${path}`;
|
|
4362
4366
|
};
|
|
4363
4367
|
|
|
4364
|
-
const
|
|
4365
|
-
|
|
4368
|
+
const getCurrentHref = async () => {
|
|
4369
|
+
try {
|
|
4370
|
+
return await invoke('Layout.getHref');
|
|
4371
|
+
} catch {
|
|
4372
|
+
// ignore
|
|
4373
|
+
}
|
|
4374
|
+
if (!globalThis.location || typeof globalThis.location.href !== 'string' || !globalThis.location.href) {
|
|
4375
|
+
return '';
|
|
4376
|
+
}
|
|
4377
|
+
return globalThis.location.href;
|
|
4378
|
+
};
|
|
4379
|
+
const getBackendLoginUrl = async backendUrl => {
|
|
4380
|
+
const loginUrl = new URL(getBackendAuthUrl(backendUrl, '/login'));
|
|
4381
|
+
const redirectUri = await getCurrentHref();
|
|
4382
|
+
if (redirectUri) {
|
|
4383
|
+
loginUrl.searchParams.set('redirect_uri', redirectUri);
|
|
4384
|
+
}
|
|
4385
|
+
return loginUrl.toString();
|
|
4366
4386
|
};
|
|
4367
4387
|
|
|
4368
4388
|
const getLoggedOutBackendAuthState = (authErrorMessage = '') => {
|
|
@@ -4397,16 +4417,59 @@ const logoutFromBackend = async backendUrl => {
|
|
|
4397
4417
|
}
|
|
4398
4418
|
};
|
|
4399
4419
|
|
|
4420
|
+
let nextLoginResponse;
|
|
4421
|
+
let nextRefreshResponse;
|
|
4422
|
+
const setNextLoginResponse = response => {
|
|
4423
|
+
nextLoginResponse = response;
|
|
4424
|
+
};
|
|
4425
|
+
const setNextRefreshResponse = response => {
|
|
4426
|
+
nextRefreshResponse = response;
|
|
4427
|
+
};
|
|
4428
|
+
const hasPendingMockLoginResponse = () => {
|
|
4429
|
+
return !!nextLoginResponse;
|
|
4430
|
+
};
|
|
4431
|
+
const hasPendingMockRefreshResponse = () => {
|
|
4432
|
+
return !!nextRefreshResponse;
|
|
4433
|
+
};
|
|
4434
|
+
const consumeNextLoginResponse = async () => {
|
|
4435
|
+
if (!nextLoginResponse) {
|
|
4436
|
+
return undefined;
|
|
4437
|
+
}
|
|
4438
|
+
const response = nextLoginResponse;
|
|
4439
|
+
nextLoginResponse = undefined;
|
|
4440
|
+
if (response.delay > 0) {
|
|
4441
|
+
await new Promise(resolve => setTimeout(resolve, response.delay));
|
|
4442
|
+
}
|
|
4443
|
+
if (response.type === 'error') {
|
|
4444
|
+
throw new Error(response.message);
|
|
4445
|
+
}
|
|
4446
|
+
return response.response;
|
|
4447
|
+
};
|
|
4448
|
+
const consumeNextRefreshResponse = async () => {
|
|
4449
|
+
if (!nextRefreshResponse) {
|
|
4450
|
+
return undefined;
|
|
4451
|
+
}
|
|
4452
|
+
const response = nextRefreshResponse;
|
|
4453
|
+
nextRefreshResponse = undefined;
|
|
4454
|
+
if (response.delay > 0) {
|
|
4455
|
+
await new Promise(resolve => setTimeout(resolve, response.delay));
|
|
4456
|
+
}
|
|
4457
|
+
if (response.type === 'error') {
|
|
4458
|
+
throw new Error(response.message);
|
|
4459
|
+
}
|
|
4460
|
+
return response.response;
|
|
4461
|
+
};
|
|
4462
|
+
|
|
4400
4463
|
const getBackendRefreshUrl = backendUrl => {
|
|
4401
4464
|
return getBackendAuthUrl(backendUrl, '/auth/refresh');
|
|
4402
4465
|
};
|
|
4403
4466
|
|
|
4404
|
-
const isObject$
|
|
4467
|
+
const isObject$3 = value => {
|
|
4405
4468
|
return !!value && typeof value === 'object';
|
|
4406
4469
|
};
|
|
4407
4470
|
|
|
4408
4471
|
const isBackendAuthResponse = value => {
|
|
4409
|
-
return isObject$
|
|
4472
|
+
return isObject$3(value);
|
|
4410
4473
|
};
|
|
4411
4474
|
|
|
4412
4475
|
const getNumber = (value, fallback = 0) => {
|
|
@@ -4440,6 +4503,10 @@ const syncBackendAuth = async backendUrl => {
|
|
|
4440
4503
|
return getLoggedOutBackendAuthState('Backend URL is missing.');
|
|
4441
4504
|
}
|
|
4442
4505
|
try {
|
|
4506
|
+
if (hasPendingMockRefreshResponse()) {
|
|
4507
|
+
const mockResponse = await consumeNextRefreshResponse();
|
|
4508
|
+
return parseBackendAuthResponse(mockResponse);
|
|
4509
|
+
}
|
|
4443
4510
|
const response = await fetch(getBackendRefreshUrl(backendUrl), {
|
|
4444
4511
|
credentials: 'include',
|
|
4445
4512
|
headers: {
|
|
@@ -4494,28 +4561,6 @@ const waitForBackendLogin = async (backendUrl, timeoutMs = 30_000, pollIntervalM
|
|
|
4494
4561
|
return getLoggedOutBackendAuthState(lastErrorMessage);
|
|
4495
4562
|
};
|
|
4496
4563
|
|
|
4497
|
-
let nextLoginResponse;
|
|
4498
|
-
const setNextLoginResponse = response => {
|
|
4499
|
-
nextLoginResponse = response;
|
|
4500
|
-
};
|
|
4501
|
-
const hasPendingMockLoginResponse = () => {
|
|
4502
|
-
return !!nextLoginResponse;
|
|
4503
|
-
};
|
|
4504
|
-
const consumeNextLoginResponse = async () => {
|
|
4505
|
-
if (!nextLoginResponse) {
|
|
4506
|
-
return undefined;
|
|
4507
|
-
}
|
|
4508
|
-
const response = nextLoginResponse;
|
|
4509
|
-
nextLoginResponse = undefined;
|
|
4510
|
-
if (response.delay > 0) {
|
|
4511
|
-
await new Promise(resolve => setTimeout(resolve, response.delay));
|
|
4512
|
-
}
|
|
4513
|
-
if (response.type === 'error') {
|
|
4514
|
-
throw new Error(response.message);
|
|
4515
|
-
}
|
|
4516
|
-
return response.response;
|
|
4517
|
-
};
|
|
4518
|
-
|
|
4519
4564
|
const isLoginResponse = value => {
|
|
4520
4565
|
if (!value || typeof value !== 'object') {
|
|
4521
4566
|
return false;
|
|
@@ -4570,7 +4615,8 @@ const handleClickLogin = async state => {
|
|
|
4570
4615
|
}
|
|
4571
4616
|
return getLoggedInState(signingInState, response);
|
|
4572
4617
|
}
|
|
4573
|
-
await
|
|
4618
|
+
const url = await getBackendLoginUrl(state.backendUrl);
|
|
4619
|
+
await openUrl(url, state.platform);
|
|
4574
4620
|
const authState = await waitForBackendLogin(state.backendUrl);
|
|
4575
4621
|
return {
|
|
4576
4622
|
...signingInState,
|
|
@@ -4936,6 +4982,28 @@ const getBasicChatTools = async (agentMode = defaultAgentMode, questionToolEnabl
|
|
|
4936
4982
|
}
|
|
4937
4983
|
};
|
|
4938
4984
|
|
|
4985
|
+
const getBackendErrorMessage = errorResult => {
|
|
4986
|
+
switch (errorResult.details) {
|
|
4987
|
+
case 'http-error':
|
|
4988
|
+
{
|
|
4989
|
+
const errorMessage = errorResult.errorMessage?.trim();
|
|
4990
|
+
if (typeof errorResult.statusCode === 'number') {
|
|
4991
|
+
const prefix = `Backend completion request failed (status ${errorResult.statusCode}).`;
|
|
4992
|
+
if (!errorMessage) {
|
|
4993
|
+
return prefix;
|
|
4994
|
+
}
|
|
4995
|
+
return `${prefix} ${errorMessage}`;
|
|
4996
|
+
}
|
|
4997
|
+
if (errorMessage) {
|
|
4998
|
+
return `Backend completion request failed. ${errorMessage}`;
|
|
4999
|
+
}
|
|
5000
|
+
return backendCompletionFailedMessage;
|
|
5001
|
+
}
|
|
5002
|
+
case 'request-failed':
|
|
5003
|
+
return backendCompletionFailedMessage;
|
|
5004
|
+
}
|
|
5005
|
+
};
|
|
5006
|
+
|
|
4939
5007
|
const getAttachmentTextPart = attachment => {
|
|
4940
5008
|
switch (attachment.displayType) {
|
|
4941
5009
|
case 'file':
|
|
@@ -5019,7 +5087,7 @@ const reset$1 = () => {
|
|
|
5019
5087
|
finished = false;
|
|
5020
5088
|
errorResult = undefined;
|
|
5021
5089
|
};
|
|
5022
|
-
const setHttpErrorResponse = (statusCode, body) => {
|
|
5090
|
+
const setHttpErrorResponse$1 = (statusCode, body) => {
|
|
5023
5091
|
const rawError = body && typeof body === 'object' ? Reflect.get(body, 'error') : undefined;
|
|
5024
5092
|
const errorCode = rawError && typeof rawError === 'object' ? Reflect.get(rawError, 'code') : undefined;
|
|
5025
5093
|
const errorMessage = rawError && typeof rawError === 'object' ? Reflect.get(rawError, 'message') : undefined;
|
|
@@ -5048,7 +5116,7 @@ const setRequestFailedResponse = (isOffline = false) => {
|
|
|
5048
5116
|
type: 'error'
|
|
5049
5117
|
};
|
|
5050
5118
|
};
|
|
5051
|
-
const takeErrorResponse = () => {
|
|
5119
|
+
const takeErrorResponse$1 = () => {
|
|
5052
5120
|
const error = errorResult;
|
|
5053
5121
|
errorResult = undefined;
|
|
5054
5122
|
return error;
|
|
@@ -5180,7 +5248,7 @@ const emitToolCalls = async (toolCallAccumulator, onToolCallsChunk) => {
|
|
|
5180
5248
|
await onToolCallsChunk(toolCalls);
|
|
5181
5249
|
};
|
|
5182
5250
|
const getMockOpenApiAssistantText = async (stream, onTextChunk, onToolCallsChunk, onDataEvent, onEventStreamFinished) => {
|
|
5183
|
-
const error = takeErrorResponse();
|
|
5251
|
+
const error = takeErrorResponse$1();
|
|
5184
5252
|
if (error) {
|
|
5185
5253
|
return error;
|
|
5186
5254
|
}
|
|
@@ -7104,6 +7172,20 @@ const isOpenRouterModel = (selectedModelId, models) => {
|
|
|
7104
7172
|
return selectedModelId.toLowerCase().startsWith('openrouter/');
|
|
7105
7173
|
};
|
|
7106
7174
|
|
|
7175
|
+
let errorResponse;
|
|
7176
|
+
const setHttpErrorResponse = (statusCode, body) => {
|
|
7177
|
+
errorResponse = {
|
|
7178
|
+
body,
|
|
7179
|
+
statusCode,
|
|
7180
|
+
type: 'http-error'
|
|
7181
|
+
};
|
|
7182
|
+
};
|
|
7183
|
+
const takeErrorResponse = () => {
|
|
7184
|
+
const response = errorResponse;
|
|
7185
|
+
errorResponse = undefined;
|
|
7186
|
+
return response;
|
|
7187
|
+
};
|
|
7188
|
+
|
|
7107
7189
|
/* eslint-disable prefer-destructuring */
|
|
7108
7190
|
|
|
7109
7191
|
const trailingSlashesRegex = /\/+$/;
|
|
@@ -7111,17 +7193,57 @@ const getBackendCompletionsEndpoint = backendUrl => {
|
|
|
7111
7193
|
const trimmedBackendUrl = backendUrl.replace(trailingSlashesRegex, '');
|
|
7112
7194
|
return `${trimmedBackendUrl}/v1/chat/completions`;
|
|
7113
7195
|
};
|
|
7114
|
-
const getEffectiveBackendModelId = selectedModelId => {
|
|
7115
|
-
const separatorIndex = selectedModelId.indexOf('/');
|
|
7116
|
-
if (separatorIndex === -1) {
|
|
7117
|
-
return selectedModelId;
|
|
7118
|
-
}
|
|
7119
|
-
return selectedModelId.slice(separatorIndex + 1);
|
|
7120
|
-
};
|
|
7121
7196
|
const hasImageAttachments = messages => {
|
|
7122
7197
|
return messages.some(message => message.attachments?.some(attachment => attachment.displayType === 'image'));
|
|
7123
7198
|
};
|
|
7199
|
+
const isObject$2 = value => {
|
|
7200
|
+
return !!value && typeof value === 'object';
|
|
7201
|
+
};
|
|
7202
|
+
const getBackendErrorMessageFromBody = body => {
|
|
7203
|
+
if (!isObject$2(body)) {
|
|
7204
|
+
return undefined;
|
|
7205
|
+
}
|
|
7206
|
+
const directMessage = Reflect.get(body, 'message');
|
|
7207
|
+
if (typeof directMessage === 'string' && directMessage) {
|
|
7208
|
+
return directMessage;
|
|
7209
|
+
}
|
|
7210
|
+
const directError = Reflect.get(body, 'error');
|
|
7211
|
+
if (typeof directError === 'string' && directError) {
|
|
7212
|
+
return directError;
|
|
7213
|
+
}
|
|
7214
|
+
if (!isObject$2(directError)) {
|
|
7215
|
+
return undefined;
|
|
7216
|
+
}
|
|
7217
|
+
const nestedMessage = Reflect.get(directError, 'message');
|
|
7218
|
+
if (typeof nestedMessage === 'string' && nestedMessage) {
|
|
7219
|
+
return nestedMessage;
|
|
7220
|
+
}
|
|
7221
|
+
return undefined;
|
|
7222
|
+
};
|
|
7223
|
+
const getBackendStatusCodeFromBody = body => {
|
|
7224
|
+
if (!isObject$2(body)) {
|
|
7225
|
+
return undefined;
|
|
7226
|
+
}
|
|
7227
|
+
const statusCode = Reflect.get(body, 'statusCode');
|
|
7228
|
+
if (typeof statusCode === 'number') {
|
|
7229
|
+
return statusCode;
|
|
7230
|
+
}
|
|
7231
|
+
return undefined;
|
|
7232
|
+
};
|
|
7124
7233
|
const getBackendAssistantText = async (messages, selectedModelId, backendUrl, authAccessToken, systemPrompt) => {
|
|
7234
|
+
const mockError = takeErrorResponse();
|
|
7235
|
+
if (mockError) {
|
|
7236
|
+
const errorMessage = getBackendErrorMessageFromBody(mockError.body);
|
|
7237
|
+
return getBackendErrorMessage({
|
|
7238
|
+
details: 'http-error',
|
|
7239
|
+
...(typeof mockError.statusCode === 'number' ? {
|
|
7240
|
+
statusCode: mockError.statusCode
|
|
7241
|
+
} : {}),
|
|
7242
|
+
...(errorMessage ? {
|
|
7243
|
+
errorMessage
|
|
7244
|
+
} : {})
|
|
7245
|
+
});
|
|
7246
|
+
}
|
|
7125
7247
|
let response;
|
|
7126
7248
|
try {
|
|
7127
7249
|
response = await fetch(getBackendCompletionsEndpoint(backendUrl), {
|
|
@@ -7133,7 +7255,8 @@ const getBackendAssistantText = async (messages, selectedModelId, backendUrl, au
|
|
|
7133
7255
|
content: message.text,
|
|
7134
7256
|
role: message.role
|
|
7135
7257
|
}))],
|
|
7136
|
-
model:
|
|
7258
|
+
model: selectedModelId,
|
|
7259
|
+
selectedModelId,
|
|
7137
7260
|
stream: false
|
|
7138
7261
|
}),
|
|
7139
7262
|
headers: {
|
|
@@ -7144,20 +7267,37 @@ const getBackendAssistantText = async (messages, selectedModelId, backendUrl, au
|
|
|
7144
7267
|
method: 'POST'
|
|
7145
7268
|
});
|
|
7146
7269
|
} catch {
|
|
7147
|
-
return
|
|
7270
|
+
return getBackendErrorMessage({
|
|
7271
|
+
details: 'request-failed'
|
|
7272
|
+
});
|
|
7148
7273
|
}
|
|
7149
7274
|
if (!response.ok) {
|
|
7275
|
+
const payload = await response.json().catch(() => undefined);
|
|
7276
|
+
const errorMessage = getBackendErrorMessageFromBody(payload);
|
|
7277
|
+
const statusCode = response.status || getBackendStatusCodeFromBody(payload);
|
|
7278
|
+
return getBackendErrorMessage({
|
|
7279
|
+
details: 'http-error',
|
|
7280
|
+
...(typeof statusCode === 'number' ? {
|
|
7281
|
+
statusCode
|
|
7282
|
+
} : {}),
|
|
7283
|
+
...(errorMessage ? {
|
|
7284
|
+
errorMessage
|
|
7285
|
+
} : {})
|
|
7286
|
+
});
|
|
7287
|
+
}
|
|
7288
|
+
let json;
|
|
7289
|
+
try {
|
|
7290
|
+
json = await response.json();
|
|
7291
|
+
} catch {
|
|
7150
7292
|
return backendCompletionFailedMessage;
|
|
7151
7293
|
}
|
|
7152
|
-
const
|
|
7153
|
-
const content = json.choices?.[0]?.message?.content;
|
|
7294
|
+
const content = json.text || json.message?.content || json.choices?.[0]?.message?.content;
|
|
7154
7295
|
return typeof content === 'string' && content ? content : backendCompletionFailedMessage;
|
|
7155
7296
|
};
|
|
7156
7297
|
const getAiResponse = async ({
|
|
7157
7298
|
agentMode = defaultAgentMode,
|
|
7158
7299
|
assetDir,
|
|
7159
7300
|
authAccessToken,
|
|
7160
|
-
authEnabled = false,
|
|
7161
7301
|
backendUrl = '',
|
|
7162
7302
|
maxToolCalls = defaultMaxToolCalls,
|
|
7163
7303
|
messageId,
|
|
@@ -7188,12 +7328,13 @@ const getAiResponse = async ({
|
|
|
7188
7328
|
useChatNetworkWorkerForRequests = false,
|
|
7189
7329
|
useChatToolWorker = true,
|
|
7190
7330
|
useMockApi,
|
|
7331
|
+
useOwnBackend = false,
|
|
7191
7332
|
userText,
|
|
7192
7333
|
webSearchEnabled = false,
|
|
7193
7334
|
workspaceUri
|
|
7194
7335
|
}) => {
|
|
7195
7336
|
useChatCoordinatorWorker = false; // TODO enable this
|
|
7196
|
-
if (useChatCoordinatorWorker && !
|
|
7337
|
+
if (useChatCoordinatorWorker && !useOwnBackend) {
|
|
7197
7338
|
try {
|
|
7198
7339
|
const result = await getAiResponse$1({
|
|
7199
7340
|
agentMode,
|
|
@@ -7254,7 +7395,7 @@ const getAiResponse = async ({
|
|
|
7254
7395
|
if (hasImageAttachments(messages) && !supportsImages) {
|
|
7255
7396
|
text = getImageNotSupportedMessage(selectedModel?.name);
|
|
7256
7397
|
}
|
|
7257
|
-
if (!text &&
|
|
7398
|
+
if (!text && useOwnBackend) {
|
|
7258
7399
|
if (!backendUrl) {
|
|
7259
7400
|
text = backendUrlRequiredMessage;
|
|
7260
7401
|
} else if (authAccessToken) {
|
|
@@ -7582,6 +7723,7 @@ const handleClickSaveOpenApiApiKey = async state => {
|
|
|
7582
7723
|
useChatCoordinatorWorker: updatedState.useChatCoordinatorWorker,
|
|
7583
7724
|
useChatNetworkWorkerForRequests: updatedState.useChatNetworkWorkerForRequests,
|
|
7584
7725
|
useMockApi: updatedState.useMockApi,
|
|
7726
|
+
useOwnBackend: updatedState.useOwnBackend,
|
|
7585
7727
|
userText: previousUserMessage.text
|
|
7586
7728
|
});
|
|
7587
7729
|
const parsedMessages = await parseAndStoreMessageContent(updatedState.parsedMessages, assistantMessage);
|
|
@@ -7670,6 +7812,7 @@ const handleClickSaveOpenRouterApiKey = async state => {
|
|
|
7670
7812
|
useChatCoordinatorWorker: updatedState.useChatCoordinatorWorker,
|
|
7671
7813
|
useChatNetworkWorkerForRequests: updatedState.useChatNetworkWorkerForRequests,
|
|
7672
7814
|
useMockApi: updatedState.useMockApi,
|
|
7815
|
+
useOwnBackend: updatedState.useOwnBackend,
|
|
7673
7816
|
userText: previousUserMessage.text
|
|
7674
7817
|
});
|
|
7675
7818
|
const parsedMessages = await parseAndStoreMessageContent(updatedState.parsedMessages, assistantMessage);
|
|
@@ -7781,7 +7924,6 @@ Assistant: ${assistantText}`;
|
|
|
7781
7924
|
const getAiSessionTitle = async (state, userText, assistantText) => {
|
|
7782
7925
|
const {
|
|
7783
7926
|
authAccessToken,
|
|
7784
|
-
authEnabled,
|
|
7785
7927
|
backendUrl,
|
|
7786
7928
|
models,
|
|
7787
7929
|
openApiApiBaseUrl,
|
|
@@ -7789,21 +7931,28 @@ const getAiSessionTitle = async (state, userText, assistantText) => {
|
|
|
7789
7931
|
openRouterApiBaseUrl,
|
|
7790
7932
|
openRouterApiKey,
|
|
7791
7933
|
selectedModelId,
|
|
7792
|
-
useMockApi
|
|
7934
|
+
useMockApi,
|
|
7935
|
+
useOwnBackend
|
|
7793
7936
|
} = state;
|
|
7794
7937
|
if (useMockApi) {
|
|
7795
7938
|
return '';
|
|
7796
7939
|
}
|
|
7797
7940
|
const usesOpenApiModel = isOpenApiModel(selectedModelId, models);
|
|
7798
7941
|
const usesOpenRouterModel = isOpenRouterModel(selectedModelId, models);
|
|
7799
|
-
if (
|
|
7800
|
-
|
|
7801
|
-
|
|
7802
|
-
|
|
7803
|
-
|
|
7804
|
-
|
|
7805
|
-
|
|
7806
|
-
|
|
7942
|
+
if (useOwnBackend) {
|
|
7943
|
+
if (!backendUrl || !authAccessToken) {
|
|
7944
|
+
return '';
|
|
7945
|
+
}
|
|
7946
|
+
} else {
|
|
7947
|
+
if (usesOpenApiModel && !openApiApiKey) {
|
|
7948
|
+
return '';
|
|
7949
|
+
}
|
|
7950
|
+
if (usesOpenRouterModel && !openRouterApiKey) {
|
|
7951
|
+
return '';
|
|
7952
|
+
}
|
|
7953
|
+
if (!usesOpenApiModel && !usesOpenRouterModel) {
|
|
7954
|
+
return '';
|
|
7955
|
+
}
|
|
7807
7956
|
}
|
|
7808
7957
|
const titlePrompt = getTitlePrompt(userText, assistantText);
|
|
7809
7958
|
const promptMessage = {
|
|
@@ -7818,7 +7967,6 @@ const getAiSessionTitle = async (state, userText, assistantText) => {
|
|
|
7818
7967
|
const titleResponse = await getAiResponse({
|
|
7819
7968
|
assetDir: state.assetDir,
|
|
7820
7969
|
authAccessToken,
|
|
7821
|
-
authEnabled,
|
|
7822
7970
|
backendUrl,
|
|
7823
7971
|
maxToolCalls: state.maxToolCalls,
|
|
7824
7972
|
messages: [promptMessage],
|
|
@@ -7839,6 +7987,7 @@ const getAiSessionTitle = async (state, userText, assistantText) => {
|
|
|
7839
7987
|
useChatNetworkWorkerForRequests: state.useChatNetworkWorkerForRequests,
|
|
7840
7988
|
useChatToolWorker: state.useChatToolWorker,
|
|
7841
7989
|
useMockApi,
|
|
7990
|
+
useOwnBackend,
|
|
7842
7991
|
userText: titlePrompt,
|
|
7843
7992
|
webSearchEnabled: false
|
|
7844
7993
|
});
|
|
@@ -8279,7 +8428,8 @@ const withProvisionedBackgroundSession = async (state, session) => {
|
|
|
8279
8428
|
};
|
|
8280
8429
|
};
|
|
8281
8430
|
const handleSubmit = async state => {
|
|
8282
|
-
const
|
|
8431
|
+
const shouldSyncBackendAuth = (state.authEnabled || state.useOwnBackend) && !!state.backendUrl;
|
|
8432
|
+
const authState = shouldSyncBackendAuth ? await syncBackendAuth(state.backendUrl) : undefined;
|
|
8283
8433
|
const effectiveState = authState ? {
|
|
8284
8434
|
...state,
|
|
8285
8435
|
...authState
|
|
@@ -8315,6 +8465,7 @@ const handleSubmit = async state => {
|
|
|
8315
8465
|
useChatNetworkWorkerForRequests,
|
|
8316
8466
|
useChatToolWorker,
|
|
8317
8467
|
useMockApi,
|
|
8468
|
+
useOwnBackend,
|
|
8318
8469
|
viewMode,
|
|
8319
8470
|
webSearchEnabled
|
|
8320
8471
|
} = effectiveState;
|
|
@@ -8532,6 +8683,7 @@ const handleSubmit = async state => {
|
|
|
8532
8683
|
useChatNetworkWorkerForRequests,
|
|
8533
8684
|
useChatToolWorker,
|
|
8534
8685
|
useMockApi,
|
|
8686
|
+
useOwnBackend,
|
|
8535
8687
|
userText,
|
|
8536
8688
|
webSearchEnabled,
|
|
8537
8689
|
workspaceUri
|
|
@@ -10318,6 +10470,15 @@ const loadUseChatToolWorker = async () => {
|
|
|
10318
10470
|
}
|
|
10319
10471
|
};
|
|
10320
10472
|
|
|
10473
|
+
const loadUseOwnBackend = async () => {
|
|
10474
|
+
try {
|
|
10475
|
+
const savedUseOwnBackend = await get('chat.useOwnBackend');
|
|
10476
|
+
return typeof savedUseOwnBackend === 'boolean' ? savedUseOwnBackend : false;
|
|
10477
|
+
} catch {
|
|
10478
|
+
return false;
|
|
10479
|
+
}
|
|
10480
|
+
};
|
|
10481
|
+
|
|
10321
10482
|
const loadVoiceDictationEnabled = async () => {
|
|
10322
10483
|
try {
|
|
10323
10484
|
const savedVoiceDictationEnabled = await get('chatView.voiceDictationEnabled');
|
|
@@ -10328,7 +10489,7 @@ const loadVoiceDictationEnabled = async () => {
|
|
|
10328
10489
|
};
|
|
10329
10490
|
|
|
10330
10491
|
const loadPreferences = async () => {
|
|
10331
|
-
const [aiSessionTitleGenerationEnabled, authEnabled, backendUrl, chatHistoryEnabled, composerDropEnabled, openApiApiKey, openRouterApiKey, emitStreamingFunctionCallEvents, reasoningPickerEnabled, scrollDownButtonEnabled, searchEnabled, streamingEnabled, todoListToolEnabled, toolEnablement, passIncludeObfuscation, useChatCoordinatorWorker, useChatMathWorker, useChatNetworkWorkerForRequests, useChatToolWorker, voiceDictationEnabled] = await Promise.all([loadAiSessionTitleGenerationEnabled(), loadAuthEnabled(), loadBackendUrl(), loadChatHistoryEnabled(), loadComposerDropEnabled(), loadOpenApiApiKey(), loadOpenRouterApiKey(), loadEmitStreamingFunctionCallEvents(), loadReasoningPickerEnabled(), loadScrollDownButtonEnabled(), loadSearchEnabled(), loadStreamingEnabled(), loadTodoListToolEnabled(), loadToolEnablement(), loadPassIncludeObfuscation(), loadUseChatCoordinatorWorker(), loadUseChatMathWorker(), loadUseChatNetworkWorkerForRequests(), loadUseChatToolWorker(), loadVoiceDictationEnabled()]);
|
|
10492
|
+
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()]);
|
|
10332
10493
|
return {
|
|
10333
10494
|
aiSessionTitleGenerationEnabled,
|
|
10334
10495
|
authEnabled,
|
|
@@ -10349,6 +10510,7 @@ const loadPreferences = async () => {
|
|
|
10349
10510
|
useChatMathWorker,
|
|
10350
10511
|
useChatNetworkWorkerForRequests,
|
|
10351
10512
|
useChatToolWorker,
|
|
10513
|
+
useOwnBackend,
|
|
10352
10514
|
voiceDictationEnabled
|
|
10353
10515
|
};
|
|
10354
10516
|
};
|
|
@@ -10420,9 +10582,10 @@ const loadContent = async (state, savedState) => {
|
|
|
10420
10582
|
useChatMathWorker,
|
|
10421
10583
|
useChatNetworkWorkerForRequests,
|
|
10422
10584
|
useChatToolWorker,
|
|
10585
|
+
useOwnBackend,
|
|
10423
10586
|
voiceDictationEnabled
|
|
10424
10587
|
} = await loadPreferences();
|
|
10425
|
-
const authState = authEnabled
|
|
10588
|
+
const authState = authEnabled || useOwnBackend ? backendUrl ? await syncBackendAuth(backendUrl) : getLoggedOutBackendAuthState() : getLoggedOutBackendAuthState();
|
|
10426
10589
|
const legacySavedSessions = getSavedSessions(savedState);
|
|
10427
10590
|
const storedSessions = await listChatSessions();
|
|
10428
10591
|
let sessions = storedSessions;
|
|
@@ -10530,6 +10693,7 @@ const loadContent = async (state, savedState) => {
|
|
|
10530
10693
|
useChatMathWorker,
|
|
10531
10694
|
useChatNetworkWorkerForRequests,
|
|
10532
10695
|
useChatToolWorker,
|
|
10696
|
+
useOwnBackend,
|
|
10533
10697
|
userName: authState.userName,
|
|
10534
10698
|
userState: authState.userState,
|
|
10535
10699
|
userSubscriptionPlan: authState.userSubscriptionPlan,
|
|
@@ -10555,15 +10719,19 @@ const getDelay = payload => {
|
|
|
10555
10719
|
};
|
|
10556
10720
|
const mockBackendAuthResponse = (state, payload) => {
|
|
10557
10721
|
const delay = getDelay(payload);
|
|
10722
|
+
const setNextResponse = payload.request === 'refresh' ? setNextRefreshResponse : setNextLoginResponse;
|
|
10558
10723
|
if (payload.type === 'error') {
|
|
10559
|
-
|
|
10724
|
+
setNextResponse({
|
|
10560
10725
|
delay,
|
|
10726
|
+
...(payload.errorName ? {
|
|
10727
|
+
errorName: payload.errorName
|
|
10728
|
+
} : {}),
|
|
10561
10729
|
message: payload.message || 'Backend authentication failed.',
|
|
10562
10730
|
type: 'error'
|
|
10563
10731
|
});
|
|
10564
10732
|
return state;
|
|
10565
10733
|
}
|
|
10566
|
-
|
|
10734
|
+
setNextResponse({
|
|
10567
10735
|
delay,
|
|
10568
10736
|
response: payload,
|
|
10569
10737
|
type: 'success'
|
|
@@ -10571,6 +10739,11 @@ const mockBackendAuthResponse = (state, payload) => {
|
|
|
10571
10739
|
return state;
|
|
10572
10740
|
};
|
|
10573
10741
|
|
|
10742
|
+
const mockBackendSetHttpErrorResponse = (state, statusCode, body) => {
|
|
10743
|
+
setHttpErrorResponse(statusCode, body);
|
|
10744
|
+
return state;
|
|
10745
|
+
};
|
|
10746
|
+
|
|
10574
10747
|
const mockOpenApiRequestGetAll = _state => {
|
|
10575
10748
|
return getAll();
|
|
10576
10749
|
};
|
|
@@ -10581,7 +10754,7 @@ const mockOpenApiRequestReset = state => {
|
|
|
10581
10754
|
};
|
|
10582
10755
|
|
|
10583
10756
|
const mockOpenApiSetHttpErrorResponse = (state, statusCode, body) => {
|
|
10584
|
-
setHttpErrorResponse(statusCode, body);
|
|
10757
|
+
setHttpErrorResponse$1(statusCode, body);
|
|
10585
10758
|
return state;
|
|
10586
10759
|
};
|
|
10587
10760
|
|
|
@@ -15544,6 +15717,18 @@ const setUseChatNetworkWorkerForRequests = async (state, useChatNetworkWorkerFor
|
|
|
15544
15717
|
};
|
|
15545
15718
|
};
|
|
15546
15719
|
|
|
15720
|
+
const setUseOwnBackend = async (state, useOwnBackend, persist = true) => {
|
|
15721
|
+
if (persist) {
|
|
15722
|
+
await update({
|
|
15723
|
+
'chat.useOwnBackend': useOwnBackend
|
|
15724
|
+
});
|
|
15725
|
+
}
|
|
15726
|
+
return {
|
|
15727
|
+
...state,
|
|
15728
|
+
useOwnBackend
|
|
15729
|
+
};
|
|
15730
|
+
};
|
|
15731
|
+
|
|
15547
15732
|
const defaultMockApiCommandId = 'ChatE2e.mockApi';
|
|
15548
15733
|
const useMockApi = (state, value, mockApiCommandId = defaultMockApiCommandId) => {
|
|
15549
15734
|
if (!value) {
|
|
@@ -15644,6 +15829,7 @@ const commandMap = {
|
|
|
15644
15829
|
'Chat.loadContent': wrapCommand(loadContent),
|
|
15645
15830
|
'Chat.loadContent2': wrapCommand(loadContent),
|
|
15646
15831
|
'Chat.mockBackendAuthResponse': wrapCommand(mockBackendAuthResponse),
|
|
15832
|
+
'Chat.mockBackendSetHttpErrorResponse': wrapCommand(mockBackendSetHttpErrorResponse),
|
|
15647
15833
|
'Chat.mockOpenApiRequestGetAll': wrapGetter(mockOpenApiRequestGetAll),
|
|
15648
15834
|
'Chat.mockOpenApiRequestReset': wrapCommand(mockOpenApiRequestReset),
|
|
15649
15835
|
'Chat.mockOpenApiSetHttpErrorResponse': wrapCommand(mockOpenApiSetHttpErrorResponse),
|
|
@@ -15689,6 +15875,7 @@ const commandMap = {
|
|
|
15689
15875
|
'Chat.setUseChatCoordinatorWorker': wrapCommand(setUseChatCoordinatorWorker),
|
|
15690
15876
|
'Chat.setUseChatMathWorker': wrapCommand(setUseChatMathWorker),
|
|
15691
15877
|
'Chat.setUseChatNetworkWorkerForRequests': wrapCommand(setUseChatNetworkWorkerForRequests),
|
|
15878
|
+
'Chat.setUseOwnBackend': wrapCommand(setUseOwnBackend),
|
|
15692
15879
|
'Chat.showComposerAttachmentPreviewOverlay': wrapCommand(showComposerAttachmentPreviewOverlay),
|
|
15693
15880
|
'Chat.terminate': terminate,
|
|
15694
15881
|
'Chat.useMockApi': wrapCommand(useMockApi)
|