First-class multi-tenant runtime for per-connection bots

Đang mở
#563 2 bình luận 1 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
30/100
Loại issue
Tính năng
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Ít trao đổi
Công nghệ
typescript
Lĩnh vực
api, backend

Hướng nghiên cứu

Bắt đầu bằng cách đọc implementation tham chiếu tại github.com/delphi-ai/multi-tenant-chat và so sánh nó với các entry point của webhook và Chat runtime trong SDK. Công việc hoàn tất khi các connection được resolve theo từng webhook, các runtime cô lập credentials và state, các handler nhận được connection context, và việc LRU eviction được bao phủ bởi các test.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

enhancement
Problem Statement

The Chat SDK assumes one bot identity and one credential set per process. In a SaaS product, each customer connects their own Telegram bot, SMS number, or WhatsApp sender. We need many isolated bot runtimes on shared webhook routes without running one process per connection.

Proposed Solution

Add a built-in multi-tenant mode (or official helper) that:

  1. Resolves a connection from platform + connectionKey on each webhook
  2. Lazily creates a Chat instance per connection with its own adapter credentials
  3. Prefixes shared state keys so thread/subscription state does not collide
  4. Exposes connection context in message handlers (e.g. via AsyncLocalStorage)
  5. Caches runtimes with LRU eviction

Handlers would receive (ctx, thread, message) where ctx.connection identifies the tenant.

Alternatives Considered
  • One global Chat and swap credentials per request: not safe for concurrent webhooks
  • One Chat singleton per connection: too much memory at scale
  • External wrapper package: works today, but belongs in the SDK long term

We ship option 3 as @delphi-ai/multi-tenant-chat until upstream support exists.

Use Case

Priority

Critical

Contribution
  • I am willing to help implement this feature
Additional Context

We already built and use this pattern. Reference implementation: https://github.com/delphi-ai/multi-tenant-chat.

Ngôn ngữ chính
TypeScript
Star
2.5k
Fork
355
Merge trung bình
2 ngày 15 giờ
Pull request đã merge (30 ngày)
42

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của vercel/chat

Tất cả issue của vercel/chat

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.