@dr-co/dsh-secret-form 0.4.0 → 0.4.2

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/index.mjs CHANGED
@@ -924,7 +924,10 @@ export function apply(ctx, config = {}) {
924
924
 
925
925
  const credentialsOf = () => (typeof ctx?.get === 'function' ? ctx.get('credentials') : ctx?.credentials);
926
926
  const handler = createRouteHandler({ forms, shares, settings, logger, credentialsOf, notifier });
927
- const route = { kind: 'prefix', path: settings.routePrefix, handler };
927
+ // A form link is opened by a person who has no DSH session; the page's own
928
+ // uuid token is the only credential. The web server's default `required`
929
+ // admission answered 401 before the handler could check that token.
930
+ const route = { kind: 'prefix', path: settings.routePrefix, auth: 'anonymous', handler };
928
931
 
929
932
  if (typeof ctx?.webServer?.register !== 'function') {
930
933
  throw new TypeError('dsh-secret-form: the webServer service is required');
package/lib/notify.mjs CHANGED
@@ -6,7 +6,14 @@
6
6
  // one-shot reminder on the session, exactly the way the graceful-restart plugin
7
7
  // wakes a session after the host comes back:
8
8
  //
9
- // schedule.create(sessionId, { title, prompt, after_seconds: 1 })
9
+ // schedule.create({ title, prompt,
10
+ // timing: { kind: 'after', after_seconds: 1 },
11
+ // target: { kind: 'session', sessionId } })
12
+ //
13
+ // The core changed that call in 0.2.2: a flat `after_seconds` next to a session
14
+ // id became one typed request, and the old shape is refused with "timing must
15
+ // contain exactly kind and its matching selector". Both are tried in turn and
16
+ // the one that worked is remembered, so a host on either core gets its note.
10
17
  //
11
18
  // `ScheduleService` owns the timer, resumes the session itself and retries on
12
19
  // its own terms. The rows in the `note` table are the outbox: a note survives a
@@ -139,6 +146,28 @@ export function createNotifier({
139
146
  } catch {}
140
147
  };
141
148
 
149
+ // Which shape of the call this host speaks, decided by the first note that
150
+ // gets through: the core moved it and a request in the other shape is refused.
151
+ let shape = null;
152
+
153
+ /** One attempt in one shape; throws the service's own refusal. */
154
+ async function placeOnce(schedule, note, which) {
155
+ if (which === 'typed') {
156
+ await schedule.create({
157
+ title: note.title,
158
+ prompt: note.prompt,
159
+ timing: { kind: 'after', after_seconds: 1 },
160
+ target: { kind: 'session', sessionId: String(note.session_id) },
161
+ });
162
+ return;
163
+ }
164
+ await schedule.create(note.session_id, {
165
+ title: note.title,
166
+ prompt: note.prompt,
167
+ after_seconds: 1,
168
+ });
169
+ }
170
+
142
171
  /**
143
172
  * Put one note on the session, retrying while the schedule service is either
144
173
  * absent or refusing.
@@ -150,20 +179,19 @@ export function createNotifier({
150
179
  const deadline = Date.now() + deadlineMs;
151
180
  let refusal;
152
181
  while (Date.now() < deadline) {
153
- try {
154
- await schedule.create(note.session_id, {
155
- title: note.title,
156
- prompt: note.prompt,
157
- after_seconds: 1,
158
- });
159
- return true;
160
- } catch (error) {
161
- refusal = String(error?.message ?? error);
162
- // A delegated child has no delivery path at all: retrying forever would
163
- // only hide that fact.
164
- if (/subagent/i.test(refusal)) throw error;
165
- await sleep(retryMs);
182
+ for (const which of shape === null ? ['typed', 'legacy'] : [shape]) {
183
+ try {
184
+ await placeOnce(schedule, note, which);
185
+ shape = which;
186
+ return true;
187
+ } catch (error) {
188
+ refusal = String(error?.message ?? error);
189
+ // A delegated child has no delivery path at all: retrying forever would
190
+ // only hide that fact.
191
+ if (/subagent/i.test(refusal)) throw error;
192
+ }
166
193
  }
194
+ await sleep(retryMs);
167
195
  }
168
196
  throw new Error(refusal ?? 'the schedule service did not accept the note in time');
169
197
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dr-co/dsh-secret-form",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Secret links in both directions for DeepSeek Harness: the human types a secret into a one-time form, or the model hands one over through a link whose reveal button works exactly once. Durable in SQLite, with file uploads and a note to the session that asked.",
5
5
  "type": "module",
6
6
  "main": "./index.mjs",