@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";Classes
Section titled “Classes”AgUiConnection
Section titled “AgUiConnection”A connection starts no work until an operation is explicitly invoked.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new AgUiConnection(
options):AgUiConnection
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
options |
AgUiConnectionOptions |
Returns
Section titled “Returns”Methods
Section titled “Methods”cancel()
Section titled “cancel()”cancel(
sessionId,turnId,options?):Promise<TurnSnapshot>
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
sessionId |
string |
turnId |
string |
options |
RequestOptions |
Returns
Section titled “Returns”Promise<TurnSnapshot>
close()
Section titled “close()”close():
void
Returns
Section titled “Returns”void
queue()
Section titled “queue()”queue(
input,options?):Promise<{id:string;state:string; }>
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
input |
RunAgentInput |
options |
RequestOptions |
Returns
Section titled “Returns”Promise<{ id: string; state: string; }>
run(
input,options?):AsyncIterable<AgUiDelivery>
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
input |
RunAgentInput |
options |
RequestOptions |
Returns
Section titled “Returns”AsyncIterable<AgUiDelivery>
snapshot()
Section titled “snapshot()”snapshot(
sessionId,options?):Promise<PublicSessionSnapshot>
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
sessionId |
string |
options |
RequestOptions |
Returns
Section titled “Returns”Promise<PublicSessionSnapshot>
subscribe()
Section titled “subscribe()”subscribe(
sessionId,options?):AsyncIterable<AgUiDelivery>
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
sessionId |
string |
options |
AgUiSubscriptionOptions |
Returns
Section titled “Returns”AsyncIterable<AgUiDelivery>
BarryApiError
Section titled “BarryApiError”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_
Extends
Section titled “Extends”Error
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new BarryApiError(
message,options):BarryApiError
Parameters
Section titled “Parameters”| 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 |
Returns
Section titled “Returns”Overrides
Section titled “Overrides”Error.constructor
Properties
Section titled “Properties”| Property | Modifier | Type |
|---|---|---|
code |
readonly |
string |
detail |
readonly |
unknown |
requestId |
readonly |
string | undefined |
status |
readonly |
number | null |
Interfaces
Section titled “Interfaces”AgUiConnectionOptions
Section titled “AgUiConnectionOptions”Extends
Section titled “Extends”Properties
Section titled “Properties”| 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. | - |
AgUiDelivery
Section titled “AgUiDelivery”Properties
Section titled “Properties”| Property | Type |
|---|---|
cursor |
string |
event |
Event |
AgUiSubscriptionOptions
Section titled “AgUiSubscriptionOptions”Controls for one request; pass separately from resource filters or inputs.
Extends
Section titled “Extends”Properties
Section titled “Properties”| 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 |
ClientCredentials
Section titled “ClientCredentials”Extended by
Section titled “Extended by”Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
resolveCredential? |
CredentialResolver |
Called for each request, including reconnects; the client never caches tokens. |
secret? |
string |
- |
ExecutionEvent
Section titled “ExecutionEvent”Properties
Section titled “Properties”| Property | Type |
|---|---|
event |
SessionEvent | { type: "segment_started" | "resolution_accepted"; } | { snapshot: TurnSnapshot; type: "segment_interrupted" | "turn_finished" | "turn_snapshot"; } |
runId |
string |
sequence |
number |
turnId |
string |
PublicSessionSnapshot
Section titled “PublicSessionSnapshot”Properties
Section titled “Properties”| 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 |
RequestOptions
Section titled “RequestOptions”Controls for one request; pass separately from resource filters or inputs.
Extended by
Section titled “Extended by”Properties
Section titled “Properties”| Property | Type |
|---|---|
signal? |
AbortSignal |
timeoutMs? |
number |
RequestScope
Section titled “RequestScope”Properties
Section titled “Properties”| Property | Type |
|---|---|
controller |
AbortController |
response? |
Response |
Methods
Section titled “Methods”dispose()
Section titled “dispose()”dispose():
void
Returns
Section titled “Returns”void
stopDeadline()
Section titled “stopDeadline()”stopDeadline():
void
Returns
Section titled “Returns”void
Type Aliases
Section titled “Type Aliases”AgUiSubscriptionDelivery
Section titled “AgUiSubscriptionDelivery”AgUiSubscriptionDelivery = {
sessionId:string;snapshot:PublicSessionSnapshot;type:"snapshot"; } | {cursor:string;event:AgUiEvent;sessionId:string;type:"event"; } | {message:string;type:"error"; }
AgUiSubscriptionRequest
Section titled “AgUiSubscriptionRequest”AgUiSubscriptionRequest =
z.infer<typeofAgUiSubscriptionRequestSchema>
Variables
Section titled “Variables”AG_UI_PACKAGE_VERSION
Section titled “AG_UI_PACKAGE_VERSION”
constAG_UI_PACKAGE_VERSION:"1.0.1"="1.0.1"
AgUiSubscriptionRequestSchema
Section titled “AgUiSubscriptionRequestSchema”
constAgUiSubscriptionRequestSchema:ZodDiscriminatedUnion<[ZodObject<{after:ZodOptional<ZodString>;sessionId:ZodString;type:ZodLiteral<"subscribe">; },$strict>,ZodObject<{type:ZodLiteral<"unsubscribe">; },$strict>],"type">
APP_EXTENSION_VERSION
Section titled “APP_EXTENSION_VERSION”
constAPP_EXTENSION_VERSION:2=2
PublicSessionSnapshotSchema
Section titled “PublicSessionSnapshotSchema”
constPublicSessionSnapshotSchema: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>
PublicTurnSchema
Section titled “PublicTurnSchema”
constPublicTurnSchema: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>
Functions
Section titled “Functions”agUiContractSchemas()
Section titled “agUiContractSchemas()”agUiContractSchemas():
Record<string,unknown>
Upstream owns AG-UI schemas; Apps owns only Barry’s extensions.
Returns
Section titled “Returns”Record<string, unknown>
agUiSse()
Section titled “agUiSse()”agUiSse(
sessionId,record):string
One cursor may project several wire events; index makes every SSE ID stable.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
sessionId |
string |
record |
ExecutionEvent |
Returns
Section titled “Returns”string
approvalDecisions()
Section titled “approvalDecisions()”approvalDecisions(
input):ApprovalDecision[]
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
input |
RunAgentInput |
Returns
Section titled “Returns”attachmentIdsForRun()
Section titled “attachmentIdsForRun()”attachmentIdsForRun(
input):string[]
Uploaded Barry files are references, not generic multimodal AG-UI input.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
input |
RunAgentInput |
Returns
Section titled “Returns”string[]
barryExtensionsForRun()
Section titled “barryExtensionsForRun()”barryExtensionsForRun(
input):object
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
input |
RunAgentInput |
Returns
Section titled “Returns”object
| Name | Type |
|---|---|
attachmentIds |
string[] |
ifActive? |
"error" | "queue" |
executionTranscript()
Section titled “executionTranscript()”executionTranscript(
inputs,events):Message[]
Build presentation history only from server-accepted input and committed events.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
inputs |
object[] |
events |
ExecutionEvent[] |
Returns
Section titled “Returns”Message[]
messageRunInput()
Section titled “messageRunInput()”messageRunInput(
snapshot,content,messageId,runId):RunAgentInput
Build an idempotent user-message run from the server-owned transcript.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
snapshot |
PublicSessionSnapshot |
content |
string |
messageId |
string |
runId |
string |
Returns
Section titled “Returns”RunAgentInput
parseAgUiEvent()
Section titled “parseAgUiEvent()”parseAgUiEvent(
value):Event
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
unknown |
Returns
Section titled “Returns”Event
parseRunAgentInput()
Section titled “parseRunAgentInput()”parseRunAgentInput(
value,sessionId):RunAgentInput
Validate upstream wire shapes; Barry never forks the AG-UI schema.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
unknown |
sessionId |
string |
Returns
Section titled “Returns”RunAgentInput
projectAgUi()
Section titled “projectAgUi()”projectAgUi(
sessionId,record):Event[]
Replay is a projection of committed domain events, never another run loop.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
sessionId |
string |
record |
ExecutionEvent |
Returns
Section titled “Returns”Event[]
References
Section titled “References”CredentialResolver
Section titled “CredentialResolver”Re-exports CredentialResolver