You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.8 KiB
56 lines
1.8 KiB
import { defineWrappedResponseHandler } from "#server/utils/handler";
|
|
import { R } from "#server/utils/response";
|
|
import { requireAdmin } from "#server/utils/admin-guard";
|
|
import { listCharacterCards } from "#server/service/character/character-card";
|
|
import { parseTags } from "#server/service/character/persona";
|
|
import { dbGlobal } from "drizzle-pkg/lib/db";
|
|
import { llmModels, llmProviders } from "drizzle-pkg/lib/schema/llm";
|
|
import { eq, inArray } from "drizzle-orm";
|
|
|
|
export default defineWrappedResponseHandler(async (event) => {
|
|
await requireAdmin(event);
|
|
|
|
const cards = await listCharacterCards(false);
|
|
|
|
const modelIds = cards
|
|
.map((c) => c.defaultModelId)
|
|
.filter((id): id is number => id != null);
|
|
|
|
const modelMap = new Map<
|
|
number,
|
|
{ modelName: string; modelId: string; providerName: string; providerStatus: string; apiKeySet: boolean }
|
|
>();
|
|
|
|
if (modelIds.length > 0) {
|
|
const rows = await dbGlobal
|
|
.select({
|
|
id: llmModels.id,
|
|
modelName: llmModels.name,
|
|
modelIdentifier: llmModels.modelId,
|
|
providerName: llmProviders.name,
|
|
providerStatus: llmProviders.status,
|
|
apiKey: llmProviders.apiKey,
|
|
})
|
|
.from(llmModels)
|
|
.innerJoin(llmProviders, eq(llmModels.providerId, llmProviders.id))
|
|
.where(inArray(llmModels.id, modelIds));
|
|
|
|
for (const row of rows) {
|
|
modelMap.set(row.id, {
|
|
modelName: row.modelName,
|
|
modelId: row.modelIdentifier,
|
|
providerName: row.providerName,
|
|
providerStatus: row.providerStatus,
|
|
apiKeySet: !!row.apiKey,
|
|
});
|
|
}
|
|
}
|
|
|
|
const list = cards.map((c) => ({
|
|
...c,
|
|
tags: parseTags(c.tags),
|
|
defaultModel: c.defaultModelId ? modelMap.get(c.defaultModelId) ?? null : null,
|
|
}));
|
|
|
|
return R.success({ list });
|
|
});
|
|
|