@tetsuo-ai/marketplace-react 0.3.2 → 0.4.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.
@@ -1,5 +1,5 @@
1
- export { Badge, Button, COMPONENT_CATALOG, DEFAULT_TRUST_HREF, DisputeBanner, EN_COMPONENT_STRINGS, HireButton, HireCheckoutModal, ListingCard, ListingGrid, Modal, ModerationBadge, PoweredByAgenC, ProviderCard, ReferrerDisclosure, ReviewPanel, Spinner, StateMessage, TaskTimeline, UNVERIFIED, VerifiedBadge, agentVerificationReaderFromRpc, cx, decodeListingCategory, decodeListingName, decodeListingTags, elementClass, evaluateAgentVerification, formatPriceSol, formatRate, formatSol, moderationStateOf, rootClass, tc, toHex, truncateAddress, useAgentVerification, useFocusTrap } from '../chunk-ZAMIL27X.js';
2
- import '../chunk-2Y6JN2VZ.js';
1
+ export { Badge, Button, COMPONENT_CATALOG, DEFAULT_TRUST_HREF, DisputeBanner, EN_COMPONENT_STRINGS, HireButton, HireCheckoutModal, ListingCard, ListingGrid, Modal, ModerationBadge, PoweredByAgenC, ProviderCard, ReferrerDisclosure, ReviewPanel, Spinner, StateMessage, TaskTimeline, UNVERIFIED, VerifiedBadge, agentVerificationReaderFromRpc, cx, decodeListingCategory, decodeListingName, decodeListingTags, elementClass, evaluateAgentVerification, formatPriceSol, formatRate, formatSol, moderationStateOf, rootClass, tc, toHex, truncateAddress, useAgentVerification, useFocusTrap } from '../chunk-BNILOX3O.js';
2
+ import '../chunk-BTAVED7S.js';
3
3
  import '../chunk-H6PJIDQR.js';
4
4
  //# sourceMappingURL=index.js.map
5
5
  //# sourceMappingURL=index.js.map
@@ -300,6 +300,76 @@ function useTaskStatus(taskPda, options) {
300
300
  refetch: () => void query.refetch()
301
301
  };
