@yaklabs-ai/plugin-sdk 0.13.7 → 0.13.9

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.
@@ -293,6 +293,12 @@ export declare type AuthBoundToolDefinition<TParams extends ToolParametersWire =
293
293
  readonly requiresAuth: RequiresAuth;
294
294
  };
295
295
 
296
+ declare interface Availability {
297
+ readonly available: boolean;
298
+ readonly reason?: string;
299
+ readonly cause?: SystemOneFailureCause;
300
+ }
301
+
296
302
  declare interface BackgroundTaskAdoptOptions {
297
303
  readonly preferredId?: string;
298
304
  readonly toolCallId?: string;
@@ -737,6 +743,85 @@ declare function CyclicOptions(type: TCyclic): TSchemaOptions;
737
743
 
738
744
  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);
739
745
 
746
+ declare type DecideAnswerFor<Q> = Q extends DecideBoolQuestion ? DecideBoolAnswer : Q extends DecideChoiceQuestion<infer L> ? DecideChoiceAnswer<L> : Q extends DecideScoreQuestion ? DecideScoreAnswer : never;
747
+
748
+ declare interface DecideBoolAnswer {
749
+ readonly type: "bool";
750
+ /** P(yes), from 0 to 1. */
751
+ readonly probability: number;
752
+ }
753
+
754
+ /** A yes/no question. `criteria` says what yes and what no mean; omit it to leave both open. */
755
+ declare interface DecideBoolQuestion {
756
+ readonly type: "bool";
757
+ readonly instructions: DecideInstructions;
758
+ readonly criteria?: {
759
+ readonly true: string;
760
+ readonly false: string;
761
+ };
762
+ }
763
+
764
+ declare interface DecideChoiceAnswer<L extends string = string> {
765
+ readonly type: "choice";
766
+ readonly choice: L;
767
+ readonly confidence: number;
768
+ /** P(label) for every offered label. */
769
+ readonly probabilities: Readonly<Record<L, number>>;
770
+ }
771
+
772
+ /** A choice among labels. Each label maps to what it means; an empty string leaves it open. */
773
+ declare interface DecideChoiceQuestion<L extends string = string> {
774
+ readonly type: "choice";
775
+ readonly instructions: DecideInstructions;
776
+ readonly criteria: Readonly<Record<L, string>>;
777
+ }
778
+
779
+ /** What a question asks: text, or a JSON object the client sends as its JSON text. */
780
+ declare type DecideInstructions = string | object;
781
+
782
+ declare type DecideModelId = "jev" | "clef" | "clef-flash";
783
+
784
+ declare type DecideQuestion = DecideBoolQuestion | DecideChoiceQuestion | DecideScoreQuestion;
785
+
786
+ /** Questions keyed by the name each answer comes back under. */
787
+ declare type DecideQuestions = Readonly<Record<string, DecideQuestion>>;
788
+
789
+ declare interface DecideRequest<Q extends DecideQuestions = DecideQuestions> {
790
+ /** Defaults to `jev`. */
791
+ readonly model?: DecideModelId;
792
+ readonly state: DecideState;
793
+ readonly questions: Q;
794
+ }
795
+
796
+ declare interface DecideScoreAnswer {
797
+ readonly type: "score";
798
+ /** The expected level, from 0 to the number of levels minus one. */
799
+ readonly score: number;
800
+ readonly confidence: number;
801
+ }
802
+
803
+ /** A score over ordered levels: the first criterion scores 0, the next 1, and so on. */
804
+ declare interface DecideScoreQuestion {
805
+ readonly type: "score";
806
+ readonly instructions: DecideInstructions;
807
+ readonly criteria: readonly string[];
808
+ }
809
+
810
+ /**
811
+ * What a decide call reads. A JSON value is sent as JSON; every value must survive
812
+ * `JSON.stringify` unchanged.
813
+ */
814
+ declare type DecideState = string | object;
815
+
816
+ /** Every asked question has an answer of its own kind. */
817
+ declare interface Decision<Q extends DecideQuestions = DecideQuestions> {
818
+ readonly model: DecideModelId;
819
+ readonly answers: {
820
+ readonly [K in keyof Q]: DecideAnswerFor<Q[K]>;
821
+ };
822
+ readonly usage?: SystemOneTokenUsage;
823
+ }
824
+
740
825
  /**
741
826
  * Declare the URIs a tool call created or updated as a side effect, on the result it returns.
742
827
  *
@@ -901,6 +986,8 @@ declare const DollarSign = "$";
901
986
 
902
987
  declare const Dot = ".";
903
988
 
989
+ declare type DurationUnit = "seconds" | "minutes" | "hours" | "days" | "weeks" | "months" | "years";
990
+
904
991
  declare const Element: (input: string) => [unknown, string] | [];
905
992
 
906
993
  declare const ElementBase: (input: string) => [unknown, string] | [];
@@ -935,6 +1022,18 @@ declare function Enum<Values extends TEnumValue[]>(values: readonly [...Values],
935
1022
  /** Creates an Enum type from a TypeScript enum declaration. */
