@try-works/extension-laya 1.0.0 → 2.0.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.
@@ -0,0 +1,152 @@
1
+ /**
2
+ * DEC-06 — the canonical TYPED decision surfaces over the SAME prepared Laya
3
+ * checkpoint and head as `decision_test` / `decision_score`.
4
+ *
5
+ * This module is pure and model-free: input validation, native-answer → declared
6
+ * payload mapping, and the native probability preservation rules live here so they
7
+ * are testable without weights. The provider in `index.ts` owns only the runtime
8
+ * call and reuses these functions.
9
+ *
10
+ * Honesty rules this module enforces:
11
+ * - `probabilityTrue` / the level probabilities are the runtime's native probability
12
+ * mass, explicitly uncalibrated (`probabilityKind: "model_probability"`); nothing
13
+ * here is calibrated or ground truth.
14
+ * - The score output preserves the native ORDINAL DISTRIBUTION and reports
15
+ * `expectedIndex = Σ i·p_i` unrounded (a fractional expectation is a mean, not a
16
+ * level). It is never converted to an argmax/hard label.
17
+ * - Abstention reports nulls rather than a guessed answer, and only when the native
18
+ * answer is absent or the runtime itself marked it low-confidence. No confidence
19
+ * threshold is invented for abstention.
20
+ * - Truncation/collapse is rejected through the same `assertDecisionInputSafe`
21
+ * (DEC-05) the compatibility tools use.
22
+ */
23
+ import { type DecisionUsageReport } from './pure.js';
24
+ /** Maximum `state` length accepted by the typed surfaces. */
25
+ export declare const TYPED_STATE_MAX = 32768;
26
+ /** Maximum `proposition` / `question` length accepted by the typed surfaces. */
27
+ export declare const TYPED_TEXT_MAX = 4096;
28
+ /** Minimum number of ordinal levels for the typed score surface (DEC-06: 2–32). */
29
+ export declare const TYPED_LEVEL_MIN = 2;
30
+ /** Maximum number of ordinal levels for the typed score surface (DEC-06: 2–32). */
31
+ export declare const TYPED_LEVEL_MAX = 32;
32
+ /** Maximum level id length. */
33
+ export declare const TYPED_LEVEL_ID_MAX = 128;
34
+ /** Maximum level description length. */
35
+ export declare const TYPED_LEVEL_DESCRIPTION_MAX = 256;
36
+ /**
37
+ * Reviewed boolean policy v1 (DEC-06: "Boolean answer thresholds come from the
38
+ * reviewed policy"). P(true) at or above this value maps to `answer: true`; it is a
39
+ * disclosed decision rule over an UNCALIBRATED probability, not a claim of truth.
40
+ */
41
+ export declare const TYPED_BOOLEAN_ANSWER_THRESHOLD = 0.5;
42
+ /** The declared input of `decision_test_typed`. */
43
+ export interface DecisionTestInput {
44
+ readonly state: string;
45
+ readonly proposition: string;
46
+ }
47
+ /** The declared output of `decision_test_typed` (the host adds `meta`). */
48
+ export interface DecisionTestOutput {
49
+ readonly status: 'answered' | 'abstained';
50
+ readonly answer: boolean | null;
51
+ readonly probabilityTrue: number | null;
52
+ readonly probabilityKind: 'model_probability';
53
+ }
54
+ /** One ordered level, least to most intense. */
55
+ export interface TypedLevel {
56
+ readonly id: string;
57
+ readonly description: string;
58
+ }
59
+ /** The declared input of `decision_score_typed`. */
60
+ export interface DecisionScoreInput {
61
+ readonly state: string;
62
+ readonly question: string;
63
+ readonly levels: readonly TypedLevel[];
64
+ }
65
+ /** The declared output of `decision_score_typed` (the host adds `meta`). */
66
+ export interface DecisionScoreOutput {
67
+ readonly status: 'scored' | 'abstained';
68
+ readonly expectedIndex: number | null;
69
+ readonly probabilities: readonly {
70
+ readonly levelId: string;
71
+ readonly probability: number;
72
+ }[];
73
+ readonly probabilityKind: 'model_probability';
74
+ }
75
+ /** The native answer fields the typed mapping consumes (the rest is ignored). */
76
+ export interface TypedNativeAnswer {
77
+ readonly probabilities?: Readonly<Record<string, number>>;
78
+ readonly low_confidence?: boolean;
79
+ }
80
+ /** A typed question as it is sent to the prepared head. */
81
+ export interface TypedQuestionPlan {
82
+ readonly kind: 'test' | 'score';
83
+ readonly questionType: 'choice' | 'score';
84
+ readonly criteria: Record<string, null> | readonly string[];
85
+ readonly prompt: string;
86
+ readonly expectedProbabilities: number;
87
+ }
88
+ /**
89
+ * Validate the typed score input: a bounded state/question and 2–32 ordered levels
90
+ * with UNIQUE IDs and UNIQUE descriptions (a duplicated criterion would make the
91
+ * native criteria indistinguishable, DEC-05).
92
+ * @param input - the untrusted tool arguments.
93
+ * @returns the normalized input.
94
+ */
95
+ export declare function validateDecisionScoreInput(input: unknown): DecisionScoreInput;
96
+ /**
97
+ * Validate the typed test input.
98
+ * @param input - the untrusted tool arguments.
99
+ * @returns the normalized input.
100
+ */
101
+ export declare function validateDecisionTestInput(input: unknown): DecisionTestInput;
102
+ /**
103
+ * Compose the native prompt for the typed boolean question.
104
+ *
105
+ * The state and proposition travel as separate labelled blocks so a proposition
106
+ * that looks like state cannot be silently merged; the runtime's own token budget
107
+ * decides truncation and the usage report is checked afterwards (DEC-05).
108
+ * @param input - the validated test input.
109
+ * @returns the prompt text.
110
+ */
111
+ export declare function decisionTestPrompt(input: DecisionTestInput): string;
112
+ /**
113
+ * Compose the native prompt for the typed ordinal question.
114
+ * @param input - the validated score input.
115
+ * @returns the prompt text.
116
+ */
117
+ export declare function decisionScorePrompt(input: DecisionScoreInput): string;
118
+ /**
119
+ * Plan the native question for a typed implementation id.
120
+ *
121
+ * Returns undefined for every non-typed implementation, so the compatibility tools'
122
+ * branches are not intercepted. The criteria are the SAME prepared head's native
123
+ * question representation: `{true,false}` for the boolean surface and the level
124
+ * descriptions (positional) for the ordinal one.
125
+ * @param implementationId - the manifest implementation id being invoked.
126
+ * @param input - the untrusted tool arguments.
127
+ * @returns the plan, or undefined when this id is not a typed surface.
128
+ */
129
+ export declare function typedQuestionPlan(implementationId: string, input: unknown): TypedQuestionPlan | undefined;
130
+ /**
131
+ * Map the native boolean answer onto the declared typed-test payload.
132
+ *
133
+ * `probabilityTrue` is the native P(true) mass, uncalibrated. `answer` applies the
134
+ * disclosed reviewed policy threshold; an abstention (no native answer or the
135
+ * runtime's own low-confidence marker) reports nulls instead of a guess.
136
+ * @param input - the validated test input.
137
+ * @param answer - the native answer (absent when the model produced none).
138
+ * @param usage - the runtime's truncation/collapse report (DEC-05).
139
+ * @returns the declared payload.
140
+ */
141
+ export declare function typedTestFromNative(input: DecisionTestInput, answer: TypedNativeAnswer | undefined, usage?: DecisionUsageReport): DecisionTestOutput;
142
+ /**
143
+ * Map the native ordinal answer onto the declared typed-score payload.
144
+ *
145
+ * The distribution is preserved in level order and `expectedIndex` is the native
146
+ * probability-weighted index, unrounded. No argmax/hard label is produced.
147
+ * @param input - the validated score input.
148
+ * @param answer - the native answer (absent when the model produced none).
149
+ * @param usage - the runtime's truncation/collapse report (DEC-05).
150
+ * @returns the declared payload.
151
+ */
152
+ export declare function typedScoreFromNative(input: DecisionScoreInput, answer: TypedNativeAnswer | undefined, usage?: DecisionUsageReport): DecisionScoreOutput;
@@ -0,0 +1,244 @@
1
+ /**
2
+ * DEC-06 — the canonical TYPED decision surfaces over the SAME prepared Laya
3
+ * checkpoint and head as `decision_test` / `decision_score`.
4
+ *
5
+ * This module is pure and model-free: input validation, native-answer → declared
6
+ * payload mapping, and the native probability preservation rules live here so they
7
+ * are testable without weights. The provider in `index.ts` owns only the runtime
8
+ * call and reuses these functions.
9
+ *
10
+ * Honesty rules this module enforces:
11
+ * - `probabilityTrue` / the level probabilities are the runtime's native probability
12
+ * mass, explicitly uncalibrated (`probabilityKind: "model_probability"`); nothing
13
+ * here is calibrated or ground truth.
14
+ * - The score output preserves the native ORDINAL DISTRIBUTION and reports
15
+ * `expectedIndex = Σ i·p_i` unrounded (a fractional expectation is a mean, not a
16
+ * level). It is never converted to an argmax/hard label.
17
+ * - Abstention reports nulls rather than a guessed answer, and only when the native
18
+ * answer is absent or the runtime itself marked it low-confidence. No confidence
19
+ * threshold is invented for abstention.
20
+ * - Truncation/collapse is rejected through the same `assertDecisionInputSafe`
21
+ * (DEC-05) the compatibility tools use.
22
+ */
23
+ import { assertDecisionInputSafe, validateProbabilityDistribution, } from './pure.js';
24
+ /** Maximum `state` length accepted by the typed surfaces. */
25
+ export const TYPED_STATE_MAX = 32768;
26
+ /** Maximum `proposition` / `question` length accepted by the typed surfaces. */
27
+ export const TYPED_TEXT_MAX = 4096;
28
+ /** Minimum number of ordinal levels for the typed score surface (DEC-06: 2–32). */
29
+ export const TYPED_LEVEL_MIN = 2;
30
+ /** Maximum number of ordinal levels for the typed score surface (DEC-06: 2–32). */
31
+ export const TYPED_LEVEL_MAX = 32;
32
+ /** Maximum level id length. */
33
+ export const TYPED_LEVEL_ID_MAX = 128;
34
+ /** Maximum level description length. */
35
+ export const TYPED_LEVEL_DESCRIPTION_MAX = 256;
36
+ /**
37
+ * Reviewed boolean policy v1 (DEC-06: "Boolean answer thresholds come from the
38
+ * reviewed policy"). P(true) at or above this value maps to `answer: true`; it is a
39
+ * disclosed decision rule over an UNCALIBRATED probability, not a claim of truth.
40
+ */
41
+ export const TYPED_BOOLEAN_ANSWER_THRESHOLD = 0.5;
42
+ function record(value, label, allowed) {
43
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
44
+ throw new Error(`${label} must be an object`);
45
+ }
46
+ const result = value;
47
+ const unknown = Object.keys(result).find(key => !allowed.includes(key));
48
+ if (unknown !== undefined) {
49
+ throw new Error(`unknown field ${JSON.stringify(unknown)}; the typed schema is closed`);
50
+ }
51
+ return result;
52
+ }
53
+ function requireString(value, field, max) {
54
+ if (typeof value !== 'string' || value.length === 0) {
55
+ throw new Error(`"${field}" must be a non-empty string`);
56
+ }
57
+ if (value.length > max)
58
+ throw new Error(`"${field}" must be at most ${max} characters, got ${value.length}`);
59
+ return value;
60
+ }
61
+ function requireState(value) {
62
+ return requireString(value, 'state', TYPED_STATE_MAX);
63
+ }
64
+ /** Validate and normalize one ordinal level entry. */
65
+ function validateLevel(value, index) {
66
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
67
+ throw new Error(`levels[${index}] must be an object`);
68
+ }
69
+ const candidate = value;
70
+ const unknown = Object.keys(candidate).filter(key => key !== 'id' && key !== 'description');
71
+ if (unknown.length > 0) {
72
+ throw new Error(`levels[${index}] has unknown field ${JSON.stringify(unknown[0])}; the level entry is closed`);
73
+ }
74
+ const id = candidate['id'];
75
+ const description = candidate['description'];
76
+ if (typeof id !== 'string' || id.length === 0)
77
+ throw new Error(`levels[${index}] id must be a non-empty string`);
78
+ if (id.length > TYPED_LEVEL_ID_MAX) {
79
+ throw new Error(`levels[${index}] id must be at most ${TYPED_LEVEL_ID_MAX} characters`);
80
+ }
81
+ if (typeof description !== 'string' || description.length === 0) {
82
+ throw new Error(`levels[${index}] description must be a non-empty string`);
83
+ }
84
+ if (description.length > TYPED_LEVEL_DESCRIPTION_MAX) {
85
+ throw new Error(`levels[${index}] description must be at most ${TYPED_LEVEL_DESCRIPTION_MAX} characters`);
86
+ }
87
+ return { id, description };
88
+ }
89
+ /**
90
+ * Validate the typed score input: a bounded state/question and 2–32 ordered levels
91
+ * with UNIQUE IDs and UNIQUE descriptions (a duplicated criterion would make the
92
+ * native criteria indistinguishable, DEC-05).
93
+ * @param input - the untrusted tool arguments.
94
+ * @returns the normalized input.
95
+ */
96
+ export function validateDecisionScoreInput(input) {
97
+ const candidate = record(input, 'decision_score_typed input', ['state', 'question', 'levels']);
98
+ const state = requireState(candidate['state']);
99
+ const question = requireString(candidate['question'], 'question', TYPED_TEXT_MAX);
100
+ const rawLevels = candidate['levels'];
101
+ if (!Array.isArray(rawLevels))
102
+ throw new Error('"levels" must be an array of {id, description}');
103
+ if (rawLevels.length < TYPED_LEVEL_MIN || rawLevels.length > TYPED_LEVEL_MAX) {
104
+ throw new Error(`"levels" must contain ${TYPED_LEVEL_MIN}..${TYPED_LEVEL_MAX} entries, got ${rawLevels.length}`);
105
+ }
106
+ const levels = rawLevels.map((level, index) => validateLevel(level, index));
107
+ const ids = new Set();
108
+ const descriptions = new Set();
109
+ for (const level of levels) {
110
+ if (ids.has(level.id))
111
+ throw new Error(`levels must have a unique id per entry; duplicate ${JSON.stringify(level.id)}`);
112
+ if (descriptions.has(level.description)) {
113
+ throw new Error(`levels must have a unique description per entry; duplicate ${JSON.stringify(level.description)}`);
114
+ }
115
+ ids.add(level.id);
116
+ descriptions.add(level.description);
117
+ }
118
+ return { state, question, levels };
119
+ }
120
+ /**
121
+ * Validate the typed test input.
122
+ * @param input - the untrusted tool arguments.
123
+ * @returns the normalized input.
124
+ */
125
+ export function validateDecisionTestInput(input) {
126
+ const candidate = record(input, 'decision_test_typed input', ['state', 'proposition']);
127
+ const state = requireState(candidate['state']);
128
+ const proposition = requireString(candidate['proposition'], 'proposition', TYPED_TEXT_MAX);
129
+ return { state, proposition };
130
+ }
131
+ /**
132
+ * Compose the native prompt for the typed boolean question.
133
+ *
134
+ * The state and proposition travel as separate labelled blocks so a proposition
135
+ * that looks like state cannot be silently merged; the runtime's own token budget
136
+ * decides truncation and the usage report is checked afterwards (DEC-05).
137
+ * @param input - the validated test input.
138
+ * @returns the prompt text.
139
+ */
140
+ export function decisionTestPrompt(input) {
141
+ return `State:\n${input.state}\n\nProposition:\n${input.proposition}`;
142
+ }
143
+ /**
144
+ * Compose the native prompt for the typed ordinal question.
145
+ * @param input - the validated score input.
146
+ * @returns the prompt text.
147
+ */
148
+ export function decisionScorePrompt(input) {
149
+ return `State:\n${input.state}\n\nQuestion:\n${input.question}`;
150
+ }
151
+ /**
152
+ * Plan the native question for a typed implementation id.
153
+ *
154
+ * Returns undefined for every non-typed implementation, so the compatibility tools'
155
+ * branches are not intercepted. The criteria are the SAME prepared head's native
156
+ * question representation: `{true,false}` for the boolean surface and the level
157
+ * descriptions (positional) for the ordinal one.
158
+ * @param implementationId - the manifest implementation id being invoked.
159
+ * @param input - the untrusted tool arguments.
160
+ * @returns the plan, or undefined when this id is not a typed surface.
161
+ */
162
+ export function typedQuestionPlan(implementationId, input) {
163
+ if (implementationId === 'laya-onnx-decision-test-typed') {
164
+ const validated = validateDecisionTestInput(input);
165
+ return {
166
+ kind: 'test',
167
+ questionType: 'choice',
168
+ criteria: { true: null, false: null },
169
+ prompt: decisionTestPrompt(validated),
170
+ expectedProbabilities: 2,
171
+ };
172
+ }
173
+ if (implementationId === 'laya-onnx-decision-score-typed') {
174
+ const validated = validateDecisionScoreInput(input);
175
+ return {
176
+ kind: 'score',
177
+ questionType: 'score',
178
+ criteria: validated.levels.map(level => level.description),
179
+ prompt: decisionScorePrompt(validated),
180
+ expectedProbabilities: validated.levels.length,
181
+ };
182
+ }
183
+ return undefined;
184
+ }
185
+ /** Whether the native answer means "the model declined", without inventing a threshold. */
186
+ function abstained(answer) {
187
+ return answer === undefined || answer.low_confidence === true;
188
+ }
189
+ /**
190
+ * Map the native boolean answer onto the declared typed-test payload.
191
+ *
192
+ * `probabilityTrue` is the native P(true) mass, uncalibrated. `answer` applies the
193
+ * disclosed reviewed policy threshold; an abstention (no native answer or the
194
+ * runtime's own low-confidence marker) reports nulls instead of a guess.
195
+ * @param input - the validated test input.
196
+ * @param answer - the native answer (absent when the model produced none).
197
+ * @param usage - the runtime's truncation/collapse report (DEC-05).
198
+ * @returns the declared payload.
199
+ */
200
+ export function typedTestFromNative(input, answer, usage) {
201
+ void input;
202
+ assertDecisionInputSafe(usage);
203
+ if (abstained(answer)) {
204
+ return { status: 'abstained', answer: null, probabilityTrue: null, probabilityKind: 'model_probability' };
205
+ }
206
+ const probabilities = validateProbabilityDistribution(answer.probabilities ?? {}, 2);
207
+ const probabilityTrue = probabilities['true'];
208
+ if (typeof probabilityTrue !== 'number') {
209
+ throw new Error('the native answer has no "true" probability; refusing to fabricate probabilityTrue');
210
+ }
211
+ return {
212
+ status: 'answered',
213
+ answer: probabilityTrue >= TYPED_BOOLEAN_ANSWER_THRESHOLD,
214
+ probabilityTrue,
215
+ probabilityKind: 'model_probability',
216
+ };
217
+ }
218
+ /**
219
+ * Map the native ordinal answer onto the declared typed-score payload.
220
+ *
221
+ * The distribution is preserved in level order and `expectedIndex` is the native
222
+ * probability-weighted index, unrounded. No argmax/hard label is produced.
223
+ * @param input - the validated score input.
224
+ * @param answer - the native answer (absent when the model produced none).
225
+ * @param usage - the runtime's truncation/collapse report (DEC-05).
226
+ * @returns the declared payload.
227
+ */
228
+ export function typedScoreFromNative(input, answer, usage) {
229
+ assertDecisionInputSafe(usage);
230
+ if (abstained(answer)) {
231
+ return { status: 'abstained', expectedIndex: null, probabilities: [], probabilityKind: 'model_probability' };
232
+ }
233
+ const probabilities = validateProbabilityDistribution(answer.probabilities ?? {}, input.levels.length);
234
+ const ordered = input.levels.map((level, index) => {
235
+ const probability = probabilities[String(index)];
236
+ if (typeof probability !== 'number') {
237
+ throw new Error(`the native score distribution has no probability for level index ${index}; refusing to fabricate one`);
238
+ }
239
+ return { levelId: level.id, probability };
240
+ });
241
+ const expectedIndex = ordered.reduce((sum, entry, index) => sum + index * entry.probability, 0);
242
+ return { status: 'scored', expectedIndex, probabilities: ordered, probabilityKind: 'model_probability' };
243
+ }
244
+ //# sourceMappingURL=typed-decision.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typed-decision.js","sourceRoot":"","sources":["../src/typed-decision.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EACL,uBAAuB,EACvB,+BAA+B,GAEhC,MAAM,WAAW,CAAA;AAElB,6DAA6D;AAC7D,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,CAAA;AACpC,gFAAgF;AAChF,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAA;AAClC,mFAAmF;AACnF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAA;AAChC,mFAAmF;AACnF,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,CAAA;AACjC,+BAA+B;AAC/B,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,CAAA;AACrC,wCAAwC;AACxC,MAAM,CAAC,MAAM,2BAA2B,GAAG,GAAG,CAAA;AAC9C;;;;GAIG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,GAAG,CAAA;AAoDjD,SAAS,MAAM,CAAC,KAAc,EAAE,KAAa,EAAE,OAA0B;IACvE,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAA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@@ -36,23 +36,12 @@
36
36
  {
37
37
  "id": "text-backbone",
38
38
  "enables": ["text"],
39
+ "note": "ONE directory holds all six artifacts. The extension's load() resolves this single group and hands its path to the vendored laya-ts Node provider, which opens encoder.onnx, encoder.onnx.data, head.onnx, head.onnx.data, tokenizer.json and rl_agent_config.json FROM THAT DIRECTORY (createNodeProvider's documented layout). The earlier three-group split (text-backbone / decision-head / tokenizer-config) produced directories the runtime could never load: the first real decision_choose call failed with 'head.onnx not found in .../text-backbone'.",
39
40
  "assets": [
40
41
  { "id": "laya-encoder-onnx", "file": "encoder.onnx", "bytes": 2451566, "source": "the split export of the pinned checkpoint", "digest": "A774C5C634B99D1A4CED21ACBF11B9617A5CD55C7C7957BD52480B17D95A97F4", "executable": false },
41
- { "id": "laya-encoder-onnx-data", "file": "encoder.onnx.data", "bytes": 1227816960, "source": "the split export of the pinned checkpoint", "digest": "F1E49A027352064D72831863456BE6160748854296BFF8332DF14130DBF79834", "executable": false }
42
- ]
43
- },
44
- {
45
- "id": "decision-head",
46
- "enables": ["text"],
47
- "assets": [
42
+ { "id": "laya-encoder-onnx-data", "file": "encoder.onnx.data", "bytes": 1227816960, "source": "the split export of the pinned checkpoint", "digest": "F1E49A027352064D72831863456BE6160748854296BFF8332DF14130DBF79834", "executable": false },
48
43
  { "id": "laya-head-onnx", "file": "head.onnx", "bytes": 245312, "source": "the split export of the pinned checkpoint", "digest": "7F6B9AC15D5FDF9EEBB352E66BDD3CE799D32885F1446014D268D8C53207858B", "executable": false },
49
- { "id": "laya-head-onnx-data", "file": "head.onnx.data", "bytes": 59899904, "source": "the split export of the pinned checkpoint", "digest": "0292A4EB478C2C3EC0B6555B4A4093BC802E965654D7AEB4AC22907A17F261D3", "executable": false }
50
- ]
51
- },
52
- {
53
- "id": "tokenizer-config",
54
- "enables": ["text"],
55
- "assets": [
44
+ { "id": "laya-head-onnx-data", "file": "head.onnx.data", "bytes": 59899904, "source": "the split export of the pinned checkpoint", "digest": "0292A4EB478C2C3EC0B6555B4A4093BC802E965654D7AEB4AC22907A17F261D3", "executable": false },
56
45
  { "id": "laya-tokenizer", "file": "tokenizer.json", "bytes": 34363188, "source": "the split export of the pinned checkpoint", "digest": "609D8F4C067CD3950F88594C5A802616CEA245823836EF5848EE4FC40AAB5B6F", "executable": false },
57
46
  { "id": "laya-rl-agent-config", "file": "rl_agent_config.json", "bytes": 472, "source": "the split export of the pinned checkpoint", "digest": "25061739243B617AD88D1219BA6F8A9C86C5881CA28DF024FA2D9B3B2FCC30C6", "executable": false }
58
47
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@try-works/extension-laya",
3
- "version": "1.0.0",
3
+ "version": "2.0.0",
4
4
  "type": "module",
5
5
  "description": "Tool Mode extension implementing the Laya decision family (decision_choose / decision_test / decision_score) on the pinned multilingual Laya checkpoint, with the vendored laya-ts runtime.",
6
6
  "license": "Apache-2.0",
@@ -11,10 +11,13 @@
11
11
  "files": [
12
12
  "tool-mode.extension.json",
13
13
  "lib",
14
+ "!lib/evaluation.*",
14
15
  "models.lock.json",
15
16
  "schema",
17
+ "config",
16
18
  "vendor",
17
- "README.md"
19
+ "README.md",
20
+ "skills"
18
21
  ],
19
22
  "toolMode": {
20
23
  "manifest": "./tool-mode.extension.json"
@@ -0,0 +1,63 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "type": "object",
4
+ "additionalProperties": false,
5
+ "description": "R21 decision_batch input: ONE call carries up to 100 bounded judgments. No caller-supplied threshold is accepted; abstention uses only the reviewed config.",
6
+ "required": [
7
+ "kind",
8
+ "items"
9
+ ],
10
+ "properties": {
11
+ "kind": {
12
+ "type": "string",
13
+ "enum": [
14
+ "test",
15
+ "choose",
16
+ "score"
17
+ ]
18
+ },
19
+ "items": {
20
+ "type": "array",
21
+ "minItems": 1,
22
+ "maxItems": 100,
23
+ "items": {
24
+ "type": "object",
25
+ "additionalProperties": false,
26
+ "required": [
27
+ "prompt"
28
+ ],
29
+ "properties": {
30
+ "id": {
31
+ "type": "string",
32
+ "description": "Opaque caller id, echoed in the matching row."
33
+ },
34
+ "prompt": {
35
+ "type": "string",
36
+ "minLength": 1,
37
+ "maxLength": 4096
38
+ },
39
+ "options": {
40
+ "type": "array",
41
+ "minItems": 2,
42
+ "maxItems": 32,
43
+ "items": {
44
+ "type": "string",
45
+ "minLength": 1
46
+ },
47
+ "description": "choose only: 2-32 distinct options."
48
+ },
49
+ "levels": {
50
+ "type": "array",
51
+ "minItems": 2,
52
+ "maxItems": 10,
53
+ "items": {
54
+ "type": "string",
55
+ "minLength": 1
56
+ },
57
+ "description": "score only: 2-10 ordered level labels."
58
+ }
59
+ }
60
+ }
61
+ }
62
+ }
63
+ }
@@ -0,0 +1,116 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "type": "object",
4
+ "additionalProperties": false,
5
+ "description": "R21 decision_batch output: rows in input order; atomic (a failing item yields a named error and no rows).",
6
+ "required": [
7
+ "rows",
8
+ "probabilityKind",
9
+ "threshold"
10
+ ],
11
+ "properties": {
12
+ "rows": {
13
+ "type": "array",
14
+ "items": {
15
+ "type": "object",
16
+ "additionalProperties": false,
17
+ "required": [
18
+ "id",
19
+ "scope",
20
+ "abstained",
21
+ "margin",
22
+ "reliability",
23
+ "probabilityKind",
24
+ "marginThreshold",
25
+ "abstainMargin"
26
+ ],
27
+ "properties": {
28
+ "id": {
29
+ "type": [
30
+ "string",
31
+ "null"
32
+ ]
33
+ },
34
+ "decision": {
35
+ "type": [
36
+ "string",
37
+ "null"
38
+ ],
39
+ "enum": [
40
+ "yes",
41
+ "no",
42
+ null
43
+ ]
44
+ },
45
+ "chosen": {
46
+ "type": [
47
+ "string",
48
+ "null"
49
+ ]
50
+ },
51
+ "score": {
52
+ "type": [
53
+ "string",
54
+ "null"
55
+ ]
56
+ },
57
+ "scope": {
58
+ "type": "string",
59
+ "enum": [
60
+ "in-scope",
61
+ "out-of-scope"
62
+ ]
63
+ },
64
+ "abstained": {
65
+ "type": "boolean"
66
+ },
67
+ "margin": {
68
+ "type": "number",
69
+ "minimum": 0,
70
+ "maximum": 1
71
+ },
72
+ "reliability": {
73
+ "type": [
74
+ "string",
75
+ "null"
76
+ ],
77
+ "enum": [
78
+ "confident",
79
+ "tentative",
80
+ null
81
+ ]
82
+ },
83
+ "probabilityKind": {
84
+ "const": "model_probability"
85
+ },
86
+ "marginThreshold": {
87
+ "type": [
88
+ "number",
89
+ "null"
90
+ ],
91
+ "minimum": 0,
92
+ "maximum": 1
93
+ },
94
+ "abstainMargin": {
95
+ "type": [
96
+ "number",
97
+ "null"
98
+ ],
99
+ "minimum": 0,
100
+ "maximum": 1
101
+ }
102
+ }
103
+ }
104
+ },
105
+ "probabilityKind": {
106
+ "const": "model_probability"
107
+ },
108
+ "threshold": {
109
+ "type": [
110
+ "number",
111
+ "null"
112
+ ],
113
+ "description": "The reviewed abstainMargin used, or null when the gate is BLOCKED; never a caller value."
114
+ }
115
+ }
116
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "type": "object",
4
+ "additionalProperties": false,
5
+ "required": ["decision", "options"],
6
+ "properties": {
7
+ "decision": { "type": "string", "minLength": 1, "maxLength": 4096, "description": "The decision to make." },
8
+ "options": {
9
+ "type": "array",
10
+ "minItems": 2,
11
+ "maxItems": 16,
12
+ "items": { "type": "string", "minLength": 1, "maxLength": 400 },
13
+ "description": "The mutually exclusive options; the answer is an index into this list."
14
+ }
15
+ }
16
+ }