-
-
Notifications
You must be signed in to change notification settings - Fork 278
feat(ai): add shared Scope identity type (precursor for persistence + memory) #980
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+79
β0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| --- | ||
| '@tanstack/ai': minor | ||
| --- | ||
|
|
||
| **Add a shared `Scope` identity type to `@tanstack/ai`.** | ||
|
|
||
| `Scope` is the single identity/isolation vocabulary for the subsystems that | ||
| persist or recall per-conversation data β `@tanstack/ai-persistence` and | ||
| `@tanstack/ai-memory`. Rather than each subsystem inventing its own notion of | ||
| "whose data is this?", both import one type: | ||
|
|
||
| ```ts | ||
| interface Scope { | ||
| threadId: string // required β the single conversation key (same as ctx.threadId) | ||
| userId?: string // durable end-user identity; required in practice for multi-user apps | ||
| tenantId?: string // multi-tenant boundary | ||
| namespace?: string // reserved logical partition; no subsystem keys on it yet | ||
| } | ||
| ``` | ||
|
|
||
| `threadId` is the one conversation key across the codebase (matching | ||
| `ChatMiddlewareContext.threadId`, with `conversationId` already deprecated in | ||
| favor of it) β subsystems must not introduce a second name (`sessionId`, β¦) for | ||
| the same concept. Every field is an isolation boundary and must be derived | ||
| server-side from trusted session state, never from client input. | ||
|
|
||
| This is additive: nothing consumes `Scope` yet. It lands ahead of the | ||
| persistence and memory PRs so both build on one settled, unambiguous identity | ||
| contract instead of diverging. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /** | ||
| * Shared identity/isolation scope for the TanStack AI subsystems that persist | ||
| * or recall per-conversation data β `@tanstack/ai-persistence` (keyed CRUD over | ||
| * threads, runs, interrupts) and `@tanstack/ai-memory` (ranked recall/save). | ||
| * | ||
| * Both subsystems answer the same underlying question β "whose data is this?" β | ||
| * so they share ONE identity vocabulary defined here rather than each inventing | ||
| * its own. `threadId` is the single conversation key across the codebase (it is | ||
| * `ChatMiddlewareContext.threadId`, and `conversationId` is deprecated in favor | ||
| * of it); a subsystem must never introduce a second name (`sessionId`, | ||
| * `conversationId`, β¦) for the same concept. | ||
| * | ||
| * ## Security | ||
| * | ||
| * A `Scope` is an isolation boundary. Derive every field server-side from | ||
| * trusted, validated session state β **never** from client input. `threadId` | ||
| * in particular resolves from a client-supplied value on the request, so a | ||
| * subsystem that reads/writes user-owned data (memory, per-user metadata) must | ||
| * pair it with a server-trusted `userId`/`tenantId` and must not treat a bare | ||
| * client `threadId` as sufficient isolation: thread ids are guessable, so on | ||
| * their own they let one caller read another's data. | ||
| */ | ||
| export interface Scope { | ||
| /** | ||
| * The conversation this data belongs to. Required β the minimal isolation | ||
| * key both subsystems already center on. Same concept as | ||
| * `ChatMiddlewareContext.threadId`. | ||
| */ | ||
| threadId: string | ||
| /** | ||
| * Durable end-user identity, for cross-thread recall and per-user isolation. | ||
| * Optional, but required in practice for any multi-user deployment β a | ||
| * `threadId` alone is not an authorization boundary (see Security above). | ||
| */ | ||
| userId?: string | ||
| /** | ||
| * Tenant/organization boundary for multi-tenant deployments. When present, | ||
| * every read and write must be confined to it. | ||
| */ | ||
| tenantId?: string | ||
| /** | ||
| * Logical partition within a tenant/user (e.g. separating distinct memory | ||
| * banks or persistence namespaces). Reserved β no subsystem keys on it yet; | ||
| * adapters that don't understand it must ignore it rather than error. | ||
| */ | ||
| namespace?: string | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π Security & Privacy | π Major | β‘ Quick win
Do not silently ignore an unsupported isolation boundary.
If
namespaceseparates memory or persistence partitions, an adapter that ignores it can return data from another namespace. Require adapters to reject unsupported non-empty namespaces, or explicitly state thatnamespacehas no isolation semantics until supported.π€ Prompt for AI Agents