@dmrlzz/davecode 0.5.1 → 0.5.3

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 (66) hide show
  1. package/dist/{ChatApp-YMHKIAAH.js → ChatApp-IF5D7XNH.js} +7 -6
  2. package/dist/{ChatApp-YMHKIAAH.js.map → ChatApp-IF5D7XNH.js.map} +1 -1
  3. package/dist/{account-5QFYCVYM.js → account-KBXJ5KR7.js} +4 -3
  4. package/dist/{accounts-756BMMAL.js → accounts-XUJNDCFH.js} +6 -5
  5. package/dist/{budget-PGSNCVVK.js → budget-PHV4NRUS.js} +5 -4
  6. package/dist/{budget-PGSNCVVK.js.map → budget-PHV4NRUS.js.map} +1 -1
  7. package/dist/{chat-D3T4YG5D.js → chat-HGTX76DU.js} +9 -8
  8. package/dist/{chat-D3T4YG5D.js.map → chat-HGTX76DU.js.map} +1 -1
  9. package/dist/chunk-732GIHRQ.js +23 -0
  10. package/dist/chunk-732GIHRQ.js.map +1 -0
  11. package/dist/{chunk-6WUVR3R2.js → chunk-AFCQURO5.js} +3 -3
  12. package/dist/{chunk-6SHOBL2X.js → chunk-DFQW3MRD.js} +2 -2
  13. package/dist/{chunk-JSRPO2AR.js → chunk-EBV5A33R.js} +4 -4
  14. package/dist/{chunk-IOATP7KH.js → chunk-FPSLYBLU.js} +5 -21
  15. package/dist/chunk-FPSLYBLU.js.map +1 -0
  16. package/dist/{chunk-K5AA65RS.js → chunk-FZJNOG2T.js} +2 -2
  17. package/dist/{chunk-HENE4DA6.js → chunk-ING5HCIO.js} +71 -3
  18. package/dist/chunk-ING5HCIO.js.map +1 -0
  19. package/dist/{chunk-JFWMLYV7.js → chunk-YSD6W27K.js} +130 -89
  20. package/dist/chunk-YSD6W27K.js.map +1 -0
  21. package/dist/{chunk-ZNUNYYN6.js → chunk-ZVNX7CSO.js} +3 -3
  22. package/dist/{config-TKGGYEN7.js → config-DG2E4VDW.js} +4 -3
  23. package/dist/{config-TKGGYEN7.js.map → config-DG2E4VDW.js.map} +1 -1
  24. package/dist/dashboard/assets/{Accounts-DciFUg4y.js → Accounts-DXiGsutB.js} +1 -1
  25. package/dist/dashboard/assets/{Callout-WgXHDPg0.js → Callout-1E8Wsl9W.js} +1 -1
  26. package/dist/dashboard/assets/{Goals-C6HL1PNE.js → Goals-kL4VAxw3.js} +1 -1
  27. package/dist/dashboard/assets/{Library-DwpBYTbK.js → Library-DZxBVUo_.js} +1 -1
  28. package/dist/dashboard/assets/{Panes-DxFSwhb7.js → Panes-C-TJekjs.js} +1 -1
  29. package/dist/dashboard/assets/{RoutesPage-Cyo0MNd7.js → RoutesPage-DWYm9tW8.js} +1 -1
  30. package/dist/dashboard/assets/{Runner-CIL7RxpN.js → Runner-CmHBjECR.js} +1 -1
  31. package/dist/dashboard/assets/{Settings-B_PEB585.js → Settings-BANphxva.js} +1 -1
  32. package/dist/dashboard/assets/{Tasks-DEfPSaE6.js → Tasks-cSx1PKyQ.js} +1 -1
  33. package/dist/dashboard/assets/{Traffic-Dcz-WhsP.js → Traffic-DEAuM6jq.js} +1 -1
  34. package/dist/dashboard/assets/{Workspace-9UCw9q7C.js → Workspace-BQFjc1jH.js} +1 -1
  35. package/dist/dashboard/assets/index-B8kld9xo.js +104 -0
  36. package/dist/dashboard/index.html +1 -1
  37. package/dist/{dist-F3NRJ5FK.js → dist-IPMBGFJD.js} +4 -2
  38. package/dist/{doctor-V4XXVVGK.js → doctor-5APOWJ5D.js} +4 -3
  39. package/dist/{doctor-V4XXVVGK.js.map → doctor-5APOWJ5D.js.map} +1 -1
  40. package/dist/{goal-RUHYPVPA.js → goal-ETZWLVKO.js} +4 -3
  41. package/dist/{goal-RUHYPVPA.js.map → goal-ETZWLVKO.js.map} +1 -1
  42. package/dist/index.js +31 -31
  43. package/dist/{init-54FKQZ2Z.js → init-YDLNA3GD.js} +4 -3
  44. package/dist/{init-54FKQZ2Z.js.map → init-YDLNA3GD.js.map} +1 -1
  45. package/dist/{run-4R25J2VN.js → run-I6N7TLHV.js} +4 -3
  46. package/dist/{run-4R25J2VN.js.map → run-I6N7TLHV.js.map} +1 -1
  47. package/dist/runtime.js +3 -2
  48. package/dist/{start-GRHW3TGE.js → start-ECLELJGJ.js} +4 -3
  49. package/dist/{start-GRHW3TGE.js.map → start-ECLELJGJ.js.map} +1 -1
  50. package/dist/{status-QR2HNPBK.js → status-QQPP67I4.js} +5 -4
  51. package/dist/{tasks-BHWDV4JS.js → tasks-RNMC2XFN.js} +5 -4
  52. package/dist/{tasks-BHWDV4JS.js.map → tasks-RNMC2XFN.js.map} +1 -1
  53. package/package.json +4 -4
  54. package/dist/chunk-HENE4DA6.js.map +0 -1
  55. package/dist/chunk-IOATP7KH.js.map +0 -1
  56. package/dist/chunk-JFWMLYV7.js.map +0 -1
  57. package/dist/dashboard/assets/index-CpztPbom.js +0 -104
  58. /package/dist/{account-5QFYCVYM.js.map → account-KBXJ5KR7.js.map} +0 -0
  59. /package/dist/{accounts-756BMMAL.js.map → accounts-XUJNDCFH.js.map} +0 -0
  60. /package/dist/{chunk-6WUVR3R2.js.map → chunk-AFCQURO5.js.map} +0 -0
  61. /package/dist/{chunk-6SHOBL2X.js.map → chunk-DFQW3MRD.js.map} +0 -0
  62. /package/dist/{chunk-JSRPO2AR.js.map → chunk-EBV5A33R.js.map} +0 -0
  63. /package/dist/{chunk-K5AA65RS.js.map → chunk-FZJNOG2T.js.map} +0 -0
  64. /package/dist/{chunk-ZNUNYYN6.js.map → chunk-ZVNX7CSO.js.map} +0 -0
  65. /package/dist/{dist-F3NRJ5FK.js.map → dist-IPMBGFJD.js.map} +0 -0
  66. /package/dist/{status-QR2HNPBK.js.map → status-QQPP67I4.js.map} +0 -0
