vitrus
Version:
TypeScript client for interfacing with the Vitrus SDK
176 lines (175 loc) • 4.95 kB
TypeScript
/**
* Vitrus SDK
*
* A TypeScript client for interfacing with the Vitrus WebSocket server.
* Provides an Actor/Agent communication model with workflow orchestration.
*/
interface JSONSchema {
type: 'object' | 'string' | 'number' | 'boolean' | 'array';
description?: string;
properties?: Record<string, JSONSchema>;
required?: string[];
items?: JSONSchema;
additionalProperties?: boolean;
}
interface OpenAITool {
name: string;
description?: string;
parameters: JSONSchema;
strict?: boolean;
}
interface WorkflowDefinition {
type: 'function';
function: OpenAITool;
}
declare class Actor {
private vitrus;
private name;
private metadata;
private commandHandlers;
constructor(vitrus: Vitrus, name: string, metadata?: any);
/**
* Register a command handler
*/
on(commandName: string, handler: Function): Actor;
/**
* Run a command on an actor
*/
run(commandName: string, ...args: any[]): Promise<any>;
/**
* Get actor metadata
*/
getMetadata(): any;
/**
* Update actor metadata
*/
updateMetadata(newMetadata: any): void;
/**
* Disconnect the actor if the SDK is currently connected as this actor.
*/
disconnect(): void;
}
declare class Scene {
private vitrus;
private sceneId;
constructor(vitrus: Vitrus, sceneId: string);
/**
* Set a structure to the scene
*/
set(structure: any): void;
/**
* Add an object to the scene
*/
add(object: any): void;
/**
* Update an object in the scene
*/
update(params: {
id: string;
[key: string]: any;
}): void;
/**
* Remove an object from the scene
*/
remove(objectId: string): void;
/**
* Get the scene
*/
get(): any;
}
declare class Vitrus {
private ws;
private apiKey;
private worldId?;
private clientId;
private connected;
private authenticated;
private messageHandlers;
private pendingRequests;
private actorCommandHandlers;
private actorCommandSignatures;
private actorMetadata;
private baseUrl;
private debug;
private actorName?;
private connectionPromise;
private _connectionReject;
private redisChannel?;
private static readonly OPEN;
constructor({ apiKey, world, baseUrl, debug }: {
apiKey: string;
world?: string;
baseUrl?: string;
debug?: boolean;
});
/**
* Connect to the WebSocket server with authentication
* @internal This is mainly for internal use, users should use authenticate()
*/
connect(actorName?: string, metadata?: any): Promise<void>;
private _establishWebSocketConnection;
private createBrowserWsWrapper;
private waitForConnection;
private waitForAuthentication;
private sendMessage;
private handleMessage;
private handleCommand;
private sendResponse;
/**
* Register a command with the server
*/
registerCommand(actorName: string, commandName: string, parameterTypes: Array<string>): Promise<void>;
private generateRequestId;
/**
* Authenticate with the API
*/
authenticate(actorName?: string, metadata?: any): Promise<boolean>;
/**
* Register a command handler for an actor
*/
registerActorCommandHandler(actorName: string, commandName: string, handler: Function, parameterTypes?: Array<string>): void;
/**
* Create or get an actor
* If options (metadata) are provided, connects and authenticates as this actor.
* If only name is provided, returns a handle for an agent to interact with.
*/
actor(name: string, options?: any): Promise<Actor>;
/**
* Get a scene
*/
scene(sceneId: string): Scene;
/**
* Run a command on an actor
*/
runCommand(actorName: string, commandName: string, args: any[]): Promise<any>;
/**
* Run a workflow
*/
workflow(workflowName: string, args?: any): Promise<any>;
/**
* Upload an image
*/
upload_image(image: any, filename?: string): Promise<string>;
/**
* Add a record
*/
add_record(data: any, name?: string): Promise<string>;
/**
* List available workflows on the server, including their definitions (OpenAI Tool Schema)
*/
list_workflows(): Promise<WorkflowDefinition[]>;
/**
* Helper to register commands that might have been added via actor.on()
* *before* the initial authentication for that actor completed.
*/
private registerPendingCommands;
getIsAuthenticated(): boolean;
getActorName(): string | undefined;
getDebug(): boolean;
/**
* Disconnects the WebSocket if the SDK is currently authenticated as the specified actor.
* @param actorName The name of the actor to disconnect.
*/
disconnectIfActor(actorName: string): void;
}
export default Vitrus;