@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.
- package/README.md +1 -1
- package/backend/chat/helpers.ts +2 -20
- package/backend/chat/stream-manager.ts +556 -547
- package/backend/database/migrations/027_create_opencode_providers_table.ts +27 -0
- package/backend/database/migrations/028_create_opencode_accounts_table.ts +25 -0
- package/backend/database/migrations/029_migrate_messages_to_unified.ts +1108 -0
- package/backend/database/migrations/index.ts +21 -0
- package/backend/database/queries/engine-queries.ts +195 -36
- package/backend/database/queries/message-queries.ts +84 -139
- package/backend/database/queries/session-queries.ts +167 -21
- package/backend/database/queries/snapshot-queries.ts +5 -4
- package/backend/database/queries/utils-queries.ts +2 -2
- package/backend/engine/adapters/claude/environment.ts +4 -5
- package/backend/engine/adapters/claude/message-converter.ts +501 -0
- package/backend/engine/adapters/claude/stream.ts +52 -47
- package/backend/engine/adapters/opencode/config.ts +156 -0
- package/backend/engine/adapters/opencode/message-converter.ts +266 -326
- package/backend/engine/adapters/opencode/server.ts +54 -12
- package/backend/engine/adapters/opencode/stream.ts +84 -101
- package/backend/engine/types.ts +17 -11
- package/backend/project/status-manager.ts +10 -13
- package/backend/snapshot/helpers.ts +46 -90
- package/backend/snapshot/snapshot-service.ts +1 -1
- package/backend/utils/paths.ts +22 -1
- package/backend/ws/chat/index.ts +1 -11
- package/backend/ws/chat/stream.ts +101 -61
- package/backend/ws/engine/claude/accounts.ts +27 -7
- package/backend/ws/engine/claude/status.ts +3 -2
- package/backend/ws/engine/opencode/index.ts +3 -1
- package/backend/ws/engine/opencode/providers.ts +300 -0
- package/backend/ws/git/commit-message.ts +6 -8
- package/backend/ws/messages/crud.ts +4 -59
- package/backend/ws/sessions/crud.ts +78 -130
- package/backend/ws/sessions/index.ts +1 -9
- package/backend/ws/settings/crud.ts +14 -11
- package/backend/ws/snapshot/restore.ts +23 -26
- package/backend/ws/snapshot/timeline.ts +5 -5
- package/dist/assets/{index-BFFIy7ZX.js → index-B95VOHJY.js} +2 -2
- package/dist/assets/main-D1QNkcRL.js +257 -0
- package/dist/assets/main-rtLiuU_x.css +1 -0
- package/dist/index.html +2 -2
- package/package.json +4 -4
- package/shared/constants/engines.ts +141 -56
- package/shared/types/database/schema.ts +39 -40
- package/shared/types/stores/settings.ts +8 -4
- package/shared/types/unified/common.ts +21 -0
- package/shared/types/unified/display.ts +25 -0
- package/shared/types/unified/engine.ts +61 -0
- package/shared/types/unified/index.ts +108 -0
- package/shared/types/unified/message.ts +151 -0
- package/shared/types/unified/stream.ts +157 -0
- package/shared/types/unified/tool.ts +268 -0
- package/shared/utils/message-formatter.ts +9 -73
- package/shared/utils/path.ts +3 -2
- package/tsconfig.json +1 -1
- package/backend/engine/adapters/claude/path-utils.ts +0 -38
- package/backend/ws/chat/background.ts +0 -201
- package/dist/assets/main-CtNvgvwE.js +0 -249
- package/dist/assets/main-DmshCkFM.css +0 -1
- package/shared/types/engine/index.ts +0 -45
- package/shared/types/messaging/index.ts +0 -242
- package/shared/types/messaging/tool.ts +0 -374
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenCode Provider Management Handlers
|
|
3
|
+
*
|
|
4
|
+
* CRUD for providers and accounts, models.dev catalog, and server restart.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { t } from 'elysia';
|
|
8
|
+
import { createRouter } from '$shared/utils/ws-server';
|
|
9
|
+
import { engineQueries } from '../../../database/queries';
|
|
10
|
+
import {
|
|
11
|
+
fetchAndCacheModelsDevCatalog,
|
|
12
|
+
getCachedModelsDevCatalog,
|
|
13
|
+
} from '../../../engine/adapters/opencode/config';
|
|
14
|
+
import { disposeOpenCodeClient } from '../../../engine/adapters/opencode/server';
|
|
15
|
+
import { disposeEngine } from '../../../engine';
|
|
16
|
+
import { streamManager } from '../../../chat';
|
|
17
|
+
import { debug } from '$shared/utils/logger';
|
|
18
|
+
|
|
19
|
+
// Shared typebox schemas
|
|
20
|
+
const AccountSchema = t.Object({
|
|
21
|
+
id: t.Number(),
|
|
22
|
+
name: t.String(),
|
|
23
|
+
isActive: t.Boolean(),
|
|
24
|
+
createdAt: t.String(),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const ProviderSchema = t.Object({
|
|
28
|
+
id: t.Number(),
|
|
29
|
+
slug: t.String(),
|
|
30
|
+
name: t.String(),
|
|
31
|
+
npm: t.Union([t.String(), t.Null()]),
|
|
32
|
+
apiUrl: t.Union([t.String(), t.Null()]),
|
|
33
|
+
options: t.String(),
|
|
34
|
+
isEnabled: t.Boolean(),
|
|
35
|
+
createdAt: t.String(),
|
|
36
|
+
accounts: t.Array(AccountSchema),
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
export const openCodeProviderHandler = createRouter()
|
|
40
|
+
|
|
41
|
+
// ═══════════════════════════════════════
|
|
42
|
+
// Provider CRUD
|
|
43
|
+
// ═══════════════════════════════════════
|
|
44
|
+
|
|
45
|
+
.http('engine:opencode-providers-list', {
|
|
46
|
+
data: t.Object({}),
|
|
47
|
+
response: t.Object({
|
|
48
|
+
providers: t.Array(ProviderSchema)
|
|
49
|
+
})
|
|
50
|
+
}, async () => {
|
|
51
|
+
const providers = engineQueries.getProvidersWithAccounts('opencode');
|
|
52
|
+
return {
|
|
53
|
+
providers: providers.map(p => ({
|
|
54
|
+
id: p.id,
|
|
55
|
+
slug: p.slug,
|
|
56
|
+
name: p.name,
|
|
57
|
+
npm: p.npm,
|
|
58
|
+
apiUrl: p.api_url,
|
|
59
|
+
options: p.options,
|
|
60
|
+
isEnabled: p.is_enabled === 1,
|
|
61
|
+
createdAt: p.created_at,
|
|
62
|
+
accounts: p.accounts.map(a => ({
|
|
63
|
+
id: a.id,
|
|
64
|
+
name: a.name,
|
|
65
|
+
isActive: a.is_active === 1,
|
|
66
|
+
createdAt: a.created_at,
|
|
67
|
+
})),
|
|
68
|
+
}))
|
|
69
|
+
};
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
.http('engine:opencode-provider-add', {
|
|
73
|
+
data: t.Object({
|
|
74
|
+
slug: t.String({ minLength: 1 }),
|
|
75
|
+
name: t.String({ minLength: 1 }),
|
|
76
|
+
npm: t.Optional(t.Union([t.String(), t.Null()])),
|
|
77
|
+
apiUrl: t.Optional(t.String()),
|
|
78
|
+
options: t.Optional(t.String()),
|
|
79
|
+
accountName: t.String({ minLength: 1 }),
|
|
80
|
+
credential: t.String({ minLength: 1 }),
|
|
81
|
+
}),
|
|
82
|
+
response: t.Object({
|
|
83
|
+
provider: ProviderSchema
|
|
84
|
+
})
|
|
85
|
+
}, async ({ data }) => {
|
|
86
|
+
// Check if provider already exists
|
|
87
|
+
const existing = engineQueries.getProviderBySlug('opencode', data.slug);
|
|
88
|
+
if (existing) {
|
|
89
|
+
throw new Error(`Provider "${data.slug}" already configured`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Create provider
|
|
93
|
+
const provider = engineQueries.createProvider({
|
|
94
|
+
engineType: 'opencode',
|
|
95
|
+
slug: data.slug,
|
|
96
|
+
name: data.name,
|
|
97
|
+
npm: data.npm ?? undefined,
|
|
98
|
+
apiUrl: data.apiUrl,
|
|
99
|
+
options: data.options,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// Create first account (auto-active)
|
|
103
|
+
const account = engineQueries.createAccount(provider.id, data.accountName, data.credential);
|
|
104
|
+
|
|
105
|
+
debug.log('engine', `OpenCode provider added: ${data.slug} with account "${data.accountName}"`);
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
provider: {
|
|
109
|
+
id: provider.id,
|
|
110
|
+
slug: provider.slug,
|
|
111
|
+
name: provider.name,
|
|
112
|
+
npm: provider.npm,
|
|
113
|
+
apiUrl: provider.api_url,
|
|
114
|
+
options: provider.options,
|
|
115
|
+
isEnabled: provider.is_enabled === 1,
|
|
116
|
+
createdAt: provider.created_at,
|
|
117
|
+
accounts: [{
|
|
118
|
+
id: account.id,
|
|
119
|
+
name: account.name,
|
|
120
|
+
isActive: account.is_active === 1,
|
|
121
|
+
createdAt: account.created_at,
|
|
122
|
+
}],
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
.http('engine:opencode-provider-remove', {
|
|
128
|
+
data: t.Object({ id: t.Number() }),
|
|
129
|
+
response: t.Object({ success: t.Boolean() })
|
|
130
|
+
}, async ({ data }) => {
|
|
131
|
+
engineQueries.deleteProvider(data.id);
|
|
132
|
+
debug.log('engine', `OpenCode provider removed: ${data.id}`);
|
|
133
|
+
return { success: true };
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
.http('engine:opencode-provider-toggle', {
|
|
137
|
+
data: t.Object({ id: t.Number(), enabled: t.Boolean() }),
|
|
138
|
+
response: t.Object({ success: t.Boolean() })
|
|
139
|
+
}, async ({ data }) => {
|
|
140
|
+
engineQueries.toggleProvider(data.id, data.enabled);
|
|
141
|
+
return { success: true };
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
.http('engine:opencode-provider-update-options', {
|
|
145
|
+
data: t.Object({ id: t.Number(), options: t.String() }),
|
|
146
|
+
response: t.Object({ success: t.Boolean() })
|
|
147
|
+
}, async ({ data }) => {
|
|
148
|
+
// Validate JSON
|
|
149
|
+
try { JSON.parse(data.options); } catch { throw new Error('Invalid JSON for options'); }
|
|
150
|
+
engineQueries.updateProviderOptions(data.id, data.options);
|
|
151
|
+
return { success: true };
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
// ═══════════════════════════════════════
|
|
155
|
+
// Account CRUD
|
|
156
|
+
// ═══════════════════════════════════════
|
|
157
|
+
|
|
158
|
+
.http('engine:opencode-account-add', {
|
|
159
|
+
data: t.Object({
|
|
160
|
+
providerDbId: t.Number(),
|
|
161
|
+
name: t.String({ minLength: 1 }),
|
|
162
|
+
credential: t.String({ minLength: 1 }),
|
|
163
|
+
}),
|
|
164
|
+
response: t.Object({
|
|
165
|
+
account: AccountSchema
|
|
166
|
+
})
|
|
167
|
+
}, async ({ data }) => {
|
|
168
|
+
const account = engineQueries.createAccount(data.providerDbId, data.name, data.credential);
|
|
169
|
+
debug.log('engine', `OpenCode account added: "${data.name}" for provider ${data.providerDbId}`);
|
|
170
|
+
return {
|
|
171
|
+
account: {
|
|
172
|
+
id: account.id,
|
|
173
|
+
name: account.name,
|
|
174
|
+
isActive: account.is_active === 1,
|
|
175
|
+
createdAt: account.created_at,
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
.http('engine:opencode-account-switch', {
|
|
181
|
+
data: t.Object({ accountId: t.Number() }),
|
|
182
|
+
response: t.Object({ success: t.Boolean() })
|
|
183
|
+
}, async ({ data }) => {
|
|
184
|
+
engineQueries.switchAccount(data.accountId);
|
|
185
|
+
return { success: true };
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
.http('engine:opencode-account-delete', {
|
|
189
|
+
data: t.Object({ accountId: t.Number() }),
|
|
190
|
+
response: t.Object({ success: t.Boolean() })
|
|
191
|
+
}, async ({ data }) => {
|
|
192
|
+
engineQueries.deleteAccount(data.accountId);
|
|
193
|
+
return { success: true };
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
.http('engine:opencode-account-rename', {
|
|
197
|
+
data: t.Object({ accountId: t.Number(), name: t.String({ minLength: 1 }) }),
|
|
198
|
+
response: t.Object({ success: t.Boolean() })
|
|
199
|
+
}, async ({ data }) => {
|
|
200
|
+
engineQueries.renameAccount(data.accountId, data.name);
|
|
201
|
+
return { success: true };
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
// ═══════════════════════════════════════
|
|
205
|
+
// Models.dev Catalog
|
|
206
|
+
// ═══════════════════════════════════════
|
|
207
|
+
|
|
208
|
+
.http('engine:opencode-models-dev-list', {
|
|
209
|
+
data: t.Object({}),
|
|
210
|
+
response: t.Object({
|
|
211
|
+
catalog: t.Array(t.Object({
|
|
212
|
+
id: t.String(),
|
|
213
|
+
name: t.String(),
|
|
214
|
+
npm: t.String(),
|
|
215
|
+
env: t.Array(t.String()),
|
|
216
|
+
api: t.Union([t.String(), t.Null()]),
|
|
217
|
+
})),
|
|
218
|
+
cachedAt: t.Union([t.String(), t.Null()]),
|
|
219
|
+
})
|
|
220
|
+
}, async () => {
|
|
221
|
+
const cached = getCachedModelsDevCatalog();
|
|
222
|
+
if (cached) {
|
|
223
|
+
return { catalog: cached.catalog, cachedAt: cached.cachedAt };
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// First time: fetch and cache
|
|
227
|
+
try {
|
|
228
|
+
const catalog = await fetchAndCacheModelsDevCatalog();
|
|
229
|
+
return { catalog, cachedAt: new Date().toISOString() };
|
|
230
|
+
} catch (error) {
|
|
231
|
+
debug.error('engine', 'Failed to fetch models.dev catalog:', error);
|
|
232
|
+
return { catalog: [], cachedAt: null };
|
|
233
|
+
}
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
.http('engine:opencode-models-dev-fetch', {
|
|
237
|
+
data: t.Object({}),
|
|
238
|
+
response: t.Object({
|
|
239
|
+
catalog: t.Array(t.Object({
|
|
240
|
+
id: t.String(),
|
|
241
|
+
name: t.String(),
|
|
242
|
+
npm: t.String(),
|
|
243
|
+
env: t.Array(t.String()),
|
|
244
|
+
api: t.Union([t.String(), t.Null()]),
|
|
245
|
+
})),
|
|
246
|
+
cachedAt: t.String(),
|
|
247
|
+
})
|
|
248
|
+
}, async () => {
|
|
249
|
+
const catalog = await fetchAndCacheModelsDevCatalog();
|
|
250
|
+
return { catalog, cachedAt: new Date().toISOString() };
|
|
251
|
+
})
|
|
252
|
+
|
|
253
|
+
// ═══════════════════════════════════════
|
|
254
|
+
// Server Restart
|
|
255
|
+
// ═══════════════════════════════════════
|
|
256
|
+
|
|
257
|
+
.http('engine:opencode-server-restart', {
|
|
258
|
+
data: t.Object({
|
|
259
|
+
force: t.Optional(t.Boolean()),
|
|
260
|
+
}),
|
|
261
|
+
response: t.Object({
|
|
262
|
+
success: t.Boolean(),
|
|
263
|
+
activeChats: t.Optional(t.Number()),
|
|
264
|
+
needsConfirmation: t.Optional(t.Boolean()),
|
|
265
|
+
})
|
|
266
|
+
}, async ({ data }) => {
|
|
267
|
+
// Check for active opencode streams
|
|
268
|
+
const activeStreams = streamManager.getActiveStreams()
|
|
269
|
+
.filter(s => s.engine === 'opencode');
|
|
270
|
+
|
|
271
|
+
if (activeStreams.length > 0 && !data.force) {
|
|
272
|
+
return {
|
|
273
|
+
success: false,
|
|
274
|
+
activeChats: activeStreams.length,
|
|
275
|
+
needsConfirmation: true,
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// Force: abort all active opencode streams first
|
|
280
|
+
if (activeStreams.length > 0) {
|
|
281
|
+
debug.log('engine', `Force-aborting ${activeStreams.length} active OpenCode streams before restart`);
|
|
282
|
+
for (const stream of activeStreams) {
|
|
283
|
+
try {
|
|
284
|
+
await streamManager.cancelStream(stream.streamId);
|
|
285
|
+
} catch (error) {
|
|
286
|
+
debug.warn('engine', `Failed to abort stream ${stream.streamId}:`, error);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// Dispose global opencode engine + shared client/server.
|
|
292
|
+
// forRestart=true ensures the server is killed even if we didn't
|
|
293
|
+
// spawn it, and the stored URL is purged so next init() spawns fresh.
|
|
294
|
+
await disposeEngine('opencode');
|
|
295
|
+
await disposeOpenCodeClient(true);
|
|
296
|
+
|
|
297
|
+
debug.log('engine', 'OpenCode server disposed. Will re-initialize on next use.');
|
|
298
|
+
|
|
299
|
+
return { success: true };
|
|
300
|
+
});
|
|
@@ -9,8 +9,7 @@ import { createRouter } from '$shared/utils/ws-server';
|
|
|
9
9
|
import { execGit } from '../../git/git-executor';
|
|
10
10
|
import { projectQueries } from '../../database/queries/project-queries';
|
|
11
11
|
import { initializeEngine } from '../../engine';
|
|
12
|
-
import {
|
|
13
|
-
import type { EngineType } from '$shared/types/engine';
|
|
12
|
+
import type { EngineType } from '$shared/types/unified';
|
|
14
13
|
import type { GeneratedCommitMessage } from '$shared/types/git';
|
|
15
14
|
import { debug } from '$shared/utils/logger';
|
|
16
15
|
|
|
@@ -43,7 +42,8 @@ export const commitMessageHandler = createRouter()
|
|
|
43
42
|
data: t.Object({
|
|
44
43
|
projectId: t.String(),
|
|
45
44
|
engine: t.String(),
|
|
46
|
-
|
|
45
|
+
providerSlug: t.String(),
|
|
46
|
+
modelId: t.String(),
|
|
47
47
|
format: t.Union([t.Literal('single-line'), t.Literal('multi-line')])
|
|
48
48
|
}),
|
|
49
49
|
response: t.Object({
|
|
@@ -83,14 +83,12 @@ Rules:
|
|
|
83
83
|
Git diff:
|
|
84
84
|
${rawDiff}`;
|
|
85
85
|
|
|
86
|
-
|
|
87
|
-
const { modelId } = parseModelId(data.model);
|
|
88
|
-
|
|
89
|
-
debug.log('git', `Generating commit message via ${engineType}/${modelId}`);
|
|
86
|
+
debug.log('git', `Generating commit message via ${engineType}/${data.modelId}`);
|
|
90
87
|
|
|
91
88
|
const result = await engine.generateStructured<GeneratedCommitMessage>({
|
|
92
89
|
prompt,
|
|
93
|
-
|
|
90
|
+
providerSlug: data.providerSlug,
|
|
91
|
+
modelId: data.modelId,
|
|
94
92
|
schema: COMMIT_MESSAGE_SCHEMA,
|
|
95
93
|
projectPath: project.path
|
|
96
94
|
});
|
|
@@ -10,16 +10,7 @@
|
|
|
10
10
|
import { t } from 'elysia';
|
|
11
11
|
import { createRouter } from '$shared/utils/ws-server';
|
|
12
12
|
import { messageQueries } from '../../database/queries';
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
function extractTextContent(content: unknown): string {
|
|
16
|
-
if (typeof content === 'string') return content;
|
|
17
|
-
if (!Array.isArray(content)) return '';
|
|
18
|
-
return content
|
|
19
|
-
.filter((c: any) => c.type === 'text')
|
|
20
|
-
.map((b: any) => b.text || '')
|
|
21
|
-
.join(' ');
|
|
22
|
-
}
|
|
13
|
+
import { loadMessage } from '$shared/utils/message-formatter';
|
|
23
14
|
|
|
24
15
|
export const crudHandler = createRouter()
|
|
25
16
|
// List messages
|
|
@@ -33,58 +24,13 @@ export const crudHandler = createRouter()
|
|
|
33
24
|
if (data.include_all) {
|
|
34
25
|
// Return all messages including those in other branches (for History view)
|
|
35
26
|
const allMessages = messageQueries.getAllBySessionId(data.session_id);
|
|
36
|
-
|
|
37
|
-
return messages;
|
|
27
|
+
return allMessages.map(msg => loadMessage(msg));
|
|
38
28
|
} else {
|
|
39
29
|
// Default: return only messages in current HEAD path (for Chat view)
|
|
40
|
-
|
|
41
|
-
return messages;
|
|
30
|
+
return messageQueries.getBySessionId(data.session_id);
|
|
42
31
|
}
|
|
43
32
|
})
|
|
44
33
|
|
|
45
|
-
// Bulk session preview — returns title, summary, and message counts for multiple sessions
|
|
46
|
-
// without loading all messages. Used by the Sessions/History modal.
|
|
47
|
-
.http('sessions:preview', {
|
|
48
|
-
data: t.Object({
|
|
49
|
-
session_ids: t.Array(t.String())
|
|
50
|
-
}),
|
|
51
|
-
response: t.Array(t.Any())
|
|
52
|
-
}, ({ data }) => {
|
|
53
|
-
return data.session_ids.map(sessionId => {
|
|
54
|
-
const preview = messageQueries.getSessionPreview(sessionId);
|
|
55
|
-
|
|
56
|
-
// Title from first user message
|
|
57
|
-
let title = 'New Conversation';
|
|
58
|
-
if (preview.firstUserMessage) {
|
|
59
|
-
const sdk = JSON.parse(preview.firstUserMessage.sdk_message);
|
|
60
|
-
const textContent = extractTextContent(sdk.message?.content).trim();
|
|
61
|
-
if (textContent) {
|
|
62
|
-
title = textContent.slice(0, 60) + (textContent.length > 60 ? '...' : '');
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Summary from last assistant message
|
|
67
|
-
let summary = 'No messages yet';
|
|
68
|
-
if (preview.lastAssistantMessage) {
|
|
69
|
-
const sdk = JSON.parse(preview.lastAssistantMessage.sdk_message);
|
|
70
|
-
const rawText = extractTextContent(sdk.message?.content);
|
|
71
|
-
const cleanText = rawText.replace(/```[\s\S]*?```/g, '').trim();
|
|
72
|
-
if (cleanText) {
|
|
73
|
-
summary = cleanText.slice(0, 100) + (cleanText.length > 100 ? '...' : '');
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return {
|
|
78
|
-
session_id: sessionId,
|
|
79
|
-
title,
|
|
80
|
-
summary,
|
|
81
|
-
userCount: preview.userCount,
|
|
82
|
-
assistantCount: preview.assistantCount,
|
|
83
|
-
count: preview.userCount + preview.assistantCount
|
|
84
|
-
};
|
|
85
|
-
});
|
|
86
|
-
})
|
|
87
|
-
|
|
88
34
|
// Get message by ID
|
|
89
35
|
.http('messages:get', {
|
|
90
36
|
data: t.Object({
|
|
@@ -98,8 +44,7 @@ export const crudHandler = createRouter()
|
|
|
98
44
|
throw new Error('Message not found');
|
|
99
45
|
}
|
|
100
46
|
|
|
101
|
-
|
|
102
|
-
return formatDatabaseMessage(message);
|
|
47
|
+
return loadMessage(message);
|
|
103
48
|
})
|
|
104
49
|
|
|
105
50
|
// Delete message
|