Skip to content
SegmentStream/ Docs

Loading documentation…

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

@segmentstream/ontology · E–H

85 public exports from @segmentstream/ontology.

Public exports

EARLIER_QUERY_METRICS_ROUTE

The earlier name of the ontology service's metric query routes, `/api/ontology/aggregate` and `/api/ontology/<entity>/aggregate`, which older app SDKs still call: both are served, and the name stays reserved for entities and metrics of the model.

const EARLIER_QUERY_METRICS_ROUTE = "aggregate"
EMAIL_MARKUP_VALUES

The values that may stand inside a tag, such as in an `href`: the platform's own addresses and the workspace's name. Every other value (the recipient's name, the code, what an action passes) stands only in text, where escaping keeps it text, so it can never become an address or add an attribute.

const EMAIL_MARKUP_VALUES: readonly [
    "link",
    "app.url",
    "app.mcpUrl",
    "workspace.name"
]
ENVIRONMENT_VARIABLES

The environment of the workspace deployment's ontology service.

const ENVIRONMENT_VARIABLES: {
    readonly databaseUrl: "SEGMENTSTREAM_ONTOLOGY_DATABASE_URL";
    readonly segmentstreamUrl: "SEGMENTSTREAM_URL";
    readonly applicationId: "SEGMENTSTREAM_APPLICATION_ID";
    readonly workspaceId: "SEGMENTSTREAM_WORKSPACE_ID";
    readonly organizationId: "SEGMENTSTREAM_ORGANIZATION_ID";
}
EVAL_TOKEN_DEFAULT_SECONDS

How long an eval session's token works unless the platform asks for less: thirty minutes.

const EVAL_TOKEN_DEFAULT_SECONDS: number
EVAL_TOKEN_MAX_SECONDS

The longest an eval session's token works: an hour, and never past the preview's expiry.

const EVAL_TOKEN_MAX_SECONDS: number
EarlierFreshMetricQueryOptions

A fresh metric query that names its metrics `measures`, as workspace code written for an earlier SDK does.

type EarlierFreshMetricQueryOptions<R, L extends string, Metric extends string, Group extends string> = Omit<FreshMetricQueryOptions<R, L, Metric, Group>, "metrics"> & {
    readonly measures: readonly [
        Metric,
        ...Metric[]
    ];
};
EarlierMetricsField

The earlier spelling of an entity's or the model's `metrics`, which declarations still accept.

interface EarlierMetricsField<M> {
    readonly measures?: M;
}
EarlierMetricsName

A warehouse-backed entity's metrics under the name released app SDKs read for their types.

interface EarlierMetricsName<M> {
    readonly measures: M;
}
EarlierName

A name an SDK release replaced.

interface EarlierName {
    readonly earlier: string;
    readonly current: string;
}
EarlierQueryMetricsName

An entity handle's `queryMetrics` under its earlier name.

interface EarlierQueryMetricsName<P, R, M> {
    aggregate<const Metric extends keyof M & string, const Group extends MetricQueryGroupKey<P, R> = never>(options: FreshMetricQueryInput<P, R, Metric, Group>): Effect.Effect<ReadonlyArray<FreshMetricQueryRow<EntityRecord<P, R>, Group, Metric>>, never, OntologyReads>;
}
Edit

A change an action made to one record, as the action response lists it. A link between two records is an edit of each, keyed by the relationship's name on that side.

const Edit: Schema.Struct<{
    readonly entity: Schema.String;
    readonly id: Schema.String;
    readonly kind: Schema.Literals<readonly [
        "create",
        "update",
        "delete",
        "link",
        "unlink"
    ]>;
    readonly changes: Schema.$Record<Schema.String, Schema.Struct<{
        readonly before: Schema.Codec<Schema.Json, Schema.Json, never, never>;
        readonly after: Schema.Codec<Schema.Json, Schema.Json, never, never>;
    }>>;
}>
type Edit = typeof Edit.Type;
EditKind
const EditKind: Schema.Literals<readonly [
    "create",
    "update",
    "delete",
    "link",
    "unlink"
]>
type EditKind = typeof EditKind.Type;
EmailDocument

An email the workspace lays out entirely itself: its subject, its HTML and its plain-text part, with `{{value}}` placeholders the platform fills and nothing else of the platform's. The HTML links to `{{link}}`, the sign-in link, which is what the email is for; values are escaped in the HTML and kept as they are in the text. Inside its tags only `{{link}}`, `{{app.url}}`, `{{app.mcpUrl}}` and `{{workspace.name}}` may stand: every other value goes in text, so no value an action passes becomes an address or an attribute. The HTML may not run code or post forms, and it links only to `https:`, `mailto:` and `tel:` addresses, `#` anchors, or the app's own addresses.

interface EmailDocument {
    readonly subject: string;
    readonly html: string;
    readonly text: string;
    readonly replyTo?: string;
}
EmailLayout

An email as fields the platform lays out in its neutral design. Every field is plain text, in which `{{name}}` stands for a value the action passes, and `{{member.name}}`, `{{member.firstName}}`, `{{workspace.name}}`, `{{app.url}}` and `{{app.mcpUrl}}` for the recipient, the workspace, the app's address and its MCP server's. The platform lays the fields out, escapes them and adds the plain-text part; `action` labels the one button, which signs the person in and opens the path the action names. A field whose text is empty once filled in is left out.

interface EmailLayout {
    readonly subject: string;
    readonly eyebrow?: string;
    readonly heading: string;
    readonly card?: {
        readonly title: string;
        readonly detail?: string;
    };
    readonly note?: string;
    readonly paragraphs?: ReadonlyArray<string>;
    readonly action: string;
    readonly sections?: ReadonlyArray<EmailSection>;
    readonly footer?: string;
    readonly replyTo?: string;
}
EmailSection

A box below an email's button: a title, a line of text, a value to copy shown large in a monospace box, such as an address, labelled items with text or a command, and a closing note.

interface EmailSection {
    readonly title: string;
    readonly text?: string;
    readonly copy?: {
        readonly label?: string;
        readonly value: string;
    };
    readonly items?: ReadonlyArray<EmailSectionItem>;
    readonly note?: string;
}
EmailSectionItem
interface EmailSectionItem {
    readonly label: string;
    readonly text?: string;
    readonly code?: string;
}
EmailTemplate

An email the workspace writes and the platform sends with a sign-in link, named by `User.sendSignInLink` or by `signIn` as its invitation, sign-in link or sign-in code email (`invitationEmail`, `linkEmail`, `codeEmail`): either fields the platform lays out ({@link EmailLayout}) or a whole document of the workspace's own ({@link EmailDocument}).

type EmailTemplate = EmailLayout | EmailDocument;
Entity

An entity: its definition, the record type (`typeof Lead.Type`), a reference schema for action inputs (`Lead.ref`), its actions, and data access for action handlers. `M` is the type of its declared metrics, which typed metric query clients read from `definition.metrics`.

interface Entity<Name extends string = string, P extends Properties = Properties, R extends Relationships = Relationships, A extends object = NoActions, M extends Metrics = Metrics, W extends EntityWrites = EntityWrites> extends EarlierQueryMetricsName<P, R, M> {
    readonly [EntityTypeId]: typeof EntityTypeId;
    readonly name: Name;
    readonly definition: EntityDefinition<P, R, M>;
    readonly "~ontology.writes": W;
    readonly properties: P;
    readonly relationships: R;
    readonly actions: A;
    readonly Type: EntityRecord<P, R>;
    readonly ref: Schema.Codec<string>;
    get(record: RecordRef, options?: GetOptions): Effect.Effect<EntityRecord<P, R>, NotFound, OntologyReads>;
    find(options?: FindOptions<EntityRecord<P, R>, LinkKeys<R>>): Effect.Effect<ReadonlyArray<EntityRecord<P, R>>, never, OntologyReads>;
    queryMetrics<const Metric extends keyof M & string, const Group extends MetricQueryGroupKey<P, R> = never>(options: FreshMetricQueryInput<P, R, Metric, Group>): Effect.Effect<ReadonlyArray<FreshMetricQueryRow<EntityRecord<P, R>, Group, Metric>>, never, OntologyReads>;
    create(values: CreateValues<P, R>): Effect.Effect<EntityRecord<P, R>, Conflict | NotFound | ScopeViolated, OntologyWrites>;
    update(record: RecordRef, values: UpdateValues<P, R>): Effect.Effect<EntityRecord<P, R>, Conflict | NotFound | ScopeViolated, OntologyWrites>;
    upsertBy(property: UniqueKeys<P>, values: CreateValues<P, R>): Effect.Effect<UpsertResult<EntityRecord<P, R>>, Conflict | NotFound | ScopeViolated, OntologyWrites>;
    createMany(records: ReadonlyArray<BatchCreateValues<P, R>>, options: {
        readonly returning: "summary";
    }): Effect.Effect<BatchSummaryResult, BatchWriteError, OntologyWrites>;
    createMany(records: ReadonlyArray<BatchCreateValues<P, R>>, options?: {
        readonly returning?: "records";
    }): Effect.Effect<BatchRecordResult<EntityRecord<P, R>>, BatchWriteError, OntologyWrites>;
    createMany(records: ReadonlyArray<BatchCreateValues<P, R>>, options?: BatchOptions): Effect.Effect<BatchResult<EntityRecord<P, R>>, BatchWriteError, OntologyWrites>;
    updateMany(records: ReadonlyArray<BatchUpdateRecord<P, R>>, options: {
        readonly returning: "summary";
    }): Effect.Effect<BatchSummaryResult, BatchWriteError, OntologyWrites>;
    updateMany(records: ReadonlyArray<BatchUpdateRecord<P, R>>, options?: {
        readonly returning?: "records";
    }): Effect.Effect<BatchRecordResult<EntityRecord<P, R>>, BatchWriteError, OntologyWrites>;
    updateMany(records: ReadonlyArray<BatchUpdateRecord<P, R>>, options?: BatchOptions): Effect.Effect<BatchResult<EntityRecord<P, R>>, BatchWriteError, OntologyWrites>;
    upsertMany<const K extends BatchKey<P>>(input: EntityUpsertManyInput<P, R, K> & {
        readonly returning: "summary";
    }): Effect.Effect<BatchSummaryResult, BatchWriteError, OntologyWrites>;
    upsertMany<const K extends BatchKey<P>>(input: EntityUpsertManyInput<P, R, K> & {
        readonly returning?: "records";
    }): Effect.Effect<BatchRecordResult<EntityRecord<P, R>>, BatchWriteError, OntologyWrites>;
    upsertMany<const K extends BatchKey<P>>(input: EntityUpsertManyInput<P, R, K>): Effect.Effect<BatchResult<EntityRecord<P, R>>, BatchWriteError, OntologyWrites>;
    delete(record: RecordRef): Effect.Effect<void, Conflict | NotFound | ScopeViolated, OntologyWrites>;
    link(relationship: ManyKeys<R>, record: RecordRef, target: RecordRef): Effect.Effect<void, NotFound | ScopeViolated, OntologyWrites>;
    unlink(relationship: ManyKeys<R>, record: RecordRef, target: RecordRef): Effect.Effect<void, NotFound | ScopeViolated, OntologyWrites>;
}
EntityDefinition
interface EntityDefinition<P extends Properties, R extends Relationships, M extends Metrics = Metrics> extends EarlierMetricsField<M> {
    readonly id: string;
    readonly label: string;
    readonly plural: string;
    readonly title: keyof P & string;
    readonly description: string;
    readonly properties: P;
    readonly source?: WarehouseSource;
    readonly metrics?: M;
    readonly relationships?: R;
    readonly indexes?: ReadonlyArray<IndexDefinition<IndexField<P, R>>>;
    readonly guide?: string;
    readonly renamedFrom?: string;
    readonly writes?: EntityWrites;
    readonly eraseFromWarehouseOnDelete?: boolean;
}
EntityManifest
const EntityManifest: Schema.Struct<{
    readonly source: Schema.optionalKey<Schema.Struct<{
        readonly asset: Schema.String;
        readonly key: Schema.$Array<Schema.String>;
        readonly currency: Schema.optionalKey<Schema.String>;
    }>>;
    readonly metrics: Schema.optionalKey<Schema.$Array<Schema.Struct<{
        readonly name: Schema.String;
        readonly label: Schema.String;
        readonly description: Schema.String;
        readonly unit: Schema.Literals<readonly [
            "number",
            "currency",
            "ratio",
            "percent"
        ]>;
        readonly format: Schema.Literals<readonly [
            "decimal",
            "currency",
            "percent"
        ]>;
        readonly expression: Schema.Codec<Schema.Json, Schema.Json, never, never>;
        readonly balanceOver: Schema.optionalKey<Schema.String>;
    }>>>;
    readonly id: Schema.String;
    readonly name: Schema.String;
    readonly label: Schema.String;
    readonly plural: Schema.String;
    readonly title: Schema.String;
    readonly description: Schema.String;
    readonly builtIn: Schema.Boolean;
    readonly renamedFrom: Schema.optionalKey<Schema.String>;
    readonly guide: Schema.optionalKey<Schema.String>;
    readonly properties: Schema.$Array<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 relationships: Schema.$Array<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;
    }>>;
    readonly indexes: Schema.$Array<Schema.Struct<{
        readonly properties: Schema.$Array<Schema.String>;
        readonly unique: Schema.Boolean;
    }>>;
    readonly actions: Schema.$Array<Schema.Struct<{
        readonly name: Schema.String;
        readonly description: Schema.String;
        readonly permission: Schema.optionalKey<Schema.String>;
        readonly anyOf: Schema.optionalKey<Schema.$Array<Schema.String>>;
        readonly input: Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>;
        readonly retryOnDeadlock: Schema.optionalKey<Schema.Boolean>;
        readonly writes: Schema.optionalKey<Schema.$Array<Schema.String>>;
        readonly connections: Schema.optionalKey<Schema.$Array<Schema.String>>;
        readonly files: Schema.optionalKey<Schema.$Array<Schema.Struct<{
            readonly entity: Schema.String;
            readonly property: Schema.String;
        }>>>;
        readonly hints: Schema.optionalKey<Schema.Struct<{
            readonly readOnly: Schema.optionalKey<Schema.Boolean>;
            readonly connectionsReadOnly: Schema.optionalKey<Schema.Boolean>;
            readonly destructive: Schema.optionalKey<Schema.Boolean>;
            readonly irreversible: Schema.optionalKey<Schema.Boolean>;
            readonly idempotent: Schema.optionalKey<Schema.Boolean>;
        }>>;
    }>>;
    readonly permissions: Schema.optionalKey<Schema.Struct<{
        readonly read: Schema.String;
        readonly create: Schema.optionalKey<Schema.String>;
        readonly update: Schema.optionalKey<Schema.String>;
        readonly delete: Schema.optionalKey<Schema.String>;
        readonly link: Schema.optionalKey<Schema.String>;
        readonly unlink: Schema.optionalKey<Schema.String>;
    }>>;
    readonly writes: Schema.optionalKey<Schema.Literal<"actions">>;
    readonly eraseFromWarehouseOnDelete: Schema.optionalKey<Schema.Literal<true>>;
}>
type EntityManifest = typeof EntityManifest.Type;
EntityPermissions

