@kindgi/adapter-model-in-process 0.1.4 → 0.1.5-rc.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 CHANGED
@@ -6,8 +6,13 @@ In-process `ModelProvider` for [`@kindgi/capabilities`](../../capabilities/). Ru
6
6
 
7
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
8
 
9
+ ## Installing
10
+
11
+ The ONNX runtime it runs on (`onnxruntime-node`, through `@huggingface/transformers`) ships its CPU binaries in the package. On Linux x64 its install script also downloads the CUDA and TensorRT providers from NuGet by default; this adapter runs on the CPU, so skip that download: with npm or yarn, `ONNXRUNTIME_NODE_INSTALL=skip npm install …` (the package's own variable). pnpm 10 and later don't run a dependency's install script unless you allow it, so leave `onnxruntime-node` off your allowed builds.
12
+
9
13
  ## Exports
10
14
 
15
+ - **`inProcessAdapterEntry`** (`IN_PROCESS_ADAPTER_ID`) — the `AdapterFactoryEntry` a runtime registers: **`inProcessAdapterFactory`** (a registration lists models by their `MODEL_SPECS` key in `metadata.models[].name`), `prepare` (`prepareInProcessModel`), and **`inProcessCheckConfig(input)`**, which reports a model that isn't one of `MODEL_SPECS` (`metadata.models`) with the factory's own message.
11
16
  - **`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
17
  - `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
18
  - **`InProcessProviderOptions`**:
@@ -0,0 +1,17 @@
1
+ import { type AdapterConfigCheckInput, type AdapterConfigProblem, type AdapterFactory, type AdapterFactoryEntry } from '@kindgi/capabilities';
2
+ /** The id the runtime registers this adapter under. */
3
+ export declare const IN_PROCESS_ADAPTER_ID = "@kindgi/adapter-model-in-process";
4
+ /**
5
+ * The runtime's factory. A provider registered with it lists models by
6
+ * their `MODEL_SPECS` key in `metadata.models[].name`.
7
+ */
8
+ export declare const inProcessAdapterFactory: AdapterFactory;
9
+ /**
10
+ * What's wrong with a registration for this adapter, read without building
11
+ * it (`AdapterFactoryEntry.checkConfig`): a model that isn't one of
12
+ * `MODEL_SPECS`. The problem's message is the error the factory throws.
13
+ */
14
+ export declare function inProcessCheckConfig(input: AdapterConfigCheckInput): readonly AdapterConfigProblem[];
15
+ /** The entry a runtime registers: the factory, its model download, and its static check. */
16
+ export declare const inProcessAdapterEntry: AdapterFactoryEntry;
17
+ //# sourceMappingURL=entry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../src/entry.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EACzB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EAEzB,MAAM,sBAAsB,CAAC;AAK9B,uDAAuD;AACvD,eAAO,MAAM,qBAAqB,qCAAqC,CAAC;AAExE;;;GAGG;AACH,eAAO,MAAM,uBAAuB,EAAE,cAQrC,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,uBAAuB,GAC7B,SAAS,oBAAoB,EAAE,CAGjC;AAED,4FAA4F;AAC5F,eAAO,MAAM,qBAAqB,EAAE,mBAMnC,CAAC"}
package/dist/entry.js ADDED
@@ -0,0 +1,48 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (C) 2026 Kindgi Inc.
3
+ import { adapterConfigError, } from '@kindgi/capabilities';
4
+ import { prepareInProcessModel } from './prepare.js';
5
+ import { MODEL_SPECS, createInProcessModelProvider } from './provider.js';
6
+ /** The id the runtime registers this adapter under. */
7
+ export const IN_PROCESS_ADAPTER_ID = '@kindgi/adapter-model-in-process';
8
+ /**
9
+ * The runtime's factory. A provider registered with it lists models by
10
+ * their `MODEL_SPECS` key in `metadata.models[].name`.
11
+ */
12
+ export const inProcessAdapterFactory = (input) => {
13
+ const problem = modelsProblem(input.metadata);
14
+ if (problem !== undefined)
15
+ throw adapterConfigError(IN_PROCESS_ADAPTER_ID, input.metadata.id, problem);
16
+ return createInProcessModelProvider({
17
+ models: input.metadata.models.map((m) => m.name),
18
+ providerId: input.metadata.id,
19
+ });
20
+ };
21
+ /**
22
+ * What's wrong with a registration for this adapter, read without building
23
+ * it (`AdapterFactoryEntry.checkConfig`): a model that isn't one of
24
+ * `MODEL_SPECS`. The problem's message is the error the factory throws.
25
+ */
26
+ export function inProcessCheckConfig(input) {
27
+ const problem = modelsProblem(input.metadata);
28
+ return problem !== undefined ? [problem] : [];
29
+ }
30
+ /** The entry a runtime registers: the factory, its model download, and its static check. */
31
+ export const inProcessAdapterEntry = {
32
+ adapterId: IN_PROCESS_ADAPTER_ID,
33
+ capabilityKind: 'llm-inference',
34
+ factory: inProcessAdapterFactory,
35
+ prepare: (params) => prepareInProcessModel(params),
36
+ checkConfig: inProcessCheckConfig,
37
+ };
38
+ function modelsProblem(metadata) {
39
+ const index = metadata.models.findIndex((m) => !Object.hasOwn(MODEL_SPECS, m.name));
40
+ const unknown = metadata.models[index];
41
+ if (unknown === undefined)
42
+ return undefined;
43
+ return {
44
+ path: `/metadata/models/${index}/name`,
45
+ message: `unknown model "${unknown.name}". Valid values: ${Object.keys(MODEL_SPECS).join(', ')}.`,
46
+ };
47
+ }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AAO,EAAE,uBAAuB;IAChC,OAAO,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,qBAAqB,CAAC,MAAgC,CAAC;IAC5E,WAAW,EAAE,oBAAoB;CAClC,CAAC;AAEF,SAAS,aAAa,CACpB,QAA6C;IAE7C,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IACpF,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvC,IAAI,OAAO,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC5C,OAAO;QACL,IAAI,EAAE,oBAAoB,KAAK,OAAO;QACtC,OAAO,EAAE,kBAAkB,OAAO,CAAC,IAAI,oBAAoB,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;KAClG,CAAC;AACJ,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export { DEFAULT_LOCAL_MODEL, MODEL_SPECS, createInProcessModelProvider, } from './provider.js';
2
2
  export type { InProcessProviderOptions, LocalModel, ModelSpec } from './provider.js';
3
3
  export { prepareInProcessModel } from './prepare.js';
4
+ export { IN_PROCESS_ADAPTER_ID, inProcessAdapterEntry, inProcessAdapterFactory, inProcessCheckConfig, } from './entry.js';
4
5
  export type { PrepareInProcessParams } from './prepare.js';
5
6
  export type { ModelProvider, PrepareEvent } from '@kindgi/capabilities';
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +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"}
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,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAC3D,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC"}
package/dist/index.js CHANGED
@@ -2,4 +2,5 @@
2
2
  // Copyright (C) 2026 Kindgi Inc.
3
3
  export { DEFAULT_LOCAL_MODEL, MODEL_SPECS, createInProcessModelProvider, } from './provider.js';
4
4
  export { prepareInProcessModel } from './prepare.js';
5
+ export { IN_PROCESS_ADAPTER_ID, inProcessAdapterEntry, inProcessAdapterFactory, inProcessCheckConfig, } from './entry.js';
5
6
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +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"}
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;AACrD,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,YAAY,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kindgi/adapter-model-in-process",
3
- "version": "0.1.4",
3
+ "version": "0.1.5-rc.0",
4
4
  "description": "In-process ModelProvider for @kindgi/capabilities. Runs small instruction-tuned LLMs inside the Node.js process via @huggingface/transformers (ONNX runtime; no external processes, no API keys). SmolLM2-360M by default (~273MB q4f16, Apache 2.0, tuned for function calling); SmolLM2-135M and Qwen3-0.6B selectable via the `models` option. prepareInProcessModel downloads a model ahead of first use and streams progress. Positioned as the cheapest tier for routing/classification/smoke-test workloads — not a replacement for hosted providers on real reasoning tasks.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -29,7 +29,7 @@
29
29
  ],
