返回 oh-my-ppt
types.ts
根目录 / src / main / generation / types.ts
1 import type { ModelTimeoutProfile } from '@shared/model-timeout'
2 import type {
3 AnimationPreferencesPayload,
4 DesignContract,
5 FontSelection,
6 SelectedElementRuntimeContext,
7 SourceDocumentPlan
8 } from '@shared/generation'
9 import type { CommonGenerationContext, GenerationDbPort } from './context'
10 import type { ModelRuntimeConfig } from '../agent-runtime/model'
11
12 export type GenerateMode = 'generate' | 'edit' | 'retry' | 'addPage' | 'retrySinglePage'
13 export type GenerateChatType = 'main' | 'page'
14
15 // Minimal context needed by finalize functions.
16 // Both GenerationContext and AddPageContext satisfy this interface.
17 export type FinalizeContext = {
18 sessionId: string
19 runId: string
20 styleId: string
21 previousSessionStatus: string
22 effectiveMode: GenerateMode
23 messageScope: GenerateChatType
24 messagePageId?: string
25 targetPageId?: string
26 projectId: string
27 modelConfigId?: string
28 modelConfigName?: string
29 runModel?: string
30 animationPreferences?: AnimationPreferencesPayload | null
31 }
32
33 export type GenerationRunContext = {
34 sessionId: string
35 userMessage: string
36 requestedType?: 'deck' | 'page'
37 effectiveMode: GenerateMode
38 selectedPageId?: string
39 selectPageIds: string[]
40 htmlPath?: string
41 selector?: string
42 elementTag?: string
43 elementText?: string
44 selectedElementContext?: SelectedElementRuntimeContext
45 sourceRunId?: string
46 session: Awaited<ReturnType<GenerationDbPort['getSession']>>
47 sessionRecord: Record<string, unknown>
48 previousSessionStatus: string
49 projectDir: string
50 abortSignal: AbortSignal
51 runId: string
52 styleId: string
53 styleSkill: CommonGenerationContext['styleSkill']
54 styleKey: string
55 styleName: string
56 styleVersion: string
57 slideSize: CommonGenerationContext['slideSize']
58 userProvidedOutlineTitles: string[]
59 totalPages: number
60 provider: string
61 apiKey: string
62 model: string
63 modelConfigId?: string
64 modelConfigName?: string
65 runModel?: string
66 maxTokens: number
67 modelRuntime: ModelRuntimeConfig
68 modelTimeouts: Record<ModelTimeoutProfile, number>
69 providerBaseUrl: string
70 projectId: string
71 messageScope: GenerateChatType
72 messagePageId?: string
73 imagePaths: string[]
74 videoPaths: string[]
75 sourceDocumentPaths: string[]
76 sourcePlan: SourceDocumentPlan | null
77 topic: string
78 deckTitle: string
79 appLocale: 'zh' | 'en'
80 fontSelection: FontSelection
81 animationPreferences: AnimationPreferencesPayload | null
82 }
83
84 export type DeckContext = GenerationRunContext & { effectiveMode: 'generate' }
85 export type EditContext = GenerationRunContext & {
86 effectiveMode: 'edit'
87 resetVisualStyle?: boolean
88 designContract?: DesignContract
89 onDeckEditStarted?: () => void
90 skipGenerationRunCreation?: boolean
91 }
92 export type RetryContext = GenerationRunContext & { effectiveMode: 'retry' }
93
94 export type AnyFlowContext =
95 | DeckContext
96 | EditContext
97 | RetryContext
98 | {
99 sessionId: string
100 runId: string
101 messageScope: GenerateChatType
102 messagePageId?: string
103 runModel?: string
104 }
105
106 export type FinalizeGenerationArgs = {
107 context: FinalizeContext
108 indexPath: string
109 totalPages: number
110 generatedPages: Array<{
111 id?: string
112 pageNumber: number
113 title: string
114 pageId: string
115 htmlPath: string
116 html: string
117 }>
118 designContract?: DesignContract
119 }
120
121 export type EmitAssistantFn = (context: AnyFlowContext, content: string) => Promise<void>
122
122 lines TYPESCRIPT