The permissions of an entity's reads and generated actions. The built-in agent chat has only `update`; `link` and `unlink` exist when the entity declares a `rel.many`. The built-in User has only `read` here: its generated member actions require `user:<verb>` for each of `USER_MEMBER_VERBS`.

interface EntityPermissions {
    readonly read: string;
    readonly create?: string;
    readonly update?: string;
    readonly delete?: string;
    readonly link?: string;
    readonly unlink?: string;
}
EntityPermissionsManifest

The permissions of an entity's reads and generated actions, so that readers need not rebuild the convention. The built-in user has only `read`; `link` and `unlink` exist with a `rel.many`. The generated `upsert_by_<property>` requires both `create` and `update`.

const EntityPermissionsManifest: Schema.Struct<{
    readonly read: Schema.String;
    readonly create: Schema.optionalKey<Schema.String>;
    readonly update: Schema.optionalKey<Schema.String>;
    readonly delete: Schema.optionalKey<Schema.String>;
    readonly link: Schema.optionalKey<Schema.String>;
    readonly unlink: Schema.optionalKey<Schema.String>;
}>
type EntityPermissionsManifest = typeof EntityPermissionsManifest.Type;
EntityQuerySchemas

The parts of an entity's query, for APIs that take them apart, such as URL parameters.

