@forgeintel/sdk 0.5.0-beta.6 → 0.5.0-beta.8

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
@@ -84,7 +84,7 @@ OpenAPI: Swagger 2.0 and OpenAPI 3.0, 3.1 and 3.2. Additive only; shared compone
84
84
  | Option | Default | |
85
85
  | --- | --- | --- |
86
86
  | `apiKey` | required | Merchant key. Also the HMAC key for IDs. |
87
- | `backendUrl` | Forge production collector | Optional override for a different Forge environment. |
87
+ | `backendUrl` | `https://dev-api.forgeintel.co/api/sdk/v2` | Optional collector override. |
88
88
  | `publicUrl` | Same-origin paths | Optional public origin for absolute rating URLs. Never infer it from request headers. |
89
89
  | `feedback` | `true` | Master switch for rating prompts, IDs, response additions and feedback routes. `false` leaves telemetry, client headers and independent agent context on. |
90
90
  | `basePath` | `/feedback` | Feedback routes (`/feedback`, `/feedback/rate`, `/feedback/summary`). |
@@ -118,7 +118,7 @@ const forge = createForge({
118
118
  });
119
119
  ```
120
120
 
121
- When enabled, context is always required on payment-bearing requests. `false` disables asking and recording. Forge documents `agent_context` and its `agent_type` and `search_query` fields as required. Use a listed agent name (or `Others` with `agent_type_other`), and the search query or `"direct"`. `{ searchQuery: false }` requires only the agent type. The legacy `required: false` option is ignored; disable `agentContext` to opt out. Context is self-reported, not authenticated identity.
121
+ When enabled, context is always required on payment-bearing requests. `false` disables asking and recording. Forge documents `agent_context` and its `agent_type` and `search_query` fields as required. Any agent name is accepted; known spellings are normalized (`Claude` and `claude-code` become `Claude Code`). Send the search query, or `"direct"`. When the merchant declares a `bazaar` extension, Forge adds the same field there (schema and example), so agents that discover the service through Bazaar see it too. `{ searchQuery: false }` requires only the agent type. The legacy `required: false` option is ignored; disable `agentContext` to opt out. Context is self-reported, not authenticated identity.
122
122
 
123
123
  Mount Forge **before payment middleware**. A request carrying `PAYMENT-SIGNATURE` or `X-PAYMENT` gets HTTP 400 with field errors when context is missing or invalid, before the downstream payment handler runs. Initial unpaid requests can still receive a 402, and inspection and feedback routes stay accessible. Feedback remains optional and has its own `feedback` switch.
124
124
 
@@ -0,0 +1,7 @@
1
+ import { type ContextOptions } from "./context.js";
2
+ /**
3
+ * Declare agent context in a v2 challenge's `bazaar` extension, in place: an `agent_context` object on JSON
4
+ * bodies, or the `agent_*` query parameters on routes without a body. Other body types, composed or
5
+ * referenced schemas, and fields the merchant already declares are left alone. Returns whether it changed.
6
+ */
7
+ export declare function addContextToBazaar(bazaar: unknown, options: ContextOptions): boolean;
package/dist/bazaar.js ADDED
@@ -0,0 +1,58 @@
1
+ import { CONTEXT_FIELD, agentContextExample, agentContextQuerySchema, agentContextSchema } from "./context.js";
2
+ const isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v);
3
+ /** Keywords whose meaning an added property could change; such schemas are left alone. */
4
+ const COMPOSED = ["$ref", "allOf", "anyOf", "oneOf", "not", "if", "then", "else", "dependentSchemas", "patternProperties"];
5
+ function declarable(schema) {
6
+ if (!isObj(schema) || COMPOSED.some((key) => key in schema))
7
+ return false;
8
+ if (schema.type !== undefined && schema.type !== "object")
9
+ return false;
10
+ if (schema.properties !== undefined && !isObj(schema.properties))
11
+ return false;
12
+ return schema.required === undefined || Array.isArray(schema.required);
13
+ }
14
+ /**
15
+ * Add properties to one part of the Bazaar input (`body` or `queryParams`): the JSON Schema in `schema` and
16
+ * the example in `info`, together. Facilitators index the Bazaar copy a client echoes with its payment only
17
+ * when `info` validates against `schema`, so declaring a required field without an example drops the listing.
18
+ * `@x402/core` checks the echo as a superset of what the server advertised, so adding keys keeps payments valid.
19
+ */
20
+ function extend(schemas, info, key, properties, required, example) {
21
+ const schema = schemas[key];
22
+ if (!declarable(schema))
23
+ return false;
24
+ const current = info[key];
25
+ if (current !== undefined && !isObj(current))
26
+ return false;
27
+ const declared = isObj(schema.properties) ? schema.properties : {};
28
+ const listed = (schema.required ?? []);
29
+ // The merchant already describes these fields: their declaration wins.
30
+ if (Object.keys(properties).some((name) => name in declared || listed.includes(name) || (isObj(current) && name in current)))
31
+ return false;
32
+ schema.properties = { ...declared, ...properties };
33
+ if (required.length)
34
+ schema.required = [...new Set([...listed, ...required])];
35
+ info[key] = { ...current, ...example };
36
+ return true;
37
+ }
38
+ /**
39
+ * Declare agent context in a v2 challenge's `bazaar` extension, in place: an `agent_context` object on JSON
40
+ * bodies, or the `agent_*` query parameters on routes without a body. Other body types, composed or
41
+ * referenced schemas, and fields the merchant already declares are left alone. Returns whether it changed.
42
+ */
43
+ export function addContextToBazaar(bazaar, options) {
44
+ if (!isObj(bazaar) || !isObj(bazaar.info) || !isObj(bazaar.info.input) || !isObj(bazaar.schema))
45
+ return false;
46
+ const inputSchema = bazaar.schema.properties?.input;
47
+ if (!isObj(inputSchema) || !isObj(inputSchema.properties))
48
+ return false;
49
+ const info = bazaar.info.input;
50
+ const required = options.required !== false;
51
+ if (info.bodyType !== undefined || "body" in inputSchema.properties) {
52
+ if (info.bodyType !== "json")
53
+ return false;
54
+ return extend(inputSchema.properties, info, "body", { [CONTEXT_FIELD]: agentContextSchema(options) }, required ? [CONTEXT_FIELD] : [], { [CONTEXT_FIELD]: agentContextExample(options) });
55
+ }
56
+ const query = agentContextQuerySchema(options);
57
+ return extend(inputSchema.properties, info, "queryParams", query.properties, query.required, agentContextExample(options, "query"));
58
+ }
package/dist/context.d.ts CHANGED
@@ -1,5 +1,13 @@
1
1
  /** Suggested agent names; anything else is kept as given. */
2
2
  export declare const AGENT_TYPES: readonly ["Claude Code", "Codex", "Cursor", "Grok Bot", "Muse", "Hermes", "Instinct", "OpenClaw", "Others"];
3
+ /**
4
+ * Example values for discovery documents that need one (Bazaar's `info`). Agents sometimes copy examples
5
+ * verbatim, so they are placeholders, and an unedited placeholder is recorded as missing rather than as a name.
6
+ */
7
+ export declare const CONTEXT_PLACEHOLDERS: {
8
+ readonly agent_type: "your agent name";
9
+ readonly search_query: "your search query, or direct";
10
+ };
3
11
  /** Suggested x402 clients; anything else is kept as given. */
4
12
  export declare const CLIENTS: readonly ["agentcash", "awal", "pay.sh", "other", "unknown"];
5
13
  /** JSON body field (POST, PUT, …). */
@@ -45,11 +53,6 @@ export declare function agentContextSchema({ searchQuery, required }?: ContextOp
45
53
  maxLength: number;
46
54
  } | undefined;
47
55
  agent_type: {
48
- type: string;
49
- enum: ("Claude Code" | "Codex" | "Cursor" | "Grok Bot" | "Muse" | "Hermes" | "Instinct" | "OpenClaw" | "Others")[];
50
- description: string;
51
- };
52
- agent_type_other: {
53
56
  description: string;
54
57
  minLength?: number | undefined;
55
58
  type: string;
@@ -60,7 +63,7 @@ export declare function agentContextSchema({ searchQuery, required }?: ContextOp
60
63
  type: string;
61
64
  description: string;
62
65
  };
63
- /** The optional query parameters, for operations without a request body. */
66
+ /** The query parameters, for operations without a request body. */
64
67
  export declare function agentContextParameters({ searchQuery }?: {
65
68
  searchQuery?: boolean;
66
69
  }): {
@@ -68,7 +71,16 @@ export declare function agentContextParameters({ searchQuery }?: {
68
71
  description: string;
69
72
  schema: Record<string, unknown>;
70
73
  }[];
71
- /** One line for the forge-feedback extension, so clients that only inspect the 402 learn about it too. */
74
+ /** The same parameters as JSON Schema properties, for discovery documents that describe a query object (Bazaar). */
75
+ export declare function agentContextQuerySchema({ searchQuery, required }?: ContextOptions): {
76
+ properties: Record<string, Record<string, unknown>>;
77
+ required: string[];
78
+ };
79
+ /** Placeholder values matching agentContextSchema (body) or agentContextQuerySchema (query). */
80
+ export declare function agentContextExample({ searchQuery }?: ContextOptions, where?: "body" | "query"): {
81
+ [x: string]: "your agent name" | "your search query, or direct";
82
+ };
83
+ /** One line for the forge-agent-context extension, so clients that only inspect the 402 learn about it too. */
72
84
  export declare function agentContextAsk({ searchQuery, required }?: ContextOptions): string;
73
85
  /** Validate the original values, before lenient parsing can truncate or discard them. */
74
86
  export declare function contextIssues(raw: Record<string, unknown>, { searchQuery }: ContextOptions): string[];
package/dist/context.js CHANGED
@@ -2,6 +2,20 @@
2
2
  // Enabled context is required on payment-bearing requests.
3
3
  /** Suggested agent names; anything else is kept as given. */
4
4
  export const AGENT_TYPES = ["Claude Code", "Codex", "Cursor", "Grok Bot", "Muse", "Hermes", "Instinct", "OpenClaw", "Others"];
5
+ /** Spellings agents use for the suggested names, compared lowercase with only letters and digits kept. */
6
+ const AGENT_ALIASES = {
7
+ claude: "Claude Code", claudecode: "Claude Code", claudecodecli: "Claude Code", anthropicclaudecode: "Claude Code",
8
+ codex: "Codex", codexcli: "Codex", openaicodex: "Codex",
9
+ cursor: "Cursor", cursoragent: "Cursor", cursorai: "Cursor",
10
+ grok: "Grok Bot", grokbot: "Grok Bot",
11
+ muse: "Muse", hermes: "Hermes", hermesagent: "Hermes", instinct: "Instinct", openclaw: "OpenClaw",
12
+ other: "Others", others: "Others", othersspecify: "Others", unknown: "Others",
13
+ };
14
+ /**
15
+ * Example values for discovery documents that need one (Bazaar's `info`). Agents sometimes copy examples
16
+ * verbatim, so they are placeholders, and an unedited placeholder is recorded as missing rather than as a name.
17
+ */
18
+ export const CONTEXT_PLACEHOLDERS = { agent_type: "your agent name", search_query: "your search query, or direct" };
5
19
  /** Suggested x402 clients; anything else is kept as given. */
6
20
  export const CLIENTS = ["agentcash", "awal", "pay.sh", "other", "unknown"];
7
21
  /** JSON body field (POST, PUT, …). */
@@ -29,15 +43,13 @@ export function parseAgentContext(input, { searchQuery = true } = {}) {
29
43
  let text = raw.replace(/[\u0000-\u001f\u007f]+/g, " ").trim().slice(0, LIMITS[key]);
30
44
  if (!text)
31
45
  continue;
32
- if (key === "agent_type") {
33
- if (/^grok(?: bot)?$/i.test(text))
34
- text = "Grok Bot";
35
- if (/^(?:others?(?: \(specify\))?|unknown)$/i.test(text))
36
- text = "Others";
37
- }
46
+ if ((key === "agent_type" || key === "search_query") && text.toLowerCase() === CONTEXT_PLACEHOLDERS[key])
47
+ continue;
48
+ if (key === "agent_type")
49
+ text = AGENT_ALIASES[text.toLowerCase().replace(/[^a-z0-9]/g, "")] ?? text;
38
50
  if (key === "search_query" && /^direct$/i.test(text))
39
51
  text = "direct";
40
- const known = key === "agent_type" ? AGENT_TYPES : key === "client" ? CLIENTS : null;
52
+ const known = key === "client" ? CLIENTS : null;
41
53
  context[key] = known?.find((v) => v.toLowerCase() === text.toLowerCase()) ?? text;
42
54
  }
43
55
  return Object.keys(context).length ? context : undefined;
@@ -86,8 +98,7 @@ export function takeFromUrl(url) {
86
98
  }
87
99
  const DESCRIPTIONS = {
88
100
  object: "information about the calling agent and how it found this service.",
89
- agent_type: "Which agent are you? Choose Others if yours is not listed and share its name in agent_type_other.",
90
- agent_type_other: "Your agent's name, when agent_type is Others.",
101
+ agent_type: `Your agent's name, for example ${AGENT_TYPES.filter((name) => name !== "Others").join(", ")}. Any name works.`,
91
102
  search_query: "The search query you used to find this service, or \"direct\" if you did not search.",
