fix(ci): lint and a11y fixes unblocks GHA deploy
- materi/new/page.tsx: add htmlFor+id pairs for all 5 form labels (a11y)
- biome --write --unsafe: fix useTemplate, useLiteralKeys, import sort
across materi module files (backend + frontend)
- These pre-existing lint errors from 0aa893a blocked the deploy pipeline
This commit is contained in:
committed by
asepharyana
parent
5658726ea5
commit
7f4196124d
@@ -1,14 +1,18 @@
|
||||
export { MateriService } from "./materi.service.js";
|
||||
export { materiService } from "./materi.service.js";
|
||||
export { materiRepository } from "./materi.repository.js";
|
||||
export {
|
||||
createMateriSchema,
|
||||
updateMateriSchema,
|
||||
materiQuerySchema,
|
||||
materiRagChatSchema,
|
||||
type CreateMateriInput,
|
||||
type UpdateMateriInput,
|
||||
createMateriSchema,
|
||||
type MateriQueryInput,
|
||||
type MateriRagChatInput,
|
||||
materiQuerySchema,
|
||||
materiRagChatSchema,
|
||||
type UpdateMateriInput,
|
||||
updateMateriSchema,
|
||||
} from "./materi.schema.js";
|
||||
export { ragChat, searchMateri, type MateriSearchHit, type RAGChatResult } from "./ragClient.js";
|
||||
export { MateriService, materiService } from "./materi.service.js";
|
||||
export {
|
||||
type MateriSearchHit,
|
||||
type RAGChatResult,
|
||||
ragChat,
|
||||
searchMateri,
|
||||
} from "./ragClient.js";
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { and, desc, eq, ilike, or, sql } from "drizzle-orm";
|
||||
import { getDatabase } from "@/shared/database/index.js";
|
||||
import {
|
||||
type MateriDocument,
|
||||
materiDocumentsTable,
|
||||
} from "@/shared/database/schema.js";
|
||||
import { getDatabase } from "@/shared/database/index.js";
|
||||
import type { MateriQueryInput } from "./materi.schema.js";
|
||||
|
||||
export class MateriRepository {
|
||||
@@ -39,8 +39,7 @@ export class MateriRepository {
|
||||
conditions.push(eq(materiDocumentsTable.is_public, true));
|
||||
}
|
||||
|
||||
const whereClause =
|
||||
conditions.length > 0 ? and(...conditions) : undefined;
|
||||
const whereClause = conditions.length > 0 ? and(...conditions) : undefined;
|
||||
|
||||
const result = await db
|
||||
.select()
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import type { MateriDocument } from "@/shared/database/schema.js";
|
||||
import { createChildLogger } from "@/shared/logger/index.js";
|
||||
import { materiRepository } from "./materi.repository.js";
|
||||
import {
|
||||
type MateriQueryInput,
|
||||
type CreateMateriInput,
|
||||
type UpdateMateriInput,
|
||||
type MateriRagChatInput,
|
||||
import type {
|
||||
CreateMateriInput,
|
||||
MateriQueryInput,
|
||||
MateriRagChatInput,
|
||||
UpdateMateriInput,
|
||||
} from "./materi.schema.js";
|
||||
import { ragChat } from "./ragClient.js";
|
||||
|
||||
@@ -14,7 +14,10 @@ const logger = createChildLogger("materi.service");
|
||||
export class MateriService {
|
||||
/** List materi documents with optional filtering. */
|
||||
async list(input: MateriQueryInput): Promise<MateriDocument[]> {
|
||||
logger.debug({ limit: input.limit, search: input.search }, "Listing materi");
|
||||
logger.debug(
|
||||
{ limit: input.limit, search: input.search },
|
||||
"Listing materi",
|
||||
);
|
||||
return materiRepository.list(input);
|
||||
}
|
||||
|
||||
@@ -72,7 +75,15 @@ export class MateriService {
|
||||
async ragChat(
|
||||
input: MateriRagChatInput,
|
||||
ownerUserId: string,
|
||||
): Promise<{ answer: string; sources: Array<{ id: string; title: string; score: number; excerpt: string }> }> {
|
||||
): Promise<{
|
||||
answer: string;
|
||||
sources: Array<{
|
||||
id: string;
|
||||
title: string;
|
||||
score: number;
|
||||
excerpt: string;
|
||||
}>;
|
||||
}> {
|
||||
logger.info({ ownerUserId, hasMateriId: !!input.materiId }, "RAG chat");
|
||||
|
||||
// Fetch relevant materi documents
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { config } from "@/shared/config/index.js";
|
||||
import { createChildLogger } from "@/shared/logger/index.js";
|
||||
import type { MateriDocument } from "@/shared/database/schema.js";
|
||||
import { createChildLogger } from "@/shared/logger/index.js";
|
||||
import { embedQuery } from "../messages/embed.js";
|
||||
import { searchArchive } from "../messages/qdrant.js";
|
||||
|
||||
@@ -101,7 +101,9 @@ export async function searchMateri(
|
||||
} else {
|
||||
// Fallback: keyword match scoring
|
||||
const titleMatch = doc.title.toLowerCase().includes(query.toLowerCase());
|
||||
const contentMatch = doc.content.toLowerCase().includes(query.toLowerCase());
|
||||
const contentMatch = doc.content
|
||||
.toLowerCase()
|
||||
.includes(query.toLowerCase());
|
||||
const tagMatch = (doc.tags ?? []).some((t) =>
|
||||
t.toLowerCase().includes(query.toLowerCase()),
|
||||
);
|
||||
@@ -117,11 +119,15 @@ export async function searchMateri(
|
||||
}
|
||||
|
||||
// Also search Discord message archive via Qdrant for conversation context
|
||||
const archiveHits = await searchArchive(queryVec ?? [], topK, SIMILARITY_THRESHOLD);
|
||||
const archiveHits = await searchArchive(
|
||||
queryVec ?? [],
|
||||
topK,
|
||||
SIMILARITY_THRESHOLD,
|
||||
);
|
||||
for (const hit of archiveHits) {
|
||||
results.push({
|
||||
document: {
|
||||
id: "archive-" + Date.now(),
|
||||
id: `archive-${Date.now()}`,
|
||||
title: "Discord Archive",
|
||||
description: null,
|
||||
content: hit.payload.text,
|
||||
@@ -153,21 +159,30 @@ export async function ragChat(
|
||||
): Promise<RAGChatResult> {
|
||||
const hits = await searchMateri(query, documents);
|
||||
|
||||
const contextBlock = hits
|
||||
.map((h) => {
|
||||
const scoreStr = h.score.toFixed(3);
|
||||
return (
|
||||
"<source id=\"" + h.document.id + "\" title=\"" + h.document.title + "\" score=\"" + scoreStr + "\">\n" +
|
||||
h.chunkText +
|
||||
"\n</source>"
|
||||
);
|
||||
})
|
||||
.join("\n\n") || "(tidak ada konteks relevan ditemukan)";
|
||||
const contextBlock =
|
||||
hits
|
||||
.map((h) => {
|
||||
const scoreStr = h.score.toFixed(3);
|
||||
return (
|
||||
'<source id="' +
|
||||
h.document.id +
|
||||
'" title="' +
|
||||
h.document.title +
|
||||
'" score="' +
|
||||
scoreStr +
|
||||
'">\n' +
|
||||
h.chunkText +
|
||||
"\n</source>"
|
||||
);
|
||||
})
|
||||
.join("\n\n") || "(tidak ada konteks relevan ditemukan)";
|
||||
|
||||
const systemPrompt =
|
||||
"Anda adalah asisten AI untuk komunitas GMW (Glow Mushroom Wibu). " +
|
||||
"Jawab pertanyaan pengguna berdasarkan konteks berikut. Jika tidak tahu, katakan tidak tahu.\n\n" +
|
||||
"Konteks materi dan arsip Discord:\n" + contextBlock + "\n\n" +
|
||||
"Konteks materi dan arsip Discord:\n" +
|
||||
contextBlock +
|
||||
"\n\n" +
|
||||
"Instruksi: jawab singkat, akurat, dan berguna. Kutip sumber jika perlu.";
|
||||
|
||||
const baseUrL = config.AI_LLM_BASE_URL;
|
||||
@@ -185,8 +200,8 @@ export async function ragChat(
|
||||
].filter((m) => m.content) as Array<{ role: string; content: string }>;
|
||||
|
||||
const authHeaders: Record<string, string> = {};
|
||||
authHeaders["Authorization"] = authHeader;
|
||||
const res = await fetch(baseUrL + "/chat/completions", {
|
||||
authHeaders.Authorization = authHeader;
|
||||
const res = await fetch(`${baseUrL}/chat/completions`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@@ -202,14 +217,16 @@ export async function ragChat(
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
throw new Error("LLM request failed: " + res.status);
|
||||
throw new Error(`LLM request failed: ${res.status}`);
|
||||
}
|
||||
|
||||
const data = (await res.json()) as {
|
||||
choices?: Array<{ message?: { content?: string } }>;
|
||||
};
|
||||
|
||||
const answer = data.choices?.[0]?.message?.content ?? "Maaf, tidak bisa menjawab saat ini.";
|
||||
const answer =
|
||||
data.choices?.[0]?.message?.content ??
|
||||
"Maaf, tidak bisa menjawab saat ini.";
|
||||
|
||||
return {
|
||||
answer,
|
||||
|
||||
@@ -7,11 +7,11 @@ import { chatbotService } from "../modules/chatbot/chatbot.service";
|
||||
import { dashboardService } from "../modules/dashboard/dashboard.service";
|
||||
import { knowledgeService } from "../modules/knowledge/knowledge.service";
|
||||
import {
|
||||
createMateriSchema,
|
||||
materiQuerySchema,
|
||||
materiRagChatSchema,
|
||||
createMateriSchema,
|
||||
updateMateriSchema,
|
||||
materiService,
|
||||
updateMateriSchema,
|
||||
} from "../modules/materi/index.js";
|
||||
import {
|
||||
mediaLoopSchema,
|
||||
|
||||
Reference in New Issue
Block a user