30
30
  "dependencies": {
31
31
  "@huggingface/transformers": "^4.3.0",
32
- "@kindgi/capabilities": "0.1.4"
32
+ "@kindgi/capabilities": "0.1.5-rc.0"
33
33
  },
34
34
  "engines": {
35
35
  "node": ">=22.12.0"
package/src/entry.ts ADDED
@@ -0,0 +1,63 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (C) 2026 Kindgi Inc.
3
+
4
+ import {
5
+ type AdapterConfigCheckInput,
6
+ type AdapterConfigProblem,
7
+ type AdapterFactory,
8
+ type AdapterFactoryEntry,
9
+ adapterConfigError,
10
+ } from '@kindgi/capabilities';
11
+
12
+ import { type PrepareInProcessParams, prepareInProcessModel } from './prepare.js';
13
+ import { type LocalModel, MODEL_SPECS, createInProcessModelProvider } from './provider.js';
14
+
15
+ /** The id the runtime registers this adapter under. */
16
+ export const IN_PROCESS_ADAPTER_ID = '@kindgi/adapter-model-in-process';
17
+
18
+ /**
19
+ * The runtime's factory. A provider registered with it lists models by
20
+ * their `MODEL_SPECS` key in `metadata.models[].name`.
21
+ */
22
+ export const inProcessAdapterFactory: AdapterFactory = (input) => {
23
+ const problem = modelsProblem(input.metadata);
24
+ if (problem !== undefined)
25
+ throw adapterConfigError(IN_PROCESS_ADAPTER_ID, input.metadata.id, problem);
26
+ return createInProcessModelProvider({
27
+ models: input.metadata.models.map((m) => m.name as LocalModel),
28
+ providerId: input.metadata.id,
29
+ });
30
+ };
31
+
32
+ /**
33
+ * What's wrong with a registration for this adapter, read without building
34
+ * it (`AdapterFactoryEntry.checkConfig`): a model that isn't one of
35
+ * `MODEL_SPECS`. The problem's message is the error the factory throws.
36
+ */
37
+ export function inProcessCheckConfig(
38
+ input: AdapterConfigCheckInput,
39
+ ): readonly AdapterConfigProblem[] {
40
+ const problem = modelsProblem(input.metadata);
41
+ return problem !== undefined ? [problem] : [];
42
+ }
43
+
44
+ /** The entry a runtime registers: the factory, its model download, and its static check. */
45
+ export const inProcessAdapterEntry: AdapterFactoryEntry = {
46
+ adapterId: IN_PROCESS_ADAPTER_ID,
47
+ capabilityKind: 'llm-inference',
48
+ factory: inProcessAdapterFactory,
49
+ prepare: (params) => prepareInProcessModel(params as PrepareInProcessParams),
50
+ checkConfig: inProcessCheckConfig,
51
+ };
52
+
53
+ function modelsProblem(
54
+ metadata: AdapterConfigCheckInput['metadata'],
55
+ ): AdapterConfigProblem | undefined {
56
+ const index = metadata.models.findIndex((m) => !Object.hasOwn(MODEL_SPECS, m.name));
57
+ const unknown = metadata.models[index];
58
+ if (unknown === undefined) return undefined;
59
+ return {
60
+ path: `/metadata/models/${index}/name`,
61
+ message: `unknown model "${unknown.name}". Valid values: ${Object.keys(MODEL_SPECS).join(', ')}.`,
62
+ };
63
+ }
package/src/index.ts CHANGED
@@ -8,5 +8,11 @@ export {
8
8
  } from './provider.js';
9
9
  export type { InProcessProviderOptions, LocalModel, ModelSpec } from './provider.js';
10
10
  export { prepareInProcessModel } from './prepare.js';
11
+ export {
12
+ IN_PROCESS_ADAPTER_ID,
13
+ inProcessAdapterEntry,
14
+ inProcessAdapterFactory,
15
+ inProcessCheckConfig,
16
+ } from './entry.js';
11
17
  export type { PrepareInProcessParams } from './prepare.js';
12
18
  export type { ModelProvider, PrepareEvent } from '@kindgi/capabilities';