ai-agent-router 0.1.21 → 0.2.0
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/.next/BUILD_ID +1 -1
- package/.next/build-manifest.json +2 -2
- package/.next/fallback-build-manifest.json +2 -2
- package/.next/server/app/_global-error.html +2 -2
- package/.next/server/app/_global-error.rsc +1 -1
- package/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/_not-found.html +1 -1
- package/.next/server/app/_not-found.rsc +1 -1
- package/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/api/config/route.js.nft.json +1 -1
- package/.next/server/app/api/gateway/[...path]/route.js.nft.json +1 -1
- package/.next/server/app/api/gateway/models/route.js.nft.json +1 -1
- package/.next/server/app/api/gateway/route.js.nft.json +1 -1
- package/.next/server/app/api/ide/claude/apply/route.js.nft.json +1 -1
- package/.next/server/app/api/ide/claude/available-models/route.js.nft.json +1 -1
- package/.next/server/app/api/ide/claude/save/route.js.nft.json +1 -1
- package/.next/server/app/api/ide/claude/status/route.js.nft.json +1 -1
- package/.next/server/app/api/ide/claude/test/route.js.nft.json +1 -1
- package/.next/server/app/api/logs/route.js.nft.json +1 -1
- package/.next/server/app/api/models/route.js.nft.json +1 -1
- package/.next/server/app/api/providers/route.js.nft.json +1 -1
- package/.next/server/app/api/providers/test/route.js.nft.json +1 -1
- package/.next/server/app/api/service/force-stop/route.js.nft.json +1 -1
- package/.next/server/app/api/service/start/route.js.nft.json +1 -1
- package/.next/server/app/api/service/status/route.js.nft.json +1 -1
- package/.next/server/app/api/service/stop/route.js.nft.json +1 -1
- package/.next/server/app/ide.html +1 -1
- package/.next/server/app/ide.rsc +1 -1
- package/.next/server/app/ide.segments/_full.segment.rsc +1 -1
- package/.next/server/app/ide.segments/_head.segment.rsc +1 -1
- package/.next/server/app/ide.segments/_index.segment.rsc +1 -1
- package/.next/server/app/ide.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/ide.segments/ide/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/ide.segments/ide.segment.rsc +1 -1
- package/.next/server/app/index.html +1 -1
- package/.next/server/app/index.rsc +1 -1
- package/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/index.segments/_full.segment.rsc +1 -1
- package/.next/server/app/index.segments/_head.segment.rsc +1 -1
- package/.next/server/app/index.segments/_index.segment.rsc +1 -1
- package/.next/server/app/index.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/logs/page_client-reference-manifest.js +1 -1
- package/.next/server/app/logs.html +1 -1
- package/.next/server/app/logs.rsc +2 -2
- package/.next/server/app/logs.segments/_full.segment.rsc +2 -2
- package/.next/server/app/logs.segments/_head.segment.rsc +1 -1
- package/.next/server/app/logs.segments/_index.segment.rsc +1 -1
- package/.next/server/app/logs.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/logs.segments/logs/__PAGE__.segment.rsc +2 -2
- package/.next/server/app/logs.segments/logs.segment.rsc +1 -1
- package/.next/server/app/models.html +1 -1
- package/.next/server/app/models.rsc +1 -1
- package/.next/server/app/models.segments/_full.segment.rsc +1 -1
- package/.next/server/app/models.segments/_head.segment.rsc +1 -1
- package/.next/server/app/models.segments/_index.segment.rsc +1 -1
- package/.next/server/app/models.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/models.segments/models/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/models.segments/models.segment.rsc +1 -1
- package/.next/server/app/providers.html +1 -1
- package/.next/server/app/providers.rsc +1 -1
- package/.next/server/app/providers.segments/_full.segment.rsc +1 -1
- package/.next/server/app/providers.segments/_head.segment.rsc +1 -1
- package/.next/server/app/providers.segments/_index.segment.rsc +1 -1
- package/.next/server/app/providers.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/providers.segments/providers/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/providers.segments/providers.segment.rsc +1 -1
- package/.next/server/chunks/[root-of-the-server]__1480f018._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__1480f018._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__1909f3aa._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__1909f3aa._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__1d4b7fc5._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__1d4b7fc5._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__372ef2bf._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__372ef2bf._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__3aaf963c._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__3aaf963c._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__6ce199d2._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__6ce199d2._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__772134c6._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__772134c6._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__7b77f523._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__7b77f523._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__c1b4b601._.js +18 -18
- package/.next/server/chunks/[root-of-the-server]__c1b4b601._.js.map +1 -1
- package/.next/server/chunks/[root-of-the-server]__ccfc7f1d._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__ccfc7f1d._.js.map +1 -1
- package/.next/server/chunks/ssr/src_app_logs_page_tsx_7b7b7b83._.js +1 -1
- package/.next/server/chunks/ssr/src_app_logs_page_tsx_7b7b7b83._.js.map +1 -1
- package/.next/server/pages/404.html +1 -1
- package/.next/server/pages/500.html +2 -2
- package/.next/static/chunks/{81c904164fe81379.js → b6b258e8582e47c4.js} +1 -1
- package/README.md +100 -111
- package/dist/src/app/api/gateway/[...path]/route.js +1 -1
- package/dist/src/app/api/gateway/route.js +1 -1
- package/dist/src/app/api/logs/route.js +2 -2
- package/dist/src/app/api/models/route.js +5 -5
- package/dist/src/app/api/providers/route.js +4 -4
- package/dist/src/app/api/providers/test/route.js +1 -1
- package/dist/src/app/api/service/start/route.js +1 -1
- package/dist/src/app/api/service/status/route.js +1 -1
- package/dist/src/app/api/service/stop/route.js +1 -1
- package/dist/src/app/logs/page.js +13 -1
- package/dist/src/cli/index.js +218 -20
- package/dist/src/db/database.js +35 -1
- package/dist/src/db/queries.js +6 -6
- package/dist/src/server/logger.js +22 -4
- package/package.json +2 -1
- package/src/app/api/gateway/[...path]/route.ts +1 -1
- package/src/app/api/gateway/route.ts +1 -1
- package/src/app/api/logs/route.ts +2 -2
- package/src/app/api/models/route.ts +5 -5
- package/src/app/api/providers/route.ts +4 -4
- package/src/app/api/providers/test/route.ts +1 -1
- package/src/app/api/service/start/route.ts +1 -1
- package/src/app/api/service/status/route.ts +1 -1
- package/src/app/api/service/stop/route.ts +1 -1
- package/src/app/logs/page.tsx +15 -5
- package/src/cli/index.ts +228 -25
- package/src/db/database.ts +34 -4
- package/src/db/queries.ts +6 -6
- package/src/server/logger.ts +19 -4
- /package/.next/static/{PkfqdzwOZgX-UhSNUuhdp → ryTeHAYUvjT1bYolc-x9Z}/_buildManifest.js +0 -0
- /package/.next/static/{PkfqdzwOZgX-UhSNUuhdp → ryTeHAYUvjT1bYolc-x9Z}/_clientMiddlewareManifest.json +0 -0
- /package/.next/static/{PkfqdzwOZgX-UhSNUuhdp → ryTeHAYUvjT1bYolc-x9Z}/_ssgManifest.js +0 -0
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
module.exports=[93695,(e,t,r)=>{t.exports=e.x("next/dist/shared/lib/no-fallback-error.external.js",()=>require("next/dist/shared/lib/no-fallback-error.external.js"))},14747,(e,t,r)=>{t.exports=e.x("path",()=>require("path"))},70406,(e,t,r)=>{t.exports=e.x("next/dist/compiled/@opentelemetry/api",()=>require("next/dist/compiled/@opentelemetry/api"))},18622,(e,t,r)=>{t.exports=e.x("next/dist/compiled/next-server/app-page-turbo.runtime.prod.js",()=>require("next/dist/compiled/next-server/app-page-turbo.runtime.prod.js"))},56704,(e,t,r)=>{t.exports=e.x("next/dist/server/app-render/work-async-storage.external.js",()=>require("next/dist/server/app-render/work-async-storage.external.js"))},32319,(e,t,r)=>{t.exports=e.x("next/dist/server/app-render/work-unit-async-storage.external.js",()=>require("next/dist/server/app-render/work-unit-async-storage.external.js"))},24725,(e,t,r)=>{t.exports=e.x("next/dist/server/app-render/after-task-async-storage.external.js",()=>require("next/dist/server/app-render/after-task-async-storage.external.js"))},98857,e=>{"use strict";var t=e.i(38483);class r{async forwardRequest(e,r){let s,o,a;console.log("[OpenAI Adapter] Starting forwardRequest:",{modelId:e.model_id,modelName:e.name||"unnamed",providerName:e.provider.name,providerBaseUrl:e.provider.base_url,hasEncryptedApiKey:!!e.provider.api_key,encryptedApiKeyLength:e.provider.api_key?.length||0});try{if(s=(0,t.decryptApiKey)(e.provider.api_key),console.log("[OpenAI Adapter] API key decrypted successfully:",{length:s.length,prefix:s.substring(0,10)+"...",suffix:"..."+s.substring(Math.max(0,s.length-10)),isEmpty:!s||""===s.trim(),fullKey:s}),!s||""===s.trim())return console.error("[OpenAI Adapter] Decrypted API key is empty!"),{status:500,headers:{"Content-Type":"application/json"},body:{error:{message:"API key is empty after decryption",type:"decryption_error"}}};s=s.trim()}catch(t){return console.error("[OpenAI Adapter] Failed to decrypt API key:",{error:t.message,stack:t.stack,encryptedKeyLength:e.provider.api_key?.length||0,encryptedKeyPrefix:e.provider.api_key?.substring(0,20)||"none"}),{status:500,headers:{"Content-Type":"application/json"},body:{error:{message:"Failed to decrypt API key: "+t.message,type:"decryption_error"}}}}let n=e.provider.base_url||"https://api.openai.com/v1";n=n.trim().replace(/\/+$/,"");let i=r.path;i&&"/"!==i&&""!==i?i.startsWith("/v1/")?i=i.substring(4):i.startsWith("/")&&(i=i.substring(1)):i="chat/completions",n.endsWith("/v1")||(n+="/v1");let l=`${n}/${i}`;console.log("[OpenAI Adapter] Forwarding request:",{baseUrl:e.provider.base_url,normalizedBaseUrl:n,originalPath:r.path,targetPath:i,url:l,method:r.method,hasApiKey:!!s,apiKeyPrefix:s?s.substring(0,7)+"...":"none",requestBody:r.body?JSON.stringify(r.body).substring(0,200):"none"});let d={"content-type":"application/json"};for(let[e,t]of(d.authorization=`Bearer ${s}`,Object.entries(r.headers))){let r=e.toLowerCase();"host"!==r&&"connection"!==r&&"authorization"!==r&&"x-api-key"!==r&&"content-length"!==r&&"content-type"!==r&&(d[e]=t)}if(console.log("[OpenAI Adapter] Request headers:",{"content-type":d["content-type"],authorization:d.authorization?`Bearer ${s.substring(0,10)}...${s.substring(s.length-4)}`:"none","authorization-full":d.authorization,"user-agent":d["user-agent"]||d["User-Agent"]||"none",allHeaders:Object.keys(d)}),"GET"!==r.method&&"HEAD"!==r.method){let t;t=r.body?{...r.body}:{},e.model_id&&(t.model=e.model_id),console.log("[OpenAI Adapter] Request body:",o=JSON.stringify(t)),console.log("[OpenAI Adapter] Request body length:",o.length)}console.log("[OpenAI Adapter] Sending fetch request:",{url:l.replace(s,"***"),method:r.method,hasBody:!!o,bodyLength:o?.length||0});let p=await fetch(l,{method:r.method,headers:d,body:o});console.log("[OpenAI Adapter] Response received:",{status:p.status,statusText:p.statusText,headers:Object.fromEntries(p.headers.entries())});let u=await p.text();console.log("[OpenAI Adapter] Response body preview:",u.substring(0,200));try{a=JSON.parse(u)}catch{a=u,console.log("[OpenAI Adapter] Response body is not JSON, returning as string")}return{status:p.status,headers:Object.fromEntries(p.headers.entries()),body:a}}async listModels(e){let r=(0,t.decryptApiKey)(e.api_key),s=e.base_url||"https://api.openai.com/v1";(s=s.trim().replace(/\/+$/,"")).endsWith("/v1")||(s=s.endsWith("/")?s+"v1":s+"/v1");let o=`${s}/models`;console.log("[OpenAI] Fetching models:",{baseUrl:e.base_url,normalizedBaseUrl:s,url:o,apiKeyPrefix:r.substring(0,10)+"...",apiKeyLength:r.length});try{let e=await fetch(o,{headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json"}});if(console.log("[OpenAI] Response status:",e.status,e.statusText),!e.ok){let t=await e.text();throw console.error("[OpenAI] Error response body:",t),Error(`Failed to fetch models: ${e.status} ${e.statusText} - ${t.substring(0,200)}`)}let t=await e.json();return console.log("[OpenAI] Fetched models count:",t.data?.length||0),(t.data||[]).map(e=>({id:e.id,name:e.id}))}catch(t){throw console.error("[OpenAI] Error fetching models:",{error:t instanceof Error?t.message:String(t),stack:t instanceof Error?t.stack:void 0,url:o,baseUrl:e.base_url}),t}}}class s{async forwardRequest(e,r){let s,o;console.log("[Anthropic Adapter] Starting forwardRequest:",{modelId:e.model_id,modelName:e.name||"unnamed",providerName:e.provider.name,providerBaseUrl:e.provider.base_url,hasEncryptedApiKey:!!e.provider.api_key,encryptedApiKeyLength:e.provider.api_key?.length||0});try{s=(0,t.decryptApiKey)(e.provider.api_key),console.log("[Anthropic Adapter] API key decrypted successfully, length:",s.length)}catch(e){return console.error("[Anthropic Adapter] Failed to decrypt API key:",e.message),{status:500,headers:{"Content-Type":"application/json"},body:{error:{message:"Failed to decrypt API key",type:"decryption_error"}}}}let a=e.provider.base_url||"https://api.anthropic.com/v1";a=a.trim().replace(/\/+$/,"");let n=r.path;console.log("[Anthropic Adapter] Path processing START:",{inputBaseUrl:e.provider.base_url,originalRequestPath:r.path,hasPath:!!r.path,pathLength:r.path?.length,pathPrefix:r.path?.substring(0,20)}),n&&"/"!==n&&""!==n?n.startsWith("/v1/")?n=n.substring(4):n.startsWith("/")?n=n.substring(1):n.startsWith("v1/")&&(n=n.substring(3)):n="messages";let i=`${a}/${n}`;console.log("[Anthropic Adapter] Path processing result:",{targetPathAfter:n,finalUrl:i}),console.log("[Anthropic Adapter] Forwarding request:",{baseUrl:e.provider.base_url,normalizedBaseUrl:a,originalPath:r.path,targetPath:n,url:i,method:r.method,hasApiKey:!!s,apiKeyPrefix:s?s.substring(0,10)+"...":"none"});let l={"x-api-key":s,Authorization:`Bearer ${s}`,"anthropic-version":"2023-06-01","Content-Type":"application/json",...r.headers};delete l.host,delete l.connection,console.log("[Anthropic Adapter] Request headers:",{"Content-Type":l["Content-Type"],"x-api-key":l["x-api-key"]?`${s.substring(0,10)}...${s.substring(s.length-4)}`:"none",Authorization:l.Authorization?`Bearer ${s.substring(0,10)}...${s.substring(s.length-4)}`:"none","anthropic-version":l["anthropic-version"]});let d=await fetch(i,{method:r.method,headers:l,body:"GET"!==r.method&&"HEAD"!==r.method?JSON.stringify(r.body):void 0});console.log("[Anthropic Adapter] Response status:",d.status,d.statusText);let p=await d.text();console.log("[Anthropic Adapter] Response body preview:",p.substring(0,200));try{o=JSON.parse(p)}catch{o=p,console.log("[Anthropic Adapter] Response body is not JSON, returning as string")}return{status:d.status,headers:Object.fromEntries(d.headers.entries()),body:o}}async listModels(e){return[{id:"claude-3-5-sonnet-20241022",name:"Claude 3.5 Sonnet"},{id:"claude-3-opus-20240229",name:"Claude 3 Opus"},{id:"claude-3-sonnet-20240229",name:"Claude 3 Sonnet"},{id:"claude-3-haiku-20240307",name:"Claude 3 Haiku"}]}}class o{async forwardRequest(e,r){let s,o=(0,t.decryptApiKey)(e.provider.api_key),a=e.provider.base_url||"https://generativelanguage.googleapis.com/v1";a=a.trim().replace(/\/+$/,"");let n=r.path;n&&"/"!==n&&""!==n?n.startsWith("/v1/")?n=n.substring(4):n.startsWith("/")&&(n=n.substring(1)):n=`models/${e.model_id}:generateContent`,a.endsWith("/v1")||(a+="/v1");let i=`${a}/${n}?key=${o}`;console.log("[Gemini Adapter] Forwarding request:",{baseUrl:e.provider.base_url,normalizedBaseUrl:a,originalPath:r.path,targetPath:n,url:i.replace(o,"***"),method:r.method,hasApiKey:!!o});let l={"Content-Type":"application/json",...r.headers};delete l.host,delete l.connection,delete l.authorization,console.log("[Gemini Adapter] Request headers:",{"Content-Type":l["Content-Type"]});let d=await fetch(i,{method:r.method,headers:l,body:"GET"!==r.method&&"HEAD"!==r.method?JSON.stringify(r.body):void 0});console.log("[Gemini Adapter] Response status:",d.status,d.statusText);let p=await d.text();console.log("[Gemini Adapter] Response body preview:",p.substring(0,200));try{s=JSON.parse(p)}catch{s=p,console.log("[Gemini Adapter] Response body is not JSON, returning as string")}return{status:d.status,headers:Object.fromEntries(d.headers.entries()),body:s}}async listModels(e){let r=(0,t.decryptApiKey)(e.api_key),s=e.base_url||"https://generativelanguage.googleapis.com/v1";try{let e=await fetch(`${s}/models?key=${r}`,{headers:{"Content-Type":"application/json"}});if(!e.ok)throw Error(`Failed to fetch models: ${e.statusText}`);let t=await e.json();if(!t.models||!Array.isArray(t.models))return console.error("[Gemini Adapter] Invalid models response:",t),[];return t.models.filter(e=>e&&"object"==typeof e).map(e=>{let t=e.name?e.name.replace("models/",""):"",r=e.displayName||e.name||"";return console.log("[Gemini Adapter] Processing model:",{id:t,name:r}),{id:t,name:r}})}catch(e){throw console.error("Error fetching Gemini models:",e),e}}}function a(e){let t=(e||"").toLowerCase().trim();switch(t){case"openai":return new r;case"anthropic":return new s;case"gemini":return new o;default:throw console.error(`[ProviderAdapter] Unsupported protocol: "${e}", normalized: "${t}"`),Error(`Unsupported protocol: ${e}. Supported protocols: openai, anthropic, gemini`)}}e.s(["getProviderAdapter",()=>a],98857)},17122,e=>{"use strict";var t=e.i(47909),r=e.i(74017),s=e.i(96250),o=e.i(59756),a=e.i(61916),n=e.i(74677),i=e.i(69741),l=e.i(16795),d=e.i(87718),p=e.i(95169),u=e.i(47587),c=e.i(66012),h=e.i(70101),g=e.i(26937),y=e.i(10372),m=e.i(93695);e.i(52474);var A=e.i(220),v=e.i(89171),b=e.i(71560),f=e.i(97731),x=e.i(98857);async function R(e){try{(0,b.getDatabase)();let{provider_id:t,model_id:r}=await e.json();if(!t||!r)return v.NextResponse.json({error:"Provider ID and Model ID are required"},{status:400});let s=await (0,f.getProviderById)(t);if(!s)return v.NextResponse.json({error:"Provider not found"},{status:404});let o=await (0,f.getModelById)(r);if(!o||o.provider_id!==t)return v.NextResponse.json({error:"Model not found or does not belong to this provider"},{status:404});let a=(0,x.getProviderAdapter)(s.protocol),n=function(e,t){switch(e){case"openai":return{method:"POST",path:"/v1/chat/completions",headers:{"Content-Type":"application/json"},query:{},body:{model:t,messages:[{role:"user",content:"test"}]}};case"anthropic":return{method:"POST",path:"/v1/messages",headers:{"Content-Type":"application/json"},query:{},body:{model:t,messages:[{role:"user",content:"test"}]}};case"gemini":return{method:"POST",path:`/v1/models/${t}:generateContent`,headers:{"Content-Type":"application/json"},query:{},body:{contents:[{parts:[{text:"test"}]}]}};default:throw Error(`Unsupported protocol: ${e}`)}}(s.protocol,o.model_id),i=new Promise((e,t)=>{setTimeout(()=>t(Error("连接超时,请检查网络或稍后重试")),1e4)}),l=a.forwardRequest({...o,provider:s},n),d=await Promise.race([l,i]);if(d.status>=200&&d.status<300)return v.NextResponse.json({success:!0,message:"连接成功,模型可用"});{let e="连接失败";return d.body?.error?.message?e=d.body.error.message:"string"==typeof d.body&&(e=d.body),401===d.status||403===d.status?e="API Key 无效,请检查配置":404===d.status?e="模型不存在或不可用":d.status>=500&&(e="服务器错误,请稍后重试"),v.NextResponse.json({success:!1,error:e,status:d.status},{status:200})}}catch(t){console.error("Test connection error:",{name:t.name,message:t.message,stack:t.stack?.substring(0,500),cause:t.cause,status:t.status});let e="连接失败";return e=t.message.includes("超时")?t.message:t.message.includes("fetch failed")||t.message.includes("ECONNREFUSED")?"无法连接到服务器,请检查 Base URL 和网络连接":t.message.includes("ENOTFOUND")||t.message.includes("DNS")?"DNS 解析失败,请检查 Base URL":t.message.includes("Authorization")||t.message?.toLowerCase().includes("401")?"Authorization header 缺失或无效":t.message||"连接失败,请检查配置",v.NextResponse.json({success:!1,error:e},{status:200})}}e.s(["POST",()=>R,"runtime",0,"nodejs"],42907);var w=e.i(42907);let E=new t.AppRouteRouteModule({definition:{kind:r.RouteKind.APP_ROUTE,page:"/api/providers/test/route",pathname:"/api/providers/test",filename:"route",bundlePath:""},distDir:".next",relativeProjectDir:"",resolvedPagePath:"[project]/src/app/api/providers/test/route.ts",nextConfigOutput:"",userland:w}),{workAsyncStorage:O,workUnitAsyncStorage:C,serverHooks:P}=E;function k(){return(0,s.patchFetch)({workAsyncStorage:O,workUnitAsyncStorage:C})}async function T(e,t,s){E.isDev&&(0,o.addRequestMeta)(e,"devRequestTimingInternalsEnd",process.hrtime.bigint());let v="/api/providers/test/route";v=v.replace(/\/index$/,"")||"/";let b=await E.prepare(e,t,{srcPage:v,multiZoneDraftMode:!1});if(!b)return t.statusCode=400,t.end("Bad Request"),null==s.waitUntil||s.waitUntil.call(s,Promise.resolve()),null;let{buildId:f,params:x,nextConfig:R,parsedUrl:w,isDraftMode:O,prerenderManifest:C,routerServerContext:P,isOnDemandRevalidate:k,revalidateOnlyGenerated:T,resolvedPathname:_,clientReferenceManifest:N,serverActionsManifest:I}=b,j=(0,i.normalizeAppPath)(v),S=!!(C.dynamicRoutes[j]||C.routes[_]),q=async()=>((null==P?void 0:P.render404)?await P.render404(e,t,w,!1):t.end("This page could not be found"),null);if(S&&!O){let e=!!C.routes[_],t=C.dynamicRoutes[j];if(t&&!1===t.fallback&&!e){if(R.experimental.adapterPath)return await q();throw new m.NoFallbackError}}let $=null;!S||E.isDev||O||($="/index"===($=_)?"/":$);let U=!0===E.isDev||!S,K=S&&!U;I&&N&&(0,n.setManifestsSingleton)({page:v,clientReferenceManifest:N,serverActionsManifest:I});let D=e.method||"GET",B=(0,a.getTracer)(),H=B.getActiveScopeSpan(),F={params:x,prerenderManifest:C,renderOpts:{experimental:{authInterrupts:!!R.experimental.authInterrupts},cacheComponents:!!R.cacheComponents,supportsDynamicResponse:U,incrementalCache:(0,o.getRequestMeta)(e,"incrementalCache"),cacheLifeProfiles:R.cacheLife,waitUntil:s.waitUntil,onClose:e=>{t.on("close",e)},onAfterTaskError:void 0,onInstrumentationRequestError:(t,r,s,o)=>E.onRequestError(e,t,s,o,P)},sharedContext:{buildId:f}},z=new l.NodeNextRequest(e),M=new l.NodeNextResponse(t),L=d.NextRequestAdapter.fromNodeNextRequest(z,(0,d.signalFromNodeResponse)(t));try{let n=async e=>E.handle(L,F).finally(()=>{if(!e)return;e.setAttributes({"http.status_code":t.statusCode,"next.rsc":!1});let r=B.getRootSpanAttributes();if(!r)return;if(r.get("next.span_type")!==p.BaseServerSpan.handleRequest)return void console.warn(`Unexpected root span type '${r.get("next.span_type")}'. Please report this Next.js issue https://github.com/vercel/next.js`);let s=r.get("next.route");if(s){let t=`${D} ${s}`;e.setAttributes({"next.route":s,"http.route":s,"next.span_name":t}),e.updateName(t)}else e.updateName(`${D} ${v}`)}),i=!!(0,o.getRequestMeta)(e,"minimalMode"),l=async o=>{var a,l;let d=async({previousCacheEntry:r})=>{try{if(!i&&k&&T&&!r)return t.statusCode=404,t.setHeader("x-nextjs-cache","REVALIDATED"),t.end("This page could not be found"),null;let a=await n(o);e.fetchMetrics=F.renderOpts.fetchMetrics;let l=F.renderOpts.pendingWaitUntil;l&&s.waitUntil&&(s.waitUntil(l),l=void 0);let d=F.renderOpts.collectedTags;if(!S)return await (0,c.sendResponse)(z,M,a,F.renderOpts.pendingWaitUntil),null;{let e=await a.blob(),t=(0,h.toNodeOutgoingHttpHeaders)(a.headers);d&&(t[y.NEXT_CACHE_TAGS_HEADER]=d),!t["content-type"]&&e.type&&(t["content-type"]=e.type);let r=void 0!==F.renderOpts.collectedRevalidate&&!(F.renderOpts.collectedRevalidate>=y.INFINITE_CACHE)&&F.renderOpts.collectedRevalidate,s=void 0===F.renderOpts.collectedExpire||F.renderOpts.collectedExpire>=y.INFINITE_CACHE?void 0:F.renderOpts.collectedExpire;return{value:{kind:A.CachedRouteKind.APP_ROUTE,status:a.status,body:Buffer.from(await e.arrayBuffer()),headers:t},cacheControl:{revalidate:r,expire:s}}}}catch(t){throw(null==r?void 0:r.isStale)&&await E.onRequestError(e,t,{routerKind:"App Router",routePath:v,routeType:"route",revalidateReason:(0,u.getRevalidateReason)({isStaticGeneration:K,isOnDemandRevalidate:k})},!1,P),t}},p=await E.handleResponse({req:e,nextConfig:R,cacheKey:$,routeKind:r.RouteKind.APP_ROUTE,isFallback:!1,prerenderManifest:C,isRoutePPREnabled:!1,isOnDemandRevalidate:k,revalidateOnlyGenerated:T,responseGenerator:d,waitUntil:s.waitUntil,isMinimalMode:i});if(!S)return null;if((null==p||null==(a=p.value)?void 0:a.kind)!==A.CachedRouteKind.APP_ROUTE)throw Object.defineProperty(Error(`Invariant: app-route received invalid cache entry ${null==p||null==(l=p.value)?void 0:l.kind}`),"__NEXT_ERROR_CODE",{value:"E701",enumerable:!1,configurable:!0});i||t.setHeader("x-nextjs-cache",k?"REVALIDATED":p.isMiss?"MISS":p.isStale?"STALE":"HIT"),O&&t.setHeader("Cache-Control","private, no-cache, no-store, max-age=0, must-revalidate");let m=(0,h.fromNodeOutgoingHttpHeaders)(p.value.headers);return i&&S||m.delete(y.NEXT_CACHE_TAGS_HEADER),!p.cacheControl||t.getHeader("Cache-Control")||m.get("Cache-Control")||m.set("Cache-Control",(0,g.getCacheControlHeader)(p.cacheControl)),await (0,c.sendResponse)(z,M,new Response(p.value.body,{headers:m,status:p.value.status||200})),null};H?await l(H):await B.withPropagatedContext(e.headers,()=>B.trace(p.BaseServerSpan.handleRequest,{spanName:`${D} ${v}`,kind:a.SpanKind.SERVER,attributes:{"http.method":D,"http.target":e.url}},l))}catch(t){if(t instanceof m.NoFallbackError||await E.onRequestError(e,t,{routerKind:"App Router",routePath:j,routeType:"route",revalidateReason:(0,u.getRevalidateReason)({isStaticGeneration:K,isOnDemandRevalidate:k})},!1,P),S)throw t;return await (0,c.sendResponse)(z,M,new Response(null,{status:500})),null}}e.s(["handler",()=>T,"patchFetch",()=>k,"routeModule",()=>E,"serverHooks",()=>P,"workAsyncStorage",()=>O,"workUnitAsyncStorage",()=>C],17122)}];
|
|
1
|
+
module.exports=[93695,(e,t,r)=>{t.exports=e.x("next/dist/shared/lib/no-fallback-error.external.js",()=>require("next/dist/shared/lib/no-fallback-error.external.js"))},14747,(e,t,r)=>{t.exports=e.x("path",()=>require("path"))},70406,(e,t,r)=>{t.exports=e.x("next/dist/compiled/@opentelemetry/api",()=>require("next/dist/compiled/@opentelemetry/api"))},18622,(e,t,r)=>{t.exports=e.x("next/dist/compiled/next-server/app-page-turbo.runtime.prod.js",()=>require("next/dist/compiled/next-server/app-page-turbo.runtime.prod.js"))},56704,(e,t,r)=>{t.exports=e.x("next/dist/server/app-render/work-async-storage.external.js",()=>require("next/dist/server/app-render/work-async-storage.external.js"))},32319,(e,t,r)=>{t.exports=e.x("next/dist/server/app-render/work-unit-async-storage.external.js",()=>require("next/dist/server/app-render/work-unit-async-storage.external.js"))},24725,(e,t,r)=>{t.exports=e.x("next/dist/server/app-render/after-task-async-storage.external.js",()=>require("next/dist/server/app-render/after-task-async-storage.external.js"))},98857,e=>{"use strict";var t=e.i(38483);class r{async forwardRequest(e,r){let s,o,a;console.log("[OpenAI Adapter] Starting forwardRequest:",{modelId:e.model_id,modelName:e.name||"unnamed",providerName:e.provider.name,providerBaseUrl:e.provider.base_url,hasEncryptedApiKey:!!e.provider.api_key,encryptedApiKeyLength:e.provider.api_key?.length||0});try{if(s=(0,t.decryptApiKey)(e.provider.api_key),console.log("[OpenAI Adapter] API key decrypted successfully:",{length:s.length,prefix:s.substring(0,10)+"...",suffix:"..."+s.substring(Math.max(0,s.length-10)),isEmpty:!s||""===s.trim(),fullKey:s}),!s||""===s.trim())return console.error("[OpenAI Adapter] Decrypted API key is empty!"),{status:500,headers:{"Content-Type":"application/json"},body:{error:{message:"API key is empty after decryption",type:"decryption_error"}}};s=s.trim()}catch(t){return console.error("[OpenAI Adapter] Failed to decrypt API key:",{error:t.message,stack:t.stack,encryptedKeyLength:e.provider.api_key?.length||0,encryptedKeyPrefix:e.provider.api_key?.substring(0,20)||"none"}),{status:500,headers:{"Content-Type":"application/json"},body:{error:{message:"Failed to decrypt API key: "+t.message,type:"decryption_error"}}}}let n=e.provider.base_url||"https://api.openai.com/v1";n=n.trim().replace(/\/+$/,"");let i=r.path;i&&"/"!==i&&""!==i?i.startsWith("/v1/")?i=i.substring(4):i.startsWith("/")&&(i=i.substring(1)):i="chat/completions",n.endsWith("/v1")||(n+="/v1");let l=`${n}/${i}`;console.log("[OpenAI Adapter] Forwarding request:",{baseUrl:e.provider.base_url,normalizedBaseUrl:n,originalPath:r.path,targetPath:i,url:l,method:r.method,hasApiKey:!!s,apiKeyPrefix:s?s.substring(0,7)+"...":"none",requestBody:r.body?JSON.stringify(r.body).substring(0,200):"none"});let d={"content-type":"application/json"};for(let[e,t]of(d.authorization=`Bearer ${s}`,Object.entries(r.headers))){let r=e.toLowerCase();"host"!==r&&"connection"!==r&&"authorization"!==r&&"x-api-key"!==r&&"content-length"!==r&&"content-type"!==r&&(d[e]=t)}if(console.log("[OpenAI Adapter] Request headers:",{"content-type":d["content-type"],authorization:d.authorization?`Bearer ${s.substring(0,10)}...${s.substring(s.length-4)}`:"none","authorization-full":d.authorization,"user-agent":d["user-agent"]||d["User-Agent"]||"none",allHeaders:Object.keys(d)}),"GET"!==r.method&&"HEAD"!==r.method){let t;t=r.body?{...r.body}:{},e.model_id&&(t.model=e.model_id),console.log("[OpenAI Adapter] Request body:",o=JSON.stringify(t)),console.log("[OpenAI Adapter] Request body length:",o.length)}console.log("[OpenAI Adapter] Sending fetch request:",{url:l.replace(s,"***"),method:r.method,hasBody:!!o,bodyLength:o?.length||0});let p=await fetch(l,{method:r.method,headers:d,body:o});console.log("[OpenAI Adapter] Response received:",{status:p.status,statusText:p.statusText,headers:Object.fromEntries(p.headers.entries())});let u=await p.text();console.log("[OpenAI Adapter] Response body preview:",u.substring(0,200));try{a=JSON.parse(u)}catch{a=u,console.log("[OpenAI Adapter] Response body is not JSON, returning as string")}return{status:p.status,headers:Object.fromEntries(p.headers.entries()),body:a}}async listModels(e){let r=(0,t.decryptApiKey)(e.api_key),s=e.base_url||"https://api.openai.com/v1";(s=s.trim().replace(/\/+$/,"")).endsWith("/v1")||(s=s.endsWith("/")?s+"v1":s+"/v1");let o=`${s}/models`;console.log("[OpenAI] Fetching models:",{baseUrl:e.base_url,normalizedBaseUrl:s,url:o,apiKeyPrefix:r.substring(0,10)+"...",apiKeyLength:r.length});try{let e=await fetch(o,{headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json"}});if(console.log("[OpenAI] Response status:",e.status,e.statusText),!e.ok){let t=await e.text();throw console.error("[OpenAI] Error response body:",t),Error(`Failed to fetch models: ${e.status} ${e.statusText} - ${t.substring(0,200)}`)}let t=await e.json();return console.log("[OpenAI] Fetched models count:",t.data?.length||0),(t.data||[]).map(e=>({id:e.id,name:e.id}))}catch(t){throw console.error("[OpenAI] Error fetching models:",{error:t instanceof Error?t.message:String(t),stack:t instanceof Error?t.stack:void 0,url:o,baseUrl:e.base_url}),t}}}class s{async forwardRequest(e,r){let s,o;console.log("[Anthropic Adapter] Starting forwardRequest:",{modelId:e.model_id,modelName:e.name||"unnamed",providerName:e.provider.name,providerBaseUrl:e.provider.base_url,hasEncryptedApiKey:!!e.provider.api_key,encryptedApiKeyLength:e.provider.api_key?.length||0});try{s=(0,t.decryptApiKey)(e.provider.api_key),console.log("[Anthropic Adapter] API key decrypted successfully, length:",s.length)}catch(e){return console.error("[Anthropic Adapter] Failed to decrypt API key:",e.message),{status:500,headers:{"Content-Type":"application/json"},body:{error:{message:"Failed to decrypt API key",type:"decryption_error"}}}}let a=e.provider.base_url||"https://api.anthropic.com/v1";a=a.trim().replace(/\/+$/,"");let n=r.path;console.log("[Anthropic Adapter] Path processing START:",{inputBaseUrl:e.provider.base_url,originalRequestPath:r.path,hasPath:!!r.path,pathLength:r.path?.length,pathPrefix:r.path?.substring(0,20)}),n&&"/"!==n&&""!==n?n.startsWith("/v1/")?n=n.substring(4):n.startsWith("/")?n=n.substring(1):n.startsWith("v1/")&&(n=n.substring(3)):n="messages";let i=`${a}/${n}`;console.log("[Anthropic Adapter] Path processing result:",{targetPathAfter:n,finalUrl:i}),console.log("[Anthropic Adapter] Forwarding request:",{baseUrl:e.provider.base_url,normalizedBaseUrl:a,originalPath:r.path,targetPath:n,url:i,method:r.method,hasApiKey:!!s,apiKeyPrefix:s?s.substring(0,10)+"...":"none"});let l={"x-api-key":s,Authorization:`Bearer ${s}`,"anthropic-version":"2023-06-01","Content-Type":"application/json",...r.headers};delete l.host,delete l.connection,console.log("[Anthropic Adapter] Request headers:",{"Content-Type":l["Content-Type"],"x-api-key":l["x-api-key"]?`${s.substring(0,10)}...${s.substring(s.length-4)}`:"none",Authorization:l.Authorization?`Bearer ${s.substring(0,10)}...${s.substring(s.length-4)}`:"none","anthropic-version":l["anthropic-version"]});let d=await fetch(i,{method:r.method,headers:l,body:"GET"!==r.method&&"HEAD"!==r.method?JSON.stringify(r.body):void 0});console.log("[Anthropic Adapter] Response status:",d.status,d.statusText);let p=await d.text();console.log("[Anthropic Adapter] Response body preview:",p.substring(0,200));try{o=JSON.parse(p)}catch{o=p,console.log("[Anthropic Adapter] Response body is not JSON, returning as string")}return{status:d.status,headers:Object.fromEntries(d.headers.entries()),body:o}}async listModels(e){return[{id:"claude-3-5-sonnet-20241022",name:"Claude 3.5 Sonnet"},{id:"claude-3-opus-20240229",name:"Claude 3 Opus"},{id:"claude-3-sonnet-20240229",name:"Claude 3 Sonnet"},{id:"claude-3-haiku-20240307",name:"Claude 3 Haiku"}]}}class o{async forwardRequest(e,r){let s,o=(0,t.decryptApiKey)(e.provider.api_key),a=e.provider.base_url||"https://generativelanguage.googleapis.com/v1";a=a.trim().replace(/\/+$/,"");let n=r.path;n&&"/"!==n&&""!==n?n.startsWith("/v1/")?n=n.substring(4):n.startsWith("/")&&(n=n.substring(1)):n=`models/${e.model_id}:generateContent`,a.endsWith("/v1")||(a+="/v1");let i=`${a}/${n}?key=${o}`;console.log("[Gemini Adapter] Forwarding request:",{baseUrl:e.provider.base_url,normalizedBaseUrl:a,originalPath:r.path,targetPath:n,url:i.replace(o,"***"),method:r.method,hasApiKey:!!o});let l={"Content-Type":"application/json",...r.headers};delete l.host,delete l.connection,delete l.authorization,console.log("[Gemini Adapter] Request headers:",{"Content-Type":l["Content-Type"]});let d=await fetch(i,{method:r.method,headers:l,body:"GET"!==r.method&&"HEAD"!==r.method?JSON.stringify(r.body):void 0});console.log("[Gemini Adapter] Response status:",d.status,d.statusText);let p=await d.text();console.log("[Gemini Adapter] Response body preview:",p.substring(0,200));try{s=JSON.parse(p)}catch{s=p,console.log("[Gemini Adapter] Response body is not JSON, returning as string")}return{status:d.status,headers:Object.fromEntries(d.headers.entries()),body:s}}async listModels(e){let r=(0,t.decryptApiKey)(e.api_key),s=e.base_url||"https://generativelanguage.googleapis.com/v1";try{let e=await fetch(`${s}/models?key=${r}`,{headers:{"Content-Type":"application/json"}});if(!e.ok)throw Error(`Failed to fetch models: ${e.statusText}`);let t=await e.json();if(!t.models||!Array.isArray(t.models))return console.error("[Gemini Adapter] Invalid models response:",t),[];return t.models.filter(e=>e&&"object"==typeof e).map(e=>{let t=e.name?e.name.replace("models/",""):"",r=e.displayName||e.name||"";return console.log("[Gemini Adapter] Processing model:",{id:t,name:r}),{id:t,name:r}})}catch(e){throw console.error("Error fetching Gemini models:",e),e}}}function a(e){let t=(e||"").toLowerCase().trim();switch(t){case"openai":return new r;case"anthropic":return new s;case"gemini":return new o;default:throw console.error(`[ProviderAdapter] Unsupported protocol: "${e}", normalized: "${t}"`),Error(`Unsupported protocol: ${e}. Supported protocols: openai, anthropic, gemini`)}}e.s(["getProviderAdapter",()=>a],98857)},17122,e=>{"use strict";var t=e.i(47909),r=e.i(74017),s=e.i(96250),o=e.i(59756),a=e.i(61916),n=e.i(74677),i=e.i(69741),l=e.i(16795),d=e.i(87718),p=e.i(95169),u=e.i(47587),c=e.i(66012),h=e.i(70101),g=e.i(26937),y=e.i(10372),m=e.i(93695);e.i(52474);var A=e.i(220),v=e.i(89171),b=e.i(71560),f=e.i(97731),x=e.i(98857);async function R(e){try{await (0,b.getDatabase)();let{provider_id:t,model_id:r}=await e.json();if(!t||!r)return v.NextResponse.json({error:"Provider ID and Model ID are required"},{status:400});let s=await (0,f.getProviderById)(t);if(!s)return v.NextResponse.json({error:"Provider not found"},{status:404});let o=await (0,f.getModelById)(r);if(!o||o.provider_id!==t)return v.NextResponse.json({error:"Model not found or does not belong to this provider"},{status:404});let a=(0,x.getProviderAdapter)(s.protocol),n=function(e,t){switch(e){case"openai":return{method:"POST",path:"/v1/chat/completions",headers:{"Content-Type":"application/json"},query:{},body:{model:t,messages:[{role:"user",content:"test"}]}};case"anthropic":return{method:"POST",path:"/v1/messages",headers:{"Content-Type":"application/json"},query:{},body:{model:t,messages:[{role:"user",content:"test"}]}};case"gemini":return{method:"POST",path:`/v1/models/${t}:generateContent`,headers:{"Content-Type":"application/json"},query:{},body:{contents:[{parts:[{text:"test"}]}]}};default:throw Error(`Unsupported protocol: ${e}`)}}(s.protocol,o.model_id),i=new Promise((e,t)=>{setTimeout(()=>t(Error("连接超时,请检查网络或稍后重试")),1e4)}),l=a.forwardRequest({...o,provider:s},n),d=await Promise.race([l,i]);if(d.status>=200&&d.status<300)return v.NextResponse.json({success:!0,message:"连接成功,模型可用"});{let e="连接失败";return d.body?.error?.message?e=d.body.error.message:"string"==typeof d.body&&(e=d.body),401===d.status||403===d.status?e="API Key 无效,请检查配置":404===d.status?e="模型不存在或不可用":d.status>=500&&(e="服务器错误,请稍后重试"),v.NextResponse.json({success:!1,error:e,status:d.status},{status:200})}}catch(t){console.error("Test connection error:",{name:t.name,message:t.message,stack:t.stack?.substring(0,500),cause:t.cause,status:t.status});let e="连接失败";return e=t.message.includes("超时")?t.message:t.message.includes("fetch failed")||t.message.includes("ECONNREFUSED")?"无法连接到服务器,请检查 Base URL 和网络连接":t.message.includes("ENOTFOUND")||t.message.includes("DNS")?"DNS 解析失败,请检查 Base URL":t.message.includes("Authorization")||t.message?.toLowerCase().includes("401")?"Authorization header 缺失或无效":t.message||"连接失败,请检查配置",v.NextResponse.json({success:!1,error:e},{status:200})}}e.s(["POST",()=>R,"runtime",0,"nodejs"],42907);var w=e.i(42907);let E=new t.AppRouteRouteModule({definition:{kind:r.RouteKind.APP_ROUTE,page:"/api/providers/test/route",pathname:"/api/providers/test",filename:"route",bundlePath:""},distDir:".next",relativeProjectDir:"",resolvedPagePath:"[project]/src/app/api/providers/test/route.ts",nextConfigOutput:"",userland:w}),{workAsyncStorage:O,workUnitAsyncStorage:C,serverHooks:P}=E;function k(){return(0,s.patchFetch)({workAsyncStorage:O,workUnitAsyncStorage:C})}async function T(e,t,s){E.isDev&&(0,o.addRequestMeta)(e,"devRequestTimingInternalsEnd",process.hrtime.bigint());let v="/api/providers/test/route";v=v.replace(/\/index$/,"")||"/";let b=await E.prepare(e,t,{srcPage:v,multiZoneDraftMode:!1});if(!b)return t.statusCode=400,t.end("Bad Request"),null==s.waitUntil||s.waitUntil.call(s,Promise.resolve()),null;let{buildId:f,params:x,nextConfig:R,parsedUrl:w,isDraftMode:O,prerenderManifest:C,routerServerContext:P,isOnDemandRevalidate:k,revalidateOnlyGenerated:T,resolvedPathname:_,clientReferenceManifest:N,serverActionsManifest:I}=b,j=(0,i.normalizeAppPath)(v),S=!!(C.dynamicRoutes[j]||C.routes[_]),q=async()=>((null==P?void 0:P.render404)?await P.render404(e,t,w,!1):t.end("This page could not be found"),null);if(S&&!O){let e=!!C.routes[_],t=C.dynamicRoutes[j];if(t&&!1===t.fallback&&!e){if(R.experimental.adapterPath)return await q();throw new m.NoFallbackError}}let $=null;!S||E.isDev||O||($="/index"===($=_)?"/":$);let U=!0===E.isDev||!S,K=S&&!U;I&&N&&(0,n.setManifestsSingleton)({page:v,clientReferenceManifest:N,serverActionsManifest:I});let D=e.method||"GET",B=(0,a.getTracer)(),H=B.getActiveScopeSpan(),F={params:x,prerenderManifest:C,renderOpts:{experimental:{authInterrupts:!!R.experimental.authInterrupts},cacheComponents:!!R.cacheComponents,supportsDynamicResponse:U,incrementalCache:(0,o.getRequestMeta)(e,"incrementalCache"),cacheLifeProfiles:R.cacheLife,waitUntil:s.waitUntil,onClose:e=>{t.on("close",e)},onAfterTaskError:void 0,onInstrumentationRequestError:(t,r,s,o)=>E.onRequestError(e,t,s,o,P)},sharedContext:{buildId:f}},z=new l.NodeNextRequest(e),M=new l.NodeNextResponse(t),L=d.NextRequestAdapter.fromNodeNextRequest(z,(0,d.signalFromNodeResponse)(t));try{let n=async e=>E.handle(L,F).finally(()=>{if(!e)return;e.setAttributes({"http.status_code":t.statusCode,"next.rsc":!1});let r=B.getRootSpanAttributes();if(!r)return;if(r.get("next.span_type")!==p.BaseServerSpan.handleRequest)return void console.warn(`Unexpected root span type '${r.get("next.span_type")}'. Please report this Next.js issue https://github.com/vercel/next.js`);let s=r.get("next.route");if(s){let t=`${D} ${s}`;e.setAttributes({"next.route":s,"http.route":s,"next.span_name":t}),e.updateName(t)}else e.updateName(`${D} ${v}`)}),i=!!(0,o.getRequestMeta)(e,"minimalMode"),l=async o=>{var a,l;let d=async({previousCacheEntry:r})=>{try{if(!i&&k&&T&&!r)return t.statusCode=404,t.setHeader("x-nextjs-cache","REVALIDATED"),t.end("This page could not be found"),null;let a=await n(o);e.fetchMetrics=F.renderOpts.fetchMetrics;let l=F.renderOpts.pendingWaitUntil;l&&s.waitUntil&&(s.waitUntil(l),l=void 0);let d=F.renderOpts.collectedTags;if(!S)return await (0,c.sendResponse)(z,M,a,F.renderOpts.pendingWaitUntil),null;{let e=await a.blob(),t=(0,h.toNodeOutgoingHttpHeaders)(a.headers);d&&(t[y.NEXT_CACHE_TAGS_HEADER]=d),!t["content-type"]&&e.type&&(t["content-type"]=e.type);let r=void 0!==F.renderOpts.collectedRevalidate&&!(F.renderOpts.collectedRevalidate>=y.INFINITE_CACHE)&&F.renderOpts.collectedRevalidate,s=void 0===F.renderOpts.collectedExpire||F.renderOpts.collectedExpire>=y.INFINITE_CACHE?void 0:F.renderOpts.collectedExpire;return{value:{kind:A.CachedRouteKind.APP_ROUTE,status:a.status,body:Buffer.from(await e.arrayBuffer()),headers:t},cacheControl:{revalidate:r,expire:s}}}}catch(t){throw(null==r?void 0:r.isStale)&&await E.onRequestError(e,t,{routerKind:"App Router",routePath:v,routeType:"route",revalidateReason:(0,u.getRevalidateReason)({isStaticGeneration:K,isOnDemandRevalidate:k})},!1,P),t}},p=await E.handleResponse({req:e,nextConfig:R,cacheKey:$,routeKind:r.RouteKind.APP_ROUTE,isFallback:!1,prerenderManifest:C,isRoutePPREnabled:!1,isOnDemandRevalidate:k,revalidateOnlyGenerated:T,responseGenerator:d,waitUntil:s.waitUntil,isMinimalMode:i});if(!S)return null;if((null==p||null==(a=p.value)?void 0:a.kind)!==A.CachedRouteKind.APP_ROUTE)throw Object.defineProperty(Error(`Invariant: app-route received invalid cache entry ${null==p||null==(l=p.value)?void 0:l.kind}`),"__NEXT_ERROR_CODE",{value:"E701",enumerable:!1,configurable:!0});i||t.setHeader("x-nextjs-cache",k?"REVALIDATED":p.isMiss?"MISS":p.isStale?"STALE":"HIT"),O&&t.setHeader("Cache-Control","private, no-cache, no-store, max-age=0, must-revalidate");let m=(0,h.fromNodeOutgoingHttpHeaders)(p.value.headers);return i&&S||m.delete(y.NEXT_CACHE_TAGS_HEADER),!p.cacheControl||t.getHeader("Cache-Control")||m.get("Cache-Control")||m.set("Cache-Control",(0,g.getCacheControlHeader)(p.cacheControl)),await (0,c.sendResponse)(z,M,new Response(p.value.body,{headers:m,status:p.value.status||200})),null};H?await l(H):await B.withPropagatedContext(e.headers,()=>B.trace(p.BaseServerSpan.handleRequest,{spanName:`${D} ${v}`,kind:a.SpanKind.SERVER,attributes:{"http.method":D,"http.target":e.url}},l))}catch(t){if(t instanceof m.NoFallbackError||await E.onRequestError(e,t,{routerKind:"App Router",routePath:j,routeType:"route",revalidateReason:(0,u.getRevalidateReason)({isStaticGeneration:K,isOnDemandRevalidate:k})},!1,P),S)throw t;return await (0,c.sendResponse)(z,M,new Response(null,{status:500})),null}}e.s(["handler",()=>T,"patchFetch",()=>k,"routeModule",()=>E,"serverHooks",()=>P,"workAsyncStorage",()=>O,"workUnitAsyncStorage",()=>C],17122)}];
|
|
2
2
|
|
|
3
3
|
//# sourceMappingURL=%5Broot-of-the-server%5D__ccfc7f1d._.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/server/providers/openai.ts","../../../src/server/providers/anthropic.ts","../../../src/server/providers/gemini.ts","../../../src/server/providers/index.ts","../../../src/app/api/providers/test/route.ts","../../../node_modules/next/dist/esm/build/templates/app-route.js"],"sourcesContent":["import type { ProviderAdapter, GatewayRequest, GatewayResponse } from './types';\nimport type { Model, Provider } from '../../db/schema';\nimport { decryptApiKey } from '../../server/crypto';\n\nexport class OpenAIAdapter implements ProviderAdapter {\n async forwardRequest(\n model: Model & { provider: Provider },\n request: GatewayRequest\n ): Promise<GatewayResponse> {\n console.log('[OpenAI Adapter] Starting forwardRequest:', {\n modelId: model.model_id,\n modelName: model.name || 'unnamed',\n providerName: model.provider.name,\n providerBaseUrl: model.provider.base_url,\n hasEncryptedApiKey: !!model.provider.api_key,\n encryptedApiKeyLength: model.provider.api_key?.length || 0,\n });\n \n let apiKey: string;\n try {\n apiKey = decryptApiKey(model.provider.api_key);\n console.log('[OpenAI Adapter] API key decrypted successfully:', {\n length: apiKey.length,\n prefix: apiKey.substring(0, 10) + '...',\n suffix: '...' + apiKey.substring(Math.max(0, apiKey.length - 10)),\n isEmpty: !apiKey || apiKey.trim() === '',\n fullKey: apiKey, // Log full key for debugging (remove in production)\n });\n \n if (!apiKey || apiKey.trim() === '') {\n console.error('[OpenAI Adapter] Decrypted API key is empty!');\n return {\n status: 500,\n headers: { 'Content-Type': 'application/json' },\n body: { error: { message: 'API key is empty after decryption', type: 'decryption_error' } },\n };\n }\n \n // Trim the API key to remove any whitespace\n apiKey = apiKey.trim();\n } catch (error: any) {\n console.error('[OpenAI Adapter] Failed to decrypt API key:', {\n error: error.message,\n stack: error.stack,\n encryptedKeyLength: model.provider.api_key?.length || 0,\n encryptedKeyPrefix: model.provider.api_key?.substring(0, 20) || 'none',\n });\n return {\n status: 500,\n headers: { 'Content-Type': 'application/json' },\n body: { error: { message: 'Failed to decrypt API key: ' + error.message, type: 'decryption_error' } },\n };\n }\n \n let baseUrl = model.provider.base_url || 'https://api.openai.com/v1';\n \n // Normalize baseUrl - ensure it doesn't end with /v1 if we're going to add it\n baseUrl = baseUrl.trim().replace(/\\/+$/, ''); // Remove trailing slashes\n \n // Build the target URL\n let targetPath = request.path;\n \n // If path is root or empty, default to chat/completions endpoint\n if (!targetPath || targetPath === '/' || targetPath === '') {\n targetPath = 'chat/completions';\n } else if (targetPath.startsWith('/v1/')) {\n targetPath = targetPath.substring(4);\n } else if (targetPath.startsWith('/')) {\n targetPath = targetPath.substring(1);\n }\n \n // Ensure baseUrl ends with /v1\n if (!baseUrl.endsWith('/v1')) {\n baseUrl = baseUrl + '/v1';\n }\n \n const url = `${baseUrl}/${targetPath}`;\n \n console.log('[OpenAI Adapter] Forwarding request:', {\n baseUrl: model.provider.base_url,\n normalizedBaseUrl: baseUrl,\n originalPath: request.path,\n targetPath,\n url,\n method: request.method,\n hasApiKey: !!apiKey,\n apiKeyPrefix: apiKey ? apiKey.substring(0, 7) + '...' : 'none',\n requestBody: request.body ? JSON.stringify(request.body).substring(0, 200) : 'none',\n });\n\n // Prepare headers - use lowercase 'authorization' to match curl example\n const headers: Record<string, string> = {\n 'content-type': 'application/json',\n };\n \n // Add Authorization header with the API key (use lowercase key)\n headers['authorization'] = `Bearer ${apiKey}`;\n \n // Merge request headers, but exclude conflicting ones\n for (const [key, value] of Object.entries(request.headers)) {\n const lowerKey = key.toLowerCase();\n // Skip headers that might conflict or are already set\n if (lowerKey !== 'host' && \n lowerKey !== 'connection' && \n lowerKey !== 'authorization' && \n lowerKey !== 'x-api-key' &&\n lowerKey !== 'content-length' &&\n lowerKey !== 'content-type') {\n // Preserve original header key case\n headers[key] = value;\n }\n }\n\n console.log('[OpenAI Adapter] Request headers:', {\n 'content-type': headers['content-type'],\n 'authorization': headers['authorization'] ? `Bearer ${apiKey.substring(0, 10)}...${apiKey.substring(apiKey.length - 4)}` : 'none',\n 'authorization-full': headers['authorization'], // Full header for debugging\n 'user-agent': headers['user-agent'] || headers['User-Agent'] || 'none',\n allHeaders: Object.keys(headers),\n });\n\n // Prepare request body - use the request body as-is, but ensure model is set\n let requestBody: string | undefined;\n if (request.method !== 'GET' && request.method !== 'HEAD') {\n let bodyData: any;\n \n if (request.body) {\n // Use request body if provided\n bodyData = { ...request.body };\n } else {\n // Create default body if not provided\n bodyData = {};\n }\n \n // Ensure model is set to the user-provided model_id\n if (model.model_id) {\n bodyData.model = model.model_id;\n }\n \n requestBody = JSON.stringify(bodyData);\n console.log('[OpenAI Adapter] Request body:', requestBody);\n console.log('[OpenAI Adapter] Request body length:', requestBody.length);\n }\n \n // Make the request\n console.log('[OpenAI Adapter] Sending fetch request:', {\n url: url.replace(apiKey, '***'),\n method: request.method,\n hasBody: !!requestBody,\n bodyLength: requestBody?.length || 0,\n });\n \n const response = await fetch(url, {\n method: request.method,\n headers,\n body: requestBody,\n });\n \n console.log('[OpenAI Adapter] Response received:', {\n status: response.status,\n statusText: response.statusText,\n headers: Object.fromEntries(response.headers.entries()),\n });\n\n const responseBody = await response.text();\n console.log('[OpenAI Adapter] Response body preview:', responseBody.substring(0, 200));\n \n let parsedBody: any;\n try {\n parsedBody = JSON.parse(responseBody);\n } catch {\n parsedBody = responseBody;\n console.log('[OpenAI Adapter] Response body is not JSON, returning as string');\n }\n\n return {\n status: response.status,\n headers: Object.fromEntries(response.headers.entries()),\n body: parsedBody,\n };\n }\n\n async listModels(provider: Provider): Promise<Array<{ id: string; name: string }>> {\n const apiKey = decryptApiKey(provider.api_key);\n let baseUrl = provider.base_url || 'https://api.openai.com/v1';\n \n // Ensure baseUrl doesn't end with / and has /v1\n baseUrl = baseUrl.trim().replace(/\\/+$/, ''); // Remove trailing slashes\n if (!baseUrl.endsWith('/v1')) {\n baseUrl = baseUrl.endsWith('/') ? baseUrl + 'v1' : baseUrl + '/v1';\n }\n \n const url = `${baseUrl}/models`;\n \n console.log('[OpenAI] Fetching models:', {\n baseUrl: provider.base_url,\n normalizedBaseUrl: baseUrl,\n url,\n apiKeyPrefix: apiKey.substring(0, 10) + '...',\n apiKeyLength: apiKey.length,\n });\n\n try {\n const response = await fetch(url, {\n headers: {\n 'Authorization': `Bearer ${apiKey}`,\n 'Content-Type': 'application/json',\n },\n });\n\n console.log('[OpenAI] Response status:', response.status, response.statusText);\n\n if (!response.ok) {\n const errorText = await response.text();\n console.error('[OpenAI] Error response body:', errorText);\n throw new Error(`Failed to fetch models: ${response.status} ${response.statusText} - ${errorText.substring(0, 200)}`);\n }\n\n const data = await response.json();\n console.log('[OpenAI] Fetched models count:', data.data?.length || 0);\n return (data.data || []).map((model: any) => ({\n id: model.id,\n name: model.id, // OpenAI uses model ID as name\n }));\n } catch (error) {\n console.error('[OpenAI] Error fetching models:', {\n error: error instanceof Error ? error.message : String(error),\n stack: error instanceof Error ? error.stack : undefined,\n url,\n baseUrl: provider.base_url,\n });\n throw error;\n }\n }\n}\n","import type { ProviderAdapter, GatewayRequest, GatewayResponse } from './types';\nimport type { Model, Provider } from '../../db/schema';\nimport { decryptApiKey } from '../../server/crypto';\n\nexport class AnthropicAdapter implements ProviderAdapter {\n async forwardRequest(\n model: Model & { provider: Provider },\n request: GatewayRequest\n ): Promise<GatewayResponse> {\n console.log('[Anthropic Adapter] Starting forwardRequest:', {\n modelId: model.model_id,\n modelName: model.name || 'unnamed',\n providerName: model.provider.name,\n providerBaseUrl: model.provider.base_url,\n hasEncryptedApiKey: !!model.provider.api_key,\n encryptedApiKeyLength: model.provider.api_key?.length || 0,\n });\n \n let apiKey: string;\n try {\n apiKey = decryptApiKey(model.provider.api_key);\n console.log('[Anthropic Adapter] API key decrypted successfully, length:', apiKey.length);\n } catch (error: any) {\n console.error('[Anthropic Adapter] Failed to decrypt API key:', error.message);\n return {\n status: 500,\n headers: { 'Content-Type': 'application/json' },\n body: { error: { message: 'Failed to decrypt API key', type: 'decryption_error' } },\n };\n }\n \n let baseUrl = model.provider.base_url || 'https://api.anthropic.com/v1';\n \n // Normalize baseUrl\n baseUrl = baseUrl.trim().replace(/\\/+$/, ''); // Remove trailing slashes\n\n // Build the target URL\n let targetPath = request.path;\n\n console.log('[Anthropic Adapter] Path processing START:', {\n inputBaseUrl: model.provider.base_url,\n originalRequestPath: request.path,\n hasPath: !!request.path,\n pathLength: request.path?.length,\n pathPrefix: request.path?.substring(0, 20),\n });\n\n // If path is root or empty, default to messages endpoint\n if (!targetPath || targetPath === '/' || targetPath === '') {\n targetPath = 'messages';\n } else if (targetPath.startsWith('/v1/')) {\n targetPath = targetPath.substring(4);\n } else if (targetPath.startsWith('/')) {\n targetPath = targetPath.substring(1);\n } else if (targetPath.startsWith('v1/')) {\n // Handle case where path is \"v1/messages\" without leading slash\n targetPath = targetPath.substring(3);\n }\n\n // Don't force /v1 suffix - let each provider's base_url handle the version path\n // For example: zhipu uses /v4, openai uses /v1, etc.\n const url = `${baseUrl}/${targetPath}`;\n\n console.log('[Anthropic Adapter] Path processing result:', {\n targetPathAfter: targetPath,\n finalUrl: url,\n });\n\n console.log('[Anthropic Adapter] Forwarding request:', {\n baseUrl: model.provider.base_url,\n normalizedBaseUrl: baseUrl,\n originalPath: request.path,\n targetPath,\n url,\n method: request.method,\n hasApiKey: !!apiKey,\n apiKeyPrefix: apiKey ? apiKey.substring(0, 10) + '...' : 'none',\n });\n\n // Prepare headers - include both x-api-key and Authorization for compatibility\n const headers: Record<string, string> = {\n 'x-api-key': apiKey,\n 'Authorization': `Bearer ${apiKey}`, // Standard Authorization header for custom gateways\n 'anthropic-version': '2023-06-01',\n 'Content-Type': 'application/json',\n ...request.headers,\n };\n delete headers['host'];\n delete headers['connection'];\n // Don't delete the Authorization header since we're setting it here\n\n console.log('[Anthropic Adapter] Request headers:', {\n 'Content-Type': headers['Content-Type'],\n 'x-api-key': headers['x-api-key'] ? `${apiKey.substring(0, 10)}...${apiKey.substring(apiKey.length - 4)}` : 'none',\n 'Authorization': headers['Authorization'] ? `Bearer ${apiKey.substring(0, 10)}...${apiKey.substring(apiKey.length - 4)}` : 'none',\n 'anthropic-version': headers['anthropic-version'],\n });\n\n // Make the request\n const response = await fetch(url, {\n method: request.method,\n headers,\n body: request.method !== 'GET' && request.method !== 'HEAD' ? JSON.stringify(request.body) : undefined,\n });\n \n console.log('[Anthropic Adapter] Response status:', response.status, response.statusText);\n\n const responseBody = await response.text();\n console.log('[Anthropic Adapter] Response body preview:', responseBody.substring(0, 200));\n \n let parsedBody: any;\n try {\n parsedBody = JSON.parse(responseBody);\n } catch {\n parsedBody = responseBody;\n console.log('[Anthropic Adapter] Response body is not JSON, returning as string');\n }\n\n return {\n status: response.status,\n headers: Object.fromEntries(response.headers.entries()),\n body: parsedBody,\n };\n }\n\n async listModels(provider: Provider): Promise<Array<{ id: string; name: string }>> {\n // Anthropic doesn't have a public models endpoint\n // Return common models\n return [\n { id: 'claude-3-5-sonnet-20241022', name: 'Claude 3.5 Sonnet' },\n { id: 'claude-3-opus-20240229', name: 'Claude 3 Opus' },\n { id: 'claude-3-sonnet-20240229', name: 'Claude 3 Sonnet' },\n { id: 'claude-3-haiku-20240307', name: 'Claude 3 Haiku' },\n ];\n }\n}\n","import type { ProviderAdapter, GatewayRequest, GatewayResponse } from './types';\nimport type { Model, Provider } from '../../db/schema';\nimport { decryptApiKey } from '../../server/crypto';\n\nexport class GeminiAdapter implements ProviderAdapter {\n async forwardRequest(\n model: Model & { provider: Provider },\n request: GatewayRequest\n ): Promise<GatewayResponse> {\n const apiKey = decryptApiKey(model.provider.api_key);\n let baseUrl = model.provider.base_url || 'https://generativelanguage.googleapis.com/v1';\n \n // Normalize baseUrl\n baseUrl = baseUrl.trim().replace(/\\/+$/, ''); // Remove trailing slashes\n \n // Build the target URL\n let targetPath = request.path;\n \n // If path is root or empty, default to generateContent endpoint\n if (!targetPath || targetPath === '/' || targetPath === '') {\n // Gemini uses model-specific endpoints: models/{model_id}:generateContent\n targetPath = `models/${model.model_id}:generateContent`;\n } else if (targetPath.startsWith('/v1/')) {\n targetPath = targetPath.substring(4);\n } else if (targetPath.startsWith('/')) {\n targetPath = targetPath.substring(1);\n }\n \n // Ensure baseUrl ends with /v1\n if (!baseUrl.endsWith('/v1')) {\n baseUrl = baseUrl + '/v1';\n }\n \n // Add API key to query params for Gemini\n const url = `${baseUrl}/${targetPath}?key=${apiKey}`;\n \n console.log('[Gemini Adapter] Forwarding request:', {\n baseUrl: model.provider.base_url,\n normalizedBaseUrl: baseUrl,\n originalPath: request.path,\n targetPath,\n url: url.replace(apiKey, '***'),\n method: request.method,\n hasApiKey: !!apiKey,\n });\n\n // Prepare headers\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n ...request.headers,\n };\n delete headers['host'];\n delete headers['connection'];\n delete headers['authorization'];\n\n console.log('[Gemini Adapter] Request headers:', {\n 'Content-Type': headers['Content-Type'],\n });\n\n // Make the request\n const response = await fetch(url, {\n method: request.method,\n headers,\n body: request.method !== 'GET' && request.method !== 'HEAD' ? JSON.stringify(request.body) : undefined,\n });\n \n console.log('[Gemini Adapter] Response status:', response.status, response.statusText);\n\n const responseBody = await response.text();\n console.log('[Gemini Adapter] Response body preview:', responseBody.substring(0, 200));\n \n let parsedBody: any;\n try {\n parsedBody = JSON.parse(responseBody);\n } catch {\n parsedBody = responseBody;\n console.log('[Gemini Adapter] Response body is not JSON, returning as string');\n }\n\n return {\n status: response.status,\n headers: Object.fromEntries(response.headers.entries()),\n body: parsedBody,\n };\n }\n\n async listModels(provider: Provider): Promise<Array<{ id: string; name: string }>> {\n const apiKey = decryptApiKey(provider.api_key);\n const baseUrl = provider.base_url || 'https://generativelanguage.googleapis.com/v1';\n\n try {\n const response = await fetch(`${baseUrl}/models?key=${apiKey}`, {\n headers: {\n 'Content-Type': 'application/json',\n },\n });\n\n if (!response.ok) {\n throw new Error(`Failed to fetch models: ${response.statusText}`);\n }\n\n const data = await response.json();\n\n if (!data.models || !Array.isArray(data.models)) {\n console.error('[Gemini Adapter] Invalid models response:', data);\n return [];\n }\n\n return data.models\n .filter((model: any) => model && typeof model === 'object')\n .map((model: any) => {\n const id = model.name ? model.name.replace('models/', '') : '';\n const name = model.displayName || model.name || '';\n console.log('[Gemini Adapter] Processing model:', { id, name });\n return { id, name };\n });\n } catch (error) {\n console.error('Error fetching Gemini models:', error);\n throw error;\n }\n }\n}\n","import type { ProviderAdapter } from './types';\nimport { OpenAIAdapter } from './openai';\nimport { AnthropicAdapter } from './anthropic';\nimport { GeminiAdapter } from './gemini';\n\nexport function getProviderAdapter(protocol: string): ProviderAdapter {\n const normalizedProtocol = (protocol || '').toLowerCase().trim();\n\n switch (normalizedProtocol) {\n case 'openai':\n return new OpenAIAdapter();\n case 'anthropic':\n return new AnthropicAdapter();\n case 'gemini':\n return new GeminiAdapter();\n default:\n console.error(`[ProviderAdapter] Unsupported protocol: \"${protocol}\", normalized: \"${normalizedProtocol}\"`);\n throw new Error(`Unsupported protocol: ${protocol}. Supported protocols: openai, anthropic, gemini`);\n }\n}\n\nexport { OpenAIAdapter, AnthropicAdapter, GeminiAdapter };\nexport type { ProviderAdapter } from './types';\n","import { NextRequest, NextResponse } from 'next/server';\nimport { getDatabase } from '@/db/database';\nimport { getProviderById, getModelById } from '@/db/queries';\nimport { getProviderAdapter } from '@/server/providers';\nimport type { GatewayRequest } from '@/server/providers/types';\n\n// Ensure Node.js runtime (required for SQLite)\nexport const runtime = 'nodejs';\n\nexport async function POST(request: NextRequest) {\n try {\n getDatabase();\n const body = await request.json();\n const { provider_id, model_id } = body;\n\n if (!provider_id || !model_id) {\n return NextResponse.json(\n { error: 'Provider ID and Model ID are required' },\n { status: 400 }\n );\n }\n\n // Get provider and model\n const provider = await getProviderById(provider_id);\n if (!provider) {\n return NextResponse.json(\n { error: 'Provider not found' },\n { status: 404 }\n );\n }\n\n const model = await getModelById(model_id);\n if (!model || model.provider_id !== provider_id) {\n return NextResponse.json(\n { error: 'Model not found or does not belong to this provider' },\n { status: 404 }\n );\n }\n\n // Get provider adapter\n const adapter = getProviderAdapter(provider.protocol);\n\n // Create a test request based on protocol\n const testRequest = createTestRequest(provider.protocol, model.model_id);\n\n // Send test request with timeout\n const timeoutPromise = new Promise((_, reject) => {\n setTimeout(() => reject(new Error('连接超时,请检查网络或稍后重试')), 10000);\n });\n\n const testPromise = adapter.forwardRequest(\n { ...model, provider } as any,\n testRequest\n );\n\n const response = await Promise.race([testPromise, timeoutPromise]) as any;\n\n // Check response status\n if (response.status >= 200 && response.status < 300) {\n return NextResponse.json({\n success: true,\n message: '连接成功,模型可用',\n });\n } else {\n // Parse error message\n let errorMessage = '连接失败';\n if (response.body?.error?.message) {\n errorMessage = response.body.error.message;\n } else if (typeof response.body === 'string') {\n errorMessage = response.body;\n }\n\n // Map common error codes to friendly messages\n if (response.status === 401 || response.status === 403) {\n errorMessage = 'API Key 无效,请检查配置';\n } else if (response.status === 404) {\n errorMessage = '模型不存在或不可用';\n } else if (response.status >= 500) {\n errorMessage = '服务器错误,请稍后重试';\n }\n\n return NextResponse.json(\n {\n success: false,\n error: errorMessage,\n status: response.status,\n },\n { status: 200 } // Return 200 so frontend can handle the error\n );\n }\n } catch (error: any) {\n console.error('Test connection error:', {\n name: error.name,\n message: error.message,\n stack: error.stack?.substring(0, 500),\n cause: error.cause,\n status: error.status,\n });\n\n // Handle specific error types\n let errorMessage = '连接失败';\n if (error.message.includes('超时')) {\n errorMessage = error.message;\n } else if (error.message.includes('fetch failed') || error.message.includes('ECONNREFUSED')) {\n errorMessage = '无法连接到服务器,请检查 Base URL 和网络连接';\n } else if (error.message.includes('ENOTFOUND') || error.message.includes('DNS')) {\n errorMessage = 'DNS 解析失败,请检查 Base URL';\n } else if (error.message.includes('Authorization') || error.message?.toLowerCase().includes('401')) {\n errorMessage = 'Authorization header 缺失或无效';\n } else {\n errorMessage = error.message || '连接失败,请检查配置';\n }\n\n return NextResponse.json(\n {\n success: false,\n error: errorMessage,\n },\n { status: 200 } // Return 200 so frontend can handle the error\n );\n }\n}\n\nfunction createTestRequest(protocol: string, modelId: string): GatewayRequest {\n switch (protocol) {\n case 'openai':\n return {\n method: 'POST',\n path: '/v1/chat/completions',\n headers: {\n 'Content-Type': 'application/json',\n },\n query: {},\n body: {\n model: modelId,\n messages: [\n {\n role: 'user',\n content: 'test',\n },\n ],\n // max_tokens: 5,\n },\n };\n\n case 'anthropic':\n return {\n method: 'POST',\n path: '/v1/messages',\n headers: {\n 'Content-Type': 'application/json',\n },\n query: {},\n body: {\n model: modelId,\n // max_tokens: 5,\n messages: [\n {\n role: 'user',\n content: 'test',\n },\n ],\n },\n };\n\n case 'gemini':\n return {\n method: 'POST',\n path: `/v1/models/${modelId}:generateContent`,\n headers: {\n 'Content-Type': 'application/json',\n },\n query: {},\n body: {\n contents: [\n {\n parts: [\n {\n text: 'test',\n },\n ],\n },\n ],\n },\n };\n\n default:\n throw new Error(`Unsupported protocol: ${protocol}`);\n }\n}\n","import { AppRouteRouteModule } from \"next/dist/esm/server/route-modules/app-route/module.compiled\";\nimport { RouteKind } from \"next/dist/esm/server/route-kind\";\nimport { patchFetch as _patchFetch } from \"next/dist/esm/server/lib/patch-fetch\";\nimport { addRequestMeta, getRequestMeta } from \"next/dist/esm/server/request-meta\";\nimport { getTracer, SpanKind } from \"next/dist/esm/server/lib/trace/tracer\";\nimport { setManifestsSingleton } from \"next/dist/esm/server/app-render/manifests-singleton\";\nimport { normalizeAppPath } from \"next/dist/esm/shared/lib/router/utils/app-paths\";\nimport { NodeNextRequest, NodeNextResponse } from \"next/dist/esm/server/base-http/node\";\nimport { NextRequestAdapter, signalFromNodeResponse } from \"next/dist/esm/server/web/spec-extension/adapters/next-request\";\nimport { BaseServerSpan } from \"next/dist/esm/server/lib/trace/constants\";\nimport { getRevalidateReason } from \"next/dist/esm/server/instrumentation/utils\";\nimport { sendResponse } from \"next/dist/esm/server/send-response\";\nimport { fromNodeOutgoingHttpHeaders, toNodeOutgoingHttpHeaders } from \"next/dist/esm/server/web/utils\";\nimport { getCacheControlHeader } from \"next/dist/esm/server/lib/cache-control\";\nimport { INFINITE_CACHE, NEXT_CACHE_TAGS_HEADER } from \"next/dist/esm/lib/constants\";\nimport { NoFallbackError } from \"next/dist/esm/shared/lib/no-fallback-error.external\";\nimport { CachedRouteKind } from \"next/dist/esm/server/response-cache\";\nimport * as userland from \"INNER_APP_ROUTE\";\n// We inject the nextConfigOutput here so that we can use them in the route\n// module.\nconst nextConfigOutput = \"\"\nconst routeModule = new AppRouteRouteModule({\n definition: {\n kind: RouteKind.APP_ROUTE,\n page: \"/api/providers/test/route\",\n pathname: \"/api/providers/test\",\n filename: \"route\",\n bundlePath: \"\"\n },\n distDir: process.env.__NEXT_RELATIVE_DIST_DIR || '',\n relativeProjectDir: process.env.__NEXT_RELATIVE_PROJECT_DIR || '',\n resolvedPagePath: \"[project]/src/app/api/providers/test/route.ts\",\n nextConfigOutput,\n userland\n});\n// Pull out the exports that we need to expose from the module. This should\n// be eliminated when we've moved the other routes to the new format. These\n// are used to hook into the route.\nconst { workAsyncStorage, workUnitAsyncStorage, serverHooks } = routeModule;\nfunction patchFetch() {\n return _patchFetch({\n workAsyncStorage,\n workUnitAsyncStorage\n });\n}\nexport { routeModule, workAsyncStorage, workUnitAsyncStorage, serverHooks, patchFetch, };\nexport async function handler(req, res, ctx) {\n if (routeModule.isDev) {\n addRequestMeta(req, 'devRequestTimingInternalsEnd', process.hrtime.bigint());\n }\n let srcPage = \"/api/providers/test/route\";\n // turbopack doesn't normalize `/index` in the page name\n // so we need to to process dynamic routes properly\n // TODO: fix turbopack providing differing value from webpack\n if (process.env.TURBOPACK) {\n srcPage = srcPage.replace(/\\/index$/, '') || '/';\n } else if (srcPage === '/index') {\n // we always normalize /index specifically\n srcPage = '/';\n }\n const multiZoneDraftMode = process.env.__NEXT_MULTI_ZONE_DRAFT_MODE;\n const prepareResult = await routeModule.prepare(req, res, {\n srcPage,\n multiZoneDraftMode\n });\n if (!prepareResult) {\n res.statusCode = 400;\n res.end('Bad Request');\n ctx.waitUntil == null ? void 0 : ctx.waitUntil.call(ctx, Promise.resolve());\n return null;\n }\n const { buildId, params, nextConfig, parsedUrl, isDraftMode, prerenderManifest, routerServerContext, isOnDemandRevalidate, revalidateOnlyGenerated, resolvedPathname, clientReferenceManifest, serverActionsManifest } = prepareResult;\n const normalizedSrcPage = normalizeAppPath(srcPage);\n let isIsr = Boolean(prerenderManifest.dynamicRoutes[normalizedSrcPage] || prerenderManifest.routes[resolvedPathname]);\n const render404 = async ()=>{\n // TODO: should route-module itself handle rendering the 404\n if (routerServerContext == null ? void 0 : routerServerContext.render404) {\n await routerServerContext.render404(req, res, parsedUrl, false);\n } else {\n res.end('This page could not be found');\n }\n return null;\n };\n if (isIsr && !isDraftMode) {\n const isPrerendered = Boolean(prerenderManifest.routes[resolvedPathname]);\n const prerenderInfo = prerenderManifest.dynamicRoutes[normalizedSrcPage];\n if (prerenderInfo) {\n if (prerenderInfo.fallback === false && !isPrerendered) {\n if (nextConfig.experimental.adapterPath) {\n return await render404();\n }\n throw new NoFallbackError();\n }\n }\n }\n let cacheKey = null;\n if (isIsr && !routeModule.isDev && !isDraftMode) {\n cacheKey = resolvedPathname;\n // ensure /index and / is normalized to one key\n cacheKey = cacheKey === '/index' ? '/' : cacheKey;\n }\n const supportsDynamicResponse = // If we're in development, we always support dynamic HTML\n routeModule.isDev === true || // If this is not SSG or does not have static paths, then it supports\n // dynamic HTML.\n !isIsr;\n // This is a revalidation request if the request is for a static\n // page and it is not being resumed from a postponed render and\n // it is not a dynamic RSC request then it is a revalidation\n // request.\n const isStaticGeneration = isIsr && !supportsDynamicResponse;\n // Before rendering (which initializes component tree modules), we have to\n // set the reference manifests to our global store so Server Action's\n // encryption util can access to them at the top level of the page module.\n if (serverActionsManifest && clientReferenceManifest) {\n setManifestsSingleton({\n page: srcPage,\n clientReferenceManifest,\n serverActionsManifest\n });\n }\n const method = req.method || 'GET';\n const tracer = getTracer();\n const activeSpan = tracer.getActiveScopeSpan();\n const context = {\n params,\n prerenderManifest,\n renderOpts: {\n experimental: {\n authInterrupts: Boolean(nextConfig.experimental.authInterrupts)\n },\n cacheComponents: Boolean(nextConfig.cacheComponents),\n supportsDynamicResponse,\n incrementalCache: getRequestMeta(req, 'incrementalCache'),\n cacheLifeProfiles: nextConfig.cacheLife,\n waitUntil: ctx.waitUntil,\n onClose: (cb)=>{\n res.on('close', cb);\n },\n onAfterTaskError: undefined,\n onInstrumentationRequestError: (error, _request, errorContext, silenceLog)=>routeModule.onRequestError(req, error, errorContext, silenceLog, routerServerContext)\n },\n sharedContext: {\n buildId\n }\n };\n const nodeNextReq = new NodeNextRequest(req);\n const nodeNextRes = new NodeNextResponse(res);\n const nextReq = NextRequestAdapter.fromNodeNextRequest(nodeNextReq, signalFromNodeResponse(res));\n try {\n const invokeRouteModule = async (span)=>{\n return routeModule.handle(nextReq, context).finally(()=>{\n if (!span) return;\n span.setAttributes({\n 'http.status_code': res.statusCode,\n 'next.rsc': false\n });\n const rootSpanAttributes = tracer.getRootSpanAttributes();\n // We were unable to get attributes, probably OTEL is not enabled\n if (!rootSpanAttributes) {\n return;\n }\n if (rootSpanAttributes.get('next.span_type') !== BaseServerSpan.handleRequest) {\n console.warn(`Unexpected root span type '${rootSpanAttributes.get('next.span_type')}'. Please report this Next.js issue https://github.com/vercel/next.js`);\n return;\n }\n const route = rootSpanAttributes.get('next.route');\n if (route) {\n const name = `${method} ${route}`;\n span.setAttributes({\n 'next.route': route,\n 'http.route': route,\n 'next.span_name': name\n });\n span.updateName(name);\n } else {\n span.updateName(`${method} ${srcPage}`);\n }\n });\n };\n const isMinimalMode = Boolean(process.env.MINIMAL_MODE || getRequestMeta(req, 'minimalMode'));\n const handleResponse = async (currentSpan)=>{\n var _cacheEntry_value;\n const responseGenerator = async ({ previousCacheEntry })=>{\n try {\n if (!isMinimalMode && isOnDemandRevalidate && revalidateOnlyGenerated && !previousCacheEntry) {\n res.statusCode = 404;\n // on-demand revalidate always sets this header\n res.setHeader('x-nextjs-cache', 'REVALIDATED');\n res.end('This page could not be found');\n return null;\n }\n const response = await invokeRouteModule(currentSpan);\n req.fetchMetrics = context.renderOpts.fetchMetrics;\n let pendingWaitUntil = context.renderOpts.pendingWaitUntil;\n // Attempt using provided waitUntil if available\n // if it's not we fallback to sendResponse's handling\n if (pendingWaitUntil) {\n if (ctx.waitUntil) {\n ctx.waitUntil(pendingWaitUntil);\n pendingWaitUntil = undefined;\n }\n }\n const cacheTags = context.renderOpts.collectedTags;\n // If the request is for a static response, we can cache it so long\n // as it's not edge.\n if (isIsr) {\n const blob = await response.blob();\n // Copy the headers from the response.\n const headers = toNodeOutgoingHttpHeaders(response.headers);\n if (cacheTags) {\n headers[NEXT_CACHE_TAGS_HEADER] = cacheTags;\n }\n if (!headers['content-type'] && blob.type) {\n headers['content-type'] = blob.type;\n }\n const revalidate = typeof context.renderOpts.collectedRevalidate === 'undefined' || context.renderOpts.collectedRevalidate >= INFINITE_CACHE ? false : context.renderOpts.collectedRevalidate;\n const expire = typeof context.renderOpts.collectedExpire === 'undefined' || context.renderOpts.collectedExpire >= INFINITE_CACHE ? undefined : context.renderOpts.collectedExpire;\n // Create the cache entry for the response.\n const cacheEntry = {\n value: {\n kind: CachedRouteKind.APP_ROUTE,\n status: response.status,\n body: Buffer.from(await blob.arrayBuffer()),\n headers\n },\n cacheControl: {\n revalidate,\n expire\n }\n };\n return cacheEntry;\n } else {\n // send response without caching if not ISR\n await sendResponse(nodeNextReq, nodeNextRes, response, context.renderOpts.pendingWaitUntil);\n return null;\n }\n } catch (err) {\n // if this is a background revalidate we need to report\n // the request error here as it won't be bubbled\n if (previousCacheEntry == null ? void 0 : previousCacheEntry.isStale) {\n const silenceLog = false;\n await routeModule.onRequestError(req, err, {\n routerKind: 'App Router',\n routePath: srcPage,\n routeType: 'route',\n revalidateReason: getRevalidateReason({\n isStaticGeneration,\n isOnDemandRevalidate\n })\n }, silenceLog, routerServerContext);\n }\n throw err;\n }\n };\n const cacheEntry = await routeModule.handleResponse({\n req,\n nextConfig,\n cacheKey,\n routeKind: RouteKind.APP_ROUTE,\n isFallback: false,\n prerenderManifest,\n isRoutePPREnabled: false,\n isOnDemandRevalidate,\n revalidateOnlyGenerated,\n responseGenerator,\n waitUntil: ctx.waitUntil,\n isMinimalMode\n });\n // we don't create a cacheEntry for ISR\n if (!isIsr) {\n return null;\n }\n if ((cacheEntry == null ? void 0 : (_cacheEntry_value = cacheEntry.value) == null ? void 0 : _cacheEntry_value.kind) !== CachedRouteKind.APP_ROUTE) {\n var _cacheEntry_value1;\n throw Object.defineProperty(new Error(`Invariant: app-route received invalid cache entry ${cacheEntry == null ? void 0 : (_cacheEntry_value1 = cacheEntry.value) == null ? void 0 : _cacheEntry_value1.kind}`), \"__NEXT_ERROR_CODE\", {\n value: \"E701\",\n enumerable: false,\n configurable: true\n });\n }\n if (!isMinimalMode) {\n res.setHeader('x-nextjs-cache', isOnDemandRevalidate ? 'REVALIDATED' : cacheEntry.isMiss ? 'MISS' : cacheEntry.isStale ? 'STALE' : 'HIT');\n }\n // Draft mode should never be cached\n if (isDraftMode) {\n res.setHeader('Cache-Control', 'private, no-cache, no-store, max-age=0, must-revalidate');\n }\n const headers = fromNodeOutgoingHttpHeaders(cacheEntry.value.headers);\n if (!(isMinimalMode && isIsr)) {\n headers.delete(NEXT_CACHE_TAGS_HEADER);\n }\n // If cache control is already set on the response we don't\n // override it to allow users to customize it via next.config\n if (cacheEntry.cacheControl && !res.getHeader('Cache-Control') && !headers.get('Cache-Control')) {\n headers.set('Cache-Control', getCacheControlHeader(cacheEntry.cacheControl));\n }\n await sendResponse(nodeNextReq, nodeNextRes, // @ts-expect-error - Argument of type 'Buffer<ArrayBufferLike>' is not assignable to parameter of type 'BodyInit | null | undefined'.\n new Response(cacheEntry.value.body, {\n headers,\n status: cacheEntry.value.status || 200\n }));\n return null;\n };\n // TODO: activeSpan code path is for when wrapped by\n // next-server can be removed when this is no longer used\n if (activeSpan) {\n await handleResponse(activeSpan);\n } else {\n await tracer.withPropagatedContext(req.headers, ()=>tracer.trace(BaseServerSpan.handleRequest, {\n spanName: `${method} ${srcPage}`,\n kind: SpanKind.SERVER,\n attributes: {\n 'http.method': method,\n 'http.target': req.url\n }\n }, handleResponse));\n }\n } catch (err) {\n if (!(err instanceof NoFallbackError)) {\n const silenceLog = false;\n await routeModule.onRequestError(req, err, {\n routerKind: 'App Router',\n routePath: normalizedSrcPage,\n routeType: 'route',\n revalidateReason: getRevalidateReason({\n isStaticGeneration,\n isOnDemandRevalidate\n })\n }, silenceLog, routerServerContext);\n }\n // rethrow so that we can handle serving error page\n // If this is during static generation, throw the error again.\n if (isIsr) throw err;\n // Otherwise, send a 500 response.\n await sendResponse(nodeNextReq, nodeNextRes, new Response(null, {\n status: 500\n }));\n return null;\n }\n}\n\n//# sourceMappingURL=app-route.js.map\n"],"names":[],"mappings":"8iCAEA,IAAA,EAAA,EAAA,CAAA,CAAA,MAEO,OAAM,EACX,MAAM,eACJ,CAAqC,CACrC,CAAuB,CACG,KAUtB,EAwGA,EA6CA,EA9JJ,QAAQ,GAAG,CAAC,4CAA6C,CACvD,QAAS,EAAM,QAAQ,CACvB,UAAW,EAAM,IAAI,EAAI,UACzB,aAAc,EAAM,QAAQ,CAAC,IAAI,CACjC,gBAAiB,EAAM,QAAQ,CAAC,QAAQ,CACxC,mBAAoB,CAAC,CAAC,EAAM,QAAQ,CAAC,OAAO,CAC5C,sBAAuB,EAAM,QAAQ,CAAC,OAAO,EAAE,QAAU,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AAC,EAAI,OAAO,CAAE,IAAI,EAAO,KAAK,CAAC,EAAA,cAAc,CAAC,aAAa,CAAE,CACvF,SAAU,CAAA,EAAG,EAAO,CAAC,EAAE,EAAA,CAAS,CAChC,KAAM,EAAA,QAAQ,CAAC,MAAM,CACrB,WAAY,CACR,cAAe,EACf,cAAe,EAAI,GAAG,AAC1B,CACJ,EAAG,GAEf,CAAE,MAAO,EAAK,CAeV,GAdM,aAAe,EAAA,eAAe,EAEhC,CAFmC,KAE7B,EAAY,cAAc,CAAC,EAAK,EAAK,CACvC,WAAY,aACZ,UAAW,EACX,UAAW,QACX,iBAAkB,CAAA,EAAA,EAAA,mBAAA,AAAmB,EAAC,CAClC,0CACA,CACJ,EACJ,GAAG,AATgB,EASJ,GAIf,EAAO,MAAM,EAKjB,OAHA,MAAM,CAAA,EAAA,EAAA,YAAA,AAAY,EAAC,EAAa,EAAa,IAAI,SAAS,KAAM,CAC5D,OAAQ,GACZ,IACO,IACX,CACJ,EAEA,qCAAqC","ignoreList":[5]}
|
|
1
|
+
{"version":3,"sources":["../../../src/server/providers/openai.ts","../../../src/server/providers/anthropic.ts","../../../src/server/providers/gemini.ts","../../../src/server/providers/index.ts","../../../src/app/api/providers/test/route.ts","../../../node_modules/next/dist/esm/build/templates/app-route.js"],"sourcesContent":["import type { ProviderAdapter, GatewayRequest, GatewayResponse } from './types';\nimport type { Model, Provider } from '../../db/schema';\nimport { decryptApiKey } from '../../server/crypto';\n\nexport class OpenAIAdapter implements ProviderAdapter {\n async forwardRequest(\n model: Model & { provider: Provider },\n request: GatewayRequest\n ): Promise<GatewayResponse> {\n console.log('[OpenAI Adapter] Starting forwardRequest:', {\n modelId: model.model_id,\n modelName: model.name || 'unnamed',\n providerName: model.provider.name,\n providerBaseUrl: model.provider.base_url,\n hasEncryptedApiKey: !!model.provider.api_key,\n encryptedApiKeyLength: model.provider.api_key?.length || 0,\n });\n \n let apiKey: string;\n try {\n apiKey = decryptApiKey(model.provider.api_key);\n console.log('[OpenAI Adapter] API key decrypted successfully:', {\n length: apiKey.length,\n prefix: apiKey.substring(0, 10) + '...',\n suffix: '...' + apiKey.substring(Math.max(0, apiKey.length - 10)),\n isEmpty: !apiKey || apiKey.trim() === '',\n fullKey: apiKey, // Log full key for debugging (remove in production)\n });\n \n if (!apiKey || apiKey.trim() === '') {\n console.error('[OpenAI Adapter] Decrypted API key is empty!');\n return {\n status: 500,\n headers: { 'Content-Type': 'application/json' },\n body: { error: { message: 'API key is empty after decryption', type: 'decryption_error' } },\n };\n }\n \n // Trim the API key to remove any whitespace\n apiKey = apiKey.trim();\n } catch (error: any) {\n console.error('[OpenAI Adapter] Failed to decrypt API key:', {\n error: error.message,\n stack: error.stack,\n encryptedKeyLength: model.provider.api_key?.length || 0,\n encryptedKeyPrefix: model.provider.api_key?.substring(0, 20) || 'none',\n });\n return {\n status: 500,\n headers: { 'Content-Type': 'application/json' },\n body: { error: { message: 'Failed to decrypt API key: ' + error.message, type: 'decryption_error' } },\n };\n }\n \n let baseUrl = model.provider.base_url || 'https://api.openai.com/v1';\n \n // Normalize baseUrl - ensure it doesn't end with /v1 if we're going to add it\n baseUrl = baseUrl.trim().replace(/\\/+$/, ''); // Remove trailing slashes\n \n // Build the target URL\n let targetPath = request.path;\n \n // If path is root or empty, default to chat/completions endpoint\n if (!targetPath || targetPath === '/' || targetPath === '') {\n targetPath = 'chat/completions';\n } else if (targetPath.startsWith('/v1/')) {\n targetPath = targetPath.substring(4);\n } else if (targetPath.startsWith('/')) {\n targetPath = targetPath.substring(1);\n }\n \n // Ensure baseUrl ends with /v1\n if (!baseUrl.endsWith('/v1')) {\n baseUrl = baseUrl + '/v1';\n }\n \n const url = `${baseUrl}/${targetPath}`;\n \n console.log('[OpenAI Adapter] Forwarding request:', {\n baseUrl: model.provider.base_url,\n normalizedBaseUrl: baseUrl,\n originalPath: request.path,\n targetPath,\n url,\n method: request.method,\n hasApiKey: !!apiKey,\n apiKeyPrefix: apiKey ? apiKey.substring(0, 7) + '...' : 'none',\n requestBody: request.body ? JSON.stringify(request.body).substring(0, 200) : 'none',\n });\n\n // Prepare headers - use lowercase 'authorization' to match curl example\n const headers: Record<string, string> = {\n 'content-type': 'application/json',\n };\n \n // Add Authorization header with the API key (use lowercase key)\n headers['authorization'] = `Bearer ${apiKey}`;\n \n // Merge request headers, but exclude conflicting ones\n for (const [key, value] of Object.entries(request.headers)) {\n const lowerKey = key.toLowerCase();\n // Skip headers that might conflict or are already set\n if (lowerKey !== 'host' && \n lowerKey !== 'connection' && \n lowerKey !== 'authorization' && \n lowerKey !== 'x-api-key' &&\n lowerKey !== 'content-length' &&\n lowerKey !== 'content-type') {\n // Preserve original header key case\n headers[key] = value;\n }\n }\n\n console.log('[OpenAI Adapter] Request headers:', {\n 'content-type': headers['content-type'],\n 'authorization': headers['authorization'] ? `Bearer ${apiKey.substring(0, 10)}...${apiKey.substring(apiKey.length - 4)}` : 'none',\n 'authorization-full': headers['authorization'], // Full header for debugging\n 'user-agent': headers['user-agent'] || headers['User-Agent'] || 'none',\n allHeaders: Object.keys(headers),\n });\n\n // Prepare request body - use the request body as-is, but ensure model is set\n let requestBody: string | undefined;\n if (request.method !== 'GET' && request.method !== 'HEAD') {\n let bodyData: any;\n \n if (request.body) {\n // Use request body if provided\n bodyData = { ...request.body };\n } else {\n // Create default body if not provided\n bodyData = {};\n }\n \n // Ensure model is set to the user-provided model_id\n if (model.model_id) {\n bodyData.model = model.model_id;\n }\n \n requestBody = JSON.stringify(bodyData);\n console.log('[OpenAI Adapter] Request body:', requestBody);\n console.log('[OpenAI Adapter] Request body length:', requestBody.length);\n }\n \n // Make the request\n console.log('[OpenAI Adapter] Sending fetch request:', {\n url: url.replace(apiKey, '***'),\n method: request.method,\n hasBody: !!requestBody,\n bodyLength: requestBody?.length || 0,\n });\n \n const response = await fetch(url, {\n method: request.method,\n headers,\n body: requestBody,\n });\n \n console.log('[OpenAI Adapter] Response received:', {\n status: response.status,\n statusText: response.statusText,\n headers: Object.fromEntries(response.headers.entries()),\n });\n\n const responseBody = await response.text();\n console.log('[OpenAI Adapter] Response body preview:', responseBody.substring(0, 200));\n \n let parsedBody: any;\n try {\n parsedBody = JSON.parse(responseBody);\n } catch {\n parsedBody = responseBody;\n console.log('[OpenAI Adapter] Response body is not JSON, returning as string');\n }\n\n return {\n status: response.status,\n headers: Object.fromEntries(response.headers.entries()),\n body: parsedBody,\n };\n }\n\n async listModels(provider: Provider): Promise<Array<{ id: string; name: string }>> {\n const apiKey = decryptApiKey(provider.api_key);\n let baseUrl = provider.base_url || 'https://api.openai.com/v1';\n \n // Ensure baseUrl doesn't end with / and has /v1\n baseUrl = baseUrl.trim().replace(/\\/+$/, ''); // Remove trailing slashes\n if (!baseUrl.endsWith('/v1')) {\n baseUrl = baseUrl.endsWith('/') ? baseUrl + 'v1' : baseUrl + '/v1';\n }\n \n const url = `${baseUrl}/models`;\n \n console.log('[OpenAI] Fetching models:', {\n baseUrl: provider.base_url,\n normalizedBaseUrl: baseUrl,\n url,\n apiKeyPrefix: apiKey.substring(0, 10) + '...',\n apiKeyLength: apiKey.length,\n });\n\n try {\n const response = await fetch(url, {\n headers: {\n 'Authorization': `Bearer ${apiKey}`,\n 'Content-Type': 'application/json',\n },\n });\n\n console.log('[OpenAI] Response status:', response.status, response.statusText);\n\n if (!response.ok) {\n const errorText = await response.text();\n console.error('[OpenAI] Error response body:', errorText);\n throw new Error(`Failed to fetch models: ${response.status} ${response.statusText} - ${errorText.substring(0, 200)}`);\n }\n\n const data = await response.json();\n console.log('[OpenAI] Fetched models count:', data.data?.length || 0);\n return (data.data || []).map((model: any) => ({\n id: model.id,\n name: model.id, // OpenAI uses model ID as name\n }));\n } catch (error) {\n console.error('[OpenAI] Error fetching models:', {\n error: error instanceof Error ? error.message : String(error),\n stack: error instanceof Error ? error.stack : undefined,\n url,\n baseUrl: provider.base_url,\n });\n throw error;\n }\n }\n}\n","import type { ProviderAdapter, GatewayRequest, GatewayResponse } from './types';\nimport type { Model, Provider } from '../../db/schema';\nimport { decryptApiKey } from '../../server/crypto';\n\nexport class AnthropicAdapter implements ProviderAdapter {\n async forwardRequest(\n model: Model & { provider: Provider },\n request: GatewayRequest\n ): Promise<GatewayResponse> {\n console.log('[Anthropic Adapter] Starting forwardRequest:', {\n modelId: model.model_id,\n modelName: model.name || 'unnamed',\n providerName: model.provider.name,\n providerBaseUrl: model.provider.base_url,\n hasEncryptedApiKey: !!model.provider.api_key,\n encryptedApiKeyLength: model.provider.api_key?.length || 0,\n });\n \n let apiKey: string;\n try {\n apiKey = decryptApiKey(model.provider.api_key);\n console.log('[Anthropic Adapter] API key decrypted successfully, length:', apiKey.length);\n } catch (error: any) {\n console.error('[Anthropic Adapter] Failed to decrypt API key:', error.message);\n return {\n status: 500,\n headers: { 'Content-Type': 'application/json' },\n body: { error: { message: 'Failed to decrypt API key', type: 'decryption_error' } },\n };\n }\n \n let baseUrl = model.provider.base_url || 'https://api.anthropic.com/v1';\n \n // Normalize baseUrl\n baseUrl = baseUrl.trim().replace(/\\/+$/, ''); // Remove trailing slashes\n\n // Build the target URL\n let targetPath = request.path;\n\n console.log('[Anthropic Adapter] Path processing START:', {\n inputBaseUrl: model.provider.base_url,\n originalRequestPath: request.path,\n hasPath: !!request.path,\n pathLength: request.path?.length,\n pathPrefix: request.path?.substring(0, 20),\n });\n\n // If path is root or empty, default to messages endpoint\n if (!targetPath || targetPath === '/' || targetPath === '') {\n targetPath = 'messages';\n } else if (targetPath.startsWith('/v1/')) {\n targetPath = targetPath.substring(4);\n } else if (targetPath.startsWith('/')) {\n targetPath = targetPath.substring(1);\n } else if (targetPath.startsWith('v1/')) {\n // Handle case where path is \"v1/messages\" without leading slash\n targetPath = targetPath.substring(3);\n }\n\n // Don't force /v1 suffix - let each provider's base_url handle the version path\n // For example: zhipu uses /v4, openai uses /v1, etc.\n const url = `${baseUrl}/${targetPath}`;\n\n console.log('[Anthropic Adapter] Path processing result:', {\n targetPathAfter: targetPath,\n finalUrl: url,\n });\n\n console.log('[Anthropic Adapter] Forwarding request:', {\n baseUrl: model.provider.base_url,\n normalizedBaseUrl: baseUrl,\n originalPath: request.path,\n targetPath,\n url,\n method: request.method,\n hasApiKey: !!apiKey,\n apiKeyPrefix: apiKey ? apiKey.substring(0, 10) + '...' : 'none',\n });\n\n // Prepare headers - include both x-api-key and Authorization for compatibility\n const headers: Record<string, string> = {\n 'x-api-key': apiKey,\n 'Authorization': `Bearer ${apiKey}`, // Standard Authorization header for custom gateways\n 'anthropic-version': '2023-06-01',\n 'Content-Type': 'application/json',\n ...request.headers,\n };\n delete headers['host'];\n delete headers['connection'];\n // Don't delete the Authorization header since we're setting it here\n\n console.log('[Anthropic Adapter] Request headers:', {\n 'Content-Type': headers['Content-Type'],\n 'x-api-key': headers['x-api-key'] ? `${apiKey.substring(0, 10)}...${apiKey.substring(apiKey.length - 4)}` : 'none',\n 'Authorization': headers['Authorization'] ? `Bearer ${apiKey.substring(0, 10)}...${apiKey.substring(apiKey.length - 4)}` : 'none',\n 'anthropic-version': headers['anthropic-version'],\n });\n\n // Make the request\n const response = await fetch(url, {\n method: request.method,\n headers,\n body: request.method !== 'GET' && request.method !== 'HEAD' ? JSON.stringify(request.body) : undefined,\n });\n \n console.log('[Anthropic Adapter] Response status:', response.status, response.statusText);\n\n const responseBody = await response.text();\n console.log('[Anthropic Adapter] Response body preview:', responseBody.substring(0, 200));\n \n let parsedBody: any;\n try {\n parsedBody = JSON.parse(responseBody);\n } catch {\n parsedBody = responseBody;\n console.log('[Anthropic Adapter] Response body is not JSON, returning as string');\n }\n\n return {\n status: response.status,\n headers: Object.fromEntries(response.headers.entries()),\n body: parsedBody,\n };\n }\n\n async listModels(provider: Provider): Promise<Array<{ id: string; name: string }>> {\n // Anthropic doesn't have a public models endpoint\n // Return common models\n return [\n { id: 'claude-3-5-sonnet-20241022', name: 'Claude 3.5 Sonnet' },\n { id: 'claude-3-opus-20240229', name: 'Claude 3 Opus' },\n { id: 'claude-3-sonnet-20240229', name: 'Claude 3 Sonnet' },\n { id: 'claude-3-haiku-20240307', name: 'Claude 3 Haiku' },\n ];\n }\n}\n","import type { ProviderAdapter, GatewayRequest, GatewayResponse } from './types';\nimport type { Model, Provider } from '../../db/schema';\nimport { decryptApiKey } from '../../server/crypto';\n\nexport class GeminiAdapter implements ProviderAdapter {\n async forwardRequest(\n model: Model & { provider: Provider },\n request: GatewayRequest\n ): Promise<GatewayResponse> {\n const apiKey = decryptApiKey(model.provider.api_key);\n let baseUrl = model.provider.base_url || 'https://generativelanguage.googleapis.com/v1';\n \n // Normalize baseUrl\n baseUrl = baseUrl.trim().replace(/\\/+$/, ''); // Remove trailing slashes\n \n // Build the target URL\n let targetPath = request.path;\n \n // If path is root or empty, default to generateContent endpoint\n if (!targetPath || targetPath === '/' || targetPath === '') {\n // Gemini uses model-specific endpoints: models/{model_id}:generateContent\n targetPath = `models/${model.model_id}:generateContent`;\n } else if (targetPath.startsWith('/v1/')) {\n targetPath = targetPath.substring(4);\n } else if (targetPath.startsWith('/')) {\n targetPath = targetPath.substring(1);\n }\n \n // Ensure baseUrl ends with /v1\n if (!baseUrl.endsWith('/v1')) {\n baseUrl = baseUrl + '/v1';\n }\n \n // Add API key to query params for Gemini\n const url = `${baseUrl}/${targetPath}?key=${apiKey}`;\n \n console.log('[Gemini Adapter] Forwarding request:', {\n baseUrl: model.provider.base_url,\n normalizedBaseUrl: baseUrl,\n originalPath: request.path,\n targetPath,\n url: url.replace(apiKey, '***'),\n method: request.method,\n hasApiKey: !!apiKey,\n });\n\n // Prepare headers\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n ...request.headers,\n };\n delete headers['host'];\n delete headers['connection'];\n delete headers['authorization'];\n\n console.log('[Gemini Adapter] Request headers:', {\n 'Content-Type': headers['Content-Type'],\n });\n\n // Make the request\n const response = await fetch(url, {\n method: request.method,\n headers,\n body: request.method !== 'GET' && request.method !== 'HEAD' ? JSON.stringify(request.body) : undefined,\n });\n \n console.log('[Gemini Adapter] Response status:', response.status, response.statusText);\n\n const responseBody = await response.text();\n console.log('[Gemini Adapter] Response body preview:', responseBody.substring(0, 200));\n \n let parsedBody: any;\n try {\n parsedBody = JSON.parse(responseBody);\n } catch {\n parsedBody = responseBody;\n console.log('[Gemini Adapter] Response body is not JSON, returning as string');\n }\n\n return {\n status: response.status,\n headers: Object.fromEntries(response.headers.entries()),\n body: parsedBody,\n };\n }\n\n async listModels(provider: Provider): Promise<Array<{ id: string; name: string }>> {\n const apiKey = decryptApiKey(provider.api_key);\n const baseUrl = provider.base_url || 'https://generativelanguage.googleapis.com/v1';\n\n try {\n const response = await fetch(`${baseUrl}/models?key=${apiKey}`, {\n headers: {\n 'Content-Type': 'application/json',\n },\n });\n\n if (!response.ok) {\n throw new Error(`Failed to fetch models: ${response.statusText}`);\n }\n\n const data = await response.json();\n\n if (!data.models || !Array.isArray(data.models)) {\n console.error('[Gemini Adapter] Invalid models response:', data);\n return [];\n }\n\n return data.models\n .filter((model: any) => model && typeof model === 'object')\n .map((model: any) => {\n const id = model.name ? model.name.replace('models/', '') : '';\n const name = model.displayName || model.name || '';\n console.log('[Gemini Adapter] Processing model:', { id, name });\n return { id, name };\n });\n } catch (error) {\n console.error('Error fetching Gemini models:', error);\n throw error;\n }\n }\n}\n","import type { ProviderAdapter } from './types';\nimport { OpenAIAdapter } from './openai';\nimport { AnthropicAdapter } from './anthropic';\nimport { GeminiAdapter } from './gemini';\n\nexport function getProviderAdapter(protocol: string): ProviderAdapter {\n const normalizedProtocol = (protocol || '').toLowerCase().trim();\n\n switch (normalizedProtocol) {\n case 'openai':\n return new OpenAIAdapter();\n case 'anthropic':\n return new AnthropicAdapter();\n case 'gemini':\n return new GeminiAdapter();\n default:\n console.error(`[ProviderAdapter] Unsupported protocol: \"${protocol}\", normalized: \"${normalizedProtocol}\"`);\n throw new Error(`Unsupported protocol: ${protocol}. Supported protocols: openai, anthropic, gemini`);\n }\n}\n\nexport { OpenAIAdapter, AnthropicAdapter, GeminiAdapter };\nexport type { ProviderAdapter } from './types';\n","import { NextRequest, NextResponse } from 'next/server';\nimport { getDatabase } from '@/db/database';\nimport { getProviderById, getModelById } from '@/db/queries';\nimport { getProviderAdapter } from '@/server/providers';\nimport type { GatewayRequest } from '@/server/providers/types';\n\n// Ensure Node.js runtime (required for SQLite)\nexport const runtime = 'nodejs';\n\nexport async function POST(request: NextRequest) {\n try {\n await getDatabase();\n const body = await request.json();\n const { provider_id, model_id } = body;\n\n if (!provider_id || !model_id) {\n return NextResponse.json(\n { error: 'Provider ID and Model ID are required' },\n { status: 400 }\n );\n }\n\n // Get provider and model\n const provider = await getProviderById(provider_id);\n if (!provider) {\n return NextResponse.json(\n { error: 'Provider not found' },\n { status: 404 }\n );\n }\n\n const model = await getModelById(model_id);\n if (!model || model.provider_id !== provider_id) {\n return NextResponse.json(\n { error: 'Model not found or does not belong to this provider' },\n { status: 404 }\n );\n }\n\n // Get provider adapter\n const adapter = getProviderAdapter(provider.protocol);\n\n // Create a test request based on protocol\n const testRequest = createTestRequest(provider.protocol, model.model_id);\n\n // Send test request with timeout\n const timeoutPromise = new Promise((_, reject) => {\n setTimeout(() => reject(new Error('连接超时,请检查网络或稍后重试')), 10000);\n });\n\n const testPromise = adapter.forwardRequest(\n { ...model, provider } as any,\n testRequest\n );\n\n const response = await Promise.race([testPromise, timeoutPromise]) as any;\n\n // Check response status\n if (response.status >= 200 && response.status < 300) {\n return NextResponse.json({\n success: true,\n message: '连接成功,模型可用',\n });\n } else {\n // Parse error message\n let errorMessage = '连接失败';\n if (response.body?.error?.message) {\n errorMessage = response.body.error.message;\n } else if (typeof response.body === 'string') {\n errorMessage = response.body;\n }\n\n // Map common error codes to friendly messages\n if (response.status === 401 || response.status === 403) {\n errorMessage = 'API Key 无效,请检查配置';\n } else if (response.status === 404) {\n errorMessage = '模型不存在或不可用';\n } else if (response.status >= 500) {\n errorMessage = '服务器错误,请稍后重试';\n }\n\n return NextResponse.json(\n {\n success: false,\n error: errorMessage,\n status: response.status,\n },\n { status: 200 } // Return 200 so frontend can handle the error\n );\n }\n } catch (error: any) {\n console.error('Test connection error:', {\n name: error.name,\n message: error.message,\n stack: error.stack?.substring(0, 500),\n cause: error.cause,\n status: error.status,\n });\n\n // Handle specific error types\n let errorMessage = '连接失败';\n if (error.message.includes('超时')) {\n errorMessage = error.message;\n } else if (error.message.includes('fetch failed') || error.message.includes('ECONNREFUSED')) {\n errorMessage = '无法连接到服务器,请检查 Base URL 和网络连接';\n } else if (error.message.includes('ENOTFOUND') || error.message.includes('DNS')) {\n errorMessage = 'DNS 解析失败,请检查 Base URL';\n } else if (error.message.includes('Authorization') || error.message?.toLowerCase().includes('401')) {\n errorMessage = 'Authorization header 缺失或无效';\n } else {\n errorMessage = error.message || '连接失败,请检查配置';\n }\n\n return NextResponse.json(\n {\n success: false,\n error: errorMessage,\n },\n { status: 200 } // Return 200 so frontend can handle the error\n );\n }\n}\n\nfunction createTestRequest(protocol: string, modelId: string): GatewayRequest {\n switch (protocol) {\n case 'openai':\n return {\n method: 'POST',\n path: '/v1/chat/completions',\n headers: {\n 'Content-Type': 'application/json',\n },\n query: {},\n body: {\n model: modelId,\n messages: [\n {\n role: 'user',\n content: 'test',\n },\n ],\n // max_tokens: 5,\n },\n };\n\n case 'anthropic':\n return {\n method: 'POST',\n path: '/v1/messages',\n headers: {\n 'Content-Type': 'application/json',\n },\n query: {},\n body: {\n model: modelId,\n // max_tokens: 5,\n messages: [\n {\n role: 'user',\n content: 'test',\n },\n ],\n },\n };\n\n case 'gemini':\n return {\n method: 'POST',\n path: `/v1/models/${modelId}:generateContent`,\n headers: {\n 'Content-Type': 'application/json',\n },\n query: {},\n body: {\n contents: [\n {\n parts: [\n {\n text: 'test',\n },\n ],\n },\n ],\n },\n };\n\n default:\n throw new Error(`Unsupported protocol: ${protocol}`);\n }\n}\n","import { AppRouteRouteModule } from \"next/dist/esm/server/route-modules/app-route/module.compiled\";\nimport { RouteKind } from \"next/dist/esm/server/route-kind\";\nimport { patchFetch as _patchFetch } from \"next/dist/esm/server/lib/patch-fetch\";\nimport { addRequestMeta, getRequestMeta } from \"next/dist/esm/server/request-meta\";\nimport { getTracer, SpanKind } from \"next/dist/esm/server/lib/trace/tracer\";\nimport { setManifestsSingleton } from \"next/dist/esm/server/app-render/manifests-singleton\";\nimport { normalizeAppPath } from \"next/dist/esm/shared/lib/router/utils/app-paths\";\nimport { NodeNextRequest, NodeNextResponse } from \"next/dist/esm/server/base-http/node\";\nimport { NextRequestAdapter, signalFromNodeResponse } from \"next/dist/esm/server/web/spec-extension/adapters/next-request\";\nimport { BaseServerSpan } from \"next/dist/esm/server/lib/trace/constants\";\nimport { getRevalidateReason } from \"next/dist/esm/server/instrumentation/utils\";\nimport { sendResponse } from \"next/dist/esm/server/send-response\";\nimport { fromNodeOutgoingHttpHeaders, toNodeOutgoingHttpHeaders } from \"next/dist/esm/server/web/utils\";\nimport { getCacheControlHeader } from \"next/dist/esm/server/lib/cache-control\";\nimport { INFINITE_CACHE, NEXT_CACHE_TAGS_HEADER } from \"next/dist/esm/lib/constants\";\nimport { NoFallbackError } from \"next/dist/esm/shared/lib/no-fallback-error.external\";\nimport { CachedRouteKind } from \"next/dist/esm/server/response-cache\";\nimport * as userland from \"INNER_APP_ROUTE\";\n// We inject the nextConfigOutput here so that we can use them in the route\n// module.\nconst nextConfigOutput = \"\"\nconst routeModule = new AppRouteRouteModule({\n definition: {\n kind: RouteKind.APP_ROUTE,\n page: \"/api/providers/test/route\",\n pathname: \"/api/providers/test\",\n filename: \"route\",\n bundlePath: \"\"\n },\n distDir: process.env.__NEXT_RELATIVE_DIST_DIR || '',\n relativeProjectDir: process.env.__NEXT_RELATIVE_PROJECT_DIR || '',\n resolvedPagePath: \"[project]/src/app/api/providers/test/route.ts\",\n nextConfigOutput,\n userland\n});\n// Pull out the exports that we need to expose from the module. This should\n// be eliminated when we've moved the other routes to the new format. These\n// are used to hook into the route.\nconst { workAsyncStorage, workUnitAsyncStorage, serverHooks } = routeModule;\nfunction patchFetch() {\n return _patchFetch({\n workAsyncStorage,\n workUnitAsyncStorage\n });\n}\nexport { routeModule, workAsyncStorage, workUnitAsyncStorage, serverHooks, patchFetch, };\nexport async function handler(req, res, ctx) {\n if (routeModule.isDev) {\n addRequestMeta(req, 'devRequestTimingInternalsEnd', process.hrtime.bigint());\n }\n let srcPage = \"/api/providers/test/route\";\n // turbopack doesn't normalize `/index` in the page name\n // so we need to to process dynamic routes properly\n // TODO: fix turbopack providing differing value from webpack\n if (process.env.TURBOPACK) {\n srcPage = srcPage.replace(/\\/index$/, '') || '/';\n } else if (srcPage === '/index') {\n // we always normalize /index specifically\n srcPage = '/';\n }\n const multiZoneDraftMode = process.env.__NEXT_MULTI_ZONE_DRAFT_MODE;\n const prepareResult = await routeModule.prepare(req, res, {\n srcPage,\n multiZoneDraftMode\n });\n if (!prepareResult) {\n res.statusCode = 400;\n res.end('Bad Request');\n ctx.waitUntil == null ? void 0 : ctx.waitUntil.call(ctx, Promise.resolve());\n return null;\n }\n const { buildId, params, nextConfig, parsedUrl, isDraftMode, prerenderManifest, routerServerContext, isOnDemandRevalidate, revalidateOnlyGenerated, resolvedPathname, clientReferenceManifest, serverActionsManifest } = prepareResult;\n const normalizedSrcPage = normalizeAppPath(srcPage);\n let isIsr = Boolean(prerenderManifest.dynamicRoutes[normalizedSrcPage] || prerenderManifest.routes[resolvedPathname]);\n const render404 = async ()=>{\n // TODO: should route-module itself handle rendering the 404\n if (routerServerContext == null ? void 0 : routerServerContext.render404) {\n await routerServerContext.render404(req, res, parsedUrl, false);\n } else {\n res.end('This page could not be found');\n }\n return null;\n };\n if (isIsr && !isDraftMode) {\n const isPrerendered = Boolean(prerenderManifest.routes[resolvedPathname]);\n const prerenderInfo = prerenderManifest.dynamicRoutes[normalizedSrcPage];\n if (prerenderInfo) {\n if (prerenderInfo.fallback === false && !isPrerendered) {\n if (nextConfig.experimental.adapterPath) {\n return await render404();\n }\n throw new NoFallbackError();\n }\n }\n }\n let cacheKey = null;\n if (isIsr && !routeModule.isDev && !isDraftMode) {\n cacheKey = resolvedPathname;\n // ensure /index and / is normalized to one key\n cacheKey = cacheKey === '/index' ? '/' : cacheKey;\n }\n const supportsDynamicResponse = // If we're in development, we always support dynamic HTML\n routeModule.isDev === true || // If this is not SSG or does not have static paths, then it supports\n // dynamic HTML.\n !isIsr;\n // This is a revalidation request if the request is for a static\n // page and it is not being resumed from a postponed render and\n // it is not a dynamic RSC request then it is a revalidation\n // request.\n const isStaticGeneration = isIsr && !supportsDynamicResponse;\n // Before rendering (which initializes component tree modules), we have to\n // set the reference manifests to our global store so Server Action's\n // encryption util can access to them at the top level of the page module.\n if (serverActionsManifest && clientReferenceManifest) {\n setManifestsSingleton({\n page: srcPage,\n clientReferenceManifest,\n serverActionsManifest\n });\n }\n const method = req.method || 'GET';\n const tracer = getTracer();\n const activeSpan = tracer.getActiveScopeSpan();\n const context = {\n params,\n prerenderManifest,\n renderOpts: {\n experimental: {\n authInterrupts: Boolean(nextConfig.experimental.authInterrupts)\n },\n cacheComponents: Boolean(nextConfig.cacheComponents),\n supportsDynamicResponse,\n incrementalCache: getRequestMeta(req, 'incrementalCache'),\n cacheLifeProfiles: nextConfig.cacheLife,\n waitUntil: ctx.waitUntil,\n onClose: (cb)=>{\n res.on('close', cb);\n },\n onAfterTaskError: undefined,\n onInstrumentationRequestError: (error, _request, errorContext, silenceLog)=>routeModule.onRequestError(req, error, errorContext, silenceLog, routerServerContext)\n },\n sharedContext: {\n buildId\n }\n };\n const nodeNextReq = new NodeNextRequest(req);\n const nodeNextRes = new NodeNextResponse(res);\n const nextReq = NextRequestAdapter.fromNodeNextRequest(nodeNextReq, signalFromNodeResponse(res));\n try {\n const invokeRouteModule = async (span)=>{\n return routeModule.handle(nextReq, context).finally(()=>{\n if (!span) return;\n span.setAttributes({\n 'http.status_code': res.statusCode,\n 'next.rsc': false\n });\n const rootSpanAttributes = tracer.getRootSpanAttributes();\n // We were unable to get attributes, probably OTEL is not enabled\n if (!rootSpanAttributes) {\n return;\n }\n if (rootSpanAttributes.get('next.span_type') !== BaseServerSpan.handleRequest) {\n console.warn(`Unexpected root span type '${rootSpanAttributes.get('next.span_type')}'. Please report this Next.js issue https://github.com/vercel/next.js`);\n return;\n }\n const route = rootSpanAttributes.get('next.route');\n if (route) {\n const name = `${method} ${route}`;\n span.setAttributes({\n 'next.route': route,\n 'http.route': route,\n 'next.span_name': name\n });\n span.updateName(name);\n } else {\n span.updateName(`${method} ${srcPage}`);\n }\n });\n };\n const isMinimalMode = Boolean(process.env.MINIMAL_MODE || getRequestMeta(req, 'minimalMode'));\n const handleResponse = async (currentSpan)=>{\n var _cacheEntry_value;\n const responseGenerator = async ({ previousCacheEntry })=>{\n try {\n if (!isMinimalMode && isOnDemandRevalidate && revalidateOnlyGenerated && !previousCacheEntry) {\n res.statusCode = 404;\n // on-demand revalidate always sets this header\n res.setHeader('x-nextjs-cache', 'REVALIDATED');\n res.end('This page could not be found');\n return null;\n }\n const response = await invokeRouteModule(currentSpan);\n req.fetchMetrics = context.renderOpts.fetchMetrics;\n let pendingWaitUntil = context.renderOpts.pendingWaitUntil;\n // Attempt using provided waitUntil if available\n // if it's not we fallback to sendResponse's handling\n if (pendingWaitUntil) {\n if (ctx.waitUntil) {\n ctx.waitUntil(pendingWaitUntil);\n pendingWaitUntil = undefined;\n }\n }\n const cacheTags = context.renderOpts.collectedTags;\n // If the request is for a static response, we can cache it so long\n // as it's not edge.\n if (isIsr) {\n const blob = await response.blob();\n // Copy the headers from the response.\n const headers = toNodeOutgoingHttpHeaders(response.headers);\n if (cacheTags) {\n headers[NEXT_CACHE_TAGS_HEADER] = cacheTags;\n }\n if (!headers['content-type'] && blob.type) {\n headers['content-type'] = blob.type;\n }\n const revalidate = typeof context.renderOpts.collectedRevalidate === 'undefined' || context.renderOpts.collectedRevalidate >= INFINITE_CACHE ? false : context.renderOpts.collectedRevalidate;\n const expire = typeof context.renderOpts.collectedExpire === 'undefined' || context.renderOpts.collectedExpire >= INFINITE_CACHE ? undefined : context.renderOpts.collectedExpire;\n // Create the cache entry for the response.\n const cacheEntry = {\n value: {\n kind: CachedRouteKind.APP_ROUTE,\n status: response.status,\n body: Buffer.from(await blob.arrayBuffer()),\n headers\n },\n cacheControl: {\n revalidate,\n expire\n }\n };\n return cacheEntry;\n } else {\n // send response without caching if not ISR\n await sendResponse(nodeNextReq, nodeNextRes, response, context.renderOpts.pendingWaitUntil);\n return null;\n }\n } catch (err) {\n // if this is a background revalidate we need to report\n // the request error here as it won't be bubbled\n if (previousCacheEntry == null ? void 0 : previousCacheEntry.isStale) {\n const silenceLog = false;\n await routeModule.onRequestError(req, err, {\n routerKind: 'App Router',\n routePath: srcPage,\n routeType: 'route',\n revalidateReason: getRevalidateReason({\n isStaticGeneration,\n isOnDemandRevalidate\n })\n }, silenceLog, routerServerContext);\n }\n throw err;\n }\n };\n const cacheEntry = await routeModule.handleResponse({\n req,\n nextConfig,\n cacheKey,\n routeKind: RouteKind.APP_ROUTE,\n isFallback: false,\n prerenderManifest,\n isRoutePPREnabled: false,\n isOnDemandRevalidate,\n revalidateOnlyGenerated,\n responseGenerator,\n waitUntil: ctx.waitUntil,\n isMinimalMode\n });\n // we don't create a cacheEntry for ISR\n if (!isIsr) {\n return null;\n }\n if ((cacheEntry == null ? void 0 : (_cacheEntry_value = cacheEntry.value) == null ? void 0 : _cacheEntry_value.kind) !== CachedRouteKind.APP_ROUTE) {\n var _cacheEntry_value1;\n throw Object.defineProperty(new Error(`Invariant: app-route received invalid cache entry ${cacheEntry == null ? void 0 : (_cacheEntry_value1 = cacheEntry.value) == null ? void 0 : _cacheEntry_value1.kind}`), \"__NEXT_ERROR_CODE\", {\n value: \"E701\",\n enumerable: false,\n configurable: true\n });\n }\n if (!isMinimalMode) {\n res.setHeader('x-nextjs-cache', isOnDemandRevalidate ? 'REVALIDATED' : cacheEntry.isMiss ? 'MISS' : cacheEntry.isStale ? 'STALE' : 'HIT');\n }\n // Draft mode should never be cached\n if (isDraftMode) {\n res.setHeader('Cache-Control', 'private, no-cache, no-store, max-age=0, must-revalidate');\n }\n const headers = fromNodeOutgoingHttpHeaders(cacheEntry.value.headers);\n if (!(isMinimalMode && isIsr)) {\n headers.delete(NEXT_CACHE_TAGS_HEADER);\n }\n // If cache control is already set on the response we don't\n // override it to allow users to customize it via next.config\n if (cacheEntry.cacheControl && !res.getHeader('Cache-Control') && !headers.get('Cache-Control')) {\n headers.set('Cache-Control', getCacheControlHeader(cacheEntry.cacheControl));\n }\n await sendResponse(nodeNextReq, nodeNextRes, // @ts-expect-error - Argument of type 'Buffer<ArrayBufferLike>' is not assignable to parameter of type 'BodyInit | null | undefined'.\n new Response(cacheEntry.value.body, {\n headers,\n status: cacheEntry.value.status || 200\n }));\n return null;\n };\n // TODO: activeSpan code path is for when wrapped by\n // next-server can be removed when this is no longer used\n if (activeSpan) {\n await handleResponse(activeSpan);\n } else {\n await tracer.withPropagatedContext(req.headers, ()=>tracer.trace(BaseServerSpan.handleRequest, {\n spanName: `${method} ${srcPage}`,\n kind: SpanKind.SERVER,\n attributes: {\n 'http.method': method,\n 'http.target': req.url\n }\n }, handleResponse));\n }\n } catch (err) {\n if (!(err instanceof NoFallbackError)) {\n const silenceLog = false;\n await routeModule.onRequestError(req, err, {\n routerKind: 'App Router',\n routePath: normalizedSrcPage,\n routeType: 'route',\n revalidateReason: getRevalidateReason({\n isStaticGeneration,\n isOnDemandRevalidate\n })\n }, silenceLog, routerServerContext);\n }\n // rethrow so that we can handle serving error page\n // If this is during static generation, throw the error again.\n if (isIsr) throw err;\n // Otherwise, send a 500 response.\n await sendResponse(nodeNextReq, nodeNextRes, new Response(null, {\n status: 500\n }));\n return null;\n }\n}\n\n//# sourceMappingURL=app-route.js.map\n"],"names":[],"mappings":"8iCAEA,IAAA,EAAA,EAAA,CAAA,CAAA,MAEO,OAAM,EACX,MAAM,eACJ,CAAqC,CACrC,CAAuB,CACG,KAUtB,EAwGA,EA6CA,EA9JJ,QAAQ,GAAG,CAAC,4CAA6C,CACvD,QAAS,EAAM,QAAQ,CACvB,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AAA,EAAA,YAAA,AAAY,EAAC,EAAa,EAChC,IAAI,SAAS,EAAW,KAAK,CAAC,IAAI,CAAE,SAChC,EACA,OAAQ,EAAW,KAAK,CAAC,MAAM,EAAI,GACvC,IACO,IACX,EAGI,EACA,MAAM,EAAe,EADT,CAGZ,MAAM,EAAO,qBAAqB,CAAC,EAAI,OAAO,CAAE,IAAI,EAAO,KAAK,CAAC,EAAA,cAAc,CAAC,aAAa,CAAE,CACvF,SAAU,CAAA,EAAG,EAAO,CAAC,EAAE,EAAA,CAAS,CAChC,KAAM,EAAA,QAAQ,CAAC,MAAM,CACrB,WAAY,CACR,cAAe,EACf,cAAe,EAAI,GAAG,AAC1B,CACJ,EAAG,GAEf,CAAE,MAAO,EAAK,CAeV,GAdM,aAAe,EAAA,eAAe,EAEhC,CAFmC,KAE7B,EAAY,cAAc,CAAC,EAAK,EAAK,CACvC,WAAY,aACZ,UAAW,EACX,UAAW,QACX,iBAAkB,CAAA,EAAA,EAAA,mBAAA,AAAmB,EAAC,oBAClC,uBACA,CACJ,EACJ,GAAG,AATgB,EASJ,GAIf,EAAO,MAAM,EAKjB,OAHA,MAAM,CAAA,EAAA,EAAA,YAAA,AAAY,EAAC,EAAa,EAAa,IAAI,SAAS,KAAM,CAC5D,OAAQ,GACZ,IACO,IACX,CACJ,EAEA,qCAAqC","ignoreList":[5]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
module.exports=[82602,a=>{"use strict";var b=a.i(87924),c=a.i(72131),d=a.i(81844),e=a.i(21215),f=a.i(71862);function g(){let[a,g]=(0,c.useState)([]),[h,i]=(0,c.useState)(null),[j,k]=(0,c.useState)(!0),[l,m]=(0,c.useState)(0),[n,o]=(0,c.useState)(0),[p,q]=(0,c.useState)([]),[r,s]=(0,c.useState)(!1),[t,u]=(0,c.useState)(null),[v,w]=(0,c.useState)(""),[x,y]=(0,c.useState)(""),{showToast:z}=(0,e.useToast)(),A=async a=>{try{await navigator.clipboard.writeText(a),z("已复制到剪贴板","success")}catch{z("复制失败,请手动复制","error")}},B=async()=>{0!==p.length&&u({open:!0,title:"删除确认",message:`确定要删除选中的 ${p.length} 条日志吗?`,onConfirm:async()=>{try{let a=await fetch(`/api/logs?ids=${p.join(",")}`,{method:"DELETE"}),b=await a.json();a.ok?(q([]),s(!1),D(),z("删除成功","success"),u(null)):z("删除失败:"+(b.error||"未知错误"),"error")}catch(a){console.error("Failed to delete logs:",a),z("删除失败","error")}}})},C=async()=>{u({open:!0,title:"清空日志",message:"确定要清空所有日志吗?此操作不可恢复!",onConfirm:async()=>{try{let a=await fetch("/api/logs?clear_all=true",{method:"DELETE"}),b=await a.json();a.ok?(m(0),q([]),s(!1),D(),z("清空成功","success"),u(null)):z("清空失败:"+(b.error||"未知错误"),"error")}catch(a){console.error("Failed to clear logs:",a),z("清空失败","error")}}})},D=async a=>{try{k(!0);let b=new URLSearchParams({limit:"50",offset:(50*l).toString()});a&&b.set("search",a);let c=await fetch(`/api/logs?${b.toString()}`),d=await c.json();g(d.logs||[]),o(d.total||0)}catch(a){console.error("Failed to load logs:",a),z("加载日志失败","error")}finally{k(!1)}},E=()=>{w(x),m(0),D(x)};(0,c.useEffect)(()=>{D()},[l,50]);let F=a=>"string"==typeof a?a:JSON.stringify(a),G=a=>I(a)?H(a):F(a),H=a=>{let b;if(!a)return"";try{b=JSON.parse(a)}catch{b=a}if(!b.includes("data:")||!b.includes("\n\n"))try{let a=JSON.parse(b);return JSON.stringify(a)}catch{return String(b)}let c=b.split("\n\n").filter(a=>a.trim()),d=[];for(let a of c){let b=a.trim();b=b.split("\n").map(a=>a.startsWith("data: ")?a.substring(6):a).join("\n"),d.push(b)}return d.join("\n\n")},I=a=>{if(!a)return!1;let b=a.includes("data:"),c=a.includes("\n\n"),d=a.includes("event:");return b||c||d};return j?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(d.default,{}),(0,b.jsx)("div",{className:"min-h-screen flex items-center justify-center",children:(0,b.jsx)("div",{className:"text-lg",children:"加载中..."})})]}):(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(d.default,{}),(0,b.jsx)("main",{className:"max-w-6xl mx-auto py-6 sm:px-6 lg:px-8",children:(0,b.jsxs)("div",{className:"px-4 py-4 sm:px-0",children:[(0,b.jsxs)("div",{className:"mb-5 flex items-center justify-between",children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("h1",{className:"text-lg font-bold text-slate-800",children:"请求日志"}),(0,b.jsx)("p",{className:"text-xs text-slate-500 mt-1",children:"查看所有 API 请求记录和响应详情"})]}),(0,b.jsxs)("div",{className:"flex gap-2 items-center",children:[(0,b.jsxs)("div",{className:"relative group",children:[(0,b.jsx)("input",{type:"text",placeholder:"搜索日志...",value:x,onChange:a=>y(a.target.value),onKeyPress:a=>{"Enter"===a.key&&E()},className:"w-64 pl-9 pr-20 py-1.5 text-xs border border-slate-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-emerald-500/30 focus:border-emerald-500 transition-all"}),(0,b.jsx)("svg",{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,b.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})}),(0,b.jsx)("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 flex items-center gap-1",children:x?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)("button",{onClick:E,className:"p-0.5 text-emerald-500 hover:text-emerald-600 hover:bg-emerald-50 rounded transition-colors",title:"确认搜索",children:(0,b.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,b.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})}),(0,b.jsx)("button",{onClick:()=>{y(""),v&&(w(""),m(0),D())},className:"p-0.5 text-slate-400 hover:text-rose-500 hover:bg-rose-50 rounded transition-colors",title:"清除搜索",children:(0,b.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,b.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}):null})]}),p.length>0&&(0,b.jsxs)("button",{onClick:B,className:"px-3 py-1.5 bg-rose-600 hover:bg-rose-700 text-white text-xs font-semibold rounded-lg border border-rose-200 transition-all duration-300",children:["删除选中 (",p.length,")"]}),(0,b.jsx)("button",{onClick:C,className:"px-3 py-1.5 bg-slate-600 hover:bg-slate-700 text-white text-xs font-semibold rounded-lg border border-slate-200 transition-all duration-300",children:"清空所有"})]})]}),(0,b.jsx)("div",{className:"bg-white/70 backdrop-blur-sm shadow-md rounded-2xl border border-emerald-100/50 overflow-hidden",children:(0,b.jsxs)("table",{className:"min-w-full divide-y divide-slate-100",children:[(0,b.jsx)("thead",{className:"bg-emerald-50/30",children:(0,b.jsxs)("tr",{children:[(0,b.jsx)("th",{className:"px-4 py-3.5 w-10",children:(0,b.jsx)("input",{type:"checkbox",checked:r&&a.length>0,onChange:b=>{var c;s(c=b.target.checked),q(c?a.map(a=>a.id):[])},className:"w-4 h-4 rounded border-slate-300 text-emerald-600 focus:ring-emerald-500"})}),(0,b.jsx)("th",{className:"px-4 py-2.5 text-left text-xs font-semibold text-slate-600 uppercase tracking-wider",children:"时间"}),(0,b.jsx)("th",{className:"px-6 py-3.5 text-left text-xs font-semibold text-gray-700 uppercase tracking-wider",children:"模型"}),(0,b.jsx)("th",{className:"px-6 py-3.5 text-left text-xs font-semibold text-gray-700 uppercase tracking-wider",children:"方法"}),(0,b.jsx)("th",{className:"px-6 py-3.5 text-left text-xs font-semibold text-gray-700 uppercase tracking-wider",children:"路径"}),(0,b.jsx)("th",{className:"px-6 py-3.5 text-left text-xs font-semibold text-gray-700 uppercase tracking-wider",children:"状态"}),(0,b.jsx)("th",{className:"px-6 py-3.5 text-left text-xs font-semibold text-gray-700 uppercase tracking-wider",children:"响应时间"}),(0,b.jsx)("th",{className:"px-6 py-3.5 text-right text-xs font-semibold text-gray-700 uppercase tracking-wider",children:"操作"})]})}),(0,b.jsx)("tbody",{className:"bg-white divide-y divide-slate-100",children:0===a.length?(0,b.jsx)("tr",{children:(0,b.jsx)("td",{colSpan:8,className:"px-4 py-12 text-center",children:(0,b.jsxs)("div",{className:"text-slate-400",children:[(0,b.jsx)("svg",{className:"mx-auto h-10 w-10 mb-3 text-slate-300",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,b.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),(0,b.jsx)("p",{className:"text-xs text-slate-500",children:v?"未找到匹配的日志":"暂无日志记录"}),v&&(0,b.jsx)("button",{onClick:()=>{y(""),w("")},className:"mt-2 text-xs text-emerald-600 hover:text-emerald-700",children:"清除搜索"})]})})}):a.map(a=>{let c=((a,b)=>{try{let c=a?JSON.parse(a):{},d=(b?JSON.parse(b):{}).model||c.model;if(Array.isArray(d)){let a=d[d.length-1];if(a&&"object"==typeof a&&"model"in a)return a.model}return"string"==typeof d?d:null}catch{return null}})(a.request_query,a.request_body)||a.model_name||"Gateway";return(0,b.jsxs)("tr",{className:"hover:bg-emerald-50/20 transition-colors duration-300",children:[(0,b.jsx)("td",{className:"px-4 py-3",children:(0,b.jsx)("input",{type:"checkbox",checked:p.includes(a.id),onChange:b=>{var c;return c=a.id,void(b.target.checked?q([...p,c]):(q(p.filter(a=>a!==c)),s(!1)))},className:"w-4 h-4 rounded border-slate-300 text-emerald-600 focus:ring-emerald-500",onClick:a=>a.stopPropagation()})}),(0,b.jsx)("td",{className:"px-4 py-3 whitespace-nowrap",children:(0,b.jsx)("div",{className:"text-xs text-slate-600",children:new Date(a.created_at+"Z").toLocaleString("zh-CN")})}),(0,b.jsx)("td",{className:"px-4 py-3 whitespace-nowrap",children:(0,b.jsxs)("div",{className:"text-xs",children:[(0,b.jsx)("div",{className:"font-medium text-slate-800",children:c}),a.provider_name&&(0,b.jsx)("div",{className:"text-[10px] text-slate-500",children:a.provider_name})]})}),(0,b.jsx)("td",{className:"px-4 py-3 whitespace-nowrap",children:(0,b.jsx)("span",{className:`px-2 py-0.5 inline-flex text-xs leading-4 font-semibold rounded-lg border ${"GET"===a.request_method?"bg-sky-50 text-sky-700 border-sky-200/50":"POST"===a.request_method?"bg-emerald-50 text-emerald-700 border-emerald-200/50":"bg-slate-50 text-slate-600 border-slate-200/50"}`,children:a.request_method})}),(0,b.jsx)("td",{className:"px-4 py-3",children:(0,b.jsx)("div",{className:"text-xs text-slate-600 font-mono max-w-xs truncate",children:a.request_path})}),(0,b.jsx)("td",{className:"px-4 py-3 whitespace-nowrap",children:(0,b.jsx)("span",{className:`px-2 py-0.5 inline-flex text-xs leading-4 font-semibold rounded-full border ${a.response_status>=200&&a.response_status<300?"bg-emerald-100/80 text-emerald-700 border-emerald-200/50":a.response_status>=400&&a.response_status<500?"bg-amber-100/80 text-amber-700 border-amber-200/50":a.response_status>=500?"bg-rose-100/80 text-rose-700 border-rose-200/50":"bg-slate-100/80 text-slate-600 border-slate-200/50"}`,children:a.response_status})}),(0,b.jsx)("td",{className:"px-4 py-3 whitespace-nowrap",children:(0,b.jsxs)("div",{className:"text-xs text-slate-600",children:[a.response_time_ms,"ms"]})}),(0,b.jsx)("td",{className:"px-4 py-3 whitespace-nowrap text-right text-xs font-medium",children:(0,b.jsx)("button",{onClick:()=>i(a),className:"text-emerald-600 hover:text-emerald-700 font-medium transition-colors duration-300",children:"查看详情"})})]},a.id)})})]})}),(0,b.jsxs)("div",{className:"mt-5 flex items-center justify-between",children:[(0,b.jsx)("div",{className:"text-xs text-slate-600",children:v?(0,b.jsxs)("span",{children:['搜索 "',(0,b.jsx)("span",{className:"font-semibold text-slate-800",children:v}),'" 找到 ',(0,b.jsx)("span",{className:"font-semibold text-slate-800",children:n})," 条结果"]}):(0,b.jsxs)("span",{children:["共 ",(0,b.jsx)("span",{className:"font-semibold text-slate-800",children:n})," 条记录"]})}),(0,b.jsxs)("div",{className:"flex space-x-2",children:[(0,b.jsx)("button",{onClick:()=>m(Math.max(0,l-1)),disabled:0===l,className:"px-3 py-1.5 border border-slate-200 rounded-lg text-xs font-medium text-slate-600 bg-white hover:bg-slate-50 disabled:opacity-50 disabled:cursor-not-allowed transition-all duration-300",children:"上一页"}),(0,b.jsx)("button",{onClick:()=>m(l+1),disabled:(l+1)*50>=n,className:"px-3 py-1.5 border border-slate-200 rounded-lg text-xs font-medium text-slate-600 bg-white hover:bg-slate-50 disabled:opacity-50 disabled:cursor-not-allowed transition-all duration-300",children:"下一页"})]})]})]})}),h&&(0,b.jsx)("div",{className:"fixed z-50 inset-0 overflow-y-auto",children:(0,b.jsxs)("div",{className:"flex items-center justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,b.jsx)("div",{className:"fixed inset-0 bg-slate-900/40 backdrop-blur-sm transition-opacity",onClick:()=>i(null)}),(0,b.jsx)("div",{className:"inline-block align-bottom bg-white rounded-2xl text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-3xl sm:w-full border border-emerald-100/50",children:(0,b.jsxs)("div",{className:"bg-white px-6 pt-5 pb-4 sm:p-6",children:[(0,b.jsxs)("div",{className:"mb-5",children:[(0,b.jsx)("h3",{className:"text-base font-bold text-slate-800 mb-1",children:"请求详情"}),(0,b.jsx)("p",{className:"text-xs text-slate-500",children:"查看完整的请求和响应信息"})]}),(0,b.jsxs)("div",{className:"space-y-4 max-h-[60vh] overflow-y-auto",children:[(0,b.jsxs)("div",{children:[(0,b.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,b.jsx)("h4",{className:"text-xs font-semibold text-slate-700",children:"请求头"}),(0,b.jsx)("button",{onClick:()=>A(F(h.request_headers)),className:"px-2 py-0.5 text-xs text-emerald-600 hover:text-emerald-700 font-medium transition-colors",children:"复制"})]}),(0,b.jsx)("pre",{className:"bg-slate-50/80 border border-slate-200 p-3 rounded-xl text-[10px] overflow-x-auto font-mono text-slate-700",children:F(h.request_headers)})]}),(0,b.jsxs)("div",{children:[(0,b.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,b.jsx)("h4",{className:"text-xs font-semibold text-slate-700",children:"请求 Query"}),(0,b.jsx)("button",{onClick:()=>A(F(h.request_query)),className:"px-2 py-0.5 text-xs text-emerald-600 hover:text-emerald-700 font-medium transition-colors",children:"复制"})]}),(0,b.jsx)("pre",{className:"bg-slate-50/80 border border-slate-200 p-3 rounded-xl text-[10px] overflow-x-auto font-mono text-slate-700",children:F(h.request_query)})]}),(0,b.jsxs)("div",{children:[(0,b.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,b.jsx)("h4",{className:"text-xs font-semibold text-slate-700",children:"请求 Body"}),(0,b.jsx)("button",{onClick:()=>A(F(h.request_body)),className:"px-2 py-0.5 text-xs text-emerald-600 hover:text-emerald-700 font-medium transition-colors",children:"复制"})]}),(0,b.jsx)("pre",{className:"bg-slate-50/80 border border-slate-200 p-3 rounded-xl text-[10px] overflow-x-auto font-mono text-slate-700",children:F(h.request_body)})]}),(0,b.jsxs)("div",{children:[(0,b.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,b.jsx)("h4",{className:"text-xs font-semibold text-slate-700",children:"响应 Body"}),(0,b.jsxs)("div",{className:"flex items-center gap-2",children:[h&&I(h.response_body)&&(0,b.jsx)("span",{className:"px-2 py-0.5 text-xs bg-indigo-100 text-indigo-700 rounded-full border border-indigo-200",children:"流式响应"}),(0,b.jsx)("button",{onClick:()=>A(G(h.response_body)),className:"px-2 py-0.5 text-xs text-emerald-600 hover:text-emerald-700 font-medium transition-colors",children:"复制"})]})]}),(0,b.jsx)("div",{className:"bg-slate-50/80 border border-slate-200 rounded-xl p-3 max-h-96 overflow-auto",children:(0,b.jsx)("pre",{className:"bg-slate-50/80 border border-slate-200 p-3 rounded-xl text-[10px] overflow-x-auto font-mono text-slate-700",children:G(h.response_body)})})]})]}),(0,b.jsx)("div",{className:"mt-5 flex justify-end",children:(0,b.jsx)("button",{type:"button",onClick:()=>i(null),className:"px-4 py-1.5 border border-slate-200 rounded-lg text-xs font-semibold text-slate-600 bg-white hover:bg-slate-50 focus:outline-none focus:ring-2 focus:ring-offset-1 focus:ring-slate-400/30 transition-all duration-300",children:"关闭"})})]})})]})}),t&&(0,b.jsx)(f.default,{open:t.open,title:t.title,message:t.message,onConfirm:t.onConfirm,onCancel:()=>u(null),type:"danger"})]})}a.s(["default",()=>g])}];
|
|
1
|
+
module.exports=[82602,a=>{"use strict";var b=a.i(87924),c=a.i(72131),d=a.i(81844),e=a.i(21215),f=a.i(71862);function g(){let[a,g]=(0,c.useState)([]),[h,i]=(0,c.useState)(null),[j,k]=(0,c.useState)(!0),[l,m]=(0,c.useState)(0),[n,o]=(0,c.useState)(0),[p,q]=(0,c.useState)([]),[r,s]=(0,c.useState)(!1),[t,u]=(0,c.useState)(null),[v,w]=(0,c.useState)(""),[x,y]=(0,c.useState)(""),{showToast:z}=(0,e.useToast)(),A=async a=>{try{await navigator.clipboard.writeText(a),z("已复制到剪贴板","success")}catch{z("复制失败,请手动复制","error")}},B=async()=>{0!==p.length&&u({open:!0,title:"删除确认",message:`确定要删除选中的 ${p.length} 条日志吗?`,onConfirm:async()=>{try{let a=await fetch(`/api/logs?ids=${p.join(",")}`,{method:"DELETE"}),b=await a.json();a.ok?(q([]),s(!1),D(),z("删除成功","success"),u(null)):z("删除失败:"+(b.error||"未知错误"),"error")}catch(a){console.error("Failed to delete logs:",a),z("删除失败","error")}}})},C=async()=>{u({open:!0,title:"清空日志",message:"确定要清空所有日志吗?此操作不可恢复!",onConfirm:async()=>{try{let a=await fetch("/api/logs?clear_all=true",{method:"DELETE"}),b=await a.json();a.ok?(m(0),q([]),s(!1),D(),z("清空成功","success"),u(null)):z("清空失败:"+(b.error||"未知错误"),"error")}catch(a){console.error("Failed to clear logs:",a),z("清空失败","error")}}})},D=async a=>{try{k(!0);let b=new URLSearchParams({limit:"50",offset:(50*l).toString()});a&&b.set("search",a);let c=await fetch(`/api/logs?${b.toString()}`),d=await c.json();g(d.logs||[]),o(d.total||0)}catch(a){console.error("Failed to load logs:",a),z("加载日志失败","error")}finally{k(!1)}},E=()=>{w(x),m(0),D(x)};(0,c.useEffect)(()=>{D()},[l,50]);let F=a=>"string"==typeof a?a:JSON.stringify(a),G=a=>I(a)?H(a):F(a),H=a=>{let b;if(!a)return"";try{b=JSON.parse(a)}catch{b=a}if(!b.includes("data:")||!b.includes("\n\n"))try{let a=JSON.parse(b);return JSON.stringify(a)}catch{return String(b)}let c=b.split("\n\n").filter(a=>a.trim()),d=[];for(let a of c){let b=a.trim();b=b.split("\n").map(a=>a.startsWith("data: ")?a.substring(6):a).join("\n"),d.push(b)}return d.join("\n\n")},I=a=>{if(!a)return!1;let b=a.includes("data:"),c=a.includes("\n\n"),d=a.includes("event:");return b||c||d};return j?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(d.default,{}),(0,b.jsx)("div",{className:"min-h-screen flex items-center justify-center",children:(0,b.jsx)("div",{className:"text-lg",children:"加载中..."})})]}):(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(d.default,{}),(0,b.jsx)("main",{className:"max-w-6xl mx-auto py-6 sm:px-6 lg:px-8",children:(0,b.jsxs)("div",{className:"px-4 py-4 sm:px-0",children:[(0,b.jsxs)("div",{className:"mb-5 flex items-center justify-between",children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("h1",{className:"text-lg font-bold text-slate-800",children:"请求日志"}),(0,b.jsx)("p",{className:"text-xs text-slate-500 mt-1",children:"查看所有 API 请求记录和响应详情"})]}),(0,b.jsxs)("div",{className:"flex gap-2 items-center",children:[(0,b.jsxs)("div",{className:"relative group",children:[(0,b.jsx)("input",{type:"text",placeholder:"搜索日志...",value:x,onChange:a=>y(a.target.value),onKeyPress:a=>{"Enter"===a.key&&E()},className:"w-64 pl-9 pr-20 py-1.5 text-xs border border-slate-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-emerald-500/30 focus:border-emerald-500 transition-all"}),(0,b.jsx)("svg",{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,b.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})}),(0,b.jsx)("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 flex items-center gap-1",children:x?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)("button",{onClick:E,className:"p-0.5 text-emerald-500 hover:text-emerald-600 hover:bg-emerald-50 rounded transition-colors",title:"确认搜索",children:(0,b.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,b.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})}),(0,b.jsx)("button",{onClick:()=>{y(""),v&&(w(""),m(0),D())},className:"p-0.5 text-slate-400 hover:text-rose-500 hover:bg-rose-50 rounded transition-colors",title:"清除搜索",children:(0,b.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,b.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}):null})]}),p.length>0&&(0,b.jsxs)("button",{onClick:B,className:"px-3 py-1.5 bg-rose-600 hover:bg-rose-700 text-white text-xs font-semibold rounded-lg border border-rose-200 transition-all duration-300",children:["删除选中 (",p.length,")"]}),(0,b.jsx)("button",{onClick:C,className:"px-3 py-1.5 bg-slate-600 hover:bg-slate-700 text-white text-xs font-semibold rounded-lg border border-slate-200 transition-all duration-300",children:"清空所有"})]})]}),(0,b.jsx)("div",{className:"bg-white/70 backdrop-blur-sm shadow-md rounded-2xl border border-emerald-100/50 overflow-hidden",children:(0,b.jsxs)("table",{className:"min-w-full divide-y divide-slate-100",children:[(0,b.jsx)("thead",{className:"bg-emerald-50/30",children:(0,b.jsxs)("tr",{children:[(0,b.jsx)("th",{className:"px-4 py-3.5 w-10",children:(0,b.jsx)("input",{type:"checkbox",checked:r&&a.length>0,onChange:b=>{var c;s(c=b.target.checked),q(c?a.map(a=>a.id):[])},className:"w-4 h-4 rounded border-slate-300 text-emerald-600 focus:ring-emerald-500"})}),(0,b.jsx)("th",{className:"px-4 py-2.5 text-left text-xs font-semibold text-slate-600 uppercase tracking-wider",children:"时间"}),(0,b.jsx)("th",{className:"px-6 py-3.5 text-left text-xs font-semibold text-gray-700 uppercase tracking-wider",children:"模型"}),(0,b.jsx)("th",{className:"px-6 py-3.5 text-left text-xs font-semibold text-gray-700 uppercase tracking-wider",children:"方法"}),(0,b.jsx)("th",{className:"px-6 py-3.5 text-left text-xs font-semibold text-gray-700 uppercase tracking-wider",children:"路径"}),(0,b.jsx)("th",{className:"px-6 py-3.5 text-left text-xs font-semibold text-gray-700 uppercase tracking-wider",children:"状态"}),(0,b.jsx)("th",{className:"px-6 py-3.5 text-left text-xs font-semibold text-gray-700 uppercase tracking-wider",children:"响应时间"}),(0,b.jsx)("th",{className:"px-6 py-3.5 text-right text-xs font-semibold text-gray-700 uppercase tracking-wider",children:"操作"})]})}),(0,b.jsx)("tbody",{className:"bg-white divide-y divide-slate-100",children:0===a.length?(0,b.jsx)("tr",{children:(0,b.jsx)("td",{colSpan:8,className:"px-4 py-12 text-center",children:(0,b.jsxs)("div",{className:"text-slate-400",children:[(0,b.jsx)("svg",{className:"mx-auto h-10 w-10 mb-3 text-slate-300",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,b.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),(0,b.jsx)("p",{className:"text-xs text-slate-500",children:v?"未找到匹配的日志":"暂无日志记录"}),v&&(0,b.jsx)("button",{onClick:()=>{y(""),w("")},className:"mt-2 text-xs text-emerald-600 hover:text-emerald-700",children:"清除搜索"})]})})}):a.map(a=>{let c=((a,b)=>{try{let c=a?JSON.parse(a):{},d=(b?JSON.parse(b):{}).model||c.model;if(Array.isArray(d)){let a=d[d.length-1];if(a&&"object"==typeof a&&"model"in a)return a.model}return"string"==typeof d?d:null}catch{return null}})(a.request_query,a.request_body)||a.model_name||"Gateway";return(0,b.jsxs)("tr",{className:"hover:bg-emerald-50/20 transition-colors duration-300",children:[(0,b.jsx)("td",{className:"px-4 py-3",children:(0,b.jsx)("input",{type:"checkbox",checked:p.includes(a.id),onChange:b=>{var c;return c=a.id,void(b.target.checked?q([...p,c]):(q(p.filter(a=>a!==c)),s(!1)))},className:"w-4 h-4 rounded border-slate-300 text-emerald-600 focus:ring-emerald-500",onClick:a=>a.stopPropagation()})}),(0,b.jsx)("td",{className:"px-4 py-3 whitespace-nowrap",children:(0,b.jsx)("div",{className:"text-xs text-slate-600",children:function(a){if(!a||"string"!=typeof a)return"";let b=a.trim();if(!b)return"";let c=new Date(/[Z+-]\d{2}:?\d{2}$/.test(b)?b:b.replace(" ","T")+"Z");return Number.isNaN(c.getTime())?b:c.toLocaleString("zh-CN")}(a.created_at)})}),(0,b.jsx)("td",{className:"px-4 py-3 whitespace-nowrap",children:(0,b.jsxs)("div",{className:"text-xs",children:[(0,b.jsx)("div",{className:"font-medium text-slate-800",children:c}),a.provider_name&&(0,b.jsx)("div",{className:"text-[10px] text-slate-500",children:a.provider_name})]})}),(0,b.jsx)("td",{className:"px-4 py-3 whitespace-nowrap",children:(0,b.jsx)("span",{className:`px-2 py-0.5 inline-flex text-xs leading-4 font-semibold rounded-lg border ${"GET"===a.request_method?"bg-sky-50 text-sky-700 border-sky-200/50":"POST"===a.request_method?"bg-emerald-50 text-emerald-700 border-emerald-200/50":"bg-slate-50 text-slate-600 border-slate-200/50"}`,children:a.request_method})}),(0,b.jsx)("td",{className:"px-4 py-3",children:(0,b.jsx)("div",{className:"text-xs text-slate-600 font-mono max-w-xs truncate",children:a.request_path})}),(0,b.jsx)("td",{className:"px-4 py-3 whitespace-nowrap",children:(0,b.jsx)("span",{className:`px-2 py-0.5 inline-flex text-xs leading-4 font-semibold rounded-full border ${a.response_status>=200&&a.response_status<300?"bg-emerald-100/80 text-emerald-700 border-emerald-200/50":a.response_status>=400&&a.response_status<500?"bg-amber-100/80 text-amber-700 border-amber-200/50":a.response_status>=500?"bg-rose-100/80 text-rose-700 border-rose-200/50":"bg-slate-100/80 text-slate-600 border-slate-200/50"}`,children:a.response_status})}),(0,b.jsx)("td",{className:"px-4 py-3 whitespace-nowrap",children:(0,b.jsxs)("div",{className:"text-xs text-slate-600",children:[a.response_time_ms,"ms"]})}),(0,b.jsx)("td",{className:"px-4 py-3 whitespace-nowrap text-right text-xs font-medium",children:(0,b.jsx)("button",{onClick:()=>i(a),className:"text-emerald-600 hover:text-emerald-700 font-medium transition-colors duration-300",children:"查看详情"})})]},a.id)})})]})}),(0,b.jsxs)("div",{className:"mt-5 flex items-center justify-between",children:[(0,b.jsx)("div",{className:"text-xs text-slate-600",children:v?(0,b.jsxs)("span",{children:['搜索 "',(0,b.jsx)("span",{className:"font-semibold text-slate-800",children:v}),'" 找到 ',(0,b.jsx)("span",{className:"font-semibold text-slate-800",children:n})," 条结果"]}):(0,b.jsxs)("span",{children:["共 ",(0,b.jsx)("span",{className:"font-semibold text-slate-800",children:n})," 条记录"]})}),(0,b.jsxs)("div",{className:"flex space-x-2",children:[(0,b.jsx)("button",{onClick:()=>m(Math.max(0,l-1)),disabled:0===l,className:"px-3 py-1.5 border border-slate-200 rounded-lg text-xs font-medium text-slate-600 bg-white hover:bg-slate-50 disabled:opacity-50 disabled:cursor-not-allowed transition-all duration-300",children:"上一页"}),(0,b.jsx)("button",{onClick:()=>m(l+1),disabled:(l+1)*50>=n,className:"px-3 py-1.5 border border-slate-200 rounded-lg text-xs font-medium text-slate-600 bg-white hover:bg-slate-50 disabled:opacity-50 disabled:cursor-not-allowed transition-all duration-300",children:"下一页"})]})]})]})}),h&&(0,b.jsx)("div",{className:"fixed z-50 inset-0 overflow-y-auto",children:(0,b.jsxs)("div",{className:"flex items-center justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0",children:[(0,b.jsx)("div",{className:"fixed inset-0 bg-slate-900/40 backdrop-blur-sm transition-opacity",onClick:()=>i(null)}),(0,b.jsx)("div",{className:"inline-block align-bottom bg-white rounded-2xl text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-3xl sm:w-full border border-emerald-100/50",children:(0,b.jsxs)("div",{className:"bg-white px-6 pt-5 pb-4 sm:p-6",children:[(0,b.jsxs)("div",{className:"mb-5",children:[(0,b.jsx)("h3",{className:"text-base font-bold text-slate-800 mb-1",children:"请求详情"}),(0,b.jsx)("p",{className:"text-xs text-slate-500",children:"查看完整的请求和响应信息"})]}),(0,b.jsxs)("div",{className:"space-y-4 max-h-[60vh] overflow-y-auto",children:[(0,b.jsxs)("div",{children:[(0,b.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,b.jsx)("h4",{className:"text-xs font-semibold text-slate-700",children:"请求头"}),(0,b.jsx)("button",{onClick:()=>A(F(h.request_headers)),className:"px-2 py-0.5 text-xs text-emerald-600 hover:text-emerald-700 font-medium transition-colors",children:"复制"})]}),(0,b.jsx)("pre",{className:"bg-slate-50/80 border border-slate-200 p-3 rounded-xl text-[10px] overflow-x-auto font-mono text-slate-700",children:F(h.request_headers)})]}),(0,b.jsxs)("div",{children:[(0,b.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,b.jsx)("h4",{className:"text-xs font-semibold text-slate-700",children:"请求 Query"}),(0,b.jsx)("button",{onClick:()=>A(F(h.request_query)),className:"px-2 py-0.5 text-xs text-emerald-600 hover:text-emerald-700 font-medium transition-colors",children:"复制"})]}),(0,b.jsx)("pre",{className:"bg-slate-50/80 border border-slate-200 p-3 rounded-xl text-[10px] overflow-x-auto font-mono text-slate-700",children:F(h.request_query)})]}),(0,b.jsxs)("div",{children:[(0,b.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,b.jsx)("h4",{className:"text-xs font-semibold text-slate-700",children:"请求 Body"}),(0,b.jsx)("button",{onClick:()=>A(F(h.request_body)),className:"px-2 py-0.5 text-xs text-emerald-600 hover:text-emerald-700 font-medium transition-colors",children:"复制"})]}),(0,b.jsx)("pre",{className:"bg-slate-50/80 border border-slate-200 p-3 rounded-xl text-[10px] overflow-x-auto font-mono text-slate-700",children:F(h.request_body)})]}),(0,b.jsxs)("div",{children:[(0,b.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,b.jsx)("h4",{className:"text-xs font-semibold text-slate-700",children:"响应 Body"}),(0,b.jsxs)("div",{className:"flex items-center gap-2",children:[h&&I(h.response_body)&&(0,b.jsx)("span",{className:"px-2 py-0.5 text-xs bg-indigo-100 text-indigo-700 rounded-full border border-indigo-200",children:"流式响应"}),(0,b.jsx)("button",{onClick:()=>A(G(h.response_body)),className:"px-2 py-0.5 text-xs text-emerald-600 hover:text-emerald-700 font-medium transition-colors",children:"复制"})]})]}),(0,b.jsx)("div",{className:"bg-slate-50/80 border border-slate-200 rounded-xl p-3 max-h-96 overflow-auto",children:(0,b.jsx)("pre",{className:"bg-slate-50/80 border border-slate-200 p-3 rounded-xl text-[10px] overflow-x-auto font-mono text-slate-700",children:G(h.response_body)})})]})]}),(0,b.jsx)("div",{className:"mt-5 flex justify-end",children:(0,b.jsx)("button",{type:"button",onClick:()=>i(null),className:"px-4 py-1.5 border border-slate-200 rounded-lg text-xs font-semibold text-slate-600 bg-white hover:bg-slate-50 focus:outline-none focus:ring-2 focus:ring-offset-1 focus:ring-slate-400/30 transition-all duration-300",children:"关闭"})})]})})]})}),t&&(0,b.jsx)(f.default,{open:t.open,title:t.title,message:t.message,onConfirm:t.onConfirm,onCancel:()=>u(null),type:"danger"})]})}a.s(["default",()=>g])}];
|
|
2
2
|
|
|
3
3
|
//# sourceMappingURL=src_app_logs_page_tsx_7b7b7b83._.js.map
|