The best way to control Claude Code, Codex and more from any computer or phone

main
ts 114 lines 3.2 KB
Raw
1 import * as Effect from "effect/Effect";
2 import * as SqlClient from "effect/sql/SqlClient";
3
4 export default Effect.gen(function* () {
5 const sql = yield* SqlClient.SqlClient;
6
7 yield* sql`
8 UPDATE projection_threads
9 SET model_selection_json = json_set(
10 model_selection_json,
11 '$.options',
12 json((
13 SELECT json_group_array(
14 json_object(
15 'id', key,
16 'value',
17 CASE type
18 WHEN 'true' THEN json('true')
19 WHEN 'false' THEN json('false')
20 ELSE atom
21 END
22 )
23 )
24 FROM json_each(json_extract(model_selection_json, '$.options'))
25 WHERE (type = 'text' AND trim(coalesce(atom, '')) != '')
26 OR type IN ('true', 'false')
27 ))
28 )
29 WHERE model_selection_json IS NOT NULL
30 AND json_type(model_selection_json, '$.options') = 'object'
31 `;
32
33 yield* sql`
34 UPDATE projection_projects
35 SET default_model_selection_json = json_set(
36 default_model_selection_json,
37 '$.options',
38 json((
39 SELECT json_group_array(
40 json_object(
41 'id', key,
42 'value',
43 CASE type
44 WHEN 'true' THEN json('true')
45 WHEN 'false' THEN json('false')
46 ELSE atom
47 END
48 )
49 )
50 FROM json_each(json_extract(default_model_selection_json, '$.options'))
51 WHERE (type = 'text' AND trim(coalesce(atom, '')) != '')
52 OR type IN ('true', 'false')
53 ))
54 )
55 WHERE default_model_selection_json IS NOT NULL
56 AND json_type(default_model_selection_json, '$.options') = 'object'
57 `;
58
59 yield* sql`
60 UPDATE orchestration_events
61 SET payload_json = json_set(
62 payload_json,
63 '$.modelSelection.options',
64 json((
65 SELECT json_group_array(
66 json_object(
67 'id', key,
68 'value',
69 CASE type
70 WHEN 'true' THEN json('true')
71 WHEN 'false' THEN json('false')
72 ELSE atom
73 END
74 )
75 )
76 FROM json_each(json_extract(payload_json, '$.modelSelection.options'))
77 WHERE (type = 'text' AND trim(coalesce(atom, '')) != '')
78 OR type IN ('true', 'false')
79 ))
80 )
81 WHERE event_type IN (
82 'thread.created',
83 'thread.meta-updated',
84 'thread.turn-start-requested'
85 )
86 AND json_type(payload_json, '$.modelSelection.options') = 'object'
87 `;
88
89 yield* sql`
90 UPDATE orchestration_events
91 SET payload_json = json_set(
92 payload_json,
93 '$.defaultModelSelection.options',
94 json((
95 SELECT json_group_array(
96 json_object(
97 'id', key,
98 'value',
99 CASE type
100 WHEN 'true' THEN json('true')
101 WHEN 'false' THEN json('false')
102 ELSE atom
103 END
104 )
105 )
106 FROM json_each(json_extract(payload_json, '$.defaultModelSelection.options'))
107 WHERE (type = 'text' AND trim(coalesce(atom, '')) != '')
108 OR type IN ('true', 'false')
109 ))
110 )
111 WHERE event_type IN ('project.created', 'project.meta-updated')
112 AND json_type(payload_json, '$.defaultModelSelection.options') = 'object'
113 `;
114 });