@blindmarket/sdk 0.1.6 → 0.1.8

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.
Files changed (156) hide show
  1. package/README.md +242 -29
  2. package/dist/chain/BlindEscrowClient.d.ts +2 -0
  3. package/dist/chain/BlindEscrowClient.js +19 -7
  4. package/dist/chain/BlindReputationClient.d.ts +3 -0
  5. package/dist/chain/BlindReputationClient.js +3 -1
  6. package/dist/chain/ChainClient.d.ts +6 -3
  7. package/dist/chain/ChainClient.js +6 -1
  8. package/dist/chain/IBlindMarketChain.d.ts +74 -0
  9. package/dist/chain/IBlindMarketChain.js +1 -0
  10. package/dist/chain/TaskRegistryClient.d.ts +2 -1
  11. package/dist/chain/TaskRegistryClient.js +15 -7
  12. package/dist/chain/createChainAdapter.d.ts +25 -0
  13. package/dist/chain/createChainAdapter.js +24 -0
  14. package/dist/chain/domain-types.d.ts +77 -0
  15. package/dist/chain/domain-types.js +1 -0
  16. package/dist/chain/evm/EVMChainAdapter.d.ts +56 -0
  17. package/dist/chain/evm/EVMChainAdapter.js +161 -0
  18. package/dist/chain/evm/index.d.ts +1 -0
  19. package/dist/chain/evm/index.js +1 -0
  20. package/dist/chain/index.d.ts +4 -0
  21. package/dist/chain/index.js +5 -0
  22. package/dist/crypto/constants.js +1 -1
  23. package/dist/errors/{BlindBountyError.d.ts → BlindMarketError.d.ts} +1 -1
  24. package/dist/errors/{BlindBountyError.js → BlindMarketError.js} +1 -1
  25. package/dist/errors/index.d.ts +1 -1
  26. package/dist/errors/index.js +1 -1
  27. package/dist/errors/subclasses.d.ts +9 -9
  28. package/dist/errors/subclasses.js +9 -9
  29. package/dist/executor/WorkerRuntime.d.ts +113 -0
  30. package/dist/executor/WorkerRuntime.js +248 -0
  31. package/dist/executor/index.d.ts +1 -0
  32. package/dist/executor/index.js +1 -0
  33. package/dist/index.d.ts +292 -22
  34. package/dist/index.js +413 -23
  35. package/dist/keystore/InMemoryKeyStore.js +2 -2
  36. package/dist/network/presets.d.ts +33 -5
  37. package/dist/network/presets.js +35 -8
  38. package/dist/network/resolve.d.ts +12 -3
  39. package/dist/network/resolve.js +15 -7
  40. package/dist/network/types.d.ts +3 -16
  41. package/dist/signer/EthersSigner.js +1 -1
  42. package/dist/storage/index.d.ts +0 -1
  43. package/dist/storage/index.js +1 -1
  44. package/dist/tools/adapters.d.ts +99 -0
  45. package/dist/tools/adapters.js +129 -0
  46. package/dist/tools/helpers.d.ts +9 -0
  47. package/dist/tools/helpers.js +169 -0
  48. package/dist/tools/index.d.ts +36 -0
  49. package/dist/tools/index.js +32 -0
  50. package/dist/tools/types.d.ts +44 -0
  51. package/dist/tools/types.js +1 -0
  52. package/dist/types.d.ts +202 -1
  53. package/dist/types.js +24 -1
  54. package/package.json +13 -2
  55. package/src/chain/BlindEscrowClient.ts +20 -6
  56. package/src/chain/BlindReputationClient.ts +6 -1
  57. package/src/chain/ChainClient.ts +9 -3
  58. package/src/chain/IBlindMarketChain.ts +109 -0
  59. package/src/chain/TaskRegistryClient.ts +17 -8
  60. package/src/chain/createChainAdapter.ts +40 -0
  61. package/src/chain/domain-types.ts +92 -0
  62. package/src/chain/evm/EVMChainAdapter.ts +212 -0
  63. package/src/chain/evm/index.ts +1 -0
  64. package/src/chain/index.ts +6 -0
  65. package/src/executor/WorkerRuntime.ts +338 -0
  66. package/src/executor/index.ts +8 -0
  67. package/src/index.ts +546 -36
  68. package/src/network/presets.ts +47 -8
  69. package/src/network/resolve.ts +20 -8
  70. package/src/network/types.ts +18 -16
  71. package/src/signer/index.ts +1 -1
  72. package/src/storage/index.ts +1 -1
  73. package/src/tools/adapters.ts +177 -0
  74. package/src/tools/helpers.ts +199 -0
  75. package/src/tools/index.ts +59 -0
  76. package/src/tools/types.ts +47 -0
  77. package/src/types.ts +222 -1
  78. package/tsconfig.json +2 -1
  79. package/dist/BlindEscrowClient-CyPuKMge.d.cts +0 -54
  80. package/dist/BlindEscrowClient-R7iGpE-n.d.ts +0 -54
  81. package/dist/KeyStore-Be_SSpCt.d.cts +0 -21
  82. package/dist/KeyStore-k1JgYPJY.d.ts +0 -21
  83. package/dist/Signer-BnqH_qew.d.cts +0 -38
  84. package/dist/Signer-LColE0Uo.d.ts +0 -38
  85. package/dist/Storage-4QOrh7rm.d.ts +0 -17
  86. package/dist/Storage-Cf4IJRMk.d.cts +0 -17
  87. package/dist/TaskRegistryClient-Ch6lYqM_.d.ts +0 -24
  88. package/dist/TaskRegistryClient-CrQjddDc.d.cts +0 -24
  89. package/dist/aes-J-7HrHze.d.cts +0 -17
  90. package/dist/aes-J-7HrHze.d.ts +0 -17
  91. package/dist/agent/index.cjs +0 -425
  92. package/dist/agent/index.cjs.map +0 -1
  93. package/dist/agent/index.d.cts +0 -63
  94. package/dist/agent/index.js.map +0 -1
  95. package/dist/api/index.cjs +0 -4
  96. package/dist/api/index.cjs.map +0 -1
  97. package/dist/api/index.d.cts +0 -2
  98. package/dist/api/index.js.map +0 -1
  99. package/dist/chain/index.cjs +0 -2484
  100. package/dist/chain/index.cjs.map +0 -1
  101. package/dist/chain/index.d.cts +0 -2305
  102. package/dist/chain/index.js.map +0 -1
  103. package/dist/compute/index.cjs +0 -4
  104. package/dist/compute/index.cjs.map +0 -1
  105. package/dist/compute/index.d.cts +0 -2
  106. package/dist/compute/index.js.map +0 -1
  107. package/dist/crypto/index.cjs +0 -424
  108. package/dist/crypto/index.cjs.map +0 -1
  109. package/dist/crypto/index.d.cts +0 -74
  110. package/dist/crypto/index.js.map +0 -1
  111. package/dist/errors/index.cjs +0 -136
  112. package/dist/errors/index.cjs.map +0 -1
  113. package/dist/errors/index.d.cts +0 -60
  114. package/dist/errors/index.js.map +0 -1
  115. package/dist/events/index.cjs +0 -41
  116. package/dist/events/index.cjs.map +0 -1
  117. package/dist/events/index.d.cts +0 -61
  118. package/dist/events/index.js.map +0 -1
  119. package/dist/index.cjs +0 -4
  120. package/dist/index.cjs.map +0 -1
  121. package/dist/index.d.cts +0 -2
  122. package/dist/index.js.map +0 -1
  123. package/dist/keystore/index.cjs +0 -335
  124. package/dist/keystore/index.cjs.map +0 -1
  125. package/dist/keystore/index.d.cts +0 -23
  126. package/dist/keystore/index.js.map +0 -1
  127. package/dist/network/index.cjs +0 -74
  128. package/dist/network/index.cjs.map +0 -1
  129. package/dist/network/index.d.cts +0 -36
  130. package/dist/network/index.js.map +0 -1
  131. package/dist/signer/index.cjs +0 -121
  132. package/dist/signer/index.cjs.map +0 -1
  133. package/dist/signer/index.d.cts +0 -40
  134. package/dist/signer/index.js.map +0 -1
  135. package/dist/storage/ZgStorage.d.ts +0 -24
  136. package/dist/storage/ZgStorage.js +0 -102
  137. package/dist/storage/index.cjs +0 -221
  138. package/dist/storage/index.cjs.map +0 -1
  139. package/dist/storage/index.d.cts +0 -44
  140. package/dist/storage/index.js.map +0 -1
  141. package/dist/testing/index.cjs +0 -4
  142. package/dist/testing/index.cjs.map +0 -1
  143. package/dist/testing/index.d.cts +0 -2
  144. package/dist/testing/index.js.map +0 -1
  145. package/dist/types-BOG5Ub1z.d.cts +0 -31
  146. package/dist/types-BOG5Ub1z.d.ts +0 -31
  147. package/dist/types-V7_ZmUb-.d.cts +0 -19
  148. package/dist/types-hAsITUQ7.d.ts +0 -19
  149. package/dist/verifier/index.cjs +0 -4
  150. package/dist/verifier/index.cjs.map +0 -1
  151. package/dist/verifier/index.d.cts +0 -2
  152. package/dist/verifier/index.js.map +0 -1
  153. package/dist/worker/index.cjs +0 -382
  154. package/dist/worker/index.cjs.map +0 -1
  155. package/dist/worker/index.d.cts +0 -58
  156. package/dist/worker/index.js.map +0 -1
