@lokascript/framework 4.4.0 → 4.6.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/CHANGELOG.md +197 -5
- package/dist/api/create-dsl.d.ts +46 -1
- package/dist/api/create-dsl.d.ts.map +1 -1
- package/dist/api/domain-registry.d.ts.map +1 -1
- package/dist/api/index.js +187 -19
- package/dist/api/index.js.map +1 -1
- package/dist/api/reading.d.ts +8 -0
- package/dist/api/reading.d.ts.map +1 -0
- package/dist/index.cjs +189 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +187 -19
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/__test__/fixtures/sql-dsl.ts +3 -0
- package/src/__test__/sql-integration.test.ts +2 -2
- package/src/api/create-dsl.test.ts +120 -0
- package/src/api/create-dsl.ts +173 -21
- package/src/api/domain-registry.test.ts +70 -5
- package/src/api/domain-registry.ts +82 -1
- package/src/api/reading.ts +29 -0
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,196 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [4.6.0] - 2026-10-15
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- **`@lokascript/semantic`: `ask` and `answer`** in every language's own word (es `preguntar` /
|
|
15
|
+
`responder`, ja `尋ねる` / `答える`, de `frage` / `antworte`): upstream's two dialog commands
|
|
16
|
+
(`ask "Name?"` prompts; `answer "Save?" with "Yes" or "No"` confirms, the choices after the language's
|
|
17
|
+
`with`). Both were refused in every language. Listed for native review in
|
|
18
|
+
`packages/semantic/NATIVE_REVIEW_NEEDED.md`.
|
|
19
|
+
- **`@lokascript/semantic`: `scroll … by` with a direction** in every language's own words
|
|
20
|
+
(`scroll #box down by 200px`: es `desplazamiento #box abajo por 200px`, ja `#boxを 下 200px スクロール`,
|
|
21
|
+
ru `прокрутить #box вниз 200px`). Upstream's relative scroll was refused in every language: no
|
|
22
|
+
direction had a word, and scroll's schema modeled `scroll to <el>` alone. Listed for native review in
|
|
23
|
+
`packages/semantic/NATIVE_REVIEW_NEEDED.md`.
|
|
24
|
+
|
|
25
|
+
### Changed
|
|
26
|
+
|
|
27
|
+
- **`@lokascript/framework`: a domain DSL's parse refuses input it did not read.**
|
|
28
|
+
`createMultilingualDSL`'s `parse` (and so `compile`, `validate`, `translate`) tries every pattern and
|
|
29
|
+
takes the best match that reads the WHOLE input: highest priority, then confidence. When the only
|
|
30
|
+
matches leave input unread, it throws `UnreadInputError` (exported; `code: 'unread-input'`, with the
|
|
31
|
+
longest match's `reading` and the `unread` text). It used to return the first match however much it
|
|
32
|
+
read, so a trailing word was dropped without a word: the domain gate (lokascript-domains) found
|
|
33
|
+
1,744 of 1,744 renders accepted with an unknown word after them, and `ask what is 2+2` asked the
|
|
34
|
+
model "what". Against the gate (domains 4.0.0, measured unpublished with `gate:upstream`): 1,527
|
|
35
|
+
cases better, 62 worse, every one `pass → refused` (a value such as `click`'s that the generator
|
|
36
|
+
ignored, now refused as unread rather than dropped); no case became silent, and no accepted parse
|
|
37
|
+
changed its reading. A multi-word llm question is quoted: `ask "what is 2+2"`.
|
|
38
|
+
- **`@lokascript/framework`: a domain DSL's `translate` refuses a rendering that does not read
|
|
39
|
+
back.** It reads its output in the target language and requires the source command: the same
|
|
40
|
+
action and role values, or the same compiled code. Otherwise it throws `TranslationReadBackError`
|
|
41
|
+
(exported; the text under `partial`, what it reads as under `reading`), unless `{ lossy: 'allow' }`,
|
|
42
|
+
as semantic's `translate`. `DomainRegistry`'s tools (the MCP `parse_` / `compile_` / `validate_` /
|
|
43
|
+
`translate_<domain>` tools) report refusals as `ok: false` with an `UNREAD_INPUT` or
|
|
44
|
+
`TRANSLATION_DOES_NOT_READ_BACK` diagnostic instead of a generic tool error, and `translate_<domain>`
|
|
45
|
+
reads its own rendering back the same way. Translating every domain gate command from English: 46
|
|
46
|
+
renders that used to be returned are now refused (45 do not parse in the target language).
|
|
47
|
+
- **`@lokascript/semantic`: the parser is split into modules.** `semantic-parser.ts` went from 9,680
|
|
48
|
+
lines to 751, across 22 modules under `parser/`, and each question about an end word (does it close a
|
|
49
|
+
block, does it stop a clause) has one reader. Each step was checked against 27,194 parses; the steps
|
|
50
|
+
that change a reading are listed under Fixed. `SemanticParseError` keeps its import path.
|
|
51
|
+
|
|
52
|
+
### Fixed
|
|
53
|
+
|
|
54
|
+
- **`@lokascript/semantic`: a handler's count** (`on click 1 …`, the first click only; `on click 2 …`)
|
|
55
|
+
is read in every language. The renders already wrote it (es `al clic 1 ocultar`), but every reader
|
|
56
|
+
outside English dropped it, so the translation was refused in all 23 languages. Bengali, Italian and
|
|
57
|
+
Thai also read every clause between a handler's event and its body (`on click elsewhere`,
|
|
58
|
+
`on mutation of attributes`, `on foo queue first`), which their head pattern skipped. In the command-shape
|
|
59
|
+
gate, 375 lanes that were refused now pass.
|
|
60
|
+
- **`@lokascript/semantic`: a query of a pseudo-class alone** (`<:checked/>`, `<:not(.done)/>`) reads
|
|
61
|
+
as a query in every language, English too. Every tokenizer read `<` and then a local variable
|
|
62
|
+
`:checked`, so a translation was refused. In the command-shape gate, 161 lanes that were refused now
|
|
63
|
+
pass.
|
|
64
|
+
- **`@lokascript/semantic`: value spellings from upstream's own tests** read in every language,
|
|
65
|
+
English too: an escaped class name (`.group-\[:nth-of-type\(3\)_\&\]:block`), a query of several
|
|
66
|
+
selectors (`<#d1, #d2/>`), a unit after parentheses (`(startWidth)px`), `[@data-foo]` and an
|
|
67
|
+
attribute after a pronoun (`set it @disabled to true`, written `its @disabled`), a dotted property
|
|
68
|
+
before `of` (`set parentNode.innerHTML of #d1 to "foo"`), and `set {bar: 2, baz: 3} on obj`. Each was
|
|
69
|
+
refused. `get` no longer has a destination slot, which no reader used and which took Italian's `in`:
|
|
70
|
+
`get #p1 in me` read back as `get #p1 on me` in Italian, and `get result as JSONString` was refused
|
|
71
|
+
in Quechua. In the command-shape gate, 202 lanes are better, 3 of them silent before.
|
|
72
|
+
- **`@lokascript/semantic`: upstream's collection expressions** read in English and translate:
|
|
73
|
+
`set :items to <span/> in #box where it matches .a`,
|
|
74
|
+
`put matches mapped to its textContent into #out`, `repeat for x in :items where x.val > 10 …`. They were refused in every language, English
|
|
75
|
+
too, or kept as an English clause after the command. A translation writes the language's own `where`,
|
|
76
|
+
as it already did in a condition (es `donde`, de `wo`), and keeps `mapped to` in English until native
|
|
77
|
+
review. Also read now: an element-scoped variable (`:items`) inside a longer value, the article in
|
|
78
|
+
`in the closest <table/>` and `checked of the :boxes`, and zh/tl's `no` before a sigil variable. Quechua and
|
|
79
|
+
Vietnamese read their own `where` back (it read as `target`, or split at its `_`), which also clears a
|
|
80
|
+
silent pair in each. In the command-shape gate, 154 lanes are better, 2 of them silent before.
|
|
81
|
+
- **`@lokascript/semantic`: a query's scope inside a phrase** reads in English and translates:
|
|
82
|
+
`put the length of <:checked/> in #box into me` (the value ended at the query and `in` was taken as
|
|
83
|
+
put's marker), `bind $n to the length of <:checked/> in the next <tbody/> …` (a positional scope),
|
|
84
|
+
`put <span/> in #box where it matches .a into me` (English came back silently as `… into #box …`), and
|
|
85
|
+
`put the length of <p/> into #out` and `put 'x' into the next <div/>'s textContent`, which the lossy
|
|
86
|
+
check refused because it read the `'s` after `<p/>` as a quote. In the command-shape gate, 63 lanes are
|
|
87
|
+
better, 1 of them silent before.
|
|
88
|
+
- **`@lokascript/semantic`: no translation reads back as other English without saying so.** The
|
|
89
|
+
command-shape gate's last five silent pairs read back as their source: pl's `closest .bar to .foo`
|
|
90
|
+
(pl's own `to` is "it"), `closest @foo` in pl and sw, a Quechua chain of `'s` (`$data's inner's val`,
|
|
91
|
+
read as a string), and Indonesian's `saya punya @data-x`. English `set closest @foo to "doh"` and
|
|
92
|
+
`put closest @foo into me`, refused in all 24 languages, read now too.
|
|
93
|
+
- **`@lokascript/semantic`: commands that semantic already models, refused in some languages,** read
|
|
94
|
+
and translate. In the command-shape gate, 168 lanes that were refused now pass; with the rows above,
|
|
95
|
+
the refused lanes of shapes semantic models went from 911 to 86, and the gate reads 26,531 pass,
|
|
96
|
+
709 refused and 0 silent. The commands:
|
|
97
|
+
- `fetch $u as JSON`, with a `$` or `:` variable as the URL (23 languages);
|
|
98
|
+
- `toggle my *display`, `*opacity` and `*visibility` (ar, de, fr, he, ja, tr);
|
|
99
|
+
- a `js(…) … end` block after `then` behind a handler head (bn, es, it, ko, pl, ru, th, tl, uk);
|
|
100
|
+
- a snake_case name (`call global_function()`), which 11 tokenizers split at its `_`;
|
|
101
|
+
- a custom event after a handler head's `or` (`on click or foo`: bn, it, ja, ko, th, tr, zh). English
|
|
102
|
+
no longer drops the second event of `on foo or bar`;
|
|
103
|
+
- `put … at end of` in Vietnamese, and in bn, hi, ja, qu and tr after a bare name
|
|
104
|
+
(`put response at end of #results`);
|
|
105
|
+
- a `set` target with no marker after it, in it, pl, ru and uk (`set .divs.innerHTML to "foo"`,
|
|
106
|
+
`#d1.parentNode`, `bar["count"]`), and `on keydown[key=="Enter"]` in ar, de, fr and he;
|
|
107
|
+
- `fetch … as Object` and `as Number` behind a bn, hi or ko handler head;
|
|
108
|
+
- a top-level `for item in items …`, which bn, hi, ko and sw read as a handler on `item`;
|
|
109
|
+
- a loop's bottom test (`repeat … until x is 3 end`) in de, fr and ko;
|
|
110
|
+
- a Korean second handler on a parameterized event (`on exception(error)`), and Polish
|
|
111
|
+
`then throw` after `do` (Polish for `into`);
|
|
112
|
+
- bn, th and vi's own word for `checked`.
|
|
113
|
+
- **`@lokascript/semantic`: `at end of` inside a behavior or a def** reads in every language:
|
|
114
|
+
`behavior B on click put "x" at end of me end` was refused, English to English too, because the
|
|
115
|
+
`end` of `at end of` closed the block. A variable spelled like an end word in such a body reads too
|
|
116
|
+
(es `fin`).
|
|
117
|
+
- **`@lokascript/semantic`: two copied type lists that had lost `property-path`.** Chinese reads
|
|
118
|
+
`put the textContent of last <.picked/> in #list`, which it refused, and ja, ko and zh write the count
|
|
119
|
+
of `repeat the textContent of #a times` in their own words (`#aのtextContent`), not English.
|
|
120
|
+
- **`@lokascript/semantic`: Quechua's `repeat until event … from …`** writes Quechua
|
|
121
|
+
(`kama ruway pointerup ta kutipay #box manta …`), not a leftover of the retired i18n transformer with
|
|
122
|
+
English `until event` and `repeat` in it.
|
|
123
|
+
- **Test runs no longer fill the temp directory**: `scripts/vitest-run.sh` gives each run its own
|
|
124
|
+
`TMPDIR` and removes it. Vitest 5.0.2 leaves a copy of every transformed module in `$TMPDIR` per run.
|
|
125
|
+
|
|
126
|
+
### Removed
|
|
127
|
+
|
|
128
|
+
- **`@hyperfixi/mcp-server`: the jsx domain's four tools** (`parse_jsx`, `compile_jsx`, `validate_jsx`,
|
|
129
|
+
`translate_jsx`), and `jsx` as a `domain` for `lse_validate_and_feedback`, `generate_training_data`
|
|
130
|
+
and the `lse_generate` prompt. The server now depends on `@lokascript/domains` ^4.0.0, which retired
|
|
131
|
+
jsx with six other preview domains (`docs-internal/DOMAINS_RETHINK.md`, D1). 8 domains remain (sql,
|
|
132
|
+
bdd, behaviorspec, llm, flow, voice, todo, learn): 32 domain tools, 102 tools defined, 97 listed by
|
|
133
|
+
default.
|
|
134
|
+
|
|
135
|
+
## [4.5.0] - 2026-10-11
|
|
136
|
+
|
|
137
|
+
Pronouns, suffixes and handler heads read as their language. In 4.4.0 every translation wrote `me` and
|
|
138
|
+
`it` in the nominative beside a marker (es `a yo`, de `zu ich`, tr `ben e`, ar `إلى أنا`), wrote every
|
|
139
|
+
case particle as a word of its own (ko `#out 에`, ja `"x" を`), and wrote a Japanese, Bengali or Turkish
|
|
140
|
+
handler head with two markers (`クリック を で`, `ক্লিক তে`, `tıklama i üzerinde`). Each of these is now
|
|
141
|
+
the language's own form, and every reader still takes the old one. The forms are listed for native
|
|
142
|
+
review in `packages/semantic/NATIVE_REVIEW_NEEDED.md`; none has been reviewed yet.
|
|
143
|
+
|
|
144
|
+
### Added
|
|
145
|
+
|
|
146
|
+
- **`@lokascript/testing-framework`: the English-leak gate counts pronoun case and marker spacing.**
|
|
147
|
+
`case:it` and an unmarked object pronoun (`case:me-object`, `case:it-object`) beside `case:me`; and
|
|
148
|
+
`spacing:<marker>`, a particle ko, ja, bn or tr attaches to its noun written as a word of its own.
|
|
149
|
+
Both shrink-only, both halves (corpus and command shapes), with per-language exit targets in
|
|
150
|
+
`LEAK_TARGETS`.
|
|
151
|
+
- **`@lokascript/semantic`: `toggle … between`** in every language's own words (ja `の間で`, hi `के बीच`,
|
|
152
|
+
he `בין`), with the style form's element written in the language.
|
|
153
|
+
- **`docs-internal/multilingual/FUSED_FORMS.md`**: the design for pronouns fused with their markers and
|
|
154
|
+
suffixes attached to words, with the owner's four questions and their answers.
|
|
155
|
+
|
|
156
|
+
### Changed
|
|
157
|
+
|
|
158
|
+
- **`@lokascript/semantic` writes a pronoun in the case its marker takes.** Free forms: es `en mí`,
|
|
159
|
+
pt `a mim`, it `a me`, tl `sa akin`, pl `do mnie`, ru `ко мне` / `во мне`, uk `до мене`, de `zu mir`
|
|
160
|
+
/ `in mich` (direction) / `auf mir` (location), hi `मुझ में`; `it` after a marker (ru `к этому`, pl
|
|
161
|
+
`do tego`, de `dazu` / `darin` / `darauf`, fr `à lui`, hi `इस में`); `me` as a verb's object (de
|
|
162
|
+
`zeige mich`, ru `покажи меня`). Fused forms: tr `bana` / `beni` / `benden`, `ona` / `onu`; ar `إليّ` / `فيه`;
|
|
163
|
+
he `אליי` / `ממני`; bn `আমাকে` / `আমাতে`; hi `मुझे`; tl `dito`; pt `nele`. Object clitics on the verb:
|
|
164
|
+
es `mostrarme`, it `metterlo`, pt `colocá-lo`, ar `ضعه`; fr writes the object pronoun before the
|
|
165
|
+
infinitive (`le mettre`, `l'afficher`, `me cacher`). Every reader takes the nominative and the English
|
|
166
|
+
forms as before.
|
|
167
|
+
- **`@lokascript/semantic` writes a case particle onto its word** in ko (`"x"을 #out에 넣다`, `나를`,
|
|
168
|
+
each particle in the form the syllable takes), ja (`#outに`, `.aを`) and bn (`#outএ`, `.xকে`), and tr
|
|
169
|
+
fuses a suffix with its own reference words (`sonucu`, `hedefe`, `belgeye`) while code keeps its
|
|
170
|
+
suffix apart (`#out e`) until a reviewer picks a code word's harmony. tr also reads a suffix on code
|
|
171
|
+
after an apostrophe (`#out'a`, `.active'i`).
|
|
172
|
+
- **`@lokascript/semantic`: a custom event in a wait takes the language's `event` word** (`esperar evento foo`,
|
|
173
|
+
ja `イベント foo 待つ`), as `repeat until event X` already does; a known DOM event keeps `esperar transitionend`.
|
|
174
|
+
`wait for <custom event>` was refused in every language. A possessive whose property is a reference word
|
|
175
|
+
(`its.detail`) now reads back as that property, not the language's word for it.
|
|
176
|
+
- **`@lokascript/semantic`: ms and pl read their lexicon's `undefined` word** (`tidak_ditakrifkan`, `niezdefiniowane`),
|
|
177
|
+
which read back as a variable name.
|
|
178
|
+
- **`@lokascript/testing-framework`: the hand-written-input gate** (`hand-written-input.test.ts`): twenty tasks a
|
|
179
|
+
native speaker writes from English, run as written on the engine against upstream; committed with no inputs.
|
|
180
|
+
- **`@lokascript/semantic` writes a handler head as one word**: ja `クリックで` (was `クリック を で`),
|
|
181
|
+
bn `ক্লিকে` (the locative in the form the word takes: `জমাতে` after a vowel; was `ক্লিক তে`),
|
|
182
|
+
tr `tıklamada` (the locative in the form harmony gives: `göndermede`, `değişiklikte`; code keeps it apart, `keyup da`; was `tıklama i üzerinde`). The readers keep taking the two-marker heads.
|
|
183
|
+
- **`@lokascript/semantic` writes a query's scope before the query** in bn, hi, tr, ja and ko (tr
|
|
184
|
+
`bendeki <p/>`, hi `मुझ में स्थित <p/>`, ja `自分 の中の <p/>`), where it wrote English's order.
|
|
185
|
+
- **`@lokascript/semantic`: es and pt write the `focus` and `blur` commands as verbs** (`enfocarme`,
|
|
186
|
+
`focar-me`); the nouns were the events' and still read.
|
|
187
|
+
- **`@lokascript/semantic`: ja's head pattern outranks its fused handler patterns**, so a ja handler's
|
|
188
|
+
body always takes the clause walk: a `js … end` block after `then` and `fetch … as T` round-trip
|
|
189
|
+
where the fused path dropped them. The 2026-08 transformer's verb-first `繰り返し イベント X を まで`
|
|
190
|
+
body no longer reads in ja (the render since 2026-08-28 does).
|
|
191
|
+
|
|
192
|
+
- **`@lokascript/htmx-adapter`: the tr vocab gains `hx-da` as an alias of `hx-on`;** `hx-üzerinde` stays the name
|
|
193
|
+
(the profile's `on` word moved to the locative; a suffix is the wrong register for an attribute name).
|
|
194
|
+
|
|
195
|
+
### Fixed
|
|
196
|
+
|
|
197
|
+
- **`publish.yml`: a repair run skips a version npm is still processing** (`E409 previously staged`)
|
|
198
|
+
instead of failing the whole run.
|
|
199
|
+
|
|
10
200
|
## [4.4.0] - 2026-10-10
|
|
11
201
|
|
|
12
202
|
Translations now read as their language. In 4.3.0, 19% of the corpus's translations and 24% of the
|
|
@@ -23,8 +213,8 @@ language has a word for. The words are the owner's vocabulary sheet
|
|
|
23
213
|
counts, per render, the English grammar words (the tokens the engine's own parser matched in the
|
|
24
214
|
source), English event names the language's lexicon has a word for, and a nominative `me` beside a
|
|
25
215
|
marker in the 13 languages where that case is wrong. Two shrink-only baselines (the corpus, in
|
|
26
|
-
`test:canonical`, and the command-shape cases, in their shards);
|
|
27
|
-
--report` prints each language against M2's targets. An English alternative a profile keeps for
|
|
216
|
+
`test:canonical`, and the command-shape cases, in their shards);
|
|
217
|
+
`tools/regen-english-leaks-baseline.ts --report` prints each language against M2's targets. An English alternative a profile keeps for
|
|
28
218
|
code-switched input, beside a primary that is the language's own, counts as English.
|
|
29
219
|
- **`@lokascript/semantic`: `transition … from … to`** reads and writes in every language (a `source`
|
|
30
220
|
role), and the bare command reads in English. The schema's `destination` role is gone: upstream has
|
|
@@ -41,8 +231,8 @@ language has a word for. The words are the owner's vocabulary sheet
|
|
|
41
231
|
back in English as upstream's first person), `does not match`, `fetch … do not throw`, `on first`,
|
|
42
232
|
`go back`, `from elsewhere`, a loop's `index`, `start view transition`, a query's `in`, a conversion's
|
|
43
233
|
`as` (the type name stays English), `the X of Y` inside an expression (es `valor de #price`, ja
|
|
44
|
-
`#priceの値`), `catch` and `finally`, `element x`, and `def` (as the noun "function", es
|
|
45
|
-
greet(name)`). bn, th and vi have their own `document` and `window`; he has its own words for all of
|
|
234
|
+
`#priceの値`), `catch` and `finally`, `element x`, and `def` (as the noun "function", es
|
|
235
|
+
`función greet(name)`). bn, th and vi have their own `document` and `window`; he has its own words for all of
|
|
46
236
|
these and for `matches`, `exists`, `or`, `not`, `first`, `next`, `previous`, `closest`, `empty`, `is`,
|
|
47
237
|
`document` and `window`; and the 15 languages that wrote English `forever` have their own (es
|
|
48
238
|
`repetir siempre`, de `endlos`, ja `ずっと`). Every reader still takes the English words. Where a word
|
|
@@ -1546,7 +1736,9 @@ _Synchronized version release. See git history for details._
|
|
|
1546
1736
|
- npm access token stored in GitHub Secrets
|
|
1547
1737
|
- 2FA recommended for npm organization
|
|
1548
1738
|
|
|
1549
|
-
[Unreleased]: https://github.com/codetalcott/hyperfixi/compare/v4.
|
|
1739
|
+
[Unreleased]: https://github.com/codetalcott/hyperfixi/compare/v4.6.0...HEAD
|
|
1740
|
+
[4.6.0]: https://github.com/codetalcott/hyperfixi/compare/v4.5.0...v4.6.0
|
|
1741
|
+
[4.5.0]: https://github.com/codetalcott/hyperfixi/compare/v4.4.0...v4.5.0
|
|
1550
1742
|
[4.4.0]: https://github.com/codetalcott/hyperfixi/compare/v4.3.0...v4.4.0
|
|
1551
1743
|
[4.3.0]: https://github.com/codetalcott/hyperfixi/compare/v4.2.0...v4.3.0
|
|
1552
1744
|
[4.2.0]: https://github.com/codetalcott/hyperfixi/compare/v4.1.0...v4.2.0
|
package/dist/api/create-dsl.d.ts
CHANGED
|
@@ -144,6 +144,8 @@ export interface ValidationResult {
|
|
|
144
144
|
readonly valid: boolean;
|
|
145
145
|
readonly node?: SemanticNode;
|
|
146
146
|
readonly errors?: string[];
|
|
147
|
+
/** Set when the input was refused for a known reason: `'unread-input'` (`UnreadInputError`). */
|
|
148
|
+
readonly errorCode?: string;
|
|
147
149
|
}
|
|
148
150
|
/**
|
|
149
151
|
* Compilation result.
|
|
@@ -152,12 +154,50 @@ export interface CompileResult {
|
|
|
152
154
|
readonly ok: boolean;
|
|
153
155
|
readonly code?: string;
|
|
154
156
|
readonly errors?: string[];
|
|
157
|
+
/** Set when the input was refused for a known reason: `'unread-input'` (`UnreadInputError`). */
|
|
158
|
+
readonly errorCode?: string;
|
|
155
159
|
readonly node?: SemanticNode;
|
|
156
160
|
readonly metadata?: {
|
|
157
161
|
readonly parser: string;
|
|
158
162
|
readonly confidence: number;
|
|
159
163
|
};
|
|
160
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* Thrown by `parse` (and so `compile`, `validate`, `translate`) when the input reads as a command
|
|
167
|
+
* only by leaving some of it unread: `select name from users banana` is not `select name from users`.
|
|
168
|
+
* `reading` is what the longest such match read, `unread` the text after it.
|
|
169
|
+
*/
|
|
170
|
+
export declare class UnreadInputError extends Error {
|
|
171
|
+
readonly input: string;
|
|
172
|
+
readonly language: string;
|
|
173
|
+
readonly reading: SemanticNode;
|
|
174
|
+
readonly unread: string;
|
|
175
|
+
readonly code = "unread-input";
|
|
176
|
+
constructor(input: string, language: string, reading: SemanticNode, unread: string);
|
|
177
|
+
}
|
|
178
|
+
/** Options for `translate`. */
|
|
179
|
+
export interface TranslateOptions {
|
|
180
|
+
/**
|
|
181
|
+
* `'allow'` returns a translation that does not read back as the source instead of throwing
|
|
182
|
+
* `TranslationReadBackError`, as semantic's `translate` does with the same option.
|
|
183
|
+
*/
|
|
184
|
+
readonly lossy?: 'allow' | 'refuse';
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Thrown by `translate` when its output, read in the target language, is not the source command:
|
|
188
|
+
* it does not read at all, or reads as another command, or with a role lost or changed. `partial` is
|
|
189
|
+
* what `translate` would have returned; `reading` what it reads as (null when it does not read).
|
|
190
|
+
*/
|
|
191
|
+
export declare class TranslationReadBackError extends Error {
|
|
192
|
+
readonly partial: string;
|
|
193
|
+
readonly from: string;
|
|
194
|
+
readonly to: string;
|
|
195
|
+
readonly source: SemanticNode;
|
|
196
|
+
readonly reading: SemanticNode | null;
|
|
197
|
+
readonly why: string;
|
|
198
|
+
readonly code = "translation-does-not-read-back";
|
|
199
|
+
constructor(partial: string, from: string, to: string, source: SemanticNode, reading: SemanticNode | null, why: string);
|
|
200
|
+
}
|
|
161
201
|
/**
|
|
162
202
|
* Main multilingual DSL interface.
|
|
163
203
|
*/
|
|
@@ -169,7 +209,12 @@ export interface MultilingualDSL {
|
|
|
169
209
|
};
|
|
170
210
|
validate(input: string, language: string): ValidationResult;
|
|
171
211
|
compile(input: string, language: string): CompileResult;
|
|
172
|
-
|
|
212
|
+
/**
|
|
213
|
+
* Parse in one language, render in another. The output must read back as the source command
|
|
214
|
+
* (the same action and role values, or the same compiled code); when it does not,
|
|
215
|
+
* `TranslationReadBackError`, unless `{ lossy: 'allow' }`.
|
|
216
|
+
*/
|
|
217
|
+
translate(input: string, fromLanguage: string, toLanguage: string, options?: TranslateOptions): string;
|
|
173
218
|
/**
|
|
174
219
|
* Render a parsed node back to natural language.
|
|
175
220
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-dsl.d.ts","sourceRoot":"","sources":["../../src/api/create-dsl.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"create-dsl.d.ts","sourceRoot":"","sources":["../../src/api/create-dsl.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,iBAAiB,EACjB,eAAe,EAEhB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE/C,OAAO,EAAmB,KAAK,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAClG,OAAO,EAAwB,KAAK,cAAc,EAAE,MAAM,wB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AAY,EACpB,OAAO,EAAE,YAAY,GAAG,IAAI,EAC5B,GAAG,EAAE,MAAM;CAKvB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAE9B,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,YAAY,CAAC;IACrD,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG;QAAE,IAAI,EAAE,YAAY,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;IAGjG,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,gBAAgB,CAAC;IAG5D,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,aAAa,CAAC;IAGxD;;;;OAIG;IACH,SAAS,CACP,KAAK,EAAE,MAAM,EACb,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,gBAAgB,GACzB,MAAM,CAAC;IAEV;;;;;;;OAOG;IACH,MAAM,CAAC,CAAC,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAG7D,qBAAqB,IAAI,MAAM,EAAE,CAAC;CACnC;AAwgBD,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,SAAS,GAAG,eAAe,CAqBxE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"domain-registry.d.ts","sourceRoot":"","sources":["../../src/api/domain-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAmC,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"domain-registry.d.ts","sourceRoot":"","sources":["../../src/api/domain-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAA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/api/index.js
CHANGED
|
@@ -1723,7 +1723,53 @@ import {
|
|
|
1723
1723
|
// src/ir/explicit-renderer.ts
|
|
1724
1724
|
import { renderExplicit, renderDocument } from "@lokascript/intent";
|
|
1725
1725
|
|
|
1726
|
+
// src/api/reading.ts
|
|
1727
|
+
function roleValues(node) {
|
|
1728
|
+
const out = /* @__PURE__ */ new Map();
|
|
1729
|
+
for (const [role, value] of node.roles) {
|
|
1730
|
+
const v = value;
|
|
1731
|
+
out.set(role, String(v?.value ?? v?.raw ?? value));
|
|
1732
|
+
}
|
|
1733
|
+
return out;
|
|
1734
|
+
}
|
|
1735
|
+
function readingDifference(source, back) {
|
|
1736
|
+
if (back.action !== source.action) return `reads as ${back.action}`;
|
|
1737
|
+
const want = roleValues(source);
|
|
1738
|
+
const got = roleValues(back);
|
|
1739
|
+
const parts = [];
|
|
1740
|
+
for (const [role, value] of want) {
|
|
1741
|
+
if (!got.has(role)) parts.push(`${role} lost`);
|
|
1742
|
+
else if (got.get(role) !== value) parts.push(`${role}: ${value} \u2192 ${got.get(role)}`);
|
|
1743
|
+
}
|
|
1744
|
+
for (const role of got.keys()) if (!want.has(role)) parts.push(`${role} added`);
|
|
1745
|
+
return parts.join(", ");
|
|
1746
|
+
}
|
|
1747
|
+
|
|
1726
1748
|
// src/api/create-dsl.ts
|
|
1749
|
+
var UnreadInputError = class extends Error {
|
|
1750
|
+
constructor(input, language, reading, unread) {
|
|
1751
|
+
super(`"${input}" (${language}) reads as ${reading.action} only by leaving "${unread}" unread`);
|
|
1752
|
+
this.input = input;
|
|
1753
|
+
this.language = language;
|
|
1754
|
+
this.reading = reading;
|
|
1755
|
+
this.unread = unread;
|
|
1756
|
+
this.code = "unread-input";
|
|
1757
|
+
this.name = "UnreadInputError";
|
|
1758
|
+
}
|
|
1759
|
+
};
|
|
1760
|
+
var TranslationReadBackError = class extends Error {
|
|
1761
|
+
constructor(partial, from, to, source, reading, why) {
|
|
1762
|
+
super(`translation ${from} \u2192 ${to} does not read back as the source (${why}): "${partial}"`);
|
|
1763
|
+
this.partial = partial;
|
|
1764
|
+
this.from = from;
|
|
1765
|
+
this.to = to;
|
|
1766
|
+
this.source = source;
|
|
1767
|
+
this.reading = reading;
|
|
1768
|
+
this.why = why;
|
|
1769
|
+
this.code = "translation-does-not-read-back";
|
|
1770
|
+
this.name = "TranslationReadBackError";
|
|
1771
|
+
}
|
|
1772
|
+
};
|
|
1727
1773
|
var DSLRegistry = class {
|
|
1728
1774
|
/**
|
|
1729
1775
|
* @param partiallyTranslatedActions Actions permitted to lack a keyword in
|
|
@@ -1808,25 +1854,50 @@ var MultilingualDSLImpl = class {
|
|
|
1808
1854
|
const profile = {
|
|
1809
1855
|
code: language
|
|
1810
1856
|
};
|
|
1857
|
+
const total = tokens.tokens.length;
|
|
1858
|
+
let best = null;
|
|
1859
|
+
let longestPartial = null;
|
|
1811
1860
|
for (const pattern of patterns) {
|
|
1861
|
+
const mark = tokens.mark();
|
|
1812
1862
|
const match = this.matcher.matchPattern(tokens, pattern, profile);
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
sourceLanguage: language,
|
|
1820
|
-
sourceText: input,
|
|
1821
|
-
patternId: pattern.id,
|
|
1822
|
-
confidence: match.confidence
|
|
1823
|
-
}
|
|
1824
|
-
};
|
|
1825
|
-
return { node, confidence: match.confidence };
|
|
1863
|
+
tokens.reset(mark);
|
|
1864
|
+
if (!match) continue;
|
|
1865
|
+
if (match.consumedTokens < total) {
|
|
1866
|
+
if (!longestPartial || match.consumedTokens > longestPartial.consumedTokens)
|
|
1867
|
+
longestPartial = match;
|
|
1868
|
+
continue;
|
|
1826
1869
|
}
|
|
1870
|
+
if (!best || match.pattern.priority > best.pattern.priority || match.pattern.priority === best.pattern.priority && match.confidence > best.confidence + 1e-3)
|
|
1871
|
+
best = match;
|
|
1872
|
+
}
|
|
1873
|
+
if (best) {
|
|
1874
|
+
const node = this.nodeOf(best, input, language);
|
|
1875
|
+
return { node, confidence: best.confidence };
|
|
1876
|
+
}
|
|
1877
|
+
if (longestPartial) {
|
|
1878
|
+
const unread = tokens.tokens.slice(longestPartial.consumedTokens).map((t) => t.value).join(" ");
|
|
1879
|
+
throw new UnreadInputError(
|
|
1880
|
+
input,
|
|
1881
|
+
language,
|
|
1882
|
+
this.nodeOf(longestPartial, input, language),
|
|
1883
|
+
unread
|
|
1884
|
+
);
|
|
1827
1885
|
}
|
|
1828
1886
|
throw new Error(`No pattern matched for input: ${input}`);
|
|
1829
1887
|
}
|
|
1888
|
+
nodeOf(match, input, language) {
|
|
1889
|
+
return {
|
|
1890
|
+
kind: "command",
|
|
1891
|
+
action: match.pattern.command,
|
|
1892
|
+
roles: match.captured,
|
|
1893
|
+
metadata: {
|
|
1894
|
+
sourceLanguage: language,
|
|
1895
|
+
sourceText: input,
|
|
1896
|
+
patternId: match.pattern.id,
|
|
1897
|
+
confidence: match.confidence
|
|
1898
|
+
}
|
|
1899
|
+
};
|
|
1900
|
+
}
|
|
1830
1901
|
validate(input, language) {
|
|
1831
1902
|
try {
|
|
1832
1903
|
const result = this.parseWithConfidence(input, language);
|
|
@@ -1837,11 +1908,12 @@ var MultilingualDSLImpl = class {
|
|
|
1837
1908
|
} catch (error) {
|
|
1838
1909
|
return {
|
|
1839
1910
|
valid: false,
|
|
1840
|
-
errors: [error instanceof Error ? error.message : String(error)]
|
|
1911
|
+
errors: [error instanceof Error ? error.message : String(error)],
|
|
1912
|
+
...error instanceof UnreadInputError ? { errorCode: error.code } : {}
|
|
1841
1913
|
};
|
|
1842
1914
|
}
|
|
1843
1915
|
}
|
|
1844
|
-
translate(input, fromLanguage, toLanguage) {
|
|
1916
|
+
translate(input, fromLanguage, toLanguage, options) {
|
|
1845
1917
|
if (isExplicitSyntax(input)) return input;
|
|
1846
1918
|
let node;
|
|
1847
1919
|
try {
|
|
@@ -1853,14 +1925,46 @@ var MultilingualDSLImpl = class {
|
|
|
1853
1925
|
throw parseError;
|
|
1854
1926
|
}
|
|
1855
1927
|
const rendered = this.registry.getSupportedLanguages().includes(toLanguage) ? this.render(node, toLanguage) : null;
|
|
1856
|
-
if (rendered != null) return rendered;
|
|
1928
|
+
if (rendered != null) return this.readsBack(rendered, node, fromLanguage, toLanguage, options);
|
|
1857
1929
|
if (this.hasGrammarProfile(fromLanguage) && this.hasGrammarProfile(toLanguage)) {
|
|
1858
|
-
return this.
|
|
1930
|
+
return this.readsBack(
|
|
1931
|
+
this.transformer.transform(input, fromLanguage, toLanguage),
|
|
1932
|
+
node,
|
|
1933
|
+
fromLanguage,
|
|
1934
|
+
toLanguage,
|
|
1935
|
+
options
|
|
1936
|
+
);
|
|
1859
1937
|
}
|
|
1860
1938
|
throw new Error(
|
|
1861
1939
|
`translate() could not render action "${node.action}" in language "${toLanguage}": no custom renderer, domain renderer, or schema pattern covers it, and no grammar profile is configured for the transformer fallback. Either add "${toLanguage}" to the DSL's languages/renderer, or set 'grammarProfile' on its LanguageConfig in createMultilingualDSL() (parse/validate/compile do not need it).`
|
|
1862
1940
|
);
|
|
1863
1941
|
}
|
|
1942
|
+
/**
|
|
1943
|
+
* `rendered`, read in `to`, must be `source`: the same action and role values, or, when the DSL
|
|
1944
|
+
* compiles, the same code (a parser may keep a translated word its generator normalizes: bdd ja
|
|
1945
|
+
* `表示` is `visible`). The rule is the domain gate's (lokascript-domains). A translation used to be
|
|
1946
|
+
* returned whatever it read as: ja/ko bdd `select` dropped its value, and nothing said so.
|
|
1947
|
+
*/
|
|
1948
|
+
readsBack(rendered, source, from, to, options) {
|
|
1949
|
+
if (options?.lossy === "allow") return rendered;
|
|
1950
|
+
let back;
|
|
1951
|
+
try {
|
|
1952
|
+
back = this.parseWithConfidence(rendered, to).node;
|
|
1953
|
+
} catch (error) {
|
|
1954
|
+
const why = error instanceof Error ? error.message : String(error);
|
|
1955
|
+
throw new TranslationReadBackError(rendered, from, to, source, null, why);
|
|
1956
|
+
}
|
|
1957
|
+
const difference = readingDifference(source, back);
|
|
1958
|
+
if (!difference) return rendered;
|
|
1959
|
+
if (this.codeGenerator) {
|
|
1960
|
+
try {
|
|
1961
|
+
if (this.codeGenerator.generate(back) === this.codeGenerator.generate(source))
|
|
1962
|
+
return rendered;
|
|
1963
|
+
} catch {
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1966
|
+
throw new TranslationReadBackError(rendered, from, to, source, back, difference);
|
|
1967
|
+
}
|
|
1864
1968
|
hasGrammarProfile(language) {
|
|
1865
1969
|
return this.profileProvider.getProfile(language) != null;
|
|
1866
1970
|
}
|
|
@@ -1886,7 +1990,8 @@ var MultilingualDSLImpl = class {
|
|
|
1886
1990
|
} catch (error) {
|
|
1887
1991
|
return {
|
|
1888
1992
|
ok: false,
|
|
1889
|
-
errors: [error instanceof Error ? error.message : String(error)]
|
|
1993
|
+
errors: [error instanceof Error ? error.message : String(error)],
|
|
1994
|
+
...error instanceof UnreadInputError ? { errorCode: error.code } : {}
|
|
1890
1995
|
};
|
|
1891
1996
|
}
|
|
1892
1997
|
}
|
|
@@ -2804,6 +2909,8 @@ var DomainRegistry = class {
|
|
|
2804
2909
|
return jsonResponse({ error: `Unknown operation: ${parsed.operation}` }, true);
|
|
2805
2910
|
}
|
|
2806
2911
|
} catch (error) {
|
|
2912
|
+
if (error instanceof UnreadInputError) return unreadInputResponse(error);
|
|
2913
|
+
if (error instanceof TranslationReadBackError) return readBackResponse(error);
|
|
2807
2914
|
const message = error instanceof Error ? error.message : String(error);
|
|
2808
2915
|
return jsonResponse({ error: `${descriptor.name} tool error: ${message}` }, true);
|
|
2809
2916
|
}
|
|
@@ -2929,6 +3036,7 @@ var DomainRegistry = class {
|
|
|
2929
3036
|
ok: result.ok,
|
|
2930
3037
|
code: result.code,
|
|
2931
3038
|
errors: result.errors,
|
|
3039
|
+
...result.errorCode === "unread-input" ? { diagnostics: [UNREAD_INPUT(result.errors)] } : {},
|
|
2932
3040
|
language,
|
|
2933
3041
|
input
|
|
2934
3042
|
});
|
|
@@ -2941,6 +3049,7 @@ var DomainRegistry = class {
|
|
|
2941
3049
|
return jsonResponse({
|
|
2942
3050
|
valid: result.valid,
|
|
2943
3051
|
errors: result.errors,
|
|
3052
|
+
...result.errorCode === "unread-input" ? { diagnostics: [UNREAD_INPUT(result.errors)] } : {},
|
|
2944
3053
|
language,
|
|
2945
3054
|
[descriptor.inputLabel]: input
|
|
2946
3055
|
});
|
|
@@ -2971,7 +3080,24 @@ var DomainRegistry = class {
|
|
|
2971
3080
|
for (const [key, value] of node.roles) {
|
|
2972
3081
|
roles[key] = value;
|
|
2973
3082
|
}
|
|
3083
|
+
if (rendered != null) {
|
|
3084
|
+
let back = null;
|
|
3085
|
+
let why = "";
|
|
3086
|
+
try {
|
|
3087
|
+
back = dsl.parse(rendered, to);
|
|
3088
|
+
why = readingDifference(node, back);
|
|
3089
|
+
if (why && compiled.ok) {
|
|
3090
|
+
const again = dsl.compile(rendered, to);
|
|
3091
|
+
if (again.ok && again.code === compiled.code) why = "";
|
|
3092
|
+
}
|
|
3093
|
+
} catch (error) {
|
|
3094
|
+
why = error instanceof Error ? error.message : String(error);
|
|
3095
|
+
}
|
|
3096
|
+
if (why)
|
|
3097
|
+
return readBackResponse(new TranslationReadBackError(rendered, from, to, node, back, why));
|
|
3098
|
+
}
|
|
2974
3099
|
return jsonResponse({
|
|
3100
|
+
ok: true,
|
|
2975
3101
|
input: { [descriptor.inputLabel]: input, language: from },
|
|
2976
3102
|
...rendered != null && { rendered: { text: rendered, language: to } },
|
|
2977
3103
|
semantic: { action: node.action, roles },
|
|
@@ -3051,7 +3177,7 @@ function generateToolDefinitions(desc) {
|
|
|
3051
3177
|
case "translate":
|
|
3052
3178
|
tools.push({
|
|
3053
3179
|
name: `translate_${desc.name}`,
|
|
3054
|
-
description: `Translate ${desc.description} input between natural languages (requires 'from' and 'to' codes). Supports: ${langList}.`,
|
|
3180
|
+
description: `Translate ${desc.description} input between natural languages (requires 'from' and 'to' codes). Supports: ${langList}. A rendering that does not read back as the source is REFUSED: ok is false, the diagnostic is TRANSLATION_DOES_NOT_READ_BACK, and its text is under \`partial\`, never \`rendered\`: do not present it as the translation. Input left unread is refused as UNREAD_INPUT.`,
|
|
3055
3181
|
inputSchema: {
|
|
3056
3182
|
type: "object",
|
|
3057
3183
|
properties: {
|
|
@@ -3085,6 +3211,46 @@ function getString(args, name, defaultValue = "") {
|
|
|
3085
3211
|
const value = args[name];
|
|
3086
3212
|
return typeof value === "string" ? value : defaultValue;
|
|
3087
3213
|
}
|
|
3214
|
+
function readingOf(node) {
|
|
3215
|
+
const roles = {};
|
|
3216
|
+
for (const [key, value] of node.roles) roles[key] = value;
|
|
3217
|
+
return { action: node.action, roles };
|
|
3218
|
+
}
|
|
3219
|
+
var UNREAD_INPUT = (errors) => ({
|
|
3220
|
+
severity: "error",
|
|
3221
|
+
code: "UNREAD_INPUT",
|
|
3222
|
+
message: errors?.[0] ?? "part of the input was not read",
|
|
3223
|
+
suggestion: "Part of the input belongs to no role of the command it reads as: remove it, or quote a value of several words."
|
|
3224
|
+
});
|
|
3225
|
+
function unreadInputResponse(error) {
|
|
3226
|
+
return jsonResponse(
|
|
3227
|
+
{
|
|
3228
|
+
ok: false,
|
|
3229
|
+
unread: error.unread,
|
|
3230
|
+
reading: readingOf(error.reading),
|
|
3231
|
+
diagnostics: [UNREAD_INPUT([error.message])]
|
|
3232
|
+
},
|
|
3233
|
+
true
|
|
3234
|
+
);
|
|
3235
|
+
}
|
|
3236
|
+
function readBackResponse(error) {
|
|
3237
|
+
return jsonResponse(
|
|
3238
|
+
{
|
|
3239
|
+
ok: false,
|
|
3240
|
+
partial: error.partial,
|
|
3241
|
+
...error.reading ? { reading: readingOf(error.reading) } : {},
|
|
3242
|
+
diagnostics: [
|
|
3243
|
+
{
|
|
3244
|
+
severity: "error",
|
|
3245
|
+
code: "TRANSLATION_DOES_NOT_READ_BACK",
|
|
3246
|
+
message: error.message,
|
|
3247
|
+
suggestion: "The rendering would not mean the source in the target language: do not present `partial` as the translation."
|
|
3248
|
+
}
|
|
3249
|
+
]
|
|
3250
|
+
},
|
|
3251
|
+
true
|
|
3252
|
+
);
|
|
3253
|
+
}
|
|
3088
3254
|
function jsonResponse(data, isError) {
|
|
3089
3255
|
return {
|
|
3090
3256
|
content: [{ type: "text", text: JSON.stringify(data, null, 2) }],
|
|
@@ -3237,6 +3403,8 @@ var CrossDomainDispatcher = class {
|
|
|
3237
3403
|
export {
|
|
3238
3404
|
CrossDomainDispatcher,
|
|
3239
3405
|
DomainRegistry,
|
|
3406
|
+
TranslationReadBackError,
|
|
3407
|
+
UnreadInputError,
|
|
3240
3408
|
createMultilingualDSL
|
|
3241
3409
|
};
|
|
3242
3410
|
//# sourceMappingURL=index.js.map
|