92
103
  };
93
104
  /** JSON Schema for the `agent_context` body property. */
@@ -97,23 +108,36 @@ export function agentContextSchema({ searchQuery = true, required = true } = {})
97
108
  description: DESCRIPTIONS.object,
98
109
  ...(required ? { required: ["agent_type", ...(searchQuery ? ["search_query"] : [])] } : {}),
99
110
  properties: {
100
- agent_type: { type: "string", enum: [...AGENT_TYPES], description: DESCRIPTIONS.agent_type },
101
- agent_type_other: { type: "string", maxLength: LIMITS.agent_type_other, ...(required ? { minLength: 1 } : {}), description: DESCRIPTIONS.agent_type_other },
111
+ agent_type: { type: "string", maxLength: LIMITS.agent_type, ...(required ? { minLength: 1 } : {}), description: DESCRIPTIONS.agent_type },
102
112
  ...(searchQuery ? { search_query: { type: "string", maxLength: LIMITS.search_query, ...(required ? { minLength: 1 } : {}), description: DESCRIPTIONS.search_query } } : {}),
103
113
  },
104
114
  };
105
115
  }
106
- /** The optional query parameters, for operations without a request body. */
116
+ /** The query parameters, for operations without a request body. */
107
117
  export function agentContextParameters({ searchQuery = true } = {}) {
108
118
  const params = [
109
- { name: CONTEXT_QUERY.agent_type, description: DESCRIPTIONS.agent_type, schema: { type: "string", enum: [...AGENT_TYPES] } },
110
- { name: CONTEXT_QUERY.agent_type_other, description: DESCRIPTIONS.agent_type_other, schema: { type: "string", maxLength: LIMITS.agent_type_other } },
119
+ { name: CONTEXT_QUERY.agent_type, description: DESCRIPTIONS.agent_type, schema: { type: "string", maxLength: LIMITS.agent_type } },
111
120
  ];
112
121
  if (searchQuery)
113
122
  params.push({ name: CONTEXT_QUERY.search_query, description: DESCRIPTIONS.search_query, schema: { type: "string", maxLength: LIMITS.search_query } });
114
123
  return params;
115
124
  }
