@tetsuo-ai/marketplace-react 0.4.1 → 0.6.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.
Files changed (84) hide show
  1. package/CHANGELOG.md +65 -0
  2. package/README.md +97 -51
  3. package/dist/chunk-7NKRSPPN.js +227 -0
  4. package/dist/chunk-7NKRSPPN.js.map +1 -0
  5. package/dist/{chunk-JVXGNW3Q.js → chunk-CDDHUFMG.js} +6 -5
  6. package/dist/chunk-CDDHUFMG.js.map +1 -0
  7. package/dist/chunk-FIDFPM5A.cjs +40 -0
  8. package/dist/chunk-FIDFPM5A.cjs.map +1 -0
  9. package/dist/chunk-IJKWKY4H.cjs +1370 -0
  10. package/dist/chunk-IJKWKY4H.cjs.map +1 -0
  11. package/dist/chunk-JTSG5FGC.cjs +397 -0
  12. package/dist/chunk-JTSG5FGC.cjs.map +1 -0
  13. package/dist/chunk-ONC6L3IX.cjs +97 -0
  14. package/dist/chunk-ONC6L3IX.cjs.map +1 -0
  15. package/dist/chunk-R76EUYDI.cjs +233 -0
  16. package/dist/chunk-R76EUYDI.cjs.map +1 -0
  17. package/dist/{chunk-XLA7DARS.js → chunk-RG5JZ6JL.js} +159 -36
  18. package/dist/chunk-RG5JZ6JL.js.map +1 -0
  19. package/dist/components/index.cjs +158 -1594
  20. package/dist/components/index.cjs.map +1 -1
  21. package/dist/components/index.d.cts +2 -2
  22. package/dist/components/index.d.ts +2 -2
  23. package/dist/components/index.js +2 -2
  24. package/dist/hooks/index.cjs +656 -509
  25. package/dist/hooks/index.cjs.map +1 -1
  26. package/dist/hooks/index.d.cts +63 -29
  27. package/dist/hooks/index.d.ts +63 -29
  28. package/dist/hooks/index.js +619 -196
  29. package/dist/hooks/index.js.map +1 -1
  30. package/dist/{index-CmVz0OOm.d.ts → index-BAyr1ODZ.d.ts} +28 -3
  31. package/dist/{index-DAZzhuO4.d.cts → index-C20NVU7_.d.cts} +28 -3
  32. package/dist/index.cjs +284 -1833
  33. package/dist/index.cjs.map +1 -1
  34. package/dist/index.d.cts +7 -8
  35. package/dist/index.d.ts +7 -8
  36. package/dist/index.js +64 -4
  37. package/dist/index.js.map +1 -1
  38. package/dist/signers/index.cjs +22 -161
  39. package/dist/signers/index.cjs.map +1 -1
  40. package/dist/signers/index.d.cts +16 -11
  41. package/dist/signers/index.d.ts +16 -11
  42. package/dist/signers/index.js +1 -1
  43. package/dist/testing/index.d.cts +1 -1
  44. package/dist/testing/index.d.ts +1 -1
  45. package/dist/theme/agenc-tailwind-preset.cjs +134 -108
  46. package/dist/{types-jvISR6bc.d.cts → types-B10rndEI.d.cts} +16 -7
  47. package/dist/{types-jvISR6bc.d.ts → types-B10rndEI.d.ts} +16 -7
  48. package/dist/{useAgentTrackRecord-DPt3SfYz.d.cts → useAgentTrackRecord-Ch7gHTFj.d.cts} +1 -1
  49. package/dist/{useAgentTrackRecord-DPt3SfYz.d.ts → useAgentTrackRecord-Ch7gHTFj.d.ts} +1 -1
  50. package/package.json +7 -4
  51. package/src/components/HireCheckoutModal.tsx +5 -2
  52. package/src/hooks/index.ts +1 -0
  53. package/src/hooks/internal.ts +178 -24
  54. package/src/hooks/useAgentTrackRecord.ts +5 -2
  55. package/src/hooks/useCompletionBond.ts +56 -21
  56. package/src/hooks/useDispute.ts +46 -9
  57. package/src/hooks/useHire.ts +113 -23
  58. package/src/hooks/useHumanlessHireFlow.ts +335 -115
  59. package/src/hooks/useListing.ts +2 -2
  60. package/src/hooks/useListings.ts +2 -2
  61. package/src/hooks/useRateHire.ts +32 -5
  62. package/src/hooks/useReferrerEarnings.ts +4 -1
  63. package/src/hooks/useSubmissionReview.ts +95 -32
  64. package/src/hooks/useTaskActivation.ts +51 -9
  65. package/src/hooks/useTaskGuarantee.ts +4 -1
  66. package/src/hooks/useTaskLifecycle.ts +104 -24
  67. package/src/hooks/useTaskStatus.ts +121 -26
  68. package/src/hooks/useTaskWork.ts +76 -12
  69. package/src/hooks/useWalletSigner.ts +11 -16
  70. package/src/index.ts +3 -0
  71. package/src/provider/AgencProvider.tsx +95 -3
  72. package/src/provider/referrer.ts +1 -1
  73. package/src/signers/README.md +13 -7
  74. package/src/signers/index.ts +6 -1
  75. package/src/signers/strings.ts +13 -1
  76. package/src/signers/types.ts +16 -5
  77. package/src/signers/wallet-account.ts +115 -29
  78. package/src/signers/wallet-adapter.ts +38 -4
  79. package/src/theme/agenc-tailwind-preset.cjs +134 -108
  80. package/src/types.ts +27 -1
  81. package/dist/chunk-JVXGNW3Q.js.map +0 -1
  82. package/dist/chunk-ON6XR4XO.js +0 -128
  83. package/dist/chunk-ON6XR4XO.js.map +0 -1
  84. package/dist/chunk-XLA7DARS.js.map +0 -1
