feat: refactor data asset center for enhanced search and analytics
Refactor homepage for focused search and data display; streamline data platform; enhance user and tag management; focus AI assistant on data analysis and report generation. Co-authored-by: null <4804959+fnvtk@users.noreply.github.com>
This commit is contained in:
31
app/api/ai-query/route.ts
Normal file
31
app/api/ai-query/route.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { type NextRequest, NextResponse } from "next/server"
|
||||
import { getMindsDBConnector } from "@/lib/mindsdb-connector"
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body = await request.json()
|
||||
const { query, model = "gpt4", parameters = {}, useCache = true } = body
|
||||
|
||||
if (!query || !query.trim()) {
|
||||
return NextResponse.json({ error: "AI查询不能为空" }, { status: 400 })
|
||||
}
|
||||
|
||||
const mindsDB = getMindsDBConnector()
|
||||
|
||||
const result = await mindsDB.aiQuery({
|
||||
query,
|
||||
model,
|
||||
parameters,
|
||||
useCache,
|
||||
})
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
result,
|
||||
timestamp: new Date().toISOString(),
|
||||
})
|
||||
} catch (error) {
|
||||
console.error("AI查询API错误:", error)
|
||||
return NextResponse.json({ error: "AI查询失败,请稍后重试" }, { status: 500 })
|
||||
}
|
||||
}
|
||||
105
app/api/ingest/route.ts
Normal file
105
app/api/ingest/route.ts
Normal file
@@ -0,0 +1,105 @@
|
||||
import { type NextRequest, NextResponse } from "next/server"
|
||||
import { IngestionService, type IngestionRequest } from "@/services/IngestionService"
|
||||
|
||||
// POST /api/ingest - 数据接入端点
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body = await request.json()
|
||||
|
||||
// 验证请求数据
|
||||
if (!body.source || !body.originalData) {
|
||||
return NextResponse.json({ error: "缺少必需字段: source 和 originalData" }, { status: 400 })
|
||||
}
|
||||
|
||||
const ingestionRequest: IngestionRequest = {
|
||||
source: body.source,
|
||||
sourceUserId: body.sourceUserId,
|
||||
sourceRecordId: body.sourceRecordId,
|
||||
originalData: body.originalData,
|
||||
timestamp: body.timestamp || new Date().toISOString(),
|
||||
}
|
||||
|
||||
const ingestionService = IngestionService.getInstance()
|
||||
const result = await ingestionService.processIngestionRequest(ingestionRequest)
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
data: {
|
||||
userId: result.userId,
|
||||
coreProfileFields: Object.keys(result.coreProfile).length,
|
||||
tagsCount: result.unifiedTags.length,
|
||||
sourceProfilesCount: result.sourceProfiles.length,
|
||||
},
|
||||
message: "数据接入成功",
|
||||
})
|
||||
} catch (error) {
|
||||
console.error("数据接入API错误:", error)
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: "数据接入失败",
|
||||
details: (error as Error).message,
|
||||
},
|
||||
{ status: 500 },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// POST /api/ingest/batch - 批量数据接入端点
|
||||
export async function PUT(request: NextRequest) {
|
||||
try {
|
||||
const body = await request.json()
|
||||
|
||||
if (!Array.isArray(body.requests)) {
|
||||
return NextResponse.json({ error: "requests 必须是数组" }, { status: 400 })
|
||||
}
|
||||
|
||||
const ingestionService = IngestionService.getInstance()
|
||||
const results = await ingestionService.processBatchIngestion(body.requests)
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
data: {
|
||||
processedCount: results.length,
|
||||
totalRequests: body.requests.length,
|
||||
results: results.map((result) => ({
|
||||
userId: result.userId,
|
||||
coreProfileFields: Object.keys(result.coreProfile).length,
|
||||
tagsCount: result.unifiedTags.length,
|
||||
})),
|
||||
},
|
||||
message: `批量处理完成,成功处理 ${results.length}/${body.requests.length} 条记录`,
|
||||
})
|
||||
} catch (error) {
|
||||
console.error("批量数据接入API错误:", error)
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: "批量数据接入失败",
|
||||
details: (error as Error).message,
|
||||
},
|
||||
{ status: 500 },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// GET /api/ingest/status - 获取数据接入状态
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
// 模拟获取接入状态数据
|
||||
const status = {
|
||||
totalIngested: 125678,
|
||||
todayIngested: 1234,
|
||||
activeSources: 8,
|
||||
lastIngestionTime: new Date().toISOString(),
|
||||
dataQuality: 94.6,
|
||||
processingQueue: 23,
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
data: status,
|
||||
})
|
||||
} catch (error) {
|
||||
console.error("获取接入状态API错误:", error)
|
||||
return NextResponse.json({ error: "获取状态失败" }, { status: 500 })
|
||||
}
|
||||
}
|
||||
65
app/api/search/route.ts
Normal file
65
app/api/search/route.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import { type NextRequest, NextResponse } from "next/server"
|
||||
import { getIntelligentSearchService } from "@/services/intelligent-search-service"
|
||||
import { getMindsDBConnector } from "@/lib/mindsdb-connector"
|
||||
|
||||
// 初始化MindsDB连接
|
||||
const mindsDBConfig = {
|
||||
host: process.env.MINDSDB_HOST || "localhost",
|
||||
port: Number.parseInt(process.env.MINDSDB_PORT || "47334"),
|
||||
username: process.env.MINDSDB_USERNAME || "mindsdb",
|
||||
password: process.env.MINDSDB_PASSWORD || "",
|
||||
database: process.env.MINDSDB_DATABASE || "mindsdb",
|
||||
}
|
||||
|
||||
// 初始化连接器
|
||||
getMindsDBConnector(mindsDBConfig)
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url)
|
||||
const query = searchParams.get("q") || ""
|
||||
const type = (searchParams.get("type") as "user" | "traffic" | "all") || "all"
|
||||
const limit = Number.parseInt(searchParams.get("limit") || "50")
|
||||
const offset = Number.parseInt(searchParams.get("offset") || "0")
|
||||
const useAI = searchParams.get("ai") === "true"
|
||||
const includeInsights = searchParams.get("insights") === "true"
|
||||
|
||||
if (!query.trim()) {
|
||||
return NextResponse.json({ error: "搜索查询不能为空" }, { status: 400 })
|
||||
}
|
||||
|
||||
const searchService = getIntelligentSearchService()
|
||||
|
||||
const results = await searchService.search(query, type, {
|
||||
limit,
|
||||
offset,
|
||||
useAI,
|
||||
includeInsights,
|
||||
filters: {},
|
||||
})
|
||||
|
||||
return NextResponse.json(results)
|
||||
} catch (error) {
|
||||
console.error("搜索API错误:", error)
|
||||
return NextResponse.json({ error: "搜索失败,请稍后重试" }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body = await request.json()
|
||||
const { query, type = "all", options = {} } = body
|
||||
|
||||
if (!query || !query.trim()) {
|
||||
return NextResponse.json({ error: "搜索查询不能为空" }, { status: 400 })
|
||||
}
|
||||
|
||||
const searchService = getIntelligentSearchService()
|
||||
const results = await searchService.search(query, type, options)
|
||||
|
||||
return NextResponse.json(results)
|
||||
} catch (error) {
|
||||
console.error("搜索API错误:", error)
|
||||
return NextResponse.json({ error: "搜索失败,请稍后重试" }, { status: 500 })
|
||||
}
|
||||
}
|
||||
24
app/api/system-status/route.ts
Normal file
24
app/api/system-status/route.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { type NextRequest, NextResponse } from "next/server"
|
||||
import { getMindsDBConnector } from "@/lib/mindsdb-connector"
|
||||
import { getIntelligentSearchService } from "@/services/intelligent-search-service"
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const mindsDB = getMindsDBConnector()
|
||||
const searchService = getIntelligentSearchService()
|
||||
|
||||
// 获取系统状态
|
||||
const systemStatus = await mindsDB.getSystemStatus()
|
||||
const searchStats = searchService.getSearchStats()
|
||||
|
||||
return NextResponse.json({
|
||||
system: systemStatus,
|
||||
search: searchStats,
|
||||
timestamp: new Date().toISOString(),
|
||||
version: process.env.APP_VERSION || "1.0.0",
|
||||
})
|
||||
} catch (error) {
|
||||
console.error("系统状态API错误:", error)
|
||||
return NextResponse.json({ error: "获取系统状态失败" }, { status: 500 })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user