@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.
Files changed (43) hide show
  1. package/README.md +38 -2
  2. package/lib/index.d.ts +18 -0
  3. package/lib/index.js +172 -0
  4. package/lib/index.js.map +1 -0
  5. package/lib/pure.d.ts +35 -0
  6. package/lib/pure.js +71 -0
  7. package/lib/pure.js.map +1 -0
  8. package/models.lock.json +63 -0
  9. package/package.json +39 -4
  10. package/schema/decision-choose.input.json +22 -0
  11. package/schema/decision-choose.output.json +20 -0
  12. package/schema/decision-score.input.json +18 -0
  13. package/schema/decision-score.output.json +18 -0
  14. package/schema/decision-test.input.json +10 -0
  15. package/schema/decision-test.output.json +18 -0
  16. package/tool-mode.extension.json +87 -0
  17. package/vendor/LICENSE.laya-ts +176 -0
  18. package/vendor/laya-ts/agent.d.ts +216 -0
  19. package/vendor/laya-ts/agent.js +631 -0
  20. package/vendor/laya-ts/common.d.ts +167 -0
  21. package/vendor/laya-ts/common.js +478 -0
  22. package/vendor/laya-ts/dx.d.ts +17 -0
  23. package/vendor/laya-ts/dx.js +46 -0
  24. package/vendor/laya-ts/email.d.ts +2 -0
  25. package/vendor/laya-ts/email.js +184 -0
  26. package/vendor/laya-ts/hooks.d.ts +134 -0
  27. package/vendor/laya-ts/hooks.js +379 -0
  28. package/vendor/laya-ts/index.d.ts +22 -0
  29. package/vendor/laya-ts/index.js +13 -0
  30. package/vendor/laya-ts/lang.d.ts +24 -0
  31. package/vendor/laya-ts/lang.js +590 -0
  32. package/vendor/laya-ts/presets.d.ts +5 -0
  33. package/vendor/laya-ts/presets.js +175 -0
  34. package/vendor/laya-ts/providers.d.ts +67 -0
  35. package/vendor/laya-ts/providers.js +668 -0
  36. package/vendor/laya-ts/router.d.ts +186 -0
  37. package/vendor/laya-ts/router.js +757 -0
  38. package/vendor/laya-ts/shortlist.d.ts +65 -0
  39. package/vendor/laya-ts/shortlist.js +407 -0
  40. package/vendor/laya-ts/structured.d.ts +89 -0
  41. package/vendor/laya-ts/structured.js +256 -0
  42. package/vendor/laya-ts/tokenizer.d.ts +66 -0
  43. package/vendor/laya-ts/tokenizer.js +482 -0
