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