@@ -0,0 +1,248 @@
1
+ import { BlindMarket } from '../index.js';
2
+ import { eciesDecrypt, aesDecrypt } from '../crypto/index.js';
3
+ // ── Defaults ────────────────────────────────────────────────────────────────
4
+ const DEFAULTS = {
5
+ browseIntervalMs: 15_000,
6
+ watchIntervalMs: 5_000,
7
+ maxConcurrentTasks: 3,
8
+ };
9
+ // ── WorkerRuntime ───────────────────────────────────────────────────────────
10
+ export class WorkerRuntime {
11
+ bb;
12
+ config;
13
+ wallet;
14
+ profile;
15
+ running = false;
16
+ paused = false;
17
+ browseTimer;
18
+ watchTimers = new Map();
19
+ executions = new Map();
20
+ listeners = new Set();
21
+ constructor(config) {
22
+ this.config = { ...DEFAULTS, ...config };
23
+ this.bb = new BlindMarket({ apiKey: config.apiKey, apiBase: config.apiBase });
24
+ }
25
+ // ── Status ──────────────────────────────────────────────────────────────
26
+ get isRunning() {
27
+ return this.running;
28
+ }
29
+ get isPaused() {
30
+ return this.paused;
31
+ }
32
+ get activeExecutions() {
33
+ return [...this.executions.values()];
34
+ }
35
+ /** Get own executor profile (available after start). */
36
+ get executorProfile() {
37
+ return this.profile;
38
+ }
39
+ /** Get own wallet info (available after start). */
40
+ get executorWallet() {
41
+ return this.wallet;
42
+ }
43
+ // ── Events ──────────────────────────────────────────────────────────────
44
+ on(listener) {
45
+ this.listeners.add(listener);
46
+ return () => this.listeners.delete(listener);
47
+ }
48
+ emit(event) {
49
+ for (const l of this.listeners)
50
+ l(event);
51
+ }
52
+ // ── Lifecycle ───────────────────────────────────────────────────────────
53
+ async start() {
54
+ if (this.running)
55
+ return this.profile;
56
+ // 1. Register or restore executor
57
+ if (this.config.existingPrivateKey && this.config.existingAddress && this.config.existingPublicKey) {
58
+ this.wallet = {
59
+ address: this.config.existingAddress,
60
+ privateKey: this.config.existingPrivateKey,
61
+ publicKey: this.config.existingPublicKey,
62
+ };
63
+ // Fetch existing profile — backend identifies by API key
64
+ const result = await this.bb.getExecutorProfile();
65
+ this.profile = result.agent;
66
+ }
67
+ else {
68
+ const result = await this.bb.createAgent({
69
+ displayName: this.config.displayName,
70
+ capabilities: this.config.capabilities,
71
+ minReward: this.config.minReward,
72
+ preferredCapabilities: this.config.preferredCapabilities,
73
+ });
74
+ this.wallet = {
75
+ address: result.wallet.address,
76
+ privateKey: result.wallet.privateKey,
77
+ publicKey: result.wallet.publicKey,
78
+ };
79
+ this.profile = result.executor;
80
+ }
81
+ this.emit({ type: 'registered', profile: this.profile });
82
+ // 2. Start the browse loop
83
+ this.running = true;
84
+ this.startBrowseLoop();
85
+ this.emit({ type: 'started' });
86
+ return this.profile;
87
+ }
88
+ stop() {
89
+ this.running = false;
90
+ if (this.browseTimer) {
91
+ clearInterval(this.browseTimer);
92
+ this.browseTimer = undefined;
93
+ }
94
+ for (const t of this.watchTimers.values())
95
+ clearInterval(t);
96
+ this.watchTimers.clear();
97
+ this.emit({ type: 'stopped' });
98
+ }
99
+ pause() {
100
+ if (!this.running || this.paused)
101
+ return;
102
+ this.paused = true;
103
+ this.emit({ type: 'paused' });
104
+ }
105
+ resume() {
106
+ if (!this.running || !this.paused)
107
+ return;
108
+ this.paused = false;
109
+ this.emit({ type: 'resumed' });
110
+ // Immediately browse instead of waiting for next interval
111
+ this.browse();
112
+ }
113
+ // ── Browse loop ─────────────────────────────────────────────────────────
114
+ startBrowseLoop() {
115
+ const ms = this.config.browseIntervalMs;
116
+ this.browseTimer = setInterval(() => this.browse(), ms);
117
+ this.browse();
118
+ }
119
+ async browse() {
120
+ if (this.paused)
121
+ return;
122
+ try {
123
+ const active = this.activeExecutions;
124
+ const inFlight = active.filter(e => e.status === 'bidding' || e.status === 'working').length;
125
+ if (inFlight >= this.config.maxConcurrentTasks)
126
+ return;
127
+ const result = await this.bb.browseA2ATasks({
128
+ capabilities: this.config.capabilities,
129
+ });
130
+ this.emit({ type: 'browse_done', found: result.tasks.length });
131
+ for (const task of result.tasks) {
132
+ if (this.executions.has(task.taskId))
133
+ continue;
134
+ if (task.status !== 'open' && task.status !== 'bidding')
135
+ continue;
136
+ if (task.executorAddress && task.executorAddress !== this.wallet?.address)
137
+ continue;
138
+ this.executions.set(task.taskId, {
139
+ taskId: task.taskId,
140
+ status: 'bidding',
141
+ task,
142
+ startedAt: Date.now(),
143
+ });
144
+ this.emit({ type: 'task_found', taskId: task.taskId, task });
145
+ await this.bb.bidOnTask(task.taskId);
146
+ this.emit({ type: 'task_bidded', taskId: task.taskId });
147
+ this.watchForAssignment(task.taskId);
148
+ }
149
+ }
150
+ catch (err) {
151
+ this.emit({ type: 'error', error: `Browse failed: ${err}` });
152
+ }
153
+ }
154
+ // ── Assignment watching ─────────────────────────────────────────────────
155
+ watchForAssignment(taskId) {
156
+ if (!this.running)
157
+ return;
158
+ const ms = this.config.watchIntervalMs;
159
+ const timer = setInterval(async () => {
160
+ if (!this.running || this.paused)
161
+ return;
162
+ try {
163
+ const detail = await this.bb.getTask(taskId);
164
+ const a2a = detail.a2aState;
165
+ if (!a2a)
166
+ return;
167
+ if (a2a.status === 'assigned') {
168
+ clearInterval(timer);
169
+ this.watchTimers.delete(taskId);
170
+ this.emit({ type: 'task_assigned', taskId });
171
+ await this.executeTask(taskId, a2a);
172
+ }
173
+ }
174
+ catch {
175
+ // Retry next tick
176
+ }
177
+ }, ms);
178
+ this.watchTimers.set(taskId, timer);
179
+ }
180
+ // ── Task execution ──────────────────────────────────────────────────────
181
+ async executeTask(taskId, a2a) {
182
+ const exec = this.executions.get(taskId);
183
+ if (!exec)
184
+ return;
185
+ try {
186
+ exec.status = 'assigned';
187
+ // Accept task — get the ECIES-wrapped AES key
188
+ const acceptResult = await this.bb.acceptTask(taskId);
189
+ exec.task = acceptResult.task;
190
+ this.emit({ type: 'task_accepted', taskId });
191
+ // Get full task detail for the storage root hash
192
+ const detail = await this.bb.getTask(taskId);
193
+ const taskHash = detail.taskHash;
194
+ // Decrypt the wrapped key with the worker's private key
195
+ let instructions = '';
196
+ if (acceptResult.wrappedKey && taskHash) {
197
+ const wrappedBytes = this.decodeWrappedKey(acceptResult.wrappedKey);
198
+ const aesKey = await eciesDecrypt(wrappedBytes, this.wallet.privateKey);
199
+ // Download ciphertext from storage via REST API
200
+ const storageResult = await this.bb.downloadBlob(taskHash);
201
+ const ciphertext = this.hexToBytes(storageResult.data);
202
+ // AES decrypt to get plaintext instructions
203
+ const plaintext = await aesDecrypt(ciphertext, aesKey);
204
+ instructions = new TextDecoder().decode(plaintext);
205
+ }
206
+ exec.status = 'working';
207
+ this.emit({ type: 'task_working', taskId });
208
+ // Call the user-provided execution handler with decrypted instructions
209
+ const result = await this.config.executeTask({
210
+ taskId,
211
+ task: acceptResult.task,
212
+ instructions,
213
+ });
214
+ exec.status = 'submitted';
215
+ this.emit({ type: 'task_executed', taskId });
216
+ // Submit result
217
+ const submitResult = await this.bb.submitResult(taskId, result);
218
+ exec.status = 'completed';
219
+ this.emit({ type: 'task_submitted', taskId, result: submitResult });
220
+ }
221
+ catch (err) {
222
+ exec.status = 'failed';
223
+ exec.error = String(err);
224
+ this.emit({ type: 'task_failed', taskId, error: String(err) });
225
+ }
226
+ }
227
+ // ── Helpers ─────────────────────────────────────────────────────────────
228
+ decodeWrappedKey(wrappedKey) {
229
+ // Backend returns wrapped key as hex or base64 in a record
230
+ const hex = Object.values(wrappedKey)[0];
231
+ if (!hex)
232
+ throw new Error('Empty wrapped key');
233
+ const clean = hex.startsWith('0x') ? hex.slice(2) : hex;
234
+ const bytes = new Uint8Array(clean.length / 2);
235
+ for (let i = 0; i < bytes.length; i++) {
236
+ bytes[i] = parseInt(clean.substring(i * 2, i * 2 + 2), 16);
237
+ }
238
+ return bytes;
239
+ }
240
+ hexToBytes(hex) {
241
+ const clean = hex.startsWith('0x') ? hex.slice(2) : hex;
242
+ const bytes = new Uint8Array(clean.length / 2);
243
+ for (let i = 0; i < bytes.length; i++) {
244
+ bytes[i] = parseInt(clean.substring(i * 2, i * 2 + 2), 16);
245
+ }
246
+ return bytes;
247
+ }
248
+ }
@@ -0,0 +1 @@
1
+ export { WorkerRuntime, type WorkerRuntimeConfig, type ExecuteTaskHandler, type TaskContext, type TaskExecutionInfo, type WorkerRuntimeEvent, } from './WorkerRuntime.js';
@@ -0,0 +1 @@
1
+ export { WorkerRuntime, } from './WorkerRuntime.js';
package/dist/index.d.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  import { ethers } from 'ethers';
2
+ import type { Address, Hex, HealthStatus, PlatformStats, OpenTask, TaskDetail, CreateTaskTx, ExecutorProfile, RegisterExecutorInput, DeployedAgentInfo, AgentWalletInfo, ReputationInfo, LeaderboardEntry, StorageUploadResult, Message, AgentSearchResult, TaskTemplate, VerifyTaskInput, A2ATaskState, CreateAgentParams, CreateAgentResult } from './types.js';
2
3
  export interface BlindMarketConfig {
4
+ /** Backend API base URL (default: https://api.blindmarket.xyz) */
3
5
  apiBase?: string;
6
+ /** API key — shared AGENT_API_KEY or device-flow token */
4
7
  apiKey: string;
5
- rpcUrl?: string;
6
8
  }
