@myrialabs/clopen 0.2.23 → 0.3.0

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 (62) 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/027_create_opencode_providers_table.ts +27 -0
  5. package/backend/database/migrations/028_create_opencode_accounts_table.ts +25 -0
  6. package/backend/database/migrations/029_migrate_messages_to_unified.ts +1108 -0
  7. package/backend/database/migrations/index.ts +21 -0
  8. package/backend/database/queries/engine-queries.ts +195 -36
  9. package/backend/database/queries/message-queries.ts +84 -139
  10. package/backend/database/queries/session-queries.ts +167 -21
  11. package/backend/database/queries/snapshot-queries.ts +5 -4
  12. package/backend/database/queries/utils-queries.ts +2 -2
  13. package/backend/engine/adapters/claude/environment.ts +4 -5
  14. package/backend/engine/adapters/claude/message-converter.ts +501 -0
  15. package/backend/engine/adapters/claude/stream.ts +52 -47
  16. package/backend/engine/adapters/opencode/config.ts +156 -0
  17. package/backend/engine/adapters/opencode/message-converter.ts +266 -326
  18. package/backend/engine/adapters/opencode/server.ts +54 -12
  19. package/backend/engine/adapters/opencode/stream.ts +84 -101
  20. package/backend/engine/types.ts +17 -11
  21. package/backend/project/status-manager.ts +10 -13
  22. package/backend/snapshot/helpers.ts +46 -90
  23. package/backend/snapshot/snapshot-service.ts +1 -1
  24. package/backend/utils/paths.ts +22 -1
  25. package/backend/ws/chat/index.ts +1 -11
  26. package/backend/ws/chat/stream.ts +101 -61
  27. package/backend/ws/engine/claude/accounts.ts +27 -7
  28. package/backend/ws/engine/claude/status.ts +3 -2
  29. package/backend/ws/engine/opencode/index.ts +3 -1
  30. package/backend/ws/engine/opencode/providers.ts +300 -0
  31. package/backend/ws/git/commit-message.ts +6 -8
  32. package/backend/ws/messages/crud.ts +4 -59
  33. package/backend/ws/sessions/crud.ts +78 -130
  34. package/backend/ws/sessions/index.ts +1 -9
  35. package/backend/ws/settings/crud.ts +14 -11
  36. package/backend/ws/snapshot/restore.ts +23 -26
  37. package/backend/ws/snapshot/timeline.ts +5 -5
  38. package/dist/assets/{index-BFFIy7ZX.js → index-B95VOHJY.js} +2 -2
  39. package/dist/assets/main-D1QNkcRL.js +257 -0
  40. package/dist/assets/main-rtLiuU_x.css +1 -0
  41. package/dist/index.html +2 -2
  42. package/package.json +4 -4
  43. package/shared/constants/engines.ts +141 -56
  44. package/shared/types/database/schema.ts +39 -40
  45. package/shared/types/stores/settings.ts +8 -4
  46. package/shared/types/unified/common.ts +21 -0
  47. package/shared/types/unified/display.ts +25 -0
  48. package/shared/types/unified/engine.ts +61 -0
  49. package/shared/types/unified/index.ts +108 -0
  50. package/shared/types/unified/message.ts +151 -0
  51. package/shared/types/unified/stream.ts +157 -0
  52. package/shared/types/unified/tool.ts +268 -0
  53. package/shared/utils/message-formatter.ts +9 -73
  54. package/shared/utils/path.ts +3 -2
  55. package/tsconfig.json +1 -1
  56. package/backend/engine/adapters/claude/path-utils.ts +0 -38
  57. package/backend/ws/chat/background.ts +0 -201
  58. package/dist/assets/main-CtNvgvwE.js +0 -249
  59. package/dist/assets/main-DmshCkFM.css +0 -1
  60. package/shared/types/engine/index.ts +0 -45
  61. package/shared/types/messaging/index.ts +0 -242
  62. package/shared/types/messaging/tool.ts +0 -374