@@ -1,6 +1,19 @@
1
1
  import { useMutation } from "@tanstack/react-query";
2
+ import { address as canonicalAddress } from "@solana/kit";
2
3
  import { useCallback, useRef, useState } from "react";
3
- import { findTaskPda } from "@tetsuo-ai/marketplace-sdk";
4
+ import {
5
+ HireAndActivateError,
6
+ HireAndActivateFinalizedFailure,
7
+ hireAndActivate as runHireAndActivate,
8
+ resumeHireAndActivate as runResumeHireAndActivate,
9
+ snapshotStructuredClone,
10
+ type HireAndActivateActivatingProgress,
11
+ type HireAndActivateInput,
12
+ type HireAndActivateModeratingProgress,
13
+ type HireAndActivateProgress,
14
+ type MarketplaceClient,
15
+ type ModerationAccountReadRpc,
16
+ } from "@tetsuo-ai/marketplace-sdk";
4
17
  import type { facade as facadeNs } from "@tetsuo-ai/marketplace-sdk";
5
18
  import { useAgencContext } from "../provider/context.js";
6
19
  import type { Address } from "../types.js";
@@ -8,15 +21,11 @@ import {
8
21
  mutationStatusOf,
9
22
  requireClient,
10
23
  resolveReferrerArgs,
11
- signerAddress,
24
+ snapshotFixedBytes32,
25
+ stabilizeSelectedTransactionSigner,
12
26
  withoutReferrerArgs,
13
27
  type MutationStatus,
14
28
  } from "./internal.js";
15
- import {
16
- resolveActivationModerationAccounts,
17
- resolveHireListingModerationAccounts,
18
- type HireListingModerationAccounts,
19
- } from "./moderation-attestor.js";
20
29
  import type { HumanlessHireInput } from "./useHire.js";
21
30
  import type { TaskActivationInput } from "./useTaskActivation.js";
22
31
 
@@ -32,8 +41,11 @@ export type HumanlessHireFlowStatus = MutationStatus;
32
41
 
33
42
  export type HumanlessHireFlowHireInput = Omit<
34
43
  HumanlessHireInput,
35
- "humanless" | "creator" | "referrer" | "referrerFeeBps"
36
- >;
44
+ "humanless" | "creator" | "referrer" | "referrerFeeBps" | "listingSpecHash"
45
+ > & {
46
+ /** Exact non-zero listing commitment required by durable SDK recovery. */
47
+ listingSpecHash: NonNullable<HumanlessHireInput["listingSpecHash"]>;
48
+ };
37
49
 
38
50
  export type HumanlessHireFlowActivationInput = Omit<
39
51
  TaskActivationInput,
@@ -47,10 +59,13 @@ export type HumanlessHireFlowActivationInput = Omit<
47
59
  moderator?: TaskActivationInput["moderator"];
48
60
  };
49
61
 
50
- export type HumanlessHireFlowCreator = HumanlessHireInput["creator"];
62
+ export type HumanlessHireFlowCreator = NonNullable<
63
+ HumanlessHireInput["creator"]
64
+ >;
51
65
 