interface EntityQuerySchemas {
    readonly where: Schema.Codec<Where>;
    readonly orderBy: Schema.Codec<ReadonlyArray<OrderBy>>;
    readonly select: Schema.Codec<ReadonlyArray<string>>;
    readonly include: Schema.Codec<Included, ReadonlyArray<string> | Included>;
    readonly limit: Schema.Codec<number>;
    readonly after: Schema.Codec<string>;
    readonly query: Schema.Codec<Query>;
}
EntityRecord

A record of the entity: system fields, declared properties, and `<relationship>Id` per `rel.one` between stored entities.

type EntityRecord<P, R> = Simplify<SystemFields & {
    readonly [K in keyof P]: ValueOf<P[K]>;
} & RelationshipIds<R>>;
EntityTarget

Where a relationship points: an entity, a thunk returning one, or an entity name.

type EntityTarget = AnyEntity | LazyEntity | string;
EntityWrites

Who writes an entity's records; see {@link EntityDefinition.writes}.

type EntityWrites = "generated" | "actions";
FILTER_OPERATORS

Filter operators. A field's type decides which apply; see {@link entityQuerySchema}.

const FILTER_OPERATORS: readonly [
    "eq",
    "ne",
    "in",
    "isNull",
    "contains",
    "startsWith",
    "gt",
    "gte",
    "lt",
    "lte",
    "between"
]
FeedbackOptions
interface FeedbackOptions {
    readonly files?: boolean;
    readonly automaticFailureReports?: boolean;
    readonly builders?: ReadonlyArray<Role | string>;
}
FieldCondition

