xytara 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.
Files changed (61) hide show
  1. package/.env.example +29 -0
  2. package/BSV_TERANODE_SETUP.md +43 -0
  3. package/README.md +66 -7
  4. package/REAL_PAYMENT_SETUP.md +61 -0
  5. package/RELEASE_NOTES.md +12 -6
  6. package/SERVICE_CONTRACT.md +31 -0
  7. package/START_HERE.md +107 -6
  8. package/TREASURY_DESTINATIONS.example.json +66 -0
  9. package/TREASURY_DESTINATIONS.production.template.json +108 -0
  10. package/adapters/examples/langchain-reference-execution-adapter.js +81 -0
  11. package/adapters/examples/langchain-reference-execution-adapter.manifest.json +79 -0
  12. package/adapters/examples/langgraph-reference-execution-adapter.js +81 -0
  13. package/adapters/examples/langgraph-reference-execution-adapter.manifest.json +79 -0
  14. package/bin/xytara-first-run.js +244 -0
  15. package/bin/xytara.js +30 -5
  16. package/integrations/dispatch.js +7 -2
  17. package/integrations/registry.js +123 -2
  18. package/lib/activity_audit_contract.js +322 -0
  19. package/lib/adapter_depth_contract.js +156 -0
  20. package/lib/bolt_lane_contract.js +55 -0
  21. package/lib/bolt_payment_front.js +172 -0
  22. package/lib/capability_execution_truth.js +269 -0
  23. package/lib/capability_registry.js +39 -2
  24. package/lib/checkout_event_security.js +142 -0
  25. package/lib/command_flow.js +169 -36
  26. package/lib/commerce_artifacts.js +23 -4
  27. package/lib/commerce_checkout.js +134 -4
  28. package/lib/commerce_client.js +20 -0
  29. package/lib/commerce_economics.js +109 -9
  30. package/lib/commerce_runtime.js +38 -2
  31. package/lib/commerce_shell.js +4 -2
  32. package/lib/external_execution_runtime.js +132 -0
  33. package/lib/go_live_operator_pack.js +339 -0
  34. package/lib/http_transport.js +32 -0
  35. package/lib/integration_matrix_contract.js +6 -0
  36. package/lib/l402_lane_contract.js +55 -0
  37. package/lib/l402_payment_front.js +192 -0
  38. package/lib/network_transport.js +110 -0
  39. package/lib/operator_intelligence.js +215 -1
  40. package/lib/payment_config.js +80 -3
  41. package/lib/payment_front_registry.js +53 -0
  42. package/lib/payment_protocol_contract.js +165 -0
  43. package/lib/payment_verification.js +23 -3
  44. package/lib/pricing_optimization_contract.js +556 -0
  45. package/lib/release_history.js +15 -0
  46. package/lib/request_rate_limit.js +144 -0
  47. package/lib/runtime_bridge.js +10 -2
  48. package/lib/runtime_operations_worker.js +282 -0
  49. package/lib/settlement_bsv_live.js +79 -4
  50. package/lib/stripe_mpp_lane_contract.js +3 -0
  51. package/lib/stripe_mpp_payment_front.js +158 -0
  52. package/lib/treasury_destinations_contract.js +543 -0
  53. package/lib/treasury_egress_policy_contract.js +91 -0
  54. package/package.json +14 -21
  55. package/server.js +627 -88
  56. package/OPERATIONS_RUNBOOK.md +0 -66
  57. package/OPERATOR_START_HERE.md +0 -63
  58. package/PROGRAM_COMPLETE_RELEASE.md +0 -63
  59. package/PROGRAM_STATUS.md +0 -57
  60. package/PUBLISH_PLAN.md +0 -14
  61. package/RELEASE_CHECKLIST.md +0 -16
@@ -2,6 +2,9 @@
2
2
 
3
3
  const crypto = require("crypto");
4
4
  const { loadPaymentConfig } = require("./payment_config");
5
+ const { parseL402Authorization, verifyL402AccessToken } = require("./l402_payment_front");
6
+ const { parseBoltAuthorization, verifyBoltAccessToken } = require("./bolt_payment_front");
7
+ const { parseStripeMppAuthorization, verifyStripeMppAccessToken } = require("./stripe_mpp_payment_front");
5
8
  const {
6
9
  buildBsvTeranodeSettlementHints,
7
10
  extractBsvTeranodePaymentReference,
@@ -44,8 +47,14 @@ function parseInstantPaymentHeaders(headers) {
44
47
  };
45
48
  }
46
49
 
