@chaoslabs/ai-sdk 0.0.3 → 0.0.4
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/README.md +46 -1
- package/dist/__tests__/http-streaming.test.d.ts +15 -0
- package/dist/__tests__/http-streaming.test.js +1401 -0
- package/dist/__tests__/stream.test.d.ts +1 -0
- package/dist/__tests__/stream.test.js +345 -0
- package/dist/__tests__/trivial.test.d.ts +1 -0
- package/dist/__tests__/trivial.test.js +6 -0
- package/dist/client.d.ts +21 -5
- package/dist/client.js +75 -29
- package/dist/http-streaming.d.ts +55 -0
- package/dist/http-streaming.js +359 -0
- package/dist/index.d.ts +4 -5
- package/dist/index.js +3 -26
- package/dist/schemas.d.ts +97 -405
- package/dist/schemas.js +18 -47
- package/dist/stream.d.ts +32 -0
- package/dist/stream.js +127 -0
- package/dist/types.d.ts +11 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -3,7 +3,12 @@
|
|
|
3
3
|
Official TypeScript SDK for the Chaos AI API. Build DeFi-aware applications with portfolio analysis, swap operations, lending, and more.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @chaoslabs/ai-sdk
|
|
9
|
+
# or
|
|
10
|
+
bun add @chaoslabs/ai-sdk
|
|
11
|
+
```
|
|
7
12
|
|
|
8
13
|
## Quick Start
|
|
9
14
|
|
|
@@ -50,6 +55,36 @@ for (const block of blocks) {
|
|
|
50
55
|
}
|
|
51
56
|
```
|
|
52
57
|
|
|
58
|
+
### 4. Real-Time Streaming (Optional)
|
|
59
|
+
|
|
60
|
+
Get real-time updates as the AI processes your request:
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
import { Chaos, WALLET_MODEL, type StreamMessage } from '@chaoslabs/ai-sdk';
|
|
64
|
+
|
|
65
|
+
const response = await chaos.chat.responses.create({
|
|
66
|
+
model: WALLET_MODEL,
|
|
67
|
+
input: [
|
|
68
|
+
{ type: 'message', role: 'user', content: 'What is in my portfolio?' }
|
|
69
|
+
],
|
|
70
|
+
metadata: { user_id: 'user-123', session_id: 'session-abc', wallet_id: '0x...' },
|
|
71
|
+
onStreamEvent: (msg: StreamMessage) => {
|
|
72
|
+
// Called immediately as each message arrives from the server
|
|
73
|
+
console.log(`[${msg.type}]`, msg.content);
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
**Stream Message Types:**
|
|
79
|
+
|
|
80
|
+
| Type | Description |
|
|
81
|
+
|------|-------------|
|
|
82
|
+
| `agent_status_change` | Status updates: `processing`, `done`, `error` |
|
|
83
|
+
| `agent_message` | Progress messages during processing |
|
|
84
|
+
| `report` | Content blocks as they're generated |
|
|
85
|
+
| `follow_up_suggestions` | Suggested follow-up queries |
|
|
86
|
+
| `user_input` | Clarification requests |
|
|
87
|
+
|
|
53
88
|
## API Reference
|
|
54
89
|
|
|
55
90
|
### Chaos Client
|
|
@@ -66,6 +101,15 @@ new Chaos(config: ChaosConfig)
|
|
|
66
101
|
| `baseUrl` | `string` | `https://ai-staging.chaoslabs.co` | API base URL |
|
|
67
102
|
| `timeout` | `number` | `120000` | Request timeout in milliseconds |
|
|
68
103
|
|
|
104
|
+
### Request Options
|
|
105
|
+
|
|
106
|
+
| Option | Type | Description |
|
|
107
|
+
|--------|------|-------------|
|
|
108
|
+
| `model` | `string` | Model to use (e.g., `WALLET_MODEL`) |
|
|
109
|
+
| `input` | `InputItem[]` | Conversation messages |
|
|
110
|
+
| `metadata` | `RequestMetadata` | User, session, and wallet info |
|
|
111
|
+
| `onStreamEvent` | `(msg: StreamMessage) => void` | Real-time streaming callback |
|
|
112
|
+
|
|
69
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.
|
|
70
114
|
|
|
71
115
|
**Available Environments:**
|
|
@@ -220,6 +264,7 @@ import type {
|
|
|
220
264
|
Block,
|
|
221
265
|
TableBlock,
|
|
222
266
|
TransactionActionBlock,
|
|
267
|
+
StreamMessage,
|
|
223
268
|
// ... and more
|
|
224
269
|
} from '@chaoslabs/ai-sdk';
|
|
225
270
|
```
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP Streaming Tests (TDD - RED Phase)
|
|
3
|
+
*
|
|
4
|
+
* These tests verify the http-based streaming implementation that will replace fetch.
|
|
5
|
+
* Tests are written BEFORE the implementation (TDD RED phase).
|
|
6
|
+
*
|
|
7
|
+
* The implementation will use Node's native http/https modules for streaming
|
|
8
|
+
* instead of fetch to ensure proper incremental streaming behavior.
|
|
9
|
+
*
|
|
10
|
+
* KEY TESTS THAT MUST FAIL INITIALLY:
|
|
11
|
+
* - httpStreamRequest function (doesn't exist yet)
|
|
12
|
+
* - StreamingHttpClient class (doesn't exist yet)
|
|
13
|
+
* - useNativeHttp option (doesn't exist yet)
|
|
14
|
+
*/
|
|
15
|
+
export {};
|