Conditions on one field of a record whose value has type `V`; see {@link FieldFilter }. A list, the user's `roles`, takes only `has` and `hasAny`.

type FieldCondition<V> = NonNullable<V> extends ReadonlyArray<infer Item> ? {
    readonly has?: Item;
    readonly hasAny?: ReadonlyArray<Item>;
} : V | null | ScalarCondition<V>;
FieldFilter

Conditions on one field; all of them must hold. `ne` matches records where the field is empty; `contains` and `startsWith` ignore case; `between` includes both ends. In a `where`, a bare value stands for `{ eq: value }` and `null` for `{ isNull: true }`. A list field takes only `has` and `hasAny`.

interface FieldFilter {
    readonly eq?: Schema.Json;
    readonly ne?: Schema.Json;
    readonly in?: ReadonlyArray<Schema.Json>;
    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
    ];
    readonly has?: string;
    readonly hasAny?: ReadonlyArray<string>;
}
FileRange

A byte range of a file revision: from `start` to `end` inclusive, the whole file by default.

interface FileRange extends OpenFile {
    readonly start?: number;
    readonly end?: number;
}
FileSource

A short-lived signed read of a byte range of a file revision, which SegmentStream's connection proxy fetches from the workspace's file storage when a connection request sends the file.

interface FileSource {
    readonly url: string;
    readonly headers: Readonly<Record<string, string>>;
    readonly start: number;
    readonly end: number;
    readonly contentType: string;
}
FileTarget