936
1023
  declare function Enum<Enum extends TTypeScriptEnumLike>(value: Enum, options?: TSchemaOptions): TEnum<TTypeScriptEnumToEnumValues<Enum>>;
937
1024
 
1025
+ declare interface EstimateDistribution<V> {
1026
+ readonly value: V | null;
1027
+ readonly mean?: V;
1028
+ readonly median?: V;
1029
+ readonly p10?: V;
1030
+ readonly p90?: V;
1031
+ /** P(value < min). */
1032
+ readonly pBelow?: number;
1033
+ /** P(value > max). */
1034
+ readonly pAbove?: number;
1035
+ }
1036
+
938
1037
  /** Applies an Evaluate action to a type. */
939
1038
  declare function Evaluate<Type extends TSchema>(type: Type, options?: TSchemaOptions): TEvaluate<Type>;
940
1039
 
@@ -1112,9 +1211,129 @@ declare interface ExtensionPaths {
1112
1211
  /** Applies an Extract action using the given types. */
1113
1212
  declare function Extract_2<Left extends TSchema, Right extends TSchema>(left: Left, right: Right, options?: TSchemaOptions): TExtract<Left, Right>;
1114
1213
 
1214
+ 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;
1215
+
1216
+ /** `date` answers are ISO dates, `time` ISO times, `datetime` ISO date-times. */
1217
+ declare interface ExtractDateTimeField extends ExtractFieldBase {
1218
+ readonly type: "date" | "time" | "datetime";
1219
+ }
1220
+
1115
1221
  /** Creates a deferred Extract action. */
1116
1222
  declare function ExtractDeferred<Left extends TSchema, Right extends TSchema>(left: Left, right: Right, options?: TSchemaOptions): TExtractDeferred<Left, Right>;
1117
1223
 
1224
+ declare interface ExtractDurationField extends ExtractFieldBase {
1225
+ readonly type: "duration";
1226
+ /** Seconds when omitted. */
1227
+ readonly unit?: DurationUnit;
1228
+ readonly integer?: boolean;
1229
+ readonly decimals?: number;
1230
+ }
1231
+
1232
+ declare interface ExtractEstimateAnswer<V = number | string> extends EstimateDistribution<V> {
1233
+ readonly type: "estimate";
1234
+ }
1235
+
1236
+ /** A distribution over one value. `min`/`max` are numbers, or ISO dates for a date estimate. */
1237
+ declare interface ExtractEstimateField extends ExtractFieldBase {
1238
+ readonly type: "estimate";
1239
+ readonly min: number | string;
1240
+ readonly max: number | string;
1241
+ /** Grid step: a positive number (days for a date estimate), `month` or `year`. */
1242
+ readonly step?: number | "month" | "year";
1243
+ readonly scale?: "linear" | "log";
1244
+ readonly unit?: string;
1245
+ }
1246
+
1247
+ declare type ExtractField = ExtractTextField | ExtractNumberField | ExtractDateTimeField | ExtractDurationField | ExtractListField | ExtractEstimateField | ExtractForecastField;
1248
+
1249
+ declare interface ExtractFieldBase {
1250
+ readonly instructions?: string;
1251
+ /** P(null) above which the value is null. Clairic's default is 0.5. */
1252
+ readonly nullThreshold?: number;
1253
+ }
1254
+
1255
+ /** Fields keyed by name. A name matches `^[A-Za-z_][A-Za-z0-9_.\-]{0,63}$`. */
1256
+ declare type ExtractFields = Readonly<Record<string, ExtractField>>;
1257
+
1258
+ declare interface ExtractForecastAnswer {
1259
+ readonly type: "forecast";
1260
+ /** One value per step; `null` when the state does not determine the forecast. */
1261
+ readonly value: readonly number[] | null;
1262
+ readonly steps: readonly EstimateDistribution<number>[];
1263
+ }
1264
+
1265
+ /** One distribution per future step. */
1266
+ declare interface ExtractForecastField extends ExtractFieldBase {
1267
+ readonly type: "forecast";
1268
+ readonly min: number;
1269
+ readonly max: number;
1270
+ /** Number of steps, 1 to 64. */
1271
+ readonly horizon: number;
1272
+ readonly interval?: ForecastInterval;
1273
+ readonly scale?: "linear" | "log";
1274
+ readonly unit?: string;
1275
+ }
1276
+
1277
+ declare interface Extraction<F extends ExtractFields = ExtractFields> {
1278
+ readonly model: ExtractModelId;
1279
+ readonly answers: {
1280
+ readonly [K in keyof F]: ExtractAnswerFor<F[K]>;
1281
+ };
1282
+ /** The state was cut to fit the model's context. */
1283
+ readonly truncated: boolean;
1284
+ readonly usage?: SystemOneTokenUsage;
1285
+ }
1286
+
1287
+ declare interface ExtractListAnswer<V> {
1288
+ readonly type: "list";
1289
+ readonly value: readonly V[] | null;
1290
+ readonly confidence?: number;
1291
+ /** One per item in `value`. */
1292
+ readonly confidences?: readonly number[];
1293
+ readonly spans?: readonly TextSpan[];
1294
+ }
1295
+
1296
+ declare interface ExtractListField extends ExtractFieldBase {
1297
+ readonly type: "list";
1298
+ readonly items: "text" | "number" | "date";
1299
+ readonly decimals?: number;
1300
+ }
1301
+
1302
+ declare type ExtractModelId = "clairic";
1303
+
1304
+ declare interface ExtractNumberField extends ExtractFieldBase {
1305
+ readonly type: "number";
1306
+ readonly unit?: string;
1307
+ readonly integer?: boolean;
1308
+ /** 0 to 6. */
1309
+ readonly decimals?: number;
1310
+ }
1311
+
1312
+ declare interface ExtractRequest<F extends ExtractFields = ExtractFields> {
1313
+ readonly model: ExtractModelId;
1314
+ /** Text only; JSON is not accepted. */
1315
+ readonly state: string;
1316
+ readonly fields: F;
1317
+ /** ISO date that anchors dates written without a year. */
1318
+ readonly referenceDate?: string;
1319
+ }
1320
+
1321
+ declare interface ExtractTextField extends ExtractFieldBase {
1322
+ readonly type: "text";
1323
+ }
1324
+
1325
+ declare interface ExtractValueAnswer<T extends "text" | "number" | "date" | "time" | "datetime" | "duration", V> {
1326
+ readonly type: T;
1327
+ /** `null` when the state does not determine the value. */
1328
+ readonly value: V | null;
1329
+ /** The best candidate even when `value` is null. */
1330
+ readonly guess?: V;
1331
+ readonly confidence?: number;
1332
+ readonly pNull?: number;
1333
+ readonly span?: TextSpan;
1334
+ readonly unit?: string;
1335
+ }
1336
+
1118
1337
  declare const Factor: (input: string) => [unknown, string] | [];
1119
1338
 
1120
1339
  declare function FactorMapping(input: [unknown, unknown, unknown, unknown, unknown]): unknown;
@@ -1125,6 +1344,8 @@ declare function FactorMapping(input: [unknown, unknown, unknown, unknown, unkno
1125
1344
  */
1126
1345
  export declare function fenced(text: string): readonly string[];
1127
1346
 
1347
+ declare type ForecastInterval = "step" | "minute" | "hour" | "day" | "week" | "month" | "quarter" | "year";
1348
+
1128
1349
  export declare function formatIsoDate(value?: string | number | Date): string;
1129
1350
 
1130
1351
  export declare function formatNumber(n: number): string;
@@ -2169,6 +2390,15 @@ export declare interface KayAgentPluginApi {
2169
2390
  * guard it with `if (api.withJev !== undefined)`.
2170
2391
  */
2171
2392
  readonly withJev: WithJev;
2393
+ /**
2394
+ * System One: fast, cheap judgment calls (`decide`) and typed field extraction (`extract`) on
2395
+ * small models (Jev, Clef, Clef Flash, Clairic). Each call is checked against `jev.use`; a call
2396
+ * that cannot be served or is not permitted throws a `SystemOneError` whose `cause.kind` says
2397
+ * why, so put the feature's cheaper path in the call's own `catch`. Always present, on every
2398
+ * host; a host with no System One throws `not-served`. Types: `@bonsai/plugin-sdk/system-one`
2399
+ * (SDK 0.13.8).
2400
+ */
2401
+ readonly systemOne: SystemOneClient;
2172
2402
  /**
2173
2403
  * The daemon's clock and the time zone the user is in, read together on each `snapshot()` call.
2174
2404
  * Always present and ungated: it confers no authority, since a plugin runs in the daemon's
@@ -6247,6 +6477,76 @@ declare const StringPattern = ".*";
6247
6477
  /** Creates a Symbol type. */
6248
6478
  declare function Symbol_2(options?: TSchemaOptions): TSymbol;
6249
6479
 
6480
+ declare interface SystemOneCallOptions {
6481
+ readonly signal?: AbortSignal;
6482
+ /** Bounds the whole call, retries included. */
6483
+ readonly timeoutMs?: number;
6484
+ /** What the call is for, carried to the host's usage accounting. Never sent to a provider. */
6485
+ readonly purpose?: string;
6486
+ }
6487
+
6488
+ declare interface SystemOneClient {
6489
+ decide<const Q extends DecideQuestions>(request: DecideRequest<Q>, options?: SystemOneCallOptions): Promise<Decision<Q>>;
6490
+ extract<const F extends ExtractFields>(request: ExtractRequest<F>, options?: SystemOneCallOptions): Promise<Extraction<F>>;
6491
+ /** Whether some provider in the current order can serve `(kind, model)`. Never rejects. */
6492
+ availability(kind: SystemOneKind, model?: SystemOneModelId): Promise<Availability>;
6493
+ }
6494
+
6495
+ /**
6496
+ * Why a call failed or a provider can't serve, as a closed set. Never prose, and never the
6497
+ * vendor's body: bodies can echo the request's state.
6498
+ */
6499
+ declare type SystemOneFailureCause = {
6500
+ readonly kind: "no-credential";
6501
+ } | {
6502
+ readonly kind: "credential-store";
6503
+ } | {
6504
+ readonly kind: "not-served";
6505
+ } | {
6506
+ readonly kind: "not-permitted";
6507
+ } | {
6508
+ readonly kind: "unknown-model";
6509
+ } | {
6510
+ readonly kind: "invalid-request";
6511
+ readonly detail: string;
6512
+ } | {
6513
+ readonly kind: "too-large";
6514
+ } | {
6515
+ readonly kind: "http";
6516
+ readonly status: number;
6517
+ } | {
6518
+ readonly kind: "transport";
6519
+ } | {
6520
+ readonly kind: "timeout";
6521
+ } | {
6522
+ readonly kind: "aborted";
6523
+ } | {
6524
+ readonly kind: "invalid-answer";
6525
+ };
6526
+
6527
+ /**
6528
+ * ---
6529
+ * responsibility: The data shapes of the System One surface: models, the decide and extract
6530
+ * vocabularies, providers, and the failure causes.
6531
+ * owns:
6532
+ * - The caller-facing question, field, answer, and result types, in Bonsai's own words
6533
+ * (`bool` for yes/no, camelCase options). The vendors' words (`noul`, snake_case) appear
6534
+ * only in `wire.ts`.
6535
+ * - {@link SystemOneProvider}, the seam a transport implements.
6536
+ * does_not_own:
6537
+ * - Which models exist (`models.ts`), how answers are checked (`wire.ts`), or how a provider is
6538
+ * picked (`system-one-client.ts`).
6539
+ * ---
6540
+ */
6541
+ declare type SystemOneKind = "decide" | "extract";
6542
+
6543
+ declare type SystemOneModelId = DecideModelId | ExtractModelId;
6544
+
6545
+ declare interface SystemOneTokenUsage {
6546
+ readonly inputTokens: number;
6547
+ readonly outputTokens: number;
6548
+ }
6549
+
6250
6550
  declare namespace T {
6251
6551
  export {
6252
6552
  Codec,
@@ -7293,6 +7593,9 @@ declare type TExtractUnion<Left extends TSchema[], Right extends TSchema, Result
7293
7593
 
7294
7594
  export declare function textResult<TDetails = undefined>(text: string, details: TDetails): AgentToolResult<TDetails>;
7295
7595
 
7596
+ /** `[start, end)` character offsets into the state. */
7597
+ declare type TextSpan = readonly [number, number];
7598
+
7296
7599
  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] : [];
7297
7600
 
7298
7601
  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);