@parcha/agentrun-import 0.0.0-bootstrap.0 → 0.1.0-beta.55

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/usage.js ADDED
@@ -0,0 +1,46 @@
1
+ // One reading of a request's token counts for every provider, so every number this package (and what imports it)
2
+ // publishes agrees: `input` is the input neither read from nor written to the cache.
3
+ // anthropic input_tokens already leaves the cache out; cache_creation.ephemeral_1h_input_tokens is the 1h part.
4
+ // openai input_tokens holds cached_input_tokens (and a cache write where one is counted): subtracted. output_tokens
5
+ // holds reasoning_output_tokens, kept as `reasoning` beside it. Codex writes OpenAI's counts.
6
+ // pi already split as Usage is, cacheWrite1h included.
7
+ import { isObject } from "./text.js";
8
+ /** Each format's names for input, cache read, cache write and output, and whether its input holds its cache counts. */
9
+ const NAMES = {
10
+ anthropic: { input: "input_tokens", cacheRead: "cache_read_input_tokens", cacheWrite: "cache_creation_input_tokens", output: "output_tokens", cachedIn: false },
11
+ openai: { input: "input_tokens", cacheRead: "cached_input_tokens", cacheWrite: "cache_write_input_tokens", output: "output_tokens", cachedIn: true },
12
+ pi: { input: "input", cacheRead: "cacheRead", cacheWrite: "cacheWrite", output: "output", cachedIn: false },
13
+ };
14
+ const count = (value) => (Number.isSafeInteger(value) && value >= 0 ? value : undefined);
15
+ /** A request's usage as `format` writes it, as Usage; undefined unless input and output are counts (an absent cache
16
+ * count is 0) and the input left is not negative. The 1h part of the cache write, or the reasoning part of the output,
17
+ * is kept only when it is a count of at most the whole. */
18
+ export function normalizeUsage(format, raw) {
19
+ if (!isObject(raw))
20
+ return undefined;
21
+ const names = NAMES[format];
22
+ const usage = { input: count(raw[names.input]), output: count(raw[names.output]), cacheRead: count(raw[names.cacheRead] ?? 0), cacheWrite: count(raw[names.cacheWrite] ?? 0) };
23
+ if (usage.input === undefined || usage.output === undefined || usage.cacheRead === undefined || usage.cacheWrite === undefined)
24
+ return undefined;
25
+ if (names.cachedIn)
26
+ usage.input -= usage.cacheRead + usage.cacheWrite;
27
+ if (usage.input < 0)
28
+ return undefined;
29
+ const out = usage;
30
+ const long = count(format === "anthropic" ? (isObject(raw.cache_creation) ? raw.cache_creation.ephemeral_1h_input_tokens : undefined) : format === "pi" ? raw.cacheWrite1h : undefined);
31
+ if (long !== undefined && long <= out.cacheWrite)
32
+ out.cacheWrite1h = long;
33
+ const reasoning = format === "openai" ? count(raw.reasoning_output_tokens) : undefined;
34
+ if (reasoning !== undefined && reasoning <= out.output)
35
+ out.reasoning = reasoning;
36
+ return out;
37
+ }
38
+ export const noTokens = () => ({ input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cacheWrite1h: 0 });
39
+ export function addTokens(into, usage) {
40
+ into.input += usage.input;
41
+ into.output += usage.output;
42
+ into.cacheRead += usage.cacheRead;
43
+ into.cacheWrite += usage.cacheWrite;
44
+ into.cacheWrite1h += usage.cacheWrite1h ?? 0;
45
+ return into;
46
+ }
package/package.json CHANGED
@@ -1 +1,60 @@
1
- {"name":"@parcha/agentrun-import","version":"0.0.0-bootstrap.0","description":"Placeholder so a trusted publisher can be set; the first release replaces it.","license":"Apache-2.0","repository":{"type":"git","url":"git+https://github.com/Parcha-ai/agentrun.git"}}
1
+ {
2
+ "name": "@parcha/agentrun-import",
3
+ "version": "0.1.0-beta.55",
4
+ "description": "Reads the coding-agent sessions under a home (Claude Code, Codex, pi) into one Session shape, with normalized token usage, subagents under their parent, byte-offset cursors for re-reads, and per-session totals.",
5
+ "keywords": [
6
+ "agentrun",
7
+ "claude-code",
8
+ "codex",
9
+ "pi",
10
+ "sessions",
11
+ "usage"
12
+ ],
13
+ "type": "module",
14
+ "license": "Apache-2.0",
15
+ "author": "Parcha Labs, Inc.",
16
+ "bin": {
17
+ "agentrun-import": "./dist/cli.js"
18
+ },
19
+ "engines": {
20
+ "node": ">=24.22.3"
21
+ },
22
+ "main": "./dist/index.js",
23
+ "types": "./dist/index.d.ts",
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "default": "./dist/index.js"
28
+ },
29
+ "./package.json": "./package.json"
30
+ },
31
+ "files": [
32
+ "dist",
33
+ "README.md",
34
+ "LICENSE",
35
+ "NOTICE"
36
+ ],
37
+ "sideEffects": false,
38
+ "scripts": {
39
+ "build": "rm -rf dist && tsc -p tsconfig.json",
40
+ "prepack": "npm run build",
41
+ "typecheck": "tsc -p tsconfig.json --noEmit",
42
+ "test": "node --test --test-concurrency=8 'test/*.test.mjs'"
43
+ },
44
+ "dependencies": {
45
+ "@earendil-works/pi-ai": "1.5.2"
46
+ },
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "git+https://github.com/Parcha-ai/agentrun.git",
50
+ "directory": "packages/import"
51
+ },
52
+ "bugs": {
53
+ "url": "https://github.com/Parcha-ai/agentrun/issues"
54
+ },
55
+ "homepage": "https://agentrun.ai",
56
+ "publishConfig": {
57
+ "access": "public",
58
+ "tag": "beta"
59
+ }
60
+ }