@orkestrel/interpret 0.0.4 → 0.0.5

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.
@@ -563,8 +563,8 @@ export declare function createSubjectManager(options?: SubjectManagerOptions): S
563
563
  * `{table}.{reasoning}` for the four reasons kinds, `result.quantitative.failed`
564
564
  * for the quantitative-result failure suffix, and `subject.fields` /
565
565
  * `subject.empty` for `describeSubject`. Every string is a plain
566
- * `interpolateMessage` template — `{{name}}`-style placeholders resolved
567
- * against the caller-supplied `values` record.
566
+ * @orkestrel/template `fillTemplate` template — `{{name}}`-style placeholders
567
+ * resolved against the caller-supplied `values` record.
568
568
  */
569
569
  export declare const DEFAULT_LEXICON: Lexicon;
570
570
 
@@ -1048,32 +1048,6 @@ export declare function createSubjectManager(options?: SubjectManagerOptions): S
1048
1048
  readonly confidence: number;
1049
1049
  }
1050
1050
 
1051
- /**
1052
- * Interpolate `{{dotted.path}}` tokens in a message template against a record.
1053
- *
1054
- * @remarks
1055
- * Each token is split on `.` into a {@link FieldPath} array and resolved with
1056
- * the contracts `resolveField` (a plain string field is ONE key, never
1057
- * dot-split — the split here is the token-to-path bridge). A finite number
1058
- * renders with `en-US` thousand grouping (`5010` → `5,010`); any other
1059
- * resolved value String-coerces. An UNRESOLVED path (the resolved value is
1060
- * `undefined`) renders as the empty string — the deterministic "nothing to
1061
- * show" rule.
1062
- *
1063
- * @param template - The message template carrying `{{dotted.path}}` tokens
1064
- * @param record - The record tokens resolve against
1065
- * @returns The template with every token replaced
1066
- *
1067
- * @example
1068
- * ```ts
1069
- * import { interpolateMessage } from '@src/core'
1070
- *
1071
- * interpolateMessage('Limit is {{limit}}', { limit: 5010 }) // 'Limit is 5,010'
1072
- * interpolateMessage('Missing {{gone}}', {}) // 'Missing '
1073
- * ```
1074
- */
1075
- export declare function interpolateMessage(template: string, record: Readonly<Record<string, unknown>>): string;
1076
-
1077
1051
  /**
1078
1052
  * The interpretation orchestrator — the sole public entry point of the
1079
1053
  * `interprets` module, mirroring the reasons `Reason` orchestrator shape.
@@ -1509,8 +1483,11 @@ export declare function createSubjectManager(options?: SubjectManagerOptions): S
1509
1483
  * dotted `FieldPath` string to its display label, falling back to
1510
1484
  * `formatField` when absent. `templates` maps a template id (e.g.
1511
1485
  * `'definition.quantitative'`, `'result.symbolic'`, `'subject.fields'`) to an
1512
- * `interpolateMessage` template string — see `DEFAULT_LEXICON` for the
1513
- * pinned neutral key set.
1486
+ * @orkestrel/template `fillTemplate` template string — see `DEFAULT_LEXICON`
1487
+ * for the pinned neutral key set. Token grammar (the `[^{}]` token class, the
1488
+ * `\{{` literal escape, whitespace trimming, and dotted-token path
1489
+ * resolution) is defined by @orkestrel/template — see the vendored
1490
+ * `guides/src/template.md` for the authoritative contract.
1514
1491
  */
1515
1492
  export declare interface Lexicon {
1516
1493
  readonly phrases?: Readonly<Record<string, Readonly<Record<string, string>>>>;
@@ -563,8 +563,8 @@ export declare function createSubjectManager(options?: SubjectManagerOptions): S
563
563
  * `{table}.{reasoning}` for the four reasons kinds, `result.quantitative.failed`
564
564
  * for the quantitative-result failure suffix, and `subject.fields` /
565
565
  * `subject.empty` for `describeSubject`. Every string is a plain
566
- * `interpolateMessage` template — `{{name}}`-style placeholders resolved
567
- * against the caller-supplied `values` record.
566
+ * @orkestrel/template `fillTemplate` template — `{{name}}`-style placeholders
567
+ * resolved against the caller-supplied `values` record.
568
568
  */
569
569
  export declare const DEFAULT_LEXICON: Lexicon;
570
570
 
@@ -1048,32 +1048,6 @@ export declare function createSubjectManager(options?: SubjectManagerOptions): S
1048
1048
  readonly confidence: number;
1049
1049
  }
1050
1050
 
