@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.
Files changed (239) hide show
  1. package/NOTICE +115 -58
  2. package/README.md +10 -13
  3. package/dist/examples/asr/parakeet-sortformer.js +24 -14
  4. package/dist/examples/asr/parakeet-transcribepsy-filesystem.js +40 -11
  5. package/dist/examples/asr/parakeet-unified-coreml.js +14 -9
  6. package/dist/examples/asr/whispercpp-prompt.js +9 -5
  7. package/dist/examples/assess-model-fit.d.ts +7 -9
  8. package/dist/examples/assess-model-fit.js +22 -43
  9. package/dist/examples/calc-tokens.d.ts +2 -0
  10. package/dist/examples/calc-tokens.js +21 -0
  11. package/dist/examples/classification/classify-image.js +11 -5
  12. package/dist/examples/completion-stop-reason.d.ts +3 -3
  13. package/dist/examples/completion-stop-reason.js +4 -4
  14. package/dist/examples/diffusion-flux3-klein.d.ts +2 -0
  15. package/dist/examples/diffusion-flux3-klein.js +102 -0
  16. package/dist/examples/diffusion-moss-image.d.ts +2 -0
  17. package/dist/examples/diffusion-moss-image.js +126 -0
  18. package/dist/examples/diffusion-qwen-image-21.js +15 -4
  19. package/dist/examples/embed-multimodal.d.ts +2 -0
  20. package/dist/examples/embed-multimodal.js +80 -0
  21. package/dist/examples/embed-p2p.js +2 -2
  22. package/dist/examples/image/megaloc.d.ts +2 -0
  23. package/dist/examples/image/megaloc.js +37 -0
  24. package/dist/examples/llamacpp-multimodal.js +18 -0
  25. package/dist/examples/rag/rag-hyperdb/pipeline.js +2 -2
  26. package/dist/examples/rag/rag-turbovec.js +2 -2
  27. package/dist/examples/sessions.d.ts +17 -0
  28. package/dist/examples/sessions.js +63 -0
  29. package/dist/examples/tools/llamacpp-deferred-tools.js +8 -4
  30. package/dist/scripts/check-resource-collectors-packaging.js +7 -6
  31. package/dist/scripts/contract/build-contract.d.ts +2 -1
  32. package/dist/scripts/contract/build-contract.js +13 -1
  33. package/dist/scripts/contract/constants-registry.d.ts +17 -0
  34. package/dist/scripts/contract/constants-registry.js +8 -2
  35. package/dist/scripts/contract/method-shapes.d.ts +4 -0
  36. package/dist/scripts/contract/method-shapes.js +4 -0
  37. package/dist/scripts/enforce-inference-versions.d.ts +1 -1
  38. package/dist/scripts/enforce-inference-versions.js +28 -18
  39. package/dist/scripts/generate-bare-kit-runtimes.js +101 -69
  40. package/dist/src/client/api/assess-model-fit.d.ts +17 -17
  41. package/dist/src/client/api/assess-model-fit.js +18 -31
  42. package/dist/src/client/api/audio-edit.d.ts +5 -3
  43. package/dist/src/client/api/audio-edit.js +5 -3
  44. package/dist/src/client/api/audio-gen-result.js +134 -45
  45. package/dist/src/client/api/audio-gen.d.ts +40 -3
  46. package/dist/src/client/api/audio-gen.js +40 -3
  47. package/dist/src/client/api/audio-understand.d.ts +2 -2
  48. package/dist/src/client/api/audio-understand.js +2 -2
  49. package/dist/src/client/api/batch-completion.js +2 -1
  50. package/dist/src/client/api/calc-tokens.d.ts +33 -0
  51. package/dist/src/client/api/calc-tokens.js +44 -0
  52. package/dist/src/client/api/cancel.d.ts +2 -2
  53. package/dist/src/client/api/cancel.js +2 -2
  54. package/dist/src/client/api/classify.d.ts +12 -5
  55. package/dist/src/client/api/classify.js +17 -5
  56. package/dist/src/client/api/client-request-id.d.ts +0 -15
  57. package/dist/src/client/api/client-request-id.js +15 -12
  58. package/dist/src/client/api/completion-stream.d.ts +8 -1
  59. package/dist/src/client/api/completion-stream.js +10 -1
  60. package/dist/src/client/api/delete-cache.d.ts +9 -2
  61. package/dist/src/client/api/delete-cache.js +13 -3
  62. package/dist/src/client/api/diffusion.d.ts +20 -4
  63. package/dist/src/client/api/diffusion.js +23 -5
  64. package/dist/src/client/api/embed.d.ts +82 -29
  65. package/dist/src/client/api/embed.js +64 -19
  66. package/dist/src/client/api/get-model-info.d.ts +2 -2
  67. package/dist/src/client/api/get-model-info.js +2 -2
  68. package/dist/src/client/api/get-system-resources.d.ts +2 -2
  69. package/dist/src/client/api/get-system-resources.js +2 -2
  70. package/dist/src/client/api/heartbeat.d.ts +3 -2
  71. package/dist/src/client/api/heartbeat.js +3 -2
  72. package/dist/src/client/api/index.d.ts +4 -3
  73. package/dist/src/client/api/index.js +2 -1
  74. package/dist/src/client/api/invoke-plugin.d.ts +8 -2
  75. package/dist/src/client/api/invoke-plugin.js +17 -2
  76. package/dist/src/client/api/load-model.js +5 -2
  77. package/dist/src/client/api/ocr.d.ts +5 -3
  78. package/dist/src/client/api/ocr.js +44 -21
  79. package/dist/src/client/api/rag.d.ts +1 -1
  80. package/dist/src/client/api/rag.js +1 -1
  81. package/dist/src/client/api/registry.d.ts +17 -7
  82. package/dist/src/client/api/registry.js +37 -12
  83. package/dist/src/client/api/resume.d.ts +2 -1
  84. package/dist/src/client/api/resume.js +2 -2
  85. package/dist/src/client/api/rpc-server.d.ts +4 -4
  86. package/dist/src/client/api/rpc-server.js +10 -10
  87. package/dist/src/client/api/state.d.ts +2 -2
  88. package/dist/src/client/api/state.js +2 -2
  89. package/dist/src/client/api/subscribe-logs.d.ts +2 -2
  90. package/dist/src/client/api/subscribe-logs.js +2 -2
  91. package/dist/src/client/api/suspend.d.ts +4 -2
  92. package/dist/src/client/api/suspend.js +4 -3
  93. package/dist/src/client/api/text-to-speech.d.ts +14 -5
  94. package/dist/src/client/api/text-to-speech.js +83 -29
  95. package/dist/src/client/api/transcribe.d.ts +6 -2
  96. package/dist/src/client/api/transcribe.js +7 -1
  97. package/dist/src/client/api/unload-model.d.ts +19 -7
  98. package/dist/src/client/api/unload-model.js +29 -11
  99. package/dist/src/client/api/upscale.d.ts +6 -3
  100. package/dist/src/client/api/upscale.js +9 -4
  101. package/dist/src/client/api/vector-index.d.ts +50 -16
  102. package/dist/src/client/api/vector-index.js +100 -48
  103. package/dist/src/client/api/video-request.d.ts +5 -5
  104. package/dist/src/client/api/video.d.ts +3 -2
  105. package/dist/src/client/api/video.js +3 -2
  106. package/dist/src/client/api/vla.d.ts +9 -5
  107. package/dist/src/client/api/vla.js +17 -8
  108. package/dist/src/client/api/world.d.ts +5 -5
  109. package/dist/src/client/api/world.js +4 -4
  110. package/dist/src/client/init-hooks.d.ts +6 -4
  111. package/dist/src/client/init-hooks.js +12 -15
  112. package/dist/src/client/logging-stream-registry.d.ts +6 -3
  113. package/dist/src/client/logging-stream-registry.js +31 -12
  114. package/dist/src/client/rpc/bundle-stamp.d.ts +29 -0
  115. package/dist/src/client/rpc/bundle-stamp.js +75 -0
  116. package/dist/src/client/rpc/expo-home-dir.d.ts +2 -0
  117. package/dist/src/client/rpc/expo-home-dir.js +4 -0
  118. package/dist/src/client/rpc/expo-rpc-client.js +189 -135
  119. package/dist/src/client/rpc/node-rpc-client.js +322 -413
  120. package/dist/src/client/rpc/pear-runtime.d.ts +12 -0
  121. package/dist/src/client/rpc/pear-runtime.js +12 -0
  122. package/dist/src/client/rpc/rpc-client.d.ts +5 -4
  123. package/dist/src/client/rpc/rpc-client.js +126 -23
  124. package/dist/src/client/rpc/rpc-error.js +21 -2
  125. package/dist/src/client/rpc/unbundled-harness.d.ts +16 -0
  126. package/dist/src/client/rpc/unbundled-harness.js +27 -0
  127. package/dist/src/client/rpc/worker-failure.d.ts +27 -0
  128. package/dist/src/client/rpc/worker-failure.js +61 -0
  129. package/dist/src/client/session-registry.d.ts +75 -0
  130. package/dist/src/client/session-registry.js +149 -0
  131. package/dist/src/client/session.d.ts +125 -0
  132. package/dist/src/client/session.js +148 -0
  133. package/dist/src/commands/bundle/addons.d.ts +14 -0
  134. package/dist/src/commands/bundle/addons.js +65 -0
  135. package/dist/src/commands/bundle/constants.js +1 -0
  136. package/dist/src/commands/bundle/entry-gen.d.ts +1 -5
  137. package/dist/src/commands/bundle/entry-gen.js +17 -50
  138. package/dist/src/commands/bundle/index.d.ts +59 -13
  139. package/dist/src/commands/bundle/index.js +345 -121
  140. package/dist/src/commands/bundle/link.d.ts +58 -0
  141. package/dist/src/commands/bundle/link.js +135 -0
  142. package/dist/src/commands/bundle/node-support.d.ts +13 -0
  143. package/dist/src/commands/bundle/node-support.js +23 -0
  144. package/dist/src/commands/bundle/read-bundle.d.ts +9 -0
  145. package/dist/src/commands/bundle/read-bundle.js +27 -0
  146. package/dist/src/commands/bundle/resolve-sdk-import.d.ts +6 -0
  147. package/dist/src/commands/bundle/resolve-sdk-import.js +24 -28
  148. package/dist/src/commands/bundle/scratch.d.ts +35 -0
  149. package/dist/src/commands/bundle/scratch.js +178 -0
  150. package/dist/src/commands/bundle/targets.d.ts +14 -0
  151. package/dist/src/commands/bundle/targets.js +37 -0
  152. package/dist/src/commands/host-prebuilds/index.d.ts +5 -4
  153. package/dist/src/commands/host-prebuilds/index.js +9 -7
  154. package/dist/src/commands/index.d.ts +4 -3
  155. package/dist/src/commands/verify/abi.d.ts +20 -14
  156. package/dist/src/commands/verify/abi.js +11 -79
  157. package/dist/src/commands/verify/bare-kit-runtime.d.ts +20 -22
  158. package/dist/src/commands/verify/bare-kit-runtime.js +102 -150
  159. package/dist/src/commands/verify/bare-kit-runtimes.d.ts +10 -9
  160. package/dist/src/commands/verify/bare-kit-runtimes.js +21 -21
  161. package/dist/src/commands/verify/bundle-source.js +25 -21
  162. package/dist/src/commands/verify/engines-advice.d.ts +2 -8
  163. package/dist/src/commands/verify/engines-advice.js +7 -54
  164. package/dist/src/commands/verify/index.d.ts +30 -29
  165. package/dist/src/commands/verify/index.js +92 -200
  166. package/dist/src/commands/verify/prebuilds.d.ts +3 -5
  167. package/dist/src/commands/verify/prebuilds.js +1 -2
  168. package/dist/src/commands/verify/resource-collectors.d.ts +0 -6
  169. package/dist/src/commands/verify/resource-collectors.js +1 -50
  170. package/dist/src/commands/verify/sidecar-runtime.d.ts +6 -0
  171. package/dist/src/commands/verify/sidecar-runtime.js +51 -0
  172. package/dist/src/expo/plugins/withBareKit.d.ts +59 -0
  173. package/dist/src/expo/plugins/withBareKit.js +204 -0
  174. package/dist/src/expo/plugins/withMobileBundle.d.ts +4 -11
  175. package/dist/src/expo/plugins/withMobileBundle.js +36 -57
  176. package/dist/src/expo/plugins/withQvacSDK.d.ts +1 -0
  177. package/dist/src/expo/plugins/withQvacSDK.js +3 -0
  178. package/dist/src/index.d.ts +6 -5
  179. package/dist/src/index.js +10 -14
  180. package/dist/src/logging/utils.js +10 -2
  181. package/dist/src/plugin-ids.d.ts +2 -1
  182. package/dist/src/plugin-ids.js +2 -0
  183. package/dist/src/schemas/public.d.ts +1 -1
  184. package/dist/src/schemas/public.js +1 -1
  185. package/dist/src/schemas/sdk-errors-client.d.ts +5 -6
  186. package/dist/src/schemas/sdk-errors-client.js +30 -36
  187. package/dist/src/schemas/sdk-errors-server.d.ts +11 -1
  188. package/dist/src/schemas/sdk-errors-server.js +60 -2
  189. package/dist/src/server/rpc/rpc-utils.d.ts +25 -4
  190. package/dist/src/server/rpc/rpc-utils.js +39 -5
  191. package/dist/src/utils/errors-client.d.ts +37 -29
  192. package/dist/src/utils/errors-client.js +50 -41
  193. package/dist/src/utils/errors-server.d.ts +59 -1
  194. package/dist/src/utils/errors-server.js +110 -1
  195. package/dist/src/utils/withTimeout.js +34 -17
  196. package/dist/src/worker/handle-request.js +25 -22
  197. package/dist/src/worker/handler-utils.d.ts +2 -6
  198. package/dist/src/worker/handler-utils.js +2 -20
  199. package/dist/src/worker/index.d.ts +2 -4
  200. package/dist/src/worker/index.js +23 -35
  201. package/dist/src/worker/plugins/ggml-image-embedding.d.ts +2 -0
  202. package/dist/src/worker/plugins/ggml-image-embedding.js +1 -0
  203. package/dist/src/worker/shim.d.ts +4 -0
  204. package/dist/src/worker/shim.js +7 -0
  205. package/dist/src/worker/start.d.ts +9 -0
  206. package/dist/src/worker/start.js +16 -0
  207. package/dist/src/worker/unbundled-shim.d.ts +2 -0
  208. package/dist/src/worker/unbundled-shim.js +4 -0
  209. package/docs/system-resources-support-matrix.md +27 -19
  210. package/package.json +62 -51
  211. package/src/electron-forge/index.cjs +65 -91
  212. package/dist/examples/model-fit-ui/server.d.ts +0 -24
  213. package/dist/examples/model-fit-ui/server.js +0 -221
  214. package/dist/src/client/rpc/ensure-worker-ready.d.ts +0 -9
  215. package/dist/src/client/rpc/ensure-worker-ready.js +0 -17
  216. package/dist/src/client/rpc/init-timeout.d.ts +0 -26
  217. package/dist/src/client/rpc/init-timeout.js +0 -25
  218. package/dist/src/client/rpc/ipc-socket-path.d.ts +0 -11
  219. package/dist/src/client/rpc/ipc-socket-path.js +0 -30
  220. package/dist/src/client/rpc/worker-startup-error.d.ts +0 -12
  221. package/dist/src/client/rpc/worker-startup-error.js +0 -13
  222. package/dist/src/commands/bundle/bare-pack.d.ts +0 -21
  223. package/dist/src/commands/bundle/bare-pack.js +0 -77
  224. package/dist/src/commands/bundle/manifest.d.ts +0 -25
  225. package/dist/src/commands/bundle/manifest.js +0 -192
  226. package/dist/src/expo/plugins/link-addons.d.ts +0 -18
  227. package/dist/src/expo/plugins/link-addons.js +0 -65
  228. package/dist/src/pear/pre.d.ts +0 -21
  229. package/dist/src/pear/pre.js +0 -450
  230. package/dist/src/server/env.d.ts +0 -22
  231. package/dist/src/server/env.js +0 -59
  232. package/dist/src/server/utils/qvac-paths.d.ts +0 -2
  233. package/dist/src/server/utils/qvac-paths.js +0 -5
  234. package/dist/src/server/utils/worker-lock.d.ts +0 -3
  235. package/dist/src/server/utils/worker-lock.js +0 -67
  236. package/dist/src/worker/create-server.d.ts +0 -8
  237. package/dist/src/worker/create-server.js +0 -51
  238. package/dist/src/worker/lifecycle.d.ts +0 -23
  239. package/dist/src/worker/lifecycle.js +0 -149
