@chaoslabs/ai-sdk 0.0.6 → 0.0.7

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.
@@ -1 +0,0 @@
1
- export {};
@@ -1,345 +0,0 @@
1
- import { describe, it, expect } from "bun:test";
2
- import { isAgentStatusMessage, isAgentMessage, isReportMessage, isFollowUpSuggestions, isUserInputMessage, parseAgentStatus, isTerminalStatus, extractAgentMessageText, extractSuggestions, extractReportBlock, parseStreamLine, parseStreamLines, } from "../stream";
3
- describe("isAgentStatusMessage", () => {
4
- it("returns true for agent_status_change message", () => {
5
- const msg = {
6
- id: "1",
7
- type: "agent_status_change",
8
- timestamp: Date.now(),
9
- content: { status: "processing" },
10
- context: {
11
- sessionId: "session-1",
12
- artifactId: "artifact-1",
13
- },
14
- };
15
- expect(isAgentStatusMessage(msg)).toBe(true);
16
- });
17
- it("returns false for other message types", () => {
18
- const msg = {
19
- id: "2",
20
- type: "agent_message",
21
- timestamp: Date.now(),
22
- content: { messageId: "m1", data: { message: "Hello" } },
23
- context: {
24
- sessionId: "session-1",
25
- artifactId: "artifact-1",
26
- },
27
- };
28
- expect(isAgentStatusMessage(msg)).toBe(false);
29
- });
30
- });
31
- describe("isAgentMessage", () => {
32
- it("returns true for agent_message type", () => {
33
- const msg = {
34
- id: "1",
35
- type: "agent_message",
36
- timestamp: Date.now(),
37
- content: { messageId: "m1", data: { message: "Hello" } },
38
- context: { sessionId: "s1", artifactId: "a1" },
39
- };
40
- expect(isAgentMessage(msg)).toBe(true);
41
- });
42
- it("returns false for other message types", () => {
43
- const msg = {
44
- id: "1",
45
- type: "report",
46
- timestamp: Date.now(),
47
- content: { id: "r1", type: "table", data: {} },
48
- context: { sessionId: "s1", artifactId: "a1" },
49
- };
50
- expect(isAgentMessage(msg)).toBe(false);
51
- });
52
- });
53
- describe("isReportMessage", () => {
54
- it("returns true for report type", () => {
55
- const msg = {
56
- id: "1",
57
- type: "report",
58
- timestamp: Date.now(),
59
- content: { id: "r1", type: "table", data: {} },
60
- context: { sessionId: "s1", artifactId: "a1" },
61
- };
62
- expect(isReportMessage(msg)).toBe(true);
63
- });
64
- it("returns false for other message types", () => {
65
- const msg = {
66
- id: "1",
67
- type: "agent_message",
68
- timestamp: Date.now(),
69
- content: { messageId: "m1", data: { message: "Hello" } },
70
- context: { sessionId: "s1", artifactId: "a1" },
71
- };
72
- expect(isReportMessage(msg)).toBe(false);
73
- });
74
- });
75
- describe("isFollowUpSuggestions", () => {
76
- it("returns true for follow_up_suggestions type", () => {
77
- const msg = {
78
- id: "1",
79
- type: "follow_up_suggestions",
80
- timestamp: Date.now(),
81
- content: { suggestions: ["Question 1?", "Question 2?"] },
82
- context: { sessionId: "s1", artifactId: "a1" },
83
- };
84
- expect(isFollowUpSuggestions(msg)).toBe(true);
85
- });
86
- it("returns false for other message types", () => {
87
- const msg = {
88
- id: "1",
89
- type: "agent_message",
90
- timestamp: Date.now(),
91
- content: { messageId: "m1", data: { message: "Hello" } },
92
- context: { sessionId: "s1", artifactId: "a1" },
93
- };
94
- expect(isFollowUpSuggestions(msg)).toBe(false);
95
- });
96
- });
97
- describe("isUserInputMessage", () => {
98
- it("returns true for user_input type", () => {
99
- const msg = {
100
- id: "1",
101
- type: "user_input",
102
- timestamp: Date.now(),
103
- content: { query: "What is my balance?" },
104
- context: { sessionId: "s1", artifactId: "a1" },
105
- };
106
- expect(isUserInputMessage(msg)).toBe(true);
107
- });
108
- it("returns false for other message types", () => {
109
- const msg = {
110
- id: "1",
111
- type: "agent_message",
112
- timestamp: Date.now(),
113
- content: { messageId: "m1", data: { message: "Hello" } },
114
- context: { sessionId: "s1", artifactId: "a1" },
115
- };
116
- expect(isUserInputMessage(msg)).toBe(false);
117
- });
118
- });
119
- describe("parseAgentStatus", () => {
120
- it("extracts status from agent_status_change message", () => {
121
- const msg = {
122
- id: "1",
123
- type: "agent_status_change",
124
- timestamp: Date.now(),
125
- content: { status: "processing" },
126
- context: { sessionId: "s1", artifactId: "a1" },
127
- };
128
- expect(parseAgentStatus(msg)).toBe("processing");
129
- });
130
- it("extracts done status", () => {
131
- const msg = {
132
- id: "1",
133
- type: "agent_status_change",
134
- timestamp: Date.now(),
135
- content: { status: "done" },
136
- context: { sessionId: "s1", artifactId: "a1" },
137
- };
138
- expect(parseAgentStatus(msg)).toBe("done");
139
- });
140
- it("returns null for non-status messages", () => {
141
- const msg = {
142
- id: "1",
143
- type: "agent_message",
144
- timestamp: Date.now(),
145
- content: { messageId: "m1", data: { message: "Hello" } },
146
- context: { sessionId: "s1", artifactId: "a1" },
147
- };
148
- expect(parseAgentStatus(msg)).toBeNull();
149
- });
150
- it("returns null for invalid content", () => {
151
- const msg = {
152
- id: "1",
153
- type: "agent_status_change",
154
- timestamp: Date.now(),
155
- content: { notStatus: "wrong" },
156
- context: { sessionId: "s1", artifactId: "a1" },
157
- };
158
- expect(parseAgentStatus(msg)).toBeNull();
159
- });
160
- });
161
- describe("isTerminalStatus", () => {
162
- it("returns true for done status", () => {
163
- expect(isTerminalStatus("done")).toBe(true);
164
- });
165
- it("returns true for error status", () => {
166
- expect(isTerminalStatus("error")).toBe(true);
167
- });
168
- it("returns true for cancelled status", () => {
169
- expect(isTerminalStatus("cancelled")).toBe(true);
170
- });
171
- it("returns false for processing status", () => {
172
- expect(isTerminalStatus("processing")).toBe(false);
173
- });
174
- });
175
- describe("extractAgentMessageText", () => {
176
- it("extracts message text from agent_message", () => {
177
- const msg = {
178
- id: "1",
179
- type: "agent_message",
180
- timestamp: Date.now(),
181
- content: { messageId: "m1", data: { message: "Hello world" } },
182
- context: { sessionId: "s1", artifactId: "a1" },
183
- };
184
- expect(extractAgentMessageText(msg)).toBe("Hello world");
185
- });
186
- it("returns null for non-agent_message types", () => {
187
- const msg = {
188
- id: "1",
189
- type: "report",
190
- timestamp: Date.now(),
191
- content: { id: "r1", type: "table", data: {} },
192
- context: { sessionId: "s1", artifactId: "a1" },
193
- };
194
- expect(extractAgentMessageText(msg)).toBeNull();
195
- });
196
- it("returns null for invalid content structure", () => {
197
- const msg = {
198
- id: "1",
199
- type: "agent_message",
200
- timestamp: Date.now(),
201
- content: { messageId: "m1" }, // missing data.message
202
- context: { sessionId: "s1", artifactId: "a1" },
203
- };
204
- expect(extractAgentMessageText(msg)).toBeNull();
205
- });
206
- });
207
- describe("extractSuggestions", () => {
208
- it("extracts suggestions array from follow_up_suggestions", () => {
209
- const msg = {
210
- id: "1",
211
- type: "follow_up_suggestions",
212
- timestamp: Date.now(),
213
- content: { suggestions: ["Question 1?", "Question 2?"] },
214
- context: { sessionId: "s1", artifactId: "a1" },
215
- };
216
- expect(extractSuggestions(msg)).toEqual(["Question 1?", "Question 2?"]);
217
- });
218
- it("returns empty array for non-follow_up_suggestions types", () => {
219
- const msg = {
220
- id: "1",
221
- type: "agent_message",
222
- timestamp: Date.now(),
223
- content: { messageId: "m1", data: { message: "Hello" } },
224
- context: { sessionId: "s1", artifactId: "a1" },
225
- };
226
- expect(extractSuggestions(msg)).toEqual([]);
227
- });
228
- it("returns empty array for invalid content structure", () => {
229
- const msg = {
230
- id: "1",
231
- type: "follow_up_suggestions",
232
- timestamp: Date.now(),
233
- content: { notSuggestions: "wrong" },
234
- context: { sessionId: "s1", artifactId: "a1" },
235
- };
236
- expect(extractSuggestions(msg)).toEqual([]);
237
- });
238
- });
239
- describe("extractReportBlock", () => {
240
- it("extracts data from report message", () => {
241
- const reportData = { columns: ["name"], rows: [["Alice"]] };
242
- const msg = {
243
- id: "1",
244
- type: "report",
245
- timestamp: Date.now(),
246
- content: { id: "r1", type: "table", data: reportData },
247
- context: { sessionId: "s1", artifactId: "a1" },
248
- };
249
- expect(extractReportBlock(msg)).toEqual(reportData);
250
- });
251
- it("returns null for non-report types", () => {
252
- const msg = {
253
- id: "1",
254
- type: "agent_message",
255
- timestamp: Date.now(),
256
- content: { messageId: "m1", data: { message: "Hello" } },
257
- context: { sessionId: "s1", artifactId: "a1" },
258
- };
259
- expect(extractReportBlock(msg)).toBeNull();
260
- });
261
- it("returns null for invalid content structure", () => {
262
- const msg = {
263
- id: "1",
264
- type: "report",
265
- timestamp: Date.now(),
266
- content: { id: "r1", type: "table" }, // missing data
267
- context: { sessionId: "s1", artifactId: "a1" },
268
- };
269
- expect(extractReportBlock(msg)).toBeNull();
270
- });
271
- });
272
- describe("parseStreamLine", () => {
273
- it("parses valid NDJSON line to StreamMessage", () => {
274
- const msg = {
275
- id: "1",
276
- type: "agent_message",
277
- timestamp: 1234567890,
278
- content: { messageId: "m1", data: { message: "Hello" } },
279
- context: { sessionId: "s1", artifactId: "a1" },
280
- };
281
- const line = JSON.stringify(msg);
282
- const result = parseStreamLine(line);
283
- expect(result).toEqual(msg);
284
- });
285
- it("returns null for empty line", () => {
286
- expect(parseStreamLine("")).toBeNull();
287
- });
288
- it("returns null for whitespace-only line", () => {
289
- expect(parseStreamLine(" ")).toBeNull();
290
- });
291
- it("returns null for invalid JSON", () => {
292
- expect(parseStreamLine("{not valid json}")).toBeNull();
293
- });
294
- it("returns null for missing required fields", () => {
295
- expect(parseStreamLine('{"id": "1"}')).toBeNull();
296
- });
297
- });
298
- describe("parseStreamLines", () => {
299
- it("parses multiple NDJSON lines", () => {
300
- const msg1 = {
301
- id: "1",
302
- type: "agent_status_change",
303
- timestamp: 1234567890,
304
- content: { status: "processing" },
305
- context: { sessionId: "s1", artifactId: "a1" },
306
- };
307
- const msg2 = {
308
- id: "2",
309
- type: "agent_message",
310
- timestamp: 1234567891,
311
- content: { messageId: "m1", data: { message: "Hello" } },
312
- context: { sessionId: "s1", artifactId: "a1" },
313
- };
314
- const text = JSON.stringify(msg1) + "\n" + JSON.stringify(msg2);
315
- const result = parseStreamLines(text);
316
- expect(result).toEqual([msg1, msg2]);
317
- });
318
- it("returns empty array for empty string", () => {
319
- expect(parseStreamLines("")).toEqual([]);
320
- });
321
- it("skips invalid lines and returns valid ones", () => {
322
- const validMsg = {
323
- id: "1",
324
- type: "agent_message",
325
- timestamp: 1234567890,
326
- content: { messageId: "m1", data: { message: "Hello" } },
327
- context: { sessionId: "s1", artifactId: "a1" },
328
- };
329
- const text = "invalid json\n" + JSON.stringify(validMsg) + "\n{broken}";
330
- const result = parseStreamLines(text);
331
- expect(result).toEqual([validMsg]);
332
- });
333
- it("handles lines with various whitespace", () => {
334
- const msg = {
335
- id: "1",
336
- type: "agent_message",
337
- timestamp: 1234567890,
338
- content: { messageId: "m1", data: { message: "Hello" } },
339
- context: { sessionId: "s1", artifactId: "a1" },
340
- };
341
- const text = "\n\n" + JSON.stringify(msg) + "\n\n";
342
- const result = parseStreamLines(text);
343
- expect(result).toEqual([msg]);
344
- });
345
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,6 +0,0 @@
1
- import { describe, it, expect } from 'bun:test';
2
- describe('test infrastructure', () => {
3
- it('works', () => {
4
- expect(1 + 1).toBe(2);
5
- });
6
- });
package/dist/blocks.d.ts DELETED
@@ -1,108 +0,0 @@
1
- import type { Block, TableBlock, ChartBlock, TransactionActionBlock, MarkdownBlock, InteractiveBlock, Primitive, Response } from './types.js';
2
- /**
3
- * Extract all table blocks from a response.
4
- */
5
- export declare function extractTableBlocks(response: Response): TableBlock[];
6
- /**
7
- * Extract all chart blocks from a response.
8
- */
9
- export declare function extractChartBlocks(response: Response): ChartBlock[];
10
- /**
11
- * Extract all transaction action blocks from a response.
12
- */
13
- export declare function extractTransactionBlocks(response: Response): TransactionActionBlock[];
14
- /**
15
- * Extract all markdown blocks from a response.
16
- */
17
- export declare function extractMarkdownBlocks(response: Response): MarkdownBlock[];
18
- /**
19
- * Extract all interactive blocks from a response.
20
- */
21
- export declare function extractInteractiveBlocks(response: Response): InteractiveBlock[];
22
- /**
23
- * Find the first table block with a matching title.
24
- */
25
- export declare function findTableByTitle(response: Response, title: string): TableBlock | undefined;
26
- /**
27
- * Find the first chart block with a matching title.
28
- */
29
- export declare function findChartByTitle(response: Response, title: string): ChartBlock | undefined;
30
- /**
31
- * Find transaction blocks containing a specific primitive type.
32
- */
33
- export declare function findTransactionsByPrimitive(response: Response, primitiveType: string): TransactionActionBlock[];
34
- /**
35
- * Extract all primitives from all transaction blocks.
36
- */
37
- export declare function extractPrimitives(response: Response): Primitive[];
38
- /**
39
- * Extract primitives of a specific type.
40
- */
41
- export declare function extractPrimitivesByType(response: Response, primitiveType: string): Primitive[];
42
- /**
43
- * Get unique primitive types from a response.
44
- */
45
- export declare function getPrimitiveTypes(response: Response): string[];
46
- /**
47
- * Convert a table block to an array of objects.
48
- * Each object has keys from the table headers.
49
- */
50
- export declare function tableToObjects<T extends Record<string, unknown>>(table: TableBlock): T[];
51
- /**
52
- * Get a specific column from a table block.
53
- */
54
- export declare function getTableColumn(table: TableBlock, columnName: string): unknown[];
55
- /**
56
- * Find a row in a table by matching a column value.
57
- */
58
- export declare function findTableRow(table: TableBlock, columnName: string, value: unknown): (string | number | boolean | null)[] | undefined;
59
- /**
60
- * Get table dimensions.
61
- */
62
- export declare function getTableDimensions(table: TableBlock): {
63
- columns: number;
64
- rows: number;
65
- };
66
- /**
67
- * Get chart data as label-value pairs.
68
- * Works with both segments and legacy data formats.
69
- */
70
- export declare function getChartData(chart: ChartBlock): Array<{
71
- label: string;
72
- value: number;
73
- }>;
74
- /**
75
- * Get the total value of all chart segments.
76
- */
77
- export declare function getChartTotal(chart: ChartBlock): number;
78
- /**
79
- * Get chart segment percentages.
80
- */
81
- export declare function getChartPercentages(chart: ChartBlock): Array<{
82
- label: string;
83
- percentage: number;
84
- }>;
85
- /**
86
- * Get all warnings from transaction blocks.
87
- */
88
- export declare function getAllWarnings(response: Response): string[];
89
- /**
90
- * Get all blockers from transaction blocks.
91
- */
92
- export declare function getAllBlockers(response: Response): string[];
93
- /**
94
- * Get the highest risk level from all transaction blocks.
95
- */
96
- export declare function getHighestRiskLevel(response: Response): string | undefined;
97
- /**
98
- * Count blocks by type in a response.
99
- */
100
- export declare function countBlocksByType(response: Response): Record<string, number>;
101
- /**
102
- * Check if a response contains any blocks.
103
- */
104
- export declare function hasBlocks(response: Response): boolean;
105
- /**
106
- * Check if a response contains a specific block type.
107
- */
108
- export declare function hasBlockType(response: Response, type: Block['type']): boolean;