@startsimpli/integrations 0.2.200 → 0.2.202

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 (147) hide show
  1. package/package.json +7 -7
  2. package/src/__tests__/briefing-actions.test.ts +11 -0
  3. package/src/__tests__/briefing-edits.test.ts +98 -0
  4. package/src/__tests__/briefing-markdown.test.ts +64 -0
  5. package/src/__tests__/converse-brain.test.ts +64 -1
  6. package/src/__tests__/converse-cards.test.ts +53 -0
  7. package/src/__tests__/converse-handoff.test.ts +8 -0
  8. package/src/__tests__/converse-meeting-brief.test.ts +72 -8
  9. package/src/__tests__/converse-meeting-duplex.test.ts +132 -0
  10. package/src/__tests__/converse-meeting-keep-speech.test.ts +87 -0
  11. package/src/__tests__/converse-meeting-vad.test.ts +1 -1
  12. package/src/__tests__/converse-page.test.tsx +148 -37
  13. package/src/__tests__/converse-roci.test.ts +22 -0
  14. package/src/__tests__/converse-spoken-form.test.ts +10 -0
  15. package/src/__tests__/converse-spoken-summary.test.ts +27 -6
  16. package/src/__tests__/converse-structure.test.ts +27 -0
  17. package/src/__tests__/converse-view.test.ts +46 -0
  18. package/src/__tests__/converse.test.ts +29 -2
  19. package/src/__tests__/corpus-ask.test.ts +22 -0
  20. package/src/__tests__/corpus-tracker.test.tsx +42 -174
  21. package/src/__tests__/data-table-logic.test.ts +75 -0
  22. package/src/__tests__/data-table.test.tsx +133 -0
  23. package/src/__tests__/extract-classify.test.ts +17 -0
  24. package/src/__tests__/fleet-page.test.tsx +57 -0
  25. package/src/__tests__/fleet-view.test.ts +149 -0
  26. package/src/__tests__/home-brief.test.tsx +25 -40
  27. package/src/__tests__/library-call-shape.test.tsx +164 -0
  28. package/src/__tests__/load-error.test.tsx +1 -1
  29. package/src/__tests__/mini-markdown.test.tsx +24 -0
  30. package/src/__tests__/overview-page.test.tsx +36 -6
  31. package/src/__tests__/plan-shell.test.tsx +6 -4
  32. package/src/__tests__/project-basis-entity.test.ts +19 -0
  33. package/src/__tests__/project-basis.test.ts +21 -0
  34. package/src/__tests__/relay-cli.test.ts +10 -1
  35. package/src/__tests__/task-detail-project-guess.test.tsx +46 -0
  36. package/src/__tests__/timeline-events.test.ts +65 -0
  37. package/src/__tests__/timeline-table.test.tsx +66 -0
  38. package/src/__tests__/todo-table-model.test.ts +75 -0
  39. package/src/__tests__/todo-table.test.tsx +202 -0
  40. package/src/__tests__/tracker-timeline-component.test.tsx +4 -4
  41. package/src/__tests__/tracker-timeline-reader.test.ts +1 -1
  42. package/src/comms/__tests__/app-sends-page.test.tsx +69 -0
  43. package/src/comms/api/comms.ts +23 -0
  44. package/src/comms/components/ResultsPanel.tsx +2 -2
  45. package/src/comms/components/SendLog.tsx +20 -8
  46. package/src/comms/components/index.ts +1 -0
  47. package/src/comms/components/pages/AppSendsPage.tsx +58 -0
  48. package/src/comms/hooks/index.ts +8 -3
  49. package/src/components/FolderTree.tsx +12 -3
  50. package/src/components/index.ts +4 -1
  51. package/src/components/pages/ConversePage.tsx +114 -105
  52. package/src/components/pages/FleetPage.tsx +115 -0
  53. package/src/components/pages/LibraryPage.tsx +63 -24
  54. package/src/components/pages/TaskDetailPage.tsx +27 -1
  55. package/src/components/pages/TrackerPage.tsx +170 -474
  56. package/src/components/pages/converse/CardView.tsx +72 -0
  57. package/src/components/pages/converse/SettingsMenu.tsx +37 -0
  58. package/src/components/pages/converse/Thread.tsx +48 -33
  59. package/src/components/pages/converse/useNeedsYou.ts +60 -0
  60. package/src/components/pages/home/BriefCard.tsx +16 -7
  61. package/src/components/pages/home/HomeBriefPage.tsx +6 -91
  62. package/src/components/pages/home/MiniMarkdown.tsx +51 -0
  63. package/src/components/pages/home/{DueSoonLine.tsx → dueSoonText.ts} +2 -11
  64. package/src/components/pages/home/index.ts +1 -1
  65. package/src/components/pages/overview/OverviewPage.tsx +46 -83
  66. package/src/components/pages/plan/TalkPage.tsx +5 -14
  67. package/src/components/pages/plan/TimelinePage.tsx +4 -2
  68. package/src/components/pages/task-tracker/ProjectGuess.tsx +42 -0
  69. package/src/components/pages/tracker/SweepPanel.tsx +108 -0
  70. package/src/components/pages/tracker/TimelineTable.tsx +70 -0
  71. package/src/components/pages/tracker/TrackerTimeline.tsx +32 -15
  72. package/src/components/table/DataTable.tsx +92 -0
  73. package/src/components/table/RowMenu.tsx +35 -0
  74. package/src/components/table/TablePagination.tsx +63 -0
  75. package/src/components/table/TableToolbar.tsx +56 -0
  76. package/src/components/table/TodoTable.tsx +142 -0
  77. package/src/components/table/index.ts +10 -0
  78. package/src/components/table/table-logic.ts +60 -0
  79. package/src/components/table/todo-model.ts +93 -0
  80. package/src/corpus/ask-items.ts +7 -4
  81. package/src/corpus/ask.ts +1 -1
  82. package/src/corpus/briefing/actions/confirm.ts +9 -1
  83. package/src/corpus/briefing/actions/execute.ts +71 -11
  84. package/src/corpus/briefing/actions/log.ts +1 -1
  85. package/src/corpus/briefing/actions/seam.ts +18 -2
  86. package/src/corpus/briefing/actions/types.ts +14 -0
  87. package/src/corpus/briefing/generate-weekly.ts +4 -0
  88. package/src/corpus/briefing/generate.ts +4 -0
  89. package/src/corpus/briefing/index.ts +1 -0
  90. package/src/corpus/briefing/intent/describe.ts +5 -1
  91. package/src/corpus/briefing/intent/edits.ts +92 -0
  92. package/src/corpus/briefing/intent/grammar.ts +3 -0
  93. package/src/corpus/briefing/intent/ground.ts +5 -1
  94. package/src/corpus/briefing/intent/match.ts +3 -1
  95. package/src/corpus/briefing/intent/model.ts +36 -3
  96. package/src/corpus/briefing/intent/resolve.ts +12 -1
  97. package/src/corpus/briefing/intent/types.ts +8 -0
  98. package/src/corpus/briefing/markdown.ts +71 -0
  99. package/src/corpus/briefing/speak.ts +13 -0
  100. package/src/corpus/client.ts +40 -146
  101. package/src/corpus/converse/brain.ts +41 -13
  102. package/src/corpus/converse/briefing-queue.ts +105 -27
  103. package/src/corpus/converse/cards.ts +69 -0
  104. package/src/corpus/converse/client.ts +6 -0
  105. package/src/corpus/converse/fleet-view.ts +126 -0
  106. package/src/corpus/converse/fleet.ts +18 -5
  107. package/src/corpus/converse/followups.ts +12 -2
  108. package/src/corpus/converse/handle.ts +21 -12
  109. package/src/corpus/converse/handoff.ts +7 -2
  110. package/src/corpus/converse/index.ts +11 -3
  111. package/src/corpus/converse/meeting-config.ts +8 -4
  112. package/src/corpus/converse/meeting.ts +66 -11
  113. package/src/corpus/converse/respond.ts +14 -2
  114. package/src/corpus/converse/roci.ts +13 -0
  115. package/src/corpus/converse/spoken-form.ts +9 -2
  116. package/src/corpus/converse/spoken-summary.ts +30 -8
  117. package/src/corpus/converse/store.ts +2 -0
  118. package/src/corpus/converse/structure.ts +39 -0
  119. package/src/corpus/converse/types.ts +14 -1
  120. package/src/corpus/converse/view.ts +34 -0
  121. package/src/corpus/entities.ts +2 -0
  122. package/src/corpus/extract.ts +9 -4
  123. package/src/corpus/index.ts +2 -0
  124. package/src/corpus/participants.ts +220 -0
  125. package/src/corpus/project-basis.ts +23 -0
  126. package/src/corpus/timeline-events.ts +83 -0
  127. package/src/corpus/tracker-sort.ts +9 -3
  128. package/src/corpus/tracker-timeline-client.ts +2 -0
  129. package/src/corpus/tracker-timeline.ts +4 -0
  130. package/src/corpus/types.ts +38 -5
  131. package/src/native/app/__tests__/plan-talk-registry.test.tsx +2 -1
  132. package/src/native/app/converseServices.ts +5 -3
  133. package/src/native/app/device.ts +2 -0
  134. package/src/native/converse/ConverseScreen.tsx +30 -4
  135. package/src/native/converse/__tests__/liveScreen.test.tsx +35 -2
  136. package/src/native/converse/__tests__/meetingIO.test.ts +55 -1
  137. package/src/native/converse/format.ts +2 -2
  138. package/src/native/converse/io.ts +15 -5
  139. package/src/native/home/HomeScreen.tsx +1 -1
  140. package/src/native/home/tab.tsx +1 -2
  141. package/src/native/plan/PlanTab.tsx +1 -2
  142. package/src/native/plan/__tests__/plan-tab.test.tsx +5 -5
  143. package/src/native/talk/TalkTab.tsx +1 -1
  144. package/src/native/talk/__tests__/talk-tab.test.tsx +1 -1
  145. package/src/__tests__/home-needs-your-call.test.tsx +0 -65
  146. package/src/components/pages/tracker/TrackerBoard.tsx +0 -45
  147. package/src/components/pages/tracker/TrackerToolbar.tsx +0 -44
