my-durable 0.0.58 → 0.0.60
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/daemon.ts +48 -0
- package/apps/dpi-backend/src/doctor.ts +17 -4
- package/apps/dpi-backend/src/errors.ts +68 -1
- package/apps/dpi-backend/src/gc-cli.ts +52 -19
- package/apps/dpi-backend/src/gc.ts +3 -1
- package/apps/dpi-backend/src/main.ts +23 -3
- package/apps/dpi-backend/src/pi-config.ts +15 -6
- package/apps/dpi-backend/src/store.ts +220 -22
- package/apps/dpi-backend/src/tunnel.ts +24 -2
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/index-4Kyozhl0.js +81 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/{index-DxGrKN6X.css → index-BkSQ2clA.css} +1 -1
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/index.html +2 -2
- package/apps/dpi-playground/apps/dpi-playground-fe/src/App.vue +9 -2
- package/apps/dpi-playground/apps/dpi-playground-fe/src/client/dialog-escape.ts +13 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/client/export-bundle.ts +70 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/client/state-draft.ts +72 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/client/store.ts +15 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/ContextBar.vue +14 -3
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/Inspector.vue +82 -69
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/ModelPicker.vue +22 -4
- package/apps/dpi-playground/apps/dpi-playground-fe/src/components/PromptDialog.vue +3 -0
- package/apps/dpi-playground/apps/dpi-playground-fe/src/style.css +19 -0
- package/apps/dpi-playground/apps/dpi-playground-hub/src/main.ts +72 -30
- package/apps/dpi-playground/apps/dpi-playground-hub/src/mux.ts +13 -2
- package/apps/dpi-playground/apps/dpi-playground-hub/src/pairing.ts +38 -17
- package/apps/dpi-playground/apps/dpi-playground-hub/src/shares.ts +7 -1
- package/apps/dpi-tui/src/app.ts +108 -25
- package/apps/dpi-tui/src/commands.ts +16 -8
- package/apps/dpi-tui/src/main.ts +46 -19
- package/apps/dpi-tui/src/pickers.ts +4 -0
- package/apps/dpi-tui/src/scroll.ts +59 -0
- package/apps/dpi-tui/src/views.ts +17 -2
- package/apps/dpi-tui/src/wrap.ts +42 -0
- package/bin/dpi.mjs +83 -0
- package/package.json +1 -1
- package/apps/dpi-playground/apps/dpi-playground-fe/dist/assets/index-DC0Iicch.js +0 -81
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// Draft editing for the device-wide App State JSON (Inspector's State tab).
|
|
2
|
+
// A draft always belongs to one device feed at one revision: switching devices
|
|
3
|
+
// resets it unconditionally (a context loss, never a silent cross-device
|
|
4
|
+
// write), a remote revision change while dirty is a conflict the user must
|
|
5
|
+
// resolve, and the text is pre-validated (debounced) with the same checks the
|
|
6
|
+
// device runs on save.
|
|
7
|
+
import { computed, ref, watch, type Ref } from "vue";
|
|
8
|
+
import { changeState, type AppState } from "@sdk/app-state";
|
|
9
|
+
import { message } from "./hub";
|
|
10
|
+
|
|
11
|
+
export type SharedStateFeed = { value: AppState; revision: number } | undefined;
|
|
12
|
+
|
|
13
|
+
/** The same checks the device runs on save — a root update through the SDK's
|
|
14
|
+
* changeState: JSON-object shape, the nesting and size limits, reserved
|
|
15
|
+
* field names. Empty when the text is a saveable state document. */
|
|
16
|
+
export function draftProblem(text: string): string {
|
|
17
|
+
try {
|
|
18
|
+
const value: unknown = JSON.parse(text);
|
|
19
|
+
if (!value || Array.isArray(value) || typeof value !== "object")
|
|
20
|
+
throw Error("App State must be a JSON object.");
|
|
21
|
+
changeState({}, { operation: "update", path: "", value: value as AppState });
|
|
22
|
+
return "";
|
|
23
|
+
} catch (e) {
|
|
24
|
+
return message(e);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function useStateDraft(shared: Ref<SharedStateFeed>, deviceId: Ref<string | undefined>) {
|
|
29
|
+
const draft = ref("");
|
|
30
|
+
const baseline = ref("");
|
|
31
|
+
const revision = ref(0);
|
|
32
|
+
const draftDevice = ref<string>();
|
|
33
|
+
const saving = ref(false);
|
|
34
|
+
/** The draft's validation problem, refreshed (debounced) as the user types. */
|
|
35
|
+
const problem = ref("");
|
|
36
|
+
const dirty = computed(() => draft.value !== baseline.value);
|
|
37
|
+
/** The draft was loaded from another device — possible for one tick while a
|
|
38
|
+
* device switch settles; never a saveable state. */
|
|
39
|
+
const deviceChanged = computed(() => dirty.value && draftDevice.value !== deviceId.value);
|
|
40
|
+
const conflict = computed(
|
|
41
|
+
() => dirty.value && (deviceChanged.value || shared.value?.revision !== revision.value),
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
function reset() {
|
|
45
|
+
draft.value = JSON.stringify(shared.value?.value ?? {}, null, 2);
|
|
46
|
+
baseline.value = draft.value;
|
|
47
|
+
revision.value = shared.value?.revision ?? 0;
|
|
48
|
+
draftDevice.value = deviceId.value;
|
|
49
|
+
problem.value = "";
|
|
50
|
+
}
|
|
51
|
+
/** Adopt a successful save's result: the saved text becomes the new
|
|
52
|
+
* baseline at the device's new revision. */
|
|
53
|
+
function commit(value: unknown, atRevision: number) {
|
|
54
|
+
draft.value = JSON.stringify(value, null, 2);
|
|
55
|
+
baseline.value = draft.value;
|
|
56
|
+
revision.value = atRevision;
|
|
57
|
+
problem.value = "";
|
|
58
|
+
}
|
|
59
|
+
// A clean draft follows the feed; a dirty one keeps the user's text until a
|
|
60
|
+
// new revision turns it into a conflict.
|
|
61
|
+
watch(shared, () => !dirty.value && reset(), { immediate: true });
|
|
62
|
+
// A device switch is always a context loss: drop the draft, dirty or not.
|
|
63
|
+
watch(deviceId, () => reset());
|
|
64
|
+
// Pre-validate as the user types (debounced) so the depth/size limits
|
|
65
|
+
// surface before the Save click, not after it.
|
|
66
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
67
|
+
watch(draft, () => {
|
|
68
|
+
clearTimeout(timer);
|
|
69
|
+
timer = setTimeout(() => (problem.value = dirty.value ? draftProblem(draft.value) : ""), 250);
|
|
70
|
+
});
|
|
71
|
+
return { draft, dirty, conflict, deviceChanged, saving, problem, revision, reset, commit };
|
|
72
|
+
}
|
|
@@ -243,6 +243,21 @@ export const currentModel = computed(() => {
|
|
|
243
243
|
const m = agentState.value.agent.model;
|
|
244
244
|
return models.value.find((x) => x.provider === m?.provider && x.id === m?.modelId);
|
|
245
245
|
});
|
|
246
|
+
/** The configured model with provenance — the agent's model when set, else the
|
|
247
|
+
* model the session was created with. Raw ids: the pair may sit outside this
|
|
248
|
+
* device's catalog (picked on another device, or a newer catalog there), in
|
|
249
|
+
* which case modelInCatalog is undefined and the UI must say so instead of
|
|
250
|
+
* rendering as if no model were picked. */
|
|
251
|
+
export const sessionModel = computed(() => {
|
|
252
|
+
const m = agentState.value.agent.model;
|
|
253
|
+
if (m?.modelId) return m;
|
|
254
|
+
const s = sessionSummary.value;
|
|
255
|
+
return s?.model ? { provider: s.provider ?? "", modelId: s.model } : undefined;
|
|
256
|
+
});
|
|
257
|
+
export const modelInCatalog = computed(() => {
|
|
258
|
+
const m = sessionModel.value;
|
|
259
|
+
return m ? models.value.find((x) => x.provider === m.provider && x.id === m.modelId) : undefined;
|
|
260
|
+
});
|
|
246
261
|
|
|
247
262
|
/** Tools and extensions come from GET agent (not streamed); refresh on selection and config changes. */
|
|
248
263
|
export const detail = shallowRef<AgentDetail>();
|
|
@@ -13,8 +13,9 @@ import {
|
|
|
13
13
|
import {
|
|
14
14
|
agentState,
|
|
15
15
|
attempt,
|
|
16
|
-
|
|
16
|
+
modelInCatalog,
|
|
17
17
|
sessionHandle,
|
|
18
|
+
sessionModel,
|
|
18
19
|
sessionSummary,
|
|
19
20
|
ui,
|
|
20
21
|
} from "../client/store";
|
|
@@ -29,7 +30,14 @@ const k = (n: number) =>
|
|
|
29
30
|
: n >= 1000
|
|
30
31
|
? `${(n / 1000).toFixed(1)}k`
|
|
31
32
|
: String(n);
|
|
32
|
-
const window = computed(() =>
|
|
33
|
+
const window = computed(() => modelInCatalog.value?.contextWindow ?? 0);
|
|
34
|
+
/** A model IS set but this device's catalog does not list it (picked on
|
|
35
|
+
* another device, or a newer catalog there): raw ids plus a note — never the
|
|
36
|
+
* pick-a-model prompt, which reads as "nothing chosen". */
|
|
37
|
+
const offCatalog = computed(() => {
|
|
38
|
+
const m = sessionModel.value;
|
|
39
|
+
return m && !modelInCatalog.value ? `${m.provider ? `${m.provider} / ` : ""}${m.modelId}` : "";
|
|
40
|
+
});
|
|
33
41
|
|
|
34
42
|
/** The last reply's prompt plus output: what the next request starts from. */
|
|
35
43
|
const used = computed(() => {
|
|
@@ -145,7 +153,10 @@ function key(which: "auto" | "wait", e: KeyboardEvent) {
|
|
|
145
153
|
<Info :size="16" />Details
|
|
146
154
|
</button>
|
|
147
155
|
</div>
|
|
148
|
-
<div v-if="
|
|
156
|
+
<div v-if="offCatalog" class="hint">
|
|
157
|
+
{{ offCatalog }} — not in this device's catalog, so its context window is unknown here.
|
|
158
|
+
</div>
|
|
159
|
+
<div v-else-if="!window" class="hint">Pick a model to see its context window.</div>
|
|
149
160
|
<template v-else>
|
|
150
161
|
<div class="context-numbers">
|
|
151
162
|
<strong>{{ k(used) }}</strong
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
Pencil,
|
|
18
18
|
Server,
|
|
19
19
|
ShieldCheck,
|
|
20
|
+
Share2,
|
|
20
21
|
Wrench,
|
|
21
22
|
PanelLeftClose,
|
|
22
23
|
PanelLeftOpen,
|
|
@@ -40,6 +41,8 @@ import ExtensionsPanel from "./ExtensionsPanel.vue";
|
|
|
40
41
|
import ContextBar from "./ContextBar.vue";
|
|
41
42
|
import { deviceClient, hub, message } from "../client/hub";
|
|
42
43
|
import { toolSignature } from "../client/signature";
|
|
44
|
+
import { useExportBundle } from "../client/export-bundle";
|
|
45
|
+
import { useStateDraft } from "../client/state-draft";
|
|
43
46
|
import {
|
|
44
47
|
agentHandle,
|
|
45
48
|
agentState,
|
|
@@ -49,6 +52,7 @@ import {
|
|
|
49
52
|
detail,
|
|
50
53
|
device,
|
|
51
54
|
deviceFeed,
|
|
55
|
+
deviceId,
|
|
52
56
|
hideInspector,
|
|
53
57
|
icon,
|
|
54
58
|
inspectorExpanded,
|
|
@@ -59,6 +63,7 @@ import {
|
|
|
59
63
|
selected,
|
|
60
64
|
session,
|
|
61
65
|
sessionHandle,
|
|
66
|
+
sessionModel,
|
|
62
67
|
sessionSummary,
|
|
63
68
|
showInspector,
|
|
64
69
|
tasks,
|
|
@@ -94,7 +99,6 @@ const usageRows = computed(() => [
|
|
|
94
99
|
{ label: "Cache write", tokens: usage.value.cacheWrite, cost: usage.value.cacheWriteCost },
|
|
95
100
|
]);
|
|
96
101
|
const background = computed(() => tasks.value.filter((t) => t.background).length);
|
|
97
|
-
const exporting = ref(false);
|
|
98
102
|
|
|
99
103
|
function configure(
|
|
100
104
|
patch: Parameters<NonNullable<typeof agentHandle.value>["configure"]>[0],
|
|
@@ -114,8 +118,12 @@ async function downloadTranscript() {
|
|
|
114
118
|
const summary = sessionSummary.value;
|
|
115
119
|
if (!dev || !summary) return;
|
|
116
120
|
try {
|
|
117
|
-
const r = await deviceClient(dev.id)
|
|
118
|
-
|
|
121
|
+
const r = await deviceClient(dev.id)
|
|
122
|
+
.agent(summary.id, selected.value?.agentId ?? 1)
|
|
123
|
+
.transcript("markdown");
|
|
124
|
+
const blob = new Blob([typeof r === "string" ? r : JSON.stringify(r)], {
|
|
125
|
+
type: "text/markdown",
|
|
126
|
+
});
|
|
119
127
|
const a = document.createElement("a");
|
|
120
128
|
a.href = URL.createObjectURL(blob);
|
|
121
129
|
a.download = `${summary.name.replace(/[^\w.-]+/g, "_") || "session"}-${summary.id.slice(0, 8)}.md`;
|
|
@@ -128,28 +136,14 @@ async function downloadTranscript() {
|
|
|
128
136
|
}
|
|
129
137
|
|
|
130
138
|
/** Whole-session bundle (Wave 1b): manifest + record + every agent's
|
|
131
|
-
* transcript and config, zipped on the device (base64 over the tunnel).
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
const bytes = Uint8Array.from(atob(r.base64), (c) => c.charCodeAt(0));
|
|
140
|
-
const online = URL.createObjectURL(new Blob([bytes], { type: r.mime || "application/zip" }));
|
|
141
|
-
const a = document.createElement("a");
|
|
142
|
-
a.href = online;
|
|
143
|
-
a.download = r.filename;
|
|
144
|
-
a.click();
|
|
145
|
-
URL.revokeObjectURL(online);
|
|
146
|
-
notify(`Bundle downloaded (${Math.max(1, Math.round(r.bytes / 1024))} KiB).`);
|
|
147
|
-
} catch (e) {
|
|
148
|
-
notify(`bundle export failed: ${message(e).slice(0, 120)}`);
|
|
149
|
-
} finally {
|
|
150
|
-
exporting.value = false;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
139
|
+
* transcript and config, zipped on the device (base64 over the tunnel). The
|
|
140
|
+
* loop lives in client/export-bundle.ts: a failure stays inline here with a
|
|
141
|
+
* retry instead of living only in a vanishing toast. */
|
|
142
|
+
const {
|
|
143
|
+
exporting: exportingBundle,
|
|
144
|
+
error: bundleError,
|
|
145
|
+
run: downloadBundle,
|
|
146
|
+
} = useExportBundle(computed(() => ({ device: device.value, summary: sessionSummary.value })));
|
|
153
147
|
|
|
154
148
|
/**
|
|
155
149
|
* Conversation share (Wave 3): upload this session's transcripts to the hub
|
|
@@ -175,10 +169,15 @@ function shareTranscript() {
|
|
|
175
169
|
for (const agent of agents) {
|
|
176
170
|
const r = await client.agent(summary.id, agent.id).transcript("markdown");
|
|
177
171
|
const text =
|
|
178
|
-
typeof r === "string"
|
|
172
|
+
typeof r === "string"
|
|
173
|
+
? r
|
|
174
|
+
: ((r as { text?: string }).text ?? JSON.stringify(r, null, 2));
|
|
179
175
|
docs.push({ name: agent.name || `agent ${agent.id}`, markdown: text });
|
|
180
176
|
}
|
|
181
|
-
const share = await hub.createShare({
|
|
177
|
+
const share = await hub.createShare({
|
|
178
|
+
title: `${summary.name} · ${dev.name}`,
|
|
179
|
+
agents: docs,
|
|
180
|
+
});
|
|
182
181
|
const url = `${location.origin}${share.url}`;
|
|
183
182
|
await navigator.clipboard?.writeText(url).catch(() => {});
|
|
184
183
|
notify(`Share link copied — expires ${share.expiresAt.slice(0, 10)}.`);
|
|
@@ -224,14 +223,9 @@ watch(
|
|
|
224
223
|
},
|
|
225
224
|
{ immediate: true },
|
|
226
225
|
);
|
|
227
|
-
/** The current model with provenance: the agent's configured model
|
|
228
|
-
* else the model the session was created with
|
|
229
|
-
|
|
230
|
-
const m = agentState.value.agent.model;
|
|
231
|
-
if (m?.modelId) return m;
|
|
232
|
-
const s = sessionSummary.value;
|
|
233
|
-
return s?.model ? { provider: s.provider ?? "", modelId: s.model } : undefined;
|
|
234
|
-
});
|
|
226
|
+
/** The current model with provenance (store): the agent's configured model
|
|
227
|
+
* when set, else the model the session was created with — raw ids, which may
|
|
228
|
+
* not be in this device's catalog. */
|
|
235
229
|
/** Longest registered root wins — the same rule the device applies on create. */
|
|
236
230
|
const modelIsDefault = computed(() => {
|
|
237
231
|
const m = sessionModel.value;
|
|
@@ -258,22 +252,21 @@ const modelLine = computed(
|
|
|
258
252
|
// ------------------------------------------------------------ App State (device-wide document)
|
|
259
253
|
|
|
260
254
|
const shared = deviceFeed.sharedState;
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
255
|
+
/** The draft belongs to one device feed at one revision (client/state-draft):
|
|
256
|
+
* a device switch resets it unconditionally — never a cross-device write —
|
|
257
|
+
* and the text is pre-validated (debounced) with the SDK's own checks. */
|
|
258
|
+
const {
|
|
259
|
+
draft: stateDraft,
|
|
260
|
+
dirty: stateDirty,
|
|
261
|
+
conflict: stateConflict,
|
|
262
|
+
deviceChanged: stateDeviceChanged,
|
|
263
|
+
problem: stateProblem,
|
|
264
|
+
revision: stateDraftRevision,
|
|
265
|
+
reset: resetStateDraft,
|
|
266
|
+
commit: commitStateDraft,
|
|
267
|
+
} = useStateDraft(shared, deviceId);
|
|
264
268
|
const stateSaving = ref(false);
|
|
265
269
|
const stateError = ref("");
|
|
266
|
-
const stateDirty = computed(() => stateDraft.value !== stateBaseline.value);
|
|
267
|
-
const stateConflict = computed(
|
|
268
|
-
() => stateDirty.value && shared.value?.revision !== stateDraftRevision.value,
|
|
269
|
-
);
|
|
270
|
-
function resetStateDraft() {
|
|
271
|
-
stateDraft.value = json(shared.value?.value ?? {});
|
|
272
|
-
stateBaseline.value = stateDraft.value;
|
|
273
|
-
stateDraftRevision.value = shared.value?.revision ?? 0;
|
|
274
|
-
stateError.value = "";
|
|
275
|
-
}
|
|
276
|
-
watch(shared, () => !stateDirty.value && resetStateDraft(), { immediate: true });
|
|
277
270
|
|
|
278
271
|
async function editState(change: StateChange) {
|
|
279
272
|
if (stateSaving.value || !agentHandle.value) return;
|
|
@@ -288,7 +281,7 @@ async function editState(change: StateChange) {
|
|
|
288
281
|
}
|
|
289
282
|
}
|
|
290
283
|
async function saveStateJson() {
|
|
291
|
-
if (stateSaving.value || !agentHandle.value) return;
|
|
284
|
+
if (stateSaving.value || stateConflict.value || !agentHandle.value) return;
|
|
292
285
|
stateError.value = "";
|
|
293
286
|
stateSaving.value = true;
|
|
294
287
|
try {
|
|
@@ -301,9 +294,7 @@ async function saveStateJson() {
|
|
|
301
294
|
value,
|
|
302
295
|
expectedRevision: stateDraftRevision.value,
|
|
303
296
|
});
|
|
304
|
-
|
|
305
|
-
stateBaseline.value = stateDraft.value;
|
|
306
|
-
stateDraftRevision.value = saved.revision;
|
|
297
|
+
commitStateDraft(saved.value, saved.revision);
|
|
307
298
|
notify("Shared App State saved.");
|
|
308
299
|
} catch (e) {
|
|
309
300
|
stateError.value = message(e);
|
|
@@ -385,23 +376,23 @@ const offeredTools = computed(() => detail.value?.tools.filter((t) => t.offered)
|
|
|
385
376
|
aria-label="Rename session"
|
|
386
377
|
@click="renameSession"
|
|
387
378
|
>
|
|
388
|
-
<Pencil :size="18"
|
|
389
|
-
|
|
379
|
+
<Pencil :size="18" /></button
|
|
380
|
+
><button
|
|
390
381
|
class="icon-button"
|
|
391
382
|
title="Download transcript (markdown)"
|
|
392
383
|
aria-label="Download transcript"
|
|
393
384
|
@click="downloadTranscript"
|
|
394
385
|
>
|
|
395
|
-
<Download :size="18"
|
|
396
|
-
|
|
386
|
+
<Download :size="18" /></button
|
|
387
|
+
><button
|
|
397
388
|
class="icon-button"
|
|
398
389
|
title="Download session bundle (.zip: manifest, transcripts, configs)"
|
|
399
390
|
aria-label="Download session bundle"
|
|
400
|
-
:disabled="
|
|
391
|
+
:disabled="exportingBundle"
|
|
401
392
|
@click="downloadBundle"
|
|
402
393
|
>
|
|
403
|
-
<PackageOpen :size="18"
|
|
404
|
-
|
|
394
|
+
<PackageOpen :size="18" /></button
|
|
395
|
+
><button
|
|
405
396
|
class="icon-button"
|
|
406
397
|
title="Share a public read-only link to this transcript"
|
|
407
398
|
aria-label="Share transcript"
|
|
@@ -425,9 +416,17 @@ const offeredTools = computed(() => detail.value?.tools.filter((t) => t.offered)
|
|
|
425
416
|
<span class="status-pill" :class="{ working: busy }"
|
|
426
417
|
><i />{{ busy ? "Working" : "Idle" }}</span
|
|
427
418
|
><span v-if="background" class="background-pill">{{ background }} background</span
|
|
428
|
-
><span class="saved" :title="device?.id"
|
|
419
|
+
><span class="saved" :title="device?.id"
|
|
420
|
+
><Server :size="18" />{{ device?.name ?? device?.id }}</span
|
|
421
|
+
>
|
|
429
422
|
<TunnelStatusBar v-if="device" :device="device" />
|
|
430
423
|
</div>
|
|
424
|
+
<p v-if="bundleError" class="message-error" role="alert">
|
|
425
|
+
{{ bundleError }}
|
|
426
|
+
<button class="small" :disabled="exportingBundle" @click="downloadBundle">
|
|
427
|
+
retry
|
|
428
|
+
</button>
|
|
429
|
+
</p>
|
|
431
430
|
</section>
|
|
432
431
|
<TokenManager v-if="device" :device="device" />
|
|
433
432
|
<section class="model-section">
|
|
@@ -510,9 +509,10 @@ const offeredTools = computed(() => detail.value?.tools.filter((t) => t.offered)
|
|
|
510
509
|
<Braces :size="18" />
|
|
511
510
|
</div>
|
|
512
511
|
<p class="hint app-state-description">
|
|
513
|
-
One shared JSON object for every agent, session and fork on
|
|
514
|
-
your agents can read, create, update or delete
|
|
515
|
-
and persist across closed browsers, interrupted
|
|
512
|
+
One shared JSON object for every agent, session and fork on
|
|
513
|
+
{{ device?.name ?? device?.id }}. You and your agents can read, create, update or delete
|
|
514
|
+
values and fields. Changes appear live and persist across closed browsers, interrupted
|
|
515
|
+
agents and backend restarts.
|
|
516
516
|
</p>
|
|
517
517
|
<textarea
|
|
518
518
|
v-model="stateDraft"
|
|
@@ -522,10 +522,16 @@ const offeredTools = computed(() => detail.value?.tools.filter((t) => t.offered)
|
|
|
522
522
|
:disabled="stateSaving || !shared"
|
|
523
523
|
rows="12"
|
|
524
524
|
/>
|
|
525
|
+
<p class="hint state-limits">
|
|
526
|
+
One JSON object, at most 24 levels of nesting and 100,000 characters, checked as you
|
|
527
|
+
type.
|
|
528
|
+
</p>
|
|
525
529
|
<div class="state-json-actions">
|
|
526
|
-
<span v-if="stateConflict" class="hint"
|
|
527
|
-
|
|
528
|
-
|
|
530
|
+
<span v-if="stateConflict" class="hint">{{
|
|
531
|
+
stateDeviceChanged
|
|
532
|
+
? "Device changed since this draft loaded. Load the latest JSON before saving."
|
|
533
|
+
: "State changed elsewhere. Load the latest JSON before saving."
|
|
534
|
+
}}</span>
|
|
529
535
|
<button
|
|
530
536
|
v-if="stateDirty"
|
|
531
537
|
class="secondary"
|
|
@@ -536,12 +542,13 @@ const offeredTools = computed(() => detail.value?.tools.filter((t) => t.offered)
|
|
|
536
542
|
</button>
|
|
537
543
|
<button
|
|
538
544
|
class="primary small"
|
|
539
|
-
:disabled="!stateDirty || stateSaving || stateConflict"
|
|
545
|
+
:disabled="!stateDirty || stateSaving || stateConflict || !!stateProblem"
|
|
540
546
|
@click="saveStateJson"
|
|
541
547
|
>
|
|
542
548
|
{{ stateSaving ? "Saving…" : "Save JSON" }}
|
|
543
549
|
</button>
|
|
544
550
|
</div>
|
|
551
|
+
<p v-if="stateProblem" class="message-error" role="alert">{{ stateProblem }}</p>
|
|
545
552
|
<p v-if="stateError" class="message-error" role="alert">{{ stateError }}</p>
|
|
546
553
|
<StateEditor
|
|
547
554
|
:value="shared?.value ?? {}"
|
|
@@ -624,4 +631,10 @@ const offeredTools = computed(() => detail.value?.tools.filter((t) => t.offered)
|
|
|
624
631
|
</aside>
|
|
625
632
|
</template>
|
|
626
633
|
|
|
627
|
-
<style scoped
|
|
634
|
+
<style scoped>
|
|
635
|
+
.usage-total th,
|
|
636
|
+
.usage-total td {
|
|
637
|
+
border-top: 1px solid var(--line);
|
|
638
|
+
font-weight: 650;
|
|
639
|
+
}
|
|
640
|
+
</style>
|
|
@@ -4,7 +4,6 @@ import { Check, X } from "lucide-vue-next";
|
|
|
4
4
|
import type { ModelInfo } from "@sdk/api";
|
|
5
5
|
import {
|
|
6
6
|
agentHandle,
|
|
7
|
-
agentState,
|
|
8
7
|
attempt,
|
|
9
8
|
device,
|
|
10
9
|
icon,
|
|
@@ -12,6 +11,7 @@ import {
|
|
|
12
11
|
notify,
|
|
13
12
|
number,
|
|
14
13
|
refreshDetail,
|
|
14
|
+
sessionModel,
|
|
15
15
|
} from "../client/store";
|
|
16
16
|
|
|
17
17
|
const emit = defineEmits<{ close: [] }>();
|
|
@@ -25,9 +25,20 @@ const filtered = computed(() =>
|
|
|
25
25
|
`${m.name} ${m.id} ${m.tier}`.toLowerCase().includes(search.value.toLowerCase()),
|
|
26
26
|
),
|
|
27
27
|
);
|
|
28
|
-
const isCurrent = (m: ModelInfo) =>
|
|
29
|
-
|
|
30
|
-
m.
|
|
28
|
+
const isCurrent = (m: ModelInfo) => {
|
|
29
|
+
const c = sessionModel.value;
|
|
30
|
+
return !!c && m.id === c.modelId && m.provider === c.provider;
|
|
31
|
+
};
|
|
32
|
+
/** The active model when this device's catalog does not list it (picked on
|
|
33
|
+
* another device, or a newer catalog there): pinned and disabled, so the
|
|
34
|
+
* current model is always visible — searching the catalog alone cannot find
|
|
35
|
+
* it. */
|
|
36
|
+
const offCatalog = computed(() => {
|
|
37
|
+
const m = sessionModel.value;
|
|
38
|
+
return m && !models.value.some((x) => x.provider === m.provider && x.id === m.modelId)
|
|
39
|
+
? m
|
|
40
|
+
: undefined;
|
|
41
|
+
});
|
|
31
42
|
|
|
32
43
|
async function choose(m: ModelInfo) {
|
|
33
44
|
const done = await attempt(() =>
|
|
@@ -60,6 +71,13 @@ async function choose(m: ModelInfo) {
|
|
|
60
71
|
aria-label="Search models"
|
|
61
72
|
/>
|
|
62
73
|
<div class="model-list">
|
|
74
|
+
<div v-if="offCatalog" class="model-row off-catalog" aria-disabled="true">
|
|
75
|
+
<img :src="icon(offCatalog.modelId)" alt="" />
|
|
76
|
+
<div>
|
|
77
|
+
<strong>{{ offCatalog.modelId }}</strong>
|
|
78
|
+
<small>{{ offCatalog.provider }} / current · not in this device's catalog</small>
|
|
79
|
+
</div>
|
|
80
|
+
</div>
|
|
63
81
|
<button
|
|
64
82
|
v-for="m in filtered"
|
|
65
83
|
:key="`${m.provider}/${m.id}`"
|
|
@@ -28,6 +28,9 @@ async function submit() {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
onMounted(() => void nextTick(() => (input.value?.focus(), input.value?.select())));
|
|
31
|
+
// App's Escape policy asks whether an action is in flight: a busy dialog
|
|
32
|
+
// stays open (cf. client/dialog-escape.ts).
|
|
33
|
+
defineExpose({ busy });
|
|
31
34
|
</script>
|
|
32
35
|
|
|
33
36
|
<template>
|
|
@@ -1821,6 +1821,25 @@ svg {
|
|
|
1821
1821
|
gap: 5px;
|
|
1822
1822
|
flex: 1;
|
|
1823
1823
|
}
|
|
1824
|
+
/* The pinned current model outside this device's catalog: laid out like a
|
|
1825
|
+
catalog row, but visibly inert — it cannot be chosen from here. */
|
|
1826
|
+
.model-list .model-row.off-catalog {
|
|
1827
|
+
width: 100%;
|
|
1828
|
+
display: flex;
|
|
1829
|
+
text-align: left;
|
|
1830
|
+
justify-content: flex-start;
|
|
1831
|
+
padding: 12px 10px;
|
|
1832
|
+
border-radius: 6px;
|
|
1833
|
+
gap: 12px;
|
|
1834
|
+
opacity: 0.75;
|
|
1835
|
+
cursor: default;
|
|
1836
|
+
}
|
|
1837
|
+
.model-list .model-row.off-catalog > div {
|
|
1838
|
+
display: flex;
|
|
1839
|
+
flex-direction: column;
|
|
1840
|
+
gap: 5px;
|
|
1841
|
+
flex: 1;
|
|
1842
|
+
}
|
|
1824
1843
|
.model-list strong {
|
|
1825
1844
|
font-size: 16px;
|
|
1826
1845
|
font-weight: 500;
|
|
@@ -130,6 +130,14 @@ const app = express();
|
|
|
130
130
|
// non-loopback direct connection is ignored (proxy-addr semantics).
|
|
131
131
|
app.set("trust proxy", isTrustedProxy);
|
|
132
132
|
app.disable("x-powered-by");
|
|
133
|
+
// Case-sensitive routes, matching the device: "/API/NETWORK" is a miss, not a
|
|
134
|
+
// silent alias of /api/network (route uniformity with the 0.0.58 device fix).
|
|
135
|
+
// Every hub caller already spells the mount lowercase — FE client (/api/...),
|
|
136
|
+
// TUI hub-feed/hub-mux (api/network, api/stream), and the public pairing
|
|
137
|
+
// ingress below; a case variant never carried different auth (audit R5).
|
|
138
|
+
// The app setting's name is Express's spelled-out form — "caseSensitive" is
|
|
139
|
+
// the Router option, silently ignored here (caught by the R5 test).
|
|
140
|
+
app.set("case sensitive routing", true);
|
|
133
141
|
// Every answer is non-sniffable; the admin API is never cacheable (it carries pairing codes and, on the
|
|
134
142
|
// pairing routes, a credential). Registered first so that refusals made further down carry them too.
|
|
135
143
|
app.use((req, res, next) => {
|
|
@@ -267,7 +275,11 @@ app.post("/api/pair/start", ...pairGuard, express.json({ limit: "16kb" }), (req,
|
|
|
267
275
|
return r.ok ? res.json(r.value) : pairErr(r, res);
|
|
268
276
|
});
|
|
269
277
|
app.post("/api/pair/verify", ...pairGuard, express.json({ limit: "16kb" }), async (req, res) => {
|
|
270
|
-
|
|
278
|
+
// Third arg (R6 F5): the origin the device actually dialed — when a signature
|
|
279
|
+
// fails under it but not under the configured hubOrigin, pairing.verify says
|
|
280
|
+
// origin_mismatch (with the DPI_HUB_ORIGIN hint) instead of counting an
|
|
281
|
+
// invalid signature toward the enrollment cancel limit.
|
|
282
|
+
const r = await pairing.verify(req.body, req.ip ?? "unknown", `${req.protocol}://${req.get("host")}`);
|
|
271
283
|
if (r.ok) return res.status(r.status).json(r.value);
|
|
272
284
|
pairErr(r, res);
|
|
273
285
|
});
|
|
@@ -343,6 +355,39 @@ app.post(
|
|
|
343
355
|
},
|
|
344
356
|
);
|
|
345
357
|
|
|
358
|
+
// ------------------------------------------------ conversation shares
|
|
359
|
+
// The shell (which holds the tunnel credentials) uploads prepared transcripts;
|
|
360
|
+
// the hub mints a tokenized PUBLIC link. The token is the capability, every
|
|
361
|
+
// share expires (retention is explicit — the checklist row demanded that
|
|
362
|
+
// decision up front), and the admin routes can kill one early.
|
|
363
|
+
//
|
|
364
|
+
// Registered BEFORE the global /api chain (same pattern as the pairing
|
|
365
|
+
// ingress): the chain's 256 KiB parser consumed the body first, so a 300 KB
|
|
366
|
+
// share 413'd before this route's 10 MiB parser ever ran (the 2 MB/agent,
|
|
367
|
+
// 8 MB/total limits in shares.ts were unreachable), and its apiRate bucket
|
|
368
|
+
// was charged twice. The full guard stack travels with the route.
|
|
369
|
+
const shares = await Shares.open(join(dpiHome(), "shares"));
|
|
370
|
+
app.post(
|
|
371
|
+
"/api/shares",
|
|
372
|
+
denialLogging(audit),
|
|
373
|
+
guard(allowedHosts),
|
|
374
|
+
apiRate,
|
|
375
|
+
express.json({ limit: "10mb" }),
|
|
376
|
+
adminAuth,
|
|
377
|
+
(req, res) => {
|
|
378
|
+
const body = req.body ?? {};
|
|
379
|
+
void shares
|
|
380
|
+
.create({ title: String(body.title ?? ""), agents: Array.isArray(body.agents) ? body.agents : [] })
|
|
381
|
+
.then((meta) =>
|
|
382
|
+
res.status(201).json({ token: meta.token, url: `/share/${meta.token}`, expiresAt: meta.expiresAt }),
|
|
383
|
+
)
|
|
384
|
+
.catch((e: unknown) => {
|
|
385
|
+
if (e instanceof ShareError) return res.status(400).json(err("invalid", e.message));
|
|
386
|
+
throw e;
|
|
387
|
+
});
|
|
388
|
+
},
|
|
389
|
+
);
|
|
390
|
+
|
|
346
391
|
// Admin /api surface: guarded, rate-bucketed per real client IP, 256 KiB JSON,
|
|
347
392
|
// and behind the admin credential (cookie or bearer).
|
|
348
393
|
app.use(
|
|
@@ -456,46 +501,28 @@ app.put(
|
|
|
456
501
|
res.json({ ok: true });
|
|
457
502
|
}),
|
|
458
503
|
);
|
|
459
|
-
//
|
|
460
|
-
//
|
|
461
|
-
// the hub mints a tokenized PUBLIC link. The token is the capability, every
|
|
462
|
-
// share expires (retention is explicit — the checklist row demanded that
|
|
463
|
-
// decision up front), and the admin routes can kill one early.
|
|
464
|
-
const shares = await Shares.open(join(dpiHome(), "shares"));
|
|
465
|
-
app.post(
|
|
466
|
-
"/api/shares",
|
|
467
|
-
denialLogging(audit),
|
|
468
|
-
apiRate,
|
|
469
|
-
express.json({ limit: "10mb" }),
|
|
470
|
-
adminAuth,
|
|
471
|
-
(req, res) => {
|
|
472
|
-
const body = req.body ?? {};
|
|
473
|
-
void shares
|
|
474
|
-
.create({ title: String(body.title ?? ""), agents: Array.isArray(body.agents) ? body.agents : [] })
|
|
475
|
-
.then((meta) =>
|
|
476
|
-
res.status(201).json({ token: meta.token, url: `/share/${meta.token}`, expiresAt: meta.expiresAt }),
|
|
477
|
-
)
|
|
478
|
-
.catch((e: unknown) => {
|
|
479
|
-
if (e instanceof ShareError) return res.status(400).json(err("invalid", e.message));
|
|
480
|
-
throw e;
|
|
481
|
-
});
|
|
482
|
-
},
|
|
483
|
-
);
|
|
504
|
+
// Share admin reads/kill (the POST lives above the global chain — its body
|
|
505
|
+
// needs the 10 MiB parser); the chain's adminAuth + 256 KiB parser cover these.
|
|
484
506
|
app.get("/api/shares", adminAuth, (_req, res) => void shares.list().then((list) => res.json({ shares: list })));
|
|
485
507
|
app.delete("/api/shares/:token", adminAuth, (req, res) =>
|
|
486
508
|
void shares.remove(String(req.params.token ?? "")).then((removed) => res.json({ removed })),
|
|
487
509
|
);
|
|
488
510
|
// The public page: transcripts only, no app shell, no scripts, inline-styled.
|
|
511
|
+
// Framing is refused explicitly: frame-ancestors is NOT a fetch directive, so
|
|
512
|
+
// it does not fall back to default-src and must be spelled out (a share page
|
|
513
|
+
// is public content — a frame is a clickjacking channel).
|
|
489
514
|
app.get("/share/:token", (req, res) => {
|
|
490
515
|
void shares.get(String(req.params.token ?? "")).then((doc) => {
|
|
491
516
|
if (!doc) {
|
|
492
517
|
res.status(404);
|
|
493
518
|
res.set("Content-Type", "text/html; charset=utf-8");
|
|
494
|
-
res.set("Content-Security-Policy", "default-src 'none'; style-src 'unsafe-inline'");
|
|
519
|
+
res.set("Content-Security-Policy", "default-src 'none'; style-src 'unsafe-inline'; frame-ancestors 'none'");
|
|
520
|
+
res.set("X-Frame-Options", "DENY");
|
|
495
521
|
return res.send(renderShareNotFound());
|
|
496
522
|
}
|
|
497
523
|
res.set("Content-Type", "text/html; charset=utf-8");
|
|
498
|
-
res.set("Content-Security-Policy", "default-src 'none'; style-src 'unsafe-inline'");
|
|
524
|
+
res.set("Content-Security-Policy", "default-src 'none'; style-src 'unsafe-inline'; frame-ancestors 'none'");
|
|
525
|
+
res.set("X-Frame-Options", "DENY");
|
|
499
526
|
res.set("Cache-Control", "no-store");
|
|
500
527
|
res.send(renderSharePage(doc));
|
|
501
528
|
});
|
|
@@ -546,11 +573,26 @@ if (args.includes("--dev")) {
|
|
|
546
573
|
});
|
|
547
574
|
next();
|
|
548
575
|
});
|
|
549
|
-
|
|
576
|
+
const dist = resolve(appDir, "apps/dpi-playground-fe/dist");
|
|
577
|
+
// Vite content-addresses /assets/* filenames, so they can cache forever; the
|
|
578
|
+
// documents that reference them (index.html and the SPA shell) must
|
|
579
|
+
// revalidate or a deploy would serve stale HTML pointing at dead hashes.
|
|
580
|
+
app.use("/assets", express.static(join(dist, "assets"), { immutable: true, maxAge: "365d" }));
|
|
581
|
+
app.use(
|
|
582
|
+
express.static(dist, {
|
|
583
|
+
setHeaders: (res, filePath) => {
|
|
584
|
+
if (filePath.endsWith(".html")) res.setHeader("Cache-Control", "no-cache");
|
|
585
|
+
},
|
|
586
|
+
}),
|
|
587
|
+
);
|
|
550
588
|
app.get("/{*path}", (req, res, next) => {
|
|
551
589
|
// A path that names a file is an asset that does not exist, not a page of the app.
|
|
552
590
|
if (extname(req.path)) return void next();
|
|
553
|
-
|
|
591
|
+
// An /api-shaped path is never a page — not even case-mangled (uniformity
|
|
592
|
+
// with the device: /API/NETWORK is a 404 miss, not the app shell).
|
|
593
|
+
if (/^\/api(\/|$)/i.test(req.path)) return void next();
|
|
594
|
+
res.setHeader("Cache-Control", "no-cache");
|
|
595
|
+
res.sendFile(join(dist, "index.html"));
|
|
554
596
|
});
|
|
555
597
|
}
|
|
556
598
|
app.use((_req, res) => res.status(404).json(err("not_found", "Not found")));
|