@ai-sdk/google-vertex 1.0.4 → 2.0.1

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