@lucid-agents/taskmarket 1.25.0 → 1.26.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/dist/THIRD_PARTY_NOTICES.md +224 -122
- package/dist/agent-compatibility.json +1 -1
- package/dist/api-H7VPA6C6.js +35 -0
- package/dist/{channels-CNVUFGAL.js → channels-4IFPTRDY.js} +5 -4
- package/dist/{chunk-GBQBHJ77.js → chunk-2AJZDGEL.js} +1 -45
- package/dist/{chunk-OZUGI2FO.js → chunk-CNWA5PU3.js} +1 -1
- package/dist/{chunk-SBCQA7NQ.js → chunk-FMK32RJF.js} +11 -127
- package/dist/{chunk-VSAHZTWA.js → chunk-GT5TOHOY.js} +5 -5
- package/dist/chunk-NTLOY7SP.js +46 -0
- package/dist/chunk-PJAWRHHZ.js +39 -0
- package/dist/chunk-Q2FZSDFG.js +933 -0
- package/dist/{chunk-KW2FNQFI.js → chunk-RPGVVVJD.js} +6 -6
- package/dist/chunk-VTMYCZLT.js +17003 -0
- package/dist/{chunk-DOI4ACQ4.js → chunk-XV6DBK4C.js} +42 -18
- package/dist/{chunk-ZS4DVWW2.js → chunk-YAKNCBUK.js} +90 -84
- package/dist/{chunk-HTJ7WSAL.js → chunk-YIOZ7W3M.js} +9 -7
- package/dist/{doctor-FDTAT6OD.js → doctor-HENBO5YV.js} +11 -19
- package/dist/index.js +16586 -5259
- package/dist/{launch-B7DBYHZD.js → launch-DMKAPDO4.js} +73 -46
- package/dist/pi-extensions/remote-tools.cjs +4 -4
- package/dist/pi-extensions/xgate.cjs +4283 -325
- package/dist/read-auth-26D4BRUP.js +10 -0
- package/dist/{reconcile-RSDLDHIA.js → reconcile-6A5U2Q7Q.js} +7 -6
- package/dist/{status-YFWORML2.js → status-GRLQL23D.js} +11 -16
- package/dist/{sync-pull-JMAKIXL6.js → sync-pull-MSYWP5WU.js} +4 -3
- package/dist/task-access-grants-54GQX63L.js +13 -0
- package/package.json +8 -4
- package/dist/chunk-4WVIB4DD.js +0 -11695
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createRequire as __tmCreateRequire } from 'node:module'; import { fileURLToPath as __tmFileURLToPath } from 'node:url'; import { dirname as __tmDirname } from 'node:path'; const require = __tmCreateRequire(import.meta.url); const __tmFilename = __tmFileURLToPath(import.meta.url); const __tmDirnameValue = __tmDirname(__tmFilename);
|
|
2
|
+
import {
|
|
3
|
+
ApiError,
|
|
4
|
+
apiDelete,
|
|
5
|
+
apiGet,
|
|
6
|
+
apiOrigin,
|
|
7
|
+
apiPost,
|
|
8
|
+
apiPut,
|
|
9
|
+
apiReadPost,
|
|
10
|
+
apiUrl,
|
|
11
|
+
failureMessage,
|
|
12
|
+
isPendingApiError,
|
|
13
|
+
legalReceiptHeadersForKeystore,
|
|
14
|
+
parseFailureBody,
|
|
15
|
+
readFailureBody,
|
|
16
|
+
withErrorContext
|
|
17
|
+
} from "./chunk-Q2FZSDFG.js";
|
|
18
|
+
import "./chunk-VTMYCZLT.js";
|
|
19
|
+
import "./chunk-S7SJMJ2I.js";
|
|
20
|
+
export {
|
|
21
|
+
ApiError,
|
|
22
|
+
apiDelete,
|
|
23
|
+
apiGet,
|
|
24
|
+
apiOrigin,
|
|
25
|
+
apiPost,
|
|
26
|
+
apiPut,
|
|
27
|
+
apiReadPost,
|
|
28
|
+
apiUrl,
|
|
29
|
+
failureMessage,
|
|
30
|
+
isPendingApiError,
|
|
31
|
+
legalReceiptHeadersForKeystore,
|
|
32
|
+
parseFailureBody,
|
|
33
|
+
readFailureBody,
|
|
34
|
+
withErrorContext
|
|
35
|
+
};
|
|
@@ -10,11 +10,12 @@ import {
|
|
|
10
10
|
selectRail,
|
|
11
11
|
uncertainPurchases,
|
|
12
12
|
withdrawalHatch
|
|
13
|
-
} from "./chunk-
|
|
14
|
-
import "./chunk-
|
|
15
|
-
import "./chunk-
|
|
16
|
-
import "./chunk-
|
|
13
|
+
} from "./chunk-YIOZ7W3M.js";
|
|
14
|
+
import "./chunk-2AJZDGEL.js";
|
|
15
|
+
import "./chunk-Q2FZSDFG.js";
|
|
16
|
+
import "./chunk-VTMYCZLT.js";
|
|
17
17
|
import "./chunk-YM4S6IE4.js";
|
|
18
|
+
import "./chunk-XJOB4NMV.js";
|
|
18
19
|
import "./chunk-S7SJMJ2I.js";
|
|
19
20
|
export {
|
|
20
21
|
allocationViews,
|
|
@@ -2,16 +2,13 @@ import { createRequire as __tmCreateRequire } from 'node:module'; import { fileU
|
|
|
2
2
|
import {
|
|
3
3
|
MppTempoChargeRequestSchema,
|
|
4
4
|
TEMPO_MAX_VALIDITY_WINDOW_SECONDS,
|
|
5
|
-
apiUrl,
|
|
6
5
|
clampValidityWindowSeconds,
|
|
7
6
|
decodeMppJson,
|
|
8
|
-
decryptPrivateKey,
|
|
9
7
|
formatMppCredential,
|
|
10
8
|
getTaskmarketHome,
|
|
11
|
-
loadKeystore,
|
|
12
9
|
mppAttributionMemo,
|
|
13
10
|
parseMppChallenge
|
|
14
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-VTMYCZLT.js";
|
|
15
12
|
|
|
16
13
|
// ../../packages/x402-payer/dist/api.js
|
|
17
14
|
var X402_PAYER_API_VERSION = 1;
|
|
@@ -7470,42 +7467,6 @@ async function createMppTempoCredential(input) {
|
|
|
7470
7467
|
return { authorization, request, transaction, memo, validBefore };
|
|
7471
7468
|
}
|
|
7472
7469
|
|
|
7473
|
-
// src/lib/signer.ts
|
|
7474
|
-
import { privateKeyToAccount } from "viem/accounts";
|
|
7475
|
-
async function fetchDeviceKey(deviceId, apiToken, keyServerUrl) {
|
|
7476
|
-
const base2 = keyServerUrl ?? apiUrl();
|
|
7477
|
-
const res = await fetch(`${base2}/api/devices/${deviceId}/key`, {
|
|
7478
|
-
method: "POST",
|
|
7479
|
-
headers: { "Content-Type": "application/json" },
|
|
7480
|
-
body: JSON.stringify({ deviceId, apiToken })
|
|
7481
|
-
});
|
|
7482
|
-
if (!res.ok) {
|
|
7483
|
-
const text = await res.text().catch(() => "");
|
|
7484
|
-
throw new Error(`Failed to fetch device key (${res.status}): ${text}`);
|
|
7485
|
-
}
|
|
7486
|
-
const data = await res.json();
|
|
7487
|
-
return data.deviceEncryptionKey;
|
|
7488
|
-
}
|
|
7489
|
-
async function signTypedData(typedData, keystore) {
|
|
7490
|
-
const account = await createWalletAccountFromKeystore(keystore);
|
|
7491
|
-
const sig = await account.signTypedData(typedData);
|
|
7492
|
-
return sig;
|
|
7493
|
-
}
|
|
7494
|
-
async function signMessage(message, keystore) {
|
|
7495
|
-
const account = await createWalletAccountFromKeystore(keystore);
|
|
7496
|
-
const sig = await account.signMessage({ message });
|
|
7497
|
-
return sig;
|
|
7498
|
-
}
|
|
7499
|
-
async function createWalletAccountFromKeystore(keystore) {
|
|
7500
|
-
const dek = await fetchDeviceKey(keystore.deviceId, keystore.apiToken, keystore.keyServerUrl);
|
|
7501
|
-
const privateKey = decryptPrivateKey(dek, keystore.encryptedKey);
|
|
7502
|
-
return privateKeyToAccount(privateKey);
|
|
7503
|
-
}
|
|
7504
|
-
async function getWalletAddress() {
|
|
7505
|
-
const keystore = await loadKeystore();
|
|
7506
|
-
return keystore.walletAddress;
|
|
7507
|
-
}
|
|
7508
|
-
|
|
7509
7470
|
// src/lib/x402-paths.ts
|
|
7510
7471
|
import path5 from "path";
|
|
7511
7472
|
function getX402JournalPath() {
|
|
@@ -7549,11 +7510,6 @@ export {
|
|
|
7549
7510
|
signSponsoredTempoTransfer,
|
|
7550
7511
|
readMppTempoChallenge,
|
|
7551
7512
|
createMppTempoCredential,
|
|
7552
|
-
fetchDeviceKey,
|
|
7553
|
-
signTypedData,
|
|
7554
|
-
signMessage,
|
|
7555
|
-
createWalletAccountFromKeystore,
|
|
7556
|
-
getWalletAddress,
|
|
7557
7513
|
getX402JournalPath,
|
|
7558
7514
|
getX402PolicyPath
|
|
7559
7515
|
};
|
|
@@ -6,14 +6,14 @@ import {
|
|
|
6
6
|
loadDeliverableRecord,
|
|
7
7
|
readComputeView,
|
|
8
8
|
taskStage
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-RPGVVVJD.js";
|
|
10
10
|
import {
|
|
11
11
|
activeClaim,
|
|
12
12
|
captureProblem,
|
|
13
13
|
killedSession,
|
|
14
14
|
loadSyncState,
|
|
15
15
|
orphanOf
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-GT5TOHOY.js";
|
|
17
17
|
import {
|
|
18
18
|
allocationViews,
|
|
19
19
|
channelView,
|
|
@@ -21,22 +21,21 @@ import {
|
|
|
21
21
|
openAgentChannels,
|
|
22
22
|
uncertainPurchases,
|
|
23
23
|
withdrawalHatch
|
|
24
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-YIOZ7W3M.js";
|
|
25
25
|
import {
|
|
26
|
-
SandboxListOutputSchema,
|
|
27
26
|
apiUrl,
|
|
28
27
|
selectedNetwork
|
|
29
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-Q2FZSDFG.js";
|
|
30
29
|
import {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
channelLines,
|
|
34
|
-
computeLines,
|
|
35
|
-
formatUsdc
|
|
36
|
-
} from "./chunk-XJOB4NMV.js";
|
|
30
|
+
SandboxListOutputSchema
|
|
31
|
+
} from "./chunk-VTMYCZLT.js";
|
|
37
32
|
import {
|
|
38
33
|
AgentLaunchError
|
|
39
34
|
} from "./chunk-YM4S6IE4.js";
|
|
35
|
+
import {
|
|
36
|
+
AGENT_VIEW_VERSION,
|
|
37
|
+
blockingPurchases
|
|
38
|
+
} from "./chunk-XJOB4NMV.js";
|
|
40
39
|
|
|
41
40
|
// src/lib/agent/status.ts
|
|
42
41
|
import { promises as fs } from "fs";
|
|
@@ -244,125 +243,10 @@ async function collectAgentStatus(deps = {}) {
|
|
|
244
243
|
view.inference.blocked = reasons.length > 0;
|
|
245
244
|
return view;
|
|
246
245
|
}
|
|
247
|
-
function statusLines(view) {
|
|
248
|
-
const lines = [
|
|
249
|
-
`taskmarket agent status (view v${view.version}, ${view.generatedAt})`,
|
|
250
|
-
view.wallet ? `Wallet: ${view.wallet.address}` : "Wallet: none",
|
|
251
|
-
`Spending policy: ${view.policy.state}${view.policy.models.length ? ` (${view.policy.models.join(", ")})` : ""}${view.policy.error ? `: ${view.policy.error}` : ""}`
|
|
252
|
-
];
|
|
253
|
-
for (const channel of view.channels) {
|
|
254
|
-
lines.push(...channelLines(channel));
|
|
255
|
-
if (channel.state === "blocked" || channel.state === "withdrawal_pending") {
|
|
256
|
-
lines.push(` ${channel.withdrawal.note}`);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
if (view.purchases.uncertain.length === 0) {
|
|
260
|
-
lines.push("Purchases with an unknown outcome: none");
|
|
261
|
-
} else {
|
|
262
|
-
lines.push("Purchases with an unknown outcome (never resent; reconcile them):");
|
|
263
|
-
for (const purchase of view.purchases.uncertain) {
|
|
264
|
-
lines.push(
|
|
265
|
-
` ${purchase.invocationId} on ${purchase.rail}: ${purchase.state}, at most ${formatUsdc(purchase.authorizedAtomic)}${purchase.blocking ? ", blocks new turns" : ""}`
|
|
266
|
-
);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
lines.push(
|
|
270
|
-
view.inference.blocked ? `New inference: blocked (${view.inference.reasons.join("; ")})` : "New inference: ready"
|
|
271
|
-
);
|
|
272
|
-
if (view.sandbox.state === "ok") {
|
|
273
|
-
lines.push(
|
|
274
|
-
view.sandbox.sandboxes.length === 0 ? "Sandbox: none" : `Sandbox: ${view.sandbox.sandboxes.map(
|
|
275
|
-
(s) => `${s.sandboxId} ${s.purpose} ${s.state}${s.creditWarning ? ` (${s.creditWarning})` : ""}`
|
|
276
|
-
).join("; ")}`
|
|
277
|
-
);
|
|
278
|
-
} else if (view.sandbox.state === "unavailable") {
|
|
279
|
-
lines.push(`Sandbox: unavailable (${view.sandbox.error})`);
|
|
280
|
-
}
|
|
281
|
-
lines.push(...computeLines(view.compute));
|
|
282
|
-
lines.push(...syncLines(view.sync));
|
|
283
|
-
lines.push(...taskLines(view.task, view.taskError));
|
|
284
|
-
return lines;
|
|
285
|
-
}
|
|
286
|
-
var STAGES = {
|
|
287
|
-
claiming: "claiming (a claim may have been sent; the next session confirms it before anything else)",
|
|
288
|
-
claimed: "claimed (the task workspace is not set up yet)",
|
|
289
|
-
working: "working (workspace ready, not validated yet)",
|
|
290
|
-
frozen: "frozen (validated, waiting for your approval to submit)",
|
|
291
|
-
submitting: "submitting (sent; the next session looks it up before anything is sent again)",
|
|
292
|
-
submitted: "submitted (not yet accepted or paid)",
|
|
293
|
-
awaiting_acceptance: "awaiting acceptance (submitted; the requester or evaluator decides)",
|
|
294
|
-
reward_pending: "reward pending (awarded; the payout is not verified on the chain yet)",
|
|
295
|
-
paid: "paid (the payout is verified on the chain)",
|
|
296
|
-
rejected: "rejected (no reward)",
|
|
297
|
-
expired: "expired (ended without an award; no reward)",
|
|
298
|
-
stopped: "stopped"
|
|
299
|
-
};
|
|
300
|
-
function taskLines(task, error) {
|
|
301
|
-
if (error) return [`Marketplace task: the run state cannot be read (${error})`];
|
|
302
|
-
if (!task) return ["Marketplace task: none"];
|
|
303
|
-
const lines = [`Marketplace task ${task.taskId} on ${task.network}: ${STAGES[task.stage]}`];
|
|
304
|
-
if (task.claimId) lines.push(` Claim: ${task.claimId}`);
|
|
305
|
-
if (task.workspace) lines.push(` Workspace (in the sandbox): ${task.workspace}`);
|
|
306
|
-
if (task.validation) {
|
|
307
|
-
lines.push(
|
|
308
|
-
` Validation: ${task.validation.attemptsUsed} of ${task.validation.maxAttempts} attempt(s) used, until ${task.validation.deadline}`
|
|
309
|
-
);
|
|
310
|
-
}
|
|
311
|
-
if (task.deliverableId) lines.push(` Deliverable: ${task.deliverableId}`);
|
|
312
|
-
if (task.submissionId) lines.push(` Submission: ${task.submissionId}`);
|
|
313
|
-
const outcome = task.outcome;
|
|
314
|
-
if (outcome?.payout) {
|
|
315
|
-
lines.push(
|
|
316
|
-
` Paid: ${outcome.payout.amount} atomic units of ${outcome.payout.asset} in ${outcome.payout.settlementTxHash}`
|
|
317
|
-
);
|
|
318
|
-
} else if (outcome?.award) {
|
|
319
|
-
lines.push(
|
|
320
|
-
` Award: ${outcome.award.workerPayment} atomic units of ${outcome.award.asset}, not verified (${outcome.unverified?.reason ?? "unverified"})`
|
|
321
|
-
);
|
|
322
|
-
}
|
|
323
|
-
if (outcome) lines.push(` Outcome observed ${outcome.observedAt}`);
|
|
324
|
-
lines.push(` As recorded ${task.updatedAt}`);
|
|
325
|
-
return lines;
|
|
326
|
-
}
|
|
327
|
-
function syncLines(sync) {
|
|
328
|
-
if (!sync.project) return ["Workspace sync: this directory cannot be read"];
|
|
329
|
-
const lines = [
|
|
330
|
-
`Workspace sync (${sync.project}): ${sync.approved ? `upload approved ${sync.approvedAt}` : "upload not approved yet"}${sync.sessionRunning ? "; a session is running here" : ""}`
|
|
331
|
-
];
|
|
332
|
-
if (sync.lastUploadAt) {
|
|
333
|
-
lines.push(` Last upload: ${sync.lastUploadAt} (${sync.uploadedFiles ?? 0} file(s))`);
|
|
334
|
-
}
|
|
335
|
-
if (sync.lastPullAt) lines.push(` Last pull: ${sync.lastPullAt}`);
|
|
336
|
-
if (sync.pending) {
|
|
337
|
-
const { clean, conflict, blocked } = sync.pending;
|
|
338
|
-
const notSaved = sync.pending.notSaved ?? 0;
|
|
339
|
-
const tooDeep = sync.pending.tooDeep ?? 0;
|
|
340
|
-
const waiting = `${clean + conflict} change(s) to pull${conflict ? ` (${conflict} in conflict)` : ""}${notSaved ? `, ${notSaved} too large to have been saved` : ""}${tooDeep ? `, ${tooDeep} director(ies) nested too deep to have been saved (taskmarket agent pull --keep-local <dir> acknowledges one, --discard all)` : ""}${blocked ? `, ${blocked} blocked` : ""}`;
|
|
341
|
-
lines.push(
|
|
342
|
-
sync.pending.saved ? ` Saved from the last session: ${waiting}; review them with taskmarket agent pull` : ` In the sandbox: ${waiting}, as counted ${sync.pending.checkedAt} (not checked live, which would resume the sandbox)`
|
|
343
|
-
);
|
|
344
|
-
}
|
|
345
|
-
if (sync.orphanSandboxId) {
|
|
346
|
-
lines.push(
|
|
347
|
-
` A killed --no-sync session left sandbox ${sync.orphanSandboxId}: taskmarket agent pull --recover brings back what the agent made there, until it stops once idle.`
|
|
348
|
-
);
|
|
349
|
-
}
|
|
350
|
-
if (sync.captureFailed) {
|
|
351
|
-
const failed = sync.captureFailed;
|
|
352
|
-
const where = failed.sandboxId ? ` (sandbox ${failed.sandboxId})` : "";
|
|
353
|
-
lines.push(
|
|
354
|
-
failed.kind === "interrupted" ? ` The last session ended at ${failed.at} before its changes were saved${where}: recover them with taskmarket agent pull --recover, or drop them with taskmarket agent pull --discard. New sessions wait until then.` : ` The last session's changes could not be saved${where}: ${failed.reason}. Recover them with taskmarket agent pull --recover, or drop them with taskmarket agent pull --discard. New sessions wait until then.`
|
|
355
|
-
);
|
|
356
|
-
}
|
|
357
|
-
return lines;
|
|
358
|
-
}
|
|
359
246
|
|
|
360
247
|
export {
|
|
361
248
|
readTaskStatus,
|
|
362
249
|
readSyncStatus,
|
|
363
250
|
listSandboxes,
|
|
364
|
-
collectAgentStatus
|
|
365
|
-
statusLines,
|
|
366
|
-
taskLines,
|
|
367
|
-
syncLines
|
|
251
|
+
collectAgentStatus
|
|
368
252
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire as __tmCreateRequire } from 'node:module'; import { fileURLToPath as __tmFileURLToPath } from 'node:url'; import { dirname as __tmDirname } from 'node:path'; const require = __tmCreateRequire(import.meta.url); const __tmFilename = __tmFileURLToPath(import.meta.url); const __tmDirnameValue = __tmDirname(__tmFilename);
|
|
2
2
|
import {
|
|
3
3
|
getTaskmarketHome
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-VTMYCZLT.js";
|
|
5
5
|
import {
|
|
6
6
|
AgentLaunchError
|
|
7
7
|
} from "./chunk-YM4S6IE4.js";
|
|
@@ -24404,8 +24404,8 @@ var SshSandboxBackend = class {
|
|
|
24404
24404
|
get isConnected() {
|
|
24405
24405
|
return !!this.conn && !this.conn.closed;
|
|
24406
24406
|
}
|
|
24407
|
-
log(message) {
|
|
24408
|
-
this.options.log?.(message);
|
|
24407
|
+
log(message, level = "error") {
|
|
24408
|
+
this.options.log?.(message, level);
|
|
24409
24409
|
}
|
|
24410
24410
|
async connect(signal) {
|
|
24411
24411
|
await this.ensure(signal);
|
|
@@ -24458,13 +24458,13 @@ var SshSandboxBackend = class {
|
|
|
24458
24458
|
this.info = { label: `${this.user}@${endpoint.host} (${this.root})` };
|
|
24459
24459
|
this.failure = void 0;
|
|
24460
24460
|
this.lastHeartbeat = Date.now();
|
|
24461
|
-
this.log(`${this.dialed ? "Reconnected" : "Connected"} to the sandbox at ${endpoint.host}
|
|
24461
|
+
this.log(`${this.dialed ? "Reconnected" : "Connected"} to the sandbox at ${endpoint.host}`, "info");
|
|
24462
24462
|
this.dialed = true;
|
|
24463
24463
|
conn.onClose(() => {
|
|
24464
24464
|
if (this.conn === conn) {
|
|
24465
24465
|
this.conn = void 0;
|
|
24466
24466
|
this.files = void 0;
|
|
24467
|
-
this.log("The sandbox connection closed; the next tool call reconnects");
|
|
24467
|
+
this.log("The sandbox connection closed; the next tool call reconnects", "info");
|
|
24468
24468
|
}
|
|
24469
24469
|
});
|
|
24470
24470
|
return { conn, files };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { createRequire as __tmCreateRequire } from 'node:module'; import { fileURLToPath as __tmFileURLToPath } from 'node:url'; import { dirname as __tmDirname } from 'node:path'; const require = __tmCreateRequire(import.meta.url); const __tmFilename = __tmFileURLToPath(import.meta.url); const __tmDirnameValue = __tmDirname(__tmFilename);
|
|
2
|
+
import {
|
|
3
|
+
TASK_ACCESS_GRANT_HEADER,
|
|
4
|
+
getTaskmarketHome
|
|
5
|
+
} from "./chunk-VTMYCZLT.js";
|
|
6
|
+
|
|
7
|
+
// src/lib/task-access-grants.ts
|
|
8
|
+
import { promises as fs } from "fs";
|
|
9
|
+
import path from "path";
|
|
10
|
+
function getGrantsPath() {
|
|
11
|
+
return path.join(getTaskmarketHome(), "task-access-grants.json");
|
|
12
|
+
}
|
|
13
|
+
async function readGrantsFile() {
|
|
14
|
+
try {
|
|
15
|
+
const raw = await fs.readFile(getGrantsPath(), "utf-8");
|
|
16
|
+
return JSON.parse(raw);
|
|
17
|
+
} catch {
|
|
18
|
+
return {};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
async function loadTaskAccessGrant(taskId) {
|
|
22
|
+
const grants = await readGrantsFile();
|
|
23
|
+
const record = grants[taskId];
|
|
24
|
+
if (!record) return null;
|
|
25
|
+
if (new Date(record.expiresAt).getTime() <= Date.now()) return null;
|
|
26
|
+
return record.grant;
|
|
27
|
+
}
|
|
28
|
+
async function taskAccessGrantHeaders(taskId) {
|
|
29
|
+
const grant = await loadTaskAccessGrant(taskId);
|
|
30
|
+
return grant ? { [TASK_ACCESS_GRANT_HEADER]: grant } : {};
|
|
31
|
+
}
|
|
32
|
+
async function saveTaskAccessGrant(taskId, grant, expiresAt) {
|
|
33
|
+
const grants = await readGrantsFile();
|
|
34
|
+
grants[taskId] = { grant, expiresAt };
|
|
35
|
+
const dir = path.dirname(getGrantsPath());
|
|
36
|
+
await fs.mkdir(dir, { recursive: true });
|
|
37
|
+
await fs.writeFile(getGrantsPath(), JSON.stringify(grants, null, 2), {
|
|
38
|
+
mode: 384
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export {
|
|
43
|
+
loadTaskAccessGrant,
|
|
44
|
+
taskAccessGrantHeaders,
|
|
45
|
+
saveTaskAccessGrant
|
|
46
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { createRequire as __tmCreateRequire } from 'node:module'; import { fileURLToPath as __tmFileURLToPath } from 'node:url'; import { dirname as __tmDirname } from 'node:path'; const require = __tmCreateRequire(import.meta.url); const __tmFilename = __tmFileURLToPath(import.meta.url); const __tmDirnameValue = __tmDirname(__tmFilename);
|
|
2
|
+
import {
|
|
3
|
+
createWalletAccountFromKeystore,
|
|
4
|
+
loadKeystore
|
|
5
|
+
} from "./chunk-Q2FZSDFG.js";
|
|
6
|
+
import {
|
|
7
|
+
READ_AUTH_ADDRESS_HEADER,
|
|
8
|
+
READ_AUTH_SIGNATURE_HEADER,
|
|
9
|
+
buildReadAuthMessage
|
|
10
|
+
} from "./chunk-VTMYCZLT.js";
|
|
11
|
+
|
|
12
|
+
// src/lib/read-auth.ts
|
|
13
|
+
async function signReadAuth() {
|
|
14
|
+
let keystore;
|
|
15
|
+
try {
|
|
16
|
+
keystore = await loadKeystore();
|
|
17
|
+
} catch {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
const account = await createWalletAccountFromKeystore(keystore);
|
|
22
|
+
const signature = await account.signMessage({
|
|
23
|
+
message: buildReadAuthMessage(keystore.walletAddress)
|
|
24
|
+
});
|
|
25
|
+
return {
|
|
26
|
+
walletAddress: keystore.walletAddress,
|
|
27
|
+
headers: {
|
|
28
|
+
[READ_AUTH_ADDRESS_HEADER]: keystore.walletAddress,
|
|
29
|
+
[READ_AUTH_SIGNATURE_HEADER]: signature
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
} catch {
|
|
33
|
+
return { walletAddress: keystore.walletAddress, headers: {} };
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export {
|
|
38
|
+
signReadAuth
|
|
39
|
+
};
|