Skip to content
SegmentStream/ Docs

Loading documentation…

↑ ↓ to navigate  ↵ to open  Esc to close
Website Console
Section menu

@segmentstream/ontology · Q–T

141 public exports from @segmentstream/ontology.

Public exports

Query

A query on any entity. The runtime checks the fields against the entity. A query. `where` follows {@link Where}; `include` adds related records by relationship name, as a list, `["owner", "tags"]`, or as an object, `{ owner: true, tags: true }`.

const Query: Schema.Struct<{
    readonly where: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>>;
    readonly orderBy: Schema.optionalKey<Schema.$Array<Schema.Struct<{
        readonly field: Schema.String;
        readonly direction: Schema.optionalKey<Schema.Literals<readonly [
            "asc",
            "desc"
        ]>>;
    }>>>;
    readonly select: Schema.optionalKey<Schema.$Array<Schema.String>>;
    readonly include: Schema.optionalKey<Schema.Codec<Included, readonly string[] | Included, never, never>>;
    readonly after: Schema.optionalKey<Schema.String>;
    readonly limit: Schema.optionalKey<Schema.Int>;
}>
interface Query {
    readonly where?: Where;
    readonly orderBy?: ReadonlyArray<OrderBy>;
    readonly select?: ReadonlyArray<string>;
    readonly include?: ReadonlyArray<string> | Included;
    readonly after?: string;
    readonly limit?: number;
}
QueryField

A field a query can filter and sort on: a system field, a property, or a `<relationship>_id`.

interface QueryField {
    readonly name: string;
    readonly storage: StorageType;
    readonly nullable: boolean;
    readonly options?: ReadonlyArray<string>;
}
QueryResult

A page of records. `nextCursor` is `null` on the last page. A page of records of any entity.

interface QueryResult<R> {
    readonly items: ReadonlyArray<R>;
    readonly nextCursor: string | null;
    readonly projected?: true;
}
const QueryResult: Schema.Struct<{
    readonly items: Schema.$Array<Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>>;
    readonly nextCursor: Schema.NullOr<Schema.String>;
    readonly projected: Schema.optionalKey<Schema.Literal<true>>;
}>
READ_VERB

The verb of every read: lists, queries, records, history, traversals and `include`.

const READ_VERB = "read"
REQUEST_ID_HEADER

The header every response carries: the correlation id quoted in error bodies and logs.

const REQUEST_ID_HEADER = "x-request-id"
RUNTIME_CONTEXT_FD

Where `segmentstream exec` passes the local runtime context: a pipe's file descriptor.

const RUNTIME_CONTEXT_FD = "SEGMENTSTREAM_RUNTIME_CONTEXT_FD"
RUNTIME_IDENTITY_ENVIRONMENT_VARIABLES

The deployment's own runtime callers, such as the app's agent: the issuer and the audience of the team's Vercel OIDC tokens, set together by the platform on deployments that have an agent. Without them a runtime token is an invalid token. Tokens must also name the project in Vercel's `VERCEL_PROJECT_ID`, as the agent runs in the same Vercel project as the ontology service.

const RUNTIME_IDENTITY_ENVIRONMENT_VARIABLES: {
    readonly issuer: "SEGMENTSTREAM_RUNTIME_OIDC_ISSUER";
    readonly audience: "SEGMENTSTREAM_RUNTIME_OIDC_AUDIENCE";
    readonly projectId: "VERCEL_PROJECT_ID";
}
RUNTIME_SOURCE_PROVIDERS

The channels whose message a tool call's runtime source can name. `initialize` lists them, so that an agent sends only a source its ontology reads.

const RUNTIME_SOURCE_PROVIDERS: readonly [
    "telegram",
    "slack",
    "whatsapp"
]
RecordRef

A record id, or a record.

type RecordRef = string | {
    readonly id: string;
};
RecordWhere

A `where` on records of type `R`, in the query language of `src/query.ts`: conditions by field, a {@link Where} on the target of each relationship `L`, and `and`, `or` and `not`. The runtime checks which operators a field's type takes.

type RecordWhere<R, L extends string = never> = {
    readonly [K in keyof R]?: FieldCondition<R[K]>;
} & {
    readonly [K in L]?: Where;
} & {
    readonly and?: ReadonlyArray<RecordWhere<R, L>>;
    readonly or?: ReadonlyArray<RecordWhere<R, L>>;
    readonly not?: RecordWhere<R, L>;
};
ReferenceOptions
interface ReferenceOptions {
    readonly optional?: boolean;
    readonly label?: string;
    readonly description?: string;
}
RelationshipManifest

A relationship as declared. The inverse is not repeated on the target entity: readers derive it from `to`, `inverse` and the second `phrase`.

const RelationshipManifest: Schema.Struct<{
    readonly on: Schema.optionalKey<Schema.Struct<{
        readonly property: Schema.String;
        readonly targetProperty: Schema.String;
    }>>;
    readonly name: Schema.String;
    readonly to: Schema.String;
    readonly inverse: Schema.String;
    readonly cardinality: Schema.Literals<readonly [
        "one",
        "many"
    ]>;
    readonly optional: Schema.optionalKey<Schema.Boolean>;
    readonly onDelete: Schema.optionalKey<Schema.Literals<readonly [
        "setNull",
        "cascade",
        "restrict"
    ]>>;
    readonly ordered: Schema.optionalKey<Schema.Boolean>;
    readonly phrase: Schema.Tuple<readonly [
        Schema.String,
        Schema.String
    ]>;
    readonly description: Schema.String;
}>
type RelationshipManifest = typeof RelationshipManifest.Type;
Relationships
type Relationships = {
    readonly [name: string]: AnyRelationship;
};
RenderOptions
interface RenderOptions {
    readonly as?: ReadonlyArray<string>;
}
ResolveIdentityInput
interface ResolveIdentityInput {
    readonly senderKind?: "member" | "service";
    readonly provider: string;
    readonly externalId: string;
    readonly chat: "private" | "group";
    readonly delivery?: {
        readonly channel: string;
        readonly chatId: string;
    };
    readonly turn: boolean;
    readonly display?: string | null;
    readonly username?: string;
    readonly noticeVersion?: string;
    readonly noticeSha256?: string;
    readonly addressVerified?: boolean;
    readonly limits?: {
        readonly perSender?: Partial<AgentLimits["perSender"]>;
        readonly newUsersPerHour?: number;
        readonly workspaceTurnsPerDay?: number;
        readonly guest?: Partial<AgentLimits["guest"]>;
    };
}
ResolvedAction
interface ResolvedAction {
    readonly name: string;
    readonly action: Action;
    readonly permission: string;
    readonly anyOf?: ReadonlyArray<string>;
    readonly input: JsonSchemaObject | undefined;
    readonly connections: ReadonlyArray<string>;
    readonly hints: ActionHints | undefined;
    readonly writes: ReadonlyArray<string> | undefined;
}
ResolvedConnection

A connection the ontology declares.

interface ResolvedConnection {
    readonly key: string;
    readonly description: string;
    readonly delivers: boolean;
    readonly owner?: "user";
    readonly handle: AnyConnectionHandle;
}
ResolvedEntity

An entity with its relationship targets resolved and its actions evaluated.

interface ResolvedEntity {
    readonly entity: AnyEntity;
    readonly name: string;
    readonly builtIn: boolean;
    readonly properties: ReadonlyArray<ResolvedProperty>;
    readonly relationships: ReadonlyArray<ResolvedRelationship>;
    readonly indexes: ReadonlyArray<ResolvedIndex>;
    readonly actions: ReadonlyArray<ResolvedAction>;
    readonly permissions: EntityPermissions;
    readonly writes: EntityWrites;
}
ResolvedFeedback
interface ResolvedFeedback {
    readonly enabled: boolean;
    readonly automaticFailureReports?: boolean;
    readonly files: boolean;
    readonly builders: ReadonlyArray<string>;
}
ResolvedGuest

Guests as the manifest carries them; the built-in role `guest` holds their permissions.

interface ResolvedGuest {
    readonly openOnInvite?: ReadonlyArray<string>;
    readonly byChannel?: Readonly<Partial<Record<GuestChannel, ReadonlyArray<string>>>>;
    readonly channels: ReadonlyArray<GuestChannel>;
    readonly origins: ReadonlyArray<string>;
    readonly botCheck?: ResolvedGuestBotCheck;
    readonly confirmations?: true;
}
ResolvedGuestBotCheck

