@primeradianthq/obol 0.2.1 → 0.2.3
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/README.md +16 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +28 -2
- package/native/darwin-arm64/libobol_ffi.dylib +0 -0
- package/native/darwin-x64/libobol_ffi.dylib +0 -0
- package/native/linux-arm64/libobol_ffi.so +0 -0
- package/native/linux-x64/libobol_ffi.so +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -46,6 +46,22 @@ The API is async because the FFI backend is loaded lazily (and cached) on first
|
|
|
46
46
|
Pricing tables must exist before estimating — run `obol refresh` (the CLI) or point
|
|
47
47
|
`OBOL_PRICING_DIR` at a directory containing a `current.json` snapshot.
|
|
48
48
|
|
|
49
|
+
### Pinning the pricing dir at runtime
|
|
50
|
+
|
|
51
|
+
To set `OBOL_PRICING_DIR` *after* the process has started, use the exported helpers rather than
|
|
52
|
+
writing `process.env` directly — under **Bun**, a runtime `process.env` write does not reach the
|
|
53
|
+
native environment the FFI (and Rust's `getenv`) observes, so the value is silently ignored. The
|
|
54
|
+
helpers call libc `setenv`/`unsetenv` under Bun (and set `process.env` for Node), so they work on
|
|
55
|
+
both runtimes:
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import { setPricingDir, clearPricingDir } from "obol";
|
|
59
|
+
|
|
60
|
+
await setPricingDir("/path/to/pricing-dir"); // a dir containing current.json
|
|
61
|
+
// … estimatePath(...) …
|
|
62
|
+
await clearPricingDir();
|
|
63
|
+
```
|
|
64
|
+
|
|
49
65
|
## Ownership
|
|
50
66
|
|
|
51
67
|
You never touch raw pointers. Each call copies obol's returned string into a JS string and then
|
package/dist/index.d.ts
CHANGED
|
@@ -34,8 +34,11 @@ declare class ObolError extends Error {
|
|
|
34
34
|
constructor(code: number, kind: string, message: string);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
declare function setPricingDir(dir: string): Promise<void>;
|
|
38
|
+
declare function clearPricingDir(): Promise<void>;
|
|
39
|
+
|
|
37
40
|
declare function version(): Promise<string>;
|
|
38
41
|
declare function estimatePath(path: string, dialect: Dialect): Promise<CostEstimate>;
|
|
39
42
|
declare function refresh(asOf: string): Promise<RefreshReport>;
|
|
40
43
|
|
|
41
|
-
export { type Approximation, type CostEstimate, type Dialect, type ModelCost, ObolError, type RefreshReport, type TokenBuckets, estimatePath, refresh, version };
|
|
44
|
+
export { type Approximation, type CostEstimate, type Dialect, type ModelCost, ObolError, type RefreshReport, type TokenBuckets, clearPricingDir, estimatePath, refresh, setPricingDir, version };
|
package/dist/index.js
CHANGED
|
@@ -41,9 +41,9 @@ function backend() {
|
|
|
41
41
|
return cached ??= load();
|
|
42
42
|
}
|
|
43
43
|
async function load() {
|
|
44
|
-
const
|
|
44
|
+
const isBun2 = typeof globalThis.Bun !== "undefined";
|
|
45
45
|
const libPath = resolveLibPath();
|
|
46
|
-
const mod =
|
|
46
|
+
const mod = isBun2 ? await import("./ffi-bun-E53EDNXE.js") : await import("./ffi-node-JGEYIBCH.js");
|
|
47
47
|
return mod.createBackend(libPath);
|
|
48
48
|
}
|
|
49
49
|
|
|
@@ -59,6 +59,30 @@ var ObolError = class extends Error {
|
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
61
|
|
|
62
|
+
// src/pricing-env.ts
|
|
63
|
+
var KEY = "OBOL_PRICING_DIR";
|
|
64
|
+
var isBun = typeof globalThis.Bun !== "undefined";
|
|
65
|
+
var libc;
|
|
66
|
+
async function nativeEnv() {
|
|
67
|
+
if (libc) return libc;
|
|
68
|
+
const { dlopen, FFIType } = await import("bun:ffi");
|
|
69
|
+
const name = process.platform === "darwin" ? "libSystem.dylib" : "libc.so.6";
|
|
70
|
+
const { symbols } = dlopen(name, {
|
|
71
|
+
setenv: { args: [FFIType.cstring, FFIType.cstring, FFIType.i32], returns: FFIType.i32 },
|
|
72
|
+
unsetenv: { args: [FFIType.cstring], returns: FFIType.i32 }
|
|
73
|
+
});
|
|
74
|
+
libc = symbols;
|
|
75
|
+
return libc;
|
|
76
|
+
}
|
|
77
|
+
async function setPricingDir(dir) {
|
|
78
|
+
process.env[KEY] = dir;
|
|
79
|
+
if (isBun) (await nativeEnv()).setenv(Buffer.from(KEY + "\0"), Buffer.from(dir + "\0"), 1);
|
|
80
|
+
}
|
|
81
|
+
async function clearPricingDir() {
|
|
82
|
+
delete process.env[KEY];
|
|
83
|
+
if (isBun) (await nativeEnv()).unsetenv(Buffer.from(KEY + "\0"));
|
|
84
|
+
}
|
|
85
|
+
|
|
62
86
|
// src/index.ts
|
|
63
87
|
function unwrap(r) {
|
|
64
88
|
if (r.code !== 0) {
|
|
@@ -91,7 +115,9 @@ async function refresh(asOf) {
|
|
|
91
115
|
}
|
|
92
116
|
export {
|
|
93
117
|
ObolError,
|
|
118
|
+
clearPricingDir,
|
|
94
119
|
estimatePath,
|
|
95
120
|
refresh,
|
|
121
|
+
setPricingDir,
|
|
96
122
|
version
|
|
97
123
|
};
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|