transcribe-cpp 0.2.0 → 0.2.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.
package/dist/ffi.js CHANGED
@@ -9,6 +9,17 @@
9
9
  */
10
10
  import koffi from "koffi";
11
11
  import { defineTypes } from "./_generated.js";
12
+ // Koffi defaults async FFI workers to a 128 KiB stack. That is too small for
13
+ // ggml Vulkan model initialization on Windows (observed as an uncatchable
14
+ // 0xC0000005 access violation on Intel Iris Xe). Keep calls asynchronous, but
15
+ // raise the stack floor with headroom for other models and compiler changes.
16
+ // Preserve a larger application-provided value because Koffi configuration is
17
+ // process-global.
18
+ const MIN_ASYNC_STACK_SIZE = 512 * 1024;
19
+ const koffiConfig = koffi.config();
20
+ if ((koffiConfig.async_stack_size ?? 0) < MIN_ASYNC_STACK_SIZE) {
21
+ koffi.config({ async_stack_size: MIN_ASYNC_STACK_SIZE });
22
+ }
12
23
  export function bindLibrary(libraryPath) {
13
24
  const lib = koffi.load(libraryPath);
14
25
  const T = defineTypes(koffi);
package/dist/loader.js CHANGED
@@ -103,8 +103,13 @@ function tryPlatformPackage() {
103
103
  }
104
104
  // A contract mismatch is fatal, not a fall-through.
105
105
  const contract = validateContract(dir, provider);
106
+ const libraryPath = path.join(dir, LIB_NAME);
107
+ if (!fs.existsSync(libraryPath)) {
108
+ throw new BackendError(`provider ${provider} at ${dir} is missing ${LIB_NAME} — the package is ` +
109
+ `partially installed. Delete node_modules and reinstall.`);
110
+ }
106
111
  return {
107
- libraryPath: path.join(dir, LIB_NAME),
112
+ libraryPath,
108
113
  artifactDir: dir,
109
114
  provider,
110
115
  backends: contract.backends ?? [],
@@ -112,6 +117,45 @@ function tryPlatformPackage() {
112
117
  }
113
118
  return null;
114
119
  }
120
+ /**
121
+ * Explain why no provider package resolved, distinguishing "never installed"
122
+ * from "partially installed". The partial state is real: an interrupted
123
+ * optional-dependency extraction (the provider is by far the largest artifact
124
+ * in the tree) leaves an empty or missing directory that npm's hidden lockfile
125
+ * (node_modules/.package-lock.json) still records as installed. npm then
126
+ * trusts that lockfile on later installs, computes an empty diff, and never
127
+ * repairs the tree — only deleting node_modules (or the hidden lockfile)
128
+ * heals it, so the error must say which state the tree is in.
129
+ */
130
+ function diagnoseMissingProvider() {
131
+ const tuple = platformTuple();
132
+ if (!tuple) {
133
+ return `no prebuilt @transcribe-cpp provider exists for ${process.platform}-${process.arch}.`;
134
+ }
135
+ const provider = `@transcribe-cpp/${tuple}`;
136
+ const require = createRequire(import.meta.url);
137
+ for (const nm of require.resolve.paths(provider) ?? []) {
138
+ const providerDir = path.join(nm, "@transcribe-cpp", tuple);
139
+ let recorded = false;
140
+ try {
141
+ const hidden = JSON.parse(fs.readFileSync(path.join(nm, ".package-lock.json"), "utf8"));
142
+ recorded = `node_modules/@transcribe-cpp/${tuple}` in (hidden.packages ?? {});
143
+ }
144
+ catch {
145
+ // No readable hidden lockfile (pnpm/bun/yarn, or not this tree) — the
146
+ // directory probe below still catches a partially extracted provider.
147
+ }
148
+ if (fs.existsSync(providerDir) || recorded) {
149
+ return (`${provider}@${OUR_VERSION} under ${nm} is partially installed — its files ` +
150
+ `are missing even though the install recorded it as complete (typically an ` +
151
+ `interrupted download of this large optional dependency). A plain \`npm install\` ` +
152
+ `will NOT repair this; delete node_modules and reinstall.`);
153
+ }
154
+ }
155
+ return (`${provider}@${OUR_VERSION} is not installed. It is an optional dependency of ` +
156
+ `transcribe-cpp, and package managers skip optional dependencies silently when ` +
157
+ `they are disabled or a download fails; reinstall with \`npm install --include=optional\`.`);
158
+ }
115
159
  /** A library produced by the source build (`npm run build:native`). */
116
160
  function tryLocalPrebuild() {
117
161
  const tuple = platformTuple();
@@ -177,8 +221,8 @@ export function resolveLibrary() {
177
221
  tryLocalPrebuild() ??
178
222
  tryDevTree() ??
179
223
  (() => {
180
- throw new BackendError("No transcribe.cpp native library found. Set TRANSCRIBE_LIBRARY, install a " +
181
- "matching @transcribe-cpp/<platform> package, run `npm run build:native` to " +
182
- `build from source, or build the shared library (build-shared/src/${LIB_NAME}).`);
224
+ throw new BackendError(`No transcribe.cpp native library found: ${diagnoseMissingProvider()} ` +
225
+ "Alternatively set TRANSCRIBE_LIBRARY, run `npm run build:native` to build " +
226
+ `from source, or build the shared library (build-shared/src/${LIB_NAME}).`);
183
227
  })());
184
228
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "transcribe-cpp",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "TypeScript/Node.js bindings for transcribe.cpp — a C/C++ speech-to-text library built on ggml",
5
5
  "type": "module",
6
6
  "exports": {
@@ -51,11 +51,11 @@
51
51
  "koffi": "^3.0.2"
52
52
  },
53
53
  "optionalDependencies": {
54
- "@transcribe-cpp/darwin-arm64-metal": "0.2.0",
55
- "@transcribe-cpp/darwin-x64-cpu": "0.2.0",
56
- "@transcribe-cpp/linux-x64-cpu-vulkan": "0.2.0",
57
- "@transcribe-cpp/linux-arm64-cpu-vulkan": "0.2.0",
58
- "@transcribe-cpp/win32-x64-cpu-vulkan": "0.2.0"
54
+ "@transcribe-cpp/darwin-arm64-metal": "0.2.1",
55
+ "@transcribe-cpp/darwin-x64-cpu": "0.2.1",
56
+ "@transcribe-cpp/linux-x64-cpu-vulkan": "0.2.1",
57
+ "@transcribe-cpp/linux-arm64-cpu-vulkan": "0.2.1",
58
+ "@transcribe-cpp/win32-x64-cpu-vulkan": "0.2.1"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@types/node": "^22.0.0",