Types Reference

Updated

All types are exported from @chaoslabs/ai-sdk and are auto-generated from the Chaos AI contracts schema.

ChatCreateRequest

The base request type for creating a chat response.

types.ts
interface ChatCreateRequest {
  model: string;
  input: InputItem[];
  stream?: boolean;
  metadata: RequestMetadata;
}

ChatCreateRequestParams

Extends ChatCreateRequest with an optional streaming callback. This is the type you pass to chaos.chat.responses.create().

types.ts
type ChatCreateRequestParams = ChatCreateRequest & {
  onStreamEvent?: (message: ChaosSDKMessage) => void;
};

InputItem

A single message in the conversation input array.

types.ts
interface InputItem {
  type: "message";
  role: "user" | "system" | "assistant";
  content: string;
}
FieldTypeDescription
type"message"Always "message"
role"user" | "system" | "assistant"The message role
contentstringThe message text

RequestMetadata

Metadata attached to every request. Contains user identity, session tracking, and wallet configuration.

types.ts
interface RequestMetadata {
  user_id: string;
  session_id: string;
  wallets?: WalletInfo[];
  wallet_context_override?: WalletContextOverride;
}
FieldTypeRequiredDescription
user_idstringYesUnique user identifier
session_idstringYesSession identifier for conversation continuity
walletsWalletInfo[]NoArray of wallet addresses (required for WALLET_MODEL)
wallet_context_overrideWalletContextOverrideNoOverride wallet context for deterministic testing

WalletInfo

A wallet address on a specific chain.

types.ts
interface WalletInfo {
  address: string;
  chain: string;
}
example.ts
const wallets: WalletInfo[] = [
  { address: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045', chain: 'ethereum' },
  { address: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045', chain: 'arbitrum' },
];

WalletContextOverride

Provide a complete wallet context to bypass the server-side portfolio fetch. Useful for deterministic testing and simulations.

types.ts
interface WalletContextOverride {
  wallet_address: string;
  balances: BalanceOverride[];
  protocol_positions?: ProtocolPositionOverride[];
  prices?: { [k: string]: number };
}
 
interface BalanceOverride {
  symbol: string;
  amount: number;
  chain: string;
  price?: number;
  value_usd?: number;
}
 
interface ProtocolPositionOverride {
  id: string;
  name: string;
  chain: string;
  portfolio_items: PositionItemOverride[];
}
 
interface PositionItemOverride {
  name: string;
  assets: PositionAssetOverride[];
}
 
interface PositionAssetOverride {
  symbol: string;
  amount: number;
  price: number;
}
wallet-override-example.ts
import { Chaos, WALLET_MODEL } from '@chaoslabs/ai-sdk';
import type { WalletContextOverride } from '@chaoslabs/ai-sdk';
 
const override: WalletContextOverride = {
  wallet_address: '0xTestWallet',
  balances: [
    { symbol: 'ETH', amount: 10, chain: 'ethereum', price: 3500 },
    { symbol: 'USDC', amount: 50000, chain: 'ethereum', price: 1 },
  ],
  protocol_positions: [
    {
      id: 'aave-v3',
      name: 'Aave V3',
      chain: 'ethereum',
      portfolio_items: [
        {
          name: 'Supply',
          assets: [{ symbol: 'WETH', amount: 5, price: 3500 }],
        },
        {
          name: 'Borrow',
          assets: [{ symbol: 'USDC', amount: 10000, price: 1 }],
        },
      ],
    },
  ],
  prices: { ETH: 3500, USDC: 1, WETH: 3500 },
};
 
const response = await chaos.chat.responses.create({
  model: WALLET_MODEL,
  input: [{ type: 'message', role: 'user', content: 'Show my portfolio' }],
  metadata: {
    user_id: 'test-user',
    session_id: 'test-session',
    wallets: [{ address: '0xTestWallet', chain: 'ethereum' }],
    wallet_context_override: override,
  },
});

ChatCreateResponse

The response object returned by chaos.chat.responses.create().

types.ts
interface ChatCreateResponse {
  id: string;
  kind: "response";
  model: string;
  status: "completed" | "failed";
  messages?: ChaosSDKMessage[];
  error?: ResponseError;
}
 
interface ResponseError {
  message: string;
  type: string;
  code: string;
}
FieldTypeDescription
idstringUnique response identifier
kind"response"Always "response"
modelstringModel used for the response
status"completed" | "failed"Whether the request succeeded
messagesChaosSDKMessage[]Array of streamed messages
errorResponseErrorError details if status is "failed"

ChaosSDKMessage

The discriminated union of all message types streamed during a response.

types.ts
type ChaosSDKMessage =
  | AgentStatusSDKMessage
  | AgentTextSDKMessage
  | BlockSDKMessage
  | FollowUpSuggestionsSDKMessage
  | UserInputSDKMessage;

Each message has a shared shape with kind: "message" and a type discriminant:

typeInterfacedata Contents
"status"AgentStatusSDKMessage{ status: "processing" | "done" }
"text"AgentTextSDKMessage{ text: string }
"block"BlockSDKMessage{ block: Block; order?: number }
"follow_up_suggestions"FollowUpSuggestionsSDKMessage{ suggestions: string[] }
"input"UserInputSDKMessage{ prompt?: string; options: UserInputOption[] }

All messages share a context object:

types.ts
interface ChaosSDKMessageContext {
  sessionId: string;
  artifactId: string;
  query?: string;
}
Was this helpful?