@startsimpli/integrations 0.2.183 → 0.2.185

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.
@@ -0,0 +1,43 @@
1
+ /**
2
+ * What is SAID aloud for a long answer (Quinn: short, like a meeting). The full answer stays on the screen; the voice says
3
+ * the first three items and "and N more", or the first sentences and "The rest is on your screen." Short answers are
4
+ * said whole (this returns undefined).
5
+ */
6
+ const WORDS = (s: string) => s.trim().split(/\s+/).filter(Boolean);
7
+ const SPOKEN_MAX_WORDS = 45;
8
+ const LIST_AT = 4;
9
+
10
+ const finish = (s: string) => s.replace(/\s+/g, ' ').trim().replace(/[,;:]+$/, '');
11
+ const endWithStop = (s: string) => (/[.!?]$/.test(s) ? s : `${s}.`);
12
+
13
+ export function spokenSummary(answer: string): string | undefined {
14
+ const text = answer.replace(/\s+/g, ' ').trim();
15
+ if (!text) return undefined;
16
+
17
+ // A numbered list: "Today: 1. A 2. B 3. C 4. D" -> the lead-in, the first three, "and 1 more".
18
+ const markers = [...text.matchAll(/(?:^|\s)(\d{1,2})[.)]\s+(?=\S)/g)];
19
+ if (markers.length >= LIST_AT && markers[0][1] === '1') {
20
+ const first = markers[0].index ?? 0;
21
+ const intro = finish(text.slice(0, first));
22
+ const items = markers.map((m, i) => finish(text.slice((m.index ?? 0) + m[0].length, markers[i + 1]?.index ?? text.length)).replace(/[.]+$/, ''));
23
+ const head = items.slice(0, 3).map((x) => endWithStop(x)).join(' ');
24
+ return `${intro ? `${endWithStop(intro)} ` : ''}${head} And ${items.length - 3} more.`;
25
+ }
26
+
27
+ const words = WORDS(text);
28
+ if (words.length <= SPOKEN_MAX_WORDS) return undefined;
29
+
30
+ // Prose: whole sentences up to the limit; if the first sentence alone is too long (a list run together with commas), cut it at a comma.
31
+ const sentences = text.match(/[^.!?]+[.!?]+(?:\s|$)|[^.!?]+$/g)?.map((s) => s.trim()).filter(Boolean) ?? [text];
32
+ let spoken = '';
33
+ for (const s of sentences) {
34
+ if (WORDS(`${spoken} ${s}`).length > SPOKEN_MAX_WORDS) break;
35
+ spoken = `${spoken} ${s}`.trim();
36
+ }
37
+ if (!spoken) {
38
+ const cut = words.slice(0, 38).join(' ');
39
+ const at = Math.max(cut.lastIndexOf(','), cut.lastIndexOf(';'));
40
+ spoken = endWithStop(finish(at > 15 ? cut.slice(0, at) : cut));
41
+ }
42
+ return `${spoken} The rest is on your screen.`;
43
+ }
@@ -30,6 +30,7 @@ function toRecord(entity: TenantEntity): ConversationRecord {
30
30
  ...(d.summary ? { summary: text(d.summary) } : {}),
31
31
  ...(d.asks ? { asks: list(d.asks) } : {}),
32
32
  ...(d.decisions ? { decisions: list(d.decisions) } : {}),
33
+ ...(d.briefing && typeof d.briefing === 'object' ? { briefing: d.briefing as ConversationRecord['briefing'] } : {}),
33
34
  };
34
35
  }
35
36
 
@@ -68,6 +69,7 @@ export function createEntityConversationStore(http: ConverseDeps['http'], ownerS
68
69
  ...(record.summary ? { summary: record.summary } : {}),
69
70
  ...(record.asks ? { asks: record.asks } : {}),
70
71
  ...(record.decisions ? { decisions: record.decisions } : {}),
72
+ briefing: record.briefing ?? null,
71
73
  },
72
74
  });
73
75
  return { ...record, id: String(row.id) };
@@ -15,6 +15,15 @@ export function renderTranscript(record: Pick<ConversationRecord, 'turns' | 'sta
15
15
  return lines.join('\n').trim();
16
16
  }
17
17
 
18
+ /**
19
+ * What End pulls asks and decisions out of: ONLY what the person said. The assistant's own replies are left out, because a reply
20
+ * that lists his to-dos ("Yesterday you added: A, B, C") read as him asking for A, B and C, and they were filed as new to-dos.
21
+ */
22
+ export function renderWhatHeSaid(record: Pick<ConversationRecord, 'turns'>): string {
23
+ const said = record.turns.filter((t) => t.from !== 'relay' && t.user.text.trim()).map((t) => `- ${t.user.text.trim()}`);
24
+ return ['## What he said', ...said].join('\n');
25
+ }
26
+
18
27
  export function titleFor(startedAt: string, firstWords: string): string {
19
28
  const day = startedAt.slice(0, 10);
20
29
  const words = firstWords.replace(/\s+/g, ' ').trim().split(' ').slice(0, 7).join(' ');
@@ -54,6 +54,8 @@ export interface ConversationRecord {
54
54
  summary?: string;
55
55
  asks?: string[];
56
56
  decisions?: string[];
57
+ /** A briefing in progress: the queue of items and the one being asked. */
58
+ briefing?: BriefingState;
57
59
  }
58
60
 
59
61
  export interface ConversationStore {
@@ -63,7 +65,11 @@ export interface ConversationStore {
63
65
  }
64
66
 
65
67
  /** What the assistant works out for one utterance. */
68
+ import type { BriefingState } from './briefing-queue';
69
+
66
70
  export interface ConverseBrainInput {
71
+ /** A briefing in progress (the queue and where it is), kept on the conversation; the next answer belongs to it. */
72
+ briefing?: BriefingState | null;
67
73
  utterance: string;
68
74
  history: HistoryLine[];
69
75
  timeZone: string;
@@ -76,6 +82,12 @@ export interface ConverseBrainOutput {
76
82
  did?: string[];
77
83
  /** The utterance is an instruction for the relay: the turn is marked so the relay's poll finds it. */
78
84
  forRelay?: boolean;
85
+ /** What the voice says when it is shorter than `text` (a long list: three items and "and N more"); the screen shows `text` whole. */
86
+ spoken?: string;
87
+ /** What the relay is told when this turn is for it, instead of the raw words (an answer to a briefing item names the item). */
88
+ relayText?: string;
89
+ /** The briefing after this turn: null = over; absent = unchanged. */
90
+ briefing?: BriefingState | null;
79
91
  /** Milliseconds spent in each step of the brain (items, intent, route, ask...): measured, never spoken. */
80
92
  timings?: Record<string, number>;
81
93
  }