AIDK API Reference / aidk-client / defineChannel
Function: defineChannel() ​
ts
function defineChannel<TIncoming, TOutgoing>(name: string): ChannelDefinition<TIncoming, TOutgoing>;Defined in: packages/client/src/channel.ts:207
Define a channel contract
Type Parameters ​
| Type Parameter | Default type |
|---|---|
TIncoming extends Record<string, unknown> | Record<string, unknown> |
TOutgoing extends Record<string, unknown> | Record<string, unknown> |
Parameters ​
| Parameter | Type | Description |
|---|---|---|
name | string | Channel name (used for both subscribe and publish) |
Returns ​
ChannelDefinition<TIncoming, TOutgoing>
Channel definition that can be connected to a client
Example ​
typescript
// Define with full types
const TodoChannel = defineChannel<
{ state_changed: { tasks: Task[] }; task_created: { task: Task } },
{ create_task: { title: string }; toggle_complete: { task_id: string } }
>('todo-list');
// Or define incrementally
const TodoChannel = defineChannel('todo-list')
.incoming<{ state_changed: { tasks: Task[] } }>()
.outgoing<{ create_task: { title: string } }>();