116
- /** One line for the forge-feedback extension, so clients that only inspect the 402 learn about it too. */
125
+ /** The same parameters as JSON Schema properties, for discovery documents that describe a query object (Bazaar). */
126
+ export function agentContextQuerySchema({ searchQuery = true, required = true } = {}) {
127
+ const properties = {};
128
+ for (const p of agentContextParameters({ searchQuery }))
129
+ properties[p.name] = { ...p.schema, ...(required ? { minLength: 1 } : {}), description: p.description };
130
+ return { properties, required: required ? Object.keys(properties) : [] };
131
+ }
132
+ /** Placeholder values matching agentContextSchema (body) or agentContextQuerySchema (query). */
133
+ export function agentContextExample({ searchQuery = true } = {}, where = "body") {
134
+ const names = where === "query" ? { agent_type: CONTEXT_QUERY.agent_type, search_query: CONTEXT_QUERY.search_query } : { agent_type: "agent_type", search_query: "search_query" };
135
+ return {
136
+ [names.agent_type]: CONTEXT_PLACEHOLDERS.agent_type,
137
+ ...(searchQuery ? { [names.search_query]: CONTEXT_PLACEHOLDERS.search_query } : {}),
138
+ };
139
+ }
140
+ /** One line for the forge-agent-context extension, so clients that only inspect the 402 learn about it too. */
117
141
  export function agentContextAsk({ searchQuery = true, required = true } = {}) {
118
142
  const fields = searchQuery ? "agent_type, search_query" : "agent_type";
119
143
  const query = searchQuery ? "agent_type, agent_search_query query parameters" : "agent_type query parameter";
@@ -128,12 +152,6 @@ export function contextIssues(raw, { searchQuery = true }) {
128
152
  issues.push(`${key} must be a non-empty string of at most ${LIMITS[key]} characters`);
129
153
  }
130
154
  }
