@ai-sdk/google-vertex 1.0.3 → 2.0.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.
package/dist/index.js CHANGED
@@ -20,636 +20,56 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
- createVertex: () => createVertex,
23
+ createVertex: () => createVertex2,
24
24
  vertex: () => vertex
25
25
  });
26
26
  module.exports = __toCommonJS(src_exports);
27
27
 
28
- // src/google-vertex-provider.ts
29
- var import_provider_utils5 = require("@ai-sdk/provider-utils");
30
- var import_vertexai3 = require("@google-cloud/vertexai");
31
-
32
- // src/google-vertex-language-model.ts
33
- var import_provider3 = require("@ai-sdk/provider");
34
- var import_provider_utils2 = require("@ai-sdk/provider-utils");
35
- var import_vertexai2 = require("@google-cloud/vertexai");
36
-
37
- // src/convert-json-schema-to-openapi-schema.ts
38
- function convertJSONSchemaToOpenAPISchema(jsonSchema) {
39
- if (typeof jsonSchema === "boolean") {
40
- return { type: "boolean", properties: {} };
41
- }
42
- const {
43
- type,
44
- description,
45
- required,
46
- properties,
47
- items,
48
- allOf,
49
- anyOf,
50
- oneOf,
51
- format,
52
- const: constValue,
53
- minLength
54
- } = jsonSchema;
55
- const result = {};
56
- if (description)
57
- result.description = description;
58
- if (required)
59
- result.required = required;
60
- if (format)
61
- result.format = format;
62
- if (constValue !== void 0) {
63
- result.enum = [constValue];
64
- }
65
- if (type) {
66
- if (Array.isArray(type)) {
67
- if (type.includes("null")) {
68
- result.type = type.filter((t) => t !== "null")[0];
69
- result.nullable = true;
70
- } else {
71
- result.type = type;
72
- }
73
- } else if (type === "null") {
74
- result.type = "null";
75
- } else {
76
- result.type = type;
77
- }
78
- }
79
- if (properties) {
80
- result.properties = Object.entries(properties).reduce(
81
- (acc, [key, value]) => {
82
- acc[key] = convertJSONSchemaToOpenAPISchema(value);
83
- return acc;
84
- },
85
- {}
86
- );
87
- }
88
- if (items) {
89
- result.items = Array.isArray(items) ? items.map(convertJSONSchemaToOpenAPISchema) : convertJSONSchemaToOpenAPISchema(items);
90
- }
91
- if (allOf) {
92
- result.allOf = allOf.map(convertJSONSchemaToOpenAPISchema);
93
- }
94
- if (anyOf) {
95
- result.anyOf = anyOf.map(convertJSONSchemaToOpenAPISchema);
96
- }
97
- if (oneOf) {
98
- result.oneOf = oneOf.map(convertJSONSchemaToOpenAPISchema);
99
- }
100
- if (minLength !== void 0)
101
- result.minLength = minLength;
102
- return result;
103
- }
104
-
105
- // src/convert-to-google-vertex-content-request.ts
106
- var import_provider = require("@ai-sdk/provider");
107
- var import_provider_utils = require("@ai-sdk/provider-utils");
108
- function convertToGoogleVertexContentRequest(prompt) {
109
- var _a, _b;
110
- const systemInstructionParts = [];
111
- const contents = [];
112
- let systemMessagesAllowed = true;
113
- for (const { role, content } of prompt) {
114
- switch (role) {
115
- case "system": {
116
- if (!systemMessagesAllowed) {
117
- throw new import_provider.UnsupportedFunctionalityError({
118
- functionality: "system messages after first user message"
119
- });
120
- }
121
- systemInstructionParts.push({ text: content });
122
- break;
123
- }
124
- case "user": {
125
- systemMessagesAllowed = false;
126
- const parts = [];
127
- for (const part of content) {
128
- switch (part.type) {
129
- case "text": {
130
- parts.push({ text: part.text });
131
- break;
132
- }
133
- case "image": {
134
- parts.push(
135
- part.image instanceof URL ? {
136
- fileData: {
137
- mimeType: (_a = part.mimeType) != null ? _a : "image/jpeg",
138
- fileUri: part.image.toString()
139
- }
140
- } : {
141
- inlineData: {
142
- mimeType: (_b = part.mimeType) != null ? _b : "image/jpeg",
143
- data: (0, import_provider_utils.convertUint8ArrayToBase64)(part.image)
144
- }
145
- }
146
- );
147
- break;
148
- }
149
- case "file": {
150
- parts.push(
151
- part.data instanceof URL ? {
152
- fileData: {
153
- mimeType: part.mimeType,
154
- fileUri: part.data.toString()
155
- }
156
- } : {
157
- inlineData: {
158
- mimeType: part.mimeType,
159
- data: part.data
160
- }
161
- }
162
- );
163
- break;
164
- }
165
- default: {
166
- const _exhaustiveCheck = part;
167
- throw new import_provider.UnsupportedFunctionalityError({
168
- functionality: `prompt part: ${_exhaustiveCheck}`
169
- });
170
- }
171
- }
172
- }
173
- contents.push({ role: "user", parts });
174
- break;
175
- }
176
- case "assistant": {
177
- systemMessagesAllowed = false;
178
- contents.push({
179
- role: "assistant",
180
- parts: content.filter((part) => part.type !== "text" || part.text.length > 0).map((part) => {
181
- switch (part.type) {
182
- case "text": {
183
- return { text: part.text };
184
- }
185
- case "tool-call": {
186
- return {
187
- functionCall: {
188
- name: part.toolName,
189
- args: part.args
190
- }
191
- };
192
- }
193
- default: {
194
- const _exhaustiveCheck = part;
195
- throw new import_provider.UnsupportedFunctionalityError({
196
- functionality: `prompt part: ${_exhaustiveCheck}`
197
- });
198
- }
199
- }
200
- })
201
- });
202
- break;
203
- }
204
- case "tool": {
205
- systemMessagesAllowed = false;
206
- contents.push({
207
- role: "user",
208
- parts: content.map((part) => ({
209
- functionResponse: {
210
- name: part.toolName,
211
- response: part.result
212
- }
213
- }))
214
- });
215
- break;
216
- }
217
- default: {
218
- const _exhaustiveCheck = role;
219
- throw new import_provider.UnsupportedFunctionalityError({
220
- functionality: `role: ${_exhaustiveCheck}`
221
- });
222
- }
223
- }
224
- }
225
- return {
226
- systemInstruction: systemInstructionParts.length > 0 ? { role: "system", parts: systemInstructionParts } : void 0,
227
- contents
228
- };
229
- }
230
-
231
- // src/google-vertex-prepare-tools.ts
232
- var import_provider2 = require("@ai-sdk/provider");
233
- var import_vertexai = require("@google-cloud/vertexai");
234
- function prepareTools({
235
- useSearchGrounding,
236
- mode
237
- }) {
238
- var _a, _b;
239
- const tools = ((_a = mode.tools) == null ? void 0 : _a.length) ? mode.tools : void 0;
240
- const toolWarnings = [];
241
- const vertexTools = [];
242
- if (tools != null) {
243
- const functionDeclarations = [];
244
- for (const tool of tools) {
245
- if (tool.type === "provider-defined") {
246
- toolWarnings.push({ type: "unsupported-tool", tool });
247
- } else {
248
- functionDeclarations.push({
249
- name: tool.name,
250
- description: (_b = tool.description) != null ? _b : "",
251
- parameters: convertJSONSchemaToOpenAPISchema(
252
- tool.parameters
253
- )
254
- });
255
- }
256
- }
257
- vertexTools.push({ functionDeclarations });
258
- }
259
- if (useSearchGrounding) {
260
- vertexTools.push({ googleSearchRetrieval: {} });
261
- }
262
- const finalTools = vertexTools.length > 0 ? vertexTools : void 0;
263
- const toolChoice = mode.toolChoice;
264
- if (toolChoice == null) {
265
- return {
266
- tools: finalTools,
267
- toolConfig: void 0,
268
- toolWarnings
269
- };
270
- }
271
- const type = toolChoice.type;
272
- switch (type) {
273
- case "auto":
274
- return {
275
- tools: finalTools,
276
- toolConfig: {
277
- functionCallingConfig: { mode: import_vertexai.FunctionCallingMode.AUTO }
278
- },
279
- toolWarnings
280
- };
281
- case "none":
282
- return {
283
- tools: finalTools,
284
- toolConfig: {
285
- functionCallingConfig: { mode: import_vertexai.FunctionCallingMode.NONE }
286
- },
287
- toolWarnings
288
- };
289
- case "required":
290
- return {
291
- tools: finalTools,
292
- toolConfig: {
293
- functionCallingConfig: { mode: import_vertexai.FunctionCallingMode.ANY }
294
- },
295
- toolWarnings
296
- };
297
- case "tool":
298
- return {
299
- tools: finalTools,
300
- toolConfig: {
301
- functionCallingConfig: {
302
- mode: import_vertexai.FunctionCallingMode.ANY,
303
- allowedFunctionNames: [toolChoice.toolName]
304
- }
305
- },
306
- toolWarnings
307
- };
308
- default: {
309
- const _exhaustiveCheck = type;
310
- throw new import_provider2.UnsupportedFunctionalityError({
311
- functionality: `Unsupported tool choice type: ${_exhaustiveCheck}`
312
- });
313
- }
314
- }
315
- }
316
-
317
- // src/map-google-vertex-finish-reason.ts
318
- function mapGoogleVertexFinishReason({
319
- finishReason,
320
- hasToolCalls
321
- }) {
322
- switch (finishReason) {
323
- case "STOP":
324
- return hasToolCalls ? "tool-calls" : "stop";
325
- case "MAX_TOKENS":
326
- return "length";
327
- case "BLOCKLIST":
328
- case "PROHIBITED_CONTENT":
329
- case "SPII":
330
- case "RECITATION":
331
- case "SAFETY":
332
- return "content-filter";
333
- case "FINISH_REASON_UNSPECIFIED":
334
- case "OTHER":
335
- return "other";
336
- default:
337
- return "unknown";
338
- }
339
- }
340
-
341
- // src/google-vertex-language-model.ts
342
- var GoogleVertexLanguageModel = class {
343
- constructor(modelId, settings, config) {
344
- this.specificationVersion = "v1";
345
- this.provider = "google-vertex";
346
- this.defaultObjectGenerationMode = "json";
347
- this.supportsImageUrls = false;
348
- this.modelId = modelId;
349
- this.settings = settings;
350
- this.config = config;
351
- }
352
- get supportsObjectGeneration() {
353
- return this.settings.structuredOutputs !== false;
354
- }
355
- async getArgs({
356
- mode,
357
- prompt,
358
- maxTokens,
359
- temperature,
360
- topP,
361
- topK,
362
- frequencyPenalty,
363
- presencePenalty,
364
- stopSequences,
365
- responseFormat,
366
- seed,
367
- headers
368
- }) {
369
- var _a, _b;
370
- const warnings = [];
371
- if (presencePenalty != null) {
372
- warnings.push({
373
- type: "unsupported-setting",
374
- setting: "presencePenalty"
375
- });
376
- }
377
- if (seed != null) {
378
- warnings.push({
379
- type: "unsupported-setting",
380
- setting: "seed"
381
- });
382
- }
383
- if (headers != null) {
384
- warnings.push({
385
- type: "unsupported-setting",
386
- setting: "headers"
387
- });
388
- }
389
- const generationConfig = {
390
- // standardized settings:
391
- maxOutputTokens: maxTokens,
392
- frequencyPenalty,
393
- temperature,
394
- topK,
395
- topP,
396
- stopSequences,
397
- // response format:
398
- responseMimeType: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? "application/json" : void 0,
399
- responseSchema: (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && // Google Vertex does not support all OpenAPI Schema features,
400
- // so this is needed as an escape hatch:
401
- this.supportsObjectGeneration ? convertJSONSchemaToOpenAPISchema(
402
- responseFormat.schema
403
- ) : void 0
404
- };
405
- const type = mode.type;
406
- switch (type) {
407
- case "regular": {
408
- const { tools, toolConfig, toolWarnings } = prepareTools({
409
- mode,
410
- useSearchGrounding: (_a = this.settings.useSearchGrounding) != null ? _a : false
411
- });
412
- const configuration = {
413
- model: this.modelId,
414
- generationConfig,
415
- tools,
416
- toolConfig,
417
- safetySettings: this.settings.safetySettings
418
- };
419
- return {
420
- model: this.config.vertexAI.getGenerativeModel(configuration),
421
- contentRequest: convertToGoogleVertexContentRequest(prompt),
422
- warnings: [...warnings, ...toolWarnings]
423
- };
424
- }
425
- case "object-json": {
426
- return {
427
- model: this.config.vertexAI.getGenerativeModel({
428
- model: this.modelId,
429
- generationConfig: {
430
- ...generationConfig,
431
- responseMimeType: "application/json",
432
- responseSchema: mode.schema != null && // Google Vertex does not support all OpenAPI Schema features,
433
- // so this is needed as an escape hatch:
434
- this.supportsObjectGeneration ? convertJSONSchemaToOpenAPISchema(
435
- mode.schema
436
- ) : void 0
437
- },
438
- safetySettings: this.settings.safetySettings
439
- }),
440
- contentRequest: convertToGoogleVertexContentRequest(prompt),
441
- warnings
442
- };
443
- }
444
- case "object-tool": {
445
- const configuration = {
446
- model: this.modelId,
447
- generationConfig,
448
- tools: [
449
- {
450
- functionDeclarations: [
451
- {
452
- name: mode.tool.name,
453
- description: (_b = mode.tool.description) != null ? _b : "",
454
- parameters: convertJSONSchemaToOpenAPISchema(
455
- mode.tool.parameters
456
- )
457
- }
458
- ]
459
- }
460
- ],
461
- toolConfig: {
462
- functionCallingConfig: { mode: import_vertexai2.FunctionCallingMode.ANY }
463
- },
464
- safetySettings: this.settings.safetySettings
465
- };
466
- return {
467
- model: this.config.vertexAI.getGenerativeModel(configuration),
468
- contentRequest: convertToGoogleVertexContentRequest(prompt),
469
- warnings
470
- };
471
- }
472
- default: {
473
- const _exhaustiveCheck = type;
474
- throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
475
- }
476
- }
477
- }
478
- supportsUrl(url) {
479
- return url.protocol === "gs:";
480
- }
481
- async doGenerate(options) {
482
- var _a, _b, _c;
483
- const { model, contentRequest, warnings } = await this.getArgs(options);
484
- const { response } = await model.generateContent(contentRequest);
485
- const firstCandidate = (_a = response.candidates) == null ? void 0 : _a[0];
486
- if (firstCandidate == null) {
487
- throw new import_provider3.NoContentGeneratedError({ message: "No candidates returned" });
488
- }
489
- const parts = firstCandidate.content.parts;
490
- const usageMetadata = response.usageMetadata;
491
- const toolCalls = getToolCallsFromParts({
492
- parts,
493
- generateId: this.config.generateId
28
+ // src/google-vertex-auth-google-auth-library.ts
29
+ var import_google_auth_library = require("google-auth-library");
30
+ var authInstance = null;
31
+ var authOptions = null;
32
+ function getAuth(options) {
33
+ if (!authInstance || options !== authOptions) {
34
+ authInstance = new import_google_auth_library.GoogleAuth({
35
+ scopes: ["https://www.googleapis.com/auth/cloud-platform"],
36
+ ...options
494
37
  });
495
- return {
496
- text: getTextFromParts(parts),
497
- toolCalls,
498
- finishReason: mapGoogleVertexFinishReason({
499
- finishReason: firstCandidate.finishReason,
500
- hasToolCalls: toolCalls != null && toolCalls.length > 0
501
- }),
502
- usage: {
503
- promptTokens: (_b = usageMetadata == null ? void 0 : usageMetadata.promptTokenCount) != null ? _b : NaN,
504
- completionTokens: (_c = usageMetadata == null ? void 0 : usageMetadata.candidatesTokenCount) != null ? _c : NaN
505
- },
506
- rawCall: {
507
- rawPrompt: contentRequest,
508
- rawSettings: {}
509
- },
510
- providerMetadata: this.settings.useSearchGrounding ? {
511
- vertex: {
512
- groundingMetadata: firstCandidate.groundingMetadata
513
- }
514
- } : void 0,
515
- warnings
516
- };
517
- }
518
- async doStream(options) {
519
- const { model, contentRequest, warnings } = await this.getArgs(options);
520
- const { stream } = await model.generateContentStream(contentRequest);
521
- let finishReason = "unknown";
522
- let usage = {
523
- promptTokens: Number.NaN,
524
- completionTokens: Number.NaN
525
- };
526
- const generateId2 = this.config.generateId;
527
- let hasToolCalls = false;
528
- let providerMetadata;
529
- return {
530
- stream: (0, import_provider_utils2.convertAsyncIteratorToReadableStream)(stream).pipeThrough(
531
- new TransformStream(
532
- {
533
- transform(chunk, controller) {
534
- var _a, _b, _c;
535
- const usageMetadata = chunk.usageMetadata;
536
- if (usageMetadata != null) {
537
- usage = {
538
- promptTokens: (_a = usageMetadata.promptTokenCount) != null ? _a : NaN,
539
- completionTokens: (_b = usageMetadata.candidatesTokenCount) != null ? _b : NaN
540
- };
541
- }
542
- const candidate = (_c = chunk.candidates) == null ? void 0 : _c[0];
543
- if (candidate == null) {
544
- return;
545
- }
546
- if (candidate.finishReason != null) {
547
- finishReason = mapGoogleVertexFinishReason({
548
- finishReason: candidate.finishReason,
549
- hasToolCalls
550
- });
551
- }
552
- if (candidate.groundingMetadata != null) {
553
- providerMetadata = {
554
- vertex: {
555
- groundingMetadata: candidate.groundingMetadata
556
- }
557
- };
558
- }
559
- const content = candidate.content;
560
- const deltaText = getTextFromParts(content.parts);
561
- if (deltaText != null) {
562
- controller.enqueue({
563
- type: "text-delta",
564
- textDelta: deltaText
565
- });
566
- }
567
- const toolCallDeltas = getToolCallsFromParts({
568
- parts: content.parts,
569
- generateId: generateId2
570
- });
571
- if (toolCallDeltas != null) {
572
- for (const toolCall of toolCallDeltas) {
573
- controller.enqueue({
574
- type: "tool-call-delta",
575
- toolCallType: "function",
576
- toolCallId: toolCall.toolCallId,
577
- toolName: toolCall.toolName,
578
- argsTextDelta: toolCall.args
579
- });
580
- controller.enqueue({
581
- type: "tool-call",
582
- toolCallType: "function",
583
- toolCallId: toolCall.toolCallId,
584
- toolName: toolCall.toolName,
585
- args: toolCall.args
586
- });
587
- hasToolCalls = true;
588
- }
589
- }
590
- },
591
- flush(controller) {
592
- controller.enqueue({
593
- type: "finish",
594
- finishReason,
595
- usage,
596
- providerMetadata
597
- });
598
- }
599
- }
600
- )
601
- ),
602
- rawCall: {
603
- rawPrompt: contentRequest,
604
- rawSettings: {}
605
- },
606
- warnings
607
- };
608
- }
609
- };
610
- function getToolCallsFromParts({
611
- parts,
612
- generateId: generateId2
613
- }) {
614
- if (parts == null) {
615
- return void 0;
38
+ authOptions = options;
616
39
  }
617
- return parts.flatMap(
618
- (part) => part.functionCall == null ? [] : {
619
- toolCallType: "function",
620
- toolCallId: generateId2(),
621
- toolName: part.functionCall.name,
622
- args: JSON.stringify(part.functionCall.args)
623
- }
624
- );
40
+ return authInstance;
625
41
  }
626
- function getTextFromParts(parts) {
627
- if (parts == null) {
628
- return void 0;
629
- }
630
- const textParts = parts.filter((part) => "text" in part);
631
- return textParts.length === 0 ? void 0 : textParts.map((part) => part.text).join("");
42
+ async function generateAuthToken(options) {
43
+ const auth = getAuth(options || {});
44
+ const client = await auth.getClient();
45
+ const token = await client.getAccessToken();
46
+ return (token == null ? void 0 : token.token) || null;
632
47
  }
633
48
 
49
+ // src/google-vertex-provider.ts
50
+ var import_provider_utils3 = require("@ai-sdk/provider-utils");
51
+
634
52
  // src/google-vertex-embedding-model.ts
635
- var import_provider4 = require("@ai-sdk/provider");
636
- var import_provider_utils4 = require("@ai-sdk/provider-utils");
53
+ var import_provider = require("@ai-sdk/provider");
54
+ var import_provider_utils2 = require("@ai-sdk/provider-utils");
637
55
  var import_zod2 = require("zod");
638
56
 
639
- // src/google-error.ts
640
- var import_provider_utils3 = require("@ai-sdk/provider-utils");
57
+ // src/google-vertex-error.ts
58
+ var import_provider_utils = require("@ai-sdk/provider-utils");
641
59
  var import_zod = require("zod");
642
- var googleErrorDataSchema = import_zod.z.object({
60
+ var googleVertexErrorDataSchema = import_zod.z.object({
643
61
  error: import_zod.z.object({
644
62
  code: import_zod.z.number().nullable(),
645
63
  message: import_zod.z.string(),
646
64
  status: import_zod.z.string()
647
65
  })
648
66
  });
649
- var googleFailedResponseHandler = (0, import_provider_utils3.createJsonErrorResponseHandler)({
650
- errorSchema: googleErrorDataSchema,
651
- errorToMessage: (data) => data.error.message
652
- });
67
+ var googleVertexFailedResponseHandler = (0, import_provider_utils.createJsonErrorResponseHandler)(
68
+ {
69
+ errorSchema: googleVertexErrorDataSchema,
70
+ errorToMessage: (data) => data.error.message
71
+ }
72
+ );
653
73
 
654
74
  // src/google-vertex-embedding-model.ts
655
75
  var GoogleVertexEmbeddingModel = class {
@@ -674,27 +94,28 @@ var GoogleVertexEmbeddingModel = class {
674
94
  abortSignal
675
95
  }) {
676
96
  if (values.length > this.maxEmbeddingsPerCall) {
677
- throw new import_provider4.TooManyEmbeddingValuesForCallError({
97
+ throw new import_provider.TooManyEmbeddingValuesForCallError({
678
98
  provider: this.provider,
679
99
  modelId: this.modelId,
680
100
  maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
681
101
  values
682
102
  });
683
103
  }
684
- const { responseHeaders, value: response } = await (0, import_provider_utils4.postJsonToApi)({
104
+ const mergedHeaders = (0, import_provider_utils2.combineHeaders)(
105
+ await (0, import_provider_utils2.resolve)(this.config.headers),
106
+ headers
107
+ );
108
+ const { responseHeaders, value: response } = await (0, import_provider_utils2.postJsonToApi)({
685
109
  url: `https://${this.config.region}-aiplatform.googleapis.com/v1/projects/${this.config.project}/locations/${this.config.region}/publishers/google/models/${this.modelId}:predict`,
686
- headers: (0, import_provider_utils4.combineHeaders)(
687
- { Authorization: `Bearer ${await this.config.generateAuthToken()}` },
688
- headers
689
- ),
110
+ headers: mergedHeaders,
690
111
  body: {
691
112
  instances: values.map((value) => ({ content: value })),
692
113
  parameters: {
693
114
  outputDimensionality: this.settings.outputDimensionality
694
115
  }
695
116
  },
696
- failedResponseHandler: googleFailedResponseHandler,
697
- successfulResponseHandler: (0, import_provider_utils4.createJsonResponseHandler)(
117
+ failedResponseHandler: googleVertexFailedResponseHandler,
118
+ successfulResponseHandler: (0, import_provider_utils2.createJsonResponseHandler)(
698
119
  googleVertexTextEmbeddingResponseSchema
699
120
  ),
700
121
  abortSignal
@@ -727,42 +148,39 @@ var googleVertexTextEmbeddingResponseSchema = import_zod2.z.object({
727
148
  });
728
149
 
729
150
  // src/google-vertex-provider.ts
151
+ var import_internal = require("@ai-sdk/google/internal");
730
152
  function createVertex(options = {}) {
731
- const loadVertexProject = () => (0, import_provider_utils5.loadSetting)({
153
+ const loadVertexProject = () => (0, import_provider_utils3.loadSetting)({
732
154
  settingValue: options.project,
733
155
  settingName: "project",
734
156
  environmentVariableName: "GOOGLE_VERTEX_PROJECT",
735
157
  description: "Google Vertex project"
736
158
  });
737
- const loadVertexLocation = () => (0, import_provider_utils5.loadSetting)({
159
+ const loadVertexLocation = () => (0, import_provider_utils3.loadSetting)({
738
160
  settingValue: options.location,
739
161
  settingName: "location",
740
162
  environmentVariableName: "GOOGLE_VERTEX_LOCATION",
741
163
  description: "Google Vertex location"
742
164
  });
743
- const createVertexAI = () => {
744
- var _a, _b;
745
- const config = {
746
- project: loadVertexProject(),
747
- location: loadVertexLocation(),
748
- googleAuthOptions: options.googleAuthOptions
749
- };
750
- return (_b = (_a = options.createVertexAI) == null ? void 0 : _a.call(options, config)) != null ? _b : new import_vertexai3.VertexAI(config);
751
- };
752
165
  const createChatModel = (modelId, settings = {}) => {
753
- var _a;
754
- return new GoogleVertexLanguageModel(modelId, settings, {
755
- vertexAI: createVertexAI(),
756
- generateId: (_a = options.generateId) != null ? _a : import_provider_utils5.generateId
166
+ var _a, _b;
167
+ const region = loadVertexLocation();
168
+ const project = loadVertexProject();
169
+ return new import_internal.GoogleGenerativeAILanguageModel(modelId, settings, {
170
+ provider: `google.vertex.chat`,
171
+ baseURL: `https://${region}-aiplatform.googleapis.com/v1/projects/${project}/locations/${region}/publishers/google`,
172
+ headers: (_a = options.headers) != null ? _a : {},
173
+ generateId: (_b = options.generateId) != null ? _b : import_provider_utils3.generateId,
174
+ fetch: options.fetch
757
175
  });
758
176
  };
759
177
  const createEmbeddingModel = (modelId, settings = {}) => {
760
- const vertexAI = createVertexAI();
178
+ var _a;
761
179
  return new GoogleVertexEmbeddingModel(modelId, settings, {
762
- provider: "google.vertex",
180
+ provider: `google.vertex.embedding`,
763
181
  region: loadVertexLocation(),
764
182
  project: loadVertexProject(),
765
- generateAuthToken: () => vertexAI.googleAuth.getAccessToken()
183
+ headers: (_a = options.headers) != null ? _a : {}
766
184
  });
767
185
  };
768
186
  const provider = function(modelId, settings) {
@@ -777,7 +195,20 @@ function createVertex(options = {}) {
777
195
  provider.textEmbeddingModel = createEmbeddingModel;
778
196
  return provider;
779
197
  }
780
- var vertex = createVertex();
198
+
199
+ // src/google-vertex-provider-node.ts
200
+ function createVertex2(options = {}) {
201
+ var _a;
202
+ return createVertex({
203
+ ...options,
204
+ headers: (_a = options.headers) != null ? _a : async () => ({
205
+ Authorization: `Bearer ${await generateAuthToken(
206
+ options.googleAuthOptions
207
+ )}`
208
+ })
209
+ });
210
+ }
211
+ var vertex = createVertex2();
781
212
  // Annotate the CommonJS export names for ESM import in node:
782
213
  0 && (module.exports = {
783
214
  createVertex,