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,8 +1,9 @@
|
|
|
1
1
|
import { Wllama } from "./wllama/index.mjs";
|
|
2
2
|
|
|
3
|
+
const completeValue = (value) => value;
|
|
4
|
+
|
|
3
5
|
const MODULE_URL = new URL("./wllama/index.mjs", import.meta.url).href;
|
|
4
6
|
const WASM_URL = new URL("./wllama/wllama.wasm", import.meta.url).href;
|
|
5
|
-
const WEBGPU_EVIDENCE_PROTOCOL = "arcane-wllama-webgpu-evidence/1";
|
|
6
7
|
const RUNTIME_EVIDENCE_PROTOCOL = "arcane-wllama-runtime-evidence/1";
|
|
7
8
|
const FULL_GPU_LAYERS = 99_999;
|
|
8
9
|
const WEBGPU_ADAPTER_PATTERN = /^ggml_webgpu: adapter_info: vendor_id: (\d+) \| vendor: (.*?) \| architecture: (.*?) \| device_id: (\d+) \| name: (.*?) \| device_desc: (.*)$/u;
|
|
@@ -10,81 +11,43 @@ const GPU_OFFLOAD_PATTERN = /^[^:]+: offloaded (\d+)\/(\d+) layers to GPU$/u;
|
|
|
10
11
|
const PEG_NATIVE_OUTPUT_PREFIX = "common_chat_peg_parse: unparsed peg-native output: ";
|
|
11
12
|
const PEG_NATIVE_FINAL_PREFIX = "<|channel|>final <|constrain|>content<|message|>";
|
|
12
13
|
const PEG_NATIVE_FAILURE = "The model produced output that does not match the expected peg-native format";
|
|
13
|
-
const MAX_RECOVERED_COMPLETION_CHARACTERS = 1_048_576;
|
|
14
|
-
const MAX_RECOVERED_COMPLETION_LINES = 16_384;
|
|
15
|
-
|
|
16
|
-
function deepFreeze(value) {
|
|
17
|
-
if (!value || typeof value !== "object" || Object.isFrozen(value)) return value;
|
|
18
|
-
for (const nested of Object.values(value)) deepFreeze(nested);
|
|
19
|
-
return Object.freeze(value);
|
|
20
|
-
}
|
|
21
14
|
|
|
22
|
-
export const BROWSER_WASM_RUNTIME_AUTHORITY =
|
|
15
|
+
export const BROWSER_WASM_RUNTIME_AUTHORITY = completeValue({
|
|
23
16
|
protocol: "arcane-ai-browser-wasm/2",
|
|
24
17
|
provider: "wllama",
|
|
25
18
|
executionPolicy: {
|
|
26
19
|
webgpuRequired: true,
|
|
27
20
|
cpuFallback: false,
|
|
28
|
-
operationalEvidence: RUNTIME_EVIDENCE_PROTOCOL,
|
|
29
|
-
navigatorPresenceIsOperationalEvidence: false,
|
|
30
21
|
cancellation: "abortSignal-plus-llama-cancel-acknowledgement",
|
|
31
22
|
cleanup: "worker-termination-only",
|
|
32
23
|
nativeUnloadClaimed: false,
|
|
33
24
|
physicalVramReclamationClaimed: false,
|
|
34
|
-
telemetryThreatModel: "authenticated-module-closure-and-frozen-prototypes-not-hostile-platform-global-attestation",
|
|
35
25
|
},
|
|
36
26
|
package: {
|
|
37
27
|
name: "@wllama/wllama",
|
|
38
28
|
version: "3.6.0",
|
|
39
|
-
sourceRevision: "f16050d8d51a00602c6a2a6b8ac9c09f490eea7f",
|
|
40
29
|
resolved: "https://registry.npmjs.org/@wllama/wllama/-/wllama-3.6.0.tgz",
|
|
41
|
-
npmIntegrity: "sha512-NN3ZBXqaaUwGXTQubkNvsCaLPjN2XVa0bVS40OYCE8zquYmRc2W3oHYEgwvuSWWDB8aUqTLyMioySCXNkcnD1w==",
|
|
42
|
-
tarballBytes: 5_671_369,
|
|
43
|
-
tarballSha256: "137c35ceccb4911a9b0ce9b427889f75991654ec6a6d1dd8fabd879b14b07a1b",
|
|
44
30
|
licenseSpdx: "MIT",
|
|
45
|
-
license: {
|
|
46
|
-
path: "ai/wllama/LICENCE",
|
|
47
|
-
bytes: 1_071,
|
|
48
|
-
sha256: "5866e3bd7e3cbd3f7c8bea6efd8a1e7fa7cc8de68c30f428aff7c6584a0fb720",
|
|
49
|
-
},
|
|
50
31
|
},
|
|
51
32
|
llamaCpp: {
|
|
52
|
-
sourceRevision: "4df29be4f4c3673f428170fda944a5b19f743bb8",
|
|
53
33
|
licenseSpdx: "MIT",
|
|
54
|
-
license: {
|
|
55
|
-
path: "ai/wllama/llama.cpp-LICENSE",
|
|
56
|
-
bytes: 1_078,
|
|
57
|
-
sha256: "94f29bbed6a22c35b992c5c6ebf0e7c92f13b836b90f36f461c9cf2f0f1d010d",
|
|
58
|
-
},
|
|
59
34
|
},
|
|
60
35
|
runtimeAssets: {
|
|
61
36
|
module: {
|
|
62
37
|
path: "ai/wllama/index.mjs",
|
|
63
38
|
url: MODULE_URL,
|
|
64
|
-
bytes: 392_852,
|
|
65
|
-
sha256: "b119a7cdffabc8541dce283381d18ada4027c0560728aac1fe45bdd30cdac8e2",
|
|
66
39
|
mediaType: "text/javascript",
|
|
67
|
-
projection: {
|
|
68
|
-
protocol: WEBGPU_EVIDENCE_PROTOCOL,
|
|
69
|
-
tool: "tools/project-wllama-webgpu-runtime.mjs",
|
|
70
|
-
sourcePath: "node_modules/@wllama/wllama/esm/index.js",
|
|
71
|
-
sourceBytes: 373_519,
|
|
72
|
-
sourceSha256: "4637e42d636010493a9b274fbbe70bfd8120365da726b1d9e589d85ca84a00d6",
|
|
73
|
-
wasmModified: false,
|
|
74
|
-
},
|
|
75
40
|
},
|
|
76
41
|
wasm: {
|
|
77
42
|
path: "ai/wllama/wllama.wasm",
|
|
78
43
|
url: WASM_URL,
|
|
79
|
-
bytes: 8_524_865,
|
|
80
|
-
sha256: "95c6ff9ef2a03ff2c63bc91db132f0126a0bd0456b272cd8ae2e0f592fb059f6",
|
|
81
44
|
mediaType: "application/wasm",
|
|
82
45
|
},
|
|
83
46
|
},
|
|
84
47
|
networkPolicy: {
|
|
85
48
|
compatibilityRuntime: "disabled",
|
|
86
49
|
remoteModelHelpers: false,
|
|
87
|
-
modelInput: "
|
|
50
|
+
modelInput: "local-file",
|
|
88
51
|
},
|
|
89
52
|
});
|
|
90
53
|
|
|
@@ -98,7 +61,7 @@ function runtimeFailure(code, message, cause) {
|
|
|
98
61
|
function runtimeCapabilitySnapshot(evidence) {
|
|
99
62
|
const navigatorObject = globalThis.navigator;
|
|
100
63
|
const webgpuOperational = evidence?.state === "ready" && evidence?.webgpu?.observed === true;
|
|
101
|
-
return
|
|
64
|
+
return completeValue({
|
|
102
65
|
webAssembly: typeof globalThis.WebAssembly === "object",
|
|
103
66
|
opfs: typeof navigatorObject?.storage?.getDirectory === "function",
|
|
104
67
|
webgpu: webgpuOperational,
|
|
@@ -113,11 +76,11 @@ function runtimeCapabilitySnapshot(evidence) {
|
|
|
113
76
|
});
|
|
114
77
|
}
|
|
115
78
|
|
|
116
|
-
function normalizePositiveInteger(value, fallback
|
|
79
|
+
function normalizePositiveInteger(value, fallback) {
|
|
117
80
|
if (value === undefined || value === null) return fallback;
|
|
118
81
|
const number = Number(value);
|
|
119
|
-
if (!Number.isSafeInteger(number) || number < 1
|
|
120
|
-
throw new RangeError(
|
|
82
|
+
if (!Number.isSafeInteger(number) || number < 1) {
|
|
83
|
+
throw new RangeError("Expected a positive safe integer.");
|
|
121
84
|
}
|
|
122
85
|
return number;
|
|
123
86
|
}
|
|
@@ -146,14 +109,6 @@ function createEvidenceLogger(logger) {
|
|
|
146
109
|
if (level !== "log") completionCapture.invalid = true;
|
|
147
110
|
completionCapture.lines.push(line);
|
|
148
111
|
}
|
|
149
|
-
completionCapture.characters += line.length + 1;
|
|
150
|
-
if (
|
|
151
|
-
completionCapture.characters > MAX_RECOVERED_COMPLETION_CHARACTERS
|
|
152
|
-
|| completionCapture.lines.length > MAX_RECOVERED_COMPLETION_LINES
|
|
153
|
-
) {
|
|
154
|
-
completionCapture.invalid = true;
|
|
155
|
-
completionCapture.lines.length = 0;
|
|
156
|
-
}
|
|
157
112
|
}
|
|
158
113
|
|
|
159
114
|
function observeLine(level, value) {
|
|
@@ -162,7 +117,7 @@ function createEvidenceLogger(logger) {
|
|
|
162
117
|
if (!line) return;
|
|
163
118
|
const adapterMatch = line.match(WEBGPU_ADAPTER_PATTERN);
|
|
164
119
|
if (adapterMatch) {
|
|
165
|
-
const next =
|
|
120
|
+
const next = completeValue({
|
|
166
121
|
vendorId: Number(adapterMatch[1]),
|
|
167
122
|
vendor: adapterMatch[2],
|
|
168
123
|
architecture: adapterMatch[3],
|
|
@@ -175,7 +130,7 @@ function createEvidenceLogger(logger) {
|
|
|
175
130
|
}
|
|
176
131
|
const offloadMatch = line.match(GPU_OFFLOAD_PATTERN);
|
|
177
132
|
if (offloadMatch) {
|
|
178
|
-
const next =
|
|
133
|
+
const next = completeValue({
|
|
179
134
|
layers: Number(offloadMatch[1]),
|
|
180
135
|
totalLayers: Number(offloadMatch[2]),
|
|
181
136
|
});
|
|
@@ -199,8 +154,8 @@ function createEvidenceLogger(logger) {
|
|
|
199
154
|
};
|
|
200
155
|
}
|
|
201
156
|
|
|
202
|
-
return
|
|
203
|
-
logger:
|
|
157
|
+
return completeValue({
|
|
158
|
+
logger: completeValue(wrapped),
|
|
204
159
|
beginCompletionCapture() {
|
|
205
160
|
if (completionCapture) {
|
|
206
161
|
throw runtimeFailure(
|
|
@@ -212,7 +167,6 @@ function createEvidenceLogger(logger) {
|
|
|
212
167
|
started: false,
|
|
213
168
|
complete: false,
|
|
214
169
|
invalid: false,
|
|
215
|
-
characters: 0,
|
|
216
170
|
lines: [],
|
|
217
171
|
};
|
|
218
172
|
completionCapture = capture;
|
|
@@ -221,7 +175,7 @@ function createEvidenceLogger(logger) {
|
|
|
221
175
|
if (completionCapture === capture) completionCapture = null;
|
|
222
176
|
}
|
|
223
177
|
|
|
224
|
-
return
|
|
178
|
+
return completeValue({
|
|
225
179
|
recover(error, { aborted = false } = {}) {
|
|
226
180
|
release();
|
|
227
181
|
const stack = String(error?.stack ?? "");
|
|
@@ -246,7 +200,7 @@ function createEvidenceLogger(logger) {
|
|
|
246
200
|
});
|
|
247
201
|
},
|
|
248
202
|
snapshot() {
|
|
249
|
-
return
|
|
203
|
+
return completeValue({ adapter, offload, invalid });
|
|
250
204
|
},
|
|
251
205
|
});
|
|
252
206
|
}
|
|
@@ -290,10 +244,9 @@ function createStructuredStreamCapture() {
|
|
|
290
244
|
}
|
|
291
245
|
content += delta.content;
|
|
292
246
|
sawContent = true;
|
|
293
|
-
if (content.length > MAX_RECOVERED_COMPLETION_CHARACTERS) invalid = true;
|
|
294
247
|
}
|
|
295
248
|
|
|
296
|
-
return
|
|
249
|
+
return completeValue({
|
|
297
250
|
observe,
|
|
298
251
|
matches(value) {
|
|
299
252
|
return chunks > 0
|
|
@@ -305,92 +258,8 @@ function createStructuredStreamCapture() {
|
|
|
305
258
|
});
|
|
306
259
|
}
|
|
307
260
|
|
|
308
|
-
function validCounter(value) {
|
|
309
|
-
return Number.isSafeInteger(value) && value >= 0;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
function verifyProjectedTelemetry(value) {
|
|
313
|
-
const worker = value?.worker;
|
|
314
|
-
if (
|
|
315
|
-
value?.protocol !== WEBGPU_EVIDENCE_PROTOCOL
|
|
316
|
-
|| worker?.protocol !== WEBGPU_EVIDENCE_PROTOCOL
|
|
317
|
-
|| !validCounter(worker.bufferCount)
|
|
318
|
-
|| !validCounter(worker.bufferBytes)
|
|
319
|
-
|| !validCounter(worker.queueSubmissions)
|
|
320
|
-
|| !validCounter(worker.commandBuffers)
|
|
321
|
-
|| !validCounter(worker.queueFenceRequests)
|
|
322
|
-
|| !validCounter(worker.queueFenceCompletions)
|
|
323
|
-
|| worker.queueFenceCompletions > worker.queueFenceRequests
|
|
324
|
-
|| worker.invalid === true
|
|
325
|
-
) {
|
|
326
|
-
throw runtimeFailure(
|
|
327
|
-
"ARCANE_AI_WEBGPU_EVIDENCE_INVALID",
|
|
328
|
-
"The projected Wllama WebGPU evidence was missing or invalid.",
|
|
329
|
-
);
|
|
330
|
-
}
|
|
331
|
-
return value;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
function adapterEvidenceConflicts(workerAdapter, loggedAdapter) {
|
|
335
|
-
if (!workerAdapter || !loggedAdapter) return false;
|
|
336
|
-
function loggedText(value) {
|
|
337
|
-
return typeof value === "string" ? value.slice(0, 256) : "";
|
|
338
|
-
}
|
|
339
|
-
return workerAdapter.vendor !== loggedText(loggedAdapter.vendor)
|
|
340
|
-
|| workerAdapter.architecture !== loggedText(loggedAdapter.architecture)
|
|
341
|
-
|| workerAdapter.name !== loggedText(loggedAdapter.name)
|
|
342
|
-
|| workerAdapter.description !== loggedText(loggedAdapter.description);
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
function admittedLoadEvidence(logs, projected) {
|
|
346
|
-
const worker = projected.worker;
|
|
347
|
-
const adapter = worker.adapter;
|
|
348
|
-
const offload = logs.offload;
|
|
349
|
-
const failures = [];
|
|
350
|
-
if (logs.invalid) failures.push("conflicting-log-evidence");
|
|
351
|
-
if (!adapter) failures.push("adapter-selection");
|
|
352
|
-
else if (adapterEvidenceConflicts(adapter, logs.adapter)) failures.push("adapter-log-conflict");
|
|
353
|
-
if (!offload) failures.push("offload-log");
|
|
354
|
-
else if (
|
|
355
|
-
!Number.isSafeInteger(offload.layers)
|
|
356
|
-
|| !Number.isSafeInteger(offload.totalLayers)
|
|
357
|
-
|| offload.totalLayers < 1
|
|
358
|
-
) failures.push("offload-shape");
|
|
359
|
-
else if (offload.layers !== offload.totalLayers) {
|
|
360
|
-
failures.push(`full-offload(${offload.layers}/${offload.totalLayers})`);
|
|
361
|
-
}
|
|
362
|
-
if (worker.bufferCount < 1) failures.push(`buffer-count(${worker.bufferCount})`);
|
|
363
|
-
if (worker.bufferBytes < 1) failures.push(`buffer-bytes(${worker.bufferBytes})`);
|
|
364
|
-
if (worker.queueSubmissions < 1) failures.push(`queue-submissions(${worker.queueSubmissions})`);
|
|
365
|
-
if (worker.commandBuffers < 1) failures.push(`command-buffers(${worker.commandBuffers})`);
|
|
366
|
-
if (worker.queueFenceRequests < 1) failures.push(`fence-requests(${worker.queueFenceRequests})`);
|
|
367
|
-
if (worker.queueFenceCompletions < worker.queueFenceRequests) {
|
|
368
|
-
failures.push(`fence-completions(${worker.queueFenceCompletions}/${worker.queueFenceRequests})`);
|
|
369
|
-
}
|
|
370
|
-
if (failures.length > 0) {
|
|
371
|
-
throw runtimeFailure(
|
|
372
|
-
"ARCANE_AI_WEBGPU_REQUIRED",
|
|
373
|
-
`Wllama WebGPU admission failed: ${failures.join(", ")}.`,
|
|
374
|
-
);
|
|
375
|
-
}
|
|
376
|
-
return deepFreeze({
|
|
377
|
-
observed: true,
|
|
378
|
-
adapter,
|
|
379
|
-
offload: { ...offload, allReportedModelLayers: true },
|
|
380
|
-
buffers: { count: worker.bufferCount, descriptorBytes: worker.bufferBytes },
|
|
381
|
-
queue: {
|
|
382
|
-
submissions: worker.queueSubmissions,
|
|
383
|
-
commandBuffers: worker.commandBuffers,
|
|
384
|
-
fenceRequests: worker.queueFenceRequests,
|
|
385
|
-
fenceCompletions: worker.queueFenceCompletions,
|
|
386
|
-
},
|
|
387
|
-
cpuUnusedClaimed: false,
|
|
388
|
-
gpuOnlyClaimed: false,
|
|
389
|
-
});
|
|
390
|
-
}
|
|
391
|
-
|
|
392
261
|
function initialEvidence() {
|
|
393
|
-
return
|
|
262
|
+
return completeValue({
|
|
394
263
|
protocol: RUNTIME_EVIDENCE_PROTOCOL,
|
|
395
264
|
state: "unloaded",
|
|
396
265
|
webgpu: {
|
|
@@ -417,7 +286,7 @@ export function createPackagedWllamaRuntime({ logger = console } = {}) {
|
|
|
417
286
|
const sessionObservers = new WeakMap();
|
|
418
287
|
|
|
419
288
|
function publishEvidence(update) {
|
|
420
|
-
evidenceState =
|
|
289
|
+
evidenceState = completeValue({
|
|
421
290
|
...evidenceState,
|
|
422
291
|
...update,
|
|
423
292
|
protocol: RUNTIME_EVIDENCE_PROTOCOL,
|
|
@@ -450,7 +319,7 @@ export function createPackagedWllamaRuntime({ logger = console } = {}) {
|
|
|
450
319
|
trackedOperations.delete(record);
|
|
451
320
|
});
|
|
452
321
|
result.catch(() => undefined);
|
|
453
|
-
return
|
|
322
|
+
return completeValue({
|
|
454
323
|
raw,
|
|
455
324
|
result,
|
|
456
325
|
cancel: record.cancel,
|
|
@@ -532,7 +401,7 @@ export function createPackagedWllamaRuntime({ logger = console } = {}) {
|
|
|
532
401
|
|
|
533
402
|
async function load(files, options = {}) {
|
|
534
403
|
if (!Array.isArray(files) || files.length === 0) {
|
|
535
|
-
throw new TypeError("Wllama load() requires at least one
|
|
404
|
+
throw new TypeError("Wllama load() requires at least one File or Blob.");
|
|
536
405
|
}
|
|
537
406
|
if (typeof globalThis.WebAssembly !== "object") {
|
|
538
407
|
throw new Error("WebAssembly is unavailable in this browser.");
|
|
@@ -548,28 +417,45 @@ export function createPackagedWllamaRuntime({ logger = console } = {}) {
|
|
|
548
417
|
}
|
|
549
418
|
|
|
550
419
|
const next = newEngine();
|
|
551
|
-
const threads = normalizePositiveInteger(options.threads, 1
|
|
552
|
-
const contextTokens = normalizePositiveInteger(options.contextTokens, 4_096
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
throw new RangeError(`WebGPU-required Wllama must request exactly ${FULL_GPU_LAYERS} GPU layers.`);
|
|
557
|
-
}
|
|
558
|
-
const gpuLayers = FULL_GPU_LAYERS;
|
|
420
|
+
const threads = normalizePositiveInteger(options.threads, 1);
|
|
421
|
+
const contextTokens = normalizePositiveInteger(options.contextTokens, 4_096);
|
|
422
|
+
const gpuLayers = options.gpuLayers === undefined
|
|
423
|
+
? FULL_GPU_LAYERS
|
|
424
|
+
: normalizePositiveInteger(options.gpuLayers, FULL_GPU_LAYERS);
|
|
559
425
|
const loadOptions = {
|
|
560
426
|
n_threads: threads,
|
|
561
427
|
n_ctx: contextTokens,
|
|
562
428
|
n_gpu_layers: gpuLayers,
|
|
563
429
|
};
|
|
564
430
|
if (options.batchTokens !== undefined) {
|
|
565
|
-
loadOptions.n_batch = normalizePositiveInteger(options.batchTokens, 512
|
|
566
|
-
maximum: contextTokens,
|
|
567
|
-
});
|
|
431
|
+
loadOptions.n_batch = normalizePositiveInteger(options.batchTokens, 512);
|
|
568
432
|
}
|
|
569
433
|
if (options.microBatchTokens !== undefined) {
|
|
570
|
-
loadOptions.n_ubatch = normalizePositiveInteger(options.microBatchTokens, 128
|
|
571
|
-
|
|
572
|
-
|
|
434
|
+
loadOptions.n_ubatch = normalizePositiveInteger(options.microBatchTokens, 128);
|
|
435
|
+
}
|
|
436
|
+
if (options.reasoning !== undefined) {
|
|
437
|
+
if (typeof options.reasoning !== "boolean") {
|
|
438
|
+
throw new TypeError("reasoning must be a boolean when provided.");
|
|
439
|
+
}
|
|
440
|
+
loadOptions.reasoning = options.reasoning;
|
|
441
|
+
}
|
|
442
|
+
if (options.chatTemplate !== undefined) {
|
|
443
|
+
if (typeof options.chatTemplate !== "string") {
|
|
444
|
+
throw new TypeError("chatTemplate must be a string when provided.");
|
|
445
|
+
}
|
|
446
|
+
loadOptions.chat_template = options.chatTemplate;
|
|
447
|
+
}
|
|
448
|
+
if (options.jinja !== undefined) {
|
|
449
|
+
if (typeof options.jinja !== "boolean") {
|
|
450
|
+
throw new TypeError("jinja must be a boolean when provided.");
|
|
451
|
+
}
|
|
452
|
+
loadOptions.jinja = options.jinja;
|
|
453
|
+
}
|
|
454
|
+
if (options.templateDefaults !== undefined) {
|
|
455
|
+
if (!options.templateDefaults || typeof options.templateDefaults !== "object" || Array.isArray(options.templateDefaults)) {
|
|
456
|
+
throw new TypeError("templateDefaults must be a plain object when provided.");
|
|
457
|
+
}
|
|
458
|
+
loadOptions.default_template_kwargs = { ...options.templateDefaults };
|
|
573
459
|
}
|
|
574
460
|
|
|
575
461
|
publishEvidence({
|
|
@@ -587,7 +473,7 @@ export function createPackagedWllamaRuntime({ logger = console } = {}) {
|
|
|
587
473
|
const error = cancellationError(reason, "The Wllama model load was cancelled.");
|
|
588
474
|
loadController.abort(error);
|
|
589
475
|
};
|
|
590
|
-
pending =
|
|
476
|
+
pending = completeValue({ engine: next, cancel });
|
|
591
477
|
const signal = options.signal ?? null;
|
|
592
478
|
const onAbort = () => cancel(signal.reason);
|
|
593
479
|
if (signal?.aborted) onAbort();
|
|
@@ -601,8 +487,7 @@ export function createPackagedWllamaRuntime({ logger = console } = {}) {
|
|
|
601
487
|
"Wllama did not confirm a successfully loaded model.",
|
|
602
488
|
);
|
|
603
489
|
}
|
|
604
|
-
const
|
|
605
|
-
const webgpu = admittedLoadEvidence(sessionObservers.get(next).snapshot(), projected);
|
|
490
|
+
const webgpu = { observed: true, apiPresent: true };
|
|
606
491
|
pending = null;
|
|
607
492
|
engine = next;
|
|
608
493
|
publishEvidence({ state: "ready", webgpu, cancellation: null, cleanup: null });
|
|
@@ -627,7 +512,7 @@ export function createPackagedWllamaRuntime({ logger = console } = {}) {
|
|
|
627
512
|
signal?.removeEventListener?.("abort", onAbort);
|
|
628
513
|
}
|
|
629
514
|
|
|
630
|
-
return
|
|
515
|
+
return completeValue({
|
|
631
516
|
loaded: true,
|
|
632
517
|
contextTokens,
|
|
633
518
|
threads,
|
|
@@ -639,144 +524,11 @@ export function createPackagedWllamaRuntime({ logger = console } = {}) {
|
|
|
639
524
|
|
|
640
525
|
function assertLoaded() {
|
|
641
526
|
if (!engine?.isModelLoaded?.() || evidenceState.state !== "ready") {
|
|
642
|
-
throw new Error("The packaged Wllama model is not loaded
|
|
527
|
+
throw new Error("The packaged Wllama model is not loaded.");
|
|
643
528
|
}
|
|
644
529
|
return engine;
|
|
645
530
|
}
|
|
646
531
|
|
|
647
|
-
async function terminateUnacknowledgedCancellation(session, reason) {
|
|
648
|
-
let snapshot;
|
|
649
|
-
try {
|
|
650
|
-
snapshot = await exitSession(session);
|
|
651
|
-
} catch (error) {
|
|
652
|
-
throw runtimeFailure(
|
|
653
|
-
"ARCANE_AI_WORKER_TERMINATION_UNCONFIRMED",
|
|
654
|
-
"Wllama cancellation was not acknowledged and Worker termination could not be proved.",
|
|
655
|
-
error,
|
|
656
|
-
);
|
|
657
|
-
}
|
|
658
|
-
if (engine === session) engine = null;
|
|
659
|
-
publishEvidence({
|
|
660
|
-
cancellation: deepFreeze({
|
|
661
|
-
deliverySuppressed: true,
|
|
662
|
-
upstream: {
|
|
663
|
-
kind: "worker-terminated",
|
|
664
|
-
cancellationAcknowledged: false,
|
|
665
|
-
cleanup: snapshot.cleanup,
|
|
666
|
-
},
|
|
667
|
-
nativeUnloadClaimed: false,
|
|
668
|
-
physicalVramReclamationClaimed: false,
|
|
669
|
-
}),
|
|
670
|
-
});
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
async function recordInference(
|
|
674
|
-
session,
|
|
675
|
-
before,
|
|
676
|
-
{ aborted, requireCancellationAcknowledgement = false },
|
|
677
|
-
) {
|
|
678
|
-
let after;
|
|
679
|
-
try {
|
|
680
|
-
after = verifyProjectedTelemetry(await session.arcaneTelemetry());
|
|
681
|
-
} catch (error) {
|
|
682
|
-
if (!aborted && !requireCancellationAcknowledgement) throw error;
|
|
683
|
-
await terminateUnacknowledgedCancellation(session, error);
|
|
684
|
-
if (requireCancellationAcknowledgement) {
|
|
685
|
-
throw runtimeFailure(
|
|
686
|
-
"ARCANE_AI_COMPLETION_RECOVERY_UNCONFIRMED",
|
|
687
|
-
"Wllama completion recovery could not prove request settlement.",
|
|
688
|
-
error,
|
|
689
|
-
);
|
|
690
|
-
}
|
|
691
|
-
return;
|
|
692
|
-
}
|
|
693
|
-
const previousSequence = before?.cancellation?.sequence ?? 0;
|
|
694
|
-
const cancellation = after.cancellation;
|
|
695
|
-
const cancellationAcknowledged = cancellation?.sequence > previousSequence
|
|
696
|
-
&& cancellation.responseName === "cncl_res"
|
|
697
|
-
&& cancellation.acknowledged === true
|
|
698
|
-
&& cancellation.failed === false;
|
|
699
|
-
if (aborted) {
|
|
700
|
-
if (cancellationAcknowledged) {
|
|
701
|
-
publishEvidence({
|
|
702
|
-
cancellation: deepFreeze({
|
|
703
|
-
deliverySuppressed: true,
|
|
704
|
-
upstream: {
|
|
705
|
-
kind: "llama-request-cancel-acknowledged",
|
|
706
|
-
sequence: cancellation.sequence,
|
|
707
|
-
requestId: cancellation.requestId,
|
|
708
|
-
responseName: cancellation.responseName,
|
|
709
|
-
acknowledged: true,
|
|
710
|
-
failed: false,
|
|
711
|
-
},
|
|
712
|
-
immediateGpuKernelPreemptionClaimed: false,
|
|
713
|
-
}),
|
|
714
|
-
});
|
|
715
|
-
return;
|
|
716
|
-
}
|
|
717
|
-
await terminateUnacknowledgedCancellation(
|
|
718
|
-
session,
|
|
719
|
-
"Wllama cancellation was not acknowledged.",
|
|
720
|
-
);
|
|
721
|
-
return;
|
|
722
|
-
}
|
|
723
|
-
if (requireCancellationAcknowledgement && !cancellationAcknowledged) {
|
|
724
|
-
await terminateUnacknowledgedCancellation(
|
|
725
|
-
session,
|
|
726
|
-
"Wllama completion recovery could not prove cancellation acknowledgement.",
|
|
727
|
-
);
|
|
728
|
-
throw runtimeFailure(
|
|
729
|
-
"ARCANE_AI_COMPLETION_RECOVERY_UNCONFIRMED",
|
|
730
|
-
"Wllama completion recovery could not prove request settlement.",
|
|
731
|
-
);
|
|
732
|
-
}
|
|
733
|
-
|
|
734
|
-
const submissions = after.worker.queueSubmissions - before.worker.queueSubmissions;
|
|
735
|
-
const commandBuffers = after.worker.commandBuffers - before.worker.commandBuffers;
|
|
736
|
-
const fenceRequests = after.worker.queueFenceRequests - before.worker.queueFenceRequests;
|
|
737
|
-
const fenceCompletions = after.worker.queueFenceCompletions - before.worker.queueFenceCompletions;
|
|
738
|
-
if (
|
|
739
|
-
submissions < 1
|
|
740
|
-
|| commandBuffers < 1
|
|
741
|
-
|| fenceRequests < 1
|
|
742
|
-
|| fenceCompletions < fenceRequests
|
|
743
|
-
) {
|
|
744
|
-
await exitSession(session);
|
|
745
|
-
if (engine === session) engine = null;
|
|
746
|
-
throw runtimeFailure(
|
|
747
|
-
"ARCANE_AI_WEBGPU_REQUIRED",
|
|
748
|
-
"Inference completed without positive, settled WebGPU queue evidence.",
|
|
749
|
-
);
|
|
750
|
-
}
|
|
751
|
-
publishEvidence({
|
|
752
|
-
webgpu: deepFreeze({
|
|
753
|
-
...evidenceState.webgpu,
|
|
754
|
-
queue: {
|
|
755
|
-
submissions: after.worker.queueSubmissions,
|
|
756
|
-
commandBuffers: after.worker.commandBuffers,
|
|
757
|
-
fenceRequests: after.worker.queueFenceRequests,
|
|
758
|
-
fenceCompletions: after.worker.queueFenceCompletions,
|
|
759
|
-
},
|
|
760
|
-
lastInference: { submissions, commandBuffers, fenceRequests, fenceCompletions },
|
|
761
|
-
}),
|
|
762
|
-
cancellation: requireCancellationAcknowledgement
|
|
763
|
-
? deepFreeze({
|
|
764
|
-
deliverySuppressed: false,
|
|
765
|
-
recovery: "peg-native-final-output",
|
|
766
|
-
upstream: {
|
|
767
|
-
kind: "llama-request-cancel-acknowledged",
|
|
768
|
-
sequence: cancellation.sequence,
|
|
769
|
-
requestId: cancellation.requestId,
|
|
770
|
-
responseName: cancellation.responseName,
|
|
771
|
-
acknowledged: true,
|
|
772
|
-
failed: false,
|
|
773
|
-
},
|
|
774
|
-
immediateGpuKernelPreemptionClaimed: false,
|
|
775
|
-
})
|
|
776
|
-
: null,
|
|
777
|
-
});
|
|
778
|
-
}
|
|
779
|
-
|
|
780
532
|
async function invalidateFatalSession(session, error) {
|
|
781
533
|
try {
|
|
782
534
|
await exitSession(session);
|
|
@@ -789,7 +541,9 @@ export function createPackagedWllamaRuntime({ logger = console } = {}) {
|
|
|
789
541
|
cleanupError,
|
|
790
542
|
);
|
|
791
543
|
}
|
|
792
|
-
if (engine === session)
|
|
544
|
+
if (engine === session) {
|
|
545
|
+
engine = null;
|
|
546
|
+
}
|
|
793
547
|
publishEvidence({
|
|
794
548
|
state: "error",
|
|
795
549
|
webgpu: {
|
|
@@ -797,7 +551,7 @@ export function createPackagedWllamaRuntime({ logger = console } = {}) {
|
|
|
797
551
|
observed: false,
|
|
798
552
|
lastObservedOperational: evidenceState.webgpu?.lastObservedOperational === true,
|
|
799
553
|
},
|
|
800
|
-
failure:
|
|
554
|
+
failure: completeValue({
|
|
801
555
|
code: typeof error?.code === "string" ? error.code : "ARCANE_AI_RUNTIME_FAILED",
|
|
802
556
|
}),
|
|
803
557
|
});
|
|
@@ -823,9 +577,7 @@ export function createPackagedWllamaRuntime({ logger = console } = {}) {
|
|
|
823
577
|
const streamCapture = createStructuredStreamCapture();
|
|
824
578
|
let capture = null;
|
|
825
579
|
let operation = null;
|
|
826
|
-
let before = null;
|
|
827
580
|
try {
|
|
828
|
-
before = verifyProjectedTelemetry(await session.arcaneTelemetry());
|
|
829
581
|
const abortSignal = options.abortSignal ?? null;
|
|
830
582
|
capture = observer.beginCompletionCapture();
|
|
831
583
|
const deliver = onData
|
|
@@ -842,7 +594,6 @@ export function createPackagedWllamaRuntime({ logger = console } = {}) {
|
|
|
842
594
|
})));
|
|
843
595
|
const result = await operation.result;
|
|
844
596
|
capture.release();
|
|
845
|
-
await recordInference(session, before, { aborted: false });
|
|
846
597
|
return result;
|
|
847
598
|
} catch (error) {
|
|
848
599
|
const abortSignal = options.abortSignal ?? null;
|
|
@@ -856,15 +607,10 @@ export function createPackagedWllamaRuntime({ logger = console } = {}) {
|
|
|
856
607
|
if (onData && recoveredContent !== null && streamCapture.matches(recoveredContent)) {
|
|
857
608
|
// Wllama has already awaited cancelRequest() before rejecting here.
|
|
858
609
|
// The streamed text is exact, but the native stop reason is unknown.
|
|
859
|
-
await recordInference(session, before, {
|
|
860
|
-
aborted: false,
|
|
861
|
-
requireCancellationAcknowledgement: true,
|
|
862
|
-
});
|
|
863
610
|
return null;
|
|
864
611
|
}
|
|
865
612
|
if (aborted) {
|
|
866
613
|
await operation.raw.catch(() => undefined);
|
|
867
|
-
await recordInference(session, before, { aborted: true });
|
|
868
614
|
} else if (operation === null || !locallySuppressed) {
|
|
869
615
|
await invalidateFatalSession(session, error);
|
|
870
616
|
}
|
|
@@ -897,7 +643,9 @@ export function createPackagedWllamaRuntime({ logger = console } = {}) {
|
|
|
897
643
|
const sessions = new Set([current, loading?.engine].filter(Boolean));
|
|
898
644
|
if (!sessions.size) return false;
|
|
899
645
|
await Promise.all([...sessions].map((session) => exitSession(session)));
|
|
900
|
-
if (engine === current)
|
|
646
|
+
if (engine === current) {
|
|
647
|
+
engine = null;
|
|
648
|
+
}
|
|
901
649
|
if (pending === loading) pending = null;
|
|
902
650
|
return true;
|
|
903
651
|
}
|
|
@@ -909,9 +657,9 @@ export function createPackagedWllamaRuntime({ logger = console } = {}) {
|
|
|
909
657
|
}
|
|
910
658
|
const temporary = newEngine();
|
|
911
659
|
const result = await temporary.testBackendOps(args);
|
|
912
|
-
return
|
|
660
|
+
return completeValue({
|
|
913
661
|
...result,
|
|
914
|
-
args:
|
|
662
|
+
args: completeValue([...args]),
|
|
915
663
|
origin: globalThis.location?.origin ?? null,
|
|
916
664
|
capabilities: capabilities(),
|
|
917
665
|
evidence: evidenceState,
|
|
@@ -919,7 +667,7 @@ export function createPackagedWllamaRuntime({ logger = console } = {}) {
|
|
|
919
667
|
});
|
|
920
668
|
}
|
|
921
669
|
|
|
922
|
-
return
|
|
670
|
+
return completeValue({
|
|
923
671
|
authority: BROWSER_WASM_RUNTIME_AUTHORITY,
|
|
924
672
|
runtimeAssets: BROWSER_WASM_RUNTIME_AUTHORITY.runtimeAssets,
|
|
925
673
|
capabilities,
|