@@ -0,0 +1,186 @@
1
+ import { type AnalyseResult } from "./lang.js";
2
+ import type { PredictOptions, QuestionDef, SystemOneResult } from "./agent.js";
3
+ import { type DecideOptions, type DecisionResult } from "./structured.js";
4
+ import { HookRegistry, type HookArg, type PredictHook } from "./hooks.js";
5
+ export declare const BUNDLE_REPO = "convaiinnovations/laya";
6
+ export interface ModelSpec {
7
+ repo: string;
8
+ subfolder: string | null;
9
+ }
10
+ export declare const DEFAULT_MODELS: Record<string, ModelSpec>;
11
+ export declare const STANDALONE_MODELS: Record<string, string>;
12
+ export type ModelName = "english" | "multilingual" | "typed-decisions";
13
+ export declare function normaliseName(name: string): ModelName;
14
+ export declare function matchTypedDecisionsWorkflow(questions: Record<string, unknown> | null | undefined): string | null;
15
+ export declare function englishFromCode(value: unknown): boolean | null;
16
+ /** Parity alias for the Python `_english_from_code` name. */
17
+ export declare const _englishFromCode: typeof englishFromCode;
18
+ export interface RouteDecision {
19
+ model: ModelName;
20
+ repo: string;
21
+ reason: string;
22
+ detection: AnalyseResult | null;
23
+ workflow: string | null;
24
+ }
25
+ export type RoutedResult = SystemOneResult & {
26
+ routing: RouteDecision;
27
+ };
28
+ export type LangGuess = string | null | undefined | ((state: unknown) => unknown);
29
+ export type AgentLoader = (name: ModelName, spec: ModelSpec) => unknown | Promise<unknown>;
30
+ export interface RouterOptions {
31
+ models?: Record<string, string | ModelSpec | [string, string | null]>;
32
+ device?: string | null;
33
+ token?: string | null;
34
+ maxLoaded?: number;
35
+ max_loaded?: number;
36
+ /** Fallback for unidentified text. Defaults to "multilingual", matching Python 0.4.0. */
37
+ default?: string;
38
+ autoTaskDetection?: boolean;
39
+ auto_task_detection?: boolean;
40
+ standaloneRepos?: boolean;
41
+ standalone_repos?: boolean;
42
+ preload?: boolean | string[];
43
+ langGuess?: LangGuess;
44
+ lang_guess?: LangGuess;
45
+ loader?: AgentLoader;
46
+ /** Optional hub revision (commit SHA/branch/tag) applied to every checkpoint load. */
47
+ revision?: string | null;
48
+ /** Per-model revision overrides, keyed by model name or alias. */
49
+ revisions?: Record<string, string | null>;
50
+ /** Per-model artifact SHA-256 digest maps, keyed by model name or alias. */
51
+ sha256Digests?: Record<string, Record<string, string> | null> | null;
52
+ /** Python-parity snake_case alias for `sha256Digests`. */
53
+ sha256_digests?: Record<string, Record<string, string> | null> | null;
54
+ hooks?: HookArg;
55
+ onPredictStart?: PredictHook;
56
+ onPredictEnd?: PredictHook;
57
+ hooksRaise?: boolean;
58
+ }
59
+ export interface RouteOptions {
60
+ model?: string | null;
61
+ task?: string | null;
62
+ lang?: string | null;
63
+ langGuess?: LangGuess;
64
+ lang_guess?: LangGuess;
65
+ hooks?: HookArg;
66
+ hooksRaise?: boolean;
67
+ }
68
+ /**
69
+ * Per-call options for `Router.predictBatch` / `predictMany` / `routeBatch`.
70
+ * `hooks`, `onPredictStart` and `onPredictEnd` are composed the same way as on `predict`:
71
+ * `setDefaultHooks` defaults, then installed hooks, then this call's hooks.
72
+ * `null`, `undefined` and `[]` add nothing.
73
+ * `hooksRaise` overrides the Router's policy for this call, including `onRoute`.
74
+ * The start and end callables apply to each request's predict lifecycle, not to routing.
75
+ */
76
+ export interface PredictBatchOptions {
77
+ hooks?: HookArg;
78
+ onPredictStart?: PredictHook;
79
+ onPredictEnd?: PredictHook;
80
+ hooksRaise?: boolean;
81
+ }
82
+ /** One item of a Router.predictBatch/routeBatch batch: state, questions, route overrides. */
83
+ export interface BatchRequest {
84
+ state: unknown;
85
+ questions: Record<string, QuestionDef>;
86
+ model?: string | null;
87
+ task?: string | null;
88
+ lang?: string | null;
89
+ langGuess?: LangGuess;
90
+ lang_guess?: LangGuess;
91
+ }
92
+ /** Turn `LAYA_SHA256_DIGESTS` into per-checkpoint digest maps when it names models. */
93
+ export declare function digestsFromEnv(models: Record<string, unknown>): Record<string, Record<string, string> | null>;
94
+ export declare const _digestsFromEnv: typeof digestsFromEnv;
95
+ export declare const _digests_from_env: typeof digestsFromEnv;
96
+ export declare class Router extends HookRegistry {
97
+ hooksRaise: boolean;
98
+ models: Record<string, ModelSpec>;
99
+ device: string | null;
100
+ token: string | null | undefined;
101
+ revision: string | null;
102
+ revisions: Partial<Record<ModelName, string | null>>;
103
+ sha256Digests: Record<string, Record<string, string> | null>;
104
+ get sha256_digests(): Record<string, Record<string, string> | null>;
105
+ maxLoaded: number;
106
+ default: ModelName;
107
+ autoTaskDetection: boolean;
108
+ langGuess: LangGuess;
109
+ loader: AgentLoader | null;
110
+ _agents: Map<string, unknown>;
111
+ _order: string[];
112
+ private readonly _loading;
113
+ constructor(opts?: RouterOptions);
114
+ load(name: string): Promise<unknown>;
115
+ _touch(key: string): void;
116
+ /** Drop least-recently-used agents until `maxLoaded` holds. Returns evicted names. */
117
+ _evict(): string[];
118
+ attach(name: string, agent: unknown): unknown;
119
+ preload(names?: string[]): Promise<this>;
120
+ unload(name?: string | null): void;
121
+ get loaded(): string[];
122
+ _resolveHint(hint: LangGuess, state: unknown): boolean | null;
123
+ /**
124
+ * Decide which checkpoint to use, then let `onRoute` hooks observe or replace the decision.
125
+ *
126
+ * `ctx.decision` is the RouteDecision; a hook may replace it (for example to pin a
127
+ * checkpoint) and the replacement is what gets returned and used. `opts.hooks` are
128
+ * per-call hooks, appended after any installed on the Router.
129
+ */
130
+ route(state: unknown, questions?: Record<string, unknown> | null, opts?: RouteOptions): RouteDecision;
131
+ /** Decide which checkpoint to use, without loading, running, or hooking anything. */
132
+ _route(state: unknown, questions?: Record<string, unknown> | null, opts?: RouteOptions): RouteDecision;
133
+ /**
134
+ * Route, then answer every question in one forward pass on the chosen checkpoint.
135
+ *
136
+ * The result is the usual systemOne payload plus a `routing` key recording the decision.
137
+ * Router-level `onPredictStart` / `onPredictEnd` hooks wrap the whole route+infer call and
138
+ * see `ctx.decision`; see hooks.ts.
139
+ */
140
+ predict(state: unknown, questions: Record<string, QuestionDef>, opts?: RouteOptions & PredictOptions): Promise<RoutedResult>;
141
+ /**
142
+ * Answer `state` against a JSON schema (or explicit `opts.questions`) and return typed
143
+ * values — see `structured.ts`. Routing options (`model`, `task`, ...) are forwarded to
144
+ * `predict`.
145
+ */
146
+ decide(state: unknown, schema: unknown, opts: DecideOptions & RouteOptions & PredictOptions & {
147
+ returnDetails: true;
148
+ }): Promise<DecisionResult>;
149
+ decide(state: unknown, schema?: unknown, opts?: DecideOptions & RouteOptions & PredictOptions): Promise<Record<string, unknown>>;
150
+ systemOne(state: unknown, questions: Record<string, QuestionDef>, opts?: RouteOptions & PredictOptions): Promise<RoutedResult>;
151
+ /**
152
+ * Route many requests in one call (Python `Router.route_batch` parity). Every request is
153
+ * validated before anything loads, so a malformed batch fails fast. Entries keep input
154
+ * order; routing is deterministic, so repeated batches route identically.
155
+ */
156
+ routeBatch(requests: BatchRequest[], opts?: PredictBatchOptions): RouteDecision[];
157
+ /**
158
+ * Route and run many requests in one call (Python `Router.predict_batch` parity).
159
+ * Requests are routed first, then grouped by checkpoint so each loaded Agent scores its
160
+ * requests in as few forward passes as possible; results are restored to input order.
161
+ * Requests routed to the same checkpoint still split into separate `predictBatch` calls
162
+ * when their question schemas differ (order-sensitively), when per-request start hooks
163
+ * set different maxLen/headMaxLen overrides, or — for an agent carrying
164
+ * `lang_temperatures` — when their languages differ: each request's effective language
165
+ * (an explicit `lang`, otherwise the detected non-English one) is forwarded so the
166
+ * batched path scores exactly like `predict`.
167
+ *
168
+ * Router-level predict hooks run per request: each request gets its own PredictContext
169
+ * carrying `decision`; `onPredictStart` may rewrite a request or `ctx.skip()` it, and
170
+ * `onPredictEnd` runs once per started request even when the batch fails.
171
+ * `opts.hooks`, `opts.onPredictStart` and `opts.onPredictEnd` are composed the way `predict`
172
+ * composes them: `setDefaultHooks` defaults, then installed hooks, then this call's hooks.
173
+ * `null` and `[]` add nothing. `hooks`
174
+ * also run `onRoute`. `opts.hooksRaise` overrides the Router's policy for this call, the way
175
+ * `predict` uses `opts.hooksRaise ?? this.hooksRaise`.
176
+ */
177
+ predictBatch(requests: BatchRequest[], batchSize?: number | null, opts?: PredictBatchOptions): Promise<RoutedResult[]>;
178
+ /** Alias of predictBatch, mirroring Python's `Router.predict_many`. */
179
+ predictMany(requests: BatchRequest[], batchSize?: number | null, opts?: PredictBatchOptions): Promise<RoutedResult[]>;
180
+ /**
181
+ * Run onPredictEnd for every started per-request context and raise the first hook
182
+ * failure, if any. Elapsed and usage are stamped on every context before any end hook
183
+ * runs, so one request's end hooks never inflate another request's elapsed time.
184
+ */
185
+ private _endContexts;
186
+ }