@segmentstream/app/ui
61 public exports from @segmentstream/app/ui.
Public exports
AgentConnect
The agent connect page in the SDK's neutral styles and the app's `texts`: what asks to be linked, an Approve button and the result. The Server Component at `/agent/connect` reads the pairing and passes it to the app's client component that renders this with its `texts`.
function AgentConnect({ code, pairing, connected, member, action, texts: appTexts, }: AgentConnectProps): import("react").JSX.Element;AgentConnectProps
interface AgentConnectProps {
readonly code: string | undefined;
readonly pairing: AgentPairing | null;
readonly connected?: string | undefined;
readonly member?: string | undefined;
readonly action?: string;
readonly texts?: AgentConnectTexts;
}AgentConnectTexts
Every word `<AgentConnect>` shows, in the app's own language. `provider` is the chat's provider as the platform names it, such as `telegram`; `member` is the `member` prop, `undefined` without it.
interface AgentConnectTexts {
readonly requestTitle: (provider: string) => ReactNode;
readonly request: (provider: string, display: string | null, member: string | undefined) => ReactNode;
readonly approve: ReactNode;
readonly connectedTitle: (provider: string) => ReactNode;
readonly connected: (provider: string, member: string | undefined) => ReactNode;
readonly expiredTitle: ReactNode;
readonly expired: ReactNode;
}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;
}BrowserSignInMethod
type BrowserSignInMethod = "email" | "segmentstream";
BrowserSignInOptions
interface BrowserSignInOptions {
readonly returnTo?: string;
readonly error?: string;
}Can
Renders its children when the signed-in user holds the permission. It only hides controls: the ontology service checks every read and action itself.
function Can({ permission, children, fallback }: CanProps): ReactNode;CanProps
interface CanProps extends ChildrenProps {
readonly permission: string;
readonly fallback?: ReactNode;
}ChannelSignInOptions
interface ChannelSignInOptions {
readonly assertion: () => string | undefined;
readonly redirectTo?: string;
}ChannelSignInState
type ChannelSignInState = {
readonly status: "loading" | "disabled" | "idle" | "pending" | "signed_in" | "error";
readonly error: string | null;
};ChildrenProps
interface ChildrenProps {
readonly children?: ReactNode;
}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>;
}IdentityLinkState
interface IdentityLinkState {
readonly status: "loading" | "ready" | "unavailable";
readonly pending: boolean;
readonly proofReady: boolean;
readonly emailEnabled: boolean;
readonly identity: LinkAccountIdentity | null;
readonly workspaceUser: LinkAccountIdentity | null;
readonly expiresAt: number | null;
readonly returnTo: string | null;
}Link
Next.js's `Link` that marks itself while the page it opens loads. From the press until the next page renders, the anchor carries `data-pending`, so the app shows at once that the press was taken, for example with Tailwind's `data-pending:` variant or `a[data-pending]` in its CSS. A link that only changes the search parameters marks itself too, where `loading.tsx` shows nothing. It adds no text, icon or style of its own: how a pending link looks is the app's. `withPendingLinks` (`@segmentstream/app/next`) keeps pages from importing the bare Next.js `Link`.
function Link({ children, ...props }: LinkProps): import("react").JSX.Element;LinkAccountIdentity
interface LinkAccountIdentity {
readonly id: string;
readonly email?: string;
readonly name?: string;
}LinkProps
Next.js's link props, without the deprecated single-child `legacyBehavior`.
type LinkProps = Omit<ComponentProps<typeof NextLink>, "legacyBehavior" | "passHref">;
NOT_INVITED
The person signed in, but the ontology has no member row for them.
const NOT_INVITED = "not_invited"
Permissions
interface Permissions {
readonly isLoading: boolean;
readonly roles: ReadonlyArray<string>;
readonly permissions: ReadonlyArray<string>;
readonly can: (permission: string) => boolean;
}SIGN_IN_ERROR_MESSAGES
const SIGN_IN_ERROR_MESSAGES: Readonly<Record<SignInErrorCode, string>>
SIGN_IN_LINK_INVALID
An emailed sign-in link that Neon Auth rejected: expired, already used or unknown.
const SIGN_IN_LINK_INVALID = "sign_in_link_invalid"
SIGN_IN_REFUSED
The person signed in, but the ontology refused that sign-in for this app: the member is deactivated, or another sign-in method already holds their address.
const SIGN_IN_REFUSED = "sign_in_refused"
ScopedPermission
A permission the user holds only for the records its `where` matches, as `/me` sends it. `where` is the condition in the wire form of a query: snake_case field names, and the signed-in user as `{ "$me": [] }` or a path from them as `{ "$me": ["staff_member", "division"] }`. It is informational, for what the app shows; the ontology service enforces it on every read and write.
interface ScopedPermission {
readonly permission: string;
readonly where: {
readonly [field: string]: JsonValue;
};
}SegmentStreamApiError
A failed SegmentStream or ontology request; `code` is the API error code, such as `not_invited`, `forbidden`, `action_rejected` or `query_timeout`.
class SegmentStreamApiError extends Error {
readonly code: string;
readonly status: number;
readonly detail: string;
readonly requestId: string | undefined;
readonly retryable: boolean;
readonly queryId: string | undefined;
readonly issues: ReadonlyArray<ApiIssue>;
readonly limit: ApiLimit | undefined;
readonly retryAfterSeconds: number | undefined;
readonly keyConsumed: boolean;
readonly refusal: string | undefined;
readonly connect: string | undefined;
constructor(input: {
readonly code: string;
readonly status: number;
readonly detail: string;
readonly requestId?: string | undefined;
readonly retryable?: boolean;
readonly queryId?: string | undefined;
readonly issues?: ReadonlyArray<ApiIssue>;
readonly limit?: ApiLimit | undefined;
readonly retryAfterSeconds?: number | undefined;
readonly keyConsumed?: boolean;
readonly refusal?: string | undefined;
readonly connect?: string | undefined;
readonly cause?: unknown;
});
}SegmentStreamLogo
The official SegmentStream logo, also used on segmentstream.com, drawn in `currentColor` so it shows on light and dark backgrounds alike. It is 210 by 45 pixels unless `className` or `width` and `height` size it.
function SegmentStreamLogo(props: SVGProps<SVGSVGElement>): import("react").JSX.Element;SegmentStreamMark
The SegmentStream mark from the official logo, drawn in `currentColor` so that it follows the text color on light and dark backgrounds, as in a "Sign in with SegmentStream" button. Size it with `className` or `width` and `height`. It is decorative unless `title` names it.
function SegmentStreamMark({ title, ...props }: SVGProps<SVGSVGElement> & {
readonly title?: string;
}): import("react").JSX.Element;SessionState
type SessionState = {
readonly status: "loading";
} | {
readonly status: "signed-out";
readonly source?: "oidc";
} | {
readonly status: "signed-in";
readonly sessionId: string;
readonly user: SessionUser;
readonly source?: "channel" | "oidc";
readonly expiresAt?: string;
} | {
readonly status: "unavailable";
readonly source?: "oidc";
};SessionUser
The person Neon Auth has signed in, before the ontology is asked about them.
interface SessionUser {
readonly id: string;
readonly email: string | null;
readonly name: string | null;
}SignIn
Email sign-in with Neon Auth in the SDK's neutral styles and the app's `texts`: `useSignIn()` with markup. Apps with their own design system render `useSignIn()` themselves.
function SignIn({ renderTelegram, renderBrowser, texts, ...options }: SignInProps): string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | import("react").JSX.Element | null;SignInController
Email sign-in for a form the app renders itself, in its own words: the controller reports failures and confirmations as codes. The calls take values, not form events.
interface SignInController {
readonly segmentstreamSignInUrl: string | null;
readonly emailEnabled: boolean;
readonly step: "email" | "code" | "link";
readonly email: string;
readonly setEmail: (value: string) => void;
readonly code: string;
readonly setCode: (value: string) => void;
readonly pending: "send" | "verify" | "resend" | "sign-out" | null;
readonly error: string | null;
readonly errorCode: SignInErrorCode | null;
readonly notice: string | null;
readonly noticeCode: SignInNoticeCode | null;
readonly resendIn: number;
readonly codeLength: number;
readonly destination: string;
readonly signedIn: boolean;
readonly notInvited: boolean;
readonly refused: boolean;
readonly linkInvalid: boolean;
readonly codeFromLink: boolean;
readonly emailFromLink: boolean;
readonly sessionEmail: string | null;
readonly submitEmail: () => Promise<void>;
readonly submitCode: (value?: string) => Promise<void>;
readonly resend: () => Promise<void>;
readonly changeEmail: () => void;
readonly switchAccount: () => Promise<void>;
}SignInErrorCode
Why the last call failed. `not_invited`: the ontology allows no sign-in with this address, so no email was sent. The app words a message for each code.
type SignInErrorCode = "email_required" | "email_invalid" | "not_invited" | "code_incomplete" | "code_invalid" | "code_expired" | "too_many_attempts" | "rate_limited" | "unavailable" | "failed";
SignInNoticeCode
What the last call confirmed: another code, or another sign-in link, was sent to `email`. The app words a message for each code.
type SignInNoticeCode = "code_resent" | "link_resent";
SignInOptions
interface SignInOptions {
readonly returnTo?: string;
readonly error?: string;
}SignInProps
interface SignInProps extends SignInOptions {
readonly texts?: SignInTexts;
readonly title?: string;
readonly renderBrowser?: (state: ReturnType<typeof useBrowserSignIn>) => ReactNode;
readonly renderTelegram?: (state: ChannelSignInState) => ReactNode;
}SignInTexts
Every word `<SignIn>` shows, in the app's own language: a message for each code `useSignIn()` reports, each heading and label, and functions for text that names an address or a number.
interface SignInTexts {
readonly title: ReactNode;
readonly emailIntro: ReactNode;
readonly emailLabel: ReactNode;
readonly segmentstreamSignIn: ReactNode;
readonly linkInvalid: ReactNode;
readonly continue: ReactNode;
readonly sending: ReactNode;
readonly checkEmailTitle: ReactNode;
readonly codeSent: (email: string, codeLength: number) => ReactNode;
readonly linkSent: (email: string) => ReactNode;
readonly codeLabel: ReactNode;
readonly signIn: ReactNode;
readonly signingIn: ReactNode;
readonly resendCode: (seconds: number) => ReactNode;
readonly resendLink: (seconds: number) => ReactNode;
readonly useAnotherEmail: ReactNode;
readonly signingOut: ReactNode;
readonly signedInTitle: ReactNode;
readonly signedInAs: (email: string | null) => ReactNode;
readonly notInvitedTitle: ReactNode;
readonly notInvited: (email: string | null) => ReactNode;
readonly refusedTitle?: ReactNode;
readonly refused?: (email: string | null) => ReactNode;
readonly errors: Readonly<Record<SignInErrorCode, ReactNode>>;
readonly notices: Readonly<Record<SignInNoticeCode, (email: string) => ReactNode>>;
}SignedIn
Renders its children when a Neon Auth session exists in this browser.
function SignedIn({ children }: ChildrenProps): ReactNode;SignedOut
Renders its children when nobody is signed in.
function SignedOut({ children }: ChildrenProps): ReactNode;TelegramSignIn
Headless component: the app owns all labels and error messages.
function TelegramSignIn({ children, ...options }: TelegramSignInProps): string | number | bigint | boolean | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | null;TelegramSignInOptions
interface TelegramSignInOptions {
readonly redirectTo?: string;
readonly initData?: () => string | undefined;
}TelegramSignInProps
interface TelegramSignInProps extends TelegramSignInOptions {
readonly children?: (state: ChannelSignInState) => ReactNode;
}UserMenu
The signed-in user's name, email and roles, and a sign-out button.
function UserMenu({ signedOutPath, texts, }: UserMenuProps): import("react").JSX.Element | null;UserMenuProps
interface UserMenuProps {
readonly signedOutPath?: string;
readonly texts?: UserMenuTexts;
}UserMenuTexts
The words `<UserMenu>` shows, in the app's own language.
interface UserMenuTexts {
readonly account: ReactNode;
readonly roles: string;
readonly signOut: ReactNode;
readonly signingOut: ReactNode;
}UserState
`useUser()`: the `/api/ontology/me` answer for the session, loaded once per session.
type UserState = {
readonly status: "loading";
readonly user: null;
readonly error: null;
} | {
readonly status: "signed-out";
readonly user: null;
readonly error: null;
} | {
readonly status: "signed-in";
readonly user: CurrentUser;
readonly error: null;
} | {
readonly status: "error";
readonly user: null;
readonly error: SegmentStreamApiError;
};isAllowed
Whether one of the holder's permissions equals `required` or covers it through a wildcard.
function isAllowed(required: string, holder: PermissionHolder): boolean;
readConnectionReturn
Reads a connection return from a URL fragment such as `#connection=gmail&confirmation=…`. `null` for any other fragment. Only the fragment is read: a `confirmation` in the query string is not one the platform sent, and is ignored.
function readConnectionReturn(hash: string): ConnectionReturn | null;
signInCodeFromLink
The address and code that a sign-in code email's link carries in the sign-in page's fragment, as the platform writes it for apps that declare `signIn.codeLink`: `/sign-in#code=482915&email=ada%40example.com`. Browsers never send the fragment to a server.
function signInCodeFromLink(hash: string): {
readonly email: string;
readonly code: string;
} | null;signInEmailFromLink
The recipient a used or expired sign-in link names in the sign-in page's fragment, as the app SDK's auth route writes it: `/sign-in?error=sign_in_link_invalid#email=ada%40example.com`.
function signInEmailFromLink(hash: string): string | null;
signInErrorCode
Why a Neon Auth (Better Auth) call failed.
function signInErrorCode(error: unknown): SignInErrorCode;
signInErrorMessage
function signInErrorMessage(error: unknown): string;
signOut
Ends the selected session in this browser, then opens `redirectTo`.
function signOut(redirectTo?: string): Promise<void>;
takeConnectionReturn
Takes the connection return the platform sent to the connections page: reads it from the URL fragment and removes the fragment from the address with `history.replaceState`, keeping the path and the query. When the page rendered {@link CONNECTION_RETURN_SCRIPT}, that script has already done so before any other script ran, and this returns what it read. Call it once, on the client, before anything else on the page reads the address; a second call returns `null`. The page then confirms the code for a signed-in member and discards it when nobody is signed in.
function takeConnectionReturn(target?: ReturnWindow): ConnectionReturn | null;
useBrowserSignIn
Headless browser-method discovery. The workspace supplies every message and control.
function useBrowserSignIn(options?: BrowserSignInOptions): {
status: "unavailable" | "loading" | "ready";
methods: readonly BrowserSignInMethod[];
primary: "email" | "segmentstream";
returnTo: string;
error: string | null;
segmentstreamSignInUrl: string | null;
connectAccountUrl: string | null;
accountSwitchUrl: string | null;
emailSignInUrl: string | null;
};useChannelSignIn
One exchange per assertion, with an absolute expiry timer. Errors are app-rendered codes.
function useChannelSignIn(provider: string, options: ChannelSignInOptions): ChannelSignInState;
useEmailIdentityLink
Explicit reverse linking. Email possession is proof only; the OIDC session selects the user.
function useEmailIdentityLink(): {
status: "error" | "pending" | "linked" | "idle";
error: string | null;
confirm: () => Promise<boolean>;
requestProof: (email: string, returnTo?: string) => Promise<boolean>;
};useIdentityLink
Linking never confirms during a GET. Post the form to confirmationUrl after explicit consent.
function useIdentityLink(): {
confirmationUrl: string;
emailProofUrl: string;
status: "loading" | "ready" | "unavailable";
pending: boolean;
proofReady: boolean;
emailEnabled: boolean;
identity: LinkAccountIdentity | null;
workspaceUser: LinkAccountIdentity | null;
expiresAt: number | null;
returnTo: string | null;
};usePermissions
The signed-in user's roles and permissions, from the same per-session answer as `useUser()`.
function usePermissions(): Permissions;
useSession
The Neon Auth session in this browser: `loading`, `signed-out`, `signed-in` or `unavailable`.
function useSession(): SessionState;
useSignIn
Email sign-in with Neon Auth, without markup. The ontology first says whether the address may sign in (`POST /api/ontology/sign-in/check`): a member with a Neon Auth account gets a six-digit code, a first sign-in gets a sign-in link, which creates the account, and an address the ontology refuses gets `not_invited` without an email. Without an ontology to ask, every address gets a code. `<SignIn texts={…} />` renders it with the SDK's own styles; apps with their own design system render the controller themselves, wording each `errorCode` and `noticeCode`.
function useSignIn({ returnTo, error: reason }?: SignInOptions): SignInController;useTelegramSignIn
Works on any app page; the public SDK configuration must explicitly enable Telegram.
function useTelegramSignIn(options?: TelegramSignInOptions): ChannelSignInState;
useUser
The signed-in user as the ontology knows them, from `GET /api/ontology/me`, loaded once per session. `status` is `loading`, `signed-out`, `signed-in` (with `user`) or `error` (with `error`; `error.code` is `not_invited` for people the app has not invited).
function useUser(): UserState;