Skip to content
WIP

This guide is a work in progress. Barry is also a work in progress.

@barry-rocks/sdk/apps

The client for AG-UI, the protocol a bag’s app uses to watch and drive a session: AgUiConnection, its event and delivery types, and the public session snapshot. Use it from an app that shows a session to a person.

import { … } from "@barry-rocks/sdk/apps";

A connection starts no work until an operation is explicitly invoked.

new AgUiConnection(options): AgUiConnection

Parameter Type
options AgUiConnectionOptions

AgUiConnection

cancel(sessionId, turnId, options?): Promise<TurnSnapshot>

Parameter Type
sessionId string
turnId string
options RequestOptions

Promise<TurnSnapshot>

close(): void

void

queue(input, options?): Promise<{ id: string; state: string; }>

Parameter Type
input RunAgentInput
options RequestOptions

Promise<{ id: string; state: string; }>

run(input, options?): AsyncIterable<AgUiDelivery>

Parameter Type
input RunAgentInput
options RequestOptions

AsyncIterable<AgUiDelivery>

snapshot(sessionId, options?): Promise<PublicSessionSnapshot>

Parameter Type
sessionId string
options RequestOptions

Promise<PublicSessionSnapshot>

subscribe(sessionId, options?): AsyncIterable<AgUiDelivery>

Parameter Type
sessionId string
options AgUiSubscriptionOptions

AsyncIterable<AgUiDelivery>


Why a call to Barry’s API did not produce a result.

status is the HTTP status once response headers arrive, and null before then. A deadline or cancellation can interrupt an unfinished response body. code is the machine-readable reason: the actions routes’ error field, or one of this client’s own (“unreachable”, “timeout”, “cancelled”, “invalid_request”, “malformed_response”, “credential_error”, “service_unconfigured”, “invalid_pagination”, “http_”).

  • Error

new BarryApiError(message, options): BarryApiError

Parameter Type
message string
options { code: string; detail?: unknown; requestId?: string; status: number | null; }
options.code string
options.detail? unknown
options.requestId? string
options.status number | null

BarryApiError

Error.constructor

Property Modifier Type
code readonly string
detail readonly unknown
requestId readonly string | undefined
status readonly number | null
Property Type Description Inherited from
baseUrl string Sessions root, such as http://localhost:4885/api/v2/sessions. -
fetch? {(input, init?): Promise<Response>; (input, init?): Promise<Response>; } - -
maxFrameBytes? number - -
resolveCredential? CredentialResolver Called for each request, including reconnects; the client never caches tokens. ClientCredentials.resolveCredential
secret? string - ClientCredentials.secret
timeoutMs? number HTTP deadline; streaming deadlines end after the response headers arrive. -

Property Type
cursor string
event Event

Controls for one request; pass separately from resource filters or inputs.

Property Type Description Inherited from
after? string | number - -
reconnect? object Opt-in GET reconnects; writes are never retried. At most ten reconnects. -
reconnect.delayMs? number - -
reconnect.maxAttempts number - -
signal? AbortSignal - RequestOptions.signal
timeoutMs? number - RequestOptions.timeoutMs

Property Type Description
resolveCredential? CredentialResolver Called for each request, including reconnects; the client never caches tokens.
secret? string -

Property Type
event SessionEvent | { type: "segment_started" | "resolution_accepted"; } | { snapshot: TurnSnapshot; type: "segment_interrupted" | "turn_finished" | "turn_snapshot"; }
runId string
sequence number
turnId string

Property Type
agUiPackageVersion string
appExtensionVersion number
capabilities object
capabilities.approvalContinuation ApprovalContinuation
capabilities.approveWithEdits boolean
capabilities.attachments boolean
capabilities.frontendTools boolean
capabilities.replay boolean
cursor number
messages Message[]
protocolVersion string
threadId string
turn TurnSnapshot | null

Controls for one request; pass separately from resource filters or inputs.

Property Type
signal? AbortSignal
timeoutMs? number

Property Type
controller AbortController
response? Response

dispose(): void

void

stopDeadline(): void

void

AgUiSubscriptionDelivery = { sessionId: string; snapshot: PublicSessionSnapshot; type: "snapshot"; } | { cursor: string; event: AgUiEvent; sessionId: string; type: "event"; } | { message: string; type: "error"; }


AgUiSubscriptionRequest = z.infer<typeof AgUiSubscriptionRequestSchema>

const AG_UI_PACKAGE_VERSION: "1.0.1" = "1.0.1"


const AgUiSubscriptionRequestSchema: ZodDiscriminatedUnion<[ZodObject<{ after: ZodOptional<ZodString>; sessionId: ZodString; type: ZodLiteral<"subscribe">; }, $strict>, ZodObject<{ type: ZodLiteral<"unsubscribe">; }, $strict>], "type">


