@bytesbrains/pi-loki-gate 1.0.0 → 1.0.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.
- package/LICENSE +1 -1
- package/README.md +6 -1
- package/package.json +5 -6
- package/src/config.ts +4 -1
- package/src/tools/query.ts +7 -2
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ For raw Docker container output (console.log + everything), use [pi-docker-logs]
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
pi install npm
|
|
10
|
+
pi install npm:@bytesbrains/pi-loki-gate
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
## Configuration
|
|
@@ -75,3 +75,8 @@ loki_worker_logs(container="ai-factory-orchestrator")
|
|
|
75
75
|
## License
|
|
76
76
|
|
|
77
77
|
MIT
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
Built and maintained by [BytesBrains](https://bytesbrains.com) — AI automation & agents, engineered to production standards.
|
|
82
|
+
*The model proposes, code guarantees.*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bytesbrains/pi-loki-gate",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Loki log gateway for pi agents — query Grafana Loki for container/job/worker logs from the wrok.in AI Factory.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -11,15 +11,14 @@
|
|
|
11
11
|
"logging",
|
|
12
12
|
"ai-factory"
|
|
13
13
|
],
|
|
14
|
-
"author": "
|
|
14
|
+
"author": "BytesBrains Pte Ltd (https://bytesbrains.com)",
|
|
15
15
|
"repository": {
|
|
16
16
|
"type": "git",
|
|
17
|
-
"url": "git+https://github.com/
|
|
18
|
-
"directory": "loki-gate"
|
|
17
|
+
"url": "git+https://github.com/bytesbrains/pi-loki-gate.git"
|
|
19
18
|
},
|
|
20
|
-
"homepage": "https://github.com/
|
|
19
|
+
"homepage": "https://github.com/bytesbrains/pi-loki-gate#readme",
|
|
21
20
|
"bugs": {
|
|
22
|
-
"url": "https://github.com/
|
|
21
|
+
"url": "https://github.com/bytesbrains/pi-loki-gate/issues"
|
|
23
22
|
},
|
|
24
23
|
"license": "MIT",
|
|
25
24
|
"main": "./src/index.ts",
|
package/src/config.ts
CHANGED
|
@@ -21,7 +21,10 @@ export function loadConfig(cwd: string): LokiConfig {
|
|
|
21
21
|
}
|
|
22
22
|
return {
|
|
23
23
|
lokiUrl: (result["lokiUrl"] as string) || DEFAULT_CONFIG.lokiUrl,
|
|
24
|
-
defaultLimit
|
|
24
|
+
const defaultLimit = parseInt(result["defaultLimit"] as string);
|
|
25
|
+
return {
|
|
26
|
+
lokiUrl: (result["lokiUrl"] as string) || DEFAULT_CONFIG.lokiUrl,
|
|
27
|
+
defaultLimit: isNaN(defaultLimit) ? DEFAULT_CONFIG.defaultLimit : defaultLimit,
|
|
25
28
|
};
|
|
26
29
|
} catch {
|
|
27
30
|
return { ...DEFAULT_CONFIG };
|
package/src/tools/query.ts
CHANGED
|
@@ -3,6 +3,11 @@ import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
|
3
3
|
import { loadConfig } from "../config";
|
|
4
4
|
import { lokiQuery, formatLogOutput } from "../helpers";
|
|
5
5
|
|
|
6
|
+
/** Escape backticks to prevent LogQL injection via user input. */
|
|
7
|
+
function escapeLogQL(value: string): string {
|
|
8
|
+
return value.replace(/`/g, '\\`');
|
|
9
|
+
}
|
|
10
|
+
|
|
6
11
|
// ─── Query Logs ───────────────────────────────────────────────────────────────
|
|
7
12
|
|
|
8
13
|
export const queryLogsTool = {
|
|
@@ -60,7 +65,7 @@ export const jobLogsTool = {
|
|
|
60
65
|
async execute(_id: string, params: any, _s: any, _u: any, ctx: ExtensionContext) {
|
|
61
66
|
const config = loadConfig(ctx.cwd);
|
|
62
67
|
const limit = params.limit || 200;
|
|
63
|
-
const query = `{service_name=~"worker|orchestrator"} |= \`${params.jobId}\``;
|
|
68
|
+
const query = `{service_name=~"worker|orchestrator"} |= \`${escapeLogQL(params.jobId)}\``;
|
|
64
69
|
|
|
65
70
|
const result = await lokiQuery(config, query, limit);
|
|
66
71
|
|
|
@@ -138,7 +143,7 @@ export const workerLogsTool = {
|
|
|
138
143
|
|
|
139
144
|
let query = `{${serviceFilter}}`;
|
|
140
145
|
if (params.search) {
|
|
141
|
-
query += ` |= \`${params.search}\``;
|
|
146
|
+
query += ` |= \`${escapeLogQL(params.search)}\``;
|
|
142
147
|
}
|
|
143
148
|
|
|
144
149
|
const result = await lokiQuery(config, query, limit);
|