feat(ai): unify AI architecture, implement RAG and legacy migration
CI / CD Pipeline / build (push) Failing after 5m36s
CI / CD Pipeline / deploy (push) Has been skipped

This commit is contained in:
2026-05-15 11:10:44 +07:00
parent 0240d80da5
commit 6cb3ae10ee
56 changed files with 6051 additions and 304 deletions
@@ -1,5 +1,7 @@
// File: src/modules/ai/entities/ai-audit-log.entity.ts
// Entity สำหรับตาราง ai_audit_logs — บันทึก AI Interaction ทุกครั้งตาม ADR-018 Rule 5
// Change Log
// - 2026-05-14: เพิ่ม ADR-023 feedback fields โดยคง legacy audit fields ไว้ช่วงเปลี่ยนผ่าน.
// Entity สำหรับตาราง ai_audit_logs — บันทึก AI Interaction และ feedback ตาม ADR-023
import {
Entity,
@@ -32,6 +34,24 @@ export class AiAuditLog extends UuidBaseEntity {
@Column({ name: 'ai_model', type: 'varchar', length: 50 })
aiModel!: string;
// ชื่อ Local Model ตาม ADR-023 development feedback log
@Index('idx_ai_audit_model_name')
@Column({ name: 'model_name', type: 'varchar', length: 100, nullable: true })
modelName?: string;
// JSON ที่ AI แนะนำก่อนมนุษย์ตรวจสอบ
@Column({ name: 'ai_suggestion_json', type: 'json', nullable: true })
aiSuggestionJson?: Record<string, unknown>;
// JSON ที่มนุษย์ยืนยันหรือแก้ไขจริง
@Column({ name: 'human_override_json', type: 'json', nullable: true })
humanOverrideJson?: Record<string, unknown>;
// User ID ภายในของผู้ยืนยันผล AI
@Index('idx_ai_audit_confirmed_by')
@Column({ name: 'confirmed_by_user_id', type: 'int', nullable: true })
confirmedByUserId?: number;
// เวลาประมวลผลเป็น milliseconds
@Column({ name: 'processing_time_ms', type: 'int', nullable: true })
processingTimeMs?: number;
@@ -0,0 +1,71 @@
// File: src/modules/ai/entities/migration-review.entity.ts
// Change Log
// - 2026-05-14: เพิ่ม entity staging queue สำหรับ Unified AI Architecture.
import {
Column,
CreateDateColumn,
Entity,
Index,
PrimaryGeneratedColumn,
UpdateDateColumn,
VersionColumn,
} from 'typeorm';
import { UuidBaseEntity } from '../../../common/entities/uuid-base.entity';
export enum MigrationReviewRecordStatus {
PENDING = 'PENDING',
IMPORTED = 'IMPORTED',
REJECTED = 'REJECTED',
}
/** รายการเอกสารเก่าที่รอ human-in-the-loop validation ก่อน commit */
@Entity('migration_review_queue')
export class MigrationReviewRecord extends UuidBaseEntity {
@PrimaryGeneratedColumn()
id!: number;
@Index('idx_migration_review_batch')
@Column({ name: 'batch_id', type: 'varchar', length: 100 })
batchId!: string;
@Column({ name: 'original_file_name', type: 'varchar', length: 255 })
originalFileName!: string;
@Column({ name: 'source_attachment_public_id', type: 'uuid', nullable: true })
sourceAttachmentPublicId?: string;
@Column({ name: 'temp_attachment_id', type: 'int', nullable: true })
tempAttachmentId?: number;
@Column({ name: 'extracted_metadata', type: 'json', nullable: true })
extractedMetadata?: Record<string, unknown>;
@Column({
name: 'confidence_score',
type: 'decimal',
precision: 4,
scale: 3,
nullable: true,
})
confidenceScore?: number;
@Index('idx_migration_review_status')
@Column({
type: 'enum',
enum: MigrationReviewRecordStatus,
default: MigrationReviewRecordStatus.PENDING,
})
status!: MigrationReviewRecordStatus;
@Column({ name: 'error_reason', type: 'text', nullable: true })
errorReason?: string;
@VersionColumn({ name: 'version' })
version!: number;
@CreateDateColumn({ name: 'created_at' })
createdAt!: Date;
@UpdateDateColumn({ name: 'updated_at' })
updatedAt!: Date;
}