ai 3.1.16 → 3.1.18

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
@@ -1314,8 +1314,32 @@ var GenerateTextResult = class {
1314
1314
  this.warnings = options.warnings;
1315
1315
  this.rawResponse = options.rawResponse;
1316
1316
  this.logprobs = options.logprobs;
1317
+ this.responseMessages = toResponseMessages(options);
1317
1318
  }
1318
1319
  };
1320
+ function toResponseMessages({
1321
+ text,
1322
+ toolCalls,
1323
+ toolResults
1324
+ }) {
1325
+ const responseMessages = [];
1326
+ responseMessages.push({
1327
+ role: "assistant",
1328
+ content: [{ type: "text", text }, ...toolCalls]
1329
+ });
1330
+ if (toolResults.length > 0) {
1331
+ responseMessages.push({
1332
+ role: "tool",
1333
+ content: toolResults.map((result) => ({
1334
+ type: "tool-result",
1335
+ toolCallId: result.toolCallId,
1336
+ toolName: result.toolName,
1337
+ result: result.result
1338
+ }))
1339
+ });
1340
+ }
1341
+ return responseMessages;
1342
+ }
1319
1343
  var experimental_generateText = generateText;
1320
1344
 
1321
1345
  // core/generate-text/run-tools-transformation.ts
@@ -3229,6 +3253,7 @@ async function parseComplexResponse({
3229
3253
  reader,
3230
3254
  abortControllerRef,
3231
3255
  update,
3256
+ onToolCall,
3232
3257
  onFinish,
3233
3258
  generateId: generateId2 = generateId,
3234
3259
  getCurrentDate = () => /* @__PURE__ */ new Date()
@@ -3269,6 +3294,14 @@ async function parseComplexResponse({
3269
3294
  prefixMap.text.toolInvocations = [];
3270
3295
  }
3271
3296
  prefixMap.text.toolInvocations.push(value);
3297
+ if (onToolCall) {
3298
+ console.log("onToolCall", value);
3299
+ const result = await onToolCall({ toolCall: value });
3300
+ console.log("onToolCall result", result);
3301
+ if (result != null) {
3302
+ prefixMap.text.toolInvocations[prefixMap.text.toolInvocations.length - 1] = { ...value, result };
3303
+ }
3304
+ }
3272
3305
  } else if (type === "tool_result") {
3273
3306
  if (prefixMap.text == null) {
3274
3307
  prefixMap.text = {