@qvac/sdk 0.23.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +115 -58
- package/README.md +10 -13
- package/dist/examples/asr/parakeet-sortformer.js +24 -14
- package/dist/examples/asr/parakeet-transcribepsy-filesystem.js +40 -11
- package/dist/examples/asr/parakeet-unified-coreml.js +14 -9
- package/dist/examples/asr/whispercpp-prompt.js +9 -5
- package/dist/examples/assess-model-fit.d.ts +7 -9
- package/dist/examples/assess-model-fit.js +22 -43
- package/dist/examples/calc-tokens.d.ts +2 -0
- package/dist/examples/calc-tokens.js +21 -0
- package/dist/examples/classification/classify-image.js +11 -5
- package/dist/examples/completion-stop-reason.d.ts +3 -3
- package/dist/examples/completion-stop-reason.js +4 -4
- package/dist/examples/diffusion-flux3-klein.d.ts +2 -0
- package/dist/examples/diffusion-flux3-klein.js +102 -0
- package/dist/examples/diffusion-moss-image.d.ts +2 -0
- package/dist/examples/diffusion-moss-image.js +126 -0
- package/dist/examples/diffusion-qwen-image-21.js +15 -4
- package/dist/examples/embed-multimodal.d.ts +2 -0
- package/dist/examples/embed-multimodal.js +80 -0
- package/dist/examples/embed-p2p.js +2 -2
- package/dist/examples/image/megaloc.d.ts +2 -0
- package/dist/examples/image/megaloc.js +37 -0
- package/dist/examples/llamacpp-multimodal.js +18 -0
- package/dist/examples/rag/rag-hyperdb/pipeline.js +2 -2
- package/dist/examples/rag/rag-turbovec.js +2 -2
- package/dist/examples/sessions.d.ts +17 -0
- package/dist/examples/sessions.js +63 -0
- package/dist/examples/tools/llamacpp-deferred-tools.js +8 -4
- package/dist/scripts/check-resource-collectors-packaging.js +7 -6
- package/dist/scripts/contract/build-contract.d.ts +2 -1
- package/dist/scripts/contract/build-contract.js +13 -1
- package/dist/scripts/contract/constants-registry.d.ts +17 -0
- package/dist/scripts/contract/constants-registry.js +8 -2
- package/dist/scripts/contract/method-shapes.d.ts +4 -0
- package/dist/scripts/contract/method-shapes.js +4 -0
- package/dist/scripts/enforce-inference-versions.d.ts +1 -1
- package/dist/scripts/enforce-inference-versions.js +28 -18
- package/dist/scripts/generate-bare-kit-runtimes.js +101 -69
- package/dist/src/client/api/assess-model-fit.d.ts +17 -17
- package/dist/src/client/api/assess-model-fit.js +18 -31
- package/dist/src/client/api/audio-edit.d.ts +5 -3
- package/dist/src/client/api/audio-edit.js +5 -3
- package/dist/src/client/api/audio-gen-result.js +134 -45
- package/dist/src/client/api/audio-gen.d.ts +40 -3
- package/dist/src/client/api/audio-gen.js +40 -3
- package/dist/src/client/api/audio-understand.d.ts +2 -2
- package/dist/src/client/api/audio-understand.js +2 -2
- package/dist/src/client/api/batch-completion.js +2 -1
- package/dist/src/client/api/calc-tokens.d.ts +33 -0
- package/dist/src/client/api/calc-tokens.js +44 -0
- package/dist/src/client/api/cancel.d.ts +2 -2
- package/dist/src/client/api/cancel.js +2 -2
- package/dist/src/client/api/classify.d.ts +12 -5
- package/dist/src/client/api/classify.js +17 -5
- package/dist/src/client/api/client-request-id.d.ts +0 -15
- package/dist/src/client/api/client-request-id.js +15 -12
- package/dist/src/client/api/completion-stream.d.ts +8 -1
- package/dist/src/client/api/completion-stream.js +10 -1
- package/dist/src/client/api/delete-cache.d.ts +9 -2
- package/dist/src/client/api/delete-cache.js +13 -3
- package/dist/src/client/api/diffusion.d.ts +20 -4
- package/dist/src/client/api/diffusion.js +23 -5
- package/dist/src/client/api/embed.d.ts +82 -29
- package/dist/src/client/api/embed.js +64 -19
- package/dist/src/client/api/get-model-info.d.ts +2 -2
- package/dist/src/client/api/get-model-info.js +2 -2
- package/dist/src/client/api/get-system-resources.d.ts +2 -2
- package/dist/src/client/api/get-system-resources.js +2 -2
- package/dist/src/client/api/heartbeat.d.ts +3 -2
- package/dist/src/client/api/heartbeat.js +3 -2
- package/dist/src/client/api/index.d.ts +4 -3
- package/dist/src/client/api/index.js +2 -1
- package/dist/src/client/api/invoke-plugin.d.ts +8 -2
- package/dist/src/client/api/invoke-plugin.js +17 -2
- package/dist/src/client/api/load-model.js +5 -2
- package/dist/src/client/api/ocr.d.ts +5 -3
- package/dist/src/client/api/ocr.js +44 -21
- package/dist/src/client/api/rag.d.ts +1 -1
- package/dist/src/client/api/rag.js +1 -1
- package/dist/src/client/api/registry.d.ts +17 -7
- package/dist/src/client/api/registry.js +37 -12
- package/dist/src/client/api/resume.d.ts +2 -1
- package/dist/src/client/api/resume.js +2 -2
- package/dist/src/client/api/rpc-server.d.ts +4 -4
- package/dist/src/client/api/rpc-server.js +10 -10
- package/dist/src/client/api/state.d.ts +2 -2
- package/dist/src/client/api/state.js +2 -2
- package/dist/src/client/api/subscribe-logs.d.ts +2 -2
- package/dist/src/client/api/subscribe-logs.js +2 -2
- package/dist/src/client/api/suspend.d.ts +4 -2
- package/dist/src/client/api/suspend.js +4 -3
- package/dist/src/client/api/text-to-speech.d.ts +14 -5
- package/dist/src/client/api/text-to-speech.js +83 -29
- package/dist/src/client/api/transcribe.d.ts +6 -2
- package/dist/src/client/api/transcribe.js +7 -1
- package/dist/src/client/api/unload-model.d.ts +19 -7
- package/dist/src/client/api/unload-model.js +29 -11
- package/dist/src/client/api/upscale.d.ts +6 -3
- package/dist/src/client/api/upscale.js +9 -4
- package/dist/src/client/api/vector-index.d.ts +50 -16
- package/dist/src/client/api/vector-index.js +100 -48
- package/dist/src/client/api/video-request.d.ts +5 -5
- package/dist/src/client/api/video.d.ts +3 -2
- package/dist/src/client/api/video.js +3 -2
- package/dist/src/client/api/vla.d.ts +9 -5
- package/dist/src/client/api/vla.js +17 -8
- package/dist/src/client/api/world.d.ts +5 -5
- package/dist/src/client/api/world.js +4 -4
- package/dist/src/client/init-hooks.d.ts +6 -4
- package/dist/src/client/init-hooks.js +12 -15
- package/dist/src/client/logging-stream-registry.d.ts +6 -3
- package/dist/src/client/logging-stream-registry.js +31 -12
- package/dist/src/client/rpc/bundle-stamp.d.ts +29 -0
- package/dist/src/client/rpc/bundle-stamp.js +75 -0
- package/dist/src/client/rpc/expo-home-dir.d.ts +2 -0
- package/dist/src/client/rpc/expo-home-dir.js +4 -0
- package/dist/src/client/rpc/expo-rpc-client.js +189 -135
- package/dist/src/client/rpc/node-rpc-client.js +322 -413
- package/dist/src/client/rpc/pear-runtime.d.ts +12 -0
- package/dist/src/client/rpc/pear-runtime.js +12 -0
- package/dist/src/client/rpc/rpc-client.d.ts +5 -4
- package/dist/src/client/rpc/rpc-client.js +126 -23
- package/dist/src/client/rpc/rpc-error.js +21 -2
- package/dist/src/client/rpc/unbundled-harness.d.ts +16 -0
- package/dist/src/client/rpc/unbundled-harness.js +27 -0
- package/dist/src/client/rpc/worker-failure.d.ts +27 -0
- package/dist/src/client/rpc/worker-failure.js +61 -0
- package/dist/src/client/session-registry.d.ts +75 -0
- package/dist/src/client/session-registry.js +149 -0
- package/dist/src/client/session.d.ts +125 -0
- package/dist/src/client/session.js +148 -0
- package/dist/src/commands/bundle/addons.d.ts +14 -0
- package/dist/src/commands/bundle/addons.js +65 -0
- package/dist/src/commands/bundle/constants.js +1 -0
- package/dist/src/commands/bundle/entry-gen.d.ts +1 -5
- package/dist/src/commands/bundle/entry-gen.js +17 -50
- package/dist/src/commands/bundle/index.d.ts +59 -13
- package/dist/src/commands/bundle/index.js +345 -121
- package/dist/src/commands/bundle/link.d.ts +58 -0
- package/dist/src/commands/bundle/link.js +135 -0
- package/dist/src/commands/bundle/node-support.d.ts +13 -0
- package/dist/src/commands/bundle/node-support.js +23 -0
- package/dist/src/commands/bundle/read-bundle.d.ts +9 -0
- package/dist/src/commands/bundle/read-bundle.js +27 -0
- package/dist/src/commands/bundle/resolve-sdk-import.d.ts +6 -0
- package/dist/src/commands/bundle/resolve-sdk-import.js +24 -28
- package/dist/src/commands/bundle/scratch.d.ts +35 -0
- package/dist/src/commands/bundle/scratch.js +178 -0
- package/dist/src/commands/bundle/targets.d.ts +14 -0
- package/dist/src/commands/bundle/targets.js +37 -0
- package/dist/src/commands/host-prebuilds/index.d.ts +5 -4
- package/dist/src/commands/host-prebuilds/index.js +9 -7
- package/dist/src/commands/index.d.ts +4 -3
- package/dist/src/commands/verify/abi.d.ts +20 -14
- package/dist/src/commands/verify/abi.js +11 -79
- package/dist/src/commands/verify/bare-kit-runtime.d.ts +20 -22
- package/dist/src/commands/verify/bare-kit-runtime.js +102 -150
- package/dist/src/commands/verify/bare-kit-runtimes.d.ts +10 -9
- package/dist/src/commands/verify/bare-kit-runtimes.js +21 -21
- package/dist/src/commands/verify/bundle-source.js +25 -21
- package/dist/src/commands/verify/engines-advice.d.ts +2 -8
- package/dist/src/commands/verify/engines-advice.js +7 -54
- package/dist/src/commands/verify/index.d.ts +30 -29
- package/dist/src/commands/verify/index.js +92 -200
- package/dist/src/commands/verify/prebuilds.d.ts +3 -5
- package/dist/src/commands/verify/prebuilds.js +1 -2
- package/dist/src/commands/verify/resource-collectors.d.ts +0 -6
- package/dist/src/commands/verify/resource-collectors.js +1 -50
- package/dist/src/commands/verify/sidecar-runtime.d.ts +6 -0
- package/dist/src/commands/verify/sidecar-runtime.js +51 -0
- package/dist/src/expo/plugins/withBareKit.d.ts +59 -0
- package/dist/src/expo/plugins/withBareKit.js +204 -0
- package/dist/src/expo/plugins/withMobileBundle.d.ts +4 -11
- package/dist/src/expo/plugins/withMobileBundle.js +36 -57
- package/dist/src/expo/plugins/withQvacSDK.d.ts +1 -0
- package/dist/src/expo/plugins/withQvacSDK.js +3 -0
- package/dist/src/index.d.ts +6 -5
- package/dist/src/index.js +10 -14
- package/dist/src/logging/utils.js +10 -2
- package/dist/src/plugin-ids.d.ts +2 -1
- package/dist/src/plugin-ids.js +2 -0
- package/dist/src/schemas/public.d.ts +1 -1
- package/dist/src/schemas/public.js +1 -1
- package/dist/src/schemas/sdk-errors-client.d.ts +5 -6
- package/dist/src/schemas/sdk-errors-client.js +30 -36
- package/dist/src/schemas/sdk-errors-server.d.ts +11 -1
- package/dist/src/schemas/sdk-errors-server.js +60 -2
- package/dist/src/server/rpc/rpc-utils.d.ts +25 -4
- package/dist/src/server/rpc/rpc-utils.js +39 -5
- package/dist/src/utils/errors-client.d.ts +37 -29
- package/dist/src/utils/errors-client.js +50 -41
- package/dist/src/utils/errors-server.d.ts +59 -1
- package/dist/src/utils/errors-server.js +110 -1
- package/dist/src/utils/withTimeout.js +34 -17
- package/dist/src/worker/handle-request.js +25 -22
- package/dist/src/worker/handler-utils.d.ts +2 -6
- package/dist/src/worker/handler-utils.js +2 -20
- package/dist/src/worker/index.d.ts +2 -4
- package/dist/src/worker/index.js +23 -35
- package/dist/src/worker/plugins/ggml-image-embedding.d.ts +2 -0
- package/dist/src/worker/plugins/ggml-image-embedding.js +1 -0
- package/dist/src/worker/shim.d.ts +4 -0
- package/dist/src/worker/shim.js +7 -0
- package/dist/src/worker/start.d.ts +9 -0
- package/dist/src/worker/start.js +16 -0
- package/dist/src/worker/unbundled-shim.d.ts +2 -0
- package/dist/src/worker/unbundled-shim.js +4 -0
- package/docs/system-resources-support-matrix.md +27 -19
- package/package.json +62 -51
- package/src/electron-forge/index.cjs +65 -91
- package/dist/examples/model-fit-ui/server.d.ts +0 -24
- package/dist/examples/model-fit-ui/server.js +0 -221
- package/dist/src/client/rpc/ensure-worker-ready.d.ts +0 -9
- package/dist/src/client/rpc/ensure-worker-ready.js +0 -17
- package/dist/src/client/rpc/init-timeout.d.ts +0 -26
- package/dist/src/client/rpc/init-timeout.js +0 -25
- package/dist/src/client/rpc/ipc-socket-path.d.ts +0 -11
- package/dist/src/client/rpc/ipc-socket-path.js +0 -30
- package/dist/src/client/rpc/worker-startup-error.d.ts +0 -12
- package/dist/src/client/rpc/worker-startup-error.js +0 -13
- package/dist/src/commands/bundle/bare-pack.d.ts +0 -21
- package/dist/src/commands/bundle/bare-pack.js +0 -77
- package/dist/src/commands/bundle/manifest.d.ts +0 -25
- package/dist/src/commands/bundle/manifest.js +0 -192
- package/dist/src/expo/plugins/link-addons.d.ts +0 -18
- package/dist/src/expo/plugins/link-addons.js +0 -65
- package/dist/src/pear/pre.d.ts +0 -21
- package/dist/src/pear/pre.js +0 -450
- package/dist/src/server/env.d.ts +0 -22
- package/dist/src/server/env.js +0 -59
- package/dist/src/server/utils/qvac-paths.d.ts +0 -2
- package/dist/src/server/utils/qvac-paths.js +0 -5
- package/dist/src/server/utils/worker-lock.d.ts +0 -3
- package/dist/src/server/utils/worker-lock.js +0 -67
- package/dist/src/worker/create-server.d.ts +0 -8
- package/dist/src/worker/create-server.js +0 -51
- package/dist/src/worker/lifecycle.d.ts +0 -23
- package/dist/src/worker/lifecycle.js +0 -149
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export declare function initializeWorker(): {
|
|
2
|
-
hasRPCConfig: boolean;
|
|
3
|
-
};
|
|
4
|
-
export declare function ensureRPCSetup(): void;
|
|
5
|
-
export declare function isWorkerInitialized(): boolean;
|
|
6
|
-
export type WorkerShutdownReason = 'signal' | 'rpc-close' | 'uncaught-exception' | 'unhandled-rejection' | 'ipc-disconnect';
|
|
7
|
-
/**
|
|
8
|
-
* Pre-terminate cleanup, callable while the worker is still alive.
|
|
9
|
-
*
|
|
10
|
-
* On platforms where the worker lives in the same OS process as the JS host
|
|
11
|
-
* (i.e. mobile via react-native-bare-kit Worklet), `Bare.exit()` would kill the
|
|
12
|
-
* entire app. This path runs the engine's cleanup (models, swarm, RAG,
|
|
13
|
-
* downloads, registry client, plugin/addon registries) without releasing the
|
|
14
|
-
* worker lock or exiting, leaving the caller (typically the SDK client about to
|
|
15
|
-
* call `worklet.terminate()`) responsible for tearing the worker down.
|
|
16
|
-
*
|
|
17
|
-
* Critical for clean termination: addons hold static state with js_ref_t
|
|
18
|
-
* handles into the current V8 isolate; without this cleanup, those refs survive
|
|
19
|
-
* into the next worklet's isolate and crash on first access.
|
|
20
|
-
*/
|
|
21
|
-
export declare function cleanupForTerminate(): Promise<void>;
|
|
22
|
-
export declare function shutdownWorker(reason: WorkerShutdownReason): Promise<void>;
|
|
23
|
-
//# sourceMappingURL=lifecycle.d.ts.map
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import os from 'bare-os';
|
|
2
|
-
import Signal from 'bare-signals';
|
|
3
|
-
import { createBareKitRPCServer, createIPCClient } from '../worker/create-server.js';
|
|
4
|
-
import { initEnv, getValidatedEnv } from '../server/env.js';
|
|
5
|
-
import { initialize as initializeEngine, close as closeEngine, cleanupForTerminate as cleanupEngineForTerminate } from '@qvac/inference/engine';
|
|
6
|
-
import { getServerLogger } from '../logging/index.js';
|
|
7
|
-
import { acquireWorkerLock, releaseWorkerLock } from '../server/utils/worker-lock.js';
|
|
8
|
-
let workerInitialized = false;
|
|
9
|
-
let rpcInitialized = false;
|
|
10
|
-
// Set true when shutdownWorker is in flight, so a later
|
|
11
|
-
// SIGTERM/SIGINT/uncaught-exception does not re-run releaseWorkerLock + Bare.exit.
|
|
12
|
-
let isShuttingDown = false;
|
|
13
|
-
const logger = getServerLogger();
|
|
14
|
-
// Defense-in-depth grace period for the SIGKILL safety net armed before
|
|
15
|
-
// Bare.exit() in shutdownWorker. If Bare.exit cannot
|
|
16
|
-
// terminate the worker within this window — typically because some path
|
|
17
|
-
// holds a non-cancellable native handle (e.g. a libuv worker thread
|
|
18
|
-
// blocked on flock; see QVAC-18197) — we force-kill the OS process to
|
|
19
|
-
// guarantee bounded shutdown time.
|
|
20
|
-
const FORCE_EXIT_GRACE_MS = 3_000;
|
|
21
|
-
function scheduleForceExit() {
|
|
22
|
-
const timer = setTimeout(() => {
|
|
23
|
-
logger.error(`Bare.exit did not terminate the worker within ${FORCE_EXIT_GRACE_MS}ms — ` +
|
|
24
|
-
`force-killing self (likely blocked native handle)`);
|
|
25
|
-
try {
|
|
26
|
-
os.kill(os.pid(), 'SIGKILL');
|
|
27
|
-
}
|
|
28
|
-
catch {
|
|
29
|
-
// best-effort — if SIGKILL itself fails, there's nothing more to do
|
|
30
|
-
}
|
|
31
|
-
}, FORCE_EXIT_GRACE_MS);
|
|
32
|
-
// Don't let the safety-net timer keep the process alive on the happy
|
|
33
|
-
// path. Bare returns an object (not a number) from setTimeout.
|
|
34
|
-
if (timer && typeof timer === 'object' && 'unref' in timer) {
|
|
35
|
-
;
|
|
36
|
-
timer.unref();
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
export function initializeWorker() {
|
|
40
|
-
if (workerInitialized) {
|
|
41
|
-
const validatedEnv = getValidatedEnv();
|
|
42
|
-
return { hasRPCConfig: !!validatedEnv.QVAC_IPC_SOCKET_PATH };
|
|
43
|
-
}
|
|
44
|
-
initializeEngine();
|
|
45
|
-
const { hasRPCConfig } = initEnv();
|
|
46
|
-
acquireWorkerLock();
|
|
47
|
-
setupShutdownHandlers();
|
|
48
|
-
workerInitialized = true;
|
|
49
|
-
logger.debug('Worker initialized');
|
|
50
|
-
logger.debug('Arguments to worker:', Bare.argv);
|
|
51
|
-
return { hasRPCConfig };
|
|
52
|
-
}
|
|
53
|
-
// Read once and unset so processes the worker spawns don't inherit it.
|
|
54
|
-
function takeIPCAuthToken() {
|
|
55
|
-
const token = os.getEnv('QVAC_IPC_AUTH_TOKEN');
|
|
56
|
-
if (token !== undefined)
|
|
57
|
-
os.unsetEnv('QVAC_IPC_AUTH_TOKEN');
|
|
58
|
-
return token;
|
|
59
|
-
}
|
|
60
|
-
export function ensureRPCSetup() {
|
|
61
|
-
if (rpcInitialized)
|
|
62
|
-
return;
|
|
63
|
-
if (!workerInitialized) {
|
|
64
|
-
initializeWorker();
|
|
65
|
-
}
|
|
66
|
-
try {
|
|
67
|
-
const validatedEnv = getValidatedEnv();
|
|
68
|
-
const ipcSocketPath = validatedEnv.QVAC_IPC_SOCKET_PATH;
|
|
69
|
-
if (ipcSocketPath) {
|
|
70
|
-
logger.info(`Running in desktop mode, connecting to IPC socket: ${ipcSocketPath}`);
|
|
71
|
-
const rpc = createIPCClient(ipcSocketPath, {
|
|
72
|
-
onDisconnect: () => void shutdownWorker('ipc-disconnect'),
|
|
73
|
-
authToken: takeIPCAuthToken()
|
|
74
|
-
});
|
|
75
|
-
logger.debug('Desktop IPC client created?', !!rpc);
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
logger.info('Running in BareKit IPC mode');
|
|
79
|
-
createBareKitRPCServer();
|
|
80
|
-
}
|
|
81
|
-
logger.info('Bare worker started and listening for RPC requests');
|
|
82
|
-
logger.debug('Working directory:', os.cwd());
|
|
83
|
-
rpcInitialized = true;
|
|
84
|
-
}
|
|
85
|
-
catch (error) {
|
|
86
|
-
logger.error('Worker error:', error);
|
|
87
|
-
Bare.exit(1);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
export function isWorkerInitialized() {
|
|
91
|
-
return workerInitialized;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Pre-terminate cleanup, callable while the worker is still alive.
|
|
95
|
-
*
|
|
96
|
-
* On platforms where the worker lives in the same OS process as the JS host
|
|
97
|
-
* (i.e. mobile via react-native-bare-kit Worklet), `Bare.exit()` would kill the
|
|
98
|
-
* entire app. This path runs the engine's cleanup (models, swarm, RAG,
|
|
99
|
-
* downloads, registry client, plugin/addon registries) without releasing the
|
|
100
|
-
* worker lock or exiting, leaving the caller (typically the SDK client about to
|
|
101
|
-
* call `worklet.terminate()`) responsible for tearing the worker down.
|
|
102
|
-
*
|
|
103
|
-
* Critical for clean termination: addons hold static state with js_ref_t
|
|
104
|
-
* handles into the current V8 isolate; without this cleanup, those refs survive
|
|
105
|
-
* into the next worklet's isolate and crash on first access.
|
|
106
|
-
*/
|
|
107
|
-
export async function cleanupForTerminate() {
|
|
108
|
-
await cleanupEngineForTerminate();
|
|
109
|
-
}
|
|
110
|
-
export async function shutdownWorker(reason) {
|
|
111
|
-
if (isShuttingDown)
|
|
112
|
-
return;
|
|
113
|
-
isShuttingDown = true;
|
|
114
|
-
const messages = {
|
|
115
|
-
signal: '🐻 Bare worker shutdown signal received, cleaning up...',
|
|
116
|
-
'rpc-close': '🧹 Worker RPC closed, cleaning up...',
|
|
117
|
-
'uncaught-exception': '💥 Uncaught exception, cleaning up...',
|
|
118
|
-
'unhandled-rejection': '💥 Unhandled rejection, cleaning up...',
|
|
119
|
-
'ipc-disconnect': '🔌 Parent IPC disconnected, cleaning up...'
|
|
120
|
-
};
|
|
121
|
-
logger.info(messages[reason]);
|
|
122
|
-
try {
|
|
123
|
-
// Idempotent: if cleanupForTerminate already ran, this only releases the
|
|
124
|
-
// engine's cache lock.
|
|
125
|
-
await closeEngine();
|
|
126
|
-
logger.info('✅ Cleanup completed successfully');
|
|
127
|
-
}
|
|
128
|
-
catch (error) {
|
|
129
|
-
logger.error('❌ Error during shutdown cleanup:', error);
|
|
130
|
-
}
|
|
131
|
-
releaseWorkerLock();
|
|
132
|
-
scheduleForceExit();
|
|
133
|
-
const isGraceful = reason === 'signal' || reason === 'rpc-close';
|
|
134
|
-
Bare.exit(isGraceful ? 0 : 1);
|
|
135
|
-
}
|
|
136
|
-
function setupShutdownHandlers() {
|
|
137
|
-
const signals = new Signal.Emitter();
|
|
138
|
-
signals.unref();
|
|
139
|
-
signals.once('SIGTERM', () => void shutdownWorker('signal'));
|
|
140
|
-
signals.once('SIGINT', () => void shutdownWorker('signal'));
|
|
141
|
-
Bare.on('uncaughtException', (err) => {
|
|
142
|
-
logger.error('Uncaught exception in worker:', err);
|
|
143
|
-
void shutdownWorker('uncaught-exception');
|
|
144
|
-
});
|
|
145
|
-
Bare.on('unhandledRejection', (reason) => {
|
|
146
|
-
logger.error('Unhandled rejection in worker:', reason);
|
|
147
|
-
void shutdownWorker('unhandled-rejection');
|
|
148
|
-
});
|
|
149
|
-
}
|