scientific-protocol 0.1.0
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/LICENSE +21 -0
- package/README.md +138 -0
- package/dist/generated/contracts.d.ts +31442 -0
- package/dist/generated/contracts.js +10623 -0
- package/dist/sdk/client.d.ts +376 -0
- package/dist/sdk/client.js +427 -0
- package/dist/sdk/index.d.ts +8 -0
- package/dist/sdk/index.js +7 -0
- package/dist/sdk/rewards.d.ts +42 -0
- package/dist/sdk/rewards.js +84 -0
- package/dist/sdk/types.d.ts +300 -0
- package/dist/sdk/types.js +1 -0
- package/dist/shared/agent-request-envelope.d.ts +40 -0
- package/dist/shared/agent-request-envelope.js +51 -0
- package/dist/shared/artifact-storage-attestations.d.ts +64 -0
- package/dist/shared/artifact-storage-attestations.js +104 -0
- package/dist/shared/artifact-storage-bundles.d.ts +44 -0
- package/dist/shared/artifact-storage-bundles.js +124 -0
- package/dist/shared/artifact-storage-policy.d.ts +38 -0
- package/dist/shared/artifact-storage-policy.js +47 -0
- package/dist/shared/contracts.d.ts +30 -0
- package/dist/shared/contracts.js +46 -0
- package/dist/shared/deployment.d.ts +52 -0
- package/dist/shared/deployment.js +156 -0
- package/dist/shared/secrets.d.ts +6 -0
- package/dist/shared/secrets.js +30 -0
- package/dist/shared/sha256.d.ts +2 -0
- package/dist/shared/sha256.js +4 -0
- package/package.json +103 -0
- package/schemas/artifact-storage-attestation.schema.json +116 -0
- package/schemas/artifact-storage-bundle.schema.json +107 -0
- package/schemas/claim.schema.json +83 -0
- package/schemas/evaluation.schema.json +96 -0
- package/schemas/replication.schema.json +103 -0
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
export class ScientificProtocolApiError extends Error {
|
|
2
|
+
body;
|
|
3
|
+
response;
|
|
4
|
+
status;
|
|
5
|
+
constructor(response, body) {
|
|
6
|
+
super(`Scientific Protocol API request failed with status ${response.status}`);
|
|
7
|
+
this.name = "ScientificProtocolApiError";
|
|
8
|
+
this.status = response.status;
|
|
9
|
+
this.response = response;
|
|
10
|
+
this.body = body;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function trimTrailingSlash(input) {
|
|
14
|
+
return input.endsWith("/") ? input.slice(0, -1) : input;
|
|
15
|
+
}
|
|
16
|
+
function parseWorkItemId(itemId) {
|
|
17
|
+
const separator = itemId.indexOf(":");
|
|
18
|
+
if (separator <= 0 || separator === itemId.length - 1) {
|
|
19
|
+
throw new Error(`unsupported_work_item_id:${itemId}`);
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
itemKey: itemId.slice(0, separator),
|
|
23
|
+
sourceId: itemId.slice(separator + 1),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function toSearchParams(query) {
|
|
27
|
+
if (!query) {
|
|
28
|
+
return "";
|
|
29
|
+
}
|
|
30
|
+
const params = new URLSearchParams();
|
|
31
|
+
for (const [key, value] of Object.entries(query)) {
|
|
32
|
+
if (value === undefined) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
params.set(key, String(value));
|
|
36
|
+
}
|
|
37
|
+
const serialized = params.toString();
|
|
38
|
+
return serialized ? `?${serialized}` : "";
|
|
39
|
+
}
|
|
40
|
+
async function parseResponseBody(response) {
|
|
41
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
42
|
+
if (contentType.includes("application/json")) {
|
|
43
|
+
return response.json();
|
|
44
|
+
}
|
|
45
|
+
const text = await response.text();
|
|
46
|
+
return text.length > 0 ? text : null;
|
|
47
|
+
}
|
|
48
|
+
export class ScientificProtocolClient {
|
|
49
|
+
baseUrl;
|
|
50
|
+
demoAdminToken;
|
|
51
|
+
defaultHeaders;
|
|
52
|
+
fetchImpl;
|
|
53
|
+
constructor(options) {
|
|
54
|
+
this.baseUrl = trimTrailingSlash(String(options.baseUrl));
|
|
55
|
+
this.demoAdminToken = options.demoAdminToken;
|
|
56
|
+
this.defaultHeaders = options.headers;
|
|
57
|
+
this.fetchImpl = options.fetch ?? fetch;
|
|
58
|
+
}
|
|
59
|
+
demo = {
|
|
60
|
+
createClaim: (input) => this.request("/demo/claims", {
|
|
61
|
+
body: input,
|
|
62
|
+
method: "POST",
|
|
63
|
+
}),
|
|
64
|
+
enqueueArtifactAudits: (input = {}) => this.request("/demo/artifact-maintenance-tasks/enqueue-audits", {
|
|
65
|
+
body: input,
|
|
66
|
+
method: "POST",
|
|
67
|
+
}),
|
|
68
|
+
getAdminStatus: () => this.request("/demo/admin/status", {
|
|
69
|
+
admin: true,
|
|
70
|
+
}),
|
|
71
|
+
getScenarios: () => this.request("/demo/scenarios"),
|
|
72
|
+
openReplicationJob: (input) => this.request("/demo/replication-jobs", {
|
|
73
|
+
body: input,
|
|
74
|
+
method: "POST",
|
|
75
|
+
}),
|
|
76
|
+
openArtifactMaintenanceTask: (input) => this.request("/demo/artifact-maintenance-tasks", {
|
|
77
|
+
body: input,
|
|
78
|
+
method: "POST",
|
|
79
|
+
}),
|
|
80
|
+
processReplicationJob: (jobId, input = {}) => this.request(`/demo/replication-jobs/${jobId}/process`, {
|
|
81
|
+
body: input,
|
|
82
|
+
method: "POST",
|
|
83
|
+
}),
|
|
84
|
+
recomputeDomain: (domainId) => this.request(`/demo/domains/${domainId}/recompute`, {
|
|
85
|
+
body: {},
|
|
86
|
+
method: "POST",
|
|
87
|
+
}),
|
|
88
|
+
reseedOperational: () => this.request("/demo/admin/reseed-operational", {
|
|
89
|
+
admin: true,
|
|
90
|
+
body: {},
|
|
91
|
+
method: "POST",
|
|
92
|
+
}),
|
|
93
|
+
resetDemo: () => this.request("/demo/admin/reset-demo", {
|
|
94
|
+
admin: true,
|
|
95
|
+
body: {},
|
|
96
|
+
method: "POST",
|
|
97
|
+
}),
|
|
98
|
+
resolveReplicationJob: (jobId, input = {}) => this.request(`/demo/replication-jobs/${jobId}/resolve`, {
|
|
99
|
+
body: input,
|
|
100
|
+
method: "POST",
|
|
101
|
+
}),
|
|
102
|
+
};
|
|
103
|
+
production = {
|
|
104
|
+
createClaim: (signedRequest) => this.request("/claims", {
|
|
105
|
+
body: signedRequest,
|
|
106
|
+
method: "POST",
|
|
107
|
+
}),
|
|
108
|
+
createSource: (signedRequest) => this.request("/sources", {
|
|
109
|
+
body: signedRequest,
|
|
110
|
+
method: "POST",
|
|
111
|
+
}),
|
|
112
|
+
createClaimDraftFromArtifact: (signedRequest) => this.request("/claim-drafts/from-artifact", {
|
|
113
|
+
body: signedRequest,
|
|
114
|
+
method: "POST",
|
|
115
|
+
}),
|
|
116
|
+
confirmSourcePublication: (sourceId, signedRequest) => this.request(`/sources/${sourceId}/confirm`, {
|
|
117
|
+
body: signedRequest,
|
|
118
|
+
method: "POST",
|
|
119
|
+
}),
|
|
120
|
+
openReplicationJob: (claimId, signedRequest) => this.request(`/claims/${claimId}/replication-jobs`, {
|
|
121
|
+
body: signedRequest,
|
|
122
|
+
method: "POST",
|
|
123
|
+
}),
|
|
124
|
+
rejectSourcePublication: (sourceId, signedRequest) => this.request(`/sources/${sourceId}/reject`, {
|
|
125
|
+
body: signedRequest,
|
|
126
|
+
method: "POST",
|
|
127
|
+
}),
|
|
128
|
+
processReplicationJob: (jobId, signedRequest) => this.request(`/replication-jobs/${jobId}/process`, {
|
|
129
|
+
body: signedRequest,
|
|
130
|
+
method: "POST",
|
|
131
|
+
}),
|
|
132
|
+
recomputeDomain: (domainId, signedRequest) => this.request(`/domains/${domainId}/recompute`, {
|
|
133
|
+
body: signedRequest,
|
|
134
|
+
method: "POST",
|
|
135
|
+
}),
|
|
136
|
+
resolveReplicationJob: (jobId, signedRequest) => this.request(`/replication-jobs/${jobId}/resolve`, {
|
|
137
|
+
body: signedRequest,
|
|
138
|
+
method: "POST",
|
|
139
|
+
}),
|
|
140
|
+
};
|
|
141
|
+
agent = {
|
|
142
|
+
claimArtifactMaintenanceTask: (taskId, signedRequest) => this.request(`/agent/artifact-maintenance-tasks/${taskId}/claim`, {
|
|
143
|
+
body: signedRequest,
|
|
144
|
+
method: "POST",
|
|
145
|
+
}),
|
|
146
|
+
heartbeatArtifactMaintenanceTask: (taskId, signedRequest) => this.request(`/agent/artifact-maintenance-tasks/${taskId}/heartbeat`, {
|
|
147
|
+
body: signedRequest,
|
|
148
|
+
method: "POST",
|
|
149
|
+
}),
|
|
150
|
+
submitArtifactAuditResults: (taskId, signedRequest) => this.request(`/agent/artifact-maintenance-tasks/${taskId}/audit-results`, {
|
|
151
|
+
body: signedRequest,
|
|
152
|
+
method: "POST",
|
|
153
|
+
}),
|
|
154
|
+
submitArtifactRepairResults: (taskId, signedRequest) => this.request(`/agent/artifact-maintenance-tasks/${taskId}/repair-results`, {
|
|
155
|
+
body: signedRequest,
|
|
156
|
+
method: "POST",
|
|
157
|
+
}),
|
|
158
|
+
claimReplicationJob: (jobId, signedRequest) => this.request(`/agent/replication-jobs/${jobId}/claim`, {
|
|
159
|
+
body: signedRequest,
|
|
160
|
+
method: "POST",
|
|
161
|
+
}),
|
|
162
|
+
heartbeatReplicationJob: (jobId, signedRequest) => this.request(`/agent/replication-jobs/${jobId}/heartbeat`, {
|
|
163
|
+
body: signedRequest,
|
|
164
|
+
method: "POST",
|
|
165
|
+
}),
|
|
166
|
+
submitReplicationResults: (jobId, signedRequest) => this.request(`/agent/replication-jobs/${jobId}/submissions`, {
|
|
167
|
+
body: signedRequest,
|
|
168
|
+
method: "POST",
|
|
169
|
+
}),
|
|
170
|
+
claimReviewTask: (taskId, signedRequest) => this.request(`/agent/review-tasks/${taskId}/claim`, {
|
|
171
|
+
body: signedRequest,
|
|
172
|
+
method: "POST",
|
|
173
|
+
}),
|
|
174
|
+
heartbeatReviewTask: (taskId, signedRequest) => this.request(`/agent/review-tasks/${taskId}/heartbeat`, {
|
|
175
|
+
body: signedRequest,
|
|
176
|
+
method: "POST",
|
|
177
|
+
}),
|
|
178
|
+
submitReviewResults: (taskId, signedRequest) => this.request(`/agent/review-tasks/${taskId}/submissions`, {
|
|
179
|
+
body: signedRequest,
|
|
180
|
+
method: "POST",
|
|
181
|
+
}),
|
|
182
|
+
submitSource: (signedRequest) => this.request("/agent/sources", {
|
|
183
|
+
body: signedRequest,
|
|
184
|
+
method: "POST",
|
|
185
|
+
}),
|
|
186
|
+
claimWorkItem: (itemId, signedRequest) => {
|
|
187
|
+
const parsed = parseWorkItemId(itemId);
|
|
188
|
+
if (parsed.itemKey === "review-task") {
|
|
189
|
+
return this.agent.claimReviewTask(parsed.sourceId, signedRequest);
|
|
190
|
+
}
|
|
191
|
+
if (parsed.itemKey === "artifact-maintenance") {
|
|
192
|
+
return this.agent.claimArtifactMaintenanceTask(parsed.sourceId, signedRequest);
|
|
193
|
+
}
|
|
194
|
+
if (parsed.itemKey === "replication-job") {
|
|
195
|
+
return this.agent.claimReplicationJob(parsed.sourceId, signedRequest);
|
|
196
|
+
}
|
|
197
|
+
throw new Error(`unsupported_claimable_work_item:${itemId}`);
|
|
198
|
+
},
|
|
199
|
+
heartbeatWorkItem: (itemId, signedRequest) => {
|
|
200
|
+
const parsed = parseWorkItemId(itemId);
|
|
201
|
+
if (parsed.itemKey === "review-task") {
|
|
202
|
+
return this.agent.heartbeatReviewTask(parsed.sourceId, signedRequest);
|
|
203
|
+
}
|
|
204
|
+
if (parsed.itemKey === "artifact-maintenance") {
|
|
205
|
+
return this.agent.heartbeatArtifactMaintenanceTask(parsed.sourceId, signedRequest);
|
|
206
|
+
}
|
|
207
|
+
if (parsed.itemKey === "replication-job") {
|
|
208
|
+
return this.agent.heartbeatReplicationJob(parsed.sourceId, signedRequest);
|
|
209
|
+
}
|
|
210
|
+
throw new Error(`unsupported_heartbeatable_work_item:${itemId}`);
|
|
211
|
+
},
|
|
212
|
+
submitWorkResults: (itemId, signedRequest) => {
|
|
213
|
+
const parsed = parseWorkItemId(itemId);
|
|
214
|
+
if (parsed.itemKey === "review-task") {
|
|
215
|
+
return this.agent.submitReviewResults(parsed.sourceId, signedRequest);
|
|
216
|
+
}
|
|
217
|
+
if (parsed.itemKey === "artifact-maintenance") {
|
|
218
|
+
if (signedRequest.envelope.actionType === "artifact_task_audit_submission") {
|
|
219
|
+
return this.agent.submitArtifactAuditResults(parsed.sourceId, signedRequest);
|
|
220
|
+
}
|
|
221
|
+
if (signedRequest.envelope.actionType === "artifact_task_repair_submission") {
|
|
222
|
+
return this.agent.submitArtifactRepairResults(parsed.sourceId, signedRequest);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
if (parsed.itemKey === "replication-job") {
|
|
226
|
+
if (signedRequest.envelope.actionType === "replication_job_submission") {
|
|
227
|
+
return this.agent.submitReplicationResults(parsed.sourceId, signedRequest);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
throw new Error(`unsupported_work_result_submission:${itemId}:${signedRequest.envelope.actionType}`);
|
|
231
|
+
},
|
|
232
|
+
createWebhookSubscription: (signedRequest) => this.request("/agent/webhook-subscriptions", {
|
|
233
|
+
body: signedRequest,
|
|
234
|
+
method: "POST",
|
|
235
|
+
}),
|
|
236
|
+
deleteWebhookSubscription: (subscriptionId, signedRequest) => this.request(`/agent/webhook-subscriptions/${subscriptionId}/delete`, {
|
|
237
|
+
body: signedRequest,
|
|
238
|
+
method: "POST",
|
|
239
|
+
}),
|
|
240
|
+
pingWebhookSubscription: (subscriptionId, signedRequest) => this.request(`/agent/webhook-subscriptions/${subscriptionId}/ping`, {
|
|
241
|
+
body: signedRequest,
|
|
242
|
+
method: "POST",
|
|
243
|
+
}),
|
|
244
|
+
};
|
|
245
|
+
async getAdminStatus() {
|
|
246
|
+
return this.request("/admin/status");
|
|
247
|
+
}
|
|
248
|
+
async getGovernance() {
|
|
249
|
+
return this.request("/governance");
|
|
250
|
+
}
|
|
251
|
+
async listGovernanceEvents(query) {
|
|
252
|
+
return this.request(`/governance/events${toSearchParams(query)}`);
|
|
253
|
+
}
|
|
254
|
+
async getGovernanceTreasury(query) {
|
|
255
|
+
return this.request(`/governance/treasury${toSearchParams(query)}`);
|
|
256
|
+
}
|
|
257
|
+
async getGovernanceProposal(proposalId, query) {
|
|
258
|
+
return this.request(`/governance/proposals/${proposalId}${toSearchParams(query)}`);
|
|
259
|
+
}
|
|
260
|
+
async listGovernanceProposals(query) {
|
|
261
|
+
return this.request(`/governance/proposals${toSearchParams(query)}`);
|
|
262
|
+
}
|
|
263
|
+
async getAgentRequest(requestId) {
|
|
264
|
+
return this.request(`/agent-requests/${requestId}`);
|
|
265
|
+
}
|
|
266
|
+
async getAgentReviewCalibration(agentId, query) {
|
|
267
|
+
return this.request(`/agents/${agentId}/review-calibration${toSearchParams(query)}`);
|
|
268
|
+
}
|
|
269
|
+
async getAgentWorkSummary(agentId, query) {
|
|
270
|
+
return this.request(`/agents/${agentId}/work-summary${toSearchParams(query)}`);
|
|
271
|
+
}
|
|
272
|
+
async getAgentRewards(agentId, query) {
|
|
273
|
+
return this.request(`/agents/${agentId}/rewards${toSearchParams(query)}`);
|
|
274
|
+
}
|
|
275
|
+
async getRewardSettlements(query) {
|
|
276
|
+
return this.request(`/reward-settlements${toSearchParams(query)}`);
|
|
277
|
+
}
|
|
278
|
+
async getRecipientRewards(recipient, query) {
|
|
279
|
+
return this.request(`/recipients/${recipient}/rewards${toSearchParams(query)}`);
|
|
280
|
+
}
|
|
281
|
+
async getRewardConfig() {
|
|
282
|
+
return this.request("/reward-config");
|
|
283
|
+
}
|
|
284
|
+
async getWriteConfig() {
|
|
285
|
+
return this.request("/write-config");
|
|
286
|
+
}
|
|
287
|
+
async getAgentRuntimeEvents(query) {
|
|
288
|
+
return this.request(`/agent-runtime/events${toSearchParams(query)}`);
|
|
289
|
+
}
|
|
290
|
+
async getAgentWebhookSubscription(subscriptionId) {
|
|
291
|
+
return this.request(`/agent-webhook-subscriptions/${subscriptionId}`);
|
|
292
|
+
}
|
|
293
|
+
async getAgentWebhookDelivery(deliveryId) {
|
|
294
|
+
return this.request(`/agent-webhook-deliveries/${deliveryId}`);
|
|
295
|
+
}
|
|
296
|
+
async getAgentWebhookSubscriptions(query) {
|
|
297
|
+
return this.request(`/agent-webhook-subscriptions${toSearchParams(query)}`);
|
|
298
|
+
}
|
|
299
|
+
async getAgentWebhookDeliveries(query) {
|
|
300
|
+
return this.request(`/agent-webhook-deliveries${toSearchParams(query)}`);
|
|
301
|
+
}
|
|
302
|
+
async getArtifactMaintenanceTask(taskId) {
|
|
303
|
+
return this.request(`/artifact-maintenance-tasks/${taskId}`);
|
|
304
|
+
}
|
|
305
|
+
async getCheckpointPublications(query) {
|
|
306
|
+
return this.request(`/checkpoint-publications${toSearchParams(query)}`);
|
|
307
|
+
}
|
|
308
|
+
async getClaim(claimId, options) {
|
|
309
|
+
return this.request(`/claims/${claimId}${toSearchParams({ view: options?.view })}`);
|
|
310
|
+
}
|
|
311
|
+
async getClaimReview(claimId) {
|
|
312
|
+
return this.request(`/claims/${claimId}/review`);
|
|
313
|
+
}
|
|
314
|
+
async getClaimRewards(claimId, query) {
|
|
315
|
+
return this.request(`/claims/${claimId}/rewards${toSearchParams(query)}`);
|
|
316
|
+
}
|
|
317
|
+
async getClaimWorkGraph(claimId) {
|
|
318
|
+
return this.request(`/claims/${claimId}/work-graph`);
|
|
319
|
+
}
|
|
320
|
+
async getWorkItem(itemId, query) {
|
|
321
|
+
return this.request(`/work-items/${encodeURIComponent(itemId)}${toSearchParams(query)}`);
|
|
322
|
+
}
|
|
323
|
+
async getDomainLeaderboard(domainId, query) {
|
|
324
|
+
return this.request(`/domains/${domainId}/leaderboard${toSearchParams(query)}`);
|
|
325
|
+
}
|
|
326
|
+
async getHealth() {
|
|
327
|
+
return this.request("/health");
|
|
328
|
+
}
|
|
329
|
+
async getReviewTask(taskId) {
|
|
330
|
+
return this.request(`/review-tasks/${taskId}`);
|
|
331
|
+
}
|
|
332
|
+
async getSource(sourceId) {
|
|
333
|
+
return this.request(`/sources/${sourceId}`);
|
|
334
|
+
}
|
|
335
|
+
async getSourcePublicationDecisions(sourceId, query) {
|
|
336
|
+
return this.request(`/sources/${sourceId}/publication-decisions${toSearchParams(query)}`);
|
|
337
|
+
}
|
|
338
|
+
async getSourceWorkGraph(sourceId) {
|
|
339
|
+
return this.request(`/sources/${sourceId}/work-graph`);
|
|
340
|
+
}
|
|
341
|
+
async listSourceFeed(query) {
|
|
342
|
+
return this.request(`/feeds/sources${toSearchParams(query)}`);
|
|
343
|
+
}
|
|
344
|
+
async listClaimFeed(query) {
|
|
345
|
+
return this.request(`/feeds/claims${toSearchParams(query)}`);
|
|
346
|
+
}
|
|
347
|
+
async listSourceEvents(query) {
|
|
348
|
+
return this.request(`/events/sources${toSearchParams(query)}`);
|
|
349
|
+
}
|
|
350
|
+
async listClaimEvents(query) {
|
|
351
|
+
return this.request(`/events/claims${toSearchParams(query)}`);
|
|
352
|
+
}
|
|
353
|
+
async getOperatorRequests(query) {
|
|
354
|
+
return this.request(`/operator-requests${toSearchParams(query)}`);
|
|
355
|
+
}
|
|
356
|
+
async getReplicationJob(jobId) {
|
|
357
|
+
return this.request(`/replication-jobs/${jobId}`);
|
|
358
|
+
}
|
|
359
|
+
async getPersistedArtifact(artifactKey) {
|
|
360
|
+
return this.request(`/persisted-artifacts/${encodeURIComponent(artifactKey)}`);
|
|
361
|
+
}
|
|
362
|
+
getPersistedArtifactContentUrl(artifactKey) {
|
|
363
|
+
return `${this.baseUrl}/persisted-artifacts/${encodeURIComponent(artifactKey)}/content`;
|
|
364
|
+
}
|
|
365
|
+
async getPersistedArtifactAudits(artifactKey, query) {
|
|
366
|
+
return this.request(`/persisted-artifacts/${encodeURIComponent(artifactKey)}/audits${toSearchParams(query)}`);
|
|
367
|
+
}
|
|
368
|
+
async getPersistedArtifactMaintenanceTasks(artifactKey, query) {
|
|
369
|
+
return this.request(`/persisted-artifacts/${encodeURIComponent(artifactKey)}/maintenance-tasks${toSearchParams(query)}`);
|
|
370
|
+
}
|
|
371
|
+
async getResolutionRun(runId) {
|
|
372
|
+
return this.request(`/resolution-runs/${runId}`);
|
|
373
|
+
}
|
|
374
|
+
async listClaims(query) {
|
|
375
|
+
return this.request(`/claims${toSearchParams(query)}`);
|
|
376
|
+
}
|
|
377
|
+
async listReplications(query) {
|
|
378
|
+
return this.request(`/replications${toSearchParams(query)}`);
|
|
379
|
+
}
|
|
380
|
+
async listCheckpoints(query) {
|
|
381
|
+
return this.request(`/checkpoints${toSearchParams(query)}`);
|
|
382
|
+
}
|
|
383
|
+
async listArtifactMaintenanceTasks(query) {
|
|
384
|
+
return this.request(`/artifact-maintenance-tasks${toSearchParams(query)}`);
|
|
385
|
+
}
|
|
386
|
+
async listReviewTasks(query) {
|
|
387
|
+
return this.request(`/review-tasks${toSearchParams(query)}`);
|
|
388
|
+
}
|
|
389
|
+
async listSources(query) {
|
|
390
|
+
return this.request(`/sources${toSearchParams(query)}`);
|
|
391
|
+
}
|
|
392
|
+
async listWorkItems(query) {
|
|
393
|
+
return this.request(`/work-items${toSearchParams(query)}`);
|
|
394
|
+
}
|
|
395
|
+
async listAgentRequests(query) {
|
|
396
|
+
return this.request(`/agent-requests${toSearchParams(query)}`);
|
|
397
|
+
}
|
|
398
|
+
async listScenarios() {
|
|
399
|
+
return this.demo.getScenarios();
|
|
400
|
+
}
|
|
401
|
+
async request(pathname, init = {}) {
|
|
402
|
+
const headers = new Headers(this.defaultHeaders);
|
|
403
|
+
if (init.headers) {
|
|
404
|
+
const extraHeaders = new Headers(init.headers);
|
|
405
|
+
for (const [key, value] of extraHeaders.entries()) {
|
|
406
|
+
headers.set(key, value);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
if (init.body !== undefined && !headers.has("content-type")) {
|
|
410
|
+
headers.set("content-type", "application/json");
|
|
411
|
+
}
|
|
412
|
+
if (init.admin && this.demoAdminToken) {
|
|
413
|
+
headers.set("authorization", `Bearer ${this.demoAdminToken}`);
|
|
414
|
+
headers.set("x-sp-demo-admin-token", this.demoAdminToken);
|
|
415
|
+
}
|
|
416
|
+
const response = await this.fetchImpl(`${this.baseUrl}${pathname}`, {
|
|
417
|
+
body: init.body === undefined ? undefined : JSON.stringify(init.body),
|
|
418
|
+
headers,
|
|
419
|
+
method: init.method ?? "GET",
|
|
420
|
+
});
|
|
421
|
+
const body = await parseResponseBody(response);
|
|
422
|
+
if (!response.ok) {
|
|
423
|
+
throw new ScientificProtocolApiError(response, body);
|
|
424
|
+
}
|
|
425
|
+
return body;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { coreProtocolContractArtifacts, deployableContractArtifacts, generatedContractArtifacts, resolutionModuleContractArtifacts, } from "../generated/contracts.js";
|
|
2
|
+
export { type AgentRequestActionType, type AgentRequestEnvelope, type AgentRequestSigner, createSignedAgentRequest, hashAgentRequestEnvelope, type SignedAgentRequestEnvelope, signAgentRequestEnvelope, verifyAgentRequestEnvelope, } from "../shared/agent-request-envelope.js";
|
|
3
|
+
export { type ArtifactStorageAttestationActionType, type ArtifactStorageAttestationEnvelope, type ArtifactStorageAttestationSigner, buildArtifactStorageAttestationEnvelope, buildArtifactStorageAttestationScopeKey, createSignedArtifactStorageAttestation, hashArtifactStorageAttestationEnvelope, type SignedArtifactStorageAttestation, signArtifactStorageAttestation, toArtifactStorageAttestationRecordInput, type VerifiedArtifactStorageAttestation, verifyArtifactStorageAttestation, } from "../shared/artifact-storage-attestations.js";
|
|
4
|
+
export { type ArtifactStorageBundleManifest, type ArtifactStorageBundleManifestArtifact, type ArtifactStorageBundleManifestArtifactInput, type ArtifactStorageBundleManifestInput, type ArtifactStorageBundlePolicyInput, buildArtifactStorageBundleManifest, createArtifactStorageBundlePolicyInputs, verifyArtifactStorageBundleManifest, } from "../shared/artifact-storage-bundles.js";
|
|
5
|
+
export { ARTIFACT_STORAGE_CLASS_POLICIES, type ArtifactDurabilityClass, type ArtifactStorageAttestationInput, type ArtifactStorageClassPolicy, type ArtifactStorageCommitmentKind, type ArtifactStoragePolicyInput, defaultArtifactStoragePolicy, resolveArtifactStoragePolicyInput, } from "../shared/artifact-storage-policy.js";
|
|
6
|
+
export { ScientificProtocolApiError, ScientificProtocolClient, type ScientificProtocolClientOptions, } from "./client.js";
|
|
7
|
+
export { claimRewardWorkKindCode, type FundClaimRewardPoolInput, fundClaimRewardPool, fundClaimRewardPoolWithContract, getClaimRewardVaultContract, type RewardContractOptions, resolveRewardAmountWei, type WithdrawAccruedRewardsInput, withdrawAccruedRewards, withdrawAccruedRewardsWithContract, } from "./rewards.js";
|
|
8
|
+
export type * from "./types.js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { coreProtocolContractArtifacts, deployableContractArtifacts, generatedContractArtifacts, resolutionModuleContractArtifacts, } from "../generated/contracts.js";
|
|
2
|
+
export { createSignedAgentRequest, hashAgentRequestEnvelope, signAgentRequestEnvelope, verifyAgentRequestEnvelope, } from "../shared/agent-request-envelope.js";
|
|
3
|
+
export { buildArtifactStorageAttestationEnvelope, buildArtifactStorageAttestationScopeKey, createSignedArtifactStorageAttestation, hashArtifactStorageAttestationEnvelope, signArtifactStorageAttestation, toArtifactStorageAttestationRecordInput, verifyArtifactStorageAttestation, } from "../shared/artifact-storage-attestations.js";
|
|
4
|
+
export { buildArtifactStorageBundleManifest, createArtifactStorageBundlePolicyInputs, verifyArtifactStorageBundleManifest, } from "../shared/artifact-storage-bundles.js";
|
|
5
|
+
export { ARTIFACT_STORAGE_CLASS_POLICIES, defaultArtifactStoragePolicy, resolveArtifactStoragePolicyInput, } from "../shared/artifact-storage-policy.js";
|
|
6
|
+
export { ScientificProtocolApiError, ScientificProtocolClient, } from "./client.js";
|
|
7
|
+
export { claimRewardWorkKindCode, fundClaimRewardPool, fundClaimRewardPoolWithContract, getClaimRewardVaultContract, resolveRewardAmountWei, withdrawAccruedRewards, withdrawAccruedRewardsWithContract, } from "./rewards.js";
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type ContractRunner } from "ethers";
|
|
2
|
+
import { getContract } from "../shared/contracts.js";
|
|
3
|
+
export type ClaimRewardWorkKind = "challenge" | "forecast" | "maintenance" | "replication" | "review" | "synthesis";
|
|
4
|
+
type RewardAmountInput = {
|
|
5
|
+
amountEth?: string;
|
|
6
|
+
amountWei?: string;
|
|
7
|
+
};
|
|
8
|
+
type ClaimRewardVaultFundingContract = {
|
|
9
|
+
fundClaimRewards(claimId: bigint, workKind: number, overrides: {
|
|
10
|
+
value: bigint;
|
|
11
|
+
}): Promise<unknown>;
|
|
12
|
+
};
|
|
13
|
+
type ClaimRewardVaultWithdrawalContract = {
|
|
14
|
+
withdrawAccruedRewards(amount: bigint, recipient: string): Promise<unknown>;
|
|
15
|
+
};
|
|
16
|
+
export type RewardContractOptions = {
|
|
17
|
+
deploymentPath?: string;
|
|
18
|
+
runner: ContractRunner;
|
|
19
|
+
};
|
|
20
|
+
export type FundClaimRewardPoolInput = RewardAmountInput & RewardContractOptions & {
|
|
21
|
+
claimId: bigint | number | string;
|
|
22
|
+
workKind: ClaimRewardWorkKind;
|
|
23
|
+
};
|
|
24
|
+
export type WithdrawAccruedRewardsInput = RewardAmountInput & RewardContractOptions & {
|
|
25
|
+
recipient: string;
|
|
26
|
+
};
|
|
27
|
+
export declare function claimRewardWorkKindCode(workKind: ClaimRewardWorkKind): number;
|
|
28
|
+
export declare function parseClaimRewardWorkKind(workKind: string): ClaimRewardWorkKind;
|
|
29
|
+
export declare function resolveRewardAmountWei(input: RewardAmountInput): bigint;
|
|
30
|
+
export declare function getClaimRewardVaultContract(options: RewardContractOptions): Promise<Awaited<ReturnType<typeof getContract>> & ClaimRewardVaultFundingContract & ClaimRewardVaultWithdrawalContract>;
|
|
31
|
+
export declare function fundClaimRewardPoolWithContract(contract: ClaimRewardVaultFundingContract, input: {
|
|
32
|
+
amountWei: bigint;
|
|
33
|
+
claimId: bigint | number | string;
|
|
34
|
+
workKind: ClaimRewardWorkKind;
|
|
35
|
+
}): Promise<unknown>;
|
|
36
|
+
export declare function withdrawAccruedRewardsWithContract(contract: ClaimRewardVaultWithdrawalContract, input: {
|
|
37
|
+
amountWei: bigint;
|
|
38
|
+
recipient: string;
|
|
39
|
+
}): Promise<unknown>;
|
|
40
|
+
export declare function fundClaimRewardPool(input: FundClaimRewardPoolInput): Promise<unknown>;
|
|
41
|
+
export declare function withdrawAccruedRewards(input: WithdrawAccruedRewardsInput): Promise<unknown>;
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { parseEther } from "ethers";
|
|
2
|
+
import { getContract } from "../shared/contracts.js";
|
|
3
|
+
import { DEFAULT_DEPLOYMENT_PATH, loadDeploymentFile } from "../shared/deployment.js";
|
|
4
|
+
const CLAIM_REWARD_WORK_KIND_CODES = {
|
|
5
|
+
challenge: 3,
|
|
6
|
+
forecast: 5,
|
|
7
|
+
maintenance: 2,
|
|
8
|
+
replication: 1,
|
|
9
|
+
review: 0,
|
|
10
|
+
synthesis: 4,
|
|
11
|
+
};
|
|
12
|
+
export function claimRewardWorkKindCode(workKind) {
|
|
13
|
+
return CLAIM_REWARD_WORK_KIND_CODES[parseClaimRewardWorkKind(String(workKind))];
|
|
14
|
+
}
|
|
15
|
+
export function parseClaimRewardWorkKind(workKind) {
|
|
16
|
+
if (workKind in CLAIM_REWARD_WORK_KIND_CODES) {
|
|
17
|
+
return workKind;
|
|
18
|
+
}
|
|
19
|
+
throw new Error(`unsupported reward work kind: ${workKind}`);
|
|
20
|
+
}
|
|
21
|
+
export function resolveRewardAmountWei(input) {
|
|
22
|
+
let amount;
|
|
23
|
+
if (typeof input.amountWei === "string") {
|
|
24
|
+
const trimmed = input.amountWei.trim();
|
|
25
|
+
if (trimmed.length === 0) {
|
|
26
|
+
throw new Error("amountWei cannot be empty");
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
amount = BigInt(trimmed);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
throw new Error("amountWei must be an integer wei amount");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
else if (typeof input.amountEth === "string") {
|
|
36
|
+
const trimmed = input.amountEth.trim();
|
|
37
|
+
if (trimmed.length === 0) {
|
|
38
|
+
throw new Error("amountEth cannot be empty");
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
amount = parseEther(trimmed);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
throw new Error("amountEth must be a decimal ETH amount");
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
throw new Error("set amountWei or amountEth");
|
|
49
|
+
}
|
|
50
|
+
if (amount <= 0n) {
|
|
51
|
+
throw new Error("reward amount must be greater than zero");
|
|
52
|
+
}
|
|
53
|
+
return amount;
|
|
54
|
+
}
|
|
55
|
+
export async function getClaimRewardVaultContract(options) {
|
|
56
|
+
const deployment = await loadDeploymentFile(options.deploymentPath ?? DEFAULT_DEPLOYMENT_PATH);
|
|
57
|
+
return (await getContract("ClaimRewardVault", deployment.addresses.claimRewardVault, options.runner));
|
|
58
|
+
}
|
|
59
|
+
export async function fundClaimRewardPoolWithContract(contract, input) {
|
|
60
|
+
return contract.fundClaimRewards(BigInt(input.claimId), claimRewardWorkKindCode(input.workKind), {
|
|
61
|
+
value: input.amountWei,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
export async function withdrawAccruedRewardsWithContract(contract, input) {
|
|
65
|
+
return contract.withdrawAccruedRewards(input.amountWei, input.recipient);
|
|
66
|
+
}
|
|
67
|
+
export async function fundClaimRewardPool(input) {
|
|
68
|
+
const amountWei = resolveRewardAmountWei(input);
|
|
69
|
+
const workKind = parseClaimRewardWorkKind(input.workKind);
|
|
70
|
+
const contract = await getClaimRewardVaultContract(input);
|
|
71
|
+
return fundClaimRewardPoolWithContract(contract, {
|
|
72
|
+
amountWei,
|
|
73
|
+
claimId: input.claimId,
|
|
74
|
+
workKind,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
export async function withdrawAccruedRewards(input) {
|
|
78
|
+
const amountWei = resolveRewardAmountWei(input);
|
|
79
|
+
const contract = await getClaimRewardVaultContract(input);
|
|
80
|
+
return withdrawAccruedRewardsWithContract(contract, {
|
|
81
|
+
amountWei,
|
|
82
|
+
recipient: input.recipient,
|
|
83
|
+
});
|
|
84
|
+
}
|