The Open Framework for Building Agents
fix(eve): recognize linked-project gateway credentials (#40)
Ruie5b777ba27bd
diff --git a/.changeset/tidy-dingos-link.md b/.changeset/tidy-dingos-link.mdnew file mode 100644index 000000000..e18ec815b--- /dev/null+++ b/.changeset/tidy-dingos-link.md@@ -0,0 +1,5 @@+---+"eve": patch+---++Resolve AI Gateway OIDC readiness through Vercel's token resolver so `eve dev` recognizes projects linked by the Vercel CLI without requiring an environment pull or showing a missing-credentials setup issue.diff --git a/packages/eve/src/cli/dev/tui/setup-issues.test.ts b/packages/eve/src/cli/dev/tui/setup-issues.test.tsindex b572f7fbc..4044ed05d 100644--- a/packages/eve/src/cli/dev/tui/setup-issues.test.ts+++ b/packages/eve/src/cli/dev/tui/setup-issues.test.ts@@ -17,9 +17,20 @@ function context(overrides: Partial<BootDetectionContext> = {}): BootDetectionCotype AgentInfo = NonNullable<BootDetectionContext["info"]>;/** A minimal but fully-typed `/eve/v1/info` payload carrying a routing decision. */-function infoWithRouting(routing: AgentInfo["agent"]["model"]["routing"]): AgentInfo {+function infoWithRouting(+ routing: AgentInfo["agent"]["model"]["routing"],+ endpoint?: AgentInfo["agent"]["model"]["endpoint"],+): AgentInfo {+ const model: AgentInfo["agent"]["model"] =+ endpoint === undefined ? { id: "m", routing } : { endpoint, id: "m", routing };+return {- agent: { agentRoot: "/a", appRoot: "/a", model: { id: "m", routing }, name: "Agent" },+ agent: {+ agentRoot: "/a",+ appRoot: "/a",+ model,+ name: "Agent",+ },capabilities: { devRoutes: true },channels: { authored: [], available: [], disabledFramework: [], framework: [] },connections: [],@@ -63,6 +74,15 @@ describe("BOOT_DETECTIONS", () => {expect(await detectSetupIssues(context({ info }))).toEqual([]);});+ it("stays quiet when the runtime resolved linked-project OIDC", async () => {+ const info = infoWithRouting(+ { kind: "gateway", target: "openai" },+ { kind: "gateway", connected: true, credential: "oidc" },+ );++ expect(await detectSetupIssues(context({ info }))).toEqual([]);+ });+it("skips a throwing detection instead of failing the boot", async () => {const issues = await detectSetupIssues(context({ env: { AI_GATEWAY_API_KEY: "k" } }), [{diff --git a/packages/eve/src/cli/dev/tui/setup-issues.ts b/packages/eve/src/cli/dev/tui/setup-issues.tsindex a92607e04..c1a829a43 100644--- a/packages/eve/src/cli/dev/tui/setup-issues.ts+++ b/packages/eve/src/cli/dev/tui/setup-issues.ts@@ -45,9 +45,16 @@ export interface BootDetection {const modelProvider: BootDetection = {id: "model-provider",async detect({ appRoot, env, info }) {- // An external-provider model is reached with its own provider key; gateway- // linking/credentials don't apply and /model can't edit it.- if (info?.agent.model.routing?.kind === "external") {+ const endpoint = info?.agent.model.endpoint;+ const isEndpointExternal =+ endpoint?.kind === "external" ||+ (endpoint === undefined && info?.agent.model.routing?.kind === "external");+ const isAIGatewayConnected = endpoint?.kind === "gateway" && endpoint.connected;++ // The running server owns endpoint readiness. Fall back to routing and+ // local credential checks only when talking to a legacy server that did+ // not return the composed endpoint state.+ if (isEndpointExternal || isAIGatewayConnected) {return [];}if (env.AI_GATEWAY_API_KEY || env.VERCEL_OIDC_TOKEN) {diff --git a/packages/eve/src/internal/nitro/routes/info.test.ts b/packages/eve/src/internal/nitro/routes/info.test.tsindex ac4db4bc3..ff0a38bc9 100644--- a/packages/eve/src/internal/nitro/routes/info.test.ts+++ b/packages/eve/src/internal/nitro/routes/info.test.ts@@ -1,8 +1,18 @@-import { describe, expect, it, vi } from "vitest";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";const mocks = vi.hoisted(() => ({buildAgentInfoResponseFromManifest: vi.fn(() => ({ kind: "eve-agent-info", version: 1 })),- loadAgentInfoManifestData: vi.fn(async () => ({ manifest: {}, schedules: [] })),+ getVercelOidcToken: vi.fn(),+ loadAgentInfoManifestData: vi.fn(async () => ({+ manifest: {+ config: {+ model: {+ routing: { kind: "gateway", target: "openai" },+ },+ },+ },+ schedules: [],+ })),localDev: vi.fn(() => "local-dev-auth"),resolveAgentInfoCompiledArtifactsSource: vi.fn(() => ({appRoot: "/tmp/app/.eve/dev-runtime/snapshots/current/app",@@ -12,6 +22,10 @@ const mocks = vi.hoisted(() => ({vercelOidc: vi.fn(() => "vercel-oidc-auth"),}));+vi.mock("#compiled/@vercel/oidc/index.js", () => ({+ getVercelOidcToken: mocks.getVercelOidcToken,+}));+vi.mock("#internal/nitro/routes/agent-info/build-agent-info-response-from-manifest.js", () => ({buildAgentInfoResponseFromManifest: mocks.buildAgentInfoResponseFromManifest,}));@@ -27,48 +41,88 @@ vi.mock("#public/channels/auth.js", () => ({vercelOidc: mocks.vercelOidc,}));+const ROUTE_INPUT = {+ appRoot: "/tmp/app",+ dev: true,+ devRuntimeArtifactsPointerPath: "/tmp/app/.eve/dev-runtime/current.json",+ mode: "development",+ moduleMapLoaderPath: "/tmp/eve/src/internal/authored-module-map-loader.ts",+} as const;++const GATEWAY_MANIFEST_DATA = {+ manifest: {+ config: {+ model: {+ routing: { kind: "gateway" as const, target: "openai" },+ },+ },+ },+ schedules: [],+};++async function requestAgentInfo(): Promise<Response> {+ const { handleAgentInfoRequest } = await import("#internal/nitro/routes/info.js");++ return await handleAgentInfoRequest(ROUTE_INPUT, new Request("http://127.0.0.1/eve/v1/info"));+}+describe("handleAgentInfoRequest", () => {- it("resolves info from the dev runtime artifact source", async () => {- // Determinism: the route reads gateway credentials from process.env.+ beforeEach(() => {vi.stubEnv("AI_GATEWAY_API_KEY", "");vi.stubEnv("VERCEL_OIDC_TOKEN", "");- const { handleAgentInfoRequest } = await import("#internal/nitro/routes/info.js");-- const response = await handleAgentInfoRequest(- {- appRoot: "/tmp/app",- dev: true,- devRuntimeArtifactsPointerPath: "/tmp/app/.eve/dev-runtime/current.json",- mode: "development",- moduleMapLoaderPath: "/tmp/eve/src/internal/authored-module-map-loader.ts",- },- new Request("http://127.0.0.1/eve/v1/info"),- );+ mocks.buildAgentInfoResponseFromManifest.mockClear();+ mocks.getVercelOidcToken.mockReset();+ mocks.getVercelOidcToken.mockRejectedValue(new Error("not linked"));+ mocks.loadAgentInfoManifestData.mockReset();+ mocks.loadAgentInfoManifestData.mockResolvedValue(GATEWAY_MANIFEST_DATA);+ mocks.resolveAgentInfoCompiledArtifactsSource.mockClear();+ });++ afterEach(() => {+ vi.unstubAllEnvs();+ });++ it("resolves info from the dev runtime artifact source", async () => {+ const response = await requestAgentInfo();expect(response.status).toBe(200);- expect(mocks.resolveAgentInfoCompiledArtifactsSource).toHaveBeenCalledWith({- appRoot: "/tmp/app",- dev: true,- devRuntimeArtifactsPointerPath: "/tmp/app/.eve/dev-runtime/current.json",- mode: "development",- moduleMapLoaderPath: "/tmp/eve/src/internal/authored-module-map-loader.ts",- });+ expect(mocks.resolveAgentInfoCompiledArtifactsSource).toHaveBeenCalledWith(ROUTE_INPUT);expect(mocks.loadAgentInfoManifestData).toHaveBeenCalledWith({compiledArtifactsSource: {appRoot: "/tmp/app/.eve/dev-runtime/snapshots/current/app",kind: "disk",},});- expect(mocks.buildAgentInfoResponseFromManifest).toHaveBeenCalledWith(- {- manifest: {},- schedules: [],- },- {- mode: "development",- gatewayCredentials: { apiKey: false, oidc: false },- },- );- vi.unstubAllEnvs();+ expect(mocks.buildAgentInfoResponseFromManifest).toHaveBeenCalledWith(GATEWAY_MANIFEST_DATA, {+ mode: "development",+ gatewayCredentials: { apiKey: false, oidc: false },+ });+ expect(mocks.getVercelOidcToken).toHaveBeenCalledOnce();+ });++ it("reports linked-project OIDC resolved by the Vercel SDK", async () => {+ mocks.getVercelOidcToken.mockResolvedValue("linked-project-token");++ const response = await requestAgentInfo();++ expect(response.status).toBe(200);+ expect(mocks.buildAgentInfoResponseFromManifest).toHaveBeenCalledWith(GATEWAY_MANIFEST_DATA, {+ mode: "development",+ gatewayCredentials: { apiKey: false, oidc: true },+ });+ expect(mocks.getVercelOidcToken).toHaveBeenCalledOnce();+ });++ it("does not resolve OIDC when an AI Gateway API key is present", async () => {+ vi.stubEnv("AI_GATEWAY_API_KEY", "gateway-key");++ const response = await requestAgentInfo();++ expect(response.status).toBe(200);+ expect(mocks.buildAgentInfoResponseFromManifest).toHaveBeenCalledWith(GATEWAY_MANIFEST_DATA, {+ mode: "development",+ gatewayCredentials: { apiKey: true, oidc: false },+ });+ expect(mocks.getVercelOidcToken).not.toHaveBeenCalled();});});diff --git a/packages/eve/src/internal/nitro/routes/info.ts b/packages/eve/src/internal/nitro/routes/info.tsindex b6bbd8ceb..164775039 100644--- a/packages/eve/src/internal/nitro/routes/info.ts+++ b/packages/eve/src/internal/nitro/routes/info.ts@@ -1,10 +1,13 @@+import { getVercelOidcToken } from "#compiled/@vercel/oidc/index.js";import { buildAgentInfoResponseFromManifest } from "#internal/nitro/routes/agent-info/build-agent-info-response-from-manifest.js";import {loadAgentInfoManifestData,resolveAgentInfoCompiledArtifactsSource,} from "#internal/nitro/routes/agent-info/load-agent-info-data.js";+import type { GatewayCredentialPresence } from "#internal/resolve-model-endpoint-status.js";import type { NitroArtifactsConfig } from "#internal/nitro/routes/runtime-artifacts.js";import { localDev, routeAuth, vercelOidc } from "#public/channels/auth.js";+import type { ModelRouting } from "#shared/agent-definition.js";type AgentInfoRouteMode = "development" | "production";@@ -19,13 +22,7 @@ async function createAgentInfoPayload(input: AgentInfoRouteInput) {return buildAgentInfoResponseFromManifest(data, {mode: input.mode ?? "development",- // Runtime-authoritative: the running server's own credentials decide gateway- // readiness. AI_GATEWAY_API_KEY outranks the OIDC token, matching the AI SDK- // gateway provider's selection order.- gatewayCredentials: {- apiKey: hasEnvValue(process.env.AI_GATEWAY_API_KEY),- oidc: hasEnvValue(process.env.VERCEL_OIDC_TOKEN),- },+ gatewayCredentials: await resolveGatewayCredentialPresence(data.manifest.config.model.routing),});}@@ -33,6 +30,28 @@ function hasEnvValue(value: string | undefined): boolean {return value !== undefined && value.trim() !== "";}+/**+ * Mirrors the AI Gateway credential selection order. The Vercel OIDC SDK owns+ * request-context, environment, and linked-project token resolution; lookup+ * failure means the gateway is unavailable and must not break agent inspection.+ */+async function resolveGatewayCredentialPresence(+ routing: ModelRouting,+): Promise<GatewayCredentialPresence> {+ const apiKey = hasEnvValue(process.env.AI_GATEWAY_API_KEY);++ if (routing.kind === "external" || apiKey) {+ return { apiKey, oidc: false };+ }++ try {+ await getVercelOidcToken();+ return { apiKey: false, oidc: true };+ } catch {+ return { apiKey: false, oidc: false };+ }+}+/*** Builds the package-owned JSON inspection response for the current agent.*