Something went wrong. Try again.
because I got bored of customising my CV for every job
Something went wrong. Try again.
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131import { AI_PROVIDER, type AIProvider, registeredProviderTypes,} from "@cv/ai-provider";import { AdminGuard, JwtAuthGuard, VerifiedScopeGuard } from "@cv/auth";import { Inject, Optional, UseGuards } from "@nestjs/common";import { PageInfo } from "@cv/core";import { Args, Int, Query, Resolver } from "@nestjs/graphql";import { AiCallLogEntryType, AiProviderStatus, QueueMessageConnection, QueueStats, SystemStatus, WorkerHealth,} from "./admin.type";import { AiCallLogService } from "./ai-call-log.service";import { QueueMonitorService } from "./queue-monitor.service";
@Resolver()@UseGuards(JwtAuthGuard, VerifiedScopeGuard, AdminGuard)export class AdminResolver { constructor( @Inject(AI_PROVIDER) @Optional() private readonly globalProvider: AIProvider | undefined, private readonly aiCallLogService: AiCallLogService, private readonly queueMonitorService: QueueMonitorService, ) {}
@Query(() => SystemStatus) async systemStatus(): Promise<SystemStatus> { const status = new SystemStatus(); status.serverUptime = process.uptime(); status.registeredProviderTypes = registeredProviderTypes();
if (!this.globalProvider?.getStatus) { status.platformProvider = this.globalProvider ? { healthy: await this.globalProvider.isHealthy(), providerName: this.globalProvider.name, detailsJson: JSON.stringify(null), } : null;
return status; }
const providerStatus = await this.globalProvider.getStatus(); const platformProvider = new AiProviderStatus(); platformProvider.healthy = providerStatus.healthy; platformProvider.providerName = providerStatus.providerName; platformProvider.detailsJson = JSON.stringify( providerStatus.details ?? null, ); status.platformProvider = platformProvider;
return status; }
@Query(() => [AiCallLogEntryType]) aiCallLog( @Args("limit", { type: () => Int, nullable: true }) limit?: number, @Args("status", { type: () => String, nullable: true }) status?: string, @Args("providerName", { type: () => String, nullable: true }) providerName?: string, ): AiCallLogEntryType[] { const entries = this.aiCallLogService.getEntries(limit ?? undefined);
return entries.filter( (e) => (!status || e.status === status) && (!providerName || e.providerName === providerName), ); }
@Query(() => [AiCallLogEntryType]) async aiCallLogHistory( @Args("limit", { type: () => Int, nullable: true }) limit?: number, @Args("status", { type: () => String, nullable: true }) status?: string, @Args("providerName", { type: () => String, nullable: true }) providerName?: string, ): Promise<AiCallLogEntryType[]> { const rows = await this.aiCallLogService.queryHistory({ ...(limit != null ? { limit } : {}), ...(status != null ? { status } : {}), ...(providerName != null ? { providerName } : {}), });
return rows.map((r) => ({ id: r.id, timestamp: r.createdAt.toISOString(), providerName: r.providerName, durationMs: r.durationMs, promptTokens: r.promptTokens ?? undefined, completionTokens: r.completionTokens ?? undefined, model: r.model ?? undefined, finishReason: r.finishReason ?? undefined, status: r.status, error: r.error ?? undefined, userId: r.userId ?? undefined, source: r.source ?? undefined, })); }
@Query(() => QueueStats) async queueStats(): Promise<QueueStats> { const result = await this.queueMonitorService.getStats(); return QueueStats.fromDomain(result); }
@Query(() => QueueMessageConnection) async queueMessages( @Args("limit", { type: () => Int, nullable: true }) limit?: number, ): Promise<InstanceType<typeof QueueMessageConnection>> { const result = await this.queueMonitorService.getMessages(limit ?? undefined); return QueueMessageConnection.fromPaginationResult({ edges: result.map((r, i) => ({ node: r, cursor: String(i) })), pageInfo: new PageInfo(false, false, null, null), totalCount: result.length, }); }
@Query(() => [WorkerHealth]) async workerHealth(): Promise<WorkerHealth[]> { const results = await this.queueMonitorService.getWorkers(); return results.map(WorkerHealth.fromDomain); }}