@ai-sdk/google-vertex 1.0.4 → 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,637 +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 supportsStructuredOutputs() {
353
- var _a;
354
- return (_a = this.settings.structuredOutputs) != null ? _a : true;
355
- }
356
- async getArgs({
357
- mode,
358
- prompt,
359
- maxTokens,
360
- temperature,
361
- topP,
362
- topK,
363
- frequencyPenalty,
364
- presencePenalty,
365
- stopSequences,
366
- responseFormat,
367
- seed,
368
- headers
369
- }) {
370
- var _a, _b;
371
- const warnings = [];
372
- if (presencePenalty != null) {
373
- warnings.push({
374
- type: "unsupported-setting",
375
- setting: "presencePenalty"
376
- });
377
- }
378
- if (seed != null) {
379
- warnings.push({
380
- type: "unsupported-setting",
381
- setting: "seed"
382
- });
383
- }
384
- if (headers != null) {
385
- warnings.push({
386
- type: "unsupported-setting",
387
- setting: "headers"
388
- });
389
- }
390
- const generationConfig = {
391
- // standardized settings:
392
- maxOutputTokens: maxTokens,
393
- frequencyPenalty,
394
- temperature,
395
- topK,
396
- topP,
397
- stopSequences,
398
- // response format:
399
- responseMimeType: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? "application/json" : void 0,
400
- responseSchema: (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && // Google Vertex does not support all OpenAPI Schema features,
401
- // so this is needed as an escape hatch:
402
- this.supportsStructuredOutputs ? convertJSONSchemaToOpenAPISchema(
403
- responseFormat.schema
404
- ) : void 0
405
- };
406
- const type = mode.type;
407
- switch (type) {
408
- case "regular": {
409
- const { tools, toolConfig, toolWarnings } = prepareTools({
410
- mode,
411
- useSearchGrounding: (_a = this.settings.useSearchGrounding) != null ? _a : false
412
- });
413
- const configuration = {
414
- model: this.modelId,
415
- generationConfig,
416
- tools,
417
- toolConfig,
418
- safetySettings: this.settings.safetySettings
419
- };
420
- return {
421
- model: this.config.vertexAI.getGenerativeModel(configuration),
422
- contentRequest: convertToGoogleVertexContentRequest(prompt),
423
- warnings: [...warnings, ...toolWarnings]
424
- };
425
- }
426
- case "object-json": {
427
- return {
428
- model: this.config.vertexAI.getGenerativeModel({
429
- model: this.modelId,
430
- generationConfig: {
431
- ...generationConfig,
432
- responseMimeType: "application/json",
433
- responseSchema: mode.schema != null && // Google Vertex does not support all OpenAPI Schema features,
434
- // so this is needed as an escape hatch:
435
- this.supportsStructuredOutputs ? convertJSONSchemaToOpenAPISchema(
436
- mode.schema
437
- ) : void 0
438
- },
439
- safetySettings: this.settings.safetySettings
440
- }),
441
- contentRequest: convertToGoogleVertexContentRequest(prompt),
442
- warnings
443
- };
444
- }
445
- case "object-tool": {
446
- const configuration = {
447
- model: this.modelId,
448
- generationConfig,
449
- tools: [
450
- {
451
- functionDeclarations: [
452
- {
453
- name: mode.tool.name,
454
- description: (_b = mode.tool.description) != null ? _b : "",
455
- parameters: convertJSONSchemaToOpenAPISchema(
456
- mode.tool.parameters
457
- )
458
- }
459
- ]
460
- }
461
- ],
462
- toolConfig: {
463
- functionCallingConfig: { mode: import_vertexai2.FunctionCallingMode.ANY }
464
- },
465
- safetySettings: this.settings.safetySettings
466
- };
467
- return {
468
- model: this.config.vertexAI.getGenerativeModel(configuration),
469
- contentRequest: convertToGoogleVertexContentRequest(prompt),
470
- warnings
471
- };
472
- }
473
- default: {
474
- const _exhaustiveCheck = type;
475
- throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
476
- }
477
- }
478
- }
479
- supportsUrl(url) {
480
- return url.protocol === "gs:";
481
- }
482
- async doGenerate(options) {
483
- var _a, _b, _c;
484
- const { model, contentRequest, warnings } = await this.getArgs(options);
485
- const { response } = await model.generateContent(contentRequest);
486
- const firstCandidate = (_a = response.candidates) == null ? void 0 : _a[0];
487
- if (firstCandidate == null) {
488
- throw new import_provider3.NoContentGeneratedError({ message: "No candidates returned" });
489
- }
490
- const parts = firstCandidate.content.parts;
491
- const usageMetadata = response.usageMetadata;
492
- const toolCalls = getToolCallsFromParts({
493
- parts,
494
- 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
495
37
  });
496
- return {
497
- text: getTextFromParts(parts),
498
- toolCalls,
499
- finishReason: mapGoogleVertexFinishReason({
500
- finishReason: firstCandidate.finishReason,
501
- hasToolCalls: toolCalls != null && toolCalls.length > 0
502
- }),
503
- usage: {
504
- promptTokens: (_b = usageMetadata == null ? void 0 : usageMetadata.promptTokenCount) != null ? _b : NaN,
505
- completionTokens: (_c = usageMetadata == null ? void 0 : usageMetadata.candidatesTokenCount) != null ? _c : NaN
506
- },
507
- rawCall: {
508
- rawPrompt: contentRequest,
509
- rawSettings: {}
510
- },
511
- providerMetadata: this.settings.useSearchGrounding ? {
512
- vertex: {
513
- groundingMetadata: firstCandidate.groundingMetadata
514
- }
515
- } : void 0,
516
- warnings
517
- };
518
- }
519
- async doStream(options) {
520
- const { model, contentRequest, warnings } = await this.getArgs(options);
521
- const { stream } = await model.generateContentStream(contentRequest);
522
- let finishReason = "unknown";
523
- let usage = {
524
- promptTokens: Number.NaN,
525
- completionTokens: Number.NaN
526
- };
527
- const generateId2 = this.config.generateId;
528
- let hasToolCalls = false;
529
- let providerMetadata;
530
- return {
531
- stream: (0, import_provider_utils2.convertAsyncIteratorToReadableStream)(stream).pipeThrough(
532
- new TransformStream(
533
- {
534
- transform(chunk, controller) {
535
- var _a, _b, _c;
536
- const usageMetadata = chunk.usageMetadata;
537
- if (usageMetadata != null) {
538
- usage = {
539
- promptTokens: (_a = usageMetadata.promptTokenCount) != null ? _a : NaN,
540
- completionTokens: (_b = usageMetadata.candidatesTokenCount) != null ? _b : NaN
541
- };
542
- }
543
- const candidate = (_c = chunk.candidates) == null ? void 0 : _c[0];
544
- if (candidate == null) {
545
- return;
546
- }
547
- if (candidate.finishReason != null) {
548
- finishReason = mapGoogleVertexFinishReason({
549
- finishReason: candidate.finishReason,
550
- hasToolCalls
551
- });
552
- }
553
- if (candidate.groundingMetadata != null) {
554
- providerMetadata = {
555
- vertex: {
556
- groundingMetadata: candidate.groundingMetadata
557
- }
558
- };
559
- }
560
- const content = candidate.content;
561
- const deltaText = getTextFromParts(content.parts);
562
- if (deltaText != null) {
563
- controller.enqueue({
564
- type: "text-delta",
565
- textDelta: deltaText
566
- });
567
- }
568
- const toolCallDeltas = getToolCallsFromParts({
569
- parts: content.parts,
570
- generateId: generateId2
571
- });
572
- if (toolCallDeltas != null) {
573
- for (const toolCall of toolCallDeltas) {
574
- controller.enqueue({
575
- type: "tool-call-delta",
576
- toolCallType: "function",
577
- toolCallId: toolCall.toolCallId,
578
- toolName: toolCall.toolName,
579
- argsTextDelta: toolCall.args
580
- });
581
- controller.enqueue({
582
- type: "tool-call",
583
- toolCallType: "function",
584
- toolCallId: toolCall.toolCallId,
585
- toolName: toolCall.toolName,
586
- args: toolCall.args
587
- });
588
- hasToolCalls = true;
589
- }
590
- }
591
- },
592
- flush(controller) {
593
- controller.enqueue({
594
- type: "finish",
595
- finishReason,
596
- usage,
597
- providerMetadata
598
- });
599
- }
600
- }
601
- )
602
- ),
603
- rawCall: {
604
- rawPrompt: contentRequest,
605
- rawSettings: {}
606
- },
607
- warnings
608
- };
609
- }
610
- };
611
- function getToolCallsFromParts({
612
- parts,
613
- generateId: generateId2
614
- }) {
615
- if (parts == null) {
616
- return void 0;
38
+ authOptions = options;
617
39
  }
618
- return parts.flatMap(
619
- (part) => part.functionCall == null ? [] : {
620
- toolCallType: "function",
621
- toolCallId: generateId2(),
622
- toolName: part.functionCall.name,
623
- args: JSON.stringify(part.functionCall.args)
624
- }
625
- );
40
+ return authInstance;
626
41
  }
