@lvce-editor/chat-view 7.9.0 → 7.10.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 +77 -19
- package/package.json +1 -1
|
@@ -7189,9 +7189,9 @@ const takeErrorResponse = () => {
|
|
|
7189
7189
|
/* eslint-disable prefer-destructuring */
|
|
7190
7190
|
|
|
7191
7191
|
const trailingSlashesRegex = /\/+$/;
|
|
7192
|
-
const
|
|
7192
|
+
const getBackendResponsesEndpoint = backendUrl => {
|
|
7193
7193
|
const trimmedBackendUrl = backendUrl.replace(trailingSlashesRegex, '');
|
|
7194
|
-
return `${trimmedBackendUrl}/v1/
|
|
7194
|
+
return `${trimmedBackendUrl}/v1/responses`;
|
|
7195
7195
|
};
|
|
7196
7196
|
const hasImageAttachments = messages => {
|
|
7197
7197
|
return messages.some(message => message.attachments?.some(attachment => attachment.displayType === 'image'));
|
|
@@ -7230,7 +7230,75 @@ const getBackendStatusCodeFromBody = body => {
|
|
|
7230
7230
|
}
|
|
7231
7231
|
return undefined;
|
|
7232
7232
|
};
|
|
7233
|
-
const
|
|
7233
|
+
const getBackendResponseOutputText = body => {
|
|
7234
|
+
if (!isObject$2(body)) {
|
|
7235
|
+
return '';
|
|
7236
|
+
}
|
|
7237
|
+
const outputText = Reflect.get(body, 'output_text');
|
|
7238
|
+
if (typeof outputText === 'string' && outputText) {
|
|
7239
|
+
return outputText;
|
|
7240
|
+
}
|
|
7241
|
+
const text = Reflect.get(body, 'text');
|
|
7242
|
+
if (typeof text === 'string' && text) {
|
|
7243
|
+
return text;
|
|
7244
|
+
}
|
|
7245
|
+
const message = Reflect.get(body, 'message');
|
|
7246
|
+
if (isObject$2(message)) {
|
|
7247
|
+
const content = Reflect.get(message, 'content');
|
|
7248
|
+
if (typeof content === 'string' && content) {
|
|
7249
|
+
return content;
|
|
7250
|
+
}
|
|
7251
|
+
}
|
|
7252
|
+
const choices = Reflect.get(body, 'choices');
|
|
7253
|
+
if (Array.isArray(choices)) {
|
|
7254
|
+
const firstChoice = choices[0];
|
|
7255
|
+
if (isObject$2(firstChoice)) {
|
|
7256
|
+
const firstMessage = Reflect.get(firstChoice, 'message');
|
|
7257
|
+
if (isObject$2(firstMessage)) {
|
|
7258
|
+
const content = Reflect.get(firstMessage, 'content');
|
|
7259
|
+
if (typeof content === 'string' && content) {
|
|
7260
|
+
return content;
|
|
7261
|
+
}
|
|
7262
|
+
}
|
|
7263
|
+
}
|
|
7264
|
+
}
|
|
7265
|
+
const output = Reflect.get(body, 'output');
|
|
7266
|
+
if (!Array.isArray(output)) {
|
|
7267
|
+
return '';
|
|
7268
|
+
}
|
|
7269
|
+
const chunks = [];
|
|
7270
|
+
for (const outputItem of output) {
|
|
7271
|
+
if (!isObject$2(outputItem)) {
|
|
7272
|
+
continue;
|
|
7273
|
+
}
|
|
7274
|
+
if (Reflect.get(outputItem, 'type') !== 'message') {
|
|
7275
|
+
continue;
|
|
7276
|
+
}
|
|
7277
|
+
const content = Reflect.get(outputItem, 'content');
|
|
7278
|
+
if (!Array.isArray(content)) {
|
|
7279
|
+
continue;
|
|
7280
|
+
}
|
|
7281
|
+
for (const part of content) {
|
|
7282
|
+
if (!isObject$2(part)) {
|
|
7283
|
+
continue;
|
|
7284
|
+
}
|
|
7285
|
+
const type = Reflect.get(part, 'type');
|
|
7286
|
+
const text = Reflect.get(part, 'text');
|
|
7287
|
+
if ((type === 'output_text' || type === 'text') && typeof text === 'string' && text) {
|
|
7288
|
+
chunks.push(text);
|
|
7289
|
+
}
|
|
7290
|
+
}
|
|
7291
|
+
}
|
|
7292
|
+
return chunks.join('');
|
|
7293
|
+
};
|
|
7294
|
+
const getBackendResponsesBody = (messages, modelId, systemPrompt, tools, maxToolCalls, webSearchEnabled, reasoningEffort, supportsReasoningEffort = false) => {
|
|
7295
|
+
const input = messages.map(message => ({
|
|
7296
|
+
content: getChatMessageOpenAiContent(message),
|
|
7297
|
+
role: message.role
|
|
7298
|
+
}));
|
|
7299
|
+
return getOpenAiParams(input, modelId, false, false, tools, webSearchEnabled, maxToolCalls, systemPrompt, undefined, reasoningEffort, supportsReasoningEffort);
|
|
7300
|
+
};
|
|
7301
|
+
const getBackendAssistantText = async (messages, modelId, backendUrl, authAccessToken, systemPrompt, agentMode = defaultAgentMode, questionToolEnabled = false, toolEnablement, maxToolCalls = defaultMaxToolCalls, webSearchEnabled = false, reasoningEffort, supportsReasoningEffort = false) => {
|
|
7234
7302
|
const mockError = takeErrorResponse();
|
|
7235
7303
|
if (mockError) {
|
|
7236
7304
|
const errorMessage = getBackendErrorMessageFromBody(mockError.body);
|
|
@@ -7246,19 +7314,9 @@ const getBackendAssistantText = async (messages, selectedModelId, backendUrl, au
|
|
|
7246
7314
|
}
|
|
7247
7315
|
let response;
|
|
7248
7316
|
try {
|
|
7249
|
-
|
|
7250
|
-
|
|
7251
|
-
|
|
7252
|
-
content: systemPrompt,
|
|
7253
|
-
role: 'system'
|
|
7254
|
-
}] : []), ...messages.map(message => ({
|
|
7255
|
-
content: message.text,
|
|
7256
|
-
role: message.role
|
|
7257
|
-
}))],
|
|
7258
|
-
model: selectedModelId,
|
|
7259
|
-
selectedModelId,
|
|
7260
|
-
stream: false
|
|
7261
|
-
}),
|
|
7317
|
+
const tools = await getBasicChatTools(agentMode, questionToolEnabled, toolEnablement);
|
|
7318
|
+
response = await fetch(getBackendResponsesEndpoint(backendUrl), {
|
|
7319
|
+
body: JSON.stringify(getBackendResponsesBody(messages, modelId, systemPrompt, tools, maxToolCalls, webSearchEnabled, reasoningEffort, supportsReasoningEffort)),
|
|
7262
7320
|
headers: {
|
|
7263
7321
|
Authorization: `Bearer ${authAccessToken}`,
|
|
7264
7322
|
'Content-Type': 'application/json',
|
|
@@ -7291,7 +7349,7 @@ const getBackendAssistantText = async (messages, selectedModelId, backendUrl, au
|
|
|
7291
7349
|
} catch {
|
|
7292
7350
|
return backendCompletionFailedMessage;
|
|
7293
7351
|
}
|
|
7294
|
-
const content = json
|
|
7352
|
+
const content = getBackendResponseOutputText(json);
|
|
7295
7353
|
return typeof content === 'string' && content ? content : backendCompletionFailedMessage;
|
|
7296
7354
|
};
|
|
7297
7355
|
const getAiResponse = async ({
|
|
@@ -7392,6 +7450,7 @@ const getAiResponse = async ({
|
|
|
7392
7450
|
const selectedModel = models.find(model => model.id === selectedModelId);
|
|
7393
7451
|
const supportsImages = selectedModel?.supportsImages ?? false;
|
|
7394
7452
|
const supportsReasoningEffort = selectedModel?.supportsReasoningEffort ?? false;
|
|
7453
|
+
const safeMaxToolCalls = Math.max(1, maxToolCalls);
|
|
7395
7454
|
if (hasImageAttachments(messages) && !supportsImages) {
|
|
7396
7455
|
text = getImageNotSupportedMessage(selectedModel?.name);
|
|
7397
7456
|
}
|
|
@@ -7399,13 +7458,12 @@ const getAiResponse = async ({
|
|
|
7399
7458
|
if (!backendUrl) {
|
|
7400
7459
|
text = backendUrlRequiredMessage;
|
|
7401
7460
|
} else if (authAccessToken) {
|
|
7402
|
-
text = await getBackendAssistantText(messages, selectedModelId, backendUrl, authAccessToken, systemPrompt);
|
|
7461
|
+
text = await getBackendAssistantText(messages, getOpenApiModelId(selectedModelId), backendUrl, authAccessToken, systemPrompt, agentMode, questionToolEnabled, toolEnablement, safeMaxToolCalls, agentMode === 'plan' ? false : webSearchEnabled, reasoningEffort, supportsReasoningEffort);
|
|
7403
7462
|
} else {
|
|
7404
7463
|
text = backendAccessTokenRequiredMessage;
|
|
7405
7464
|
}
|
|
7406
7465
|
}
|
|
7407
7466
|
if (!text && usesOpenApiModel) {
|
|
7408
|
-
const safeMaxToolCalls = Math.max(1, maxToolCalls);
|
|
7409
7467
|
if (useMockApi) {
|
|
7410
7468
|
const openAiInput = messages.map(message => ({
|
|
7411
7469
|
content: getChatMessageOpenAiContent(message),
|