feat(personal-assistant): add confirmed project memory
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import type {
|
||||
MemoryCandidate,
|
||||
MemoryConfirmRequest,
|
||||
MemoryConfirmResult,
|
||||
ServiceMemory
|
||||
} from '@/types/api';
|
||||
import { apiRequest } from './api';
|
||||
|
||||
const candidateBase = '/api/aihr/personal-assistant/memory-candidates';
|
||||
|
||||
type RawServiceMemory = Omit<ServiceMemory, 'version'> & { version?: number; currentVersion?: number };
|
||||
|
||||
const rowsOf = <T>(value: T[] | { rows?: T[]; records?: T[] } | null | undefined): T[] => {
|
||||
if (Array.isArray(value)) return value;
|
||||
return value?.rows || value?.records || [];
|
||||
};
|
||||
|
||||
export const createMemoryIdempotencyKey = (candidateId: number) => {
|
||||
const suffix = typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function'
|
||||
? crypto.randomUUID()
|
||||
: `${Date.now()}-${Math.random().toString(36).slice(2, 12)}`;
|
||||
return `memory-confirm-${candidateId}-${suffix}`;
|
||||
};
|
||||
|
||||
export const getMemoryCandidates = async (status = 'DRAFT') =>
|
||||
rowsOf(await apiRequest<MemoryCandidate[] | { rows?: MemoryCandidate[]; records?: MemoryCandidate[] }>({
|
||||
url: `${candidateBase}?status=${encodeURIComponent(status)}`,
|
||||
method: 'GET',
|
||||
timeout: 15000
|
||||
}));
|
||||
|
||||
export const confirmMemoryCandidate = (candidateId: number, request: MemoryConfirmRequest) =>
|
||||
apiRequest<MemoryConfirmResult>({
|
||||
url: `${candidateBase}/${candidateId}/confirm`,
|
||||
method: 'POST',
|
||||
data: request,
|
||||
timeout: 15000
|
||||
});
|
||||
|
||||
export const dismissMemoryCandidate = (candidateId: number) =>
|
||||
apiRequest<{ id: number; status: string }>({
|
||||
url: `${candidateBase}/${candidateId}/dismiss`,
|
||||
method: 'POST',
|
||||
timeout: 15000
|
||||
});
|
||||
|
||||
export const getServiceMemories = async () => {
|
||||
const rows = rowsOf(await apiRequest<RawServiceMemory[] | { rows?: RawServiceMemory[]; records?: RawServiceMemory[] }>({
|
||||
url: '/api/aihr/service-memories',
|
||||
method: 'GET',
|
||||
timeout: 15000
|
||||
}));
|
||||
return rows.map((item) => ({ ...item, version: item.version ?? item.currentVersion ?? 0 }));
|
||||
};
|
||||
Reference in New Issue
Block a user