@startsimpli/integrations 0.2.163 → 0.2.164
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 +3 -3
- package/src/__tests__/converse-brain.test.ts +20 -3
- package/src/corpus/converse/brain.ts +6 -1
- package/src/corpus/converse/index.ts +1 -0
- package/src/native/app/FoundryApp.tsx +1 -1
- package/src/native/app/__tests__/launch.test.ts +1 -1
- package/src/native/app/converseServices.ts +4 -2
- package/src/native/app/launch.ts +4 -0
- package/src/native/app/services.ts +2 -2
- package/src/native/converse/__tests__/controller.test.ts +7 -0
- package/src/native/converse/api.ts +11 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@startsimpli/integrations",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.164",
|
|
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,9 +50,9 @@
|
|
|
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/utils": "^0.4.18",
|
|
53
54
|
"@startsimpli/auth": "^0.4.52",
|
|
54
|
-
"@startsimpli/ui": "^0.4.182"
|
|
55
|
-
"@startsimpli/utils": "^0.4.18"
|
|
55
|
+
"@startsimpli/ui": "^0.4.182"
|
|
56
56
|
},
|
|
57
57
|
"peerDependenciesMeta": {
|
|
58
58
|
"react": {
|
|
@@ -34,16 +34,33 @@ function setup() {
|
|
|
34
34
|
};
|
|
35
35
|
const scope = { orgId: 'org', userId: ME } as never;
|
|
36
36
|
const ask = vi.fn(async () => ({ answer: 'Two things are due today: the bench and printer paper.' }));
|
|
37
|
-
const
|
|
37
|
+
const deps = {
|
|
38
38
|
ownerSub: ME,
|
|
39
39
|
loadItems: async () => [...rows.values()].filter((r) => r.entity_type === 'commitment').map((r) => ({ id: r.id, title: r.data.title, status: r.data.status, dueAt: r.data.due_at, ownerSub: ME })) as never,
|
|
40
40
|
seam: commitmentEditSeam({ api: createPlanningApi({ http: http as never, scope }), http: http as never, scope }),
|
|
41
41
|
log: createEntityActionLog(http as never, ME),
|
|
42
42
|
ask,
|
|
43
|
-
}
|
|
44
|
-
|
|
43
|
+
};
|
|
44
|
+
const brain = createConverseBrain(deps);
|
|
45
|
+
return { rows, brain, ask, deps };
|
|
45
46
|
}
|
|
46
47
|
|
|
48
|
+
describe('a conversational turn never says "unanswerable"', () => {
|
|
49
|
+
const brainWith = (answer: string, status?: string) => {
|
|
50
|
+
const s = setup();
|
|
51
|
+
return createConverseBrain({ ...(s.deps as any), ask: async () => ({ answer, status }) });
|
|
52
|
+
};
|
|
53
|
+
it.each([['unanswerable'], ['Unanswerable.'], [' '], ['']])('says what it cannot see instead of %j', async (answer) => {
|
|
54
|
+
const out = await brainWith(answer, 'no_evidence')({ utterance: 'What is on my plate today?', history: [], timeZone: TZ, now: NOW });
|
|
55
|
+
expect(out.text.toLowerCase()).not.toContain('unanswerable');
|
|
56
|
+
expect(out.text).toMatch(/could not find|don't see|do not see/i);
|
|
57
|
+
});
|
|
58
|
+
it('a real answer is passed through', async () => {
|
|
59
|
+
const out = await brainWith('The bench is due today.', 'answered')({ utterance: 'what is due', history: [], timeZone: TZ, now: NOW });
|
|
60
|
+
expect(out.text).toBe('The bench is due today');
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
47
64
|
describe('converse brain', () => {
|
|
48
65
|
it('a plain sure instruction edits the item and says what it did', async () => {
|
|
49
66
|
const s = setup();
|
|
@@ -53,6 +53,10 @@ export function speakableAnswer(answer: string): string {
|
|
|
53
53
|
return speakable(answer, MAX_SPOKEN_WORDS) || answer.trim();
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
/** What is said when Ask has nothing usable: say what cannot be seen, never a raw status word. */
|
|
57
|
+
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.';
|
|
58
|
+
const GIVE_UP = /^\W*(unanswerable|unknown|n\/a|none|null|undefined)\W*$/i;
|
|
59
|
+
|
|
56
60
|
export function createConverseBrain(deps: ConverseBrainDeps): ConverseBrain {
|
|
57
61
|
return async ({ utterance, history, timeZone, now }) => {
|
|
58
62
|
const open = (await deps.loadItems().catch(() => [] as BriefingItem[])).map(intentItem);
|
|
@@ -73,7 +77,8 @@ export function createConverseBrain(deps: ConverseBrainDeps): ConverseBrain {
|
|
|
73
77
|
}
|
|
74
78
|
|
|
75
79
|
const answered = await deps.ask({ question: questionWithHistory(utterance, history), timeZone, now });
|
|
76
|
-
|
|
80
|
+
const spoken = speakableAnswer(answered.answer ?? '');
|
|
81
|
+
return { text: !spoken || GIVE_UP.test(spoken) ? CANNOT_SEE : spoken };
|
|
77
82
|
};
|
|
78
83
|
}
|
|
79
84
|
|
|
@@ -56,7 +56,7 @@ function Root({ config, device, registry }: { config: FoundryAppConfig; device:
|
|
|
56
56
|
);
|
|
57
57
|
const { banners, services } = useMemo(() => {
|
|
58
58
|
const b = createBanners();
|
|
59
|
-
return { banners: b, services: createFoundryServices({ config, device, banners: b, strings, fakeConverse: launch.fakeConverse, fakeBriefing: launch.fakeBriefing ? { corpus: fakeCorpus as FakeNativeCorpusApi, script: launch.fakeReply } : null }) };
|
|
59
|
+
return { banners: b, services: createFoundryServices({ config, device, banners: b, strings, fakeConverse: launch.fakeConverse, fakeConverseSound: launch.fakeConverseSound, fakeBriefing: launch.fakeBriefing ? { corpus: fakeCorpus as FakeNativeCorpusApi, script: launch.fakeReply } : null }) };
|
|
60
60
|
}, [config, device, strings, launch, fakeCorpus]);
|
|
61
61
|
// The engine is the device's; a haptic that throws (no taptic hardware, simulator) never breaks a screen.
|
|
62
62
|
// Every call is logged to the diagnostics (`haptic`, then `haptic.result`) so a device run proves the engine was invoked.
|
|
@@ -7,7 +7,7 @@ const args = (o: Record<string, string>) => (k: string) => o[k];
|
|
|
7
7
|
|
|
8
8
|
describe('readLaunch', () => {
|
|
9
9
|
it('a plain launch is real mode with nothing to open', () => {
|
|
10
|
-
expect(readLaunch(args({}), config)).toEqual({ fake: false, scenario: 'normal', target: null, autostop: null, scheme: null, hapticProbe: false, fakeBriefing: false, fakeConverse: false, fakeReply: [] });
|
|
10
|
+
expect(readLaunch(args({}), config)).toEqual({ fake: false, scenario: 'normal', target: null, autostop: null, scheme: null, hapticProbe: false, fakeBriefing: false, fakeConverse: false, fakeConverseSound: false, fakeReply: [] });
|
|
11
11
|
});
|
|
12
12
|
it('-tgFakeTabs with -tgTab and -tgDetail', () => {
|
|
13
13
|
expect(readLaunch(args({ tgFakeTabs: '1', tgTab: 'tracker', tgDetail: 'c1' }), config)).toMatchObject({ fake: true, target: { tab: 'tracker', id: 'c1' } });
|
|
@@ -24,8 +24,10 @@ export function createConverse(deps: {
|
|
|
24
24
|
session: ReturnType<typeof createSession>;
|
|
25
25
|
diag: ReturnType<typeof createDiagnostics>;
|
|
26
26
|
fake: boolean;
|
|
27
|
+
/** The fake speaks its replies (the bundled clip). Off: text only, silent. */
|
|
28
|
+
fakeSound?: boolean;
|
|
27
29
|
}) {
|
|
28
|
-
const { config, device, session, diag, fake } = deps;
|
|
30
|
+
const { config, device, session, diag, fake, fakeSound } = deps;
|
|
29
31
|
const rec = device.recording;
|
|
30
32
|
if (!rec) throw new Error('features.converse needs the recording bindings (features.recording on, device.recording supplied)');
|
|
31
33
|
const dev = device.briefing;
|
|
@@ -37,7 +39,7 @@ export function createConverse(deps: {
|
|
|
37
39
|
});
|
|
38
40
|
const permissions = createPermissionFlow({ perms: rec.permissions, openSettings: rec.openSettings, log: diag.log });
|
|
39
41
|
const api = fake
|
|
40
|
-
? createFakeConverseApi({ ...(dev.fixture ? { fixture: dev.fixture } : {}) })
|
|
42
|
+
? createFakeConverseApi({ ...(fakeSound && dev.fixture ? { fixture: dev.fixture } : {}) })
|
|
41
43
|
: createConverseApi({ tandemUrl: config.tenant.url, authorizedFetch: session.authorizedFetch, bearer: session.bearer, filePart: rec.filePart });
|
|
42
44
|
const controller = createConverseController({
|
|
43
45
|
api, audio, speaker: player, removeFile: rec.removeFile, ensurePermission: permissions.ensure, newId: newTurnId, diag, allowSilence: fake,
|
package/src/native/app/launch.ts
CHANGED
|
@@ -14,6 +14,7 @@ import type { FoundryAppConfig } from './config/types';
|
|
|
14
14
|
* -tgFakeBriefing 1 'What's on the plate' plays a bundled clip over a fixed briefing: no server, no sign-in (add -tgFakeTabs 1)
|
|
15
15
|
* -tgFakeReply "a|b" what the fake reply 'hears' on each hold-to-talk, in order (needs -tgFakeBriefing); default "move this one to later"
|
|
16
16
|
* -tgFakeConverse 1 the Converse tab talks to a scripted assistant: no server, no sign-in (add -tgFakeTabs 1)
|
|
17
|
+
* -tgFakeConverseSound 1 with -tgFakeConverse: speak the replies with the bundled clip (audible: opt-in only)
|
|
17
18
|
* -tgHapticProbe 1 fire one haptic per interaction through the real engine; the diagnostics log shows each call and the engine's answer
|
|
18
19
|
* -tgScheme light|dark override the config's theme mode (simulator checks of the light theme)
|
|
19
20
|
*/
|
|
@@ -32,6 +33,8 @@ export interface LaunchArgs {
|
|
|
32
33
|
fakeReply: string[];
|
|
33
34
|
/** `-tgFakeConverse 1`: the Converse tab talks to a scripted assistant (and speaks with the bundled clip). */
|
|
34
35
|
fakeConverse: boolean;
|
|
36
|
+
/** `-tgFakeConverseSound 1`: the fake assistant's replies are spoken with the bundled clip. Off by default so simulator runs are silent. */
|
|
37
|
+
fakeConverseSound: boolean;
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
export function readLaunch(get: (key: string) => unknown, config: Pick<FoundryAppConfig, 'tabs'>): LaunchArgs {
|
|
@@ -54,6 +57,7 @@ export function readLaunch(get: (key: string) => unknown, config: Pick<FoundryAp
|
|
|
54
57
|
target,
|
|
55
58
|
autostop: Number.isFinite(n) && n > 0 ? n : null,
|
|
56
59
|
fakeConverse: str('tgFakeConverse') === '1',
|
|
60
|
+
fakeConverseSound: str('tgFakeConverseSound') === '1',
|
|
57
61
|
hapticProbe: str('tgHapticProbe') === '1',
|
|
58
62
|
fakeBriefing: str('tgFakeBriefing') === '1',
|
|
59
63
|
fakeReply: str('tgFakeReply').split('|').map((l) => l.trim()).filter(Boolean),
|
|
@@ -105,7 +105,7 @@ function createRecording(deps: { config: FoundryAppConfig; device: FoundryDevice
|
|
|
105
105
|
* The composition root: session (sign-in, refresh, sign-out), diagnostics, the link router and, when recording is on,
|
|
106
106
|
* the recorder with its upload queue. The app shell passes the device bindings; nothing here is Foundry-specific.
|
|
107
107
|
*/
|
|
108
|
-
export function createFoundryServices(deps: { config: FoundryAppConfig; device: FoundryDevice; banners: Banners; strings: FoundryStrings; /** `-tgFakeBriefing`: a fixed briefing and the device's bundled clip over the fake tenant (and `-tgFakeReply`'s script). */ fakeBriefing?: FakeBriefingDeps | null; /** `-tgFakeConverse`: the Converse tab talks to a scripted assistant. */ fakeConverse?: boolean }) {
|
|
108
|
+
export function createFoundryServices(deps: { config: FoundryAppConfig; device: FoundryDevice; banners: Banners; strings: FoundryStrings; /** `-tgFakeBriefing`: a fixed briefing and the device's bundled clip over the fake tenant (and `-tgFakeReply`'s script). */ fakeBriefing?: FakeBriefingDeps | null; /** `-tgFakeConverse`: the Converse tab talks to a scripted assistant. */ fakeConverse?: boolean; fakeConverseSound?: boolean }) {
|
|
109
109
|
const { config, device, banners } = deps;
|
|
110
110
|
const diagPath = device.documentUri('diagnostics.json');
|
|
111
111
|
const diag = createDiagnostics({
|
|
@@ -128,7 +128,7 @@ export function createFoundryServices(deps: { config: FoundryAppConfig; device:
|
|
|
128
128
|
|
|
129
129
|
const briefing = config.features.briefing ? createBriefing({ config, device, session, diag, strings: deps.strings, fake: deps.fakeBriefing ?? null }) : null;
|
|
130
130
|
|
|
131
|
-
const converse = config.features.converse ? createConverse({ config, device, session, diag, fake: Boolean(deps.fakeConverse) }) : null;
|
|
131
|
+
const converse = config.features.converse ? createConverse({ config, device, session, diag, fake: Boolean(deps.fakeConverse), fakeSound: Boolean(deps.fakeConverseSound) }) : null;
|
|
132
132
|
|
|
133
133
|
let open: (tab: string, id?: string) => void = () => undefined;
|
|
134
134
|
const goTab = config.tabs.find((t) => t.screen === 'record')?.key;
|
|
@@ -180,3 +180,10 @@ describe('converse api', () => {
|
|
|
180
180
|
expect(f.ended).toEqual(['fake-conversation']);
|
|
181
181
|
});
|
|
182
182
|
});
|
|
183
|
+
|
|
184
|
+
describe('converse api timeout', () => {
|
|
185
|
+
it('a turn that never answers fails instead of hanging', async () => {
|
|
186
|
+
const api = createConverseApi({ tandemUrl: 'http://t', authorizedFetch: (() => new Promise(() => undefined)) as never, bearer: async () => null, createForm: () => new FormData(), timeoutMs: 20 });
|
|
187
|
+
await expect(api.send({ conversationId: null, text: 'x' })).rejects.toThrow(/no answer/);
|
|
188
|
+
});
|
|
189
|
+
});
|
|
@@ -31,6 +31,14 @@ export interface ConverseApi {
|
|
|
31
31
|
|
|
32
32
|
interface Wire { conversation_id: string; transcript?: string; reply_text?: string; audio_url?: string | null }
|
|
33
33
|
|
|
34
|
+
/** Rejects with a plain (retryable) error after `ms`, and aborts the request when it can. */
|
|
35
|
+
async function withTimeout<T>(ms: number, run: (signal: AbortSignal) => Promise<T>): Promise<T> {
|
|
36
|
+
const ctl = new AbortController();
|
|
37
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
38
|
+
const late = new Promise<never>((_, reject) => { timer = setTimeout(() => { ctl.abort(); reject(new Error(`no answer after ${Math.round(ms / 1000)} s`)); }, ms); });
|
|
39
|
+
try { return await Promise.race([run(ctl.signal), late]); } finally { clearTimeout(timer); }
|
|
40
|
+
}
|
|
41
|
+
|
|
34
42
|
async function refusal(res: Response, what: string): Promise<Error> {
|
|
35
43
|
const detail = await res.json().catch(() => ({})) as { detail?: string; code?: string };
|
|
36
44
|
return Object.assign(new Error(detail.detail || `${what} failed (${res.status})`), { status: res.status, ...(detail.code ? { code: detail.code } : {}) });
|
|
@@ -47,6 +55,8 @@ export function createConverseApi(deps: {
|
|
|
47
55
|
filePart?: (uri: string) => Blob;
|
|
48
56
|
createForm?: () => FormData;
|
|
49
57
|
timeZone?: string;
|
|
58
|
+
/** A turn that has not answered by then fails (retryably) instead of leaving the screen on 'Thinking' for good. Default 120 s. */
|
|
59
|
+
timeoutMs?: number;
|
|
50
60
|
}): ConverseApi {
|
|
51
61
|
const base = deps.tandemUrl.replace(/\/+$/, '');
|
|
52
62
|
const timeZone = deps.timeZone ?? (() => { try { return Intl.DateTimeFormat().resolvedOptions().timeZone; } catch { return undefined; } })();
|
|
@@ -61,7 +71,7 @@ export function createConverseApi(deps: {
|
|
|
61
71
|
if (request.conversationId) body.append('conversation_id', request.conversationId);
|
|
62
72
|
if (request.turnId) body.append('turn_id', request.turnId);
|
|
63
73
|
if (timeZone) body.append('timeZone', timeZone);
|
|
64
|
-
const res = await deps.authorizedFetch(`${base}/corpus/converse`, { method: 'POST', body });
|
|
74
|
+
const res = await withTimeout(deps.timeoutMs ?? 120_000, (signal) => deps.authorizedFetch(`${base}/corpus/converse`, { method: 'POST', body, signal }));
|
|
65
75
|
if (!res.ok) throw await refusal(res, 'POST /corpus/converse');
|
|
66
76
|
const w = (await res.json()) as Wire;
|
|
67
77
|
return { conversationId: w.conversation_id, transcript: w.transcript ?? '', replyText: w.reply_text ?? '', audioUrl: w.audio_url ?? null };
|