@tetsuo-ai/marketplace-react 0.1.0 → 0.2.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 (65) hide show
  1. package/CHANGELOG.md +29 -3
  2. package/README.md +50 -20
  3. package/dist/{chunk-ABS77JB2.js → chunk-D2TDU3TJ.js} +3 -3
  4. package/dist/{chunk-ABS77JB2.js.map → chunk-D2TDU3TJ.js.map} +1 -1
  5. package/dist/{chunk-GN5DYVN5.js → chunk-ECU7HGO3.js} +6 -5
  6. package/dist/chunk-ECU7HGO3.js.map +1 -0
  7. package/dist/{chunk-YORZNYZZ.js → chunk-FAIRTAIB.js} +53 -17
  8. package/dist/chunk-FAIRTAIB.js.map +1 -0
  9. package/dist/{chunk-5OTKSRHM.js → chunk-MNJ2EQDJ.js} +3 -3
  10. package/dist/{chunk-5OTKSRHM.js.map → chunk-MNJ2EQDJ.js.map} +1 -1
  11. package/dist/{chunk-KJMR6OGC.js → chunk-WJUVTFJ7.js} +105 -9
  12. package/dist/chunk-WJUVTFJ7.js.map +1 -0
  13. package/dist/components/agenc-components.css +20 -0
  14. package/dist/components/index.cjs +147 -17
  15. package/dist/components/index.cjs.map +1 -1
  16. package/dist/components/index.d.cts +2 -2
  17. package/dist/components/index.d.ts +2 -2
  18. package/dist/components/index.js +3 -3
  19. package/dist/hooks/index.cjs +350 -28
  20. package/dist/hooks/index.cjs.map +1 -1
  21. package/dist/hooks/index.d.cts +160 -36
  22. package/dist/hooks/index.d.ts +160 -36
  23. package/dist/hooks/index.js +299 -19
  24. package/dist/hooks/index.js.map +1 -1
  25. package/dist/{index-BLrlBVj-.d.cts → index-C9R3B80j.d.ts} +176 -47
  26. package/dist/{index-CKTYsNPH.d.ts → index-CTTh1ZPg.d.cts} +176 -47
  27. package/dist/index.cjs +168 -33
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.d.cts +10 -19
  30. package/dist/index.d.ts +10 -19
  31. package/dist/index.js +17 -12
  32. package/dist/index.js.map +1 -1
  33. package/dist/signers/index.cjs +4 -3
  34. package/dist/signers/index.cjs.map +1 -1
  35. package/dist/signers/index.js +2 -2
  36. package/dist/{useAgentTrackRecord-BLf1nrbu.d.cts → useAgentTrackRecord-BCvRHYM2.d.cts} +7 -7
  37. package/dist/{useAgentTrackRecord-BLf1nrbu.d.ts → useAgentTrackRecord-BCvRHYM2.d.ts} +7 -7
  38. package/package.json +4 -3
  39. package/src/components/HireButton.tsx +1 -2
  40. package/src/components/HireCheckoutModal.tsx +8 -9
  41. package/src/components/ProviderCard.stories.tsx +54 -4
  42. package/src/components/ProviderCard.tsx +113 -9
  43. package/src/components/ReferrerDisclosure.tsx +8 -12
  44. package/src/components/__fixtures__/index.tsx +28 -0
  45. package/src/components/agenc-components.css +20 -0
  46. package/src/components/index.ts +12 -0
  47. package/src/components/strings.ts +10 -2
  48. package/src/components/useAgentVerification.ts +223 -0
  49. package/src/hooks/index.ts +47 -4
  50. package/src/hooks/internal.ts +74 -2
  51. package/src/hooks/useHire.ts +30 -38
  52. package/src/hooks/useHumanlessHireFlow.ts +259 -0
  53. package/src/hooks/useRateHire.ts +52 -0
  54. package/src/hooks/useReferrerEarnings.ts +32 -33
  55. package/src/hooks/useTaskActivation.ts +58 -0
  56. package/src/hooks/useTaskLifecycle.ts +110 -0
  57. package/src/hooks/useTaskWork.ts +76 -0
  58. package/src/index.ts +12 -2
  59. package/src/provider/AgencProvider.tsx +3 -3
  60. package/src/provider/referrer.ts +24 -32
  61. package/src/strings/index.ts +5 -3
  62. package/src/types.ts +7 -10
  63. package/dist/chunk-GN5DYVN5.js.map +0 -1
  64. package/dist/chunk-KJMR6OGC.js.map +0 -1
  65. package/dist/chunk-YORZNYZZ.js.map +0 -1
