Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

Merge feat/devin-cli-windsurf-provider: Devin CLI + Windsurf provider + OAuth

diegosouzapwa24972477796
diff --cc src/app/api/oauth/[provider]/[action]/route.ts
index 4db7573a5b,8bd8b902db..341eac7ee0
--- a/src/app/api/oauth/[provider]/[action]/route.ts
+++ b/src/app/api/oauth/[provider]/[action]/route.ts
@@@ -594,8 -593,7 +594,81 @@@ export async function POST
},
});
} catch (exchangeErr: any) {
- return NextResponse.json({ success: false, error: exchangeErr.message }, { status: 500 });
+ console.error("OAuth exchange error:", exchangeErr);
- return NextResponse.json({ success: false, error: "Internal server error" }, { status: 500 });
++ return NextResponse.json(
++ { success: false, error: "Internal server error" },
++ { status: 500 }
++ );
++ }
++ }
++
++ if (action === "import-token") {
++ const { token, connectionId } = body;
++
++ if (!IMPORT_TOKEN_PROVIDERS.has(provider)) {
++ return NextResponse.json(
++ {
++ error: `import-token not supported for provider: ${provider}. Supported: ${[...IMPORT_TOKEN_PROVIDERS].join(", ")}`,
++ },
++ { status: 400 }
++ );
++ }
++
++ try {
++ // Map the raw token via the provider's mapTokens() — skips the HTTP exchange entirely.
++ const providerData = getProvider(provider);
++ const tokenData = providerData.mapTokens({ accessToken: token });
++
++ // Normalize: if name is missing, use email as fallback display label
++ if (!tokenData.name && (tokenData.email || tokenData.displayName)) {
++ tokenData.name = tokenData.email || tokenData.displayName;
++ }
++
++ const expiresAt = tokenData.expiresIn
++ ? new Date(Date.now() + tokenData.expiresIn * 1000).toISOString()
++ : null;
++
++ let connection: any;
++ if (tokenData.email) {
++ const existing = await getProviderConnections({ provider });
++ const match = existing.find((c: any) => {
++ if (c.id && safeEqual(connectionId, c.id)) return true;
++ if (!safeEqual(c.email, tokenData.email) || c.authType !== "oauth") return false;
++ return true;
++ });
++ const matchId = typeof match?.id === "string" ? match.id : null;
++ if (matchId) {
++ connection = await updateProviderConnection(matchId, {
++ ...tokenData,
++ expiresAt,
++ testStatus: "active",
++ isActive: true,
++ });
++ }
++ }
++ if (!connection) {
++ connection = await createProviderConnection({
++ provider,
++ authType: "oauth",
++ ...tokenData,
++ expiresAt,
++ testStatus: "active",
++ });
++ }
++
++ await syncToCloudIfEnabled();
++
++ return NextResponse.json({
++ success: true,
++ connection: {
++ id: connection.id,
++ provider: connection.provider,
++ email: connection.email,
++ displayName: connection.displayName,
++ },
++ });
++ } catch (importErr: any) {
++ return NextResponse.json({ success: false, error: importErr.message }, { status: 500 });
}
}