@orkestrel/agent 0.0.26 → 0.0.28
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/dist/src/core/index.cjs +766 -36
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +670 -7
- package/dist/src/core/index.d.ts +670 -7
- package/dist/src/core/index.js +750 -39
- package/dist/src/core/index.js.map +1 -1
- package/package.json +7 -7
package/dist/src/core/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type { EmitterErrorHandler } from '@orkestrel/emitter';
|
|
|
9
9
|
import type { EmitterHooks } from '@orkestrel/emitter';
|
|
10
10
|
import type { EmitterInterface } from '@orkestrel/emitter';
|
|
11
11
|
import type { FileInterface } from '@orkestrel/workspace';
|
|
12
|
+
import type { JSONRecord } from '@orkestrel/contract';
|
|
12
13
|
import { JSONShape } from '@orkestrel/contract';
|
|
13
14
|
import { JSONValue } from '@orkestrel/contract';
|
|
14
15
|
import { LiteralShape } from '@orkestrel/contract';
|
|
@@ -445,7 +446,12 @@ export declare type AgentEventMap = {
|
|
|
445
446
|
readonly tool: readonly [call: ToolCall, result: ToolResult];
|
|
446
447
|
/** Reports a turn's {@link TokenUsage} — emitted after a usage-bearing provider call. */
|
|
447
448
|
readonly usage: readonly [usage: TokenUsage];
|
|
448
|
-
/**
|
|
449
|
+
/**
|
|
450
|
+
* Reports a call denied by scope or authority, before dispatch.
|
|
451
|
+
* A turn advertising no tools drops each call with `no tool is advertised in the active scope`.
|
|
452
|
+
* Otherwise a call excluded by the tool allow-list carries `<tool name> is not in the active scope` and
|
|
453
|
+
* produces a denial tool result and message. Authority evaluates only admitted calls.
|
|
454
|
+
*/
|
|
449
455
|
readonly deny: readonly [call: ToolCall, reason: string | undefined];
|
|
450
456
|
/** Reports the run settled successfully (a natural finish or a cancel's partial) — the {@link AgentResult}. */
|
|
451
457
|
readonly finish: readonly [result: AgentResult];
|
|
@@ -624,6 +630,99 @@ export declare interface AgentJobInput {
|
|
|
624
630
|
readonly children?: readonly AgentJobInput[];
|
|
625
631
|
}
|
|
626
632
|
|
|
633
|
+
/**
|
|
634
|
+
* Implements the bounded HTTP calls, validation, and result merging of a judge behind concrete
|
|
635
|
+
* wire seams.
|
|
636
|
+
*
|
|
637
|
+
* @remarks
|
|
638
|
+
* A subclass fills `name`, `body`, and `read`; the constructor takes the `batch` switch that
|
|
639
|
+
* decides whether one call carries every question or each question gets its own call in key
|
|
640
|
+
* order. `ask` validates the request before any call, builds every body before the first call so
|
|
641
|
+
* a wire limit refuses the request before inference, and runs the calls one after another, each
|
|
642
|
+
* under its own deadline folded with the caller's signal. A cancel throws a `JudgeAbortError`
|
|
643
|
+
* whose `partial` merges the calls that completed. A transport error reaches the caller unchanged.
|
|
644
|
+
*
|
|
645
|
+
* @example Writing a judge wire
|
|
646
|
+
* ```ts
|
|
647
|
+
* import type { JudgeRequest, JudgeResult } from '@orkestrel/agent'
|
|
648
|
+
* import { AgentJudge, JudgeError } from '@orkestrel/agent'
|
|
649
|
+
* import { isFiniteNumber, isRecord } from '@orkestrel/contract'
|
|
650
|
+
*
|
|
651
|
+
* // A wire whose server answers one yes/no question per call as { "yes": 0.93 }.
|
|
652
|
+
* class YesJudge extends AgentJudge {
|
|
653
|
+
* readonly name = 'yes'
|
|
654
|
+
* body(request: JudgeRequest): object {
|
|
655
|
+
* return { model: this.model, state: request.state, questions: request.questions }
|
|
656
|
+
* }
|
|
657
|
+
* read(value: unknown, request: JudgeRequest): JudgeResult {
|
|
658
|
+
* const [id] = Object.keys(request.questions)
|
|
659
|
+
* if (id === undefined || !isRecord(value) || !isFiniteNumber(value.yes)) {
|
|
660
|
+
* throw new JudgeError('PROTOCOL', 'judge error: unreadable answer')
|
|
661
|
+
* }
|
|
662
|
+
* return { model: this.model, answers: { [id]: { form: 'noul', noul: value.yes } } }
|
|
663
|
+
* }
|
|
664
|
+
* }
|
|
665
|
+
*
|
|
666
|
+
* const judge = new YesJudge({
|
|
667
|
+
* url: 'http://localhost:8010',
|
|
668
|
+
* path: '/v1/yes',
|
|
669
|
+
* model: 'yes-1',
|
|
670
|
+
* batch: false,
|
|
671
|
+
* })
|
|
672
|
+
* ```
|
|
673
|
+
*/
|
|
674
|
+
export declare abstract class AgentJudge implements AgentJudgeInterface {
|
|
675
|
+
#private;
|
|
676
|
+
constructor(input: AgentJudgeInput);
|
|
677
|
+
/** Identifies the concrete wire. */
|
|
678
|
+
abstract readonly name: string;
|
|
679
|
+
/** Exposes the instance's minted UUID. */
|
|
680
|
+
get id(): string;
|
|
681
|
+
/** Exposes the configured model identity. */
|
|
682
|
+
get model(): string;
|
|
683
|
+
/** Projects one call's request onto the concrete protocol's wire body. */
|
|
684
|
+
abstract body(request: JudgeRequest): object;
|
|
685
|
+
/** Decodes one call's parsed response body into the answers for that call's questions. */
|
|
686
|
+
abstract read(value: unknown, request: JudgeRequest): JudgeResult;
|
|
687
|
+
/**
|
|
688
|
+
* Asks every question of the request about its state and merges the answers of every call.
|
|
689
|
+
*
|
|
690
|
+
* @param request - The state and the questions keyed by caller id
|
|
691
|
+
* @param signal - The caller's cancellation bound
|
|
692
|
+
* @returns The merged answers, refusals, and usage of every call
|
|
693
|
+
* @throws JudgeAbortError Thrown when the caller's signal or a call's deadline fires, carrying
|
|
694
|
+
* the merged result of the completed calls
|
|
695
|
+
* @throws JudgeError Thrown with code `QUESTION` for an empty question map, a malformed question
|
|
696
|
+
* or state, or a wire refusal before any call; with code `HTTP` for a non-OK response; and with
|
|
697
|
+
* code `PROTOCOL` for a missing or unparsable response body
|
|
698
|
+
*/
|
|
699
|
+
ask(request: JudgeRequest, signal: AbortSignal): Promise<JudgeResult>;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
/**
|
|
703
|
+
* Configures the judge engine's destination, identity, and call split.
|
|
704
|
+
*
|
|
705
|
+
* @remarks
|
|
706
|
+
* `path` appends to `url`. `model` is the identity the judge reports when a response names none.
|
|
707
|
+
* `timeout`, `fetch`, and `headers` bound, carry, and authenticate each call as they do for a
|
|
708
|
+
* provider; the deadline applies to each call on its own.
|
|
709
|
+
*/
|
|
710
|
+
export declare interface AgentJudgeInput extends Pick<ProviderOptions, 'timeout' | 'fetch' | 'headers'> {
|
|
711
|
+
readonly url: string;
|
|
712
|
+
readonly path?: string;
|
|
713
|
+
readonly model: string;
|
|
714
|
+
/** If true, one call carries every question; if false, the engine issues one call per question. Default: true. */
|
|
715
|
+
readonly batch?: boolean;
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
/** Defines the wire seams of the shared judge engine. */
|
|
719
|
+
export declare interface AgentJudgeInterface extends JudgeInterface {
|
|
720
|
+
/** Projects one call's request onto the concrete protocol's serializable body. */
|
|
721
|
+
body(request: JudgeRequest): object;
|
|
722
|
+
/** Decodes one call's parsed response body into the answers for that call's questions. */
|
|
723
|
+
read(value: unknown, request: JudgeRequest): JudgeResult;
|
|
724
|
+
}
|
|
725
|
+
|
|
627
726
|
/**
|
|
628
727
|
* Configures `createAgent` — the loop's bounds and pacing, the reserved `on` hooks, the
|
|
629
728
|
* construction-time context wiring (`instructions` / `workspaces` / `scope`), the `conversations`
|
|
@@ -667,7 +766,7 @@ export declare interface AgentJobInput {
|
|
|
667
766
|
* - `workspaces` — an optional pre-built {@link WorkspaceManagerInterface} forwarded to the
|
|
668
767
|
* agent's context; a fresh empty one is created when omitted (mirrors {@link AgentContextOptions.workspaces}).
|
|
669
768
|
* - `scope` — an optional initial active {@link ScopeInterface} forwarded to the agent's context
|
|
670
|
-
* (the
|
|
769
|
+
* (the context and tool-dispatch filter); `undefined` ⇒ every registered tool is admitted.
|
|
671
770
|
* - `on` — the reserved {@link EmitterHooks} key: initial listeners for the agent's
|
|
672
771
|
* {@link AgentEventMap}, wired at construction (for example `{ finish: (r) => log(r) }`).
|
|
673
772
|
*/
|
|
@@ -682,7 +781,16 @@ export declare interface AgentOptions {
|
|
|
682
781
|
readonly instructions?: InstructionManagerInterface;
|
|
683
782
|
/** Reuses a pre-built workspace registry forwarded to the agent's context; a fresh empty one is created when omitted. */
|
|
684
783
|
readonly workspaces?: WorkspaceManagerInterface;
|
|
685
|
-
/**
|
|
784
|
+
/**
|
|
785
|
+
* Sets the initial active scope; `undefined` admits every registered tool.
|
|
786
|
+
* Each turn snapshots the scope's tool allow-list before advertising and checks calls
|
|
787
|
+
* against that list before applying authority. An absent list also admits unknown names
|
|
788
|
+
* to authority and the registry, which returns its tool-not-found failure.
|
|
789
|
+
* A reply to a turn advertising no tools ends the run as its answer, records an assistant
|
|
790
|
+
* message without calls, and emits a `deny` event for every dropped call without marking it partial.
|
|
791
|
+
* Other scoped-out calls produce denial tool results and messages, and the loop continues.
|
|
792
|
+
* Changing the context scope through the `apply` method takes effect on the next turn.
|
|
793
|
+
*/
|
|
686
794
|
readonly scope?: ScopeInterface;
|
|
687
795
|
/** Caps the tool-iteration turns before the loop stops; defaults to `DEFAULT_AGENT_LIMIT`. */
|
|
688
796
|
readonly limit?: number;
|
|
@@ -695,11 +803,11 @@ export declare interface AgentOptions {
|
|
|
695
803
|
/** Carries an external cancel; its abort commits a partial result. */
|
|
696
804
|
readonly signal?: AbortSignal;
|
|
697
805
|
/**
|
|
698
|
-
* Holds an optional policy gate consulted
|
|
806
|
+
* Holds an optional policy gate consulted after scope admits a tool call — a denied call is
|
|
699
807
|
* fed back to the model as a denial {@link ToolResult} (a `tool` chunk + a tool
|
|
700
808
|
* message) rather than executed (no tool run, no budget cost), so the model sees the
|
|
701
|
-
* denial and can react; an allowed call dispatches normally. Omitted ⇒ every call
|
|
702
|
-
* dispatches
|
|
809
|
+
* denial and can react; an allowed call dispatches normally. Omitted ⇒ every admitted call
|
|
810
|
+
* dispatches through the registry.
|
|
703
811
|
*/
|
|
704
812
|
readonly authority?: AuthorityInterface;
|
|
705
813
|
/**
|
|
@@ -1044,6 +1152,11 @@ export declare interface AgentResult {
|
|
|
1044
1152
|
readonly thinking?: string;
|
|
1045
1153
|
/** Holds the summed {@link TokenUsage} across the turn's provider calls (present when any reported it). */
|
|
1046
1154
|
readonly usage?: TokenUsage;
|
|
1155
|
+
/**
|
|
1156
|
+
* Reports cancellation or a turn limit reached with unresolved tool intent.
|
|
1157
|
+
* A reply to a turn advertising no tools is a complete answer (`false`), even if it
|
|
1158
|
+
* contains calls: those calls are dropped and observed through the `deny` event.
|
|
1159
|
+
*/
|
|
1047
1160
|
readonly partial: boolean;
|
|
1048
1161
|
}
|
|
1049
1162
|
|
|
@@ -1350,6 +1463,31 @@ export declare interface AuthorityRule {
|
|
|
1350
1463
|
readonly reason?: string;
|
|
1351
1464
|
}
|
|
1352
1465
|
|
|
1466
|
+
/**
|
|
1467
|
+
* Merges the results of a judge request's calls into one result.
|
|
1468
|
+
*
|
|
1469
|
+
* @remarks
|
|
1470
|
+
* Pure and total. Answers and refusals are joined by question id; `refusals` is omitted when no
|
|
1471
|
+
* call refused a question. Each call's usage passes through {@link sanitizeUsage} and the totals
|
|
1472
|
+
* add through {@link sumUsage}; `usage` is omitted when no call reported one. The model is the
|
|
1473
|
+
* first call's, or the given model when the list is empty, as the empty partial of a cancel
|
|
1474
|
+
* before the first call requires.
|
|
1475
|
+
*
|
|
1476
|
+
* @param model - The judge's configured model, reported when no call completed
|
|
1477
|
+
* @param results - The completed calls' results in call order
|
|
1478
|
+
* @returns The merged result
|
|
1479
|
+
* @example
|
|
1480
|
+
* ```ts
|
|
1481
|
+
* buildJudgeResult('tev1:0.8b', []) // { model: 'tev1:0.8b', answers: {} }
|
|
1482
|
+
* buildJudgeResult('jev-latest', [
|
|
1483
|
+
* { model: 'jev-1.13.0', answers: { urgent: { form: 'noul', noul: 0.95 } } },
|
|
1484
|
+
* { model: 'jev-1.13.0', answers: {}, refusals: { team: { missing: ['sales'] } } },
|
|
1485
|
+
* ])
|
|
1486
|
+
* // { model: 'jev-1.13.0', answers: { urgent: ... }, refusals: { team: { missing: ['sales'] } } }
|
|
1487
|
+
* ```
|
|
1488
|
+
*/
|
|
1489
|
+
export declare function buildJudgeResult(model: string, results: readonly JudgeResult[]): JudgeResult;
|
|
1490
|
+
|
|
1353
1491
|
/**
|
|
1354
1492
|
* Assembles a provider result with only populated optional fields.
|
|
1355
1493
|
*
|
|
@@ -1482,6 +1620,22 @@ export declare interface ChannelInterface<T> {
|
|
|
1482
1620
|
drain(): AsyncGenerator<T, void>;
|
|
1483
1621
|
}
|
|
1484
1622
|
|
|
1623
|
+
/** Carries a choice distribution keyed by option name, in criteria order. */
|
|
1624
|
+
export declare interface ChoiceAnswer {
|
|
1625
|
+
readonly form: 'choice';
|
|
1626
|
+
readonly probabilities: Readonly<Record<string, number>>;
|
|
1627
|
+
}
|
|
1628
|
+
|
|
1629
|
+
/** Maps each option name the model sees to its description; null keeps an undescribed option in the map. */
|
|
1630
|
+
export declare type ChoiceCriteria = Readonly<Record<string, JudgeEntry | null>>;
|
|
1631
|
+
|
|
1632
|
+
/** Asks the model to pick one named option from its criteria. */
|
|
1633
|
+
export declare interface ChoiceQuestion {
|
|
1634
|
+
readonly form: 'choice';
|
|
1635
|
+
readonly instructions?: JudgeEntry;
|
|
1636
|
+
readonly criteria: ChoiceCriteria;
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1485
1639
|
/**
|
|
1486
1640
|
* Collects the `base64` payload of the image files in a workspace file list — the data an agent
|
|
1487
1641
|
* context attaches to the last user message.
|
|
@@ -1522,6 +1676,35 @@ export declare interface CompactOptions {
|
|
|
1522
1676
|
readonly sections?: number;
|
|
1523
1677
|
}
|
|
1524
1678
|
|
|
1679
|
+
/**
|
|
1680
|
+
* Derives the winner, its probability, the published confidence, and a score answer's expected
|
|
1681
|
+
* level from a judge answer's distribution.
|
|
1682
|
+
*
|
|
1683
|
+
* @remarks
|
|
1684
|
+
* The winner is the first strictly greatest candidate in enumeration order: an option name in
|
|
1685
|
+
* criteria order, a level index, or `'false'` then `'true'` for a noul, so a noul of exactly 0.5
|
|
1686
|
+
* names `'false'`. Confidence follows the TypeSafe formulas, whatever confidence a server sent: a
|
|
1687
|
+
* choice reads `(max(p) - 1/n) / (1 - 1/n)`, a noul reads `|2p - 1|` (the choice formula at
|
|
1688
|
+
* n = 2), and a score reads `max(0, 1 - spread / even_spread)`, where `spread` sums each level's
|
|
1689
|
+
* probability times its distance from the winning level and `even_spread` is the mean distance
|
|
1690
|
+
* from the middle level. `score` is the expected level `sum(i * p_i)` and is set only for a score
|
|
1691
|
+
* answer.
|
|
1692
|
+
*
|
|
1693
|
+
* @param answer - The answer whose distribution is read
|
|
1694
|
+
* @returns The derived measures
|
|
1695
|
+
* @throws JudgeError Thrown with code `PROTOCOL` when a choice or score answer has fewer than 2
|
|
1696
|
+
* candidates, because the confidence formulas divide by the candidate count
|
|
1697
|
+
* @example
|
|
1698
|
+
* ```ts
|
|
1699
|
+
* computeReading({ form: 'choice', probabilities: { billing: 0.88, technical: 0.12, sales: 0 } })
|
|
1700
|
+
* // { winner: 'billing', probability: 0.88, confidence: 0.82 } to two decimals
|
|
1701
|
+
* computeReading({ form: 'score', probabilities: [0, 0.57, 0.43] })
|
|
1702
|
+
* // { winner: '1', probability: 0.57, confidence: 0.355, score: 1.43 } to three decimals
|
|
1703
|
+
* computeReading({ form: 'noul', noul: 0.5 }) // { winner: 'false', probability: 0.5, confidence: 0 }
|
|
1704
|
+
* ```
|
|
1705
|
+
*/
|
|
1706
|
+
export declare function computeReading(answer: JudgeAnswer): Reading;
|
|
1707
|
+
|
|
1525
1708
|
/**
|
|
1526
1709
|
* Holds a provider's optional context-framing default, keyed by section kind — the framing a model
|
|
1527
1710
|
* prefers (for example XML tags against Markdown headers), declared by a {@link ProviderInterface}
|
|
@@ -2343,6 +2526,24 @@ export declare interface ConversationStoreInterface {
|
|
|
2343
2526
|
*/
|
|
2344
2527
|
export declare type ConversationSummaryHandler = (messages: readonly Message[]) => Promise<string>;
|
|
2345
2528
|
|
|
2529
|
+
/**
|
|
2530
|
+
* Owns a value by serializing it to JSON and parsing the text, so the copy shares nothing with its source.
|
|
2531
|
+
*
|
|
2532
|
+
* @remarks
|
|
2533
|
+
* A value that JSON cannot carry, such as a cycle or a bigint, and a value that serializes to
|
|
2534
|
+
* nothing, such as a function, both return undefined, so a guard over the result refuses them.
|
|
2535
|
+
* A proxied value serializes through its traps, where a structured clone refuses it.
|
|
2536
|
+
*
|
|
2537
|
+
* @param value - The value to own
|
|
2538
|
+
* @returns The owned JSON copy, or undefined when the value is not JSON
|
|
2539
|
+
* @example
|
|
2540
|
+
* ```ts
|
|
2541
|
+
* copyJSON({ state: 'A ticket.' }) // { state: 'A ticket.' }
|
|
2542
|
+
* copyJSON(() => 1) // undefined
|
|
2543
|
+
* ```
|
|
2544
|
+
*/
|
|
2545
|
+
export declare function copyJSON(value: unknown): unknown;
|
|
2546
|
+
|
|
2346
2547
|
/**
|
|
2347
2548
|
* Creates an agent loop — an {@link AgentInterface} composing a
|
|
2348
2549
|
* {@link ProviderInterface}, its {@link AgentContextInterface}, and a tool registry
|
|
@@ -2926,6 +3127,18 @@ export declare function createScope(input: ScopeInput): ScopeInterface;
|
|
|
2926
3127
|
*/
|
|
2927
3128
|
export declare function createScopeManager(options?: ScopeManagerOptions): ScopeManagerInterface;
|
|
2928
3129
|
|
|
3130
|
+
/**
|
|
3131
|
+
* Creates a judge that sends every question through the configured System One server.
|
|
3132
|
+
*
|
|
3133
|
+
* @param options - The server origin, model, and optional transport, headers, and timeout
|
|
3134
|
+
* @returns The configured judge behind its shared interface
|
|
3135
|
+
* @example
|
|
3136
|
+
* ```ts
|
|
3137
|
+
* const judge = createSystemOneJudge({ url: 'http://localhost:11434', model: 'tev1:0.8b' })
|
|
3138
|
+
* ```
|
|
3139
|
+
*/
|
|
3140
|
+
export declare function createSystemOneJudge(options: SystemOneJudgeOptions): JudgeInterface;
|
|
3141
|
+
|
|
2929
3142
|
/**
|
|
2930
3143
|
* Creates a fresh stream-stateful `<think>` separator — a {@link ThinkSplitterInterface} that
|
|
2931
3144
|
* splits a thinking model's in-content `<think>…</think>` reasoning spans away from the answer,
|
|
@@ -3142,6 +3355,40 @@ export declare function estimateMessages(messages: readonly Message[]): number;
|
|
|
3142
3355
|
*/
|
|
3143
3356
|
export declare function estimateTokens(text: string): number;
|
|
3144
3357
|
|
|
3358
|
+
/**
|
|
3359
|
+
* Extracts a System One distribution in question criteria order and drops server measures.
|
|
3360
|
+
*
|
|
3361
|
+
* @remarks
|
|
3362
|
+
* Every requested candidate must have a finite probability in [0, 1]; the helper checks each
|
|
3363
|
+
* requested candidate itself and reads no other member. Score maps and arrays project onto the
|
|
3364
|
+
* requested levels. Additional candidates are ignored, sums are unconstrained, and probabilities
|
|
3365
|
+
* are preserved without normalization.
|
|
3366
|
+
*
|
|
3367
|
+
* @param answer - The wire answer to decode
|
|
3368
|
+
* @param question - The question defining the form and candidate order
|
|
3369
|
+
* @returns The domain answer, or undefined for a mismatched form or a requested candidate whose
|
|
3370
|
+
* probability is missing, not finite, or outside [0, 1]
|
|
3371
|
+
* @example
|
|
3372
|
+
* ```ts
|
|
3373
|
+
* extractSystemOneAnswer({ type: 'noul', noul: 0.9 }, { form: 'noul' })
|
|
3374
|
+
* // { form: 'noul', noul: 0.9 }
|
|
3375
|
+
* ```
|
|
3376
|
+
*/
|
|
3377
|
+
export declare function extractSystemOneAnswer(answer: SystemOneAnswer, question: JudgeQuestion): JudgeAnswer | undefined;
|
|
3378
|
+
|
|
3379
|
+
/**
|
|
3380
|
+
* Maps complete System One token counts onto validated token usage.
|
|
3381
|
+
*
|
|
3382
|
+
* @param usage - The optional wire token counts
|
|
3383
|
+
* @returns Token usage, or undefined for missing, null, negative, or non-finite counts
|
|
3384
|
+
* @example
|
|
3385
|
+
* ```ts
|
|
3386
|
+
* extractSystemOneUsage({ input_tokens: 975, output_tokens: 4 })
|
|
3387
|
+
* // { prompt: 975, completion: 4, total: 979 }
|
|
3388
|
+
* ```
|
|
3389
|
+
*/
|
|
3390
|
+
export declare function extractSystemOneUsage(usage: SystemOneUsage | undefined): TokenUsage | undefined;
|
|
3391
|
+
|
|
3145
3392
|
/**
|
|
3146
3393
|
* Filters a list of items by a {@link import('./types.js').ScopeInterface} allow-list of keys —
|
|
3147
3394
|
* `undefined` passes everything, `[]` passes nothing, and a non-empty list passes the listed keys
|
|
@@ -3556,6 +3803,71 @@ export declare function isConversationError(value: unknown): value is Conversati
|
|
|
3556
3803
|
*/
|
|
3557
3804
|
export declare function isConversationSnapshot(value: unknown): value is ConversationSnapshot;
|
|
3558
3805
|
|
|
3806
|
+
/**
|
|
3807
|
+
* Narrows a caught value to a {@link JudgeAbortError} through `instanceof`, so a `catch` can
|
|
3808
|
+
* recover its `partial` result.
|
|
3809
|
+
*
|
|
3810
|
+
* @param value - The caught value
|
|
3811
|
+
* @returns True if the value is a {@link JudgeAbortError}; false otherwise
|
|
3812
|
+
* @example
|
|
3813
|
+
* ```ts
|
|
3814
|
+
* isJudgeAbortError(new JudgeAbortError({ model: 'tev1:0.8b', answers: {} })) // true
|
|
3815
|
+
* ```
|
|
3816
|
+
*/
|
|
3817
|
+
export declare function isJudgeAbortError(value: unknown): value is JudgeAbortError;
|
|
3818
|
+
|
|
3819
|
+
/**
|
|
3820
|
+
* Checks whether a value is a judge entry: a string, a JSON record, or a JSON array.
|
|
3821
|
+
*
|
|
3822
|
+
* @remarks
|
|
3823
|
+
* Total: a cycle, a non-JSON member, a class instance, and a hostile input return false. `null`
|
|
3824
|
+
* is not an entry; a criteria guard admits it where the protocol keeps it.
|
|
3825
|
+
*
|
|
3826
|
+
* @param value - The unknown entry candidate
|
|
3827
|
+
* @returns True if the value is a string or JSON structure the model can read; false otherwise
|
|
3828
|
+
* @example
|
|
3829
|
+
* ```ts
|
|
3830
|
+
* isJudgeEntry('Customer asks for a refund') // true
|
|
3831
|
+
* isJudgeEntry({ ticket: 4182, tags: ['billing'] }) // true
|
|
3832
|
+
* isJudgeEntry(null) // false
|
|
3833
|
+
* isJudgeEntry({ opened: new Date() }) // false
|
|
3834
|
+
* ```
|
|
3835
|
+
*/
|
|
3836
|
+
export declare function isJudgeEntry(value: unknown): value is JudgeEntry;
|
|
3837
|
+
|
|
3838
|
+
/**
|
|
3839
|
+
* Narrows a caught value to the judge failure class through `instanceof`.
|
|
3840
|
+
*
|
|
3841
|
+
* @param value - The caught value
|
|
3842
|
+
* @returns True if the value is a {@link JudgeError}; false otherwise
|
|
3843
|
+
* @example
|
|
3844
|
+
* ```ts
|
|
3845
|
+
* isJudgeError(new JudgeError('HTTP', 'judge error: 429', { status: 429 })) // true
|
|
3846
|
+
* ```
|
|
3847
|
+
*/
|
|
3848
|
+
export declare function isJudgeError(value: unknown): value is JudgeError;
|
|
3849
|
+
|
|
3850
|
+
/**
|
|
3851
|
+
* Checks whether a value is a well-formed judge question of the choice, score, or noul form.
|
|
3852
|
+
*
|
|
3853
|
+
* @remarks
|
|
3854
|
+
* Total: a hostile input returns false. A choice needs at least 2 options and a score at least 2
|
|
3855
|
+
* levels, because the confidence formula divides by the candidate count; a description or a level
|
|
3856
|
+
* can be `null`. `instructions` and noul `criteria` are omitted when absent and never `null`.
|
|
3857
|
+
* Server limits on option, level, and question counts are left to the server.
|
|
3858
|
+
*
|
|
3859
|
+
* @param value - The unknown question candidate
|
|
3860
|
+
* @returns True if the value is a question the judge engine can send; false otherwise
|
|
3861
|
+
* @example
|
|
3862
|
+
* ```ts
|
|
3863
|
+
* isJudgeQuestion({ form: 'choice', criteria: { billing: null, bug: 'Software defect' } }) // true
|
|
3864
|
+
* isJudgeQuestion({ form: 'score', criteria: ['Cosmetic', null, 'Blocking'] }) // true
|
|
3865
|
+
* isJudgeQuestion({ form: 'noul', instructions: 'Is a refund owed?' }) // true
|
|
3866
|
+
* isJudgeQuestion({ form: 'choice', criteria: { billing: null } }) // false
|
|
3867
|
+
* ```
|
|
3868
|
+
*/
|
|
3869
|
+
export declare function isJudgeQuestion(value: unknown): value is JudgeQuestion;
|
|
3870
|
+
|
|
3559
3871
|
/**
|
|
3560
3872
|
* Checks whether a value satisfies the domain conversation-message contract.
|
|
3561
3873
|
*
|
|
@@ -3629,6 +3941,44 @@ export declare function isProviderError(value: unknown): value is ProviderError;
|
|
|
3629
3941
|
*/
|
|
3630
3942
|
export declare function isSection(value: unknown): value is Section;
|
|
3631
3943
|
|
|
3944
|
+
/**
|
|
3945
|
+
* Checks whether a value is a System One answer whose type and distribution the wire can read.
|
|
3946
|
+
*
|
|
3947
|
+
* @remarks
|
|
3948
|
+
* The guard checks `type` and the distribution the wire dereferences: the `noul` number for a
|
|
3949
|
+
* noul, the `probabilities` map for a choice, and the `probabilities` map or dense array for a
|
|
3950
|
+
* score, each probability a finite number in [0, 1]. The `choice`, `score`, `confidence`, and
|
|
3951
|
+
* `legend` members are carried unchecked, because the wire never reads them, so a value this
|
|
3952
|
+
* guard accepts can hold any value in those members. Distribution sums are not constrained;
|
|
3953
|
+
* values are never normalized. Hostile reads return false.
|
|
3954
|
+
*
|
|
3955
|
+
* @param value - The unknown answer candidate
|
|
3956
|
+
* @returns True if the type and the distribution satisfy the wire contract; false otherwise
|
|
3957
|
+
* @example
|
|
3958
|
+
* ```ts
|
|
3959
|
+
* isSystemOneAnswer({ type: 'noul', noul: 0.9 }) // true
|
|
3960
|
+
* isSystemOneAnswer({ type: 'score', probabilities: [0.2, 0.8] }) // true
|
|
3961
|
+
* isSystemOneAnswer({ type: 'noul', noul: 1.1 }) // false
|
|
3962
|
+
* ```
|
|
3963
|
+
*/
|
|
3964
|
+
export declare function isSystemOneAnswer(value: unknown): value is SystemOneAnswer;
|
|
3965
|
+
|
|
3966
|
+
/**
|
|
3967
|
+
* Checks whether a value is a System One response envelope with optional model and usage.
|
|
3968
|
+
*
|
|
3969
|
+
* @remarks
|
|
3970
|
+
* Answers remain unknown until checked against their questions. Missing and null usage counts
|
|
3971
|
+
* are accepted. Extra members are ignored, and unreadable fields return false.
|
|
3972
|
+
*
|
|
3973
|
+
* @param value - The unknown response candidate
|
|
3974
|
+
* @returns True if the envelope fields have their wire types; false otherwise
|
|
3975
|
+
* @example
|
|
3976
|
+
* ```ts
|
|
3977
|
+
* isSystemOneResponse({ answers: {}, usage: { input_tokens: null } }) // true
|
|
3978
|
+
* ```
|
|
3979
|
+
*/
|
|
3980
|
+
export declare function isSystemOneResponse(value: unknown): value is SystemOneResponse;
|
|
3981
|
+
|
|
3632
3982
|
/**
|
|
3633
3983
|
* Joins the reasoning a run's provider calls separated from the answer — the first call
|
|
3634
3984
|
* seeds the accumulation, a later call appends blank-line separated so each turn's reasoning
|
|
@@ -3652,6 +4002,84 @@ export declare function isSection(value: unknown): value is Section;
|
|
|
3652
4002
|
*/
|
|
3653
4003
|
export declare function joinThinking(running: string | undefined, next: string): string;
|
|
3654
4004
|
|
|
4005
|
+
/**
|
|
4006
|
+
* Reports a judge call cancelled by the caller's signal or its deadline, carrying the
|
|
4007
|
+
* {@link JudgeResult} merged from the calls that completed before the cancel and the
|
|
4008
|
+
* machine-readable `code` `'ABORT'`.
|
|
4009
|
+
*
|
|
4010
|
+
* @remarks
|
|
4011
|
+
* `partial` keeps the answers and the usage of every completed call, so usage reported by
|
|
4012
|
+
* completed calls is retained; a cancel before the first call carries an empty partial. `cause` holds the failure the
|
|
4013
|
+
* cancel superseded when a throw raced the abort, and is undefined when the cancel was the only
|
|
4014
|
+
* failure.
|
|
4015
|
+
*/
|
|
4016
|
+
export declare class JudgeAbortError extends Error {
|
|
4017
|
+
/** Names the machine-readable condition — `'ABORT'`: a judge call cancelled mid-flight. */
|
|
4018
|
+
readonly code: "ABORT";
|
|
4019
|
+
readonly partial: JudgeResult;
|
|
4020
|
+
constructor(partial: JudgeResult, options?: ErrorOptions);
|
|
4021
|
+
}
|
|
4022
|
+
|
|
4023
|
+
/** Names one answer by its form; it stores only the distribution a server returned. */
|
|
4024
|
+
export declare type JudgeAnswer = ChoiceAnswer | ScoreAnswer | NoulAnswer;
|
|
4025
|
+
|
|
4026
|
+
/** Carries text or structured JSON the model reads; mirrors the TypeSafe `EntryType` without its null arm. */
|
|
4027
|
+
export declare type JudgeEntry = string | JSONRecord | readonly JSONValue[];
|
|
4028
|
+
|
|
4029
|
+
/**
|
|
4030
|
+
* Reports a coded judge failure with its HTTP status and underlying cause when available.
|
|
4031
|
+
*
|
|
4032
|
+
* @remarks
|
|
4033
|
+
* The judge engine throws this error for a non-OK HTTP response, a missing or unparsable
|
|
4034
|
+
* response body, and a request refused before inference. Concrete wire decoders also use it for
|
|
4035
|
+
* a response they cannot read and for a wire limit. `status` is present only for an `HTTP`
|
|
4036
|
+
* failure; other codes leave it undefined.
|
|
4037
|
+
*/
|
|
4038
|
+
export declare class JudgeError extends Error {
|
|
4039
|
+
/** Names the machine-readable condition — `'HTTP'`: a non-OK response; `'PROTOCOL'`: a missing, unparsable, or unreadable response body; `'QUESTION'`: a request refused before inference. */
|
|
4040
|
+
readonly code: JudgeErrorCode;
|
|
4041
|
+
/** Holds the response status for an HTTP failure, or undefined for other codes. */
|
|
4042
|
+
readonly status: number | undefined;
|
|
4043
|
+
constructor(code: JudgeErrorCode, message: string, options?: ProviderErrorOptions);
|
|
4044
|
+
}
|
|
4045
|
+
|
|
4046
|
+
/** Names the machine-readable judge failure conditions. */
|
|
4047
|
+
export declare type JudgeErrorCode =
|
|
4048
|
+
/** Reports a non-OK HTTP response. */
|
|
4049
|
+
'HTTP'
|
|
4050
|
+
/** Reports a missing or unparsable response body, or a response a wire cannot read. */
|
|
4051
|
+
| 'PROTOCOL'
|
|
4052
|
+
/** Reports a request refused before inference: an empty question map, a malformed question or state, a wire limit, or a judge configuration that would refuse every request. */
|
|
4053
|
+
| 'QUESTION';
|
|
4054
|
+
|
|
4055
|
+
/** Answers typed questions about one state with probabilities; the sibling of `ProviderInterface`, never a provider. */
|
|
4056
|
+
export declare interface JudgeInterface {
|
|
4057
|
+
readonly id: string;
|
|
4058
|
+
readonly name: string;
|
|
4059
|
+
/** Holds the configured model identity; the wire composes it from everything that changes an answer under one state. */
|
|
4060
|
+
readonly model: string;
|
|
4061
|
+
/** Asks every question of the request about its state and returns the merged answers. */
|
|
4062
|
+
ask(request: JudgeRequest, signal: AbortSignal): Promise<JudgeResult>;
|
|
4063
|
+
}
|
|
4064
|
+
|
|
4065
|
+
/** Names one question by its form, the protocol's type field under the fleet's named discriminant. */
|
|
4066
|
+
export declare type JudgeQuestion = ChoiceQuestion | ScoreQuestion | NoulQuestion;
|
|
4067
|
+
|
|
4068
|
+
/** Carries one state and the questions asked about it, keyed by caller ids the model never sees; each question is evaluated on its own. */
|
|
4069
|
+
export declare interface JudgeRequest {
|
|
4070
|
+
readonly state: JudgeEntry;
|
|
4071
|
+
readonly questions: Readonly<Record<string, JudgeQuestion>>;
|
|
4072
|
+
}
|
|
4073
|
+
|
|
4074
|
+
/** Carries the answering model, the answers keyed by question id, the refusals, and the usage the request's calls spent. */
|
|
4075
|
+
export declare interface JudgeResult {
|
|
4076
|
+
readonly model: string;
|
|
4077
|
+
readonly answers: Readonly<Record<string, JudgeAnswer>>;
|
|
4078
|
+
/** Holds each refused question by id; absent when none was refused. An id appears in answers or refusals, never both. */
|
|
4079
|
+
readonly refusals?: Readonly<Record<string, Refusal>>;
|
|
4080
|
+
readonly usage?: TokenUsage;
|
|
4081
|
+
}
|
|
4082
|
+
|
|
3655
4083
|
/**
|
|
3656
4084
|
* Bounds the decoded error excerpt's input in bytes — `2048`, the leading bytes of a non-OK
|
|
3657
4085
|
* response body handed to the decoder before the read cancels the remainder, so a `ProviderError`
|
|
@@ -3733,6 +4161,8 @@ export declare class MemoryConversationStore implements ConversationStoreInterfa
|
|
|
3733
4161
|
* `tool_calls` a prior generation produced, replayed back into the next request so
|
|
3734
4162
|
* the model sees its own decision. A `tool` turn carries the tool's result in
|
|
3735
4163
|
* `content` (the textual outcome), keyed back to the call by the conversation order.
|
|
4164
|
+
* For a successful tool result, a string is the content as is; any other value is
|
|
4165
|
+
* JSON-encoded. A failed tool result carries its error text unchanged.
|
|
3736
4166
|
*/
|
|
3737
4167
|
export declare interface Message {
|
|
3738
4168
|
readonly id: string;
|
|
@@ -3848,6 +4278,25 @@ arguments: ObjectShape<Record<never, never>, JSONShape>;
|
|
|
3848
4278
|
images: OptionalShape<ArrayShape<StringShape>>;
|
|
3849
4279
|
}, boolean | ContractShape>;
|
|
3850
4280
|
|
|
4281
|
+
/** Carries the probability that the answer is yes; the protocol's noul field. */
|
|
4282
|
+
export declare interface NoulAnswer {
|
|
4283
|
+
readonly form: 'noul';
|
|
4284
|
+
readonly noul: number;
|
|
4285
|
+
}
|
|
4286
|
+
|
|
4287
|
+
/** Carries what makes a noul answer true and what makes it false; an omitted side is undescribed. */
|
|
4288
|
+
export declare interface NoulCriteria {
|
|
4289
|
+
readonly true?: JudgeEntry;
|
|
4290
|
+
readonly false?: JudgeEntry;
|
|
4291
|
+
}
|
|
4292
|
+
|
|
4293
|
+
/** Asks the model whether a statement about the state holds. */
|
|
4294
|
+
export declare interface NoulQuestion {
|
|
4295
|
+
readonly form: 'noul';
|
|
4296
|
+
readonly instructions?: JudgeEntry;
|
|
4297
|
+
readonly criteria?: NoulCriteria;
|
|
4298
|
+
}
|
|
4299
|
+
|
|
3851
4300
|
/**
|
|
3852
4301
|
* Names the status a relay answers for a request body at or above its byte budget — `413`,
|
|
3853
4302
|
* carried with no body and answered for an aborted inbound read as well.
|
|
@@ -4179,6 +4628,18 @@ export declare interface ProviderStreamOptions {
|
|
|
4179
4628
|
readonly schema?: Readonly<Record<string, unknown>>;
|
|
4180
4629
|
}
|
|
4181
4630
|
|
|
4631
|
+
/**
|
|
4632
|
+
* Projects a judge question onto the System One wire while preserving omitted members.
|
|
4633
|
+
*
|
|
4634
|
+
* @param question - The domain question to send
|
|
4635
|
+
* @returns The wire question with `type` replacing `form`
|
|
4636
|
+
* @example
|
|
4637
|
+
* ```ts
|
|
4638
|
+
* questionToSystemOne({ form: 'noul' }) // { type: 'noul' }
|
|
4639
|
+
* ```
|
|
4640
|
+
*/
|
|
4641
|
+
export declare function questionToSystemOne(question: JudgeQuestion): SystemOneQuestion;
|
|
4642
|
+
|
|
4182
4643
|
/**
|
|
4183
4644
|
* Decodes UTF-8 chunks with a final flush and releases the stream on every exit.
|
|
4184
4645
|
*
|
|
@@ -4193,6 +4654,41 @@ export declare interface ProviderStreamOptions {
|
|
|
4193
4654
|
*/
|
|
4194
4655
|
export declare function readChunks(body: ReadableStream<Uint8Array>, signal?: AbortSignal): AsyncGenerator<string>;
|
|
4195
4656
|
|
|
4657
|
+
/**
|
|
4658
|
+
* Builds a request's JSON headers, awaiting the caller's header hook inside the call's
|
|
4659
|
+
* cancellation bound.
|
|
4660
|
+
*
|
|
4661
|
+
* @remarks
|
|
4662
|
+
* The headers start with `Content-Type: application/json`; each entry the hook returns is set
|
|
4663
|
+
* over them, so the hook overrides the content type only when it returns that header. The hook
|
|
4664
|
+
* receives `signal` and races its abort, and the abort listener is removed on every exit. Both
|
|
4665
|
+
* HTTP engines, the provider and the judge, read their headers here.
|
|
4666
|
+
*
|
|
4667
|
+
* @param hook - The caller's header hook, or undefined for the JSON content type alone
|
|
4668
|
+
* @param signal - The call's combined caller and deadline signal
|
|
4669
|
+
* @returns The request headers
|
|
4670
|
+
* @throws Thrown when the signal aborts before the hook settles, with the signal's reason, and
|
|
4671
|
+
* when the hook throws or rejects, with the hook's own failure
|
|
4672
|
+
* @example
|
|
4673
|
+
* ```ts
|
|
4674
|
+
* const signal = new AbortController().signal
|
|
4675
|
+
* const headers = await readHeaders(() => ({ authorization: 'Bearer KEY' }), signal)
|
|
4676
|
+
* headers.get('authorization') // 'Bearer KEY'
|
|
4677
|
+
* headers.get('content-type') // 'application/json'
|
|
4678
|
+
* ```
|
|
4679
|
+
*/
|
|
4680
|
+
export declare function readHeaders(hook: ProviderOptions['headers'], signal: AbortSignal): Promise<Headers>;
|
|
4681
|
+
|
|
4682
|
+
/** Carries the measures `computeReading` derives from an answer; nothing stores them. */
|
|
4683
|
+
export declare interface Reading {
|
|
4684
|
+
/** Holds the first strictly greatest candidate in enumeration order: an option name, a level index, or true or false. */
|
|
4685
|
+
readonly winner: string;
|
|
4686
|
+
readonly probability: number;
|
|
4687
|
+
readonly confidence: number;
|
|
4688
|
+
/** Holds the expected level of a score answer; the protocol's score field. */
|
|
4689
|
+
readonly score?: number;
|
|
4690
|
+
}
|
|
4691
|
+
|
|
4196
4692
|
/**
|
|
4197
4693
|
* Reads a UTF-8 prefix of a byte stream and cancels its remainder.
|
|
4198
4694
|
*
|
|
@@ -4216,6 +4712,11 @@ export declare function readChunks(body: ReadableStream<Uint8Array>, signal?: Ab
|
|
|
4216
4712
|
*/
|
|
4217
4713
|
export declare function readText(body: ReadableStream<Uint8Array>, limit?: number, signal?: AbortSignal): Promise<TextRead>;
|
|
4218
4714
|
|
|
4715
|
+
/** Reports a question a wire could not read a candidate for; it lists the caller's keys and invents no probability. */
|
|
4716
|
+
export declare interface Refusal {
|
|
4717
|
+
readonly missing: readonly string[];
|
|
4718
|
+
}
|
|
4719
|
+
|
|
4219
4720
|
/**
|
|
4220
4721
|
* Names the relay's newline-delimited JSON content type — `'application/x-ndjson; charset=utf-8'`,
|
|
4221
4722
|
* the header a relay response carries beside `cache-control: no-store`.
|
|
@@ -4711,7 +5212,11 @@ export declare class Scope implements ScopeInterface {
|
|
|
4711
5212
|
export declare interface ScopeFilter {
|
|
4712
5213
|
/** Lists the allowed instruction `name`s (`undefined` ⇒ all, `[]` ⇒ none, else only-listed). */
|
|
4713
5214
|
readonly instructions?: readonly string[];
|
|
4714
|
-
/**
|
|
5215
|
+
/**
|
|
5216
|
+
* Lists the allowed tool `name`s (`undefined` ⇒ all, `[]` ⇒ none, else only-listed).
|
|
5217
|
+
* The loop advertises and dispatches only admitted tools, checking scope before authority.
|
|
5218
|
+
* If no definition is advertised, the reply ends the run without dispatching its calls.
|
|
5219
|
+
*/
|
|
4715
5220
|
readonly tools?: readonly string[];
|
|
4716
5221
|
/**
|
|
4717
5222
|
* Lists the allowed active-workspace file `path`s (`undefined` ⇒ all, `[]` ⇒ none, else only-listed) —
|
|
@@ -4858,6 +5363,26 @@ export declare interface ScopeManagerOptions {
|
|
|
4858
5363
|
readonly error?: EmitterErrorHandler;
|
|
4859
5364
|
}
|
|
4860
5365
|
|
|
5366
|
+
/** Carries a score distribution indexed by level. */
|
|
5367
|
+
export declare interface ScoreAnswer {
|
|
5368
|
+
readonly form: 'score';
|
|
5369
|
+
readonly probabilities: readonly number[];
|
|
5370
|
+
}
|
|
5371
|
+
|
|
5372
|
+
/** Lists at least two score levels from level 0 upward; null leaves a level undescribed. */
|
|
5373
|
+
export declare type ScoreCriteria = readonly [
|
|
5374
|
+
JudgeEntry | null,
|
|
5375
|
+
JudgeEntry | null,
|
|
5376
|
+
...Array<JudgeEntry | null>
|
|
5377
|
+
];
|
|
5378
|
+
|
|
5379
|
+
/** Asks the model to place the state on an ordered scale of levels. */
|
|
5380
|
+
export declare interface ScoreQuestion {
|
|
5381
|
+
readonly form: 'score';
|
|
5382
|
+
readonly instructions?: JudgeEntry;
|
|
5383
|
+
readonly criteria: ScoreCriteria;
|
|
5384
|
+
}
|
|
5385
|
+
|
|
4861
5386
|
/**
|
|
4862
5387
|
* Holds a slice of folded messages digested into a summary — the unit of compaction a
|
|
4863
5388
|
* {@link ConversationInterface} produces when it `compact`s its live tail.
|
|
@@ -4949,6 +5474,144 @@ export declare interface StreamInterface<T, R> {
|
|
|
4949
5474
|
*/
|
|
4950
5475
|
export declare function sumUsage(running: TokenUsage | undefined, next: TokenUsage): TokenUsage;
|
|
4951
5476
|
|
|
5477
|
+
/** Names the System One decision endpoint shared by compatible servers. */
|
|
5478
|
+
export declare const SYSTEM_ONE_PATH = "/v1/systemone";
|
|
5479
|
+
|
|
5480
|
+
/** Unites the TypeSafe System One answer forms. */
|
|
5481
|
+
export declare type SystemOneAnswer = SystemOneChoiceAnswer | SystemOneScoreAnswer | SystemOneNoulAnswer;
|
|
5482
|
+
|
|
5483
|
+
/** Transliterates a TypeSafe System One choice distribution and optional server measures. */
|
|
5484
|
+
export declare interface SystemOneChoiceAnswer {
|
|
5485
|
+
readonly type: 'choice';
|
|
5486
|
+
readonly probabilities: Readonly<Record<string, number>>;
|
|
5487
|
+
readonly choice?: string;
|
|
5488
|
+
readonly confidence?: number;
|
|
5489
|
+
}
|
|
5490
|
+
|
|
5491
|
+
/** Carries a TypeSafe System One entry, including the wire's explicit null. */
|
|
5492
|
+
export declare type SystemOneEntry = JudgeEntry | null;
|
|
5493
|
+
|
|
5494
|
+
/**
|
|
5495
|
+
* Carries judge questions over the System One protocol and derives answers from server distributions.
|
|
5496
|
+
*
|
|
5497
|
+
* @remarks
|
|
5498
|
+
* The caller supplies the server origin and model. Every question travels in one request.
|
|
5499
|
+
* Server measures are ignored; the response model is preserved.
|
|
5500
|
+
* `headers` supplies authentication through the shared judge engine.
|
|
5501
|
+
*
|
|
5502
|
+
* @example Asking a System One server a choice, a noul, and a score
|
|
5503
|
+
* ```ts
|
|
5504
|
+
* import { computeReading, createSystemOneJudge } from '@orkestrel/agent'
|
|
5505
|
+
*
|
|
5506
|
+
* const judge = createSystemOneJudge({ url: 'http://localhost:11434', model: 'tev1:0.8b' })
|
|
5507
|
+
* const result = await judge.ask(
|
|
5508
|
+
* {
|
|
5509
|
+
* state: 'Our checkout has returned 500 errors since 9am. I want a refund for today.',
|
|
5510
|
+
* questions: {
|
|
5511
|
+
* label: {
|
|
5512
|
+
* form: 'choice',
|
|
5513
|
+
* instructions: 'Which label fits this ticket?',
|
|
5514
|
+
* criteria: { billing: 'Payments and refunds', bug: 'Software errors', account: null },
|
|
5515
|
+
* },
|
|
5516
|
+
* refund: {
|
|
5517
|
+
* form: 'noul',
|
|
5518
|
+
* instructions: 'Does the customer ask for money back?',
|
|
5519
|
+
* criteria: {
|
|
5520
|
+
* true: 'The customer asks for a refund or for money back.',
|
|
5521
|
+
* false: 'The customer does not ask for money back.',
|
|
5522
|
+
* },
|
|
5523
|
+
* },
|
|
5524
|
+
* severity: {
|
|
5525
|
+
* form: 'score',
|
|
5526
|
+
* instructions: 'How severe is the reported issue?',
|
|
5527
|
+
* criteria: ['Cosmetic; no impact', 'Degraded, workaround exists', 'Blocking; no workaround'],
|
|
5528
|
+
* },
|
|
5529
|
+
* },
|
|
5530
|
+
* },
|
|
5531
|
+
* AbortSignal.timeout(30_000),
|
|
5532
|
+
* )
|
|
5533
|
+
* const readings = Object.fromEntries(
|
|
5534
|
+
* Object.entries(result.answers).map(([id, answer]) => [id, computeReading(answer)]),
|
|
5535
|
+
* )
|
|
5536
|
+
* result.model // 'tev1:0.8b' — the model the server named
|
|
5537
|
+
* result.usage // { prompt: 975, completion: 4, total: 979 }
|
|
5538
|
+
* readings.label // { winner: 'bug', probability: 0.9691, confidence: 0.9536 } to four decimals
|
|
5539
|
+
* readings.refund // { winner: 'true', probability: 0.9979, confidence: 0.9958 } to four decimals
|
|
5540
|
+
* readings.severity // { winner: '1', probability: 0.9494, confidence: 0.9241, score: 0.9919 } to four decimals
|
|
5541
|
+
* ```
|
|
5542
|
+
*/
|
|
5543
|
+
export declare class SystemOneJudge extends AgentJudge {
|
|
5544
|
+
constructor(options: SystemOneJudgeOptions);
|
|
5545
|
+
/** Identifies the System One protocol. */
|
|
5546
|
+
readonly name = "systemone";
|
|
5547
|
+
/**
|
|
5548
|
+
* Projects the state and questions onto the System One request with the configured model.
|
|
5549
|
+
*
|
|
5550
|
+
* @param request - The state and questions keyed by caller id
|
|
5551
|
+
* @returns The System One request body
|
|
5552
|
+
*/
|
|
5553
|
+
body(request: JudgeRequest): SystemOneRequest;
|
|
5554
|
+
/**
|
|
5555
|
+
* Decodes requested System One answers and reports the server model and available usage.
|
|
5556
|
+
*
|
|
5557
|
+
* @param value - The parsed response body
|
|
5558
|
+
* @param request - The questions defining the expected answers
|
|
5559
|
+
* @returns The decoded distributions, model, and available usage
|
|
5560
|
+
* @throws JudgeError Thrown with code `PROTOCOL` for a malformed envelope or an invalid answer naming its question id
|
|
5561
|
+
*/
|
|
5562
|
+
read(value: unknown, request: JudgeRequest): JudgeResult;
|
|
5563
|
+
}
|
|
5564
|
+
|
|
5565
|
+
/** Configures the System One server, model, transport, authentication, and deadline. */
|
|
5566
|
+
export declare interface SystemOneJudgeOptions extends Pick<ProviderOptions, 'timeout' | 'fetch' | 'headers'> {
|
|
5567
|
+
/** Holds the server origin without a path. */
|
|
5568
|
+
readonly url: string;
|
|
5569
|
+
readonly model: string;
|
|
5570
|
+
}
|
|
5571
|
+
|
|
5572
|
+
/** Transliterates a TypeSafe System One yes probability and optional server confidence. */
|
|
5573
|
+
export declare interface SystemOneNoulAnswer {
|
|
5574
|
+
readonly type: 'noul';
|
|
5575
|
+
readonly noul: number;
|
|
5576
|
+
readonly confidence?: number;
|
|
5577
|
+
}
|
|
5578
|
+
|
|
5579
|
+
/** Transliterates a TypeSafe System One question with its protocol discriminant and criteria. */
|
|
5580
|
+
export declare interface SystemOneQuestion {
|
|
5581
|
+
readonly type: 'choice' | 'score' | 'noul';
|
|
5582
|
+
readonly instructions?: SystemOneEntry;
|
|
5583
|
+
readonly criteria?: ChoiceCriteria | ScoreCriteria | NoulCriteria | null;
|
|
5584
|
+
}
|
|
5585
|
+
|
|
5586
|
+
/** Transliterates the TypeSafe System One request body. */
|
|
5587
|
+
export declare interface SystemOneRequest {
|
|
5588
|
+
readonly state: SystemOneEntry;
|
|
5589
|
+
readonly model: string;
|
|
5590
|
+
readonly questions: Readonly<Record<string, SystemOneQuestion>>;
|
|
5591
|
+
}
|
|
5592
|
+
|
|
5593
|
+
/** Transliterates the System One response envelope before question-specific answer validation. */
|
|
5594
|
+
export declare interface SystemOneResponse {
|
|
5595
|
+
readonly model?: string;
|
|
5596
|
+
readonly answers: Readonly<Record<string, unknown>>;
|
|
5597
|
+
readonly usage?: SystemOneUsage;
|
|
5598
|
+
}
|
|
5599
|
+
|
|
5600
|
+
/** Accepts System One score probabilities and legends as maps or llama.cpp arrays. */
|
|
5601
|
+
export declare interface SystemOneScoreAnswer {
|
|
5602
|
+
readonly type: 'score';
|
|
5603
|
+
readonly probabilities: Readonly<Record<string, number>> | readonly number[];
|
|
5604
|
+
readonly score?: number;
|
|
5605
|
+
readonly legend?: Readonly<Record<string, SystemOneEntry>> | readonly SystemOneEntry[];
|
|
5606
|
+
readonly confidence?: number;
|
|
5607
|
+
}
|
|
5608
|
+
|
|
5609
|
+
/** Transliterates TypeSafe System One token counts with missing or null counts permitted. */
|
|
5610
|
+
export declare interface SystemOneUsage {
|
|
5611
|
+
readonly input_tokens?: number | null;
|
|
5612
|
+
readonly output_tokens?: number | null;
|
|
5613
|
+
}
|
|
5614
|
+
|
|
4952
5615
|
/** Carries a decoded stream prefix and whether the stream ended within its byte budget. */
|
|
4953
5616
|
export declare interface TextRead {
|
|
4954
5617
|
readonly text: string;
|