A bot check as the manifest carries it: the connection by its key.

type ResolvedGuestBotCheck = {
    readonly scheme: GuestBotCheckScheme;
    readonly connection: string;
    readonly input: string;
    readonly secret?: undefined;
} | {
    readonly scheme: GuestBotCheckScheme;
    readonly secret: string;
    readonly connection?: undefined;
    readonly input?: undefined;
};
ResolvedIndex
interface ResolvedIndex {
    readonly properties: ReadonlyArray<string>;
    readonly unique: boolean;
}
ResolvedProperty
interface ResolvedProperty {
    readonly name: string;
    readonly schema: Schema.Top;
    readonly definition: PropertyDefinition;
}
ResolvedRelationship
interface ResolvedRelationship {
    readonly name: string;
    readonly relationship: AnyRelationship;
    readonly target: string | undefined;
}
ResolvedSignInOptions

The sign-in options of a checked ontology, with the sign-up its definition declares.

interface ResolvedSignInOptions extends SignInOptions {
    readonly signUp?: ResolvedSignUp;
    readonly guest?: ResolvedGuest;
    readonly onSignUp?: string;
}
ResolvedSignUp

Sign-up as the manifest carries it: the wire names of the roles each open channel grants.

interface ResolvedSignUp {
    readonly channels: Readonly<Partial<Record<SignUpChannel, ReadonlyArray<string>>>>;
    readonly origins?: ReadonlyArray<string>;
}
ResolvedTool

One tool of a checked toolset, as the service serves it.

interface ResolvedTool {
    readonly handle?: ToolHandler;
    readonly name: string;
    readonly mcpName: string;
    readonly permission: string;
    readonly access: "read" | "write";
    readonly fixed: Readonly<Record<string, FixedValue>>;
    readonly description: string;
    readonly inputSchema: Readonly<Record<string, unknown>>;
    readonly hints: ResolvedToolHints;
}
ResolvedToolset

A checked toolset.

interface ResolvedToolset {
    readonly name: string;
    readonly description: string;
    readonly connection: string;
    readonly api: string;
    readonly protocolVersion: string;
    readonly tools: ReadonlyArray<ResolvedTool>;
}
RetainedEntity

Storage the database keeps for an entity the ontology no longer declares, or for the fields a declared entity no longer declares. Its names derive from it as from a declared entity's, and renames keep them current. Kept storage holds no foreign keys; kept fields are also nullable and have no default or index. Declaring the entity again with its id, or the field again under its name, restores it.

const RetainedEntity: Schema.Struct<{
    readonly id: Schema.String;
    readonly name: Schema.String;
    readonly removed: Schema.Boolean;
    readonly properties: Schema.$Array<Schema.encodeKeys<Schema.Struct<{
        readonly column: Schema.optionalKey<Schema.String>;
        readonly scope: Schema.optionalKey<Schema.$Array<Schema.String>>;
        readonly name: Schema.String;
        readonly type: Schema.Literals<readonly [
            "text",
            "email",
            "url",
            "integer",
            "number",
            "boolean",
            "date",
            "timestamp",
            "select",
            "json",
            "blob",
            "list"
        ]>;
        readonly label: Schema.String;
        readonly description: Schema.optionalKey<Schema.String>;
        readonly optional: Schema.Boolean;
        readonly unique: Schema.Boolean;
        readonly managed: Schema.Boolean;
        readonly excludeFromReplication: Schema.optionalKey<Schema.Boolean>;
        readonly default: Schema.optionalKey<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
        readonly display: Schema.optionalKey<Schema.String>;
        readonly renamedFrom: Schema.optionalKey<Schema.String>;
        readonly min: Schema.optionalKey<Schema.Number>;
        readonly max: Schema.optionalKey<Schema.Number>;
        readonly maxLength: Schema.optionalKey<Schema.Number>;
        readonly accept: Schema.optionalKey<Schema.$Array<Schema.String>>;
        readonly maxBytes: Schema.optionalKey<Schema.Number>;
        readonly options: Schema.optionalKey<Schema.$Array<Schema.Struct<{
            readonly value: Schema.String;
            readonly label: Schema.String;
            readonly description: Schema.String;
        }>>>;
        readonly items: Schema.optionalKey<Schema.Literals<readonly [
            "text",
            "email",
            "url",
            "integer",
            "number",
            "boolean",
            "date",
            "timestamp",
            "select",
            "json",
            "blob",
            "list"
        ]>>;
    }>, {
        readonly renamedFrom: "renamed_from";
        readonly maxLength: "max_length";
        readonly maxBytes: "max_bytes";
        readonly excludeFromReplication: "exclude_from_replication";
    }>>;
    readonly relationships: Schema.$Array<Schema.encodeKeys<Schema.Struct<{
        readonly on: Schema.optionalKey<Schema.encodeKeys<Schema.Struct<{
            readonly property: Schema.String;
            readonly targetProperty: Schema.String;
        }>, {
            readonly targetProperty: "target_property";
        }>>;
        readonly onDelete: Schema.optionalKey<Schema.decodeTo<Schema.Literals<readonly [
            "setNull",
            "cascade",
            "restrict"
        ]>, Schema.Literals<readonly [
            "set_null",
            "cascade",
            "restrict"
        ]>, never, never>>;
        readonly name: Schema.String;
        readonly to: Schema.String;
        readonly inverse: Schema.String;
        readonly cardinality: Schema.Literals<readonly [
            "one",
            "many"
        ]>;
        readonly optional: Schema.optionalKey<Schema.Boolean>;
        readonly ordered: Schema.optionalKey<Schema.Boolean>;
        readonly phrase: Schema.Tuple<readonly [
            Schema.String,
            Schema.String
        ]>;
        readonly description: Schema.String;
    }>, {
        readonly onDelete: "on_delete";
    }>>;
    readonly indexes: Schema.$Array<Schema.Struct<{
        readonly properties: Schema.$Array<Schema.String>;
        readonly unique: Schema.Boolean;
    }>>;
    readonly fields: Schema.Struct<{
        readonly properties: Schema.$Array<Schema.encodeKeys<Schema.Struct<{
            readonly column: Schema.optionalKey<Schema.String>;
            readonly scope: Schema.optionalKey<Schema.$Array<Schema.String>>;
            readonly name: Schema.String;
            readonly type: Schema.Literals<readonly [
                "text",
                "email",
                "url",
                "integer",
                "number",
                "boolean",
                "date",
                "timestamp",
                "select",
                "json",
                "blob",
                "list"
            ]>;
            readonly label: Schema.String;
            readonly description: Schema.optionalKey<Schema.String>;
            readonly optional: Schema.Boolean;
            readonly unique: Schema.Boolean;
            readonly managed: Schema.Boolean;
            readonly excludeFromReplication: Schema.optionalKey<Schema.Boolean>;
            readonly default: Schema.optionalKey<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
            readonly display: Schema.optionalKey<Schema.String>;
            readonly renamedFrom: Schema.optionalKey<Schema.String>;
            readonly min: Schema.optionalKey<Schema.Number>;
            readonly max: Schema.optionalKey<Schema.Number>;
            readonly maxLength: Schema.optionalKey<Schema.Number>;
            readonly accept: Schema.optionalKey<Schema.$Array<Schema.String>>;
            readonly maxBytes: Schema.optionalKey<Schema.Number>;
            readonly options: Schema.optionalKey<Schema.$Array<Schema.Struct<{
                readonly value: Schema.String;
                readonly label: Schema.String;
                readonly description: Schema.String;
            }>>>;
            readonly items: Schema.optionalKey<Schema.Literals<readonly [
                "text",
                "email",
                "url",
                "integer",
                "number",
                "boolean",
                "date",
                "timestamp",
                "select",
                "json",
                "blob",
                "list"
            ]>>;
        }>, {
            readonly renamedFrom: "renamed_from";
            readonly maxLength: "max_length";
            readonly maxBytes: "max_bytes";
            readonly excludeFromReplication: "exclude_from_replication";
        }>>;
        readonly relationships: Schema.$Array<Schema.encodeKeys<Schema.Struct<{
            readonly on: Schema.optionalKey<Schema.encodeKeys<Schema.Struct<{
                readonly property: Schema.String;
                readonly targetProperty: Schema.String;
            }>, {
                readonly targetProperty: "target_property";
            }>>;
            readonly onDelete: Schema.optionalKey<Schema.decodeTo<Schema.Literals<readonly [
                "setNull",
                "cascade",
                "restrict"
            ]>, Schema.Literals<readonly [
                "set_null",
                "cascade",
                "restrict"
            ]>, never, never>>;
            readonly name: Schema.String;
            readonly to: Schema.String;
            readonly inverse: Schema.String;
            readonly cardinality: Schema.Literals<readonly [
                "one",
                "many"
            ]>;
            readonly optional: Schema.optionalKey<Schema.Boolean>;
            readonly ordered: Schema.optionalKey<Schema.Boolean>;
            readonly phrase: Schema.Tuple<readonly [
                Schema.String,
                Schema.String
            ]>;
            readonly description: Schema.String;
        }>, {
            readonly onDelete: "on_delete";
        }>>;
    }>;
}>
type RetainedEntity = typeof RetainedEntity.Type;
RetainedStorage

