@try-works/tool-mode-runtime-litert 0.0.0-stage → 0.1.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/ear-frontend.d.ts +113 -0
- package/lib/ear-frontend.d.ts.map +1 -0
- package/lib/ear-frontend.js +258 -0
- package/lib/ear.d.ts +51 -0
- package/lib/ear.d.ts.map +1 -0
- package/lib/ear.js +296 -0
- package/lib/emo-tokenizer.d.ts +87 -0
- package/lib/emo-tokenizer.d.ts.map +1 -0
- package/lib/emo-tokenizer.js +365 -0
- package/lib/emo.d.ts +53 -0
- package/lib/emo.d.ts.map +1 -0
- package/lib/emo.js +218 -0
- package/lib/errors.d.ts +14 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +29 -0
- package/lib/index.d.ts +28 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +34 -0
- package/lib/model.d.ts +103 -0
- package/lib/model.d.ts.map +1 -0
- package/lib/model.js +112 -0
- package/lib/moderator.d.ts +59 -0
- package/lib/moderator.d.ts.map +1 -0
- package/lib/moderator.js +189 -0
- package/lib/pillow.d.ts +75 -0
- package/lib/pillow.d.ts.map +1 -0
- package/lib/pillow.js +187 -0
- package/lib/png.d.ts +27 -0
- package/lib/png.d.ts.map +1 -0
- package/lib/png.js +176 -0
- package/lib/processor.d.ts +43 -0
- package/lib/processor.d.ts.map +1 -0
- package/lib/processor.js +48 -0
- package/lib/provider-factory.d.ts +44 -0
- package/lib/provider-factory.d.ts.map +1 -0
- package/lib/provider-factory.js +219 -0
- package/lib/runtime.d.ts +41 -0
- package/lib/runtime.d.ts.map +1 -0
- package/lib/runtime.js +66 -0
- package/lib/shapes.d.ts +28 -0
- package/lib/shapes.d.ts.map +1 -0
- package/lib/shapes.js +187 -0
- package/lib/shim.d.ts +45 -0
- package/lib/shim.d.ts.map +1 -0
- package/lib/shim.js +215 -0
- package/lib/wav.d.ts +39 -0
- package/lib/wav.d.ts.map +1 -0
- package/lib/wav.js +134 -0
- package/package.json +47 -4
- package/README.md +0 -3
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The emo front end: the EMTK semantic tokenizer and the hashed n-gram featurizer.
|
|
3
|
+
*
|
|
4
|
+
* PRIMARY SOURCE (Desert-Ant-Labs/desert-ant-core @ baf4e6e3b4655c8e54aa8d5a25215b5f35f899a7):
|
|
5
|
+
* - Sources/Emo/Tokenizer.swift:5-13 FNV-1a (offset 0xCBF29CE484222325, prime 0x100000001B3)
|
|
6
|
+
* - Sources/Emo/Tokenizer.swift:15-43 NGram.encode: five bucket seeds, impSeed
|
|
7
|
+
* 0xFF51AFD7ED558CCD, bucket = h % nBuckets,
|
|
8
|
+
* sign from bit 63, importance = h(impSeed) % nImportance
|
|
9
|
+
* - Sources/Emo/Tokenizer.swift:45-96 per-script features: Latin w:/g:, Indic a:/k:,
|
|
10
|
+
* CJK c:/j:, SEA s:
|
|
11
|
+
* - Sources/Emo/Tokenizer.swift:98-110 NFKC + lowercase normalization and word runs
|
|
12
|
+
* - Sources/Emo/Tokenizer.swift:112-163 clusters, Jamo, category predicates
|
|
13
|
+
* - Sources/Emo/Tokenizer.swift:166-203 EMTK container: magic EMTK, offset 6, u32 unkID,
|
|
14
|
+
* u32 k, k float32 scores, k uint16 byte lengths, UTF-8
|
|
15
|
+
* pieces back to back, maxLen = min(maxScalars, 24)
|
|
16
|
+
* - Sources/Emo/Tokenizer.swift:205-242 Viterbi: window maxLen, strict-greater tie-break,
|
|
17
|
+
* unk fallback with the unk score
|
|
18
|
+
* - Sources/Emo/Tokenizer.swift:276-366 byte-exact vocabulary keys; duplicate byte pieces
|
|
19
|
+
* make the container malformed
|
|
20
|
+
*
|
|
21
|
+
* EQUIVALENCE RISK (recorded verbatim in the lock qualification): the Swift front end uses
|
|
22
|
+
* TextNormalization NFKC plus Swift Unicode category predicates; this port uses the JavaScript
|
|
23
|
+
* engine's NFKC/Unicode data. Arithmetic is pinned by independent Python FNV goldens and by our
|
|
24
|
+
* own tokenizer vectors, but Swift <-> JS NFKC equality and Viterbi tie-order equivalence are
|
|
25
|
+
* NOT independently proven (no ground-truth tokenizer vectors were available).
|
|
26
|
+
*/
|
|
27
|
+
/** FNV-1a 64-bit offset basis. */
|
|
28
|
+
export const EMO_OFFSET_BASIS = 0xcbf29ce484222325n;
|
|
29
|
+
/** FNV-1a 64-bit prime. */
|
|
30
|
+
export const EMO_PRIME = 0x100000001b3n;
|
|
31
|
+
const MASK64 = 0xffffffffffffffffn;
|
|
32
|
+
/** The five bucket seeds (Tokenizer.swift:38-41). */
|
|
33
|
+
export const EMO_BUCKET_SEEDS = [
|
|
34
|
+
0x9e3779b97f4a7c15n,
|
|
35
|
+
0xc2b2ae3d27d4eb4fn,
|
|
36
|
+
0x165667b19e3779f9n,
|
|
37
|
+
0x27d4eb2f165667c5n,
|
|
38
|
+
0x85ebca77c2b2ae63n,
|
|
39
|
+
];
|
|
40
|
+
/** The importance seed (Tokenizer.swift:42). */
|
|
41
|
+
export const EMO_IMPORTANCE_SEED = 0xff51afd7ed558ccdn;
|
|
42
|
+
/** The Viterbi window cap (Tokenizer.swift:201). */
|
|
43
|
+
export const EMO_MAX_TOKEN_SCALARS = 24;
|
|
44
|
+
const ENCODER = new TextEncoder();
|
|
45
|
+
/** FNV-1a over the UTF-8 bytes of a string (Tokenizer.swift:5-13). */
|
|
46
|
+
export function fnv64(text, seed) {
|
|
47
|
+
let hash = (EMO_OFFSET_BASIS ^ seed) & MASK64;
|
|
48
|
+
for (const byte of ENCODER.encode(text)) {
|
|
49
|
+
hash ^= BigInt(byte);
|
|
50
|
+
hash = (hash * EMO_PRIME) & MASK64;
|
|
51
|
+
}
|
|
52
|
+
return hash;
|
|
53
|
+
}
|
|
54
|
+
/** The longest piece in scalars, measured as non-continuation bytes (Tokenizer.swift:190-193). */
|
|
55
|
+
const scalarCount = (bytes) => {
|
|
56
|
+
let count = 0;
|
|
57
|
+
for (const byte of bytes)
|
|
58
|
+
if ((byte & 0xc0) !== 0x80)
|
|
59
|
+
count += 1;
|
|
60
|
+
return count;
|
|
61
|
+
};
|
|
62
|
+
const hexKey = (bytes) => Buffer.from(bytes).toString('hex');
|
|
63
|
+
const utf8Width = (codePoint) => codePoint < 0x80 ? 1 : codePoint < 0x800 ? 2 : codePoint < 0x10000 ? 3 : 4;
|
|
64
|
+
/**
|
|
65
|
+
* Parse the EMTK container (Tokenizer.swift:166-203).
|
|
66
|
+
*
|
|
67
|
+
* @param bytes - the whole emo_tokenizer.bin
|
|
68
|
+
* @returns the tokenizer
|
|
69
|
+
* @throws Error naming the malformed part
|
|
70
|
+
*/
|
|
71
|
+
export const parseEmtTokenizer = (bytes) => {
|
|
72
|
+
if (bytes.length < 14)
|
|
73
|
+
throw new Error('the EMTK tokenizer is truncated: shorter than its header');
|
|
74
|
+
const magic = String.fromCharCode(bytes[0] ?? 0, bytes[1] ?? 0, bytes[2] ?? 0, bytes[3] ?? 0);
|
|
75
|
+
if (magic !== 'EMTK')
|
|
76
|
+
throw new Error('the tokenizer is not an EMTK container: bad magic ' + JSON.stringify(magic));
|
|
77
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
78
|
+
const require = (offset, need, part) => {
|
|
79
|
+
if (offset + need > bytes.length)
|
|
80
|
+
throw new Error('the EMTK tokenizer is truncated in its ' + part);
|
|
81
|
+
};
|
|
82
|
+
let offset = 6;
|
|
83
|
+
require(offset, 8, 'unk/k header');
|
|
84
|
+
const unkID = view.getUint32(offset, true);
|
|
85
|
+
offset += 4;
|
|
86
|
+
const k = view.getUint32(offset, true);
|
|
87
|
+
offset += 4;
|
|
88
|
+
if (k === 0)
|
|
89
|
+
throw new Error('the EMTK tokenizer has no pieces');
|
|
90
|
+
if (unkID >= k)
|
|
91
|
+
throw new Error('the EMTK unk id ' + String(unkID) + ' is outside its ' + String(k) + '-piece vocabulary');
|
|
92
|
+
require(offset, k * 4, 'scores');
|
|
93
|
+
const scores = [];
|
|
94
|
+
for (let index = 0; index < k; index += 1) {
|
|
95
|
+
scores.push(view.getFloat32(offset, true));
|
|
96
|
+
offset += 4;
|
|
97
|
+
}
|
|
98
|
+
require(offset, k * 2, 'piece lengths');
|
|
99
|
+
const lengths = [];
|
|
100
|
+
for (let index = 0; index < k; index += 1) {
|
|
101
|
+
lengths.push(view.getUint16(offset, true));
|
|
102
|
+
offset += 2;
|
|
103
|
+
}
|
|
104
|
+
const vocabulary = new Map();
|
|
105
|
+
let maxScalars = 1;
|
|
106
|
+
for (let index = 0; index < k; index += 1) {
|
|
107
|
+
const length = lengths[index] ?? 0;
|
|
108
|
+
require(offset, length, 'pieces');
|
|
109
|
+
const piece = bytes.subarray(offset, offset + length);
|
|
110
|
+
offset += length;
|
|
111
|
+
const key = hexKey(piece);
|
|
112
|
+
if (vocabulary.has(key))
|
|
113
|
+
throw new Error('the EMTK tokenizer contains duplicate piece bytes at id ' + String(index));
|
|
114
|
+
vocabulary.set(key, index);
|
|
115
|
+
const scalars = scalarCount(piece);
|
|
116
|
+
if (scalars > maxScalars)
|
|
117
|
+
maxScalars = scalars;
|
|
118
|
+
}
|
|
119
|
+
const unkScore = scores[unkID] ?? 0;
|
|
120
|
+
const maxLen = Math.min(maxScalars, EMO_MAX_TOKEN_SCALARS);
|
|
121
|
+
const encode = (text) => {
|
|
122
|
+
const marker = '\u2581';
|
|
123
|
+
const lowered = text.toLowerCase().normalize('NFKC');
|
|
124
|
+
let normalized = marker;
|
|
125
|
+
for (const character of lowered)
|
|
126
|
+
normalized += character === ' ' ? marker : character;
|
|
127
|
+
const scalars = Array.from(normalized);
|
|
128
|
+
const n = scalars.length;
|
|
129
|
+
if (n === 0)
|
|
130
|
+
return [];
|
|
131
|
+
const utf8 = ENCODER.encode(normalized);
|
|
132
|
+
const span = new Array(n + 1);
|
|
133
|
+
span[0] = 0;
|
|
134
|
+
for (let index = 0; index < n; index += 1) {
|
|
135
|
+
const scalar = scalars[index] ?? '';
|
|
136
|
+
span[index + 1] = (span[index] ?? 0) + utf8Width(scalar.codePointAt(0) ?? 0);
|
|
137
|
+
}
|
|
138
|
+
const best = new Float64Array(n + 1);
|
|
139
|
+
best.fill(-1e18);
|
|
140
|
+
best[0] = 0;
|
|
141
|
+
const backPos = new Int32Array(n + 1);
|
|
142
|
+
backPos.fill(-1);
|
|
143
|
+
const backID = new Int32Array(n + 1);
|
|
144
|
+
backID.fill(-1);
|
|
145
|
+
for (let i = 1; i <= n; i += 1) {
|
|
146
|
+
const lo = Math.max(0, i - maxLen);
|
|
147
|
+
for (let j = lo; j < i; j += 1) {
|
|
148
|
+
const start = span[j] ?? 0;
|
|
149
|
+
const end = span[i] ?? start;
|
|
150
|
+
const id = vocabulary.get(hexKey(utf8.subarray(start, end)));
|
|
151
|
+
if (id === undefined)
|
|
152
|
+
continue;
|
|
153
|
+
const score = (best[j] ?? -1e18) + (scores[id] ?? 0);
|
|
154
|
+
if (score > (best[i] ?? -1e18)) {
|
|
155
|
+
best[i] = score;
|
|
156
|
+
backPos[i] = j;
|
|
157
|
+
backID[i] = id;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
const fallback = (best[i - 1] ?? -1e18) + unkScore;
|
|
161
|
+
if (fallback > (best[i] ?? -1e18)) {
|
|
162
|
+
best[i] = fallback;
|
|
163
|
+
backPos[i] = i - 1;
|
|
164
|
+
backID[i] = unkID;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const ids = [];
|
|
168
|
+
let position = n;
|
|
169
|
+
while (position > 0) {
|
|
170
|
+
const id = backID[position] ?? -1;
|
|
171
|
+
if (id < 0)
|
|
172
|
+
break;
|
|
173
|
+
ids.push(id);
|
|
174
|
+
position = backPos[position] ?? 0;
|
|
175
|
+
}
|
|
176
|
+
return ids.reverse();
|
|
177
|
+
};
|
|
178
|
+
return { vocabSize: k, unkID, scores, maxLen, encode };
|
|
179
|
+
};
|
|
180
|
+
/** Unicode White_Space (what Swift's isWhitespace covers for this purpose). */
|
|
181
|
+
const isWhitespace = (codePoint) => codePoint === 0x20
|
|
182
|
+
|| (codePoint >= 0x09 && codePoint <= 0x0d)
|
|
183
|
+
|| codePoint === 0x85
|
|
184
|
+
|| codePoint === 0xa0
|
|
185
|
+
|| codePoint === 0x1680
|
|
186
|
+
|| (codePoint >= 0x2000 && codePoint <= 0x200a)
|
|
187
|
+
|| codePoint === 0x2028
|
|
188
|
+
|| codePoint === 0x2029
|
|
189
|
+
|| codePoint === 0x202f
|
|
190
|
+
|| codePoint === 0x205f
|
|
191
|
+
|| codePoint === 0x3000;
|
|
192
|
+
const WORD = /[\p{L}\p{M}\p{N}]/u;
|
|
193
|
+
const MARK = /\p{M}/u;
|
|
194
|
+
const isWordScalar = (value) => WORD.test(value);
|
|
195
|
+
const isMark = (value) => MARK.test(value);
|
|
196
|
+
const isHangul = (codePoint) => codePoint >= 0xac00 && codePoint <= 0xd7a3;
|
|
197
|
+
const isSEA = (codePoint) => (codePoint >= 0x0e00 && codePoint <= 0x0eff)
|
|
198
|
+
|| (codePoint >= 0x1000 && codePoint <= 0x109f)
|
|
199
|
+
|| (codePoint >= 0x1780 && codePoint <= 0x17ff);
|
|
200
|
+
const isIndic = (codePoint) => codePoint >= 0x0900 && codePoint <= 0x0dff;
|
|
201
|
+
const isCJK = (codePoint) => (codePoint >= 0x4e00 && codePoint <= 0x9fff)
|
|
202
|
+
|| (codePoint >= 0x3400 && codePoint <= 0x4dbf)
|
|
203
|
+
|| (codePoint >= 0x2_0000 && codePoint <= 0x2_a6df)
|
|
204
|
+
|| (codePoint >= 0xf900 && codePoint <= 0xfaff)
|
|
205
|
+
|| (codePoint >= 0x3040 && codePoint <= 0x30ff)
|
|
206
|
+
|| (codePoint >= 0x31f0 && codePoint <= 0x31ff)
|
|
207
|
+
|| isHangul(codePoint);
|
|
208
|
+
/** NFKC then lowercase, with whitespace runs collapsed to one space (Tokenizer.swift:98-101). */
|
|
209
|
+
const normalizeForNgrams = (text) => {
|
|
210
|
+
const normalized = text.normalize('NFKC').toLowerCase();
|
|
211
|
+
const words = [];
|
|
212
|
+
let current = '';
|
|
213
|
+
for (const character of normalized) {
|
|
214
|
+
const codePoint = character.codePointAt(0) ?? 0;
|
|
215
|
+
if (isWhitespace(codePoint)) {
|
|
216
|
+
if (current.length > 0) {
|
|
217
|
+
words.push(current);
|
|
218
|
+
current = '';
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
current += character;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
if (current.length > 0)
|
|
226
|
+
words.push(current);
|
|
227
|
+
return words.join(' ');
|
|
228
|
+
};
|
|
229
|
+
/** Word runs: scalar sequences of letters, marks and numbers (Tokenizer.swift:103-110). */
|
|
230
|
+
const wordRuns = (text) => {
|
|
231
|
+
const runs = [];
|
|
232
|
+
let current = [];
|
|
233
|
+
for (const character of text) {
|
|
234
|
+
if (isWordScalar(character)) {
|
|
235
|
+
current.push(character);
|
|
236
|
+
}
|
|
237
|
+
else if (current.length > 0) {
|
|
238
|
+
runs.push(current);
|
|
239
|
+
current = [];
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
if (current.length > 0)
|
|
243
|
+
runs.push(current);
|
|
244
|
+
return runs;
|
|
245
|
+
};
|
|
246
|
+
const scalarsText = (characters) => {
|
|
247
|
+
let out = '';
|
|
248
|
+
for (const character of characters)
|
|
249
|
+
out += character;
|
|
250
|
+
return out;
|
|
251
|
+
};
|
|
252
|
+
const charGrams = (characters, lo, hi, tag) => {
|
|
253
|
+
const out = [];
|
|
254
|
+
for (let size = lo; size <= hi; size += 1) {
|
|
255
|
+
if (characters.length < size)
|
|
256
|
+
continue;
|
|
257
|
+
for (let index = 0; index <= characters.length - size; index += 1) {
|
|
258
|
+
out.push(tag + scalarsText(characters.slice(index, index + size)));
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return out;
|
|
262
|
+
};
|
|
263
|
+
const clusters = (characters) => {
|
|
264
|
+
const out = [];
|
|
265
|
+
let current = [];
|
|
266
|
+
for (const character of characters) {
|
|
267
|
+
if (current.length === 0) {
|
|
268
|
+
current = [character];
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
const previous = current[current.length - 1];
|
|
272
|
+
const value = previous?.codePointAt(0) ?? 0;
|
|
273
|
+
const virama = value >= 0x0900 && value <= 0x0dff && ((value & 0xff) === 0x4d || (value & 0xff) === 0xcd);
|
|
274
|
+
if (isMark(character) || virama)
|
|
275
|
+
current.push(character);
|
|
276
|
+
else {
|
|
277
|
+
out.push(current);
|
|
278
|
+
current = [character];
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
if (current.length > 0)
|
|
282
|
+
out.push(current);
|
|
283
|
+
return out;
|
|
284
|
+
};
|
|
285
|
+
const clusterGrams = (clusterList, lo, hi, tag) => {
|
|
286
|
+
const out = [];
|
|
287
|
+
for (let size = lo; size <= hi; size += 1) {
|
|
288
|
+
if (clusterList.length < size)
|
|
289
|
+
continue;
|
|
290
|
+
for (let index = 0; index <= clusterList.length - size; index += 1) {
|
|
291
|
+
out.push(tag + scalarsText(clusterList.slice(index, index + size).flat()));
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return out;
|
|
295
|
+
};
|
|
296
|
+
const jamo = (codePoint) => {
|
|
297
|
+
if (!isHangul(codePoint))
|
|
298
|
+
return [String.fromCodePoint(codePoint)];
|
|
299
|
+
const offset = codePoint - 0xac00;
|
|
300
|
+
const lead = String.fromCodePoint(0x1100 + Math.trunc(offset / 588));
|
|
301
|
+
const vowel = String.fromCodePoint(0x1161 + Math.trunc((offset % 588) / 28));
|
|
302
|
+
return offset % 28 === 0
|
|
303
|
+
? [lead, vowel]
|
|
304
|
+
: [lead, vowel, String.fromCodePoint(0x11a7 + (offset % 28))];
|
|
305
|
+
};
|
|
306
|
+
/**
|
|
307
|
+
* The ordered feature strings for one phrase (Tokenizer.swift:45-96).
|
|
308
|
+
*
|
|
309
|
+
* Latin runs emit w: + the word, then g: n-grams over <word> sizes 3..5; Indic runs emit a:,
|
|
310
|
+
* k: cluster unigrams and k: cluster bigrams/trigrams over <clusters>; CJK runs emit j: Jamo
|
|
311
|
+
* n-grams for Hangul plus c: scalar n-grams sizes 1..2; SEA runs emit s: scalar n-grams 2..4.
|
|
312
|
+
* Empty text produces the w:\u0000 sentinel.
|
|
313
|
+
*/
|
|
314
|
+
export const emoFeatureList = (text) => {
|
|
315
|
+
const features = [];
|
|
316
|
+
for (const run of wordRuns(normalizeForNgrams(text))) {
|
|
317
|
+
const codePoints = run.map((character) => character.codePointAt(0) ?? 0);
|
|
318
|
+
if (codePoints.some(isSEA)) {
|
|
319
|
+
features.push(...charGrams(run, 2, 4, 's:'));
|
|
320
|
+
}
|
|
321
|
+
else if (codePoints.some(isIndic)) {
|
|
322
|
+
const clusterList = clusters(run);
|
|
323
|
+
features.push('a:' + scalarsText(run));
|
|
324
|
+
features.push(...clusterGrams(clusterList, 1, 1, 'k:'));
|
|
325
|
+
features.push(...clusterGrams([['<'], ...clusterList, ['>']], 2, 3, 'k:'));
|
|
326
|
+
}
|
|
327
|
+
else if (codePoints.some(isCJK)) {
|
|
328
|
+
const extended = [];
|
|
329
|
+
for (const character of run) {
|
|
330
|
+
const codePoint = character.codePointAt(0) ?? 0;
|
|
331
|
+
if (isHangul(codePoint))
|
|
332
|
+
features.push(...charGrams(jamo(codePoint), 2, 4, 'j:'));
|
|
333
|
+
extended.push(character);
|
|
334
|
+
}
|
|
335
|
+
features.push(...charGrams(extended, 1, 2, 'c:'));
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
features.push('w:' + scalarsText(run));
|
|
339
|
+
features.push(...charGrams(['<', ...run, '>'], 3, 5, 'g:'));
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
return features.length === 0 ? ['w:\u0000'] : features;
|
|
343
|
+
};
|
|
344
|
+
/** Hash the feature list into the model's bucket/sign/importance arrays (Tokenizer.swift:15-36). */
|
|
345
|
+
export const encodeNgrams = (text, geometry) => {
|
|
346
|
+
const features = emoFeatureList(text).slice(0, geometry.maxFeatures);
|
|
347
|
+
const featureCount = features.length;
|
|
348
|
+
const buckets = new Int32Array(featureCount * geometry.nHashes);
|
|
349
|
+
const signs = new Float32Array(featureCount * geometry.nHashes);
|
|
350
|
+
const importance = new Int32Array(featureCount);
|
|
351
|
+
const bucketModulus = BigInt(Math.max(geometry.nBuckets, 1));
|
|
352
|
+
const importanceModulus = BigInt(Math.max(geometry.nImportance, 1));
|
|
353
|
+
for (let feature = 0; feature < featureCount; feature += 1) {
|
|
354
|
+
const value = features[feature] ?? '';
|
|
355
|
+
for (let hashIndex = 0; hashIndex < geometry.nHashes; hashIndex += 1) {
|
|
356
|
+
const seed = EMO_BUCKET_SEEDS[hashIndex] ?? 0n;
|
|
357
|
+
const hash = fnv64(value, seed);
|
|
358
|
+
buckets[feature * geometry.nHashes + hashIndex] = Number(hash % bucketModulus);
|
|
359
|
+
signs[feature * geometry.nHashes + hashIndex] = ((hash >> 63n) & 1n) === 1n ? 1 : -1;
|
|
360
|
+
}
|
|
361
|
+
importance[feature] = Number(fnv64(value, EMO_IMPORTANCE_SEED) % importanceModulus);
|
|
362
|
+
}
|
|
363
|
+
return { buckets, signs, importance, count: Math.max(featureCount, 1) };
|
|
364
|
+
};
|
|
365
|
+
//# sourceMappingURL=emo-tokenizer.js.map
|
package/lib/emo.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Processor emo/text-v1: on-device emoji suggestions over the emo LiteRT artifact.
|
|
3
|
+
*
|
|
4
|
+
* PRIMARY SOURCE (Desert-Ant-Labs/desert-ant-core @ baf4e6e3b4655c8e54aa8d5a25215b5f35f899a7):
|
|
5
|
+
* - Sources/Emo/Model.swift:19-30 label order, descending probability, limit
|
|
6
|
+
* - Sources/Emo/Model.swift:33-79 n-gram windows, sem ids/mask padding and the six tensor
|
|
7
|
+
* names/shapes feeding output "probabilities"
|
|
8
|
+
* - Sources/Emo/Model.swift:43-52 fmax feature window and the max(nf, 1) count
|
|
9
|
+
* - Sources/Emo/Model.swift:54-64 sem window; empty token list keeps one unmasked pad
|
|
10
|
+
* - Sources/Emo/EmoMeta.swift:7-35 meta fields and JSON key names
|
|
11
|
+
* - Sources/Emo/Emo.swift:109-120 trimmed input, limit semantics
|
|
12
|
+
* - Sources/Emo/Tokenizer.swift EMTK tokenizer + FNV n-gram featurizer (emo-tokenizer.ts)
|
|
13
|
+
* - .assets/emo/emo_meta.json labels 812, n_hashes 3, n_buckets 44000, n_importance 16000,
|
|
14
|
+
* sem_pad_index 48000, fmax 512, smax 64
|
|
15
|
+
*
|
|
16
|
+
* INPUT closed: { text: string, limit?: integer 1..20 }. text is bounded at 1024 Unicode code
|
|
17
|
+
* points (JSON Schema maxLength counts code points too); empty or whitespace-only text is
|
|
18
|
+
* refused as InvalidInput. OUTPUT exactly: { suggestions: [{emoji, confidence}], labels: 812 }.
|
|
19
|
+
* Emoji strings are read from emo_meta.json labels[index] and are never hardcoded; a meta whose
|
|
20
|
+
* label count or constants disagree with the pinned artifact is RuntimeUnavailable, as is a
|
|
21
|
+
* model probability vector whose length differs from the label count (never silently truncated).
|
|
22
|
+
*
|
|
23
|
+
* HONEST LIMITS: confidence is the model's raw softmax probability for that label, not a
|
|
24
|
+
* calibrated probability, and suggestions are hints rather than promises. The vendor describes
|
|
25
|
+
* coverage across 23 languages (Emo.swift:38-43); this tool does not return or verify a
|
|
26
|
+
* language and makes no per-language accuracy claim. v1 applies no skin-tone variant.
|
|
27
|
+
*/
|
|
28
|
+
import { type RecipeProcessor } from './processor.ts';
|
|
29
|
+
/** The processor id this module owns. */
|
|
30
|
+
export declare const EMO_PROCESSOR = "emo/text-v1";
|
|
31
|
+
/** The label count at the pinned revision. */
|
|
32
|
+
export declare const EMO_LABEL_COUNT = 812;
|
|
33
|
+
/** FNV hashes per n-gram feature. */
|
|
34
|
+
export declare const EMO_N_HASHES = 3;
|
|
35
|
+
/** N-gram hash-bucket table size. */
|
|
36
|
+
export declare const EMO_N_BUCKETS = 44000;
|
|
37
|
+
/** Importance-table size. */
|
|
38
|
+
export declare const EMO_N_IMPORTANCE = 16000;
|
|
39
|
+
/** The padding row appended to the semantic table. */
|
|
40
|
+
export declare const EMO_SEM_PAD_INDEX = 48000;
|
|
41
|
+
/** The fixed n-gram feature window. */
|
|
42
|
+
export declare const EMO_FMAX = 512;
|
|
43
|
+
/** The fixed semantic-token window. */
|
|
44
|
+
export declare const EMO_SMAX = 64;
|
|
45
|
+
/** Default suggestion count for the tool (the SDK default is 3; PHASE4 pins 5). */
|
|
46
|
+
export declare const EMO_DEFAULT_LIMIT = 5;
|
|
47
|
+
/** The largest suggestion count the tool accepts. */
|
|
48
|
+
export declare const EMO_MAX_LIMIT = 20;
|
|
49
|
+
/** The text bound, in Unicode code points. */
|
|
50
|
+
export declare const EMO_MAX_TEXT_CHARACTERS = 1024;
|
|
51
|
+
/** The emo processor. */
|
|
52
|
+
export declare const emoTextProcessor: RecipeProcessor;
|
|
53
|
+
//# sourceMappingURL=emo.d.ts.map
|
package/lib/emo.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emo.d.ts","sourceRoot":"","sources":["../src/emo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAYH,OAAO,EAAyC,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAG5F,yCAAyC;AACzC,eAAO,MAAM,aAAa,gBAAgB,CAAA;AAE1C,8CAA8C;AAC9C,eAAO,MAAM,eAAe,MAAM,CAAA;AAClC,qCAAqC;AACrC,eAAO,MAAM,YAAY,IAAI,CAAA;AAC7B,qCAAqC;AACrC,eAAO,MAAM,aAAa,QAAS,CAAA;AACnC,6BAA6B;AAC7B,eAAO,MAAM,gBAAgB,QAAS,CAAA;AACtC,sDAAsD;AACtD,eAAO,MAAM,iBAAiB,QAAS,CAAA;AACvC,uCAAuC;AACvC,eAAO,MAAM,QAAQ,MAAM,CAAA;AAC3B,uCAAuC;AACvC,eAAO,MAAM,QAAQ,KAAK,CAAA;AAC1B,mFAAmF;AACnF,eAAO,MAAM,iBAAiB,IAAI,CAAA;AAClC,qDAAqD;AACrD,eAAO,MAAM,aAAa,KAAK,CAAA;AAC/B,8CAA8C;AAC9C,eAAO,MAAM,uBAAuB,OAAO,CAAA;AA0I3C,yBAAyB;AACzB,eAAO,MAAM,gBAAgB,EAAE,eAiC9B,CAAA"}
|
package/lib/emo.js
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Processor emo/text-v1: on-device emoji suggestions over the emo LiteRT artifact.
|
|
3
|
+
*
|
|
4
|
+
* PRIMARY SOURCE (Desert-Ant-Labs/desert-ant-core @ baf4e6e3b4655c8e54aa8d5a25215b5f35f899a7):
|
|
5
|
+
* - Sources/Emo/Model.swift:19-30 label order, descending probability, limit
|
|
6
|
+
* - Sources/Emo/Model.swift:33-79 n-gram windows, sem ids/mask padding and the six tensor
|
|
7
|
+
* names/shapes feeding output "probabilities"
|
|
8
|
+
* - Sources/Emo/Model.swift:43-52 fmax feature window and the max(nf, 1) count
|
|
9
|
+
* - Sources/Emo/Model.swift:54-64 sem window; empty token list keeps one unmasked pad
|
|
10
|
+
* - Sources/Emo/EmoMeta.swift:7-35 meta fields and JSON key names
|
|
11
|
+
* - Sources/Emo/Emo.swift:109-120 trimmed input, limit semantics
|
|
12
|
+
* - Sources/Emo/Tokenizer.swift EMTK tokenizer + FNV n-gram featurizer (emo-tokenizer.ts)
|
|
13
|
+
* - .assets/emo/emo_meta.json labels 812, n_hashes 3, n_buckets 44000, n_importance 16000,
|
|
14
|
+
* sem_pad_index 48000, fmax 512, smax 64
|
|
15
|
+
*
|
|
16
|
+
* INPUT closed: { text: string, limit?: integer 1..20 }. text is bounded at 1024 Unicode code
|
|
17
|
+
* points (JSON Schema maxLength counts code points too); empty or whitespace-only text is
|
|
18
|
+
* refused as InvalidInput. OUTPUT exactly: { suggestions: [{emoji, confidence}], labels: 812 }.
|
|
19
|
+
* Emoji strings are read from emo_meta.json labels[index] and are never hardcoded; a meta whose
|
|
20
|
+
* label count or constants disagree with the pinned artifact is RuntimeUnavailable, as is a
|
|
21
|
+
* model probability vector whose length differs from the label count (never silently truncated).
|
|
22
|
+
*
|
|
23
|
+
* HONEST LIMITS: confidence is the model's raw softmax probability for that label, not a
|
|
24
|
+
* calibrated probability, and suggestions are hints rather than promises. The vendor describes
|
|
25
|
+
* coverage across 23 languages (Emo.swift:38-43); this tool does not return or verify a
|
|
26
|
+
* language and makes no per-language accuracy claim. v1 applies no skin-tone variant.
|
|
27
|
+
*/
|
|
28
|
+
import { readFile } from 'node:fs/promises';
|
|
29
|
+
import path from 'node:path';
|
|
30
|
+
import { Effect, Schema } from 'effect';
|
|
31
|
+
import { InferenceFailed, InvalidInput, RuntimeUnavailable } from '@try-works/tool-mode-runtime-core';
|
|
32
|
+
import { describeCause } from "./errors.js";
|
|
33
|
+
import { encodeNgrams, parseEmtTokenizer } from "./emo-tokenizer.js";
|
|
34
|
+
import { closedKeyFailure, inputCeilingFailure } from "./processor.js";
|
|
35
|
+
import { LitertSession } from "./runtime.js";
|
|
36
|
+
/** The processor id this module owns. */
|
|
37
|
+
export const EMO_PROCESSOR = 'emo/text-v1';
|
|
38
|
+
/** The label count at the pinned revision. */
|
|
39
|
+
export const EMO_LABEL_COUNT = 812;
|
|
40
|
+
/** FNV hashes per n-gram feature. */
|
|
41
|
+
export const EMO_N_HASHES = 3;
|
|
42
|
+
/** N-gram hash-bucket table size. */
|
|
43
|
+
export const EMO_N_BUCKETS = 44_000;
|
|
44
|
+
/** Importance-table size. */
|
|
45
|
+
export const EMO_N_IMPORTANCE = 16_000;
|
|
46
|
+
/** The padding row appended to the semantic table. */
|
|
47
|
+
export const EMO_SEM_PAD_INDEX = 48_000;
|
|
48
|
+
/** The fixed n-gram feature window. */
|
|
49
|
+
export const EMO_FMAX = 512;
|
|
50
|
+
/** The fixed semantic-token window. */
|
|
51
|
+
export const EMO_SMAX = 64;
|
|
52
|
+
/** Default suggestion count for the tool (the SDK default is 3; PHASE4 pins 5). */
|
|
53
|
+
export const EMO_DEFAULT_LIMIT = 5;
|
|
54
|
+
/** The largest suggestion count the tool accepts. */
|
|
55
|
+
export const EMO_MAX_LIMIT = 20;
|
|
56
|
+
/** The text bound, in Unicode code points. */
|
|
57
|
+
export const EMO_MAX_TEXT_CHARACTERS = 1024;
|
|
58
|
+
const OUTPUT_NAME = 'probabilities';
|
|
59
|
+
const INPUT_KEYS = new Set(['text', 'limit']);
|
|
60
|
+
const EmoMetaSchema = Schema.Struct({
|
|
61
|
+
labels: Schema.Array(Schema.NonEmptyString),
|
|
62
|
+
n_hashes: Schema.Finite,
|
|
63
|
+
n_buckets: Schema.Finite,
|
|
64
|
+
n_importance: Schema.Finite,
|
|
65
|
+
sem_pad_index: Schema.Finite,
|
|
66
|
+
fmax: Schema.Finite,
|
|
67
|
+
smax: Schema.Finite,
|
|
68
|
+
});
|
|
69
|
+
/** Read one JSON asset beside the model as a lossless JSON value. */
|
|
70
|
+
function readAssetJson(assetDirectory, name) {
|
|
71
|
+
return Effect.tryPromise({
|
|
72
|
+
try: async () => JSON.parse(await readFile(path.join(assetDirectory, name), 'utf8')),
|
|
73
|
+
catch: (cause) => new RuntimeUnavailable({ provider: 'litert', reason: 'the emo asset "' + name + '" cannot be read as JSON: ' + describeCause(cause) }),
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/** Read and validate the pinned meta. */
|
|
77
|
+
function loadMeta(assetDirectory) {
|
|
78
|
+
return Effect.flatMap(readAssetJson(assetDirectory, 'emo_meta.json'), (raw) => {
|
|
79
|
+
const decoded = Schema.decodeUnknownOption(EmoMetaSchema)(raw);
|
|
80
|
+
if (decoded._tag === 'None') {
|
|
81
|
+
return Effect.fail(new RuntimeUnavailable({ provider: 'litert', reason: 'the emo emo_meta.json is not the pinned document' }));
|
|
82
|
+
}
|
|
83
|
+
const meta = decoded.value;
|
|
84
|
+
const problems = [];
|
|
85
|
+
if (meta.labels.length !== EMO_LABEL_COUNT)
|
|
86
|
+
problems.push('labels must number ' + String(EMO_LABEL_COUNT) + ', not ' + String(meta.labels.length));
|
|
87
|
+
if (meta.n_hashes !== EMO_N_HASHES)
|
|
88
|
+
problems.push('n_hashes must be ' + String(EMO_N_HASHES));
|
|
89
|
+
if (meta.n_buckets !== EMO_N_BUCKETS)
|
|
90
|
+
problems.push('n_buckets must be ' + String(EMO_N_BUCKETS));
|
|
91
|
+
if (meta.n_importance !== EMO_N_IMPORTANCE)
|
|
92
|
+
problems.push('n_importance must be ' + String(EMO_N_IMPORTANCE));
|
|
93
|
+
if (meta.sem_pad_index !== EMO_SEM_PAD_INDEX)
|
|
94
|
+
problems.push('sem_pad_index must be ' + String(EMO_SEM_PAD_INDEX));
|
|
95
|
+
if (meta.fmax !== EMO_FMAX)
|
|
96
|
+
problems.push('fmax must be ' + String(EMO_FMAX));
|
|
97
|
+
if (meta.smax !== EMO_SMAX)
|
|
98
|
+
problems.push('smax must be ' + String(EMO_SMAX));
|
|
99
|
+
return problems.length > 0
|
|
100
|
+
? Effect.fail(new RuntimeUnavailable({ provider: 'litert', reason: 'emo_meta.json does not match the pinned artifact: ' + problems.join('; ') }))
|
|
101
|
+
: Effect.succeed(meta);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
/** Read and parse the EMTK tokenizer. */
|
|
105
|
+
function loadTokenizer(assetDirectory) {
|
|
106
|
+
return Effect.tryPromise({
|
|
107
|
+
try: async () => parseEmtTokenizer(new Uint8Array(await readFile(path.join(assetDirectory, 'emo_tokenizer.bin')))),
|
|
108
|
+
catch: (cause) => new RuntimeUnavailable({ provider: 'litert', reason: 'the emo tokenizer cannot be used: ' + describeCause(cause) }),
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/** Refuse one input before any tokenizer or engine work. */
|
|
112
|
+
function parseInput(input, maxInputBytes) {
|
|
113
|
+
const ceiling = inputCeilingFailure(input, { maxInputBytes, timeoutMs: 0 });
|
|
114
|
+
if (ceiling !== undefined)
|
|
115
|
+
return Effect.fail(ceiling);
|
|
116
|
+
const keys = closedKeyFailure(input, INPUT_KEYS, 'text and limit');
|
|
117
|
+
if (keys !== undefined)
|
|
118
|
+
return Effect.fail(keys);
|
|
119
|
+
const textValue = input['text'];
|
|
120
|
+
if (textValue === undefined)
|
|
121
|
+
return Effect.fail(new InvalidInput({ field: 'text', message: 'text is required' }));
|
|
122
|
+
if (!Schema.is(Schema.String)(textValue))
|
|
123
|
+
return Effect.fail(new InvalidInput({ field: 'text', message: 'text must be a string' }));
|
|
124
|
+
const codePoints = Array.from(textValue).length;
|
|
125
|
+
if (codePoints === 0)
|
|
126
|
+
return Effect.fail(new InvalidInput({ field: 'text', message: 'text must not be empty' }));
|
|
127
|
+
if (codePoints > EMO_MAX_TEXT_CHARACTERS) {
|
|
128
|
+
return Effect.fail(new InvalidInput({
|
|
129
|
+
field: 'text',
|
|
130
|
+
message: 'text must be at most ' + String(EMO_MAX_TEXT_CHARACTERS) + ' Unicode code points',
|
|
131
|
+
}));
|
|
132
|
+
}
|
|
133
|
+
const trimmed = textValue.trim();
|
|
134
|
+
if (trimmed.length === 0)
|
|
135
|
+
return Effect.fail(new InvalidInput({ field: 'text', message: 'text must not be empty or whitespace only' }));
|
|
136
|
+
const limitValue = input['limit'];
|
|
137
|
+
if (limitValue !== undefined) {
|
|
138
|
+
if (!Schema.is(Schema.Int)(limitValue) || limitValue < 1 || limitValue > EMO_MAX_LIMIT) {
|
|
139
|
+
return Effect.fail(new InvalidInput({
|
|
140
|
+
field: 'limit',
|
|
141
|
+
message: 'limit must be an integer between 1 and ' + String(EMO_MAX_LIMIT) + ', or omitted for the default of ' + String(EMO_DEFAULT_LIMIT),
|
|
142
|
+
}));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return Effect.succeed({ text: trimmed, limit: limitValue ?? EMO_DEFAULT_LIMIT });
|
|
146
|
+
}
|
|
147
|
+
/** The fixed-window feeds (Model.swift:38-74). */
|
|
148
|
+
function packFeeds(meta, tokenizer, text) {
|
|
149
|
+
const ngrams = encodeNgrams(text, {
|
|
150
|
+
nBuckets: meta.n_buckets,
|
|
151
|
+
nHashes: meta.n_hashes,
|
|
152
|
+
nImportance: meta.n_importance,
|
|
153
|
+
maxFeatures: meta.fmax,
|
|
154
|
+
});
|
|
155
|
+
const featureCount = ngrams.count;
|
|
156
|
+
const buckets = new Int32Array(meta.fmax * meta.n_hashes);
|
|
157
|
+
const signs = new Float32Array(meta.fmax * meta.n_hashes);
|
|
158
|
+
const importance = new Int32Array(meta.fmax);
|
|
159
|
+
buckets.set(ngrams.buckets, 0);
|
|
160
|
+
signs.set(ngrams.signs, 0);
|
|
161
|
+
importance.set(ngrams.importance, 0);
|
|
162
|
+
let ids = tokenizer.encode(text);
|
|
163
|
+
if (ids.length > meta.smax)
|
|
164
|
+
ids = ids.slice(0, meta.smax);
|
|
165
|
+
const semIDs = new Int32Array(meta.smax);
|
|
166
|
+
semIDs.fill(meta.sem_pad_index);
|
|
167
|
+
const semMask = new Float32Array(meta.smax);
|
|
168
|
+
if (ids.length === 0) {
|
|
169
|
+
semMask[0] = 1;
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
for (let index = 0; index < ids.length; index += 1) {
|
|
173
|
+
semIDs[index] = ids[index] ?? meta.sem_pad_index;
|
|
174
|
+
semMask[index] = 1;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
ngram_buckets: { data: buckets, dims: [1, meta.fmax, meta.n_hashes] },
|
|
179
|
+
ngram_signs: { data: signs, dims: [1, meta.fmax, meta.n_hashes] },
|
|
180
|
+
ngram_importance: { data: importance, dims: [1, meta.fmax] },
|
|
181
|
+
ngram_count: { data: Float32Array.from([Math.max(featureCount, 1)]), dims: [1, 1] },
|
|
182
|
+
sem_ids: { data: semIDs, dims: [1, meta.smax] },
|
|
183
|
+
sem_mask: { data: semMask, dims: [1, meta.smax] },
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
/** The emo processor. */
|
|
187
|
+
export const emoTextProcessor = {
|
|
188
|
+
id: EMO_PROCESSOR,
|
|
189
|
+
features: [EMO_PROCESSOR],
|
|
190
|
+
invoke: ({ input, limits, assetDirectory }) => Effect.gen(function* () {
|
|
191
|
+
const options = yield* parseInput(input, limits.maxInputBytes);
|
|
192
|
+
const meta = yield* loadMeta(assetDirectory);
|
|
193
|
+
const tokenizer = yield* loadTokenizer(assetDirectory);
|
|
194
|
+
const session = yield* LitertSession;
|
|
195
|
+
const raw = yield* session.run(packFeeds(meta, tokenizer, options.text));
|
|
196
|
+
const probabilities = raw[OUTPUT_NAME];
|
|
197
|
+
if (!(probabilities instanceof Float32Array) || probabilities.length !== meta.labels.length) {
|
|
198
|
+
return yield* Effect.fail(new RuntimeUnavailable({
|
|
199
|
+
provider: 'litert',
|
|
200
|
+
reason: 'the emo model returned ' + String(probabilities?.length ?? 'no') + ' probabilities for ' + String(meta.labels.length) + ' labels',
|
|
201
|
+
}));
|
|
202
|
+
}
|
|
203
|
+
return yield* Effect.try({
|
|
204
|
+
try: () => {
|
|
205
|
+
for (const value of probabilities) {
|
|
206
|
+
if (!Number.isFinite(value))
|
|
207
|
+
throw new Error('the emo model returned a non-finite probability');
|
|
208
|
+
}
|
|
209
|
+
const ranked = meta.labels.map((emoji, index) => ({ emoji, confidence: probabilities[index] ?? 0, index }));
|
|
210
|
+
ranked.sort((a, b) => b.confidence - a.confidence || a.index - b.index);
|
|
211
|
+
const suggestions = ranked.slice(0, options.limit).map((entry) => ({ emoji: entry.emoji, confidence: entry.confidence }));
|
|
212
|
+
return { suggestions, labels: meta.labels.length };
|
|
213
|
+
},
|
|
214
|
+
catch: (cause) => new InferenceFailed({ provider: 'litert', phase: 'post', message: describeCause(cause) }),
|
|
215
|
+
});
|
|
216
|
+
}),
|
|
217
|
+
};
|
|
218
|
+
//# sourceMappingURL=emo.js.map
|
package/lib/errors.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed runtime failures, re-exported from the shared contract package.
|
|
3
|
+
*
|
|
4
|
+
* `@try-works/tool-mode-runtime-core` owns the tagged-error classes for the whole runtime
|
|
5
|
+
* layer. This package imports the same class VALUES rather than redeclaring them, so an
|
|
6
|
+
* `instanceof` or `catchTag` in any consumer matches the error it saw — two structurally
|
|
7
|
+
* identical copies would not. `describeCause` stays local: it is a message helper, not part
|
|
8
|
+
* of the error protocol.
|
|
9
|
+
*/
|
|
10
|
+
import { InferenceFailed, RuntimeUnavailable } from '@try-works/tool-mode-runtime-core';
|
|
11
|
+
export { InferenceFailed, RuntimeUnavailable };
|
|
12
|
+
/** A short, always-defined description of an unknown thrown value. */
|
|
13
|
+
export declare const describeCause: (cause: unknown) => string;
|
|
14
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAA;AAEvF,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,CAAA;AAE9C,sEAAsE;AACtE,eAAO,MAAM,aAAa,GAAI,OAAO,OAAO,KAAG,MAU9C,CAAA"}
|