@chaoschain/sdk 0.2.4 → 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 +53 -0
- package/README.md +135 -1
- package/dist/{IPFSLocal-BqyHRp_l.d.ts → IPFSLocal-B4hnMEfS.d.ts} +1 -1
- package/dist/{IPFSLocal-azjjaiGR.d.cts → IPFSLocal-zRj6kG8e.d.cts} +1 -1
- package/dist/index.cjs +198 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +178 -6
- package/dist/index.d.ts +178 -6
- package/dist/index.js +198 -18
- 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/{types-DZze-Z8B.d.cts → types-BBVtx_jV.d.cts} +10 -2
- package/dist/{types-DZze-Z8B.d.ts → types-BBVtx_jV.d.ts} +10 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,59 @@ 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
|
+
|
|
26
|
+
## [0.3.0] - 2026-03-20
|
|
27
|
+
|
|
28
|
+
### Added
|
|
29
|
+
|
|
30
|
+
- **Session SDK** (`src/session/`): `SessionClient` and `Session` classes for Engineering Studio session ingestion
|
|
31
|
+
- `session.start()` — Create a new coding session
|
|
32
|
+
- `session.log()` — Log events with automatic parent chaining
|
|
33
|
+
- `session.step()` — Convenience wrapper mapping friendly names to canonical event types
|
|
34
|
+
- `session.complete()` — Complete session and get `workflow_id` + `data_hash`
|
|
35
|
+
- Automatic `parent_event_id` chaining across sequential `log()` calls
|
|
36
|
+
- `step()` helper maps friendly names (`planning`, `implementing`, `testing`, `debugging`, `completing`) to canonical event types
|
|
37
|
+
- E2E smoke test script at `scripts/test-session-e2e.ts` for validating against live gateway
|
|
38
|
+
- Session SDK accessible via `sdk.session` when gateway is configured
|
|
39
|
+
- **Verifier Agent Support**: Complete PoA (Proof-of-Agency) scoring utilities for verifier agents
|
|
40
|
+
- `verifyWorkEvidence()` — Validate evidence DAG and extract deterministic signals
|
|
41
|
+
- `extractAgencySignals()` — Extract initiative, collaboration, reasoning signals from evidence
|
|
42
|
+
- `composeScoreVector()` — Compose final score vector with verifier judgment (compliance/efficiency required)
|
|
43
|
+
- `composeScoreVectorWithDefaults()` — Compose scores with fallback defaults
|
|
44
|
+
- `GatewayClient.getPendingWork()` — Discover pending work for a studio
|
|
45
|
+
- `GatewayClient.getWorkEvidence()` — Fetch full evidence graph for work submission
|
|
46
|
+
- Types: `AgencySignals`, `VerifierAssessment`, `WorkVerificationResult`, `EngineeringStudioPolicy`, `WorkMandate`
|
|
47
|
+
- **Verifier Integration Guide** documentation with complete step-by-step workflow
|
|
48
|
+
|
|
49
|
+
### Changed
|
|
50
|
+
|
|
51
|
+
- **Gateway is now always configured by default**: SDK automatically creates a `GatewayClient` pointing to `https://gateway.chaoscha.in` when no `gatewayConfig` or `gatewayUrl` is provided. This is a **breaking change** for code that expected `sdk.gateway` to be `null` when not explicitly configured.
|
|
52
|
+
- Gateway client initialization log now shows the resolved base URL
|
|
53
|
+
- Updated README with comprehensive verifier agent integration examples and 3-layer PoA scoring architecture
|
|
54
|
+
|
|
55
|
+
### Fixed
|
|
56
|
+
|
|
57
|
+
- `randomUUID()` now uses `node:crypto` import for Node.js compatibility
|
|
58
|
+
- **Treasury address correction**: Fixed incorrect treasury address for `base-sepolia` network in `X402PaymentManager` (changed from `0x8004AA63c570c570eBF15376c0dB199918BFe9Fb` to `0x20E7B2A2c8969725b88Dd3EF3a11Bc3353C83F70`)
|
|
59
|
+
- TypeScript unused parameter warning in `computeComplianceSignal()` (renamed `observed` to `_observed`)
|
|
60
|
+
|
|
8
61
|
## [0.2.0] - Unreleased
|
|
9
62
|
|
|
10
63
|
### Added
|
package/README.md
CHANGED
|
@@ -11,6 +11,7 @@ The ChaosChain TypeScript SDK enables developers to build autonomous AI agents w
|
|
|
11
11
|
- **ERC-8004 v1.0** ✅ **100% compliant** - on-chain identity, validation and reputation
|
|
12
12
|
- **ChaosChain Studios** - Multi-agent collaboration with reputation and rewards
|
|
13
13
|
- **Gateway Integration** - Workflow orchestration, crash recovery, and XMTP messaging
|
|
14
|
+
- **Engineering Studio Sessions** - Capture agent work sessions with automatic Evidence DAG construction
|
|
14
15
|
- **x402 payments** using Coinbase's HTTP 402 protocol
|
|
15
16
|
- **Pluggable storage** - IPFS, Pinata, Irys, 0G Storage
|
|
16
17
|
- **Type-safe** - Full TypeScript support with exported types
|
|
@@ -51,6 +52,78 @@ Storage backends are optional and intended for development/testing. In productio
|
|
|
51
52
|
- **Missing RPC URL** → set `rpcUrl` explicitly (recommended for production).
|
|
52
53
|
- **Using Gateway without config** → pass `gatewayConfig` or `gatewayUrl` to the constructor.
|
|
53
54
|
|
|
55
|
+
## Engineering Studio — Session SDK
|
|
56
|
+
|
|
57
|
+
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.
|
|
58
|
+
|
|
59
|
+
**Quick Start:**
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
import { SessionClient } from '@chaoschain/sdk';
|
|
63
|
+
|
|
64
|
+
const client = new SessionClient({
|
|
65
|
+
gatewayUrl: 'https://gateway.chaoscha.in',
|
|
66
|
+
apiKey: process.env.CHAOSCHAIN_API_KEY,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// 1. Start a session
|
|
70
|
+
const session = await client.start({
|
|
71
|
+
studio_address: '0xFA0795fD5D7F58eCAa7Eae35Ad9cB8AED9424Dd0',
|
|
72
|
+
agent_address: '0x9B4Cef62a0ce1671ccFEFA6a6D8cBFa165c49831',
|
|
73
|
+
task_type: 'feature',
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// 2. Log events (automatic parent chaining)
|
|
77
|
+
await session.log({ summary: 'Planning cache layer implementation' });
|
|
78
|
+
|
|
79
|
+
// 3. Use step() for common workflows
|
|
80
|
+
await session.step('implementing', 'Added CacheService class');
|
|
81
|
+
await session.step('testing', 'All 47 tests pass');
|
|
82
|
+
|
|
83
|
+
// 4. Complete and get workflow_id + data_hash
|
|
84
|
+
const { workflow_id, data_hash } = await session.complete();
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
**step() Mappings:**
|
|
88
|
+
|
|
89
|
+
| Friendly Name | Canonical Event Type |
|
|
90
|
+
|--------------|---------------------|
|
|
91
|
+
| `planning` | `plan_created` |
|
|
92
|
+
| `implementing`| `file_written` |
|
|
93
|
+
| `testing` | `test_run` |
|
|
94
|
+
| `debugging` | `debug_step` |
|
|
95
|
+
| `completing` | `submission_created`|
|
|
96
|
+
|
|
97
|
+
**View Your Session:**
|
|
98
|
+
|
|
99
|
+
After completing a session, view it in the browser:
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+
https://gateway.chaoscha.in/v1/sessions/{session_id}/viewer
|
|
103
|
+
```
|
|
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
|
+
|
|
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.
|
|
126
|
+
|
|
54
127
|
## Canonical Examples
|
|
55
128
|
|
|
56
129
|
### 0) Verifier agent (pending work → evidence → scores)
|
|
@@ -100,7 +173,20 @@ for (const work of pending.data.work) {
|
|
|
100
173
|
|
|
101
174
|
**Full verifier flow** (registration, polling loop, reputation): see the [Verifier Integration Guide](https://github.com/ChaosChain/chaoschain/blob/main/docs/VERIFIER_INTEGRATION_GUIDE.md) (or `docs/VERIFIER_INTEGRATION_GUIDE.md` in the ChaosChain repo). Gateway base URL: `https://gateway.chaoscha.in`. Evidence endpoint requires an API key.
|
|
102
175
|
|
|
103
|
-
|
|
176
|
+
#### Recommended verifier flow
|
|
177
|
+
|
|
178
|
+
Use `verifyWorkEvidence()` to validate the DAG and extract signals, then `composeScoreVector()` with your compliance and efficiency assessments:
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
const result = verifyWorkEvidence(evidence, { studioPolicy, workMandate });
|
|
182
|
+
|
|
183
|
+
const scores = composeScoreVector(result.signals, {
|
|
184
|
+
complianceScore: 0.87,
|
|
185
|
+
efficiencyScore: 0.81,
|
|
186
|
+
});
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### 1) Minimal "Happy Path" (Gateway-first)
|
|
104
190
|
|
|
105
191
|
```typescript
|
|
106
192
|
import { ChaosChainSDK, NetworkConfig, AgentRole } from '@chaoschain/sdk';
|
|
@@ -1132,6 +1218,54 @@ npm test -- WalletManager.test.ts
|
|
|
1132
1218
|
npm run test:coverage
|
|
1133
1219
|
```
|
|
1134
1220
|
|
|
1221
|
+
## E2E Testing
|
|
1222
|
+
|
|
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.
|
|
1238
|
+
|
|
1239
|
+
```bash
|
|
1240
|
+
CHAOSCHAIN_API_KEY=cc_... \
|
|
1241
|
+
STUDIO_ADDRESS=0x... \
|
|
1242
|
+
AGENT_ADDRESS=0x... \
|
|
1243
|
+
npx tsx scripts/test-session-e2e.ts
|
|
1244
|
+
```
|
|
1245
|
+
|
|
1246
|
+
### Multi-agent mode
|
|
1247
|
+
|
|
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
|
+
```
|
|
1257
|
+
|
|
1258
|
+
### What the test does
|
|
1259
|
+
|
|
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
|
|
1266
|
+
|
|
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.
|
|
1268
|
+
|
|
1135
1269
|
## FAQ
|
|
1136
1270
|
|
|
1137
1271
|
**Q: Do I need to deploy contracts?**
|
package/dist/index.cjs
CHANGED
|
@@ -15393,6 +15393,189 @@ var StudioClient = class {
|
|
|
15393
15393
|
return ethers.ethers.hexlify(ethers.ethers.randomBytes(32));
|
|
15394
15394
|
}
|
|
15395
15395
|
};
|
|
15396
|
+
var STEP_TYPE_MAP = {
|
|
15397
|
+
planning: "plan_created",
|
|
15398
|
+
testing: "test_run",
|
|
15399
|
+
debugging: "debug_step",
|
|
15400
|
+
implementing: "file_written",
|
|
15401
|
+
completing: "submission_created"
|
|
15402
|
+
};
|
|
15403
|
+
var Session = class {
|
|
15404
|
+
/** Session ID returned by the gateway. */
|
|
15405
|
+
sessionId;
|
|
15406
|
+
gatewayUrl;
|
|
15407
|
+
apiKey;
|
|
15408
|
+
studioAddress;
|
|
15409
|
+
agentAddress;
|
|
15410
|
+
studioPolicyVersion;
|
|
15411
|
+
workMandateId;
|
|
15412
|
+
taskType;
|
|
15413
|
+
lastEventId;
|
|
15414
|
+
/** @internal — use {@link SessionClient.start} to create instances. */
|
|
15415
|
+
constructor(opts) {
|
|
15416
|
+
this.sessionId = opts.sessionId;
|
|
15417
|
+
this.gatewayUrl = opts.gatewayUrl;
|
|
15418
|
+
this.apiKey = opts.apiKey;
|
|
15419
|
+
this.lastEventId = opts.lastEventId ?? null;
|
|
15420
|
+
this.studioAddress = opts.studioAddress;
|
|
15421
|
+
this.agentAddress = opts.agentAddress;
|
|
15422
|
+
this.studioPolicyVersion = opts.studioPolicyVersion;
|
|
15423
|
+
this.workMandateId = opts.workMandateId;
|
|
15424
|
+
this.taskType = opts.taskType;
|
|
15425
|
+
}
|
|
15426
|
+
/**
|
|
15427
|
+
* Log a session event.
|
|
15428
|
+
*
|
|
15429
|
+
* Automatically generates `event_id`, `timestamp`, and chains `parent_event_ids`
|
|
15430
|
+
* from the previous event so the gateway can build a causal DAG.
|
|
15431
|
+
*
|
|
15432
|
+
* @param opts - Event details. Only `summary` is required.
|
|
15433
|
+
* @throws Error if the gateway returns a non-2xx status.
|
|
15434
|
+
*/
|
|
15435
|
+
async log(opts) {
|
|
15436
|
+
const eventId = crypto2.randomUUID();
|
|
15437
|
+
const event = {
|
|
15438
|
+
event_id: eventId,
|
|
15439
|
+
event_type: opts.event_type ?? "artifact_created",
|
|
15440
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
15441
|
+
summary: opts.summary,
|
|
15442
|
+
causality: {
|
|
15443
|
+
parent_event_ids: this.lastEventId ? [this.lastEventId] : []
|
|
15444
|
+
},
|
|
15445
|
+
agent: {
|
|
15446
|
+
agent_address: opts.agent?.agent_address ?? this.agentAddress,
|
|
15447
|
+
role: opts.agent?.role ?? "worker"
|
|
15448
|
+
},
|
|
15449
|
+
studio: {
|
|
15450
|
+
studio_address: this.studioAddress,
|
|
15451
|
+
studio_policy_version: this.studioPolicyVersion
|
|
15452
|
+
},
|
|
15453
|
+
task: {
|
|
15454
|
+
work_mandate_id: this.workMandateId,
|
|
15455
|
+
task_type: this.taskType
|
|
15456
|
+
},
|
|
15457
|
+
...opts.metadata ? { metadata: opts.metadata } : {}
|
|
15458
|
+
};
|
|
15459
|
+
await this.post(`/v1/sessions/${this.sessionId}/events`, [event]);
|
|
15460
|
+
this.lastEventId = eventId;
|
|
15461
|
+
}
|
|
15462
|
+
/**
|
|
15463
|
+
* Convenience wrapper around {@link log} that maps human-friendly step names
|
|
15464
|
+
* to canonical event types.
|
|
15465
|
+
*
|
|
15466
|
+
* Mappings:
|
|
15467
|
+
* - `"planning"` → `plan_created`
|
|
15468
|
+
* - `"testing"` → `test_run`
|
|
15469
|
+
* - `"debugging"` → `debug_step`
|
|
15470
|
+
* - `"implementing"` → `file_written`
|
|
15471
|
+
* - `"completing"` → `submission_created`
|
|
15472
|
+
*
|
|
15473
|
+
* Unknown step types fall back to `artifact_created`.
|
|
15474
|
+
*
|
|
15475
|
+
* @param stepType - Friendly step name.
|
|
15476
|
+
* @param summary - What happened in this step.
|
|
15477
|
+
*/
|
|
15478
|
+
async step(stepType, summary, agent) {
|
|
15479
|
+
const eventType = STEP_TYPE_MAP[stepType] ?? "artifact_created";
|
|
15480
|
+
await this.log({ event_type: eventType, summary, agent });
|
|
15481
|
+
}
|
|
15482
|
+
/**
|
|
15483
|
+
* Complete the session.
|
|
15484
|
+
*
|
|
15485
|
+
* Triggers the on-chain WorkSubmission workflow (if the gateway is configured for it)
|
|
15486
|
+
* and returns `workflow_id` + `data_hash` for downstream verification/scoring.
|
|
15487
|
+
*
|
|
15488
|
+
* @param opts - Optional status (`"completed"` | `"failed"`) and summary.
|
|
15489
|
+
* @returns `{ workflow_id, data_hash }` — both may be `null` if the gateway
|
|
15490
|
+
* workflow engine is not configured.
|
|
15491
|
+
* @throws Error if the gateway returns a non-2xx status.
|
|
15492
|
+
*/
|
|
15493
|
+
async complete(opts) {
|
|
15494
|
+
const body = {};
|
|
15495
|
+
if (opts?.status) body.status = opts.status;
|
|
15496
|
+
if (opts?.summary) body.summary = opts.summary;
|
|
15497
|
+
const data = await this.post(`/v1/sessions/${this.sessionId}/complete`, body);
|
|
15498
|
+
return {
|
|
15499
|
+
workflow_id: data.data?.workflow_id ?? null,
|
|
15500
|
+
data_hash: data.data?.data_hash ?? null
|
|
15501
|
+
};
|
|
15502
|
+
}
|
|
15503
|
+
// ---------------------------------------------------------------------------
|
|
15504
|
+
// Internal HTTP helper
|
|
15505
|
+
// ---------------------------------------------------------------------------
|
|
15506
|
+
async post(path4, body) {
|
|
15507
|
+
const url = `${this.gatewayUrl}${path4}`;
|
|
15508
|
+
const headers = { "Content-Type": "application/json" };
|
|
15509
|
+
if (this.apiKey) headers["X-API-Key"] = this.apiKey;
|
|
15510
|
+
try {
|
|
15511
|
+
const res = await axios2__default.default({ method: "POST", url, data: body, headers, timeout: 3e4 });
|
|
15512
|
+
return res.data;
|
|
15513
|
+
} catch (err) {
|
|
15514
|
+
const axiosErr = err;
|
|
15515
|
+
const status = axiosErr.response?.status ?? 0;
|
|
15516
|
+
const detail = JSON.stringify(axiosErr.response?.data ?? axiosErr.message);
|
|
15517
|
+
throw new Error(`Session request failed: POST ${path4} \u2192 ${status} ${detail}`);
|
|
15518
|
+
}
|
|
15519
|
+
}
|
|
15520
|
+
};
|
|
15521
|
+
|
|
15522
|
+
// src/session/SessionClient.ts
|
|
15523
|
+
var SessionClient = class {
|
|
15524
|
+
gatewayUrl;
|
|
15525
|
+
apiKey;
|
|
15526
|
+
constructor(config = {}) {
|
|
15527
|
+
this.gatewayUrl = (config.gatewayUrl ?? "https://gateway.chaoscha.in").replace(/\/$/, "");
|
|
15528
|
+
this.apiKey = config.apiKey;
|
|
15529
|
+
}
|
|
15530
|
+
/**
|
|
15531
|
+
* Create a new coding session on the gateway.
|
|
15532
|
+
*
|
|
15533
|
+
* Returns a {@link Session} instance that can be used to log events, run steps,
|
|
15534
|
+
* and complete the session. The gateway persists all events and constructs the
|
|
15535
|
+
* Evidence DAG automatically.
|
|
15536
|
+
*
|
|
15537
|
+
* @param opts - Session creation parameters.
|
|
15538
|
+
* @returns A live {@link Session} bound to the newly created session ID.
|
|
15539
|
+
* @throws Error if the gateway returns a non-2xx status.
|
|
15540
|
+
*/
|
|
15541
|
+
async start(opts) {
|
|
15542
|
+
const body = {
|
|
15543
|
+
studio_address: opts.studio_address,
|
|
15544
|
+
agent_address: opts.agent_address
|
|
15545
|
+
};
|
|
15546
|
+
if (opts.work_mandate_id) body.work_mandate_id = opts.work_mandate_id;
|
|
15547
|
+
if (opts.task_type) body.task_type = opts.task_type;
|
|
15548
|
+
if (opts.studio_policy_version) body.studio_policy_version = opts.studio_policy_version;
|
|
15549
|
+
if (opts.session_id) body.session_id = opts.session_id;
|
|
15550
|
+
const url = `${this.gatewayUrl}/v1/sessions`;
|
|
15551
|
+
const headers = { "Content-Type": "application/json" };
|
|
15552
|
+
if (this.apiKey) headers["X-API-Key"] = this.apiKey;
|
|
15553
|
+
let data;
|
|
15554
|
+
try {
|
|
15555
|
+
const res = await axios2__default.default({ method: "POST", url, data: body, headers, timeout: 3e4 });
|
|
15556
|
+
data = res.data;
|
|
15557
|
+
} catch (err) {
|
|
15558
|
+
const axiosErr = err;
|
|
15559
|
+
const status = axiosErr.response?.status ?? 0;
|
|
15560
|
+
const detail = JSON.stringify(axiosErr.response?.data ?? axiosErr.message);
|
|
15561
|
+
throw new Error(`Failed to create session: POST /v1/sessions \u2192 ${status} ${detail}`);
|
|
15562
|
+
}
|
|
15563
|
+
const sessionId = data.data?.session_id;
|
|
15564
|
+
if (!sessionId) {
|
|
15565
|
+
throw new Error("Gateway response missing session_id");
|
|
15566
|
+
}
|
|
15567
|
+
return new Session({
|
|
15568
|
+
sessionId,
|
|
15569
|
+
gatewayUrl: this.gatewayUrl,
|
|
15570
|
+
apiKey: this.apiKey,
|
|
15571
|
+
studioAddress: opts.studio_address,
|
|
15572
|
+
agentAddress: opts.agent_address,
|
|
15573
|
+
studioPolicyVersion: opts.studio_policy_version ?? "engineering-studio-default-v1",
|
|
15574
|
+
workMandateId: opts.work_mandate_id ?? "generic-task",
|
|
15575
|
+
taskType: opts.task_type ?? "general"
|
|
15576
|
+
});
|
|
15577
|
+
}
|
|
15578
|
+
};
|
|
15396
15579
|
|
|
15397
15580
|
// src/ChaosChainSDK.ts
|
|
15398
15581
|
var ChaosChainSDK = class _ChaosChainSDK {
|
|
@@ -15410,8 +15593,10 @@ var ChaosChainSDK = class _ChaosChainSDK {
|
|
|
15410
15593
|
a2aX402Extension;
|
|
15411
15594
|
processIntegrity;
|
|
15412
15595
|
mandateManager;
|
|
15413
|
-
// Gateway client for workflow submission (
|
|
15414
|
-
gateway
|
|
15596
|
+
// Gateway client for workflow submission (always initialized)
|
|
15597
|
+
gateway;
|
|
15598
|
+
/** Session client for Engineering Studio session management. */
|
|
15599
|
+
session;
|
|
15415
15600
|
// Studio client for direct on-chain operations
|
|
15416
15601
|
studio;
|
|
15417
15602
|
// Configuration
|
|
@@ -15576,7 +15761,10 @@ var ChaosChainSDK = class _ChaosChainSDK {
|
|
|
15576
15761
|
const gatewayConfig = config.gatewayConfig ?? (config.gatewayUrl ? { gatewayUrl: config.gatewayUrl } : {});
|
|
15577
15762
|
this.gateway = new GatewayClient(gatewayConfig);
|
|
15578
15763
|
const gatewayBaseUrl = gatewayConfig.baseUrl ?? gatewayConfig.gatewayUrl ?? "https://gateway.chaoscha.in";
|
|
15579
|
-
|
|
15764
|
+
this.session = new SessionClient({
|
|
15765
|
+
gatewayUrl: gatewayBaseUrl,
|
|
15766
|
+
apiKey: gatewayConfig.auth?.apiKey
|
|
15767
|
+
});
|
|
15580
15768
|
this.studio = new StudioClient({
|
|
15581
15769
|
provider: this.provider,
|
|
15582
15770
|
signer: this.walletManager.getWallet(),
|
|
@@ -15589,16 +15777,6 @@ var ChaosChainSDK = class _ChaosChainSDK {
|
|
|
15589
15777
|
);
|
|
15590
15778
|
_ChaosChainSDK.warnedStudioClientProduction = true;
|
|
15591
15779
|
}
|
|
15592
|
-
console.log(`\u{1F680} ChaosChain SDK initialized for ${this.agentName}`);
|
|
15593
|
-
console.log(` Network: ${this.network}`);
|
|
15594
|
-
console.log(` Wallet: ${this.walletManager.getAddress()}`);
|
|
15595
|
-
console.log(` Features:`);
|
|
15596
|
-
console.log(` - ERC-8004: \u2705`);
|
|
15597
|
-
console.log(` - x402 Payments: ${this.x402PaymentManager ? "\u2705" : "\u274C"}`);
|
|
15598
|
-
console.log(` - Multi-Payment: ${this.paymentManager ? "\u2705" : "\u274C"}`);
|
|
15599
|
-
console.log(` - Google AP2: ${this.googleAP2 ? "\u2705" : "\u274C"}`);
|
|
15600
|
-
console.log(` - Process Integrity: ${this.processIntegrity ? "\u2705" : "\u274C"}`);
|
|
15601
|
-
console.log(` - Storage: \u2705`);
|
|
15602
15780
|
}
|
|
15603
15781
|
// ============================================================================
|
|
15604
15782
|
// ERC-8004 Identity Methods
|
|
@@ -16007,7 +16185,7 @@ var ChaosChainSDK = class _ChaosChainSDK {
|
|
|
16007
16185
|
* Get SDK version
|
|
16008
16186
|
*/
|
|
16009
16187
|
getVersion() {
|
|
16010
|
-
return "0.
|
|
16188
|
+
return "0.3.1";
|
|
16011
16189
|
}
|
|
16012
16190
|
/**
|
|
16013
16191
|
* Get SDK capabilities summary
|
|
@@ -16037,9 +16215,11 @@ var ChaosChainSDK = class _ChaosChainSDK {
|
|
|
16037
16215
|
}
|
|
16038
16216
|
/**
|
|
16039
16217
|
* Check if Gateway is configured.
|
|
16218
|
+
* Always returns true in v0.3.0+. Gateway is always initialized pointing to
|
|
16219
|
+
* https://gateway.chaoscha.in unless overridden via gatewayConfig.
|
|
16040
16220
|
*/
|
|
16041
16221
|
isGatewayEnabled() {
|
|
16042
|
-
return
|
|
16222
|
+
return true;
|
|
16043
16223
|
}
|
|
16044
16224
|
/**
|
|
16045
16225
|
* Get Gateway client instance.
|
|
@@ -16803,7 +16983,7 @@ function verifyWorkEvidence(evidence, context) {
|
|
|
16803
16983
|
}
|
|
16804
16984
|
|
|
16805
16985
|
// src/index.ts
|
|
16806
|
-
var SDK_VERSION = "0.
|
|
16986
|
+
var SDK_VERSION = "0.3.1";
|
|
16807
16987
|
var ERC8004_VERSION = "1.0";
|
|
16808
16988
|
var X402_VERSION = "1.0";
|
|
16809
16989
|
var src_default = ChaosChainSDK;
|
|
@@ -16864,6 +17044,8 @@ exports.SDKValidationError = ValidationError;
|
|
|
16864
17044
|
exports.SDK_VERSION = SDK_VERSION;
|
|
16865
17045
|
exports.STUDIO_FACTORY_ABI = STUDIO_FACTORY_ABI;
|
|
16866
17046
|
exports.STUDIO_PROXY_ABI = STUDIO_PROXY_ABI;
|
|
17047
|
+
exports.Session = Session;
|
|
17048
|
+
exports.SessionClient = SessionClient;
|
|
16867
17049
|
exports.StorageError = StorageError;
|
|
16868
17050
|
exports.StudioClient = StudioClient;
|
|
16869
17051
|
exports.StudioManager = StudioManager;
|