fix: 完善AI流式后台任务与模型配置

This commit is contained in:
LoveChengke committed 2026-11-07 22:25:39 +08:00
1 parent 0b35a58f07
commit cdb64c5499
30 files changed
+1732 -150

No files matched your search

+21 -1
View File
@@ -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 };
+19
View File
@@ -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] : [];
});
}
}
+1
View File
@@ -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';
+3 -1
View File
@@ -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;