jiren 3.7.0 → 3.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.
@@ -0,0 +1,9 @@
1
+ import { JirenClient as NativeJirenClient } from "./client";
2
+ import { JirenClient as FetchJirenClient } from "./client-node-fetch";
3
+ import { isNativeAvailable } from "./native";
4
+
5
+ const forceFallback = process.env.JIREN_FORCE_FETCH_FALLBACK === "1";
6
+
7
+ export const JirenClient = (
8
+ !forceFallback && isNativeAvailable ? NativeJirenClient : FetchJirenClient
9
+ ) as unknown as typeof NativeJirenClient;
@@ -1,5 +1,5 @@
1
1
  // Main client
2
- export { JirenClient } from "./client";
2
+ export { JirenClient } from "./client-bun";
3
3
 
4
4
  // Types
5
5
  export type {
@@ -1,11 +1,38 @@
1
1
  import { dlopen, FFIType, suffix } from "bun:ffi";
2
- import { join } from "path";
3
-
4
- const platform = process.platform;
5
- const arch = process.arch;
2
+ import fs from "fs";
3
+ import { delimiter, dirname, join } from "path";
6
4
 
7
5
  // Reverted to flat structure
8
6
  const libPath = join(import.meta.dir, `../lib/libhttpclient.${suffix}`);
7
+ const libDir = dirname(libPath);
8
+
9
+ if (process.platform === "win32") {
10
+ // Ensure dependent DLLs (e.g. libcurl.dll, zlib1.dll) in jiren/lib are discoverable.
11
+ const currentPath = process.env.PATH ?? process.env.Path ?? "";
12
+ const hasLibDir = currentPath
13
+ .split(delimiter)
14
+ .some((entry) => entry.toLowerCase() === libDir.toLowerCase());
15
+ if (!hasLibDir) {
16
+ const nextPath = `${libDir}${delimiter}${currentPath}`;
17
+ process.env.PATH = nextPath;
18
+ process.env.Path = nextPath;
19
+ }
20
+ }
21
+
22
+ const preloadedWindowsDeps: Array<ReturnType<typeof dlopen>> = [];
23
+
24
+ if (process.platform === "win32") {
25
+ const dependencies = ["zlib1.dll", "libcurl.dll"];
26
+ for (const dependency of dependencies) {
27
+ const dependencyPath = join(libDir, dependency);
28
+ if (!fs.existsSync(dependencyPath)) continue;
29
+ try {
30
+ preloadedWindowsDeps.push(dlopen(dependencyPath, {} as any));
31
+ } catch {
32
+ // Best-effort: dlopen of libhttpclient.dll may still succeed via PATH/system lookup.
33
+ }
34
+ }
35
+ }
9
36
 
10
37
  export const ffiDef = {
11
38
  zclient_new: {
@@ -383,4 +410,37 @@ export const ffiDef = {
383
410
  },
384
411
  } as const;
385
412
 
386
- export const lib = dlopen(libPath, ffiDef);
413
+ let nativeLib: ReturnType<typeof dlopen> | null = null;
414
+ let nativeLoadError: Error | null = null;
415
+
416
+ try {
417
+ if (!fs.existsSync(libPath)) {
418
+ nativeLoadError = new Error(`Native library not found at: ${libPath}`);
419
+ } else {
420
+ nativeLib = dlopen(libPath, ffiDef);
421
+ }
422
+ } catch (error) {
423
+ nativeLoadError =
424
+ error instanceof Error ? error : new Error("Unknown native load error");
425
+ }
426
+
427
+ export const isNativeAvailable = nativeLib !== null;
428
+ export const nativeLibraryPath = libPath;
429
+ export const nativeAvailabilityError = nativeLoadError;
430
+
431
+ function unavailableSymbol(symbol: string) {
432
+ return () => {
433
+ const reason = nativeLoadError?.message || "Native runtime unavailable";
434
+ throw new Error(
435
+ `[Jiren] Native symbol "${symbol}" is unavailable. ${reason}`,
436
+ );
437
+ };
438
+ }
439
+
440
+ const unavailableSymbols = new Proxy({} as Record<string, any>, {
441
+ get(_target, symbol) {
442
+ return unavailableSymbol(String(symbol));
443
+ },
444
+ });
445
+
446
+ export const lib = (nativeLib ?? { symbols: unavailableSymbols }) as any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jiren",
3
- "version": "3.7.0",
3
+ "version": "3.9.0",
4
4
  "author": "",
5
5
  "main": "index.ts",
6
6
  "module": "index.ts",