import { RealtimeManager } from '@ai-matrx/data/realtime'; import { RecordsClient } from '../core/index.cjs'; import { CreateEntityDataPortOptions, EntityDataPort } from '../entity/index.cjs'; import { RecordOrganizationPort, ObjectOrganizationAnswer } from '../core/index.cjs'; import { RecordsConfig, RowAgentPort, RecordsErrorSink, RecordsDataSource, RecordsChangeSink, RowAgentTarget } from '../core/index.cjs'; import { Uuid, RecordsResult } from '../core/index.cjs'; import { RecordSearchRequest, RecordSearchHit, listStoreRecordCandidates } from '../search/index.cjs'; import '../subscription-BRwuydeh.cjs'; import '../rule-Ch4aZVWV.cjs'; import '../relation-DuY2Eis-.cjs'; import '../field-BJBjyD8y.cjs'; import '../doors-CBiSnfzU.cjs'; import '../pickListDoors-cMy0JEig.cjs'; import '../portal-Cd8TMBAQ.cjs'; import '../table-kind/index.cjs'; import '../types-BJf9xVXa.cjs'; /** A signed-in database identity: the client every door and live change rides, and who it is. */ interface RecordsSession { /** A supabase-js client (or anything shaped like one) carrying the identity's access token. */ supabase: object; /** The identity's user id, when known (the live-change echo test and the client's own mirror use it). */ userId?: Uuid; } /** How setup signs in. Session today; an organization API key later — same port. */ interface RecordsAuthPort { readonly kind: "session" | "api_key"; session(): Promise; } /** A supabase-js client that already carries a signed-in person (browser sign-in, `signInWithPassword`, SSR cookies). */ declare function sessionAuth(supabase: object, userId?: Uuid): RecordsAuthPort; interface CreateRecordsOptions { auth: RecordsAuthPort; /** * Where new things are saved and which organization a write runs in. `null` = no writes, reads across * all. A function receives every organization the identity belongs to and answers the host's choice. */ organizationId: Uuid | null | ((organizationIds: readonly Uuid[]) => Uuid | null); /** Who is acting. Default: the signed-in person (`user`). An agent acting for a person names `on_behalf_of`. */ actor?: RecordsConfig["actor"]; /** * Live changes. Default `true`: one realtime manager over the session's client. Pass your own * `RealtimeManager` to share a socket, or `false` for none (`watch` then says so and returns a no-op). */ live?: boolean | RealtimeManager; /** * Platform-record aliases (`{ contacts: { kind: "entity", token: "party" } }`) for `entities`. Optional. */ entityAliases?: CreateEntityDataPortOptions["aliases"]; /** The associations store (`@ai-matrx/associations/core` `createAssociationsStore`) bound by the host; handed back as-is. */ associations?: TAssociations; /** * WHICH ORGANIZATION OWNS A RECORD — a port. Default: `custom.where_id_opens`, one call per ask. A host * that keeps answers across remounts or seeds them from a server render binds its own. */ organizationOf?: RecordOrganizationPort; /** RUN AN AGENT ON A ROW — a port the host binds (the run belongs to `@ai-matrx/agents`). Unbound, there is none. */ rowAgent?: RowAgentPort; onError?: RecordsErrorSink; } interface RecordsSetup { /** How this setup signed in. */ readonly authKind: RecordsAuthPort["kind"]; /** The signed-in identity's user id, when known. */ readonly userId: Uuid | undefined; /** Every organization the identity belongs to (reads span them; the host filters visibly). */ readonly organizationIds: readonly Uuid[]; /** Where this setup's writes go (the host's choice), or null. */ readonly organizationId: Uuid | null; /** The typed client over the store's doors: tables, records, versions, archive and restore, views, forms… */ readonly records: RecordsClient; /** The data source the doors ride — hand it to any other section (`records/forms`, `records/search`). */ readonly dataSource: RecordsDataSource; /** Platform records (contacts, projects, tasks) through the same port shape custom tables use. */ readonly entities: EntityDataPort; /** The live-changes manager, or null when `live: false`. */ readonly realtime: RealtimeManager | null; /** Search every table the identity can see (never narrowed by `organizationId`). */ search(request: RecordSearchRequest): Promise>; /** Candidates for a "link a record" picker. */ recordCandidates(args: { search?: string; limit?: number; }): ReturnType; /** * Watch one table's records (other people's changes; this setup's own writes are dropped). `records(ids)` * names the changed records (`null` = re-read the page); `shape()` = the table's columns moved. */ watch(tableId: Uuid, sink: Partial, organizationId?: Uuid): () => void; /** The associations store the host bound, if any. */ readonly associations: TAssociations | undefined; /** Which organization owns an object (table, record, form…), read from the object — never the person's pick. */ organizationOf(id: Uuid): Promise; /** The host's agent runner, or null when none is bound (agent buttons are then not drawn). */ readonly rowAgent: RowAgentPort | null; /** Run an agent on a row through the bound runner; refuses by name when none is bound. */ runAgentOnRow(target: RowAgentTarget): Promise>; /** Close live channels (a Node script calls this before it exits). */ close(): void; } declare function createRecords(options: CreateRecordsOptions): Promise>; export { createRecords, sessionAuth }; export type { CreateRecordsOptions, RecordsAuthPort, RecordsSession, RecordsSetup };