What the catalog records beside the applied manifest about the storage it keeps.

const RetainedStorage: Schema.Struct<{
    readonly entities: Schema.$Array<Schema.Struct<{
        readonly id: Schema.String;
        readonly name: Schema.String;
        readonly removed: Schema.Boolean;
        readonly properties: Schema.$Array<Schema.encodeKeys<Schema.Struct<{
            readonly column: Schema.optionalKey<Schema.String>;
            readonly scope: Schema.optionalKey<Schema.$Array<Schema.String>>;
            readonly name: Schema.String;
            readonly type: Schema.Literals<readonly [
                "text",
                "email",
                "url",
                "integer",
                "number",
                "boolean",
                "date",
                "timestamp",
                "select",
                "json",
                "blob",
                "list"
            ]>;
            readonly label: Schema.String;
            readonly description: Schema.optionalKey<Schema.String>;
            readonly optional: Schema.Boolean;
            readonly unique: Schema.Boolean;
            readonly managed: Schema.Boolean;
            readonly excludeFromReplication: Schema.optionalKey<Schema.Boolean>;
            readonly default: Schema.optionalKey<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
            readonly display: Schema.optionalKey<Schema.String>;
            readonly renamedFrom: Schema.optionalKey<Schema.String>;
            readonly min: Schema.optionalKey<Schema.Number>;
            readonly max: Schema.optionalKey<Schema.Number>;
            readonly maxLength: Schema.optionalKey<Schema.Number>;
            readonly accept: Schema.optionalKey<Schema.$Array<Schema.String>>;
            readonly maxBytes: Schema.optionalKey<Schema.Number>;
            readonly options: Schema.optionalKey<Schema.$Array<Schema.Struct<{
                readonly value: Schema.String;
                readonly label: Schema.String;
                readonly description: Schema.String;
            }>>>;
            readonly items: Schema.optionalKey<Schema.Literals<readonly [
                "text",
                "email",
                "url",
                "integer",
                "number",
                "boolean",
                "date",
                "timestamp",
                "select",
                "json",
                "blob",
                "list"
            ]>>;
        }>, {
            readonly renamedFrom: "renamed_from";
            readonly maxLength: "max_length";
            readonly maxBytes: "max_bytes";
            readonly excludeFromReplication: "exclude_from_replication";
        }>>;
        readonly relationships: Schema.$Array<Schema.encodeKeys<Schema.Struct<{
            readonly on: Schema.optionalKey<Schema.encodeKeys<Schema.Struct<{
                readonly property: Schema.String;
                readonly targetProperty: Schema.String;
            }>, {
                readonly targetProperty: "target_property";
            }>>;
            readonly onDelete: Schema.optionalKey<Schema.decodeTo<Schema.Literals<readonly [
                "setNull",
                "cascade",
                "restrict"
            ]>, Schema.Literals<readonly [
                "set_null",
                "cascade",
                "restrict"
            ]>, never, never>>;
            readonly name: Schema.String;
            readonly to: Schema.String;
            readonly inverse: Schema.String;
            readonly cardinality: Schema.Literals<readonly [
                "one",
                "many"
            ]>;
            readonly optional: Schema.optionalKey<Schema.Boolean>;
            readonly ordered: Schema.optionalKey<Schema.Boolean>;
            readonly phrase: Schema.Tuple<readonly [
                Schema.String,
                Schema.String
            ]>;
            readonly description: Schema.String;
        }>, {
            readonly onDelete: "on_delete";
        }>>;
        readonly indexes: Schema.$Array<Schema.Struct<{
            readonly properties: Schema.$Array<Schema.String>;
            readonly unique: Schema.Boolean;
        }>>;
        readonly fields: Schema.Struct<{
            readonly properties: Schema.$Array<Schema.encodeKeys<Schema.Struct<{
                readonly column: Schema.optionalKey<Schema.String>;
                readonly scope: Schema.optionalKey<Schema.$Array<Schema.String>>;
                readonly name: Schema.String;
                readonly type: Schema.Literals<readonly [
                    "text",
                    "email",
                    "url",
                    "integer",
                    "number",
                    "boolean",
                    "date",
                    "timestamp",
                    "select",
                    "json",
                    "blob",
                    "list"
                ]>;
                readonly label: Schema.String;
                readonly description: Schema.optionalKey<Schema.String>;
                readonly optional: Schema.Boolean;
                readonly unique: Schema.Boolean;
                readonly managed: Schema.Boolean;
                readonly excludeFromReplication: Schema.optionalKey<Schema.Boolean>;
                readonly default: Schema.optionalKey<Schema.Codec<Schema.Json, Schema.Json, never, never>>;
                readonly display: Schema.optionalKey<Schema.String>;
                readonly renamedFrom: Schema.optionalKey<Schema.String>;
                readonly min: Schema.optionalKey<Schema.Number>;
                readonly max: Schema.optionalKey<Schema.Number>;
                readonly maxLength: Schema.optionalKey<Schema.Number>;
                readonly accept: Schema.optionalKey<Schema.$Array<Schema.String>>;
                readonly maxBytes: Schema.optionalKey<Schema.Number>;
                readonly options: Schema.optionalKey<Schema.$Array<Schema.Struct<{
                    readonly value: Schema.String;
                    readonly label: Schema.String;
                    readonly description: Schema.String;
                }>>>;
                readonly items: Schema.optionalKey<Schema.Literals<readonly [
                    "text",
                    "email",
                    "url",
                    "integer",
                    "number",
                    "boolean",
                    "date",
                    "timestamp",
                    "select",
                    "json",
                    "blob",
                    "list"
                ]>>;
            }>, {
                readonly renamedFrom: "renamed_from";
                readonly maxLength: "max_length";
                readonly maxBytes: "max_bytes";
                readonly excludeFromReplication: "exclude_from_replication";
            }>>;
            readonly relationships: Schema.$Array<Schema.encodeKeys<Schema.Struct<{
                readonly on: Schema.optionalKey<Schema.encodeKeys<Schema.Struct<{
                    readonly property: Schema.String;
                    readonly targetProperty: Schema.String;
                }>, {
                    readonly targetProperty: "target_property";
                }>>;
                readonly onDelete: Schema.optionalKey<Schema.decodeTo<Schema.Literals<readonly [
                    "setNull",
                    "cascade",
                    "restrict"
                ]>, Schema.Literals<readonly [
                    "set_null",
                    "cascade",
                    "restrict"
                ]>, never, never>>;
                readonly name: Schema.String;
                readonly to: Schema.String;
                readonly inverse: Schema.String;
                readonly cardinality: Schema.Literals<readonly [
                    "one",
                    "many"
                ]>;
                readonly optional: Schema.optionalKey<Schema.Boolean>;
                readonly ordered: Schema.optionalKey<Schema.Boolean>;
                readonly phrase: Schema.Tuple<readonly [
                    Schema.String,
                    Schema.String
                ]>;
                readonly description: Schema.String;
            }>, {
                readonly onDelete: "on_delete";
            }>>;
        }>;
    }>>;
}>
type RetainedStorage = typeof RetainedStorage.Type;
ReviewReviseInput

A member's request that the agent redraft a reply it held for review.

interface ReviewReviseInput {
    readonly review: string;
    readonly note: string;
}
ReviewReviseResult

The redraft the agent started: its result replaces the review only while it is the last one.

interface ReviewReviseResult {
    readonly revision: string;
}
ReviewSendInput

A member's approval of a reply the agent held for review: the draft, or their edit of it.

