@chaoslabs/ai-sdk 0.0.1 → 0.0.2
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/dist/index.d.ts +4 -2
- package/dist/index.js +3 -1
- package/dist/response.js +49 -5
- package/dist/schemas.d.ts +739 -492
- package/dist/schemas.js +221 -110
- package/dist/types.d.ts +171 -104
- package/dist/types.js +12 -19
- package/package.json +8 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { Chaos as default, Chaos, WALLET_MODEL, ASK_MODEL } from './client.js';
|
|
2
2
|
export type { V1WalletRequest, V1AskRequest } from './request.js';
|
|
3
3
|
export type { V1StreamEvent, V1FinalState } from './response.js';
|
|
4
|
-
export type { ChaosConfig, CreateResponseParams, RequestMetadata, InputItem, Response, OutputItem, ContentPart, Block, OutputText, ChaosBlock, TableBlock,
|
|
4
|
+
export type { ChaosConfig, CreateResponseParams, RequestMetadata, InputItem, Response, OutputItem, ContentPart, Block, OutputText, ChaosBlock, MarkdownBlock, TableBlock, TableColumnType, TableSortDirection, TableColumnConfig, ChartBlock, ChartSeries, ChartSegment, ChartAxis, ChartDataPoint, TransactionActionBlock, Primitive, PrimitiveIcon, PrimitiveLineItem, PrimitiveDisplay, RawTransaction, TransactionGroup, Risks, RiskInfoItem, InteractiveBlock, InteractiveOption, ResponseError, } from './types.js';
|
|
5
5
|
export { ChaosError, ChaosTimeoutError } from './types.js';
|
|
6
|
-
export { extractText, extractBlocks, hasRisks, hasBlockers, isTableBlock,
|
|
6
|
+
export { extractText, extractBlocks, hasRisks, hasBlockers, isTableBlock, isChartBlock, isTransactionActionBlock, isInteractiveBlock, isMarkdownBlock, isOutputText, isChaosBlock, } from './types.js';
|
|
7
|
+
export { BlockSchema, parseRawBlock, detectBlockType } from './schemas.js';
|
|
8
|
+
export type { BlockParsed } from './schemas.js';
|
package/dist/index.js
CHANGED
|
@@ -3,4 +3,6 @@ export { Chaos as default, Chaos, WALLET_MODEL, ASK_MODEL } from './client.js';
|
|
|
3
3
|
// Export error classes
|
|
4
4
|
export { ChaosError, ChaosTimeoutError } from './types.js';
|
|
5
5
|
// Export helper functions
|
|
6
|
-
export { extractText, extractBlocks, hasRisks, hasBlockers, isTableBlock,
|
|
6
|
+
export { extractText, extractBlocks, hasRisks, hasBlockers, isTableBlock, isChartBlock, isTransactionActionBlock, isInteractiveBlock, isMarkdownBlock, isOutputText, isChaosBlock, } from './types.js';
|
|
7
|
+
// Export schemas for validation
|
|
8
|
+
export { BlockSchema, parseRawBlock, detectBlockType } from './schemas.js';
|
package/dist/response.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
//
|
|
3
3
|
// Parses responses from /v1/chat/stream endpoint.
|
|
4
4
|
// Handles type: "report" events with content.data blocks.
|
|
5
|
-
import {
|
|
5
|
+
import { parseRawBlock } from './schemas.js';
|
|
6
6
|
// ============================================================================
|
|
7
7
|
// Response Parser
|
|
8
8
|
// ============================================================================
|
|
@@ -67,6 +67,48 @@ export async function parseV1Stream(body, onEvent) {
|
|
|
67
67
|
}
|
|
68
68
|
return { blocks };
|
|
69
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Parse a raw block using schema detection.
|
|
72
|
+
* Returns the parsed block or null if parsing fails.
|
|
73
|
+
* Transforms legacy data formats to normalized structure.
|
|
74
|
+
*/
|
|
75
|
+
function parseBlock(rawBlock) {
|
|
76
|
+
const result = parseRawBlock(rawBlock);
|
|
77
|
+
if (result.success) {
|
|
78
|
+
const block = result.data;
|
|
79
|
+
// Transform legacy chart data format to segments
|
|
80
|
+
if (block.type === 'chart') {
|
|
81
|
+
const chartBlock = block;
|
|
82
|
+
// If server sent data as [[label, value], ...] but not segments, convert it
|
|
83
|
+
if (chartBlock.data && (!chartBlock.segments || chartBlock.segments.length === 0)) {
|
|
84
|
+
chartBlock.segments = chartBlock.data.map(([label, value]) => ({
|
|
85
|
+
label,
|
|
86
|
+
value,
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
// Clean up null values for cleaner API
|
|
90
|
+
if (chartBlock.segments === null)
|
|
91
|
+
chartBlock.segments = undefined;
|
|
92
|
+
if (chartBlock.series === null)
|
|
93
|
+
chartBlock.series = undefined;
|
|
94
|
+
if (chartBlock.categories === null)
|
|
95
|
+
chartBlock.categories = undefined;
|
|
96
|
+
if (chartBlock.xAxis === null)
|
|
97
|
+
chartBlock.xAxis = undefined;
|
|
98
|
+
if (chartBlock.yAxis === null)
|
|
99
|
+
chartBlock.yAxis = undefined;
|
|
100
|
+
if (chartBlock.sourceName === null)
|
|
101
|
+
chartBlock.sourceName = undefined;
|
|
102
|
+
if (chartBlock.timeframe === null)
|
|
103
|
+
chartBlock.timeframe = undefined;
|
|
104
|
+
if (chartBlock.isCurrency === null)
|
|
105
|
+
chartBlock.isCurrency = undefined;
|
|
106
|
+
}
|
|
107
|
+
return block;
|
|
108
|
+
}
|
|
109
|
+
console.error('Block parse error:', result.error);
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
70
112
|
/**
|
|
71
113
|
* Convert v1 final state to SDK Response format.
|
|
72
114
|
*/
|
|
@@ -83,8 +125,8 @@ export function toV1Response(responseId, model, finalState) {
|
|
|
83
125
|
});
|
|
84
126
|
}
|
|
85
127
|
else if (rawBlock && typeof rawBlock === 'object') {
|
|
86
|
-
// Block content -
|
|
87
|
-
const block =
|
|
128
|
+
// Block content - parse with schema
|
|
129
|
+
const block = parseBlock(rawBlock);
|
|
88
130
|
if (block) {
|
|
89
131
|
content.push({
|
|
90
132
|
type: 'chaos.block',
|
|
@@ -95,11 +137,13 @@ export function toV1Response(responseId, model, finalState) {
|
|
|
95
137
|
}
|
|
96
138
|
}
|
|
97
139
|
const output = content.length > 0
|
|
98
|
-
? [
|
|
140
|
+
? [
|
|
141
|
+
{
|
|
99
142
|
type: 'message',
|
|
100
143
|
role: 'assistant',
|
|
101
144
|
content,
|
|
102
|
-
}
|
|
145
|
+
},
|
|
146
|
+
]
|
|
103
147
|
: [];
|
|
104
148
|
return {
|
|
105
149
|
id: responseId,
|