@@ -1,38 +0,0 @@
1
- import { resolve } from 'path';
2
-
3
- export function normalizePath(projectPath: string): string {
4
- let normalizedProjectPath = projectPath;
5
-
6
- if (process.platform === 'win32') {
7
- if (!projectPath.match(/^[A-Za-z]:\\/)) {
8
- if (projectPath.startsWith('\\')) {
9
- const currentDrive = process.cwd().substring(0, 2);
10
- normalizedProjectPath = currentDrive + projectPath;
11
- } else {
12
- normalizedProjectPath = resolve(projectPath);
13
- }
14
- }
15
-
16
- normalizedProjectPath = normalizedProjectPath.replace(/\//g, '\\');
17
- }
18
-
19
- return normalizedProjectPath;
20
- }
21
-
22
- export function changeWorkingDirectory(targetPath: string): string {
23
- const originalCwd = process.cwd();
24
-
25
- try {
26
- process.chdir(targetPath);
27
- return originalCwd;
28
- } catch (error) {
29
- throw new Error(`Cannot change working directory to ${targetPath}: ${error}`);
30
- }
31
- }
32
-
33
- export function restoreWorkingDirectory(originalCwd: string): void {
34
- try {
35
- process.chdir(originalCwd);
36
- } catch (error) {
37
- }
38
- }
@@ -1,201 +0,0 @@
1
- /**
2
- * Chat Background Streaming
3
- *
4
- * Handles background chat streaming that continues even when browser is closed.
5
- * Provides HTTP endpoints for stream management and polling.
6
- */
7
-
8
- import { t } from 'elysia';
9
- import { createRouter } from '$shared/utils/ws-server';
10
- import { streamManager } from '../../chat/stream-manager';
11
- import { debug } from '$shared/utils/logger';
12
- import { ws } from '$backend/utils/ws';
13
-
14
- export const backgroundHandler = createRouter()
15
- // Start background stream (fire-and-forget)
16
- .on('chat:background-start', {
17
- data: t.Object({
18
- prompt: t.Any(), // SDKUserMessage object
19
- chatSessionId: t.String(),
20
- projectPath: t.Optional(t.String()),
21
- messages: t.Optional(t.Array(t.Any())),
22
- model: t.Optional(t.String()),
23
- temperature: t.Optional(t.Number()),
24
- senderId: t.Optional(t.String()),
25
- senderName: t.Optional(t.String())
26
- })
27
- }, async ({ data, conn }) => {
28
- const projectId = ws.getProjectId(conn);
29
-
30
- try {
31
- debug.log('chat', 'WS chat:background-start received:', {
32
- chatSessionId: data.chatSessionId,
33
- projectId,
34
- messagesCount: data.messages?.length || 0
35
- });
36
-
37
- // Start background stream
38
- const streamId = await streamManager.startStream({
39
- projectPath: data.projectPath || '',
40
- projectId,
41
- prompt: data.prompt,
42
- messages: data.messages || [],
43
- chatSessionId: data.chatSessionId,
44
- model: data.model,
45
- temperature: data.temperature,
46
- senderId: data.senderId,
47
- senderName: data.senderName
48
- });
49
-
50
- debug.log('chat', 'Background stream started with ID:', streamId);
51
-
52
- // Broadcast to all users in project (collaborative)
53
- ws.emit.project(projectId, 'chat:background-started', {
54
- streamId,
55
- status: 'started'
56
- });
57
- } catch (error) {
58
- const errorMessage = error instanceof Error ? error.message : 'Unknown error';
59
- debug.error('chat', 'WS chat:background-start error:', errorMessage);
60
-
61
- ws.emit.project(projectId, 'chat:background-error', {
62
- error: errorMessage
63
- });
64
- }
65
- })
66
-
67
- // Get background stream state (HTTP pattern for request-response)
68
- .http('chat:background-state', {
69
- data: t.Object({
70
- streamId: t.Optional(t.String()),
71
- chatSessionId: t.Optional(t.String()),
72
- offset: t.Optional(t.Number())
73
- }),
74
- response: t.Object({
75
- streamId: t.String(),
76
- status: t.Union([
77
- t.Literal('active'),
78
- t.Literal('completed'),
79
- t.Literal('error'),
80
- t.Literal('cancelled')
81
- ]),
82
- processId: t.String(),
83
- messages: t.Array(t.Any()),
84
- currentPartialText: t.Optional(t.String()),
85
- currentReasoningText: t.Optional(t.String()),
86
- error: t.Optional(t.String()),
87
- startedAt: t.String(),
88
- completedAt: t.Optional(t.String())
89
- })
90
- }, async ({ data, conn }) => {
91
- const projectId = ws.getProjectId(conn);
92
-
93
- // Find stream by ID or session
94
- let streamState;
95
- if (data.streamId) {
96
- streamState = streamManager.getStream(data.streamId);
97
- } else if (data.chatSessionId) {
98
- streamState = streamManager.getSessionStream(data.chatSessionId, projectId);
99
- }
100
-
101
- // Return a "not found" response instead of throwing
102
- // This happens normally when a stream was cancelled/completed and cleaned up
103
- if (!streamState) {
104
- return {
105
- streamId: data.streamId || data.chatSessionId || '',
106
- status: 'completed' as const,
107
- processId: '',
108
- messages: [],
109
- currentPartialText: undefined,
110
- currentReasoningText: undefined,
111
- error: undefined,
112
- startedAt: new Date().toISOString(),
113
- completedAt: new Date().toISOString()
114
- };
115
- }
116
-
117
- // Get messages from offset
118
- const offset = data.offset || 0;
119
- const messages = streamState.messages.slice(offset);
120
-
121
- return {
122
- streamId: streamState.streamId,
123
- status: streamState.status,
124
- processId: streamState.processId,
125
- messages,
126
- currentPartialText: streamState.currentPartialText,
127
- currentReasoningText: streamState.currentReasoningText,
128
- error: streamState.error,
129
- startedAt: streamState.startedAt.toISOString(),
130
- completedAt: streamState.completedAt?.toISOString()
131
- };
132
- })
133
-
134
- // Get background stream messages (HTTP pattern for request-response)
135
- .http('chat:background-messages', {
136
- data: t.Object({
137
- streamId: t.Optional(t.String()),
138
- chatSessionId: t.Optional(t.String()),
139
- offset: t.Optional(t.Number())
140
- }),
141
- response: t.Object({
142
- messages: t.Array(t.Any()),
143
- hasMore: t.Boolean(),
144
- status: t.String()
145
- })
146
- }, async ({ data, conn }) => {
147
- const projectId = ws.getProjectId(conn);
148
-
149
- // Find stream by ID or session
150
- let streamState;
151
- if (data.streamId) {
152
- streamState = streamManager.getStream(data.streamId);
153
- } else if (data.chatSessionId) {
154
- streamState = streamManager.getSessionStream(data.chatSessionId, projectId);
155
- }
156
-
157
- if (!streamState) {
158
- throw new Error('Stream not found');
159
- }
160
-
161
- // Get messages from offset
162
- const offset = data.offset || 0;
163
- const messages = streamState.messages.slice(offset);
164
- const hasMore = streamState.status === 'active';
165
-
166
- return {
167
- messages,
168
- hasMore,
169
- status: streamState.status
170
- };
171
- })
172
-
173
- // Cancel background stream (HTTP pattern for request-response)
174
- .http('chat:background-cancel', {
175
- data: t.Object({
176
- streamId: t.String()
177
- }),
178
- response: t.Object({
179
- status: t.Literal('cancelled')
180
- })
181
- }, async ({ data }) => {
182
- const cancelled = await streamManager.cancelStream(data.streamId);
183
-
184
- if (!cancelled) {
185
- throw new Error('Stream not found or already completed');
186
- }
187
-
188
- return {
189
- status: 'cancelled' as const
190
- };
191
- })
192
-
193
- // Event declarations (only for fire-and-forget actions)
194
- .emit('chat:background-started', t.Object({
195
- streamId: t.String(),
196
- status: t.Literal('started')
197
- }))
198
-
199
- .emit('chat:background-error', t.Object({
200
- error: t.String()
201
- }));