@primeradianthq/obol 0.1.1 → 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/README.md +3 -3
- package/dist/{ffi-bun-C6QZKITS.js → ffi-bun-E53EDNXE.js} +0 -7
- package/dist/{ffi-node-27DIUBG7.js → ffi-node-JGEYIBCH.js} +0 -9
- package/dist/index.d.ts +3 -4
- package/dist/index.js +2 -6
- 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
|
@@ -29,13 +29,13 @@ The library is resolved in order: `$OBOL_LIB` (explicit path) → the package's
|
|
|
29
29
|
## Usage
|
|
30
30
|
|
|
31
31
|
```ts
|
|
32
|
-
import { estimatePath,
|
|
32
|
+
import { estimatePath, refresh, version, ObolError } from "obol";
|
|
33
33
|
|
|
34
|
-
const est = await estimatePath("session.jsonl", "claude");
|
|
34
|
+
const est = await estimatePath("session.jsonl", "claude");
|
|
35
35
|
console.log(est.total_usd, est.pricing_as_of);
|
|
36
36
|
|
|
37
37
|
try {
|
|
38
|
-
await
|
|
38
|
+
await estimatePath("session.jsonl", "gemini");
|
|
39
39
|
} catch (e) {
|
|
40
40
|
if (e instanceof ObolError) console.error(e.code, e.kind, e.message);
|
|
41
41
|
}
|
|
@@ -5,11 +5,9 @@ function createBackend(libPath) {
|
|
|
5
5
|
obol_version: { args: [], returns: FFIType.ptr },
|
|
6
6
|
obol_string_free: { args: [FFIType.ptr], returns: FFIType.void },
|
|
7
7
|
obol_estimate_path: { args: [FFIType.cstring, FFIType.cstring, FFIType.ptr], returns: FFIType.i32 },
|
|
8
|
-
obol_estimate_bytes: { args: [FFIType.ptr, FFIType.u64, FFIType.cstring, FFIType.ptr], returns: FFIType.i32 },
|
|
9
8
|
obol_refresh_pricing: { args: [FFIType.cstring, FFIType.ptr], returns: FFIType.i32 }
|
|
10
9
|
});
|
|
11
10
|
const cstr = (s) => s === null ? null : Buffer.from(s + "\0");
|
|
12
|
-
const nonEmpty = (data) => data.length === 0 ? new Uint8Array(1) : data;
|
|
13
11
|
const drain = (code, out) => {
|
|
14
12
|
const p = out[0];
|
|
15
13
|
if (p === 0n) return { code, json: null };
|
|
@@ -25,11 +23,6 @@ function createBackend(libPath) {
|
|
|
25
23
|
const code = symbols.obol_estimate_path(cstr(path), cstr(dialect), ptr(out));
|
|
26
24
|
return drain(code, out);
|
|
27
25
|
},
|
|
28
|
-
estimateBytes(data, dialect) {
|
|
29
|
-
const out = new BigUint64Array(1);
|
|
30
|
-
const code = symbols.obol_estimate_bytes(ptr(nonEmpty(data)), BigInt(data.length), cstr(dialect), ptr(out));
|
|
31
|
-
return drain(code, out);
|
|
32
|
-
},
|
|
33
26
|
refresh(asOf) {
|
|
34
27
|
const out = new BigUint64Array(1);
|
|
35
28
|
const code = symbols.obol_refresh_pricing(cstr(asOf), ptr(out));
|
|
@@ -7,11 +7,7 @@ function createBackend(libPath) {
|
|
|
7
7
|
const obol_estimate_path = lib.func(
|
|
8
8
|
"int obol_estimate_path(const char* path, const char* dialect, _Out_ void** out)"
|
|
9
9
|
);
|
|
10
|
-
const obol_estimate_bytes = lib.func(
|
|
11
|
-
"int obol_estimate_bytes(const uint8_t* data, size_t len, const char* dialect, _Out_ void** out)"
|
|
12
|
-
);
|
|
13
10
|
const obol_refresh = lib.func("int obol_refresh_pricing(const char* as_of, _Out_ void** out)");
|
|
14
|
-
const nonEmpty = (data) => data.length === 0 ? Buffer.alloc(1) : data;
|
|
15
11
|
const drain = (code, out) => {
|
|
16
12
|
const p = out[0];
|
|
17
13
|
if (p === null || p === void 0) return { code, json: null };
|
|
@@ -27,11 +23,6 @@ function createBackend(libPath) {
|
|
|
27
23
|
const code = obol_estimate_path(path, dialect, out);
|
|
28
24
|
return drain(code, out);
|
|
29
25
|
},
|
|
30
|
-
estimateBytes(data, dialect) {
|
|
31
|
-
const out = [null];
|
|
32
|
-
const code = obol_estimate_bytes(nonEmpty(data), data.length, dialect, out);
|
|
33
|
-
return drain(code, out);
|
|
34
|
-
},
|
|
35
26
|
refresh(asOf) {
|
|
36
27
|
const out = [null];
|
|
37
28
|
const code = obol_refresh(asOf, out);
|
package/dist/index.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ interface RefreshReport {
|
|
|
27
27
|
as_of: string;
|
|
28
28
|
written_to: string;
|
|
29
29
|
}
|
|
30
|
-
type Dialect = "claude" | "codex" | "pi";
|
|
30
|
+
type Dialect = "claude" | "codex" | "pi" | "gemini" | "opencode" | "copilot" | "kimi";
|
|
31
31
|
declare class ObolError extends Error {
|
|
32
32
|
code: number;
|
|
33
33
|
kind: string;
|
|
@@ -35,8 +35,7 @@ declare class ObolError extends Error {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
declare function version(): Promise<string>;
|
|
38
|
-
declare function estimatePath(path: string, dialect
|
|
39
|
-
declare function estimateBytes(data: Uint8Array, dialect?: Dialect | null): Promise<CostEstimate>;
|
|
38
|
+
declare function estimatePath(path: string, dialect: Dialect): Promise<CostEstimate>;
|
|
40
39
|
declare function refresh(asOf: string): Promise<RefreshReport>;
|
|
41
40
|
|
|
42
|
-
export { type Approximation, type CostEstimate, type Dialect, type ModelCost, ObolError, type RefreshReport, type TokenBuckets,
|
|
41
|
+
export { type Approximation, type CostEstimate, type Dialect, type ModelCost, ObolError, type RefreshReport, type TokenBuckets, estimatePath, refresh, version };
|
package/dist/index.js
CHANGED
|
@@ -43,7 +43,7 @@ function backend() {
|
|
|
43
43
|
async function load() {
|
|
44
44
|
const isBun = typeof globalThis.Bun !== "undefined";
|
|
45
45
|
const libPath = resolveLibPath();
|
|
46
|
-
const mod = isBun ? await import("./ffi-bun-
|
|
46
|
+
const mod = isBun ? await import("./ffi-bun-E53EDNXE.js") : await import("./ffi-node-JGEYIBCH.js");
|
|
47
47
|
return mod.createBackend(libPath);
|
|
48
48
|
}
|
|
49
49
|
|
|
@@ -83,18 +83,14 @@ function unwrap(r) {
|
|
|
83
83
|
async function version() {
|
|
84
84
|
return (await backend()).version();
|
|
85
85
|
}
|
|
86
|
-
async function estimatePath(path, dialect
|
|
86
|
+
async function estimatePath(path, dialect) {
|
|
87
87
|
return unwrap((await backend()).estimatePath(path, dialect));
|
|
88
88
|
}
|
|
89
|
-
async function estimateBytes(data, dialect = null) {
|
|
90
|
-
return unwrap((await backend()).estimateBytes(data, dialect));
|
|
91
|
-
}
|
|
92
89
|
async function refresh(asOf) {
|
|
93
90
|
return unwrap((await backend()).refresh(asOf));
|
|
94
91
|
}
|
|
95
92
|
export {
|
|
96
93
|
ObolError,
|
|
97
|
-
estimateBytes,
|
|
98
94
|
estimatePath,
|
|
99
95
|
refresh,
|
|
100
96
|
version
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|