@qvac/sdk 0.8.2 → 0.9.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 +267 -63
- package/README.md +2 -0
- package/dist/client/api/diffusion.d.ts +32 -0
- package/dist/client/api/diffusion.js +103 -0
- package/dist/client/api/embed.d.ts +9 -3
- package/dist/client/api/embed.js +4 -1
- package/dist/client/api/finetune.d.ts +69 -0
- package/dist/client/api/finetune.js +139 -0
- package/dist/client/api/get-model-info.d.ts +1 -1
- package/dist/client/api/index.d.ts +4 -0
- package/dist/client/api/index.js +4 -0
- package/dist/client/api/rag.d.ts +1 -1
- package/dist/client/api/rag.js +1 -1
- package/dist/client/api/resume.d.ts +14 -0
- package/dist/client/api/resume.js +20 -0
- package/dist/client/api/suspend.d.ts +13 -0
- package/dist/client/api/suspend.js +19 -0
- package/dist/client/api/transcribe.d.ts +25 -17
- package/dist/client/api/transcribe.js +115 -35
- package/dist/client/rpc/bare-client.d.ts +5 -1
- package/dist/client/rpc/bare-client.js +70 -57
- package/dist/client/rpc/expo-rpc-client.d.ts +4 -0
- package/dist/client/rpc/expo-rpc-client.js +8 -0
- package/dist/client/rpc/node-rpc-client.d.ts +4 -0
- package/dist/client/rpc/node-rpc-client.js +8 -0
- package/dist/client/rpc/rpc-client.d.ts +13 -0
- package/dist/client/rpc/rpc-client.js +131 -1
- package/dist/examples/delegated-inference/composite.d.ts +2 -0
- package/dist/examples/delegated-inference/composite.js +99 -0
- package/dist/examples/diffusion-flux2-klein.d.ts +2 -0
- package/dist/examples/diffusion-flux2-klein.js +46 -0
- package/dist/examples/diffusion-simple.d.ts +2 -0
- package/dist/examples/diffusion-simple.js +17 -0
- package/dist/examples/diffusion-txt2img.d.ts +2 -0
- package/dist/examples/diffusion-txt2img.js +40 -0
- package/dist/examples/embed-p2p.js +2 -2
- package/dist/examples/finetune/llamacpp-finetune.d.ts +2 -0
- package/dist/examples/finetune/llamacpp-finetune.js +78 -0
- package/dist/examples/logging-streaming.js +1 -1
- package/dist/examples/mcp-websearch.js +2 -0
- package/dist/examples/ocr-fasttext.js +11 -0
- package/dist/examples/profiling/per-call.js +3 -3
- package/dist/examples/rag/rag-chromadb.js +2 -2
- package/dist/examples/rag/rag-hyperdb/pipeline.js +1 -1
- package/dist/examples/rag/rag-lancedb.js +2 -2
- package/dist/examples/rag/rag-sqlite.js +2 -2
- package/dist/examples/suspend-resume.d.ts +2 -0
- package/dist/examples/suspend-resume.js +52 -0
- package/dist/examples/transcription/parakeet-ctc-filesystem.js +3 -5
- package/dist/examples/transcription/parakeet-microphone-record.js +42 -33
- package/dist/examples/transcription/parakeet-sortformer.js +13 -3
- package/dist/examples/transcription/parakeet-tdt-filesystem.js +5 -7
- package/dist/examples/transcription/whispercpp-filesystem-streaming.d.ts +2 -0
- package/dist/examples/transcription/whispercpp-filesystem-streaming.js +99 -0
- package/dist/examples/transcription/whispercpp-microphone-record.js +78 -299
- package/dist/examples/transcription/whispercpp-prompt.js +11 -0
- package/dist/examples/translation/translation-llm.js +2 -2
- package/dist/examples/tts/supertonic-multilingual.d.ts +2 -0
- package/dist/examples/tts/supertonic-multilingual.js +56 -0
- package/dist/examples/tts/supertonic.js +12 -7
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/logging/utils.js +1 -1
- package/dist/models/registry/models.d.ts +15176 -4264
- package/dist/models/registry/models.js +18657 -7404
- package/dist/models/update-models/codegen.js +2 -2
- package/dist/models/update-models/naming.js +26 -0
- package/dist/pear/pre.js +2 -0
- package/dist/polyfills/bare-globals.d.ts +2 -0
- package/dist/polyfills/bare-globals.js +4 -0
- package/dist/polyfills/bare-globals.noop.d.ts +2 -0
- package/dist/polyfills/bare-globals.noop.js +1 -0
- package/dist/profiling/exporters.js +16 -11
- package/dist/profiling/model-execution.d.ts +16 -0
- package/dist/profiling/model-execution.js +33 -0
- package/dist/schemas/common.d.ts +967 -198
- package/dist/schemas/common.js +16 -1
- package/dist/schemas/completion-stream.d.ts +14 -6
- package/dist/schemas/completion-stream.js +4 -3
- package/dist/schemas/download-asset.d.ts +7 -3
- package/dist/schemas/embed.d.ts +19 -0
- package/dist/schemas/embed.js +7 -0
- package/dist/schemas/engine-addon-map.js +4 -1
- package/dist/schemas/finetune.d.ts +620 -0
- package/dist/schemas/finetune.js +161 -0
- package/dist/schemas/get-model-info.d.ts +2 -0
- package/dist/schemas/get-model-info.js +1 -0
- package/dist/schemas/index.d.ts +5 -1
- package/dist/schemas/index.js +5 -1
- package/dist/schemas/llamacpp-config.d.ts +26 -6
- package/dist/schemas/llamacpp-config.js +12 -0
- package/dist/schemas/load-model.d.ts +4005 -1400
- package/dist/schemas/load-model.js +34 -1
- package/dist/schemas/model-src-utils.d.ts +10 -2
- package/dist/schemas/model-types.d.ts +19 -1
- package/dist/schemas/model-types.js +11 -0
- package/dist/schemas/ocr.d.ts +2 -0
- package/dist/schemas/plugin.d.ts +24 -3
- package/dist/schemas/plugin.js +14 -0
- package/dist/schemas/profiling.d.ts +4 -0
- package/dist/schemas/profiling.js +4 -0
- package/dist/schemas/registry.d.ts +18 -0
- package/dist/schemas/registry.js +2 -0
- package/dist/schemas/reload-config.d.ts +9 -1
- package/dist/schemas/resume.d.ts +10 -0
- package/dist/schemas/resume.js +7 -0
- package/dist/schemas/sdcpp-config.d.ts +327 -0
- package/dist/schemas/sdcpp-config.js +102 -0
- package/dist/schemas/sdk-config.d.ts +1225 -235
- package/dist/schemas/sdk-config.js +4 -0
- package/dist/schemas/sdk-errors-server.d.ts +2 -0
- package/dist/schemas/sdk-errors-server.js +12 -0
- package/dist/schemas/suspend.d.ts +10 -0
- package/dist/schemas/suspend.js +7 -0
- package/dist/schemas/text-to-speech.d.ts +187 -10
- package/dist/schemas/text-to-speech.js +12 -4
- package/dist/schemas/transcription-config.d.ts +16 -56
- package/dist/schemas/transcription-config.js +0 -2
- package/dist/schemas/transcription.d.ts +66 -6
- package/dist/schemas/transcription.js +29 -7
- package/dist/schemas/translate.d.ts +14 -4
- package/dist/schemas/translate.js +10 -2
- package/dist/schemas/translation-config.d.ts +30 -10
- package/dist/server/bare/delegate-rpc-client.js +3 -3
- package/dist/server/bare/hyperswarm.js +15 -3
- package/dist/server/bare/ops/embed.d.ts +8 -4
- package/dist/server/bare/ops/embed.js +15 -4
- package/dist/server/bare/ops/transcribe.d.ts +6 -2
- package/dist/server/bare/ops/transcribe.js +53 -1
- package/dist/server/bare/ops/translate.d.ts +4 -1
- package/dist/server/bare/ops/translate.js +28 -65
- package/dist/server/bare/ops/unload-model.js +2 -0
- package/dist/server/bare/plugins/index.d.ts +1 -0
- package/dist/server/bare/plugins/index.js +1 -0
- package/dist/server/bare/plugins/llamacpp-completion/ops/cache-logger.d.ts +1 -0
- package/dist/server/bare/plugins/llamacpp-completion/ops/cache-logger.js +3 -0
- package/dist/server/bare/plugins/llamacpp-completion/ops/completion-stream.d.ts +3 -1
- package/dist/server/bare/plugins/llamacpp-completion/ops/completion-stream.js +57 -11
- package/dist/server/bare/plugins/llamacpp-completion/ops/finetune.d.ts +11 -0
- package/dist/server/bare/plugins/llamacpp-completion/ops/finetune.js +112 -0
- package/dist/server/bare/plugins/llamacpp-completion/plugin.d.ts +175 -5
- package/dist/server/bare/plugins/llamacpp-completion/plugin.js +45 -35
- package/dist/server/bare/plugins/llamacpp-embedding/plugin.d.ts +11 -1
- package/dist/server/bare/plugins/llamacpp-embedding/plugin.js +9 -4
- package/dist/server/bare/plugins/nmtcpp-translation/plugin.d.ts +17 -2
- package/dist/server/bare/plugins/nmtcpp-translation/plugin.js +16 -15
- package/dist/server/bare/plugins/onnx-ocr/ops/ocr-stream.d.ts +5 -7
- package/dist/server/bare/plugins/onnx-ocr/ops/ocr-stream.js +11 -3
- package/dist/server/bare/plugins/onnx-ocr/plugin.d.ts +2 -0
- package/dist/server/bare/plugins/onnx-ocr/plugin.js +24 -19
- package/dist/server/bare/plugins/onnx-tts/ops/text-to-speech.d.ts +7 -2
- package/dist/server/bare/plugins/onnx-tts/ops/text-to-speech.js +22 -97
- package/dist/server/bare/plugins/onnx-tts/plugin.d.ts +98 -9
- package/dist/server/bare/plugins/onnx-tts/plugin.js +85 -46
- package/dist/server/bare/plugins/parakeet-transcription/plugin.d.ts +30 -60
- package/dist/server/bare/plugins/parakeet-transcription/plugin.js +49 -37
- package/dist/server/bare/plugins/sdcpp-generation/ops/diffusion.d.ts +3 -0
- package/dist/server/bare/plugins/sdcpp-generation/ops/diffusion.js +51 -0
- package/dist/server/bare/plugins/sdcpp-generation/plugin.d.ts +278 -0
- package/dist/server/bare/plugins/sdcpp-generation/plugin.js +70 -0
- package/dist/server/bare/plugins/whispercpp-transcription/plugin.d.ts +38 -2
- package/dist/server/bare/plugins/whispercpp-transcription/plugin.js +43 -22
- package/dist/server/bare/rag-hyperdb/handlers/ingest.js +2 -1
- package/dist/server/bare/rag-hyperdb/handlers/search.js +2 -1
- package/dist/server/bare/rag-hyperdb/rag-workspace-manager.js +7 -0
- package/dist/server/bare/registry/model-config-utils.js +3 -0
- package/dist/server/bare/registry/model-registry.d.ts +2 -2
- package/dist/server/bare/registry/model-registry.js +1 -1
- package/dist/server/bare/registry/registry-client.js +21 -0
- package/dist/server/bare/runtime-lifecycle.d.ts +28 -0
- package/dist/server/bare/runtime-lifecycle.js +132 -0
- package/dist/server/bare/types/addon-responses.d.ts +62 -0
- package/dist/server/bare/types/addon-responses.js +1 -0
- package/dist/server/env.js +3 -1
- package/dist/server/rpc/delegate-transport.js +1 -1
- package/dist/server/rpc/handle-request.js +50 -4
- package/dist/server/rpc/handler-registry.js +20 -1
- package/dist/server/rpc/handler-utils.d.ts +5 -3
- package/dist/server/rpc/handler-utils.js +52 -50
- package/dist/server/rpc/handlers/delete-cache.js +3 -0
- package/dist/server/rpc/handlers/diffusion-stream.d.ts +3 -0
- package/dist/server/rpc/handlers/diffusion-stream.js +4 -0
- package/dist/server/rpc/handlers/finetune.d.ts +3 -0
- package/dist/server/rpc/handlers/finetune.js +16 -0
- package/dist/server/rpc/handlers/index.d.ts +10 -0
- package/dist/server/rpc/handlers/index.js +10 -0
- package/dist/server/rpc/handlers/load-model/hyperdrive.js +24 -9
- package/dist/server/rpc/handlers/load-model/registry.d.ts +11 -0
- package/dist/server/rpc/handlers/load-model/registry.js +31 -4
- package/dist/server/rpc/handlers/plugin-dispatch.d.ts +1 -13
- package/dist/server/rpc/handlers/plugin-dispatch.js +21 -21
- package/dist/server/rpc/handlers/resume.d.ts +3 -0
- package/dist/server/rpc/handlers/resume.js +11 -0
- package/dist/server/rpc/handlers/suspend.d.ts +3 -0
- package/dist/server/rpc/handlers/suspend.js +11 -0
- package/dist/server/rpc/handlers/transcribe-stream.d.ts +1 -1
- package/dist/server/rpc/handlers/transcribe-stream.js +2 -2
- package/dist/server/rpc/handlers/transcribe.d.ts +3 -0
- package/dist/server/rpc/handlers/transcribe.js +4 -0
- package/dist/server/rpc/profiling/operation-metrics.js +107 -16
- package/dist/server/rpc/profiling/operation-wrappers.d.ts +1 -1
- package/dist/server/rpc/profiling/operation-wrappers.js +51 -19
- package/dist/server/rpc/progress-throttle.d.ts +8 -0
- package/dist/server/rpc/progress-throttle.js +47 -0
- package/dist/server/rpc/rpc-utils.d.ts +5 -0
- package/dist/server/rpc/rpc-utils.js +11 -0
- package/dist/server/utils/path-security.js +1 -1
- package/dist/server/utils/tool-integration.js +10 -0
- package/dist/server/utils/tool-parser.js +9 -5
- package/dist/server/worker-core.d.ts +2 -0
- package/dist/server/worker-core.js +26 -23
- package/dist/server/worker.js +2 -1
- package/dist/utils/encoding.d.ts +9 -0
- package/dist/utils/encoding.js +14 -0
- package/dist/utils/errors-server.d.ts +6 -0
- package/dist/utils/errors-server.js +11 -0
- package/package.json +81 -25
- package/dist/server/rpc/delegate-utils.d.ts +0 -2
- package/dist/server/rpc/delegate-utils.js +0 -5
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
* Generic wrappers for profiling handler execution.
|
|
3
3
|
* Used to wrap dispatch/invoke functions with timing capture.
|
|
4
4
|
*/
|
|
5
|
-
import { PROFILING_KEY, } from "../../../schemas/index.js";
|
|
5
|
+
import { PROFILING_KEY, OPERATION_EVENT_KEY, } from "../../../schemas/index.js";
|
|
6
6
|
import { nowMs, generateProfileId } from "../../../profiling/clock.js";
|
|
7
7
|
import { record, shouldProfile } from "../../../profiling/controller.js";
|
|
8
8
|
import { buildOperationEvent } from "./operation-metrics.js";
|
|
9
|
+
import { isTerminalChunk } from "../rpc-utils";
|
|
9
10
|
function getRequestProfilingMeta(request) {
|
|
10
11
|
if (!request || typeof request !== "object") {
|
|
11
12
|
return undefined;
|
|
@@ -33,10 +34,10 @@ function resolvePerCallProfiling(options) {
|
|
|
33
34
|
mode: meta.mode,
|
|
34
35
|
};
|
|
35
36
|
}
|
|
36
|
-
function
|
|
37
|
+
function buildAndRecordOperationEvent(params) {
|
|
37
38
|
const event = buildOperationEvent(params.options.op, params.profileId, params.startTs, params.executionMs, params.options.request, params.finalResponse, params.ttfb);
|
|
38
39
|
if (!event)
|
|
39
|
-
return;
|
|
40
|
+
return undefined;
|
|
40
41
|
if (params.errored) {
|
|
41
42
|
event.tags = { ...event.tags, error: "true" };
|
|
42
43
|
}
|
|
@@ -44,6 +45,7 @@ function recordOperationEvent(params) {
|
|
|
44
45
|
event.count = params.count;
|
|
45
46
|
}
|
|
46
47
|
record(event);
|
|
48
|
+
return event;
|
|
47
49
|
}
|
|
48
50
|
export async function profileReplyHandler(options, handler) {
|
|
49
51
|
const perCall = resolvePerCallProfiling(options);
|
|
@@ -55,18 +57,21 @@ export async function profileReplyHandler(options, handler) {
|
|
|
55
57
|
try {
|
|
56
58
|
const result = await handler();
|
|
57
59
|
const executionMs = nowMs() - startTs;
|
|
58
|
-
|
|
60
|
+
const event = buildAndRecordOperationEvent({
|
|
59
61
|
options,
|
|
60
62
|
profileId,
|
|
61
63
|
startTs,
|
|
62
64
|
executionMs,
|
|
63
65
|
finalResponse: result,
|
|
64
66
|
});
|
|
67
|
+
if (event) {
|
|
68
|
+
result[OPERATION_EVENT_KEY] = event;
|
|
69
|
+
}
|
|
65
70
|
return result;
|
|
66
71
|
}
|
|
67
72
|
catch (error) {
|
|
68
73
|
const executionMs = nowMs() - startTs;
|
|
69
|
-
|
|
74
|
+
buildAndRecordOperationEvent({
|
|
70
75
|
options,
|
|
71
76
|
profileId,
|
|
72
77
|
startTs,
|
|
@@ -79,37 +84,61 @@ export async function profileReplyHandler(options, handler) {
|
|
|
79
84
|
export async function* profileStreamHandler(options, handler) {
|
|
80
85
|
const perCall = resolvePerCallProfiling(options);
|
|
81
86
|
if (!shouldProfile(options.op, perCall)) {
|
|
82
|
-
yield* handler();
|
|
83
|
-
return;
|
|
87
|
+
return yield* handler();
|
|
84
88
|
}
|
|
85
89
|
const profileId = generateProfileId();
|
|
86
90
|
const startTs = nowMs();
|
|
87
91
|
let ttfb;
|
|
88
92
|
let lastChunk;
|
|
89
93
|
let chunkCount = 0;
|
|
94
|
+
let eventAttached = false;
|
|
95
|
+
const iterator = handler();
|
|
90
96
|
try {
|
|
91
|
-
|
|
97
|
+
while (true) {
|
|
98
|
+
const result = await iterator.next();
|
|
99
|
+
if (result.done) {
|
|
100
|
+
if (!eventAttached) {
|
|
101
|
+
const executionMs = nowMs() - startTs;
|
|
102
|
+
buildAndRecordOperationEvent({
|
|
103
|
+
options,
|
|
104
|
+
profileId,
|
|
105
|
+
startTs,
|
|
106
|
+
executionMs,
|
|
107
|
+
finalResponse: lastChunk,
|
|
108
|
+
ttfb,
|
|
109
|
+
count: chunkCount,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
return result.value;
|
|
113
|
+
}
|
|
114
|
+
const chunk = result.value;
|
|
92
115
|
if (ttfb === undefined) {
|
|
93
116
|
ttfb = nowMs() - startTs;
|
|
94
117
|
}
|
|
95
118
|
chunkCount++;
|
|
96
119
|
lastChunk = chunk;
|
|
120
|
+
if (!eventAttached && isTerminalChunk(chunk)) {
|
|
121
|
+
const executionMs = nowMs() - startTs;
|
|
122
|
+
const event = buildAndRecordOperationEvent({
|
|
123
|
+
options,
|
|
124
|
+
profileId,
|
|
125
|
+
startTs,
|
|
126
|
+
executionMs,
|
|
127
|
+
finalResponse: chunk,
|
|
128
|
+
ttfb,
|
|
129
|
+
count: chunkCount,
|
|
130
|
+
});
|
|
131
|
+
if (event) {
|
|
132
|
+
chunk[OPERATION_EVENT_KEY] = event;
|
|
133
|
+
}
|
|
134
|
+
eventAttached = true;
|
|
135
|
+
}
|
|
97
136
|
yield chunk;
|
|
98
137
|
}
|
|
99
|
-
const executionMs = nowMs() - startTs;
|
|
100
|
-
recordOperationEvent({
|
|
101
|
-
options,
|
|
102
|
-
profileId,
|
|
103
|
-
startTs,
|
|
104
|
-
executionMs,
|
|
105
|
-
finalResponse: lastChunk,
|
|
106
|
-
ttfb,
|
|
107
|
-
count: chunkCount,
|
|
108
|
-
});
|
|
109
138
|
}
|
|
110
139
|
catch (error) {
|
|
111
140
|
const executionMs = nowMs() - startTs;
|
|
112
|
-
|
|
141
|
+
buildAndRecordOperationEvent({
|
|
113
142
|
options,
|
|
114
143
|
profileId,
|
|
115
144
|
startTs,
|
|
@@ -121,4 +150,7 @@ export async function* profileStreamHandler(options, handler) {
|
|
|
121
150
|
});
|
|
122
151
|
throw error;
|
|
123
152
|
}
|
|
153
|
+
finally {
|
|
154
|
+
await iterator.return?.(undefined);
|
|
155
|
+
}
|
|
124
156
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const PROGRESS_THROTTLE_MS = 150;
|
|
2
|
+
export declare const PROGRESS_MAX_PENDING = 100;
|
|
3
|
+
export type ProgressThrottle<T> = {
|
|
4
|
+
push: (update: T) => void;
|
|
5
|
+
flush: () => void;
|
|
6
|
+
};
|
|
7
|
+
export declare function createProgressThrottle<T>(writeBatch: (updates: T[]) => void, clock?: () => number, throttleMs?: number, maxPending?: number): ProgressThrottle<T>;
|
|
8
|
+
//# sourceMappingURL=progress-throttle.d.ts.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export const PROGRESS_THROTTLE_MS = 150;
|
|
2
|
+
export const PROGRESS_MAX_PENDING = 100;
|
|
3
|
+
export function createProgressThrottle(writeBatch, clock = Date.now, throttleMs = PROGRESS_THROTTLE_MS, maxPending = PROGRESS_MAX_PENDING) {
|
|
4
|
+
let lastWrite = 0;
|
|
5
|
+
let pending = [];
|
|
6
|
+
let flushTimer = null;
|
|
7
|
+
function flushPending() {
|
|
8
|
+
if (pending.length === 0)
|
|
9
|
+
return;
|
|
10
|
+
lastWrite = clock();
|
|
11
|
+
const batch = pending;
|
|
12
|
+
pending = [];
|
|
13
|
+
writeBatch(batch);
|
|
14
|
+
}
|
|
15
|
+
function push(update) {
|
|
16
|
+
const now = clock();
|
|
17
|
+
if (now - lastWrite >= throttleMs) {
|
|
18
|
+
lastWrite = now;
|
|
19
|
+
writeBatch([update]);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
pending.push(update);
|
|
23
|
+
if (pending.length >= maxPending) {
|
|
24
|
+
if (flushTimer) {
|
|
25
|
+
clearTimeout(flushTimer);
|
|
26
|
+
flushTimer = null;
|
|
27
|
+
}
|
|
28
|
+
flushPending();
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (!flushTimer) {
|
|
32
|
+
flushTimer = setTimeout(() => {
|
|
33
|
+
flushTimer = null;
|
|
34
|
+
flushPending();
|
|
35
|
+
}, throttleMs - (now - lastWrite));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function flush() {
|
|
40
|
+
if (flushTimer) {
|
|
41
|
+
clearTimeout(flushTimer);
|
|
42
|
+
flushTimer = null;
|
|
43
|
+
}
|
|
44
|
+
flushPending();
|
|
45
|
+
}
|
|
46
|
+
return { push, flush };
|
|
47
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
let commandCounter = 0;
|
|
2
|
+
export function getNextCommandId() {
|
|
3
|
+
commandCounter = (commandCounter + 1) % Number.MAX_SAFE_INTEGER;
|
|
4
|
+
return commandCounter;
|
|
5
|
+
}
|
|
6
|
+
export function isTerminalChunk(value) {
|
|
7
|
+
return (typeof value === "object" &&
|
|
8
|
+
value !== null &&
|
|
9
|
+
"done" in value &&
|
|
10
|
+
value.done === true);
|
|
11
|
+
}
|
|
@@ -8,7 +8,7 @@ export { sanitizePathComponent } from "../../utils/path-sanitize.js";
|
|
|
8
8
|
* Both paths are resolved to absolute before comparison.
|
|
9
9
|
*/
|
|
10
10
|
export function isPathWithinBase(basePath, targetPath) {
|
|
11
|
-
return checkPathWithinBase(basePath, targetPath, path.resolve, path.sep || "/");
|
|
11
|
+
return checkPathWithinBase(basePath, targetPath, (...args) => path.resolve(...args), path.sep || "/");
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
14
|
* Sanitize components, join them to a base path, and verify the result
|
|
@@ -14,8 +14,18 @@ export function setupToolGrammar(modelConfig, tools) {
|
|
|
14
14
|
const grammar = convertToolsToGrammar(tools);
|
|
15
15
|
modelConfig["grammar"] = grammar;
|
|
16
16
|
}
|
|
17
|
+
function isInsideThinkBlock(text) {
|
|
18
|
+
const lastOpen = text.lastIndexOf("<think>");
|
|
19
|
+
if (lastOpen === -1)
|
|
20
|
+
return false;
|
|
21
|
+
const lastClose = text.lastIndexOf("</think>");
|
|
22
|
+
return lastClose < lastOpen;
|
|
23
|
+
}
|
|
17
24
|
export function checkForToolEvents(accumulatedText, currentToken, tools, emittedToolCallPositions) {
|
|
18
25
|
const events = [];
|
|
26
|
+
if (isInsideThinkBlock(accumulatedText)) {
|
|
27
|
+
return events;
|
|
28
|
+
}
|
|
19
29
|
if (currentToken.includes("</tool_call>") || currentToken.includes("}")) {
|
|
20
30
|
const { toolCalls, errors } = parseToolCalls(accumulatedText, tools);
|
|
21
31
|
for (const call of toolCalls) {
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
function stripThinkingBlocks(text) {
|
|
2
|
+
return text.replace(/<think>[\s\S]*?<\/think>/gi, "");
|
|
3
|
+
}
|
|
1
4
|
let toolCallSequence = 0;
|
|
2
5
|
function generateStableToolCallId(name, args) {
|
|
3
6
|
const content = `${name}:${JSON.stringify(args)}`;
|
|
@@ -196,22 +199,23 @@ export function parseToolCalls(text, tools) {
|
|
|
196
199
|
if (!tools || tools.length === 0) {
|
|
197
200
|
return { toolCalls: [], errors: [] };
|
|
198
201
|
}
|
|
199
|
-
|
|
202
|
+
const cleaned = stripThinkingBlocks(text);
|
|
203
|
+
let result = parseGemmaFormat(cleaned, tools);
|
|
200
204
|
if (result.toolCalls.length > 0) {
|
|
201
205
|
return result;
|
|
202
206
|
}
|
|
203
|
-
result = parseQwenFormat(
|
|
207
|
+
result = parseQwenFormat(cleaned, tools);
|
|
204
208
|
if (result.toolCalls.length > 0) {
|
|
205
209
|
return result;
|
|
206
210
|
}
|
|
207
|
-
result = parseLlamacppFormat(
|
|
211
|
+
result = parseLlamacppFormat(cleaned, tools);
|
|
208
212
|
if (result.toolCalls.length > 0) {
|
|
209
213
|
return result;
|
|
210
214
|
}
|
|
211
|
-
if (
|
|
215
|
+
if (cleaned.includes("<tool_call>")) {
|
|
212
216
|
return { toolCalls: [], errors: [] };
|
|
213
217
|
}
|
|
214
|
-
result = parseGenericFormat(
|
|
218
|
+
result = parseGenericFormat(cleaned, tools);
|
|
215
219
|
return result;
|
|
216
220
|
}
|
|
217
221
|
export function convertToolsToGrammar(tools) {
|
|
@@ -3,4 +3,6 @@ export declare function initializeWorkerCore(): {
|
|
|
3
3
|
};
|
|
4
4
|
export declare function ensureRPCSetup(): void;
|
|
5
5
|
export declare function isCoreInitialized(): boolean;
|
|
6
|
+
export type BareDirectShutdownReason = "signal" | "rpc-close";
|
|
7
|
+
export declare function shutdownBareDirectWorker(reason: BareDirectShutdownReason): Promise<void>;
|
|
6
8
|
//# sourceMappingURL=worker-core.d.ts.map
|
|
@@ -61,28 +61,31 @@ function clearRegistries() {
|
|
|
61
61
|
clearAllAddonLoggers();
|
|
62
62
|
clearPlugins();
|
|
63
63
|
}
|
|
64
|
+
export async function shutdownBareDirectWorker(reason) {
|
|
65
|
+
if (isShuttingDown)
|
|
66
|
+
return;
|
|
67
|
+
isShuttingDown = true;
|
|
68
|
+
const message = reason === "signal"
|
|
69
|
+
? "🐻 Bare worker shutdown signal received, cleaning up..."
|
|
70
|
+
: "🧹 Bare direct mode RPC closed, cleaning up...";
|
|
71
|
+
logger.info(message);
|
|
72
|
+
try {
|
|
73
|
+
clearRegistries();
|
|
74
|
+
await Promise.allSettled([
|
|
75
|
+
destroySwarm(),
|
|
76
|
+
closeAllRagInstances(),
|
|
77
|
+
cleanupDownloads(),
|
|
78
|
+
unloadAllModels(),
|
|
79
|
+
closeRegistryClient(),
|
|
80
|
+
]);
|
|
81
|
+
logger.info("✅ Cleanup completed successfully");
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
logger.error("❌ Error during shutdown cleanup:", error);
|
|
85
|
+
}
|
|
86
|
+
process.exit(0);
|
|
87
|
+
}
|
|
64
88
|
function setupShutdownHandlers() {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return;
|
|
68
|
-
isShuttingDown = true;
|
|
69
|
-
logger.info("🐻 Bare worker shutdown signal received, cleaning up...");
|
|
70
|
-
try {
|
|
71
|
-
clearRegistries();
|
|
72
|
-
await Promise.allSettled([
|
|
73
|
-
destroySwarm(),
|
|
74
|
-
closeAllRagInstances(),
|
|
75
|
-
cleanupDownloads(),
|
|
76
|
-
unloadAllModels(),
|
|
77
|
-
closeRegistryClient(),
|
|
78
|
-
]);
|
|
79
|
-
logger.info("✅ Cleanup completed successfully");
|
|
80
|
-
}
|
|
81
|
-
catch (error) {
|
|
82
|
-
logger.error("❌ Error during shutdown cleanup:", error);
|
|
83
|
-
}
|
|
84
|
-
process.exit(0);
|
|
85
|
-
};
|
|
86
|
-
process.once("SIGTERM", () => void shutdownHandler());
|
|
87
|
-
process.once("SIGINT", () => void shutdownHandler());
|
|
89
|
+
process.once("SIGTERM", () => void shutdownBareDirectWorker("signal"));
|
|
90
|
+
process.once("SIGINT", () => void shutdownBareDirectWorker("signal"));
|
|
88
91
|
}
|
package/dist/server/worker.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { initializeWorkerCore, ensureRPCSetup } from "./worker-core.js";
|
|
5
5
|
import { registerPlugin } from "./plugins/index.js";
|
|
6
6
|
import { getServerLogger } from "../logging/index.js";
|
|
7
|
-
import { llmPlugin, embeddingsPlugin, whisperPlugin, parakeetPlugin, nmtPlugin, ttsPlugin, ocrPlugin, } from "./bare/plugins/index.js";
|
|
7
|
+
import { llmPlugin, embeddingsPlugin, whisperPlugin, parakeetPlugin, nmtPlugin, ttsPlugin, ocrPlugin, diffusionPlugin, } from "./bare/plugins/index.js";
|
|
8
8
|
const { hasRPCConfig } = initializeWorkerCore();
|
|
9
9
|
const logger = getServerLogger();
|
|
10
10
|
logger.info("🐻 Hello from Bare");
|
|
@@ -16,6 +16,7 @@ registerPlugin(parakeetPlugin);
|
|
|
16
16
|
registerPlugin(nmtPlugin);
|
|
17
17
|
registerPlugin(ttsPlugin);
|
|
18
18
|
registerPlugin(ocrPlugin);
|
|
19
|
+
registerPlugin(diffusionPlugin);
|
|
19
20
|
logger.info(hasRPCConfig
|
|
20
21
|
? "Parsed RPC configuration from arguments"
|
|
21
22
|
: "Using default configuration (direct mode)");
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decodes a base64 string to a Uint8Array.
|
|
3
|
+
*
|
|
4
|
+
* Uses atob which is available across all runtimes (Node, Bare, React Native).
|
|
5
|
+
* Buffer is not globally available in React Native (Hermes engine), so this
|
|
6
|
+
* provides a cross-platform alternative to Buffer.from(str, "base64").
|
|
7
|
+
*/
|
|
8
|
+
export declare function decodeBase64(base64: string): Uint8Array;
|
|
9
|
+
//# sourceMappingURL=encoding.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decodes a base64 string to a Uint8Array.
|
|
3
|
+
*
|
|
4
|
+
* Uses atob which is available across all runtimes (Node, Bare, React Native).
|
|
5
|
+
* Buffer is not globally available in React Native (Hermes engine), so this
|
|
6
|
+
* provides a cross-platform alternative to Buffer.from(str, "base64").
|
|
7
|
+
*/
|
|
8
|
+
export function decodeBase64(base64) {
|
|
9
|
+
const binary = atob(base64);
|
|
10
|
+
const bytes = new Uint8Array(binary.length);
|
|
11
|
+
for (let i = 0; i < binary.length; i++)
|
|
12
|
+
bytes[i] = binary.charCodeAt(i);
|
|
13
|
+
return bytes;
|
|
14
|
+
}
|
|
@@ -227,6 +227,12 @@ export declare class PluginLoggingInvalidError extends QvacErrorBase {
|
|
|
227
227
|
export declare class PluginDefinitionInvalidError extends QvacErrorBase {
|
|
228
228
|
constructor(modelType: string, details: string, cause?: unknown);
|
|
229
229
|
}
|
|
230
|
+
export declare class LifecycleSuspendFailedError extends QvacErrorBase {
|
|
231
|
+
constructor(details?: string, cause?: unknown);
|
|
232
|
+
}
|
|
233
|
+
export declare class LifecycleResumeFailedError extends QvacErrorBase {
|
|
234
|
+
constructor(details?: string, cause?: unknown);
|
|
235
|
+
}
|
|
230
236
|
export declare class PathTraversalError extends QvacErrorBase {
|
|
231
237
|
constructor(component: string, basePath: string, cause?: unknown);
|
|
232
238
|
}
|
|
@@ -396,6 +396,17 @@ export class PluginDefinitionInvalidError extends QvacErrorBase {
|
|
|
396
396
|
super(createErrorOptions(SDK_SERVER_ERROR_CODES.PLUGIN_DEFINITION_INVALID, [modelType, details], cause));
|
|
397
397
|
}
|
|
398
398
|
}
|
|
399
|
+
// ============== Lifecycle Errors ==============
|
|
400
|
+
export class LifecycleSuspendFailedError extends QvacErrorBase {
|
|
401
|
+
constructor(details, cause) {
|
|
402
|
+
super(createErrorOptions(SDK_SERVER_ERROR_CODES.LIFECYCLE_SUSPEND_FAILED, details ? [details] : undefined, cause));
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
export class LifecycleResumeFailedError extends QvacErrorBase {
|
|
406
|
+
constructor(details, cause) {
|
|
407
|
+
super(createErrorOptions(SDK_SERVER_ERROR_CODES.LIFECYCLE_RESUME_FAILED, details ? [details] : undefined, cause));
|
|
408
|
+
}
|
|
409
|
+
}
|
|
399
410
|
// ============== Security Errors ==============
|
|
400
411
|
export class PathTraversalError extends QvacErrorBase {
|
|
401
412
|
constructor(component, basePath, cause) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qvac/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -9,6 +9,51 @@
|
|
|
9
9
|
},
|
|
10
10
|
"bugs": "https://github.com/tetherto/qvac/issues",
|
|
11
11
|
"homepage": "https://github.com/tetherto/qvac/tree/main/packages/sdk#readme",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"ai",
|
|
14
|
+
"bare",
|
|
15
|
+
"cross-platform",
|
|
16
|
+
"deep-learning",
|
|
17
|
+
"diffusion",
|
|
18
|
+
"edge-ai",
|
|
19
|
+
"embeddings",
|
|
20
|
+
"expo",
|
|
21
|
+
"gguf",
|
|
22
|
+
"gpu",
|
|
23
|
+
"holepunch",
|
|
24
|
+
"hyperswarm",
|
|
25
|
+
"image-generation",
|
|
26
|
+
"inference",
|
|
27
|
+
"large-language-model",
|
|
28
|
+
"llama-cpp",
|
|
29
|
+
"llm",
|
|
30
|
+
"local",
|
|
31
|
+
"local-ai",
|
|
32
|
+
"machine-learning",
|
|
33
|
+
"ml",
|
|
34
|
+
"model-registry",
|
|
35
|
+
"node",
|
|
36
|
+
"ocr",
|
|
37
|
+
"offline",
|
|
38
|
+
"on-device",
|
|
39
|
+
"p2p",
|
|
40
|
+
"peer-to-peer",
|
|
41
|
+
"private-ai",
|
|
42
|
+
"qvac",
|
|
43
|
+
"rag",
|
|
44
|
+
"react-native",
|
|
45
|
+
"sdk",
|
|
46
|
+
"self-hosted",
|
|
47
|
+
"speech-to-text",
|
|
48
|
+
"stt",
|
|
49
|
+
"tether",
|
|
50
|
+
"text-to-speech",
|
|
51
|
+
"transcription",
|
|
52
|
+
"translation",
|
|
53
|
+
"tts",
|
|
54
|
+
"typescript",
|
|
55
|
+
"whisper"
|
|
56
|
+
],
|
|
12
57
|
"type": "module",
|
|
13
58
|
"main": "./dist/index.js",
|
|
14
59
|
"types": "./dist/index.d.ts",
|
|
@@ -51,6 +96,10 @@
|
|
|
51
96
|
"types": "./dist/server/bare/plugins/onnx-ocr/plugin.d.ts",
|
|
52
97
|
"import": "./dist/server/bare/plugins/onnx-ocr/plugin.js"
|
|
53
98
|
},
|
|
99
|
+
"./sdcpp-generation/plugin": {
|
|
100
|
+
"types": "./dist/server/bare/plugins/sdcpp-generation/plugin.d.ts",
|
|
101
|
+
"import": "./dist/server/bare/plugins/sdcpp-generation/plugin.js"
|
|
102
|
+
},
|
|
54
103
|
"./plugin-utils": {
|
|
55
104
|
"types": "./dist/schemas/plugin.d.ts",
|
|
56
105
|
"import": "./dist/schemas/plugin.js"
|
|
@@ -69,6 +118,12 @@
|
|
|
69
118
|
"./pear-pre": "./dist/pear/pre.js"
|
|
70
119
|
},
|
|
71
120
|
"imports": {
|
|
121
|
+
"#polyfill-bare-globals": {
|
|
122
|
+
"bun": "./dist/polyfills/bare-globals.noop.js",
|
|
123
|
+
"node": "./dist/polyfills/bare-globals.noop.js",
|
|
124
|
+
"bare": "./dist/polyfills/bare-globals.js",
|
|
125
|
+
"default": "./dist/polyfills/bare-globals.noop.js"
|
|
126
|
+
},
|
|
72
127
|
"#rpc": {
|
|
73
128
|
"react-native": "./dist/client/rpc/expo-rpc-client.js",
|
|
74
129
|
"bare": "./dist/client/rpc/bare-client.js",
|
|
@@ -117,34 +172,35 @@
|
|
|
117
172
|
"changelog:generate": "node ../../scripts/sdk/generate-changelog-sdk-pod.cjs --package=sdk && prettier --write changelog"
|
|
118
173
|
},
|
|
119
174
|
"dependencies": {
|
|
120
|
-
"@qvac/decoder-audio": "^0.3.
|
|
121
|
-
"@qvac/
|
|
122
|
-
"@qvac/
|
|
175
|
+
"@qvac/decoder-audio": "^0.3.7",
|
|
176
|
+
"@qvac/diffusion-cpp": "^0.1.3",
|
|
177
|
+
"@qvac/dl-filesystem": "^0.2.1",
|
|
178
|
+
"@qvac/embed-llamacpp": "^0.13.4",
|
|
123
179
|
"@qvac/error": "^0.1.1",
|
|
124
|
-
"@qvac/langdetect-text": "^0.1.
|
|
125
|
-
"@qvac/llm-llamacpp": "^0.
|
|
180
|
+
"@qvac/langdetect-text": "^0.1.2",
|
|
181
|
+
"@qvac/llm-llamacpp": "^0.14.4",
|
|
126
182
|
"@qvac/logging": "^0.1.0",
|
|
127
|
-
"@qvac/ocr-onnx": "^0.2
|
|
128
|
-
"@qvac/rag": "^0.4.
|
|
129
|
-
"@qvac/registry-client": "^0.
|
|
130
|
-
"@qvac/transcription-parakeet": "^0.
|
|
131
|
-
"@qvac/transcription-whispercpp": "^0.
|
|
132
|
-
"@qvac/translation-nmtcpp": "^0.6.
|
|
133
|
-
"@qvac/tts-onnx": "^0.
|
|
183
|
+
"@qvac/ocr-onnx": "^0.4.2",
|
|
184
|
+
"@qvac/rag": "^0.4.4",
|
|
185
|
+
"@qvac/registry-client": "^0.4.0",
|
|
186
|
+
"@qvac/transcription-parakeet": "^0.3.1",
|
|
187
|
+
"@qvac/transcription-whispercpp": "^0.6.1",
|
|
188
|
+
"@qvac/translation-nmtcpp": "^0.6.10",
|
|
189
|
+
"@qvac/tts-onnx": "^0.8.2",
|
|
134
190
|
"fast-safe-stringify": "2.1.1",
|
|
135
191
|
"which-runtime": "^1.3.2",
|
|
136
192
|
"zod": "^4.0.17"
|
|
137
193
|
},
|
|
138
194
|
"devDependencies": {
|
|
139
195
|
"@eslint/js": "^9.33.0",
|
|
140
|
-
"@expo/config-plugins": "^54.0.
|
|
196
|
+
"@expo/config-plugins": "^54.0.4",
|
|
141
197
|
"@lancedb/lancedb": "^0.21.3",
|
|
142
198
|
"@modelcontextprotocol/sdk": "^1.12.1",
|
|
143
|
-
"@qvac/cli": "^0.2.
|
|
199
|
+
"@qvac/cli": "^0.2.3",
|
|
144
200
|
"@sqliteai/sqlite-wasm": "3.50.4-sync.0.8.30-vector.0.9.23",
|
|
145
201
|
"@types/node": "^24.2.1",
|
|
146
202
|
"@types/tar-stream": "^3.1.4",
|
|
147
|
-
"bare-pack": "^2.0.
|
|
203
|
+
"bare-pack": "^2.0.1",
|
|
148
204
|
"bare-readline": "^1.2.0",
|
|
149
205
|
"brittle": "^3.19.1",
|
|
150
206
|
"chromadb": "^3.0.14",
|
|
@@ -152,9 +208,9 @@
|
|
|
152
208
|
"eslint-import-resolver-typescript": "^4.4.4",
|
|
153
209
|
"eslint-plugin-import": "^2.30.0",
|
|
154
210
|
"eslint-plugin-react": "^7.37.5",
|
|
155
|
-
"expo": "^54.0.
|
|
156
|
-
"expo-device": "^8.0.
|
|
157
|
-
"expo-file-system": "^19.0.
|
|
211
|
+
"expo": "^54.0.33",
|
|
212
|
+
"expo-device": "^8.0.10",
|
|
213
|
+
"expo-file-system": "^19.0.21",
|
|
158
214
|
"globals": "^16.3.0",
|
|
159
215
|
"husky": "^9.1.7",
|
|
160
216
|
"hyperdb": "^4.16.1",
|
|
@@ -166,20 +222,20 @@
|
|
|
166
222
|
"remark-frontmatter": "^5.0.0",
|
|
167
223
|
"remark-mdx": "^3.1.1",
|
|
168
224
|
"tsx": "^4.21.0",
|
|
169
|
-
"typescript": "^5.9.
|
|
225
|
+
"typescript": "^5.9.3",
|
|
170
226
|
"typescript-eslint": "^8.39.0"
|
|
171
227
|
},
|
|
172
228
|
"peerDependencies": {
|
|
173
229
|
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
174
|
-
"@qvac/cli": "^0.2.
|
|
230
|
+
"@qvac/cli": "^0.2.3",
|
|
175
231
|
"bare-abort-controller": "^1.0.0",
|
|
176
232
|
"bare-buffer": "^3.4.2",
|
|
177
|
-
"bare-crypto": "^1.
|
|
233
|
+
"bare-crypto": "^1.13.4",
|
|
178
234
|
"bare-dns": "^2.1.4",
|
|
179
235
|
"bare-fetch": "^2.5.1",
|
|
180
236
|
"bare-fs": "^4.5.2",
|
|
181
237
|
"bare-http1": "^4.1.6",
|
|
182
|
-
"bare-https": "^2.1.
|
|
238
|
+
"bare-https": "^2.1.3",
|
|
183
239
|
"bare-link": "^2.1.10",
|
|
184
240
|
"bare-net": "^2.2.0",
|
|
185
241
|
"bare-os": "^3.6.2",
|
|
@@ -188,7 +244,7 @@
|
|
|
188
244
|
"bare-rpc": "^1.0.0",
|
|
189
245
|
"bare-runtime": "^1.24.2",
|
|
190
246
|
"bare-stream": "^2.7.0",
|
|
191
|
-
"bare-subprocess": "^5.2.
|
|
247
|
+
"bare-subprocess": "^5.2.3",
|
|
192
248
|
"bare-zlib": "^1.3.1",
|
|
193
249
|
"compact-encoding": "^2.19.0",
|
|
194
250
|
"corestore": "^7.4.5",
|
|
@@ -202,7 +258,7 @@
|
|
|
202
258
|
"llm-splitter": "~0.2.0",
|
|
203
259
|
"pear-pipe": "^1.0.6",
|
|
204
260
|
"react-native-bare-kit": "^0.11.5",
|
|
205
|
-
"tar-stream": "^3.1.
|
|
261
|
+
"tar-stream": "^3.1.8"
|
|
206
262
|
},
|
|
207
263
|
"peerDependenciesMeta": {
|
|
208
264
|
"@qvac/cli": {
|