@startsimpli/integrations 0.2.201 → 0.2.203
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/package.json +6 -6
- package/src/__tests__/briefing-markdown.test.ts +64 -0
- package/src/__tests__/converse-cards.test.ts +53 -0
- package/src/__tests__/converse-page.test.tsx +148 -37
- package/src/__tests__/converse-roci.test.ts +22 -0
- package/src/__tests__/converse-structure.test.ts +27 -0
- package/src/__tests__/converse-view.test.ts +46 -0
- package/src/__tests__/corpus-tracker.test.tsx +32 -176
- package/src/__tests__/data-table-logic.test.ts +75 -0
- package/src/__tests__/data-table.test.tsx +133 -0
- package/src/__tests__/home-brief.test.tsx +25 -40
- package/src/__tests__/library-call-shape.test.tsx +164 -0
- package/src/__tests__/load-error.test.tsx +1 -1
- package/src/__tests__/mini-markdown.test.tsx +24 -0
- package/src/__tests__/overview-page.test.tsx +36 -6
- package/src/__tests__/plan-shell.test.tsx +6 -4
- package/src/__tests__/timeline-events.test.ts +65 -0
- package/src/__tests__/timeline-table.test.tsx +66 -0
- package/src/__tests__/todo-table-model.test.ts +75 -0
- package/src/__tests__/todo-table.test.tsx +202 -0
- package/src/__tests__/tracker-timeline-component.test.tsx +4 -4
- package/src/__tests__/tracker-timeline-reader.test.ts +1 -1
- package/src/comms/__tests__/app-sends-page.test.tsx +69 -0
- package/src/comms/api/comms.ts +23 -0
- package/src/comms/components/ResultsPanel.tsx +2 -2
- package/src/comms/components/SendLog.tsx +20 -8
- package/src/comms/components/index.ts +1 -0
- package/src/comms/components/pages/AppSendsPage.tsx +58 -0
- package/src/comms/hooks/index.ts +8 -3
- package/src/components/FolderTree.tsx +12 -3
- package/src/components/index.ts +2 -1
- package/src/components/pages/ConversePage.tsx +114 -105
- package/src/components/pages/LibraryPage.tsx +63 -24
- package/src/components/pages/TrackerPage.tsx +170 -474
- package/src/components/pages/converse/CardView.tsx +72 -0
- package/src/components/pages/converse/SettingsMenu.tsx +37 -0
- package/src/components/pages/converse/Thread.tsx +48 -33
- package/src/components/pages/converse/useNeedsYou.ts +60 -0
- package/src/components/pages/home/BriefCard.tsx +16 -7
- package/src/components/pages/home/HomeBriefPage.tsx +6 -91
- package/src/components/pages/home/MiniMarkdown.tsx +51 -0
- package/src/components/pages/home/{DueSoonLine.tsx → dueSoonText.ts} +2 -11
- package/src/components/pages/home/index.ts +1 -1
- package/src/components/pages/overview/OverviewPage.tsx +46 -83
- package/src/components/pages/plan/TalkPage.tsx +5 -14
- package/src/components/pages/plan/TimelinePage.tsx +4 -2
- package/src/components/pages/tracker/SweepPanel.tsx +108 -0
- package/src/components/pages/tracker/TimelineTable.tsx +70 -0
- package/src/components/pages/tracker/TrackerTimeline.tsx +32 -15
- package/src/components/table/DataTable.tsx +92 -0
- package/src/components/table/RowMenu.tsx +35 -0
- package/src/components/table/TablePagination.tsx +63 -0
- package/src/components/table/TableToolbar.tsx +56 -0
- package/src/components/table/TodoTable.tsx +142 -0
- package/src/components/table/index.ts +10 -0
- package/src/components/table/table-logic.ts +60 -0
- package/src/components/table/todo-model.ts +93 -0
- package/src/corpus/briefing/generate-weekly.ts +4 -0
- package/src/corpus/briefing/generate.ts +4 -0
- package/src/corpus/briefing/index.ts +1 -0
- package/src/corpus/briefing/markdown.ts +71 -0
- package/src/corpus/client.ts +38 -146
- package/src/corpus/converse/cards.ts +69 -0
- package/src/corpus/converse/index.ts +6 -0
- package/src/corpus/converse/roci.ts +13 -0
- package/src/corpus/converse/structure.ts +39 -0
- package/src/corpus/converse/view.ts +34 -0
- package/src/corpus/index.ts +2 -0
- package/src/corpus/participants.ts +220 -0
- package/src/corpus/timeline-events.ts +83 -0
- package/src/corpus/tracker-sort.ts +9 -3
- package/src/corpus/tracker-timeline-client.ts +2 -0
- package/src/corpus/tracker-timeline.ts +4 -0
- package/src/corpus/types.ts +32 -5
- package/src/native/app/__tests__/plan-talk-registry.test.tsx +2 -1
- package/src/native/converse/ConverseScreen.tsx +3 -5
- package/src/native/home/HomeScreen.tsx +1 -1
- package/src/native/home/tab.tsx +1 -2
- package/src/native/plan/PlanTab.tsx +1 -2
- package/src/native/plan/__tests__/plan-tab.test.tsx +5 -5
- package/src/native/talk/TalkTab.tsx +1 -1
- package/src/native/talk/__tests__/talk-tab.test.tsx +1 -1
- package/src/__tests__/home-needs-your-call.test.tsx +0 -65
- package/src/components/pages/tracker/TrackerBoard.tsx +0 -45
- package/src/components/pages/tracker/TrackerToolbar.tsx +0 -44
package/src/corpus/client.ts
CHANGED
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
import { writePossiblyDone } from './possibly-done';
|
|
34
34
|
import { patchEditedItem } from './commitment-edit';
|
|
35
35
|
import { readStandings } from './standings';
|
|
36
|
+
import { createParticipantReader } from './participants';
|
|
36
37
|
import { createTimelineReader } from './tracker-timeline-client';
|
|
37
38
|
import {
|
|
38
39
|
DEFAULT_PARTICIPANT_EDGES,
|
|
@@ -89,6 +90,7 @@ import type {
|
|
|
89
90
|
MoneyEvent,
|
|
90
91
|
Party,
|
|
91
92
|
PartyRef,
|
|
93
|
+
ListSourcesOptions,
|
|
92
94
|
PlanningApi,
|
|
93
95
|
SourceFreshness,
|
|
94
96
|
} from './types';
|
|
@@ -262,11 +264,13 @@ function commitmentParams(query: CommitmentQuery, type: string): Record<string,
|
|
|
262
264
|
...(query.pageSize ? { page_size: Math.min(query.pageSize, 200) } : {}),
|
|
263
265
|
// Oldest debt first unless the screen asks otherwise — asking the server
|
|
264
266
|
// means page one is the right page one.
|
|
265
|
-
order: commitmentOrder(query.sort),
|
|
267
|
+
order: commitmentOrder(query.sort, query.sortDir),
|
|
266
268
|
};
|
|
267
269
|
if (statuses.length === 1) out['attr.status'] = statuses[0];
|
|
268
270
|
else if (statuses.length > 1) out['attr.status__in'] = statuses.join(',');
|
|
269
|
-
|
|
271
|
+
const subtypes = Array.isArray(query.subtype) ? query.subtype : query.subtype ? [query.subtype] : [];
|
|
272
|
+
if (subtypes.length === 1) out['attr.subtype'] = subtypes[0];
|
|
273
|
+
else if (subtypes.length > 1) out['attr.subtype__in'] = subtypes.join(',');
|
|
270
274
|
if (query.owner) out['attr.owner_name__icontains'] = query.owner.slice(0, TEXT_FILTER_MAX);
|
|
271
275
|
if (query.dueBefore) out['attr.due_at__lte'] = query.dueBefore;
|
|
272
276
|
if (query.changedAfter) out['attr.last_seen_at__gte'] = query.changedAfter;
|
|
@@ -293,7 +297,7 @@ function commitmentParams(query: CommitmentQuery, type: string): Record<string,
|
|
|
293
297
|
/** Which server parameter carries which `CommitmentQuery` key. */
|
|
294
298
|
const FILTER_PARAMS: Array<[keyof CommitmentQuery, string[]]> = [
|
|
295
299
|
['status', ['attr.status', 'attr.status__in']],
|
|
296
|
-
['subtype', ['attr.subtype']],
|
|
300
|
+
['subtype', ['attr.subtype', 'attr.subtype__in']],
|
|
297
301
|
['owner', ['attr.owner_name__icontains']],
|
|
298
302
|
['dueBefore', ['attr.due_at__lte']],
|
|
299
303
|
['changedAfter', ['attr.last_seen_at__gte']],
|
|
@@ -589,141 +593,10 @@ export function createCorpusApi(
|
|
|
589
593
|
}
|
|
590
594
|
}
|
|
591
595
|
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
const response = await http.get<DrfPage<T>>(path, { params: { ...extra, page: index } });
|
|
597
|
-
const results = response?.results ?? [];
|
|
598
|
-
rows.push(...results);
|
|
599
|
-
if (!response?.next || results.length === 0) break;
|
|
600
|
-
}
|
|
601
|
-
return rows;
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
// ---------------------------------------------------------------------
|
|
605
|
-
// the participant graph
|
|
606
|
-
// ---------------------------------------------------------------------
|
|
607
|
-
//
|
|
608
|
-
// THE EDGES OF THE RECORDS ON SCREEN, AND NO OTHERS (bd startsim-o0o6o.2).
|
|
609
|
-
// This used to be `readAll(relationships, {})` — every edge in the workspace,
|
|
610
|
-
// twenty pages of it, on a comment saying the endpoint had no filters. It has
|
|
611
|
-
// them: `entity__in` takes the ids of one page, bounded at `MAX_ID_LIST`,
|
|
612
|
-
// which is the shape `RelationshipQuery`'s own docstring says it exists for.
|
|
613
|
-
//
|
|
614
|
-
// ONE read for a page of records, not one per record — and cached per record,
|
|
615
|
-
// so a screen that lists, opens a row and then asks a question spends it once.
|
|
616
|
-
// It FAILS SOFT: a tenant whose relationships endpoint is missing or refused
|
|
617
|
-
// renders exactly what it rendered before this existed, rather than an error
|
|
618
|
-
// where a Library used to be.
|
|
619
|
-
let roster: { at: number; value: Promise<Party[]> } | null = null;
|
|
620
|
-
const known = new Map<string, { at: number; value: PartyRef[] }>();
|
|
621
|
-
|
|
622
|
-
/**
|
|
623
|
-
* The people an edge can point AT, read once and reused.
|
|
624
|
-
*
|
|
625
|
-
* Still a walked list, because there is no id filter on `/entities/`: the
|
|
626
|
-
* recognised set is `search`, `source`, `party`, the occurred window,
|
|
627
|
-
* `related_*`, `order` and `attr.*`, and an unrecognised `id__in` would be
|
|
628
|
-
* swept into `ignored_filters` and answered with the whole page. It is at
|
|
629
|
-
* least a TYPED read — `?type=party` is applied server-side — and it is only
|
|
630
|
-
* reached when the narrowed edge read came back with edges to resolve.
|
|
631
|
-
*/
|
|
632
|
-
function partyRoster(): Promise<Party[]> {
|
|
633
|
-
const now = Date.now();
|
|
634
|
-
if (!roster || now - roster.at > graphTtlMs) {
|
|
635
|
-
roster = {
|
|
636
|
-
at: now,
|
|
637
|
-
value: readAll<TenantEntity>(entities, { type: types.party })
|
|
638
|
-
.then((rows) => rows.map((entity) => toParty(entity, scope)))
|
|
639
|
-
.catch(() => []),
|
|
640
|
-
};
|
|
641
|
-
}
|
|
642
|
-
return roster.value;
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
/**
|
|
646
|
-
* The edges touching these records, or `null` when the server did not confirm
|
|
647
|
-
* it narrowed by them.
|
|
648
|
-
*
|
|
649
|
-
* `null` IS NOT "NO EDGES", and the difference is the whole point. A fork
|
|
650
|
-
* without `RelationshipQuery` accepts `entity__in`, names it in
|
|
651
|
-
* `ignored_filters` and answers with an arbitrary page of the WHOLE edge table
|
|
652
|
-
* (bd startsim-768w.38.39) — rows that look exactly like a narrow answer and
|
|
653
|
-
* would put the wrong people, or a fraction of the right ones, on a record.
|
|
654
|
-
* start-simpli#154 settled what to do with a result the server did not
|
|
655
|
-
* confirm: do not use it. So this reports that it could not ask, and the
|
|
656
|
-
* caller renders what it rendered before the join existed.
|
|
657
|
-
*
|
|
658
|
-
* `rel_type` rides along unchecked on purpose: it only ever makes the answer
|
|
659
|
-
* SMALLER, and `indexParticipants` ranks by edge type anyway. A fork that
|
|
660
|
-
* ignores it pays in PAGES rather than in correctness — a record with many
|
|
661
|
-
* non-participant edges can push its people onto a second page, and the walk
|
|
662
|
-
* below follows `next` until it has them.
|
|
663
|
-
*/
|
|
664
|
-
async function edgesFor(recordIds: string[]): Promise<TenantRelationship[] | null> {
|
|
665
|
-
const rows: TenantRelationship[] = [];
|
|
666
|
-
for (let start = 0; start < recordIds.length; start += MAX_ID_LIST) {
|
|
667
|
-
// CHUNKED, because `_uuid_list` answers a longer list with a 400 rather
|
|
668
|
-
// than truncating it. Truncating here instead would drop the people off
|
|
669
|
-
// the tail of a wide page silently, which is the failure being undone.
|
|
670
|
-
const chunk = recordIds.slice(start, start + MAX_ID_LIST);
|
|
671
|
-
const extra: Record<string, unknown> = {
|
|
672
|
-
entity__in: chunk.join(','),
|
|
673
|
-
page_size: MAX_ID_LIST,
|
|
674
|
-
};
|
|
675
|
-
if (participantEdges.length) extra.rel_type = participantEdges.join(',');
|
|
676
|
-
for (let index = 1; index <= maxGraphPages; index += 1) {
|
|
677
|
-
const response = await http.get<DrfPage<TenantRelationship> & ServerFilterReport>(
|
|
678
|
-
relationships,
|
|
679
|
-
{ params: { ...extra, page: index } },
|
|
680
|
-
);
|
|
681
|
-
const applied = response.applied_filters ?? response.appliedFilters;
|
|
682
|
-
if (!applied?.includes('entity__in')) return null;
|
|
683
|
-
const results = response.results ?? [];
|
|
684
|
-
rows.push(...results);
|
|
685
|
-
if (!response.next || results.length === 0) break;
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
return rows;
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
async function participantsFor(
|
|
692
|
-
records: Array<string | number>,
|
|
693
|
-
): Promise<Map<string, PartyRef[]>> {
|
|
694
|
-
const out = new Map<string, PartyRef[]>();
|
|
695
|
-
if (!resolveParticipants) return out;
|
|
696
|
-
const now = Date.now();
|
|
697
|
-
const wanted: string[] = [];
|
|
698
|
-
for (const record of records) {
|
|
699
|
-
const id = String(record ?? '').trim();
|
|
700
|
-
if (!id || out.has(id) || wanted.includes(id)) continue;
|
|
701
|
-
const cached = known.get(id);
|
|
702
|
-
if (cached && now - cached.at <= graphTtlMs) out.set(id, cached.value);
|
|
703
|
-
else wanted.push(id);
|
|
704
|
-
}
|
|
705
|
-
if (wanted.length === 0) return out;
|
|
706
|
-
try {
|
|
707
|
-
const edges = await edgesFor(wanted);
|
|
708
|
-
// Could not ask. Nothing is cached, so the next page asks again rather
|
|
709
|
-
// than remembering an answer that was never given.
|
|
710
|
-
if (!edges) return out;
|
|
711
|
-
const parties = edges.length ? await partyRoster() : [];
|
|
712
|
-
const indexed = edges.length
|
|
713
|
-
? indexParticipants(edges, parties, participantEdges)
|
|
714
|
-
: new Map<string, PartyRef[]>();
|
|
715
|
-
for (const id of wanted) {
|
|
716
|
-
// A record the server confirmed has no participant edges is REMEMBERED
|
|
717
|
-
// as having none — otherwise every page re-asks for the same silence.
|
|
718
|
-
const people = indexed.get(id) ?? [];
|
|
719
|
-
known.set(id, { at: now, value: people });
|
|
720
|
-
out.set(id, people);
|
|
721
|
-
}
|
|
722
|
-
} catch {
|
|
723
|
-
// The Library renders without its Parties block rather than not at all.
|
|
724
|
-
}
|
|
725
|
-
return out;
|
|
726
|
-
}
|
|
596
|
+
const { participantsFor } = createParticipantReader({
|
|
597
|
+
http, entities, relationships, types, scope,
|
|
598
|
+
participantEdges, maxGraphPages, graphTtlMs, resolveParticipants,
|
|
599
|
+
});
|
|
727
600
|
|
|
728
601
|
return {
|
|
729
602
|
...createFilingApi(http, { entities, relationships }),
|
|
@@ -731,11 +604,21 @@ export function createCorpusApi(
|
|
|
731
604
|
// The Tracker timeline's server reads (grouped counts + one capped page per series).
|
|
732
605
|
timeline: createTimelineReader({ http, type: types.commitment, entitiesPath: entities }),
|
|
733
606
|
|
|
734
|
-
|
|
607
|
+
participantsFor,
|
|
608
|
+
|
|
609
|
+
async listDocuments(query, listOptions) {
|
|
735
610
|
const documents = await page<TenantEntity>(types.document, query, (entity) => entity);
|
|
611
|
+
// `participants: false` is the Library's first paint: the rows come back as
|
|
612
|
+
// soon as the ONE documents read does, and the people on them are fetched
|
|
613
|
+
// separately (`participantsFor`) and patched in. The default stays "with
|
|
614
|
+
// people" so every other caller reads exactly what it always read.
|
|
615
|
+
//
|
|
736
616
|
// Skip the edge read entirely for an empty page: an empty corpus should
|
|
737
617
|
// cost exactly the one request it costs today.
|
|
738
|
-
const byRecord =
|
|
618
|
+
const byRecord =
|
|
619
|
+
listOptions?.participants === false
|
|
620
|
+
? new Map<string, PartyRef[]>()
|
|
621
|
+
: await participantsFor(documents.results.map((entity) => entity.id));
|
|
739
622
|
return {
|
|
740
623
|
...documents,
|
|
741
624
|
results: documents.results.map((entity) =>
|
|
@@ -1023,7 +906,7 @@ export function createCorpusApi(
|
|
|
1023
906
|
* unnarrowed one, so a count it did not confirm is not reported at all —
|
|
1024
907
|
* and `0` is left free to mean what it says.
|
|
1025
908
|
*/
|
|
1026
|
-
async listSources(): Promise<SourceFreshness[]> {
|
|
909
|
+
async listSources(sourceOptions?: ListSourcesOptions): Promise<SourceFreshness[]> {
|
|
1027
910
|
const connectionPage = await http
|
|
1028
911
|
.get<DrfPage<Record<string, unknown>>>(connections)
|
|
1029
912
|
.catch(() => EMPTY_PAGE as DrfPage<Record<string, unknown>>);
|
|
@@ -1048,11 +931,20 @@ export function createCorpusApi(
|
|
|
1048
931
|
for (const { key } of live) {
|
|
1049
932
|
if (!pending.has(key)) pending.set(key, countDocumentsFrom(key));
|
|
1050
933
|
}
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
)
|
|
934
|
+
// THE COUNTS ARE AN ORNAMENT ON A CARD WHOSE POINT IS FRESHNESS, so a caller
|
|
935
|
+
// that passes `onCounts` gets the cards the moment the connections answer
|
|
936
|
+
// and the numbers afterwards. One COUNT per source, however many cards, is
|
|
937
|
+
// one more request each; on a backend that answers one at a time seven of
|
|
938
|
+
// them stood between the reader and the strip (measured, 2026-11-20).
|
|
939
|
+
const settled = Promise.all(
|
|
940
|
+
[...pending].map(async ([key, count]) => [key, await count] as const),
|
|
941
|
+
).then((entries) => new Map(entries));
|
|
942
|
+
let counts = new Map<string, number | null>();
|
|
943
|
+
if (sourceOptions?.onCounts) {
|
|
944
|
+
void settled.then((resolved) => sourceOptions.onCounts?.(resolved));
|
|
945
|
+
} else {
|
|
946
|
+
counts = await settled;
|
|
947
|
+
}
|
|
1056
948
|
|
|
1057
949
|
const now = Date.now();
|
|
1058
950
|
return live.map(({ connection, key }) => {
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THREAD CARDS: every item that needs Quinn (a question, an approval, the brief, a task, an email, a result) is ONE
|
|
3
|
+
* shape, drawn by one component with one layout: chip, who asked, time / title / one-line detail / actions.
|
|
4
|
+
* Pure data, no React: the web thread and the native thread read the same cards. Only real items become cards; a
|
|
5
|
+
* source that has nothing to say produces none, and a sample item is marked `sample` so it can never pass as urgent.
|
|
6
|
+
*/
|
|
7
|
+
import type { DecisionRecord } from '../notify/types';
|
|
8
|
+
|
|
9
|
+
export type CardType = 'question' | 'approval' | 'brief' | 'task' | 'email' | 'result';
|
|
10
|
+
|
|
11
|
+
export const CARD_CHIP: Record<CardType, string> = { question: 'QUESTION', approval: 'APPROVAL', brief: 'BRIEF', task: 'TASK', email: 'EMAIL', result: 'RESULT' };
|
|
12
|
+
|
|
13
|
+
export interface CardAction { id: string; label: string; /** One primary action per card. */ primary?: boolean }
|
|
14
|
+
|
|
15
|
+
export interface ThreadCard {
|
|
16
|
+
/** Stable across reloads, so a card is never shown twice. */
|
|
17
|
+
id: string;
|
|
18
|
+
type: CardType;
|
|
19
|
+
/** Who asked. Always shown. */
|
|
20
|
+
from: string;
|
|
21
|
+
/** ISO time the item arrived; the thread keeps cards in this order. */
|
|
22
|
+
at: string;
|
|
23
|
+
title: string;
|
|
24
|
+
/** One line. */
|
|
25
|
+
detail?: string;
|
|
26
|
+
/** Markdown body (the brief's bullets). */
|
|
27
|
+
body?: string;
|
|
28
|
+
actions: CardAction[];
|
|
29
|
+
/** A question with no fixed options is answered in a typed reply. */
|
|
30
|
+
freeReply?: boolean;
|
|
31
|
+
/** Further questions waiting behind this one in the same decision. */
|
|
32
|
+
more?: number;
|
|
33
|
+
/** Set once answered: the card stays where it was and shows the answer. */
|
|
34
|
+
resolved?: string;
|
|
35
|
+
/** Labelled TEST SAMPLE on screen and never offered as urgent. */
|
|
36
|
+
sample?: boolean;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const DEFAULT_SENDER = 'Tandem';
|
|
40
|
+
|
|
41
|
+
/** A decision record as a card: the first open question, its options as the actions (the first is the recommended one). */
|
|
42
|
+
export function decisionCard(d: DecisionRecord, from: string = DEFAULT_SENDER): ThreadCard {
|
|
43
|
+
const open = d.questions.filter((q) => !d.answers.some((a) => a.n === q.n));
|
|
44
|
+
const q = open[0] ?? d.questions[0];
|
|
45
|
+
const base: ThreadCard = { id: `decision:${d.id}`, type: 'question', from, at: d.created_at, title: d.title, detail: q?.text, actions: [], ...(/^TEST SAMPLE/i.test(d.title) ? { sample: true } : {}) };
|
|
46
|
+
if (d.status === 'answered' || !open.length) {
|
|
47
|
+
return { ...base, resolved: d.answers.map((a) => a.answer).join(' · ') || 'Answered' };
|
|
48
|
+
}
|
|
49
|
+
const options = q?.options ?? [];
|
|
50
|
+
return {
|
|
51
|
+
...base,
|
|
52
|
+
actions: options.map((label, i) => ({ id: `option:${i}`, label, primary: i === 0 })),
|
|
53
|
+
freeReply: options.length === 0,
|
|
54
|
+
...(open.length > 1 ? { more: open.length - 1 } : {}),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function briefCard(b: { id: string; title: string; bullets: string[]; at: string }): ThreadCard {
|
|
59
|
+
return {
|
|
60
|
+
id: b.id, type: 'brief', from: 'Roci', at: b.at, title: b.title,
|
|
61
|
+
body: b.bullets.map((x) => `- ${x}`).join('\n'),
|
|
62
|
+
actions: [{ id: 'read', label: 'Read it aloud', primary: true }],
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The same card, answered: it keeps its place in the thread and shows the answer instead of its actions. */
|
|
67
|
+
export function resolveCard(c: ThreadCard, answer: string): ThreadCard {
|
|
68
|
+
return { ...c, actions: [], freeReply: false, more: undefined, resolved: answer };
|
|
69
|
+
}
|
|
@@ -38,3 +38,9 @@ export { ACTIVITY_QUESTION, activityOf, composeActivity, forOwner, loadActivity
|
|
|
38
38
|
export type { Activity, ActivityWindow, ActivityNote } from '../activity';
|
|
39
39
|
export { askSources, sourceOf, sourcesOfDocs } from './sources';
|
|
40
40
|
export { itemAnswer } from './item-answers';
|
|
41
|
+
export { converseView, MIC_COLORS } from './view';
|
|
42
|
+
export type { ConverseView } from './view';
|
|
43
|
+
export { ASSISTANT_NAME, normalizeAssistantName } from './roci';
|
|
44
|
+
export { structureReply } from './structure';
|
|
45
|
+
export { CARD_CHIP, DEFAULT_SENDER, briefCard, decisionCard, resolveCard } from './cards';
|
|
46
|
+
export type { CardAction, CardType, ThreadCard } from './cards';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE ASSISTANT'S NAME. It is Roci. There is no wake word: nothing listens for the name. But Quinn types it the way it
|
|
3
|
+
* sounds, "Rossi". Normalised on the way IN, before the model sees the text, so the assistant is never confused about
|
|
4
|
+
* who it is being asked. ONLY "Rossi" (whole word): Rocky, Roxy and Rosie can be real names or other words, so they are
|
|
5
|
+
* left exactly as written.
|
|
6
|
+
*/
|
|
7
|
+
export const ASSISTANT_NAME = 'Roci';
|
|
8
|
+
|
|
9
|
+
const ROSSI = /\brossi\b/gi;
|
|
10
|
+
|
|
11
|
+
export function normalizeAssistantName(text: string, name: string = ASSISTANT_NAME): string {
|
|
12
|
+
return text ? text.replace(ROSSI, name) : text;
|
|
13
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Roci's words as STRUCTURED text. The server replies in a speakable form (no markup, so it can be read aloud): one
|
|
3
|
+
* run of sentences, or "1. ... 2. ..." inline. On screen that is a wall of text. This gives it shape without changing
|
|
4
|
+
* what is said: a lead line, then short bullets. Text that already has Markdown blocks is left exactly as it is, and a
|
|
5
|
+
* short single sentence stays a sentence. Pure, so web and native share it.
|
|
6
|
+
*/
|
|
7
|
+
const BLOCK = /^\s{0,3}(#{1,6}\s|[-*+]\s|\d+[.)]\s)/m;
|
|
8
|
+
|
|
9
|
+
function clean(s: string): string {
|
|
10
|
+
return s.replace(/\s*\(\s*\)/g, '').replace(/\s+([.,;])/g, '$1').replace(/\s{2,}/g, ' ').trim();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function sentences(text: string): string[] {
|
|
14
|
+
return text.match(/[^.!?]+(?:[.!?]+(?=\s|$)|$)/g)?.map((s) => s.trim()).filter(Boolean) ?? [text];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function structureReply(text: string): string {
|
|
18
|
+
let t = clean(text ?? '');
|
|
19
|
+
// One line that starts with a bullet but holds a whole numbered run ("- Do a. 2. Do b. 3. Do c."): the bullet was item 1.
|
|
20
|
+
if (!t.includes('\n') && /^[-*+]\s+/.test(t) && /\s2\.\s/.test(t) && /\s3\.\s/.test(t)) t = `1. ${t.replace(/^[-*+]\s+/, '')}`;
|
|
21
|
+
if (!t || (t.includes('\n') && BLOCK.test(t))) return text ?? '';
|
|
22
|
+
if (!t.includes('\n') && BLOCK.test(t) && !/\s2\.\s/.test(t)) return text ?? '';
|
|
23
|
+
|
|
24
|
+
// "Lead. 1. a. 2. b. 3. c. Tail": an inline numbered run.
|
|
25
|
+
const numbered = t.split(/(?:^|\s)\d+\.\s+/);
|
|
26
|
+
if (numbered.length >= 3 && /(?:^|\s)1\.\s/.test(t) && /\s2\.\s/.test(t)) {
|
|
27
|
+
const [lead, ...rest] = numbered;
|
|
28
|
+
const tailAt = rest.length ? rest[rest.length - 1].search(/(?<=[.!?])\s+(?=[A-Z])/) : -1;
|
|
29
|
+
const last = rest[rest.length - 1];
|
|
30
|
+
const items = tailAt > -1 ? [...rest.slice(0, -1), last.slice(0, tailAt)] : rest;
|
|
31
|
+
const tail = tailAt > -1 ? last.slice(tailAt).trim() : '';
|
|
32
|
+
return [lead.trim(), items.map((i) => `- ${i.trim().replace(/[.]$/, '')}`).join('\n'), tail].filter(Boolean).join('\n\n');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const parts = sentences(t);
|
|
36
|
+
if (parts.length < 3) return t;
|
|
37
|
+
const [lead, ...rest] = parts;
|
|
38
|
+
return `${lead}\n\n${rest.map((s) => `- ${s}`).join('\n')}`;
|
|
39
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { MeetingState } from './meeting';
|
|
2
|
+
|
|
3
|
+
/** What the Talk screen shows for a meeting state; the web page and the native screen read the same flags. */
|
|
4
|
+
export interface ConverseView {
|
|
5
|
+
/** The mic is on and a conversation is running (`micOn` alone is only the preference, true before anything starts). */
|
|
6
|
+
listening: boolean;
|
|
7
|
+
thinking: boolean;
|
|
8
|
+
speaking: boolean;
|
|
9
|
+
/** The conversation is being saved. */
|
|
10
|
+
busy: boolean;
|
|
11
|
+
/** Stop is offered while a reply is being thought about or spoken. */
|
|
12
|
+
canStop: boolean;
|
|
13
|
+
/** The Voice/Text switch: which side is on. Kept for the native screen; the web page has one mic and no switch. */
|
|
14
|
+
mode: 'voice' | 'text';
|
|
15
|
+
/** The big status word: what the assistant is doing right now. */
|
|
16
|
+
status: 'READY' | 'LISTENING' | 'THINKING' | 'SPEAKING';
|
|
17
|
+
/** What the ONE mic control does when pressed: Talk (start listening), Mute (stop listening and send), Interrupt (cut the reply off). */
|
|
18
|
+
micAction: 'talk' | 'mute' | 'interrupt';
|
|
19
|
+
/** The state, carried by the mic's colour (no banner, no status text). */
|
|
20
|
+
micTone: 'idle' | 'listening' | 'thinking' | 'speaking' | 'muted';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** The mic's colour per state: the phone's mapping (drive-mode-ui ConverseScreen), lifted here so web and iOS share it. White text >= 5:1. */
|
|
24
|
+
export const MIC_COLORS = { idle: '#4F46E5', listening: '#0B6E3A', thinking: '#9A4A06', speaking: '#1D4ED8', muted: '#374151' } as const;
|
|
25
|
+
|
|
26
|
+
export function converseView(s: Pick<MeetingState, 'phase' | 'micOn'>): ConverseView {
|
|
27
|
+
const thinking = s.phase === 'thinking';
|
|
28
|
+
const speaking = s.phase === 'speaking';
|
|
29
|
+
const listening = s.micOn && (s.phase === 'listening' || thinking || speaking);
|
|
30
|
+
const busy = s.phase === 'ending';
|
|
31
|
+
const status = speaking ? 'SPEAKING' : thinking || busy ? 'THINKING' : listening ? 'LISTENING' : 'READY';
|
|
32
|
+
const micAction = thinking || speaking ? 'interrupt' : listening ? 'mute' : 'talk';
|
|
33
|
+
return { listening, thinking, speaking, busy, canStop: thinking || speaking, mode: listening ? 'voice' : 'text', status, micAction, micTone: thinking || busy ? 'thinking' : speaking ? 'speaking' : listening ? 'listening' : s.phase === 'listening' ? 'muted' : 'idle' };
|
|
34
|
+
}
|
package/src/corpus/index.ts
CHANGED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE PARTICIPANT GRAPH — who is on a record — read out of the tenant's edges
|
|
3
|
+
* (bd startsim-768w.38.18, startsim-o0o6o.2), split out of `client.ts` so that
|
|
4
|
+
* file stops growing and so the Library can ask for it AFTER the rows are up.
|
|
5
|
+
*
|
|
6
|
+
* THE ROWS DO NOT WAIT FOR THIS. It is an edge read plus a walk of the whole
|
|
7
|
+
* party roster, and on a loaded or distant backend that chain was the page: the
|
|
8
|
+
* Library's first rows sat behind relationships and then six serial roster
|
|
9
|
+
* pages (measured, 2026-11-20). `createCorpusApi` therefore lets a caller list
|
|
10
|
+
* documents WITHOUT participants and fetch them separately, and this module
|
|
11
|
+
* reads the roster's tail in PARALLEL once page one has said how long it is.
|
|
12
|
+
*/
|
|
13
|
+
import type { CorpusHttp } from './client';
|
|
14
|
+
import { MAX_ID_LIST, indexParticipants, toParty } from './entities';
|
|
15
|
+
import type { TenantEntity, TenantRelationship, CorpusTypeKeys } from './entities';
|
|
16
|
+
import type { CorpusScope, Party, PartyRef } from './types';
|
|
17
|
+
|
|
18
|
+
interface DrfPage<T> {
|
|
19
|
+
count: number;
|
|
20
|
+
next: string | null;
|
|
21
|
+
previous: string | null;
|
|
22
|
+
results: T[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface ServerFilterReport {
|
|
26
|
+
applied_filters?: string[];
|
|
27
|
+
appliedFilters?: string[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface ParticipantReaderOptions {
|
|
31
|
+
http: CorpusHttp;
|
|
32
|
+
entities: string;
|
|
33
|
+
relationships: string;
|
|
34
|
+
types: CorpusTypeKeys;
|
|
35
|
+
scope: CorpusScope;
|
|
36
|
+
participantEdges: readonly string[];
|
|
37
|
+
maxGraphPages: number;
|
|
38
|
+
graphTtlMs: number;
|
|
39
|
+
resolveParticipants: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Rows asked for per roster read; the tenant caps it, so this is a ceiling. */
|
|
43
|
+
const ROSTER_PAGE_SIZE = 100;
|
|
44
|
+
|
|
45
|
+
export function createParticipantReader(options: ParticipantReaderOptions) {
|
|
46
|
+
const {
|
|
47
|
+
http, entities, relationships, types, scope,
|
|
48
|
+
participantEdges, maxGraphPages, graphTtlMs, resolveParticipants,
|
|
49
|
+
} = options;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Every page of a DRF list, the TAIL IN PARALLEL: page one says how many rows
|
|
53
|
+
* there are, so pages two to N are asked for together instead of each waiting
|
|
54
|
+
* for the one before. Six serial roster reads were the longest chain on the
|
|
55
|
+
* Library's critical path (273 parties, 50 a page); at 100 a page and in
|
|
56
|
+
* parallel it is two round trips however long the roster gets.
|
|
57
|
+
*
|
|
58
|
+
* Falls back to the serial walk when page one does not report a usable
|
|
59
|
+
* `count`, or when the server hands back fewer rows than the page it was asked
|
|
60
|
+
* for without having said it was the last — a tenant that caps `page_size`
|
|
61
|
+
* lower than requested still walks correctly, just slower.
|
|
62
|
+
*/
|
|
63
|
+
async function readAllParallel<T>(path: string, extra: Record<string, unknown>): Promise<T[]> {
|
|
64
|
+
const first = await http.get<DrfPage<T>>(path, {
|
|
65
|
+
params: { ...extra, page: 1, page_size: ROSTER_PAGE_SIZE },
|
|
66
|
+
});
|
|
67
|
+
const rows: T[] = [...(first?.results ?? [])];
|
|
68
|
+
if (!first?.next || rows.length === 0) return rows;
|
|
69
|
+
const total = Number(first.count);
|
|
70
|
+
const per = rows.length;
|
|
71
|
+
if (!Number.isFinite(total) || total <= per) {
|
|
72
|
+
// No count to plan from: keep walking, one page after the other.
|
|
73
|
+
for (let index = 2; index <= maxGraphPages; index += 1) {
|
|
74
|
+
const response = await http.get<DrfPage<T>>(path, {
|
|
75
|
+
params: { ...extra, page: index, page_size: ROSTER_PAGE_SIZE },
|
|
76
|
+
});
|
|
77
|
+
const results = response?.results ?? [];
|
|
78
|
+
rows.push(...results);
|
|
79
|
+
if (!response?.next || results.length === 0) break;
|
|
80
|
+
}
|
|
81
|
+
return rows;
|
|
82
|
+
}
|
|
83
|
+
const last = Math.min(maxGraphPages, Math.ceil(total / per));
|
|
84
|
+
const rest = await Promise.all(
|
|
85
|
+
Array.from({ length: Math.max(0, last - 1) }, (_, offset) =>
|
|
86
|
+
http.get<DrfPage<T>>(path, {
|
|
87
|
+
params: { ...extra, page: offset + 2, page_size: ROSTER_PAGE_SIZE },
|
|
88
|
+
}),
|
|
89
|
+
),
|
|
90
|
+
);
|
|
91
|
+
for (const response of rest) rows.push(...(response?.results ?? []));
|
|
92
|
+
return rows;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// ---------------------------------------------------------------------
|
|
96
|
+
// the participant graph
|
|
97
|
+
// ---------------------------------------------------------------------
|
|
98
|
+
//
|
|
99
|
+
// THE EDGES OF THE RECORDS ON SCREEN, AND NO OTHERS (bd startsim-o0o6o.2).
|
|
100
|
+
// This used to be `readAll(relationships, {})` — every edge in the workspace,
|
|
101
|
+
// twenty pages of it, on a comment saying the endpoint had no filters. It has
|
|
102
|
+
// them: `entity__in` takes the ids of one page, bounded at `MAX_ID_LIST`,
|
|
103
|
+
// which is the shape `RelationshipQuery`'s own docstring says it exists for.
|
|
104
|
+
//
|
|
105
|
+
// ONE read for a page of records, not one per record — and cached per record,
|
|
106
|
+
// so a screen that lists, opens a row and then asks a question spends it once.
|
|
107
|
+
// It FAILS SOFT: a tenant whose relationships endpoint is missing or refused
|
|
108
|
+
// renders exactly what it rendered before this existed, rather than an error
|
|
109
|
+
// where a Library used to be.
|
|
110
|
+
let roster: { at: number; value: Promise<Party[]> } | null = null;
|
|
111
|
+
const known = new Map<string, { at: number; value: PartyRef[] }>();
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* The people an edge can point AT, read once and reused.
|
|
115
|
+
*
|
|
116
|
+
* Still a walked list, because there is no id filter on `/entities/`: the
|
|
117
|
+
* recognised set is `search`, `source`, `party`, the occurred window,
|
|
118
|
+
* `related_*`, `order` and `attr.*`, and an unrecognised `id__in` would be
|
|
119
|
+
* swept into `ignored_filters` and answered with the whole page. It is at
|
|
120
|
+
* least a TYPED read — `?type=party` is applied server-side — and it is only
|
|
121
|
+
* reached when the narrowed edge read came back with edges to resolve.
|
|
122
|
+
*/
|
|
123
|
+
function partyRoster(): Promise<Party[]> {
|
|
124
|
+
const now = Date.now();
|
|
125
|
+
if (!roster || now - roster.at > graphTtlMs) {
|
|
126
|
+
roster = {
|
|
127
|
+
at: now,
|
|
128
|
+
value: readAllParallel<TenantEntity>(entities, { type: types.party })
|
|
129
|
+
.then((rows) => rows.map((entity) => toParty(entity, scope)))
|
|
130
|
+
.catch(() => []),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
return roster.value;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* The edges touching these records, or `null` when the server did not confirm
|
|
138
|
+
* it narrowed by them.
|
|
139
|
+
*
|
|
140
|
+
* `null` IS NOT "NO EDGES", and the difference is the whole point. A fork
|
|
141
|
+
* without `RelationshipQuery` accepts `entity__in`, names it in
|
|
142
|
+
* `ignored_filters` and answers with an arbitrary page of the WHOLE edge table
|
|
143
|
+
* (bd startsim-768w.38.39) — rows that look exactly like a narrow answer and
|
|
144
|
+
* would put the wrong people, or a fraction of the right ones, on a record.
|
|
145
|
+
* start-simpli#154 settled what to do with a result the server did not
|
|
146
|
+
* confirm: do not use it. So this reports that it could not ask, and the
|
|
147
|
+
* caller renders what it rendered before the join existed.
|
|
148
|
+
*
|
|
149
|
+
* `rel_type` rides along unchecked on purpose: it only ever makes the answer
|
|
150
|
+
* SMALLER, and `indexParticipants` ranks by edge type anyway. A fork that
|
|
151
|
+
* ignores it pays in PAGES rather than in correctness — a record with many
|
|
152
|
+
* non-participant edges can push its people onto a second page, and the walk
|
|
153
|
+
* below follows `next` until it has them.
|
|
154
|
+
*/
|
|
155
|
+
async function edgesFor(recordIds: string[]): Promise<TenantRelationship[] | null> {
|
|
156
|
+
const rows: TenantRelationship[] = [];
|
|
157
|
+
for (let start = 0; start < recordIds.length; start += MAX_ID_LIST) {
|
|
158
|
+
// CHUNKED, because `_uuid_list` answers a longer list with a 400 rather
|
|
159
|
+
// than truncating it. Truncating here instead would drop the people off
|
|
160
|
+
// the tail of a wide page silently, which is the failure being undone.
|
|
161
|
+
const chunk = recordIds.slice(start, start + MAX_ID_LIST);
|
|
162
|
+
const extra: Record<string, unknown> = {
|
|
163
|
+
entity__in: chunk.join(','),
|
|
164
|
+
page_size: MAX_ID_LIST,
|
|
165
|
+
};
|
|
166
|
+
if (participantEdges.length) extra.rel_type = participantEdges.join(',');
|
|
167
|
+
for (let index = 1; index <= maxGraphPages; index += 1) {
|
|
168
|
+
const response = await http.get<DrfPage<TenantRelationship> & ServerFilterReport>(
|
|
169
|
+
relationships,
|
|
170
|
+
{ params: { ...extra, page: index } },
|
|
171
|
+
);
|
|
172
|
+
const applied = response.applied_filters ?? response.appliedFilters;
|
|
173
|
+
if (!applied?.includes('entity__in')) return null;
|
|
174
|
+
const results = response.results ?? [];
|
|
175
|
+
rows.push(...results);
|
|
176
|
+
if (!response.next || results.length === 0) break;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return rows;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
async function participantsFor(
|
|
183
|
+
records: Array<string | number>,
|
|
184
|
+
): Promise<Map<string, PartyRef[]>> {
|
|
185
|
+
const out = new Map<string, PartyRef[]>();
|
|
186
|
+
if (!resolveParticipants) return out;
|
|
187
|
+
const now = Date.now();
|
|
188
|
+
const wanted: string[] = [];
|
|
189
|
+
for (const record of records) {
|
|
190
|
+
const id = String(record ?? '').trim();
|
|
191
|
+
if (!id || out.has(id) || wanted.includes(id)) continue;
|
|
192
|
+
const cached = known.get(id);
|
|
193
|
+
if (cached && now - cached.at <= graphTtlMs) out.set(id, cached.value);
|
|
194
|
+
else wanted.push(id);
|
|
195
|
+
}
|
|
196
|
+
if (wanted.length === 0) return out;
|
|
197
|
+
try {
|
|
198
|
+
const edges = await edgesFor(wanted);
|
|
199
|
+
// Could not ask. Nothing is cached, so the next page asks again rather
|
|
200
|
+
// than remembering an answer that was never given.
|
|
201
|
+
if (!edges) return out;
|
|
202
|
+
const parties = edges.length ? await partyRoster() : [];
|
|
203
|
+
const indexed = edges.length
|
|
204
|
+
? indexParticipants(edges, parties, participantEdges)
|
|
205
|
+
: new Map<string, PartyRef[]>();
|
|
206
|
+
for (const id of wanted) {
|
|
207
|
+
// A record the server confirmed has no participant edges is REMEMBERED
|
|
208
|
+
// as having none — otherwise every page re-asks for the same silence.
|
|
209
|
+
const people = indexed.get(id) ?? [];
|
|
210
|
+
known.set(id, { at: now, value: people });
|
|
211
|
+
out.set(id, people);
|
|
212
|
+
}
|
|
213
|
+
} catch {
|
|
214
|
+
// The Library renders without its Parties block rather than not at all.
|
|
215
|
+
}
|
|
216
|
+
return out;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return { participantsFor };
|
|
220
|
+
}
|