@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
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { ModelHandleInvalidatedError, SessionInvalidatedError } from '../utils/errors-client.js';
|
|
2
|
+
/** The owner's id in errors about its own model handles. It never goes on the wire. */
|
|
3
|
+
export const OWNER_HANDLE_ID = 'owner';
|
|
4
|
+
/** Sessions that have not ended; runtime shutdown and worker loss end them all. */
|
|
5
|
+
const openSessions = new Set();
|
|
6
|
+
/**
|
|
7
|
+
* The record behind a call's options rides on the options object under a
|
|
8
|
+
* symbol key, so the RPC layer finds the session's state without a lookup by
|
|
9
|
+
* id that would have to outlive the handle. A symbol-keyed own property
|
|
10
|
+
* survives the spreads the API functions make of their options and never
|
|
11
|
+
* reaches JSON.
|
|
12
|
+
*/
|
|
13
|
+
const SESSION_RECORD = Symbol('qvac.sessionRecord');
|
|
14
|
+
/** Model ids the owner loaded on the running runtime and has not unloaded. */
|
|
15
|
+
const ownerModels = new Set();
|
|
16
|
+
/**
|
|
17
|
+
* Model ids the owner loaded on a runtime that has since stopped. A call
|
|
18
|
+
* naming one is refused locally until a load returns the same id again.
|
|
19
|
+
*/
|
|
20
|
+
const invalidOwnerModels = new Set();
|
|
21
|
+
export function createSessionRecord(sessionId, opened) {
|
|
22
|
+
const record = {
|
|
23
|
+
sessionId,
|
|
24
|
+
opened,
|
|
25
|
+
openError: undefined,
|
|
26
|
+
ended: undefined,
|
|
27
|
+
heldModels: new Set()
|
|
28
|
+
};
|
|
29
|
+
// A session the worker refused never opened: the handle keeps the error for
|
|
30
|
+
// its later calls, and the registry lets the record go.
|
|
31
|
+
opened.catch((error) => {
|
|
32
|
+
record.openError = error;
|
|
33
|
+
openSessions.delete(record);
|
|
34
|
+
});
|
|
35
|
+
openSessions.add(record);
|
|
36
|
+
return record;
|
|
37
|
+
}
|
|
38
|
+
export function endSession(record, reason) {
|
|
39
|
+
openSessions.delete(record);
|
|
40
|
+
if (record.ended === undefined)
|
|
41
|
+
record.ended = reason;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Runtime shutdown or worker loss: every open session is gone with it, and so
|
|
45
|
+
* is every model the owner had loaded.
|
|
46
|
+
*/
|
|
47
|
+
export function endAllSessions(reason) {
|
|
48
|
+
for (const record of openSessions)
|
|
49
|
+
endSession(record, reason);
|
|
50
|
+
for (const modelId of ownerModels)
|
|
51
|
+
invalidOwnerModels.add(modelId);
|
|
52
|
+
ownerModels.clear();
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Whether this client has a session open or still opening. A session counts
|
|
56
|
+
* from `openSession()`, before the worker has registered it; one whose open
|
|
57
|
+
* failed does not.
|
|
58
|
+
*/
|
|
59
|
+
export function hasClientSessions() {
|
|
60
|
+
for (const record of openSessions) {
|
|
61
|
+
if (record.openError === undefined)
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
export function isSessionEnded(record) {
|
|
67
|
+
return record.ended !== undefined;
|
|
68
|
+
}
|
|
69
|
+
/** Binds the session behind a call's options; the handle calls it for every option object it stamps. */
|
|
70
|
+
export function bindSession(options, record) {
|
|
71
|
+
;
|
|
72
|
+
options[SESSION_RECORD] = record;
|
|
73
|
+
}
|
|
74
|
+
/** The session behind a call's options, or undefined for an owner call or a bare `sessionId`. */
|
|
75
|
+
export function sessionOf(options) {
|
|
76
|
+
return options === undefined ? undefined : options[SESSION_RECORD];
|
|
77
|
+
}
|
|
78
|
+
/** A load resolved: the session behind the options, or the owner when there is no `sessionId`, holds the model. */
|
|
79
|
+
export function recordHeldModel(options, modelId) {
|
|
80
|
+
if (options?.sessionId === undefined) {
|
|
81
|
+
invalidOwnerModels.delete(modelId);
|
|
82
|
+
ownerModels.add(modelId);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
sessionOf(options)?.heldModels.add(modelId);
|
|
86
|
+
}
|
|
87
|
+
/** An unload released the caller's lease on the model. */
|
|
88
|
+
export function releaseHeldModel(options, modelId) {
|
|
89
|
+
if (options?.sessionId === undefined) {
|
|
90
|
+
ownerModels.delete(modelId);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
sessionOf(options)?.heldModels.delete(modelId);
|
|
94
|
+
}
|
|
95
|
+
export function isModelHeldBySession(record, modelId) {
|
|
96
|
+
return record.heldModels.has(modelId);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Called by the RPC layer before a session-stamped request leaves the
|
|
100
|
+
* process. Resolves once the session is open on the worker; rejects with the
|
|
101
|
+
* typed local error when the session can no longer be used.
|
|
102
|
+
*/
|
|
103
|
+
export async function awaitSessionUsable(record, request) {
|
|
104
|
+
assertSessionUsable(record, request);
|
|
105
|
+
await record.opened;
|
|
106
|
+
assertSessionUsable(record, request);
|
|
107
|
+
}
|
|
108
|
+
/** The check `awaitSessionUsable` makes, without waiting for the open. */
|
|
109
|
+
export function assertSessionUsable(record, request) {
|
|
110
|
+
if (record.openError !== undefined)
|
|
111
|
+
throw record.openError;
|
|
112
|
+
if (record.ended !== undefined)
|
|
113
|
+
throw endedError(record, request.modelId);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Called by the RPC layer before an owner request leaves the process. A model
|
|
117
|
+
* the owner loaded on a runtime that has since stopped is refused here, so
|
|
118
|
+
* the caller learns why the id is dead instead of getting a not-found error
|
|
119
|
+
* from a fresh worker.
|
|
120
|
+
*/
|
|
121
|
+
// Requests whose `modelId` does not need the model loaded: `deleteCache` uses
|
|
122
|
+
// it only to locate cache files on disk, and a `cancel` by model on a runtime
|
|
123
|
+
// that no longer has the model finds nothing to cancel.
|
|
124
|
+
const OWNER_REQUESTS_WITHOUT_MODEL_HANDLE = new Set(['deleteCache', 'cancel']);
|
|
125
|
+
export function assertOwnerModelUsable(request) {
|
|
126
|
+
if (OWNER_REQUESTS_WITHOUT_MODEL_HANDLE.has(request.type))
|
|
127
|
+
return;
|
|
128
|
+
const modelId = request.modelId;
|
|
129
|
+
if (modelId !== undefined && invalidOwnerModels.has(modelId)) {
|
|
130
|
+
throw new ModelHandleInvalidatedError(modelId, OWNER_HANDLE_ID);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function endedError(record, modelId) {
|
|
134
|
+
const reason = record.ended ?? 'closed';
|
|
135
|
+
if (modelId !== undefined && record.heldModels.has(modelId)) {
|
|
136
|
+
return new ModelHandleInvalidatedError(modelId, record.sessionId);
|
|
137
|
+
}
|
|
138
|
+
return new SessionInvalidatedError(record.sessionId, reason);
|
|
139
|
+
}
|
|
140
|
+
/** Test seam: the number of sessions the registry tracks as open or opening. */
|
|
141
|
+
export function trackedSessionCount() {
|
|
142
|
+
return openSessions.size;
|
|
143
|
+
}
|
|
144
|
+
/** Test seam: forget every open session and owner model. */
|
|
145
|
+
export function resetSessionRegistry() {
|
|
146
|
+
openSessions.clear();
|
|
147
|
+
ownerModels.clear();
|
|
148
|
+
invalidOwnerModels.clear();
|
|
149
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import type { RPCOptions } from '@qvac/inference/surface';
|
|
2
|
+
import * as api from '../client/api/index.js';
|
|
3
|
+
import { send } from '../client/rpc/rpc-client.js';
|
|
4
|
+
import { type SessionRecord } from '../client/session-registry.js';
|
|
5
|
+
export interface OpenSessionOptions {
|
|
6
|
+
/** Label for worker logs and diagnostics. */
|
|
7
|
+
name?: string;
|
|
8
|
+
}
|
|
9
|
+
type Api = typeof api;
|
|
10
|
+
/**
|
|
11
|
+
* A caller session on the shared runtime. It has the same methods as the
|
|
12
|
+
* module-level SDK; every call made through it carries the session id, so:
|
|
13
|
+
*
|
|
14
|
+
* - `cancel` only reaches this session's requests;
|
|
15
|
+
* - `loadModel` takes a lease on the model, and `unloadModel` releases only
|
|
16
|
+
* this session's lease;
|
|
17
|
+
* - `close()` cancels the session's requests, disposes the vector indexes it
|
|
18
|
+
* opened and releases its leases.
|
|
19
|
+
*
|
|
20
|
+
* A session never shuts the runtime down. Only the module-level `close()`,
|
|
21
|
+
* the owner's call, does that, and it ends every session with it. The
|
|
22
|
+
* operations that change the runtime for every session (`suspend`, `resume`,
|
|
23
|
+
* `deleteCache`, `startRpcServer`, `stopRpcServer`) are not on the handle;
|
|
24
|
+
* the worker refuses them from a session with `OwnerOnlyError`.
|
|
25
|
+
*/
|
|
26
|
+
export interface QvacSession {
|
|
27
|
+
readonly sessionId: string;
|
|
28
|
+
readonly name: string | undefined;
|
|
29
|
+
/** Resolves once the worker has registered the session. Calls queue behind it on their own. */
|
|
30
|
+
readonly opened: Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Whether this session loaded `modelId` and has not unloaded it. Stays true
|
|
33
|
+
* after the session ends: a call naming such a model then fails with
|
|
34
|
+
* `ModelHandleInvalidatedError` instead of `SessionInvalidatedError`.
|
|
35
|
+
*/
|
|
36
|
+
isModelHeld(modelId: string): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Cancels the session's requests, disposes the vector indexes it opened,
|
|
39
|
+
* releases its model leases and ends the handle.
|
|
40
|
+
*/
|
|
41
|
+
close(options?: RPCOptions): Promise<void>;
|
|
42
|
+
loadModel: Api['loadModel'];
|
|
43
|
+
downloadAsset: Api['downloadAsset'];
|
|
44
|
+
unloadModel: Api['unloadModel'];
|
|
45
|
+
completion: Api['completion'];
|
|
46
|
+
batchCompletion: Api['batchCompletion'];
|
|
47
|
+
embed: Api['embed'];
|
|
48
|
+
embedBatch: Api['embedBatch'];
|
|
49
|
+
decide: Api['decide'];
|
|
50
|
+
rerank: Api['rerank'];
|
|
51
|
+
transcribe: Api['transcribe'];
|
|
52
|
+
transcribeStream: Api['transcribeStream'];
|
|
53
|
+
bciTranscribe: Api['bciTranscribe'];
|
|
54
|
+
bciTranscribeStream: Api['bciTranscribeStream'];
|
|
55
|
+
translate: Api['translate'];
|
|
56
|
+
textToSpeech: Api['textToSpeech'];
|
|
57
|
+
textToSpeechStream: Api['textToSpeechStream'];
|
|
58
|
+
finetune: Api['finetune'];
|
|
59
|
+
cancel: Api['cancel'];
|
|
60
|
+
ragChunk: Api['ragChunk'];
|
|
61
|
+
ragIngest: Api['ragIngest'];
|
|
62
|
+
ragSaveEmbeddings: Api['ragSaveEmbeddings'];
|
|
63
|
+
ragSearch: Api['ragSearch'];
|
|
64
|
+
ragDeleteEmbeddings: Api['ragDeleteEmbeddings'];
|
|
65
|
+
ragReindex: Api['ragReindex'];
|
|
66
|
+
ragListWorkspaces: Api['ragListWorkspaces'];
|
|
67
|
+
ragCloseWorkspace: Api['ragCloseWorkspace'];
|
|
68
|
+
ragDeleteWorkspace: Api['ragDeleteWorkspace'];
|
|
69
|
+
createVectorIndex: Api['createVectorIndex'];
|
|
70
|
+
loadVectorIndex: Api['loadVectorIndex'];
|
|
71
|
+
ocr: Api['ocr'];
|
|
72
|
+
classify: Api['classify'];
|
|
73
|
+
diffusion: Api['diffusion'];
|
|
74
|
+
upscale: Api['upscale'];
|
|
75
|
+
video: Api['video'];
|
|
76
|
+
worldCreateScene: Api['worldCreateScene'];
|
|
77
|
+
worldStep: Api['worldStep'];
|
|
78
|
+
audioGen: Api['audioGen'];
|
|
79
|
+
audioEdit: Api['audioEdit'];
|
|
80
|
+
audioUnderstand: Api['audioUnderstand'];
|
|
81
|
+
vla: Api['vla'];
|
|
82
|
+
vlaHparams: Api['vlaHparams'];
|
|
83
|
+
vlaSetEmbodiment: Api['vlaSetEmbodiment'];
|
|
84
|
+
invokePlugin: Api['invokePlugin'];
|
|
85
|
+
invokePluginStream: Api['invokePluginStream'];
|
|
86
|
+
calcTokens: Api['calcTokens'];
|
|
87
|
+
getModelInfo: Api['getModelInfo'];
|
|
88
|
+
getLoadedModelInfo: Api['getLoadedModelInfo'];
|
|
89
|
+
getSystemResources: Api['getSystemResources'];
|
|
90
|
+
assessModelFit: Api['assessModelFit'];
|
|
91
|
+
heartbeat: Api['heartbeat'];
|
|
92
|
+
loggingStream: Api['loggingStream'];
|
|
93
|
+
subscribeServerLogs: Api['subscribeServerLogs'];
|
|
94
|
+
modelRegistryList: Api['modelRegistryList'];
|
|
95
|
+
modelRegistrySearch: Api['modelRegistrySearch'];
|
|
96
|
+
modelRegistryGetModel: Api['modelRegistryGetModel'];
|
|
97
|
+
state: Api['state'];
|
|
98
|
+
discoverRpcServers: Api['discoverRpcServers'];
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Opens a caller session on the runtime and returns its handle at once. The
|
|
102
|
+
* `openSession` round trip runs in the background; calls made on the handle
|
|
103
|
+
* wait for it, so the handle is usable immediately.
|
|
104
|
+
*
|
|
105
|
+
* @param options - `name` labels the session in worker logs.
|
|
106
|
+
* @returns The session handle.
|
|
107
|
+
* @throws {SessionIdConflictError} Through `session.opened` and every call,
|
|
108
|
+
* when the worker already has a session with the minted id.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* const a = openSession({ name: 'harness' })
|
|
113
|
+
* const b = openSession({ name: 'skill-runner' })
|
|
114
|
+
* const modelId = await a.loadModel({ modelSrc: QWEN3_600M_INST_Q4 })
|
|
115
|
+
* await b.loadModel({ modelSrc: QWEN3_600M_INST_Q4 }) // same model, second lease
|
|
116
|
+
* const run = a.completion({ modelId, history: [...] })
|
|
117
|
+
* await b.cancel({ requestId: run.requestId }) // cancelled: 0, the run continues
|
|
118
|
+
* await a.close() // releases a's lease, the model stays for b
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export declare function openSession(options?: OpenSessionOptions): QvacSession;
|
|
122
|
+
/** `session.close()`, with the transport passed in so tests can fail it. */
|
|
123
|
+
export declare function closeSessionRecord(record: SessionRecord, options?: RPCOptions, sendRequest?: typeof send): Promise<void>;
|
|
124
|
+
export {};
|
|
125
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import * as api from '../client/api/index.js';
|
|
2
|
+
import { createVectorIndexClient } from '../client/api/vector-index.js';
|
|
3
|
+
import { send } from '../client/rpc/rpc-client.js';
|
|
4
|
+
import { generateClientRequestId } from '../client/api/client-request-id.js';
|
|
5
|
+
import { bindSession, createSessionRecord, endSession, isModelHeldBySession, isSessionEnded } from '../client/session-registry.js';
|
|
6
|
+
import { InvalidResponseError, SessionInvalidatedError } from '../utils/errors-client.js';
|
|
7
|
+
/**
|
|
8
|
+
* Opens a caller session on the runtime and returns its handle at once. The
|
|
9
|
+
* `openSession` round trip runs in the background; calls made on the handle
|
|
10
|
+
* wait for it, so the handle is usable immediately.
|
|
11
|
+
*
|
|
12
|
+
* @param options - `name` labels the session in worker logs.
|
|
13
|
+
* @returns The session handle.
|
|
14
|
+
* @throws {SessionIdConflictError} Through `session.opened` and every call,
|
|
15
|
+
* when the worker already has a session with the minted id.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const a = openSession({ name: 'harness' })
|
|
20
|
+
* const b = openSession({ name: 'skill-runner' })
|
|
21
|
+
* const modelId = await a.loadModel({ modelSrc: QWEN3_600M_INST_Q4 })
|
|
22
|
+
* await b.loadModel({ modelSrc: QWEN3_600M_INST_Q4 }) // same model, second lease
|
|
23
|
+
* const run = a.completion({ modelId, history: [...] })
|
|
24
|
+
* await b.cancel({ requestId: run.requestId }) // cancelled: 0, the run continues
|
|
25
|
+
* await a.close() // releases a's lease, the model stays for b
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export function openSession(options = {}) {
|
|
29
|
+
const sessionId = generateClientRequestId();
|
|
30
|
+
const name = options.name;
|
|
31
|
+
const opened = sendOpenSession({ type: 'openSession', sessionId, ...(name && { name }) });
|
|
32
|
+
// Later calls surface the failure themselves; an unobserved rejection here
|
|
33
|
+
// must not crash the host.
|
|
34
|
+
opened.catch(() => { });
|
|
35
|
+
return createSessionHandle(createSessionRecord(sessionId, opened), name);
|
|
36
|
+
}
|
|
37
|
+
async function sendOpenSession(request) {
|
|
38
|
+
const response = await send(request);
|
|
39
|
+
if (response.type !== 'openSession')
|
|
40
|
+
throw new InvalidResponseError('openSession');
|
|
41
|
+
}
|
|
42
|
+
/** `session.close()`, with the transport passed in so tests can fail it. */
|
|
43
|
+
export async function closeSessionRecord(record, options, sendRequest = send) {
|
|
44
|
+
const assertNotEnded = () => {
|
|
45
|
+
if (isSessionEnded(record)) {
|
|
46
|
+
throw new SessionInvalidatedError(record.sessionId, record.ended ?? 'closed');
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
assertNotEnded();
|
|
50
|
+
await record.opened;
|
|
51
|
+
// The owner's close can end the session during the wait. Sending then
|
|
52
|
+
// would start a new worker only to close a session it never had.
|
|
53
|
+
assertNotEnded();
|
|
54
|
+
const request = { type: 'closeSession', sessionId: record.sessionId };
|
|
55
|
+
try {
|
|
56
|
+
const response = await sendRequest(request, options);
|
|
57
|
+
if (response.type !== 'closeSession')
|
|
58
|
+
throw new InvalidResponseError('closeSession');
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
// The worker stops accepting the session as soon as the close reaches
|
|
62
|
+
// it, so a close whose reply was lost (a timeout, a transport error)
|
|
63
|
+
// still ends it there, and a retry could only get SessionNotOpenError.
|
|
64
|
+
endSession(record, 'closed');
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function createSessionHandle(record, name) {
|
|
68
|
+
const { sessionId, opened } = record;
|
|
69
|
+
// Session-stamped options for every wire call made through the handle. A
|
|
70
|
+
// caller's own options are kept; `sessionId` is set by the handle, and the
|
|
71
|
+
// record behind it rides along for the RPC layer's local checks.
|
|
72
|
+
const withSession = (options) => {
|
|
73
|
+
const stamped = { ...options, sessionId };
|
|
74
|
+
bindSession(stamped, record);
|
|
75
|
+
return stamped;
|
|
76
|
+
};
|
|
77
|
+
// A vector index handle outlives the call that opened it, so its client is
|
|
78
|
+
// built over a session-stamped transport: every later call on the handle
|
|
79
|
+
// runs as this session too.
|
|
80
|
+
const vectorIndexes = createVectorIndexClient((request, options) => send(request, withSession(options)));
|
|
81
|
+
// `loadModel` is overloaded, so its parameter type is not contextually
|
|
82
|
+
// available; the public type is restored by the cast.
|
|
83
|
+
const loadModel = ((options, rpcOptions) => api.loadModel(options, withSession(rpcOptions)));
|
|
84
|
+
return {
|
|
85
|
+
sessionId,
|
|
86
|
+
name,
|
|
87
|
+
opened,
|
|
88
|
+
isModelHeld: (modelId) => isModelHeldBySession(record, modelId),
|
|
89
|
+
close: (options) => closeSessionRecord(record, options),
|
|
90
|
+
loadModel,
|
|
91
|
+
unloadModel: (params, options) => api.unloadModel(params, withSession(options)),
|
|
92
|
+
downloadAsset: (options, rpcOptions) => api.downloadAsset(options, withSession(rpcOptions)),
|
|
93
|
+
completion: (params) => api.completion({ ...params, rpcOptions: withSession(params.rpcOptions) }),
|
|
94
|
+
batchCompletion: (params) => api.batchCompletion({ ...params, rpcOptions: withSession(params.rpcOptions) }),
|
|
95
|
+
embed: ((params, options) => api.embed(params, withSession(options))),
|
|
96
|
+
embedBatch: (params, options) => api.embedBatch(params, withSession(options)),
|
|
97
|
+
decide: ((params, options) => api.decide(params, withSession(options))),
|
|
98
|
+
rerank: (params, options) => api.rerank(params, withSession(options)),
|
|
99
|
+
transcribe: ((params, options) => api.transcribe(params, withSession(options))),
|
|
100
|
+
transcribeStream: ((params, options) => api.transcribeStream(params, withSession(options))),
|
|
101
|
+
bciTranscribe: ((params, options) => api.bciTranscribe(params, withSession(options))),
|
|
102
|
+
bciTranscribeStream: ((params, options) => api.bciTranscribeStream(params, withSession(options))),
|
|
103
|
+
translate: (params, options) => api.translate(params, withSession(options)),
|
|
104
|
+
textToSpeech: (params, options) => api.textToSpeech(params, withSession(options)),
|
|
105
|
+
textToSpeechStream: (params, options) => api.textToSpeechStream(params, withSession(options)),
|
|
106
|
+
finetune: ((params, options) => api.finetune(params, withSession(options))),
|
|
107
|
+
cancel: (params, options) => api.cancel(params, withSession(options)),
|
|
108
|
+
ragChunk: (params, options) => api.ragChunk(params, withSession(options)),
|
|
109
|
+
ragIngest: (params, options) => api.ragIngest(params, withSession(options)),
|
|
110
|
+
ragSaveEmbeddings: (params, options) => api.ragSaveEmbeddings(params, withSession(options)),
|
|
111
|
+
ragSearch: (params, options) => api.ragSearch(params, withSession(options)),
|
|
112
|
+
ragDeleteEmbeddings: (params, options) => api.ragDeleteEmbeddings(params, withSession(options)),
|
|
113
|
+
ragReindex: (params, options) => api.ragReindex(params, withSession(options)),
|
|
114
|
+
ragListWorkspaces: (options) => api.ragListWorkspaces(withSession(options)),
|
|
115
|
+
ragCloseWorkspace: (params, options) => api.ragCloseWorkspace(params, withSession(options)),
|
|
116
|
+
ragDeleteWorkspace: (params, options) => api.ragDeleteWorkspace(params, withSession(options)),
|
|
117
|
+
createVectorIndex: vectorIndexes.createVectorIndex,
|
|
118
|
+
loadVectorIndex: vectorIndexes.loadVectorIndex,
|
|
119
|
+
ocr: (params, options) => api.ocr(params, withSession(options)),
|
|
120
|
+
classify: (params, options) => api.classify(params, withSession(options)),
|
|
121
|
+
diffusion: (params, options) => api.diffusion(params, withSession(options)),
|
|
122
|
+
upscale: (params, options) => api.upscale(params, withSession(options)),
|
|
123
|
+
video: (params, options) => api.video(params, withSession(options)),
|
|
124
|
+
worldCreateScene: ((params, options) => api.worldCreateScene(params, withSession(options))),
|
|
125
|
+
worldStep: (params, options) => api.worldStep(params, withSession(options)),
|
|
126
|
+
audioGen: (params, options) => api.audioGen(params, withSession(options)),
|
|
127
|
+
audioEdit: (params, options) => api.audioEdit(params, withSession(options)),
|
|
128
|
+
audioUnderstand: (params, options) => api.audioUnderstand(params, withSession(options)),
|
|
129
|
+
vla: (params, options) => api.vla(params, withSession(options)),
|
|
130
|
+
vlaHparams: (params, options) => api.vlaHparams(params, withSession(options)),
|
|
131
|
+
vlaSetEmbodiment: (params, options) => api.vlaSetEmbodiment(params, withSession(options)),
|
|
132
|
+
invokePlugin: (options, rpcOptions) => api.invokePlugin(options, withSession(rpcOptions)),
|
|
133
|
+
invokePluginStream: (options, rpcOptions) => api.invokePluginStream(options, withSession(rpcOptions)),
|
|
134
|
+
calcTokens: (params, options) => api.calcTokens(params, withSession(options)),
|
|
135
|
+
getModelInfo: (params, options) => api.getModelInfo(params, withSession(options)),
|
|
136
|
+
getLoadedModelInfo: (params, options) => api.getLoadedModelInfo(params, withSession(options)),
|
|
137
|
+
getSystemResources: (input, options) => api.getSystemResources(input, withSession(options)),
|
|
138
|
+
assessModelFit: (input, options) => api.assessModelFit(input, withSession(options)),
|
|
139
|
+
heartbeat: (options) => api.heartbeat(withSession(options)),
|
|
140
|
+
loggingStream: (params, options) => api.loggingStream(params, withSession(options)),
|
|
141
|
+
subscribeServerLogs: (handler, options) => api.subscribeServerLogs(handler, withSession(options)),
|
|
142
|
+
modelRegistryList: (options) => api.modelRegistryList(withSession(options)),
|
|
143
|
+
modelRegistrySearch: (params, options) => api.modelRegistrySearch(params, withSession(options)),
|
|
144
|
+
modelRegistryGetModel: (registryPath, registrySource, options) => api.modelRegistryGetModel(registryPath, registrySource, withSession(options)),
|
|
145
|
+
state: (options) => api.state(withSession(options)),
|
|
146
|
+
discoverRpcServers: (options, rpcOptions) => api.discoverRpcServers(options, withSession(rpcOptions))
|
|
147
|
+
};
|
|
148
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Logger } from '../../logging/types.js';
|
|
2
|
+
interface ListBundledAddonsOptions {
|
|
3
|
+
bundlePath: string;
|
|
4
|
+
projectRoot: string;
|
|
5
|
+
logger: Logger;
|
|
6
|
+
includeAudioDecoder?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare const AUDIO_DECODER_ADDON = "bare-ffmpeg";
|
|
9
|
+
export declare function buildNestedPathIndex(resolutions: Record<string, unknown>, projectRoot: string): Map<string, Set<string>>;
|
|
10
|
+
/** The native addon packages the bundle's module graph loads, sorted by name. */
|
|
11
|
+
export declare function listBundledAddons(options: ListBundledAddonsOptions): Promise<string[]>;
|
|
12
|
+
export declare function listBundledAddonModules(options: ListBundledAddonsOptions): Promise<string[]>;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=addons.d.ts.map
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import fs, { promises as fsp } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { bundleRoot, readBundle } from '../../commands/bundle/read-bundle.js';
|
|
4
|
+
export const AUDIO_DECODER_ADDON = 'bare-ffmpeg';
|
|
5
|
+
const NODE_MODULES_RE = /\/node_modules\/(@[^/]+\/[^/]+|[^/]+)(?=\/)/g;
|
|
6
|
+
export function buildNestedPathIndex(resolutions, projectRoot) {
|
|
7
|
+
const index = new Map();
|
|
8
|
+
for (const key of Object.keys(resolutions)) {
|
|
9
|
+
for (const match of key.matchAll(NODE_MODULES_RE)) {
|
|
10
|
+
const pkgName = match[1];
|
|
11
|
+
if (!pkgName)
|
|
12
|
+
continue;
|
|
13
|
+
const idx = match.index;
|
|
14
|
+
if (idx === undefined)
|
|
15
|
+
continue;
|
|
16
|
+
const marker = `/node_modules/${pkgName}/`;
|
|
17
|
+
const candidate = path.join(projectRoot, key.slice(1, idx + marker.length), 'package.json');
|
|
18
|
+
let set = index.get(pkgName);
|
|
19
|
+
if (!set) {
|
|
20
|
+
set = new Set();
|
|
21
|
+
index.set(pkgName, set);
|
|
22
|
+
}
|
|
23
|
+
set.add(candidate);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return index;
|
|
27
|
+
}
|
|
28
|
+
/** The native addon packages the bundle's module graph loads, sorted by name. */
|
|
29
|
+
export async function listBundledAddons(options) {
|
|
30
|
+
const { bundlePath, projectRoot, logger, includeAudioDecoder = true } = options;
|
|
31
|
+
const bundle = await readBundle(bundlePath);
|
|
32
|
+
const pathsByPackage = buildNestedPathIndex(bundle.resolutions, bundleRoot(bundle.main, projectRoot));
|
|
33
|
+
const addons = [];
|
|
34
|
+
for (const [pkgName, candidates] of pathsByPackage) {
|
|
35
|
+
let pkgJson = null;
|
|
36
|
+
for (const candidate of candidates) {
|
|
37
|
+
try {
|
|
38
|
+
if (fs.existsSync(candidate)) {
|
|
39
|
+
pkgJson = JSON.parse(await fsp.readFile(candidate, 'utf8'));
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
logger.warn(` Could not read ${candidate}: ${err.message}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (pkgJson?.addon === true && (includeAudioDecoder || pkgName !== AUDIO_DECODER_ADDON)) {
|
|
48
|
+
addons.push(pkgName);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return addons.sort();
|
|
52
|
+
}
|
|
53
|
+
export async function listBundledAddonModules(options) {
|
|
54
|
+
const addons = new Set(await listBundledAddons(options));
|
|
55
|
+
const bundle = await readBundle(options.bundlePath);
|
|
56
|
+
const root = bundleRoot(bundle.main, options.projectRoot);
|
|
57
|
+
return Object.keys(bundle.resolutions)
|
|
58
|
+
.filter((key) => {
|
|
59
|
+
const packages = [...key.matchAll(NODE_MODULES_RE)];
|
|
60
|
+
const owner = packages[packages.length - 1]?.[1];
|
|
61
|
+
return owner !== undefined && addons.has(owner);
|
|
62
|
+
})
|
|
63
|
+
.map((key) => path.join(root, key.slice(1)))
|
|
64
|
+
.sort();
|
|
65
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export const BUILTIN_PLUGINS = {
|
|
2
2
|
'llamacpp-completion': { exportName: 'llmPlugin' },
|
|
3
3
|
'llamacpp-embedding': { exportName: 'embeddingsPlugin' },
|
|
4
|
+
'ggml-image-embedding': { exportName: 'imageEmbeddingPlugin' },
|
|
4
5
|
'llamacpp-decision': { exportName: 'decisionPlugin' },
|
|
5
6
|
'llamacpp-rerank': { exportName: 'rerankPlugin' },
|
|
6
7
|
'whispercpp-transcription': { exportName: 'whisperPlugin' },
|
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
export declare function generateWorkerEntry(pluginSpecifiers: string[], sdkName: string, resolveImport?: (specifier: string) => string
|
|
2
|
-
export declare function generateWorkerEntries(pluginSpecifiers: string[], sdkName: string, resolveBundleImport: (specifier: string) => string, rpcServerProvider?: string): {
|
|
3
|
-
runtimeEntry: string;
|
|
4
|
-
bundleEntry: string;
|
|
5
|
-
};
|
|
1
|
+
export declare function generateWorkerEntry(pluginSpecifiers: string[], sdkName: string, rpcServerProvider?: string, resolveImport?: (specifier: string) => string): string;
|
|
6
2
|
//# sourceMappingURL=entry-gen.d.ts.map
|
|
@@ -1,58 +1,25 @@
|
|
|
1
1
|
import { parseBuiltinSpecifier } from '../../commands/bundle/plugins.js';
|
|
2
|
-
export function generateWorkerEntry(pluginSpecifiers, sdkName, resolveImport = (specifier) => specifier
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
if (rpcServerProvider) {
|
|
7
|
-
imports.push(`import { registerRpcServerProvider } from ${JSON.stringify(resolveImport(`${sdkName}/rpc-server-provider`))};`, `import rpcServerProvider from ${JSON.stringify(resolveImport(rpcServerProvider))};`);
|
|
8
|
-
registrations.push('registerRpcServerProvider(rpcServerProvider);');
|
|
9
|
-
}
|
|
2
|
+
export function generateWorkerEntry(pluginSpecifiers, sdkName, rpcServerProvider, resolveImport = (specifier) => specifier) {
|
|
3
|
+
const from = (specifier) => JSON.stringify(resolveImport(specifier));
|
|
4
|
+
const imports = [`import { startWorker } from ${from(`${sdkName}/worker`)}`];
|
|
5
|
+
const plugins = [];
|
|
10
6
|
for (const specifier of pluginSpecifiers) {
|
|
11
7
|
const builtin = parseBuiltinSpecifier(specifier, sdkName);
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const varName = `customPlugin${varIndex++}`;
|
|
18
|
-
imports.push(`import ${varName} from "${resolveImport(specifier)}";`);
|
|
19
|
-
registrations.push(`registerPlugin(${varName});`);
|
|
20
|
-
}
|
|
8
|
+
const name = builtin ? builtin.exportName : `customPlugin${plugins.length}`;
|
|
9
|
+
imports.push(builtin
|
|
10
|
+
? `import { ${name} } from ${from(specifier)}`
|
|
11
|
+
: `import ${name} from ${from(specifier)}`);
|
|
12
|
+
plugins.push(name);
|
|
21
13
|
}
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
* Plugins: ${pluginSpecifiers.length}
|
|
29
|
-
*
|
|
30
|
-
${pluginsList}
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
import { initializeWorker, ensureRPCSetup } from "${resolveImport(`${sdkName}/worker-lifecycle`)}";
|
|
34
|
-
import { registerPlugin } from "${resolveImport(`${sdkName}/plugins`)}";
|
|
35
|
-
import { getServerLogger } from "${resolveImport(`${sdkName}/logging`)}";
|
|
36
|
-
|
|
37
|
-
${importsStr}
|
|
38
|
-
|
|
39
|
-
const { hasRPCConfig } = initializeWorker();
|
|
40
|
-
|
|
41
|
-
const logger = getServerLogger();
|
|
42
|
-
logger.info("🐻 QVAC Worker (custom bundle)");
|
|
43
|
-
logger.info("📦 Plugins: ${pluginSpecifiers.length}");
|
|
44
|
-
|
|
45
|
-
${registrationsStr}
|
|
14
|
+
const options = [`plugins: [${plugins.join(', ')}]`];
|
|
15
|
+
if (rpcServerProvider) {
|
|
16
|
+
imports.push(`import rpcServerProvider from ${from(rpcServerProvider)}`);
|
|
17
|
+
options.push('rpcServerProvider');
|
|
18
|
+
}
|
|
19
|
+
return `${imports.join('\n')}
|
|
46
20
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
ensureRPCSetup();
|
|
21
|
+
export default function start(ipc, ready) {
|
|
22
|
+
return startWorker(ipc, ready, { ${options.join(', ')} })
|
|
50
23
|
}
|
|
51
24
|
`;
|
|
52
25
|
}
|
|
53
|
-
export function generateWorkerEntries(pluginSpecifiers, sdkName, resolveBundleImport, rpcServerProvider) {
|
|
54
|
-
return {
|
|
55
|
-
runtimeEntry: generateWorkerEntry(pluginSpecifiers, sdkName, undefined, rpcServerProvider),
|
|
56
|
-
bundleEntry: generateWorkerEntry(pluginSpecifiers, sdkName, resolveBundleImport, rpcServerProvider)
|
|
57
|
-
};
|
|
58
|
-
}
|