@p4r4d0xb0x/opencode-provider-logger 1.1.0 → 1.1.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.
@@ -1,61 +1,29 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- LocalWriter: () => LocalWriter,
24
- SessionBuffer: () => SessionBuffer,
25
- WorkerUploader: () => WorkerUploader,
26
- createOpenCodeHooks: () => createHooks,
27
- default: () => opencode_default,
28
- defaultConfig: () => defaultConfig,
29
- makeEntry: () => makeEntry
30
- });
31
- module.exports = __toCommonJS(index_exports);
32
-
33
1
  // ../provider-logger-core/dist/types.js
34
- var import_node_path = require("node:path");
35
- var import_node_fs = require("node:fs");
36
- var import_node_crypto = require("node:crypto");
37
- var import_node_os = require("node:os");
2
+ import { join } from "node:path";
3
+ import { readFileSync, writeFileSync } from "node:fs";
4
+ import { randomUUID } from "node:crypto";
5
+ import { homedir } from "node:os";
38
6
  function getOrCreateAuthToken() {
39
7
  if (process.env.PROVIDER_LOGGER_AUTH_TOKEN) {
40
8
  return process.env.PROVIDER_LOGGER_AUTH_TOKEN;
41
9
  }
42
- const home = process.env.HOME ?? (0, import_node_os.homedir)();
43
- const tokenPath = (0, import_node_path.join)(home, ".paradox_uuid");
10
+ const home = process.env.HOME ?? homedir();
11
+ const tokenPath = join(home, ".paradox_uuid");
44
12
  try {
45
- const existing = (0, import_node_fs.readFileSync)(tokenPath, "utf-8").trim();
13
+ const existing = readFileSync(tokenPath, "utf-8").trim();
46
14
  if (existing)
47
15
  return existing;
48
16
  } catch {
49
17
  }
50
- const token = (0, import_node_crypto.randomUUID)();
18
+ const token = randomUUID();
51
19
  try {
52
- (0, import_node_fs.writeFileSync)(tokenPath, token + "\n", { mode: 384 });
20
+ writeFileSync(tokenPath, token + "\n", { mode: 384 });
53
21
  } catch {
54
22
  }
55
23
  return token;
56
24
  }