A file property an authored action may populate during preparation.

interface FileTarget {
    readonly entity: string;
    readonly property: string;
}
Files

File I/O outside transactions, bound to the current action or workflow principal.

class Files extends Files_base {
}
FilterOperator
type FilterOperator = (typeof FILTER_OPERATORS)[number];
FindOptions

A query from an action handler: the query language, plus `forUpdate`. Included relationships are added to the records under their names, but are not part of the records' type.

interface FindOptions<R = StoredRecord, L extends string = never> {
    readonly where?: RecordWhere<R, L>;
    readonly orderBy?: ReadonlyArray<{
        readonly field: keyof R & string;
        readonly direction?: "asc" | "desc";
    }>;
    readonly include?: ReadonlyArray<L> | {
        readonly [K in L]?: true;
    };
    readonly after?: string;
    readonly limit?: number;
    readonly forUpdate?: boolean;
}
FixedValue

A value the workspace fixes for one argument of a tool.

const FixedValue: Schema.Union<readonly [
    Schema.String,
    Schema.Number,
    Schema.Boolean
]>
type FixedValue = typeof FixedValue.Type;
FoundAction

An action and every permission a principal needs to run it, or, with `anyPermission`, one.

interface FoundAction extends ActionRequirement {
    readonly action: AnyAction;
    readonly generated: boolean;
}
FreshAggregateOptions
type FreshAggregateOptions<R = StoredRecord, L extends string = never, Metric extends string = string, Group extends string = string> = EarlierFreshMetricQueryOptions<R, L, Metric, Group>;
FreshAggregateRow
type FreshAggregateRow<Record, Group extends keyof Record, Metric extends string> = FreshMetricQueryRow<Record, Group, Metric>;
FreshMetricQueryInput

The options of an entity's fresh metric query, its metrics under either of their names.

type FreshMetricQueryInput<P, R, Metric extends string, Group extends string> = FreshMetricQueryOptions<EntityRecord<P, R>, LinkKeys<R>, Metric, Group> | EarlierFreshMetricQueryOptions<EntityRecord<P, R>, LinkKeys<R>, Metric, Group>;
FreshMetricQueryOptions

A fresh metric query from an action: metrics the entity declares, computed in the workspace database over the records `where` matches, in the action's transaction. `where` is the query language of `find` and must match an indexed field of the entity with `eq` or `in`; see docs/ontology.md, "Fresh metric queries inside an action".

interface FreshMetricQueryOptions<R = StoredRecord, L extends string = never, Metric extends string = string, Group extends string = string> {
    readonly metrics: readonly [
        Metric,
        ...Metric[]
    ];
    readonly groupBy?: ReadonlyArray<Group>;
    readonly where: RecordWhere<R, L>;
}
FreshMetricQueryRow

One row of a fresh metric query: the grouped fields, typed as the record's, and each metric as a decimal string, or `null` where the warehouse's value is null too.

type FreshMetricQueryRow<Record, Group extends keyof Record, Metric extends string> = Simplify<{
    readonly [K in Group]: Record[K];
} & {
    readonly [K in Metric]: string | null;
}>;
GUEST_BOT_CHECK_SCHEMES

The challenge providers a guest's bot check can verify. `turnstile` is Cloudflare Turnstile: the website renders its widget with the site key, and a connection holds its secret key.

const GUEST_BOT_CHECK_SCHEMES: readonly [
    "turnstile"
]
GUEST_CHANNELS

