@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 +7 -5
- package/THIRD-PARTY-INVENTORY.json +1 -1
- package/dist/disclosure.d.ts +298 -0
- package/dist/disclosure.js +64 -0
- package/dist/kay-agent-testing.d.ts +299 -1
- package/dist/kay-agent-testing.js +65 -0
- package/dist/kay-agent.d.ts +298 -0
- package/dist/kay-app.d.ts +325 -7
- package/dist/kay-app.js +13 -11
- package/dist/system-one.d.ts +321 -0
- package/dist/system-one.js +69 -0
- package/package.json +5 -1
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The client a host with no System One binds: every call throws `not-served` without touching the
|
|
3
|
+
* network, so a caller's own `catch` runs exactly as it would for an unavailable model.
|
|
4
|
+
*/
|
|
5
|
+
export declare function createUnavailableSystemOneClient(): SystemOneClient;
|
|
6
|
+
|
|
7
|
+
export declare type DecideAnswer = DecideBoolAnswer | DecideChoiceAnswer | DecideScoreAnswer;
|
|
8
|
+
|
|
9
|
+
export declare type DecideAnswerFor<Q> = Q extends DecideBoolQuestion ? DecideBoolAnswer : Q extends DecideChoiceQuestion<infer L> ? DecideChoiceAnswer<L> : Q extends DecideScoreQuestion ? DecideScoreAnswer : never;
|
|
10
|
+
|
|
11
|
+
export declare interface DecideBoolAnswer {
|
|
12
|
+
readonly type: "bool";
|
|
13
|
+
/** P(yes), from 0 to 1. */
|
|
14
|
+
readonly probability: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** A yes/no question. `criteria` says what yes and what no mean; omit it to leave both open. */
|
|
18
|
+
export declare interface DecideBoolQuestion {
|
|
19
|
+
readonly type: "bool";
|
|
20
|
+
readonly instructions: string;
|
|
21
|
+
readonly criteria?: {
|
|
22
|
+
readonly true: string;
|
|
23
|
+
readonly false: string;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export declare interface DecideChoiceAnswer<L extends string = string> {
|
|
28
|
+
readonly type: "choice";
|
|
29
|
+
readonly choice: L;
|
|
30
|
+
readonly confidence: number;
|
|
31
|
+
/** P(label) for every offered label. */
|
|
32
|
+
readonly probabilities: Readonly<Record<L, number>>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** A choice among labels. Each label maps to what it means; an empty string leaves it open. */
|
|
36
|
+
export declare interface DecideChoiceQuestion<L extends string = string> {
|
|
37
|
+
readonly type: "choice";
|
|
38
|
+
readonly instructions: string;
|
|
39
|
+
readonly criteria: Readonly<Record<L, string>>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export declare type DecideModelId = "jev" | "clef" | "clef-flash";
|
|
43
|
+
|
|
44
|
+
export declare type DecideQuestion = DecideBoolQuestion | DecideChoiceQuestion | DecideScoreQuestion;
|
|
45
|
+
|
|
46
|
+
/** Questions keyed by the name each answer comes back under. */
|
|
47
|
+
export declare type DecideQuestions = Readonly<Record<string, DecideQuestion>>;
|
|
48
|
+
|
|
49
|
+
export declare interface DecideRequest<Q extends DecideQuestions = DecideQuestions> {
|
|
50
|
+
/** Defaults to `jev`. */
|
|
51
|
+
readonly model?: DecideModelId;
|
|
52
|
+
readonly state: DecideState;
|
|
53
|
+
readonly questions: Q;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export declare interface DecideScoreAnswer {
|
|
57
|
+
readonly type: "score";
|
|
58
|
+
/** The expected level, from 0 to the number of levels minus one. */
|
|
59
|
+
readonly score: number;
|
|
60
|
+
readonly confidence: number;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** A score over ordered levels: the first criterion scores 0, the next 1, and so on. */
|
|
64
|
+
export declare interface DecideScoreQuestion {
|
|
65
|
+
readonly type: "score";
|
|
66
|
+
readonly instructions: string;
|
|
67
|
+
readonly criteria: readonly string[];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* What a decide call reads. A JSON value is sent as JSON; every value must survive
|
|
72
|
+
* `JSON.stringify` unchanged.
|
|
73
|
+
*/
|
|
74
|
+
export declare type DecideState = string | object;
|
|
75
|
+
|
|
76
|
+
/** Every asked question has an answer of its own kind. */
|
|
77
|
+
export declare interface Decision<Q extends DecideQuestions = DecideQuestions> {
|
|
78
|
+
readonly model: DecideModelId;
|
|
79
|
+
readonly answers: {
|
|
80
|
+
readonly [K in keyof Q]: DecideAnswerFor<Q[K]>;
|
|
81
|
+
};
|
|
82
|
+
readonly usage?: SystemOneTokenUsage;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
declare type DurationUnit = "seconds" | "minutes" | "hours" | "days" | "weeks" | "months" | "years";
|
|
86
|
+
|
|
87
|
+
export declare interface EstimateDistribution<V> {
|
|
88
|
+
readonly value: V | null;
|
|
89
|
+
readonly mean?: V;
|
|
90
|
+
readonly median?: V;
|
|
91
|
+
readonly p10?: V;
|
|
92
|
+
readonly p90?: V;
|
|
93
|
+
/** P(value < min). */
|
|
94
|
+
readonly pBelow?: number;
|
|
95
|
+
/** P(value > max). */
|
|
96
|
+
readonly pAbove?: number;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export declare type ExtractAnswer = ExtractAnswerFor<ExtractField>;
|
|
100
|
+
|
|
101
|
+
export 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;
|
|
102
|
+
|
|
103
|
+
/** `date` answers are ISO dates, `time` ISO times, `datetime` ISO date-times. */
|
|
104
|
+
export declare interface ExtractDateTimeField extends ExtractFieldBase {
|
|
105
|
+
readonly type: "date" | "time" | "datetime";
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export declare interface ExtractDurationField extends ExtractFieldBase {
|
|
109
|
+
readonly type: "duration";
|
|
110
|
+
/** Seconds when omitted. */
|
|
111
|
+
readonly unit?: DurationUnit;
|
|
112
|
+
readonly integer?: boolean;
|
|
113
|
+
readonly decimals?: number;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export declare interface ExtractEstimateAnswer<V = number | string> extends EstimateDistribution<V> {
|
|
117
|
+
readonly type: "estimate";
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** A distribution over one value. `min`/`max` are numbers, or ISO dates for a date estimate. */
|
|
121
|
+
export declare interface ExtractEstimateField extends ExtractFieldBase {
|
|
122
|
+
readonly type: "estimate";
|
|
123
|
+
readonly min: number | string;
|
|
124
|
+
readonly max: number | string;
|
|
125
|
+
/** Grid step: a positive number (days for a date estimate), `month` or `year`. */
|
|
126
|
+
readonly step?: number | "month" | "year";
|
|
127
|
+
readonly scale?: "linear" | "log";
|
|
128
|
+
readonly unit?: string;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export declare type ExtractField = ExtractTextField | ExtractNumberField | ExtractDateTimeField | ExtractDurationField | ExtractListField | ExtractEstimateField | ExtractForecastField;
|
|
132
|
+
|
|
133
|
+
declare interface ExtractFieldBase {
|
|
134
|
+
readonly instructions?: string;
|
|
135
|
+
/** P(null) above which the value is null. Clairic's default is 0.5. */
|
|
136
|
+
readonly nullThreshold?: number;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Fields keyed by name. A name matches `^[A-Za-z_][A-Za-z0-9_.\-]{0,63}$`. */
|
|
140
|
+
export declare type ExtractFields = Readonly<Record<string, ExtractField>>;
|
|
141
|
+
|
|
142
|
+
export declare interface ExtractForecastAnswer {
|
|
143
|
+
readonly type: "forecast";
|
|
144
|
+
/** One value per step; `null` when the state does not determine the forecast. */
|
|
145
|
+
readonly value: readonly number[] | null;
|
|
146
|
+
readonly steps: readonly EstimateDistribution<number>[];
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** One distribution per future step. */
|
|
150
|
+
export declare interface ExtractForecastField extends ExtractFieldBase {
|
|
151
|
+
readonly type: "forecast";
|
|
152
|
+
readonly min: number;
|
|
153
|
+
readonly max: number;
|
|
154
|
+
/** Number of steps, 1 to 64. */
|
|
155
|
+
readonly horizon: number;
|
|
156
|
+
readonly interval?: ForecastInterval;
|
|
157
|
+
readonly scale?: "linear" | "log";
|
|
158
|
+
readonly unit?: string;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export declare interface Extraction<F extends ExtractFields = ExtractFields> {
|
|
162
|
+
readonly model: ExtractModelId;
|
|
163
|
+
readonly answers: {
|
|
164
|
+
readonly [K in keyof F]: ExtractAnswerFor<F[K]>;
|
|
165
|
+
};
|
|
166
|
+
/** The state was cut to fit the model's context. */
|
|
167
|
+
readonly truncated: boolean;
|
|
168
|
+
readonly usage?: SystemOneTokenUsage;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export declare interface ExtractListAnswer<V> {
|
|
172
|
+
readonly type: "list";
|
|
173
|
+
readonly value: readonly V[] | null;
|
|
174
|
+
readonly confidence?: number;
|
|
175
|
+
/** One per item in `value`. */
|
|
176
|
+
readonly confidences?: readonly number[];
|
|
177
|
+
readonly spans?: readonly TextSpan[];
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export declare interface ExtractListField extends ExtractFieldBase {
|
|
181
|
+
readonly type: "list";
|
|
182
|
+
readonly items: "text" | "number" | "date";
|
|
183
|
+
readonly decimals?: number;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export declare type ExtractModelId = "clairic";
|
|
187
|
+
|
|
188
|
+
export declare interface ExtractNumberField extends ExtractFieldBase {
|
|
189
|
+
readonly type: "number";
|
|
190
|
+
readonly unit?: string;
|
|
191
|
+
readonly integer?: boolean;
|
|
192
|
+
/** 0 to 6. */
|
|
193
|
+
readonly decimals?: number;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export declare interface ExtractRequest<F extends ExtractFields = ExtractFields> {
|
|
197
|
+
readonly model: ExtractModelId;
|
|
198
|
+
/** Text only; JSON is not accepted. */
|
|
199
|
+
readonly state: string;
|
|
200
|
+
readonly fields: F;
|
|
201
|
+
/** ISO date that anchors dates written without a year. */
|
|
202
|
+
readonly referenceDate?: string;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export declare interface ExtractTextField extends ExtractFieldBase {
|
|
206
|
+
readonly type: "text";
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export declare interface ExtractValueAnswer<T extends "text" | "number" | "date" | "time" | "datetime" | "duration", V> {
|
|
210
|
+
readonly type: T;
|
|
211
|
+
/** `null` when the state does not determine the value. */
|
|
212
|
+
readonly value: V | null;
|
|
213
|
+
/** The best candidate even when `value` is null. */
|
|
214
|
+
readonly guess?: V;
|
|
215
|
+
readonly confidence?: number;
|
|
216
|
+
readonly pNull?: number;
|
|
217
|
+
readonly span?: TextSpan;
|
|
218
|
+
readonly unit?: string;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
declare type ForecastInterval = "step" | "minute" | "hour" | "day" | "week" | "month" | "quarter" | "year";
|
|
222
|
+
|
|
223
|
+
export declare function isSystemOneError(error: unknown): error is SystemOneError;
|
|
224
|
+
|
|
225
|
+
export declare interface SystemOneAvailability {
|
|
226
|
+
readonly available: boolean;
|
|
227
|
+
readonly reason?: string;
|
|
228
|
+
readonly cause?: SystemOneFailureCause;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export declare interface SystemOneCallOptions {
|
|
232
|
+
readonly signal?: AbortSignal;
|
|
233
|
+
/** Bounds the whole call, retries included. */
|
|
234
|
+
readonly timeoutMs?: number;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export declare interface SystemOneClient {
|
|
238
|
+
decide<const Q extends DecideQuestions>(request: DecideRequest<Q>, options?: SystemOneCallOptions): Promise<Decision<Q>>;
|
|
239
|
+
extract<const F extends ExtractFields>(request: ExtractRequest<F>, options?: SystemOneCallOptions): Promise<Extraction<F>>;
|
|
240
|
+
/** Whether some provider in the current order can serve `(kind, model)`. Never rejects. */
|
|
241
|
+
availability(kind: SystemOneKind, model?: SystemOneModelId): Promise<SystemOneAvailability>;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* The one error a System One call rejects with. Its message names the cause, model, and
|
|
246
|
+
* provider, never the vendor's body: bodies can echo the request's state, and this error
|
|
247
|
+
* reaches logs.
|
|
248
|
+
*/
|
|
249
|
+
export declare class SystemOneError extends Error {
|
|
250
|
+
readonly cause: SystemOneFailureCause;
|
|
251
|
+
readonly kind: SystemOneKind;
|
|
252
|
+
readonly model: string;
|
|
253
|
+
/** The provider that failed; absent when no provider was tried. */
|
|
254
|
+
readonly providerId: string | undefined;
|
|
255
|
+
constructor(init: {
|
|
256
|
+
readonly cause: SystemOneFailureCause;
|
|
257
|
+
readonly kind: SystemOneKind;
|
|
258
|
+
readonly model: string;
|
|
259
|
+
readonly providerId?: string | undefined;
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Why a call failed or a provider can't serve, as a closed set. Never prose, and never the
|
|
265
|
+
* vendor's body: bodies can echo the request's state.
|
|
266
|
+
*/
|
|
267
|
+
export declare type SystemOneFailureCause = {
|
|
268
|
+
readonly kind: "no-credential";
|
|
269
|
+
} | {
|
|
270
|
+
readonly kind: "credential-store";
|
|
271
|
+
} | {
|
|
272
|
+
readonly kind: "not-served";
|
|
273
|
+
} | {
|
|
274
|
+
readonly kind: "not-permitted";
|
|
275
|
+
} | {
|
|
276
|
+
readonly kind: "unknown-model";
|
|
277
|
+
} | {
|
|
278
|
+
readonly kind: "invalid-request";
|
|
279
|
+
readonly detail: string;
|
|
280
|
+
} | {
|
|
281
|
+
readonly kind: "too-large";
|
|
282
|
+
} | {
|
|
283
|
+
readonly kind: "http";
|
|
284
|
+
readonly status: number;
|
|
285
|
+
} | {
|
|
286
|
+
readonly kind: "transport";
|
|
287
|
+
} | {
|
|
288
|
+
readonly kind: "timeout";
|
|
289
|
+
} | {
|
|
290
|
+
readonly kind: "aborted";
|
|
291
|
+
} | {
|
|
292
|
+
readonly kind: "invalid-answer";
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* ---
|
|
297
|
+
* responsibility: The data shapes of the System One surface: models, the decide and extract
|
|
298
|
+
* vocabularies, providers, and the failure causes.
|
|
299
|
+
* owns:
|
|
300
|
+
* - The caller-facing question, field, answer, and result types, in Bonsai's own words
|
|
301
|
+
* (`bool` for yes/no, camelCase options). The vendors' words (`noul`, snake_case) appear
|
|
302
|
+
* only in `wire.ts`.
|
|
303
|
+
* - {@link SystemOneProvider}, the seam a transport implements.
|
|
304
|
+
* does_not_own:
|
|
305
|
+
* - Which models exist (`models.ts`), how answers are checked (`wire.ts`), or how a provider is
|
|
306
|
+
* picked (`system-one-client.ts`).
|
|
307
|
+
* ---
|
|
308
|
+
*/
|
|
309
|
+
export declare type SystemOneKind = "decide" | "extract";
|
|
310
|
+
|
|
311
|
+
export declare type SystemOneModelId = DecideModelId | ExtractModelId;
|
|
312
|
+
|
|
313
|
+
export declare interface SystemOneTokenUsage {
|
|
314
|
+
readonly inputTokens: number;
|
|
315
|
+
readonly outputTokens: number;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/** `[start, end)` character offsets into the state. */
|
|
319
|
+
export declare type TextSpan = readonly [number, number];
|
|
320
|
+
|
|
321
|
+
export { }
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// packages/system-one/dist/errors.js
|
|
2
|
+
var SystemOneError = class extends Error {
|
|
3
|
+
cause;
|
|
4
|
+
kind;
|
|
5
|
+
model;
|
|
6
|
+
/** The provider that failed; absent when no provider was tried. */
|
|
7
|
+
providerId;
|
|
8
|
+
constructor(init) {
|
|
9
|
+
super(describe(init));
|
|
10
|
+
this.name = "SystemOneError";
|
|
11
|
+
this.cause = init.cause;
|
|
12
|
+
this.kind = init.kind;
|
|
13
|
+
this.model = init.model;
|
|
14
|
+
this.providerId = init.providerId;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
function describe(init) {
|
|
18
|
+
const where = init.providerId === void 0 ? "" : ` on provider ${init.providerId}`;
|
|
19
|
+
const detail = init.cause.kind === "http" ? ` (HTTP ${init.cause.status})` : init.cause.kind === "invalid-request" ? ` (${init.cause.detail})` : "";
|
|
20
|
+
return `System One ${init.kind} on ${init.model}${where} failed: ${init.cause.kind}${detail}.`;
|
|
21
|
+
}
|
|
22
|
+
function isSystemOneError(error) {
|
|
23
|
+
return error instanceof SystemOneError;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// packages/system-one/dist/models.js
|
|
27
|
+
var DEFAULT_DECIDE_MODEL = "jev";
|
|
28
|
+
var SYSTEM_ONE_LIMITS = {
|
|
29
|
+
/** The serialized request body, in bytes. */
|
|
30
|
+
maxBodyBytes: 64 * 1024,
|
|
31
|
+
maxQuestions: 8,
|
|
32
|
+
maxFields: 32,
|
|
33
|
+
minChoiceOptions: 2,
|
|
34
|
+
maxChoiceOptions: 255,
|
|
35
|
+
minScoreLevels: 2,
|
|
36
|
+
maxScoreLevels: 10,
|
|
37
|
+
maxForecastHorizon: 64
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// packages/system-one/dist/unavailable.js
|
|
41
|
+
var NOT_SERVED = {
|
|
42
|
+
available: false,
|
|
43
|
+
reason: "This host has no System One models.",
|
|
44
|
+
cause: { kind: "not-served" }
|
|
45
|
+
};
|
|
46
|
+
function createUnavailableSystemOneClient() {
|
|
47
|
+
return {
|
|
48
|
+
decide(request) {
|
|
49
|
+
return Promise.reject(new SystemOneError({
|
|
50
|
+
kind: "decide",
|
|
51
|
+
model: request.model ?? DEFAULT_DECIDE_MODEL,
|
|
52
|
+
cause: { kind: "not-served" }
|
|
53
|
+
}));
|
|
54
|
+
},
|
|
55
|
+
extract(request) {
|
|
56
|
+
return Promise.reject(new SystemOneError({
|
|
57
|
+
kind: "extract",
|
|
58
|
+
model: request.model,
|
|
59
|
+
cause: { kind: "not-served" }
|
|
60
|
+
}));
|
|
61
|
+
},
|
|
62
|
+
availability: () => Promise.resolve(NOT_SERVED)
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
export {
|
|
66
|
+
SystemOneError,
|
|
67
|
+
createUnavailableSystemOneClient,
|
|
68
|
+
isSystemOneError
|
|
69
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yaklabs-ai/plugin-sdk",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.8",
|
|
4
4
|
"description": "The Kay plugin SDK — types and helpers for authoring a Kay directory plugin.",
|
|
5
5
|
"author": "YakLabs",
|
|
6
6
|
"type": "module",
|
|
@@ -64,6 +64,10 @@
|
|
|
64
64
|
"./vendored-mcp": {
|
|
65
65
|
"types": "./dist/vendored-mcp.d.ts",
|
|
66
66
|
"default": "./dist/vendored-mcp.js"
|
|
67
|
+
},
|
|
68
|
+
"./system-one": {
|
|
69
|
+
"types": "./dist/system-one.d.ts",
|
|
70
|
+
"default": "./dist/system-one.js"
|
|
67
71
|
}
|
|
68
72
|
},
|
|
69
73
|
"files": [
|