@adminide-stack/clock-tik-mobile 12.0.37-alpha.0 → 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 +22 -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/connectors.js +3 -0
- package/lib/chat/connectors.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/config/env-config.js +7 -1
- package/lib/config/env-config.js.map +1 -1
- package/lib/offer/blackFriday.js.map +1 -1
- package/lib/offer/state.js.map +1 -1
- package/lib/screens/Chat/index.js +2 -1
- package/lib/screens/Chat/index.js.map +1 -1
- package/lib/screens/Home/index.js +9 -5
- package/lib/screens/Home/index.js.map +1 -1
- package/lib/utils/yantraLinks.js +26 -8
- package/lib/utils/yantraLinks.js.map +1 -1
- package/package.json +4 -4
- package/src/__tests__/agent.test.ts +201 -0
- package/src/__tests__/chores.test.ts +15 -2
- package/src/__tests__/connectLink.test.ts +21 -0
- package/src/__tests__/envConfig.test.ts +14 -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/connectors.ts +13 -3
- 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/config/env-config.ts +13 -0
- package/src/offer/blackFriday.ts +1 -1
- package/src/offer/state.ts +1 -1
- package/src/screens/Chat/index.tsx +6 -1
- package/src/screens/Home/index.tsx +10 -7
- package/src/utils/yantraLinks.ts +40 -10
package/lib/utils/yantraLinks.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {agentAppUrl,auth0Token,KNOWN_YANTRA_APPS}from'../chat/auth.js';import {openUrl,yantraAppUrl,openInSheet}from'./links.js';const APP_SIGN_IN_START_PATH = "/resources/app-sign-in/start";
|
|
1
|
+
import {agentAppUrl,auth0Token,KNOWN_YANTRA_APPS}from'../chat/auth.js';import {platformBase}from'../chat/results.js';import {openUrl,yantraAppUrl,openInSheet}from'./links.js';const APP_SIGN_IN_START_PATH = "/resources/app-sign-in/start";
|
|
2
2
|
const START_TIMEOUT_MS = 5e3;
|
|
3
3
|
const defaultDeps = {
|
|
4
4
|
token: auth0Token,
|
|
5
5
|
agentApp: agentAppUrl,
|
|
6
|
-
fetch: (
|
|
6
|
+
fetch: (input, init) => fetch(input, init)
|
|
7
7
|
};
|
|
8
8
|
function originOf(url) {
|
|
9
9
|
try {
|
|
@@ -14,7 +14,20 @@ function originOf(url) {
|
|
|
14
14
|
}
|
|
15
15
|
async function yantraOrigins(agentApp = agentAppUrl) {
|
|
16
16
|
const named = await agentApp().catch(() => "");
|
|
17
|
-
return new Set([yantraAppUrl(),
|
|
17
|
+
return new Set([named, yantraAppUrl(), ...KNOWN_YANTRA_APPS].map(originOf).filter(Boolean));
|
|
18
|
+
}
|
|
19
|
+
function appForSurface(origin, apps) {
|
|
20
|
+
var _a;
|
|
21
|
+
const m = /^https:\/\/[a-z0-9-]+-surface\.([a-z0-9.-]+)$/i.exec(origin);
|
|
22
|
+
if (!m)
|
|
23
|
+
return "";
|
|
24
|
+
const base = m[1].toLowerCase();
|
|
25
|
+
for (const app of apps) {
|
|
26
|
+
const host = (_a = /^https:\/\/([^/:]+)$/i.exec(app)) == null ? void 0 : _a[1];
|
|
27
|
+
if (host && platformBase(host) === base)
|
|
28
|
+
return app;
|
|
29
|
+
}
|
|
30
|
+
return "";
|
|
18
31
|
}
|
|
19
32
|
async function signedInYantraLink(url, deps = defaultDeps) {
|
|
20
33
|
let target;
|
|
@@ -23,8 +36,13 @@ async function signedInYantraLink(url, deps = defaultDeps) {
|
|
|
23
36
|
} catch (e) {
|
|
24
37
|
return url;
|
|
25
38
|
}
|
|
26
|
-
if (target.protocol !== "https:"
|
|
39
|
+
if (target.protocol !== "https:")
|
|
40
|
+
return url;
|
|
41
|
+
const apps = await yantraOrigins(deps.agentApp);
|
|
42
|
+
const app = apps.has(target.origin) ? target.origin : appForSurface(target.origin, apps);
|
|
43
|
+
if (!app)
|
|
27
44
|
return url;
|
|
45
|
+
const returnTo = app === target.origin ? `${target.pathname}${target.search}${target.hash}` : target.toString();
|
|
28
46
|
let token;
|
|
29
47
|
try {
|
|
30
48
|
token = await deps.token();
|
|
@@ -34,14 +52,14 @@ async function signedInYantraLink(url, deps = defaultDeps) {
|
|
|
34
52
|
const controller = new AbortController();
|
|
35
53
|
const timer = setTimeout(() => controller.abort(), START_TIMEOUT_MS);
|
|
36
54
|
try {
|
|
37
|
-
const res = await deps.fetch(`${
|
|
55
|
+
const res = await deps.fetch(`${app}${APP_SIGN_IN_START_PATH}`, {
|
|
38
56
|
method: "POST",
|
|
39
57
|
headers: {
|
|
40
58
|
"Content-Type": "application/json",
|
|
41
59
|
Authorization: `Bearer ${token}`
|
|
42
60
|
},
|
|
43
61
|
body: JSON.stringify({
|
|
44
|
-
returnTo
|
|
62
|
+
returnTo
|
|
45
63
|
}),
|
|
46
64
|
signal: controller.signal
|
|
47
65
|
});
|
|
@@ -49,7 +67,7 @@ async function signedInYantraLink(url, deps = defaultDeps) {
|
|
|
49
67
|
return url;
|
|
50
68
|
const body = await res.json().catch(() => null);
|
|
51
69
|
const link = typeof (body == null ? void 0 : body.url) === "string" ? body.url : "";
|
|
52
|
-
return link && originOf(link) ===
|
|
70
|
+
return link && originOf(link) === app ? link : url;
|
|
53
71
|
} catch (e) {
|
|
54
72
|
return url;
|
|
55
73
|
} finally {
|
|
@@ -65,4 +83,4 @@ async function openYantraInSheet(url) {
|
|
|
65
83
|
if (!url)
|
|
66
84
|
return;
|
|
67
85
|
return openInSheet(await signedInYantraLink(url));
|
|
68
|
-
}export{APP_SIGN_IN_START_PATH,openYantraInSheet,openYantraUrl,signedInYantraLink,yantraOrigins};//# sourceMappingURL=yantraLinks.js.map
|
|
86
|
+
}export{APP_SIGN_IN_START_PATH,appForSurface,openYantraInSheet,openYantraUrl,signedInYantraLink,yantraOrigins};//# sourceMappingURL=yantraLinks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"yantraLinks.js","sources":["../../src/utils/yantraLinks.ts"],"sourcesContent":["/**\n * Yantra's pages, opened signed in.\n *\n * Clockbook signs in with the person's Yantra account, but the browser sheet keeps its own cookies: a\n * Yantra page opened there (Connect Google Calendar, the Connectors page) asked them to sign in again\n * with the account they had just used here. Yantra hands the sign-in over instead: asked with the\n * person's Auth0 ID token (POST <app>/resources/app-sign-in/start), it answers a one-time link (good for\n * a minute) that signs the sheet in and goes on to the page. Without one (signed out here, offline, a\n * Yantra that does not have it yet) the page opens as before.\n *\n * The ID token only ever goes to a Yantra app this build knows: the configured one, the one Lucy's agent\n * names, and production's and staging's. A link to anywhere else (one in Lucy's reply, say) opens as is.\n */\nimport { agentAppUrl, auth0Token, KNOWN_YANTRA_APPS } from '../chat/auth';\nimport { openInSheet, openUrl, yantraAppUrl } from './links';\n\nexport const APP_SIGN_IN_START_PATH = '/resources/app-sign-in/start';\n/** The sign-in link should come back at once; past this the page opens without it. */\nconst START_TIMEOUT_MS = 5000;\n\nexport interface SignInDeps {\n token: () => Promise<string>;\n agentApp: () => Promise<string>;\n fetch: typeof fetch;\n}\n\nconst defaultDeps: SignInDeps = {
|
|
1
|
+
{"version":3,"file":"yantraLinks.js","sources":["../../src/utils/yantraLinks.ts"],"sourcesContent":["/**\n * Yantra's pages, opened signed in.\n *\n * Clockbook signs in with the person's Yantra account, but the browser sheet keeps its own cookies: a\n * Yantra page opened there (Connect Google Calendar, the Connectors page) asked them to sign in again\n * with the account they had just used here. Yantra hands the sign-in over instead: asked with the\n * person's Auth0 ID token (POST <app>/resources/app-sign-in/start), it answers a one-time link (good for\n * a minute) that signs the sheet in and goes on to the page. Without one (signed out here, offline, a\n * Yantra that does not have it yet) the page opens as before.\n *\n * A Yantra surface (`https://<name>-surface.<base>/`: Travel, Shopping...) is opened the same way: the\n * link goes to the Yantra app of that base, signs the sheet in there and goes on to the surface, which finds\n * the session (its cookie covers the whole base) and mints its own token from it. Without it the surface\n * showed its own \"Sign in to Yantra\" card.\n *\n * The ID token only ever goes to a Yantra app this build knows: the configured one, the one Lucy's agent\n * names, and production's and staging's. A link to anywhere else (one in Lucy's reply, say) opens as is.\n */\nimport { agentAppUrl, auth0Token, KNOWN_YANTRA_APPS } from '../chat/auth';\nimport { platformBase } from '../chat/results';\nimport { openInSheet, openUrl, yantraAppUrl } from './links';\n\nexport const APP_SIGN_IN_START_PATH = '/resources/app-sign-in/start';\n/** The sign-in link should come back at once; past this the page opens without it. */\nconst START_TIMEOUT_MS = 5000;\n\nexport interface SignInDeps {\n token: () => Promise<string>;\n agentApp: () => Promise<string>;\n fetch: typeof fetch;\n}\n\nconst defaultDeps: SignInDeps = {\n token: auth0Token,\n agentApp: agentAppUrl,\n fetch: (input, init) => fetch(input, init),\n};\n\nfunction originOf(url: string): string {\n try {\n return new URL(url).origin;\n } catch {\n return '';\n }\n}\n\n/** The Yantra apps the ID token may go to: the one Lucy's agent names first, then the configured one. */\nexport async function yantraOrigins(agentApp: SignInDeps['agentApp'] = agentAppUrl): Promise<Set<string>> {\n const named = await agentApp().catch(() => '');\n return new Set([named, yantraAppUrl(), ...KNOWN_YANTRA_APPS].map(originOf).filter(Boolean));\n}\n\n/**\n * The Yantra app a surface belongs to: for `https://<name>-surface.<base>`, the first of `apps` whose host has\n * that base (platformBase); '' for anything else. Read with patterns: React Native's URL has no hostname.\n */\nexport function appForSurface(origin: string, apps: Iterable<string>): string {\n const m = /^https:\\/\\/[a-z0-9-]+-surface\\.([a-z0-9.-]+)$/i.exec(origin);\n if (!m) return '';\n const base = m[1].toLowerCase();\n for (const app of apps) {\n const host = /^https:\\/\\/([^/:]+)$/i.exec(app)?.[1];\n if (host && platformBase(host) === base) return app;\n }\n return '';\n}\n\n/**\n * `url` as a link that opens it signed in to the person's Yantra account, when it is a page of a Yantra\n * app or one of its surfaces and Yantra gives one; else `url` itself.\n */\nexport async function signedInYantraLink(url: string, deps: SignInDeps = defaultDeps): Promise<string> {\n let target: URL;\n try {\n target = new URL(url);\n } catch {\n return url;\n }\n if (target.protocol !== 'https:') return url;\n const apps = await yantraOrigins(deps.agentApp);\n // A page of the app itself, or a surface: then the app of its base signs the sheet in and goes on to it.\n const app = apps.has(target.origin) ? target.origin : appForSurface(target.origin, apps);\n if (!app) return url;\n const returnTo = app === target.origin ? `${target.pathname}${target.search}${target.hash}` : target.toString();\n\n let token: string;\n try {\n token = await deps.token();\n } catch {\n return url; // signed out here: Yantra's own sign-in, as before\n }\n\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), START_TIMEOUT_MS);\n try {\n const res = await deps.fetch(`${app}${APP_SIGN_IN_START_PATH}`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },\n body: JSON.stringify({ returnTo }),\n signal: controller.signal,\n });\n if (!res.ok) return url;\n const body = (await res.json().catch(() => null)) as { url?: unknown } | null;\n const link = typeof body?.url === 'string' ? body.url : '';\n // Only ever the sign-in page of the Yantra that was asked.\n return link && originOf(link) === app ? link : url;\n } catch {\n return url;\n } finally {\n clearTimeout(timer);\n }\n}\n\n/** Opens a page in the in-app browser sheet, signed in when it is a Yantra page (see signedInYantraLink). */\nexport async function openYantraUrl(url: string): Promise<void> {\n if (!url) return;\n return openUrl(await signedInYantraLink(url));\n}\n\n/** openInSheet, signed in when it is a Yantra page or surface. */\nexport async function openYantraInSheet(url: string): Promise<void> {\n if (!url) return;\n return openInSheet(await signedInYantraLink(url));\n}\n"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adminide-stack/clock-tik-mobile",
|
|
3
|
-
"version": "12.0.37-alpha.
|
|
3
|
+
"version": "12.0.37-alpha.2",
|
|
4
4
|
"description": "Clockbook mobile screens: the native Clockbook home and the app drawer",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "CDMBase LLC",
|
|
@@ -23,11 +23,11 @@
|
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@jest/globals": "^29.7.0",
|
|
26
|
-
"common": "12.0.37-alpha.
|
|
26
|
+
"common": "12.0.37-alpha.1"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"@admin-layout/gluestack-ui-mobile": "*",
|
|
30
|
-
"@adminide-stack/clock-tik-browser": "12.0.
|
|
30
|
+
"@adminide-stack/clock-tik-browser": "12.0.37-alpha.1",
|
|
31
31
|
"@adminide-stack/user-auth0-client": "*",
|
|
32
32
|
"@common-stack/client-react": "*",
|
|
33
33
|
"@common-stack/core": "*",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"typescript": {
|
|
64
64
|
"definition": "lib/index.d.ts"
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "066f8a14c9122888f9f9287a8e64d68ad85f2b9a"
|
|
67
67
|
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { describe, expect, it, jest } from '@jest/globals';
|
|
2
|
+
|
|
3
|
+
// agent.ts streams with expo/fetch, signs in through native storage and watches the app state: stub them for node.
|
|
4
|
+
jest.mock<{ fetch: jest.Mock }>('expo/fetch', () => ({ fetch: jest.fn() }), { virtual: true });
|
|
5
|
+
jest.mock<
|
|
6
|
+
Pick<
|
|
7
|
+
typeof import('../chat/auth'),
|
|
8
|
+
'agentBackendUrl' | 'agentUrl' | 'getChatToken' | 'clearChatToken' | 'isLockedOut'
|
|
9
|
+
>
|
|
10
|
+
>('../chat/auth', () => ({
|
|
11
|
+
agentBackendUrl: async () => 'https://backend.test/graphql',
|
|
12
|
+
agentUrl: () => 'https://agent.test',
|
|
13
|
+
getChatToken: async () => 'tok',
|
|
14
|
+
clearChatToken: async () => undefined,
|
|
15
|
+
isLockedOut: () => false,
|
|
16
|
+
}));
|
|
17
|
+
jest.mock<Pick<typeof import('../chat/appFront'), 'inFront' | 'onFront' | 'whenInFront'>>('../chat/appFront', () => ({
|
|
18
|
+
inFront: () => true,
|
|
19
|
+
onFront: () => () => undefined,
|
|
20
|
+
whenInFront: async () => undefined,
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
// eslint-disable-next-line import/first
|
|
24
|
+
import { fetch as streamFetch } from 'expo/fetch';
|
|
25
|
+
// eslint-disable-next-line import/first
|
|
26
|
+
import { BUSY_GIVE_UP_MS, sendTurn, WAITING_FOR_LAST } from '../chat/agent';
|
|
27
|
+
|
|
28
|
+
const stream = jest.mocked(
|
|
29
|
+
streamFetch as (url: string, init: { body: string; signal: AbortSignal }) => Promise<unknown>,
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
/** A streamed reply: the SSE blocks as the agent writes them. */
|
|
33
|
+
function sse(...events: [string, unknown][]) {
|
|
34
|
+
const text = events.map(([e, d]) => `event: ${e}\ndata: ${JSON.stringify(d)}\n\n`).join('');
|
|
35
|
+
let sent = false;
|
|
36
|
+
return {
|
|
37
|
+
status: 200,
|
|
38
|
+
ok: true,
|
|
39
|
+
body: {
|
|
40
|
+
getReader: () => ({
|
|
41
|
+
read: async () => {
|
|
42
|
+
if (sent) return { done: true, value: undefined };
|
|
43
|
+
sent = true;
|
|
44
|
+
return { done: false, value: new TextEncoder().encode(text) };
|
|
45
|
+
},
|
|
46
|
+
}),
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const json = (body: unknown, status = 200) => ({ status, ok: status < 300, json: async () => body });
|
|
51
|
+
const busySse = () => sse(['error', { class: 'session_busy', error: 'still working on your previous message' }]);
|
|
52
|
+
const busy409 = () => ({ status: 409, ok: false, body: null });
|
|
53
|
+
|
|
54
|
+
/** The agent's plain GETs (agent.ts authed) go through the global fetch. */
|
|
55
|
+
function agentReads() {
|
|
56
|
+
const get = jest.fn<(url: string, init?: unknown) => Promise<unknown>>();
|
|
57
|
+
globalThis.fetch = get as unknown as typeof fetch;
|
|
58
|
+
stream.mockReset();
|
|
59
|
+
return get;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const handlers = () => ({ onText: jest.fn(), onStatus: jest.fn(), onSession: jest.fn() });
|
|
63
|
+
const sentTurnIds = () => stream.mock.calls.map(([, init]) => JSON.parse(init.body).turn_id as string);
|
|
64
|
+
|
|
65
|
+
/** Runs a turn on a fake clock, moving it on a second at a time until it settles. */
|
|
66
|
+
async function onFakeClock<T>(start: () => Promise<T>, ms = 40 * 60_000): Promise<T> {
|
|
67
|
+
jest.useFakeTimers();
|
|
68
|
+
try {
|
|
69
|
+
let out: { v: T } | { e: unknown } | undefined;
|
|
70
|
+
start().then(
|
|
71
|
+
(v) => {
|
|
72
|
+
out = { v };
|
|
73
|
+
},
|
|
74
|
+
(e: unknown) => {
|
|
75
|
+
out = { e };
|
|
76
|
+
},
|
|
77
|
+
);
|
|
78
|
+
for (let t = 0; t < ms && !out; t += 1000) await jest.advanceTimersByTimeAsync(1000);
|
|
79
|
+
if (!out) throw new Error('still waiting');
|
|
80
|
+
if ('e' in out) throw out.e;
|
|
81
|
+
return out.v;
|
|
82
|
+
} finally {
|
|
83
|
+
jest.useRealTimers();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
describe('sendTurn when the agent is still on an earlier turn', () => {
|
|
88
|
+
// "Update me?" in the 2026-11-17 report: refused as busy while the agent was still on earlier turns.
|
|
89
|
+
it('waits until the session has room, then sends the same turn instead of failing', async () => {
|
|
90
|
+
const get = agentReads();
|
|
91
|
+
stream
|
|
92
|
+
.mockResolvedValueOnce(busySse())
|
|
93
|
+
.mockResolvedValueOnce(sse(['delta', { text: 'Here is where it stands.' }], ['done', {}]));
|
|
94
|
+
get.mockResolvedValueOnce(json({ in_flight: true })).mockResolvedValueOnce(json({ in_flight: false }));
|
|
95
|
+
const h = handlers();
|
|
96
|
+
|
|
97
|
+
await expect(onFakeClock(() => sendTurn('Update me?', 'srv_1', h, new AbortController().signal))).resolves.toBe(
|
|
98
|
+
'Here is where it stands.',
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
const ids = sentTurnIds();
|
|
102
|
+
|
|
103
|
+
expect(ids).toHaveLength(2);
|
|
104
|
+
expect(ids[1]).toBe(ids[0]);
|
|
105
|
+
expect(get.mock.calls.map(([url]) => url)).toStrictEqual([
|
|
106
|
+
'https://agent.test/v1/agent/session?id=srv_1',
|
|
107
|
+
'https://agent.test/v1/agent/session?id=srv_1',
|
|
108
|
+
]);
|
|
109
|
+
expect(h.onStatus).toHaveBeenCalledWith(WAITING_FOR_LAST);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('treats an HTTP 409 refusal the same way', async () => {
|
|
113
|
+
const get = agentReads();
|
|
114
|
+
stream.mockResolvedValueOnce(busy409()).mockResolvedValueOnce(sse(['delta', { text: 'Done.' }], ['done', {}]));
|
|
115
|
+
get.mockResolvedValue(json({ in_flight: false }));
|
|
116
|
+
|
|
117
|
+
await expect(
|
|
118
|
+
onFakeClock(() => sendTurn('hello', 'srv_1', handlers(), new AbortController().signal)),
|
|
119
|
+
).resolves.toBe('Done.');
|
|
120
|
+
expect(new Set(sentTurnIds()).size).toBe(1);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// cdecli#838: `queued` says whether another message would be refused; mid-turn there can still be room.
|
|
124
|
+
it('goes as soon as the agent says there is room, even while it is mid-turn', async () => {
|
|
125
|
+
const get = agentReads();
|
|
126
|
+
stream.mockResolvedValueOnce(busySse()).mockResolvedValueOnce(sse(['delta', { text: 'Next.' }], ['done', {}]));
|
|
127
|
+
get.mockResolvedValueOnce(json({ in_flight: true, queued: true })).mockResolvedValueOnce(
|
|
128
|
+
json({ in_flight: true, queued: false }),
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
await expect(
|
|
132
|
+
onFakeClock(() => sendTurn('and this', 'srv_1', handlers(), new AbortController().signal)),
|
|
133
|
+
).resolves.toBe('Next.');
|
|
134
|
+
expect(get).toHaveBeenCalledTimes(2);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// Seen live on dev (cdecli 2.20.120): GET /v1/agent/session said idle while the agent kept refusing.
|
|
138
|
+
it('keeps waiting, longer each time, when the agent reports room but still refuses', async () => {
|
|
139
|
+
const get = agentReads();
|
|
140
|
+
const replies = [busySse(), busySse(), busySse(), busySse(), sse(['delta', { text: 'Ok.' }], ['done', {}])];
|
|
141
|
+
const sentAt: number[] = [];
|
|
142
|
+
stream.mockImplementation(async () => {
|
|
143
|
+
sentAt.push(Date.now());
|
|
144
|
+
return replies.shift();
|
|
145
|
+
});
|
|
146
|
+
get.mockResolvedValue(json({ in_flight: false }));
|
|
147
|
+
|
|
148
|
+
await expect(
|
|
149
|
+
onFakeClock(() => sendTurn('Update me?', 'srv_1', handlers(), new AbortController().signal)),
|
|
150
|
+
).resolves.toBe('Ok.');
|
|
151
|
+
|
|
152
|
+
const gaps = sentAt.slice(1).map((t, i) => t - sentAt[i]);
|
|
153
|
+
|
|
154
|
+
expect(new Set(sentTurnIds()).size).toBe(1);
|
|
155
|
+
expect(gaps).toHaveLength(4);
|
|
156
|
+
expect(gaps[3]).toBeGreaterThan(gaps[0]);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('keeps waiting through a moment the agent cannot be reached', async () => {
|
|
160
|
+
const get = agentReads();
|
|
161
|
+
stream.mockResolvedValueOnce(busySse()).mockResolvedValueOnce(sse(['delta', { text: 'Back.' }], ['done', {}]));
|
|
162
|
+
get.mockRejectedValueOnce(new Error('offline')).mockResolvedValueOnce(json({ in_flight: false }));
|
|
163
|
+
|
|
164
|
+
await expect(
|
|
165
|
+
onFakeClock(() => sendTurn('hi', 'srv_1', handlers(), new AbortController().signal)),
|
|
166
|
+
).resolves.toBe('Back.');
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('gives up as busy past the agent’s own turn limit', async () => {
|
|
170
|
+
const get = agentReads();
|
|
171
|
+
stream.mockImplementation(async () => busySse());
|
|
172
|
+
get.mockResolvedValue(json({ in_flight: true, queued: true }));
|
|
173
|
+
const started = Date.now();
|
|
174
|
+
let endedAt = 0;
|
|
175
|
+
|
|
176
|
+
await expect(
|
|
177
|
+
onFakeClock(() =>
|
|
178
|
+
sendTurn('hi', 'srv_1', handlers(), new AbortController().signal).finally(() => {
|
|
179
|
+
endedAt = Date.now();
|
|
180
|
+
}),
|
|
181
|
+
),
|
|
182
|
+
).rejects.toMatchObject({ kind: 'busy' });
|
|
183
|
+
expect(endedAt - started).toBeGreaterThanOrEqual(BUSY_GIVE_UP_MS);
|
|
184
|
+
expect(stream).toHaveBeenCalledTimes(1);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it('stops waiting when the chat stops the reply', async () => {
|
|
188
|
+
const get = agentReads();
|
|
189
|
+
stream.mockImplementation(async () => busySse());
|
|
190
|
+
get.mockResolvedValue(json({ in_flight: true }));
|
|
191
|
+
const stop = new AbortController();
|
|
192
|
+
|
|
193
|
+
await expect(
|
|
194
|
+
onFakeClock(() => {
|
|
195
|
+
setTimeout(() => stop.abort(), 10_000);
|
|
196
|
+
return sendTurn('hi', 'srv_1', handlers(), stop.signal);
|
|
197
|
+
}),
|
|
198
|
+
).rejects.toMatchObject({ kind: 'stopped' });
|
|
199
|
+
expect(stream).toHaveBeenCalledTimes(1);
|
|
200
|
+
});
|
|
201
|
+
});
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
// chores.ts reads through chat/auth.ts (native storage): the record parsing and grouping are what is tested here.
|
|
2
2
|
jest.mock('../chat/auth', () => ({ agentBackendUrl: jest.fn(), getChatToken: jest.fn() }));
|
|
3
|
+
// chores.ts keeps the phone's last list in AsyncStorage, a native module: stub it for node as the other suites do.
|
|
4
|
+
jest.mock('@react-native-async-storage/async-storage', () => ({ getItem: jest.fn(), setItem: jest.fn() }), {
|
|
5
|
+
virtual: true,
|
|
6
|
+
});
|
|
3
7
|
|
|
4
8
|
// eslint-disable-next-line import/first
|
|
5
9
|
import { choreFromRow, groupChores, setAskingChore, setChoreProgress, type Chore } from '../chat/chores';
|
|
@@ -93,9 +97,18 @@ describe('groupChores', () => {
|
|
|
93
97
|
});
|
|
94
98
|
|
|
95
99
|
describe('connectors', () => {
|
|
96
|
-
it('opens
|
|
100
|
+
it('opens an app’s connect form directly, and a vault entry’s connect page', () => {
|
|
97
101
|
expect(connectLink('https://yantra.app/', 'google-gmail')).toBe(
|
|
98
|
-
'https://yantra.app/
|
|
102
|
+
'https://yantra.app/account/connectors?credentialChain=google-gmail&autoStart=true',
|
|
103
|
+
);
|
|
104
|
+
expect(connectLink('https://yantra.app', 'google-calendar')).toBe(
|
|
105
|
+
'https://yantra.app/account/connectors?credentialChain=google-calendar&autoStart=true',
|
|
106
|
+
);
|
|
107
|
+
expect(connectLink('https://yantra.app', 'site-login')).toBe(
|
|
108
|
+
'https://yantra.app/connect/site-login?via=surface',
|
|
109
|
+
);
|
|
110
|
+
expect(connectLink('https://yantra.app', 'something-new')).toBe(
|
|
111
|
+
'https://yantra.app/connect/something-new?via=surface',
|
|
99
112
|
);
|
|
100
113
|
expect(allConnectorsLink('https://yantra.app')).toBe('https://yantra.app/account/connectors');
|
|
101
114
|
expect(connectLink('', 'google-gmail')).toBe('');
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Where Clockbook's Connect opens Yantra (chat/connectors.ts connectLink): an app's form at once, a vault entry's page. */
|
|
2
|
+
import { connectLink } from '../chat/connectors';
|
|
3
|
+
|
|
4
|
+
describe('connectLink', () => {
|
|
5
|
+
it('opens Google Calendar’s connect form on the Connectors page, with nothing in between', () => {
|
|
6
|
+
expect(connectLink('https://yantra.app', 'google-calendar')).toBe(
|
|
7
|
+
'https://yantra.app/account/connectors?credentialChain=google-calendar&autoStart=true',
|
|
8
|
+
);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('keeps the connect page for a vault entry, which opens the form for its kind', () => {
|
|
12
|
+
expect(connectLink('https://yantra.app/', 'autofill-payment-card')).toBe(
|
|
13
|
+
'https://yantra.app/connect/autofill-payment-card?via=surface',
|
|
14
|
+
);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('gives nothing without an app or a connector', () => {
|
|
18
|
+
expect(connectLink('', 'google-calendar')).toBe('');
|
|
19
|
+
expect(connectLink('https://yantra.app', ' ')).toBe('');
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { describe, expect, it } from '@jest/globals';
|
|
2
|
+
import { isTestBuild } from '../config/env-config';
|
|
3
|
+
|
|
4
|
+
describe('test builds', () => {
|
|
5
|
+
it('are development builds and the preview channel, never a store build', () => {
|
|
6
|
+
expect(isTestBuild({ dev: true, channel: '' })).toBe(true);
|
|
7
|
+
expect(isTestBuild({ dev: false, channel: 'preview' })).toBe(true);
|
|
8
|
+
expect(isTestBuild({ dev: false, channel: 'production' })).toBe(false);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('leaves a build that did not say what it is out', () => {
|
|
12
|
+
expect(isTestBuild({ dev: false, channel: '' })).toBe(false);
|
|
13
|
+
});
|
|
14
|
+
});
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import {
|
|
2
|
+
connectButton,
|
|
3
|
+
connectHandovers,
|
|
4
|
+
connectHeading,
|
|
5
|
+
connectName,
|
|
6
|
+
connectUrl,
|
|
7
|
+
doneWords,
|
|
8
|
+
stripConnectCards,
|
|
9
|
+
surfaceButton,
|
|
10
|
+
surfaceHandovers,
|
|
11
|
+
} from '../chat/handover';
|
|
12
|
+
|
|
13
|
+
// What Lucy sent on 2026-11-22 when Flipkart wanted a sign-in (replayed on dev): the words, her computer, a login card.
|
|
14
|
+
const FLIPKART = [
|
|
15
|
+
"I've opened Flipkart's sign-in on my computer. Flipkart signs in with your phone number and a code.",
|
|
16
|
+
'',
|
|
17
|
+
'[[surface:computer|Sign in to Flipkart, then tell me]]',
|
|
18
|
+
'',
|
|
19
|
+
'[CONNECTOR_CONNECT]{"requestId":"fk7q2m9d","connector":"site-login","title":"Flipkart login","reason":"Save your Flipkart sign-in so I can sign in for you next time.","form":{"site":"flipkart.com","loginUrl":"https://www.flipkart.com/login"}}[/CONNECTOR_CONNECT]',
|
|
20
|
+
].join('\n');
|
|
21
|
+
|
|
22
|
+
describe('surfaceHandovers', () => {
|
|
23
|
+
it("hands over Lucy's computer with what to do there", () => {
|
|
24
|
+
expect(surfaceHandovers(FLIPKART)).toEqual([
|
|
25
|
+
{
|
|
26
|
+
id: 'computer',
|
|
27
|
+
title: "Lucy's computer",
|
|
28
|
+
host: 'computer-surface',
|
|
29
|
+
label: 'Sign in to Flipkart, then tell me',
|
|
30
|
+
},
|
|
31
|
+
]);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('takes each surface once, resolves aliases, and leaves out one this chat cannot open', () => {
|
|
35
|
+
const text =
|
|
36
|
+
'[[surface:computer]] [[surface:Computer|Again]] [[surface:trips|Your trip]] [[surface:mystery|?]]';
|
|
37
|
+
expect(surfaceHandovers(text).map((s) => [s.id, s.label])).toEqual([
|
|
38
|
+
['computer', ''],
|
|
39
|
+
['travel', 'Your trip'],
|
|
40
|
+
]);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('waits for a marker still streaming in', () => {
|
|
44
|
+
expect(surfaceHandovers('Opened it.\n[[surface:compu')).toEqual([]);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('words the button after the surface', () => {
|
|
48
|
+
expect(surfaceButton({ title: "Lucy's computer" })).toBe("Open Lucy's computer");
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe('connectHandovers', () => {
|
|
53
|
+
it('reads a website-login card', () => {
|
|
54
|
+
expect(connectHandovers(FLIPKART)).toEqual([
|
|
55
|
+
{
|
|
56
|
+
requestId: 'fk7q2m9d',
|
|
57
|
+
connector: 'site-login',
|
|
58
|
+
title: 'Flipkart login',
|
|
59
|
+
reason: 'Save your Flipkart sign-in so I can sign in for you next time.',
|
|
60
|
+
site: 'flipkart.com',
|
|
61
|
+
loginUrl: 'https://www.flipkart.com/login',
|
|
62
|
+
},
|
|
63
|
+
]);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('reads the shapes a model drifts to: no closing tag, flat fields, `provider` for `connector`, escaped JSON', () => {
|
|
67
|
+
expect(connectHandovers('Save it.\n[CONNECTOR_CONNECT]{"requestId":"a1","connector":"google-gmail"}')).toEqual([
|
|
68
|
+
{ requestId: 'a1', connector: 'google-gmail' },
|
|
69
|
+
]);
|
|
70
|
+
expect(
|
|
71
|
+
connectHandovers(
|
|
72
|
+
'[CONNECTOR_CONNECT]{"id":"b2","provider":"site-login","site":"amazon.in"}[/CONNECTOR_CONNECT]',
|
|
73
|
+
),
|
|
74
|
+
).toEqual([{ requestId: 'b2', connector: 'site-login', site: 'amazon.in' }]);
|
|
75
|
+
expect(connectHandovers('[CONNECTOR_CONNECT]{\\"requestId\\":\\"c3\\",\\"connector\\":\\"openai\\"}')).toEqual([
|
|
76
|
+
{ requestId: 'c3', connector: 'openai' },
|
|
77
|
+
]);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('keeps only what the form reads, as strings, and a sign-in page only over http(s)', () => {
|
|
81
|
+
const [card] = connectHandovers(
|
|
82
|
+
'[CONNECTOR_CONNECT]{"requestId":"d4","connector":"site-login","credentialId":"bad id!","form":{"site":7,"loginUrl":"javascript:alert(1)"}}[/CONNECTOR_CONNECT]',
|
|
83
|
+
);
|
|
84
|
+
expect(card).toEqual({ requestId: 'd4', connector: 'site-login' });
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('skips a card with nothing to connect, one still streaming in, and the same card twice', () => {
|
|
88
|
+
expect(connectHandovers('[CONNECTOR_CONNECT]{"requestId":"e5"}[/CONNECTOR_CONNECT]')).toEqual([]);
|
|
89
|
+
expect(connectHandovers('[CONNECTOR_CONNECT]{"requestId":"e5","connec')).toEqual([]);
|
|
90
|
+
const twice = '[CONNECTOR_CONNECT]{"requestId":"f6","connector":"openai"}[/CONNECTOR_CONNECT]';
|
|
91
|
+
expect(connectHandovers(`${twice}\n${twice}`)).toHaveLength(1);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe('stripConnectCards', () => {
|
|
96
|
+
it('takes every card out of the words and keeps the rest', () => {
|
|
97
|
+
expect(
|
|
98
|
+
stripConnectCards(
|
|
99
|
+
'Before.\n[CONNECTOR_CONNECT]{"requestId":"a","connector":"x"}[/CONNECTOR_CONNECT]\nAfter.',
|
|
100
|
+
),
|
|
101
|
+
).toBe('Before.\n\nAfter.');
|
|
102
|
+
expect(stripConnectCards('Before. [CONNECTOR_CONNECT]{"connector":"x","note":"a } in a string"} After.')).toBe(
|
|
103
|
+
'Before. After.',
|
|
104
|
+
);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('cuts a card still streaming in, and a stray tag of another shape', () => {
|
|
108
|
+
expect(stripConnectCards('Before.\n[CONNECTOR_CONNECT]{"requestId":"a","conn')).toBe('Before.\n');
|
|
109
|
+
expect(stripConnectCards('Before. [CONNECTOR_CONNECT] whatever')).toBe('Before. ');
|
|
110
|
+
expect(stripConnectCards('Before. [/CONNECTOR_CONNECT] After.')).toBe('Before. After.');
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
describe('what a connect card says', () => {
|
|
115
|
+
const login = connectHandovers(FLIPKART)[0];
|
|
116
|
+
|
|
117
|
+
it('names a website login, an autofill entry and an app', () => {
|
|
118
|
+
expect(connectHeading(login)).toBe('Save your Flipkart login');
|
|
119
|
+
expect(connectButton(login)).toBe('Save');
|
|
120
|
+
expect(connectHeading({ requestId: 'a', connector: 'site-login', site: 'myntra.com' })).toBe(
|
|
121
|
+
'Save your myntra.com login',
|
|
122
|
+
);
|
|
123
|
+
expect(connectHeading({ requestId: 'a', connector: 'autofill-payment-card' })).toBe('Add your payment card');
|
|
124
|
+
expect(connectButton({ requestId: 'a', connector: 'autofill-payment-card' })).toBe('Add');
|
|
125
|
+
expect(connectHeading({ requestId: 'a', connector: 'google-calendar' })).toBe('Connect Google Calendar');
|
|
126
|
+
expect(connectButton({ requestId: 'a', connector: 'google-calendar' })).toBe('Connect');
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('says Update for a saved entry it changes', () => {
|
|
130
|
+
const update = { ...login, credentialId: 'cred_1' };
|
|
131
|
+
expect(connectHeading(update)).toBe('Update your Flipkart login');
|
|
132
|
+
expect(connectButton(update)).toBe('Update');
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it("opens Yantra's /connect page for it, as the kit's card does", () => {
|
|
136
|
+
expect(connectUrl('https://yantra.app/', login)).toBe(
|
|
137
|
+
'https://yantra.app/connect/site-login?request=fk7q2m9d&via=surface&title=Flipkart%20login&site=flipkart.com&loginUrl=https%3A%2F%2Fwww.flipkart.com%2Flogin',
|
|
138
|
+
);
|
|
139
|
+
expect(connectUrl('https://yantra.app', { requestId: 'x y', connector: 'google-gmail' })).toBe(
|
|
140
|
+
'https://yantra.app/connect/google-gmail?via=surface',
|
|
141
|
+
);
|
|
142
|
+
expect(connectUrl('', login)).toBe('');
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('answers for the person once they are back', () => {
|
|
146
|
+
expect(doneWords('connect', connectName(login))).toBe('I saved my Flipkart login.');
|
|
147
|
+
expect(doneWords('surface', "Lucy's computer")).toBe('Done');
|
|
148
|
+
});
|
|
149
|
+
});
|
|
@@ -69,10 +69,32 @@ describe('question cards', () => {
|
|
|
69
69
|
});
|
|
70
70
|
|
|
71
71
|
describe('displayText', () => {
|
|
72
|
-
it('drops web-only
|
|
72
|
+
it('drops web-only widgets and what is drawn under the bubble, and keeps a surface it cannot open as its label', () => {
|
|
73
73
|
const t =
|
|
74
74
|
'On it. [[surface:phone-calls|Phone Calls]]\n\n```yantra:widget {"propsComponent":"travel"}```\n[CONNECTOR_CONNECT]{"id":"gmail"}[/CONNECTOR_CONNECT]';
|
|
75
|
-
expect(displayText(t)).toBe('On it.
|
|
75
|
+
expect(displayText(t)).toBe('On it.');
|
|
76
|
+
expect(displayText('Opened it. [[surface:mystery-board|The board]]')).toBe('Opened it. The board');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// The Flipkart sign-in of 2026-11-22: the words said "below" and "on my computer", and nothing was there to tap.
|
|
80
|
+
it('keeps the computer hand-over and a website-login card out of the words, with no line left blank', () => {
|
|
81
|
+
const reply = [
|
|
82
|
+
"I've opened Flipkart's sign-in on my computer.",
|
|
83
|
+
'',
|
|
84
|
+
'[[surface:computer|Sign in to Flipkart, then tell me]]',
|
|
85
|
+
'',
|
|
86
|
+
"Tell me when you're signed in.",
|
|
87
|
+
'',
|
|
88
|
+
'[CONNECTOR_CONNECT]{"requestId":"fk7q2m9d","connector":"site-login","title":"Flipkart login","form":{"site":"flipkart.com"}}[/CONNECTOR_CONNECT]',
|
|
89
|
+
].join('\n');
|
|
90
|
+
expect(displayText(reply)).toBe(
|
|
91
|
+
"I've opened Flipkart's sign-in on my computer.\n\nTell me when you're signed in.",
|
|
92
|
+
);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('never shows a hand-over still streaming in', () => {
|
|
96
|
+
expect(displayText('Opened it.\n\n[[surface:comp')).toBe('Opened it.');
|
|
97
|
+
expect(displayText('Opened it.\n\n[CONNECTOR_CONNECT]{"requestId":"a1","connec')).toBe('Opened it.');
|
|
76
98
|
});
|
|
77
99
|
|
|
78
100
|
const envelope = JSON.stringify({
|
|
@@ -121,5 +143,8 @@ describe('small lines', () => {
|
|
|
121
143
|
it('opens sessions as Lucy, taught to ask with cards', () => {
|
|
122
144
|
expect(SYSTEM_PROMPT).toContain('You are Lucy');
|
|
123
145
|
expect(SYSTEM_PROMPT).toContain('[ASK_USER]');
|
|
146
|
+
// Lucy knows her computer without being told, and how this chat shows it.
|
|
147
|
+
expect(SYSTEM_PROMPT).toContain('the Computer of the yantra-computer skill');
|
|
148
|
+
expect(SYSTEM_PROMPT).toContain('[[surface:computer|the step there]]');
|
|
124
149
|
});
|
|
125
150
|
});
|