Skip to content

Commit 7cfa87c

Browse files
committed
chore: format
1 parent 74ce231 commit 7cfa87c

8 files changed

Lines changed: 69 additions & 113 deletions

File tree

examples/agent-deploy/app/device/capabilities/page.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,12 @@ function DeviceCapabilitiesContent() {
240240
className="w-full py-2 text-[13px] font-medium rounded-md bg-foreground text-background hover:opacity-90 transition-all disabled:opacity-50 cursor-pointer active:scale-[0.98]"
241241
>
242242
{signingIn
243-
? isSignUp ? "Creating account..." : "Signing in..."
244-
: isSignUp ? "Create Account & Review" : "Sign In & Review"}
243+
? isSignUp
244+
? "Creating account..."
245+
: "Signing in..."
246+
: isSignUp
247+
? "Create Account & Review"
248+
: "Sign In & Review"}
245249
</button>
246250
</form>
247251

examples/agent-deploy/app/sites/[slug]/route.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import { getSiteBySlug } from "@/lib/db";
22
import { NextResponse } from "next/server";
33

4-
export async function GET(
5-
_request: Request,
6-
{ params }: { params: Promise<{ slug: string }> },
7-
) {
4+
export async function GET(_request: Request, { params }: { params: Promise<{ slug: string }> }) {
85
const { slug } = await params;
96
const site = await getSiteBySlug(slug);
107
if (!site) {

examples/gmail-proxy/app/device/capabilities/device-capabilities.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -459,11 +459,7 @@ export default function DeviceCapabilities({ agentId, code }: { agentId?: string
459459
</div>
460460
<div>
461461
<h1 className="text-[22px] font-normal text-foreground">
462-
{approved
463-
? result.claimed
464-
? "Agent Claimed"
465-
: "Access Approved"
466-
: "Access Denied"}
462+
{approved ? (result.claimed ? "Agent Claimed" : "Access Approved") : "Access Denied"}
467463
</h1>
468464
<p className="mt-2 text-sm text-muted">
469465
{approved

examples/gmail-proxy/lib/auth.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,8 +569,9 @@ export const auth = betterAuth({
569569
agentAuth({
570570
allowDynamicHostRegistration: true,
571571
freshSessionWindow: async ({ ctx }) => {
572-
const userId = (ctx as Record<string, any>).context?.session?.user
573-
?.id as string | undefined;
572+
const userId = (ctx as Record<string, any>).context?.session?.user?.id as
573+
| string
574+
| undefined;
574575
if (!userId) return 300;
575576
if ((await getSetting(userId, "freshSessionEnabled")) !== "true") return 0;
576577
return parseInt((await getSetting(userId, "freshSessionWindow")) ?? "300", 10);

examples/vercel-proxy/app/device/capabilities/device-capabilities.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -421,11 +421,7 @@ export default function DeviceCapabilities({ agentId, code }: { agentId?: string
421421
</div>
422422
<div>
423423
<h1 className="text-xl font-semibold text-white">
424-
{approved
425-
? result.claimed
426-
? "Agent Claimed"
427-
: "Access Approved"
428-
: "Access Denied"}
424+
{approved ? (result.claimed ? "Agent Claimed" : "Access Approved") : "Access Denied"}
429425
</h1>
430426
<p className="mt-2 text-sm text-muted">
431427
{approved
@@ -530,9 +526,7 @@ export default function DeviceCapabilities({ agentId, code }: { agentId?: string
530526
</div>
531527
<span
532528
className={`inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium ${
533-
isClaim
534-
? "bg-blue-500/10 text-blue-400"
535-
: "bg-amber-500/10 text-amber-400"
529+
isClaim ? "bg-blue-500/10 text-blue-400" : "bg-amber-500/10 text-amber-400"
536530
}`}
537531
>
538532
{isClaim ? "Autonomous" : "Pending"}

packages/agent-auth/src/routes/approve-capability.ts

Lines changed: 43 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ export function approveCapability(
6363
use: [sessionMiddleware],
6464
metadata: {
6565
openapi: {
66-
description:
67-
"Approve or deny a pending agent registration or capability request.",
66+
description: "Approve or deny a pending agent registration or capability request.",
6867
},
6968
},
7069
},
@@ -123,19 +122,16 @@ export function approveCapability(
123122
let deviceApprovalRequests: ApprovalRequest[] = [];
124123
if (approvalRequest) {
125124
deviceApprovalRequests =
126-
approvalRequest.method === "device_authorization"
127-
? [approvalRequest]
128-
: [];
125+
approvalRequest.method === "device_authorization" ? [approvalRequest] : [];
129126
} else {
130-
deviceApprovalRequests =
131-
await ctx.context.adapter.findMany<ApprovalRequest>({
132-
model: TABLE.approval,
133-
where: [
134-
{ field: "agentId", value: agentId },
135-
{ field: "status", value: "pending" },
136-
{ field: "method", value: "device_authorization" },
137-
],
138-
});
127+
deviceApprovalRequests = await ctx.context.adapter.findMany<ApprovalRequest>({
128+
model: TABLE.approval,
129+
where: [
130+
{ field: "agentId", value: agentId },
131+
{ field: "status", value: "pending" },
132+
{ field: "method", value: "device_authorization" },
133+
],
134+
});
139135
}
140136

141137
// Check expiry on any resolved approval request
@@ -147,41 +143,33 @@ export function approveCapability(
147143
}
148144

149145
// Verify user_code for device_authorization approvals (approve only — deny is safe)
150-
const hasDeviceApproval = deviceApprovalRequests.some(
151-
(r) => r.userCodeHash,
152-
);
146+
const hasDeviceApproval = deviceApprovalRequests.some((r) => r.userCodeHash);
153147
if (action === "approve" && hasDeviceApproval) {
154148
if (!userCode) {
155149
throw agentError("BAD_REQUEST", ERR.INVALID_USER_CODE);
156150
}
157151
const normalized = normalizeUserCode(userCode);
158152
const submittedHash = await hashToken(normalized);
159-
const matched = deviceApprovalRequests.some(
160-
(r) => r.userCodeHash === submittedHash,
161-
);
153+
const matched = deviceApprovalRequests.some((r) => r.userCodeHash === submittedHash);
162154
if (!matched) {
163155
throw agentError("FORBIDDEN", ERR.INVALID_USER_CODE);
164156
}
165157
}
166158

167-
const allGrants =
168-
await ctx.context.adapter.findMany<AgentCapabilityGrant>({
169-
model: TABLE.grant,
170-
where: [{ field: "agentId", value: agentId }],
171-
});
159+
const allGrants = await ctx.context.adapter.findMany<AgentCapabilityGrant>({
160+
model: TABLE.grant,
161+
where: [{ field: "agentId", value: agentId }],
162+
});
172163

173164
// ── Claim: autonomous agent ownership transfer ──
174165
if (isClaim) {
175166
const now = new Date();
176167

177168
if (action === "deny") {
178-
const resolved = await resolvePendingApprovalRequests(
179-
ctx.context.adapter,
180-
{
181-
agentId,
182-
status: "denied",
183-
},
184-
);
169+
const resolved = await resolvePendingApprovalRequests(ctx.context.adapter, {
170+
agentId,
171+
status: "denied",
172+
});
185173
void deliverApprovalNotifications(resolved, {
186174
agent_id: agentId,
187175
status: "denied",
@@ -245,9 +233,7 @@ export function approveCapability(
245233
);
246234
}
247235

248-
const activeCaps = allGrants
249-
.filter((g) => g.status === "active")
250-
.map((g) => g.capability);
236+
const activeCaps = allGrants.filter((g) => g.status === "active").map((g) => g.capability);
251237

252238
await opts.onAutonomousAgentClaimed?.({
253239
ctx,
@@ -258,13 +244,10 @@ export function approveCapability(
258244
capabilities: activeCaps,
259245
});
260246

261-
const resolved = await resolvePendingApprovalRequests(
262-
ctx.context.adapter,
263-
{
264-
agentId,
265-
status: "approved",
266-
},
267-
);
247+
const resolved = await resolvePendingApprovalRequests(ctx.context.adapter, {
248+
agentId,
249+
status: "approved",
250+
});
268251
void deliverApprovalNotifications(resolved, {
269252
agent_id: agentId,
270253
status: "approved",
@@ -286,10 +269,7 @@ export function approveCapability(
286269
status: "approved",
287270
agentId,
288271
claimed: true,
289-
agent_capability_grants: formatGrantsResponse(
290-
allGrants,
291-
opts.capabilities,
292-
),
272+
agent_capability_grants: formatGrantsResponse(allGrants, opts.capabilities),
293273
});
294274
}
295275

@@ -298,10 +278,7 @@ export function approveCapability(
298278
const agentIsPending = agent.status === "pending";
299279

300280
if (pendingGrants.length === 0 && !agentIsPending) {
301-
throw agentError(
302-
"PRECONDITION_FAILED",
303-
ERR.CAPABILITY_REQUEST_ALREADY_RESOLVED,
304-
);
281+
throw agentError("PRECONDITION_FAILED", ERR.CAPABILITY_REQUEST_ALREADY_RESOLVED);
305282
}
306283

307284
if (action === "deny") {
@@ -334,13 +311,10 @@ export function approveCapability(
334311
? `User denied the authorization request: ${denyReason}`
335312
: "User denied the authorization request.";
336313

337-
const resolved = await resolvePendingApprovalRequests(
338-
ctx.context.adapter,
339-
{
340-
agentId,
341-
status: "denied",
342-
},
343-
);
314+
const resolved = await resolvePendingApprovalRequests(ctx.context.adapter, {
315+
agentId,
316+
status: "denied",
317+
});
344318

345319
void deliverApprovalNotifications(resolved, {
346320
agent_id: agentId,
@@ -417,9 +391,7 @@ export function approveCapability(
417391
// Per-capability overrides can still escalate to webauthn
418392
if (!requiresWebAuthn) {
419393
const capDefs = opts.capabilities ?? [];
420-
const capDefMap = new Map<string, Capability>(
421-
capDefs.map((c) => [c.name, c]),
422-
);
394+
const capDefMap = new Map<string, Capability>(capDefs.map((c) => [c.name, c]));
423395
requiresWebAuthn = capabilities.some((capId) => {
424396
const def = capDefMap.get(capId);
425397
return def?.approvalStrength === "webauthn";
@@ -449,10 +421,7 @@ export function approveCapability(
449421
}
450422

451423
if (!webauthnResponse) {
452-
const { options } = await generateApprovalChallenge(
453-
opts.proofOfPresence,
454-
passkeys,
455-
);
424+
const { options } = await generateApprovalChallenge(opts.proofOfPresence, passkeys);
456425

457426
challengeCache.set(session.user.id, agentId, options.challenge);
458427

@@ -467,10 +436,7 @@ export function approveCapability(
467436
);
468437
}
469438

470-
const expectedChallenge = challengeCache.consume(
471-
session.user.id,
472-
agentId,
473-
);
439+
const expectedChallenge = challengeCache.consume(session.user.id, agentId);
474440

475441
if (!expectedChallenge) {
476442
throw agentError(
@@ -480,11 +446,8 @@ export function approveCapability(
480446
);
481447
}
482448

483-
const assertionResponse =
484-
webauthnResponse as unknown as AuthenticationResponseJSON;
485-
const matchingPasskey = passkeys.find(
486-
(pk) => pk.credentialID === assertionResponse.id,
487-
);
449+
const assertionResponse = webauthnResponse as unknown as AuthenticationResponseJSON;
450+
const matchingPasskey = passkeys.find((pk) => pk.credentialID === assertionResponse.id);
488451

489452
if (!matchingPasskey) {
490453
throw agentError(
@@ -529,10 +492,7 @@ export function approveCapability(
529492
}
530493

531494
if (opts.blockedCapabilities.length > 0) {
532-
const blocked = findBlockedCapabilities(
533-
[...approvedCapIds],
534-
opts.blockedCapabilities,
535-
);
495+
const blocked = findBlockedCapabilities([...approvedCapIds], opts.blockedCapabilities);
536496
if (blocked.length > 0) {
537497
throw agentError(
538498
"BAD_REQUEST",
@@ -542,10 +502,7 @@ export function approveCapability(
542502
}
543503
}
544504

545-
const activeGrantsByCapability = new Map<
546-
string,
547-
AgentCapabilityGrant[]
548-
>();
505+
const activeGrantsByCapability = new Map<string, AgentCapabilityGrant[]>();
549506
for (const g of allGrants) {
550507
if (g.status !== "active") continue;
551508
const list = activeGrantsByCapability.get(g.capability) ?? [];
@@ -556,8 +513,7 @@ export function approveCapability(
556513

557514
for (const grant of pendingGrants) {
558515
if (approvedCapIds.has(grant.capability)) {
559-
const existingActive =
560-
activeGrantsByCapability.get(grant.capability) ?? [];
516+
const existingActive = activeGrantsByCapability.get(grant.capability) ?? [];
561517
const alreadyCovered = existingActive.some((ag) =>
562518
constraintsCover(ag.constraints, grant.constraints),
563519
);
@@ -601,13 +557,10 @@ export function approveCapability(
601557
}
602558
}
603559

604-
const resolved = await resolvePendingApprovalRequests(
605-
ctx.context.adapter,
606-
{
607-
agentId,
608-
status: added.length > 0 || agentIsPending ? "approved" : "denied",
609-
},
610-
);
560+
const resolved = await resolvePendingApprovalRequests(ctx.context.adapter, {
561+
agentId,
562+
status: added.length > 0 || agentIsPending ? "approved" : "denied",
563+
});
611564

612565
void deliverApprovalNotifications(resolved, {
613566
agent_id: agentId,

packages/cli/src/mcp.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
22
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
33
import { z, type ZodRawShape } from "zod";
4-
import { getAgentAuthTools, filterTools, SERVER_INSTRUCTIONS, type ToolParameters } from "@auth/agent";
4+
import {
5+
getAgentAuthTools,
6+
filterTools,
7+
SERVER_INSTRUCTIONS,
8+
type ToolParameters,
9+
} from "@auth/agent";
510
import { createClient, type ClientConfig } from "./client.js";
611

712
interface PropertyDescriptor {

packages/sdk/src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ export { detectHostName, detectTool } from "./host-name";
66
export { matchQuery, matchQueryScored } from "./search";
77
export type { ScoredMatch } from "./search";
88
export { AgentAuthSDKError } from "./types";
9-
export { getAgentAuthTools, filterTools, toOpenAITools, toAISDKTools, toAnthropicTools } from "./tools";
9+
export {
10+
getAgentAuthTools,
11+
filterTools,
12+
toOpenAITools,
13+
toAISDKTools,
14+
toAnthropicTools,
15+
} from "./tools";
1016
export { SERVER_INSTRUCTIONS } from "./instructions";
1117

1218
export type {

0 commit comments

Comments
 (0)