fix: 完善AI流式后台任务与模型配置
This commit is contained in:
1 parent
0b35a58f07
commit
cdb64c5499
30 files changed
+1732
-150
No files matched your search
@@ -50,5 +50,25 @@ export interface AiConversationResult {
|
||||
planId: string | null;
|
||||
message: string;
|
||||
steps: AiPlanStep[];
|
||||
results: { action: string; label: string; data: unknown }[];
|
||||
results: { action: string; label: string; data: unknown; operation?: AiOperation }[];
|
||||
}
|
||||
export interface AiTaskDto {
|
||||
id: string;
|
||||
state: string;
|
||||
text: string;
|
||||
events: AiAgentEvent[];
|
||||
result?: AiConversationResult;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
export type AiReasoningEffort = 'auto' | 'none' | 'low' | 'medium' | 'high' | 'max';
|
||||
export interface AiModelInfo {
|
||||
id: string;
|
||||
name: string;
|
||||
efforts: AiReasoningEffort[];
|
||||
}
|
||||
export type AiAgentEvent =
|
||||
| { type: 'status'; message: string }
|
||||
| { type: 'message'; text: string }
|
||||
| { type: 'result'; result: AiConversationResult }
|
||||
| { type: 'error'; code: string; message: string; retryable: boolean };
|
||||
@@ -0,0 +1,19 @@
|
||||
/** 同时用于模型和应用 SSE;保留跨网络块的 UTF-8 解码由调用方负责。 */
|
||||
export class EventStreamDecoder {
|
||||
private buffer = '';
|
||||
constructor(private readonly maxBuffered = 1024 * 1024) {}
|
||||
push(chunk: string): string[] {
|
||||
this.buffer += chunk;
|
||||
if (this.buffer.length > this.maxBuffered) throw new Error('事件流单帧过大');
|
||||
const frames = this.buffer.split(/\r?\n\r?\n/);
|
||||
this.buffer = frames.pop() ?? '';
|
||||
return frames.flatMap((frame) => {
|
||||
const data = frame
|
||||
.split(/\r?\n/)
|
||||
.filter((line) => line.startsWith('data:'))
|
||||
.map((line) => line.slice(5).replace(/^ /, ''))
|
||||
.join('\n');
|
||||
return data ? [data] : [];
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -13,3 +13,4 @@ export type * from './types.js';
|
||||
export * from './courseware.js';
|
||||
export * from './lifecycle.js';
|
||||
export type * from './ai.js';
|
||||
export * from './event-stream.js';
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { AiConversationRequest } from './ai.js';
|
||||
import type { AiConversationRequest, AiReasoningEffort } from './ai.js';
|
||||
import type { CoursewareTransfer } from './courseware.js';
|
||||
import type {
|
||||
ClientUpdateProgressDto,
|
||||
@@ -1808,6 +1808,7 @@ export type AiProvider = 'openai' | 'mock';
|
||||
|
||||
/** `GET/PUT /api/ai/settings`:大模型设置(**API Key 只进不出**) */
|
||||
export interface AiSettingsDto {
|
||||
reasoningEffort: AiReasoningEffort;
|
||||
enabled: boolean;
|
||||
provider: AiProvider;
|
||||
baseUrl: string;
|
||||
@@ -1821,6 +1822,7 @@ export interface AiSettingsDto {
|
||||
}
|
||||
|
||||
export interface UpdateAiSettingsRequest {
|
||||
reasoningEffort?: AiReasoningEffort;
|
||||
enabled?: boolean;
|
||||
provider?: AiProvider;
|
||||
baseUrl?: string;
|
||||
|
||||
Reference in new issue
Block a user