fix(evolution): add proper TypeScript types for API clients
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
c2b4fe19cc
commit
3b6d178ef7
|
|
@ -29,6 +29,14 @@ export interface MessageDto {
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API 响应类型
|
||||||
|
*/
|
||||||
|
interface ApiResponse<T> {
|
||||||
|
success: boolean;
|
||||||
|
data: T;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Conversation Service 客户端
|
* Conversation Service 客户端
|
||||||
* 用于调用 conversation-service 的内部 API
|
* 用于调用 conversation-service 的内部 API
|
||||||
|
|
@ -64,7 +72,7 @@ export class ConversationClient {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
const data = await response.json();
|
const data = (await response.json()) as ApiResponse<ConversationDto[]>;
|
||||||
|
|
||||||
if (!data.success) {
|
if (!data.success) {
|
||||||
throw new Error('Failed to fetch conversations');
|
throw new Error('Failed to fetch conversations');
|
||||||
|
|
@ -85,7 +93,7 @@ export class ConversationClient {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
const data = await response.json();
|
const data = (await response.json()) as ApiResponse<MessageDto[]>;
|
||||||
|
|
||||||
if (!data.success) {
|
if (!data.success) {
|
||||||
throw new Error('Failed to fetch messages');
|
throw new Error('Failed to fetch messages');
|
||||||
|
|
@ -114,7 +122,7 @@ export class ConversationClient {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
const data = await response.json();
|
const data = (await response.json()) as ApiResponse<{ count: number }>;
|
||||||
|
|
||||||
if (!data.success) {
|
if (!data.success) {
|
||||||
throw new Error('Failed to count conversations');
|
throw new Error('Failed to count conversations');
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,14 @@ export interface ExperienceStatisticsDto {
|
||||||
byType: Record<string, number>;
|
byType: Record<string, number>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API 响应类型
|
||||||
|
*/
|
||||||
|
interface ApiResponse<T> {
|
||||||
|
success: boolean;
|
||||||
|
data: T;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Knowledge Service 客户端
|
* Knowledge Service 客户端
|
||||||
* 用于调用 knowledge-service 的内部 API
|
* 用于调用 knowledge-service 的内部 API
|
||||||
|
|
@ -66,7 +74,7 @@ export class KnowledgeClient {
|
||||||
},
|
},
|
||||||
body: JSON.stringify(params),
|
body: JSON.stringify(params),
|
||||||
});
|
});
|
||||||
const data = await response.json();
|
const data = (await response.json()) as ApiResponse<ExperienceDto>;
|
||||||
|
|
||||||
if (!data.success) {
|
if (!data.success) {
|
||||||
throw new Error('Failed to save experience');
|
throw new Error('Failed to save experience');
|
||||||
|
|
@ -87,7 +95,7 @@ export class KnowledgeClient {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
const data = await response.json();
|
const data = (await response.json()) as ApiResponse<ExperienceStatisticsDto>;
|
||||||
|
|
||||||
if (!data.success) {
|
if (!data.success) {
|
||||||
throw new Error('Failed to get statistics');
|
throw new Error('Failed to get statistics');
|
||||||
|
|
@ -118,7 +126,7 @@ export class KnowledgeClient {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
const data = await response.json();
|
const data = (await response.json()) as ApiResponse<{ count: number }>;
|
||||||
|
|
||||||
if (!data.success) {
|
if (!data.success) {
|
||||||
throw new Error('Failed to count experiences');
|
throw new Error('Failed to count experiences');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue