@alisio/sdk 0.8.0 → 0.10.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 (2) hide show
  1. package/dist/index.d.ts +168 -1
  2. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -752,10 +752,23 @@ export interface RunEventDataMap {
752
752
  reason: "manual" | "auto" | "budget";
753
753
  error: string;
754
754
  };
755
- /** Tool results clipped in place to fit the context budget. */
755
+ /**
756
+ * Tool results clipped in place to fit the context budget. Elision by the Context Governor is
757
+ * never reported here: it lives only in `context_governed`.
758
+ */
756
759
  context_reduced: {
757
760
  messages: number;
761
+ /** Why the results were clipped; absent on events from older cores. */
762
+ reason?: "budget";
763
+ /** Estimate of the tokens the clip saved (characters divided by the shared heuristic). */
764
+ tokensSaved?: number;
758
765
  };
766
+ /**
767
+ * What the Context Governor decided for one model request (modes `shadow` and `on`; never
768
+ * emitted when it is `off`). Counts, enum keys, tool names and provider call ids only: no paths,
769
+ * patterns, stub text or file content.
770
+ */
771
+ context_governed: ContextGovernedData;
759
772
  session_context_injected: {
760
773
  tokens: number;
761
774
  sources: string[];
@@ -806,6 +819,136 @@ export interface RunEventDataMap {
806
819
  actual: ProofStatus;
807
820
  };
808
821
  }
822
+ /**
823
+ * Kind of a context segment. Consumers must accept values they do not know: the list can grow.
824
+ */
825
+ export type ContextSegmentKind = "system" | "instructions" | "user" | "assistant" | "tool_call" | "tool_result" | "checkpoint" | "invariant" | "memory" | "other";
826
+ /** Why the Context Governor replaced a tool result with a stub. Consumers must accept new values. */
827
+ export type ContextElisionReason = "superseded_read" | "stale_bg_output" | "duplicate_search";
828
+ /** Tool results the model saw (`observed`) and later acted on (`used`). */
829
+ export interface ContextUsageCounts {
830
+ observed: number;
831
+ used: number;
832
+ }
833
+ /**
834
+ * Payload of `context_governed`. Token figures are ESTIMATES (about 4 characters per token), never
835
+ * provider usage. Consumers must ignore fields they do not know.
836
+ */
837
+ export interface ContextGovernedData {
838
+ policyVersion: number;
839
+ mode: "shadow" | "on";
840
+ /** 1-based number of the model request inside the run. */
841
+ request: number;
842
+ /** Messages in the history of this request. */
843
+ messages: number;
844
+ /** Inventory segments of that history (without pinned ones). */
845
+ segments: number;
846
+ /** Tool results that would be (`shadow`) or were (`on`) replaced by a stub. */
847
+ elided: number;
848
+ byReason: Record<ContextElisionReason, number>;
849
+ tokensBefore: number;
850
+ tokensAfter: number;
851
+ tokensSaved: number;
852
+ /** Call ids elided for the first time at this request (at most 32). */
853
+ elidedCallIds?: string[];
854
+ /** How many newly elided call ids did not fit in `elidedCallIds`. */
855
+ elidedCallIdsOmitted?: number;
856
+ /** Counts of the invariants block of this request; never its text. */
857
+ invariants?: {
858
+ count: number;
859
+ chars: number;
860
+ omitted: number;
861
+ };
862
+ /** Heuristic usage of the tool results seen by this process in this session (advisory). */
863
+ usage?: {
864
+ observed: number;
865
+ used: number;
866
+ pending: number;
867
+ unattributed: number;
868
+ byKind?: Partial<Record<ContextSegmentKind, ContextUsageCounts>>;
869
+ /** At most 16 tools; the rest are folded into `other`. */
870
+ byTool?: Record<string, ContextUsageCounts>;
871
+ };
872
+ }
873
+ /** Where an invariant comes from. Consumers must accept values they do not know. */
874
+ export type ContextInvariantKind = "instruction" | "goal" | "plan" | "criterion" | "grant";
875
+ /** How protected a context segment is. Consumers must accept values they do not know. */
876
+ export type ContextCriticality = "pinned" | "high" | "normal" | "low";
877
+ /**
878
+ * One piece of the history a model request carries, as `GET /api/sessions/:sid/context/report`
879
+ * and `/context` explain it. Ids and counts only: never the text of the segment.
880
+ */
881
+ export interface ContextSegment {
882
+ /** Stable id (the id the Governor uses for the same segment). */
883
+ id: string;
884
+ kind: ContextSegmentKind;
885
+ /** File path, tool name or message role. */
886
+ origin?: string;
887
+ /** Provider call id of a `tool_call` / `tool_result` segment. */
888
+ callId?: string;
889
+ /** Token ESTIMATE, never provider usage. */
890
+ tokens: number;
891
+ criticality: ContextCriticality;
892
+ /** Why the segment has that criticality. */
893
+ reason?: string;
894
+ /** Present when the Governor replaced (`on`) or would replace (`shadow`) the result by a stub. */
895
+ elided?: {
896
+ reason: ContextElisionReason;
897
+ /** Call id of the later result that made this one redundant. */
898
+ replacedBy?: string;
899
+ tokensSaved: number;
900
+ };
901
+ /** Heuristic: a later call acted on the same path. Absent when it cannot be decided. */
902
+ used?: boolean;
903
+ }
904
+ /**
905
+ * `GET /api/sessions/:sid/context/report`: what the next model request of a session carries and
906
+ * what the Context Governor does with it. The one report that the web panel, `/context` in the TUI
907
+ * and the `context_governed` events agree on. Token figures are ESTIMATES. With `mode: "off"` the
908
+ * Governor measures nothing, so `segments` is empty.
909
+ */
910
+ export interface ContextReport {
911
+ sessionId: string;
912
+ policyVersion: number;
913
+ mode: "off" | "shadow" | "on";
914
+ /** 1-based request number of the latest `context_governed` event of this process, if any. */
915
+ request?: number;
916
+ /** Messages in the history. */
917
+ messages: number;
918
+ /** Segments of the history that count for `ContextGovernedData.segments` plus the pinned ones, in order. */
919
+ segments: ContextSegment[];
920
+ /** Segments dropped from `segments` to bound the report (elided, pinned and low ones stay first). */
921
+ segmentsOmitted?: number;
922
+ tokensBefore: number;
923
+ tokensAfter: number;
924
+ tokensSaved: number;
925
+ /** Tool results replaced (`on`) or that would be (`shadow`). */
926
+ elided: number;
927
+ byReason: Record<ContextElisionReason, number>;
928
+ /**
929
+ * The standing context the next request carries after a compaction, as counts only: never the
930
+ * text of an instruction, goal, plan or criterion. All zero before the first compaction.
931
+ */
932
+ invariants: {
933
+ /** Invariants collected for the next request. */
934
+ count: number;
935
+ /** How many of them did not fit `context.invariants.maxChars` and are left out of the request. */
936
+ omitted: number;
937
+ byKind: Partial<Record<ContextInvariantKind, number>>;
938
+ };
939
+ /** Share of the tool results the agent acted on later; only kinds with decided results. */
940
+ usedRatioByKind: Partial<Record<ContextSegmentKind, number>>;
941
+ /** Heuristic usage counts of this process (advisory, lost on restart). */
942
+ usage?: {
943
+ observed: number;
944
+ used: number;
945
+ pending: number;
946
+ unattributed: number;
947
+ stubOnly: number;
948
+ rereads: number;
949
+ byTool?: Record<string, ContextUsageCounts>;
950
+ };
951
+ }
809
952
  /** Every `RunEvent.type` the core emits today. `RunEvent.type` itself stays `string`. */
810
953
  export type RunEventType = keyof RunEventDataMap;
811
954
  /** Event types never persisted to the session store (and therefore without `eventId`). */
@@ -3095,6 +3238,14 @@ export interface EvalRunRecord {
3095
3238
  * treated as not reported by every aggregation.
3096
3239
  */
3097
3240
  usagePartial?: true;
3241
+ /**
3242
+ * Input tokens the provider served from its prompt cache, summed over the turns. ABSENT when
3243
+ * the provider did not report it (never 0 for "unknown"); an explicit 0 from the provider is
3244
+ * kept. Main-loop calls only, like `inputTokens`.
3245
+ */
3246
+ cachedInputTokens?: number;
3247
+ /** True when only SOME turns that reported usage also reported cached tokens: the sum understates. */
3248
+ cachedPartial?: true;
3098
3249
  wallMs: number;
3099
3250
  turns: number;
3100
3251
  toolCalls: number;
@@ -3170,6 +3321,10 @@ export interface EvalTaskMetrics {
3170
3321
  varianceTokens?: number;
3171
3322
  tokensPerSuccess?: number;
3172
3323
  wallMsPerSuccess?: number;
3324
+ /** cachedInput / input tokens over the judged runs that reported it (see `cachedInputRuns`). */
3325
+ cachedInputRatio?: number;
3326
+ /** How many judged runs of this task reported cached input completely. */
3327
+ cachedInputRuns?: number;
3173
3328
  };
3174
3329
  /** Present only when the caller supplied rates and every judged run reported usage. */
3175
3330
  estimated?: {
@@ -3212,6 +3367,18 @@ export interface EvalReport {
3212
3367
  budgetExceeded: number;
3213
3368
  runs?: number;
3214
3369
  failed?: number;
3370
+ /**
3371
+ * Provider cached input of this arm, over the judged runs that reported it completely (no
3372
+ * partial sums, no partial usage). Absent when none did: no ratio is computed from nothing.
3373
+ * `ratio` is tokens / inputTokens pooled over those runs, not a mean of run ratios.
3374
+ */
3375
+ cachedInput?: {
3376
+ tokens: number;
3377
+ inputTokens: number;
3378
+ ratio: number;
3379
+ runsReporting: number;
3380
+ runsJudged: number;
3381
+ };
3215
3382
  };
3216
3383
  /** The rates behind every `estimated` figure; absent when none was supplied. */
3217
3384
  rates?: EvalRates;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alisio/sdk",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
4
4
  "description": "Typed plugin SDK for Alisio: the stable contract for tools, commands, context, compaction and session hooks, model completions and storage. Types only plus tiny helpers; zero runtime dependencies.",
5
5
  "author": "Gustavo Gutiérrez",
6
6
  "license": "MIT",