@try-works/extension-laya 0.0.0-stage → 1.0.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/README.md +38 -2
- package/lib/index.d.ts +18 -0
- package/lib/index.js +172 -0
- package/lib/index.js.map +1 -0
- package/lib/pure.d.ts +35 -0
- package/lib/pure.js +71 -0
- package/lib/pure.js.map +1 -0
- package/models.lock.json +63 -0
- package/package.json +39 -4
- package/schema/decision-choose.input.json +22 -0
- package/schema/decision-choose.output.json +20 -0
- package/schema/decision-score.input.json +18 -0
- package/schema/decision-score.output.json +18 -0
- package/schema/decision-test.input.json +10 -0
- package/schema/decision-test.output.json +18 -0
- package/tool-mode.extension.json +87 -0
- package/vendor/LICENSE.laya-ts +176 -0
- package/vendor/laya-ts/agent.d.ts +216 -0
- package/vendor/laya-ts/agent.js +631 -0
- package/vendor/laya-ts/common.d.ts +167 -0
- package/vendor/laya-ts/common.js +478 -0
- package/vendor/laya-ts/dx.d.ts +17 -0
- package/vendor/laya-ts/dx.js +46 -0
- package/vendor/laya-ts/email.d.ts +2 -0
- package/vendor/laya-ts/email.js +184 -0
- package/vendor/laya-ts/hooks.d.ts +134 -0
- package/vendor/laya-ts/hooks.js +379 -0
- package/vendor/laya-ts/index.d.ts +22 -0
- package/vendor/laya-ts/index.js +13 -0
- package/vendor/laya-ts/lang.d.ts +24 -0
- package/vendor/laya-ts/lang.js +590 -0
- package/vendor/laya-ts/presets.d.ts +5 -0
- package/vendor/laya-ts/presets.js +175 -0
- package/vendor/laya-ts/providers.d.ts +67 -0
- package/vendor/laya-ts/providers.js +668 -0
- package/vendor/laya-ts/router.d.ts +186 -0
- package/vendor/laya-ts/router.js +757 -0
- package/vendor/laya-ts/shortlist.d.ts +65 -0
- package/vendor/laya-ts/shortlist.js +407 -0
- package/vendor/laya-ts/structured.d.ts +89 -0
- package/vendor/laya-ts/structured.js +256 -0
- package/vendor/laya-ts/tokenizer.d.ts +66 -0
- package/vendor/laya-ts/tokenizer.js +482 -0
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opt-in prediction hooks: observe or shape every decision without forking.
|
|
3
|
+
*
|
|
4
|
+
* A hook is either a plain `(ctx) => void` or an object implementing any subset of the
|
|
5
|
+
* lifecycle methods on `Hook`. Hooks are configured on `Agent` / `Router` and can be
|
|
6
|
+
* overridden per call. Port of `laya/hooks.py`.
|
|
7
|
+
*/
|
|
8
|
+
/** Mutable state passed to every hook for one call. */
|
|
9
|
+
export class PredictContext {
|
|
10
|
+
/** `states` / `questions` may be rewritten by `onPredictStart`. */
|
|
11
|
+
states;
|
|
12
|
+
questions;
|
|
13
|
+
/** Shared by every hook of one call. */
|
|
14
|
+
runId;
|
|
15
|
+
/** Set by `skip()` or after inference; `onPredictEnd` may rewrite it. */
|
|
16
|
+
results = null;
|
|
17
|
+
/** Router: the RouteDecision. */
|
|
18
|
+
decision = null;
|
|
19
|
+
/** Resolved checkpoint name. */
|
|
20
|
+
model = null;
|
|
21
|
+
agent = null;
|
|
22
|
+
router = null;
|
|
23
|
+
/** Per-call token-budget overrides; null = agent config. */
|
|
24
|
+
maxLen = null;
|
|
25
|
+
headMaxLen = null;
|
|
26
|
+
/** Aggregated input/output tokens across results. */
|
|
27
|
+
usage = null;
|
|
28
|
+
startedAt;
|
|
29
|
+
elapsedMs = null;
|
|
30
|
+
error = null;
|
|
31
|
+
constructor(init) {
|
|
32
|
+
this.states = init.states;
|
|
33
|
+
this.questions = init.questions;
|
|
34
|
+
this.runId = newRunId();
|
|
35
|
+
this.startedAt = now();
|
|
36
|
+
for (const [k, v] of Object.entries(init)) {
|
|
37
|
+
if (k !== "states" && k !== "questions" && v !== undefined) {
|
|
38
|
+
this[k] = v;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** Set cached results from a start hook; inference is skipped, end hooks still run. */
|
|
43
|
+
skip(results) {
|
|
44
|
+
this.results = results;
|
|
45
|
+
}
|
|
46
|
+
/** Set elapsedMs from startedAt. Called by the dispatching call, not by hooks. */
|
|
47
|
+
markElapsed() {
|
|
48
|
+
this.elapsedMs = now() - this.startedAt;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function newRunId() {
|
|
52
|
+
const c = globalThis.crypto;
|
|
53
|
+
if (c && typeof c.randomUUID === "function")
|
|
54
|
+
return c.randomUUID().replaceAll("-", "");
|
|
55
|
+
let hex = "";
|
|
56
|
+
for (let i = 0; i < 32; i++)
|
|
57
|
+
hex += Math.floor(Math.random() * 16).toString(16);
|
|
58
|
+
return hex;
|
|
59
|
+
}
|
|
60
|
+
function now() {
|
|
61
|
+
const p = globalThis.performance;
|
|
62
|
+
return p && typeof p.now === "function" ? p.now() : Date.now();
|
|
63
|
+
}
|
|
64
|
+
export const HOOK_EVENTS = [
|
|
65
|
+
"onPredictStart",
|
|
66
|
+
"onPredictEnd",
|
|
67
|
+
"onRoute",
|
|
68
|
+
"onLoad",
|
|
69
|
+
"onEvict",
|
|
70
|
+
"onError",
|
|
71
|
+
];
|
|
72
|
+
/**
|
|
73
|
+
* No-op base class: subclass it and override only the events you need.
|
|
74
|
+
*
|
|
75
|
+
* `Hook` is the structural interface; `BaseHook` is the concrete convenience when you would
|
|
76
|
+
* rather subclass than implement methods by shape. Every method does nothing by default.
|
|
77
|
+
*/
|
|
78
|
+
export class BaseHook {
|
|
79
|
+
onPredictStart(_ctx) { }
|
|
80
|
+
onPredictEnd(_ctx) { }
|
|
81
|
+
onRoute(_ctx) { }
|
|
82
|
+
onLoad(_ctx) { }
|
|
83
|
+
onEvict(_ctx) { }
|
|
84
|
+
onError(_ctx) { }
|
|
85
|
+
}
|
|
86
|
+
function isHookLike(item) {
|
|
87
|
+
return (typeof item === "object" &&
|
|
88
|
+
item !== null &&
|
|
89
|
+
HOOK_EVENTS.some((e) => typeof item[e] === "function"));
|
|
90
|
+
}
|
|
91
|
+
function typeName(v) {
|
|
92
|
+
if (v === null)
|
|
93
|
+
return "null";
|
|
94
|
+
if (Array.isArray(v))
|
|
95
|
+
return "Array";
|
|
96
|
+
if (typeof v === "object")
|
|
97
|
+
return v.constructor?.name ?? "object";
|
|
98
|
+
return typeof v;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Normalise the hook arguments shared by Agent, Router and every predict call: an optional
|
|
102
|
+
* hook (object or list) plus optional plain start/end callables. A plain callable is not a
|
|
103
|
+
* hook on its own -- which lifecycle event would it bind to? Passing one as `hooks` is a
|
|
104
|
+
* TypeError; pass it as `onPredictStart` / `onPredictEnd` instead. The same callable as both
|
|
105
|
+
* start and end is a TypeError too: the registry dedupes by identity, so one of the two would
|
|
106
|
+
* silently never fire.
|
|
107
|
+
*/
|
|
108
|
+
export function normaliseHooks(hooks, onPredictStart, onPredictEnd) {
|
|
109
|
+
const out = [];
|
|
110
|
+
const append = (item) => {
|
|
111
|
+
if (item === null || item === undefined)
|
|
112
|
+
return;
|
|
113
|
+
if (typeof item === "function") {
|
|
114
|
+
// A JS function can carry properties; one that also defines hook methods is ambiguous.
|
|
115
|
+
if (HOOK_EVENTS.some((e) => typeof item[e] === "function")) {
|
|
116
|
+
throw new TypeError("a hook must be a plain callable or implement hook methods, not both");
|
|
117
|
+
}
|
|
118
|
+
throw new TypeError("a plain callable is ambiguous; pass it as onPredictStart or onPredictEnd");
|
|
119
|
+
}
|
|
120
|
+
if (Array.isArray(item)) {
|
|
121
|
+
for (const h of item)
|
|
122
|
+
append(h);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (typeof item !== "object") {
|
|
126
|
+
throw new TypeError(`hooks must be Hook objects, got ${typeName(item)}`);
|
|
127
|
+
}
|
|
128
|
+
if (!isHookLike(item)) {
|
|
129
|
+
throw new TypeError(`a hook must implement at least one hook method (${HOOK_EVENTS.join(", ")})`);
|
|
130
|
+
}
|
|
131
|
+
out.push(item);
|
|
132
|
+
};
|
|
133
|
+
append(hooks);
|
|
134
|
+
if (onPredictStart !== null && onPredictStart !== undefined) {
|
|
135
|
+
if (typeof onPredictStart !== "function") {
|
|
136
|
+
throw new TypeError(`onPredictStart must be callable, got ${typeName(onPredictStart)}`);
|
|
137
|
+
}
|
|
138
|
+
out.push({ onPredictStart });
|
|
139
|
+
}
|
|
140
|
+
if (onPredictEnd !== null && onPredictEnd !== undefined) {
|
|
141
|
+
if (typeof onPredictEnd !== "function") {
|
|
142
|
+
throw new TypeError(`onPredictEnd must be callable, got ${typeName(onPredictEnd)}`);
|
|
143
|
+
}
|
|
144
|
+
out.push({ onPredictEnd });
|
|
145
|
+
}
|
|
146
|
+
if (onPredictStart !== null &&
|
|
147
|
+
onPredictStart !== undefined &&
|
|
148
|
+
onPredictStart === onPredictEnd) {
|
|
149
|
+
throw new TypeError("onPredictStart and onPredictEnd must be different callables; one callable cannot serve both events");
|
|
150
|
+
}
|
|
151
|
+
return out;
|
|
152
|
+
}
|
|
153
|
+
const defaultHooksList = [];
|
|
154
|
+
/** The process-wide hooks, a copy, in order. Empty unless set via `setDefaultHooks`. */
|
|
155
|
+
export function defaultHooks() {
|
|
156
|
+
return [...defaultHooksList];
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Replace the process-wide default hooks.
|
|
160
|
+
*
|
|
161
|
+
* Defaults run before installed and per-call hooks for every `Agent` and `Router` in the
|
|
162
|
+
* process, so a tracer or metrics hook does not have to be threaded through every
|
|
163
|
+
* construction. Accepts the same arguments as the `hooks` option.
|
|
164
|
+
*/
|
|
165
|
+
export function setDefaultHooks(hooks, onPredictStart, onPredictEnd) {
|
|
166
|
+
const normalised = normaliseHooks(hooks, onPredictStart, onPredictEnd);
|
|
167
|
+
defaultHooksList.length = 0;
|
|
168
|
+
defaultHooksList.push(...normalised);
|
|
169
|
+
}
|
|
170
|
+
/** Append one hook or a list of hooks to the process-wide defaults. */
|
|
171
|
+
export function addDefaultHook(hook) {
|
|
172
|
+
defaultHooksList.push(...normaliseHooks(hook));
|
|
173
|
+
}
|
|
174
|
+
/** Remove every process-wide default hook. */
|
|
175
|
+
export function clearDefaultHooks() {
|
|
176
|
+
defaultHooksList.length = 0;
|
|
177
|
+
}
|
|
178
|
+
const defaultsRan = new WeakSet();
|
|
179
|
+
/** `Router.predict` marks the options of its Agent call: the Router already ran the defaults for this request. */
|
|
180
|
+
export function markDefaultsRan(opts) {
|
|
181
|
+
defaultsRan.add(opts);
|
|
182
|
+
}
|
|
183
|
+
/** Whether `opts` was marked by `markDefaultsRan`, so the Agent must not run the defaults a second time. */
|
|
184
|
+
export function defaultsAlreadyRan(opts) {
|
|
185
|
+
return defaultsRan.has(opts);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Effective hook list for one call: defaults, then installed, then per-call hooks.
|
|
189
|
+
*
|
|
190
|
+
* Reads the process-wide defaults at call time, so hooks set after construction still apply.
|
|
191
|
+
*/
|
|
192
|
+
export function composeHooks(installed, hooks, onPredictStart, onPredictEnd) {
|
|
193
|
+
if (defaultHooksList.length === 0 && installed.length === 0 && (hooks === null || hooks === undefined) &&
|
|
194
|
+
(onPredictStart === null || onPredictStart === undefined) &&
|
|
195
|
+
(onPredictEnd === null || onPredictEnd === undefined)) {
|
|
196
|
+
return EMPTY_HOOKS;
|
|
197
|
+
}
|
|
198
|
+
return [...defaultHooksList, ...installed, ...normaliseHooks(hooks, onPredictStart, onPredictEnd)];
|
|
199
|
+
}
|
|
200
|
+
const EMPTY_HOOKS = [];
|
|
201
|
+
Object.freeze(EMPTY_HOOKS);
|
|
202
|
+
/**
|
|
203
|
+
* Base class giving a runtime-mutable hook list.
|
|
204
|
+
*
|
|
205
|
+
* `Agent` and `Router` extend it so hooks can be added, removed or scoped after construction.
|
|
206
|
+
* Mutation replaces the array, so a call that already snapshotted its active hooks is never
|
|
207
|
+
* disturbed by an add or remove that lands mid-flight.
|
|
208
|
+
*/
|
|
209
|
+
export class HookRegistry {
|
|
210
|
+
hooks = [];
|
|
211
|
+
/** Install one hook or a list of them. Returns this for chaining. */
|
|
212
|
+
addHook(hook) {
|
|
213
|
+
const added = normaliseHooks(hook);
|
|
214
|
+
if (added.length > 0)
|
|
215
|
+
this.hooks = [...this.hooks, ...added];
|
|
216
|
+
return this;
|
|
217
|
+
}
|
|
218
|
+
/** Remove a hook by identity. Returns true if it was installed. */
|
|
219
|
+
removeHook(hook) {
|
|
220
|
+
const before = this.hooks.length;
|
|
221
|
+
this.hooks = this.hooks.filter((installed) => installed !== hook);
|
|
222
|
+
return this.hooks.length !== before;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Run `fn` with hooks installed, then remove them -- works for sync and async `fn`:
|
|
226
|
+
*
|
|
227
|
+
* await router.withHooks([tracer], () => router.predict(state, questions));
|
|
228
|
+
*/
|
|
229
|
+
withHooks(hookArgs, fn) {
|
|
230
|
+
const added = normaliseHooks(hookArgs);
|
|
231
|
+
this.hooks = [...this.hooks, ...added];
|
|
232
|
+
const release = () => {
|
|
233
|
+
this.hooks = this.hooks.filter((installed) => !added.includes(installed));
|
|
234
|
+
};
|
|
235
|
+
let out;
|
|
236
|
+
try {
|
|
237
|
+
out = fn();
|
|
238
|
+
}
|
|
239
|
+
catch (err) {
|
|
240
|
+
release();
|
|
241
|
+
throw err;
|
|
242
|
+
}
|
|
243
|
+
if (out instanceof Promise) {
|
|
244
|
+
return out.finally(release);
|
|
245
|
+
}
|
|
246
|
+
release();
|
|
247
|
+
return out;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
/** Sum the per-state usage blocks so a hook sees one total for the call. */
|
|
251
|
+
export function aggregateUsage(results) {
|
|
252
|
+
const total = (key) => results.reduce((acc, r) => {
|
|
253
|
+
const usage = r?.["usage"];
|
|
254
|
+
const v = usage?.[key];
|
|
255
|
+
return acc + (typeof v === "number" && Number.isFinite(v) ? Math.trunc(v) : 0);
|
|
256
|
+
}, 0);
|
|
257
|
+
return { input_tokens: total("input_tokens"), output_tokens: total("output_tokens") };
|
|
258
|
+
}
|
|
259
|
+
function reportHookFailure(hook, event, err) {
|
|
260
|
+
const name = hook?.constructor?.name ?? "hook";
|
|
261
|
+
console.warn(`laya: hook ${name}.${event} failed: ${String(err)}`);
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Call `event` on every hook that implements it.
|
|
265
|
+
*
|
|
266
|
+
* `raiseErrors=false` warns and continues, for hooks (telemetry) that must not fail a
|
|
267
|
+
* request. Python also takes a `lock` to serialise dispatch for hooks that are not safe to
|
|
268
|
+
* run concurrently; JS hooks run on one thread, so there is nothing to lock.
|
|
269
|
+
*
|
|
270
|
+
* It does not wait for a hook that returns a promise, so it is for callers that cannot wait,
|
|
271
|
+
* such as the synchronous `Router.route`; a rejection can then only be reported as a warning.
|
|
272
|
+
* `dispatchAsync` waits and applies `raiseErrors` to it.
|
|
273
|
+
*/
|
|
274
|
+
function isThenable(value) {
|
|
275
|
+
return typeof value?.then === "function";
|
|
276
|
+
}
|
|
277
|
+
function trimTrailingZeros(decimal) {
|
|
278
|
+
const dot = decimal.indexOf(".");
|
|
279
|
+
if (dot < 0)
|
|
280
|
+
return decimal;
|
|
281
|
+
let end = decimal.length;
|
|
282
|
+
while (end > 0 && decimal.charAt(end - 1) === "0")
|
|
283
|
+
end--;
|
|
284
|
+
if (end > 0 && decimal.charAt(end - 1) === ".")
|
|
285
|
+
end--;
|
|
286
|
+
return decimal.slice(0, end);
|
|
287
|
+
}
|
|
288
|
+
/** Seconds the way CPython prints `"%g"`: `exceeded 0.05s` and `exceeded 1s`, not `1.0s`. */
|
|
289
|
+
function formatTimeoutSeconds(timeoutMs) {
|
|
290
|
+
const value = timeoutMs / 1000;
|
|
291
|
+
if (!Number.isFinite(value))
|
|
292
|
+
return String(value);
|
|
293
|
+
const scientific = value.toExponential(5);
|
|
294
|
+
const marker = scientific.indexOf("e");
|
|
295
|
+
if (marker < 0)
|
|
296
|
+
return scientific;
|
|
297
|
+
const exponent = Number(scientific.slice(marker + 1));
|
|
298
|
+
if (exponent < -4 || exponent >= 6) {
|
|
299
|
+
const sign = exponent < 0 ? "-" : "+";
|
|
300
|
+
return (trimTrailingZeros(scientific.slice(0, marker)) +
|
|
301
|
+
`e${sign}${String(Math.abs(exponent)).padStart(2, "0")}`);
|
|
302
|
+
}
|
|
303
|
+
return trimTrailingZeros(value.toFixed(5 - exponent));
|
|
304
|
+
}
|
|
305
|
+
/** JS has no `TimeoutError` class; Python raises that builtin, so the name is set to match. */
|
|
306
|
+
function hookTimeoutError(operationName, timeoutMs) {
|
|
307
|
+
const err = new Error(`laya: hook ${operationName} exceeded ${formatTimeoutSeconds(timeoutMs)}s`);
|
|
308
|
+
err.name = "TimeoutError";
|
|
309
|
+
return err;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Await one hook result. The return value is discarded: nothing reads it.
|
|
313
|
+
*
|
|
314
|
+
* A non-thenable has already finished, so a configured timeout starts no timer. A thenable is
|
|
315
|
+
* raced against `timeoutMs`, and the timer is cleared whether the hook settles or the deadline
|
|
316
|
+
* wins. The deadline matches Python: `TimeoutError`, `laya: hook <Class.event> exceeded <N>s`.
|
|
317
|
+
*/
|
|
318
|
+
async function runWithTimeout(result, timeoutMs, operationName) {
|
|
319
|
+
if (timeoutMs === null || timeoutMs === undefined) {
|
|
320
|
+
await result;
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
if (!isThenable(result))
|
|
324
|
+
return;
|
|
325
|
+
let timer;
|
|
326
|
+
try {
|
|
327
|
+
await Promise.race([
|
|
328
|
+
result,
|
|
329
|
+
new Promise((_, reject) => {
|
|
330
|
+
timer = setTimeout(() => {
|
|
331
|
+
reject(hookTimeoutError(operationName, timeoutMs));
|
|
332
|
+
}, timeoutMs);
|
|
333
|
+
}),
|
|
334
|
+
]);
|
|
335
|
+
}
|
|
336
|
+
finally {
|
|
337
|
+
if (timer !== undefined)
|
|
338
|
+
clearTimeout(timer);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
export function dispatch(hooks, event, ctx, opts = {}) {
|
|
342
|
+
const raiseErrors = opts.raiseErrors ?? true;
|
|
343
|
+
for (const hook of hooks) {
|
|
344
|
+
const method = hook?.[event];
|
|
345
|
+
if (typeof method !== "function")
|
|
346
|
+
continue;
|
|
347
|
+
try {
|
|
348
|
+
const result = method.call(hook, ctx);
|
|
349
|
+
if (isThenable(result)) {
|
|
350
|
+
Promise.resolve(result).catch((err) => reportHookFailure(hook, event, err));
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
catch (err) {
|
|
354
|
+
if (raiseErrors)
|
|
355
|
+
throw err;
|
|
356
|
+
reportHookFailure(hook, event, err);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
/** Like `dispatch`, but waits for each hook that returns a promise before the next runs, and a
|
|
361
|
+
* rejection follows `raiseErrors` the way a thrown error does. */
|
|
362
|
+
export async function dispatchAsync(hooks, event, ctx, opts = {}) {
|
|
363
|
+
const timeoutMs = opts.timeoutMs ?? null;
|
|
364
|
+
const raiseErrors = opts.raiseErrors ?? true;
|
|
365
|
+
for (const hook of hooks) {
|
|
366
|
+
const method = hook?.[event];
|
|
367
|
+
if (typeof method !== "function")
|
|
368
|
+
continue;
|
|
369
|
+
const operationName = `${hook?.constructor?.name ?? "hook"}.${event}`;
|
|
370
|
+
try {
|
|
371
|
+
await runWithTimeout(method.call(hook, ctx), timeoutMs, operationName);
|
|
372
|
+
}
|
|
373
|
+
catch (err) {
|
|
374
|
+
if (raiseErrors)
|
|
375
|
+
throw err;
|
|
376
|
+
reportHookFailure(hook, event, err);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare const VERSION = "0.1.0";
|
|
2
|
+
export { Agent, checkQuestion, toInternal, defaultTokenizer } from "./agent.js";
|
|
3
|
+
export type { QuestionDef, SystemOneResult, ChoiceAnswer, ScoreAnswer, NoulAnswer, SystemAnswer, SystemUsage, ActionInfo, AgentCfg, AgentOptions, PredictOptions, } from "./agent.js";
|
|
4
|
+
export { createNodeProvider, createWebProvider, feed, feedHead, loadNodeBundle, loadWebBundle, PINNED_REVISIONS, resolveRevision } from "./providers.js";
|
|
5
|
+
export type { Batch, SessionProvider, ProviderOptions, NodeBundle, WebBundle } from "./providers.js";
|
|
6
|
+
export { Router, normaliseName, DEFAULT_MODELS, digestsFromEnv, _digestsFromEnv } from "./router.js";
|
|
7
|
+
export type { RoutedResult, RouteDecision, ModelName, ModelSpec, BatchRequest, PredictBatchOptions, RouterOptions, RouteOptions } from "./router.js";
|
|
8
|
+
export { shortlistChoice, predictShortlist, predictTournament, embedFnFromAgent, cached, cachedEmbedFn, DEFAULT_SHORTLIST_K, DEFAULT_SHORTLIST_MAXSIZE, DEFAULT_TOURNAMENT_GROUP } from "./shortlist.js";
|
|
9
|
+
export type { EmbedFn, ShortlistMeta, TournamentMeta, CacheInfo, CachedEmbedFn } from "./shortlist.js";
|
|
10
|
+
export { analyse, isEnglish, guessLatinLanguage, detectScript } from "./lang.js";
|
|
11
|
+
export type { AnalyseResult, LatinProfile } from "./lang.js";
|
|
12
|
+
export { cleanEmailBody, emailState } from "./email.js";
|
|
13
|
+
export { PredictContext, HookRegistry, BaseHook, normaliseHooks, dispatch, aggregateUsage, composeHooks, defaultHooks, setDefaultHooks, addDefaultHook, clearDefaultHooks, HOOK_EVENTS, } from "./hooks.js";
|
|
14
|
+
export type { Hook, HookEvent, HookArg, PredictHook, PredictHookArg } from "./hooks.js";
|
|
15
|
+
export { triageQuestions, emailQuestions, guardQuestions, moderationQuestions, routerQuestions } from "./presets.js";
|
|
16
|
+
export { decide, planFromJsonSchema, questionsFromJsonSchema, answersToJson, SchemaError, MAX_PROPERTIES, MAX_OPTIONS, MAX_SCORE_LEVELS, } from "./structured.js";
|
|
17
|
+
export type { DecisionResult, DecideOptions, DecideRunner, PlannedField } from "./structured.js";
|
|
18
|
+
export { renderOptions, serializeState, buildSequence, buildQuestionPrefix, sequenceWithState, collapsedOptions, softmax, confidenceFromProbs, answerConfidence, checkMinConfidence, checkMinConfidenceMap, flagLowConfidence, optionBucket, resolveMinConfidence, clampTemperature, tempBucket, applyBinningMap, checkBinningMap, collateItems, TEMP_MIN, TEMP_MAX, } from "./common.js";
|
|
19
|
+
export type { QType, InternalQ, CollateItem, CollatedBatch, QuestionPrefix, SequenceStats, OptionStats, MinConfidence, MinConfidenceMap, MinConfidenceBucket, MinConfidenceKey, BinningEntry, BinningMap, } from "./common.js";
|
|
20
|
+
export { q, best, topK, isConfident } from "./dx.js";
|
|
21
|
+
export { bpeEncode, metaspaceEncode, encodeWithData, parseTokenizerJson, loadTokenizerJson, CHECKPOINT_IDS, SPECIAL_ALIASES, METASPACE_REPLACEMENT } from "./tokenizer.js";
|
|
22
|
+
export type { TokenizerLike, TokenizerData, TokenizerIds, PreTokenizerKind } from "./tokenizer.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const VERSION = "0.1.0";
|
|
2
|
+
export { Agent, checkQuestion, toInternal, defaultTokenizer } from "./agent.js";
|
|
3
|
+
export { createNodeProvider, createWebProvider, feed, feedHead, loadNodeBundle, loadWebBundle, PINNED_REVISIONS, resolveRevision } from "./providers.js";
|
|
4
|
+
export { Router, normaliseName, DEFAULT_MODELS, digestsFromEnv, _digestsFromEnv } from "./router.js";
|
|
5
|
+
export { shortlistChoice, predictShortlist, predictTournament, embedFnFromAgent, cached, cachedEmbedFn, DEFAULT_SHORTLIST_K, DEFAULT_SHORTLIST_MAXSIZE, DEFAULT_TOURNAMENT_GROUP } from "./shortlist.js";
|
|
6
|
+
export { analyse, isEnglish, guessLatinLanguage, detectScript } from "./lang.js";
|
|
7
|
+
export { cleanEmailBody, emailState } from "./email.js";
|
|
8
|
+
export { PredictContext, HookRegistry, BaseHook, normaliseHooks, dispatch, aggregateUsage, composeHooks, defaultHooks, setDefaultHooks, addDefaultHook, clearDefaultHooks, HOOK_EVENTS, } from "./hooks.js";
|
|
9
|
+
export { triageQuestions, emailQuestions, guardQuestions, moderationQuestions, routerQuestions } from "./presets.js";
|
|
10
|
+
export { decide, planFromJsonSchema, questionsFromJsonSchema, answersToJson, SchemaError, MAX_PROPERTIES, MAX_OPTIONS, MAX_SCORE_LEVELS, } from "./structured.js";
|
|
11
|
+
export { renderOptions, serializeState, buildSequence, buildQuestionPrefix, sequenceWithState, collapsedOptions, softmax, confidenceFromProbs, answerConfidence, checkMinConfidence, checkMinConfidenceMap, flagLowConfidence, optionBucket, resolveMinConfidence, clampTemperature, tempBucket, applyBinningMap, checkBinningMap, collateItems, TEMP_MIN, TEMP_MAX, } from "./common.js";
|
|
12
|
+
export { q, best, topK, isConfident } from "./dx.js";
|
|
13
|
+
export { bpeEncode, metaspaceEncode, encodeWithData, parseTokenizerJson, loadTokenizerJson, CHECKPOINT_IDS, SPECIAL_ALIASES, METASPACE_REPLACEMENT } from "./tokenizer.js";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare const NON_EN_DIACRITIC_RATE = 0.02;
|
|
2
|
+
export declare function stateText(state: unknown, maxChars?: number): string;
|
|
3
|
+
export declare function detectScript(text: string): string;
|
|
4
|
+
export declare function scriptProfile(text: string): Record<string, number>;
|
|
5
|
+
export interface LatinProfile {
|
|
6
|
+
language: string | null;
|
|
7
|
+
englishHits: number;
|
|
8
|
+
diacriticRate: number;
|
|
9
|
+
looksNonEnglish: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function latinProfile(text: string): LatinProfile;
|
|
12
|
+
export declare function guessLatinLanguage(text: string): string | null;
|
|
13
|
+
export interface AnalyseResult {
|
|
14
|
+
script: string;
|
|
15
|
+
scriptProfile: Record<string, number>;
|
|
16
|
+
language: string | null;
|
|
17
|
+
isEnglish: boolean;
|
|
18
|
+
languageUndecided: boolean;
|
|
19
|
+
diacriticRate: number;
|
|
20
|
+
nonLatinFraction: number;
|
|
21
|
+
mixedSegment: string | null;
|
|
22
|
+
}
|
|
23
|
+
export declare function analyse(state: unknown): AnalyseResult;
|
|
24
|
+
export declare function isEnglish(state: unknown): boolean;
|