@timefly/opencode-plugin 0.2.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,23 @@
1
+ export type OpenCodeTokenUsage = {
2
+ input: number;
3
+ output: number;
4
+ reasoning: number;
5
+ cache: {
6
+ read: number;
7
+ write: number;
8
+ };
9
+ };
10
+ export type TokenMetrics = {
11
+ inputTokens: number;
12
+ outputTokens: number;
13
+ totalTokens: number;
14
+ reasoningTokens: number;
15
+ cacheReadTokens: number;
16
+ cacheWriteTokens: number;
17
+ outputTokensPerSecond?: number;
18
+ totalTokensPerSecond?: number;
19
+ };
20
+ export declare const sumTokenUsage: (tokenUsage: OpenCodeTokenUsage) => number;
21
+ export declare const buildTokenMetrics: (tokenUsage: OpenCodeTokenUsage, durationMs?: number) => TokenMetrics;
22
+ export declare const buildTokenMetadata: (tokenMetrics: TokenMetrics, extra?: Record<string, string | number | boolean>) => Record<string, string | number | boolean>;
23
+ //# sourceMappingURL=token-usage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token-usage.d.ts","sourceRoot":"","sources":["../src/token-usage.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,GAAG;IAChC,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE;QACN,IAAI,EAAE,MAAM,CAAA;QACZ,KAAK,EAAE,MAAM,CAAA;KACb,CAAA;CACD,CAAA;AAED,MAAM,MAAM,YAAY,GAAG;IAC1B,WAAW,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;IACpB,WAAW,EAAE,MAAM,CAAA;IACnB,eAAe,EAAE,MAAM,CAAA;IACvB,eAAe,EAAE,MAAM,CAAA;IACvB,gBAAgB,EAAE,MAAM,CAAA;IACxB,qBAAqB,CAAC,EAAE,MAAM,CAAA;IAC9B,oBAAoB,CAAC,EAAE,MAAM,CAAA;CAC7B,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,YAAY,kBAAkB,KAAG,MACH,CAAA;AAE5D,eAAO,MAAM,iBAAiB,GAAI,YAAY,kBAAkB,EAAE,aAAa,MAAM,KAAG,YAmBvF,CAAA;AAED,eAAO,MAAM,kBAAkB,GAAI,cAAc,YAAY,EAAE,QAAO,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAM,KAAG,MAAM,CAC5H,MAAM,EACN,MAAM,GAAG,MAAM,GAAG,OAAO,CAUxB,CAAA"}
@@ -0,0 +1,28 @@
1
+ export const sumTokenUsage = (tokenUsage) => tokenUsage.input + tokenUsage.output + tokenUsage.reasoning;
2
+ export const buildTokenMetrics = (tokenUsage, durationMs) => {
3
+ const inputTokens = tokenUsage.input;
4
+ const outputTokens = tokenUsage.output;
5
+ const reasoningTokens = tokenUsage.reasoning;
6
+ const totalTokens = sumTokenUsage(tokenUsage);
7
+ const durationSeconds = durationMs && durationMs > 0 ? durationMs / 1000 : undefined;
8
+ return {
9
+ inputTokens,
10
+ outputTokens,
11
+ totalTokens,
12
+ reasoningTokens,
13
+ cacheReadTokens: tokenUsage.cache.read,
14
+ cacheWriteTokens: tokenUsage.cache.write,
15
+ outputTokensPerSecond: durationSeconds !== undefined ? Math.round((outputTokens / durationSeconds) * 100) / 100 : undefined,
16
+ totalTokensPerSecond: durationSeconds !== undefined ? Math.round((totalTokens / durationSeconds) * 100) / 100 : undefined
17
+ };
18
+ };
19
+ export const buildTokenMetadata = (tokenMetrics, extra = {}) => ({
20
+ reasoning_tokens: tokenMetrics.reasoningTokens,
21
+ cache_read_tokens: tokenMetrics.cacheReadTokens,
22
+ cache_write_tokens: tokenMetrics.cacheWriteTokens,
23
+ ...(tokenMetrics.outputTokensPerSecond !== undefined
24
+ ? { output_tokens_per_second: tokenMetrics.outputTokensPerSecond }
25
+ : {}),
26
+ ...(tokenMetrics.totalTokensPerSecond !== undefined ? { total_tokens_per_second: tokenMetrics.totalTokensPerSecond } : {}),
27
+ ...extra
28
+ });
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "@timefly/opencode-plugin",
3
+ "version": "0.2.0",
4
+ "description": "TimeFly telemetry plugin for OpenCode — sessions, tokens, models, and tools",
5
+ "type": "module",
6
+ "bin": {
7
+ "timefly-opencode-install": "./dist/install.js",
8
+ "timefly-opencode-login": "./dist/login.js",
9
+ "setup-opencode": "./dist/install.js",
10
+ "login": "./dist/login.js"
11
+ },
12
+ "main": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.js",
18
+ "default": "./dist/index.js"
19
+ }
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "README.md"
24
+ ],
25
+ "scripts": {
26
+ "build": "tsc -p tsconfig.json",
27
+ "typecheck": "tsc -p tsconfig.json --noEmit && tsc -p test/tsconfig.json --noEmit",
28
+ "test": "bun test",
29
+ "prepublishOnly": "bun run build && bun run typecheck && bun test",
30
+ "setup-opencode": "bun run dist/install.js",
31
+ "login": "bun run dist/login.js",
32
+ "link": "bun link"
33
+ },
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "https://github.com/TimeFly-Dev/ai-integrations.git",
37
+ "directory": "packages/opencode-plugin"
38
+ },
39
+ "publishConfig": {
40
+ "access": "public"
41
+ },
42
+ "keywords": [
43
+ "opencode",
44
+ "opencode-plugin",
45
+ "timefly",
46
+ "telemetry",
47
+ "ai",
48
+ "tokens",
49
+ "claude",
50
+ "llm"
51
+ ],
52
+ "homepage": "https://timefly.dev/integrations",
53
+ "bugs": {
54
+ "url": "https://github.com/TimeFly-Dev/ai-integrations/issues"
55
+ },
56
+ "license": "MIT",
57
+ "dependencies": {
58
+ "@timefly/ai-sdk": "^0.2.0"
59
+ },
60
+ "peerDependencies": {
61
+ "@opencode-ai/plugin": ">=1.0.0"
62
+ },
63
+ "devDependencies": {
64
+ "@opencode-ai/plugin": "^1.17.7",
65
+ "@timefly/ai-sdk": "workspace:*",
66
+ "@types/bun": "^1.3.14",
67
+ "@types/node": "^22.15.21",
68
+ "typescript": "^5.9.3"
69
+ },
70
+ "engines": {
71
+ "node": ">=18"
72
+ }
73
+ }