@chaoschain/sdk 0.3.1 → 0.3.3
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 +22 -0
- package/README.md +50 -1
- 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 +40 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -393
- package/dist/index.d.ts +9 -393
- package/dist/index.js +40 -14
- 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 +222 -0
- package/dist/session/index.cjs.map +1 -0
- package/dist/session/index.d.cts +193 -0
- package/dist/session/index.d.ts +193 -0
- package/dist/session/index.js +215 -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
|
@@ -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
|
@@ -15403,10 +15403,16 @@ var STEP_TYPE_MAP = {
|
|
|
15403
15403
|
var Session = class {
|
|
15404
15404
|
/** Session ID returned by the gateway. */
|
|
15405
15405
|
sessionId;
|
|
15406
|
-
|
|
15407
|
-
|
|
15406
|
+
/** Epoch number returned by the gateway. */
|
|
15407
|
+
epoch;
|
|
15408
|
+
/** Studio contract address for this session. */
|
|
15408
15409
|
studioAddress;
|
|
15410
|
+
/** Default agent wallet address for this session. */
|
|
15409
15411
|
agentAddress;
|
|
15412
|
+
/** URL to view this session's Evidence DAG in the browser. */
|
|
15413
|
+
viewerUrl;
|
|
15414
|
+
gatewayUrl;
|
|
15415
|
+
apiKey;
|
|
15410
15416
|
studioPolicyVersion;
|
|
15411
15417
|
workMandateId;
|
|
15412
15418
|
taskType;
|
|
@@ -15414,6 +15420,8 @@ var Session = class {
|
|
|
15414
15420
|
/** @internal — use {@link SessionClient.start} to create instances. */
|
|
15415
15421
|
constructor(opts) {
|
|
15416
15422
|
this.sessionId = opts.sessionId;
|
|
15423
|
+
this.epoch = opts.epoch;
|
|
15424
|
+
this.viewerUrl = `${opts.gatewayUrl}/v1/sessions/${opts.sessionId}/viewer`;
|
|
15417
15425
|
this.gatewayUrl = opts.gatewayUrl;
|
|
15418
15426
|
this.apiKey = opts.apiKey;
|
|
15419
15427
|
this.lastEventId = opts.lastEventId ?? null;
|
|
@@ -15429,7 +15437,12 @@ var Session = class {
|
|
|
15429
15437
|
* Automatically generates `event_id`, `timestamp`, and chains `parent_event_ids`
|
|
15430
15438
|
* from the previous event so the gateway can build a causal DAG.
|
|
15431
15439
|
*
|
|
15432
|
-
* @param opts -
|
|
15440
|
+
* @param opts.summary - Human-readable description of what happened (required).
|
|
15441
|
+
* @param opts.event_type - Canonical event type (default: `"artifact_created"`).
|
|
15442
|
+
* @param opts.metadata - Arbitrary key-value metadata attached to the event.
|
|
15443
|
+
* @param opts.agent - Override the session-level agent for this event.
|
|
15444
|
+
* Pass `{ agent_address, role? }` to emit the event from a different agent.
|
|
15445
|
+
* Valid roles: `"worker"`, `"verifier"`, `"collaborator"`. Defaults to `"worker"`.
|
|
15433
15446
|
* @throws Error if the gateway returns a non-2xx status.
|
|
15434
15447
|
*/
|
|
15435
15448
|
async log(opts) {
|
|
@@ -15472,8 +15485,9 @@ var Session = class {
|
|
|
15472
15485
|
*
|
|
15473
15486
|
* Unknown step types fall back to `artifact_created`.
|
|
15474
15487
|
*
|
|
15475
|
-
* @param stepType - Friendly step name.
|
|
15488
|
+
* @param stepType - Friendly step name (`"planning"`, `"implementing"`, `"testing"`, `"debugging"`, `"completing"`).
|
|
15476
15489
|
* @param summary - What happened in this step.
|
|
15490
|
+
* @param agent - Optional agent override for this event. Same as `log({ agent })`.
|
|
15477
15491
|
*/
|
|
15478
15492
|
async step(stepType, summary, agent) {
|
|
15479
15493
|
const eventType = STEP_TYPE_MAP[stepType] ?? "artifact_created";
|
|
@@ -15483,11 +15497,13 @@ var Session = class {
|
|
|
15483
15497
|
* Complete the session.
|
|
15484
15498
|
*
|
|
15485
15499
|
* Triggers the on-chain WorkSubmission workflow (if the gateway is configured for it)
|
|
15486
|
-
* and returns
|
|
15500
|
+
* and returns the session result.
|
|
15487
15501
|
*
|
|
15488
|
-
* @param opts -
|
|
15489
|
-
* @
|
|
15490
|
-
*
|
|
15502
|
+
* @param opts.status - `"completed"` or `"failed"` (default: `"completed"`).
|
|
15503
|
+
* @param opts.summary - Human-readable summary of the session outcome.
|
|
15504
|
+
* @returns `{ workflow_id, data_hash, epoch }` — `workflow_id` and `data_hash`
|
|
15505
|
+
* may be `null` if the gateway workflow engine is not configured.
|
|
15506
|
+
* `epoch` is the epoch this session belongs to.
|
|
15491
15507
|
* @throws Error if the gateway returns a non-2xx status.
|
|
15492
15508
|
*/
|
|
15493
15509
|
async complete(opts) {
|
|
@@ -15497,7 +15513,8 @@ var Session = class {
|
|
|
15497
15513
|
const data = await this.post(`/v1/sessions/${this.sessionId}/complete`, body);
|
|
15498
15514
|
return {
|
|
15499
15515
|
workflow_id: data.data?.workflow_id ?? null,
|
|
15500
|
-
data_hash: data.data?.data_hash ?? null
|
|
15516
|
+
data_hash: data.data?.data_hash ?? null,
|
|
15517
|
+
epoch: data.data.epoch
|
|
15501
15518
|
};
|
|
15502
15519
|
}
|
|
15503
15520
|
// ---------------------------------------------------------------------------
|
|
@@ -15534,8 +15551,16 @@ var SessionClient = class {
|
|
|
15534
15551
|
* and complete the session. The gateway persists all events and constructs the
|
|
15535
15552
|
* Evidence DAG automatically.
|
|
15536
15553
|
*
|
|
15537
|
-
*
|
|
15538
|
-
*
|
|
15554
|
+
* The returned session exposes `session.sessionId`, `session.epoch`,
|
|
15555
|
+
* `session.studioAddress`, and `session.agentAddress`.
|
|
15556
|
+
*
|
|
15557
|
+
* @param opts.studio_address - Studio contract address (required).
|
|
15558
|
+
* @param opts.agent_address - Worker agent wallet address (required).
|
|
15559
|
+
* @param opts.task_type - Task classification: `"feature"`, `"bugfix"`, `"refactor"`, etc. (default: `"general"`).
|
|
15560
|
+
* @param opts.work_mandate_id - Work mandate identifier (default: `"generic-task"`).
|
|
15561
|
+
* @param opts.studio_policy_version - Studio policy version (default: `"engineering-studio-default-v1"`).
|
|
15562
|
+
* @param opts.session_id - Client-provided session ID. Server generates one if omitted.
|
|
15563
|
+
* @returns A live {@link Session} bound to the newly created session ID and epoch.
|
|
15539
15564
|
* @throws Error if the gateway returns a non-2xx status.
|
|
15540
15565
|
*/
|
|
15541
15566
|
async start(opts) {
|
|
@@ -15572,7 +15597,8 @@ var SessionClient = class {
|
|
|
15572
15597
|
agentAddress: opts.agent_address,
|
|
15573
15598
|
studioPolicyVersion: opts.studio_policy_version ?? "engineering-studio-default-v1",
|
|
15574
15599
|
workMandateId: opts.work_mandate_id ?? "generic-task",
|
|
15575
|
-
taskType: opts.task_type ?? "general"
|
|
15600
|
+
taskType: opts.task_type ?? "general",
|
|
15601
|
+
epoch: data.data.epoch
|
|
15576
15602
|
});
|
|
15577
15603
|
}
|
|
15578
15604
|
};
|
|
@@ -16185,7 +16211,7 @@ var ChaosChainSDK = class _ChaosChainSDK {
|
|
|
16185
16211
|
* Get SDK version
|
|
16186
16212
|
*/
|
|
16187
16213
|
getVersion() {
|
|
16188
|
-
return "0.3.
|
|
16214
|
+
return "0.3.3";
|
|
16189
16215
|
}
|
|
16190
16216
|
/**
|
|
16191
16217
|
* Get SDK capabilities summary
|
|
@@ -16983,7 +17009,7 @@ function verifyWorkEvidence(evidence, context) {
|
|
|
16983
17009
|
}
|
|
16984
17010
|
|
|
16985
17011
|
// src/index.ts
|
|
16986
|
-
var SDK_VERSION = "0.3.
|
|
17012
|
+
var SDK_VERSION = "0.3.3";
|
|
16987
17013
|
var ERC8004_VERSION = "1.0";
|
|
16988
17014
|
var X402_VERSION = "1.0";
|
|
16989
17015
|
var src_default = ChaosChainSDK;
|