my-durable 0.0.66 → 0.0.67

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.
@@ -7,7 +7,7 @@
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-d3YKeCCM.js"></script>
10
+ <script type="module" crossorigin src="/assets/index-CpNu1wqa.js"></script>
11
11
  <link rel="stylesheet" crossorigin href="/assets/index-DSU1QhGO.css">
12
12
  </head>
13
13
  <body>
@@ -3,8 +3,23 @@
3
3
  import { DpiClient } from "@sdk/client";
4
4
  import { DpiError } from "@sdk/errors";
5
5
  import type { ErrorCode, NetworkDevice } from "@sdk/api";
6
+ import { notify } from "./store";
6
7
 
7
- export const deviceClient = (id: string) => new DpiClient(`/api/devices/${encodeURIComponent(id)}`);
8
+ // R13 (R9-6.3 FE): the collapse of identical un-keyed creates is an accepted
9
+ // retry-safety tradeoff — but it must be VISIBLE. The device's replay verdict
10
+ // rides the tunnel envelope, the hub surfaces Idempotent-Replay, and the SDK
11
+ // hook turns it into a toast naming the escape hatch (own idempotency-key).
12
+ let replayToastAt = 0;
13
+ export const deviceClient = (id: string) =>
14
+ new DpiClient(`/api/devices/${encodeURIComponent(id)}`, undefined, {
15
+ onIdempotentReplay: (path) => {
16
+ // Replays can arrive in bursts (a re-connected UI re-firing identical
17
+ // creates) — one toast per 30 s is plenty of signal.
18
+ if (Date.now() - replayToastAt < 30_000) return;
19
+ replayToastAt = Date.now();
20
+ notify(`Replayed an earlier identical request (${path}) — send a custom idempotency key for deliberate repeats.`);
21
+ },
22
+ });
8
23
 
9
24
  async function call<T>(method: string, path: string, body?: unknown): Promise<T> {
10
25
  const r = await fetch(`/api${path}`, {
@@ -91,6 +91,10 @@ export function proxy(
91
91
  const contentType =
92
92
  typeof upstream.contentType === "string" ? upstream.contentType : undefined;
93
93
  res.status(status).set(LOCKED_DOWN_HEADERS);
94
+ // R13 (R9-6.3 FE): the device's replay verdict surfaces as the standard
95
+ // header — a hub-controlled literal (never a passthrough of arbitrary
96
+ // device header names/values), same trust boundary as the zip label.
97
+ if (upstream.idempotentReplay === true) res.set("Idempotent-Replay", "true");
94
98
  if (!contentType || mediaType(contentType) === "application/json")
95
99
  res.type("application/json").send(body);
96
100
  else {
@@ -29,6 +29,10 @@ export interface TransportResponse {
29
29
  bodyEncoding?: "base64";
30
30
  /** Sanitized Content-Disposition from the device (binary responses); may be undefined. */
31
31
  contentDisposition?: string;
32
+ /** R13 (R9-6.3 FE): the device answered this request with an idempotency
33
+ * REPLAY — the proxy surfaces it as the Idempotent-Replay response header
34
+ * so clients can tell a replay from a fresh create. */
35
+ idempotentReplay?: true;
32
36
  /** Diagnostics: assembled byte count for chunked responses. */
33
37
  rawBytes?: number;
34
38
  }
@@ -103,6 +107,9 @@ export class LanTransport implements DeviceTransport {
103
107
  body: textual ? raw.toString("utf8") : raw.toString("base64"),
104
108
  ...(textual ? {} : { bodyEncoding: "base64" as const }),
105
109
  ...(textual ? {} : { contentDisposition: safeHeaderValue(response.headers.get("content-disposition")) }),
110
+ // R13 (R9-6.3 FE): same replay verdict on the LAN leg — one TransportResponse
111
+ // contract, both transports.
112
+ ...(response.headers.get("idempotent-replay") === "true" ? { idempotentReplay: true as const } : {}),
106
113
  };
107
114
  }
108
115
 
@@ -293,6 +293,7 @@ export class TunnelDispatcher {
293
293
  ...(frame.bodyEncoding === "base64"
294
294
  ? { contentDisposition: safeHeaderValue(frame.contentDisposition) }
295
295
  : {}),
296
+ ...(frame.idempotentReplay === true ? { idempotentReplay: true as const } : {}),
296
297
  });
297
298
  return;
298
299
  }
@@ -335,6 +336,7 @@ export class TunnelDispatcher {
335
336
  body?: unknown;
336
337
  bodyEncoding?: unknown;
337
338
  contentDisposition?: unknown;
339
+ idempotentReplay?: unknown;
338
340
  }
339
341
  | undefined;
340
342
  if (typeof env?.status !== "number" || !Number.isFinite(env.status)) {
@@ -354,6 +356,7 @@ export class TunnelDispatcher {
354
356
  ...(env.bodyEncoding === "base64"
355
357
  ? { contentDisposition: safeHeaderValue(env.contentDisposition) }
356
358
  : {}),
359
+ ...(env.idempotentReplay === true ? { idempotentReplay: true as const } : {}),
357
360
  rawBytes: out.rawBytes,
358
361
  });
359
362
  }
@@ -152,6 +152,11 @@ export class DpiClient {
152
152
  constructor(
153
153
  baseUrl: string,
154
154
  private readonly token?: string,
155
+ /** R13 (R9-6.3 FE): fired when a request's response carried
156
+ * Idempotent-Replay: true — the answer is a REPLAY of an earlier
157
+ * identical request, not a fresh effect. UIs use it to tell the user;
158
+ * clients that need deliberate repeats send their own idempotencyKey. */
159
+ private readonly hooks: { onIdempotentReplay?: (path: string) => void } = {},
155
160
  ) {
156
161
  this.baseUrl = baseUrl.replace(/\/+$/, "");
157
162
  }
@@ -201,6 +206,7 @@ export class DpiClient {
201
206
  (response.status === 401 ? "unauthorized" : response.status === 404 ? "not_found" : "internal");
202
207
  throw new DpiError(code, error?.message ?? `${response.status} ${response.statusText}`, response.status);
203
208
  }
209
+ if (response.headers.get("idempotent-replay") === "true") this.hooks.onIdempotentReplay?.(path);
204
210
  return data as T;
205
211
  }
206
212
 
@@ -232,6 +232,10 @@ export const TunnelFrame = Type.Union([
232
232
  // sanitized download filename. Absent on the legacy textual envelope.
233
233
  bodyEncoding: Type.Optional(Type.Union([Type.Literal("base64")])),
234
234
  contentDisposition: Type.Optional(Type.String({ maxLength: 200 })),
235
+ // R13 (R9-6.3 FE): the device sets this literal when the loopback response
236
+ // was an idempotency REPLAY; hubs forward it as the Idempotent-Replay
237
+ // response header so clients can tell a replay from a fresh create.
238
+ idempotentReplay: Type.Optional(Type.Literal(true)),
235
239
  }),
236
240
  TunnelControl,
237
241
  Type.Object(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "my-durable",
3
- "version": "0.0.66",
3
+ "version": "0.0.67",
4
4
  "description": "Durable Pi — the durable agent network: hub web UI, device backend daemon, TUI admin and the shared SDK, packaged as one runnable monorepo install",
5
5
  "license": "MIT",
6
6
  "repository": {