UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

43 lines • 2.21 kB
import { getApiProvider, } from "@earendil-works/pi-ai"; import { getVertexAdcAccess } from "@earendil-works/pi-ai/api/google-vertex-adc.lazy"; import { lazyStream } from "@earendil-works/pi-ai/api/lazy"; export const VERTEX_MODEL_GARDEN_LOCATION = "global"; /** * The registration baseUrl. It only satisfies registration: while a model still carries it, the request URL is * built per call from the ADC-resolved project. Any other value is the user's models.json baseUrl (senpi#4765). */ export const VERTEX_MODEL_GARDEN_REGISTRATION_BASE_URL = "https://aiplatform.googleapis.com/v1"; /** * The project comes from its own environment (`options.env`, then the ADC quota * project, then `getProjectId()`), never from the API-key slot: a stored secret * must not end up in the request URL, and the project may legitimately come from * ADC alone. */ export const defaultResolveVertexAccess = (options) => getVertexAdcAccess({ env: options?.env }); export function vertexHost(location) { return location === "global" ? "aiplatform.googleapis.com" : `${location}-aiplatform.googleapis.com`; } function buildVertexOpenApiBaseUrl(project, location = VERTEX_MODEL_GARDEN_LOCATION) { return `https://${vertexHost(location)}/v1/projects/${encodeURIComponent(project)}/locations/${location}/endpoints/openapi`; } function requireApi(api) { const provider = getApiProvider(api); if (!provider) throw new Error(`API provider ${api} is not registered`); return provider; } export function streamVertexModelGarden(model, context, options, resolveAccess = defaultResolveVertexAccess) { return lazyStream(model, async () => { const access = await resolveAccess(options); const baseUrl = model.baseUrl === VERTEX_MODEL_GARDEN_REGISTRATION_BASE_URL ? buildVertexOpenApiBaseUrl(access.project) : model.baseUrl; const target = { ...model, baseUrl }; return requireApi("openai-completions").streamSimple(target, context, { ...options, apiKey: access.accessToken, headers: { ...options?.headers, "x-goog-user-project": access.quotaProject }, }); }); } //# sourceMappingURL=transport.js.map