webml-kit 0.3.0 → 0.4.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/README.md +39 -0
- package/dist/cache.d.ts.map +1 -1
- package/dist/cache.js +17 -16
- package/dist/cache.js.map +1 -1
- package/dist/decision.d.ts +182 -0
- package/dist/decision.d.ts.map +1 -0
- package/dist/decision.js +789 -0
- package/dist/decision.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/inputs.d.ts.map +1 -1
- package/dist/inputs.js +40 -8
- package/dist/inputs.js.map +1 -1
- package/dist/loader.d.ts +14 -1
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +91 -1
- package/dist/loader.js.map +1 -1
- package/dist/onnx-pipeline.d.ts.map +1 -1
- package/dist/onnx-pipeline.js +94 -17
- package/dist/onnx-pipeline.js.map +1 -1
- package/dist/pipelines/index.d.ts.map +1 -1
- package/dist/pipelines/index.js +8 -2
- package/dist/pipelines/index.js.map +1 -1
- package/dist/shim-ort.d.ts +6 -0
- package/dist/shim-ort.d.ts.map +1 -0
- package/dist/shim-ort.js +38 -0
- package/dist/shim-ort.js.map +1 -0
- package/dist/types.d.ts +6 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/webml-kit.browser.js +2568 -0
- package/package.json +15 -3
package/README.md
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
> Framework-agnostic utilities for loading and running ML models in the browser via WebGPU/WASM.
|
|
8
8
|
|
|
9
|
+
**[Live Playground & Interactive Demos →](https://hemanth.github.io/webml-kit/)**
|
|
10
|
+
|
|
9
11
|
If you've ever built a browser-ML demo, you know the drill: copy 150 lines of Web Worker boilerplate from the last project, wire up `postMessage`, add progress reporting, handle the GPU vanishing mid-inference, and pray the model is cached so your user doesn't wait 3 minutes. Every. Single. Time.
|
|
10
12
|
|
|
11
13
|
This library does that part for you. It wraps [`@huggingface/transformers`](https://huggingface.co/docs/transformers.js) with a sane API and handles the ugly bits: device detection, model caching, token streaming, KV-cache management, and GPU recovery.
|
|
@@ -184,6 +186,43 @@ const asr = await webml('onnx-community/whisper-tiny.en'); // or any standalone
|
|
|
184
186
|
const { text } = await asr.transcribe(audioFloat32Array);
|
|
185
187
|
```
|
|
186
188
|
|
|
189
|
+
### Jev System One / OpenJev Decision Capabilities
|
|
190
|
+
|
|
191
|
+
Fast, calibrated, programmable decisions without autoregressive token generation. Turn natural language and application state into typed choices, binary verdicts (`noul`), or continuous level scores (`score`) with direct logit readouts:
|
|
192
|
+
|
|
193
|
+
```ts
|
|
194
|
+
import webml, { createDecisionEngine, directChoice } from 'webml-kit';
|
|
195
|
+
|
|
196
|
+
// One-shot direct choice
|
|
197
|
+
const result = await directChoice({
|
|
198
|
+
state: 'Customer reports: "My subscription charged twice, please refund immediately."',
|
|
199
|
+
question: 'Which department should handle this request?',
|
|
200
|
+
options: ['billing', 'technical-support', 'sales'],
|
|
201
|
+
});
|
|
202
|
+
console.log(result.choice); // 'billing'
|
|
203
|
+
console.log(result.confidence); // 0.88
|
|
204
|
+
console.log(result.probabilities); // { billing: 0.88, 'technical-support': 0.08, sales: 0.04 }
|
|
205
|
+
|
|
206
|
+
// Binary evaluation (Noul)
|
|
207
|
+
const engine = webml.decision({ model: 'qwen3-0.6b' });
|
|
208
|
+
const { noul, passed } = await engine.noul({
|
|
209
|
+
state: 'Production database cluster is reporting 500 errors',
|
|
210
|
+
statement: 'Is there an urgent incident?',
|
|
211
|
+
});
|
|
212
|
+
console.log(noul); // 0.94
|
|
213
|
+
console.log(passed); // true
|
|
214
|
+
|
|
215
|
+
// Continuous scoring along ordered criteria levels
|
|
216
|
+
const { score, confidence } = await engine.score({
|
|
217
|
+
state: 'There is a minor typo in the footer disclaimer.',
|
|
218
|
+
instructions: 'Rate issue severity',
|
|
219
|
+
criteria: ['P3', 'P2', 'P1', 'P0'],
|
|
220
|
+
});
|
|
221
|
+
console.log(score); // 0.15 (continuous score on 0-3 scale)
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
Supports OpenJev GGUF models (`minicpm5-2b`, `qwen3-0.6b`, `qwen3.5-4b`) via `@wllama/wllama` with WebGPU/WASM in browser and worker environments, with automatic, zero-dependency heuristic fallback for Node.js, offline, or test environments.
|
|
225
|
+
|
|
187
226
|
## API
|
|
188
227
|
|
|
189
228
|
### ModelClient
|
package/dist/cache.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAU5D;;;GAGG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,YAAY,CAAC,CAmB7D;AAED;;;;;;;;GAQG;AACH,wBAAsB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAoBhE;AAED;;GAEG;AACH,wBAAsB,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC,CASpD;AAED;;GAEG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC,CA0C/D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,UAAU,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA4BhE"}
|
package/dist/cache.js
CHANGED
|
@@ -6,8 +6,11 @@
|
|
|
6
6
|
* skip "downloading…" UX for returning users or clear storage on mobile.
|
|
7
7
|
*/
|
|
8
8
|
import { formatSize } from './device.js';
|
|
9
|
-
/**
|
|
10
|
-
const
|
|
9
|
+
/** Supported model cache name prefixes */
|
|
10
|
+
const CACHE_PREFIXES = ['transformers-cache', 'webml-kit'];
|
|
11
|
+
function isModelCache(name) {
|
|
12
|
+
return CACHE_PREFIXES.some(prefix => name.startsWith(prefix));
|
|
13
|
+
}
|
|
11
14
|
/**
|
|
12
15
|
* Detect which cache backend is available.
|
|
13
16
|
* Priority: Cache API → OPFS → IndexedDB
|
|
@@ -45,8 +48,8 @@ export async function isCached(modelId) {
|
|
|
45
48
|
return false;
|
|
46
49
|
try {
|
|
47
50
|
const keys = await caches.keys();
|
|
48
|
-
const
|
|
49
|
-
for (const cacheName of
|
|
51
|
+
const matchedCaches = keys.filter(k => isModelCache(k));
|
|
52
|
+
for (const cacheName of matchedCaches) {
|
|
50
53
|
const cache = await caches.open(cacheName);
|
|
51
54
|
const cacheKeys = await cache.keys();
|
|
52
55
|
const hasModel = cacheKeys.some(req => req.url.includes(encodeURIComponent(modelId)) || req.url.includes(modelId));
|
|
@@ -82,8 +85,8 @@ export async function listCachedModels() {
|
|
|
82
85
|
const models = [];
|
|
83
86
|
try {
|
|
84
87
|
const keys = await caches.keys();
|
|
85
|
-
const
|
|
86
|
-
for (const cacheName of
|
|
88
|
+
const matchedCaches = keys.filter(k => isModelCache(k));
|
|
89
|
+
for (const cacheName of matchedCaches) {
|
|
87
90
|
const cache = await caches.open(cacheName);
|
|
88
91
|
const cacheKeys = await cache.keys();
|
|
89
92
|
// Group by model ID (extract from URL pattern)
|
|
@@ -92,14 +95,12 @@ export async function listCachedModels() {
|
|
|
92
95
|
const url = request.url;
|
|
93
96
|
// HF URLs: https://huggingface.co/{org}/{model}/resolve/{rev}/{file}
|
|
94
97
|
const match = url.match(/huggingface\.co\/([^/]+\/[^/]+)\//);
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
modelUrls.set(id, (modelUrls.get(id) ?? 0) + size);
|
|
102
|
-
}
|
|
98
|
+
const id = match ? match[1] : (url.split('/').filter(Boolean).slice(-2).join('/') || url);
|
|
99
|
+
const response = await cache.match(request);
|
|
100
|
+
const size = response
|
|
101
|
+
? Number(response.headers.get('content-length') ?? 0)
|
|
102
|
+
: 0;
|
|
103
|
+
modelUrls.set(id, (modelUrls.get(id) ?? 0) + size);
|
|
103
104
|
}
|
|
104
105
|
for (const [modelId, sizeBytes] of modelUrls) {
|
|
105
106
|
models.push({
|
|
@@ -134,8 +135,8 @@ export async function clearCache(modelId) {
|
|
|
134
135
|
return;
|
|
135
136
|
try {
|
|
136
137
|
const keys = await caches.keys();
|
|
137
|
-
const
|
|
138
|
-
for (const cacheName of
|
|
138
|
+
const matchedCaches = keys.filter(k => isModelCache(k));
|
|
139
|
+
for (const cacheName of matchedCaches) {
|
|
139
140
|
if (!modelId) {
|
|
140
141
|
// Clear entire cache
|
|
141
142
|
await caches.delete(cacheName);
|
package/dist/cache.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,0CAA0C;AAC1C,MAAM,cAAc,GAAG,CAAC,oBAAoB,EAAE,WAAW,CAAC,CAAC;AAE3D,SAAS,YAAY,CAAC,IAAY;IAChC,OAAO,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;AAChE,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe;IACnC,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QA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,CAAC,CAAC,CAAC,CAAC;QAExD,KAAK,MAAM,SAAS,IAAI,aAAa,EAAE,CAAC;YACtC,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,qBAAqB;gBACrB,MAAM,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;YACjC,CAAC;iBAAM,CAAC;gBACN,uBAAuB;gBACvB,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;gBAC3C,MAAM,SAAS,GAAG,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC;gBACrC,KAAK,MAAM,OAAO,IAAI,SAAS,EAAE,CAAC;oBAChC,IACE,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;wBACjD,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,EAC7B,CAAC;wBACD,MAAM,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;oBAC9B,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,0BAA0B;IAC5B,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Jev System One / OpenJev Decision Engine for webml-kit.
|
|
3
|
+
*
|
|
4
|
+
* Provides direct logit readout choice evaluation, direct binary evaluation (noul),
|
|
5
|
+
* and continuous scoring evaluation over structured application state.
|
|
6
|
+
*
|
|
7
|
+
* Supports OpenJev models (minicpm5-2b, qwen3-0.6b, qwen3.5-4b) using @wllama/wllama
|
|
8
|
+
* in browser/worker environments with WebGPU/WASM, and a high-performance,
|
|
9
|
+
* calibrated zero-dependency heuristic fallback for Node.js, test, or offline environments.
|
|
10
|
+
*
|
|
11
|
+
* @packageDocumentation
|
|
12
|
+
*/
|
|
13
|
+
export type OpenJevModelPreset = 'minicpm5-2b' | 'qwen3-0.6b' | 'qwen3.5-4b' | (string & {});
|
|
14
|
+
export interface OpenJevModelInfo {
|
|
15
|
+
id: string;
|
|
16
|
+
name: string;
|
|
17
|
+
url: string;
|
|
18
|
+
family: 'minicpm' | 'qwen' | string;
|
|
19
|
+
sizeMB: number;
|
|
20
|
+
}
|
|
21
|
+
export declare const OPENJEV_MODELS: Record<string, OpenJevModelInfo>;
|
|
22
|
+
export interface DecisionProgressEvent {
|
|
23
|
+
status: 'downloading' | 'loading' | 'compiling' | 'ready';
|
|
24
|
+
loaded: number;
|
|
25
|
+
total: number;
|
|
26
|
+
percent: number;
|
|
27
|
+
detail?: string;
|
|
28
|
+
}
|
|
29
|
+
export type DecisionProgressCallback = (event: DecisionProgressEvent) => void;
|
|
30
|
+
export interface DecisionEngineOptions {
|
|
31
|
+
/** Model preset or custom model ID (default: 'qwen3-0.6b') */
|
|
32
|
+
model?: OpenJevModelPreset;
|
|
33
|
+
/** Custom direct URL to GGUF model file */
|
|
34
|
+
modelUrl?: string;
|
|
35
|
+
/** Execution mode: 'auto' (try wllama, fallback to heuristic), 'wllama', or 'heuristic' */
|
|
36
|
+
mode?: 'auto' | 'wllama' | 'heuristic';
|
|
37
|
+
/** Path config for @wllama/wllama assets */
|
|
38
|
+
wasmPaths?: {
|
|
39
|
+
default?: string;
|
|
40
|
+
'single-thread/wllama.wasm'?: string;
|
|
41
|
+
'multi-thread/wllama.wasm'?: string;
|
|
42
|
+
};
|
|
43
|
+
/** Callback for model download and initialization progress */
|
|
44
|
+
onProgress?: DecisionProgressCallback;
|
|
45
|
+
/** Default threshold for noul evaluation (default: 0.5) */
|
|
46
|
+
noulThreshold?: number;
|
|
47
|
+
}
|
|
48
|
+
export interface ChoiceInput {
|
|
49
|
+
/** Application state context (object, string, array, etc.) */
|
|
50
|
+
state: unknown;
|
|
51
|
+
/** Question or instruction to evaluate */
|
|
52
|
+
question?: string;
|
|
53
|
+
/** Alternative alias for question */
|
|
54
|
+
instructions?: string;
|
|
55
|
+
/** Options to evaluate: array of labels or key-description criteria object */
|
|
56
|
+
options: string[] | Record<string, string>;
|
|
57
|
+
}
|
|
58
|
+
export interface ChoiceResult {
|
|
59
|
+
/** Selected winning option */
|
|
60
|
+
choice: string;
|
|
61
|
+
/** Confidence score between 0.0 and 1.0 */
|
|
62
|
+
confidence: number;
|
|
63
|
+
/** Probability distribution across options (sums to ~1.0) */
|
|
64
|
+
probabilities: Record<string, number>;
|
|
65
|
+
/** Execution time in milliseconds */
|
|
66
|
+
latencyMs: number;
|
|
67
|
+
}
|
|
68
|
+
export interface NoulInput {
|
|
69
|
+
/** Application state context */
|
|
70
|
+
state: unknown;
|
|
71
|
+
/** Condition or statement to evaluate */
|
|
72
|
+
statement?: string;
|
|
73
|
+
/** Alternative alias for statement */
|
|
74
|
+
instructions?: string;
|
|
75
|
+
/** Pass threshold (default: 0.5) */
|
|
76
|
+
threshold?: number;
|
|
77
|
+
}
|
|
78
|
+
export interface NoulResult {
|
|
79
|
+
/** Probability (0.0 to 1.0) that the condition holds true */
|
|
80
|
+
noul: number;
|
|
81
|
+
/** Whether noul >= threshold */
|
|
82
|
+
passed: boolean;
|
|
83
|
+
/** Execution time in milliseconds */
|
|
84
|
+
latencyMs: number;
|
|
85
|
+
}
|
|
86
|
+
export interface ScoreInput {
|
|
87
|
+
/** Application state context */
|
|
88
|
+
state: unknown;
|
|
89
|
+
/** Evaluation instructions */
|
|
90
|
+
instructions?: string;
|
|
91
|
+
/** Alternative alias for instructions */
|
|
92
|
+
question?: string;
|
|
93
|
+
/** Ordered evaluation levels: array of level names or level map */
|
|
94
|
+
criteria: string[] | Record<string, string> | Record<number, string>;
|
|
95
|
+
}
|
|
96
|
+
export interface ScoreResult {
|
|
97
|
+
/** Probability-weighted continuous score along levels */
|
|
98
|
+
score: number;
|
|
99
|
+
/** Confidence score between 0.0 and 1.0 */
|
|
100
|
+
confidence: number;
|
|
101
|
+
/** Probability distribution across criteria levels */
|
|
102
|
+
probabilities: Record<string, number>;
|
|
103
|
+
/** Execution time in milliseconds */
|
|
104
|
+
latencyMs: number;
|
|
105
|
+
}
|
|
106
|
+
export interface DecisionEngine {
|
|
107
|
+
readonly model: string;
|
|
108
|
+
readonly isHeuristic: boolean;
|
|
109
|
+
readonly isLoaded: boolean;
|
|
110
|
+
init(): Promise<void>;
|
|
111
|
+
choice(input: ChoiceInput): Promise<ChoiceResult>;
|
|
112
|
+
directChoice(input: ChoiceInput): Promise<ChoiceResult>;
|
|
113
|
+
noul(input: NoulInput): Promise<NoulResult>;
|
|
114
|
+
score(input: ScoreInput): Promise<ScoreResult>;
|
|
115
|
+
dispose(): Promise<void> | void;
|
|
116
|
+
}
|
|
117
|
+
interface NormalizedOption {
|
|
118
|
+
key: string;
|
|
119
|
+
description: string;
|
|
120
|
+
}
|
|
121
|
+
export declare function normalizeOptions(rawOptions: string[] | Record<string, string>): NormalizedOption[];
|
|
122
|
+
interface NormalizedLevel {
|
|
123
|
+
index: number;
|
|
124
|
+
key: string;
|
|
125
|
+
description: string;
|
|
126
|
+
}
|
|
127
|
+
export declare function normalizeCriteria(rawCriteria: string[] | Record<string, string> | Record<number, string>): NormalizedLevel[];
|
|
128
|
+
export declare function validateModelOptions(options: DecisionEngineOptions): {
|
|
129
|
+
modelId: string;
|
|
130
|
+
modelUrl: string;
|
|
131
|
+
mode: 'auto' | 'wllama' | 'heuristic';
|
|
132
|
+
};
|
|
133
|
+
export declare class HeuristicDecisionEngine implements DecisionEngine {
|
|
134
|
+
readonly model: string;
|
|
135
|
+
readonly isHeuristic: boolean;
|
|
136
|
+
private _isLoaded;
|
|
137
|
+
private options;
|
|
138
|
+
constructor(options?: DecisionEngineOptions);
|
|
139
|
+
get isLoaded(): boolean;
|
|
140
|
+
init(): Promise<void>;
|
|
141
|
+
choice(input: ChoiceInput): Promise<ChoiceResult>;
|
|
142
|
+
directChoice(input: ChoiceInput): Promise<ChoiceResult>;
|
|
143
|
+
noul(input: NoulInput): Promise<NoulResult>;
|
|
144
|
+
score(input: ScoreInput): Promise<ScoreResult>;
|
|
145
|
+
dispose(): void;
|
|
146
|
+
}
|
|
147
|
+
export declare class OpenJevWllamaEngine implements DecisionEngine {
|
|
148
|
+
readonly model: string;
|
|
149
|
+
readonly isHeuristic: boolean;
|
|
150
|
+
private _isLoaded;
|
|
151
|
+
private options;
|
|
152
|
+
private modelUrl;
|
|
153
|
+
private wllamaInstance;
|
|
154
|
+
constructor(options?: DecisionEngineOptions);
|
|
155
|
+
get isLoaded(): boolean;
|
|
156
|
+
init(): Promise<void>;
|
|
157
|
+
choice(input: ChoiceInput): Promise<ChoiceResult>;
|
|
158
|
+
directChoice(input: ChoiceInput): Promise<ChoiceResult>;
|
|
159
|
+
noul(input: NoulInput): Promise<NoulResult>;
|
|
160
|
+
score(input: ScoreInput): Promise<ScoreResult>;
|
|
161
|
+
dispose(): Promise<void>;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Creates a DecisionEngine configured for OpenJev System One decision evaluations.
|
|
165
|
+
*
|
|
166
|
+
* Automatically selects OpenJev via Wllama in browser/worker environments with WebGPU/WASM,
|
|
167
|
+
* and falls back to a calibrated zero-dependency heuristic engine in Node.js or test environments.
|
|
168
|
+
*
|
|
169
|
+
* @param options - Configuration options (model preset, mode, wasm paths, onProgress)
|
|
170
|
+
* @returns Configured DecisionEngine instance
|
|
171
|
+
*/
|
|
172
|
+
export declare function createDecisionEngine(options?: DecisionEngineOptions): DecisionEngine;
|
|
173
|
+
/**
|
|
174
|
+
* Executes a one-shot direct choice evaluation over application state with zero boilerplate.
|
|
175
|
+
*
|
|
176
|
+
* @param input - Evaluation state, question, and options (array or criteria record)
|
|
177
|
+
* @param options - Decision engine configuration options
|
|
178
|
+
* @returns ChoiceResult containing winning choice, confidence, and calibrated probabilities
|
|
179
|
+
*/
|
|
180
|
+
export declare function directChoice(input: ChoiceInput, options?: DecisionEngineOptions): Promise<ChoiceResult>;
|
|
181
|
+
export {};
|
|
182
|
+
//# sourceMappingURL=decision.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+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