@cnife/pi-miscs 0.1.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.
- package/extensions/debug-request-body.ts +22 -0
- package/extensions/exit.ts +11 -0
- package/package.json +17 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
|
|
5
|
+
export default function (pi: ExtensionAPI) {
|
|
6
|
+
const debugDir = process.env.PI_DEBUG_REQUEST_BODY;
|
|
7
|
+
if (!debugDir) return;
|
|
8
|
+
|
|
9
|
+
fs.mkdirSync(debugDir, { recursive: true });
|
|
10
|
+
|
|
11
|
+
pi.on("before_provider_request", (event, _ctx) => {
|
|
12
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
|
|
13
|
+
const payload = event.payload as Record<string, unknown>;
|
|
14
|
+
const modelId = (payload.model as string) ?? "unknown";
|
|
15
|
+
const filename = `${timestamp}--${modelId}.json`;
|
|
16
|
+
const filePath = path.join(debugDir, filename);
|
|
17
|
+
|
|
18
|
+
fs.writeFileSync(filePath, JSON.stringify(payload, null, 2), "utf-8");
|
|
19
|
+
|
|
20
|
+
console.log(`[debug-request-body] wrote ${filePath}`);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
|
|
3
|
+
export default function (pi: ExtensionAPI) {
|
|
4
|
+
pi.on("input", async (event, ctx) => {
|
|
5
|
+
if (event.text.trim() === "exit") {
|
|
6
|
+
ctx.shutdown();
|
|
7
|
+
return { action: "handled" };
|
|
8
|
+
}
|
|
9
|
+
return { action: "continue" };
|
|
10
|
+
});
|
|
11
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cnife/pi-miscs",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pi-package"
|
|
7
|
+
],
|
|
8
|
+
"description": "Miscellaneous small pi extensions (debug, exit)",
|
|
9
|
+
"pi": {
|
|
10
|
+
"extensions": [
|
|
11
|
+
"./extensions"
|
|
12
|
+
]
|
|
13
|
+
},
|
|
14
|
+
"peerDependencies": {
|
|
15
|
+
"@earendil-works/pi-coding-agent": "*"
|
|
16
|
+
}
|
|
17
|
+
}
|