Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

vertex-e2e.ts

48 lines1.5 KB

1import type { VertexClientConfig } from '@tanstack/ai-vertex'
2​
3const E2E_PROJECT = 'e2e-project'
4const E2E_LOCATION = 'us-central1'
5​
6// `@google/genai` defaults Vertex to `v1beta1`. aimock's Vertex handler only
7// matches `/v1/projects/{p}/locations/{l}/publishers/google/models/{m}:…`.
8const E2E_API_VERSION = 'v1'
9​
10type VertexAuthClient = NonNullable<
11 NonNullable<VertexClientConfig['googleAuthOptions']>['authClient']
13​
14/**
15 * Dummy Google auth so Vertex mode does not try Application Default
16 * Credentials in CI. aimock does not check the bearer token.
17 *
18 * Project + location keep the Vertex request path
19 * `/v1/projects/{p}/locations/{l}/publishers/google/models/{m}:streamGenerateContent`,
20 * which aimock already serves.
21 */
22class E2eVertexAuthClient {
23 async getRequestHeaders() {
24 return new Headers({ Authorization: 'Bearer e2e-dummy' })
25 }
27​
28export function vertexE2eAuthClient() {
29 return new E2eVertexAuthClient()
31​
32export function vertexE2eConfig(
33 baseUrl: string,
34 headers?: Record<string, string>,
35): VertexClientConfig {
36 return {
37 project: E2E_PROJECT,
38 location: E2E_LOCATION,
39 apiVersion: E2E_API_VERSION,
40 httpOptions: { baseUrl, headers, apiVersion: E2E_API_VERSION },
41 googleAuthOptions: {
42 // GoogleAuthOptions.authClient is the abstract AuthClient class from
43 // google-auth-library. GoogleAuth only calls getRequestHeaders() on
44 // the cached client. This package does not depend on that library.
45 authClient: new E2eVertexAuthClient() as VertexAuthClient,
46 },
47 }