@typed-assistant/builder 0.0.70 → 0.0.71

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.70",
3
+ "version": "0.0.71",
4
4
  "exports": {
5
5
  "./appProcess": "./src/appProcess.tsx",
6
6
  "./bunInstall": "./src/bunInstall.tsx",
@@ -27,7 +27,7 @@
27
27
  "@typed-assistant/eslint-config": "0.0.10",
28
28
  "@typed-assistant/logger": "0.0.20",
29
29
  "@typed-assistant/utils": "0.0.17",
30
- "@typed-assistant/typescript-config": "0.0.9"
30
+ "@typed-assistant/typescript-config": "0.0.10"
31
31
  },
32
32
  "peerDependencies": {},
33
33
  "publishConfig": {
@@ -17,7 +17,7 @@ type AddonInfoResponse = {
17
17
  rating: number
18
18
  boot: string
19
19
  arch: string[]
20
- machine: any[]
20
+ machine: unknown[]
21
21
  homeassistant: null
22
22
  url: string
23
23
  detached: boolean
@@ -1,6 +1,5 @@
1
1
  import { logger } from "@typed-assistant/logger"
2
2
  import type { Subprocess } from "bun"
3
- import { $ } from "bun"
4
3
 
5
4
  const killListeners: (() => void | Promise<void>)[] = []
6
5
  const softKillListeners: (() => void | Promise<void>)[] = []
@@ -204,7 +204,7 @@ export const startWebappServer = async ({
204
204
  .get(
205
205
  "/log.txt",
206
206
  async ({ query }) => {
207
- return getLogsFromFile("trace", query.limit)
207
+ return getLogsFromFile({ level: "trace", limit: query.limit })
208
208
  },
209
209
  {
210
210
  query: t.Object({
@@ -223,12 +223,25 @@ export const startWebappServer = async ({
223
223
  t.Literal("error"),
224
224
  t.Literal("fatal"),
225
225
  ]),
226
+ offset: t.Optional(t.String()),
226
227
  }),
228
+
227
229
  async open(ws) {
228
- ws.send(await getLogsFromFile(ws.data.query.level, ws.data.query.limit))
230
+ console.log("😅😅😅 ~ ws.data.query:", ws.data.query)
231
+ ws.send(
232
+ await getLogsFromFile({
233
+ level: ws.data.query.level,
234
+ limit: ws.data.query.limit,
235
+ offset: ws.data.query.offset,
236
+ }),
237
+ )
229
238
  logSubscribers.set(ws.id, async () => {
230
239
  ws.send(
231
- await getLogsFromFile(ws.data.query.level, ws.data.query.limit),
240
+ await getLogsFromFile({
241
+ level: ws.data.query.level,
242
+ limit: ws.data.query.limit,
243
+ offset: ws.data.query.offset,
244
+ }),
232
245
  )
233
246
  })
234
247
  },
@@ -327,8 +340,18 @@ export const startWebappServer = async ({
327
340
 
328
341
  export type WebServer = Awaited<ReturnType<typeof startWebappServer>>
329
342
 
330
- const getLogsFromFile = async (level: keyof typeof levels, limit?: string) => {
343
+ const getLogsFromFile = async ({
344
+ level,
345
+ limit: limitProp,
346
+ offset: offsetProp = "0",
347
+ }: {
348
+ level: keyof typeof levels
349
+ limit?: string
350
+ offset?: string
351
+ }) => {
331
352
  try {
353
+ const limit = Number(limitProp)
354
+ const offset = Number(offsetProp)
332
355
  const lines = (await Bun.file("./log.txt").text())
333
356
  .split("\n")
334
357
  .map(
@@ -340,7 +363,10 @@ const getLogsFromFile = async (level: keyof typeof levels, limit?: string) => {
340
363
  .filter((log) => log.level >= levels[level])
341
364
 
342
365
  const logFile = limit
343
- ? lines.slice(lines.length - 1 - Number(limit), lines.length - 1)
366
+ ? lines.slice(
367
+ lines.length - 1 - limit * (offset + 1),
368
+ lines.length - 1 - limit * offset,
369
+ )
344
370
  : lines
345
371
 
346
372
  return { logs: logFile }
@@ -10,8 +10,7 @@ export const Logs = ({ basePath }: { basePath: string }) => {
10
10
  const [dateTimeVisibility, setDateTimeVisibility] = useState<
11
11
  "hidden" | "timeOnly" | "visible"
12
12
  >("timeOnly")
13
- const { level, setLevel, logs, ws } = useLogStore()
14
- console.log("😅😅😅 ~ logs:", logs)
13
+ const { level, setLevel, logs, offset, setOffset, ws } = useLogStore()
15
14
 
16
15
  return (
17
16
  <>
@@ -26,50 +25,63 @@ export const Logs = ({ basePath }: { basePath: string }) => {
26
25
  View raw log.txt
27
26
  </a>
28
27
 
29
- <div className="flex flex-wrap gap-2">
30
- <div className="flex gap-2">
31
- <label htmlFor="dateTimeVisibility">Date/Time</label>
32
- <select
33
- className="border border-gray-300 rounded-md text-slate-800 px-2"
34
- id="dateTimeVisibility"
35
- onChange={(e) =>
36
- setDateTimeVisibility(
37
- e.target.value as typeof dateTimeVisibility,
38
- )
39
- }
40
- value={dateTimeVisibility}
41
- >
42
- <option value="hidden">Hidden</option>
43
- <option value="timeOnly">Time only</option>
44
- <option value="visible">Visible</option>
45
- </select>
28
+ <div className="flex flex-wrap gap-2 justify-between w-full items-end">
29
+ <div className="flex flex-wrap gap-2">
30
+ <div className="">
31
+ <label className="block mb-1" htmlFor="dateTimeVisibility">
32
+ Date/Time
33
+ </label>
34
+ <select
35
+ className="border border-gray-300 rounded-md text-slate-800 px-2"
36
+ id="dateTimeVisibility"
37
+ onChange={(e) =>
38
+ setDateTimeVisibility(
39
+ e.target.value as typeof dateTimeVisibility,
40
+ )
41
+ }
42
+ value={dateTimeVisibility}
43
+ >
44
+ <option value="hidden">Hidden</option>
45
+ <option value="timeOnly">Time only</option>
46
+ <option value="visible">Visible</option>
47
+ </select>
48
+ </div>
49
+ <div className="">
50
+ <label className="block mb-1" htmlFor="level">
51
+ Level
52
+ </label>
53
+ <select
54
+ className="border border-gray-300 rounded-md text-slate-800 px-2"
55
+ id="level"
56
+ onChange={(e) => setLevel(e.target.value as typeof level)}
57
+ value={level}
58
+ >
59
+ <option value="trace">Trace</option>
60
+ <option value="debug">Debug</option>
61
+ <option value="info">Info</option>
62
+ <option value="warn">Warn</option>
63
+ <option value="error">Error</option>
64
+ <option value="fatal">Fatal</option>
65
+ </select>
66
+ </div>
46
67
  </div>
68
+
47
69
  <div className="flex gap-2">
48
- <label htmlFor="dateTimeVisibility">Level</label>
49
- <select
50
- className="border border-gray-300 rounded-md text-slate-800 px-2"
51
- id="level"
52
- onChange={(e) => setLevel(e.target.value as typeof level)}
53
- value={level}
70
+ {offset > 0 && (
71
+ <button
72
+ className={buttonStyle}
73
+ onClick={() => setOffset((offset) => offset - 1)}
74
+ >
75
+ Previous
76
+ </button>
77
+ )}
78
+ <button
79
+ className={buttonStyle}
80
+ onClick={() => setOffset((offset) => offset + 1)}
54
81
  >
55
- <option value="trace">Trace</option>
56
- <option value="debug">Debug</option>
57
- <option value="info">Info</option>
58
- <option value="warn">Warn</option>
59
- <option value="error">Error</option>
60
- <option value="fatal">Fatal</option>
61
- </select>
82
+ Next
83
+ </button>
62
84
  </div>
63
- {/* <div className="flex gap-2">
64
- <label htmlFor="limit">Limit</label>
65
- <input
66
- className="border border-gray-300 rounded-md text-slate-800 px-2"
67
- id="limit"
68
- onChange={(e) => setLimit(Number(e.target.value))}
69
- size={8}
70
- value={limit}
71
- />
72
- </div> */}
73
85
  </div>
74
86
  </>
75
87
  )}
@@ -1,10 +1,10 @@
1
1
  import { useCallback, useEffect, useState } from "react"
2
- import { app } from "./api"
3
- import { useWS } from "./useWS"
4
- import { WSIndicator } from "./WSIndicator"
2
+ import { twMerge } from "tailwind-merge"
5
3
  import { AppSection } from "./AppSection"
4
+ import { WSIndicator } from "./WSIndicator"
5
+ import { app } from "./api"
6
6
  import { buttonStyle } from "./styles"
7
- import { twMerge } from "tailwind-merge"
7
+ import { useWS } from "./useWS"
8
8
 
9
9
  type ButtonAsyncProps = {
10
10
  onClick: () => Promise<{ error?: unknown }>
@@ -116,53 +116,3 @@ export function Terminal() {
116
116
  </AppSection>
117
117
  )
118
118
  }
119
-
120
- const RestartAppButton = () => {
121
- const [state, setState] = useState<"idle" | "loading" | "error" | "success">(
122
- "idle",
123
- )
124
-
125
- useEffect(() => {
126
- if (state !== "loading" && state !== "idle") {
127
- const timeout = setTimeout(() => setState("idle"), 2000)
128
-
129
- return () => {
130
- clearTimeout(timeout)
131
- }
132
- }
133
- }, [state])
134
-
135
- const onClick = async () => {
136
- if (state !== "idle") return
137
- setState("loading")
138
-
139
- const { data, error } = await app["restart-app"].get()
140
-
141
- if (error) {
142
- setState("error")
143
- return
144
- }
145
-
146
- setState("success")
147
- }
148
-
149
- return (
150
- <button
151
- className={twMerge(
152
- buttonStyle,
153
- state === "loading" && "bg-blue-500",
154
- state === "error" && "bg-red-500",
155
- state === "success" && "bg-green-500",
156
- )}
157
- onClick={onClick}
158
- >
159
- {state === "loading"
160
- ? "Restarting app..."
161
- : state === "error"
162
- ? "Error restarting app"
163
- : state === "success"
164
- ? "App restarted"
165
- : "Restart app"}
166
- </button>
167
- )
168
- }
@@ -15,22 +15,22 @@ let logStore = {
15
15
  export const getLogStore = ({
16
16
  level,
17
17
  limit,
18
+ offset,
18
19
  }: {
19
20
  level: keyof typeof levels
20
21
  limit: string
22
+ offset: string
21
23
  }) => ({
22
24
  subscribe: (listener: () => void) => {
23
25
  listeners = [...listeners, listener]
24
- const ws = app.logsws.subscribe({
25
- $query: { level, limit },
26
- })
26
+ const ws = app.logsws.subscribe({ $query: { level, limit, offset } })
27
27
  logStore = {
28
28
  logs: [],
29
29
  ws,
30
30
  }
31
31
  emitChange()
32
32
 
33
- ws.on("open", (event) => {
33
+ ws.on("open", () => {
34
34
  logStore = {
35
35
  logs: logStore.logs,
36
36
  ws: logStore.ws,
@@ -66,9 +66,15 @@ export const useLogStore = () => {
66
66
  const [level, setLevel] = useState<
67
67
  "trace" | "debug" | "info" | "warn" | "error" | "fatal"
68
68
  >("info")
69
+ const [offset, setOffset] = useState(0)
69
70
  const logStore = useMemo(
70
- () => getLogStore({ level, limit: limit.toString() }),
71
- [level, limit],
71
+ () =>
72
+ getLogStore({
73
+ level,
74
+ limit: limit.toString(),
75
+ offset: offset.toString(),
76
+ }),
77
+ [level, limit, offset],
72
78
  )
73
79
  const { logs, ws } = useSyncExternalStore(
74
80
  logStore.subscribe,
@@ -81,6 +87,8 @@ export const useLogStore = () => {
81
87
  level,
82
88
  setLevel,
83
89
  logs,
90
+ offset,
91
+ setOffset,
84
92
  ws,
85
93
  }
86
94
  }
package/tsconfig.json CHANGED
@@ -2,9 +2,9 @@
2
2
  "extends": "@typed-assistant/typescript-config/react.json",
3
3
  "compilerOptions": {
4
4
  "paths": {
5
- "@elysiajs/eden": ["./node_modules/@elysiajs/eden/"],
6
- },
5
+ "@elysiajs/eden": ["./node_modules/@elysiajs/eden/"]
6
+ }
7
7
  },
8
8
  "include": ["src"],
9
- "exclude": ["node_modules", "dist"],
9
+ "exclude": ["node_modules", "dist"]
10
10
  }