Non-autoregressive System 1 decision engine. Typed choice, score and yes/no decisions over any text in a single forward pass, in 100+ languages, with a router that picks the right checkpoint per request.
Python calibrationclassificationdecision-modelhuggingfacejevmodernbertmultilingualnlppythonpytorchroutingtyped-decisionszero-shot
fix(ts): close the hook timeout template literal in hooks.ts
Cursor Agentcf0e8ffb8e8b
diff --git a/laya-ts/src/agent.ts b/laya-ts/src/agent.tsindex a895ff12..72ec1e59 100644--- a/laya-ts/src/agent.ts+++ b/laya-ts/src/agent.ts@@ -516,6 +516,8 @@ export class Agent extends HookRegistry {? [...this.hooks, ...normaliseHooks(opts.hooks, opts.onPredictStart, opts.onPredictEnd)]: composeHooks(this.hooks, opts.hooks, opts.onPredictStart, opts.onPredictEnd);const raiseErrors = opts.hooksRaise ?? this.hooksRaise;+ const hookTimeoutSec = this.hooksTimeout ?? null;+ const hookTimeoutMs = hookTimeoutSec !== null ? hookTimeoutSec * 1000 : null;const ctx = new PredictContext({states,questions: questions as Record<string, unknown>,@@ -524,7 +526,7 @@ export class Agent extends HookRegistry {headMaxLen: opts.headMaxLen ?? null,});try {- await dispatchAsync(active, "onPredictStart", ctx, { raiseErrors, timeoutMs: this.hooksTimeout !== null ? this.hooksTimeout * 1000 : null });+ await dispatchAsync(active, "onPredictStart", ctx, { raiseErrors, timeoutMs: hookTimeoutMs });if (ctx.results === null) {if (!Array.isArray(ctx.states)) {throw new TypeError(@@ -575,7 +577,7 @@ export class Agent extends HookRegistry {}}try {- await dispatchAsync(active, "onPredictEnd", ctx, { raiseErrors, timeoutMs: this.hooksTimeout !== null ? this.hooksTimeout * 1000 : null });+ await dispatchAsync(active, "onPredictEnd", ctx, { raiseErrors, timeoutMs: hookTimeoutMs });} catch (hookErr) {// End hooks run on the failure path too; do not let one mask the real error.if (ctx.error === null) throw hookErr;diff --git a/laya-ts/src/hooks.ts b/laya-ts/src/hooks.tsindex de475e2a..45adc74a 100644--- a/laya-ts/src/hooks.ts+++ b/laya-ts/src/hooks.ts@@ -348,7 +348,7 @@ async function runWithTimeout<T>(try {return await Promise.race([promise, new Promise<never>((_, reject) => {abortController.signal.addEventListener("abort", () => {- reject(new Error(`hook ${operationName} timed out after ${timeoutMs}ms")));+ reject(new Error(`hook ${operationName} timed out after ${timeoutMs}ms`));});})]);} finally {@@ -360,7 +360,7 @@ export function dispatch(hooks: Hook[],event: HookEvent,ctx: PredictContext,- opts: { raiseErrors?: boolean; timeoutMs?: number | null } = {},+ opts: { raiseErrors?: boolean; timeoutMs?: number | null; hook?: Hook } = {},): void {const timeoutMs = opts.timeoutMs ?? null;const operationName = `${(opts.hook?.constructor?.name ?? "hook")}.`;@@ -395,7 +395,7 @@ export async function dispatchAsync(const method = hook?.[event];if (typeof method !== "function") continue;try {- await runWithTimeout(method.call(hook, ctx), timeoutMs, operationName);+ await runWithTimeout(Promise.resolve(method.call(hook, ctx)), timeoutMs, operationName);} catch (err) {if (raiseErrors) throw err;reportHookFailure(hook, event, err);