@sirenodeck/sirenodeck 0.2.10 → 0.4.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/config-ui/vite.config.ts +2 -0
- package/dist/main.mjs +1585 -807
- package/dist/{windows-CRWdUgCn.mjs → windows-BCvfQ3PA.mjs} +4 -4
- package/frontend/src/App.tsx +3 -0
- package/frontend/src/components/Deck.tsx +13 -2
- package/frontend/vite.config.ts +2 -0
- package/package.json +10 -1
- package/src/addon/api.ts +24 -1
- package/src/addon/data-directory.ts +52 -0
- package/src/api/protocol-internal.ts +5 -0
- package/src/builtin-addons/index.ts +0 -1
- package/src/builtin-addons/internal-settings/backend.ts +1 -1
- package/src/builtin-addons/internal-settings/buttons/brightness/common/frontend.tsx +14 -3
- package/src/builtin-addons/internal-settings/buttons/brightness-compact/frontend.tsx +6 -0
- package/src/builtin-addons/internal-settings/index.ts +15 -0
- package/src/builtin-addons/register-builtins.ts +0 -3
- package/src/cli/commands/addon-decks.ts +1 -0
- package/src/cli/commands/addon-setup-config.ts +85 -0
- package/src/cli/commands/addon-setup.ts +134 -0
- package/src/cli/commands/run.ts +57 -11
- package/src/cli/commands/service-manager.ts +3 -5
- package/src/cli/commands/start.ts +14 -81
- package/src/cli/commands/status-probes.ts +126 -0
- package/src/cli/commands/status.ts +166 -16
- package/src/cli/commands/stop.ts +4 -0
- package/src/cli/index.ts +2 -0
- package/src/config/environment.ts +44 -0
- package/src/config/loader.ts +17 -1
- package/src/config/schemas.ts +2 -1
- package/src/config/validation.ts +5 -1
- package/src/deck/addon-handler-bridge.ts +105 -6
- package/src/deck/addon-settings.ts +94 -0
- package/src/deck/deck-config.ts +1 -0
- package/src/deck/inject-config-ui-button.ts +25 -14
- package/src/deck/runtime/runtime.ts +175 -3
- package/src/deck/system-back-injection.ts +2 -0
- package/src/deck/system-buttons/registry.tsx +1 -0
- package/src/deck/system-buttons/types.ts +1 -0
- package/src/outputClient/real.ts +18 -1
- package/src/render/browser-renderer.ts +68 -12
- package/src/render/ws-bridge.ts +2 -0
- package/src/system/credentials/native.ts +74 -0
- package/src/system/credentials/store.ts +77 -0
- package/src/system/providers/notification/windows.ts +4 -4
- package/src/themes/default/sirenodeck.json +1 -0
- package/src/themes/light/sirenodeck.json +1 -0
- package/src/themes/manifest.ts +1 -0
- package/src/ui/primitives/Chip.tsx +1 -0
- package/src/ui/primitives/StatusIndicator.tsx +36 -0
- package/src/ui/primitives/index.ts +1 -0
- package/src/ui/surfaces/BinaryToggleSurface.tsx +52 -0
- package/src/ui/surfaces/LoadingSurface.tsx +34 -0
- package/src/ui/surfaces/index.ts +2 -0
- package/src/util/build-fingerprint.ts +32 -0
- package/src/util/daemon-control.ts +41 -0
- package/src/util/runtime-health.ts +57 -0
- package/src/util/runtime-identity.ts +25 -0
- package/src/vite/component-identity.ts +48 -0
- package/src/builtin-addons/brightness/README.md +0 -51
- package/src/builtin-addons/brightness/buttons/brightness/backend.ts +0 -13
- package/src/builtin-addons/brightness/buttons/brightness/config.ts +0 -20
- package/src/builtin-addons/brightness/buttons/brightness/frontend.tsx +0 -50
- package/src/builtin-addons/brightness/domain/macos.ts +0 -46
- package/src/builtin-addons/brightness/index.d.ts +0 -5
- package/src/builtin-addons/brightness/index.ts +0 -20
- package/src/builtin-addons/brightness/poller.ts +0 -27
- package/src/builtin-addons/brightness/sirenodeck.json +0 -6
- /package/src/builtin-addons/{brightness/providers → internal-settings/brightness-providers}/darwin.ts +0 -0
- /package/src/builtin-addons/{brightness/providers → internal-settings/brightness-providers}/index.ts +0 -0
- /package/src/builtin-addons/{brightness/providers → internal-settings/brightness-providers}/linux.ts +0 -0
- /package/src/builtin-addons/{brightness/providers → internal-settings/brightness-providers}/windows.ts +0 -0
|
@@ -10,6 +10,14 @@ import {
|
|
|
10
10
|
resolveDaemonPaths,
|
|
11
11
|
} from "@/util/daemon"
|
|
12
12
|
import { listDevices } from "@/device"
|
|
13
|
+
import { requestDaemonHealth, requestDaemonToken } from "@/util/daemon-control"
|
|
14
|
+
import {
|
|
15
|
+
probeBridgeInfo,
|
|
16
|
+
probeHttp,
|
|
17
|
+
probeWebIdentity,
|
|
18
|
+
type BuildIdentity,
|
|
19
|
+
} from "./status-probes"
|
|
20
|
+
import { runtimeIdentity } from "@/util/runtime-identity"
|
|
13
21
|
|
|
14
22
|
import { cancel, intro, log, outro } from "@/cli/prompt"
|
|
15
23
|
|
|
@@ -28,6 +36,39 @@ const formatUptime = (ms: number): string => {
|
|
|
28
36
|
return `${seconds}s`
|
|
29
37
|
}
|
|
30
38
|
|
|
39
|
+
const group = (title: string, details: readonly string[]): string =>
|
|
40
|
+
[
|
|
41
|
+
title,
|
|
42
|
+
...details.map((detail, i) => {
|
|
43
|
+
const separator = detail.indexOf(": ")
|
|
44
|
+
const formatted =
|
|
45
|
+
separator < 0
|
|
46
|
+
? detail
|
|
47
|
+
: `${detail.slice(0, separator + 2)}${colorize(detail.slice(separator + 2), 97)}`
|
|
48
|
+
return `${i === details.length - 1 ? "└─" : "├─"} ${formatted}`
|
|
49
|
+
}),
|
|
50
|
+
].join("\n")
|
|
51
|
+
|
|
52
|
+
const colorize = (value: string, color: number): string => {
|
|
53
|
+
const enabled =
|
|
54
|
+
process.env.NO_COLOR === undefined &&
|
|
55
|
+
process.env.FORCE_COLOR !== "0" &&
|
|
56
|
+
(process.stdout.isTTY ||
|
|
57
|
+
(process.env.FORCE_COLOR !== undefined && process.env.FORCE_COLOR !== ""))
|
|
58
|
+
return enabled
|
|
59
|
+
? `\u001b[${color}m${value.replaceAll("\u001b[39m", `\u001b[${color}m`)}\u001b[39m`
|
|
60
|
+
: value
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const coloredStatus = (value: string): string => {
|
|
64
|
+
const color = /^(running|ready|healthy|responding|same source)/i.test(value)
|
|
65
|
+
? 32
|
|
66
|
+
: /^(failed|unreachable|MISMATCH|stale)/i.test(value)
|
|
67
|
+
? 31
|
|
68
|
+
: 33
|
|
69
|
+
return colorize(value, color)
|
|
70
|
+
}
|
|
71
|
+
|
|
31
72
|
export const status = async ({ logger }: StatusOptions): Promise<void> => {
|
|
32
73
|
void logger // kept for callers that want pino logs out-of-band
|
|
33
74
|
|
|
@@ -37,6 +78,16 @@ export const status = async ({ logger }: StatusOptions): Promise<void> => {
|
|
|
37
78
|
if (pid === null) {
|
|
38
79
|
intro("sirenodeck status")
|
|
39
80
|
log.error("Daemon is not running")
|
|
81
|
+
for (const component of [
|
|
82
|
+
"Core",
|
|
83
|
+
"Bridge",
|
|
84
|
+
"Frontend",
|
|
85
|
+
"Config UI",
|
|
86
|
+
"Renderer",
|
|
87
|
+
"Device",
|
|
88
|
+
]) {
|
|
89
|
+
log.info(`${component}: unknown (daemon not running)`)
|
|
90
|
+
}
|
|
40
91
|
cancel("✗ No daemon process found")
|
|
41
92
|
return
|
|
42
93
|
}
|
|
@@ -50,11 +101,16 @@ export const status = async ({ logger }: StatusOptions): Promise<void> => {
|
|
|
50
101
|
|
|
51
102
|
intro("sirenodeck status")
|
|
52
103
|
|
|
104
|
+
let daemonDetails: string[] = []
|
|
53
105
|
if (alive) {
|
|
54
106
|
const startedAt = state?.startedAt ?? null
|
|
55
107
|
const uptime =
|
|
56
108
|
startedAt !== null ? formatUptime(Date.now() - startedAt) : "—"
|
|
57
|
-
|
|
109
|
+
daemonDetails = [
|
|
110
|
+
`PID: ${pid}`,
|
|
111
|
+
`Uptime: ${uptime}`,
|
|
112
|
+
`Children: ${childPids.length > 0 ? `${childPids.length} (${childPids.join(", ")})` : "none tracked"}`,
|
|
113
|
+
]
|
|
58
114
|
} else {
|
|
59
115
|
log.warn(`Status: stale pid file (pid ${pid} not alive)`)
|
|
60
116
|
}
|
|
@@ -64,7 +120,7 @@ export const status = async ({ logger }: StatusOptions): Promise<void> => {
|
|
|
64
120
|
typeof flags?.deviceModel === "string" ? flags.deviceModel : "mk2"
|
|
65
121
|
|
|
66
122
|
if (isEmulator) {
|
|
67
|
-
log.info(
|
|
123
|
+
log.info(group("Device", [`Mode: emulator`, `Model: ${deviceModel}`]))
|
|
68
124
|
} else {
|
|
69
125
|
let hardwareLabel = "—"
|
|
70
126
|
try {
|
|
@@ -77,33 +133,127 @@ export const status = async ({ logger }: StatusOptions): Promise<void> => {
|
|
|
77
133
|
// permission errors. Fall through to the "—" placeholder — status
|
|
78
134
|
// must not blow up if device detection is unavailable.
|
|
79
135
|
}
|
|
80
|
-
log.info(
|
|
136
|
+
log.info(group("Device", [`Mode: hardware`, `Model: ${hardwareLabel}`]))
|
|
81
137
|
}
|
|
82
138
|
|
|
83
139
|
const remoteOn = state?.remote === true || flags?.remote === true
|
|
84
|
-
log.info(`Remote: ${remoteOn ? "on" : "off"}`)
|
|
85
|
-
|
|
86
|
-
log.info(`Config: ${configPath ?? "—"}`)
|
|
87
|
-
|
|
88
140
|
const theme = state?.theme ?? "default"
|
|
89
|
-
log.info(
|
|
141
|
+
log.info(
|
|
142
|
+
group("Configuration", [
|
|
143
|
+
`Config: ${configPath ?? "—"}`,
|
|
144
|
+
`Theme: ${theme}`,
|
|
145
|
+
`Remote: ${remoteOn ? "on" : "off"}`,
|
|
146
|
+
]),
|
|
147
|
+
)
|
|
90
148
|
|
|
91
|
-
if (childPids.length > 0) {
|
|
149
|
+
if (!alive && childPids.length > 0) {
|
|
92
150
|
log.info(`Children: ${childPids.length} (${childPids.join(", ")})`)
|
|
93
|
-
} else {
|
|
151
|
+
} else if (!alive) {
|
|
94
152
|
log.info("Children: none tracked")
|
|
95
153
|
}
|
|
96
154
|
|
|
97
155
|
if (alive && state !== null) {
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
156
|
+
const [
|
|
157
|
+
token,
|
|
158
|
+
health,
|
|
159
|
+
frontend,
|
|
160
|
+
configUi,
|
|
161
|
+
frontendIdentity,
|
|
162
|
+
configUiIdentity,
|
|
163
|
+
] = await Promise.all([
|
|
164
|
+
requestDaemonToken(paths),
|
|
165
|
+
requestDaemonHealth(paths),
|
|
166
|
+
probeHttp(state.frontendUrl),
|
|
167
|
+
state.configUiUrl
|
|
168
|
+
? probeHttp(state.configUiUrl)
|
|
169
|
+
: Promise.resolve("unknown" as const),
|
|
170
|
+
probeWebIdentity(state.frontendUrl, "frontend"),
|
|
171
|
+
state.configUiUrl
|
|
172
|
+
? probeWebIdentity(state.configUiUrl, "config-ui")
|
|
173
|
+
: Promise.resolve(null),
|
|
174
|
+
])
|
|
175
|
+
const bridge = await probeBridgeInfo(state.wsUrl, token)
|
|
176
|
+
const identityLabel = (identity: BuildIdentity | null): string => {
|
|
177
|
+
if (!identity) return "version/build unknown"
|
|
178
|
+
const matches =
|
|
179
|
+
identity.buildId && health?.identity?.buildId
|
|
180
|
+
? identity.buildId === health.identity.buildId &&
|
|
181
|
+
identity.version === health.identity.version
|
|
182
|
+
? "same source as daemon"
|
|
183
|
+
: "MISMATCH"
|
|
184
|
+
: "comparison unknown"
|
|
185
|
+
return `${identity.version} build ${identity.buildId?.slice(0, 12) ?? "unknown"} (${coloredStatus(matches)})`
|
|
186
|
+
}
|
|
187
|
+
log.info(
|
|
188
|
+
group(`Daemon: ${coloredStatus("running")}`, [
|
|
189
|
+
...daemonDetails,
|
|
190
|
+
`Version: ${identityLabel(health?.identity ?? null)}`,
|
|
191
|
+
]),
|
|
192
|
+
)
|
|
193
|
+
log.info(group("CLI", [`Version: ${identityLabel(runtimeIdentity)}`]))
|
|
194
|
+
log.info(
|
|
195
|
+
group(`Core: ${coloredStatus(health?.core ?? "unknown")}`, [
|
|
196
|
+
`Version: ${identityLabel(health?.identity ?? null)}`,
|
|
197
|
+
]),
|
|
198
|
+
)
|
|
199
|
+
log.info(
|
|
200
|
+
group(`Bridge: ${coloredStatus(bridge.status)}`, [
|
|
201
|
+
`Check: authenticated WebSocket handshake`,
|
|
202
|
+
`URL: ${state.wsUrl}`,
|
|
203
|
+
`Version: ${identityLabel(bridge.identity)}`,
|
|
204
|
+
]),
|
|
205
|
+
)
|
|
206
|
+
log.info(
|
|
207
|
+
group(`Frontend: ${coloredStatus(frontend)}`, [
|
|
208
|
+
`Check: HTTP`,
|
|
209
|
+
`URL: ${state.frontendUrl}`,
|
|
210
|
+
`Version: ${identityLabel(frontendIdentity)}`,
|
|
211
|
+
]),
|
|
212
|
+
)
|
|
213
|
+
log.info(
|
|
214
|
+
group(`Config UI: ${coloredStatus(configUi)}`, [
|
|
215
|
+
`Check: HTTP`,
|
|
216
|
+
...(state.configUiUrl ? [`URL: ${state.configUiUrl}`] : []),
|
|
217
|
+
`Version: ${identityLabel(configUiIdentity)}`,
|
|
218
|
+
]),
|
|
219
|
+
)
|
|
220
|
+
if (isEmulator) {
|
|
221
|
+
log.info("Renderer: not applicable (emulator mode)")
|
|
222
|
+
} else {
|
|
223
|
+
const rendererState =
|
|
224
|
+
health?.renderer?.state === "healthy" &&
|
|
225
|
+
health.renderer.lastFrameAt !== null &&
|
|
226
|
+
Date.now() - health.renderer.lastFrameAt > 10_000
|
|
227
|
+
? "degraded (no recent frame)"
|
|
228
|
+
: (health?.renderer?.state ?? "unknown")
|
|
229
|
+
const lastFrame = health?.renderer?.lastFrameAt
|
|
230
|
+
? new Date(health.renderer.lastFrameAt).toISOString()
|
|
231
|
+
: "unknown"
|
|
232
|
+
log.info(
|
|
233
|
+
group(`Renderer: ${coloredStatus(rendererState)}`, [
|
|
234
|
+
`Last frame: ${lastFrame}`,
|
|
235
|
+
`Version: ${identityLabel(health?.identity ?? null)}`,
|
|
236
|
+
]),
|
|
237
|
+
)
|
|
102
238
|
}
|
|
103
|
-
log.info(`Bridge URL : ${state.wsUrl}`)
|
|
104
239
|
outro("✓ Status snapshot")
|
|
105
240
|
} else {
|
|
106
|
-
|
|
241
|
+
if (alive)
|
|
242
|
+
log.info(group(`Daemon: ${coloredStatus("running")}`, daemonDetails))
|
|
243
|
+
for (const component of [
|
|
244
|
+
"Core",
|
|
245
|
+
"Bridge",
|
|
246
|
+
"Frontend",
|
|
247
|
+
"Config UI",
|
|
248
|
+
"Renderer",
|
|
249
|
+
]) {
|
|
250
|
+
log.info(`${component}: unknown (runtime state unavailable)`)
|
|
251
|
+
}
|
|
252
|
+
cancel(
|
|
253
|
+
alive
|
|
254
|
+
? "✗ Daemon is running but runtime state is unavailable"
|
|
255
|
+
: "✗ Stale pid file — daemon process is not running",
|
|
256
|
+
)
|
|
107
257
|
}
|
|
108
258
|
}
|
|
109
259
|
|
package/src/cli/commands/stop.ts
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
resolveDaemonPaths,
|
|
14
14
|
} from "@/util/daemon"
|
|
15
15
|
import { removeDaemonControl } from "@/util/daemon-control"
|
|
16
|
+
import { invokeManager, isUnitInstalled } from "./service-manager"
|
|
16
17
|
import {
|
|
17
18
|
readDaemonEventsFromSnapshot,
|
|
18
19
|
snapshotDaemonLog,
|
|
@@ -61,6 +62,9 @@ const killGracefully = async (
|
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
export const stop = async ({ logger }: StopOptions): Promise<void> => {
|
|
65
|
+
if (isUnitInstalled()) {
|
|
66
|
+
await invokeManager({ action: "stop", logger })
|
|
67
|
+
}
|
|
64
68
|
const pid = readPid()
|
|
65
69
|
if (pid === null) {
|
|
66
70
|
logger.info("stop: no running daemon found")
|
package/src/cli/index.ts
CHANGED
|
@@ -36,6 +36,7 @@ import {
|
|
|
36
36
|
} from "@/util/daemon"
|
|
37
37
|
import { cancel, intro, log } from "./prompt"
|
|
38
38
|
import { skillsCommand } from "./commands/skills"
|
|
39
|
+
import { addonSetupCommand } from "./commands/addon-setup"
|
|
39
40
|
|
|
40
41
|
export interface GlobalOptions {
|
|
41
42
|
verbose?: boolean
|
|
@@ -360,6 +361,7 @@ export const buildCli = async (): Promise<{
|
|
|
360
361
|
logsCommand as CommandModule<object, GlobalOptions>,
|
|
361
362
|
systemRequirementsCommand as CommandModule<object, GlobalOptions>,
|
|
362
363
|
installCommand as CommandModule<object, GlobalOptions>,
|
|
364
|
+
addonSetupCommand as CommandModule<object, GlobalOptions>,
|
|
363
365
|
skillsCommand as CommandModule<object, GlobalOptions>,
|
|
364
366
|
],
|
|
365
367
|
packageName: PACKAGE_NAME,
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export class MissingEnvironmentVariableError extends Error {
|
|
2
|
+
constructor(
|
|
3
|
+
readonly variable: string,
|
|
4
|
+
readonly configPath: string,
|
|
5
|
+
) {
|
|
6
|
+
super(
|
|
7
|
+
`Environment variable ${variable} is not set (at ${configPath || "<root>"})`,
|
|
8
|
+
)
|
|
9
|
+
this.name = "MissingEnvironmentVariableError"
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Resolve placeholders in values, never mapping keys or YAML source text. */
|
|
14
|
+
export const resolveEnvironmentVariables = (
|
|
15
|
+
value: unknown,
|
|
16
|
+
env: NodeJS.ProcessEnv = process.env,
|
|
17
|
+
path = "",
|
|
18
|
+
): unknown => {
|
|
19
|
+
if (typeof value === "string") {
|
|
20
|
+
return value.replace(
|
|
21
|
+
/\$\{env:([A-Za-z_][A-Za-z0-9_]*)\}/g,
|
|
22
|
+
(_match, name: string) => {
|
|
23
|
+
const resolved = Object.hasOwn(env, name) ? env[name] : undefined
|
|
24
|
+
if (resolved === undefined)
|
|
25
|
+
throw new MissingEnvironmentVariableError(name, path)
|
|
26
|
+
return resolved
|
|
27
|
+
},
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
if (Array.isArray(value)) {
|
|
31
|
+
return value.map((item, index) =>
|
|
32
|
+
resolveEnvironmentVariables(item, env, `${path}[${index}]`),
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
if (typeof value === "object" && value !== null) {
|
|
36
|
+
return Object.fromEntries(
|
|
37
|
+
Object.entries(value).map(([key, item]) => [
|
|
38
|
+
key,
|
|
39
|
+
resolveEnvironmentVariables(item, env, path ? `${path}.${key}` : key),
|
|
40
|
+
]),
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
return value
|
|
44
|
+
}
|
package/src/config/loader.ts
CHANGED
|
@@ -8,6 +8,10 @@ import { getOriginalCwd } from "@/cli/cwd"
|
|
|
8
8
|
import { IncludeResolutionError, resolveIncludes } from "./include-resolver"
|
|
9
9
|
import { RawConfigSchema, type RawConfig } from "./schemas"
|
|
10
10
|
import { expandButtonReferences } from "./reference-expander"
|
|
11
|
+
import {
|
|
12
|
+
MissingEnvironmentVariableError,
|
|
13
|
+
resolveEnvironmentVariables,
|
|
14
|
+
} from "./environment"
|
|
11
15
|
|
|
12
16
|
export interface LoadConfigOptions {
|
|
13
17
|
configPath: string
|
|
@@ -169,7 +173,19 @@ export const loadConfig = ({
|
|
|
169
173
|
}: LoadConfigOptions): LoadConfigResult => {
|
|
170
174
|
const configDir = dirname(configPath)
|
|
171
175
|
const raw = loadConfigFile(configPath)
|
|
172
|
-
|
|
176
|
+
let expanded: unknown
|
|
177
|
+
try {
|
|
178
|
+
expanded = resolveEnvironmentVariables(
|
|
179
|
+
expandButtonReferences(raw, configDir),
|
|
180
|
+
)
|
|
181
|
+
} catch (err) {
|
|
182
|
+
if (err instanceof MissingEnvironmentVariableError) {
|
|
183
|
+
throw new ConfigLoadError(err.message, [
|
|
184
|
+
{ message: err.message, path: err.configPath },
|
|
185
|
+
])
|
|
186
|
+
}
|
|
187
|
+
throw err
|
|
188
|
+
}
|
|
173
189
|
const result = RawConfigSchema.safeParse(expanded)
|
|
174
190
|
if (!result.success) {
|
|
175
191
|
// ponytail: recurse into unionErrors so the user sees the actual
|
package/src/config/schemas.ts
CHANGED
|
@@ -159,12 +159,13 @@ export const AddonDeckDefaultsSchema = z
|
|
|
159
159
|
* Phase 11: addon-config block under `addons[i]`. Hosts three shape variants:
|
|
160
160
|
* - `defaults:` addon-wide deck defaults (applied before per-deck overrides)
|
|
161
161
|
* - `decks:` record keyed by addon deck id, with per-deck overrides
|
|
162
|
-
* - addon-
|
|
162
|
+
* - `service:` addon-global backend settings (never merged into deck config)
|
|
163
163
|
*/
|
|
164
164
|
export const AddonConfigSchema = z
|
|
165
165
|
.object({
|
|
166
166
|
defaults: AddonDeckDefaultsSchema.optional(),
|
|
167
167
|
decks: z.record(z.string(), AddonDeckOverrideSchema).optional(),
|
|
168
|
+
service: z.record(z.string(), z.unknown()).optional(),
|
|
168
169
|
})
|
|
169
170
|
.strict()
|
|
170
171
|
|
package/src/config/validation.ts
CHANGED
|
@@ -99,6 +99,7 @@ export const validateButton = (
|
|
|
99
99
|
path: string,
|
|
100
100
|
deckId?: string,
|
|
101
101
|
position?: number,
|
|
102
|
+
allowInternal = false,
|
|
102
103
|
): ButtonValidationResult => {
|
|
103
104
|
const base = { deckId, position }
|
|
104
105
|
const issues: FullValidationIssue[] = []
|
|
@@ -119,7 +120,10 @@ export const validateButton = (
|
|
|
119
120
|
return { issues, schemaIssues: [] }
|
|
120
121
|
}
|
|
121
122
|
const def = registry.getButtonType(btn.type)!
|
|
122
|
-
if (
|
|
123
|
+
if (
|
|
124
|
+
isSystemButtonType(btn.type) ||
|
|
125
|
+
(!allowInternal && def.def.service.internal === true)
|
|
126
|
+
) {
|
|
123
127
|
issues.push({
|
|
124
128
|
level: "error",
|
|
125
129
|
path: `${path}.type`,
|
|
@@ -19,6 +19,12 @@ import type { Methods } from "@/deck/methods"
|
|
|
19
19
|
import type { Runtime, RuntimeDeck } from "@/deck/runtime"
|
|
20
20
|
import type { StatePublisher } from "@/render/state-publisher"
|
|
21
21
|
import type { WsBridge } from "@/render/ws-bridge"
|
|
22
|
+
import {
|
|
23
|
+
scopeCredentials,
|
|
24
|
+
type CredentialBackend,
|
|
25
|
+
} from "@/system/credentials/store"
|
|
26
|
+
import { createNativeCredentialBackend } from "@/system/credentials/native"
|
|
27
|
+
import { createAddonDataDirectory } from "@/addon/data-directory"
|
|
22
28
|
|
|
23
29
|
export interface BridgeAddonServicesParams {
|
|
24
30
|
readonly runtime: Runtime
|
|
@@ -36,6 +42,11 @@ export interface BridgeAddonServicesParams {
|
|
|
36
42
|
readonly statePublisher: Pick<StatePublisher, "registerChannel">
|
|
37
43
|
readonly bridge: Pick<WsBridge, "broadcast" | "registerCacheablePoller">
|
|
38
44
|
readonly methods: Methods
|
|
45
|
+
/** Backend-only configuration keyed by the loaded addon manifest name. */
|
|
46
|
+
readonly addonServiceConfigs?: ReadonlyMap<string, unknown>
|
|
47
|
+
readonly credentialBackend?: CredentialBackend
|
|
48
|
+
/** Override the host application-data root, primarily for tests. */
|
|
49
|
+
readonly addonDataRoot?: string
|
|
39
50
|
/** Optional host callback that re-materializes addon decks (dynamic decks). */
|
|
40
51
|
readonly requestDeckRebuild?: () => void
|
|
41
52
|
}
|
|
@@ -106,6 +117,8 @@ export const bridgeAddonServices = async (
|
|
|
106
117
|
statePublisher,
|
|
107
118
|
bridge,
|
|
108
119
|
methods,
|
|
120
|
+
addonServiceConfigs,
|
|
121
|
+
credentialBackend = createNativeCredentialBackend(),
|
|
109
122
|
requestDeckRebuild,
|
|
110
123
|
} = params
|
|
111
124
|
const logger = params.logger.child({ component: "addon-handler" })
|
|
@@ -129,6 +142,7 @@ export const bridgeAddonServices = async (
|
|
|
129
142
|
|
|
130
143
|
const addonModules = new Map<string, AddonModule>()
|
|
131
144
|
const addonGlobalServices = new Map<string, AddonGlobalService>()
|
|
145
|
+
const addonDataDirectories = new Map<string, () => Promise<string>>()
|
|
132
146
|
const addonMethods = new Map<
|
|
133
147
|
string,
|
|
134
148
|
Readonly<Record<string, AddonServiceMethod>>
|
|
@@ -179,6 +193,16 @@ export const bridgeAddonServices = async (
|
|
|
179
193
|
}
|
|
180
194
|
|
|
181
195
|
for (const [addonName, globalService] of addonGlobalServices) {
|
|
196
|
+
const getDataDirectory = createAddonDataDirectory(
|
|
197
|
+
addonName,
|
|
198
|
+
params.addonDataRoot,
|
|
199
|
+
)
|
|
200
|
+
addonDataDirectories.set(addonName, getDataDirectory)
|
|
201
|
+
const interruptions = new Set<() => void>()
|
|
202
|
+
abortController.signal.addEventListener("abort", () => {
|
|
203
|
+
for (const release of interruptions) release()
|
|
204
|
+
interruptions.clear()
|
|
205
|
+
})
|
|
182
206
|
const primaryChannel = globalService.pollers?.[0]?.channel
|
|
183
207
|
const pollersById = new Map<string, AddonGlobalPoller>()
|
|
184
208
|
for (const poller of globalService.pollers ?? []) {
|
|
@@ -186,6 +210,37 @@ export const bridgeAddonServices = async (
|
|
|
186
210
|
}
|
|
187
211
|
|
|
188
212
|
const ctx: AddonServiceContext = {
|
|
213
|
+
getDataDirectory,
|
|
214
|
+
interruptDeck: (deckId, options) => {
|
|
215
|
+
if (abortController.signal.aborted) return null
|
|
216
|
+
const release = runtime.interruptDeck(deckId, options)
|
|
217
|
+
if (release === null) return null
|
|
218
|
+
const ownedRelease = () => {
|
|
219
|
+
interruptions.delete(ownedRelease)
|
|
220
|
+
release()
|
|
221
|
+
}
|
|
222
|
+
interruptions.add(ownedRelease)
|
|
223
|
+
return ownedRelease
|
|
224
|
+
},
|
|
225
|
+
showModal: (deckId, options) => {
|
|
226
|
+
if (abortController.signal.aborted) return null
|
|
227
|
+
let ownedRelease: () => void
|
|
228
|
+
const release = runtime.showModal(deckId, {
|
|
229
|
+
onOk: async () => {
|
|
230
|
+
interruptions.delete(ownedRelease)
|
|
231
|
+
if (abortController.signal.aborted) return
|
|
232
|
+
await options?.onOk?.()
|
|
233
|
+
},
|
|
234
|
+
})
|
|
235
|
+
if (release === null) return null
|
|
236
|
+
ownedRelease = () => {
|
|
237
|
+
interruptions.delete(ownedRelease)
|
|
238
|
+
release()
|
|
239
|
+
}
|
|
240
|
+
interruptions.add(ownedRelease)
|
|
241
|
+
return ownedRelease
|
|
242
|
+
},
|
|
243
|
+
credentials: scopeCredentials(credentialBackend, addonName),
|
|
189
244
|
publish: (data: unknown) => {
|
|
190
245
|
if (primaryChannel !== undefined) {
|
|
191
246
|
bridge.broadcast({
|
|
@@ -229,7 +284,10 @@ export const bridgeAddonServices = async (
|
|
|
229
284
|
}
|
|
230
285
|
|
|
231
286
|
try {
|
|
232
|
-
const result = globalService.onLoad?.(
|
|
287
|
+
const result = globalService.onLoad?.(
|
|
288
|
+
ctx,
|
|
289
|
+
addonServiceConfigs?.get(addonName),
|
|
290
|
+
)
|
|
233
291
|
if (result instanceof Promise) {
|
|
234
292
|
result.catch((err) => {
|
|
235
293
|
logger.error({ addonName, err }, `addon onLoad failed`)
|
|
@@ -278,6 +336,7 @@ export const bridgeAddonServices = async (
|
|
|
278
336
|
buttonAbort: AbortController
|
|
279
337
|
buttonService: AddonButtonService
|
|
280
338
|
wrappedCtx: AddonButtonServiceContext<unknown>
|
|
339
|
+
activate: () => void
|
|
281
340
|
}>
|
|
282
341
|
>()
|
|
283
342
|
const mountedButtonSignatures = new Map<string, string>()
|
|
@@ -381,18 +440,40 @@ export const bridgeAddonServices = async (
|
|
|
381
440
|
store,
|
|
382
441
|
}
|
|
383
442
|
|
|
384
|
-
|
|
443
|
+
let buttonAbort = new AbortController()
|
|
385
444
|
abortController.signal.addEventListener("abort", () =>
|
|
386
445
|
buttonAbort.abort(),
|
|
387
446
|
)
|
|
388
447
|
|
|
389
|
-
|
|
448
|
+
let wrappedCtx = {
|
|
390
449
|
...buttonCtx,
|
|
391
450
|
signal: buttonAbort.signal,
|
|
392
451
|
}
|
|
393
452
|
|
|
453
|
+
const entry = {
|
|
454
|
+
handlerId,
|
|
455
|
+
buttonAbort,
|
|
456
|
+
buttonService,
|
|
457
|
+
wrappedCtx,
|
|
458
|
+
activate: () => {
|
|
459
|
+
if (!buttonAbort.signal.aborted || abortController.signal.aborted)
|
|
460
|
+
return
|
|
461
|
+
buttonAbort = new AbortController()
|
|
462
|
+
wrappedCtx = { ...buttonCtx, signal: buttonAbort.signal }
|
|
463
|
+
entry.buttonAbort = buttonAbort
|
|
464
|
+
entry.wrappedCtx = wrappedCtx
|
|
465
|
+
try {
|
|
466
|
+
buttonService.onMount?.(wrappedCtx)
|
|
467
|
+
} catch (err) {
|
|
468
|
+
logger.error(
|
|
469
|
+
{ addonName, buttonType, err },
|
|
470
|
+
`addon onMount threw`,
|
|
471
|
+
)
|
|
472
|
+
}
|
|
473
|
+
},
|
|
474
|
+
}
|
|
394
475
|
const existing = deckButtonCleanup.get(deck.id) ?? []
|
|
395
|
-
existing.push(
|
|
476
|
+
existing.push(entry)
|
|
396
477
|
deckButtonCleanup.set(deck.id, existing)
|
|
397
478
|
|
|
398
479
|
try {
|
|
@@ -509,6 +590,7 @@ export const bridgeAddonServices = async (
|
|
|
509
590
|
const tracked = deckButtonCleanup.get(deckId)
|
|
510
591
|
if (tracked === undefined) return
|
|
511
592
|
for (const { buttonAbort, buttonService, wrappedCtx } of tracked) {
|
|
593
|
+
if (buttonAbort.signal.aborted) continue
|
|
512
594
|
try {
|
|
513
595
|
buttonService.onUnmount?.(wrappedCtx)
|
|
514
596
|
} catch (err) {
|
|
@@ -519,18 +601,33 @@ export const bridgeAddonServices = async (
|
|
|
519
601
|
},
|
|
520
602
|
)
|
|
521
603
|
trackedCleanup.push(unsubscribeDeckInactive)
|
|
604
|
+
trackedCleanup.push(
|
|
605
|
+
pubSub.subscribe("runtime:activeDeck", (payload: unknown) => {
|
|
606
|
+
if (
|
|
607
|
+
typeof payload !== "object" ||
|
|
608
|
+
payload === null ||
|
|
609
|
+
!("deckId" in payload)
|
|
610
|
+
)
|
|
611
|
+
return
|
|
612
|
+
for (const entry of deckButtonCleanup.get(String(payload.deckId)) ?? []) {
|
|
613
|
+
entry.activate()
|
|
614
|
+
}
|
|
615
|
+
}),
|
|
616
|
+
)
|
|
522
617
|
|
|
523
618
|
abortController.signal.addEventListener("abort", () => {
|
|
524
619
|
for (const [addonName, globalService] of addonGlobalServices) {
|
|
525
620
|
try {
|
|
526
621
|
const ctx: AddonServiceContext = {
|
|
622
|
+
getDataDirectory: addonDataDirectories.get(addonName),
|
|
623
|
+
credentials: scopeCredentials(credentialBackend, addonName),
|
|
527
624
|
publish: () => {},
|
|
528
625
|
poll: async () => {},
|
|
529
626
|
signal: abortController.signal,
|
|
530
627
|
executor,
|
|
531
628
|
notify: methods.notify,
|
|
532
629
|
}
|
|
533
|
-
globalService.onUnload?.(ctx)
|
|
630
|
+
globalService.onUnload?.(ctx, addonServiceConfigs?.get(addonName))
|
|
534
631
|
} catch (err) {
|
|
535
632
|
logger.error({ addonName, err }, `addon onUnload failed`)
|
|
536
633
|
}
|
|
@@ -546,13 +643,15 @@ export const bridgeAddonServices = async (
|
|
|
546
643
|
for (const [addonName, globalService] of addonGlobalServices) {
|
|
547
644
|
try {
|
|
548
645
|
const ctx: AddonServiceContext = {
|
|
646
|
+
getDataDirectory: addonDataDirectories.get(addonName),
|
|
647
|
+
credentials: scopeCredentials(credentialBackend, addonName),
|
|
549
648
|
publish: () => {},
|
|
550
649
|
poll: async () => {},
|
|
551
650
|
signal: abortController.signal,
|
|
552
651
|
executor,
|
|
553
652
|
notify: methods.notify,
|
|
554
653
|
}
|
|
555
|
-
globalService.onUnload?.(ctx)
|
|
654
|
+
globalService.onUnload?.(ctx, addonServiceConfigs?.get(addonName))
|
|
556
655
|
} catch (err) {
|
|
557
656
|
logger.error({ addonName, err }, `addon onUnload failed`)
|
|
558
657
|
}
|