Skip to content

feat(ai): add shared Scope identity type (precursor for persistence + memory)#980

Merged
AlemTuzlak merged 1 commit into
mainfrom
feat/core-scope
Jul 22, 2026
Merged

feat(ai): add shared Scope identity type (precursor for persistence + memory)#980
AlemTuzlak merged 1 commit into
mainfrom
feat/core-scope

Conversation

@tombeckenham

@tombeckenham tombeckenham commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

🎯 Changes

Adds a single shared Scope identity type to @tanstack/ai — the one identity/isolation vocabulary for the subsystems that persist or recall per-conversation data: @tanstack/ai-persistence (#785) and @tanstack/ai-memory (#541).

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
}

Why this is its own PR, merged first. The two in-flight subsystems currently diverge on identity:

  • memory invented MemoryScope = { sessionId, userId? }sessionId is a second name for the conversation key.
  • persistence keys on a bare threadId: string and a separate flat scope: string (metadata store), with no userId/tenantId at all.

threadId is already the single conversation key across the codebase (ChatMiddlewareContext.threadId, with conversationId deprecated in favor of it). Public identity surface is irreversible after release, so pinning it once — here, ahead of both PRs — lets #785 and #541 rebase onto one settled contract instead of racing to set the vocabulary. Persistence drops its flat scope: string/bare threadId; memory renames sessionId → threadId and inherits userId/tenantId/namespace.

Security. Every field is an isolation boundary and must be derived server-side from trusted session state, never from client input — a bare client threadId is not an authorization boundary. This is documented on the type.

Scope of this PR. Additive and inert: Scope is exported from the package root but nothing consumes it yet. No behavior change, no other subsystem touched.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally (narrow gate: test:types, test:oxlint, build, test:knip for @tanstack/ai).

🚀 Release Impact

  • This change affects published code, and I have generated a changeset (@tanstack/ai minor).
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • New Features

    • Added a shared Scope type for consistently identifying and isolating conversation data.
    • Supports conversation, user, tenant, and namespace identifiers, with conversation ID required.
    • Exported the type for use across TanStack AI integrations.
  • Documentation

    • Documented server-side derivation requirements and compatibility guidance for unsupported namespace handling.

Introduce a single identity/isolation vocabulary (Scope) in @tanstack/ai
for the subsystems that persist or recall per-conversation data —
ai-persistence and ai-memory. threadId is the one conversation key (matching
ChatMiddlewareContext.threadId); userId/tenantId/namespace are optional. Every
field is an isolation boundary derived server-side, never from client input.