131
- const parsed = parseAgentContext(raw);
132
- if (parsed?.agent_type && !AGENT_TYPES.includes(parsed.agent_type)) {
133
- issues.push("agent_type must be a listed agent name, or Others with agent_type_other");
134
- }
135
- if (raw.agent_type_other !== undefined && (typeof raw.agent_type_other !== "string" || !raw.agent_type_other.trim() || raw.agent_type_other.length > 80)) {
136
- issues.push("agent_type_other must be a non-empty string of at most 80 characters");
137
- }
155
+ // Any name is accepted: known spellings are normalized by parseAgentContext, others are kept as given.
138
156
  return issues;
139
157
  }
package/dist/core.d.ts CHANGED
@@ -178,7 +178,7 @@ export declare const FEEDBACK_HEADERS: {
178
178
  export declare const BODY_LIMIT: number;
179
179
  /** Max OpenAPI document an adapter should buffer for enrichment. */
180
180
  export declare const SPEC_LIMIT: number;
181
- export declare const DEFAULT_BACKEND_URL = "https://app-api.forgeintel.co/api/sdk/v2";
181
+ export declare const DEFAULT_BACKEND_URL = "https://dev-api.forgeintel.co/api/sdk/v2";
182
182
  /**
183
183
  * Check options without throwing. Invalid required options are errors (Forge runs disabled);
184
184
  * invalid optional values are warnings and fall back to their defaults.
package/dist/core.js CHANGED
@@ -14,7 +14,7 @@ export const FEEDBACK_HEADERS = { "Cache-Control": "no-store", "X-Robots-Tag": "
14
14
  export const BODY_LIMIT = 8 * 1024;
15
15
  /** Max OpenAPI document an adapter should buffer for enrichment. */
16
16
  export const SPEC_LIMIT = 10 * 1024 * 1024;
17
- export const DEFAULT_BACKEND_URL = "https://app-api.forgeintel.co/api/sdk/v2";
17
+ export const DEFAULT_BACKEND_URL = "https://dev-api.forgeintel.co/api/sdk/v2";
18
18
  /**
19
19
  * Check options without throwing. Invalid required options are errors (Forge runs disabled);
20
20
  * invalid optional values are warnings and fall back to their defaults.
@@ -212,10 +212,12 @@ function enabledCore(options, configWarnings) {
212
212
  const challengeMarker = challengeSentence.includes(rateUrl) ? rateUrl : challengeSentence;
213
213
  const challengeAdditions = {
214
214
  ...(describe ? { sentence: challengeSentence, marker: challengeMarker } : {}),
215
- ...(!feedback || options.challengeExtension === false ? {} : { extension: feedbackExtension(rateUrl, tone, collectContext ? agentContextAsk({ searchQuery, required: requiredContext }) : undefined) }),
215
+ ...(!feedback || options.challengeExtension === false ? {} : { extension: feedbackExtension(rateUrl, tone) }),
216
216
  };
217
- if (!feedback && collectContext)
217
+ if (collectContext)
218
218
  challengeAdditions.contextExtension = { info: { agent_context: agentContextAsk({ searchQuery, required: requiredContext }), optional: !requiredContext } };
219
+ if (collectContext)
220
+ challengeAdditions.bazaarContext = { searchQuery, required: requiredContext };
219
221
  const touchChallenges = Boolean(challengeAdditions.sentence || challengeAdditions.extension || challengeAdditions.contextExtension);
220
222
  // Set once a document has been enriched; lets body injection respect strict response schemas.
221
223
  let allowInjection = null;
package/dist/x402.d.ts CHANGED
@@ -1,14 +1,14 @@
1
1
  import { type Tone } from "./ask.js";
2
+ import type { ContextOptions } from "./context.js";
2
3
  /** Key of the Forge extension in x402 v2 `extensions`: in the 402 challenge (next to e.g. `bazaar`) and in the payment receipt. */
3
4
  export declare const FEEDBACK_EXTENSION = "forge-feedback";
4
5
  /**
5
6
  * The `forge-feedback` challenge extension: how to rate the call, as structured data. Clients that inspect
6
7
  * the 402 (e.g. `awal x402 details`) print every extension, so this reaches agents before they pay.
7
- * With `agentContext`, it also says how to report agent context with the paid request.
8
+ * Agent context is a separate switch with its own extension (`forge-agent-context`).
8
9
  */
9
- export declare function feedbackExtension(rateUrl: string, tone?: Tone, agentContext?: string): {
10
+ export declare function feedbackExtension(rateUrl: string, tone?: Tone): {
10
11
  info: {
11
- agent_context?: string | undefined;
12
12
  rate: string;
13
13
  outcome: string[];
14
14
  issue: {
@@ -50,13 +50,15 @@ export interface ChallengeAdditions {
50
50
  marker?: string;
51
51
  /** Added as extensions["forge-feedback"] (v2 only; v1 challenges have no extensions). */
52
52
  extension?: unknown;
53
- /** Independent context prompt when feedback is disabled. */
53
+ /** Added as extensions["forge-agent-context"] whenever agent context is enabled, independent of feedback. */
54
54
  contextExtension?: unknown;
55
+ /** Declare agent context in the merchant's `bazaar` extension (schema and example together). */
56
+ bazaarContext?: ContextOptions;
55
57
  }
56
58
  /**
57
- * Add the rating sentence and/or the forge-feedback extension to a base64 PAYMENT-REQUIRED header (x402 v2).
58
- * `accepts` is untouched: v2 matches payments on `accepts`, and @x402/core only checks echoed extensions
59
- * the server itself advertised, so an added extension doesn't affect payment.
59
+ * Add the rating sentence, Forge's extensions and Bazaar agent context to a base64 PAYMENT-REQUIRED header (x402 v2).
60
+ * `accepts` is untouched: v2 matches payments on `accepts`. @x402/core checks that each echoed extension's `info`
61
+ * contains what the server advertised, so added extensions and added Bazaar fields don't affect payment.
60
62
  * Returns undefined when the header can't be parsed or already has everything.
61
63
  */
62
64
  export declare function describeChallenge(headerValue: string, additions: ChallengeAdditions): string | undefined;
package/dist/x402.js CHANGED
@@ -1,13 +1,14 @@
1
1
  import { ASK } from "./ask.js";
2
+ import { addContextToBazaar } from "./bazaar.js";
2
3
  import { ISSUES, PROTOCOL } from "./values.js";
3
4
  /** Key of the Forge extension in x402 v2 `extensions`: in the 402 challenge (next to e.g. `bazaar`) and in the payment receipt. */
4
5
  export const FEEDBACK_EXTENSION = "forge-feedback";
5
6
  /**
6
7
  * The `forge-feedback` challenge extension: how to rate the call, as structured data. Clients that inspect
7
8
  * the 402 (e.g. `awal x402 details`) print every extension, so this reaches agents before they pay.
8
- * With `agentContext`, it also says how to report agent context with the paid request.
9
+ * Agent context is a separate switch with its own extension (`forge-agent-context`).
9
10
  */
10
- export function feedbackExtension(rateUrl, tone = "soft", agentContext) {
11
+ export function feedbackExtension(rateUrl, tone = "soft") {
11
12
  return {
12
13
  info: {
13
14
  protocol: PROTOCOL,
@@ -18,7 +19,6 @@ export function feedbackExtension(rateUrl, tone = "soft", agentContext) {
18
19
  issue: { when: "The outcome is not fully. Tells the merchant what to fix.", values: Object.keys(ISSUES) },
19
20
  feedback_id: "In the paid response body (feedback_id) and the Forge-Feedback-Id header.",
20
21
  payment: "None. Plain GET, not an x402 endpoint.",
21
- ...(agentContext ? { agent_context: agentContext } : {}),
22
22
  },
23
23
  };
24
24
  }
@@ -81,17 +81,20 @@ function addToV2(challenge, add) {
81
81
  changed = true;
82
82
  }
83
83
  else if (typeof extensions === "object" && !Array.isArray(extensions) && !(key in extensions)) {
84
- // Added last, so the merchant's own extensions (e.g. bazaar) keep their order and content.
84
+ // Added last, so the merchant's own extensions (e.g. bazaar) keep their order.
85
85
  challenge.extensions = { ...extensions, [key]: extension };
86
86
  changed = true;
87
87
  }
88
88
  }
89
+ const extensions = challenge.extensions;
90
+ if (add.bazaarContext && extensions && typeof extensions === "object" && addContextToBazaar(extensions.bazaar, add.bazaarContext))
91
+ changed = true;
89
92
  return changed;
90
93
  }
91
94
  /**
92
- * Add the rating sentence and/or the forge-feedback extension to a base64 PAYMENT-REQUIRED header (x402 v2).
93
- * `accepts` is untouched: v2 matches payments on `accepts`, and @x402/core only checks echoed extensions
94
- * the server itself advertised, so an added extension doesn't affect payment.
95
+ * Add the rating sentence, Forge's extensions and Bazaar agent context to a base64 PAYMENT-REQUIRED header (x402 v2).
96
+ * `accepts` is untouched: v2 matches payments on `accepts`. @x402/core checks that each echoed extension's `info`
97
+ * contains what the server advertised, so added extensions and added Bazaar fields don't affect payment.
95
98
  * Returns undefined when the header can't be parsed or already has everything.
96
99
  */
97
100
  export function describeChallenge(headerValue, additions) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forgeintel/sdk",
3
- "version": "0.5.0-beta.6",
3
+ "version": "0.5.0-beta.8",
4
4
  "description": "The Forge SDK for x402 paid APIs: agent feedback, required 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",