627
- function getTextFromParts(parts) {
628
- if (parts == null) {
629
- return void 0;
630
- }
631
- const textParts = parts.filter((part) => "text" in part);
632
- 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;
633
47
  }
634
48
 
49
+ // src/google-vertex-provider.ts
50
+ var import_provider_utils3 = require("@ai-sdk/provider-utils");
51
+
635
52
  // src/google-vertex-embedding-model.ts
636
- var import_provider4 = require("@ai-sdk/provider");
637
- 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");
638
55
  var import_zod2 = require("zod");
639
56
 
640
- // src/google-error.ts
641
- 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");
642
59
  var import_zod = require("zod");
643
- var googleErrorDataSchema = import_zod.z.object({
60
+ var googleVertexErrorDataSchema = import_zod.z.object({
644
61
  error: import_zod.z.object({
645
62
  code: import_zod.z.number().nullable(),
646
63
  message: import_zod.z.string(),
647
64
  status: import_zod.z.string()
648
65
  })
649
66
  });
650
- var googleFailedResponseHandler = (0, import_provider_utils3.createJsonErrorResponseHandler)({
651
- errorSchema: googleErrorDataSchema,
652
- errorToMessage: (data) => data.error.message
653
- });
67
+ var googleVertexFailedResponseHandler = (0, import_provider_utils.createJsonErrorResponseHandler)(
68
+ {
69
+ errorSchema: googleVertexErrorDataSchema,
70
+ errorToMessage: (data) => data.error.message
71
+ }
72
+ );
654
73
 
655
74
  // src/google-vertex-embedding-model.ts
656
75
  var GoogleVertexEmbeddingModel = class {
@@ -675,27 +94,28 @@ var GoogleVertexEmbeddingModel = class {
675
94
  abortSignal
676
95
  }) {
677
96
  if (values.length > this.maxEmbeddingsPerCall) {
678
- throw new import_provider4.TooManyEmbeddingValuesForCallError({
97
+ throw new import_provider.TooManyEmbeddingValuesForCallError({
679
98
  provider: this.provider,
680
99
  modelId: this.modelId,
681
100
  maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
682
101
  values
683
102
  });
684
103
  }
685
- 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)({
686
109
  url: `https://${this.config.region}-aiplatform.googleapis.com/v1/projects/${this.config.project}/locations/${this.config.region}/publishers/google/models/${this.modelId}:predict`,
687
- headers: (0, import_provider_utils4.combineHeaders)(
688
- { Authorization: `Bearer ${await this.config.generateAuthToken()}` },
689
- headers
690
- ),
110
+ headers: mergedHeaders,
691
111
  body: {
692
112
  instances: values.map((value) => ({ content: value })),
693
113
  parameters: {
694
114
  outputDimensionality: this.settings.outputDimensionality
695
115
  }
696
116
  },
697
- failedResponseHandler: googleFailedResponseHandler,
698
- successfulResponseHandler: (0, import_provider_utils4.createJsonResponseHandler)(
117
+ failedResponseHandler: googleVertexFailedResponseHandler,
118
+ successfulResponseHandler: (0, import_provider_utils2.createJsonResponseHandler)(
699
119
  googleVertexTextEmbeddingResponseSchema
700
120
  ),
701
121
  abortSignal
@@ -728,42 +148,39 @@ var googleVertexTextEmbeddingResponseSchema = import_zod2.z.object({
728
148
  });
729
149
 
730
150
  // src/google-vertex-provider.ts
151
+ var import_internal = require("@ai-sdk/google/internal");
731
152
  function createVertex(options = {}) {
732
- const loadVertexProject = () => (0, import_provider_utils5.loadSetting)({
153
+ const loadVertexProject = () => (0, import_provider_utils3.loadSetting)({
733
154
  settingValue: options.project,
734
155
  settingName: "project",
735
156
  environmentVariableName: "GOOGLE_VERTEX_PROJECT",
736
157
  description: "Google Vertex project"
737
158
  });
738
- const loadVertexLocation = () => (0, import_provider_utils5.loadSetting)({
159
+ const loadVertexLocation = () => (0, import_provider_utils3.loadSetting)({
739
160
  settingValue: options.location,
740
161
  settingName: "location",
741
162
  environmentVariableName: "GOOGLE_VERTEX_LOCATION",
742
163
  description: "Google Vertex location"
743
164
  });
744
- const createVertexAI = () => {
745
- var _a, _b;
746
- const config = {
747
- project: loadVertexProject(),
748
- location: loadVertexLocation(),
749
- googleAuthOptions: options.googleAuthOptions
750
- };
751
- return (_b = (_a = options.createVertexAI) == null ? void 0 : _a.call(options, config)) != null ? _b : new import_vertexai3.VertexAI(config);
752
- };
753
165
  const createChatModel = (modelId, settings = {}) => {
754
- var _a;
755
- return new GoogleVertexLanguageModel(modelId, settings, {
756
- vertexAI: createVertexAI(),
757
- 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
758
175
  });
759
176
  };
760
177
  const createEmbeddingModel = (modelId, settings = {}) => {
761
- const vertexAI = createVertexAI();
178
+ var _a;
762
179
  return new GoogleVertexEmbeddingModel(modelId, settings, {
763
- provider: "google.vertex",
180
+ provider: `google.vertex.embedding`,
764
181
  region: loadVertexLocation(),
765
182
  project: loadVertexProject(),
766
- generateAuthToken: () => vertexAI.googleAuth.getAccessToken()
183
+ headers: (_a = options.headers) != null ? _a : {}
767
184
  });
768
185
  };
769
186
  const provider = function(modelId, settings) {
@@ -778,7 +195,20 @@ function createVertex(options = {}) {
778
195
  provider.textEmbeddingModel = createEmbeddingModel;
779
196
  return provider;
780
197
  }
781
- 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();
782
212
  // Annotate the CommonJS export names for ESM import in node:
783
213
  0 && (module.exports = {
784
214
  createVertex,