@ljw1004/opencode-trace 0.1.1 → 0.1.2
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/index.ts +20 -31
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -544,35 +544,24 @@ async function tracedFetch(
|
|
|
544
544
|
return res
|
|
545
545
|
}
|
|
546
546
|
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
}
|
|
547
|
+
/* Plugin model:
|
|
548
|
+
* - This module is loaded with dynamic import() when plugin state is initialized for an instance/directory.
|
|
549
|
+
* The module import is normally cached, so our top-level state like `orig` survives repeated hook initialization
|
|
550
|
+
* - Opencode calls `default.server()` when it initializes this plugin's server hooks for that instance.
|
|
551
|
+
* This can happen more than once per process across instance reload/dispose, which is why our fetch()
|
|
552
|
+
* patch is guarded even though the module itself is loaded only once.
|
|
553
|
+
* - Opencode v1.3 has a single unified process for both TUI and server, so its plugin entrypoint `default` is just a function.
|
|
554
|
+
* - Opencode v1.4 has two separate entrypoints, `default.tui()` and `default.server()`
|
|
555
|
+
*/
|
|
556
|
+
const main: (() => Promise<object>) & {id?: unknown, server?: unknown} = async () => {
|
|
557
|
+
if (!orig) {
|
|
558
|
+
orig = globalThis.fetch.bind(globalThis);
|
|
559
|
+
globalThis.fetch = tracedFetch;
|
|
560
|
+
}
|
|
561
|
+
return {};
|
|
562
|
+
};
|
|
564
563
|
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
//
|
|
568
|
-
|
|
569
|
-
// ]
|
|
570
|
-
//
|
|
571
|
-
// And it uses a different default export:
|
|
572
|
-
// export default async function opencodeTracePlugin() {
|
|
573
|
-
// if (!orig) {
|
|
574
|
-
// orig = globalThis.fetch.bind(globalThis);
|
|
575
|
-
// globalThis.fetch = tracedFetch;
|
|
576
|
-
// }
|
|
577
|
-
// return {}
|
|
578
|
-
// }
|
|
564
|
+
const entrypoint = main; // opencode v1.3 expects default export to be a function
|
|
565
|
+
entrypoint.id = "ljw1004.opencode-trace";
|
|
566
|
+
entrypoint.server = main; // opencode v1.4 expects default export to be an object, with server() being what executes
|
|
567
|
+
export default entrypoint;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ljw1004/opencode-trace",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "OpenCode plugin that saves raw json LLM request+responses as jsonl in ~/opencode-trace, with built-in HTML interactive viewer",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|