@zerogpu/browser-extension-sdk 0.3.0 → 0.4.0-dev.202609241109.g8b86510
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/dist/assets/zerogpu-assets.json +3 -3
- package/dist/extension/zerogpu-background.js +1 -406
- package/dist/extension/zerogpu-offscreen.js +1 -5752
- package/dist/extension/zerogpu-settings-link.js +1 -169
- package/dist/loader.js +0 -1
- package/dist/manifest.json +6 -6
- package/dist/types/adapters/kinds.d.ts +20 -0
- package/dist/types/adapters/onnx/adapter.d.ts +12 -0
- package/dist/types/adapters/onnx/runtime.d.ts +38 -0
- package/dist/types/adapters/onnx/sequence-classification.d.ts +40 -0
- package/dist/types/adapters/registry.d.ts +9 -2
- package/dist/types/adapters/types.d.ts +10 -1
- package/dist/types/config/types.d.ts +5 -0
- package/dist/types/runtime/sdk-state.d.ts +1 -0
- package/dist/types/storage/cached-model.d.ts +1 -0
- package/dist/types/transport/http.d.ts +1 -0
- package/dist/v/zerogpu-browser-sdk.89e3d0cc311c.umd.js +1 -0
- package/dist/zerogpu-browser-sdk.cjs +1 -5490
- package/dist/zerogpu-browser-sdk.esm.js +1 -5487
- package/dist/zerogpu-browser-sdk.umd.js +1 -5496
- package/docs/multi-model-support.md +11 -1
- package/package.json +1 -1
- package/dist/extension/zerogpu-background.js.map +0 -1
- package/dist/extension/zerogpu-offscreen.js.map +0 -1
- package/dist/extension/zerogpu-settings-link.js.map +0 -1
- package/dist/loader.js.map +0 -1
- package/dist/v/zerogpu-browser-sdk.8d29febc744c.umd.js +0 -5496
- package/dist/v/zerogpu-browser-sdk.8d29febc744c.umd.js.map +0 -1
- package/dist/zerogpu-browser-sdk.cjs.map +0 -1
- package/dist/zerogpu-browser-sdk.esm.js.map +0 -1
- package/dist/zerogpu-browser-sdk.umd.js.map +0 -1
|
@@ -1,169 +1 @@
|
|
|
1
|
-
var ZeroGpuSettingsLink = (
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* ZeroGPU "extension kit" — end-user consent store.
|
|
6
|
-
*
|
|
7
|
-
* An end user must be able to stop the SDK on their own device, and have that
|
|
8
|
-
* stick across browser restarts. That decision lives in `chrome.storage.local`
|
|
9
|
-
* rather than the offscreen document's `localStorage`, because the service
|
|
10
|
-
* worker has to read it *before* deciding whether to create the offscreen
|
|
11
|
-
* document at all — and it has no access to that document's storage.
|
|
12
|
-
*
|
|
13
|
-
* Enforcement is entirely client-side: opting out stops the device connecting.
|
|
14
|
-
* Nothing is deregistered server-side.
|
|
15
|
-
*/
|
|
16
|
-
/** Single `chrome.storage.local` key holding the whole record. */
|
|
17
|
-
/**
|
|
18
|
-
* Serialises writes, for the same reason the bridge serialises applies. Toggling
|
|
19
|
-
* twice in quick succession is two concurrent calls — each bridge message is
|
|
20
|
-
* handled independently — and `storage.local` promises no ordering between
|
|
21
|
-
* them, so the earlier decision could be the one that lands last and persists
|
|
22
|
-
* while the user is looking at the later one. Queueing also keeps `updatedAt`
|
|
23
|
-
* in step with what actually got stored.
|
|
24
|
-
*/
|
|
25
|
-
Promise.resolve();
|
|
26
|
-
/** Default host for the ZeroGPU-hosted end-user settings page. */
|
|
27
|
-
const ZEROGPU_SETTINGS_BASE_URL = 'https://zerogpu.ai/extension-settings';
|
|
28
|
-
/**
|
|
29
|
-
* Build the end-user settings URL for this extension. Deliberately carries no
|
|
30
|
-
* operator key: the page only needs the extension id to address a message, and
|
|
31
|
-
* keeping keys out is what lets the page stay backend-free.
|
|
32
|
-
*/
|
|
33
|
-
const buildZeroGpuSettingsUrl = ({ extensionId, appName, baseUrl = ZEROGPU_SETTINGS_BASE_URL, debug = false }) => {
|
|
34
|
-
const url = new URL(baseUrl);
|
|
35
|
-
url.searchParams.set('browser', 'chrome');
|
|
36
|
-
url.searchParams.set('extension_id', extensionId);
|
|
37
|
-
if (appName)
|
|
38
|
-
url.searchParams.set('app_name', appName);
|
|
39
|
-
if (debug)
|
|
40
|
-
url.searchParams.set('debug_mode', 'true');
|
|
41
|
-
return url.toString();
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* ZeroGPU "extension kit" — drop-in settings link.
|
|
46
|
-
*
|
|
47
|
-
* Any extension page (popup, options, a settings screen) can offer the end-user
|
|
48
|
-
* opt-out with no JavaScript of its own:
|
|
49
|
-
*
|
|
50
|
-
* <a data-zerogpu-settings>Resource sharing</a>
|
|
51
|
-
* <script src="vendor/zerogpu/zerogpu-settings-link.js"></script>
|
|
52
|
-
*
|
|
53
|
-
* Nothing is configured per host: the extension id comes from `chrome.runtime.id`
|
|
54
|
-
* and the display name from the manifest, so those two lines are identical in
|
|
55
|
-
* every extension. Built as a classic script rather than a module, because a
|
|
56
|
-
* plain popup.html has to be able to `<script src>` it without the host
|
|
57
|
-
* declaring `"type": "module"`.
|
|
58
|
-
*/
|
|
59
|
-
/** Marks an element as the settings entry point. */
|
|
60
|
-
const ZEROGPU_SETTINGS_ATTRIBUTE = 'data-zerogpu-settings';
|
|
61
|
-
/** Set once an element is wired, so a repeat call cannot stack click handlers. */
|
|
62
|
-
const WIRED_ATTRIBUTE = 'data-zerogpu-settings-wired';
|
|
63
|
-
const getChrome = () => (typeof chrome !== 'undefined' ? chrome : undefined);
|
|
64
|
-
/**
|
|
65
|
-
* Build the settings URL for this extension. Per-element overrides are read from
|
|
66
|
-
* `data-zerogpu-app-name`, `data-zerogpu-base-url` and `data-zerogpu-debug`.
|
|
67
|
-
* Returns null outside an extension page, where there is no id to address.
|
|
68
|
-
*/
|
|
69
|
-
const resolveZeroGpuSettingsUrl = (element) => {
|
|
70
|
-
const runtime = getChrome()?.runtime;
|
|
71
|
-
const extensionId = runtime?.id;
|
|
72
|
-
if (!extensionId)
|
|
73
|
-
return null;
|
|
74
|
-
const data = element?.dataset ?? {};
|
|
75
|
-
return buildZeroGpuSettingsUrl({
|
|
76
|
-
extensionId,
|
|
77
|
-
// The manifest name is what the user already knows the extension as, so it
|
|
78
|
-
// is a better default than anything the host would have to repeat here.
|
|
79
|
-
appName: data.zerogpuAppName || runtime.getManifest?.()?.name,
|
|
80
|
-
baseUrl: data.zerogpuBaseUrl || undefined,
|
|
81
|
-
debug: data.zerogpuDebug === 'true'
|
|
82
|
-
});
|
|
83
|
-
};
|
|
84
|
-
/**
|
|
85
|
-
* Elements that already turn a keypress into a click. A <button> fires click on
|
|
86
|
-
* both Enter and Space for free, so giving it `role="button"` and a tabindex
|
|
87
|
-
* would be redundant markup, not an improvement. Anchors never reach here.
|
|
88
|
-
*/
|
|
89
|
-
const activatesOnKeyPress = (element) => element.tagName === 'BUTTON' || element.tagName === 'INPUT';
|
|
90
|
-
const openInNewTab = (url) => {
|
|
91
|
-
const api = getChrome();
|
|
92
|
-
// chrome.tabs.create needs no "tabs" permission; that permission only gates
|
|
93
|
-
// reading sensitive tab properties.
|
|
94
|
-
if (api?.tabs?.create)
|
|
95
|
-
api.tabs.create({ url });
|
|
96
|
-
else
|
|
97
|
-
window.open(url, '_blank', 'noopener');
|
|
98
|
-
};
|
|
99
|
-
/**
|
|
100
|
-
* Wire every marked element under `root`. An anchor gets a real href, so it can
|
|
101
|
-
* be middle-clicked or copied; anything else gets a click handler. Returns how
|
|
102
|
-
* many were wired, and is safe to call again after rendering more markup.
|
|
103
|
-
*/
|
|
104
|
-
const applyZeroGpuSettingsLinks = (root = document) => {
|
|
105
|
-
const elements = Array.from(root.querySelectorAll(`[${ZEROGPU_SETTINGS_ATTRIBUTE}]:not([${WIRED_ATTRIBUTE}])`));
|
|
106
|
-
let wired = 0;
|
|
107
|
-
for (const element of elements) {
|
|
108
|
-
const url = resolveZeroGpuSettingsUrl(element);
|
|
109
|
-
// Outside an extension page there is no id to send, and the settings page
|
|
110
|
-
// cannot answer without one. Leave the markup alone rather than shipping a
|
|
111
|
-
// link that is guaranteed to fail.
|
|
112
|
-
if (!url)
|
|
113
|
-
continue;
|
|
114
|
-
if (element instanceof HTMLAnchorElement) {
|
|
115
|
-
element.href = url;
|
|
116
|
-
if (!element.target)
|
|
117
|
-
element.target = '_blank';
|
|
118
|
-
element.rel = 'noopener noreferrer';
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
const activate = (event) => {
|
|
122
|
-
event.preventDefault();
|
|
123
|
-
openInNewTab(url);
|
|
124
|
-
};
|
|
125
|
-
element.addEventListener('click', activate);
|
|
126
|
-
// A bare <span> or <div> is neither focusable nor keyboard-activatable,
|
|
127
|
-
// so a click handler alone would leave the opt-out reachable by mouse
|
|
128
|
-
// only. Give it the button semantics it is being used as, without
|
|
129
|
-
// overriding anything the host set deliberately.
|
|
130
|
-
if (!activatesOnKeyPress(element)) {
|
|
131
|
-
if (!element.hasAttribute('tabindex'))
|
|
132
|
-
element.setAttribute('tabindex', '0');
|
|
133
|
-
if (!element.hasAttribute('role'))
|
|
134
|
-
element.setAttribute('role', 'button');
|
|
135
|
-
element.addEventListener('keydown', (event) => {
|
|
136
|
-
const { key } = event;
|
|
137
|
-
// role="button" has to answer to both. Space also needs the default
|
|
138
|
-
// suppressed, or it scrolls the page.
|
|
139
|
-
if (key === 'Enter' || key === ' ')
|
|
140
|
-
activate(event);
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
element.setAttribute(WIRED_ATTRIBUTE, '');
|
|
145
|
-
wired += 1;
|
|
146
|
-
}
|
|
147
|
-
return wired;
|
|
148
|
-
};
|
|
149
|
-
// Wire whatever is in the document already. Covers a <script> in <head> as well
|
|
150
|
-
// as one at the end of <body>.
|
|
151
|
-
if (typeof document !== 'undefined') {
|
|
152
|
-
if (document.readyState === 'loading') {
|
|
153
|
-
document.addEventListener('DOMContentLoaded', () => {
|
|
154
|
-
applyZeroGpuSettingsLinks();
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
applyZeroGpuSettingsLinks();
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
exports.ZEROGPU_SETTINGS_ATTRIBUTE = ZEROGPU_SETTINGS_ATTRIBUTE;
|
|
163
|
-
exports.applyZeroGpuSettingsLinks = applyZeroGpuSettingsLinks;
|
|
164
|
-
exports.resolveZeroGpuSettingsUrl = resolveZeroGpuSettingsUrl;
|
|
165
|
-
|
|
166
|
-
return exports;
|
|
167
|
-
|
|
168
|
-
})({});
|
|
169
|
-
//# sourceMappingURL=zerogpu-settings-link.js.map
|
|
1
|
+
var ZeroGpuSettingsLink=function(e){"use strict";Promise.resolve();const t="data-zerogpu-settings",r="data-zerogpu-settings-wired",n=()=>"undefined"!=typeof chrome?chrome:void 0,o=e=>{const t=n()?.runtime,r=t?.id;if(!r)return null;const o=e?.dataset??{};return(({extensionId:e,appName:t,baseUrl:r="https://zerogpu.ai/extension-settings",debug:n=!1})=>{const o=new URL(r);return o.searchParams.set("browser","chrome"),o.searchParams.set("extension_id",e),t&&o.searchParams.set("app_name",t),n&&o.searchParams.set("debug_mode","true"),o.toString()})({extensionId:r,appName:o.zerogpuAppName||t.getManifest?.()?.name,baseUrl:o.zerogpuBaseUrl||void 0,debug:"true"===o.zerogpuDebug})},s=e=>"BUTTON"===e.tagName||"INPUT"===e.tagName,a=e=>{const t=n();t?.tabs?.create?t.tabs.create({url:e}):window.open(e,"_blank","noopener")},i=(e=document)=>{const n=Array.from(e.querySelectorAll(`[${t}]:not([${r}])`));let i=0;for(const e of n){const t=o(e);if(t){if(e instanceof HTMLAnchorElement)e.href=t,e.target||(e.target="_blank"),e.rel="noopener noreferrer";else{const r=e=>{e.preventDefault(),a(t)};e.addEventListener("click",r),s(e)||(e.hasAttribute("tabindex")||e.setAttribute("tabindex","0"),e.hasAttribute("role")||e.setAttribute("role","button"),e.addEventListener("keydown",e=>{const{key:t}=e;"Enter"!==t&&" "!==t||r(e)}))}e.setAttribute(r,""),i+=1}}return i};return"undefined"!=typeof document&&("loading"===document.readyState?document.addEventListener("DOMContentLoaded",()=>{i()}):i()),e.ZEROGPU_SETTINGS_ATTRIBUTE=t,e.applyZeroGpuSettingsLinks=i,e.resolveZeroGpuSettingsUrl=o,e}({});
|
package/dist/loader.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
1
|
!function(e){"use strict";const t="ZeroGpuBrowserSdk",r="ZeroGpuSdk",n=e=>{const{script:n,documentRef:o,windowRef:s,fetchImpl:i}=e;if(s[t]?.initZeroGpuSdk)return Promise.resolve();const c=/^(true|1)$/i.test((n.getAttribute("data-enable-console-logs")??n.getAttribute("enableConsoleLogs")??"").trim()),a=(...e)=>{c&&console.warn(...e)},d=(...e)=>{c&&console.error(...e)},u=n.getAttribute("src")??"";let l;try{l=new URL(u,e.baseUri)}catch{l=new URL(e.baseUri)}const m=new URL("manifest.json",l).toString(),f=new URL("zerogpu-browser-sdk.umd.js",l).toString(),w=[];let p=()=>{};const b=new Promise(e=>{p=e}),g=()=>{const e=s[t];if(e&&"function"==typeof e.initZeroGpuSdk){for(s[r]=e;w.length>0;){const t=w.shift();try{const r=e[t.method];Promise.resolve(r?.(...t.args)).then(t.resolve,t.reject)}catch(e){t.reject(e)}}p()}else d("[ZeroGpuSdk] Core bundle loaded but global API is missing.")};if(!s[r]){const e=e=>(...t)=>new Promise((r,n)=>{w.push({method:e,args:t,resolve:r,reject:n})});s[r]={ready:b,initZeroGpuSdk:e("initZeroGpuSdk"),setCustomParams:e("setCustomParams")}}const h=(e,t)=>{const r=o.createElement("script");for(const e of Array.from(n.attributes))"src"!==e.name&&"integrity"!==e.name&&r.setAttribute(e.name,e.value);r.src=e,r.async=!0,r.setAttribute("data-zerogpu-core","true"),t&&(r.integrity=t,r.crossOrigin=n.crossOrigin??"anonymous"),r.addEventListener("load",g),r.addEventListener("error",()=>{d("[ZeroGpuSdk] Failed to load core bundle from",e)}),(o.head??o.documentElement).appendChild(r)};return(async()=>{try{const e=await i(m,{credentials:"omit"});if(!e.ok)throw new Error(`manifest HTTP ${e.status}`);const t=await e.json();if(!t?.coreBundleUrl)throw new Error("manifest missing coreBundleUrl");const r=new URL(t.coreBundleUrl,m).toString();h(r,t.integrity)}catch(e){a("[ZeroGpuSdk] Manifest unavailable, falling back to stable bundle.",e),h(f)}})()};(()=>{if("undefined"==typeof document||"undefined"==typeof window)return;const e=document.currentScript instanceof HTMLScriptElement?document.currentScript:null;e&&n({script:e,documentRef:document,windowRef:window,fetchImpl:window.fetch.bind(window),baseUri:document.baseURI})})(),e.bootZeroGpuLoader=n}({});
|
|
2
|
-
//# sourceMappingURL=loader.js.map
|
package/dist/manifest.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
3
|
-
"channel": "
|
|
4
|
-
"buildId": "
|
|
5
|
-
"coreBundleUrl": "v/zerogpu-browser-sdk.
|
|
6
|
-
"integrity": "sha384-
|
|
7
|
-
"builtAt": "2026-09-
|
|
2
|
+
"version": "0.4.0-dev.202609241109.g8b86510+8b86510",
|
|
3
|
+
"channel": "development",
|
|
4
|
+
"buildId": "89e3d0cc311c",
|
|
5
|
+
"coreBundleUrl": "v/zerogpu-browser-sdk.89e3d0cc311c.umd.js",
|
|
6
|
+
"integrity": "sha384-zkP44YR2AA4t8AzrJx1JM9V5mYRiJ1Z1a4sPZYrdD8pbRXLGQtVikOIPTqzewVBg",
|
|
7
|
+
"builtAt": "2026-09-24T11:11:12.343Z"
|
|
8
8
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inference kinds — the catalog's `inference_kind` column, served on each
|
|
3
|
+
* register-response model as `inferenceKind`. The kind (not the taskType)
|
|
4
|
+
* selects the on-device runner, so any taskType runs "out of the box" when
|
|
5
|
+
* its kind is supported. Recipes without a kind keep the historical
|
|
6
|
+
* taskType mapping. Vocabulary shared with the Android SDK and the worker.
|
|
7
|
+
*/
|
|
8
|
+
export declare const INFERENCE_KINDS: {
|
|
9
|
+
/** Encoder + classification head: logits [1, N] → top-K `{label: score}`. */
|
|
10
|
+
readonly SEQUENCE_CLASSIFICATION: "sequence_classification";
|
|
11
|
+
/** Encoder-decoder (T5-style), greedy decode → `{ text }`. */
|
|
12
|
+
readonly SEQ2SEQ_GENERATION: "seq2seq_generation";
|
|
13
|
+
/** NLI zero-shot over caller-supplied categories → `{label: score}`. */
|
|
14
|
+
readonly ZERO_SHOT_CLASSIFICATION: "zero_shot_classification";
|
|
15
|
+
/** Decoder-only generation (GGUF via wllama) → `{ text }`. */
|
|
16
|
+
readonly DECODER_GENERATION: "decoder_generation";
|
|
17
|
+
};
|
|
18
|
+
export type InferenceKind = (typeof INFERENCE_KINDS)[keyof typeof INFERENCE_KINDS];
|
|
19
|
+
/** Trimmed, lower-cased kind, or undefined when absent/blank. */
|
|
20
|
+
export declare const normalizeInferenceKind: (value: unknown) => string | undefined;
|
|
@@ -1,3 +1,15 @@
|
|
|
1
1
|
import { SlmConfig } from '../../config/types';
|
|
2
2
|
import { AdapterLoadOptions, AdapterLoadResult } from '../types';
|
|
3
|
+
import { INFERENCE_KINDS } from '../kinds';
|
|
4
|
+
/**
|
|
5
|
+
* Which runner serves a recipe. A supported `inferenceKind` decides, whatever
|
|
6
|
+
* the taskType; without one (or with a kind this adapter does not implement)
|
|
7
|
+
* the historical taskType mapping applies — `'task'`.
|
|
8
|
+
*/
|
|
9
|
+
export type OnnxRunner = typeof INFERENCE_KINDS.SEQUENCE_CLASSIFICATION | typeof INFERENCE_KINDS.SEQ2SEQ_GENERATION | typeof INFERENCE_KINDS.ZERO_SHOT_CLASSIFICATION | 'task';
|
|
10
|
+
export declare const resolveOnnxRunner: (config: Pick<SlmConfig, "inferenceKind">) => OnnxRunner;
|
|
11
|
+
/** transformers.js pipeline task a pipeline-backed runner loads. */
|
|
12
|
+
export declare const resolvePipelineTask: (config: Pick<SlmConfig, "inferenceKind" | "taskType">) => string;
|
|
13
|
+
/** seq2seq default when generation_config.json declares no max_new_tokens. */
|
|
14
|
+
export declare const DEFAULT_SEQ2SEQ_MAX_NEW_TOKENS = 48;
|
|
3
15
|
export declare const loadOnnxAdapter: (slm: SlmConfig, options?: AdapterLoadOptions) => Promise<AdapterLoadResult>;
|
|
@@ -26,12 +26,50 @@ export interface TransformersEnv {
|
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
|
+
/** Output tensor as onnxruntime-web returns it. */
|
|
30
|
+
export interface OrtTensorLike {
|
|
31
|
+
data: ArrayLike<number>;
|
|
32
|
+
dims: readonly number[];
|
|
33
|
+
}
|
|
34
|
+
/** The raw onnxruntime-web InferenceSession transformers.js creates. */
|
|
35
|
+
export interface OrtSessionLike {
|
|
36
|
+
inputNames: readonly string[];
|
|
37
|
+
outputNames: readonly string[];
|
|
38
|
+
run(feeds: Record<string, unknown>): Promise<Record<string, OrtTensorLike>>;
|
|
39
|
+
}
|
|
40
|
+
export interface TransformersTokenizerLike {
|
|
41
|
+
encode(text: string): number[];
|
|
42
|
+
model_max_length?: number;
|
|
43
|
+
}
|
|
44
|
+
/** A bare `PreTrainedModel`: parsed config.json + the ONNX session. */
|
|
45
|
+
export interface TransformersBareModelLike {
|
|
46
|
+
config: Record<string, unknown>;
|
|
47
|
+
session: OrtSessionLike;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The lower-level transformers.js exports the data-driven runners need — the
|
|
51
|
+
* tokenizer, a model-type-agnostic session loader and the Tensor class of the
|
|
52
|
+
* SAME bundled onnxruntime-web the pipelines use (one ORT, one wasm).
|
|
53
|
+
*/
|
|
54
|
+
export interface TransformersLib {
|
|
55
|
+
AutoTokenizer: {
|
|
56
|
+
from_pretrained(source: string, options?: Record<string, unknown>): Promise<TransformersTokenizerLike>;
|
|
57
|
+
};
|
|
58
|
+
PreTrainedModel: {
|
|
59
|
+
from_pretrained(source: string, options?: Record<string, unknown>): Promise<TransformersBareModelLike>;
|
|
60
|
+
};
|
|
61
|
+
Tensor: new (type: string, data: BigInt64Array, dims: number[]) => unknown;
|
|
62
|
+
}
|
|
29
63
|
declare global {
|
|
30
64
|
interface Window {
|
|
31
65
|
TransformersPipeline?: (task: string, modelPath: string, options?: Record<string, unknown>) => Promise<TransformersPipelineFn>;
|
|
32
66
|
TransformersEnv?: TransformersEnv;
|
|
67
|
+
TransformersLib?: TransformersLib;
|
|
33
68
|
}
|
|
34
69
|
}
|
|
70
|
+
/** Picks the {@link TransformersLib} exports off an imported transformers.js module. */
|
|
71
|
+
export declare const pickTransformersLib: (mod: unknown) => TransformersLib | undefined;
|
|
72
|
+
export declare const requireTransformersLib: () => TransformersLib;
|
|
35
73
|
export declare const TRANSFORMERS_CDN = "https://cdn.jsdelivr.net/npm/@xenova/transformers@2.17.2/dist/transformers.min.js";
|
|
36
74
|
export declare const ensureTransformersRuntime: () => Promise<void>;
|
|
37
75
|
export declare const sanitizeBaseUrl: (url: string) => string;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { TransformersBareModelLike, TransformersLib, TransformersTokenizerLike } from './runtime';
|
|
2
|
+
/**
|
|
3
|
+
* `sequence_classification` runner: tokenizer + a raw onnxruntime-web session
|
|
4
|
+
* (logits [1, N]) — deliberately NOT a transformers.js pipeline, so it works
|
|
5
|
+
* for any encoder the bundle ships regardless of `model_type` (transformers.js
|
|
6
|
+
* 2.17 cannot build e.g. ModernBERT through AutoModel, but its session loader
|
|
7
|
+
* and tokenizer are model-type agnostic).
|
|
8
|
+
*
|
|
9
|
+
* Output contract (shared with Android + worker): `Record<label, score>` of the
|
|
10
|
+
* top K labels by score, highest first. Scores are sigmoid for
|
|
11
|
+
* `problem_type: multi_label_classification`, softmax otherwise.
|
|
12
|
+
*/
|
|
13
|
+
export declare const DEFAULT_TOP_K = 50;
|
|
14
|
+
/** Used when neither config.json nor tokenizer_config.json bounds the input. */
|
|
15
|
+
export declare const DEFAULT_MAX_LENGTH = 512;
|
|
16
|
+
export type Activation = 'sigmoid' | 'softmax';
|
|
17
|
+
export declare const chooseActivation: (problemType: unknown) => Activation;
|
|
18
|
+
export declare const sigmoid: (logits: ArrayLike<number>) => number[];
|
|
19
|
+
export declare const softmax: (logits: ArrayLike<number>) => number[];
|
|
20
|
+
export declare const applyActivation: (activation: Activation, logits: ArrayLike<number>) => number[];
|
|
21
|
+
/** `id2label` → index-ordered label list; missing ids become `LABEL_<i>` (HF convention). */
|
|
22
|
+
export declare const labelsFromConfig: (config: Record<string, unknown>, count: number) => string[];
|
|
23
|
+
/** The model's max sequence length: min of the bounds config.json / tokenizer declare. */
|
|
24
|
+
export declare const resolveMaxLength: (config: Record<string, unknown>, tokenizer: Pick<TransformersTokenizerLike, "model_max_length">) => number;
|
|
25
|
+
/**
|
|
26
|
+
* Truncates to `maxLength` like HF's longest-first truncation of a single
|
|
27
|
+
* sequence: the trailing special token ([SEP] / </s>) is kept so the model
|
|
28
|
+
* still sees a well-formed sequence.
|
|
29
|
+
*/
|
|
30
|
+
export declare const truncateIds: (ids: number[], maxLength: number, trailingSpecialId?: number) => number[];
|
|
31
|
+
/** Top K `{label: score}` by score, highest first (insertion order = rank). */
|
|
32
|
+
export declare const topKScores: (scores: number[], labels: string[], k: number) => Record<string, number>;
|
|
33
|
+
export declare const resolveTopK: (requested: unknown) => number;
|
|
34
|
+
export interface SequenceClassifier {
|
|
35
|
+
readonly labelCount: number;
|
|
36
|
+
readonly maxLength: number;
|
|
37
|
+
readonly activation: Activation;
|
|
38
|
+
classify(text: string, topK?: number): Promise<Record<string, number>>;
|
|
39
|
+
}
|
|
40
|
+
export declare const createSequenceClassifier: (lib: Pick<TransformersLib, "Tensor">, tokenizer: TransformersTokenizerLike, model: TransformersBareModelLike) => SequenceClassifier;
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { AdapterCapability, AdapterFactory } from './types';
|
|
2
2
|
export declare const registerAdapter: (factory: AdapterFactory) => void;
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Resolves the factory for a recipe. A supported `inferenceKind` wins and
|
|
5
|
+
* accepts ANY taskType (the kind decides the runner, the taskType is only a
|
|
6
|
+
* routing label). Recipes without a kind — or with a kind no factory
|
|
7
|
+
* implements — fall back to the historical taskType capability list, so
|
|
8
|
+
* existing catalog rows behave exactly as before.
|
|
9
|
+
*/
|
|
10
|
+
export declare const getAdapterFactory: (framework: string | undefined, taskType: string | undefined, inferenceKind?: string) => AdapterFactory | undefined;
|
|
11
|
+
export declare const isSupported: (framework: string | undefined, taskType: string | undefined, inferenceKind?: string) => boolean;
|
|
5
12
|
export declare const listRegisteredCapabilities: () => AdapterCapability[];
|
|
@@ -4,9 +4,16 @@ export interface ModelLoadMetrics {
|
|
|
4
4
|
loadModelMs?: number;
|
|
5
5
|
sizeBytes?: number;
|
|
6
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* What a factory can run. A capability declares either a `taskType` (the
|
|
9
|
+
* historical mapping, used for recipes without an inference kind) or an
|
|
10
|
+
* `inferenceKind` (any taskType whose recipe carries that kind). On a loaded
|
|
11
|
+
* adapter both are filled in from the recipe.
|
|
12
|
+
*/
|
|
7
13
|
export interface AdapterCapability {
|
|
8
14
|
inferenceFramework: string;
|
|
9
|
-
taskType
|
|
15
|
+
taskType?: string;
|
|
16
|
+
inferenceKind?: string;
|
|
10
17
|
modelType?: string;
|
|
11
18
|
}
|
|
12
19
|
export interface InferenceInput {
|
|
@@ -19,6 +26,8 @@ export interface InferenceInput {
|
|
|
19
26
|
schema?: unknown;
|
|
20
27
|
mask?: string;
|
|
21
28
|
maxNewTokens?: number;
|
|
29
|
+
/** sequence_classification: how many top labels to return (default 50). */
|
|
30
|
+
topK?: number;
|
|
22
31
|
type?: string;
|
|
23
32
|
[key: string]: unknown;
|
|
24
33
|
}
|
|
@@ -12,6 +12,11 @@ export interface SlmConfig {
|
|
|
12
12
|
modelRepoId?: string;
|
|
13
13
|
modelType?: string;
|
|
14
14
|
inferenceFramework?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Catalog `inference_kind` — selects the on-device runner (see
|
|
17
|
+
* adapters/kinds.ts). Absent → the historical taskType mapping.
|
|
18
|
+
*/
|
|
19
|
+
inferenceKind?: string;
|
|
15
20
|
manifest?: Record<string, unknown>;
|
|
16
21
|
requiredFiles?: RequiredFileSpec[];
|
|
17
22
|
quantized: boolean;
|