@startsimpli/integrations 0.2.187 → 0.2.189
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 +5 -5
- package/src/__tests__/connection-reconnect.test.tsx +69 -0
- package/src/__tests__/converse-brain.test.ts +44 -0
- package/src/__tests__/converse-meeting.test.ts +118 -0
- package/src/__tests__/converse-page.test.tsx +150 -83
- package/src/__tests__/converse.test.ts +32 -0
- package/src/__tests__/corpus-tracker.test.tsx +37 -35
- package/src/__tests__/plan-shell.test.tsx +14 -11
- package/src/__tests__/possibly-done-extract.test.ts +90 -0
- package/src/__tests__/possibly-done-ui.test.tsx +80 -0
- package/src/components/pages/ConversePage.tsx +128 -83
- package/src/components/pages/TaskDetailPage.tsx +22 -0
- package/src/components/pages/TrackerPage.tsx +15 -141
- package/src/components/pages/connections/ConnectionCard.tsx +20 -0
- package/src/components/pages/connections/bound-api.ts +2 -0
- package/src/components/pages/converse/Thread.tsx +46 -0
- package/src/components/pages/converse/browserIO.ts +15 -5
- package/src/components/pages/home/CompactItemRow.tsx +4 -1
- package/src/components/pages/plan/TalkPage.tsx +8 -29
- package/src/components/pages/tracker/PossiblyDone.tsx +49 -0
- package/src/corpus/client.ts +2 -0
- package/src/corpus/commitments.ts +27 -6
- package/src/corpus/converse/brain.ts +24 -16
- package/src/corpus/converse/handle.ts +24 -2
- package/src/corpus/converse/index.ts +2 -1
- package/src/corpus/converse/meeting.ts +70 -21
- package/src/corpus/converse/route.ts +4 -3
- package/src/corpus/converse/sources.ts +17 -0
- package/src/corpus/converse/types.ts +19 -0
- package/src/corpus/entities.ts +4 -0
- package/src/corpus/nav-copy.ts +3 -3
- package/src/corpus/possibly-done.ts +59 -0
- package/src/corpus/types.ts +17 -1
- package/src/native/converse/ConverseScreen.tsx +101 -78
- package/src/native/converse/__tests__/liveScreen.test.tsx +46 -13
- package/src/native/converse/io.ts +2 -1
- package/src/native/talk/TalkTab.tsx +15 -24
- package/src/native/talk/__tests__/talk-tab.test.tsx +8 -21
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/** The thread: every line of the one conversation, in order. Plain list in normal flow: nothing is ever laid over it. */
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
|
|
4
|
+
import type { MeetingLine } from '../../../corpus/converse/meeting';
|
|
5
|
+
|
|
6
|
+
export type ThreadSlot = 'bubbleUser' | 'bubbleReply' | 'muted' | 'chip' | 'replay';
|
|
7
|
+
|
|
8
|
+
export interface ThreadProps {
|
|
9
|
+
lines: MeetingLine[];
|
|
10
|
+
cx: (slot: ThreadSlot) => string;
|
|
11
|
+
/** Plays one assistant line's audio again; absent when the line has no sound. */
|
|
12
|
+
canReplay: (line: MeetingLine) => boolean;
|
|
13
|
+
onReplay: (line: MeetingLine) => void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const WHO: Record<MeetingLine['role'], string> = { user: 'You: ', assistant: 'Tandem: ', relay: 'Relay: ', system: '' };
|
|
17
|
+
|
|
18
|
+
export function Thread({ lines, cx, canReplay, onReplay }: ThreadProps) {
|
|
19
|
+
return (
|
|
20
|
+
<ol className="space-y-2" aria-label="Conversation" data-testid="converse-thread">
|
|
21
|
+
{lines.map((line, i) => (
|
|
22
|
+
<li
|
|
23
|
+
key={i}
|
|
24
|
+
data-from={line.role}
|
|
25
|
+
data-intent={line.intent}
|
|
26
|
+
className={line.role === 'user' ? cx('bubbleUser') : line.role === 'system' ? cx('muted') : cx('bubbleReply')}
|
|
27
|
+
>
|
|
28
|
+
{line.role === 'system' ? null : <span className={line.role === 'relay' ? 'mr-1 font-medium' : 'sr-only'}>{WHO[line.role]}</span>}
|
|
29
|
+
<span>{line.text}</span>
|
|
30
|
+
{line.role === 'assistant' && canReplay(line) ? (
|
|
31
|
+
<button type="button" className={`${cx('replay')} ml-2 align-middle`} aria-label="Play this reply" title="Play this reply" onClick={() => onReplay(line)}>
|
|
32
|
+
<svg aria-hidden="true" viewBox="0 0 24 24" width="16" height="16" fill="currentColor"><path d="M3 9v6h4l5 5V4L7 9H3zm13.5 3a4.5 4.5 0 0 0-2.5-4v8a4.5 4.5 0 0 0 2.5-4z" /></svg>
|
|
33
|
+
</button>
|
|
34
|
+
) : null}
|
|
35
|
+
{line.role === 'assistant' && line.sources?.length ? (
|
|
36
|
+
<ul className="mt-1 flex flex-wrap gap-1" aria-label="Sources">
|
|
37
|
+
{line.sources.map((s, k) => (
|
|
38
|
+
<li key={`${s.id}-${k}`} className={cx('chip')} data-testid="converse-source" title={s.id}>{s.kind}: {s.title}</li>
|
|
39
|
+
))}
|
|
40
|
+
</ul>
|
|
41
|
+
) : null}
|
|
42
|
+
</li>
|
|
43
|
+
))}
|
|
44
|
+
</ol>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
@@ -36,6 +36,8 @@ export interface BrowserIOOptions {
|
|
|
36
36
|
export interface BrowserMeetingIO extends MeetingIO {
|
|
37
37
|
/** Call inside the Start tap: opens the mic, resumes audio, unlocks playback. Throws a readable Error. */
|
|
38
38
|
open(): Promise<void>;
|
|
39
|
+
/** Call inside a tap: makes the reply player ready WITHOUT opening the microphone, so typed messages can be read aloud. */
|
|
40
|
+
unlockPlayback?(): void;
|
|
39
41
|
close(): void;
|
|
40
42
|
/** Changes the speed of the reply that is playing now, too. */
|
|
41
43
|
setSpeed(speed: number): void;
|
|
@@ -78,11 +80,18 @@ export function createBrowserMeetingIO(options: BrowserIOOptions = {}): BrowserM
|
|
|
78
80
|
return options.recorderFactory ? options.recorderFactory(s, mimeType) : new MediaRecorder(s, mimeType ? { mimeType } : undefined);
|
|
79
81
|
};
|
|
80
82
|
|
|
83
|
+
const unlock = () => {
|
|
84
|
+
if (audio) return;
|
|
85
|
+
audio = options.createAudio ? options.createAudio() : new Audio();
|
|
86
|
+
audio.src = SILENCE_WAV;
|
|
87
|
+
void audio.play()?.catch(() => undefined);
|
|
88
|
+
};
|
|
89
|
+
|
|
81
90
|
return {
|
|
91
|
+
unlockPlayback: unlock,
|
|
92
|
+
|
|
82
93
|
async open() {
|
|
83
|
-
|
|
84
|
-
audio.src = SILENCE_WAV;
|
|
85
|
-
void audio.play()?.catch(() => undefined);
|
|
94
|
+
unlock();
|
|
86
95
|
const devices = options.mediaDevices ?? navigator.mediaDevices;
|
|
87
96
|
if (!devices?.getUserMedia) {
|
|
88
97
|
throw new Error(typeof window !== 'undefined' && !window.isSecureContext ? 'The microphone needs a secure (https) page.' : 'This browser cannot record audio.');
|
|
@@ -106,7 +115,7 @@ export function createBrowserMeetingIO(options: BrowserIOOptions = {}): BrowserM
|
|
|
106
115
|
lock = null;
|
|
107
116
|
stream?.getTracks().forEach((t) => t.stop());
|
|
108
117
|
audio?.pause();
|
|
109
|
-
meter = null; stream = null;
|
|
118
|
+
meter = null; stream = null; audio = null;
|
|
110
119
|
},
|
|
111
120
|
|
|
112
121
|
listen(signal, config: MeetingConfig) {
|
|
@@ -131,7 +140,8 @@ export function createBrowserMeetingIO(options: BrowserIOOptions = {}): BrowserM
|
|
|
131
140
|
recorder.onstop = () => then(new Blob(chunks, { type: recorder.mimeType || 'audio/webm' }));
|
|
132
141
|
if (recorder.state !== 'inactive') recorder.stop(); else recorder.onstop?.(new Event('stop'));
|
|
133
142
|
};
|
|
134
|
-
|
|
143
|
+
// Aborted with reason 'finish' (the mic button): if he was speaking, send what was recorded; otherwise just stop.
|
|
144
|
+
const onAbort = () => (signal.reason === 'finish' && speaking ? stopRecorder((blob) => finish(blob)) : stopRecorder(() => finish(null, true)));
|
|
135
145
|
signal.addEventListener('abort', onAbort);
|
|
136
146
|
|
|
137
147
|
const timer = setTimer(() => {
|
|
@@ -35,11 +35,13 @@ export interface CompactItemRowProps {
|
|
|
35
35
|
showStatus?: boolean;
|
|
36
36
|
/** The due date is Tandem's guess, not confirmed: drawn lighter, never as a warning. */
|
|
37
37
|
guessedDue?: boolean;
|
|
38
|
+
/** Extra content under the title (e.g. a "Possibly done" note). */
|
|
39
|
+
below?: React.ReactNode;
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
const CHIP = 'inline-flex max-w-[14rem] items-center truncate rounded-full border border-gray-200 bg-gray-50 px-2 py-0.5 text-xs text-gray-700';
|
|
41
43
|
|
|
42
|
-
export function CompactItemRow({ item, days, due, project, trackerName, onOpen, actions, showStatus = true, guessedDue }: CompactItemRowProps) {
|
|
44
|
+
export function CompactItemRow({ item, days, due, project, trackerName, onOpen, actions, showStatus = true, guessedDue, below }: CompactItemRowProps) {
|
|
43
45
|
const late = days !== null && days < 0 && item.status !== 'done';
|
|
44
46
|
const label = dueLabel(days, due);
|
|
45
47
|
return (
|
|
@@ -53,6 +55,7 @@ export function CompactItemRow({ item, days, due, project, trackerName, onOpen,
|
|
|
53
55
|
{item.status === 'blocked' && item.statusReason ? (
|
|
54
56
|
<span className="block truncate text-xs text-gray-500">Blocked: {item.statusReason}</span>
|
|
55
57
|
) : null}
|
|
58
|
+
{below}
|
|
56
59
|
</div>
|
|
57
60
|
<div className="flex shrink-0 items-center gap-2">
|
|
58
61
|
{project ? <span className={CHIP} title={project}>{project}</span> : null}
|
|
@@ -1,48 +1,27 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* TALK:
|
|
5
|
-
*
|
|
6
|
-
* Ask (a question, answered with the sources it came from). Each mode is the existing
|
|
7
|
-
* composer, mounted by the host; this file only owns the toggle and the one-line subtitle.
|
|
4
|
+
* TALK: ONE screen for the conversation with Tandem: to-dos, questions, plans, the relay and voice notes, in one thread.
|
|
5
|
+
* No modes. The host mounts the `ConversePage`; this file only adds the one-line subtitle.
|
|
8
6
|
*/
|
|
9
7
|
import * as React from 'react';
|
|
10
8
|
|
|
11
|
-
import {
|
|
9
|
+
import { TAB_COPY } from '../../../corpus/nav-copy';
|
|
12
10
|
|
|
13
11
|
export interface TalkPageProps {
|
|
14
|
-
mode: TalkMode;
|
|
15
|
-
onModeChange: (mode: TalkMode) => void;
|
|
16
12
|
/** The `ConversePage`. */
|
|
17
13
|
talk: React.ReactNode;
|
|
18
|
-
|
|
19
|
-
ask: React.ReactNode;
|
|
20
|
-
classNames?: Partial<Record<'root' | 'tabs' | 'tab' | 'tabActive' | 'subtitle', string>>;
|
|
14
|
+
classNames?: Partial<Record<'root' | 'subtitle', string>>;
|
|
21
15
|
}
|
|
22
16
|
|
|
23
|
-
const DEFAULTS = {
|
|
24
|
-
root: 'space-y-4',
|
|
25
|
-
tabs: 'inline-flex overflow-hidden rounded-md border border-gray-300',
|
|
26
|
-
tab: 'px-4 py-1.5 text-sm text-gray-700',
|
|
27
|
-
tabActive: 'bg-gray-900 px-4 py-1.5 text-sm text-white',
|
|
28
|
-
subtitle: 'text-sm text-gray-500',
|
|
29
|
-
};
|
|
17
|
+
const DEFAULTS = { root: 'space-y-3', subtitle: 'text-sm text-gray-500' };
|
|
30
18
|
|
|
31
|
-
export function TalkPage({
|
|
19
|
+
export function TalkPage({ talk, classNames = {} }: TalkPageProps) {
|
|
32
20
|
const cn = { ...DEFAULTS, ...classNames };
|
|
33
|
-
const current = TALK_MODES.find((m) => m.key === mode) ?? TALK_MODES[0];
|
|
34
21
|
return (
|
|
35
22
|
<div className={cn.root}>
|
|
36
|
-
<
|
|
37
|
-
|
|
38
|
-
<button
|
|
39
|
-
key={m.key} type="button" role="tab" aria-selected={m.key === current.key}
|
|
40
|
-
className={m.key === current.key ? cn.tabActive : cn.tab} onClick={() => onModeChange(m.key)}
|
|
41
|
-
>{m.label}</button>
|
|
42
|
-
))}
|
|
43
|
-
</div>
|
|
44
|
-
<p className={cn.subtitle} data-testid="talk-mode-subtitle">{current.subtitle}</p>
|
|
45
|
-
{current.key === 'ask' ? ask : talk}
|
|
23
|
+
<p className={cn.subtitle} data-testid="talk-mode-subtitle">{TAB_COPY.talk.subtitle}</p>
|
|
24
|
+
{talk}
|
|
46
25
|
</div>
|
|
47
26
|
);
|
|
48
27
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* "Possibly done: <statement> (<meeting>, <date>)" with Mark done / Not done,
|
|
3
|
+
* drawn on the to-do the statement was matched to. Presentational: the host
|
|
4
|
+
* owns the two writes. Nothing here closes anything by itself.
|
|
5
|
+
*/
|
|
6
|
+
import * as React from 'react';
|
|
7
|
+
|
|
8
|
+
import { stripMarkdown } from '../../Markdown';
|
|
9
|
+
import { dismissCandidate, pendingCandidates } from '../../../corpus/possibly-done';
|
|
10
|
+
import type { Commitment, PossiblyDone } from '../../../corpus/types';
|
|
11
|
+
|
|
12
|
+
const BTN = 'rounded border border-gray-300 px-2 py-0.5 text-xs text-gray-700 hover:border-gray-400';
|
|
13
|
+
|
|
14
|
+
/** The patch that closes the item on the strength of this meeting statement. */
|
|
15
|
+
export const markDonePatch = (candidate: PossiblyDone) => ({
|
|
16
|
+
status: 'done' as const,
|
|
17
|
+
statusReason: candidate.quote,
|
|
18
|
+
resolvedAt: new Date().toISOString(),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
/** The patch that remembers this meeting's statement was rejected. */
|
|
22
|
+
export const notDonePatch = (item: Commitment, candidate: PossiblyDone) => ({
|
|
23
|
+
possiblyDone: dismissCandidate(item.possiblyDone, candidate.documentId),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export function PossiblyDoneNote({ item, onMarkDone, onNotDone, disabled }: {
|
|
27
|
+
item: Commitment;
|
|
28
|
+
onMarkDone: (item: Commitment, candidate: PossiblyDone) => void;
|
|
29
|
+
onNotDone: (item: Commitment, candidate: PossiblyDone) => void;
|
|
30
|
+
disabled?: boolean;
|
|
31
|
+
}) {
|
|
32
|
+
if (item.status === 'done' || item.status === 'dropped') return null;
|
|
33
|
+
const pending = pendingCandidates(item.possiblyDone);
|
|
34
|
+
if (!pending.length) return null;
|
|
35
|
+
return (
|
|
36
|
+
<div className="mt-1 space-y-1" data-testid="possibly-done">
|
|
37
|
+
{pending.map((c) => (
|
|
38
|
+
<div key={c.documentId} className="flex flex-wrap items-center gap-2 text-xs text-amber-900">
|
|
39
|
+
<span className="min-w-0">
|
|
40
|
+
<span className="font-medium">Possibly done:</span> “{stripMarkdown(c.quote)}”
|
|
41
|
+
{' '}({[c.documentTitle || 'meeting', c.at ? new Date(c.at).toLocaleDateString() : ''].filter(Boolean).join(', ')})
|
|
42
|
+
</span>
|
|
43
|
+
<button type="button" className={BTN} disabled={disabled} onClick={() => onMarkDone(item, c)}>Mark done</button>
|
|
44
|
+
<button type="button" className={BTN} disabled={disabled} onClick={() => onNotDone(item, c)}>Not done</button>
|
|
45
|
+
</div>
|
|
46
|
+
))}
|
|
47
|
+
</div>
|
|
48
|
+
);
|
|
49
|
+
}
|
package/src/corpus/client.ts
CHANGED
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
* second copy of the graph that will drift; the edge is the declared contract,
|
|
31
31
|
* so the edge is what is read. The join is cached, bounded and fails soft.
|
|
32
32
|
*/
|
|
33
|
+
import { writePossiblyDone } from './possibly-done';
|
|
33
34
|
import { patchEditedItem } from './commitment-edit';
|
|
34
35
|
import { readStandings } from './standings';
|
|
35
36
|
import { createTimelineReader } from './tracker-timeline-client';
|
|
@@ -1451,6 +1452,7 @@ export function createPlanningApi(options: CreateCorpusApiOptions): PlanningApi
|
|
|
1451
1452
|
// an edit to an already-done item, never over a value the caller sent):
|
|
1452
1453
|
// the Tracker timeline's "done per day" reads this.
|
|
1453
1454
|
else if (patch.status === 'done' && item.status !== 'done') wire.resolved_at = new Date((options.now ?? Date.now)()).toISOString();
|
|
1455
|
+
if (patch.possiblyDone !== undefined) wire.possibly_done = writePossiblyDone(patch.possiblyDone);
|
|
1454
1456
|
// `null` clears the mark: the tenant reads anything but 'private' as shared.
|
|
1455
1457
|
if (patch.visibility !== undefined) {
|
|
1456
1458
|
wire.visibility = patch.visibility ?? '';
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
* no-op rather than a doubling, and it is why `mention_count` is trustworthy
|
|
38
38
|
* enough to sort by.
|
|
39
39
|
*/
|
|
40
|
+
import { withCandidate } from './possibly-done';
|
|
40
41
|
import { jaccard, tokenize } from './text';
|
|
41
42
|
import type {
|
|
42
43
|
Commitment,
|
|
@@ -86,6 +87,14 @@ const UNANCHORED_MERGE_THRESHOLD = 0.7;
|
|
|
86
87
|
*/
|
|
87
88
|
const RESOLVE_THRESHOLD = 0.45;
|
|
88
89
|
|
|
90
|
+
/**
|
|
91
|
+
* The lowest wording overlap at which a statement is kept on an item as "possibly
|
|
92
|
+
* done". Below it the match is one shared stem ("planning" in a trip that was
|
|
93
|
+
* cancelled vs. "plan the offsite", 0.11) and attaching it would put a wrong
|
|
94
|
+
* claim on a to-do; at the weak end of real hits it is 0.25-0.3.
|
|
95
|
+
*/
|
|
96
|
+
export const CANDIDATE_FLOOR = 0.2;
|
|
97
|
+
|
|
89
98
|
/** With no subject to anchor on, the wording has to carry the whole claim. */
|
|
90
99
|
const UNANCHORED_RESOLVE_THRESHOLD = 0.7;
|
|
91
100
|
|
|
@@ -477,11 +486,19 @@ export function applyResolutions(
|
|
|
477
486
|
} else {
|
|
478
487
|
// ONE review row per claim — its single best candidate. Listing every open
|
|
479
488
|
// item on the matter would bury the one that matters.
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
489
|
+
const quote = claim.quote || claim.statement;
|
|
490
|
+
needsReview.push({ commitmentId: best.commitment.externalId, documentId: claim.documentId, quote });
|
|
491
|
+
// ...and the same statement is kept ON that item, to be confirmed there.
|
|
492
|
+
// A statement that matched nothing never reaches this branch: dropped.
|
|
493
|
+
if (best.score >= CANDIDATE_FLOOR) {
|
|
494
|
+
const next = withCandidate(best.commitment.possiblyDone, {
|
|
495
|
+
quote, documentId: claim.documentId, documentTitle: document.title || '', at, state: 'pending',
|
|
496
|
+
});
|
|
497
|
+
if (next) {
|
|
498
|
+
best.commitment.possiblyDone = next;
|
|
499
|
+
touched.add(best.commitment.externalId);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
485
502
|
}
|
|
486
503
|
}
|
|
487
504
|
|
|
@@ -491,7 +508,11 @@ export function applyResolutions(
|
|
|
491
508
|
// ---------------------------------------------------------------------------
|
|
492
509
|
|
|
493
510
|
function cloneCommitment(commitment: Commitment): Commitment {
|
|
494
|
-
return {
|
|
511
|
+
return {
|
|
512
|
+
...commitment,
|
|
513
|
+
mentions: commitment.mentions.map((mention) => ({ ...mention })),
|
|
514
|
+
...(commitment.possiblyDone ? { possiblyDone: commitment.possiblyDone.map((c) => ({ ...c })) } : {}),
|
|
515
|
+
};
|
|
495
516
|
}
|
|
496
517
|
|
|
497
518
|
function unique(values: string[]): string[] {
|
|
@@ -18,10 +18,11 @@ import type { BriefingItem } from '../briefing/types';
|
|
|
18
18
|
import { FLEET_FRESH_MS, ageWords } from './fleet';
|
|
19
19
|
import { routeUtterance } from './route';
|
|
20
20
|
import { spokenSummary } from './spoken-summary';
|
|
21
|
+
import { sourcesOfDocs } from './sources';
|
|
21
22
|
import { ACTIVITY_QUESTION, composeActivity, forOwner, type Activity, type ActivityWindow } from '../activity';
|
|
22
23
|
import { questionWindow } from '../ask-items-intent';
|
|
23
24
|
import { BRIEF_ME, NEEDS_ME, buildQueue, firstPrompt, relayItemsFrom, stepBriefing, type BriefingEffect, type BriefingState } from './briefing-queue';
|
|
24
|
-
import type { ConverseBrain, HistoryLine } from './types';
|
|
25
|
+
import type { ConverseBrain, ConverseSource, HistoryLine } from './types';
|
|
25
26
|
|
|
26
27
|
const MIN_AUTO = 0.85;
|
|
27
28
|
/** A spoken answer is read in full, but not forever. */
|
|
@@ -38,7 +39,7 @@ export interface ConverseBrainDeps {
|
|
|
38
39
|
/** What happened in a calendar window (to-dos finished or added, conversations, notes): "what did I do yesterday". Omit: those go to Ask. */
|
|
39
40
|
loadActivity?(window: ActivityWindow, timeZone: string): Promise<Activity>;
|
|
40
41
|
/** Answers a question over the person's items, notes and documents; the app wires `askCorpus`. */
|
|
41
|
-
ask(input: { question: string; timeZone: string; now: number }): Promise<{ answer: string; status?: string }>;
|
|
42
|
+
ask(input: { question: string; timeZone: string; now: number }): Promise<{ answer: string; status?: string; sources?: ConverseSource[] }>;
|
|
42
43
|
minAutoConfidence?: number;
|
|
43
44
|
/** Sorts a line into work for the relay / a fleet-status question / other. Omit: everything not an item edit goes to Ask. */
|
|
44
45
|
routeLlm?: BriefingScriptLlm | null;
|
|
@@ -62,6 +63,9 @@ const SMALL_TALK: Array<[RegExp, string]> = [
|
|
|
62
63
|
/** What a fleet-status question is about: the agents, sessions, lanes, the relay, what is blocked or shipping. */
|
|
63
64
|
export const FLEET_WORDS = /\b(agents?|sessions?|fleet|lanes?|relay|bridge|blocked|blocker|shipping|shipped|deploy(?:ed|ing|s)?|prs?|pull requests?|status|working on|up to)\b/i;
|
|
64
65
|
|
|
66
|
+
/** Wrapping up, said short: nothing else in the line. */
|
|
67
|
+
export const WRAP_UP = /^(?:(?:ok(?:ay)?|alright|all right|so)[, ]+)?(?:(?:please |just |go ahead and )?(?:parse|file|save|process|wrap up|wrap|finish|close)(?: out)?(?: that| this| the| my| it| up)*(?: note| notes| conversation| thing)?|that'?s (?:it|all|everything)|that is (?:it|all|everything)|i'?m (?:done|finished)|i am (?:done|finished)|we'?re (?:done|finished)|done|all done|end (?:the )?(?:note|conversation))\W*$/i;
|
|
68
|
+
|
|
65
69
|
/** A who/what/when/where/why/how question, or "tell/show/give me": answered, never acted on as an item edit. */
|
|
66
70
|
const ASKING = /^(what|what's|whats|how|when|where|who|why|which|tell me|give me|show me)\b/i;
|
|
67
71
|
|
|
@@ -129,12 +133,14 @@ export function createConverseBrain(deps: ConverseBrainDeps): ConverseBrain {
|
|
|
129
133
|
const route = await (early ?? timed('route', () => routeUtterance(deps.routeLlm, utterance, recent)));
|
|
130
134
|
// A question about his own to-dos, notes or dates ("is the to-do ... overdue?") is never an order for the relay, whatever the model says;
|
|
131
135
|
// an order needs the relay's name or a line that is not a question.
|
|
132
|
-
if (route === 'work') return QUESTION.test(utterance.trim()) && !ADDRESSES_RELAY.test(utterance) ? null : { text: PASSED_TO_RELAY, forRelay: true };
|
|
136
|
+
if (route === 'work') return QUESTION.test(utterance.trim()) && !ADDRESSES_RELAY.test(utterance) ? null : { text: PASSED_TO_RELAY, forRelay: true, intent: 'relay' as const };
|
|
137
|
+
// A plan or thoughts out loud (no question, nothing for the relay): kept in the conversation, acknowledged in two words.
|
|
138
|
+
if (route === 'note') return QUESTION.test(utterance.trim()) || ADDRESSES_RELAY.test(utterance) ? null : { text: 'Got it.', intent: 'note' as const };
|
|
133
139
|
// The routing model sometimes sends "What is on my plate today?" to the fleet snapshot (seen 1 in 2 on the real model).
|
|
134
140
|
// A fleet-status answer is only right when the words are about the fleet, so a status route without them is not trusted.
|
|
135
141
|
if (route !== 'status' || !FLEET_WORDS.test(utterance)) return null;
|
|
136
142
|
const snap = await timed('fleet', async () => deps.loadFleetStatus?.().catch(() => null));
|
|
137
|
-
if (!snap) return { text: NO_FLEET_STATUS, forRelay: true };
|
|
143
|
+
if (!snap) return { text: NO_FLEET_STATUS, forRelay: true, intent: 'relay' as const };
|
|
138
144
|
const at = Date.parse(snap.updatedAt);
|
|
139
145
|
const stale = !Number.isFinite(at) || now - at > FLEET_FRESH_MS;
|
|
140
146
|
// What the relay is waiting on him for is walked one item at a time, not read as a paragraph.
|
|
@@ -142,16 +148,16 @@ export function createConverseBrain(deps: ConverseBrainDeps): ConverseBrain {
|
|
|
142
148
|
if (waiting.length) {
|
|
143
149
|
const state: BriefingState = { queue: waiting, index: 0 };
|
|
144
150
|
const age = ageWords(snap.updatedAt, now);
|
|
145
|
-
return { text: `${stale ? `From the relay's snapshot${age ? `, ${age}` : ''}, not live. ` : ''}${firstPrompt(state)}`, briefing: state, ...(stale ? { forRelay: true } : {}) };
|
|
151
|
+
return { text: `${stale ? `From the relay's snapshot${age ? `, ${age}` : ''}, not live. ` : ''}${firstPrompt(state)}`, briefing: state, intent: 'briefing' as const, ...(stale ? { forRelay: true } : {}) };
|
|
146
152
|
}
|
|
147
|
-
if (!deps.answerFrom) return { text: NO_FLEET_STATUS, forRelay: true };
|
|
153
|
+
if (!deps.answerFrom) return { text: NO_FLEET_STATUS, forRelay: true, intent: 'relay' as const };
|
|
148
154
|
const said = await timed('answer', () => deps.answerFrom!({ question: `${utterance}\n\n${NO_FILLER}`, material: `Fleet status as of ${snap.updatedAt || 'an unknown time'}:\n${snap.text}` }).catch(() => ''));
|
|
149
155
|
const spoken = speakableAnswer(said);
|
|
150
156
|
const body = !spoken || GIVE_UP.test(spoken) ? speakableAnswer(snap.text.split('\n').filter((l) => l.trim() && !l.startsWith('#')).slice(0, 4).join(' ')) : spoken;
|
|
151
|
-
if (!stale) return { text: body };
|
|
157
|
+
if (!stale) return { text: body, intent: 'question' as const };
|
|
152
158
|
// The age is added here, not left to the model: a snapshot must never sound live.
|
|
153
159
|
const age = ageWords(snap.updatedAt, now);
|
|
154
|
-
return { text: `This is from the relay's last snapshot${age ? `, ${age}` : ''}, not live. ${body} I have asked the relay for a current one.`, forRelay: true };
|
|
160
|
+
return { text: `This is from the relay's last snapshot${age ? `, ${age}` : ''}, not live. ${body} I have asked the relay for a current one.`, forRelay: true, intent: 'relay' as const };
|
|
155
161
|
}
|
|
156
162
|
|
|
157
163
|
/** Runs what an answer to a briefing item asks for (an edit through the seam, or a note for the relay) and says the next item. */
|
|
@@ -167,7 +173,7 @@ export function createConverseBrain(deps: ConverseBrainDeps): ConverseBrain {
|
|
|
167
173
|
did = outcome.results.map((r) => r.spoken).filter(Boolean);
|
|
168
174
|
if (outcome.failed) text = text.replace(/^Noted\./, 'I could not change that one.');
|
|
169
175
|
}
|
|
170
|
-
return { text, briefing: step.state, ...(did?.length ? { did } : {}), ...(effect?.kind === 'relay' ? { forRelay: true, relayText: effect.text } : {}) };
|
|
176
|
+
return { text, briefing: step.state, intent: 'briefing' as const, ...(did?.length ? { did } : {}), ...(effect?.kind === 'relay' ? { forRelay: true, relayText: effect.text } : {}) };
|
|
171
177
|
}
|
|
172
178
|
|
|
173
179
|
async function run({ utterance, history, timeZone, now, briefing }: Parameters<ConverseBrain>[0], timed: Timed): ReturnType<ConverseBrain> {
|
|
@@ -181,14 +187,16 @@ export function createConverseBrain(deps: ConverseBrainDeps): ConverseBrain {
|
|
|
181
187
|
const step = stepBriefing(briefing, utterance);
|
|
182
188
|
if (!step.passThrough) return applyStep(step, utterance, now, timeZone, timed);
|
|
183
189
|
}
|
|
190
|
+
// "Parse that note" / "that's it" / "I'm done": he is wrapping up. The turn files the conversation through the normal End.
|
|
191
|
+
if (WRAP_UP.test(utterance.trim())) return { text: 'Filing it now.', finish: true, intent: 'note' as const };
|
|
184
192
|
const small = smallTalkReply(utterance);
|
|
185
|
-
if (small) return { text: small };
|
|
193
|
+
if (small) return { text: small, intent: 'chat' as const };
|
|
186
194
|
// "What did I do yesterday": answered from WHEN things happened (a window read, not a word search). Read only.
|
|
187
195
|
if (deps.loadActivity && ACTIVITY_QUESTION.test(utterance.trim())) {
|
|
188
196
|
const window = questionWindow(utterance, now, timeZone);
|
|
189
197
|
if (window) {
|
|
190
198
|
const found = forOwner(await timed('activity', () => deps.loadActivity!(window, timeZone)), deps.ownerSub);
|
|
191
|
-
return { text: composeActivity(window, found) };
|
|
199
|
+
return { text: composeActivity(window, found), intent: 'question' as const, sources: sourcesOfDocs(found.docs) };
|
|
192
200
|
}
|
|
193
201
|
}
|
|
194
202
|
// "What is on my plate" starts a briefing: by project, one item at a time.
|
|
@@ -198,9 +206,9 @@ export function createConverseBrain(deps: ConverseBrainDeps): ConverseBrain {
|
|
|
198
206
|
timed('fleet', async () => deps.loadFleetStatus?.().catch(() => null) ?? null),
|
|
199
207
|
]);
|
|
200
208
|
const queue = buildQueue({ items: rows, relayItems: snap ? relayItemsFrom(snap.text) : [], now, timeZone, relayFirst: NEEDS_ME.test(utterance) });
|
|
201
|
-
if (!queue.length) return { text: 'Nothing needs you right now.' };
|
|
209
|
+
if (!queue.length) return { text: 'Nothing needs you right now.', intent: 'briefing' as const };
|
|
202
210
|
const state: BriefingState = { queue, index: 0 };
|
|
203
|
-
return { text: firstPrompt(state), briefing: state };
|
|
211
|
+
return { text: firstPrompt(state), briefing: state, intent: 'briefing' as const };
|
|
204
212
|
}
|
|
205
213
|
// A QUESTION is almost never an item edit, and the routing model does not depend on the intent model: start it now so a
|
|
206
214
|
// question pays for one wait, not two. An instruction ("mark ... done") still never wakes the routing model.
|
|
@@ -233,7 +241,7 @@ export function createConverseBrain(deps: ConverseBrainDeps): ConverseBrain {
|
|
|
233
241
|
actions: intent.actions, clientActionId: `converse-${now}-${Math.abs(hash(utterance))}`.slice(0, 64), seam: deps.seam, log: deps.log,
|
|
234
242
|
ownerSub: deps.ownerSub, now: () => now, timeZone,
|
|
235
243
|
}));
|
|
236
|
-
return { text: outcome.text, did: outcome.results.map((r) => r.spoken).filter(Boolean) };
|
|
244
|
+
return { text: outcome.text, did: outcome.results.map((r) => r.spoken).filter(Boolean), intent: 'command' as const };
|
|
237
245
|
}
|
|
238
246
|
|
|
239
247
|
if (!ADDRESSES_RELAY.test(utterance)) {
|
|
@@ -244,9 +252,9 @@ export function createConverseBrain(deps: ConverseBrainDeps): ConverseBrain {
|
|
|
244
252
|
const answered = await (earlyAsk ?? timed('ask', () => deps.ask({ question: askQuestion(utterance, history), timeZone, now })));
|
|
245
253
|
// The screen gets the whole answer (cleaned for reading); the voice gets a short version of a long one.
|
|
246
254
|
const full = speakable(answered.answer ?? '', 400) || (answered.answer ?? '').trim();
|
|
247
|
-
if (!full || GIVE_UP.test(full)) return { text: CANNOT_SEE };
|
|
255
|
+
if (!full || GIVE_UP.test(full)) return { text: CANNOT_SEE, intent: 'question' as const };
|
|
248
256
|
const short = spokenSummary(full);
|
|
249
|
-
return { text: full, ...(short ? { spoken: short } : {}) };
|
|
257
|
+
return { text: full, intent: 'question' as const, ...(short ? { spoken: short } : {}), ...(answered.sources?.length ? { sources: answered.sources } : {}) };
|
|
250
258
|
}
|
|
251
259
|
|
|
252
260
|
return async (input) => {
|
|
@@ -30,6 +30,8 @@ const resultOf = (id: string, turn: ConverseTurn): ConverseTurnResult => ({
|
|
|
30
30
|
reply_text: turn.assistant.text,
|
|
31
31
|
audio_url: turn.assistant.audio_ref ? turnAudioPath(id, turn.n) : null,
|
|
32
32
|
audio_reason: turn.assistant.audio_ref ? null : (turn.assistant.audio_reason ?? 'no audio was produced'),
|
|
33
|
+
...(turn.intent ? { intent: turn.intent } : {}),
|
|
34
|
+
...(turn.sources?.length ? { sources: turn.sources } : {}),
|
|
33
35
|
});
|
|
34
36
|
|
|
35
37
|
function validate(req: ConverseTurnRequest) {
|
|
@@ -85,6 +87,9 @@ export async function handleConverseTurn(deps: ConverseDeps, req: ConverseTurnRe
|
|
|
85
87
|
let forRelay = false;
|
|
86
88
|
let relayText: string | undefined;
|
|
87
89
|
let spokenText: string | undefined;
|
|
90
|
+
let intent: ConverseTurn['intent'];
|
|
91
|
+
let sources: ConverseTurn['sources'];
|
|
92
|
+
let finish = false;
|
|
88
93
|
let briefing = record?.briefing;
|
|
89
94
|
if (utterance) {
|
|
90
95
|
const lines = (record?.turns ?? []).flatMap((t) => [{ role: 'user' as const, text: t.user.text }, { role: 'assistant' as const, text: t.from === 'relay' ? `The relay said: ${t.assistant.text}` : t.assistant.text }]).filter((l) => l.text);
|
|
@@ -96,6 +101,9 @@ export async function handleConverseTurn(deps: ConverseDeps, req: ConverseTurnRe
|
|
|
96
101
|
forRelay = Boolean(out.forRelay);
|
|
97
102
|
relayText = out.relayText;
|
|
98
103
|
spokenText = out.spoken;
|
|
104
|
+
intent = out.intent;
|
|
105
|
+
sources = out.sources;
|
|
106
|
+
finish = Boolean(out.finish);
|
|
99
107
|
if (out.briefing !== undefined) briefing = out.briefing ?? undefined;
|
|
100
108
|
lap('brain');
|
|
101
109
|
for (const [k, v] of Object.entries(out.timings ?? {})) timing[`brain.${k}`] = v;
|
|
@@ -105,6 +113,10 @@ export async function handleConverseTurn(deps: ConverseDeps, req: ConverseTurnRe
|
|
|
105
113
|
}
|
|
106
114
|
}
|
|
107
115
|
|
|
116
|
+
// Wrapping up an empty conversation files nothing.
|
|
117
|
+
const priorTurns = record?.turns.length ?? 0;
|
|
118
|
+
if (finish && priorTurns === 0) { replyText = 'There is nothing to file yet.'; finish = false; spokenText = undefined; }
|
|
119
|
+
|
|
108
120
|
// 3. Keep both recordings; speak the reply. Neither is allowed to lose the turn.
|
|
109
121
|
const user: ConverseSide = { text: utterance };
|
|
110
122
|
if (req.audio && deps.audio) {
|
|
@@ -123,7 +135,7 @@ export async function handleConverseTurn(deps: ConverseDeps, req: ConverseTurnRe
|
|
|
123
135
|
lap('tts');
|
|
124
136
|
|
|
125
137
|
// 4. Save.
|
|
126
|
-
const turn: ConverseTurn = { n, turn_id: turnId, at: new Date(now).toISOString(), user, assistant, ...(did ? { did } : {}), ...(forRelay ? { for_relay: true } : {}) };
|
|
138
|
+
const turn: ConverseTurn = { n, turn_id: turnId, at: new Date(now).toISOString(), user, assistant, ...(did ? { did } : {}), ...(forRelay ? { for_relay: true } : {}), ...(intent ? { intent } : {}), ...(sources?.length ? { sources } : {}) };
|
|
127
139
|
const startedAt = record?.startedAt ?? turn.at;
|
|
128
140
|
await store.save({
|
|
129
141
|
...(record ?? { status: 'open' as const, conversationId, externalId: '' }),
|
|
@@ -135,10 +147,20 @@ export async function handleConverseTurn(deps: ConverseDeps, req: ConverseTurnRe
|
|
|
135
147
|
});
|
|
136
148
|
// The relay finds its work in one list, so a passed-on turn is also recorded there. Never allowed to lose the turn.
|
|
137
149
|
if (forRelay) await addRelayOrder(deps, { conversation_id: conversationId, turn: n, text: relayText ?? utterance, at: turn.at }).catch((e) => console.error('[converse] relay inbox write failed', e));
|
|
150
|
+
// He said "parse that note" / "that's it": file the conversation through the normal End, here, in the same turn.
|
|
151
|
+
let ended: { ended: true; filed: { note: boolean; todos: number } } | undefined;
|
|
152
|
+
if (finish) {
|
|
153
|
+
try {
|
|
154
|
+
const done = await handleConverseEnd(deps, { conversationId });
|
|
155
|
+
ended = { ended: true, filed: { note: true, todos: done.asks.length } };
|
|
156
|
+
} catch (error) {
|
|
157
|
+
console.error('[converse] wrap-up failed (the conversation is kept open)', error);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
138
160
|
lap('save');
|
|
139
161
|
timing.total = Date.now() - clock.t0;
|
|
140
162
|
deps.onTiming?.(timing, { conversationId, turn: n });
|
|
141
|
-
return resultOf(conversationId, turn);
|
|
163
|
+
return { ...resultOf(conversationId, turn), ...(ended ?? {}) };
|
|
142
164
|
}
|
|
143
165
|
|
|
144
166
|
/** End: finish the record, write the transcript as its document body, pull out asks and decisions, then file it (project + to-dos). Idempotent. */
|
|
@@ -9,7 +9,7 @@ export { renderNextSteps, renderTranscript, titleFor } from './transcript';
|
|
|
9
9
|
export { ConverseError, CONVERSATION_SOURCE, turnAudioPath } from './types';
|
|
10
10
|
export type {
|
|
11
11
|
ConversationRecord, ConversationStore, ConverseBrain, ConverseBrainInput, ConverseBrainOutput, ConverseDeps, ConverseEndResult, ConverseHandoffInput,
|
|
12
|
-
ConverseThread, ConverseThreadTurn, ConverseTurn, ConverseTurnRequest, ConverseTurnResult, HistoryLine,
|
|
12
|
+
ConverseIntent, ConverseSource, ConverseThread, ConverseThreadTurn, ConverseTurn, ConverseTurnRequest, ConverseTurnResult, HistoryLine,
|
|
13
13
|
} from './types';
|
|
14
14
|
export { createConverseBrain, questionWithHistory, speakableAnswer } from './brain';
|
|
15
15
|
export type { ConverseBrainDeps } from './brain';
|
|
@@ -34,3 +34,4 @@ export type { FleetSnapshot } from './fleet';
|
|
|
34
34
|
export { PASSED_TO_RELAY, NO_FLEET_STATUS, NO_FILLER } from './brain';
|
|
35
35
|
export { ACTIVITY_QUESTION, activityOf, composeActivity, forOwner, loadActivity } from '../activity';
|
|
36
36
|
export type { Activity, ActivityWindow, ActivityNote } from '../activity';
|
|
37
|
+
export { askSources, sourceOf, sourcesOfDocs } from './sources';
|