@buffcore/admin-shell 0.8.43 → 0.8.45

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 (157) hide show
  1. package/dist/components/Markdown.d.ts +9 -3
  2. package/dist/components/Markdown.js +84 -34
  3. package/dist/components/Sheet.d.ts +5 -1
  4. package/dist/components/Sheet.js +8 -2
  5. package/dist/components/TextArea.d.ts +3 -1
  6. package/dist/components/TextArea.js +3 -3
  7. package/dist/components/icons.d.ts +1 -0
  8. package/dist/components/icons.js +1 -0
  9. package/dist/workbench/app/ServedPrototype.d.ts +2 -0
  10. package/dist/workbench/app/ServedPrototype.js +11 -1
  11. package/dist/workbench/app/__snapshots__/places-dom.test.tsx.snap +30 -3
  12. package/dist/workbench/app/actions.d.ts +4 -2
  13. package/dist/workbench/app/actions.js +9 -4
  14. package/dist/workbench/app/brief-short.d.ts +14 -0
  15. package/dist/workbench/app/brief-short.js +103 -0
  16. package/dist/workbench/app/chat-session.d.ts +5 -5
  17. package/dist/workbench/app/chat-session.js +8 -3
  18. package/dist/workbench/app/chat.d.ts +17 -4
  19. package/dist/workbench/app/chat.js +9 -4
  20. package/dist/workbench/app/frame.js +5 -1
  21. package/dist/workbench/app/loop.js +2 -18
  22. package/dist/workbench/app/pages.js +10 -2
  23. package/dist/workbench/app/prototype.js +3 -0
  24. package/dist/workbench/app/test/loop-fixture.d.ts +13 -1
  25. package/dist/workbench/app/useStudio.d.ts +2 -1
  26. package/dist/workbench/studio/frame/AgentPanel.js +24 -1
  27. package/dist/workbench/studio/frame/Composer.js +13 -10
  28. package/dist/workbench/studio/frame/PanelList.js +1 -1
  29. package/dist/workbench/studio/frame/Segmented.d.ts +3 -1
  30. package/dist/workbench/studio/frame/Segmented.js +4 -3
  31. package/dist/workbench/studio/frame/SettingsSheet.js +10 -9
  32. package/dist/workbench/studio/frame/StudioFrame.js +7 -6
  33. package/dist/workbench/studio/frame/StudioRegions.js +4 -1
  34. package/dist/workbench/studio/frame/TurnControls.d.ts +2 -1
  35. package/dist/workbench/studio/frame/TurnControls.js +4 -1
  36. package/dist/workbench/studio/frame/layout.d.ts +2 -0
  37. package/dist/workbench/studio/frame/layout.js +2 -0
  38. package/dist/workbench/studio/frame/panelControls.d.ts +21 -1
  39. package/dist/workbench/studio/frame/scrollbars.d.ts +1 -0
  40. package/dist/workbench/studio/frame/scrollbars.js +12 -0
  41. package/dist/workbench/studio/frame/useTurnDraft.d.ts +22 -2
  42. package/dist/workbench/studio/frame/useTurnDraft.js +48 -16
  43. package/dist/workbench/studio/i18n/frame.en.d.ts +3 -0
  44. package/dist/workbench/studio/i18n/frame.en.js +4 -1
  45. package/dist/workbench/studio/i18n/frame.es.json +4 -1
  46. package/dist/workbench/studio/i18n/index.js +6 -0
  47. package/dist/workbench/studio/i18n/loop.en.d.ts +11 -38
  48. package/dist/workbench/studio/i18n/loop.en.js +11 -38
  49. package/dist/workbench/studio/i18n/loop.es.json +11 -38
  50. package/dist/workbench/studio/i18n/marks.en.d.ts +41 -0
  51. package/dist/workbench/studio/i18n/marks.en.js +42 -0
  52. package/dist/workbench/studio/i18n/marks.es.json +40 -0
  53. package/dist/workbench/studio/i18n/start.en.d.ts +5 -0
  54. package/dist/workbench/studio/i18n/start.en.js +7 -2
  55. package/dist/workbench/studio/i18n/start.es.json +7 -2
  56. package/dist/workbench/studio/i18n/workspace.en.d.ts +45 -0
  57. package/dist/workbench/studio/i18n/workspace.en.js +46 -0
  58. package/dist/workbench/studio/i18n/workspace.es.json +44 -0
  59. package/dist/workbench/studio/loop/BriefDocument.d.ts +9 -6
  60. package/dist/workbench/studio/loop/BriefDocument.js +48 -76
  61. package/dist/workbench/studio/loop/BriefLists.d.ts +11 -0
  62. package/dist/workbench/studio/loop/BriefLists.js +42 -0
  63. package/dist/workbench/studio/loop/BriefPage.d.ts +6 -2
  64. package/dist/workbench/studio/loop/BriefPage.js +32 -4
  65. package/dist/workbench/studio/loop/BriefReading.d.ts +19 -0
  66. package/dist/workbench/studio/loop/BriefReading.js +22 -0
  67. package/dist/workbench/studio/loop/BriefSection.d.ts +22 -0
  68. package/dist/workbench/studio/loop/BriefSection.js +47 -0
  69. package/dist/workbench/studio/loop/BriefWho.d.ts +6 -0
  70. package/dist/workbench/studio/loop/BriefWho.js +56 -0
  71. package/dist/workbench/studio/loop/CanvasBar.d.ts +0 -1
  72. package/dist/workbench/studio/loop/CanvasBar.js +2 -3
  73. package/dist/workbench/studio/loop/ConsoleFrame.d.ts +13 -0
  74. package/dist/workbench/studio/loop/ConsoleFrame.js +29 -0
  75. package/dist/workbench/studio/loop/NotThisCard.d.ts +6 -1
  76. package/dist/workbench/studio/loop/NotThisCard.js +28 -20
  77. package/dist/workbench/studio/loop/ProtoJourneys.d.ts +1 -8
  78. package/dist/workbench/studio/loop/ProtoJourneys.js +0 -14
  79. package/dist/workbench/studio/loop/PrototypeApp.d.ts +12 -1
  80. package/dist/workbench/studio/loop/PrototypeApp.js +30 -13
  81. package/dist/workbench/studio/loop/PrototypeAttempt.d.ts +2 -1
  82. package/dist/workbench/studio/loop/PrototypeAttempt.js +94 -29
  83. package/dist/workbench/studio/loop/PrototypePage.d.ts +4 -2
  84. package/dist/workbench/studio/loop/PrototypePage.js +25 -1
  85. package/dist/workbench/studio/loop/PrototypePreview.d.ts +35 -6
  86. package/dist/workbench/studio/loop/PrototypePreview.js +127 -76
  87. package/dist/workbench/studio/loop/PrototypePreviewSlot.d.ts +13 -0
  88. package/dist/workbench/studio/loop/PrototypePreviewSlot.js +23 -0
  89. package/dist/workbench/studio/loop/PrototypeScenes.d.ts +1 -1
  90. package/dist/workbench/studio/loop/ServedPlanning.js +1 -1
  91. package/dist/workbench/studio/loop/StudioLoop.d.ts +7 -2
  92. package/dist/workbench/studio/loop/StudioLoop.js +4 -10
  93. package/dist/workbench/studio/loop/WorkspaceBar.d.ts +15 -0
  94. package/dist/workbench/studio/loop/WorkspaceBar.js +52 -0
  95. package/dist/workbench/studio/loop/WorkspaceJourneys.d.ts +17 -0
  96. package/dist/workbench/studio/loop/WorkspaceJourneys.js +99 -0
  97. package/dist/workbench/studio/loop/WorkspaceLeft.d.ts +14 -0
  98. package/dist/workbench/studio/loop/WorkspaceLeft.js +42 -0
  99. package/dist/workbench/studio/loop/WorkspaceStage.d.ts +24 -0
  100. package/dist/workbench/studio/loop/WorkspaceStage.js +142 -0
  101. package/dist/workbench/studio/loop/WorkspaceSteps.d.ts +20 -0
  102. package/dist/workbench/studio/loop/WorkspaceSteps.js +96 -0
  103. package/dist/workbench/studio/loop/moments.js +0 -3
  104. package/dist/workbench/studio/loop/prototype-bridge.d.ts +8 -0
  105. package/dist/workbench/studio/loop/prototype-bridge.js +16 -0
  106. package/dist/workbench/studio/loop/prototype-document.d.ts +9 -0
  107. package/dist/workbench/studio/loop/prototype-document.js +90 -2
  108. package/dist/workbench/studio/loop/prototype-part.d.ts +43 -0
  109. package/dist/workbench/studio/loop/prototype-part.js +104 -0
  110. package/dist/workbench/studio/loop/types.d.ts +26 -26
  111. package/dist/workbench/studio/loop/types.js +0 -3
  112. package/dist/workbench/studio/loop/usePrototypeFrame.d.ts +6 -1
  113. package/dist/workbench/studio/loop/usePrototypeFrame.js +4 -0
  114. package/dist/workbench/studio/loop/workspace-journeys.d.ts +22 -0
  115. package/dist/workbench/studio/loop/workspace-journeys.js +63 -0
  116. package/dist/workbench/studio/loop/workspace-state.d.ts +94 -0
  117. package/dist/workbench/studio/loop/workspace-state.js +50 -0
  118. package/dist/workbench/studio/marks/ChangeList.d.ts +7 -0
  119. package/dist/workbench/studio/marks/ChangeList.js +70 -0
  120. package/dist/workbench/studio/marks/MarkHint.d.ts +18 -0
  121. package/dist/workbench/studio/marks/MarkHint.js +58 -0
  122. package/dist/workbench/studio/marks/MarkNumber.d.ts +6 -0
  123. package/dist/workbench/studio/marks/MarkNumber.js +24 -0
  124. package/dist/workbench/studio/marks/MarksLayer.d.ts +15 -0
  125. package/dist/workbench/studio/marks/MarksLayer.js +144 -0
  126. package/dist/workbench/studio/marks/PinNote.d.ts +13 -0
  127. package/dist/workbench/studio/marks/PinNote.js +49 -0
  128. package/dist/workbench/studio/marks/QueuedChanges.d.ts +6 -0
  129. package/dist/workbench/studio/marks/QueuedChanges.js +51 -0
  130. package/dist/workbench/studio/marks/WorkspaceMarks.d.ts +15 -0
  131. package/dist/workbench/studio/marks/WorkspaceMarks.js +67 -0
  132. package/dist/workbench/studio/marks/marks-message.d.ts +13 -0
  133. package/dist/workbench/studio/marks/marks-message.js +93 -0
  134. package/dist/workbench/studio/marks/marks.d.ts +105 -0
  135. package/dist/workbench/studio/marks/marks.js +133 -0
  136. package/dist/workbench/studio/marks/useMarking.d.ts +36 -0
  137. package/dist/workbench/studio/marks/useMarking.js +111 -0
  138. package/dist/workbench/studio/marks/useSendMarks.d.ts +18 -0
  139. package/dist/workbench/studio/marks/useSendMarks.js +80 -0
  140. package/dist/workbench/studio/types.d.ts +2 -0
  141. package/dist/workbench/studio/work/StudioLater.js +0 -1
  142. package/dist/workbench/studio/work/work-test-data.d.ts +6 -0
  143. package/package.json +6 -6
  144. package/dist/workbench/studio/loop/FsPlan.d.ts +0 -7
  145. package/dist/workbench/studio/loop/FsPlan.js +0 -64
  146. package/dist/workbench/studio/loop/FsStage.d.ts +0 -6
  147. package/dist/workbench/studio/loop/FsStage.js +0 -74
  148. package/dist/workbench/studio/loop/FsToolbar.d.ts +0 -6
  149. package/dist/workbench/studio/loop/FsToolbar.js +0 -61
  150. package/dist/workbench/studio/loop/FullScreen.d.ts +0 -5
  151. package/dist/workbench/studio/loop/FullScreen.js +0 -89
  152. package/dist/workbench/studio/loop/PrototypePreviewMenus.d.ts +0 -18
  153. package/dist/workbench/studio/loop/PrototypePreviewMenus.js +0 -75
  154. package/dist/workbench/studio/loop/PrototypePreviewToolbar.d.ts +0 -27
  155. package/dist/workbench/studio/loop/PrototypePreviewToolbar.js +0 -52
  156. package/dist/workbench/studio/loop/fsViews.d.ts +0 -12
  157. package/dist/workbench/studio/loop/fsViews.js +0 -6
