mnemospark 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +84 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +1643 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +595 -0
- package/dist/index.js +3217 -0
- package/dist/index.js.map +1 -0
- package/openclaw.plugin.json +22 -0
- package/package.json +91 -0
- package/scripts/README.md +61 -0
- package/scripts/install-aws-cli.sh +28 -0
- package/scripts/install-jq.sh +13 -0
- package/scripts/install-pnpm.sh +20 -0
- package/scripts/reinstall.sh +102 -0
- package/scripts/seed-mnemospark-backend.sh +96 -0
- package/scripts/sync-plugin-version.js +24 -0
- package/scripts/uninstall.sh +67 -0
- package/scripts/verify-dev-tools.sh +56 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,595 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenClaw Plugin Types (locally defined)
|
|
3
|
+
*
|
|
4
|
+
* OpenClaw's plugin SDK uses duck typing — these match the shapes
|
|
5
|
+
* expected by registerProvider() and the plugin system.
|
|
6
|
+
* Defined locally to avoid depending on internal OpenClaw paths.
|
|
7
|
+
*/
|
|
8
|
+
type ModelApi = "openai-completions" | "openai-responses" | "anthropic-messages" | "google-generative-ai" | "github-copilot" | "bedrock-converse-stream";
|
|
9
|
+
type ModelDefinitionConfig = {
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
api?: ModelApi;
|
|
13
|
+
reasoning: boolean;
|
|
14
|
+
input: Array<"text" | "image">;
|
|
15
|
+
cost: {
|
|
16
|
+
input: number;
|
|
17
|
+
output: number;
|
|
18
|
+
cacheRead: number;
|
|
19
|
+
cacheWrite: number;
|
|
20
|
+
};
|
|
21
|
+
contextWindow: number;
|
|
22
|
+
maxTokens: number;
|
|
23
|
+
headers?: Record<string, string>;
|
|
24
|
+
};
|
|
25
|
+
type ModelProviderConfig = {
|
|
26
|
+
baseUrl: string;
|
|
27
|
+
apiKey?: string;
|
|
28
|
+
api?: ModelApi;
|
|
29
|
+
headers?: Record<string, string>;
|
|
30
|
+
authHeader?: boolean;
|
|
31
|
+
models: ModelDefinitionConfig[];
|
|
32
|
+
};
|
|
33
|
+
type AuthProfileCredential = {
|
|
34
|
+
apiKey?: string;
|
|
35
|
+
type?: string;
|
|
36
|
+
[key: string]: unknown;
|
|
37
|
+
};
|
|
38
|
+
type ProviderAuthResult = {
|
|
39
|
+
profiles: Array<{
|
|
40
|
+
profileId: string;
|
|
41
|
+
credential: AuthProfileCredential;
|
|
42
|
+
}>;
|
|
43
|
+
configPatch?: Record<string, unknown>;
|
|
44
|
+
defaultModel?: string;
|
|
45
|
+
notes?: string[];
|
|
46
|
+
};
|
|
47
|
+
type WizardPrompter = {
|
|
48
|
+
text: (opts: {
|
|
49
|
+
message: string;
|
|
50
|
+
validate?: (value: string) => string | undefined;
|
|
51
|
+
}) => Promise<string | symbol>;
|
|
52
|
+
note: (message: string) => void;
|
|
53
|
+
progress: (message: string) => {
|
|
54
|
+
stop: (message?: string) => void;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
type ProviderAuthContext = {
|
|
58
|
+
config: Record<string, unknown>;
|
|
59
|
+
agentDir?: string;
|
|
60
|
+
workspaceDir?: string;
|
|
61
|
+
prompter: WizardPrompter;
|
|
62
|
+
runtime: {
|
|
63
|
+
log: (message: string) => void;
|
|
64
|
+
};
|
|
65
|
+
isRemote: boolean;
|
|
66
|
+
openUrl: (url: string) => Promise<void>;
|
|
67
|
+
};
|
|
68
|
+
type ProviderAuthMethod = {
|
|
69
|
+
id: string;
|
|
70
|
+
label: string;
|
|
71
|
+
hint?: string;
|
|
72
|
+
kind: "oauth" | "api_key" | "token" | "device_code" | "custom";
|
|
73
|
+
run: (ctx: ProviderAuthContext) => Promise<ProviderAuthResult>;
|
|
74
|
+
};
|
|
75
|
+
type ProviderPlugin = {
|
|
76
|
+
id: string;
|
|
77
|
+
label: string;
|
|
78
|
+
docsPath?: string;
|
|
79
|
+
aliases?: string[];
|
|
80
|
+
envVars?: string[];
|
|
81
|
+
models?: ModelProviderConfig;
|
|
82
|
+
auth: ProviderAuthMethod[];
|
|
83
|
+
formatApiKey?: (cred: AuthProfileCredential) => string;
|
|
84
|
+
};
|
|
85
|
+
type PluginLogger = {
|
|
86
|
+
debug?: (message: string) => void;
|
|
87
|
+
info: (message: string) => void;
|
|
88
|
+
warn: (message: string) => void;
|
|
89
|
+
error: (message: string) => void;
|
|
90
|
+
};
|
|
91
|
+
type OpenClawPluginService = {
|
|
92
|
+
id: string;
|
|
93
|
+
start: () => void | Promise<void>;
|
|
94
|
+
stop?: () => void | Promise<void>;
|
|
95
|
+
};
|
|
96
|
+
type OpenClawPluginApi = {
|
|
97
|
+
id: string;
|
|
98
|
+
name: string;
|
|
99
|
+
version?: string;
|
|
100
|
+
description?: string;
|
|
101
|
+
source: string;
|
|
102
|
+
config: Record<string, unknown> & {
|
|
103
|
+
models?: {
|
|
104
|
+
providers?: Record<string, ModelProviderConfig>;
|
|
105
|
+
};
|
|
106
|
+
agents?: Record<string, unknown>;
|
|
107
|
+
};
|
|
108
|
+
pluginConfig?: Record<string, unknown>;
|
|
109
|
+
logger: PluginLogger;
|
|
110
|
+
registerProvider: (provider: ProviderPlugin) => void;
|
|
111
|
+
registerTool: (tool: unknown, opts?: unknown) => void;
|
|
112
|
+
registerHook: (events: string | string[], handler: unknown, opts?: unknown) => void;
|
|
113
|
+
registerHttpRoute: (params: {
|
|
114
|
+
path: string;
|
|
115
|
+
handler: unknown;
|
|
116
|
+
}) => void;
|
|
117
|
+
registerService: (service: OpenClawPluginService) => void;
|
|
118
|
+
registerCommand: (command: unknown) => void;
|
|
119
|
+
resolvePath: (input: string) => string;
|
|
120
|
+
on: (hookName: string, handler: unknown, opts?: unknown) => void;
|
|
121
|
+
};
|
|
122
|
+
type OpenClawPluginDefinition = {
|
|
123
|
+
id?: string;
|
|
124
|
+
name?: string;
|
|
125
|
+
description?: string;
|
|
126
|
+
version?: string;
|
|
127
|
+
register?: (api: OpenClawPluginApi) => void | Promise<void>;
|
|
128
|
+
activate?: (api: OpenClawPluginApi) => void | Promise<void>;
|
|
129
|
+
};
|
|
130
|
+
type PluginCommandContext = {
|
|
131
|
+
senderId?: string;
|
|
132
|
+
channel: string;
|
|
133
|
+
isAuthorizedSender: boolean;
|
|
134
|
+
args?: string;
|
|
135
|
+
commandBody: string;
|
|
136
|
+
config: Record<string, unknown>;
|
|
137
|
+
};
|
|
138
|
+
type PluginCommandResult = {
|
|
139
|
+
text?: string;
|
|
140
|
+
isError?: boolean;
|
|
141
|
+
};
|
|
142
|
+
type PluginCommandHandler = (ctx: PluginCommandContext) => PluginCommandResult | Promise<PluginCommandResult>;
|
|
143
|
+
type OpenClawPluginCommandDefinition = {
|
|
144
|
+
name: string;
|
|
145
|
+
description: string;
|
|
146
|
+
acceptsArgs?: boolean;
|
|
147
|
+
requireAuth?: boolean;
|
|
148
|
+
handler: PluginCommandHandler;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Balance Monitor for ClawRouter
|
|
153
|
+
*
|
|
154
|
+
* Monitors USDC balance on Base network with intelligent caching.
|
|
155
|
+
* Provides pre-request balance checks to prevent failed payments.
|
|
156
|
+
*
|
|
157
|
+
* Caching Strategy:
|
|
158
|
+
* - TTL: 30 seconds (balance is cached to avoid excessive RPC calls)
|
|
159
|
+
* - Optimistic deduction: after successful payment, subtract estimated cost from cache
|
|
160
|
+
* - Invalidation: on payment failure, immediately refresh from RPC
|
|
161
|
+
*/
|
|
162
|
+
/** Balance thresholds in USDC smallest unit (6 decimals) */
|
|
163
|
+
declare const BALANCE_THRESHOLDS: {
|
|
164
|
+
/** Low balance warning threshold: $1.00 */
|
|
165
|
+
readonly LOW_BALANCE_MICROS: 1000000n;
|
|
166
|
+
/** Effectively zero threshold: $0.0001 (covers dust/rounding) */
|
|
167
|
+
readonly ZERO_THRESHOLD: 100n;
|
|
168
|
+
};
|
|
169
|
+
/** Balance information returned by checkBalance() */
|
|
170
|
+
type BalanceInfo = {
|
|
171
|
+
/** Raw balance in USDC smallest unit (6 decimals) */
|
|
172
|
+
balance: bigint;
|
|
173
|
+
/** Formatted balance as "$X.XX" */
|
|
174
|
+
balanceUSD: string;
|
|
175
|
+
/** True if balance < $1.00 */
|
|
176
|
+
isLow: boolean;
|
|
177
|
+
/** True if balance < $0.0001 (effectively zero) */
|
|
178
|
+
isEmpty: boolean;
|
|
179
|
+
/** Wallet address for funding instructions */
|
|
180
|
+
walletAddress: string;
|
|
181
|
+
};
|
|
182
|
+
/** Result from checkSufficient() */
|
|
183
|
+
type SufficiencyResult = {
|
|
184
|
+
/** True if balance >= estimated cost */
|
|
185
|
+
sufficient: boolean;
|
|
186
|
+
/** Current balance info */
|
|
187
|
+
info: BalanceInfo;
|
|
188
|
+
/** If insufficient, the shortfall as "$X.XX" */
|
|
189
|
+
shortfall?: string;
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* Monitors USDC balance on Base network.
|
|
193
|
+
*
|
|
194
|
+
* Usage:
|
|
195
|
+
* const monitor = new BalanceMonitor("0x...");
|
|
196
|
+
* const info = await monitor.checkBalance();
|
|
197
|
+
* if (info.isLow) console.warn("Low balance!");
|
|
198
|
+
*/
|
|
199
|
+
declare class BalanceMonitor {
|
|
200
|
+
private readonly client;
|
|
201
|
+
private readonly walletAddress;
|
|
202
|
+
/** Cached balance (null = not yet fetched) */
|
|
203
|
+
private cachedBalance;
|
|
204
|
+
/** Timestamp when cache was last updated */
|
|
205
|
+
private cachedAt;
|
|
206
|
+
constructor(walletAddress: string);
|
|
207
|
+
/**
|
|
208
|
+
* Check current USDC balance.
|
|
209
|
+
* Uses cache if valid, otherwise fetches from RPC.
|
|
210
|
+
*/
|
|
211
|
+
checkBalance(): Promise<BalanceInfo>;
|
|
212
|
+
/**
|
|
213
|
+
* Check if balance is sufficient for an estimated cost.
|
|
214
|
+
*
|
|
215
|
+
* @param estimatedCostMicros - Estimated cost in USDC smallest unit (6 decimals)
|
|
216
|
+
*/
|
|
217
|
+
checkSufficient(estimatedCostMicros: bigint): Promise<SufficiencyResult>;
|
|
218
|
+
/**
|
|
219
|
+
* Optimistically deduct estimated cost from cached balance.
|
|
220
|
+
* Call this after a successful payment to keep cache accurate.
|
|
221
|
+
*
|
|
222
|
+
* @param amountMicros - Amount to deduct in USDC smallest unit
|
|
223
|
+
*/
|
|
224
|
+
deductEstimated(amountMicros: bigint): void;
|
|
225
|
+
/**
|
|
226
|
+
* Invalidate cache, forcing next checkBalance() to fetch from RPC.
|
|
227
|
+
* Call this after a payment failure to get accurate balance.
|
|
228
|
+
*/
|
|
229
|
+
invalidate(): void;
|
|
230
|
+
/**
|
|
231
|
+
* Force refresh balance from RPC (ignores cache).
|
|
232
|
+
*/
|
|
233
|
+
refresh(): Promise<BalanceInfo>;
|
|
234
|
+
/**
|
|
235
|
+
* Format USDC amount (in micros) as "$X.XX".
|
|
236
|
+
*/
|
|
237
|
+
formatUSDC(amountMicros: bigint): string;
|
|
238
|
+
/**
|
|
239
|
+
* Get the wallet address being monitored.
|
|
240
|
+
*/
|
|
241
|
+
getWalletAddress(): string;
|
|
242
|
+
/** Fetch balance from RPC */
|
|
243
|
+
private fetchBalance;
|
|
244
|
+
/** Build BalanceInfo from raw balance */
|
|
245
|
+
private buildInfo;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Local mnemospark proxy server.
|
|
250
|
+
*
|
|
251
|
+
* This proxy only forwards mnemospark storage endpoints to the backend API and
|
|
252
|
+
* serves health checks. It does not handle chat completions or model routing.
|
|
253
|
+
*/
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Get the proxy port from pre-loaded configuration.
|
|
257
|
+
* Port is validated at module load time, this just returns the cached value.
|
|
258
|
+
*/
|
|
259
|
+
declare function getProxyPort(): number;
|
|
260
|
+
/** Callback info for low balance warning */
|
|
261
|
+
type LowBalanceInfo = {
|
|
262
|
+
balanceUSD: string;
|
|
263
|
+
walletAddress: string;
|
|
264
|
+
};
|
|
265
|
+
/** Callback info for insufficient funds error */
|
|
266
|
+
type InsufficientFundsInfo = {
|
|
267
|
+
balanceUSD: string;
|
|
268
|
+
requiredUSD: string;
|
|
269
|
+
walletAddress: string;
|
|
270
|
+
};
|
|
271
|
+
type ProxyOptions = {
|
|
272
|
+
walletKey: string;
|
|
273
|
+
/** Port to listen on (default: 7120) */
|
|
274
|
+
port?: number;
|
|
275
|
+
onReady?: (port: number) => void;
|
|
276
|
+
onError?: (error: Error) => void;
|
|
277
|
+
/** Called when balance drops below $1.00 (warning, request still proceeds) */
|
|
278
|
+
onLowBalance?: (info: LowBalanceInfo) => void;
|
|
279
|
+
/** Called when balance is insufficient for a request (request fails) */
|
|
280
|
+
onInsufficientFunds?: (info: InsufficientFundsInfo) => void;
|
|
281
|
+
};
|
|
282
|
+
type ProxyHandle = {
|
|
283
|
+
port: number;
|
|
284
|
+
baseUrl: string;
|
|
285
|
+
walletAddress: string;
|
|
286
|
+
balanceMonitor: BalanceMonitor;
|
|
287
|
+
close: () => Promise<void>;
|
|
288
|
+
};
|
|
289
|
+
/**
|
|
290
|
+
* Start the local mnemospark backend proxy server.
|
|
291
|
+
*
|
|
292
|
+
* If a proxy is already running on the target port, reuses it instead of failing.
|
|
293
|
+
* Port can be configured via MNEMOSPARK_PROXY_PORT environment variable.
|
|
294
|
+
*
|
|
295
|
+
* Returns a handle with the assigned port, base URL, and a close function.
|
|
296
|
+
*/
|
|
297
|
+
declare function startProxy(options: ProxyOptions): Promise<ProxyHandle>;
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Payment Parameter Cache
|
|
301
|
+
*
|
|
302
|
+
* Caches the 402 payment parameters (payTo, asset, network, etc.) after the first
|
|
303
|
+
* request to each endpoint. On subsequent requests, pre-signs the payment and
|
|
304
|
+
* attaches it to the first request, skipping the 402 round trip (~200ms savings).
|
|
305
|
+
*/
|
|
306
|
+
type CachedPaymentParams = {
|
|
307
|
+
payTo: string;
|
|
308
|
+
asset: string;
|
|
309
|
+
scheme: string;
|
|
310
|
+
network: string;
|
|
311
|
+
extra?: {
|
|
312
|
+
name?: string;
|
|
313
|
+
version?: string;
|
|
314
|
+
};
|
|
315
|
+
maxTimeoutSeconds?: number;
|
|
316
|
+
resourceUrl?: string;
|
|
317
|
+
resourceDescription?: string;
|
|
318
|
+
cachedAt: number;
|
|
319
|
+
};
|
|
320
|
+
declare class PaymentCache {
|
|
321
|
+
private cache;
|
|
322
|
+
private ttlMs;
|
|
323
|
+
constructor(ttlMs?: number);
|
|
324
|
+
/** Get cached payment params for an endpoint path. */
|
|
325
|
+
get(endpointPath: string): CachedPaymentParams | undefined;
|
|
326
|
+
/** Cache payment params from a 402 response. */
|
|
327
|
+
set(endpointPath: string, params: Omit<CachedPaymentParams, "cachedAt">): void;
|
|
328
|
+
/** Invalidate cache for an endpoint (e.g., if payTo changed). */
|
|
329
|
+
invalidate(endpointPath: string): void;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* x402 Payment Implementation
|
|
334
|
+
*
|
|
335
|
+
* Based on BlockRun's proven implementation.
|
|
336
|
+
* Handles 402 Payment Required responses with EIP-712 signed USDC transfers.
|
|
337
|
+
*
|
|
338
|
+
* Optimizations (v0.3.0):
|
|
339
|
+
* - Payment cache: after first 402, caches {payTo, asset, network} per endpoint.
|
|
340
|
+
* On subsequent requests, pre-signs payment and sends with first request,
|
|
341
|
+
* skipping the 402 round trip (~200ms savings).
|
|
342
|
+
* - Falls back to normal 402 flow if pre-signed payment is rejected.
|
|
343
|
+
*/
|
|
344
|
+
|
|
345
|
+
/** Pre-auth parameters for skipping the 402 round trip. */
|
|
346
|
+
type PreAuthParams = {
|
|
347
|
+
estimatedAmount: string;
|
|
348
|
+
};
|
|
349
|
+
/** Result from createPaymentFetch — includes the fetch wrapper and payment cache. */
|
|
350
|
+
type PaymentFetchResult = {
|
|
351
|
+
fetch: (input: RequestInfo | URL, init?: RequestInit, preAuth?: PreAuthParams) => Promise<Response>;
|
|
352
|
+
cache: PaymentCache;
|
|
353
|
+
};
|
|
354
|
+
/**
|
|
355
|
+
* Create a fetch wrapper that handles x402 payment automatically.
|
|
356
|
+
*
|
|
357
|
+
* Supports pre-auth: if cached payment params + estimated amount are available,
|
|
358
|
+
* pre-signs and attaches payment to the first request, skipping the 402 round trip.
|
|
359
|
+
* Falls back to normal 402 flow if pre-signed payment is rejected.
|
|
360
|
+
*/
|
|
361
|
+
declare function createPaymentFetch(privateKey: `0x${string}`): PaymentFetchResult;
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Typed Error Classes for mnemospark
|
|
365
|
+
*
|
|
366
|
+
* Provides structured errors for balance-related failures with
|
|
367
|
+
* all necessary information for user-friendly error messages.
|
|
368
|
+
*/
|
|
369
|
+
/**
|
|
370
|
+
* Thrown when wallet has insufficient USDC balance for a request.
|
|
371
|
+
*/
|
|
372
|
+
declare class InsufficientFundsError extends Error {
|
|
373
|
+
readonly code: "INSUFFICIENT_FUNDS";
|
|
374
|
+
readonly currentBalanceUSD: string;
|
|
375
|
+
readonly requiredUSD: string;
|
|
376
|
+
readonly walletAddress: string;
|
|
377
|
+
constructor(opts: {
|
|
378
|
+
currentBalanceUSD: string;
|
|
379
|
+
requiredUSD: string;
|
|
380
|
+
walletAddress: string;
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Thrown when wallet has no USDC balance (or effectively zero).
|
|
385
|
+
*/
|
|
386
|
+
declare class EmptyWalletError extends Error {
|
|
387
|
+
readonly code: "EMPTY_WALLET";
|
|
388
|
+
readonly walletAddress: string;
|
|
389
|
+
constructor(walletAddress: string);
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Type guard to check if an error is InsufficientFundsError.
|
|
393
|
+
*/
|
|
394
|
+
declare function isInsufficientFundsError(error: unknown): error is InsufficientFundsError;
|
|
395
|
+
/**
|
|
396
|
+
* Type guard to check if an error is EmptyWalletError.
|
|
397
|
+
*/
|
|
398
|
+
declare function isEmptyWalletError(error: unknown): error is EmptyWalletError;
|
|
399
|
+
/**
|
|
400
|
+
* Type guard to check if an error is a balance-related error.
|
|
401
|
+
*/
|
|
402
|
+
declare function isBalanceError(error: unknown): error is InsufficientFundsError | EmptyWalletError;
|
|
403
|
+
/**
|
|
404
|
+
* Thrown when RPC call fails (network error, node down, etc).
|
|
405
|
+
* Distinguishes infrastructure failures from actual empty wallets.
|
|
406
|
+
*/
|
|
407
|
+
declare class RpcError extends Error {
|
|
408
|
+
readonly code: "RPC_ERROR";
|
|
409
|
+
readonly originalError: unknown;
|
|
410
|
+
constructor(message: string, originalError?: unknown);
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Type guard to check if an error is RpcError.
|
|
414
|
+
*/
|
|
415
|
+
declare function isRpcError(error: unknown): error is RpcError;
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Retry Logic for mnemospark
|
|
419
|
+
*
|
|
420
|
+
* Provides fetch wrapper with exponential backoff for transient errors.
|
|
421
|
+
* Retries on 429 (rate limit), 502, 503, 504 (server errors).
|
|
422
|
+
*/
|
|
423
|
+
/** Configuration for retry behavior */
|
|
424
|
+
type RetryConfig = {
|
|
425
|
+
/** Maximum number of retries (default: 2) */
|
|
426
|
+
maxRetries: number;
|
|
427
|
+
/** Base delay in ms for exponential backoff (default: 500) */
|
|
428
|
+
baseDelayMs: number;
|
|
429
|
+
/** HTTP status codes that trigger a retry (default: [429, 502, 503, 504]) */
|
|
430
|
+
retryableCodes: number[];
|
|
431
|
+
};
|
|
432
|
+
/** Default retry configuration */
|
|
433
|
+
declare const DEFAULT_RETRY_CONFIG: RetryConfig;
|
|
434
|
+
/**
|
|
435
|
+
* Wrap a fetch-like function with retry logic and exponential backoff.
|
|
436
|
+
*
|
|
437
|
+
* @param fetchFn - The fetch function to wrap (can be standard fetch or x402 payFetch)
|
|
438
|
+
* @param url - URL to fetch
|
|
439
|
+
* @param init - Fetch init options
|
|
440
|
+
* @param config - Retry configuration (optional, uses defaults)
|
|
441
|
+
* @returns Response from successful fetch or last failed attempt
|
|
442
|
+
*
|
|
443
|
+
* @example
|
|
444
|
+
* ```typescript
|
|
445
|
+
* const response = await fetchWithRetry(
|
|
446
|
+
* fetch,
|
|
447
|
+
* "https://api.example.com/endpoint",
|
|
448
|
+
* { method: "POST", body: JSON.stringify(data) },
|
|
449
|
+
* { maxRetries: 3 }
|
|
450
|
+
* );
|
|
451
|
+
* ```
|
|
452
|
+
*/
|
|
453
|
+
declare function fetchWithRetry(fetchFn: (url: string, init?: RequestInit) => Promise<Response>, url: string, init?: RequestInit, config?: Partial<RetryConfig>): Promise<Response>;
|
|
454
|
+
/**
|
|
455
|
+
* Check if an error or response indicates a retryable condition.
|
|
456
|
+
*/
|
|
457
|
+
declare function isRetryable(errorOrResponse: Error | Response, config?: Partial<RetryConfig>): boolean;
|
|
458
|
+
|
|
459
|
+
type PriceStorageQuoteRequest = {
|
|
460
|
+
wallet_address: string;
|
|
461
|
+
object_id: string;
|
|
462
|
+
object_id_hash: string;
|
|
463
|
+
gb: number;
|
|
464
|
+
provider: string;
|
|
465
|
+
region: string;
|
|
466
|
+
};
|
|
467
|
+
type PriceStorageQuoteResponse = {
|
|
468
|
+
timestamp: string;
|
|
469
|
+
quote_id: string;
|
|
470
|
+
storage_price: number;
|
|
471
|
+
addr: string;
|
|
472
|
+
object_id: string;
|
|
473
|
+
object_id_hash: string;
|
|
474
|
+
object_size_gb: number;
|
|
475
|
+
provider: string;
|
|
476
|
+
location: string;
|
|
477
|
+
};
|
|
478
|
+
type UploadPayload = {
|
|
479
|
+
mode: "inline" | "presigned";
|
|
480
|
+
content_base64?: string;
|
|
481
|
+
content_sha256: string;
|
|
482
|
+
content_length_bytes: number;
|
|
483
|
+
wrapped_dek: string;
|
|
484
|
+
encryption_algorithm: "AES-256-GCM";
|
|
485
|
+
bucket_name_hint: string;
|
|
486
|
+
key_store_path_hint: string;
|
|
487
|
+
};
|
|
488
|
+
type StorageUploadRequest = {
|
|
489
|
+
quote_id: string;
|
|
490
|
+
wallet_address: string;
|
|
491
|
+
object_id: string;
|
|
492
|
+
object_id_hash: string;
|
|
493
|
+
quoted_storage_price: number;
|
|
494
|
+
payload: UploadPayload;
|
|
495
|
+
};
|
|
496
|
+
type StorageUploadResponse = {
|
|
497
|
+
quote_id: string;
|
|
498
|
+
addr: string;
|
|
499
|
+
addr_hash?: string;
|
|
500
|
+
trans_id?: string;
|
|
501
|
+
storage_price?: number;
|
|
502
|
+
object_id: string;
|
|
503
|
+
object_key: string;
|
|
504
|
+
provider: string;
|
|
505
|
+
bucket_name: string;
|
|
506
|
+
location: string;
|
|
507
|
+
upload_url?: string;
|
|
508
|
+
upload_headers?: Record<string, string>;
|
|
509
|
+
};
|
|
510
|
+
type FetchLike$2 = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
511
|
+
type ProxyQuoteOptions = {
|
|
512
|
+
proxyBaseUrl?: string;
|
|
513
|
+
fetchImpl?: FetchLike$2;
|
|
514
|
+
};
|
|
515
|
+
type ProxyUploadOptions = {
|
|
516
|
+
proxyBaseUrl?: string;
|
|
517
|
+
fetchImpl?: FetchLike$2;
|
|
518
|
+
idempotencyKey?: string;
|
|
519
|
+
};
|
|
520
|
+
|
|
521
|
+
type StorageObjectRequest = {
|
|
522
|
+
wallet_address: string;
|
|
523
|
+
object_key: string;
|
|
524
|
+
location?: string;
|
|
525
|
+
};
|
|
526
|
+
type StorageLsResponse = {
|
|
527
|
+
success: boolean;
|
|
528
|
+
key: string;
|
|
529
|
+
size_bytes: number;
|
|
530
|
+
bucket: string;
|
|
531
|
+
object_id?: string;
|
|
532
|
+
};
|
|
533
|
+
type StorageDeleteResponse = {
|
|
534
|
+
success: boolean;
|
|
535
|
+
key: string;
|
|
536
|
+
bucket: string;
|
|
537
|
+
bucket_deleted: boolean;
|
|
538
|
+
};
|
|
539
|
+
type StorageDownloadProxyResponse = {
|
|
540
|
+
success: boolean;
|
|
541
|
+
key: string;
|
|
542
|
+
file_path: string;
|
|
543
|
+
};
|
|
544
|
+
type FetchLike$1 = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
545
|
+
type ProxyStorageOptions = {
|
|
546
|
+
proxyBaseUrl?: string;
|
|
547
|
+
fetchImpl?: FetchLike$1;
|
|
548
|
+
};
|
|
549
|
+
|
|
550
|
+
type FetchLike = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
551
|
+
type BackupObjectOptions = {
|
|
552
|
+
platform?: NodeJS.Platform;
|
|
553
|
+
tmpDir?: string;
|
|
554
|
+
homeDir?: string;
|
|
555
|
+
now?: () => number;
|
|
556
|
+
randomBytes?: (size: number) => Buffer;
|
|
557
|
+
availableDiskBytes?: number;
|
|
558
|
+
};
|
|
559
|
+
type BackupObjectResult = {
|
|
560
|
+
objectId: string;
|
|
561
|
+
objectIdHash: string;
|
|
562
|
+
objectSizeGb: string;
|
|
563
|
+
archivePath: string;
|
|
564
|
+
objectLogPath: string;
|
|
565
|
+
};
|
|
566
|
+
type CreateCloudCommandOptions = {
|
|
567
|
+
backupOptions?: BackupObjectOptions;
|
|
568
|
+
buildBackupObjectFn?: (targetPath: string, options?: BackupObjectOptions) => Promise<BackupObjectResult>;
|
|
569
|
+
requestPriceStorageQuoteFn?: (request: PriceStorageQuoteRequest, options?: ProxyQuoteOptions) => Promise<PriceStorageQuoteResponse>;
|
|
570
|
+
requestStorageUploadFn?: (request: StorageUploadRequest, options?: ProxyUploadOptions) => Promise<StorageUploadResponse>;
|
|
571
|
+
resolveWalletPrivateKeyFn?: (homeDir?: string) => Promise<`0x${string}`>;
|
|
572
|
+
createPaymentFetchFn?: (privateKey: `0x${string}`) => PaymentFetchResult;
|
|
573
|
+
fetchImpl?: FetchLike;
|
|
574
|
+
nowDateFn?: () => Date;
|
|
575
|
+
idempotencyKeyFn?: () => string;
|
|
576
|
+
proxyQuoteOptions?: ProxyQuoteOptions;
|
|
577
|
+
proxyUploadOptions?: ProxyUploadOptions;
|
|
578
|
+
requestStorageLsFn?: (request: StorageObjectRequest, options?: ProxyStorageOptions) => Promise<StorageLsResponse>;
|
|
579
|
+
requestStorageDownloadFn?: (request: StorageObjectRequest, options?: ProxyStorageOptions) => Promise<StorageDownloadProxyResponse>;
|
|
580
|
+
requestStorageDeleteFn?: (request: StorageObjectRequest, options?: ProxyStorageOptions) => Promise<StorageDeleteResponse>;
|
|
581
|
+
proxyStorageOptions?: ProxyStorageOptions;
|
|
582
|
+
objectLogHomeDir?: string;
|
|
583
|
+
};
|
|
584
|
+
declare function createCloudCommand(options?: CreateCloudCommandOptions): OpenClawPluginCommandDefinition;
|
|
585
|
+
|
|
586
|
+
/**
|
|
587
|
+
* mnemospark plugin entrypoint.
|
|
588
|
+
*
|
|
589
|
+
* This plugin provides wallet and cloud storage commands and starts a local
|
|
590
|
+
* proxy that forwards mnemospark backend storage endpoints.
|
|
591
|
+
*/
|
|
592
|
+
|
|
593
|
+
declare const plugin: OpenClawPluginDefinition;
|
|
594
|
+
|
|
595
|
+
export { BALANCE_THRESHOLDS, type BalanceInfo, BalanceMonitor, type CachedPaymentParams, DEFAULT_RETRY_CONFIG, EmptyWalletError, InsufficientFundsError, type InsufficientFundsInfo, type LowBalanceInfo, PaymentCache, type PaymentFetchResult, type PreAuthParams, type ProxyHandle, type ProxyOptions, type RetryConfig, RpcError, type SufficiencyResult, createCloudCommand, createPaymentFetch, plugin as default, fetchWithRetry, getProxyPort, isBalanceError, isEmptyWalletError, isInsufficientFundsError, isRetryable, isRpcError, startProxy };
|