@adminide-stack/clock-tik-mobile 12.0.37-alpha.1 → 12.0.37-alpha.2
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/CHANGELOG.md +12 -0
- package/jest.config.cjs +3 -0
- package/lib/chat/agent.js +40 -1
- package/lib/chat/agent.js.map +1 -1
- package/lib/chat/handover.js +196 -0
- package/lib/chat/handover.js.map +1 -0
- package/lib/chat/protocol.js +16 -2
- package/lib/chat/protocol.js.map +1 -1
- package/lib/components/HandoverCards.js +179 -0
- package/lib/components/HandoverCards.js.map +1 -0
- package/lib/components/ResultCards.js +3 -3
- package/lib/components/ResultCards.js.map +1 -1
- package/lib/screens/Chat/index.js +2 -1
- package/lib/screens/Chat/index.js.map +1 -1
- package/lib/utils/yantraLinks.js +26 -8
- package/lib/utils/yantraLinks.js.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/agent.test.ts +201 -0
- package/src/__tests__/chores.test.ts +4 -0
- package/src/__tests__/handover.test.ts +149 -0
- package/src/__tests__/protocol.test.ts +27 -2
- package/src/__tests__/yantraLinks.test.ts +66 -1
- package/src/chat/agent.ts +65 -0
- package/src/chat/handover.ts +241 -0
- package/src/chat/protocol.ts +23 -7
- package/src/components/HandoverCards.tsx +224 -0
- package/src/components/ResultCards.tsx +4 -3
- package/src/screens/Chat/index.tsx +6 -1
- package/src/utils/yantraLinks.ts +40 -10
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What Lucy hands over beside her words: a place to do a step herself can't (her Computer, to sign in to a site or pass
|
|
3
|
+
* a robot check; another of Yantra's surfaces), as a `[[surface:<id>|<what to do there>]]` marker, and something to
|
|
4
|
+
* connect or keep in the vault (a website login, a card, an app), as a `[CONNECTOR_CONNECT]{…}[/CONNECTOR_CONNECT]`
|
|
5
|
+
* card. The web chat draws both (browser surfaces.ts with CallsCard's SurfaceLinks, and the kit's ConnectorConnectCard).
|
|
6
|
+
* This chat used to take them out of the bubble and draw nothing, so "save it below" and "sign in on your Computer"
|
|
7
|
+
* pointed at nothing a phone could tap. components/HandoverCards.tsx draws them; these are the pure parts.
|
|
8
|
+
*
|
|
9
|
+
* The connect marker rules are a copy of the kit's (`@yantra/surface-kit` chat/connectorConnectProtocol.ts, itself a
|
|
10
|
+
* copy of yantra-app common's CONNECTOR_CONNECT_PROTOCOL): the documented shape, and the same shape whose closing tag
|
|
11
|
+
* the model left off. Keep the link in step with the kit's connectorConnectUrl, which Yantra's /connect page reads.
|
|
12
|
+
*/
|
|
13
|
+
import { surfaceLink, takeSurfaceMarkers } from '@adminide-stack/clock-tik-browser/lib/pages/Home/chat/surfaces.js';
|
|
14
|
+
|
|
15
|
+
/* ----------------------------------------------------------------------------- surfaces */
|
|
16
|
+
|
|
17
|
+
export interface SurfaceHandover {
|
|
18
|
+
/** The surface's own id, an alias resolved: `computer`. */
|
|
19
|
+
id: string;
|
|
20
|
+
/** "your Computer". */
|
|
21
|
+
title: string;
|
|
22
|
+
/** Its host's first label: `computer-surface`. */
|
|
23
|
+
host: string;
|
|
24
|
+
/** What Lucy said to do there ("Sign in to Flipkart"); may be empty. */
|
|
25
|
+
label: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The surfaces a reply hands over, each once, in order; one this chat cannot open is left out. */
|
|
29
|
+
export function surfaceHandovers(text: string): SurfaceHandover[] {
|
|
30
|
+
const seen = new Set<string>();
|
|
31
|
+
return takeSurfaceMarkers(text).markers.flatMap((marker) => {
|
|
32
|
+
const link = surfaceLink(marker.id);
|
|
33
|
+
if (!link || seen.has(link.id)) return [];
|
|
34
|
+
seen.add(link.id);
|
|
35
|
+
return [{ ...link, label: marker.label }];
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The card's button: "Open your Computer", "Open Phone Calls". */
|
|
40
|
+
export function surfaceButton(surface: Pick<SurfaceHandover, 'title'>): string {
|
|
41
|
+
return `Open ${surface.title}`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/* ----------------------------------------------------------------------------- connect cards */
|
|
45
|
+
|
|
46
|
+
export const SITE_LOGIN = 'site-login';
|
|
47
|
+
|
|
48
|
+
export interface ConnectHandover {
|
|
49
|
+
requestId: string;
|
|
50
|
+
/** A catalog connector's template key, `site-login`, or an autofill kind (`autofill-payment-card`). */
|
|
51
|
+
connector: string;
|
|
52
|
+
/** The card's name for it ("Flipkart login"). */
|
|
53
|
+
title?: string;
|
|
54
|
+
/** Why Lucy asks, one sentence. */
|
|
55
|
+
reason?: string;
|
|
56
|
+
/** For a website login: the site and the sign-in page her Computer is on. */
|
|
57
|
+
site?: string;
|
|
58
|
+
loginUrl?: string;
|
|
59
|
+
/** The saved entry the card updates, when Lucy names one. */
|
|
60
|
+
credentialId?: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const OPEN_TAG = /\[CONNECTOR_CONNECT\]\s*(?=\{)/g;
|
|
64
|
+
const CLOSE_TAG = /^\s*\[\/CONNECTOR_CONNECT\]/;
|
|
65
|
+
const SAFE_ID = /^[A-Za-z0-9_-]+$/;
|
|
66
|
+
|
|
67
|
+
/** The JSON object that opens at `text[start]`, through its matching `}`; null while it is still coming in. */
|
|
68
|
+
function balancedObject(text: string, start: number): string | null {
|
|
69
|
+
let depth = 0;
|
|
70
|
+
let inString = false;
|
|
71
|
+
for (let i = start; i < text.length; i += 1) {
|
|
72
|
+
const ch = text[i];
|
|
73
|
+
if (inString) {
|
|
74
|
+
if (ch === '\\') i += 1;
|
|
75
|
+
else if (ch === '"') inString = false;
|
|
76
|
+
} else if (ch === '"') inString = true;
|
|
77
|
+
else if (ch === '{') depth += 1;
|
|
78
|
+
else if (ch === '}') {
|
|
79
|
+
depth -= 1;
|
|
80
|
+
if (depth === 0) return text.slice(start, i + 1);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* A card's body opening at `text[start]`: the object through its matching `}`, or, for a body copied out of a tool result
|
|
88
|
+
* with its quotes still escaped (`{\"connector\":…}`, whose braces never balance), through the `}` before the closing
|
|
89
|
+
* tag or the end. null while it is still coming in.
|
|
90
|
+
*/
|
|
91
|
+
function cardBody(text: string, start: number): string | null {
|
|
92
|
+
const json = balancedObject(text, start);
|
|
93
|
+
if (json) return json;
|
|
94
|
+
const escaped = /^\{\s*\\"[\s\S]*?\}(?=\s*(?:\[\/CONNECTOR_CONNECT\]|$))/.exec(text.slice(start));
|
|
95
|
+
return escaped ? escaped[0] : null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const clean = (v: unknown): string | undefined => (typeof v === 'string' && v.trim() ? v.trim() : undefined);
|
|
99
|
+
|
|
100
|
+
function readBody(json: string): Record<string, unknown> | null {
|
|
101
|
+
const parse = (s: string) => {
|
|
102
|
+
try {
|
|
103
|
+
const body = JSON.parse(s) as unknown;
|
|
104
|
+
return body && typeof body === 'object' && !Array.isArray(body) ? (body as Record<string, unknown>) : null;
|
|
105
|
+
} catch {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
// A body copied out of a tool result with one level of escaping left on (`{\"connector\":…}`).
|
|
110
|
+
return parse(json) ?? (/^\{\s*\\"/.test(json) ? parse(json.replace(/\\(["\\])/g, '$1')) : null);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function toHandover(body: Record<string, unknown>, index: number): ConnectHandover | null {
|
|
114
|
+
// `provider` and `type` are what the model writes in place of `connector`.
|
|
115
|
+
const connector = clean(body.connector) ?? clean(body.provider) ?? clean(body.type);
|
|
116
|
+
if (!connector) return null;
|
|
117
|
+
const card: ConnectHandover = {
|
|
118
|
+
requestId: clean(body.requestId) ?? clean(body.id) ?? `connect-${index}`,
|
|
119
|
+
connector,
|
|
120
|
+
};
|
|
121
|
+
const title = clean(body.title) ?? clean(body.label) ?? clean(body.name);
|
|
122
|
+
const reason = clean(body.reason);
|
|
123
|
+
const credentialId = clean(body.credentialId) ?? clean(body.credential_id);
|
|
124
|
+
if (title) card.title = title;
|
|
125
|
+
if (reason) card.reason = reason;
|
|
126
|
+
if (credentialId && SAFE_ID.test(credentialId)) card.credentialId = credentialId;
|
|
127
|
+
// Only the fields the form reads, only as strings: the marker is model output. Nested under `form`, or flat.
|
|
128
|
+
const form = (body.form && typeof body.form === 'object' ? body.form : body) as Record<string, unknown>;
|
|
129
|
+
const site = clean(form.site);
|
|
130
|
+
const loginUrl = clean(form.loginUrl) ?? clean(form.login_url) ?? clean(form.url);
|
|
131
|
+
if (site) card.site = site;
|
|
132
|
+
if (loginUrl && /^https?:\/\//i.test(loginUrl)) card.loginUrl = loginUrl;
|
|
133
|
+
return card;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** Every finished connect card in a reply, in order; one still streaming in is left for the next read. */
|
|
137
|
+
export function connectHandovers(text: string): ConnectHandover[] {
|
|
138
|
+
const cards: ConnectHandover[] = [];
|
|
139
|
+
for (const m of text.matchAll(OPEN_TAG)) {
|
|
140
|
+
const start = (m.index ?? 0) + m[0].length;
|
|
141
|
+
const json = cardBody(text, start);
|
|
142
|
+
const body = json ? readBody(json) : null;
|
|
143
|
+
const card = body ? toHandover(body, cards.length) : null;
|
|
144
|
+
if (card && !cards.some((c) => c.requestId === card.requestId)) cards.push(card);
|
|
145
|
+
}
|
|
146
|
+
return cards;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Every connect card's text, gone from the words: finished, missing its closing tag, or still coming in. */
|
|
150
|
+
export function stripConnectCards(text: string): string {
|
|
151
|
+
let out = '';
|
|
152
|
+
let at = 0;
|
|
153
|
+
// A tag inside a card already cut (index < at) went with that card.
|
|
154
|
+
for (const m of text.matchAll(OPEN_TAG)) {
|
|
155
|
+
const index = m.index ?? 0;
|
|
156
|
+
if (index >= at) {
|
|
157
|
+
out += text.slice(at, index);
|
|
158
|
+
const start = index + m[0].length;
|
|
159
|
+
const json = cardBody(text, start);
|
|
160
|
+
if (!json) return out; // still streaming in: nothing after it is the bubble's yet
|
|
161
|
+
const close = CLOSE_TAG.exec(text.slice(start + json.length));
|
|
162
|
+
at = start + json.length + (close ? close[0].length : 0);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
out += text.slice(at);
|
|
166
|
+
// An opening tag the cards above did not take (no body yet, or not JSON) runs to its closing tag or the end, as
|
|
167
|
+
// the bubble always cut it; a closing tag left on its own goes alone.
|
|
168
|
+
return out
|
|
169
|
+
.replace(/\[CONNECTOR_CONNECT\][\s\S]*?(?:\[\/CONNECTOR_CONNECT\]|$)/g, '')
|
|
170
|
+
.replace(/\[\/CONNECTOR_CONNECT\]/g, '');
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const isSiteLogin = (card: Pick<ConnectHandover, 'connector'>) => card.connector.toLowerCase() === SITE_LOGIN;
|
|
174
|
+
|
|
175
|
+
/** An autofill entry the vault keeps (a card, an address, a passport), as words: "payment card". */
|
|
176
|
+
function autofillNoun(connector: string): string | undefined {
|
|
177
|
+
const raw = connector.trim().toLowerCase();
|
|
178
|
+
if (!/^autofill[-_ ]/.test(raw)) return undefined;
|
|
179
|
+
return (
|
|
180
|
+
raw
|
|
181
|
+
.replace(/^autofill[-_ ]+/, '')
|
|
182
|
+
.replace(/[-_]+/g, ' ')
|
|
183
|
+
.trim() || undefined
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** What the card connects, as it names it: "Flipkart login", "Google Calendar". */
|
|
188
|
+
export function connectName(card: ConnectHandover): string {
|
|
189
|
+
if (card.title) return card.title;
|
|
190
|
+
if (isSiteLogin(card)) return card.site ? `${card.site} login` : 'website login';
|
|
191
|
+
const noun = autofillNoun(card.connector);
|
|
192
|
+
if (noun) return noun;
|
|
193
|
+
const words = card.connector
|
|
194
|
+
.replace(/-app-[a-z0-9]+$/i, '')
|
|
195
|
+
.replace(/[_-]+/g, ' ')
|
|
196
|
+
.trim();
|
|
197
|
+
return words ? words.replace(/\b\w/g, (c) => c.toUpperCase()) : card.connector;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** The card's heading (the kit's connectorConnectHeading): "Save your Flipkart login", "Connect Google Calendar". */
|
|
201
|
+
export function connectHeading(card: ConnectHandover): string {
|
|
202
|
+
const noun = autofillNoun(card.connector);
|
|
203
|
+
if (noun && !card.title) return `${card.credentialId ? 'Update' : 'Add'} your ${noun}`;
|
|
204
|
+
if (isSiteLogin(card)) return `${card.credentialId ? 'Update' : 'Save'} your ${connectName(card)}`;
|
|
205
|
+
return `Connect ${connectName(card)}`;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** The button's word. */
|
|
209
|
+
export function connectButton(card: ConnectHandover): string {
|
|
210
|
+
if (card.credentialId) return 'Update';
|
|
211
|
+
if (isSiteLogin(card)) return 'Save';
|
|
212
|
+
return autofillNoun(card.connector) ? 'Add' : 'Connect';
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Yantra's page for the card (the kit's connectorConnectUrl): `/connect/<connector>` with the site, the sign-in page
|
|
217
|
+
* and the entry it updates, `via=surface` because no gateway answers this chat. '' without an app.
|
|
218
|
+
*/
|
|
219
|
+
export function connectUrl(appUrl: string, card: ConnectHandover): string {
|
|
220
|
+
const base = appUrl.trim().replace(/\/+$/, '');
|
|
221
|
+
if (!base) return '';
|
|
222
|
+
const params: string[] = [];
|
|
223
|
+
const add = (key: string, value: string) => params.push(`${key}=${encodeURIComponent(value)}`);
|
|
224
|
+
if (SAFE_ID.test(card.requestId)) add('request', card.requestId);
|
|
225
|
+
add('via', 'surface');
|
|
226
|
+
if (card.title) add('title', card.title);
|
|
227
|
+
if (card.credentialId) add('credential', card.credentialId);
|
|
228
|
+
if (isSiteLogin(card)) {
|
|
229
|
+
if (card.site) add('site', card.site);
|
|
230
|
+
if (card.loginUrl) add('loginUrl', card.loginUrl);
|
|
231
|
+
}
|
|
232
|
+
return `${base}/connect/${encodeURIComponent(card.connector)}?${params.join('&')}`;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* What the person says back from a card once they have been there, so Lucy carries on without them typing it: "Done"
|
|
237
|
+
* is the word her Computer hand-over waits for (yantra-computer "When they say done"); a saved login she looks up.
|
|
238
|
+
*/
|
|
239
|
+
export function doneWords(kind: 'surface' | 'connect', name: string): string {
|
|
240
|
+
return kind === 'connect' ? `I saved my ${name}.` : 'Done';
|
|
241
|
+
}
|
package/src/chat/protocol.ts
CHANGED
|
@@ -8,6 +8,8 @@ import {
|
|
|
8
8
|
RESULT_CARDS_PROMPT,
|
|
9
9
|
takeResultWidgets,
|
|
10
10
|
} from '@adminide-stack/clock-tik-browser/lib/pages/Home/chat/results.js';
|
|
11
|
+
import { surfaceLink } from '@adminide-stack/clock-tik-browser/lib/pages/Home/chat/surfaces.js';
|
|
12
|
+
import { stripConnectCards } from './handover';
|
|
11
13
|
|
|
12
14
|
export const MAX_QUESTIONS = 6;
|
|
13
15
|
|
|
@@ -152,18 +154,32 @@ export function formatAskAnswers(ask: AskUser, answers: Record<string, AskAnswer
|
|
|
152
154
|
|
|
153
155
|
/* ----------------------------------------------------------------------------- display */
|
|
154
156
|
|
|
157
|
+
/** A surface marker as the gateway reads it (surfaces.ts MARKER): `[[surface:<id>]]` or `[[surface:<id>|<label>]]`. */
|
|
158
|
+
const SURFACE_MARKER = /[ \t]*\[\[\s*surface\s*:\s*([A-Za-z0-9_-]{1,40})\s*(?:\|\s*([^\]\n]{0,200}?))?\s*\]\]/gi;
|
|
159
|
+
|
|
160
|
+
/** The text without a surface marker still streaming in at its end (`[[surface:comp`), as surfaces.ts cuts it. */
|
|
161
|
+
function withoutUnfinishedSurface(text: string): string {
|
|
162
|
+
const at = text.lastIndexOf('[[');
|
|
163
|
+
if (at < 0) return text;
|
|
164
|
+
const tail = text.slice(at + 2);
|
|
165
|
+
if (tail.includes('\n') || tail.includes(']]')) return text;
|
|
166
|
+
const head = tail.trimStart().toLowerCase();
|
|
167
|
+
return head.startsWith('surface') || 'surface'.startsWith(head) ? text.slice(0, at) : text;
|
|
168
|
+
}
|
|
169
|
+
|
|
155
170
|
/**
|
|
156
171
|
* A reply's text as the bubble shows it: no question block (it has its own card), no result blocks in any of the forms
|
|
157
|
-
* a model writes them (fenced, under a bare marker, or still streaming in: they draw as cards), and
|
|
158
|
-
*
|
|
172
|
+
* a model writes them (fenced, under a bare marker, or still streaming in: they draw as cards), no Connect cards and no
|
|
173
|
+
* marker of a surface this chat opens (both drawn under the bubble, components/HandoverCards.tsx), other widgets
|
|
174
|
+
* dropped, and a surface this chat cannot open reduced to its plain label.
|
|
159
175
|
*/
|
|
160
176
|
export function displayText(text: string): string {
|
|
161
|
-
return takeResultWidgets(text)
|
|
162
|
-
.content.replace(ASK_RE_ALL, '')
|
|
163
|
-
.replace(/\[CONNECTOR_CONNECT\][\s\S]*?(?:\[\/CONNECTOR_CONNECT\]|$)/g, '')
|
|
177
|
+
return withoutUnfinishedSurface(stripConnectCards(takeResultWidgets(text).content.replace(ASK_RE_ALL, '')))
|
|
164
178
|
.replace(/```yantra:widget[\s\S]*?(?:```|$)/g, '')
|
|
165
|
-
.replace(
|
|
166
|
-
|
|
179
|
+
.replace(SURFACE_MARKER, (marker: string, id: string, label: string | undefined) =>
|
|
180
|
+
surfaceLink(id) ? '' : `${/^[ \t]*/.exec(marker)?.[0] ?? ''}${(label ?? id).trim()}`,
|
|
181
|
+
)
|
|
182
|
+
.replace(/^[ \t]+$/gm, '')
|
|
167
183
|
.replace(/\n{3,}/g, '\n\n')
|
|
168
184
|
.trim();
|
|
169
185
|
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What Lucy hands over under her words (chat/handover.ts): her computer, opened over the chat signed in, to sign in to
|
|
3
|
+
* a site or finish a step there; another of Yantra's surfaces; and a Connect card, for something to connect or keep in
|
|
4
|
+
* the vault, opened on Yantra's own form. Once the person has been there and come back, the card offers the words that
|
|
5
|
+
* tell Lucy to carry on, so they need not type them.
|
|
6
|
+
*/
|
|
7
|
+
import React, { useMemo, useState } from 'react';
|
|
8
|
+
import { Pressable, StyleSheet, Text, View } from 'react-native';
|
|
9
|
+
import { Ionicons } from '@expo/vector-icons';
|
|
10
|
+
import { agentAppUrl } from '../chat/auth';
|
|
11
|
+
import {
|
|
12
|
+
connectButton,
|
|
13
|
+
connectHandovers,
|
|
14
|
+
connectHeading,
|
|
15
|
+
connectName,
|
|
16
|
+
connectUrl,
|
|
17
|
+
doneWords,
|
|
18
|
+
surfaceButton,
|
|
19
|
+
surfaceHandovers,
|
|
20
|
+
type ConnectHandover,
|
|
21
|
+
type SurfaceHandover,
|
|
22
|
+
} from '../chat/handover';
|
|
23
|
+
import { surfaceUrl } from '../chat/results';
|
|
24
|
+
import { yantraAppUrl } from '../utils/links';
|
|
25
|
+
import { openYantraInSheet } from '../utils/yantraLinks';
|
|
26
|
+
import { tap } from '../welcome/haptics';
|
|
27
|
+
import { ConnectorLogo } from './ConnectorLogo';
|
|
28
|
+
import { ui } from '../theme/muse';
|
|
29
|
+
|
|
30
|
+
/** The Yantra app on Lucy's own environment (her agent names it), else the configured one: her computer lives there. */
|
|
31
|
+
const appUrl = (): Promise<string> =>
|
|
32
|
+
agentAppUrl()
|
|
33
|
+
.catch(() => '')
|
|
34
|
+
.then((app) => app || yantraAppUrl());
|
|
35
|
+
|
|
36
|
+
interface Props {
|
|
37
|
+
/** Lucy's reply as she wrote it, markers and all. */
|
|
38
|
+
text: string;
|
|
39
|
+
/** The newest reply, and Lucy done writing it: only then can the person answer from a card. */
|
|
40
|
+
live: boolean;
|
|
41
|
+
onReply: (words: string) => void;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function HandoverCards({ text, live, onReply }: Props) {
|
|
45
|
+
const surfaces = useMemo(() => surfaceHandovers(text), [text]);
|
|
46
|
+
const connects = useMemo(() => connectHandovers(text), [text]);
|
|
47
|
+
if (!surfaces.length && !connects.length) return null;
|
|
48
|
+
return (
|
|
49
|
+
<View style={s.stack}>
|
|
50
|
+
{surfaces.map((surface) => (
|
|
51
|
+
<SurfaceCard key={surface.id} surface={surface} live={live} onReply={onReply} />
|
|
52
|
+
))}
|
|
53
|
+
{connects.map((card) => (
|
|
54
|
+
<ConnectCard key={card.requestId} card={card} live={live} onReply={onReply} />
|
|
55
|
+
))}
|
|
56
|
+
</View>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Opens `link` (once it resolves) in the sheet; true once the person is back from it. */
|
|
61
|
+
function useOpened(): [boolean, (link: () => Promise<string>) => void] {
|
|
62
|
+
const [opened, setOpened] = useState(false);
|
|
63
|
+
const [opening, setOpening] = useState(false);
|
|
64
|
+
const open = (link: () => Promise<string>) => {
|
|
65
|
+
if (opening) return;
|
|
66
|
+
tap();
|
|
67
|
+
setOpening(true);
|
|
68
|
+
link()
|
|
69
|
+
.then((url) => (url ? openYantraInSheet(url).then(() => setOpened(true)) : undefined))
|
|
70
|
+
.catch(() => undefined)
|
|
71
|
+
.finally(() => setOpening(false));
|
|
72
|
+
};
|
|
73
|
+
return [opened, open];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** "Done" once they are back, while Lucy waits on it. */
|
|
77
|
+
function DoneButton({ label, words, onReply }: { label: string; words: string; onReply: (words: string) => void }) {
|
|
78
|
+
return (
|
|
79
|
+
<Pressable
|
|
80
|
+
accessibilityRole="button"
|
|
81
|
+
accessibilityLabel={label}
|
|
82
|
+
onPress={() => {
|
|
83
|
+
tap();
|
|
84
|
+
onReply(words);
|
|
85
|
+
}}
|
|
86
|
+
hitSlop={6}
|
|
87
|
+
style={({ pressed }) => [s.done, pressed && s.donePressed]}
|
|
88
|
+
>
|
|
89
|
+
<Ionicons name="checkmark" size={16} color={ui.surface} />
|
|
90
|
+
<Text style={s.doneText}>{label}</Text>
|
|
91
|
+
</Pressable>
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function SurfaceCard({
|
|
96
|
+
surface,
|
|
97
|
+
live,
|
|
98
|
+
onReply,
|
|
99
|
+
}: {
|
|
100
|
+
surface: SurfaceHandover;
|
|
101
|
+
live: boolean;
|
|
102
|
+
onReply: Props['onReply'];
|
|
103
|
+
}) {
|
|
104
|
+
const [opened, open] = useOpened();
|
|
105
|
+
const button = surfaceButton(surface);
|
|
106
|
+
return (
|
|
107
|
+
<View style={s.group}>
|
|
108
|
+
<Pressable
|
|
109
|
+
accessibilityRole="link"
|
|
110
|
+
accessibilityLabel={surface.label ? `${surface.label}. ${button}` : button}
|
|
111
|
+
accessibilityHint={`Opens ${surface.title} over the chat`}
|
|
112
|
+
onPress={() => open(() => appUrl().then((app) => surfaceUrl(surface.host, app)))}
|
|
113
|
+
style={({ pressed }) => [s.card, pressed && s.cardPressed]}
|
|
114
|
+
>
|
|
115
|
+
<View style={s.tile}>
|
|
116
|
+
<Ionicons
|
|
117
|
+
name={surface.id === 'computer' ? 'desktop-outline' : 'albums-outline'}
|
|
118
|
+
size={18}
|
|
119
|
+
color={ui.accentText}
|
|
120
|
+
/>
|
|
121
|
+
</View>
|
|
122
|
+
<View style={s.text}>
|
|
123
|
+
<Text style={s.title} numberOfLines={2}>
|
|
124
|
+
{surface.label || button}
|
|
125
|
+
</Text>
|
|
126
|
+
{surface.label ? <Text style={s.sub}>{button}</Text> : null}
|
|
127
|
+
</View>
|
|
128
|
+
<Ionicons name="arrow-up-outline" size={18} color={ui.ink2} style={s.out} />
|
|
129
|
+
</Pressable>
|
|
130
|
+
{opened && live ? (
|
|
131
|
+
<DoneButton label="Done" words={doneWords('surface', surface.title)} onReply={onReply} />
|
|
132
|
+
) : null}
|
|
133
|
+
</View>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function ConnectCard({ card, live, onReply }: { card: ConnectHandover; live: boolean; onReply: Props['onReply'] }) {
|
|
138
|
+
const [opened, open] = useOpened();
|
|
139
|
+
const heading = connectHeading(card);
|
|
140
|
+
const verb = connectButton(card);
|
|
141
|
+
return (
|
|
142
|
+
<View style={s.group}>
|
|
143
|
+
<View style={s.card}>
|
|
144
|
+
<ConnectorLogo id={card.connector} size={36} />
|
|
145
|
+
<View style={s.text}>
|
|
146
|
+
<Text style={s.title} numberOfLines={2}>
|
|
147
|
+
{heading}
|
|
148
|
+
</Text>
|
|
149
|
+
{card.reason ? <Text style={s.sub}>{card.reason}</Text> : null}
|
|
150
|
+
</View>
|
|
151
|
+
<Pressable
|
|
152
|
+
accessibilityRole="button"
|
|
153
|
+
accessibilityLabel={`${verb}: ${heading}`}
|
|
154
|
+
accessibilityHint="Opens the form on Yantra"
|
|
155
|
+
onPress={() => open(() => appUrl().then((app) => connectUrl(app, card)))}
|
|
156
|
+
hitSlop={6}
|
|
157
|
+
style={({ pressed }) => [s.verb, pressed && s.verbPressed]}
|
|
158
|
+
>
|
|
159
|
+
<Text style={s.verbText}>{verb}</Text>
|
|
160
|
+
</Pressable>
|
|
161
|
+
</View>
|
|
162
|
+
{opened && live ? (
|
|
163
|
+
<DoneButton label="I saved it" words={doneWords('connect', connectName(card))} onReply={onReply} />
|
|
164
|
+
) : null}
|
|
165
|
+
</View>
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const LINE = 'rgba(26,23,20,0.11)';
|
|
170
|
+
|
|
171
|
+
const s = StyleSheet.create({
|
|
172
|
+
// As wide as a bubble can be (ui.tsx bubble), so a short label does not shrink the card around it.
|
|
173
|
+
stack: { gap: 8, width: '84%' },
|
|
174
|
+
group: { gap: 8, alignItems: 'flex-start' },
|
|
175
|
+
card: {
|
|
176
|
+
alignSelf: 'stretch',
|
|
177
|
+
flexDirection: 'row',
|
|
178
|
+
alignItems: 'center',
|
|
179
|
+
gap: 12,
|
|
180
|
+
minHeight: 56,
|
|
181
|
+
paddingVertical: 10,
|
|
182
|
+
paddingLeft: 10,
|
|
183
|
+
paddingRight: 12,
|
|
184
|
+
borderRadius: 16,
|
|
185
|
+
borderWidth: 1,
|
|
186
|
+
borderColor: LINE,
|
|
187
|
+
backgroundColor: ui.surface,
|
|
188
|
+
},
|
|
189
|
+
cardPressed: { transform: [{ scale: 0.985 }], backgroundColor: ui.bg },
|
|
190
|
+
tile: {
|
|
191
|
+
width: 36,
|
|
192
|
+
height: 36,
|
|
193
|
+
borderRadius: 11,
|
|
194
|
+
backgroundColor: ui.accentSoft,
|
|
195
|
+
alignItems: 'center',
|
|
196
|
+
justifyContent: 'center',
|
|
197
|
+
},
|
|
198
|
+
text: { flex: 1, minWidth: 0, gap: 2 },
|
|
199
|
+
title: { fontSize: 14.5, lineHeight: 19, fontWeight: '600', color: ui.ink },
|
|
200
|
+
sub: { fontSize: 12.5, lineHeight: 17, color: ui.muted },
|
|
201
|
+
out: { transform: [{ rotate: '45deg' }] },
|
|
202
|
+
verb: {
|
|
203
|
+
minWidth: 64,
|
|
204
|
+
height: 34,
|
|
205
|
+
paddingHorizontal: 14,
|
|
206
|
+
borderRadius: 17,
|
|
207
|
+
backgroundColor: ui.accent,
|
|
208
|
+
alignItems: 'center',
|
|
209
|
+
justifyContent: 'center',
|
|
210
|
+
},
|
|
211
|
+
verbPressed: { backgroundColor: ui.accentPressed },
|
|
212
|
+
verbText: { fontSize: 14, fontWeight: '600', color: ui.surface },
|
|
213
|
+
done: {
|
|
214
|
+
flexDirection: 'row',
|
|
215
|
+
alignItems: 'center',
|
|
216
|
+
gap: 6,
|
|
217
|
+
height: 34,
|
|
218
|
+
paddingHorizontal: 14,
|
|
219
|
+
borderRadius: 17,
|
|
220
|
+
backgroundColor: ui.ink,
|
|
221
|
+
},
|
|
222
|
+
donePressed: { opacity: 0.85 },
|
|
223
|
+
doneText: { fontSize: 14, fontWeight: '600', color: ui.surface },
|
|
224
|
+
});
|
|
@@ -24,7 +24,8 @@ import Svg, { Path } from 'react-native-svg';
|
|
|
24
24
|
import { MARK } from './Logo';
|
|
25
25
|
import { useReducedMotion } from '../hooks/useReducedMotion';
|
|
26
26
|
import { tap, tick } from '../welcome/haptics';
|
|
27
|
-
import {
|
|
27
|
+
import { yantraAppUrl } from '../utils/links';
|
|
28
|
+
import { openYantraInSheet } from '../utils/yantraLinks';
|
|
28
29
|
import {
|
|
29
30
|
actionWord,
|
|
30
31
|
BADGES,
|
|
@@ -279,7 +280,7 @@ function OutLink({ link, small }: { link?: ResultLink; small?: boolean }) {
|
|
|
279
280
|
accessibilityLabel={link.label}
|
|
280
281
|
accessibilityHint="Opens in the browser"
|
|
281
282
|
hitSlop={small ? 6 : 3}
|
|
282
|
-
onPress={() =>
|
|
283
|
+
onPress={() => openYantraInSheet(link.href)}
|
|
283
284
|
style={({ pressed }) => [c.out, small && c.outSmall, pressed && { backgroundColor: ui.fill }]}
|
|
284
285
|
>
|
|
285
286
|
<Glyph name="out" size={small ? 14 : 16} weight={2} />
|
|
@@ -298,7 +299,7 @@ function useMore(kind: ResultCard['kind']): { more: MoreSurface; href: string }
|
|
|
298
299
|
|
|
299
300
|
function openSurface(href: string) {
|
|
300
301
|
tap();
|
|
301
|
-
|
|
302
|
+
openYantraInSheet(href);
|
|
302
303
|
}
|
|
303
304
|
|
|
304
305
|
/** "More flights in Travel": the card's way past what Lucy found. */
|
|
@@ -48,6 +48,7 @@ import { dictationProblem, MicButton } from '../../components/MicButton';
|
|
|
48
48
|
import { displayText, formatAskAnswers, type AskAnswer, type AskUser } from '../../chat/protocol';
|
|
49
49
|
import { laterWords, takeResults } from '../../chat/results';
|
|
50
50
|
import { ResultCards } from '../../components/ResultCards';
|
|
51
|
+
import { HandoverCards } from '../../components/HandoverCards';
|
|
51
52
|
import type { ChatMessage } from '../../chat/store';
|
|
52
53
|
import { PROMPT_MAX, yantraAppUrl } from '../../utils/links';
|
|
53
54
|
import { TEXT_LUCY } from '../../imessage/platform';
|
|
@@ -295,7 +296,10 @@ function MessageRow(props: RowProps) {
|
|
|
295
296
|
return <LucyRow {...props} />;
|
|
296
297
|
}
|
|
297
298
|
|
|
298
|
-
/**
|
|
299
|
+
/**
|
|
300
|
+
* Lucy's reply: her words, what she hands over (her computer, a Connect card: components/HandoverCards.tsx), her flights
|
|
301
|
+
* or products as cards (components/ResultCards.tsx), then how she is getting on.
|
|
302
|
+
*/
|
|
299
303
|
function LucyRow({ m, index, thread, last, activity, streaming, onRetry, onReply }: RowProps) {
|
|
300
304
|
const taken = useMemo(() => takeResults(m.content, m.id), [m.content, m.id]);
|
|
301
305
|
const text = displayText(taken.content);
|
|
@@ -312,6 +316,7 @@ function LucyRow({ m, index, thread, last, activity, streaming, onRetry, onReply
|
|
|
312
316
|
<Markdown>{text}</Markdown>
|
|
313
317
|
</Bubble>
|
|
314
318
|
) : null}
|
|
319
|
+
<HandoverCards text={taken.content} live={last && !streaming} onReply={onReply} />
|
|
315
320
|
{taken.cards.length ? (
|
|
316
321
|
<ResultCards cards={taken.cards} later={later} busy={streaming} onReply={onReply} />
|
|
317
322
|
) : null}
|