Skip to content
SegmentStream/ Docs

Loading documentation…

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

@segmentstream/app · A–D

41 public exports from @segmentstream/app.

Public exports

AGENT_CONNECT_HANDLER

The Route Handler the agent connect page's form posts to.

const AGENT_CONNECT_HANDLER = "/api/agent/connect"
AGENT_CONNECT_PAGE

The app's page where a signed-in member links their chat account to the workspace agent.

const AGENT_CONNECT_PAGE = "/agent/connect"
ActionCall

Runs one action: `lead.actions.changeStatus({ lead, status }, { validateOnly })`.

type ActionCall<Input, Result> = (input: Input, options?: ActionOptions) => Promise<ActionResponse<Result>>;
ActionOptions
interface ActionOptions extends RequestOptions {
    readonly validateOnly?: boolean;
    readonly idempotencyKey?: string;
    readonly createIntent?: string;
}
ActionResponse

`POST /api/ontology/<entity>/actions/<action>` answers `{ result, validation, edits }`.

interface ActionResponse<Result = unknown> {
    readonly result: Result | null;
    readonly validation: {
        readonly ok: boolean;
        readonly issues: ReadonlyArray<ValidationIssue>;
    };
    readonly edits: ReadonlyArray<Edit>;
}
AgentAuthorizationRequest

An agent asking to act for the signed-in member, as the consent page shows it.

interface AgentAuthorizationRequest {
    readonly id: string;
    readonly client: {
        readonly name: string;
        readonly uri: string | null;
        readonly redirectUri: string;
        readonly redirectHost: string;
    };
    readonly scope: AgentScope;
    readonly permissions: ReadonlyArray<string>;
    readonly expiresAt: string;
}
AgentAuthorizations
interface AgentAuthorizations {
    readonly request: (id: string) => Promise<AgentAuthorizationRequest | null>;
    readonly deviceLookup: (userCode: string) => Promise<DeviceLookup>;
    readonly deviceRequest: (userCode: string) => Promise<AgentAuthorizationRequest | null>;
    readonly consentHandler: () => {
        readonly POST: (request: Request) => Promise<Response>;
    };
}
AgentChatPersona
interface AgentChatPersona {
    readonly groupAccess?: "members" | "public" | null;
    readonly title: string;
    readonly assigned: string | null;
    readonly effective: string;
    readonly source: "chat" | "rule" | "default";
    readonly names: readonly string[];
}
AgentIdentities
interface AgentIdentities {
    readonly personaChats: (after?: string) => Promise<{
        chats: readonly {
            id: string;
            title: string;
            channel: string;
        }[];
        after: string | null;
    }>;
    readonly chatPersona: (chat: string) => Promise<AgentChatPersona>;
    readonly setChatPersona: (chat: string, persona: string | null, expected: string | null) => Promise<void>;
    readonly pairing: (code: string) => Promise<AgentPairing>;
    readonly approvePairing: (code: string) => Promise<AgentIdentity>;
    readonly identities: () => Promise<ReadonlyArray<AgentIdentity>>;
    readonly revokeIdentity: (id: string) => Promise<void>;
    readonly connectHandler: () => {
        readonly POST: (request: Request) => Promise<Response>;
    };
}
AgentIdentity

A chat account linked to a member: the agent acts as that member for its messages.

interface AgentIdentity {
    readonly id: string;
    readonly provider: string;
    readonly externalId: string;
    readonly display: string | null;
    readonly createdAt: string;
    readonly revokedAt: string | null;
}
AgentPairing

A chat account asking to be linked to the signed-in member, as the connect page shows it. The workspace agent answers a sender it does not know with the link `/agent/connect?code=<code>`.

interface AgentPairing {
    readonly provider: string;
    readonly display: string | null;
    readonly expiresAt: string;
}
AgentScope

Everything the member may do, or only the reads of it.

