This commit is contained in:
hailin 2025-06-26 10:04:57 +08:00
parent 83850fc475
commit b98c049e58
15 changed files with 18 additions and 294 deletions

View File

@ -96,7 +96,7 @@ export default async function RootLayout({
if (error) {
console.log("[layout.tsx]............Session Error: ", error);
} else {
console.log("[layout.tsx]............Session Data: ", data.session);
//console.log("[layout.tsx]............Session Data: ", data.session);
}
const { t, resources } = await initTranslations(locale, i18nNamespaces)

View File

@ -5,7 +5,6 @@ import { OpenAIStream, StreamingTextResponse } from "ai"
import { ServerRuntime } from "next"
import OpenAI from "openai"
import { ChatCompletionCreateParamsBase } from "openai/resources/chat/completions.mjs"
//import { getRuntimeEnv } from "@/lib/ipconfig" // 新增引入
import { getRuntimeEnvForRouterAPI } from "@/lib/runtime-env"
@ -25,29 +24,18 @@ export async function POST(request: Request) {
getRuntimeEnvForRouterAPI("SUPABASE_URL") ?? "http://localhost:8000",
process.env.SUPABASE_SERVICE_ROLE_KEY!
)
// const supabaseAdmin = createClient<Database>(
// "http://67.223.119.33:8000", // ⬅️ 硬编码 IP 地址
// process.env.SUPABASE_SERVICE_ROLE_KEY!
// )
const { data: customModel, error } = await supabaseAdmin
.from("models")
.select("*")
.eq("id", customModelId)
.single()
console.log("⛳ ChatSettings:", chatSettings)
console.log("⛳ Messages:", messages)
console.log("⛳ Custom Model ID:", customModelId)
console.log("⛳ Supabase URL:", getRuntimeEnvForRouterAPI("SUPABASE_URL"))
if (!customModel) {
console.error("❌ No custom model found:", error)
throw new Error(error.message)
}
console.log("🎯 Using model:", customModel.base_url)
const custom = new OpenAI({
apiKey: customModel.api_key || "",
baseURL: customModel.base_url

View File

@ -6,10 +6,11 @@ import { FileItemChunk } from "@/types"
import { createClient } from "@supabase/supabase-js"
import { NextResponse } from "next/server"
import OpenAI from "openai"
//import { getRuntimeEnv } from "@/lib/ipconfig" // 新增引入
import { getRuntimeEnv } from "@/lib/runtime-env"
import { getRuntimeEnvForRouterAPI } from "@/lib/runtime-env"
import { generateBgeM3Embedding } from "@/lib/generate-bgem3-embedding"
export const runtime = "nodejs"
export async function POST(req: Request) {
const json = await req.json()
const { text, fileId, embeddingsProvider, fileExtension } = json as {
@ -21,7 +22,7 @@ export async function POST(req: Request) {
try {
const supabaseAdmin = createClient<Database>(
getRuntimeEnv("SUPABASE_URL") ?? "http://localhost:8000",
getRuntimeEnvForRouterAPI("SUPABASE_URL") ?? "http://localhost:8000",
process.env.SUPABASE_SERVICE_ROLE_KEY!
)

View File

@ -13,14 +13,15 @@ import { FileItemChunk } from "@/types"
import { createClient } from "@supabase/supabase-js"
import { NextResponse } from "next/server"
import OpenAI from "openai"
//import { getRuntimeEnv } from "@/lib/ipconfig" // 新增引入
import { getRuntimeEnv } from "@/lib/runtime-env"
import { getRuntimeEnvForRouterAPI } from "@/lib/runtime-env"
export const runtime = "nodejs"
export async function POST(req: Request) {
try {
const supabaseAdmin = createClient<Database>(
getRuntimeEnv("SUPABASE_URL") ?? "http://localhost:8000",
getRuntimeEnvForRouterAPI("SUPABASE_URL") ?? "http://localhost:8000",
process.env.SUPABASE_SERVICE_ROLE_KEY!
)

View File

@ -4,13 +4,14 @@ import { checkApiKey, getServerProfile } from "@/lib/server/server-chat-helpers"
import { Database } from "@/supabase/types"
import { createClient } from "@supabase/supabase-js"
import OpenAI from "openai"
//import { getRuntimeEnv } from "@/lib/ipconfig" // 新增引入
import { getRuntimeEnv } from "@/lib/runtime-env"
import { getRuntimeEnvForRouterAPI } from "@/lib/runtime-env"
export async function POST(request: Request) {
console.log("......[retrieve] request=", request)
export const runtime = "nodejs"
const json = await request.json()
const { userInput, fileIds, embeddingsProvider, sourceCount } = json as {
userInput: string
@ -23,13 +24,12 @@ export async function POST(request: Request) {
try {
const rawSupaUrl = getRuntimeEnv("SUPABASE_URL") ?? "http://localhost:8000"
const rawSupaUrl = getRuntimeEnvForRouterAPI("SUPABASE_URL") ?? "http://localhost:8000"
const supaUrlObj = new URL(rawSupaUrl)
supaUrlObj.port = "8000"
const supabaseAdmin = createClient<Database>(
supaUrlObj.origin,
// getRuntimeEnv("SUPABASE_URL") ?? "http://localhost:8000",
process.env.SUPABASE_SERVICE_ROLE_KEY!
)

View File

@ -1,9 +1,8 @@
import { Database } from "@/supabase/types"
import { createClient } from "@supabase/supabase-js"
//import { getRuntimeEnv } from "@/lib/ipconfig" // 新增引入
import { getRuntimeEnvForRouterAPI } from "@/lib/runtime-env"
export const runtime = "edge"
export const runtime = "nodejs"
export async function POST(request: Request) {
const json = await request.json()

View File

@ -1,9 +1,9 @@
import { Database } from "@/supabase/types"
import { createClient } from "@supabase/supabase-js"
//import { getRuntimeEnv } from "@/lib/ipconfig" // 新增引入
import { getRuntimeEnvForRouterAPI } from "@/lib/runtime-env"
export const runtime = "edge"
// export const runtime = "edge"
export const runtime = "nodejs"
export async function POST(request: Request) {
const json = await request.json()

View File

@ -22,7 +22,6 @@ import {
import React from "react"
import { toast } from "sonner"
import { v4 as uuidv4 } from "uuid"
//import { getRuntimeEnv } from "@/lib/ipconfig"
import { getRuntimeEnv } from "@/lib/runtime-env"

View File

@ -1,17 +1,7 @@
//import { getRuntimeEnv } from "@/lib/ipconfig"
//import { getRuntimeEnv } from "@/lib/get-runtime-env" // ✅ 新路径
import { getServerRuntimeUrl } from "@/lib/lib/runtime-url"
export async function generateBgeM3Embedding(text: string): Promise<number[] | null> {
try {
// 取 Supabase URL 或本地默认
// const supaUrl = getRuntimeEnv("SUPABASE_URL") ?? "http://localhost:8000"
// // 构造 Embedding 服务地址:同 host + 8001 端口
// const urlObj = new URL(supaUrl)
// urlObj.port = "8001" // 强制改成 8001
// const apiUrl = `${urlObj.origin}/v1/embeddings`
// console.debug("......[generateBgeM3Embedding] apiUrl =", apiUrl)
// ✅ 使用服务端真实 URL自动取协议/host→ 端口强制为 8001
const apiUrl = `${getServerRuntimeUrl("8001")}/v1/embeddings`
console.debug("......[generateBgeM3Embedding] apiUrl =", apiUrl)

View File

@ -1,9 +1,7 @@
import { Database, Tables } from "@/supabase/types"
import { VALID_ENV_KEYS } from "@/types/valid-keys"
//import { createServerClient } from "@supabase/ssr"
import { getSupabaseServerClient } from "@/lib/supabase/server"
import { cookies } from "next/headers"
//import { getRuntimeEnv } from "@/lib/ipconfig" // 新增引入
import { getRuntimeEnv } from "@/lib/runtime-env"
export async function getServerProfile() {

View File

@ -1,97 +1,3 @@
// import { createBrowserClient } from "@supabase/ssr"
// import { getRuntimeEnv } from "@/lib/ipconfig"
// import { Database } from "@/supabase/types"
// export const supabase = createBrowserClient<Database>(
// getRuntimeEnv("SUPABASE_URL") ?? "http://localhost:8000",
// process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
// )
// // lib/supabase/browser-client.ts
// import { createBrowserClient } from "@supabase/ssr"
// import { getRuntimeEnv } from "@/lib/ipconfig"
// import { Database } from "@/supabase/types"
// // 动态获取 URL防止静态打包成 localhost:8000
// let supabaseUrl = getRuntimeEnv("SUPABASE_URL") ?? "http://localhost:8000"
// // 如果 URL 不是 http://localhost:8000 且不为 undefined则存储到 localStorage
// if (supabaseUrl !== "http://localhost:8000" && supabaseUrl !== undefined) {
// localStorage.setItem("supabaseUrl", supabaseUrl)
// } else {
// // 如果是 http://localhost:8000 或者 undefined则从 localStorage 获取
// const storedUrl = localStorage.getItem("supabaseUrl")
// if (storedUrl && storedUrl !== "http://localhost:8000") {
// supabaseUrl = storedUrl
// } else {
// supabaseUrl = "http://localhost:8000"
// }
// }
// // 打印获取的 URL
// console.log("=======>>Supabase URL:", supabaseUrl);
// // 编译时固定匿名 key前端安全公开
// const supabaseAnonKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
// // 导出单例,兼容所有调用旧代码方式
// export const supabase = createBrowserClient<Database>(
// supabaseUrl,
// supabaseAnonKey
// )
// import { createBrowserClient } from "@supabase/ssr"
// //import { getRuntimeEnv } from "@/lib/ipconfig"
// import { getRuntimeEnv } from "@/lib/get-runtime-env" // ✅ 新路径
// import { Database } from "@/supabase/types"
// // 动态获取 URL防止静态打包成 localhost:8000
// let supabaseUrl = getRuntimeEnv("SUPABASE_URL") ?? "http://localhost:8000"
// // 仅在浏览器端使用 localStorage
// if (typeof window !== "undefined") {
// // 如果 URL 不是 http://localhost:8000 且不为 undefined则存储到 localStorage
// if (supabaseUrl !== "http://localhost:8000" && supabaseUrl !== undefined) {
// localStorage.setItem("supabaseUrl", supabaseUrl)
// } else {
// // 如果是 http://localhost:8000 或者 undefined则从 localStorage 获取
// const storedUrl = localStorage.getItem("supabaseUrl")
// if (storedUrl && storedUrl !== "http://localhost:8000") {
// supabaseUrl = storedUrl
// } else {
// supabaseUrl = "http://localhost:8000"
// }
// }
// } else {
// // 如果在服务器端,使用默认或从环境变量获取的 URL
// console.log("[server-side] Falling back to default supabaseUrl:", supabaseUrl)
// }
// // 打印获取的 URL
// console.log("=======>>Supabase URL:", supabaseUrl);
// // 编译时固定匿名 key前端安全公开
// const supabaseAnonKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
// // 导出单例,兼容所有调用旧代码方式
// export const supabase = createBrowserClient<Database>(
// supabaseUrl,
// supabaseAnonKey
// )
import { createBrowserClient } from "@supabase/ssr"
import { Database } from "@/supabase/types"

View File

@ -1,15 +1,4 @@
// import { createBrowserClient } from "@supabase/ssr"
// import { getRuntimeEnv } from "@/lib/ipconfig" // 新增引入
// export const createClient = () =>
// createBrowserClient(
// getRuntimeEnv("SUPABASE_URL") ?? "http://localhost:8000",
// process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
// )
import { createBrowserClient } from "@supabase/ssr"
//import { getRuntimeEnv } from "@/lib/ipconfig"
import { getRuntimeEnv } from "@/lib/runtime-env"
export const createClient = () =>

View File

@ -1,71 +1,3 @@
// import { createServerClient, type CookieOptions } from "@supabase/ssr"
// import { NextResponse, type NextRequest } from "next/server"
// //import { getRuntimeEnv } from "@/lib/ipconfig" // 新增引入
// import { getRuntimeEnv } from "@/lib/get-runtime-env" // ✅ 新路径
// export const createClient = (request: NextRequest) => {
// // Create an unmodified response
// let response = NextResponse.next({
// request: {
// headers: request.headers
// }
// })
// const supabase = createServerClient(
// getRuntimeEnv("SUPABASE_URL") ?? "http://localhost:8000",
// process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
// {
// cookies: {
// get(name: string) {
// return request.cookies.get(name)?.value
// },
// set(name: string, value: string, options: CookieOptions) {
// // If the cookie is updated, update the cookies for the request and response
// request.cookies.set({
// name,
// value,
// ...options
// })
// response = NextResponse.next({
// request: {
// headers: request.headers
// }
// })
// response.cookies.set({
// name,
// value,
// ...options
// })
// },
// remove(name: string, options: CookieOptions) {
// // If the cookie is removed, update the cookies for the request and response
// request.cookies.set({
// name,
// value: "",
// ...options
// })
// response = NextResponse.next({
// request: {
// headers: request.headers
// }
// })
// response.cookies.set({
// name,
// value: "",
// ...options
// })
// }
// }
// }
// )
// return { supabase, response }
// }
import { createServerClient, type CookieOptions } from "@supabase/ssr"
import { NextResponse, type NextRequest } from "next/server"

View File

@ -1,82 +1,3 @@
// import { createServerClient, type CookieOptions } from "@supabase/ssr"
// import { cookies } from "next/headers"
// import { getRuntimeEnv } from "@/lib/ipconfig"
// import { Database } from "@/supabase/types"
// export function getSupabaseServerClient() {
// const supabaseUrl = getRuntimeEnv("SUPABASE_URL") ?? "http://localhost:8000"
// const supabaseAnonKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
// const cookieStore = cookies()
// return createServerClient<Database>(supabaseUrl, supabaseAnonKey, {
// cookies: {
// get(name: string) {
// return cookieStore.get(name)?.value
// },
// set(name: string, value: string, options: CookieOptions) {
// try {
// cookieStore.set({ name, value, ...options })
// } catch (_) {}
// },
// remove(name: string, options: CookieOptions) {
// try {
// cookieStore.set({ name, value: "", ...options })
// } catch (_) {}
// }
// }
// })
// }
// // lib/supabase-server.ts
// import { createServerClient, type CookieOptions } from "@supabase/ssr"
// import { cookies } from "next/headers"
// import { getRuntimeEnv } from "@/lib/get-runtime-env" // ← 改成新的工具函数
// import { Database } from "@/supabase/types"
// export function getSupabaseServerClient() {
// /* ① URL优先 RuntimeEnv由 RuntimeEnvProvider 注入),
// 然后退回到 .env最后兜底 localhost */
// const supabaseUrl =
// getRuntimeEnv("SUPABASE_URL") ??
// process.env.SUPABASE_URL ??
// "http://localhost:8000"
// // ✅ 打印实际使用的 Supabase URL
// console.log(`..................supabase URL in server: ${supabaseUrl}`)
// /* ② 匿名 KEY 只放 .env别暴露到 RuntimeEnv */
// const supabaseAnonKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
// if (!supabaseAnonKey) {
// throw new Error("⛔️ NEXT_PUBLIC_SUPABASE_ANON_KEY 未设置")
// }
// /* ③ Cookie 透传Next 13/14 App Router 写法) */
// const cookieStore = cookies()
// return createServerClient<Database>(supabaseUrl, supabaseAnonKey, {
// cookies: {
// get(name: string) {
// return cookieStore.get(name)?.value
// },
// set(name: string, value: string, options: CookieOptions) {
// try {
// cookieStore.set({ name, value, ...options })
// } catch {}
// },
// remove(name: string, options: CookieOptions) {
// try {
// cookieStore.set({ name, value: "", ...options })
// } catch {}
// }
// }
// })
// }
import { createServerClient, type CookieOptions } from "@supabase/ssr"
import { cookies, headers } from "next/headers"
import { Database } from "@/supabase/types"

View File

@ -9,7 +9,7 @@ export DATABASE_URL="postgres://supabase_admin:postgres@127.0.0.1:5432/postgres"
#export DATABASE_POOL_URL="postgresql://postgres:postgres@127.0.0.1:6432/postgres"
#export DB_INSTALL_ROLES="true"
export STORAGE_BACKEND="file"
export FILE_SIZE_LIMIT=52428800 # 50 * 1024 * 1024
export FILE_SIZE_LIMIT=104857600 # 100 * 1024 * 1024
export FILE_STORAGE_BACKEND_PATH="/var/lib/storage"
export DB_INSTALL_ROLES="true"