@openlegion/platform 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/README.md +1189 -2
- package/dist/body.d.ts +9 -0
- package/dist/body.js +28 -0
- package/dist/chat-history.d.ts +53 -0
- package/dist/chat-history.js +11 -0
- package/dist/client.d.ts +217 -0
- package/dist/client.js +367 -0
- package/dist/core.d.ts +47 -0
- package/dist/core.js +1 -0
- package/dist/crypto.d.ts +25 -0
- package/dist/crypto.js +81 -0
- package/dist/errors.d.ts +111 -0
- package/dist/errors.js +134 -0
- package/dist/events.d.ts +131 -0
- package/dist/events.js +5 -0
- package/dist/generated/api.d.ts +5505 -0
- package/dist/generated/api.js +446 -0
- package/dist/handler.d.ts +201 -0
- package/dist/handler.js +682 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +12 -0
- package/dist/kit-agents.d.ts +95 -0
- package/dist/kit-agents.js +280 -0
- package/dist/kit-codes.d.ts +279 -0
- package/dist/kit-codes.js +44 -0
- package/dist/kit-connections.d.ts +21 -0
- package/dist/kit-connections.js +189 -0
- package/dist/kit-files.d.ts +8 -0
- package/dist/kit-files.js +117 -0
- package/dist/kit-model-keys.d.ts +8 -0
- package/dist/kit-model-keys.js +86 -0
- package/dist/kit-threads.d.ts +3 -0
- package/dist/kit-threads.js +92 -0
- package/dist/kit-tools.d.ts +21 -0
- package/dist/kit-tools.js +47 -0
- package/dist/kit.d.ts +130 -0
- package/dist/kit.js +155 -0
- package/dist/mcp-server.d.ts +27 -0
- package/dist/mcp-server.js +166 -0
- package/dist/next.d.ts +24 -0
- package/dist/next.js +6 -0
- package/dist/ol-signed.d.ts +82 -0
- package/dist/ol-signed.js +115 -0
- package/dist/react/add-server.d.ts +90 -0
- package/dist/react/add-server.js +183 -0
- package/dist/react/agent-chat.d.ts +925 -0
- package/dist/react/agent-chat.js +1917 -0
- package/dist/react/agent-editor.d.ts +133 -0
- package/dist/react/agent-editor.js +222 -0
- package/dist/react/agent-kit.d.ts +160 -0
- package/dist/react/agent-kit.js +279 -0
- package/dist/react/agent-list.d.ts +247 -0
- package/dist/react/agent-list.js +248 -0
- package/dist/react/approval-card.d.ts +272 -0
- package/dist/react/approval-card.js +372 -0
- package/dist/react/artifact-card.d.ts +38 -0
- package/dist/react/artifact-card.js +39 -0
- package/dist/react/avatar.d.ts +21 -0
- package/dist/react/avatar.js +33 -0
- package/dist/react/card-ledger.d.ts +30 -0
- package/dist/react/card-ledger.js +49 -0
- package/dist/react/chat-timing.d.ts +121 -0
- package/dist/react/chat-timing.js +229 -0
- package/dist/react/computer-view.d.ts +309 -0
- package/dist/react/computer-view.js +543 -0
- package/dist/react/computer-viewer.d.ts +175 -0
- package/dist/react/computer-viewer.js +555 -0
- package/dist/react/computer-wire.d.ts +178 -0
- package/dist/react/computer-wire.js +244 -0
- package/dist/react/connect-button.d.ts +145 -0
- package/dist/react/connect-button.js +212 -0
- package/dist/react/connection-request.d.ts +16 -0
- package/dist/react/connection-request.js +18 -0
- package/dist/react/connections-list.d.ts +90 -0
- package/dist/react/connections-list.js +76 -0
- package/dist/react/errors.d.ts +250 -0
- package/dist/react/errors.js +146 -0
- package/dist/react/files.d.ts +41 -0
- package/dist/react/files.js +78 -0
- package/dist/react/index.d.ts +35 -0
- package/dist/react/index.js +26 -0
- package/dist/react/limit-words.d.ts +80 -0
- package/dist/react/limit-words.js +53 -0
- package/dist/react/markdown.d.ts +42 -0
- package/dist/react/markdown.js +56 -0
- package/dist/react/md-parse.d.ts +106 -0
- package/dist/react/md-parse.js +638 -0
- package/dist/react/model-keys-card.d.ts +94 -0
- package/dist/react/model-keys-card.js +123 -0
- package/dist/react/reload.d.ts +211 -0
- package/dist/react/reload.js +339 -0
- package/dist/react/reveal.d.ts +17 -0
- package/dist/react/reveal.js +22 -0
- package/dist/react/schedule-editor.d.ts +107 -0
- package/dist/react/schedule-editor.js +172 -0
- package/dist/react/schedule-time.d.ts +66 -0
- package/dist/react/schedule-time.js +90 -0
- package/dist/react/styles.css +1274 -0
- package/dist/react/transport.d.ts +49 -0
- package/dist/react/transport.js +380 -0
- package/dist/react/use-connections.d.ts +155 -0
- package/dist/react/use-connections.js +231 -0
- package/dist/react/use-model-keys.d.ts +47 -0
- package/dist/react/use-model-keys.js +57 -0
- package/dist/react/use-threads.d.ts +63 -0
- package/dist/react/use-threads.js +73 -0
- package/dist/react/vault-form.d.ts +92 -0
- package/dist/react/vault-form.js +151 -0
- package/dist/schema.d.ts +47 -0
- package/dist/schema.js +16 -0
- package/dist/secrets.d.ts +15 -0
- package/dist/secrets.js +18 -0
- package/dist/stream.d.ts +129 -0
- package/dist/stream.js +192 -0
- package/dist/testing.d.ts +33 -0
- package/dist/testing.js +40 -0
- package/dist/webhooks.d.ts +31 -0
- package/dist/webhooks.js +72 -0
- package/package.json +85 -3
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The chat's timing: when it looks for the run a decision starts (`followUpWaits`, `lookAfterDecision`), when an
|
|
3
|
+
* open conversation looks for what arrived (`noticeLooks`), how long it shows it is working after a decision
|
|
4
|
+
* (`decisionWatch`), and where a Stop stands (`stopStateAfter`). Pure, with their clocks passed in where a test
|
|
5
|
+
* needs them; `useAgentChat` wires them (`agent-chat.tsx`, which re-exports them).
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* How long to wait before each look for the run an approval decision starts: every second for the first 30 s (the
|
|
9
|
+
* chat shows it is working meanwhile, and a 204 is cheap), then doubling up to 15 s, for about two minutes in all (a
|
|
10
|
+
* resumed run can take that long to start). The kit answers 204 until then.
|
|
11
|
+
*/
|
|
12
|
+
export declare function followUpWaits(totalMs?: number): number[];
|
|
13
|
+
/**
|
|
14
|
+
* The looks for the run a decision starts (`followUpWaits`), until one follows it (`followed`, set when a followed
|
|
15
|
+
* reply ends) or the chat is gone. APPROVED EARLY (run 6): tapped while a reply was being written, the decision's run
|
|
16
|
+
* cannot start before that reply's run ends, and that reply's end is not the decision's run. The looks begin once it
|
|
17
|
+
* has ended (`replyOpen`), and run their whole schedule from then.
|
|
18
|
+
*/
|
|
19
|
+
export declare function lookAfterDecision(o: {
|
|
20
|
+
replyOpen: Promise<void> | null;
|
|
21
|
+
begin: () => void;
|
|
22
|
+
look: () => Promise<void>;
|
|
23
|
+
followed: () => boolean;
|
|
24
|
+
here: () => boolean;
|
|
25
|
+
missed?: () => Promise<boolean>;
|
|
26
|
+
sleep?: (ms: number) => Promise<void>;
|
|
27
|
+
}): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* WHEN AN OPEN CONVERSATION LOOKS: every `everyMs` while `visible()` and `idle()`, and on `poke()` (the tab
|
|
30
|
+
* shown, the window focused) when both hold; never two looks within 2 s, and not right after it opens (it looked
|
|
31
|
+
* then). `everyMs` 0: never.
|
|
32
|
+
*
|
|
33
|
+
* A LOOK OWED IS TAKEN AS SOON AS IT CAN BE (case B): a tick that found the chat busy is owed, and taken when the chat
|
|
34
|
+
* says it is idle again (`settled()`), not a whole period later. A look that found a run, or whose read of the thread
|
|
35
|
+
* failed (`look` resolves false: it followed the run, the run was just ending, the read did not come back) is looked
|
|
36
|
+
* again 2 s after it ended, so the thread is read after the run, at most 3 times in a row.
|
|
37
|
+
*/
|
|
38
|
+
export declare function noticeLooks(o: {
|
|
39
|
+
everyMs: number;
|
|
40
|
+
visible: () => boolean;
|
|
41
|
+
idle: () => boolean;
|
|
42
|
+
look: () => void | Promise<boolean>;
|
|
43
|
+
now?: () => number;
|
|
44
|
+
}): {
|
|
45
|
+
poke(): void;
|
|
46
|
+
settled(): void;
|
|
47
|
+
dispose(): void;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* AFTER APPROVE OR REJECT, THE CHAT SHOWS IT IS WORKING: from the platform's answer until the reply the decision
|
|
51
|
+
* starts has ended, or for 30 s if no reply is found. Not before: the card says it is being decided until then, and an
|
|
52
|
+
* answer with no run to follow (`run_refused`: the workspace cannot run, the agent is paused) never shows it working
|
|
53
|
+
* (REJECT-THINKING). The run is found by looking (`followUp`), so a Stop asked before then is
|
|
54
|
+
* remembered and sent the moment a look finds it. `useAgentChat` wires it: `show` is the working state, `follow`
|
|
55
|
+
* starts the looks, `stop` stops the run being followed.
|
|
56
|
+
*/
|
|
57
|
+
export interface DecisionWatch {
|
|
58
|
+
/** Approve or Reject was tapped; `taken` says whether the platform took the decision with a run to follow. `replyOpen`: a reply was being written at the tap. */
|
|
59
|
+
decided(taken: Promise<boolean>, replyOpen?: boolean): void;
|
|
60
|
+
/** A look found the run and its reply is being drawn. */
|
|
61
|
+
attached(): void;
|
|
62
|
+
/** The reply being drawn ended (the decision's, or the one open at the tap). */
|
|
63
|
+
ended(): void;
|
|
64
|
+
/** Stop, asked while waiting with no run found yet: true when it is remembered for that run. */
|
|
65
|
+
stopEarly(): boolean;
|
|
66
|
+
dispose(): void;
|
|
67
|
+
}
|
|
68
|
+
export declare function decisionWatch(o: {
|
|
69
|
+
show: (working: boolean) => void;
|
|
70
|
+
follow: () => void;
|
|
71
|
+
stop: () => void;
|
|
72
|
+
windowMs?: number;
|
|
73
|
+
}): DecisionWatch;
|
|
74
|
+
/** Where a Stop stands: asked, done (the run's stream said so), or not possible (the reply carries on). */
|
|
75
|
+
export type StopState = "stopping" | "stopped" | "failed";
|
|
76
|
+
/** What moves a Stop along (`stopStateAfter`). */
|
|
77
|
+
type StopEvent = {
|
|
78
|
+
type: "tap";
|
|
79
|
+
} | {
|
|
80
|
+
type: "stream-stopped";
|
|
81
|
+
} | {
|
|
82
|
+
type: "ended";
|
|
83
|
+
} | {
|
|
84
|
+
type: "no-run";
|
|
85
|
+
} | {
|
|
86
|
+
type: "refused";
|
|
87
|
+
busy: boolean;
|
|
88
|
+
} | {
|
|
89
|
+
type: "send";
|
|
90
|
+
startsReply: boolean;
|
|
91
|
+
} | {
|
|
92
|
+
type: "gone";
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* STOP IS IMMEDIATE IN THE KIT. The engine starts no new work after a Stop but lets the model call in flight
|
|
96
|
+
* finish, so the run ends up to one model call later. From the tap: "stopping" (Send is back, "Stopping…" where
|
|
97
|
+
* "Stopped." will go); the run's stream says it stopped: "stopped"; the reply ends: null, the line now carried by
|
|
98
|
+
* the reply itself (`stopped`, as a reload draws it). A message sent meanwhile waits its turn and leaves the state
|
|
99
|
+
* as it is; only a send that starts a reply clears it. A run that ended before the stop took leaves no line.
|
|
100
|
+
*/
|
|
101
|
+
export declare function stopStateAfter(s: StopState | null, e: StopEvent): StopState | null;
|
|
102
|
+
/** After the read at a reply's end, how many more looks try a run's read before it is let go. */
|
|
103
|
+
export declare const SETTLE_LOOKS = 3;
|
|
104
|
+
/**
|
|
105
|
+
* A RUN'S READ IS OWED UNTIL A READ HOLDS ITS REPLY. When a followed reply
|
|
106
|
+
* ends, the chat reads the thread to draw it as a reload would; a replayed stream carries only words, so a read that
|
|
107
|
+
* fails, or comes before the run's message is written, would leave its tool lines and approval card out for good.
|
|
108
|
+
* `ended` owes the run's read, `settled` pays it, `missed` counts a read that did not; each look tries what is
|
|
109
|
+
* `owed`, and a run missed `max` more times is let go (a run that left no reply, as a stop before any words, must
|
|
110
|
+
* not keep the chat looking).
|
|
111
|
+
*/
|
|
112
|
+
export declare function settleLedger(max?: number): {
|
|
113
|
+
ended(run: string, liveId: string): void;
|
|
114
|
+
settled(run: string): void;
|
|
115
|
+
missed(run: string): void;
|
|
116
|
+
owed(): Array<{
|
|
117
|
+
run: string;
|
|
118
|
+
liveId: string;
|
|
119
|
+
}>;
|
|
120
|
+
};
|
|
121
|
+
export {};
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
export function followUpWaits(totalMs = 120_000) {
|
|
2
|
+
const waits = [500];
|
|
3
|
+
let sum = 500;
|
|
4
|
+
while (sum + 1000 <= DECISION_WINDOW_MS) {
|
|
5
|
+
waits.push(1000);
|
|
6
|
+
sum += 1000;
|
|
7
|
+
}
|
|
8
|
+
for (;;) {
|
|
9
|
+
const next = Math.min(Math.max(waits[waits.length - 1] * 2, 2000), 15_000);
|
|
10
|
+
if (sum >= totalMs - next / 2)
|
|
11
|
+
break;
|
|
12
|
+
waits.push(next);
|
|
13
|
+
sum += next;
|
|
14
|
+
}
|
|
15
|
+
return waits;
|
|
16
|
+
}
|
|
17
|
+
export async function lookAfterDecision(o) {
|
|
18
|
+
const sleep = o.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
19
|
+
if (o.replyOpen)
|
|
20
|
+
await o.replyOpen;
|
|
21
|
+
if (!o.here())
|
|
22
|
+
return;
|
|
23
|
+
o.begin();
|
|
24
|
+
let read = false;
|
|
25
|
+
for (const wait of followUpWaits()) {
|
|
26
|
+
await sleep(wait);
|
|
27
|
+
if (o.followed() || !o.here())
|
|
28
|
+
return;
|
|
29
|
+
await o.look();
|
|
30
|
+
if (o.followed())
|
|
31
|
+
return;
|
|
32
|
+
if (!read && o.missed) {
|
|
33
|
+
read = true;
|
|
34
|
+
if (await o.missed())
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (o.missed && o.here() && !o.followed())
|
|
39
|
+
await o.missed();
|
|
40
|
+
}
|
|
41
|
+
export function noticeLooks(o) {
|
|
42
|
+
const now = o.now ?? (() => Date.now());
|
|
43
|
+
let last = now();
|
|
44
|
+
let live = o.everyMs > 0;
|
|
45
|
+
let owed = false;
|
|
46
|
+
let again = 0;
|
|
47
|
+
let soon;
|
|
48
|
+
const tryLook = () => {
|
|
49
|
+
if (!live || !o.visible())
|
|
50
|
+
return;
|
|
51
|
+
if (!o.idle()) {
|
|
52
|
+
owed = true;
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (now() - last < NOTICE_GAP_MS)
|
|
56
|
+
return;
|
|
57
|
+
last = now();
|
|
58
|
+
owed = false;
|
|
59
|
+
const done = o.look();
|
|
60
|
+
if (!done)
|
|
61
|
+
return;
|
|
62
|
+
void done.then((idle) => {
|
|
63
|
+
if (!live)
|
|
64
|
+
return;
|
|
65
|
+
if (idle !== false || again >= NOTICE_AGAIN) {
|
|
66
|
+
again = 0;
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
again += 1;
|
|
70
|
+
owed = true;
|
|
71
|
+
if (soon !== undefined)
|
|
72
|
+
clearTimeout(soon);
|
|
73
|
+
soon = setTimeout(() => {
|
|
74
|
+
soon = undefined;
|
|
75
|
+
if (owed)
|
|
76
|
+
tryLook();
|
|
77
|
+
}, NOTICE_GAP_MS);
|
|
78
|
+
}, () => undefined);
|
|
79
|
+
};
|
|
80
|
+
const timer = live
|
|
81
|
+
? setInterval(() => {
|
|
82
|
+
again = 0;
|
|
83
|
+
tryLook();
|
|
84
|
+
}, o.everyMs)
|
|
85
|
+
: undefined;
|
|
86
|
+
return {
|
|
87
|
+
poke: tryLook,
|
|
88
|
+
settled() {
|
|
89
|
+
if (owed)
|
|
90
|
+
tryLook();
|
|
91
|
+
},
|
|
92
|
+
dispose() {
|
|
93
|
+
live = false;
|
|
94
|
+
if (timer !== undefined)
|
|
95
|
+
clearInterval(timer);
|
|
96
|
+
if (soon !== undefined)
|
|
97
|
+
clearTimeout(soon);
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const NOTICE_GAP_MS = 2_000;
|
|
102
|
+
const NOTICE_AGAIN = 3;
|
|
103
|
+
const DECISION_WINDOW_MS = 30_000;
|
|
104
|
+
export function decisionWatch(o) {
|
|
105
|
+
let waiting = false;
|
|
106
|
+
let shown = false;
|
|
107
|
+
let found = false;
|
|
108
|
+
let stopWanted = false;
|
|
109
|
+
let replyOpen = false;
|
|
110
|
+
let timer;
|
|
111
|
+
let decision = 0;
|
|
112
|
+
const finish = () => {
|
|
113
|
+
if (timer !== undefined)
|
|
114
|
+
clearTimeout(timer);
|
|
115
|
+
timer = undefined;
|
|
116
|
+
const was = shown;
|
|
117
|
+
waiting = false;
|
|
118
|
+
shown = false;
|
|
119
|
+
found = false;
|
|
120
|
+
stopWanted = false;
|
|
121
|
+
replyOpen = false;
|
|
122
|
+
if (was)
|
|
123
|
+
o.show(false);
|
|
124
|
+
};
|
|
125
|
+
const countDown = () => {
|
|
126
|
+
if (timer !== undefined)
|
|
127
|
+
clearTimeout(timer);
|
|
128
|
+
timer = setTimeout(() => {
|
|
129
|
+
timer = undefined;
|
|
130
|
+
if (waiting && !found)
|
|
131
|
+
finish();
|
|
132
|
+
}, o.windowMs ?? DECISION_WINDOW_MS);
|
|
133
|
+
};
|
|
134
|
+
return {
|
|
135
|
+
decided(taken, open = false) {
|
|
136
|
+
const mine = ++decision;
|
|
137
|
+
waiting = true;
|
|
138
|
+
found = false;
|
|
139
|
+
replyOpen = open;
|
|
140
|
+
if (timer !== undefined)
|
|
141
|
+
clearTimeout(timer);
|
|
142
|
+
timer = undefined;
|
|
143
|
+
if (!open)
|
|
144
|
+
countDown();
|
|
145
|
+
void taken.then((ok) => {
|
|
146
|
+
if (mine !== decision || !waiting)
|
|
147
|
+
return;
|
|
148
|
+
if (!ok)
|
|
149
|
+
return finish();
|
|
150
|
+
if (!shown) {
|
|
151
|
+
shown = true;
|
|
152
|
+
o.show(true);
|
|
153
|
+
}
|
|
154
|
+
o.follow();
|
|
155
|
+
}, () => {
|
|
156
|
+
if (mine === decision)
|
|
157
|
+
finish();
|
|
158
|
+
});
|
|
159
|
+
},
|
|
160
|
+
attached() {
|
|
161
|
+
if (!waiting)
|
|
162
|
+
return;
|
|
163
|
+
found = true;
|
|
164
|
+
if (stopWanted) {
|
|
165
|
+
stopWanted = false;
|
|
166
|
+
o.stop();
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
ended() {
|
|
170
|
+
if (!waiting)
|
|
171
|
+
return;
|
|
172
|
+
if (found)
|
|
173
|
+
return finish();
|
|
174
|
+
if (replyOpen) {
|
|
175
|
+
replyOpen = false;
|
|
176
|
+
countDown();
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
stopEarly() {
|
|
180
|
+
if (!waiting || found)
|
|
181
|
+
return false;
|
|
182
|
+
stopWanted = true;
|
|
183
|
+
return true;
|
|
184
|
+
},
|
|
185
|
+
dispose() {
|
|
186
|
+
if (timer !== undefined)
|
|
187
|
+
clearTimeout(timer);
|
|
188
|
+
timer = undefined;
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
export function stopStateAfter(s, e) {
|
|
193
|
+
switch (e.type) {
|
|
194
|
+
case "tap":
|
|
195
|
+
return "stopping";
|
|
196
|
+
case "stream-stopped":
|
|
197
|
+
return "stopped";
|
|
198
|
+
case "ended":
|
|
199
|
+
case "no-run":
|
|
200
|
+
return null;
|
|
201
|
+
case "refused":
|
|
202
|
+
return e.busy ? "failed" : null;
|
|
203
|
+
case "send":
|
|
204
|
+
return e.startsReply || s === "failed" ? null : s;
|
|
205
|
+
case "gone":
|
|
206
|
+
return s === "stopping" ? null : s;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
export const SETTLE_LOOKS = 3;
|
|
210
|
+
export function settleLedger(max = SETTLE_LOOKS) {
|
|
211
|
+
const owed = new Map();
|
|
212
|
+
return {
|
|
213
|
+
ended(run, liveId) {
|
|
214
|
+
owed.set(run, { liveId, misses: -1 });
|
|
215
|
+
},
|
|
216
|
+
settled(run) {
|
|
217
|
+
owed.delete(run);
|
|
218
|
+
},
|
|
219
|
+
missed(run) {
|
|
220
|
+
const o = owed.get(run);
|
|
221
|
+
if (!o)
|
|
222
|
+
return;
|
|
223
|
+
o.misses += 1;
|
|
224
|
+
if (o.misses >= max)
|
|
225
|
+
owed.delete(run);
|
|
226
|
+
},
|
|
227
|
+
owed: () => [...owed].map(([run, o]) => ({ run, liveId: o.liveId })),
|
|
228
|
+
};
|
|
229
|
+
}
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<ComputerView>`: a person watches their agent's browser live, and can take over and give back.
|
|
3
|
+
*
|
|
4
|
+
* <ComputerView session={computerSessionOf(part.data)} fetchViewer={({ control, signal }) =>
|
|
5
|
+
* fetch("/api/computer-viewer", { method: "POST", body: JSON.stringify({ session, control }), signal }).then(readViewerGrant)} />
|
|
6
|
+
*
|
|
7
|
+
* `<AgentChat computer={{ fetchViewer }}>` draws it for you: each `data-computer` part is a one-line row with Watch,
|
|
8
|
+
* and Watch opens this view in place (no live thumbnail: a picture per part would mint a token for everyone who
|
|
9
|
+
* scrolls past, and a 1280-wide page shrunk that far can't be read).
|
|
10
|
+
*
|
|
11
|
+
* A BAR ABOVE THE PICTURE: one sentence saying where things stand (a polite status, announced when the state
|
|
12
|
+
* changes, never per frame), the site on its own line, and one button: Take over or Give back, never both.
|
|
13
|
+
*
|
|
14
|
+
* TAKE OVER. While the person holds control the picture takes the pointer and the keys and sends them to the page,
|
|
15
|
+
* and the agent's own steps wait (they answer `owner_has_control`). Tab and Esc go to the page; ESC, THEN TAB, leaves
|
|
16
|
+
* the picture. On a phone a tap is a click, a one-finger drag scrolls the page, a pinch is the phone's own zoom, and
|
|
17
|
+
* Keyboard opens the on-screen keyboard.
|
|
18
|
+
*
|
|
19
|
+
* NEVER SHOWN, NEVER KEPT: tokens and the channel live in memory only (never the DOM, a URL, `console` or a callback);
|
|
20
|
+
* only the current picture exists, and none after the stream ends; there is no download or screenshot control; no
|
|
21
|
+
* sentence carries a page's words; the site line is a checked hostname. Redacting a vault-filled field is the
|
|
22
|
+
* kernel's: the view cannot tell a value in a picture, and does not try.
|
|
23
|
+
*/
|
|
24
|
+
import { type ReactNode, type Ref } from "react";
|
|
25
|
+
import { type FetchViewer, type ViewerNote, type ViewerSnapshot, type ViewerTimingStep } from "./computer-viewer.ts";
|
|
26
|
+
import { type ComputerSession } from "./computer-wire.ts";
|
|
27
|
+
export interface ComputerViewLabels {
|
|
28
|
+
/** The view's group label. */
|
|
29
|
+
region: string;
|
|
30
|
+
/** The chat's row, closed: the agent is using a browser. */
|
|
31
|
+
rowUsing: string;
|
|
32
|
+
/** The chat's row, closed: a person holds the browser. */
|
|
33
|
+
rowOwnerControl: string;
|
|
34
|
+
watch: string;
|
|
35
|
+
/** The close button while the view connects, reconnects or shows the page. */
|
|
36
|
+
stopWatching: string;
|
|
37
|
+
/** The close button where nothing is being watched: the browser can't be reached, or watching was refused. */
|
|
38
|
+
dismiss?: string;
|
|
39
|
+
connecting: string;
|
|
40
|
+
working: string;
|
|
41
|
+
parked: string;
|
|
42
|
+
challenge: string;
|
|
43
|
+
signIn: string;
|
|
44
|
+
youHaveControl: string;
|
|
45
|
+
controlSoon: string;
|
|
46
|
+
someoneElse: string;
|
|
47
|
+
gaveBack: string;
|
|
48
|
+
/**
|
|
49
|
+
* After a check's or a sign-in's sentence, when the run has ended and the browser waits for the person (`parked`):
|
|
50
|
+
* what comes next. Nothing carries on by itself then.
|
|
51
|
+
*/
|
|
52
|
+
thenGoOn?: string;
|
|
53
|
+
/**
|
|
54
|
+
* The chat's row, closed, for a browser a person held when the run ended. The platform knows only that, not whether
|
|
55
|
+
* they still hold it, so this never says who holds it now.
|
|
56
|
+
*/
|
|
57
|
+
waitingForYou?: string;
|
|
58
|
+
/** After Give back in a browser that waits for the person, and the open view of one held at the close that nobody holds now. */
|
|
59
|
+
gaveBackWaiting?: string;
|
|
60
|
+
expired: string;
|
|
61
|
+
/** Control ran out in a browser that waits for the person: nobody has it now, and the agent goes on only when told. */
|
|
62
|
+
expiredWaiting?: string;
|
|
63
|
+
dropped: string;
|
|
64
|
+
/** The view's connection dropped in a browser that waits for the person: as `expiredWaiting`. */
|
|
65
|
+
droppedWaiting?: string;
|
|
66
|
+
/**
|
|
67
|
+
* Control ended (given back, run out, dropped) while keys the person typed may not have reached the page: what they
|
|
68
|
+
* typed last (often a password) needs a look. Take over is the filled button.
|
|
69
|
+
*/
|
|
70
|
+
inputLost?: string;
|
|
71
|
+
/** As `inputLost`, in a browser that waits for the person: no Go on until they have looked. */
|
|
72
|
+
inputLostWaiting?: string;
|
|
73
|
+
/**
|
|
74
|
+
* Go on: the filled button in a browser that waits for the person once nobody holds it (gave back, control ran out,
|
|
75
|
+
* the view dropped). It sends `goOnMessage` through the chat's own send, as if the person typed it. Only where the
|
|
76
|
+
* chat can send; `<ComputerView>` alone draws it only with `onGoOn`.
|
|
77
|
+
*/
|
|
78
|
+
goOn?: string;
|
|
79
|
+
/** What Go on sends, in the person's name: their own words, so the button says what it sends. */
|
|
80
|
+
goOnMessage?: string;
|
|
81
|
+
/**
|
|
82
|
+
* The chat's pointer, in the newest reply that used a browser whose row is in an earlier reply: the button that brings
|
|
83
|
+
* that row into sight and opens it.
|
|
84
|
+
*/
|
|
85
|
+
showBrowser?: string;
|
|
86
|
+
takeRefused: string;
|
|
87
|
+
reconnecting: string;
|
|
88
|
+
unreachable: string;
|
|
89
|
+
refused: string;
|
|
90
|
+
endedRunEnded: string;
|
|
91
|
+
endedClosed: string;
|
|
92
|
+
endedDeadline: string;
|
|
93
|
+
endedParkExpired: string;
|
|
94
|
+
endedStopped: string;
|
|
95
|
+
endedFailed: string;
|
|
96
|
+
endedUnknown: string;
|
|
97
|
+
takeOver: string;
|
|
98
|
+
giveBack: string;
|
|
99
|
+
/** Give back, pressed: what was typed is still being sent before control goes back. */
|
|
100
|
+
givingBack?: string;
|
|
101
|
+
retry: string;
|
|
102
|
+
keyboard: string;
|
|
103
|
+
picture: string;
|
|
104
|
+
pictureHeld: string;
|
|
105
|
+
hint: string;
|
|
106
|
+
}
|
|
107
|
+
export declare const DEFAULT_COMPUTER_VIEW_LABELS: ComputerViewLabels;
|
|
108
|
+
export type ComputerButton = {
|
|
109
|
+
kind: "take";
|
|
110
|
+
primary: boolean;
|
|
111
|
+
} | {
|
|
112
|
+
kind: "give_back";
|
|
113
|
+
} | {
|
|
114
|
+
kind: "retry";
|
|
115
|
+
} | null;
|
|
116
|
+
/**
|
|
117
|
+
* The one sentence and the one button for where things stand. `snap` null: the chat's closed row, from
|
|
118
|
+
* the part alone. The end wins over everything; then the stream's own state; then what the part says the agent is
|
|
119
|
+
* doing. No sentence carries a page's words.
|
|
120
|
+
*
|
|
121
|
+
* A browser parked for the person (`parked` with `waiting_for`): the run has ended, so a check's or a sign-in's sentence
|
|
122
|
+
* says what comes next, and Give back (or control running out, or the view dropping) says to tell the agent to go on. For one a person held at the close, the closed
|
|
123
|
+
* row never says who holds it now (the platform cannot know); the open view reads it from the kernel. A park for a held
|
|
124
|
+
* act (no `waiting_for`) reads as before.
|
|
125
|
+
*/
|
|
126
|
+
export declare function computerWords(snap: ViewerSnapshot | null, session: ComputerSession | null, l: ComputerViewLabels, canTakeOver: boolean, canGoOn?: boolean): {
|
|
127
|
+
sentence: string;
|
|
128
|
+
button: ComputerButton;
|
|
129
|
+
goOn?: true;
|
|
130
|
+
};
|
|
131
|
+
/** A view's note, and the part it arose under (`currentNote`). */
|
|
132
|
+
export interface SeenNote {
|
|
133
|
+
note: ViewerNote;
|
|
134
|
+
key: string;
|
|
135
|
+
/** The part changed under it: it stays ended. */
|
|
136
|
+
over?: true;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* A NOTE IS ABOUT THE MOMENT IT AROSE. The view's own note (gave back, control ran out, the view dropped,
|
|
140
|
+
* taking over refused) belongs to the part it arose under: the session's status, its wait, and the reply that holds the
|
|
141
|
+
* session's newest part (`newestIn`). Once that changes (a new status or wait, or a newer run's part), the note ends for
|
|
142
|
+
* good, and the view reads the session's new state: a later run that parks the browser for a sign-in says so, with
|
|
143
|
+
* Take over, not "You gave control back. Tell your agent to go on." with Go on. `seen`: what the last call returned.
|
|
144
|
+
* No note: the very same snapshot. Pure.
|
|
145
|
+
*/
|
|
146
|
+
export declare function currentNote(snap: ViewerSnapshot, seen: SeenNote | null, session: ComputerSession | null, newestIn?: string | null): {
|
|
147
|
+
snap: ViewerSnapshot;
|
|
148
|
+
seen: SeenNote | null;
|
|
149
|
+
};
|
|
150
|
+
/** Where the chat draws each browser session (`computerPlaces`). */
|
|
151
|
+
export interface ComputerPlaces {
|
|
152
|
+
/** At a session's FIRST part: the session, with its newest words (its row). Elsewhere: null. */
|
|
153
|
+
row(message: string, index: number, data: unknown): ComputerSession | null;
|
|
154
|
+
/**
|
|
155
|
+
* At a session's NEWEST part, when that is in a later message than its first and the browser has not ended: the
|
|
156
|
+
* session, with its newest words (the pointer to its row). Elsewhere: null.
|
|
157
|
+
*/
|
|
158
|
+
pointer(message: string, index: number, data: unknown): ComputerSession | null;
|
|
159
|
+
/** The message that holds the session's newest part, or null. */
|
|
160
|
+
newestIn(session: string): string | null;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* THE AGENT'S BROWSER IN THE CHAT: a session's `data-computer` parts, in the order drawn. Its ONE row is at its first
|
|
164
|
+
* part, with its newest words, so an open view never moves (and never reconnects). The newest reply that used it, when
|
|
165
|
+
* that is a later one, gets the pointer at the newest part, while the browser still exists. Pure.
|
|
166
|
+
*/
|
|
167
|
+
export declare function computerPlaces(messages: ReadonlyArray<{
|
|
168
|
+
id: string;
|
|
169
|
+
parts: ReadonlyArray<{
|
|
170
|
+
type: string;
|
|
171
|
+
}>;
|
|
172
|
+
}>): ComputerPlaces;
|
|
173
|
+
/**
|
|
174
|
+
* Where things stand, for Go on: pressed once, it is not drawn again until this changes (the part, the phase, who holds
|
|
175
|
+
* it, or the note). Pure.
|
|
176
|
+
*/
|
|
177
|
+
export declare function goOnKey(snap: ViewerSnapshot, session: ComputerSession | null): string;
|
|
178
|
+
/**
|
|
179
|
+
* The picture's aspect ratio: the newest frame's own width and height, so the page is never letterboxed. No frame (or
|
|
180
|
+
* one with no size): the last one's, so the box does not jump while the view reconnects; none yet: null, and the
|
|
181
|
+
* stylesheet's placeholder holds. The same object while the size is unchanged. Pure.
|
|
182
|
+
*/
|
|
183
|
+
export declare function pictureRatio(last: {
|
|
184
|
+
w: number;
|
|
185
|
+
h: number;
|
|
186
|
+
} | null, frame: {
|
|
187
|
+
w: number;
|
|
188
|
+
h: number;
|
|
189
|
+
} | null): {
|
|
190
|
+
w: number;
|
|
191
|
+
h: number;
|
|
192
|
+
} | null;
|
|
193
|
+
export interface ComputerViewViewProps {
|
|
194
|
+
snap: ViewerSnapshot;
|
|
195
|
+
session: ComputerSession | null;
|
|
196
|
+
labels: ComputerViewLabels;
|
|
197
|
+
canTakeOver: boolean;
|
|
198
|
+
/** The current picture's object URL, once decoded. */
|
|
199
|
+
frameUrl: string | null;
|
|
200
|
+
onTake: () => void;
|
|
201
|
+
onGiveBack: () => void;
|
|
202
|
+
onRetry: () => void;
|
|
203
|
+
/** Go on (`labels.goOn`): absent, no such button. Drawn only where `computerWords` says it is the next step. */
|
|
204
|
+
onGoOn?: (() => void) | undefined;
|
|
205
|
+
/** The `goOnKey` Go on was pressed in: not drawn again while it is the current one. */
|
|
206
|
+
goOnPressed?: string | null | undefined;
|
|
207
|
+
/** The picture's aspect ratio (`pictureRatio`), set on the box itself. Null: the stylesheet's placeholder. */
|
|
208
|
+
ratio?: {
|
|
209
|
+
w: number;
|
|
210
|
+
h: number;
|
|
211
|
+
} | null | undefined;
|
|
212
|
+
/** Stop watching (the chat's row closes the view). Absent: no such button. */
|
|
213
|
+
onClose?: (() => void) | undefined;
|
|
214
|
+
/** The off-screen field that brings up a phone's keyboard, while the person holds control. */
|
|
215
|
+
keys?: ReactNode;
|
|
216
|
+
onKeyboard?: (() => void) | undefined;
|
|
217
|
+
rootRef?: Ref<HTMLDivElement> | undefined;
|
|
218
|
+
buttonRef?: Ref<HTMLButtonElement> | undefined;
|
|
219
|
+
pictureRef?: Ref<HTMLDivElement> | undefined;
|
|
220
|
+
className?: string | undefined;
|
|
221
|
+
}
|
|
222
|
+
/** The view as drawn: a pure function of the snapshot and the part, for the component and for tests. */
|
|
223
|
+
export declare function ComputerViewView(props: ComputerViewViewProps): import("react").JSX.Element;
|
|
224
|
+
export interface ComputerViewProps {
|
|
225
|
+
/** The host's function that asks its server for a viewer grant (`readViewerGrant` reads the answer). */
|
|
226
|
+
fetchViewer: FetchViewer;
|
|
227
|
+
/** The chat's `data-computer` part (`computerSessionOf(part.data)`): what the agent is doing, and why it ended. */
|
|
228
|
+
session?: ComputerSession | null | undefined;
|
|
229
|
+
/** False hides Take over for this person. Your server must refuse a control grant to them as well. */
|
|
230
|
+
canTakeOver?: boolean | undefined;
|
|
231
|
+
labels?: Partial<ComputerViewLabels> | undefined;
|
|
232
|
+
/** Told when this person takes control (true) and when they no longer hold it (false). */
|
|
233
|
+
onControlChange?: ((held: boolean) => void) | undefined;
|
|
234
|
+
/** Stop watching: shown when given (the chat's row passes it). */
|
|
235
|
+
onClose?: (() => void) | undefined;
|
|
236
|
+
/**
|
|
237
|
+
* Go on, in a browser that waits for the person once nobody holds it: send your go-on message (`labels.goOnMessage`)
|
|
238
|
+
* as the person's own. Absent: no Go on. `<AgentChat>` passes the chat's send, only while it can send.
|
|
239
|
+
*/
|
|
240
|
+
onGoOn?: (() => void) | undefined;
|
|
241
|
+
/** Put focus on the view when it opens (the chat's Watch does). */
|
|
242
|
+
autoFocus?: boolean | undefined;
|
|
243
|
+
/**
|
|
244
|
+
* The message that holds the session's newest part (the chat's row passes it). When it changes, a newer run has used
|
|
245
|
+
* the browser, and the view's own note (gave back, ran out, dropped) ends, as it does when the part's status or wait
|
|
246
|
+
* changes.
|
|
247
|
+
*/
|
|
248
|
+
partAt?: string | null | undefined;
|
|
249
|
+
/** Bring the view into sight and to its first control: each new value does it once (the chat's pointer). */
|
|
250
|
+
reveal?: number | undefined;
|
|
251
|
+
/** For the kernel's routes; the page's own `fetch` by default. */
|
|
252
|
+
fetch?: typeof fetch | undefined;
|
|
253
|
+
/**
|
|
254
|
+
* For diagnosing a stall: each step of a connection as it happens (asked, granted, the stream opened, its first
|
|
255
|
+
* bytes, state and frame, the first picture decoded, or the watchdog), with the time. Step names only.
|
|
256
|
+
*/
|
|
257
|
+
onTiming?: ((step: ViewerTimingStep, at: number) => void) | undefined;
|
|
258
|
+
className?: string | undefined;
|
|
259
|
+
}
|
|
260
|
+
export declare function ComputerView(props: ComputerViewProps): import("react").JSX.Element;
|
|
261
|
+
/** What `<AgentChat computer>` takes: the host's `fetchViewer`, and the view's options. */
|
|
262
|
+
export interface AgentChatComputer {
|
|
263
|
+
fetchViewer: FetchViewer;
|
|
264
|
+
canTakeOver?: boolean | undefined;
|
|
265
|
+
labels?: Partial<ComputerViewLabels> | undefined;
|
|
266
|
+
onControlChange?: ((held: boolean) => void) | undefined;
|
|
267
|
+
/** For the kernel's routes; the page's own `fetch` by default (never the chat's kit `fetch`). */
|
|
268
|
+
fetch?: typeof fetch | undefined;
|
|
269
|
+
/** For diagnosing a stall: `<ComputerView onTiming>`. */
|
|
270
|
+
onTiming?: ((step: ViewerTimingStep, at: number) => void) | undefined;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* WHICH BROWSERS THE PERSON HOLDS HERE: the sessions (`cps_…`) whose control a view open in this chat holds, and how a
|
|
274
|
+
* view says so. `<AgentChat>` provides it; a browser act's card for one of them holds Approve back. Null outside a chat.
|
|
275
|
+
*/
|
|
276
|
+
export declare const BrowserControlContext: import("react").Context<{
|
|
277
|
+
held: ReadonlySet<string>;
|
|
278
|
+
report: (session: string, held: boolean) => void;
|
|
279
|
+
goOn: (() => void) | null;
|
|
280
|
+
} | null>;
|
|
281
|
+
/**
|
|
282
|
+
* THE CHAT'S BROWSER ROWS, for the pointer: each row says how to bring it into sight and open it (`add`, which returns
|
|
283
|
+
* how to take that back), and where its session's newest part is. `<AgentChat>` provides it; null outside a chat.
|
|
284
|
+
*/
|
|
285
|
+
export declare const ComputerRowsContext: import("react").Context<{
|
|
286
|
+
add: (session: string, show: () => void) => () => void;
|
|
287
|
+
show: (session: string) => void;
|
|
288
|
+
newestIn: (session: string) => string | null;
|
|
289
|
+
} | null>;
|
|
290
|
+
/**
|
|
291
|
+
* THE POINTER: in the newest reply that used a browser whose row is in an earlier reply,
|
|
292
|
+
* one compact line, the session's sentence and one button that brings that row into sight and opens it. Never a
|
|
293
|
+
* second view, never a moved one. The sentence is not a live region: the row's own says each change, once. Drawn only
|
|
294
|
+
* while the browser exists (`computerPlaces`).
|
|
295
|
+
*/
|
|
296
|
+
export declare function ComputerPointer({ session, computer }: {
|
|
297
|
+
session: ComputerSession;
|
|
298
|
+
computer?: AgentChatComputer | undefined;
|
|
299
|
+
}): import("react").JSX.Element;
|
|
300
|
+
/** The sessions held after a view says it holds `session` (or no longer does). No change: the very same set. Pure. */
|
|
301
|
+
export declare function controlAfter(held: ReadonlySet<string>, session: string, isHeld: boolean): ReadonlySet<string>;
|
|
302
|
+
/**
|
|
303
|
+
* The chat's one-line row for a `data-computer` part: the sentence, the site, and Watch, which opens
|
|
304
|
+
* `<ComputerView>` in place. Without the host's `fetchViewer`, the sentence alone; once ended, no Watch.
|
|
305
|
+
*/
|
|
306
|
+
export declare function ComputerRow({ session, computer }: {
|
|
307
|
+
session: ComputerSession;
|
|
308
|
+
computer?: AgentChatComputer | undefined;
|
|
309
|
+
}): import("react").JSX.Element;
|