dsh-tidy-display 0.4.2 → 0.4.4

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.
Files changed (37) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/lib/client.js +141 -15
  3. package/lib/client.js.map +1 -1
  4. package/lib/types/client/OfficialContent.d.ts +9 -0
  5. package/lib/types/client/OfficialContent.d.ts.map +1 -1
  6. package/lib/types/client/OfficialContent.js +30 -9
  7. package/lib/types/client/OfficialContent.js.map +1 -1
  8. package/lib/types/client/Reader.d.ts.map +1 -1
  9. package/lib/types/client/Reader.js +11 -2
  10. package/lib/types/client/Reader.js.map +1 -1
  11. package/lib/types/client/ToolActivity.d.ts.map +1 -1
  12. package/lib/types/client/ToolActivity.js +3 -1
  13. package/lib/types/client/ToolActivity.js.map +1 -1
  14. package/lib/types/client/entry-policy.d.ts.map +1 -1
  15. package/lib/types/client/entry-policy.js +4 -1
  16. package/lib/types/client/entry-policy.js.map +1 -1
  17. package/lib/types/client/entry.d.ts.map +1 -1
  18. package/lib/types/client/entry.js +44 -1
  19. package/lib/types/client/entry.js.map +1 -1
  20. package/lib/types/client/index.d.ts.map +1 -1
  21. package/lib/types/client/index.js +40 -5
  22. package/lib/types/client/index.js.map +1 -1
  23. package/lib/types/client/official-slots.d.ts +18 -0
  24. package/lib/types/client/official-slots.d.ts.map +1 -1
  25. package/lib/types/client/official-slots.js +38 -4
  26. package/lib/types/client/official-slots.js.map +1 -1
  27. package/package.json +1 -1
  28. package/src/client/OfficialContent.tsx +32 -8
  29. package/src/client/Reader.module.css +31 -2
  30. package/src/client/Reader.tsx +10 -2
  31. package/src/client/ToolActivity.tsx +3 -1
  32. package/src/client/entry-policy.ts +4 -1
  33. package/src/client/entry.tsx +42 -1
  34. package/src/client/index.tsx +37 -5
  35. package/src/client/official-slots.tsx +47 -3
  36. package/tests/entry.test.ts +9 -5
  37. package/tests/official-slots.test.ts +41 -1
@@ -1,4 +1,4 @@
1
- import { createElement, memo, useMemo, type ComponentType, type ReactNode } from 'react';
1
+ import { createElement, memo, useCallback, useMemo, useSyncExternalStore, type ComponentType, type ReactNode } from 'react';
2
2
  import type { Context } from '@deepseek-ai/cordis';
3
3
  import type { SlotEntryDef, SlotMap, SlotSpec, StoredEntry } from '@deepseek-ai/dsh-client-ui-slots';
4
4
  import type {} from '@deepseek-ai/dsh-client-ui-renderer/client';
