@chaoschain/sdk 0.3.0 → 0.3.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/CHANGELOG.md +33 -0
- package/README.md +102 -12
- package/dist/{IPFSLocal-B4hnMEfS.d.ts → IPFSLocal-B_Sgmd_Q.d.ts} +1 -1
- package/dist/{IPFSLocal-zRj6kG8e.d.cts → IPFSLocal-DjFddwHD.d.cts} +1 -1
- package/dist/gateway/index.cjs +591 -0
- package/dist/gateway/index.cjs.map +1 -0
- package/dist/gateway/index.d.cts +3 -0
- package/dist/gateway/index.d.ts +3 -0
- package/dist/gateway/index.js +581 -0
- package/dist/gateway/index.js.map +1 -0
- package/dist/index-CL0fidQs.d.ts +223 -0
- package/dist/index-iUO5l1VD.d.cts +223 -0
- package/dist/index.cjs +8 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -382
- package/dist/index.d.ts +9 -382
- package/dist/index.js +8 -5
- package/dist/index.js.map +1 -1
- package/dist/providers/compute/index.d.cts +1 -1
- package/dist/providers/compute/index.d.ts +1 -1
- package/dist/providers/storage/index.d.cts +2 -2
- package/dist/providers/storage/index.d.ts +2 -2
- package/dist/session/index.cjs +196 -0
- package/dist/session/index.cjs.map +1 -0
- package/dist/session/index.d.cts +169 -0
- package/dist/session/index.d.ts +169 -0
- package/dist/session/index.js +189 -0
- package/dist/session/index.js.map +1 -0
- package/dist/{types-BBVtx_jV.d.cts → types-C0Ay90UI.d.cts} +1 -1
- package/dist/{types-BBVtx_jV.d.ts → types-C0Ay90UI.d.ts} +1 -1
- package/package.json +11 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,39 @@ All notable changes to the ChaosChain TypeScript SDK will be documented in this
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.3.2] - 2026-03-23
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **Subpath package exports** for edge/serverless: `@chaoschain/sdk/session` and `@chaoschain/sdk/gateway` (lightweight bundles; no ethers / IPFS / heavy Node deps in those entry points)
|
|
13
|
+
- **`src/gateway/index.ts`** — re-exports `GatewayClient`, selected gateway types, and gateway-related exceptions
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
|
|
17
|
+
- **`src/types.ts`** — `import type` for `ethers` where only types are needed (no runtime change)
|
|
18
|
+
|
|
19
|
+
### Documentation
|
|
20
|
+
|
|
21
|
+
- README **Edge Runtime / Serverless Usage**: caveat that `GatewayClient.submitWork()` uses `Buffer`; read/poll APIs are safe on strict V8 isolates; binary `submitWork` needs Node compat or a Buffer polyfill
|
|
22
|
+
|
|
23
|
+
## [0.3.1] - 2026-03-22
|
|
24
|
+
|
|
25
|
+
### Added
|
|
26
|
+
|
|
27
|
+
- **Multi-agent sessions (per-event agent override)** on `Session.log()` and `Session.step()`:
|
|
28
|
+
- Optional `agent: { agent_address, role? }` on `log()` — override applies to that event only
|
|
29
|
+
- Optional third argument on `step()` for the same override
|
|
30
|
+
- Types: `SessionAgentOverride`, `SessionAgentRole` (`worker` | `verifier` | `collaborator`), aligned with gateway validation
|
|
31
|
+
- Unit tests in `tests/Session.test.ts` for override paths and multi-agent sequences
|
|
32
|
+
|
|
33
|
+
### Changed
|
|
34
|
+
|
|
35
|
+
- **`scripts/test-session-e2e.ts`**: `OVERRIDE_AGENT_ADDRESS` is **optional**. Without it, the smoke test runs the original 4-event single-agent path (`node_count >= 4`). With it set, the script logs extra collaborator events and expects `node_count >= 7`.
|
|
36
|
+
|
|
37
|
+
### Fixed
|
|
38
|
+
|
|
39
|
+
- README **E2E Testing** section now documents required vs optional env vars and both smoke-test modes
|
|
40
|
+
|
|
8
41
|
## [0.3.0] - 2026-03-20
|
|
9
42
|
|
|
10
43
|
### Added
|
package/README.md
CHANGED
|
@@ -52,6 +52,55 @@ Storage backends are optional and intended for development/testing. In productio
|
|
|
52
52
|
- **Missing RPC URL** → set `rpcUrl` explicitly (recommended for production).
|
|
53
53
|
- **Using Gateway without config** → pass `gatewayConfig` or `gatewayUrl` to the constructor.
|
|
54
54
|
|
|
55
|
+
## Edge Runtime / Serverless Usage
|
|
56
|
+
|
|
57
|
+
The main entry point (`@chaoschain/sdk`) includes ethers, IPFS, and Node.js-only dependencies that break in edge runtimes. If you are deploying to **Cloudflare Workers**, **Vercel Edge Functions**, **Deno Deploy**, or any V8 isolate environment, use the lightweight subpath imports instead:
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
import { SessionClient } from '@chaoschain/sdk/session'; // 6.59 KB
|
|
61
|
+
import { GatewayClient } from '@chaoschain/sdk/gateway'; // 20 KB
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
> **Note:** `GatewayClient.submitWork()` uses `Buffer` internally for binary encoding.
|
|
65
|
+
> For read-only and polling operations (`getWorkflow`, `getPendingWork`, `getWorkEvidence`),
|
|
66
|
+
> the gateway subpath works in all V8 isolate environments.
|
|
67
|
+
> For `submitWork` with binary content, use Node.js compat mode or a Buffer polyfill.
|
|
68
|
+
|
|
69
|
+
| Entry point | Size | What's included |
|
|
70
|
+
|---|---|---|
|
|
71
|
+
| `@chaoschain/sdk` | 490 KB | Everything: ethers, storage backends, IPFS, all modules |
|
|
72
|
+
| `@chaoschain/sdk/session` | 6.59 KB | `SessionClient`, `Session`, session types |
|
|
73
|
+
| `@chaoschain/sdk/gateway` | 20 KB | `GatewayClient`, workflow types, gateway exceptions |
|
|
74
|
+
|
|
75
|
+
Both subpaths are free of ethers, StorageBackends, form-data, and Node.js built-in dependencies. Use them when you only need to interact with the gateway via HTTP (sessions, score submission, workflow polling).
|
|
76
|
+
|
|
77
|
+
**Example: Cloudflare Worker**
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
import { SessionClient } from '@chaoschain/sdk/session';
|
|
81
|
+
import { GatewayClient } from '@chaoschain/sdk/gateway';
|
|
82
|
+
|
|
83
|
+
export default {
|
|
84
|
+
async fetch(request: Request, env: Env) {
|
|
85
|
+
const client = new SessionClient({
|
|
86
|
+
gatewayUrl: env.GATEWAY_URL,
|
|
87
|
+
apiKey: env.CHAOSCHAIN_API_KEY,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const session = await client.start({
|
|
91
|
+
studio_address: env.STUDIO_ADDRESS,
|
|
92
|
+
agent_address: env.AGENT_ADDRESS,
|
|
93
|
+
task_type: 'feature',
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
await session.step('implementing', 'Built feature X');
|
|
97
|
+
const { workflow_id, data_hash } = await session.complete();
|
|
98
|
+
|
|
99
|
+
return Response.json({ workflow_id, data_hash });
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
```
|
|
103
|
+
|
|
55
104
|
## Engineering Studio — Session SDK
|
|
56
105
|
|
|
57
106
|
The Session SDK enables AI agents to capture their work sessions without manually constructing event schemas or DAGs. Sessions automatically build a verifiable Evidence DAG that produces trust profiles for reputation and scoring.
|
|
@@ -102,6 +151,26 @@ After completing a session, view it in the browser:
|
|
|
102
151
|
https://gateway.chaoscha.in/v1/sessions/{session_id}/viewer
|
|
103
152
|
```
|
|
104
153
|
|
|
154
|
+
**Multi-Agent Sessions:**
|
|
155
|
+
|
|
156
|
+
Multiple agents can contribute to the same session by overriding the agent per event:
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
// Copilot writes code (session default agent)
|
|
160
|
+
await session.step('implementing', 'Added CacheService class');
|
|
161
|
+
|
|
162
|
+
// CodeRabbit reviews (different agent, same session)
|
|
163
|
+
await session.log({
|
|
164
|
+
summary: 'Code review: LGTM',
|
|
165
|
+
agent: { agent_address: '0xCodeRabbit...', role: 'collaborator' },
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
// Copilot continues (back to default automatically)
|
|
169
|
+
await session.step('testing', 'All tests pass');
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Valid roles: `worker`, `verifier`, `collaborator`.
|
|
173
|
+
|
|
105
174
|
**Note:** The Session SDK only requires `gatewayUrl` and `apiKey` — no private key or blockchain signer needed for session-only usage. Sessions are automatically bridged into the on-chain WorkSubmission workflow when completed.
|
|
106
175
|
|
|
107
176
|
## Canonical Examples
|
|
@@ -1200,7 +1269,21 @@ npm run test:coverage
|
|
|
1200
1269
|
|
|
1201
1270
|
## E2E Testing
|
|
1202
1271
|
|
|
1203
|
-
The SDK includes an end-to-end smoke test that validates the Session SDK against the live gateway
|
|
1272
|
+
The SDK includes an end-to-end smoke test that validates the Session SDK against the live gateway (`scripts/test-session-e2e.ts`).
|
|
1273
|
+
|
|
1274
|
+
### Environment variables
|
|
1275
|
+
|
|
1276
|
+
| Variable | Required | Description |
|
|
1277
|
+
|----------|----------|-------------|
|
|
1278
|
+
| `CHAOSCHAIN_API_KEY` | **Yes** | API key (e.g. `cc_agent_...`, `cc_worker_...`) |
|
|
1279
|
+
| `STUDIO_ADDRESS` | **Yes** | Studio contract address |
|
|
1280
|
+
| `AGENT_ADDRESS` | **Yes** | Default worker wallet for the session |
|
|
1281
|
+
| `OVERRIDE_AGENT_ADDRESS` | No | Second wallet for per-event collaborator overrides (enables multi-agent path) |
|
|
1282
|
+
| `GATEWAY_URL` | No | Defaults to `https://gateway.chaoscha.in` |
|
|
1283
|
+
|
|
1284
|
+
### Single-agent mode (default)
|
|
1285
|
+
|
|
1286
|
+
Four sequential events on the default agent. Pass when `node_count >= 4` on the session context response.
|
|
1204
1287
|
|
|
1205
1288
|
```bash
|
|
1206
1289
|
CHAOSCHAIN_API_KEY=cc_... \
|
|
@@ -1209,21 +1292,28 @@ AGENT_ADDRESS=0x... \
|
|
|
1209
1292
|
npx tsx scripts/test-session-e2e.ts
|
|
1210
1293
|
```
|
|
1211
1294
|
|
|
1212
|
-
|
|
1295
|
+
### Multi-agent mode
|
|
1296
|
+
|
|
1297
|
+
Set `OVERRIDE_AGENT_ADDRESS` to run three additional collaborator events (per-event `agent` override). Pass when `node_count >= 7`.
|
|
1213
1298
|
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1299
|
+
```bash
|
|
1300
|
+
CHAOSCHAIN_API_KEY=cc_... \
|
|
1301
|
+
STUDIO_ADDRESS=0x... \
|
|
1302
|
+
AGENT_ADDRESS=0x... \
|
|
1303
|
+
OVERRIDE_AGENT_ADDRESS=0x... \
|
|
1304
|
+
npx tsx scripts/test-session-e2e.ts
|
|
1305
|
+
```
|
|
1217
1306
|
|
|
1218
|
-
|
|
1307
|
+
### What the test does
|
|
1219
1308
|
|
|
1220
|
-
1. Creates a `SessionClient` and starts a
|
|
1221
|
-
2. Logs
|
|
1222
|
-
3.
|
|
1223
|
-
4.
|
|
1224
|
-
5.
|
|
1309
|
+
1. Creates a `SessionClient` and starts a session
|
|
1310
|
+
2. Logs four base events with automatic parent chaining
|
|
1311
|
+
3. **(Multi-agent only)** Logs three more events with `agent` override + default agent alternation
|
|
1312
|
+
4. Completes the session; prints `workflow_id` and `data_hash` when present
|
|
1313
|
+
5. GET `/v1/sessions/{id}/context` — checks `session_metadata` and `evidence_summary.node_count` against the mode threshold
|
|
1314
|
+
6. GET `/v1/sessions/{id}/viewer` — expects HTTP 200
|
|
1225
1315
|
|
|
1226
|
-
**PASS
|
|
1316
|
+
**PASS:** Exit code `0` when all steps succeed and `node_count` meets the mode threshold (`>= 4` single-agent, `>= 7` multi-agent). Exit code `1` on failure.
|
|
1227
1317
|
|
|
1228
1318
|
## FAQ
|
|
1229
1319
|
|