Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .changeset/fix-basepath-reconnect.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"agents": patch
---

Fix `useAgent` and `AgentClient` crashing when using `basePath` routing. `PartySocket.reconnect()` requires `room` to be set, but `basePath` mode bypasses room-based URL construction. The fix provides `room` and `party` in socket options even when `basePath` is used, as a workaround pending a fix in partysocket.
Fix `useAgent` and `AgentClient` crashing when using `basePath` routing.
5 changes: 5 additions & 0 deletions .changeset/remove-basepath-workaround.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"agents": patch
---

Remove `room`/`party` workaround for `basePath` routing now that partysocket handles reconnect without requiring `room` to be set.
14 changes: 2 additions & 12 deletions packages/agents/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,19 +164,9 @@ export class AgentClient<State = unknown> extends PartySocket {
constructor(options: AgentClientOptions<State>) {
const agentNamespace = camelCaseToKebabCase(options.agent);

// If basePath is provided, use it directly; otherwise construct from agent/name.
// WORKAROUND: When using basePath, we still set `room` and `party` because
// PartySocket.reconnect() requires `room` to be set, even though basePath bypasses
// the room-based URL construction. This should be removed once partysocket is fixed
// to skip the `room` check when `basePath` is provided.
// If basePath is provided, use it directly; otherwise construct from agent/name
const socketOptions = options.basePath
? {
basePath: options.basePath,
party: agentNamespace,
room: options.name || "default",
path: options.path,
...options
}
? { basePath: options.basePath, path: options.path, ...options }
: {
party: agentNamespace,
prefix: "agents",
Expand Down
8 changes: 1 addition & 7 deletions packages/agents/src/react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -434,16 +434,10 @@ export function useAgent<State>(
resetReady();
}

// If basePath is provided, use it directly; otherwise construct from agent/name.
// WORKAROUND: When using basePath, we still set `room` and `party` because
// PartySocket.reconnect() requires `room` to be set, even though basePath bypasses
// the room-based URL construction. This should be removed once partysocket is fixed
// to skip the `room` check when `basePath` is provided.
// If basePath is provided, use it directly; otherwise construct from agent/name
const socketOptions = options.basePath
? {
basePath: options.basePath,
party: agentNamespace,
room: options.name || "default",
path: options.path,
query: resolvedQuery,
...restOptions
Expand Down
Loading