Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fuzzy-states-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"agents": patch
---

Allow agents to customize OAuth client behavior
18 changes: 11 additions & 7 deletions packages/agents/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -831,9 +831,9 @@ export class Agent<Env, State = unknown> extends Server<Env> {
private async _scheduleNextAlarm() {
// Find the next schedule that needs to be executed
const result = this.sql`
SELECT time FROM cf_agents_schedules
SELECT time FROM cf_agents_schedules
WHERE time > ${Math.floor(Date.now() / 1000)}
ORDER BY time ASC
ORDER BY time ASC
LIMIT 1
`;
if (!result) return;
Expand Down Expand Up @@ -1004,11 +1004,7 @@ export class Agent<Env, State = unknown> extends Server<Env> {
authUrl: string | undefined;
clientId: string | undefined;
}> {
const authProvider = new DurableObjectOAuthClientProvider(
this.ctx.storage,
this.name,
callbackUrl
);
const authProvider = this.createOAuthProvider(callbackUrl);

if (reconnect) {
authProvider.serverId = reconnect.id;
Expand Down Expand Up @@ -1091,6 +1087,14 @@ export class Agent<Env, State = unknown> extends Server<Env> {

return mcpState;
}

createOAuthProvider(callbackUrl: string): AgentsOAuthProvider {
return new DurableObjectOAuthClientProvider(
this.ctx.storage,
this.name,
callbackUrl
);
}
}

/**
Expand Down