my-durable 0.0.40 → 0.0.42
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/apps/dpi-backend/src/backup-cli.ts +220 -0
- package/apps/dpi-backend/src/backup.ts +523 -0
- package/apps/dpi-backend/src/doctor.ts +19 -1
- package/apps/dpi-backend/src/env-vars.ts +234 -0
- package/apps/dpi-backend/src/main.ts +1 -0
- package/apps/dpi-backend/src/notify-cli.ts +211 -0
- package/apps/dpi-backend/src/notify-sinks.ts +947 -0
- package/apps/dpi-backend/src/projects.ts +18 -1
- package/apps/dpi-backend/src/routes.ts +29 -1
- package/apps/dpi-backend/src/store.ts +170 -9
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/index-DaurAPEn.css +1 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/index-o6Rn26ft.js +81 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/index.html +2 -2
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/EnvPanel.vue +268 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/Inspector.vue +8 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/NewSessionDialog.vue +37 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/NotifyPanel.vue +292 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/ProjectBar.vue +41 -1
- package/apps/dpi-sdk/src/api.ts +79 -1
- package/apps/dpi-sdk/src/client.ts +32 -0
- package/apps/dpi-sdk/src/protocol/rest-routes.ts +9 -0
- package/bin/dpi.mjs +15 -0
- package/docs/host-project-checklist.md +6 -6
- package/package.json +1 -1
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/index-DMJMesxP.css +0 -1
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/index-jDhVa5sg.js +0 -81
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
<meta name="referrer" content="no-referrer" />
|
|
8
8
|
<link rel="icon" type="image/svg+xml" href="/icons/durable-pi.svg" />
|
|
9
9
|
<title>Durable Pi | Network</title>
|
|
10
|
-
<script type="module" crossorigin src="/assets/index-
|
|
11
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
10
|
+
<script type="module" crossorigin src="/assets/index-o6Rn26ft.js"></script>
|
|
11
|
+
<link rel="stylesheet" crossorigin href="/assets/index-DaurAPEn.css">
|
|
12
12
|
</head>
|
|
13
13
|
<body>
|
|
14
14
|
<div id="app"></div>
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// Env-var management (Wave 2): the DEVICE's own env file — the one loadConfig
|
|
3
|
+
// reads at boot. orca edits a host's default agent environment the same way.
|
|
4
|
+
//
|
|
5
|
+
// Guardrails from the backend, mirrored here: managed keys and process-only
|
|
6
|
+
// vars are read-only, secret values arrive masked and stay masked. Every
|
|
7
|
+
// change needs a daemon restart to apply — the panel says so, it does not
|
|
8
|
+
// pretend otherwise.
|
|
9
|
+
import { computed, ref, watch } from "vue";
|
|
10
|
+
import { RefreshCw, Plus, Pencil, Trash2, FileCog } from "lucide-vue-next";
|
|
11
|
+
import type { EnvFileView, EnvVarView } from "@sdk/api";
|
|
12
|
+
import { deviceClient, message } from "../client/hub";
|
|
13
|
+
import { notify, selected, ui } from "../client/store";
|
|
14
|
+
|
|
15
|
+
const view = ref<EnvFileView | null>(null);
|
|
16
|
+
const loading = ref(false);
|
|
17
|
+
const error = ref("");
|
|
18
|
+
const busy = ref("");
|
|
19
|
+
const deviceId = computed(() => selected.value?.deviceId);
|
|
20
|
+
const client = () => deviceClient(deviceId.value ?? "");
|
|
21
|
+
|
|
22
|
+
const adding = ref(false);
|
|
23
|
+
const draft = ref({ key: "", value: "" });
|
|
24
|
+
|
|
25
|
+
async function load() {
|
|
26
|
+
if (!deviceId.value) return void (view.value = null);
|
|
27
|
+
loading.value = true;
|
|
28
|
+
error.value = "";
|
|
29
|
+
try {
|
|
30
|
+
view.value = await client().envView();
|
|
31
|
+
} catch (e) {
|
|
32
|
+
const text = message(e);
|
|
33
|
+
error.value =
|
|
34
|
+
(e as { code?: string }).code === "not_found" || /allowlist/i.test(text)
|
|
35
|
+
? "This device runs an older build: update it (`dpi update`) to edit env vars."
|
|
36
|
+
: text.slice(0, 160);
|
|
37
|
+
} finally {
|
|
38
|
+
loading.value = false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
watch(deviceId, load, { immediate: true });
|
|
42
|
+
|
|
43
|
+
const editable = (v: EnvVarView) => v.source === "file" && !v.managed;
|
|
44
|
+
|
|
45
|
+
async function add() {
|
|
46
|
+
const key = draft.value.key.trim().toUpperCase();
|
|
47
|
+
if (!key || !draft.value.value) return;
|
|
48
|
+
busy.value = "new";
|
|
49
|
+
try {
|
|
50
|
+
await client().setEnvVar(key, draft.value.value);
|
|
51
|
+
adding.value = false;
|
|
52
|
+
draft.value = { key: "", value: "" };
|
|
53
|
+
await load();
|
|
54
|
+
notify(`${key} saved — restart the device to apply it.`);
|
|
55
|
+
} catch (e) {
|
|
56
|
+
notify(message(e).slice(0, 160));
|
|
57
|
+
} finally {
|
|
58
|
+
busy.value = "";
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function edit(v: EnvVarView) {
|
|
63
|
+
ui.dialog = {
|
|
64
|
+
kind: "prompt",
|
|
65
|
+
title: `Set ${v.key}`,
|
|
66
|
+
label: "Value",
|
|
67
|
+
hint: v.secret
|
|
68
|
+
? "The current value is secret and stays masked. Type a new value to replace it."
|
|
69
|
+
: "Single line. Applies after the next device restart.",
|
|
70
|
+
value: v.secret ? "" : v.masked,
|
|
71
|
+
placeholder: v.secret ? v.masked : "",
|
|
72
|
+
submit: "Save value",
|
|
73
|
+
run: async (value) => {
|
|
74
|
+
if (!value) throw Error("A value is required");
|
|
75
|
+
await client().setEnvVar(v.key, value);
|
|
76
|
+
await load();
|
|
77
|
+
notify(`${v.key} saved — restart the device to apply it.`);
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function remove(v: EnvVarView) {
|
|
83
|
+
ui.dialog = {
|
|
84
|
+
kind: "prompt",
|
|
85
|
+
title: `Remove ${v.key} from the env file?`,
|
|
86
|
+
hint: "The line is deleted from the file. Restart the device to apply it.",
|
|
87
|
+
submit: "Remove",
|
|
88
|
+
danger: true,
|
|
89
|
+
run: async () => {
|
|
90
|
+
await client().removeEnvVar(v.key);
|
|
91
|
+
await load();
|
|
92
|
+
notify(`${v.key} removed — restart the device to apply it.`);
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
</script>
|
|
97
|
+
|
|
98
|
+
<template>
|
|
99
|
+
<section class="env-panel" aria-label="Device environment">
|
|
100
|
+
<header class="panel-heading">
|
|
101
|
+
<span><FileCog :size="16" />ENV</span>
|
|
102
|
+
<button class="icon-button" :disabled="loading || !deviceId" aria-label="Refresh env" title="Refresh" @click="load">
|
|
103
|
+
<RefreshCw :size="15" :class="{ spin: loading }" />
|
|
104
|
+
</button>
|
|
105
|
+
<button
|
|
106
|
+
class="icon-button"
|
|
107
|
+
:disabled="!deviceId || !!error"
|
|
108
|
+
aria-label="Add an env var"
|
|
109
|
+
title="Add an env var to the device's env file"
|
|
110
|
+
@click="adding = !adding"
|
|
111
|
+
>
|
|
112
|
+
<Plus :size="15" />
|
|
113
|
+
</button>
|
|
114
|
+
</header>
|
|
115
|
+
|
|
116
|
+
<p class="hint">
|
|
117
|
+
The device's env file — loaded once at boot. Keys here reach the daemon and its sessions.
|
|
118
|
+
</p>
|
|
119
|
+
<p v-if="!deviceId" class="hint">Select a session to see its device.</p>
|
|
120
|
+
<p v-else-if="error" class="message-error">{{ error }}</p>
|
|
121
|
+
<p v-else-if="view?.restartRequired" class="message-restart">
|
|
122
|
+
Changed since boot — restart the device (<code>dpi device stop && dpi device start</code>) to apply.
|
|
123
|
+
</p>
|
|
124
|
+
|
|
125
|
+
<form v-if="adding" class="add-form" @submit.prevent="add">
|
|
126
|
+
<label
|
|
127
|
+
>Key (UPPER_SNAKE_CASE)<input v-model="draft.key" placeholder="DPI_NOTIFY_ALLOW_PRIVATE" required />
|
|
128
|
+
</label>
|
|
129
|
+
<label>Value<input v-model="draft.value" placeholder="1" required /></label>
|
|
130
|
+
<div class="row">
|
|
131
|
+
<button class="primary small" type="submit" :disabled="busy === 'new'">
|
|
132
|
+
{{ busy === "new" ? "saving…" : "Save to env file" }}
|
|
133
|
+
</button>
|
|
134
|
+
<button class="small" type="button" @click="adding = false">Cancel</button>
|
|
135
|
+
</div>
|
|
136
|
+
<p class="hint">
|
|
137
|
+
Managed keys (DPI_TOKEN, DPI_PORT, start dirs…) have their own settings and are refused here.
|
|
138
|
+
</p>
|
|
139
|
+
</form>
|
|
140
|
+
|
|
141
|
+
<p v-if="!adding && view && !view.vars.length && !error" class="hint">
|
|
142
|
+
No vars in the env file yet.
|
|
143
|
+
</p>
|
|
144
|
+
|
|
145
|
+
<ul v-if="view?.vars.length" class="var-list">
|
|
146
|
+
<li v-for="v in view.vars" :key="v.key" class="var" :class="{ ro: !editable(v) }">
|
|
147
|
+
<div class="head">
|
|
148
|
+
<code class="key">{{ v.key }}</code>
|
|
149
|
+
<span class="tag">{{ v.source === "process" ? "process" : "file" }}</span>
|
|
150
|
+
<span v-if="v.managed" class="tag" title="Has its own setting; edit that instead">managed</span>
|
|
151
|
+
<span class="spacer" />
|
|
152
|
+
<button
|
|
153
|
+
v-if="editable(v)"
|
|
154
|
+
class="icon-button"
|
|
155
|
+
:aria-label="`Edit ${v.key}`"
|
|
156
|
+
:title="v.secret ? 'Replace the value' : 'Edit the value'"
|
|
157
|
+
@click="edit(v)"
|
|
158
|
+
>
|
|
159
|
+
<Pencil :size="13" />
|
|
160
|
+
</button>
|
|
161
|
+
<button
|
|
162
|
+
v-if="editable(v)"
|
|
163
|
+
class="icon-button"
|
|
164
|
+
:aria-label="`Remove ${v.key}`"
|
|
165
|
+
title="Remove from the env file"
|
|
166
|
+
@click="remove(v)"
|
|
167
|
+
>
|
|
168
|
+
<Trash2 :size="13" />
|
|
169
|
+
</button>
|
|
170
|
+
</div>
|
|
171
|
+
<code class="value" :title="v.secret ? 'secret — masked' : v.masked">{{ v.masked }}</code>
|
|
172
|
+
</li>
|
|
173
|
+
</ul>
|
|
174
|
+
|
|
175
|
+
<p v-if="view" class="hint path">{{ view.envFile }}</p>
|
|
176
|
+
</section>
|
|
177
|
+
</template>
|
|
178
|
+
|
|
179
|
+
<style scoped>
|
|
180
|
+
.env-panel {
|
|
181
|
+
display: flex;
|
|
182
|
+
flex-direction: column;
|
|
183
|
+
gap: 10px;
|
|
184
|
+
padding: 4px 2px 12px;
|
|
185
|
+
font-size: 16px;
|
|
186
|
+
}
|
|
187
|
+
.var-list {
|
|
188
|
+
display: flex;
|
|
189
|
+
flex-direction: column;
|
|
190
|
+
gap: 6px;
|
|
191
|
+
margin: 0;
|
|
192
|
+
padding: 0;
|
|
193
|
+
list-style: none;
|
|
194
|
+
}
|
|
195
|
+
.var {
|
|
196
|
+
display: flex;
|
|
197
|
+
flex-direction: column;
|
|
198
|
+
gap: 3px;
|
|
199
|
+
padding: 7px 10px;
|
|
200
|
+
border: 1px solid var(--line);
|
|
201
|
+
border-radius: 10px;
|
|
202
|
+
}
|
|
203
|
+
.var.ro {
|
|
204
|
+
opacity: 0.72;
|
|
205
|
+
}
|
|
206
|
+
.var .head {
|
|
207
|
+
display: flex;
|
|
208
|
+
align-items: center;
|
|
209
|
+
gap: 6px;
|
|
210
|
+
flex-wrap: wrap;
|
|
211
|
+
}
|
|
212
|
+
.var .spacer {
|
|
213
|
+
margin-left: auto;
|
|
214
|
+
}
|
|
215
|
+
.var .key {
|
|
216
|
+
font-size: 15px;
|
|
217
|
+
}
|
|
218
|
+
.var .value {
|
|
219
|
+
font-size: 13px;
|
|
220
|
+
opacity: 0.75;
|
|
221
|
+
word-break: break-all;
|
|
222
|
+
}
|
|
223
|
+
.add-form {
|
|
224
|
+
display: flex;
|
|
225
|
+
flex-direction: column;
|
|
226
|
+
gap: 8px;
|
|
227
|
+
padding: 10px;
|
|
228
|
+
border: 1px solid var(--line);
|
|
229
|
+
border-radius: 10px;
|
|
230
|
+
}
|
|
231
|
+
.add-form label {
|
|
232
|
+
display: flex;
|
|
233
|
+
flex-direction: column;
|
|
234
|
+
gap: 3px;
|
|
235
|
+
font-size: 13px;
|
|
236
|
+
opacity: 0.85;
|
|
237
|
+
}
|
|
238
|
+
.add-form input {
|
|
239
|
+
font: inherit;
|
|
240
|
+
font-size: 15px;
|
|
241
|
+
padding: 5px 8px;
|
|
242
|
+
color: var(--fg);
|
|
243
|
+
background: transparent;
|
|
244
|
+
border: 1px solid var(--line);
|
|
245
|
+
border-radius: 8px;
|
|
246
|
+
}
|
|
247
|
+
.add-form .row {
|
|
248
|
+
display: flex;
|
|
249
|
+
gap: 6px;
|
|
250
|
+
}
|
|
251
|
+
.message-restart {
|
|
252
|
+
font-size: 14px;
|
|
253
|
+
color: var(--warn, #e5a50a);
|
|
254
|
+
}
|
|
255
|
+
.hint.path {
|
|
256
|
+
font-size: 12px;
|
|
257
|
+
opacity: 0.55;
|
|
258
|
+
word-break: break-all;
|
|
259
|
+
}
|
|
260
|
+
.spin {
|
|
261
|
+
animation: spin 1s linear infinite;
|
|
262
|
+
}
|
|
263
|
+
@keyframes spin {
|
|
264
|
+
to {
|
|
265
|
+
transform: rotate(360deg);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
</style>
|
|
@@ -7,6 +7,8 @@ import {
|
|
|
7
7
|
PackageOpen,
|
|
8
8
|
PiggyBank,
|
|
9
9
|
CalendarClock,
|
|
10
|
+
Bell,
|
|
11
|
+
FileCog,
|
|
10
12
|
GitBranch,
|
|
11
13
|
ChevronDown,
|
|
12
14
|
FolderOpen,
|
|
@@ -28,6 +30,8 @@ import GitPanel from "./GitPanel.vue";
|
|
|
28
30
|
import HostPanel from "./HostPanel.vue";
|
|
29
31
|
import UsagePanel from "./UsagePanel.vue";
|
|
30
32
|
import SchedulesPanel from "./SchedulesPanel.vue";
|
|
33
|
+
import NotifyPanel from "./NotifyPanel.vue";
|
|
34
|
+
import EnvPanel from "./EnvPanel.vue";
|
|
31
35
|
import ExtensionsPanel from "./ExtensionsPanel.vue";
|
|
32
36
|
import ContextBar from "./ContextBar.vue";
|
|
33
37
|
import { deviceClient, message } from "../client/hub";
|
|
@@ -70,6 +74,8 @@ const tabs = [
|
|
|
70
74
|
{ id: "host", label: "Host", icon: Activity },
|
|
71
75
|
{ id: "usage", label: "Usage", icon: PiggyBank },
|
|
72
76
|
{ id: "auto", label: "Auto", icon: CalendarClock },
|
|
77
|
+
{ id: "notify", label: "Notify", icon: Bell },
|
|
78
|
+
{ id: "env", label: "Env", icon: FileCog },
|
|
73
79
|
{ id: "state", label: "State", icon: Braces },
|
|
74
80
|
{ id: "tasks", label: "Tasks", icon: Activity },
|
|
75
81
|
{ id: "tools", label: "Tools", icon: Wrench },
|
|
@@ -441,6 +447,8 @@ const offeredTools = computed(() => detail.value?.tools.filter((t) => t.offered)
|
|
|
441
447
|
<HostPanel v-if="ui.tab === 'host'" />
|
|
442
448
|
<UsagePanel v-if="ui.tab === 'usage'" />
|
|
443
449
|
<SchedulesPanel v-if="ui.tab === 'auto'" />
|
|
450
|
+
<NotifyPanel v-if="ui.tab === 'notify'" />
|
|
451
|
+
<EnvPanel v-if="ui.tab === 'env'" />
|
|
444
452
|
<ExtensionsPanel v-if="ui.tab === 'extensions'" />
|
|
445
453
|
<template v-if="ui.tab === 'tools'"
|
|
446
454
|
><div class="panel-heading">
|
|
@@ -63,6 +63,43 @@ const rememberCwd = (devId: string, cwd: string) => {
|
|
|
63
63
|
const pending = ref(false);
|
|
64
64
|
const error = ref("");
|
|
65
65
|
|
|
66
|
+
/**
|
|
67
|
+
* Per-project default model (Wave 2): once the cwd names a registered project,
|
|
68
|
+
* the picker follows that project's choice. Longest registered root wins, the
|
|
69
|
+
* same rule the device applies on create — the prefill just makes it visible
|
|
70
|
+
* before the session exists.
|
|
71
|
+
*/
|
|
72
|
+
const projectModels = ref<Record<string, { provider: string; modelId: string }>>({});
|
|
73
|
+
watch(
|
|
74
|
+
deviceId,
|
|
75
|
+
async (id) => {
|
|
76
|
+
projectModels.value = {};
|
|
77
|
+
if (!id) return;
|
|
78
|
+
try {
|
|
79
|
+
const { projects } = await deviceClient(id).projects(true);
|
|
80
|
+
projectModels.value = Object.fromEntries(
|
|
81
|
+
projects.filter((p) => p.model).map((p) => [p.rootPath, p.model!]),
|
|
82
|
+
);
|
|
83
|
+
} catch {
|
|
84
|
+
/* older device: no project defaults, the device default stays */
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
{ immediate: true },
|
|
88
|
+
);
|
|
89
|
+
watch(
|
|
90
|
+
[() => draft.value.cwd, projectModels],
|
|
91
|
+
() => {
|
|
92
|
+
const cwd = draft.value.cwd;
|
|
93
|
+
if (!cwd) return;
|
|
94
|
+
const roots = Object.keys(projectModels.value)
|
|
95
|
+
.filter((root) => cwd === root || cwd.startsWith(`${root}/`))
|
|
96
|
+
.sort((a, b) => b.length - a.length);
|
|
97
|
+
const model = roots.length ? projectModels.value[roots[0]] : undefined;
|
|
98
|
+
if (model) draft.value.model = `${model.provider}/${model.modelId}`;
|
|
99
|
+
},
|
|
100
|
+
{ immediate: true },
|
|
101
|
+
);
|
|
102
|
+
|
|
66
103
|
watch(
|
|
67
104
|
device,
|
|
68
105
|
(d) => {
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// Outbound notifications (Wave 2): webhook / ntfy sinks owned by the DEVICE.
|
|
3
|
+
// This panel only edits the records and can fire a test event; delivery happens
|
|
4
|
+
// on the device, so it works with no browser open.
|
|
5
|
+
import { computed, ref, watch } from "vue";
|
|
6
|
+
import { Bell, Plus, RefreshCw, Send, Trash2, Power } from "lucide-vue-next";
|
|
7
|
+
import type { NotifyDelivery, NotifySinkView } from "@sdk/api";
|
|
8
|
+
import { deviceClient, message } from "../client/hub";
|
|
9
|
+
import { notify, selected, ui } from "../client/store";
|
|
10
|
+
|
|
11
|
+
const sinks = ref<NotifySinkView[]>([]);
|
|
12
|
+
const busy = ref("");
|
|
13
|
+
const error = ref("");
|
|
14
|
+
const loading = ref(false);
|
|
15
|
+
const results = ref<NotifyDelivery[]>([]);
|
|
16
|
+
const deviceId = computed(() => selected.value?.deviceId);
|
|
17
|
+
const client = () => deviceClient(deviceId.value ?? "");
|
|
18
|
+
|
|
19
|
+
const adding = ref(false);
|
|
20
|
+
const draft = ref({ kind: "webhook" as "webhook" | "ntfy", url: "", label: "", events: "" });
|
|
21
|
+
|
|
22
|
+
async function load() {
|
|
23
|
+
if (!deviceId.value) return void (sinks.value = []);
|
|
24
|
+
loading.value = true;
|
|
25
|
+
error.value = "";
|
|
26
|
+
try {
|
|
27
|
+
sinks.value = (await client().notifySinks()).sinks;
|
|
28
|
+
} catch (e) {
|
|
29
|
+
const code = (e as { code?: string }).code;
|
|
30
|
+
error.value =
|
|
31
|
+
code === "not_found" || /allowlist/i.test(message(e))
|
|
32
|
+
? "This device runs an older build: update it (`dpi update`) to use notifications."
|
|
33
|
+
: message(e).slice(0, 160);
|
|
34
|
+
} finally {
|
|
35
|
+
loading.value = false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
watch(deviceId, load, { immediate: true });
|
|
39
|
+
|
|
40
|
+
const when = (at?: number) => {
|
|
41
|
+
if (!at) return "never";
|
|
42
|
+
const mins = Math.round((Date.now() - at) / 60_000);
|
|
43
|
+
return mins < 1 ? "just now" : mins < 60 ? `${mins}m ago` : `${Math.round(mins / 60)}h ago`;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
async function create() {
|
|
47
|
+
const d = draft.value;
|
|
48
|
+
if (!d.url.trim()) return;
|
|
49
|
+
busy.value = "new";
|
|
50
|
+
try {
|
|
51
|
+
await client().createNotifySink({
|
|
52
|
+
kind: d.kind,
|
|
53
|
+
url: d.url.trim(),
|
|
54
|
+
...(d.label.trim() ? { label: d.label.trim() } : {}),
|
|
55
|
+
...(d.events.trim()
|
|
56
|
+
? { events: d.events.split(",").map((e) => e.trim()).filter(Boolean) }
|
|
57
|
+
: {}),
|
|
58
|
+
});
|
|
59
|
+
adding.value = false;
|
|
60
|
+
draft.value = { kind: "webhook", url: "", label: "", events: "" };
|
|
61
|
+
await load();
|
|
62
|
+
notify("Sink added on the device.");
|
|
63
|
+
} catch (e) {
|
|
64
|
+
notify(message(e).slice(0, 160));
|
|
65
|
+
} finally {
|
|
66
|
+
busy.value = "";
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function toggle(sink: NotifySinkView) {
|
|
71
|
+
busy.value = sink.id;
|
|
72
|
+
try {
|
|
73
|
+
await client().updateNotifySink(sink.id, { enabled: !sink.enabled });
|
|
74
|
+
await load();
|
|
75
|
+
} catch (e) {
|
|
76
|
+
notify(message(e).slice(0, 140));
|
|
77
|
+
} finally {
|
|
78
|
+
busy.value = "";
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function remove(sink: NotifySinkView) {
|
|
83
|
+
ui.dialog = {
|
|
84
|
+
kind: "prompt",
|
|
85
|
+
title: `Remove this ${sink.kind} sink?`,
|
|
86
|
+
hint: "The device stops notifying this target. Nothing else changes.",
|
|
87
|
+
submit: "Remove sink",
|
|
88
|
+
danger: true,
|
|
89
|
+
run: async () => {
|
|
90
|
+
await client().removeNotifySink(sink.id);
|
|
91
|
+
await load();
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async function test() {
|
|
97
|
+
busy.value = "test";
|
|
98
|
+
results.value = [];
|
|
99
|
+
try {
|
|
100
|
+
results.value = (await client().testNotifySinks()).results;
|
|
101
|
+
const failed = results.value.filter((r) => r.status === "failed").length;
|
|
102
|
+
notify(
|
|
103
|
+
results.value.length
|
|
104
|
+
? `Test: ${results.value.length - failed} sent${failed ? `, ${failed} failed` : ""}.`
|
|
105
|
+
: "No enabled sinks matched — nothing was sent.",
|
|
106
|
+
);
|
|
107
|
+
} catch (e) {
|
|
108
|
+
notify(message(e).slice(0, 160));
|
|
109
|
+
} finally {
|
|
110
|
+
busy.value = "";
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
</script>
|
|
114
|
+
|
|
115
|
+
<template>
|
|
116
|
+
<section class="notify-panel" aria-label="Notification sinks">
|
|
117
|
+
<header class="panel-heading">
|
|
118
|
+
<span><Bell :size="16" />NOTIFY</span>
|
|
119
|
+
<button class="icon-button" :disabled="loading || !deviceId" aria-label="Refresh sinks" title="Refresh sinks" @click="load">
|
|
120
|
+
<RefreshCw :size="15" :class="{ spin: loading }" />
|
|
121
|
+
</button>
|
|
122
|
+
<button
|
|
123
|
+
class="icon-button"
|
|
124
|
+
:disabled="!deviceId || !sinks.length || busy === 'test'"
|
|
125
|
+
aria-label="Send a test notification"
|
|
126
|
+
title="Send a test event through every enabled sink"
|
|
127
|
+
@click="test"
|
|
128
|
+
>
|
|
129
|
+
<Send :size="15" />
|
|
130
|
+
</button>
|
|
131
|
+
<button class="icon-button" :disabled="!deviceId" aria-label="Add a sink" title="Add a sink" @click="adding = !adding">
|
|
132
|
+
<Plus :size="15" />
|
|
133
|
+
</button>
|
|
134
|
+
</header>
|
|
135
|
+
|
|
136
|
+
<p class="hint">Delivered by the device — no browser needs to be open.</p>
|
|
137
|
+
<p v-if="!deviceId" class="hint">Select a session to see its device.</p>
|
|
138
|
+
<p v-else-if="error" class="message-error">{{ error }}</p>
|
|
139
|
+
|
|
140
|
+
<form v-if="adding" class="add-form" @submit.prevent="create">
|
|
141
|
+
<label
|
|
142
|
+
>Kind
|
|
143
|
+
<select v-model="draft.kind">
|
|
144
|
+
<option value="webhook">webhook (JSON POST)</option>
|
|
145
|
+
<option value="ntfy">ntfy (topic)</option>
|
|
146
|
+
</select>
|
|
147
|
+
</label>
|
|
148
|
+
<label
|
|
149
|
+
>URL
|
|
150
|
+
<input v-model="draft.url" :placeholder="draft.kind === 'ntfy' ? 'https://ntfy.sh/my-topic' : 'https://example.com/hook'" required />
|
|
151
|
+
</label>
|
|
152
|
+
<label>Label<input v-model="draft.label" placeholder="phone" /></label>
|
|
153
|
+
<label
|
|
154
|
+
>Events
|
|
155
|
+
<input v-model="draft.events" placeholder="empty = all — e.g. session.failed,schedule.*" />
|
|
156
|
+
</label>
|
|
157
|
+
<div class="row">
|
|
158
|
+
<button class="primary small" type="submit" :disabled="busy === 'new'">
|
|
159
|
+
{{ busy === "new" ? "adding…" : "Add sink" }}
|
|
160
|
+
</button>
|
|
161
|
+
<button class="small" type="button" @click="adding = false">Cancel</button>
|
|
162
|
+
</div>
|
|
163
|
+
<p class="hint">LAN targets (192.168.x, localhost) need <code>DPI_NOTIFY_ALLOW_PRIVATE=1</code> on the device.</p>
|
|
164
|
+
</form>
|
|
165
|
+
|
|
166
|
+
<p v-if="!adding && !sinks.length && deviceId && !error" class="hint">
|
|
167
|
+
No sinks yet. Press + to add a webhook or an ntfy topic.
|
|
168
|
+
</p>
|
|
169
|
+
|
|
170
|
+
<ul v-if="sinks.length" class="sink-list">
|
|
171
|
+
<li v-for="s in sinks" :key="s.id" class="sink" :class="{ off: !s.enabled }">
|
|
172
|
+
<div class="head">
|
|
173
|
+
<span class="tag">{{ s.kind }}</span>
|
|
174
|
+
<b>{{ s.label || s.url }}</b>
|
|
175
|
+
<em class="next">{{ s.lastError ? `last failed` : `sent ${when(s.lastDeliveryAt)}` }}</em>
|
|
176
|
+
</div>
|
|
177
|
+
<code class="url">{{ s.url }}</code>
|
|
178
|
+
<p v-if="s.events?.length" class="hint">events: {{ s.events.join(", ") }}</p>
|
|
179
|
+
<p v-if="s.lastError" class="message-error">{{ s.lastError.slice(0, 160) }}</p>
|
|
180
|
+
<div class="row">
|
|
181
|
+
<button class="small" :disabled="busy === s.id" @click="toggle(s)">
|
|
182
|
+
<Power :size="12" />{{ s.enabled ? "disable" : "enable" }}
|
|
183
|
+
</button>
|
|
184
|
+
<button class="small danger" :disabled="busy === s.id" @click="remove(s)"><Trash2 :size="12" />remove</button>
|
|
185
|
+
</div>
|
|
186
|
+
</li>
|
|
187
|
+
</ul>
|
|
188
|
+
|
|
189
|
+
<ul v-if="results.length" class="results" aria-label="Test results">
|
|
190
|
+
<li v-for="r in results" :key="r.id" :class="r.status">
|
|
191
|
+
<span class="tag">{{ r.status }}</span> {{ r.kind }} {{ r.id.slice(0, 8) }}
|
|
192
|
+
<em v-if="r.detail">{{ r.detail }}</em>
|
|
193
|
+
</li>
|
|
194
|
+
</ul>
|
|
195
|
+
</section>
|
|
196
|
+
</template>
|
|
197
|
+
|
|
198
|
+
<style scoped>
|
|
199
|
+
.notify-panel {
|
|
200
|
+
display: flex;
|
|
201
|
+
flex-direction: column;
|
|
202
|
+
gap: 10px;
|
|
203
|
+
padding: 4px 2px 12px;
|
|
204
|
+
font-size: 16px;
|
|
205
|
+
}
|
|
206
|
+
.sink-list,
|
|
207
|
+
.results {
|
|
208
|
+
display: flex;
|
|
209
|
+
flex-direction: column;
|
|
210
|
+
gap: 8px;
|
|
211
|
+
margin: 0;
|
|
212
|
+
padding: 0;
|
|
213
|
+
list-style: none;
|
|
214
|
+
}
|
|
215
|
+
.sink {
|
|
216
|
+
display: flex;
|
|
217
|
+
flex-direction: column;
|
|
218
|
+
gap: 4px;
|
|
219
|
+
padding: 8px 10px;
|
|
220
|
+
border: 1px solid var(--line);
|
|
221
|
+
border-radius: 10px;
|
|
222
|
+
}
|
|
223
|
+
.sink.off {
|
|
224
|
+
opacity: 0.6;
|
|
225
|
+
}
|
|
226
|
+
.sink .head {
|
|
227
|
+
display: flex;
|
|
228
|
+
align-items: center;
|
|
229
|
+
gap: 6px;
|
|
230
|
+
flex-wrap: wrap;
|
|
231
|
+
}
|
|
232
|
+
.sink .next {
|
|
233
|
+
margin-left: auto;
|
|
234
|
+
font-style: normal;
|
|
235
|
+
font-size: 13px;
|
|
236
|
+
opacity: 0.7;
|
|
237
|
+
}
|
|
238
|
+
.sink .url,
|
|
239
|
+
.url {
|
|
240
|
+
font-size: 13px;
|
|
241
|
+
opacity: 0.7;
|
|
242
|
+
word-break: break-all;
|
|
243
|
+
}
|
|
244
|
+
.sink .row,
|
|
245
|
+
.add-form .row {
|
|
246
|
+
display: flex;
|
|
247
|
+
gap: 6px;
|
|
248
|
+
flex-wrap: wrap;
|
|
249
|
+
}
|
|
250
|
+
.results li {
|
|
251
|
+
display: flex;
|
|
252
|
+
align-items: center;
|
|
253
|
+
gap: 6px;
|
|
254
|
+
font-size: 15px;
|
|
255
|
+
}
|
|
256
|
+
.results li.failed {
|
|
257
|
+
color: var(--warn, #e5a50a);
|
|
258
|
+
}
|
|
259
|
+
.add-form {
|
|
260
|
+
display: flex;
|
|
261
|
+
flex-direction: column;
|
|
262
|
+
gap: 8px;
|
|
263
|
+
padding: 10px;
|
|
264
|
+
border: 1px solid var(--line);
|
|
265
|
+
border-radius: 10px;
|
|
266
|
+
}
|
|
267
|
+
.add-form label {
|
|
268
|
+
display: flex;
|
|
269
|
+
flex-direction: column;
|
|
270
|
+
gap: 3px;
|
|
271
|
+
font-size: 13px;
|
|
272
|
+
opacity: 0.85;
|
|
273
|
+
}
|
|
274
|
+
.add-form input,
|
|
275
|
+
.add-form select {
|
|
276
|
+
font: inherit;
|
|
277
|
+
font-size: 15px;
|
|
278
|
+
padding: 5px 8px;
|
|
279
|
+
color: var(--fg);
|
|
280
|
+
background: transparent;
|
|
281
|
+
border: 1px solid var(--line);
|
|
282
|
+
border-radius: 8px;
|
|
283
|
+
}
|
|
284
|
+
.spin {
|
|
285
|
+
animation: spin 1s linear infinite;
|
|
286
|
+
}
|
|
287
|
+
@keyframes spin {
|
|
288
|
+
to {
|
|
289
|
+
transform: rotate(360deg);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
</style>
|