mtok-relay 0.1.3 → 0.1.5
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/dist/mtok-relay.mjs +32 -8
- package/package.json +1 -1
package/dist/mtok-relay.mjs
CHANGED
|
@@ -2157,7 +2157,7 @@ var secp256k1 = createCurve({
|
|
|
2157
2157
|
}, sha256);
|
|
2158
2158
|
|
|
2159
2159
|
// node_modules/viem/_esm/errors/version.js
|
|
2160
|
-
var version = "2.54.
|
|
2160
|
+
var version = "2.54.6";
|
|
2161
2161
|
|
|
2162
2162
|
// node_modules/viem/_esm/errors/base.js
|
|
2163
2163
|
var errorConfig = {
|
|
@@ -4645,6 +4645,7 @@ function readRelayConfig({ argv = process.argv.slice(2), env = process.env } = {
|
|
|
4645
4645
|
const port = Number(flag(argv, "--port") ?? 8788);
|
|
4646
4646
|
const rpcFlag = flag(argv, "--rpc");
|
|
4647
4647
|
const settlementPubkeyFlag = flag(argv, "--settlement-pubkey");
|
|
4648
|
+
const sellerAgentId = flag(argv, "--seller-agent");
|
|
4648
4649
|
const outPrice = Number(flag(argv, "--out-price") ?? 0);
|
|
4649
4650
|
const inPrice = Number(flag(argv, "--in-price") ?? outPrice);
|
|
4650
4651
|
const redemptionFile = flag(argv, "--redemption-file") ?? env.RELAY_REDEMPTION_FILE ?? null;
|
|
@@ -4671,6 +4672,7 @@ function readRelayConfig({ argv = process.argv.slice(2), env = process.env } = {
|
|
|
4671
4672
|
return {
|
|
4672
4673
|
offerId,
|
|
4673
4674
|
model,
|
|
4675
|
+
sellerAgentId,
|
|
4674
4676
|
upstream,
|
|
4675
4677
|
apiBase,
|
|
4676
4678
|
port,
|
|
@@ -5068,6 +5070,30 @@ function createOnchainVerifier({
|
|
|
5068
5070
|
};
|
|
5069
5071
|
}
|
|
5070
5072
|
|
|
5073
|
+
// bridge/bridge.mjs
|
|
5074
|
+
function httpUpstream({ baseUrl, key }) {
|
|
5075
|
+
const url = String(baseUrl || "").replace(/\/$/, "") + "/chat/completions";
|
|
5076
|
+
return async (payload) => {
|
|
5077
|
+
const res = await fetch(url, {
|
|
5078
|
+
method: "POST",
|
|
5079
|
+
headers: {
|
|
5080
|
+
"content-type": "application/json",
|
|
5081
|
+
...key ? { authorization: `Bearer ${key}` } : {}
|
|
5082
|
+
},
|
|
5083
|
+
body: JSON.stringify(payload)
|
|
5084
|
+
});
|
|
5085
|
+
const text = await res.text();
|
|
5086
|
+
let json;
|
|
5087
|
+
try {
|
|
5088
|
+
json = JSON.parse(text);
|
|
5089
|
+
} catch {
|
|
5090
|
+
throw new Error(`non-JSON upstream response (${res.status})`);
|
|
5091
|
+
}
|
|
5092
|
+
if (!res.ok) throw new Error(json?.error?.message || `upstream ${res.status}`);
|
|
5093
|
+
return json;
|
|
5094
|
+
};
|
|
5095
|
+
}
|
|
5096
|
+
|
|
5071
5097
|
// src/rpc.mjs
|
|
5072
5098
|
var BASE_MAINNET_RPCS = [
|
|
5073
5099
|
"https://mainnet.base.org",
|
|
@@ -5089,10 +5115,11 @@ async function createRelayRuntime(config) {
|
|
|
5089
5115
|
const served = createRedemptionStore({ file: config.redemptionFile });
|
|
5090
5116
|
const drawLocks = /* @__PURE__ */ new Map();
|
|
5091
5117
|
const platform = await fetchPlatformConfig(config);
|
|
5092
|
-
const verifier = createOnchainVerifier({ rpcUrls: rpcUrlsFor(platform.chainId, config.rpcFlag), usdcAddress: platform.usdcAddress });
|
|
5118
|
+
const verifier = createOnchainVerifier({ rpcUrls: rpcUrlsFor(platform.chainId, config.rpcFlag), usdcAddress: platform.usdcAddress, expectedChainId: platform.chainId });
|
|
5093
5119
|
if (!verifier.configured) throw new Error("onchain verifier not configured (missing usdcAddress in /api/config)");
|
|
5094
5120
|
const payerDenylist = new Set((config.payerDenylist ?? []).map((a) => String(a).trim().toLowerCase()).filter(Boolean));
|
|
5095
5121
|
const screenPayer = typeof config.screenPayer === "function" ? config.screenPayer : null;
|
|
5122
|
+
const upstream = httpUpstream({ baseUrl: config.upstream + "/v1", key: config.upstreamKey });
|
|
5096
5123
|
const payerDenied = async (payer) => {
|
|
5097
5124
|
if (!payer) return false;
|
|
5098
5125
|
if (payerDenylist.has(payer)) return true;
|
|
@@ -5134,6 +5161,8 @@ async function createRelayRuntime(config) {
|
|
|
5134
5161
|
paid = await verifier.verifyDrawPaid(drawPaidTxHash, {
|
|
5135
5162
|
contractAddress: platform.dripContractAddress,
|
|
5136
5163
|
buyerAgentId: buyerId,
|
|
5164
|
+
sellerAgentId: config.sellerAgentId,
|
|
5165
|
+
// when set, enforces the offer-owner match (#codex review)
|
|
5137
5166
|
bookingId,
|
|
5138
5167
|
offerId: config.offerId,
|
|
5139
5168
|
model: config.model,
|
|
@@ -5175,12 +5204,7 @@ async function createRelayRuntime(config) {
|
|
|
5175
5204
|
const safeRequest = { ...request, max_tokens: bound.maxTok };
|
|
5176
5205
|
let completion;
|
|
5177
5206
|
try {
|
|
5178
|
-
|
|
5179
|
-
method: "POST",
|
|
5180
|
-
headers: { "content-type": "application/json", authorization: "Bearer " + config.upstreamKey },
|
|
5181
|
-
body: JSON.stringify(safeRequest)
|
|
5182
|
-
});
|
|
5183
|
-
completion = await upstreamRes.json();
|
|
5207
|
+
completion = await upstream(safeRequest);
|
|
5184
5208
|
} catch (e) {
|
|
5185
5209
|
return send(res, 502, { error: "upstream_error", detail: e.message });
|
|
5186
5210
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mtok-relay",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Reference seller relay for mtok.market — accepts on-chain-prepaid chunk draws and serves inference from an upstream you control. Run with: npx mtok-relay --offer <id> --model <id> --upstream <url>.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|