import { C as ChatStore } from '../../chat-store-dqaTB0vU.mjs'; import { D as DrizzleClientOptions } from '../../client-BYVNvU5S.mjs'; export { a as DrizzleDb, g as getDrizzleDb } from '../../client-BYVNvU5S.mjs'; import * as ai from 'ai'; import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core'; import 'drizzle-orm/postgres-js'; /** * Drizzle schema for the default ChatStore (v2, parts-first). * * This is the schema the *default* store uses. A BYO store may use any schema * it likes — this one is not part of the public contract, the `ChatStore` * interface is. It's exported so consumers on the default path can run * `drizzle-kit` against it and so the migration can reference it. * * What changed from v0.7.1 * ------------------------ * The old schema stored a flattened `content: text` as the apparent source of * truth and tucked the real AI SDK `parts` into a `metadata` jsonb blob. That * inverted the actual authority — `parts` (text + reasoning + tool calls + * sources + files) is what the AI SDK round-trips and what rendering needs; * `content` was a lossy shadow. * * v2 makes that authority explicit: * • `parts` — jsonb NOT NULL — the canonical AI SDK message parts. Source * of truth for rendering and model replay. * • `text` — text — a denormalised projection of the text parts, for * cheap previews / titles / search. Never authoritative. * * A backfill migration populates these from the old columns so existing * installs upgrade without data loss (see migrations/). */ declare const conversations: drizzle_orm_pg_core.PgTableWithColumns<{ name: "chat_conversations"; schema: undefined; columns: { id: drizzle_orm_pg_core.PgColumn<{ name: "id"; tableName: "chat_conversations"; dataType: "string"; columnType: "PgText"; data: string; driverParam: string; notNull: true; hasDefault: false; isPrimaryKey: true; isAutoincrement: false; hasRuntimeDefault: false; enumValues: [string, ...string[]]; baseColumn: never; identity: undefined; generated: undefined; }, {}, {}>; userId: drizzle_orm_pg_core.PgColumn<{ name: "user_id"; tableName: "chat_conversations"; dataType: "string"; columnType: "PgText"; data: string; driverParam: string; notNull: true; hasDefault: false; isPrimaryKey: false; isAutoincrement: false; hasRuntimeDefault: false; enumValues: [string, ...string[]]; baseColumn: never; identity: undefined; generated: undefined; }, {}, {}>; title: drizzle_orm_pg_core.PgColumn<{ name: "title"; tableName: "chat_conversations"; dataType: "string"; columnType: "PgText"; data: string; driverParam: string; notNull: true; hasDefault: true; isPrimaryKey: false; isAutoincrement: false; hasRuntimeDefault: false; enumValues: [string, ...string[]]; baseColumn: never; identity: undefined; generated: undefined; }, {}, {}>; metadata: drizzle_orm_pg_core.PgColumn<{ name: "metadata"; tableName: "chat_conversations"; dataType: "json"; columnType: "PgJsonb"; data: Record; driverParam: unknown; notNull: false; hasDefault: false; isPrimaryKey: false; isAutoincrement: false; hasRuntimeDefault: false; enumValues: undefined; baseColumn: never; identity: undefined; generated: undefined; }, {}, { $type: Record; }>; createdAt: drizzle_orm_pg_core.PgColumn<{ name: "created_at"; tableName: "chat_conversations"; dataType: "date"; columnType: "PgTimestamp"; data: Date; driverParam: string; notNull: true; hasDefault: true; isPrimaryKey: false; isAutoincrement: false; hasRuntimeDefault: false; enumValues: undefined; baseColumn: never; identity: undefined; generated: undefined; }, {}, {}>; updatedAt: drizzle_orm_pg_core.PgColumn<{ name: "updated_at"; tableName: "chat_conversations"; dataType: "date"; columnType: "PgTimestamp"; data: Date; driverParam: string; notNull: true; hasDefault: true; isPrimaryKey: false; isAutoincrement: false; hasRuntimeDefault: false; enumValues: undefined; baseColumn: never; identity: undefined; generated: undefined; }, {}, {}>; }; dialect: "pg"; }>; declare const messages: drizzle_orm_pg_core.PgTableWithColumns<{ name: "chat_messages"; schema: undefined; columns: { id: drizzle_orm_pg_core.PgColumn<{ name: "id"; tableName: "chat_messages"; dataType: "string"; columnType: "PgText"; data: string; driverParam: string; notNull: true; hasDefault: false; isPrimaryKey: true; isAutoincrement: false; hasRuntimeDefault: false; enumValues: [string, ...string[]]; baseColumn: never; identity: undefined; generated: undefined; }, {}, {}>; conversationId: drizzle_orm_pg_core.PgColumn<{ name: "conversation_id"; tableName: "chat_messages"; dataType: "string"; columnType: "PgText"; data: string; driverParam: string; notNull: true; hasDefault: false; isPrimaryKey: false; isAutoincrement: false; hasRuntimeDefault: false; enumValues: [string, ...string[]]; baseColumn: never; identity: undefined; generated: undefined; }, {}, {}>; role: drizzle_orm_pg_core.PgColumn<{ name: "role"; tableName: "chat_messages"; dataType: "string"; columnType: "PgText"; data: "user" | "assistant" | "system"; driverParam: string; notNull: true; hasDefault: false; isPrimaryKey: false; isAutoincrement: false; hasRuntimeDefault: false; enumValues: [string, ...string[]]; baseColumn: never; identity: undefined; generated: undefined; }, {}, { $type: "user" | "assistant" | "system"; }>; parts: drizzle_orm_pg_core.PgColumn<{ name: "parts"; tableName: "chat_messages"; dataType: "json"; columnType: "PgJsonb"; data: ai.UIMessagePart[]; driverParam: unknown; notNull: true; hasDefault: false; isPrimaryKey: false; isAutoincrement: false; hasRuntimeDefault: false; enumValues: undefined; baseColumn: never; identity: undefined; generated: undefined; }, {}, { $type: ai.UIMessagePart[]; }>; text: drizzle_orm_pg_core.PgColumn<{ name: "text"; tableName: "chat_messages"; dataType: "string"; columnType: "PgText"; data: string; driverParam: string; notNull: true; hasDefault: true; isPrimaryKey: false; isAutoincrement: false; hasRuntimeDefault: false; enumValues: [string, ...string[]]; baseColumn: never; identity: undefined; generated: undefined; }, {}, {}>; model: drizzle_orm_pg_core.PgColumn<{ name: "model"; tableName: "chat_messages"; dataType: "string"; columnType: "PgText"; data: string; driverParam: string; notNull: false; hasDefault: false; isPrimaryKey: false; isAutoincrement: false; hasRuntimeDefault: false; enumValues: [string, ...string[]]; baseColumn: never; identity: undefined; generated: undefined; }, {}, {}>; createdAt: drizzle_orm_pg_core.PgColumn<{ name: "created_at"; tableName: "chat_messages"; dataType: "date"; columnType: "PgTimestamp"; data: Date; driverParam: string; notNull: true; hasDefault: true; isPrimaryKey: false; isAutoincrement: false; hasRuntimeDefault: false; enumValues: undefined; baseColumn: never; identity: undefined; generated: undefined; }, {}, {}>; }; dialect: "pg"; }>; type ConversationRow = typeof conversations.$inferSelect; type NewConversationRow = typeof conversations.$inferInsert; type MessageRow = typeof messages.$inferSelect; type NewMessageRow = typeof messages.$inferInsert; type schema_ConversationRow = ConversationRow; type schema_MessageRow = MessageRow; type schema_NewConversationRow = NewConversationRow; type schema_NewMessageRow = NewMessageRow; declare const schema_conversations: typeof conversations; declare const schema_messages: typeof messages; declare namespace schema { export { type schema_ConversationRow as ConversationRow, type schema_MessageRow as MessageRow, type schema_NewConversationRow as NewConversationRow, type schema_NewMessageRow as NewMessageRow, schema_conversations as conversations, schema_messages as messages }; } /** * Default ChatStore implementation, on Postgres via Drizzle. * * This is the "hosted/default" persistence the widget ships with. It is just * one implementation of the `ChatStore` interface — the interface, not this * file, is the contract. Every method here upholds the interface's security * invariants: * * • The store is bound to one `userId` (constructor arg from the verified * server session). No method takes a userId. * • Reads are implicitly scoped to that user. `getConversation` / * `listMessages` return null/[] for rows the user doesn't own — never * another user's data, and not distinguishable from "not found". * • Mutations verify ownership and throw `ConversationOwnershipError` on a * foreign row. * • `saveTurn` is idempotent on message id and bumps `updatedAt`. */ /** * Create a `ChatStoreFactory` backed by the default Drizzle/Postgres store. * * Pass to `createChatHandler({ store: createDrizzleChatStore() })`. The * factory binds each store instance to the verified `userId` the handler * provides per request. The underlying connection pool is shared. */ declare function createDrizzleChatStore(options?: DrizzleClientOptions): (userId: string) => ChatStore; export { type ConversationRow, DrizzleClientOptions, type MessageRow, type NewConversationRow, type NewMessageRow, createDrizzleChatStore, schema };