@@ -1,3 +1,6 @@
1
+ import {
2
+ openBrowser
3
+ } from "./chunk-732GIHRQ.js";
1
4
  import {
2
5
  ConfigError,
3
6
  PROVIDER_KINDS,
@@ -11,6 +14,7 @@ import {
11
14
  WorkspaceLock,
12
15
  apiConfigIssues,
13
16
  connectionMethod,
17
+ createAccountControl,
14
18
  createEngine,
15
19
  createGoalService,
16
20
  createRunner,
@@ -21,7 +25,7 @@ import {
21
25
  newId2,
22
26
  routeSchema,
23
27
  taskIdSchema
24
- } from "./chunk-HENE4DA6.js";
28
+ } from "./chunk-ING5HCIO.js";
25
29
 
26
30
  // src/runtime.ts
27
31
  import { existsSync as existsSync3 } from "fs";
@@ -37,13 +41,14 @@ import { resolve } from "path";
37
41
  import cors from "@fastify/cors";
38
42
  import fastifyStatic from "@fastify/static";
39
43
  import Fastify from "fastify";
40
- import { z as z4 } from "zod";
41
44
  import { z } from "zod";
45
+ import { z as z5 } from "zod";
42
46
  import { z as z2 } from "zod";
43
47
  import { z as z3 } from "zod";
44
- import { z as z5 } from "zod";
45
- import { Readable } from "stream";
48
+ import { z as z4 } from "zod";
46
49
  import { z as z6 } from "zod";
50
+ import { Readable } from "stream";
51
+ import { z as z7 } from "zod";
47
52
  function sendApiError(reply, status, code, message, extra = {}) {
48
53
  return reply.code(status).send({ error: { message, code, ...extra } });
49
54
  }
@@ -92,55 +97,81 @@ function describeRoutingError(err) {
92
97
  body: { message: "Internal gateway error", type: "api_error", code: "internal_error" }
93
98
  };
94
99
  }