interface ReviewSendInput {
    readonly review: string;
    readonly text?: string;
    readonly to?: ReadonlyArray<string>;
    readonly cc?: ReadonlyArray<string>;
    readonly unlessNewer?: boolean;
    readonly files?: ReadonlyArray<{
        readonly entity: string;
        readonly id: string;
        readonly property: string;
        readonly revisionId: string;
    }>;
}
ReviewSendResult

What sending an approved reply did; `duplicate` when an earlier approval already sent it.

interface ReviewSendResult {
    readonly status: "sent" | "uncertain" | "failed";
    readonly text: string;
    readonly messageId: string | null;
    readonly duplicate: boolean;
    readonly files?: ReadonlyArray<AgentDraftFile>;
    readonly message?: string | null;
    readonly recipients?: {
        readonly to: ReadonlyArray<string>;
        readonly cc: ReadonlyArray<string>;
    };
}
Role

A business role: a named set of permissions. Members are given roles from the CLI or the app; an API key holds exactly the roles it was created with.

interface Role<Name extends string = string> {
    readonly [RoleTypeId]: typeof RoleTypeId;
    readonly name: Name;
    readonly description: string;
    readonly permissions: ReadonlyArray<string>;
    readonly scopes: ReadonlyArray<ScopedPermission>;
    readonly unusedScopes?: ReadonlyArray<ScopedPermission>;
}
RoleManifest
const RoleManifest: Schema.Struct<{
    readonly name: Schema.String;
    readonly description: Schema.String;
    readonly builtIn: Schema.Boolean;
    readonly permissions: Schema.optionalKey<Schema.$Array<Schema.String>>;
    readonly scopes: Schema.optionalKey<Schema.$Array<Schema.Struct<{
        readonly permission: Schema.String;
        readonly where: Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>;
    }>>>;
}>
type RoleManifest = typeof RoleManifest.Type;
RoleOptions
interface RoleOptions {
    readonly description: string;
    readonly permissions: ReadonlyArray<RolePermission>;
}
RolePermission

A role permission: `<entity>:<verb>`, or a scoped one, `{ permission, where }`.

type RolePermission = string | ScopedPermission;
RolePermissions

A role as permissions are computed from it: the declared role or its manifest entry.

interface RolePermissions {
    readonly name: string;
    readonly permissions?: ReadonlyArray<string> | undefined;
    readonly scopes?: ReadonlyArray<ScopedPermission> | undefined;
}
RunActionInput

What the HTTP service needs from the SQL runtime in `src/runtime`, bound to one ontology and one database. `src/runtime/service-binding.ts` implements it; the service only calls it, and tests substitute it.

interface RunActionInput {
    readonly runtime?: ActionRuntime;
    readonly entity: string;
    readonly action: string;
    readonly input: unknown;
    readonly principal: Principal;
    readonly options: {
        readonly validateOnly?: boolean;
        readonly idempotencyKey?: string;
        readonly createIntent?: string;
        readonly confirm?: {
            readonly locale: string;
        };
    };
    readonly afterCommit?: (committed: CommittedAction) => Effect.Effect<void>;
    readonly requestId?: string;
    readonly connections?: ConnectionTransport["Service"];
}
RuntimeIdentityConfig

Whom the service trusts as its runtime caller: Vercel OIDC tokens of the functions of this deployment's own project. The app's agent is a service of the same Vercel project as the ontology service, so `VERCEL_PROJECT_ID` pins exactly the deployment's own functions.

interface RuntimeIdentityConfig {
    readonly issuer: string;
    readonly audience: string;
    readonly projectId: string;
    readonly environment?: "production" | "preview";
}
RuntimeSource

Decoded only at a verified runtime boundary; ordinary action arguments never establish provenance.

const RuntimeSource: Schema.Union<readonly [
    Schema.Struct<{
        readonly provider: Schema.Literal<"telegram">;
        readonly channel: Schema.optionalKey<Schema.String>;
        readonly chat_id: Schema.String;
        readonly thread_id: Schema.String;
        readonly message_id: Schema.optionalKey<Schema.String>;
        readonly sent_at: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
        readonly reply_to_message_id: Schema.optionalKey<Schema.String>;
        readonly callback_query_id: Schema.optionalKey<Schema.String>;
        readonly sender: Schema.optionalKey<Schema.String>;
        readonly location: Schema.optionalKey<Schema.Struct<{
            readonly latitude: Schema.Number;
            readonly longitude: Schema.Number;
            readonly horizontal_accuracy: Schema.optionalKey<Schema.Number>;
            readonly live_period: Schema.optionalKey<Schema.Int>;
        }>>;
        readonly attachments: Schema.optionalKey<Schema.$Array<Schema.Struct<{
            readonly file_id: Schema.String;
            readonly file_unique_id: Schema.optionalKey<Schema.String>;
            readonly kind: Schema.Literals<readonly [
                "photo",
                "document",
                "voice",
                "audio",
                "video",
                "video_note",
                "sticker",
                "animation"
            ]>;
            readonly media_type: Schema.optionalKey<Schema.String>;
            readonly staged_id: Schema.String;
        }>>>;
    }>,
    Schema.Struct<{
        readonly provider: Schema.Literals<readonly [
            "slack",
            "whatsapp"
        ]>;
        readonly channel: Schema.optionalKey<Schema.String>;
        readonly chat_id: Schema.String;
        readonly thread_id: Schema.String;
        readonly kind: Schema.Literals<readonly [
            "private",
            "group"
        ]>;
        readonly peer: Schema.optionalKey<Schema.String>;
        readonly message_id: Schema.optionalKey<Schema.String>;
        readonly sender: Schema.optionalKey<Schema.String>;
    }>
]>
type RuntimeSource = typeof RuntimeSource.Type;
SIGN_IN_CODE_VALUE

The value only the sign-in code email (`signIn.codeEmail`) has besides the built-in ones.

const SIGN_IN_CODE_VALUE = "code"
SIGN_IN_METHODS

How a person signs in with an address. `code`: a six-digit code, for a member who has signed in with Neon Auth before, so their Neon Auth account exists. `link`: an emailed sign-in link, for everyone else; Neon Auth sends codes only to existing accounts, and a link creates the account.

const SIGN_IN_METHODS: readonly [
    "code",
    "link"
]
SIGN_IN_POLICIES

Who may become a member by signing in. `invited`: only a person whose email a member row already holds, created by an invitation or a role grant; anyone else is refused. `open`: anyone who signs in becomes a member holding only `member`, as a customer-facing app wants.

const SIGN_IN_POLICIES: readonly [
    "invited",
    "open"
]
SIGN_IN_RECORD_INTERVAL_MS

Every request authenticates, so recording each one would write a history row per request. A returning member's sign-in is recorded once the last one is older than a Neon Auth token's lifetime: about once per token, which is how often an active member authenticates afresh.

const SIGN_IN_RECORD_INTERVAL_MS: number
SIGN_UP_CHANNELS

The channels a stranger may sign up through. `email` is sign-in by email code in the app; `web` is a visitor who writes to the agent from one of the websites `signUp.origins` names, which `guest` supersedes; the others are a first private message to the agent, or opening the Telegram Mini App.

const SIGN_UP_CHANNELS: readonly [
    "email",
    "segmentstream",
    "telegram",
    "whatsapp",
    "web"
]
SYSTEM_PROPERTIES

Properties every entity has. They are never declared and cannot be redeclared.

const SYSTEM_PROPERTIES: readonly [
    "id",
    "created_at",
    "updated_at",
    "created_by",
    "updated_by"
]
ScopeFilter

Conditions on one field in a scope: a {@link import ("./query.js").FieldFilter} that may use `me`.

interface ScopeFilter {
    readonly eq?: ScopeValue;
    readonly ne?: ScopeValue;
    readonly in?: ReadonlyArray<Schema.Json> | MeReference;
    readonly isNull?: boolean;
    readonly contains?: string;
    readonly startsWith?: string;
    readonly gt?: number | string;
    readonly gte?: number | string;
    readonly lt?: number | string;
    readonly lte?: number | string;
    readonly between?: readonly [
        number | string,
        number | string
    ];
}
ScopeManifest

A scoped permission of a role: `<entity>:<verb>` and the `where` of the records it covers, in the wire form of a query on the entity, where `{ "$me": [...] }` stands for the caller or a path from them. Readers that do not enforce scopes may show the `where` or ignore it.

