@lvce-editor/chat-view 4.3.0 → 4.4.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.
@@ -851,7 +851,7 @@ const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer)
851
851
  const responseMessage = await promise;
852
852
  return unwrapJsonRpcResult(responseMessage);
853
853
  };
854
- const createRpc = ipc => {
854
+ const createRpc$1 = ipc => {
855
855
  const callbacks = Object.create(null);
856
856
  ipc._resolve = (id, response) => {
857
857
  const fn = callbacks[id];
@@ -931,7 +931,7 @@ const create$6 = async ({
931
931
  });
932
932
  const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
933
933
  handleIpc(ipc);
934
- const rpc = createRpc(ipc);
934
+ const rpc = createRpc$1(ipc);
935
935
  messagePort.start();
936
936
  return rpc;
937
937
  };
@@ -1002,7 +1002,7 @@ const create$3 = async ({
1002
1002
  register(commandMap);
1003
1003
  const ipc = await listen$1(IpcChildWithModuleWorkerAndMessagePort$1);
1004
1004
  handleIpc(ipc);
1005
- const rpc = createRpc(ipc);
1005
+ const rpc = createRpc$1(ipc);
1006
1006
  return rpc;
1007
1007
  };
1008
1008
 
@@ -1027,7 +1027,7 @@ const createMockRpc = ({
1027
1027
  };
1028
1028
 
1029
1029
  const rpcs = Object.create(null);
1030
- const set$4 = (id, rpc) => {
1030
+ const set$5 = (id, rpc) => {
1031
1031
  rpcs[id] = rpc;
1032
1032
  };
1033
1033
  const get$2 = id => {
@@ -1060,7 +1060,7 @@ const create$2 = rpcId => {
1060
1060
  const mockRpc = createMockRpc({
1061
1061
  commandMap
1062
1062
  });
1063
- set$4(rpcId, mockRpc);
1063
+ set$5(rpcId, mockRpc);
1064
1064
  // @ts-ignore
1065
1065
  mockRpc[Symbol.dispose] = () => {
1066
1066
  remove(rpcId);
@@ -1069,15 +1069,14 @@ const create$2 = rpcId => {
1069
1069
  return mockRpc;
1070
1070
  },
1071
1071
  set(rpc) {
1072
- set$4(rpcId, rpc);
1072
+ set$5(rpcId, rpc);
1073
1073
  }
1074
1074
  };
1075
1075
  };
1076
1076
 
1077
1077
  const {
1078
- invoke: invoke$2,
1079
- set: set$3
1080
- } = create$2(6002);
1078
+ set: set$4
1079
+ } = create$2(6007);
1081
1080
 
1082
1081
  const Button$2 = 'button';
1083
1082
 
@@ -1146,6 +1145,7 @@ const Enter = 3;
1146
1145
 
1147
1146
  const Shift = 1 << 10 >>> 0;
1148
1147
 
1148
+ const ChatNetworkWorker = 6002;
1149
1149
  const ExtensionHostWorker = 44;
1150
1150
  const RendererWorker = 1;
1151
1151
 
@@ -1159,6 +1159,11 @@ const SetPatches = 'Viewlet.setPatches';
1159
1159
 
1160
1160
  const FocusChatInput = 8000;
1161
1161
 
1162
+ const {
1163
+ invoke: invoke$2,
1164
+ set: set$3
1165
+ } = create$2(ChatNetworkWorker);
1166
+
1162
1167
  const {
1163
1168
  invoke: invoke$1,
1164
1169
  set: set$2
@@ -2956,6 +2961,17 @@ const openRouterTooManyRequestsMessage = 'OpenRouter rate limit reached (429). P
2956
2961
  const openRouterRequestFailureReasons = ['ContentSecurityPolicyViolation: Check DevTools for details.', 'OpenRouter server offline: Check DevTools for details.', 'Check your internet connection.'];
2957
2962
  const openRouterTooManyRequestsReasons = ['Wait a short time and retry your request.', 'Reduce request frequency to avoid rate limits.', 'Use a different model if this one is saturated.'];
2958
2963
 
2964
+ const getToolErrorPayload = error => {
2965
+ const rawStack = error && typeof error === 'object' ? Reflect.get(error, 'stack') : undefined;
2966
+ return {
2967
+ error: String(error),
2968
+ ...(typeof rawStack === 'string' && rawStack.trim() ? {
2969
+ errorStack: rawStack,
2970
+ stack: rawStack
2971
+ } : {})
2972
+ };
2973
+ };
2974
+
2959
2975
  const executeGetWorkspaceUriTool = async (_args, _options) => {
2960
2976
  try {
2961
2977
  const workspaceUri = await getWorkspacePath();
@@ -2963,9 +2979,7 @@ const executeGetWorkspaceUriTool = async (_args, _options) => {
2963
2979
  workspaceUri
2964
2980
  });
2965
2981
  } catch (error) {
2966
- return JSON.stringify({
2967
- error: String(error)
2968
- });
2982
+ return JSON.stringify(getToolErrorPayload(error));
2969
2983
  }
2970
2984
  };
2971
2985
 
@@ -2987,7 +3001,7 @@ const executeListFilesTool = async (args, _options) => {
2987
3001
  });
2988
3002
  } catch (error) {
2989
3003
  return JSON.stringify({
2990
- error: String(error),
3004
+ ...getToolErrorPayload(error),
2991
3005
  uri
2992
3006
  });
2993
3007
  }
@@ -3037,10 +3051,7 @@ const executeReadFileTool = async (args, _options) => {
3037
3051
  });
3038
3052
  } catch (error) {
3039
3053
  return JSON.stringify({
3040
- error: String(error),
3041
- ...(error instanceof Error && typeof error.stack === 'string' ? {
3042
- stack: error.stack
3043
- } : {}),
3054
+ ...getToolErrorPayload(error),
3044
3055
  uri
3045
3056
  });
3046
3057
  }
@@ -3060,10 +3071,7 @@ const executeReadFileTool = async (args, _options) => {
3060
3071
  });
