@anionex/dsh-turn-rewind 0.3.11 → 0.3.13

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.
@@ -1,10 +1,18 @@
1
1
  import { type ReactNode } from 'react';
2
+ /** Durable reference carried by one `image` / `file` content block. */
3
+ interface AttachmentRefLike {
4
+ readonly attachmentId?: string;
5
+ readonly name?: string;
6
+ readonly mediaType?: string;
7
+ readonly bytes?: number;
8
+ }
2
9
  interface ConversationNodeLike {
3
10
  readonly kind: string;
4
11
  readonly seq: number;
5
12
  readonly content?: readonly {
6
13
  readonly type: string;
7
14
  readonly text?: string;
15
+ readonly attachment?: AttachmentRefLike;
8
16
  }[];
9
17
  }
10
18
  interface ConversationChatNodeLike {
@@ -36,21 +44,41 @@ interface ConversationSnapshotLike extends ChatSnapshotLike {
36
44
  /** Selector hook shape shared by `useSession` and `useChat`. */
37
45
  type SnapshotSelectorHook = <T>(selector: (snapshot: ConversationSnapshotLike) => T) => T;
38
46
  type RewindNodeLike = ConversationNodeLike | ConversationChatNodeLike;
47
+ /** One durable attachment that the restart has to hand back to the composer. */
48
+ interface RewindAttachment {
49
+ readonly kind: 'image' | 'file';
50
+ readonly attachmentId: string;
51
+ readonly name: string;
52
+ readonly mediaType: string;
53
+ readonly sourceSessionId?: string;
54
+ readonly messageSeq?: number;
55
+ }
39
56
  interface RewindMatch {
40
57
  readonly messageSeq: number;
41
58
  readonly promptText: string;
59
+ /** Present only when the message carried attachments; absent keeps older doubles valid. */
60
+ readonly attachments?: readonly RewindAttachment[];
42
61
  }
43
62
  interface RewindMessageActionProps {
44
63
  readonly matched: RewindMatch;
45
64
  readonly sessionId: string;
46
- readonly openRestoredSession: (sessionId: string, promptText: string) => Promise<void>;
65
+ readonly openRestoredSession: (sessionId: string, promptText: string, attachments?: readonly RewindAttachment[]) => Promise<void>;
47
66
  }
48
67
  interface RewindPortalBridgeProps {
49
68
  readonly sessionId: string;
50
- readonly openRestoredSession: (sessionId: string, promptText: string) => Promise<void>;
51
- readonly useSession: SnapshotSelectorHook;
69
+ readonly openRestoredSession: (sessionId: string, promptText: string, attachments?: readonly RewindAttachment[]) => Promise<void>;
70
+ /**
71
+ * Legacy 0.1.x chat snapshot hooks kept optional for older test doubles and
72
+ * hosts; DSH 0.2.0 stopped injecting them, so the bridge reads the Host turn
73
+ * anchor endpoint instead.
74
+ */
75
+ readonly useSession?: SnapshotSelectorHook;
52
76
  readonly useChat?: SnapshotSelectorHook;
53
77
  }
78
+ interface RewindPortalTarget {
79
+ readonly container: HTMLElement;
80
+ readonly matched: RewindMatch;
81
+ }
54
82
  interface SlotsLike {
55
83
  inject(name: string, install: () => unknown): void;
56
84
  register<I, P>(entry: {
@@ -82,6 +110,8 @@ interface ClientContextLike {
82
110
  readonly input: {
83
111
  for(scope: unknown): {
84
112
  setDraft(text: string): void;
113
+ addAttachments?(ids: readonly string[]): boolean;
114
+ notify?(level: 'info' | 'error', text: string): void;
85
115
  };
86
116
  };
87
117
  };
@@ -201,8 +231,16 @@ type UiLocale = 'zh' | 'en';
201
231
  * @returns the language whose copy to render.
202
232
  */
203
233
  export declare function resolveUiLocale(active: string | undefined): UiLocale;
204
- /** Return the rewind anchor and editable text owned by one direct user message. */
234
+ /** Return the rewind anchor, editable text, and durable attachments owned by one direct user message. */
205
235
  export declare function selectRewindMessage(node: ConversationNodeLike): RewindMatch | null;
236
+ /**
237
+ * Collect the durable `image` / `file` references carried by one user message.
238
+ *
239
+ * Keep missing references so restoration can report unavailable attachments.
240
+ * @param node - the direct user-message node the rewind anchors on.
241
+ * @returns attachments in message order; empty when the message has none.
242
+ */
243
+ export declare function selectRewindAttachments(node: ConversationNodeLike): readonly RewindAttachment[];
206
244
  /**
207
245
  * Browser plugin entry: bridge every direct user-message action row to the rewind UI.
208
246
  *
@@ -225,8 +263,13 @@ export declare function apply(ctx: ClientContextLike): void;
225
263
  * @returns the chat nodes in render order.
226
264
  */
227
265
  export declare function collectChatNodes(order: readonly string[] | null, store: ChatNodeStoreLike | readonly RewindNodeLike[] | null): readonly RewindNodeLike[];
228
- /** Session-scoped bridge that portals rewind controls into direct user-message action rows. */
229
- export declare function RewindMessagePortals({ sessionId, openRestoredSession, useSession, useChat }: RewindPortalBridgeProps): ReactNode;
266
+ /**
267
+ * Session-scoped bridge that portals rewind controls into direct user-message action rows.
268
+ *
269
+ * DSH 0.1.x passes chat snapshot hooks; DSH 0.2.0 stopped injecting them, so the
270
+ * bridge falls back to DOM rows plus the Host turn-anchor endpoint.
271
+ */
272
+ export declare function RewindMessagePortals(props: RewindPortalBridgeProps): ReactNode;
230
273
  /** User-message action and its review-first file/conversation restore dialog. */
231
274
  export declare function RewindMessageAction({ matched, sessionId, openRestoredSession }: RewindMessageActionProps): ReactNode;
232
275
  interface TurnRewindSettingsCardProps {
@@ -241,7 +284,44 @@ export declare function selectRewindMessageTarget(value: RewindNodeLike): {
241
284
  readonly matched: RewindMatch;
242
285
  readonly rowKey: string;
243
286
  } | null;
244
- export declare function openSessionWithDraft(ctx: ClientContextLike, sessionId: string, promptText: string): Promise<void>;
287
+ /**
288
+ * Legacy chat-snapshot bridge kept for 0.1.x hosts and test doubles.
289
+ * DSH 0.2.0 uses {@link collectDomPortalTargets} instead.
290
+ */
291
+ export declare function collectPortalTargets(nodes: readonly RewindNodeLike[]): readonly RewindPortalTarget[];
292
+ /**
293
+ * Re-upload one durable attachment as a fresh draft attachment.
294
+ *
295
+ * The stored bytes are read back from the Host, wrapped in a `File`, and handed
296
+ * to the composer bridge, because the composer only understands browser files.
297
+ * @param attachment - durable reference taken from the rewound message.
298
+ * @returns the rebuilt file, or `undefined` when the Host cannot serve it.
299
+ */
300
+ export declare function readAttachmentFile(attachment: RewindAttachment): Promise<File>;
301
+ /**
302
+ * Hand a rewound message's attachments back to the composer.
303
+ *
304
+ * Draft attachments are browser-owned `File`s with upload receipts, so the
305
+ * durable references are read back from the Host and registered exactly the way
306
+ * the composer's own picker does it: `createDrafts` allocates the drafts,
307
+ * `input.for(scope).addAttachments` adopts their draft IDs.
308
+ *
309
+ * Use the public session input facade, which exists before the visual editor
310
+ * mounts. Failures are surfaced to the rewind dialog and refused drafts are released.
311
+ * @param ctx - client context carrying the conversation service.
312
+ * @param sessionId - Session whose composer receives the files.
313
+ * @param attachments - durable references carried by the rewound message.
314
+ * @returns number of attachments actually restored.
315
+ */
316
+ export declare function restoreComposerAttachments(ctx: ClientContextLike, sessionId: string, attachments: readonly RewindAttachment[], prepared?: readonly PromiseSettledResult<File>[]): Promise<number>;
317
+ /**
318
+ * Open the rewound Session and put the message back into its composer.
319
+ * @param ctx - client context carrying the Session navigation service.
320
+ * @param sessionId - target Session.
321
+ * @param promptText - message text to restore.
322
+ * @param attachments - attachments carried by that message.
323
+ */
324
+ export declare function openSessionWithDraft(ctx: ClientContextLike, sessionId: string, promptText: string, attachments?: readonly RewindAttachment[]): Promise<void>;
245
325
  /**
246
326
  * Read one rewind response body without ever leaking a raw parse error.
247
327
  *
@@ -154,6 +154,15 @@ declare module '@deepseek-ai/cordis' {
154
154
  }
155
155
  }
156
156
  export declare const REWIND_HTTP_PATH = "/turn-rewind";
157
+ /**
158
+ * Same-origin route mapping every recorded turn to its opening user-message seq.
159
+ *
160
+ * DSH 0.2.0 removed the per-message chat snapshot from session-scoped slot
161
+ * entries, so the browser half can no longer resolve a rendered message row back
162
+ * to the Session event seq the rewind API anchors on. This read-only endpoint
163
+ * restores that mapping without touching project files or the Session log.
164
+ */
165
+ export declare const TURNS_HTTP_PATH = "/turn-rewind/turns";
157
166
  /** Capture each turn beside model work and gate root tool side effects on its bounded outcome. */
158
167
  export declare class TurnCheckpointCoordinator {
159
168
  private readonly engine;
@@ -180,10 +189,23 @@ export declare class TurnCheckpointCoordinator {
180
189
  }
181
190
  /** Register the same-origin preview/apply endpoint consumed by the browser half. */
182
191
  export declare function installRewindHttp(ctx: Context, engine: ChangeLedgerEngine, coordinator: TurnCheckpointCoordinator): void;
192
+ /** Build the read-only turn-anchor handler as a testable unit. */
193
+ export declare function createTurnsHttpHandler(ctx: Pick<Context, 'sessions' | 'sessionQuery'>): (request: HttpRequestLike, response: HttpResponseLike) => Promise<void>;
183
194
  /** Build the exact-route handler as a testable unit. */
184
195
  export declare function createRewindHttpHandler(ctx: ConversationRestartContext & {
185
196
  readonly agents?: AgentsLike;
186
197
  }, engine: ChangeLedgerEngine, coordinator: TurnCheckpointCoordinator): (request: HttpRequestLike, response: HttpResponseLike) => Promise<void>;
198
+ /** Same-origin route that replays one stored attachment's bytes to the browser. */
199
+ export declare const ATTACHMENT_HTTP_PATH = "/turn-rewind/attachment-bytes";
200
+ /** Register the attachment-bytes route consumed by the rewound composer draft. */
201
+ export declare function installAttachmentHttp(ctx: Context): void;
202
+ /**
203
+ * Build the attachment-bytes route as a testable unit.
204
+ *
205
+ * Bytes travel in a JSON envelope shared by Web and Desktop carriers;
206
+ * the browser rebuilds a `File` from the verified message reference.
207
+ */
208
+ export declare function createAttachmentHttpHandler(ctx: Pick<Context, 'get' | 'sessions' | 'sessionQuery'>): (request: HttpRequestLike, response: HttpResponseLike) => Promise<void>;
187
209
  export declare const MANAGE_HTTP_PATH = "/turn-rewind/manage";
188
210
  /** Register the same-origin storage-management endpoint consumed by the settings card. */
189
211
  export declare function installManageHttp(ctx: Context, engine: ChangeLedgerEngine): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anionex/dsh-turn-rewind",
3
- "version": "0.3.11",
3
+ "version": "0.3.13",
4
4
  "description": "Turn-level conversation and workspace rewind for DeepSeek Harness, powered by a persistent Change Ledger",
5
5
  "repository": {
6
6
  "type": "git",
@@ -63,7 +63,7 @@
63
63
  ]
64
64
  },
65
65
  "compatibility": {
66
- "dsh": ">=0.1.0-rc.8 <0.2.0 || ^0.1.7-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.2 || 0.2.1-rc.3",
66
+ "dsh": ">=0.1.0-rc.8 <0.2.0 || ^0.1.7-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.2 || 0.2.1-rc.3 || 0.2.1-rc.5 || 0.2.2-rc.1",
67
67
  "dshReleases": {
68
68
  "0.1.0-rc.8": "compatible",
69
69
  "0.1.1-rc.1": "compatible",
@@ -78,7 +78,9 @@
78
78
  "0.1.7-rc.2": "compatible",
79
79
  "0.2.0-rc.2": "compatible",
80
80
  "0.2.1-rc.2": "compatible",
81
- "0.2.1-rc.3": "compatible"
81
+ "0.2.1-rc.3": "compatible",
82
+ "0.2.1-rc.5": "compatible",
83
+ "0.2.2-rc.1": "compatible"
82
84
  },
83
85
  "profiles": [
84
86
  "web"
@@ -104,7 +106,7 @@
104
106
  "license": "BSD-3-Clause",
105
107
  "peerDependencies": {
106
108
  "@deepseek-ai/cordis": "^4.0.1",
107
- "@deepseek-ai/dsh-settings": "0.2.1-rc.3 || >=0.1.0-rc.8 <0.2.0 || ^0.1.1-rc.1 || ^0.1.2-alpha.1 || ^0.1.5-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.2",
109
+ "@deepseek-ai/dsh-settings": "0.2.1-rc.3 || >=0.1.0-rc.8 <0.2.0 || ^0.1.1-rc.1 || ^0.1.2-alpha.1 || ^0.1.5-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.2 || 0.2.1-rc.5 || 0.2.2-rc.1",
108
110
  "@deepseek-ai/schemastery": "^3.18.1"
109
111
  },
110
112
  "peerDependenciesMeta": {