@kindgi/adapter-model-in-process 0.0.0-bootstrap.0 → 0.1.1
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/LICENSE +201 -0
- package/README.md +69 -2
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/models.d.ts +44 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +41 -0
- package/dist/models.js.map +1 -0
- package/dist/prepare.d.ts +44 -0
- package/dist/prepare.d.ts.map +1 -0
- package/dist/prepare.js +99 -0
- package/dist/prepare.js.map +1 -0
- package/dist/provider.d.ts +43 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +165 -0
- package/dist/provider.js.map +1 -0
- package/package.json +48 -4
- package/src/index.ts +12 -0
- package/src/models.ts +84 -0
- package/src/prepare.ts +166 -0
- package/src/provider.ts +236 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Kindgi Inc.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,70 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@kindgi/adapter-model-in-process`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
In-process `ModelProvider` for [`@kindgi/capabilities`](../../capabilities/). Runs small instruction-tuned models inside the Node.js process through `@huggingface/transformers` (ONNX runtime): no API key, no external process, no network once the weights are cached, and zero USD cost. Intended as the cheapest routing tier — classification, extraction, routing, smoke tests — not as a replacement for hosted models on reasoning tasks.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
Give the capability router a local provider it can match like any other. Every model reports `cost` of `0`, the provider's `region` is `'in-process'`, and `attributes` carry `in-process` plus each model's tier and `suitableFor` hints (`routing`, `classification`, `local`, `lower-cost`, …) for preference matching. `prepareInProcessModel` downloads weights ahead of the first call and streams progress in the `PrepareEvent` shape used by `AdapterFactoryEntry.prepare`.
|
|
8
|
+
|
|
9
|
+
## Exports
|
|
10
|
+
|
|
11
|
+
- **`createInProcessModelProvider(options?)`** — returns a `ModelProvider`. Construction is cheap: each model's pipeline loads on the first `invoke()` that names it (concurrent first calls share one load), downloading weights if they are not cached yet. With `@huggingface/transformers` 4.x the default cache is a `.cache` directory inside that package's install location; `cacheDir` redirects the model files (transformers.js 4.3 can still write a model's `config.json` to its default cache). Throws when `models` is empty; `invoke()` throws for a model the provider does not expose.
|
|
12
|
+
- `invoke()` passes each message to the model's chat template as `{ role, content }`, uses `maxOutputTokens` as `max_new_tokens` (default `512`), samples only when `temperature > 0` (greedy otherwise), and returns `finishReason: 'stop'` and `costUsd: 0`. Token counts come from the model's tokenizer, falling back to about four characters per token. `abortSignal` is not observed.
|
|
13
|
+
- **`InProcessProviderOptions`**:
|
|
14
|
+
- `models?: readonly LocalModel[]` — models to expose; default `[DEFAULT_LOCAL_MODEL]`.
|
|
15
|
+
- `providerId?: string` — `metadata.id`; default `in-process/<models joined with '+'>`. Lets the same model set be registered twice under different ids.
|
|
16
|
+
- `cacheDir?: string` — directory for downloaded model files, passed to transformers.js as `cache_dir`.
|
|
17
|
+
- **`LocalModel`**, **`MODEL_SPECS`**, **`ModelSpec`**, **`DEFAULT_LOCAL_MODEL`** — the closed model set and its per-model spec (`hfName`, `approxDownloadMb`, `contextWindow`, `toolUse`, `tier`, `suitableFor`, `dtype`). All use `q4f16` weights:
|
|
18
|
+
|
|
19
|
+
| `LocalModel` | Hugging Face repo | Download | Context | Tier |
|
|
20
|
+
|---|---|---|---|---|
|
|
21
|
+
| `smollm2-135m` | `HuggingFaceTB/SmolLM2-135M-Instruct` | ~118 MB | 8,192 | ultra-light |
|
|
22
|
+
| `smollm2-360m` (default) | `HuggingFaceTB/SmolLM2-360M-Instruct` | ~273 MB | 8,192 | small |
|
|
23
|
+
| `qwen3-0.6b` | `onnx-community/Qwen3-0.6B-ONNX` | ~550 MB | 32,768 | medium |
|
|
24
|
+
|
|
25
|
+
- **`prepareInProcessModel(params?)`** / **`PrepareInProcessParams`** — `AsyncIterable<PrepareEvent>` for `{ model?, cacheDir? }` (model defaults to `DEFAULT_LOCAL_MODEL`). Loads the model once, yielding `progress` events (with `ratio`, `loadedBytes`, `totalBytes`, `file` when known) and then a single `ready` or `error`. The loaded pipeline is not shared: a provider loads its own copy from the cache on first `invoke()`.
|
|
26
|
+
- **`ModelProvider`**, **`PrepareEvent`** — type re-exports from `@kindgi/capabilities`.
|
|
27
|
+
|
|
28
|
+
## Example
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { createProviderRegistry } from '@kindgi/capabilities';
|
|
32
|
+
import {
|
|
33
|
+
createInProcessModelProvider,
|
|
34
|
+
prepareInProcessModel,
|
|
35
|
+
} from '@kindgi/adapter-model-in-process';
|
|
36
|
+
|
|
37
|
+
// Download (or verify the cached copy of) the weights before serving traffic.
|
|
38
|
+
for await (const event of prepareInProcessModel({ model: 'smollm2-360m' })) {
|
|
39
|
+
if (event.kind === 'error') throw new Error(event.message);
|
|
40
|
+
if (event.kind === 'progress' && event.ratio !== undefined) {
|
|
41
|
+
console.log(`${event.file ?? 'model'} ${Math.round(event.ratio * 100)}%`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const provider = createInProcessModelProvider({ models: ['smollm2-360m'] });
|
|
46
|
+
const { registry } = createProviderRegistry();
|
|
47
|
+
registry.register(tenantId, provider); // metadata.id: 'in-process/smollm2-360m'
|
|
48
|
+
|
|
49
|
+
const result = await provider.invoke({
|
|
50
|
+
model: 'smollm2-360m',
|
|
51
|
+
messages: [
|
|
52
|
+
{ role: 'system', content: 'Classify the ticket as billing, bug or other. Reply with one word.' },
|
|
53
|
+
{ role: 'user', content: 'I was charged twice for the acme plan this month.' },
|
|
54
|
+
],
|
|
55
|
+
maxOutputTokens: 8,
|
|
56
|
+
});
|
|
57
|
+
console.log(result.message.content, result.usage); // costUsd is always 0
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Non-goals
|
|
61
|
+
|
|
62
|
+
- **Streaming.** `invoke()` resolves with the complete response.
|
|
63
|
+
- **Tool calling and structured output.** `tools`, `structuredOutput`, and message `toolCalls` / `toolCallId` are not passed to the model; responses are plain text.
|
|
64
|
+
- **Arbitrary Hugging Face models.** Only the three `LocalModel` keys are selectable.
|
|
65
|
+
|
|
66
|
+
## Related
|
|
67
|
+
|
|
68
|
+
- [`@kindgi/capabilities`](../../capabilities/) — `ModelProvider`, the provider registry, and `AdapterFactoryEntry`.
|
|
69
|
+
- [`@kindgi/adapter-model-openai-compat`](../model-openai-compat/) — for local runners that expose an OpenAI-compatible HTTP endpoint instead.
|
|
70
|
+
- [`@kindgi/dev-echo-provider`](../../dev-echo-provider/) — deterministic scripted provider for tests.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { DEFAULT_LOCAL_MODEL, MODEL_SPECS, createInProcessModelProvider, } from './provider.js';
|
|
2
|
+
export type { InProcessProviderOptions, LocalModel, ModelSpec } from './provider.js';
|
|
3
|
+
export { prepareInProcessModel } from './prepare.js';
|
|
4
|
+
export type { PrepareInProcessParams } from './prepare.js';
|
|
5
|
+
export type { ModelProvider, PrepareEvent } from '@kindgi/capabilities';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,mBAAmB,EACnB,WAAW,EACX,4BAA4B,GAC7B,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,wBAAwB,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACrF,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACrD,YAAY,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAC3D,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC;AAEjC,OAAO,EACL,mBAAmB,EACnB,WAAW,EACX,4BAA4B,GAC7B,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/models.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model registry — three selectable tiers, all Apache 2.0.
|
|
3
|
+
*
|
|
4
|
+
* Sizes are approximate q4f16 (4-bit quantization, float16 activations)
|
|
5
|
+
* download sizes. The first `invoke()` naming a model (or a
|
|
6
|
+
* `prepareInProcessModel` run for it) downloads the files into the
|
|
7
|
+
* transformers.js cache; later loads read from the cache. The default
|
|
8
|
+
* cache is transformers.js's own `env.cacheDir` — with
|
|
9
|
+
* `@huggingface/transformers` 4.x, a `.cache` directory inside that
|
|
10
|
+
* package's install location. The `cacheDir` option (provider and
|
|
11
|
+
* prepare) is passed to the pipeline as `cache_dir` and redirects the
|
|
12
|
+
* model files; transformers.js 4.3 can still write a model's
|
|
13
|
+
* `config.json` to its default cache.
|
|
14
|
+
*
|
|
15
|
+
* Positioning per tier:
|
|
16
|
+
* - `smollm2-135m` — ultra-light. Routing, tag extraction, short
|
|
17
|
+
* classification, simple JSON. Do not use for reasoning or math.
|
|
18
|
+
* - `smollm2-360m` — default. Instruction-tuned with function-calling,
|
|
19
|
+
* summarisation and rewriting data. Best quality-per-megabyte in the
|
|
20
|
+
* tier.
|
|
21
|
+
* - `qwen3-0.6b` — highest local quality. Larger download; better on
|
|
22
|
+
* reasoning / longer contexts.
|
|
23
|
+
*/
|
|
24
|
+
export type LocalModel = 'smollm2-135m' | 'smollm2-360m' | 'qwen3-0.6b';
|
|
25
|
+
export interface ModelSpec {
|
|
26
|
+
/** Hugging Face hub repo id — must have transformers.js-compatible ONNX assets. */
|
|
27
|
+
readonly hfName: string;
|
|
28
|
+
/** Approximate q4f16 download size in MB. */
|
|
29
|
+
readonly approxDownloadMb: number;
|
|
30
|
+
/** Model context window in tokens. */
|
|
31
|
+
readonly contextWindow: number;
|
|
32
|
+
/** Whether the model was tuned for tool / function-calling use. */
|
|
33
|
+
readonly toolUse: boolean;
|
|
34
|
+
/** Rough size tier — added to the provider's `attributes` and each model's `description`. */
|
|
35
|
+
readonly tier: 'ultra-light' | 'small' | 'medium';
|
|
36
|
+
/** Suitable-for hints for capability router preference matching. */
|
|
37
|
+
readonly suitableFor: readonly string[];
|
|
38
|
+
/** dtype passed to transformers.js pipeline. Balances quality vs size. */
|
|
39
|
+
readonly dtype: 'q4f16' | 'q8' | 'fp16' | 'fp32';
|
|
40
|
+
}
|
|
41
|
+
export declare const MODEL_SPECS: Record<LocalModel, ModelSpec>;
|
|
42
|
+
/** Default model when none supplied — best quality-per-MB in the tier. */
|
|
43
|
+
export declare const DEFAULT_LOCAL_MODEL: LocalModel;
|
|
44
|
+
//# sourceMappingURL=models.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,MAAM,UAAU,GAAG,cAAc,GAAG,cAAc,GAAG,YAAY,CAAC;AAExE,MAAM,WAAW,SAAS;IACxB,mFAAmF;IACnF,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,6CAA6C;IAC7C,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,sCAAsC;IACtC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,mEAAmE;IACnE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,6FAA6F;IAC7F,QAAQ,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,GAAG,QAAQ,CAAC;IAClD,oEAAoE;IACpE,QAAQ,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;IACxC,0EAA0E;IAC1E,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,CAAC;CAClD;AAED,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,UAAU,EAAE,SAAS,CAmCrD,CAAC;AAEF,0EAA0E;AAC1E,eAAO,MAAM,mBAAmB,EAAE,UAA2B,CAAC"}
|
package/dist/models.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Copyright (C) 2026 Kindgi Inc.
|
|
3
|
+
export const MODEL_SPECS = {
|
|
4
|
+
'smollm2-135m': {
|
|
5
|
+
hfName: 'HuggingFaceTB/SmolLM2-135M-Instruct',
|
|
6
|
+
approxDownloadMb: 118,
|
|
7
|
+
contextWindow: 8192,
|
|
8
|
+
toolUse: false,
|
|
9
|
+
tier: 'ultra-light',
|
|
10
|
+
suitableFor: ['routing', 'classification', 'smoke-test', 'local', 'lower-cost'],
|
|
11
|
+
dtype: 'q4f16',
|
|
12
|
+
},
|
|
13
|
+
'smollm2-360m': {
|
|
14
|
+
hfName: 'HuggingFaceTB/SmolLM2-360M-Instruct',
|
|
15
|
+
approxDownloadMb: 273,
|
|
16
|
+
contextWindow: 8192,
|
|
17
|
+
toolUse: true,
|
|
18
|
+
tier: 'small',
|
|
19
|
+
suitableFor: [
|
|
20
|
+
'routing',
|
|
21
|
+
'classification',
|
|
22
|
+
'extraction',
|
|
23
|
+
'summarization',
|
|
24
|
+
'local',
|
|
25
|
+
'lower-cost',
|
|
26
|
+
],
|
|
27
|
+
dtype: 'q4f16',
|
|
28
|
+
},
|
|
29
|
+
'qwen3-0.6b': {
|
|
30
|
+
hfName: 'onnx-community/Qwen3-0.6B-ONNX',
|
|
31
|
+
approxDownloadMb: 550,
|
|
32
|
+
contextWindow: 32_768,
|
|
33
|
+
toolUse: true,
|
|
34
|
+
tier: 'medium',
|
|
35
|
+
suitableFor: ['reasoning', 'routing', 'classification', 'extraction', 'long-context', 'local'],
|
|
36
|
+
dtype: 'q4f16',
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
/** Default model when none supplied — best quality-per-MB in the tier. */
|
|
40
|
+
export const DEFAULT_LOCAL_MODEL = 'smollm2-360m';
|
|
41
|
+
//# sourceMappingURL=models.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC;AA4CjC,MAAM,CAAC,MAAM,WAAW,GAAkC;IACxD,cAAc,EAAE;QACd,MAAM,EAAE,qCAAqC;QAC7C,gBAAgB,EAAE,GAAG;QACrB,aAAa,EAAE,IAAI;QACnB,OAAO,EAAE,KAAK;QACd,IAAI,EAAE,aAAa;QACnB,WAAW,EAAE,CAAC,SAAS,EAAE,gBAAgB,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,CAAC;QAC/E,KAAK,EAAE,OAAO;KACf;IACD,cAAc,EAAE;QACd,MAAM,EAAE,qCAAqC;QAC7C,gBAAgB,EAAE,GAAG;QACrB,aAAa,EAAE,IAAI;QACnB,OAAO,EAAE,IAAI;QACb,IAAI,EAAE,OAAO;QACb,WAAW,EAAE;YACX,SAAS;YACT,gBAAgB;YAChB,YAAY;YACZ,eAAe;YACf,OAAO;YACP,YAAY;SACb;QACD,KAAK,EAAE,OAAO;KACf;IACD,YAAY,EAAE;QACZ,MAAM,EAAE,gCAAgC;QACxC,gBAAgB,EAAE,GAAG;QACrB,aAAa,EAAE,MAAM;QACrB,OAAO,EAAE,IAAI;QACb,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,CAAC,WAAW,EAAE,SAAS,EAAE,gBAAgB,EAAE,YAAY,EAAE,cAAc,EAAE,OAAO,CAAC;QAC9F,KAAK,EAAE,OAAO;KACf;CACF,CAAC;AAEF,0EAA0E;AAC1E,MAAM,CAAC,MAAM,mBAAmB,GAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { PrepareEvent } from '@kindgi/capabilities';
|
|
2
|
+
import { type LocalModel } from './models.js';
|
|
3
|
+
/**
|
|
4
|
+
* `prepareInProcessModel` — the in-process adapter's download / warmup
|
|
5
|
+
* step, in the shape of `AdapterFactoryEntry.prepare()` from
|
|
6
|
+
* `@kindgi/capabilities`. Streams download / warmup progress as
|
|
7
|
+
* framework `PrepareEvent`s so an HTTP SSE endpoint (such as
|
|
8
|
+
* `POST /v1/adapters/:adapterId/prepare` in `@kindgi/api`) can stream
|
|
9
|
+
* them to a client.
|
|
10
|
+
*
|
|
11
|
+
* What happens under the hood:
|
|
12
|
+
* 0. Yield a first `progress` event naming the model and its
|
|
13
|
+
* approximate download size, before any callback fires.
|
|
14
|
+
* 1. Dynamically import `@huggingface/transformers` (kept
|
|
15
|
+
* dynamic so shape tests don't touch the ONNX runtime).
|
|
16
|
+
* 2. Call `pipeline('text-generation', hfName, {dtype,
|
|
17
|
+
* progress_callback})`. First run: transformers.js downloads
|
|
18
|
+
* the model into its cache (`cacheDir` when set, passed as
|
|
19
|
+
* `cache_dir`; otherwise transformers.js's default, see
|
|
20
|
+
* `models.ts`). Subsequent runs hit the cache — the callback
|
|
21
|
+
* still fires but reports zero-byte "downloads."
|
|
22
|
+
* 3. The pipeline's progress_callback fires with events like
|
|
23
|
+
* `{status: 'initiate' | 'download' | 'progress' | 'done',
|
|
24
|
+
* name, file, progress?, loaded?, total?}`. We translate each
|
|
25
|
+
* into a `PrepareEvent` and enqueue it for the async iterator
|
|
26
|
+
* to yield.
|
|
27
|
+
* 4. When the pipeline promise resolves → emit `{kind: 'ready'}`
|
|
28
|
+
* and end the stream. On rejection → emit
|
|
29
|
+
* `{kind: 'error', message}` and end.
|
|
30
|
+
*
|
|
31
|
+
* Consumer pattern (e.g. inside an SSE route):
|
|
32
|
+
* ```ts
|
|
33
|
+
* for await (const event of prepareInProcessModel({model: 'smollm2-360m'})) {
|
|
34
|
+
* sendSse(event);
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export interface PrepareInProcessParams {
|
|
39
|
+
readonly model?: LocalModel;
|
|
40
|
+
/** Directory for downloaded model files, passed to transformers.js as `cache_dir`. */
|
|
41
|
+
readonly cacheDir?: string;
|
|
42
|
+
}
|
|
43
|
+
export declare function prepareInProcessModel(params?: PrepareInProcessParams): AsyncIterable<PrepareEvent>;
|
|
44
|
+
//# sourceMappingURL=prepare.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prepare.d.ts","sourceRoot":"","sources":["../src/prepare.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEzD,OAAO,EAAuB,KAAK,UAAU,EAAe,MAAM,aAAa,CAAC;AAEhF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC;IAC5B,sFAAsF;IACtF,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B;AAWD,wBAAuB,qBAAqB,CAC1C,MAAM,GAAE,sBAA2B,GAClC,aAAa,CAAC,YAAY,CAAC,CA0G7B"}
|
package/dist/prepare.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Copyright (C) 2026 Kindgi Inc.
|
|
3
|
+
import { DEFAULT_LOCAL_MODEL, MODEL_SPECS } from './models.js';
|
|
4
|
+
export async function* prepareInProcessModel(params = {}) {
|
|
5
|
+
const modelKey = params.model ?? DEFAULT_LOCAL_MODEL;
|
|
6
|
+
const spec = MODEL_SPECS[modelKey];
|
|
7
|
+
const queue = [];
|
|
8
|
+
let resolveWait;
|
|
9
|
+
let ended = false;
|
|
10
|
+
const enqueue = (event) => {
|
|
11
|
+
queue.push(event);
|
|
12
|
+
const w = resolveWait;
|
|
13
|
+
resolveWait = undefined;
|
|
14
|
+
w?.();
|
|
15
|
+
};
|
|
16
|
+
const finish = (event) => {
|
|
17
|
+
queue.push(event);
|
|
18
|
+
ended = true;
|
|
19
|
+
const w = resolveWait;
|
|
20
|
+
resolveWait = undefined;
|
|
21
|
+
w?.();
|
|
22
|
+
};
|
|
23
|
+
const progressCallback = (raw) => {
|
|
24
|
+
if (raw === null || typeof raw !== 'object')
|
|
25
|
+
return;
|
|
26
|
+
const r = raw;
|
|
27
|
+
switch (r.status) {
|
|
28
|
+
case 'initiate':
|
|
29
|
+
enqueue({
|
|
30
|
+
kind: 'progress',
|
|
31
|
+
message: `Fetching ${r.file ?? r.name ?? spec.hfName}`,
|
|
32
|
+
...(r.file !== undefined && { file: r.file }),
|
|
33
|
+
});
|
|
34
|
+
return;
|
|
35
|
+
case 'download':
|
|
36
|
+
enqueue({
|
|
37
|
+
kind: 'progress',
|
|
38
|
+
message: `Downloading ${r.file ?? r.name ?? spec.hfName}`,
|
|
39
|
+
...(r.file !== undefined && { file: r.file }),
|
|
40
|
+
});
|
|
41
|
+
return;
|
|
42
|
+
case 'progress':
|
|
43
|
+
if (typeof r.progress === 'number') {
|
|
44
|
+
enqueue({
|
|
45
|
+
kind: 'progress',
|
|
46
|
+
message: `Downloading ${r.file ?? r.name ?? spec.hfName}`,
|
|
47
|
+
ratio: Math.max(0, Math.min(1, r.progress / 100)),
|
|
48
|
+
...(typeof r.loaded === 'number' && { loadedBytes: r.loaded }),
|
|
49
|
+
...(typeof r.total === 'number' && { totalBytes: r.total }),
|
|
50
|
+
...(r.file !== undefined && { file: r.file }),
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return;
|
|
54
|
+
case 'done':
|
|
55
|
+
enqueue({
|
|
56
|
+
kind: 'progress',
|
|
57
|
+
message: `Completed ${r.file ?? r.name ?? spec.hfName}`,
|
|
58
|
+
ratio: 1,
|
|
59
|
+
...(r.file !== undefined && { file: r.file }),
|
|
60
|
+
});
|
|
61
|
+
return;
|
|
62
|
+
default:
|
|
63
|
+
// 'ready' + any unknown status — ignore; the load-promise
|
|
64
|
+
// resolution is the authoritative "done" signal.
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
// Kick off the load in parallel with the yield loop.
|
|
69
|
+
const loadPromise = (async () => {
|
|
70
|
+
const mod = (await import('@huggingface/transformers'));
|
|
71
|
+
return mod.pipeline('text-generation', spec.hfName, {
|
|
72
|
+
dtype: spec.dtype,
|
|
73
|
+
progress_callback: progressCallback,
|
|
74
|
+
...(params.cacheDir !== undefined && { cache_dir: params.cacheDir }),
|
|
75
|
+
});
|
|
76
|
+
})();
|
|
77
|
+
loadPromise.then(() => finish({ kind: 'ready', message: `${spec.hfName} ready` }), (err) => finish({
|
|
78
|
+
kind: 'error',
|
|
79
|
+
message: err instanceof Error ? err.message : String(err),
|
|
80
|
+
}));
|
|
81
|
+
// Prologue — tell the consumer what's about to happen even before
|
|
82
|
+
// the callback fires (transformers.js can silently sit on a cache
|
|
83
|
+
// check for a second or two before emitting anything).
|
|
84
|
+
yield {
|
|
85
|
+
kind: 'progress',
|
|
86
|
+
message: `Preparing ${spec.hfName} (~${spec.approxDownloadMb} MB, ${spec.tier} tier)`,
|
|
87
|
+
};
|
|
88
|
+
while (!ended || queue.length > 0) {
|
|
89
|
+
const next = queue.shift();
|
|
90
|
+
if (next !== undefined) {
|
|
91
|
+
yield next;
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
await new Promise((resolve) => {
|
|
95
|
+
resolveWait = resolve;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=prepare.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prepare.js","sourceRoot":"","sources":["../src/prepare.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { ModelProvider } from '@kindgi/capabilities';
|
|
2
|
+
import { type LocalModel } from './models.js';
|
|
3
|
+
export interface InProcessProviderOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Local models this provider exposes. Each entry becomes a
|
|
6
|
+
* `ModelInfo` in the returned `ProviderMetadata.models[]`. Pipelines
|
|
7
|
+
* are loaded lazily per model on the first invocation that names
|
|
8
|
+
* them. Defaults to `[DEFAULT_LOCAL_MODEL]` when omitted.
|
|
9
|
+
*/
|
|
10
|
+
readonly models?: readonly LocalModel[];
|
|
11
|
+
/**
|
|
12
|
+
* Override the provider id embedded in `ProviderMetadata.id` — useful
|
|
13
|
+
* when you want two registrations of the same model set with
|
|
14
|
+
* different capability declarations (e.g. one for routing, one for
|
|
15
|
+
* extraction).
|
|
16
|
+
*/
|
|
17
|
+
readonly providerId?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Directory for downloaded model files, passed to transformers.js as
|
|
20
|
+
* `cache_dir`. Defaults to transformers.js's own cache (`env.cacheDir`;
|
|
21
|
+
* see `models.ts`).
|
|
22
|
+
*/
|
|
23
|
+
readonly cacheDir?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Create an in-process `ModelProvider` backed by `@huggingface/transformers`.
|
|
27
|
+
*
|
|
28
|
+
* Pipelines are loaded lazily per model on the first `invoke()` call
|
|
29
|
+
* that names them — construction of the provider is cheap. Model
|
|
30
|
+
* weights download into the transformers.js cache (or `cacheDir`) on
|
|
31
|
+
* first use; later loads read from the cache.
|
|
32
|
+
*
|
|
33
|
+
* Cost is always `0` USD (no external service). Resource-usage recording
|
|
34
|
+
* still tracks token counts + duration so operators can see the local
|
|
35
|
+
* model's real load in aggregate reports.
|
|
36
|
+
*
|
|
37
|
+
* The returned provider is safe to share process-wide; each underlying
|
|
38
|
+
* pipeline serialises its own requests inside the ONNX runtime.
|
|
39
|
+
*/
|
|
40
|
+
export declare function createInProcessModelProvider(options?: InProcessProviderOptions): ModelProvider;
|
|
41
|
+
export type { LocalModel, ModelSpec } from './models.js';
|
|
42
|
+
export { MODEL_SPECS, DEFAULT_LOCAL_MODEL } from './models.js';
|
|
43
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAMV,aAAa,EAEd,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAuB,KAAK,UAAU,EAA+B,MAAM,aAAa,CAAC;AAoBhG,MAAM,WAAW,wBAAwB;IACvC;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,UAAU,EAAE,CAAC;IACxC;;;;;OAKG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,4BAA4B,CAC1C,OAAO,GAAE,wBAA6B,GACrC,aAAa,CA2Ef;AAsFD,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC"}
|