nexus-agents 2.151.0 → 2.152.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.
@@ -1,357 +0,0 @@
1
- import { z } from 'zod';
2
-
3
- /**
4
- * nexus-agents/config - Model Capabilities Type Definitions
5
- *
6
- * Zod schemas and TypeScript interfaces for the model capabilities matrix.
7
- * Defines output/input modalities, tool support, and special features
8
- * for each supported AI model.
9
- *
10
- * @module config/model-capabilities-types
11
- * (Source: Issue #683, Epic #682)
12
- */
13
-
14
- /** Output modalities a model can produce. */
15
- declare const OUTPUT_MODALITIES: readonly ["text", "image_png", "image_jpeg", "audio_pcm", "audio_wav", "audio_mp3", "video_mp4", "svg", "structured_json", "code"];
16
- type OutputModality = (typeof OUTPUT_MODALITIES)[number];
17
- /** Input modalities a model can accept. */
18
- declare const INPUT_MODALITIES: readonly ["text", "image", "audio", "video", "pdf", "code"];
19
- type InputModality = (typeof INPUT_MODALITIES)[number];
20
- /** Tool capabilities a model supports. */
21
- declare const TOOL_CAPABILITIES: readonly ["mcp", "function_calling", "computer_use", "code_execution_sandbox", "web_search", "file_operations", "structured_output", "apply_patch"];
22
- type ToolCapability = (typeof TOOL_CAPABILITIES)[number];
23
- /** Special features beyond standard text generation. */
24
- declare const SPECIAL_FEATURES: readonly ["extended_thinking", "deep_research", "streaming", "grounding", "citations", "image_editing", "voice_cloning", "live_api", "context_caching"];
25
- type SpecialFeature = (typeof SPECIAL_FEATURES)[number];
26
- /** CLI tool names supported by the routing system. */
27
- declare const CLI_NAMES: readonly ["claude", "gemini", "codex", "opencode"];
28
- type CliNameLiteral = (typeof CLI_NAMES)[number];
29
- /**
30
- * Canonical model id enum used for narrow `ModelId` typing and as the
31
- * argument to `z.enum(MODEL_IDS)` in `ModelCapabilitySchema`.
32
- *
33
- * This is a hand-maintained narrow tuple rather than a derived view
34
- * from `ModelRegistry` because the literal-union type is load-bearing:
35
- * — Zod schemas (`ModelCapabilitySchema.id`, `replacedBy`) need a
36
- * closed enum at compile time.
37
- * — Many function signatures across `src/` accept `ModelId` and rely
38
- * on the narrowed type for exhaustiveness.
39
- *
40
- * The runtime invariant — `MODEL_IDS` matches the in-tree registry
41
- * entries — is asserted by `model-ids-invariant.test.ts`. If you add
42
- * or remove a model in `DEFAULT_MODEL_CAPABILITIES.models`, you must
43
- * also update this list (and the test will tell you when they drift).
44
- *
45
- * Slice E of #2546 will collapse `model-capabilities.ts` itself; at
46
- * that point `MODEL_IDS` either moves to `model-config-helpers.ts` or
47
- * its consumers are loosened to `string`. This narrow type stays
48
- * until then.
49
- */
50
- declare const MODEL_IDS: readonly ["claude-opus", "claude-sonnet", "claude-haiku", "gemini-3-pro", "gemini-pro", "gemini-3-flash", "gemini-flash", "codex-5.3", "codex-5.2", "codex-5.1-mini", "opencode-default", "opencode-custom-opus", "opencode-custom-sonnet", "openrouter-nemotron-super", "openrouter-qwen-coder"];
51
- type ModelId = (typeof MODEL_IDS)[number];
52
- /** Quality scores for model capability routing (0-10 scale). */
53
- declare const QualityScoresSchema: z.ZodObject<{
54
- reasoning: z.ZodNumber;
55
- codeGeneration: z.ZodNumber;
56
- speed: z.ZodNumber;
57
- cost: z.ZodNumber;
58
- }, z.core.$strip>;
59
- type QualityScores = z.infer<typeof QualityScoresSchema>;
60
- /** Pricing information (USD per 1M tokens). */
61
- declare const PricingSchema: z.ZodObject<{
62
- inputPer1M: z.ZodNumber;
63
- outputPer1M: z.ZodNumber;
64
- }, z.core.$strip>;
65
- type Pricing = z.infer<typeof PricingSchema>;
66
-
67
- /**
68
- * decision-cost — per-DECISION cost aggregation over a governed panel's voters.
69
- *
70
- * Source: Issue #3855 (epic #3854 child, M4).
71
- *
72
- * A governed decision — a `consensus_vote` or `pr_review` run — fans out to N
73
- * voter calls; each voter is one LLM call. Per-CALL usage telemetry already
74
- * exists ({@link module:learning/usage-log} — token + cost per model call,
75
- * PR #2479/#2480 era). This module is the AGGREGATION layer that rolls those
76
- * per-call numbers UP into a single per-decision answer: "what did this
77
- * governed decision cost?".
78
- *
79
- * It is a PURE rollup (no I/O, no clock, no env reads at the math layer):
80
- * {@link rollupDecisionCost} takes the per-voter cost inputs + the billing mode
81
- * and returns a {@link DecisionCostSummary} — total tokens, total USD, a
82
- * per-voter breakdown, and a per-model breakdown. Persistence + the live
83
- * `process.env` billing-mode read live in the callers (the store + the tools),
84
- * mirroring the usage-log split between `computeCostUSD` (pure) and
85
- * `recordUsageEvent` (I/O).
86
- *
87
- * Design decisions that the fixture tests pin (#3855 acceptance criteria):
88
- *
89
- * - **Missing cost is UNMEASURED, not zero.** A voter with no token counts
90
- * (e.g. a CLI-subscription adapter that doesn't report usage, or an error
91
- * vote that never reached the model) is counted in `unmeasuredVoters` and
92
- * contributes 0 to the totals — but the summary records that the total is a
93
- * floor, not an exact figure (`measured` < `voterCount`). Treating unmeasured
94
- * as a true $0 would silently understate spend; this keeps the honesty.
95
- * - **Plan mode records 0-cost but keeps tokens.** Under `NEXUS_BILLING_MODE=plan`
96
- * the spend is pre-covered by a subscription, so cost is recorded as $0 while
97
- * token counts are preserved (so the operator can still see consumption and
98
- * a later `api`-mode reprice is possible). This mirrors how plan mode zeroes
99
- * cost in routing/scoring without dropping the token signal.
100
- *
101
- * @module observability/decision-cost
102
- */
103
-
104
- /** Billing mode in effect for a decision. Mirrors `NEXUS_BILLING_MODE`. */
105
- type DecisionBillingMode = 'plan' | 'api';
106
- /** Per-voter line in the decision rollup. */
107
- interface VoterCostBreakdown {
108
- readonly role: string;
109
- readonly model: string;
110
- readonly inputTokens: number;
111
- readonly outputTokens: number;
112
- readonly totalTokens: number;
113
- /** Effective cost after billing-mode application (0 in plan mode). */
114
- readonly costUsd: number;
115
- /**
116
- * True when this voter reported NO usage at all (no tokens, no cost). Its
117
- * zeros are placeholders, not a measured $0 / 0-token call.
118
- */
119
- readonly unmeasured: boolean;
120
- }
121
- /** Per-model rollup line within a single decision. */
122
- interface ModelCostBreakdown {
123
- readonly model: string;
124
- readonly voterCount: number;
125
- readonly inputTokens: number;
126
- readonly outputTokens: number;
127
- readonly totalTokens: number;
128
- readonly costUsd: number;
129
- }
130
- /**
131
- * The per-decision cost rollup. Totals are a FLOOR when `unmeasuredVoters > 0`
132
- * — read alongside `measuredVoters` / `voterCount` for the confidence.
133
- */
134
- interface DecisionCostSummary {
135
- /** Billing mode applied to produce `totalCostUsd` (and per-line `costUsd`). */
136
- readonly billingMode: DecisionBillingMode;
137
- /** Total voters folded into this decision. */
138
- readonly voterCount: number;
139
- /** Voters that reported usage (tokens and/or cost). */
140
- readonly measuredVoters: number;
141
- /** Voters that reported no usage at all (counted, not zeroed-as-fact). */
142
- readonly unmeasuredVoters: number;
143
- readonly totalInputTokens: number;
144
- readonly totalOutputTokens: number;
145
- readonly totalTokens: number;
146
- /**
147
- * Total cost in USD. 0 under `plan` mode by construction. A FLOOR when
148
- * `unmeasuredVoters > 0` (unmeasured voters contribute 0, not their unknown
149
- * real cost).
150
- */
151
- readonly totalCostUsd: number;
152
- /** Per-voter breakdown, in input order. */
153
- readonly perVoter: readonly VoterCostBreakdown[];
154
- /** Per-model breakdown, sorted by total cost desc then total tokens desc. */
155
- readonly perModel: readonly ModelCostBreakdown[];
156
- }
157
-
158
- /**
159
- * Types, schemas, and response helpers for the consensus_vote MCP tool.
160
- * Extracted from consensus-vote.ts for file size compliance (Issue #708).
161
- *
162
- * @module mcp/tools/consensus-vote-types
163
- */
164
-
165
- /**
166
- * Available consensus voting strategies.
167
- *
168
- * - `simple_majority`: Standard majority voting (>50%)
169
- * - `supermajority`: Requires >=67% approval
170
- * - `unanimous`: Requires 100% approval
171
- * - `proof_of_learning`: Weighted by agent performance (Issue #103)
172
- * - `higher_order`: Bayesian-optimal with correlation awareness (Issue #514)
173
- * - `opinion_wise`: Alias for higher_order (Issue #333)
174
- */
175
- type VotingStrategy = 'simple_majority' | 'supermajority' | 'unanimous' | 'proof_of_learning' | 'higher_order' | 'opinion_wise';
176
- /**
177
- * How error-source votes (timed-out or crashed voters) are counted toward
178
- * the threshold (#2630).
179
- *
180
- * - `reduce_denominator` (default for non-strict strategies): errors are
181
- * filtered out before the engine sees votes — denominator = non-error
182
- * votes. Best for operational decisions where you trust the responding
183
- * voters and infrastructure flake should not block the vote.
184
- * - `count_as_abstain`: error votes reach the engine as abstain. Behaves
185
- * conservatively — a timed-out voter effectively withholds approval
186
- * relative to the threshold. Use when you can't tell what the error
187
- * voter would have decided and want the math to reflect uncertainty.
188
- * - `fail_closed` (default for unanimous / higher_order): any error voids
189
- * the vote. Threshold math is not run. Use for security-critical or
190
- * breaking-change decisions where every voter must be heard.
191
- * - `absolute_quorum` (opt-in, #4132): an errored voter DEGRADES the panel
192
- * verdict to `no_quorum` instead of being silently dropped from the
193
- * denominator. Unlike `fail_closed` (which reports a rejection-flavored void),
194
- * `absolute_quorum` reports `no_quorum` — a recoverable "re-run the missing
195
- * voice" state that never manufactures `approved` NOR `rejected` from an
196
- * induced error. An approval requires ZERO errors, the contrarian (catfish)
197
- * present and non-error (unless quick-mode drops it), and an ABSOLUTE approval
198
- * count (`ceil(fraction * panelSize)` over the full requested panel — not just
199
- * a majority of the responders). A genuine reject (zero errors) still blocks.
200
- * The anti-DoS point: a voter you can knock offline can only ever force a
201
- * re-run, never flip the verdict.
202
- *
203
- * Regardless of policy, a hard floor applies: when errors exceed 50% of
204
- * total voters, the vote always fails. Catches "all CLIs are down" — a
205
- * 2-voter consensus is not a real consensus.
206
- */
207
- declare const ErrorPolicySchema: z.ZodEnum<{
208
- reduce_denominator: "reduce_denominator";
209
- count_as_abstain: "count_as_abstain";
210
- fail_closed: "fail_closed";
211
- absolute_quorum: "absolute_quorum";
212
- }>;
213
- type ErrorPolicy = z.infer<typeof ErrorPolicySchema>;
214
- /**
215
- * Threshold values accepted by the `--threshold` CLI flag and the
216
- * \`threshold\` MCP input field (#2638 — single source of truth).
217
- *
218
- * Maps to consensus algorithms via:
219
- * `majority → simple_majority`, `supermajority → supermajority`, `unanimous → unanimous`.
220
- *
221
- * Used as the canonical Zod schema for CLI parsing
222
- * (`cli.ts:parseThreshold`), validation (`cli-commands-validators.ts:isValidThreshold`),
223
- * and the `ConsensusVoteInputSchema.threshold` field.
224
- */
225
- declare const VoteThresholdSchema: z.ZodEnum<{
226
- supermajority: "supermajority";
227
- unanimous: "unanimous";
228
- majority: "majority";
229
- }>;
230
- type VoteThreshold = z.infer<typeof VoteThresholdSchema>;
231
- declare const ConsensusVoteInputSchema: z.ZodObject<{
232
- proposal: z.ZodString;
233
- threshold: z.ZodOptional<z.ZodEnum<{
234
- supermajority: "supermajority";
235
- unanimous: "unanimous";
236
- majority: "majority";
237
- }>>;
238
- strategy: z.ZodOptional<z.ZodEnum<{
239
- simple_majority: "simple_majority";
240
- supermajority: "supermajority";
241
- unanimous: "unanimous";
242
- proof_of_learning: "proof_of_learning";
243
- opinion_wise: "opinion_wise";
244
- higher_order: "higher_order";
245
- }>>;
246
- errorPolicy: z.ZodOptional<z.ZodEnum<{
247
- reduce_denominator: "reduce_denominator";
248
- count_as_abstain: "count_as_abstain";
249
- fail_closed: "fail_closed";
250
- absolute_quorum: "absolute_quorum";
251
- }>>;
252
- quickMode: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
253
- simulateVotes: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
254
- mode: z.ZodOptional<z.ZodEnum<{
255
- async: "async";
256
- sync: "sync";
257
- }>>;
258
- idempotencyKey: z.ZodOptional<z.ZodString>;
259
- ratifies: z.ZodOptional<z.ZodString>;
260
- }, z.core.$strip>;
261
- type ConsensusVoteInput = z.infer<typeof ConsensusVoteInputSchema>;
262
- interface AgentVoteSummary {
263
- role: string;
264
- decision: 'approve' | 'reject' | 'abstain';
265
- confidence: number;
266
- reasoning: string;
267
- simulated: boolean;
268
- /** True when this vote was generated from an error (Issue #815). */
269
- error: boolean;
270
- /** Model used for this agent's vote (Issue #817). */
271
- modelUsed?: string;
272
- /** Structured rejection categories for reject→refine→re-vote loops (Issue #1213). */
273
- rejectionCategories?: readonly string[];
274
- }
275
- /**
276
- * Canonical set of decision statuses a vote response can carry. Single source
277
- * of truth: the `consensus_vote` MCP `outputSchema` reuses
278
- * {@link VoteDecisionStatusSchema} so the advertised enum can never be narrower
279
- * than what {@link buildResponse} emits (all five are reachable —
280
- * `no_quorum` on an all-error/no-quorum panel, the rest via
281
- * {@link mapOutcomeToDecision}). A narrower schema made strict MCP clients
282
- * reject `timeout`/`pending` votes with a `-32602`-class error (#4032).
283
- */
284
- declare const VoteDecisionStatusSchema: z.ZodEnum<{
285
- timeout: "timeout";
286
- rejected: "rejected";
287
- pending: "pending";
288
- approved: "approved";
289
- no_quorum: "no_quorum";
290
- }>;
291
- type VoteDecisionStatus = z.infer<typeof VoteDecisionStatusSchema>;
292
- /** Higher-Order Voting metadata (Issue #514). */
293
- interface HigherOrderMetadata {
294
- posteriorApproval: number;
295
- posteriorRejection: number;
296
- effectiveVoteCount: number;
297
- method: 'ow' | 'isp' | 'simple';
298
- usedCorrelationData: boolean;
299
- improvementOverBaseline: number;
300
- downweightedAgents: readonly string[];
301
- reasoning: string;
302
- }
303
- interface ConsensusVoteResponse {
304
- proposal: string;
305
- threshold?: VoteThreshold;
306
- strategy: VotingStrategy;
307
- decision: VoteDecisionStatus;
308
- approvalPercentage: number;
309
- voteCounts: {
310
- approve: number;
311
- reject: number;
312
- abstain: number;
313
- error: number;
314
- };
315
- votes: AgentVoteSummary[];
316
- durationMs: number;
317
- simulateVotes: boolean;
318
- higherOrderMetadata?: HigherOrderMetadata;
319
- /**
320
- * Set when an error policy short-circuited the vote (#2630/#3124). Explains a
321
- * `rejected` decision that may coexist with a high `approvalPercentage` — e.g.
322
- * `fail_closed: 1 voter(s) errored`. Absent on normally-tallied votes.
323
- */
324
- policyReason?: string;
325
- /**
326
- * Set when the panel was DEGRADED (#3587): some voters errored, so the
327
- * decision rests on fewer than the requested number of voters. Surfaces a
328
- * silently-shrunk panel so the result isn't read as a full-strength consensus.
329
- * Absent when every requested voter returned a real vote.
330
- */
331
- panelWarning?: string;
332
- /**
333
- * Per-decision cost rollup (#3855): per-voter / per-model token + USD totals
334
- * for this governed decision. Rides the existing response — no new MCP tool.
335
- * Totals are a floor when `costSummary.unmeasuredVoters > 0` (voters whose
336
- * adapter reported no usage are counted as unmeasured, not a measured $0).
337
- */
338
- costSummary?: DecisionCostSummary;
339
- /**
340
- * #3991: whether the authentic vote record (#3897) was persisted at vote time.
341
- * Post-#3991 the runtime ledger routes through `nexusDataPath` under
342
- * `governance/`, so a writable `.nexus-agents/governance/` location almost
343
- * always exists and `true` is the normal case. `false` means the persist was
344
- * skipped (all votes simulated) or the write failed (data dir unwritable) —
345
- * see {@link voteRecordNote}. Surfaces to the MCP caller what was previously
346
- * only a server-side WARN.
347
- */
348
- voteRecordPersisted: boolean;
349
- /**
350
- * #3991: present only when {@link voteRecordPersisted} is `false` — the
351
- * actionable reason the record was not written (e.g. the data dir is unwritable
352
- * → fix permissions or set `NEXUS_VOTE_RECORDS_PATH` to a writable path).
353
- */
354
- voteRecordNote?: string;
355
- }
356
-
357
- export { type AgentVoteSummary as A, type CliNameLiteral as C, type DecisionCostSummary as D, type ErrorPolicy as E, type InputModality as I, type ModelId as M, type OutputModality as O, type Pricing as P, type QualityScores as Q, type SpecialFeature as S, type ToolCapability as T, type VotingStrategy as V, type ConsensusVoteInput as a, ConsensusVoteInputSchema as b, type ConsensusVoteResponse as c, type VoteDecisionStatus as d, type VoteThreshold as e };