ai 3.0.19 → 3.0.20

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.
Files changed (61) hide show
  1. package/anthropic/dist/index.d.mts +44 -10
  2. package/anthropic/dist/index.d.ts +44 -10
  3. package/anthropic/dist/index.js +17 -31
  4. package/anthropic/dist/index.js.map +1 -1
  5. package/anthropic/dist/index.mjs +17 -31
  6. package/anthropic/dist/index.mjs.map +1 -1
  7. package/dist/index.d.mts +97 -24
  8. package/dist/index.d.ts +97 -24
  9. package/dist/index.js +55 -118
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.mjs +53 -117
  12. package/dist/index.mjs.map +1 -1
  13. package/google/dist/index.d.mts +44 -10
  14. package/google/dist/index.d.ts +44 -10
  15. package/google/dist/index.js +47 -43
  16. package/google/dist/index.js.map +1 -1
  17. package/google/dist/index.mjs +47 -43
  18. package/google/dist/index.mjs.map +1 -1
  19. package/mistral/dist/index.d.mts +44 -10
  20. package/mistral/dist/index.d.ts +44 -10
  21. package/mistral/dist/index.js +6 -21
  22. package/mistral/dist/index.js.map +1 -1
  23. package/mistral/dist/index.mjs +6 -21
  24. package/mistral/dist/index.mjs.map +1 -1
  25. package/openai/dist/index.d.mts +44 -10
  26. package/openai/dist/index.d.ts +44 -10
  27. package/openai/dist/index.js +9 -29
  28. package/openai/dist/index.js.map +1 -1
  29. package/openai/dist/index.mjs +9 -29
  30. package/openai/dist/index.mjs.map +1 -1
  31. package/package.json +1 -1
  32. package/react/dist/index.d.mts +8 -4
  33. package/react/dist/index.d.ts +12 -6
  34. package/react/dist/index.js +23 -105
  35. package/react/dist/index.js.map +1 -1
  36. package/react/dist/index.mjs +22 -105
  37. package/react/dist/index.mjs.map +1 -1
  38. package/react/dist/index.server.d.mts +4 -2
  39. package/react/dist/index.server.d.ts +4 -2
  40. package/react/dist/index.server.js.map +1 -1
  41. package/react/dist/index.server.mjs.map +1 -1
  42. package/rsc/dist/rsc-server.mjs +6 -16
  43. package/rsc/dist/rsc-server.mjs.map +1 -1
  44. package/solid/dist/index.js +19 -104
  45. package/solid/dist/index.js.map +1 -1
  46. package/solid/dist/index.mjs +19 -104
  47. package/solid/dist/index.mjs.map +1 -1
  48. package/spec/dist/index.d.mts +48 -20
  49. package/spec/dist/index.d.ts +48 -20
  50. package/spec/dist/index.js +4 -14
  51. package/spec/dist/index.js.map +1 -1
  52. package/spec/dist/index.mjs +4 -14
  53. package/spec/dist/index.mjs.map +1 -1
  54. package/svelte/dist/index.js +19 -104
  55. package/svelte/dist/index.js.map +1 -1
  56. package/svelte/dist/index.mjs +19 -104
  57. package/svelte/dist/index.mjs.map +1 -1
  58. package/vue/dist/index.js +19 -104
  59. package/vue/dist/index.js.map +1 -1
  60. package/vue/dist/index.mjs +19 -104
  61. package/vue/dist/index.mjs.map +1 -1
@@ -75,13 +75,13 @@ type LanguageModelV1CallSettings = {
75
75
  };
76
76
 
77
77
  /**
78
- * A prompt is a list of messages.
79
- *
80
- * Note: Not all models and prompt formats support multi-modal inputs and
81
- * tool calls. The validation happens at runtime.
82
- *
83
- * Note: This is not a user-facing prompt. The AI SDK methods will map the
84
- * user-facing prompt types such as chat or instruction prompts to this format.
78
+ A prompt is a list of messages.
79
+
80
+ Note: Not all models and prompt formats support multi-modal inputs and
81
+ tool calls. The validation happens at runtime.
82
+
83
+ Note: This is not a user-facing prompt. The AI SDK methods will map the
84
+ user-facing prompt types such as chat or instruction prompts to this format.
85
85
  */
86
86
  type LanguageModelV1Prompt = Array<LanguageModelV1Message>;
