AIDK API Reference / aidk-client / EngineClient
Class: EngineClient ​
Defined in: packages/client/src/engine-client.ts:232
Constructors ​
Constructor ​
new EngineClient(config: EngineClientConfig): EngineClient;Defined in: packages/client/src/engine-client.ts:238
Parameters ​
| Parameter | Type |
|---|---|
config | EngineClientConfig |
Returns ​
EngineClient
Methods ​
disconnect() ​
disconnect(): void;Defined in: packages/client/src/engine-client.ts:767
Returns ​
void
dispose() ​
dispose(): void;Defined in: packages/client/src/engine-client.ts:848
Returns ​
void
execute() ​
execute(id: string, input: EngineInput): Promise<ExecutionResult>;Defined in: packages/client/src/engine-client.ts:409
Execute (non-streaming)
Parameters ​
| Parameter | Type |
|---|---|
id | string |
input | EngineInput |
Returns ​
Promise<ExecutionResult>
getConnectionInfo() ​
getConnectionInfo(): TransportInfo;Defined in: packages/client/src/engine-client.ts:755
Returns ​
getConnectionState() ​
getConnectionState(): TransportState;Defined in: packages/client/src/engine-client.ts:751
Returns ​
getExecution() ​
getExecution(executionId: string): Promise<Execution>;Defined in: packages/client/src/engine-client.ts:801
Parameters ​
| Parameter | Type |
|---|---|
executionId | string |
Returns ​
Promise<Execution>
getExecutions() ​
getExecutions(params?: Record<string, unknown>): Promise<Execution[]>;Defined in: packages/client/src/engine-client.ts:775
Parameters ​
| Parameter | Type |
|---|---|
params? | Record<string, unknown> |
Returns ​
Promise<Execution[]>
getMetrics() ​
getMetrics(params?: Record<string, unknown>): Promise<ExecutionMetrics[]>;Defined in: packages/client/src/engine-client.ts:818
Parameters ​
| Parameter | Type |
|---|---|
params? | Record<string, unknown> |
Returns ​
Promise<ExecutionMetrics[]>
getSessionId() ​
getSessionId(): string;Defined in: packages/client/src/engine-client.ts:360
Returns ​
string
getUserId() ​
getUserId(): string | undefined;Defined in: packages/client/src/engine-client.ts:364
Returns ​
string | undefined
isConnected() ​
isConnected(): boolean;Defined in: packages/client/src/engine-client.ts:759
Returns ​
boolean
publish() ​
publish<T>(
channel: string,
type: string,
payload?: unknown,
_options?: {
excludeSender?: boolean;
}): Promise<T>;Defined in: packages/client/src/engine-client.ts:512
Publish an event to a channel
Type Parameters ​
| Type Parameter | Default type |
|---|---|
T | unknown |
Parameters ​
| Parameter | Type |
|---|---|
channel | string |
type | string |
payload? | unknown |
_options? | { excludeSender?: boolean; } |
_options.excludeSender? | boolean |
Returns ​
Promise<T>
reconnect() ​
reconnect(): void;Defined in: packages/client/src/engine-client.ts:763
Returns ​
void
sendMessage() ​
sendMessage(message: {
content?: unknown;
type: string;
}, options?: {
targetPid?: string;
}): Promise<void>;Defined in: packages/client/src/engine-client.ts:730
Send a message to a running execution.
Messages are delivered to the execution's onMessage lifecycle hooks and queued for TickState.queuedMessages on the next render tick.
Messages are routed by sessionId (automatic via channel subscription). If multiple executions run in the same session, you can optionally specify a targetPid to target a specific execution.
Parameters ​
| Parameter | Type | Description |
|---|---|---|
message | { content?: unknown; type: string; } | The message to send (type and content) |
message.content? | unknown | - |
message.type? | string | - |
options? | { targetPid?: string; } | Optional targeting options |
options.targetPid? | string | - |
Returns ​
Promise<void>
Promise resolving when message is acknowledged
Example ​
// Send user feedback to the current session's execution
await client.sendMessage({
type: 'user_feedback',
content: { priority: 'high', focus: 'security' }
});
// Request execution to stop
await client.sendMessage({
type: 'stop',
content: { reason: 'User requested stop' }
});
// Target a specific execution (when multiple run in same session)
await client.sendMessage(
{ type: 'feedback', content: { ... } },
{ targetPid: 'exec_abc123' }
);sendToolConfirmation() ​
sendToolConfirmation(
toolUseId: string,
confirmed: boolean,
options: {
always?: boolean;
}): Promise<{
success: boolean;
toolUseId: string;
}>;Defined in: packages/client/src/engine-client.ts:655
Send a tool confirmation response to the server.
Called when the user confirms or denies a tool execution request. The server is waiting for this response before proceeding with execution.
Parameters ​
| Parameter | Type | Description |
|---|---|---|
toolUseId | string | ID of the tool call being confirmed |
confirmed | boolean | Whether the user confirmed the execution |
options | { always?: boolean; } | Additional options |
options.always? | boolean | If true, remember this decision for future calls |
Returns ​
Promise<{ success: boolean; toolUseId: string; }>
Confirmation result
Example ​
// User confirms tool execution
await client.sendToolConfirmation(toolCall.id, true);
// User denies tool execution
await client.sendToolConfirmation(toolCall.id, false);
// User says "always allow this tool"
await client.sendToolConfirmation(toolCall.id, true, { always: true });
// User says "never allow this tool"
await client.sendToolConfirmation(toolCall.id, false, { always: true });sendToolResult() ​
sendToolResult(
toolUseId: string,
content: unknown,
options: {
error?: string;
isError?: boolean;
}): Promise<{
success: boolean;
toolUseId: string;
}>;Defined in: packages/client/src/engine-client.ts:591
Send a tool result back to the server.
Used when a client-executed tool (render, action) needs to return a result. For example, when a form is submitted and the server is waiting for the response.
Parameters ​
| Parameter | Type | Description |
|---|---|---|
toolUseId | string | The toolUseId from the tool_call event |
content | unknown | The result content (ContentBlock[] or string or object) |
options | { error?: string; isError?: boolean; } | Additional options |
options.error? | string | - |
options.isError? | boolean | - |
Returns ​
Promise<{ success: boolean; toolUseId: string; }>
Promise resolving when result is acknowledged
Example ​
// In a form component after user submits
await client.sendToolResult(toolCall.id, { name: 'John', age: 30 });
// With explicit content blocks
await client.sendToolResult(toolCall.id, [
{ type: 'json', text: JSON.stringify(formData), data: formData }
]);
// For errors
await client.sendToolResult(toolCall.id, 'Validation failed', { isError: true });stream() ​
stream(id: string, input: EngineInput): AsyncGenerator<EngineStreamEvent>;Defined in: packages/client/src/engine-client.ts:433
Stream execution
Parameters ​
| Parameter | Type |
|---|---|
id | string |
input | EngineInput |
Returns ​
AsyncGenerator<EngineStreamEvent>
subscribe() ​
subscribe(channelFilter: string | string[], handler: (event: ChannelEvent) => void): () => void;Defined in: packages/client/src/engine-client.ts:505
Subscribe to channel events
Parameters ​
| Parameter | Type |
|---|---|
channelFilter | string | string[] |
handler | (event: ChannelEvent) => void |
Returns ​
(): void;Returns ​
void
updateConfig() ​
updateConfig(updates: Partial<EngineClientConfig>): void;Defined in: packages/client/src/engine-client.ts:323
Update client configuration. Only triggers reconnect if userId or threadId actually changed.
Parameters ​
| Parameter | Type |
|---|---|
updates | Partial<EngineClientConfig> |
Returns ​
void