{"_id":"@delphi-ai/multi-tenant-chat","_rev":"2-8c3c9c5ded1996288a2b7388e15e522b","name":"@delphi-ai/multi-tenant-chat","dist-tags":{"latest":"0.1.1"},"versions":{"0.1.0":{"name":"@delphi-ai/multi-tenant-chat","version":"0.1.0","keywords":["chat","multi-tenant","vercel","bot","webhook"],"license":"MIT","_id":"@delphi-ai/multi-tenant-chat@0.1.0","maintainers":[{"name":"mrlol","email":"mrlol.yt.oficial@gmail.com"}],"homepage":"https://github.com/delphi-ai/multi-tenant-chat#readme","bugs":{"url":"https://github.com/delphi-ai/multi-tenant-chat/issues"},"dist":{"shasum":"39e39fe5133072a68d04ac76bc674a926f273921","tarball":"https://registry.npmjs.org/@delphi-ai/multi-tenant-chat/-/multi-tenant-chat-0.1.0.tgz","fileCount":9,"integrity":"sha512-ubKnVfx8qUPa1UD/mdEkOh51MO6tyhNzhyB7/NaEoHZFILSWVA8gf/qNDTHydpMvXwRx4YQwluZcvvqlUgAvtw==","signatures":[{"sig":"MEYCIQCz3plISqm1HvaqnQmJfmAKpjF+SzkfAtxni2djj+U5ewIhAN5mzb1qvVlaZoVLrQx4o2ok8OhhQoe/3Joz+xuoIcdb","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":48991},"main":"./dist/index.cjs","type":"module","_from":"file:delphi-ai-multi-tenant-chat-0.1.0.tgz","types":"./dist/index.d.ts","module":"./dist/index.js","engines":{"node":">=20"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"}},"scripts":{"lint":"eslint src --max-warnings 0","test":"vitest run","build":"tsup","check-types":"tsc --noEmit"},"_npmUser":{"name":"mrlol","email":"mrlol.yt.oficial@gmail.com"},"_resolved":"/private/var/folders/0d/48lg7k0130721mkff_gkkn1w0000gn/T/cf93f8d247c19d5ebb7516f7a9a3bf3e/delphi-ai-multi-tenant-chat-0.1.0.tgz","_integrity":"sha512-ubKnVfx8qUPa1UD/mdEkOh51MO6tyhNzhyB7/NaEoHZFILSWVA8gf/qNDTHydpMvXwRx4YQwluZcvvqlUgAvtw==","repository":{"url":"git+https://github.com/delphi-ai/multi-tenant-chat.git","type":"git"},"_npmVersion":"10.9.3","description":"Multi-tenant runtime manager for the Vercel Chat SDK","directories":{},"_nodeVersion":"22.18.0","_hasShrinkwrap":false,"devDependencies":{"chat":"^4.27.0","tsup":"^8.0.0","eslint":"^9.0.0","vitest":"^4.0.0","typescript":"^5.9.0","@types/node":"^22.0.0","typescript-eslint":"^8.59.2"},"peerDependencies":{"chat":"^4.27.0"},"_npmOperationalInternal":{"tmp":"tmp/multi-tenant-chat_0.1.0_1778266140798_0.8657589752212209","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"@delphi-ai/multi-tenant-chat","version":"0.1.1","description":"Multi-tenant runtime manager for the Vercel Chat SDK","type":"module","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"}},"main":"./dist/index.cjs","module":"./dist/index.js","types":"./dist/index.d.ts","scripts":{"build":"tsup","check-types":"tsc --noEmit","lint":"eslint src --max-warnings 0","test":"vitest run","prepare":"tsup"},"peerDependencies":{"chat":"^4.27.0"},"devDependencies":{"@types/node":"^22.0.0","chat":"^4.27.0","eslint":"^9.0.0","tsup":"^8.0.0","typescript":"^5.9.0","typescript-eslint":"^8.59.2","vitest":"^4.0.0"},"engines":{"node":">=20"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/delphi-ai/multi-tenant-chat.git"},"keywords":["chat","multi-tenant","vercel","bot","webhook"],"gitHead":"ec9953544b4713589f0aa42901ed4df1a66e5213","_id":"@delphi-ai/multi-tenant-chat@0.1.1","bugs":{"url":"https://github.com/delphi-ai/multi-tenant-chat/issues"},"homepage":"https://github.com/delphi-ai/multi-tenant-chat#readme","_nodeVersion":"24.15.0","_npmVersion":"11.14.1","dist":{"integrity":"sha512-f+PDVGtS9RcJ4nVMkN5gbdohdHUwTeYbb/XKgO1GodW3i6pip2UwbQXwnsXn9xB+JbgSHjyeszEKLuV2DqeliA==","shasum":"b3b3f98d899d1d7c6e81f2c0c8cca90fbbac2bdf","tarball":"https://registry.npmjs.org/@delphi-ai/multi-tenant-chat/-/multi-tenant-chat-0.1.1.tgz","fileCount":9,"unpackedSize":47824,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDGFZusyub4NlKK25cJY3CD2kqOfH98j0MaeQZ6RCR2fwIhALdqhwLN5AqBUnHbtLHp0ubskVr13CFGIx+Bg/70x0MZ"}]},"_npmUser":{"name":"mrlol","email":"mrlol.yt.oficial@gmail.com"},"directories":{},"maintainers":[{"name":"mrlol","email":"mrlol.yt.oficial@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/multi-tenant-chat_0.1.1_1781556160284_0.0015837769950586278"},"_hasShrinkwrap":false}},"time":{"created":"2026-05-08T18:49:00.668Z","modified":"2026-06-15T20:42:40.565Z","0.1.0":"2026-05-08T18:49:00.961Z","0.1.1":"2026-06-15T20:42:40.430Z"},"bugs":{"url":"https://github.com/delphi-ai/multi-tenant-chat/issues"},"license":"MIT","homepage":"https://github.com/delphi-ai/multi-tenant-chat#readme","keywords":["chat","multi-tenant","vercel","bot","webhook"],"repository":{"type":"git","url":"git+https://github.com/delphi-ai/multi-tenant-chat.git"},"description":"Multi-tenant runtime manager for the Vercel Chat SDK","maintainers":[{"name":"mrlol","email":"mrlol.yt.oficial@gmail.com"}],"readme":"# @delphi-ai/multi-tenant-chat\n\nMulti-tenant runtime manager for the [Vercel Chat SDK](https://github.com/vercel/chat). Manages per-connection `Chat` instances with lazy creation, LRU eviction, and `AsyncLocalStorage`-based connection context.\n\n## Install\n\n```bash\npnpm add @delphi-ai/multi-tenant-chat\n\n# Peer dependency\npnpm add chat\n```\n\n## Usage\n\n```ts\nimport { MultiTenantChat, type ChatConnection } from \"@delphi-ai/multi-tenant-chat\";\n\ninterface MyConnection extends ChatConnection {\n  ownerId: string;\n}\n\nconst manager = new MultiTenantChat<MyConnection>({\n  async resolveConnection({ platform, connectionKey, request }) {\n    // Look up connection from your database\n    return { id: connectionKey, platform, ownerId: \"user-123\" };\n  },\n\n  async resolveCredentials(connection) {\n    // Return platform-specific credentials\n    return { botToken: \"xoxb-...\" };\n  },\n\n  state: yourStateAdapter,\n\n  platforms: {\n    slack: (credentials) => createSlackAdapter(credentials),\n    telegram: (credentials) => createTelegramAdapter(credentials),\n  },\n\n  async onDirectMessage(ctx, thread, message) {\n    await thread.post(\"Hello from multi-tenant chat!\");\n  },\n});\n\n// In your webhook handler:\nexport async function POST(request: Request) {\n  return manager.handleWebhook(request, {\n    platform: \"telegram\",\n    connectionKey: \"connection-id\",\n  });\n}\n```\n\n## API\n\n### `MultiTenantChat<T extends ChatConnection>`\n\nMain class that manages per-connection Chat instances.\n\n**Config:**\n- `resolveConnection` — resolve a connection from platform + key + request\n- `resolveCredentials` — return credentials for a connection\n- `state` — a `StateAdapter` (shared across all connections, keys are auto-prefixed)\n- `platforms` — map of platform name to adapter factory\n- `onDirectMessage` / `onMention` / `onSubscribedMessage` — message handlers\n- `onError` — global error handler\n- `runtimeCacheMax` — max cached Chat instances (default 1000)\n\n**Methods:**\n- `handleWebhook(request, { platform, connectionKey })` — route a webhook to the correct Chat instance\n- `destroyRuntime(connectionId)` — tear down a cached runtime\n\n### `getConnection<T>()`\n\nRetrieve the current connection from `AsyncLocalStorage` context (inside a handler).\n\n### `createPrefixedState(base, prefix)`\n\nWrap any `StateAdapter` with per-connection key namespacing.\n\n### `RuntimeCache`\n\nLRU cache of live `Chat` instances with lazy creation and eviction.\n\n## License\n\nMIT\n","readmeFilename":"README.md"}