@blindmarket/sdk 0.1.5 → 0.1.7
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/README.md +242 -29
- package/dist/chain/BlindEscrowClient.js +5 -1
- package/dist/chain/ChainClient.d.ts +1 -1
- package/dist/chain/ChainClient.js +1 -1
- package/dist/crypto/constants.js +1 -1
- package/dist/errors/BlindMarketError.d.ts +14 -0
- package/dist/errors/BlindMarketError.js +30 -0
- package/dist/errors/index.d.ts +1 -1
- package/dist/errors/index.js +1 -1
- package/dist/errors/subclasses.d.ts +9 -9
- package/dist/errors/subclasses.js +9 -9
- package/dist/index.d.ts +282 -29
- package/dist/index.js +399 -41
- package/dist/keystore/InMemoryKeyStore.js +2 -2
- package/dist/mcp.d.ts +23 -0
- package/dist/mcp.js +101 -0
- package/dist/signer/EthersSigner.js +1 -1
- package/dist/storage/index.d.ts +0 -1
- package/dist/storage/index.js +1 -1
- package/dist/tools/adapters.d.ts +99 -0
- package/dist/tools/adapters.js +129 -0
- package/dist/tools/helpers.d.ts +9 -0
- package/dist/tools/helpers.js +169 -0
- package/dist/tools/index.d.ts +36 -0
- package/dist/tools/index.js +32 -0
- package/dist/tools/types.d.ts +44 -0
- package/dist/tools/types.js +1 -0
- package/dist/types.d.ts +201 -0
- package/dist/types.js +24 -1
- package/package.json +13 -2
- package/src/chain/BlindEscrowClient.ts +5 -0
- package/src/index.ts +518 -49
- package/src/storage/index.ts +1 -1
- package/src/tools/adapters.ts +177 -0
- package/src/tools/helpers.ts +199 -0
- package/src/tools/index.ts +59 -0
- package/src/tools/types.ts +47 -0
- package/src/types.ts +220 -0
- package/tsconfig.json +2 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
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.
|
|
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
|
|
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,50 +145,202 @@ export declare class BlindMarket {
|
|
|
44
145
|
*/
|
|
45
146
|
deployAgent(params: DeployAgentParams): Promise<DeployedAgent>;
|
|
46
147
|
/**
|
|
47
|
-
*
|
|
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
|
-
|
|
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
|
-
*
|
|
179
|
+
* Update a deployed agent's config (instructions, model, tools, etc.).
|
|
180
|
+
* Requires owner auth.
|
|
52
181
|
*/
|
|
53
|
-
|
|
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;
|
|
68
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;
|
|
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>;
|
|
69
286
|
/**
|
|
70
|
-
*
|
|
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
|
+
* });
|
|
71
295
|
*/
|
|
72
|
-
|
|
73
|
-
status: number;
|
|
74
|
-
agent: string;
|
|
75
|
-
worker: string;
|
|
76
|
-
amount: string;
|
|
77
|
-
}>;
|
|
296
|
+
watchTask(taskId: string, callback: (task: TaskDetail) => void, intervalMs?: number): () => void;
|
|
78
297
|
/**
|
|
79
|
-
*
|
|
298
|
+
* Poll an agent's status at a fixed interval. Returns an unsubscribe function.
|
|
80
299
|
*/
|
|
81
|
-
|
|
300
|
+
watchAgent(agentId: string, callback: (agent: DeployedAgentInfo) => void, intervalMs?: number): () => void;
|
|
82
301
|
/**
|
|
83
|
-
*
|
|
84
|
-
*
|
|
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.
|
|
85
307
|
*
|
|
86
308
|
* @example
|
|
87
|
-
*
|
|
88
|
-
* const
|
|
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);
|
|
89
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;
|
|
329
|
+
}>;
|
|
330
|
+
/**
|
|
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).
|
|
90
338
|
*/
|
|
91
|
-
static
|
|
339
|
+
static pollSession(token: string, apiBase?: string, intervalMs?: number, timeoutMs?: number): Promise<string>;
|
|
92
340
|
}
|
|
93
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 './types.js';
|