@browser-ai/core 2.0.1 → 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.js CHANGED
@@ -482,44 +482,6 @@ function getExpectedInputs(prompt) {
482
482
  }
483
483
  return Array.from(inputs).map((type) => ({ type }));
484
484
  }
485
- function prependSystemPromptToMessages(messages, systemPrompt) {
486
- if (!systemPrompt.trim()) {
487
- return messages;
488
- }
489
- const prompts = messages.map((message) => ({ ...message }));
490
- const firstUserIndex = prompts.findIndex(
491
- (message) => message.role === "user"
492
- );
493
- if (firstUserIndex !== -1) {
494
- const firstUserMessage = prompts[firstUserIndex];
495
- if (Array.isArray(firstUserMessage.content)) {
496
- const content = firstUserMessage.content.slice();
497
- content.unshift({
498
- type: "text",
499
- value: `${systemPrompt}
500
-
501
- `
502
- });
503
- prompts[firstUserIndex] = {
504
- ...firstUserMessage,
505
- content
506
- };
507
- } else if (typeof firstUserMessage.content === "string") {
508
- prompts[firstUserIndex] = {
509
- ...firstUserMessage,
510
- content: `${systemPrompt}
511
-
512
- ${firstUserMessage.content}`
513
- };
514
- }
515
- } else {
516
- prompts.unshift({
517
- role: "user",
518
- content: systemPrompt
519
- });
520
- }
521
- return prompts;
522
- }
523
485
 
524
486
  // src/utils/tool-utils.ts
525
487
  function isFunctionTool(tool) {
@@ -1117,19 +1079,19 @@ var BrowserAIChatLanguageModel = class {
1117
1079
  expectedInputs,
1118
1080
  functionTools
1119
1081
  } = converted;
1120
- const session = await this.getSession(void 0, expectedInputs, void 0);
1121
- const systemPrompt = await buildJsonToolSystemPrompt(
1082
+ const systemPrompt = buildJsonToolSystemPrompt(
1122
1083
  systemMessage,
1123
1084
  functionTools,
1124
1085
  {
1125
1086
  allowParallelToolCalls: false
1126
1087
  }
1127
1088
  );
1128
- const promptMessages = prependSystemPromptToMessages(
1129
- messages,
1130
- systemPrompt
1089
+ const session = await this.getSession(
1090
+ void 0,
1091
+ expectedInputs,
1092
+ systemPrompt || void 0
1131
1093
  );
1132
- const rawResponse = await session.prompt(promptMessages, promptOptions);
1094
+ const rawResponse = await session.prompt(messages, promptOptions);
1133
1095
  const { toolCalls, textContent } = parseJsonFunctionCalls(rawResponse);
1134
1096
  if (toolCalls.length > 0) {
1135
1097
  const toolCallsToEmit = toolCalls.slice(0, 1);
@@ -1164,7 +1126,7 @@ var BrowserAIChatLanguageModel = class {
1164
1126
  reasoning: void 0
1165
1127
  }
1166
1128
  },
1167
- request: { body: { messages: promptMessages, options: promptOptions } },
1129
+ request: { body: { messages, options: promptOptions } },
1168
1130
  warnings
1169
1131
  };
1170
1132
  }
@@ -1190,7 +1152,7 @@ var BrowserAIChatLanguageModel = class {
1190
1152
  reasoning: void 0
1191
1153
  }
1192
1154
  },
1193
- request: { body: { messages: promptMessages, options: promptOptions } },
1155
+ request: { body: { messages, options: promptOptions } },
1194
1156
  warnings
1195
1157
  };
1196
1158
  }
@@ -1237,23 +1199,23 @@ var BrowserAIChatLanguageModel = class {
1237
1199
  expectedInputs,
1238
1200
  functionTools
1239
1201
  } = converted;
1240
- const session = await this.getSession(void 0, expectedInputs, void 0);
1241
- const systemPrompt = await buildJsonToolSystemPrompt(
1202
+ const systemPrompt = buildJsonToolSystemPrompt(
1242
1203
  systemMessage,
1243
1204
  functionTools,
1244
1205
  {
1245
1206
  allowParallelToolCalls: false
1246
1207
  }
1247
1208
  );
1248
- const promptMessages = prependSystemPromptToMessages(
1249
- messages,
1250
- systemPrompt
1209
+ const session = await this.getSession(
1210
+ void 0,
1211
+ expectedInputs,
1212
+ systemPrompt || void 0
1251
1213
  );
1252
1214
  const streamOptions = {
1253
1215
  ...promptOptions,
1254
1216
  signal: options.abortSignal
1255
1217
  };
1256
- const conversationHistory = [...promptMessages];
1218
+ const conversationHistory = [...messages];
1257
1219
  const textId = "text-0";
1258
1220
  const stream = new ReadableStream({
1259
1221
  start: async (controller) => {
@@ -1559,7 +1521,7 @@ var BrowserAIChatLanguageModel = class {
1559
1521
  });
1560
1522
  return {
1561
1523
  stream,
1562
- request: { body: { messages: promptMessages, options: promptOptions } }
1524
+ request: { body: { messages, options: promptOptions } }
1563
1525
  };
1564
1526
  }
1565
1527
  };