AIDK API Reference / aidk-shared
aidk-shared ​
AIDK Shared Types ​
Platform-independent type definitions shared across all AIDK packages. These types define the core data structures for messages, content blocks, tools, and streaming.
Content Blocks ​
Content blocks are discriminated unions representing all content types:
- Text - Plain text content
- Image/Audio/Video - Media content with base64 or URL sources
- ToolUse/ToolResult - Tool call requests and responses
- Code - Executable code blocks
Messages ​
Messages represent conversation entries with roles:
user- Human inputassistant- Model responsessystem- System promptstool_result- Tool execution results
Usage ​
import type { Message, ContentBlock, ToolDefinition } from 'aidk-shared';
const message: Message = {
role: 'user',
content: [{ type: 'text', text: 'Hello!' }]
};See ​
- ContentBlock - All content block types
- Message - Conversation message structure
- ToolDefinition - Tool schema definition
Enumerations ​
| Enumeration | Description |
|---|---|
| ToolExecutionType | Tool execution type determines how and where the tool is CONFIGURED to execute. This is the tool's definition - where it SHOULD run. |
| ToolIntent | Tool intent describes WHAT the tool does, independent of WHERE it runs. Used by clients to determine how to render/handle tool calls. |
Classes ​
| Class | Description |
|---|---|
| AbortError | Error thrown when an operation is aborted or cancelled. |
| AdapterError | Error thrown by model adapters for provider-specific errors. |
| AIDKError | Base class for all AIDK errors. Provides consistent structure, serialization, and type identification. |
| ContextError | Error thrown when context is missing or invalid. |
| NotFoundError | Error thrown when a required resource cannot be found. |
| ReactivityError | Error thrown for reactivity/signal system issues. |
| StateError | Error thrown when an operation is attempted in an invalid state. |
| TransportError | Error thrown for network/transport failures. |
| ValidationError | Error thrown when input validation fails. |
Interfaces ​
| Interface | Description |
|---|---|
| ClientToolDefinition | Client tool definition - sent by clients to declare available tools. Simplified interface for client-provided tools. |
| DevToolsConfig | Configuration for DevTools integration in the engine |
| DevToolsEventBase | Base fields present on all DevTools events |
| DTCompiledEvent | Base fields present on all DevTools events |
| DTContentDeltaEvent | Base fields present on all DevTools events |
| DTExecutionEndEvent | Base fields present on all DevTools events |
| DTExecutionStartEvent | Base fields present on all DevTools events |
| DTModelRequestEvent | Base fields present on all DevTools events |
| DTModelResponseEvent | Base fields present on all DevTools events |
| DTModelStartEvent | Base fields present on all DevTools events |
| DTProcedureEndEvent | Emitted when a procedure completes successfully. |
| DTProcedureErrorEvent | Emitted when a procedure fails with an error. |
| DTProcedureStartEvent | Emitted when any procedure starts execution. This captures model calls, tool executions, engine operations, etc. |
| DTProviderRequestEvent | Base fields present on all DevTools events |
| DTProviderResponseEvent | Base fields present on all DevTools events |
| DTReasoningDeltaEvent | Base fields present on all DevTools events |
| DTStateChangeEvent | Base fields present on all DevTools events |
| DTTickEndEvent | Base fields present on all DevTools events |
| DTTickStartEvent | Base fields present on all DevTools events |
| DTToolCallEvent | Base fields present on all DevTools events |
| DTToolConfirmationEvent | Base fields present on all DevTools events |
| DTToolResultEvent | Base fields present on all DevTools events |
| ExecutionContextFields | Execution context fields for events in an execution tree |
| ModelConfig | Model configuration - simplified platform-independent structure. |
| ModelInput | Model input - simplified platform-independent structure. |
| ModelOutput | Model output - simplified platform-independent structure. |
| SerializedAIDKError | Serialized error format for transport |
| TimelineEntry | Timeline entry - represents a message or event in the conversation. |
| TokenUsage | Token usage information (normalized across providers). |
| ToolCall | Tool call - represents a tool call made by the model. |
| ToolConfirmationResponse | Response from client when confirming/denying a tool execution. Sent via POST /api/channels/tool-confirmation. |
| ToolConfirmationResult | Result of a tool confirmation, includes tool metadata for hooks/events. Used internally and in stream events. |
| ToolDefinition | Simplified tool definition - platform-independent base structure. Used for direct tool execution from clients. |
| ToolResult | Tool result - represents the result of a tool execution. |
Type Aliases ​
| Type Alias | Description |
|---|---|
| - | |
| - | |
| AIDKErrorCode | Error codes for programmatic error handling. Format: CATEGORY_SPECIFIC (e.g., ABORT_CANCELLED, NOT_FOUND_MODEL) |
| DevToolsBatchSubscriber | Batch subscriber callback type |
| DevToolsEvent | All DevTools event types |
| DevToolsSubscriber | Subscriber callback type |
| - | |
| ModelToolReference | Reference to a tool that can be used with a model. Can be a string (tool name/id), ToolDefinition, or ClientToolDefinition. |
| ResourceType | Resource types that can be "not found" |
| ToolExecutor | Tool executor identifies WHO actually executed a tool. |
Variables ​
| Variable | Description |
|---|---|
| CONTENT_COMPONENT_SYMBOL | Symbol used to mark content components. |
| DEVTOOLS_CHANNEL | DevTools channel name - used for engine to emit events |
| devToolsEmitter | Singleton DevTools emitter instance. |
| HOST_PRIMITIVE_SYMBOL | Symbol used to mark host primitive components. These are structural primitives that should be handled by the renderer, not executed as functions. |
| SEMANTIC_COMPONENT_SYMBOL | Symbol used to mark semantic components. |
Functions ​
| Function | Description |
|---|---|
| ensureError | Ensure a value is an Error, wrapping if necessary. Useful for catch blocks that might receive non-Error values. |
| hasSymbol | Check if a value has a specific symbol marker. |
| isAbortError | Check if error is an AbortError |
| isAdapterError | Check if error is an AdapterError |
| isAIDKError | Check if error is any AIDK error |
| isContentBlock | Check if value is a ContentBlock. Validates that type is a known block type, not just any object with a type property. |
| isContentComponent | Check if a value is a content component. |
| isContextError | Check if error is a ContextError |
| isHostPrimitive | Check if a value is a host primitive component. Minification-safe - uses symbol identity, not function name. |
| isMessage | Check if value is a Message |
| isNotFoundError | Check if error is a NotFoundError |
| isReactivityError | Check if error is a ReactivityError |
| isSemanticComponent | Check if a value is a semantic component. |
| isStateError | Check if error is a StateError |
| isTransportError | Check if error is a TransportError |
| isValidationError | Check if error is a ValidationError |
| markAsContentComponent | Mark a function as a content component. |
| markAsHostPrimitive | Mark a function as a host primitive. Host primitives are structural components that should be handled by the renderer directly, not executed as functions. |
| markAsSemanticComponent | Mark a function as a semantic component. |
| markWithSymbol | Mark a function with a symbol for identity checking. Returns the same function with the symbol attached. |
| normalizeContentArray | Normalize ContentInputArray to ContentBlock[] |
| normalizeContentInput | Normalize ContentInput to ContentBlock |
| normalizeDevToolsConfig | Normalize DevTools config from various input formats. |
| normalizeMessageInput | Normalize MessageInput to Message[] |
| wrapAsAIDKError | Wrap any error as an AIDK error if it isn't already. |
References ​
AssistantAllowedBlock ​
Re-exports AssistantAllowedBlock
AssistantMessage ​
Re-exports AssistantMessage
AudioBlock ​
Re-exports AudioBlock
AudioMimeType ​
Re-exports AudioMimeType
Base64Source ​
Re-exports Base64Source
base64SourceToBuffer ​
Re-exports base64SourceToBuffer
BaseContentBlock ​
Re-exports BaseContentBlock
BaseMediaSource ​
Re-exports BaseMediaSource
BlockType ​
Re-exports BlockType
BlockTypes ​
Re-exports BlockTypes
bufferToBase64Source ​
Re-exports bufferToBase64Source
CodeBlock ​
Re-exports CodeBlock
CodeExecutionResultBlock ​
Re-exports CodeExecutionResultBlock
CodeLanguage ​
Re-exports CodeLanguage
ContentBlock ​
Re-exports ContentBlock
ContentDeltaEvent ​
Re-exports ContentDeltaEvent
ContentEndEvent ​
Re-exports ContentEndEvent
ContentEvent ​
Re-exports ContentEvent
ContentInput ​
Re-exports ContentInput
ContentInputArray ​
Re-exports ContentInputArray
ContentStartEvent ​
Re-exports ContentStartEvent
createAssistantMessage ​
Re-exports createAssistantMessage
createEventMessage ​
Re-exports createEventMessage
createSystemMessage ​
Re-exports createSystemMessage
createToolMessage ​
Re-exports createToolMessage
createUserMessage ​
Re-exports createUserMessage
CsvBlock ​
Re-exports CsvBlock
DataBlock ​
Re-exports DataBlock
DocumentBlock ​
Re-exports DocumentBlock
DocumentMimeType ​
Re-exports DocumentMimeType
EngineErrorEvent ​
Re-exports EngineErrorEvent
EngineEvent ​
Re-exports EngineEvent
EngineStreamEvent ​
Re-exports EngineStreamEvent
EventAllowedBlock ​
Re-exports EventAllowedBlock
EventBlock ​
Re-exports EventBlock
EventMessage ​
Re-exports EventMessage
ExecutableCodeBlock ​
Re-exports ExecutableCodeBlock
ExecutionEndEvent ​
Re-exports ExecutionEndEvent
ExecutionEvent ​
Re-exports ExecutionEvent
ExecutionStartEvent ​
Re-exports ExecutionStartEvent
extractText ​
Re-exports extractText
extractToolUses ​
Re-exports extractToolUses
FileIdSource ​
Re-exports FileIdSource
ForkEndEvent ​
Re-exports ForkEndEvent
ForkStartEvent ​
Re-exports ForkStartEvent
GCSSource ​
Re-exports GCSSource
GeneratedFileBlock ​
Re-exports GeneratedFileBlock
GeneratedImageBlock ​
Re-exports GeneratedImageBlock
HtmlBlock ​
Re-exports HtmlBlock
ImageBlock ​
Re-exports ImageBlock
ImageMimeType ​
Re-exports ImageMimeType
isAssistantMessage ​
Re-exports isAssistantMessage
isDeltaEvent ​
Re-exports isDeltaEvent
isEngineEvent ​
Re-exports isEngineEvent
isEventBlock ​
Re-exports isEventBlock
isEventMessage ​
Re-exports isEventMessage
isFinalEvent ​
Re-exports isFinalEvent
isForkEvent ​
Re-exports isForkEvent
isMediaBlock ​
Re-exports isMediaBlock
isSpawnEvent ​
Re-exports isSpawnEvent
isStateChangeBlock ​
Re-exports isStateChangeBlock
isStreamEvent ​
Re-exports isStreamEvent
isSystemEventBlock ​
Re-exports isSystemEventBlock
isSystemMessage ​
Re-exports isSystemMessage
isTextBlock ​
Re-exports isTextBlock
isToolMessage ​
Re-exports isToolMessage
isToolResultBlock ​
Re-exports isToolResultBlock
isToolUseBlock ​
Re-exports isToolUseBlock
isUrlString ​
Re-exports isUrlString
isUserActionBlock ​
Re-exports isUserActionBlock
isUserMessage ​
Re-exports isUserMessage
JsonBlock ​
Re-exports JsonBlock
MediaBlock ​
Re-exports MediaBlock
MediaSource ​
Re-exports MediaSource
MediaSourceType ​
Re-exports MediaSourceType
Message ​
Re-exports Message
MessageEndEvent ​
Re-exports MessageEndEvent
MessageEvent ​
Re-exports MessageEvent
MessageInput ​
Re-exports MessageInput
MessageRole ​
Re-exports MessageRole
MessageRoles ​
Re-exports MessageRoles
MessageStartEvent ​
Re-exports MessageStartEvent
ReasoningBlock ​
Re-exports ReasoningBlock
ReasoningDeltaEvent ​
Re-exports ReasoningDeltaEvent
ReasoningEndEvent ​
Re-exports ReasoningEndEvent
ReasoningEvent ​
Re-exports ReasoningEvent
ReasoningStartEvent ​
Re-exports ReasoningStartEvent
S3Source ​
Re-exports S3Source
SpawnEndEvent ​
Re-exports SpawnEndEvent
SpawnStartEvent ​
Re-exports SpawnStartEvent
StateChangeBlock ​
Re-exports StateChangeBlock
StopReason ​
Re-exports StopReason
StreamChunk ​
Re-exports StreamChunk
StreamChunkType ​
Re-exports StreamChunkType
StreamErrorEvent ​
Re-exports StreamErrorEvent
StreamEvent ​
Re-exports StreamEvent
StreamEventBase ​
Re-exports StreamEventBase
stringToMediaSource ​
Re-exports stringToMediaSource
SystemAllowedBlock ​
Re-exports SystemAllowedBlock
SystemEventBlock ​
Re-exports SystemEventBlock
SystemMessage ​
Re-exports SystemMessage
TextBlock ​
Re-exports TextBlock
TickEndEvent ​
Re-exports TickEndEvent
TickEvent ​
Re-exports TickEvent
TickStartEvent ​
Re-exports TickStartEvent
ToolAllowedBlock ​
Re-exports ToolAllowedBlock
ToolBlock ​
Re-exports ToolBlock
ToolCallDeltaEvent ​
Re-exports ToolCallDeltaEvent
ToolCallEndEvent ​
Re-exports ToolCallEndEvent
ToolCallEvent ​
Re-exports ToolCallEvent
ToolCallStartEvent ​
Re-exports ToolCallStartEvent
ToolConfirmationRequiredEvent ​
Re-exports ToolConfirmationRequiredEvent
ToolConfirmationResultEvent ​
Re-exports ToolConfirmationResultEvent
ToolMessage ​
Re-exports ToolMessage
ToolResultBlock ​
Re-exports ToolResultBlock
ToolResultEvent ​
Re-exports ToolResultEvent
ToolUseBlock ​
Re-exports ToolUseBlock
UrlSource ​
Re-exports UrlSource
UserActionBlock ​
Re-exports UserActionBlock
UserAllowedBlock ​
Re-exports UserAllowedBlock
UserMessage ​
Re-exports UserMessage
VideoBlock ​
Re-exports VideoBlock
VideoMimeType ​
Re-exports VideoMimeType
XmlBlock ​
Re-exports XmlBlock