@isomorph.ai/app-sdk 1.40.0 → 1.41.0

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/README.md CHANGED
@@ -457,7 +457,24 @@ Keep that table protected by the app's user row rules. A trusted action must sti
457
457
 
458
458
  The outer agent may use app-defined tools for takeover and opening the authorized view. Resume requires an explicit user or app decision. Keep any outer-agent conversation in the app's existing job/task storage when ending a waiting job; this SDK does not persist the outer model's messages. The CUA persists its own conversation/resume state under the same task folder as screenshots and progress in its existing result bucket, without passwords or OTPs.
459
459
 
460
- P0 `getSavedLogin(accountRef, website)` and `getOtp(taskId, website)` return `{status:'unavailable'}` and call no integration. Use human takeover when no approved backend input is supplied. Governance saved-login/website storage and email/SMS OTP lookup are P0.5, not part of this SDK change. These task helpers require the matching CUA handoff release; existing new-computer sign-in helpers below remain separate.
460
+ A website that texts or mails a one-time code: `signInWithOtp` from `dist/computer-use-otp.js` does the password login, waits for the helper to ask for the code, reads it from the company's own phone number or mailbox through the app's integration grant, answers it once and returns when the helper succeeded or needs a person. The app process does the reading; the computer-use service never calls governance.
461
+
462
+ ```ts
463
+ import { signInWithOtp } from '@isomorph.ai/app-sdk/dist/computer-use-otp.js';
464
+ const answer = await signInWithOtp(computer, input.pauseId, { allowedHosts: ['netbanking.hdfcbank.com'], username, password }, {
465
+ execute: app.integrations.execute,
466
+ sms: { connection: 'company-phone', from: 'HDFCBK' }, // phone.sms.list on the company line
467
+ // email: { connection: 'company-gmail', provider: 'gmail', from: 'alerts@hdfcbank.net' }, // or the connected mailbox (gmail | outlook)
468
+ });
469
+ // { status: 'success' } | { status: 'human_help_needed', reason } | { status: 'ended', taskStatus }
470
+ ```
471
+
472
+ - Only messages that arrived after the login started count; the code is the 4 to 8 digits next to "OTP", "code" or "password" (`extract` overrides it). It waits `timeoutMs` (3 min) for the message, checking every `pollIntervalMs` (5 s).
473
+ - One code per pause: a website that asks for a second one gets a person (`human_help_needed`), as does a helper that gives up. Success leaves the task paused; resume it as above.
474
+ - `readOtp(source, since)` reads a code on its own, for a page that asks for one outside a login.
475
+ - The connection needs the app's grant for `phone.sms.list`, or `gmail.thread.list` + `gmail.message.read` (Outlook: `outlook.message.list` + `outlook.message.read`), and the portal account must be registered to that number or mailbox.
476
+
477
+ `getSavedLogin(accountRef, website)` still returns `{status:'unavailable'}`; governance saved-login storage is not part of the SDK. These task helpers require the matching CUA handoff release; existing new-computer sign-in helpers below remain separate.
461
478
 
462
479
  ## Browser sign-in for computer use
463
480
 