const ScopeManifest: Schema.Struct<{
    readonly permission: Schema.String;
    readonly where: Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>;
}>
type ScopeManifest = typeof ScopeManifest.Type;
ScopeValue

A value in a scope: JSON, as in any `where`, or `me` and paths from it.

type ScopeValue = Schema.Json | MeReference;
ScopeViolated

A write would leave a record outside the scope of the permission that allowed it: the record matched the role's `where` before the change and does not after it. The service answers 403 with the entity and the permission; the scope's `where` and the values stay out of the response.

class ScopeViolated extends ScopeViolated_base {
}
ScopeWhere

The `where` of a scoped permission: a {@link import ("./query.js").Where} of the permission's entity, in which `me` stands for the caller. A relationship compared with `me` or a path compares its key: `{ owner: me }`, `{ division: { in: me.staffMember.division } }`.

interface ScopeWhere {
    readonly and?: ReadonlyArray<ScopeWhere>;
    readonly or?: ReadonlyArray<ScopeWhere>;
    readonly not?: ScopeWhere;
    readonly [field: string]: ScopeFilter | {
        readonly some?: ScopeWhere;
        readonly none?: ScopeWhere;
        readonly every?: ScopeWhere;
    } | ScopeWhere | ReadonlyArray<ScopeWhere> | ScopeValue | undefined;
}
ScopedPermission

A role permission limited to the records its `where` matches. A scoped read filters the rows the caller sees; a scoped write checks the record before and after the change.

interface ScopedPermission {
    readonly permission: string;
    readonly where: ScopeWhere;
    readonly readsAll?: true;
}
SeenChat

A chat the agent saw, as `POST /api/ontology/agent/chats/seen` answers.

interface SeenChat {
    readonly id: string;
    readonly title: string;
    readonly description: string | null;
    readonly purpose: string | null;
    readonly whenToUse: string | null;
    readonly handled?: true;
}
SelectOption

A described value of a `select` property.

interface SelectOption {
    readonly value: string;
    readonly label: string;
    readonly description?: string;
}
SelectOptionInput

A `select` option: a plain string for quick use, or a described option.

type SelectOptionInput<V extends string> = V | {
    readonly value: V;
    readonly label?: string;
    readonly description: string;
};
SelectOptionManifest
const SelectOptionManifest: Schema.Struct<{
    readonly value: Schema.String;
    readonly label: Schema.String;
    readonly description: Schema.String;
}>
SignInCheck

Whether an address may sign in, and how, as `POST /api/ontology/sign-in/check` answers before the app sends an email. Under `invited`, only an active member's address is allowed. Under `open`, every address is allowed with `link`, so the answer reveals nothing about who has signed in.

type SignInCheck = {
    readonly allowed: false;
} | {
    readonly allowed: true;
    readonly method: SignInMethod;
};
SignInIdentity

A member verified by their token.

interface SignInIdentity {
    readonly provider: IdentityProvider;
    readonly oidcIdentity?: {
        readonly issuer: string;
        readonly subject: string;
    };
    readonly subject: string;
    readonly email?: string;
    readonly name?: string;
}
SignInManifest
const SignInManifest: Schema.encodeKeys<Schema.Struct<{
    readonly browser: Schema.optionalKey<Schema.encodeKeys<Schema.Struct<{
        readonly methods: Schema.$Array<Schema.String>;
        readonly primary: Schema.String;
        readonly autoRedirect: Schema.Boolean;
        readonly local: Schema.optionalKey<Schema.Struct<{
            readonly port: Schema.Int;
        }>>;
    }>, {
        readonly autoRedirect: "auto_redirect";
    }>>;
    readonly policy: Schema.String;
    readonly channels: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Unknown>>;
    readonly onNewUser: Schema.optionalKey<Schema.String>;
    readonly codeLink: Schema.optionalKey<Schema.Boolean>;
    readonly cli: Schema.optionalKey<Schema.Boolean>;
    readonly signUp: Schema.optionalKey<Schema.Struct<{
        readonly channels: Schema.$Record<Schema.String, Schema.Unknown>;
        readonly origins: Schema.optionalKey<Schema.$Array<Schema.String>>;
    }>>;
    readonly onSignUp: Schema.optionalKey<Schema.String>;
    readonly guest: Schema.optionalKey<Schema.encodeKeys<Schema.Struct<{
        readonly openOnInvite: Schema.optionalKey<Schema.$Array<Schema.String>>;
        readonly byChannel: Schema.optionalKey<Schema.$Record<Schema.String, Schema.$Array<Schema.String>>>;
        readonly channels: Schema.$Array<Schema.String>;
        readonly origins: Schema.$Array<Schema.String>;
        readonly botCheck: Schema.optionalKey<Schema.Struct<{
            readonly scheme: Schema.String;
            readonly connection: Schema.optionalKey<Schema.String>;
            readonly input: Schema.optionalKey<Schema.String>;
            readonly secret: Schema.optionalKey<Schema.String>;
        }>>;
        readonly confirmations: Schema.optionalKey<Schema.Boolean>;
    }>, {
        readonly botCheck: "bot_check";
    }>>;
    readonly invitationEmail: Schema.optionalKey<Schema.String>;
    readonly linkEmail: Schema.optionalKey<Schema.String>;
    readonly codeEmail: Schema.optionalKey<Schema.String>;
}>, {
    readonly onNewUser: "on_new_user";
    readonly codeLink: "code_link";
    readonly signUp: "sign_up";
    readonly onSignUp: "on_sign_up";
    readonly invitationEmail: "invitation_email";
    readonly linkEmail: "link_email";
    readonly codeEmail: "code_email";
}>
type SignInManifest = typeof SignInManifest.Type;
SignInMethod
type SignInMethod = (typeof SIGN_IN_METHODS)[number];
SignInOptions

How people become members of the app. Email and channel admission are independent.

interface SignInOptions {
    readonly policy: SignInPolicy;
    readonly browser?: BrowserSignInOptions;
    readonly channels?: Readonly<Partial<Record<ChannelProvider, SignInPolicy>>>;
    readonly onNewUser?: string;
    readonly codeLink?: boolean;
    readonly cli?: boolean;
    readonly invitationEmail?: string;
    readonly linkEmail?: string;
    readonly codeEmail?: string;
}
SignInPolicy
type SignInPolicy = (typeof SIGN_IN_POLICIES)[number];
SignUpChannel
type SignUpChannel = (typeof SIGN_UP_CHANNELS)[number] | WorkspaceSignUpChannel;
SignUpOptions

Where a stranger may become a user, and the roles they are given. A channel not listed admits only invited or paired people. A user created by sign-up holds exactly these roles, granted like any other and revocable one person at a time, and never the `member` baseline of invited people.

interface SignUpOptions<R = unknown> {
    readonly channels: ReadonlyArray<SignUpChannel>;
    readonly roles: ReadonlyArray<R>;
    readonly byChannel?: Readonly<Partial<Record<SignUpChannel, ReadonlyArray<R>>>>;
    readonly origins?: ReadonlyArray<string>;
}
SortDirection
const SortDirection: Schema.Literals<readonly [
    "asc",
    "desc"
]>
type SortDirection = typeof SortDirection.Type;
SqlOntologyRuntime

The SQL runtime: the {@link OntologyRuntime } contract for action handlers, plus the paged reads the HTTP API serves.

