意图理解
This commit is contained in:
1 parent
7e98d7dc52
commit
d639b24c2d
6 files changed
+292
-26
No files matched your search
@@ -36,6 +36,7 @@ import type {
|
||||
AIOutline,
|
||||
BlockedSection,
|
||||
CompletedIntervention,
|
||||
ParsedIntent,
|
||||
ProgressEvent,
|
||||
ProgressEventType,
|
||||
ReviewIssue,
|
||||
@@ -66,6 +67,9 @@ const INITIAL_STATE: AIWritingState = {
|
||||
streamingDraftSections: [],
|
||||
outlineStreamingText: '',
|
||||
outlineThinkingText: '',
|
||||
intentStreamingText: '',
|
||||
intentThinkingText: '',
|
||||
parsedIntent: null,
|
||||
researchProgress: '',
|
||||
streamingReviewItems: [],
|
||||
revisionSummary: null,
|
||||
@@ -146,6 +150,41 @@ function handleEvent(prev: AIWritingState, event: ProgressEvent): AIWritingState
|
||||
case 'step_done':
|
||||
return base;
|
||||
|
||||
case 'intent_chunk': {
|
||||
const text = (event as unknown as { text: string }).text ?? '';
|
||||
const isThinking = (event as unknown as { is_thinking: boolean }).is_thinking ?? false;
|
||||
return {
|
||||
...prev,
|
||||
intentStreamingText: isThinking ? prev.intentStreamingText : prev.intentStreamingText + text,
|
||||
intentThinkingText: isThinking ? prev.intentThinkingText + text : prev.intentThinkingText,
|
||||
};
|
||||
}
|
||||
|
||||
case 'intent_ready': {
|
||||
const ev = event as unknown as {
|
||||
articleType?: string;
|
||||
article_type?: string;
|
||||
targetAudience?: string;
|
||||
target_audience?: string;
|
||||
wordCountTarget?: number;
|
||||
word_count_target?: number;
|
||||
refinedIntent?: string;
|
||||
refined_intent?: string;
|
||||
};
|
||||
const parsed: ParsedIntent = {
|
||||
articleType: ev.articleType ?? ev.article_type ?? '',
|
||||
targetAudience: ev.targetAudience ?? ev.target_audience ?? '',
|
||||
wordCountTarget: Number(ev.wordCountTarget ?? ev.word_count_target ?? 800),
|
||||
refinedIntent: ev.refinedIntent ?? ev.refined_intent ?? '',
|
||||
};
|
||||
return {
|
||||
...base,
|
||||
parsedIntent: parsed,
|
||||
intentStreamingText: '',
|
||||
intentThinkingText: '',
|
||||
};
|
||||
}
|
||||
|
||||
case 'research_progress':
|
||||
return { ...base, researchProgress: event.message ?? '' };
|
||||
|
||||
@@ -403,6 +442,7 @@ function customToProgressEvent(raw: unknown, sessionId: string): ProgressEvent |
|
||||
// 后端 _save_draft_to_repo 等 helper 不走 custom 通道,type 必为节点 emit 的 chunk 类型
|
||||
if (!type) return null;
|
||||
const allowed: ProgressEventType[] = [
|
||||
'intent_chunk', 'intent_ready',
|
||||
'research_progress', 'outline_chunk', 'draft_chunk',
|
||||
'review_chunk', 'review_item_done',
|
||||
];
|
||||
|
||||
Reference in new issue
Block a user