@myrialabs/clopen 0.4.14 → 0.4.15

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 (46) hide show
  1. package/backend/auth/permissions.ts +2 -0
  2. package/backend/database/migrations/056_support_mssql_driver.ts +137 -0
  3. package/backend/database/migrations/index.ts +7 -0
  4. package/backend/database/queries/engine-queries.ts +13 -0
  5. package/backend/database/queries/message-queries.ts +43 -1
  6. package/backend/db-client/connection-manager.ts +8 -2
  7. package/backend/db-client/drivers/mssql.ts +829 -0
  8. package/backend/db-client/drivers/mysql.ts +33 -4
  9. package/backend/db-client/drivers/postgres.ts +55 -5
  10. package/backend/db-client/drivers/sql-builders.test.ts +70 -0
  11. package/backend/db-client/drivers/sql-builders.ts +9 -2
  12. package/backend/db-client/pool-config.ts +32 -0
  13. package/backend/db-client/query-executor.test.ts +42 -0
  14. package/backend/db-client/query-executor.ts +47 -3
  15. package/backend/engine/adapters/opencode/config.ts +9 -0
  16. package/backend/engine/adapters/opencode/models.ts +10 -1
  17. package/backend/engine/adapters/opencode/server.ts +110 -2
  18. package/backend/index.ts +6 -0
  19. package/backend/preview/browser/browser-preview-service.ts +15 -6
  20. package/backend/preview/browser/browser-video-capture.ts +232 -100
  21. package/backend/preview/browser/scripts/video-stream.ts +216 -56
  22. package/backend/preview/browser/types.ts +24 -12
  23. package/backend/ws/chat/stream.ts +12 -4
  24. package/backend/ws/db-client/connections.ts +2 -1
  25. package/backend/ws/db-client/query.ts +41 -4
  26. package/backend/ws/db-client/schema.ts +45 -1
  27. package/backend/ws/engine/claude/accounts.ts +37 -13
  28. package/backend/ws/engine/codex/accounts.ts +36 -4
  29. package/backend/ws/engine/copilot/accounts.ts +12 -0
  30. package/backend/ws/engine/opencode/providers.ts +72 -1
  31. package/backend/ws/engine/qwen/accounts.ts +22 -0
  32. package/backend/ws/messages/crud.ts +13 -0
  33. package/backend/ws/preview/browser/interact.ts +10 -8
  34. package/backend/ws/preview/browser/webcodecs.ts +26 -2
  35. package/dist/assets/{index-BWf-DDJN.js → index-ChF_jIXj.js} +1 -1
  36. package/dist/assets/{index-CDZf6lfv.js → index-EunAFLxP.js} +1 -1
  37. package/dist/assets/{main-C15mQTCW.js → main-CTs4NXwP.js} +407 -367
  38. package/dist/assets/main-moCAkEwm.css +1 -0
  39. package/dist/index.html +2 -2
  40. package/package.json +5 -1
  41. package/shared/types/db-client/connection.ts +1 -1
  42. package/shared/types/db-client/query.ts +4 -1
  43. package/shared/utils/db-client/split-sql.test.ts +13 -0
  44. package/shared/utils/db-client/split-sql.ts +38 -1
  45. package/shared/utils/subagent-wire-trim.ts +87 -0
  46. package/dist/assets/main-Ba5ZGlY4.css +0 -1
