@yaklabs-ai/plugin-sdk 0.13.6 → 0.13.8

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.
@@ -203,6 +203,12 @@ declare interface AuthAccount {
203
203
  readonly needsReconnect?: boolean;
204
204
  }
205
205
 
206
+ declare interface Availability {
207
+ readonly available: boolean;
208
+ readonly reason?: string;
209
+ readonly cause?: SystemOneFailureCause;
210
+ }
211
+
206
212
  declare interface BackgroundTaskAdoptOptions {
207
213
  readonly preferredId?: string;
208
214
  readonly toolCallId?: string;
@@ -504,6 +510,82 @@ declare function CyclicOptions(type: TCyclic): TSchemaOptions;
504
510
 
505
511
  declare type CyclicStackLength<Stack extends unknown[], MaxLength extends number, Buffer extends unknown[] = []> = (Stack extends [infer Left, ...infer Right] ? Buffer['length'] extends MaxLength ? false : CyclicStackLength<Right, MaxLength, [...Buffer, Left]> : true);
506
512
 
513
+ declare type DecideAnswerFor<Q> = Q extends DecideBoolQuestion ? DecideBoolAnswer : Q extends DecideChoiceQuestion<infer L> ? DecideChoiceAnswer<L> : Q extends DecideScoreQuestion ? DecideScoreAnswer : never;
514
+
515
+ declare interface DecideBoolAnswer {
516
+ readonly type: "bool";
517
+ /** P(yes), from 0 to 1. */
518
+ readonly probability: number;
519
+ }
520
+
521
+ /** A yes/no question. `criteria` says what yes and what no mean; omit it to leave both open. */
522
+ declare interface DecideBoolQuestion {
523
+ readonly type: "bool";
524
+ readonly instructions: string;
525
+ readonly criteria?: {
526
+ readonly true: string;
527
+ readonly false: string;
528
+ };
529
+ }
530
+
531
+ declare interface DecideChoiceAnswer<L extends string = string> {
532
+ readonly type: "choice";
533
+ readonly choice: L;
534
+ readonly confidence: number;
535
+ /** P(label) for every offered label. */
536
+ readonly probabilities: Readonly<Record<L, number>>;
537
+ }
538
+
539
+ /** A choice among labels. Each label maps to what it means; an empty string leaves it open. */
540
+ declare interface DecideChoiceQuestion<L extends string = string> {
541
+ readonly type: "choice";
542
+ readonly instructions: string;
543
+ readonly criteria: Readonly<Record<L, string>>;
544
+ }
545
+
546
+ declare type DecideModelId = "jev" | "clef" | "clef-flash";
547
+
548
+ declare type DecideQuestion = DecideBoolQuestion | DecideChoiceQuestion | DecideScoreQuestion;
549
+
550
+ /** Questions keyed by the name each answer comes back under. */
551
+ declare type DecideQuestions = Readonly<Record<string, DecideQuestion>>;
552
+
553
+ declare interface DecideRequest<Q extends DecideQuestions = DecideQuestions> {
554
+ /** Defaults to `jev`. */
555
+ readonly model?: DecideModelId;
556
+ readonly state: DecideState;
557
+ readonly questions: Q;
558
+ }
559
+
560
+ declare interface DecideScoreAnswer {
561
+ readonly type: "score";
562
+ /** The expected level, from 0 to the number of levels minus one. */
563
+ readonly score: number;
564
+ readonly confidence: number;
565
+ }
566
+
567
+ /** A score over ordered levels: the first criterion scores 0, the next 1, and so on. */
568
+ declare interface DecideScoreQuestion {
569
+ readonly type: "score";
570
+ readonly instructions: string;
571
+ readonly criteria: readonly string[];
572
+ }
573
+
574
+ /**
575
+ * What a decide call reads. A JSON value is sent as JSON; every value must survive
576
+ * `JSON.stringify` unchanged.
577
+ */
578
+ declare type DecideState = string | object;
579
+
580
+ /** Every asked question has an answer of its own kind. */
581
+ declare interface Decision<Q extends DecideQuestions = DecideQuestions> {
582
+ readonly model: DecideModelId;
583
+ readonly answers: {
584
+ readonly [K in keyof Q]: DecideAnswerFor<Q[K]>;
585
+ };
586
+ readonly usage?: SystemOneTokenUsage;
587
+ }
588
+
507
589
  /** Createsa uni-directional Codec with Decode only. The Decode function is called on Value.Decode */
508
590
  declare function Decode<Type extends TSchema, Callback extends TDecodeCallback<StaticDecode<Type>, unknown>>(type: Type, callback: Callback): TCodec<Type, ReturnType<Callback>>;
509
591
 
@@ -597,6 +679,8 @@ declare const DollarSign = "$";
597
679
 
598
680
  declare const Dot = ".";
599
681
 
682
+ declare type DurationUnit = "seconds" | "minutes" | "hours" | "days" | "weeks" | "months" | "years";
683
+
600
684
  declare const Element: (input: string) => [unknown, string] | [];
601
685
 
602
686
  declare const ElementBase: (input: string) => [unknown, string] | [];
@@ -631,6 +715,18 @@ declare function Enum<Values extends TEnumValue[]>(values: readonly [...Values],
631
715
  /** Creates an Enum type from a TypeScript enum declaration. */
632
716
  declare function Enum<Enum extends TTypeScriptEnumLike>(value: Enum, options?: TSchemaOptions): TEnum<TTypeScriptEnumToEnumValues<Enum>>;
633
717
 
718
+ declare interface EstimateDistribution<V> {
719
+ readonly value: V | null;
720
+ readonly mean?: V;
721
+ readonly median?: V;
722
+ readonly p10?: V;
723
+ readonly p90?: V;
724
+ /** P(value < min). */
725
+ readonly pBelow?: number;
726
+ /** P(value > max). */
727
+ readonly pAbove?: number;
728
+ }
729
+
634
730
  /** Applies an Evaluate action to a type. */
635
731
  declare function Evaluate<Type extends TSchema>(type: Type, options?: TSchemaOptions): TEvaluate<Type>;
636
732
 
@@ -808,9 +904,129 @@ declare interface ExtensionPaths {
808
904
  /** Applies an Extract action using the given types. */
809
905
  declare function Extract_2<Left extends TSchema, Right extends TSchema>(left: Left, right: Right, options?: TSchemaOptions): TExtract<Left, Right>;
810
906
 
907
+ declare type ExtractAnswerFor<F> = F extends ExtractTextField ? ExtractValueAnswer<"text", string> : F extends ExtractNumberField ? ExtractValueAnswer<"number", number> : F extends ExtractDateTimeField ? ExtractValueAnswer<F["type"], string> : F extends ExtractDurationField ? ExtractValueAnswer<"duration", number> : F extends ExtractListField ? ExtractListAnswer<F["items"] extends "number" ? number : string> : F extends ExtractEstimateField ? ExtractEstimateAnswer<F["min"] extends string ? string : number> : F extends ExtractForecastField ? ExtractForecastAnswer : never;
908
+
909
+ /** `date` answers are ISO dates, `time` ISO times, `datetime` ISO date-times. */
910
+ declare interface ExtractDateTimeField extends ExtractFieldBase {
911
+ readonly type: "date" | "time" | "datetime";
912
+ }
913
+
811
914
  /** Creates a deferred Extract action. */
812
915
  declare function ExtractDeferred<Left extends TSchema, Right extends TSchema>(left: Left, right: Right, options?: TSchemaOptions): TExtractDeferred<Left, Right>;
813
916
 
917
+ declare interface ExtractDurationField extends ExtractFieldBase {
918
+ readonly type: "duration";
919
+ /** Seconds when omitted. */
920
+ readonly unit?: DurationUnit;
921
+ readonly integer?: boolean;
922
+ readonly decimals?: number;
923
+ }
924
+
925
+ declare interface ExtractEstimateAnswer<V = number | string> extends EstimateDistribution<V> {
926
+ readonly type: "estimate";
927
+ }
928
+
929
+ /** A distribution over one value. `min`/`max` are numbers, or ISO dates for a date estimate. */
930
+ declare interface ExtractEstimateField extends ExtractFieldBase {
931
+ readonly type: "estimate";
932
+ readonly min: number | string;
933
+ readonly max: number | string;
934
+ /** Grid step: a positive number (days for a date estimate), `month` or `year`. */
935
+ readonly step?: number | "month" | "year";
936
+ readonly scale?: "linear" | "log";
937
+ readonly unit?: string;
938
+ }
939
+
940
+ declare type ExtractField = ExtractTextField | ExtractNumberField | ExtractDateTimeField | ExtractDurationField | ExtractListField | ExtractEstimateField | ExtractForecastField;
941
+
942
+ declare interface ExtractFieldBase {
943
+ readonly instructions?: string;
944
+ /** P(null) above which the value is null. Clairic's default is 0.5. */
945
+ readonly nullThreshold?: number;
946
+ }
947
+
948
+ /** Fields keyed by name. A name matches `^[A-Za-z_][A-Za-z0-9_.\-]{0,63}$`. */
949
+ declare type ExtractFields = Readonly<Record<string, ExtractField>>;
950
+
951
+ declare interface ExtractForecastAnswer {
952
+ readonly type: "forecast";
953
+ /** One value per step; `null` when the state does not determine the forecast. */
954
+ readonly value: readonly number[] | null;
955
+ readonly steps: readonly EstimateDistribution<number>[];
956
+ }
957
+
958
+ /** One distribution per future step. */
959
+ declare interface ExtractForecastField extends ExtractFieldBase {
960
+ readonly type: "forecast";
961
+ readonly min: number;
962
+ readonly max: number;
963
+ /** Number of steps, 1 to 64. */
964
+ readonly horizon: number;
965
+ readonly interval?: ForecastInterval;
966
+ readonly scale?: "linear" | "log";
967
+ readonly unit?: string;
968
+ }
969
+
970
+ declare interface Extraction<F extends ExtractFields = ExtractFields> {
971
+ readonly model: ExtractModelId;
972
+ readonly answers: {
973
+ readonly [K in keyof F]: ExtractAnswerFor<F[K]>;
974
+ };
975
+ /** The state was cut to fit the model's context. */
976
+ readonly truncated: boolean;
977
+ readonly usage?: SystemOneTokenUsage;
978
+ }
979
+
980
+ declare interface ExtractListAnswer<V> {
981
+ readonly type: "list";
982
+ readonly value: readonly V[] | null;
983
+ readonly confidence?: number;
984
+ /** One per item in `value`. */
985
+ readonly confidences?: readonly number[];
986
+ readonly spans?: readonly TextSpan[];
987
+ }
988
+
989
+ declare interface ExtractListField extends ExtractFieldBase {
990
+ readonly type: "list";
991
+ readonly items: "text" | "number" | "date";
992
+ readonly decimals?: number;
993
+ }
994
+
995
+ declare type ExtractModelId = "clairic";
996
+
997
+ declare interface ExtractNumberField extends ExtractFieldBase {
998
+ readonly type: "number";
999
+ readonly unit?: string;
1000
+ readonly integer?: boolean;
1001
+ /** 0 to 6. */
1002
+ readonly decimals?: number;
1003
+ }
1004
+
1005
+ declare interface ExtractRequest<F extends ExtractFields = ExtractFields> {
1006
+ readonly model: ExtractModelId;
1007
+ /** Text only; JSON is not accepted. */
1008
+ readonly state: string;
1009
+ readonly fields: F;
1010
+ /** ISO date that anchors dates written without a year. */
1011
+ readonly referenceDate?: string;
1012
+ }
1013
+
1014
+ declare interface ExtractTextField extends ExtractFieldBase {
1015
+ readonly type: "text";
1016
+ }
1017
+
1018
+ declare interface ExtractValueAnswer<T extends "text" | "number" | "date" | "time" | "datetime" | "duration", V> {
1019
+ readonly type: T;
1020
+ /** `null` when the state does not determine the value. */
1021
+ readonly value: V | null;
1022
+ /** The best candidate even when `value` is null. */
1023
+ readonly guess?: V;
1024
+ readonly confidence?: number;
1025
+ readonly pNull?: number;
1026
+ readonly span?: TextSpan;
1027
+ readonly unit?: string;
1028
+ }
1029
+
814
1030
  declare const Factor: (input: string) => [unknown, string] | [];
815
1031
 
816
1032
  declare function FactorMapping(input: [unknown, unknown, unknown, unknown, unknown]): unknown;
@@ -827,10 +1043,12 @@ declare function FactorMapping(input: [unknown, unknown, unknown, unknown, unkno
827
1043
  export declare function fauxAuthContext(overrides?: Partial<ExtensionAuthContext>): ExtensionAuthContext;
828
1044
 
829
1045
  /** The capability handles a `KayAgentPluginApi` always carries — authority is decided per call. */
830
- export declare type FauxKayAgentCapabilities = Pick<KayAgentPluginApi, "network" | "webSession" | "process" | "whiteboard" | "interaction" | "interceptToolCall" | "withJev" | "events" | "time" | "userFiles" | "familyFolder">;
1046
+ export declare type FauxKayAgentCapabilities = Pick<KayAgentPluginApi, "network" | "webSession" | "process" | "whiteboard" | "interaction" | "interceptToolCall" | "withJev" | "systemOne" | "events" | "time" | "userFiles" | "familyFolder">;
831
1047
 
832
1048
  export declare function fauxKayAgentCapabilities(): FauxKayAgentCapabilities;
833
1049
 
1050
+ declare type ForecastInterval = "step" | "minute" | "hour" | "day" | "week" | "month" | "quarter" | "year";
1051
+
834
1052
  /** Creates a Function type. */
835
1053
  declare function _Function_<Parameters extends TSchema[], ReturnType extends TSchema>(parameters: [...Parameters], returnType: ReturnType, options?: TSchemaOptions): TFunction<Parameters, ReturnType>;
836
1054
 
@@ -1726,6 +1944,15 @@ declare interface KayAgentPluginApi {
1726
1944
  * guard it with `if (api.withJev !== undefined)`.
1727
1945
  */
1728
1946
  readonly withJev: WithJev;
1947
+ /**
1948
+ * System One: fast, cheap judgment calls (`decide`) and typed field extraction (`extract`) on
1949
+ * small models (Jev, Clef, Clef Flash, Clairic). Each call is checked against `jev.use`; a call
1950
+ * that cannot be served or is not permitted throws a `SystemOneError` whose `cause.kind` says
1951
+ * why, so put the feature's cheaper path in the call's own `catch`. Always present, on every
1952
+ * host; a host with no System One throws `not-served`. Types: `@bonsai/plugin-sdk/system-one`
1953
+ * (SDK 0.13.8).
1954
+ */
1955
+ readonly systemOne: SystemOneClient;
1729
1956
  /**
1730
1957
  * The daemon's clock and the time zone the user is in, read together on each `snapshot()` call.
1731
1958
  * Always present and ungated: it confers no authority, since a plugin runs in the daemon's
@@ -4284,6 +4511,74 @@ declare const StringPattern = ".*";
4284
4511
  /** Creates a Symbol type. */
4285
4512
  declare function Symbol_2(options?: TSchemaOptions): TSymbol;
4286
4513
 
4514
+ declare interface SystemOneCallOptions {
4515
+ readonly signal?: AbortSignal;
4516
+ /** Bounds the whole call, retries included. */
4517
+ readonly timeoutMs?: number;
4518
+ }
4519
+
4520
+ declare interface SystemOneClient {
4521
+ decide<const Q extends DecideQuestions>(request: DecideRequest<Q>, options?: SystemOneCallOptions): Promise<Decision<Q>>;
4522
+ extract<const F extends ExtractFields>(request: ExtractRequest<F>, options?: SystemOneCallOptions): Promise<Extraction<F>>;
4523
+ /** Whether some provider in the current order can serve `(kind, model)`. Never rejects. */
4524
+ availability(kind: SystemOneKind, model?: SystemOneModelId): Promise<Availability>;
4525
+ }
4526
+
4527
+ /**
4528
+ * Why a call failed or a provider can't serve, as a closed set. Never prose, and never the
4529
+ * vendor's body: bodies can echo the request's state.
4530
+ */
4531
+ declare type SystemOneFailureCause = {
4532
+ readonly kind: "no-credential";
4533
+ } | {
4534
+ readonly kind: "credential-store";
4535
+ } | {
4536
+ readonly kind: "not-served";
4537
+ } | {
4538
+ readonly kind: "not-permitted";
4539
+ } | {
4540
+ readonly kind: "unknown-model";
4541
+ } | {
4542
+ readonly kind: "invalid-request";
4543
+ readonly detail: string;
4544
+ } | {
4545
+ readonly kind: "too-large";
4546
+ } | {
4547
+ readonly kind: "http";
4548
+ readonly status: number;
4549
+ } | {
4550
+ readonly kind: "transport";
4551
+ } | {
4552
+ readonly kind: "timeout";
4553
+ } | {
4554
+ readonly kind: "aborted";
4555
+ } | {
4556
+ readonly kind: "invalid-answer";
4557
+ };
4558
+
4559
+ /**
4560
+ * ---
4561
+ * responsibility: The data shapes of the System One surface: models, the decide and extract
4562
+ * vocabularies, providers, and the failure causes.
4563
+ * owns:
4564
+ * - The caller-facing question, field, answer, and result types, in Bonsai's own words
4565
+ * (`bool` for yes/no, camelCase options). The vendors' words (`noul`, snake_case) appear
4566
+ * only in `wire.ts`.
4567
+ * - {@link SystemOneProvider}, the seam a transport implements.
4568
+ * does_not_own:
4569
+ * - Which models exist (`models.ts`), how answers are checked (`wire.ts`), or how a provider is
4570
+ * picked (`system-one-client.ts`).
4571
+ * ---
4572
+ */
4573
+ declare type SystemOneKind = "decide" | "extract";
4574
+
4575
+ declare type SystemOneModelId = DecideModelId | ExtractModelId;
4576
+
4577
+ declare interface SystemOneTokenUsage {
4578
+ readonly inputTokens: number;
4579
+ readonly outputTokens: number;
4580
+ }
4581
+
4287
4582
  declare namespace T {
4288
4583
  export {
4289
4584
  Codec,
@@ -5340,6 +5635,9 @@ declare type TExtractType<Left extends TSchema, Right extends TSchema, Check ext
5340
5635
 
5341
5636
  declare type TExtractUnion<Left extends TSchema[], Right extends TSchema, Result extends TSchema[] = []> = (Left extends [infer Head extends TSchema, ...infer Tail extends TSchema[]] ? TExtractUnion<Tail, Right, [...Result, ...TExtractType<Head, Right>]> : Result);
5342
5637
 
5638
+ /** `[start, end)` character offsets into the state. */
5639
+ declare type TextSpan = readonly [number, number];
5640
+
5343
5641
  declare type TFactor<Input extends string> = (TKeyOf<Input> extends [infer _0, infer Input extends string] ? (TBase<Input> extends [infer _1, infer Input extends string] ? (TIndexArray<Input> extends [infer _2, infer Input extends string] ? (TExtends_2<Input> extends [infer _3, infer Input extends string] ? (TWith<Input> extends [infer _4, infer Input extends string] ? [[_0, _1, _2, _3, _4], Input] : []) : []) : []) : []) : []) extends [infer _0 extends [unknown, unknown, unknown, unknown, unknown], infer Input extends string] ? [S.TFactorMapping<_0>, Input] : [];
5344
5642
 
5345
5643
  declare type TFactorExtends<Type extends T.TSchema, Extends extends unknown[]> = (Extends extends [infer Right extends T.TSchema, infer True extends T.TSchema, infer False extends T.TSchema] ? S_2.TConditionalDeferred<Type, Right, True, False> : Type);
@@ -34,6 +34,68 @@ function readProducedResourceDeclarations(details) {
34
34
  return { kind: "declared", resources: claimed };
35
35
  }
36
36
 
37
+ // packages/system-one/dist/errors.js
38
+ var SystemOneError = class extends Error {
39
+ cause;
40
+ kind;
41
+ model;
42
+ /** The provider that failed; absent when no provider was tried. */
43
+ providerId;
44
+ constructor(init) {
45
+ super(describe(init));
46
+ this.name = "SystemOneError";
47
+ this.cause = init.cause;
48
+ this.kind = init.kind;
49
+ this.model = init.model;
50
+ this.providerId = init.providerId;
51
+ }
52
+ };
53
+ function describe(init) {
54
+ const where = init.providerId === void 0 ? "" : ` on provider ${init.providerId}`;
55
+ const detail = init.cause.kind === "http" ? ` (HTTP ${init.cause.status})` : init.cause.kind === "invalid-request" ? ` (${init.cause.detail})` : "";
56
+ return `System One ${init.kind} on ${init.model}${where} failed: ${init.cause.kind}${detail}.`;
57
+ }
58
+
59
+ // packages/system-one/dist/models.js
60
+ var DEFAULT_DECIDE_MODEL = "jev";
61
+ var SYSTEM_ONE_LIMITS = {
62
+ /** The serialized request body, in bytes. */
63
+ maxBodyBytes: 64 * 1024,
64
+ maxQuestions: 8,
65
+ maxFields: 32,
66
+ minChoiceOptions: 2,
67
+ maxChoiceOptions: 255,
68
+ minScoreLevels: 2,
69
+ maxScoreLevels: 10,
70
+ maxForecastHorizon: 64
71
+ };
72
+
73
+ // packages/system-one/dist/unavailable.js
74
+ var NOT_SERVED = {
75
+ available: false,
76
+ reason: "This host has no System One models.",
77
+ cause: { kind: "not-served" }
78
+ };
79
+ function createUnavailableSystemOneClient() {
80
+ return {
81
+ decide(request) {
82
+ return Promise.reject(new SystemOneError({
83
+ kind: "decide",
84
+ model: request.model ?? DEFAULT_DECIDE_MODEL,
85
+ cause: { kind: "not-served" }
86
+ }));
87
+ },
88
+ extract(request) {
89
+ return Promise.reject(new SystemOneError({
90
+ kind: "extract",
91
+ model: request.model,
92
+ cause: { kind: "not-served" }
93
+ }));
94
+ },
95
+ availability: () => Promise.resolve(NOT_SERVED)
96
+ };
97
+ }
98
+
37
99
  // packages/plugin-primitives/dist/is-object.js
38
100
  function isObject(value) {
39
101
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -169,6 +231,9 @@ function fauxKayAgentCapabilities() {
169
231
  // client, no key, and no network, which is all a double here has to guarantee. A test that
170
232
  // wants a real Jev answer overrides this handle after the spread, like any other.
171
233
  withJev: async (_use, fallback) => fallback(),
234
+ // Throws `not-served`, so the plugin's own `catch` runs. A test that wants answers overrides
235
+ // this handle after the spread.
236
+ systemOne: createUnavailableSystemOneClient(),
172
237
  // Accepts and drops, like the registrations above: the real `publish` never throws, so a
173
238
  // rejecting double would fail tests for a reason production never has. A test asserting what
174
239
  // its plugin publishes overrides this handle after the spread.