m2m-market 2.5.0 → 2.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/README.md CHANGED
@@ -99,109 +99,71 @@ try {
99
99
  console.log(await M2MConnectionClient.fromEnvironment().testConnection());
100
100
  ```
101
101
 
102
- ## Buy an x402 resource
103
-
104
- M2M can buy resources listed in the x402 Bazaar for your Agent. M2M pays the
105
- seller in USDC on Base and charges your Agent's M2M balance, within the limits
106
- M2M sets for your account. Search matches whole words.
107
-
102
+ ## Buy an x402 service
103
+ `buyExternal` is the one method for buying from the x402 Bazaar. Describe what you
104
+ need and give the data to send. M2M finds a listing, matches your data to its
105
+ input schema by exact field name, and buys it. M2M pays the seller in USDC on
106
+ Base and charges your Agent's M2M balance, within the limits M2M sets for your
107
+ account. Nothing is invented: a field you do not supply is never filled in, and
108
+ no language model builds the request.
108
109
  ```js
109
- const found = await client.searchExternal("supported chains rpcs explorers", { limit: 10 });
110
- const listing = found.listings[0]; // candidate_id, name, price_usdc_base_units, resource_url
110
+ // Check first. Nothing is charged, journaled or signed.
111
+ const plan = await client.buyExternal("convert currencies", { amount: 100, from: "USD", to: "GBP" }, { dryRun: true });
112
+ console.log(plan.status, plan.purchase, plan.alternatives);
111
113
 
112
- const result = await client.purchaseExternal(listing.candidate_id);
113
- console.log(result.purchase.status, result.purchase.response);
114
+ // Then buy. maxPriceUsdc is optional and can only lower the ceiling.
115
+ const result = await client.buyExternal("convert currencies", { amount: 100, from: "USD", to: "GBP" }, { maxPriceUsdc: "0.01" });
116
+ console.log(result.status, result.purchase);
114
117
  ```
118
+ Your Agent token policy and the account limits always apply, whether or not you
119
+ set `maxPriceUsdc`. Search matches whole words.
115
120
 
116
- Keep `result.idempotency_key`. If the result is `pending`, call
117
- `purchaseExternal(candidateId, { idempotencyKey })` again with the same key
118
- to get the outcome. The same key is never paid twice. Reusing a key with a
119
- different method, body or query is refused with `idempotency_key_conflict` (409).
121
+ | `status` | Meaning |
122
+ |---|---|
123
+ | a purchase status (`completed`, `pending`, `paid_request_rejected`, ...) | A listing was bought. The result has `purchase`, `candidate_id`, `idempotency_key` and `attempts`. |
124
+ | `planned` | `dryRun` only. Nothing was charged. `alternatives` lists other listings with price and any missing fields. |
125
+ | `needs_input` | No listing could be built from your data. `candidates` (up to 3) each list `description`, `input_schema`, `missing` (such as `body.city`) and `invalid`. Nothing was charged. Add the fields and call again. |
126
+ | `no_match` | Nothing matched `need`. |
127
+ | `over_price_cap` | Every match costs more than `maxPriceUsdc`. |
120
128
 
121
- ### GET and POST listings
129
+ ### Giving the data
130
+ - **By field name:** `{ city: "Paris" }`. A value goes to the body or the query, whichever the listing's schema names. Names must match the schema exactly.
131
+ - **Whole body or query:** `inputs.body` and `inputs.query` are sent as given. Use them for listings with no schema.
132
+ - **GET or POST:** you never choose. M2M uses the method the listing declares.
122
133
 
123
- Each listing's `consumption` block has the `method` (GET or POST today) and an
124
- `input` summary: `body_type`, `body_required`, `has_body_schema`,
125
- `has_query_schema`, `schema_coverage`. M2M always uses the listing's method.
126
- `method` is optional and must match it.
134
+ Put sensitive values in the body, not the query. Query values are stored with the
135
+ purchase record; only a hash of the body is stored.
127
136
 
137
+ ### Choosing a listing
138
+ By default `buyExternal` buys the cheapest listing your data satisfies. To buy a
139
+ specific one, take its `candidate_id` from `alternatives` or `candidates` and pass
140
+ it with the same `need` and `inputs`:
128
141
  ```js
129
- // GET with query parameters
130
- await client.purchaseExternal(listing.candidate_id, { query: { chain: "base" } });
131
-
132
- // POST with a JSON body
133
- await client.purchaseExternal(listing.candidate_id, {
134
- body: { text: "hello", lang: "en" },
135
- });
142
+ await client.buyExternal("convert currencies", { amount: 100, from: "USD", to: "GBP" },
143
+ { candidateId: "m2m-federated-candidate-v1-..." });
136
144
  ```
137
-
138
- Put sensitive values in `body`, not `query`. Query values are stored with the
139
- purchase record; only a hash of the body is stored. Calls with no `method`,
140
- `body` or `query` send the same request as before.
141
-
142
- ### Refusals and rejected requests
143
-
144
- Input is checked against the listing's schema before anything is signed or
145
- charged. A refusal rejects the promise and nothing is charged. The reason code
146
- is in the error payload: `candidate_not_consumable`, `method_unknown`,
147
- `method_unsupported`, `method_mismatch`, `body_not_accepted`,
148
- `body_type_unsupported`, `input_required`, `input_invalid` (with a `fields` list
149
- of `path` and `code`), `input_too_large` (413) and `query_conflict`.
150
-
151
- If the seller refuses the paid request, `purchase.status` is
152
- `paid_request_rejected`, with `http_status`, `method` and
153
- `rejection: { http_status, reason }`. The reason is one of `bad_request`,
154
- `unauthorized`, `payment_required`, `forbidden`, `not_found`,
155
- `method_not_allowed`, `payload_too_large`, `unsupported_media_type`,
156
- `unprocessable_input`, `rate_limited`, `seller_error` or `other_non_2xx`. The
157
- request is not retried. The purchase stays pending
158
- (`charge_policy: "retained_pending_review"`) until M2M checks the payment on
159
- the chain. It is then released and the charge is returned, and the status
160
- becomes `reconciled_released`. If the payment did settle, the status becomes
161
- `reconciled_settled` and the charge stands. The same applies to
162
- `seller_error_refund_pending_review`.
163
-
164
- ## Describe what you need
165
- `buyExternal` does the search, the listing choice and the request building for
166
- you. Give a short `need` and the data to send. M2M finds a listing, matches your
167
- data to its input schema by exact field name, and buys it. Nothing is invented:
168
- a field you do not supply is never filled in.
145
+ With `candidateId` and a `null` need, the request is sent as given:
146
+ `{ body, query }` as inputs, and `idempotencyKey` is used as is.
147
+
148
+ ### Safety rules
149
+ - Another listing is tried only after a refusal that happened before any charge, at most 3 in all.
150
+ - After a charge, a `pending` result or `paid_request_rejected`, the call stops. A different seller is never tried.
151
+ - Each attempt uses its own key derived from your `idempotencyKey` and the listing, so repeating a call never pays twice.
152
+ - Input is checked against the listing's schema before anything is signed or charged. A refusal rejects the promise with the reason in `error.payload.code` (`input_required`, `input_invalid` with a `fields` list, `candidate_not_consumable`, `method_mismatch`, `input_too_large`, and others). Nothing is charged.
153
+
154
+ ### Pending and rejected purchases
155
+ If `status` is `pending`, collect the result with the request in `resume`. The same
156
+ key is never paid twice:
169
157
  ```js
170
- const result = await client.buyExternal(
171
- "weather forecast",
172
- { city: "Paris", units: "metric" }, // values by schema field name
173
- { maxPriceUsdc: "0.01" }, // optional, can only lower the ceiling
174
- );
175
- console.log(result.status, result.purchase);
158
+ const done = await client.buyExternal(null, result.resume.inputs, result.resume.options);
176
159
  ```
177
- Check first with `{ dryRun: true }`. It charges, journals and signs nothing and
178
- resolves with `status: "planned"` and the method, URL, listing price and body.
179
- `maxPriceUsdc` is optional. Your Agent token policy and the account limits
180
- always apply, whether or not you set it.
181
-
182
- | `status` | Meaning |
183
- |---|---|
184
- | a purchase status (`completed`, `pending`, `paid_request_rejected`, ...) | A listing was bought. The result has `purchase`, `candidate_id`, `idempotency_key` and `attempts`. |
185
- | `planned` | `dryRun` only. Nothing was charged. |
186
- | `needs_input` | No listing could be built from your data. `candidates` (up to 3) each list `input_schema`, `missing` (such as `body.city`) and `invalid`. Nothing was charged. Add the fields and call again. |
187
- | `no_match` | Nothing matched `need`. |
188
- | `over_price_cap` | Every match costs more than `maxPriceUsdc`. |
160
+ If the seller refuses the paid request, `purchase.status` is `paid_request_rejected`,
161
+ with `http_status`, `method` and `rejection: { http_status, reason }`. The request
162
+ is not retried. The purchase stays pending until M2M checks the payment on the
163
+ chain. It is then released and the charge returned (`reconciled_released`), or, if
164
+ the payment did settle, marked `reconciled_settled` and the charge stands.
189
165
 
190
- Use `inputs.body` or `inputs.query` to give a whole request body or query as is,
191
- for listings with no schema. Search now returns each listing's `body_schema` and
192
- `query_schema` in `listing.input` (left out with `schema_truncated: true` above
193
- 16 KB).
194
-
195
- Another listing is tried only after a refusal that happened before any charge,
196
- at most 3 in all. After a charge, a `pending` result or `paid_request_rejected`,
197
- the call stops and returns that result. A different seller is never tried. Each
198
- attempt uses its own key derived from your `idempotencyKey` and the listing, so
199
- repeating a call never pays twice. If the status is `pending`, collect it with
200
- `await client.purchaseExternal(result.resume.candidateId, result.resume.options)`.
201
-
202
- As a model tool, use `buyExternalToolDefinition()` and
203
- `createBuyExternalToolHandler(client)` from `m2m-market/adapters`; the tool is
204
- named `buy_external_service`.
166
+ `searchExternal` and `purchaseExternal` are deprecated. They still work and warn.
205
167
 
206
168
  ## OpenAI-compatible tool
207
169
 
package/adapters.d.ts CHANGED
@@ -41,6 +41,7 @@ export const M2M_BUY_EXTERNAL_TOOL_DESCRIPTION: string;
41
41
  export interface BuyExternalToolArguments {
42
42
  need: string;
43
43
  inputs?: JsonObject;
44
+ candidate_id?: string;
44
45
  max_price_usdc?: string;
45
46
  dry_run?: boolean;
46
47
  }
package/adapters.js CHANGED
@@ -174,6 +174,7 @@ export function buyExternalToolDefinition() {
174
174
  description: "Values to send, by field name, such as {\"city\": \"Paris\"}. Use 'body' or 'query' for a whole request body or query as is.",
175
175
  additionalProperties: true,
176
176
  },
177
+ candidate_id: { type: "string", description: "Optional. Buy this listing, taken from a needs_input or planned result, instead of the cheapest match." },
177
178
  max_price_usdc: { type: "string", description: "Optional price ceiling in USDC, such as '0.01'. Account limits always apply." },
178
179
  dry_run: { type: "boolean", description: "Check what would be bought without charging." },
179
180
  },
@@ -192,8 +193,8 @@ export class M2MExternalToolAdapter {
192
193
  this.client = client;
193
194
  }
194
195
 
195
- invoke({ need, inputs, max_price_usdc, dry_run = false }) {
196
- return this.client.buyExternal(need, inputs, { maxPriceUsdc: max_price_usdc, dryRun: dry_run === true });
196
+ invoke({ need, inputs, candidate_id, max_price_usdc, dry_run = false }) {
197
+ return this.client.buyExternal(need, inputs, { candidateId: candidate_id, maxPriceUsdc: max_price_usdc, dryRun: dry_run === true });
197
198
  }
198
199
 
199
200
  async invokeJson(argumentsValue) {
package/index.d.ts CHANGED
@@ -49,6 +49,8 @@ export interface ExecuteTaskOptions extends Omit<SubmitOptions, "attemptNumber"
49
49
  export type JsonValue = string | number | boolean | null | JsonValue[] | { [key: string]: JsonValue };
50
50
 
51
51
  export interface BuyExternalOptions {
52
+ /** Pin one listing. With a need, it is found by search and inputs are matched to its schema. Without a need, the request is sent as given and idempotencyKey is used as is. */
53
+ candidateId?: string;
52
54
  /** Optional price cap in USDC, for example "0.01". It can only lower the ceiling; Agent token policy and account limits always apply. */
53
55
  maxPriceUsdc?: string | number;
54
56
  /** Return the validated plan without charging. */
@@ -61,6 +63,7 @@ export interface BuyExternalOptions {
61
63
  export interface BuyExternalCandidate {
62
64
  candidate_id: string;
63
65
  name: string;
66
+ description?: string;
64
67
  price_usdc_base_units: string;
65
68
  method: string;
66
69
  input_schema: JsonObject;
@@ -76,8 +79,10 @@ export interface BuyExternalResult extends JsonObject {
76
79
  idempotency_key?: string;
77
80
  attempts?: Array<{ candidate_id: string; outcome: string }>;
78
81
  candidates?: BuyExternalCandidate[];
79
- /** Present when status is pending: purchaseExternal(resume.candidateId, resume.options) collects it. */
80
- resume?: { candidateId: string; options: PurchaseExternalOptions };
82
+ /** Dry run only: other listings with price and any missing fields. */
83
+ alternatives?: BuyExternalCandidate[];
84
+ /** Present when status is pending: buyExternal(null, resume.inputs, resume.options) collects it. */
85
+ resume?: { inputs: JsonObject; options: BuyExternalOptions };
81
86
  }
82
87
  export interface PurchaseExternalOptions {
83
88
  /** Return the plan without charging, journaling or signing. purchase.status is "planned". */
@@ -118,10 +123,12 @@ export class M2MConnectionClient {
118
123
  discover(options?: DiscoverOptions): Promise<JsonObject>;
119
124
  /** Buy one external x402 Bazaar resource for this Agent. Reuse idempotencyKey to fetch a pending result. */
120
125
  /** Find x402 Bazaar resources M2M can buy for this Agent (read-only). */
126
+ /** @deprecated Use buyExternal(need, inputs, { dryRun: true }). */
121
127
  searchExternal(intent: string, options?: { limit?: number; cursor?: string }): Promise<JsonObject>;
128
+ /** @deprecated Use buyExternal(null, { body, query }, { candidateId, idempotencyKey }). */
122
129
  purchaseExternal(candidateId: string, options?: PurchaseExternalOptions): Promise<JsonObject>;
123
- /** Describe what you need and give your data. M2M finds and buys a matching x402 service. */
124
- buyExternal(need: string, inputs?: JsonObject | null, options?: BuyExternalOptions): Promise<BuyExternalResult>;
130
+ /** Find and buy an x402 service. Describe what you need and give your data. This is the only method you need. */
131
+ buyExternal(need: string | null, inputs?: JsonObject | null, options?: BuyExternalOptions): Promise<BuyExternalResult>;
125
132
  /** Evidence only; does not change settlement, reputation or ranking. */
126
133
  submitAcceptance(queryId: string, options: { acceptanceId: string; accepted: boolean }): Promise<JsonObject>;
127
134
  getQueryStatus(queryId: string): Promise<JsonObject>;
package/index.js CHANGED
@@ -26,6 +26,28 @@ const PRE_CHARGE_REFUSALS = new Set([
26
26
  ]);
27
27
  const PRE_CHARGE_ATTEMPTS = 3;
28
28
 
29
+ const warned = new Set();
30
+ function deprecated(name, replacement) {
31
+ if (warned.has(name)) return;
32
+ warned.add(name);
33
+ process.emitWarning(`${name} is deprecated; use ${replacement}`, "DeprecationWarning");
34
+ }
35
+
36
+ // Shape a purchase reply: status, candidate, attempts and, when pending, a resume request.
37
+ function finishExternal(result, candidateId, key, options, attempts) {
38
+ const purchase = result.purchase && typeof result.purchase === "object" ? result.purchase : {};
39
+ const status = String(purchase.status || result.status || "");
40
+ attempts.push({ candidate_id: candidateId, outcome: status });
41
+ const out = { ...result, status, candidate_id: candidateId, attempts };
42
+ if (status === "pending") {
43
+ const values = {};
44
+ if (Object.prototype.hasOwnProperty.call(options, "body")) values.body = options.body;
45
+ if (options.query !== undefined) values.query = options.query;
46
+ out.resume = { inputs: values, options: { candidateId, idempotencyKey: key } };
47
+ }
48
+ return out;
49
+ }
50
+
29
51
  export class M2MConnectionClient {
30
52
  constructor({
31
53
  connectionToken,
@@ -186,7 +208,7 @@ export class M2MConnectionClient {
186
208
  * The same key is never paid twice.
187
209
  */
188
210
  /** Find x402 Bazaar resources M2M can buy for this Agent (read-only). Search matches whole words. */
189
- searchExternal(intent, { limit = 10, cursor } = {}) {
211
+ _searchExternal(intent, { limit = 10, cursor } = {}) {
190
212
  if (!String(intent || "").trim()) throw new Error("intent is required");
191
213
  const body = { intent: String(intent).trim(), limit };
192
214
  if (cursor) body.cursor = cursor;
@@ -199,7 +221,7 @@ export class M2MConnectionClient {
199
221
  * Put sensitive values in the body, not the query. The server validates all of them before anything is paid.
200
222
  * dryRun: true charges, journals and signs nothing; purchase.status is "planned" with the request the purchase would use.
201
223
  */
202
- async purchaseExternal(candidateId, { idempotencyKey, method, body, query, dryRun = false } = {}) {
224
+ async _purchaseExternal(candidateId, { idempotencyKey, method, body, query, dryRun = false } = {}) {
203
225
  const key = String(idempotencyKey || randomUUID());
204
226
  if (key.length < 8 || key.length > 128) throw new Error("idempotencyKey must be 8-128 characters");
205
227
  if (!String(candidateId || "").trim()) throw new Error("candidateId is required");
@@ -221,26 +243,46 @@ export class M2MConnectionClient {
221
243
  return { idempotency_key: key, ...result };
222
244
  }
223
245
 
246
+ /** @deprecated Use buyExternal(need, inputs, { dryRun: true }); it also lists alternatives. */
247
+ searchExternal(intent, options) {
248
+ deprecated("searchExternal", "buyExternal(need, inputs, { dryRun: true })");
249
+ return this._searchExternal(intent, options);
250
+ }
251
+
252
+ /** @deprecated Use buyExternal(null, { body, query }, { candidateId, idempotencyKey }). */
253
+ purchaseExternal(candidateId, options) {
254
+ deprecated("purchaseExternal", "buyExternal(null, { body, query }, { candidateId, idempotencyKey })");
255
+ return this._purchaseExternal(candidateId, options);
256
+ }
257
+
224
258
  /**
225
- * Describe what you need and give your data. M2M finds and buys a matching x402 service.
259
+ * Find and buy an x402 service. Describe what you need and give your data. This is the only method you need.
226
260
  *
227
- * Searches the x402 Bazaar for `need`, keeps listings M2M can buy (and, with maxPriceUsdc, priced at or
228
- * below it), maps `inputs` to each listing's schema by exact field name, and buys the best listing the
261
+ * With `need`, M2M searches the x402 Bazaar, keeps listings it can buy (and, with maxPriceUsdc, priced at or
262
+ * below it), maps `inputs` to each listing's schema by exact field name, and buys the cheapest listing the
229
263
  * inputs satisfy. maxPriceUsdc is optional and can only lower the ceiling: the Agent token policy and the
230
264
  * account limits always apply. Use inputs.body or inputs.query to give a whole body or query as is.
231
265
  *
232
- * Resolves with `status`: the purchase status (completed, pending, paid_request_rejected, ...) plus
233
- * purchase, candidate_id, idempotency_key, attempts and, for pending, `resume`; or planned (dryRun),
234
- * needs_input (up to 3 candidates with input_schema, missing, invalid), no_match, over_price_cap.
266
+ * `candidateId` pins one listing. With `need` as well, that listing is found by search and your inputs are
267
+ * matched to its schema. With `need` null, the request is sent as given (inputs.body, inputs.query) and
268
+ * `idempotencyKey` is used as is. That is also how a pending result is collected:
269
+ * client.buyExternal(null, r.resume.inputs, r.resume.options).
270
+ *
271
+ * dryRun charges, journals and signs nothing. The result has status "planned", the chosen listing's method,
272
+ * URL, price and request, and `alternatives`: other listings with price and any missing fields.
273
+ *
274
+ * Resolves with `status`: the purchase status (completed, pending, paid_request_rejected, ...) plus purchase,
275
+ * candidate_id, idempotency_key, attempts and, for pending, `resume`; or planned (dryRun), needs_input (up to 3
276
+ * candidates with description, input_schema, missing, invalid), no_match, over_price_cap.
235
277
  *
236
278
  * Another listing is tried only after a refusal that happened before any charge, at most 3 in all.
237
279
  * After a charge, a pending result or a rejected paid request it stops; a different seller is never tried.
238
- * Each attempt uses its own key derived from idempotencyKey and the listing. To collect a pending result:
239
- * client.purchaseExternal(r.resume.candidateId, r.resume.options).
280
+ * Each attempt uses its own key derived from idempotencyKey and the listing.
240
281
  */
241
- async buyExternal(need, inputs, { maxPriceUsdc, dryRun = false, idempotencyKey, limit = 25 } = {}) {
282
+ async buyExternal(need, inputs, { candidateId, maxPriceUsdc, dryRun = false, idempotencyKey, limit = 25 } = {}) {
242
283
  const text = String(need || "").trim();
243
- if (!text) throw new Error("need is required");
284
+ const pinned = String(candidateId || "").trim();
285
+ if (!text && !pinned) throw new Error("need or candidateId is required");
244
286
  if (inputs !== undefined && inputs !== null && (typeof inputs !== "object" || Array.isArray(inputs))) {
245
287
  throw new TypeError("inputs must be an object");
246
288
  }
@@ -248,8 +290,18 @@ export class M2MConnectionClient {
248
290
  const callKey = String(idempotencyKey || randomUUID());
249
291
  if (callKey.length < 8 || callKey.length > 128) throw new Error("idempotencyKey must be 8-128 characters");
250
292
 
251
- const found = await this.searchExternal(text, { limit });
252
- const listings = (Array.isArray(found.listings) ? found.listings : []).filter((item) => item && typeof item === "object");
293
+ if (pinned && !text) {
294
+ const values = inputs || {};
295
+ const options = { idempotencyKey: callKey, dryRun };
296
+ if (Object.prototype.hasOwnProperty.call(values, "body")) options.body = values.body;
297
+ if (values.query && typeof values.query === "object" && !Array.isArray(values.query)) options.query = values.query;
298
+ const result = await this._purchaseExternal(pinned, options);
299
+ return finishExternal(result, pinned, callKey, options, []);
300
+ }
301
+
302
+ const found = await this._searchExternal(text, { limit });
303
+ let listings = (Array.isArray(found.listings) ? found.listings : []).filter((item) => item && typeof item === "object");
304
+ if (pinned) listings = listings.filter((item) => item.candidate_id === pinned);
253
305
  const priced = [];
254
306
  listings.forEach((listing, position) => {
255
307
  let price;
@@ -279,6 +331,7 @@ export class M2MConnectionClient {
279
331
  return {
280
332
  candidate_id: listing.candidate_id,
281
333
  name: listing.name,
334
+ description: listing.description,
282
335
  price_usdc_base_units: listing.price_usdc_base_units,
283
336
  method: listing.method,
284
337
  input_schema: schema,
@@ -291,32 +344,28 @@ export class M2MConnectionClient {
291
344
  const refused = [];
292
345
  for (const entry of usable) {
293
346
  const { listing, built } = entry;
294
- const candidateId = String(listing.candidate_id);
295
- const key = createHash("sha256").update(`${callKey}:${candidateId}`).digest("hex");
347
+ const cid = String(listing.candidate_id);
348
+ const key = createHash("sha256").update(`${callKey}:${cid}`).digest("hex");
296
349
  const options = { idempotencyKey: key, dryRun };
297
350
  if (listing.method) options.method = String(listing.method);
298
351
  if (built.has_body) options.body = built.body;
299
352
  if (built.has_query) options.query = built.query;
300
353
  let result;
301
354
  try {
302
- result = await this.purchaseExternal(candidateId, options);
355
+ result = await this._purchaseExternal(cid, options);
303
356
  } catch (error) {
304
357
  const code = error instanceof M2MConnectionError ? String((error.payload || {}).code || "") : "";
305
358
  if (!PRE_CHARGE_REFUSALS.has(code)) {
306
- if (error && typeof error === "object") error.attempts = [...attempts, { candidate_id: candidateId, outcome: code || "error" }];
359
+ if (error && typeof error === "object") error.attempts = [...attempts, { candidate_id: cid, outcome: code || "error" }];
307
360
  throw error;
308
361
  }
309
- attempts.push({ candidate_id: candidateId, outcome: code });
362
+ attempts.push({ candidate_id: cid, outcome: code });
310
363
  refused.push(describe(entry, (error.payload || {}).fields || []));
311
364
  continue;
312
365
  }
313
- const purchase = result.purchase && typeof result.purchase === "object" ? result.purchase : {};
314
- const status = String(purchase.status || result.status || "");
315
- attempts.push({ candidate_id: candidateId, outcome: status });
316
- const out = { ...result, status, candidate_id: candidateId, attempts };
317
- if (status === "pending") {
318
- const { dryRun: _unused, ...resumeOptions } = options;
319
- out.resume = { candidateId, options: resumeOptions };
366
+ const out = finishExternal(result, cid, key, options, attempts);
367
+ if (dryRun) {
368
+ out.alternatives = ranked.filter((item) => item.listing.candidate_id !== cid).slice(0, 5).map((item) => describe(item));
320
369
  }
321
370
  return out;
322
371
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "m2m-market",
3
- "version": "2.5.0",
3
+ "version": "2.6.0",
4
4
  "description": "Customer SDK for connecting AI Agents to M2M Market",
5
5
  "author": "M2M Market, Inc.",
6
6
  "type": "module",
package/protocols.js CHANGED
@@ -32,7 +32,7 @@ export async function connectMcp({ accessToken, timeoutMs = 30000, fetchImpl = g
32
32
  const transport = new sdk.StreamableHTTPClientTransport(new URL(MCP_RESOURCE), {
33
33
  fetch: guardedFetch, reconnectionOptions: { maxRetries: 0, initialReconnectionDelay: 1000, maxReconnectionDelay: 1000, reconnectionDelayGrowFactor: 1 }
34
34
  });
35
- const client = new sdk.Client({ name: 'm2m-market', version: '2.5.0' });
35
+ const client = new sdk.Client({ name: 'm2m-market', version: '2.6.0' });
36
36
  try { await client.connect(transport); }
37
37
  catch { await client.close().catch(() => {}); throw new M2MAPIError('mcp_connection_failed'); }
38
38
  return client; // caller closes it in finally; no automatic paid call or replay