@myrialabs/clopen 0.2.24 → 0.3.1

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.
Files changed (60) hide show
  1. package/README.md +1 -1
  2. package/backend/chat/helpers.ts +2 -20
  3. package/backend/chat/stream-manager.ts +556 -547
  4. package/backend/database/migrations/029_migrate_messages_to_unified.ts +1108 -0
  5. package/backend/database/migrations/index.ts +7 -0
  6. package/backend/database/queries/engine-queries.ts +195 -36
  7. package/backend/database/queries/index.ts +1 -2
  8. package/backend/database/queries/message-queries.ts +84 -139
  9. package/backend/database/queries/session-queries.ts +167 -21
  10. package/backend/database/queries/snapshot-queries.ts +5 -4
  11. package/backend/database/queries/utils-queries.ts +2 -2
  12. package/backend/engine/adapters/claude/environment.ts +4 -5
  13. package/backend/engine/adapters/claude/message-converter.ts +552 -0
  14. package/backend/engine/adapters/claude/stream.ts +59 -47
  15. package/backend/engine/adapters/opencode/config.ts +7 -7
  16. package/backend/engine/adapters/opencode/message-converter.ts +328 -352
  17. package/backend/engine/adapters/opencode/stream.ts +84 -101
  18. package/backend/engine/types.ts +17 -11
  19. package/backend/project/status-manager.ts +10 -13
  20. package/backend/snapshot/helpers.ts +46 -90
  21. package/backend/snapshot/snapshot-service.ts +1 -1
  22. package/backend/utils/paths.ts +22 -1
  23. package/backend/ws/chat/index.ts +1 -11
  24. package/backend/ws/chat/stream.ts +101 -61
  25. package/backend/ws/engine/claude/accounts.ts +27 -7
  26. package/backend/ws/engine/claude/status.ts +3 -2
  27. package/backend/ws/engine/opencode/providers.ts +25 -24
  28. package/backend/ws/git/commit-message.ts +6 -8
  29. package/backend/ws/messages/crud.ts +4 -59
  30. package/backend/ws/sessions/crud.ts +78 -130
  31. package/backend/ws/sessions/index.ts +1 -9
  32. package/backend/ws/settings/crud.ts +14 -11
  33. package/backend/ws/snapshot/restore.ts +23 -26
  34. package/backend/ws/snapshot/timeline.ts +5 -5
  35. package/dist/assets/{index-w7Uwi2Jz.js → index-BVWBZlgD.js} +2 -2
  36. package/dist/assets/main-Cgbs6dR7.js +246 -0
  37. package/dist/assets/main-TEa2MRnh.css +1 -0
  38. package/dist/index.html +2 -2
  39. package/package.json +4 -4
  40. package/shared/constants/engines.ts +141 -56
  41. package/shared/types/database/schema.ts +39 -40
  42. package/shared/types/stores/settings.ts +8 -4
  43. package/shared/types/unified/common.ts +21 -0
  44. package/shared/types/unified/display.ts +25 -0
  45. package/shared/types/unified/engine.ts +61 -0
  46. package/shared/types/unified/index.ts +130 -0
  47. package/shared/types/unified/message.ts +151 -0
  48. package/shared/types/unified/stream.ts +157 -0
  49. package/shared/types/unified/tool.ts +409 -0
  50. package/shared/utils/message-formatter.ts +9 -73
  51. package/shared/utils/path.ts +3 -2
  52. package/tsconfig.json +1 -1
  53. package/backend/database/queries/opencode-provider-queries.ts +0 -190
  54. package/backend/engine/adapters/claude/path-utils.ts +0 -38
  55. package/backend/ws/chat/background.ts +0 -201
  56. package/dist/assets/main-B4q8wX9B.js +0 -257
  57. package/dist/assets/main-Bfz5Urp3.css +0 -1
  58. package/shared/types/engine/index.ts +0 -45
  59. package/shared/types/messaging/index.ts +0 -242
  60. package/shared/types/messaging/tool.ts +0 -374