7
9
  export interface DeployAgentParams {
8
10
  name: string;
@@ -23,18 +25,117 @@ export interface DeployedAgent {
23
25
  inftTokenId?: number;
24
26
  status: string;
25
27
  }
28
+ declare class ApiError extends Error {
29
+ status: number;
30
+ body?: unknown | undefined;
31
+ constructor(status: number, message: string, body?: unknown | undefined);
32
+ }
33
+ /**
34
+ * BlindMarket REST API client.
35
+ *
36
+ * Two usage modes:
37
+ * 1. **High-level (this class)** — talks to the BlindMarket backend over REST.
38
+ * Covers the full task lifecycle, agent management, A2A, and marketplace.
39
+ * 2. **Low-level primitives** — `Agent`, `Worker`, `PrivateKeySigner`, etc.
40
+ * for on-chain + crypto operations when you need direct chain access.
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * const bb = new BlindMarket({ apiKey: process.env.BLINDMARKET_API_KEY! });
45
+ *
46
+ * // Deploy an agent
47
+ * const agent = await bb.deployAgent({ name: 'my-agent', ... });
48
+ *
49
+ * // Watch for status changes
50
+ * const unsub = bb.watchTask(42, (state) => console.log(state.status));
51
+ * ```
52
+ */
26
53
  export declare class BlindMarket {
27
54
  private apiBase;
28
55
  private apiKey;
29
56
  constructor(config: BlindMarketConfig);
57
+ /**
58
+ * Tool definitions for AI agent frameworks. Access framework-specific formats
59
+ * via property — no need to remember adapter function names.
60
+ *
61
+ * IMPORTANT: due to ESM circular-dependency constraints this is a standalone
62
+ * function rather than an instance getter. You pass `bb` once and reach the
63
+ * format you need.
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * import { BlindMarket, tools } from '@blindmarket/sdk';
68
+ * const bb = new BlindMarket({ apiKey });
69
+ *
70
+ * // OpenAI (default — also works with Vercel AI SDK)
71
+ * openai.chat.completions.create({ model: 'gpt-4', tools: tools(bb).definitions });
72
+ *
73
+ * // LangChain
74
+ * createReactAgent({ llm, tools: tools(bb).langchain });
75
+ *
76
+ * // Claude
77
+ * anthropic.messages.create({ model, tools: tools(bb).claude });
78
+ *
79
+ * // Vercel
80
+ * generateText({ model, tools: tools(bb).vercel });
81
+ * ```
82
+ */
30
83
  private req;
84
+ /** Backend liveness check. */
85
+ health(): Promise<HealthStatus>;
86
+ /** Live platform counts. */
87
+ stats(): Promise<PlatformStats>;
88
+ /** List open tasks (human-readable). */
89
+ listTasks(limit?: number): Promise<OpenTask[]>;
90
+ /** Get full task details (on-chain + A2A state). */
91
+ getTask(id: string): Promise<TaskDetail>;
92
+ /**
93
+ * Build an unsigned `createTask` transaction.
94
+ * You must sign and broadcast it with your wallet.
95
+ */
96
+ createTask(params: {
97
+ agent: Address;
98
+ amount: string;
99
+ token: Address;
100
+ category: string;
101
+ locationZone: string;
102
+ deadline: number;
103
+ }): Promise<CreateTaskTx>;
104
+ /**
105
+ * Build an unsigned `assignWorker` transaction.
106
+ */
107
+ assignWorker(taskId: string, worker: Address): Promise<{
108
+ unsignedTx: object;
109
+ }>;
110
+ /**
111
+ * Build an unsigned `cancelTask` transaction.
112
+ */
113
+ cancelTask(taskId: string): Promise<{
114
+ unsignedTx: object;
115
+ }>;
116
+ /**
117
+ * Build an unsigned `claimTimeout` transaction.
118
+ */
119
+ claimTimeout(taskId: string): Promise<{
120
+ unsignedTx: object;
121
+ }>;
122
+ /**
123
+ * Build an unsigned `submitEvidence` transaction.
124
+ */
125
+ submitEvidence(params: {
126
+ taskId: string;
127
+ evidenceHash: Hex;
128
+ }): Promise<{
129
+ unsignedTx: object;
130
+ }>;
31
131
  /**
32
- * Deploy a new agent. Generates a wallet, mints an INFT, returns the agent.
132
+ * Deploy a new agent. The backend generates a wallet, mints an INFT,
133
+ * and returns the agent descriptor.
33
134
  *
34
135
  * @example
35
136
  * const agent = await bb.deployAgent({
36
137
  * name: 'research-agent',
37
- * instructions: 'You research topics and post tasks for humans to verify.',
138
+ * instructions: 'You research topics and post tasks.',
38
139
  * provider: 'anthropic',
39
140
  * model: 'claude-sonnet-4-5',
40
141
  * apiKey: process.env.ANTHROPIC_API_KEY!,
@@ -44,40 +145,209 @@ export declare class BlindMarket {
44
145
  */
45
146
  deployAgent(params: DeployAgentParams): Promise<DeployedAgent>;
46
147
  /**
47
- * List all agents owned by an address.
148
+ * One-shot agent creation: generates a secp256k1 wallet, then registers the
149
+ * agent as an executor in the A2A marketplace with the generated wallet
150
+ * address and public key. Replaces the manual two-step flow of generating a
151
+ * wallet, then calling registerExecutor().
152
+ *
153
+ * The private key is returned **once** in the response — store it securely.
154
+ *
155
+ * @example
156
+ * const { executor, wallet } = await bb.createAgent({
157
+ * displayName: 'DataBot',
158
+ * capabilities: [AgentCap.DATA_PROCESSING, AgentCap.WEB_RESEARCH],
159
+ * minReward: '1000000000000000000', // 1 0G in wei
160
+ * });
161
+ * console.log(`Agent ${wallet.address} registered as ${executor.address}`);
48
162
  */
49
- listAgents(ownerAddress: string): Promise<DeployedAgent[]>;
163
+ createAgent(params: CreateAgentParams): Promise<CreateAgentResult>;
164
+ /** List deployed agents, optionally filtered by owner address. */
165
+ listAgents(ownerAddress?: string): Promise<DeployedAgentInfo[]>;
166
+ /** Get a single deployed agent by ID. */
167
+ getAgent(id: string): Promise<DeployedAgentInfo>;
168
+ /** Get an agent's on-chain wallet address. */
169
+ getAgentWallet(id: string): Promise<AgentWalletInfo>;
170
+ /** Start a deployed agent. Requires owner auth. */
171
+ startAgent(id: string): Promise<DeployedAgentInfo>;
172
+ /** Stop a deployed agent. Requires owner auth. */
173
+ stopAgent(id: string): Promise<DeployedAgentInfo>;
174
+ /** Pause a deployed agent. Requires owner auth. */
175
+ pauseAgent(id: string): Promise<DeployedAgentInfo>;
176
+ /** Restart a deployed agent. Requires owner auth. */
177
+ restartAgent(id: string): Promise<DeployedAgentInfo>;
50
178
  /**
51
- * Assign a worker to a task. Returns an unsigned tx.
179
+ * Update a deployed agent's config (instructions, model, tools, etc.).
180
+ * Requires owner auth.
52
181
  */
53
- assignWorker(taskId: string, worker: string): Promise<{
182
+ updateAgent(id: string, patch: Partial<{
183
+ instructions: string;
184
+ model: string;
185
+ capabilities: string[];
186
+ tools: object[];
187
+ minReward: string;
188
+ }>): Promise<DeployedAgentInfo>;
189
+ /** Register as an A2A agent executor (worker-side). */
190
+ registerExecutor(params: RegisterExecutorInput): Promise<{
191
+ agent: ExecutorProfile;
192
+ }>;
193
+ /** List registered A2A executors, optionally filtered by capability. */
194
+ listExecutors(capabilities?: string[]): Promise<{
195
+ executors: ExecutorProfile[];
196
+ }>;
197
+ /** Get own executor profile with on-chain + decayed reputation. */
198
+ getExecutorProfile(): Promise<{
199
+ agent: ExecutorProfile;
200
+ }>;
201
+ /** Browse A2A tasks available for execution. */
202
+ browseA2ATasks(params?: {
203
+ capabilities?: string[];
204
+ minReputation?: number;
205
+ }): Promise<{
206
+ tasks: A2ATaskState[];
207
+ }>;
208
+ /** Register intent to accept a task (bid). */
209
+ bidOnTask(taskId: string): Promise<void>;
210
+ /** Accept a task and get wrapped AES key. Requires executor auth. */
211
+ acceptTask(taskId: string): Promise<{
212
+ task: A2ATaskState;
213
+ wrappedKey: Record<string, string>;
214
+ }>;
215
+ /** Submit result for an accepted task. */
216
+ submitResult(taskId: string, resultData: Record<string, unknown>): Promise<{
54
217
  unsignedTx: object;
218
+ task: A2ATaskState;
219
+ }>;
220
+ /** Get tasks posted by the authenticated user. */
221
+ getPostedTasks(): Promise<{
222
+ tasks: A2ATaskState[];
223
+ }>;
224
+ /** Get tasks executed by the authenticated user. */
225
+ getExecutions(address?: string): Promise<{
226
+ tasks: A2ATaskState[];
55
227
  }>;
56
228
  /**
57
- * Trigger TEE verification for a task.
229
+ * Trigger TEE / AI verification for a task.
58
230
  */
59
- verify(params: {
60
- taskId: number;
61
- requirements: string;
62
- evidenceSummary: string;
63
- category?: string;
64
- }): Promise<{
231
+ verify(params: VerifyTaskInput): Promise<{
65
232
  passed: boolean;
66
233
  confidence: number;
67
234
  reasoning: string;
235
+ teeVerified?: boolean;
236
+ }>;
237
+ /** List available 0G Compute inference providers. */
238
+ getVerificationProviders(): Promise<{
239
+ providers: Array<{
240
+ address: Address;
241
+ model: string;
242
+ }>;
243
+ }>;
244
+ /** Check if 0G Compute is configured. */
245
+ getVerificationStatus(): Promise<{
246
+ configured: boolean;
247
+ provider?: string;
248
+ }>;
249
+ /** Get merged reputation (on-chain + off-chain) for an address. */
250
+ getReputation(address: Address): Promise<ReputationInfo>;
251
+ /** Get top workers by decayed score. */
252
+ getLeaderboard(limit?: number): Promise<LeaderboardEntry[]>;
253
+ /** Upload an encrypted blob to 0G Storage. */
254
+ uploadBlob(data: Hex): Promise<StorageUploadResult>;
255
+ /** Download a blob by root hash. */
256
+ downloadBlob(rootHash: Hex): Promise<{
257
+ data: Hex;
258
+ }>;
259
+ /** Send a message to another user or agent. */
260
+ sendMessage(params: {
261
+ taskId: string;
262
+ to: string;
263
+ content: string;
264
+ }): Promise<{
265
+ message: Message;
68
266
  }>;
267
+ /** Get inbox messages. */
268
+ getInbox(): Promise<{
269
+ messages: Message[];
270
+ }>;
271
+ /** Get unread message count. */
272
+ getUnreadCount(): Promise<{
273
+ count: number;
274
+ }>;
275
+ /** Search agents by capability and/or minimum rating. */
276
+ searchAgents(params?: {
277
+ capability?: string;
278
+ minRating?: number;
279
+ }): Promise<AgentSearchResult[]>;
280
+ /** List public task templates. */
281
+ listTemplates(): Promise<TaskTemplate[]>;
282
+ /** List own templates. */
283
+ listMyTemplates(): Promise<TaskTemplate[]>;
284
+ /** Create a task template. */
285
+ createTemplate(params: Partial<TaskTemplate>): Promise<TaskTemplate>;
286
+ /**
287
+ * Poll a task's status at a fixed interval. Calls `callback` on every change.
288
+ * Returns an unsubscribe function.
289
+ *
290
+ * @example
291
+ * const stop = bb.watchTask('42', (task) => {
292
+ * console.log('Status:', task.status);
293
+ * if (task.status === 'verified') stop();
294
+ * });
295
+ */
296
+ watchTask(taskId: string, callback: (task: TaskDetail) => void, intervalMs?: number): () => void;
69
297
  /**
70
- * Get task status.
298
+ * Poll an agent's status at a fixed interval. Returns an unsubscribe function.
71
299
  */
72
- getTask(taskId: string): Promise<{
73
- status: number;
74
- agent: string;
75
- worker: string;
76
- amount: string;
300
+ watchAgent(agentId: string, callback: (agent: DeployedAgentInfo) => void, intervalMs?: number): () => void;
301
+ /**
302
+ * Start a device-flow registration session. Generates a magic-link URL
303
+ * that the user opens in a browser to sign with their wallet.
304
+ *
305
+ * After registering, call `BlindMarket.pollSession(token)` to wait for
306
+ * the user to confirm and receive the API key.
307
+ *
308
+ * @example
309
+ * ```ts
310
+ * const wallet = ethers.Wallet.createRandom();
311
+ * const { url, token } = await BlindMarket.register({
312
+ * agentName: 'my-agent',
313
+ * agentWallet: wallet.address,
314
+ * agentPublicKey: wallet.publicKey,
315
+ * });
316
+ * console.log('Open', url, 'to confirm');
317
+ * const apiKey = await BlindMarket.pollSession(token);
318
+ * const bb = new BlindMarket({ apiKey });
319
+ * ```
320
+ */
321
+ static register(params: {
322
+ agentName: string;
323
+ agentWallet: string;
324
+ agentPublicKey: string;
325
+ apiBase?: string;
326
+ }): Promise<{
327
+ token: string;
328
+ url: string;
77
329
  }>;
78
330
  /**
79
- * List open tasks.
331
+ * Poll a device-flow registration session until the user confirms or
332
+ * the session expires. Returns the API key to use with `new BlindMarket({ apiKey })`.
333
+ *
334
+ * @param token - The session token from `BlindMarket.register()`.
335
+ * @param apiBase - Optional custom API base URL.
336
+ * @param intervalMs - Poll interval (default 2s).
337
+ * @param timeoutMs - Max wait time (default 5min).
80
338
  */
81
- listTasks(limit?: number): Promise<object[]>;
339
+ static pollSession(token: string, apiBase?: string, intervalMs?: number, timeoutMs?: number): Promise<string>;
82
340
  }
83
341
  export { ethers };
342
+ export { ApiError };
343
+ export { tools, createBlindMarketTools, createTaskTools, createAgentManagementTools, createA2ATools, toLangChainTools, toVercelTools, toOpenAITools, toClaudeTools, } from './tools/index.js';
344
+ export type { Tool, ToolKit, ToolDefinition } from './tools/types.js';
345
+ export type { BlindMarketTools } from './tools/index.js';
346
+ export * from './executor/index.js';
347
+ export * from './types.js';
348
+ export { EVMChainAdapter } from './chain/evm/index.js';
349
+ export { createChainAdapter } from './chain/createChainAdapter.js';
350
+ export type { CreateChainAdapterOptions } from './chain/createChainAdapter.js';
351
+ export type { IBlindMarketChain } from './chain/IBlindMarketChain.js';
352
+ export type { Network, EVMNetwork, BlockchainType, CreateTaskParams, DomainTask, DomainTaskMeta, DomainReputation, DomainTxReceipt, ChainSigner, } from './chain/domain-types.js';
353
+ export { isEVMNetwork } from './network/resolve.js';