const APP_EXTENSION_VERSION: 2 = 2


const PublicSessionSnapshotSchema: ZodObject<{ agUiPackageVersion: ZodString; appExtensionVersion: ZodInt; capabilities: ZodObject<{ approvalContinuation: ZodEnum<{ durable: "durable"; live: "live"; unsupported: "unsupported"; }>; approveWithEdits: ZodBoolean; attachments: ZodBoolean; frontendTools: ZodBoolean; replay: ZodBoolean; }, $strict>; cursor: ZodInt; messages: ZodArray<ZodDiscriminatedUnion<[ZodObject<{ }, $loose>, ZodObject<{ }, $loose>, ZodObject<{ }, $loose>], string>>; protocolVersion: ZodString; threadId: ZodString; turn: ZodNullable<ZodObject<{ error: ZodOptional<ZodString>; id: ZodString; interrupts: ZodArray<ZodObject<{ call: ZodObject<{ description: ZodOptional<…>; id: ZodString; input: ZodUnknown; tool: ZodString; }, $strict>; expiresAt: ZodOptional<ZodString>; id: ZodString; runId: ZodString; status: ZodEnum<{ approved: "approved"; cancelled: "cancelled"; denied: "denied"; expired: "expired"; pending: "pending"; }>; }, $strict>>; result: ZodOptional<ZodUnknown>; reviewPolicy: ZodDiscriminatedUnion<[ZodObject<{ mode: ZodLiteral<"automatic">; }, $strict>, ZodObject<{ expiresAt: ZodOptional<ZodISODateTime>; mode: ZodLiteral<"review_required">; }, $strict>], "mode">; revision: ZodInt; runId: ZodString; sessionId: ZodString; state: ZodEnum<{ cancelled: "cancelled"; completed: "completed"; failed: "failed"; queued: "queued"; recovery_required: "recovery_required"; running: "running"; waiting_for_input: "waiting_for_input"; }>; }, $strict>>; }, $strict>


const PublicTurnSchema: ZodObject<{ error: ZodOptional<ZodString>; id: ZodString; interrupts: ZodArray<ZodObject<{ call: ZodObject<{ description: ZodOptional<ZodString>; id: ZodString; input: ZodUnknown; tool: ZodString; }, $strict>; expiresAt: ZodOptional<ZodString>; id: ZodString; runId: ZodString; status: ZodEnum<{ approved: "approved"; cancelled: "cancelled"; denied: "denied"; expired: "expired"; pending: "pending"; }>; }, $strict>>; result: ZodOptional<ZodUnknown>; reviewPolicy: ZodDiscriminatedUnion<[ZodObject<{ mode: ZodLiteral<"automatic">; }, $strict>, ZodObject<{ expiresAt: ZodOptional<ZodISODateTime>; mode: ZodLiteral<"review_required">; }, $strict>], "mode">; revision: ZodInt; runId: ZodString; sessionId: ZodString; state: ZodEnum<{ cancelled: "cancelled"; completed: "completed"; failed: "failed"; queued: "queued"; recovery_required: "recovery_required"; running: "running"; waiting_for_input: "waiting_for_input"; }>; }, $strict>

agUiContractSchemas(): Record<string, unknown>

Upstream owns AG-UI schemas; Apps owns only Barry’s extensions.

Record<string, unknown>


agUiSse(sessionId, record): string

One cursor may project several wire events; index makes every SSE ID stable.

Parameter Type
sessionId string
record ExecutionEvent

string


approvalDecisions(input): ApprovalDecision[]

Parameter Type
input RunAgentInput

ApprovalDecision[]


attachmentIdsForRun(input): string[]

Uploaded Barry files are references, not generic multimodal AG-UI input.

Parameter Type
input RunAgentInput

string[]


barryExtensionsForRun(input): object

Parameter Type
input RunAgentInput

object

Name Type
attachmentIds string[]
ifActive? "error" | "queue"

executionTranscript(inputs, events): Message[]

Build presentation history only from server-accepted input and committed events.

Parameter Type
inputs object[]
events ExecutionEvent[]

Message[]


messageRunInput(snapshot, content, messageId, runId): RunAgentInput

Build an idempotent user-message run from the server-owned transcript.

Parameter Type
snapshot PublicSessionSnapshot
content string
messageId string
runId string

RunAgentInput


parseAgUiEvent(value): Event

Parameter Type
value unknown

Event


parseRunAgentInput(value, sessionId): RunAgentInput

Validate upstream wire shapes; Barry never forks the AG-UI schema.

Parameter Type
value unknown
sessionId string

RunAgentInput


projectAgUi(sessionId, record): Event[]

Replay is a projection of committed domain events, never another run loop.

Parameter Type
sessionId string
record ExecutionEvent

Event[]

Re-exports CredentialResolver