type AgentScope = "ontology" | "ontology:read";
AggregateEntityClient
type AggregateEntityClient<Property extends string = string, Measure extends string = string, Temporal extends Property = Property, Path extends string = never> = EntityMetricQueryClient<Property, Measure, Temporal, Path>;
AggregateField
type AggregateField = MetricQueryField;
AggregateFilterOperator
type AggregateFilterOperator = MetricQueryFilterOperator;
AggregateGranularity
type AggregateGranularity = MetricQueryGranularity;
AggregateRequest
type AggregateRequest<Property extends string = string, Measure extends string = string, Temporal extends Property = Property, Path extends string = never> = WithEarlierNames<EntityMetricQuery<Property, Measure, Temporal, Path>, Measure>;
AggregateResult
type AggregateResult<Row = Record<string, string | boolean | null>> = MetricQueryResult<Row>;
ApiIssue

One problem with a request's input, as the ontology service reports it.

interface ApiIssue {
    readonly path: ReadonlyArray<string | number>;
    readonly message: string;
}
ApiLimit

Structured platform limits; workspace clients choose their own user-facing wording.

type ApiLimit = {
    readonly kind: "storage_quota";
    readonly usedBytes: number;
    readonly requestedBytes: number;
    readonly quotaBytes: number;
} | {
    readonly kind: "pending_uploads";
    readonly pending: number;
    readonly max: number;
    readonly uploads?: ReadonlyArray<{
        readonly id: string;
        readonly filename: string;
        readonly expiresAt: string;
    }>;
} | {
    readonly kind: "member_attachments";
    readonly live: number;
    readonly max: number;
} | {
    readonly kind: "agent_turns";
    readonly scope: string;
};
AppUser

The signed-in user. With Neon Auth, the person's ontology `user` record with the roles and permissions from `GET /api/ontology/me`; with the legacy SegmentStream sign-in, the member the app session token names, without ontology roles.

interface AppUser extends TokenUser {
    readonly id: string;
    readonly roles: ReadonlyArray<string>;
    readonly permissions: ReadonlyArray<string>;
    readonly scopes?: ReadonlyArray<ScopedPermission>;
    readonly kind?: string;
    readonly active?: boolean;
    readonly authUserId?: string;
}
AuthRouteHandler
type AuthRouteHandler = (request: Request, context: {
    params: Promise<{
        path: string[];
    }>;
}) => Promise<Response>;
AuthRouteHandlers

The Neon Auth API for `app/src/app/api/auth/[...path]/route.ts`.

interface AuthRouteHandlers {
    readonly GET: AuthRouteHandler;
    readonly POST: AuthRouteHandler;
    readonly PUT: AuthRouteHandler;
    readonly DELETE: AuthRouteHandler;
    readonly PATCH: AuthRouteHandler;
}
AuthenticationMethod

Primary server integration; declared browser methods take precedence over legacy environment discovery.

type AuthenticationMethod = "neon-auth" | "segmentstream";
BlobUploadTicket
interface BlobUploadTicket {
    readonly uploadId: string;
}
CONNECTIONS_HANDLER

Where the connections page's Route Handlers are served: `app/api/account/connections/[[...path]]`, which also routes the bare path. The page and its handlers are listed in the proxy's `sessionOptionalPaths`, so that nobody is sent to sign-in from the page with its confirmation code in the address.

const CONNECTIONS_HANDLER = "/api/account/connections"
CONNECTIONS_PATH

The app's page where each user connects their own accounts for owned connections. The platform sends every consent back to this path on the app's production address, with the result in the URL fragment, so the page must be served here.

const CONNECTIONS_PATH = "/account/connections"
CONNECTION_RETURN_SCRIPT

An inline script for the root layout's `<head>`, rendered with `<script dangerouslySetInnerHTML={{ __html: CONNECTION_RETURN_SCRIPT }} />` ahead of any script the app adds. A browser runs it as the parser reaches it, and Next.js loads its own scripts `async`, so on the connections page it removes a connection return from the address before any other script runs, the framework's router included, and keeps it for {@link takeConnectionReturn}. Elsewhere it does nothing. It carries no text. Under a nonce-based `Content-Security-Policy` it needs the nonce.

const CONNECTION_RETURN_SCRIPT: string
Change
interface Change {
    readonly before: JsonValue;
    readonly after: JsonValue;
}
ChatOverrideInput
interface ChatOverrideInput {
    readonly mode?: string;
    readonly smart?: Pick<SmartPolicyInput, "instructions" | "criteria" | "engagement" | "thresholds"> & {
        readonly context?: Pick<NonNullable<SmartPolicyInput["context"]>, "messages" | "includeChatGuidance">;
    };
    readonly participants?: Participants;
}
ConnectionReturn