Additive precursor: nothing consumes Scope yet. Landed ahead of the persistence
(#785) and memory (#541) PRs so both build on one settled identity contract
instead of diverging (sessionId vs threadId, bare threadId vs flat scope:string).
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a shared Scope interface for conversation identity and isolation, exports it from @tanstack/ai, and documents the additive minor release. The type includes required threadId plus optional user, tenant, and namespace fields.

Changes

Shared Scope contract

Layer / File(s) Summary
Define and export Scope
packages/ai/src/scope.ts, packages/ai/src/index.ts, .changeset/shared-scope.md
Defines the documented Scope interface, re-exports it from the package root, and adds a minor release note describing its field contract and current unconsumed status.

Estimated code review effort: 1 (Trivial) | ~5 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely matches the main change: adding a shared Scope identity type for persistence and memory.
Description check ✅ Passed The description follows the required template and includes the changes, checklist, and release impact sections with concrete details.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/core-scope

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

3 package(s) bumped directly, 44 bumped as dependents.

🟥 Major bumps

Package Version Reason
@tanstack/ai-durable-stream 0.0.0 → 1.0.0 Changeset
@tanstack/ai-acp 0.2.3 → 1.0.0 Dependent
@tanstack/ai-angular 0.3.1 → 1.0.0 Dependent
@tanstack/ai-anthropic 0.16.3 → 1.0.0 Dependent
@tanstack/ai-bedrock 0.1.4 → 1.0.0 Dependent
@tanstack/ai-claude-code 0.2.3 → 1.0.0 Dependent
@tanstack/ai-code-mode 0.3.8 → 1.0.0 Dependent
@tanstack/ai-code-mode-skills 0.3.11 → 1.0.0 Dependent
@tanstack/ai-codex 0.2.3 → 1.0.0 Dependent
@tanstack/ai-elevenlabs 0.2.34 → 1.0.0 Dependent
@tanstack/ai-fal 0.9.12 → 1.0.0 Dependent
@tanstack/ai-gemini 0.20.1 → 1.0.0 Dependent
@tanstack/ai-grok 0.14.9 → 1.0.0 Dependent
@tanstack/ai-grok-build 0.2.3 → 1.0.0 Dependent
@tanstack/ai-groq 0.5.3 → 1.0.0 Dependent
@tanstack/ai-isolate-node 0.1.47 → 1.0.0 Dependent
@tanstack/ai-isolate-quickjs 0.1.47 → 1.0.0 Dependent
@tanstack/ai-mistral 0.2.3 → 1.0.0 Dependent
@tanstack/ai-ollama 0.8.16 → 1.0.0 Dependent
@tanstack/ai-openai 0.17.1 → 1.0.0 Dependent
@tanstack/ai-opencode 0.2.3 → 1.0.0 Dependent
@tanstack/ai-openrouter 0.15.10 → 1.0.0 Dependent
@tanstack/ai-preact 0.11.1 → 1.0.0 Dependent
@tanstack/ai-react 0.18.1 → 1.0.0 Dependent
@tanstack/ai-react-ui 0.8.15 → 1.0.0 Dependent
@tanstack/ai-sandbox 0.2.4 → 1.0.0 Dependent
@tanstack/ai-sandbox-cloudflare 0.2.4 → 1.0.0 Dependent
@tanstack/ai-sandbox-daytona 0.2.0 → 1.0.0 Dependent
@tanstack/ai-sandbox-docker 0.2.0 → 1.0.0 Dependent
@tanstack/ai-sandbox-local-process 0.2.0 → 1.0.0 Dependent
@tanstack/ai-sandbox-sprites 0.2.1 → 1.0.0 Dependent
@tanstack/ai-sandbox-vercel 0.2.0 → 1.0.0 Dependent
@tanstack/ai-solid 0.15.1 → 1.0.0 Dependent
@tanstack/ai-solid-ui 0.7.14 → 1.0.0 Dependent
@tanstack/ai-svelte 0.15.1 → 1.0.0 Dependent
@tanstack/ai-vue 0.15.1 → 1.0.0 Dependent
@tanstack/openai-base 0.9.9 → 1.0.0 Dependent

🟨 Minor bumps

Package Version Reason
@tanstack/ai 0.42.0 → 0.43.0 Changeset
@tanstack/ai-client 0.22.1 → 0.23.0 Changeset

🟩 Patch bumps

Package Version Reason
@tanstack/ai-devtools-core 0.4.24 → 0.4.25 Dependent
@tanstack/ai-isolate-cloudflare 0.2.38 → 0.2.39 Dependent
@tanstack/ai-mcp 0.2.5 → 0.2.6 Dependent
@tanstack/ai-vue-ui 0.2.34 → 0.2.35 Dependent
@tanstack/preact-ai-devtools 0.1.67 → 0.1.68 Dependent
@tanstack/react-ai-devtools 0.2.67 → 0.2.68 Dependent
@tanstack/solid-ai-devtools 0.2.67 → 0.2.68 Dependent
ag-ui 0.0.2 → 0.0.3 Dependent

@nx-cloud

nx-cloud Bot commented Jul 22, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 35070e7

Command Status Duration Result
nx run-many --targets=build --exclude=examples/... ✅ Succeeded 1m 44s View ↗

☁️ Nx Cloud last updated this comment at 2026-07-22 06:40:15 UTC

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/ai/src/scope.ts`:
- Around line 41-46: The Scope namespace contract currently permits adapters to
silently ignore a potentially isolating boundary. Update the namespace
documentation and related Scope handling so unsupported non-empty namespace
values are rejected by adapters, or explicitly define namespace as having no
isolation semantics until implementation support exists; preserve behavior for
omitted or empty namespaces.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: dd514cf4-abde-4639-ad02-98d04fba793b

📥 Commits

Reviewing files that changed from the base of the PR and between bcb1b93 and 35070e7.

📒 Files selected for processing (3)
  • .changeset/shared-scope.md
  • packages/ai/src/index.ts
  • packages/ai/src/scope.ts

Comment thread packages/ai/src/scope.ts
Comment on lines +41 to +46
/**
* 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

Copy link
Copy Markdown
Contributor

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 namespace separates 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 that namespace has no isolation semantics until supported.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/ai/src/scope.ts` around lines 41 - 46, The Scope namespace contract
currently permits adapters to silently ignore a potentially isolating boundary.
Update the namespace documentation and related Scope handling so unsupported
non-empty namespace values are rejected by adapters, or explicitly define
namespace as having no isolation semantics until implementation support exists;
preserve behavior for omitted or empty namespaces.

@pkg-pr-new

pkg-pr-new Bot commented Jul 22, 2026

Copy link
Copy Markdown

Open in StackBlitz

@tanstack/ai

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai@980

@tanstack/ai-acp

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-acp@980

@tanstack/ai-angular

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-angular@980

@tanstack/ai-anthropic

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-anthropic@980

@tanstack/ai-bedrock

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-bedrock@980

@tanstack/ai-claude-code

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-claude-code@980

@tanstack/ai-client

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-client@980

@tanstack/ai-code-mode

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-code-mode@980

@tanstack/ai-code-mode-skills

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-code-mode-skills@980

@tanstack/ai-codex

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-codex@980

@tanstack/ai-devtools-core

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-devtools-core@980

@tanstack/ai-durable-stream

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-durable-stream@980

@tanstack/ai-elevenlabs

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-elevenlabs@980

@tanstack/ai-event-client

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-event-client@980

@tanstack/ai-fal

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-fal@980

@tanstack/ai-gemini

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-gemini@980

@tanstack/ai-grok

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-grok@980

@tanstack/ai-grok-build

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-grok-build@980

@tanstack/ai-groq

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-groq@980

@tanstack/ai-isolate-cloudflare

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-cloudflare@980

@tanstack/ai-isolate-node

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-node@980

@tanstack/ai-isolate-quickjs

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-quickjs@980

@tanstack/ai-mcp

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-mcp@980

@tanstack/ai-mistral

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-mistral@980

@tanstack/ai-ollama

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-ollama@980

@tanstack/ai-openai

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-openai@980

@tanstack/ai-opencode

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-opencode@980

@tanstack/ai-openrouter

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-openrouter@980

@tanstack/ai-preact

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-preact@980

@tanstack/ai-react

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-react@980

@tanstack/ai-react-ui

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-react-ui@980

@tanstack/ai-sandbox

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox@980

@tanstack/ai-sandbox-cloudflare

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-cloudflare@980

@tanstack/ai-sandbox-daytona

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-daytona@980

@tanstack/ai-sandbox-docker

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-docker@980

@tanstack/ai-sandbox-local-process

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-local-process@980

@tanstack/ai-sandbox-sprites

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-sprites@980

@tanstack/ai-sandbox-vercel

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-vercel@980

@tanstack/ai-solid

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-solid@980

@tanstack/ai-solid-ui

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-solid-ui@980

@tanstack/ai-svelte

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-svelte@980

@tanstack/ai-utils

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-utils@980

@tanstack/ai-vue

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vue@980

@tanstack/ai-vue-ui

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vue-ui@980

@tanstack/openai-base

npm i https://pkg.pr.new/TanStack/ai/@tanstack/openai-base@980

@tanstack/preact-ai-devtools

npm i https://pkg.pr.new/TanStack/ai/@tanstack/preact-ai-devtools@980

@tanstack/react-ai-devtools

npm i https://pkg.pr.new/TanStack/ai/@tanstack/react-ai-devtools@980

@tanstack/solid-ai-devtools

npm i https://pkg.pr.new/TanStack/ai/@tanstack/solid-ai-devtools@980

commit: 35070e7

@tombeckenham
tombeckenham requested a review from a team July 22, 2026 06:46
@AlemTuzlak
AlemTuzlak merged commit 4ce7600 into main Jul 22, 2026
10 checks passed
@AlemTuzlak
AlemTuzlak deleted the feat/core-scope branch July 22, 2026 11:29
@github-actions github-actions Bot mentioned this pull request Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants