@chaoschain/sdk 0.3.0 → 0.3.1

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 CHANGED
@@ -5,6 +5,24 @@ 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.1] - 2026-03-22
9
+
10
+ ### Added
11
+
12
+ - **Multi-agent sessions (per-event agent override)** on `Session.log()` and `Session.step()`:
13
+ - Optional `agent: { agent_address, role? }` on `log()` — override applies to that event only
14
+ - Optional third argument on `step()` for the same override
15
+ - Types: `SessionAgentOverride`, `SessionAgentRole` (`worker` | `verifier` | `collaborator`), aligned with gateway validation
16
+ - Unit tests in `tests/Session.test.ts` for override paths and multi-agent sequences
17
+
18
+ ### Changed
19
+
20
+ - **`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`.
21
+
22
+ ### Fixed
23
+
24
+ - README **E2E Testing** section now documents required vs optional env vars and both smoke-test modes
25
+
8
26
  ## [0.3.0] - 2026-03-20
9
27
 
10
28
  ### Added
package/README.md CHANGED
@@ -102,6 +102,26 @@ After completing a session, view it in the browser:
102
102
  https://gateway.chaoscha.in/v1/sessions/{session_id}/viewer
103
103
  ```
104
104
 
105
+ **Multi-Agent Sessions:**
106
+
107
+ Multiple agents can contribute to the same session by overriding the agent per event:
108
+
109
+ ```typescript
110
+ // Copilot writes code (session default agent)
111
+ await session.step('implementing', 'Added CacheService class');
112
+
113
+ // CodeRabbit reviews (different agent, same session)
114
+ await session.log({
115
+ summary: 'Code review: LGTM',
116
+ agent: { agent_address: '0xCodeRabbit...', role: 'collaborator' },
117
+ });
118
+
119
+ // Copilot continues (back to default automatically)
120
+ await session.step('testing', 'All tests pass');
121
+ ```
122
+
123
+ Valid roles: `worker`, `verifier`, `collaborator`.
124
+
105
125
  **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
126
 
107
127
  ## Canonical Examples
@@ -1200,7 +1220,21 @@ npm run test:coverage
1200
1220
 
1201
1221
  ## E2E Testing
1202
1222
 
1203
- The SDK includes an end-to-end smoke test that validates the Session SDK against the live gateway:
1223
+ The SDK includes an end-to-end smoke test that validates the Session SDK against the live gateway (`scripts/test-session-e2e.ts`).
1224
+
1225
+ ### Environment variables
1226
+
1227
+ | Variable | Required | Description |
1228
+ |----------|----------|-------------|
1229
+ | `CHAOSCHAIN_API_KEY` | **Yes** | API key (e.g. `cc_agent_...`, `cc_worker_...`) |
1230
+ | `STUDIO_ADDRESS` | **Yes** | Studio contract address |
1231
+ | `AGENT_ADDRESS` | **Yes** | Default worker wallet for the session |
1232
+ | `OVERRIDE_AGENT_ADDRESS` | No | Second wallet for per-event collaborator overrides (enables multi-agent path) |
1233
+ | `GATEWAY_URL` | No | Defaults to `https://gateway.chaoscha.in` |
1234
+
1235
+ ### Single-agent mode (default)
1236
+
1237
+ Four sequential events on the default agent. Pass when `node_count >= 4` on the session context response.
1204
1238
 
1205
1239
  ```bash
1206
1240
  CHAOSCHAIN_API_KEY=cc_... \
@@ -1209,21 +1243,28 @@ AGENT_ADDRESS=0x... \
1209
1243
  npx tsx scripts/test-session-e2e.ts
1210
1244
  ```
1211
1245
 
1212
- **Required Environment Variables:**
1246
+ ### Multi-agent mode
1213
1247
 
