跳到主要内容
非官方简体中文翻译,内容版权归 Mastra 所有,遵循 Apache-2.0 许可。

Memory.updateThreadResourceId()

The .updateThreadResourceId() method transfers ownership of an existing thread to a different resource by reassigning its resourceId. It updates the thread and all of its associated messages so that they belong to the new resource, while preserving the thread's original createdAt timestamp. This is useful for scenarios such as moving a private thread into a shared workspace.

Usage example
Usage example的直接链接

import { Memory } from '@mastra/memory'
import { LibSQLStore } from '@mastra/libsql'

const memory = new Memory({
storage: new LibSQLStore({ id: 'memory-store', url: 'file:./memory.db' }),
})

const thread = await memory.updateThreadResourceId({
threadId: 'thread-123',
resourceId: 'new-resource-456',
})

Parameters
Parameters的直接链接

threadId:

string
The ID of the thread to transfer.

resourceId:

string
The resource that should own the thread after the call.

Returns
Returns的直接链接

thread:

StorageThreadType
The updated thread with the new resourceId. If the thread already belongs to the target resource, it is returned unchanged.

Behavior
Behavior的直接链接

  • The thread's resourceId is reassigned to the new resource, and all of its messages are updated to reference the new resource.
  • The thread's original createdAt timestamp is preserved. The updatedAt timestamp is refreshed.
  • If the thread already belongs to the target resource, the method is a no-op and returns the existing thread.
  • If the thread doesn't exist, the method throws an error.

Security
Security的直接链接

Thread ownership transfer changes which resource a thread belongs to, bypassing the normal per-resource ownership checks. The HTTP endpoint (POST /memory/threads/:threadId/transfer) is only available to privileged, non-resource-scoped callers. Requests made with a resolved resource scope are rejected, and when server.auth is configured without an FGA provider the endpoint also rejects unscoped requests rather than treating them as implicitly privileged. Perform transfers from a trusted service context rather than exposing this operation directly to end users.

Like all memory mutations (deleting threads, listing messages, writing working memory), this endpoint is unauthenticated on a server configured with no authentication at all. Configure server.auth (and, for per-resource enforcement, an FGA provider) before exposing the memory API to untrusted callers.

On this page