arcane-os 0.7.3 → 0.8.1
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 +20 -0
- package/README.md +8 -8
- package/browser-runtime/ai/browser-speech-artifacts.mjs +47 -0
- package/browser-runtime/ai/browser-speech.mjs +1 -0
- package/docs/architecture.md +1 -1
- package/docs/reference/ai/browser-speech.md +27 -0
- package/docs/reference/asset-versioning.md +11 -4
- package/docs/reference/runtime-modules.md +9 -0
- package/docs/reference/sdk-api.md +19 -0
- package/package.json +2 -2
- package/runtime/arcane/modules/HTMLImport.js +18 -5
- package/src/import-map.mjs +24 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.8.1
|
|
4
|
+
|
|
5
|
+
- Use `arcaneVersion` as the sole local resource version field across import maps,
|
|
6
|
+
runtime materialization, source serving, packaged applications, and dynamic
|
|
7
|
+
components. Remove `v` and duplicate version fields while preserving unrelated
|
|
8
|
+
query parameters, fragments, and ordinary caching.
|
|
9
|
+
- Reuse the registered `html-import` constructor across module URL variants,
|
|
10
|
+
including overlapping application startup and developer error-dialog imports.
|
|
11
|
+
Prevent duplicate custom-element registration from raising `NotSupportedError`
|
|
12
|
+
while preserving component loading, readiness, teardown, and existing instances.
|
|
13
|
+
|
|
14
|
+
## 0.8.0
|
|
15
|
+
|
|
16
|
+
- Add `removeBrowserSpeechModelCache()` to remove an explicitly retired Hugging
|
|
17
|
+
Face speech model from the current browser origin's upstream cache. Preserve
|
|
18
|
+
other models, voices, runtimes, DBOPFS artifacts, and preferences; report each
|
|
19
|
+
completed removal and surface cancellation or partial failure.
|
|
20
|
+
- Keep model retirement policy in consuming applications. The operation starts
|
|
21
|
+
no model download or inference and leaves NPU, GPU, and CPU selection unchanged.
|
|
22
|
+
|
|
3
23
|
## 0.7.3
|
|
4
24
|
|
|
5
25
|
- Correct public development serving for OPFS/DBOPFS and other browser APIs
|
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ version-locked SDK runtime, while an integrated Arcane checkout uses its live
|
|
|
19
19
|
`arcane/` runtime. Both profiles preserve the same app URLs, theme, packaging,
|
|
20
20
|
event, cancellation, and browser run contracts.
|
|
21
21
|
|
|
22
|
-
This checkout defines the `0.
|
|
22
|
+
This checkout defines the `0.8.1` SDK contract. Applications pin one exact npm
|
|
23
23
|
version and lockfile; registry state is deliberately not baked into application
|
|
24
24
|
artifacts.
|
|
25
25
|
|
|
@@ -35,7 +35,7 @@ Create one browser application, install its pinned SDK, and start its source
|
|
|
35
35
|
server:
|
|
36
36
|
|
|
37
37
|
```bash
|
|
38
|
-
npx arcane-os@0.
|
|
38
|
+
npx arcane-os@0.8.1 new hello-speech --path ./hello-speech --target browser
|
|
39
39
|
cd hello-speech
|
|
40
40
|
npm install
|
|
41
41
|
npm run dev
|
|
@@ -386,7 +386,7 @@ uses the same controller for automatic memory extraction.
|
|
|
386
386
|
Create a new repository-shaped Arcane application with the exact stable SDK:
|
|
387
387
|
|
|
388
388
|
```bash
|
|
389
|
-
npx arcane-os@0.
|
|
389
|
+
npx arcane-os@0.8.1 new my-app --path ./my-app --target portable --git
|
|
390
390
|
cd my-app
|
|
391
391
|
npm install
|
|
392
392
|
npm run dev
|
|
@@ -396,7 +396,7 @@ To enroll an existing repository, install the exact SDK and initialize only
|
|
|
396
396
|
missing Arcane files:
|
|
397
397
|
|
|
398
398
|
```bash
|
|
399
|
-
npm install --save-dev --save-exact arcane-os@0.
|
|
399
|
+
npm install --save-dev --save-exact arcane-os@0.8.1
|
|
400
400
|
npm exec -- arcane init my-app --target portable
|
|
401
401
|
```
|
|
402
402
|
|
|
@@ -412,7 +412,7 @@ npm exec -- arcane-os targets
|
|
|
412
412
|
No global SDK install or standalone Arcane CLI is required. The application
|
|
413
413
|
repository's exact npm dependency and lockfile own the CLI and toolchain version.
|
|
414
414
|
|
|
415
|
-
Use `npx arcane-os@0.
|
|
415
|
+
Use `npx arcane-os@0.8.1` for the initial bootstrap because it names this npm
|
|
416
416
|
package explicitly; bare `npx arcane` outside an installed project could resolve
|
|
417
417
|
a different package. Both installed commands invoke the same headless toolchain.
|
|
418
418
|
Project-local npm scripts use the SDK pinned by that app's `package-lock.json`,
|
|
@@ -432,7 +432,7 @@ node ./bin/arcane.mjs new local-app --path ../local-app --target portable --git
|
|
|
432
432
|
|
|
433
433
|
# From the generated app repository
|
|
434
434
|
cd ../local-app
|
|
435
|
-
npm install --save-dev --save-exact ../arcane-os-sdk/arcane-os-0.
|
|
435
|
+
npm install --save-dev --save-exact ../arcane-os-sdk/arcane-os-0.8.1.tgz
|
|
436
436
|
npm ci
|
|
437
437
|
```
|
|
438
438
|
|
|
@@ -441,7 +441,7 @@ same location. The lockfile retains the selected package dependency while
|
|
|
441
441
|
Arcane uses the installed package name and version. Local directory `file:` dependencies are not
|
|
442
442
|
accepted because npm may install them as links; use a packed `.tgz`. A GitHub
|
|
443
443
|
runner also needs that tarball at the locked path. After publication, replace
|
|
444
|
-
the local declaration with the exact `arcane-os@0.
|
|
444
|
+
the local declaration with the exact `arcane-os@0.8.1` registry package and
|
|
445
445
|
commit the regenerated lock.
|
|
446
446
|
|
|
447
447
|
Generated repositories use `npm ci --ignore-scripts` in CI. Run dependency
|
|
@@ -580,7 +580,7 @@ package installation, or assertions.
|
|
|
580
580
|
|
|
581
581
|
## Current target support
|
|
582
582
|
|
|
583
|
-
Version `0.
|
|
583
|
+
Version `0.8.1` exposes one browser target and five explicitly paired
|
|
584
584
|
native development targets: a non-runnable portable directory, a
|
|
585
585
|
Windows x64 unsigned-local-test EXE bundle, Linux x64 and Linux ARM64
|
|
586
586
|
unsigned-local-test DEBs, and an Android development-signed APK. The
|
|
@@ -2331,6 +2331,53 @@ export function createDbopfsSpeechArtifactStore({
|
|
|
2331
2331
|
return store;
|
|
2332
2332
|
}
|
|
2333
2333
|
|
|
2334
|
+
export async function removeBrowserSpeechModelCache(
|
|
2335
|
+
{repository, cacheStorage = globalThis.caches, signal} = {}
|
|
2336
|
+
) {
|
|
2337
|
+
const selectedRepository = requiredText(repository, 'repository');
|
|
2338
|
+
const removed = [];
|
|
2339
|
+
const result = {repository: selectedRepository, removed};
|
|
2340
|
+
const modelPath = `/${selectedRepository.split('/').map(encodeURIComponent).join('/')}/resolve/`;
|
|
2341
|
+
|
|
2342
|
+
try {
|
|
2343
|
+
throwIfAborted(signal);
|
|
2344
|
+
if (!is.function(cacheStorage?.has) || !is.function(cacheStorage?.open)) {
|
|
2345
|
+
throw speechError(
|
|
2346
|
+
'ARCANE_AI_STORAGE_UNAVAILABLE',
|
|
2347
|
+
'Browser model cache storage is unavailable.',
|
|
2348
|
+
undefined,
|
|
2349
|
+
'browser-speech-model-cache-unavailable'
|
|
2350
|
+
);
|
|
2351
|
+
}
|
|
2352
|
+
const cached = await cacheStorage.has('transformers-cache');
|
|
2353
|
+
throwIfAborted(signal);
|
|
2354
|
+
if (!cached) return result;
|
|
2355
|
+
const cache = await cacheStorage.open('transformers-cache');
|
|
2356
|
+
const requests = await cache.keys();
|
|
2357
|
+
for (const request of requests) {
|
|
2358
|
+
throwIfAborted(signal);
|
|
2359
|
+
const url = new URL(request.url);
|
|
2360
|
+
if (url.origin !== 'https://huggingface.co' || !url.pathname.startsWith(modelPath)) {
|
|
2361
|
+
continue;
|
|
2362
|
+
}
|
|
2363
|
+
if (await cache.delete(request)) removed.push(request.url);
|
|
2364
|
+
}
|
|
2365
|
+
throwIfAborted(signal);
|
|
2366
|
+
return result;
|
|
2367
|
+
} catch (cause) {
|
|
2368
|
+
const error = cause?.name === 'AbortError' || isBrowserSpeechArtifactError(cause)
|
|
2369
|
+
? cause
|
|
2370
|
+
: speechError(
|
|
2371
|
+
'ARCANE_AI_STORAGE_DELETE_FAILED',
|
|
2372
|
+
'Unable to remove the selected browser speech model download.',
|
|
2373
|
+
cause,
|
|
2374
|
+
'browser-speech-model-cache-delete-rejected'
|
|
2375
|
+
);
|
|
2376
|
+
error.removed = removed;
|
|
2377
|
+
throw error;
|
|
2378
|
+
}
|
|
2379
|
+
}
|
|
2380
|
+
|
|
2334
2381
|
export function isBrowserSpeechAuthority(value) {
|
|
2335
2382
|
return AUTHORITIES.has(value);
|
|
2336
2383
|
}
|
package/docs/architecture.md
CHANGED
|
@@ -289,7 +289,7 @@ paths are withheld from the native provider. The provider copies the complete
|
|
|
289
289
|
selected release rather than accepting an unrelated source path. Verification
|
|
290
290
|
is a separate explicit operation for a selected release artifact.
|
|
291
291
|
|
|
292
|
-
The SDK `0.
|
|
292
|
+
The SDK `0.8.1` runtime requires Arcane `0.8.12` or newer. Compatibility
|
|
293
293
|
is contractual rather than exact-version pinning: the prepared Core must meet
|
|
294
294
|
the highest minimum declared by the runtime, selected app, and bundled app
|
|
295
295
|
dependencies; keep each app's Arcane protocol generation; and provide every
|
|
@@ -1027,6 +1027,33 @@ forward a security payload to the Worker and performs no security work. Passing
|
|
|
1027
1027
|
`{secure:true}` does not activate hardening. Any future hardening stage requires
|
|
1028
1028
|
a separate user review and an explicit implementation change before it may execute.
|
|
1029
1029
|
|
|
1030
|
+
## `removeBrowserSpeechModelCache()`
|
|
1031
|
+
|
|
1032
|
+
```javascript
|
|
1033
|
+
const removal = await removeBrowserSpeechModelCache(
|
|
1034
|
+
{repository: 'Xenova/whisper-small', signal}
|
|
1035
|
+
);
|
|
1036
|
+
```
|
|
1037
|
+
|
|
1038
|
+
Exported by `arcane-os/ai/browser-speech`. This explicit operation removes all
|
|
1039
|
+
cached revisions of the exact selected Hugging Face model from the current
|
|
1040
|
+
origin's existing `transformers-cache`. It returns `{repository,removed}`,
|
|
1041
|
+
where `removed` contains the complete URLs actually deleted. An absent cache or
|
|
1042
|
+
model returns an empty list. Other models, runtime files, the Kokoro voice
|
|
1043
|
+
cache, DBOPFS files, and preferences remain untouched. No model is loaded or
|
|
1044
|
+
downloaded and no inference is started.
|
|
1045
|
+
|
|
1046
|
+
The caller owns model retirement policy and must stop using the retired model
|
|
1047
|
+
before removal so a live provider cannot download it again. This operation is
|
|
1048
|
+
separate from `store.remove(authority)`, which removes declared DBOPFS files.
|
|
1049
|
+
`cacheStorage` may explicitly supply a CacheStorage implementation; it defaults
|
|
1050
|
+
to `globalThis.caches`. Missing storage rejects with
|
|
1051
|
+
`ARCANE_AI_STORAGE_UNAVAILABLE`; cache failures reject with
|
|
1052
|
+
`ARCANE_AI_STORAGE_DELETE_FAILED`. An aborted `signal` stops further removals
|
|
1053
|
+
with `AbortError`. Deletions already completed are retained in `error.removed`;
|
|
1054
|
+
removal is repeatable and does not claim transactional rollback. The operation
|
|
1055
|
+
enumerates one cache once and awaits each matching deletion in order.
|
|
1056
|
+
|
|
1030
1057
|
## Ordinary module routing
|
|
1031
1058
|
|
|
1032
1059
|
Artifact-graph preparation reads each stored JavaScript module, discovers
|
|
@@ -7,10 +7,11 @@ SDK package metadata, not a timestamp, content measurement, or application
|
|
|
7
7
|
constant.
|
|
8
8
|
|
|
9
9
|
For example, an existing `./arcane/modules/HTMLImport.js?v=6#module` reference
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
becomes `./arcane/modules/HTMLImport.js?arcaneVersion=${version}#module`.
|
|
11
|
+
`arcaneVersion` is the sole resource version field: transformation removes `v`,
|
|
12
|
+
updates the first existing `arcaneVersion`, and removes duplicate version fields.
|
|
13
|
+
Regenerating for another SDK release replaces that version value. Unrelated
|
|
14
|
+
query fields, their spelling, and fragments remain intact.
|
|
14
15
|
|
|
15
16
|
## Public tooling
|
|
16
17
|
|
|
@@ -57,6 +58,12 @@ take effect on ordinary navigation or refresh; they do not replace live module
|
|
|
57
58
|
instances, force a reload, restart a model, or erase a conversation. The SDK does
|
|
58
59
|
not retain earlier installed runtime trees after materialization.
|
|
59
60
|
|
|
61
|
+
`HTMLImport` registers its element once per browser custom-element registry.
|
|
62
|
+
Previously authored revision URLs and the developer error dialog's module URL
|
|
63
|
+
can be different; each import exports the constructor already registered in that
|
|
64
|
+
document. Repeated imports do not replace existing component instances or
|
|
65
|
+
register a second `html-import` definition.
|
|
66
|
+
|
|
60
67
|
## Scope and work
|
|
61
68
|
|
|
62
69
|
One invocation acts on the selected workspace/application. Runtime
|
|
@@ -2052,6 +2052,15 @@ Defines the same-origin `<html-import>` loader with open shadow root, inline scr
|
|
|
2052
2052
|
|
|
2053
2053
|
default `HTMLImport`; registers `html-import`; `connectedCallback()` and `ready`.
|
|
2054
2054
|
|
|
2055
|
+
Registration occurs once per custom-element registry. Imports through different
|
|
2056
|
+
module URLs reuse and export the registered constructor, including overlapping
|
|
2057
|
+
application startup and developer error-dialog imports. Existing component
|
|
2058
|
+
instances, loading, readiness events, and teardown keep that same constructor.
|
|
2059
|
+
|
|
2060
|
+
Local component resources use the loader's `arcaneVersion` as their sole version
|
|
2061
|
+
field. Existing `v` fields are removed; unrelated query fields and fragments
|
|
2062
|
+
remain intact.
|
|
2063
|
+
|
|
2055
2064
|
Exact exports: `default`.
|
|
2056
2065
|
|
|
2057
2066
|
### Availability and normalization
|
|
@@ -125,6 +125,7 @@ browser map are cataloged separately in [Runtime modules](runtime-modules.md).
|
|
|
125
125
|
| `createCanonicalUstarHeader()` | function | `arcane-os` | Packaging and release bundles | Node |
|
|
126
126
|
| `createDbopfsModelStore()` | function | `arcane-os/ai/browser-wasm` | Browser-WASM local AI | Browser with a ready DBOPFS instance and OPFS |
|
|
127
127
|
| `createDbopfsSpeechArtifactStore()` | function | `arcane-os/ai/browser-speech` | Browser speech providers | Browser with ready DBOPFS, Web Locks, Fetch, File/Blob, and object URLs |
|
|
128
|
+
| `removeBrowserSpeechModelCache()` | function | `arcane-os/ai/browser-speech` | Browser speech providers | Browser CacheStorage; explicit removal of one selected upstream model |
|
|
128
129
|
| `createNativeBuildPlan()` | function | `arcane-os` | Targets, native plans, and providers | Node; selected browser/native target or provider as documented |
|
|
129
130
|
| `createNativeTargetAdapter()` | function | `arcane-os` | Targets, native plans, and providers | Node; selected browser/native target or provider as documented |
|
|
130
131
|
| `createReporter()` | function | `arcane-os` | Events, processes, and testing | Node |
|
|
@@ -6396,6 +6397,24 @@ const authority = createBrowserSpeechAuthority({
|
|
|
6396
6397
|
});
|
|
6397
6398
|
```
|
|
6398
6399
|
|
|
6400
|
+
## removeBrowserSpeechModelCache()
|
|
6401
|
+
|
|
6402
|
+
```text
|
|
6403
|
+
removeBrowserSpeechModelCache({ repository, cacheStorage=globalThis.caches, signal }={})
|
|
6404
|
+
```
|
|
6405
|
+
|
|
6406
|
+
Removes cached Hugging Face resources for the exact selected repository, across
|
|
6407
|
+
all revisions, from the current origin's existing `transformers-cache`.
|
|
6408
|
+
Returns `{repository,removed}`, including each complete URL actually deleted.
|
|
6409
|
+
An absent model or cache returns an empty list. The caller must stop using the
|
|
6410
|
+
retired model first; this operation does not unload providers or start inference.
|
|
6411
|
+
Other models, runtime resources, voice caches, declared DBOPFS artifacts, and
|
|
6412
|
+
preferences are preserved. Use `store.remove(authority)` separately for declared
|
|
6413
|
+
DBOPFS artifacts. Missing storage and cache failures surface
|
|
6414
|
+
`ARCANE_AI_STORAGE_UNAVAILABLE` and `ARCANE_AI_STORAGE_DELETE_FAILED`.
|
|
6415
|
+
Cancellation stops subsequent deletions with `AbortError`; `error.removed`
|
|
6416
|
+
retains the complete list of deletions already completed.
|
|
6417
|
+
|
|
6399
6418
|
## createDbopfsSpeechArtifactStore()
|
|
6400
6419
|
|
|
6401
6420
|
### Overview
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "arcane-os",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "Arcane OS JavaScript SDK, project-local CLI, browser runtime, and repository-portable application packager.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.mjs",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"test:unit": "node ./bin/arcane-test.mjs test/app-descriptor.test.mjs test/app-schema.test.mjs test/contracts.test.mjs test/doctor.test.mjs test/mail-credentials.test.mjs test/mail-outbox.test.mjs test/mail-public-api.test.mjs test/mail-send.test.mjs test/mail-transport.test.mjs test/targets.test.mjs test/workspace-operation-lock.test.mjs",
|
|
68
68
|
"test:functional": "node ./bin/arcane-test.mjs test/browser-speech-providers.test.mjs test/browser-wasm-gpu-notice.test.mjs test/browser-wasm-download-resume.test.mjs test/cli.test.mjs test/dbopfs-document-library.test.mjs test/dev-server.test.mjs test/dom-event-instrumentation.test.mjs test/event-manager.test.mjs test/events.test.mjs test/import-map.test.mjs test/mail-cli.test.mjs test/mail-runtime.test.mjs test/mail-server.test.mjs test/packaging.test.mjs test/persistent-ai-chat-session.test.mjs test/reference-completeness.test.mjs test/runtime-api-behavior.test.mjs test/runtime.test.mjs test/scaffold.test.mjs test/speech-playback.test.mjs test/site.test.mjs test/update-check.test.mjs",
|
|
69
69
|
"test:integration": "node ./bin/arcane-test.mjs test/integrated-shared.test.mjs test/integrated-workspace.test.mjs test/mail-browser.test.mjs test/native-plan.test.mjs test/native-provider-loader.test.mjs test/npm-release.test.mjs test/release-bundle.test.mjs test/release-capability-smoke.test.mjs test/shared-payload-batch.test.mjs test/tarball.test.mjs test/wllama-webgpu-runtime.test.mjs",
|
|
70
|
-
"test:regression": "node ./bin/arcane-test.mjs test/channel-workflows.test.mjs test/logging-regression.test.mjs test/markdown-speech.test.mjs test/prepared-speech.test.mjs test/native-provider-generation.test.mjs test/speech-queue-regression.test.mjs test/testing.test.mjs test/test-sets.test.mjs",
|
|
70
|
+
"test:regression": "node ./bin/arcane-test.mjs test/channel-workflows.test.mjs test/html-import-registration.test.mjs test/logging-regression.test.mjs test/markdown-speech.test.mjs test/prepared-speech.test.mjs test/native-provider-generation.test.mjs test/speech-queue-regression.test.mjs test/testing.test.mjs test/test-sets.test.mjs",
|
|
71
71
|
"check": "node tools/check-source.mjs && npm test",
|
|
72
72
|
"check:release": "node tools/check-source.mjs --package-only && npm run test:release",
|
|
73
73
|
"pack:local": "npm pack --ignore-scripts",
|
|
@@ -43,14 +43,21 @@ function versionComponentResource(value,baseHref){
|
|
|
43
43
|
const versionField=`arcaneVersion=${encodeURIComponent(htmlImportAssetVersion)}`;
|
|
44
44
|
let replaced=false;
|
|
45
45
|
const fields=query?query.split('&').map(function versionQueryField(field){
|
|
46
|
-
|
|
46
|
+
const parameter=new URLSearchParams(field);
|
|
47
|
+
if(parameter.has('v'))return null;
|
|
48
|
+
if(!parameter.has('arcaneVersion'))return field;
|
|
47
49
|
if(replaced)return null;
|
|
48
50
|
replaced=true;
|
|
49
|
-
|
|
51
|
+
const equals=field.indexOf('=');
|
|
52
|
+
const key=equals<0?field:field.slice(0,equals);
|
|
53
|
+
return `${key}=${encodeURIComponent(htmlImportAssetVersion)}`;
|
|
50
54
|
}).filter(function retainQueryField(field){
|
|
51
55
|
return field!==null;
|
|
52
56
|
}):[];
|
|
53
|
-
if(!replaced)
|
|
57
|
+
if(!replaced){
|
|
58
|
+
if(fields.at(-1)==='')fields[fields.length-1]=versionField;
|
|
59
|
+
else fields.push(versionField);
|
|
60
|
+
}
|
|
54
61
|
return `${pathname}?${fields.join('&')}${fragment}`;
|
|
55
62
|
}
|
|
56
63
|
|
|
@@ -538,6 +545,12 @@ class HTMLImport extends HTMLElement {
|
|
|
538
545
|
}
|
|
539
546
|
}
|
|
540
547
|
|
|
541
|
-
|
|
548
|
+
// Application startup and error dialogs can import different URL variants.
|
|
549
|
+
// Each variant must use the constructor already owned by this registry.
|
|
550
|
+
const RegisteredHTMLImport = customElements.get('html-import') || HTMLImport;
|
|
551
|
+
|
|
552
|
+
if(RegisteredHTMLImport === HTMLImport){
|
|
553
|
+
customElements.define('html-import', HTMLImport);
|
|
554
|
+
}
|
|
542
555
|
|
|
543
|
-
export default
|
|
556
|
+
export default RegisteredHTMLImport;
|
package/src/import-map.mjs
CHANGED
|
@@ -814,6 +814,8 @@ function assetUrlVersionEdits(value,version){
|
|
|
814
814
|
if(queryStart<0)return [{start:address.length,end:address.length,value:`?arcaneVersion=${versionValue}`}];
|
|
815
815
|
const query=address.slice(queryStart+1);
|
|
816
816
|
const edits=[];
|
|
817
|
+
const parameters=[];
|
|
818
|
+
let versionFound=false;
|
|
817
819
|
let offset=queryStart+1;
|
|
818
820
|
for(const parameter of query.split('&')){
|
|
819
821
|
const equals=parameter.indexOf('=');
|
|
@@ -821,7 +823,10 @@ function assetUrlVersionEdits(value,version){
|
|
|
821
823
|
let decodedKey=key;
|
|
822
824
|
try{decodedKey=decodeURIComponent(key.replaceAll('+',' '));}
|
|
823
825
|
catch{decodedKey=key;}
|
|
824
|
-
|
|
826
|
+
const remove=decodedKey==='v'||(decodedKey==='arcaneVersion'&&versionFound);
|
|
827
|
+
parameters.push({start:offset,end:offset+parameter.length,remove});
|
|
828
|
+
if(decodedKey==='arcaneVersion'&&!versionFound){
|
|
829
|
+
versionFound=true;
|
|
825
830
|
edits.push({
|
|
826
831
|
start:offset+(equals<0?parameter.length:equals+1),
|
|
827
832
|
end:offset+parameter.length,
|
|
@@ -830,10 +835,25 @@ function assetUrlVersionEdits(value,version){
|
|
|
830
835
|
}
|
|
831
836
|
offset+=parameter.length+1;
|
|
832
837
|
}
|
|
833
|
-
|
|
838
|
+
// Remove adjacent obsolete fields together, including only their separator.
|
|
839
|
+
// Other field spelling and source-level escapes remain untouched.
|
|
840
|
+
for(let index=0;index<parameters.length;index+=1){
|
|
841
|
+
if(!parameters[index].remove)continue;
|
|
842
|
+
const first=index;
|
|
843
|
+
while(parameters[index+1]?.remove)index+=1;
|
|
844
|
+
edits.push({
|
|
845
|
+
start:parameters[first].start-(first>0?1:0),
|
|
846
|
+
end:parameters[index].end+(first===0&&index<parameters.length-1?1:0),
|
|
847
|
+
value:''
|
|
848
|
+
});
|
|
849
|
+
}
|
|
850
|
+
const lastRetained=parameters.findLast(function retainedParameter(parameter){
|
|
851
|
+
return !parameter.remove;
|
|
852
|
+
});
|
|
853
|
+
if(!versionFound)edits.push({
|
|
834
854
|
start:address.length,
|
|
835
855
|
end:address.length,
|
|
836
|
-
value:`${
|
|
856
|
+
value:`${lastRetained&&lastRetained.end>lastRetained.start?'&':''}arcaneVersion=${versionValue}`
|
|
837
857
|
});
|
|
838
858
|
return edits;
|
|
839
859
|
}
|
|
@@ -841,7 +861,7 @@ function assetUrlVersionEdits(value,version){
|
|
|
841
861
|
function applyReferenceEdits(source,edits){
|
|
842
862
|
let result=source;
|
|
843
863
|
for(const edit of edits.sort(function descendingReferenceOffset(left,right){
|
|
844
|
-
return right.start-left.start;
|
|
864
|
+
return right.start-left.start||right.end-left.end;
|
|
845
865
|
})){
|
|
846
866
|
result=result.slice(0,edit.start)+edit.value+result.slice(edit.end);
|
|
847
867
|
}
|