Commit c3e5bba
authored
feat: unify the provider tables and resolve the chat provider on the server (#2540)
* feat(server): merge acp agents and llm providers into one table
Both are providers for the chat, and everything above the database already
said so: the chat target is one union with a kind on the client, and the
wire target has always been a discriminated union. Only storage disagreed,
and it charged for the mismatch. Selecting an acp agent left the default
provider pointing at the previously selected llm one, because the write was
conditional on kind. A scheduled job could reference an llm provider and
nothing else, so picking Claude Code in chat was possible while scheduling
against it was not.
Migration 0010 creates the unified table and copies both sources in; 0011
repoints scheduled jobs and drops the old tables. Two migrations rather than
one, so the copy proves itself before anything is dropped, and because
drizzle cannot diff a simultaneous add and remove without a rename prompt.
Drizzle put its drops ahead of its own foreign key pragma, which fired the
ON DELETE SET NULL on scheduled jobs and silently unlinked every job from
its provider. Reordered so the drops happen after the rebuild, inside the
block where enforcement is off.
The default provider now lives on a column, and a partial unique index
admits exactly one row, of either kind. Not keyed by profile: sqlite treats
nulls as distinct in a unique index, so pairing it with the unset profile
column would let every row be default at once.
Also brings the packaged-build schema fallback current. It had drifted four
migrations behind, so a build without migration files would have created a
database with none of this epic's tables. The test's copy of the migration
history is now derived from the journal, since a hand written duplicate is
what let the drift go unnoticed.
* feat: resolve the chat provider on the server
The provider block is gone from the chat body. A request names an id, or
names nothing and gets whichever provider is selected, and the server fills
in the model, endpoint and credentials from the row. Sixteen fields of
provider configuration collapse into one, and the api key, the aws secret
and the session token stop crossing the wire on every message.
Every one of those fields is still accepted. The extension updates
independently of the browser binary, so a shipped build can be running a
client that sends the whole configuration inline; the server stops
requiring them, not accepting them, and a row it does not recognise leaves
whatever the client sent in place.
The selection moved to the server with the tables it points at, so choosing
a coding agent now records it. It could not before: the default lived in
extension storage and only ever named an llm provider, so picking an agent
left it pointing at the provider chosen before it.
The scheduled runner drops its provider lookup entirely, and the guard that
came with it. That guard existed because an unreachable list and an empty
one looked alike, so a job could run on the built-in provider with the
wrong credentials and still be recorded as a success. There is nothing to
tell apart now: the job names an id and the server resolves it.
Refine prompt still resolves on the client. It posts to its own endpoint
with its own schema, and giving it the same treatment is separate work.
* fix(server): gate chat on trust when the server supplies the credentials
A browseros chat request is deliberately allowed without the app-origin
check, on the reasoning that it carries its own credentials and so can only
spend what the caller already had. Resolving the provider from storage broke
that reasoning: naming an id, or naming nothing and taking the selected
provider, would have let any local caller spend the user's key against an
external service.
The check now applies exactly when the configuration came from a stored row.
A request that brought its own is as unrestricted as it was before, so the
capability that reasoning was about is untouched.
* fix(server): gate chat on every path where the server holds the credential
The previous gate keyed on whether a stored provider row was read, on the
reasoning that a request naming no known row must have brought its own key.
That is false for four provider types. The oauth three take a token from
this machine's oauth store and browseros takes the gateway credential, so
naming one with an unknown id skipped the check and had the server hand
over a credential the caller never held.
The predicate lives beside resolveLLMConfig, since it has to mirror those
branches exactly and would drift if the route kept its own copy.
This particular hole predates the change: the exemption for browseros
requests and the credential injection behind it were both already there. It
is fixed here because the gate added alongside it claims the ungated path is
safe, and that claim has to hold.
The chat integration test now sends the origin header the extension always
sends. It was relying on the exemption this closes, and the routes the
background alarm runner already calls carry that header today.
* test(server): stop a module mock dropping the exports it does not name
CI failed with `Export named 'SERVER_CREDENTIALED_PROVIDERS' not found`
against a file that plainly exports it. A module factory is a total
replacement, so everything it omits disappears for every file importing that
module afterwards, and bun's registry is process wide. Adding an export to a
module someone mocks partially is enough to break a different file entirely.
The factory now spreads the real module and overrides only the function under
test. This does not reproduce locally: file ordering is stable on APFS and
not on ext4, which the test runner's own notes call out as the reason this
class of failure kills CI while local runs pass.1 parent 92df7a9 commit c3e5bba
47 files changed
Lines changed: 3256 additions & 728 deletions
File tree
- packages/browseros-agent/apps
- app
- lib
- messaging/server
- schedules
- modules
- chat
- llm-providers
- local-first-migration
- server
- src
- api
- routes
- services
- lib
- agents/storage
- clients/llm
- db
- migrations
- meta
- schema
- llm-providers
- providers
- tests
- api
- routes
- services
- lib
- agents
- db
- llm-providers
- providers
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 40 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
29 | 68 | | |
30 | 69 | | |
31 | 70 | | |
| |||
Lines changed: 25 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
44 | 53 | | |
45 | 54 | | |
46 | 55 | | |
| |||
61 | 70 | | |
62 | 71 | | |
63 | 72 | | |
| 73 | + | |
64 | 74 | | |
65 | 75 | | |
66 | 76 | | |
| |||
74 | 84 | | |
75 | 85 | | |
76 | 86 | | |
77 | | - | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
78 | 97 | | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | 98 | | |
86 | | - | |
87 | 99 | | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | 100 | | |
98 | 101 | | |
99 | 102 | | |
100 | | - | |
101 | | - | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
102 | 107 | | |
103 | 108 | | |
104 | 109 | | |
| |||
Lines changed: 6 additions & 51 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | 4 | | |
10 | 5 | | |
11 | 6 | | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | 7 | | |
18 | 8 | | |
19 | 9 | | |
| |||
73 | 63 | | |
74 | 64 | | |
75 | 65 | | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | 66 | | |
115 | 67 | | |
116 | 68 | | |
117 | 69 | | |
118 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
119 | 75 | | |
120 | 76 | | |
121 | 77 | | |
| |||
138 | 94 | | |
139 | 95 | | |
140 | 96 | | |
| 97 | + | |
141 | 98 | | |
142 | 99 | | |
143 | | - | |
144 | 100 | | |
145 | 101 | | |
146 | 102 | | |
| |||
157 | 113 | | |
158 | 114 | | |
159 | 115 | | |
160 | | - | |
161 | 116 | | |
162 | 117 | | |
163 | 118 | | |
| |||
Lines changed: 39 additions & 102 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
81 | 97 | | |
82 | 98 | | |
83 | 99 | | |
| |||
106 | 122 | | |
107 | 123 | | |
108 | 124 | | |
109 | | - | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
110 | 131 | | |
111 | 132 | | |
112 | 133 | | |
| |||
115 | 136 | | |
116 | 137 | | |
117 | 138 | | |
118 | | - | |
119 | | - | |
120 | | - | |
| 139 | + | |
| 140 | + | |
121 | 141 | | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
122 | 157 | | |
123 | 158 | | |
124 | 159 | | |
| |||
141 | 176 | | |
142 | 177 | | |
143 | 178 | | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
25 | 24 | | |
26 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
| |||
0 commit comments