@chaoslabs/ai-sdk 0.0.9 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,58 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.0.11] - 2026-01-27
9
+
10
+ ### Added
11
+
12
+ - **Typed StreamMessage**: `StreamMessage` is now a discriminated union with properly typed `content` for each message type:
13
+ - `agent_status_change`: `AgentStatusContent` with typed `status` field
14
+ - `agent_message`: `AgentMessageContent` with typed `data.message` field
15
+ - `report`: `ReportContent` with typed `data` (Block), `captions` (Caption[]), `references` (Reference[])
16
+ - `follow_up_suggestions`: `FollowUpSuggestionsContent` with typed `data.followUpQueries`
17
+ - `user_input`: `UserInputContent` with typed `candidates`
18
+
19
+ - **New types exported**:
20
+ - `Caption` - Block caption with label, value, group, collapsable
21
+ - `Reference` - Source reference with title, url, content, hiddenUrl, textSpans, engineId
22
+ - `AgentStatusMessage`, `AgentTextMessage`, `ReportMessage`, `FollowUpSuggestionsMessage`, `UserInputMessage` - Individual message types for type narrowing
23
+
24
+ - **Type-safe content access**: TypeScript now narrows content type automatically when checking `msg.type`:
25
+ ```typescript
26
+ if (msg.type === 'agent_status_change') {
27
+ console.log(msg.content.status); // TypeScript knows this is AgentStatus
28
+ }
29
+ ```
30
+
31
+ ### Changed
32
+
33
+ - `ReportContent.data` changed from `unknown` to `Block`
34
+ - `ReportContent.captions` changed from `unknown[]` to `Caption[]`
35
+ - `ReportContent.references` changed from `unknown` to `Reference[]`
36
+ - `extractReportBlock()` return type changed from `unknown | null` to `Block | null`
37
+ - `UserInputCandidate.coingecko_coin_id` renamed to `token_id`
38
+
39
+ ### Removed
40
+
41
+ - Staging environment support removed - SDK now only supports production (`https://ai.chaoslabs.co`)
42
+ - `CHAOS_STAGING_URL` and `CHAOS_STAGING_API_KEY` environment variables no longer used in examples
43
+
44
+ ## [0.0.10] - 2026-01-27
45
+
46
+ ### Changed
47
+
48
+ - Default `baseUrl` changed from staging to production (`https://ai.chaoslabs.co`)
49
+
50
+ ## [0.0.9] - 2026-01-26
51
+
52
+ ### Added
53
+
54
+ - Initial public release
55
+ - Core client with streaming support
56
+ - Block types: Markdown, Table, Chart, TransactionAction, Interactive
57
+ - Primitive constants and helpers
58
+ - Conversation class for multi-turn interactions
package/README.md CHANGED
@@ -29,7 +29,7 @@ import { Chaos, WALLET_MODEL, extractText, extractBlocks } from '@chaoslabs/ai-s
29
29
 
30
30
  const chaos = new Chaos({
31
31
  apiKey: process.env.CHAOS_API_KEY,
32
- baseUrl: 'https://ai-staging.chaoslabs.co', // Optional, this is the default
32
+ baseUrl: 'https://ai.chaoslabs.co', // Optional, this is the default
33
33
  });
34
34
 