@@ -1,242 +0,0 @@
1
- /**
2
- * Messaging Types
3
- *
4
- * HANYA re-export types resmi dari @anthropic-ai/claude-agent-sdk
5
- * TIDAK ada custom types - gunakan langsung dari SDK
6
- */
7
-
8
- // ========================================
9
- // RE-EXPORT OFFICIAL SDK TYPES ONLY
10
- // ========================================
11
-
12
- // Re-export all message types from Claude Agent SDK
13
- export type {
14
- SDKMessage,
15
- SDKAssistantMessage,
16
- SDKUserMessage,
17
- SDKUserMessageReplay,
18
- SDKResultMessage,
19
- SDKSystemMessage,
20
- SDKPartialAssistantMessage,
21
- SDKCompactBoundaryMessage,
22
- Options,
23
- PermissionMode,
24
- ApiKeySource,
25
- ConfigScope,
26
- McpServerConfig,
27
- McpStdioServerConfig,
28
- McpSSEServerConfig,
29
- McpHttpServerConfig,
30
- McpSdkServerConfigWithInstance,
31
- Query,
32
- PermissionResult,
33
- CanUseTool,
34
- HookEvent,
35
- HookCallback,
36
- HookCallbackMatcher,
37
- HookInput,
38
- BaseHookInput,
39
- PreToolUseHookInput,
40
- PostToolUseHookInput,
41
- NotificationHookInput,
42
- UserPromptSubmitHookInput,
43
- SessionStartHookInput,
44
- SessionEndHookInput,
45
- StopHookInput,
46
- SubagentStopHookInput,
47
- PreCompactHookInput,
48
- HookJSONOutput,
49
- AsyncHookJSONOutput,
50
- SyncHookJSONOutput,
51
- PermissionUpdate,
52
- PermissionBehavior,
53
- PermissionRuleValue,
54
- NonNullableUsage
55
- } from '@anthropic-ai/claude-agent-sdk';
56
-
57
- // Re-import SDKUserMessage for use in this file
58
- import type { SDKUserMessage as _SDKUserMessage } from '@anthropic-ai/claude-agent-sdk';
59
-
60
- /**
61
- * SDKMessage enriched with engine metadata.
62
- * Used by engine adapters and stream-manager to carry reasoning flags etc.
63
- * without polluting the root with untyped properties like `_reasoning`.
64
- */
65
- export type EngineSDKMessage = SDKMessage & {
66
- metadata?: {
67
- reasoning?: boolean;
68
- interrupted?: boolean;
69
- };
70
- };
71
-
72
- // Re-export the main query function and utilities
73
- export { query, tool, createSdkMcpServer } from '@anthropic-ai/claude-agent-sdk';
74
-
75
- // AbortError is a custom error class we can define if needed
76
- export class AbortError extends Error {
77
- constructor(message: string = 'Operation aborted') {
78
- super(message);
79
- this.name = 'AbortError';
80
- }
81
- }
82
-
83
- // Re-export content types from Anthropic SDK for message content
84
- export type {
85
- ContentBlock,
86
- ContentBlockParam,
87
- TextBlock,
88
- TextBlockParam,
89
- ImageBlockParam,
90
- SearchResultBlockParam,
91
- ToolUseBlock,
92
- ToolResultBlockParam,
93
- Message as APIMessage,
94
- MessageParam as APIMessageParam,
95
- Usage
96
- } from '@anthropic-ai/sdk/resources/messages';
97
-
98
-
99
- import type { SDKMessage, SDKCompactBoundaryMessage, SDKPartialAssistantMessage } from '@anthropic-ai/claude-agent-sdk/sdk';
100
- import type { Usage } from '@anthropic-ai/sdk/resources/messages';
101
-
102
- // Import content type statically
103
- import type { ContentBlock } from '@anthropic-ai/sdk/resources/messages';
104
-
105
- // MessageContent type for UI components
106
- export type MessageContent = ContentBlock;
107
-
108
- // Re-export tool types from tool.ts
109
- export type {
110
- // Tool input types
111
- BashToolInput,
112
- BashOutputToolInput,
113
- EditToolInput,
114
- ExitPlanModeToolInput,
115
- GlobToolInput,
116
- GrepToolInput,
117
- TaskStopToolInput,
118
- ListMcpResourcesToolInput,
119
- NotebookEditToolInput,
120
- ReadMcpResourceToolInput,
121
- ReadToolInput,
122
- TaskToolInput,
123
- TodoWriteToolInput,
124
- WebFetchToolInput,
125
- WebSearchToolInput,
126
- WriteToolInput,
127
- AskUserQuestionToolInput,
128
- ConfigToolInput,
129
- EnterWorktreeToolInput,
130
- AgentToolInput,
131
- EnterPlanModeToolInput,
132
- SkillToolInput,
133
- SubAgentActivity,
134
- ToolInput,
135
-
136
- // Tool output types (from SDK)
137
- TaskOutput,
138
- AskUserQuestionOutput,
139
- BashOutput,
140
- ConfigOutput,
141
- EnterWorktreeOutput,
142
- EditOutput,
143
- ExitPlanModeOutput,
144
- ReadOutput,
145
- WriteOutput,
146
- GlobOutput,
147
- GrepOutput,
148
- WebFetchOutput,
149
- WebSearchOutput,
150
- NotebookEditOutput,
151
- TodoWriteOutput,
152
- TaskStopOutput,
153
- ListMcpResourcesOutput,
154
- ReadMcpResourceOutput,
155
- ToolOutput,
156
-
157
- // Tool result type
158
- ToolResult
159
- } from './tool';
160
-
161
- // ========================================
162
- // STREAM EVENT TYPES
163
- // ========================================
164
-
165
- // Unified SSE event data type for both server and client
166
- export interface SSEEventData {
167
- // Connection/Process info
168
- processId?: string;
169
- timestamp?: string;
170
- error?: string;
171
-
172
- // Message data
173
- message?: SDKMessage;
174
- usage?: Usage;
175
-
176
- // Database metadata (for message tracking)
177
- message_id?: string;
178
- parent_message_id?: string | null;
179
-
180
- // User/sender information for shared chat
181
- sender_id?: string;
182
- sender_name?: string;
183
-
184
- // Notification data
185
- notification?: {
186
- type: string;
187
- title: string;
188
- message: string;
189
- icon?: string;
190
- };
191
-
192
- // Compact boundary indicator
193
- compactBoundary?: {
194
- trigger: 'manual' | 'auto';
195
- preTokens: number;
196
- };
197
-
198
- // Partial message text (for streaming)
199
- partialText?: string;
200
-
201
- // Delta text for smooth typing effect
202
- deltaText?: string;
203
-
204
- // Event type for partial messages
205
- eventType?: 'start' | 'update' | 'end';
206
-
207
- // Engine that produced this message
208
- engine?: string;
209
- }
210
-
211
- export interface ClaudeStreamRequest {
212
- projectPath: string;
213
- projectId?: string; // Project ID for tracking
214
- prompt: string; // User prompt as string (will be converted to SDKUserMessage by server)
215
- messages?: Array<{ role: string; content: string }>;
216
- chatSessionId?: string; // Database session ID for persistence
217
- model?: string;
218
- temperature?: number;
219
- senderId?: string; // User ID for shared chat
220
- senderName?: string; // User name for display
221
- forkSession?: boolean; // Fork session instead of continuing (default: false)
222
- }
223
-
224
- // Model configuration (engine-aware)
225
- export type { EngineModel } from '$shared/types/engine';
226
-
227
- // File attachment interface
228
- export interface FileAttachment {
229
- type: 'image' | 'document';
230
- data: string; // base64 encoded
231
- mediaType: string;
232
- fileName: string;
233
- }
234
-
235
- // Chat service configuration
236
- export interface ChatServiceOptions {
237
- onLoadingTextChange?: (text: string) => void;
238
- onStreamStart?: (processId: string) => void;
239
- onStreamEnd?: () => void;
240
- onError?: (error: Error) => void;
241
- attachedFiles?: FileAttachment[];
242
- }
@@ -1,374 +0,0 @@
1
- /**
2
- * Tool Types
3
- *
4
- * Defines all tool input/output interfaces for UI components.
5
- * Input types AND output types are imported from the official SDK.
6
- */
7
-
8
- // ============================================================
9
- // SDK Tool Input Types
10
- // ============================================================
11
-
12
- import type {
13
- AgentInput,
14
- AskUserQuestionInput,
15
- BashInput,
16
- TaskOutputInput,
17
- ConfigInput,
18
- EnterWorktreeInput,
19
- ExitPlanModeInput,
20
- FileEditInput,
21
- FileReadInput,
22
- FileWriteInput,
23
- GlobInput,
24
- GrepInput,
25
- ListMcpResourcesInput,
26
- McpInput,
27
- NotebookEditInput,
28
- ReadMcpResourceInput,
29
- TaskStopInput,
30
- TodoWriteInput,
31
- WebFetchInput,
32
- WebSearchInput
33
- } from '@anthropic-ai/claude-agent-sdk/sdk-tools';
34
-
35
- // ============================================================
36
- // SDK Tool Output Types
37
- // ============================================================
38
-
39
- import type {
40
- AgentOutput as SDKAgentOutput,
41
- AskUserQuestionOutput as SDKAskUserQuestionOutput,
42
- BashOutput as SDKBashOutput,
43
- ConfigOutput as SDKConfigOutput,
44
- EnterWorktreeOutput as SDKEnterWorktreeOutput,
45
- ExitPlanModeOutput as SDKExitPlanModeOutput,
46
- FileEditOutput as SDKFileEditOutput,
47
- FileReadOutput as SDKFileReadOutput,
48
- FileWriteOutput as SDKFileWriteOutput,
49
- GlobOutput as SDKGlobOutput,
50
- GrepOutput as SDKGrepOutput,
51
- ListMcpResourcesOutput as SDKListMcpResourcesOutput,
52
- NotebookEditOutput as SDKNotebookEditOutput,
53
- ReadMcpResourceOutput as SDKReadMcpResourceOutput,
54
- TaskStopOutput as SDKTaskStopOutput,
55
- TodoWriteOutput as SDKTodoWriteOutput,
56
- WebFetchOutput as SDKWebFetchOutput,
57
- WebSearchOutput as SDKWebSearchOutput
58
- } from '@anthropic-ai/claude-agent-sdk/sdk-tools';
59
-
60
- // Re-export SDK output types with consistent names
61
- export type TaskOutput = SDKAgentOutput;
62
- export type AskUserQuestionOutput = SDKAskUserQuestionOutput;
63
- export type BashOutput = SDKBashOutput;
64
- export type ConfigOutput = SDKConfigOutput;
65
- export type EnterWorktreeOutput = SDKEnterWorktreeOutput;
66
- export type ExitPlanModeOutput = SDKExitPlanModeOutput;
67
- export type EditOutput = SDKFileEditOutput;
68
- export type ReadOutput = SDKFileReadOutput;
69
- export type WriteOutput = SDKFileWriteOutput;
70
- export type GlobOutput = SDKGlobOutput;
71
- export type GrepOutput = SDKGrepOutput;
72
- export type ListMcpResourcesOutput = SDKListMcpResourcesOutput;
73
- export type NotebookEditOutput = SDKNotebookEditOutput;
74
- export type ReadMcpResourceOutput = SDKReadMcpResourceOutput;
75
- export type TaskStopOutput = SDKTaskStopOutput;
76
- export type TodoWriteOutput = SDKTodoWriteOutput;
77
- export type WebFetchOutput = SDKWebFetchOutput;
78
- export type WebSearchOutput = SDKWebSearchOutput;
79
-
80
- /**
81
- * Union type for all possible tool outputs (SDK types)
82
- */
83
- export type ToolOutput =
84
- | TaskOutput
85
- | AskUserQuestionOutput
86
- | BashOutput
87
- | ConfigOutput
88
- | EnterWorktreeOutput
89
- | ExitPlanModeOutput
90
- | EditOutput
91
- | ReadOutput
92
- | WriteOutput
93
- | GlobOutput
94
- | GrepOutput
95
- | ListMcpResourcesOutput
96
- | NotebookEditOutput
97
- | ReadMcpResourceOutput
98
- | TaskStopOutput
99
- | TodoWriteOutput
100
- | WebFetchOutput
101
- | WebSearchOutput;
102
-
103
- // ============================================================
104
- // Tool Result Type (for embedding in tool_use)
105
- // ============================================================
106
-
107
- export interface ToolResult {
108
- type: 'tool_result';
109
- tool_use_id: string;
110
- content: string;
111
- is_error?: boolean;
112
- }
113
-
114
- // ============================================================
115
- // Tool Metadata (set by chat service on stream end)
116
- // ============================================================
117
-
118
- export interface ToolMetadata {
119
- /** Tool was interrupted — stream ended (error/cancel/complete) before tool got its result */
120
- interrupted?: boolean;
121
- }
122
-
123
- // ============================================================
124
- // Tool Input Types for UI Components
125
- // ============================================================
126
-
127
- export interface BashToolInput {
128
- type: 'tool_use';
129
- id: string;
130
- name: 'Bash';
131
- input: BashInput;
132
- $result?: ToolResult;
133
- metadata?: ToolMetadata;
134
- }
135
-
136
- export interface BashOutputToolInput {
137
- type: 'tool_use';
138
- id: string;
139
- name: 'TaskOutput';
140
- input: TaskOutputInput;
141
- $result?: ToolResult;
142
- metadata?: ToolMetadata;
143
- }
144
-
145
- export interface EditToolInput {
146
- type: 'tool_use';
147
- id: string;
148
- name: 'Edit';
149
- input: FileEditInput;
150
- $result?: ToolResult;
151
- metadata?: ToolMetadata;
152
- }
153
-
154
- export interface ExitPlanModeToolInput {
155
- type: 'tool_use';
156
- id: string;
157
- name: 'ExitPlanMode';
158
- input: ExitPlanModeInput;
159
- $result?: ToolResult;
160
- metadata?: ToolMetadata;
161
- }
162
-
163
- export interface GlobToolInput {
164
- type: 'tool_use';
165
- id: string;
166
- name: 'Glob';
167
- input: GlobInput;
168
- $result?: ToolResult;
169
- metadata?: ToolMetadata;
170
- }
171
-
172
- export interface GrepToolInput {
173
- type: 'tool_use';
174
- id: string;
175
- name: 'Grep';
176
- input: GrepInput;
177
- $result?: ToolResult;
178
- metadata?: ToolMetadata;
179
- }
180
-
181
- export interface TaskStopToolInput {
182
- type: 'tool_use';
183
- id: string;
184
- name: 'TaskStop';
185
- input: TaskStopInput;
186
- $result?: ToolResult;
187
- metadata?: ToolMetadata;
188
- }
189
-
190
- export interface ListMcpResourcesToolInput {
191
- type: 'tool_use';
192
- id: string;
193
- name: 'ListMcpResources';
194
- input: ListMcpResourcesInput;
195
- $result?: ToolResult;
196
- metadata?: ToolMetadata;
197
- }
198
-
199
- export interface NotebookEditToolInput {
200
- type: 'tool_use';
201
- id: string;
202
- name: 'NotebookEdit';
203
- input: NotebookEditInput;
204
- $result?: ToolResult;
205
- metadata?: ToolMetadata;
206
- }
207
-
208
- export interface ReadMcpResourceToolInput {
209
- type: 'tool_use';
210
- id: string;
211
- name: 'ReadMcpResource';
212
- input: ReadMcpResourceInput;
213
- $result?: ToolResult;
214
- metadata?: ToolMetadata;
215
- }
216
-
217
- export interface ReadToolInput {
218
- type: 'tool_use';
219
- id: string;
220
- name: 'Read';
221
- input: FileReadInput;
222
- $result?: ToolResult;
223
- metadata?: ToolMetadata;
224
- }
225
-
226
- export interface TaskToolInput {
227
- type: 'tool_use';
228
- id: string;
229
- name: 'Task';
230
- input: AgentInput;
231
- $result?: ToolResult;
232
- metadata?: ToolMetadata;
233
- }
234
-
235
- export interface TodoWriteToolInput {
236
- type: 'tool_use';
237
- id: string;
238
- name: 'TodoWrite';
239
- input: TodoWriteInput;
240
- $result?: ToolResult;
241
- metadata?: ToolMetadata;
242
- }
243
-
244
- export interface WebFetchToolInput {
245
- type: 'tool_use';
246
- id: string;
247
- name: 'WebFetch';
248
- input: WebFetchInput;
249
- $result?: ToolResult;
250
- metadata?: ToolMetadata;
251
- }
252
-
253
- export interface WebSearchToolInput {
254
- type: 'tool_use';
255
- id: string;
256
- name: 'WebSearch';
257
- input: WebSearchInput;
258
- $result?: ToolResult;
259
- metadata?: ToolMetadata;
260
- }
261
-
262
- export interface WriteToolInput {
263
- type: 'tool_use';
264
- id: string;
265
- name: 'Write';
266
- input: FileWriteInput;
267
- $result?: ToolResult;
268
- metadata?: ToolMetadata;
269
- }
270
-
271
- export interface AskUserQuestionToolInput {
272
- type: 'tool_use';
273
- id: string;
274
- name: 'AskUserQuestion';
275
- input: AskUserQuestionInput;
276
- $result?: ToolResult;
277
- metadata?: ToolMetadata;
278
- }
279
-
280
- export interface ConfigToolInput {
281
- type: 'tool_use';
282
- id: string;
283
- name: 'Config';
284
- input: ConfigInput;
285
- $result?: ToolResult;
286
- metadata?: ToolMetadata;
287
- }
288
-
289
- export interface EnterWorktreeToolInput {
290
- type: 'tool_use';
291
- id: string;
292
- name: 'EnterWorktree';
293
- input: EnterWorktreeInput;
294
- $result?: ToolResult;
295
- metadata?: ToolMetadata;
296
- }
297
-
298
- // Sub-agent activity item for Agent tool display
299
- export interface SubAgentActivity {
300
- type: 'tool_use' | 'text';
301
- toolName?: string;
302
- toolInput?: any;
303
- toolResult?: any;
304
- text?: string;
305
- }
306
-
307
- export interface AgentToolInput {
308
- type: 'tool_use';
309
- id: string;
310
- name: 'Agent';
311
- input: AgentInput;
312
- $result?: ToolResult;
313
- $subMessages?: SubAgentActivity[];
314
- metadata?: ToolMetadata;
315
- }
316
-
317
- export interface EnterPlanModeToolInput {
318
- type: 'tool_use';
319
- id: string;
320
- name: 'EnterPlanMode';
321
- input: Record<string, unknown>;
322
- $result?: ToolResult;
323
- metadata?: ToolMetadata;
324
- }
325
-
326
- /**
327
- * Skill tool input — manually defined (not from SDK).
328
- *
329
- * Neither @anthropic-ai/claude-agent-sdk nor @opencode-ai/sdk export a
330
- * SkillInput type. The shape is inferred from observed tool_use payloads
331
- * where `input.skill` is the slash-command name and `input.args` is an
332
- * optional argument string.
333
- */
334
- export interface SkillToolInput {
335
- type: 'tool_use';
336
- id: string;
337
- name: 'Skill';
338
- input: {
339
- skill: string;
340
- args?: string;
341
- };
342
- $result?: ToolResult;
343
- /** Expanded skill prompt (from synthetic user message) */
344
- $skillPrompt?: string;
345
- metadata?: ToolMetadata;
346
- }
347
-
348
- // ============================================================
349
- // Union of All Tool Input Types
350
- // ============================================================
351
-
352
- export type ToolInput =
353
- | BashToolInput
354
- | BashOutputToolInput
355
- | EditToolInput
356
- | ExitPlanModeToolInput
357
- | GlobToolInput
358
- | GrepToolInput
359
- | TaskStopToolInput
360
- | ListMcpResourcesToolInput
361
- | NotebookEditToolInput
362
- | ReadMcpResourceToolInput
363
- | ReadToolInput
364
- | TaskToolInput
365
- | TodoWriteToolInput
366
- | WebFetchToolInput
367
- | WebSearchToolInput
368
- | WriteToolInput
369
- | AskUserQuestionToolInput
370
- | ConfigToolInput
371
- | EnterWorktreeToolInput
372
- | AgentToolInput
373
- | EnterPlanModeToolInput
374
- | SkillToolInput;