@tetsuo-ai/marketplace-react 0.3.1 → 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.
Files changed (44) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/dist/{chunk-D2TDU3TJ.js → chunk-AKPPKMQ2.js} +3 -3
  3. package/dist/{chunk-D2TDU3TJ.js.map → chunk-AKPPKMQ2.js.map} +1 -1
  4. package/dist/{chunk-WJUVTFJ7.js → chunk-BNILOX3O.js} +4 -4
  5. package/dist/{chunk-WJUVTFJ7.js.map → chunk-BNILOX3O.js.map} +1 -1
  6. package/dist/{chunk-FAIRTAIB.js → chunk-BTAVED7S.js} +88 -5
  7. package/dist/chunk-BTAVED7S.js.map +1 -0
  8. package/dist/{chunk-ECU7HGO3.js → chunk-H6PJIDQR.js} +4 -3
  9. package/dist/chunk-H6PJIDQR.js.map +1 -0
  10. package/dist/{chunk-MNJ2EQDJ.js → chunk-ON6XR4XO.js} +3 -3
  11. package/dist/{chunk-MNJ2EQDJ.js.map → chunk-ON6XR4XO.js.map} +1 -1
  12. package/dist/components/index.cjs +57 -1
  13. package/dist/components/index.cjs.map +1 -1
  14. package/dist/components/index.d.cts +1 -1
  15. package/dist/components/index.d.ts +1 -1
  16. package/dist/components/index.js +3 -3
  17. package/dist/hooks/index.cjs +159 -48
  18. package/dist/hooks/index.cjs.map +1 -1
  19. package/dist/hooks/index.d.cts +20 -9
  20. package/dist/hooks/index.d.ts +20 -9
  21. package/dist/hooks/index.js +80 -53
  22. package/dist/hooks/index.js.map +1 -1
  23. package/dist/{index-DGq7M4mo.d.ts → index-DQ3Xovkq.d.ts} +8 -1
  24. package/dist/{index-CrEAPlme.d.cts → index-UxuvIlmD.d.cts} +8 -1
  25. package/dist/index.cjs +57 -1
  26. package/dist/index.cjs.map +1 -1
  27. package/dist/index.d.cts +2 -2
  28. package/dist/index.d.ts +2 -2
  29. package/dist/index.js +9 -8
  30. package/dist/index.js.map +1 -1
  31. package/dist/signers/index.cjs +2 -1
  32. package/dist/signers/index.cjs.map +1 -1
  33. package/dist/signers/index.js +2 -2
  34. package/package.json +2 -2
  35. package/src/hooks/moderation-attestor.ts +176 -57
  36. package/src/hooks/useHire.ts +27 -0
  37. package/src/hooks/useHumanlessHireFlow.ts +74 -17
  38. package/src/hooks/useReferrerEarnings.ts +73 -38
  39. package/src/hooks/useTaskActivation.ts +19 -13
  40. package/src/provider/AgencProvider.tsx +1 -0
  41. package/src/strings/index.ts +3 -1
  42. package/src/types.ts +6 -0
  43. package/dist/chunk-ECU7HGO3.js.map +0 -1
  44. package/dist/chunk-FAIRTAIB.js.map +0 -1
