返回 oh-my-ppt
intent-router.ts
根目录 / src / main / thinking / intent-router.ts
1 import type { ThinkingStage } from '@shared/thinking'
2
3 export type ThinkingIntent =
4 | 'restart'
5 | 'plan_outline'
6 | 'expand_draft'
7 | 'refine'
8 | 'confirm_ready'
9 | 'collect_info'
10 | 'small_chat'
11
12 export interface ThinkingIntentRoute {
13 intent: ThinkingIntent
14 requestedStage: ThinkingStage | null
15 confidence: 'high' | 'medium' | 'low'
16 reason: string
17 }
18
19 export function routeThinkingIntent(args: {
20 userMessage: string
21 currentStage?: ThinkingStage
22 }): ThinkingIntentRoute {
23 const text = args.userMessage.trim()
24 const lower = text.toLowerCase()
25
26 if (/let's start over|start over|从头开始|重新开始/.test(lower)) {
27 return route('restart', 'collect', 'high', 'User explicitly asked to restart.')
28 }
29
30 if (/可以了|生成吧|开始生成|确认生成|就按这个|ready|confirm|looks good/.test(lower)) {
31 return route('confirm_ready', 'ready', 'high', 'User confirmed the current plan.')
32 }
33
34 if (
35 /展开|细化|详细|继续写|完善.*细节|补充.*细节|丰富.*内容|内容.*丰富|丰富一下|深入.*展开|逐页写|写详细|完善一下|expand|detail|flesh out/.test(
36 lower
37 )
38 ) {
39 return route('expand_draft', 'draft', 'high', 'User asked to flesh out details.')
40 }
41
42 if (/refine|polish|tweak|优化|调整.*细节|润色/.test(lower)) {
43 return route('refine', 'refine', 'high', 'User asked to refine or polish existing content.')
44 }
45
46 if (
47 /adjust.*outline|change.*structure|大纲|拆页|规划|需要.*设计|设计吧|设计一下|出大纲|调整.*大纲|修改.*结构|可以[,,]?\s*规划一下|规划一下|开始吧/.test(
48 lower
49 )
50 ) {
51 return route('plan_outline', 'outline', 'high', 'User asked for outline or page planning.')
52 }
53
54 if (args.currentStage === 'collect') {
55 return route('collect_info', null, 'medium', 'Collecting requirements before planning.')
56 }
57
58 return route('small_chat', null, 'low', 'No workflow transition intent detected.')
59 }
60
61 function route(
62 intent: ThinkingIntent,
63 requestedStage: ThinkingStage | null,
64 confidence: ThinkingIntentRoute['confidence'],
65 reason: string
66 ): ThinkingIntentRoute {
67 return {
68 intent,
69 requestedStage,
70 confidence,
71 reason
72 }
73 }
74
74 lines TYPESCRIPT