reasonix 0.0.3 → 0.0.5
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 +133 -58
- package/dist/cli/index.js +811 -57
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +108 -6
- package/dist/index.js +487 -23
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-Y7L6L5QS.js +0 -262
- package/dist/chunk-Y7L6L5QS.js.map +0 -1
- package/dist/cli/chunk-T2ODXAJP.js +0 -263
- package/dist/cli/chunk-T2ODXAJP.js.map +0 -1
- package/dist/cli/client-RIVGDOJP.js +0 -10
- package/dist/cli/client-RIVGDOJP.js.map +0 -1
- package/dist/client-KEA2D52Q.js +0 -9
- package/dist/client-KEA2D52Q.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -172,6 +172,58 @@ declare function emptyPlanState(): TypedPlanState;
|
|
|
172
172
|
declare function isPlanStateEmpty(s: TypedPlanState | null | undefined): boolean;
|
|
173
173
|
declare function harvest(reasoningContent: string | null | undefined, client?: DeepSeekClient, options?: HarvestOptions): Promise<TypedPlanState>;
|
|
174
174
|
|
|
175
|
+
/**
|
|
176
|
+
* Self-consistency branching.
|
|
177
|
+
*
|
|
178
|
+
* When enabled, the loop fans out into N parallel samples per turn (varied
|
|
179
|
+
* temperatures), runs Pillar 2 harvest on each, and selects the sample with
|
|
180
|
+
* the fewest flagged uncertainties (ties broken by answer length — a crude
|
|
181
|
+
* Occam prior).
|
|
182
|
+
*
|
|
183
|
+
* The unique opportunity here: because DeepSeek is ~20× cheaper than Claude,
|
|
184
|
+
* running N=3–5 samples per turn is still cheaper than a single Claude call,
|
|
185
|
+
* while the majority-confidence selection tends to dominate single-sample
|
|
186
|
+
* answers on fuzzy multi-step reasoning tasks.
|
|
187
|
+
*/
|
|
188
|
+
|
|
189
|
+
interface BranchSample {
|
|
190
|
+
index: number;
|
|
191
|
+
temperature: number;
|
|
192
|
+
response: ChatResponse;
|
|
193
|
+
planState: TypedPlanState;
|
|
194
|
+
}
|
|
195
|
+
type BranchSelector = (samples: BranchSample[]) => BranchSample;
|
|
196
|
+
interface BranchOptions {
|
|
197
|
+
/** Number of parallel samples. 1 disables branching. Default 1. */
|
|
198
|
+
budget?: number;
|
|
199
|
+
/** Temperatures for each branch. Default spreads across [0, 1]. */
|
|
200
|
+
temperatures?: readonly number[];
|
|
201
|
+
/** Harvest options; the selector needs harvest to score samples. */
|
|
202
|
+
harvestOptions?: HarvestOptions;
|
|
203
|
+
/** Custom selector. Default: min uncertainties, tie-break shortest answer. */
|
|
204
|
+
selector?: BranchSelector;
|
|
205
|
+
/**
|
|
206
|
+
* Fires as each sample finishes (main call + harvest both complete).
|
|
207
|
+
* Useful for progress UI. Not awaited; exceptions are swallowed.
|
|
208
|
+
*/
|
|
209
|
+
onSampleDone?: (sample: BranchSample) => void;
|
|
210
|
+
}
|
|
211
|
+
interface BranchResult {
|
|
212
|
+
chosen: BranchSample;
|
|
213
|
+
samples: BranchSample[];
|
|
214
|
+
}
|
|
215
|
+
/** Default: fewest uncertainties wins, ties broken by shorter answer content. */
|
|
216
|
+
declare const defaultSelector: BranchSelector;
|
|
217
|
+
declare function runBranches(client: DeepSeekClient, request: ChatRequestOptions, opts?: BranchOptions): Promise<BranchResult>;
|
|
218
|
+
/** Sum usage across branch samples for telemetry purposes. */
|
|
219
|
+
declare function aggregateBranchUsage(samples: readonly BranchSample[]): {
|
|
220
|
+
promptTokens: number;
|
|
221
|
+
completionTokens: number;
|
|
222
|
+
totalTokens: number;
|
|
223
|
+
promptCacheHitTokens: number;
|
|
224
|
+
promptCacheMissTokens: number;
|
|
225
|
+
};
|
|
226
|
+
|
|
175
227
|
interface ImmutablePrefixOptions {
|
|
176
228
|
system: string;
|
|
177
229
|
toolSpecs?: readonly ToolSpec[];
|
|
@@ -342,17 +394,42 @@ interface ToolDefinition<A = any, R = any> {
|
|
|
342
394
|
parameters?: JSONSchema;
|
|
343
395
|
fn: (args: A) => R | Promise<R>;
|
|
344
396
|
}
|
|
397
|
+
interface ToolRegistryOptions {
|
|
398
|
+
/**
|
|
399
|
+
* Auto-flatten schemas that exceed depth/width thresholds before sending
|
|
400
|
+
* them to the model. Re-nests arguments transparently on dispatch.
|
|
401
|
+
* Default: true. Pass false to opt out.
|
|
402
|
+
*/
|
|
403
|
+
autoFlatten?: boolean;
|
|
404
|
+
}
|
|
345
405
|
declare class ToolRegistry {
|
|
346
406
|
private readonly _tools;
|
|
407
|
+
private readonly _autoFlatten;
|
|
408
|
+
constructor(opts?: ToolRegistryOptions);
|
|
347
409
|
register<A, R>(def: ToolDefinition<A, R>): this;
|
|
348
410
|
has(name: string): boolean;
|
|
349
411
|
get(name: string): ToolDefinition | undefined;
|
|
350
412
|
get size(): number;
|
|
413
|
+
/** True if a registered tool's schema was flattened for the model. */
|
|
414
|
+
wasFlattened(name: string): boolean;
|
|
351
415
|
specs(): ToolSpec[];
|
|
352
416
|
dispatch(name: string, argumentsRaw: string | Record<string, unknown>): Promise<string>;
|
|
353
417
|
}
|
|
354
418
|
|
|
355
|
-
type EventRole = "assistant_delta" | "assistant_final" | "tool" | "done" | "error";
|
|
419
|
+
type EventRole = "assistant_delta" | "assistant_final" | "tool" | "done" | "error" | "branch_start" | "branch_progress" | "branch_done";
|
|
420
|
+
interface BranchSummary {
|
|
421
|
+
budget: number;
|
|
422
|
+
chosenIndex: number;
|
|
423
|
+
uncertainties: number[];
|
|
424
|
+
temperatures: number[];
|
|
425
|
+
}
|
|
426
|
+
interface BranchProgress {
|
|
427
|
+
completed: number;
|
|
428
|
+
total: number;
|
|
429
|
+
latestIndex: number;
|
|
430
|
+
latestTemperature: number;
|
|
431
|
+
latestUncertainties: number;
|
|
432
|
+
}
|
|
356
433
|
interface LoopEvent {
|
|
357
434
|
turn: number;
|
|
358
435
|
role: EventRole;
|
|
@@ -362,6 +439,8 @@ interface LoopEvent {
|
|
|
362
439
|
stats?: TurnStats;
|
|
363
440
|
planState?: TypedPlanState;
|
|
364
441
|
repair?: RepairReport;
|
|
442
|
+
branch?: BranchSummary;
|
|
443
|
+
branchProgress?: BranchProgress;
|
|
365
444
|
error?: string;
|
|
366
445
|
}
|
|
367
446
|
interface CacheFirstLoopOptions {
|
|
@@ -377,6 +456,13 @@ interface CacheFirstLoopOptions {
|
|
|
377
456
|
* cheap but non-zero V3 call per turn).
|
|
378
457
|
*/
|
|
379
458
|
harvest?: boolean | HarvestOptions;
|
|
459
|
+
/**
|
|
460
|
+
* Self-consistency branching. Pass a number for just a budget (e.g. 3) or
|
|
461
|
+
* a full `BranchOptions` object. Disables streaming for the branched turn
|
|
462
|
+
* because all samples must complete before selection. Auto-enables harvest
|
|
463
|
+
* since the default selector scores samples by plan-state uncertainty.
|
|
464
|
+
*/
|
|
465
|
+
branch?: number | BranchOptions;
|
|
380
466
|
}
|
|
381
467
|
/**
|
|
382
468
|
* Pillar 1 — Cache-First Loop.
|
|
@@ -387,21 +473,37 @@ interface CacheFirstLoopOptions {
|
|
|
387
473
|
*
|
|
388
474
|
* Yields a stream of events so a TUI can render progressively.
|
|
389
475
|
*/
|
|
476
|
+
interface ReconfigurableOptions {
|
|
477
|
+
model?: string;
|
|
478
|
+
harvest?: boolean | HarvestOptions;
|
|
479
|
+
branch?: number | BranchOptions;
|
|
480
|
+
stream?: boolean;
|
|
481
|
+
}
|
|
390
482
|
declare class CacheFirstLoop {
|
|
391
483
|
readonly client: DeepSeekClient;
|
|
392
484
|
readonly prefix: ImmutablePrefix;
|
|
393
485
|
readonly tools: ToolRegistry;
|
|
394
|
-
readonly model: string;
|
|
395
486
|
readonly maxToolIters: number;
|
|
396
|
-
readonly stream: boolean;
|
|
397
|
-
readonly harvestEnabled: boolean;
|
|
398
|
-
readonly harvestOptions: HarvestOptions;
|
|
399
487
|
readonly log: AppendOnlyLog;
|
|
400
488
|
readonly scratch: VolatileScratch;
|
|
401
489
|
readonly stats: SessionStats;
|
|
402
490
|
readonly repair: ToolCallRepair;
|
|
491
|
+
model: string;
|
|
492
|
+
stream: boolean;
|
|
493
|
+
harvestEnabled: boolean;
|
|
494
|
+
harvestOptions: HarvestOptions;
|
|
495
|
+
branchEnabled: boolean;
|
|
496
|
+
branchOptions: BranchOptions;
|
|
403
497
|
private _turn;
|
|
498
|
+
private _streamPreference;
|
|
404
499
|
constructor(opts: CacheFirstLoopOptions);
|
|
500
|
+
/**
|
|
501
|
+
* Reconfigure model/harvest/branch/stream mid-session. The loop's log,
|
|
502
|
+
* scratch, and stats are preserved — only the per-turn behavior changes.
|
|
503
|
+
* Used by the TUI's slash commands and by library callers who want to
|
|
504
|
+
* flip a knob between turns.
|
|
505
|
+
*/
|
|
506
|
+
configure(opts: ReconfigurableOptions): void;
|
|
405
507
|
private buildMessages;
|
|
406
508
|
step(userInput: string): AsyncGenerator<LoopEvent>;
|
|
407
509
|
run(userInput: string, onEvent?: (ev: LoopEvent) => void): Promise<string>;
|
|
@@ -446,4 +548,4 @@ declare function redactKey(key: string): string;
|
|
|
446
548
|
|
|
447
549
|
declare const VERSION = "0.0.1";
|
|
448
550
|
|
|
449
|
-
export { AppendOnlyLog, CacheFirstLoop, type CacheFirstLoopOptions, type ChatMessage, type ChatResponse, DeepSeekClient, type DeepSeekClientOptions, type EventRole, type FlattenDecision, type HarvestOptions, ImmutablePrefix, type ImmutablePrefixOptions, type JSONSchema, type LoopEvent, type ReasonixConfig, type RepairReport, type RetryInfo, type RetryOptions, type Role, type ScavengeOptions, type ScavengeResult, SessionStats, type SessionSummary, StormBreaker, type StreamChunk, type ToolCall, ToolCallRepair, type ToolCallRepairOptions, type ToolDefinition, type ToolFunctionSpec, ToolRegistry, type ToolSpec, type TruncationRepairResult, type TurnStats, type TypedPlanState, Usage, VERSION, VolatileScratch, analyzeSchema, claudeEquivalentCost, costUsd, defaultConfigPath, emptyPlanState, fetchWithRetry, flattenSchema, harvest, isPlanStateEmpty, isPlausibleKey, loadApiKey, loadDotenv, nestArguments, readConfig, redactKey, repairTruncatedJson, saveApiKey, scavengeToolCalls, writeConfig };
|
|
551
|
+
export { AppendOnlyLog, type BranchOptions, type BranchProgress, type BranchResult, type BranchSample, type BranchSelector, type BranchSummary, CacheFirstLoop, type CacheFirstLoopOptions, type ChatMessage, type ChatResponse, DeepSeekClient, type DeepSeekClientOptions, type EventRole, type FlattenDecision, type HarvestOptions, ImmutablePrefix, type ImmutablePrefixOptions, type JSONSchema, type LoopEvent, type ReasonixConfig, type ReconfigurableOptions, type RepairReport, type RetryInfo, type RetryOptions, type Role, type ScavengeOptions, type ScavengeResult, SessionStats, type SessionSummary, StormBreaker, type StreamChunk, type ToolCall, ToolCallRepair, type ToolCallRepairOptions, type ToolDefinition, type ToolFunctionSpec, ToolRegistry, type ToolSpec, type TruncationRepairResult, type TurnStats, type TypedPlanState, Usage, VERSION, VolatileScratch, aggregateBranchUsage, analyzeSchema, claudeEquivalentCost, costUsd, defaultConfigPath, defaultSelector, emptyPlanState, fetchWithRetry, flattenSchema, harvest, isPlanStateEmpty, isPlausibleKey, loadApiKey, loadDotenv, nestArguments, readConfig, redactKey, repairTruncatedJson, runBranches, saveApiKey, scavengeToolCalls, writeConfig };
|