@@ -214,13 +214,26 @@ declare function useTaskActivation(taskPda: Parameters<typeof facade.setTaskJobS
214
214
  type HumanlessHireFlowPhase = "idle" | "hiring" | "moderating" | "activating" | "activated" | "error";
215
215
  type HumanlessHireFlowStatus = MutationStatus;
216
216
  type HumanlessHireFlowHireInput = Omit<HumanlessHireInput, "humanless" | "creator" | "referrer" | "referrerFeeBps">;
217
- type HumanlessHireFlowActivationInput = Omit<TaskActivationInput, "creator" | "jobSpecHash" | "jobSpecUri">;
217
+ type HumanlessHireFlowActivationInput = Omit<TaskActivationInput, "creator" | "jobSpecHash" | "jobSpecUri" | "moderator"> & {
218
+ /**
219
+ * Override the activation `moderator` (P1.2). Defaults to the `moderator`
220
+ * returned by `hostAndModerateJobSpec` — the attestation service that
221
+ * signed the task moderation is whose record the publish gate consumes.
222
+ */
223
+ moderator?: TaskActivationInput["moderator"];
224
+ };
218
225
  type HumanlessHireFlowCreator = HumanlessHireInput["creator"];
219
226
  type HumanlessHireFlowJobSpecHash = Parameters<typeof facade.setTaskJobSpec>[0]["jobSpecHash"];
220
227
  interface HumanlessHireFlowModerationResult {
221
228
  jobSpecHash: HumanlessHireFlowJobSpecHash;
222
229
  jobSpecUri: string;
223
230
  moderationAttested: boolean;
231
+ /**
232
+ * The pubkey that signed/recorded the task attestation (P1.2) — the
233
+ * attestation service's signer (e.g. attest.agenc.ag `GET /v1/info` →
234
+ * `moderator`). Names whose record the publish gate consumes.
235
+ */
236
+ moderator: Address;
224
237
  moderation?: unknown;
225
238
  }
226
239
  interface HumanlessHireFlowHostInput<TJobSpec> {
@@ -364,7 +377,7 @@ interface UseWalletSignerResult {
364
377
  */
365
378
  declare function useWalletSigner(options?: UseWalletSignerOptions): UseWalletSignerResult;
366
379
 
367
- /** A single referral-earning hire (shape defined now; populated once the earnings indexer ships). */
380
+ /** A single referral-earning hire. */
368
381
  interface ReferrerHire {
369
382
  /** The minted Task PDA of the referred hire. */
370
383
  taskPda: string;
@@ -372,7 +385,7 @@ interface ReferrerHire {
372
385
  hireRecordPda: string;
373
386
  /** Referral fee earned on this hire, in lamports. */
374
387
  feeLamports: bigint;
375
- /** Transaction signature of the hire. */
388
+ /** Transaction signature of the hire (empty until event indexing lands). */
376
389
  signature: string;
377
390
  }
378
391
  /** Return value of {@link useReferrerEarnings}. */
@@ -387,7 +400,7 @@ interface UseReferrerEarningsResult {
387
400
  totalLamports: bigint;
388
401
  /** Per-hire earnings. `[]` while not live. */
389
402
  hires: ReferrerHire[];
390
- /** True while a fetch is in flight. Always false until the earnings indexer ships. */
403
+ /** True while a fetch is in flight. */
391
404
  isLoading: boolean;
392
405
  /** The fetch error, or null. */
393
406
  error: Error | null;
@@ -400,17 +413,15 @@ interface UseReferrerEarningsResult {
400
413
  refetch: () => void;
401
414
  }
402
415
  /**
403
- * Read a referrer wallet's earnings.
416
+ * Read a referrer wallet's aggregated earnings from the hosted explorer.
404
417
  *
405
418
  * @param wallet - The referrer wallet (base58 / Address). Falsy disables the
406
- * (future) fetch; the not-live state is still returned.
407
- * @returns {@link UseReferrerEarningsResult} — the not-live zero state until
408
- * the earnings indexer ships.
419
+ * fetch; the not-live state is still returned.
420
+ * @returns {@link UseReferrerEarningsResult}
409
421
  *
410
422
  * @example
411
423
  * ```tsx
412
424
  * const { live, totalLamports, hires, reason } = useReferrerEarnings(myWallet);
413
- * // until the earnings indexer ships: live === false, totalLamports === 0n, hires === []
414
425
  * ```
415
426
  */
416
427
  declare function useReferrerEarnings(wallet: Address | string | undefined | null): UseReferrerEarningsResult;
@@ -214,13 +214,26 @@ declare function useTaskActivation(taskPda: Parameters<typeof facade.setTaskJobS
214
214
  type HumanlessHireFlowPhase = "idle" | "hiring" | "moderating" | "activating" | "activated" | "error";
215
215
  type HumanlessHireFlowStatus = MutationStatus;
216
216
  type HumanlessHireFlowHireInput = Omit<HumanlessHireInput, "humanless" | "creator" | "referrer" | "referrerFeeBps">;
217
- type HumanlessHireFlowActivationInput = Omit<TaskActivationInput, "creator" | "jobSpecHash" | "jobSpecUri">;
217
+ type HumanlessHireFlowActivationInput = Omit<TaskActivationInput, "creator" | "jobSpecHash" | "jobSpecUri" | "moderator"> & {
218
+ /**
219
+ * Override the activation `moderator` (P1.2). Defaults to the `moderator`
220
+ * returned by `hostAndModerateJobSpec` — the attestation service that
221
+ * signed the task moderation is whose record the publish gate consumes.
222
+ */
223
+ moderator?: TaskActivationInput["moderator"];
224
+ };
218
225
  type HumanlessHireFlowCreator = HumanlessHireInput["creator"];
219
226
  type HumanlessHireFlowJobSpecHash = Parameters<typeof facade.setTaskJobSpec>[0]["jobSpecHash"];
220
227
  interface HumanlessHireFlowModerationResult {
221
228
  jobSpecHash: HumanlessHireFlowJobSpecHash;
222
229
  jobSpecUri: string;
223
230
  moderationAttested: boolean;
231
+ /**
232
+ * The pubkey that signed/recorded the task attestation (P1.2) — the
233
+ * attestation service's signer (e.g. attest.agenc.ag `GET /v1/info` →
234
+ * `moderator`). Names whose record the publish gate consumes.
235
+ */
236
+ moderator: Address;
224
237
  moderation?: unknown;
225
238
  }
226
239
  interface HumanlessHireFlowHostInput<TJobSpec> {
@@ -364,7 +377,7 @@ interface UseWalletSignerResult {
364
377
  */
365
378
  declare function useWalletSigner(options?: UseWalletSignerOptions): UseWalletSignerResult;
366
379
 
367
- /** A single referral-earning hire (shape defined now; populated once the earnings indexer ships). */
380
+ /** A single referral-earning hire. */
368
381
  interface ReferrerHire {
369
382
  /** The minted Task PDA of the referred hire. */
370
383
  taskPda: string;
@@ -372,7 +385,7 @@ interface ReferrerHire {
372
385
  hireRecordPda: string;
373
386
  /** Referral fee earned on this hire, in lamports. */
374
387
  feeLamports: bigint;
375
- /** Transaction signature of the hire. */
388
+ /** Transaction signature of the hire (empty until event indexing lands). */
376
389
  signature: string;
377
390
  }
378
391
  /** Return value of {@link useReferrerEarnings}. */
@@ -387,7 +400,7 @@ interface UseReferrerEarningsResult {
387
400
  totalLamports: bigint;
388
401
  /** Per-hire earnings. `[]` while not live. */
389
402
  hires: ReferrerHire[];
390
- /** True while a fetch is in flight. Always false until the earnings indexer ships. */
403
+ /** True while a fetch is in flight. */
391
404
  isLoading: boolean;
392
405
  /** The fetch error, or null. */
393
406
  error: Error | null;
@@ -400,17 +413,15 @@ interface UseReferrerEarningsResult {
400
413
  refetch: () => void;
401
414
  }
402
415
  /**
403
- * Read a referrer wallet's earnings.
416
+ * Read a referrer wallet's aggregated earnings from the hosted explorer.
404
417
  *
405
418
  * @param wallet - The referrer wallet (base58 / Address). Falsy disables the
406
- * (future) fetch; the not-live state is still returned.
407
- * @returns {@link UseReferrerEarningsResult} — the not-live zero state until
408
- * the earnings indexer ships.
419
+ * fetch; the not-live state is still returned.
420
+ * @returns {@link UseReferrerEarningsResult}
409
421
  *
410
422
  * @example
411
423
  * ```tsx
412
424
  * const { live, totalLamports, hires, reason } = useReferrerEarnings(myWallet);
413
- * // until the earnings indexer ships: live === false, totalLamports === 0n, hires === []
414
425
  * ```
415
426
  */
416
427
  declare function useReferrerEarnings(wallet: Address | string | undefined | null): UseReferrerEarningsResult;
@@ -1,11 +1,10 @@
1
- import { ReadTransportUnsupportedError } from '../chunk-D2TDU3TJ.js';
2
- import { useAgencContext, queryKeys, pdaKey, requireClient, mutationStatusOf, resolveReferrerArgs, withoutReferrerArgs, signerAddress } from '../chunk-FAIRTAIB.js';
3
- export { QUERY_KEY_ROOT, queryKeys, useHire, useWalletSigner } from '../chunk-FAIRTAIB.js';
4
- import { t } from '../chunk-ECU7HGO3.js';
1
+ import { ReadTransportUnsupportedError } from '../chunk-AKPPKMQ2.js';
2
+ import { useAgencContext, queryKeys, pdaKey, requireClient, resolveActivationModerationAccounts, mutationStatusOf, resolveReferrerArgs, withoutReferrerArgs, resolveHireListingModerationAccounts, signerAddress } from '../chunk-BTAVED7S.js';
3
+ export { QUERY_KEY_ROOT, queryKeys, useHire, useWalletSigner } from '../chunk-BTAVED7S.js';
4
+ import { t } from '../chunk-H6PJIDQR.js';
5
5
  import { useQuery, useMutation } from '@tanstack/react-query';
6
6
  import { useState, useMemo, useCallback, useRef, useEffect } from 'react';
7
- import { TaskStatus, facade, findTaskPda, findTaskModerationPda, fetchMaybeTaskModeration, findModerationConfigPda, fetchMaybeModerationConfig, findModerationAttestorPda } from '@tetsuo-ai/marketplace-sdk';
8
- import { createSolanaRpc } from '@solana/kit';
7
+ import { TaskStatus, facade, findTaskPda } from '@tetsuo-ai/marketplace-sdk';
9
8
 
10
9
  var DEFAULT_PAGE_SIZE = 12;
11
10
  function useListings(filter, options) {
@@ -261,50 +260,21 @@ function useSubmissionReview(taskPda) {
261
260
  }
262
261
  };
263
262
  }
264
- async function resolveActivationModerationAttestor(input) {
265
- try {
266
- const rpc = input.rpc ?? (input.rpcUrl ? createSolanaRpc(input.rpcUrl) : null);
267
- if (!rpc) return void 0;
268
- const [taskModerationPda] = await findTaskModerationPda({
269
- task: input.task,
270
- jobSpecHash: input.jobSpecHash
271
- });
272
- const taskModeration = await fetchMaybeTaskModeration(
273
- rpc,
274
- taskModerationPda
275
- );
276
- if (!taskModeration.exists) return void 0;
277
- const [moderationConfigPda] = await findModerationConfigPda();
278
- const moderationConfig = await fetchMaybeModerationConfig(
279
- rpc,
280
- moderationConfigPda
281
- );
282
- if (moderationConfig.exists && taskModeration.data.moderator === moderationConfig.data.moderationAuthority) {
283
- return void 0;
284
- }
285
- const [rosterPda] = await findModerationAttestorPda({
286
- attestor: taskModeration.data.moderator
287
- });
288
- return rosterPda;
289
- } catch {
290
- return void 0;
291
- }
292
- }
293
-
294
- // src/hooks/useTaskActivation.ts
295
263
  function useTaskActivation(taskPda) {
296
264
  const ctx = useAgencContext();
297
265
  const mutation = useMutation({
298
266
  mutationFn: async (input) => {
299
267
  const client = requireClient(ctx.client);
300
- const moderationAttestor = input.moderationAttestor ?? await resolveActivationModerationAttestor({
268
+ const callerResolved = input.moderationAttestor !== void 0 || input.moderatorIsAttestor !== void 0 || input.taskModeration !== void 0;
269
+ const resolved = callerResolved ? {} : await resolveActivationModerationAccounts({
301
270
  rpcUrl: ctx.rpcUrl,
302
271
  task: taskPda,
303
- jobSpecHash: input.jobSpecHash
272
+ jobSpecHash: input.jobSpecHash,
273
+ moderator: input.moderator
304
274
  });
305
275
  const { signature } = await client.setTaskJobSpec({
306
276
  ...input,
307
- ...moderationAttestor !== void 0 ? { moderationAttestor } : {},
277
+ ...resolved,
308
278
  task: taskPda,
309
279
  creator: input.creator ?? client.signer
310
280
  });
@@ -351,7 +321,16 @@ function validateModerationResult(result) {
351
321
  "Task moderation returned an empty jobSpecUri; activation was not signed."
352
322
  );
353
323
  }
354
- return { jobSpecHash: result.jobSpecHash, jobSpecUri };
324
+ if (typeof result.moderator !== "string" || !result.moderator.trim()) {
325
+ throw new Error(
326
+ "Task moderation returned no moderator pubkey; activation was not signed."
327
+ );
328
+ }
329
+ return {
330
+ jobSpecHash: result.jobSpecHash,
331
+ jobSpecUri,
332
+ moderator: result.moderator
333
+ };
355
334
  }
356
335
  function useHumanlessHireFlow() {
357
336
  const ctx = useAgencContext();
@@ -367,8 +346,19 @@ function useHumanlessHireFlow() {
367
346
  setPhase("hiring");
368
347
  setProgress(emptyProgress());
369
348
  try {
349
+ const hireListingSpecHash = input.hire.listingSpecHash;
350
+ let hireModerationArgs = {};
351
+ if (input.hire.moderationAttestor === void 0 && input.hire.moderatorIsAttestor === void 0 && input.hire.listingModeration === void 0 && hireListingSpecHash !== void 0) {
352
+ hireModerationArgs = await resolveHireListingModerationAccounts({
353
+ rpcUrl: ctx.rpcUrl,
354
+ listing: input.hire.listing,
355
+ listingSpecHash: hireListingSpecHash,
356
+ moderator: input.hire.moderator
357
+ });
358
+ }
370
359
  const hireResult = await client.hireFromListingHumanless({
371
360
  ...hireInput,
361
+ ...hireModerationArgs,
372
362
  creator,
373
363
  ...referrerArgs
374
364
  });
@@ -391,25 +381,29 @@ function useHumanlessHireFlow() {
391
381
  hireSignature: hireResult.signature,
392
382
  referrerInjected
393
383
  });
394
- const { jobSpecHash, jobSpecUri } = validateModerationResult(moderation);
384
+ const { jobSpecHash, jobSpecUri, moderator } = validateModerationResult(moderation);
395
385
  setProgress((current) => ({
396
386
  ...current,
397
387
  jobSpecHash,
398
388
  jobSpecUri
399
389
  }));
400
390
  setPhase("activating");
401
- const moderationAttestor = input.activation?.moderationAttestor ?? await resolveActivationModerationAttestor({
391
+ const activationModerator = input.activation?.moderator ?? moderator;
392
+ const activationCallerResolved = input.activation?.moderationAttestor !== void 0 || input.activation?.moderatorIsAttestor !== void 0 || input.activation?.taskModeration !== void 0;
393
+ const activationModerationArgs = activationCallerResolved ? {} : await resolveActivationModerationAccounts({
402
394
  rpcUrl: ctx.rpcUrl,
403
395
  task: taskPda,
404
- jobSpecHash
396
+ jobSpecHash,
397
+ moderator: activationModerator
405
398
  });
406
399
  const activationResult = await client.setTaskJobSpec({
407
400
  ...input.activation ?? {},
408
- ...moderationAttestor !== void 0 ? { moderationAttestor } : {},
401
+ ...activationModerationArgs,
409
402
  task: taskPda,
410
403
  creator,
411
404
  jobSpecHash,
412
- jobSpecUri
405
+ jobSpecUri,
406
+ moderator: activationModerator
413
407
  });
414
408
  const result = {
415
409
  taskPda,
@@ -628,23 +622,48 @@ function useDispute(taskPda, options) {
628
622
  reset: mutation.reset
629
623
  };
630
624
  }
631
- var EARNINGS_INDEXER_LIVE = false;
625
+ var EARNINGS_INDEXER_DEFAULTS = {
626
+ mainnet: "https://api.agenc.ag"
627
+ };
628
+ function resolveEarningsBaseUrl(ctx) {
629
+ return ctx.indexerBaseUrl ?? EARNINGS_INDEXER_DEFAULTS[ctx.network] ?? null;
630
+ }
632
631
  function useReferrerEarnings(wallet) {
633
632
  const ctx = useAgencContext();
634
633
  const capability = ctx.resolveReferrerCapability();
635
- const enabled = capability.live && EARNINGS_INDEXER_LIVE;
636
- useQuery(
634
+ const earningsBase = resolveEarningsBaseUrl(ctx);
635
+ const enabled = capability.live && earningsBase !== null && Boolean(wallet);
636
+ const query = useQuery(
637
637
  {
638
638
  queryKey: queryKeys.referrerEarnings(wallet ? pdaKey(wallet) : ""),
639
639
  enabled,
640
640
  queryFn: async () => {
641
- throw new Error(
642
- "useReferrerEarnings: the referrer earnings indexer is not deployed; this query must never run while EARNINGS_INDEXER_LIVE is false."
643
- );
641
+ const url = `${earningsBase}/api/explorer/referrers/${encodeURIComponent(
642
+ String(wallet)
643
+ )}/hires`;
644
+ const response = await fetch(url, {
645
+ headers: { accept: "application/json" }
646
+ });
647
+ if (!response.ok) {
648
+ throw new Error(
649
+ t("referrer.earningsFetchFailed") + ` (HTTP ${response.status})`
650
+ );
651
+ }
652
+ const body = await response.json();
653
+ const hires = (body.hires ?? []).map((h) => ({
654
+ taskPda: String(h.taskPda ?? ""),
655
+ hireRecordPda: String(h.hireRecordPda ?? ""),
656
+ feeLamports: BigInt(h.feeLamports ?? "0"),
657
+ signature: String(h.signature ?? "")
658
+ }));
659
+ return {
660
+ totalLamports: BigInt(body.totalLamports ?? "0"),
661
+ hires
662
+ };
644
663
  }
645
664
  }
646
665
  );
647
- if (!capability.live || !EARNINGS_INDEXER_LIVE) {
666
+ if (!enabled) {
648
667
  return {
649
668
  live: false,
650
669
  totalLamports: 0n,
@@ -656,6 +675,14 @@ function useReferrerEarnings(wallet) {
656
675
  }
657
676
  };
658
677
  }
678
+ return {
679
+ live: true,
680
+ totalLamports: query.data?.totalLamports ?? 0n,
681
+ hires: query.data?.hires ?? [],
682
+ isLoading: query.isLoading,
683
+ error: query.error ?? null,
684
+ refetch: () => void query.refetch()
685
+ };
659
686
  }
660
687
 
661
688
  export { projectTrackRecord, useAgentTrackRecord, useDispute, useHumanlessHireFlow, useListing, useListings, useRateHire, useReferrerEarnings, useSubmissionReview, useTaskActivation, useTaskLifecycle, useTaskStatus, useTaskWork };