interface SqlOntologyRuntime extends OntologyRuntimeService {
    readonly query: (input: {
        readonly entity: string;
        readonly query: Query;
        readonly reader?: ScopeReader;
    }) => Effect.Effect<QueryResult<StoredRecord>, InvalidQuery>;
    readonly get: (input: {
        readonly entity: string;
        readonly id: string;
        readonly forUpdate?: boolean;
        readonly reader?: ScopeReader;
    }) => Effect.Effect<StoredRecord, NotFound>;
    readonly related: (input: {
        readonly entity: string;
        readonly id: string;
        readonly relationship: string;
        readonly query?: Query;
        readonly reader?: ScopeReader;
    }) => Effect.Effect<QueryResult<StoredRecord>, InvalidQuery | NotFound>;
    readonly history: (input: {
        readonly entity: string;
        readonly id: string;
        readonly after?: string;
        readonly limit?: number;
        readonly reader?: ScopeReader;
    }) => Effect.Effect<QueryResult<HistoryEntry>, InvalidQuery | NotFound>;
    readonly members: {
        readonly grantRoles: (input: {
            readonly id: string;
            readonly roles: ReadonlyArray<string>;
        }) => Effect.Effect<StoredRecord, UnknownRole | NotFound>;
        readonly revokeRoles: (input: {
            readonly id: string;
            readonly roles: ReadonlyArray<string> | "all";
        }) => Effect.Effect<StoredRecord, UnknownRole | NotFound>;
        readonly invite: (input: {
            readonly email: string;
            readonly name?: string | undefined;
            readonly roles?: ReadonlyArray<string> | undefined;
        }) => Effect.Effect<StoredRecord, UnknownRole | Conflict>;
        readonly setActive: (input: {
            readonly id: string;
            readonly active: boolean;
        }) => Effect.Effect<StoredRecord, NotFound>;
    };
    readonly identities: {
        readonly attest: (input: AttestIdentityInput) => Effect.Effect<StoredRecord, ActionRejected | Conflict | NotFound>;
        readonly attach: (input: AttachIdentityInput) => Effect.Effect<StoredRecord, ActionRejected | Conflict | NotFound>;
        readonly revoke: (input: {
            readonly id: string;
        }) => Effect.Effect<StoredRecord, NotFound>;
    };
}
StageFile
interface StageFile<E, R> {
    readonly target: FileTarget;
    readonly key: string;
    readonly recordId?: string;
    readonly createIntent?: string;
    readonly filename: string;
    readonly contentType: string;
    readonly size: number;
    readonly action?: string;
    readonly open: () => Effect.Effect<Stream.Stream<Uint8Array, E, R>, E, R>;
}
StorageNames

The names a database's schema holds, from `readStorageNames`.

interface StorageNames {
    readonly names: ReadonlyArray<string>;
    readonly columns: Readonly<Record<string, ReadonlyArray<string>>>;
}
StorageType

How a record field is stored: a property type, or a UUID for ids and `<relationship>_id` keys.

type StorageType = PropertyType | "uuid";
StoredFile

A stored file revision read back, with its bytes.

interface StoredFile {
    readonly file: BlobValue;
    readonly bytes: Uint8Array;
}
StoredRecord

A record as the runtime returns it, before an entity handle gives it the entity's type.

type StoredRecord = Readonly<Record<string, unknown>>;
StoredRecordMismatch

A stored record does not match its entity's definition. A defect: the schema and data diverged.

class StoredRecordMismatch extends StoredRecordMismatch_base {
}
StoredRolesListing

The role names a listing leaves out of a member's or an API key's stored roles: those {@link implicitRoleNames } reserves, and while nobody says, the earlier `member` and `feedback_reporter`.

interface StoredRolesListing {
    readonly hiddenRoles?: ReadonlyArray<string>;
}
StoredValues

Values to write, keyed by property and relationship name.

type StoredValues = Readonly<Record<string, unknown>>;
StubRequest

A call as a stub receives it.

interface StubRequest extends ConnectionCall {
    readonly connection: string;
    readonly text: string;
}
StubResponse

A stubbed response for {@link Connections.test}.

interface StubResponse {
    readonly status?: number;
    readonly headers?: ConnectionHeaders;
    readonly json?: unknown;
    readonly text?: string;
}
StubSelection

Whose credential a call to an owned connection uses, as a stub receives it: `undefined` for a shared connection's call.

interface StubSelection {
    readonly owner: string;
    readonly call: ConnectionCallKind;
}
SystemFields

Fields every record has. They are never declared.

interface SystemFields {
    readonly id: string;
    readonly createdAt: string;
    readonly updatedAt: string;
    readonly createdBy: string | null;
    readonly updatedBy: string | null;
}
SystemProperty
type SystemProperty = "id" | "createdAt" | "updatedAt" | "createdBy" | "updatedBy";
TOOLSET_LOCK_VERSION

The lock format `segmentstream connection mcp lock` writes.

const TOOLSET_LOCK_VERSION = 1
TestConnectionsOptions

Options of {@link Connections.test}.

interface TestConnectionsOptions {
    readonly owner?: string;
    readonly call?: ConnectionCallKind;
}
TextOptions
interface TextOptions extends PropertyOptions<string> {
    readonly maxLength?: number;
}
ToolHandler
type ToolHandler = (invocation: ToolInvocation) => Promise<ToolResult>;
ToolInvocation

Trusted workspace code runs after caller authorization, for every MCP entry point. call() may invoke this tool or another permitted read in the same locked toolset. Fixed arguments are applied by the transport. Raw provider results remain inside the hook.

interface ToolInvocation {
    readonly principal: Principal;
    readonly name: string;
    readonly input: Readonly<Record<string, unknown>>;
    readonly signal: AbortSignal;
    readonly call: (name: string, input: Readonly<Record<string, unknown>>) => Promise<ToolResult>;
    readonly recordCost: (costUsd: number) => Promise<void>;
}
Toolset

A provider's MCP tools served by the ontology: see {@link toolset}.

interface Toolset<Name extends string = string> {
    readonly [ToolsetTypeId]: typeof ToolsetTypeId;
    readonly name: Name;
    readonly definition: ToolsetDefinition;
}
ToolsetDefinition
interface ToolsetDefinition {
    readonly connection: AnyConnectionHandle;
    readonly api: string;
    readonly lock: unknown;
    readonly description: string;
    readonly tools?: Readonly<Record<string, ToolsetToolOptions>>;
}
ToolsetLock

The pinned tools of one MCP API of a connection, written by `segmentstream connection mcp lock` and committed with the workspace. The ontology's catalog is built from it, so a provider's change reaches members only through a reviewed commit and a deploy.

const ToolsetLock: Schema.Struct<{
    readonly version: Schema.Literal<1>;
    readonly connection: Schema.String;
    readonly api: Schema.String;
    readonly url: Schema.String;
    readonly protocolVersion: Schema.String;
    readonly server: Schema.optionalKey<Schema.Struct<{
        readonly name: Schema.String;
        readonly version: Schema.optionalKey<Schema.String>;
    }>>;
    readonly tools: Schema.$Array<Schema.Struct<{
        readonly name: Schema.String;
        readonly access: Schema.Literals<readonly [
            "read",
            "write"
        ]>;
        readonly fixed: Schema.$Record<Schema.String, Schema.Union<readonly [
            Schema.String,
            Schema.Number,
            Schema.Boolean
        ]>>;
        readonly description: Schema.String;
        readonly inputSchema: Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>;
        readonly outputSchema: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>>;
        readonly annotations: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>>;
    }>>;
}>
type ToolsetLock = typeof ToolsetLock.Type;
ToolsetLockTool

One locked tool: the declared access and fixed values, and what the server said about it.

const ToolsetLockTool: Schema.Struct<{
    readonly name: Schema.String;
    readonly access: Schema.Literals<readonly [
        "read",
        "write"
    ]>;
    readonly fixed: Schema.$Record<Schema.String, Schema.Union<readonly [
        Schema.String,
        Schema.Number,
        Schema.Boolean
    ]>>;
    readonly description: Schema.String;
    readonly inputSchema: Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>;
    readonly outputSchema: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>>;
    readonly annotations: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>>;
}>
type ToolsetLockTool = typeof ToolsetLockTool.Type;
ToolsetToolOptions

Workspace presentation and handling of an existing provider tool.

interface ToolsetToolOptions {
    readonly handle?: ToolHandler;
    readonly description?: string;
}
TriggerFunction

A synchronous function of an action trigger: no `await`, no effects, no entity handles. It runs inside the action's transaction and reads only the event and the record.

type TriggerFunction<Event, T, Out> = (event: Event, record: TriggerRecord<T>) => Out;
TriggerRecord

The record of the trigger's entity an action edited: its id, and the stored record before and after the action. `before` is `undefined` on a create, `after` on a delete. Only stored properties and relationship ids; warehouse-backed properties are absent.

interface TriggerRecord<T = unknown> {
    readonly record: string;
    readonly before: T | undefined;
    readonly after: T | undefined;
}
queryFields

The fields of an entity's records, in record order. A value-matched relationship has no `<relationship>_id`: its reference is the property named in `on`.

function queryFields(entity: EntityManifest): ReadonlyArray<QueryField>;
queryJsonSchema

The JSON Schema (draft 2020-12) of an entity's queries, for MCP tools, OpenAPI and the console.

function queryJsonSchema(manifest: OntologyManifest, entityName: string, warehouseRecords?: boolean): JsonSchemaObject;
queryResultJsonSchema

