@browser-ai/core 2.0.2 → 2.0.3

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/index.mjs CHANGED
@@ -454,44 +454,6 @@ function getExpectedInputs(prompt) {
454
454
  }
455
455
  return Array.from(inputs).map((type) => ({ type }));
456
456
  }
457
- function prependSystemPromptToMessages(messages, systemPrompt) {
458
- if (!systemPrompt.trim()) {
459
- return messages;
460
- }
461
- const prompts = messages.map((message) => ({ ...message }));
462
- const firstUserIndex = prompts.findIndex(
463
- (message) => message.role === "user"
464
- );
465
- if (firstUserIndex !== -1) {
466
- const firstUserMessage = prompts[firstUserIndex];
467
- if (Array.isArray(firstUserMessage.content)) {
468
- const content = firstUserMessage.content.slice();
469
- content.unshift({
470
- type: "text",
471
- value: `${systemPrompt}
472
-
473
- `
474
- });
475
- prompts[firstUserIndex] = {
476
- ...firstUserMessage,
477
- content
478
- };
479
- } else if (typeof firstUserMessage.content === "string") {
480
- prompts[firstUserIndex] = {
481
- ...firstUserMessage,
482
- content: `${systemPrompt}
483
-
484
- ${firstUserMessage.content}`
485
- };
486
- }
487
- } else {
488
- prompts.unshift({
489
- role: "user",
490
- content: systemPrompt
491
- });
492
- }
493
- return prompts;
494
- }
495
457
 
496
458
  // src/utils/tool-utils.ts
497
459
  function isFunctionTool(tool) {
@@ -1089,19 +1051,19 @@ var BrowserAIChatLanguageModel = class {
1089
1051
  expectedInputs,
1090
1052
  functionTools
1091
1053
  } = converted;
1092
- const session = await this.getSession(void 0, expectedInputs, void 0);
1093
- const systemPrompt = await buildJsonToolSystemPrompt(
1054
+ const systemPrompt = buildJsonToolSystemPrompt(
1094
1055
  systemMessage,
1095
1056
  functionTools,
1096
1057
  {
1097
1058
  allowParallelToolCalls: false
1098
1059
  }
1099
1060
  );
1100
- const promptMessages = prependSystemPromptToMessages(
1101
- messages,
1102
- systemPrompt
1061
+ const session = await this.getSession(
1062
+ void 0,
1063
+ expectedInputs,
1064
+ systemPrompt || void 0
1103
1065
  );
1104
- const rawResponse = await session.prompt(promptMessages, promptOptions);
1066
+ const rawResponse = await session.prompt(messages, promptOptions);
1105
1067
  const { toolCalls, textContent } = parseJsonFunctionCalls(rawResponse);
1106
1068
  if (toolCalls.length > 0) {
1107
1069
  const toolCallsToEmit = toolCalls.slice(0, 1);
@@ -1136,7 +1098,7 @@ var BrowserAIChatLanguageModel = class {
1136
1098
  reasoning: void 0
1137
1099
  }
1138
1100
  },
1139
- request: { body: { messages: promptMessages, options: promptOptions } },
1101
+ request: { body: { messages, options: promptOptions } },
1140
1102
  warnings
1141
1103
  };
1142
1104
  }
@@ -1162,7 +1124,7 @@ var BrowserAIChatLanguageModel = class {
1162
1124
  reasoning: void 0
1163
1125
  }
1164
1126
  },
1165
- request: { body: { messages: promptMessages, options: promptOptions } },
1127
+ request: { body: { messages, options: promptOptions } },
1166
1128
  warnings
1167
1129
  };
1168
1130
  }
@@ -1209,23 +1171,23 @@ var BrowserAIChatLanguageModel = class {
1209
1171
  expectedInputs,
1210
1172
  functionTools
1211
1173
  } = converted;
1212
- const session = await this.getSession(void 0, expectedInputs, void 0);
1213
- const systemPrompt = await buildJsonToolSystemPrompt(
1174
+ const systemPrompt = buildJsonToolSystemPrompt(
1214
1175
  systemMessage,
1215
1176
  functionTools,
1216
1177
  {
1217
1178
  allowParallelToolCalls: false
1218
1179
  }
1219
1180
  );
1220
- const promptMessages = prependSystemPromptToMessages(
1221
- messages,
1222
- systemPrompt
1181
+ const session = await this.getSession(
1182
+ void 0,
1183
+ expectedInputs,
1184
+ systemPrompt || void 0
1223
1185
  );
1224
1186
  const streamOptions = {
1225
1187
  ...promptOptions,
1226
1188
  signal: options.abortSignal
1227
1189
  };
1228
- const conversationHistory = [...promptMessages];
1190
+ const conversationHistory = [...messages];
1229
1191
  const textId = "text-0";
1230
1192
  const stream = new ReadableStream({
1231
1193
  start: async (controller) => {
@@ -1531,7 +1493,7 @@ var BrowserAIChatLanguageModel = class {
1531
1493
  });
1532
1494
  return {
1533
1495
  stream,
1534
- request: { body: { messages: promptMessages, options: promptOptions } }
1496
+ request: { body: { messages, options: promptOptions } }
1535
1497
  };
1536
1498
  }
1537
1499
  };