Skip to content

Commit eb9129d

Browse files
chore: migrate fmt to biome (#936)
* configure * migrate ci * apply format * weird cf stuff * format then lint
1 parent 7f573f1 commit eb9129d

380 files changed

Lines changed: 10790 additions & 11075 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test.yml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,26 @@ jobs:
1616
- name: Checkout repository
1717
uses: actions/checkout@v4
1818

19+
- name: Setup Bun
20+
uses: oven-sh/setup-bun@v2
21+
22+
# Remove when lint is migrated to Biome
1923
- name: Set up Deno
2024
uses: denoland/setup-deno@v2
2125
with:
2226
deno-version: v2.x
2327

2428
- name: Install dependencies
25-
run: deno install
26-
27-
- name: Run lint
28-
run: deno run lint
29+
run: bun install
2930

3031
- name: Run format
31-
run: deno run fmt --check
32+
run: bun run fmt:check
3233

33-
- name: Print TSC version
34-
run: deno run version
34+
- name: Run lint
35+
run: bun run lint
3536

3637
- name: Run check
37-
env:
38-
DENO_V8_FLAGS: --max-old-space-size=16384
39-
run: deno run check
38+
run: bun run check
4039

4140
- name: Run test
42-
run: deno run test
41+
run: bun run test

apps/api/main.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const instrumentedApp = getRuntimeKey() === "deno" ? app : instrument(app);
1717
const SELF_DOMAINS: string[] = [
1818
Hosts.API,
1919
// @ts-expect-error env is not typed
20-
...env.VITE_USE_LOCAL_BACKEND ? [] : [Hosts.APPS],
20+
...(env.VITE_USE_LOCAL_BACKEND ? [] : [Hosts.APPS]),
2121
// @ts-expect-error env is not typed
2222
`localhost:${env.PORT || 8000}`,
2323
];
@@ -71,11 +71,7 @@ globalThis.fetch = async function patchedFetch(
7171
// Default export that wraps app with per-request context initializer
7272
export default {
7373
email,
74-
fetch(
75-
request: Request,
76-
env: any,
77-
ctx: ExecutionContext,
78-
): Promise<Response> {
74+
fetch(request: Request, env: any, ctx: ExecutionContext): Promise<Response> {
7975
return contextStorage.run({ env, ctx }, async () => {
8076
return await instrumentedApp.fetch!(
8177
request as Request<unknown, IncomingRequestCfProperties<unknown>>,

apps/api/src/api.ts

Lines changed: 46 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,14 @@ export const honoCtxToAppCtx = (c: Context<AppEnv>): AppContext => {
5353
token: c.req.header("Authorization")?.replace("Bearer ", ""),
5454
kbFileProcessor: c.env.KB_FILE_PROCESSOR,
5555
workspaceDO: c.env.WORKSPACE_DB,
56-
workspace: slug && root
57-
? {
58-
root,
59-
slug,
60-
value: workspace,
61-
}
62-
: undefined,
56+
workspace:
57+
slug && root
58+
? {
59+
root,
60+
slug,
61+
value: workspace,
62+
}
63+
: undefined,
6364
};
6465
};
6566

@@ -101,12 +102,14 @@ const createMCPHandlerFor = (
101102
{
102103
annotations: tool.annotations,
103104
description: tool.description,
104-
inputSchema: "shape" in tool.inputSchema
105-
? (tool.inputSchema.shape as z.ZodRawShape)
106-
: z.object({}).shape,
105+
inputSchema:
106+
"shape" in tool.inputSchema
107+
? (tool.inputSchema.shape as z.ZodRawShape)
108+
: z.object({}).shape,
107109
outputSchema:
108-
tool.outputSchema && typeof tool.outputSchema === "object" &&
109-
"shape" in tool.outputSchema
110+
tool.outputSchema &&
111+
typeof tool.outputSchema === "object" &&
112+
"shape" in tool.outputSchema
110113
? (tool.outputSchema.shape as z.ZodRawShape)
111114
: z.object({}).shape,
112115
},
@@ -182,28 +185,30 @@ const createToolCallHandlerFor = <
182185
app.use(logger());
183186

184187
// Enable CORS for all routes on api.deco.chat and localhost
185-
app.use(cors({
186-
origin: (origin) => origin,
187-
maxAge: 86400, // one day
188-
allowMethods: ["HEAD", "GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"],
189-
allowHeaders: [
190-
"Content-Type",
191-
"Authorization",
192-
"Cookie",
193-
"Accept",
194-
"cache-control",
195-
"pragma",
196-
"x-trace-debug-id",
197-
"x-deno-isolate-instance-id",
198-
],
199-
exposeHeaders: [
200-
"Content-Type",
201-
"Authorization",
202-
"Set-Cookie",
203-
"x-trace-debug-id",
204-
],
205-
credentials: true,
206-
}));
188+
app.use(
189+
cors({
190+
origin: (origin) => origin,
191+
maxAge: 86400, // one day
192+
allowMethods: ["HEAD", "GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"],
193+
allowHeaders: [
194+
"Content-Type",
195+
"Authorization",
196+
"Cookie",
197+
"Accept",
198+
"cache-control",
199+
"pragma",
200+
"x-trace-debug-id",
201+
"x-deno-isolate-instance-id",
202+
],
203+
exposeHeaders: [
204+
"Content-Type",
205+
"Authorization",
206+
"Set-Cookie",
207+
"x-trace-debug-id",
208+
],
209+
credentials: true,
210+
}),
211+
);
207212

208213
app.use(withContextMiddleware);
209214
app.use(setUserMiddleware);
@@ -221,24 +226,12 @@ app.use(async (c, next) => {
221226
app.use(withActorsMiddleware);
222227

223228
// MCP endpoint handlers
224-
app.all(
225-
"/mcp",
226-
createMCPHandlerFor(GLOBAL_TOOLS),
227-
);
228-
app.all(
229-
"/:root/:slug/mcp",
230-
createMCPHandlerFor(WORKSPACE_TOOLS),
231-
);
232-
app.all(
233-
"/:root/:slug/agents/:agentId/mcp",
234-
createMCPHandlerFor(AGENT_TOOLS),
235-
);
229+
app.all("/mcp", createMCPHandlerFor(GLOBAL_TOOLS));
230+
app.all("/:root/:slug/mcp", createMCPHandlerFor(WORKSPACE_TOOLS));
231+
app.all("/:root/:slug/agents/:agentId/mcp", createMCPHandlerFor(AGENT_TOOLS));
236232

237233
// Tool call endpoint handlers
238-
app.post(
239-
"/tools/call/:tool",
240-
createToolCallHandlerFor(GLOBAL_TOOLS),
241-
);
234+
app.post("/tools/call/:tool", createToolCallHandlerFor(GLOBAL_TOOLS));
242235
app.post(
243236
"/:root/:slug/tools/call/:tool",
244237
createToolCallHandlerFor(WORKSPACE_TOOLS),
@@ -302,8 +295,8 @@ app.get("/files/:root/:slug/:path{.+}", async (c) => {
302295
}
303296

304297
return c.body(response.body, 200, {
305-
"Content-Type": response.headers.get("content-type") ||
306-
"application/octet-stream",
298+
"Content-Type":
299+
response.headers.get("content-type") || "application/octet-stream",
307300
});
308301
});
309302

@@ -313,7 +306,7 @@ const getPublicKey = async (): Promise<JsonWebKey> => {
313306
};
314307
app.get("/.well-known/jwks.json", async () => {
315308
return Response.json({
316-
keys: [{ ...await getPublicKey(), kid: DECO_CHAT_KEY_ID }],
309+
keys: [{ ...(await getPublicKey()), kid: DECO_CHAT_KEY_ID }],
317310
});
318311
});
319312
// External webhooks

apps/api/src/app.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,28 @@ export const appsDomainOf = (req: Request, url?: URL) => {
1111
url ??= new URL(req.url);
1212
const referer = req.headers.get("referer");
1313

14-
return url.searchParams.get(APPS_DOMAIN_QS) ||
15-
(referer && new URL(referer).searchParams.get(APPS_DOMAIN_QS));
14+
return (
15+
url.searchParams.get(APPS_DOMAIN_QS) ||
16+
(referer && new URL(referer).searchParams.get(APPS_DOMAIN_QS))
17+
);
1618
};
1719

1820
const normalizeHost = (req: Request) => {
19-
const host = req.headers.get("host") ?? new URL(req.url).hostname ??
20-
"localhost";
21+
const host =
22+
req.headers.get("host") ?? new URL(req.url).hostname ?? "localhost";
2123

2224
const appsHost = appsDomainOf(req);
2325
if (appsHost) {
2426
return Hosts.APPS;
2527
}
26-
return {
27-
[Hosts.API]: Hosts.API,
28-
localhost: Hosts.API,
29-
"localhost:3001": Hosts.API,
30-
"localhost:8000": Hosts.API,
31-
}[host] ?? Hosts.APPS;
28+
return (
29+
{
30+
[Hosts.API]: Hosts.API,
31+
localhost: Hosts.API,
32+
"localhost:3001": Hosts.API,
33+
"localhost:8000": Hosts.API,
34+
}[host] ?? Hosts.APPS
35+
);
3236
};
3337

3438
export const app = new Hono<AppEnv>({

apps/api/src/apps.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,15 @@ export const fetchScript = async (
2727
}
2828
const scriptFetcher = dispatcher.get<{
2929
DECO_CHAT_APP_ORIGIN: string;
30-
}>(script, {}, {
31-
outbound: {
32-
DECO_CHAT_APP_ORIGIN: script,
30+
}>(
31+
script,
32+
{},
33+
{
34+
outbound: {
35+
DECO_CHAT_APP_ORIGIN: script,
36+
},
3337
},
34-
});
38+
);
3539
const response = await scriptFetcher.fetch(req).catch((err) => {
3640
if ("message" in err && err.message.startsWith("Worker not found")) {
3741
// we tried to get a worker that doesn't exist in our dispatch namespace
@@ -46,26 +50,25 @@ export const fetchScript = async (
4650
app.use(withContextMiddleware);
4751
app.all("/*", async (c: Context<AppEnv>) => {
4852
const url = new URL(c.req.url);
49-
let host = appsDomainOf(c.req.raw) ?? c.req.header("host") ??
50-
url.host;
53+
let host = appsDomainOf(c.req.raw) ?? c.req.header("host") ?? url.host;
5154
if (!host) {
5255
return new Response("No host", { status: 400 });
5356
}
5457
const locator = Entrypoint.script(host);
5558
// if it has a deployment ID, we can use the script ID directly
5659
let script = locator?.isCanonical ? locator.slug : null;
5760
const getScriptFn = async (): Promise<string | null> => {
58-
const { data, error } = await c.var.db.from("deco_chat_hosting_routes")
61+
const { data, error } = await c.var.db
62+
.from("deco_chat_hosting_routes")
5963
.select(`
6064
*,
6165
deco_chat_hosting_apps_deployments!deployment_id(
6266
id,
6367
deco_chat_hosting_apps!hosting_app_id(slug)
6468
)
65-
`).eq(
66-
"route_pattern",
67-
host,
68-
).maybeSingle();
69+
`)
70+
.eq("route_pattern", host)
71+
.maybeSingle();
6972

7073
if ((error || !data) && locator) {
7174
return locator.slug;
@@ -83,10 +86,9 @@ app.all("/*", async (c: Context<AppEnv>) => {
8386
};
8487
const isNoCache = c.req.header("x-domain-swr-ignore-cache") === "true";
8588
if (!script) {
86-
script = isNoCache ? await getScriptFn() : await domainSWRCache.cache(
87-
getScriptFn,
88-
host,
89-
).catch(() => null);
89+
script = isNoCache
90+
? await getScriptFn()
91+
: await domainSWRCache.cache(getScriptFn, host).catch(() => null);
9092
}
9193

9294
if (!script) {

apps/api/src/auth/index.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ export const getUser = async (
7171
supabase,
7272
DECO_CHAT_API_JWT_PRIVATE_KEY && DECO_CHAT_API_JWT_PUBLIC_KEY
7373
? {
74-
public: DECO_CHAT_API_JWT_PUBLIC_KEY,
75-
private: DECO_CHAT_API_JWT_PRIVATE_KEY,
76-
}
74+
public: DECO_CHAT_API_JWT_PUBLIC_KEY,
75+
private: DECO_CHAT_API_JWT_PRIVATE_KEY,
76+
}
7777
: undefined,
7878
);
7979

@@ -123,7 +123,8 @@ appLogin.all("/oauth", async (ctx: AppContext) => {
123123

124124
// user already logged in, set by userMiddleware
125125
if (user && !user.is_anonymous) {
126-
const origin = ctx.req.header("referer") ||
126+
const origin =
127+
ctx.req.header("referer") ||
127128
ctx.req.header("origin") ||
128129
"https://deco.chat";
129130
return ctx.redirect(origin);
@@ -177,8 +178,8 @@ appLogin.all("/magiclink", async (ctx: AppContext) => {
177178
const redirectTo = cli
178179
? AUTH_URL_CLI
179180
: url.host.includes("localhost")
180-
? "http://localhost:3001/"
181-
: "https://api.deco.chat/";
181+
? "http://localhost:3001/"
182+
: "https://api.deco.chat/";
182183

183184
await db.auth.signInWithOtp({
184185
email,
@@ -229,7 +230,8 @@ appAuth.all("/callback/magiclink", async (ctx: AppContext) => {
229230
const request = ctx.req.raw;
230231
const { db, headers } = createDbAndHeadersForRequest(ctx);
231232
const url = new URL(request.url);
232-
const next = url.searchParams.get("next") ||
233+
const next =
234+
url.searchParams.get("next") ||
233235
(url.host.includes("localhost")
234236
? "http://localhost:3000"
235237
: "https://deco.chat");

apps/api/src/durable-objects/workspace-database.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ export class WorkspaceDatabase extends DurableObject implements IWorkspaceDB {
1515

1616
exec({ sql, params }: DatatabasesRunSqlInput) {
1717
return {
18-
result: [{
19-
results: this.sql.exec(sql, ...(params ?? [])).toArray(),
20-
success: true,
21-
}],
18+
result: [
19+
{
20+
results: this.sql.exec(sql, ...(params ?? [])).toArray(),
21+
success: true,
22+
},
23+
],
2224
[Symbol.dispose]: () => {},
2325
};
2426
}

0 commit comments

Comments
 (0)