The JSON Schema (draft 2020-12) of a page of an entity's records.

function queryResultJsonSchema(manifest: OntologyManifest, entityName: string): JsonSchemaObject;
queryResultSchema

A page of records described by `record`.

function queryResultSchema<S extends Schema.Top>(record: S): Schema.Struct<{
    readonly items: Schema.$Array<S>;
    readonly nextCursor: Schema.NullOr<Schema.String>;
}>;
readCatalog

The manifest recorded by the last applied migration, or undefined when none was applied. It is decoded with the manifest contract, so fields this SDK does not know are dropped.

const readCatalog: (input: CatalogInput) => Effect.Effect<OntologyManifest | undefined, CatalogInvalid | SqlError>
readHistoryActivityIndexes

Only valid, complete covering indexes satisfy the upgrade; failed builds are retried.

const readHistoryActivityIndexes: (input: CatalogInput) => Effect.Effect<ReadonlySet<string>, SqlError>
readLocalConnectionContext

Reads the local runtime context from the pipe `segmentstream exec` opened, once, and removes the variable so that child processes cannot read it again. `undefined` when the CLI passed none.

function readLocalConnectionContext(environment: Record<string, string | undefined>): LocalConnectionContext | undefined;
readRetainedStorage

The storage the catalog records as kept: what removals retained, which declaring the entity or

const readRetainedStorage: (input: CatalogInput) => Effect.Effect<RetainedStorage, CatalogInvalid | SqlError>
readRuntimeTables

The runtime tables the database has, for `planMigration`'s `existingTables`: a database that an earlier SDK migrated lacks the tables added since. A grants table without app-session binding is reported incomplete so the idempotent OAuth DDL also upgrades an unchanged manifest, and so is an action attribution table without `chat`, an API keys table without `delegation` and an attachments table whose source check predates one of {@link ATTACHMENT_SOURCES }, that lacks the view of its earlier name or that cannot keep observed files ({@link OBSERVED_ATTACHMENTS_INDEX }), which the idempotent attribution, API key and attachment DDL add and widen. A table still named {@link LEGACY_ATTACHMENTS_TABLE } is reported under that name, so that the plan renames it. {@link WORKFLOW_START_OWNERS }, which names no table, is reported when `_workflow_starts` has the run owner columns, which the plan adds for an ontology that declares an owned workflow. Only for a `target` that declares one does the query look for them; every other ontology's is unchanged.

const readRuntimeTables: (input: CatalogInput & {
    readonly target?: Pick<OntologyManifest, "connections" | "workflows"> | undefined;
}) => Effect.Effect<ReadonlySet<string>, SqlError>
readScope

The records of `entity` a holder reads: `undefined` when it holds no scoped permission or reads the entity unscoped, else the {@link effectiveScope} of `<entity>:read`. A holder without the read permission gets `undefined` too: whether it may read at all is the permission check's decision.

function readScope(entity: string, holder: PermissionHolder): ScopeWhere | undefined;
readStorageNames

The names in the current schema, for `planMigration`'s `existingStorage`: relations and types, which share one namespace, and the columns of each table. Names starting with `_`, which no entity's storage uses, are left out.

const readStorageNames: (input: CatalogInput) => Effect.Effect<StorageNames, SqlError>
reconcileWorkflowUsers

Brings the workflow users of the workspace in line with the ontology's workflows, as deploy does in the migration's transaction: each declared workflow's user is created if missing, reactivated and given exactly the workflow's role; a user whose workflow is no longer declared is deactivated, so its runs are refused and history keeps its name. Repeating it changes nothing. Database failures, including those of the history writes, fail with their `SqlError`.

function reconcileWorkflowUsers(ontology: Ontology, input: {
    readonly workspaceId: string;
}): Effect.Effect<void, SqlError, SqlClient.SqlClient>;
rel

Relationship constructors.

const rel: {
    readonly one: typeof one;
    readonly many: typeof many;
}
renderCatalog

Renders the catalog as prose for agents and people: each entity with its properties, both directions of its relationships and its actions, then the roles with their permissions and the `where`, in wire form, of each scoped one. Without a reader, each action and each entity's reads say which permission they require and which roles grant it; with one, only the actions the reader may run are listed. A pure function of the manifest, so the console, the CLI and the service describe the same ontology.

function renderCatalog(manifest: OntologyManifest, options?: RenderOptions): string;
requireDeploymentCapability

Recheck the deadline on every admission, including a warm process and cached sessions.

function requireDeploymentCapability(deployment: DeploymentObservation, capability?: keyof DeploymentCapabilities, now?: number): void;
resolveAction

The entity's authored action of that name with the permission it requires, or else its generated one with the permissions named after it.

function resolveAction(ontology: Ontology, entityName: string, actionName: string): FoundAction | undefined;
resolveApiKeyCredential

An API key's principal and whether it acts with delegation; see {@link resolvePrincipalByApiKey}.

function resolveApiKeyCredential(ontology: Ontology, key: string): Effect.Effect<ApiKeyCredential, PrincipalRejected, SqlClient.SqlClient>;
resolveChannelIdentity

Shared verified admission for agents and channel-app adapters; never expose trusted inputs to browsers.

function resolveChannelIdentity(ontology: Ontology, sql: SqlClient.SqlClient, input: ResolveIdentityInput): Effect.Effect<AgentResolution, never, never>;
resolveChannelSignIn

Call only after verifying a channel-app assertion. Shares admission, limits and onboarding with agents.

function resolveChannelSignIn(ontology: Ontology, sql: SqlClient.SqlClient, input: ChannelSignInInput): Effect.Effect<AgentResolution, never, never>;
resolvePrincipalByApiKey

The principal of an API key, with the permissions its roles have in the ontology. Unknown and revoked keys and inactive users are rejected. A key with delegation resolves to its user too: the service authenticates its requests as the member they name, and refuses them otherwise.

function resolvePrincipalByApiKey(ontology: Ontology, key: string): Effect.Effect<Principal, PrincipalRejected, SqlClient.SqlClient>;
resolvePrincipalByIdentity

The principal of a member signed in with a verified token. On first sign-in the member's `user` is linked by email when someone invited them; a person nobody invited is rejected as `not_invited` under the `invited` policy and becomes a member holding only `member` under `open`. Every sign-in that lets the member in sets `lastSignInAt`, at most once per {@link SIGN_IN_RECORD_INTERVAL_MS}, so history keeps it. If the User row is busy, recording is deferred to a later request instead of delaying authentication. Inactive users are rejected.

function resolvePrincipalByIdentity(ontology: Ontology, claims: IdentityClaims): Effect.Effect<Principal, PrincipalRejected, SqlClient.SqlClient>;
resolveWorkflowUser

Resolve the keyless service user a workflow's runs act as: one per declared workflow, holding exactly the workflow's role, named by `workflows:<workspace id>:<workflow name>`. Deploy creates it; a run before that creates it here. It never rewrites roles: a user whose roles are not exactly the declared role is rejected (`role_mismatch`) until a deploy reconciles it. A workflow the serving ontology does not declare is rejected, as is an inactive user. Its permissions are what `member` and its role grant, and every action checks them as for any caller.

function resolveWorkflowUser(ontology: Ontology, input: {
    readonly workspaceId: string;
    readonly workflow: string;
}): Effect.Effect<Principal, PrincipalRejected, SqlClient.SqlClient>;
revokeApiKey

Revokes an API key. Revoking it again changes nothing.

function revokeApiKey(input: {
    readonly id: string;
}): Effect.Effect<void, never, SqlClient.SqlClient>;
revokeMemberRoles

Removes roles from the member with this email, or every assigned role. The member stays, so history keeps their name. Roles the ontology no longer declares can be removed too.

function revokeMemberRoles(ontology: Ontology, input: {
    readonly email: string;
    readonly roles: ReadonlyArray<string> | "all";
}): Effect.Effect<MemberSummary, UnknownRole | MemberNotFound, SqlClient.SqlClient>;
revokeMemberSessions

Session revocation integration point for every channel-app issuer (including Mini Apps).

function revokeMemberSessions(sql: SqlClient.SqlClient, userId: string): Effect.Effect<void, import("effect/unstable/sql/SqlError").SqlError, never>;
role
function role<const Name extends string>(name: Name, options: RoleOptions): Role<Name>;
roleEntries

A role's entries rebuilt from its permissions and scopes, as a manifest lists them: each scoped permission at its place, once per scope. A scope whose permission the list lacks comes last.

