Skip to content

Commit 821ec01

Browse files
committed
updates
1 parent 12fad4c commit 821ec01

File tree

5 files changed

+10
-28
lines changed

5 files changed

+10
-28
lines changed

public/_redirects

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
/agents/examples/schedule-tasks/ /agents/api-reference/schedule-tasks/ 301
106106
/agents/examples/using-ai-models/ /agents/api-reference/using-ai-models/ 301
107107
/agents/examples/websockets/ /agents/api-reference/websockets/ 301
108-
/agents/examples/sdk/ /agents/api-reference/creating-agents/ 301
108+
/agents/examples/sdk/ /agents/api-reference/agents-api/ 301
109109

110110
# ai
111111
/ai/ /use-cases/ai/ 301

src/content/docs/agents/api-reference/creating-agents.mdx renamed to src/content/docs/agents/api-reference/agents-api.mdx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Creating Agents
2+
title: Agents API
33
pcx_content_type: concept
44
sidebar:
55
order: 1
@@ -74,11 +74,9 @@ class MyAgent extends Agent<Env, State> {
7474
// Called when a WebSocket connection is established
7575
// Access the original request via ctx.request for auth etc.
7676
async onConnect(connection: Connection, ctx: ConnectionContext) {
77-
// Authenticate the connection
77+
// Connections are automatically accepted by the SDK.
78+
// You can also explicitly close a connection here with connection.close()
7879
// Access the Request on ctx.request to inspect headers, cookies and the URL
79-
80-
// Accept the connection
81-
connection.accept();
8280
}
8381

8482
// Called for each message received on a WebSocket connection

src/content/docs/agents/api-reference/calling-agents.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ interface Env {
124124
export default {
125125
async fetch(request, env, ctx): Promise<Response> {
126126
// Use the onBeforeConnect and onBeforeRequest hooks to authenticate clients
127-
// or run logic before handling a
127+
// or run logic before handling a HTTP request or WebSocket.
128128
return (
129129
(await routeAgentRequest(request, env, {
130130
// Run logic before a WebSocket client connects

src/content/docs/agents/api-reference/using-ai-models.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ import { OpenAI } from "openai"
3434

3535
export class MyAgent extends Agent<Env> {
3636
async onConnect(connection: Connection, ctx: ConnectionContext) {
37-
// Omitted for simplicity: authenticating the user
38-
connection.accept()
37+
//
3938
}
4039

4140
async onMessage(connection: Connection, message: WSMessage) {

src/content/docs/agents/api-reference/websockets.mdx

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,10 @@ Here's an example of an Agent that echoes back any message it receives:
2323
import { Agent, Connection } from "agents-sdk";
2424

2525
export class ChatAgent extends Agent {
26-
async onConnect(connection: Connection, ctx: ConnectionContext) {
27-
// Access the request to verify any authentication tokens
28-
// provided in headers or cookies
29-
let token = ctx.request.headers.get("Authorization");
30-
if (!token) {
31-
await connection.close(4000, "Unauthorized");
32-
return;
33-
}
34-
35-
// Handle auth using your favorite library and/or auth scheme:
36-
// try {
37-
// await jwt.verify(token, env.JWT_SECRET);
38-
// } catch (error) {
39-
// connection.close(4000, 'Invalid Authorization header');
40-
// return;
41-
// }
42-
43-
// Accept valid connections
44-
connection.accept()
26+
async onConnect(connection: Connection, ctx: ConnectionContext) {
27+
// Connections are automatically accepted by the SDK.
28+
// You can also explicitly close a connection here with connection.close()
29+
// Access the Request on ctx.request to inspect headers, cookies and the URL
4530
}
4631

4732
async onMessage(connection: Connection, message: WSMessage) {

0 commit comments

Comments
 (0)