@qvac/harness 0.7.1 → 1.0.0-rc.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/README.md +224 -0
- package/dist-lib/index.d.ts +55 -3
- package/dist-lib/index.js +721 -236
- package/dist-lib/lib/capabilities/completion-engine/abort-polyfill.d.ts +1 -0
- package/dist-lib/lib/capabilities/completion-engine/abort-polyfill.js +10 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/answering.d.ts +3 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/answering.js +17 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/approval.d.ts +4 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/approval.js +29 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/direct-search.d.ts +4 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/direct-search.js +73 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/execute.d.ts +41 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/execute.js +49 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/executing.d.ts +3 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/executing.js +102 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/execution-plan.d.ts +47 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/execution-plan.js +87 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/finishing.d.ts +2 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/finishing.js +32 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/inspect-preload.d.ts +3 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/inspect-preload.js +75 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/inspecting.d.ts +3 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/inspecting.js +152 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/loading-skill.d.ts +3 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/loading-skill.js +94 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/preload-failure.d.ts +9 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/preload-failure.js +11 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/preloading.d.ts +3 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/preloading.js +114 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/preparing.d.ts +3 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/preparing.js +198 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/rejecting.d.ts +3 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/rejecting.js +71 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/rejection.d.ts +18 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/rejection.js +70 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/resolving.d.ts +3 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/resolving.js +60 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/stream.d.ts +21 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/stream.js +48 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/streaming.d.ts +3 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/streaming.js +156 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.d.ts +7 -0
- package/dist-lib/lib/capabilities/completion-engine/actors/wrap-up.js +61 -0
- package/dist-lib/lib/capabilities/completion-engine/driver.d.ts +25 -0
- package/dist-lib/lib/capabilities/completion-engine/driver.js +553 -0
- package/dist-lib/lib/capabilities/completion-engine/durable.d.ts +61 -0
- package/dist-lib/lib/capabilities/completion-engine/durable.js +150 -0
- package/dist-lib/lib/capabilities/completion-engine/operations.d.ts +6 -0
- package/dist-lib/lib/capabilities/completion-engine/operations.js +239 -0
- package/dist-lib/lib/capabilities/completion-engine/ports.d.ts +3 -0
- package/dist-lib/lib/capabilities/completion-engine/ports.js +267 -0
- package/dist-lib/lib/capabilities/completion-engine/session.d.ts +76 -0
- package/dist-lib/lib/capabilities/completion-engine/session.js +70 -0
- package/dist-lib/lib/capabilities/completion-loop/index.d.ts +80 -0
- package/dist-lib/lib/capabilities/completion-loop/index.js +158 -0
- package/dist-lib/lib/capabilities/completion-loop/metrics.d.ts +5 -0
- package/dist-lib/lib/capabilities/completion-loop/metrics.js +29 -0
- package/dist-lib/lib/capabilities/completion-loop/round.d.ts +33 -0
- package/dist-lib/lib/capabilities/completion-loop/round.js +353 -0
- package/dist-lib/lib/capabilities/completion-loop/tool-execution.d.ts +60 -0
- package/dist-lib/lib/capabilities/completion-loop/tool-execution.js +270 -0
- package/dist-lib/lib/capabilities/completion-loop/turns.d.ts +23 -0
- package/dist-lib/lib/capabilities/completion-loop/turns.js +112 -0
- package/dist-lib/lib/capabilities/completion-runtime.d.ts +46 -0
- package/dist-lib/lib/capabilities/completion-runtime.js +74 -0
- package/dist-lib/lib/capabilities/completion.d.ts +18 -335
- package/dist-lib/lib/capabilities/completion.js +20 -1301
- package/dist-lib/lib/capabilities/download.d.ts +1 -1
- package/dist-lib/lib/capabilities/download.js +7 -2
- package/dist-lib/lib/capabilities/invoke.js +5 -3
- package/dist-lib/lib/capabilities/tool-plan.d.ts +35 -0
- package/dist-lib/lib/capabilities/tool-plan.js +66 -0
- package/dist-lib/lib/capabilities/tool-turns.d.ts +11 -2
- package/dist-lib/lib/capabilities/tool-turns.js +30 -2
- package/dist-lib/lib/capabilities/types.d.ts +287 -0
- package/dist-lib/lib/capabilities/types.js +1 -0
- package/dist-lib/lib/completion-lifecycle.d.ts +14 -0
- package/dist-lib/lib/completion-lifecycle.js +126 -0
- package/dist-lib/lib/connect.d.ts +10 -3
- package/dist-lib/lib/connect.js +329 -23
- package/dist-lib/lib/contract-types.d.ts +19 -2
- package/dist-lib/lib/harness-lifecycle.d.ts +66 -0
- package/dist-lib/lib/harness-lifecycle.js +129 -0
- package/dist-lib/lib/helpers/detach-json.d.ts +1 -0
- package/dist-lib/lib/helpers/detach-json.js +146 -0
- package/dist-lib/lib/helpers/markup-scanner.d.ts +26 -0
- package/dist-lib/lib/helpers/markup-scanner.js +156 -0
- package/dist-lib/lib/helpers/markup-stream-filter.js +138 -35
- package/dist-lib/lib/helpers/race-abort.d.ts +9 -4
- package/dist-lib/lib/helpers/race-abort.js +2 -7
- package/dist-lib/lib/helpers/recovery-required.d.ts +1 -0
- package/dist-lib/lib/helpers/recovery-required.js +1 -0
- package/dist-lib/lib/helpers/run-outcome.d.ts +10 -2
- package/dist-lib/lib/helpers/run-outcome.js +8 -5
- package/dist-lib/lib/helpers/tool-call-markup.d.ts +2 -0
- package/dist-lib/lib/helpers/tool-call-markup.js +197 -82
- package/dist-lib/lib/hooks/built-in/arg-repair.d.ts +1 -0
- package/dist-lib/lib/hooks/built-in/arg-repair.js +1 -0
- package/dist-lib/lib/hooks/built-in/egress.d.ts +1 -0
- package/dist-lib/lib/hooks/built-in/egress.js +2 -1
- package/dist-lib/lib/hooks/built-in/sandbox.d.ts +1 -0
- package/dist-lib/lib/hooks/built-in/sandbox.js +6 -1
- package/dist-lib/lib/hooks/built-in/skill-catalog.d.ts +1 -0
- package/dist-lib/lib/hooks/built-in/skill-catalog.js +2 -1
- package/dist-lib/lib/hooks/pipeline.d.ts +4 -1
- package/dist-lib/lib/hooks/pipeline.js +24 -2
- package/dist-lib/lib/hooks/run.d.ts +2 -1
- package/dist-lib/lib/hooks/run.js +19 -7
- package/dist-lib/lib/hooks/types.d.ts +17 -6
- package/dist-lib/lib/machine/completion/actions/approval.d.ts +3 -0
- package/dist-lib/lib/machine/completion/actions/approval.js +16 -0
- package/dist-lib/lib/machine/completion/actions/completion.d.ts +23 -0
- package/dist-lib/lib/machine/completion/actions/completion.js +142 -0
- package/dist-lib/lib/machine/completion/actions/skills.d.ts +9 -0
- package/dist-lib/lib/machine/completion/actions/skills.js +83 -0
- package/dist-lib/lib/machine/completion/actions/tools.d.ts +16 -0
- package/dist-lib/lib/machine/completion/actions/tools.js +173 -0
- package/dist-lib/lib/machine/completion/context.d.ts +9 -0
- package/dist-lib/lib/machine/completion/context.js +44 -0
- package/dist-lib/lib/machine/completion/contract.d.ts +6 -0
- package/dist-lib/lib/machine/completion/contract.js +1 -0
- package/dist-lib/lib/machine/completion/guards/retry.d.ts +9 -0
- package/dist-lib/lib/machine/completion/guards/retry.js +25 -0
- package/dist-lib/lib/machine/completion/implementations.d.ts +81 -0
- package/dist-lib/lib/machine/completion/implementations.js +152 -0
- package/dist-lib/lib/machine/completion/machine.d.ts +375 -0
- package/dist-lib/lib/machine/completion/machine.js +511 -0
- package/dist-lib/lib/machine/completion/ports.d.ts +65 -0
- package/dist-lib/lib/machine/completion/ports.js +224 -0
- package/dist-lib/lib/machine/completion/rules.d.ts +39 -0
- package/dist-lib/lib/machine/completion/rules.js +115 -0
- package/dist-lib/lib/machine/completion/types.d.ts +493 -0
- package/dist-lib/lib/machine/completion/types.js +1 -0
- package/dist-lib/lib/machine/engine.d.ts +93 -0
- package/dist-lib/lib/machine/engine.js +483 -0
- package/dist-lib/lib/machine/errors.d.ts +44 -0
- package/dist-lib/lib/machine/errors.js +373 -0
- package/dist-lib/lib/machine/guards.d.ts +2 -0
- package/dist-lib/lib/machine/guards.js +6 -0
- package/dist-lib/lib/machine/index.d.ts +20 -0
- package/dist-lib/lib/machine/index.js +11 -0
- package/dist-lib/lib/machine/replay-output.d.ts +24 -0
- package/dist-lib/lib/machine/replay-output.js +50 -0
- package/dist-lib/lib/machine/stable-stringify.d.ts +1 -0
- package/dist-lib/lib/machine/stable-stringify.js +11 -0
- package/dist-lib/lib/models/model-pool.d.ts +14 -6
- package/dist-lib/lib/models/model-pool.js +95 -30
- package/dist-lib/lib/run-log/history-codec.d.ts +23 -0
- package/dist-lib/lib/run-log/history-codec.js +973 -0
- package/dist-lib/lib/run-log/patch.d.ts +6 -0
- package/dist-lib/lib/run-log/patch.js +93 -0
- package/dist-lib/lib/run-log/persisted-actor.d.ts +18 -0
- package/dist-lib/lib/run-log/persisted-actor.js +218 -0
- package/dist-lib/lib/run-log/protocol-types.d.ts +153 -0
- package/dist-lib/lib/run-log/protocol-types.js +1 -0
- package/dist-lib/lib/run-log/protocol.d.ts +27 -0
- package/dist-lib/lib/run-log/protocol.js +1056 -0
- package/dist-lib/lib/run-log/replay.d.ts +25 -0
- package/dist-lib/lib/run-log/replay.js +129 -0
- package/dist-lib/lib/run-log/run-journal.d.ts +125 -0
- package/dist-lib/lib/run-log/run-journal.js +783 -0
- package/dist-lib/lib/run-log-inspect.d.ts +25 -0
- package/dist-lib/lib/run-log-inspect.js +627 -0
- package/dist-lib/lib/run-log-protocol.d.ts +2 -0
- package/dist-lib/lib/run-log-protocol.js +1 -0
- package/dist-lib/lib/run-log-redact.d.ts +27 -0
- package/dist-lib/lib/run-log-redact.js +1107 -0
- package/dist-lib/lib/serve.js +307 -11
- package/dist-lib/lib/spawn.js +3 -2
- package/dist-lib/lib/tool-call-display.d.ts +1 -21
- package/dist-lib/lib/tools/exec/adapters/python/wheels.js +2 -1
- package/dist-lib/lib/tools/exec.d.ts +2 -1
- package/dist-lib/lib/tools/exec.js +57 -2
- package/dist-lib/lib/tools/generate-image.js +1 -1
- package/dist-lib/lib/tools/generate-music.js +1 -1
- package/dist-lib/lib/tools/http-request.d.ts +2 -1
- package/dist-lib/lib/tools/http-request.js +2 -1
- package/dist-lib/lib/tools/mcp-call.js +8 -1
- package/dist-lib/lib/tools/operations/builders.d.ts +1 -0
- package/dist-lib/lib/tools/operations/builders.js +1 -0
- package/dist-lib/lib/tools/operations/compile.js +11 -1
- package/dist-lib/lib/tools/operations/manifest.js +1 -0
- package/dist-lib/lib/tools/outbound-guard.d.ts +8 -6
- package/dist-lib/lib/tools/outbound-guard.js +25 -8
- package/dist-lib/lib/tools/skills/catalog.d.ts +1 -0
- package/dist-lib/lib/tools/skills/catalog.js +35 -0
- package/dist-lib/lib/tools/skills/cli-schema-types.d.ts +1 -0
- package/dist-lib/lib/tools/skills/cli-schema.js +25 -0
- package/dist-lib/lib/wire.d.ts +5 -0
- package/dist-lib/lib/wire.js +128 -5
- package/dist-lib/schema/harness.js +20 -5
- package/dist-lib/spec/hrpc/messages.js +95 -15
- package/dist-lib/spec/hyperschema/index.js +95 -15
- package/dist-lib/spec/hyperschema/schema.json +69 -1
- package/dist-lib/spec/hyperschema/types.d.ts +10 -3
- package/package.json +20 -2
- package/patches/@qvac%2Finference@0.20.0.patch +67 -0
- package/patches/bare-stow@0.1.5.patch +68 -0
- package/patches/hypercore-blob-server@1.15.0.patch +15 -0
- package/patches/localwatch@1.4.3.patch +13 -0
- package/patches/pyodide@314.0.2.patch +144 -0
|
@@ -6,29 +6,42 @@ import { defaultContextSize } from './context.js';
|
|
|
6
6
|
import { customContextLength } from './model-catalog.js';
|
|
7
7
|
import { adrenoSafeKvCache } from './kv-cache.js';
|
|
8
8
|
import { DEFAULT_EMBED_BATCH_SIZE } from './embed-config.js';
|
|
9
|
+
import { errorMessage } from '../guards.js';
|
|
9
10
|
import { hlog } from '../log.js';
|
|
10
11
|
import { RUNAWAY_STOP_SEQUENCES } from '../helpers/control-tokens.js';
|
|
11
12
|
import { raceTimeout } from '../helpers/race-timeout.js';
|
|
12
13
|
import { resolveModelSrc } from './model-source.js';
|
|
13
|
-
|
|
14
|
+
export class ModelUnloadError extends Error {
|
|
15
|
+
constructor(cause) {
|
|
16
|
+
super(errorMessage(cause));
|
|
17
|
+
this.name = 'ModelUnloadError';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
14
20
|
export function createLoadTracker() {
|
|
15
21
|
const inflight = new Set();
|
|
16
|
-
let draining =
|
|
22
|
+
let draining = false;
|
|
23
|
+
let drainSdk = null;
|
|
17
24
|
const cancel = (sdk, requestId) => {
|
|
25
|
+
if (!sdk.cancel) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
18
28
|
void sdk.cancel({ requestId }).catch(noop);
|
|
19
29
|
};
|
|
20
30
|
return {
|
|
21
31
|
get draining() {
|
|
22
|
-
return draining
|
|
32
|
+
return draining;
|
|
23
33
|
},
|
|
24
|
-
track(pending) {
|
|
34
|
+
track(pending, sdk) {
|
|
25
35
|
const { requestId } = pending;
|
|
26
36
|
if (!requestId) {
|
|
27
37
|
return pending;
|
|
28
38
|
}
|
|
29
39
|
if (draining) {
|
|
30
|
-
|
|
31
|
-
|
|
40
|
+
const canceller = sdk ?? drainSdk;
|
|
41
|
+
if (canceller) {
|
|
42
|
+
cancel(canceller, requestId);
|
|
43
|
+
return pending;
|
|
44
|
+
}
|
|
32
45
|
}
|
|
33
46
|
inflight.add(requestId);
|
|
34
47
|
const untrack = () => inflight.delete(requestId);
|
|
@@ -36,14 +49,21 @@ export function createLoadTracker() {
|
|
|
36
49
|
return pending;
|
|
37
50
|
},
|
|
38
51
|
drain(sdk) {
|
|
39
|
-
draining =
|
|
52
|
+
draining = true;
|
|
53
|
+
if (sdk) {
|
|
54
|
+
drainSdk = sdk;
|
|
55
|
+
}
|
|
56
|
+
if (!drainSdk) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
40
59
|
for (const requestId of inflight) {
|
|
41
|
-
cancel(
|
|
60
|
+
cancel(drainSdk, requestId);
|
|
42
61
|
}
|
|
43
62
|
inflight.clear();
|
|
44
63
|
},
|
|
45
64
|
undrain() {
|
|
46
|
-
draining =
|
|
65
|
+
draining = false;
|
|
66
|
+
drainSdk = null;
|
|
47
67
|
}
|
|
48
68
|
};
|
|
49
69
|
}
|
|
@@ -89,9 +109,10 @@ export function releaseModel(pool, key) {
|
|
|
89
109
|
void pending.then(() => releaseSettled(pool, key), () => releaseSettled(pool, key));
|
|
90
110
|
}
|
|
91
111
|
function releaseSettled(pool, key) {
|
|
92
|
-
if (
|
|
93
|
-
|
|
112
|
+
if (pool.destroyed) {
|
|
113
|
+
return;
|
|
94
114
|
}
|
|
115
|
+
pool.release(key);
|
|
95
116
|
}
|
|
96
117
|
export function loadedModels(pool) {
|
|
97
118
|
const out = [];
|
|
@@ -318,7 +339,14 @@ export function loadClockGuard(model, sdk, { now = () => Date.now(), monoMs = mo
|
|
|
318
339
|
};
|
|
319
340
|
return { race };
|
|
320
341
|
}
|
|
321
|
-
export function
|
|
342
|
+
export async function resolveCtxSize(loadSdk, model, opts) {
|
|
343
|
+
if (opts.ctxSize) {
|
|
344
|
+
return opts.ctxSize;
|
|
345
|
+
}
|
|
346
|
+
const sdk = await loadSdk();
|
|
347
|
+
return defaultContextSize(await resolveModelSrc(sdk, model));
|
|
348
|
+
}
|
|
349
|
+
export function createModelPool(loadSdk, notify, { deviceConfig = {}, loads = createLoadTracker(), onUnloadFailure } = {}) {
|
|
322
350
|
const load = async (model, opts) => {
|
|
323
351
|
const sdk = await loadSdk();
|
|
324
352
|
const modelSrc = await resolveModelSrc(sdk, model);
|
|
@@ -358,17 +386,17 @@ export function createModelPool(loadSdk, notify, { deviceConfig = {}, loads = cr
|
|
|
358
386
|
modelType: 'llamacpp-completion',
|
|
359
387
|
modelConfig,
|
|
360
388
|
onProgress: (progress) => notify(progressState(model, progress))
|
|
361
|
-
})));
|
|
389
|
+
}), sdk));
|
|
362
390
|
hlog('llm loaded', { model, loadMs: Date.now() - loadStarted });
|
|
363
391
|
return { model, modelId, ctxSize };
|
|
364
392
|
};
|
|
365
393
|
return new ModelPuddle({
|
|
366
394
|
open: (key, model = key, opts = {}) => reportedHandle(notify, model, () => load(model, opts)),
|
|
367
|
-
gc: unloadOnGc(loadSdk, notify),
|
|
395
|
+
gc: unloadOnGc(loadSdk, notify, onUnloadFailure),
|
|
368
396
|
...NO_IDLE_GC
|
|
369
397
|
});
|
|
370
398
|
}
|
|
371
|
-
export function createEmbedPool(loadSdk, notify, { faults, batchSize = DEFAULT_EMBED_BATCH_SIZE, openclCacheDir, loads = createLoadTracker() }) {
|
|
399
|
+
export function createEmbedPool(loadSdk, notify, { faults, batchSize = DEFAULT_EMBED_BATCH_SIZE, openclCacheDir, loads = createLoadTracker(), onUnloadFailure }) {
|
|
372
400
|
const load = async (model) => {
|
|
373
401
|
const sdk = await loadSdk();
|
|
374
402
|
const modelSrc = await resolveModelSrc(sdk, model, 'embeddings');
|
|
@@ -383,16 +411,16 @@ export function createEmbedPool(loadSdk, notify, { faults, batchSize = DEFAULT_E
|
|
|
383
411
|
openclCacheDir: openclCache || undefined
|
|
384
412
|
},
|
|
385
413
|
onProgress: (progress) => notify(progressState(model, progress))
|
|
386
|
-
})));
|
|
414
|
+
}), sdk));
|
|
387
415
|
return { model, modelId };
|
|
388
416
|
};
|
|
389
417
|
return new ModelPuddle({
|
|
390
418
|
open: (key, model = key) => reportedHandle(notify, model, () => load(model)),
|
|
391
|
-
gc: unloadOnGc(loadSdk, notify),
|
|
419
|
+
gc: unloadOnGc(loadSdk, notify, onUnloadFailure),
|
|
392
420
|
...NO_IDLE_GC
|
|
393
421
|
});
|
|
394
422
|
}
|
|
395
|
-
export function createVoicePool(loadSdk, notify, { modelType, addon, modelConfig, openclCacheDir, loads = createLoadTracker() }) {
|
|
423
|
+
export function createVoicePool(loadSdk, notify, { modelType, addon, modelConfig, openclCacheDir, loads = createLoadTracker(), onUnloadFailure }) {
|
|
396
424
|
const wantsGpu = modelConfig?.['useGPU'] === true;
|
|
397
425
|
let gpuRefused = false;
|
|
398
426
|
const load = async (model) => {
|
|
@@ -406,7 +434,7 @@ export function createVoicePool(loadSdk, notify, { modelType, addon, modelConfig
|
|
|
406
434
|
modelType,
|
|
407
435
|
modelConfig: openclCache ? { openclCacheDir: openclCache, ...config } : config,
|
|
408
436
|
onProgress: (progress) => notify(progressState(model, progress))
|
|
409
|
-
}));
|
|
437
|
+
}), sdk);
|
|
410
438
|
};
|
|
411
439
|
const modelId = await loadClockGuard(model, sdk).race(attempt().catch((err) => {
|
|
412
440
|
if (!wantsGpu || gpuRefused || loads.draining)
|
|
@@ -419,34 +447,71 @@ export function createVoicePool(loadSdk, notify, { modelType, addon, modelConfig
|
|
|
419
447
|
};
|
|
420
448
|
return new ModelPuddle({
|
|
421
449
|
open: (key, model = key) => reportedHandle(notify, model, () => load(model)),
|
|
422
|
-
gc: unloadOnGc(loadSdk, notify),
|
|
450
|
+
gc: unloadOnGc(loadSdk, notify, onUnloadFailure),
|
|
423
451
|
...NO_IDLE_GC
|
|
424
452
|
});
|
|
425
453
|
}
|
|
426
|
-
function unloadOnGc(loadSdk, notify) {
|
|
454
|
+
function unloadOnGc(loadSdk, notify, onUnloadFailure) {
|
|
427
455
|
return async (handles) => {
|
|
428
|
-
const
|
|
456
|
+
const loadedHandles = [];
|
|
429
457
|
for (const handle of handles) {
|
|
430
458
|
const pending = handle.peek();
|
|
431
459
|
if (pending === null) {
|
|
432
460
|
continue;
|
|
433
461
|
}
|
|
434
|
-
let loaded;
|
|
435
462
|
try {
|
|
436
|
-
|
|
463
|
+
loadedHandles.push(await pending);
|
|
437
464
|
}
|
|
438
|
-
catch {
|
|
439
|
-
|
|
465
|
+
catch { }
|
|
466
|
+
}
|
|
467
|
+
if (loadedHandles.length === 0) {
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
const reportFailure = (modelId, error) => {
|
|
471
|
+
try {
|
|
472
|
+
onUnloadFailure?.(modelId, error);
|
|
473
|
+
}
|
|
474
|
+
catch (callbackError) {
|
|
475
|
+
hlog('model unload failure observer failed', { error: String(callbackError) });
|
|
476
|
+
}
|
|
477
|
+
};
|
|
478
|
+
let sdk;
|
|
479
|
+
try {
|
|
480
|
+
sdk = await loadSdk();
|
|
481
|
+
}
|
|
482
|
+
catch (error) {
|
|
483
|
+
for (const { modelId } of loadedHandles) {
|
|
484
|
+
reportFailure(modelId, error);
|
|
485
|
+
}
|
|
486
|
+
throw new ModelUnloadError(error);
|
|
487
|
+
}
|
|
488
|
+
let unloadError;
|
|
489
|
+
let unloadFailed = false;
|
|
490
|
+
for (const { model, modelId } of loadedHandles) {
|
|
491
|
+
try {
|
|
492
|
+
notify({ status: 'unloading', model });
|
|
493
|
+
}
|
|
494
|
+
catch (error) {
|
|
495
|
+
hlog('model unloading observer failed', { error: String(error) });
|
|
440
496
|
}
|
|
441
|
-
const { model, modelId } = loaded;
|
|
442
|
-
notify({ status: 'unloading', model });
|
|
443
497
|
try {
|
|
444
498
|
await sdk.unloadModel({ modelId });
|
|
445
499
|
}
|
|
446
|
-
catch {
|
|
500
|
+
catch (error) {
|
|
501
|
+
unloadError ??= error;
|
|
502
|
+
unloadFailed = true;
|
|
503
|
+
reportFailure(modelId, error);
|
|
447
504
|
continue;
|
|
448
505
|
}
|
|
449
|
-
|
|
506
|
+
try {
|
|
507
|
+
notify({ status: 'unloaded', model, catalogChanged: true });
|
|
508
|
+
}
|
|
509
|
+
catch (error) {
|
|
510
|
+
hlog('model unloaded observer failed', { error: String(error) });
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
if (unloadFailed) {
|
|
514
|
+
throw new ModelUnloadError(unloadError);
|
|
450
515
|
}
|
|
451
516
|
};
|
|
452
517
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type Patch } from './patch.ts';
|
|
2
|
+
export type { HistoryReference } from './protocol-types.ts';
|
|
3
|
+
export interface HistoryProjectionOptions {
|
|
4
|
+
base: readonly unknown[] | undefined;
|
|
5
|
+
failureRefs?: ReadonlySet<string>;
|
|
6
|
+
validateFailureOutputs?: boolean;
|
|
7
|
+
validate?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare const FAILURE_RESULT_REF_MACHINE_VERSION = 8;
|
|
10
|
+
export declare function requestMessages(request: unknown): readonly unknown[] | undefined;
|
|
11
|
+
export declare function compactSnapshotHistory<Value>(snapshot: Value, base: readonly unknown[] | undefined): Value;
|
|
12
|
+
export declare function materializeSnapshotHistory<Value>(snapshot: Value, base: readonly unknown[] | undefined, allowLegacyInlineFailureResults?: boolean): Value;
|
|
13
|
+
export declare function compactMachineEvent<Value>(event: Value, base: readonly unknown[] | undefined): Value;
|
|
14
|
+
export declare function materializeMachineEvent<Value>(event: Value, base: readonly unknown[] | undefined): Value;
|
|
15
|
+
export interface SnapshotHistoryValidationOptions {
|
|
16
|
+
allowLegacyInlineFailureResults?: boolean;
|
|
17
|
+
validateMachineContext?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export declare function validateSnapshotHistory(snapshot: unknown, base: readonly unknown[] | undefined, options?: SnapshotHistoryValidationOptions): void;
|
|
20
|
+
export declare function snapshotFailureResultRefs(snapshot: unknown, allowLegacyInlineFailureResults?: boolean): ReadonlySet<string>;
|
|
21
|
+
export declare function validateMachineEventHistory(event: unknown, base: readonly unknown[] | undefined, failureRefs?: ReadonlySet<string>): void;
|
|
22
|
+
export declare function foldMachineEventHistory(previous: unknown, patch: Patch, options: HistoryProjectionOptions): unknown;
|
|
23
|
+
export declare function validateHistoryProjection(value: unknown, options: HistoryProjectionOptions): void;
|