Trim legacy AI app APIs
This commit is contained in:
@@ -3,8 +3,7 @@ import { streamRequestClient } from '#/api/stream-request';
|
|||||||
import { useAppContextStore } from '#/store/app-context';
|
import { useAppContextStore } from '#/store/app-context';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注入系统变量到工作流输入
|
* Inject current application context into AI requests.
|
||||||
* 自动添加 application_id、application_code、form_code 等系统变量
|
|
||||||
*/
|
*/
|
||||||
function injectSystemVariables(
|
function injectSystemVariables(
|
||||||
inputs: Record<string, any>,
|
inputs: Record<string, any>,
|
||||||
@@ -12,20 +11,14 @@ function injectSystemVariables(
|
|||||||
const appContextStore = useAppContextStore();
|
const appContextStore = useAppContextStore();
|
||||||
const result = { ...inputs };
|
const result = { ...inputs };
|
||||||
|
|
||||||
// 注入 application_id(子应用模式下)
|
|
||||||
if (appContextStore.currentApp?.id && !result.application_id) {
|
if (appContextStore.currentApp?.id && !result.application_id) {
|
||||||
result.application_id = appContextStore.currentApp.id;
|
result.application_id = appContextStore.currentApp.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 注入 application_code(子应用模式下)
|
|
||||||
if (appContextStore.currentApp?.code && !result.application_code) {
|
if (appContextStore.currentApp?.code && !result.application_code) {
|
||||||
result.application_code = appContextStore.currentApp.code;
|
result.application_code = appContextStore.currentApp.code;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 注入 form_code(如果 inputs 中已经包含)
|
|
||||||
// form_code 通常由调用方(如表单列表)传入
|
|
||||||
// 这里不做额外处理,保持原样传递
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,103 +137,6 @@ export interface DefaultModel {
|
|||||||
output_price?: number;
|
output_price?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** AI 应用 */
|
|
||||||
export interface AIApp {
|
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
code: string;
|
|
||||||
description: string;
|
|
||||||
icon: string;
|
|
||||||
app_type: 'agent' | 'chat' | 'completion' | 'workflow';
|
|
||||||
status: 'disabled' | 'draft' | 'published';
|
|
||||||
model_id: null | string;
|
|
||||||
model_name: string;
|
|
||||||
system_prompt: string;
|
|
||||||
temperature: number;
|
|
||||||
top_p: number;
|
|
||||||
max_tokens: number;
|
|
||||||
opening_statement: string;
|
|
||||||
suggested_questions: string[];
|
|
||||||
workflow_definition: Record<string, any>;
|
|
||||||
is_public: boolean;
|
|
||||||
conversation_count: number;
|
|
||||||
message_count: number;
|
|
||||||
created_at: string;
|
|
||||||
updated_at: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 应用列表项 */
|
|
||||||
export interface AppListItem {
|
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
code: string;
|
|
||||||
description: string;
|
|
||||||
icon: string;
|
|
||||||
app_type: string;
|
|
||||||
status: string;
|
|
||||||
model_name: string;
|
|
||||||
is_public: boolean;
|
|
||||||
conversation_count: number;
|
|
||||||
message_count: number;
|
|
||||||
created_at: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 创建应用 */
|
|
||||||
export interface AppCreateInput {
|
|
||||||
name: string;
|
|
||||||
code: string;
|
|
||||||
description?: string;
|
|
||||||
icon?: string;
|
|
||||||
app_type?: string;
|
|
||||||
model_id?: string;
|
|
||||||
system_prompt?: string;
|
|
||||||
temperature?: number;
|
|
||||||
top_p?: number;
|
|
||||||
max_tokens?: number;
|
|
||||||
opening_statement?: string;
|
|
||||||
suggested_questions?: string[];
|
|
||||||
is_public?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 对话 */
|
|
||||||
export interface Conversation {
|
|
||||||
id: string;
|
|
||||||
app_id: string;
|
|
||||||
app_name: string;
|
|
||||||
title: string;
|
|
||||||
message_count: number;
|
|
||||||
total_tokens: number;
|
|
||||||
is_pinned: boolean;
|
|
||||||
created_at: string;
|
|
||||||
updated_at: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 对话列表项 */
|
|
||||||
export interface ConversationListItem {
|
|
||||||
id: string;
|
|
||||||
title: string;
|
|
||||||
message_count: number;
|
|
||||||
is_pinned: boolean;
|
|
||||||
updated_at: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 消息 */
|
|
||||||
export interface Message {
|
|
||||||
id: string;
|
|
||||||
role: 'assistant' | 'system' | 'user';
|
|
||||||
content: string;
|
|
||||||
status: 'completed' | 'failed' | 'pending' | 'stopped';
|
|
||||||
prompt_tokens: number;
|
|
||||||
completion_tokens: number;
|
|
||||||
total_tokens: number;
|
|
||||||
model_name: string;
|
|
||||||
latency: number;
|
|
||||||
error_message: string;
|
|
||||||
feedback: string;
|
|
||||||
created_at: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 工作流类型 */
|
|
||||||
export type WorkflowType = 'application' | 'automation' | 'data_process' | 'form' | 'general' | 'report';
|
export type WorkflowType = 'application' | 'automation' | 'data_process' | 'form' | 'general' | 'report';
|
||||||
|
|
||||||
/** AI 工作流 */
|
/** AI 工作流 */
|
||||||
@@ -491,179 +387,6 @@ export async function deleteModelApi(id: string) {
|
|||||||
return requestClient.delete(`${BASE_URL}/model/${id}`);
|
return requestClient.delete(`${BASE_URL}/model/${id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============ 应用 API ============
|
|
||||||
|
|
||||||
/** 获取应用列表 */
|
|
||||||
export async function getAppListApi(params?: {
|
|
||||||
app_type?: string;
|
|
||||||
name?: string;
|
|
||||||
page?: number;
|
|
||||||
pageSize?: number;
|
|
||||||
status?: string;
|
|
||||||
}) {
|
|
||||||
return requestClient.get<PaginatedResponse<AppListItem>>(
|
|
||||||
`${BASE_URL}/app/list`,
|
|
||||||
{ params },
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 获取已发布应用列表 */
|
|
||||||
export async function getPublishedAppsApi() {
|
|
||||||
return requestClient.get<AppListItem[]>(`${BASE_URL}/app/published`);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 获取应用详情 */
|
|
||||||
export async function getAppDetailApi(id: string) {
|
|
||||||
return requestClient.get<AIApp>(`${BASE_URL}/app/${id}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 根据编码获取应用 */
|
|
||||||
export async function getAppByCodeApi(code: string) {
|
|
||||||
return requestClient.get<AIApp>(`${BASE_URL}/app/code/${code}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 创建应用 */
|
|
||||||
export async function createAppApi(data: AppCreateInput) {
|
|
||||||
return requestClient.post<AIApp>(`${BASE_URL}/app`, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 更新应用 */
|
|
||||||
export async function updateAppApi(id: string, data: Partial<AppCreateInput>) {
|
|
||||||
return requestClient.put<AIApp>(`${BASE_URL}/app/${id}`, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 删除应用 */
|
|
||||||
export async function deleteAppApi(id: string) {
|
|
||||||
return requestClient.delete(`${BASE_URL}/app/${id}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 发布应用 */
|
|
||||||
export async function publishAppApi(id: string) {
|
|
||||||
return requestClient.post<AIApp>(`${BASE_URL}/app/${id}/publish`);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 停用应用 */
|
|
||||||
export async function disableAppApi(id: string) {
|
|
||||||
return requestClient.post<AIApp>(`${BASE_URL}/app/${id}/disable`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ============ 对话 API ============
|
|
||||||
|
|
||||||
/** 获取对话列表 */
|
|
||||||
export async function getConversationListApi(
|
|
||||||
appId: string,
|
|
||||||
params?: { page?: number; pageSize?: number },
|
|
||||||
) {
|
|
||||||
return requestClient.get<PaginatedResponse<ConversationListItem>>(
|
|
||||||
`${BASE_URL}/chat/conversations`,
|
|
||||||
{ params: { app_id: appId, ...params } },
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 创建对话 */
|
|
||||||
export async function createConversationApi(data: {
|
|
||||||
app_id: string;
|
|
||||||
title?: string;
|
|
||||||
}) {
|
|
||||||
return requestClient.post<Conversation>(
|
|
||||||
`${BASE_URL}/chat/conversations`,
|
|
||||||
data,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 获取对话详情 */
|
|
||||||
export async function getConversationDetailApi(id: string) {
|
|
||||||
return requestClient.get<Conversation>(
|
|
||||||
`${BASE_URL}/chat/conversations/${id}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 更新对话 */
|
|
||||||
export async function updateConversationApi(
|
|
||||||
id: string,
|
|
||||||
data: { is_pinned?: boolean; title?: string },
|
|
||||||
) {
|
|
||||||
return requestClient.put<Conversation>(
|
|
||||||
`${BASE_URL}/chat/conversations/${id}`,
|
|
||||||
data,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 删除对话 */
|
|
||||||
export async function deleteConversationApi(id: string) {
|
|
||||||
return requestClient.delete(`${BASE_URL}/chat/conversations/${id}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 获取消息列表 */
|
|
||||||
export async function getMessagesApi(conversationId: string, limit?: number) {
|
|
||||||
return requestClient.get<Message[]>(
|
|
||||||
`${BASE_URL}/chat/conversations/${conversationId}/messages`,
|
|
||||||
{ params: { limit } },
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 发送消息 */
|
|
||||||
export async function sendMessageApi(conversationId: string, content: string) {
|
|
||||||
return requestClient.post<Message>(
|
|
||||||
`${BASE_URL}/chat/conversations/${conversationId}/messages`,
|
|
||||||
{ content },
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 聊天流式事件类型 */
|
|
||||||
export interface ChatStreamEvent {
|
|
||||||
type: 'content' | 'done' | 'error';
|
|
||||||
content?: string;
|
|
||||||
message?: {
|
|
||||||
content: string;
|
|
||||||
id: string;
|
|
||||||
latency: number;
|
|
||||||
tokens: number;
|
|
||||||
};
|
|
||||||
error?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 流式发送消息 */
|
|
||||||
export function sendMessageStreamApi(
|
|
||||||
conversationId: string,
|
|
||||||
content: string,
|
|
||||||
onEvent: (event: ChatStreamEvent) => void,
|
|
||||||
onError?: (error: Error) => void,
|
|
||||||
onComplete?: () => void,
|
|
||||||
): () => void {
|
|
||||||
return streamRequestClient<ChatStreamEvent>(
|
|
||||||
`${BASE_URL}/chat/conversations/${conversationId}/messages/stream`,
|
|
||||||
{ content },
|
|
||||||
{
|
|
||||||
onData: onEvent,
|
|
||||||
onError: (error) => {
|
|
||||||
console.error('Stream error:', error);
|
|
||||||
onError?.(error);
|
|
||||||
},
|
|
||||||
onComplete,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 消息反馈 */
|
|
||||||
export async function messageFeedbackApi(
|
|
||||||
messageId: string,
|
|
||||||
feedback: 'dislike' | 'like',
|
|
||||||
) {
|
|
||||||
return requestClient.post(`${BASE_URL}/chat/messages/${messageId}/feedback`, {
|
|
||||||
feedback,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 重新生成消息 */
|
|
||||||
export async function regenerateMessageApi(messageId: string) {
|
|
||||||
return requestClient.post<Message>(
|
|
||||||
`${BASE_URL}/chat/messages/${messageId}/regenerate`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ============ 工作流 API ============
|
|
||||||
|
|
||||||
/** 获取节点 Schema 列表 */
|
/** 获取节点 Schema 列表 */
|
||||||
export async function getNodeSchemasApi() {
|
export async function getNodeSchemasApi() {
|
||||||
return requestClient.get<NodeSchema[]>(`${BASE_URL}/workflow/nodes/schemas`);
|
return requestClient.get<NodeSchema[]>(`${BASE_URL}/workflow/nodes/schemas`);
|
||||||
@@ -966,7 +689,7 @@ export function runWorkflowStreamApi(
|
|||||||
onComplete?: () => void,
|
onComplete?: () => void,
|
||||||
useDraft: boolean = false,
|
useDraft: boolean = false,
|
||||||
): () => void {
|
): () => void {
|
||||||
// 自动注入系统变量(application_id 等)
|
// Inject current application context.
|
||||||
const finalInputs = injectSystemVariables(inputs);
|
const finalInputs = injectSystemVariables(inputs);
|
||||||
|
|
||||||
return streamRequestClient<WorkflowStreamEvent>(
|
return streamRequestClient<WorkflowStreamEvent>(
|
||||||
@@ -1488,14 +1211,13 @@ export function sendAgentMessageStream(
|
|||||||
data: {
|
data: {
|
||||||
attachments?: AttachmentInput[];
|
attachments?: AttachmentInput[];
|
||||||
conversation_id?: string;
|
conversation_id?: string;
|
||||||
form_code?: string;
|
|
||||||
message: string;
|
message: string;
|
||||||
},
|
},
|
||||||
onEvent: (event: AgentChatEvent) => void,
|
onEvent: (event: AgentChatEvent) => void,
|
||||||
onError?: (error: Error) => void,
|
onError?: (error: Error) => void,
|
||||||
onComplete?: () => void,
|
onComplete?: () => void,
|
||||||
) {
|
) {
|
||||||
// 自动注入系统变量(application_id、form_code 等)
|
// Inject current application context.
|
||||||
const finalData = injectSystemVariables(data);
|
const finalData = injectSystemVariables(data);
|
||||||
|
|
||||||
return streamRequestClient<AgentChatEvent>(
|
return streamRequestClient<AgentChatEvent>(
|
||||||
|
|||||||
Reference in New Issue
Block a user