Channel kinds with a guest admission path. Named connections select their own policy.

const GUEST_CHANNELS: readonly [
    "web",
    "telegram",
    "slack",
    "whatsapp"
]
GUEST_EMAIL_CODE_PATH
const GUEST_EMAIL_CODE_PATH = "/api/ontology/agent/guests/email-code"
GUEST_SIGN_UP_PATH
const GUEST_SIGN_UP_PATH = "/api/ontology/agent/guests/sign-up"
GUEST_USAGE_PATH
const GUEST_USAGE_PATH = "/api/ontology/agent/guests/usage"
GeneratedActionManifest

A generated action, described as the manifest describes authored ones.

interface GeneratedActionManifest {
    readonly name: string;
    readonly description: string;
    readonly permissions: ReadonlyArray<string>;
    readonly input: JsonSchemaObject;
}
GeneratedActions

An entity's generated actions by name.

type GeneratedActions = Readonly<Record<string, AnyAction>>;
GeneratedActionsProvider

`generatedActions(entity, ontology)`: `create`, `update`, `delete`, `upsert_by_<property>`, `link` and `unlink`, as `src/runtime/generated-actions.ts` derives them.

type GeneratedActionsProvider = (entity: ResolvedEntity, ontology: Ontology) => Readonly<Record<string, AnyAction>>;
GetOptions
interface GetOptions {
    readonly forUpdate?: boolean;
}
GuestBotCheck

The challenge a website's visitor passes before they become a guest.

type GuestBotCheck = {
    readonly scheme: GuestBotCheckScheme;
    readonly connection: AnyConnectionHandle;
    readonly input: string;
    readonly secret?: undefined;
} | {
    readonly scheme: GuestBotCheckScheme;
    readonly secret: string;
    readonly connection?: undefined;
    readonly input?: undefined;
};
GuestBotCheckScheme
type GuestBotCheckScheme = (typeof GUEST_BOT_CHECK_SCHEMES)[number];
GuestChannel
type GuestChannel = (typeof GUEST_CHANNELS)[number] | WorkspaceSignUpChannel;
GuestIssue

A guest's credential, as {@link AgentWebStore.guest} answers it.

type GuestIssue = {
    readonly status: "issued";
    readonly guestId: string;
    readonly token: string;
    readonly refreshToken: string;
    readonly expiresAt: Date;
} | {
    readonly status: "limited";
    readonly retryAfterSeconds: number;
} | {
    readonly status: "refused";
};
GuestManifest

Guests: the channels they talk to the agent on and the websites whose visitors they are. Their permissions are the built-in `guest` role's. Read as text: channels and origins a reader does not know admit nobody.

const GuestManifest: 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";
}>
GuestOptions

Who may talk to the agent without signing in or signing up: a guest, the counterpart of the built-in `member`. A guest is a session, not a user: nobody proved who they are, so no user or identity record is created for them. The channel selects their roles, defaulting to `guest`. Without `guest`, nobody chats without signing in or signing up.

interface GuestOptions<P = unknown, R = unknown> {
    readonly openOnInvite?: ReadonlyArray<string>;
    readonly byChannel?: Readonly<Partial<Record<GuestChannel, ReadonlyArray<R>>>>;
    readonly channels: ReadonlyArray<GuestChannel>;
    readonly origins?: ReadonlyArray<string>;
    readonly permissions: ReadonlyArray<P>;
    readonly botCheck?: GuestBotCheck;
    readonly confirmations?: boolean;
}
GuestUpgrade

A guest who proved an email address, as {@link AgentWebStore.upgradeGuest} answers it.

type GuestUpgrade = {
    readonly status: "upgraded";
    readonly userId: string;
    readonly created: boolean;
    readonly token: string;
    readonly refreshToken: string;
    readonly expiresAt: Date;
} | {
    readonly status: "sign_up_closed";
} | {
    readonly status: "member_address";
} | {
    readonly status: "refused";
};
HeldReplyInput

A reply the agent held for review, as `POST /api/ontology/agent/drafts` reports it.

interface HeldReplyInput {
    readonly key: string;
    readonly provider: string;
    readonly channel: string;
    readonly chatId: string;
    readonly recipient: string;
    readonly to?: ReadonlyArray<string>;
    readonly cc?: ReadonlyArray<string>;
    readonly participants?: ReadonlyArray<string>;
    readonly threadId: string;
    readonly replyTo: string | null;
    readonly memberId: string;
    readonly sessionId: string;
    readonly text: string;
    readonly files?: ReadonlyArray<AgentDraftFile>;
    readonly mode: "always" | "whenUnsure" | "requested";
    readonly confidence: number | null;
    readonly requested?: {
        readonly note?: string;
        readonly notedBy: string;
        readonly basis: string;
    };
    readonly turnId?: string;
    readonly basis?: string;
}
HeldReview

