m2m-market 2.1.0 → 2.2.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 +15 -0
- package/adapters.js +5 -5
- package/index.d.ts +4 -1
- package/index.js +19 -1
- package/package.json +1 -1
- package/protocols.js +1 -1
package/README.md
CHANGED
|
@@ -52,6 +52,21 @@ const result = await client.executeTask({
|
|
|
52
52
|
console.log(result.response);
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
+
## Ask in plain language
|
|
56
|
+
|
|
57
|
+
```js
|
|
58
|
+
const result = await client.ask("I need weather for Nairobi today");
|
|
59
|
+
console.log(result.response);
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
M2M works out the capability, reads the inputs from the text (here a location
|
|
63
|
+
and a date), maps them onto each Provider's own field names, picks a validated
|
|
64
|
+
Provider and applies the dashboard spending policy. No payload or policy is
|
|
65
|
+
needed. If a required input is missing from the text, the request fails with
|
|
66
|
+
`intent_input_missing` before anything is reserved; add it to the text or pass
|
|
67
|
+
`payload`. `client.discover({ intent })` previews what would be sent
|
|
68
|
+
(`resolved.input` and each candidate's `provider_input`) without spending.
|
|
69
|
+
|
|
55
70
|
## Ask for an outcome
|
|
56
71
|
|
|
57
72
|
```js
|
package/adapters.js
CHANGED
|
@@ -19,7 +19,7 @@ export function openAIToolDefinition() {
|
|
|
19
19
|
},
|
|
20
20
|
intent: {
|
|
21
21
|
type: "string",
|
|
22
|
-
description: "Plain-language outcome needed, such as '
|
|
22
|
+
description: "Plain-language outcome needed, such as 'I need weather for Nairobi today'. M2M reads the inputs from it.",
|
|
23
23
|
},
|
|
24
24
|
required_capabilities: {
|
|
25
25
|
type: "array",
|
|
@@ -39,7 +39,7 @@ export function openAIToolDefinition() {
|
|
|
39
39
|
},
|
|
40
40
|
payload: {
|
|
41
41
|
type: "object",
|
|
42
|
-
description: "JSON input
|
|
42
|
+
description: "Optional JSON input. Omit it to let M2M read the inputs from the intent.",
|
|
43
43
|
additionalProperties: true,
|
|
44
44
|
},
|
|
45
45
|
maximum_price_m2m: {
|
|
@@ -53,7 +53,7 @@ export function openAIToolDefinition() {
|
|
|
53
53
|
description: "Optional stricter minimum Provider reputation.",
|
|
54
54
|
},
|
|
55
55
|
},
|
|
56
|
-
required: ["
|
|
56
|
+
required: ["intent"],
|
|
57
57
|
additionalProperties: false,
|
|
58
58
|
},
|
|
59
59
|
},
|
|
@@ -134,8 +134,8 @@ export class M2MToolAdapter {
|
|
|
134
134
|
description: M2M_TOOL_DESCRIPTION,
|
|
135
135
|
schema: z.object({
|
|
136
136
|
category: z.string().min(1).optional(),
|
|
137
|
-
intent: z.string().min(1)
|
|
138
|
-
payload: z.object({}).catchall(z.unknown()),
|
|
137
|
+
intent: z.string().min(1),
|
|
138
|
+
payload: z.object({}).catchall(z.unknown()).optional(),
|
|
139
139
|
required_capabilities: z.array(z.string()).optional(),
|
|
140
140
|
expect: z.array(z.string()).optional(),
|
|
141
141
|
maximum_attempts: z.number().int().min(1).max(5).optional(),
|
package/index.d.ts
CHANGED
|
@@ -27,7 +27,8 @@ export interface SubmitOptions {
|
|
|
27
27
|
/** Provide category, intent, or both. */
|
|
28
28
|
category?: string;
|
|
29
29
|
intent?: string;
|
|
30
|
-
|
|
30
|
+
/** Optional when an intent is given: M2M reads the inputs from the text. */
|
|
31
|
+
payload?: JsonObject;
|
|
31
32
|
requiredCapabilities?: string[];
|
|
32
33
|
integrationTypes?: string[];
|
|
33
34
|
/** Output fields the result must contain. */
|
|
@@ -80,6 +81,8 @@ export class M2MConnectionClient {
|
|
|
80
81
|
purchase(options: ExecuteTaskOptions): Promise<JsonObject>;
|
|
81
82
|
/** @deprecated Use purchase. */
|
|
82
83
|
executeTask(options: ExecuteTaskOptions): Promise<JsonObject>;
|
|
84
|
+
/** Buy an outcome from a plain-language request, e.g. "I need weather for Nairobi today". */
|
|
85
|
+
ask(intent: string, options?: Omit<ExecuteTaskOptions, "intent">): Promise<JsonObject>;
|
|
83
86
|
}
|
|
84
87
|
|
|
85
88
|
export * from "./procurement.js";
|
package/index.js
CHANGED
|
@@ -107,7 +107,15 @@ export class M2MConnectionClient {
|
|
|
107
107
|
if (!String(category || "").trim() && !String(intent || "").trim()) {
|
|
108
108
|
throw new TypeError("A service category or an intent is required");
|
|
109
109
|
}
|
|
110
|
-
|
|
110
|
+
// Payload is optional with an intent: M2M reads standard inputs from the
|
|
111
|
+
// text and maps them onto each Provider's own field names.
|
|
112
|
+
if (payload === undefined || payload === null) {
|
|
113
|
+
if (!String(intent || "").trim()) {
|
|
114
|
+
throw new TypeError("A payload is required when no intent is given");
|
|
115
|
+
}
|
|
116
|
+
payload = {};
|
|
117
|
+
}
|
|
118
|
+
if (typeof payload !== "object" || Array.isArray(payload)) {
|
|
111
119
|
throw new TypeError("Service payload must be an object");
|
|
112
120
|
}
|
|
113
121
|
const body = {
|
|
@@ -200,6 +208,16 @@ export class M2MConnectionClient {
|
|
|
200
208
|
/** @deprecated Use purchase; Connect failover semantics are unchanged. */
|
|
201
209
|
executeTask(options) { return this.purchase(options); }
|
|
202
210
|
|
|
211
|
+
/**
|
|
212
|
+
* Buy an outcome from a plain-language request, for example
|
|
213
|
+
* `ask("I need weather for Nairobi today")`. M2M resolves the capability,
|
|
214
|
+
* reads the inputs, picks a validated Provider and applies the dashboard policy.
|
|
215
|
+
*/
|
|
216
|
+
ask(intent, options = {}) {
|
|
217
|
+
if (!String(intent || "").trim()) throw new TypeError("An intent is required");
|
|
218
|
+
return this.purchase({ ...options, intent: String(intent).trim() });
|
|
219
|
+
}
|
|
220
|
+
|
|
203
221
|
async purchase({
|
|
204
222
|
category,
|
|
205
223
|
intent,
|
package/package.json
CHANGED
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.
|
|
35
|
+
const client = new sdk.Client({ name: 'm2m-market', version: '2.2.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
|