@t2000/sdk 10.36.1 → 10.37.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/README.md +2 -0
- package/dist/index.cjs +532 -6
- package/dist/index.d.cts +283 -15
- package/dist/index.d.ts +283 -15
- package/dist/index.js +503 -7
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -35,6 +35,8 @@ The SDK also ships the **escrow-job builders** for agent-to-agent deliverable wo
|
|
|
35
35
|
|
|
36
36
|
The **open board** reads are public: `listOpenJobs(base, { status, query, limit, offset })` returns ONE page — `{ total, returned, truncated, nextOffset?, openJobs }` — never a bare list, so check `truncated` before treating a page as the whole board. Board rows carry a one-line `briefPreview`, not the task; the full `brief` is on the detail read, `getOpenJob(base, id)`.
|
|
37
37
|
|
|
38
|
+
**Sell headlessly** — `CommerceClient` is the one write path for seller onboarding (the same one `t2 agent *` / `t2 service *` call): `register()` (sponsored, idempotent) · `updateProfile()` · `upsertService()` / `retireService()` · `createPackage({ name, tiers })` (three `{base}-basic|standard|premium` listings, same slug math as the console) · `listEndpoint()` (x402, live-probed) · `resolveRef('#16')`. Gasless; errors are `T2000Error` with the API's message. Walkthrough → **[docs.t2000.ai/how-to/sell-headlessly](https://docs.t2000.ai/how-to/sell-headlessly)**.
|
|
39
|
+
|
|
38
40
|
## Full reference
|
|
39
41
|
|
|
40
42
|
Factory methods, full API surface, supported assets, Cetus swap routing, x402 payments, error handling, architecture →
|
package/dist/index.cjs
CHANGED
|
@@ -3762,6 +3762,17 @@ function isCustomHireEnvelope(text) {
|
|
|
3762
3762
|
return false;
|
|
3763
3763
|
}
|
|
3764
3764
|
}
|
|
3765
|
+
|
|
3766
|
+
// src/sponsored-guard.ts
|
|
3767
|
+
var sponsoredTxGuard = null;
|
|
3768
|
+
function setSponsoredTxGuard(guard) {
|
|
3769
|
+
sponsoredTxGuard = guard;
|
|
3770
|
+
}
|
|
3771
|
+
function runSponsoredTxGuard(ctx) {
|
|
3772
|
+
sponsoredTxGuard?.(ctx);
|
|
3773
|
+
}
|
|
3774
|
+
|
|
3775
|
+
// src/open-jobs.ts
|
|
3765
3776
|
async function fetchJson(url, init) {
|
|
3766
3777
|
const res = await fetch(url, {
|
|
3767
3778
|
method: init?.method ?? "GET",
|
|
@@ -3776,10 +3787,6 @@ async function fetchJson(url, init) {
|
|
|
3776
3787
|
}
|
|
3777
3788
|
return json;
|
|
3778
3789
|
}
|
|
3779
|
-
var sponsoredTxGuard = null;
|
|
3780
|
-
function setSponsoredTxGuard(guard) {
|
|
3781
|
-
sponsoredTxGuard = guard;
|
|
3782
|
-
}
|
|
3783
3790
|
async function listOpenJobs(base, filter = {}) {
|
|
3784
3791
|
const params = new URLSearchParams();
|
|
3785
3792
|
if (filter.status) params.set("status", filter.status);
|
|
@@ -3811,7 +3818,7 @@ async function getOpenJob(base, id) {
|
|
|
3811
3818
|
}
|
|
3812
3819
|
async function sponsoredOpeningVerb(base, signer, action, params) {
|
|
3813
3820
|
const address = signer.getAddress();
|
|
3814
|
-
|
|
3821
|
+
runSponsoredTxGuard({ base, action });
|
|
3815
3822
|
const prep = await fetchJson(`${base}/job/prepare`, {
|
|
3816
3823
|
method: "POST",
|
|
3817
3824
|
body: { address, action, params }
|
|
@@ -3821,7 +3828,7 @@ async function sponsoredOpeningVerb(base, signer, action, params) {
|
|
|
3821
3828
|
if (!(nonce && txBytes)) {
|
|
3822
3829
|
throw new Error("Failed to prepare the transaction.");
|
|
3823
3830
|
}
|
|
3824
|
-
|
|
3831
|
+
runSponsoredTxGuard({ base, action, txBytes });
|
|
3825
3832
|
const { signature } = await signer.signTransaction(utils.fromBase64(txBytes));
|
|
3826
3833
|
const json = await fetchJson(`${base}/job/submit`, {
|
|
3827
3834
|
method: "POST",
|
|
@@ -3858,6 +3865,495 @@ function refundOpenJob(base, signer, openingId) {
|
|
|
3858
3865
|
});
|
|
3859
3866
|
}
|
|
3860
3867
|
|
|
3868
|
+
// src/commerce/endpoint.ts
|
|
3869
|
+
init_errors();
|
|
3870
|
+
|
|
3871
|
+
// src/commerce/http.ts
|
|
3872
|
+
init_errors();
|
|
3873
|
+
var DEFAULT_COMMERCE_API_BASE2 = "https://api.t2000.ai/v1";
|
|
3874
|
+
function codeForStatus(status) {
|
|
3875
|
+
if (status === 400 || status === 409 || status === 422) {
|
|
3876
|
+
return "INVALID_INPUT";
|
|
3877
|
+
}
|
|
3878
|
+
if (status === 429 || status >= 500) {
|
|
3879
|
+
return "RPC_ERROR";
|
|
3880
|
+
}
|
|
3881
|
+
return "UNKNOWN";
|
|
3882
|
+
}
|
|
3883
|
+
function apiErrorMessage(json, status) {
|
|
3884
|
+
const err = json.error;
|
|
3885
|
+
if (typeof err === "string") {
|
|
3886
|
+
return err;
|
|
3887
|
+
}
|
|
3888
|
+
const msg = err?.message;
|
|
3889
|
+
return typeof msg === "string" ? msg : `HTTP ${status}`;
|
|
3890
|
+
}
|
|
3891
|
+
async function apiRequest(url, init) {
|
|
3892
|
+
const res = await fetch(url, {
|
|
3893
|
+
method: init?.method ?? (init?.body === void 0 ? "GET" : "POST"),
|
|
3894
|
+
headers: {
|
|
3895
|
+
accept: "application/json",
|
|
3896
|
+
...init?.body === void 0 ? {} : { "Content-Type": "application/json" }
|
|
3897
|
+
},
|
|
3898
|
+
body: init?.body === void 0 ? void 0 : JSON.stringify(init.body)
|
|
3899
|
+
});
|
|
3900
|
+
const json = await res.json().catch(() => ({}));
|
|
3901
|
+
return { ok: res.ok, status: res.status, json };
|
|
3902
|
+
}
|
|
3903
|
+
async function apiJson(url, init) {
|
|
3904
|
+
const res = await apiRequest(url, init);
|
|
3905
|
+
if (!res.ok) {
|
|
3906
|
+
throw new exports.T2000Error(codeForStatus(res.status), apiErrorMessage(res.json, res.status), {
|
|
3907
|
+
status: res.status,
|
|
3908
|
+
...res.json.error && typeof res.json.error === "object" ? { api: res.json.error } : {}
|
|
3909
|
+
});
|
|
3910
|
+
}
|
|
3911
|
+
return res.json;
|
|
3912
|
+
}
|
|
3913
|
+
function invalidInput(message) {
|
|
3914
|
+
return new exports.T2000Error("INVALID_INPUT", message);
|
|
3915
|
+
}
|
|
3916
|
+
async function signPreparedTx(base, action, signer, txBytes) {
|
|
3917
|
+
runSponsoredTxGuard({ base, action, txBytes });
|
|
3918
|
+
const { signature } = await signer.signTransaction(utils.fromBase64(txBytes));
|
|
3919
|
+
return signature;
|
|
3920
|
+
}
|
|
3921
|
+
|
|
3922
|
+
// src/commerce/endpoint.ts
|
|
3923
|
+
function endpointIssueLines(prep) {
|
|
3924
|
+
const lines = (prep.probe?.issues ?? []).map(
|
|
3925
|
+
(i) => ` \u2717 ${i.message ?? i.code}`
|
|
3926
|
+
);
|
|
3927
|
+
for (const r of prep.routes ?? []) {
|
|
3928
|
+
if (r.probeOk === false) {
|
|
3929
|
+
lines.push(` \u2717 ${r.method ?? "POST"} ${r.path}`);
|
|
3930
|
+
for (const i of r.issues ?? []) {
|
|
3931
|
+
lines.push(` ${i.message ?? i.code}`);
|
|
3932
|
+
}
|
|
3933
|
+
}
|
|
3934
|
+
}
|
|
3935
|
+
return lines;
|
|
3936
|
+
}
|
|
3937
|
+
async function setEndpoint(apiBase, signer, endpoint, primary) {
|
|
3938
|
+
const address = signer.getAddress();
|
|
3939
|
+
runSponsoredTxGuard({ base: apiBase, action: "update" });
|
|
3940
|
+
const res = await apiRequest(`${apiBase}/agent/endpoint/prepare`, {
|
|
3941
|
+
method: "POST",
|
|
3942
|
+
body: { address, endpoint, ...primary ? { primary } : {} }
|
|
3943
|
+
});
|
|
3944
|
+
const prep = res.json;
|
|
3945
|
+
if (!res.ok) {
|
|
3946
|
+
const msg = apiErrorMessage(prep, res.status);
|
|
3947
|
+
const detail = endpointIssueLines(prep).join("\n");
|
|
3948
|
+
throw new exports.T2000Error(
|
|
3949
|
+
"INVALID_INPUT",
|
|
3950
|
+
detail ? `${msg}
|
|
3951
|
+
${detail}` : msg,
|
|
3952
|
+
{ status: res.status, probe: prep.probe ?? null, routes: prep.routes ?? [] }
|
|
3953
|
+
);
|
|
3954
|
+
}
|
|
3955
|
+
if (!(typeof prep.nonce === "string" && typeof prep.txBytes === "string")) {
|
|
3956
|
+
throw invalidInput("Failed to prepare the listing.");
|
|
3957
|
+
}
|
|
3958
|
+
const signature = await signPreparedTx(apiBase, "update", signer, prep.txBytes);
|
|
3959
|
+
const sub = await apiJson(`${apiBase}/agent/endpoint/submit`, {
|
|
3960
|
+
method: "POST",
|
|
3961
|
+
body: { nonce: prep.nonce, address, signature }
|
|
3962
|
+
});
|
|
3963
|
+
const listed = endpoint !== "";
|
|
3964
|
+
return {
|
|
3965
|
+
address,
|
|
3966
|
+
endpoint: listed ? prep.primary?.url ?? endpoint : null,
|
|
3967
|
+
listed,
|
|
3968
|
+
probe: prep.probe ?? null,
|
|
3969
|
+
origin: prep.origin ?? null,
|
|
3970
|
+
primary: prep.primary ?? null,
|
|
3971
|
+
routes: prep.routes ?? [],
|
|
3972
|
+
...typeof sub.digest === "string" ? { digest: sub.digest } : {}
|
|
3973
|
+
};
|
|
3974
|
+
}
|
|
3975
|
+
function listEndpoint(apiBase, signer, endpoint, opts = {}) {
|
|
3976
|
+
const target = endpoint.trim();
|
|
3977
|
+
if (!target) {
|
|
3978
|
+
throw invalidInput("Provide your x402 endpoint URL.");
|
|
3979
|
+
}
|
|
3980
|
+
return setEndpoint(apiBase, signer, target, opts.primary);
|
|
3981
|
+
}
|
|
3982
|
+
function removeEndpoint(apiBase, signer) {
|
|
3983
|
+
return setEndpoint(apiBase, signer, "");
|
|
3984
|
+
}
|
|
3985
|
+
|
|
3986
|
+
// src/commerce/types.ts
|
|
3987
|
+
var AGENT_CATEGORIES = [
|
|
3988
|
+
"ai-models",
|
|
3989
|
+
"data-feeds",
|
|
3990
|
+
"finance",
|
|
3991
|
+
"research",
|
|
3992
|
+
"dev-tools",
|
|
3993
|
+
"creative",
|
|
3994
|
+
"travel",
|
|
3995
|
+
"comms",
|
|
3996
|
+
"other"
|
|
3997
|
+
];
|
|
3998
|
+
var SERVICE_TIERS = ["basic", "standard", "premium"];
|
|
3999
|
+
|
|
4000
|
+
// src/commerce/package-slug.ts
|
|
4001
|
+
var SERVICE_SLUG_RE = /^[a-z0-9][a-z0-9-]{1,47}$/;
|
|
4002
|
+
function trimDashes(s) {
|
|
4003
|
+
let start = 0;
|
|
4004
|
+
let end = s.length;
|
|
4005
|
+
while (start < end && s.charCodeAt(start) === 45) start += 1;
|
|
4006
|
+
while (end > start && s.charCodeAt(end - 1) === 45) end -= 1;
|
|
4007
|
+
return s.slice(start, end);
|
|
4008
|
+
}
|
|
4009
|
+
function slugify(name) {
|
|
4010
|
+
return trimDashes(name.toLowerCase().replaceAll(/[^a-z0-9]+/g, "-")).slice(0, 48);
|
|
4011
|
+
}
|
|
4012
|
+
var TIER_SLUG_RE = /^(.+)-(basic|standard|premium)$/;
|
|
4013
|
+
var MAX_TIER_BASE_LENGTH = 48 - "-standard".length;
|
|
4014
|
+
function parseServiceTierSlug(slug) {
|
|
4015
|
+
const m = TIER_SLUG_RE.exec(slug);
|
|
4016
|
+
if (!m) {
|
|
4017
|
+
return null;
|
|
4018
|
+
}
|
|
4019
|
+
return { base: m[1], tier: m[2] };
|
|
4020
|
+
}
|
|
4021
|
+
function packageBaseSlug(slugified) {
|
|
4022
|
+
const cut = slugified.slice(0, MAX_TIER_BASE_LENGTH);
|
|
4023
|
+
let end = cut.length;
|
|
4024
|
+
while (end > 0 && cut.charCodeAt(end - 1) === 45) end -= 1;
|
|
4025
|
+
return cut.slice(0, end);
|
|
4026
|
+
}
|
|
4027
|
+
function packageTierSlugs(base) {
|
|
4028
|
+
return SERVICE_TIERS.map((tier) => ({ tier, slug: `${base}-${tier}` }));
|
|
4029
|
+
}
|
|
4030
|
+
|
|
4031
|
+
// src/commerce/challenge.ts
|
|
4032
|
+
async function sha256Hex2(content) {
|
|
4033
|
+
const digest = await crypto.subtle.digest(
|
|
4034
|
+
"SHA-256",
|
|
4035
|
+
new TextEncoder().encode(content)
|
|
4036
|
+
);
|
|
4037
|
+
return Array.from(new Uint8Array(digest)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
4038
|
+
}
|
|
4039
|
+
function servicePayloadSha256(payload) {
|
|
4040
|
+
return sha256Hex2(JSON.stringify(payload));
|
|
4041
|
+
}
|
|
4042
|
+
function profileChallengeMessage(nonce) {
|
|
4043
|
+
return `t2000-agent-profile:${nonce}`;
|
|
4044
|
+
}
|
|
4045
|
+
function serviceChallengeMessage(nonce, payloadHash) {
|
|
4046
|
+
return `t2000-agent-service:${nonce}:${payloadHash}`;
|
|
4047
|
+
}
|
|
4048
|
+
async function fetchChallengeNonce(apiBase, address) {
|
|
4049
|
+
const challenge = await apiJson(`${apiBase}/agent/challenge`, {
|
|
4050
|
+
method: "POST",
|
|
4051
|
+
body: { address }
|
|
4052
|
+
});
|
|
4053
|
+
const nonce = challenge.nonce;
|
|
4054
|
+
if (typeof nonce !== "string" || !nonce) {
|
|
4055
|
+
throw invalidInput("Failed to get a challenge nonce.");
|
|
4056
|
+
}
|
|
4057
|
+
return nonce;
|
|
4058
|
+
}
|
|
4059
|
+
async function signChallenge(apiBase, signer, message) {
|
|
4060
|
+
const nonce = await fetchChallengeNonce(apiBase, signer.getAddress());
|
|
4061
|
+
const text = await message(nonce);
|
|
4062
|
+
const { signature } = await signer.signPersonalMessage(
|
|
4063
|
+
new TextEncoder().encode(text)
|
|
4064
|
+
);
|
|
4065
|
+
return { nonce, signature };
|
|
4066
|
+
}
|
|
4067
|
+
|
|
4068
|
+
// src/commerce/service.ts
|
|
4069
|
+
function serviceUpsertPayload(input) {
|
|
4070
|
+
const slug = input.slug.trim().toLowerCase();
|
|
4071
|
+
if (!SERVICE_SLUG_RE.test(slug)) {
|
|
4072
|
+
throw invalidInput(
|
|
4073
|
+
"slug must be 2-48 chars of [a-z0-9-], starting alphanumeric."
|
|
4074
|
+
);
|
|
4075
|
+
}
|
|
4076
|
+
return {
|
|
4077
|
+
...input.mode ? { mode: input.mode } : {},
|
|
4078
|
+
slug,
|
|
4079
|
+
name: input.name.trim(),
|
|
4080
|
+
description: input.description.trim(),
|
|
4081
|
+
priceUsdc: input.priceUsdc,
|
|
4082
|
+
slaMinutes: input.slaMinutes,
|
|
4083
|
+
reviewWindowMinutes: input.reviewWindowMinutes ?? 1440,
|
|
4084
|
+
rejectSplitBps: input.rejectSplitBps ?? 8e3,
|
|
4085
|
+
requirements: input.requirements,
|
|
4086
|
+
deliverable: input.deliverable.trim(),
|
|
4087
|
+
...input.examples === void 0 ? {} : { examples: input.examples }
|
|
4088
|
+
};
|
|
4089
|
+
}
|
|
4090
|
+
async function signedServiceAction(apiBase, signer, action, payload) {
|
|
4091
|
+
const address = signer.getAddress();
|
|
4092
|
+
const { nonce, signature } = await signChallenge(
|
|
4093
|
+
apiBase,
|
|
4094
|
+
signer,
|
|
4095
|
+
async (n) => serviceChallengeMessage(n, await servicePayloadSha256(payload))
|
|
4096
|
+
);
|
|
4097
|
+
return apiJson(`${apiBase}/agent/service`, {
|
|
4098
|
+
method: "POST",
|
|
4099
|
+
body: { address, nonce, signature, action, payload }
|
|
4100
|
+
});
|
|
4101
|
+
}
|
|
4102
|
+
async function upsertService(apiBase, signer, input) {
|
|
4103
|
+
const payload = serviceUpsertPayload(input);
|
|
4104
|
+
const response = await signedServiceAction(apiBase, signer, "upsert", payload);
|
|
4105
|
+
return { address: signer.getAddress(), slug: payload.slug, response };
|
|
4106
|
+
}
|
|
4107
|
+
async function retireService(apiBase, signer, slug) {
|
|
4108
|
+
const clean = slug.trim().toLowerCase();
|
|
4109
|
+
if (!SERVICE_SLUG_RE.test(clean)) {
|
|
4110
|
+
throw invalidInput("slug must be 2-48 chars of [a-z0-9-], starting alphanumeric.");
|
|
4111
|
+
}
|
|
4112
|
+
const response = await signedServiceAction(apiBase, signer, "retire", {
|
|
4113
|
+
slug: clean
|
|
4114
|
+
});
|
|
4115
|
+
return { address: signer.getAddress(), slug: clean, response };
|
|
4116
|
+
}
|
|
4117
|
+
|
|
4118
|
+
// src/commerce/package.ts
|
|
4119
|
+
function planPackage(input) {
|
|
4120
|
+
const name = input.name.trim();
|
|
4121
|
+
if (!name) {
|
|
4122
|
+
throw invalidInput("name is required.");
|
|
4123
|
+
}
|
|
4124
|
+
const base = packageBaseSlug((input.baseSlug ?? slugify(name)).trim().toLowerCase());
|
|
4125
|
+
if (!base || !SERVICE_SLUG_RE.test(`${base}-basic`)) {
|
|
4126
|
+
throw invalidInput(
|
|
4127
|
+
"Could not derive a package slug from the name \u2014 pass baseSlug (a-z, 0-9, dashes)."
|
|
4128
|
+
);
|
|
4129
|
+
}
|
|
4130
|
+
const byTier = /* @__PURE__ */ new Map();
|
|
4131
|
+
for (const t of input.tiers) {
|
|
4132
|
+
if (!SERVICE_TIERS.includes(t.tier)) {
|
|
4133
|
+
throw invalidInput(`Unknown tier "${t.tier}" \u2014 use basic, standard, premium.`);
|
|
4134
|
+
}
|
|
4135
|
+
if (byTier.has(t.tier)) {
|
|
4136
|
+
throw invalidInput(`Tier "${t.tier}" given twice.`);
|
|
4137
|
+
}
|
|
4138
|
+
byTier.set(t.tier, t);
|
|
4139
|
+
}
|
|
4140
|
+
const missing = SERVICE_TIERS.filter((t) => !byTier.has(t));
|
|
4141
|
+
if (missing.length > 0) {
|
|
4142
|
+
throw invalidInput(
|
|
4143
|
+
`A package needs all three tiers \u2014 missing: ${missing.join(", ")}.`
|
|
4144
|
+
);
|
|
4145
|
+
}
|
|
4146
|
+
return {
|
|
4147
|
+
base,
|
|
4148
|
+
tiers: packageTierSlugs(base).map(({ tier, slug }) => {
|
|
4149
|
+
const t = byTier.get(tier);
|
|
4150
|
+
return {
|
|
4151
|
+
tier,
|
|
4152
|
+
slug,
|
|
4153
|
+
input: {
|
|
4154
|
+
mode: "create",
|
|
4155
|
+
slug,
|
|
4156
|
+
name,
|
|
4157
|
+
description: (t.description ?? input.description).trim(),
|
|
4158
|
+
priceUsdc: t.priceUsdc,
|
|
4159
|
+
slaMinutes: t.slaMinutes ?? input.slaMinutes,
|
|
4160
|
+
deliverable: t.deliverable,
|
|
4161
|
+
requirements: input.requirements,
|
|
4162
|
+
reviewWindowMinutes: t.reviewWindowMinutes ?? input.reviewWindowMinutes,
|
|
4163
|
+
rejectSplitBps: t.rejectSplitBps ?? input.rejectSplitBps
|
|
4164
|
+
}
|
|
4165
|
+
};
|
|
4166
|
+
})
|
|
4167
|
+
};
|
|
4168
|
+
}
|
|
4169
|
+
async function createPackage(apiBase, signer, input) {
|
|
4170
|
+
const plan = planPackage(input);
|
|
4171
|
+
const tiers = [];
|
|
4172
|
+
for (const t of plan.tiers) {
|
|
4173
|
+
await upsertService(apiBase, signer, t.input);
|
|
4174
|
+
tiers.push({ tier: t.tier, slug: t.slug, priceUsdc: t.input.priceUsdc });
|
|
4175
|
+
}
|
|
4176
|
+
return { address: signer.getAddress(), base: plan.base, tiers };
|
|
4177
|
+
}
|
|
4178
|
+
|
|
4179
|
+
// src/commerce/resolve.ts
|
|
4180
|
+
init_errors();
|
|
4181
|
+
var FALLBACK_MISS = "Use an Agent ID (#93), @handle, or full 0x\u2026 address.";
|
|
4182
|
+
function agentResolveUrl(q, apiBase = DEFAULT_COMMERCE_API_BASE2) {
|
|
4183
|
+
return `${apiBase}/agents/resolve?q=${encodeURIComponent(q.trim())}`;
|
|
4184
|
+
}
|
|
4185
|
+
async function resolveAgentRef(q, apiBase = DEFAULT_COMMERCE_API_BASE2) {
|
|
4186
|
+
const res = await apiRequest(agentResolveUrl(q, apiBase));
|
|
4187
|
+
const json = res.json;
|
|
4188
|
+
if (!(res.ok && typeof json.address === "string")) {
|
|
4189
|
+
throw new exports.T2000Error(
|
|
4190
|
+
"CONTACT_NOT_FOUND",
|
|
4191
|
+
typeof json.error === "string" ? json.error : FALLBACK_MISS,
|
|
4192
|
+
{ ref: q }
|
|
4193
|
+
);
|
|
4194
|
+
}
|
|
4195
|
+
return {
|
|
4196
|
+
address: json.address,
|
|
4197
|
+
...typeof json.numericId === "number" || json.numericId === null ? { numericId: json.numericId } : {},
|
|
4198
|
+
...typeof json.name === "string" ? { name: json.name } : {}
|
|
4199
|
+
};
|
|
4200
|
+
}
|
|
4201
|
+
async function getAgentProfile(address, apiBase = DEFAULT_COMMERCE_API_BASE2) {
|
|
4202
|
+
const res = await apiRequest(`${apiBase}/agents/${encodeURIComponent(address)}`);
|
|
4203
|
+
if (!res.ok) {
|
|
4204
|
+
return null;
|
|
4205
|
+
}
|
|
4206
|
+
return { ...res.json, address };
|
|
4207
|
+
}
|
|
4208
|
+
|
|
4209
|
+
// src/commerce/profile.ts
|
|
4210
|
+
function parseAgentCategory(raw) {
|
|
4211
|
+
const c = raw.trim().toLowerCase();
|
|
4212
|
+
if (!AGENT_CATEGORIES.includes(c)) {
|
|
4213
|
+
throw invalidInput(
|
|
4214
|
+
`category must be one of: ${AGENT_CATEGORIES.join(", ")} (got "${raw}").`
|
|
4215
|
+
);
|
|
4216
|
+
}
|
|
4217
|
+
return c;
|
|
4218
|
+
}
|
|
4219
|
+
async function updateProfile(apiBase, signer, input) {
|
|
4220
|
+
const hasField = input.name !== void 0 || input.imageUrl !== void 0 || input.description !== void 0 || input.category !== void 0 || input.website !== void 0 || input.twitter !== void 0 || input.github !== void 0;
|
|
4221
|
+
if (!hasField) {
|
|
4222
|
+
throw invalidInput(
|
|
4223
|
+
"Provide at least one of name, imageUrl, description, category, website, twitter, github."
|
|
4224
|
+
);
|
|
4225
|
+
}
|
|
4226
|
+
const category = input.category === void 0 ? void 0 : parseAgentCategory(input.category);
|
|
4227
|
+
const address = signer.getAddress();
|
|
4228
|
+
const { nonce, signature } = await signChallenge(
|
|
4229
|
+
apiBase,
|
|
4230
|
+
signer,
|
|
4231
|
+
profileChallengeMessage
|
|
4232
|
+
);
|
|
4233
|
+
await apiJson(`${apiBase}/agent/profile`, {
|
|
4234
|
+
method: "POST",
|
|
4235
|
+
body: {
|
|
4236
|
+
address,
|
|
4237
|
+
nonce,
|
|
4238
|
+
signature,
|
|
4239
|
+
displayName: input.name,
|
|
4240
|
+
imageUrl: input.imageUrl,
|
|
4241
|
+
description: input.description,
|
|
4242
|
+
category,
|
|
4243
|
+
website: input.website,
|
|
4244
|
+
twitter: input.twitter,
|
|
4245
|
+
github: input.github
|
|
4246
|
+
}
|
|
4247
|
+
});
|
|
4248
|
+
return { address };
|
|
4249
|
+
}
|
|
4250
|
+
async function ensureCategory(apiBase, signer, category) {
|
|
4251
|
+
if (category !== void 0) {
|
|
4252
|
+
const parsed = parseAgentCategory(category);
|
|
4253
|
+
await updateProfile(apiBase, signer, { category: parsed });
|
|
4254
|
+
return parsed;
|
|
4255
|
+
}
|
|
4256
|
+
const profile = await getAgentProfile(signer.getAddress(), apiBase).catch(
|
|
4257
|
+
() => null
|
|
4258
|
+
);
|
|
4259
|
+
const existing = typeof profile?.category === "string" && profile.category ? profile.category : null;
|
|
4260
|
+
if (!existing) {
|
|
4261
|
+
throw invalidInput(
|
|
4262
|
+
`Pick a directory category first \u2014 buyers browse listings by category. Set one of ${AGENT_CATEGORIES.join(" | ")} (updateProfile({ category }) / t2 agent profile --category).`
|
|
4263
|
+
);
|
|
4264
|
+
}
|
|
4265
|
+
return existing;
|
|
4266
|
+
}
|
|
4267
|
+
|
|
4268
|
+
// src/commerce/register.ts
|
|
4269
|
+
async function registerAgent(apiBase, signer) {
|
|
4270
|
+
const address = signer.getAddress();
|
|
4271
|
+
runSponsoredTxGuard({ base: apiBase, action: "register" });
|
|
4272
|
+
const prep = await apiJson(`${apiBase}/agent/register/prepare`, {
|
|
4273
|
+
method: "POST",
|
|
4274
|
+
body: { address }
|
|
4275
|
+
});
|
|
4276
|
+
if (prep.alreadyRegistered === true) {
|
|
4277
|
+
return { address, alreadyRegistered: true };
|
|
4278
|
+
}
|
|
4279
|
+
const regNonce = prep.regNonce;
|
|
4280
|
+
const txBytes = prep.txBytes;
|
|
4281
|
+
if (!(typeof regNonce === "string" && typeof txBytes === "string")) {
|
|
4282
|
+
throw invalidInput("Failed to prepare registration.");
|
|
4283
|
+
}
|
|
4284
|
+
const signature = await signPreparedTx(apiBase, "register", signer, txBytes);
|
|
4285
|
+
const res = await apiJson(`${apiBase}/agent/register/submit`, {
|
|
4286
|
+
method: "POST",
|
|
4287
|
+
body: { regNonce, address, agentSignature: signature }
|
|
4288
|
+
});
|
|
4289
|
+
return {
|
|
4290
|
+
address,
|
|
4291
|
+
alreadyRegistered: res.alreadyRegistered === true,
|
|
4292
|
+
...typeof res.digest === "string" ? { digest: res.digest } : {}
|
|
4293
|
+
};
|
|
4294
|
+
}
|
|
4295
|
+
|
|
4296
|
+
// src/commerce/client.ts
|
|
4297
|
+
var CommerceClient = class {
|
|
4298
|
+
signer;
|
|
4299
|
+
apiBase;
|
|
4300
|
+
constructor(options) {
|
|
4301
|
+
this.signer = options.signer;
|
|
4302
|
+
let base = options.apiBase ?? DEFAULT_COMMERCE_API_BASE2;
|
|
4303
|
+
while (base.endsWith("/")) base = base.slice(0, -1);
|
|
4304
|
+
this.apiBase = base;
|
|
4305
|
+
}
|
|
4306
|
+
/** This signer's wallet address. */
|
|
4307
|
+
get address() {
|
|
4308
|
+
return this.signer.getAddress();
|
|
4309
|
+
}
|
|
4310
|
+
/** Register the wallet as an on-chain Agent ID (sponsored; idempotent). */
|
|
4311
|
+
register() {
|
|
4312
|
+
return registerAgent(this.apiBase, this.signer);
|
|
4313
|
+
}
|
|
4314
|
+
/** Set public profile fields (signed, no gas). */
|
|
4315
|
+
updateProfile(input) {
|
|
4316
|
+
return updateProfile(this.apiBase, this.signer, input);
|
|
4317
|
+
}
|
|
4318
|
+
/** The sell gate — set `category` or confirm the live one; throws when
|
|
4319
|
+
* neither exists. Returns the category in force. */
|
|
4320
|
+
ensureCategory(category) {
|
|
4321
|
+
return ensureCategory(this.apiBase, this.signer, category);
|
|
4322
|
+
}
|
|
4323
|
+
/** This seller's public profile (null when unregistered). */
|
|
4324
|
+
profile() {
|
|
4325
|
+
return getAgentProfile(this.address, this.apiBase);
|
|
4326
|
+
}
|
|
4327
|
+
/** List (or fully re-write) one service — `mode: "create"` refuses a live slug. */
|
|
4328
|
+
upsertService(input) {
|
|
4329
|
+
return upsertService(this.apiBase, this.signer, input);
|
|
4330
|
+
}
|
|
4331
|
+
/** Take a service off the board (funded jobs keep settling on-chain). */
|
|
4332
|
+
retireService(input) {
|
|
4333
|
+
return retireService(
|
|
4334
|
+
this.apiBase,
|
|
4335
|
+
this.signer,
|
|
4336
|
+
typeof input === "string" ? input : input.slug
|
|
4337
|
+
);
|
|
4338
|
+
}
|
|
4339
|
+
/** Three tiers under one name — `{base}-basic|standard|premium`. */
|
|
4340
|
+
createPackage(input) {
|
|
4341
|
+
return createPackage(this.apiBase, this.signer, input);
|
|
4342
|
+
}
|
|
4343
|
+
/** Sell an x402 API (origin or one 402 URL) — live-probed, sponsored. */
|
|
4344
|
+
listEndpoint(endpoint, opts = {}) {
|
|
4345
|
+
return listEndpoint(this.apiBase, this.signer, endpoint, opts);
|
|
4346
|
+
}
|
|
4347
|
+
/** Clear the x402 listing. */
|
|
4348
|
+
removeEndpoint() {
|
|
4349
|
+
return removeEndpoint(this.apiBase, this.signer);
|
|
4350
|
+
}
|
|
4351
|
+
/** `#93` · `@handle` · `name.sui` · `0x…` → wallet (marketplace refs only). */
|
|
4352
|
+
resolveRef(q) {
|
|
4353
|
+
return resolveAgentRef(q, this.apiBase);
|
|
4354
|
+
}
|
|
4355
|
+
};
|
|
4356
|
+
|
|
3861
4357
|
// src/utils/resolve-created.ts
|
|
3862
4358
|
var OPENING_TYPE_MARKER = "::opening::Opening<";
|
|
3863
4359
|
var ESCROW_JOB_TYPE_MARKER = "::escrow::Job<";
|
|
@@ -4309,11 +4805,13 @@ exports.A2A_ESCROW_PACKAGE_V6_ID = A2A_ESCROW_PACKAGE_V6_ID;
|
|
|
4309
4805
|
exports.A2A_ESCROW_PACKAGE_V7_ID = A2A_ESCROW_PACKAGE_V7_ID;
|
|
4310
4806
|
exports.A2A_ESCROW_PACKAGE_V8_ID = A2A_ESCROW_PACKAGE_V8_ID;
|
|
4311
4807
|
exports.A2A_SCORE_BOARD_ID = A2A_SCORE_BOARD_ID;
|
|
4808
|
+
exports.AGENT_CATEGORIES = AGENT_CATEGORIES;
|
|
4312
4809
|
exports.AUDRIC_PARENT = AUDRIC_PARENT;
|
|
4313
4810
|
exports.AUDRIC_PARENT_NAME = AUDRIC_PARENT_NAME;
|
|
4314
4811
|
exports.AUDRIC_PARENT_NFT_ID = AUDRIC_PARENT_NFT_ID;
|
|
4315
4812
|
exports.CETUS_USDC_SUI_POOL = CETUS_USDC_SUI_POOL;
|
|
4316
4813
|
exports.CLOCK_ID = CLOCK_ID;
|
|
4814
|
+
exports.CommerceClient = CommerceClient;
|
|
4317
4815
|
exports.DEFAULT_ACTIVITY_REPORT_URL = DEFAULT_ACTIVITY_REPORT_URL;
|
|
4318
4816
|
exports.DEFAULT_API_BASE = DEFAULT_API_BASE;
|
|
4319
4817
|
exports.DEFAULT_COMMERCE_API_BASE = DEFAULT_COMMERCE_API_BASE;
|
|
@@ -4338,6 +4836,7 @@ exports.MAX_DELIVER_HORIZON_MS = MAX_DELIVER_HORIZON_MS;
|
|
|
4338
4836
|
exports.MAX_JOB_USDC = MAX_JOB_USDC;
|
|
4339
4837
|
exports.MAX_OPEN_WINDOW_MS = MAX_OPEN_WINDOW_MS;
|
|
4340
4838
|
exports.MAX_REVIEW_WINDOW_MS = MAX_REVIEW_WINDOW_MS;
|
|
4839
|
+
exports.MAX_TIER_BASE_LENGTH = MAX_TIER_BASE_LENGTH;
|
|
4341
4840
|
exports.MIN_JOB_USDC = MIN_JOB_USDC;
|
|
4342
4841
|
exports.MIST_PER_SUI = MIST_PER_SUI;
|
|
4343
4842
|
exports.OPENING_CLAIM_POLICIES = OPENING_CLAIM_POLICIES;
|
|
@@ -4351,6 +4850,8 @@ exports.PROVEN_MIN_REVIEWS = PROVEN_MIN_REVIEWS;
|
|
|
4351
4850
|
exports.REVIEW_MAX_STARS = REVIEW_MAX_STARS;
|
|
4352
4851
|
exports.REVIEW_MIN_STARS = REVIEW_MIN_STARS;
|
|
4353
4852
|
exports.SENDABLE_ASSETS = SENDABLE_ASSETS;
|
|
4853
|
+
exports.SERVICE_SLUG_RE = SERVICE_SLUG_RE;
|
|
4854
|
+
exports.SERVICE_TIERS = SERVICE_TIERS;
|
|
4354
4855
|
exports.SPONSORED_PYTH_DEPENDENT_PROVIDERS = SPONSORED_PYTH_DEPENDENT_PROVIDERS;
|
|
4355
4856
|
exports.STABLE_ASSETS = STABLE_ASSETS;
|
|
4356
4857
|
exports.SUINS_NAME_REGEX = SUINS_NAME_REGEX;
|
|
@@ -4367,6 +4868,7 @@ exports.WRITE_APPENDER_REGISTRY = WRITE_APPENDER_REGISTRY;
|
|
|
4367
4868
|
exports.ZkLoginSigner = ZkLoginSigner;
|
|
4368
4869
|
exports.addSendToTx = addSendToTx;
|
|
4369
4870
|
exports.addSwapToTx = addSwapToTx;
|
|
4871
|
+
exports.agentResolveUrl = agentResolveUrl;
|
|
4370
4872
|
exports.approxUsdValue = approxUsdValue;
|
|
4371
4873
|
exports.assertAllowedAsset = assertAllowedAsset;
|
|
4372
4874
|
exports.assertBuyerRequirements = assertBuyerRequirements;
|
|
@@ -4403,12 +4905,15 @@ exports.classifySendAsset = classifySendAsset;
|
|
|
4403
4905
|
exports.classifyTransaction = classifyTransaction;
|
|
4404
4906
|
exports.clearLimits = clearLimits;
|
|
4405
4907
|
exports.composeTx = composeTx;
|
|
4908
|
+
exports.createPackage = createPackage;
|
|
4406
4909
|
exports.customHireEnvelope = customHireEnvelope;
|
|
4407
4910
|
exports.dailySpentToday = dailySpentToday;
|
|
4408
4911
|
exports.deriveAgentScoreId = deriveAgentScoreId;
|
|
4409
4912
|
exports.deriveAllowedAddressesFromPtb = deriveAllowedAddressesFromPtb;
|
|
4410
4913
|
exports.deserializeCetusRoute = deserializeCetusRoute;
|
|
4411
4914
|
exports.displayHandle = displayHandle;
|
|
4915
|
+
exports.endpointIssueLines = endpointIssueLines;
|
|
4916
|
+
exports.ensureCategory = ensureCategory;
|
|
4412
4917
|
exports.executeTx = executeTx;
|
|
4413
4918
|
exports.exportPrivateKey = exportPrivateKey;
|
|
4414
4919
|
exports.extractAllUserLegs = extractAllUserLegs;
|
|
@@ -4417,6 +4922,7 @@ exports.extractTxCommands = extractTxCommands;
|
|
|
4417
4922
|
exports.extractTxSender = extractTxSender;
|
|
4418
4923
|
exports.fallbackLabel = fallbackLabel;
|
|
4419
4924
|
exports.fetchAllCoins = fetchAllCoins;
|
|
4925
|
+
exports.fetchChallengeNonce = fetchChallengeNonce;
|
|
4420
4926
|
exports.fetchService = fetchService;
|
|
4421
4927
|
exports.findSwapRoute = findSwapRoute;
|
|
4422
4928
|
exports.formatAssetAmount = formatAssetAmount;
|
|
@@ -4425,6 +4931,7 @@ exports.formatUsd = formatUsd;
|
|
|
4425
4931
|
exports.fullHandle = fullHandle;
|
|
4426
4932
|
exports.generateKeypair = generateKeypair;
|
|
4427
4933
|
exports.getAddress = getAddress;
|
|
4934
|
+
exports.getAgentProfile = getAgentProfile;
|
|
4428
4935
|
exports.getAgentScore = getAgentScore;
|
|
4429
4936
|
exports.getCoinMeta = getCoinMeta;
|
|
4430
4937
|
exports.getDecimals = getDecimals;
|
|
@@ -4446,6 +4953,7 @@ exports.isCustomHireEnvelope = isCustomHireEnvelope;
|
|
|
4446
4953
|
exports.isInRegistry = isInRegistry;
|
|
4447
4954
|
exports.jobActionsFor = jobActionsFor;
|
|
4448
4955
|
exports.keypairFromPrivateKey = keypairFromPrivateKey;
|
|
4956
|
+
exports.listEndpoint = listEndpoint;
|
|
4449
4957
|
exports.listModels = listModels;
|
|
4450
4958
|
exports.listOpenJobs = listOpenJobs;
|
|
4451
4959
|
exports.listServices = listServices;
|
|
@@ -4458,8 +4966,13 @@ exports.mistToSui = mistToSui;
|
|
|
4458
4966
|
exports.normalizeAddressInput = normalizeAddressInput;
|
|
4459
4967
|
exports.normalizeAsset = normalizeAsset;
|
|
4460
4968
|
exports.normalizeCoinType = normalizeCoinType;
|
|
4969
|
+
exports.packageBaseSlug = packageBaseSlug;
|
|
4970
|
+
exports.packageTierSlugs = packageTierSlugs;
|
|
4971
|
+
exports.parseAgentCategory = parseAgentCategory;
|
|
4972
|
+
exports.parseServiceTierSlug = parseServiceTierSlug;
|
|
4461
4973
|
exports.parseSuiRpcTx = parseSuiRpcTx;
|
|
4462
4974
|
exports.payWithX402 = payWithX402;
|
|
4975
|
+
exports.planPackage = planPackage;
|
|
4463
4976
|
exports.postOpenJob = postOpenJob;
|
|
4464
4977
|
exports.preflightCreateJob = preflightCreateJob;
|
|
4465
4978
|
exports.preflightCreateOpening = preflightCreateOpening;
|
|
@@ -4468,6 +4981,7 @@ exports.preflightPay = preflightPay;
|
|
|
4468
4981
|
exports.preflightSend = preflightSend;
|
|
4469
4982
|
exports.preflightSwap = preflightSwap;
|
|
4470
4983
|
exports.probeX402 = probeX402;
|
|
4984
|
+
exports.profileChallengeMessage = profileChallengeMessage;
|
|
4471
4985
|
exports.putJobSpec = putJobSpec;
|
|
4472
4986
|
exports.queryBalance = queryBalance;
|
|
4473
4987
|
exports.queryHistory = queryHistory;
|
|
@@ -4478,25 +4992,37 @@ exports.readLimitsFile = readLimitsFile;
|
|
|
4478
4992
|
exports.recordDailySpend = recordDailySpend;
|
|
4479
4993
|
exports.refineLendingLabel = refineLendingLabel;
|
|
4480
4994
|
exports.refundOpenJob = refundOpenJob;
|
|
4995
|
+
exports.registerAgent = registerAgent;
|
|
4996
|
+
exports.removeEndpoint = removeEndpoint;
|
|
4481
4997
|
exports.reportX402Activity = reportX402Activity;
|
|
4482
4998
|
exports.resolveAddressToSuinsViaRpc = resolveAddressToSuinsViaRpc;
|
|
4999
|
+
exports.resolveAgentRef = resolveAgentRef;
|
|
4483
5000
|
exports.resolveCreatedObjectId = resolveCreatedObjectId;
|
|
4484
5001
|
exports.resolveSuinsViaRpc = resolveSuinsViaRpc;
|
|
4485
5002
|
exports.resolveSymbol = resolveSymbol;
|
|
4486
5003
|
exports.resolveTokenType = resolveTokenType;
|
|
5004
|
+
exports.retireService = retireService;
|
|
4487
5005
|
exports.saveBech32 = saveBech32;
|
|
4488
5006
|
exports.saveKey = saveKey;
|
|
4489
5007
|
exports.selectAndSplitCoin = selectAndSplitCoin;
|
|
4490
5008
|
exports.selectSuiCoin = selectSuiCoin;
|
|
4491
5009
|
exports.serializeCetusRoute = serializeCetusRoute;
|
|
5010
|
+
exports.serviceChallengeMessage = serviceChallengeMessage;
|
|
5011
|
+
exports.servicePayloadSha256 = servicePayloadSha256;
|
|
5012
|
+
exports.serviceUpsertPayload = serviceUpsertPayload;
|
|
4492
5013
|
exports.setLimits = setLimits;
|
|
4493
5014
|
exports.setSponsoredTxGuard = setSponsoredTxGuard;
|
|
5015
|
+
exports.signChallenge = signChallenge;
|
|
4494
5016
|
exports.simulateTransaction = simulateTransaction;
|
|
5017
|
+
exports.slugify = slugify;
|
|
4495
5018
|
exports.stableToRaw = stableToRaw;
|
|
4496
5019
|
exports.submitJobReview = submitJobReview;
|
|
4497
5020
|
exports.suiToMist = suiToMist;
|
|
4498
5021
|
exports.throwIfSimulationFailed = throwIfSimulationFailed;
|
|
5022
|
+
exports.trimDashes = trimDashes;
|
|
4499
5023
|
exports.truncateAddress = truncateAddress;
|
|
5024
|
+
exports.updateProfile = updateProfile;
|
|
5025
|
+
exports.upsertService = upsertService;
|
|
4500
5026
|
exports.usdcToRaw = usdcToRaw;
|
|
4501
5027
|
exports.validateAddress = validateAddress;
|
|
4502
5028
|
exports.validateLabel = validateLabel;
|