letsdecide 0.0.0-stage → 0.3.0
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/LICENSE +202 -0
- package/README.md +80 -3
- package/conformance.d.ts +21 -0
- package/conformance.js +91 -0
- package/index.d.ts +247 -0
- package/index.js +378 -0
- package/middleware.d.ts +98 -0
- package/middleware.js +385 -0
- package/package.json +30 -6
- package/pkg/letsdecide_wasm.d.ts +68 -0
- package/pkg/letsdecide_wasm.js +488 -0
- package/pkg/letsdecide_wasm_bg.wasm +0 -0
- package/pkg/letsdecide_wasm_bg.wasm.d.ts +19 -0
package/middleware.js
ADDED
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
// A middleware is `(next) => (model, request, opts) => Promise<DecisionResponse>`.
|
|
2
|
+
|
|
3
|
+
/** Wraps `client.decide` in the given middleware; the first is outermost. */
|
|
4
|
+
export function compose(client, ...middleware) {
|
|
5
|
+
return middleware.reduceRight((next, mw) => mw(next), (...args) => client.decide(...args));
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const defaultSleep = (ms, signal) =>
|
|
9
|
+
new Promise((resolve, reject) => {
|
|
10
|
+
const t = setTimeout(resolve, ms);
|
|
11
|
+
signal?.addEventListener("abort", () => (clearTimeout(t), reject(signal.reason)), { once: true });
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
/** Retries `retryable` errors with jittered exponential backoff, honouring `retryAfterMs` (capped at `maxMs`). */
|
|
15
|
+
export function retry({ maxAttempts = 3, baseMs = 200, maxMs = 30_000, sleep = defaultSleep } = {}) {
|
|
16
|
+
return (next) => async (model, request, opts = {}) => {
|
|
17
|
+
for (let attempts = 1; ; attempts++) {
|
|
18
|
+
opts.signal?.throwIfAborted();
|
|
19
|
+
try {
|
|
20
|
+
return { ...(await next(model, request, opts)), attempts };
|
|
21
|
+
} catch (e) {
|
|
22
|
+
if (!e.retryable || attempts >= maxAttempts) throw Object.assign(e, { attempts });
|
|
23
|
+
const backoff = baseMs * 2 ** (attempts - 1) * (0.5 + Math.random() / 2);
|
|
24
|
+
await sleep(Math.min(e.retryAfterMs ?? backoff, maxMs), opts.signal);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Worth trying another call (or model) after this error.
|
|
31
|
+
const recoverable = (e) => e.retryable || e.code === "Unsupported";
|
|
32
|
+
|
|
33
|
+
/** On a retryable or `Unsupported` error, tries the next model; throws the last error if all fail. */
|
|
34
|
+
export function fallback(models) {
|
|
35
|
+
return (next) => async (model, request, opts) => {
|
|
36
|
+
const chain = [model, ...models];
|
|
37
|
+
let attempts = 0;
|
|
38
|
+
for (let i = 0; ; i++) {
|
|
39
|
+
try {
|
|
40
|
+
const res = await next(chain[i], request, opts);
|
|
41
|
+
return { ...res, attempts: attempts + (res.attempts ?? 1), fellBackFrom: i ? model : undefined };
|
|
42
|
+
} catch (e) {
|
|
43
|
+
attempts += e.attempts ?? 1;
|
|
44
|
+
if (i + 1 >= chain.length || !recoverable(e)) throw Object.assign(e, { attempts });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Starts another call when the current one is slower than `delayMs` (or fails
|
|
52
|
+
* recoverably); the first answer wins and the rest are aborted. Hedges go to
|
|
53
|
+
* `models` in order, or to the same model when empty.
|
|
54
|
+
*/
|
|
55
|
+
export function hedge({ delayMs = 1000, models = [] } = {}) {
|
|
56
|
+
return (next) => (model, request, opts = {}) =>
|
|
57
|
+
new Promise((resolve, reject) => {
|
|
58
|
+
const chain = [model, ...(models.length ? models : [model])];
|
|
59
|
+
const ctrls = [];
|
|
60
|
+
let started = 0, pending = 0, done = false, stopped = false, hard, timer;
|
|
61
|
+
const finish = (settle, value) => {
|
|
62
|
+
if (done) return;
|
|
63
|
+
done = true;
|
|
64
|
+
clearTimeout(timer);
|
|
65
|
+
opts.signal?.removeEventListener("abort", onAbort);
|
|
66
|
+
ctrls.forEach((c) => c.abort());
|
|
67
|
+
settle(value);
|
|
68
|
+
};
|
|
69
|
+
const onAbort = () => finish(reject, opts.signal.reason);
|
|
70
|
+
if (opts.signal?.aborted) return reject(opts.signal.reason);
|
|
71
|
+
opts.signal?.addEventListener("abort", onAbort, { once: true });
|
|
72
|
+
const launch = () => {
|
|
73
|
+
if (done || stopped || started >= chain.length) return;
|
|
74
|
+
const i = started++;
|
|
75
|
+
pending++;
|
|
76
|
+
const ctrl = new AbortController();
|
|
77
|
+
ctrls.push(ctrl);
|
|
78
|
+
clearTimeout(timer);
|
|
79
|
+
if (started < chain.length) timer = setTimeout(launch, delayMs);
|
|
80
|
+
Promise.resolve()
|
|
81
|
+
.then(() => next(chain[i], request, { ...opts, signal: ctrl.signal }))
|
|
82
|
+
.then(
|
|
83
|
+
(res) => finish(resolve, { ...res, hedgedFrom: i ? model : undefined }),
|
|
84
|
+
(e) => {
|
|
85
|
+
pending--;
|
|
86
|
+
// A hard error stops new hedges, but a call still in flight may yet answer.
|
|
87
|
+
if (!recoverable(e)) {
|
|
88
|
+
stopped = true;
|
|
89
|
+
hard ??= e;
|
|
90
|
+
clearTimeout(timer);
|
|
91
|
+
}
|
|
92
|
+
if (!stopped && started < chain.length) return launch();
|
|
93
|
+
if (!pending) finish(reject, hard ?? e);
|
|
94
|
+
},
|
|
95
|
+
);
|
|
96
|
+
};
|
|
97
|
+
launch();
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Known per-request question caps, by provider. */
|
|
102
|
+
const QUESTION_LIMITS = { clef: 64, openai: 400, gemini: 1000 };
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Splits a request with more than `maxQuestions` questions into several and
|
|
106
|
+
* merges the answers. `maxQuestions` is a number or `(model) => number`; by
|
|
107
|
+
* default it is the provider's documented cap. Input tokens and cost are
|
|
108
|
+
* summed: the input is sent (and billed) once per part.
|
|
109
|
+
*/
|
|
110
|
+
export function split({ maxQuestions, concurrency = 4 } = {}) {
|
|
111
|
+
const limit = (model) => {
|
|
112
|
+
const n =
|
|
113
|
+
(typeof maxQuestions === "function" ? maxQuestions(model) : maxQuestions) ??
|
|
114
|
+
QUESTION_LIMITS[model.split("/")[0]] ??
|
|
115
|
+
Infinity;
|
|
116
|
+
if (!(n >= 1)) throw new RangeError("split: maxQuestions must be at least 1");
|
|
117
|
+
return Math.floor(n);
|
|
118
|
+
};
|
|
119
|
+
if (!(concurrency >= 1)) throw new RangeError("split: concurrency must be at least 1");
|
|
120
|
+
return (next) => async (model, request, opts = {}) => {
|
|
121
|
+
const ids = Object.keys(request.questions);
|
|
122
|
+
const size = limit(model);
|
|
123
|
+
if (ids.length <= size) return next(model, request, opts);
|
|
124
|
+
opts.signal?.throwIfAborted();
|
|
125
|
+
const parts = [];
|
|
126
|
+
for (let i = 0; i < ids.length; i += size) {
|
|
127
|
+
const questions = Object.fromEntries(ids.slice(i, i + size).map((id) => [id, request.questions[id]]));
|
|
128
|
+
parts.push({ ...request, questions });
|
|
129
|
+
}
|
|
130
|
+
// One failed part fails the whole call; abort the others.
|
|
131
|
+
const ctrl = new AbortController();
|
|
132
|
+
const onAbort = () => ctrl.abort(opts.signal.reason);
|
|
133
|
+
opts.signal?.addEventListener("abort", onAbort, { once: true });
|
|
134
|
+
const results = new Array(parts.length);
|
|
135
|
+
let cursor = 0;
|
|
136
|
+
const worker = async () => {
|
|
137
|
+
while (cursor < parts.length) {
|
|
138
|
+
const n = cursor++;
|
|
139
|
+
results[n] = await next(model, parts[n], { ...opts, signal: ctrl.signal });
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
try {
|
|
143
|
+
await Promise.all(Array.from({ length: Math.min(concurrency, parts.length) }, worker));
|
|
144
|
+
} catch (e) {
|
|
145
|
+
ctrl.abort(e);
|
|
146
|
+
throw e;
|
|
147
|
+
} finally {
|
|
148
|
+
opts.signal?.removeEventListener("abort", onAbort);
|
|
149
|
+
}
|
|
150
|
+
return merge(results);
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function merge(results) {
|
|
155
|
+
const sum = (k) => (results.every((r) => r[k] != null) ? results.reduce((a, r) => a + r[k], 0) : null);
|
|
156
|
+
const out = {
|
|
157
|
+
model: results.find((r) => r.model)?.model ?? null,
|
|
158
|
+
answers: Object.assign({}, ...results.map((r) => r.answers)),
|
|
159
|
+
input_tokens: sum("input_tokens"),
|
|
160
|
+
parts: results.length,
|
|
161
|
+
};
|
|
162
|
+
const cost = sum("estimated_cost_usd");
|
|
163
|
+
if (cost != null) out.estimated_cost_usd = cost;
|
|
164
|
+
// Parts may be answered by different models (fallback, hedge): say so.
|
|
165
|
+
const models = [...new Set(results.map((r) => r.model).filter(Boolean))];
|
|
166
|
+
if (models.length > 1) out.models = models;
|
|
167
|
+
for (const k of ["fellBackFrom", "hedgedFrom"]) {
|
|
168
|
+
const v = results.find((r) => r[k])?.[k];
|
|
169
|
+
if (v) out[k] = v;
|
|
170
|
+
}
|
|
171
|
+
// Blocked means every answer is refused, so only when every part was.
|
|
172
|
+
if (results.every((r) => r.block_reason)) out.block_reason = results[0].block_reason;
|
|
173
|
+
if (results.some((r) => r.attempts)) out.attempts = results.reduce((a, r) => a + (r.attempts ?? 1), 0);
|
|
174
|
+
return out;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Also sends each request to `model` in the background and reports both
|
|
179
|
+
* answers to `onResult({ model, shadowModel, request, primary, shadow, error, comparison })`.
|
|
180
|
+
* The caller gets the primary answer as soon as it is ready; shadow
|
|
181
|
+
* failures are reported, never thrown. `sample` (0..1) limits the share of traffic.
|
|
182
|
+
*/
|
|
183
|
+
export function shadow({ model: shadowModel, onResult, sample = 1, random = Math.random }) {
|
|
184
|
+
return (next) => async (model, request, opts = {}) => {
|
|
185
|
+
const run = random() < sample;
|
|
186
|
+
const ctrl = new AbortController();
|
|
187
|
+
const shadowCall = run
|
|
188
|
+
? Promise.resolve()
|
|
189
|
+
.then(() => next(shadowModel, request, { signal: ctrl.signal }))
|
|
190
|
+
.then((shadow) => ({ shadow }), (error) => ({ error }))
|
|
191
|
+
: null;
|
|
192
|
+
let primary;
|
|
193
|
+
try {
|
|
194
|
+
primary = await next(model, request, opts);
|
|
195
|
+
} catch (e) {
|
|
196
|
+
// Nothing to compare against: stop paying for the mirror.
|
|
197
|
+
ctrl.abort(e);
|
|
198
|
+
throw e;
|
|
199
|
+
}
|
|
200
|
+
shadowCall?.then(({ shadow, error }) => {
|
|
201
|
+
const comparison = shadow ? compare(primary, shadow) : undefined;
|
|
202
|
+
try {
|
|
203
|
+
onResult({ model, shadowModel, request, primary, shadow, error, comparison });
|
|
204
|
+
} catch {
|
|
205
|
+
// A reporting bug must not surface on the caller's path.
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
return primary;
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Per-question agreement between two responses. Yes/no agrees when both are
|
|
214
|
+
* on the same side of 0.5; choice when the choice is equal; score when the
|
|
215
|
+
* values round to the same level. `delta` is the absolute difference in
|
|
216
|
+
* P(yes) or score. `agreement` is the share of comparable questions that agree.
|
|
217
|
+
*/
|
|
218
|
+
export function compare(a, b) {
|
|
219
|
+
const questions = {};
|
|
220
|
+
for (const [id, x] of Object.entries(a.answers)) {
|
|
221
|
+
const y = b.answers[id];
|
|
222
|
+
if (!y || x.kind !== y.kind || x.kind === "refused") continue;
|
|
223
|
+
if (x.kind === "yesno") {
|
|
224
|
+
questions[id] = { agree: x.probability >= 0.5 === y.probability >= 0.5, delta: Math.abs(x.probability - y.probability) };
|
|
225
|
+
} else if (x.kind === "choice") {
|
|
226
|
+
questions[id] = { agree: x.choice === y.choice };
|
|
227
|
+
} else {
|
|
228
|
+
questions[id] = { agree: Math.round(x.value) === Math.round(y.value), delta: Math.abs(x.value - y.value) };
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
const all = Object.values(questions);
|
|
232
|
+
const agreement = all.length ? all.filter((q) => q.agree).length / all.length : null;
|
|
233
|
+
return { agreement, questions };
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Adds a `calibrated` field next to each raw answer; raw numbers are never
|
|
238
|
+
* changed. `calibrators` is one `(p) => p` for every question or
|
|
239
|
+
* `{ [questionId]: (p) => p }`. Yes/no gets `calibrated.probability`;
|
|
240
|
+
* choice and score get renormalised `calibrated.probabilities` and the top
|
|
241
|
+
* `calibrated.confidence`.
|
|
242
|
+
*/
|
|
243
|
+
export function calibrate(calibrators) {
|
|
244
|
+
const pick = (id) =>
|
|
245
|
+
typeof calibrators === "function" ? calibrators : Object.hasOwn(calibrators, id) ? calibrators[id] : undefined;
|
|
246
|
+
return (next) => async (model, request, opts) => {
|
|
247
|
+
const res = await next(model, request, opts);
|
|
248
|
+
const answers = {};
|
|
249
|
+
for (const [id, a] of Object.entries(res.answers)) {
|
|
250
|
+
const f = pick(id);
|
|
251
|
+
answers[id] = f && a.kind !== "refused" ? { ...a, calibrated: calibrateAnswer(a, f) } : a;
|
|
252
|
+
}
|
|
253
|
+
return { ...res, answers };
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function calibrateAnswer(a, f) {
|
|
258
|
+
const clamp = (p) => Math.min(1, Math.max(0, f(p)));
|
|
259
|
+
if (a.kind === "yesno") return { probability: clamp(a.probability) };
|
|
260
|
+
const raw = Object.entries(a.probabilities).map(([k, p]) => [k, clamp(p)]);
|
|
261
|
+
const total = raw.reduce((s, [, p]) => s + p, 0);
|
|
262
|
+
const probabilities = Object.fromEntries(raw.map(([k, p]) => [k, total ? p / total : 0]));
|
|
263
|
+
return { probabilities, confidence: Math.max(0, ...Object.values(probabilities)) };
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Fits a monotonic calibrator (isotonic regression, pool-adjacent-violators)
|
|
268
|
+
* from `[predicted, outcome]` pairs, outcome 0 or 1. Returns `(p) => p`,
|
|
269
|
+
* linear between fitted points.
|
|
270
|
+
*/
|
|
271
|
+
export function fitIsotonic(samples) {
|
|
272
|
+
const sorted = [...samples].sort((a, b) => a[0] - b[0]);
|
|
273
|
+
// Equal predictions form one point.
|
|
274
|
+
const points = [];
|
|
275
|
+
for (const [x, y] of sorted) {
|
|
276
|
+
if (points.at(-1)?.x === x) {
|
|
277
|
+
points.at(-1).sum += Number(y);
|
|
278
|
+
points.at(-1).n++;
|
|
279
|
+
} else points.push({ x, sum: Number(y), n: 1 });
|
|
280
|
+
}
|
|
281
|
+
const blocks = [];
|
|
282
|
+
for (const p of points) {
|
|
283
|
+
blocks.push({ ...p });
|
|
284
|
+
while (blocks.length > 1 && mean(blocks.at(-2)) > mean(blocks.at(-1))) {
|
|
285
|
+
const b = blocks.pop();
|
|
286
|
+
const a = blocks.at(-1);
|
|
287
|
+
a.x = (a.x * a.n + b.x * b.n) / (a.n + b.n);
|
|
288
|
+
a.sum += b.sum;
|
|
289
|
+
a.n += b.n;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
const pts = blocks.map((b) => [b.x, mean(b)]);
|
|
293
|
+
return (p) => {
|
|
294
|
+
if (!pts.length) return p;
|
|
295
|
+
if (p <= pts[0][0]) return pts[0][1];
|
|
296
|
+
for (let i = 1; i < pts.length; i++) {
|
|
297
|
+
const [x0, y0] = pts[i - 1];
|
|
298
|
+
const [x1, y1] = pts[i];
|
|
299
|
+
if (p <= x1) return x1 === x0 ? y1 : y0 + ((p - x0) / (x1 - x0)) * (y1 - y0);
|
|
300
|
+
}
|
|
301
|
+
return pts.at(-1)[1];
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
const mean = (b) => b.sum / b.n;
|
|
305
|
+
|
|
306
|
+
/** Mean squared error of `[predicted, outcome]` pairs: lower is better calibrated. */
|
|
307
|
+
export function brierScore(samples) {
|
|
308
|
+
if (!samples.length) return null;
|
|
309
|
+
return samples.reduce((s, [p, y]) => s + (p - y) ** 2, 0) / samples.length;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Calls `onStart({ model, request })`, then `onEnd({ model, request, response, durationMs })`
|
|
314
|
+
* or `onError({ model, request, error, durationMs })`. Hook errors are ignored.
|
|
315
|
+
*/
|
|
316
|
+
export function observe({ onStart, onEnd, onError, now = () => performance.now() } = {}) {
|
|
317
|
+
const call = (hook, arg) => {
|
|
318
|
+
try {
|
|
319
|
+
hook?.(arg);
|
|
320
|
+
} catch {
|
|
321
|
+
// Observability must never change the result.
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
return (next) => async (model, request, opts) => {
|
|
325
|
+
const t0 = now();
|
|
326
|
+
call(onStart, { model, request });
|
|
327
|
+
try {
|
|
328
|
+
const response = await next(model, request, opts);
|
|
329
|
+
call(onEnd, { model, request, response, durationMs: now() - t0 });
|
|
330
|
+
return response;
|
|
331
|
+
} catch (error) {
|
|
332
|
+
call(onError, { model, request, error, durationMs: now() - t0 });
|
|
333
|
+
throw error;
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Asks several models the same request at once and returns every result, keyed by model, in
|
|
340
|
+
* member order. Nothing is merged: combining answers is the app's choice. `decide`: `client.decide`
|
|
341
|
+
* or a composed one (so `retry` etc. apply per member). `members`: `"provider/model"` strings or
|
|
342
|
+
* `{ model, enabled? }`. Every member gets the same request.
|
|
343
|
+
* Each result is `{ response }`, `{ error }`, `{ skipped: true }` (the member can't take the
|
|
344
|
+
* request: `Unsupported`, raised before any network call) or `{ timedOut: true }`, plus `ms`.
|
|
345
|
+
*/
|
|
346
|
+
export async function fanOut(decide, request, members, { timeoutMs, signal } = {}) {
|
|
347
|
+
const active = members.map((m) => (typeof m === "string" ? { model: m } : m)).filter((m) => m.enabled !== false);
|
|
348
|
+
if (!active.length) throw new RangeError("fanOut: no enabled members");
|
|
349
|
+
const seen = new Set();
|
|
350
|
+
for (const m of active) {
|
|
351
|
+
if (seen.has(m.model)) throw new RangeError(`fanOut: \`${m.model}\` is listed twice`);
|
|
352
|
+
seen.add(m.model);
|
|
353
|
+
}
|
|
354
|
+
signal?.throwIfAborted();
|
|
355
|
+
|
|
356
|
+
// One controller stops every member: on the caller's signal or at the deadline. Members
|
|
357
|
+
// are raced against it too, so one that ignores its signal can't hold the call open.
|
|
358
|
+
const ctrl = new AbortController();
|
|
359
|
+
const onAbort = () => ctrl.abort(signal.reason);
|
|
360
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
361
|
+
const STOPPED = Symbol("stopped");
|
|
362
|
+
const stopped = new Promise((resolve) => ctrl.signal.addEventListener("abort", () => resolve(STOPPED), { once: true }));
|
|
363
|
+
const timer = timeoutMs != null ? setTimeout(() => ctrl.abort(), timeoutMs) : undefined;
|
|
364
|
+
const run = async (m) => {
|
|
365
|
+
const t0 = Date.now();
|
|
366
|
+
try {
|
|
367
|
+
const response = await Promise.race([decide(m.model, request, { signal: ctrl.signal }), stopped]);
|
|
368
|
+
if (response !== STOPPED) return { response, ms: Date.now() - t0 };
|
|
369
|
+
if (signal?.aborted) throw signal.reason;
|
|
370
|
+
return { timedOut: true, ms: Date.now() - t0 };
|
|
371
|
+
} catch (e) {
|
|
372
|
+
if (signal?.aborted) throw e; // the caller cancelled: not a member failure
|
|
373
|
+
const ms = Date.now() - t0;
|
|
374
|
+
if (ctrl.signal.aborted) return { timedOut: true, ms };
|
|
375
|
+
return e?.code === "Unsupported" ? { skipped: true, ms } : { error: e, ms };
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
try {
|
|
379
|
+
const results = await Promise.all(active.map(run));
|
|
380
|
+
return Object.fromEntries(active.map((m, i) => [m.model, results[i]]));
|
|
381
|
+
} finally {
|
|
382
|
+
clearTimeout(timer);
|
|
383
|
+
signal?.removeEventListener("abort", onAbort);
|
|
384
|
+
}
|
|
385
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "letsdecide",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "letsdecide",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "One request shape for every decision API (Jev, Clef, OpenAI, Gemini). WebAssembly core.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"keywords": ["llm", "openai", "gemini", "adapter", "decision", "wasm"],
|
|
7
|
+
"homepage": "https://github.com/Azoies1/LetsDecide#javascript--typescript",
|
|
8
|
+
"bugs": "https://github.com/Azoies1/LetsDecide/issues",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/Azoies1/LetsDecide.git",
|
|
12
|
+
"directory": "bindings/js"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"main": "index.js",
|
|
16
|
+
"types": "index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": { "types": "./index.d.ts", "default": "./index.js" },
|
|
19
|
+
"./middleware.js": { "types": "./middleware.d.ts", "default": "./middleware.js" },
|
|
20
|
+
"./conformance": { "types": "./conformance.d.ts", "default": "./conformance.js" },
|
|
21
|
+
"./conformance.js": { "types": "./conformance.d.ts", "default": "./conformance.js" }
|
|
22
|
+
},
|
|
23
|
+
"files": ["index.js", "index.d.ts", "middleware.js", "middleware.d.ts", "conformance.js", "conformance.d.ts", "pkg"],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "cargo build -p letsdecide-wasm --target wasm32-unknown-unknown --release && wasm-bindgen --target web --out-dir pkg ../../target/wasm32-unknown-unknown/release/letsdecide_wasm.wasm",
|
|
26
|
+
"test": "node --test test/*.test.js",
|
|
27
|
+
"test:types": "npx --yes -p typescript@5.6.3 tsc -p test-types",
|
|
28
|
+
"prepublishOnly": "npm run build && node --test test/*.test.js"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
export function build(model: string, request: string, config: string): string;
|
|
5
|
+
|
|
6
|
+
export function build_dialect(dialect: string, model: string, request: string, config: string): string;
|
|
7
|
+
|
|
8
|
+
export function builtins(): string;
|
|
9
|
+
|
|
10
|
+
export function capabilities(model: string): string;
|
|
11
|
+
|
|
12
|
+
export function check(request: string, response: string): string;
|
|
13
|
+
|
|
14
|
+
export function classify_http(response: string): string;
|
|
15
|
+
|
|
16
|
+
export function dialect(name: string): string;
|
|
17
|
+
|
|
18
|
+
export function parse(model: string, request: string, response: string): string;
|
|
19
|
+
|
|
20
|
+
export function parse_dialect(dialect: string, request: string, response: string): string;
|
|
21
|
+
|
|
22
|
+
export function resolve_dialect(dialect: string): string;
|
|
23
|
+
|
|
24
|
+
export function validate(request: string, capabilities: string): string;
|
|
25
|
+
|
|
26
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
27
|
+
|
|
28
|
+
export interface InitOutput {
|
|
29
|
+
readonly memory: WebAssembly.Memory;
|
|
30
|
+
readonly build: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
|
|
31
|
+
readonly build_dialect: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => [number, number];
|
|
32
|
+
readonly builtins: () => [number, number];
|
|
33
|
+
readonly capabilities: (a: number, b: number) => [number, number];
|
|
34
|
+
readonly check: (a: number, b: number, c: number, d: number) => [number, number];
|
|
35
|
+
readonly classify_http: (a: number, b: number) => [number, number];
|
|
36
|
+
readonly dialect: (a: number, b: number) => [number, number];
|
|
37
|
+
readonly parse: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
|
|
38
|
+
readonly parse_dialect: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
|
|
39
|
+
readonly resolve_dialect: (a: number, b: number) => [number, number];
|
|
40
|
+
readonly validate: (a: number, b: number, c: number, d: number) => [number, number];
|
|
41
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
42
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
43
|
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
44
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
45
|
+
readonly __wbindgen_start: () => void;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
52
|
+
* a precompiled `WebAssembly.Module`.
|
|
53
|
+
*
|
|
54
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
55
|
+
*
|
|
56
|
+
* @returns {InitOutput}
|
|
57
|
+
*/
|
|
58
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
62
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
63
|
+
*
|
|
64
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
65
|
+
*
|
|
66
|
+
* @returns {Promise<InitOutput>}
|
|
67
|
+
*/
|
|
68
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|