1051
- /**
1052
- * Interpolate `{{dotted.path}}` tokens in a message template against a record.
1053
- *
1054
- * @remarks
1055
- * Each token is split on `.` into a {@link FieldPath} array and resolved with
1056
- * the contracts `resolveField` (a plain string field is ONE key, never
1057
- * dot-split — the split here is the token-to-path bridge). A finite number
1058
- * renders with `en-US` thousand grouping (`5010` → `5,010`); any other
1059
- * resolved value String-coerces. An UNRESOLVED path (the resolved value is
1060
- * `undefined`) renders as the empty string — the deterministic "nothing to
1061
- * show" rule.
1062
- *
1063
- * @param template - The message template carrying `{{dotted.path}}` tokens
1064
- * @param record - The record tokens resolve against
1065
- * @returns The template with every token replaced
1066
- *
1067
- * @example
1068
- * ```ts
1069
- * import { interpolateMessage } from '@src/core'
1070
- *
1071
- * interpolateMessage('Limit is {{limit}}', { limit: 5010 }) // 'Limit is 5,010'
1072
- * interpolateMessage('Missing {{gone}}', {}) // 'Missing '
1073
- * ```
1074
- */
1075
- export declare function interpolateMessage(template: string, record: Readonly<Record<string, unknown>>): string;
1076
-
1077
1051
  /**
1078
1052
  * The interpretation orchestrator — the sole public entry point of the
1079
1053
  * `interprets` module, mirroring the reasons `Reason` orchestrator shape.
@@ -1509,8 +1483,11 @@ export declare function createSubjectManager(options?: SubjectManagerOptions): S
1509
1483
  * dotted `FieldPath` string to its display label, falling back to
1510
1484
  * `formatField` when absent. `templates` maps a template id (e.g.
1511
1485
  * `'definition.quantitative'`, `'result.symbolic'`, `'subject.fields'`) to an
1512
- * `interpolateMessage` template string — see `DEFAULT_LEXICON` for the
1513
- * pinned neutral key set.
1486
+ * @orkestrel/template `fillTemplate` template string — see `DEFAULT_LEXICON`
1487
+ * for the pinned neutral key set. Token grammar (the `[^{}]` token class, the
1488
+ * `\{{` literal escape, whitespace trimming, and dotted-token path
1489
+ * resolution) is defined by @orkestrel/template — see the vendored
1490
+ * `guides/src/template.md` for the authoritative contract.
1514
1491
  */
