Skip to content

AIDK API Reference / aidk-client / EngineClient

Class: EngineClient ​

Defined in: packages/client/src/engine-client.ts:232

Constructors ​

Constructor ​

ts
new EngineClient(config: EngineClientConfig): EngineClient;

Defined in: packages/client/src/engine-client.ts:238

Parameters ​

ParameterType
configEngineClientConfig

Returns ​

EngineClient

Methods ​

disconnect() ​

ts
disconnect(): void;

Defined in: packages/client/src/engine-client.ts:767

Returns ​

void


dispose() ​

ts
dispose(): void;

Defined in: packages/client/src/engine-client.ts:848

Returns ​

void


execute() ​

ts
execute(id: string, input: EngineInput): Promise<ExecutionResult>;

Defined in: packages/client/src/engine-client.ts:409

Execute (non-streaming)

Parameters ​

ParameterType
idstring
inputEngineInput

Returns ​

Promise<ExecutionResult>


getConnectionInfo() ​

ts
getConnectionInfo(): TransportInfo;

Defined in: packages/client/src/engine-client.ts:755

Returns ​

TransportInfo


getConnectionState() ​

ts
getConnectionState(): TransportState;

Defined in: packages/client/src/engine-client.ts:751

Returns ​

TransportState


getExecution() ​

ts
getExecution(executionId: string): Promise<Execution>;

Defined in: packages/client/src/engine-client.ts:801

Parameters ​

ParameterType
executionIdstring

Returns ​

Promise<Execution>


getExecutions() ​

ts
getExecutions(params?: Record<string, unknown>): Promise<Execution[]>;

Defined in: packages/client/src/engine-client.ts:775

Parameters ​

ParameterType
params?Record<string, unknown>

Returns ​

Promise<Execution[]>


getMetrics() ​

ts
getMetrics(params?: Record<string, unknown>): Promise<ExecutionMetrics[]>;

Defined in: packages/client/src/engine-client.ts:818

Parameters ​

ParameterType
params?Record<string, unknown>

Returns ​

Promise<ExecutionMetrics[]>


getSessionId() ​

ts
getSessionId(): string;

Defined in: packages/client/src/engine-client.ts:360

Returns ​

string


getUserId() ​

ts
getUserId(): string | undefined;

Defined in: packages/client/src/engine-client.ts:364

Returns ​

string | undefined


isConnected() ​

ts
isConnected(): boolean;

Defined in: packages/client/src/engine-client.ts:759

Returns ​

boolean


publish() ​

ts
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 ParameterDefault type
Tunknown

Parameters ​

ParameterType
channelstring
typestring
payload?unknown
_options?{ excludeSender?: boolean; }
_options.excludeSender?boolean

Returns ​

Promise<T>


reconnect() ​

ts
reconnect(): void;

Defined in: packages/client/src/engine-client.ts:763

Returns ​

void


sendMessage() ​

ts
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 ​

ParameterTypeDescription
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 ​

typescript
// 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() ​

ts
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 ​

ParameterTypeDescription
toolUseIdstringID of the tool call being confirmed
confirmedbooleanWhether the user confirmed the execution
options{ always?: boolean; }Additional options
options.always?booleanIf true, remember this decision for future calls

Returns ​

Promise<{ success: boolean; toolUseId: string; }>

Confirmation result

Example ​

typescript
// 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() ​

ts
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 ​

ParameterTypeDescription
toolUseIdstringThe toolUseId from the tool_call event
contentunknownThe 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 ​

typescript
// 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() ​

ts
stream(id: string, input: EngineInput): AsyncGenerator<EngineStreamEvent>;

Defined in: packages/client/src/engine-client.ts:433

Stream execution

Parameters ​

ParameterType
idstring
inputEngineInput

Returns ​

AsyncGenerator<EngineStreamEvent>


subscribe() ​

ts
subscribe(channelFilter: string | string[], handler: (event: ChannelEvent) => void): () => void;

Defined in: packages/client/src/engine-client.ts:505

Subscribe to channel events

Parameters ​

ParameterType
channelFilterstring | string[]
handler(event: ChannelEvent) => void

Returns ​

ts
(): void;
Returns ​

void


updateConfig() ​

ts
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 ​

ParameterType
updatesPartial<EngineClientConfig>

Returns ​

void

Released under the MIT License.