@asterai/client
Version:
client library for asterai.io
70 lines (69 loc) • 2.08 kB
TypeScript
import { Root } from "protobufjs";
export type AsteraiAgentArgs = {
queryKey: string;
appId: string;
appProtos?: string[];
apiBaseUrl?: string;
};
export type QueryArgs = {
query: string;
conversationId?: string;
};
export declare class AsteraiAgent {
/** The agent application ID. */
readonly appId: string;
private readonly queryKey;
private readonly apiBaseUrl;
private protos;
constructor(args: AsteraiAgentArgs);
/**
* Create a new instance of this agent with a different query key.
*
* Read more about query keys here:
* https://docs.asterai.io/querying_an_app.html#query-keys
*/
withQueryKey(queryKey: string): AsteraiAgent;
query(args: QueryArgs): Promise<QueryResponse>;
/**
* Fetches the agent's summary markdown file, containing
* a natural language description of the functions and
* plugins available in the agent.
*
* This is useful context for agent-to-agent communication.
*/
fetchSummary(): Promise<string>;
}
export type TokenCallback = (token: string) => void;
export type PluginOutputCallback = (output: PluginOutput) => void;
export type PluginOutput = {
name: string;
value: any;
};
export type EndCallback = (state: EndState) => void;
export type EndState = {
reason: EndReason;
};
export type EndReason = "finished" | "aborted";
/**
* The response object for an agent's query.
*/
export declare class QueryResponse {
private response;
private abortController;
private protos;
private isActive;
private onTokenCallbacks;
private onPluginOutputCallbacks;
private onEndCallbacks;
constructor(response: Response, abortController: AbortController, protos: Root[]);
private setupResponse;
onToken(callback: TokenCallback): void;
onPluginOutput(callback: PluginOutputCallback): void;
onEnd(callback: EndCallback): void;
text(): Promise<string>;
private callOnToken;
private callPluginOutput;
private callOnEnd;
abort(): void;
private decodePluginOutput;
}