pi-observability 1.0.1 → 1.3.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/.oxfmtrc.json +3 -0
- package/.oxlintrc.json +15 -0
- package/.zed/settings.json +222 -0
- package/README.md +98 -31
- package/demo-preview.gif +0 -0
- package/extensions/lib/footer-engine/format.ts +67 -0
- package/extensions/lib/footer-engine/index.ts +55 -0
- package/extensions/lib/footer-engine/layout.ts +47 -0
- package/extensions/lib/footer-engine/segments.ts +95 -0
- package/extensions/lib/footer-engine/types.ts +56 -0
- package/extensions/lib/settings/domain.ts +161 -0
- package/extensions/lib/settings/index.ts +32 -0
- package/extensions/lib/settings/manager.ts +58 -0
- package/extensions/lib/settings/metadata.ts +114 -0
- package/extensions/lib/settings/storage.ts +38 -0
- package/extensions/lib/settings/tui.ts +44 -0
- package/extensions/lib/settings/types.ts +40 -0
- package/extensions/lib/storage/file-backend.ts +62 -0
- package/extensions/lib/storage/index.ts +33 -0
- package/extensions/lib/storage/json-store.ts +32 -0
- package/extensions/lib/storage/jsonl-store.ts +29 -0
- package/extensions/lib/storage/memory-backend.ts +37 -0
- package/extensions/lib/storage/types.ts +23 -0
- package/extensions/observability.ts +653 -558
- package/package.json +55 -48
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { JsonlStore, RawBackend } from "./types.js";
|
|
2
|
+
|
|
3
|
+
export function createJsonlStore<T>(backend: RawBackend, name: string): JsonlStore<T> {
|
|
4
|
+
const fileName = `${name}.jsonl`;
|
|
5
|
+
|
|
6
|
+
return {
|
|
7
|
+
async append(value: T): Promise<void> {
|
|
8
|
+
const line = JSON.stringify(value);
|
|
9
|
+
await backend.append(fileName, line);
|
|
10
|
+
},
|
|
11
|
+
|
|
12
|
+
async read(options?: { last?: number }): Promise<T[]> {
|
|
13
|
+
const lines = await backend.readLines(fileName, options);
|
|
14
|
+
const results: T[] = [];
|
|
15
|
+
for (const line of lines) {
|
|
16
|
+
try {
|
|
17
|
+
results.push(JSON.parse(line) as T);
|
|
18
|
+
} catch (err) {
|
|
19
|
+
console.error(`[storage] corrupt JSONL line in ${fileName}, skipping:`, err);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return results;
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
async trim(options: { keepLast: number }): Promise<void> {
|
|
26
|
+
await backend.trimLines(fileName, options.keepLast);
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { RawBackend } from "./types.js";
|
|
2
|
+
|
|
3
|
+
export function createMemoryBackend(initial?: Map<string, string>): RawBackend {
|
|
4
|
+
const store = initial ?? new Map<string, string>();
|
|
5
|
+
|
|
6
|
+
return {
|
|
7
|
+
async read(name) {
|
|
8
|
+
return store.get(name);
|
|
9
|
+
},
|
|
10
|
+
|
|
11
|
+
async write(name, content) {
|
|
12
|
+
store.set(name, content);
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
async append(name, line) {
|
|
16
|
+
const existing = store.get(name) ?? "";
|
|
17
|
+
store.set(name, `${existing}${line}\n`);
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
async readLines(name, options) {
|
|
21
|
+
const text = store.get(name);
|
|
22
|
+
if (!text) return [];
|
|
23
|
+
const lines = text.split("\n").filter((l) => l.trim());
|
|
24
|
+
if (options?.last !== undefined && options.last > 0) {
|
|
25
|
+
return lines.slice(-options.last);
|
|
26
|
+
}
|
|
27
|
+
return lines;
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
async trimLines(name, keepLast) {
|
|
31
|
+
const lines = await this.readLines(name);
|
|
32
|
+
if (lines.length <= keepLast) return;
|
|
33
|
+
const kept = lines.slice(-keepLast);
|
|
34
|
+
store.set(name, kept.map((l) => `${l}\n`).join(""));
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface JsonStore<T> {
|
|
2
|
+
load(): Promise<T>;
|
|
3
|
+
save(value: T): Promise<void>;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface JsonlStore<T> {
|
|
7
|
+
append(value: T): Promise<void>;
|
|
8
|
+
read(options?: { last?: number }): Promise<T[]>;
|
|
9
|
+
trim(options: { keepLast: number }): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface Storage {
|
|
13
|
+
json<T>(name: string, options?: { defaults?: T }): JsonStore<T>;
|
|
14
|
+
jsonl<T>(name: string): JsonlStore<T>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface RawBackend {
|
|
18
|
+
read(name: string): Promise<string | undefined>;
|
|
19
|
+
write(name: string, content: string): Promise<void>;
|
|
20
|
+
append(name: string, line: string): Promise<void>;
|
|
21
|
+
readLines(name: string, options?: { last?: number }): Promise<string[]>;
|
|
22
|
+
trimLines(name: string, keepLast: number): Promise<void>;
|
|
23
|
+
}
|