@khorsheed/dsh-client-message-tools 0.3.0 → 0.3.1

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/lib/index.js CHANGED
@@ -1,22 +1,30 @@
1
+ import * as sessionApi from "@deepseek-ai/dsh-session";
1
2
  import { SessionSeq } from "@deepseek-ai/dsh-session";
2
3
  import { createUserMessage } from "@deepseek-ai/dsh-llm";
3
4
  import { Remote, TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
4
5
  import { isAppendSurfaceEvent, isReplacementSurfaceEvent } from "@deepseek-ai/dsh-session/surface";
5
6
  //#region lib/types/marker.js
6
7
  /**
7
- * Shared message-tools markers: the plugin source tag stamped on withdrawal
8
- * replacement events, the `op` discriminator telling edit replacements, edit
9
- * triggers, and assistant-text restore replays apart from withdrawals and
10
- * user-message restores, the model-facing placeholder and trigger texts, and
11
- * the pure predicates both the Host service and the browser projection
12
- * consume. No new session event type is ever written — an
8
+ * Shared message-tools markers: the producer-owned source kind stamped on
9
+ * every message-tools event, the `op` discriminator telling edit
10
+ * replacements, edit triggers, and assistant-text restore replays apart from
11
+ * withdrawals and user-message restores, the model-facing placeholder and
12
+ * trigger texts, and the pure predicates both the Host service and the
13
+ * browser projection consume. No new session event type is ever written — an
13
14
  * out-of-harness event type cannot carry `ignorable: true` (Session.append
14
15
  * assigns the envelope), so a persisted unknown type would make
15
16
  * session-persistence refuse the log on reload. The events themselves are the
16
17
  * durable audit trail.
17
18
  * @module @khorsheed/dsh-client-message-tools/marker
18
19
  */
19
- /** Plugin source tag identifying every message-tools event. */
20
+ /**
21
+ * The producer-owned source kind identifying every message-tools event. It is
22
+ * also the legacy wrapper's `plugin` value: released V3 logs carry
23
+ * `{ kind: 'plugin', plugin: 'message-tools' }` (a pre-V4 host still serves
24
+ * them verbatim), and the official V3→V4 migration rewrites those to
25
+ * `kind: 'plugin:message-tools'` — {@link isMessageToolsSource} accepts all
26
+ * three durable forms.
27
+ */
20
28
  const MESSAGE_TOOLS_PLUGIN = "message-tools";
21
29
  /**
22
30
  * Model-facing placeholder left on the surface in place of the withdrawn
@@ -33,49 +41,79 @@ const WITHDRAWN_NOTICE = "(用户撤回了这条消息及其后的所有内容)"
33
41
  const EDIT_TRIGGER_NOTICE = "(用户编辑了上一条消息,请按编辑后的内容重新回答)";
34
42
  /**
35
43
  * Model-facing frame preceding a replayed assistant text in a restore: the
36
- * replay lands as a user-role message (assistant/message cannot carry a
37
- * plugin source, and the session turn/step trace forbids ad-hoc assistant
38
- * appends), so the frame keeps the role honest for the model.
44
+ * replay lands as a user-role message (assistant/message requires the model
45
+ * source, and the session turn/step trace forbids ad-hoc assistant
46
+ * appends), so the frame keeps the role honest for the model. On hosts whose
47
+ * session fold carries the S12 `user/message` projection the frame never
48
+ * reaches the model — the projection strips it and corrects the role at
49
+ * derivation time; everywhere else it is the role-honesty device.
39
50
  */
40
51
  const RESTORED_ASSISTANT_NOTICE = "(以下是先前被撤回、现随恢复放回的助手回复)";
41
- /** The plugin-tagged source of an edit replacement (op: 'edit'). */
52
+ /** The producer-owned source of a withdrawal replacement or a user-message restore replay (no op). */
53
+ function messageToolsSource() {
54
+ return Object.freeze({ kind: MESSAGE_TOOLS_PLUGIN });
55
+ }
56
+ /** The producer-owned source of an edit replacement (op: 'edit'). */
42
57
  function editReplacementSource() {
43
58
  return Object.freeze({
44
- kind: "plugin",
45
- plugin: MESSAGE_TOOLS_PLUGIN,
59
+ kind: MESSAGE_TOOLS_PLUGIN,
46
60
  op: "edit"
47
61
  });
48
62
  }
49
- /** The plugin-tagged source of an edit trigger message (op: 'edit-trigger'). */
63
+ /** The producer-owned source of an edit trigger message (op: 'edit-trigger'). */
50
64
  function editTriggerSource() {
51
65
  return Object.freeze({
52
- kind: "plugin",
53
- plugin: MESSAGE_TOOLS_PLUGIN,
66
+ kind: MESSAGE_TOOLS_PLUGIN,
54
67
  op: "edit-trigger"
55
68
  });
56
69
  }
57
- /** The plugin-tagged source of a restored assistant-text replay (op: 'restore-assistant'). */
70
+ /** The producer-owned source of a restored assistant-text replay (op: 'restore-assistant'). */
58
71
  function restoreAssistantSource() {
59
72
  return Object.freeze({
60
- kind: "plugin",
61
- plugin: MESSAGE_TOOLS_PLUGIN,
73
+ kind: MESSAGE_TOOLS_PLUGIN,
62
74
  op: "restore-assistant"
63
75
  });
64
76
  }
65
- /** Read the op discriminator off a message source (absent on legacy events). */
77
+ /** Read the op discriminator off a message source (absent on plain withdrawal/restore events). */
66
78
  function messageToolsOp(source) {
67
79
  const op = source?.op;
68
80
  return op === "edit" || op === "edit-trigger" || op === "restore-assistant" ? op : void 0;
69
81
  }
70
82
  /**
83
+ * Whether a durable source belongs to message-tools, in every form the log
84
+ * can hold: the current producer-owned kind (`message-tools`), the V3→V4
85
+ * migrated kind (`plugin:message-tools` — released V3 files rewritten once by
86
+ * the official migration), and the released V3 wrapper a pre-V4 host still
87
+ * serves verbatim (`{ kind: 'plugin', plugin: 'message-tools' }`).
88
+ * @param source - the persisted message source to test.
89
+ * @returns true when the source names this producer.
90
+ */
91
+ function isMessageToolsSource(source) {
92
+ if (typeof source !== "object" || source === null) return false;
93
+ const record = source;
94
+ return record.kind === "message-tools" || record.kind === `plugin:message-tools` || record.kind === "plugin" && record.plugin === "message-tools";
95
+ }
96
+ /**
97
+ * Strip the model-facing restore frame from a replayed assistant text for
98
+ * DISPLAY: the frame belongs to the model context (role honesty), never to
99
+ * the transcript row. Texts without the frame pass through unchanged.
100
+ * @param text - the replayed content's joined text.
101
+ * @returns the display text without the frame prefix.
102
+ */
103
+ function stripRestoreAssistantFrame(text) {
104
+ const prefix = `${RESTORED_ASSISTANT_NOTICE}\n`;
105
+ return text.startsWith(prefix) ? text.slice(prefix.length) : text;
106
+ }
107
+ /**
71
108
  * Whether the event is a message-tools WITHDRAWAL replacement: a
72
- * `user/message` surface replacement whose source carries this plugin's tag
73
- * and no `op` discriminator (legacy and current withdrawals both).
109
+ * `user/message` surface replacement whose source names this producer
110
+ * (any durable form — see {@link isMessageToolsSource}) with no `op`
111
+ * discriminator.
74
112
  * @param event - the session event to test.
75
113
  * @returns the event narrowed to a withdrawal replacement when matched.
76
114
  */
77
115
  function isMessageToolsReplacement(event) {
78
- return event.type === "user/message" && isReplacementSurfaceEvent(event) && event.data.source.kind === "plugin" && event.data.source.plugin === "message-tools" && messageToolsOp(event.data.source) === void 0;
116
+ return event.type === "user/message" && isReplacementSurfaceEvent(event) && isMessageToolsSource(event.data.source) && messageToolsOp(event.data.source) === void 0;
79
117
  }
80
118
  /**
81
119
  * Whether the event is a message-tools EDIT replacement: a `user/message`
@@ -84,7 +122,7 @@ function isMessageToolsReplacement(event) {
84
122
  * @returns the event narrowed to an edit replacement when matched.
85
123
  */
86
124
  function isMessageToolsEdit(event) {
87
- return event.type === "user/message" && isReplacementSurfaceEvent(event) && event.data.source.kind === "plugin" && event.data.source.plugin === "message-tools" && messageToolsOp(event.data.source) === "edit";
125
+ return event.type === "user/message" && isReplacementSurfaceEvent(event) && isMessageToolsSource(event.data.source) && messageToolsOp(event.data.source) === "edit";
88
126
  }
89
127
  /**
90
128
  * Whether the event is a message-tools restore: an append-surface
@@ -93,7 +131,7 @@ function isMessageToolsEdit(event) {
93
131
  * @returns the event narrowed to a message-tools restore when matched.
94
132
  */
95
133
  function isMessageToolsRestore(event) {
96
- return event.type === "user/message" && event.surfaceOp === "append" && event.data.source.kind === "plugin" && event.data.source.plugin === "message-tools" && messageToolsOp(event.data.source) === void 0;
134
+ return event.type === "user/message" && event.surfaceOp === "append" && isMessageToolsSource(event.data.source) && messageToolsOp(event.data.source) === void 0;
97
135
  }
98
136
  /**
99
137
  * Whether the event is a message-tools ASSISTANT-text restore replay: an
@@ -103,7 +141,115 @@ function isMessageToolsRestore(event) {
103
141
  * @returns the event narrowed to a restore-assistant replay when matched.
104
142
  */
105
143
  function isMessageToolsRestoreAssistant(event) {
106
- return event.type === "user/message" && event.surfaceOp === "append" && event.data.source.kind === "plugin" && event.data.source.plugin === "message-tools" && messageToolsOp(event.data.source) === "restore-assistant";
144
+ return event.type === "user/message" && event.surfaceOp === "append" && isMessageToolsSource(event.data.source) && messageToolsOp(event.data.source) === "restore-assistant";
145
+ }
146
+ //#endregion
147
+ //#region lib/types/restore-projection.js
148
+ /**
149
+ * The `user/message` projection correcting restore replays at derivation
150
+ * time. It registers on the SHARED user-message vocabulary (a custom event
151
+ * type could never persist — S2), so the fold calls `project` synchronously
152
+ * for EVERY user message, inside append validation: it must be a pure
153
+ * pass-through (empty map) for anything without the restore mark, and it must
154
+ * NEVER throw — a throw atomically rejects the candidate append, so a
155
+ * throwing projection would break ordinary user messages instance-wide. Any
156
+ * malformed durable payload therefore also yields an empty map.
157
+ */
158
+ const restoreAssistantProjection = {
159
+ type: "user/message",
160
+ project(event, context) {
161
+ try {
162
+ const source = event.data?.source;
163
+ if (messageToolsOp(source) !== "restore-assistant") return /* @__PURE__ */ new Map();
164
+ const committed = context.events[event.seq - context.baseSeq];
165
+ const message = context.messages.get(event.seq) ?? (committed?.type === "user/message" ? committed.data : void 0) ?? event.data;
166
+ const content = message.content.map((block) => block.type === "text" && typeof block.text === "string" ? {
167
+ ...block,
168
+ text: stripRestoreAssistantFrame(block.text)
169
+ } : block);
170
+ return /* @__PURE__ */ new Map([[event.seq, {
171
+ ...message,
172
+ role: "assistant",
173
+ content
174
+ }]]);
175
+ } catch {
176
+ return /* @__PURE__ */ new Map();
177
+ }
178
+ }
179
+ };
180
+ /** One synthetic user/message event for the fold-semantics probe. */
181
+ function probeEvent(seq, text, source) {
182
+ return {
183
+ type: "user/message",
184
+ seq: SessionSeq(seq),
185
+ time: 0,
186
+ data: createUserMessage({
187
+ content: [{
188
+ type: "text",
189
+ text
190
+ }],
191
+ source
192
+ }),
193
+ surfaceOp: "append"
194
+ };
195
+ }
196
+ /**
197
+ * Whether this host's surface fold can carry a `user/message` projection at
198
+ * all. 0.1.6-alpha.1 routes every event of a projected type through the
199
+ * projection plan and never joins it to the surface (probe-verified): a
200
+ * registered user/message projection would silently drop EVERY user message
201
+ * from the model context. This probe folds two synthetic events through the
202
+ * real `foldSurface` and accepts only the composing semantics the design
203
+ * needs — plain messages keep their node, and a restore replay keeps its
204
+ * node AND derives assistant-role with the frame stripped — so the channel
205
+ * stays dormant on 0.1.6-alpha.1 and lights up by itself on a host whose
206
+ * fold composes. Pure, synchronous, side-effect-free.
207
+ * @param fold - the host's surface fold, injectable for tests.
208
+ * @param derive - the host's single-event derivation, injectable for tests.
209
+ * @returns true when a registered user/message projection is safe.
210
+ */
211
+ function restoreProjectionFoldSupported(fold = sessionApi.foldSurface, derive = sessionApi.deriveEventMessage) {
212
+ try {
213
+ if (typeof fold !== "function" || typeof derive !== "function") return false;
214
+ const events = [probeEvent(0, "probe", { kind: "user" }), probeEvent(1, `${RESTORED_ASSISTANT_NOTICE}\nprobe answer`, restoreAssistantSource())];
215
+ const folded = fold(events, [restoreAssistantProjection]);
216
+ if (folded.nodes.length !== events.length) return false;
217
+ const derived = derive(events[1], folded.projectedMessages);
218
+ return derived?.role === "assistant" && derived.content.some((block) => block.type === "text" && block.text === "probe answer");
219
+ } catch {
220
+ return false;
221
+ }
222
+ }
223
+ /**
224
+ * Probe and register the restore-assistant projection, degrading to the
225
+ * framed user-role channel (which the durable events already carry) whenever
226
+ * the host cannot carry the projection: pre-0.1.6 (`registerMessageProjection`
227
+ * absent), a fold that cannot compose projections with surface membership, or
228
+ * a registration conflict (the projection slot is one-per-type per instance —
229
+ * a future official projection claiming user/message throws, and the plugin
230
+ * must not take the instance down with it).
231
+ * @param ctx - host context carrying the session store.
232
+ * @param foldSupported - fold-semantics probe, injectable for tests.
233
+ * @returns true when the projection channel is active.
234
+ */
235
+ function registerRestoreProjection(ctx, foldSupported = restoreProjectionFoldSupported) {
236
+ const sessions = ctx.sessions;
237
+ if (typeof sessions.registerMessageProjection !== "function") {
238
+ ctx.logger.info("message-tools: host has no sessions.registerMessageProjection — restored assistant text stays in the framed user-role channel");
239
+ return false;
240
+ }
241
+ if (!foldSupported()) {
242
+ ctx.logger.warn("message-tools: host message-projection fold drops projected user/message events from the surface — restored assistant text stays in the framed user-role channel");
243
+ return false;
244
+ }
245
+ try {
246
+ const dispose = sessions.registerMessageProjection(restoreAssistantProjection);
247
+ ctx.effect(() => () => dispose(), "message-tools: restore-assistant projection");
248
+ return true;
249
+ } catch {
250
+ ctx.logger.warn("message-tools: a user/message message-projection is already registered — restored assistant text stays in the framed user-role channel");
251
+ return false;
252
+ }
107
253
  }
108
254
  //#endregion
109
255
  //#region lib/types/withdraw.js
@@ -423,7 +569,7 @@ var __esDecorate = function(ctor, descriptorIn, decorators, contextIn, initializ
423
569
  /**
424
570
  * messageTools Remote service: appends the withdrawal replacement to the
425
571
  * owning Session and flushes it durable. The replacement event's
426
- * plugin-tagged source is the audit trail; no new session event type is
572
+ * producer-owned source is the audit trail; no new session event type is
427
573
  * introduced, so session reload stays safe for harnesses without this plugin.
428
574
  */
429
575
  let MessageToolsService = (() => {
@@ -485,10 +631,11 @@ let MessageToolsService = (() => {
485
631
  constructor(ctx) {
486
632
  super(ctx, "messageTools");
487
633
  __runInitializers(this, _instanceExtraInitializers);
634
+ registerRestoreProjection(ctx);
488
635
  }
489
636
  /**
490
637
  * Withdraw a user message: replace it and every surface node after it with
491
- * a minimal plugin-sourced placeholder, hiding the span from the model.
638
+ * a minimal producer-sourced placeholder, hiding the span from the model.
492
639
  * @param request - session identity and target message seq.
493
640
  * @returns the replacement receipt, or a rejection from the closed failure union.
494
641
  */
@@ -508,10 +655,7 @@ let MessageToolsService = (() => {
508
655
  type: "text",
509
656
  text: WITHDRAWN_NOTICE
510
657
  }],
511
- source: {
512
- kind: "plugin",
513
- plugin: MESSAGE_TOOLS_PLUGIN
514
- }
658
+ source: messageToolsSource()
515
659
  }), {
516
660
  surfaceOp: {
517
661
  op: "replace",
@@ -532,14 +676,14 @@ let MessageToolsService = (() => {
532
676
  /**
533
677
  * Restore a withdrawn span: replay every replayable entry of it (user
534
678
  * messages verbatim — including the last edit's new text — and framed
535
- * assistant text; tool calls/results never replay) as fresh plugin-tagged
536
- * `user/message` appends at the conversation tail, in original order, each
537
- * citing its original event in `sourceEventSeqs`. The surface replace model
538
- * is positional — a replaced span folds into one node — so the span cannot
539
- * be restored in place; the replayed entries are simply the newest messages
540
- * the model sees. Assistant text replays as framed user-role messages:
541
- * `assistant/message` cannot carry a plugin source and the turn/step trace
542
- * forbids assistant appends outside a step.
679
+ * assistant text; tool calls/results never replay) as fresh
680
+ * producer-sourced `user/message` appends at the conversation tail, in
681
+ * original order, each citing its original event in `sourceEventSeqs`. The
682
+ * surface replace model is positional — a replaced span folds into one
683
+ * node — so the span cannot be restored in place; the replayed entries are
684
+ * simply the newest messages the model sees. Assistant text replays as
685
+ * framed user-role messages: `assistant/message` requires the model source
686
+ * and the turn/step trace forbids assistant appends outside a step.
543
687
  * @param request - session identity and withdrawn message seq.
544
688
  * @returns the restore receipt, or a rejection from the closed failure union.
545
689
  */
@@ -558,10 +702,7 @@ let MessageToolsService = (() => {
558
702
  for (const entry of planned.plan.entries) {
559
703
  const message = entry.role === "user" ? createUserMessage({
560
704
  content: [...entry.content],
561
- source: {
562
- kind: "plugin",
563
- plugin: MESSAGE_TOOLS_PLUGIN
564
- }
705
+ source: messageToolsSource()
565
706
  }) : createUserMessage({
566
707
  content: [{
567
708
  type: "text",
@@ -586,7 +727,7 @@ let MessageToolsService = (() => {
586
727
  * with the edited text itself (no placeholder, no tail duplicate — the
587
728
  * edited text appears exactly once, in the replacement event), then start a
588
729
  * regeneration turn. The harness has no wake-without-append path, so the
589
- * turn is started by `agent.followup` carrying a minimal plugin-sourced
730
+ * turn is started by `agent.followup` carrying a minimal producer-sourced
590
731
  * trigger message (the ankh-guard/schedule pattern); the trigger is not the
591
732
  * edited text and lands once, as itself.
592
733
  * @param request - session identity, target seq, edited text.
@@ -1,12 +1,14 @@
1
1
  /* Generated by @deepseek-ai/dsh-typert-generator from FaceModel — do not edit. */
2
2
  import { z } from 'zod'
3
3
 
4
- const _khorsheed_dsh_client_message_tools_messageTools_edit_parameter_0$schema = z.object({
4
+ let _khorsheed_dsh_client_message_tools_messageTools_edit_parameter_0$schema$value
5
+ const _khorsheed_dsh_client_message_tools_messageTools_edit_parameter_0$schema = () => (_khorsheed_dsh_client_message_tools_messageTools_edit_parameter_0$schema$value ??= z.object({
5
6
  'sessionId': z.intersection(z.string(), z.unknown()).readonly(),
6
7
  'targetSeq': z.number().readonly(),
7
8
  'text': z.string().readonly(),
8
- })
9
- const _khorsheed_dsh_client_message_tools_messageTools_edit_result$schema = z.union([z.object({
9
+ }))
10
+ let _khorsheed_dsh_client_message_tools_messageTools_edit_result$schema$value
11
+ const _khorsheed_dsh_client_message_tools_messageTools_edit_result$schema = () => (_khorsheed_dsh_client_message_tools_messageTools_edit_result$schema$value ??= z.union([z.object({
10
12
  'ok': z.literal(true).readonly(),
11
13
  'value': z.object({
12
14
  'replacementSeq': z.number().readonly(),
@@ -25,12 +27,14 @@ const _khorsheed_dsh_client_message_tools_messageTools_edit_result$schema = z.un
25
27
  }), z.object({
26
28
  'code': z.literal("empty-text").readonly(),
27
29
  })]).readonly(),
28
- })])
29
- const _khorsheed_dsh_client_message_tools_messageTools_restore_parameter_0$schema = z.object({
30
+ })]))
31
+ let _khorsheed_dsh_client_message_tools_messageTools_restore_parameter_0$schema$value
32
+ const _khorsheed_dsh_client_message_tools_messageTools_restore_parameter_0$schema = () => (_khorsheed_dsh_client_message_tools_messageTools_restore_parameter_0$schema$value ??= z.object({
30
33
  'sessionId': z.intersection(z.string(), z.unknown()).readonly(),
31
34
  'targetSeq': z.number().readonly(),
32
- })
33
- const _khorsheed_dsh_client_message_tools_messageTools_restore_result$schema = z.union([z.object({
35
+ }))
36
+ let _khorsheed_dsh_client_message_tools_messageTools_restore_result$schema$value
37
+ const _khorsheed_dsh_client_message_tools_messageTools_restore_result$schema = () => (_khorsheed_dsh_client_message_tools_messageTools_restore_result$schema$value ??= z.union([z.object({
34
38
  'ok': z.literal(true).readonly(),
35
39
  'value': z.object({
36
40
  'restoredSeq': z.number().readonly(),
@@ -46,12 +50,14 @@ const _khorsheed_dsh_client_message_tools_messageTools_restore_result$schema = z
46
50
  }), z.object({
47
51
  'code': z.literal("not-withdrawn").readonly(),
48
52
  })]).readonly(),
49
- })])
50
- const _khorsheed_dsh_client_message_tools_messageTools_withdraw_parameter_0$schema = z.object({
53
+ })]))
54
+ let _khorsheed_dsh_client_message_tools_messageTools_withdraw_parameter_0$schema$value
55
+ const _khorsheed_dsh_client_message_tools_messageTools_withdraw_parameter_0$schema = () => (_khorsheed_dsh_client_message_tools_messageTools_withdraw_parameter_0$schema$value ??= z.object({
51
56
  'sessionId': z.intersection(z.string(), z.unknown()).readonly(),
52
57
  'targetSeq': z.number().readonly(),
53
- })
54
- const _khorsheed_dsh_client_message_tools_messageTools_withdraw_result$schema = z.union([z.object({
58
+ }))
59
+ let _khorsheed_dsh_client_message_tools_messageTools_withdraw_result$schema$value
60
+ const _khorsheed_dsh_client_message_tools_messageTools_withdraw_result$schema = () => (_khorsheed_dsh_client_message_tools_messageTools_withdraw_result$schema$value ??= z.union([z.object({
55
61
  'ok': z.literal(true).readonly(),
56
62
  'value': z.object({
57
63
  'replacementSeq': z.number().readonly(),
@@ -68,7 +74,7 @@ const _khorsheed_dsh_client_message_tools_messageTools_withdraw_result$schema =
68
74
  }), z.object({
69
75
  'code': z.literal("already-withdrawn").readonly(),
70
76
  })]).readonly(),
71
- })])
77
+ })]))
72
78
 
73
79
  export const TYPERT = {
74
80
  package: '@khorsheed/dsh-client-message-tools',
@@ -90,16 +96,18 @@ export const TYPERT = {
90
96
  codec: {
91
97
  mode: 'strict',
92
98
  typeSymbol: '@khorsheed/dsh-client-message-tools/types#MessageToolsEditRequest',
93
- schema: _khorsheed_dsh_client_message_tools_messageTools_edit_parameter_0$schema,
99
+ create: _khorsheed_dsh_client_message_tools_messageTools_edit_parameter_0$schema,
100
+ schema: _khorsheed_dsh_client_message_tools_messageTools_edit_parameter_0$schema(),
94
101
  },
95
102
  },
96
103
  ],
97
104
  result: {
98
105
  mode: 'strict',
99
106
  typeSymbol: '@khorsheed/dsh-client-message-tools/types#MessageToolsEditResult',
100
- schema: _khorsheed_dsh_client_message_tools_messageTools_edit_result$schema,
107
+ create: _khorsheed_dsh_client_message_tools_messageTools_edit_result$schema,
108
+ schema: _khorsheed_dsh_client_message_tools_messageTools_edit_result$schema(),
101
109
  },
102
- sourceLocation: {"file":"packages/message-tools/src/index.ts","line":135,"column":9},
110
+ sourceLocation: {"file":"packages/message-tools/src/index.ts","line":140,"column":9},
103
111
  },
104
112
  {
105
113
  id: '@khorsheed/dsh-client-message-tools#messageTools/restore',
@@ -115,16 +123,18 @@ export const TYPERT = {
115
123
  codec: {
116
124
  mode: 'strict',
117
125
  typeSymbol: '@khorsheed/dsh-client-message-tools/types#MessageToolsRestoreRequest',
118
- schema: _khorsheed_dsh_client_message_tools_messageTools_restore_parameter_0$schema,
126
+ create: _khorsheed_dsh_client_message_tools_messageTools_restore_parameter_0$schema,
127
+ schema: _khorsheed_dsh_client_message_tools_messageTools_restore_parameter_0$schema(),
119
128
  },
120
129
  },
121
130
  ],
122
131
  result: {
123
132
  mode: 'strict',
124
133
  typeSymbol: '@khorsheed/dsh-client-message-tools/types#MessageToolsRestoreResult',
125
- schema: _khorsheed_dsh_client_message_tools_messageTools_restore_result$schema,
134
+ create: _khorsheed_dsh_client_message_tools_messageTools_restore_result$schema,
135
+ schema: _khorsheed_dsh_client_message_tools_messageTools_restore_result$schema(),
126
136
  },
127
- sourceLocation: {"file":"packages/message-tools/src/index.ts","line":97,"column":9},
137
+ sourceLocation: {"file":"packages/message-tools/src/index.ts","line":102,"column":9},
128
138
  },
129
139
  {
130
140
  id: '@khorsheed/dsh-client-message-tools#messageTools/withdraw',
@@ -140,25 +150,27 @@ export const TYPERT = {
140
150
  codec: {
141
151
  mode: 'strict',
142
152
  typeSymbol: '@khorsheed/dsh-client-message-tools/types#MessageToolsWithdrawRequest',
143
- schema: _khorsheed_dsh_client_message_tools_messageTools_withdraw_parameter_0$schema,
153
+ create: _khorsheed_dsh_client_message_tools_messageTools_withdraw_parameter_0$schema,
154
+ schema: _khorsheed_dsh_client_message_tools_messageTools_withdraw_parameter_0$schema(),
144
155
  },
145
156
  },
146
157
  ],
147
158
  result: {
148
159
  mode: 'strict',
149
160
  typeSymbol: '@khorsheed/dsh-client-message-tools/types#MessageToolsWithdrawResult',
150
- schema: _khorsheed_dsh_client_message_tools_messageTools_withdraw_result$schema,
161
+ create: _khorsheed_dsh_client_message_tools_messageTools_withdraw_result$schema,
162
+ schema: _khorsheed_dsh_client_message_tools_messageTools_withdraw_result$schema(),
151
163
  },
152
- sourceLocation: {"file":"packages/message-tools/src/index.ts","line":63,"column":9},
164
+ sourceLocation: {"file":"packages/message-tools/src/index.ts","line":68,"column":9},
153
165
  },
154
166
  ],
155
167
  model: {
156
168
  "services": [
157
169
  {
158
- "description": "messageTools Remote service: appends the withdrawal replacement to the owning Session and flushes it durable. The replacement event's plugin-tagged source is the audit trail; no new session event type is introduced, so session reload stays safe for harnesses without this plugin.",
170
+ "description": "messageTools Remote service: appends the withdrawal replacement to the owning Session and flushes it durable. The replacement event's producer-owned source is the audit trail; no new session event type is introduced, so session reload stays safe for harnesses without this plugin.",
159
171
  "summary": "messageTools Remote service: appends the withdrawal replacement to the owning Session and flushes it durable.",
160
172
  "tags": [],
161
- "jsDoc": "/**\n * messageTools Remote service: appends the withdrawal replacement to the\n * owning Session and flushes it durable. The replacement event's\n * plugin-tagged source is the audit trail; no new session event type is\n * introduced, so session reload stays safe for harnesses without this plugin.\n */",
173
+ "jsDoc": "/**\n * messageTools Remote service: appends the withdrawal replacement to the\n * owning Session and flushes it durable. The replacement event's\n * producer-owned source is the audit trail; no new session event type is\n * introduced, so session reload stays safe for harnesses without this plugin.\n */",
162
174
  "key": "messageTools",
163
175
  "exportName": "MessageToolsService",
164
176
  "members": [
@@ -166,22 +178,22 @@ export const TYPERT = {
166
178
  "kind": "method",
167
179
  "name": "withdraw",
168
180
  "signature": "@Remote('withdraw') async withdraw(request: MessageToolsWithdrawRequest): Promise<MessageToolsWithdrawResult>",
169
- "summary": "Withdraw a user message: replace it and every surface node after it with a minimal plugin-sourced placeholder, hiding the span from the model.",
170
- "jsDoc": "/**\n * Withdraw a user message: replace it and every surface node after it with\n * a minimal plugin-sourced placeholder, hiding the span from the model.\n * @param request - session identity and target message seq.\n * @returns the replacement receipt, or a rejection from the closed failure union.\n */"
181
+ "summary": "Withdraw a user message: replace it and every surface node after it with a minimal producer-sourced placeholder, hiding the span from the model.",
182
+ "jsDoc": "/**\n * Withdraw a user message: replace it and every surface node after it with\n * a minimal producer-sourced placeholder, hiding the span from the model.\n * @param request - session identity and target message seq.\n * @returns the replacement receipt, or a rejection from the closed failure union.\n */"
171
183
  },
172
184
  {
173
185
  "kind": "method",
174
186
  "name": "restore",
175
187
  "signature": "@Remote('restore') async restore(request: MessageToolsRestoreRequest): Promise<MessageToolsRestoreResult>",
176
- "summary": "Restore a withdrawn span: replay every replayable entry of it (user messages verbatim — including the last edit's new text — and framed assistant text; tool calls/results never replay) as fresh plugin-tagged `user/message` appends at the conversation tail, in original order, each citing its original event in `sourceEventSeqs`.",
177
- "jsDoc": "/**\n * Restore a withdrawn span: replay every replayable entry of it (user\n * messages verbatim — including the last edit's new text — and framed\n * assistant text; tool calls/results never replay) as fresh plugin-tagged\n * `user/message` appends at the conversation tail, in original order, each\n * citing its original event in `sourceEventSeqs`. The surface replace model\n * is positional — a replaced span folds into one node — so the span cannot\n * be restored in place; the replayed entries are simply the newest messages\n * the model sees. Assistant text replays as framed user-role messages:\n * `assistant/message` cannot carry a plugin source and the turn/step trace\n * forbids assistant appends outside a step.\n * @param request - session identity and withdrawn message seq.\n * @returns the restore receipt, or a rejection from the closed failure union.\n */"
188
+ "summary": "Restore a withdrawn span: replay every replayable entry of it (user messages verbatim — including the last edit's new text — and framed assistant text; tool calls/results never replay) as fresh producer-sourced `user/message` appends at the conversation tail, in original order, each citing its original event in `sourceEventSeqs`.",
189
+ "jsDoc": "/**\n * Restore a withdrawn span: replay every replayable entry of it (user\n * messages verbatim — including the last edit's new text — and framed\n * assistant text; tool calls/results never replay) as fresh\n * producer-sourced `user/message` appends at the conversation tail, in\n * original order, each citing its original event in `sourceEventSeqs`. The\n * surface replace model is positional — a replaced span folds into one\n * node — so the span cannot be restored in place; the replayed entries are\n * simply the newest messages the model sees. Assistant text replays as\n * framed user-role messages: `assistant/message` requires the model source\n * and the turn/step trace forbids assistant appends outside a step.\n * @param request - session identity and withdrawn message seq.\n * @returns the restore receipt, or a rejection from the closed failure union.\n */"
178
190
  },
179
191
  {
180
192
  "kind": "method",
181
193
  "name": "edit",
182
194
  "signature": "@Remote('edit') async edit(request: MessageToolsEditRequest): Promise<MessageToolsEditResult>",
183
195
  "summary": "Edit a user message in place: replace it and every surface node after it with the edited text itself (no placeholder, no tail duplicate — the edited text appears exactly once, in the replacement event), then start a regeneration turn.",
184
- "jsDoc": "/**\n * Edit a user message in place: replace it and every surface node after it\n * with the edited text itself (no placeholder, no tail duplicate — the\n * edited text appears exactly once, in the replacement event), then start a\n * regeneration turn. The harness has no wake-without-append path, so the\n * turn is started by `agent.followup` carrying a minimal plugin-sourced\n * trigger message (the ankh-guard/schedule pattern); the trigger is not the\n * edited text and lands once, as itself.\n * @param request - session identity, target seq, edited text.\n * @returns the replacement receipt and whether the turn was triggered, or a rejection.\n */"
196
+ "jsDoc": "/**\n * Edit a user message in place: replace it and every surface node after it\n * with the edited text itself (no placeholder, no tail duplicate — the\n * edited text appears exactly once, in the replacement event), then start a\n * regeneration turn. The harness has no wake-without-append path, so the\n * turn is started by `agent.followup` carrying a minimal producer-sourced\n * trigger message (the ankh-guard/schedule pattern); the trigger is not the\n * edited text and lands once, as itself.\n * @param request - session identity, target seq, edited text.\n * @returns the replacement receipt and whether the turn was triggered, or a rejection.\n */"
185
197
  }
186
198
  ],
187
199
  "types": [