@@ -1,4 +1,5 @@
1
- import { PROTOTYPE_LIVENESS, PROTOTYPE_WAIT, prototypeHeartbeat, prototypeHello, prototypeNavigationId, prototypeReply, } from './prototype-bridge.js';
1
+ import { PROTOTYPE_LIVENESS, PROTOTYPE_WAIT, prototypeHeartbeat, prototypeHello, prototypeNavigationId, prototypePlayer, prototypeReply, } from './prototype-bridge.js';
2
+ import { partAsker } from './prototype-part.js';
2
3
  /** A deadline seen later than this (ms) was missed by the page, not by the app. */
3
4
  const LATE_SLACK = 1_000;
4
5
  /* Event x state -> readiness / nonce issued / controls / deadline
@@ -25,6 +26,13 @@ const LATE_SLACK = 1_000;
25
26
  * Error/refused reply or hello -> failed / revoke port+nonce / off / cancel
26
27
  * Failed/closed + hello or beat -> unchanged; restart needs a new session
27
28
  * Disposal -> closed / revoke port+nonce / off / cancel
29
+ * Player note on that port -> this document plays show messages (an older app sends none)
30
+ * Later reply on that port -> only its step caption is taken; journeys and controls unchanged
31
+ * show() on a player document -> kept as the wanted choice; sent on the current port once alive
32
+ * Hello again (the app reloaded) -> the wanted choice is sent again on the new port once alive
33
+ * show() otherwise, or failed -> false: nothing kept, the caller reloads the frame instead
34
+ * partAt() while alive -> one ask on the current port; its answer (a name, a box) or none
35
+ * partAt() otherwise; new hello -> undefined at once; a waiting ask settles undefined (stale port)
28
36
  * A nonce is not a capability: even one copied into name/storage cannot renew via window messages.
29
37
  * Only that hello's port carries replies/beats; the app closes it and clears its nonce on pagehide.
30
38
  */