@@ -1,10 +1,10 @@
1
- import { ReadTransportUnsupportedError } from '../chunk-ABS77JB2.js';
2
- import { useAgencContext, queryKeys, pdaKey, requireClient } from '../chunk-YORZNYZZ.js';
3
- export { QUERY_KEY_ROOT, queryKeys, useHire, useWalletSigner } from '../chunk-YORZNYZZ.js';
4
- import { t } from '../chunk-GN5DYVN5.js';
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';
5
5
  import { useQuery, useMutation } from '@tanstack/react-query';
6
6
  import { useState, useMemo, useCallback, useRef, useEffect } from 'react';
7
- import { TaskStatus, facade } from '@tetsuo-ai/marketplace-sdk';
7
+ import { TaskStatus, facade, findTaskPda } from '@tetsuo-ai/marketplace-sdk';
8
8
 
9
9
  var DEFAULT_PAGE_SIZE = 12;
10
10
  function useListings(filter, options) {
@@ -260,6 +260,293 @@ function useSubmissionReview(taskPda) {
260
260
  }
261
261
  };
262
262
  }
263
+ function useTaskActivation(taskPda) {
264
+ const ctx = useAgencContext();
265
+ const mutation = useMutation({
266
+ mutationFn: async (input) => {
267
+ const client = requireClient(ctx.client);
268
+ const { signature } = await client.setTaskJobSpec({
269
+ ...input,
270
+ task: taskPda,
271
+ creator: input.creator ?? client.signer
272
+ });
273
+ return signature;
274
+ }
275
+ });
276
+ const activate = useCallback(
277
+ (input) => mutation.mutateAsync(input),
278
+ [mutation]
279
+ );
280
+ return {
281
+ activate,
282
+ status: mutationStatusOf(mutation),
283
+ signature: mutation.data ?? null,
284
+ error: mutation.error ?? null,
285
+ isPending: mutation.isPending,
286
+ reset: mutation.reset
287
+ };
288
+ }
289
+ function emptyProgress() {
290
+ return {
291
+ taskPda: null,
292
+ hireSignature: null,
293
+ activationSignature: null,
294
+ jobSpecHash: null,
295
+ jobSpecUri: null,
296
+ referrerInjected: false
297
+ };
298
+ }
299
+ function validateModerationResult(result) {
300
+ if (result.moderationAttested !== true) {
301
+ throw new Error(
302
+ "Task moderation was not attested; activation was not signed."
303
+ );
304
+ }
305
+ if (!(result.jobSpecHash instanceof Uint8Array) || result.jobSpecHash.byteLength !== 32) {
306
+ throw new Error(
307
+ "Task moderation returned an invalid jobSpecHash; activation was not signed."
308
+ );
309
+ }
310
+ const jobSpecUri = result.jobSpecUri.trim();
311
+ if (!jobSpecUri) {
312
+ throw new Error(
313
+ "Task moderation returned an empty jobSpecUri; activation was not signed."
314
+ );
315
+ }
316
+ return { jobSpecHash: result.jobSpecHash, jobSpecUri };
317
+ }
318
+ function useHumanlessHireFlow() {
319
+ const ctx = useAgencContext();
320
+ const [phase, setPhase] = useState("idle");
321
+ const [progress, setProgress] = useState(emptyProgress);
322
+ const flowInFlight = useRef(false);
323
+ const mutation = useMutation({
324
+ mutationFn: async (input) => {
325
+ const client = requireClient(ctx.client);
326
+ const creator = input.creator ?? client.signer;
327
+ const { referrerArgs, referrerInjected } = resolveReferrerArgs(ctx);
328
+ const hireInput = withoutReferrerArgs(input.hire);
329
+ setPhase("hiring");
330
+ setProgress(emptyProgress());
331
+ try {
332
+ const hireResult = await client.hireFromListingHumanless({
333
+ ...hireInput,
334
+ creator,
335
+ ...referrerArgs
336
+ });
337
+ const [taskPda] = await findTaskPda({
338
+ creator: signerAddress(creator),
339
+ taskId: input.hire.taskId
340
+ });
341
+ setProgress({
342
+ ...emptyProgress(),
343
+ taskPda,
344
+ hireSignature: hireResult.signature,
345
+ referrerInjected
346
+ });
347
+ setPhase("moderating");
348
+ const moderation = await input.hostAndModerateJobSpec({
349
+ taskPda,
350
+ taskId: input.hire.taskId,
351
+ listing: input.hire.listing,
352
+ jobSpec: input.jobSpec,
353
+ hireSignature: hireResult.signature,
354
+ referrerInjected
355
+ });
356
+ const { jobSpecHash, jobSpecUri } = validateModerationResult(moderation);
357
+ setProgress((current) => ({
358
+ ...current,
359
+ jobSpecHash,
360
+ jobSpecUri
361
+ }));
362
+ setPhase("activating");
363
+ const activationResult = await client.setTaskJobSpec({
364
+ ...input.activation ?? {},
365
+ task: taskPda,
366
+ creator,
367
+ jobSpecHash,
368
+ jobSpecUri
369
+ });
370
+ const result = {
371
+ taskPda,
372
+ hireSignature: hireResult.signature,
373
+ activationSignature: activationResult.signature,
374
+ jobSpecHash,
375
+ jobSpecUri,
376
+ referrerInjected,
377
+ moderation: moderation.moderation
378
+ };
379
+ setProgress((current) => ({
380
+ ...current,
381
+ activationSignature: activationResult.signature
382
+ }));
383
+ setPhase("activated");
384
+ return result;
385
+ } catch (error) {
386
+ setPhase("error");
387
+ throw error;
388
+ }
389
+ }
390
+ });
391
+ const hireAndActivate = useCallback(
392
+ async (input) => {
393
+ if (flowInFlight.current) {
394
+ throw new Error("A humanless hire flow is already in progress.");
395
+ }
396
+ flowInFlight.current = true;
397
+ try {
398
+ return await mutation.mutateAsync(input);
399
+ } finally {
400
+ flowInFlight.current = false;
401
+ }
402
+ },
403
+ [mutation]
404
+ );
405
+ const reset = useCallback(() => {
406
+ mutation.reset();
407
+ setPhase("idle");
408
+ setProgress(emptyProgress());
409
+ }, [mutation]);
410
+ return {
411
+ hireAndActivate,
412
+ phase,
413
+ status: mutationStatusOf(mutation),
414
+ progress,
415
+ result: mutation.data ?? null,
416
+ error: mutation.error ?? null,
417
+ isPending: mutation.isPending,
418
+ reset
419
+ };
420
+ }
421
+ function useTaskWork(taskPda) {
422
+ const ctx = useAgencContext();
423
+ const claimMut = useMutation({
424
+ mutationFn: async (input) => {
425
+ const client = requireClient(ctx.client);
426
+ const { signature } = await client.claimTaskWithJobSpec({
427
+ ...input,
428
+ task: taskPda
429
+ });
430
+ return signature;
431
+ }
432
+ });
433
+ const submitMut = useMutation({
434
+ mutationFn: async (input) => {
435
+ const client = requireClient(ctx.client);
436
+ const { signature } = await client.submitTaskResult({
437
+ ...input,
438
+ task: taskPda
439
+ });
440
+ return signature;
441
+ }
442
+ });
443
+ const claim = useCallback((input) => claimMut.mutateAsync(input), [claimMut]);
444
+ const submit = useCallback(
445
+ (input) => submitMut.mutateAsync(input),
446
+ [submitMut]
447
+ );
448
+ const active = claimMut.isPending || submitMut.isPending;
449
+ const latest = [claimMut, submitMut].find((m) => m.isError || m.isSuccess) ?? claimMut;
450
+ return {
451
+ claim,
452
+ submit,
453
+ status: active ? "pending" : mutationStatusOf(latest),
454
+ signature: latest.data ?? null,
455
+ error: claimMut.error ?? submitMut.error ?? null,
456
+ isPending: active,
457
+ reset: () => {
458
+ claimMut.reset();
459
+ submitMut.reset();
460
+ }
461
+ };
462
+ }
463
+ function useTaskLifecycle(taskPda) {
464
+ const ctx = useAgencContext();
465
+ const cancelMut = useMutation({
466
+ mutationFn: async (input) => {
467
+ const client = requireClient(ctx.client);
468
+ const { signature } = await client.cancelTask({
469
+ ...input ?? {},
470
+ task: taskPda,
471
+ authority: input?.authority ?? client.signer
472
+ });
473
+ return signature;
474
+ }
475
+ });
476
+ const closeMut = useMutation({
477
+ mutationFn: async (input) => {
478
+ const client = requireClient(ctx.client);
479
+ const { signature } = await client.closeTask({
480
+ ...input ?? {},
481
+ task: taskPda,
482
+ authority: input?.authority ?? client.signer
483
+ });
484
+ return signature;
485
+ }
486
+ });
487
+ const autoAcceptMut = useMutation({
488
+ mutationFn: async (input) => {
489
+ const client = requireClient(ctx.client);
490
+ const { signature } = await client.autoAcceptTaskResult({
491
+ ...input,
492
+ task: taskPda,
493
+ authority: input.authority ?? client.signer
494
+ });
495
+ return signature;
496
+ }
497
+ });
498
+ const cancel = useCallback(
499
+ (input) => cancelMut.mutateAsync(input),
500
+ [cancelMut]
501
+ );
502
+ const close = useCallback(
503
+ (input) => closeMut.mutateAsync(input),
504
+ [closeMut]
505
+ );
506
+ const autoAccept = useCallback(
507
+ (input) => autoAcceptMut.mutateAsync(input),
508
+ [autoAcceptMut]
509
+ );
510
+ const active = cancelMut.isPending || closeMut.isPending || autoAcceptMut.isPending;
511
+ const latest = [cancelMut, closeMut, autoAcceptMut].find((m) => m.isError || m.isSuccess) ?? cancelMut;
512
+ return {
513
+ cancel,
514
+ close,
515
+ autoAccept,
516
+ status: active ? "pending" : mutationStatusOf(latest),
517
+ signature: latest.data ?? null,
518
+ error: cancelMut.error ?? closeMut.error ?? autoAcceptMut.error ?? null,
519
+ isPending: active,
520
+ reset: () => {
521
+ cancelMut.reset();
522
+ closeMut.reset();
523
+ autoAcceptMut.reset();
524
+ }
525
+ };
526
+ }
527
+ function useRateHire(taskPda) {
528
+ const ctx = useAgencContext();
529
+ const mutation = useMutation({
530
+ mutationFn: async (input) => {
531
+ const client = requireClient(ctx.client);
532
+ const { signature } = await client.rateHire({
533
+ ...input,
534
+ task: taskPda,
535
+ buyer: input.buyer ?? client.signer
536
+ });
537
+ return signature;
538
+ }
539
+ });
540
+ const rate = useCallback((input) => mutation.mutateAsync(input), [mutation]);
541
+ return {
542
+ rate,
543
+ status: mutationStatusOf(mutation),
544
+ signature: mutation.data ?? null,
545
+ error: mutation.error ?? null,
546
+ isPending: mutation.isPending,
547
+ reset: mutation.reset
548
+ };
549
+ }
263
550
  function useDispute(taskPda, options) {
264
551
  const ctx = useAgencContext();
265
552
  const reader = options?.disputeReader;
@@ -297,43 +584,36 @@ function useDispute(taskPda, options) {
297
584
  reset: mutation.reset
298
585
  };
299
586
  }
