@tetsuo-ai/marketplace-react 0.4.0 → 0.5.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/CHANGELOG.md +78 -0
- package/README.md +93 -47
- package/dist/chunk-7NKRSPPN.js +227 -0
- package/dist/chunk-7NKRSPPN.js.map +1 -0
- package/dist/{chunk-BNILOX3O.js → chunk-CDDHUFMG.js} +38 -6
- package/dist/chunk-CDDHUFMG.js.map +1 -0
- package/dist/chunk-FIDFPM5A.cjs +40 -0
- package/dist/chunk-FIDFPM5A.cjs.map +1 -0
- package/dist/chunk-IJKWKY4H.cjs +1370 -0
- package/dist/chunk-IJKWKY4H.cjs.map +1 -0
- package/dist/chunk-JTSG5FGC.cjs +397 -0
- package/dist/chunk-JTSG5FGC.cjs.map +1 -0
- package/dist/chunk-ONC6L3IX.cjs +97 -0
- package/dist/chunk-ONC6L3IX.cjs.map +1 -0
- package/dist/chunk-R76EUYDI.cjs +233 -0
- package/dist/chunk-R76EUYDI.cjs.map +1 -0
- package/dist/chunk-RG5JZ6JL.js +378 -0
- package/dist/chunk-RG5JZ6JL.js.map +1 -0
- package/dist/components/index.cjs +158 -1513
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.d.cts +2 -2
- package/dist/components/index.d.ts +2 -2
- package/dist/components/index.js +2 -2
- package/dist/hooks/index.cjs +693 -457
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +109 -28
- package/dist/hooks/index.d.ts +109 -28
- package/dist/hooks/index.js +659 -178
- package/dist/hooks/index.js.map +1 -1
- package/dist/{index-DQ3Xovkq.d.ts → index-BAyr1ODZ.d.ts} +76 -6
- package/dist/{index-UxuvIlmD.d.cts → index-C20NVU7_.d.cts} +76 -6
- package/dist/index.cjs +284 -1752
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -8
- package/dist/index.d.ts +7 -8
- package/dist/index.js +64 -4
- package/dist/index.js.map +1 -1
- package/dist/signers/index.cjs +22 -161
- package/dist/signers/index.cjs.map +1 -1
- package/dist/signers/index.d.cts +16 -11
- package/dist/signers/index.d.ts +16 -11
- package/dist/signers/index.js +1 -1
- package/dist/testing/index.d.cts +1 -1
- package/dist/testing/index.d.ts +1 -1
- package/dist/theme/agenc-tailwind-preset.cjs +134 -108
- package/dist/{types-jvISR6bc.d.cts → types-B10rndEI.d.cts} +16 -7
- package/dist/{types-jvISR6bc.d.ts → types-B10rndEI.d.ts} +16 -7
- package/dist/{useAgentTrackRecord-BCvRHYM2.d.cts → useAgentTrackRecord-Ch7gHTFj.d.cts} +40 -3
- package/dist/{useAgentTrackRecord-BCvRHYM2.d.ts → useAgentTrackRecord-Ch7gHTFj.d.ts} +40 -3
- package/package.json +6 -3
- package/src/components/GuaranteedBadge.tsx +73 -0
- package/src/components/HireCheckoutModal.tsx +5 -2
- package/src/components/index.ts +4 -0
- package/src/components/strings.ts +8 -0
- package/src/hooks/index.ts +14 -0
- package/src/hooks/internal.ts +179 -22
- package/src/hooks/useAgentTrackRecord.ts +5 -2
- package/src/hooks/useCompletionBond.ts +191 -0
- package/src/hooks/useDispute.ts +46 -9
- package/src/hooks/useHire.ts +113 -23
- package/src/hooks/useHumanlessHireFlow.ts +335 -115
- package/src/hooks/useListing.ts +2 -2
- package/src/hooks/useListings.ts +2 -2
- package/src/hooks/useRateHire.ts +32 -5
- package/src/hooks/useReferrerEarnings.ts +4 -1
- package/src/hooks/useSubmissionReview.ts +95 -32
- package/src/hooks/useTaskActivation.ts +51 -9
- package/src/hooks/useTaskGuarantee.ts +123 -0
- package/src/hooks/useTaskLifecycle.ts +104 -24
- package/src/hooks/useTaskStatus.ts +121 -26
- package/src/hooks/useTaskWork.ts +76 -12
- package/src/hooks/useWalletSigner.ts +11 -16
- package/src/index.ts +5 -0
- package/src/provider/AgencProvider.tsx +95 -3
- package/src/provider/referrer.ts +1 -1
- package/src/signers/README.md +13 -7
- package/src/signers/index.ts +6 -1
- package/src/signers/strings.ts +13 -1
- package/src/signers/types.ts +16 -5
- package/src/signers/wallet-account.ts +115 -29
- package/src/signers/wallet-adapter.ts +38 -4
- package/src/theme/agenc-tailwind-preset.cjs +134 -108
- package/src/types.ts +32 -3
- package/dist/chunk-BNILOX3O.js.map +0 -1
- package/dist/chunk-BTAVED7S.js +0 -226
- package/dist/chunk-BTAVED7S.js.map +0 -1
- package/dist/chunk-ON6XR4XO.js +0 -128
- package/dist/chunk-ON6XR4XO.js.map +0 -1
package/dist/hooks/index.cjs
CHANGED
|
@@ -1,123 +1,20 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var chunkONC6L3IX_cjs = require('../chunk-ONC6L3IX.cjs');
|
|
4
|
+
var chunkJTSG5FGC_cjs = require('../chunk-JTSG5FGC.cjs');
|
|
5
|
+
var chunkFIDFPM5A_cjs = require('../chunk-FIDFPM5A.cjs');
|
|
3
6
|
var reactQuery = require('@tanstack/react-query');
|
|
4
7
|
var react = require('react');
|
|
5
|
-
var kit = require('@solana/kit');
|
|
6
8
|
var marketplaceSdk = require('@tetsuo-ai/marketplace-sdk');
|
|
9
|
+
var kit = require('@solana/kit');
|
|
7
10
|
|
|
8
|
-
// src/hooks/useListings.ts
|
|
9
|
-
|
|
10
|
-
// src/strings/index.ts
|
|
11
|
-
var EN_STRINGS = {
|
|
12
|
-
// Provider / context wiring errors (developer-facing, but routed for parity).
|
|
13
|
-
"provider.missingContext": "useAgencContext must be used within <AgencProvider>.",
|
|
14
|
-
"provider.missingWriteClient": "No write client is configured. Pass config.client, or config.rpcUrl + config.signer, to <AgencProvider> before using a mutating hook.",
|
|
15
|
-
"provider.missingSigner": "No signer is configured on <AgencProvider>. Connect a wallet or pass config.signer.",
|
|
16
|
-
// Referrer config validation / capability surface.
|
|
17
|
-
"referrer.invalidWallet": "Referrer wallet is not a valid base58 Solana address: {wallet}.",
|
|
18
|
-
"referrer.invalidFeeBps": "Referrer feeBps must be an integer between {min} and {max} (basis points); got {feeBps}.",
|
|
19
|
-
"referrer.notLive": "Referral fee is not active for this hire.",
|
|
20
|
-
"referrer.notLiveReason": "No referrer is configured for this provider.",
|
|
21
|
-
"referrer.earningsNotLiveReason": "Referral settlement is live, but no earnings endpoint is available on this network (configure indexer.baseUrl).",
|
|
22
|
-
"referrer.earningsFetchFailed": "The referrer earnings endpoint could not be read.",
|
|
23
|
-
// Read transport.
|
|
24
|
-
"transport.noReadSource": "No read source is configured. Pass an indexer baseUrl, an rpc/queryTransport, to <AgencProvider> or createReadTransport().",
|
|
25
|
-
// Generic loading / empty / error states (components extend these).
|
|
26
|
-
"state.loading": "Loading\u2026",
|
|
27
|
-
"state.empty": "Nothing to show yet.",
|
|
28
|
-
"state.error": "Something went wrong.",
|
|
29
|
-
// Hire flow shells (components fill out the rest).
|
|
30
|
-
"hire.cta": "Hire",
|
|
31
|
-
"hire.pending": "Confirming\u2026",
|
|
32
|
-
"hire.funded": "Escrow funded."
|
|
33
|
-
};
|
|
34
|
-
function t(id, vars, options) {
|
|
35
|
-
const catalog = options?.catalog ?? EN_STRINGS;
|
|
36
|
-
const template = catalog[id] ?? id;
|
|
37
|
-
return template;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// src/provider/context.ts
|
|
41
|
-
var AgencContext = react.createContext(null);
|
|
42
|
-
AgencContext.displayName = "AgencContext";
|
|
43
|
-
function useAgencContext() {
|
|
44
|
-
const ctx = react.useContext(AgencContext);
|
|
45
|
-
if (ctx === null) {
|
|
46
|
-
throw new Error(t("provider.missingContext"));
|
|
47
|
-
}
|
|
48
|
-
return ctx;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// src/hooks/internal.ts
|
|
52
|
-
var QUERY_KEY_ROOT = "agenc";
|
|
53
|
-
var queryKeys = {
|
|
54
|
-
/** All listings list queries (with their filter object as the leaf). */
|
|
55
|
-
listings: (filter) => [QUERY_KEY_ROOT, "listings", filter ?? null],
|
|
56
|
-
/** One listing + its joined provider/track-record/moderation. */
|
|
57
|
-
listing: (pda) => [QUERY_KEY_ROOT, "listing", pda],
|
|
58
|
-
/** One agent's indexer track record. */
|
|
59
|
-
agentTrackRecord: (agentPda) => [QUERY_KEY_ROOT, "agentTrackRecord", agentPda],
|
|
60
|
-
/** One task's status (read via transport / svm decode). */
|
|
61
|
-
taskStatus: (taskPda) => [QUERY_KEY_ROOT, "taskStatus", taskPda],
|
|
62
|
-
/** One task's dispute record. */
|
|
63
|
-
dispute: (taskPda) => [QUERY_KEY_ROOT, "dispute", taskPda],
|
|
64
|
-
/** One referrer wallet's earnings (indexer-gated; see useReferrerEarnings). */
|
|
65
|
-
referrerEarnings: (wallet) => [QUERY_KEY_ROOT, "referrerEarnings", wallet]
|
|
66
|
-
};
|
|
67
|
-
function requireClient(client) {
|
|
68
|
-
if (client === null) {
|
|
69
|
-
throw new Error(t("provider.missingWriteClient"));
|
|
70
|
-
}
|
|
71
|
-
return client;
|
|
72
|
-
}
|
|
73
|
-
function mutationStatusOf(mutation) {
|
|
74
|
-
if (mutation.isPending) return "pending";
|
|
75
|
-
if (mutation.isError) return "error";
|
|
76
|
-
if (mutation.isSuccess) return "success";
|
|
77
|
-
return "idle";
|
|
78
|
-
}
|
|
79
|
-
function pdaKey(pda) {
|
|
80
|
-
return String(pda);
|
|
81
|
-
}
|
|
82
|
-
function resolveReferrerArgs(ctx) {
|
|
83
|
-
const capability = ctx.resolveReferrerCapability();
|
|
84
|
-
if (!capability.live || !capability.referrer) {
|
|
85
|
-
return { referrerArgs: {}, referrerInjected: false };
|
|
86
|
-
}
|
|
87
|
-
return {
|
|
88
|
-
referrerArgs: {
|
|
89
|
-
referrer: capability.referrer.wallet,
|
|
90
|
-
referrerFeeBps: capability.referrer.feeBps
|
|
91
|
-
},
|
|
92
|
-
referrerInjected: true
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
function signerAddress(signerOrAddress) {
|
|
96
|
-
if (typeof signerOrAddress === "string") {
|
|
97
|
-
return signerOrAddress;
|
|
98
|
-
}
|
|
99
|
-
if (typeof signerOrAddress === "object" && signerOrAddress !== null && "address" in signerOrAddress && typeof signerOrAddress.address === "string") {
|
|
100
|
-
return signerOrAddress.address;
|
|
101
|
-
}
|
|
102
|
-
throw new Error("Expected a TransactionSigner or Address with an address field.");
|
|
103
|
-
}
|
|
104
|
-
function withoutReferrerArgs(input) {
|
|
105
|
-
const {
|
|
106
|
-
referrer: _referrer,
|
|
107
|
-
referrerFeeBps: _referrerFeeBps,
|
|
108
|
-
...rest
|
|
109
|
-
} = input;
|
|
110
|
-
return rest;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// src/hooks/useListings.ts
|
|
114
11
|
var DEFAULT_PAGE_SIZE = 12;
|
|
115
12
|
function useListings(filter, options) {
|
|
116
|
-
const { read } = useAgencContext();
|
|
13
|
+
const { read, cacheNamespace } = chunkJTSG5FGC_cjs.useAgencContext();
|
|
117
14
|
const pageSize = options?.pageSize ?? DEFAULT_PAGE_SIZE;
|
|
118
15
|
const enabled = options?.enabled ?? true;
|
|
119
16
|
const query = reactQuery.useQuery({
|
|
120
|
-
queryKey: queryKeys.listings(filter),
|
|
17
|
+
queryKey: chunkJTSG5FGC_cjs.queryKeys.listings(filter, cacheNamespace),
|
|
121
18
|
queryFn: () => read.listActiveListings(filter),
|
|
122
19
|
enabled
|
|
123
20
|
});
|
|
@@ -145,24 +42,11 @@ function useListings(filter, options) {
|
|
|
145
42
|
refetch
|
|
146
43
|
};
|
|
147
44
|
}
|
|
148
|
-
var ReadTransportUnsupportedError = class extends Error {
|
|
149
|
-
/** The unsupported operation name. */
|
|
150
|
-
operation;
|
|
151
|
-
constructor(operation) {
|
|
152
|
-
super(
|
|
153
|
-
`Read operation "${operation}" requires the indexer backend; the gPA fallback has no trustless equivalent. Configure an indexer baseUrl on <AgencProvider> to use it.`
|
|
154
|
-
);
|
|
155
|
-
this.name = "ReadTransportUnsupportedError";
|
|
156
|
-
this.operation = operation;
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
// src/hooks/useListing.ts
|
|
161
45
|
function useListing(pda, options) {
|
|
162
|
-
const { read } = useAgencContext();
|
|
46
|
+
const { read, cacheNamespace } = chunkJTSG5FGC_cjs.useAgencContext();
|
|
163
47
|
const enabled = (options?.enabled ?? true) && Boolean(pda);
|
|
164
48
|
const query = reactQuery.useQuery({
|
|
165
|
-
queryKey: queryKeys.listing(pda ? pdaKey(pda) : ""),
|
|
49
|
+
queryKey: chunkJTSG5FGC_cjs.queryKeys.listing(pda ? chunkJTSG5FGC_cjs.pdaKey(pda) : "", cacheNamespace),
|
|
166
50
|
enabled,
|
|
167
51
|
queryFn: async () => {
|
|
168
52
|
const result = await read.getListing(pda);
|
|
@@ -171,7 +55,7 @@ function useListing(pda, options) {
|
|
|
171
55
|
try {
|
|
172
56
|
trackRecord = await read.agentTrackRecord(provider);
|
|
173
57
|
} catch (err) {
|
|
174
|
-
if (!(err instanceof ReadTransportUnsupportedError)) throw err;
|
|
58
|
+
if (!(err instanceof chunkONC6L3IX_cjs.ReadTransportUnsupportedError)) throw err;
|
|
175
59
|
}
|
|
176
60
|
return {
|
|
177
61
|
address: result.address,
|
|
@@ -218,10 +102,13 @@ function projectTrackRecord(raw) {
|
|
|
218
102
|
};
|
|
219
103
|
}
|
|
220
104
|
function useAgentTrackRecord(agentPda, options) {
|
|
221
|
-
const { read } = useAgencContext();
|
|
105
|
+
const { read, cacheNamespace } = chunkJTSG5FGC_cjs.useAgencContext();
|
|
222
106
|
const enabled = (options?.enabled ?? true) && Boolean(agentPda);
|
|
223
107
|
const query = reactQuery.useQuery({
|
|
224
|
-
queryKey: queryKeys.agentTrackRecord(
|
|
108
|
+
queryKey: chunkJTSG5FGC_cjs.queryKeys.agentTrackRecord(
|
|
109
|
+
agentPda ? chunkJTSG5FGC_cjs.pdaKey(agentPda) : "",
|
|
110
|
+
cacheNamespace
|
|
111
|
+
),
|
|
225
112
|
enabled,
|
|
226
113
|
queryFn: async () => {
|
|
227
114
|
const raw = await read.agentTrackRecord(agentPda);
|
|
@@ -245,17 +132,32 @@ var TERMINAL_STATUSES = /* @__PURE__ */ new Set([
|
|
|
245
132
|
marketplaceSdk.TaskStatus.Cancelled,
|
|
246
133
|
marketplaceSdk.TaskStatus.RejectFrozen
|
|
247
134
|
]);
|
|
135
|
+
var DEFAULT_MAX_EVENTS = 256;
|
|
136
|
+
var MAX_POLL_INTERVAL_MS = 2147483647;
|
|
248
137
|
function hasResult(task) {
|
|
249
138
|
return task !== null && task.result.length > 0 && task.result.some((b) => b !== 0);
|
|
250
139
|
}
|
|
251
140
|
function useTaskStatus(taskPda, options) {
|
|
252
|
-
useAgencContext();
|
|
141
|
+
const ctx = chunkJTSG5FGC_cjs.useAgencContext();
|
|
253
142
|
const reader = options?.taskReader;
|
|
254
143
|
const enabled = (options?.enabled ?? true) && Boolean(taskPda) && Boolean(reader);
|
|
255
144
|
const pollIntervalMs = options?.pollIntervalMs ?? 2e3;
|
|
256
|
-
const
|
|
145
|
+
const maxEvents = options?.maxEvents ?? DEFAULT_MAX_EVENTS;
|
|
146
|
+
if (!Number.isSafeInteger(pollIntervalMs) || pollIntervalMs < 0 || pollIntervalMs > MAX_POLL_INTERVAL_MS) {
|
|
147
|
+
throw new RangeError(
|
|
148
|
+
`useTaskStatus: pollIntervalMs must be a non-negative integer no greater than ${MAX_POLL_INTERVAL_MS} (got ${pollIntervalMs})`
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
if (!Number.isSafeInteger(maxEvents) || maxEvents < 0) {
|
|
152
|
+
throw new RangeError(
|
|
153
|
+
`useTaskStatus: maxEvents must be a non-negative safe integer (got ${maxEvents})`
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
const taskIdentity = taskPda ? chunkJTSG5FGC_cjs.pdaKey(taskPda) : "";
|
|
157
|
+
const [eventState, setEventState] = react.useState(() => ({ taskIdentity, events: [] }));
|
|
158
|
+
const events = eventState.taskIdentity === taskIdentity ? eventState.events : [];
|
|
257
159
|
const query = reactQuery.useQuery({
|
|
258
|
-
queryKey: queryKeys.taskStatus(
|
|
160
|
+
queryKey: chunkJTSG5FGC_cjs.queryKeys.taskStatus(taskIdentity, ctx.cacheNamespace),
|
|
259
161
|
enabled,
|
|
260
162
|
queryFn: () => reader(taskPda),
|
|
261
163
|
// Poll until terminal / target reached; then stop (return `false`).
|
|
@@ -273,22 +175,52 @@ function useTaskStatus(taskPda, options) {
|
|
|
273
175
|
refetchRef.current = query.refetch;
|
|
274
176
|
const eventsSource = options?.events;
|
|
275
177
|
react.useEffect(() => {
|
|
276
|
-
|
|
178
|
+
setEventState({ taskIdentity, events: [] });
|
|
179
|
+
if (!enabled || !eventsSource || !taskPda) return;
|
|
180
|
+
const controller = new AbortController();
|
|
181
|
+
const aborted = /* @__PURE__ */ Symbol("aborted");
|
|
182
|
+
const abortPromise = new Promise((resolve) => {
|
|
183
|
+
controller.signal.addEventListener("abort", () => resolve(aborted), {
|
|
184
|
+
once: true
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
let iterator = null;
|
|
277
188
|
let cancelled = false;
|
|
278
|
-
|
|
189
|
+
let finished = false;
|
|
190
|
+
void (async () => {
|
|
279
191
|
try {
|
|
280
|
-
|
|
192
|
+
const iterable = typeof eventsSource === "function" ? eventsSource({ signal: controller.signal, taskPda }) : eventsSource;
|
|
193
|
+
iterator = iterable[Symbol.asyncIterator]();
|
|
194
|
+
while (!cancelled) {
|
|
195
|
+
const next = await Promise.race([iterator.next(), abortPromise]);
|
|
196
|
+
if (next === aborted) break;
|
|
281
197
|
if (cancelled) break;
|
|
282
|
-
|
|
198
|
+
if (next.done) {
|
|
199
|
+
finished = true;
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
setEventState((prev) => ({
|
|
203
|
+
taskIdentity,
|
|
204
|
+
events: prev.taskIdentity === taskIdentity ? maxEvents === 0 ? [] : [...prev.events, next.value].slice(-maxEvents) : maxEvents === 0 ? [] : [next.value]
|
|
205
|
+
}));
|
|
283
206
|
void refetchRef.current();
|
|
284
207
|
}
|
|
285
208
|
} catch {
|
|
209
|
+
} finally {
|
|
210
|
+
finished = true;
|
|
286
211
|
}
|
|
287
212
|
})();
|
|
288
213
|
return () => {
|
|
289
214
|
cancelled = true;
|
|
215
|
+
controller.abort();
|
|
216
|
+
if (!finished && iterator?.return) {
|
|
217
|
+
try {
|
|
218
|
+
void Promise.resolve(iterator.return()).catch(() => void 0);
|
|
219
|
+
} catch {
|
|
220
|
+
}
|
|
221
|
+
}
|
|
290
222
|
};
|
|
291
|
-
}, [eventsSource]);
|
|
223
|
+
}, [enabled, eventsSource, maxEvents, taskIdentity, taskPda]);
|
|
292
224
|
const task = query.data ?? null;
|
|
293
225
|
return {
|
|
294
226
|
task,
|
|
@@ -300,141 +232,6 @@ function useTaskStatus(taskPda, options) {
|
|
|
300
232
|
refetch: () => void query.refetch()
|
|
301
233
|
};
|
|
302
234
|
}
|
|
303
|
-
function readRpc(input) {
|
|
304
|
-
return input.rpc ?? (input.rpcUrl ? kit.createSolanaRpc(input.rpcUrl) : null);
|
|
305
|
-
}
|
|
306
|
-
async function resolveRosterEntry(rpc, moderator) {
|
|
307
|
-
const [moderationConfigPda] = await marketplaceSdk.findModerationConfigPda();
|
|
308
|
-
const moderationConfig = await marketplaceSdk.fetchMaybeModerationConfig(
|
|
309
|
-
rpc,
|
|
310
|
-
moderationConfigPda
|
|
311
|
-
);
|
|
312
|
-
if (moderationConfig.exists && moderationConfig.data.moderationAuthority === moderator) {
|
|
313
|
-
return void 0;
|
|
314
|
-
}
|
|
315
|
-
const [rosterPda] = await marketplaceSdk.findModerationAttestorPda({ attestor: moderator });
|
|
316
|
-
const roster = await marketplaceSdk.fetchMaybeModerationAttestor(rpc, rosterPda);
|
|
317
|
-
return roster.exists ? rosterPda : void 0;
|
|
318
|
-
}
|
|
319
|
-
async function resolveActivationModerationAccounts(input) {
|
|
320
|
-
try {
|
|
321
|
-
const rpc = readRpc(input);
|
|
322
|
-
if (!rpc) return {};
|
|
323
|
-
const moderationAttestor = await resolveRosterEntry(rpc, input.moderator);
|
|
324
|
-
const attestorPart = moderationAttestor !== void 0 ? { moderationAttestor } : {};
|
|
325
|
-
const [v2Pda] = await marketplaceSdk.findTaskModerationPda({
|
|
326
|
-
task: input.task,
|
|
327
|
-
jobSpecHash: input.jobSpecHash,
|
|
328
|
-
moderator: input.moderator
|
|
329
|
-
});
|
|
330
|
-
const v2 = await marketplaceSdk.fetchMaybeTaskModeration(rpc, v2Pda);
|
|
331
|
-
if (v2.exists) return attestorPart;
|
|
332
|
-
const [legacyPda] = await marketplaceSdk.facade.findLegacyTaskModerationPda({
|
|
333
|
-
task: input.task,
|
|
334
|
-
jobSpecHash: input.jobSpecHash
|
|
335
|
-
});
|
|
336
|
-
const legacy = await marketplaceSdk.fetchMaybeTaskModeration(rpc, legacyPda);
|
|
337
|
-
if (legacy.exists && legacy.data.moderator === input.moderator) {
|
|
338
|
-
return { ...attestorPart, taskModeration: legacyPda };
|
|
339
|
-
}
|
|
340
|
-
return attestorPart;
|
|
341
|
-
} catch {
|
|
342
|
-
return {};
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
async function resolveHireListingModerationAccounts(input) {
|
|
346
|
-
try {
|
|
347
|
-
const rpc = readRpc(input);
|
|
348
|
-
if (!rpc) return {};
|
|
349
|
-
const moderationAttestor = await resolveRosterEntry(rpc, input.moderator);
|
|
350
|
-
const attestorPart = moderationAttestor !== void 0 ? { moderationAttestor } : {};
|
|
351
|
-
const [v2Pda] = await marketplaceSdk.findListingModerationPda({
|
|
352
|
-
listing: input.listing,
|
|
353
|
-
jobSpecHash: input.listingSpecHash,
|
|
354
|
-
moderator: input.moderator
|
|
355
|
-
});
|
|
356
|
-
const v2 = await marketplaceSdk.fetchMaybeListingModeration(rpc, v2Pda);
|
|
357
|
-
if (v2.exists) return attestorPart;
|
|
358
|
-
const [legacyPda] = await marketplaceSdk.facade.findLegacyListingModerationPda({
|
|
359
|
-
listing: input.listing,
|
|
360
|
-
jobSpecHash: input.listingSpecHash
|
|
361
|
-
});
|
|
362
|
-
const legacy = await marketplaceSdk.fetchMaybeListingModeration(rpc, legacyPda);
|
|
363
|
-
if (legacy.exists && legacy.data.moderator === input.moderator) {
|
|
364
|
-
return { ...attestorPart, listingModeration: legacyPda };
|
|
365
|
-
}
|
|
366
|
-
return attestorPart;
|
|
367
|
-
} catch {
|
|
368
|
-
return {};
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
// src/hooks/useHire.ts
|
|
373
|
-
function useHire() {
|
|
374
|
-
const ctx = useAgencContext();
|
|
375
|
-
const mutation = reactQuery.useMutation({
|
|
376
|
-
mutationFn: async (input) => {
|
|
377
|
-
const client = requireClient(ctx.client);
|
|
378
|
-
const { referrerArgs, referrerInjected } = resolveReferrerArgs(ctx);
|
|
379
|
-
const hireInput = withoutReferrerArgs(input);
|
|
380
|
-
const listingSpecHash = input.listingSpecHash;
|
|
381
|
-
let moderationArgs = {};
|
|
382
|
-
if (input.moderationAttestor === void 0 && input.moderatorIsAttestor === void 0 && input.listingModeration === void 0 && listingSpecHash !== void 0) {
|
|
383
|
-
moderationArgs = await resolveHireListingModerationAccounts({
|
|
384
|
-
rpcUrl: ctx.rpcUrl,
|
|
385
|
-
listing: input.listing,
|
|
386
|
-
listingSpecHash,
|
|
387
|
-
moderator: input.moderator
|
|
388
|
-
});
|
|
389
|
-
}
|
|
390
|
-
const creator = input.creator ?? client.signer;
|
|
391
|
-
let signature;
|
|
392
|
-
if (input.humanless === true) {
|
|
393
|
-
const result = await client.hireFromListingHumanless({
|
|
394
|
-
...hireInput,
|
|
395
|
-
...moderationArgs,
|
|
396
|
-
creator,
|
|
397
|
-
...referrerArgs
|
|
398
|
-
});
|
|
399
|
-
signature = result.signature;
|
|
400
|
-
} else {
|
|
401
|
-
const authority = input.authority ?? client.signer;
|
|
402
|
-
const result = await client.hireFromListing({
|
|
403
|
-
...hireInput,
|
|
404
|
-
...moderationArgs,
|
|
405
|
-
authority,
|
|
406
|
-
creator,
|
|
407
|
-
...referrerArgs
|
|
408
|
-
});
|
|
409
|
-
signature = result.signature;
|
|
410
|
-
}
|
|
411
|
-
const [taskPda] = await marketplaceSdk.findTaskPda({
|
|
412
|
-
creator: signerAddress(creator),
|
|
413
|
-
taskId: input.taskId
|
|
414
|
-
});
|
|
415
|
-
return { signature, taskPda, referrerInjected };
|
|
416
|
-
}
|
|
417
|
-
});
|
|
418
|
-
const hire = react.useCallback(
|
|
419
|
-
(input) => mutation.mutateAsync(input),
|
|
420
|
-
[mutation]
|
|
421
|
-
);
|
|
422
|
-
const status = react.useMemo(() => {
|
|
423
|
-
if (mutation.isPending) return "pending";
|
|
424
|
-
if (mutation.isError) return "error";
|
|
425
|
-
if (mutation.isSuccess) return "success";
|
|
426
|
-
return "idle";
|
|
427
|
-
}, [mutation.isPending, mutation.isError, mutation.isSuccess]);
|
|
428
|
-
return {
|
|
429
|
-
hire,
|
|
430
|
-
status,
|
|
431
|
-
taskPda: mutation.data?.taskPda ?? null,
|
|
432
|
-
signature: mutation.data?.signature ?? null,
|
|
433
|
-
error: mutation.error ?? null,
|
|
434
|
-
isPending: mutation.isPending,
|
|
435
|
-
reset: mutation.reset
|
|
436
|
-
};
|
|
437
|
-
}
|
|
438
235
|
function statusOf(m) {
|
|
439
236
|
if (m.isPending) return "pending";
|
|
440
237
|
if (m.isError) return "error";
|
|
@@ -442,63 +239,107 @@ function statusOf(m) {
|
|
|
442
239
|
return "idle";
|
|
443
240
|
}
|
|
444
241
|
function useSubmissionReview(taskPda) {
|
|
445
|
-
const ctx = useAgencContext();
|
|
242
|
+
const ctx = chunkJTSG5FGC_cjs.useAgencContext();
|
|
243
|
+
const lastAction = react.useRef(
|
|
244
|
+
null
|
|
245
|
+
);
|
|
446
246
|
const acceptMut = reactQuery.useMutation({
|
|
447
|
-
mutationFn: async (input) => {
|
|
448
|
-
const client = requireClient(ctx.client);
|
|
247
|
+
mutationFn: async ({ client, input }) => {
|
|
449
248
|
const { signature: signature2 } = await client.acceptTaskResult({
|
|
450
249
|
...input,
|
|
451
|
-
task: taskPda
|
|
452
|
-
creator: input.creator ?? client.signer
|
|
250
|
+
task: taskPda
|
|
453
251
|
});
|
|
454
252
|
return signature2;
|
|
455
253
|
}
|
|
456
254
|
});
|
|
457
255
|
const rejectMut = reactQuery.useMutation({
|
|
458
|
-
mutationFn: async (input) => {
|
|
459
|
-
const client = requireClient(ctx.client);
|
|
256
|
+
mutationFn: async ({ client, input }) => {
|
|
460
257
|
const ix = await marketplaceSdk.facade.rejectTaskResult({
|
|
461
258
|
...input,
|
|
462
|
-
task: taskPda
|
|
463
|
-
creator: input.creator ?? client.signer
|
|
259
|
+
task: taskPda
|
|
464
260
|
});
|
|
465
261
|
const { signature: signature2 } = await client.send([ix]);
|
|
466
262
|
return signature2;
|
|
467
263
|
}
|
|
468
264
|
});
|
|
469
265
|
const requestChangesMut = reactQuery.useMutation({
|
|
470
|
-
mutationFn: async (input) => {
|
|
471
|
-
const client = requireClient(ctx.client);
|
|
266
|
+
mutationFn: async ({ client, input }) => {
|
|
472
267
|
const ix = await marketplaceSdk.facade.requestChanges({
|
|
473
268
|
...input,
|
|
474
|
-
task: taskPda
|
|
475
|
-
creator: input.creator ?? client.signer
|
|
269
|
+
task: taskPda
|
|
476
270
|
});
|
|
477
271
|
const { signature: signature2 } = await client.send([ix]);
|
|
478
272
|
return signature2;
|
|
479
273
|
}
|
|
480
274
|
});
|
|
481
275
|
const accept = react.useCallback(
|
|
482
|
-
(input) =>
|
|
483
|
-
|
|
276
|
+
async (input) => {
|
|
277
|
+
const client = chunkJTSG5FGC_cjs.requireClient(ctx.client);
|
|
278
|
+
const detachedInput = chunkJTSG5FGC_cjs.snapshotRecord(input);
|
|
279
|
+
const creator = chunkJTSG5FGC_cjs.stabilizeSelectedTransactionSigner(
|
|
280
|
+
client.signer,
|
|
281
|
+
detachedInput.creator
|
|
282
|
+
);
|
|
283
|
+
const snapshottedInput = chunkJTSG5FGC_cjs.snapshotRecord({
|
|
284
|
+
...detachedInput,
|
|
285
|
+
creator,
|
|
286
|
+
...detachedInput.bidSettlement === void 0 ? {} : { bidSettlement: chunkJTSG5FGC_cjs.snapshotRecord(detachedInput.bidSettlement) }
|
|
287
|
+
});
|
|
288
|
+
lastAction.current = "accept";
|
|
289
|
+
return acceptMut.mutateAsync({ client, input: snapshottedInput });
|
|
290
|
+
},
|
|
291
|
+
[acceptMut, ctx.client]
|
|
484
292
|
);
|
|
485
293
|
const reject = react.useCallback(
|
|
486
|
-
(input) =>
|
|
487
|
-
|
|
294
|
+
async (input) => {
|
|
295
|
+
const client = chunkJTSG5FGC_cjs.requireClient(ctx.client);
|
|
296
|
+
const detachedInput = chunkJTSG5FGC_cjs.snapshotRecord(input);
|
|
297
|
+
const creator = chunkJTSG5FGC_cjs.stabilizeSelectedTransactionSigner(
|
|
298
|
+
client.signer,
|
|
299
|
+
detachedInput.creator
|
|
300
|
+
);
|
|
301
|
+
const snapshottedInput = chunkJTSG5FGC_cjs.snapshotRecord({
|
|
302
|
+
...detachedInput,
|
|
303
|
+
creator,
|
|
304
|
+
rejectionHash: chunkJTSG5FGC_cjs.snapshotFixedBytes32(
|
|
305
|
+
detachedInput.rejectionHash,
|
|
306
|
+
"useSubmissionReview.reject: rejectionHash"
|
|
307
|
+
)
|
|
308
|
+
});
|
|
309
|
+
lastAction.current = "reject";
|
|
310
|
+
return rejectMut.mutateAsync({ client, input: snapshottedInput });
|
|
311
|
+
},
|
|
312
|
+
[ctx.client, rejectMut]
|
|
488
313
|
);
|
|
489
314
|
const requestChanges = react.useCallback(
|
|
490
|
-
(input) =>
|
|
491
|
-
|
|
315
|
+
async (input) => {
|
|
316
|
+
const client = chunkJTSG5FGC_cjs.requireClient(ctx.client);
|
|
317
|
+
const detachedInput = chunkJTSG5FGC_cjs.snapshotRecord(input);
|
|
318
|
+
const creator = chunkJTSG5FGC_cjs.stabilizeSelectedTransactionSigner(
|
|
319
|
+
client.signer,
|
|
320
|
+
detachedInput.creator
|
|
321
|
+
);
|
|
322
|
+
const snapshottedInput = chunkJTSG5FGC_cjs.snapshotRecord({
|
|
323
|
+
...detachedInput,
|
|
324
|
+
creator,
|
|
325
|
+
changesHash: chunkJTSG5FGC_cjs.snapshotFixedBytes32(
|
|
326
|
+
detachedInput.changesHash,
|
|
327
|
+
"useSubmissionReview.requestChanges: changesHash"
|
|
328
|
+
)
|
|
329
|
+
});
|
|
330
|
+
lastAction.current = "requestChanges";
|
|
331
|
+
return requestChangesMut.mutateAsync({
|
|
332
|
+
client,
|
|
333
|
+
input: snapshottedInput
|
|
334
|
+
});
|
|
335
|
+
},
|
|
336
|
+
[ctx.client, requestChangesMut]
|
|
492
337
|
);
|
|
493
338
|
const anyPending = acceptMut.isPending || rejectMut.isPending || requestChangesMut.isPending;
|
|
494
|
-
const
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
) ?? acceptMut
|
|
499
|
-
);
|
|
500
|
-
const error = acceptMut.error ?? rejectMut.error ?? requestChangesMut.error ?? null;
|
|
501
|
-
const signature = acceptMut.data ?? rejectMut.data ?? requestChangesMut.data ?? null;
|
|
339
|
+
const latest = lastAction.current === "reject" ? rejectMut : lastAction.current === "requestChanges" ? requestChangesMut : acceptMut;
|
|
340
|
+
const status = anyPending ? "pending" : statusOf(latest);
|
|
341
|
+
const error = latest.error ?? null;
|
|
342
|
+
const signature = latest.data ?? null;
|
|
502
343
|
return {
|
|
503
344
|
accept,
|
|
504
345
|
reject,
|
|
@@ -507,6 +348,7 @@ function useSubmissionReview(taskPda) {
|
|
|
507
348
|
error,
|
|
508
349
|
signature,
|
|
509
350
|
reset: () => {
|
|
351
|
+
lastAction.current = null;
|
|
510
352
|
acceptMut.reset();
|
|
511
353
|
rejectMut.reset();
|
|
512
354
|
requestChangesMut.reset();
|
|
@@ -514,33 +356,62 @@ function useSubmissionReview(taskPda) {
|
|
|
514
356
|
};
|
|
515
357
|
}
|
|
516
358
|
function useTaskActivation(taskPda) {
|
|
517
|
-
const ctx = useAgencContext();
|
|
359
|
+
const ctx = chunkJTSG5FGC_cjs.useAgencContext();
|
|
518
360
|
const mutation = reactQuery.useMutation({
|
|
519
|
-
mutationFn: async (
|
|
520
|
-
|
|
361
|
+
mutationFn: async ({
|
|
362
|
+
client,
|
|
363
|
+
input,
|
|
364
|
+
taskPda: snapshottedTaskPda,
|
|
365
|
+
creator,
|
|
366
|
+
orchestrationRpcUrl,
|
|
367
|
+
orchestrationRpc
|
|
368
|
+
}) => {
|
|
521
369
|
const callerResolved = input.moderationAttestor !== void 0 || input.moderatorIsAttestor !== void 0 || input.taskModeration !== void 0;
|
|
522
|
-
const resolved = callerResolved ? {} : await resolveActivationModerationAccounts({
|
|
523
|
-
rpcUrl:
|
|
524
|
-
|
|
370
|
+
const resolved = callerResolved ? {} : await chunkJTSG5FGC_cjs.resolveActivationModerationAccounts({
|
|
371
|
+
rpcUrl: orchestrationRpcUrl,
|
|
372
|
+
...orchestrationRpc === null ? {} : { rpc: orchestrationRpc },
|
|
373
|
+
task: snapshottedTaskPda,
|
|
525
374
|
jobSpecHash: input.jobSpecHash,
|
|
526
375
|
moderator: input.moderator
|
|
527
376
|
});
|
|
528
377
|
const { signature } = await client.setTaskJobSpec({
|
|
529
378
|
...input,
|
|
530
379
|
...resolved,
|
|
531
|
-
task:
|
|
532
|
-
creator
|
|
380
|
+
task: snapshottedTaskPda,
|
|
381
|
+
creator
|
|
533
382
|
});
|
|
534
383
|
return signature;
|
|
535
384
|
}
|
|
536
385
|
});
|
|
537
386
|
const activate = react.useCallback(
|
|
538
|
-
(input) =>
|
|
539
|
-
|
|
387
|
+
async (input) => {
|
|
388
|
+
const client = chunkJTSG5FGC_cjs.requireClient(ctx.client);
|
|
389
|
+
const detachedInput = { ...input };
|
|
390
|
+
const snapshottedInput = {
|
|
391
|
+
...detachedInput,
|
|
392
|
+
jobSpecHash: chunkJTSG5FGC_cjs.snapshotFixedBytes32(
|
|
393
|
+
detachedInput.jobSpecHash,
|
|
394
|
+
"useTaskActivation: jobSpecHash"
|
|
395
|
+
)
|
|
396
|
+
};
|
|
397
|
+
const creator = chunkJTSG5FGC_cjs.stabilizeSelectedTransactionSigner(
|
|
398
|
+
client.signer,
|
|
399
|
+
detachedInput.creator
|
|
400
|
+
);
|
|
401
|
+
return mutation.mutateAsync({
|
|
402
|
+
client,
|
|
403
|
+
input: snapshottedInput,
|
|
404
|
+
taskPda,
|
|
405
|
+
creator,
|
|
406
|
+
orchestrationRpcUrl: ctx.orchestrationRpcUrl,
|
|
407
|
+
orchestrationRpc: ctx.orchestrationRpc
|
|
408
|
+
});
|
|
409
|
+
},
|
|
410
|
+
[ctx, mutation]
|
|
540
411
|
);
|
|
541
412
|
return {
|
|
542
413
|
activate,
|
|
543
|
-
status: mutationStatusOf(mutation),
|
|
414
|
+
status: chunkJTSG5FGC_cjs.mutationStatusOf(mutation),
|
|
544
415
|
signature: mutation.data ?? null,
|
|
545
416
|
error: mutation.error ?? null,
|
|
546
417
|
isPending: mutation.isPending,
|
|
@@ -554,20 +425,114 @@ function emptyProgress() {
|
|
|
554
425
|
activationSignature: null,
|
|
555
426
|
jobSpecHash: null,
|
|
556
427
|
jobSpecUri: null,
|
|
557
|
-
referrerInjected: false
|
|
428
|
+
referrerInjected: false,
|
|
429
|
+
recovery: null
|
|
558
430
|
};
|
|
559
431
|
}
|
|
560
|
-
function
|
|
432
|
+
function readCreatorAddress(creator, label) {
|
|
433
|
+
try {
|
|
434
|
+
return kit.address(creator.address);
|
|
435
|
+
} catch (cause) {
|
|
436
|
+
throw new TypeError(
|
|
437
|
+
`useHumanlessHireFlow: ${label} must expose a valid Solana address`,
|
|
438
|
+
{ cause }
|
|
439
|
+
);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
function assertCreatorUnchanged(creator, expectedAddress) {
|
|
443
|
+
if (readCreatorAddress(creator, "creator") !== expectedAddress) {
|
|
444
|
+
throw new TypeError(
|
|
445
|
+
"useHumanlessHireFlow: creator address changed after enqueue; no transaction was submitted"
|
|
446
|
+
);
|
|
447
|
+
}
|
|
448
|
+
return creator;
|
|
449
|
+
}
|
|
450
|
+
function snapshotFlowInput(input, defaultCreator) {
|
|
451
|
+
let jobSpec;
|
|
452
|
+
try {
|
|
453
|
+
jobSpec = marketplaceSdk.snapshotStructuredClone(
|
|
454
|
+
input.jobSpec,
|
|
455
|
+
"useHumanlessHireFlow: jobSpec"
|
|
456
|
+
);
|
|
457
|
+
} catch (cause) {
|
|
458
|
+
throw new TypeError(
|
|
459
|
+
"useHumanlessHireFlow: jobSpec must be structured-cloneable",
|
|
460
|
+
{ cause }
|
|
461
|
+
);
|
|
462
|
+
}
|
|
463
|
+
const creator = chunkJTSG5FGC_cjs.stabilizeSelectedTransactionSigner(
|
|
464
|
+
defaultCreator,
|
|
465
|
+
input.creator
|
|
466
|
+
);
|
|
467
|
+
return {
|
|
468
|
+
creatorAddress: readCreatorAddress(creator, "creator"),
|
|
469
|
+
input: {
|
|
470
|
+
...input,
|
|
471
|
+
hire: {
|
|
472
|
+
...input.hire,
|
|
473
|
+
taskId: chunkJTSG5FGC_cjs.snapshotFixedBytes32(
|
|
474
|
+
input.hire.taskId,
|
|
475
|
+
"useHumanlessHireFlow: hire.taskId"
|
|
476
|
+
),
|
|
477
|
+
listingSpecHash: chunkJTSG5FGC_cjs.snapshotFixedBytes32(
|
|
478
|
+
input.hire.listingSpecHash,
|
|
479
|
+
"useHumanlessHireFlow: hire.listingSpecHash"
|
|
480
|
+
),
|
|
481
|
+
taskJobSpecHash: chunkJTSG5FGC_cjs.snapshotFixedBytes32(
|
|
482
|
+
input.hire.taskJobSpecHash,
|
|
483
|
+
"useHumanlessHireFlow: hire.taskJobSpecHash"
|
|
484
|
+
)
|
|
485
|
+
},
|
|
486
|
+
jobSpec,
|
|
487
|
+
...input.activation === void 0 ? {} : { activation: { ...input.activation } },
|
|
488
|
+
creator
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
function snapshotRecovery(recovery) {
|
|
493
|
+
return recovery.phase === "activating" ? {
|
|
494
|
+
...recovery,
|
|
495
|
+
jobSpecHash: chunkJTSG5FGC_cjs.snapshotFixedBytes32(
|
|
496
|
+
recovery.jobSpecHash,
|
|
497
|
+
"useHumanlessHireFlow: recovery.jobSpecHash"
|
|
498
|
+
)
|
|
499
|
+
} : { ...recovery };
|
|
500
|
+
}
|
|
501
|
+
function progressFromRecovery(recovery, referrerInjected) {
|
|
502
|
+
const committed = recovery.phase !== "hiring";
|
|
503
|
+
const activating = recovery.phase === "activating" ? recovery : null;
|
|
504
|
+
return {
|
|
505
|
+
taskPda: recovery.taskPda,
|
|
506
|
+
hireSignature: committed && recovery.hireSignature !== "" ? recovery.hireSignature : null,
|
|
507
|
+
activationSignature: null,
|
|
508
|
+
jobSpecHash: activating?.jobSpecHash ?? null,
|
|
509
|
+
jobSpecUri: activating?.jobSpecUri ?? null,
|
|
510
|
+
referrerInjected,
|
|
511
|
+
recovery
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
function validateModerationResult(result, committedHash) {
|
|
561
515
|
if (result.moderationAttested !== true) {
|
|
562
516
|
throw new Error(
|
|
563
517
|
"Task moderation was not attested; activation was not signed."
|
|
564
518
|
);
|
|
565
519
|
}
|
|
566
|
-
|
|
520
|
+
let jobSpecHash;
|
|
521
|
+
try {
|
|
522
|
+
jobSpecHash = chunkJTSG5FGC_cjs.snapshotFixedBytes32(
|
|
523
|
+
result.jobSpecHash,
|
|
524
|
+
"useHumanlessHireFlow: moderation.jobSpecHash"
|
|
525
|
+
);
|
|
526
|
+
} catch {
|
|
567
527
|
throw new Error(
|
|
568
528
|
"Task moderation returned an invalid jobSpecHash; activation was not signed."
|
|
569
529
|
);
|
|
570
530
|
}
|
|
531
|
+
if (!jobSpecHash.every((byte, index) => byte === committedHash[index])) {
|
|
532
|
+
throw new Error(
|
|
533
|
+
"Task moderation returned a jobSpecHash different from the hash committed at hire; activation was not signed."
|
|
534
|
+
);
|
|
535
|
+
}
|
|
571
536
|
const jobSpecUri = result.jobSpecUri.trim();
|
|
572
537
|
if (!jobSpecUri) {
|
|
573
538
|
throw new Error(
|
|
@@ -580,100 +545,118 @@ function validateModerationResult(result) {
|
|
|
580
545
|
);
|
|
581
546
|
}
|
|
582
547
|
return {
|
|
583
|
-
jobSpecHash
|
|
548
|
+
jobSpecHash,
|
|
584
549
|
jobSpecUri,
|
|
585
550
|
moderator: result.moderator
|
|
586
551
|
};
|
|
587
552
|
}
|
|
588
553
|
function useHumanlessHireFlow() {
|
|
589
|
-
const ctx = useAgencContext();
|
|
554
|
+
const ctx = chunkJTSG5FGC_cjs.useAgencContext();
|
|
590
555
|
const [phase, setPhase] = react.useState("idle");
|
|
591
556
|
const [progress, setProgress] = react.useState(emptyProgress);
|
|
592
557
|
const flowInFlight = react.useRef(false);
|
|
593
558
|
const mutation = reactQuery.useMutation({
|
|
594
|
-
mutationFn: async (
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
559
|
+
mutationFn: async ({
|
|
560
|
+
input,
|
|
561
|
+
creatorAddress,
|
|
562
|
+
recovery,
|
|
563
|
+
client,
|
|
564
|
+
rpc,
|
|
565
|
+
rpcUrl,
|
|
566
|
+
referral
|
|
567
|
+
}) => {
|
|
568
|
+
const creator = assertCreatorUnchanged(input.creator, creatorAddress);
|
|
569
|
+
const { referrerArgs, referrerInjected } = referral;
|
|
570
|
+
const hireInput = chunkJTSG5FGC_cjs.withoutReferrerArgs(input.hire);
|
|
571
|
+
const activationInput = { ...input.activation ?? {} };
|
|
572
|
+
let activationRecovery = recovery?.phase === "activating" ? recovery : null;
|
|
573
|
+
setPhase(recovery?.phase ?? "hiring");
|
|
574
|
+
setProgress(
|
|
575
|
+
recovery === null ? { ...emptyProgress(), referrerInjected } : progressFromRecovery(recovery, referrerInjected)
|
|
576
|
+
);
|
|
601
577
|
try {
|
|
602
|
-
const
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
listing: input.hire.listing,
|
|
608
|
-
listingSpecHash: hireListingSpecHash,
|
|
609
|
-
moderator: input.hire.moderator
|
|
610
|
-
});
|
|
611
|
-
}
|
|
612
|
-
const hireResult = await client.hireFromListingHumanless({
|
|
613
|
-
...hireInput,
|
|
614
|
-
...hireModerationArgs,
|
|
615
|
-
creator,
|
|
616
|
-
...referrerArgs
|
|
617
|
-
});
|
|
618
|
-
const [taskPda] = await marketplaceSdk.findTaskPda({
|
|
619
|
-
creator: signerAddress(creator),
|
|
620
|
-
taskId: input.hire.taskId
|
|
621
|
-
});
|
|
622
|
-
setProgress({
|
|
623
|
-
...emptyProgress(),
|
|
624
|
-
taskPda,
|
|
625
|
-
hireSignature: hireResult.signature,
|
|
626
|
-
referrerInjected
|
|
627
|
-
});
|
|
628
|
-
setPhase("moderating");
|
|
629
|
-
const moderation = await input.hostAndModerateJobSpec({
|
|
630
|
-
taskPda,
|
|
631
|
-
taskId: input.hire.taskId,
|
|
632
|
-
listing: input.hire.listing,
|
|
578
|
+
const orchestration = {
|
|
579
|
+
hire: {
|
|
580
|
+
...hireInput,
|
|
581
|
+
...referrerArgs
|
|
582
|
+
},
|
|
633
583
|
jobSpec: input.jobSpec,
|
|
634
|
-
|
|
635
|
-
referrerInjected
|
|
636
|
-
});
|
|
637
|
-
const { jobSpecHash, jobSpecUri, moderator } = validateModerationResult(moderation);
|
|
638
|
-
setProgress((current) => ({
|
|
639
|
-
...current,
|
|
640
|
-
jobSpecHash,
|
|
641
|
-
jobSpecUri
|
|
642
|
-
}));
|
|
643
|
-
setPhase("activating");
|
|
644
|
-
const activationModerator = input.activation?.moderator ?? moderator;
|
|
645
|
-
const activationCallerResolved = input.activation?.moderationAttestor !== void 0 || input.activation?.moderatorIsAttestor !== void 0 || input.activation?.taskModeration !== void 0;
|
|
646
|
-
const activationModerationArgs = activationCallerResolved ? {} : await resolveActivationModerationAccounts({
|
|
647
|
-
rpcUrl: ctx.rpcUrl,
|
|
648
|
-
task: taskPda,
|
|
649
|
-
jobSpecHash,
|
|
650
|
-
moderator: activationModerator
|
|
651
|
-
});
|
|
652
|
-
const activationResult = await client.setTaskJobSpec({
|
|
653
|
-
...input.activation ?? {},
|
|
654
|
-
...activationModerationArgs,
|
|
655
|
-
task: taskPda,
|
|
584
|
+
activation: activationInput,
|
|
656
585
|
creator,
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
586
|
+
hostAndModerateJobSpec: async (host) => {
|
|
587
|
+
const committed = {
|
|
588
|
+
phase: "moderating",
|
|
589
|
+
taskPda: host.taskPda,
|
|
590
|
+
hireSignature: host.hireSignature,
|
|
591
|
+
hireIntentDigest: host.hireIntentDigest,
|
|
592
|
+
...host.hireReconciled === true ? { hireReconciled: true } : {}
|
|
593
|
+
};
|
|
594
|
+
setProgress(progressFromRecovery(committed, referrerInjected));
|
|
595
|
+
const moderation = await input.hostAndModerateJobSpec({
|
|
596
|
+
taskPda: host.taskPda,
|
|
597
|
+
taskId: host.taskId,
|
|
598
|
+
listing: host.listing,
|
|
599
|
+
jobSpec: host.jobSpec,
|
|
600
|
+
hireSignature: host.hireSignature,
|
|
601
|
+
...host.hireReconciled === true ? { hireReconciled: true } : {},
|
|
602
|
+
referrerInjected
|
|
603
|
+
});
|
|
604
|
+
const validated = validateModerationResult(
|
|
605
|
+
moderation,
|
|
606
|
+
input.hire.taskJobSpecHash
|
|
607
|
+
);
|
|
608
|
+
const activationModerator = input.activation?.moderator ?? validated.moderator;
|
|
609
|
+
activationRecovery = {
|
|
610
|
+
phase: "activating",
|
|
611
|
+
taskPda: host.taskPda,
|
|
612
|
+
hireSignature: host.hireSignature,
|
|
613
|
+
hireIntentDigest: host.hireIntentDigest,
|
|
614
|
+
...host.hireReconciled === true ? { hireReconciled: true } : {},
|
|
615
|
+
...validated,
|
|
616
|
+
moderator: activationModerator
|
|
617
|
+
};
|
|
618
|
+
return moderation;
|
|
619
|
+
},
|
|
620
|
+
onPhase: (nextPhase) => {
|
|
621
|
+
setPhase(nextPhase);
|
|
622
|
+
if (nextPhase === "activating" && activationRecovery !== null) {
|
|
623
|
+
setProgress(
|
|
624
|
+
progressFromRecovery(activationRecovery, referrerInjected)
|
|
625
|
+
);
|
|
626
|
+
}
|
|
627
|
+
},
|
|
628
|
+
...rpc !== null ? { rpc } : {},
|
|
629
|
+
...rpcUrl !== null ? { rpcUrl } : {}
|
|
630
|
+
};
|
|
631
|
+
const orchestrationResult = recovery === null ? await marketplaceSdk.hireAndActivate(client, orchestration) : await marketplaceSdk.resumeHireAndActivate(client, orchestration, recovery);
|
|
661
632
|
const result = {
|
|
662
|
-
taskPda,
|
|
663
|
-
hireSignature:
|
|
664
|
-
activationSignature:
|
|
665
|
-
jobSpecHash,
|
|
666
|
-
jobSpecUri,
|
|
633
|
+
taskPda: orchestrationResult.taskPda,
|
|
634
|
+
hireSignature: orchestrationResult.hireSignature,
|
|
635
|
+
activationSignature: orchestrationResult.activationSignature,
|
|
636
|
+
jobSpecHash: orchestrationResult.jobSpecHash,
|
|
637
|
+
jobSpecUri: orchestrationResult.jobSpecUri,
|
|
667
638
|
referrerInjected,
|
|
668
|
-
|
|
639
|
+
...orchestrationResult.hireReconciled === true ? { hireReconciled: true } : {},
|
|
640
|
+
...orchestrationResult.activationReconciled === true ? { activationReconciled: true } : {},
|
|
641
|
+
moderation: orchestrationResult.moderation
|
|
669
642
|
};
|
|
670
|
-
setProgress(
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
643
|
+
setProgress({
|
|
644
|
+
taskPda: result.taskPda,
|
|
645
|
+
hireSignature: result.hireSignature || null,
|
|
646
|
+
activationSignature: result.activationSignature || null,
|
|
647
|
+
jobSpecHash: result.jobSpecHash,
|
|
648
|
+
jobSpecUri: result.jobSpecUri,
|
|
649
|
+
referrerInjected,
|
|
650
|
+
recovery: null
|
|
651
|
+
});
|
|
674
652
|
setPhase("activated");
|
|
675
653
|
return result;
|
|
676
654
|
} catch (error) {
|
|
655
|
+
if (error instanceof marketplaceSdk.HireAndActivateError) {
|
|
656
|
+
setProgress(progressFromRecovery(error.progress, referrerInjected));
|
|
657
|
+
} else if (error instanceof marketplaceSdk.HireAndActivateFinalizedFailure) {
|
|
658
|
+
setProgress({ ...emptyProgress(), referrerInjected });
|
|
659
|
+
}
|
|
677
660
|
setPhase("error");
|
|
678
661
|
throw error;
|
|
679
662
|
}
|
|
@@ -686,12 +669,44 @@ function useHumanlessHireFlow() {
|
|
|
686
669
|
}
|
|
687
670
|
flowInFlight.current = true;
|
|
688
671
|
try {
|
|
689
|
-
|
|
672
|
+
const client = chunkJTSG5FGC_cjs.requireClient(ctx.client);
|
|
673
|
+
const snapshot = snapshotFlowInput(input, client.signer);
|
|
674
|
+
return await mutation.mutateAsync({
|
|
675
|
+
...snapshot,
|
|
676
|
+
recovery: null,
|
|
677
|
+
client,
|
|
678
|
+
rpc: ctx.orchestrationRpc,
|
|
679
|
+
rpcUrl: ctx.orchestrationRpcUrl,
|
|
680
|
+
referral: chunkJTSG5FGC_cjs.resolveReferrerArgs(ctx)
|
|
681
|
+
});
|
|
682
|
+
} finally {
|
|
683
|
+
flowInFlight.current = false;
|
|
684
|
+
}
|
|
685
|
+
},
|
|
686
|
+
[ctx, mutation]
|
|
687
|
+
);
|
|
688
|
+
const resumeHireAndActivate = react.useCallback(
|
|
689
|
+
async (input, recovery) => {
|
|
690
|
+
if (flowInFlight.current) {
|
|
691
|
+
throw new Error("A humanless hire flow is already in progress.");
|
|
692
|
+
}
|
|
693
|
+
flowInFlight.current = true;
|
|
694
|
+
try {
|
|
695
|
+
const client = chunkJTSG5FGC_cjs.requireClient(ctx.client);
|
|
696
|
+
const snapshot = snapshotFlowInput(input, client.signer);
|
|
697
|
+
return await mutation.mutateAsync({
|
|
698
|
+
...snapshot,
|
|
699
|
+
recovery: snapshotRecovery(recovery),
|
|
700
|
+
client,
|
|
701
|
+
rpc: ctx.orchestrationRpc,
|
|
702
|
+
rpcUrl: ctx.orchestrationRpcUrl,
|
|
703
|
+
referral: chunkJTSG5FGC_cjs.resolveReferrerArgs(ctx)
|
|
704
|
+
});
|
|
690
705
|
} finally {
|
|
691
706
|
flowInFlight.current = false;
|
|
692
707
|
}
|
|
693
708
|
},
|
|
694
|
-
[mutation]
|
|
709
|
+
[ctx, mutation]
|
|
695
710
|
);
|
|
696
711
|
const reset = react.useCallback(() => {
|
|
697
712
|
mutation.reset();
|
|
@@ -700,8 +715,9 @@ function useHumanlessHireFlow() {
|
|
|
700
715
|
}, [mutation]);
|
|
701
716
|
return {
|
|
702
717
|
hireAndActivate,
|
|
718
|
+
resumeHireAndActivate,
|
|
703
719
|
phase,
|
|
704
|
-
status: mutationStatusOf(mutation),
|
|
720
|
+
status: chunkJTSG5FGC_cjs.mutationStatusOf(mutation),
|
|
705
721
|
progress,
|
|
706
722
|
result: mutation.data ?? null,
|
|
707
723
|
error: mutation.error ?? null,
|
|
@@ -710,10 +726,10 @@ function useHumanlessHireFlow() {
|
|
|
710
726
|
};
|
|
711
727
|
}
|
|
712
728
|
function useTaskWork(taskPda) {
|
|
713
|
-
const ctx = useAgencContext();
|
|
729
|
+
const ctx = chunkJTSG5FGC_cjs.useAgencContext();
|
|
730
|
+
const lastAction = react.useRef(null);
|
|
714
731
|
const claimMut = reactQuery.useMutation({
|
|
715
|
-
mutationFn: async (input) => {
|
|
716
|
-
const client = requireClient(ctx.client);
|
|
732
|
+
mutationFn: async ({ client, input }) => {
|
|
717
733
|
const { signature } = await client.claimTaskWithJobSpec({
|
|
718
734
|
...input,
|
|
719
735
|
task: taskPda
|
|
@@ -722,8 +738,7 @@ function useTaskWork(taskPda) {
|
|
|
722
738
|
}
|
|
723
739
|
});
|
|
724
740
|
const submitMut = reactQuery.useMutation({
|
|
725
|
-
mutationFn: async (input) => {
|
|
726
|
-
const client = requireClient(ctx.client);
|
|
741
|
+
mutationFn: async ({ client, input }) => {
|
|
727
742
|
const { signature } = await client.submitTaskResult({
|
|
728
743
|
...input,
|
|
729
744
|
task: taskPda
|
|
@@ -731,84 +746,175 @@ function useTaskWork(taskPda) {
|
|
|
731
746
|
return signature;
|
|
732
747
|
}
|
|
733
748
|
});
|
|
734
|
-
const claim = react.useCallback(
|
|
749
|
+
const claim = react.useCallback(
|
|
750
|
+
async (input) => {
|
|
751
|
+
const client = chunkJTSG5FGC_cjs.requireClient(ctx.client);
|
|
752
|
+
const detachedInput = chunkJTSG5FGC_cjs.snapshotRecord(input);
|
|
753
|
+
const authority = chunkJTSG5FGC_cjs.stabilizeSelectedTransactionSigner(
|
|
754
|
+
client.signer,
|
|
755
|
+
detachedInput.authority
|
|
756
|
+
);
|
|
757
|
+
const snapshottedInput = chunkJTSG5FGC_cjs.snapshotRecord({
|
|
758
|
+
...detachedInput,
|
|
759
|
+
authority,
|
|
760
|
+
...detachedInput.jobSpecHash === void 0 ? {} : {
|
|
761
|
+
jobSpecHash: chunkJTSG5FGC_cjs.snapshotFixedBytes32(
|
|
762
|
+
detachedInput.jobSpecHash,
|
|
763
|
+
"useTaskWork.claim: jobSpecHash"
|
|
764
|
+
)
|
|
765
|
+
}
|
|
766
|
+
});
|
|
767
|
+
lastAction.current = "claim";
|
|
768
|
+
return claimMut.mutateAsync({ client, input: snapshottedInput });
|
|
769
|
+
},
|
|
770
|
+
[claimMut, ctx.client]
|
|
771
|
+
);
|
|
735
772
|
const submit = react.useCallback(
|
|
736
|
-
(input) =>
|
|
737
|
-
|
|
773
|
+
async (input) => {
|
|
774
|
+
const client = chunkJTSG5FGC_cjs.requireClient(ctx.client);
|
|
775
|
+
const detachedInput = chunkJTSG5FGC_cjs.snapshotRecord(input);
|
|
776
|
+
const authority = chunkJTSG5FGC_cjs.stabilizeSelectedTransactionSigner(
|
|
777
|
+
client.signer,
|
|
778
|
+
detachedInput.authority
|
|
779
|
+
);
|
|
780
|
+
const snapshottedInput = chunkJTSG5FGC_cjs.snapshotRecord({
|
|
781
|
+
...detachedInput,
|
|
782
|
+
authority,
|
|
783
|
+
proofHash: chunkJTSG5FGC_cjs.snapshotFixedBytes32(
|
|
784
|
+
detachedInput.proofHash,
|
|
785
|
+
"useTaskWork.submit: proofHash"
|
|
786
|
+
),
|
|
787
|
+
resultData: chunkJTSG5FGC_cjs.snapshotOptionalFixedBytes(
|
|
788
|
+
detachedInput.resultData,
|
|
789
|
+
64,
|
|
790
|
+
"useTaskWork.submit: resultData"
|
|
791
|
+
)
|
|
792
|
+
});
|
|
793
|
+
lastAction.current = "submit";
|
|
794
|
+
return submitMut.mutateAsync({ client, input: snapshottedInput });
|
|
795
|
+
},
|
|
796
|
+
[ctx.client, submitMut]
|
|
738
797
|
);
|
|
739
798
|
const active = claimMut.isPending || submitMut.isPending;
|
|
740
|
-
const latest =
|
|
799
|
+
const latest = lastAction.current === "submit" ? submitMut : claimMut;
|
|
741
800
|
return {
|
|
742
801
|
claim,
|
|
743
802
|
submit,
|
|
744
|
-
status: active ? "pending" : mutationStatusOf(latest),
|
|
803
|
+
status: active ? "pending" : chunkJTSG5FGC_cjs.mutationStatusOf(latest),
|
|
745
804
|
signature: latest.data ?? null,
|
|
746
|
-
error:
|
|
805
|
+
error: latest.error ?? null,
|
|
747
806
|
isPending: active,
|
|
748
807
|
reset: () => {
|
|
808
|
+
lastAction.current = null;
|
|
749
809
|
claimMut.reset();
|
|
750
810
|
submitMut.reset();
|
|
751
811
|
}
|
|
752
812
|
};
|
|
753
813
|
}
|
|
754
814
|
function useTaskLifecycle(taskPda) {
|
|
755
|
-
const ctx = useAgencContext();
|
|
815
|
+
const ctx = chunkJTSG5FGC_cjs.useAgencContext();
|
|
816
|
+
const lastAction = react.useRef(null);
|
|
756
817
|
const cancelMut = reactQuery.useMutation({
|
|
757
|
-
mutationFn: async (input) => {
|
|
758
|
-
const client = requireClient(ctx.client);
|
|
818
|
+
mutationFn: async ({ client, input }) => {
|
|
759
819
|
const { signature } = await client.cancelTask({
|
|
760
|
-
...input
|
|
761
|
-
task: taskPda
|
|
762
|
-
authority: input?.authority ?? client.signer
|
|
820
|
+
...input,
|
|
821
|
+
task: taskPda
|
|
763
822
|
});
|
|
764
823
|
return signature;
|
|
765
824
|
}
|
|
766
825
|
});
|
|
767
826
|
const closeMut = reactQuery.useMutation({
|
|
768
|
-
mutationFn: async (input) => {
|
|
769
|
-
const client = requireClient(ctx.client);
|
|
827
|
+
mutationFn: async ({ client, input }) => {
|
|
770
828
|
const { signature } = await client.closeTask({
|
|
771
|
-
...input
|
|
772
|
-
task: taskPda
|
|
773
|
-
authority: input?.authority ?? client.signer
|
|
829
|
+
...input,
|
|
830
|
+
task: taskPda
|
|
774
831
|
});
|
|
775
832
|
return signature;
|
|
776
833
|
}
|
|
777
834
|
});
|
|
778
835
|
const autoAcceptMut = reactQuery.useMutation({
|
|
779
|
-
mutationFn: async (input) => {
|
|
780
|
-
const client = requireClient(ctx.client);
|
|
836
|
+
mutationFn: async ({ client, input }) => {
|
|
781
837
|
const { signature } = await client.autoAcceptTaskResult({
|
|
782
838
|
...input,
|
|
783
|
-
task: taskPda
|
|
784
|
-
authority: input.authority ?? client.signer
|
|
839
|
+
task: taskPda
|
|
785
840
|
});
|
|
786
841
|
return signature;
|
|
787
842
|
}
|
|
788
843
|
});
|
|
789
844
|
const cancel = react.useCallback(
|
|
790
|
-
(input) =>
|
|
791
|
-
|
|
845
|
+
async (input) => {
|
|
846
|
+
const client = chunkJTSG5FGC_cjs.requireClient(ctx.client);
|
|
847
|
+
const detachedInput = chunkJTSG5FGC_cjs.snapshotRecord(input ?? {});
|
|
848
|
+
const authority = chunkJTSG5FGC_cjs.stabilizeSelectedTransactionSigner(
|
|
849
|
+
client.signer,
|
|
850
|
+
detachedInput.authority
|
|
851
|
+
);
|
|
852
|
+
const snapshottedInput = chunkJTSG5FGC_cjs.snapshotRecord({
|
|
853
|
+
...detachedInput,
|
|
854
|
+
authority,
|
|
855
|
+
// audit F5/F12: cancelTask requires the bond PDAs; the SDK facade derives
|
|
856
|
+
// them from authority / workerBondAuthority. Default the worker wallet to
|
|
857
|
+
// the task PDA itself — it can never be a bond poster (PDAs can't sign),
|
|
858
|
+
// so the derived worker-bond PDA is the empty no-op account.
|
|
859
|
+
workerBondAuthority: detachedInput.workerBondAuthority ?? taskPda,
|
|
860
|
+
...detachedInput.workerAccounts === void 0 ? {} : {
|
|
861
|
+
workerAccounts: chunkJTSG5FGC_cjs.snapshotRecordArray(detachedInput.workerAccounts)
|
|
862
|
+
},
|
|
863
|
+
...detachedInput.bidSettlement === void 0 ? {} : { bidSettlement: chunkJTSG5FGC_cjs.snapshotRecord(detachedInput.bidSettlement) }
|
|
864
|
+
});
|
|
865
|
+
lastAction.current = "cancel";
|
|
866
|
+
return cancelMut.mutateAsync({ client, input: snapshottedInput });
|
|
867
|
+
},
|
|
868
|
+
[cancelMut, ctx.client]
|
|
792
869
|
);
|
|
793
870
|
const close = react.useCallback(
|
|
794
|
-
(input) =>
|
|
795
|
-
|
|
871
|
+
async (input) => {
|
|
872
|
+
const client = chunkJTSG5FGC_cjs.requireClient(ctx.client);
|
|
873
|
+
const detachedInput = chunkJTSG5FGC_cjs.snapshotRecord(input ?? {});
|
|
874
|
+
const authority = chunkJTSG5FGC_cjs.stabilizeSelectedTransactionSigner(
|
|
875
|
+
client.signer,
|
|
876
|
+
detachedInput.authority
|
|
877
|
+
);
|
|
878
|
+
const snapshottedInput = chunkJTSG5FGC_cjs.snapshotRecord({
|
|
879
|
+
...detachedInput,
|
|
880
|
+
authority,
|
|
881
|
+
...detachedInput.children === void 0 ? {} : { children: chunkJTSG5FGC_cjs.snapshotRecordArray(detachedInput.children) }
|
|
882
|
+
});
|
|
883
|
+
lastAction.current = "close";
|
|
884
|
+
return closeMut.mutateAsync({ client, input: snapshottedInput });
|
|
885
|
+
},
|
|
886
|
+
[closeMut, ctx.client]
|
|
796
887
|
);
|
|
797
888
|
const autoAccept = react.useCallback(
|
|
798
|
-
(input) =>
|
|
799
|
-
|
|
889
|
+
async (input) => {
|
|
890
|
+
const client = chunkJTSG5FGC_cjs.requireClient(ctx.client);
|
|
891
|
+
const detachedInput = chunkJTSG5FGC_cjs.snapshotRecord(input);
|
|
892
|
+
const authority = chunkJTSG5FGC_cjs.stabilizeSelectedTransactionSigner(
|
|
893
|
+
client.signer,
|
|
894
|
+
detachedInput.authority
|
|
895
|
+
);
|
|
896
|
+
const snapshottedInput = chunkJTSG5FGC_cjs.snapshotRecord({
|
|
897
|
+
...detachedInput,
|
|
898
|
+
authority,
|
|
899
|
+
...detachedInput.bidSettlement === void 0 ? {} : { bidSettlement: chunkJTSG5FGC_cjs.snapshotRecord(detachedInput.bidSettlement) }
|
|
900
|
+
});
|
|
901
|
+
lastAction.current = "autoAccept";
|
|
902
|
+
return autoAcceptMut.mutateAsync({ client, input: snapshottedInput });
|
|
903
|
+
},
|
|
904
|
+
[autoAcceptMut, ctx.client]
|
|
800
905
|
);
|
|
801
906
|
const active = cancelMut.isPending || closeMut.isPending || autoAcceptMut.isPending;
|
|
802
|
-
const latest =
|
|
907
|
+
const latest = lastAction.current === "close" ? closeMut : lastAction.current === "autoAccept" ? autoAcceptMut : cancelMut;
|
|
803
908
|
return {
|
|
804
909
|
cancel,
|
|
805
910
|
close,
|
|
806
911
|
autoAccept,
|
|
807
|
-
status: active ? "pending" : mutationStatusOf(latest),
|
|
912
|
+
status: active ? "pending" : chunkJTSG5FGC_cjs.mutationStatusOf(latest),
|
|
808
913
|
signature: latest.data ?? null,
|
|
809
|
-
error:
|
|
914
|
+
error: latest.error ?? null,
|
|
810
915
|
isPending: active,
|
|
811
916
|
reset: () => {
|
|
917
|
+
lastAction.current = null;
|
|
812
918
|
cancelMut.reset();
|
|
813
919
|
closeMut.reset();
|
|
814
920
|
autoAcceptMut.reset();
|
|
@@ -816,22 +922,40 @@ function useTaskLifecycle(taskPda) {
|
|
|
816
922
|
};
|
|
817
923
|
}
|
|
818
924
|
function useRateHire(taskPda) {
|
|
819
|
-
const ctx = useAgencContext();
|
|
925
|
+
const ctx = chunkJTSG5FGC_cjs.useAgencContext();
|
|
820
926
|
const mutation = reactQuery.useMutation({
|
|
821
|
-
mutationFn: async (input) => {
|
|
822
|
-
const client = requireClient(ctx.client);
|
|
927
|
+
mutationFn: async ({ client, input }) => {
|
|
823
928
|
const { signature } = await client.rateHire({
|
|
824
929
|
...input,
|
|
825
|
-
task: taskPda
|
|
826
|
-
buyer: input.buyer ?? client.signer
|
|
930
|
+
task: taskPda
|
|
827
931
|
});
|
|
828
932
|
return signature;
|
|
829
933
|
}
|
|
830
934
|
});
|
|
831
|
-
const rate = react.useCallback(
|
|
935
|
+
const rate = react.useCallback(
|
|
936
|
+
async (input) => {
|
|
937
|
+
const client = chunkJTSG5FGC_cjs.requireClient(ctx.client);
|
|
938
|
+
const detachedInput = chunkJTSG5FGC_cjs.snapshotRecord(input);
|
|
939
|
+
const buyer = chunkJTSG5FGC_cjs.stabilizeSelectedTransactionSigner(
|
|
940
|
+
client.signer,
|
|
941
|
+
detachedInput.buyer
|
|
942
|
+
);
|
|
943
|
+
const snapshottedInput = chunkJTSG5FGC_cjs.snapshotRecord({
|
|
944
|
+
...detachedInput,
|
|
945
|
+
buyer,
|
|
946
|
+
reviewHash: chunkJTSG5FGC_cjs.snapshotOptionalFixedBytes(
|
|
947
|
+
detachedInput.reviewHash,
|
|
948
|
+
32,
|
|
949
|
+
"useRateHire.rate: reviewHash"
|
|
950
|
+
)
|
|
951
|
+
});
|
|
952
|
+
return mutation.mutateAsync({ client, input: snapshottedInput });
|
|
953
|
+
},
|
|
954
|
+
[ctx.client, mutation]
|
|
955
|
+
);
|
|
832
956
|
return {
|
|
833
957
|
rate,
|
|
834
|
-
status: mutationStatusOf(mutation),
|
|
958
|
+
status: chunkJTSG5FGC_cjs.mutationStatusOf(mutation),
|
|
835
959
|
signature: mutation.data ?? null,
|
|
836
960
|
error: mutation.error ?? null,
|
|
837
961
|
isPending: mutation.isPending,
|
|
@@ -839,29 +963,54 @@ function useRateHire(taskPda) {
|
|
|
839
963
|
};
|
|
840
964
|
}
|
|
841
965
|
function useDispute(taskPda, options) {
|
|
842
|
-
const ctx = useAgencContext();
|
|
966
|
+
const ctx = chunkJTSG5FGC_cjs.useAgencContext();
|
|
843
967
|
const reader = options?.disputeReader;
|
|
844
968
|
const enabled = (options?.enabled ?? true) && Boolean(taskPda) && Boolean(reader);
|
|
845
969
|
const read = reactQuery.useQuery({
|
|
846
|
-
queryKey: queryKeys.dispute(
|
|
970
|
+
queryKey: chunkJTSG5FGC_cjs.queryKeys.dispute(
|
|
971
|
+
taskPda ? chunkJTSG5FGC_cjs.pdaKey(taskPda) : "",
|
|
972
|
+
ctx.cacheNamespace
|
|
973
|
+
),
|
|
847
974
|
enabled,
|
|
848
975
|
queryFn: () => reader(taskPda)
|
|
849
976
|
});
|
|
850
977
|
const mutation = reactQuery.useMutation({
|
|
851
|
-
mutationFn: async (input) => {
|
|
852
|
-
const client = requireClient(ctx.client);
|
|
978
|
+
mutationFn: async ({ client, input }) => {
|
|
853
979
|
const { signature } = await client.initiateDispute({
|
|
854
980
|
...input,
|
|
855
|
-
task: taskPda
|
|
856
|
-
authority: input.authority ?? client.signer
|
|
981
|
+
task: taskPda
|
|
857
982
|
});
|
|
858
983
|
void read.refetch();
|
|
859
984
|
return signature;
|
|
860
985
|
}
|
|
861
986
|
});
|
|
862
987
|
const initiate = react.useCallback(
|
|
863
|
-
(input) =>
|
|
864
|
-
|
|
988
|
+
async (input) => {
|
|
989
|
+
const client = chunkJTSG5FGC_cjs.requireClient(ctx.client);
|
|
990
|
+
const detachedInput = chunkJTSG5FGC_cjs.snapshotRecord(input);
|
|
991
|
+
const authority = chunkJTSG5FGC_cjs.stabilizeSelectedTransactionSigner(
|
|
992
|
+
client.signer,
|
|
993
|
+
detachedInput.authority
|
|
994
|
+
);
|
|
995
|
+
const snapshottedInput = chunkJTSG5FGC_cjs.snapshotRecord({
|
|
996
|
+
...detachedInput,
|
|
997
|
+
authority,
|
|
998
|
+
disputeId: chunkJTSG5FGC_cjs.snapshotFixedBytes32(
|
|
999
|
+
detachedInput.disputeId,
|
|
1000
|
+
"useDispute.initiate: disputeId"
|
|
1001
|
+
),
|
|
1002
|
+
taskId: chunkJTSG5FGC_cjs.snapshotFixedBytes32(
|
|
1003
|
+
detachedInput.taskId,
|
|
1004
|
+
"useDispute.initiate: taskId"
|
|
1005
|
+
),
|
|
1006
|
+
evidenceHash: chunkJTSG5FGC_cjs.snapshotFixedBytes32(
|
|
1007
|
+
detachedInput.evidenceHash,
|
|
1008
|
+
"useDispute.initiate: evidenceHash"
|
|
1009
|
+
)
|
|
1010
|
+
});
|
|
1011
|
+
return mutation.mutateAsync({ client, input: snapshottedInput });
|
|
1012
|
+
},
|
|
1013
|
+
[ctx.client, mutation]
|
|
865
1014
|
);
|
|
866
1015
|
const status = mutation.isPending ? "pending" : mutation.isError ? "error" : mutation.isSuccess ? "success" : "idle";
|
|
867
1016
|
return {
|
|
@@ -875,15 +1024,82 @@ function useDispute(taskPda, options) {
|
|
|
875
1024
|
reset: mutation.reset
|
|
876
1025
|
};
|
|
877
1026
|
}
|
|
878
|
-
function
|
|
879
|
-
const ctx = useAgencContext();
|
|
880
|
-
const
|
|
881
|
-
const
|
|
882
|
-
const
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
1027
|
+
function useCompletionBond(taskPda) {
|
|
1028
|
+
const ctx = chunkJTSG5FGC_cjs.useAgencContext();
|
|
1029
|
+
const queryClient = reactQuery.useQueryClient();
|
|
1030
|
+
const lastAction = react.useRef(null);
|
|
1031
|
+
const invalidateGuarantee = react.useCallback(() => {
|
|
1032
|
+
void queryClient.invalidateQueries({
|
|
1033
|
+
queryKey: chunkJTSG5FGC_cjs.queryKeys.taskGuarantee(chunkJTSG5FGC_cjs.pdaKey(taskPda), ctx.cacheNamespace)
|
|
1034
|
+
});
|
|
1035
|
+
}, [ctx.cacheNamespace, queryClient, taskPda]);
|
|
1036
|
+
const postMut = reactQuery.useMutation({
|
|
1037
|
+
mutationFn: async ({ client, input }) => {
|
|
1038
|
+
const { signature } = await client.postCompletionBond({
|
|
1039
|
+
...input,
|
|
1040
|
+
task: taskPda
|
|
1041
|
+
});
|
|
1042
|
+
invalidateGuarantee();
|
|
1043
|
+
return signature;
|
|
1044
|
+
}
|
|
1045
|
+
});
|
|
1046
|
+
const reclaimMut = reactQuery.useMutation({
|
|
1047
|
+
mutationFn: async ({ client, input }) => {
|
|
1048
|
+
const { signature } = await client.reclaimCompletionBond({
|
|
1049
|
+
...input,
|
|
1050
|
+
task: taskPda
|
|
1051
|
+
});
|
|
1052
|
+
invalidateGuarantee();
|
|
1053
|
+
return signature;
|
|
1054
|
+
}
|
|
1055
|
+
});
|
|
1056
|
+
const post = react.useCallback(
|
|
1057
|
+
async (input) => {
|
|
1058
|
+
const client = chunkJTSG5FGC_cjs.requireClient(ctx.client);
|
|
1059
|
+
const detachedInput = chunkJTSG5FGC_cjs.snapshotRecord(input);
|
|
1060
|
+
const authority = chunkJTSG5FGC_cjs.stabilizeSelectedTransactionSigner(
|
|
1061
|
+
client.signer,
|
|
1062
|
+
detachedInput.authority
|
|
1063
|
+
);
|
|
1064
|
+
const snapshottedInput = chunkJTSG5FGC_cjs.snapshotRecord({
|
|
1065
|
+
...detachedInput,
|
|
1066
|
+
authority
|
|
1067
|
+
});
|
|
1068
|
+
lastAction.current = "post";
|
|
1069
|
+
return postMut.mutateAsync({ client, input: snapshottedInput });
|
|
1070
|
+
},
|
|
1071
|
+
[ctx.client, postMut]
|
|
1072
|
+
);
|
|
1073
|
+
const reclaim = react.useCallback(
|
|
1074
|
+
async (input) => {
|
|
1075
|
+
const client = chunkJTSG5FGC_cjs.requireClient(ctx.client);
|
|
1076
|
+
const detachedInput = chunkJTSG5FGC_cjs.snapshotRecord(input);
|
|
1077
|
+
const feePayer = chunkJTSG5FGC_cjs.stabilizeSelectedTransactionSigner(client.signer);
|
|
1078
|
+
const snapshottedInput = chunkJTSG5FGC_cjs.snapshotRecord({
|
|
1079
|
+
...detachedInput,
|
|
1080
|
+
party: detachedInput.party ?? feePayer.address
|
|
1081
|
+
});
|
|
1082
|
+
lastAction.current = "reclaim";
|
|
1083
|
+
return reclaimMut.mutateAsync({ client, input: snapshottedInput });
|
|
1084
|
+
},
|
|
1085
|
+
[ctx.client, reclaimMut]
|
|
1086
|
+
);
|
|
1087
|
+
const isPending = postMut.isPending || reclaimMut.isPending;
|
|
1088
|
+
const latest = lastAction.current === "reclaim" ? reclaimMut : postMut;
|
|
1089
|
+
const status = isPending ? "pending" : chunkJTSG5FGC_cjs.mutationStatusOf(latest);
|
|
1090
|
+
return {
|
|
1091
|
+
post,
|
|
1092
|
+
reclaim,
|
|
1093
|
+
status,
|
|
1094
|
+
error: latest.error ?? null,
|
|
1095
|
+
signature: latest.data ?? null,
|
|
1096
|
+
isPending,
|
|
1097
|
+
reset: () => {
|
|
1098
|
+
lastAction.current = null;
|
|
1099
|
+
postMut.reset();
|
|
1100
|
+
reclaimMut.reset();
|
|
1101
|
+
}
|
|
1102
|
+
};
|
|
887
1103
|
}
|
|
888
1104
|
var EARNINGS_INDEXER_DEFAULTS = {
|
|
889
1105
|
mainnet: "https://api.agenc.ag"
|
|
@@ -892,13 +1108,16 @@ function resolveEarningsBaseUrl(ctx) {
|
|
|
892
1108
|
return ctx.indexerBaseUrl ?? EARNINGS_INDEXER_DEFAULTS[ctx.network] ?? null;
|
|
893
1109
|
}
|
|
894
1110
|
function useReferrerEarnings(wallet) {
|
|
895
|
-
const ctx = useAgencContext();
|
|
1111
|
+
const ctx = chunkJTSG5FGC_cjs.useAgencContext();
|
|
896
1112
|
const capability = ctx.resolveReferrerCapability();
|
|
897
1113
|
const earningsBase = resolveEarningsBaseUrl(ctx);
|
|
898
1114
|
const enabled = capability.live && earningsBase !== null && Boolean(wallet);
|
|
899
1115
|
const query = reactQuery.useQuery(
|
|
900
1116
|
{
|
|
901
|
-
queryKey: queryKeys.referrerEarnings(
|
|
1117
|
+
queryKey: chunkJTSG5FGC_cjs.queryKeys.referrerEarnings(
|
|
1118
|
+
wallet ? chunkJTSG5FGC_cjs.pdaKey(wallet) : "",
|
|
1119
|
+
ctx.cacheNamespace
|
|
1120
|
+
),
|
|
902
1121
|
enabled,
|
|
903
1122
|
queryFn: async () => {
|
|
904
1123
|
const url = `${earningsBase}/api/explorer/referrers/${encodeURIComponent(
|
|
@@ -909,7 +1128,7 @@ function useReferrerEarnings(wallet) {
|
|
|
909
1128
|
});
|
|
910
1129
|
if (!response.ok) {
|
|
911
1130
|
throw new Error(
|
|
912
|
-
t("referrer.earningsFetchFailed") + ` (HTTP ${response.status})`
|
|
1131
|
+
chunkFIDFPM5A_cjs.t("referrer.earningsFetchFailed") + ` (HTTP ${response.status})`
|
|
913
1132
|
);
|
|
914
1133
|
}
|
|
915
1134
|
const body = await response.json();
|
|
@@ -933,7 +1152,7 @@ function useReferrerEarnings(wallet) {
|
|
|
933
1152
|
hires: [],
|
|
934
1153
|
isLoading: false,
|
|
935
1154
|
error: null,
|
|
936
|
-
reason: capability.live ? t("referrer.earningsNotLiveReason") : capability.reason ?? t("referrer.notLiveReason"),
|
|
1155
|
+
reason: capability.live ? chunkFIDFPM5A_cjs.t("referrer.earningsNotLiveReason") : capability.reason ?? chunkFIDFPM5A_cjs.t("referrer.notLiveReason"),
|
|
937
1156
|
refetch: () => {
|
|
938
1157
|
}
|
|
939
1158
|
};
|
|
@@ -948,12 +1167,30 @@ function useReferrerEarnings(wallet) {
|
|
|
948
1167
|
};
|
|
949
1168
|
}
|
|
950
1169
|
|
|
951
|
-
exports
|
|
1170
|
+
Object.defineProperty(exports, "QUERY_KEY_ROOT", {
|
|
1171
|
+
enumerable: true,
|
|
1172
|
+
get: function () { return chunkJTSG5FGC_cjs.QUERY_KEY_ROOT; }
|
|
1173
|
+
});
|
|
1174
|
+
Object.defineProperty(exports, "queryKeys", {
|
|
1175
|
+
enumerable: true,
|
|
1176
|
+
get: function () { return chunkJTSG5FGC_cjs.queryKeys; }
|
|
1177
|
+
});
|
|
1178
|
+
Object.defineProperty(exports, "useHire", {
|
|
1179
|
+
enumerable: true,
|
|
1180
|
+
get: function () { return chunkJTSG5FGC_cjs.useHire; }
|
|
1181
|
+
});
|
|
1182
|
+
Object.defineProperty(exports, "useTaskGuarantee", {
|
|
1183
|
+
enumerable: true,
|
|
1184
|
+
get: function () { return chunkJTSG5FGC_cjs.useTaskGuarantee; }
|
|
1185
|
+
});
|
|
1186
|
+
Object.defineProperty(exports, "useWalletSigner", {
|
|
1187
|
+
enumerable: true,
|
|
1188
|
+
get: function () { return chunkJTSG5FGC_cjs.useWalletSigner; }
|
|
1189
|
+
});
|
|
952
1190
|
exports.projectTrackRecord = projectTrackRecord;
|
|
953
|
-
exports.queryKeys = queryKeys;
|
|
954
1191
|
exports.useAgentTrackRecord = useAgentTrackRecord;
|
|
1192
|
+
exports.useCompletionBond = useCompletionBond;
|
|
955
1193
|
exports.useDispute = useDispute;
|
|
956
|
-
exports.useHire = useHire;
|
|
957
1194
|
exports.useHumanlessHireFlow = useHumanlessHireFlow;
|
|
958
1195
|
exports.useListing = useListing;
|
|
959
1196
|
exports.useListings = useListings;
|
|
@@ -964,6 +1201,5 @@ exports.useTaskActivation = useTaskActivation;
|
|
|
964
1201
|
exports.useTaskLifecycle = useTaskLifecycle;
|
|
965
1202
|
exports.useTaskStatus = useTaskStatus;
|
|
966
1203
|
exports.useTaskWork = useTaskWork;
|
|
967
|
-
exports.useWalletSigner = useWalletSigner;
|
|
968
1204
|
//# sourceMappingURL=index.cjs.map
|
|
969
1205
|
//# sourceMappingURL=index.cjs.map
|