@@ -37,9 +45,15 @@ export function watchPrototypeDocument(input) {
37
45
  let timedOutSilently = false;
38
46
  let phase = 'waiting';
39
47
  let published = false;
48
+ /** This document said it plays show messages; the choice it should show; what was sent to it. */
49
+ let player = false;
50
+ let wanted;
51
+ let sent;
40
52
  let deadline = 0;
41
53
  let timer;
54
+ const parts = partAsker();
42
55
  const revoke = () => {
56
+ parts.cancel();
43
57
  if (port) {
44
58
  port.onmessage = null;
45
59
  port.close();
@@ -124,6 +138,8 @@ export function watchPrototypeDocument(input) {
124
138
  forgiven = false;
125
139
  discovery = undefined;
126
140
  published = false;
141
+ player = false;
142
+ sent = undefined;
127
143
  nonce = prototypeNavigationId();
128
144
  port = hello.port;
129
145
  input.publish({});
@@ -135,7 +151,19 @@ export function watchPrototypeDocument(input) {
135
151
  return;
136
152
  // Expiry turns controls off, but a valid late proof on this document's port can revive it.
137
153
  lapsed();
138
- const reply = discovery === undefined ? prototypeReply(message.data, expected) : undefined;
154
+ if (parts.receive(message.data, expected))
155
+ return;
156
+ if (prototypePlayer(message.data, expected)) {
157
+ player = true;
158
+ return;
159
+ }
160
+ // Once the journeys are known, only a later reply is read as one; heartbeats skip that parse.
161
+ const reply = discovery === undefined ||
162
+ (typeof message.data === 'string' && message.data.includes('"ape:prototype:reply"'))
163
+ ? prototypeReply(message.data, expected)
164
+ : undefined;
165
+ if (reply && discovery !== undefined)
166
+ return caption(reply);
139
167
  if (reply && 'cause' in reply)
140
168
  return fail('reply', reply.cause);
141
169
  if (reply) {
@@ -144,6 +172,7 @@ export function watchPrototypeDocument(input) {
144
172
  if (phase === 'alive') {
145
173
  published = true;
146
174
  input.publish(discovery);
175
+ flush();
147
176
  }
148
177
  return;
149
178
  }
@@ -159,6 +188,7 @@ export function watchPrototypeDocument(input) {
159
188
  published = true;
160
189
  input.publish(discovery);
161
190
  }
191
+ flush();
162
192
  };
163
193
  current.start();
164
194
  try {
@@ -174,12 +204,70 @@ export function watchPrototypeDocument(input) {
174
204
  fail();
175
205
  }
176
206
  };
207
+ /**
208
+ * A later reply (the app re-sends one when its step changes) updates only the step caption: the
209
+ * journeys, liveness and controls stay as the first reply and the beats made them. A refused
210
+ * later reply is ignored, as before.
211
+ */
212
+ const caption = (reply) => {
213
+ if (!discovery || !('discovery' in reply))
214
+ return;
215
+ const { stepCaption: old, ...rest } = discovery;
216
+ const next = reply.discovery.stepCaption;
217
+ if (JSON.stringify(old) === JSON.stringify(next))
218
+ return;
219
+ discovery = next ? { ...rest, stepCaption: next } : rest;
220
+ if (published)
221
+ input.publish(discovery);
222
+ };
223
+ /** Sends the wanted choice once to the current document, when it is alive and plays them. */
224
+ const flush = () => {
225
+ if (!wanted || sent === wanted || !player || !port || !nonce)
226
+ return;
227
+ if (phase !== 'alive' || discovery === undefined)
228
+ return;
229
+ const choice = wanted;
230
+ try {
231
+ port.postMessage(JSON.stringify({
232
+ type: 'ape:prototype:show',
233
+ version: 2,
234
+ navigation: input.navigation,
235
+ document: nonce,
236
+ ...(choice.journey ? { journey: choice.journey, step: choice.step ?? 0 } : {}),
237
+ ...(!choice.journey && choice.data ? { data: choice.data } : {}),
238
+ }));
239
+ sent = choice;
240
+ }
241
+ catch {
242
+ // A port that cannot carry it: the next hello's port gets the wanted choice.
243
+ }
244
+ };
245
+ /**
246
+ * Tells the app which journey and step, or which data, to show, without a reload. It goes only
247
+ * on the private port of the document whose hello passed the origin check. The choice is kept:
248
+ * sent now when that document is alive, else (its port gone stale while it reloads) on the next
249
+ * hello's port. False when the session failed or closed, or the document does not play show
250
+ * messages (an older app): the caller reloads the frame at that choice instead.
251
+ */
252
+ const show = (choice) => {
253
+ if (phase === 'failed' || phase === 'closed' || !player)
254
+ return false;
255
+ wanted = choice;
256
+ flush();
257
+ return true;
258
+ };
177
259
  window.addEventListener('message', receive);
178
260
  document.addEventListener('visibilitychange', visibility);
179
261
  input.publish({});
180
262
  renew(PROTOTYPE_WAIT);
263
+ /** Asks the running app which part is at (x, y) of its page; undefined when it cannot say. */
264
+ const partAt = (x, y) => port && nonce && alive()
265
+ ? parts.ask(port, { navigation: input.navigation, document: nonce }, x, y)
266
+ : Promise.resolve(undefined);
181
267
  return {
182
268
  alive,
269
+ show,
270
+ partAt,
183
271
  fail,
184
272
  timedOutSilently: () => timedOutSilently,
185
273
  close: () => {
@@ -0,0 +1,43 @@
1
+ import { type MarkScroll } from '@buffcore/contracts/workbench';
2
+ /**
3
+ * The part at a point of the framed app: its name (when it has one) and its box, in the app's px,
4
+ * and how far the app is scrolled.
5
+ */
6
+ export type PrototypePart = {
7
+ name?: string;
8
+ box: {
9
+ x: number;
10
+ y: number;
11
+ w: number;
12
+ h: number;
13
+ };
14
+ scroll?: MarkScroll;
15
+ };
16
+ /** An answer longer than this is refused whole: a name and a box are far smaller. */
17
+ export declare const PROTOTYPE_PART = 1024;
18
+ /** How long the studio waits for the answer before it says "this spot" instead (ms). */
19
+ export declare const PART_WAIT = 1500;
20
+ type Expected = {
21
+ navigation: string;
22
+ document: string;
23
+ };
24
+ /**
25
+ * One answer read strictly. Undefined when it is not a spot answer at all; `refused` when it is
26
+ * one but too long, malformed, or for another navigation or document; else the part.
27
+ */
28
+ export declare function prototypeSpot(data: unknown, expected: Expected): {
29
+ ask: number;
30
+ part: PrototypePart;
31
+ } | 'refused' | undefined;
32
+ /**
33
+ * The studio's side of "what is at this point": one ask at a time on the current document's
34
+ * private port. A newer ask, a new hello (cancel), an answer that is refused or late all settle
35
+ * the waiting ask with undefined, so the caller says "this spot".
36
+ */
37
+ export declare function partAsker(): {
38
+ ask(port: MessagePort, expected: Expected, x: number, y: number): Promise<PrototypePart | undefined>;
39
+ /** True when the message was a spot answer (taken or refused), so nothing else reads it. */
40
+ receive(data: unknown, expected: Expected): boolean;
41
+ cancel: () => void;
42
+ };
43
+ export {};
@@ -0,0 +1,104 @@
1
+ import { markScroll } from '@buffcore/contracts/workbench';
2
+ import { z } from 'zod';
3
+ /** An answer longer than this is refused whole: a name and a box are far smaller. */
4
+ export const PROTOTYPE_PART = 1_024;
5
+ /** How long the studio waits for the answer before it says "this spot" instead (ms). */
6
+ export const PART_WAIT = 1_500;
7
+ const size = z.number().int().min(0).max(100_000);
8
+ const spot = z.strictObject({
9
+ type: z.literal('ape:prototype:spot'),
10
+ version: z.literal(2),
11
+ navigation: z.string().uuid(),
12
+ document: z.string().uuid(),
13
+ ask: z.number().int().min(1).max(1_000_000),
14
+ // One short line, never control characters: the part's label, not the app's content.
15
+ name: z
16
+ .string()
17
+ .trim()
18
+ .min(1)
19
+ .max(80)
20
+ .regex(/^[^\p{Cc}\p{Cf}]+$/u)
21
+ .optional(),
22
+ box: z.strictObject({ x: size, y: size, w: size, h: size }),
23
+ scroll: markScroll.optional(),
24
+ });
25
+ /**
26
+ * One answer read strictly. Undefined when it is not a spot answer at all; `refused` when it is
27
+ * one but too long, malformed, or for another navigation or document; else the part.
28
+ */
29
+ export function prototypeSpot(data, expected) {
30
+ if (typeof data !== 'string' || !data.includes('"ape:prototype:spot"'))
31
+ return;
32
+ if (data.length > PROTOTYPE_PART)
33
+ return 'refused';
34
+ let value;
35
+ try {
36
+ value = JSON.parse(data);
37
+ }
38
+ catch {
39
+ return 'refused';
40
+ }
41
+ const answer = spot.safeParse(value);
42
+ if (!answer.success ||
43
+ answer.data.navigation !== expected.navigation ||
44
+ answer.data.document !== expected.document)
45
+ return 'refused';
46
+ const { ask, name, box, scroll } = answer.data;
47
+ return { ask, part: { ...(name ? { name } : {}), box, ...(scroll ? { scroll } : {}) } };
48
+ }
49
+ /**
50
+ * The studio's side of "what is at this point": one ask at a time on the current document's
51
+ * private port. A newer ask, a new hello (cancel), an answer that is refused or late all settle
52
+ * the waiting ask with undefined, so the caller says "this spot".
53
+ */
54
+ export function partAsker() {
55
+ let count = 0;
56
+ let waiting;
57
+ const settle = (part) => {
58
+ const current = waiting;
59
+ waiting = undefined;
60
+ current?.done(part);
61
+ };
62
+ return {
63
+ ask(port, expected, x, y) {
64
+ settle();
65
+ count += 1;
66
+ const ask = count;
67
+ return new Promise((resolve) => {
68
+ const timer = setTimeout(() => waiting?.ask === ask && settle(), PART_WAIT);
69
+ waiting = {
70
+ ask,
71
+ done: (part) => {
72
+ clearTimeout(timer);
73
+ resolve(part);
74
+ },
75
+ };
76
+ try {
77
+ port.postMessage(JSON.stringify({
78
+ type: 'ape:prototype:part',
79
+ version: 2,
80
+ ...expected,
81
+ ask,
82
+ x: Math.max(0, Math.round(x)),
83
+ y: Math.max(0, Math.round(y)),
84
+ }));
85
+ }
86
+ catch {
87
+ settle();
88
+ }
89
+ });
90
+ },
91
+ /** True when the message was a spot answer (taken or refused), so nothing else reads it. */
92
+ receive(data, expected) {
93
+ const answer = prototypeSpot(data, expected);
94
+ if (answer === undefined)
95
+ return false;
96
+ if (answer === 'refused')
97
+ settle();
98
+ else if (answer.ask === waiting?.ask)
99
+ settle(answer.part);
100
+ return true;
101
+ },
102
+ cancel: () => settle(),
103
+ };
104
+ }
@@ -1,7 +1,7 @@
1
1
  import type { FoundAgent } from '@buffcore/contracts/workbench';
2
2
  import type { AgentMessage, PlanExtension, PlanMilestone, StudioProduct } from '../types.ts';
3
3
  /** The moments the studio's states panel lists for the loop, in order. */
4
- export declare const LOOP_MOMENTS: readonly ['fresh', 'agents', 'brief', 'autopilot', 'plan', 'brand', 'brand-picked', 'journeys', 'proto-v1', 'proto-comment', 'proto-v2', 'approved', 'proto-states', 'proto-lanes', 'proto-drift', 'fs-tablet', 'fs-overview', 'fs-change'];
4
+ export declare const LOOP_MOMENTS: readonly ['fresh', 'agents', 'brief', 'autopilot', 'plan', 'brand', 'brand-picked', 'journeys', 'proto-v1', 'proto-comment', 'proto-v2', 'approved', 'proto-states', 'proto-lanes', 'proto-drift'];
5
5
  export type LoopMoment = (typeof LOOP_MOMENTS)[number];
6
6
  /** An agent found on this computer. */
7
7
  export interface AgentRow {
@@ -29,6 +29,17 @@ export interface BriefQuestion {
29
29
  /** The choice that answers it, when it is one of the loop's. */
30
30
  choice?: ChoiceKey;
31
31
  }
32
+ /** A section of plan/brief.md: its heading there, and its whole Markdown, to read. */
33
+ export interface BriefPart {
34
+ heading: string;
35
+ text: string;
36
+ }
37
+ /** The sections the Brief shows short, each with its Read more. */
38
+ export type BriefShort = 'what' | 'who' | 'kind' | 'earns' | 'must' | 'later';
39
+ /**
40
+ * The brief, short first: each section's one-line summary (or its first sentence), Must have and
41
+ * Not now as items. An empty field is a section the brief does not have: it is not shown.
42
+ */
32
43
  export interface BriefDoc {
33
44
  what: string;
34
45
  who: readonly {
@@ -37,10 +48,19 @@ export interface BriefDoc {
37
48
  note?: string;
38
49
  }[];
39
50
  kind?: 'B2C' | 'B2B';
51
+ /** The kind section's own line; without it the page says what the kind means. */
52
+ kindLine?: string;
40
53
  earns?: string;
41
54
  must?: readonly string[];
55
+ /** How many items the section holds in all, when more than `must` (its summaries). */
56
+ mustCount?: number;
42
57
  later?: readonly string[];
58
+ laterCount?: number;
43
59
  questions: readonly BriefQuestion[];
60
+ /** Each short section's whole text, for its Read more; none, no Read more. */
61
+ read?: Partial<Record<BriefShort, BriefPart>>;
62
+ /** Every section of plan/brief.md in order, for Read the whole brief. */
63
+ whole?: readonly BriefPart[];
44
64
  }
45
65
  export type ChoiceKey = 'length' | 'm1' | 'first' | 'list';
46
66
  /** A choice in the loop: its options, what the agent picks, and why. */
@@ -136,6 +156,11 @@ export interface ProtoSample {
136
156
  scene: string;
137
157
  label: string;
138
158
  }[];
159
+ /** The console's own scenes, for the workspace's Screens. */
160
+ consoleOthers?: readonly {
161
+ scene: string;
162
+ label: string;
163
+ }[];
139
164
  versions: readonly {
140
165
  v: string;
141
166
  commit: string;
@@ -179,30 +204,6 @@ export interface ProtoSample {
179
204
  added?: string;
180
205
  }[];
181
206
  }
182
- export interface FsMark {
183
- n: number;
184
- kind: 'area' | 'select' | 'draw';
185
- where: string;
186
- device: 'phone' | 'tablet' | 'desktop';
187
- note: string;
188
- /** Where it sits on the screen, as percentages of its width and height; an area has a size. */
189
- at: {
190
- x: number;
191
- y: number;
192
- w?: number;
193
- h?: number;
194
- };
195
- }
196
- export interface FsSample {
197
- marks: readonly FsMark[];
198
- text: string;
199
- plan: {
200
- id: string;
201
- title: string;
202
- steps: readonly string[];
203
- touches: readonly string[];
204
- };
205
- }
206
207
  /** Everything a loop page draws, for one sample product. */
207
208
  export interface LoopSample {
208
209
  contained?: boolean;
@@ -222,7 +223,6 @@ export interface LoopSample {
222
223
  };
223
224
  journeys: readonly JourneyRole[];
224
225
  proto: ProtoSample;
225
- fs: FsSample;
226
226
  /** The agent's panel for each moment. */
227
227
  talk: Record<LoopMoment, readonly AgentMessage[]>;
228
228
  }
@@ -15,7 +15,4 @@ export const LOOP_MOMENTS = [
15
15
  'proto-states',
16
16
  'proto-lanes',
17
17
  'proto-drift',
18
- 'fs-tablet',
19
- 'fs-overview',
20
- 'fs-change',
21
18
  ];
@@ -1,4 +1,5 @@
1
- import { type FrameFailure } from './prototype-document.ts';
1
+ import { type FrameFailure, type PrototypeShow } from './prototype-document.ts';
2
+ import type { PrototypePart } from './prototype-part.ts';
2
3
  /** The session owns document changes; React only publishes its current navigation's answer. */
3
4
  export declare function usePrototypeFrame(origin: string, navigation: string,
4
5
  /** Remember when the switched address stayed silent so the next navigation uses the given one. */
@@ -22,5 +23,9 @@ onSwitch?: () => void, running?: boolean): {
22
23
  cause: import("./prototype-bridge.ts").FrameCause | undefined;
23
24
  recoverable: true | undefined;
24
25
  alive: () => boolean;
26
+ /** Sends the choice to the running app; false when it could not, and the frame must reload. */
27
+ show: (choice: PrototypeShow) => boolean;
25
28
  fail: (status?: FrameFailure) => void | undefined;
29
+ /** The part of the running app at (x, y) of its page: a name and a box, or undefined. */
30
+ partAt: (x: number, y: number) => Promise<PrototypePart | undefined>;
26
31
  };
@@ -54,6 +54,10 @@ onSwitch, running) {
54
54
  cause: current?.value.cause,
55
55
  recoverable: current?.value.recoverable,
56
56
  alive: () => session.current?.alive() ?? false,
57
+ /** Sends the choice to the running app; false when it could not, and the frame must reload. */
58
+ show: (choice) => session.current?.show(choice) ?? false,
57
59
  fail: (status) => session.current?.fail(status),
60
+ /** The part of the running app at (x, y) of its page: a name and a box, or undefined. */
61
+ partAt: (x, y) => session.current?.partAt(x, y) ?? Promise.resolve(undefined),
58
62
  };
59
63
  }
@@ -0,0 +1,22 @@
1
+ import type { PlayableJourney } from './prototype-bridge.ts';
2
+ import type { JourneyRole } from './types.ts';
3
+ import type { WorkspaceApp } from './workspace-state.tsx';
4
+ export interface WorkspaceJourney {
5
+ /** The plan's id, or the app's key for a journey only the app lists. */
6
+ id: string;
7
+ name: string;
8
+ where: WorkspaceApp;
9
+ /** Each step's name from the plan; '' where the plan names none (the app's count is longer). */
10
+ steps: readonly string[];
11
+ /** The running app's key, when it plays this journey. */
12
+ key?: string;
13
+ }
14
+ export interface WorkspaceGroup {
15
+ /** None for the app's journeys that give no role. */
16
+ role?: string;
17
+ where: WorkspaceApp;
18
+ journeys: readonly WorkspaceJourney[];
19
+ }
20
+ export declare function workspaceGroups(roles: readonly JourneyRole[], live: readonly PlayableJourney[]): WorkspaceGroup[];
21
+ /** The journey the shown app has open: the app's playing one or one looked at, or the console's. */
22
+ export declare function openJourney(groups: readonly WorkspaceGroup[], where: WorkspaceApp, id: string | undefined, key?: string): WorkspaceJourney | undefined;
@@ -0,0 +1,63 @@
1
+ const named = (planned, count) => Array.from({ length: count }, (_, i) => planned[i] ?? '');
2
+ /**
3
+ * Each planned app journey's match among the app's: by key first, across every plan row, then by
4
+ * title among the app's journeys no row took. One app journey is never two rows.
5
+ */
6
+ function matches(roles, live) {
7
+ const rows = roles.flatMap((role) => (role.where === 'app' ? role.journeys : []));
8
+ const found = new Map();
9
+ const used = new Set();
10
+ const take = (row, by) => {
11
+ const entry = found.has(row) ? undefined : live.find((e) => !used.has(e.key) && by(e));
12
+ if (!entry)
13
+ return;
14
+ found.set(row, entry);
15
+ used.add(entry.key);
16
+ };
17
+ for (const row of rows)
18
+ take(row, (entry) => entry.key === row.id);
19
+ for (const row of rows)
20
+ take(row, (entry) => entry.title === row.name);
21
+ return { found, used };
22
+ }
23
+ export function workspaceGroups(roles, live) {
24
+ const { found, used } = matches(roles, live);
25
+ const planned = roles.map((role) => ({
26
+ role: role.role,
27
+ where: role.where,
28
+ journeys: role.journeys.map((journey) => {
29
+ const match = found.get(journey);
30
+ return {
31
+ id: journey.id,
32
+ name: journey.name,
33
+ where: role.where,
34
+ steps: named(journey.steps, match?.steps ?? journey.steps.length),
35
+ ...(match ? { key: match.key } : {}),
36
+ };
37
+ }),
38
+ }));
39
+ const unplanned = new Map();
40
+ for (const entry of live) {
41
+ if (used.has(entry.key))
42
+ continue;
43
+ const list = unplanned.get(entry.role || undefined) ?? [];
44
+ list.push({
45
+ id: entry.key,
46
+ name: entry.title,
47
+ where: 'app',
48
+ steps: named([], entry.steps),
49
+ key: entry.key,
50
+ });
51
+ unplanned.set(entry.role || undefined, list);
52
+ }
53
+ const rest = Array.from(unplanned, ([role, journeys]) => ({ ...(role ? { role } : {}), where: 'app', journeys }));
54
+ // The customer app's groups first, then the console's, each in the plan's order.
55
+ return [...planned, ...rest]
56
+ .filter((group) => group.journeys.length > 0)
57
+ .sort((a, b) => Number(a.where === 'console') - Number(b.where === 'console'));
58
+ }
59
+ /** The journey the shown app has open: the app's playing one or one looked at, or the console's. */
60
+ export function openJourney(groups, where, id, key) {
61
+ const all = groups.flatMap((group) => group.journeys).filter((j) => j.where === where);
62
+ return (key ? all.find((j) => j.key === key) : undefined) ?? all.find((j) => j.id === id);
63
+ }
@@ -0,0 +1,94 @@
1
+ import { type ReactNode } from 'react';
2
+ import type { PrototypePart } from './prototype-part.ts';
3
+ import type { ProtoView } from './protoView.ts';
4
+ export type WorkspaceTool = 'select' | 'comment' | 'draw' | 'area';
5
+ export type WorkspaceApp = 'app' | 'console';
6
+ export declare const WORKSPACE_TOOLS: readonly WorkspaceTool[];
7
+ export type WorkspaceScreen = {
8
+ scene: string;
9
+ label: string;
10
+ };
11
+ /** What the page gives the workspace: where the console runs, the listed screens, the overlay. */
12
+ export interface WorkspaceSetup {
13
+ /** The console's own address (the stack's admin); none when it is not known. */
14
+ consoleUrl?: string;
15
+ /** The customer app's address, for its screens' links. */
16
+ appUrl?: string;
17
+ screens?: {
18
+ app: readonly WorkspaceScreen[];
19
+ console: readonly WorkspaceScreen[];
20
+ };
21
+ /** Drawn over the device's screen, in screen pixels (see `WorkspaceStage`). */
22
+ overlay?: ReactNode;
23
+ /** How many marks wait to be sent; the phone-wide foot bar's Changes shows it. */
24
+ changes?: number;
25
+ /** The tool, when the page holds it; otherwise the workspace keeps its own (Select first). */
26
+ tool?: WorkspaceTool;
27
+ onTool?: (tool: WorkspaceTool) => void;
28
+ /** What stands in for the live console (a drawn scene); none frames the console at its address. */
29
+ console?: ReactNode;
30
+ }
31
+ /** Where a workspace starts (a drawn scene's moment); a person starts on the customer app. */
32
+ export type WorkspaceStart = Partial<Pick<WorkspaceState, 'app' | 'tool' | 'console'>>;
33
+ export interface WorkspaceState {
34
+ app: WorkspaceApp;
35
+ tool: WorkspaceTool;
36
+ /** The console's open journey (a plan id) and its step from 0; the person follows it by hand. */
37
+ console: {
38
+ journey?: string;
39
+ step: number;
40
+ };
41
+ /** The console has been shown once, so its frame stays loaded from then on. */
42
+ consoleShown: boolean;
43
+ setup: WorkspaceSetup;
44
+ setApp: (app: WorkspaceApp) => void;
45
+ setTool: (tool: WorkspaceTool) => void;
46
+ setConsole: (console: {
47
+ journey?: string;
48
+ step: number;
49
+ }) => void;
50
+ }
51
+ /** Holds the workspace's choices for everything inside it (the page's preview). */
52
+ export declare function PrototypeWorkspace({ setup, start, children, }: {
53
+ setup: WorkspaceSetup;
54
+ start?: WorkspaceStart;
55
+ children: ReactNode;
56
+ }): import("react").JSX.Element;
57
+ /** The workspace's choices: the page's, or (a preview drawn on its own) a set of its own. */
58
+ export declare function useWorkspace(): WorkspaceState;
59
+ /**
60
+ * The device stage, for what draws over it (marking). `screen` is the element the shown app fills,
61
+ * at the device's own size in CSS pixels and drawn at `zoom` (1 on a phone-wide studio's bare
62
+ * screen); the overlay sits over it in screen pixels, so an app point is a screen point / zoom.
63
+ * The framed app is the `iframe` inside `screen`. `where` says what the shown app is showing.
64
+ */
65
+ export interface WorkspaceStage {
66
+ tool: WorkspaceTool;
67
+ app: WorkspaceApp;
68
+ device: NonNullable<ProtoView['device']>;
69
+ orientation: NonNullable<ProtoView['orientation']>;
70
+ screen: HTMLElement | null;
71
+ zoom: number;
72
+ /** `data`: the sample data shown, when no journey plays on the customer app. */
73
+ where: {
74
+ journey?: string;
75
+ step?: number;
76
+ screen: string;
77
+ data?: string;
78
+ };
79
+ /** The running customer app's part at a point of its page (a name, a box, its scroll). */
80
+ partAt?: (x: number, y: number) => Promise<PrototypePart | undefined>;
81
+ /** Shows the customer app at this device, journey step or sample data again. */
82
+ show?: (place: StageShow) => void;
83
+ }
84
+ /** What `WorkspaceStage.show` takes: a marked place of the customer app. */
85
+ export interface StageShow {
86
+ device: NonNullable<ProtoView['device']>;
87
+ orientation?: 'landscape';
88
+ journey?: string;
89
+ step?: number;
90
+ data?: string;
91
+ }
92
+ export declare const WorkspaceStageContext: import("react").Context<WorkspaceStage | undefined>;
93
+ /** The stage while it is drawn; undefined outside it. */
94
+ export declare const useWorkspaceStage: () => WorkspaceStage | undefined;
@@ -0,0 +1,50 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ // The prototype workspace's own choices: which app is shown, which tool a click uses, and where the
3
+ // console's journey is. They live above the framed app, so the app coming up or a step changing
4
+ // never resets them, and switching apps keeps each app's step.
5
+ //
6
+ // For marking (built on top of this): `useWorkspaceStage()` gives the chosen tool and the device's
7
+ // screen while the stage is drawn, and `WorkspaceSetup.overlay` is drawn over that screen.
8
+ import { createContext, useContext, useMemo, useState } from 'react';
9
+ export const WORKSPACE_TOOLS = ['select', 'comment', 'draw', 'area'];
10
+ const StateContext = createContext(undefined);
11
+ function useWorkspaceValue(setup, start = {}) {
12
+ const [app, setShown] = useState(start.app ?? 'app');
13
+ const [consoleShown, setConsoleShown] = useState(false);
14
+ const [ownTool, setOwnTool] = useState(start.tool ?? 'select');
15
+ const [console, setConsole] = useState(start.console ?? { step: 0 });
16
+ // Marking is on the customer app: the console is not pictured yet, so a click there selects.
17
+ const tool = app === 'console' ? 'select' : (setup.tool ?? ownTool);
18
+ const { onTool } = setup;
19
+ return useMemo(() => ({
20
+ app,
21
+ tool,
22
+ console,
23
+ consoleShown: consoleShown || app === 'console',
24
+ setup,
25
+ setApp: (next) => {
26
+ if (next === 'console')
27
+ setConsoleShown(true);
28
+ setShown(next);
29
+ },
30
+ setTool: (next) => {
31
+ setOwnTool(next);
32
+ onTool?.(next);
33
+ },
34
+ setConsole,
35
+ }), [app, tool, console, consoleShown, setup, onTool]);
36
+ }
37
+ /** Holds the workspace's choices for everything inside it (the page's preview). */
38
+ export function PrototypeWorkspace({ setup, start, children, }) {
39
+ const value = useWorkspaceValue(setup, start);
40
+ return _jsx(StateContext.Provider, { value: value, children: children });
41
+ }
42
+ const NO_SETUP = {};
43
+ /** The workspace's choices: the page's, or (a preview drawn on its own) a set of its own. */
44
+ export function useWorkspace() {
45
+ const own = useWorkspaceValue(NO_SETUP);
46
+ return useContext(StateContext) ?? own;
47
+ }
48
+ export const WorkspaceStageContext = createContext(undefined);
49
+ /** The stage while it is drawn; undefined outside it. */
50
+ export const useWorkspaceStage = () => useContext(WorkspaceStageContext);
@@ -0,0 +1,7 @@
1
+ import type { ControlledAgent } from '../frame/panelControls.ts';
2
+ import { type MarkSheet, type MarksPage } from './marks.ts';
3
+ export declare function ChangeList({ agent, page, sheet, }: {
4
+ agent: ControlledAgent;
5
+ page: MarksPage;
6
+ sheet: MarkSheet;
7
+ }): import("react").JSX.Element;