52
- export type HumanlessHireFlowJobSpecHash =
53
- Parameters<typeof facadeNs.setTaskJobSpec>[0]["jobSpecHash"];
66
+ export type HumanlessHireFlowJobSpecHash = Parameters<
67
+ typeof facadeNs.setTaskJobSpec
68
+ >[0]["jobSpecHash"];
54
69
 
55
70
  export interface HumanlessHireFlowModerationResult {
56
71
  jobSpecHash: HumanlessHireFlowJobSpecHash;
@@ -71,6 +86,8 @@ export interface HumanlessHireFlowHostInput<TJobSpec> {
71
86
  listing: HumanlessHireFlowHireInput["listing"];
72
87
  jobSpec: TJobSpec;
73
88
  hireSignature: string;
89
+ /** True when finalized account state, rather than a wire response, proved the hire. */
90
+ hireReconciled?: boolean;
74
91
  referrerInjected: boolean;
75
92
  }
76
93
 
@@ -93,6 +110,12 @@ export interface HumanlessHireFlowProgress {
93
110
  jobSpecHash: HumanlessHireFlowJobSpecHash | null;
94
111
  jobSpecUri: string | null;
95
112
  referrerInjected: boolean;
113
+ /**
114
+ * Durable SDK resume token. Persist this token before retrying a failed
115
+ * post-submission flow; pass it to `resumeHireAndActivate`, never to the
116
+ * funded `hireAndActivate` entry point.
117
+ */
118
+ recovery: HireAndActivateProgress | null;
96
119
  }
97
120
 
98
121
  export interface HumanlessHireFlowResult {
@@ -102,6 +125,8 @@ export interface HumanlessHireFlowResult {
102
125
  jobSpecHash: HumanlessHireFlowJobSpecHash;
103
126
  jobSpecUri: string;
104
127
  referrerInjected: boolean;
128
+ hireReconciled?: boolean;
129
+ activationReconciled?: boolean;
105
130
  moderation?: unknown;
106
131
  }
107
132
 
@@ -109,6 +134,11 @@ export interface UseHumanlessHireFlowResult<TJobSpec = unknown> {
109
134
  hireAndActivate: (
110
135
  input: HumanlessHireFlowInput<TJobSpec>,
111
136
  ) => Promise<HumanlessHireFlowResult>;
137
+ /** Resume an exact durable SDK token without submitting another hire. */
138
+ resumeHireAndActivate: (
139
+ input: HumanlessHireFlowInput<TJobSpec>,
140
+ recovery: HireAndActivateProgress,
141
+ ) => Promise<HumanlessHireFlowResult>;
112
142
  phase: HumanlessHireFlowPhase;
113
143
  status: HumanlessHireFlowStatus;
114
144
  progress: HumanlessHireFlowProgress;
@@ -126,11 +156,126 @@ function emptyProgress(): HumanlessHireFlowProgress {
126
156
  jobSpecHash: null,
127
157
  jobSpecUri: null,
128
158
  referrerInjected: false,
159
+ recovery: null,
160
+ };
161
+ }
162
+
163
+ interface SnapshottedFlowInput<TJobSpec> {
164
+ input: HumanlessHireFlowInput<TJobSpec>;
165
+ creatorAddress: Address;
166
+ }
167
+
168
+ function readCreatorAddress(
169
+ creator: HumanlessHireFlowCreator,
170
+ label: string,
171
+ ): Address {
172
+ try {
173
+ return canonicalAddress(creator.address);
174
+ } catch (cause) {
175
+ throw new TypeError(
176
+ `useHumanlessHireFlow: ${label} must expose a valid Solana address`,
177
+ { cause },
178
+ );
179
+ }
180
+ }
181
+
182
+ function assertCreatorUnchanged(
183
+ creator: HumanlessHireFlowCreator,
184
+ expectedAddress: Address,
185
+ ): HumanlessHireFlowCreator {
186
+ if (readCreatorAddress(creator, "creator") !== expectedAddress) {
187
+ throw new TypeError(
188
+ "useHumanlessHireFlow: creator address changed after enqueue; no transaction was submitted",
189
+ );
190
+ }
191
+ return creator;
192
+ }
193
+
194
+ function snapshotFlowInput<TJobSpec>(
195
+ input: HumanlessHireFlowInput<TJobSpec>,
196
+ defaultCreator: HumanlessHireFlowCreator,
197
+ ): SnapshottedFlowInput<TJobSpec> {
198
+ let jobSpec: TJobSpec;
199
+ try {
200
+ jobSpec = snapshotStructuredClone(
201
+ input.jobSpec,
202
+ "useHumanlessHireFlow: jobSpec",
203
+ );
204
+ } catch (cause) {
205
+ throw new TypeError(
206
+ "useHumanlessHireFlow: jobSpec must be structured-cloneable",
207
+ { cause },
208
+ );
209
+ }
210
+ const creator = stabilizeSelectedTransactionSigner(
211
+ defaultCreator,
212
+ input.creator,
213
+ ) as HumanlessHireFlowCreator;
214
+ return {
215
+ creatorAddress: readCreatorAddress(creator, "creator"),
216
+ input: {
217
+ ...input,
218
+ hire: {
219
+ ...input.hire,
220
+ taskId: snapshotFixedBytes32(
221
+ input.hire.taskId,
222
+ "useHumanlessHireFlow: hire.taskId",
223
+ ),
224
+ listingSpecHash: snapshotFixedBytes32(
225
+ input.hire.listingSpecHash,
226
+ "useHumanlessHireFlow: hire.listingSpecHash",
227
+ ),
228
+ taskJobSpecHash: snapshotFixedBytes32(
229
+ input.hire.taskJobSpecHash,
230
+ "useHumanlessHireFlow: hire.taskJobSpecHash",
231
+ ),
232
+ },
233
+ jobSpec,
234
+ ...(input.activation === undefined
235
+ ? {}
236
+ : { activation: { ...input.activation } }),
237
+ creator,
238
+ },
239
+ };
240
+ }
241
+
242
+ function snapshotRecovery(
243
+ recovery: HireAndActivateProgress,
244
+ ): HireAndActivateProgress {
245
+ return recovery.phase === "activating"
246
+ ? {
247
+ ...recovery,
248
+ jobSpecHash: snapshotFixedBytes32(
249
+ recovery.jobSpecHash,
250
+ "useHumanlessHireFlow: recovery.jobSpecHash",
251
+ ),
252
+ }
253
+ : { ...recovery };
254
+ }
255
+
256
+ function progressFromRecovery(
257
+ recovery: HireAndActivateProgress,
258
+ referrerInjected: boolean,
259
+ ): HumanlessHireFlowProgress {
260
+ const committed = recovery.phase !== "hiring";
261
+ const activating = recovery.phase === "activating" ? recovery : null;
262
+ return {
263
+ taskPda: recovery.taskPda,
264
+ hireSignature:
265
+ committed && recovery.hireSignature !== ""
266
+ ? recovery.hireSignature
267
+ : null,
268
+ activationSignature: null,
269
+ jobSpecHash: activating?.jobSpecHash ?? null,
270
+ jobSpecUri: activating?.jobSpecUri ?? null,
271
+ referrerInjected,
272
+ recovery,
129
273
  };
130
274
  }
131
275
 
132
276
  function validateModerationResult(
133
277
  result: HumanlessHireFlowModerationResult,
278
+ committedHash: HumanlessHireFlowJobSpecHash,
134
279
  ): {
135
280
  jobSpecHash: HumanlessHireFlowJobSpecHash;
136
281
  jobSpecUri: string;
@@ -141,14 +286,22 @@ function validateModerationResult(
141
286
  "Task moderation was not attested; activation was not signed.",
142
287
  );
143
288
  }
144
- if (
145
- !(result.jobSpecHash instanceof Uint8Array) ||
146
- result.jobSpecHash.byteLength !== 32
147
- ) {
289
+ let jobSpecHash: HumanlessHireFlowJobSpecHash;
290
+ try {
291
+ jobSpecHash = snapshotFixedBytes32(
292
+ result.jobSpecHash,
293
+ "useHumanlessHireFlow: moderation.jobSpecHash",
294
+ ) as HumanlessHireFlowJobSpecHash;
295
+ } catch {
148
296
  throw new Error(
149
297
  "Task moderation returned an invalid jobSpecHash; activation was not signed.",
150
298
  );
151
299
  }
300
+ if (!jobSpecHash.every((byte, index) => byte === committedHash[index])) {
301
+ throw new Error(
302
+ "Task moderation returned a jobSpecHash different from the hash committed at hire; activation was not signed.",
303
+ );
304
+ }
152
305
  const jobSpecUri = result.jobSpecUri.trim();
153
306
  if (!jobSpecUri) {
154
307
  throw new Error(
@@ -161,13 +314,15 @@ function validateModerationResult(
161
314
  );
162
315
  }
163
316
  return {
164
- jobSpecHash: result.jobSpecHash,
317
+ jobSpecHash,
165
318
  jobSpecUri,
166
319
  moderator: result.moderator,
167
320
  };
168
321
  }
169
322
 
170
- export function useHumanlessHireFlow<TJobSpec = unknown>(): UseHumanlessHireFlowResult<TJobSpec> {
323
+ export function useHumanlessHireFlow<
324
+ TJobSpec = unknown,
325
+ >(): UseHumanlessHireFlowResult<TJobSpec> {
171
326
  const ctx = useAgencContext();
172
327
  const [phase, setPhase] = useState<HumanlessHireFlowPhase>("idle");
173
328
  const [progress, setProgress] =
@@ -177,117 +332,145 @@ export function useHumanlessHireFlow<TJobSpec = unknown>(): UseHumanlessHireFlow
177
332
  const mutation = useMutation<
178
333
  HumanlessHireFlowResult,
179
334
  Error,
180
- HumanlessHireFlowInput<TJobSpec>
335
+ {
336
+ input: HumanlessHireFlowInput<TJobSpec>;
337
+ creatorAddress: Address;
338
+ recovery: HireAndActivateProgress | null;
339
+ client: MarketplaceClient;
340
+ rpc: ModerationAccountReadRpc | null;
341
+ rpcUrl: string | null;
342
+ referral: ReturnType<typeof resolveReferrerArgs>;
343
+ }
181
344
  >({
182
- mutationFn: async (input) => {
183
- const client = requireClient(ctx.client);
184
- const creator = input.creator ?? client.signer;
185
- const { referrerArgs, referrerInjected } = resolveReferrerArgs(ctx);
345
+ mutationFn: async ({
346
+ input,
347
+ creatorAddress,
348
+ recovery,
349
+ client,
350
+ rpc,
351
+ rpcUrl,
352
+ referral,
353
+ }) => {
354
+ // The public boundary already canonicalized same-address fee-payer
355
+ // overrides and stabilized distinct signers. Re-read the locked address
356
+ // defensively before any funded orchestration work begins.
357
+ const creator = assertCreatorUnchanged(input.creator!, creatorAddress);
358
+ const { referrerArgs, referrerInjected } = referral;
186
359
  const hireInput = withoutReferrerArgs(input.hire);
360
+ const activationInput: NonNullable<
361
+ HireAndActivateInput<TJobSpec>["activation"]
362
+ > = { ...(input.activation ?? {}) };
363
+ let activationRecovery: HireAndActivateActivatingProgress | null =
364
+ recovery?.phase === "activating" ? recovery : null;
187
365
 
188
- setPhase("hiring");
189
- setProgress(emptyProgress());
366
+ setPhase(recovery?.phase ?? "hiring");
367
+ setProgress(
368
+ recovery === null
369
+ ? { ...emptyProgress(), referrerInjected }
370
+ : progressFromRecovery(recovery, referrerInjected),
371
+ );
190
372
 
191
373
  try {
192
- // P1.2: resolve the hire gate's moderation mechanics (roster PDA /
193
- // legacy record override) unless the caller supplied any of them.
194
- const hireListingSpecHash = input.hire.listingSpecHash;
195
- let hireModerationArgs: HireListingModerationAccounts = {};
196
- if (
197
- input.hire.moderationAttestor === undefined &&
198
- input.hire.moderatorIsAttestor === undefined &&
199
- input.hire.listingModeration === undefined &&
200
- hireListingSpecHash !== undefined
201
- ) {
202
- hireModerationArgs = await resolveHireListingModerationAccounts({
203
- rpcUrl: ctx.rpcUrl,
204
- listing: input.hire.listing,
205
- listingSpecHash: hireListingSpecHash,
206
- moderator: input.hire.moderator,
207
- });
208
- }
209
- const hireResult = await client.hireFromListingHumanless({
210
- ...hireInput,
211
- ...hireModerationArgs,
374
+ // The SDK owns automatic hire-moderation account resolution. Keeping
375
+ // those transaction-mechanics fields outside this wrapper's logical
376
+ // input makes the intent digest identical on an ambiguous resume.
377
+ const orchestration: HireAndActivateInput<TJobSpec> = {
378
+ hire: {
379
+ ...hireInput,
380
+ ...referrerArgs,
381
+ } as HireAndActivateInput<TJobSpec>["hire"],
382
+ jobSpec: input.jobSpec,
383
+ activation: activationInput,
212
384
  creator,
213
- ...referrerArgs,
214
- } as Parameters<typeof facadeNs.hireFromListingHumanless>[0]);
215
-
216
- const [taskPda] = await findTaskPda({
217
- creator: signerAddress(creator),
218
- taskId: input.hire.taskId,
219
- });
220
-
221
- setProgress({
222
- ...emptyProgress(),
223
- taskPda,
224
- hireSignature: hireResult.signature,
225
- referrerInjected,
226
- });
385
+ hostAndModerateJobSpec: async (host) => {
386
+ const committed: HireAndActivateModeratingProgress = {
387
+ phase: "moderating",
388
+ taskPda: host.taskPda,
389
+ hireSignature: host.hireSignature,
390
+ hireIntentDigest: host.hireIntentDigest,
391
+ ...(host.hireReconciled === true ? { hireReconciled: true } : {}),
392
+ };
393
+ setProgress(progressFromRecovery(committed, referrerInjected));
227
394
 
228
- setPhase("moderating");
229
- const moderation = await input.hostAndModerateJobSpec({
230
- taskPda,
231
- taskId: input.hire.taskId,
232
- listing: input.hire.listing,
233
- jobSpec: input.jobSpec,
234
- hireSignature: hireResult.signature,
235
- referrerInjected,
236
- });
237
- const { jobSpecHash, jobSpecUri, moderator } =
238
- validateModerationResult(moderation);
239
-
240
- setProgress((current) => ({
241
- ...current,
242
- jobSpecHash,
243
- jobSpecUri,
244
- }));
245
-
246
- setPhase("activating");
247
- // P1.2: the publish gate consumes the record of the moderator that
248
- // signed the attestation (the host callback's service by default).
249
- // Resolve the gate mechanics (roster PDA / legacy record override)
250
- // unless the caller supplied any of them.
251
- const activationModerator = input.activation?.moderator ?? moderator;
252
- const activationCallerResolved =
253
- input.activation?.moderationAttestor !== undefined ||
254
- input.activation?.moderatorIsAttestor !== undefined ||
255
- input.activation?.taskModeration !== undefined;
256
- const activationModerationArgs = activationCallerResolved
257
- ? {}
258
- : await resolveActivationModerationAccounts({
259
- rpcUrl: ctx.rpcUrl,
260
- task: taskPda,
261
- jobSpecHash,
262
- moderator: activationModerator,
395
+ const moderation = await input.hostAndModerateJobSpec({
396
+ taskPda: host.taskPda,
397
+ taskId: host.taskId,
398
+ listing: host.listing,
399
+ jobSpec: host.jobSpec,
400
+ hireSignature: host.hireSignature,
401
+ ...(host.hireReconciled === true ? { hireReconciled: true } : {}),
402
+ referrerInjected,
263
403
  });
264
- const activationResult = await client.setTaskJobSpec({
265
- ...(input.activation ?? {}),
266
- ...activationModerationArgs,
267
- task: taskPda,
268
- creator,
269
- jobSpecHash,
270
- jobSpecUri,
271
- moderator: activationModerator,
272
- } as Parameters<typeof facadeNs.setTaskJobSpec>[0]);
404
+ const validated = validateModerationResult(
405
+ moderation,
406
+ input.hire.taskJobSpecHash,
407
+ );
408
+ const activationModerator =
409
+ input.activation?.moderator ?? validated.moderator;
410
+ activationRecovery = {
411
+ phase: "activating",
412
+ taskPda: host.taskPda,
413
+ hireSignature: host.hireSignature,
414
+ hireIntentDigest: host.hireIntentDigest,
415
+ ...(host.hireReconciled === true ? { hireReconciled: true } : {}),
416
+ ...validated,
417
+ moderator: activationModerator,
418
+ };
419
+ return moderation;
420
+ },
421
+ onPhase: (nextPhase) => {
422
+ setPhase(nextPhase);
423
+ if (nextPhase === "activating" && activationRecovery !== null) {
424
+ setProgress(
425
+ progressFromRecovery(activationRecovery, referrerInjected),
426
+ );
427
+ }
428
+ },
429
+ ...(rpc !== null ? { rpc } : {}),
430
+ ...(rpcUrl !== null ? { rpcUrl } : {}),
431
+ };
432
+
433
+ const orchestrationResult =
434
+ recovery === null
435
+ ? await runHireAndActivate(client, orchestration)
436
+ : await runResumeHireAndActivate(client, orchestration, recovery);
273
437
 
274
438
  const result: HumanlessHireFlowResult = {
275
- taskPda,
276
- hireSignature: hireResult.signature,
277
- activationSignature: activationResult.signature,
278
- jobSpecHash,
279
- jobSpecUri,
439
+ taskPda: orchestrationResult.taskPda,
440
+ hireSignature: orchestrationResult.hireSignature,
441
+ activationSignature: orchestrationResult.activationSignature,
442
+ jobSpecHash: orchestrationResult.jobSpecHash,
443
+ jobSpecUri: orchestrationResult.jobSpecUri,
280
444
  referrerInjected,
281
- moderation: moderation.moderation,
445
+ ...(orchestrationResult.hireReconciled === true
446
+ ? { hireReconciled: true }
447
+ : {}),
448
+ ...(orchestrationResult.activationReconciled === true
449
+ ? { activationReconciled: true }
450
+ : {}),
451
+ moderation: orchestrationResult.moderation,
282
452
  };
283
453
 
284
- setProgress((current) => ({
285
- ...current,
286
- activationSignature: activationResult.signature,
287
- }));
454
+ setProgress({
455
+ taskPda: result.taskPda,
456
+ hireSignature: result.hireSignature || null,
457
+ activationSignature: result.activationSignature || null,
458
+ jobSpecHash: result.jobSpecHash,
459
+ jobSpecUri: result.jobSpecUri,
460
+ referrerInjected,
461
+ recovery: null,
462
+ });
288
463
  setPhase("activated");
289
464
  return result;
290
465
  } catch (error) {
466
+ if (error instanceof HireAndActivateError) {
467
+ setProgress(progressFromRecovery(error.progress, referrerInjected));
468
+ } else if (error instanceof HireAndActivateFinalizedFailure) {
469
+ // The exact candidate transaction failed atomically and the SDK
470
+ // proved no hire accounts exist. Discard the non-resubmitting token;
471
+ // the surfaced retrySafe error explicitly permits a corrected retry.
472
+ setProgress({ ...emptyProgress(), referrerInjected });
473
+ }
291
474
  setPhase("error");
292
475
  throw error;
293
476
  }
@@ -301,12 +484,48 @@ export function useHumanlessHireFlow<TJobSpec = unknown>(): UseHumanlessHireFlow
301
484
  }
302
485
  flowInFlight.current = true;
303
486
  try {
304
- return await mutation.mutateAsync(input);
487
+ const client = requireClient(ctx.client);
488
+ const snapshot = snapshotFlowInput(input, client.signer);
489
+ return await mutation.mutateAsync({
490
+ ...snapshot,
491
+ recovery: null,
492
+ client,
493
+ rpc: ctx.orchestrationRpc,
494
+ rpcUrl: ctx.orchestrationRpcUrl,
495
+ referral: resolveReferrerArgs(ctx),
496
+ });
497
+ } finally {
498
+ flowInFlight.current = false;
499
+ }
500
+ },
501
+ [ctx, mutation],
502
+ );
503
+
504
+ const resumeHireAndActivate = useCallback(
505
+ async (
506
+ input: HumanlessHireFlowInput<TJobSpec>,
507
+ recovery: HireAndActivateProgress,
508
+ ) => {
509
+ if (flowInFlight.current) {
510
+ throw new Error("A humanless hire flow is already in progress.");
511
+ }
512
+ flowInFlight.current = true;
513
+ try {
514
+ const client = requireClient(ctx.client);
515
+ const snapshot = snapshotFlowInput(input, client.signer);
516
+ return await mutation.mutateAsync({
517
+ ...snapshot,
518
+ recovery: snapshotRecovery(recovery),
519
+ client,
520
+ rpc: ctx.orchestrationRpc,
521
+ rpcUrl: ctx.orchestrationRpcUrl,
522
+ referral: resolveReferrerArgs(ctx),
523
+ });
305
524
  } finally {
306
525
  flowInFlight.current = false;
307
526
  }
308
527
  },
309
- [mutation],
528
+ [ctx, mutation],
310
529
  );
311
530
 
312
531
  const reset = useCallback(() => {
@@ -317,6 +536,7 @@ export function useHumanlessHireFlow<TJobSpec = unknown>(): UseHumanlessHireFlow
317
536
 
318
537
  return {
319
538
  hireAndActivate,
539
+ resumeHireAndActivate,
320
540
  phase,
321
541
  status: mutationStatusOf(mutation),
322
542
  progress,
@@ -93,11 +93,11 @@ export function useListing(
93
93
  pda: Address | string | undefined | null,
94
94
  options?: UseListingOptions,
95
95
  ): UseListingResult {
96
- const { read } = useAgencContext();
96
+ const { read, cacheNamespace } = useAgencContext();
97
97
  const enabled = (options?.enabled ?? true) && Boolean(pda);
98
98
 
99
99
  const query = useQuery<ListingDetail, Error>({
100
- queryKey: queryKeys.listing(pda ? pdaKey(pda) : ""),
100
+ queryKey: queryKeys.listing(pda ? pdaKey(pda) : "", cacheNamespace),
101
101
  enabled,
102
102
  queryFn: async () => {
103
103
  // 1) The listing itself.
@@ -89,12 +89,12 @@ export function useListings(
89
89
  filter?: UseListingsFilter,
90
90
  options?: UseListingsOptions,
91
91
  ): UseListingsResult {
92
- const { read } = useAgencContext();
92
+ const { read, cacheNamespace } = useAgencContext();
93
93
  const pageSize = options?.pageSize ?? DEFAULT_PAGE_SIZE;
94
94
  const enabled = options?.enabled ?? true;
95
95
 
96
96
  const query = useQuery<ListingRow[], Error>({
97
- queryKey: queryKeys.listings(filter),
97
+ queryKey: queryKeys.listings(filter, cacheNamespace),
98
98
  queryFn: () => read.listActiveListings(filter),
99
99
  enabled,
100
100
  });
@@ -2,9 +2,13 @@ import { useMutation } from "@tanstack/react-query";
2
2
  import { useCallback } from "react";
3
3
  import type { facade as facadeNs } from "@tetsuo-ai/marketplace-sdk";
4
4
  import { useAgencContext } from "../provider/context.js";
5
+ import type { MarketplaceClient } from "../types.js";
5
6
  import {
6
7
  mutationStatusOf,
7
8
  requireClient,
9
+ snapshotOptionalFixedBytes,
10
+ snapshotRecord,
11
+ stabilizeSelectedTransactionSigner,
8
12
  type MutationStatus,
9
13
  } from "./internal.js";
10
14
 
@@ -16,6 +20,11 @@ export type RateHireInput = Omit<
16
20
  };
17
21
  export type RateHireStatus = MutationStatus;
18
22
 
23
+ interface QueuedRateHireInput {
24
+ readonly client: MarketplaceClient;
25
+ readonly input: RateHireInput;
26
+ }
27
+
19
28
  export interface UseRateHireResult {
20
29
  rate: (input: RateHireInput) => Promise<string>;
21
30
  status: RateHireStatus;
@@ -29,18 +38,36 @@ export function useRateHire(
29
38
  taskPda: Parameters<typeof facadeNs.rateHire>[0]["task"],
30
39
  ): UseRateHireResult {
31
40
  const ctx = useAgencContext();
32
- const mutation = useMutation<string, Error, RateHireInput>({
33
- mutationFn: async (input) => {
34
- const client = requireClient(ctx.client);
41
+ const mutation = useMutation<string, Error, QueuedRateHireInput>({
42
+ mutationFn: async ({ client, input }) => {
35
43
  const { signature } = await client.rateHire({
36
44
  ...input,
37
45
  task: taskPda,
38
- buyer: input.buyer ?? client.signer,
39
46
  } as Parameters<typeof facadeNs.rateHire>[0]);
40
47
  return signature;
41
48
  },
42
49
  });
43
- const rate = useCallback((input: RateHireInput) => mutation.mutateAsync(input), [mutation]);
50
+ const rate = useCallback(
51
+ async (input: RateHireInput) => {
52
+ const client = requireClient(ctx.client);
53
+ const detachedInput = snapshotRecord(input);
54
+ const buyer = stabilizeSelectedTransactionSigner(
55
+ client.signer,
56
+ detachedInput.buyer,
57
+ );
58
+ const snapshottedInput = snapshotRecord({
59
+ ...detachedInput,
60
+ buyer,
61
+ reviewHash: snapshotOptionalFixedBytes(
62
+ detachedInput.reviewHash,
63
+ 32,
64
+ "useRateHire.rate: reviewHash",
65
+ ),
66
+ }) as RateHireInput;
67
+ return mutation.mutateAsync({ client, input: snapshottedInput });
68
+ },
69
+ [ctx.client, mutation],
70
+ );
44
71
  return {
45
72
  rate,
46
73
  status: mutationStatusOf(mutation),
@@ -108,7 +108,10 @@ export function useReferrerEarnings(
108
108
 
109
109
  const query = useQuery<{ totalLamports: bigint; hires: ReferrerHire[] }, Error>(
110
110
  {
111
- queryKey: queryKeys.referrerEarnings(wallet ? pdaKey(wallet) : ""),
111
+ queryKey: queryKeys.referrerEarnings(
112
+ wallet ? pdaKey(wallet) : "",
113
+ ctx.cacheNamespace,
114
+ ),
112
115
  enabled,
113
116
  queryFn: async () => {
114
117
  const url = `${earningsBase}/api/explorer/referrers/${encodeURIComponent(