agentgui 1.0.110 → 1.0.112
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prd +281 -0
- package/database.js +87 -0
- package/package.json +2 -2
- package/server.js +25 -2
- package/static/index.html +50 -4
- package/static/js/client.js +14 -7
- package/static/js/conversations.js +41 -2
- package/conversation-importer.js +0 -63
- package/hot-reload-manager.js +0 -186
- package/lib/database-service.ts +0 -640
- package/lib/machines.ts +0 -190
- package/lib/schemas.ts +0 -190
- package/lib/sync-service.ts +0 -615
- package/lib/types.ts +0 -413
package/lib/types.ts
DELETED
|
@@ -1,413 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TYPES.TS - Complete type definitions for the separated data and sync system
|
|
3
|
-
* Guarantees type safety across CLI tests, server, and client
|
|
4
|
-
* Immutable by design - all structures are readonly
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
// ============================================================================
|
|
8
|
-
// CONVERSATION TYPES
|
|
9
|
-
// ============================================================================
|
|
10
|
-
|
|
11
|
-
export interface Conversation {
|
|
12
|
-
readonly id: string;
|
|
13
|
-
readonly agentId: string;
|
|
14
|
-
readonly title: string | null;
|
|
15
|
-
readonly created_at: number;
|
|
16
|
-
readonly updated_at: number;
|
|
17
|
-
readonly status: ConversationStatus;
|
|
18
|
-
readonly agentType?: string;
|
|
19
|
-
readonly source?: 'gui' | 'imported';
|
|
20
|
-
readonly externalId?: string;
|
|
21
|
-
readonly firstPrompt?: string;
|
|
22
|
-
readonly messageCount?: number;
|
|
23
|
-
readonly projectPath?: string;
|
|
24
|
-
readonly gitBranch?: string;
|
|
25
|
-
readonly sourcePath?: string;
|
|
26
|
-
readonly lastSyncedAt?: number;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export type ConversationStatus = 'active' | 'archived' | 'deleted';
|
|
30
|
-
|
|
31
|
-
export interface ConversationCreateInput {
|
|
32
|
-
agentId: string;
|
|
33
|
-
title?: string | null;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface ConversationUpdateInput {
|
|
37
|
-
title?: string;
|
|
38
|
-
status?: ConversationStatus;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// ============================================================================
|
|
42
|
-
// MESSAGE TYPES
|
|
43
|
-
// ============================================================================
|
|
44
|
-
|
|
45
|
-
export interface Message {
|
|
46
|
-
readonly id: string;
|
|
47
|
-
readonly conversationId: string;
|
|
48
|
-
readonly role: MessageRole;
|
|
49
|
-
readonly content: string;
|
|
50
|
-
readonly created_at: number;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export type MessageRole = 'user' | 'assistant' | 'system';
|
|
54
|
-
|
|
55
|
-
export interface MessageCreateInput {
|
|
56
|
-
conversationId: string;
|
|
57
|
-
role: MessageRole;
|
|
58
|
-
content: string;
|
|
59
|
-
idempotencyKey?: string;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// ============================================================================
|
|
63
|
-
// SESSION TYPES (for message processing)
|
|
64
|
-
// ============================================================================
|
|
65
|
-
|
|
66
|
-
export interface Session {
|
|
67
|
-
readonly id: string;
|
|
68
|
-
readonly conversationId: string;
|
|
69
|
-
readonly status: SessionStatus;
|
|
70
|
-
readonly started_at: number;
|
|
71
|
-
readonly completed_at?: number;
|
|
72
|
-
readonly response?: SessionResponse;
|
|
73
|
-
readonly error?: string;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export type SessionStatus = 'pending' | 'processing' | 'completed' | 'error' | 'cancelled';
|
|
77
|
-
|
|
78
|
-
export interface SessionResponse {
|
|
79
|
-
readonly text: string;
|
|
80
|
-
readonly messageId: string;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// ============================================================================
|
|
84
|
-
// SYNC STATE TYPES
|
|
85
|
-
// ============================================================================
|
|
86
|
-
|
|
87
|
-
export type SyncState = 'idle' | 'loading' | 'synced' | 'error' | 'offline' | 'reconciling';
|
|
88
|
-
|
|
89
|
-
export interface SyncStatus {
|
|
90
|
-
readonly state: SyncState;
|
|
91
|
-
readonly lastSyncTime?: number;
|
|
92
|
-
readonly nextRetryTime?: number;
|
|
93
|
-
readonly error?: string;
|
|
94
|
-
readonly retryCount: number;
|
|
95
|
-
readonly maxRetries: number;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export interface SyncEvent {
|
|
99
|
-
readonly type: SyncEventType;
|
|
100
|
-
readonly timestamp: number;
|
|
101
|
-
readonly data: Record<string, unknown>;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export type SyncEventType =
|
|
105
|
-
| 'conversation_created'
|
|
106
|
-
| 'conversation_updated'
|
|
107
|
-
| 'conversation_deleted'
|
|
108
|
-
| 'message_created'
|
|
109
|
-
| 'message_updated'
|
|
110
|
-
| 'message_deleted'
|
|
111
|
-
| 'sync_started'
|
|
112
|
-
| 'sync_completed'
|
|
113
|
-
| 'sync_failed'
|
|
114
|
-
| 'offline_detected'
|
|
115
|
-
| 'online_detected';
|
|
116
|
-
|
|
117
|
-
// ============================================================================
|
|
118
|
-
// PAGINATION TYPES
|
|
119
|
-
// ============================================================================
|
|
120
|
-
|
|
121
|
-
export interface PaginationParams {
|
|
122
|
-
readonly limit: number;
|
|
123
|
-
readonly offset: number;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export interface PaginatedResult<T> {
|
|
127
|
-
readonly items: readonly T[];
|
|
128
|
-
readonly total: number;
|
|
129
|
-
readonly limit: number;
|
|
130
|
-
readonly offset: number;
|
|
131
|
-
readonly hasMore: boolean;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// ============================================================================
|
|
135
|
-
// IDEMPOTENCY TYPES
|
|
136
|
-
// ============================================================================
|
|
137
|
-
|
|
138
|
-
export interface IdempotencyKey {
|
|
139
|
-
readonly key: string;
|
|
140
|
-
readonly value: string;
|
|
141
|
-
readonly created_at: number;
|
|
142
|
-
readonly ttl: number;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// ============================================================================
|
|
146
|
-
// ERROR TYPES
|
|
147
|
-
// ============================================================================
|
|
148
|
-
|
|
149
|
-
export class SyncError extends Error {
|
|
150
|
-
constructor(
|
|
151
|
-
public code: string,
|
|
152
|
-
public message: string,
|
|
153
|
-
public retryable: boolean = false,
|
|
154
|
-
public context?: Record<string, unknown>
|
|
155
|
-
) {
|
|
156
|
-
super(message);
|
|
157
|
-
this.name = 'SyncError';
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
export type ErrorCode =
|
|
162
|
-
| 'DATABASE_ERROR'
|
|
163
|
-
| 'NETWORK_ERROR'
|
|
164
|
-
| 'SYNC_CONFLICT'
|
|
165
|
-
| 'VALIDATION_ERROR'
|
|
166
|
-
| 'NOT_FOUND'
|
|
167
|
-
| 'UNAUTHORIZED'
|
|
168
|
-
| 'TIMEOUT'
|
|
169
|
-
| 'UNKNOWN';
|
|
170
|
-
|
|
171
|
-
// ============================================================================
|
|
172
|
-
// STATE MACHINE CONTEXT
|
|
173
|
-
// ============================================================================
|
|
174
|
-
|
|
175
|
-
export interface SyncMachineContext {
|
|
176
|
-
readonly conversationId?: string;
|
|
177
|
-
readonly messageId?: string;
|
|
178
|
-
readonly lastError?: Error;
|
|
179
|
-
readonly retryCount: number;
|
|
180
|
-
readonly syncData: Record<string, unknown>;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
// ============================================================================
|
|
184
|
-
// API RESPONSE TYPES
|
|
185
|
-
// ============================================================================
|
|
186
|
-
|
|
187
|
-
export interface ApiResponse<T> {
|
|
188
|
-
readonly data?: T;
|
|
189
|
-
readonly error?: string;
|
|
190
|
-
readonly timestamp: number;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
export interface ConversationsListResponse {
|
|
194
|
-
readonly conversations: readonly Conversation[];
|
|
195
|
-
readonly total: number;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
export interface MessagesListResponse {
|
|
199
|
-
readonly messages: readonly Message[];
|
|
200
|
-
readonly total: number;
|
|
201
|
-
readonly hasMore: boolean;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
// ============================================================================
|
|
205
|
-
// VALIDATION RESULT TYPES
|
|
206
|
-
// ============================================================================
|
|
207
|
-
|
|
208
|
-
export interface ValidationResult {
|
|
209
|
-
readonly valid: boolean;
|
|
210
|
-
readonly errors: readonly ValidationError[];
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
export interface ValidationError {
|
|
214
|
-
readonly field: string;
|
|
215
|
-
readonly message: string;
|
|
216
|
-
readonly value?: unknown;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// ============================================================================
|
|
220
|
-
// CONFLICT RESOLUTION TYPES
|
|
221
|
-
// ============================================================================
|
|
222
|
-
|
|
223
|
-
export type ConflictResolutionStrategy = 'last-write-wins' | 'server-wins' | 'client-wins';
|
|
224
|
-
|
|
225
|
-
export interface ConflictInfo {
|
|
226
|
-
readonly localVersion: unknown;
|
|
227
|
-
readonly remoteVersion: unknown;
|
|
228
|
-
readonly resolution: ConflictResolutionStrategy;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
// ============================================================================
|
|
232
|
-
// RECOVERY TYPES
|
|
233
|
-
// ============================================================================
|
|
234
|
-
|
|
235
|
-
export interface RecoveryCheckpoint {
|
|
236
|
-
readonly timestamp: number;
|
|
237
|
-
readonly synced: boolean;
|
|
238
|
-
readonly data: Record<string, unknown>;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
export interface RecoveryState {
|
|
242
|
-
readonly lastCheckpoint?: RecoveryCheckpoint;
|
|
243
|
-
readonly pendingOperations: readonly unknown[];
|
|
244
|
-
readonly offline: boolean;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
// ============================================================================
|
|
248
|
-
// STREAMING & EXECUTION TYPES
|
|
249
|
-
// ============================================================================
|
|
250
|
-
|
|
251
|
-
export type ContentBlockType = 'text' | 'image' | 'tool_use' | 'tool_result' | 'document';
|
|
252
|
-
|
|
253
|
-
export interface TextBlock {
|
|
254
|
-
readonly type: 'text';
|
|
255
|
-
readonly text: string;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
export interface ImageBlock {
|
|
259
|
-
readonly type: 'image';
|
|
260
|
-
readonly source: {
|
|
261
|
-
readonly type: 'url' | 'base64';
|
|
262
|
-
readonly url?: string;
|
|
263
|
-
readonly media_type?: string;
|
|
264
|
-
readonly data?: string;
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
export interface ToolUseBlock {
|
|
269
|
-
readonly type: 'tool_use';
|
|
270
|
-
readonly id: string;
|
|
271
|
-
readonly name: string;
|
|
272
|
-
readonly input: Record<string, unknown>;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
export interface ToolResultBlock {
|
|
276
|
-
readonly type: 'tool_result';
|
|
277
|
-
readonly tool_use_id: string;
|
|
278
|
-
readonly content: string;
|
|
279
|
-
readonly is_error?: boolean;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
export interface DocumentBlock {
|
|
283
|
-
readonly type: 'document';
|
|
284
|
-
readonly source: {
|
|
285
|
-
readonly type: 'url' | 'base64' | 'file';
|
|
286
|
-
readonly url?: string;
|
|
287
|
-
readonly media_type?: string;
|
|
288
|
-
readonly data?: string;
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
export type ContentBlock = TextBlock | ImageBlock | ToolUseBlock | ToolResultBlock | DocumentBlock;
|
|
293
|
-
|
|
294
|
-
export interface ClaudeMessage {
|
|
295
|
-
readonly id: string;
|
|
296
|
-
readonly type: 'message';
|
|
297
|
-
readonly role: 'user' | 'assistant';
|
|
298
|
-
readonly content: readonly ContentBlock[];
|
|
299
|
-
readonly model?: string;
|
|
300
|
-
readonly stop_reason?: 'end_turn' | 'max_tokens' | 'tool_use' | 'stop_sequence';
|
|
301
|
-
readonly stop_sequence?: string;
|
|
302
|
-
readonly usage?: {
|
|
303
|
-
readonly input_tokens: number;
|
|
304
|
-
readonly output_tokens: number;
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
export interface ExecutionMetadata {
|
|
309
|
-
readonly sessionId: string;
|
|
310
|
-
readonly conversationId: string;
|
|
311
|
-
readonly agentId: string;
|
|
312
|
-
readonly startTime: number;
|
|
313
|
-
readonly endTime?: number;
|
|
314
|
-
readonly duration?: number;
|
|
315
|
-
readonly inputTokens?: number;
|
|
316
|
-
readonly outputTokens?: number;
|
|
317
|
-
readonly totalTokens?: number;
|
|
318
|
-
readonly toolCalls: number;
|
|
319
|
-
readonly toolResults: number;
|
|
320
|
-
readonly errorCount: number;
|
|
321
|
-
readonly status: 'running' | 'completed' | 'error' | 'timeout' | 'interrupted';
|
|
322
|
-
readonly errorMessage?: string;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
export type StreamingEventType =
|
|
326
|
-
| 'streaming_start'
|
|
327
|
-
| 'content_block_start'
|
|
328
|
-
| 'content_block_delta'
|
|
329
|
-
| 'content_block_stop'
|
|
330
|
-
| 'message_start'
|
|
331
|
-
| 'message_delta'
|
|
332
|
-
| 'message_stop'
|
|
333
|
-
| 'streaming_error'
|
|
334
|
-
| 'streaming_complete';
|
|
335
|
-
|
|
336
|
-
export interface StreamingEvent {
|
|
337
|
-
readonly type: StreamingEventType;
|
|
338
|
-
readonly timestamp: number;
|
|
339
|
-
readonly sessionId: string;
|
|
340
|
-
readonly conversationId: string;
|
|
341
|
-
readonly data: Record<string, unknown>;
|
|
342
|
-
readonly eventId?: string;
|
|
343
|
-
readonly retryable?: boolean;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
export interface StreamingStartEvent extends StreamingEvent {
|
|
347
|
-
readonly type: 'streaming_start';
|
|
348
|
-
readonly data: {
|
|
349
|
-
readonly sessionId: string;
|
|
350
|
-
readonly messageId: string;
|
|
351
|
-
readonly agentId: string;
|
|
352
|
-
};
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
export interface ContentBlockStartEvent extends StreamingEvent {
|
|
356
|
-
readonly type: 'content_block_start';
|
|
357
|
-
readonly data: {
|
|
358
|
-
readonly index: number;
|
|
359
|
-
readonly blockType: ContentBlockType;
|
|
360
|
-
};
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
export interface ContentBlockDeltaEvent extends StreamingEvent {
|
|
364
|
-
readonly type: 'content_block_delta';
|
|
365
|
-
readonly data: {
|
|
366
|
-
readonly index: number;
|
|
367
|
-
readonly delta: {
|
|
368
|
-
readonly type: 'text_delta' | 'input_json_delta';
|
|
369
|
-
readonly text?: string;
|
|
370
|
-
readonly partial_json?: string;
|
|
371
|
-
};
|
|
372
|
-
};
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
export interface ContentBlockStopEvent extends StreamingEvent {
|
|
376
|
-
readonly type: 'content_block_stop';
|
|
377
|
-
readonly data: {
|
|
378
|
-
readonly index: number;
|
|
379
|
-
};
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
export interface MessageStopEvent extends StreamingEvent {
|
|
383
|
-
readonly type: 'message_stop';
|
|
384
|
-
readonly data: {
|
|
385
|
-
readonly messageId: string;
|
|
386
|
-
readonly stopReason: string;
|
|
387
|
-
readonly usage: {
|
|
388
|
-
readonly inputTokens: number;
|
|
389
|
-
readonly outputTokens: number;
|
|
390
|
-
};
|
|
391
|
-
};
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
export interface StreamingCompleteEvent extends StreamingEvent {
|
|
395
|
-
readonly type: 'streaming_complete';
|
|
396
|
-
readonly data: {
|
|
397
|
-
readonly sessionId: string;
|
|
398
|
-
readonly messageId: string;
|
|
399
|
-
readonly eventCount: number;
|
|
400
|
-
readonly totalDuration: number;
|
|
401
|
-
readonly metadata: ExecutionMetadata;
|
|
402
|
-
};
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
export interface StreamingErrorEvent extends StreamingEvent {
|
|
406
|
-
readonly type: 'streaming_error';
|
|
407
|
-
readonly data: {
|
|
408
|
-
readonly sessionId: string;
|
|
409
|
-
readonly error: string;
|
|
410
|
-
readonly code?: string;
|
|
411
|
-
readonly recoverable: boolean;
|
|
412
|
-
};
|
|
413
|
-
}
|