Skip to content

threads

Conversation-thread listing exposed as a Mastra custom API route.

Backed entirely by native Mastra: looks up the active agent by id, asks its Memory instance to listThreads filtered to the caller’s resource, and shapes each into the JSON-safe MastraThread wire type. A sibling DELETE removes a single named thread.

A sibling DELETE removes a single named thread; a PATCH renames one (renameThread).

Like historyRoute this registers through Mastra’s registerApiRoute so it shares the MastraServer auth-middleware pipeline (in ./server.ts), which has already stamped the resource id (MASTRA_RESOURCE_ID_KEY) and the targeted thread id (MASTRA_THREAD_ID_KEY, resolved from the thread-selection header / cookie) on RequestContext by the time a handler runs. Resource scoping lives here so a caller can only ever see, rename, or delete its own threads; no cookie or user lookups happen in this module.