File size: 2,986 Bytes
94193b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// lib/server-generate/types.ts
import type { MultiAgentOrchestrator } from '@/lib/llm/multi-agent-orchestrator';
import type { VirtualFileSystem } from '@/lib/vfs';
import type { ProviderId } from '@/lib/llm/providers/types';

/** Passed to MultiAgentOrchestrator when running server-side */
export interface ServerOrchestratorContext {
  apiBaseUrl: string;
  vfs: VirtualFileSystem;
  config: ServerGenerationParams;
  onEvent: (event: string, data: Record<string, unknown>) => void;
  /** Paths mutated since last flush — populated by VFS mutation proxy */
  dirtyPaths: Set<string>;
}

/** All config the server needs from the client to run generation */
export interface ServerGenerationParams {
  provider: ProviderId;
  model: string;
  apiKey: string;
  providerBaseUrl?: string;
  temperature?: number;
  maxTokens?: number;
  reasoningEnabled?: boolean;
  compactionEnabled?: boolean;
  compactionLimit?: number;
  debugStreamEnabled?: boolean;
  modelPricing?: Record<string, { prompt: number; completion: number }>;
  cachedModels?: Array<{ id: string; name: string; context_length?: number }>;
}

/** Server-side task state */
export interface ServerTask {
  taskId: string;
  projectId: string;
  sessionId: string;
  workspaceId?: string;
  status: 'running' | 'paused' | 'stopping' | 'completed' | 'failed' | 'cancelled';
  startedAt: number;
  orchestrator: MultiAgentOrchestrator | null;
  buildDeferred: boolean;
  /** Resolve function for pending build delegation */
  pendingBuildResolve: ((result: BuildResult) => void) | null;
  /** Metadata for client display (shelf) */
  prompt?: string;
  model?: string;
  projectName?: string;
}

export interface BuildResult {
  success: boolean;
  errors?: string[];
}

/** SSE event envelope */
export interface SSEEvent {
  id: number;
  event: string;
  data: Record<string, unknown> & { sourceProjectId: string };
  buffered: boolean; // false for delta events (not stored in replay buffer)
}

/** Start generation request body */
export interface StartGenerationRequest {
  projectId: string;
  prompt: string;
  model: string;
  apiKey: string;
  workspaceId?: string;
  projectName?: string;
  providerConfig?: { baseUrl?: string; provider?: ProviderId };
  permissionMode?: 'auto' | 'ask' | 'custom';
  permissionOverrides?: Record<string, 'ask' | 'allow'>;
  conversationHistory: unknown[];
  executeOptions?: {
    images?: Array<{ data: string; mediaType: string }>;
    focusContext?: { domPath: string; snippet: string };
    semanticBlocks?: Array<{ name: string; domPath: string; position: string; description: string }>;
    displayPrompt?: string;
  };
  generationParams: Omit<ServerGenerationParams, 'provider' | 'model' | 'apiKey' | 'providerBaseUrl'>;
}

/** Batch file fetch request */
export interface FileFetchRequest {
  taskId: string;
  paths: string[];
}

/** Batch file fetch response item */
export interface FileFetchResponseItem {
  path: string;
  content: string;
  binary: boolean;
}