57
25
  function defaultConfig(platform) {
58
- const home = process.env.HOME ?? (0, import_node_os.homedir)();
26
+ const home = process.env.HOME ?? homedir();
59
27
  const dirMap = {
60
28
  opencode: `${home}/.cache/opencode/provider-logs`,
61
29
  "claude-code": `${home}/.cache/claude-code/provider-logs`,
@@ -116,51 +84,51 @@ var SessionBuffer = class {
116
84
  };
117
85
 
118
86
  // ../provider-logger-core/dist/logger.js
119
- var import_promises = require("node:fs/promises");
120
- var import_node_path2 = require("node:path");
87
+ import { mkdir, writeFile, appendFile, readdir, stat, unlink, rmdir } from "node:fs/promises";
88
+ import { join as join2 } from "node:path";
121
89
  var LocalWriter = class {
122
90
  config;
123
91
  constructor(config) {
124
92
  this.config = config;
125
93
  }
126
94
  sessionDir(sessionID) {
127
- return (0, import_node_path2.join)(this.config.localDir, sessionID);
95
+ return join2(this.config.localDir, sessionID);
128
96
  }
129
97
  /** Write a batch of entries to a new JSONL file (used by buffered mode) */
130
98
  async write(sessionID, entries) {
131
99
  if (entries.length === 0)
132
100
  return "";
133
101
  const dir = this.sessionDir(sessionID);
134
- await (0, import_promises.mkdir)(dir, { recursive: true });
102
+ await mkdir(dir, { recursive: true });
135
103
  const tsNanos = makeTimestampNanos();
136
- const filepath = (0, import_node_path2.join)(dir, `${tsNanos}.jsonl`);
104
+ const filepath = join2(dir, `${tsNanos}.jsonl`);
137
105
  const content = entries.map((e) => JSON.stringify(e)).join("\n") + "\n";
138
- await (0, import_promises.writeFile)(filepath, content, "utf-8");
106
+ await writeFile(filepath, content, "utf-8");
139
107
  return filepath;
140
108
  }
141
109
  /** Append a single entry to a session-scoped JSONL file (used by hook scripts) */
142
110
  async append(sessionID, entry) {
143
111
  const dir = this.sessionDir(sessionID);
144
- await (0, import_promises.mkdir)(dir, { recursive: true });
145
- const filepath = (0, import_node_path2.join)(dir, `${sessionID}.jsonl`);
146
- await (0, import_promises.appendFile)(filepath, JSON.stringify(entry) + "\n", "utf-8");
112
+ await mkdir(dir, { recursive: true });
113
+ const filepath = join2(dir, `${sessionID}.jsonl`);
114
+ await appendFile(filepath, JSON.stringify(entry) + "\n", "utf-8");
147
115
  return filepath;
148
116
  }
149
117
  async getPending() {
150
118
  const pending = [];
151
119
  try {
152
- const sessions = await (0, import_promises.readdir)(this.config.localDir);
120
+ const sessions = await readdir(this.config.localDir);
153
121
  for (const sessionID of sessions) {
154
122
  const dir = this.sessionDir(sessionID);
155
- const s = await (0, import_promises.stat)(dir).catch(() => null);
123
+ const s = await stat(dir).catch(() => null);
156
124
  if (!s?.isDirectory())
157
125
  continue;
158
- const files = await (0, import_promises.readdir)(dir);
126
+ const files = await readdir(dir);
159
127
  const uploaded = new Set(files.filter((f) => f.endsWith(".uploaded")));
160
128
  for (const file of files) {
161
129
  if (file.endsWith(".jsonl") && !uploaded.has(`${file}.uploaded`)) {
162
130
  pending.push({
163
- path: (0, import_node_path2.join)(dir, file),
131
+ path: join2(dir, file),
164
132
  sessionID,
165
133
  tsNanos: file.replace(".jsonl", "")
166
134
  });
@@ -172,36 +140,36 @@ var LocalWriter = class {
172
140
  return pending;
173
141
  }
174
142
  async markUploaded(filepath) {
175
- await (0, import_promises.writeFile)(`${filepath}.uploaded`, "", "utf-8");
143
+ await writeFile(`${filepath}.uploaded`, "", "utf-8");
176
144
  }
177
145
  async cleanup() {
178
146
  const cutoff = Date.now() - this.config.retentionDays * 24 * 60 * 60 * 1e3;
179
147
  try {
180
- const sessions = await (0, import_promises.readdir)(this.config.localDir);
148
+ const sessions = await readdir(this.config.localDir);
181
149
  for (const sessionID of sessions) {
182
150
  const dir = this.sessionDir(sessionID);
183
- const s = await (0, import_promises.stat)(dir).catch(() => null);
151
+ const s = await stat(dir).catch(() => null);
184
152
  if (!s?.isDirectory())
185
153
  continue;
186
- const files = await (0, import_promises.readdir)(dir);
154
+ const files = await readdir(dir);
187
155
  for (const file of files) {
188
156
  if (!file.endsWith(".jsonl"))
189
157
  continue;
190
- const filepath = (0, import_node_path2.join)(dir, file);
191
- const fstat = await (0, import_promises.stat)(filepath).catch(() => null);
158
+ const filepath = join2(dir, file);
159
+ const fstat = await stat(filepath).catch(() => null);
192
160
  if (!fstat)
193
161
  continue;
194
162
  const hasMarker = files.includes(`${file}.uploaded`);
195
163
  if (hasMarker && fstat.mtimeMs < cutoff) {
196
- await (0, import_promises.unlink)(filepath).catch(() => {
164
+ await unlink(filepath).catch(() => {
197
165
  });
198
- await (0, import_promises.unlink)(`${filepath}.uploaded`).catch(() => {
166
+ await unlink(`${filepath}.uploaded`).catch(() => {
199
167
  });
200
168
  }
201
169
  }
202
- const remaining = await (0, import_promises.readdir)(dir).catch(() => ["placeholder"]);
170
+ const remaining = await readdir(dir).catch(() => ["placeholder"]);
203
171
  if (remaining.length === 0) {
204
- await (0, import_promises.rmdir)(dir).catch(() => {
172
+ await rmdir(dir).catch(() => {
205
173
  });
206
174
  }
207
175
  }
@@ -217,7 +185,7 @@ function makeTimestampNanos() {
217
185
  }
218
186
 
219
187
  // ../provider-logger-core/dist/uploader.js
220
- var import_promises2 = require("node:fs/promises");
188
+ import { readFile } from "node:fs/promises";
221
189
  var WorkerUploader = class {
222
190
  config;
223
191
  writer;
@@ -230,7 +198,7 @@ var WorkerUploader = class {
230
198
  async upload(file) {
231
199
  const url = `${this.config.workerUrl}/${file.sessionID}/${file.tsNanos}.jsonl`;
232
200
  try {
233
- const body = await (0, import_promises2.readFile)(file.path);
201
+ const body = await readFile(file.path);
234
202
  const res = await fetch(url, {
235
203
  method: "PUT",
236
204
  headers: {
@@ -270,12 +238,12 @@ var WorkerUploader = class {
270
238
  };
271
239
 
272
240
  // ../provider-logger-core/dist/entry.js
273
- var import_node_crypto2 = require("node:crypto");
241
+ import { randomUUID as randomUUID2 } from "node:crypto";
274
242
  function makeEntry(platform, sessionID, category, hookName, input, output, meta) {
275
243
  const now = Date.now();
276
244
  const micro = Math.floor(Math.random() * 1e6);
277
245
  return {
278
- id: (0, import_node_crypto2.randomUUID)(),
246
+ id: randomUUID2(),
279
247
  timestamp: new Date(now).toISOString(),
280
248
  timestampNanos: `${now}${String(micro).padStart(6, "0")}`,
281
249
  sessionID,
@@ -382,7 +350,7 @@ function createHooks(buffer, config, flush, log) {
382
350
  }
383
351
 
384
352
  // src/adapters/opencode/index.ts
385
- var import_node_path3 = require("node:path");
353
+ import { basename } from "node:path";
386
354
  var providerLogger = async ({ client }) => {
387
355
  const config = defaultConfig("opencode");
388
356
  const buffer = new SessionBuffer();
@@ -405,7 +373,7 @@ var providerLogger = async ({ client }) => {
405
373
  try {
406
374
  const filepath = await writer.write(sessionID, entries);
407
375
  if (filepath) {
408
- const tsNanos = (0, import_node_path3.basename)(filepath, ".jsonl");
376
+ const tsNanos = basename(filepath, ".jsonl");
409
377
  await uploader.upload({ path: filepath, sessionID, tsNanos });
410
378
  }
411
379
  } catch (err) {
@@ -422,7 +390,7 @@ var providerLogger = async ({ client }) => {
422
390
  writes.push(
423
391
  writer.write(sessionID, entries).then(async (filepath) => {
424
392
  if (filepath) {
425
- const tsNanos = (0, import_node_path3.basename)(filepath, ".jsonl");
393
+ const tsNanos = basename(filepath, ".jsonl");
426
394
  await uploader.upload({ path: filepath, sessionID, tsNanos });
427
395
  }
428
396
  }).catch((err) => {
@@ -440,12 +408,12 @@ var providerLogger = async ({ client }) => {
440
408
  return createHooks(buffer, config, flush, log);
441
409
  };
442
410
  var opencode_default = providerLogger;
443
- // Annotate the CommonJS export names for ESM import in node:
444
- 0 && (module.exports = {
411
+ export {
445
412
  LocalWriter,
446
413
  SessionBuffer,
447
414
  WorkerUploader,
448
- createOpenCodeHooks,
415
+ createHooks as createOpenCodeHooks,
416
+ opencode_default as default,
449
417
  defaultConfig,
450
418
  makeEntry
451
- });
419
+ };
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "@p4r4d0xb0x/opencode-provider-logger",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Provider logger plugin for OpenCode",
5
- "main": "dist/index.cjs",
5
+ "type": "module",
6
+ "main": "dist/index.js",
6
7
  "types": "dist/index.d.ts",
7
8
  "exports": {
8
9
  ".": {
9
10
  "types": "./dist/index.d.ts",
10
- "require": "./dist/index.cjs",
11
- "default": "./dist/index.cjs"
11
+ "default": "./dist/index.js"
12
12
  }
13
13
  },
14
14
  "files": ["dist"],
15
15
  "scripts": {
16
- "build": "tsc --emitDeclarationOnly && esbuild src/index.ts --bundle --platform=node --format=cjs --outfile=dist/index.cjs --external:@opencode-ai/plugin --external:@opencode-ai/sdk",
16
+ "build": "tsc --emitDeclarationOnly && esbuild src/index.ts --bundle --platform=node --format=esm --outfile=dist/index.js --external:@opencode-ai/plugin --external:@opencode-ai/sdk",
17
17
  "test": "bun test",
18
18
  "prepublishOnly": "npm run build"
19
19
  },