@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.
- package/dist/{ChatApp-YMHKIAAH.js → ChatApp-IF5D7XNH.js} +7 -6
- package/dist/{ChatApp-YMHKIAAH.js.map → ChatApp-IF5D7XNH.js.map} +1 -1
- package/dist/{account-5QFYCVYM.js → account-KBXJ5KR7.js} +4 -3
- package/dist/{accounts-756BMMAL.js → accounts-XUJNDCFH.js} +6 -5
- package/dist/{budget-PGSNCVVK.js → budget-PHV4NRUS.js} +5 -4
- package/dist/{budget-PGSNCVVK.js.map → budget-PHV4NRUS.js.map} +1 -1
- package/dist/{chat-D3T4YG5D.js → chat-HGTX76DU.js} +9 -8
- package/dist/{chat-D3T4YG5D.js.map → chat-HGTX76DU.js.map} +1 -1
- package/dist/chunk-732GIHRQ.js +23 -0
- package/dist/chunk-732GIHRQ.js.map +1 -0
- package/dist/{chunk-6WUVR3R2.js → chunk-AFCQURO5.js} +3 -3
- package/dist/{chunk-6SHOBL2X.js → chunk-DFQW3MRD.js} +2 -2
- package/dist/{chunk-JSRPO2AR.js → chunk-EBV5A33R.js} +4 -4
- package/dist/{chunk-IOATP7KH.js → chunk-FPSLYBLU.js} +5 -21
- package/dist/chunk-FPSLYBLU.js.map +1 -0
- package/dist/{chunk-K5AA65RS.js → chunk-FZJNOG2T.js} +2 -2
- package/dist/{chunk-HENE4DA6.js → chunk-ING5HCIO.js} +71 -3
- package/dist/chunk-ING5HCIO.js.map +1 -0
- package/dist/{chunk-JFWMLYV7.js → chunk-YSD6W27K.js} +130 -89
- package/dist/chunk-YSD6W27K.js.map +1 -0
- package/dist/{chunk-ZNUNYYN6.js → chunk-ZVNX7CSO.js} +3 -3
- package/dist/{config-TKGGYEN7.js → config-DG2E4VDW.js} +4 -3
- package/dist/{config-TKGGYEN7.js.map → config-DG2E4VDW.js.map} +1 -1
- package/dist/dashboard/assets/{Accounts-DciFUg4y.js → Accounts-DXiGsutB.js} +1 -1
- package/dist/dashboard/assets/{Callout-WgXHDPg0.js → Callout-1E8Wsl9W.js} +1 -1
- package/dist/dashboard/assets/{Goals-C6HL1PNE.js → Goals-kL4VAxw3.js} +1 -1
- package/dist/dashboard/assets/{Library-DwpBYTbK.js → Library-DZxBVUo_.js} +1 -1
- package/dist/dashboard/assets/{Panes-DxFSwhb7.js → Panes-C-TJekjs.js} +1 -1
- package/dist/dashboard/assets/{RoutesPage-Cyo0MNd7.js → RoutesPage-DWYm9tW8.js} +1 -1
- package/dist/dashboard/assets/{Runner-CIL7RxpN.js → Runner-CmHBjECR.js} +1 -1
- package/dist/dashboard/assets/{Settings-B_PEB585.js → Settings-BANphxva.js} +1 -1
- package/dist/dashboard/assets/{Tasks-DEfPSaE6.js → Tasks-cSx1PKyQ.js} +1 -1
- package/dist/dashboard/assets/{Traffic-Dcz-WhsP.js → Traffic-DEAuM6jq.js} +1 -1
- package/dist/dashboard/assets/{Workspace-9UCw9q7C.js → Workspace-BQFjc1jH.js} +1 -1
- package/dist/dashboard/assets/index-B8kld9xo.js +104 -0
- package/dist/dashboard/index.html +1 -1
- package/dist/{dist-F3NRJ5FK.js → dist-IPMBGFJD.js} +4 -2
- package/dist/{doctor-V4XXVVGK.js → doctor-5APOWJ5D.js} +4 -3
- package/dist/{doctor-V4XXVVGK.js.map → doctor-5APOWJ5D.js.map} +1 -1
- package/dist/{goal-RUHYPVPA.js → goal-ETZWLVKO.js} +4 -3
- package/dist/{goal-RUHYPVPA.js.map → goal-ETZWLVKO.js.map} +1 -1
- package/dist/index.js +31 -31
- package/dist/{init-54FKQZ2Z.js → init-YDLNA3GD.js} +4 -3
- package/dist/{init-54FKQZ2Z.js.map → init-YDLNA3GD.js.map} +1 -1
- package/dist/{run-4R25J2VN.js → run-I6N7TLHV.js} +4 -3
- package/dist/{run-4R25J2VN.js.map → run-I6N7TLHV.js.map} +1 -1
- package/dist/runtime.js +3 -2
- package/dist/{start-GRHW3TGE.js → start-ECLELJGJ.js} +4 -3
- package/dist/{start-GRHW3TGE.js.map → start-ECLELJGJ.js.map} +1 -1
- package/dist/{status-QR2HNPBK.js → status-QQPP67I4.js} +5 -4
- package/dist/{tasks-BHWDV4JS.js → tasks-RNMC2XFN.js} +5 -4
- package/dist/{tasks-BHWDV4JS.js.map → tasks-RNMC2XFN.js.map} +1 -1
- package/package.json +4 -4
- package/dist/chunk-HENE4DA6.js.map +0 -1
- package/dist/chunk-IOATP7KH.js.map +0 -1
- package/dist/chunk-JFWMLYV7.js.map +0 -1
- package/dist/dashboard/assets/index-CpztPbom.js +0 -104
- /package/dist/{account-5QFYCVYM.js.map → account-KBXJ5KR7.js.map} +0 -0
- /package/dist/{accounts-756BMMAL.js.map → accounts-XUJNDCFH.js.map} +0 -0
- /package/dist/{chunk-6WUVR3R2.js.map → chunk-AFCQURO5.js.map} +0 -0
- /package/dist/{chunk-6SHOBL2X.js.map → chunk-DFQW3MRD.js.map} +0 -0
- /package/dist/{chunk-JSRPO2AR.js.map → chunk-EBV5A33R.js.map} +0 -0
- /package/dist/{chunk-K5AA65RS.js.map → chunk-FZJNOG2T.js.map} +0 -0
- /package/dist/{chunk-ZNUNYYN6.js.map → chunk-ZVNX7CSO.js.map} +0 -0
- /package/dist/{dist-F3NRJ5FK.js.map → dist-IPMBGFJD.js.map} +0 -0
- /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-
|
|
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
|
|
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
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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 =
|
|
107
|
-
id:
|
|
108
|
-
type:
|
|
109
|
-
function:
|
|
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 =
|
|
112
|
-
role:
|
|
113
|
-
content:
|
|
114
|
-
name:
|
|
115
|
-
tool_call_id:
|
|
116
|
-
tool_calls:
|
|
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 =
|
|
119
|
-
model:
|
|
120
|
-
messages:
|
|
121
|
-
stream:
|
|
122
|
-
temperature:
|
|
123
|
-
top_p:
|
|
124
|
-
max_tokens:
|
|
125
|
-
stop:
|
|
126
|
-
tools:
|
|
127
|
-
|
|
128
|
-
type:
|
|
129
|
-
function:
|
|
130
|
-
name:
|
|
131
|
-
description:
|
|
132
|
-
parameters:
|
|
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:
|
|
137
|
-
|
|
138
|
-
|
|
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:
|
|
171
|
+
user: z2.string().optional()
|
|
141
172
|
});
|
|
142
|
-
var positiveInt =
|
|
143
|
-
var quotaLimits =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
160
|
-
plan:
|
|
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:
|
|
164
|
-
amount:
|
|
165
|
-
currency:
|
|
166
|
-
period:
|
|
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:
|
|
199
|
+
notes: z2.string().trim().max(1e3).optional()
|
|
169
200
|
}).strict();
|
|
170
201
|
var accountFields = {
|
|
171
|
-
label:
|
|
172
|
-
enabled:
|
|
173
|
-
priority:
|
|
174
|
-
weight:
|
|
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:
|
|
209
|
+
secret: z2.string().min(1).max(1e5).optional()
|
|
179
210
|
};
|
|
180
|
-
var accountCreateSchema =
|
|
181
|
-
var accountPatchSchema =
|
|
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 =
|
|
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:
|
|
208
|
-
description:
|
|
209
|
-
acceptance:
|
|
210
|
-
notes:
|
|
211
|
-
dependsOn:
|
|
212
|
-
priority:
|
|
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 =
|
|
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 =
|
|
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:
|
|
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 =
|
|
234
|
-
var goalStartSchema =
|
|
235
|
-
objective:
|
|
236
|
-
maxRounds:
|
|
237
|
-
maxTasks:
|
|
238
|
-
maxTokens:
|
|
239
|
-
dryRun:
|
|
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 =
|
|
242
|
-
minutes:
|
|
243
|
-
bucketSec:
|
|
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) =>
|
|
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",
|
|
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",
|
|
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",
|
|
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",
|
|
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 =
|
|
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:
|
|
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 (
|
|
1643
|
-
launched: await launchLoginTerminal(
|
|
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-
|
|
1747
|
+
//# sourceMappingURL=chunk-YSD6W27K.js.map
|