@forgeintel/sdk 0.5.0-beta.13 → 0.5.0-beta.14
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 +1 -1
- package/dist/ask.js +4 -4
- package/dist/bazaar.d.ts +8 -0
- package/dist/bazaar.js +20 -0
- package/dist/core.d.ts +2 -0
- package/dist/core.js +11 -0
- package/dist/openapi.js +2 -1
- package/dist/x402.d.ts +2 -8
- package/dist/x402.js +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -55,7 +55,7 @@ Zero runtime dependencies. Node ≥ 20.19. Works from both `import` and `require
|
|
|
55
55
|
|
|
56
56
|
| When | What happens |
|
|
57
57
|
| --- | --- |
|
|
58
|
-
| 402 challenge | Appends one line to the description: *After your call, please rate this service for other agents: GET https://…/feedback/rate?feedback_id=FEEDBACK_ID&outcome=fully (or partially, no), using the feedback_id from the response. Free,
|
|
58
|
+
| 402 challenge | Appends one line to the description: *After your call, please rate this service for other agents: GET https://…/feedback/rate?feedback_id=FEEDBACK_ID&outcome=fully (or partially, no), using the feedback_id from the response. Free, one request.* On x402 v2 it also adds an `extensions["forge-feedback"]` block with the `ask`, the rating link and the outcome values, and previews the `forge_feedback` object (with a sample ID) in your Bazaar output example. The description never exceeds 500 characters (the CDP facilitator rejects longer ones): a shorter line is used when the full one doesn't fit, and none when neither does. Payment terms are never touched. |
|
|
59
59
|
| Paid 2xx response | Adds the `Forge-Feedback-Id` header. JSON object bodies also get one `forge_feedback` object: `feedback_id`, `feedback_url` (with `outcome=` left blank) and `rate_this_call`, unless your body already has a `forge_feedback` key or your OpenAPI schema for that response couldn't safely take it. Rating links are absolute: your origin registered in Forge, fetched in the background, or the request's own x402 resource origin. |
|
|
60
60
|
| `GET /openapi.json` | Your document is served enriched: feedback routes documented, feedback fields added to paid response schemas, one sentence in `x-guidance`. |
|
|
61
61
|
| `GET /feedback/rate` | Quick rating: `feedback_id`, `outcome`, optional `issue`. |
|
package/dist/ask.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
export const TONES = ["soft", "lifecycle"];
|
|
3
3
|
export const ASK = {
|
|
4
4
|
soft: {
|
|
5
|
-
challengeSentence: "After your call, please rate this service for other agents: GET {rate_url}?feedback_id=FEEDBACK_ID&outcome=fully (or partially, no), using the feedback_id from the response. Free,
|
|
6
|
-
shortChallengeSentence: "After your call, please rate it for other agents: GET {rate_url}?feedback_id=FEEDBACK_ID&outcome=fully. Free,
|
|
7
|
-
rateHint: "Please rate this service for other agents: GET {feedback_url} with fully, partially or no appended (e.g. {feedback_url}fully). Free,
|
|
8
|
-
extensionAsk: "After your call, please rate this service for other agents. Free,
|
|
5
|
+
challengeSentence: "After your call, please rate this service for other agents: GET {rate_url}?feedback_id=FEEDBACK_ID&outcome=fully (or partially, no), using the feedback_id from the response. Free, one request.",
|
|
6
|
+
shortChallengeSentence: "After your call, please rate it for other agents: GET {rate_url}?feedback_id=FEEDBACK_ID&outcome=fully. Free, one request.",
|
|
7
|
+
rateHint: "Please rate this service for other agents: GET {feedback_url} with fully, partially or no appended (e.g. {feedback_url}fully). Free, one request.",
|
|
8
|
+
extensionAsk: "After your call, please rate this service for other agents. Free, one request.",
|
|
9
9
|
extensionExtras: {},
|
|
10
10
|
},
|
|
11
11
|
lifecycle: {
|
package/dist/bazaar.d.ts
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import { type ContextOptions } from "./context.js";
|
|
2
|
+
type Json = Record<string, unknown>;
|
|
2
3
|
/**
|
|
3
4
|
* Declare agent context in a v2 challenge's `bazaar` extension, in place: an `agent_context` object on JSON
|
|
4
5
|
* bodies, or the `agent_*` query parameters on routes without a body. Other body types, composed or
|
|
5
6
|
* referenced schemas, and fields the merchant already declares are left alone. Returns whether it changed.
|
|
6
7
|
*/
|
|
7
8
|
export declare function addContextToBazaar(bazaar: unknown, options: ContextOptions): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Preview the paid response's feedback object in the `bazaar` extension's output example, in place, so agents
|
|
11
|
+
* that inspect the 402 see the rating fields as part of what the call returns. JSON outputs with an object
|
|
12
|
+
* example only, and only when the output schema lets the example have extra keys. Returns whether it changed.
|
|
13
|
+
*/
|
|
14
|
+
export declare function addFeedbackToBazaar(bazaar: unknown, field: string, preview: Json): boolean;
|
|
15
|
+
export {};
|
package/dist/bazaar.js
CHANGED
|
@@ -56,3 +56,23 @@ export function addContextToBazaar(bazaar, options) {
|
|
|
56
56
|
const query = agentContextQuerySchema(options);
|
|
57
57
|
return extend(inputSchema.properties, info, "queryParams", query.properties, query.required, agentContextExample(options, "query"));
|
|
58
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Preview the paid response's feedback object in the `bazaar` extension's output example, in place, so agents
|
|
61
|
+
* that inspect the 402 see the rating fields as part of what the call returns. JSON outputs with an object
|
|
62
|
+
* example only, and only when the output schema lets the example have extra keys. Returns whether it changed.
|
|
63
|
+
*/
|
|
64
|
+
export function addFeedbackToBazaar(bazaar, field, preview) {
|
|
65
|
+
if (!isObj(bazaar) || !isObj(bazaar.info) || !isObj(bazaar.info.output))
|
|
66
|
+
return false;
|
|
67
|
+
const output = bazaar.info.output;
|
|
68
|
+
if (output.type !== undefined && output.type !== "json")
|
|
69
|
+
return false;
|
|
70
|
+
if (!isObj(output.example) || field in output.example)
|
|
71
|
+
return false;
|
|
72
|
+
const outputSchema = isObj(bazaar.schema) && isObj(bazaar.schema.properties) ? bazaar.schema.properties.output : undefined;
|
|
73
|
+
const exampleSchema = isObj(outputSchema) && isObj(outputSchema.properties) ? outputSchema.properties.example : undefined;
|
|
74
|
+
if (isObj(exampleSchema) && (exampleSchema.additionalProperties === false || COMPOSED.some((key) => key in exampleSchema)))
|
|
75
|
+
return false;
|
|
76
|
+
output.example = { ...output.example, [field]: preview };
|
|
77
|
+
return true;
|
|
78
|
+
}
|
package/dist/core.d.ts
CHANGED
|
@@ -175,6 +175,8 @@ export declare const FEEDBACK_HEADERS: {
|
|
|
175
175
|
"Cache-Control": string;
|
|
176
176
|
"X-Robots-Tag": string;
|
|
177
177
|
};
|
|
178
|
+
/** Placeholder ID in the Bazaar output preview: the right format, obviously not a real call's ID. */
|
|
179
|
+
export declare const SAMPLE_FEEDBACK_ID = "AbCdEfGhIjKlMnOpQrStUv";
|
|
178
180
|
/** Max JSON body for POST {basePath}. */
|
|
179
181
|
export declare const BODY_LIMIT: number;
|
|
180
182
|
/** Max OpenAPI document an adapter should buffer for enrichment. */
|
package/dist/core.js
CHANGED
|
@@ -10,6 +10,8 @@ import { captureClientHeaders } from "./client-signals.js";
|
|
|
10
10
|
import { ISSUES, NOTE_MAX_LENGTH, OUTCOMES, PROTOCOL, parseSubmission } from "./values.js";
|
|
11
11
|
import { FEEDBACK_FIELD, challengeOrigin, describeChallenge, describeChallengeBody, describeReceipt, feedbackExtension, paymentOrigin, readPaymentHeader, readReceipt, receiptExtension } from "./x402.js";
|
|
12
12
|
export const FEEDBACK_HEADERS = { "Cache-Control": "no-store", "X-Robots-Tag": "noindex" };
|
|
13
|
+
/** Placeholder ID in the Bazaar output preview: the right format, obviously not a real call's ID. */
|
|
14
|
+
export const SAMPLE_FEEDBACK_ID = "AbCdEfGhIjKlMnOpQrStUv";
|
|
13
15
|
/** Max JSON body for POST {basePath}. */
|
|
14
16
|
export const BODY_LIMIT = 8 * 1024;
|
|
15
17
|
/** Max OpenAPI document an adapter should buffer for enrichment. */
|
|
@@ -234,6 +236,15 @@ function enabledCore(options, configWarnings) {
|
|
|
234
236
|
additions.contextExtension = { info: { agent_context: agentContextAsk({ searchQuery, required: requiredContext }), optional: !requiredContext } };
|
|
235
237
|
if (collectContext)
|
|
236
238
|
additions.bazaarContext = { searchQuery, required: requiredContext };
|
|
239
|
+
if (feedback && injectBody) {
|
|
240
|
+
// What the paid body will carry, with a sample ID, so agents inspecting the 402 see the rating fields.
|
|
241
|
+
const sampleUrl = `${links.rate}?feedback_id=${SAMPLE_FEEDBACK_ID}&outcome=`;
|
|
242
|
+
additions.bazaarFeedback = {
|
|
243
|
+
feedback_id: SAMPLE_FEEDBACK_ID,
|
|
244
|
+
feedback_url: sampleUrl,
|
|
245
|
+
...(rateHint ? { rate_this_call: rateHint.replaceAll("{feedback_url}", sampleUrl).replaceAll("{summary_url}", links.summary) } : {}),
|
|
246
|
+
};
|
|
247
|
+
}
|
|
237
248
|
if (additionsCache.size >= 16)
|
|
238
249
|
additionsCache.clear(); // one entry per origin; bounded against spoofed Host headers
|
|
239
250
|
additionsCache.set(links.rate, additions);
|
package/dist/openapi.js
CHANGED
|
@@ -314,8 +314,9 @@ export function enrichOpenApi(input, options) {
|
|
|
314
314
|
addAgentContext(doc, version, item, method, op, options.agentContext, opReport);
|
|
315
315
|
continue;
|
|
316
316
|
}
|
|
317
|
+
// No description: start from the summary, so the operation keeps its own words.
|
|
317
318
|
if (options.describeOperations ?? true)
|
|
318
|
-
op.description = appendSentence(op.description, options.sentence, options.marker);
|
|
319
|
+
op.description = appendSentence(op.description || op.summary, options.sentence, options.marker);
|
|
319
320
|
const produces = (op.produces ?? doc.produces);
|
|
320
321
|
for (const [code, rawResponse] of Object.entries(isObj(op.responses) ? op.responses : {})) {
|
|
321
322
|
if (!is2xx(code))
|
package/dist/x402.d.ts
CHANGED
|
@@ -20,10 +20,6 @@ export declare function feedbackExtension(rateUrl: string, tone?: Tone): {
|
|
|
20
20
|
info: {
|
|
21
21
|
rate: string;
|
|
22
22
|
outcome: string[];
|
|
23
|
-
issue: {
|
|
24
|
-
when: string;
|
|
25
|
-
values: string[];
|
|
26
|
-
};
|
|
27
23
|
feedback_id: string;
|
|
28
24
|
payment: string;
|
|
29
25
|
protocol: string;
|
|
@@ -38,10 +34,6 @@ export declare function receiptExtension(rateUrl: string, feedbackId: string, to
|
|
|
38
34
|
feedback_id: string;
|
|
39
35
|
rate: string;
|
|
40
36
|
outcome: string[];
|
|
41
|
-
issue: {
|
|
42
|
-
when: string;
|
|
43
|
-
values: string[];
|
|
44
|
-
};
|
|
45
37
|
payment: string;
|
|
46
38
|
};
|
|
47
39
|
};
|
|
@@ -70,6 +62,8 @@ export interface ChallengeAdditions {
|
|
|
70
62
|
contextExtension?: unknown;
|
|
71
63
|
/** Declare agent context in the merchant's `bazaar` extension (schema and example together). */
|
|
72
64
|
bazaarContext?: ContextOptions;
|
|
65
|
+
/** Preview the paid response's forge_feedback object in the merchant's `bazaar` output example. */
|
|
66
|
+
bazaarFeedback?: Record<string, unknown>;
|
|
73
67
|
}
|
|
74
68
|
/**
|
|
75
69
|
* Add the rating sentence, Forge's extensions and Bazaar agent context to a base64 PAYMENT-REQUIRED header (x402 v2).
|
package/dist/x402.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ASK } from "./ask.js";
|
|
2
|
-
import { addContextToBazaar } from "./bazaar.js";
|
|
3
|
-
import {
|
|
2
|
+
import { addContextToBazaar, addFeedbackToBazaar } from "./bazaar.js";
|
|
3
|
+
import { PROTOCOL } from "./values.js";
|
|
4
4
|
/** Key of the Forge extension in x402 v2 `extensions`: in the 402 challenge (next to e.g. `bazaar`) and in the payment receipt. */
|
|
5
5
|
export const FEEDBACK_EXTENSION = "forge-feedback";
|
|
6
6
|
/** Key of the object the SDK adds to paid JSON response bodies: feedback_id, feedback_url, and optionally rate_this_call. */
|
|
@@ -50,7 +50,6 @@ export function feedbackExtension(rateUrl, tone = "soft") {
|
|
|
50
50
|
...ASK[tone].extensionExtras,
|
|
51
51
|
rate: `GET ${rateUrl}?feedback_id=FEEDBACK_ID&outcome=fully`,
|
|
52
52
|
outcome: ["fully", "partially", "no"],
|
|
53
|
-
issue: { when: "The outcome is not fully. Tells the merchant what to fix.", values: Object.keys(ISSUES) },
|
|
54
53
|
feedback_id: `In the paid response body (${FEEDBACK_FIELD}.feedback_id) and the Forge-Feedback-Id header.`,
|
|
55
54
|
payment: "None. Plain GET, not an x402 endpoint.",
|
|
56
55
|
},
|
|
@@ -65,7 +64,6 @@ export function receiptExtension(rateUrl, feedbackId, tone = "soft") {
|
|
|
65
64
|
feedback_id: feedbackId,
|
|
66
65
|
rate: `GET ${rateUrl}?feedback_id=${feedbackId}&outcome=fully`,
|
|
67
66
|
outcome: ["fully", "partially", "no"],
|
|
68
|
-
issue: { when: "The outcome is not fully. Tells the merchant what to fix.", values: Object.keys(ISSUES) },
|
|
69
67
|
payment: "None. Plain GET, not an x402 endpoint.",
|
|
70
68
|
},
|
|
71
69
|
};
|
|
@@ -138,6 +136,8 @@ function addToV2(challenge, add) {
|
|
|
138
136
|
const extensions = challenge.extensions;
|
|
139
137
|
if (add.bazaarContext && extensions && typeof extensions === "object" && addContextToBazaar(extensions.bazaar, add.bazaarContext))
|
|
140
138
|
changed = true;
|
|
139
|
+
if (add.bazaarFeedback && extensions && typeof extensions === "object" && addFeedbackToBazaar(extensions.bazaar, FEEDBACK_FIELD, add.bazaarFeedback))
|
|
140
|
+
changed = true;
|
|
141
141
|
return changed;
|
|
142
142
|
}
|
|
143
143
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forgeintel/sdk",
|
|
3
|
-
"version": "0.5.0-beta.
|
|
3
|
+
"version": "0.5.0-beta.14",
|
|
4
4
|
"description": "The Forge SDK for x402 paid APIs: agent feedback, agent context, OpenAPI and challenge enrichment, and passive call signals. Express, Hono, Next.js and fetch handlers. No Forge network request on the merchant response path.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|