@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.
- package/CHANGELOG.md +65 -0
- package/README.md +97 -51
- package/dist/chunk-7NKRSPPN.js +227 -0
- package/dist/chunk-7NKRSPPN.js.map +1 -0
- package/dist/{chunk-JVXGNW3Q.js → chunk-CDDHUFMG.js} +6 -5
- package/dist/chunk-CDDHUFMG.js.map +1 -0
- package/dist/chunk-FIDFPM5A.cjs +40 -0
- package/dist/chunk-FIDFPM5A.cjs.map +1 -0
- package/dist/chunk-IJKWKY4H.cjs +1370 -0
- package/dist/chunk-IJKWKY4H.cjs.map +1 -0
- package/dist/chunk-JTSG5FGC.cjs +397 -0
- package/dist/chunk-JTSG5FGC.cjs.map +1 -0
- package/dist/chunk-ONC6L3IX.cjs +97 -0
- package/dist/chunk-ONC6L3IX.cjs.map +1 -0
- package/dist/chunk-R76EUYDI.cjs +233 -0
- package/dist/chunk-R76EUYDI.cjs.map +1 -0
- package/dist/{chunk-XLA7DARS.js → chunk-RG5JZ6JL.js} +159 -36
- package/dist/chunk-RG5JZ6JL.js.map +1 -0
- package/dist/components/index.cjs +158 -1594
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.d.cts +2 -2
- package/dist/components/index.d.ts +2 -2
- package/dist/components/index.js +2 -2
- package/dist/hooks/index.cjs +656 -509
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +63 -29
- package/dist/hooks/index.d.ts +63 -29
- package/dist/hooks/index.js +619 -196
- package/dist/hooks/index.js.map +1 -1
- package/dist/{index-CmVz0OOm.d.ts → index-BAyr1ODZ.d.ts} +28 -3
- package/dist/{index-DAZzhuO4.d.cts → index-C20NVU7_.d.cts} +28 -3
- package/dist/index.cjs +284 -1833
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -8
- package/dist/index.d.ts +7 -8
- package/dist/index.js +64 -4
- package/dist/index.js.map +1 -1
- package/dist/signers/index.cjs +22 -161
- package/dist/signers/index.cjs.map +1 -1
- package/dist/signers/index.d.cts +16 -11
- package/dist/signers/index.d.ts +16 -11
- package/dist/signers/index.js +1 -1
- package/dist/testing/index.d.cts +1 -1
- package/dist/testing/index.d.ts +1 -1
- package/dist/theme/agenc-tailwind-preset.cjs +134 -108
- package/dist/{types-jvISR6bc.d.cts → types-B10rndEI.d.cts} +16 -7
- package/dist/{types-jvISR6bc.d.ts → types-B10rndEI.d.ts} +16 -7
- package/dist/{useAgentTrackRecord-DPt3SfYz.d.cts → useAgentTrackRecord-Ch7gHTFj.d.cts} +1 -1
- package/dist/{useAgentTrackRecord-DPt3SfYz.d.ts → useAgentTrackRecord-Ch7gHTFj.d.ts} +1 -1
- package/package.json +7 -4
- package/src/components/HireCheckoutModal.tsx +5 -2
- package/src/hooks/index.ts +1 -0
- package/src/hooks/internal.ts +178 -24
- package/src/hooks/useAgentTrackRecord.ts +5 -2
- package/src/hooks/useCompletionBond.ts +56 -21
- package/src/hooks/useDispute.ts +46 -9
- package/src/hooks/useHire.ts +113 -23
- package/src/hooks/useHumanlessHireFlow.ts +335 -115
- package/src/hooks/useListing.ts +2 -2
- package/src/hooks/useListings.ts +2 -2
- package/src/hooks/useRateHire.ts +32 -5
- package/src/hooks/useReferrerEarnings.ts +4 -1
- package/src/hooks/useSubmissionReview.ts +95 -32
- package/src/hooks/useTaskActivation.ts +51 -9
- package/src/hooks/useTaskGuarantee.ts +4 -1
- package/src/hooks/useTaskLifecycle.ts +104 -24
- package/src/hooks/useTaskStatus.ts +121 -26
- package/src/hooks/useTaskWork.ts +76 -12
- package/src/hooks/useWalletSigner.ts +11 -16
- package/src/index.ts +3 -0
- package/src/provider/AgencProvider.tsx +95 -3
- package/src/provider/referrer.ts +1 -1
- package/src/signers/README.md +13 -7
- package/src/signers/index.ts +6 -1
- package/src/signers/strings.ts +13 -1
- package/src/signers/types.ts +16 -5
- package/src/signers/wallet-account.ts +115 -29
- package/src/signers/wallet-adapter.ts +38 -4
- package/src/theme/agenc-tailwind-preset.cjs +134 -108
- package/src/types.ts +27 -1
- package/dist/chunk-JVXGNW3Q.js.map +0 -1
- package/dist/chunk-ON6XR4XO.js +0 -128
- package/dist/chunk-ON6XR4XO.js.map +0 -1
- package/dist/chunk-XLA7DARS.js.map +0 -1
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkFIDFPM5A_cjs = require('./chunk-FIDFPM5A.cjs');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
var marketplaceSdk = require('@tetsuo-ai/marketplace-sdk');
|
|
6
|
+
var reactQuery = require('@tanstack/react-query');
|
|
7
|
+
var kit = require('@solana/kit');
|
|
8
|
+
|
|
9
|
+
var AgencContext = react.createContext(null);
|
|
10
|
+
AgencContext.displayName = "AgencContext";
|
|
11
|
+
function useAgencContext() {
|
|
12
|
+
const ctx = react.useContext(AgencContext);
|
|
13
|
+
if (ctx === null) {
|
|
14
|
+
throw new Error(chunkFIDFPM5A_cjs.t("provider.missingContext"));
|
|
15
|
+
}
|
|
16
|
+
return ctx;
|
|
17
|
+
}
|
|
18
|
+
var QUERY_KEY_ROOT = "agenc";
|
|
19
|
+
var DEFAULT_QUERY_CACHE_NAMESPACE = "default";
|
|
20
|
+
function queryRoot(cacheNamespace) {
|
|
21
|
+
return [QUERY_KEY_ROOT, cacheNamespace];
|
|
22
|
+
}
|
|
23
|
+
var queryKeys = {
|
|
24
|
+
/** All listings list queries (with their filter object as the leaf). */
|
|
25
|
+
listings: (filter, cacheNamespace = DEFAULT_QUERY_CACHE_NAMESPACE) => [...queryRoot(cacheNamespace), "listings", filter ?? null],
|
|
26
|
+
/** One listing + its joined provider/track-record/moderation. */
|
|
27
|
+
listing: (pda, cacheNamespace = DEFAULT_QUERY_CACHE_NAMESPACE) => [...queryRoot(cacheNamespace), "listing", pda],
|
|
28
|
+
/** One agent's indexer track record. */
|
|
29
|
+
agentTrackRecord: (agentPda, cacheNamespace = DEFAULT_QUERY_CACHE_NAMESPACE) => [...queryRoot(cacheNamespace), "agentTrackRecord", agentPda],
|
|
30
|
+
/** One task's status (read via transport / svm decode). */
|
|
31
|
+
taskStatus: (taskPda, cacheNamespace = DEFAULT_QUERY_CACHE_NAMESPACE) => [...queryRoot(cacheNamespace), "taskStatus", taskPda],
|
|
32
|
+
/** One task's dispute record. */
|
|
33
|
+
dispute: (taskPda, cacheNamespace = DEFAULT_QUERY_CACHE_NAMESPACE) => [...queryRoot(cacheNamespace), "dispute", taskPda],
|
|
34
|
+
/** One task's completion-bond ("Guaranteed Hire") state. */
|
|
35
|
+
taskGuarantee: (taskPda, cacheNamespace = DEFAULT_QUERY_CACHE_NAMESPACE) => [...queryRoot(cacheNamespace), "taskGuarantee", taskPda],
|
|
36
|
+
/** One referrer wallet's earnings (indexer-gated; see useReferrerEarnings). */
|
|
37
|
+
referrerEarnings: (wallet, cacheNamespace = DEFAULT_QUERY_CACHE_NAMESPACE) => [...queryRoot(cacheNamespace), "referrerEarnings", wallet]
|
|
38
|
+
};
|
|
39
|
+
function requireClient(client) {
|
|
40
|
+
if (client === null) {
|
|
41
|
+
throw new Error(chunkFIDFPM5A_cjs.t("provider.missingWriteClient"));
|
|
42
|
+
}
|
|
43
|
+
return client;
|
|
44
|
+
}
|
|
45
|
+
function mutationStatusOf(mutation) {
|
|
46
|
+
if (mutation.isPending) return "pending";
|
|
47
|
+
if (mutation.isError) return "error";
|
|
48
|
+
if (mutation.isSuccess) return "success";
|
|
49
|
+
return "idle";
|
|
50
|
+
}
|
|
51
|
+
function pdaKey(pda) {
|
|
52
|
+
return String(pda);
|
|
53
|
+
}
|
|
54
|
+
function resolveReferrerArgs(ctx) {
|
|
55
|
+
const capability = ctx.resolveReferrerCapability();
|
|
56
|
+
if (!capability.live || !capability.referrer) {
|
|
57
|
+
return { referrerArgs: {}, referrerInjected: false };
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
referrerArgs: {
|
|
61
|
+
referrer: capability.referrer.wallet,
|
|
62
|
+
referrerFeeBps: capability.referrer.feeBps
|
|
63
|
+
},
|
|
64
|
+
referrerInjected: true
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function snapshotFixedBytes32(value, label) {
|
|
68
|
+
return snapshotFixedBytes(value, 32, label);
|
|
69
|
+
}
|
|
70
|
+
function snapshotFixedBytes(value, byteLength, label) {
|
|
71
|
+
if (!isExactUint8Array(value) || typedArrayByteLengthGetter?.call(value) !== byteLength || !hasOrdinaryArrayBuffer(value)) {
|
|
72
|
+
throw new TypeError(`${label} must be exactly ${byteLength} bytes`);
|
|
73
|
+
}
|
|
74
|
+
return new Uint8Array(value);
|
|
75
|
+
}
|
|
76
|
+
var typedArrayPrototype = Object.getPrototypeOf(Uint8Array.prototype);
|
|
77
|
+
var typedArrayTagGetter = Object.getOwnPropertyDescriptor(
|
|
78
|
+
typedArrayPrototype,
|
|
79
|
+
Symbol.toStringTag
|
|
80
|
+
)?.get;
|
|
81
|
+
var typedArrayByteLengthGetter = Object.getOwnPropertyDescriptor(
|
|
82
|
+
typedArrayPrototype,
|
|
83
|
+
"byteLength"
|
|
84
|
+
)?.get;
|
|
85
|
+
var typedArrayBufferGetter = Object.getOwnPropertyDescriptor(
|
|
86
|
+
typedArrayPrototype,
|
|
87
|
+
"buffer"
|
|
88
|
+
)?.get;
|
|
89
|
+
var arrayBufferByteLengthGetter = Object.getOwnPropertyDescriptor(
|
|
90
|
+
ArrayBuffer.prototype,
|
|
91
|
+
"byteLength"
|
|
92
|
+
)?.get;
|
|
93
|
+
function isExactUint8Array(value) {
|
|
94
|
+
return ArrayBuffer.isView(value) && typedArrayTagGetter?.call(value) === "Uint8Array";
|
|
95
|
+
}
|
|
96
|
+
function hasOrdinaryArrayBuffer(value) {
|
|
97
|
+
try {
|
|
98
|
+
const buffer = typedArrayBufferGetter?.call(value);
|
|
99
|
+
return buffer !== void 0 && typeof arrayBufferByteLengthGetter?.call(buffer) === "number";
|
|
100
|
+
} catch {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function snapshotOptionalFixedBytes(value, byteLength, label) {
|
|
105
|
+
if (value === void 0 || value === null) return value;
|
|
106
|
+
if (isExactUint8Array(value)) {
|
|
107
|
+
return snapshotFixedBytes(value, byteLength, label);
|
|
108
|
+
}
|
|
109
|
+
if (typeof value !== "object") {
|
|
110
|
+
throw new TypeError(`${label} must be exactly ${byteLength} bytes or None`);
|
|
111
|
+
}
|
|
112
|
+
const option = value;
|
|
113
|
+
const tag = option.__option;
|
|
114
|
+
if (tag === "None") {
|
|
115
|
+
return Object.freeze({ __option: "None" });
|
|
116
|
+
}
|
|
117
|
+
if (tag === "Some") {
|
|
118
|
+
const bytes = snapshotFixedBytes(option.value, byteLength, label);
|
|
119
|
+
return Object.freeze({ __option: "Some", value: bytes });
|
|
120
|
+
}
|
|
121
|
+
throw new TypeError(`${label} must be exactly ${byteLength} bytes or None`);
|
|
122
|
+
}
|
|
123
|
+
function snapshotRecord(value) {
|
|
124
|
+
return Object.freeze({ ...value });
|
|
125
|
+
}
|
|
126
|
+
function snapshotRecordArray(value) {
|
|
127
|
+
return Object.freeze(value.map((entry) => snapshotRecord(entry)));
|
|
128
|
+
}
|
|
129
|
+
function stabilizeSelectedTransactionSigner(clientSigner, override) {
|
|
130
|
+
const stableClientSigner = marketplaceSdk.stabilizeTransactionSigner(clientSigner);
|
|
131
|
+
if (override === void 0 || override === stableClientSigner || override.address === stableClientSigner.address) {
|
|
132
|
+
return stableClientSigner;
|
|
133
|
+
}
|
|
134
|
+
const stableOverride = marketplaceSdk.stabilizeTransactionSigner(override);
|
|
135
|
+
return stableOverride.address === stableClientSigner.address ? stableClientSigner : stableOverride;
|
|
136
|
+
}
|
|
137
|
+
function withoutReferrerArgs(input) {
|
|
138
|
+
const {
|
|
139
|
+
referrer: _referrer,
|
|
140
|
+
referrerFeeBps: _referrerFeeBps,
|
|
141
|
+
...rest
|
|
142
|
+
} = input;
|
|
143
|
+
return rest;
|
|
144
|
+
}
|
|
145
|
+
function useTaskGuarantee(taskPda, options) {
|
|
146
|
+
const ctx = useAgencContext();
|
|
147
|
+
const injected = options?.guaranteeReader;
|
|
148
|
+
const rpcUrl = ctx.rpcUrl;
|
|
149
|
+
const reader = react.useMemo(() => {
|
|
150
|
+
if (injected) return injected;
|
|
151
|
+
if (!rpcUrl) return null;
|
|
152
|
+
return (pda) => marketplaceSdk.fetchTaskGuarantee(
|
|
153
|
+
kit.createSolanaRpc(rpcUrl),
|
|
154
|
+
pda
|
|
155
|
+
);
|
|
156
|
+
}, [injected, rpcUrl]);
|
|
157
|
+
const enabled = (options?.enabled ?? true) && Boolean(taskPda) && reader !== null;
|
|
158
|
+
const query = reactQuery.useQuery({
|
|
159
|
+
queryKey: queryKeys.taskGuarantee(
|
|
160
|
+
taskPda ? pdaKey(taskPda) : "",
|
|
161
|
+
ctx.cacheNamespace
|
|
162
|
+
),
|
|
163
|
+
enabled,
|
|
164
|
+
queryFn: () => reader(taskPda)
|
|
165
|
+
});
|
|
166
|
+
const guarantee = query.data ?? null;
|
|
167
|
+
return {
|
|
168
|
+
guarantee,
|
|
169
|
+
guaranteed: guarantee?.guaranteed ?? false,
|
|
170
|
+
isLoading: query.isLoading,
|
|
171
|
+
error: query.error ?? null,
|
|
172
|
+
refetch: () => void query.refetch()
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
function readRpc(input) {
|
|
176
|
+
return input.rpc ?? (input.rpcUrl ? kit.createSolanaRpc(input.rpcUrl) : null);
|
|
177
|
+
}
|
|
178
|
+
async function resolveRosterEntry(rpc, moderator) {
|
|
179
|
+
const [moderationConfigPda] = await marketplaceSdk.findModerationConfigPda();
|
|
180
|
+
const moderationConfig = await marketplaceSdk.fetchMaybeModerationConfig(
|
|
181
|
+
rpc,
|
|
182
|
+
moderationConfigPda
|
|
183
|
+
);
|
|
184
|
+
if (moderationConfig.exists && moderationConfig.data.moderationAuthority === moderator) {
|
|
185
|
+
return void 0;
|
|
186
|
+
}
|
|
187
|
+
const [rosterPda] = await marketplaceSdk.findModerationAttestorPda({ attestor: moderator });
|
|
188
|
+
const roster = await marketplaceSdk.fetchMaybeModerationAttestor(rpc, rosterPda);
|
|
189
|
+
return roster.exists ? rosterPda : void 0;
|
|
190
|
+
}
|
|
191
|
+
async function resolveActivationModerationAccounts(input) {
|
|
192
|
+
try {
|
|
193
|
+
const rpc = readRpc(input);
|
|
194
|
+
if (!rpc) return {};
|
|
195
|
+
const moderationAttestor = await resolveRosterEntry(rpc, input.moderator);
|
|
196
|
+
const attestorPart = moderationAttestor !== void 0 ? { moderationAttestor } : {};
|
|
197
|
+
const [v2Pda] = await marketplaceSdk.findTaskModerationPda({
|
|
198
|
+
task: input.task,
|
|
199
|
+
jobSpecHash: input.jobSpecHash,
|
|
200
|
+
moderator: input.moderator
|
|
201
|
+
});
|
|
202
|
+
const v2 = await marketplaceSdk.fetchMaybeTaskModeration(rpc, v2Pda);
|
|
203
|
+
if (v2.exists) return attestorPart;
|
|
204
|
+
const [legacyPda] = await marketplaceSdk.facade.findLegacyTaskModerationPda({
|
|
205
|
+
task: input.task,
|
|
206
|
+
jobSpecHash: input.jobSpecHash
|
|
207
|
+
});
|
|
208
|
+
const legacy = await marketplaceSdk.fetchMaybeTaskModeration(rpc, legacyPda);
|
|
209
|
+
if (legacy.exists && legacy.data.moderator === input.moderator) {
|
|
210
|
+
return { ...attestorPart, taskModeration: legacyPda };
|
|
211
|
+
}
|
|
212
|
+
return attestorPart;
|
|
213
|
+
} catch {
|
|
214
|
+
return {};
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
async function resolveHireListingModerationAccounts(input) {
|
|
218
|
+
try {
|
|
219
|
+
const rpc = readRpc(input);
|
|
220
|
+
if (!rpc) return {};
|
|
221
|
+
const moderationAttestor = await resolveRosterEntry(rpc, input.moderator);
|
|
222
|
+
const attestorPart = moderationAttestor !== void 0 ? { moderationAttestor } : {};
|
|
223
|
+
const [v2Pda] = await marketplaceSdk.findListingModerationPda({
|
|
224
|
+
listing: input.listing,
|
|
225
|
+
jobSpecHash: input.listingSpecHash,
|
|
226
|
+
moderator: input.moderator
|
|
227
|
+
});
|
|
228
|
+
const v2 = await marketplaceSdk.fetchMaybeListingModeration(rpc, v2Pda);
|
|
229
|
+
if (v2.exists) return attestorPart;
|
|
230
|
+
const [legacyPda] = await marketplaceSdk.facade.findLegacyListingModerationPda({
|
|
231
|
+
listing: input.listing,
|
|
232
|
+
jobSpecHash: input.listingSpecHash
|
|
233
|
+
});
|
|
234
|
+
const legacy = await marketplaceSdk.fetchMaybeListingModeration(rpc, legacyPda);
|
|
235
|
+
if (legacy.exists && legacy.data.moderator === input.moderator) {
|
|
236
|
+
return { ...attestorPart, listingModeration: legacyPda };
|
|
237
|
+
}
|
|
238
|
+
return attestorPart;
|
|
239
|
+
} catch {
|
|
240
|
+
return {};
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// src/hooks/useHire.ts
|
|
245
|
+
function useHire() {
|
|
246
|
+
const ctx = useAgencContext();
|
|
247
|
+
const mutation = reactQuery.useMutation({
|
|
248
|
+
mutationFn: async ({
|
|
249
|
+
client,
|
|
250
|
+
input,
|
|
251
|
+
creator,
|
|
252
|
+
creatorAddress,
|
|
253
|
+
authority,
|
|
254
|
+
orchestrationRpcUrl,
|
|
255
|
+
orchestrationRpc,
|
|
256
|
+
referral
|
|
257
|
+
}) => {
|
|
258
|
+
const { referrerArgs, referrerInjected } = referral;
|
|
259
|
+
const [taskPda] = await marketplaceSdk.findTaskPda({
|
|
260
|
+
creator: creatorAddress,
|
|
261
|
+
taskId: input.taskId
|
|
262
|
+
});
|
|
263
|
+
const listingSpecHash = input.listingSpecHash;
|
|
264
|
+
let moderationArgs = {};
|
|
265
|
+
if (input.moderationAttestor === void 0 && input.moderatorIsAttestor === void 0 && input.listingModeration === void 0 && listingSpecHash !== void 0) {
|
|
266
|
+
moderationArgs = await resolveHireListingModerationAccounts({
|
|
267
|
+
rpcUrl: orchestrationRpcUrl,
|
|
268
|
+
...orchestrationRpc === null ? {} : { rpc: orchestrationRpc },
|
|
269
|
+
listing: input.listing,
|
|
270
|
+
listingSpecHash,
|
|
271
|
+
moderator: input.moderator
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
let signature;
|
|
275
|
+
if (input.humanless === true) {
|
|
276
|
+
const result = await client.hireFromListingHumanless({
|
|
277
|
+
...input,
|
|
278
|
+
...moderationArgs,
|
|
279
|
+
creator,
|
|
280
|
+
...referrerArgs
|
|
281
|
+
});
|
|
282
|
+
signature = result.signature;
|
|
283
|
+
} else {
|
|
284
|
+
if (authority === void 0) {
|
|
285
|
+
throw new Error("useHire: missing snapshotted authority");
|
|
286
|
+
}
|
|
287
|
+
const result = await client.hireFromListing({
|
|
288
|
+
...input,
|
|
289
|
+
...moderationArgs,
|
|
290
|
+
authority,
|
|
291
|
+
creator,
|
|
292
|
+
...referrerArgs
|
|
293
|
+
});
|
|
294
|
+
signature = result.signature;
|
|
295
|
+
}
|
|
296
|
+
return { signature, taskPda, referrerInjected };
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
const hire = react.useCallback(
|
|
300
|
+
async (input) => {
|
|
301
|
+
const client = requireClient(ctx.client);
|
|
302
|
+
const detachedInput = withoutReferrerArgs(input);
|
|
303
|
+
const snapshottedInput = {
|
|
304
|
+
...detachedInput,
|
|
305
|
+
taskId: snapshotFixedBytes32(detachedInput.taskId, "useHire: taskId"),
|
|
306
|
+
...detachedInput.listingSpecHash === void 0 ? {} : {
|
|
307
|
+
listingSpecHash: snapshotFixedBytes32(
|
|
308
|
+
detachedInput.listingSpecHash,
|
|
309
|
+
"useHire: listingSpecHash"
|
|
310
|
+
)
|
|
311
|
+
},
|
|
312
|
+
...detachedInput.taskJobSpecHash === void 0 ? {} : {
|
|
313
|
+
taskJobSpecHash: snapshotFixedBytes32(
|
|
314
|
+
detachedInput.taskJobSpecHash,
|
|
315
|
+
"useHire: taskJobSpecHash"
|
|
316
|
+
)
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
const clientSigner = stabilizeSelectedTransactionSigner(client.signer);
|
|
320
|
+
const creator = stabilizeSelectedTransactionSigner(
|
|
321
|
+
clientSigner,
|
|
322
|
+
detachedInput.creator
|
|
323
|
+
);
|
|
324
|
+
const creatorAddress = creator.address;
|
|
325
|
+
let authority;
|
|
326
|
+
if (detachedInput.humanless !== true) {
|
|
327
|
+
const selectedAuthority = stabilizeSelectedTransactionSigner(
|
|
328
|
+
clientSigner,
|
|
329
|
+
detachedInput.authority
|
|
330
|
+
);
|
|
331
|
+
authority = stabilizeSelectedTransactionSigner(
|
|
332
|
+
creator,
|
|
333
|
+
selectedAuthority
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
return mutation.mutateAsync({
|
|
337
|
+
client,
|
|
338
|
+
input: snapshottedInput,
|
|
339
|
+
creator,
|
|
340
|
+
creatorAddress,
|
|
341
|
+
...authority === void 0 ? {} : { authority },
|
|
342
|
+
orchestrationRpcUrl: ctx.orchestrationRpcUrl,
|
|
343
|
+
orchestrationRpc: ctx.orchestrationRpc,
|
|
344
|
+
// Resolve fresh at this synchronous enqueue boundary so provider
|
|
345
|
+
// changes cannot alter an already accepted hire intent.
|
|
346
|
+
referral: resolveReferrerArgs(ctx)
|
|
347
|
+
});
|
|
348
|
+
},
|
|
349
|
+
[ctx, mutation]
|
|
350
|
+
);
|
|
351
|
+
const status = react.useMemo(() => {
|
|
352
|
+
if (mutation.isPending) return "pending";
|
|
353
|
+
if (mutation.isError) return "error";
|
|
354
|
+
if (mutation.isSuccess) return "success";
|
|
355
|
+
return "idle";
|
|
356
|
+
}, [mutation.isPending, mutation.isError, mutation.isSuccess]);
|
|
357
|
+
return {
|
|
358
|
+
hire,
|
|
359
|
+
status,
|
|
360
|
+
taskPda: mutation.data?.taskPda ?? null,
|
|
361
|
+
signature: mutation.data?.signature ?? null,
|
|
362
|
+
error: mutation.error ?? null,
|
|
363
|
+
isPending: mutation.isPending,
|
|
364
|
+
reset: mutation.reset
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
function useWalletSigner(options) {
|
|
368
|
+
const ctx = useAgencContext();
|
|
369
|
+
const adapter = options?.adapter;
|
|
370
|
+
const signer = adapter !== void 0 ? adapter.signer : ctx.signer ?? null;
|
|
371
|
+
const connected = adapter !== void 0 ? adapter.connected ?? adapter.signer !== null : ctx.signer !== null;
|
|
372
|
+
const connect = react.useCallback(() => {
|
|
373
|
+
return adapter?.connect ? adapter.connect() : void 0;
|
|
374
|
+
}, [adapter]);
|
|
375
|
+
return { signer, connected, connect };
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
exports.AgencContext = AgencContext;
|
|
379
|
+
exports.QUERY_KEY_ROOT = QUERY_KEY_ROOT;
|
|
380
|
+
exports.mutationStatusOf = mutationStatusOf;
|
|
381
|
+
exports.pdaKey = pdaKey;
|
|
382
|
+
exports.queryKeys = queryKeys;
|
|
383
|
+
exports.requireClient = requireClient;
|
|
384
|
+
exports.resolveActivationModerationAccounts = resolveActivationModerationAccounts;
|
|
385
|
+
exports.resolveReferrerArgs = resolveReferrerArgs;
|
|
386
|
+
exports.snapshotFixedBytes32 = snapshotFixedBytes32;
|
|
387
|
+
exports.snapshotOptionalFixedBytes = snapshotOptionalFixedBytes;
|
|
388
|
+
exports.snapshotRecord = snapshotRecord;
|
|
389
|
+
exports.snapshotRecordArray = snapshotRecordArray;
|
|
390
|
+
exports.stabilizeSelectedTransactionSigner = stabilizeSelectedTransactionSigner;
|
|
391
|
+
exports.useAgencContext = useAgencContext;
|
|
392
|
+
exports.useHire = useHire;
|
|
393
|
+
exports.useTaskGuarantee = useTaskGuarantee;
|
|
394
|
+
exports.useWalletSigner = useWalletSigner;
|
|
395
|
+
exports.withoutReferrerArgs = withoutReferrerArgs;
|
|
396
|
+
//# sourceMappingURL=chunk-JTSG5FGC.cjs.map
|
|
397
|
+
//# sourceMappingURL=chunk-JTSG5FGC.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/provider/context.ts","../src/hooks/internal.ts","../src/hooks/useTaskGuarantee.ts","../src/hooks/moderation-attestor.ts","../src/hooks/useHire.ts","../src/hooks/useWalletSigner.ts"],"names":["createContext","useContext","t","stabilizeTransactionSigner","useMemo","fetchTaskGuarantee","createSolanaRpc","useQuery","findModerationConfigPda","fetchMaybeModerationConfig","findModerationAttestorPda","fetchMaybeModerationAttestor","findTaskModerationPda","fetchMaybeTaskModeration","facade","findListingModerationPda","fetchMaybeListingModeration","useMutation","findTaskPda","useCallback"],"mappings":";;;;;;;;AAkBO,IAAM,YAAA,GAAeA,oBAAwC,IAAI;AACxE,YAAA,CAAa,WAAA,GAAc,cAAA;AASpB,SAAS,eAAA,GAAqC;AACnD,EAAA,MAAM,GAAA,GAAMC,iBAAW,YAAY,CAAA;AACnC,EAAA,IAAI,QAAQ,IAAA,EAAM;AAChB,IAAA,MAAM,IAAI,KAAA,CAAMC,mBAAA,CAAE,yBAAyB,CAAC,CAAA;AAAA,EAC9C;AACA,EAAA,OAAO,GAAA;AACT;ACXO,IAAM,cAAA,GAAiB;AAGvB,IAAM,6BAAA,GAAgC,SAAA;AAE7C,SAAS,UAAU,cAAA,EAAwB;AACzC,EAAA,OAAO,CAAC,gBAAgB,cAAc,CAAA;AACxC;AAYO,IAAM,SAAA,GAAY;AAAA;AAAA,EAEvB,QAAA,EAAU,CACR,MAAA,EACA,cAAA,GAAyB,6BAAA,KACtB,CAAC,GAAG,SAAA,CAAU,cAAc,CAAA,EAAG,UAAA,EAAY,MAAA,IAAU,IAAI,CAAA;AAAA;AAAA,EAE9D,OAAA,EAAS,CACP,GAAA,EACA,cAAA,GAAyB,6BAAA,KACtB,CAAC,GAAG,SAAA,CAAU,cAAc,CAAA,EAAG,SAAA,EAAW,GAAG,CAAA;AAAA;AAAA,EAElD,gBAAA,EAAkB,CAChB,QAAA,EAC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,IAAA,EAAM,OAAA,IAAW,IAAA;AAAA,IACnC,SAAA,EAAW,QAAA,CAAS,IAAA,EAAM,SAAA,IAAa,IAAA;AAAA,IACvC,KAAA,EAAO,SAAS,KAAA,IAAS,IAAA;AAAA,IACzB,WAAW,QAAA,CAAS,SAAA;AAAA,IACpB,OAAO,QAAA,CAAS;AAAA,GAClB;AACF;AC1OO,SAAS,gBACd,OAAA,EACuB;AACvB,EAAA,MAAM,MAAM,eAAA,EAAgB;AAC5B,EAAA,MAAM,UAAU,OAAA,EAAS,OAAA;AAGzB,EAAA,MAAM,SACJ,OAAA,KAAY,MAAA,GAAY,OAAA,CAAQ,MAAA,GAAU,IAAI,MAAA,IAAU,IAAA;AAC1D,EAAA,MAAM,SAAA,GACJ,YAAY,MAAA,GACP,OAAA,CAAQ,aAAa,OAAA,CAAQ,MAAA,KAAW,IAAA,GACzC,GAAA,CAAI,MAAA,KAAW,IAAA;AAErB,EAAA,MAAM,OAAA,GAAUe,kBAAY,MAAM;AAGhC,IAAA,OAAO,OAAA,EAAS,OAAA,GAAU,OAAA,CAAQ,OAAA,EAAQ,GAAI,MAAA;AAAA,EAChD,CAAA,EAAG,CAAC,OAAO,CAAC,CAAA;AAEZ,EAAA,OAAO,EAAE,MAAA,EAAQ,SAAA,EAAW,OAAA,EAAQ;AACtC","file":"chunk-JTSG5FGC.cjs","sourcesContent":["/**\n * The React context object + the internal `useAgencContext()` hook.\n *\n * Split from the component file so the context identity is stable and so hooks\n * can import the context without pulling the JSX provider into their module\n * graph. SSR-safe: this module only calls `createContext` at import time, never\n * touches `window`.\n *\n * @module provider/context\n */\nimport { createContext, useContext } from \"react\";\nimport { t } from \"../strings/index.js\";\nimport type { AgencContextValue } from \"../types.js\";\n\n/**\n * The AgenC context. `null` until a `<AgencProvider>` mounts above the consumer\n * — {@link useAgencContext} turns that into a clear developer error.\n */\nexport const AgencContext = createContext<AgencContextValue | null>(null);\nAgencContext.displayName = \"AgencContext\";\n\n/**\n * Read the AgenC context. INTERNAL hook the package's own hooks build on; also\n * exported from the package root so downstream hooks (components agent) can\n * reach the resolved transport/client/referrer.\n *\n * @throws Error when called outside a `<AgencProvider>`.\n */\nexport function useAgencContext(): AgencContextValue {\n const ctx = useContext(AgencContext);\n if (ctx === null) {\n throw new Error(t(\"provider.missingContext\"));\n }\n return ctx;\n}\n","/**\n * Internal helpers shared by the headless hooks.\n *\n * - A namespaced TanStack Query key factory so every hook's cache entries are\n * stable, collision-free, and individually invalidatable.\n * - Tiny guards that turn a missing write client / signer into a clear,\n * catalog-routed error (never a `null.method()` crash) BEFORE a mutation runs.\n *\n * SSR-safe: pure functions, no `window`/`document`, no module-scope side\n * effects.\n *\n * @module hooks/internal\n */\nimport { stabilizeTransactionSigner } from \"@tetsuo-ai/marketplace-sdk\";\nimport { t } from \"../strings/index.js\";\nimport type {\n Address,\n AgencContextValue,\n MarketplaceClient,\n TransactionSigner,\n} from \"../types.js\";\n\n/** Root namespace for every cache key this package writes. */\nexport const QUERY_KEY_ROOT = \"agenc\" as const;\n\n/** Namespace used only by direct callers that omit deployment identity. */\nexport const DEFAULT_QUERY_CACHE_NAMESPACE = \"default\" as const;\n\nfunction queryRoot(cacheNamespace: string) {\n return [QUERY_KEY_ROOT, cacheNamespace] as const;\n}\n\n/**\n * Stable, hierarchical TanStack Query keys. Hooks build their keys ONLY through\n * this factory so a consumer (or a hook) can invalidate a deployment sub-tree\n * (`[\"agenc\", namespace, \"listings\"]`) or one entity\n * (`[\"agenc\", namespace, \"listing\", pda]`).\n *\n * `JSON.stringify` is intentionally NOT used — TanStack compares keys\n * structurally, so passing the raw filter object keeps equality correct for\n * `bigint`/`Address` values without a serialization step.\n */\nexport const queryKeys = {\n /** All listings list queries (with their filter object as the leaf). */\n listings: (\n filter?: unknown,\n cacheNamespace: string = DEFAULT_QUERY_CACHE_NAMESPACE,\n ) => [...queryRoot(cacheNamespace), \"listings\", filter ?? null] as const,\n /** One listing + its joined provider/track-record/moderation. */\n listing: (\n pda: string,\n cacheNamespace: string = DEFAULT_QUERY_CACHE_NAMESPACE,\n ) => [...queryRoot(cacheNamespace), \"listing\", pda] as const,\n /** One agent's indexer track record. */\n agentTrackRecord: (\n agentPda: string,\n cacheNamespace: string = DEFAULT_QUERY_CACHE_NAMESPACE,\n ) => [...queryRoot(cacheNamespace), \"agentTrackRecord\", agentPda] as const,\n /** One task's status (read via transport / svm decode). */\n taskStatus: (\n taskPda: string,\n cacheNamespace: string = DEFAULT_QUERY_CACHE_NAMESPACE,\n ) => [...queryRoot(cacheNamespace), \"taskStatus\", taskPda] as const,\n /** One task's dispute record. */\n dispute: (\n taskPda: string,\n cacheNamespace: string = DEFAULT_QUERY_CACHE_NAMESPACE,\n ) => [...queryRoot(cacheNamespace), \"dispute\", taskPda] as const,\n /** One task's completion-bond (\"Guaranteed Hire\") state. */\n taskGuarantee: (\n taskPda: string,\n cacheNamespace: string = DEFAULT_QUERY_CACHE_NAMESPACE,\n ) => [...queryRoot(cacheNamespace), \"taskGuarantee\", taskPda] as const,\n /** One referrer wallet's earnings (indexer-gated; see useReferrerEarnings). */\n referrerEarnings: (\n wallet: string,\n cacheNamespace: string = DEFAULT_QUERY_CACHE_NAMESPACE,\n ) => [...queryRoot(cacheNamespace), \"referrerEarnings\", wallet] as const,\n} as const;\n\n/**\n * Assert a write client exists, returning it narrowed to non-null. Throws a\n * clear, catalog-routed error when the provider was configured read-only (no\n * `client` and no resolvable `rpcUrl` + `signer`).\n *\n * Mutating hooks call this at the top of their `mutationFn` so the failure is a\n * descriptive Error in the mutation's `error` channel — never a crash.\n *\n * @throws Error (`provider.missingWriteClient`) when `client` is null.\n */\nexport function requireClient(\n client: MarketplaceClient | null,\n): MarketplaceClient {\n if (client === null) {\n throw new Error(t(\"provider.missingWriteClient\"));\n }\n return client;\n}\n\nexport type MutationStatus = \"idle\" | \"pending\" | \"success\" | \"error\";\n\nexport function mutationStatusOf(mutation: {\n isPending: boolean;\n isError: boolean;\n isSuccess: boolean;\n}): MutationStatus {\n if (mutation.isPending) return \"pending\";\n if (mutation.isError) return \"error\";\n if (mutation.isSuccess) return \"success\";\n return \"idle\";\n}\n\n/** Coerce an `Address | string` to its string form for use as a cache key. */\nexport function pdaKey(pda: Address | string): string {\n return String(pda);\n}\n\nexport interface ReferrerArgs {\n referrer?: Address;\n referrerFeeBps?: number;\n}\n\nexport interface ResolvedReferrerArgs {\n referrerArgs: ReferrerArgs;\n referrerInjected: boolean;\n}\n\nexport function resolveReferrerArgs(\n ctx: Pick<AgencContextValue, \"resolveReferrerCapability\">,\n): ResolvedReferrerArgs {\n const capability = ctx.resolveReferrerCapability();\n if (!capability.live || !capability.referrer) {\n return { referrerArgs: {}, referrerInjected: false };\n }\n return {\n referrerArgs: {\n referrer: capability.referrer.wallet,\n referrerFeeBps: capability.referrer.feeBps,\n },\n referrerInjected: true,\n };\n}\n\n/**\n * Detach one on-chain fixed-byte value from caller-owned mutable storage.\n * Validation happens synchronously at the hook's public enqueue boundary so a\n * later TanStack/SDK await can never observe a different byte sequence.\n */\nexport function snapshotFixedBytes32(\n value: unknown,\n label: string,\n): Uint8Array {\n return snapshotFixedBytes(value, 32, label);\n}\n\nfunction snapshotFixedBytes(\n value: unknown,\n byteLength: number,\n label: string,\n): Uint8Array {\n if (\n !isExactUint8Array(value) ||\n typedArrayByteLengthGetter?.call(value) !== byteLength ||\n !hasOrdinaryArrayBuffer(value)\n ) {\n throw new TypeError(`${label} must be exactly ${byteLength} bytes`);\n }\n return new Uint8Array(value);\n}\n\nconst typedArrayPrototype = Object.getPrototypeOf(Uint8Array.prototype);\nconst typedArrayTagGetter = Object.getOwnPropertyDescriptor(\n typedArrayPrototype,\n Symbol.toStringTag,\n)?.get;\nconst typedArrayByteLengthGetter = Object.getOwnPropertyDescriptor(\n typedArrayPrototype,\n \"byteLength\",\n)?.get;\nconst typedArrayBufferGetter = Object.getOwnPropertyDescriptor(\n typedArrayPrototype,\n \"buffer\",\n)?.get;\nconst arrayBufferByteLengthGetter = Object.getOwnPropertyDescriptor(\n ArrayBuffer.prototype,\n \"byteLength\",\n)?.get;\n\n/**\n * Recognize the SDK's exact byte-view contract across browser/worker realms.\n * `instanceof` is realm-local and `Object#toString` honors a spoofable own\n * `Symbol.toStringTag`. Calling the shared `%TypedArray%` intrinsic getter\n * directly performs the unforgeable typed-array-kind check across realms.\n */\nfunction isExactUint8Array(value: unknown): value is Uint8Array {\n return (\n ArrayBuffer.isView(value) &&\n typedArrayTagGetter?.call(value) === \"Uint8Array\"\n );\n}\n\n/** Shared backing can change concurrently and cannot yield one coherent hash. */\nfunction hasOrdinaryArrayBuffer(value: Uint8Array): boolean {\n try {\n const buffer = typedArrayBufferGetter?.call(value);\n return (\n buffer !== undefined &&\n typeof arrayBufferByteLengthGetter?.call(buffer) === \"number\"\n );\n } catch {\n // `%ArrayBuffer%.byteLength` rejects SharedArrayBuffer and foreign brands.\n return false;\n }\n}\n\n/**\n * Detach a nullable Solana `OptionOrNullable<ReadonlyUint8Array>` while\n * preserving its public representation. Both the convenient nullable form and\n * Kit's explicit `Some`/`None` objects are accepted by generated encoders.\n */\nexport function snapshotOptionalFixedBytes<T>(\n value: T,\n byteLength: number,\n label: string,\n): T {\n if (value === undefined || value === null) return value;\n if (isExactUint8Array(value)) {\n return snapshotFixedBytes(value, byteLength, label) as T;\n }\n if (typeof value !== \"object\") {\n throw new TypeError(`${label} must be exactly ${byteLength} bytes or None`);\n }\n\n const option = value as {\n readonly __option?: unknown;\n readonly value?: unknown;\n };\n const tag = option.__option;\n if (tag === \"None\") {\n return Object.freeze({ __option: \"None\" }) as T;\n }\n if (tag === \"Some\") {\n const bytes = snapshotFixedBytes(option.value, byteLength, label);\n return Object.freeze({ __option: \"Some\", value: bytes }) as T;\n }\n throw new TypeError(`${label} must be exactly ${byteLength} bytes or None`);\n}\n\n/**\n * Copy and freeze one caller-owned record. Callers with nested mutable values\n * must replace those values with their own snapshots before enqueueing.\n */\nexport function snapshotRecord<T extends object>(value: T): T {\n return Object.freeze({ ...value }) as T;\n}\n\n/** Copy a caller-owned account collection and every known-flat entry. */\nexport function snapshotRecordArray<T extends object>(\n value: readonly T[],\n): readonly T[] {\n return Object.freeze(value.map((entry) => snapshotRecord(entry)));\n}\n\n/**\n * Stabilize the fee-payer signer and the exact optional instruction override at\n * the synchronous hook boundary. An override for the fee-payer's canonical\n * address resolves to the fee-payer object because Solana Kit rejects distinct\n * signer implementations for one address. A different-address override keeps\n * its own identity after the SDK guard permanently locks its address. Other\n * stateful wallet/session fields remain usable.\n */\nexport function stabilizeSelectedTransactionSigner(\n clientSigner: TransactionSigner,\n override?: TransactionSigner,\n): TransactionSigner {\n const stableClientSigner = stabilizeTransactionSigner(clientSigner);\n if (\n override === undefined ||\n override === stableClientSigner ||\n override.address === stableClientSigner.address\n ) {\n return stableClientSigner;\n }\n const stableOverride = stabilizeTransactionSigner(override);\n return stableOverride.address === stableClientSigner.address\n ? stableClientSigner\n : stableOverride;\n}\n\nexport function withoutReferrerArgs<T extends object>(\n input: T,\n): Omit<T, \"referrer\" | \"referrerFeeBps\"> {\n const {\n referrer: _referrer,\n referrerFeeBps: _referrerFeeBps,\n ...rest\n } = input as T & { referrer?: unknown; referrerFeeBps?: unknown };\n return rest;\n}\n","/**\n * `useTaskGuarantee(taskPda)` — a task's completion-bond (\"Guaranteed Hire\")\n * state, read-only.\n *\n * Guaranteed Hire is the productized read of the LIVE completion-bond\n * machinery: a worker who posts a completion bond stakes 25% of the reward on\n * passing review, and forfeits it if the result is rejected or they lose a\n * dispute. `guaranteed` is `true` iff the worker bond is posted and unresolved\n * (bond PDAs are closed by every settlement exit, so live == unresolved).\n *\n * HONEST BOUNDARY (phase 1 — do not overclaim in UI copy): a FORFEITED bond\n * pays the protocol **treasury**, not the harmed party. The buyer's protection\n * today is the escrow refund on a failed review PLUS the worker's 25% skin in\n * the game — the buyer does not receive the bond itself. Phase 2 (batch-2\n * program work) redirects forfeiture to the harmed party.\n *\n * ## How it reads\n *\n * The bond accounts are keyed by (task, posting wallet) and the worker's\n * wallet is not derivable from the Task account alone, so this is a\n * `getProgramAccounts` read (`CompletionBond.task` memcmp) — the SDK's\n * `fetchTaskGuarantee`. Resolution order:\n * 1. `options.guaranteeReader` — an injected reader seam (tests, litesvm,\n * custom transports; same pattern as `useTaskStatus`/`useDispute`);\n * 2. the provider's resolved `rpcUrl` — a kit RPC is built for the read. NOTE:\n * the RPC must allow `getProgramAccounts` (many public providers restrict\n * it); a rejection surfaces in `error`, never a crash.\n * Without either, the hook stays idle.\n *\n * @module hooks/useTaskGuarantee\n */\nimport { useQuery } from \"@tanstack/react-query\";\nimport { useMemo } from \"react\";\nimport { createSolanaRpc } from \"@solana/kit\";\nimport {\n fetchTaskGuarantee,\n type ProgramAccountsSource,\n type TaskGuarantee,\n} from \"@tetsuo-ai/marketplace-sdk\";\nimport { useAgencContext } from \"../provider/context.js\";\nimport type { Address } from \"../types.js\";\nimport { pdaKey, queryKeys } from \"./internal.js\";\n\n/** Reads a task's {@link TaskGuarantee} (the SDK `fetchTaskGuarantee` shape). */\nexport type TaskGuaranteeReader = (\n taskPda: Address | string,\n) => Promise<TaskGuarantee>;\n\n/** Options for {@link useTaskGuarantee}. */\nexport interface UseTaskGuaranteeOptions {\n /**\n * Injected reader seam (wins over the provider `rpcUrl` default). Wire it\n * from litesvm/gpa-sim in tests or from your own transport.\n */\n guaranteeReader?: TaskGuaranteeReader;\n /** Disable the read. Default `true` when `taskPda` + a read source exist. */\n enabled?: boolean;\n}\n\n/** Return value of {@link useTaskGuarantee}. */\nexport interface UseTaskGuaranteeResult {\n /** The full bond state (worker/creator bonds + flag), or null until read. */\n guarantee: TaskGuarantee | null;\n /**\n * Convenience: `guarantee?.guaranteed ?? false` — `true` iff the worker\n * bond is live (posted and unresolved).\n */\n guaranteed: boolean;\n /** True while the first read is in flight. */\n isLoading: boolean;\n /** The read error, or null. */\n error: Error | null;\n /** Force a refetch (e.g. after posting/reclaiming a bond). */\n refetch: () => void;\n}\n\n/**\n * Read a task's Guaranteed Hire state.\n *\n * @param taskPda - The Task PDA (falsy disables the read).\n * @param options - Reader seam + enabled.\n * @returns {@link UseTaskGuaranteeResult}.\n */\nexport function useTaskGuarantee(\n taskPda: Address | string | undefined | null,\n options?: UseTaskGuaranteeOptions,\n): UseTaskGuaranteeResult {\n const ctx = useAgencContext();\n const injected = options?.guaranteeReader;\n const rpcUrl = ctx.rpcUrl;\n\n // Injected seam wins; else build a gPA read over the provider's rpcUrl.\n const reader = useMemo<TaskGuaranteeReader | null>(() => {\n if (injected) return injected;\n if (!rpcUrl) return null;\n return (pda) =>\n fetchTaskGuarantee(\n createSolanaRpc(rpcUrl) as unknown as ProgramAccountsSource,\n pda as Address,\n );\n }, [injected, rpcUrl]);\n\n const enabled =\n (options?.enabled ?? true) && Boolean(taskPda) && reader !== null;\n\n const query = useQuery<TaskGuarantee, Error>({\n queryKey: queryKeys.taskGuarantee(\n taskPda ? pdaKey(taskPda) : \"\",\n ctx.cacheNamespace,\n ),\n enabled,\n queryFn: () => reader!(taskPda as Address | string),\n });\n\n const guarantee = query.data ?? null;\n return {\n guarantee,\n guaranteed: guarantee?.guaranteed ?? false,\n isLoading: query.isLoading,\n error: query.error ?? null,\n refetch: () => void query.refetch(),\n };\n}\n","/**\n * Resolve the P1.2 moderation accounts a consumption gate needs.\n *\n * Post-P1.2 (open roster) every consumption gate — `set_task_job_spec` for\n * activation, `hire_from_listing`/`hire_from_listing_humanless` for hires —\n * names an explicit `moderator` whose attestation it consumes, and the\n * moderation record lives at the v2 moderator-keyed seeds\n * (`[\"task_moderation_v2\", task, hash, moderator]` / the listing mirror). The\n * caller supplies WHO to trust (the `moderator` — reading it from their\n * attestation service, e.g. attest.agenc.ag `GET /v1/info`); these helpers\n * resolve the MECHANICS:\n *\n * - the roster-entry PDA (`[\"moderation_attestor\", moderator]`) the gate\n * requires whenever the moderator is a registered attestor rather than the\n * global `moderation_authority`;\n * - the legacy grace window: when no v2 record exists but a PRE-upgrade record\n * authored by the SAME moderator sits at the frozen legacy seeds, the gate\n * still accepts it if the transaction points at it explicitly — so the\n * resolver returns that record override.\n *\n * Any resolution failure degrades to \"no overrides\" — the program stays the\n * enforcement point; a read hiccup must never make the flow MORE broken than\n * not resolving at all.\n *\n * @module hooks/moderation-attestor\n */\nimport { createSolanaRpc } from \"@solana/kit\";\nimport {\n facade,\n fetchMaybeListingModeration,\n fetchMaybeModerationAttestor,\n fetchMaybeModerationConfig,\n fetchMaybeTaskModeration,\n findListingModerationPda,\n findModerationAttestorPda,\n findModerationConfigPda,\n findTaskModerationPda,\n} from \"@tetsuo-ai/marketplace-sdk\";\nimport type { Address } from \"../types.js\";\n\n/** The account-read slice of a kit RPC that the resolvers need. */\ntype AccountReadRpc = Parameters<typeof fetchMaybeTaskModeration>[0];\n\n/** The job-spec hash exactly as the moderation-record PDA seeds accept it. */\ntype JobSpecHashSeed = Parameters<typeof findTaskModerationPda>[0][\"jobSpecHash\"];\n\n/** Moderation accounts resolved for a task activation (`set_task_job_spec`). */\nexport interface ActivationModerationAccounts {\n /** Roster-entry PDA to attach, absent on the global-authority path. */\n moderationAttestor?: Address;\n /**\n * Explicit record override — set only when the attestation predates the\n * P1.2 upgrade and lives at the frozen legacy seeds (grace window).\n */\n taskModeration?: Address;\n}\n\n/** Moderation accounts resolved for a hire (`hire_from_listing*`). */\nexport interface HireListingModerationAccounts {\n /** Roster-entry PDA to attach, absent on the global-authority path. */\n moderationAttestor?: Address;\n /**\n * Explicit record override — set only when the attestation predates the\n * P1.2 upgrade and lives at the frozen legacy seeds (grace window).\n */\n listingModeration?: Address;\n}\n\nfunction readRpc(input: {\n rpcUrl: string | null;\n rpc?: AccountReadRpc;\n}): AccountReadRpc | null {\n return (\n input.rpc ??\n (input.rpcUrl\n ? (createSolanaRpc(input.rpcUrl) as unknown as AccountReadRpc)\n : null)\n );\n}\n\n/**\n * Roster vs global-authority: return the `[\"moderation_attestor\", moderator]`\n * roster PDA to attach, or `undefined` when the moderator IS the global\n * moderation authority (the gate's authority branch needs no roster account).\n *\n * The roster PDA is attached ONLY when the entry verifiably exists on-chain:\n * a set-but-uninitialized optional account fails the gate harder than\n * attaching nothing (`AccountNotInitialized` vs the authority branch), so an\n * unreadable/absent entry degrades to \"no account\" — callers on an exotic\n * setup can still force the roster path with `moderatorIsAttestor`.\n */\nasync function resolveRosterEntry(\n rpc: AccountReadRpc,\n moderator: Address,\n): Promise<Address | undefined> {\n const [moderationConfigPda] = await findModerationConfigPda();\n const moderationConfig = await fetchMaybeModerationConfig(\n rpc,\n moderationConfigPda,\n );\n if (\n moderationConfig.exists &&\n moderationConfig.data.moderationAuthority === moderator\n ) {\n return undefined;\n }\n const [rosterPda] = await findModerationAttestorPda({ attestor: moderator });\n const roster = await fetchMaybeModerationAttestor(rpc, rosterPda);\n return roster.exists ? rosterPda : undefined;\n}\n\n/**\n * Resolve the moderation accounts to attach to `set_task_job_spec`, given the\n * `moderator` whose attestation the activation consumes.\n *\n * @param input.rpcUrl - Resolved HTTP RPC endpoint (from provider context).\n * @param input.task - The task PDA being activated.\n * @param input.jobSpecHash - The 32-byte canonical job-spec hash.\n * @param input.moderator - The attestation signer the gate should consume\n * (e.g. the attestation service's `moderator` from `GET /v1/info`).\n * @param input.rpc - Test seam: a pre-built account-read RPC wins over\n * `rpcUrl`.\n */\nexport async function resolveActivationModerationAccounts(input: {\n rpcUrl: string | null;\n task: Address;\n jobSpecHash: JobSpecHashSeed;\n moderator: Address;\n rpc?: AccountReadRpc;\n}): Promise<ActivationModerationAccounts> {\n try {\n const rpc = readRpc(input);\n if (!rpc) return {};\n\n const moderationAttestor = await resolveRosterEntry(rpc, input.moderator);\n const attestorPart =\n moderationAttestor !== undefined ? { moderationAttestor } : {};\n\n // Prefer the v2 moderator-keyed record (what recordTaskModeration writes\n // post-upgrade); the facade derives it by default, so no override needed.\n const [v2Pda] = await findTaskModerationPda({\n task: input.task,\n jobSpecHash: input.jobSpecHash,\n moderator: input.moderator,\n });\n const v2 = await fetchMaybeTaskModeration(rpc, v2Pda);\n if (v2.exists) return attestorPart;\n\n // Grace window: a pre-upgrade record at the frozen legacy seeds is still\n // consumable when the transaction points at it explicitly AND it was\n // authored by the same moderator the gate is told to consume.\n const [legacyPda] = await facade.findLegacyTaskModerationPda({\n task: input.task,\n jobSpecHash: input.jobSpecHash,\n });\n const legacy = await fetchMaybeTaskModeration(rpc, legacyPda);\n if (legacy.exists && legacy.data.moderator === input.moderator) {\n return { ...attestorPart, taskModeration: legacyPda };\n }\n\n return attestorPart;\n } catch {\n // Degrade to \"no overrides\" — never block the flow on a read failure.\n return {};\n }\n}\n\n/**\n * Resolve the moderation accounts to attach to a hire\n * (`hire_from_listing` / `hire_from_listing_humanless`), given the\n * `moderator` whose listing attestation the hire gate should consume.\n *\n * @param input.rpcUrl - Resolved HTTP RPC endpoint (from provider context).\n * @param input.listing - The ServiceListing PDA being hired.\n * @param input.listingSpecHash - The listing's pinned 32-byte `spec_hash`.\n * @param input.moderator - The attestation signer the gate should consume.\n * @param input.rpc - Test seam: a pre-built account-read RPC wins over\n * `rpcUrl`.\n */\nexport async function resolveHireListingModerationAccounts(input: {\n rpcUrl: string | null;\n listing: Address;\n listingSpecHash: JobSpecHashSeed;\n moderator: Address;\n rpc?: AccountReadRpc;\n}): Promise<HireListingModerationAccounts> {\n try {\n const rpc = readRpc(input);\n if (!rpc) return {};\n\n const moderationAttestor = await resolveRosterEntry(rpc, input.moderator);\n const attestorPart =\n moderationAttestor !== undefined ? { moderationAttestor } : {};\n\n const [v2Pda] = await findListingModerationPda({\n listing: input.listing,\n jobSpecHash: input.listingSpecHash,\n moderator: input.moderator,\n });\n const v2 = await fetchMaybeListingModeration(rpc, v2Pda);\n if (v2.exists) return attestorPart;\n\n const [legacyPda] = await facade.findLegacyListingModerationPda({\n listing: input.listing,\n jobSpecHash: input.listingSpecHash,\n });\n const legacy = await fetchMaybeListingModeration(rpc, legacyPda);\n if (legacy.exists && legacy.data.moderator === input.moderator) {\n return { ...attestorPart, listingModeration: legacyPda };\n }\n\n return attestorPart;\n } catch {\n // Degrade to \"no overrides\" — never block the flow on a read failure.\n return {};\n }\n}\n","/**\n * `useHire()` — the hire mutation hook (the embeddable money path).\n *\n * Drives `client.hireFromListing(...)` through the provider's write client and\n * surfaces the resulting transaction signature + minted Task PDA. Typed\n * `AgencError`s from the runtime client are surfaced UNTOUCHED in `error`.\n *\n * ## REFERRER SETTLEMENT\n *\n * The full protocol surface supports a demand-side referrer leg. This hook:\n * - reads `resolveReferrerCapability()` from context BEFORE building the hire;\n * - when `live === true`, spreads the validated provider referrer into the hire\n * input for both standard and humanless hires;\n * - the `referrerInjected` flag in the result is the audit signal. We never set\n * it true unless the transaction input included the referrer fields.\n *\n * @module hooks/useHire\n */\nimport { useMutation } from \"@tanstack/react-query\";\nimport { useCallback, useMemo } from \"react\";\nimport { findTaskPda } from \"@tetsuo-ai/marketplace-sdk\";\nimport type { facade as facadeNs } from \"@tetsuo-ai/marketplace-sdk\";\nimport { useAgencContext } from \"../provider/context.js\";\nimport type { Address } from \"../types.js\";\nimport {\n requireClient,\n resolveReferrerArgs,\n snapshotFixedBytes32,\n stabilizeSelectedTransactionSigner,\n withoutReferrerArgs,\n} from \"./internal.js\";\nimport {\n resolveHireListingModerationAccounts,\n type HireListingModerationAccounts,\n} from \"./moderation-attestor.js\";\n\n/**\n * Input to a standard `hire(...)` — a buyer that has a registered marketplace\n * agent (`creatorAgent`). This task settles on the HIRE COMPLETION path (the\n * worker calls `complete_task`). This is the SDK `facade.hireFromListing` input\n * MINUS the fee-payer signers, which default to the provider's write-client\n * signer (authority == creator == buyer). Pass them only to override.\n *\n * NOTE: deliberately NO referrer field — the referrer is provider-level config\n * and is injected only when `resolveReferrerCapability()` is live.\n */\nexport type HireInput = Omit<\n Parameters<typeof facadeNs.hireFromListing>[0],\n \"authority\" | \"creator\" | \"referrer\" | \"referrerFeeBps\"\n> & {\n /** Standard hire (default). */\n humanless?: false;\n /** Override the buyer authority signer (defaults to the client signer). */\n authority?: Parameters<typeof facadeNs.hireFromListing>[0][\"authority\"];\n /** Override the buyer/creator signer (defaults to the client signer). */\n creator?: Parameters<typeof facadeNs.hireFromListing>[0][\"creator\"];\n};\n\n/**\n * Input to a HUMANLESS `hire(...)` — a plain-wallet buyer with NO registered\n * agent (the storefront-visitor path). The task is pinned to CreatorReview, so\n * it settles via the BUYER REVIEW path (`useSubmissionReview` accept/reject) —\n * the human reviews before funds release. This is the SDK\n * `facade.hireFromListingHumanless` input minus the `creator` signer (defaulted\n * to the client signer).\n */\nexport type HumanlessHireInput = Omit<\n Parameters<typeof facadeNs.hireFromListingHumanless>[0],\n \"creator\" | \"referrer\" | \"referrerFeeBps\"\n> & {\n /** Discriminates the humanless storefront-visitor hire. */\n humanless: true;\n /** Override the buyer/creator signer (defaults to the client signer). */\n creator?: Parameters<typeof facadeNs.hireFromListingHumanless>[0][\"creator\"];\n};\n\n/** The union of standard and humanless hire inputs. */\nexport type AnyHireInput = HireInput | HumanlessHireInput;\n\n/** Lifecycle status of the hire mutation. */\nexport type HireStatus = \"idle\" | \"pending\" | \"success\" | \"error\";\n\n/** Result of a settled hire. */\nexport interface HireResult {\n /** The confirmed transaction signature. */\n signature: string;\n /** The minted Task PDA (derived from creator + taskId). */\n taskPda: Address;\n /**\n * Whether a referrer fee leg was injected into THIS hire. Audit signal —\n * never fabricated.\n */\n referrerInjected: boolean;\n}\n\n/** Return value of {@link useHire}. */\nexport interface UseHireResult {\n /** Execute a hire. Resolves to {@link HireResult}; rejects with `AgencError`. */\n hire: (input: AnyHireInput) => Promise<HireResult>;\n /** Current mutation status. */\n status: HireStatus;\n /** The minted Task PDA from the last successful hire, or null. */\n taskPda: Address | null;\n /** The signature from the last successful hire, or null. */\n signature: string | null;\n /** The error from the last hire (typed `AgencError` untouched), or null. */\n error: Error | null;\n /** Whether a hire is currently in flight. */\n isPending: boolean;\n /** Reset the mutation back to idle. */\n reset: () => void;\n}\n\ntype HireCreator = Parameters<\n typeof facadeNs.hireFromListingHumanless\n>[0][\"creator\"];\ntype HireAuthority = Parameters<\n typeof facadeNs.hireFromListing\n>[0][\"authority\"];\n\ninterface HireMutationVariables {\n client: ReturnType<typeof requireClient>;\n input: AnyHireInput;\n creator: HireCreator;\n creatorAddress: Address;\n authority?: HireAuthority;\n orchestrationRpcUrl: ReturnType<\n typeof useAgencContext\n >[\"orchestrationRpcUrl\"];\n orchestrationRpc: ReturnType<typeof useAgencContext>[\"orchestrationRpc\"];\n referral: ReturnType<typeof resolveReferrerArgs>;\n}\n\n/**\n * The hire hook.\n *\n * @returns {@link UseHireResult}.\n *\n * @example\n * ```tsx\n * const { hire, status, taskPda, error } = useHire();\n * await hire({\n * listing, creatorAgent, taskId, expectedPrice: price, expectedVersion: 1n,\n * listingSpecHash, taskJobSpecHash,\n * });\n * ```\n */\nexport function useHire(): UseHireResult {\n const ctx = useAgencContext();\n\n const mutation = useMutation<HireResult, Error, HireMutationVariables>({\n mutationFn: async ({\n client,\n input,\n creator,\n creatorAddress,\n authority,\n orchestrationRpcUrl,\n orchestrationRpc,\n referral,\n }): Promise<HireResult> => {\n const { referrerArgs, referrerInjected } = referral;\n\n // Derive exactly once from the synchronously captured signer identity and\n // detached task id. The same PDA is returned after the funded await.\n const [taskPda] = await findTaskPda({\n creator: creatorAddress,\n taskId: input.taskId,\n });\n\n // P1.2: the hire gate names an explicit `moderator` (the caller's trust\n // decision) and needs the roster-entry PDA when that moderator is a\n // registered attestor, plus a record override when the listing\n // attestation predates the upgrade (legacy grace window). Resolve the\n // mechanics automatically unless the caller supplied any of them.\n const listingSpecHash = input.listingSpecHash;\n let moderationArgs: HireListingModerationAccounts = {};\n if (\n input.moderationAttestor === undefined &&\n input.moderatorIsAttestor === undefined &&\n input.listingModeration === undefined &&\n listingSpecHash !== undefined\n ) {\n moderationArgs = await resolveHireListingModerationAccounts({\n rpcUrl: orchestrationRpcUrl,\n ...(orchestrationRpc === null ? {} : { rpc: orchestrationRpc }),\n listing: input.listing,\n listingSpecHash,\n moderator: input.moderator,\n });\n }\n\n let signature: string;\n\n if (input.humanless === true) {\n // Storefront-visitor hire: no creator agent; CreatorReview-pinned, so\n // it settles via the buyer review path (useSubmissionReview).\n const result = await client.hireFromListingHumanless({\n ...input,\n ...moderationArgs,\n creator,\n ...referrerArgs,\n } as Parameters<typeof facadeNs.hireFromListingHumanless>[0]);\n signature = result.signature;\n } else {\n // Standard hire: authority == creator == buyer (the buyer has an agent).\n if (authority === undefined) {\n throw new Error(\"useHire: missing snapshotted authority\");\n }\n const result = await client.hireFromListing({\n ...input,\n ...moderationArgs,\n authority,\n creator,\n ...referrerArgs,\n } as Parameters<typeof facadeNs.hireFromListing>[0]);\n signature = result.signature;\n }\n\n return { signature, taskPda, referrerInjected };\n },\n });\n\n const hire = useCallback(\n async (input: AnyHireInput) => {\n const client = requireClient(ctx.client);\n const detachedInput = withoutReferrerArgs(input) as AnyHireInput;\n const snapshottedInput = {\n ...detachedInput,\n taskId: snapshotFixedBytes32(detachedInput.taskId, \"useHire: taskId\"),\n ...(detachedInput.listingSpecHash === undefined\n ? {}\n : {\n listingSpecHash: snapshotFixedBytes32(\n detachedInput.listingSpecHash,\n \"useHire: listingSpecHash\",\n ),\n }),\n ...(detachedInput.taskJobSpecHash === undefined\n ? {}\n : {\n taskJobSpecHash: snapshotFixedBytes32(\n detachedInput.taskJobSpecHash,\n \"useHire: taskJobSpecHash\",\n ),\n }),\n } as unknown as AnyHireInput;\n\n // Stabilize the same signer objects the SDK will place in the\n // instruction. The SDK helper canonicalizes and permanently locks the\n // address while preserving Kit's fee-payer/signer object identity and\n // any unrelated stateful wallet/session fields.\n const clientSigner = stabilizeSelectedTransactionSigner(client.signer);\n const creator = stabilizeSelectedTransactionSigner(\n clientSigner,\n detachedInput.creator,\n );\n const creatorAddress = creator.address;\n let authority: HireAuthority | undefined;\n if (detachedInput.humanless !== true) {\n const selectedAuthority = stabilizeSelectedTransactionSigner(\n clientSigner,\n detachedInput.authority,\n );\n // Creator and authority may be two wallet-adapter wrappers for the\n // same non-fee-payer account. Kit requires one object identity per\n // address across every signer role, so make creator the canonical\n // representative for that address while preserving distinct signers.\n authority = stabilizeSelectedTransactionSigner(\n creator,\n selectedAuthority,\n );\n }\n\n return mutation.mutateAsync({\n client,\n input: snapshottedInput,\n creator,\n creatorAddress,\n ...(authority === undefined ? {} : { authority }),\n orchestrationRpcUrl: ctx.orchestrationRpcUrl,\n orchestrationRpc: ctx.orchestrationRpc,\n // Resolve fresh at this synchronous enqueue boundary so provider\n // changes cannot alter an already accepted hire intent.\n referral: resolveReferrerArgs(ctx),\n });\n },\n [ctx, mutation],\n );\n\n const status: HireStatus = useMemo(() => {\n if (mutation.isPending) return \"pending\";\n if (mutation.isError) return \"error\";\n if (mutation.isSuccess) return \"success\";\n return \"idle\";\n }, [mutation.isPending, mutation.isError, mutation.isSuccess]);\n\n return {\n hire,\n status,\n taskPda: mutation.data?.taskPda ?? null,\n signature: mutation.data?.signature ?? null,\n error: mutation.error ?? null,\n isPending: mutation.isPending,\n reset: mutation.reset,\n };\n}\n","/**\n * `useWalletSigner()` — bridges a browser wallet into the kit `TransactionSigner`\n * the SDK write client expects.\n *\n * ## Adapter seam\n *\n * The package's Wallet Standard and legacy wallet-adapter bridges produce kit\n * `TransactionSigner`s, while this hook stays defined against a small\n * **documented adapter interface** ({@link WalletSignerAdapter}) so it does not\n * own any wallet library's connection lifecycle. A caller passes its adapter\n * state and this hook normalizes it to the\n * `{ signer, connected, connect() }` contract every other hook expects.\n *\n * With NO adapter passed, the hook falls back to the provider's configured\n * `signer` (the `AgencProvider config.signer` slot), so a server-supplied or\n * test signer just works and `connect()` is a no-op.\n *\n * SSR-safe: no `window`/`document`; the adapter (which may touch wallet globals)\n * is the caller's responsibility to gate to the client. This hook only reads\n * what the adapter already resolved.\n *\n * @module hooks/useWalletSigner\n */\nimport { useCallback } from \"react\";\nimport { useAgencContext } from \"../provider/context.js\";\nimport type { TransactionSigner } from \"../types.js\";\n\n/**\n * The minimal adapter shape this hook bridges. Any wallet connection hook can\n * return this shape after resolving its signer with `signerFromWalletAccount`\n * or `signerFromWalletAdapter`.\n */\nexport interface WalletSignerAdapter {\n /** The resolved kit signer, or null when no wallet is connected. */\n signer: TransactionSigner | null;\n /** Whether a wallet is currently connected. */\n connected?: boolean;\n /** Trigger the wallet connect flow (browser-only). Optional. */\n connect?: () => void | Promise<void>;\n}\n\n/** Options for {@link useWalletSigner}. */\nexport interface UseWalletSignerOptions {\n /**\n * A wallet adapter (e.g. the signer-adapters hook's result). When omitted the\n * hook falls back to the provider's `config.signer`.\n */\n adapter?: WalletSignerAdapter;\n}\n\n/** Return value of {@link useWalletSigner}. */\nexport interface UseWalletSignerResult {\n /** The resolved kit `TransactionSigner`, or null. */\n signer: TransactionSigner | null;\n /** Whether a signer is available (adapter-connected or provider-configured). */\n connected: boolean;\n /** Trigger the wallet connect flow. No-op when no adapter `connect` exists. */\n connect: () => void | Promise<void>;\n}\n\n/**\n * Resolve the active signer for write operations.\n *\n * @param options - Optional wallet adapter; falls back to the provider signer.\n * @returns {@link UseWalletSignerResult}.\n *\n * @example\n * ```tsx\n * const adapter = useMyWalletConnection(); // returns WalletSignerAdapter\n * const { signer, connected, connect } = useWalletSigner({ adapter });\n * ```\n */\nexport function useWalletSigner(\n options?: UseWalletSignerOptions,\n): UseWalletSignerResult {\n const ctx = useAgencContext();\n const adapter = options?.adapter;\n\n // Adapter wins when present; otherwise the provider's configured signer.\n const signer: TransactionSigner | null =\n adapter !== undefined ? adapter.signer : (ctx.signer ?? null);\n const connected =\n adapter !== undefined\n ? (adapter.connected ?? adapter.signer !== null)\n : ctx.signer !== null;\n\n const connect = useCallback(() => {\n // No adapter (or no connect on it) => provider-supplied signer is already\n // \"connected\"; connecting is a no-op rather than an error.\n return adapter?.connect ? adapter.connect() : undefined;\n }, [adapter]);\n\n return { signer, connected, connect };\n}\n"]}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkFIDFPM5A_cjs = require('./chunk-FIDFPM5A.cjs');
|
|
4
|
+
var kit = require('@solana/kit');
|
|
5
|
+
var marketplaceSdk = require('@tetsuo-ai/marketplace-sdk');
|
|
6
|
+
|
|
7
|
+
var ReadTransportUnsupportedError = class extends Error {
|
|
8
|
+
/** The unsupported operation name. */
|
|
9
|
+
operation;
|
|
10
|
+
constructor(operation) {
|
|
11
|
+
super(
|
|
12
|
+
`Read operation "${operation}" requires the indexer backend; the gPA fallback has no trustless equivalent. Configure an indexer baseUrl on <AgencProvider> to use it.`
|
|
13
|
+
);
|
|
14
|
+
this.name = "ReadTransportUnsupportedError";
|
|
15
|
+
this.operation = operation;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
function toAddress(pda) {
|
|
19
|
+
if (typeof pda !== "string") return pda;
|
|
20
|
+
if (!kit.isAddress(pda)) {
|
|
21
|
+
throw new TypeError(`Not a valid base58 Solana address: ${pda}`);
|
|
22
|
+
}
|
|
23
|
+
return kit.address(pda);
|
|
24
|
+
}
|
|
25
|
+
function indexerReadTransport(config, indexerClientOptions) {
|
|
26
|
+
const client = marketplaceSdk.createIndexerClient({
|
|
27
|
+
baseUrl: config.baseUrl,
|
|
28
|
+
apiKey: config.apiKey,
|
|
29
|
+
...indexerClientOptions ?? {}
|
|
30
|
+
});
|
|
31
|
+
return {
|
|
32
|
+
kind: "indexer",
|
|
33
|
+
listActiveListings: (options) => client.listActiveListings(options),
|
|
34
|
+
async getListing(pda) {
|
|
35
|
+
const listing = await client.getListing(pda);
|
|
36
|
+
const account = marketplaceSdk.getServiceListingDecoder().decode(
|
|
37
|
+
base64ToBytes(listing.accountData)
|
|
38
|
+
);
|
|
39
|
+
return {
|
|
40
|
+
address: toAddress(listing.pda),
|
|
41
|
+
account,
|
|
42
|
+
indexer: listing
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
listingHires: (pda) => client.listingHires(pda),
|
|
46
|
+
agentTrackRecord: (pda) => client.agentTrackRecord(pda)
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function gpaReadTransport(rpc) {
|
|
50
|
+
return {
|
|
51
|
+
kind: "gpa",
|
|
52
|
+
listActiveListings: (options) => marketplaceSdk.listActiveListings(rpc, options),
|
|
53
|
+
async getListing(pda) {
|
|
54
|
+
const target = toAddress(pda);
|
|
55
|
+
const all = await marketplaceSdk.listActiveListings(rpc, {});
|
|
56
|
+
const hit = all.find((entry) => entry.address === target);
|
|
57
|
+
if (hit === void 0) {
|
|
58
|
+
throw new Error(
|
|
59
|
+
`Listing ${pda} not found among active listings via the gPA fallback (it may be inactive, or your RPC restricts getProgramAccounts \u2014 use an indexer baseUrl for single-listing lookups).`
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
return { address: hit.address, account: hit.account };
|
|
63
|
+
},
|
|
64
|
+
listingHires() {
|
|
65
|
+
return Promise.reject(new ReadTransportUnsupportedError("listingHires"));
|
|
66
|
+
},
|
|
67
|
+
agentTrackRecord() {
|
|
68
|
+
return Promise.reject(
|
|
69
|
+
new ReadTransportUnsupportedError("agentTrackRecord")
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function base64ToBytes(b64) {
|
|
75
|
+
if (typeof atob === "function") {
|
|
76
|
+
const binary = atob(b64);
|
|
77
|
+
const bytes = new Uint8Array(binary.length);
|
|
78
|
+
for (let i = 0; i < binary.length; i += 1) {
|
|
79
|
+
bytes[i] = binary.charCodeAt(i);
|
|
80
|
+
}
|
|
81
|
+
return bytes;
|
|
82
|
+
}
|
|
83
|
+
return Uint8Array.from(Buffer.from(b64, "base64"));
|
|
84
|
+
}
|
|
85
|
+
function createReadTransport(config) {
|
|
86
|
+
if (config.queryTransport) return config.queryTransport;
|
|
87
|
+
if (config.indexer?.baseUrl) {
|
|
88
|
+
return indexerReadTransport(config.indexer, config.indexerClientOptions);
|
|
89
|
+
}
|
|
90
|
+
if (config.rpc) return gpaReadTransport(config.rpc);
|
|
91
|
+
throw new Error(chunkFIDFPM5A_cjs.t("transport.noReadSource"));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
exports.ReadTransportUnsupportedError = ReadTransportUnsupportedError;
|
|
95
|
+
exports.createReadTransport = createReadTransport;
|
|
96
|
+
//# sourceMappingURL=chunk-ONC6L3IX.cjs.map
|
|
97
|
+
//# sourceMappingURL=chunk-ONC6L3IX.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/transport/index.ts"],"names":["isAddress","address","createIndexerClient","getServiceListingDecoder","gpaListActiveListings","t"],"mappings":";;;;;;AAwCO,IAAM,6BAAA,GAAN,cAA4C,KAAA,CAAM;AAAA;AAAA,EAE9C,SAAA;AAAA,EACT,YAAY,SAAA,EAAmB;AAC7B,IAAA,KAAA;AAAA,MACE,mBAAmB,SAAS,CAAA,wIAAA;AAAA,KAG9B;AACA,IAAA,IAAA,CAAK,IAAA,GAAO,+BAAA;AACZ,IAAA,IAAA,CAAK,SAAA,GAAY,SAAA;AAAA,EACnB;AACF;AAGA,SAAS,UAAU,GAAA,EAAgC;AACjD,EAAA,IAAI,OAAO,GAAA,KAAQ,QAAA,EAAU,OAAO,GAAA;AACpC,EAAA,IAAI,CAACA,aAAA,CAAU,GAAG,CAAA,EAAG;AACnB,IAAA,MAAM,IAAI,SAAA,CAAU,CAAA,mCAAA,EAAsC,GAAG,CAAA,CAAE,CAAA;AAAA,EACjE;AACA,EAAA,OAAOC,YAAQ,GAAG,CAAA;AACpB;AAGA,SAAS,oBAAA,CACP,QACA,oBAAA,EACe;AACf,EAAA,MAAM,SAAwBC,kCAAA,CAAoB;AAAA,IAChD,SAAS,MAAA,CAAO,OAAA;AAAA,IAChB,QAAQ,MAAA,CAAO,MAAA;AAAA,IACf,GAAI,wBAAwB;AAAC,GAC9B,CAAA;AACD,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,SAAA;AAAA,IACN,kBAAA,EAAoB,CAAC,OAAA,KAAY,MAAA,CAAO,mBAAmB,OAAO,CAAA;A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A,CAAO,IAAI,6BAAA,CAA8B,cAAc,CAAC,CAAA;AAAA,IACzE,CAAA;AAAA,IACA,gBAAA,GAAmB;AACjB,MAAA,OAAO,OAAA,CAAQ,MAAA;AAAA,QACb,IAAI,8BAA8B,kBAAkB;AAAA,OACtD;AAAA,IACF;AAAA,GACF;AACF;AAGA,SAAS,cAAc,GAAA,EAAyB;AAC9C,EAAA,IAAI,OAAO,SAAS,UAAA,EAAY;AAC9B,IAAA,MAAM,MAAA,GAAS,KAAK,GAAG,CAAA;AACvB,IAAA,MAAM,KAAA,GAAQ,IAAI,UAAA,CAAW,MAAA,CAAO,MAAM,CAAA;AAC1C,IAAA,KAAA,IAAS,IAAI,CAAA,EAAG,CAAA,GAAI,MAAA,CAAO,MAAA,EAAQ,KAAK,CAAA,EAAG;AACzC,MAAA,KAAA,CAAM,CAAC,CAAA,GAAI,MAAA,CAAO,UAAA,CAAW,CAAC,CAAA;AAAA,IAChC;AACA,IAAA,OAAO,KAAA;AAAA,EACT;AAEA,EAAA,OAAO,WAAW,IAAA,CAAK,MAAA,CAAO,IAAA,CAAK,GAAA,EAAK,QAAQ,CAAC,CAAA;AACnD;AAeO,SAAS,oBACd,MAAA,EACe;AACf,EAAA,IAAI,MAAA,CAAO,cAAA,EAAgB,OAAO,MAAA,CAAO,cAAA;AACzC,EAAA,IAAI,MAAA,CAAO,SAAS,OAAA,EAAS;AAC3B,IAAA,OAAO,oBAAA,CAAqB,MAAA,CAAO,OAAA,EAAS,MAAA,CAAO,oBAAoB,CAAA;AAAA,EACzE;AACA,EAAA,IAAI,MAAA,CAAO,GAAA,EAAK,OAAO,gBAAA,CAAiB,OAAO,GAAG,CAAA;AAClD,EAAA,MAAM,IAAI,KAAA,CAAMC,mBAAA,CAAE,wBAAwB,CAAC,CAAA;AAC7C","file":"chunk-ONC6L3IX.cjs","sourcesContent":["/**\n * The read-transport abstraction — indexer-first with RPC/gPA fallback.\n *\n * `createReadTransport({ indexer?, rpc?, queryTransport? })` returns one\n * {@link ReadTransport}. When an indexer `baseUrl` is set it routes through the\n * SDK's `createIndexerClient` (the scale path); otherwise it falls back to the\n * SDK's gPA `listActiveListings` / account fetch (the trustless path). The two\n * backends return parity shapes BY SDK DESIGN, so callers never branch on which\n * one is live.\n *\n * `queryTransport` is a full override slot — pass a mock/pre-built transport\n * (tests, SSR fixtures) and it is used verbatim.\n *\n * SSR-safe: no `window`/`document` and no Node built-ins at module scope; the\n * SDK's indexer client is browser-safe (fetch + kit codecs only).\n *\n * @module transport\n */\nimport { address, isAddress } from \"@solana/kit\";\nimport {\n createIndexerClient,\n getServiceListingDecoder,\n listActiveListings as gpaListActiveListings,\n type IndexerClient,\n} from \"@tetsuo-ai/marketplace-sdk\";\nimport { t } from \"../strings/index.js\";\nimport type {\n Address,\n CreateReadTransportConfig,\n GpaReadSource,\n IndexerConfig,\n ReadListingResult,\n ReadTransport,\n} from \"../types.js\";\nimport type { CreateIndexerClientOptions } from \"@tetsuo-ai/marketplace-sdk\";\n\n/**\n * Thrown when a gPA-fallback transport is asked for an indexer-only capability\n * (aggregated hires / track record have no trustless gPA equivalent).\n */\nexport class ReadTransportUnsupportedError extends Error {\n /** The unsupported operation name. */\n readonly operation: string;\n constructor(operation: string) {\n super(\n `Read operation \"${operation}\" requires the indexer backend; the gPA ` +\n `fallback has no trustless equivalent. Configure an indexer baseUrl on ` +\n `<AgencProvider> to use it.`,\n );\n this.name = \"ReadTransportUnsupportedError\";\n this.operation = operation;\n }\n}\n\n/** Coerce a string|Address PDA into a kit Address (validates base58). */\nfunction toAddress(pda: Address | string): Address {\n if (typeof pda !== \"string\") return pda;\n if (!isAddress(pda)) {\n throw new TypeError(`Not a valid base58 Solana address: ${pda}`);\n }\n return address(pda);\n}\n\n/** Build the indexer-backed read transport. */\nfunction indexerReadTransport(\n config: IndexerConfig,\n indexerClientOptions?: Partial<CreateIndexerClientOptions>,\n): ReadTransport {\n const client: IndexerClient = createIndexerClient({\n baseUrl: config.baseUrl,\n apiKey: config.apiKey,\n ...(indexerClientOptions ?? {}),\n });\n return {\n kind: \"indexer\",\n listActiveListings: (options) => client.listActiveListings(options),\n async getListing(pda): Promise<ReadListingResult> {\n const listing = await client.getListing(pda);\n const account = getServiceListingDecoder().decode(\n base64ToBytes(listing.accountData),\n );\n return {\n address: toAddress(listing.pda),\n account,\n indexer: listing,\n };\n },\n listingHires: (pda) => client.listingHires(pda),\n agentTrackRecord: (pda) => client.agentTrackRecord(pda),\n };\n}\n\n/** Build the gPA-fallback read transport over a kit RPC / ProgramAccountsTransport. */\nfunction gpaReadTransport(rpc: GpaReadSource): ReadTransport {\n return {\n kind: \"gpa\",\n listActiveListings: (options) => gpaListActiveListings(rpc, options),\n async getListing(pda): Promise<ReadListingResult> {\n // No single-account decode helper crosses the transport seam here, so we\n // scope the active-listings query down to the one PDA. (The indexer path\n // is the efficient one; this fallback is the trustless escape hatch.)\n const target = toAddress(pda);\n const all = await gpaListActiveListings(rpc, {});\n const hit = all.find((entry) => entry.address === target);\n if (hit === undefined) {\n throw new Error(\n `Listing ${pda} not found among active listings via the gPA ` +\n `fallback (it may be inactive, or your RPC restricts ` +\n `getProgramAccounts — use an indexer baseUrl for single-listing ` +\n `lookups).`,\n );\n }\n return { address: hit.address, account: hit.account };\n },\n listingHires() {\n return Promise.reject(new ReadTransportUnsupportedError(\"listingHires\"));\n },\n agentTrackRecord() {\n return Promise.reject(\n new ReadTransportUnsupportedError(\"agentTrackRecord\"),\n );\n },\n };\n}\n\n/** Browser-safe base64 → bytes (atob in browsers, Buffer in Node). */\nfunction base64ToBytes(b64: string): Uint8Array {\n if (typeof atob === \"function\") {\n const binary = atob(b64);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i += 1) {\n bytes[i] = binary.charCodeAt(i);\n }\n return bytes;\n }\n // Node fallback — Buffer is always present there.\n return Uint8Array.from(Buffer.from(b64, \"base64\"));\n}\n\n/**\n * Create the unified read transport.\n *\n * Resolution order:\n * 1. `queryTransport` override (wins — tests/mocks/SSR fixtures);\n * 2. `indexer.baseUrl` present → indexer-first transport;\n * 3. `rpc` present → gPA fallback transport;\n * 4. nothing configured → throws a descriptive error.\n *\n * @param config - See {@link CreateReadTransportConfig}.\n * @returns A {@link ReadTransport}.\n * @throws Error when no read source is configured.\n */\nexport function createReadTransport(\n config: CreateReadTransportConfig,\n): ReadTransport {\n if (config.queryTransport) return config.queryTransport;\n if (config.indexer?.baseUrl) {\n return indexerReadTransport(config.indexer, config.indexerClientOptions);\n }\n if (config.rpc) return gpaReadTransport(config.rpc);\n throw new Error(t(\"transport.noReadSource\"));\n}\n\nexport type { ReadTransport } from \"../types.js\";\n"]}
|