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
|
@@ -188,6 +188,23 @@ export function v1(
|
|
|
188
188
|
r.post("/projects/:id/archive", route(async (req, res) => res.json(await store.archiveProject(param(req, "id")))));
|
|
189
189
|
r.post("/projects/:id/unarchive", route(async (req, res) => res.json(await store.unarchiveProject(param(req, "id")))));
|
|
190
190
|
|
|
191
|
+
// ---------------------------------------------------- notifications
|
|
192
|
+
// Outbound fan-out (webhook/ntfy). Configured here, delivered by the device.
|
|
193
|
+
r.get("/notify/sinks", (_req, res) => res.json({ sinks: store.notifySinkList() }));
|
|
194
|
+
r.post("/notify/sinks", route(async (req, res) => res.status(201).json(await store.createNotifySink(req.body ?? {}))));
|
|
195
|
+
r.patch("/notify/sinks/:id", route(async (req, res) => res.json(await store.updateNotifySink(param(req, "id"), req.body ?? {}))));
|
|
196
|
+
r.delete("/notify/sinks/:id", route(async (req, res) => res.json(await store.removeNotifySink(param(req, "id")))));
|
|
197
|
+
r.post("/notify/test", route(async (_req, res) => res.json({ results: await store.testNotifySinks() })));
|
|
198
|
+
|
|
199
|
+
// -------------------------------------------------------- schedules
|
|
200
|
+
// The device owns execution (systemd/cron are deliberately rejected by config);
|
|
201
|
+
// these routes only read and edit the schedule records.
|
|
202
|
+
r.get("/schedules", (_req, res) => res.json({ schedules: store.scheduleList() }));
|
|
203
|
+
r.post("/schedules", route(async (req, res) => res.status(201).json(await store.createSchedule(req.body ?? {}))));
|
|
204
|
+
r.patch("/schedules/:id", route(async (req, res) => res.json(await store.updateSchedule(param(req, "id"), req.body ?? {}))));
|
|
205
|
+
r.delete("/schedules/:id", route(async (req, res) => res.json(await store.removeSchedule(param(req, "id")))));
|
|
206
|
+
r.post("/schedules/:id/run", route(async (req, res) => res.json(await store.runScheduleNow(param(req, "id")))));
|
|
207
|
+
|
|
191
208
|
// ---------------------------------------------------------- sessions
|
|
192
209
|
r.get("/sessions", route(async (_req, res) => res.json((await store.tree()).sessions)));
|
|
193
210
|
r.post("/sessions", create, route(async (req, res) => res.status(201).json(await store.create(req.body ?? {}))));
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `dpi schedule` — scheduled sessions from the CLI (checklist Wave 2).
|
|
3
|
+
*
|
|
4
|
+
* The device owns the clock: this command only edits and reads the schedule
|
|
5
|
+
* records over the local device API, so the running daemon picks changes up
|
|
6
|
+
* without a restart. Same endpoint resolution as `dpi doctor`.
|
|
7
|
+
*/
|
|
8
|
+
import { authHeaders, deviceEndpoint, defaultDoctorIo, type DoctorIo } from "./doctor.js";
|
|
9
|
+
|
|
10
|
+
export interface ScheduleView {
|
|
11
|
+
id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
cwd: string;
|
|
14
|
+
model: { provider: string; modelId: string };
|
|
15
|
+
prompt: string;
|
|
16
|
+
everyMinutes?: number;
|
|
17
|
+
dailyAt?: string;
|
|
18
|
+
enabled: boolean;
|
|
19
|
+
nextRunAt: number | null;
|
|
20
|
+
lastRunAt?: number;
|
|
21
|
+
lastSessionId?: string;
|
|
22
|
+
lastOutcome?: "ok" | "failed";
|
|
23
|
+
lastError?: string;
|
|
24
|
+
running: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const SCHEDULE_HELP = `dpi schedule — scheduled sessions (the device owns the clock)
|
|
28
|
+
|
|
29
|
+
dpi schedule list
|
|
30
|
+
dpi schedule add --name <name> --cwd <dir> --prompt <text> --model <provider>/<model>
|
|
31
|
+
(--every <minutes> | --daily HH:MM) [--disabled]
|
|
32
|
+
dpi schedule enable|disable <id-prefix>
|
|
33
|
+
dpi schedule run <id-prefix>
|
|
34
|
+
dpi schedule remove <id-prefix>
|
|
35
|
+
|
|
36
|
+
--every N interval trigger, 5–1440 minutes
|
|
37
|
+
--daily HH:MM daily trigger, local time
|
|
38
|
+
A run creates a fresh session (named "<schedule> · <time>") and sends the prompt
|
|
39
|
+
to its root agent.`;
|
|
40
|
+
|
|
41
|
+
/** doctor's IO (env file, token, fetch) plus the two print hooks a CLI needs. */
|
|
42
|
+
export interface ScheduleIo extends DoctorIo {
|
|
43
|
+
print: (line: string) => void;
|
|
44
|
+
printErr: (line: string) => void;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const defaultScheduleIo = (): ScheduleIo => ({
|
|
48
|
+
...defaultDoctorIo(),
|
|
49
|
+
print: (line) => process.stdout.write(`${line}\n`),
|
|
50
|
+
printErr: (line) => process.stderr.write(`${line}\n`),
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const flag = (argv: readonly string[], name: string): string | undefined => {
|
|
54
|
+
const i = argv.indexOf(name);
|
|
55
|
+
return i >= 0 ? argv[i + 1] : undefined;
|
|
56
|
+
};
|
|
57
|
+
const positional = (argv: readonly string[]): string[] =>
|
|
58
|
+
argv.filter((arg, i) => !arg.startsWith("--") && !(i > 0 && argv[i - 1]?.startsWith("--")));
|
|
59
|
+
|
|
60
|
+
async function call<T>(
|
|
61
|
+
io: ScheduleIo,
|
|
62
|
+
method: string,
|
|
63
|
+
path: string,
|
|
64
|
+
body?: unknown,
|
|
65
|
+
): Promise<{ ok: true; data: T } | { ok: false; error: string }> {
|
|
66
|
+
const cfg = deviceEndpoint(io);
|
|
67
|
+
if (!cfg.token) return { ok: false, error: `no DPI_TOKEN (looked in ${cfg.envFile})` };
|
|
68
|
+
try {
|
|
69
|
+
const res = await io.fetchImpl(`${cfg.baseUrl}${path}`, {
|
|
70
|
+
method,
|
|
71
|
+
headers: {
|
|
72
|
+
...authHeaders(cfg.token),
|
|
73
|
+
...(body === undefined ? {} : { "content-type": "application/json" }),
|
|
74
|
+
},
|
|
75
|
+
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
76
|
+
signal: AbortSignal.timeout(io.timeoutMs),
|
|
77
|
+
});
|
|
78
|
+
const parsed = (await res.json().catch(() => ({}))) as Record<string, unknown>;
|
|
79
|
+
if (!res.ok) return { ok: false, error: `${res.status} ${(parsed as { error?: { message?: string } })?.error?.message ?? ""}`.trim() };
|
|
80
|
+
return { ok: true, data: parsed as T };
|
|
81
|
+
} catch (e) {
|
|
82
|
+
return { ok: false, error: e instanceof Error ? e.message : String(e) };
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const when = (at: number | null | undefined): string => {
|
|
87
|
+
if (!at) return "—";
|
|
88
|
+
const delta = at - Date.now();
|
|
89
|
+
const mins = Math.round(Math.abs(delta) / 60_000);
|
|
90
|
+
const human = mins < 60 ? `${mins}m` : mins < 1440 ? `${Math.round(mins / 60)}h` : `${Math.round(mins / 1440)}d`;
|
|
91
|
+
return delta >= 0 ? `in ${human}` : `${human} ago`;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const trigger = (s: ScheduleView) => (s.everyMinutes ? `every ${s.everyMinutes}m` : `daily ${s.dailyAt}`);
|
|
95
|
+
|
|
96
|
+
export function formatSchedules(list: readonly ScheduleView[]): string[] {
|
|
97
|
+
if (!list.length) return ["no schedules. Add one with `dpi schedule add --help`."];
|
|
98
|
+
return list.map((s) => {
|
|
99
|
+
const state = !s.enabled ? "disabled" : s.running ? "running" : "enabled";
|
|
100
|
+
const outcome = s.lastOutcome ? ` last ${s.lastOutcome}${s.lastError ? ` (${s.lastError.slice(0, 40)})` : ""}` : "";
|
|
101
|
+
return `${s.id.slice(0, 8)} ${s.name} — ${trigger(s)}, ${state}, next ${when(s.nextRunAt)}${outcome}\n ${s.cwd}`;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Resolve an id prefix the way a human types it (`dpi schedule run 3f2a`). */
|
|
106
|
+
export function matchSchedule(list: readonly ScheduleView[], prefix: string): ScheduleView[] {
|
|
107
|
+
const needle = prefix.toLowerCase();
|
|
108
|
+
return list.filter((s) => s.id.toLowerCase().startsWith(needle));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export async function scheduleCli(argv: readonly string[], io: ScheduleIo = defaultScheduleIo()): Promise<number> {
|
|
112
|
+
const [sub, ...rest] = argv;
|
|
113
|
+
if (sub === "--help" || sub === "-h") {
|
|
114
|
+
io.print(SCHEDULE_HELP);
|
|
115
|
+
return 0;
|
|
116
|
+
}
|
|
117
|
+
// No subcommand lists, like `dpi device` with no verb shows the device.
|
|
118
|
+
if (!sub || sub === "list") {
|
|
119
|
+
const listed = await call<{ schedules: ScheduleView[] }>(io, "GET", "/v1/schedules");
|
|
120
|
+
if (!listed.ok) {
|
|
121
|
+
io.printErr(`dpi schedule: ${listed.error}`);
|
|
122
|
+
return 1;
|
|
123
|
+
}
|
|
124
|
+
for (const line of formatSchedules(listed.data.schedules ?? [])) io.print(line);
|
|
125
|
+
return 0;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (sub === "add") {
|
|
129
|
+
const every = flag(rest, "--every");
|
|
130
|
+
const daily = flag(rest, "--daily");
|
|
131
|
+
const body = {
|
|
132
|
+
name: flag(rest, "--name"),
|
|
133
|
+
cwd: flag(rest, "--cwd"),
|
|
134
|
+
prompt: flag(rest, "--prompt"),
|
|
135
|
+
model: (() => {
|
|
136
|
+
const raw = flag(rest, "--model") ?? "";
|
|
137
|
+
const slash = raw.indexOf("/");
|
|
138
|
+
return slash > 0 ? { provider: raw.slice(0, slash), modelId: raw.slice(slash + 1) } : undefined;
|
|
139
|
+
})(),
|
|
140
|
+
...(every ? { everyMinutes: Number(every) } : {}),
|
|
141
|
+
...(daily ? { dailyAt: daily } : {}),
|
|
142
|
+
...(rest.includes("--disabled") ? { enabled: false } : {}),
|
|
143
|
+
};
|
|
144
|
+
if (!body.name || !body.cwd || !body.prompt || !body.model) {
|
|
145
|
+
io.printErr(`dpi schedule add: --name, --cwd, --prompt and --model are required\n\n${SCHEDULE_HELP}`);
|
|
146
|
+
return 2;
|
|
147
|
+
}
|
|
148
|
+
const created = await call<ScheduleView>(io, "POST", "/v1/schedules", body);
|
|
149
|
+
if (!created.ok) {
|
|
150
|
+
io.printErr(`dpi schedule: ${created.error}`);
|
|
151
|
+
return 1;
|
|
152
|
+
}
|
|
153
|
+
io.print(`created ${created.data.id.slice(0, 8)} — ${created.data.name}, ${trigger(created.data)}, next ${when(created.data.nextRunAt)}`);
|
|
154
|
+
return 0;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const prefix = positional(rest)[0];
|
|
158
|
+
if (!prefix) {
|
|
159
|
+
io.printErr(`dpi schedule ${sub}: an id prefix is required\n\n${SCHEDULE_HELP}`);
|
|
160
|
+
return 2;
|
|
161
|
+
}
|
|
162
|
+
const listed = await call<{ schedules: ScheduleView[] }>(io, "GET", "/v1/schedules");
|
|
163
|
+
if (!listed.ok) {
|
|
164
|
+
io.printErr(`dpi schedule: ${listed.error}`);
|
|
165
|
+
return 1;
|
|
166
|
+
}
|
|
167
|
+
const matches = matchSchedule(listed.data.schedules ?? [], prefix);
|
|
168
|
+
if (!matches.length) {
|
|
169
|
+
io.printErr(`dpi schedule: no schedule starts with '${prefix}'`);
|
|
170
|
+
return 1;
|
|
171
|
+
}
|
|
172
|
+
if (matches.length > 1) {
|
|
173
|
+
io.printErr(`dpi schedule: '${prefix}' matches ${matches.length} schedules — be more specific:`);
|
|
174
|
+
for (const m of matches) io.printErr(` ${m.id.slice(0, 8)} ${m.name}`);
|
|
175
|
+
return 2;
|
|
176
|
+
}
|
|
177
|
+
const target = matches[0];
|
|
178
|
+
|
|
179
|
+
if (sub === "enable" || sub === "disable") {
|
|
180
|
+
const patched = await call<ScheduleView>(io, "PATCH", `/v1/schedules/${target.id}`, {
|
|
181
|
+
enabled: sub === "enable",
|
|
182
|
+
});
|
|
183
|
+
if (!patched.ok) {
|
|
184
|
+
io.printErr(`dpi schedule: ${patched.error}`);
|
|
185
|
+
return 1;
|
|
186
|
+
}
|
|
187
|
+
io.print(`${sub}d ${target.id.slice(0, 8)} — next ${when(patched.data.nextRunAt)}`);
|
|
188
|
+
return 0;
|
|
189
|
+
}
|
|
190
|
+
if (sub === "run") {
|
|
191
|
+
io.print(`${target.name}: running…`);
|
|
192
|
+
const ran = await call<ScheduleView>(io, "POST", `/v1/schedules/${target.id}/run`, {});
|
|
193
|
+
if (!ran.ok) {
|
|
194
|
+
io.printErr(`dpi schedule: ${ran.error}`);
|
|
195
|
+
return 1;
|
|
196
|
+
}
|
|
197
|
+
io.print(`${ran.data.lastOutcome ?? "ok"}${ran.data.lastError ? ` — ${ran.data.lastError}` : ""}; next ${when(ran.data.nextRunAt)}`);
|
|
198
|
+
return ran.data.lastOutcome === "failed" ? 1 : 0;
|
|
199
|
+
}
|
|
200
|
+
if (sub === "remove") {
|
|
201
|
+
const removed = await call<{ removed: boolean }>(io, "DELETE", `/v1/schedules/${target.id}`);
|
|
202
|
+
if (!removed.ok) {
|
|
203
|
+
io.printErr(`dpi schedule: ${removed.error}`);
|
|
204
|
+
return 1;
|
|
205
|
+
}
|
|
206
|
+
io.print(`removed ${target.id.slice(0, 8)} — ${target.name}`);
|
|
207
|
+
return 0;
|
|
208
|
+
}
|
|
209
|
+
io.printErr(`dpi schedule: unknown subcommand '${sub}'\n\n${SCHEDULE_HELP}`);
|
|
210
|
+
return 2;
|
|
211
|
+
}
|