@isomorph.ai/app-sdk 1.41.0 → 1.42.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 +4 -4
- package/dist/computer-use-handoff.d.ts +28 -15
- package/dist/computer-use-handoff.js +22 -5
- package/dist/computer-use-otp.js +3 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -448,11 +448,11 @@ export default async function viewComputer(input: { taskId: string; pauseId: str
|
|
|
448
448
|
|
|
449
449
|
Keep that table protected by the app's user row rules. A trusted action must still check `owner_id` against `ctx.user.id`; never use workload identity as proof of human ownership.
|
|
450
450
|
|
|
451
|
-
- `requestTakeover(reason, requiredInput?)` requests a pause; `requiredInput` is `human` (default) or `login`. Poll `check()` until `waiting_for_input` gives `
|
|
452
|
-
- `view(pauseId)` returns `{status:'
|
|
453
|
-
- `input(pauseId, action)` sends the same `SignInAction` click/type/key/scroll commands used by `sendSignInInput
|
|
451
|
+
- `requestTakeover(reason, requiredInput?)` requests a pause; `requiredInput` is `human` (default) or `login`. It answers the pause (`taskId`, `pauseId`, `status`, `reason`, `requiredInput`; the same pause again if one exists). Poll `check()` until `waiting_for_input` gives the pause plus the optional login result; while the task is not waiting, `check()` answers its progress (`status`, `steps`, `lastStep`, `summary`, `finalUrl`, `waiting`, `message`).
|
|
452
|
+
- `view(pauseId)` returns `{status:'ready', screenshot, url}`; while the task is still pausing, or once it resumed, the API answers 409 and the call throws. Reuse the existing sign-in screenshot UI: display the base64 PNG as an image, map clicks to image pixels, and forward keyboard/scroll events through app actions. Viewing does not itself resume the agent.
|
|
453
|
+
- `input(pauseId, action)` sends the same `SignInAction` click/type/key/scroll commands used by `sendSignInInput` (`typeText` may be up to 4096 characters here) and answers what the computer did. The CUA accepts human input only while the task is paused; it blocks the helper and main agent from acting at the same time.
|
|
454
454
|
- `completeLogin(pauseId, {allowedHosts, username, password})`, or `completeLogin(pauseId, {otp})`, queues the separate browser-action-only login agent on this computer. **Call only from private server code, never expose this method or credentials as model tool inputs, prompts, progress, logs or job input/results.** Poll `check()` for `login.status: success | needs_input | human_help_needed`, with `input:'otp'` when another code is needed. Helper success leaves the main agent paused.
|
|
455
|
-
- `resume(pauseId)` explicitly resumes
|
|
455
|
+
- `resume(pauseId)` explicitly resumes and answers the pause with `status: 'resume_queued'`; it does not wait for completion. On Continue, call this from the authorized app action, then enqueue the app's continuation job. That job creates `createComputerUseTool({...jobOptions, runKey: originalRunKey, attach:true})`: it polls the same task without sending `/tasks` again. Keep the original saved-session and download options if needed. Stale/duplicate resumes fail with 409; do not silently retry with a new pause ID. If enqueue fails, retry attaching to the already resumed task, not another resume.
|
|
456
456
|
- `cancel()` stops the task, including while waiting.
|
|
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.
|
|
@@ -27,12 +27,34 @@ export declare function waitingInput(answer: {
|
|
|
27
27
|
message?: unknown;
|
|
28
28
|
}): ComputerUseWaiting;
|
|
29
29
|
export type ComputerUsePage = {
|
|
30
|
-
status: 'pausing';
|
|
31
|
-
} | {
|
|
32
30
|
status: 'ready';
|
|
33
31
|
screenshot: string;
|
|
34
32
|
url: string;
|
|
35
33
|
};
|
|
34
|
+
/** A pause as the computer-use API describes it on takeover, login and resume; `status` is the task's, not only `waiting_for_input`. */
|
|
35
|
+
export type ComputerUsePause = {
|
|
36
|
+
taskId: string;
|
|
37
|
+
pauseId: string;
|
|
38
|
+
status: string;
|
|
39
|
+
reason: string;
|
|
40
|
+
requiredInput: 'login' | 'otp' | 'human';
|
|
41
|
+
};
|
|
42
|
+
/** What the paused computer answered to one input: the desktop function's own result, passed through. */
|
|
43
|
+
export type ComputerUseInputResult = Record<string, unknown>;
|
|
44
|
+
/** Progress of a task that is not waiting: the same fields `createComputerUseTool` reads while it polls. */
|
|
45
|
+
export type ComputerUseProgress = {
|
|
46
|
+
status: string;
|
|
47
|
+
steps?: number;
|
|
48
|
+
lastStep?: string | null;
|
|
49
|
+
summary?: string | null;
|
|
50
|
+
finalUrl?: string | null;
|
|
51
|
+
waiting?: {
|
|
52
|
+
reason: string;
|
|
53
|
+
since: string;
|
|
54
|
+
attempts: number;
|
|
55
|
+
} | null;
|
|
56
|
+
message?: ComputerUseMessage;
|
|
57
|
+
};
|
|
36
58
|
export type ComputerUseLoginInput = {
|
|
37
59
|
allowedHosts: readonly string[];
|
|
38
60
|
username: string;
|
|
@@ -49,23 +71,14 @@ export interface ComputerUseHandoffOptions extends ComputerUseTransport {
|
|
|
49
71
|
authorize(): Promise<boolean> | boolean;
|
|
50
72
|
}
|
|
51
73
|
export declare function createComputerUseHandoff(options: ComputerUseHandoffOptions): {
|
|
52
|
-
requestTakeover(reason: string, requiredInput?: "login" | "human"): Promise<
|
|
53
|
-
status: string;
|
|
54
|
-
}>;
|
|
74
|
+
requestTakeover(reason: string, requiredInput?: "login" | "human"): Promise<ComputerUsePause>;
|
|
55
75
|
view(pauseId: string): Promise<ComputerUsePage>;
|
|
56
|
-
input(pauseId: string, action: SignInAction): Promise<
|
|
57
|
-
status: "accepted";
|
|
58
|
-
}>;
|
|
76
|
+
input(pauseId: string, action: SignInAction): Promise<ComputerUseInputResult>;
|
|
59
77
|
completeLogin(pauseId: string, input: ComputerUseLoginInput): Promise<{
|
|
60
78
|
status: "login_queued";
|
|
61
79
|
}>;
|
|
62
|
-
check(): Promise<ComputerUseWaiting |
|
|
63
|
-
|
|
64
|
-
status: string;
|
|
65
|
-
}>;
|
|
66
|
-
resume(pauseId: string): Promise<{
|
|
67
|
-
status: "resume_queued";
|
|
68
|
-
}>;
|
|
80
|
+
check(): Promise<ComputerUseWaiting | ComputerUseProgress>;
|
|
81
|
+
resume(pauseId: string): Promise<ComputerUsePause>;
|
|
69
82
|
cancel(): Promise<{
|
|
70
83
|
status: string;
|
|
71
84
|
}>;
|
|
@@ -46,6 +46,11 @@ export function createComputerUseHandoff(options) {
|
|
|
46
46
|
throw refused(path, answer.status, privateInput ? undefined : answer.body);
|
|
47
47
|
return answer.body;
|
|
48
48
|
};
|
|
49
|
+
const pauseOf = (answer) => {
|
|
50
|
+
if (typeof answer.taskId !== 'string' || typeof answer.pauseId !== 'string' || !['login', 'otp', 'human'].includes(String(answer.requiredInput)))
|
|
51
|
+
throw new Error('The computer use API returned an incomplete pause.');
|
|
52
|
+
return { taskId: answer.taskId, pauseId: answer.pauseId, status: String(answer.status), reason: typeof answer.reason === 'string' ? answer.reason : 'Outside input needed.', requiredInput: answer.requiredInput };
|
|
53
|
+
};
|
|
49
54
|
const paused = (pauseId) => {
|
|
50
55
|
if (!pauseId || typeof pauseId !== 'string')
|
|
51
56
|
throw new Error('Computer use handoff needs the current pauseId.');
|
|
@@ -55,12 +60,11 @@ export function createComputerUseHandoff(options) {
|
|
|
55
60
|
requestTakeover(reason, requiredInput = 'human') {
|
|
56
61
|
if (!reason.trim() || !['login', 'human'].includes(requiredInput))
|
|
57
62
|
throw new Error('Takeover needs a reason and login or human input.');
|
|
58
|
-
return post('/tasks/takeover', { reason, requiredInput });
|
|
63
|
+
return post('/tasks/takeover', { reason, requiredInput }).then(pauseOf);
|
|
59
64
|
},
|
|
65
|
+
// The API answers 409 while the task is still pausing or after it resumed; `ready` is the only 200.
|
|
60
66
|
async view(pauseId) {
|
|
61
67
|
const page = await post('/tasks/view', paused(pauseId));
|
|
62
|
-
if (page.status === 'pausing')
|
|
63
|
-
return { status: 'pausing' };
|
|
64
68
|
if (page.status !== 'ready' || typeof page.screenshot !== 'string' || typeof page.url !== 'string')
|
|
65
69
|
throw new Error('The computer use API returned an incomplete screen.');
|
|
66
70
|
return { status: 'ready', screenshot: page.screenshot, url: page.url };
|
|
@@ -88,10 +92,23 @@ export function createComputerUseHandoff(options) {
|
|
|
88
92
|
if (answer.status === 'waiting_for_input')
|
|
89
93
|
return waitingInput(answer);
|
|
90
94
|
const message = computerUseMessage(answer.message);
|
|
91
|
-
|
|
95
|
+
const progress = { status: String(answer.status) };
|
|
96
|
+
if (typeof answer.steps === 'number')
|
|
97
|
+
progress.steps = answer.steps;
|
|
98
|
+
if (answer.last_step !== undefined)
|
|
99
|
+
progress.lastStep = answer.last_step;
|
|
100
|
+
if (answer.summary !== undefined)
|
|
101
|
+
progress.summary = answer.summary;
|
|
102
|
+
if (answer.final_url !== undefined)
|
|
103
|
+
progress.finalUrl = answer.final_url;
|
|
104
|
+
if (answer.waiting !== undefined)
|
|
105
|
+
progress.waiting = answer.waiting;
|
|
106
|
+
if (message)
|
|
107
|
+
progress.message = message;
|
|
108
|
+
return progress;
|
|
92
109
|
},
|
|
93
110
|
resume(pauseId) {
|
|
94
|
-
return post('/tasks/resume', paused(pauseId));
|
|
111
|
+
return post('/tasks/resume', paused(pauseId)).then(pauseOf);
|
|
95
112
|
},
|
|
96
113
|
cancel() {
|
|
97
114
|
return post('/tasks/cancel');
|
package/dist/computer-use-otp.js
CHANGED
|
@@ -69,11 +69,10 @@ export async function signInWithOtp(handoff, pauseId, login, otp, options = {})
|
|
|
69
69
|
const check = await handoff.check();
|
|
70
70
|
if (check.status === 'done' || check.status === 'failed')
|
|
71
71
|
return { status: 'ended', taskStatus: check.status };
|
|
72
|
-
if (
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
if (now() >= deadline)
|
|
73
|
+
return { status: 'human_help_needed', reason: 'The sign-in helper did not finish in time.' };
|
|
74
|
+
if (check.status !== 'waiting_for_input')
|
|
75
75
|
continue;
|
|
76
|
-
}
|
|
77
76
|
const login = check.login;
|
|
78
77
|
if (login?.status === 'success')
|
|
79
78
|
return { status: 'success' };
|