@@ -74,7 +74,9 @@ export const ADMIN_ONLY_ROUTES = new Set([
74
74
  'engine:opencode-provider-add',
75
75
  'engine:opencode-provider-remove',
76
76
  'engine:opencode-provider-toggle',
77
+ 'engine:opencode-provider-update',
77
78
  'engine:opencode-provider-update-options',
79
+ 'engine:opencode-provider-fetch-models',
78
80
  'engine:opencode-account-add',
79
81
  'engine:opencode-account-switch',
80
82
  'engine:opencode-account-delete',
@@ -0,0 +1,137 @@
1
+ import type { DatabaseConnection } from '$shared/types/database/connection';
2
+ import { debug } from '$shared/utils/logger';
3
+
4
+ export const description = 'Support mssql driver in db_client_connections CHECK constraint';
5
+
6
+ export const up = (db: DatabaseConnection): void => {
7
+ debug.log('migration', 'Updating CHECK constraint for mssql support in db_client_connections...');
8
+
9
+ // Recreate table to update driver CHECK constraint in SQLite
10
+ db.exec('PRAGMA foreign_keys = OFF;');
11
+
12
+ db.exec(`
13
+ CREATE TABLE IF NOT EXISTS db_client_connections_new (
14
+ id TEXT PRIMARY KEY,
15
+ name TEXT NOT NULL,
16
+ driver TEXT NOT NULL CHECK (driver IN ('mysql','postgres','sqlite','mongodb','redis','mssql')),
17
+ host TEXT,
18
+ port INTEGER,
19
+ username TEXT,
20
+ password TEXT,
21
+ database TEXT,
22
+ ssl_mode TEXT DEFAULT 'disable' CHECK (ssl_mode IN ('disable','require','verify-ca','verify-full')),
23
+ ssl_ca TEXT,
24
+ ssh_enabled INTEGER NOT NULL DEFAULT 0,
25
+ ssh_host TEXT,
26
+ ssh_port INTEGER DEFAULT 22,
27
+ ssh_username TEXT,
28
+ ssh_auth_method TEXT DEFAULT 'password' CHECK (ssh_auth_method IN ('password','key')),
29
+ ssh_password TEXT,
30
+ ssh_private_key TEXT,
31
+ ssh_passphrase TEXT,
32
+ options_json TEXT,
33
+ color TEXT,
34
+ created_at TEXT NOT NULL,
35
+ updated_at TEXT NOT NULL,
36
+ last_used_at TEXT,
37
+ owner_user_id TEXT
38
+ )
39
+ `);
40
+
41
+ db.exec(`
42
+ INSERT INTO db_client_connections_new (
43
+ id, name, driver, host, port, username, password, database, ssl_mode, ssl_ca,
44
+ ssh_enabled, ssh_host, ssh_port, ssh_username, ssh_auth_method, ssh_password,
45
+ ssh_private_key, ssh_passphrase, options_json, color, created_at, updated_at,
46
+ last_used_at, owner_user_id
47
+ )
48
+ SELECT
49
+ id, name, driver, host, port, username, password, database, ssl_mode, ssl_ca,
50
+ ssh_enabled, ssh_host, ssh_port, ssh_username, ssh_auth_method, ssh_password,
51
+ ssh_private_key, ssh_passphrase, options_json, color, created_at, updated_at,
52
+ last_used_at, owner_user_id
53
+ FROM db_client_connections;
54
+ `);
55
+
56
+ db.exec('DROP TABLE db_client_connections;');
57
+ db.exec('ALTER TABLE db_client_connections_new RENAME TO db_client_connections;');
58
+
59
+ db.exec(`
60
+ CREATE INDEX IF NOT EXISTS idx_db_client_conn_last_used
61
+ ON db_client_connections(last_used_at DESC)
62
+ `);
63
+
64
+ db.exec(`
65
+ CREATE INDEX IF NOT EXISTS idx_db_client_conn_owner
66
+ ON db_client_connections(owner_user_id)
67
+ `);
68
+
69
+ db.exec('PRAGMA foreign_keys = ON;');
70
+ debug.log('migration', 'CHECK constraint updated successfully');
71
+ };
72
+
73
+ export const down = (db: DatabaseConnection): void => {
74
+ debug.log('migration', 'Rolling back mssql support in CHECK constraint...');
75
+ db.exec('PRAGMA foreign_keys = OFF;');
76
+
77
+ db.exec(`
78
+ CREATE TABLE IF NOT EXISTS db_client_connections_new (
79
+ id TEXT PRIMARY KEY,
80
+ name TEXT NOT NULL,
81
+ driver TEXT NOT NULL CHECK (driver IN ('mysql','postgres','sqlite','mongodb','redis')),
82
+ host TEXT,
83
+ port INTEGER,
84
+ username TEXT,
85
+ password TEXT,
86
+ database TEXT,
87
+ ssl_mode TEXT DEFAULT 'disable' CHECK (ssl_mode IN ('disable','require','verify-ca','verify-full')),
88
+ ssl_ca TEXT,
89
+ ssh_enabled INTEGER NOT NULL DEFAULT 0,
90
+ ssh_host TEXT,
91
+ ssh_port INTEGER DEFAULT 22,
92
+ ssh_username TEXT,
93
+ ssh_auth_method TEXT DEFAULT 'password' CHECK (ssh_auth_method IN ('password','key')),
94
+ ssh_password TEXT,
95
+ ssh_private_key TEXT,
96
+ ssh_passphrase TEXT,
97
+ options_json TEXT,
98
+ color TEXT,
99
+ created_at TEXT NOT NULL,
100
+ updated_at TEXT NOT NULL,
101
+ last_used_at TEXT,
102
+ owner_user_id TEXT
103
+ )
104
+ `);
105
+
106
+ db.exec(`
107
+ INSERT INTO db_client_connections_new (
108
+ id, name, driver, host, port, username, password, database, ssl_mode, ssl_ca,
109
+ ssh_enabled, ssh_host, ssh_port, ssh_username, ssh_auth_method, ssh_password,
110
+ ssh_private_key, ssh_passphrase, options_json, color, created_at, updated_at,
111
+ last_used_at, owner_user_id
112
+ )
113
+ SELECT
114
+ id, name, driver, host, port, username, password, database, ssl_mode, ssl_ca,
115
+ ssh_enabled, ssh_host, ssh_port, ssh_username, ssh_auth_method, ssh_password,
116
+ ssh_private_key, ssh_passphrase, options_json, color, created_at, updated_at,
117
+ last_used_at, owner_user_id
118
+ FROM db_client_connections
119
+ WHERE driver != 'mssql';
120
+ `);
121
+
122
+ db.exec('DROP TABLE db_client_connections;');
123
+ db.exec('ALTER TABLE db_client_connections_new RENAME TO db_client_connections;');
124
+
125
+ db.exec(`
126
+ CREATE INDEX IF NOT EXISTS idx_db_client_conn_last_used
127
+ ON db_client_connections(last_used_at DESC)
128
+ `);
129
+
130
+ db.exec(`
131
+ CREATE INDEX IF NOT EXISTS idx_db_client_conn_owner
132
+ ON db_client_connections(owner_user_id)
133
+ `);
134
+
135
+ db.exec('PRAGMA foreign_keys = ON;');
136
+ debug.log('migration', 'Rollback completed');
137
+ };
@@ -54,6 +54,7 @@ import * as migration052 from './052_add_default_profile_to_projects';
54
54
  import * as migration053 from './053_add_profile_to_permission_sets';
55
55
  import * as migration054 from './054_drop_subagent_agent_type';
56
56
  import * as migration055 from './055_artifact_model_tools_per_engine';
57
+ import * as migration056 from './056_support_mssql_driver';
57
58
 
58
59
  // Export all migrations in order
59
60
  export const migrations = [
@@ -386,6 +387,12 @@ export const migrations = [
386
387
  description: migration055.description,
387
388
  up: migration055.up,
388
389
  down: migration055.down
390
+ },
391
+ {
392
+ id: '056',
393
+ description: migration056.description,
394
+ up: migration056.up,
395
+ down: migration056.down
389
396
  }
390
397
  ];
391
398
 
@@ -115,6 +115,19 @@ export const engineQueries = {
115
115
  return db.prepare(`SELECT * FROM engine_providers WHERE id = ?`).get(id) as EngineProvider;
116
116
  },
117
117
 
118
+ updateProvider(id: number, data: { slug?: string; name?: string; apiUrl?: string; options?: string }): void {
119
+ const db = getDatabase();
120
+ const sets: string[] = [];
121
+ const vals: (string | number)[] = [];
122
+ if (data.slug !== undefined) { sets.push('slug = ?'); vals.push(data.slug); }
123
+ if (data.name !== undefined) { sets.push('name = ?'); vals.push(data.name); }
124
+ if (data.apiUrl !== undefined) { sets.push('api_url = ?'); vals.push(data.apiUrl); }
125
+ if (data.options !== undefined) { sets.push('options = ?'); vals.push(data.options); }
126
+ if (sets.length === 0) return;
127
+ vals.push(id);
128
+ db.prepare(`UPDATE engine_providers SET ${sets.join(', ')} WHERE id = ?`).run(...vals);
129
+ },
130
+
118
131
  updateProviderOptions(id: number, options: string): void {
119
132
  const db = getDatabase();
120
133
  db.prepare(`UPDATE engine_providers SET options = ? WHERE id = ?`).run(options, id);
@@ -2,6 +2,7 @@ import { getDatabase } from '../index';
2
2
  import type { DatabaseMessage } from '$shared/types/database/schema';
3
3
  import type { UnifiedMessage } from '$shared/types/unified';
4
4
  import { debug } from '$shared/utils/logger';
5
+ import { trimSubAgentForWire } from '$shared/utils/subagent-wire-trim';
5
6
 
6
7
  /** Parse message JSON from a DB row. */
7
8
  function parseMessage(row: DatabaseMessage): UnifiedMessage {
@@ -25,7 +26,10 @@ export const messageQueries = {
25
26
  }
26
27
 
27
28
  const path = this.getPathToRoot(session.head_message_id);
28
- return path.map(parseMessage);
29
+ // Trim sub-agent tool noise from the display payload. The DB rows keep the
30
+ // full data; only what is sent to the frontend is slimmed. See
31
+ // trimSubAgentForWire for the rationale.
32
+ return path.map(parseMessage).map(trimSubAgentForWire);
29
33
  },
30
34
 
31
35
  /**
@@ -51,6 +55,44 @@ export const messageQueries = {
51
55
  return message;
52
56
  },
53
57
 
58
+ /**
59
+ * Get the full (untrimmed) sub-agent messages nested under a message's
60
+ * tool_use blocks, matched by `parent.toolUseId`.
61
+ *
62
+ * The wire payload trims sub-agent noise (see trimSubAgentForWire), so the
63
+ * frontend's in-memory copy is slimmed. The Debug modal uses this to fetch
64
+ * the complete sub-agent data straight from the DB and rebuild the full view.
65
+ */
66
+ getSubAgentMessages(messageId: string): UnifiedMessage[] {
67
+ const db = getDatabase();
68
+ const row = db.prepare(`
69
+ SELECT * FROM messages WHERE id = ?
70
+ `).get(messageId) as DatabaseMessage | null;
71
+ if (!row) return [];
72
+
73
+ const parent = parseMessage(row);
74
+ if (parent.type !== 'assistant') return [];
75
+
76
+ const toolUseIds = new Set(
77
+ parent.content
78
+ .filter(block => block.type === 'tool_use')
79
+ .map(block => (block as { id: string }).id)
80
+ );
81
+ if (toolUseIds.size === 0) return [];
82
+
83
+ const rows = db.prepare(`
84
+ SELECT * FROM messages WHERE session_id = ?
85
+ ORDER BY created_at ASC
86
+ `).all(row.session_id) as DatabaseMessage[];
87
+
88
+ return rows
89
+ .map(parseMessage)
90
+ .filter(msg => {
91
+ const parentToolUseId = msg.parent?.toolUseId;
92
+ return parentToolUseId != null && toolUseIds.has(parentToolUseId);
93
+ });
94
+ },
95
+
54
96
  create(messageData: {
55
97
  session_id: string;
56
98
  message: UnifiedMessage;
@@ -13,6 +13,7 @@ import { PostgresAdapter } from './drivers/postgres';
13
13
  import { SqliteAdapter } from './drivers/sqlite';
14
14
  import { MongoDbAdapter } from './drivers/mongodb';
15
15
  import { RedisAdapter } from './drivers/redis';
16
+ import { MssqlAdapter } from './drivers/mssql';
16
17
  import type { DbClientDriverAdapter } from './drivers/types';
17
18
  import type {
18
19
  DbClientConnection,
@@ -28,8 +29,11 @@ interface ConnectionEntry {
28
29
  lastUsedAt: number;
29
30
  }
30
31
 
31
- const IDLE_MS = 10 * 60 * 1000; // 10 minutes
32
- const SWEEP_INTERVAL_MS = 60 * 1000; // 1 minute
32
+ // Tear an idle adapter (and its pool) down quickly so a browsed connection
33
+ // doesn't hold server-side sessions after the user walks away. The adapter is
34
+ // reopened transparently on next use.
35
+ const IDLE_MS = 60 * 1000; // 1 minute
36
+ const SWEEP_INTERVAL_MS = 30 * 1000; // 30 seconds
33
37
 
34
38
  class ConnectionManager {
35
39
  private entries = new Map<string, ConnectionEntry>();
@@ -53,6 +57,7 @@ class ConnectionManager {
53
57
  case 'sqlite': return new SqliteAdapter();
54
58
  case 'mongodb': return new MongoDbAdapter();
55
59
  case 'redis': return new RedisAdapter();
60
+ case 'mssql': return new MssqlAdapter();
56
61
  default: {
57
62
  const exhaustive: never = driver;
58
63
  throw new Error(`Unsupported driver: ${exhaustive}`);
@@ -225,6 +230,7 @@ function defaultPortFor(driver: DbDriver): number {
225
230
  case 'postgres': return 5432;
226
231
  case 'mongodb': return 27017;
227
232
  case 'redis': return 6379;
233
+ case 'mssql': return 1433;
228
234
  case 'sqlite': return 0;
229
235
  }
230
236
  }