3061
3072
  } catch (error) {
3062
3073
  return JSON.stringify({
3063
- error: String(error),
3064
- ...(error instanceof Error && typeof error.stack === 'string' ? {
3065
- stack: error.stack
3066
- } : {}),
3074
+ ...getToolErrorPayload(error),
3067
3075
  path: normalizedPath
3068
3076
  });
3069
3077
  }
@@ -3109,7 +3117,7 @@ const executeWriteFileTool = async (args, _options) => {
3109
3117
  });
3110
3118
  } catch (error) {
3111
3119
  return JSON.stringify({
3112
- error: String(error),
3120
+ ...getToolErrorPayload(error),
3113
3121
  path: normalizedPath
3114
3122
  });
3115
3123
  }
@@ -3346,6 +3354,36 @@ const readNextChunk = async () => {
3346
3354
  return promise;
3347
3355
  };
3348
3356
 
3357
+ const getResponseFunctionCalls$1 = value => {
3358
+ if (!value || typeof value !== 'object') {
3359
+ return [];
3360
+ }
3361
+ const output = Reflect.get(value, 'output');
3362
+ if (!Array.isArray(output)) {
3363
+ return [];
3364
+ }
3365
+ const responseFunctionCalls = [];
3366
+ for (const item of output) {
3367
+ if (!item || typeof item !== 'object') {
3368
+ continue;
3369
+ }
3370
+ if (Reflect.get(item, 'type') !== 'function_call') {
3371
+ continue;
3372
+ }
3373
+ const callId = Reflect.get(item, 'call_id');
3374
+ const name = Reflect.get(item, 'name');
3375
+ const rawArguments = Reflect.get(item, 'arguments');
3376
+ if (typeof callId !== 'string' || typeof name !== 'string') {
3377
+ continue;
3378
+ }
3379
+ responseFunctionCalls.push({
3380
+ arguments: typeof rawArguments === 'string' ? rawArguments : '',
3381
+ callId,
3382
+ name
3383
+ });
3384
+ }
3385
+ return responseFunctionCalls;
3386
+ };
3349
3387
  const parseSseDataLines = eventChunk => {
3350
3388
  const lines = eventChunk.split('\n');
3351
3389
  const dataLines = [];
@@ -3375,6 +3413,9 @@ const getMockOpenApiAssistantText = async (stream, onTextChunk, onToolCallsChunk
3375
3413
  let text = '';
3376
3414
  let remainder = '';
3377
3415
  let toolCallAccumulator = {};
3416
+ let responseFunctionCalls = [];
3417
+ let responseId;
3418
+ let requestDone = false;
3378
3419
  let finishedNotified = false;
3379
3420
  const notifyFinished = async () => {
3380
3421
  if (finishedNotified) {
@@ -3394,6 +3435,13 @@ const getMockOpenApiAssistantText = async (stream, onTextChunk, onToolCallsChunk
3394
3435
  }
3395
3436
  const eventType = Reflect.get(parsed, 'type');
3396
3437
  if (eventType === 'response.completed') {
3438
+ const response = Reflect.get(parsed, 'response');
3439
+ responseFunctionCalls = getResponseFunctionCalls$1(response);
3440
+ const parsedResponseId = response && typeof response === 'object' ? Reflect.get(response, 'id') : undefined;
3441
+ if (typeof parsedResponseId === 'string' && parsedResponseId) {
3442
+ responseId = parsedResponseId;
3443
+ }
3444
+ requestDone = true;
3397
3445
  await notifyFinished();
3398
3446
  return;
3399
3447
  }
@@ -3465,8 +3513,9 @@ const getMockOpenApiAssistantText = async (stream, onTextChunk, onToolCallsChunk
3465
3513
  const consumeSseDataLines = async dataLines => {
3466
3514
  for (const line of dataLines) {
3467
3515
  if (line === '[DONE]') {
3516
+ requestDone = true;
3468
3517
  await notifyFinished();
3469
- continue;
3518
+ break;
3470
3519
  }
3471
3520
  let parsed;
3472
3521
  try {
@@ -3475,9 +3524,12 @@ const getMockOpenApiAssistantText = async (stream, onTextChunk, onToolCallsChunk
3475
3524
  continue;
3476
3525
  }
3477
3526
  await handleParsedSseEvent(parsed);
3527
+ if (requestDone) {
3528
+ break;
3529
+ }
3478
3530
  }
3479
3531
  };
3480
- while (true) {
3532
+ while (!requestDone) {
3481
3533
  const chunk = await readNextChunk();
3482
3534
  if (typeof chunk !== 'string') {
3483
3535
  break;
@@ -3493,6 +3545,9 @@ const getMockOpenApiAssistantText = async (stream, onTextChunk, onToolCallsChunk
3493
3545
  remainder = remainder.slice(separatorIndex + 2);
3494
3546
  const dataLines = parseSseDataLines(rawEvent);
3495
3547
  await consumeSseDataLines(dataLines);
3548
+ if (requestDone) {
3549
+ break;
3550
+ }
3496
3551
  }
3497
3552
  continue;
3498
3553
  }
@@ -3501,12 +3556,16 @@ const getMockOpenApiAssistantText = async (stream, onTextChunk, onToolCallsChunk
3501
3556
  await onTextChunk(chunk);
3502
3557
  }
3503
3558
  }
3504
- if (remainder) {
3559
+ if (!requestDone && remainder) {
3505
3560
  const dataLines = parseSseDataLines(remainder);
3506
3561
  await consumeSseDataLines(dataLines);
3507
3562
  }
3508
3563
  await notifyFinished();
3509
3564
  return {
3565
+ ...(responseId ? {
3566
+ responseId
3567
+ } : {}),
3568
+ responseFunctionCalls,
3510
3569
  text,
3511
3570
  type: 'success'
3512
3571
  };
@@ -3782,18 +3841,22 @@ const getToolCallExecutionStatus = content => {
3782
3841
  status: 'success'
3783
3842
  };
3784
3843
  }
3785
- const rawErrorStack = Reflect.get(parsed, 'stack');
3844
+ const rawStack = Reflect.get(parsed, 'errorStack') ?? Reflect.get(parsed, 'stack');
3845
+ const errorStack = typeof rawStack === 'string' && rawStack.trim() ? rawStack : undefined;
3786
3846
  const errorMessage = getShortToolErrorMessage(rawError);
3787
3847
  if (/not[\s_-]?found|enoent/i.test(errorMessage)) {
3788
3848
  return {
3849
+ ...(errorStack ? {
3850
+ errorStack
3851
+ } : {}),
3789
3852
  status: 'not-found'
3790
3853
  };
3791
3854
  }
3792
3855
  return {
3793
- errorMessage,
3794
- ...(typeof rawErrorStack === 'string' && rawErrorStack.trim() ? {
3795
- errorStack: rawErrorStack
3856
+ ...(errorStack ? {
3857
+ errorStack
3796
3858
  } : {}),
3859
+ errorMessage,
3797
3860
  status: 'error'
3798
3861
  };
3799
3862
  };
@@ -4397,6 +4460,9 @@ const getOpenApiAssistantText = async (messages, modelId, openApiApiKey, openApi
4397
4460
  const executionStatus = getToolCallExecutionStatus(content);
4398
4461
  executedToolCalls.push({
4399
4462
  arguments: toolCall.arguments,
4463
+ ...(executionStatus.errorStack ? {
4464
+ errorStack: executionStatus.errorStack
4465
+ } : {}),
4400
4466
  ...(executionStatus.errorMessage ? {
4401
4467
  errorMessage: executionStatus.errorMessage
4402
4468
  } : {}),
@@ -4535,6 +4601,9 @@ const getOpenApiAssistantText = async (messages, modelId, openApiApiKey, openApi
4535
4601
  const executionStatus = getToolCallExecutionStatus(content);
4536
4602
  executedToolCalls.push({
4537
4603
  arguments: toolCall.arguments,
4604
+ ...(executionStatus.errorStack ? {
4605
+ errorStack: executionStatus.errorStack
4606
+ } : {}),
4538
4607
  ...(executionStatus.errorMessage ? {
4539
4608
  errorMessage: executionStatus.errorMessage
4540
4609
  } : {}),
@@ -4601,6 +4670,9 @@ const getOpenApiAssistantText = async (messages, modelId, openApiApiKey, openApi
4601
4670
  const executionStatus = getToolCallExecutionStatus(content);
4602
4671
  executedToolCalls.push({
4603
4672
  arguments: typeof rawArguments === 'string' ? rawArguments : '',
4673
+ ...(executionStatus.errorStack ? {
4674
+ errorStack: executionStatus.errorStack
4675
+ } : {}),
4604
4676
  ...(executionStatus.errorMessage ? {
4605
4677
  errorMessage: executionStatus.errorMessage
4606
4678
  } : {}),
@@ -5101,6 +5173,8 @@ const getAll = () => {
5101
5173
  return requests;
5102
5174
  };
5103
5175
 
5176
+ /* eslint-disable prefer-destructuring */
5177
+
5104
5178
  const getAiResponse = async ({
5105
5179
  assetDir,
5106
5180
  messageId,
@@ -5140,20 +5214,36 @@ const getAiResponse = async ({
5140
5214
  'Content-Type': 'application/json',
5141
5215
  ...getClientRequestIdHeader()
5142
5216
  };
5143
- capture({
5144
- headers,
5145
- method: 'POST',
5146
- payload: getOpenAiParams(openAiInput, modelId, streamingEnabled, passIncludeObfuscation, getBasicChatTools(), webSearchEnabled),
5147
- url: getOpenApiApiEndpoint(openApiApiBaseUrl)
5148
- });
5149
- const result = await getMockOpenApiAssistantText(streamingEnabled, onTextChunk, onToolCallsChunk, onDataEvent, onEventStreamFinished);
5150
- if (result.type === 'success') {
5151
- const {
5152
- text: assistantText
5153
- } = result;
5154
- text = assistantText;
5155
- } else {
5156
- text = getOpenApiErrorMessage(result);
5217
+ const maxToolIterations = 4;
5218
+ let previousResponseId;
5219
+ for (let i = 0; i <= maxToolIterations; i++) {
5220
+ capture({
5221
+ headers,
5222
+ method: 'POST',
5223
+ payload: getOpenAiParams(openAiInput, modelId, streamingEnabled, passIncludeObfuscation, getBasicChatTools(), webSearchEnabled, previousResponseId),
5224
+ url: getOpenApiApiEndpoint(openApiApiBaseUrl)
5225
+ });
5226
+ const result = await getMockOpenApiAssistantText(streamingEnabled, onTextChunk, onToolCallsChunk, onDataEvent, onEventStreamFinished);
5227
+ if (result.type !== 'success') {
5228
+ text = getOpenApiErrorMessage(result);
5229
+ break;
5230
+ }
5231
+ text = result.text;
5232
+ if (result.responseId) {
5233
+ previousResponseId = result.responseId;
5234
+ }
5235
+ if (result.responseFunctionCalls.length === 0) {
5236
+ break;
5237
+ }
5238
+ openAiInput.length = 0;
5239
+ for (const toolCall of result.responseFunctionCalls) {
5240
+ const content = await executeChatTool(toolCall.name, toolCall.arguments);
5241
+ openAiInput.push({
5242
+ call_id: toolCall.callId,
5243
+ output: content,
5244
+ type: 'function_call_output'
5245
+ });
5246
+ }
5157
5247
  }
5158
5248
  } else if (openApiApiKey) {
5159
5249
  const result = await getOpenApiAssistantText(messages, getOpenApiModelId(selectedModelId), openApiApiKey, openApiApiBaseUrl, assetDir, platform, {
@@ -6525,7 +6615,7 @@ const createExtensionHostRpc = async () => {
6525
6615
  }
6526
6616
  };
6527
6617
 
6528
- const initialize = async () => {
6618
+ const initialize$1 = async () => {
6529
6619
  const rpc = await createExtensionHostRpc();
6530
6620
  set$2(rpc);
6531
6621
  };
@@ -25993,7 +26083,7 @@ const commandMap = {
25993
26083
  'Chat.handleProjectListContextMenu': wrapCommand(handleProjectListContextMenu),
25994
26084
  'Chat.handleProjectListScroll': wrapCommand(handleProjectListScroll),
25995
26085
  'Chat.handleSubmit': wrapCommand(handleSubmit),
25996
- 'Chat.initialize': initialize,
26086
+ 'Chat.initialize': initialize$1,
25997
26087
  'Chat.loadContent': wrapCommand(loadContent),
25998
26088
  'Chat.loadContent2': wrapCommand(loadContent),
25999
26089
  'Chat.mockOpenApiRequestGetAll': wrapGetter(mockOpenApiRequestGetAll),
@@ -26019,6 +26109,33 @@ const commandMap = {
26019
26109
  'Chat.useMockApi': wrapCommand(useMockApi)
26020
26110
  };
26021
26111
 
26112
+ let initialized = false;
26113
+ const sendMessagePortToChatMathWorker = async port => {
26114
+ try {
26115
+ await invoke('sendMessagePortToChatMathWorker', port);
26116
+ } catch {
26117
+ await invoke('SendMessagePortToChatMathWorker.sendMessagePortToChatMathWorker', port);
26118
+ }
26119
+ };
26120
+ const createRpc = () => {
26121
+ return create$4({
26122
+ commandMap: {},
26123
+ send: sendMessagePortToChatMathWorker
26124
+ });
26125
+ };
26126
+ const initialize = async () => {
26127
+ if (initialized) {
26128
+ return;
26129
+ }
26130
+ const rpc = await createRpc();
26131
+ set$4(rpc);
26132
+ initialized = true;
26133
+ };
26134
+
26135
+ const initializeChatMathWorker = async () => {
26136
+ await initialize();
26137
+ };
26138
+
26022
26139
  const send = port => {
26023
26140
  return sendMessagePortToChatNetworkWorker(port);
26024
26141
  };
@@ -26036,7 +26153,7 @@ const listen = async () => {
26036
26153
  commandMap: commandMap
26037
26154
  });
26038
26155
  set$1(rpc);
26039
- await initializeChatNetworkWorker();
26156
+ await Promise.all([initializeChatNetworkWorker(), initializeChatMathWorker()]);
26040
26157
  };
26041
26158
 
26042
26159
  const main = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/chat-view",
3
- "version": "4.3.0",
3
+ "version": "4.4.0",
4
4
  "description": "Chat View Worker",
5
5
  "repository": {
6
6
  "type": "git",