1214
- - `CHAOSCHAIN_API_KEY` Your API key (e.g., `cc_agent_...` or `cc_worker_...`)
1215
- - `STUDIO_ADDRESS` — Studio contract address (e.g., `0xFA0795fD5D7F58eCAa7Eae35Ad9cB8AED9424Dd0`)
1216
- - `AGENT_ADDRESS` — Worker agent wallet address
1248
+ Set `OVERRIDE_AGENT_ADDRESS` to run three additional collaborator events (per-event `agent` override). Pass when `node_count >= 7`.
1249
+
1250
+ ```bash
1251
+ CHAOSCHAIN_API_KEY=cc_... \
1252
+ STUDIO_ADDRESS=0x... \
1253
+ AGENT_ADDRESS=0x... \
1254
+ OVERRIDE_AGENT_ADDRESS=0x... \
1255
+ npx tsx scripts/test-session-e2e.ts
1256
+ ```
1217
1257
 
1218
- **What the Test Does:**
1258
+ ### What the test does
1219
1259
 
1220
- 1. Creates a `SessionClient` and starts a new session
1221
- 2. Logs 4 sequential events with automatic parent chaining
1222
- 3. Completes the session and verifies `workflow_id` + `data_hash` are returned
1223
- 4. Validates the context endpoint returns correct evidence summary
1224
- 5. Verifies the session viewer is accessible
1260
+ 1. Creates a `SessionClient` and starts a session
1261
+ 2. Logs four base events with automatic parent chaining
1262
+ 3. **(Multi-agent only)** Logs three more events with `agent` override + default agent alternation
1263
+ 4. Completes the session; prints `workflow_id` and `data_hash` when present
1264
+ 5. GET `/v1/sessions/{id}/context` checks `session_metadata` and `evidence_summary.node_count` against the mode threshold
1265
+ 6. GET `/v1/sessions/{id}/viewer` — expects HTTP 200
1225
1266
 
1226
- **PASS means:** All SDK methods work correctly, the gateway accepts and processes sessions, and the Evidence DAG is constructed properly. The test exits with code 0 on success, 1 on failure.
1267
+ **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
1268
 
1228
1269
  ## FAQ
1229
1270
 
package/dist/index.cjs CHANGED
@@ -15442,7 +15442,10 @@ var Session = class {
15442
15442
  causality: {
15443
15443
  parent_event_ids: this.lastEventId ? [this.lastEventId] : []
15444
15444
  },
15445
- agent: { agent_address: this.agentAddress, role: "worker" },
15445
+ agent: {
15446
+ agent_address: opts.agent?.agent_address ?? this.agentAddress,
15447
+ role: opts.agent?.role ?? "worker"
15448
+ },
15446
15449
  studio: {
15447
15450
  studio_address: this.studioAddress,
15448
15451
  studio_policy_version: this.studioPolicyVersion
@@ -15472,9 +15475,9 @@ var Session = class {
15472
15475
  * @param stepType - Friendly step name.
15473
15476
  * @param summary - What happened in this step.
15474
15477
  */
15475
- async step(stepType, summary) {
15478
+ async step(stepType, summary, agent) {
15476
15479
  const eventType = STEP_TYPE_MAP[stepType] ?? "artifact_created";
15477
- await this.log({ event_type: eventType, summary });
15480
+ await this.log({ event_type: eventType, summary, agent });
15478
15481
  }
15479
15482
  /**
15480
15483
  * Complete the session.
@@ -16182,7 +16185,7 @@ var ChaosChainSDK = class _ChaosChainSDK {
16182
16185
  * Get SDK version
16183
16186
  */
16184
16187
  getVersion() {
16185
- return "0.3.0";
16188
+ return "0.3.1";
16186
16189
  }
16187
16190
  /**
16188
16191
  * Get SDK capabilities summary
@@ -16980,7 +16983,7 @@ function verifyWorkEvidence(evidence, context) {
16980
16983
  }
16981
16984
 
16982
16985
  // src/index.ts
16983
- var SDK_VERSION = "0.3.0";
16986
+ var SDK_VERSION = "0.3.1";
16984
16987
  var ERC8004_VERSION = "1.0";
16985
16988
  var X402_VERSION = "1.0";
16986
16989
  var src_default = ChaosChainSDK;