@@ -73,6 +73,5 @@ export declare function createComputerUseHandoff(options: ComputerUseHandoffOpti
73
73
  export declare function getSavedLogin(_accountRef: string, _website: string): Promise<{
74
74
  status: 'unavailable';
75
75
  }>;
76
- export declare function getOtp(_taskId: string, _website: string): Promise<{
77
- status: 'unavailable';
78
- }>;
76
+ /** A one-time code comes from the app's own mailbox or phone number: `signInWithOtp` in `computer-use-otp.js`. */
77
+ export { readOtp, signInWithOtp } from './computer-use-otp.js';
@@ -104,6 +104,5 @@ function validSecret(value) {
104
104
  export async function getSavedLogin(_accountRef, _website) {
105
105
  return { status: 'unavailable' };
106
106
  }
107
- export async function getOtp(_taskId, _website) {
108
- return { status: 'unavailable' };
109
- }
107
+ /** A one-time code comes from the app's own mailbox or phone number: `signInWithOtp` in `computer-use-otp.js`. */
108
+ export { readOtp, signInWithOtp } from './computer-use-otp.js';
@@ -0,0 +1,62 @@
1
+ import type { createComputerUseHandoff } from './computer-use-handoff.js';
2
+ type Handoff = ReturnType<typeof createComputerUseHandoff>;
3
+ /** `app.integrations.execute` from `createClient()`: the app's own grant, identity and rate limit. */
4
+ export type IntegrationExecute = (connection: string, request: {
5
+ operation: string;
6
+ resource: string;
7
+ input?: Record<string, unknown>;
8
+ }) => Promise<unknown>;
9
+ export interface OtpSource {
10
+ execute: IntegrationExecute;
11
+ /** The connected mailbox the website mails the code to. `from` is the website's sender address. */
12
+ email?: {
13
+ connection: string;
14
+ provider: 'gmail' | 'outlook';
15
+ from: string;
16
+ resource?: string;
17
+ };
18
+ /** The company phone number the website texts the code to. `from` is the sender id, such as `HDFCBK`. */
19
+ sms?: {
20
+ connection: string;
21
+ from?: string;
22
+ resource?: string;
23
+ };
24
+ /** The code in a message's text; the default takes 4 to 8 digits next to "OTP", "code" or "password", else the first such group. */
25
+ extract?: (text: string) => string | undefined;
26
+ /** How long to wait for the message, default 3 minutes; checked every `pollIntervalMs`, default 5 s. */
27
+ timeoutMs?: number;
28
+ pollIntervalMs?: number;
29
+ }
30
+ export type OtpSignIn = {
31
+ status: 'success';
32
+ }
33
+ /** The website wants a person: no code arrived in time, a second code was asked for, or the helper gave up. The task is still paused. */
34
+ | {
35
+ status: 'human_help_needed';
36
+ reason: string;
37
+ }
38
+ /** The task ended while signing in. */
39
+ | {
40
+ status: 'ended';
41
+ taskStatus: string;
42
+ };
43
+ export declare function extractOtp(text: string): string | undefined;
44
+ /** Reads the website's one-time code sent since `since`, waiting up to `timeoutMs` for it to arrive. */
45
+ export declare function readOtp(options: OtpSource, since: Date, now?: () => number): Promise<string | undefined>;
46
+ /**
47
+ * Signs in on a paused task's computer with a username and password, answers
48
+ * the website's one-time code from the mailbox or phone the app may read, and
49
+ * returns once the helper succeeded or needs a person. Call it only from
50
+ * private server code: the values never reach a model, a log or a job result.
51
+ * Success leaves the task paused; the app resumes it when it decides to.
52
+ */
53
+ export declare function signInWithOtp(handoff: Handoff, pauseId: string, login: {
54
+ allowedHosts: readonly string[];
55
+ username: string;
56
+ password: string;
57
+ }, otp: OtpSource, options?: {
58
+ pollIntervalMs?: number;
59
+ timeoutMs?: number;
60
+ now?: () => number;
61
+ }): Promise<OtpSignIn>;
62
+ export {};
@@ -0,0 +1,92 @@
1
+ const CODE_NEAR_WORD = /(?:otp|one[\s-]?time|passcode|password|code|pin)\D{0,40}?(\d{4,8})\b/i;
2
+ const CODE_ALONE = /\b(\d{4,8})\b/;
3
+ export function extractOtp(text) {
4
+ return CODE_NEAR_WORD.exec(text)?.[1] ?? CODE_ALONE.exec(text)?.[1];
5
+ }
6
+ function source(options) {
7
+ if (typeof options.execute !== 'function' || (options.email === undefined) === (options.sms === undefined))
8
+ throw new Error('An OTP source is execute plus exactly one of email or sms.');
9
+ return { kind: options.email ? 'email' : 'sms' };
10
+ }
11
+ /** The newest message from the website since `since`, as text, or undefined when none has arrived. */
12
+ async function latestMessage(options, since) {
13
+ const arrived = (at) => new Date(at).getTime() >= since.getTime();
14
+ if (options.sms) {
15
+ const { connection, from, resource = 'company-line' } = options.sms;
16
+ const answer = await options.execute(connection, { operation: 'phone.sms.list', resource, input: { since: since.toISOString(), ...(from ? { from } : {}) } });
17
+ const message = (answer.messages ?? []).filter(item => arrived(item.receivedAt)).sort((a, b) => b.receivedAt.localeCompare(a.receivedAt))[0];
18
+ return message?.body;
19
+ }
20
+ const { connection, provider, from, resource = 'inbox' } = options.email;
21
+ if (provider === 'gmail') {
22
+ const list = await options.execute(connection, { operation: 'gmail.thread.list', resource, input: { q: `from:${from} newer_than:1d`, limit: 10 } });
23
+ const thread = (list.threads ?? []).filter(item => arrived(item.date)).sort((a, b) => b.date.localeCompare(a.date))[0];
24
+ if (!thread)
25
+ return undefined;
26
+ const message = await options.execute(connection, { operation: 'gmail.message.read', resource, input: { messageId: thread.messageId } });
27
+ return `${message.subject}\n${message.text}`;
28
+ }
29
+ const list = await options.execute(connection, { operation: 'outlook.message.list', resource, input: { q: `from:${from}` } });
30
+ const summary = (list.mailMessages ?? []).filter(item => arrived(item.receivedAt) && item.from.toLowerCase().includes(from.toLowerCase())).sort((a, b) => b.receivedAt.localeCompare(a.receivedAt))[0];
31
+ if (!summary)
32
+ return undefined;
33
+ const message = await options.execute(connection, { operation: 'outlook.message.read', resource, input: { messageId: summary.id } });
34
+ return `${message.subject}\n${message.text}`;
35
+ }
36
+ const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
37
+ /** Reads the website's one-time code sent since `since`, waiting up to `timeoutMs` for it to arrive. */
38
+ export async function readOtp(options, since, now = Date.now) {
39
+ source(options);
40
+ const extract = options.extract ?? extractOtp;
41
+ const deadline = now() + (options.timeoutMs ?? 180_000);
42
+ for (;;) {
43
+ const text = await latestMessage(options, since);
44
+ const code = text === undefined ? undefined : extract(text);
45
+ if (code)
46
+ return code;
47
+ if (now() >= deadline)
48
+ return undefined;
49
+ await sleep(options.pollIntervalMs ?? 5_000);
50
+ }
51
+ }
52
+ /**
53
+ * Signs in on a paused task's computer with a username and password, answers
54
+ * the website's one-time code from the mailbox or phone the app may read, and
55
+ * returns once the helper succeeded or needs a person. Call it only from
56
+ * private server code: the values never reach a model, a log or a job result.
57
+ * Success leaves the task paused; the app resumes it when it decides to.
58
+ */
59
+ export async function signInWithOtp(handoff, pauseId, login, otp, options = {}) {
60
+ source(otp);
61
+ const now = options.now ?? Date.now;
62
+ // A clock a minute ahead of the mail server must not hide the code.
63
+ const since = new Date(now() - 60_000);
64
+ await handoff.completeLogin(pauseId, login);
65
+ let answered = false;
66
+ const deadline = now() + (options.timeoutMs ?? 600_000);
67
+ for (;;) {
68
+ await sleep(options.pollIntervalMs ?? 5_000);
69
+ const check = await handoff.check();
70
+ if (check.status === 'done' || check.status === 'failed')
71
+ return { status: 'ended', taskStatus: check.status };
72
+ if (check.status !== 'waiting_for_input') {
73
+ if (now() >= deadline)
74
+ return { status: 'human_help_needed', reason: 'The sign-in helper did not finish in time.' };
75
+ continue;
76
+ }
77
+ const login = check.login;
78
+ if (login?.status === 'success')
79
+ return { status: 'success' };
80
+ if (login?.status === 'human_help_needed')
81
+ return { status: 'human_help_needed', reason: 'The sign-in helper could not finish on its own.' };
82
+ if (login?.status === 'needs_input' && login.input === 'otp') {
83
+ if (answered)
84
+ return { status: 'human_help_needed', reason: 'The website asked for a second code.' };
85
+ const code = await readOtp(otp, since, now);
86
+ if (!code)
87
+ return { status: 'human_help_needed', reason: `No code arrived by ${otp.email ? 'email' : 'SMS'} in time.` };
88
+ await handoff.completeLogin(pauseId, { otp: code });
89
+ answered = true;
90
+ }
91
+ }
92
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@isomorph.ai/app-sdk",
3
- "version": "1.40.0",
3
+ "version": "1.41.0",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",