@startsimpli/integrations 0.2.228 → 0.2.230
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 +4 -4
- package/src/__tests__/corpus-ask-lookup.test.ts +70 -0
- package/src/comms/__tests__/email-auth.test.tsx +173 -0
- package/src/comms/api/comms.ts +21 -0
- package/src/comms/components/EmailAuthApply.tsx +83 -0
- package/src/comms/components/EmailAuthPanel.tsx +140 -0
- package/src/comms/components/SendingDomain.tsx +3 -0
- package/src/comms/components/index.ts +1 -0
- package/src/comms/hooks/index.ts +38 -0
- package/src/comms/types/index.ts +77 -0
- package/src/components/pages/ConversePage.tsx +1 -1
- package/src/corpus/ask-items.ts +15 -5
- package/src/corpus/converse/brain.ts +3 -3
- package/src/corpus/give-up.ts +4 -0
- package/src/corpus/llm.ts +5 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@startsimpli/integrations",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.230",
|
|
4
4
|
"description": "Provider-agnostic types, API clients, hooks, and UI primitives for email + calendar integrations across StartSimpli apps, plus foundry customer email (subpath ./comms).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://startsimpli.com",
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
"react-native": ">=0.74.0",
|
|
51
51
|
"@startsimpli/ui-native": ">=0.1.12",
|
|
52
52
|
"react-native-safe-area-context": ">=4.0.0",
|
|
53
|
-
"@startsimpli/auth": "^0.4.64",
|
|
54
53
|
"@startsimpli/ui": "^0.4.211",
|
|
54
|
+
"@startsimpli/auth": "^0.4.64",
|
|
55
55
|
"@startsimpli/utils": "^0.4.23"
|
|
56
56
|
},
|
|
57
57
|
"peerDependenciesMeta": {
|
|
@@ -98,11 +98,11 @@
|
|
|
98
98
|
"vitest": "^3.0.0",
|
|
99
99
|
"react-native": "0.85.3",
|
|
100
100
|
"react-native-safe-area-context": "~5.7.0",
|
|
101
|
-
"@startsimpli/llm": "0.4.32",
|
|
102
101
|
"@startsimpli/ui": "0.4.211",
|
|
103
102
|
"@startsimpli/ui-native": "0.1.15",
|
|
104
103
|
"@startsimpli/auth": "0.4.64",
|
|
105
|
-
"@startsimpli/utils": "0.4.23"
|
|
104
|
+
"@startsimpli/utils": "0.4.23",
|
|
105
|
+
"@startsimpli/llm": "0.4.32"
|
|
106
106
|
},
|
|
107
107
|
"scripts": {
|
|
108
108
|
"type-check": "tsc --noEmit && tsc --noEmit -p tsconfig.native.json",
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Talk's "What is ENG-141 about?" answered "unanswerable: true" (bd, Todo: tandem-go-assistant): (a) the model put the give-up
|
|
3
|
+
* phrase inside the answer string and it was shown as the answer; (b) a question that names a tracked item by its key had
|
|
4
|
+
* no item words or dates, so no to-do was ever read.
|
|
5
|
+
*/
|
|
6
|
+
import { describe, expect, it } from 'vitest';
|
|
7
|
+
|
|
8
|
+
import { askCorpus } from '../corpus/ask';
|
|
9
|
+
import { itemKeysIn } from '../corpus/ask-items';
|
|
10
|
+
import { isGiveUp } from '../corpus/give-up';
|
|
11
|
+
import { parseAnswerDraft } from '../corpus/llm';
|
|
12
|
+
import { createFixtureCorpusApi, FIXTURE_ORG } from '../corpus/fixtures';
|
|
13
|
+
import type { AnswerDraft, AnswerRequest, Commitment, CorpusLlm } from '../corpus/types';
|
|
14
|
+
|
|
15
|
+
const SCOPE = { orgId: FIXTURE_ORG };
|
|
16
|
+
const NOW = Date.parse('2026-11-11T12:00:00Z');
|
|
17
|
+
const item = (id: string, over: Partial<Commitment>): Commitment => ({
|
|
18
|
+
id, externalId: `commit:${id}`, dedupeKey: id, subtype: 'task', title: `Item ${id}`, detail: '', status: 'open', subjectKey: '', actionKey: '', mentions: [],
|
|
19
|
+
firstSeenAt: '2026-10-01T00:00:00Z', lastSeenAt: null, extractorVersion: 'x', source: 'linear', sourceLabel: 'Linear', scope: SCOPE, ownerSub: 'me', ...over,
|
|
20
|
+
}) as Commitment;
|
|
21
|
+
const ITEMS = [
|
|
22
|
+
item('a', { title: "Don't add the prompt box.", sync: { state: 'synced', key: 'ENG-141', stateName: 'Todo' } }),
|
|
23
|
+
item('b', { title: 'Old finished thing', status: 'done', sync: { state: 'synced', key: 'ENG-9', stateName: 'Done' } }),
|
|
24
|
+
item('c', { title: 'Something else', sync: { state: 'synced', key: 'ENG-1410', stateName: 'Todo' } }),
|
|
25
|
+
];
|
|
26
|
+
const commitments = { listCommitments: async () => ({ count: ITEMS.length, next: null, previous: null, results: ITEMS }) };
|
|
27
|
+
const llm = (calls: AnswerRequest[]): CorpusLlm => ({
|
|
28
|
+
describe: () => ({ provider: 'scripted', model: 's', live: false }),
|
|
29
|
+
async answer(input): Promise<AnswerDraft> { calls.push(input); return { answer: 'It says not to add the prompt box.', citations: [{ documentId: 'item:commit:a' }] }; },
|
|
30
|
+
});
|
|
31
|
+
const ask = (question: string, calls: AnswerRequest[]) =>
|
|
32
|
+
askCorpus({ question, mode: 'ask', scope: SCOPE }, { corpus: createFixtureCorpusApi(), llm: llm(calls), commitments }, { now: NOW });
|
|
33
|
+
|
|
34
|
+
describe('questions that name a tracked item by its key', () => {
|
|
35
|
+
it('reads the keys a question names, case-insensitively, whole keys only', () => {
|
|
36
|
+
expect(itemKeysIn('What is ENG-141 about?')).toEqual(['ENG-141']);
|
|
37
|
+
expect(itemKeysIn('compare eng-141 and TAN-7')).toEqual(['ENG-141', 'TAN-7']);
|
|
38
|
+
expect(itemKeysIn('what happened in 2026-11')).toEqual([]);
|
|
39
|
+
});
|
|
40
|
+
it('hands the model that item, with no item words or dates in the question, and cites it', async () => {
|
|
41
|
+
const calls: AnswerRequest[] = [];
|
|
42
|
+
const res = await ask('What is ENG-141 about?', calls);
|
|
43
|
+
expect(calls).toHaveLength(1);
|
|
44
|
+
expect(JSON.stringify(calls[0])).toContain("Don't add the prompt box.");
|
|
45
|
+
expect(JSON.stringify(calls[0])).not.toContain('Something else');
|
|
46
|
+
expect(res.status).toBe('answered');
|
|
47
|
+
expect(res.citations.map((c) => c.document.id)).toEqual(['item:commit:a']);
|
|
48
|
+
});
|
|
49
|
+
it('finds a finished item by its key too, and never confuses ENG-141 with ENG-1410', async () => {
|
|
50
|
+
const calls: AnswerRequest[] = [];
|
|
51
|
+
await ask('what was eng-9?', calls);
|
|
52
|
+
expect(JSON.stringify(calls[0] ?? {})).toContain('Old finished thing');
|
|
53
|
+
const c2: AnswerRequest[] = [];
|
|
54
|
+
await ask('What is ENG-141 about?', c2);
|
|
55
|
+
expect(JSON.stringify(c2[0])).not.toContain('ENG-1410');
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe('a give-up phrase is never shown as an answer', () => {
|
|
60
|
+
it('recognises the bare word, with a value, and the usual non-answers', () => {
|
|
61
|
+
for (const s of ['unanswerable', 'Unanswerable: true', 'unanswerable: true.', ' n/a ', 'unknown', 'null']) expect(isGiveUp(s)).toBe(true);
|
|
62
|
+
});
|
|
63
|
+
it('leaves a real sentence alone', () => {
|
|
64
|
+
for (const s of ['The status is unknown until Friday.', 'It is not unanswerable: see the deck.', 'ENG-141 says not to add the prompt box.']) expect(isGiveUp(s)).toBe(false);
|
|
65
|
+
});
|
|
66
|
+
it('a draft whose answer is the give-up phrase becomes an empty, unanswerable draft', () => {
|
|
67
|
+
expect(parseAnswerDraft('{"answer":"unanswerable: true","citations":[],"unanswerable":false}')).toEqual({ answer: '', citations: [], unanswerable: true });
|
|
68
|
+
expect(parseAnswerDraft('{"answer":"Fine.","citations":[],"unanswerable":false}')?.answer).toBe('Fine.');
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/** Email security section of the sending-domain panel (bd startsim-7p3vi.8). */
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from 'vitest';
|
|
4
|
+
import { fireEvent, render, screen, waitFor, within } from '@testing-library/react';
|
|
5
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
6
|
+
import { http, HttpResponse } from 'msw';
|
|
7
|
+
import { setupServer } from 'msw/node';
|
|
8
|
+
|
|
9
|
+
import { SendingDomain } from '../components/SendingDomain';
|
|
10
|
+
import { createCommsApi, setApiBase } from '../api/index';
|
|
11
|
+
import type { DmarcReportSummary, EmailAuthDiagnosis } from '../types/index';
|
|
12
|
+
import { BASE, P, SLUG, settings } from './fixtures';
|
|
13
|
+
|
|
14
|
+
let diagnosis: EmailAuthDiagnosis;
|
|
15
|
+
let reports: DmarcReportSummary;
|
|
16
|
+
let connected = false;
|
|
17
|
+
const calls: string[] = [];
|
|
18
|
+
const DNS = `${BASE}/api/v1/foundry/tenants/${SLUG}/dns-connection/`;
|
|
19
|
+
|
|
20
|
+
const server = setupServer(
|
|
21
|
+
http.get(`${P}/settings/`, () =>
|
|
22
|
+
HttpResponse.json(settings({ sending_domain: 'crochets.site', domain_status: 'pending' }))),
|
|
23
|
+
http.get(`${P}/settings/domain/email-auth/`, () => HttpResponse.json(diagnosis)),
|
|
24
|
+
http.get(`${P}/settings/domain/dmarc-reports/`, () => HttpResponse.json(reports)),
|
|
25
|
+
http.get(DNS, () => HttpResponse.json({ provider: 'namecheap', connected, zone_name: 'crochets.site', has_token: connected })),
|
|
26
|
+
http.put(DNS, async ({ request }) => {
|
|
27
|
+
calls.push(`put ${JSON.stringify(await request.json())}`);
|
|
28
|
+
connected = true;
|
|
29
|
+
return HttpResponse.json({ provider: 'namecheap', connected: true, zone_name: 'crochets.site', has_token: true });
|
|
30
|
+
}),
|
|
31
|
+
http.post(`${P}/settings/domain/email-auth/apply/`, () => {
|
|
32
|
+
calls.push('apply');
|
|
33
|
+
return HttpResponse.json({ applied: true, records: ['@', '_dmarc'] });
|
|
34
|
+
}),
|
|
35
|
+
http.post(`${P}/settings/domain/email-auth/rollback/`, () => {
|
|
36
|
+
calls.push('rollback');
|
|
37
|
+
return HttpResponse.json({ applied: false, rolled_back: true, records: ['@'] });
|
|
38
|
+
}),
|
|
39
|
+
);
|
|
40
|
+
beforeAll(() => {
|
|
41
|
+
server.listen({ onUnhandledRequest: 'error' });
|
|
42
|
+
setApiBase(`${BASE}/api/v1`);
|
|
43
|
+
});
|
|
44
|
+
afterEach(() => server.resetHandlers());
|
|
45
|
+
afterAll(() => server.close());
|
|
46
|
+
|
|
47
|
+
function mount() {
|
|
48
|
+
const qc = new QueryClient({ defaultOptions: { queries: { retry: false } } });
|
|
49
|
+
return render(
|
|
50
|
+
<QueryClientProvider client={qc}>
|
|
51
|
+
<SendingDomain api={createCommsApi(SLUG)} />
|
|
52
|
+
</QueryClientProvider>,
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const NO_REPORTS: DmarcReportSummary = {
|
|
57
|
+
days: 30, reports: 0, messages: 0, dmarc_fail: 0, pass_rate: null, last_report_at: null, sources: [],
|
|
58
|
+
};
|
|
59
|
+
beforeEach(() => { reports = NO_REPORTS; connected = false; calls.length = 0; });
|
|
60
|
+
|
|
61
|
+
describe('EmailAuthPanel', () => {
|
|
62
|
+
it('shows each record with its reason and the record to publish', async () => {
|
|
63
|
+
diagnosis = {
|
|
64
|
+
domain: 'crochets.site',
|
|
65
|
+
status: 'missing',
|
|
66
|
+
records: [
|
|
67
|
+
{ purpose: 'spf', type: 'TXT', host: 'crochets.site', status: 'fail', reason: 'SPF does not list mailjet.',
|
|
68
|
+
current: 'v=spf1 ~all', recommended: 'v=spf1 include:spf.mailjet.com ~all' },
|
|
69
|
+
{ purpose: 'dkim', type: 'TXT', host: 'k._domainkey.crochets.site', status: 'ok', reason: 'DKIM ok.',
|
|
70
|
+
current: 'x', recommended: 'x' },
|
|
71
|
+
{ purpose: 'dmarc', type: 'TXT', host: '_dmarc.crochets.site', status: 'missing', reason: 'No DMARC record.',
|
|
72
|
+
current: '', recommended: 'v=DMARC1; p=none' },
|
|
73
|
+
],
|
|
74
|
+
};
|
|
75
|
+
mount();
|
|
76
|
+
const spf = await screen.findByTestId('email-auth-spf');
|
|
77
|
+
expect(within(spf).getByText('Fix')).toBeTruthy();
|
|
78
|
+
expect(within(spf).getByText('v=spf1 include:spf.mailjet.com ~all')).toBeTruthy();
|
|
79
|
+
const dmarc = screen.getByTestId('email-auth-dmarc');
|
|
80
|
+
expect(within(dmarc).getByText('Missing')).toBeTruthy();
|
|
81
|
+
expect(within(dmarc).getByText('v=DMARC1; p=none')).toBeTruthy();
|
|
82
|
+
// A passing record shows no record to publish.
|
|
83
|
+
expect(within(screen.getByTestId('email-auth-dkim')).queryByText('Copy')).toBeNull();
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('shows the DMARC report roll-up with failing senders, or says none arrived yet', async () => {
|
|
87
|
+
diagnosis = { domain: 'crochets.site', status: 'ok', records: [] };
|
|
88
|
+
mount();
|
|
89
|
+
expect(await screen.findByText(/No DMARC reports received yet/)).toBeTruthy();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('lists the sources that failed DMARC', async () => {
|
|
93
|
+
diagnosis = { domain: 'crochets.site', status: 'ok', records: [] };
|
|
94
|
+
reports = {
|
|
95
|
+
days: 30, reports: 2, messages: 20, dmarc_fail: 5, pass_rate: 0.75, last_report_at: null,
|
|
96
|
+
sources: [{ source_ip: '9.9.9.9', messages: 5, dmarc_fail: 5, reporters: ['google.com'] }],
|
|
97
|
+
};
|
|
98
|
+
mount();
|
|
99
|
+
const box = await screen.findByTestId('dmarc-reports');
|
|
100
|
+
expect(within(box).getByText(/75% passed DMARC/)).toBeTruthy();
|
|
101
|
+
expect(within(box).getByText(/9\.9\.9\.9/)).toBeTruthy();
|
|
102
|
+
});
|
|
103
|
+
it('offers the next DMARC step with the record when the last 30 days are clean', async () => {
|
|
104
|
+
diagnosis = {
|
|
105
|
+
domain: 'crochets.site', status: 'ok', records: [],
|
|
106
|
+
ladder: { policy: 'none', next: 'quarantine', ready: true, recommended: 'v=DMARC1; p=quarantine',
|
|
107
|
+
evidence: { days: 30, reports: 4, messages: 120, dmarc_fail: 0 } },
|
|
108
|
+
};
|
|
109
|
+
mount();
|
|
110
|
+
const box = await screen.findByTestId('dmarc-ladder');
|
|
111
|
+
expect(within(box).getByText(/move to p=quarantine/)).toBeTruthy();
|
|
112
|
+
expect(within(box).getByText('v=DMARC1; p=quarantine')).toBeTruthy();
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('says why the next DMARC step is not ready, and shows nothing at p=reject', async () => {
|
|
116
|
+
diagnosis = {
|
|
117
|
+
domain: 'crochets.site', status: 'ok', records: [],
|
|
118
|
+
ladder: { policy: 'none', next: 'quarantine', ready: false, recommended: '',
|
|
119
|
+
evidence: { days: 30, reports: 4, messages: 120, dmarc_fail: 7 } },
|
|
120
|
+
};
|
|
121
|
+
const { unmount } = mount();
|
|
122
|
+
expect(await screen.findByText(/7 of 120 messages failed DMARC/)).toBeTruthy();
|
|
123
|
+
unmount();
|
|
124
|
+
diagnosis = {
|
|
125
|
+
domain: 'crochets.site', status: 'ok', records: [],
|
|
126
|
+
ladder: { policy: 'reject', next: null, ready: false, recommended: '',
|
|
127
|
+
evidence: { days: 30, reports: 4, messages: 120, dmarc_fail: 0 } },
|
|
128
|
+
};
|
|
129
|
+
mount();
|
|
130
|
+
expect(await screen.findByText(/No DMARC reports received yet/)).toBeTruthy();
|
|
131
|
+
expect(screen.queryByTestId('dmarc-ladder')).toBeNull();
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
const FIXABLE: EmailAuthDiagnosis = {
|
|
135
|
+
domain: 'crochets.site', status: 'missing',
|
|
136
|
+
records: [{ purpose: 'dmarc', type: 'TXT', host: '_dmarc.crochets.site', status: 'missing',
|
|
137
|
+
reason: 'No DMARC record.', current: '', recommended: 'v=DMARC1; p=none' }],
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
it('connects Namecheap with the foundry domain as the zone, never echoing the key', async () => {
|
|
141
|
+
diagnosis = FIXABLE;
|
|
142
|
+
mount();
|
|
143
|
+
fireEvent.click(await screen.findByText('Connect Namecheap to publish these for me'));
|
|
144
|
+
fireEvent.change(screen.getByLabelText('API user'), { target: { value: 'qosha' } });
|
|
145
|
+
fireEvent.change(screen.getByLabelText('API key'), { target: { value: 'k-123' } });
|
|
146
|
+
fireEvent.change(screen.getByLabelText('Allowlisted IP'), { target: { value: '1.2.3.4' } });
|
|
147
|
+
fireEvent.click(screen.getByText('Connect'));
|
|
148
|
+
await screen.findByText('Publish these records');
|
|
149
|
+
expect(JSON.parse(calls[0].slice(4))).toEqual({
|
|
150
|
+
provider: 'namecheap', api_user: 'qosha', api_key: 'k-123', client_ip: '1.2.3.4', zone_name: 'crochets.site',
|
|
151
|
+
});
|
|
152
|
+
expect(screen.queryByDisplayValue('k-123')).toBeNull();
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('publishes the records and can undo, once connected', async () => {
|
|
156
|
+
diagnosis = FIXABLE;
|
|
157
|
+
connected = true;
|
|
158
|
+
mount();
|
|
159
|
+
fireEvent.click(await screen.findByText('Publish these records'));
|
|
160
|
+
await screen.findByText(/Published: @, _dmarc/);
|
|
161
|
+
fireEvent.click(screen.getByText('Undo last publish'));
|
|
162
|
+
await screen.findByText(/Restored the zone/);
|
|
163
|
+
await waitFor(() => expect(calls).toEqual(['apply', 'rollback']));
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('offers no publish or connect when every record is fine', async () => {
|
|
167
|
+
diagnosis = { domain: 'crochets.site', status: 'ok', records: [] };
|
|
168
|
+
mount();
|
|
169
|
+
await screen.findByText(/No DMARC reports received yet/);
|
|
170
|
+
expect(screen.queryByText('Publish these records')).toBeNull();
|
|
171
|
+
expect(screen.queryByText('Connect Namecheap to publish these for me')).toBeNull();
|
|
172
|
+
});
|
|
173
|
+
});
|
package/src/comms/api/comms.ts
CHANGED
|
@@ -20,6 +20,11 @@ import type {
|
|
|
20
20
|
AssetsQuery,
|
|
21
21
|
CommsAsset,
|
|
22
22
|
CommsSettings,
|
|
23
|
+
DmarcReportSummary,
|
|
24
|
+
DnsConnection,
|
|
25
|
+
EmailAuthChange,
|
|
26
|
+
EmailAuthDiagnosis,
|
|
27
|
+
NamecheapConnectInput,
|
|
23
28
|
CommsSettingsPatch,
|
|
24
29
|
AudienceSegments,
|
|
25
30
|
AudienceSpec,
|
|
@@ -52,6 +57,15 @@ export interface CommsApi {
|
|
|
52
57
|
updateSettings(patch: CommsSettingsPatch): Promise<CommsSettings>;
|
|
53
58
|
connectDomain(domain: string): Promise<CommsSettings>;
|
|
54
59
|
checkDomain(): Promise<CommsSettings>;
|
|
60
|
+
/** Live SPF / DKIM / DMARC diagnosis of the sending domain. Read-only. */
|
|
61
|
+
getEmailAuth(): Promise<EmailAuthDiagnosis>;
|
|
62
|
+
/** Publish the records the diagnosis asks for through the connected registrar (snapshot kept for undo). */
|
|
63
|
+
applyEmailAuth(): Promise<EmailAuthChange>;
|
|
64
|
+
/** Restore the zone as it was before the last apply. */
|
|
65
|
+
rollbackEmailAuth(): Promise<EmailAuthChange>;
|
|
66
|
+
getDnsConnection(): Promise<DnsConnection>;
|
|
67
|
+
connectNamecheap(input: NamecheapConnectInput): Promise<DnsConnection>;
|
|
68
|
+
getDmarcReports(): Promise<DmarcReportSummary>;
|
|
55
69
|
|
|
56
70
|
// programs
|
|
57
71
|
listPrograms(): Promise<CommsProgram[]>;
|
|
@@ -118,6 +132,13 @@ export function createCommsApi(slug: string): CommsApi {
|
|
|
118
132
|
updateSettings: (patch) => request(`${P}/settings/`, { method: 'PATCH', body: patch }),
|
|
119
133
|
connectDomain: (domain) => request(`${P}/settings/domain/`, { method: 'POST', body: { domain } }),
|
|
120
134
|
checkDomain: () => request(`${P}/settings/domain/check/`, { method: 'POST' }),
|
|
135
|
+
getEmailAuth: () => request(`${P}/settings/domain/email-auth/`),
|
|
136
|
+
applyEmailAuth: () => request(`${P}/settings/domain/email-auth/apply/`, { method: 'POST' }),
|
|
137
|
+
rollbackEmailAuth: () => request(`${P}/settings/domain/email-auth/rollback/`, { method: 'POST' }),
|
|
138
|
+
getDnsConnection: () => request(`/foundry/tenants/${seg(slug)}/dns-connection/?provider=namecheap`),
|
|
139
|
+
connectNamecheap: (input) =>
|
|
140
|
+
request(`/foundry/tenants/${seg(slug)}/dns-connection/`, { method: 'PUT', body: { provider: 'namecheap', ...input } }),
|
|
141
|
+
getDmarcReports: () => request(`${P}/settings/domain/dmarc-reports/`),
|
|
121
142
|
|
|
122
143
|
listPrograms: () => request(`${P}/programs/`),
|
|
123
144
|
getProgram: (key) => request(`${P}/programs/${seg(key)}/`),
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Publish the missing SPF / DKIM / DMARC records for the sending domain instead of
|
|
3
|
+
* copying them by hand (bd startsim-7p3vi.9). Folded into the email security
|
|
4
|
+
* section: with a Namecheap account connected the primary action is "Publish
|
|
5
|
+
* these records" (plus Undo); without one, a short connect form takes its place.
|
|
6
|
+
*/
|
|
7
|
+
import { useState, type ReactElement } from 'react';
|
|
8
|
+
import { Button, Input, Label } from '@startsimpli/ui';
|
|
9
|
+
|
|
10
|
+
import type { CommsApi } from '../api/comms';
|
|
11
|
+
import { useConnectNamecheap, useDnsConnection, useEmailAuthChange } from '../hooks/index';
|
|
12
|
+
import { ErrorNotice, Note } from './_shared';
|
|
13
|
+
|
|
14
|
+
function ConnectForm({ api, domain }: { api: CommsApi; domain: string }): ReactElement {
|
|
15
|
+
const connect = useConnectNamecheap(api);
|
|
16
|
+
const [open, setOpen] = useState(false);
|
|
17
|
+
const [f, setF] = useState({ api_user: '', api_key: '', client_ip: '', username: '' });
|
|
18
|
+
const set = (k: keyof typeof f) => (e: { target: { value: string } }) => setF({ ...f, [k]: e.target.value });
|
|
19
|
+
if (!open) {
|
|
20
|
+
return (
|
|
21
|
+
<Button type="button" variant="outline" size="sm" onClick={() => setOpen(true)}>
|
|
22
|
+
Connect Namecheap to publish these for me
|
|
23
|
+
</Button>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
return (
|
|
27
|
+
<form
|
|
28
|
+
className="space-y-2"
|
|
29
|
+
aria-label="Connect Namecheap"
|
|
30
|
+
onSubmit={(e) => {
|
|
31
|
+
e.preventDefault();
|
|
32
|
+
connect.mutate({ ...f, username: f.username || undefined, zone_name: domain });
|
|
33
|
+
}}
|
|
34
|
+
>
|
|
35
|
+
<Note>
|
|
36
|
+
Namecheap API access must be on, with this machine's IP allowlisted. The key is stored encrypted and never shown again.
|
|
37
|
+
</Note>
|
|
38
|
+
{(
|
|
39
|
+
[['api_user', 'API user'], ['api_key', 'API key'], ['client_ip', 'Allowlisted IP'], ['username', 'Username (if different)']] as const
|
|
40
|
+
).map(([k, label]) => (
|
|
41
|
+
<div key={k} className="space-y-1">
|
|
42
|
+
<Label htmlFor={`nc-${k}`}>{label}</Label>
|
|
43
|
+
<Input
|
|
44
|
+
id={`nc-${k}`}
|
|
45
|
+
type={k === 'api_key' ? 'password' : 'text'}
|
|
46
|
+
autoComplete="off"
|
|
47
|
+
value={f[k]}
|
|
48
|
+
onChange={set(k)}
|
|
49
|
+
/>
|
|
50
|
+
</div>
|
|
51
|
+
))}
|
|
52
|
+
<ErrorNotice error={connect.error} />
|
|
53
|
+
<Button type="submit" size="sm" disabled={connect.isPending || !f.api_user || !f.api_key || !f.client_ip}>
|
|
54
|
+
{connect.isPending ? 'Checking…' : 'Connect'}
|
|
55
|
+
</Button>
|
|
56
|
+
</form>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function EmailAuthApply({ api, domain }: { api: CommsApi; domain: string }): ReactElement | null {
|
|
61
|
+
const { data: conn, isLoading } = useDnsConnection(api);
|
|
62
|
+
const apply = useEmailAuthChange(api, 'apply');
|
|
63
|
+
const undo = useEmailAuthChange(api, 'rollback');
|
|
64
|
+
if (isLoading || !conn) return null;
|
|
65
|
+
if (!conn.connected) return <ConnectForm api={api} domain={domain} />;
|
|
66
|
+
return (
|
|
67
|
+
<div className="space-y-2" data-testid="email-auth-apply">
|
|
68
|
+
<div className="flex items-center gap-2">
|
|
69
|
+
<Button type="button" size="sm" disabled={apply.isPending} onClick={() => apply.mutate()}>
|
|
70
|
+
{apply.isPending ? 'Publishing…' : 'Publish these records'}
|
|
71
|
+
</Button>
|
|
72
|
+
<Button type="button" variant="outline" size="sm" disabled={undo.isPending} onClick={() => undo.mutate()}>
|
|
73
|
+
Undo last publish
|
|
74
|
+
</Button>
|
|
75
|
+
</div>
|
|
76
|
+
<ErrorNotice error={apply.error ?? undo.error} />
|
|
77
|
+
{apply.data ? (
|
|
78
|
+
<Note>{apply.data.applied ? `Published: ${apply.data.records.join(', ')}.` : 'Nothing needed publishing.'}</Note>
|
|
79
|
+
) : null}
|
|
80
|
+
{undo.data ? <Note>{undo.data.rolled_back ? 'Restored the zone as it was before.' : 'Nothing to undo.'}</Note> : null}
|
|
81
|
+
</div>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Live SPF / DKIM / DMARC diagnosis of the sending domain (bd startsim-7p3vi.8),
|
|
3
|
+
* shown inside the sending-domain panel: per record a status, the plain reason,
|
|
4
|
+
* and the exact record to publish when something needs to change. Publishing goes through EmailAuthApply.
|
|
5
|
+
*/
|
|
6
|
+
import { useState, type ReactElement } from 'react';
|
|
7
|
+
import { Badge, Button } from '@startsimpli/ui';
|
|
8
|
+
|
|
9
|
+
import type { CommsApi } from '../api/comms';
|
|
10
|
+
import { useDmarcReports, useEmailAuth } from '../hooks/index';
|
|
11
|
+
import type { DmarcLadder, EmailAuthRecord,EmailAuthStatus as Status } from '../types/index';
|
|
12
|
+
import { EmailAuthApply } from './EmailAuthApply';
|
|
13
|
+
import { ErrorNotice, Note } from './_shared';
|
|
14
|
+
|
|
15
|
+
const LABEL: Record<Status, string> = { ok: 'OK', warn: 'Tighten', fail: 'Fix', missing: 'Missing' };
|
|
16
|
+
const NAME: Record<string, string> = { spf: 'SPF', dkim: 'DKIM', dmarc: 'DMARC' };
|
|
17
|
+
|
|
18
|
+
function Row({ r }: { r: EmailAuthRecord }): ReactElement {
|
|
19
|
+
const [copied, setCopied] = useState(false);
|
|
20
|
+
return (
|
|
21
|
+
<li className="space-y-1 rounded-md border p-3 text-sm" data-testid={`email-auth-${r.purpose}`}>
|
|
22
|
+
<div className="flex items-center gap-2">
|
|
23
|
+
<span className="font-medium">{NAME[r.purpose] ?? r.purpose}</span>
|
|
24
|
+
<Badge variant={r.status === 'ok' ? 'default' : r.status === 'warn' ? 'secondary' : 'destructive'}>
|
|
25
|
+
{LABEL[r.status]}
|
|
26
|
+
</Badge>
|
|
27
|
+
</div>
|
|
28
|
+
<p className="text-muted-foreground">{r.reason}</p>
|
|
29
|
+
{r.recommended && r.status !== 'ok' ? (
|
|
30
|
+
<div className="space-y-1">
|
|
31
|
+
<Note>
|
|
32
|
+
Publish a {r.type} record at <span className="break-all font-mono text-xs">{r.host}</span>:
|
|
33
|
+
</Note>
|
|
34
|
+
<div className="flex items-start gap-2">
|
|
35
|
+
<code className="break-all rounded bg-muted px-2 py-1 text-xs">{r.recommended}</code>
|
|
36
|
+
<Button
|
|
37
|
+
type="button"
|
|
38
|
+
variant="outline"
|
|
39
|
+
size="sm"
|
|
40
|
+
onClick={() => {
|
|
41
|
+
void navigator.clipboard?.writeText(r.recommended).then(() => setCopied(true));
|
|
42
|
+
}}
|
|
43
|
+
>
|
|
44
|
+
{copied ? 'Copied' : 'Copy'}
|
|
45
|
+
</Button>
|
|
46
|
+
</div>
|
|
47
|
+
</div>
|
|
48
|
+
) : null}
|
|
49
|
+
</li>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function Reports({ api }: { api: CommsApi }): ReactElement | null {
|
|
54
|
+
const { data } = useDmarcReports(api);
|
|
55
|
+
if (!data) return null;
|
|
56
|
+
if (data.reports === 0) {
|
|
57
|
+
return <Note>No DMARC reports received yet. Mailbox providers send them daily once DMARC is published.</Note>;
|
|
58
|
+
}
|
|
59
|
+
const bad = data.sources.filter((s) => s.dmarc_fail > 0);
|
|
60
|
+
return (
|
|
61
|
+
<div className="space-y-1 text-sm" data-testid="dmarc-reports">
|
|
62
|
+
<p>
|
|
63
|
+
Last {data.days} days: {data.messages} messages from {data.reports} reports,{' '}
|
|
64
|
+
{data.pass_rate === null ? 'n/a' : `${Math.round(data.pass_rate * 100)}%`} passed DMARC.
|
|
65
|
+
</p>
|
|
66
|
+
{bad.length ? (
|
|
67
|
+
<ul className="space-y-0.5">
|
|
68
|
+
{bad.map((s) => (
|
|
69
|
+
<li key={s.source_ip} className="text-muted-foreground">
|
|
70
|
+
<span className="font-mono text-xs">{s.source_ip}</span>: {s.dmarc_fail} of {s.messages} failed
|
|
71
|
+
{' '}(seen by {s.reporters.join(', ')})
|
|
72
|
+
</li>
|
|
73
|
+
))}
|
|
74
|
+
</ul>
|
|
75
|
+
) : null}
|
|
76
|
+
</div>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function Ladder({ l, host }: { l: DmarcLadder; host: string }): ReactElement | null {
|
|
81
|
+
const [copied, setCopied] = useState(false);
|
|
82
|
+
if (!l.next) return null;
|
|
83
|
+
const e = l.evidence;
|
|
84
|
+
return (
|
|
85
|
+
<div className="space-y-1 rounded-md border p-3 text-sm" data-testid="dmarc-ladder">
|
|
86
|
+
{l.ready ? (
|
|
87
|
+
<>
|
|
88
|
+
<p>Last {e.days} days clean ({e.messages} messages, none failed DMARC): move to p={l.next}.</p>
|
|
89
|
+
<Note>
|
|
90
|
+
Replace the DMARC record at <span className="break-all font-mono text-xs">{host}</span>:
|
|
91
|
+
</Note>
|
|
92
|
+
<div className="flex items-start gap-2">
|
|
93
|
+
<code className="break-all rounded bg-muted px-2 py-1 text-xs">{l.recommended}</code>
|
|
94
|
+
<Button
|
|
95
|
+
type="button"
|
|
96
|
+
variant="outline"
|
|
97
|
+
size="sm"
|
|
98
|
+
onClick={() => {
|
|
99
|
+
void navigator.clipboard?.writeText(l.recommended).then(() => setCopied(true));
|
|
100
|
+
}}
|
|
101
|
+
>
|
|
102
|
+
{copied ? 'Copied' : 'Copy'}
|
|
103
|
+
</Button>
|
|
104
|
+
</div>
|
|
105
|
+
</>
|
|
106
|
+
) : (
|
|
107
|
+
<p className="text-muted-foreground">
|
|
108
|
+
Not ready for p={l.next}:{' '}
|
|
109
|
+
{e.reports === 0
|
|
110
|
+
? 'no DMARC reports yet, so there is no evidence.'
|
|
111
|
+
: `${e.dmarc_fail} of ${e.messages} messages failed DMARC in the last ${e.days} days.`}
|
|
112
|
+
</p>
|
|
113
|
+
)}
|
|
114
|
+
</div>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function EmailAuthPanel({ api, domain }: { api: CommsApi; domain: string }): ReactElement | null {
|
|
119
|
+
const { data, error, isLoading } = useEmailAuth(api, Boolean(domain));
|
|
120
|
+
if (!domain) return null;
|
|
121
|
+
return (
|
|
122
|
+
<section className="space-y-2" aria-label="Email security">
|
|
123
|
+
<h3 className="text-sm font-medium">Email security for {domain}</h3>
|
|
124
|
+
{isLoading ? <Note>Checking DNS…</Note> : null}
|
|
125
|
+
<ErrorNotice error={error} />
|
|
126
|
+
{data ? (
|
|
127
|
+
<ul className="space-y-2">
|
|
128
|
+
{data.records.map((r) => (
|
|
129
|
+
<Row key={r.purpose} r={r} />
|
|
130
|
+
))}
|
|
131
|
+
</ul>
|
|
132
|
+
) : null}
|
|
133
|
+
{data?.records.some((r) => r.status !== 'ok' && r.recommended) ? <EmailAuthApply api={api} domain={domain} /> : null}
|
|
134
|
+
{data ? <Reports api={api} /> : null}
|
|
135
|
+
{data?.ladder ? (
|
|
136
|
+
<Ladder l={data.ladder} host={data.records.find((r) => r.purpose === 'dmarc')?.host ?? `_dmarc.${domain}`} />
|
|
137
|
+
) : null}
|
|
138
|
+
</section>
|
|
139
|
+
);
|
|
140
|
+
}
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
import type { CommsApi } from '../api/comms';
|
|
21
21
|
import { useCheckDomain, useCommsSettings, useConnectDomain } from '../hooks/index';
|
|
22
22
|
import type { DomainRecord, DomainStatus } from '../types/index';
|
|
23
|
+
import { EmailAuthPanel } from './EmailAuthPanel';
|
|
23
24
|
import { ErrorNotice, Note, formatDate, useFieldId } from './_shared';
|
|
24
25
|
|
|
25
26
|
export interface SendingDomainProps {
|
|
@@ -108,6 +109,8 @@ export function SendingDomain({ api }: SendingDomainProps): ReactElement | null
|
|
|
108
109
|
</Table>
|
|
109
110
|
) : null}
|
|
110
111
|
|
|
112
|
+
{settings.sending_domain ? <EmailAuthPanel api={api} domain={settings.sending_domain} /> : null}
|
|
113
|
+
|
|
111
114
|
<Note>
|
|
112
115
|
{verified
|
|
113
116
|
? `Mail goes out from ${settings.from_address ?? settings.sending_domain}.`
|
|
@@ -6,6 +6,7 @@ export * from './EmailPreviewPage';
|
|
|
6
6
|
export * from './ApprovalModeSetting';
|
|
7
7
|
export * from './VoiceSettings';
|
|
8
8
|
export * from './DefaultTimeZoneSetting';
|
|
9
|
+
export * from './EmailAuthPanel';
|
|
9
10
|
export * from './SendingDomain';
|
|
10
11
|
export * from './ProductUpdates';
|
|
11
12
|
export * from './DraftReview';
|
package/src/comms/hooks/index.ts
CHANGED
|
@@ -26,6 +26,11 @@ import type {
|
|
|
26
26
|
CommsMetrics,
|
|
27
27
|
CommsProgram,
|
|
28
28
|
CommsSettings,
|
|
29
|
+
DmarcReportSummary,
|
|
30
|
+
DnsConnection,
|
|
31
|
+
EmailAuthChange,
|
|
32
|
+
EmailAuthDiagnosis,
|
|
33
|
+
NamecheapConnectInput,
|
|
29
34
|
CommsSettingsPatch,
|
|
30
35
|
Draft,
|
|
31
36
|
DraftAudience,
|
|
@@ -49,6 +54,9 @@ import type {
|
|
|
49
54
|
export const commsKeys = {
|
|
50
55
|
all: (slug: string) => ['startsimpli', 'comms', slug] as const,
|
|
51
56
|
settings: (slug: string) => ['startsimpli', 'comms', slug, 'settings'] as const,
|
|
57
|
+
dmarcReports: (slug: string) => ['startsimpli', 'comms', slug, 'settings', 'dmarc-reports'] as const,
|
|
58
|
+
dnsConnection: (slug: string) => ['startsimpli', 'comms', slug, 'dns-connection'] as const,
|
|
59
|
+
emailAuth: (slug: string) => ['startsimpli', 'comms', slug, 'settings', 'email-auth'] as const,
|
|
52
60
|
programs: (slug: string) => ['startsimpli', 'comms', slug, 'programs'] as const,
|
|
53
61
|
generation: (slug: string, key: string, step: number) =>
|
|
54
62
|
['startsimpli', 'comms', slug, 'generation', key, step] as const,
|
|
@@ -122,6 +130,36 @@ export function useConnectDomain(api: CommsApi): UseMutationResult<CommsSettings
|
|
|
122
130
|
return useSettingsWrite(api, (domain: string) => api.connectDomain(domain));
|
|
123
131
|
}
|
|
124
132
|
|
|
133
|
+
/** Live diagnosis; sits under the settings key, so connecting or re-checking the domain refetches it. */
|
|
134
|
+
export function useDmarcReports(api: CommsApi, enabled = true): UseQueryResult<DmarcReportSummary> {
|
|
135
|
+
return useQuery({ queryKey: commsKeys.dmarcReports(api.slug), queryFn: () => api.getDmarcReports(), enabled, staleTime: 60_000 });
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function useEmailAuth(api: CommsApi, enabled = true): UseQueryResult<EmailAuthDiagnosis> {
|
|
139
|
+
return useQuery({ queryKey: commsKeys.emailAuth(api.slug), queryFn: () => api.getEmailAuth(), enabled, staleTime: 60_000 });
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function useDnsConnection(api: CommsApi, enabled = true): UseQueryResult<DnsConnection> {
|
|
143
|
+
return useQuery({ queryKey: commsKeys.dnsConnection(api.slug), queryFn: () => api.getDnsConnection(), enabled });
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function useConnectNamecheap(api: CommsApi): UseMutationResult<DnsConnection, Error, NamecheapConnectInput> {
|
|
147
|
+
const qc = useQueryClient();
|
|
148
|
+
return useMutation<DnsConnection, Error, NamecheapConnectInput>({
|
|
149
|
+
mutationFn: (input) => api.connectNamecheap(input),
|
|
150
|
+
onSuccess: () => qc.invalidateQueries({ queryKey: commsKeys.dnsConnection(api.slug) }),
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Apply or undo a DNS publish; either way the live diagnosis is stale, so refetch it. */
|
|
155
|
+
export function useEmailAuthChange(api: CommsApi, kind: 'apply' | 'rollback'): UseMutationResult<EmailAuthChange, Error, void> {
|
|
156
|
+
const qc = useQueryClient();
|
|
157
|
+
return useMutation<EmailAuthChange, Error, void>({
|
|
158
|
+
mutationFn: () => (kind === 'apply' ? api.applyEmailAuth() : api.rollbackEmailAuth()),
|
|
159
|
+
onSuccess: () => qc.invalidateQueries({ queryKey: commsKeys.emailAuth(api.slug) }),
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
125
163
|
export function useCheckDomain(api: CommsApi): UseMutationResult<CommsSettings, Error, void> {
|
|
126
164
|
return useSettingsWrite(api, () => api.checkDomain());
|
|
127
165
|
}
|
package/src/comms/types/index.ts
CHANGED
|
@@ -35,6 +35,83 @@ export interface DomainRecord {
|
|
|
35
35
|
purpose?: DomainRecordPurpose;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
/** One record of the live SPF / DKIM / DMARC diagnosis (GET settings/domain/email-auth/). */
|
|
39
|
+
export type EmailAuthStatus = 'ok' | 'warn' | 'fail' | 'missing';
|
|
40
|
+
|
|
41
|
+
export interface EmailAuthRecord {
|
|
42
|
+
purpose: DomainRecordPurpose;
|
|
43
|
+
type: string;
|
|
44
|
+
host: string;
|
|
45
|
+
status: EmailAuthStatus;
|
|
46
|
+
/** Plain-language why. */
|
|
47
|
+
reason: string;
|
|
48
|
+
/** What DNS holds now ('' if nothing). */
|
|
49
|
+
current: string;
|
|
50
|
+
/** The value to publish ('' when nothing needs to change). */
|
|
51
|
+
recommended: string;
|
|
52
|
+
policy?: string;
|
|
53
|
+
inherited_from?: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface DmarcSource {
|
|
57
|
+
source_ip: string;
|
|
58
|
+
messages: number;
|
|
59
|
+
dmarc_fail: number;
|
|
60
|
+
reporters: string[];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface DmarcReportSummary {
|
|
64
|
+
days: number;
|
|
65
|
+
reports: number;
|
|
66
|
+
messages: number;
|
|
67
|
+
dmarc_fail: number;
|
|
68
|
+
pass_rate: number | null;
|
|
69
|
+
last_report_at: string | null;
|
|
70
|
+
sources: DmarcSource[];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Where the DMARC policy can go next, with the evidence that says whether it is safe. */
|
|
74
|
+
export interface DmarcLadder {
|
|
75
|
+
policy: string;
|
|
76
|
+
/** Next policy step, null at p=reject or when there is no DMARC record. */
|
|
77
|
+
next: 'quarantine' | 'reject' | null;
|
|
78
|
+
ready: boolean;
|
|
79
|
+
/** The full record with the next policy substituted ('' when there is no next step). */
|
|
80
|
+
recommended: string;
|
|
81
|
+
evidence: { days: number; reports: number; messages: number; dmarc_fail: number };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface EmailAuthDiagnosis {
|
|
85
|
+
domain: string;
|
|
86
|
+
/** The worst record status. */
|
|
87
|
+
status: EmailAuthStatus;
|
|
88
|
+
records: EmailAuthRecord[];
|
|
89
|
+
ladder?: DmarcLadder;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** The foundry's registrar DNS account (GET/PUT foundry/tenants/{slug}/dns-connection/). Secrets are never returned. */
|
|
93
|
+
export interface DnsConnection {
|
|
94
|
+
provider: 'namecheap' | 'cloudflare';
|
|
95
|
+
connected: boolean;
|
|
96
|
+
zone_name: string;
|
|
97
|
+
has_token: boolean;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface NamecheapConnectInput {
|
|
101
|
+
api_user: string;
|
|
102
|
+
api_key: string;
|
|
103
|
+
client_ip: string;
|
|
104
|
+
username?: string;
|
|
105
|
+
zone_name: string;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** POST email-auth/apply/ and /rollback/. */
|
|
109
|
+
export interface EmailAuthChange {
|
|
110
|
+
applied: boolean;
|
|
111
|
+
rolled_back?: boolean;
|
|
112
|
+
records: string[];
|
|
113
|
+
}
|
|
114
|
+
|
|
38
115
|
export interface SourceRepo {
|
|
39
116
|
provider: 'github';
|
|
40
117
|
owner: string;
|
|
@@ -48,7 +48,7 @@ const MicIcon = () => (
|
|
|
48
48
|
);
|
|
49
49
|
const StopIcon = () => <span aria-hidden="true" className="inline-block h-3.5 w-3.5 rounded-sm bg-current" />;
|
|
50
50
|
|
|
51
|
-
const EMPTY: MeetingState = { phase: 'idle', retryable: false, lines: [], error: null, noAudio: null, conversationId: null, saved: null, relayNotice: null, micOn: false, micLive: false };
|
|
51
|
+
const EMPTY: MeetingState = { phase: 'idle', retryable: false, lines: [], error: null, noAudio: null, conversationId: null, saved: null, relayNotice: null, micOn: false, micLive: false, hearing: false };
|
|
52
52
|
|
|
53
53
|
export function ConversePage({ client, meeting, createIO, savedLink, notify, cards: hostCards, assistantName = ASSISTANT_NAME }: ConversePageProps) {
|
|
54
54
|
const [state, setState] = React.useState<MeetingState>(EMPTY);
|
package/src/corpus/ask-items.ts
CHANGED
|
@@ -79,7 +79,13 @@ export function selectItems(items: Commitment[], intent: ItemIntent, ctx: ItemCo
|
|
|
79
79
|
(dueDay(a.dueAt, zone) ?? '9999').localeCompare(dueDay(b.dueAt, zone) ?? '9999') || (a.priority ?? 9) - (b.priority ?? 9));
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
/**
|
|
82
|
+
/** Tracker keys a question names ("What is ENG-141 about?"): whole keys, upper-cased, in order, deduped. */
|
|
83
|
+
export function itemKeysIn(question: string): string[] {
|
|
84
|
+
const found = question.match(/(?<![A-Za-z0-9-])[A-Za-z][A-Za-z0-9]{1,9}-\d{1,6}(?![A-Za-z0-9-])/g) ?? [];
|
|
85
|
+
return [...new Set(found.map((k) => k.toUpperCase()))];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Items for a question: read, scope-check, select, convert. Empty when it is not an item question. A question that names an item by its key reads that item, whatever its words or dates. */
|
|
83
89
|
export async function retrieveItems(
|
|
84
90
|
question: string,
|
|
85
91
|
api: Pick<CommitmentApi, 'listCommitments'> | undefined,
|
|
@@ -88,16 +94,20 @@ export async function retrieveItems(
|
|
|
88
94
|
limit: number,
|
|
89
95
|
): Promise<{ intent: ItemIntent | null; retrieved: RetrievedDocument[]; matched: number }> {
|
|
90
96
|
const intent = itemIntent(question, ctx.now, ctx.timeZone);
|
|
91
|
-
|
|
97
|
+
const keys = itemKeysIn(question);
|
|
98
|
+
if ((!intent && !keys.length) || !api) return { intent: null, retrieved: [], matched: 0 };
|
|
92
99
|
const page = await api.listCommitments({ pageSize: 200, sort: 'due', withFocus: true }).catch(() => null);
|
|
93
|
-
if (!page) return { intent, retrieved: [], matched: 0 };
|
|
100
|
+
if (!page) return { intent: intent ?? null, retrieved: [], matched: 0 };
|
|
94
101
|
// The project names load beside the item list (the caller starts both), so they are awaited only now.
|
|
95
102
|
const names = await Promise.resolve(ctx.focusNames).catch(() => undefined);
|
|
96
103
|
const resolved = { ...ctx, focusNames: names };
|
|
97
|
-
const
|
|
104
|
+
const inScope = page.results.filter((item) => isInScope(item, scope));
|
|
105
|
+
// Named by key: exactly those items, finished ones included (that is what was asked for). No such key: fall back to the intent.
|
|
106
|
+
const named = keys.length ? inScope.filter((item) => item.sync?.key && keys.includes(item.sync.key.toUpperCase())) : [];
|
|
107
|
+
const selected = named.length || !intent ? named : selectItems(inScope, intent, resolved);
|
|
98
108
|
const retrieved = selected.slice(0, limit).map((item): RetrievedDocument => {
|
|
99
109
|
const document = itemAsDocument(item, resolved);
|
|
100
110
|
return { document, score: 1, matchedTerms: [], snippet: document.body.split('\n').slice(0, 2).join(' · ') };
|
|
101
111
|
});
|
|
102
|
-
return { intent, retrieved, matched: selected.length };
|
|
112
|
+
return { intent: intent ?? null, retrieved, matched: selected.length };
|
|
103
113
|
}
|
|
@@ -28,6 +28,7 @@ import { localDate } from '../today';
|
|
|
28
28
|
import { questionWindow } from '../ask-items-intent';
|
|
29
29
|
import { BRIEF_ME, NEEDS_ME, buildQueue, firstPrompt, relayItemsFrom, startBriefing, stepBriefing, type BriefingEffect, type BriefingState } from './briefing-queue';
|
|
30
30
|
import type { ConverseBrain, ConverseSource, HistoryLine } from './types';
|
|
31
|
+
import { isGiveUp } from '../give-up';
|
|
31
32
|
|
|
32
33
|
const MIN_AUTO = 0.85;
|
|
33
34
|
/** A spoken answer is read in full, but not forever. */
|
|
@@ -122,7 +123,6 @@ export function speakableAnswer(answer: string): string {
|
|
|
122
123
|
|
|
123
124
|
/** What is said when Ask has nothing usable: say what cannot be seen, never a raw status word. */
|
|
124
125
|
export const CANNOT_SEE = 'I could not find anything about that in your items or notes. You can ask what is due this week, or tell me what to add.';
|
|
125
|
-
const GIVE_UP = /^\W*(unanswerable|unknown|n\/a|none|null|undefined)\W*$/i;
|
|
126
126
|
|
|
127
127
|
/** Times each awaited step into `timings` (a step that runs twice adds up). */
|
|
128
128
|
function stopwatch() {
|
|
@@ -162,7 +162,7 @@ export function createConverseBrain(deps: ConverseBrainDeps): ConverseBrain {
|
|
|
162
162
|
if (!deps.answerFrom) return { text: NO_FLEET_STATUS, forRelay: true, intent: 'relay' as const };
|
|
163
163
|
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(() => ''));
|
|
164
164
|
const spoken = speakableAnswer(said);
|
|
165
|
-
const body = !spoken ||
|
|
165
|
+
const body = !spoken || isGiveUp(spoken) ? speakableAnswer(snap.text.split('\n').filter((l) => l.trim() && !l.startsWith('#')).slice(0, 4).join(' ')) : spoken;
|
|
166
166
|
if (!stale) return { text: body, intent: 'question' as const };
|
|
167
167
|
// The age is added here, not left to the model: a snapshot must never sound live.
|
|
168
168
|
const age = ageWords(snap.updatedAt, now);
|
|
@@ -307,7 +307,7 @@ export function createConverseBrain(deps: ConverseBrainDeps): ConverseBrain {
|
|
|
307
307
|
const answered = await (earlyAsk ?? timed('ask', () => deps.ask({ question: askQuestion(utterance, history), timeZone, now })));
|
|
308
308
|
// The screen gets the whole answer (cleaned for reading); the voice gets a short version of a long one.
|
|
309
309
|
const full = speakable(answered.answer ?? '', 400) || (answered.answer ?? '').trim();
|
|
310
|
-
if (!full ||
|
|
310
|
+
if (!full || isGiveUp(full)) return { text: CANNOT_SEE, intent: 'question' as const };
|
|
311
311
|
const short = spokenSummary(full);
|
|
312
312
|
const sources = answered.sources ?? (answered.citations ? askSources(answered) : undefined);
|
|
313
313
|
const listed: PlayedItem[] = (sources ?? []).filter((x) => x.id.startsWith('item:')).map((x) => ({ id: x.id.replace(/^item:/, ''), title: x.title }));
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** A model's non-answer ("unanswerable", "unanswerable: true", "n/a", ...) as the WHOLE of an answer: never shown, treated as no answer. */
|
|
2
|
+
const GIVE_UP = /^\W*(unanswerable|unknown|n\/a|none|null|undefined)(\W+(true|false))?\W*$/i;
|
|
3
|
+
|
|
4
|
+
export const isGiveUp = (text: string): boolean => GIVE_UP.test(text);
|
package/src/corpus/llm.ts
CHANGED
|
@@ -20,6 +20,7 @@ import { SpeechService } from '@startsimpli/llm/speech';
|
|
|
20
20
|
import type { SpeechServiceConfig } from '@startsimpli/llm/speech';
|
|
21
21
|
|
|
22
22
|
import { answerSystemPrompt, renderAnswerPrompt } from './ask';
|
|
23
|
+
import { isGiveUp } from './give-up';
|
|
23
24
|
import { classifySystemPrompt, renderClassifyPrompt } from './classify';
|
|
24
25
|
import { renderTeamPrompt, teamSystemPrompt } from './classify-team';
|
|
25
26
|
import {
|
|
@@ -172,7 +173,10 @@ export function parseAnswerDraft(raw: string): AnswerDraft | null {
|
|
|
172
173
|
const extraction = extractJson(raw);
|
|
173
174
|
if (!extraction.success || !extraction.json || typeof extraction.json !== 'object') return null;
|
|
174
175
|
const json = extraction.json as Record<string, unknown>;
|
|
175
|
-
const
|
|
176
|
+
const rawAnswer = typeof json.answer === 'string' ? json.answer : '';
|
|
177
|
+
// The model wrote its give-up INTO the answer string: that is no answer, not something to show.
|
|
178
|
+
if (rawAnswer && isGiveUp(rawAnswer)) return { answer: '', citations: [], unanswerable: true };
|
|
179
|
+
const answer = rawAnswer;
|
|
176
180
|
if (!answer && json.unanswerable !== true) return null;
|
|
177
181
|
const citations = Array.isArray(json.citations)
|
|
178
182
|
? json.citations
|