@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.
@@ -0,0 +1,223 @@
1
+ import { G as GatewayClientConfig, $ as GatewayHealthResponse, g as WorkflowStatus, h as ScoreSubmissionMode, s as PendingWorkResponse, t as WorkEvidenceResponse, q as WorkflowError } from './types-C0Ay90UI.js';
2
+
3
+ declare class GatewayClient {
4
+ private gatewayUrl;
5
+ private timeout;
6
+ private maxPollTime;
7
+ private pollInterval;
8
+ private defaultHeaders?;
9
+ private auth?;
10
+ private retryConfig?;
11
+ constructor(config: GatewayClientConfig);
12
+ private _resolveTimeout;
13
+ private _resolveAuthMode;
14
+ private _buildHeaders;
15
+ private _classifyStatusCode;
16
+ private _normalizeError;
17
+ private _getRetryDelayMs;
18
+ private _sleep;
19
+ /**
20
+ * Make HTTP request to Gateway.
21
+ * Handles errors and transforms them to Gateway exceptions.
22
+ */
23
+ private _request;
24
+ /**
25
+ * Parse workflow status from API response.
26
+ */
27
+ private _parseWorkflowStatus;
28
+ healthCheck(): Promise<GatewayHealthResponse>;
29
+ isHealthy(): Promise<boolean>;
30
+ /**
31
+ * Create a work submission workflow.
32
+ * POST /workflows/work-submission
33
+ *
34
+ * SDK prepares inputs; Gateway handles:
35
+ * - Evidence upload to Arweave
36
+ * - Transaction submission
37
+ * - Confirmation waiting
38
+ *
39
+ * @param studioAddress - Ethereum address of the studio
40
+ * @param epoch - Epoch number
41
+ * @param agentAddress - Ethereum address of the submitting agent
42
+ * @param dataHash - Bytes32 hash of the work (as hex string)
43
+ * @param threadRoot - Bytes32 DKG thread root (as hex string)
44
+ * @param evidenceRoot - Bytes32 evidence Merkle root (as hex string)
45
+ * @param evidenceContent - Raw evidence bytes (will be base64 encoded)
46
+ * @param signerAddress - Ethereum address of the signer (must be registered in Gateway)
47
+ * @returns WorkflowStatus - Initial status of the created workflow
48
+ */
49
+ submitWork(studioAddress: string, epoch: number, agentAddress: string, dataHash: string, threadRoot: string, evidenceRoot: string, evidenceContent: Buffer | string, signerAddress: string): Promise<WorkflowStatus>;
50
+ /**
51
+ * Create a score submission workflow.
52
+ * POST /workflows/score-submission
53
+ *
54
+ * Supports two modes:
55
+ * - DIRECT (default): Simple direct scoring, requires workerAddress
56
+ * - COMMIT_REVEAL: Commit-reveal pattern, requires salt
57
+ *
58
+ * @param studioAddress - Ethereum address of the studio
59
+ * @param epoch - Epoch number
60
+ * @param validatorAddress - Ethereum address of the validator
61
+ * @param dataHash - Bytes32 hash of the work being scored (as hex string)
62
+ * @param scores - Array of dimension scores (0-10000 basis points)
63
+ * @param signerAddress - Ethereum address of the signer
64
+ * @param options - Additional options (workerAddress, salt, mode)
65
+ */
66
+ submitScore(studioAddress: string, epoch: number, validatorAddress: string, dataHash: string, scores: number[], signerAddress: string, options?: {
67
+ workerAddress?: string;
68
+ salt?: string;
69
+ mode?: ScoreSubmissionMode;
70
+ }): Promise<WorkflowStatus>;
71
+ /**
72
+ * Create a close epoch workflow.
73
+ * POST /workflows/close-epoch
74
+ *
75
+ * This is economically final — cannot be undone.
76
+ *
77
+ * @param studioAddress - Ethereum address of the studio
78
+ * @param epoch - Epoch number to close
79
+ * @param signerAddress - Ethereum address of the signer
80
+ */
81
+ closeEpoch(studioAddress: string, epoch: number, signerAddress: string): Promise<WorkflowStatus>;
82
+ /**
83
+ * Get workflow status by ID.
84
+ * GET /workflows/{id}
85
+ */
86
+ getWorkflow(workflowId: string): Promise<WorkflowStatus>;
87
+ /**
88
+ * List workflows with optional filters.
89
+ * GET /workflows?studio=&state=&type=
90
+ */
91
+ listWorkflows(options?: {
92
+ studio?: string;
93
+ state?: string;
94
+ workflowType?: string;
95
+ }): Promise<WorkflowStatus[]>;
96
+ /**
97
+ * Poll workflow until it reaches a terminal state.
98
+ *
99
+ * @param workflowId - UUID of the workflow
100
+ * @param options - Polling options
101
+ * @throws WorkflowFailedError - If workflow reaches FAILED state
102
+ * @throws GatewayTimeoutError - If maxWait exceeded
103
+ */
104
+ waitForCompletion(workflowId: string, options?: {
105
+ maxWait?: number;
106
+ pollInterval?: number;
107
+ onProgress?: (status: WorkflowStatus) => void;
108
+ }): Promise<WorkflowStatus>;
109
+ /**
110
+ * Submit work and wait for completion.
111
+ */
112
+ submitWorkAndWait(studioAddress: string, epoch: number, agentAddress: string, dataHash: string, threadRoot: string, evidenceRoot: string, evidenceContent: Buffer | string, signerAddress: string, options?: {
113
+ onProgress?: (status: WorkflowStatus) => void;
114
+ }): Promise<WorkflowStatus>;
115
+ /**
116
+ * Submit score and wait for completion.
117
+ */
118
+ submitScoreAndWait(studioAddress: string, epoch: number, validatorAddress: string, dataHash: string, scores: number[], signerAddress: string, options?: {
119
+ workerAddress?: string;
120
+ workAddress?: string;
121
+ salt?: string;
122
+ mode?: ScoreSubmissionMode;
123
+ onProgress?: (status: WorkflowStatus) => void;
124
+ }): Promise<WorkflowStatus>;
125
+ /**
126
+ * Close epoch and wait for completion.
127
+ */
128
+ closeEpochAndWait(studioAddress: string, epoch: number, signerAddress: string, options?: {
129
+ onProgress?: (status: WorkflowStatus) => void;
130
+ }): Promise<WorkflowStatus>;
131
+ /**
132
+ * Fetch pending (unfinalized) work for a studio from the gateway.
133
+ *
134
+ * @param studioAddress - 0x-prefixed studio contract address
135
+ * @param options - Optional limit/offset for pagination
136
+ * @returns Typed pending work response
137
+ */
138
+ getPendingWork(studioAddress: string, options?: {
139
+ limit?: number;
140
+ offset?: number;
141
+ }): Promise<PendingWorkResponse>;
142
+ /**
143
+ * Fetch full evidence graph for a work submission.
144
+ * Endpoint: GET /v1/work/{hash}/evidence
145
+ */
146
+ getWorkEvidence(workHash: string): Promise<WorkEvidenceResponse>;
147
+ }
148
+
149
+ /**
150
+ * Exception classes for the ChaosChain SDK.
151
+ *
152
+ * This module defines all custom exceptions used throughout the SDK
153
+ * to provide clear error handling and debugging information.
154
+ */
155
+ declare class ChaosChainSDKError extends Error {
156
+ details: Record<string, any>;
157
+ constructor(message: string, details?: Record<string, any>);
158
+ toString(): string;
159
+ }
160
+ declare class AgentRegistrationError extends ChaosChainSDKError {
161
+ constructor(message: string, details?: Record<string, any>);
162
+ }
163
+ declare class PaymentError extends ChaosChainSDKError {
164
+ constructor(message: string, details?: Record<string, any>);
165
+ }
166
+ declare class StorageError extends ChaosChainSDKError {
167
+ constructor(message: string, details?: Record<string, any>);
168
+ }
169
+ declare class IntegrityVerificationError extends ChaosChainSDKError {
170
+ constructor(message: string, details?: Record<string, any>);
171
+ }
172
+ declare class ContractError extends ChaosChainSDKError {
173
+ constructor(message: string, details?: Record<string, any>);
174
+ }
175
+ declare class ValidationError extends ChaosChainSDKError {
176
+ constructor(message: string, details?: Record<string, any>);
177
+ }
178
+ declare class ConfigurationError extends ChaosChainSDKError {
179
+ constructor(message: string, details?: Record<string, any>);
180
+ }
181
+ /**
182
+ * Options passed when constructing a GatewayError (statusCode, response, category, retryable).
183
+ */
184
+ interface GatewayErrorDetails {
185
+ statusCode?: number;
186
+ response?: Record<string, any>;
187
+ category?: 'transient' | 'permanent' | 'auth' | 'unknown';
188
+ retryable?: boolean;
189
+ }
190
+ /**
191
+ * Base error from Gateway API.
192
+ */
193
+ declare class GatewayError extends ChaosChainSDKError {
194
+ readonly statusCode?: number;
195
+ readonly response?: Record<string, any>;
196
+ readonly category?: 'transient' | 'permanent' | 'auth' | 'unknown';
197
+ readonly retryable?: boolean;
198
+ constructor(message: string, details?: GatewayErrorDetails);
199
+ }
200
+ /**
201
+ * Failed to connect to Gateway.
202
+ */
203
+ declare class GatewayConnectionError extends GatewayError {
204
+ constructor(message: string);
205
+ }
206
+ /**
207
+ * Gateway request or polling timed out.
208
+ */
209
+ declare class GatewayTimeoutError extends GatewayError {
210
+ readonly workflowId: string;
211
+ readonly lastStatus?: WorkflowStatus;
212
+ constructor(workflowId: string, message: string, lastStatus?: WorkflowStatus);
213
+ }
214
+ /**
215
+ * Workflow reached FAILED state.
216
+ */
217
+ declare class WorkflowFailedError extends GatewayError {
218
+ readonly workflowId: string;
219
+ readonly workflowError: WorkflowError;
220
+ constructor(workflowId: string, error: WorkflowError);
221
+ }
222
+
223
+ export { AgentRegistrationError as A, ChaosChainSDKError as C, GatewayClient as G, IntegrityVerificationError as I, PaymentError as P, StorageError as S, ValidationError as V, WorkflowFailedError as W, ContractError as a, ConfigurationError as b, GatewayError as c, GatewayConnectionError as d, GatewayTimeoutError as e };
@@ -0,0 +1,223 @@
1
+ import { G as GatewayClientConfig, $ as GatewayHealthResponse, g as WorkflowStatus, h as ScoreSubmissionMode, s as PendingWorkResponse, t as WorkEvidenceResponse, q as WorkflowError } from './types-C0Ay90UI.cjs';
2
+
3
+ declare class GatewayClient {
4
+ private gatewayUrl;
5
+ private timeout;
6
+ private maxPollTime;
7
+ private pollInterval;
8
+ private defaultHeaders?;
9
+ private auth?;
10
+ private retryConfig?;
11
+ constructor(config: GatewayClientConfig);
12
+ private _resolveTimeout;
13
+ private _resolveAuthMode;
14
+ private _buildHeaders;
15
+ private _classifyStatusCode;
16
+ private _normalizeError;
17
+ private _getRetryDelayMs;
18
+ private _sleep;
19
+ /**
20
+ * Make HTTP request to Gateway.
21
+ * Handles errors and transforms them to Gateway exceptions.
22
+ */
23
+ private _request;
24
+ /**
25
+ * Parse workflow status from API response.
26
+ */
27
+ private _parseWorkflowStatus;
28
+ healthCheck(): Promise<GatewayHealthResponse>;
29
+ isHealthy(): Promise<boolean>;
30
+ /**
31
+ * Create a work submission workflow.
32
+ * POST /workflows/work-submission
33
+ *
34
+ * SDK prepares inputs; Gateway handles:
35
+ * - Evidence upload to Arweave
36
+ * - Transaction submission
37
+ * - Confirmation waiting
38
+ *
39
+ * @param studioAddress - Ethereum address of the studio
40
+ * @param epoch - Epoch number
41
+ * @param agentAddress - Ethereum address of the submitting agent
42
+ * @param dataHash - Bytes32 hash of the work (as hex string)
43
+ * @param threadRoot - Bytes32 DKG thread root (as hex string)
44
+ * @param evidenceRoot - Bytes32 evidence Merkle root (as hex string)
45
+ * @param evidenceContent - Raw evidence bytes (will be base64 encoded)
46
+ * @param signerAddress - Ethereum address of the signer (must be registered in Gateway)
47
+ * @returns WorkflowStatus - Initial status of the created workflow
48
+ */
49
+ submitWork(studioAddress: string, epoch: number, agentAddress: string, dataHash: string, threadRoot: string, evidenceRoot: string, evidenceContent: Buffer | string, signerAddress: string): Promise<WorkflowStatus>;
50
+ /**
51
+ * Create a score submission workflow.
52
+ * POST /workflows/score-submission
53
+ *
54
+ * Supports two modes:
55
+ * - DIRECT (default): Simple direct scoring, requires workerAddress
56
+ * - COMMIT_REVEAL: Commit-reveal pattern, requires salt
57
+ *
58
+ * @param studioAddress - Ethereum address of the studio
59
+ * @param epoch - Epoch number
60
+ * @param validatorAddress - Ethereum address of the validator
61
+ * @param dataHash - Bytes32 hash of the work being scored (as hex string)
62
+ * @param scores - Array of dimension scores (0-10000 basis points)
63
+ * @param signerAddress - Ethereum address of the signer
64
+ * @param options - Additional options (workerAddress, salt, mode)
65
+ */
66
+ submitScore(studioAddress: string, epoch: number, validatorAddress: string, dataHash: string, scores: number[], signerAddress: string, options?: {
67
+ workerAddress?: string;
68
+ salt?: string;
69
+ mode?: ScoreSubmissionMode;
70
+ }): Promise<WorkflowStatus>;
71
+ /**
72
+ * Create a close epoch workflow.
73
+ * POST /workflows/close-epoch
74
+ *
75
+ * This is economically final — cannot be undone.
76
+ *
77
+ * @param studioAddress - Ethereum address of the studio
78
+ * @param epoch - Epoch number to close
79
+ * @param signerAddress - Ethereum address of the signer
80
+ */
81
+ closeEpoch(studioAddress: string, epoch: number, signerAddress: string): Promise<WorkflowStatus>;
82
+ /**
83
+ * Get workflow status by ID.
84
+ * GET /workflows/{id}
85
+ */
86
+ getWorkflow(workflowId: string): Promise<WorkflowStatus>;
87
+ /**
88
+ * List workflows with optional filters.
89
+ * GET /workflows?studio=&state=&type=
90
+ */
91
+ listWorkflows(options?: {
92
+ studio?: string;
93
+ state?: string;
94
+ workflowType?: string;
95
+ }): Promise<WorkflowStatus[]>;
96
+ /**
97
+ * Poll workflow until it reaches a terminal state.
98
+ *
99
+ * @param workflowId - UUID of the workflow
100
+ * @param options - Polling options
101
+ * @throws WorkflowFailedError - If workflow reaches FAILED state
102
+ * @throws GatewayTimeoutError - If maxWait exceeded
103
+ */
104
+ waitForCompletion(workflowId: string, options?: {
105
+ maxWait?: number;
106
+ pollInterval?: number;
107
+ onProgress?: (status: WorkflowStatus) => void;
108
+ }): Promise<WorkflowStatus>;
109
+ /**
110
+ * Submit work and wait for completion.
111
+ */
112
+ submitWorkAndWait(studioAddress: string, epoch: number, agentAddress: string, dataHash: string, threadRoot: string, evidenceRoot: string, evidenceContent: Buffer | string, signerAddress: string, options?: {
113
+ onProgress?: (status: WorkflowStatus) => void;
114
+ }): Promise<WorkflowStatus>;
115
+ /**
116
+ * Submit score and wait for completion.
117
+ */
118
+ submitScoreAndWait(studioAddress: string, epoch: number, validatorAddress: string, dataHash: string, scores: number[], signerAddress: string, options?: {
119
+ workerAddress?: string;
120
+ workAddress?: string;
121
+ salt?: string;
122
+ mode?: ScoreSubmissionMode;
123
+ onProgress?: (status: WorkflowStatus) => void;
124
+ }): Promise<WorkflowStatus>;
125
+ /**
126
+ * Close epoch and wait for completion.
127
+ */
128
+ closeEpochAndWait(studioAddress: string, epoch: number, signerAddress: string, options?: {
129
+ onProgress?: (status: WorkflowStatus) => void;
130
+ }): Promise<WorkflowStatus>;
131
+ /**
132
+ * Fetch pending (unfinalized) work for a studio from the gateway.
133
+ *
134
+ * @param studioAddress - 0x-prefixed studio contract address
135
+ * @param options - Optional limit/offset for pagination
136
+ * @returns Typed pending work response
137
+ */
138
+ getPendingWork(studioAddress: string, options?: {
139
+ limit?: number;
140
+ offset?: number;
141
+ }): Promise<PendingWorkResponse>;
142
+ /**
143
+ * Fetch full evidence graph for a work submission.
144
+ * Endpoint: GET /v1/work/{hash}/evidence
145
+ */
146
+ getWorkEvidence(workHash: string): Promise<WorkEvidenceResponse>;
147
+ }
148
+
149
+ /**
150
+ * Exception classes for the ChaosChain SDK.
151
+ *
152
+ * This module defines all custom exceptions used throughout the SDK
153
+ * to provide clear error handling and debugging information.
154
+ */
155
+ declare class ChaosChainSDKError extends Error {
156
+ details: Record<string, any>;
157
+ constructor(message: string, details?: Record<string, any>);
158
+ toString(): string;
159
+ }
160
+ declare class AgentRegistrationError extends ChaosChainSDKError {
161
+ constructor(message: string, details?: Record<string, any>);
162
+ }
163
+ declare class PaymentError extends ChaosChainSDKError {
164
+ constructor(message: string, details?: Record<string, any>);
165
+ }
166
+ declare class StorageError extends ChaosChainSDKError {
167
+ constructor(message: string, details?: Record<string, any>);
168
+ }
169
+ declare class IntegrityVerificationError extends ChaosChainSDKError {
170
+ constructor(message: string, details?: Record<string, any>);
171
+ }
172
+ declare class ContractError extends ChaosChainSDKError {
173
+ constructor(message: string, details?: Record<string, any>);
174
+ }
175
+ declare class ValidationError extends ChaosChainSDKError {
176
+ constructor(message: string, details?: Record<string, any>);
177
+ }
178
+ declare class ConfigurationError extends ChaosChainSDKError {
179
+ constructor(message: string, details?: Record<string, any>);
180
+ }
181
+ /**
182
+ * Options passed when constructing a GatewayError (statusCode, response, category, retryable).
183
+ */
184
+ interface GatewayErrorDetails {
185
+ statusCode?: number;
186
+ response?: Record<string, any>;
187
+ category?: 'transient' | 'permanent' | 'auth' | 'unknown';
188
+ retryable?: boolean;
189
+ }
190
+ /**
191
+ * Base error from Gateway API.
192
+ */
193
+ declare class GatewayError extends ChaosChainSDKError {
194
+ readonly statusCode?: number;
195
+ readonly response?: Record<string, any>;
196
+ readonly category?: 'transient' | 'permanent' | 'auth' | 'unknown';
197
+ readonly retryable?: boolean;
198
+ constructor(message: string, details?: GatewayErrorDetails);
199
+ }
200
+ /**
201
+ * Failed to connect to Gateway.
202
+ */
203
+ declare class GatewayConnectionError extends GatewayError {
204
+ constructor(message: string);
205
+ }
206
+ /**
207
+ * Gateway request or polling timed out.
208
+ */
209
+ declare class GatewayTimeoutError extends GatewayError {
210
+ readonly workflowId: string;
211
+ readonly lastStatus?: WorkflowStatus;
212
+ constructor(workflowId: string, message: string, lastStatus?: WorkflowStatus);
213
+ }
214
+ /**
215
+ * Workflow reached FAILED state.
216
+ */
217
+ declare class WorkflowFailedError extends GatewayError {
218
+ readonly workflowId: string;
219
+ readonly workflowError: WorkflowError;
220
+ constructor(workflowId: string, error: WorkflowError);
221
+ }
222
+
223
+ export { AgentRegistrationError as A, ChaosChainSDKError as C, GatewayClient as G, IntegrityVerificationError as I, PaymentError as P, StorageError as S, ValidationError as V, WorkflowFailedError as W, ContractError as a, ConfigurationError as b, GatewayError as c, GatewayConnectionError as d, GatewayTimeoutError as e };
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.2";
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.2";
16984
16987
  var ERC8004_VERSION = "1.0";
16985
16988
  var X402_VERSION = "1.0";
16986
16989
  var src_default = ChaosChainSDK;