@soverius-ai/browser-models-angular 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 soverius-ai contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,9 @@
1
- # Temporary Holding Version
1
+ # @soverius-ai/browser-models-angular
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Angular package for [@soverius-ai/browser-models](https://www.npmjs.com/package/@soverius-ai/browser-models): `provideBrowserModels()`, `injectBrowserModels()` (model state as signals), `withDevtools()`.
4
+
5
+ ```bash
6
+ pnpm add @soverius-ai/browser-models @soverius-ai/browser-models-angular
7
+ ```
8
+
9
+ [Angular docs](https://browser-models.soverius.ai/docs/angular) · [Playground](https://browser-models.soverius.ai/playground?platform=angular) · by [Soverius AI](https://soverius.ai) · MIT
@@ -0,0 +1,86 @@
1
+ import * as i0 from "@angular/core";
2
+ import { DestroyRef, Injectable, InjectionToken, computed, inject, makeEnvironmentProviders, provideEnvironmentInitializer, signal } from "@angular/core";
3
+ import { ModelStore } from "@soverius-ai/browser-models/agent";
4
+ const BROWSER_MODELS_AGENT = new InjectionToken("BROWSER_MODELS_AGENT");
5
+ var BrowserModels = class BrowserModels {
6
+ agent = inject(BROWSER_MODELS_AGENT);
7
+ #store = new ModelStore(this.agent);
8
+ #state = signal(this.#store.getState(), ...ngDevMode ? [{ debugName: "#state" }] : /* istanbul ignore next */ []);
9
+ modelIds = this.#store.modelIds;
10
+ selectedModel = computed(() => this.#state().selectedModel, ...ngDevMode ? [{ debugName: "selectedModel" }] : /* istanbul ignore next */ []);
11
+ availability = computed(() => this.#state().availability, ...ngDevMode ? [{ debugName: "availability" }] : /* istanbul ignore next */ []);
12
+ progress = computed(() => this.#state().progress, ...ngDevMode ? [{ debugName: "progress" }] : /* istanbul ignore next */ []);
13
+ error = computed(() => this.#state().error, ...ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []);
14
+ models = computed(() => this.#state().models, ...ngDevMode ? [{ debugName: "models" }] : /* istanbul ignore next */ []);
15
+ storage = computed(() => this.#state().storage, ...ngDevMode ? [{ debugName: "storage" }] : /* istanbul ignore next */ []);
16
+ ready = computed(() => this.#state().availability === "available", ...ngDevMode ? [{ debugName: "ready" }] : /* istanbul ignore next */ []);
17
+ constructor() {
18
+ const stop = this.#store.subscribe(() => this.#state.set(this.#store.getState()));
19
+ inject(DestroyRef).onDestroy(stop);
20
+ }
21
+ selectModel(modelId) {
22
+ return this.#store.selectModel(modelId);
23
+ }
24
+ refresh() {
25
+ return this.#store.refresh();
26
+ }
27
+ refreshModels() {
28
+ return this.#store.refreshModels();
29
+ }
30
+ download() {
31
+ return this.#store.download();
32
+ }
33
+ deleteModel(modelId) {
34
+ return this.#store.deleteModel(modelId);
35
+ }
36
+ static ɵfac = i0.ɵɵngDeclareFactory({
37
+ minVersion: "12.0.0",
38
+ version: "22.2.6",
39
+ ngImport: i0,
40
+ type: BrowserModels,
41
+ deps: [],
42
+ target: i0.ɵɵFactoryTarget.Injectable
43
+ });
44
+ static ɵprov = i0.ɵɵngDeclareInjectable({
45
+ minVersion: "12.0.0",
46
+ version: "22.2.6",
47
+ ngImport: i0,
48
+ type: BrowserModels
49
+ });
50
+ };
51
+ i0.ɵɵngDeclareClassMetadata({
52
+ minVersion: "12.0.0",
53
+ version: "22.2.6",
54
+ ngImport: i0,
55
+ type: BrowserModels,
56
+ decorators: [{ type: Injectable }],
57
+ ctorParameters: () => []
58
+ });
59
+ function injectBrowserModels() {
60
+ return inject(BrowserModels);
61
+ }
62
+ function provideBrowserModels(...features) {
63
+ if (!features.map((feature) => feature.kind).includes("agent")) throw new Error("provideBrowserModels() needs withAgent(agent).");
64
+ return makeEnvironmentProviders([BrowserModels, ...features.flatMap((feature) => feature.providers)]);
65
+ }
66
+ function withAgent(agent) {
67
+ return {
68
+ kind: "agent",
69
+ providers: [{
70
+ provide: BROWSER_MODELS_AGENT,
71
+ useValue: agent
72
+ }]
73
+ };
74
+ }
75
+ function withDevtools() {
76
+ return {
77
+ kind: "devtools",
78
+ providers: [provideEnvironmentInitializer(() => {
79
+ const stop = inject(BROWSER_MODELS_AGENT).connectDevtools();
80
+ inject(DestroyRef).onDestroy(stop);
81
+ })]
82
+ };
83
+ }
84
+ export { BROWSER_MODELS_AGENT, BrowserModels, injectBrowserModels, provideBrowserModels, withAgent, withDevtools };
85
+
86
+ //# sourceMappingURL=soverius-ai-browser-models-angular.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"soverius-ai-browser-models-angular.mjs","names":[],"sources":["../../../../../libs/frameworks/angular/src/lib/tokens.ts","../../../../../libs/frameworks/angular/src/lib/browser-models.ts","../../../../../libs/frameworks/angular/src/lib/provide-browser-models.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\nimport type { BrowserModelsAgent } from '@soverius-ai/browser-models/agent';\n\n/** The agent the application uses, registered with `withAgent()`. */\nexport const BROWSER_MODELS_AGENT: InjectionToken<BrowserModelsAgent> =\n new InjectionToken<BrowserModelsAgent>('BROWSER_MODELS_AGENT');\n","import {\n DestroyRef,\n Injectable,\n computed,\n inject,\n signal,\n type Signal,\n} from '@angular/core';\nimport {\n ModelStore,\n type BrowserModelsAgent,\n type ModelState,\n} from '@soverius-ai/browser-models/agent';\nimport { BROWSER_MODELS_AGENT } from './tokens.ts';\n\nexport type {\n ModelStatus,\n StorageUse,\n} from '@soverius-ai/browser-models/agent';\n\n/**\n * Model state as Angular signals, on top of the framework-neutral `ModelStore`.\n * Provided by `provideBrowserModels()`; use `injectBrowserModels()`.\n */\n@Injectable()\nexport class BrowserModels {\n // Public members have explicit types: an inferred type can end up in the published .d.ts as a\n // path into this repository.\n readonly agent: BrowserModelsAgent = inject(BROWSER_MODELS_AGENT);\n\n readonly #store = new ModelStore(this.agent);\n readonly #state = signal(this.#store.getState());\n\n /** The ids of all registered models, for a model picker. */\n readonly modelIds: readonly string[] = this.#store.modelIds;\n /** The model the chat uses. Change it with `selectModel()`. */\n readonly selectedModel: Signal<ModelState['selectedModel']> = computed(\n () => this.#state().selectedModel,\n );\n /** Whether the selected model can run, needs a download, or is not supported here. */\n readonly availability: Signal<ModelState['availability']> = computed(\n () => this.#state().availability,\n );\n /** Download progress from 0 to 1 while `download()` runs. */\n readonly progress: Signal<ModelState['progress']> = computed(\n () => this.#state().progress,\n );\n /** The last error, if any. */\n readonly error: Signal<ModelState['error']> = computed(\n () => this.#state().error,\n );\n /** All registered models and whether they are downloaded. Filled by `refreshModels()`. */\n readonly models: Signal<ModelState['models']> = computed(\n () => this.#state().models,\n );\n /** Browser storage used by this site. Filled by `refreshModels()`. */\n readonly storage: Signal<ModelState['storage']> = computed(\n () => this.#state().storage,\n );\n /** True when the selected model is ready for chat. */\n readonly ready: Signal<boolean> = computed(\n () => this.#state().availability === 'available',\n );\n\n constructor() {\n const stop = this.#store.subscribe(() =>\n this.#state.set(this.#store.getState()),\n );\n inject(DestroyRef).onDestroy(stop);\n }\n\n /** Switches the chat to another registered model. There is no automatic fallback. */\n selectModel(modelId: string): Promise<void> {\n return this.#store.selectModel(modelId);\n }\n\n /** Checks the selected model's availability again. */\n refresh(): Promise<void> {\n return this.#store.refresh();\n }\n\n /** Checks every registered model. Call it when you show a model list. */\n refreshModels(): Promise<void> {\n return this.#store.refreshModels();\n }\n\n /** Downloads and loads the selected model. Call it from a click: browsers may require a user gesture. */\n download(): Promise<void> {\n return this.#store.download();\n }\n\n /** Deletes a downloaded model with its engine's official API. */\n deleteModel(modelId: string): Promise<void> {\n return this.#store.deleteModel(modelId);\n }\n}\n\n/** The model state of the agent registered with `provideBrowserModels()`. */\nexport function injectBrowserModels(): BrowserModels {\n return inject(BrowserModels);\n}\n","import {\n DestroyRef,\n EnvironmentProviders,\n Provider,\n inject,\n makeEnvironmentProviders,\n provideEnvironmentInitializer,\n} from '@angular/core';\nimport type { Engine } from '@soverius-ai/browser-models';\nimport type { BrowserModelsAgent } from '@soverius-ai/browser-models/agent';\nimport { BrowserModels } from './browser-models.ts';\nimport { BROWSER_MODELS_AGENT } from './tokens.ts';\n\n/** A feature for `provideBrowserModels()`, in the style of `provideRouter(withX())`. */\nexport interface BrowserModelsFeature {\n readonly kind: 'agent' | 'devtools';\n readonly providers: readonly (Provider | EnvironmentProviders)[];\n}\n\n/**\n * Registers the browser models agent for the application:\n *\n * ```ts\n * const agent = new BrowserModelsAgent({ models: { nano: new PromptApiEngine() }, defaultModel: 'nano' });\n * providers: [\n * provideBrowserModels(withAgent(agent), withDevtools()),\n * provideCopilotKit({ agents: { default: agent } }),\n * ]\n * ```\n */\nexport function provideBrowserModels(\n ...features: readonly BrowserModelsFeature[]\n): EnvironmentProviders {\n const kinds = features.map((feature) => feature.kind);\n if (!kinds.includes('agent')) {\n throw new Error('provideBrowserModels() needs withAgent(agent).');\n }\n return makeEnvironmentProviders([\n BrowserModels,\n ...features.flatMap((feature) => feature.providers),\n ]);\n}\n\n/** The agent to use. Create it with `new BrowserModelsAgent()` and pass the same agent to CopilotKit. */\nexport function withAgent<Models extends Readonly<Record<string, Engine>>>(\n agent: BrowserModelsAgent<Models>,\n): BrowserModelsFeature {\n return {\n kind: 'agent',\n providers: [{ provide: BROWSER_MODELS_AGENT, useValue: agent }],\n };\n}\n\n/** Sends every agent event to the soverius debugger while the application runs. */\nexport function withDevtools(): BrowserModelsFeature {\n return {\n kind: 'devtools',\n providers: [\n provideEnvironmentInitializer(() => {\n const stop = inject(BROWSER_MODELS_AGENT).connectDevtools();\n inject(DestroyRef).onDestroy(stop);\n }),\n ],\n };\n}\n"],"mappings":";;;AAIA,MAAa,uBACX,IAAI,eAAmC,sBAAsB;ACoB/D,IAAa,gBAAb,MAAa,cAAa;CAGf,QAA4B,OAAO,oBAAoB;CAEvD,SAAS,IAAI,WAAW,KAAK,KAAK;CAClC,SAAS,OAAO,KAAK,OAAO,SAAQ,GAAG,GAAA,YAAA,CAAA,EAAA,WAAA,SAAA,CAAA,+BAAA,CAAA,CAAA;CAGvC,WAA8B,KAAK,OAAO;CAE1C,gBAAqD,eACtD,KAAK,OAAM,CAAE,CAAC,eACrB,GAAA,YAAA,CAAA,EAAA,WAAA,gBAAA,CAAA,+BAAA,CAAA,CAAA;CAEQ,eAAmD,eACpD,KAAK,OAAM,CAAE,CAAC,cACrB,GAAA,YAAA,CAAA,EAAA,WAAA,eAAA,CAAA,+BAAA,CAAA,CAAA;CAEQ,WAA2C,eAC5C,KAAK,OAAM,CAAE,CAAC,UACrB,GAAA,YAAA,CAAA,EAAA,WAAA,WAAA,CAAA,+BAAA,CAAA,CAAA;CAEQ,QAAqC,eACtC,KAAK,OAAM,CAAE,CAAC,OACrB,GAAA,YAAA,CAAA,EAAA,WAAA,QAAA,CAAA,+BAAA,CAAA,CAAA;CAEQ,SAAuC,eACxC,KAA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,MAAM,IAAI,MAAM,gDAAgD;CAElE,OAAO,yBAAyB,CAC9B,eACA,GAAG,SAAS,SAAS,YAAY,QAAQ,SAAS,CACnD,CAAA;AACH;AAGA,SAAgB,UACd,OAAiC;CAEjC,OAAO;EACL,MAAM;EACN,WAAW,CAAC;GAAE,SAAS;GAAsB,UAAU;EAAK,CAAE;CAC/D;AACH;AAGA,SAAgB,eAAY;CAC1B,OAAO;EACL,MAAM;EACN,WAAW,CACT,oCAAmC;GACjC,MAAM,OAAO,OAAO,oBAAoB,CAAC,CAAC,gBAAe;GACzD,OAAO,UAAU,CAAC,CAAC,UAAU,IAAI;EACnC,CAAC,CACF;CACF;AACH"}
package/package.json CHANGED
@@ -1,6 +1,35 @@
1
1
  {
2
2
  "name": "@soverius-ai/browser-models-angular",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "peerDependencies": {
5
+ "@angular/core": "^22.2.0",
6
+ "@soverius-ai/browser-models": "0.1.0"
7
+ },
8
+ "sideEffects": false,
9
+ "license": "MIT",
10
+ "homepage": "https://browser-models.soverius.ai",
11
+ "description": "Angular layer for @soverius-ai/browser-models: provideBrowserModels(), signals, debugger wiring.",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/Soverius-AI/browser-models.git",
15
+ "directory": "libs/frameworks/angular"
16
+ },
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
20
+ "module": "fesm2022/soverius-ai-browser-models-angular.mjs",
21
+ "typings": "types/soverius-ai-browser-models-angular.d.ts",
22
+ "exports": {
23
+ "./package.json": {
24
+ "default": "./package.json"
25
+ },
26
+ ".": {
27
+ "types": "./types/soverius-ai-browser-models-angular.d.ts",
28
+ "default": "./fesm2022/soverius-ai-browser-models-angular.mjs"
29
+ }
30
+ },
31
+ "type": "module",
32
+ "dependencies": {
33
+ "tslib": "^2.3.0"
34
+ }
6
35
  }
@@ -0,0 +1,67 @@
1
+ import * as i0 from "@angular/core";
2
+ import { EnvironmentProviders, InjectionToken, Provider, Signal } from "@angular/core";
3
+ import { BrowserModelsAgent, ModelState, ModelStatus, StorageUse } from "@soverius-ai/browser-models/agent";
4
+ import { Engine } from "@soverius-ai/browser-models";
5
+ /**
6
+ * Model state as Angular signals, on top of the framework-neutral `ModelStore`.
7
+ * Provided by `provideBrowserModels()`; use `injectBrowserModels()`.
8
+ */
9
+ export declare class BrowserModels {
10
+ #private;
11
+ readonly agent: BrowserModelsAgent;
12
+ /** The ids of all registered models, for a model picker. */
13
+ readonly modelIds: readonly string[];
14
+ /** The model the chat uses. Change it with `selectModel()`. */
15
+ readonly selectedModel: Signal<ModelState['selectedModel']>;
16
+ /** Whether the selected model can run, needs a download, or is not supported here. */
17
+ readonly availability: Signal<ModelState['availability']>;
18
+ /** Download progress from 0 to 1 while `download()` runs. */
19
+ readonly progress: Signal<ModelState['progress']>;
20
+ /** The last error, if any. */
21
+ readonly error: Signal<ModelState['error']>;
22
+ /** All registered models and whether they are downloaded. Filled by `refreshModels()`. */
23
+ readonly models: Signal<ModelState['models']>;
24
+ /** Browser storage used by this site. Filled by `refreshModels()`. */
25
+ readonly storage: Signal<ModelState['storage']>;
26
+ /** True when the selected model is ready for chat. */
27
+ readonly ready: Signal<boolean>;
28
+ constructor();
29
+ /** Switches the chat to another registered model. There is no automatic fallback. */
30
+ selectModel(modelId: string): Promise<void>;
31
+ /** Checks the selected model's availability again. */
32
+ refresh(): Promise<void>;
33
+ /** Checks every registered model. Call it when you show a model list. */
34
+ refreshModels(): Promise<void>;
35
+ /** Downloads and loads the selected model. Call it from a click: browsers may require a user gesture. */
36
+ download(): Promise<void>;
37
+ /** Deletes a downloaded model with its engine's official API. */
38
+ deleteModel(modelId: string): Promise<void>;
39
+ static ɵfac: i0.ɵɵFactoryDeclaration<BrowserModels, never>;
40
+ static ɵprov: i0.ɵɵInjectableDeclaration<any>;
41
+ }
42
+ /** The model state of the agent registered with `provideBrowserModels()`. */
43
+ export declare function injectBrowserModels(): BrowserModels;
44
+ /** A feature for `provideBrowserModels()`, in the style of `provideRouter(withX())`. */
45
+ interface BrowserModelsFeature {
46
+ readonly kind: 'agent' | 'devtools';
47
+ readonly providers: readonly (Provider | EnvironmentProviders)[];
48
+ }
49
+ /**
50
+ * Registers the browser models agent for the application:
51
+ *
52
+ * ```ts
53
+ * const agent = new BrowserModelsAgent({ models: { nano: new PromptApiEngine() }, defaultModel: 'nano' });
54
+ * providers: [
55
+ * provideBrowserModels(withAgent(agent), withDevtools()),
56
+ * provideCopilotKit({ agents: { default: agent } }),
57
+ * ]
58
+ * ```
59
+ */
60
+ export declare function provideBrowserModels(...features: readonly BrowserModelsFeature[]): EnvironmentProviders;
61
+ /** The agent to use. Create it with `new BrowserModelsAgent()` and pass the same agent to CopilotKit. */
62
+ export declare function withAgent<Models extends Readonly<Record<string, Engine>>>(agent: BrowserModelsAgent<Models>): BrowserModelsFeature;
63
+ /** Sends every agent event to the soverius debugger while the application runs. */
64
+ export declare function withDevtools(): BrowserModelsFeature;
65
+ /** The agent the application uses, registered with `withAgent()`. */
66
+ export declare const BROWSER_MODELS_AGENT: InjectionToken<BrowserModelsAgent>;
67
+ export type { BrowserModelsFeature, ModelStatus, StorageUse };