@prplkane/roundtable 0.6.6 → 0.7.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/src/validate.js CHANGED
@@ -3,6 +3,7 @@
3
3
  // the seats module or the exporter sees it. Pure, so it is unit tested.
4
4
 
5
5
  import { researchSettings } from './research.js';
6
+ import { agentLinkProfile } from './seats.js';
6
7
 
7
8
  export const LIMITS = {
8
9
  decision: 2000, option: 200, options: [2, 12], field: 4000, exportTo: 1024, seats: [2, 8], message: 4000,
@@ -79,11 +80,17 @@ export function validateDebateRequest(body, { adapters }) {
79
80
  if (o.budget != null) {
80
81
  if (typeof o.budget !== 'object' || Array.isArray(o.budget)) fail('budget', 'an object');
81
82
  options_.budget = {};
82
- for (const [vendor, cap] of Object.entries(o.budget)) {
83
+ for (const [key, cap] of Object.entries(o.budget)) {
84
+ // a bare vendor caps every seat of that vendor; `acp@profile` caps one AgentLink profile
85
+ const at = key.indexOf('@'), vendor = at < 0 ? key : key.slice(0, at), profile = at < 0 ? null : key.slice(at + 1);
83
86
  if (!adapters[vendor]) fail('budget', `unknown vendor ${vendor}`);
84
- const tokens = amount(cap?.tokens, `${vendor} token cap`), usd = amount(cap?.usd, `${vendor} dollar cap`);
87
+ if (profile != null) {
88
+ if (adapters[vendor].kind !== 'acp') fail('budget', `${adapters[vendor].label} takes one budget for all its seats; use "${vendor}"`);
89
+ try { agentLinkProfile(profile); } catch (e) { fail('budget', `${key}: ${e.message}`); }
90
+ }
91
+ const tokens = amount(cap?.tokens, `${key} token cap`), usd = amount(cap?.usd, `${key} dollar cap`);
85
92
  if (usd > 0 && !adapters[vendor].paths?.cost) fail('budget', `${adapters[vendor].label} does not report cost, so it cannot take a dollar cap`);
86
- options_.budget[vendor] = { ...(tokens != null ? { tokens } : {}), ...(usd != null ? { usd } : {}) };
93
+ options_.budget[key] = { ...(tokens != null ? { tokens } : {}), ...(usd != null ? { usd } : {}) };
87
94
  }
88
95
  }
89
96
  return { fieldNotes, seats: body.seats, chairman: body.chairman ?? null, options: options_ };