@qvac/sdk 0.8.3 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. package/NOTICE +267 -63
  2. package/README.md +1 -1
  3. package/dist/client/api/diffusion.d.ts +32 -0
  4. package/dist/client/api/diffusion.js +103 -0
  5. package/dist/client/api/embed.d.ts +9 -3
  6. package/dist/client/api/embed.js +4 -1
  7. package/dist/client/api/finetune.d.ts +69 -0
  8. package/dist/client/api/finetune.js +139 -0
  9. package/dist/client/api/get-model-info.d.ts +1 -1
  10. package/dist/client/api/index.d.ts +4 -0
  11. package/dist/client/api/index.js +4 -0
  12. package/dist/client/api/rag.d.ts +1 -1
  13. package/dist/client/api/rag.js +1 -1
  14. package/dist/client/api/resume.d.ts +14 -0
  15. package/dist/client/api/resume.js +20 -0
  16. package/dist/client/api/suspend.d.ts +13 -0
  17. package/dist/client/api/suspend.js +19 -0
  18. package/dist/client/api/transcribe.d.ts +25 -17
  19. package/dist/client/api/transcribe.js +115 -35
  20. package/dist/client/rpc/bare-client.d.ts +5 -1
  21. package/dist/client/rpc/bare-client.js +70 -57
  22. package/dist/client/rpc/expo-rpc-client.d.ts +4 -0
  23. package/dist/client/rpc/expo-rpc-client.js +8 -0
  24. package/dist/client/rpc/node-rpc-client.d.ts +4 -0
  25. package/dist/client/rpc/node-rpc-client.js +8 -0
  26. package/dist/client/rpc/rpc-client.d.ts +13 -0
  27. package/dist/client/rpc/rpc-client.js +131 -1
  28. package/dist/examples/delegated-inference/composite.d.ts +2 -0
  29. package/dist/examples/delegated-inference/composite.js +99 -0
  30. package/dist/examples/diffusion-flux2-klein.d.ts +2 -0
  31. package/dist/examples/diffusion-flux2-klein.js +46 -0
  32. package/dist/examples/diffusion-simple.d.ts +2 -0
  33. package/dist/examples/diffusion-simple.js +17 -0
  34. package/dist/examples/diffusion-txt2img.d.ts +2 -0
  35. package/dist/examples/diffusion-txt2img.js +40 -0
  36. package/dist/examples/embed-p2p.js +2 -2
  37. package/dist/examples/finetune/llamacpp-finetune.d.ts +2 -0
  38. package/dist/examples/finetune/llamacpp-finetune.js +78 -0
  39. package/dist/examples/logging-streaming.js +1 -1
  40. package/dist/examples/mcp-websearch.js +2 -0
  41. package/dist/examples/ocr-fasttext.js +11 -0
  42. package/dist/examples/profiling/per-call.js +3 -3
  43. package/dist/examples/rag/rag-chromadb.js +2 -2
  44. package/dist/examples/rag/rag-hyperdb/pipeline.js +1 -1
  45. package/dist/examples/rag/rag-lancedb.js +2 -2
  46. package/dist/examples/rag/rag-sqlite.js +2 -2
  47. package/dist/examples/suspend-resume.d.ts +2 -0
  48. package/dist/examples/suspend-resume.js +52 -0
  49. package/dist/examples/transcription/parakeet-ctc-filesystem.js +3 -5
  50. package/dist/examples/transcription/parakeet-microphone-record.js +42 -33
  51. package/dist/examples/transcription/parakeet-sortformer.js +13 -3
  52. package/dist/examples/transcription/parakeet-tdt-filesystem.js +5 -7
  53. package/dist/examples/transcription/whispercpp-filesystem-streaming.d.ts +2 -0
  54. package/dist/examples/transcription/whispercpp-filesystem-streaming.js +99 -0
  55. package/dist/examples/transcription/whispercpp-microphone-record.js +78 -299
  56. package/dist/examples/transcription/whispercpp-prompt.js +11 -0
  57. package/dist/examples/translation/translation-llm.js +2 -2
  58. package/dist/examples/tts/supertonic-multilingual.d.ts +2 -0
  59. package/dist/examples/tts/supertonic-multilingual.js +56 -0
  60. package/dist/examples/tts/supertonic.js +12 -7
  61. package/dist/index.d.ts +3 -2
  62. package/dist/index.js +3 -2
  63. package/dist/logging/utils.js +1 -1
  64. package/dist/models/registry/models.d.ts +15176 -4264
  65. package/dist/models/registry/models.js +18657 -7404
  66. package/dist/models/update-models/codegen.js +2 -2
  67. package/dist/models/update-models/naming.js +26 -0
  68. package/dist/pear/pre.js +2 -0
  69. package/dist/polyfills/bare-globals.d.ts +2 -0
  70. package/dist/polyfills/bare-globals.js +4 -0
  71. package/dist/polyfills/bare-globals.noop.d.ts +2 -0
  72. package/dist/polyfills/bare-globals.noop.js +1 -0
  73. package/dist/profiling/exporters.js +16 -11
  74. package/dist/profiling/model-execution.d.ts +16 -0
  75. package/dist/profiling/model-execution.js +33 -0
  76. package/dist/schemas/common.d.ts +967 -198
  77. package/dist/schemas/common.js +16 -1
  78. package/dist/schemas/completion-stream.d.ts +14 -6
  79. package/dist/schemas/completion-stream.js +4 -3
  80. package/dist/schemas/download-asset.d.ts +7 -3
  81. package/dist/schemas/embed.d.ts +19 -0
  82. package/dist/schemas/embed.js +7 -0
  83. package/dist/schemas/engine-addon-map.js +4 -1
  84. package/dist/schemas/finetune.d.ts +620 -0
  85. package/dist/schemas/finetune.js +161 -0
  86. package/dist/schemas/get-model-info.d.ts +2 -0
  87. package/dist/schemas/get-model-info.js +1 -0
  88. package/dist/schemas/index.d.ts +5 -1
  89. package/dist/schemas/index.js +5 -1
  90. package/dist/schemas/llamacpp-config.d.ts +26 -6
  91. package/dist/schemas/llamacpp-config.js +12 -0
  92. package/dist/schemas/load-model.d.ts +4005 -1400
  93. package/dist/schemas/load-model.js +34 -1
  94. package/dist/schemas/model-src-utils.d.ts +10 -2
  95. package/dist/schemas/model-types.d.ts +19 -1
  96. package/dist/schemas/model-types.js +11 -0
  97. package/dist/schemas/ocr.d.ts +2 -0
  98. package/dist/schemas/plugin.d.ts +24 -3
  99. package/dist/schemas/plugin.js +14 -0
  100. package/dist/schemas/profiling.d.ts +4 -0
  101. package/dist/schemas/profiling.js +4 -0
  102. package/dist/schemas/registry.d.ts +18 -0
  103. package/dist/schemas/registry.js +2 -0
  104. package/dist/schemas/reload-config.d.ts +9 -1
  105. package/dist/schemas/resume.d.ts +10 -0
  106. package/dist/schemas/resume.js +7 -0
  107. package/dist/schemas/sdcpp-config.d.ts +327 -0
  108. package/dist/schemas/sdcpp-config.js +102 -0
  109. package/dist/schemas/sdk-config.d.ts +1225 -235
  110. package/dist/schemas/sdk-config.js +4 -0
  111. package/dist/schemas/sdk-errors-server.d.ts +2 -0
  112. package/dist/schemas/sdk-errors-server.js +12 -0
  113. package/dist/schemas/suspend.d.ts +10 -0
  114. package/dist/schemas/suspend.js +7 -0
  115. package/dist/schemas/text-to-speech.d.ts +187 -10
  116. package/dist/schemas/text-to-speech.js +12 -4
  117. package/dist/schemas/transcription-config.d.ts +16 -56
  118. package/dist/schemas/transcription-config.js +0 -2
  119. package/dist/schemas/transcription.d.ts +66 -6
  120. package/dist/schemas/transcription.js +29 -7
  121. package/dist/schemas/translate.d.ts +14 -4
  122. package/dist/schemas/translate.js +10 -2
  123. package/dist/schemas/translation-config.d.ts +30 -10
  124. package/dist/server/bare/delegate-rpc-client.js +3 -3
  125. package/dist/server/bare/hyperswarm.js +15 -3
  126. package/dist/server/bare/ops/embed.d.ts +8 -4
  127. package/dist/server/bare/ops/embed.js +15 -4
  128. package/dist/server/bare/ops/transcribe.d.ts +6 -2
  129. package/dist/server/bare/ops/transcribe.js +53 -1
  130. package/dist/server/bare/ops/translate.d.ts +4 -1
  131. package/dist/server/bare/ops/translate.js +28 -65
  132. package/dist/server/bare/ops/unload-model.js +2 -0
  133. package/dist/server/bare/plugins/index.d.ts +1 -0
  134. package/dist/server/bare/plugins/index.js +1 -0
  135. package/dist/server/bare/plugins/llamacpp-completion/ops/completion-stream.d.ts +3 -1
  136. package/dist/server/bare/plugins/llamacpp-completion/ops/completion-stream.js +45 -9
  137. package/dist/server/bare/plugins/llamacpp-completion/ops/finetune.d.ts +11 -0
  138. package/dist/server/bare/plugins/llamacpp-completion/ops/finetune.js +112 -0
  139. package/dist/server/bare/plugins/llamacpp-completion/plugin.d.ts +175 -5
  140. package/dist/server/bare/plugins/llamacpp-completion/plugin.js +45 -35
  141. package/dist/server/bare/plugins/llamacpp-embedding/plugin.d.ts +11 -1
  142. package/dist/server/bare/plugins/llamacpp-embedding/plugin.js +9 -4
  143. package/dist/server/bare/plugins/nmtcpp-translation/plugin.d.ts +17 -2
  144. package/dist/server/bare/plugins/nmtcpp-translation/plugin.js +16 -15
  145. package/dist/server/bare/plugins/onnx-ocr/ops/ocr-stream.d.ts +5 -7
  146. package/dist/server/bare/plugins/onnx-ocr/ops/ocr-stream.js +11 -3
  147. package/dist/server/bare/plugins/onnx-ocr/plugin.d.ts +2 -0
  148. package/dist/server/bare/plugins/onnx-ocr/plugin.js +24 -19
  149. package/dist/server/bare/plugins/onnx-tts/ops/text-to-speech.d.ts +7 -2
  150. package/dist/server/bare/plugins/onnx-tts/ops/text-to-speech.js +22 -97
  151. package/dist/server/bare/plugins/onnx-tts/plugin.d.ts +98 -9
  152. package/dist/server/bare/plugins/onnx-tts/plugin.js +85 -46
  153. package/dist/server/bare/plugins/parakeet-transcription/plugin.d.ts +30 -60
  154. package/dist/server/bare/plugins/parakeet-transcription/plugin.js +49 -37
  155. package/dist/server/bare/plugins/sdcpp-generation/ops/diffusion.d.ts +3 -0
  156. package/dist/server/bare/plugins/sdcpp-generation/ops/diffusion.js +51 -0
  157. package/dist/server/bare/plugins/sdcpp-generation/plugin.d.ts +278 -0
  158. package/dist/server/bare/plugins/sdcpp-generation/plugin.js +70 -0
  159. package/dist/server/bare/plugins/whispercpp-transcription/plugin.d.ts +38 -2
  160. package/dist/server/bare/plugins/whispercpp-transcription/plugin.js +43 -22
  161. package/dist/server/bare/rag-hyperdb/handlers/ingest.js +2 -1
  162. package/dist/server/bare/rag-hyperdb/handlers/search.js +2 -1
  163. package/dist/server/bare/rag-hyperdb/rag-workspace-manager.js +7 -0
  164. package/dist/server/bare/registry/model-config-utils.js +3 -0
  165. package/dist/server/bare/registry/model-registry.d.ts +2 -2
  166. package/dist/server/bare/registry/model-registry.js +1 -1
  167. package/dist/server/bare/registry/registry-client.js +21 -0
  168. package/dist/server/bare/runtime-lifecycle.d.ts +28 -0
  169. package/dist/server/bare/runtime-lifecycle.js +132 -0
  170. package/dist/server/bare/types/addon-responses.d.ts +62 -0
  171. package/dist/server/bare/types/addon-responses.js +1 -0
  172. package/dist/server/env.js +3 -1
  173. package/dist/server/rpc/delegate-transport.js +1 -1
  174. package/dist/server/rpc/handle-request.js +50 -4
  175. package/dist/server/rpc/handler-registry.js +20 -1
  176. package/dist/server/rpc/handler-utils.d.ts +5 -3
  177. package/dist/server/rpc/handler-utils.js +52 -50
  178. package/dist/server/rpc/handlers/delete-cache.js +3 -0
  179. package/dist/server/rpc/handlers/diffusion-stream.d.ts +3 -0
  180. package/dist/server/rpc/handlers/diffusion-stream.js +4 -0
  181. package/dist/server/rpc/handlers/finetune.d.ts +3 -0
  182. package/dist/server/rpc/handlers/finetune.js +16 -0
  183. package/dist/server/rpc/handlers/index.d.ts +10 -0
  184. package/dist/server/rpc/handlers/index.js +10 -0
  185. package/dist/server/rpc/handlers/load-model/hyperdrive.js +24 -9
  186. package/dist/server/rpc/handlers/load-model/registry.d.ts +11 -0
  187. package/dist/server/rpc/handlers/load-model/registry.js +31 -4
  188. package/dist/server/rpc/handlers/plugin-dispatch.d.ts +1 -13
  189. package/dist/server/rpc/handlers/plugin-dispatch.js +21 -21
  190. package/dist/server/rpc/handlers/resume.d.ts +3 -0
  191. package/dist/server/rpc/handlers/resume.js +11 -0
  192. package/dist/server/rpc/handlers/suspend.d.ts +3 -0
  193. package/dist/server/rpc/handlers/suspend.js +11 -0
  194. package/dist/server/rpc/handlers/transcribe-stream.d.ts +1 -1
  195. package/dist/server/rpc/handlers/transcribe-stream.js +2 -2
  196. package/dist/server/rpc/handlers/transcribe.d.ts +3 -0
  197. package/dist/server/rpc/handlers/transcribe.js +4 -0
  198. package/dist/server/rpc/profiling/operation-metrics.js +107 -16
  199. package/dist/server/rpc/profiling/operation-wrappers.d.ts +1 -1
  200. package/dist/server/rpc/profiling/operation-wrappers.js +51 -19
  201. package/dist/server/rpc/progress-throttle.d.ts +8 -0
  202. package/dist/server/rpc/progress-throttle.js +47 -0
  203. package/dist/server/rpc/rpc-utils.d.ts +5 -0
  204. package/dist/server/rpc/rpc-utils.js +11 -0
  205. package/dist/server/utils/path-security.js +1 -1
  206. package/dist/server/utils/tool-integration.js +10 -0
  207. package/dist/server/utils/tool-parser.js +9 -5
  208. package/dist/server/worker-core.d.ts +2 -0
  209. package/dist/server/worker-core.js +26 -23
  210. package/dist/server/worker.js +2 -1
  211. package/dist/utils/encoding.d.ts +9 -0
  212. package/dist/utils/encoding.js +14 -0
  213. package/dist/utils/errors-server.d.ts +6 -0
  214. package/dist/utils/errors-server.js +11 -0
  215. package/package.json +36 -25
  216. package/dist/server/rpc/delegate-utils.d.ts +0 -2
  217. 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 recordOperationEvent(params) {
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
- recordOperationEvent({
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
- recordOperationEvent({
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
- for await (const chunk of handler()) {
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
- recordOperationEvent({
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,5 @@
1
+ export declare function getNextCommandId(): number;
2
+ export declare function isTerminalChunk(value: unknown): value is {
3
+ done: true;
4
+ };
5
+ //# sourceMappingURL=rpc-utils.d.ts.map
@@ -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
- let result = parseGemmaFormat(text, tools);
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(text, tools);
207
+ result = parseQwenFormat(cleaned, tools);
204
208
  if (result.toolCalls.length > 0) {
205
209
  return result;
206
210
  }
207
- result = parseLlamacppFormat(text, tools);
211
+ result = parseLlamacppFormat(cleaned, tools);
208
212
  if (result.toolCalls.length > 0) {
209
213
  return result;
210
214
  }
211
- if (text.includes("<tool_call>")) {
215
+ if (cleaned.includes("<tool_call>")) {
212
216
  return { toolCalls: [], errors: [] };
213
217
  }
214
- result = parseGenericFormat(text, tools);
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
- const shutdownHandler = async () => {
66
- if (isShuttingDown)
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
  }
@@ -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.8.3",
3
+ "version": "0.9.1",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -96,6 +96,10 @@
96
96
  "types": "./dist/server/bare/plugins/onnx-ocr/plugin.d.ts",
97
97
  "import": "./dist/server/bare/plugins/onnx-ocr/plugin.js"
98
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
+ },
99
103
  "./plugin-utils": {
100
104
  "types": "./dist/schemas/plugin.d.ts",
101
105
  "import": "./dist/schemas/plugin.js"
@@ -114,6 +118,12 @@
114
118
  "./pear-pre": "./dist/pear/pre.js"
115
119
  },
116
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
+ },
117
127
  "#rpc": {
118
128
  "react-native": "./dist/client/rpc/expo-rpc-client.js",
119
129
  "bare": "./dist/client/rpc/bare-client.js",
@@ -162,34 +172,35 @@
162
172
  "changelog:generate": "node ../../scripts/sdk/generate-changelog-sdk-pod.cjs --package=sdk && prettier --write changelog"
163
173
  },
164
174
  "dependencies": {
165
- "@qvac/decoder-audio": "^0.3.3",
166
- "@qvac/dl-filesystem": "^0.2.0",
167
- "@qvac/embed-llamacpp": "^0.12.0",
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",
168
179
  "@qvac/error": "^0.1.1",
169
- "@qvac/langdetect-text": "^0.1.0",
170
- "@qvac/llm-llamacpp": "^0.12.1",
180
+ "@qvac/langdetect-text": "^0.1.2",
181
+ "@qvac/llm-llamacpp": "^0.14.4",
171
182
  "@qvac/logging": "^0.1.0",
172
- "@qvac/ocr-onnx": "^0.2.0",
173
- "@qvac/rag": "^0.4.2",
174
- "@qvac/registry-client": "^0.2.1",
175
- "@qvac/transcription-parakeet": "^0.2.0",
176
- "@qvac/transcription-whispercpp": "^0.5.0",
177
- "@qvac/translation-nmtcpp": "^0.6.1",
178
- "@qvac/tts-onnx": "^0.6.1",
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",
179
190
  "fast-safe-stringify": "2.1.1",
180
191
  "which-runtime": "^1.3.2",
181
192
  "zod": "^4.0.17"
182
193
  },
183
194
  "devDependencies": {
184
195
  "@eslint/js": "^9.33.0",
185
- "@expo/config-plugins": "^54.0.1",
196
+ "@expo/config-plugins": "^54.0.4",
186
197
  "@lancedb/lancedb": "^0.21.3",
187
198
  "@modelcontextprotocol/sdk": "^1.12.1",
188
- "@qvac/cli": "^0.2.2",
199
+ "@qvac/cli": "^0.2.3",
189
200
  "@sqliteai/sqlite-wasm": "3.50.4-sync.0.8.30-vector.0.9.23",
190
201
  "@types/node": "^24.2.1",
191
202
  "@types/tar-stream": "^3.1.4",
192
- "bare-pack": "^2.0.0",
203
+ "bare-pack": "^2.0.1",
193
204
  "bare-readline": "^1.2.0",
194
205
  "brittle": "^3.19.1",
195
206
  "chromadb": "^3.0.14",
@@ -197,9 +208,9 @@
197
208
  "eslint-import-resolver-typescript": "^4.4.4",
198
209
  "eslint-plugin-import": "^2.30.0",
199
210
  "eslint-plugin-react": "^7.37.5",
200
- "expo": "^54.0.0",
201
- "expo-device": "^8.0.0",
202
- "expo-file-system": "^19.0.15",
211
+ "expo": "^54.0.33",
212
+ "expo-device": "^8.0.10",
213
+ "expo-file-system": "^19.0.21",
203
214
  "globals": "^16.3.0",
204
215
  "husky": "^9.1.7",
205
216
  "hyperdb": "^4.16.1",
@@ -211,20 +222,20 @@
211
222
  "remark-frontmatter": "^5.0.0",
212
223
  "remark-mdx": "^3.1.1",
213
224
  "tsx": "^4.21.0",
214
- "typescript": "^5.9.2",
225
+ "typescript": "^5.9.3",
215
226
  "typescript-eslint": "^8.39.0"
216
227
  },
217
228
  "peerDependencies": {
218
229
  "@modelcontextprotocol/sdk": "^1.0.0",
219
- "@qvac/cli": "^0.2.2",
230
+ "@qvac/cli": "^0.2.3",
220
231
  "bare-abort-controller": "^1.0.0",
221
232
  "bare-buffer": "^3.4.2",
222
- "bare-crypto": "^1.11.2",
233
+ "bare-crypto": "^1.13.4",
223
234
  "bare-dns": "^2.1.4",
224
235
  "bare-fetch": "^2.5.1",
225
236
  "bare-fs": "^4.5.2",
226
237
  "bare-http1": "^4.1.6",
227
- "bare-https": "^2.1.1",
238
+ "bare-https": "^2.1.3",
228
239
  "bare-link": "^2.1.10",
229
240
  "bare-net": "^2.2.0",
230
241
  "bare-os": "^3.6.2",
@@ -233,7 +244,7 @@
233
244
  "bare-rpc": "^1.0.0",
234
245
  "bare-runtime": "^1.24.2",
235
246
  "bare-stream": "^2.7.0",
236
- "bare-subprocess": "^5.2.1",
247
+ "bare-subprocess": "^5.2.3",
237
248
  "bare-zlib": "^1.3.1",
238
249
  "compact-encoding": "^2.19.0",
239
250
  "corestore": "^7.4.5",
@@ -247,7 +258,7 @@
247
258
  "llm-splitter": "~0.2.0",
248
259
  "pear-pipe": "^1.0.6",
249
260
  "react-native-bare-kit": "^0.11.5",
250
- "tar-stream": "^3.1.7"
261
+ "tar-stream": "^3.1.8"
251
262
  },
252
263
  "peerDependenciesMeta": {
253
264
  "@qvac/cli": {
@@ -1,2 +0,0 @@
1
- export declare function getNextCommandId(): number;
2
- //# sourceMappingURL=delegate-utils.d.ts.map
@@ -1,5 +0,0 @@
1
- let commandCounter = 0;
2
- export function getNextCommandId() {
3
- commandCounter = (commandCounter + 1) % Number.MAX_SAFE_INTEGER;
4
- return commandCounter;
5
- }