feat(ai): add shared Scope identity type (precursor for persistence + memory) #980
main fromrefs/pull/980/head·merged by AlemTuzlak View on GitHub🎯 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? }—sessionIdis a second name for the conversation key. - persistence keys on a bare
threadId: stringand a separate flatscope: string(metadata store), with nouserId/tenantIdat 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:knipfor@tanstack/ai).
🚀 Release Impact#
- This change affects published code, and I have generated a changeset (
@tanstack/aiminor). - This change is docs/CI/dev-only (no release).
Summary by CodeRabbit#
New Features
- Added a shared
Scopetype 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.
- Added a shared
Documentation
- Documented server-side derivation requirements and compatibility guidance for unsupported namespace handling.
- 1
🚀 Changeset Version Preview#
3 package(s) bumped directly, 44 bumped as dependents.
🟥 Major bumps#
Package Version Reason @tanstack/ai-durable-stream0.0.0 → 1.0.0 Changeset @tanstack/ai-acp0.2.3 → 1.0.0 Dependent @tanstack/ai-angular0.3.1 → 1.0.0 Dependent @tanstack/ai-anthropic0.16.3 → 1.0.0 Dependent @tanstack/ai-bedrock0.1.4 → 1.0.0 Dependent @tanstack/ai-claude-code0.2.3 → 1.0.0 Dependent @tanstack/ai-code-mode0.3.8 → 1.0.0 Dependent @tanstack/ai-code-mode-skills0.3.11 → 1.0.0 Dependent @tanstack/ai-codex0.2.3 → 1.0.0 Dependent @tanstack/ai-elevenlabs0.2.34 → 1.0.0 Dependent @tanstack/ai-fal0.9.12 → 1.0.0 Dependent @tanstack/ai-gemini0.20.1 → 1.0.0 Dependent @tanstack/ai-grok0.14.9 → 1.0.0 Dependent @tanstack/ai-grok-build0.2.3 → 1.0.0 Dependent @tanstack/ai-groq0.5.3 → 1.0.0 Dependent @tanstack/ai-isolate-node0.1.47 → 1.0.0 Dependent @tanstack/ai-isolate-quickjs0.1.47 → 1.0.0 Dependent @tanstack/ai-mistral0.2.3 → 1.0.0 Dependent @tanstack/ai-ollama0.8.16 → 1.0.0 Dependent @tanstack/ai-openai0.17.1 → 1.0.0 Dependent @tanstack/ai-opencode0.2.3 → 1.0.0 Dependent @tanstack/ai-openrouter0.15.10 → 1.0.0 Dependent @tanstack/ai-preact0.11.1 → 1.0.0 Dependent @tanstack/ai-react0.18.1 → 1.0.0 Dependent @tanstack/ai-react-ui0.8.15 → 1.0.0 Dependent @tanstack/ai-sandbox0.2.4 → 1.0.0 Dependent @tanstack/ai-sandbox-cloudflare0.2.4 → 1.0.0 Dependent @tanstack/ai-sandbox-daytona0.2.0 → 1.0.0 Dependent @tanstack/ai-sandbox-docker0.2.0 → 1.0.0 Dependent @tanstack/ai-sandbox-local-process0.2.0 → 1.0.0 Dependent @tanstack/ai-sandbox-sprites0.2.1 → 1.0.0 Dependent @tanstack/ai-sandbox-vercel0.2.0 → 1.0.0 Dependent @tanstack/ai-solid0.15.1 → 1.0.0 Dependent @tanstack/ai-solid-ui0.7.14 → 1.0.0 Dependent @tanstack/ai-svelte0.15.1 → 1.0.0 Dependent @tanstack/ai-vue0.15.1 → 1.0.0 Dependent @tanstack/openai-base0.9.9 → 1.0.0 Dependent 🟨 Minor bumps#
Package Version Reason @tanstack/ai0.42.0 → 0.43.0 Changeset @tanstack/ai-client0.22.1 → 0.23.0 Changeset 🟩 Patch bumps#
Package Version Reason @tanstack/ai-devtools-core0.4.24 → 0.4.25 Dependent @tanstack/ai-isolate-cloudflare0.2.38 → 0.2.39 Dependent @tanstack/ai-mcp0.2.5 → 0.2.6 Dependent @tanstack/ai-vue-ui0.2.34 → 0.2.35 Dependent @tanstack/preact-ai-devtools0.1.67 → 0.1.68 Dependent @tanstack/react-ai-devtools0.2.67 → 0.2.68 Dependent @tanstack/solid-ai-devtools0.2.67 → 0.2.68 Dependent ag-ui0.0.2 → 0.0.3 Dependent View your CI Pipeline Execution ↗ for commit 35070e7a9a631e92557014b8f5461177ced3ca24
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:15UTCActionable 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 bcb1b939c46c4ea58b288a262ac844827fe209cc and 35070e7a9a631e92557014b8f5461177ced3ca24.
📒 Files selected for processing (3)
.changeset/shared-scope.mdpackages/ai/src/index.tspackages/ai/src/scope.ts
@@ -0,0 +26,21 @@26+ * key both subsystems already center on. Same concept as27+ * `ChatMiddlewareContext.threadId`.28+ */29+ threadId: string30+ /**31+ * Durable end-user identity, for cross-thread recall and per-user isolation.32+ * Optional, but required in practice for any multi-user deployment — a33+ * `threadId` alone is not an authorization boundary (see Security above).34+ */35+ userId?: string36+ /**37+ * Tenant/organization boundary for multi-tenant deployments. When present,38+ * every read and write must be confined to it.39+ */40+ tenantId?: string41+ /**42+ * Logical partition within a tenant/user (e.g. separating distinct memory43+ * banks or persistence namespaces). Reserved — no subsystem keys on it yet;44+ * adapters that don't understand it must ignore it rather than error.45+ */46+ namespace?: string🔒 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
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.@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@980commit:
35070e7AlemTuzlak approved these changes
AlemTuzlak merged this4ce7600
AlemTuzlak closed this
Sign in to join this conversation.
📝 Walkthrough
Walkthrough#
Adds a shared
Scopeinterface for conversation identity and isolation, exports it from@tanstack/ai, and documents the additive minor release. The type includes requiredthreadIdplus optional user, tenant, and namespace fields.Changes#
Shared Scope contract
packages/ai/src/scope.ts,packages/ai/src/index.ts,.changeset/shared-scope.mdScopeinterface, 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)
✨ Finishing Touches
📝 Generate docstrings
🧪 Generate unit tests (beta)
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