@swissspidy/belay-core 0.1.0 → 0.1.1
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/dist/calibration.d.ts +11 -0
- package/dist/calibration.d.ts.map +1 -0
- package/dist/calibration.js +68 -0
- package/dist/calibration.js.map +1 -0
- package/dist/cloud.d.ts +37 -0
- package/dist/cloud.d.ts.map +1 -0
- package/dist/cloud.js +43 -0
- package/dist/cloud.js.map +1 -0
- package/dist/confidence.d.ts +22 -0
- package/dist/confidence.d.ts.map +1 -0
- package/dist/confidence.js +30 -0
- package/dist/confidence.js.map +1 -0
- package/dist/cost.d.ts +60 -0
- package/dist/cost.d.ts.map +1 -0
- package/dist/cost.js +99 -0
- package/dist/cost.js.map +1 -0
- package/dist/errors.d.ts +24 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +16 -0
- package/dist/errors.js.map +1 -0
- package/dist/hash.d.ts +5 -0
- package/dist/hash.d.ts.map +1 -0
- package/dist/hash.js +19 -0
- package/dist/hash.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/schema.d.ts +33 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +174 -0
- package/dist/schema.js.map +1 -0
- package/dist/task.d.ts +7 -0
- package/dist/task.d.ts.map +1 -0
- package/dist/task.js +288 -0
- package/dist/task.js.map +1 -0
- package/dist/types.d.ts +396 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/package.json +3 -2
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { CalibrationFile } from './types.js';
|
|
2
|
+
export declare const CALIBRATION_VERSION = 1;
|
|
3
|
+
/**
|
|
4
|
+
* Validates an unknown value as a v1 calibration file. When `task` is given, also checks
|
|
5
|
+
* that the file belongs to that task. Throws `BelayError('invalid-calibration')`.
|
|
6
|
+
*/
|
|
7
|
+
export declare function parseCalibration(data: unknown, task?: string): CalibrationFile;
|
|
8
|
+
/** Threshold for a local top label: the per-label override if present, else the global one. */
|
|
9
|
+
export declare function thresholdFor(calibration: Pick<CalibrationFile, 'threshold' | 'thresholds'>, label?: string): number;
|
|
10
|
+
export declare function loadCalibration(source: CalibrationFile | string | URL | (() => Promise<CalibrationFile>), task?: string): Promise<CalibrationFile>;
|
|
11
|
+
//# sourceMappingURL=calibration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calibration.d.ts","sourceRoot":"","sources":["../src/calibration.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAOrC;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,eAAe,CA2B9E;AAED,+FAA+F;AAC/F,wBAAgB,YAAY,CAAC,WAAW,EAAE,IAAI,CAAC,eAAe,EAAE,WAAW,GAAG,YAAY,CAAC,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAKnH;AAED,wBAAsB,eAAe,CACnC,MAAM,EAAE,eAAe,GAAG,MAAM,GAAG,GAAG,GAAG,CAAC,MAAM,OAAO,CAAC,eAAe,CAAC,CAAC,EACzE,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,eAAe,CAAC,CAU1B"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { BelayError } from './errors.js';
|
|
2
|
+
export const CALIBRATION_VERSION = 1;
|
|
3
|
+
const isNum = (v) => typeof v === 'number' && Number.isFinite(v);
|
|
4
|
+
const isProb = (v) => isNum(v) && v >= 0 && v <= 1;
|
|
5
|
+
/** A threshold above 1 keeps nothing local: every run escalates. */
|
|
6
|
+
const isThreshold = (v) => isNum(v) && v >= 0;
|
|
7
|
+
/**
|
|
8
|
+
* Validates an unknown value as a v1 calibration file. When `task` is given, also checks
|
|
9
|
+
* that the file belongs to that task. Throws `BelayError('invalid-calibration')`.
|
|
10
|
+
*/
|
|
11
|
+
export function parseCalibration(data, task) {
|
|
12
|
+
const fail = (msg) => {
|
|
13
|
+
throw new BelayError('invalid-calibration', `Invalid calibration file: ${msg}`);
|
|
14
|
+
};
|
|
15
|
+
if (!data || typeof data !== 'object')
|
|
16
|
+
fail('not an object');
|
|
17
|
+
const c = data;
|
|
18
|
+
if (c.version !== CALIBRATION_VERSION)
|
|
19
|
+
fail(`unsupported version ${String(c.version)}`);
|
|
20
|
+
if (typeof c.task !== 'string')
|
|
21
|
+
fail('missing task');
|
|
22
|
+
if (task !== undefined && c.task !== task)
|
|
23
|
+
fail(`file is for task "${c.task}", not "${task}"`);
|
|
24
|
+
if (typeof c.schemaFingerprint !== 'string')
|
|
25
|
+
fail('missing schemaFingerprint');
|
|
26
|
+
if (!isThreshold(c.threshold))
|
|
27
|
+
fail('threshold must be a number ≥ 0');
|
|
28
|
+
if (c.thresholds !== undefined) {
|
|
29
|
+
if (typeof c.thresholds !== 'object' || c.thresholds === null)
|
|
30
|
+
fail('thresholds must be an object');
|
|
31
|
+
for (const [label, t] of Object.entries(c.thresholds)) {
|
|
32
|
+
if (!isThreshold(t))
|
|
33
|
+
fail(`thresholds["${label}"] must be a number ≥ 0`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (!c.expected || !isProb(c.expected.localShare) || !isProb(c.expected.accuracy)) {
|
|
37
|
+
fail('expected.accuracy and expected.localShare must be numbers in [0, 1]');
|
|
38
|
+
}
|
|
39
|
+
if (!Array.isArray(c.curve))
|
|
40
|
+
fail('curve must be an array');
|
|
41
|
+
if (!c.confidenceHistogram || !Array.isArray(c.confidenceHistogram.edges) || !Array.isArray(c.confidenceHistogram.counts)) {
|
|
42
|
+
fail('confidenceHistogram must have edges and counts');
|
|
43
|
+
}
|
|
44
|
+
else if (c.confidenceHistogram.edges.length !== c.confidenceHistogram.counts.length + 1) {
|
|
45
|
+
fail('confidenceHistogram.edges must have one more entry than counts');
|
|
46
|
+
}
|
|
47
|
+
return c;
|
|
48
|
+
}
|
|
49
|
+
/** Threshold for a local top label: the per-label override if present, else the global one. */
|
|
50
|
+
export function thresholdFor(calibration, label) {
|
|
51
|
+
if (label !== undefined && calibration.thresholds && Object.hasOwn(calibration.thresholds, label)) {
|
|
52
|
+
return calibration.thresholds[label];
|
|
53
|
+
}
|
|
54
|
+
return calibration.threshold;
|
|
55
|
+
}
|
|
56
|
+
export async function loadCalibration(source, task) {
|
|
57
|
+
if (typeof source === 'function')
|
|
58
|
+
return parseCalibration(await source(), task);
|
|
59
|
+
if (typeof source === 'string' || source instanceof URL) {
|
|
60
|
+
const res = await fetch(source);
|
|
61
|
+
if (!res.ok) {
|
|
62
|
+
throw new BelayError('invalid-calibration', `Failed to fetch calibration ${String(source)}: HTTP ${res.status}`);
|
|
63
|
+
}
|
|
64
|
+
return parseCalibration(await res.json(), task);
|
|
65
|
+
}
|
|
66
|
+
return parseCalibration(source, task);
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=calibration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calibration.js","sourceRoot":"","sources":["../src/calibration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAErC,MAAM,KAAK,GAAG,CAAC,CAAU,EAAe,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;AACvF,MAAM,MAAM,GAAG,CAAC,CAAU,EAAe,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACzE,oEAAoE;AACpE,MAAM,WAAW,GAAG,CAAC,CAA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/B,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,MAAyE,EACzE,IAAa;IAEb,IAAI,OAAO,MAAM,KAAK,UAAU;QAAE,OAAO,gBAAgB,CAAC,MAAM,MAAM,EAAE,EAAE,IAAI,CAAC,CAAC;IAChF,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,YAAY,GAAG,EAAE,CAAC;QACxD,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,CAAC;QAChC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;YACZ,MAAM,IAAI,UAAU,CAAC,qBAAqB,EAAE,+BAA+B,MAAM,CAAC,MAAM,CAAC,UAAU,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;QACnH,CAAC;QACD,OAAO,gBAAgB,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC;IAClD,CAAC;IACD,OAAO,gBAAgB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AACxC,CAAC"}
|
package/dist/cloud.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { CloudRequest, CloudRunner, CloudUsage, TaskSchema } from './types.js';
|
|
2
|
+
export type CloudFn<S extends TaskSchema = TaskSchema> = (request: CloudRequest<S>, options: {
|
|
3
|
+
signal?: AbortSignal;
|
|
4
|
+
/** Report the call's token usage, so calibration and `savingsMeter()` can measure its cost. */
|
|
5
|
+
reportUsage: (usage: CloudUsage | CloudUsage[]) => void;
|
|
6
|
+
}) => Promise<unknown>;
|
|
7
|
+
/**
|
|
8
|
+
* Wraps a plain async function as a cloud runner. The function returns the raw output:
|
|
9
|
+
* the bare value, the `{ value }` wrapper, or a JSON string of either. The task validates it.
|
|
10
|
+
* Token usage goes through `reportUsage`, since the output itself may be a `{ value }` object.
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* cloudAdapter(async ({ instruction, input, jsonSchema }, { signal }) => {
|
|
14
|
+
* const res = await fetch('/api/classify', { method: 'POST', body: JSON.stringify({ instruction, input, jsonSchema }), signal });
|
|
15
|
+
* return res.json();
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function cloudAdapter<S extends TaskSchema = TaskSchema>(fn: CloudFn<S>, options?: {
|
|
20
|
+
id?: string;
|
|
21
|
+
}): CloudRunner<S>;
|
|
22
|
+
export interface FetchAdapterOptions<S extends TaskSchema = TaskSchema> {
|
|
23
|
+
/** Your backend endpoint. Never put provider API keys in the browser. */
|
|
24
|
+
url: string | URL;
|
|
25
|
+
headers?: Record<string, string>;
|
|
26
|
+
/** Builds the request body. Defaults to the JSON-serialized request (functions dropped). */
|
|
27
|
+
body?: (request: CloudRequest<S>) => unknown;
|
|
28
|
+
/** Extracts the output from the parsed JSON response. Defaults to the whole response. */
|
|
29
|
+
select?: (json: unknown) => unknown;
|
|
30
|
+
/** Extracts token usage from the parsed JSON response, if your backend passes it through. */
|
|
31
|
+
usage?: (json: unknown) => CloudUsage | CloudUsage[] | undefined;
|
|
32
|
+
id?: string;
|
|
33
|
+
fetch?: typeof fetch;
|
|
34
|
+
}
|
|
35
|
+
/** A cloud runner that POSTs the request as JSON to your endpoint. */
|
|
36
|
+
export declare function fetchAdapter<S extends TaskSchema = TaskSchema>(options: FetchAdapterOptions<S>): CloudRunner<S>;
|
|
37
|
+
//# sourceMappingURL=cloud.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloud.d.ts","sourceRoot":"","sources":["../src/cloud.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAEjG,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,IAAI,CACvD,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,EACxB,OAAO,EAAE;IACP,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,+FAA+F;IAC/F,WAAW,EAAE,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,EAAE,KAAK,IAAI,CAAC;CACzD,KACE,OAAO,CAAC,OAAO,CAAC,CAAC;AAEtB;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,EAC5D,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC,EACd,OAAO,GAAE;IAAE,EAAE,CAAC,EAAE,MAAM,CAAA;CAAO,GAC5B,WAAW,CAAC,CAAC,CAAC,CAShB;AAED,MAAM,WAAW,mBAAmB,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU;IACpE,yEAAyE;IACzE,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,4FAA4F;IAC5F,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC;IAC7C,yFAAyF;IACzF,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC;IACpC,6FAA6F;IAC7F,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,UAAU,GAAG,UAAU,EAAE,GAAG,SAAS,CAAC;IACjE,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACtB;AAED,sEAAsE;AACtE,wBAAgB,YAAY,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,EAAE,OAAO,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAmB/G"}
|
package/dist/cloud.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wraps a plain async function as a cloud runner. The function returns the raw output:
|
|
3
|
+
* the bare value, the `{ value }` wrapper, or a JSON string of either. The task validates it.
|
|
4
|
+
* Token usage goes through `reportUsage`, since the output itself may be a `{ value }` object.
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* cloudAdapter(async ({ instruction, input, jsonSchema }, { signal }) => {
|
|
8
|
+
* const res = await fetch('/api/classify', { method: 'POST', body: JSON.stringify({ instruction, input, jsonSchema }), signal });
|
|
9
|
+
* return res.json();
|
|
10
|
+
* });
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export function cloudAdapter(fn, options = {}) {
|
|
14
|
+
return {
|
|
15
|
+
id: options.id ?? 'cloud',
|
|
16
|
+
async run(request, opts) {
|
|
17
|
+
let usage;
|
|
18
|
+
const value = await fn(request, { ...opts, reportUsage: (u) => void (usage = u) });
|
|
19
|
+
return usage ? { value, usage } : { value };
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/** A cloud runner that POSTs the request as JSON to your endpoint. */
|
|
24
|
+
export function fetchAdapter(options) {
|
|
25
|
+
const doFetch = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
26
|
+
return cloudAdapter(async (request, { signal, reportUsage }) => {
|
|
27
|
+
const body = options.body ? options.body(request) : request;
|
|
28
|
+
const res = await doFetch(options.url, {
|
|
29
|
+
method: 'POST',
|
|
30
|
+
headers: { 'content-type': 'application/json', ...options.headers },
|
|
31
|
+
body: JSON.stringify(body),
|
|
32
|
+
...(signal ? { signal } : {}),
|
|
33
|
+
});
|
|
34
|
+
if (!res.ok)
|
|
35
|
+
throw new Error(`Cloud endpoint responded with HTTP ${res.status}`);
|
|
36
|
+
const json = await res.json();
|
|
37
|
+
const usage = options.usage?.(json);
|
|
38
|
+
if (usage)
|
|
39
|
+
reportUsage(usage);
|
|
40
|
+
return options.select ? options.select(json) : json;
|
|
41
|
+
}, { id: options.id ?? 'fetch' });
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=cloud.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
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,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC9B,CAAC,CAAC;QACH,IAAI,CAAC,GAAG,CAAC,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,sCAAsC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;QACjF,MAAM,IAAI,GAAY,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;QACvC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,CAAC;QACpC,IAAI,KAAK;YAAE,WAAW,CAAC,KAAK,CAAC,CAAC;QAC9B,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACtD,CAAC,EACD,EAAE,EAAE,EAAE,OAAO,CAAC,EAAE,IAAI,OAAO,EAAE,CAC9B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ProbabilityEntry } from './types.js';
|
|
2
|
+
/** Probability of the top option: the confidence signal for classifier tasks. */
|
|
3
|
+
export declare function topProbability(probabilities: readonly ProbabilityEntry[]): number;
|
|
4
|
+
export interface ConfidenceSignals {
|
|
5
|
+
/** Whether the output passed schema validation. */
|
|
6
|
+
valid: boolean;
|
|
7
|
+
/** Confidence reported by the local runner itself, if any. */
|
|
8
|
+
runner?: number | undefined;
|
|
9
|
+
/** P(correct) from the classifier-as-judge, if any. */
|
|
10
|
+
judge?: number | undefined;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Combines the signals into one confidence (ADR 0001, "Confidence signal"):
|
|
14
|
+
*
|
|
15
|
+
* - schema validation is a hard gate: an invalid output has confidence 0;
|
|
16
|
+
* - with only one of `runner` / `judge`, that value is the confidence;
|
|
17
|
+
* - with both, the minimum (the more pessimistic signal wins);
|
|
18
|
+
* - with neither, `undefined`: the task cannot decide and reports a configuration error.
|
|
19
|
+
*/
|
|
20
|
+
export declare function combineConfidence(signals: ConfidenceSignals): number | undefined;
|
|
21
|
+
export declare function clamp01(n: number): number;
|
|
22
|
+
//# sourceMappingURL=confidence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"confidence.d.ts","sourceRoot":"","sources":["../src/confidence.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,iFAAiF;AACjF,wBAAgB,cAAc,CAAC,aAAa,EAAE,SAAS,gBAAgB,EAAE,GAAG,MAAM,CAIjF;AAED,MAAM,WAAW,iBAAiB;IAChC,mDAAmD;IACnD,KAAK,EAAE,OAAO,CAAC;IACf,8DAA8D;IAC9D,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,uDAAuD;IACvD,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC5B;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,iBAAiB,GAAG,MAAM,GAAG,SAAS,CAKhF;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAGzC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Probability of the top option: the confidence signal for classifier tasks. */
|
|
2
|
+
export function topProbability(probabilities) {
|
|
3
|
+
let top = 0;
|
|
4
|
+
for (const p of probabilities)
|
|
5
|
+
if (p.probability > top)
|
|
6
|
+
top = p.probability;
|
|
7
|
+
return clamp01(top);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Combines the signals into one confidence (ADR 0001, "Confidence signal"):
|
|
11
|
+
*
|
|
12
|
+
* - schema validation is a hard gate: an invalid output has confidence 0;
|
|
13
|
+
* - with only one of `runner` / `judge`, that value is the confidence;
|
|
14
|
+
* - with both, the minimum (the more pessimistic signal wins);
|
|
15
|
+
* - with neither, `undefined`: the task cannot decide and reports a configuration error.
|
|
16
|
+
*/
|
|
17
|
+
export function combineConfidence(signals) {
|
|
18
|
+
if (!signals.valid)
|
|
19
|
+
return 0;
|
|
20
|
+
const values = [signals.runner, signals.judge].filter((v) => typeof v === 'number');
|
|
21
|
+
if (values.length === 0)
|
|
22
|
+
return undefined;
|
|
23
|
+
return clamp01(Math.min(...values));
|
|
24
|
+
}
|
|
25
|
+
export function clamp01(n) {
|
|
26
|
+
if (Number.isNaN(n))
|
|
27
|
+
return 0;
|
|
28
|
+
return n < 0 ? 0 : n > 1 ? 1 : n;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=confidence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"confidence.js","sourceRoot":"","sources":["../src/confidence.ts"],"names":[],"mappings":"AAEA,iFAAiF;AACjF,MAAM,UAAU,cAAc,CAAC,aAA0C;IACvE,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,KAAK,MAAM,CAAC,IAAI,aAAa;QAAE,IAAI,CAAC,CAAC,WAAW,GAAG,GAAG;YAAE,GAAG,GAAG,CAAC,CAAC,WAAW,CAAC;IAC5E,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC;AACtB,CAAC;AAWD;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAA0B;IAC1D,IAAI,CAAC,OAAO,CAAC,KAAK;QAAE,OAAO,CAAC,CAAC;IAC7B,MAAM,MAAM,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAe,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC;IACjG,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IAC1C,OAAO,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,CAAS;IAC/B,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAAE,OAAO,CAAC,CAAC;IAC9B,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACnC,CAAC"}
|
package/dist/cost.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { BelayEvent, CloudUsage, PriceTable, TokenPrices } from './types.js';
|
|
2
|
+
/** Normalizes a runner's usage report to a list of per-model parts. */
|
|
3
|
+
export declare function usageParts(usage: CloudUsage | readonly CloudUsage[] | undefined): CloudUsage[];
|
|
4
|
+
/**
|
|
5
|
+
* Cost of one cloud call from its token usage. Prices are per million tokens. A price table is
|
|
6
|
+
* keyed by the model id the provider reports, so a call that a fallback model served is priced
|
|
7
|
+
* at that model's rates. Throws when a model has no price: guessing would make every saving wrong.
|
|
8
|
+
*/
|
|
9
|
+
export declare function costOf(usage: CloudUsage | readonly CloudUsage[], prices: PriceTable | TokenPrices): number;
|
|
10
|
+
export interface SavingsMeterOptions {
|
|
11
|
+
/** Per-token prices, to measure the cost of each cloud call from the usage its runner reports. */
|
|
12
|
+
prices?: PriceTable | TokenPrices;
|
|
13
|
+
/**
|
|
14
|
+
* Cost of one cloud call, used when calls report no usage, and to value the calls the cascade
|
|
15
|
+
* avoided before any cloud call has been measured. A calibration file's `cost.cloudPerRun` fits.
|
|
16
|
+
*/
|
|
17
|
+
cloudPerRun?: number;
|
|
18
|
+
currency?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface SavingsSummary {
|
|
21
|
+
currency: string | null;
|
|
22
|
+
runs: number;
|
|
23
|
+
/** Answered on device because the local confidence met the threshold. */
|
|
24
|
+
local: number;
|
|
25
|
+
/** Answered by the cloud runner. */
|
|
26
|
+
cloud: number;
|
|
27
|
+
/** Answered on device only because escalation was blocked (policy, consent, cloud error). */
|
|
28
|
+
blocked: number;
|
|
29
|
+
/** Spent on cloud calls: measured where usage was reported, otherwise `cloudPerRun` each. */
|
|
30
|
+
cloudSpend: number | null;
|
|
31
|
+
/** Mean cost of one cloud call (measured when possible). */
|
|
32
|
+
costPerCloudRun: number | null;
|
|
33
|
+
/** What the `local` runs would have cost in the cloud: `local × costPerCloudRun`. */
|
|
34
|
+
saved: number | null;
|
|
35
|
+
/** `saved / (saved + cloudSpend)`: the share of the cloud-only bill the cascade avoided. */
|
|
36
|
+
savedShare: number | null;
|
|
37
|
+
/** How many cloud calls were priced from reported usage. */
|
|
38
|
+
measuredCalls: number;
|
|
39
|
+
}
|
|
40
|
+
export interface SavingsMeter {
|
|
41
|
+
/** Pass as the task's `onEvent` (or call it from yours). */
|
|
42
|
+
readonly onEvent: (event: BelayEvent) => void;
|
|
43
|
+
/** Totals so far, for all tasks or one. */
|
|
44
|
+
summary(task?: string): SavingsSummary;
|
|
45
|
+
reset(): void;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Counts what the cascade saves in production. Only runs that stayed on device because the
|
|
49
|
+
* local answer was confident count as saved; runs kept local because escalation was blocked
|
|
50
|
+
* are reported separately. Unmeasured calls, and the value of avoided ones, use the mean
|
|
51
|
+
* measured cost per call, falling back to `cloudPerRun`.
|
|
52
|
+
*
|
|
53
|
+
* ```ts
|
|
54
|
+
* const meter = savingsMeter({ prices, cloudPerRun: calibration.cost?.cloudPerRun });
|
|
55
|
+
* const triage = task({ ..., onEvent: meter.onEvent });
|
|
56
|
+
* meter.summary(); // { runs, local, cloud, cloudSpend, saved, savedShare, ... }
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare function savingsMeter(options?: SavingsMeterOptions): SavingsMeter;
|
|
60
|
+
//# sourceMappingURL=cost.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cost.d.ts","sourceRoot":"","sources":["../src/cost.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAA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f;AAWD;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAE,mBAAwB,GAAG,YAAY,CAoD5E"}
|
package/dist/cost.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/** Normalizes a runner's usage report to a list of per-model parts. */
|
|
2
|
+
export function usageParts(usage) {
|
|
3
|
+
if (!usage)
|
|
4
|
+
return [];
|
|
5
|
+
return Array.isArray(usage) ? [...usage] : [usage];
|
|
6
|
+
}
|
|
7
|
+
function pricesFor(prices, model) {
|
|
8
|
+
if (typeof prices.input === 'number')
|
|
9
|
+
return prices;
|
|
10
|
+
const table = prices;
|
|
11
|
+
if (model !== undefined && Object.hasOwn(table, model))
|
|
12
|
+
return table[model];
|
|
13
|
+
const known = Object.keys(table).join(', ') || 'none';
|
|
14
|
+
throw new Error(model === undefined ? `usage names no model and the price table has several (${known})` : `no price for model "${model}" (prices for: ${known})`);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Cost of one cloud call from its token usage. Prices are per million tokens. A price table is
|
|
18
|
+
* keyed by the model id the provider reports, so a call that a fallback model served is priced
|
|
19
|
+
* at that model's rates. Throws when a model has no price: guessing would make every saving wrong.
|
|
20
|
+
*/
|
|
21
|
+
export function costOf(usage, prices) {
|
|
22
|
+
let total = 0;
|
|
23
|
+
for (const part of usageParts(usage)) {
|
|
24
|
+
const p = pricesFor(prices, part.model);
|
|
25
|
+
total +=
|
|
26
|
+
part.inputTokens * p.input +
|
|
27
|
+
part.outputTokens * p.output +
|
|
28
|
+
(part.cacheReadInputTokens ?? 0) * (p.cacheRead ?? p.input) +
|
|
29
|
+
(part.cacheWriteInputTokens ?? 0) * (p.cacheWrite ?? p.input);
|
|
30
|
+
}
|
|
31
|
+
return total / 1e6;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Counts what the cascade saves in production. Only runs that stayed on device because the
|
|
35
|
+
* local answer was confident count as saved; runs kept local because escalation was blocked
|
|
36
|
+
* are reported separately. Unmeasured calls, and the value of avoided ones, use the mean
|
|
37
|
+
* measured cost per call, falling back to `cloudPerRun`.
|
|
38
|
+
*
|
|
39
|
+
* ```ts
|
|
40
|
+
* const meter = savingsMeter({ prices, cloudPerRun: calibration.cost?.cloudPerRun });
|
|
41
|
+
* const triage = task({ ..., onEvent: meter.onEvent });
|
|
42
|
+
* meter.summary(); // { runs, local, cloud, cloudSpend, saved, savedShare, ... }
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export function savingsMeter(options = {}) {
|
|
46
|
+
const tallies = new Map();
|
|
47
|
+
const tallyFor = (task) => {
|
|
48
|
+
let t = tallies.get(task);
|
|
49
|
+
if (!t)
|
|
50
|
+
tallies.set(task, (t = { runs: 0, local: 0, cloud: 0, blocked: 0, measuredCalls: 0, measuredSpend: 0 }));
|
|
51
|
+
return t;
|
|
52
|
+
};
|
|
53
|
+
const onEvent = (event) => {
|
|
54
|
+
if (event.type !== 'run')
|
|
55
|
+
return;
|
|
56
|
+
const t = tallyFor(event.task);
|
|
57
|
+
t.runs++;
|
|
58
|
+
if (event.source === 'cloud') {
|
|
59
|
+
t.cloud++;
|
|
60
|
+
if (options.prices && event.cloudUsage?.length) {
|
|
61
|
+
t.measuredSpend += costOf(event.cloudUsage, options.prices);
|
|
62
|
+
t.measuredCalls++;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else if (event.escalationBlocked) {
|
|
66
|
+
t.blocked++;
|
|
67
|
+
}
|
|
68
|
+
else if (event.escalationReason === null) {
|
|
69
|
+
t.local++;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
const summary = (task) => {
|
|
73
|
+
const parts = task === undefined ? [...tallies.values()] : tallies.has(task) ? [tallies.get(task)] : [];
|
|
74
|
+
const sum = (key) => parts.reduce((a, t) => a + t[key], 0);
|
|
75
|
+
const runs = sum('runs');
|
|
76
|
+
const local = sum('local');
|
|
77
|
+
const cloud = sum('cloud');
|
|
78
|
+
const measuredCalls = sum('measuredCalls');
|
|
79
|
+
const measuredSpend = sum('measuredSpend');
|
|
80
|
+
const costPerCloudRun = measuredCalls ? measuredSpend / measuredCalls : (options.cloudPerRun ?? null);
|
|
81
|
+
const cloudSpend = costPerCloudRun === null ? null : measuredSpend + (cloud - measuredCalls) * costPerCloudRun;
|
|
82
|
+
const saved = costPerCloudRun === null ? null : local * costPerCloudRun;
|
|
83
|
+
const denominator = saved === null || cloudSpend === null ? 0 : saved + cloudSpend;
|
|
84
|
+
return {
|
|
85
|
+
currency: options.currency ?? null,
|
|
86
|
+
runs,
|
|
87
|
+
local,
|
|
88
|
+
cloud,
|
|
89
|
+
blocked: sum('blocked'),
|
|
90
|
+
cloudSpend,
|
|
91
|
+
costPerCloudRun,
|
|
92
|
+
saved,
|
|
93
|
+
savedShare: denominator > 0 ? saved / denominator : null,
|
|
94
|
+
measuredCalls,
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
return { onEvent, summary, reset: () => tallies.clear() };
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=cost.js.map
|
package/dist/cost.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cost.js","sourceRoot":"","sources":["../src/cost.ts"],"names":[],"mappings":"AAEA,uEAAuE;AACvE,MAAM,UAAU,UAAU,CAAC,KAAqD;IAC9E,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAC;IACtB,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAmB,CAAC,CAAC;AACnE,CAAC;AAED,SAAS,SAAS,CAAC,MAAgC,EAAE,KAAyB;IAC5E,IAAI,OAAQ,MAAsB,CAAC,KAAK,KAAK,QAAQ;QAAE,OAAO,MAAqB,CAAC;IACpF,MAAM,KAAK,GAAG,MAAoB,CAAC;IACnC,IAAI,KAAK,KAAK,SAAS,IAAI,MAAM,CAAC,MAA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B,UAAU;YACV,eAAe;YACf,KAAK;YACL,UAAU,EAAE,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC,KAAM,GAAG,WAAW,CAAC,CAAC,CAAC,IAAI;YACzD,aAAa;SACd,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;AAC5D,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type BelayErrorCode =
|
|
2
|
+
/** No local output and escalation was not possible or not permitted. */
|
|
3
|
+
'no-result'
|
|
4
|
+
/** The cloud runner threw or returned an output that does not match the schema. */
|
|
5
|
+
| 'cloud-error' | 'cloud-invalid-output'
|
|
6
|
+
/** The task definition is invalid. */
|
|
7
|
+
| 'invalid-task'
|
|
8
|
+
/** The calibration file is malformed or does not belong to this task. */
|
|
9
|
+
| 'invalid-calibration';
|
|
10
|
+
export declare class BelayError extends Error {
|
|
11
|
+
readonly name = "BelayError";
|
|
12
|
+
readonly code: BelayErrorCode;
|
|
13
|
+
constructor(code: BelayErrorCode, message: string, options?: {
|
|
14
|
+
cause?: unknown;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Thrown by a local runner from `run()` when the model is not usable (e.g. it would need
|
|
19
|
+
* a download). The cascade treats it as escalation reason `local-unavailable`.
|
|
20
|
+
*/
|
|
21
|
+
export declare class LocalUnavailableError extends Error {
|
|
22
|
+
readonly name = "LocalUnavailableError";
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc;AACxB,wEAAwE;AACtE,WAAW;AACb,mFAAmF;GACjF,aAAa,GACb,sBAAsB;AACxB,sCAAsC;GACpC,cAAc;AAChB,yEAAyE;GACvE,qBAAqB,CAAC;AAE1B,qBAAa,UAAW,SAAQ,KAAK;IACnC,SAAkB,IAAI,gBAAgB;IACtC,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAE9B,YAAY,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,EAG/E;CACF;AAED;;;GAGG;AACH,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,SAAkB,IAAI,2BAA2B;CAClD"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export class BelayError extends Error {
|
|
2
|
+
name = 'BelayError';
|
|
3
|
+
code;
|
|
4
|
+
constructor(code, message, options) {
|
|
5
|
+
super(message, options);
|
|
6
|
+
this.code = code;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Thrown by a local runner from `run()` when the model is not usable (e.g. it would need
|
|
11
|
+
* a download). The cascade treats it as escalation reason `local-unavailable`.
|
|
12
|
+
*/
|
|
13
|
+
export class LocalUnavailableError extends Error {
|
|
14
|
+
name = 'LocalUnavailableError';
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAWA,MAAM,OAAO,UAAW,SAAQ,KAAK;IACjB,IAAI,GAAG,YAAY,CAAC;IAC7B,IAAI,CAAiB;IAE9B,YAAY,IAAoB,EAAE,OAAe,EAAE,OAA6B;QAC9E,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAC5B,IAAI,GAAG,uBAAuB,CAAC;CAClD"}
|
package/dist/hash.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** 32-bit FNV-1a over UTF-16 code units, hex encoded. Not cryptographic; used for fingerprints. */
|
|
2
|
+
export declare function fnv1a(text: string): string;
|
|
3
|
+
/** JSON.stringify with sorted object keys, so equal values serialize identically. */
|
|
4
|
+
export declare function canonicalJson(value: unknown): string;
|
|
5
|
+
//# sourceMappingURL=hash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AAAA,mGAAmG;AACnG,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAO1C;AAED,qFAAqF;AACrF,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CASpD"}
|
package/dist/hash.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** 32-bit FNV-1a over UTF-16 code units, hex encoded. Not cryptographic; used for fingerprints. */
|
|
2
|
+
export function fnv1a(text) {
|
|
3
|
+
let hash = 0x811c9dc5;
|
|
4
|
+
for (let i = 0; i < text.length; i++) {
|
|
5
|
+
hash ^= text.charCodeAt(i);
|
|
6
|
+
hash = Math.imul(hash, 0x01000193);
|
|
7
|
+
}
|
|
8
|
+
return (hash >>> 0).toString(16).padStart(8, '0');
|
|
9
|
+
}
|
|
10
|
+
/** JSON.stringify with sorted object keys, so equal values serialize identically. */
|
|
11
|
+
export function canonicalJson(value) {
|
|
12
|
+
return JSON.stringify(value, (_key, v) => {
|
|
13
|
+
if (v && typeof v === 'object' && !Array.isArray(v)) {
|
|
14
|
+
return Object.fromEntries(Object.entries(v).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)));
|
|
15
|
+
}
|
|
16
|
+
return v;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=hash.js.map
|
package/dist/hash.js.map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 -0,0 +1,15 @@
|
|
|
1
|
+
export { task } from './task.js';
|
|
2
|
+
export { cloudAdapter, fetchAdapter } from './cloud.js';
|
|
3
|
+
export type { CloudFn, FetchAdapterOptions } from './cloud.js';
|
|
4
|
+
export { costOf, savingsMeter, usageParts } from './cost.js';
|
|
5
|
+
export type { SavingsMeter, SavingsMeterOptions, SavingsSummary } from './cost.js';
|
|
6
|
+
export { combineConfidence, topProbability, clamp01 } from './confidence.js';
|
|
7
|
+
export type { ConfidenceSignals } from './confidence.js';
|
|
8
|
+
export { CALIBRATION_VERSION, loadCalibration, parseCalibration, thresholdFor } from './calibration.js';
|
|
9
|
+
export { assertValidSchema, buildInstruction, labelOf, normalizeOptions, optionLabels, parseValue, schemaFingerprint, toJsonSchema, } from './schema.js';
|
|
10
|
+
export type { ParseResult } from './schema.js';
|
|
11
|
+
export { BelayError, LocalUnavailableError } from './errors.js';
|
|
12
|
+
export type { BelayErrorCode } from './errors.js';
|
|
13
|
+
export { canonicalJson, fnv1a } from './hash.js';
|
|
14
|
+
export type * from './types.js';
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACxD,YAAY,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC7D,YAAY,EAAE,YAAY,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACnF,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC7E,YAAY,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACxG,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,OAAO,EACP,gBAAgB,EAChB,YAAY,EACZ,UAAU,EACV,iBAAiB,EACjB,YAAY,GACb,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAChE,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AACjD,mBAAmB,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { task } from './task.js';
|
|
2
|
+
export { cloudAdapter, fetchAdapter } from './cloud.js';
|
|
3
|
+
export { costOf, savingsMeter, usageParts } from './cost.js';
|
|
4
|
+
export { combineConfidence, topProbability, clamp01 } from './confidence.js';
|
|
5
|
+
export { CALIBRATION_VERSION, loadCalibration, parseCalibration, thresholdFor } from './calibration.js';
|
|
6
|
+
export { assertValidSchema, buildInstruction, labelOf, normalizeOptions, optionLabels, parseValue, schemaFingerprint, toJsonSchema, } from './schema.js';
|
|
7
|
+
export { BelayError, LocalUnavailableError } from './errors.js';
|
|
8
|
+
export { canonicalJson, fnv1a } from './hash.js';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAExD,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE7D,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE7E,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACxG,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,OAAO,EACP,gBAAgB,EAChB,YAAY,EACZ,UAAU,EACV,iBAAiB,EACjB,YAAY,GACb,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEhE,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { OptionInput, OptionSpec, TaskSchema, ValueOf } from './types.js';
|
|
2
|
+
export declare function normalizeOptions(options: readonly OptionInput[]): OptionSpec[];
|
|
3
|
+
export declare function optionLabels(schema: TaskSchema): string[];
|
|
4
|
+
/** Throws `BelayError('invalid-task')` if the schema is malformed. */
|
|
5
|
+
export declare function assertValidSchema(schema: TaskSchema): void;
|
|
6
|
+
/**
|
|
7
|
+
* Fingerprint of everything in the schema that influences model behavior (type, prompt,
|
|
8
|
+
* option labels and descriptions, JSON Schema). Stored in calibration files so a task can
|
|
9
|
+
* tell when its calibration was produced for a different schema.
|
|
10
|
+
*/
|
|
11
|
+
export declare function schemaFingerprint(schema: TaskSchema): string;
|
|
12
|
+
/**
|
|
13
|
+
* JSON Schema of the output. Non-structured outputs are wrapped as `{ "value": ... }`
|
|
14
|
+
* because many providers require an object at the root.
|
|
15
|
+
*/
|
|
16
|
+
export declare function toJsonSchema(schema: TaskSchema): Record<string, unknown>;
|
|
17
|
+
/** A provider-neutral instruction for cloud runners that build their own prompt from it. */
|
|
18
|
+
export declare function buildInstruction(schema: TaskSchema, context?: string): string;
|
|
19
|
+
export type ParseResult<V> = {
|
|
20
|
+
ok: true;
|
|
21
|
+
value: V;
|
|
22
|
+
} | {
|
|
23
|
+
ok: false;
|
|
24
|
+
error: string;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Coerces a runner output into the schema's value type. Accepts the bare value or the
|
|
28
|
+
* `{ value }` wrapper from {@link toJsonSchema}, and JSON strings of either.
|
|
29
|
+
*/
|
|
30
|
+
export declare function parseValue<S extends TaskSchema>(schema: S, raw: unknown): ParseResult<ValueOf<S>>;
|
|
31
|
+
/** Label of a value for telemetry and per-label thresholds; `undefined` for structured tasks. */
|
|
32
|
+
export declare function labelOf(schema: TaskSchema, value: unknown): string | undefined;
|
|
33
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE/E,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,SAAS,WAAW,EAAE,GAAG,UAAU,EAAE,CAE9E;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,EAAE,CAUzD;AAED,sEAAsE;AACtE,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CA0B1D;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAM5D;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAgBxE;AAED,4FAA4F;AAC5F,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAyB7E;AAED,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,K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