302
302
  }
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
303
373
  function useHire() {
304
374
  const ctx = useAgencContext();
305
375
  const mutation = reactQuery.useMutation({
@@ -307,11 +377,22 @@ function useHire() {
307
377
  const client = requireClient(ctx.client);
308
378
  const { referrerArgs, referrerInjected } = resolveReferrerArgs(ctx);
309
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
+ }
310
390
  const creator = input.creator ?? client.signer;
311
391
  let signature;
312
392
  if (input.humanless === true) {
313
393
  const result = await client.hireFromListingHumanless({
314
394
  ...hireInput,
395
+ ...moderationArgs,
315
396
  creator,
316
397
  ...referrerArgs
317
398
  });
@@ -320,6 +401,7 @@ function useHire() {
320
401
  const authority = input.authority ?? client.signer;
321
402
  const result = await client.hireFromListing({
322
403
  ...hireInput,
404
+ ...moderationArgs,
323
405
  authority,
324
406
  creator,
325
407
  ...referrerArgs
@@ -431,50 +513,21 @@ function useSubmissionReview(taskPda) {
431
513
  }
432
514
  };
433
515
  }
434
- async function resolveActivationModerationAttestor(input) {
435
- try {
436
- const rpc = input.rpc ?? (input.rpcUrl ? kit.createSolanaRpc(input.rpcUrl) : null);
437
- if (!rpc) return void 0;
438
- const [taskModerationPda] = await marketplaceSdk.findTaskModerationPda({
439
- task: input.task,
440
- jobSpecHash: input.jobSpecHash
441
- });
442
- const taskModeration = await marketplaceSdk.fetchMaybeTaskModeration(
443
- rpc,
444
- taskModerationPda
445
- );
446
- if (!taskModeration.exists) return void 0;
447
- const [moderationConfigPda] = await marketplaceSdk.findModerationConfigPda();
448
- const moderationConfig = await marketplaceSdk.fetchMaybeModerationConfig(
449
- rpc,
450
- moderationConfigPda
451
- );
452
- if (moderationConfig.exists && taskModeration.data.moderator === moderationConfig.data.moderationAuthority) {
453
- return void 0;
454
- }
455
- const [rosterPda] = await marketplaceSdk.findModerationAttestorPda({
456
- attestor: taskModeration.data.moderator
457
- });
458
- return rosterPda;
459
- } catch {
460
- return void 0;
461
- }
462
- }
463
-
464
- // src/hooks/useTaskActivation.ts
465
516
  function useTaskActivation(taskPda) {
466
517
  const ctx = useAgencContext();
467
518
  const mutation = reactQuery.useMutation({
468
519
  mutationFn: async (input) => {
469
520
  const client = requireClient(ctx.client);
470
- const moderationAttestor = input.moderationAttestor ?? await resolveActivationModerationAttestor({
521
+ const callerResolved = input.moderationAttestor !== void 0 || input.moderatorIsAttestor !== void 0 || input.taskModeration !== void 0;
522
+ const resolved = callerResolved ? {} : await resolveActivationModerationAccounts({
471
523
  rpcUrl: ctx.rpcUrl,
472
524
  task: taskPda,
473
- jobSpecHash: input.jobSpecHash
525
+ jobSpecHash: input.jobSpecHash,
526
+ moderator: input.moderator
474
527
  });
475
528
  const { signature } = await client.setTaskJobSpec({
476
529
  ...input,
477
- ...moderationAttestor !== void 0 ? { moderationAttestor } : {},
530
+ ...resolved,
478
531
  task: taskPda,
479
532
  creator: input.creator ?? client.signer
480
533
  });
@@ -521,7 +574,16 @@ function validateModerationResult(result) {
521
574
  "Task moderation returned an empty jobSpecUri; activation was not signed."
522
575
  );
523
576
  }
524
- return { jobSpecHash: result.jobSpecHash, jobSpecUri };
577
+ if (typeof result.moderator !== "string" || !result.moderator.trim()) {
578
+ throw new Error(
579
+ "Task moderation returned no moderator pubkey; activation was not signed."
580
+ );
581
+ }
582
+ return {
583
+ jobSpecHash: result.jobSpecHash,
584
+ jobSpecUri,
585
+ moderator: result.moderator
586
+ };
525
587
  }
526
588
  function useHumanlessHireFlow() {
527
589
  const ctx = useAgencContext();
@@ -537,8 +599,19 @@ function useHumanlessHireFlow() {
537
599
  setPhase("hiring");
538
600
  setProgress(emptyProgress());
539
601
  try {
602
+ const hireListingSpecHash = input.hire.listingSpecHash;
603
+ let hireModerationArgs = {};
604
+ if (input.hire.moderationAttestor === void 0 && input.hire.moderatorIsAttestor === void 0 && input.hire.listingModeration === void 0 && hireListingSpecHash !== void 0) {
605
+ hireModerationArgs = await resolveHireListingModerationAccounts({
606
+ rpcUrl: ctx.rpcUrl,
607
+ listing: input.hire.listing,
608
+ listingSpecHash: hireListingSpecHash,
609
+ moderator: input.hire.moderator
610
+ });
611
+ }
540
612
  const hireResult = await client.hireFromListingHumanless({
541
613
  ...hireInput,
614
+ ...hireModerationArgs,
542
615
  creator,
543
616
  ...referrerArgs
544
617
  });
@@ -561,25 +634,29 @@ function useHumanlessHireFlow() {
561
634
  hireSignature: hireResult.signature,
562
635
  referrerInjected
563
636
  });
564
- const { jobSpecHash, jobSpecUri } = validateModerationResult(moderation);
637
+ const { jobSpecHash, jobSpecUri, moderator } = validateModerationResult(moderation);
565
638
  setProgress((current) => ({
566
639
  ...current,
567
640
  jobSpecHash,
568
641
  jobSpecUri
569
642
  }));
570
643
  setPhase("activating");
571
- const moderationAttestor = input.activation?.moderationAttestor ?? await resolveActivationModerationAttestor({
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({
572
647
  rpcUrl: ctx.rpcUrl,
573
648
  task: taskPda,
574
- jobSpecHash
649
+ jobSpecHash,
650
+ moderator: activationModerator
575
651
  });
576
652
  const activationResult = await client.setTaskJobSpec({
577
653
  ...input.activation ?? {},
578
- ...moderationAttestor !== void 0 ? { moderationAttestor } : {},
654
+ ...activationModerationArgs,
579
655
  task: taskPda,
580
656
  creator,
581
657
  jobSpecHash,
582
- jobSpecUri
658
+ jobSpecUri,
659
+ moderator: activationModerator
583
660
  });
584
661
  const result = {
585
662
  taskPda,