@@ -15,13 +15,15 @@ import {
15
15
  TableRow,
16
16
  } from '@startsimpli/ui';
17
17
 
18
- import type { CommsApi } from '../api/comms';
18
+ import type { SendReportApi } from '../api/comms';
19
19
  import { useSends } from '../hooks/index';
20
20
  import { COMEBACK_PROGRAM_KEY, PRODUCT_UPDATE_PROGRAM_KEY } from '../types/index';
21
21
  import { ErrorNotice, NativeSelect, formatDate, formatDateTime, formatLocalTime, useFieldId } from './_shared';
22
22
 
23
23
  export interface SendLogProps {
24
- api: CommsApi;
24
+ api: SendReportApi;
25
+ /** Program filter choices. 'text' = free-text key (apps whose programs are not a fixed list). */
26
+ programs?: { value: string; label: string }[] | 'text';
25
27
  /** Rows per server page. Default 25; the server caps at 100. */
26
28
  pageSize?: number;
27
29
  }
@@ -36,7 +38,7 @@ const STATUSES = ['', 'pending', 'sent', 'delivered', 'opened', 'clicked', 'boun
36
38
 
37
39
  const programLabel = (key: string) => PROGRAMS.find((p) => p.value === key)?.label ?? key;
38
40
 
39
- export function SendLog({ api, pageSize = 25 }: SendLogProps): ReactElement {
41
+ export function SendLog({ api, programs = PROGRAMS, pageSize = 25 }: SendLogProps): ReactElement {
40
42
  const [page, setPage] = useState(1);
41
43
  const [program, setProgram] = useState('');
42
44
  const [status, setStatus] = useState('');
@@ -54,11 +56,21 @@ export function SendLog({ api, pageSize = 25 }: SendLogProps): ReactElement {
54
56
  <div className="space-y-1">
55
57
  <Label htmlFor={programId}>Program</Label>
56
58
  <div>
57
- <NativeSelect id={programId} value={program} onChange={(e) => { setProgram(e.target.value); setPage(1); }}>
58
- {PROGRAMS.map((p) => (
59
- <option key={p.value} value={p.value}>{p.label}</option>
60
- ))}
61
- </NativeSelect>
59
+ {programs === 'text' ? (
60
+ <input
61
+ id={programId}
62
+ className="h-9 rounded-md border bg-background px-2 text-sm"
63
+ placeholder="All"
64
+ value={program}
65
+ onChange={(e) => { setProgram(e.target.value.trim()); setPage(1); }}
66
+ />
67
+ ) : (
68
+ <NativeSelect id={programId} value={program} onChange={(e) => { setProgram(e.target.value); setPage(1); }}>
69
+ {programs.map((p) => (
70
+ <option key={p.value} value={p.value}>{p.label}</option>
71
+ ))}
72
+ </NativeSelect>
73
+ )}
62
74
  </div>
63
75
  </div>
64
76
  <div className="space-y-1">
@@ -14,3 +14,4 @@ export * from './ScheduledSends';
14
14
  export * from './ResultsPanel';
15
15
  export * from './SendLog';
16
16
  export * from './AudiencePanel';
17
+ export * from './pages/AppSendsPage';
@@ -0,0 +1,58 @@
1
+ /**
2
+ * APP SENDS: the Platform-scope log of every email a first-party app (crochet,
3
+ * raise...) sends through Foundry comms (bd startsim-u5iwb.9). Superuser only;
4
+ * the routes answer 403 otherwise and this renders that as a plain notice.
5
+ *
6
+ * `<AppSendsPage />` is the whole integration; the mounting app wires the
7
+ * bearer with setAuthTokenProvider first. One title, an app switch, the
8
+ * results, then the paged send log.
9
+ */
10
+ import { useMemo, useState, type ReactElement } from 'react';
11
+
12
+ import { createAppCommsApi } from '../../api/comms';
13
+ import { useCommsApps } from '../../hooks/index';
14
+ import { CommsApiError } from '../../types/index';
15
+ import { ResultsPanel } from '../ResultsPanel';
16
+ import { SendLog } from '../SendLog';
17
+ import { ErrorNotice, NativeSelect, useFieldId } from '../_shared';
18
+
19
+ export function AppSendsPage(): ReactElement {
20
+ const apps = useCommsApps();
21
+ const [picked, setPicked] = useState<string | null>(null);
22
+ const appId = useFieldId('comms-app-sends-app');
23
+ const list = apps.data ?? [];
24
+ const app = picked ?? list.find((a) => a.sent > 0)?.app ?? list[0]?.app ?? null;
25
+ const api = useMemo(() => (app ? createAppCommsApi(app) : null), [app]);
26
+
27
+ const forbidden = apps.error instanceof CommsApiError && apps.error.status === 403;
28
+
29
+ return (
30
+ <div className="space-y-4">
31
+ <h1 className="text-xl font-semibold">App emails</h1>
32
+ {forbidden ? (
33
+ <p className="text-sm text-muted-foreground">Only Platform admins can see every app's email.</p>
34
+ ) : (
35
+ <ErrorNotice error={apps.error} />
36
+ )}
37
+ {apps.data && list.length === 0 ? (
38
+ <p className="text-sm text-muted-foreground">No apps have sent email yet.</p>
39
+ ) : null}
40
+ {list.length > 0 && app && api ? (
41
+ <>
42
+ <div className="space-y-1">
43
+ <label htmlFor={appId} className="text-sm font-medium">App</label>
44
+ <div>
45
+ <NativeSelect id={appId} value={app} onChange={(e) => setPicked(e.target.value)}>
46
+ {list.map((a) => (
47
+ <option key={a.app} value={a.app}>{`${a.app} (${a.sent} sent, 30 days)`}</option>
48
+ ))}
49
+ </NativeSelect>
50
+ </div>
51
+ </div>
52
+ <ResultsPanel key={`m-${app}`} api={api} />
53
+ <SendLog key={`l-${app}`} api={api} programs="text" />
54
+ </>
55
+ ) : null}
56
+ </div>
57
+ );
58
+ }
@@ -17,7 +17,7 @@ import {
17
17
  type UseQueryResult,
18
18
  } from '@tanstack/react-query';
19
19
 
20
- import type { CommsApi } from '../api/comms';
20
+ import { listCommsApps, type AppActivity, type CommsApi, type SendReportApi } from '../api/comms';
21
21
  import type {
22
22
  AssetsQuery,
23
23
  AudienceSegments,
@@ -371,7 +371,7 @@ export function useDeleteAsset(api: CommsApi): UseMutationResult<void, Error, st
371
371
  // results ------------------------------------------------------------------
372
372
 
373
373
  /** Server-side pagination: page/page_size go to the server, never sliced here. */
374
- export function useSends(api: CommsApi, q: SendsQuery): UseQueryResult<SendsPage> {
374
+ export function useSends(api: SendReportApi, q: SendsQuery): UseQueryResult<SendsPage> {
375
375
  return useQuery({
376
376
  queryKey: commsKeys.sends(api.slug, q),
377
377
  queryFn: () => api.listSends(q),
@@ -379,6 +379,11 @@ export function useSends(api: CommsApi, q: SendsQuery): UseQueryResult<SendsPage
379
379
  });
380
380
  }
381
381
 
382
- export function useCommsMetrics(api: CommsApi, q: MetricsQuery): UseQueryResult<CommsMetrics> {
382
+ export function useCommsMetrics(api: SendReportApi, q: MetricsQuery): UseQueryResult<CommsMetrics> {
383
383
  return useQuery({ queryKey: commsKeys.metrics(api.slug, q), queryFn: () => api.getMetrics(q) });
384
384
  }
385
+
386
+ /** First-party apps with their send counts (Platform-scope send log). */
387
+ export function useCommsApps(days = 30): UseQueryResult<AppActivity[]> {
388
+ return useQuery({ queryKey: ['startsimpli', 'comms', 'apps', days] as const, queryFn: () => listCommsApps(days) });
389
+ }
@@ -95,6 +95,14 @@ export interface FolderTreeProps {
95
95
  * flat list it rendered before. Never a half-drawn tree.
96
96
  */
97
97
  onUnavailable?: () => void;
98
+ /**
99
+ * Do not read the first level yet. The Library holds it until its own rows
100
+ * are on screen: the facet read is the slowest one on a cold tenant and a
101
+ * server that answers one request at a time would otherwise answer it BEFORE
102
+ * the records the reader came for. The tree still shows "Loading folders…"
103
+ * while it waits; nothing about what it draws changes.
104
+ */
105
+ hold?: boolean;
98
106
  classNames?: Partial<Record<FolderTreeSlot, string>>;
99
107
  }
100
108
 
@@ -139,6 +147,7 @@ export function FolderTree({
139
147
  rootLabel = 'All documents',
140
148
  pageSize = 100,
141
149
  onUnavailable,
150
+ hold = false,
142
151
  classNames = {},
143
152
  }: FolderTreeProps) {
144
153
  const cn = { ...DEFAULTS, ...classNames };
@@ -219,8 +228,8 @@ export function FolderTree({
219
228
  }, [load]);
220
229
 
221
230
  React.useEffect(() => {
222
- if (!unavailable) ensure(FOLDER_ROOT);
223
- }, [ensure, unavailable]);
231
+ if (!unavailable && !hold) ensure(FOLDER_ROOT);
232
+ }, [ensure, unavailable, hold]);
224
233
 
225
234
  React.useEffect(() => {
226
235
  if (unavailable && !told.current) {
@@ -254,7 +263,7 @@ export function FolderTree({
254
263
  </button>
255
264
  </div>
256
265
 
257
- {root.loading && root.rows.length === 0 ? (
266
+ {(root.loading || hold) && root.rows.length === 0 ? (
258
267
  <p className={cn.muted}>Loading folders…</p>
259
268
  ) : null}
260
269
  {root.error ? <p className={cn.error} role="alert">{root.error}</p> : null}
@@ -42,6 +42,7 @@ export { FolderTree, folderTrail } from './FolderTree';
42
42
  export type { FolderSource, FolderTreeProps, FolderTreeSlot } from './FolderTree';
43
43
  export * from './pages/AskPage';
44
44
  export * from './pages/TrackerPage';
45
+ export * from './table';
45
46
  export * from './pages/TaskDetailPage';
46
47
  // Task-tracker pieces (bd startsim-2nn3h): the sync settings and the link chip.
47
48
  export { TaskTrackerSettings } from './pages/task-tracker/TaskTrackerSettings';
@@ -71,11 +72,13 @@ export type { WorkItemSlot } from './pages/work-items';
71
72
  export * from './pages/VoiceNotesPage';
72
73
  export { VoiceRecordButton, VOICE_MIME_CANDIDATES } from './pages/VoiceRecordButton';
73
74
  export { ConversePage } from './pages/ConversePage';
74
- export type { ConversePageProps, ConverseClassNames } from './pages/ConversePage';
75
+ export type { ConversePageProps } from './pages/ConversePage';
75
76
  export { ConnectorPage } from './pages/ConnectorPage';
76
77
  export type { ConnectorPageProps, ConnectorClassNames } from './pages/ConnectorPage';
77
78
  export { DecisionsPage } from './pages/DecisionsPage';
78
79
  export type { DecisionsPageProps, DecisionsClassNames } from './pages/DecisionsPage';
80
+ export { FleetPage } from './pages/FleetPage';
81
+ export type { FleetPageProps, FleetPayload } from './pages/FleetPage';
79
82
  export type { VoiceRecordButtonProps, VoiceRecordClassNames } from './pages/VoiceRecordButton';
80
83
  export * from './pages/home';
81
84
  export * from './pages/questions';
@@ -1,11 +1,11 @@
1
1
  /**
2
- * THE CONVERSE PAGE: one screen, one thread (Quinn). He talks or types to his assistant here: to-dos, wrapping them up,
3
- * questions, thinking a project through, orders for the relay, and the morning voice note. Nothing is a mode.
2
+ * THE TALK SCREEN: Roci, one thread (Quinn, design A). Everything is in time order in ONE thread: Roci's words as
3
+ * structured Markdown, what you said, and the things that need you as typed cards, answered inline.
4
4
  *
5
- * The thread is always readable (normal flow, nothing laid over it). Under it, a text box with a SMALL mic toggle and
6
- * Send beside it: tap the mic to listen, tap it again to stop and send what was said; typing works with the mic off.
7
- * "Done" saves the conversation; saying "parse that note" / "that's it" is handled by the assistant itself, and the
8
- * thread then shows a quiet "Filed: N to-dos" line. The loop is `createMeetingController`, shared with the native app.
5
+ * ONE mic, and it IS hands-free mode: Talk -> Mute while listening -> Interrupt while Roci thinks or speaks. The mic's colour
6
+ * is the state (no banner, no status text). Speed, replay and save live in ONE
7
+ * settings menu. No Voice/Text switch, no Drive button, no subtitle, no wake word (nothing listens for the name).
8
+ * The loop is `createMeetingController`, shared with the native app.
9
9
  */
10
10
  import * as React from 'react';
11
11
 
@@ -15,50 +15,44 @@ import type { MeetingConfig } from '../../corpus/converse/meeting-config';
15
15
  import { resolveMeetingConfig } from '../../corpus/converse/meeting-config';
16
16
  import type { ConverseEndResult } from '../../corpus/converse/types';
17
17
  import { createBrowserMeetingIO, type BrowserMeetingIO } from './converse/browserIO';
18
- import { DEFAULT_SPEED, SPEEDS, loadSpeed, normalizeSpeed, saveSpeed } from './converse/speed';
19
- import { Thread } from './converse/Thread';
20
-
21
- export type ConverseSlot = 'root' | 'secondary' | 'bubbleUser' | 'bubbleReply' | 'muted' | 'error' | 'input' | 'chip' | 'replay' | 'mic' | 'micOn';
22
- export type ConverseClassNames = Partial<Record<ConverseSlot, string>>;
23
-
24
- const FALLBACK: Record<ConverseSlot, string> = {
25
- root: 'space-y-3', secondary: 'rounded-md border px-3 py-2 text-sm', bubbleUser: 'rounded-lg border p-3 text-sm', bubbleReply: 'rounded-lg border p-3 text-sm',
26
- muted: 'text-sm opacity-70', error: 'rounded-md border p-3 text-sm', input: 'rounded-md border px-3 py-2 text-base',
27
- chip: 'rounded-full border px-2 py-0.5 text-xs opacity-80', replay: 'inline-flex rounded border p-1 opacity-70',
28
- mic: 'inline-flex h-10 w-10 shrink-0 items-center justify-center rounded-full border', micOn: 'inline-flex h-10 w-10 shrink-0 items-center justify-center rounded-full border bg-red-600 text-white',
29
- };
30
-
31
- const EMPTY: MeetingState = { phase: 'idle', retryable: false, lines: [], error: null, noAudio: null, conversationId: null, saved: null, relayNotice: null, micOn: false };
18
+ import { DEFAULT_SPEED, loadSpeed, saveSpeed } from './converse/speed';
19
+ import { ASSISTANT_NAME, normalizeAssistantName } from '../../corpus/converse/roci';
20
+ import { MIC_COLORS, converseView } from '../../corpus/converse/view';
21
+ import type { ThreadCard } from '../../corpus/converse/cards';
22
+ import type { NotifyClient } from '../../corpus/notify/client';
23
+ import { SettingsMenu } from './converse/SettingsMenu';
24
+ import { Thread, type ThreadItem } from './converse/Thread';
25
+ import { useNeedsYou } from './converse/useNeedsYou';
32
26
 
33
27
  export interface ConversePageProps {
34
28
  client: ConverseClient;
35
- classNames?: ConverseClassNames;
36
29
  /** Meeting settings; every one has a default. */
37
30
  meeting?: Partial<MeetingConfig>;
38
31
  /** Injectable for tests; defaults to the browser's microphone and audio element. */
39
32
  createIO?: () => BrowserMeetingIO;
40
- /** Where the saved conversation can be read; given the Done result. */
33
+ /** Where the saved conversation can be read; given the saved result. */
41
34
  savedLink?: (saved: ConverseEndResult) => React.ReactNode;
35
+ /** The needs-you queue (pending decisions): shown as question cards in the thread and answered there. */
36
+ notify?: NotifyClient;
37
+ /** Real cards the host has (the brief); their `read` action asks Roci to read it. */
38
+ cards?: ThreadCard[];
39
+ /** What the assistant is called. Typed "Rossi" and friends become this. */
40
+ assistantName?: string;
42
41
  }
43
42
 
44
- const STATUS: Record<string, string> = {
45
- idle: '',
46
- listening: 'Listening… tap the mic again to send.',
47
- thinking: 'Thinking…',
48
- speaking: 'Speaking…',
49
- ending: 'Saving…',
50
- ended: '',
51
- stopped: 'The conversation stopped.',
52
- };
43
+ const MIC_LABEL = { talk: 'Talk', mute: 'Mute', interrupt: 'Interrupt' } as const;
44
+ const SUGGESTIONS = ["What's on my plate", 'Read my brief', 'Anything for me to approve?'];
53
45
 
54
46
  const MicIcon = () => (
55
47
  <svg aria-hidden="true" viewBox="0 0 24 24" width="20" height="20" fill="currentColor"><path d="M12 14a3 3 0 0 0 3-3V5a3 3 0 0 0-6 0v6a3 3 0 0 0 3 3zm5-3a5 5 0 0 1-10 0H5a7 7 0 0 0 6 6.92V21h2v-3.08A7 7 0 0 0 19 11h-2z" /></svg>
56
48
  );
49
+ const StopIcon = () => <span aria-hidden="true" className="inline-block h-3.5 w-3.5 rounded-sm bg-current" />;
50
+
51
+ const EMPTY: MeetingState = { phase: 'idle', retryable: false, lines: [], error: null, noAudio: null, conversationId: null, saved: null, relayNotice: null, micOn: false, micLive: false };
57
52
 
58
- export function ConversePage({ client, classNames, meeting, createIO, savedLink }: ConversePageProps) {
59
- const cx = (slot: ConverseSlot) => classNames?.[slot] ?? FALLBACK[slot];
53
+ export function ConversePage({ client, meeting, createIO, savedLink, notify, cards: hostCards, assistantName = ASSISTANT_NAME }: ConversePageProps) {
60
54
  const [state, setState] = React.useState<MeetingState>(EMPTY);
61
- /** Lines of conversations already saved with Done: the thread keeps them, the next message starts a new conversation. */
55
+ /** Lines of conversations already saved: the thread keeps them, the next message starts a new conversation. */
62
56
  const [history, setHistory] = React.useState<MeetingLine[]>([]);
63
57
  const [error, setError] = React.useState<string | null>(null);
64
58
  const [draft, setDraft] = React.useState('');
@@ -66,21 +60,24 @@ export function ConversePage({ client, classNames, meeting, createIO, savedLink
66
60
  const io = React.useRef<BrowserMeetingIO | null>(null);
67
61
  const micReady = React.useRef(false);
68
62
  const endRef = React.useRef<HTMLDivElement | null>(null);
69
- /** Reply text -> its audio url, so each assistant line can be played again (the controller only replays the newest). */
63
+ /** Reply text -> its audio url, so the last reply can be played again from the settings menu. */
70
64
  const audioOf = React.useRef(new Map<string, string>());
71
65
  const replayAbort = React.useRef<AbortController | null>(null);
72
66
  const [speed, setSpeedState] = React.useState<number>(DEFAULT_SPEED);
73
67
  const speedRef = React.useRef(speed);
74
68
  React.useEffect(() => { const v = loadSpeed(); speedRef.current = v; setSpeedState(v); }, []);
75
- function onSpeed(v: number) {
76
- speedRef.current = v; setSpeedState(v); saveSpeed(v); io.current?.setSpeed?.(v);
77
- }
69
+ function onSpeed(v: number) { speedRef.current = v; setSpeedState(v); saveSpeed(v); io.current?.setSpeed?.(v); }
78
70
 
71
+ const needs = useNeedsYou(notify);
79
72
  const lines = React.useMemo(() => [...history, ...state.lines], [history, state.lines]);
73
+ /** ONE list in time order: cards arrived before this session's conversation, so they lead; lines follow as said. */
74
+ const items = React.useMemo<ThreadItem[]>(() => {
75
+ const cards = [...(hostCards ?? []), ...needs.cards].sort((a, b) => a.at.localeCompare(b.at));
76
+ return [...cards.map((card) => ({ kind: 'card' as const, card })), ...lines.map((line) => ({ kind: 'line' as const, line }))];
77
+ }, [hostCards, needs.cards, lines]);
80
78
  React.useEffect(() => { endRef.current?.scrollIntoView?.({ block: 'end' }); }, [lines, state.phase]);
81
79
  React.useEffect(() => () => { void ctl.current?.end(); io.current?.close(); }, []);
82
80
 
83
- /** The same client, remembering which audio belongs to which reply (for the per-line speaker). */
84
81
  const trackedClient = React.useMemo<ConverseClient>(() => ({
85
82
  ...client,
86
83
  turn: async (input) => {
@@ -105,9 +102,10 @@ export function ConversePage({ client, classNames, meeting, createIO, savedLink
105
102
  return ctl.current;
106
103
  }
107
104
 
108
- async function onMic() {
105
+ /** Talk: opens the microphone inside the tap, then listens. */
106
+ async function startListening() {
109
107
  setError(null);
110
- if (state.micOn) { ctl.current?.mic(false); return; }
108
+ if (state.micOn) return;
111
109
  const browserIO = ensureIO();
112
110
  if (!micReady.current) {
113
111
  try {
@@ -121,94 +119,105 @@ export function ConversePage({ client, classNames, meeting, createIO, savedLink
121
119
  ensureCtl().mic(true);
122
120
  }
123
121
 
122
+ /** The ONE mic control: Talk, Mute (stop listening and send what was said), Interrupt (cut the reply off). */
123
+ function onMic() {
124
+ if (view.micAction === 'interrupt') { ctl.current?.stop(); return; }
125
+ if (view.micAction === 'mute') { setError(null); ctl.current?.mic(false); return; }
126
+ void startListening();
127
+ }
128
+
129
+ async function send(text: string) {
130
+ const clean = normalizeAssistantName(text.trim(), assistantName);
131
+ if (!clean) return;
132
+ setError(null);
133
+ ensureIO().unlockPlayback?.(); // inside the tap, so the spoken reply is allowed to play; does not touch the microphone
134
+ await ensureCtl().sendText(clean);
135
+ }
124
136
  async function onSend(event: React.FormEvent) {
125
137
  event.preventDefault();
126
- const text = draft.trim();
127
- if (!text) return;
138
+ const text = draft;
128
139
  setDraft('');
129
- setError(null);
130
- ensureIO().unlockPlayback?.(); // inside the tap, so the spoken reply is allowed to play; does not touch the microphone
131
- await ensureCtl().sendText(text);
140
+ await send(text);
132
141
  }
133
142
 
134
- async function onDone() {
143
+ async function onSave() {
135
144
  const c = ctl.current;
136
145
  if (!c) return;
137
- const lines = c.getState().lines;
146
+ const saving = c.getState().lines;
138
147
  await c.end();
139
148
  const saved = c.getState().saved;
140
149
  micReady.current = false;
141
150
  io.current?.close();
142
151
  // Keep what was said on screen; the controller is replaced on the next message.
143
- setHistory((h) => [...h, ...lines]);
152
+ setHistory((h) => [...h, ...saving]);
144
153
  setState({ ...EMPTY, saved, error: c.getState().error });
145
154
  ctl.current = null;
146
155
  }
147
156
 
148
- async function onReplay(line: MeetingLine) {
149
- const url = audioOf.current.get(line.text);
150
- if (!url) return;
157
+ const lastReply = [...lines].reverse().find((l) => l.role === 'assistant' && audioOf.current.has(l.text));
158
+ async function onReplay() {
159
+ const url = lastReply ? audioOf.current.get(lastReply.text) : undefined;
160
+ if (!lastReply || !url) return;
151
161
  replayAbort.current?.abort();
152
162
  const abort = new AbortController();
153
163
  replayAbort.current = abort;
154
- const cfg = resolveMeetingConfig(meeting);
155
164
  ensureIO().unlockPlayback?.();
156
- await ensureIO().speak({ conversationId: state.conversationId ?? '', turn: 0, replyText: line.text, audioUrl: url }, abort.signal, cfg);
165
+ await ensureIO().speak({ conversationId: state.conversationId ?? '', turn: 0, replyText: lastReply.text, audioUrl: url }, abort.signal, resolveMeetingConfig(meeting));
157
166
  }
158
167
 
159
- const status = state.noAudio && state.lines.length && state.phase !== 'thinking'
160
- ? `No spoken reply: ${state.noAudio}. The text is above.`
161
- : STATUS[state.phase] ?? '';
162
- const busy = state.phase === 'thinking' || state.phase === 'ending';
168
+ function onCardAction(card: ThreadCard, actionId: string) {
169
+ if (card.type === 'brief' && actionId === 'read') { void send('Read my brief'); return; }
170
+ const label = needs.optionLabel(card, actionId);
171
+ if (card.type === 'question' && label) void needs.answer(card, label);
172
+ }
163
173
 
174
+ const view = converseView(state);
175
+ const noAudio = state.noAudio && state.lines.length && state.phase !== 'thinking' ? `No spoken reply: ${state.noAudio}. The text is above.` : null;
164
176
  return (
165
- <div className={cx('root')}>
166
- <Thread
167
- lines={lines}
168
- cx={cx}
169
- canReplay={(l) => audioOf.current.has(l.text)}
170
- onReplay={(l) => void onReplay(l)}
171
- />
172
- {state.saved ? (
173
- <p className={cx('muted')} role="status" data-testid="converse-saved">
174
- Saved {state.saved.turns} turn{state.saved.turns === 1 ? '' : 's'}. {savedLink?.(state.saved)}
175
- </p>
176
- ) : null}
177
- <p className={cx('muted')} role="status" aria-live="polite" data-testid="converse-status">{status}</p>
178
- {error || state.error ? <div className={cx('error')} role="alert">{error ?? state.error}</div> : null}
179
- {state.relayNotice ? (
180
- <div className={cx('muted')} role="status" data-testid="converse-relay-notice">
181
- Relay: {state.relayNotice}{' '}
182
- <button type="button" className={cx('secondary')} onClick={() => ctl.current?.dismissNotice()}>Dismiss</button>
183
- </div>
184
- ) : null}
185
- <form onSubmit={onSend} className="flex items-center gap-2">
186
- <button
187
- type="button" onClick={() => void onMic()} className={state.micOn ? cx('micOn') : cx('mic')} data-testid="converse-mic"
188
- aria-pressed={state.micOn} aria-label={state.micOn ? 'Stop the microphone and send' : 'Start the microphone'} title={state.micOn ? 'Tap to stop and send' : 'Tap to talk'}
189
- ><MicIcon /></button>
190
- <input
191
- className={`${cx('input')} min-w-0 flex-1`} value={draft} onChange={(e) => setDraft(e.target.value)}
192
- placeholder="Type or tap the mic" aria-label="Type a message" enterKeyHint="send"
193
- />
194
- <button type="submit" className={cx('secondary')} disabled={!draft.trim()}>Send</button>
195
- </form>
196
- {lines.length === 0 ? (
197
- <div className="flex flex-wrap items-center gap-2 text-sm" data-testid="converse-suggestions">
198
- <span className={cx('muted')}>Try:</span>
199
- {['What is due today?', 'Add a to-do: call the vendor', 'What am I waiting on?'].map((s) => (
200
- <button key={s} type="button" className="rounded-full border border-gray-300 bg-white px-3 py-1 text-gray-700 hover:border-gray-400" onClick={() => setDraft(s)}>{s}</button>
201
- ))}
202
- </div>
203
- ) : null}
204
- <div className="flex flex-wrap items-center gap-3 text-sm">
205
- <button type="button" className={cx('secondary')} title="Save this conversation" onClick={() => void onDone()} disabled={busy || (!ctl.current)}>Done</button>
206
- <label className={cx('muted')} htmlFor="converse-speed">Speed</label>
207
- <select id="converse-speed" className="rounded-md border border-gray-300 bg-white px-2 py-1 text-sm text-gray-800" value={speed} onChange={(e) => onSpeed(normalizeSpeed(e.target.value))} data-testid="converse-speed" aria-label="Speech speed">
208
- {SPEEDS.map((v) => <option key={v} value={v}>{v}x</option>)}
209
- </select>
177
+ <div className="flex min-h-[calc(100dvh-4rem)] flex-col gap-4">
178
+ <header className="flex justify-end" data-testid="converse-header">
179
+ <SettingsMenu speed={speed} onSpeed={onSpeed} canReplay={!!lastReply} onReplay={() => void onReplay()} canSave={!!ctl.current && !view.busy} onSave={() => void onSave()} />
180
+ </header>
181
+ <div className="flex-1 space-y-3">
182
+ {items.length ? (
183
+ <Thread items={items} assistantName={assistantName} cardProps={{ onAction: onCardAction, onReply: (c, t) => void needs.answer(c, t), busyId: needs.busyId, errors: needs.errors }} />
184
+ ) : null}
185
+ {state.saved ? (
186
+ <p className="text-center text-xs text-gray-500" role="status" data-testid="converse-saved">
187
+ Saved {state.saved.turns} turn{state.saved.turns === 1 ? '' : 's'}. {savedLink?.(state.saved)}
188
+ </p>
189
+ ) : null}
190
+ {noAudio ? <p className="text-center text-xs text-gray-500" role="status" data-testid="converse-no-audio">{noAudio}</p> : null}
191
+ {error || state.error ? <div className="rounded-md border border-red-200 bg-red-50 p-3 text-sm text-red-700" role="alert">{error ?? state.error}</div> : null}
192
+ {state.relayNotice ? (
193
+ <div className="rounded-md border border-gray-200 bg-white p-3 text-sm text-gray-600" role="status" data-testid="converse-relay-notice">
194
+ Relay: {state.relayNotice}{' '}
195
+ <button type="button" className="font-semibold underline" onClick={() => ctl.current?.dismissNotice()}>Dismiss</button>
196
+ </div>
197
+ ) : null}
198
+ <div ref={endRef} />
199
+ </div>
200
+ <div className="sticky bottom-0 space-y-2 bg-gray-50 pb-2 pt-2">
201
+ {lines.length === 0 ? (
202
+ <div className="flex flex-wrap items-center gap-2 text-sm" data-testid="converse-suggestions">
203
+ {SUGGESTIONS.map((s) => (
204
+ <button key={s} type="button" className="rounded-full border border-gray-300 bg-white px-3 py-1 text-gray-700 hover:border-gray-400" onClick={() => void send(s)}>{s}</button>
205
+ ))}
206
+ </div>
207
+ ) : null}
208
+ <form onSubmit={onSend} className="flex items-center gap-2">
209
+ <input
210
+ className="min-w-0 flex-1 rounded-full border border-gray-300 bg-white px-4 py-2.5 text-base" value={draft} onChange={(e) => setDraft(e.target.value)}
211
+ placeholder={`Ask ${assistantName} anything…`} aria-label="Type a message" enterKeyHint="send"
212
+ />
213
+ <button
214
+ type="button" onClick={onMic} data-testid="converse-mic" data-action={view.micAction}
215
+ data-tone={view.micTone} style={{ backgroundColor: MIC_COLORS[view.micTone] }}
216
+ aria-pressed={view.micAction !== 'talk'} aria-label={MIC_LABEL[view.micAction]} title={`${MIC_LABEL[view.micAction]} (${view.micTone === 'idle' ? 'ready' : view.micTone})`}
217
+ disabled={view.busy} className="inline-flex h-11 shrink-0 items-center gap-2 rounded-full px-5 text-sm font-semibold text-white disabled:opacity-50"
218
+ >{view.micAction === 'interrupt' ? <StopIcon /> : <MicIcon />}{MIC_LABEL[view.micAction]}</button>
219
+ </form>
210
220
  </div>
211
- <div ref={endRef} />
212
221
  </div>
213
222
  );
214
- }
223
+ }