@@ -1,11 +0,0 @@
1
- /**
2
- * Create the endpoint the worker dials.
3
- *
4
- * On Unix the socket sits in a fresh directory that only the current user can
5
- * enter, so other local users cannot reach it whatever the process umask. On
6
- * Windows it is a named pipe, whose default access already denies other users.
7
- */
8
- export declare function createIPCSocketPath(): string;
9
- /** Remove the socket file and its directory. Named pipes have nothing to remove. */
10
- export declare function removeIPCSocketPath(socketPath: string): void;
11
- //# sourceMappingURL=ipc-socket-path.d.ts.map
@@ -1,30 +0,0 @@
1
- import { randomBytes } from 'node:crypto';
2
- import fs from 'node:fs';
3
- import os from 'node:os';
4
- import path from 'node:path';
5
- const SOCKET_FILE_NAME = 'worker.sock';
6
- /**
7
- * Create the endpoint the worker dials.
8
- *
9
- * On Unix the socket sits in a fresh directory that only the current user can
10
- * enter, so other local users cannot reach it whatever the process umask. On
11
- * Windows it is a named pipe, whose default access already denies other users.
12
- */
13
- export function createIPCSocketPath() {
14
- if (process.platform === 'win32') {
15
- const timestamp = Date.now().toString(36);
16
- const randomSuffix = randomBytes(2).toString('hex');
17
- return `\\\\.\\pipe\\qvac-worker-${process.pid}-${timestamp}-${randomSuffix}`;
18
- }
19
- const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'qvac-worker-'));
20
- return path.join(dir, SOCKET_FILE_NAME);
21
- }
22
- /** Remove the socket file and its directory. Named pipes have nothing to remove. */
23
- export function removeIPCSocketPath(socketPath) {
24
- if (process.platform === 'win32')
25
- return;
26
- const dir = path.dirname(socketPath);
27
- fs.rmSync(socketPath, { force: true });
28
- if (fs.existsSync(dir))
29
- fs.rmdirSync(dir);
30
- }
@@ -1,12 +0,0 @@
1
- import { WorkerStartupError } from '../../utils/errors-client.js';
2
- export interface WorkerExit {
3
- code: number | null;
4
- signal: string | null;
5
- }
6
- /**
7
- * Always returns a cause. A worker that is still running and has written
8
- * nothing carries no diagnostic text, but `workerExited: false` is what tells a
9
- * caller that waiting longer could still help.
10
- */
11
- export declare function createRPCInitTimeoutCause(stderrTail: string, workerExit: WorkerExit | null): WorkerStartupError;
12
- //# sourceMappingURL=worker-startup-error.d.ts.map
@@ -1,13 +0,0 @@
1
- import { WorkerStartupError } from '../../utils/errors-client.js';
2
- /**
3
- * Always returns a cause. A worker that is still running and has written
4
- * nothing carries no diagnostic text, but `workerExited: false` is what tells a
5
- * caller that waiting longer could still help.
6
- */
7
- export function createRPCInitTimeoutCause(stderrTail, workerExit) {
8
- const stderr = stderrTail.trimEnd();
9
- if (workerExit) {
10
- return new WorkerStartupError(`Worker process exited with code ${workerExit.code}, signal ${workerExit.signal} before IPC connection was established`, { code: workerExit.code, signal: workerExit.signal }, stderr);
11
- }
12
- return new WorkerStartupError('Worker did not establish IPC before the RPC initialization timeout', null, stderr);
13
- }
@@ -1,21 +0,0 @@
1
- import type { Logger } from '../../logging/types.js';
2
- export declare const BARE_PACK_NODE_ENGINES = "^22.21.0 || >=24.9.0";
3
- export declare function isBarePackNodeSupported(version: string): boolean;
4
- interface NodeVersions {
5
- node: string;
6
- bun?: string | undefined;
7
- }
8
- interface RunBarePackOptions {
9
- entryPath: string;
10
- outputPath: string;
11
- hosts: string[];
12
- importsMapPath: string;
13
- deferModules: string[];
14
- quiet: boolean;
15
- logger: Logger;
16
- /** The runtime running bare-pack; defaults to this process. Tests inject an older Node. */
17
- nodeVersions?: NodeVersions | undefined;
18
- }
19
- export declare function runBarePack(options: RunBarePackOptions): Promise<void>;
20
- export {};
21
- //# sourceMappingURL=bare-pack.d.ts.map
@@ -1,77 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import { createRequire } from 'node:module';
4
- import { spawn } from 'node:child_process';
5
- import { platform, execPath, versions } from 'node:process';
6
- import semver from 'semver';
7
- import { BarePackNotInstalledError, BarePackNodeUnsupportedError, BarePackError } from '../../utils/errors-client.js';
8
- const require = createRequire(import.meta.url);
9
- // bare-module-lexer (loaded by bare-pack through bare-module-traverse) calls
10
- // js_is_sharedarraybuffer from its native addon, which Node outside this range
11
- // lacks; the bare-pack child process crashes instead of throwing. Same range as
12
- // engines.node in @qvac/cli.
13
- export const BARE_PACK_NODE_ENGINES = '^22.21.0 || >=24.9.0';
14
- export function isBarePackNodeSupported(version) {
15
- return semver.satisfies(version, BARE_PACK_NODE_ENGINES, { includePrerelease: true });
16
- }
17
- // On Node, bare-pack is spawned with this process's execPath, so checking
18
- // process.versions.node checks the Node that will load the lexer. Under Bun,
19
- // process.versions.node is Bun's emulated value and, except on Windows, bare-pack
20
- // runs through its shebang in the `node` from PATH, which cannot be checked here.
21
- function assertNodeCanRunBarePack(nodeVersions) {
22
- if (nodeVersions.bun !== undefined)
23
- return;
24
- if (isBarePackNodeSupported(nodeVersions.node))
25
- return;
26
- throw new BarePackNodeUnsupportedError(nodeVersions.node, BARE_PACK_NODE_ENGINES);
27
- }
28
- function resolveBarePackBin() {
29
- try {
30
- const barePackPkgPath = require.resolve('bare-pack/package');
31
- const barePackDir = path.dirname(barePackPkgPath);
32
- return path.join(barePackDir, 'bin.js');
33
- }
34
- catch {
35
- return null;
36
- }
37
- }
38
- export async function runBarePack(options) {
39
- const { entryPath, outputPath, hosts, importsMapPath, deferModules, quiet, logger } = options;
40
- const nodeVersions = options.nodeVersions ?? versions;
41
- const barePackBin = resolveBarePackBin();
42
- if (!barePackBin || !fs.existsSync(barePackBin)) {
43
- throw new BarePackNotInstalledError();
44
- }
45
- assertNodeCanRunBarePack(nodeVersions);
46
- return new Promise((resolve, reject) => {
47
- const hostArgs = hosts.flatMap((h) => ['--host', h]);
48
- const deferArgs = deferModules.flatMap((m) => ['--defer', m]);
49
- const args = [
50
- ...hostArgs,
51
- '--linked',
52
- '--imports',
53
- importsMapPath,
54
- ...deferArgs,
55
- '--out',
56
- outputPath,
57
- entryPath
58
- ];
59
- // Windows cannot exec a .js file directly, so it always goes through execPath.
60
- const viaShebang = nodeVersions.bun !== undefined && platform !== 'win32';
61
- const command = viaShebang ? barePackBin : execPath;
62
- const spawnArgs = viaShebang ? args : [barePackBin, ...args];
63
- logger.debug(`\nšŸ“¦ Running: ${command} ${spawnArgs.join(' ')}`);
64
- const proc = spawn(command, spawnArgs, {
65
- stdio: quiet ? 'ignore' : 'inherit'
66
- });
67
- proc.on('close', (code) => {
68
- if (code === 0) {
69
- resolve();
70
- }
71
- else {
72
- reject(new BarePackError(code ?? 1, entryPath, outputPath));
73
- }
74
- });
75
- proc.on('error', reject);
76
- });
77
- }
@@ -1,25 +0,0 @@
1
- import type { Logger } from '../../logging/types.js';
2
- interface BarePackHeader {
3
- id?: string;
4
- main?: string;
5
- imports?: Record<string, unknown>;
6
- resolutions?: Record<string, unknown>;
7
- }
8
- interface GenerateAddonsManifestOptions {
9
- bundlePath: string;
10
- outputDir: string;
11
- projectRoot: string;
12
- logger: Logger;
13
- includeAudioDecoder?: boolean;
14
- }
15
- export declare const AUDIO_DECODER_ADDON = "bare-ffmpeg";
16
- interface GenerateAddonsManifestResult {
17
- manifestPath: string;
18
- addons: string[];
19
- }
20
- export declare function extractPackedString(bundleJsText: string): string;
21
- export declare function extractBarePackHeader(packed: string): BarePackHeader;
22
- export declare function buildNestedPathIndex(resolutions: Record<string, unknown>, projectRoot: string): Map<string, Set<string>>;
23
- export declare function generateAddonsManifest(options: GenerateAddonsManifestOptions): Promise<GenerateAddonsManifestResult>;
24
- export {};
25
- //# sourceMappingURL=manifest.d.ts.map
@@ -1,192 +0,0 @@
1
- import fs, { promises as fsp } from 'node:fs';
2
- import path from 'node:path';
3
- export const AUDIO_DECODER_ADDON = 'bare-ffmpeg';
4
- export function extractPackedString(bundleJsText) {
5
- const idx = bundleJsText.indexOf('module.exports');
6
- if (idx === -1) {
7
- throw new Error("bundle does not contain 'module.exports'");
8
- }
9
- const eq = bundleJsText.indexOf('=', idx);
10
- if (eq === -1) {
11
- throw new Error("could not find '=' after module.exports");
12
- }
13
- let i = eq + 1;
14
- while (i < bundleJsText.length && /\s/.test(bundleJsText[i] ?? ''))
15
- i++;
16
- const quote = bundleJsText[i];
17
- if (quote !== '"' && quote !== "'") {
18
- throw new Error('export value is not a string literal');
19
- }
20
- i++;
21
- let out = '';
22
- let esc = false;
23
- for (; i < bundleJsText.length; i++) {
24
- const ch = bundleJsText[i];
25
- if (esc) {
26
- switch (ch) {
27
- case 'n':
28
- out += '\n';
29
- break;
30
- case 'r':
31
- out += '\r';
32
- break;
33
- case 't':
34
- out += '\t';
35
- break;
36
- case 'b':
37
- out += '\b';
38
- break;
39
- case 'f':
40
- out += '\f';
41
- break;
42
- case 'v':
43
- out += '\v';
44
- break;
45
- case '\\':
46
- out += '\\';
47
- break;
48
- case '"':
49
- out += '"';
50
- break;
51
- case "'":
52
- out += "'";
53
- break;
54
- case 'x': {
55
- const hex = bundleJsText.slice(i + 1, i + 3);
56
- if (!/^[0-9a-fA-F]{2}$/.test(hex))
57
- throw new Error('bad \\x escape');
58
- out += String.fromCharCode(parseInt(hex, 16));
59
- i += 2;
60
- break;
61
- }
62
- case 'u': {
63
- const hex = bundleJsText.slice(i + 1, i + 5);
64
- if (!/^[0-9a-fA-F]{4}$/.test(hex))
65
- throw new Error('bad \\u escape');
66
- out += String.fromCharCode(parseInt(hex, 16));
67
- i += 4;
68
- break;
69
- }
70
- default:
71
- out += ch;
72
- }
73
- esc = false;
74
- continue;
75
- }
76
- if (ch === '\\') {
77
- esc = true;
78
- continue;
79
- }
80
- if (ch === quote)
81
- break;
82
- out += ch;
83
- }
84
- if (i >= bundleJsText.length) {
85
- throw new Error('unterminated string literal');
86
- }
87
- return out;
88
- }
89
- export function extractBarePackHeader(packed) {
90
- const firstNL = packed.indexOf('\n');
91
- if (firstNL === -1) {
92
- throw new Error('packed string missing first newline separator');
93
- }
94
- const jsonStart = packed.indexOf('{', firstNL + 1);
95
- if (jsonStart === -1) {
96
- throw new Error('could not find header JSON start in packed string');
97
- }
98
- let i = jsonStart;
99
- let depth = 0;
100
- let inStr = false;
101
- let esc = false;
102
- for (; i < packed.length; i++) {
103
- const ch = packed[i];
104
- if (inStr) {
105
- if (esc)
106
- esc = false;
107
- else if (ch === '\\')
108
- esc = true;
109
- else if (ch === '"')
110
- inStr = false;
111
- continue;
112
- }
113
- if (ch === '"')
114
- inStr = true;
115
- else if (ch === '{')
116
- depth++;
117
- else if (ch === '}') {
118
- depth--;
119
- if (depth === 0) {
120
- i++;
121
- break;
122
- }
123
- }
124
- }
125
- if (depth !== 0) {
126
- throw new Error('unbalanced braces while extracting header JSON');
127
- }
128
- return JSON.parse(packed.slice(jsonStart, i));
129
- }
130
- const NODE_MODULES_RE = /\/node_modules\/(@[^/]+\/[^/]+|[^/]+)(?=\/)/g;
131
- export function buildNestedPathIndex(resolutions, projectRoot) {
132
- const index = new Map();
133
- for (const key of Object.keys(resolutions)) {
134
- for (const match of key.matchAll(NODE_MODULES_RE)) {
135
- const pkgName = match[1];
136
- if (!pkgName)
137
- continue;
138
- const idx = match.index;
139
- if (idx === undefined)
140
- continue;
141
- const marker = `/node_modules/${pkgName}/`;
142
- const candidate = path.join(projectRoot, key.slice(1, idx + marker.length), 'package.json');
143
- let set = index.get(pkgName);
144
- if (!set) {
145
- set = new Set();
146
- index.set(pkgName, set);
147
- }
148
- set.add(candidate);
149
- }
150
- }
151
- return index;
152
- }
153
- export async function generateAddonsManifest(options) {
154
- const { bundlePath, outputDir, projectRoot, logger, includeAudioDecoder = true } = options;
155
- logger.info('\nšŸ“¦ Generating addons manifest...');
156
- const bundleJsText = await fsp.readFile(bundlePath, 'utf8');
157
- const packed = extractPackedString(bundleJsText);
158
- const header = extractBarePackHeader(packed);
159
- const resolutions = header.resolutions ?? {};
160
- const pathsByPackage = buildNestedPathIndex(resolutions, projectRoot);
161
- const addons = [];
162
- for (const [pkgName, candidates] of pathsByPackage) {
163
- let pkgJson = null;
164
- for (const candidate of candidates) {
165
- try {
166
- if (fs.existsSync(candidate)) {
167
- pkgJson = JSON.parse(await fsp.readFile(candidate, 'utf8'));
168
- break;
169
- }
170
- }
171
- catch (err) {
172
- logger.warn(` Could not read ${candidate}: ${err.message}`);
173
- }
174
- }
175
- if (pkgJson?.addon === true && (includeAudioDecoder || pkgName !== AUDIO_DECODER_ADDON)) {
176
- addons.push(pkgName);
177
- }
178
- }
179
- addons.sort();
180
- const bundleId = typeof header.id === 'string' && header.id.length > 0 ? header.id : 'unknown';
181
- const manifest = {
182
- version: 1,
183
- bundleId,
184
- addons
185
- };
186
- const manifestPath = path.join(outputDir, 'addons.manifest.json');
187
- await fsp.writeFile(manifestPath, JSON.stringify(manifest, null, 2) + '\n');
188
- logger.info(` Found ${pathsByPackage.size} packages in bundle graph`);
189
- logger.info(` Identified ${addons.length} native addons: ${addons.join(', ') || '(none)'}`);
190
- logger.info(` Wrote ${manifestPath}`);
191
- return { manifestPath, addons };
192
- }
@@ -1,18 +0,0 @@
1
- import type { Logger } from '../../logging/types.js';
2
- export interface LinkAddonsOptions {
3
- projectRoot: string;
4
- entryPath: string;
5
- hosts: string[];
6
- logger: Logger;
7
- }
8
- /**
9
- * Links the native addons the worker entry loads into react-native-bare-kit
10
- * for each phone platform in `hosts`, replacing what the platform had.
11
- */
12
- export declare function linkAddons(options: LinkAddonsOptions): Promise<string[]>;
13
- /**
14
- * Addons that ship a library under the same name write it to the same path,
15
- * and the copy linked last is the one the app loads.
16
- */
17
- export declare function warnOverwritten(written: string[], out: string, logger: Logger): void;
18
- //# sourceMappingURL=link-addons.d.ts.map
@@ -1,65 +0,0 @@
1
- import { promises as fsp } from 'node:fs';
2
- import path from 'node:path';
3
- import link from 'bare-link';
4
- import { findInAncestorNodeModules } from '../../expo/plugins/find-in-ancestor-node-modules.js';
5
- import { AddonLinkFailedError } from '../../utils/errors-client.js';
6
- /** Where react-native-bare-kit builds each platform's linked addons from. */
7
- const PLATFORMS = [
8
- { prefix: 'android-', out: ['android', 'src', 'main', 'addons'] },
9
- { prefix: 'ios-', out: ['ios', 'addons'] }
10
- ];
11
- /**
12
- * Links the native addons the worker entry loads into react-native-bare-kit
13
- * for each phone platform in `hosts`, replacing what the platform had.
14
- */
15
- export async function linkAddons(options) {
16
- const { projectRoot, entryPath, hosts, logger } = options;
17
- const bareKitDir = findInAncestorNodeModules(projectRoot, 'react-native-bare-kit');
18
- if (bareKitDir === null) {
19
- logger.warn('react-native-bare-kit is not installed; the native addons were not linked.');
20
- return [];
21
- }
22
- const written = [];
23
- for (const platform of PLATFORMS) {
24
- const platformHosts = hosts.filter((host) => host.startsWith(platform.prefix));
25
- if (platformHosts.length === 0)
26
- continue;
27
- // bare-link signs Apple frameworks with codesign.
28
- if (platform.prefix === 'ios-' && process.platform !== 'darwin') {
29
- logger.warn(`Linking iOS addons needs macOS; skipped ${platformHosts.join(', ')}.`);
30
- continue;
31
- }
32
- const out = path.join(bareKitDir, ...platform.out);
33
- await fsp.rm(out, { recursive: true, force: true });
34
- const platformWritten = [];
35
- try {
36
- for await (const resource of link(entryPath, { hosts: platformHosts, out })) {
37
- logger.debug(`Linked ${path.relative(projectRoot, resource)}`);
38
- platformWritten.push(resource);
39
- }
40
- }
41
- catch (error) {
42
- throw new AddonLinkFailedError(platformHosts, error);
43
- }
44
- warnOverwritten(platformWritten, out, logger);
45
- written.push(...platformWritten);
46
- }
47
- return written;
48
- }
49
- /**
50
- * Addons that ship a library under the same name write it to the same path,
51
- * and the copy linked last is the one the app loads.
52
- */
53
- export function warnOverwritten(written, out, logger) {
54
- const seen = new Set();
55
- const overwritten = new Set();
56
- for (const file of written) {
57
- if (seen.has(file))
58
- overwritten.add(file);
59
- seen.add(file);
60
- }
61
- if (overwritten.size === 0)
62
- return;
63
- const files = [...overwritten].map((file) => path.relative(out, file)).sort();
64
- logger.warn(`Several native addons ship ${files.join(', ')}; only the copy linked last is kept.`);
65
- }
@@ -1,21 +0,0 @@
1
- /**
2
- * QVAC Pear Pre-Hook
3
- *
4
- * Invoked by Pear before `pear run` or `pear stage` to:
5
- * 1. Generate `qvac/worker.pear.entry.mjs` with selected plugins
6
- * 2. Persist `pear.stage.entrypoints` to package.json for routing
7
- *
8
- * Note: `qvac verify bundle` is not wired here yet — run it manually
9
- * (locally and/or in CI) before `pear stage` / `pear run`.
10
- *
11
- * @example package.json configuration
12
- * ```json
13
- * {
14
- * "pear": {
15
- * "pre": ["@qvac/sdk/pear-pre"]
16
- * }
17
- * }
18
- * ```
19
- */
20
- export {};
21
- //# sourceMappingURL=pre.d.ts.map