47
- function parsePayment(headers, requiredHeaders) {
50
+ function parsePayment(headers, requiredHeaders, options) {
48
51
  const required = Array.isArray(requiredHeaders) ? requiredHeaders : [];
52
+ const opts = options || {};
53
+ if (required.includes("authorization")) {
54
+ if (opts.authorization_scheme === "mpp" || opts.payment_protocol === "mpp") return parseStripeMppAuthorization(headers);
55
+ if (opts.authorization_scheme === "bolt" || opts.payment_protocol === "bolt") return parseBoltAuthorization(headers);
56
+ return parseL402Authorization(headers);
57
+ }
49
58
  if (required.includes("payment-signature")) return parseInstantPaymentHeaders(headers);
50
59
  return parseNativePaymentHeaders(headers);
51
60
  }
@@ -148,9 +157,20 @@ function verifyPaymentPayloadAgainstQuote(paymentPayload, quote, walletId, maxAg
148
157
  return { ok: true, age_seconds: ageSeconds };
149
158
  }
150
159
 
151
- function verifyPaymentAcceptance(state, headers, requiredHeaders, quote) {
160
+ function verifyPaymentAcceptance(state, headers, requiredHeaders, quote, options) {
152
161
  const config = loadPaymentConfig();
153
- const payment = parsePayment(headers || {}, requiredHeaders);
162
+ const required = Array.isArray(requiredHeaders) ? requiredHeaders : [];
163
+ const opts = options || {};
164
+ if (required.includes("authorization")) {
165
+ if (opts.authorization_scheme === "mpp" || opts.payment_protocol === "mpp") {
166
+ return verifyStripeMppAccessToken(headers || {}, quote);
167
+ }
168
+ if (opts.authorization_scheme === "bolt" || opts.payment_protocol === "bolt") {
169
+ return verifyBoltAccessToken(headers || {}, quote);
170
+ }
171
+ return verifyL402AccessToken(headers || {}, quote);
172
+ }
173
+ const payment = parsePayment(headers || {}, requiredHeaders, opts);
154
174
  if (config.verification_mode === "presence") {
155
175
  return {
156
176
  ok: true,
@@ -0,0 +1,556 @@
1
+ "use strict";
2
+
3
+ const { findTask } = require("../fixtures/catalog");
4
+ const { getCatalog, getCreditPackList } = require("./catalog_contract");
5
+
6
+ const PRICING_BAND_UNITS = {
7
+ utility: 1,
8
+ transactional: 2,
9
+ decision_support: 3,
10
+ governed_high_consequence: 5,
11
+ trust_critical: 8
12
+ };
13
+
14
+ function normalizeAmount(value) {
15
+ const amount = Number(value || 0);
16
+ return Number.isFinite(amount) ? amount : 0;
17
+ }
18
+
19
+ function collectQuotes(state) {
20
+ return state && state.quotes instanceof Map ? Array.from(state.quotes.values()) : [];
21
+ }
22
+
23
+ function valuesFromCollection(collection) {
24
+ if (!collection) return [];
25
+ if (collection instanceof Map) return Array.from(collection.values());
26
+ return Array.isArray(collection) ? collection : [];
27
+ }
28
+
29
+ function collectCheckoutPurchaseIntents(state) {
30
+ return valuesFromCollection(state && state.checkoutPurchaseIntents);
31
+ }
32
+
33
+ function collectCheckoutSessions(state) {
34
+ return valuesFromCollection(state && state.checkoutSessions);
35
+ }
36
+
37
+ function collectCheckoutEvents(state) {
38
+ return valuesFromCollection(state && state.checkoutEvents);
39
+ }
40
+
41
+ function collectExternalCreditGrants(state) {
42
+ return valuesFromCollection(state && state.externalCreditGrants);
43
+ }
44
+
45
+ function collectPaymentLedger(state) {
46
+ return Array.isArray(state && state.paymentLedger) ? state.paymentLedger : [];
47
+ }
48
+
49
+ function collectRefunds(state) {
50
+ return valuesFromCollection(state && state.refunds);
51
+ }
52
+
53
+ function collectTransactions(state) {
54
+ return valuesFromCollection(state && state.transactions)
55
+ .map((entry) => entry && entry.transaction ? entry.transaction : entry)
56
+ .filter(Boolean);
57
+ }
58
+
59
+ function resolveQuotePricingBand(quote) {
60
+ const taskRefs = Array.isArray(quote && quote.task_refs) ? quote.task_refs : [];
61
+ const observed = new Set();
62
+ for (const taskRef of taskRefs) {
63
+ const task = findTask(taskRef);
64
+ if (task && task.pricing_band) observed.add(task.pricing_band);
65
+ }
66
+ if (observed.has("trust_critical")) return "trust_critical";
67
+ if (observed.has("governed_high_consequence")) return "governed_high_consequence";
68
+ if (observed.has("decision_support")) return "decision_support";
69
+ if (observed.has("transactional")) return "transactional";
70
+ return observed.has("utility") ? "utility" : "utility";
71
+ }
72
+
73
+ function listTaskPricesByBand() {
74
+ const catalog = getCatalog();
75
+ const tasks = Array.isArray(catalog && catalog.tasks) ? catalog.tasks : [];
76
+ const byBand = new Map();
77
+ for (const task of tasks) {
78
+ if (!task || !task.pricing_band || !task.public_launch_price) continue;
79
+ const amount = normalizeAmount(task.public_launch_price.amount_minor);
80
+ if (amount <= 0) continue;
81
+ const band = String(task.pricing_band);
82
+ const current = byBand.get(band) || [];
83
+ current.push(amount);
84
+ byBand.set(band, current);
85
+ }
86
+ return byBand;
87
+ }
88
+
89
+ function buildMinimumChargeFloors() {
90
+ const byBand = listTaskPricesByBand();
91
+ return Object.entries(PRICING_BAND_UNITS).map(([pricingBand, usageUnits]) => {
92
+ const amounts = (byBand.get(pricingBand) || []).slice().sort((left, right) => left - right);
93
+ const observedMin = amounts.length > 0 ? amounts[0] : usageUnits * 10;
94
+ return {
95
+ pricing_band: pricingBand,
96
+ usage_units: usageUnits,
97
+ minimum_charge_floor_minor: observedMin,
98
+ currency: "USD_CENTS",
99
+ reasoning: "prevent_undercharging_of_runtime_consequence_even_when_quotes_are_small"
100
+ };
101
+ });
102
+ }
103
+
104
+ function buildStarterPricing() {
105
+ const packs = getCreditPackList();
106
+ const starter = packs.find((pack) => pack && pack.pack_id === "credits.starter") || null;
107
+ return {
108
+ starter_pack_id: starter ? starter.pack_id : "credits.starter",
109
+ starter_pack_amount_minor: starter ? starter.nominal_amount_minor : 1000,
110
+ starter_pack_units: starter ? starter.issued_units : 100,
111
+ recommended_free_boundary: [
112
+ "auth",
113
+ "docs",
114
+ "catalog",
115
+ "light_preview"
116
+ ],
117
+ recommended_paid_entry: [
118
+ "credit_pack_topup",
119
+ "quote_then_execute",
120
+ "low_friction_starter_pack_conversion"
121
+ ],
122
+ why_it_matters: "reduce_first-purchase_friction_without_giving_away_execution_and_consequence"
123
+ };
124
+ }
125
+
126
+ function buildCreditPackBreakpoints() {
127
+ return getCreditPackList().map((pack) => ({
128
+ pack_id: pack.pack_id,
129
+ category: pack.category,
130
+ issued_units: pack.issued_units,
131
+ nominal_amount_minor: pack.nominal_amount_minor,
132
+ intended_usage_posture: pack.intended_usage_posture,
133
+ recommended_for: pack.recommended_for
134
+ }));
135
+ }
136
+
137
+ function buildConsequencePremiumMultipliers() {
138
+ return [
139
+ { posture_id: "standard_runtime", multiplier: 1, recommended_for: "normal_direct_runtime_execution" },
140
+ { posture_id: "priority_runtime", multiplier: 1.15, recommended_for: "time-sensitive_runtime_execution" },
141
+ { posture_id: "transactional_consequence", multiplier: 1.2, recommended_for: "settlement_or_commit_bearing_work" },
142
+ { posture_id: "governed_high_consequence", multiplier: 1.35, recommended_for: "governed_or_multi-step_high_consequence_execution" },
143
+ { posture_id: "trust_critical", multiplier: 1.5, recommended_for: "trust-critical_authority_identity_or_proof-bearing_execution" }
144
+ ];
145
+ }
146
+
147
+ function buildQuoteAbandonmentSummary(state) {
148
+ const quotes = collectQuotes(state);
149
+ const statusCounts = quotes.reduce((acc, quote) => {
150
+ const key = quote && quote.status ? quote.status : "unknown";
151
+ acc[key] = (acc[key] || 0) + 1;
152
+ return acc;
153
+ }, {});
154
+ const total = quotes.length;
155
+ const executed = Number(statusCounts.executed || 0);
156
+ const accepted = Number(statusCounts.accepted || 0);
157
+ const expired = Number(statusCounts.expired || 0);
158
+ const quoted = Number(statusCounts.quoted || 0);
159
+ const converted = executed + accepted;
160
+ const quotedAmountMinor = quotes.reduce((sum, quote) => sum + normalizeAmount(quote && quote.amount_minor), 0);
161
+ const convertedAmountMinor = quotes
162
+ .filter((quote) => quote && (quote.status === "accepted" || quote.status === "executed"))
163
+ .reduce((sum, quote) => sum + normalizeAmount(quote.amount_minor), 0);
164
+ const expiredAmountMinor = quotes
165
+ .filter((quote) => quote && quote.status === "expired")
166
+ .reduce((sum, quote) => sum + normalizeAmount(quote.amount_minor), 0);
167
+ return {
168
+ summary_version: "xytara-quote-abandonment-summary-v2",
169
+ quote_count: total,
170
+ status_counts: statusCounts,
171
+ accepted_or_executed_count: converted,
172
+ open_quote_count: quoted,
173
+ expired_quote_count: expired,
174
+ quoted_amount_minor: quotedAmountMinor,
175
+ converted_amount_minor: convertedAmountMinor,
176
+ expired_amount_minor: expiredAmountMinor,
177
+ conversion_rate: total > 0 ? Number((converted / total).toFixed(4)) : null,
178
+ abandonment_rate: total > 0 ? Number((expired / total).toFixed(4)) : null,
179
+ revenue_capture_rate: quotedAmountMinor > 0 ? Number((convertedAmountMinor / quotedAmountMinor).toFixed(4)) : null,
180
+ note: "true_revenue_optimization_requires_live_quote_acceptance_and_abandonment_data_not_just_static_policy"
181
+ };
182
+ }
183
+
184
+ function buildQuoteCohortSummary(state, groupingKey) {
185
+ const quotes = collectQuotes(state);
186
+ const groups = new Map();
187
+ for (const quote of quotes) {
188
+ const key = groupingKey(quote);
189
+ const current = groups.get(key) || {
190
+ cohort_id: key,
191
+ quote_count: 0,
192
+ quoted_amount_minor: 0,
193
+ converted_count: 0,
194
+ converted_amount_minor: 0,
195
+ expired_count: 0,
196
+ expired_amount_minor: 0,
197
+ open_count: 0
198
+ };
199
+ const amount = normalizeAmount(quote && quote.amount_minor);
200
+ current.quote_count += 1;
201
+ current.quoted_amount_minor += amount;
202
+ if (quote && (quote.status === "accepted" || quote.status === "executed")) {
203
+ current.converted_count += 1;
204
+ current.converted_amount_minor += amount;
205
+ } else if (quote && quote.status === "expired") {
206
+ current.expired_count += 1;
207
+ current.expired_amount_minor += amount;
208
+ } else if (quote && quote.status === "quoted") {
209
+ current.open_count += 1;
210
+ }
211
+ groups.set(key, current);
212
+ }
213
+ return Array.from(groups.values())
214
+ .map((entry) => ({
215
+ ...entry,
216
+ conversion_rate: entry.quote_count > 0 ? Number((entry.converted_count / entry.quote_count).toFixed(4)) : null,
217
+ abandonment_rate: entry.quote_count > 0 ? Number((entry.expired_count / entry.quote_count).toFixed(4)) : null,
218
+ revenue_capture_rate: entry.quoted_amount_minor > 0
219
+ ? Number((entry.converted_amount_minor / entry.quoted_amount_minor).toFixed(4))
220
+ : null
221
+ }))
222
+ .sort((left, right) => right.quoted_amount_minor - left.quoted_amount_minor || right.quote_count - left.quote_count);
223
+ }
224
+
225
+ function buildQuoteCohorts(state) {
226
+ return {
227
+ by_pricing_band: buildQuoteCohortSummary(state, (quote) => resolveQuotePricingBand(quote)),
228
+ by_payment_protocol: buildQuoteCohortSummary(state, (quote) => quote && quote.payment_protocol ? quote.payment_protocol : "unknown"),
229
+ by_settlement_mode: buildQuoteCohortSummary(state, (quote) => quote && quote.settlement_mode ? quote.settlement_mode : "default")
230
+ };
231
+ }
232
+
233
+ function determineSampleMaturity(signalCounts) {
234
+ const counts = signalCounts || {};
235
+ const quoteCount = Number(counts.quote_count || 0);
236
+ const checkoutEventCount = Number(counts.checkout_event_count || 0);
237
+ const paymentLedgerCount = Number(counts.payment_ledger_count || 0);
238
+ const externalCreditGrantCount = Number(counts.external_credit_grant_count || 0);
239
+ const executionTransactionCount = Number(counts.execution_transaction_count || 0);
240
+
241
+ if (quoteCount >= 100 && paymentLedgerCount >= 20 && executionTransactionCount >= 20) {
242
+ return "mature_live_signals";
243
+ }
244
+ if (
245
+ quoteCount >= 25
246
+ && (checkoutEventCount >= 5 || paymentLedgerCount >= 5 || externalCreditGrantCount >= 5)
247
+ && executionTransactionCount >= 5
248
+ ) {
249
+ return "emerging_live_signals";
250
+ }
251
+ return "sparse_live_signals";
252
+ }
253
+
254
+ function postureForSampleMaturity(sampleMaturity) {
255
+ if (sampleMaturity === "mature_live_signals") return "ready_for_cautious_price_tests";
256
+ if (sampleMaturity === "emerging_live_signals") return "observe_and_prepare_small_price_tests";
257
+ return "observe_do_not_optimize_aggressively";
258
+ }
259
+
260
+ function buildRevenueSignalSummary(state) {
261
+ const quotes = collectQuotes(state);
262
+ const checkoutPurchaseIntents = collectCheckoutPurchaseIntents(state);
263
+ const checkoutSessions = collectCheckoutSessions(state);
264
+ const checkoutEvents = collectCheckoutEvents(state);
265
+ const externalCreditGrants = collectExternalCreditGrants(state);
266
+ const paymentLedger = collectPaymentLedger(state);
267
+ const refunds = collectRefunds(state);
268
+ const transactions = collectTransactions(state);
269
+ const quoteSummary = buildQuoteAbandonmentSummary(state);
270
+ const paidCheckoutEvents = checkoutEvents.filter((event) => event && event.payment_status === "paid");
271
+ const refundedCheckoutEvents = checkoutEvents.filter((event) =>
272
+ event && (event.payment_status === "refunded" || event.payment_status === "chargeback")
273
+ );
274
+ const checkoutPaidIntents = checkoutPurchaseIntents.filter((intent) =>
275
+ intent && (
276
+ intent.checkout_status === "paid"
277
+ || intent.customer_status === "credits_issued"
278
+ || intent.customer_status === "execution_dispatched"
279
+ || (intent.fulfillment && (intent.fulfillment.credits_issued || intent.fulfillment.execution_authorized))
280
+ )
281
+ );
282
+ const counts = {
283
+ quote_count: quotes.length,
284
+ checkout_purchase_intent_count: checkoutPurchaseIntents.length,
285
+ checkout_session_count: checkoutSessions.length,
286
+ checkout_event_count: checkoutEvents.length,
287
+ paid_checkout_event_count: paidCheckoutEvents.length,
288
+ refunded_checkout_event_count: refundedCheckoutEvents.length,
289
+ paid_checkout_intent_count: checkoutPaidIntents.length,
290
+ external_credit_grant_count: externalCreditGrants.length,
291
+ payment_ledger_count: paymentLedger.length,
292
+ refund_count: refunds.length,
293
+ execution_transaction_count: transactions.length
294
+ };
295
+ const sampleMaturity = determineSampleMaturity(counts);
296
+ return {
297
+ summary_version: "xytara-revenue-signal-summary-v1",
298
+ sample_maturity: sampleMaturity,
299
+ pricing_change_posture: postureForSampleMaturity(sampleMaturity),
300
+ counts,
301
+ amounts: {
302
+ quoted_amount_minor: quoteSummary.quoted_amount_minor,
303
+ converted_quote_amount_minor: quoteSummary.converted_amount_minor,
304
+ paid_checkout_amount_minor: paidCheckoutEvents.reduce((sum, event) => sum + normalizeAmount(event && event.amount_received_minor), 0),
305
+ payment_ledger_amount_minor: paymentLedger.reduce((sum, payment) => sum + normalizeAmount(payment && payment.amount_minor), 0),
306
+ external_credit_grant_amount_minor: externalCreditGrants.reduce((sum, grant) => sum + normalizeAmount(grant && grant.amount_minor), 0),
307
+ refund_amount_minor: refunds.reduce((sum, refund) => sum + normalizeAmount(refund && refund.amount_minor), 0)
308
+ },
309
+ rates: {
310
+ quote_conversion_rate: quoteSummary.conversion_rate,
311
+ quote_abandonment_rate: quoteSummary.abandonment_rate,
312
+ revenue_capture_rate: quoteSummary.revenue_capture_rate,
313
+ checkout_paid_rate: checkoutPurchaseIntents.length > 0
314
+ ? Number((checkoutPaidIntents.length / checkoutPurchaseIntents.length).toFixed(4))
315
+ : null,
316
+ refund_request_rate: checkoutPurchaseIntents.length > 0
317
+ ? Number((refunds.length / checkoutPurchaseIntents.length).toFixed(4))
318
+ : null
319
+ },
320
+ required_next_metrics: [
321
+ "quote_created_and_expired_counts",
322
+ "hosted_checkout_start_and_paid_counts",
323
+ "hosted_checkout_api_pack_purchase_counts",
324
+ "external_credit_grant_success_and_retry_counts",
325
+ "execution_transaction_completion_counts",
326
+ "refund_and_chargeback_counts"
327
+ ],
328
+ operator_note: sampleMaturity === "sparse_live_signals"
329
+ ? "live_revenue_signals_are_sparse_so_hold_pricing_thresholds_and_collect_more_evidence"
330
+ : "live_revenue_signals_are_available_for_careful_operator_review"
331
+ };
332
+ }
333
+
334
+ function buildPricingDecisionGuardrail(state) {
335
+ const revenueSignals = buildRevenueSignalSummary(state);
336
+ const allowPriceChange = revenueSignals.sample_maturity === "mature_live_signals";
337
+ return {
338
+ guardrail_version: "xytara-pricing-decision-guardrail-v1",
339
+ sample_maturity: revenueSignals.sample_maturity,
340
+ allow_price_change: allowPriceChange,
341
+ pricing_change_posture: revenueSignals.pricing_change_posture,
342
+ required_before_price_change: [
343
+ "enough_real_quotes_to_measure_conversion_and_abandonment",
344
+ "enough_hosted_checkout_events_to_measure_pack_purchase_conversion",
345
+ "enough_external_credit_grants_to_measure_fulfillment_reliability",
346
+ "enough_execution_transactions_to_measure_paid_usage_quality",
347
+ "refund_or_chargeback_monitoring_present"
348
+ ],
349
+ allowed_actions: allowPriceChange
350
+ ? [
351
+ "run_small_operator_reviewed_price_tests",
352
+ "adjust_auto_topup_thresholds_with_documented_rationale",
353
+ "review_package_breakpoints_against_live_conversion"
354
+ ]
355
+ : [
356
+ "collect_live_quote_checkout_grant_execution_and_refund_metrics",
357
+ "keep_current_package_prices_and_thresholds",
358
+ "improve_instrumentation_and_operator_reporting"
359
+ ],
360
+ blocked_actions: allowPriceChange
361
+ ? []
362
+ : [
363
+ "raise_or_lower_public_package_prices_from_sparse_signals",
364
+ "change_auto_topup_thresholds_without_live_conversion_rationale",
365
+ "remove_starter_api_pack_or_change_hosted_checkout_gateway_language"
366
+ ],
367
+ evidence: {
368
+ counts: revenueSignals.counts,
369
+ rates: revenueSignals.rates
370
+ }
371
+ };
372
+ }
373
+
374
+ function buildPackageThresholdRationale(state) {
375
+ const revenueSignals = buildRevenueSignalSummary(state);
376
+ return {
377
+ rationale_version: "xytara-package-threshold-rationale-v1",
378
+ current_posture: revenueSignals.sample_maturity === "mature_live_signals"
379
+ ? "eligible_for_operator_reviewed_threshold_tests"
380
+ : "hold_current_thresholds_until_live_metrics_mature",
381
+ hosted_checkout_gateway_product_boundary: "public_checkout_sells_api_packs_while_internal_runtime_accounts_consume_credits_and_entitlements",
382
+ starter_api_pack: {
383
+ public_package_id: "starter-api",
384
+ internal_credit_pack_id: "credits.starter",
385
+ rationale: "keep_the_first_paid_entry_simple_and_compliant_as_an_api_pack_while_mapping_to_internal_machine_runtime_credits",
386
+ tuning_rule: "do_not_change_until_checkout_conversion_grant_success_execution_completion_and_refund_rates_are_visible"
387
+ },
388
+ auto_topup: {
389
+ current_action: "observe",
390
+ rationale: "auto_topup_thresholds_should_follow_repeat_usage_and_low_balance_behavior_not_static_launch_assumptions",
391
+ tuning_rule: "require_live_repeat_purchase_or_low_balance_data_before_threshold_changes"
392
+ },
393
+ evidence: {
394
+ sample_maturity: revenueSignals.sample_maturity,
395
+ counts: revenueSignals.counts
396
+ }
397
+ };
398
+ }
399
+
400
+ function buildOptimizationRecommendations(state) {
401
+ const quoteSummary = buildQuoteAbandonmentSummary(state);
402
+ const cohorts = buildQuoteCohorts(state);
403
+ const decisionGuardrail = buildPricingDecisionGuardrail(state);
404
+ const recommendations = [];
405
+ const utilityBand = cohorts.by_pricing_band.find((entry) => entry.cohort_id === "utility");
406
+ const trustBand = cohorts.by_pricing_band.find((entry) => entry.cohort_id === "trust_critical");
407
+ const x402Cohort = cohorts.by_payment_protocol.find((entry) => entry.cohort_id === "x402");
408
+ const creditCohort = cohorts.by_payment_protocol.find((entry) => entry.cohort_id === "account_credits");
409
+ const highOpenQuotes = quoteSummary.open_quote_count >= 5;
410
+
411
+ if (decisionGuardrail.allow_price_change && utilityBand && utilityBand.abandonment_rate !== null && utilityBand.abandonment_rate > 0.35) {
412
+ recommendations.push({
413
+ action_id: "soften_utility_entry_pricing",
414
+ why: "utility_band_is_showing_meaningful_quote_abandonment",
415
+ target_surface: "starter_pricing_and_minimum_charge_floors",
416
+ evidence: utilityBand
417
+ });
418
+ }
419
+ if (decisionGuardrail.allow_price_change && trustBand && trustBand.conversion_rate !== null && trustBand.conversion_rate > 0.7) {
420
+ recommendations.push({
421
+ action_id: "review_trust_critical_premium_upward",
422
+ why: "high-consequence_quotes_are_closing_well_enough_to_support_margin_capture",
423
+ target_surface: "high_consequence_premium_multipliers",
424
+ evidence: trustBand
425
+ });
426
+ }
427
+ if (decisionGuardrail.allow_price_change && x402Cohort && creditCohort && x402Cohort.conversion_rate !== null && creditCohort.conversion_rate !== null
428
+ && x402Cohort.conversion_rate + 0.15 < creditCohort.conversion_rate) {
429
+ recommendations.push({
430
+ action_id: "push_repeat_use_toward_credits_after_first_x402_conversion",
431
+ why: "credits_are_converting_better_than_direct_machine_payment_for_repeat_use",
432
+ target_surface: "credit_pack_breakpoints_and_runtime_prompts",
433
+ evidence: {
434
+ x402: x402Cohort,
435
+ account_credits: creditCohort
436
+ }
437
+ });
438
+ }
439
+ if (highOpenQuotes) {
440
+ recommendations.push({
441
+ action_id: "review_quote_ttl_and_follow-up",
442
+ why: "too_many_quotes_are_stalling_without_resolving_to_payment_or_expiry",
443
+ target_surface: "quote_lifecycle_and_payment_prompts",
444
+ evidence: {
445
+ open_quote_count: quoteSummary.open_quote_count,
446
+ quote_count: quoteSummary.quote_count
447
+ }
448
+ });
449
+ }
450
+ if (recommendations.length === 0) {
451
+ recommendations.push({
452
+ action_id: "continue_live_quote_observation",
453
+ why: decisionGuardrail.allow_price_change
454
+ ? "no_price_change_signal_has_cleared_operator_review_thresholds_yet"
455
+ : "not_enough_live_variance_yet_to_justify_aggressive_pricing_changes",
456
+ target_surface: "quote_acceptance_and_abandonment_monitoring",
457
+ evidence: {
458
+ quote_summary: quoteSummary,
459
+ decision_guardrail: decisionGuardrail
460
+ }
461
+ });
462
+ }
463
+ return {
464
+ recommendation_version: "xytara-pricing-optimization-recommendations-v1",
465
+ recommendations
466
+ };
467
+ }
468
+
469
+ function buildPricingOptimizationPack(state) {
470
+ const minimumChargeFloors = buildMinimumChargeFloors();
471
+ const starterPricing = buildStarterPricing();
472
+ const creditPackBreakpoints = buildCreditPackBreakpoints();
473
+ const quoteAbandonmentSummary = buildQuoteAbandonmentSummary(state);
474
+ const quoteCohorts = buildQuoteCohorts(state);
475
+ const recommendations = buildOptimizationRecommendations(state);
476
+ const revenueSignalSummary = buildRevenueSignalSummary(state);
477
+ const pricingDecisionGuardrail = buildPricingDecisionGuardrail(state);
478
+ const packageThresholdRationale = buildPackageThresholdRationale(state);
479
+ return {
480
+ product: "xytara",
481
+ category: "machine-commerce-pricing-optimization-pack",
482
+ pack_version: "xytara-pricing-optimization-pack-v3",
483
+ optimization_posture: "quote_based_pricing_with_credit_conversion_and_consequence_weighting",
484
+ pricing_change_posture: revenueSignalSummary.pricing_change_posture,
485
+ live_data_note: revenueSignalSummary.operator_note,
486
+ why_not_flat_pricing: [
487
+ "flat_pricing_undercharges_high_consequence_runtime_work",
488
+ "flat_pricing_overprices_simple_utility_and_entry_paths",
489
+ "quote_based_pricing_preserves_margin_capture_across_different_runtime_shapes"
490
+ ],
491
+ minimum_charge_floors: minimumChargeFloors,
492
+ pricing_band_review: {
493
+ pricing_band_units: PRICING_BAND_UNITS,
494
+ policy_goal: "keep_simple_work_easy_to_try_while_protecting_margin_on_consequence-bearing_runtime"
495
+ },
496
+ credit_pack_breakpoints: creditPackBreakpoints,
497
+ starter_pricing: starterPricing,
498
+ high_consequence_premium_multipliers: buildConsequencePremiumMultipliers(),
499
+ quote_abandonment_summary: quoteAbandonmentSummary,
500
+ quote_conversion_cohorts: quoteCohorts,
501
+ revenue_signal_summary: revenueSignalSummary,
502
+ pricing_decision_guardrail: pricingDecisionGuardrail,
503
+ package_threshold_rationale: packageThresholdRationale,
504
+ optimization_recommendations: recommendations,
505
+ data_dependent_tuning: [
506
+ "conversion_test_starter_pack_pricing",
507
+ "review_quote_acceptance_and_expiry",
508
+ "lift_or_lower_minimum_charge_floors_based_on_real_demand",
509
+ "tighten_or_relax_premium_multipliers_based_on_close_rate_and_margin"
510
+ ],
511
+ supported_surfaces: {
512
+ credit_pack_ref: "/v1/credit-packs",
513
+ pricing_policy_ref_template: "/v1/economics/accounts/:account_id/pricing-policy-package",
514
+ quote_policy_ref_template: "/v1/economics/accounts/:account_id/quote-policy-package",
515
+ payment_quotes_ref: "/v1/payment-quotes",
516
+ quote_cohorts_ref: "/v1/pricing-optimization/quote-cohorts",
517
+ recommendations_ref: "/v1/pricing-optimization/recommendations",
518
+ revenue_signal_summary_ref: "/v1/pricing-optimization/revenue-signal-summary",
519
+ decision_guardrail_ref: "/v1/pricing-optimization/decision-guardrail"
520
+ }
521
+ };
522
+ }
523
+
524
+ function summarizePricingOptimizationPack(state) {
525
+ const pack = buildPricingOptimizationPack(state);
526
+ return {
527
+ product: "xytara",
528
+ category: "machine-commerce-pricing-optimization-pack-summary",
529
+ summary_version: "xytara-pricing-optimization-pack-summary-v3",
530
+ optimization_posture: pack.optimization_posture,
531
+ pricing_change_posture: pack.pricing_change_posture,
532
+ sample_maturity: pack.revenue_signal_summary.sample_maturity,
533
+ allow_price_change: pack.pricing_decision_guardrail.allow_price_change,
534
+ floor_count: pack.minimum_charge_floors.length,
535
+ credit_pack_breakpoint_count: pack.credit_pack_breakpoints.length,
536
+ premium_multiplier_count: pack.high_consequence_premium_multipliers.length,
537
+ quote_count: pack.quote_abandonment_summary.quote_count,
538
+ checkout_event_count: pack.revenue_signal_summary.counts.checkout_event_count,
539
+ external_credit_grant_count: pack.revenue_signal_summary.counts.external_credit_grant_count,
540
+ payment_ledger_count: pack.revenue_signal_summary.counts.payment_ledger_count,
541
+ refund_count: pack.revenue_signal_summary.counts.refund_count,
542
+ execution_transaction_count: pack.revenue_signal_summary.counts.execution_transaction_count,
543
+ recommendation_count: pack.optimization_recommendations.recommendations.length,
544
+ linked_surfaces: pack.supported_surfaces
545
+ };
546
+ }
547
+
548
+ module.exports = {
549
+ buildPricingOptimizationPack,
550
+ summarizePricingOptimizationPack,
551
+ buildQuoteAbandonmentSummary,
552
+ buildQuoteCohorts,
553
+ buildRevenueSignalSummary,
554
+ buildPricingDecisionGuardrail,
555
+ buildOptimizationRecommendations
556
+ };
@@ -10,6 +10,21 @@ function buildReleaseHistory() {
10
10
  current_version: packageJson.version,
11
11
  release_track: "public_release",
12
12
  history: [
13
+ {
14
+ version: "2.6.0",
15
+ channel: "public_release",
16
+ maturity_posture: "expansion_ready",
17
+ headline: "expansion release with public first-run polish, provider-backed adapter depth, framework reference adapters, and operator observability",
18
+ milestone_refs: [
19
+ "public_first_run_quote_and_credits_execution",
20
+ "provider_backed_mcp_adapter_depth",
21
+ "langgraph_reference_adapter",
22
+ "langchain_reference_adapter",
23
+ "operator_observability_pack",
24
+ "pricing_telemetry_guardrails",
25
+ "framework_adapter_verifier_coverage"
26
+ ]
27
+ },
13
28
  {
14
29
  version: "2.5.0",
15
30
  channel: "public_release",