What the platform sent the browser back to the connections page with, in the URL fragment (docs/private-connections-spec.md, "In the app"): the connection's key and either the one-use confirmation code the page confirms or discards, or the code of what went wrong.

type ConnectionReturn = {
    readonly connection: string;
    readonly confirmation: string;
} | {
    readonly connection: string;
    readonly error: string;
};
CurrentUser

The signed-in person as the ontology knows them: their `user` record, the roles they hold, the permissions those roles grant, wildcards included, and which of them cover only some records.

interface CurrentUser {
    readonly id: string;
    readonly name: string | null;
    readonly email: string | null;
    readonly kind: string;
    readonly active: boolean;
    readonly roles: ReadonlyArray<string>;
    readonly permissions: ReadonlyArray<string>;
    readonly scopes?: ReadonlyArray<ScopedPermission>;
}
DeploymentAdmissionCode
type DeploymentAdmissionCode = "preview_configuration_invalid" | "preview_expired" | "preview_capability_unavailable" | "preview_authentication_unavailable" | "preview_storage_binding_invalid";
DeploymentAdmissionError

Stable codes only: workspace code owns explanations and presentation.

class DeploymentAdmissionError extends Error {
    readonly code: DeploymentAdmissionCode;
    readonly capability?: keyof DeploymentCapabilities | undefined;
    readonly _tag = "DeploymentAdmissionError";
    constructor(code: DeploymentAdmissionCode, capability?: keyof DeploymentCapabilities | undefined);
    get status(): number;
}
DeploymentCapabilities

Runtime observations; authorization of the machine credential remains platform-owned.

interface DeploymentCapabilities {
    readonly warehouseRead: boolean;
    readonly pipelineRuns: boolean;
    readonly connections: boolean;
    readonly agents: boolean;
    readonly workflows: boolean;
}
DeploymentObservation
type DeploymentObservation = {
    readonly target: "production";
    readonly deploymentId?: string;
    readonly capabilities: DeploymentCapabilities;
} | {
    readonly target: "preview";
    readonly deploymentId: string;
    readonly expiresAt: string;
    readonly capabilities: DeploymentCapabilities;
};
DeviceCodeUnavailable

Why a device code cannot be decided: it `expired`, was already `decided`, or is `unknown` (never issued, mistyped, cleaned up, or reported by an ontology service too old to say).

type DeviceCodeUnavailable = "expired" | "decided" | "unknown";
DeviceLookup

A device code looked up for the signed-in member: its request, or why there is none.

type DeviceLookup = {
    readonly status: "pending";
    readonly request: AgentAuthorizationRequest;
} | {
    readonly status: DeviceCodeUnavailable;
};
createBlobStorageClient

Portable client: ontology requests use the member transport; bytes use only a scoped grant.

function createBlobStorageClient(transport: OntologyTransport, transfer?: typeof fetch): {
    list(signal?: AbortSignal): Promise<OpenUploadSessions>;
    status: (id: string, signal?: AbortSignal) => Promise<UploadSession>;
    cancel: (id: string) => Promise<UploadSession>;
    uploadForAction(target: FileUploadTarget, file: File, options?: FileUploadOptions): Promise<{
        upload: UploadSession;
        ticket: BlobUploadTicket;
        options: {
            createIntent?: string | undefined;
            idempotencyKey: string;
        };
    }>;
    download(entity: string, recordId: string, property: string, options?: FileDownloadOptions): Promise<FileTransfer>;
};
createSegmentStreamApp

Creates the SegmentStream integration for a Next.js workspace app. Pass the type of the app's ontology to type `segmentstream.ontology`: ```ts import type ontology from "../../ontology"; import link from "../segmentstream.json"; export const segmentstream = createSegmentStreamApp<typeof ontology>(link); ``` With `NEON_AUTH_BASE_URL` set, users sign in with Neon Auth and their roles and permissions come from the ontology. Without it, members sign in with their SegmentStream account, as in 0.2.

function createSegmentStreamApp<O = unknown>(config: SegmentStreamAppConfig): SegmentStreamApp<O>;