The review a held reply became.

interface HeldReview {
    readonly id: string;
    readonly status: string;
    readonly created: boolean;
}
HistoryEntry

A row of `<entity>_history`.

const HistoryEntry: Schema.Struct<{
    readonly execution: Schema.optionalKey<Schema.Struct<{
        readonly issuer: Schema.String;
        readonly audience: Schema.String;
        readonly organizationId: Schema.String;
        readonly workspaceId: Schema.String;
        readonly subject: Schema.String;
        readonly deploymentId: Schema.String;
        readonly ontologyDeploymentId: Schema.String;
        readonly servingOntologyDeploymentId: Schema.String;
        readonly ontologyOrigin: Schema.String;
        readonly environment: Schema.Literals<readonly [
            "production",
            "preview"
        ]>;
        readonly jobName: Schema.NullOr<Schema.String>;
        readonly runId: Schema.String;
        readonly executionId: Schema.NullOr<Schema.String>;
        readonly attemptId: Schema.String;
        readonly generation: Schema.Number;
        readonly tokenId: Schema.String;
        readonly issuedAt: Schema.Number;
        readonly expiresAt: Schema.Number;
    }>>;
    readonly chat: Schema.optionalKey<Schema.Struct<{
        readonly provider: Schema.String;
        readonly chatId: Schema.String;
        readonly sessionId: Schema.optionalKey<Schema.String>;
    }>>;
    readonly id: Schema.String;
    readonly recordId: Schema.String;
    readonly action: Schema.String;
    readonly actionId: Schema.String;
    readonly kind: Schema.Literals<readonly [
        "create",
        "update",
        "delete",
        "link",
        "unlink"
    ]>;
    readonly principalId: Schema.NullOr<Schema.String>;
    readonly at: Schema.String;
    readonly changes: Schema.$Record<Schema.String, Schema.Struct<{
        readonly before: Schema.Codec<Schema.Json, Schema.Json, never, never>;
        readonly after: Schema.Codec<Schema.Json, Schema.Json, never, never>;
    }>>;
}>
type HistoryEntry = typeof HistoryEntry.Type;
earlierMetricsFieldProblem

Why a definition's metrics cannot be read, for `check`: it declares them under both names. A definition with only one of them has no such problem.

function earlierMetricsFieldProblem(definition: unknown): string | undefined;
earlierNamesOf

The earlier names a definition uses, for `check` to warn about: those {@link withCurrentDefinitionNames} renamed in it, or those it still declares itself. A field declared under both names is not among them; {@link earlierMetricsFieldProblem} refuses it.

function earlierNamesOf(definition: unknown): ReadonlyArray<EarlierName>;
effectiveChannelLimits

Only trusted runtimes submit limits; channel-app callers omit them and reuse the latest policy. The agent sends guest limits only from its web channel, so limits without `guest` keep the guest limits stored before.

function effectiveChannelLimits(sql: SqlClient.SqlClient, input?: ResolveIdentityInput["limits"]): Effect.Effect<AgentLimits, never, never>;
effectiveScope

Which records of `required` the principal's grants cover, once {@link isAllowed} said it holds it: `undefined` when some grant covers it unscoped, wildcards included; otherwise the `where` of the one scoped grant that names it, or the `or` of several. Without any grant the result is `{ or: [] }`, which matches no record.

function effectiveScope(required: string, principal: PermissionHolder): ScopeWhere | undefined;
encodeManifest

Encode only ontology-owned metadata. JSON values and JSON Schema keywords remain opaque.

function encodeManifest(manifest: OntologyManifest): Readonly<Record<string, unknown>>;
entity

Declares an entity. Add its actions with `.actions((self) => ({ … }))`; see {@link ActionsBuilder}. The data access methods delegate to {@link OntologyReads} and {@link OntologyWrites}, which the ontology service provides to actions.

function entity<const Name extends string, const P extends Properties, const R extends Relationships = NoRelationships, const M extends Metrics = NoMetrics>(name: Name, definition: EntityDefinition<P, R> & {
    readonly source: WarehouseSource;
    readonly metrics?: M;
} & EarlierMetricsField<M>): WarehouseBackedEntity<Name, P, R, M>;
function entity<const Name extends string, const P extends Properties, const R extends Relationships = NoRelationships, const M extends Metrics = NoMetrics, const W extends EntityWrites = "generated">(name: Name, definition: EntityDefinition<P, R, M> & {
    readonly writes?: W;
}): DraftEntity<Name, P, R, M, W>;
entityQueryResultSchema