@@ -59,6 +59,45 @@ declare module '@deepseek-ai/dsh-client-ui-slots' {
59
59
  // Existing Reader presentations own these rows. All other node kinds, including
60
60
  // future registrations, reach the official renderer through the fallback seat.
61
61
  const READER_NODES = new Set(['user', 'steering', 'assistant-step', 'tool-call', 'turn-tail', 'turn-process']);
62
+
63
+ /**
64
+ * An external takeover registers the node with a negative priority. The host's own
65
+ * assistant-step registration carries none (register-node-renderers.ts), so the
66
+ * sign of the rank is the smallest sufficient signal that someone else renders it.
67
+ */
68
+ export const isShadowWinner = (entry: StoredEntry): boolean =>
69
+ typeof entry.options.priority === 'number' && entry.options.priority < 0;
70
+
71
+ /**
72
+ * Mirror only node kinds the Reader does not present itself. assistant-step stays
73
+ * Reader-owned unless a shadow takeover wins its cell; then it must reach the
74
+ * mirror seat so the Reader can delegate to it.
75
+ */
76
+ export const acceptOfficialNode = (entry: StoredEntry): boolean =>
77
+ !READER_NODES.has(entry.options.key ?? '')
78
+ || (entry.options.key === 'assistant-step' && isShadowWinner(entry));
79
+
80
+ /** Registry captured at install; the Reader's delegation read needs election winners. */
81
+ let installedSlots: CompositionRegistry | undefined;
82
+
83
+ /**
84
+ * Reactive read for the Reader: does an external shadow takeover win the
85
+ * assistant-step cell? Subscribes to the source slot so enabling the takeover
86
+ * plugin after mount flips the answer.
87
+ */
88
+ export function useAssistantStepShadow(): boolean {
89
+ const registry = installedSlots;
90
+ const subscribe = useCallback(
91
+ (notify: () => void) => registry?.subscribe(OFFICIAL_SLOTS.nodes, notify) ?? (() => {}),
92
+ [registry],
93
+ );
94
+ const read = useCallback(
95
+ () => registry?.entriesOfSlot(OFFICIAL_SLOTS.nodes)
96
+ .some(entry => entry.options.key === 'assistant-step' && isShadowWinner(entry)) ?? false,
97
+ [registry],
98
+ );
99
+ return useSyncExternalStore(subscribe, read);
100
+ }
62
101
  const EXPECTED: Record<OfficialFamily, Spec[]> = {
63
102
  actions: [{ kind: 'list', scope: 'session' }],
64
103
  tools: [{ kind: 'keyed', scope: 'session' }],
@@ -199,6 +238,7 @@ export function installOfficialSlots(ctx: Context): () => void {
199
238
  // The SlotMap overloads are for statically declared keys. Aliases are a
200
239
  // runtime composition, using exactly the public erased metadata contract.
201
240
  const slots = ctx.slots as unknown as CompositionRegistry;
241
+ installedSlots = slots;
202
242
  const disposers: (() => void)[] = [];
203
243
  try {
204
244
  for (const [name, source] of Object.entries(OFFICIAL_SLOTS)) {
@@ -213,14 +253,18 @@ export function installOfficialSlots(ctx: Context): () => void {
213
253
  console.warn(`[dsh-tidy-display] official slot contract drift on mirror: ${source} (${spec.kind}/${spec.scope} vs ${declared?.kind ?? 'none'}/${declared?.scope ?? 'none'})`);
214
254
  }
215
255
  return mirrorOfficialSlot(slots, source, target, `dsh-tidy-display.official.${family}`,
216
- family === 'nodes' ? entry => !READER_NODES.has(entry.options.key ?? '') : undefined);
256
+ family === 'nodes' ? acceptOfficialNode : undefined);
217
257
  }));
218
258
  }
219
259
  } catch (error) {
220
260
  for (const stop of disposers.reverse()) stop();
261
+ if (installedSlots === slots) installedSlots = undefined;
221
262
  throw error;
222
263
  }
223
- return () => { for (const stop of disposers.splice(0).reverse()) stop(); };
264
+ return () => {
265
+ for (const stop of disposers.splice(0).reverse()) stop();
266
+ if (installedSlots === slots) installedSlots = undefined;
267
+ };
224
268
  }
225
269
 
226
270
  export type OfficialSlotKey = typeof OFFICIAL_SLOTS[OfficialFamily] & keyof SlotMap;
@@ -2,20 +2,24 @@ import assert from 'node:assert/strict';
2
2
  import { test } from 'node:test';
3
3
  import { ReaderEntryPolicy, readerEntryRequested } from '../src/client/entry-policy.js';
4
4
 