function roleEntries(permissions: ReadonlyArray<string>, scopes: ReadonlyArray<ScopedPermission>): ReadonlyArray<RolePermission>;
rolePermissions

The permissions and scopes of a role's entries. A string is kept as written, even twice, so that an ontology without scoped permissions lists exactly what it declares; a scoped entry adds its permission once, and is dropped into `unusedScopes` when the role grants the same permission unscoped, in any case. Anything else is kept for `check` to report.

function rolePermissions(entries: ReadonlyArray<RolePermission>): {
    readonly permissions: ReadonlyArray<string>;
    readonly scopes: ReadonlyArray<ScopedPermission>;
    readonly unusedScopes?: ReadonlyArray<ScopedPermission>;
};
rolesGranting

The roles whose permissions cover `required`, by name.

function rolesGranting(roles: ReadonlyArray<RolePermissions>, required: string): ReadonlyArray<string>;
runAction

Runs an action the way every action runs, authored or generated: 1. decode the input with the action's schema; issues are returned, not raised; 2. check that the principal's permissions cover the action's (PermissionDenied); 3. with `validateOnly`, stop, unless the action is generated, the principal's permission for it is scoped and the input holds no upload: then run step 6 in a transaction that is always rolled back, and answer a NotFound or ScopeViolated of the writes as a validation issue; 4. reauthorize and replay a committed blob action, if its idempotency key matches; otherwise run `prepare`, when the action has one, without a transaction: reads and the declared connections only, under {@link PREPARE_TIMEOUT}; 5. without a handler, answer with what `prepare` returned; when a trigger matches the action, make sure through the {@link WorkflowStarter } in context that a recovery run will sweep after the transaction's deadline, and refuse the action with WorkflowRecoveryUnavailable when it cannot; 6. open a transaction and run the handler with what `prepare` returned and the runtime, which records history rows for every write, under one action id, with `created_by`/`updated_by` set to the principal; 7. evaluate the action triggers that match the action, and insert the starts they decide, in the same transaction: a trigger function that throws rolls the action back, an input its workflow does not accept fails it with TriggerInputInvalid; 8. commit, or roll back on any failure, defect or interruption; an action explicitly declared retryOnDeadlock may repeat steps 6–8 after a confirmed deadlock rollback, with fresh state; 9. start the decided runs through the {@link WorkflowStarter } in context, then run the after-commit effects, outside the transaction. Database failures are defects.

function runAction<R = never>(ontology: Ontology, request: ActionRequest<R>): Effect.Effect<ActionOutcome, ActionError | ConnectionError | UnknownAction | TriggerInputInvalid | WorkflowRecoveryUnavailable, SqlClient.SqlClient | R>;
runBlobStorageMaintenance

Scheduler capability that survives removal of blob declarations. Never reads file contents.

function runBlobStorageMaintenance(input: {
    readonly databaseUrl: Redacted.Redacted<string>;
    readonly binding: Redacted.Redacted<BlobStorageBinding>;
    readonly limit?: number;
}): Effect.Effect<{
    removed: number;
    hasMore: boolean;
}, import("effect/unstable/sql/SqlError").SqlError | BlobStorageError, never>;
runNewUserHook

Runs after admission commits, before a model turn or app session. True means retry pending. A user `signUp` created runs `onSignUp` with the roles they hold; a user an open `signIn.channels` created runs `onNewUser` with only `member`. Workload authority never applies.

function runNewUserHook(ontology: Ontology, sql: SqlClient.SqlClient, principal: Principal): Effect.Effect<boolean>;
scopesOf

The scoped entries of the roles a principal holds, in the order the ontology declares them, without the dead ones: those a held role grants unscoped, by the same permission or through a wildcard, since an unscoped grant covers every record. With {@link permissionsOf}, what a principal's `scopes` holds; {@link effectiveScope} stays the authority either way.

function scopesOf(roles: ReadonlyArray<RolePermissions>, held: ReadonlyArray<string>): ReadonlyArray<ScopedPermission>;
serveWorkflowCallback

Answers one Workflow SDK queue delivery with the SDK's flow handler, as `ontologyWorkflows()` mounts it. A request that is not a delivery of the ontology's queue to the exact route is answered 404 without reaching the SDK. Before the handler runs, `warm` builds this instance's ontology service if nothing has bound the runtime yet; a failure to start throws, so the delivery fails and the queue retries it. The request's OIDC token stays available to the steps.

function serveWorkflowCallback(request: Request, handler: (request: Request) => Promise<Response>, options: WorkflowCallbackOptions): Promise<Response>;
setMemberActive

Deactivates or reactivates a member, as `user.deactivate` and `user.reactivate` do, as a platform write. An inactive member keeps their roles and history, and the service rejects their requests. Deactivation also revokes sessions, including repeated requests.

function setMemberActive(ontology: Ontology, input: MemberKey & {
    readonly active: boolean;
}): Effect.Effect<MemberSummary, MemberNotFound, SqlClient.SqlClient>;
setMemberBlocked

Sticky blocking is independent of activation and survives unpairing or another identity.

function setMemberBlocked(ontology: Ontology, input: {
    readonly id: string;
    readonly blocked: boolean;
}): Effect.Effect<MemberSummary, MemberNotFound, SqlClient.SqlClient>;
setUserRoles

Replaces the roles a user was given. Members hold `member` whatever is assigned.

function setUserRoles(ontology: Ontology, input: {
    readonly userId: string;
    readonly roles: ReadonlyArray<string>;
}): Effect.Effect<void, UnknownRole, SqlClient.SqlClient>;
signInPolicyOf

The sign-in policy a manifest declares. A manifest without one, or with a policy this reader does not know, reads as `invited`: the closed choice, so that a misread never lets strangers in.

function signInPolicyOf(manifest: Pick<OntologyManifest, "signIn">): SignInPolicy;
signUpOrigin
const signUpOrigin: typeof websiteOrigin
signUpOriginsOf

The websites whose visitors may sign up on `web`, by origin: empty while `web` is closed to sign-up. Entries that are not an origin `signUp.origins` accepts are left out.

function signUpOriginsOf(manifest: Pick<OntologyManifest, "signIn">): ReadonlyArray<string>;
signUpRolesOf

The wire names of the roles a stranger who signs up on this channel is given, or `undefined` when the channel is closed to sign-up: not a channel this reader knows, or no well-formed entry.

function signUpRolesOf(manifest: Pick<OntologyManifest, "signIn">, channel: string): ReadonlyArray<string> | undefined;
sqlAgentStore

The agent store on the runtime's agent tables, as `ontology_app`. Expiry is the database's `now()`; a pairing is consumed with one `UPDATE … WHERE "consumed_at" IS NULL`, so two concurrent approvals cannot both succeed. Ids that are not UUIDs find nothing rather than fail the cast. Chats the agent sees are `agent_chat` records, written as the platform with history. Holding a reply is admitted, bounded and starts the workflows whose triggers on `agent_draft` fire for it as an action is and does, with the `ActionTransactions` and `WorkflowStarter` it runs with.

function sqlAgentStore(ontology: Ontology, sql: SqlClient.SqlClient): AgentStore;
sqlServiceRuntime

The default runtime of `createOntologyService`: the SQL runtime on the workspace database.

const sqlServiceRuntime: OntologyServiceRuntime
takeoverChannelsOf

The channels whose private chats staff may take over from the agent; empty without any.

function takeoverChannelsOf(manifest: Pick<OntologyManifest, "inbox">): ReadonlySet<string>;
toolset

Serves the tools a connection's MCP API declares, as `connections/connections.py` lists them and the lock pins them, to every client of the ontology's MCP server. Each tool becomes the MCP tool `<toolset>_<tool>`, which a member may see and call with the permission `<toolset>:<tool>`. A toolset has no records: no table, `find`, `get` or `history`. `lock` is the JSON of `ontology/mcp/<key>.<api>.lock.json`, imported with `{ type: "json" }`: ```ts export const GitHub = toolset("github", { connection: github, api: "mcp", lock: githubLock, description: "The platform's source repository: code, commits, pull requests and issues.", }); ```

function toolset<const Name extends string>(name: Name, definition: ToolsetDefinition): Toolset<Name>;
triggerPath

The route Vercel calls for a cron trigger: `/api/ontology/workflows/<workflow>/triggers/<trigger>`.

function triggerPath(workflow: string, trigger: string): string;