my-durable 0.0.39 → 0.0.41
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/doctor.ts +29 -9
- package/apps/dpi-backend/src/gc-cli.ts +113 -0
- package/apps/dpi-backend/src/gc.ts +142 -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/routes.ts +17 -0
- package/apps/dpi-backend/src/schedule-cli.ts +211 -0
- package/apps/dpi-backend/src/schedules.ts +676 -0
- package/apps/dpi-backend/src/store.ts +275 -7
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/index-D6ClJqd8.css +1 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/index-DMb-n4O-.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/client/hub.ts +2 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/client/store.ts +4 -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/NotifyPanel.vue +292 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/SchedulesPanel.vue +289 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/TreeRow.vue +13 -1
- package/apps/dpi-playground/apps/dpi-playground-hub/src/main.ts +20 -1
- package/apps/dpi-sdk/src/api.ts +100 -0
- package/apps/dpi-sdk/src/client.ts +38 -0
- package/apps/dpi-sdk/src/protocol/rest-routes.ts +12 -0
- package/bin/dpi.mjs +22 -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-CYZxCPDU.js +0 -81
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/index-v7IQ7Jg5.css +0 -1
|
@@ -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-DMb-n4O-.js"></script>
|
|
11
|
+
<link rel="stylesheet" crossorigin href="/assets/index-D6ClJqd8.css">
|
|
12
12
|
</head>
|
|
13
13
|
<body>
|
|
14
14
|
<div id="app"></div>
|
|
@@ -26,6 +26,8 @@ async function call<T>(method: string, path: string, body?: unknown): Promise<T>
|
|
|
26
26
|
|
|
27
27
|
export const hub = {
|
|
28
28
|
network: () => call<{ configFile?: string; devices: NetworkDevice[] }>("GET", "/network"),
|
|
29
|
+
/** The hub's own version, for the "device is behind" badge. */
|
|
30
|
+
version: () => call<{ version: string; node: string }>("GET", "/version"),
|
|
29
31
|
/** Probe a device now. Devices themselves are configured in dpi-network.yaml, not here. */
|
|
30
32
|
check: (id: string) =>
|
|
31
33
|
call<NetworkDevice>("POST", `/devices/${encodeURIComponent(id)}/check`, {}),
|
|
@@ -15,6 +15,9 @@ export const streamState = ref(stream.state);
|
|
|
15
15
|
stream.onState((s) => (streamState.value = s));
|
|
16
16
|
export const network = useNetwork(stream);
|
|
17
17
|
export const configFile = ref<string>();
|
|
18
|
+
/** The hub's own version. A device reporting another one is behind (badge only:
|
|
19
|
+
* the hub never pushes code, devices self-update). */
|
|
20
|
+
export const hubVersion = ref<string>();
|
|
18
21
|
|
|
19
22
|
// ------------------------------------------------------------------ selection + persisted UI state
|
|
20
23
|
|
|
@@ -122,6 +125,7 @@ export async function boot() {
|
|
|
122
125
|
hub.uiGet<{ tree: boolean; inspector: boolean }>("layout.panels"),
|
|
123
126
|
]);
|
|
124
127
|
if (panels) Object.assign(layout, panels);
|
|
128
|
+
void hub.version().then((v) => (hubVersion.value = v.version)).catch(() => {});
|
|
125
129
|
configFile.value = net.configFile;
|
|
126
130
|
if (!network.model.devices.length)
|
|
127
131
|
network.model.apply({ type: "network", devices: net.devices });
|
|
@@ -6,6 +6,8 @@ import {
|
|
|
6
6
|
Download,
|
|
7
7
|
PackageOpen,
|
|
8
8
|
PiggyBank,
|
|
9
|
+
CalendarClock,
|
|
10
|
+
Bell,
|
|
9
11
|
GitBranch,
|
|
10
12
|
ChevronDown,
|
|
11
13
|
FolderOpen,
|
|
@@ -26,6 +28,8 @@ import TasksPanel from "./TasksPanel.vue";
|
|
|
26
28
|
import GitPanel from "./GitPanel.vue";
|
|
27
29
|
import HostPanel from "./HostPanel.vue";
|
|
28
30
|
import UsagePanel from "./UsagePanel.vue";
|
|
31
|
+
import SchedulesPanel from "./SchedulesPanel.vue";
|
|
32
|
+
import NotifyPanel from "./NotifyPanel.vue";
|
|
29
33
|
import ExtensionsPanel from "./ExtensionsPanel.vue";
|
|
30
34
|
import ContextBar from "./ContextBar.vue";
|
|
31
35
|
import { deviceClient, message } from "../client/hub";
|
|
@@ -67,6 +71,8 @@ const tabs = [
|
|
|
67
71
|
{ id: "git", label: "Git", icon: GitBranch },
|
|
68
72
|
{ id: "host", label: "Host", icon: Activity },
|
|
69
73
|
{ id: "usage", label: "Usage", icon: PiggyBank },
|
|
74
|
+
{ id: "auto", label: "Auto", icon: CalendarClock },
|
|
75
|
+
{ id: "notify", label: "Notify", icon: Bell },
|
|
70
76
|
{ id: "state", label: "State", icon: Braces },
|
|
71
77
|
{ id: "tasks", label: "Tasks", icon: Activity },
|
|
72
78
|
{ id: "tools", label: "Tools", icon: Wrench },
|
|
@@ -437,6 +443,8 @@ const offeredTools = computed(() => detail.value?.tools.filter((t) => t.offered)
|
|
|
437
443
|
<GitPanel v-if="ui.tab === 'git'" />
|
|
438
444
|
<HostPanel v-if="ui.tab === 'host'" />
|
|
439
445
|
<UsagePanel v-if="ui.tab === 'usage'" />
|
|
446
|
+
<SchedulesPanel v-if="ui.tab === 'auto'" />
|
|
447
|
+
<NotifyPanel v-if="ui.tab === 'notify'" />
|
|
440
448
|
<ExtensionsPanel v-if="ui.tab === 'extensions'" />
|
|
441
449
|
<template v-if="ui.tab === 'tools'"
|
|
442
450
|
><div class="panel-heading">
|
|
@@ -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>
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// Scheduled sessions (Wave 2): the DEVICE owns the clock — this panel only
|
|
3
|
+
// reads and edits the records over the tunnel, so the daemon runs them whether
|
|
4
|
+
// or not a browser is open. A run creates a fresh session per trigger.
|
|
5
|
+
import { computed, ref, watch } from "vue";
|
|
6
|
+
import { CalendarClock, Play, Plus, RefreshCw, Trash2, Power } from "lucide-vue-next";
|
|
7
|
+
import type { ScheduleView } from "@sdk/api";
|
|
8
|
+
import { deviceClient, message } from "../client/hub";
|
|
9
|
+
import { notify, selected, ui } from "../client/store";
|
|
10
|
+
|
|
11
|
+
const schedules = ref<ScheduleView[]>([]);
|
|
12
|
+
const busy = ref("");
|
|
13
|
+
const error = ref("");
|
|
14
|
+
const loading = ref(false);
|
|
15
|
+
const deviceId = computed(() => selected.value?.deviceId);
|
|
16
|
+
const client = () => deviceClient(deviceId.value ?? "");
|
|
17
|
+
|
|
18
|
+
const every = ref("60");
|
|
19
|
+
const daily = ref("");
|
|
20
|
+
const adding = ref(false);
|
|
21
|
+
const draft = ref({ name: "", cwd: "", prompt: "", model: "" });
|
|
22
|
+
|
|
23
|
+
async function load() {
|
|
24
|
+
if (!deviceId.value) return void (schedules.value = []);
|
|
25
|
+
loading.value = true;
|
|
26
|
+
error.value = "";
|
|
27
|
+
try {
|
|
28
|
+
schedules.value = (await client().schedules()).schedules;
|
|
29
|
+
} catch (e) {
|
|
30
|
+
const code = (e as { code?: string }).code;
|
|
31
|
+
error.value =
|
|
32
|
+
code === "not_found" || /allowlist/i.test(message(e))
|
|
33
|
+
? "This device runs an older build: update it (`dpi update`) to use schedules."
|
|
34
|
+
: message(e).slice(0, 160);
|
|
35
|
+
} finally {
|
|
36
|
+
loading.value = false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
watch(deviceId, load, { immediate: true });
|
|
40
|
+
|
|
41
|
+
const when = (at: number | null) => {
|
|
42
|
+
if (!at) return "—";
|
|
43
|
+
const delta = at - Date.now();
|
|
44
|
+
const mins = Math.round(Math.abs(delta) / 60_000);
|
|
45
|
+
const human = mins < 60 ? `${mins}m` : mins < 1440 ? `${Math.round(mins / 60)}h` : `${Math.round(mins / 1440)}d`;
|
|
46
|
+
return delta >= 0 ? `in ${human}` : `${human} ago`;
|
|
47
|
+
};
|
|
48
|
+
const trigger = (s: ScheduleView) => (s.everyMinutes ? `every ${s.everyMinutes}m` : `daily ${s.dailyAt}`);
|
|
49
|
+
|
|
50
|
+
async function withBusy(id: string, fn: () => Promise<unknown>, done: string) {
|
|
51
|
+
busy.value = id;
|
|
52
|
+
try {
|
|
53
|
+
await fn();
|
|
54
|
+
await load();
|
|
55
|
+
notify(done);
|
|
56
|
+
} catch (e) {
|
|
57
|
+
notify(message(e).slice(0, 140));
|
|
58
|
+
} finally {
|
|
59
|
+
busy.value = "";
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const toggle = (s: ScheduleView) =>
|
|
64
|
+
withBusy(s.id, () => client().updateSchedule(s.id, { enabled: !s.enabled }), s.enabled ? "Schedule paused." : "Schedule resumed.");
|
|
65
|
+
|
|
66
|
+
const runNow = (s: ScheduleView) =>
|
|
67
|
+
withBusy(s.id, () => client().runSchedule(s.id), `${s.name}: run finished.`);
|
|
68
|
+
|
|
69
|
+
const remove = (s: ScheduleView) =>
|
|
70
|
+
(ui.dialog = {
|
|
71
|
+
kind: "prompt",
|
|
72
|
+
title: `Remove ${s.name}?`,
|
|
73
|
+
hint: "The schedule stops being run. Sessions it already created are untouched.",
|
|
74
|
+
submit: "Remove schedule",
|
|
75
|
+
danger: true,
|
|
76
|
+
run: () => withBusy(s.id, () => client().removeSchedule(s.id), "Schedule removed."),
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
/** The model is picked from the device's own catalog, not typed from memory. */
|
|
80
|
+
const models = ref<{ key: string }[]>([]);
|
|
81
|
+
async function openAdd() {
|
|
82
|
+
adding.value = true;
|
|
83
|
+
draft.value = { name: "", cwd: selected.value?.sessionId ? "" : "", prompt: "", model: "" };
|
|
84
|
+
try {
|
|
85
|
+
const device = await client().device();
|
|
86
|
+
models.value = device.models.map((m) => ({ key: `${m.provider}/${m.id}` }));
|
|
87
|
+
draft.value.model = device.defaultModel;
|
|
88
|
+
} catch {
|
|
89
|
+
models.value = [];
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function save() {
|
|
94
|
+
const d = draft.value;
|
|
95
|
+
const [provider, ...rest] = d.model.split("/");
|
|
96
|
+
const modelId = rest.join("/");
|
|
97
|
+
if (!d.name.trim() || !d.cwd.trim() || !d.prompt.trim() || !provider || !modelId) return;
|
|
98
|
+
busy.value = "new";
|
|
99
|
+
try {
|
|
100
|
+
await client().createSchedule({
|
|
101
|
+
name: d.name.trim(),
|
|
102
|
+
cwd: d.cwd.trim(),
|
|
103
|
+
prompt: d.prompt,
|
|
104
|
+
model: { provider, modelId },
|
|
105
|
+
// One trigger only: exactly what the registry demands.
|
|
106
|
+
...(daily.value.trim() ? { dailyAt: daily.value.trim() } : { everyMinutes: Number(every.value) || 60 }),
|
|
107
|
+
});
|
|
108
|
+
adding.value = false;
|
|
109
|
+
await load();
|
|
110
|
+
notify("Schedule created. The device runs it on its own clock.");
|
|
111
|
+
} catch (e) {
|
|
112
|
+
notify(message(e).slice(0, 160));
|
|
113
|
+
} finally {
|
|
114
|
+
busy.value = "";
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
</script>
|
|
118
|
+
|
|
119
|
+
<template>
|
|
120
|
+
<section class="schedules-panel" aria-label="Scheduled sessions">
|
|
121
|
+
<header class="panel-heading">
|
|
122
|
+
<span><CalendarClock :size="16" />SCHEDULES</span>
|
|
123
|
+
<button class="icon-button" :disabled="loading || !deviceId" aria-label="Refresh schedules" title="Refresh schedules" @click="load">
|
|
124
|
+
<RefreshCw :size="15" :class="{ spin: loading }" />
|
|
125
|
+
</button>
|
|
126
|
+
<button class="icon-button" :disabled="!deviceId" aria-label="Add schedule" title="Add schedule" @click="openAdd">
|
|
127
|
+
<Plus :size="15" />
|
|
128
|
+
</button>
|
|
129
|
+
</header>
|
|
130
|
+
|
|
131
|
+
<p class="hint">Runs on the device's own clock — no browser needs to be open.</p>
|
|
132
|
+
<p v-if="!deviceId" class="hint">Select a session to see its device.</p>
|
|
133
|
+
<p v-else-if="error" class="message-error">{{ error }}</p>
|
|
134
|
+
|
|
135
|
+
<form v-if="adding" class="add-form" @submit.prevent="save">
|
|
136
|
+
<label>Name<input v-model="draft.name" placeholder="Nightly smoke" required /></label>
|
|
137
|
+
<label>Directory<input v-model="draft.cwd" placeholder="/home/me/project" required /></label>
|
|
138
|
+
<label>Prompt<textarea v-model="draft.prompt" rows="3" placeholder="Run the tests and summarise failures" required /></label>
|
|
139
|
+
<label
|
|
140
|
+
>Model
|
|
141
|
+
<select v-model="draft.model">
|
|
142
|
+
<option v-for="m in models" :key="m.key" :value="m.key">{{ m.key }}</option>
|
|
143
|
+
</select>
|
|
144
|
+
</label>
|
|
145
|
+
<div class="trigger-row">
|
|
146
|
+
<label class="inline">Every <input v-model="every" class="num" :disabled="!!daily.trim()" /> min</label>
|
|
147
|
+
<span class="muted">or</span>
|
|
148
|
+
<label class="inline">daily at <input v-model="daily" class="num time" placeholder="03:00" :disabled="!!every" /></label>
|
|
149
|
+
</div>
|
|
150
|
+
<div class="row">
|
|
151
|
+
<button class="primary small" type="submit" :disabled="busy === 'new'">
|
|
152
|
+
{{ busy === "new" ? "creating…" : "Create schedule" }}
|
|
153
|
+
</button>
|
|
154
|
+
<button class="small" type="button" @click="adding = false">Cancel</button>
|
|
155
|
+
</div>
|
|
156
|
+
</form>
|
|
157
|
+
|
|
158
|
+
<p v-if="!adding && !schedules.length && deviceId && !error" class="hint">
|
|
159
|
+
No schedules yet. Press + to add one.
|
|
160
|
+
</p>
|
|
161
|
+
|
|
162
|
+
<ul v-if="schedules.length" class="schedule-list">
|
|
163
|
+
<li v-for="s in schedules" :key="s.id" class="schedule" :class="{ off: !s.enabled }">
|
|
164
|
+
<div class="head">
|
|
165
|
+
<b>{{ s.name }}</b>
|
|
166
|
+
<span class="tag">{{ trigger(s) }}</span>
|
|
167
|
+
<span v-if="s.running" class="tag running">running</span>
|
|
168
|
+
<span v-else-if="s.lastOutcome === 'failed'" class="tag bad" :title="s.lastError">last run failed</span>
|
|
169
|
+
<span class="next">{{ s.enabled ? `next ${when(s.nextRunAt)}` : "paused" }}</span>
|
|
170
|
+
</div>
|
|
171
|
+
<code class="cwd">{{ s.cwd }}</code>
|
|
172
|
+
<p v-if="s.lastError" class="message-error">{{ s.lastError.slice(0, 160) }}</p>
|
|
173
|
+
<div class="row">
|
|
174
|
+
<button class="small" :disabled="busy === s.id" @click="runNow(s)"><Play :size="12" />run now</button>
|
|
175
|
+
<button class="small" :disabled="busy === s.id" @click="toggle(s)">
|
|
176
|
+
<Power :size="12" />{{ s.enabled ? "pause" : "resume" }}
|
|
177
|
+
</button>
|
|
178
|
+
<button class="small danger" :disabled="busy === s.id" @click="remove(s)"><Trash2 :size="12" />remove</button>
|
|
179
|
+
</div>
|
|
180
|
+
</li>
|
|
181
|
+
</ul>
|
|
182
|
+
</section>
|
|
183
|
+
</template>
|
|
184
|
+
|
|
185
|
+
<style scoped>
|
|
186
|
+
.schedules-panel {
|
|
187
|
+
display: flex;
|
|
188
|
+
flex-direction: column;
|
|
189
|
+
gap: 10px;
|
|
190
|
+
padding: 4px 2px 12px;
|
|
191
|
+
font-size: 16px;
|
|
192
|
+
}
|
|
193
|
+
.schedule-list {
|
|
194
|
+
display: flex;
|
|
195
|
+
flex-direction: column;
|
|
196
|
+
gap: 8px;
|
|
197
|
+
margin: 0;
|
|
198
|
+
padding: 0;
|
|
199
|
+
list-style: none;
|
|
200
|
+
}
|
|
201
|
+
.schedule {
|
|
202
|
+
display: flex;
|
|
203
|
+
flex-direction: column;
|
|
204
|
+
gap: 4px;
|
|
205
|
+
padding: 8px 10px;
|
|
206
|
+
border: 1px solid var(--line);
|
|
207
|
+
border-radius: 10px;
|
|
208
|
+
}
|
|
209
|
+
.schedule.off {
|
|
210
|
+
opacity: 0.6;
|
|
211
|
+
}
|
|
212
|
+
.schedule .head {
|
|
213
|
+
display: flex;
|
|
214
|
+
align-items: center;
|
|
215
|
+
gap: 6px;
|
|
216
|
+
flex-wrap: wrap;
|
|
217
|
+
}
|
|
218
|
+
.schedule .next {
|
|
219
|
+
margin-left: auto;
|
|
220
|
+
font-size: 13px;
|
|
221
|
+
opacity: 0.7;
|
|
222
|
+
}
|
|
223
|
+
.schedule .tag.running {
|
|
224
|
+
border-color: var(--accent);
|
|
225
|
+
color: var(--accent);
|
|
226
|
+
}
|
|
227
|
+
.schedule .tag.bad {
|
|
228
|
+
border-color: var(--warn, #e5a50a);
|
|
229
|
+
}
|
|
230
|
+
.schedule .cwd {
|
|
231
|
+
font-size: 13px;
|
|
232
|
+
opacity: 0.7;
|
|
233
|
+
word-break: break-all;
|
|
234
|
+
}
|
|
235
|
+
.schedule .row,
|
|
236
|
+
.trigger-row {
|
|
237
|
+
display: flex;
|
|
238
|
+
gap: 6px;
|
|
239
|
+
align-items: center;
|
|
240
|
+
flex-wrap: wrap;
|
|
241
|
+
}
|
|
242
|
+
.add-form {
|
|
243
|
+
display: flex;
|
|
244
|
+
flex-direction: column;
|
|
245
|
+
gap: 8px;
|
|
246
|
+
padding: 10px;
|
|
247
|
+
border: 1px solid var(--line);
|
|
248
|
+
border-radius: 10px;
|
|
249
|
+
}
|
|
250
|
+
.add-form label {
|
|
251
|
+
display: flex;
|
|
252
|
+
flex-direction: column;
|
|
253
|
+
gap: 3px;
|
|
254
|
+
font-size: 13px;
|
|
255
|
+
opacity: 0.85;
|
|
256
|
+
}
|
|
257
|
+
.add-form input,
|
|
258
|
+
.add-form textarea,
|
|
259
|
+
.add-form select {
|
|
260
|
+
font: inherit;
|
|
261
|
+
font-size: 15px;
|
|
262
|
+
padding: 5px 8px;
|
|
263
|
+
color: var(--fg);
|
|
264
|
+
background: transparent;
|
|
265
|
+
border: 1px solid var(--line);
|
|
266
|
+
border-radius: 8px;
|
|
267
|
+
}
|
|
268
|
+
.add-form .inline {
|
|
269
|
+
flex-direction: row;
|
|
270
|
+
align-items: center;
|
|
271
|
+
gap: 5px;
|
|
272
|
+
opacity: 1;
|
|
273
|
+
}
|
|
274
|
+
.add-form input.num {
|
|
275
|
+
width: 72px;
|
|
276
|
+
}
|
|
277
|
+
.add-form .muted {
|
|
278
|
+
font-size: 13px;
|
|
279
|
+
opacity: 0.6;
|
|
280
|
+
}
|
|
281
|
+
.spin {
|
|
282
|
+
animation: spin 1s linear infinite;
|
|
283
|
+
}
|
|
284
|
+
@keyframes spin {
|
|
285
|
+
to {
|
|
286
|
+
transform: rotate(360deg);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
</style>
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
} from "lucide-vue-next";
|
|
16
16
|
import DeviceIcon from "./DeviceIcon.vue";
|
|
17
17
|
import type { TreeNode } from "@sdk/models";
|
|
18
|
-
import { ago } from "../client/store";
|
|
18
|
+
import { ago, hubVersion } from "../client/store";
|
|
19
19
|
import { branchOf } from "../client/session-git";
|
|
20
20
|
|
|
21
21
|
const props = defineProps<{
|
|
@@ -42,6 +42,12 @@ const background = computed(() =>
|
|
|
42
42
|
: (agent.value?.background ?? 0),
|
|
43
43
|
);
|
|
44
44
|
const busy = computed(() => session.value?.busy || agent.value?.busy);
|
|
45
|
+
/** Behind the hub's build: devices self-update, this is only a hint. */
|
|
46
|
+
const behind = computed(() => {
|
|
47
|
+
const theirs = device.value?.info?.packageVersion;
|
|
48
|
+
const ours = hubVersion.value;
|
|
49
|
+
return Boolean(theirs && ours && ours !== "unknown" && theirs !== ours);
|
|
50
|
+
});
|
|
45
51
|
const statusText = computed(() => {
|
|
46
52
|
const d = device.value;
|
|
47
53
|
if (!d) return "";
|
|
@@ -113,6 +119,12 @@ const title = computed(() => {
|
|
|
113
119
|
<DeviceIcon :device="device" :size="16" />
|
|
114
120
|
<b class="name">{{ label }}</b>
|
|
115
121
|
<span class="badge">{{ device.kind }}</span>
|
|
122
|
+
<span
|
|
123
|
+
v-if="behind"
|
|
124
|
+
class="tag update"
|
|
125
|
+
:title="`device runs ${device?.info?.packageVersion ?? '?'}; hub runs ${hubVersion}. Devices self-update: dpi update`"
|
|
126
|
+
>update</span
|
|
127
|
+
>
|
|
116
128
|
<span class="meta" :class="{ err: dot === 'err' }">{{ statusText }}</span>
|
|
117
129
|
<span class="acts" @click.stop>
|
|
118
130
|
<button
|