1515
1492
  export declare interface Lexicon {
1516
1493
  readonly phrases?: Readonly<Record<string, Readonly<Record<string, string>>>>;
@@ -1,6 +1,7 @@
1
- import { arrayOf, isBoolean, isFiniteNumber, isRecord, isString, notOf, parseJSONAs, recordOf, resolveField, unionOf } from "@orkestrel/contract";
1
+ import { arrayOf, isBoolean, isFiniteNumber, isRecord, isString, notOf, parseJSONAs, recordOf, unionOf } from "@orkestrel/contract";
2
2
  import { applyOperation, formatField, isDefinition, isFieldPath, isSymbolicExpression } from "@orkestrel/reason";
3
3
  import { Emitter } from "@orkestrel/emitter";
4
+ import { fillTemplate } from "@orkestrel/template";
4
5
  //#region src/core/constants.ts
5
6
  /**
6
7
  * Default `similarity` for `createInterpret` / `matchAlias` — the fuzzy
@@ -87,8 +88,8 @@ var DEFAULT_VERBS = Object.freeze({});
87
88
  * `{table}.{reasoning}` for the four reasons kinds, `result.quantitative.failed`
88
89
  * for the quantitative-result failure suffix, and `subject.fields` /
89
90
  * `subject.empty` for `describeSubject`. Every string is a plain
90
- * `interpolateMessage` template — `{{name}}`-style placeholders resolved
91
- * against the caller-supplied `values` record.
91
+ * @orkestrel/template `fillTemplate` template — `{{name}}`-style placeholders
92
+ * resolved against the caller-supplied `values` record.
92
93
  */
93
94
  var DEFAULT_LEXICON = Object.freeze({
94
95
  phrases: Object.freeze({}),
@@ -367,38 +368,6 @@ function setField(subject, field, value) {
367
368
  };
368
369
  }
369
370
  /**
370
- * Interpolate `{{dotted.path}}` tokens in a message template against a record.
371
- *
372
- * @remarks
373
- * Each token is split on `.` into a {@link FieldPath} array and resolved with
374
- * the contracts `resolveField` (a plain string field is ONE key, never
375
- * dot-split — the split here is the token-to-path bridge). A finite number
376
- * renders with `en-US` thousand grouping (`5010` → `5,010`); any other
377
- * resolved value String-coerces. An UNRESOLVED path (the resolved value is
378
- * `undefined`) renders as the empty string — the deterministic "nothing to
379
- * show" rule.
380
- *
381
- * @param template - The message template carrying `{{dotted.path}}` tokens
382
- * @param record - The record tokens resolve against
383
- * @returns The template with every token replaced
384
- *
385
- * @example
386
- * ```ts
387
- * import { interpolateMessage } from '@src/core'
388
- *
389
- * interpolateMessage('Limit is {{limit}}', { limit: 5010 }) // 'Limit is 5,010'
390
- * interpolateMessage('Missing {{gone}}', {}) // 'Missing '
391
- * ```
392
- */
393
- function interpolateMessage(template, record) {
394
- return template.replace(/\{\{\s*([^}]+?)\s*\}\}/g, (_match, path) => {
395
- const value = resolveField(record, path.split("."));
396
- if (value === void 0) return "";
397
- if (isFiniteNumber(value)) return value.toLocaleString("en-US");
398
- return String(value);
399
- });
400
- }
401
- /**
402
371
  * Replace every whole-word occurrence of a map's keys with their values.
403
372
  *
404
373
  * @remarks
@@ -1516,7 +1485,7 @@ var Narrator = class {
1516
1485
  line(id, values) {
1517
1486
  if (!Object.hasOwn(this.#lexicon.templates, id)) return "";
1518
1487
  const template = this.#lexicon.templates[id];
1519
- return typeof template === "string" ? interpolateMessage(template, values) : "";
1488
+ return typeof template === "string" ? fillTemplate(template, values, { missing: "empty" }) : "";
1520
1489
  }
1521
1490
  value(unit, raw) {
1522
1491
  if (Object.hasOwn(this.#formatters, unit)) {
@@ -2631,6 +2600,6 @@ function createNarrator(options) {
2631
2600
  return new Narrator(options);
2632
2601
  }
2633
2602
  //#endregion
2634
- export { CONFIDENCE_ALIAS, CONFIDENCE_CARRIED, CONFIDENCE_COLLECT, CONFIDENCE_COMPUTED, CONFIDENCE_DEFAULT, CONFIDENCE_EXACT, CONFIDENCE_POSITIONAL, Clarifier, DEFAULT_ABBREVIATIONS, DEFAULT_ACTIONS, DEFAULT_CONTRACTIONS, DEFAULT_CORRECTIONS, DEFAULT_DOMAINS, DEFAULT_INTERPRET_FLOOR, DEFAULT_INTERPRET_HISTORY, DEFAULT_INTERPRET_SIMILARITY, DEFAULT_LEXICON, DEFAULT_VERBS, DefinitionManager, Extractor, Formatter, Generator, INTERPRET_ID, Interpret, InterpretContext, InterpretError, NUMBER_PATTERN, Narrator, Normalizer, SubjectManager, TemplateManager, UNSAFE_FIELD_SEGMENTS, applyReplacements, assignEntities, canonicalize, classifyIntent, collapseWhitespace, createClarifier, createDefinitionManager, createExtractor, createFormatter, createGenerator, createInterpret, createInterpretContext, createNarrator, createNormalizer, createSubjectManager, createTemplate, createTemplateManager, deriveAggregateField, describeSubject, digestValue, escapeRegExp, extractNumbers, interpolateMessage, isComputedField, isEntityMapping, isFieldDefault, isInterpretError, isTemplate, matchAlias, matchTemplate, parseTemplate, resolveExpression, scoreSimilarity, scoreTemplate, setField, tokenize, variablesOf };
2603
+ export { CONFIDENCE_ALIAS, CONFIDENCE_CARRIED, CONFIDENCE_COLLECT, CONFIDENCE_COMPUTED, CONFIDENCE_DEFAULT, CONFIDENCE_EXACT, CONFIDENCE_POSITIONAL, Clarifier, DEFAULT_ABBREVIATIONS, DEFAULT_ACTIONS, DEFAULT_CONTRACTIONS, DEFAULT_CORRECTIONS, DEFAULT_DOMAINS, DEFAULT_INTERPRET_FLOOR, DEFAULT_INTERPRET_HISTORY, DEFAULT_INTERPRET_SIMILARITY, DEFAULT_LEXICON, DEFAULT_VERBS, DefinitionManager, Extractor, Formatter, Generator, INTERPRET_ID, Interpret, InterpretContext, InterpretError, NUMBER_PATTERN, Narrator, Normalizer, SubjectManager, TemplateManager, UNSAFE_FIELD_SEGMENTS, applyReplacements, assignEntities, canonicalize, classifyIntent, collapseWhitespace, createClarifier, createDefinitionManager, createExtractor, createFormatter, createGenerator, createInterpret, createInterpretContext, createNarrator, createNormalizer, createSubjectManager, createTemplate, createTemplateManager, deriveAggregateField, describeSubject, digestValue, escapeRegExp, extractNumbers, isComputedField, isEntityMapping, isFieldDefault, isInterpretError, isTemplate, matchAlias, matchTemplate, parseTemplate, resolveExpression, scoreSimilarity, scoreTemplate, setField, tokenize, variablesOf };
2635
2604
 
2636
2605
  //# sourceMappingURL=index.js.map