5
- test('fresh sessions default to reading, without requiring a special URL', () => {
5
+ // R2: the default tab is 对话 — an entry with no explicit request never forces
6
+ // the reader. A null/undefined view falls through to the host's own default.
7
+ test('fresh sessions default to the host (对话), not the reading view', () => {
6
8
  const policy = new ReaderEntryPolicy(false);
7
- assert.equal(policy.select(null), 'reader');
9
+ assert.equal(policy.select(null), null);
10
+ assert.equal(policy.select(undefined), null);
8
11
  assert.equal(policy.select('reader'), null);
9
- assert.equal(policy.select(undefined), 'reader');
10
12
  });
11
13
 
12
14
  test('an explicit native or third-party tab selection is not overwritten', () => {
13
15
  const policy = new ReaderEntryPolicy(false);
14
16
  for (const view of ['chat', 'trajectory', 'other-plugin']) assert.equal(policy.select(view), null);
15
- assert.equal(policy.select(null), 'reader');
17
+ assert.equal(policy.select(null), null);
16
18
  assert.equal(policy.select('chat'), null);
17
19
  });
18
20
 
21
+ // With an explicit ?reader=1 request the reader lands once, then releases every
22
+ // later tab choice — including a still-null view, because the request is spent.
19
23
  test('the trial URL enters reading once and releases later tab choices', () => {
20
24
  let consumed = 0;
21
25
  const policy = new ReaderEntryPolicy(true, () => { consumed++; });
@@ -25,7 +29,7 @@ test('the trial URL enters reading once and releases later tab choices', () => {
25
29
  assert.equal(policy.select('chat'), null);
26
30
  assert.equal(policy.select('trajectory'), null);
27
31
  assert.equal(consumed, 1);
28
- assert.equal(policy.select(null), 'reader');
32
+ assert.equal(policy.select(null), null);
29
33
  });
30
34
 
31
35
  test('already-selected reading still consumes the entry request', () => {
@@ -2,7 +2,7 @@ import assert from 'node:assert/strict';
2
2
  import test from 'node:test';
3
3
  import { memo } from 'react';
4
4
  import { SlotCore } from '@deepseek-ai/dsh-client-ui-slots';
5
- import { mirrorOfficialSlot, readerTailMatch, type CompositionRegistry } from '../src/client/official-slots.js';
5
+ import { acceptOfficialNode, isShadowWinner, mirrorOfficialSlot, readerTailMatch, type CompositionRegistry } from '../src/client/official-slots.js';
6
6
 
7
7
  function registry(kind: 'keyed' | 'chain' | 'list' = 'keyed') {
8
8
  const core = new SlotCore();
@@ -10,6 +10,7 @@ function registry(kind: 'keyed' | 'chain' | 'list' = 'keyed') {
10
10
  register({ name: 'root', children: {
11
11
  source: { kind, scope: 'session' },
12
12
  reader: { kind, scope: 'session' },
13
+ toolview: { kind: 'keyed', scope: 'session' },
13
14
  } }, () => null);
14
15
  const slots: CompositionRegistry = {
15
16
  register,
@@ -96,6 +97,45 @@ test('new registrations do not remount existing cards; winner changes and unload
96
97
  assert.equal(core.entriesOfSlot('reader').length, 0);
97
98
  });
98
99
 
100
+ test('a keyed render_ui toolview registration reaches the mirror seat', () => {
101
+ const { core, slots, register } = registry();
102
+ const genui = memo(() => null);
103
+ register({ name: 'source', key: 'render_ui' }, genui);
104
+ const stop = mirrorOfficialSlot(slots, 'source', 'toolview', 'reader.toolview');
105
+ const mirrored = core.entriesOfSlot('toolview')[0];
106
+ assert.equal(mirrored.component, genui);
107
+ assert.equal(mirrored.options.key, 'render_ui');
108
+ stop();
109
+ assert.equal(core.entriesOfSlot('toolview').length, 0);
110
+ });
111
+
112
+ test('the host assistant-step baseline is not mirrored into the reader seat', () => {
113
+ const { core, slots, register } = registry();
114
+ register({ name: 'source', key: 'assistant-step' }, memo(() => null));
115
+ register({ name: 'source', key: 'command' }, memo(() => null));
116
+ const stop = mirrorOfficialSlot(slots, 'source', 'reader', 'reader.children', acceptOfficialNode);
117
+ assert.deepEqual(core.entriesOfSlot('reader').map(entry => entry.options.key), ['command']);
118
+ stop();
119
+ });
120
+
121
+ test('a negative-priority assistant-step shadow takeover is mirrored into the reader seat', async () => {
122
+ const { core, slots, register } = registry();
123
+ register({ name: 'source', key: 'assistant-step' }, memo(() => null));
124
+ const shadow = memo(() => null);
125
+ const stop = mirrorOfficialSlot(slots, 'source', 'reader', 'reader.children', acceptOfficialNode);
126
+ assert.equal(core.entriesOfSlot('reader').length, 0);
127
+ const dropShadow = register({ name: 'source', key: 'assistant-step', priority: -10 }, shadow);
128
+ await changed();
129
+ const taken = core.entriesOfSlot('reader')[0];
130
+ assert.equal(taken.component, shadow);
131
+ assert.equal(taken.options.key, 'assistant-step');
132
+ assert.equal(isShadowWinner(taken), true);
133
+ dropShadow();
134
+ await changed();
135
+ assert.equal(core.entriesOfSlot('reader').length, 0);
136
+ stop();
137
+ });
138
+
99
139
  test('partial setup rolls back its own registrations on a nested contract failure', () => {
100
140
  const { core, slots, register } = registry();
101
141
  register({ name: 'source', key: 'nested', children: { detail: { kind: 'single', scope: 'session' } } }, () => null);