587
+ var EARNINGS_INDEXER_LIVE = false;
300
588
  function useReferrerEarnings(wallet) {
301
589
  const ctx = useAgencContext();
302
590
  const capability = ctx.resolveReferrerCapability();
303
- const enabled = capability.live && Boolean(wallet);
304
- const query = useQuery(
591
+ const enabled = capability.live && EARNINGS_INDEXER_LIVE;
592
+ useQuery(
305
593
  {
306
594
  queryKey: queryKeys.referrerEarnings(wallet ? pdaKey(wallet) : ""),
307
595
  enabled,
308
596
  queryFn: async () => {
309
597
  throw new Error(
310
- "useReferrerEarnings: the P6.2 referrer earnings path is not deployed; this query must never run while capability.live is false."
598
+ "useReferrerEarnings: the referrer earnings indexer is not deployed; this query must never run while EARNINGS_INDEXER_LIVE is false."
311
599
  );
312
600
  }
313
601
  }
314
602
  );
315
- if (!capability.live) {
603
+ if (!capability.live || !EARNINGS_INDEXER_LIVE) {
316
604
  return {
317
605
  live: false,
318
606
  totalLamports: 0n,
319
607
  hires: [],
320
608
  isLoading: false,
321
609
  error: null,
322
- reason: capability.reason ?? t("referrer.notLiveReason"),
610
+ reason: capability.live ? t("referrer.earningsNotLiveReason") : capability.reason ?? t("referrer.notLiveReason"),
323
611
  refetch: () => {
324
612
  }
325
613
  };
326
614
  }
327
- return {
328
- live: true,
329
- totalLamports: query.data?.totalLamports ?? 0n,
330
- hires: query.data?.hires ?? [],
331
- isLoading: query.isLoading,
332
- error: query.error ?? null,
333
- refetch: () => void query.refetch()
334
- };
335
615
  }
336
616
 
337
- export { projectTrackRecord, useAgentTrackRecord, useDispute, useListing, useListings, useReferrerEarnings, useSubmissionReview, useTaskStatus };
617
+ export { projectTrackRecord, useAgentTrackRecord, useDispute, useHumanlessHireFlow, useListing, useListings, useRateHire, useReferrerEarnings, useSubmissionReview, useTaskActivation, useTaskLifecycle, useTaskStatus, useTaskWork };
338
618
  //# sourceMappingURL=index.js.map
339
619
  //# sourceMappingURL=index.js.map