@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.
package/lib/pure.js CHANGED
@@ -24,6 +24,201 @@ export function answerConfidence(p) {
24
24
  return 1;
25
25
  return Math.min(1, Math.max(0, Math.max(...p)));
26
26
  }
27
+ /** R18/DEC-06: the only probability kind the LOCAL decision payloads advertise. */
28
+ export const LOCAL_DECISION_PROBABILITY_KIND = 'model_probability';
29
+ /** R18 default scope; R20's detector replaces it with a computed boundary. */
30
+ export const LOCAL_DECISION_SCOPE = 'in-scope';
31
+ /**
32
+ * Reliability for one margin (R22): a margin at or above the reviewed trustMargin is
33
+ * 'confident'; strictly below is 'tentative'. No default threshold is invented.
34
+ * @param margin - the top-two probability gap.
35
+ * @param trustMargin - the REVIEWED trustMargin in [0,1].
36
+ * @returns the per-item reliability.
37
+ */
38
+ export function reliabilityOf(margin, trustMargin) {
39
+ if (!Number.isFinite(trustMargin) || trustMargin < 0 || trustMargin > 1) {
40
+ throw new Error('trustMargin must be a finite number in [0,1]; no default is invented');
41
+ }
42
+ return margin >= trustMargin ? 'confident' : 'tentative';
43
+ }
44
+ /**
45
+ * The top-two probability gap (margin). The two highest finite probabilities are
46
+ * compared; fewer than two values has no gap and reports 0.
47
+ * @param probabilities - label/index → probability.
48
+ * @returns the non-negative gap between the best and second-best probability.
49
+ */
50
+ export function topTwoMargin(probabilities) {
51
+ const values = Object.values(probabilities)
52
+ .filter(value => Number.isFinite(value))
53
+ .sort((left, right) => right - left);
54
+ if (values.length < 2)
55
+ return 0;
56
+ return Math.max(0, (values[0] ?? 0) - (values[1] ?? 0));
57
+ }
58
+ /**
59
+ * Build the v2 local decision payload (R18).
60
+ *
61
+ * Fields are the contract: the mapped answer, raw probabilities, the pinned
62
+ * `model_probability` kind, the top-two margin, the scope and `abstained`. NO
63
+ * confidence/calibrated/answer_confidence field is emitted.
64
+ * @param input - kind, answer label, probabilities, abstention and optional scope.
65
+ * @returns the schema-shaped payload (before the optional act-gate field).
66
+ */
67
+ export function buildLocalDecisionPayload(input) {
68
+ const scope = input.scope ?? LOCAL_DECISION_SCOPE;
69
+ // R20: an out-of-scope judgment is REFUSED, not answered. Withholding the label and
70
+ // marking abstention is the honest output (DEC-04: no field beats a mislabelled one).
71
+ const outOfScope = scope === 'out-of-scope';
72
+ // R22: a null answer IS an abstention. Treat it exactly like a withheld answer so the
73
+ // payload can never say abstained:false with no answer, or claim reliability for it.
74
+ const withheld = outOfScope || input.answer === null || input.abstained;
75
+ const answer = withheld ? null : input.answer;
76
+ const margin = topTwoMargin(input.probabilities);
77
+ const trustMargin = input.trustMargin;
78
+ const hasTrustMargin = trustMargin !== undefined;
79
+ const base = {
80
+ probabilities: input.probabilities,
81
+ probabilityKind: LOCAL_DECISION_PROBABILITY_KIND,
82
+ margin,
83
+ scope,
84
+ abstained: withheld,
85
+ // R19: the reviewed abstain margin is echoed when a reviewed gate exists; null while
86
+ // the committed config is still PROPOSED (BLOCKED). Never a default.
87
+ abstainMargin: input.abstainMargin ?? null,
88
+ // R22: reliability is claimed ONLY from a reviewed trustMargin and never on an abstention.
89
+ marginThreshold: hasTrustMargin ? trustMargin : null,
90
+ reliability: withheld || !hasTrustMargin ? null : reliabilityOf(margin, trustMargin),
91
+ };
92
+ if (input.kind === 'test')
93
+ return { ...base, decision: answer };
94
+ if (input.kind === 'choose')
95
+ return { ...base, chosen: answer };
96
+ return { ...base, score: answer };
97
+ }
98
+ /**
99
+ * Apply the reviewed abstain margin to a probability map (R19).
100
+ * A margin STRICTLY below the threshold abstains; equal or above answers.
101
+ * @param probabilities - label/index → probability.
102
+ * @param threshold - the REVIEWED abstainMargin in [0,1]; never a default.
103
+ * @returns the decision plus the observed margin and the threshold used.
104
+ */
105
+ export function marginGate(probabilities, threshold) {
106
+ if (!Number.isFinite(threshold) || threshold < 0 || threshold > 1) {
107
+ throw new Error('abstainMargin must be a finite number in [0,1]; no default is invented');
108
+ }
109
+ const margin = topTwoMargin(probabilities);
110
+ return { abstain: margin < threshold, margin, threshold };
111
+ }
112
+ /**
113
+ * Withhold a local decision payload whose margin is below the reviewed threshold (R19).
114
+ * The probabilities, margin, scope and probabilityKind are preserved; the answer becomes
115
+ * null and abstained becomes true. A clearing margin returns the payload unchanged.
116
+ * @param payload - the v2 local payload.
117
+ * @param threshold - the reviewed abstainMargin.
118
+ * @returns the gated payload.
119
+ */
120
+ export function applyMarginGate(payload, threshold) {
121
+ const gate = marginGate(payload.probabilities, threshold);
122
+ if (!gate.abstain)
123
+ return { ...payload, abstainMargin: threshold };
124
+ const withheld = { ...payload, abstained: true, reliability: null, abstainMargin: threshold };
125
+ if (payload.decision !== undefined)
126
+ return { ...withheld, decision: null };
127
+ if (payload.chosen !== undefined)
128
+ return { ...withheld, chosen: null };
129
+ if (payload.score !== undefined)
130
+ return { ...withheld, score: null };
131
+ return withheld;
132
+ }
133
+ /**
134
+ * Replay the gate over CORRECT labelled rows and fail when it loses more than the reviewed
135
+ * coverage budget (R19). This is a replay check, not a new measurement.
136
+ * @param rows - correct-labelled rows with their probabilities.
137
+ * @param threshold - the reviewed abstainMargin.
138
+ * @param budget - the reviewed coverageBudget (non-negative integer).
139
+ * @returns ok with the lost count, or a named coverage failure.
140
+ */
141
+ export function coverageBudgetFailure(rows, threshold, budget) {
142
+ if (!Number.isInteger(budget) || budget < 0) {
143
+ throw new Error('coverageBudget must be a non-negative integer; no default is invented');
144
+ }
145
+ const lostCorrect = rows.filter(row => row.correct && marginGate(row.probabilities, threshold).abstain).length;
146
+ if (lostCorrect > budget) {
147
+ return {
148
+ ok: false,
149
+ code: 'COVERAGE_BUDGET_EXCEEDED',
150
+ lostCorrect,
151
+ budget,
152
+ message: 'abstaining at ' + String(threshold) + ' would lose ' + String(lostCorrect)
153
+ + ' correct rows, over the reviewed coverageBudget of ' + String(budget),
154
+ };
155
+ }
156
+ return { ok: true, lostCorrect, budget };
157
+ }
158
+ /** Whether a fixture document carries the operator's review provenance. */
159
+ function reviewedForReplay(document) {
160
+ const reviewedAt = document.reviewedAt;
161
+ return document.reviewStatus === 'reviewed'
162
+ && reviewedAt !== undefined
163
+ && Number.isFinite(Date.parse(reviewedAt))
164
+ && document.blind === true
165
+ && typeof document.reviewer === 'string'
166
+ && document.reviewer.trim().length > 0;
167
+ }
168
+ /**
169
+ * Replay the R22 held-out containment/tolerance rule (R22), or return BLOCKED with a named
170
+ * reason. The committed fixtures are draft-unreviewed, so this returns BLOCKED today and
171
+ * claims no pass. A dev-fitted reviewed trustMargin is supplied by the caller, never refit
172
+ * here.
173
+ * @param dev - the development fixture document (must be reviewed, used for provenance only).
174
+ * @param heldout - the held-out fixture document (acceptance only).
175
+ * @param trustMargin - the REVIEWED trust margin fitted on dev.
176
+ * @param tolerance - the pre-registered maximum fraction of trust rows allowed in tentative.
177
+ * @returns REPLAYED results or a named BLOCKED reason.
178
+ */
179
+ export function evaluateR22Replay(dev, heldout, trustMargin, tolerance) {
180
+ reliabilityOf(0, trustMargin); // validates trustMargin; no default is invented
181
+ if (!Number.isFinite(tolerance) || tolerance < 0 || tolerance > 1) {
182
+ throw new Error('tolerance must be a finite fraction in [0,1]');
183
+ }
184
+ if (!reviewedForReplay(dev) || !reviewedForReplay(heldout)) {
185
+ return {
186
+ status: 'BLOCKED',
187
+ code: 'R22_FIXTURES_NOT_REVIEWED',
188
+ reason: 'the R22 fixtures are not operator-reviewed (dev: ' + String(dev.reviewStatus)
189
+ + ', held-out: ' + String(heldout.reviewStatus)
190
+ + '); a non-empty reviewedAt is required and draft-unreviewed never replays',
191
+ };
192
+ }
193
+ const rows = heldout.rows ?? [];
194
+ if (rows.length === 0 || rows.some(row => row.probabilities === undefined || row.label === undefined)) {
195
+ return {
196
+ status: 'BLOCKED',
197
+ code: 'R22_NO_CAPTURED_VECTORS',
198
+ reason: 'the reviewed R22 held-out rows have no captured probabilities/labels; '
199
+ + 'a replay cannot invent margins or labels',
200
+ };
201
+ }
202
+ const evaluated = rows.map(row => ({
203
+ label: row.label,
204
+ reliability: reliabilityOf(topTwoMargin(row.probabilities ?? {}), trustMargin),
205
+ }));
206
+ const mustRecheck = evaluated.filter(row => row.label === 'must-recheck');
207
+ const trust = evaluated.filter(row => row.label === 'trust');
208
+ const tentativeContainsMustRecheck = mustRecheck.every(row => row.reliability === 'tentative');
209
+ const tentativeTrustRows = trust.filter(row => row.reliability === 'tentative').length;
210
+ const allowedTrustInTentative = Math.ceil(trust.length * tolerance);
211
+ return {
212
+ status: 'REPLAYED',
213
+ tentativeContainsMustRecheck,
214
+ toleranceExceeded: !tentativeContainsMustRecheck || tentativeTrustRows > allowedTrustInTentative,
215
+ mustRecheckRows: mustRecheck.length,
216
+ trustRows: trust.length,
217
+ tentativeTrustRows,
218
+ allowedTrustInTentative,
219
+ confidentRows: trust.length - tentativeTrustRows,
220
+ };
221
+ }
27
222
  /**
28
223
  * Map logits to a boundary decision: softmax, argmax, and ties broken by the
29
224
  * INPUT order of the labels (deterministic; the vendored runtime's stable
@@ -68,4 +263,243 @@ export function validateOptions(options, max) {
68
263
  }
69
264
  return [...options];
70
265
  }
266
+ /** A refused decision input, carrying the code the caller/UI must surface (DEC-05). */
267
+ export class DecisionInputError extends Error {
268
+ name = 'DecisionInputError';
269
+ /** The stable rejection code. */
270
+ code;
271
+ constructor(code, message) {
272
+ super(message);
273
+ this.code = code;
274
+ }
275
+ }
276
+ /**
277
+ * Reject a decision whose input the model did not fully receive (DEC-05).
278
+ *
279
+ * The native runtime reports both dropped state tokens (`truncated`, a token-budget
280
+ * fact) and options that collapsed to the same head representation (`options`).
281
+ * Returning a confident answer over either would hide the loss.
282
+ * @param usage - the runtime's usage report.
283
+ * @throws DecisionInputError with `INPUT_TRUNCATED` or `INDISTINGUISHABLE_OPTIONS`.
284
+ */
285
+ export function assertDecisionInputSafe(usage) {
286
+ if (usage === undefined)
287
+ return;
288
+ const dropped = Number(usage.state_tokens_dropped ?? 0);
289
+ if (usage.truncated === true || (Number.isFinite(dropped) && dropped > 0)) {
290
+ const questions = usage.truncated_questions?.length ? ` (questions: ${usage.truncated_questions.join(', ')})` : '';
291
+ throw new DecisionInputError('INPUT_TRUNCATED', `the decision input exceeded the prepared checkpoint's token budget and dropped ${dropped} state token(s)${questions}; `
292
+ + 'rejecting rather than returning a confident decision over input the model did not receive (DEC-05)');
293
+ }
294
+ if (usage.options !== undefined && Object.keys(usage.options).length > 0) {
295
+ throw new DecisionInputError('INDISTINGUISHABLE_OPTIONS', 'distinct options collapsed to the same model representation; rejecting the request rather than returning a decision '
296
+ + 'that cannot distinguish them (DEC-05)');
297
+ }
298
+ }
299
+ /**
300
+ * Validate a probability distribution the runtime reported (DEC-04).
301
+ *
302
+ * The native API returns probabilities as an object; a malformed vector is not a
303
+ * weaker answer, it is an answer the extension must not report as probabilities.
304
+ * Length must match the declared options/levels, every value must be finite and in
305
+ * [0,1], and the total must be 1 within a small floating-point tolerance.
306
+ * @param probabilities - the runtime's index/label → probability map.
307
+ * @param expectedEntries - how many options/levels the answer covers.
308
+ * @returns the same map, when valid.
309
+ * @throws Error naming the violated property.
310
+ */
311
+ export function validateProbabilityDistribution(probabilities, expectedEntries) {
312
+ const entries = Object.entries(probabilities);
313
+ if (entries.length !== expectedEntries) {
314
+ throw new Error(`probability vector must have ${expectedEntries} entries, got ${entries.length}`);
315
+ }
316
+ let sum = 0;
317
+ for (const [key, value] of entries) {
318
+ if (typeof value !== 'number' || !Number.isFinite(value)) {
319
+ throw new Error(`probability for ${JSON.stringify(key)} must be finite`);
320
+ }
321
+ if (value < 0 || value > 1) {
322
+ throw new Error(`probability for ${JSON.stringify(key)} must be between 0 and 1`);
323
+ }
324
+ sum += value;
325
+ }
326
+ if (Math.abs(sum - 1) > 1e-3) {
327
+ throw new Error(`probabilities must sum to 1 within 1e-3, got ${sum}`);
328
+ }
329
+ return probabilities;
330
+ }
331
+ /** Object keys that cannot safely be used as native choice criteria keys (DEC-03). */
332
+ const UNSAFE_PROVIDER_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
333
+ /**
334
+ * Build a stable reversible provider-key mapping for choice options (DEC-03).
335
+ *
336
+ * The native API uses each criterion key as both the option text and the answer
337
+ * key. Ordinary labels are therefore passed through unchanged. The reserved object
338
+ * keys (`__proto__`, `constructor`, `prototype`) are unsafe as object keys and get a
339
+ * deterministic `__option_<index>` surrogate instead; every answer is mapped back to
340
+ * the caller's original ID before it is returned. Surrogates never collide with a
341
+ * caller label in the same question.
342
+ * @param options - the caller's validated option labels, in input order.
343
+ * @returns the native criteria plus the reverse mapping.
344
+ */
345
+ export function mapProviderOptionKeys(options) {
346
+ const reserved = new Set(options);
347
+ const providerKeys = options.map((label, index) => {
348
+ if (!UNSAFE_PROVIDER_KEYS.has(label))
349
+ return label;
350
+ let candidate = `__option_${index}`;
351
+ while (reserved.has(candidate))
352
+ candidate = `_${candidate}`;
353
+ reserved.add(candidate);
354
+ return candidate;
355
+ });
356
+ const reverse = new Map(providerKeys.map((key, index) => [key, options[index]]));
357
+ const criteria = Object.fromEntries(providerKeys.map(key => [key, null]));
358
+ return {
359
+ criteria,
360
+ originalToProvider: providerKeys,
361
+ toOriginal: providerKey => reverse.get(providerKey) ?? providerKey,
362
+ toOriginalProbabilities: probabilities => Object.fromEntries(Object.entries(probabilities).map(([key, value]) => [reverse.get(key) ?? key, value])),
363
+ };
364
+ }
365
+ /**
366
+ * Map a native choice onto the STANDARD `decision.choose` contract.
367
+ *
368
+ * The runtime's own chosen label is revalidated against the caller's FULL option
369
+ * set before it is used; an unknown label refuses instead of being rendered. When
370
+ * the runtime abstained (null choice), the argmax over the caller's options is
371
+ * used so the standard payload always names an option.
372
+ * @param options - the caller's complete options, in order.
373
+ * @param chosenLabel - the runtime's choice, or null when it abstained.
374
+ * @param probabilities - per-option probabilities, keyed by option label.
375
+ * @param confidence - the runtime's uncalibrated confidence mass.
376
+ * @returns the standard contract payload, never with a label outside `options`.
377
+ */
378
+ export function standardChooseFromNative(options, chosenLabel, probabilities, confidence) {
379
+ validateOptions(options, 16);
380
+ let chosenLabelOrNull = chosenLabel;
381
+ if (chosenLabelOrNull !== null && !options.includes(chosenLabelOrNull)) {
382
+ throw new Error(`the runtime chose ${JSON.stringify(chosenLabelOrNull)}, which is not one of the supplied options`);
383
+ }
384
+ if (chosenLabelOrNull === null) {
385
+ let best = Number.NEGATIVE_INFINITY;
386
+ for (const option of options) {
387
+ const value = probabilities[option];
388
+ if (typeof value === 'number' && Number.isFinite(value) && value > best) {
389
+ best = value;
390
+ chosenLabelOrNull = option;
391
+ }
392
+ }
393
+ if (chosenLabelOrNull === null)
394
+ throw new Error('the runtime abstained and no option carries a probability');
395
+ }
396
+ const chosen = options.indexOf(chosenLabelOrNull);
397
+ if (chosen < 0)
398
+ throw new Error('the chosen option is not in the supplied option set');
399
+ const mass = Number.isFinite(confidence) ? Math.max(0, Math.min(1, confidence)) : 0;
400
+ const confidenceLabel = mass >= 0.6 ? 'confident' : mass >= 0.35 ? 'likely' : 'tentative';
401
+ return {
402
+ chosen,
403
+ confidence: confidenceLabel,
404
+ reason: `Chose ${JSON.stringify(chosenLabelOrNull)} (uncalibrated probability ${mass.toFixed(4)}).`,
405
+ };
406
+ }
407
+ /**
408
+ * Map a SCORE answer onto the caller's level label.
409
+ *
410
+ * The runtime answers a score question with BOTH an expected value
411
+ * (`score: Σ i·p_i`, a float) and per-index probabilities plus a legend. The
412
+ * declared output schema requires a LABEL (`score: string|null`), so the label is
413
+ * the argmax of those probabilities — exactly what the vendored runtime's own
414
+ * `best()` returns — mapped through the levels the caller supplied. The expected
415
+ * value is deliberately NOT reported as the score: it is a mean, not a level.
416
+ * @param probabilities - the answer's index→probability map.
417
+ * @param levels - the caller's levels, lowest first.
418
+ * @returns the level label, or null when no index maps to a level.
419
+ */
420
+ export function scoreLevelFromProbabilities(probabilities, levels) {
421
+ let bestIndex = -1;
422
+ let bestValue = Number.NEGATIVE_INFINITY;
423
+ for (const [key, value] of Object.entries(probabilities)) {
424
+ const index = Number(key);
425
+ if (!Number.isInteger(index) || index < 0 || index >= levels.length)
426
+ continue;
427
+ if (typeof value !== 'number' || !Number.isFinite(value))
428
+ continue;
429
+ if (value > bestValue) {
430
+ bestValue = value;
431
+ bestIndex = index;
432
+ }
433
+ }
434
+ return bestIndex === -1 ? null : (levels[bestIndex] ?? null);
435
+ }
436
+ /** The provenance problems that block an R19 replay, if any. */
437
+ function r19ProvenanceIssues(document, label) {
438
+ const issues = [];
439
+ if (document.reviewStatus !== 'reviewed') {
440
+ issues.push(label + ' is ' + String(document.reviewStatus ?? 'missing') + ' (not reviewed)');
441
+ }
442
+ if (document.reviewedAt === undefined || document.reviewedAt.trim().length === 0) {
443
+ issues.push(label + ' has no reviewedAt');
444
+ }
445
+ else if (!Number.isFinite(Date.parse(document.reviewedAt))) {
446
+ issues.push(label + ' reviewedAt is not a parseable date');
447
+ }
448
+ if (document.blind !== true)
449
+ issues.push(label + ' does not record blind:true');
450
+ if (document.reviewer === undefined || document.reviewer.trim().length === 0) {
451
+ issues.push(label + ' has no non-empty reviewer');
452
+ }
453
+ return issues;
454
+ }
455
+ /**
456
+ * Replay the reviewed margin gate over the held-out task-shape fixtures (R19), wiring the
457
+ * reviewed coverageBudget into the verdict.
458
+ *
459
+ * The replay is BLOCKED with a named reason unless BOTH halves carry operator provenance
460
+ * (reviewStatus 'reviewed', a parseable reviewedAt, blind:true, a non-empty reviewer) AND
461
+ * every held-out row carries a captured probability map and a correctness label. A
462
+ * dev-fitted abstainMargin is supplied by the caller, never refit on held-out data.
463
+ * @param dev - the development fixture document (provenance only).
464
+ * @param heldout - the held-out fixture document (acceptance only).
465
+ * @param abstainMargin - the REVIEWED abstain margin.
466
+ * @param coverageBudget - the REVIEWED maximum correct rows the gate may lose.
467
+ * @returns REPLAYED results with the coverage verdict, or a named BLOCKED reason.
468
+ */
469
+ export function evaluateR19Replay(dev, heldout, abstainMargin, coverageBudget) {
470
+ marginGate({ yes: 1, no: 0 }, abstainMargin); // validates abstainMargin; no default is invented
471
+ const provenance = [...r19ProvenanceIssues(dev, 'the dev fixture'), ...r19ProvenanceIssues(heldout, 'the held-out fixture')];
472
+ if (provenance.length > 0) {
473
+ return {
474
+ status: 'BLOCKED',
475
+ code: 'R19_FIXTURES_NOT_REVIEWED',
476
+ reason: 'the R19 fixtures lack reviewed+blind provenance: ' + provenance.join('; '),
477
+ };
478
+ }
479
+ const rows = heldout.rows ?? [];
480
+ if (rows.length === 0 || rows.some(row => row.probabilities === undefined || row.correct === undefined)) {
481
+ return {
482
+ status: 'BLOCKED',
483
+ code: 'R19_NO_CAPTURED_VECTORS',
484
+ reason: 'the reviewed R19 held-out rows have no captured probabilities/correctness; '
485
+ + 'a replay cannot invent vectors or labels',
486
+ };
487
+ }
488
+ // SAFETY: every held-out row was checked above for a captured probabilities map and a
489
+ // correctness boolean; the assertions restate that validated invariant for the mapper.
490
+ const evaluated = rows.map(row => ({
491
+ correct: row.correct,
492
+ probabilities: row.probabilities,
493
+ }));
494
+ const abstentions = evaluated.filter(row => marginGate(row.probabilities, abstainMargin).abstain).length;
495
+ const lostCorrect = evaluated.filter(row => row.correct && marginGate(row.probabilities, abstainMargin).abstain).length;
496
+ const wrongRoutes = evaluated.filter(row => !row.correct && !marginGate(row.probabilities, abstainMargin).abstain).length;
497
+ return {
498
+ status: 'REPLAYED',
499
+ abstentions,
500
+ lostCorrect,
501
+ wrongRoutes,
502
+ coverage: coverageBudgetFailure(evaluated, abstainMargin, coverageBudget),
503
+ };
504
+ }
71
505
  //# sourceMappingURL=pure.js.map
