mtok-relay 0.1.4 → 0.1.6

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.
@@ -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.4";
2160
+ var version = "2.54.6";
2161
2161
 
2162
2162
  // node_modules/viem/_esm/errors/base.js
2163
2163
  var errorConfig = {
@@ -5070,6 +5070,30 @@ function createOnchainVerifier({
5070
5070
  };
5071
5071
  }
5072
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
+
5073
5097
  // src/rpc.mjs
5074
5098
  var BASE_MAINNET_RPCS = [
5075
5099
  "https://mainnet.base.org",
@@ -5091,10 +5115,11 @@ async function createRelayRuntime(config) {
5091
5115
  const served = createRedemptionStore({ file: config.redemptionFile });
5092
5116
  const drawLocks = /* @__PURE__ */ new Map();
5093
5117
  const platform = await fetchPlatformConfig(config);
5094
- 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 });
5095
5119
  if (!verifier.configured) throw new Error("onchain verifier not configured (missing usdcAddress in /api/config)");
5096
5120
  const payerDenylist = new Set((config.payerDenylist ?? []).map((a) => String(a).trim().toLowerCase()).filter(Boolean));
5097
5121
  const screenPayer = typeof config.screenPayer === "function" ? config.screenPayer : null;
5122
+ const upstream = httpUpstream({ baseUrl: config.upstream + "/v1", key: config.upstreamKey });
5098
5123
  const payerDenied = async (payer) => {
5099
5124
  if (!payer) return false;
5100
5125
  if (payerDenylist.has(payer)) return true;
@@ -5179,12 +5204,7 @@ async function createRelayRuntime(config) {
5179
5204
  const safeRequest = { ...request, max_tokens: bound.maxTok };
5180
5205
  let completion;
5181
5206
  try {
5182
- const upstreamRes = await fetch(config.upstream + "/v1/chat/completions", {
5183
- method: "POST",
5184
- headers: { "content-type": "application/json", authorization: "Bearer " + config.upstreamKey },
5185
- body: JSON.stringify(safeRequest)
5186
- });
5187
- completion = await upstreamRes.json();
5207
+ completion = await upstream(safeRequest);
5188
5208
  } catch (e) {
5189
5209
  return send(res, 502, { error: "upstream_error", detail: e.message });
5190
5210
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mtok-relay",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
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": {