@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.
package/README.md CHANGED
@@ -13,7 +13,7 @@ it under the name your plugin code actually imports:
13
13
  ```json
14
14
  {
15
15
  "dependencies": {
16
- "@bonsai/plugin-sdk": "npm:@yaklabs-ai/plugin-sdk@^0.13.7"
16
+ "@bonsai/plugin-sdk": "npm:@yaklabs-ai/plugin-sdk@^0.13.8"
17
17
  }
18
18
  }
19
19
  ```
@@ -62,7 +62,7 @@ Every tool the entrypoint registers is declared in the manifest too:
62
62
  "description": "Greets people by name.",
63
63
  "version": "0.1.0",
64
64
  "namespace": "widgets",
65
- "compatibility": { "sdk": "^0.13.7" },
65
+ "compatibility": { "sdk": "^0.13.8" },
66
66
  "targets": {
67
67
  "kay": {
68
68
  "agent": {
@@ -128,11 +128,13 @@ naming both versions, instead of loading it and finding no `activate`.
128
128
  | `@bonsai/plugin-sdk/agent-conversation` | How a session's agent-to-agent traffic groups into conversations, from 0.13.7 |
129
129
  | `@bonsai/plugin-sdk/app-data` | The app-data size caps, on an entry with no other import, from 0.13.7 |
130
130
  | `@bonsai/plugin-sdk/vendored-mcp` | The kit for a plugin built on a vendor's hosted MCP server, from 0.13.7 |
131
+ | `@bonsai/plugin-sdk/system-one` | The types and error class for `api.systemOne` / `app.systemOne`, from 0.13.8 |
131
132
 
132
133
  A plugin that imports a subpath declares at least the version its row names (`^0.13.7` for the
133
- last four). `vendored-mcp` builds the plugin's URI module (its link cards and help); hosting the
134
- vendor's MCP server itself is a separate host decision, and Bonsai currently makes it only for
135
- its own bundled plugins.
134
+ four from 0.13.7, `^0.13.8` for `system-one`). `vendored-mcp` builds the plugin's URI module (its link cards and help); hosting the
135
+ vendor's MCP server itself is a separate host decision: Bonsai hosts it once a person approves
136
+ the plugin's `mcp.host-server` grant for that server's name and URL. A server that needs an OAuth
137
+ sign-in is, for now, supported only for Bonsai's own plugins.
136
138
 
137
139
  `kay-agent/host` is intentionally not published; it is Bonsai's own loading
138
140
  machinery, not an authoring API.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
3
  "package": "@yaklabs-ai/plugin-sdk",
4
- "version": "0.13.7",
4
+ "version": "0.13.8",
5
5
  "target": "npm",
6
6
  "firstPartyLicense": "MIT",
7
7
  "bundled": [
@@ -249,6 +249,12 @@ declare interface AuthAccount {
249
249
  readonly needsReconnect?: boolean;
250
250
  }
251
251
 
252
+ declare interface Availability {
253
+ readonly available: boolean;
254
+ readonly reason?: string;
255
+ readonly cause?: SystemOneFailureCause;
256
+ }
257
+
252
258
  declare interface BackgroundTaskAdoptOptions {
253
259
  readonly preferredId?: string;
254
260
  readonly toolCallId?: string;
@@ -593,6 +599,82 @@ declare function CyclicOptions(type: TCyclic): TSchemaOptions;
593
599
 
594
600
  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);
595
601
 
602
+ declare type DecideAnswerFor<Q> = Q extends DecideBoolQuestion ? DecideBoolAnswer : Q extends DecideChoiceQuestion<infer L> ? DecideChoiceAnswer<L> : Q extends DecideScoreQuestion ? DecideScoreAnswer : never;
603
+
604
+ declare interface DecideBoolAnswer {
605
+ readonly type: "bool";
606
+ /** P(yes), from 0 to 1. */
607
+ readonly probability: number;
608
+ }
609
+
610
+ /** A yes/no question. `criteria` says what yes and what no mean; omit it to leave both open. */
611
+ declare interface DecideBoolQuestion {
612
+ readonly type: "bool";
613
+ readonly instructions: string;
614
+ readonly criteria?: {
615
+ readonly true: string;
616
+ readonly false: string;
617
+ };
618
+ }
619
+
620
+ declare interface DecideChoiceAnswer<L extends string = string> {
621
+ readonly type: "choice";
622
+ readonly choice: L;
623
+ readonly confidence: number;
624
+ /** P(label) for every offered label. */
625
+ readonly probabilities: Readonly<Record<L, number>>;
626
+ }
627
+
628
+ /** A choice among labels. Each label maps to what it means; an empty string leaves it open. */
629
+ declare interface DecideChoiceQuestion<L extends string = string> {
630
+ readonly type: "choice";
631
+ readonly instructions: string;
632
+ readonly criteria: Readonly<Record<L, string>>;
633
+ }
634
+
635
+ declare type DecideModelId = "jev" | "clef" | "clef-flash";
636
+
637
+ declare type DecideQuestion = DecideBoolQuestion | DecideChoiceQuestion | DecideScoreQuestion;
638
+
639
+ /** Questions keyed by the name each answer comes back under. */
640
+ declare type DecideQuestions = Readonly<Record<string, DecideQuestion>>;
641
+
642
+ declare interface DecideRequest<Q extends DecideQuestions = DecideQuestions> {
643
+ /** Defaults to `jev`. */
644
+ readonly model?: DecideModelId;
645
+ readonly state: DecideState;
646
+ readonly questions: Q;
647
+ }
648
+
649
+ declare interface DecideScoreAnswer {
650
+ readonly type: "score";
651
+ /** The expected level, from 0 to the number of levels minus one. */
652
+ readonly score: number;
653
+ readonly confidence: number;
654
+ }
655
+
656
+ /** A score over ordered levels: the first criterion scores 0, the next 1, and so on. */
657
+ declare interface DecideScoreQuestion {
658
+ readonly type: "score";
659
+ readonly instructions: string;
660
+ readonly criteria: readonly string[];
661
+ }
662
+
663
+ /**
664
+ * What a decide call reads. A JSON value is sent as JSON; every value must survive
665
+ * `JSON.stringify` unchanged.
666
+ */
667
+ declare type DecideState = string | object;
668
+
669
+ /** Every asked question has an answer of its own kind. */
670
+ declare interface Decision<Q extends DecideQuestions = DecideQuestions> {
671
+ readonly model: DecideModelId;
672
+ readonly answers: {
673
+ readonly [K in keyof Q]: DecideAnswerFor<Q[K]>;
674
+ };
675
+ readonly usage?: SystemOneTokenUsage;
676
+ }
677
+
596
678
  /** One skill entry from a plugin's manifest (`targets.kay.agent.contributes.skills`). */
597
679
  export declare interface DeclaredSkillContribution {
598
680
  readonly localId: string;
@@ -714,6 +796,8 @@ declare const DollarSign = "$";
714
796
 
715
797
  declare const Dot = ".";
716
798
 
799
+ declare type DurationUnit = "seconds" | "minutes" | "hours" | "days" | "weeks" | "months" | "years";
800
+
717
801
  declare const Element: (input: string) => [unknown, string] | [];
718
802
 
719
803
  declare const ElementBase: (input: string) => [unknown, string] | [];
@@ -748,6 +832,18 @@ declare function Enum<Values extends TEnumValue[]>(values: readonly [...Values],
748
832
  /** Creates an Enum type from a TypeScript enum declaration. */
749
833
  declare function Enum<Enum extends TTypeScriptEnumLike>(value: Enum, options?: TSchemaOptions): TEnum<TTypeScriptEnumToEnumValues<Enum>>;
750
834
 
835
+ declare interface EstimateDistribution<V> {
836
+ readonly value: V | null;
837
+ readonly mean?: V;
838
+ readonly median?: V;
839
+ readonly p10?: V;
840
+ readonly p90?: V;
841
+ /** P(value < min). */
842
+ readonly pBelow?: number;
843
+ /** P(value > max). */
844
+ readonly pAbove?: number;
845
+ }
846
+
751
847
  /** Applies an Evaluate action to a type. */
752
848
  declare function Evaluate<Type extends TSchema>(type: Type, options?: TSchemaOptions): TEvaluate<Type>;
753
849
 
@@ -925,13 +1021,135 @@ declare interface ExtensionPaths {
925
1021
  /** Applies an Extract action using the given types. */
926
1022
  declare function Extract_2<Left extends TSchema, Right extends TSchema>(left: Left, right: Right, options?: TSchemaOptions): TExtract<Left, Right>;
927
1023
 
1024
+ 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;
1025
+
1026
+ /** `date` answers are ISO dates, `time` ISO times, `datetime` ISO date-times. */
1027
+ declare interface ExtractDateTimeField extends ExtractFieldBase {
1028
+ readonly type: "date" | "time" | "datetime";
1029
+ }
1030
+
928
1031
  /** Creates a deferred Extract action. */
929
1032
  declare function ExtractDeferred<Left extends TSchema, Right extends TSchema>(left: Left, right: Right, options?: TSchemaOptions): TExtractDeferred<Left, Right>;
930
1033
 
1034
+ declare interface ExtractDurationField extends ExtractFieldBase {
1035
+ readonly type: "duration";
1036
+ /** Seconds when omitted. */
1037
+ readonly unit?: DurationUnit;
1038
+ readonly integer?: boolean;
1039
+ readonly decimals?: number;
1040
+ }
1041
+
1042
+ declare interface ExtractEstimateAnswer<V = number | string> extends EstimateDistribution<V> {
1043
+ readonly type: "estimate";
1044
+ }
1045
+
1046
+ /** A distribution over one value. `min`/`max` are numbers, or ISO dates for a date estimate. */
1047
+ declare interface ExtractEstimateField extends ExtractFieldBase {
1048
+ readonly type: "estimate";
1049
+ readonly min: number | string;
1050
+ readonly max: number | string;
1051
+ /** Grid step: a positive number (days for a date estimate), `month` or `year`. */
1052
+ readonly step?: number | "month" | "year";
1053
+ readonly scale?: "linear" | "log";
1054
+ readonly unit?: string;
1055
+ }
1056
+
1057
+ declare type ExtractField = ExtractTextField | ExtractNumberField | ExtractDateTimeField | ExtractDurationField | ExtractListField | ExtractEstimateField | ExtractForecastField;
1058
+
1059
+ declare interface ExtractFieldBase {
1060
+ readonly instructions?: string;
1061
+ /** P(null) above which the value is null. Clairic's default is 0.5. */
1062
+ readonly nullThreshold?: number;
1063
+ }
1064
+
1065
+ /** Fields keyed by name. A name matches `^[A-Za-z_][A-Za-z0-9_.\-]{0,63}$`. */
1066
+ declare type ExtractFields = Readonly<Record<string, ExtractField>>;
1067
+
1068
+ declare interface ExtractForecastAnswer {
1069
+ readonly type: "forecast";
1070
+ /** One value per step; `null` when the state does not determine the forecast. */
1071
+ readonly value: readonly number[] | null;
1072
+ readonly steps: readonly EstimateDistribution<number>[];
1073
+ }
1074
+
1075
+ /** One distribution per future step. */
1076
+ declare interface ExtractForecastField extends ExtractFieldBase {
1077
+ readonly type: "forecast";
1078
+ readonly min: number;
1079
+ readonly max: number;
1080
+ /** Number of steps, 1 to 64. */
1081
+ readonly horizon: number;
1082
+ readonly interval?: ForecastInterval;
1083
+ readonly scale?: "linear" | "log";
1084
+ readonly unit?: string;
1085
+ }
1086
+
1087
+ declare interface Extraction<F extends ExtractFields = ExtractFields> {
1088
+ readonly model: ExtractModelId;
1089
+ readonly answers: {
1090
+ readonly [K in keyof F]: ExtractAnswerFor<F[K]>;
1091
+ };
1092
+ /** The state was cut to fit the model's context. */
1093
+ readonly truncated: boolean;
1094
+ readonly usage?: SystemOneTokenUsage;
1095
+ }
1096
+
1097
+ declare interface ExtractListAnswer<V> {
1098
+ readonly type: "list";
1099
+ readonly value: readonly V[] | null;
1100
+ readonly confidence?: number;
1101
+ /** One per item in `value`. */
1102
+ readonly confidences?: readonly number[];
1103
+ readonly spans?: readonly TextSpan[];
1104
+ }
1105
+
1106
+ declare interface ExtractListField extends ExtractFieldBase {
1107
+ readonly type: "list";
1108
+ readonly items: "text" | "number" | "date";
1109
+ readonly decimals?: number;
1110
+ }
1111
+
1112
+ declare type ExtractModelId = "clairic";
1113
+
1114
+ declare interface ExtractNumberField extends ExtractFieldBase {
1115
+ readonly type: "number";
1116
+ readonly unit?: string;
1117
+ readonly integer?: boolean;
1118
+ /** 0 to 6. */
1119
+ readonly decimals?: number;
1120
+ }
1121
+
1122
+ declare interface ExtractRequest<F extends ExtractFields = ExtractFields> {
1123
+ readonly model: ExtractModelId;
1124
+ /** Text only; JSON is not accepted. */
1125
+ readonly state: string;
1126
+ readonly fields: F;
1127
+ /** ISO date that anchors dates written without a year. */
1128
+ readonly referenceDate?: string;
1129
+ }
1130
+
1131
+ declare interface ExtractTextField extends ExtractFieldBase {
1132
+ readonly type: "text";
1133
+ }
1134
+
1135
+ declare interface ExtractValueAnswer<T extends "text" | "number" | "date" | "time" | "datetime" | "duration", V> {
1136
+ readonly type: T;
1137
+ /** `null` when the state does not determine the value. */
1138
+ readonly value: V | null;
1139
+ /** The best candidate even when `value` is null. */
1140
+ readonly guess?: V;
1141
+ readonly confidence?: number;
1142
+ readonly pNull?: number;
1143
+ readonly span?: TextSpan;
1144
+ readonly unit?: string;
1145
+ }
1146
+
931
1147
  declare const Factor: (input: string) => [unknown, string] | [];
932
1148
 
933
1149
  declare function FactorMapping(input: [unknown, unknown, unknown, unknown, unknown]): unknown;
934
1150
 
1151
+ declare type ForecastInterval = "step" | "minute" | "hour" | "day" | "week" | "month" | "quarter" | "year";
1152
+
935
1153
  /** Creates a Function type. */
936
1154
  declare function _Function_<Parameters extends TSchema[], ReturnType extends TSchema>(parameters: [...Parameters], returnType: ReturnType, options?: TSchemaOptions): TFunction<Parameters, ReturnType>;
937
1155
 
@@ -1812,6 +2030,15 @@ declare interface KayAgentPluginApi {
1812
2030
  * guard it with `if (api.withJev !== undefined)`.
1813
2031
  */
1814
2032
  readonly withJev: WithJev;
2033
+ /**
2034
+ * System One: fast, cheap judgment calls (`decide`) and typed field extraction (`extract`) on
2035
+ * small models (Jev, Clef, Clef Flash, Clairic). Each call is checked against `jev.use`; a call
2036
+ * that cannot be served or is not permitted throws a `SystemOneError` whose `cause.kind` says
2037
+ * why, so put the feature's cheaper path in the call's own `catch`. Always present, on every
2038
+ * host; a host with no System One throws `not-served`. Types: `@bonsai/plugin-sdk/system-one`
2039
+ * (SDK 0.13.8).
2040
+ */
2041
+ readonly systemOne: SystemOneClient;
1815
2042
  /**
1816
2043
  * The daemon's clock and the time zone the user is in, read together on each `snapshot()` call.
1817
2044
  * Always present and ungated: it confers no authority, since a plugin runs in the daemon's
@@ -4373,6 +4600,74 @@ declare const StringPattern = ".*";
4373
4600
  /** Creates a Symbol type. */
4374
4601
  declare function Symbol_2(options?: TSchemaOptions): TSymbol;
4375
4602
 
4603
+ declare interface SystemOneCallOptions {
4604
+ readonly signal?: AbortSignal;
4605
+ /** Bounds the whole call, retries included. */
4606
+ readonly timeoutMs?: number;
4607
+ }
4608
+
4609
+ declare interface SystemOneClient {
4610
+ decide<const Q extends DecideQuestions>(request: DecideRequest<Q>, options?: SystemOneCallOptions): Promise<Decision<Q>>;
4611
+ extract<const F extends ExtractFields>(request: ExtractRequest<F>, options?: SystemOneCallOptions): Promise<Extraction<F>>;
4612
+ /** Whether some provider in the current order can serve `(kind, model)`. Never rejects. */
4613
+ availability(kind: SystemOneKind, model?: SystemOneModelId): Promise<Availability>;
4614
+ }
4615
+
4616
+ /**
4617
+ * Why a call failed or a provider can't serve, as a closed set. Never prose, and never the
4618
+ * vendor's body: bodies can echo the request's state.
4619
+ */
4620
+ declare type SystemOneFailureCause = {
4621
+ readonly kind: "no-credential";
4622
+ } | {
4623
+ readonly kind: "credential-store";
4624
+ } | {
4625
+ readonly kind: "not-served";
4626
+ } | {
4627
+ readonly kind: "not-permitted";
4628
+ } | {
4629
+ readonly kind: "unknown-model";
4630
+ } | {
4631
+ readonly kind: "invalid-request";
4632
+ readonly detail: string;
4633
+ } | {
4634
+ readonly kind: "too-large";
4635
+ } | {
4636
+ readonly kind: "http";
4637
+ readonly status: number;
4638
+ } | {
4639
+ readonly kind: "transport";
4640
+ } | {
4641
+ readonly kind: "timeout";
4642
+ } | {
4643
+ readonly kind: "aborted";
4644
+ } | {
4645
+ readonly kind: "invalid-answer";
4646
+ };
4647
+
4648
+ /**
4649
+ * ---
4650
+ * responsibility: The data shapes of the System One surface: models, the decide and extract
4651
+ * vocabularies, providers, and the failure causes.
4652
+ * owns:
4653
+ * - The caller-facing question, field, answer, and result types, in Bonsai's own words
4654
+ * (`bool` for yes/no, camelCase options). The vendors' words (`noul`, snake_case) appear
4655
+ * only in `wire.ts`.
4656
+ * - {@link SystemOneProvider}, the seam a transport implements.
4657
+ * does_not_own:
4658
+ * - Which models exist (`models.ts`), how answers are checked (`wire.ts`), or how a provider is
4659
+ * picked (`system-one-client.ts`).
4660
+ * ---
4661
+ */
4662
+ declare type SystemOneKind = "decide" | "extract";
4663
+
4664
+ declare type SystemOneModelId = DecideModelId | ExtractModelId;
4665
+
4666
+ declare interface SystemOneTokenUsage {
4667
+ readonly inputTokens: number;
4668
+ readonly outputTokens: number;
4669
+ }
4670
+
4376
4671
  declare namespace T {
4377
4672
  export {
4378
4673
  Codec,
@@ -5417,6 +5712,9 @@ declare type TExtractType<Left extends TSchema, Right extends TSchema, Check ext
5417
5712
 
5418
5713
  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);
5419
5714
 
5715
+ /** `[start, end)` character offsets into the state. */
5716
+ declare type TextSpan = readonly [number, number];
5717
+
5420
5718
  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] : [];
5421
5719
 
5422
5720
  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);
@@ -741,6 +741,68 @@ function unavailableInteractionSurfaces(message) {
741
741
  };
742
742
  }
743
743
 
744
+ // packages/system-one/dist/errors.js
745
+ var SystemOneError = class extends Error {
746
+ cause;
747
+ kind;
748
+ model;
749
+ /** The provider that failed; absent when no provider was tried. */
750
+ providerId;
751
+ constructor(init) {
752
+ super(describe(init));
753
+ this.name = "SystemOneError";
754
+ this.cause = init.cause;
755
+ this.kind = init.kind;
756
+ this.model = init.model;
757
+ this.providerId = init.providerId;
758
+ }
759
+ };
760
+ function describe(init) {
761
+ const where = init.providerId === void 0 ? "" : ` on provider ${init.providerId}`;
762
+ const detail = init.cause.kind === "http" ? ` (HTTP ${init.cause.status})` : init.cause.kind === "invalid-request" ? ` (${init.cause.detail})` : "";
763
+ return `System One ${init.kind} on ${init.model}${where} failed: ${init.cause.kind}${detail}.`;
764
+ }
765
+
766
+ // packages/system-one/dist/models.js
767
+ var DEFAULT_DECIDE_MODEL = "jev";
768
+ var SYSTEM_ONE_LIMITS = {
769
+ /** The serialized request body, in bytes. */
770
+ maxBodyBytes: 64 * 1024,
771
+ maxQuestions: 8,
772
+ maxFields: 32,
773
+ minChoiceOptions: 2,
774
+ maxChoiceOptions: 255,
775
+ minScoreLevels: 2,
776
+ maxScoreLevels: 10,
777
+ maxForecastHorizon: 64
778
+ };
779
+
780
+ // packages/system-one/dist/unavailable.js
781
+ var NOT_SERVED = {
782
+ available: false,
783
+ reason: "This host has no System One models.",
784
+ cause: { kind: "not-served" }
785
+ };
786
+ function createUnavailableSystemOneClient() {
787
+ return {
788
+ decide(request) {
789
+ return Promise.reject(new SystemOneError({
790
+ kind: "decide",
791
+ model: request.model ?? DEFAULT_DECIDE_MODEL,
792
+ cause: { kind: "not-served" }
793
+ }));
794
+ },
795
+ extract(request) {
796
+ return Promise.reject(new SystemOneError({
797
+ kind: "extract",
798
+ model: request.model,
799
+ cause: { kind: "not-served" }
800
+ }));
801
+ },
802
+ availability: () => Promise.resolve(NOT_SERVED)
803
+ };
804
+ }
805
+
744
806
  // packages/plugin-sdk/dist/disclosure/probe-kay-agent-capabilities.js
745
807
  var inertResult = () => new Promise(() => {
746
808
  });
@@ -784,6 +846,8 @@ function createKayAgentProbeCapabilityHandles() {
784
846
  interceptToolCall: () => {
785
847
  },
786
848
  withJev: INERT_WITH_JEV,
849
+ // Throws `not-served` at once, the outcome a plugin's own `catch` already handles.
850
+ systemOne: createUnavailableSystemOneClient(),
787
851
  // Fire-and-forget on the real api too, so dropping is the inert shape: nothing to hang on.
788
852
  events: { publish: () => {
789
853
  } },