arcane-os 0.3.0 → 0.3.2
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/CHANGELOG.md +27 -0
- package/README.md +86 -117
- package/bin/arcane-test.mjs +170 -46
- package/browser-runtime/ai/browser-speech-artifacts.mjs +887 -909
- package/browser-runtime/ai/browser-speech-providers.mjs +96 -152
- package/browser-runtime/ai/browser-wasm-llm-provider.mjs +627 -819
- package/browser-runtime/ai/browser-wasm.mjs +24 -35
- package/browser-runtime/ai/browser-wllama-runtime.mjs +64 -316
- package/browser-runtime/ai/model-controller.mjs +584 -181
- package/browser-runtime/ai/speech-worker-client.mjs +8 -146
- package/browser-runtime/ai/speech-worker-runtime.mjs +643 -363
- package/browser-runtime/dom-event-instrumentation.mjs +55 -147
- package/browser-runtime/event-manager.mjs +239 -624
- package/package.json +5 -6
- package/runtime/arcane/components/app-bar.html +3 -15
- package/runtime/arcane/components/assistant-panel.html +10 -10
- package/runtime/arcane/components/calculator.html +1 -1
- package/runtime/arcane/components/chat.html +1359 -135
- package/runtime/arcane/components/conversation-view.html +2 -2
- package/runtime/arcane/components/document-inspector.html +11 -17
- package/runtime/arcane/components/file-manager.html +13 -56
- package/runtime/arcane/components/markdown-document.html +82 -281
- package/runtime/arcane/components/markdown-editor.html +7 -10
- package/runtime/arcane/components/media-embed.html +6 -6
- package/runtime/arcane/components/screen-capture.html +4 -4
- package/runtime/arcane/components/source-explanation.html +2 -2
- package/runtime/arcane/components/speech.html +112 -68
- package/runtime/arcane/components/terminal-workspace.html +4 -4
- package/runtime/arcane/components/theme-editor.html +1 -1
- package/runtime/arcane/components/unified-inbox.html +2 -2
- package/runtime/arcane/components/voice-transcription.html +31 -21
- package/runtime/arcane/entities/Calculation.js +2 -3
- package/runtime/arcane/entities/Chat.js +228 -43
- package/runtime/arcane/entities/Preference.js +3 -5
- package/runtime/arcane/entities/Weather.js +5 -5
- package/runtime/arcane/modules/AI.js +1050 -427
- package/runtime/arcane/modules/AIProviderRuntime.js +658 -363
- package/runtime/arcane/modules/AIResponseLength.js +9 -19
- package/runtime/arcane/modules/AIRuntimeState.js +109 -72
- package/runtime/arcane/modules/ArcaneNavigationPolicy.js +45 -32
- package/runtime/arcane/modules/BrowserTestSuite.js +78 -122
- package/runtime/arcane/modules/CalculatorEngine.js +9 -9
- package/runtime/arcane/modules/CommunicationAppController.js +3 -7
- package/runtime/arcane/modules/ComponentContracts.js +30 -32
- package/runtime/arcane/modules/ConfiguredAIChatSession.js +281 -230
- package/runtime/arcane/modules/ConversationActionItems.js +26 -59
- package/runtime/arcane/modules/ConversationClosingReport.js +34 -61
- package/runtime/arcane/modules/ConversationTimebox.js +27 -15
- package/runtime/arcane/modules/DBOPFSDocumentLibrary.js +152 -344
- package/runtime/arcane/modules/DocumentLexicalSearch.js +25 -91
- package/runtime/arcane/modules/HTMLImport.js +54 -1
- package/runtime/arcane/modules/IsolatedModelQuestionRunner.js +40 -203
- package/runtime/arcane/modules/LocalAIReadiness.js +40 -60
- package/runtime/arcane/modules/LocalAIReadinessController.js +15 -13
- package/runtime/arcane/modules/MD.js +1 -45
- package/runtime/arcane/modules/Mail.js +51 -103
- package/runtime/arcane/modules/MailOutbox.mjs +95 -193
- package/runtime/arcane/modules/MailTransport.mjs +36 -57
- package/runtime/arcane/modules/ModelDefinition.js +22 -106
- package/runtime/arcane/modules/OpenMeteoWeatherProvider.js +39 -101
- package/runtime/arcane/modules/PersistentAIChatSession.js +281 -18
- package/runtime/arcane/modules/PreferenceStore.js +102 -30
- package/runtime/arcane/modules/RiskSignalAnalyzer.js +8 -9
- package/runtime/arcane/modules/ScopedOPFSCache.js +7 -42
- package/runtime/arcane/modules/ScreenCapture.js +175 -128
- package/runtime/arcane/modules/SpeechPlayback.js +46 -149
- package/runtime/arcane/modules/StaticDocumentCatalog.js +173 -407
- package/runtime/arcane/modules/ToolCallRouter.js +25 -12
- package/runtime/arcane/modules/YouTubeMedia.js +6 -5
- package/schemas/arcane-app-bundle.schema.json +13 -78
- package/schemas/arcane-app.schema.json +9 -25
- package/schemas/arcane-lock.schema.json +18 -151
- package/schemas/arcane-package.schema.json +2 -16
- package/schemas/native-build-plan.schema.json +119 -122
- package/src/app-descriptor.mjs +75 -132
- package/src/application-tests.mjs +200 -0
- package/src/cli/main.mjs +27 -46
- package/src/constants.mjs +3 -4
- package/src/dev-server.mjs +30 -324
- package/src/doctor.mjs +92 -154
- package/src/dom-event-instrumentation.mjs +55 -147
- package/src/errors.mjs +2 -3
- package/src/event-manager.mjs +239 -624
- package/src/event-queue.mjs +3 -3
- package/src/import-map.mjs +273 -1028
- package/src/index.mjs +14 -16
- package/src/installed-sdk-runtime.mjs +40 -62
- package/src/integrated-provider-loader.mjs +53 -382
- package/src/mail-api.mjs +0 -2
- package/src/mail-server.mjs +224 -580
- package/src/mail.mjs +4 -10
- package/src/native-plan.mjs +163 -598
- package/src/native-provider-loader.mjs +104 -1063
- package/src/packager/core.mjs +485 -3229
- package/src/process.mjs +5 -10
- package/src/release-bundle.mjs +292 -2405
- package/src/runtime.mjs +76 -396
- package/src/scaffold.mjs +30 -80
- package/src/sdk-browser-runtime.mjs +70 -626
- package/src/source-server.mjs +588 -0
- package/src/targets/index.mjs +78 -188
- package/src/templates/workspace-template.mjs +19 -135
- package/src/testing-loader.mjs +164 -0
- package/src/testing.mjs +1 -1
- package/src/toolchain.mjs +131 -544
- package/src/update-check.mjs +26 -64
- package/src/workspace-operation-lock.mjs +139 -430
- package/src/workspace-runtime.mjs +112 -779
- package/src/workspace.mjs +40 -302
- package/browser-runtime/ARCANE_SDK_BROWSER_RELEASE.json +0 -218
- package/browser-runtime/ai/ARCANE_AI_BROWSER_SPEECH_COMPONENTS.json +0 -203
- package/browser-runtime/ai/ARCANE_AI_BROWSER_WASM_COMPONENTS.json +0 -80
- package/browser-runtime/ai/internal/sha256.mjs +0 -166
- package/docs/architecture.md +0 -344
- package/docs/compatibility.md +0 -36
- package/docs/event-manager.md +0 -294
- package/docs/platform-targets.md +0 -108
- package/docs/publishing.md +0 -201
- package/docs/reference/README.md +0 -187
- package/docs/reference/ai/browser-speech-package-authority.json +0 -835
- package/docs/reference/ai/browser-speech.md +0 -1252
- package/docs/reference/ai/browser-wasm.md +0 -530
- package/docs/reference/arcane-ollama.md +0 -288
- package/docs/reference/availability-and-normalization.md +0 -183
- package/docs/reference/behavioral-testing.md +0 -133
- package/docs/reference/cli.md +0 -779
- package/docs/reference/core/README.md +0 -62
- package/docs/reference/core/arcane-ai-contracts.md +0 -907
- package/docs/reference/core/arcane-api.md +0 -601
- package/docs/reference/core/arcane-entities.md +0 -65
- package/docs/reference/core/arcane-events.md +0 -134
- package/docs/reference/core/ollama-module.md +0 -181
- package/docs/reference/core/reference/arcane-api/ai-and-ollama.md +0 -1909
- package/docs/reference/core/reference/arcane-api/applications-terminal-capabilities.md +0 -1057
- package/docs/reference/core/reference/arcane-api/core-and-events.md +0 -320
- package/docs/reference/core/reference/arcane-api/filesystem-storage-preferences-appearance.md +0 -610
- package/docs/reference/core/reference/arcane-api/namespaces.md +0 -1157
- package/docs/reference/core/reference/arcane-api/platform-installation-users-system.md +0 -1423
- package/docs/reference/core/reference/arcane-api/session-provisioning-diagnostics-development.md +0 -315
- package/docs/reference/event-manager.md +0 -1511
- package/docs/reference/inventory/package-api.json +0 -3284
- package/docs/reference/inventory/runtime-components.json +0 -1011
- package/docs/reference/inventory/runtime-entities.json +0 -26
- package/docs/reference/inventory/runtime-modules.json +0 -1431
- package/docs/reference/mail.md +0 -316
- package/docs/reference/protocols.md +0 -677
- package/docs/reference/runtime-components.md +0 -1366
- package/docs/reference/runtime-entities.md +0 -303
- package/docs/reference/runtime-modules.md +0 -2960
- package/docs/reference/sdk-api.md +0 -6694
- package/docs/roadmap.md +0 -79
- package/docs/work-amplification.md +0 -129
- package/runtime/ARCANE_RUNTIME_RELEASE.json +0 -826
|
@@ -1,530 +0,0 @@
|
|
|
1
|
-
# Browser-WASM local AI
|
|
2
|
-
|
|
3
|
-
Use this browser-only entrypoint when an application deliberately owns a local
|
|
4
|
-
GGUF model authority and wants provider-neutral LLM lifecycle, chat, streaming,
|
|
5
|
-
cancellation, and structural tool-call results without an Arcane Core host.
|
|
6
|
-
For ordinary hosted applications, start with the [Arcane AI
|
|
7
|
-
contracts](../core/arcane-ai-contracts.md) and `globalThis.Arcane.ai`. This
|
|
8
|
-
page is the focused local-browser path beneath the normalized AI decision
|
|
9
|
-
guide.
|
|
10
|
-
|
|
11
|
-
The wiring example assumes a scaffolded or materialized Arcane application
|
|
12
|
-
with SDK `0.3.0`'s runtime tree and generated browser import map.
|
|
13
|
-
`arcane/DBOPFS` is a managed browser-map specifier, not an npm package export.
|
|
14
|
-
See [browser runtime delivery](../protocols.md#browser-runtime-delivery) before
|
|
15
|
-
using the example in a custom host or bundler.
|
|
16
|
-
|
|
17
|
-
```javascript
|
|
18
|
-
import DBOPFS from 'arcane/DBOPFS';
|
|
19
|
-
import {
|
|
20
|
-
createArcaneAI,
|
|
21
|
-
createBrowserModelSource,
|
|
22
|
-
createBrowserWasmLlmProvider,
|
|
23
|
-
createDbopfsModelStore
|
|
24
|
-
} from 'arcane-os/ai/browser-wasm';
|
|
25
|
-
|
|
26
|
-
const MODEL = Object.freeze({
|
|
27
|
-
id:'my-reviewed-model',
|
|
28
|
-
files:Object.freeze([{
|
|
29
|
-
name:'model-q4-00001-of-00002.gguf',
|
|
30
|
-
url:'https://models.example/revisions/4f7c/model-q4-00001-of-00002.gguf',
|
|
31
|
-
bytes:123456789,
|
|
32
|
-
sha256:'0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
|
|
33
|
-
},{
|
|
34
|
-
name:'model-q4-00002-of-00002.gguf',
|
|
35
|
-
url:'https://models.example/revisions/4f7c/model-q4-00002-of-00002.gguf',
|
|
36
|
-
bytes:98765432,
|
|
37
|
-
sha256:'abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789'
|
|
38
|
-
}])
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
const dbopfs = globalThis.dbopfs || new DBOPFS({applicationId:'my-app'});
|
|
42
|
-
await dbopfs.readyPromise;
|
|
43
|
-
const source = createBrowserModelSource(MODEL);
|
|
44
|
-
const store = createDbopfsModelStore({dbopfs});
|
|
45
|
-
const provider = createBrowserWasmLlmProvider({source, store});
|
|
46
|
-
const ai = createArcaneAI({
|
|
47
|
-
provider,
|
|
48
|
-
loadPolicy:'manual',
|
|
49
|
-
security:{secure:true}
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
// Put this behind an explicit user action: it can download every declared file.
|
|
53
|
-
async function loadReviewedModel() {
|
|
54
|
-
return ai.load({threads:1, contextTokens:4096});
|
|
55
|
-
}
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
The browser-WASM runtime closure packages the authenticated
|
|
59
|
-
`@wllama/wllama` `3.6.0` ESM and WebAssembly runtime plus the Wllama and
|
|
60
|
-
llama.cpp MIT license texts. It
|
|
61
|
-
packages no model weights, default model catalog, CDN fallback, native
|
|
62
|
-
provider, speech synthesis, or transcription. The sibling
|
|
63
|
-
[`arcane-os/ai/browser-speech`](browser-speech.md) entrypoint supplies speech
|
|
64
|
-
provider mechanisms but still no runtime/model bytes. Callers supply every
|
|
65
|
-
model-source authority. Each file's `bytes` is an optional expected positive
|
|
66
|
-
byte length, not inline model data. The declared URL binds selection identity;
|
|
67
|
-
exact byte identity is established only by the checks the caller enables and
|
|
68
|
-
supplies.
|
|
69
|
-
|
|
70
|
-
## Lifecycle at a glance
|
|
71
|
-
|
|
72
|
-
`createArcaneAI()` owns one LLM controller. Its default `loadPolicy` is
|
|
73
|
-
`on-demand`; the first request may download and initialize the model. Use
|
|
74
|
-
`manual` when a user action, resource review, or progress UI must precede load.
|
|
75
|
-
|
|
76
|
-
| Operation | Result |
|
|
77
|
-
| --- | --- |
|
|
78
|
-
| `ai.status()` | Frozen `{llm: status}` wrapper. |
|
|
79
|
-
| `ai.load(options)` | Flat LLM status after load. |
|
|
80
|
-
| `ai.llm.chat(request)` / `ai.fetchRequest(request)` | Validated OpenAI-like completion. |
|
|
81
|
-
| `ai.llm.stream(request)` | Frozen async-iterator handle with `result` and `cancel(reason)`. |
|
|
82
|
-
| `ai.streamRequest(request)` | Consumes the stream and returns text or `{toolName: argumentJsonString}`. |
|
|
83
|
-
| `ai.createChatSession(options)` | Asynchronously resolves `Promise<PersistentAIChatSession>` bound to this exact controller; caller-supplied `chat` is rejected. |
|
|
84
|
-
| `ai.unload()` | Cancels active work, releases the Wllama session, and returns flat unloaded status; the DBOPFS cache remains. |
|
|
85
|
-
| `ai.dispose()` | Permanently disposes the controller; explicit `store.remove(source)` is required to delete cached model bytes. |
|
|
86
|
-
|
|
87
|
-
The controller emits `statechange` and `progress` through
|
|
88
|
-
`addEventListener()`, `removeEventListener()`, or `on()`. Event `detail` is the
|
|
89
|
-
current frozen status. Provider states are `unloaded`, `loading`, `ready`,
|
|
90
|
-
`unloading`, and `error`.
|
|
91
|
-
|
|
92
|
-
## Model authority, security, and cache admission
|
|
93
|
-
|
|
94
|
-
The canonical model descriptor is `{id, files:[{name?,url,bytes?,sha256?},...]}`.
|
|
95
|
-
The ordered `files` array is nonempty; names and URLs are unique. Each URL must
|
|
96
|
-
be absolute HTTPS without credentials or a fragment; revision-floating `main`,
|
|
97
|
-
`master`, and `latest` path segments are rejected. When supplied, `bytes` is a
|
|
98
|
-
positive safe integer and `sha256` is exactly 64 hexadecimal characters. The
|
|
99
|
-
legacy one-file `{id,url,bytes?,sha256?}` shape remains accepted and normalizes
|
|
100
|
-
to one ordered member.
|
|
101
|
-
|
|
102
|
-
Fetch follows HTTPS redirects and records the requested and final HTTPS URL in
|
|
103
|
-
the completion evidence. A redirect that leaves HTTPS is rejected. A declared
|
|
104
|
-
URL, revision-looking path, or recorded final URL is not a byte digest: only an
|
|
105
|
-
enabled byte-length or SHA-256 check establishes that corresponding integrity
|
|
106
|
-
fact. When a check is disabled, status reports it as `unchecked`.
|
|
107
|
-
|
|
108
|
-
App, provider/model-binding, and load-operation options use the same
|
|
109
|
-
plain-JavaScript shape:
|
|
110
|
-
|
|
111
|
-
```javascript
|
|
112
|
-
{
|
|
113
|
-
security:{
|
|
114
|
-
secure:true,
|
|
115
|
-
checks:{byteLength:true, sha256:true}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
The SDK default is `secure:false`. Security fields resolve independently from
|
|
121
|
-
the load operation, then provider/model binding, then app configuration, then
|
|
122
|
-
the SDK default. Omitted fields inherit; they do not become `false`. After
|
|
123
|
-
resolution, `secure:true` makes both checks enabled by default and
|
|
124
|
-
`secure:false` makes both checks disabled by default. An explicit inherited or
|
|
125
|
-
lower-scope `checks.byteLength` or `checks.sha256` boolean overrides that secure
|
|
126
|
-
default for its check.
|
|
127
|
-
|
|
128
|
-
An enabled byte-length check requires descriptor `bytes` and compares it with
|
|
129
|
-
the actual cached or downloaded byte count. A disabled byte-length check permits
|
|
130
|
-
`bytes` to be absent and never rejects a cached or downloaded model by comparing
|
|
131
|
-
it with an expected size. The store still counts and records the
|
|
132
|
-
observed byte length for storage and progress metadata on every install and
|
|
133
|
-
cache reuse.
|
|
134
|
-
|
|
135
|
-
An enabled SHA-256 check requires descriptor `sha256` and hashes the actual
|
|
136
|
-
stored or cached file. A disabled SHA-256 check permits `sha256` to be absent
|
|
137
|
-
and does not hash or reread a multi-gigabyte model solely to produce a digest.
|
|
138
|
-
Only enabled checks fail closed. Regardless of optional integrity checks, a
|
|
139
|
-
load succeeds only after Wllama reports that the model is loaded.
|
|
140
|
-
|
|
141
|
-
The DBOPFS adapter commits an `arcane.ai.browser-wasm.model.v4` completion
|
|
142
|
-
manifest only after every ordered file succeeds. Status reports the effective
|
|
143
|
-
`security.secure`, both effective check booleans, and per-check integrity
|
|
144
|
-
outcomes. Overall integrity is `verified` when every enabled check succeeded,
|
|
145
|
-
`pending` while an enabled check is running, and `unchecked` when neither check
|
|
146
|
-
is enabled. Before completion an enabled check reports `pending`; after a
|
|
147
|
-
successful load each check independently reports `verified` or `unchecked`.
|
|
148
|
-
`load({offline:true})` never
|
|
149
|
-
performs a model request; it uses a compatible cached entry or rejects with
|
|
150
|
-
`ARCANE_AI_MODEL_OFFLINE_MISS`.
|
|
151
|
-
|
|
152
|
-
```javascript
|
|
153
|
-
const {security, integrity} = ai.status().llm;
|
|
154
|
-
console.log(security.secure, security.checks.byteLength, security.checks.sha256);
|
|
155
|
-
console.log(integrity.state); // 'unchecked' or 'verified'
|
|
156
|
-
console.log(integrity.byteLength.observed); // actual cached/downloaded bytes
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
For one-file compatibility, older descriptors can supply `immutableUrl` as the
|
|
160
|
-
URL alias and `name` as a cache-filename hint. If both `url` and
|
|
161
|
-
`immutableUrl` are present, they must match. Legacy `licenseSpdx` and
|
|
162
|
-
`sourceRevision` properties are
|
|
163
|
-
not canonical descriptor fields or runtime admission checks; applications remain responsible for model selection,
|
|
164
|
-
provenance, and license compliance. Version-2/3 compatibility is internal; a
|
|
165
|
-
new successful completion is always recorded as version 4 without inventing an
|
|
166
|
-
integrity result.
|
|
167
|
-
|
|
168
|
-
`localOnly:true` describes inference after load. It does not mean a cache miss
|
|
169
|
-
cannot download. Source downloads use CORS, omit credentials and referrer,
|
|
170
|
-
disable HTTP caching, and honor `AbortSignal`.
|
|
171
|
-
|
|
172
|
-
On Chrome, observing a lower-power Intel WebGPU adapter may open
|
|
173
|
-
`chrome://flags/#force-high-performance-gpu` in a new tab and show an alert
|
|
174
|
-
explaining that Chrome must be completely restarted after changing the flag.
|
|
175
|
-
The notice is advisory; it does not change browser settings, prove a faster
|
|
176
|
-
adapter exists, or make a failed load succeed.
|
|
177
|
-
|
|
178
|
-
## Streaming, cancellation, and tools
|
|
179
|
-
|
|
180
|
-
```javascript
|
|
181
|
-
async function streamLocalSummaryAfterUserChoice(cancelButton) {
|
|
182
|
-
// The selected browser-WASM model must already be ready.
|
|
183
|
-
if (!cancelButton?.addEventListener) {
|
|
184
|
-
throw new TypeError('A cancel button is required.');
|
|
185
|
-
}
|
|
186
|
-
const abort = new AbortController();
|
|
187
|
-
const stream = ai.llm.stream({
|
|
188
|
-
localOnly:true,
|
|
189
|
-
signal:abort.signal,
|
|
190
|
-
messages:[{role:'user', content:'Summarize this text.'}],
|
|
191
|
-
maxTokens:128
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
const cancel = () => abort.abort('user cancelled');
|
|
195
|
-
cancelButton.addEventListener('click', cancel, {once:true});
|
|
196
|
-
try {
|
|
197
|
-
for await (const chunk of stream) renderChunk(chunk);
|
|
198
|
-
const completion = await stream.result;
|
|
199
|
-
renderCompletion(completion);
|
|
200
|
-
} catch (error) {
|
|
201
|
-
if (error?.code !== 'ARCANE_AI_REQUEST_ABORTED') throw error;
|
|
202
|
-
renderCancelled();
|
|
203
|
-
} finally {
|
|
204
|
-
cancelButton.removeEventListener('click', cancel);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
An active cancellation rejects as `ARCANE_AI_REQUEST_ABORTED`. Requests are
|
|
210
|
-
serialized; provider status exposes `busy` and `queued`. Supported request
|
|
211
|
-
generation fields include temperature, top-K, top-P, min-P, repeat penalty,
|
|
212
|
-
maximum tokens, seed, and stop sequences. Load settings separately include
|
|
213
|
-
`contextTokens`, `batchTokens`, `microBatchTokens`, `threads`, and GPU-layer
|
|
214
|
-
count. The shipped runtime always sets `gpuLayers: 99999`: WebGPU and proved
|
|
215
|
-
full offload are mandatory, and there is no CPU fallback. Secure context,
|
|
216
|
-
adapter selection, full-offload, logical-buffer, queue-submission, and
|
|
217
|
-
settled-fence evidence are load admission; cross-origin isolation and coarse
|
|
218
|
-
hardware fields remain observations.
|
|
219
|
-
|
|
220
|
-
Tool definitions, tool choice, parallel-tool-call preference, and JSON or JSON
|
|
221
|
-
Schema structured-output requests are passed to Wllama. Returned tool calls are
|
|
222
|
-
validated and surfaced as structural data. Argument payloads remain JSON
|
|
223
|
-
strings. The SDK never invokes a handler or executes a tool; application code
|
|
224
|
-
must review policy, validate arguments, choose whether to execute, and submit a
|
|
225
|
-
later tool result.
|
|
226
|
-
|
|
227
|
-
## Errors and unavailable states
|
|
228
|
-
|
|
229
|
-
Invalid configuration can throw `TypeError` or `RangeError`. Operational
|
|
230
|
-
failures expose a stable `.code`; the internal error class is not exported.
|
|
231
|
-
Handle the narrow code needed by the current operation and treat other failures
|
|
232
|
-
as unavailable.
|
|
233
|
-
|
|
234
|
-
| Area | Stable codes |
|
|
235
|
-
| --- | --- |
|
|
236
|
-
| Source and download | `ARCANE_AI_MODEL_SOURCE_INVALID`, `ARCANE_AI_MODEL_SOURCE_UNAVAILABLE`, `ARCANE_AI_MODEL_DOWNLOAD_FAILED`, `ARCANE_AI_MODEL_REDIRECT_BLOCKED`, `ARCANE_AI_MODEL_SIZE_MISMATCH`, `ARCANE_AI_MODEL_DIGEST_MISMATCH` |
|
|
237
|
-
| Cache and storage | `ARCANE_AI_MODEL_CACHE_REJECTED`, `ARCANE_AI_MODEL_OFFLINE_MISS`, `ARCANE_AI_STORAGE_UNAVAILABLE`, `ARCANE_AI_STORAGE_READ_FAILED`, `ARCANE_AI_STORAGE_DELETE_FAILED` |
|
|
238
|
-
| Lifecycle | `ARCANE_AI_UNAVAILABLE`, `ARCANE_AI_NOT_READY`, `ARCANE_AI_MODEL_NOT_READY`, `ARCANE_AI_LOAD_FAILED`, `ARCANE_AI_UNLOAD_FAILED`, `ARCANE_AI_DISPOSE_FAILED`, `ARCANE_AI_DISPOSED`, `ARCANE_AI_OPERATION_SUPERSEDED`, `ARCANE_AI_SECURITY_RELOAD_REQUIRED` |
|
|
239
|
-
| Requests | `ARCANE_AI_REQUEST_ABORTED`, `ARCANE_AI_REQUEST_FAILED`, `ARCANE_AI_RUNTIME_BUSY`, `ARCANE_AI_INVALID_PROVIDER_RESULT`, `ARCANE_AI_LOCAL_ONLY_UNAVAILABLE`, `ARCANE_AI_ADAPTER_PROTOCOL_MISMATCH` |
|
|
240
|
-
| Provider/2 adapter | `ARCANE_AI_MODEL_AUTHORITY_REQUIRED`, `ARCANE_AI_PROVIDER_ROLE_MISMATCH`, `ARCANE_AI_PROVIDER_PROGRESS_INVALID`, `ARCANE_AI_PROVIDER_STATUS_INVALID`, `ARCANE_AI_PROVIDER_OPERATION_UNAVAILABLE` |
|
|
241
|
-
| WebGPU and model admission | `ARCANE_AI_WEBGPU_REQUIRED`, `ARCANE_AI_WEBGPU_API_UNAVAILABLE`, `ARCANE_AI_WEBGPU_EVIDENCE_INVALID`, `ARCANE_AI_MODEL_FULL_OFFLOAD_UNPROVEN`, `ARCANE_AI_MODEL_WEBGPU_REQUIREMENT_FAILED`, `ARCANE_AI_MODEL_GPU_MEMORY_INSUFFICIENT`, `ARCANE_AI_MODEL_SHARD_TOO_LARGE`, `ARCANE_AI_MODEL_RELOAD_REQUIRED`, `ARCANE_AI_LOAD_PLAN_RELOAD_REQUIRED` |
|
|
242
|
-
| Worker cleanup and recovery | `ARCANE_AI_WORKER_TERMINATION_UNCONFIRMED`, `ARCANE_AI_COMPLETION_RECOVERY_UNCONFIRMED` |
|
|
243
|
-
| Diagnostics | `ARCANE_AI_PROBE_FAILED` |
|
|
244
|
-
|
|
245
|
-
Capability and status records also carry stable reason codes. These observations
|
|
246
|
-
are not all thrown errors: positive and unknown states let an application
|
|
247
|
-
explain why load is available, blocked, or not yet measured without guessing.
|
|
248
|
-
|
|
249
|
-
| Observation | Status/reason codes |
|
|
250
|
-
| --- | --- |
|
|
251
|
-
| Browser prerequisites | `ARCANE_AI_WEBASSEMBLY_UNAVAILABLE`, `ARCANE_AI_OPFS_UNAVAILABLE`, `ARCANE_AI_SECURE_CONTEXT_REQUIRED` |
|
|
252
|
-
| Model/storage sizing | `ARCANE_AI_MODEL_STORAGE_REQUIREMENT_UNBOUNDED`, `ARCANE_AI_MODEL_STORAGE_REQUIREMENT_UNKNOWN`, `ARCANE_AI_STORAGE_ESTIMATE_UNAVAILABLE`, `ARCANE_AI_STORAGE_ESTIMATE_FAILED`, `ARCANE_AI_STORAGE_ESTIMATE_INVALID`, `ARCANE_AI_STORAGE_NOT_MEASURED`, `ARCANE_AI_STORAGE_CAPACITY_INSUFFICIENT` |
|
|
253
|
-
| Positive cache/storage state | `ARCANE_AI_MODEL_CACHE_COMPLETE`, `ARCANE_AI_STORAGE_CAPACITY_AVAILABLE` |
|
|
254
|
-
| WebGPU execution evidence | `ARCANE_AI_WEBGPU_EXECUTION_OBSERVED`, `ARCANE_AI_WEBGPU_EXECUTION_UNOBSERVED` |
|
|
255
|
-
| Provider and runtime failure state | `ARCANE_AI_PROVIDER_UNAVAILABLE`, `ARCANE_AI_RUNTIME_FAILED` |
|
|
256
|
-
|
|
257
|
-
`capabilities()` reports browser observations such as WebAssembly, OPFS,
|
|
258
|
-
WebGPU API presence, admitted WebGPU operation, secure context, cross-origin
|
|
259
|
-
isolation, and hardware concurrency. `navigator.gpu` alone is not operational
|
|
260
|
-
evidence. The authoritative runtime can operate without cross-origin isolation,
|
|
261
|
-
so that flag is not a hard gate; secure context and WebGPU/full-offload evidence
|
|
262
|
-
are. `probe()` exercises packaged Wllama backend operations only while unloaded;
|
|
263
|
-
it neither admits nor downloads a model.
|
|
264
|
-
|
|
265
|
-
## BROWSER_WASM_RUNTIME_AUTHORITY
|
|
266
|
-
|
|
267
|
-
### Overview
|
|
268
|
-
|
|
269
|
-
Deep-frozen identity for the shipped browser runtime. Its protocol is
|
|
270
|
-
`arcane-ai-browser-wasm/2`; the direct provider uses
|
|
271
|
-
`arcane-ai-adapter/1` and `adaptV1LlmProvider()` projects it into
|
|
272
|
-
`arcane-ai-provider/2`. It records Wllama `3.6.0`, the embedded llama.cpp
|
|
273
|
-
revision, authenticated module/WASM byte lengths and SHA-256 values, licenses,
|
|
274
|
-
and the disabled compatibility-runtime and remote-model-helper policy.
|
|
275
|
-
|
|
276
|
-
### Value and import
|
|
277
|
-
|
|
278
|
-
```text
|
|
279
|
-
const BROWSER_WASM_RUNTIME_AUTHORITY
|
|
280
|
-
```
|
|
281
|
-
|
|
282
|
-
### Availability and normalization
|
|
283
|
-
|
|
284
|
-
**Browser metadata; safely inspectable without loading a model.** The value is
|
|
285
|
-
an immutable receipt, not a provider instance, model catalog, or capability
|
|
286
|
-
grant.
|
|
287
|
-
|
|
288
|
-
### Example
|
|
289
|
-
|
|
290
|
-
```javascript
|
|
291
|
-
import {BROWSER_WASM_RUNTIME_AUTHORITY} from 'arcane-os/ai/browser-wasm';
|
|
292
|
-
|
|
293
|
-
console.log(BROWSER_WASM_RUNTIME_AUTHORITY.protocol);
|
|
294
|
-
console.log(BROWSER_WASM_RUNTIME_AUTHORITY.package.version); // 3.6.0
|
|
295
|
-
```
|
|
296
|
-
|
|
297
|
-
## createArcaneAI()
|
|
298
|
-
|
|
299
|
-
### Overview
|
|
300
|
-
|
|
301
|
-
Creates the application-facing facade around a provider or an existing LLM
|
|
302
|
-
controller. Use this as the primary browser-local API; construct the source,
|
|
303
|
-
store, and Wllama provider beneath it.
|
|
304
|
-
|
|
305
|
-
### Signature and result
|
|
306
|
-
|
|
307
|
-
```text
|
|
308
|
-
createArcaneAI({ llm=null, provider=null, loadPolicy='on-demand', security }={})
|
|
309
|
-
```
|
|
310
|
-
|
|
311
|
-
At least one `llm` or `provider` is required; when both are supplied, `llm`
|
|
312
|
-
takes precedence. `loadPolicy` is `on-demand` or `manual`. The frozen result
|
|
313
|
-
contains `llm`, `runtime`, `createChatSession`, `status`, `load`,
|
|
314
|
-
`unload`, `probe`, `fetchRequest`, `streamRequest`, and `dispose`.
|
|
315
|
-
`security` is the app-level security configuration inherited by provider loads.
|
|
316
|
-
The SDK default is `secure:false`; `ai.load({security})` can override inherited
|
|
317
|
-
fields for that operation.
|
|
318
|
-
|
|
319
|
-
When `llm` is an existing `ModelController`, that controller keeps the security
|
|
320
|
-
and load policy with which it was created. This function
|
|
321
|
-
does not reapply its `loadPolicy` argument in that case, and supplying `security` alongside the
|
|
322
|
-
existing controller throws `TypeError`. Passing a provider instead creates a
|
|
323
|
-
new controller with the requested policy and security.
|
|
324
|
-
|
|
325
|
-
### Availability and normalization
|
|
326
|
-
|
|
327
|
-
**Browser.** It normalizes provider lifecycle and request observation without
|
|
328
|
-
selecting a model, changing browser permissions, contacting Arcane Core, or
|
|
329
|
-
creating a fallback provider.
|
|
330
|
-
|
|
331
|
-
### Example
|
|
332
|
-
|
|
333
|
-
```javascript
|
|
334
|
-
const ai = createArcaneAI({provider, loadPolicy:'manual'});
|
|
335
|
-
async function loadCachedModelAfterUserChoice() {
|
|
336
|
-
const off = ai.llm.on('statechange', event => renderStatus(event.detail));
|
|
337
|
-
try {
|
|
338
|
-
return await ai.load({offline:true});
|
|
339
|
-
} finally {
|
|
340
|
-
off();
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
```
|
|
344
|
-
|
|
345
|
-
`await ai.createChatSession(options)` dynamically creates a
|
|
346
|
-
[`PersistentAIChatSession`](../runtime-modules.md#persistentaichatsessionjs)
|
|
347
|
-
whose `chat` function is permanently bound to this controller. `options` must
|
|
348
|
-
be a plain object and must not contain `chat`; this prevents a session from
|
|
349
|
-
claiming the controller's lifecycle while sending its turns through another
|
|
350
|
-
provider.
|
|
351
|
-
|
|
352
|
-
## createBrowserModelSource()
|
|
353
|
-
|
|
354
|
-
### Overview
|
|
355
|
-
|
|
356
|
-
Validates a caller-owned canonical ordered multi-file descriptor and creates
|
|
357
|
-
the cancellable HTTPS download source accepted by this provider. A legacy
|
|
358
|
-
one-file descriptor normalizes to one ordered member.
|
|
359
|
-
|
|
360
|
-
### Signature and result
|
|
361
|
-
|
|
362
|
-
```text
|
|
363
|
-
createBrowserModelSource(descriptor, { fetchImpl=null }={})
|
|
364
|
-
```
|
|
365
|
-
|
|
366
|
-
The frozen source includes `kind`, the canonical descriptor fields,
|
|
367
|
-
`descriptor`, and `open(memberIndex,{signal})`. `open()` requires a member
|
|
368
|
-
index for multi-file sources and returns a readable response body,
|
|
369
|
-
requested/final URLs, reported byte length, and `cancel()`; it does not admit
|
|
370
|
-
bytes to the cache.
|
|
371
|
-
|
|
372
|
-
### Availability and normalization
|
|
373
|
-
|
|
374
|
-
**Browser Fetch with CORS.** URL and optional metadata syntax are normalized.
|
|
375
|
-
Expected length and SHA-256 are enforced only when their effective checks are
|
|
376
|
-
enabled for load.
|
|
377
|
-
|
|
378
|
-
### Example
|
|
379
|
-
|
|
380
|
-
```javascript
|
|
381
|
-
const source = createBrowserModelSource(MODEL);
|
|
382
|
-
console.log(source.id, source.files);
|
|
383
|
-
```
|
|
384
|
-
|
|
385
|
-
## createBrowserWasmLlmProvider()
|
|
386
|
-
|
|
387
|
-
### Overview
|
|
388
|
-
|
|
389
|
-
Creates the local-only Wllama provider from genuine source and store objects
|
|
390
|
-
created by this module. Structural lookalikes are rejected.
|
|
391
|
-
|
|
392
|
-
### Signature and result
|
|
393
|
-
|
|
394
|
-
```text
|
|
395
|
-
createBrowserWasmLlmProvider({ source, sources, store, loadDefaults={}, security, logger=console }={})
|
|
396
|
-
```
|
|
397
|
-
|
|
398
|
-
`sources` is a nonempty array of unique SDK-created model sources. Optional
|
|
399
|
-
legacy `source` identifies the default and must be one member of `sources`; when
|
|
400
|
-
`sources` is omitted, `source` supplies the one-model catalog. The frozen
|
|
401
|
-
result exposes protocol and provider identity, default model metadata,
|
|
402
|
-
`catalog`, `capabilities`, `status`, `load`, `unload`, `chat`, `stream`,
|
|
403
|
-
`streamChat`, `use`, `probe`, and `dispose`. Direct provider `load()` selects a
|
|
404
|
-
catalog model and returns `{model,status}`;
|
|
405
|
-
the facade `ai.load()` returns the flat controller status.
|
|
406
|
-
Provider `security` supplies the provider/model-binding scope. Direct
|
|
407
|
-
`provider.load({security})` and facade `ai.load({security})` supply the
|
|
408
|
-
operation scope.
|
|
409
|
-
|
|
410
|
-
### Availability and normalization
|
|
411
|
-
|
|
412
|
-
**Browser secure context with WebAssembly, OPFS/DBOPFS, WebGPU, and admitted
|
|
413
|
-
full-offload evidence.** Inference is local after a successful Wllama load.
|
|
414
|
-
The runtime forces `gpuLayers: 99999`; callers cannot select CPU or partial
|
|
415
|
-
offload. Status discloses effective checks, capability policy, storage/model
|
|
416
|
-
compatibility, and whether enabled integrity checks are pending, unchecked, or
|
|
417
|
-
verified.
|
|
418
|
-
|
|
419
|
-
### Example
|
|
420
|
-
|
|
421
|
-
```javascript
|
|
422
|
-
const provider = createBrowserWasmLlmProvider({
|
|
423
|
-
sources:[source],
|
|
424
|
-
store,
|
|
425
|
-
loadDefaults:{threads:1, contextTokens:4096}
|
|
426
|
-
});
|
|
427
|
-
console.log(provider.status().state); // unloaded
|
|
428
|
-
```
|
|
429
|
-
|
|
430
|
-
## createDbopfsModelStore()
|
|
431
|
-
|
|
432
|
-
### Overview
|
|
433
|
-
|
|
434
|
-
Adapts an existing DBOPFS instance without renaming or replacing its public
|
|
435
|
-
methods. The adapter owns model-file, observed-byte, optional-check, and
|
|
436
|
-
completion-manifest behavior.
|
|
437
|
-
|
|
438
|
-
### Signature and result
|
|
439
|
-
|
|
440
|
-
```text
|
|
441
|
-
createDbopfsModelStore({ dbopfs, tableName='arcane_ai_browser_models', estimateStorage=null }={})
|
|
442
|
-
```
|
|
443
|
-
|
|
444
|
-
The optional `estimateStorage()` function supplies bounded storage evidence
|
|
445
|
-
when the browser's default estimator is unavailable or an application owns a
|
|
446
|
-
more precise quota view. The frozen result contains `kind`, `tableName`, the
|
|
447
|
-
original `adapter`, and `ready`, `openVerified`, `install`, `ensure`, and
|
|
448
|
-
`remove`. `ensure()` returns
|
|
449
|
-
`{files,file,manifest,observedBytes,integrity,cache}`: `files` preserves the
|
|
450
|
-
ordered model set, while the one-file compatibility field `file` is that sole
|
|
451
|
-
member or `null`. `cache` is `cached` or `installed`. `openVerified()` remains
|
|
452
|
-
a compatibility helper that requires both byte-length and SHA-256 verification.
|
|
453
|
-
|
|
454
|
-
### Availability and normalization
|
|
455
|
-
|
|
456
|
-
**Browser with a ready DBOPFS instance and OPFS.** A cache receipt reports only
|
|
457
|
-
the checks actually performed. Unchecked cache metadata is not integrity
|
|
458
|
-
evidence, and no cache receipt is a transferable capability token or proof of
|
|
459
|
-
model license rights.
|
|
460
|
-
|
|
461
|
-
### Example
|
|
462
|
-
|
|
463
|
-
```javascript
|
|
464
|
-
const store = createDbopfsModelStore({dbopfs});
|
|
465
|
-
async function verifyCachedModelAfterUserChoice() {
|
|
466
|
-
await store.ready();
|
|
467
|
-
const cached = await store.openVerified(source);
|
|
468
|
-
console.log(cached ? 'verified cache' : 'cache miss');
|
|
469
|
-
}
|
|
470
|
-
```
|
|
471
|
-
|
|
472
|
-
## adaptV1LlmProvider()
|
|
473
|
-
|
|
474
|
-
### Overview
|
|
475
|
-
|
|
476
|
-
Projects one compatible admitted v1 browser-WASM provider into the same
|
|
477
|
-
provider/2 LLM role used by `AIProviderRuntime.js`. Admission checks the v1
|
|
478
|
-
protocol, required identity/methods, and local-only capability; it does not
|
|
479
|
-
establish SDK provenance for an arbitrary compatible object. The adapter does
|
|
480
|
-
not change the wrapped provider, download a model, execute a tool, or create a
|
|
481
|
-
fallback.
|
|
482
|
-
|
|
483
|
-
### Signature and result
|
|
484
|
-
|
|
485
|
-
```text
|
|
486
|
-
adaptV1LlmProvider(provider)
|
|
487
|
-
```
|
|
488
|
-
|
|
489
|
-
The frozen result exposes `{protocol:'arcane-ai-provider/2',role:'llm',id,
|
|
490
|
-
localOnly:true,catalog,inspect,status,load,request,unload,dispose}`. Inspection
|
|
491
|
-
returns `arcane-ai-model-authority/1` only for an exact catalog selection.
|
|
492
|
-
`request()` admits only `chat` and `stream` and preserves structural tool data.
|
|
493
|
-
|
|
494
|
-
### Availability and normalization
|
|
495
|
-
|
|
496
|
-
The adapter is available anywhere the caller can supply an admitted
|
|
497
|
-
`arcane-ai-browser-wasm/1` provider object. It performs only the versioned
|
|
498
|
-
provider-shape normalization into `arcane-ai-provider/2`; it does not create a
|
|
499
|
-
runtime, choose or download a model, grant host capability, change local-only
|
|
500
|
-
behavior, or make an arbitrary provider authoritative. Provider lifecycle,
|
|
501
|
-
cancellation, catalog selection, and failures remain owned by the wrapped
|
|
502
|
-
provider and are forwarded through the normalized role contract.
|
|
503
|
-
|
|
504
|
-
### Example
|
|
505
|
-
|
|
506
|
-
```javascript
|
|
507
|
-
import {adaptV1LlmProvider} from 'arcane-os/ai/browser-wasm';
|
|
508
|
-
import {getAIProviderRuntime} from 'arcane/AIProviderRuntime';
|
|
509
|
-
|
|
510
|
-
const runtime = getAIProviderRuntime();
|
|
511
|
-
const release = runtime.register(adaptV1LlmProvider(provider));
|
|
512
|
-
// Configure an exact llm route before load/use. Release registration at teardown.
|
|
513
|
-
release();
|
|
514
|
-
```
|
|
515
|
-
|
|
516
|
-
## Related reference
|
|
517
|
-
|
|
518
|
-
- [Canonical `createArcaneAI()` entry](../sdk-api.md#createarcaneai) and the
|
|
519
|
-
sibling [`BROWSER_WASM_RUNTIME_AUTHORITY`](../sdk-api.md#browserwasmruntimeauthority),
|
|
520
|
-
[`adaptV1LlmProvider()`](../sdk-api.md#adaptv1llmprovider),
|
|
521
|
-
[`createBrowserModelSource()`](../sdk-api.md#createbrowsermodelsource),
|
|
522
|
-
[`createBrowserWasmLlmProvider()`](../sdk-api.md#createbrowserwasmllmprovider),
|
|
523
|
-
and [`createDbopfsModelStore()`](../sdk-api.md#createdbopfsmodelstore) entries
|
|
524
|
-
- [Browser-local normalization boundary](../availability-and-normalization.md#browser-local-provider-adapter)
|
|
525
|
-
- [Authenticated browser runtime delivery](../protocols.md#browser-runtime-delivery)
|
|
526
|
-
- [Browser-WASM behavior evidence](../behavioral-testing.md#behavioral-coverage-model)
|
|
527
|
-
- [DBOPFS runtime module](../runtime-modules.md#dbopfsjs)
|
|
528
|
-
- [Browser speech providers](browser-speech.md)
|
|
529
|
-
- [Provider-neutral AI runtime](../runtime-modules.md#aiproviderruntimejs)
|
|
530
|
-
- [Persistent chat](../runtime-modules.md#persistentaichatsessionjs)
|