package/lib/pure.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"pure.js","sourceRoot":"","sources":["../src/pure.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,6EAA6E;AAC7E,MAAM,CAAC,MAAM,WAAW,GAAG,EAAE,CAAA;AAC7B,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,CAAA;AAElC,yDAAyD;AACzD,MAAM,UAAU,OAAO,CAAC,CAAoB;IAC1C,MAAM,CAA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B;QAC/B,aAAa,EAAE,GAAG,CAAC,aAAiD;KACrE,CAAC,CAAC,CAAA;IACH,MAAM,WAAW,GAAG,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,CAAA;IACxG,MAAM,WAAW,GAAG,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,OAAO,IAAI,UAAU,CAAC,GAAG,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,CAAA;IACvH,MAAM,WAAW,GAAG,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,CAAA;IACzH,OAAO;QACL,MAAM,EAAE,UAAU;QAClB,WAAW;QACX,WAAW;QACX,WAAW;QACX,QAAQ,EAAE,qBAAqB,CAAC,SAAS,EAAE,aAAa,EAAE,cAAc,CAAC;KAC1E,CAAA;AACH,CAAC"}
package/lib/scope.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ /**
2
+ * R20: the bounded scope of a local Laya decision.
3
+ *
4
+ * JEV boundary: these tools are "System One, not a reasoner". They answer a BOUNDED judgment
5
+ * over the supplied text (classification, yes/no, choice, ordinal). Generation, arithmetic,
6
+ * dates, multi-hop reasoning and greeting/thanks judgments are OUT OF SCOPE: returning a
7
+ * coin-flip answer there is worse than refusing (DEC-04).
8
+ *
9
+ * Detection is deliberately CONSERVATIVE: only direct question/imperative patterns fire, so a
10
+ * document that merely CONTAINS an excluded word still passes when the predicate is bounded.
11
+ *
12
+ * @module scope
13
+ */
14
+ /** The decision scope values the local v2 contracts declare. */
15
+ export type DecisionScope = 'in-scope' | 'out-of-scope';
16
+ /**
17
+ * Classify one local decision request as in scope or out of scope.
18
+ *
19
+ * The PREDICATE is the judgment being asked; it is what the detector reads. The document text
20
+ * is only used when no separate predicate is supplied (and even then only via the same direct
21
+ * patterns), so a document that contains "thank you" is not mistaken for a greeting judgment.
22
+ * @param text - the supplied document/state (fallback only when predicate is empty).
23
+ * @param predicate - the bounded judgment/question being asked.
24
+ * @returns 'in-scope' or 'out-of-scope'.
25
+ */
26
+ export declare function scopeOf(text: string, predicate: string): DecisionScope;
package/lib/scope.js ADDED
@@ -0,0 +1,79 @@
1
+ /**
2
+ * R20: the bounded scope of a local Laya decision.
3
+ *
4
+ * JEV boundary: these tools are "System One, not a reasoner". They answer a BOUNDED judgment
5
+ * over the supplied text (classification, yes/no, choice, ordinal). Generation, arithmetic,
6
+ * dates, multi-hop reasoning and greeting/thanks judgments are OUT OF SCOPE: returning a
7
+ * coin-flip answer there is worse than refusing (DEC-04).
8
+ *
9
+ * Detection is deliberately CONSERVATIVE: only direct question/imperative patterns fire, so a
10
+ * document that merely CONTAINS an excluded word still passes when the predicate is bounded.
11
+ *
12
+ * @module scope
13
+ */
14
+ /**
15
+ * Direct question/imperative patterns only. A bare keyword in a document never fires; the
16
+ * pattern must ask the excluded question (or give the excluded imperative).
17
+ */
18
+ const EXCLUDED_PATTERNS = [
19
+ {
20
+ reason: 'greeting/thanks judgment',
21
+ pattern: /\b(is|are|was|were)\b[^?]{0,60}?\b(a|an)\s+(greeting|greetings|salutation)\b/i,
22
+ },
23
+ {
24
+ reason: 'greeting/thanks judgment',
25
+ pattern: /\b(is|are)\b[^?]{0,60}?\b(a|an)\s+(thank[- ]?you|thanks)\b/i,
26
+ },
27
+ {
28
+ reason: 'arithmetic',
29
+ pattern: /\b(what('s| is)|calculate|compute|solve|evaluate)\b[^?]{0,80}\d+\s*[-+*/x×÷]\s*\d+/i,
30
+ },
31
+ {
32
+ reason: 'arithmetic',
33
+ pattern: /^\s*[\d(]+\s*[-+*/x×÷]\s*[\d(]+\s*=?\s*\??\s*$/,
34
+ },
35
+ {
36
+ reason: 'arithmetic',
37
+ pattern: /\d+\s*[-+*/x×÷]\s*\d+\s*=\s*\d+/,
38
+ },
39
+ {
40
+ reason: 'date/time',
41
+ pattern: /\b(what (date|day|time)|which (date|day)|when (was|is|will)|how many (days|hours|minutes)|current (date|time)|what day of the week)\b/i,
42
+ },
43
+ {
44
+ reason: 'date/time',
45
+ pattern: /\b\d{4}-\d{2}-\d{2}\b/,
46
+ },
47
+ {
48
+ reason: 'multi-hop reasoning',
49
+ pattern: /\b(multi[- ]?hop|multi[- ]?step|step[- ]by[- ]?step|chain of thought|reason through)\b/i,
50
+ },
51
+ {
52
+ reason: 'generation',
53
+ pattern: /^\s*(please\s+)?(write|compose|generate|draft|summari[sz]e|translate|rewrite|paraphrase|create)\b/i,
54
+ },
55
+ {
56
+ reason: 'generation',
57
+ pattern: /\b(write|compose|generate|draft|summari[sz]e|translate|rewrite|paraphrase|create)\b[^?]{0,100}?\b(haiku|poem|story|essay|article|email|letter|title|summary|sentence|paragraph|response)\b/i,
58
+ },
59
+ ];
60
+ /**
61
+ * Classify one local decision request as in scope or out of scope.
62
+ *
63
+ * The PREDICATE is the judgment being asked; it is what the detector reads. The document text
64
+ * is only used when no separate predicate is supplied (and even then only via the same direct
65
+ * patterns), so a document that contains "thank you" is not mistaken for a greeting judgment.
66
+ * @param text - the supplied document/state (fallback only when predicate is empty).
67
+ * @param predicate - the bounded judgment/question being asked.
68
+ * @returns 'in-scope' or 'out-of-scope'.
69
+ */
70
+ export function scopeOf(text, predicate) {
71
+ const asked = predicate.trim().length > 0 ? predicate : text;
72
+ const normalized = asked.replace(/\s+/g, ' ').trim();
73
+ for (const excluded of EXCLUDED_PATTERNS) {
74
+ if (excluded.pattern.test(normalized))
75
+ return 'out-of-scope';
76
+ }
77
+ return 'in-scope';
78
+ }
79
+ //# sourceMappingURL=scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope.js","sourceRoot":"","sources":["../src/scope.ts"],"names":[],"mapp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