agents
Version:
A home for your AI agents
98 lines (96 loc) • 3.41 kB
TypeScript
import {
_ as TranscriptMessage,
c as InboundEvent,
m as ResponseChunk,
n as ConversationInfo,
p as Participant,
r as ConversationOperation,
y as TurnStatus
} from "../../../protocol-CukuI73M.js";
//#region src/experimental/channels/web/client.d.ts
type WebChannelClientState = {
connected: boolean /** The conversation this client follows, once connected. */;
conversationId?: string /** Conversation operations this client may send. */;
operations: ConversationOperation[];
you?: Participant /** The transcript, with the output of running turns applied. */;
messages: TranscriptMessage[] /** Turns that are queued, running or awaiting input. */;
turns: TurnStatus[] /** The agent's conversations, once listed or pushed. */;
conversations?: ConversationInfo[];
};
/** An inbound event; the client fills in `eventId` when it is left out. */
type ClientEvent = InboundEvent extends infer E
? E extends {
eventId: string;
}
? Omit<E, "eventId"> & {
eventId?: string;
}
: never
: never;
/** Turn statuses and response output, frame by frame. */
type WebChannelActivity =
| {
type: "turn";
turn: TurnStatus;
}
| {
type: "chunks";
responseId: string;
turnId: string;
chunks: ResponseChunk[];
}
| {
type: "end";
responseId: string;
turnId: string;
state: "ended" | "interrupted" | "not-found";
};
type WebChannelClientOptions = {
/**
* The URL to reconnect to once the client follows another conversation.
* Default: the gateway's default, `/channels/<route>/<conversation>`.
*/
followUrl?(url: URL, conversationId: string): URL;
};
/** A browser client for the Web Channel, with reconnects. */
declare class WebChannelClient {
#private;
constructor(url: string | URL, options?: WebChannelClientOptions);
get state(): WebChannelClientState;
/** Calls the listener on every change. Returns the unsubscribe. */
subscribe(listener: (state: WebChannelClientState) => void): () => void;
/**
* Calls the listener with each turn status, response chunk and response
* ending as it arrives, including chunks that arrive after the turn has
* settled. Returns the unsubscribe.
*/
onActivity(listener: (activity: WebChannelActivity) => void): () => void;
/** The chunks received so far for a response this client is reading. */
chunksOf(responseId: string): readonly ResponseChunk[] | undefined;
/**
* Resolves once the agent accepts the event, and rejects if it refuses.
* While disconnected the event waits, and it is sent again after a
* reconnect until acknowledged; Channels drops repeats by `eventId`.
* Rejects once the client is closed.
*/
send(event: ClientEvent): Promise<void>;
/** The agent's conversations. Rejects while disconnected or closed. */
listConversations(): Promise<ConversationInfo[]>;
/**
* Follow another conversation: reconnect to it, as after a create or
* fork. Events still waiting for an ack are rejected, since they were
* meant for the conversation left behind.
*/
follow(conversationId: string): void;
/** Closes the connection and rejects events still waiting for an ack. */
close(): void;
}
//#endregion
export {
ClientEvent,
WebChannelActivity,
WebChannelClient,
WebChannelClientOptions,
WebChannelClientState
};
//# sourceMappingURL=client.d.ts.map