@typed-assistant/builder 0.0.55 → 0.0.57

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typed-assistant/builder",
3
- "version": "0.0.55",
3
+ "version": "0.0.57",
4
4
  "exports": {
5
5
  "./appProcess": "./src/appProcess.tsx",
6
6
  "./bunInstall": "./src/bunInstall.tsx",
@@ -26,9 +26,9 @@
26
26
  "ts-toolbelt": "^9.6.0",
27
27
  "typescript": "^5.3.3",
28
28
  "@typed-assistant/eslint-config": "0.0.9",
29
- "@typed-assistant/utils": "0.0.15",
30
29
  "@typed-assistant/logger": "0.0.17",
31
- "@typed-assistant/typescript-config": "0.0.9"
30
+ "@typed-assistant/typescript-config": "0.0.9",
31
+ "@typed-assistant/utils": "0.0.15"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "home-assistant-js-websocket": "^8.2.0"
@@ -10,6 +10,7 @@ export const pullChanges = async () => {
10
10
  { emoji: "⬇️🚨" },
11
11
  `Failed to pull changes.\n (${stderr.toString().trim()})`,
12
12
  )
13
+ return
13
14
  }
14
15
  const gitPullText = stdout.toString()
15
16
  const packageJSONUpdated = /package.json/.test(gitPullText)
@@ -11,6 +11,8 @@ import { getAddonInfo } from "./getAddonInfo"
11
11
  import { addKillListener, killSubprocess } from "./killProcess"
12
12
  import { restartAddon } from "./restartAddon"
13
13
  import { levels } from "@typed-assistant/logger/levels"
14
+ import { getSupervisorAPI } from "@typed-assistant/utils/getHassAPI"
15
+ import { withErrorHandling } from "@typed-assistant/utils/withErrorHandling"
14
16
 
15
17
  const indexHtmlFilePath = `${import.meta.dir}/webserver/index.html` as const
16
18
  const cssFile = `${import.meta.dir}/webserver/input.css` as const
@@ -141,6 +143,20 @@ export const startWebappServer = async ({
141
143
  translations: "HIDDEN",
142
144
  }
143
145
  })
146
+ .get("/stats", async () => {
147
+ const { data, error } = await withErrorHandling(
148
+ getSupervisorAPI<{
149
+ error?: never
150
+ cpu_percent: number
151
+ memory_usage: number
152
+ memory_limit: number
153
+ memory_percent: number
154
+ }>,
155
+ )("/addons/self/stats")
156
+
157
+ if (error) return { error: error.message }
158
+ return data
159
+ })
144
160
  .get(
145
161
  "/log.txt",
146
162
  async ({ query }) => {
@@ -164,17 +180,6 @@ export const startWebappServer = async ({
164
180
  t.Literal("fatal"),
165
181
  ]),
166
182
  }),
167
- response: t.Object({
168
- logs: t.Array(
169
- t.Object({
170
- level: t.Number(),
171
- time: t.Number(),
172
- pid: t.Number(),
173
- hostname: t.String(),
174
- msg: t.String(),
175
- }),
176
- ),
177
- }),
178
183
  async open(ws) {
179
184
  ws.send(await getLogsFromFile(ws.data.query.level, ws.data.query.limit))
180
185
  logSubscribers.set(ws.id, async () => {
@@ -1,5 +1,8 @@
1
1
  import { Terminal } from "./Terminal"
2
2
  import { Logs } from "./Logs"
3
+ import { useEffect, useState } from "react"
4
+ import { app } from "./api"
5
+ import { Await } from "ts-toolbelt/out/Any/Await"
3
6
 
4
7
  const basePath = process.env.BASE_PATH ?? ""
5
8
 
@@ -10,10 +13,43 @@ const App = () => {
10
13
  <Terminal />
11
14
  </div>
12
15
  <div className="col-span-1">
13
- <Logs basePath={basePath} />
16
+ <div className="p-4 text-xs h-full max-h-dvh w-dvw md:w-auto overflow-x-auto flex flex-col">
17
+ <Logs basePath={basePath} />
18
+ <Logs basePath={basePath} />
19
+ </div>
14
20
  </div>
15
21
  </div>
16
22
  )
17
23
  }
18
24
 
25
+ const Stats = () => {
26
+ const [error, setError] = useState<string | null>(null)
27
+ const [stats, setStats] =
28
+ useState<Awaited<ReturnType<typeof app.stats.get>>["data"]>()
29
+
30
+ useEffect(() => {
31
+ app.stats.get().then((stats) => {
32
+ if (stats.error || stats.data.error) {
33
+ setError(stats.error?.message ?? stats.data?.error ?? "Unknown error")
34
+ return
35
+ }
36
+
37
+ setStats(stats.data)
38
+ })
39
+ }, [])
40
+
41
+ if (error || stats?.error) {
42
+ return <div>Error: {error}</div>
43
+ }
44
+ if (stats?.error) {
45
+ return <div>Error: {error}</div>
46
+ }
47
+
48
+ return (
49
+ <div className="">
50
+ <div>Memory: </div>
51
+ </div>
52
+ )
53
+ }
54
+
19
55
  export default App
@@ -1,13 +1,12 @@
1
+ import type { LogSchema } from "@typed-assistant/logger"
2
+ import { levels } from "@typed-assistant/logger/levels"
3
+ import { getPrettyTimestamp } from "@typed-assistant/utils/getPrettyTimestamp"
1
4
  import { useCallback, useState } from "react"
2
- import { z } from "zod"
3
5
  import { AppSection } from "./AppSection"
4
6
  import { WSIndicator } from "./WSIndicator"
5
7
  import { app } from "./api"
6
- import { useWS } from "./useWS"
7
- import { getPrettyTimestamp } from "@typed-assistant/utils/getPrettyTimestamp"
8
- import { levels } from "@typed-assistant/logger/levels"
9
- import type { LogSchema } from "@typed-assistant/logger"
10
8
  import { buttonStyle } from "./styles"
9
+ import { useWS } from "./useWS"
11
10
 
12
11
  export const Logs = ({ basePath }: { basePath: string }) => {
13
12
  const [limit, setLimit] = useState(200)