@tetsuo-ai/marketplace-react 0.1.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 (112) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/LICENSE +21 -0
  3. package/README.md +172 -0
  4. package/dist/chunk-5OTKSRHM.js +128 -0
  5. package/dist/chunk-5OTKSRHM.js.map +1 -0
  6. package/dist/chunk-ABS77JB2.js +94 -0
  7. package/dist/chunk-ABS77JB2.js.map +1 -0
  8. package/dist/chunk-GN5DYVN5.js +35 -0
  9. package/dist/chunk-GN5DYVN5.js.map +1 -0
  10. package/dist/chunk-KJMR6OGC.js +1198 -0
  11. package/dist/chunk-KJMR6OGC.js.map +1 -0
  12. package/dist/chunk-YORZNYZZ.js +107 -0
  13. package/dist/chunk-YORZNYZZ.js.map +1 -0
  14. package/dist/components/agenc-components.css +570 -0
  15. package/dist/components/index.cjs +1335 -0
  16. package/dist/components/index.cjs.map +1 -0
  17. package/dist/components/index.d.cts +5 -0
  18. package/dist/components/index.d.ts +5 -0
  19. package/dist/components/index.js +5 -0
  20. package/dist/components/index.js.map +1 -0
  21. package/dist/hooks/index.cjs +493 -0
  22. package/dist/hooks/index.cjs.map +1 -0
  23. package/dist/hooks/index.d.cts +294 -0
  24. package/dist/hooks/index.d.ts +294 -0
  25. package/dist/hooks/index.js +339 -0
  26. package/dist/hooks/index.js.map +1 -0
  27. package/dist/index-BLrlBVj-.d.cts +1129 -0
  28. package/dist/index-CKTYsNPH.d.ts +1129 -0
  29. package/dist/index.cjs +1690 -0
  30. package/dist/index.cjs.map +1 -0
  31. package/dist/index.d.cts +235 -0
  32. package/dist/index.d.ts +235 -0
  33. package/dist/index.js +127 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/signers/index.cjs +166 -0
  36. package/dist/signers/index.cjs.map +1 -0
  37. package/dist/signers/index.d.cts +136 -0
  38. package/dist/signers/index.d.ts +136 -0
  39. package/dist/signers/index.js +4 -0
  40. package/dist/signers/index.js.map +1 -0
  41. package/dist/testing/index.cjs +62 -0
  42. package/dist/testing/index.cjs.map +1 -0
  43. package/dist/testing/index.d.cts +71 -0
  44. package/dist/testing/index.d.ts +71 -0
  45. package/dist/testing/index.js +60 -0
  46. package/dist/testing/index.js.map +1 -0
  47. package/dist/theme/agenc-tailwind-preset.cjs +184 -0
  48. package/dist/theme/agenc-tokens.css +132 -0
  49. package/dist/types-jvISR6bc.d.cts +135 -0
  50. package/dist/types-jvISR6bc.d.ts +135 -0
  51. package/dist/useAgentTrackRecord-BLf1nrbu.d.cts +249 -0
  52. package/dist/useAgentTrackRecord-BLf1nrbu.d.ts +249 -0
  53. package/package.json +139 -0
  54. package/src/components/DisputeBanner.stories.tsx +39 -0
  55. package/src/components/DisputeBanner.tsx +110 -0
  56. package/src/components/HireButton.stories.tsx +72 -0
  57. package/src/components/HireButton.tsx +151 -0
  58. package/src/components/HireCheckoutModal.stories.tsx +107 -0
  59. package/src/components/HireCheckoutModal.tsx +284 -0
  60. package/src/components/ListingCard.stories.tsx +55 -0
  61. package/src/components/ListingCard.tsx +148 -0
  62. package/src/components/ListingGrid.stories.tsx +44 -0
  63. package/src/components/ListingGrid.tsx +137 -0
  64. package/src/components/Modal.tsx +121 -0
  65. package/src/components/PoweredByAgenC.tsx +85 -0
  66. package/src/components/ProviderCard.stories.tsx +61 -0
  67. package/src/components/ProviderCard.tsx +154 -0
  68. package/src/components/ReferrerDisclosure.tsx +67 -0
  69. package/src/components/ReviewPanel.stories.tsx +65 -0
  70. package/src/components/ReviewPanel.tsx +141 -0
  71. package/src/components/TaskTimeline.stories.tsx +43 -0
  72. package/src/components/TaskTimeline.tsx +156 -0
  73. package/src/components/__fixtures__/index.tsx +173 -0
  74. package/src/components/agenc-components.css +570 -0
  75. package/src/components/badges.tsx +115 -0
  76. package/src/components/format.ts +150 -0
  77. package/src/components/index.ts +102 -0
  78. package/src/components/primitives.tsx +236 -0
  79. package/src/components/strings.ts +131 -0
  80. package/src/components/useFocusTrap.ts +122 -0
  81. package/src/hooks/index.ts +90 -0
  82. package/src/hooks/internal.ts +70 -0
  83. package/src/hooks/useAgentTrackRecord.ts +166 -0
  84. package/src/hooks/useDispute.ts +130 -0
  85. package/src/hooks/useHire.ts +198 -0
  86. package/src/hooks/useListing.ts +138 -0
  87. package/src/hooks/useListings.ts +133 -0
  88. package/src/hooks/useReferrerEarnings.ts +134 -0
  89. package/src/hooks/useSubmissionReview.ts +179 -0
  90. package/src/hooks/useTaskStatus.ts +192 -0
  91. package/src/hooks/useWalletSigner.ts +99 -0
  92. package/src/index.ts +170 -0
  93. package/src/provider/AgencProvider.tsx +169 -0
  94. package/src/provider/context.ts +35 -0
  95. package/src/provider/index.ts +17 -0
  96. package/src/provider/network.ts +68 -0
  97. package/src/provider/referrer.ts +97 -0
  98. package/src/signers/README.md +130 -0
  99. package/src/signers/embedded-wallet-mock.ts +158 -0
  100. package/src/signers/embedded-wallet.ts +64 -0
  101. package/src/signers/index.ts +48 -0
  102. package/src/signers/strings.ts +39 -0
  103. package/src/signers/types.ts +158 -0
  104. package/src/signers/wallet-account.ts +128 -0
  105. package/src/signers/wallet-adapter.ts +149 -0
  106. package/src/strings/index.ts +119 -0
  107. package/src/testing/index.ts +24 -0
  108. package/src/theme/agenc-tailwind-preset.cjs +184 -0
  109. package/src/theme/agenc-tokens.css +132 -0
  110. package/src/theme/index.ts +94 -0
  111. package/src/transport/index.ts +164 -0
  112. package/src/types.ts +224 -0
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Ladle stories for {@link TaskTimeline} — every lifecycle stage + the
3
+ * off-path terminals + loading / empty / error.
4
+ */
5
+ import type { Story } from "@ladle/react";
6
+ import { TaskStatus } from "@tetsuo-ai/marketplace-sdk";
7
+ import { TaskTimeline } from "./TaskTimeline.js";
8
+
9
+ export default {
10
+ title: "Task / TaskTimeline",
11
+ };
12
+
13
+ export const Open: Story = () => <TaskTimeline status={TaskStatus.Open} />;
14
+ export const InProgress: Story = () => (
15
+ <TaskTimeline status={TaskStatus.InProgress} />
16
+ );
17
+ export const PendingReview: Story = () => (
18
+ <TaskTimeline status={TaskStatus.PendingValidation} />
19
+ );
20
+ export const Completed: Story = () => (
21
+ <TaskTimeline status={TaskStatus.Completed} />
22
+ );
23
+ export const Cancelled: Story = () => (
24
+ <TaskTimeline status={TaskStatus.Cancelled} />
25
+ );
26
+ export const Disputed: Story = () => (
27
+ <TaskTimeline status={TaskStatus.Disputed} />
28
+ );
29
+ export const RejectFrozen: Story = () => (
30
+ <TaskTimeline status={TaskStatus.RejectFrozen} />
31
+ );
32
+ export const Loading: Story = () => <TaskTimeline status={null} isLoading />;
33
+ export const Empty: Story = () => <TaskTimeline status={null} />;
34
+ export const ErrorState: Story = () => (
35
+ <TaskTimeline
36
+ status={null}
37
+ error={new Error("could not read task")}
38
+ onRetry={() => {}}
39
+ />
40
+ );
41
+ export const Unstyled: Story = () => (
42
+ <TaskTimeline status={TaskStatus.InProgress} unstyled />
43
+ );
@@ -0,0 +1,156 @@
1
+ /**
2
+ * `<TaskTimeline>` — the lifecycle progress of a hired task.
3
+ *
4
+ * Renders the canonical happy-path stages (Open → In progress → Pending review
5
+ * → Completed) as an ordered, accessible list with the current stage marked,
6
+ * and surfaces the terminal off-path states (Cancelled / Disputed / Rejected-
7
+ * frozen) when reached. Presentational: it takes a `TaskStatus | null` (from
8
+ * `useTaskStatus().status`) plus loading/error, so it renders under SSR and in
9
+ * Ladle without owning a reader.
10
+ *
11
+ * @module components/TaskTimeline
12
+ */
13
+ import type { ReactNode } from "react";
14
+ import { TaskStatus } from "@tetsuo-ai/marketplace-sdk";
15
+ import { tc } from "./format.js";
16
+ import { StateMessage, cx, rootClass, type ThemableProps } from "./primitives.js";
17
+
18
+ /** Props for {@link TaskTimeline}. */
19
+ export interface TaskTimelineProps extends ThemableProps {
20
+ /** The current task status (from `useTaskStatus().status`). */
21
+ status: TaskStatus | null;
22
+ /** True while loading the status. */
23
+ isLoading?: boolean;
24
+ /** A read error. */
25
+ error?: Error | null;
26
+ /** Retry handler for the error state. */
27
+ onRetry?: () => void;
28
+ }
29
+
30
+ /** The happy-path stages in order. */
31
+ const HAPPY_PATH: ReadonlyArray<{ status: TaskStatus; stringId: string }> = [
32
+ { status: TaskStatus.Open, stringId: "components.taskTimeline.status.Open" },
33
+ {
34
+ status: TaskStatus.InProgress,
35
+ stringId: "components.taskTimeline.status.InProgress",
36
+ },
37
+ {
38
+ status: TaskStatus.PendingValidation,
39
+ stringId: "components.taskTimeline.status.PendingValidation",
40
+ },
41
+ {
42
+ status: TaskStatus.Completed,
43
+ stringId: "components.taskTimeline.status.Completed",
44
+ },
45
+ ];
46
+
47
+ /** Off-path terminal statuses + their tone class suffix. */
48
+ const OFF_PATH: Partial<Record<TaskStatus, { stringId: string; tone: string }>> =
49
+ {
50
+ [TaskStatus.Cancelled]: {
51
+ stringId: "components.taskTimeline.status.Cancelled",
52
+ tone: "cancelled",
53
+ },
54
+ [TaskStatus.Disputed]: {
55
+ stringId: "components.taskTimeline.status.Disputed",
56
+ tone: "disputed",
57
+ },
58
+ [TaskStatus.RejectFrozen]: {
59
+ stringId: "components.taskTimeline.status.RejectFrozen",
60
+ tone: "rejected",
61
+ },
62
+ };
63
+
64
+ /** The index of `status` within the happy path, or -1. */
65
+ function happyIndex(status: TaskStatus): number {
66
+ return HAPPY_PATH.findIndex((s) => s.status === status);
67
+ }
68
+
69
+ /**
70
+ * Render a task's lifecycle progress.
71
+ */
72
+ export function TaskTimeline({
73
+ status,
74
+ isLoading = false,
75
+ error = null,
76
+ onRetry,
77
+ unstyled,
78
+ className,
79
+ }: TaskTimelineProps): ReactNode {
80
+ const timelineClass = rootClass("agenc-timeline", unstyled, className);
81
+
82
+ if (error) {
83
+ return (
84
+ <div className={timelineClass}>
85
+ <StateMessage kind="error" onRetry={onRetry} unstyled={unstyled} />
86
+ </div>
87
+ );
88
+ }
89
+ if (isLoading && status === null) {
90
+ return (
91
+ <div className={timelineClass}>
92
+ <StateMessage kind="loading" unstyled={unstyled} />
93
+ </div>
94
+ );
95
+ }
96
+ if (status === null) {
97
+ return (
98
+ <div className={timelineClass}>
99
+ <StateMessage
100
+ kind="empty"
101
+ message={tc("components.taskTimeline.empty")}
102
+ unstyled={unstyled}
103
+ />
104
+ </div>
105
+ );
106
+ }
107
+
108
+ const offPath = OFF_PATH[status];
109
+ const currentIndex = offPath ? -1 : happyIndex(status);
110
+
111
+ return (
112
+ <div className={timelineClass} aria-label={tc("components.taskTimeline.title")}>
113
+ <ol className={unstyled ? undefined : "agenc-timeline__list"}>
114
+ {HAPPY_PATH.map((stage, index) => {
115
+ const done = currentIndex > index;
116
+ const current = currentIndex === index;
117
+ const state = done ? "done" : current ? "current" : "upcoming";
118
+ return (
119
+ <li
120
+ key={stage.status}
121
+ className={
122
+ unstyled
123
+ ? undefined
124
+ : cx("agenc-timeline__step", `agenc-timeline__step--${state}`)
125
+ }
126
+ aria-current={current ? "step" : undefined}
127
+ >
128
+ <span
129
+ className={unstyled ? undefined : "agenc-timeline__marker"}
130
+ aria-hidden="true"
131
+ />
132
+ <span className={unstyled ? undefined : "agenc-timeline__label"}>
133
+ {tc(stage.stringId)}
134
+ </span>
135
+ </li>
136
+ );
137
+ })}
138
+ </ol>
139
+ {offPath ? (
140
+ <p
141
+ className={
142
+ unstyled
143
+ ? undefined
144
+ : cx(
145
+ "agenc-timeline__terminal",
146
+ `agenc-timeline__terminal--${offPath.tone}`,
147
+ )
148
+ }
149
+ role="status"
150
+ >
151
+ {tc(offPath.stringId)}
152
+ </p>
153
+ ) : null}
154
+ </div>
155
+ );
156
+ }
@@ -0,0 +1,173 @@
1
+ /**
2
+ * Deterministic fixtures shared by the component stories AND the axe/structural
3
+ * tests. Kept out of the package barrel (an internal `__fixtures__` dir) so it
4
+ * never ships as public API; tsup only bundles the entry points.
5
+ *
6
+ * The fixtures build BYTE-TRUE listing fields via the SDK's canonical encoders
7
+ * so `ListingCard`'s decode path is exercised for real, and otherwise cast the
8
+ * remaining on-chain fields to keep the fixtures small.
9
+ *
10
+ * @module components/__fixtures__
11
+ */
12
+ import type { ReactNode } from "react";
13
+ import { address } from "@solana/kit";
14
+ import { values } from "@tetsuo-ai/marketplace-sdk";
15
+ import { AgencProvider } from "../../provider/index.js";
16
+ import type {
17
+ Address,
18
+ AgencProviderConfig,
19
+ IndexerListing,
20
+ MarketplaceClient,
21
+ ReadTransport,
22
+ ServiceListing,
23
+ } from "../../types.js";
24
+ import type { ListingCardData } from "../ListingCard.js";
25
+ import type { AgentTrackRecord } from "../../hooks/useAgentTrackRecord.js";
26
+
27
+ /** A stable provider-agent PDA for fixtures. */
28
+ export const FIXTURE_AGENT = address(
29
+ "So11111111111111111111111111111111111111112",
30
+ ) as Address;
31
+
32
+ /** A stable listing PDA for fixtures. */
33
+ export const FIXTURE_LISTING = address(
34
+ "Stake11111111111111111111111111111111111111",
35
+ ) as Address;
36
+
37
+ /** A stable referrer wallet for the disclosure fixtures. */
38
+ export const FIXTURE_REFERRER = "11111111111111111111111111111111";
39
+
40
+ /**
41
+ * Build a decoded `ServiceListing` with byte-true metadata fields. Overrides
42
+ * are shallow-merged.
43
+ */
44
+ export function makeListing(
45
+ overrides: Partial<ServiceListing> = {},
46
+ ): ServiceListing {
47
+ return {
48
+ providerAgent: FIXTURE_AGENT,
49
+ authority: FIXTURE_AGENT,
50
+ name: values.encodeListingName("Translation service"),
51
+ category: values.encodeListingCategory("translation"),
52
+ tags: values.encodeListingTags(["english-to-french", "docs"]),
53
+ specHash: new Uint8Array(32),
54
+ specUri: "agenc://job-spec/sha256/" + "0".repeat(64),
55
+ price: 250_000_000n,
56
+ priceMint: { __option: "None" },
57
+ totalHires: 42n,
58
+ version: 3n,
59
+ state: 0,
60
+ ...overrides,
61
+ } as unknown as ServiceListing;
62
+ }
63
+
64
+ /** A `ListingCardData` (address + decoded account) fixture. */
65
+ export function makeListingRow(
66
+ addr: Address = FIXTURE_LISTING,
67
+ overrides: Partial<ServiceListing> = {},
68
+ ): ListingCardData {
69
+ return { address: addr, account: makeListing(overrides) };
70
+ }
71
+
72
+ /** A small set of listing rows for the grid story. */
73
+ export function makeListingRows(count = 6): ListingCardData[] {
74
+ const base = [
75
+ "Stake11111111111111111111111111111111111111",
76
+ "Vote111111111111111111111111111111111111111",
77
+ "Config1111111111111111111111111111111111111",
78
+ "BPFLoader1111111111111111111111111111111111",
79
+ "Sysvar1111111111111111111111111111111111111",
80
+ "Feature111111111111111111111111111111111111",
81
+ ];
82
+ return Array.from({ length: count }, (_, i) =>
83
+ makeListingRow(address(base[i % base.length]!) as Address, {
84
+ name: values.encodeListingName(`Service #${i + 1}`),
85
+ price: BigInt((i + 1) * 100_000_000),
86
+ totalHires: BigInt(i * 7),
87
+ }),
88
+ );
89
+ }
90
+
91
+ /** An indexer listing projection fixture (attested by default). */
92
+ export function makeIndexerListing(
93
+ overrides: Partial<IndexerListing> = {},
94
+ ): IndexerListing {
95
+ return {
96
+ pda: String(FIXTURE_LISTING),
97
+ accountData: "",
98
+ decoded: {} as IndexerListing["decoded"],
99
+ metadataValid: true,
100
+ metadataIssues: [],
101
+ lastSlot: 1,
102
+ lastSignature: "sig",
103
+ ...overrides,
104
+ } as IndexerListing;
105
+ }
106
+
107
+ /** A projected track record fixture. */
108
+ export function makeTrackRecord(
109
+ overrides: Partial<AgentTrackRecord> = {},
110
+ ): AgentTrackRecord {
111
+ return {
112
+ agent: FIXTURE_AGENT,
113
+ completions: 18,
114
+ disputesInitiated: 1,
115
+ disputesLost: 2,
116
+ completionRate: 0.9,
117
+ disputeRate: 0.1,
118
+ slashHistory: [],
119
+ recentOutcomes: [],
120
+ partial: true,
121
+ ...overrides,
122
+ };
123
+ }
124
+
125
+ /** A no-op read transport for provider-wrapped stories. */
126
+ export function fixtureReadTransport(): ReadTransport {
127
+ return {
128
+ kind: "indexer",
129
+ listActiveListings: async () => [],
130
+ getListing: async () => {
131
+ throw new Error("fixture: getListing not wired");
132
+ },
133
+ listingHires: async () => [],
134
+ agentTrackRecord: async () => {
135
+ throw new Error("fixture: agentTrackRecord not wired");
136
+ },
137
+ };
138
+ }
139
+
140
+ /** A stub write client whose hire resolves successfully (for HireButton). */
141
+ export function fixtureClient(): MarketplaceClient {
142
+ return {
143
+ signer: { address: FIXTURE_AGENT } as MarketplaceClient["signer"],
144
+ transport: {} as MarketplaceClient["transport"],
145
+ send: async () => ({ signature: "fixture-sig", logs: [] }),
146
+ hireFromListing: async () => ({ signature: "fixture-sig", logs: [] }),
147
+ } as unknown as MarketplaceClient;
148
+ }
149
+
150
+ /**
151
+ * Wrap a story in an `AgencProvider` with the fixture transport/client and an
152
+ * optional referrer (for the connected `HireButton` story + the disclosure).
153
+ */
154
+ export function FixtureProvider({
155
+ children,
156
+ referrer,
157
+ withClient = true,
158
+ }: {
159
+ children: ReactNode;
160
+ referrer?: { wallet: string; feeBps: number };
161
+ withClient?: boolean;
162
+ }): ReactNode {
163
+ const config: AgencProviderConfig = {
164
+ network: "localnet",
165
+ queryTransport: fixtureReadTransport(),
166
+ client: withClient ? fixtureClient() : undefined,
167
+ signer: withClient
168
+ ? ({ address: FIXTURE_AGENT } as AgencProviderConfig["signer"])
169
+ : undefined,
170
+ referrer,
171
+ };
172
+ return <AgencProvider config={config}>{children}</AgencProvider>;
173
+ }