@omercnet/paseo-top 0.0.0-stage → 0.0.1-alpha

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.
@@ -0,0 +1,56 @@
1
+ import { defineRpc } from "@getpaseo/plugin";
2
+ import { z } from "zod";
3
+
4
+ /** One history point every this often, `HISTORY_LENGTH` of them: five minutes in all. */
5
+ export const HISTORY_EVERY_MS = 10_000;
6
+ export const HISTORY_LENGTH = 30;
7
+
8
+ const percent = z.number().min(0).max(100);
9
+
10
+ /** Usage of the daemon host. Percentages are 0-100; `null` means the host cannot report it yet. */
11
+ const sample = z.object({
12
+ cpu: percent.nullable(),
13
+ memory: percent,
14
+ disk: percent.nullable(),
15
+ /** Disk read plus write throughput in bytes per second. */
16
+ io: z.number().min(0).nullable(),
17
+ });
18
+
19
+ export type Sample = z.infer<typeof sample>;
20
+
21
+ /** What one agent's whole process tree is costing, including everything its tools launched. */
22
+ const session = z.object({
23
+ agentId: z.string(),
24
+ title: z.string().nullable(),
25
+ workspace: z.string().nullable(),
26
+ /** CPU in cores: 1.5 means one and a half cores busy, summed over the tree. */
27
+ cores: z.number().min(0),
28
+ /** Resident memory in bytes, summed over the tree. */
29
+ rss: z.number().min(0),
30
+ /** The busiest process in the tree, which is usually what is actually heavy. */
31
+ command: z.string(),
32
+ processes: z.number().int().min(1),
33
+ heavy: z.boolean(),
34
+ });
35
+
36
+ export type Session = z.infer<typeof session>;
37
+
38
+ const load = z.object({ cores: z.number().min(0), rss: z.number().min(0) });
39
+
40
+ export const getUsage = defineRpc({
41
+ name: "top.usage",
42
+ input: z.object({}),
43
+ output: sample.extend({
44
+ /** Earlier samples, oldest first, `HISTORY_EVERY_MS` apart, so a fresh client has a timeline. */
45
+ history: z.array(sample).max(HISTORY_LENGTH),
46
+ totalMemory: z.number().positive(),
47
+ /** Busiest first. `null` where the host cannot attribute processes (anything but Linux). */
48
+ sessions: z.array(session).nullable(),
49
+ /**
50
+ * Everything scanned that is not listed in `sessions`: processes of no agent, of other daemons'
51
+ * agents, and of sessions past the list cap. Time spent in the kernel, exited processes and the
52
+ * page cache are not processes, so sessions plus this are not the whole host's usage.
53
+ */
54
+ other: load,
55
+ }),
56
+ });