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