fix(evolution): add proper TypeScript types for API clients

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-01-24 20:22:42 -08:00
parent c2b4fe19cc
commit 3b6d178ef7
2 changed files with 22 additions and 6 deletions

View File

@ -29,6 +29,14 @@ export interface MessageDto {
createdAt: Date;
}
/**
* API
*/
interface ApiResponse<T> {
success: boolean;
data: T;
}
/**
* Conversation Service
* conversation-service API
@ -64,7 +72,7 @@ export class ConversationClient {
try {
const response = await fetch(url);
const data = await response.json();
const data = (await response.json()) as ApiResponse<ConversationDto[]>;
if (!data.success) {
throw new Error('Failed to fetch conversations');
@ -85,7 +93,7 @@ export class ConversationClient {
try {
const response = await fetch(url);
const data = await response.json();
const data = (await response.json()) as ApiResponse<MessageDto[]>;
if (!data.success) {
throw new Error('Failed to fetch messages');
@ -114,7 +122,7 @@ export class ConversationClient {
try {
const response = await fetch(url);
const data = await response.json();
const data = (await response.json()) as ApiResponse<{ count: number }>;
if (!data.success) {
throw new Error('Failed to count conversations');

View File

@ -30,6 +30,14 @@ export interface ExperienceStatisticsDto {
byType: Record<string, number>;
}
/**
* API
*/
interface ApiResponse<T> {
success: boolean;
data: T;
}
/**
* Knowledge Service
* knowledge-service API
@ -66,7 +74,7 @@ export class KnowledgeClient {
},
body: JSON.stringify(params),
});
const data = await response.json();
const data = (await response.json()) as ApiResponse<ExperienceDto>;
if (!data.success) {
throw new Error('Failed to save experience');
@ -87,7 +95,7 @@ export class KnowledgeClient {
try {
const response = await fetch(url);
const data = await response.json();
const data = (await response.json()) as ApiResponse<ExperienceStatisticsDto>;
if (!data.success) {
throw new Error('Failed to get statistics');
@ -118,7 +126,7 @@ export class KnowledgeClient {
try {
const response = await fetch(url);
const data = await response.json();
const data = (await response.json()) as ApiResponse<{ count: number }>;
if (!data.success) {
throw new Error('Failed to count experiences');