A page of an entity's records, with the relationships a query may include.

function entityQueryResultSchema(manifest: OntologyManifest, entityName: string, wire?: boolean, warehouseRecords?: boolean): Schema.Codec<QueryResult<JsonRecord>, unknown>;
entityQuerySchema

The query schema of one entity; see {@link entityQuerySchemas}.

function entityQuerySchema(manifest: OntologyManifest, entityName: string, warehouseRecords?: boolean): Schema.Codec<Query>;
entityQuerySchemas

The precise query schemas of one entity: its fields with the operators of their types, its relationships (declared and inverse), the fields it can sort on and the relationships it can include. Every struct is closed: an unknown field, operator or key is an issue whatever the parse options, never a silently ignored filter.

function entityQuerySchemas(manifest: OntologyManifest, entityName: string, wire?: boolean, warehouseRecords?: boolean): EntityQuerySchemas;
entityRecordSchema

The record of an entity as the runtime returns it: system fields, properties (`null` when empty; dates as `YYYY-MM-DD`, timestamps as ISO 8601 in UTC) and a `<relationship>_id` per `rel.one`. It checks the shape of stored values, not the refinements of the definition (`maxLength`, `min`, patterns), so that tightening a refinement never makes existing records unreadable.

function entityRecordSchema(entity: EntityManifest): Schema.Codec<JsonRecord>;
findAction

The entity's authored action of that name, or else its generated one.

function findAction(ontology: Ontology, entityName: string, actionName: string): AnyAction | undefined;
findApiKey

One API key by its id, or undefined.

function findApiKey(input: {
    readonly id: string;
} & StoredRolesListing): Effect.Effect<ApiKeySummary | undefined, never, SqlClient.SqlClient>;
formatDiagnostics
function formatDiagnostics(diagnostics: ReadonlyArray<Diagnostic>): string;
formatManifest

The manifest as a file: canonical key order, two-space indentation and a final newline.

function formatManifest(manifest: OntologyManifest): string;
generateApiKey

A new API key: 8 random bytes of key id and 32 of secret. Show it once; it is not stored.

function generateApiKey(): string;
generatedActionManifests

The generated actions described as the manifest describes authored ones, for catalogs and MCP.

function generatedActionManifests(ontology: Ontology, entityName: string): ReadonlyArray<GeneratedActionManifest>;
generatedActionPermissions

What a generated action requires: `<entity>:<action>`, except `upsert_by_<property>`, which may create or update and so requires both `<entity>:create` and `<entity>:update`.

function generatedActionPermissions(entity: string, action: string): ReadonlyArray<string>;
generatedActions

The actions generated for an entity: `create`, `update` (without `managed` properties), `delete`, `upsert_by_<property>` per unique property, and `link`/`unlink` when it declares a `rel.many` whose target keeps its generated writes. An entity that declares `writes: "actions"` has none. They are ordinary actions and run through the same pipeline. Their `permission` is unset: each requires the permission named after it (`lead:create`), and `upsert_by_<property>` both `create` and `update`, as `generatedActionPermissions` says. The built-in User has only its member management: `invite`, `grant_roles`, `revoke_roles`, `deactivate` and `reactivate`; members are otherwise created by sign-in and services by the app or the CLI. The built-in agent chat has only `update`, for its unmanaged properties: the agent records chats and their members. The built-in identities have `attach`, `attest` and `revoke`, explicitly authorized account and contact management.

function generatedActions(ontology: Ontology, entityName: string): GeneratedActions;
grantMemberRoles

Grants roles of the ontology to the member with this email, creating the member when no user has it; their name defaults to the email. Granting a role they hold changes nothing.

function grantMemberRoles(ontology: Ontology, input: {
    readonly email: string;
    readonly name?: string | undefined;
    readonly roles: ReadonlyArray<string>;
}): Effect.Effect<MemberSummary, UnknownRole | MemberNotFound, SqlClient.SqlClient>;
grants

Whether a granted permission, which may hold wildcards, covers the required one. A wildcard entity covers every entity but those in {@link EXPLICIT_GRANT_ENTITIES}, and of those in {@link WILDCARD_ENTITY_VERBS} only the listed verbs.

function grants(granted: string, required: string): boolean;
guestOf

Where guests talk to the agent and the websites whose visitors they are, as a manifest declares them: `undefined` when it admits no guests, because it declares none, or none on a channel this reader knows, or no website it can read.

function guestOf(manifest: Pick<OntologyManifest, "signIn">): ResolvedGuest | undefined;
hashApiKeySecret

PBKDF2-SHA256 of a secret with its salt, in hex: what `_api_keys.hash` holds.

function hashApiKeySecret(secret: string, salt: string): Promise<string>;