35
35
  const response = await chaos.chat.responses.create({
@@ -98,7 +98,7 @@ new Chaos(config: ChaosConfig)
98
98
  | Option | Type | Default | Description |
99
99
  |--------|------|---------|-------------|
100
100
  | `apiKey` | `string` | Required | Your Chaos API key |
101
- | `baseUrl` | `string` | `https://ai-staging.chaoslabs.co` | API base URL |
101
+ | `baseUrl` | `string` | `https://ai.chaoslabs.co` | API base URL |
102
102
  | `timeout` | `number` | `120000` | Request timeout in milliseconds |
103
103
 
104
104
  ### Request Options
@@ -110,15 +110,6 @@ new Chaos(config: ChaosConfig)
110
110
  | `metadata` | `RequestMetadata` | User, session, and wallet info |
111
111
  | `onStreamEvent` | `(msg: StreamMessage) => void` | Real-time streaming callback |
112
112
 
113
- > **Important:** API keys are environment-specific. A staging API key will not work with the production API, and vice versa. Make sure your `apiKey` and `baseUrl` are from the same environment.
114
-
115
- **Available Environments:**
116
-
117
- | Environment | Base URL |
118
- |-------------|----------|
119
- | Staging | `https://ai-staging.chaoslabs.co` |
120
- | Production | Coming soon |
121
-
122
113
  ### Models
123
114
 
124
115
  | Model | Description |
package/dist/client.d.ts CHANGED
@@ -55,7 +55,7 @@ declare class V1Chat {
55
55
  *
56
56
  * const chaos = new Chaos({
57
57
  * apiKey: 'ck-...',
58
- * baseUrl: 'https://ai-staging.chaoslabs.co'
58
+ * baseUrl: 'https://ai.chaoslabs.co'
59
59
  * });
60
60
  *
61
61
  * const response = await chaos.chat.responses.create({
package/dist/client.js CHANGED
@@ -155,7 +155,7 @@ class V1Chat {
155
155
  *
156
156
  * const chaos = new Chaos({
157
157
  * apiKey: 'ck-...',
158
- * baseUrl: 'https://ai-staging.chaoslabs.co'
158
+ * baseUrl: 'https://ai.chaoslabs.co'
159
159
  * });
160
160
  *
161
161
  * const response = await chaos.chat.responses.create({
@@ -181,7 +181,7 @@ export class Chaos {
181
181
  const useNativeHttp = config.useNativeHttp !== false;
182
182
  this.config = {
183
183
  apiKey: config.apiKey,
184
- baseUrl: config.baseUrl || 'https://ai-staging.chaoslabs.co',
184
+ baseUrl: config.baseUrl || 'https://ai.chaoslabs.co',
185
185
  timeout: config.timeout || DEFAULT_TIMEOUT,
186
186
  useNativeHttp,
187
187
  };
package/dist/index.d.ts CHANGED
@@ -14,4 +14,4 @@ export { PRIMITIVE_SWAP, PRIMITIVE_SUPPLY, PRIMITIVE_WITHDRAW, PRIMITIVE_BORROW,
14
14
  export type { PrimitiveType } from './primitives.js';
15
15
  export { extractTableBlocks, extractChartBlocks, extractTransactionBlocks, extractMarkdownBlocks, extractInteractiveBlocks, findTableByTitle, findChartByTitle, findTransactionsByPrimitive, extractPrimitives, extractPrimitivesByType, getPrimitiveTypes, tableToObjects, getTableColumn, findTableRow, getTableDimensions, getChartData, getChartTotal, getChartPercentages, getAllWarnings, getAllBlockers, getHighestRiskLevel, countBlocksByType, hasBlocks, hasBlockType, } from './blocks.js';
16
16
  export { isAgentStatusMessage, isAgentMessage, isReportMessage, isFollowUpSuggestions, isUserInputMessage, parseAgentStatus, isTerminalStatus, extractAgentMessageText, extractSuggestions, extractReportBlock, parseStreamLine, parseStreamLines, } from './stream.js';
17
- export type { MessageType, AgentStatus, StreamMessage, StreamMessageContext, } from './stream.js';
17
+ export type { MessageType, AgentStatus, StreamMessage, StreamMessageContext, AgentStatusContent, AgentMessageContent, AgentTextData, ReportContent, Caption, Reference, FollowUpSuggestionsContent, FollowUpData, UserInputContent, UserInputCandidate, AgentStatusMessage, AgentTextMessage, ReportMessage, FollowUpSuggestionsMessage, UserInputMessage, } from './stream.js';
package/dist/stream.d.ts CHANGED
@@ -3,7 +3,12 @@
3
3
  *
4
4
  * Utilities for parsing and working with WebSocket stream messages
5
5
  * from the Chaos AI backend.
6
+ *
7
+ * StreamMessage is a discriminated union - the `type` field determines
8
+ * the shape of `content`. TypeScript will narrow the content type
9
+ * automatically when you check the type field.
6
10
  */
11
+ import type { Block } from "./types.js";
7
12
  export type MessageType = "agent_status_change" | "agent_message" | "report" | "follow_up_suggestions" | "user_input";
8
13
  export type AgentStatus = "processing" | "done" | "error" | "cancelled";
9
14
  export interface StreamMessageContext {
@@ -11,22 +16,212 @@ export interface StreamMessageContext {
11
16
  artifactId: string;
12
17
  query?: string;
13
18
  }
14
- export interface StreamMessage {
19
+ /**
20
+ * Content for agent_status_change messages.
21
+ * Indicates the current status of the agent workflow.
22
+ */
23
+ export interface AgentStatusContent {
24
+ status: AgentStatus;
25
+ }
26
+ /**
27
+ * Content for agent_message messages (thinking/progress messages).
28
+ * Contains the agent's current thinking or progress update.
29
+ */
30
+ export interface AgentMessageContent {
31
+ messageId: string;
32
+ artifactId: string;
33
+ type: string;
34
+ data: AgentTextData;
35
+ order: number;
36
+ createdAt: number;
37
+ updatedAt: number;
38
+ metadata?: Record<string, unknown>;
39
+ }
40
+ /**
41
+ * The data payload within an agent message.
42
+ */
43
+ export interface AgentTextData {
44
+ message: string;
45
+ }
46
+ /**
47
+ * A caption for a report block.
48
+ */
49
+ export interface Caption {
50
+ label: string;
51
+ value: unknown;
52
+ group?: string;
53
+ collapsable?: boolean;
54
+ }
55
+ /**
56
+ * A reference used to generate the response.
57
+ */
58
+ export interface Reference {
59
+ title: string;
60
+ url: string;
61
+ content: string;
62
+ hiddenUrl?: string;
63
+ textSpans?: number[][];
64
+ engineId?: string;
65
+ }
66
+ /**
67
+ * Content for report messages.
68
+ * Contains a block of content (markdown, table, chart, etc.)
69
+ */
70
+ export interface ReportContent {
71
+ id: string;
72
+ artifactId: string;
73
+ type: string;
74
+ data: Block;
75
+ order: number;
76
+ createdAt: number;
77
+ updatedAt: number;
78
+ createdBy?: string;
79
+ metadata?: Record<string, unknown>;
80
+ captions?: Caption[];
81
+ references?: Reference[];
82
+ version?: number;
83
+ }
84
+ /**
85
+ * Content for follow_up_suggestions messages.
86
+ * Contains suggested follow-up queries.
87
+ */
88
+ export interface FollowUpSuggestionsContent {
89
+ messageId: string;
90
+ artifactId: string;
91
+ type: string;
92
+ data: FollowUpData;
93
+ order: number;
94
+ createdAt: number;
95
+ updatedAt: number;
96
+ metadata?: Record<string, unknown>;
97
+ }
98
+ /**
99
+ * The data payload for follow-up suggestions.
100
+ */
101
+ export interface FollowUpData {
102
+ followUpQueries: string[];
103
+ }
104
+ /**
105
+ * Content for user_input messages.
106
+ * Indicates the agent needs clarification from the user.
107
+ */
108
+ export interface UserInputContent {
109
+ type: string;
110
+ candidates: Record<string, UserInputCandidate[]>;
111
+ }
112
+ /**
113
+ * A candidate option for user disambiguation.
114
+ */
115
+ export interface UserInputCandidate {
116
+ symbol: string;
117
+ name: string;
118
+ market_cap: number;
119
+ token_id: string;
120
+ score: number;
121
+ }
122
+ interface StreamMessageBase {
15
123
  id: string;
16
- type: MessageType;
17
124
  timestamp: number;
18
- content: unknown;
19
125
  context: StreamMessageContext;
20
126
  }
21
- export declare function isAgentStatusMessage(msg: StreamMessage): boolean;
22
- export declare function isAgentMessage(msg: StreamMessage): boolean;
23
- export declare function isReportMessage(msg: StreamMessage): boolean;
24
- export declare function isFollowUpSuggestions(msg: StreamMessage): boolean;
25
- export declare function isUserInputMessage(msg: StreamMessage): boolean;
127
+ /**
128
+ * Agent status change message.
129
+ * @example
130
+ * if (msg.type === 'agent_status_change') {
131
+ * console.log(msg.content.status); // TypeScript knows this is AgentStatus
132
+ * }
133
+ */
134
+ export interface AgentStatusMessage extends StreamMessageBase {
135
+ type: "agent_status_change";
136
+ content: AgentStatusContent;
137
+ }
138
+ /**
139
+ * Agent thinking/progress message.
140
+ * @example
141
+ * if (msg.type === 'agent_message') {
142
+ * console.log(msg.content.data.message); // TypeScript knows the shape
143
+ * }
144
+ */
145
+ export interface AgentTextMessage extends StreamMessageBase {
146
+ type: "agent_message";
147
+ content: AgentMessageContent;
148
+ }
149
+ /**
150
+ * Report block message (markdown, table, chart, etc.)
151
+ * @example
152
+ * if (msg.type === 'report') {
153
+ * const blockData = msg.content.data; // The actual block
154
+ * }
155
+ */
156
+ export interface ReportMessage extends StreamMessageBase {
157
+ type: "report";
158
+ content: ReportContent;
159
+ }
160
+ /**
161
+ * Follow-up suggestions message.
162
+ * @example
163
+ * if (msg.type === 'follow_up_suggestions') {
164
+ * const queries = msg.content.data.followUpQueries;
165
+ * }
166
+ */
167
+ export interface FollowUpSuggestionsMessage extends StreamMessageBase {
168
+ type: "follow_up_suggestions";
169
+ content: FollowUpSuggestionsContent;
170
+ }
171
+ /**
172
+ * User input request message.
173
+ * @example
174
+ * if (msg.type === 'user_input') {
175
+ * const candidates = msg.content.candidates;
176
+ * }
177
+ */
178
+ export interface UserInputMessage extends StreamMessageBase {
179
+ type: "user_input";
180
+ content: UserInputContent;
181
+ }
182
+ /**
183
+ * Union of all stream message types.
184
+ *
185
+ * This is a discriminated union - check the `type` field to narrow
186
+ * the content type automatically:
187
+ *
188
+ * @example
189
+ * function handleMessage(msg: StreamMessage) {
190
+ * switch (msg.type) {
191
+ * case 'agent_status_change':
192
+ * // TypeScript knows: msg.content is AgentStatusContent
193
+ * console.log(msg.content.status);
194
+ * break;
195
+ * case 'agent_message':
196
+ * // TypeScript knows: msg.content is AgentMessageContent
197
+ * console.log(msg.content.data.message);
198
+ * break;
199
+ * case 'report':
200
+ * // TypeScript knows: msg.content is ReportContent
201
+ * console.log(msg.content.data);
202
+ * break;
203
+ * case 'follow_up_suggestions':
204
+ * // TypeScript knows: msg.content is FollowUpSuggestionsContent
205
+ * console.log(msg.content.data.followUpQueries);
206
+ * break;
207
+ * case 'user_input':
208
+ * // TypeScript knows: msg.content is UserInputContent
209
+ * console.log(msg.content.candidates);
210
+ * break;
211
+ * }
212
+ * }
213
+ */
214
+ export type StreamMessage = AgentStatusMessage | AgentTextMessage | ReportMessage | FollowUpSuggestionsMessage | UserInputMessage;
215
+ export declare function isAgentStatusMessage(msg: StreamMessage): msg is AgentStatusMessage;
216
+ export declare function isAgentMessage(msg: StreamMessage): msg is AgentTextMessage;
217
+ export declare function isReportMessage(msg: StreamMessage): msg is ReportMessage;
218
+ export declare function isFollowUpSuggestions(msg: StreamMessage): msg is FollowUpSuggestionsMessage;
219
+ export declare function isUserInputMessage(msg: StreamMessage): msg is UserInputMessage;
26
220
  export declare function parseAgentStatus(msg: StreamMessage): AgentStatus | null;
27
221
  export declare function isTerminalStatus(status: AgentStatus): boolean;
28
222
  export declare function extractAgentMessageText(msg: StreamMessage): string | null;
29
223
  export declare function extractSuggestions(msg: StreamMessage): string[];
30
- export declare function extractReportBlock(msg: StreamMessage): unknown | null;
224
+ export declare function extractReportBlock(msg: StreamMessage): Block | null;
31
225
  export declare function parseStreamLine(line: string): StreamMessage | null;
32
226
  export declare function parseStreamLines(text: string): StreamMessage[];
227
+ export {};
package/dist/stream.js CHANGED
@@ -3,6 +3,10 @@
3
3
  *
4
4
  * Utilities for parsing and working with WebSocket stream messages
5
5
  * from the Chaos AI backend.
6
+ *
7
+ * StreamMessage is a discriminated union - the `type` field determines
8
+ * the shape of `content`. TypeScript will narrow the content type
9
+ * automatically when you check the type field.
6
10
  */
7
11
  // ============================================================================
8
12
  // Type Guards
@@ -30,49 +34,32 @@ export function parseAgentStatus(msg) {
30
34
  if (msg.type !== "agent_status_change") {
31
35
  return null;
32
36
  }
33
- const content = msg.content;
34
- if (typeof content?.status === "string" &&
35
- VALID_STATUSES.includes(content.status)) {
36
- return content.status;
37
- }
38
- return null;
37
+ return msg.content.status;
39
38
  }
40
39
  const TERMINAL_STATUSES = ["done", "error", "cancelled"];
41
40
  export function isTerminalStatus(status) {
42
41
  return TERMINAL_STATUSES.includes(status);
43
42
  }
44
43
  // ============================================================================
45
- // Content Extraction
44
+ // Content Extraction (for convenience, type guards provide same functionality)
46
45
  // ============================================================================
47
46
  export function extractAgentMessageText(msg) {
48
47
  if (msg.type !== "agent_message") {
49
48
  return null;
50
49
  }
51
- const content = msg.content;
52
- if (typeof content?.data?.message === "string") {
53
- return content.data.message;
54
- }
55
- return null;
50
+ return msg.content.data.message;
56
51
  }
57
52
  export function extractSuggestions(msg) {
58
53
  if (msg.type !== "follow_up_suggestions") {
59
54
  return [];
60
55
  }
61
- const content = msg.content;
62
- if (Array.isArray(content?.suggestions)) {
63
- return content.suggestions.filter((s) => typeof s === "string");
64
- }
65
- return [];
56
+ return msg.content.data.followUpQueries;
66
57
  }
67
58
  export function extractReportBlock(msg) {
68
59
  if (msg.type !== "report") {
69
60
  return null;
70
61
  }
71
- const content = msg.content;
72
- if (content?.data !== undefined) {
73
- return content.data;
74
- }
75
- return null;
62
+ return msg.content.data;
76
63
  }
77
64
  // ============================================================================
78
65
  // Stream Parser
package/dist/types.d.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  export interface ChaosConfig {
5
5
  /** API key for authentication */
6
6
  apiKey: string;
7
- /** Base URL for the API (defaults to https://ai-staging.chaoslabs.co) */
7
+ /** Base URL for the API (defaults to https://ai.chaoslabs.co) */
8
8
  baseUrl?: string;
9
9
  /** Request timeout in milliseconds (defaults to 120000) */
10
10
  timeout?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chaoslabs/ai-sdk",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "Chaos AI SDK - TypeScript SDK for the Chaos AI API",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -14,6 +14,7 @@
14
14
  "files": [
15
15
  "dist",
16
16
  "README.md",
17
+ "CHANGELOG.md",
17
18
  "LICENSE"
18
19
  ],
19
20
  "scripts": {