95
- var providerKind = z.enum(PROVIDER_KINDS);
96
- var contentPart = z.discriminatedUnion("type", [
97
- z.object({ type: z.literal("text"), text: z.string() }),
98
- z.object({
99
- type: z.literal("image_url"),
100
- image_url: z.object({
101
- url: z.string(),
102
- detail: z.enum(["auto", "low", "high"]).optional()
100
+ var loginSchema = z.object({ provider: z.enum(["google", "github"]).optional() });
101
+ function registerAccountRoutes(app, account) {
102
+ if (!account) return;
103
+ app.get("/api/account", async (_request, reply) => {
104
+ reply.header("Cache-Control", "no-store");
105
+ return account.state();
106
+ });
107
+ app.post("/api/account/login", async (request, reply) => {
108
+ const parsed = loginSchema.safeParse(request.body ?? {});
109
+ if (!parsed.success)
110
+ return sendApiError(reply, 400, "invalid_body", "Unknown sign-in provider.");
111
+ try {
112
+ return reply.code(202).send(await account.login(parsed.data.provider));
113
+ } catch {
114
+ return sendApiError(reply, 502, "account_unavailable", "Could not start the sign-in.");
115
+ }
116
+ });
117
+ app.post("/api/account/cancel", async (_request, reply) => {
118
+ await account.cancel();
119
+ return reply.code(204).send();
120
+ });
121
+ app.post("/api/account/logout", async (_request, reply) => {
122
+ await account.logout();
123
+ return reply.code(204).send();
124
+ });
125
+ }
126
+ var providerKind = z2.enum(PROVIDER_KINDS);
127
+ var contentPart = z2.discriminatedUnion("type", [
128
+ z2.object({ type: z2.literal("text"), text: z2.string() }),
129
+ z2.object({
130
+ type: z2.literal("image_url"),
131
+ image_url: z2.object({
132
+ url: z2.string(),
133
+ detail: z2.enum(["auto", "low", "high"]).optional()
103
134
  })
104
135
  })
105
136
  ]);
106
- var toolCall = z.object({
107
- id: z.string(),
108
- type: z.literal("function"),
109
- function: z.object({ name: z.string(), arguments: z.string() })
137
+ var toolCall = z2.object({
138
+ id: z2.string(),
139
+ type: z2.literal("function"),
140
+ function: z2.object({ name: z2.string(), arguments: z2.string() })
110
141
  });
111
- var chatMessage = z.object({
112
- role: z.enum(["system", "user", "assistant", "tool"]),
113
- content: z.union([z.string(), z.array(contentPart), z.null()]),
114
- name: z.string().optional(),
115
- tool_call_id: z.string().optional(),
116
- tool_calls: z.array(toolCall).optional()
142
+ var chatMessage = z2.object({
143
+ role: z2.enum(["system", "user", "assistant", "tool"]),
144
+ content: z2.union([z2.string(), z2.array(contentPart), z2.null()]),
145
+ name: z2.string().optional(),
146
+ tool_call_id: z2.string().optional(),
147
+ tool_calls: z2.array(toolCall).optional()
117
148
  });
118
- var chatRequestSchema = z.object({
119
- model: z.string().min(1),
120
- messages: z.array(chatMessage).min(1),
121
- stream: z.boolean().optional(),
122
- temperature: z.number().min(0).max(2).optional(),
123
- top_p: z.number().min(0).max(1).optional(),
124
- max_tokens: z.number().int().positive().optional(),
125
- stop: z.union([z.string(), z.array(z.string())]).optional(),
126
- tools: z.array(
127
- z.object({
128
- type: z.literal("function"),
129
- function: z.object({
130
- name: z.string(),
131
- description: z.string().optional(),
132
- parameters: z.record(z.string(), z.unknown()).optional()
149
+ var chatRequestSchema = z2.object({
150
+ model: z2.string().min(1),
151
+ messages: z2.array(chatMessage).min(1),
152
+ stream: z2.boolean().optional(),
153
+ temperature: z2.number().min(0).max(2).optional(),
154
+ top_p: z2.number().min(0).max(1).optional(),
155
+ max_tokens: z2.number().int().positive().optional(),
156
+ stop: z2.union([z2.string(), z2.array(z2.string())]).optional(),
157
+ tools: z2.array(
158
+ z2.object({
159
+ type: z2.literal("function"),
160
+ function: z2.object({
161
+ name: z2.string(),
162
+ description: z2.string().optional(),
163
+ parameters: z2.record(z2.string(), z2.unknown()).optional()
133
164
  })
134
165
  })
135
166
  ).optional(),
136
- tool_choice: z.union([
137
- z.enum(["auto", "none", "required"]),
138
- z.object({ type: z.literal("function"), function: z.object({ name: z.string() }) })
167
+ tool_choice: z2.union([
168
+ z2.enum(["auto", "none", "required"]),
169
+ z2.object({ type: z2.literal("function"), function: z2.object({ name: z2.string() }) })
139
170
  ]).optional(),
140
- user: z.string().optional()
171
+ user: z2.string().optional()
141
172
  });
142
- var positiveInt = z.number().int().positive();
143
- var quotaLimits = z.object({
173
+ var positiveInt = z2.number().int().positive();
174
+ var quotaLimits = z2.object({
144
175
  tpm: positiveInt.optional(),
145
176
  rpm: positiveInt.optional(),
146
177
  tokens5h: positiveInt.optional(),
@@ -149,41 +180,41 @@ var quotaLimits = z.object({
149
180
  requestsDaily: positiveInt.optional()
150
181
  }).strict();
151
182
  var SECRET_KEY = /^(api[-_]?key|secret|client[-_]?secret|(access|refresh|session|auth|bearer)?[-_]?token|password|passwd|cookies?|authorization|credentials?)$/i;
152
- var accountConfig = z.record(z.string(), z.unknown()).refine((config) => !Object.keys(config).some((key) => SECRET_KEY.test(key)), {
183
+ var accountConfig = z2.record(z2.string(), z2.unknown()).refine((config) => !Object.keys(config).some((key) => SECRET_KEY.test(key)), {
153
184
  message: 'config must not contain credentials; send them in "secret" instead'
154
185
  });
155
- var subscriptionDate = z.string().trim().refine(
186
+ var subscriptionDate = z2.string().trim().refine(
156
187
  (value) => /^\d{4}-\d{2}-\d{2}(T[\d:.]+(Z|[+-]\d{2}:?\d{2})?)?$/.test(value) && !Number.isNaN(Date.parse(value)),
157
188
  { message: "expected a date (YYYY-MM-DD) or an ISO timestamp" }
158
189
  );
159
- var subscriptionSchema = z.object({
160
- plan: z.string().trim().min(1).max(120).optional(),
190
+ var subscriptionSchema = z2.object({
191
+ plan: z2.string().trim().min(1).max(120).optional(),
161
192
  paidAt: subscriptionDate.optional(),
162
193
  renewsAt: subscriptionDate.optional(),
163
- price: z.object({
164
- amount: z.number().min(0).max(1e6),
165
- currency: z.string().trim().regex(/^[A-Za-z]{3}$/, "expected a 3-letter currency code").transform((c) => c.toUpperCase()),
166
- period: z.enum(["month", "year"])
194
+ price: z2.object({
195
+ amount: z2.number().min(0).max(1e6),
196
+ currency: z2.string().trim().regex(/^[A-Za-z]{3}$/, "expected a 3-letter currency code").transform((c) => c.toUpperCase()),
197
+ period: z2.enum(["month", "year"])
167
198
  }).strict().optional(),
168
- notes: z.string().trim().max(1e3).optional()
199
+ notes: z2.string().trim().max(1e3).optional()
169
200
  }).strict();
170
201
  var accountFields = {
171
- label: z.string().trim().min(1).max(200),
172
- enabled: z.boolean().optional(),
173
- priority: z.number().int().min(0).max(1e6).optional(),
174
- weight: z.number().min(0).max(1e3).optional(),
202
+ label: z2.string().trim().min(1).max(200),
203
+ enabled: z2.boolean().optional(),
204
+ priority: z2.number().int().min(0).max(1e6).optional(),
205
+ weight: z2.number().min(0).max(1e3).optional(),
175
206
  limits: quotaLimits.optional(),
176
207
  config: accountConfig.optional(),
177
208
  /** API key / token. Encrypted at rest and never returned. */
178
- secret: z.string().min(1).max(1e5).optional()
209
+ secret: z2.string().min(1).max(1e5).optional()
179
210
  };
180
- var accountCreateSchema = z.object({ provider: providerKind, ...accountFields, subscription: subscriptionSchema.optional() }).strict();
181
- var accountPatchSchema = z.object({
211
+ var accountCreateSchema = z2.object({ provider: providerKind, ...accountFields, subscription: subscriptionSchema.optional() }).strict();
212
+ var accountPatchSchema = z2.object({
182
213
  ...accountFields,
183
214
  label: accountFields.label.optional(),
184
215
  subscription: subscriptionSchema.nullable().optional()
185
216
  }).strict();
186
- var routesUpdateSchema = z.object({ routes: z.array(routeSchema).max(200), defaultRoute: z.string().min(1).optional() }).strict().superRefine((body, ctx) => {
217
+ var routesUpdateSchema = z2.object({ routes: z2.array(routeSchema).max(200), defaultRoute: z2.string().min(1).optional() }).strict().superRefine((body, ctx) => {
187
218
  const seen = /* @__PURE__ */ new Set();
188
219
  body.routes.forEach((route, index) => {
189
220
  if (seen.has(route.name)) {
@@ -204,14 +235,14 @@ var routesUpdateSchema = z.object({ routes: z.array(routeSchema).max(200), defau
204
235
  }
205
236
  });
206
237
  var taskText = {
207
- title: z.string().trim().min(1).max(300),
208
- description: z.string().max(5e4),
209
- acceptance: z.array(z.string().trim().min(1).max(2e3)).max(100),
210
- notes: z.string().max(5e4),
211
- dependsOn: z.array(z.string().min(1)).max(500),
212
- priority: z.number().finite()
238
+ title: z2.string().trim().min(1).max(300),
239
+ description: z2.string().max(5e4),
240
+ acceptance: z2.array(z2.string().trim().min(1).max(2e3)).max(100),
241
+ notes: z2.string().max(5e4),
242
+ dependsOn: z2.array(z2.string().min(1)).max(500),
243
+ priority: z2.number().finite()
213
244
  };
214
- var taskCreateSchema = z.object({
245
+ var taskCreateSchema = z2.object({
215
246
  id: taskIdSchema,
216
247
  title: taskText.title,
217
248
  description: taskText.description.optional(),
@@ -219,30 +250,30 @@ var taskCreateSchema = z.object({
219
250
  priority: taskText.priority.optional(),
220
251
  acceptance: taskText.acceptance.optional()
221
252
  }).strict();
222
- var taskPatchSchema = z.object({
253
+ var taskPatchSchema = z2.object({
223
254
  title: taskText.title.optional(),
224
255
  description: taskText.description.nullable().optional(),
225
256
  dependsOn: taskText.dependsOn.optional(),
226
257
  priority: taskText.priority.nullable().optional(),
227
258
  acceptance: taskText.acceptance.nullable().optional(),
228
259
  notes: taskText.notes.nullable().optional(),
229
- status: z.enum(TASK_STATUSES).optional()
260
+ status: z2.enum(TASK_STATUSES).optional()
230
261
  }).strict().refine((patch) => Object.values(patch).some((v) => v !== void 0), {
231
262
  message: "send at least one field to change"
232
263
  });
233
- var runnerStartSchema = z.object({ taskId: z.string().min(1).optional() }).strict();
234
- var goalStartSchema = z.object({
235
- objective: z.string().trim().min(1).max(4e3),
236
- maxRounds: z.number().int().min(1).max(20).optional(),
237
- maxTasks: z.number().int().min(1).max(100).optional(),
238
- maxTokens: z.number().int().min(1e3).optional(),
239
- dryRun: z.boolean().optional()
264
+ var runnerStartSchema = z2.object({ taskId: z2.string().min(1).optional() }).strict();
265
+ var goalStartSchema = z2.object({
266
+ objective: z2.string().trim().min(1).max(4e3),
267
+ maxRounds: z2.number().int().min(1).max(20).optional(),
268
+ maxTasks: z2.number().int().min(1).max(100).optional(),
269
+ maxTokens: z2.number().int().min(1e3).optional(),
270
+ dryRun: z2.boolean().optional()
240
271
  }).strict();
241
- var timeseriesQuerySchema = z.object({
242
- minutes: z.coerce.number().int().min(1).max(7 * 24 * 60).default(60),
243
- bucketSec: z.coerce.number().int().min(1).max(86400).default(60)
272
+ var timeseriesQuerySchema = z2.object({
273
+ minutes: z2.coerce.number().int().min(1).max(7 * 24 * 60).default(60),
274
+ bucketSec: z2.coerce.number().int().min(1).max(86400).default(60)
244
275
  });
245
- var limitQuerySchema = (fallback, max = 1e3) => z.object({ limit: z.coerce.number().int().min(1).max(max).default(fallback) });
276
+ var limitQuerySchema = (fallback, max = 1e3) => z2.object({ limit: z2.coerce.number().int().min(1).max(max).default(fallback) });
246
277
  function registerGoalRoutes(app, engine, options) {
247
278
  const { audit } = engine;
248
279
  const unavailable = (reply) => sendApiError(
@@ -284,7 +315,7 @@ function registerGoalRoutes(app, engine, options) {
284
315
  app.post("/api/goals", async (request, reply) => {
285
316
  const parsed = goalStartSchema.safeParse(request.body);
286
317
  if (!parsed.success) {
287
- return sendApiError(reply, 400, "invalid_body", z2.prettifyError(parsed.error));
318
+ return sendApiError(reply, 400, "invalid_body", z3.prettifyError(parsed.error));
288
319
  }
289
320
  const goals = control(reply);
290
321
  if (!goals) return reply;
@@ -388,7 +419,7 @@ function registerTaskRoutes(app, engine, options) {
388
419
  app.post("/api/tasks", async (request, reply) => {
389
420
  const parsed = taskCreateSchema.safeParse(request.body);
390
421
  if (!parsed.success) {
391
- return sendApiError(reply, 400, "invalid_body", z3.prettifyError(parsed.error));
422
+ return sendApiError(reply, 400, "invalid_body", z4.prettifyError(parsed.error));
392
423
  }
393
424
  const brain = writable(reply);
394
425
  if (isReply(brain)) return brain;
@@ -403,7 +434,7 @@ function registerTaskRoutes(app, engine, options) {
403
434
  app.patch("/api/tasks/:id", async (request, reply) => {
404
435
  const parsed = taskPatchSchema.safeParse(request.body);
405
436
  if (!parsed.success) {
406
- return sendApiError(reply, 400, "invalid_body", z3.prettifyError(parsed.error));
437
+ return sendApiError(reply, 400, "invalid_body", z4.prettifyError(parsed.error));
407
438
  }
408
439
  const brain = writable(reply);
409
440
  if (isReply(brain)) return brain;
@@ -446,7 +477,7 @@ function isReply(value) {
446
477
  var EMPTY_GRAPH = { version: 1, tasks: [] };
447
478
  var IDLE = { state: "idle" };
448
479
  function invalid(reply, error) {
449
- return sendApiError(reply, 400, "invalid_body", z4.prettifyError(error));
480
+ return sendApiError(reply, 400, "invalid_body", z5.prettifyError(error));
450
481
  }
451
482
  function registerApiRoutes(app, engine, options) {
452
483
  const { accounts, events, audit, quota, keyring } = engine;
@@ -748,7 +779,7 @@ function registerAuthRoutes(app, login) {
748
779
  reply.header("Cache-Control", "no-store").header("Referrer-Policy", "no-referrer");
749
780
  if (!login)
750
781
  return sendApiError(reply, 503, "login_not_configured", "Sign-in is not configured.");
751
- const parsed = z5.object({ state: z5.string().min(1).max(200), code: z5.string().min(1).max(4096) }).safeParse(request.query);
782
+ const parsed = z6.object({ state: z6.string().min(1).max(200), code: z6.string().min(1).max(4096) }).safeParse(request.query);
752
783
  const binding = authCookie(request, "dc_login");
753
784
  if (!parsed.success || !binding)
754
785
  return reply.redirect(`${login.options.origin}/#/login?error=signin_failed`);
@@ -848,7 +879,7 @@ function registerV1Routes(app, engine) {
848
879
  const parsed = chatRequestSchema.safeParse(request.body);
849
880
  if (!parsed.success) {
850
881
  return sendOpenAIError(reply, 400, {
851
- message: z6.prettifyError(parsed.error),
882
+ message: z7.prettifyError(parsed.error),
852
883
  type: "invalid_request_error",
853
884
  code: "invalid_body"
854
885
  });
@@ -1095,6 +1126,7 @@ async function buildGateway(engine, options = {}) {
1095
1126
  });
1096
1127
  registerV1Routes(app, engine);
1097
1128
  registerAuthRoutes(app, login);
1129
+ registerAccountRoutes(app, options.account);
1098
1130
  registerApiRoutes(app, engine, options);
1099
1131
  registerEventRoutes(app, engine, options.heartbeatMs ?? 15e3);
1100
1132
  return app;
@@ -1633,18 +1665,25 @@ async function startRuntime(options) {
1633
1665
  ...projectRoot ? { projectRoot } : {},
1634
1666
  ...options.config ? { config: options.config } : {}
1635
1667
  });
1668
+ let account;
1636
1669
  try {
1637
1670
  const project = projectRoot ? wireProject(engine, projectRoot, { env: options.env }) : void 0;
1638
1671
  const wantDashboard = options.dashboard !== false && engine.config.server.dashboard;
1639
1672
  const dashboardDir = wantDashboard ? resolveDashboardDir(options.env) : void 0;
1640
1673
  const bindHost = options.host ?? engine.config.server.host;
1641
1674
  const loginLauncher = LOOPBACK_HOSTS.has(bindHost) ? {
1642
- launch: async (account) => ({
1643
- launched: await launchLoginTerminal(account.id, { env: options.env })
1675
+ launch: async (account2) => ({
1676
+ launched: await launchLoginTerminal(account2.id, { env: options.env })
1644
1677
  })
1645
1678
  } : void 0;
1679
+ account = LOOPBACK_HOSTS.has(bindHost) ? createAccountControl({
1680
+ home: options.home,
1681
+ env: options.env,
1682
+ open: (url) => openBrowser(url)
1683
+ }) : void 0;
1646
1684
  const app = await startGateway(engine, {
1647
1685
  logger: options.logger ?? false,
1686
+ ...account ? { account } : {},
1648
1687
  ...options.loginLauncher ?? loginLauncher ? { loginLauncher: options.loginLauncher ?? loginLauncher } : {},
1649
1688
  ...dashboardDir ? { dashboardDir } : {},
1650
1689
  ...project ? { brain: project.source, runner: project.runner, goals: project.goals } : {},
@@ -1674,6 +1713,7 @@ async function startRuntime(options) {
1674
1713
  const active = goals?.activeGoalId;
1675
1714
  if (active) await goals?.cancel(active);
1676
1715
  await runner?.stop();
1716
+ await account?.close();
1677
1717
  await app.close();
1678
1718
  } finally {
1679
1719
  engine.close();
@@ -1681,6 +1721,7 @@ async function startRuntime(options) {
1681
1721
  }
1682
1722
  };
1683
1723
  } catch (err) {
1724
+ await account?.close();
1684
1725
  engine.close();
1685
1726
  throw err;
1686
1727
  }
@@ -1703,4 +1744,4 @@ export {
1703
1744
  resolveProjectRoot,
1704
1745
  startRuntime
1705
1746
  };
1706
- //# sourceMappingURL=chunk-JFWMLYV7.js.map
1747
+ //# sourceMappingURL=chunk-YSD6W27K.js.map