87
87
  type LanguageModelV1Message = {
@@ -97,35 +97,69 @@ type LanguageModelV1Message = {
97
97
  role: 'tool';
98
98
  content: Array<LanguageModelV1ToolResultPart>;
99
99
  };
100
+ /**
101
+ Text content part of a prompt. It contains a string of text.
102
+ */
100
103
  interface LanguageModelV1TextPart {
101
104
  type: 'text';
102
105
  /**
103
- * The text content.
106
+ The text content.
104
107
  */
105
108
  text: string;
106
109
  }
110
+ /**
111
+ Image content part of a prompt. It contains an image.
112
+ */
107
113
  interface LanguageModelV1ImagePart {
108
114
  type: 'image';
109
115
  /**
110
- * Image data as a Uint8Array (e.g. from a Blob or Buffer) or a URL.
116
+ Image data as a Uint8Array (e.g. from a Blob or Buffer) or a URL.
111
117
  */
112
118
  image: Uint8Array | URL;
113
119
  /**
114
- * Optional mime type of the image.
120
+ Optional mime type of the image.
115
121
  */
116
122
  mimeType?: string;
117
123
  }
124
+ /**
125
+ Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
126
+ */
118
127
  interface LanguageModelV1ToolCallPart {
119
128
  type: 'tool-call';
129
+ /**
130
+ ID of the tool call. This ID is used to match the tool call with the tool result.
131
+ */
120
132
  toolCallId: string;
133
+ /**
134
+ Name of the tool that is being called.
135
+ */
121
136
  toolName: string;
137
+ /**
138
+ Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
139
+ */
122
140
  args: unknown;
123
141
  }
142
+ /**
143
+ Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
144
+ */
124
145
  interface LanguageModelV1ToolResultPart {
125
146
  type: 'tool-result';
147
+ /**
148
+ ID of the tool call that this result is associated with.
149
+ */
126
150
  toolCallId: string;
151
+ /**
152
+ Name of the tool that generated this result.
153
+ */
127
154
  toolName: string;
155
+ /**
156
+ Result of the tool call. This is a JSON-serializable object.
157
+ */
128
158
  result: unknown;
159
+ /**
160
+ Optional flag if the result is an error or an error message.
161
+ */
162
+ isError?: boolean;
129
163
  }
130
164
 
131
165
  type LanguageModelV1CallOptions = LanguageModelV1CallSettings & {
@@ -75,13 +75,13 @@ type LanguageModelV1CallSettings = {
75
75
  };
76
76
 
77
77
  /**
78
- * A prompt is a list of messages.
79
- *
80
- * Note: Not all models and prompt formats support multi-modal inputs and
81
- * tool calls. The validation happens at runtime.
82
- *
83
- * Note: This is not a user-facing prompt. The AI SDK methods will map the
84
- * user-facing prompt types such as chat or instruction prompts to this format.
78
+ A prompt is a list of messages.
79
+
80
+ Note: Not all models and prompt formats support multi-modal inputs and
81
+ tool calls. The validation happens at runtime.
82
+
83
+ Note: This is not a user-facing prompt. The AI SDK methods will map the
84
+ user-facing prompt types such as chat or instruction prompts to this format.
85
85
  */
86
86
  type LanguageModelV1Prompt = Array<LanguageModelV1Message>;
87
87
  type LanguageModelV1Message = {
@@ -97,35 +97,69 @@ type LanguageModelV1Message = {
97
97
  role: 'tool';
98
98
  content: Array<LanguageModelV1ToolResultPart>;
99
99
  };
100
+ /**
101
+ Text content part of a prompt. It contains a string of text.
102
+ */
100
103
  interface LanguageModelV1TextPart {
101
104
  type: 'text';
102
105
  /**
103
- * The text content.
106
+ The text content.
104
107
  */
105
108
  text: string;
106
109
  }
110
+ /**
111
+ Image content part of a prompt. It contains an image.
112
+ */
107
113
  interface LanguageModelV1ImagePart {
108
114
  type: 'image';
109
115
  /**
110
- * Image data as a Uint8Array (e.g. from a Blob or Buffer) or a URL.
116
+ Image data as a Uint8Array (e.g. from a Blob or Buffer) or a URL.
111
117
  */
112
118
  image: Uint8Array | URL;
113
119
  /**
114
- * Optional mime type of the image.
120
+ Optional mime type of the image.
115
121
  */
116
122
  mimeType?: string;
117
123
  }
124
+ /**
125
+ Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
126
+ */
118
127
  interface LanguageModelV1ToolCallPart {
119
128
  type: 'tool-call';
129
+ /**
130
+ ID of the tool call. This ID is used to match the tool call with the tool result.
131
+ */
120
132
  toolCallId: string;
133
+ /**
134
+ Name of the tool that is being called.
135
+ */
121
136
  toolName: string;
137
+ /**
138
+ Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
139
+ */
122
140
  args: unknown;
123
141
  }
142
+ /**
143
+ Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
144
+ */
124
145
  interface LanguageModelV1ToolResultPart {
125
146
  type: 'tool-result';
147
+ /**
148
+ ID of the tool call that this result is associated with.
149
+ */
126
150
  toolCallId: string;
151
+ /**
152
+ Name of the tool that generated this result.
153
+ */
127
154
  toolName: string;
155
+ /**
156
+ Result of the tool call. This is a JSON-serializable object.
157
+ */
128
158
  result: unknown;
159
+ /**
160
+ Optional flag if the result is an error or an error message.
161
+ */
162
+ isError?: boolean;
129
163
  }
130
164
 
131
165
  type LanguageModelV1CallOptions = LanguageModelV1CallSettings & {
@@ -499,26 +499,19 @@ function convertUint8ArrayToBase64(array) {
499
499
 
500
500
  // spec/errors/unsupported-functionality-error.ts
501
501
  var UnsupportedFunctionalityError = class extends Error {
502
- constructor({
503
- provider,
504
- functionality
505
- }) {
506
- super(
507
- `'${functionality}' functionality not supported by the '${provider}' provider.`
508
- );
502
+ constructor({ functionality }) {
503
+ super(`'${functionality}' functionality not supported.`);
509
504
  this.name = "AI_UnsupportedFunctionalityError";
510
- this.provider = provider;
511
505
  this.functionality = functionality;
512
506
  }
513
507
  static isUnsupportedFunctionalityError(error) {
514
- return error instanceof Error && error.name === "AI_UnsupportedFunctionalityError" && typeof error.provider === "string" && typeof error.functionality === "string";
508
+ return error instanceof Error && error.name === "AI_UnsupportedFunctionalityError" && typeof error.functionality === "string";
515
509
  }
516
510
  toJSON() {
517
511
  return {
518
512
  name: this.name,
519
513
  message: this.message,
520
514
  stack: this.stack,
521
- provider: this.provider,
522
515
  functionality: this.functionality
523
516
  };
524
517
  }
@@ -528,10 +521,7 @@ var UnsupportedFunctionalityError = class extends Error {
528
521
  var import_zod2 = require("zod");
529
522
 
530
523
  // google/convert-to-google-generative-ai-messages.ts
531
- function convertToGoogleGenerativeAIMessages({
532
- prompt,
533
- provider
534
- }) {
524
+ function convertToGoogleGenerativeAIMessages(prompt) {
535
525
  const messages = [];
536
526
  for (const { role, content } of prompt) {
537
527
  switch (role) {
@@ -552,7 +542,6 @@ function convertToGoogleGenerativeAIMessages({
552
542
  case "image": {
553
543
  if (part.image instanceof URL) {
554
544
  throw new UnsupportedFunctionalityError({
555
- provider,
556
545
  functionality: "URL image parts"
557
546
  });
558
547
  } else {
@@ -628,10 +617,13 @@ var googleFailedResponseHandler = createJsonErrorResponseHandler({
628
617
  });
629
618
 
630
619
  // google/map-google-generative-ai-finish-reason.ts
631
- function mapGoogleGenerativeAIFinishReason(finishReason) {
620
+ function mapGoogleGenerativeAIFinishReason({
621
+ finishReason,
622
+ hasToolCalls
623
+ }) {
632
624
  switch (finishReason) {
633
625
  case "STOP":
634
- return "stop";
626
+ return hasToolCalls ? "tool-calls" : "stop";
635
627
  case "MAX_TOKENS":
636
628
  return "length";
637
629
  case "RECITATION":
@@ -697,10 +689,7 @@ var GoogleGenerativeAILanguageModel = class {
697
689
  topP
698
690
  },
699
691
  // prompt:
700
- contents: convertToGoogleGenerativeAIMessages({
701
- provider: this.provider,
702
- prompt
703
- })
692
+ contents: convertToGoogleGenerativeAIMessages(prompt)
704
693
  };
705
694
  switch (type) {
706
695
  case "regular": {
@@ -722,20 +711,17 @@ var GoogleGenerativeAILanguageModel = class {
722
711
  }
723
712
  case "object-json": {
724
713
  throw new UnsupportedFunctionalityError({
725
- functionality: "object-json mode",
726
- provider: this.provider
714
+ functionality: "object-json mode"
727
715
  });
728
716
  }
729
717
  case "object-tool": {
730
718
  throw new UnsupportedFunctionalityError({
731
- functionality: "object-tool mode",
732
- provider: this.provider
719
+ functionality: "object-tool mode"
733
720
  });
734
721
  }
735
722
  case "object-grammar": {
736
723
  throw new UnsupportedFunctionalityError({
737
- functionality: "object-grammar mode",
738
- provider: this.provider
724
+ functionality: "object-grammar mode"
739
725
  });
740
726
  }
741
727
  default: {
@@ -757,13 +743,17 @@ var GoogleGenerativeAILanguageModel = class {
757
743
  });
758
744
  const { contents: rawPrompt, ...rawSettings } = args;
759
745
  const candidate = response.candidates[0];
746
+ const toolCalls = getToolCallsFromParts({
747
+ parts: candidate.content.parts,
748
+ generateId: this.config.generateId
749
+ });
760
750
  return {
761
751
  text: getTextFromParts(candidate.content.parts),
762
- toolCalls: getToolCallsFromParts({
763
- parts: candidate.content.parts,
764
- generateId: this.config.generateId
752
+ toolCalls,
753
+ finishReason: mapGoogleGenerativeAIFinishReason({
754
+ finishReason: candidate.finishReason,
755
+ hasToolCalls: toolCalls != null && toolCalls.length > 0
765
756
  }),
766
- finishReason: mapGoogleGenerativeAIFinishReason(candidate.finishReason),
767
757
  usage: {
768
758
  promptTokens: NaN,
769
759
  completionTokens: (_a = candidate.tokenCount) != null ? _a : NaN
@@ -789,6 +779,7 @@ var GoogleGenerativeAILanguageModel = class {
789
779
  completionTokens: Number.NaN
790
780
  };
791
781
  const generateId2 = this.config.generateId;
782
+ let hasToolCalls = false;
792
783
  return {
793
784
  stream: response.pipeThrough(
794
785
  new TransformStream({
@@ -800,9 +791,10 @@ var GoogleGenerativeAILanguageModel = class {
800
791
  const value = chunk.value;
801
792
  const candidate = value.candidates[0];
802
793
  if ((candidate == null ? void 0 : candidate.finishReason) != null) {
803
- finishReason = mapGoogleGenerativeAIFinishReason(
804
- candidate.finishReason
805
- );
794
+ finishReason = mapGoogleGenerativeAIFinishReason({
795
+ finishReason: candidate.finishReason,
796
+ hasToolCalls
797
+ });
806
798
  }
807
799
  if (candidate.tokenCount != null) {
808
800
  usage = {
@@ -810,7 +802,11 @@ var GoogleGenerativeAILanguageModel = class {
810
802
  completionTokens: candidate.tokenCount
811
803
  };
812
804
  }
813
- const deltaText = getTextFromParts(candidate.content.parts);
805
+ const content = candidate.content;
806
+ if (content == null) {
807
+ return;
808
+ }
809
+ const deltaText = getTextFromParts(content.parts);
814
810
  if (deltaText != null) {
815
811
  controller.enqueue({
816
812
  type: "text-delta",
@@ -818,7 +814,7 @@ var GoogleGenerativeAILanguageModel = class {
818
814
  });
819
815
  }
820
816
  const toolCallDeltas = getToolCallsFromParts({
821
- parts: candidate.content.parts,
817
+ parts: content.parts,
822
818
  generateId: generateId2
823
819
  });
824
820
  if (toolCallDeltas != null) {
@@ -837,6 +833,7 @@ var GoogleGenerativeAILanguageModel = class {
837
833
  toolName: toolCall.toolName,
838
834
  args: toolCall.args
839
835
  });
836
+ hasToolCalls = true;
840
837
  }
841
838
  }
842
839
  },
@@ -900,16 +897,23 @@ var contentSchema = import_zod2.z.object({
900
897
  ])
901
898
  )
902
899
  });
903
- var candidateSchema = import_zod2.z.object({
904
- content: contentSchema,
905
- finishReason: import_zod2.z.string().optional(),
906
- tokenCount: import_zod2.z.number().optional()
907
- });
908
900
  var responseSchema = import_zod2.z.object({
909
- candidates: import_zod2.z.array(candidateSchema)
901
+ candidates: import_zod2.z.array(
902
+ import_zod2.z.object({
903
+ content: contentSchema,
904
+ finishReason: import_zod2.z.string().optional(),
905
+ tokenCount: import_zod2.z.number().optional()
906
+ })
907
+ )
910
908
  });
911
909
  var chunkSchema = import_zod2.z.object({
912
- candidates: import_zod2.z.array(candidateSchema)
910
+ candidates: import_zod2.z.array(
911
+ import_zod2.z.object({
912
+ content: contentSchema.optional(),
913
+ finishReason: import_zod2.z.string().optional(),
914
+ tokenCount: import_zod2.z.number().optional()
915
+ })
916
+ )
913
917
  });
914
918
 
915
919
  // google/google-facade.ts