@fungi.computer/oyster 0.10.0 → 0.11.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 +33 -2
- package/dist/agents.d.ts +66 -22
- package/dist/agents.js +128 -38
- package/dist/authorization.d.ts +25 -3
- package/dist/authorization.js +47 -14
- package/dist/browser/capability-source.d.ts +23 -5
- package/dist/browser/capability-source.js +19 -22
- package/dist/browser/index.d.ts +2 -1
- package/dist/browser/index.js +1 -0
- package/dist/browser/live-view.d.ts +38 -0
- package/dist/browser/live-view.js +179 -0
- package/dist/channels/binding.d.ts +2 -0
- package/dist/channels/run-decision.d.ts +33 -0
- package/dist/channels/run-decision.js +25 -0
- package/dist/channels/visitor-channel.d.ts +84 -14
- package/dist/channels/visitor-channel.js +55 -32
- package/dist/channels/visitor-edge.d.ts +18 -2
- package/dist/channels/visitor-edge.js +67 -5
- package/dist/channels/visitors.d.ts +4 -0
- package/dist/channels/visitors.js +22 -1
- package/dist/channels/web-binding.d.ts +117 -0
- package/dist/channels/web-binding.js +227 -0
- package/dist/embed-metafiles.d.ts +8 -0
- package/dist/embed-metafiles.js +2 -0
- package/dist/embed-scripts.d.ts +8 -0
- package/dist/embed-scripts.js +3 -0
- package/dist/host.d.ts +3 -1
- package/dist/host.js +6 -1
- package/dist/page/embed-challenge.d.ts +19 -0
- package/dist/page/embed-challenge.js +45 -0
- package/dist/page/embed-error.d.ts +2 -0
- package/dist/page/embed-error.js +16 -0
- package/dist/page/embed-loader-protocol.d.ts +12 -0
- package/dist/page/embed-loader-protocol.js +29 -0
- package/dist/standalone/agent-connections.d.ts +22 -19
- package/dist/standalone/agent-connections.js +150 -106
- package/dist/standalone/agents.d.ts +168 -14
- package/dist/standalone/agents.js +310 -17
- package/dist/standalone/browser.d.ts +14 -2
- package/dist/standalone/browser.js +52 -4
- package/dist/standalone/channel-session-door.d.ts +4 -0
- package/dist/standalone/channel-session-door.js +72 -0
- package/dist/standalone/owner-routes.d.ts +4 -3
- package/dist/standalone/owner-routes.js +7 -1
- package/dist/standalone/visitor-edge.d.ts +36 -0
- package/dist/standalone/visitor-edge.js +67 -0
- package/dist/standalone/visitor-proof.d.ts +23 -0
- package/dist/standalone/visitor-proof.js +67 -0
- package/dist/standalone/website-channels.d.ts +134 -0
- package/dist/standalone/website-channels.js +262 -0
- package/dist/standalone/worker-routes.d.ts +4 -1
- package/dist/standalone/worker-routes.js +3 -0
- package/dist/standalone/worker.d.ts +2 -1
- package/dist/standalone/worker.js +4 -0
- package/dist/testing/capabilities.d.ts +3 -0
- package/dist/testing/capabilities.js +1 -0
- package/dist/testing/installation.d.ts +4 -2
- package/dist/testing/installation.js +7 -2
- package/dist/workers-git.js +2 -2
- package/docs/api/agents.md +103 -36
- package/docs/api/browser.md +115 -8
- package/docs/api/workers-git.md +6 -6
- package/package.json +31 -6
|
@@ -32,7 +32,7 @@ export declare const CLOUD_BROWSER_DESCRIPTIONS: Readonly<{
|
|
|
32
32
|
readonly scroll: "Scroll an open session's page by a pixel delta.";
|
|
33
33
|
readonly screenshot: "Capture a PNG screenshot of an open session's page and save it to a Computer path; returns the saved byte count, never the bytes.";
|
|
34
34
|
readonly pdf: "Render an open session's page to PDF and save it to a Computer path; returns the saved byte count, never the bytes.";
|
|
35
|
-
readonly handoff: "
|
|
35
|
+
readonly handoff: "Pause an open session so the person can take over for a login or captcha. In a channel conversation the owner is notified and takes over. Otherwise the result is {paused: true, view}: ask the person with the question tool, include the view link, and wait for their answer. They press Done in the view to resume; drive again only after that.";
|
|
36
36
|
readonly close: "End a driven session and release its lease.";
|
|
37
37
|
}>;
|
|
38
38
|
/**
|
|
@@ -56,12 +56,30 @@ export type AgentBrowserDoor = Readonly<{
|
|
|
56
56
|
/** Pause the owner's lease for a Team member. */
|
|
57
57
|
handoff: (owner: LeaseOwner, leaseId: string) => Promise<void>;
|
|
58
58
|
}>;
|
|
59
|
+
/**
|
|
60
|
+
* How a host hands a paused lease to a person. A channel Session (a website
|
|
61
|
+
* visitor) takes the conversation handoff; every other Session gets the live
|
|
62
|
+
* view and asks the person itself.
|
|
63
|
+
*/
|
|
64
|
+
export type BrowserHandoffPorts = Readonly<{
|
|
65
|
+
/**
|
|
66
|
+
* Request the channel conversation handoff for this Session. True when the
|
|
67
|
+
* Session is a channel conversation and was handed off; false for any other
|
|
68
|
+
* Session. `null` when the host has no conversations owner.
|
|
69
|
+
*/
|
|
70
|
+
channel: ((sessionId: string, reason: string) => boolean) | null;
|
|
71
|
+
/** The host-relative live-view path for one lease of this Session's owner. */
|
|
72
|
+
viewPath: (owner: Readonly<{
|
|
73
|
+
teamId: string;
|
|
74
|
+
agentId: string;
|
|
75
|
+
}>, leaseId: string) => string;
|
|
76
|
+
}>;
|
|
59
77
|
/**
|
|
60
78
|
* Compose the `cloudBrowser` source for one Session, on either host. `browser`
|
|
61
79
|
* is the module's lease door (in-process, or the Hub's egress RPC); `saveFile`
|
|
62
|
-
* is the host's Computer bytes writer and `
|
|
63
|
-
*
|
|
64
|
-
* offered. A lease needs a Session identity, so a session-free host (e.g. the
|
|
80
|
+
* is the host's Computer bytes writer and `handoff` its "needs you" ports. A
|
|
81
|
+
* host without a Computer passes `null` for `saveFile` and that operation is
|
|
82
|
+
* not offered. A lease needs a Session identity, so a session-free host (e.g. the
|
|
65
83
|
* MCP execute path) gets no module at all.
|
|
66
84
|
*/
|
|
67
85
|
export declare function browserCapabilitySource(deps: Readonly<{
|
|
@@ -72,5 +90,5 @@ export declare function browserCapabilitySource(deps: Readonly<{
|
|
|
72
90
|
browser: AgentBrowserDoor;
|
|
73
91
|
quickReads: boolean;
|
|
74
92
|
saveFile: SaveBrowserFile | null;
|
|
75
|
-
|
|
93
|
+
handoff: BrowserHandoffPorts;
|
|
76
94
|
}>): CapabilitySource;
|
|
@@ -22,7 +22,7 @@ export const CLOUD_BROWSER_DESCRIPTIONS = Object.freeze({
|
|
|
22
22
|
module: "A work browser for reading and driving public pages. markdown/links/scrape/extract " +
|
|
23
23
|
"need no session. open/navigate/snapshot/click/type/press/scroll drive one session by " +
|
|
24
24
|
"leaseId; screenshot/pdf save to a Computer path (bytes never enter this transcript). " +
|
|
25
|
-
"handoff
|
|
25
|
+
"handoff pauses the session for the person to take over for a login or captcha; close ends the lease. " +
|
|
26
26
|
"To show the member something yourself, use the Session browser tools, not this.",
|
|
27
27
|
markdown: "Render a JavaScript page and return it as markdown, truncated to maxChars (default 20000).",
|
|
28
28
|
links: "Render a page and return up to 500 links found on it.",
|
|
@@ -37,7 +37,7 @@ export const CLOUD_BROWSER_DESCRIPTIONS = Object.freeze({
|
|
|
37
37
|
scroll: "Scroll an open session's page by a pixel delta.",
|
|
38
38
|
screenshot: "Capture a PNG screenshot of an open session's page and save it to a Computer path; returns the saved byte count, never the bytes.",
|
|
39
39
|
pdf: "Render an open session's page to PDF and save it to a Computer path; returns the saved byte count, never the bytes.",
|
|
40
|
-
handoff: "
|
|
40
|
+
handoff: "Pause an open session so the person can take over for a login or captcha. In a channel conversation the owner is notified and takes over. Otherwise the result is {paused: true, view}: ask the person with the question tool, include the view link, and wait for their answer. They press Done in the view to resume; drive again only after that.",
|
|
41
41
|
close: "End a driven session and release its lease.",
|
|
42
42
|
});
|
|
43
43
|
for (const [name, text] of Object.entries(CLOUD_BROWSER_DESCRIPTIONS))
|
|
@@ -65,7 +65,7 @@ function cloudBrowserFailureMessage(error) {
|
|
|
65
65
|
case "CloudBrowserLeaseNotFound":
|
|
66
66
|
return "that leaseId is not open for this session; call open first";
|
|
67
67
|
case "CloudBrowserLeasePaused":
|
|
68
|
-
return "a
|
|
68
|
+
return "a person has this lease; ask them to press Done in the browser view, then try again";
|
|
69
69
|
case "CloudBrowserCapacityExceeded":
|
|
70
70
|
return "this Team has too many cloud browsers open at once; close one first";
|
|
71
71
|
case "CloudBrowserCreditDenied":
|
|
@@ -111,9 +111,11 @@ const destinationResultSchema = z.strictObject({
|
|
|
111
111
|
path: z.string(),
|
|
112
112
|
bytes: z.number().int().nonnegative(),
|
|
113
113
|
});
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
})
|
|
114
|
+
/** A channel Session's owner was notified, or the person is given a live view. */
|
|
115
|
+
const handoffResultSchema = z.union([
|
|
116
|
+
z.strictObject({ status: z.literal("handed_off") }),
|
|
117
|
+
z.strictObject({ paused: z.literal(true), view: z.string().min(1) }),
|
|
118
|
+
]);
|
|
117
119
|
/** Build the `cloudBrowser` module once a Session identity is known. */
|
|
118
120
|
function buildCloudBrowserModule(options) {
|
|
119
121
|
/** Run one call, mapping any thrown failure and parsing the result through `schema`. */
|
|
@@ -176,10 +178,7 @@ function buildCloudBrowserModule(options) {
|
|
|
176
178
|
reason: z.string().min(1).max(500),
|
|
177
179
|
}),
|
|
178
180
|
output: handoffResultSchema,
|
|
179
|
-
execute: (input) => run("handoff", handoffResultSchema,
|
|
180
|
-
await handoff(input.leaseId, input.reason);
|
|
181
|
-
return { status: "handed_off" };
|
|
182
|
-
}),
|
|
181
|
+
execute: (input) => run("handoff", handoffResultSchema, () => handoff(input.leaseId, input.reason)),
|
|
183
182
|
}),
|
|
184
183
|
};
|
|
185
184
|
}
|
|
@@ -283,8 +282,7 @@ function buildCloudBrowserModule(options) {
|
|
|
283
282
|
Object.assign(operations, quickReads);
|
|
284
283
|
if (options.saveFile !== null)
|
|
285
284
|
Object.assign(operations, saveOperations(options.saveFile));
|
|
286
|
-
|
|
287
|
-
Object.assign(operations, handoffOperation(options.handoff));
|
|
285
|
+
Object.assign(operations, handoffOperation(options.handoff));
|
|
288
286
|
return Mycelium.module({
|
|
289
287
|
id: "cloud-browser",
|
|
290
288
|
name: "cloudBrowser",
|
|
@@ -295,9 +293,9 @@ function buildCloudBrowserModule(options) {
|
|
|
295
293
|
/**
|
|
296
294
|
* Compose the `cloudBrowser` source for one Session, on either host. `browser`
|
|
297
295
|
* is the module's lease door (in-process, or the Hub's egress RPC); `saveFile`
|
|
298
|
-
* is the host's Computer bytes writer and `
|
|
299
|
-
*
|
|
300
|
-
* offered. A lease needs a Session identity, so a session-free host (e.g. the
|
|
296
|
+
* is the host's Computer bytes writer and `handoff` its "needs you" ports. A
|
|
297
|
+
* host without a Computer passes `null` for `saveFile` and that operation is
|
|
298
|
+
* not offered. A lease needs a Session identity, so a session-free host (e.g. the
|
|
301
299
|
* MCP execute path) gets no module at all.
|
|
302
300
|
*/
|
|
303
301
|
export function browserCapabilitySource(deps) {
|
|
@@ -317,17 +315,16 @@ export function browserCapabilitySource(deps) {
|
|
|
317
315
|
agentId: identity.agentId,
|
|
318
316
|
sessionId,
|
|
319
317
|
};
|
|
320
|
-
const requestHandoff = deps.requestHandoff;
|
|
321
318
|
const registration = buildCloudBrowserModule({
|
|
322
319
|
call: (op, opSignal) => deps.browser.call(owner, op, opSignal),
|
|
323
320
|
quickReads: deps.quickReads,
|
|
324
321
|
saveFile: deps.saveFile,
|
|
325
|
-
handoff:
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
322
|
+
handoff: async (leaseId, reason) => {
|
|
323
|
+
await deps.browser.handoff(owner, leaseId);
|
|
324
|
+
if (deps.handoff.channel?.(sessionId, `cloud browser: ${reason}`))
|
|
325
|
+
return { status: "handed_off" };
|
|
326
|
+
return { paused: true, view: deps.handoff.viewPath(owner, leaseId) };
|
|
327
|
+
},
|
|
331
328
|
});
|
|
332
329
|
return Promise.resolve({
|
|
333
330
|
snapshot: { version: "cloud-browser-v1", modules: [registration] },
|
package/dist/browser/index.d.ts
CHANGED
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
* the agent's `cloudBrowser` tool. Raw CDP stays internal to this directory.
|
|
9
9
|
*/
|
|
10
10
|
export { createBrowser, type Browser, type BrowserEvent, type BrowserHost, type BrowserLimits, type BrowserMemberAction, type BrowserMeter, } from "./browser.js";
|
|
11
|
-
export { browserCapabilitySource, CLOUD_BROWSER_DESCRIPTIONS, type AgentBrowserDoor, type SaveBrowserFile, } from "./capability-source.js";
|
|
11
|
+
export { browserCapabilitySource, CLOUD_BROWSER_DESCRIPTIONS, type AgentBrowserDoor, type BrowserHandoffPorts, type SaveBrowserFile, } from "./capability-source.js";
|
|
12
|
+
export { liveView, liveViewPaths, type LiveView, type LiveViewDoor, type LiveViewPaths, } from "./live-view.js";
|
|
12
13
|
export { CloudBrowserCapacityExceeded, CloudBrowserCreditDenied, CloudBrowserLeaseNotFound, CloudBrowserLeasePaused, CloudBrowserTimeout, CloudBrowserUnavailable, CloudBrowserUpstreamError, CloudBrowserUrlDenied, type CloudBrowserFailure, } from "./errors.js";
|
|
13
14
|
export type { LeaseOwner } from "./lease-registry.js";
|
|
14
15
|
export { cloudBrowserBounds, extractInputSchema, extractResultSchema, linksResultSchema, markdownInputSchema, markdownResultSchema, navigateResultSchema, openResultSchema, scrapeInputSchema, scrapeResultSchema, snapshotResultSchema, type BinaryResult, type CloudBrowserAck, type CloudBrowserClosed, type CloudBrowserOperation, type CloudBrowserOperationResult, type ExtractInput, type ExtractResult, type LinksResult, type MarkdownInput, type MarkdownResult, type NavigateResult, type OpenResult, type ScrapeInput, type ScrapeResult, type SnapshotResult, } from "./operations.js";
|
package/dist/browser/index.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
export { createBrowser, } from "./browser.js";
|
|
11
11
|
export { browserCapabilitySource, CLOUD_BROWSER_DESCRIPTIONS, } from "./capability-source.js";
|
|
12
|
+
export { liveView, liveViewPaths, } from "./live-view.js";
|
|
12
13
|
export { CloudBrowserCapacityExceeded, CloudBrowserCreditDenied, CloudBrowserLeaseNotFound, CloudBrowserLeasePaused, CloudBrowserTimeout, CloudBrowserUnavailable, CloudBrowserUpstreamError, CloudBrowserUrlDenied, } from "./errors.js";
|
|
13
14
|
export { cloudBrowserBounds, extractInputSchema, extractResultSchema, linksResultSchema, markdownInputSchema, markdownResultSchema, navigateResultSchema, openResultSchema, scrapeInputSchema, scrapeResultSchema, snapshotResultSchema, } from "./operations.js";
|
|
14
15
|
export { browserRunQuickReads, } from "./quick-reads.js";
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { BrowserMemberAction } from "./browser.js";
|
|
2
|
+
import type { BinaryResult } from "./operations.js";
|
|
3
|
+
/**
|
|
4
|
+
* The person's live view of a paused cloud-browser lease, shared by both
|
|
5
|
+
* hosts. It is request/response handlers, not a router: each host registers
|
|
6
|
+
* three routes under its own admission (the Hub's Team chain, a standalone
|
|
7
|
+
* Oyster's owner requirement in `authorization.ts`) and passes the door
|
|
8
|
+
* that admission produced. The page never carries a bearer or a CDP URL;
|
|
9
|
+
* every fetch is same-origin and rides the viewer's own session. It forwards
|
|
10
|
+
* only the closed {@link BrowserMemberAction} set, and never reaches the model.
|
|
11
|
+
*/
|
|
12
|
+
/** One admitted viewer's door into one lease: `Browser.member` already bound to it. */
|
|
13
|
+
export type LiveViewDoor = (action: BrowserMemberAction, signal: AbortSignal) => Promise<BinaryResult | null>;
|
|
14
|
+
/** The three paths a host serves for one lease, relative to its own origin. */
|
|
15
|
+
export type LiveViewPaths = Readonly<{
|
|
16
|
+
/** The page a member opens to watch and steer the lease. */
|
|
17
|
+
view: string;
|
|
18
|
+
/** The current screenshot of the lease's page. */
|
|
19
|
+
frame: string;
|
|
20
|
+
/** Where the page posts the member's clicks and typing. */
|
|
21
|
+
input: string;
|
|
22
|
+
}>;
|
|
23
|
+
/** The host-relative paths for a lease whose live view is served under `base`. */
|
|
24
|
+
export declare function liveViewPaths(base: string): LiveViewPaths;
|
|
25
|
+
/** The handlers for one lease's view, frame and input routes. */
|
|
26
|
+
export type LiveView = Readonly<{
|
|
27
|
+
/** The HTML page a member opens to watch and steer the lease. */
|
|
28
|
+
page: () => Response;
|
|
29
|
+
/** The current screenshot of the lease's page. */
|
|
30
|
+
frame: (signal: AbortSignal) => Promise<Response>;
|
|
31
|
+
/** Applies the member's click or typing and answers whether it was accepted. */
|
|
32
|
+
input: (request: Request, signal: AbortSignal) => Promise<Response>;
|
|
33
|
+
}>;
|
|
34
|
+
/**
|
|
35
|
+
* Build the handlers for one admitted viewer and lease. `report` receives a
|
|
36
|
+
* request body that did not decode, so the host can log it with its own sink.
|
|
37
|
+
*/
|
|
38
|
+
export declare function liveView(door: LiveViewDoor, paths: LiveViewPaths, report: (event: "input_body_unavailable", cause: unknown) => void): LiveView;
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { CloudBrowserLeaseNotFound, CloudBrowserUnavailable, } from "./errors.js";
|
|
3
|
+
/** The host-relative paths for a lease whose live view is served under `base`. */
|
|
4
|
+
export function liveViewPaths(base) {
|
|
5
|
+
return {
|
|
6
|
+
view: `${base}/view`,
|
|
7
|
+
frame: `${base}/frame`,
|
|
8
|
+
input: `${base}/input`,
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
const actionSchema = z.discriminatedUnion("kind", [
|
|
12
|
+
z.strictObject({ kind: z.literal("screenshot") }),
|
|
13
|
+
z.strictObject({
|
|
14
|
+
kind: z.literal("click"),
|
|
15
|
+
x: z.number().int().min(0).max(20_000),
|
|
16
|
+
y: z.number().int().min(0).max(20_000),
|
|
17
|
+
}),
|
|
18
|
+
z.strictObject({ kind: z.literal("type"), text: z.string().max(10_000) }),
|
|
19
|
+
z.strictObject({
|
|
20
|
+
kind: z.literal("scroll"),
|
|
21
|
+
deltaX: z.number().int().min(-100_000).max(100_000).default(0),
|
|
22
|
+
deltaY: z.number().int().min(-100_000).max(100_000).default(0),
|
|
23
|
+
}),
|
|
24
|
+
z.strictObject({ kind: z.literal("resume") }),
|
|
25
|
+
]);
|
|
26
|
+
function failureStatus(cause) {
|
|
27
|
+
if (cause instanceof CloudBrowserLeaseNotFound)
|
|
28
|
+
return 404;
|
|
29
|
+
if (cause instanceof CloudBrowserUnavailable)
|
|
30
|
+
return 503;
|
|
31
|
+
return 502;
|
|
32
|
+
}
|
|
33
|
+
function json(body, status) {
|
|
34
|
+
return Response.json(body, { status });
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Build the handlers for one admitted viewer and lease. `report` receives a
|
|
38
|
+
* request body that did not decode, so the host can log it with its own sink.
|
|
39
|
+
*/
|
|
40
|
+
export function liveView(door, paths, report) {
|
|
41
|
+
return {
|
|
42
|
+
page: () => new Response(viewPage(paths), {
|
|
43
|
+
headers: {
|
|
44
|
+
"content-type": "text/html; charset=utf-8",
|
|
45
|
+
"cache-control": "no-store",
|
|
46
|
+
},
|
|
47
|
+
}),
|
|
48
|
+
frame: async (signal) => {
|
|
49
|
+
try {
|
|
50
|
+
const frame = await door({ kind: "screenshot" }, signal);
|
|
51
|
+
if (frame === null)
|
|
52
|
+
return json({ error: "no_frame" }, 502);
|
|
53
|
+
return new Response(new Blob([frame.bytes.slice().buffer]), {
|
|
54
|
+
status: 200,
|
|
55
|
+
headers: {
|
|
56
|
+
"content-type": frame.contentType,
|
|
57
|
+
"cache-control": "no-store",
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
return json({ error: "frame_unavailable" }, failureStatus(error));
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
input: async (request, signal) => {
|
|
66
|
+
let body;
|
|
67
|
+
try {
|
|
68
|
+
body = await request.json();
|
|
69
|
+
}
|
|
70
|
+
catch (cause) {
|
|
71
|
+
report("input_body_unavailable", cause);
|
|
72
|
+
return json({ error: "invalid_action" }, 400);
|
|
73
|
+
}
|
|
74
|
+
const parsed = actionSchema.safeParse(body);
|
|
75
|
+
if (!parsed.success)
|
|
76
|
+
return json({ error: "invalid_action" }, 400);
|
|
77
|
+
try {
|
|
78
|
+
await door(parsed.data, signal);
|
|
79
|
+
return json({ ok: true }, 200);
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
return json({ error: "input_failed" }, failureStatus(error));
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function viewPage(paths) {
|
|
88
|
+
return `<!doctype html>
|
|
89
|
+
<html lang="en">
|
|
90
|
+
<head>
|
|
91
|
+
<meta charset="utf-8" />
|
|
92
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
93
|
+
<meta name="color-scheme" content="light dark" />
|
|
94
|
+
<title>Cloud browser</title>
|
|
95
|
+
<style>
|
|
96
|
+
:root { --bg: #f6f5f2; --panel: #ffffff; --ink: #1c1b19; --muted: #6a6761; --line: #d9d6cf; --accent: #2f6f4e; --accent-ink: #ffffff; --live: #2f9e63; }
|
|
97
|
+
@media (prefers-color-scheme: dark) {
|
|
98
|
+
:root { --bg: #161513; --panel: #201f1c; --ink: #ece9e2; --muted: #9a968d; --line: #36342f; --accent: #5cb987; --accent-ink: #10231a; --live: #5cd08f; }
|
|
99
|
+
}
|
|
100
|
+
* { box-sizing: border-box; }
|
|
101
|
+
body { margin: 0; min-height: 100vh; font: 15px/1.4 system-ui, sans-serif; background: var(--bg); color: var(--ink); }
|
|
102
|
+
main { max-width: 1200px; margin: 0 auto; padding: 16px; display: grid; gap: 12px; }
|
|
103
|
+
header { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
|
|
104
|
+
header h1 { font-size: 16px; margin: 0; font-weight: 600; flex: 1; min-width: 12ch; }
|
|
105
|
+
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--live); flex: none; }
|
|
106
|
+
.dot[data-state="idle"] { background: var(--muted); }
|
|
107
|
+
.hint { color: var(--muted); margin: 0; }
|
|
108
|
+
.controls { display: flex; gap: 8px; flex-wrap: wrap; }
|
|
109
|
+
.controls input { flex: 1; min-width: 12ch; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: inherit; font: inherit; }
|
|
110
|
+
button { padding: 8px 14px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: inherit; font: inherit; cursor: pointer; }
|
|
111
|
+
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
|
|
112
|
+
#stage { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); overflow: hidden; }
|
|
113
|
+
#frame { display: block; width: 100%; height: auto; cursor: crosshair; }
|
|
114
|
+
#done { padding: 16px; margin: 0; }
|
|
115
|
+
</style>
|
|
116
|
+
</head>
|
|
117
|
+
<body>
|
|
118
|
+
<main>
|
|
119
|
+
<header>
|
|
120
|
+
<span class="dot" id="dot" data-state="live"></span>
|
|
121
|
+
<h1>The Agent needs you in this browser</h1>
|
|
122
|
+
<div class="controls"><button class="primary" id="done-button" type="button">Done</button></div>
|
|
123
|
+
</header>
|
|
124
|
+
<p class="hint" id="hint">Click the page to interact, type below, then press Done so the Agent can continue.</p>
|
|
125
|
+
<div class="controls">
|
|
126
|
+
<input id="text" type="text" autocomplete="off" placeholder="Text to type into the focused field" />
|
|
127
|
+
<button id="send" type="button">Send text</button>
|
|
128
|
+
</div>
|
|
129
|
+
<div id="stage"><img id="frame" alt="Live cloud browser" /></div>
|
|
130
|
+
</main>
|
|
131
|
+
<script>
|
|
132
|
+
const paths = ${JSON.stringify(paths)};
|
|
133
|
+
const img = document.getElementById("frame");
|
|
134
|
+
const dot = document.getElementById("dot");
|
|
135
|
+
let finished = false;
|
|
136
|
+
async function act(action) {
|
|
137
|
+
const response = await fetch(paths.input, {
|
|
138
|
+
method: "POST",
|
|
139
|
+
headers: { "content-type": "application/json" },
|
|
140
|
+
body: JSON.stringify(action),
|
|
141
|
+
});
|
|
142
|
+
return response.ok;
|
|
143
|
+
}
|
|
144
|
+
async function refresh() {
|
|
145
|
+
if (finished) return;
|
|
146
|
+
const response = await fetch(paths.frame, { cache: "no-store" });
|
|
147
|
+
dot.dataset.state = response.ok ? "live" : "idle";
|
|
148
|
+
if (!response.ok) return;
|
|
149
|
+
const previous = img.src;
|
|
150
|
+
img.src = URL.createObjectURL(await response.blob());
|
|
151
|
+
if (previous.startsWith("blob:")) URL.revokeObjectURL(previous);
|
|
152
|
+
}
|
|
153
|
+
img.addEventListener("click", async (event) => {
|
|
154
|
+
const rect = img.getBoundingClientRect();
|
|
155
|
+
await act({
|
|
156
|
+
kind: "click",
|
|
157
|
+
x: Math.round((event.clientX - rect.left) * (img.naturalWidth / rect.width)),
|
|
158
|
+
y: Math.round((event.clientY - rect.top) * (img.naturalHeight / rect.height)),
|
|
159
|
+
});
|
|
160
|
+
await refresh();
|
|
161
|
+
});
|
|
162
|
+
document.getElementById("send").addEventListener("click", async () => {
|
|
163
|
+
const field = document.getElementById("text");
|
|
164
|
+
if (field.value) await act({ kind: "type", text: field.value });
|
|
165
|
+
field.value = "";
|
|
166
|
+
await refresh();
|
|
167
|
+
});
|
|
168
|
+
document.getElementById("done-button").addEventListener("click", async () => {
|
|
169
|
+
if (!(await act({ kind: "resume" }))) return;
|
|
170
|
+
finished = true;
|
|
171
|
+
dot.dataset.state = "idle";
|
|
172
|
+
document.querySelector("main").innerHTML = '<p id="done">Done. The Agent can drive the browser again.</p>';
|
|
173
|
+
});
|
|
174
|
+
refresh();
|
|
175
|
+
setInterval(refresh, 1000);
|
|
176
|
+
</script>
|
|
177
|
+
</body>
|
|
178
|
+
</html>`;
|
|
179
|
+
}
|
|
@@ -13,6 +13,8 @@ export type ConversationBinding = Readonly<{
|
|
|
13
13
|
siteKey: string;
|
|
14
14
|
origins: readonly string[];
|
|
15
15
|
accent?: string | undefined;
|
|
16
|
+
/** Visitors must pass Turnstile before a mint. */
|
|
17
|
+
turnstile?: boolean | undefined;
|
|
16
18
|
}> | Readonly<{
|
|
17
19
|
provider: "discord" | "email" | "game";
|
|
18
20
|
}>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ConversationBinding } from "./binding.js";
|
|
2
|
+
/**
|
|
3
|
+
* Whether one Session of an Agent may run, and under which channel binding.
|
|
4
|
+
* A channel never narrows or widens the Agent's own tools and permissions; it
|
|
5
|
+
* only admits or refuses the run. A missing, suspended or unreadable binding
|
|
6
|
+
* denies the run.
|
|
7
|
+
*/
|
|
8
|
+
export type ChannelRunDecision<B extends ConversationBinding> = Readonly<{
|
|
9
|
+
kind: "private";
|
|
10
|
+
}> | Readonly<{
|
|
11
|
+
kind: "channel";
|
|
12
|
+
binding: B;
|
|
13
|
+
}> | Readonly<{
|
|
14
|
+
kind: "denied";
|
|
15
|
+
bindingId: string;
|
|
16
|
+
reason: ChannelDenial;
|
|
17
|
+
}>;
|
|
18
|
+
/** Why a channel Session may not run. */
|
|
19
|
+
export type ChannelDenial = "binding_missing" | "binding_suspended" | "lookup_failed";
|
|
20
|
+
/**
|
|
21
|
+
* Decide one Session. `conversationBindingId` is the binding the Session was
|
|
22
|
+
* opened under (null for an owner Session); `binding` is that binding as the
|
|
23
|
+
* Agent currently knows it, or null when it knows none.
|
|
24
|
+
*/
|
|
25
|
+
export declare function decideChannelRun<B extends ConversationBinding>(input: Readonly<{
|
|
26
|
+
conversationBindingId: string | null;
|
|
27
|
+
binding: B | null;
|
|
28
|
+
}>): ChannelRunDecision<B>;
|
|
29
|
+
/** Run the lookup and decision together; a throwing lookup denies. */
|
|
30
|
+
export declare function decideChannelRunSafely<B extends ConversationBinding>(lookup: () => Readonly<{
|
|
31
|
+
conversationBindingId: string | null;
|
|
32
|
+
binding: B | null;
|
|
33
|
+
}>, sessionId: string, onFailure: (cause: unknown) => void): ChannelRunDecision<B>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decide one Session. `conversationBindingId` is the binding the Session was
|
|
3
|
+
* opened under (null for an owner Session); `binding` is that binding as the
|
|
4
|
+
* Agent currently knows it, or null when it knows none.
|
|
5
|
+
*/
|
|
6
|
+
export function decideChannelRun(input) {
|
|
7
|
+
const { conversationBindingId: bindingId, binding } = input;
|
|
8
|
+
if (bindingId === null)
|
|
9
|
+
return { kind: "private" };
|
|
10
|
+
if (binding?.bindingId !== bindingId)
|
|
11
|
+
return { kind: "denied", bindingId, reason: "binding_missing" };
|
|
12
|
+
if (binding.lifecycle !== "active")
|
|
13
|
+
return { kind: "denied", bindingId, reason: "binding_suspended" };
|
|
14
|
+
return { kind: "channel", binding };
|
|
15
|
+
}
|
|
16
|
+
/** Run the lookup and decision together; a throwing lookup denies. */
|
|
17
|
+
export function decideChannelRunSafely(lookup, sessionId, onFailure) {
|
|
18
|
+
try {
|
|
19
|
+
return decideChannelRun(lookup());
|
|
20
|
+
}
|
|
21
|
+
catch (cause) {
|
|
22
|
+
onFailure(cause);
|
|
23
|
+
return { kind: "denied", bindingId: sessionId, reason: "lookup_failed" };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -1,37 +1,103 @@
|
|
|
1
1
|
import { type ConversationBinding } from "./binding.js";
|
|
2
2
|
import { type ChannelConversations, type ChannelWithdrawResult, type InboundEvent, type IntakeResult, type SessionDoor, type VisitorPendingPrompt, type VisitorReadOptions } from "./conversations.js";
|
|
3
3
|
import type { ChannelVisitors, VisitorGrant } from "./visitors.js";
|
|
4
|
+
export type AuthenticatedChannelVisitor = NonNullable<Awaited<ReturnType<ChannelVisitors["authenticate"]>>>;
|
|
4
5
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* Conversation work on an already authenticated visitor. Only the trusted
|
|
7
|
+
* edge/host can choose this path; no client-supplied visitor id is decoded here.
|
|
8
|
+
* The Hub's token-bearing door composes this same owner below.
|
|
8
9
|
*/
|
|
9
|
-
export declare function
|
|
10
|
+
export declare function createAuthenticatedVisitorChannel(options: Readonly<{
|
|
10
11
|
binding: (bindingId: string) => ConversationBinding | null;
|
|
11
|
-
visitors: () => ChannelVisitors;
|
|
12
12
|
conversations: () => ChannelConversations;
|
|
13
13
|
sessionDoor: () => SessionDoor;
|
|
14
14
|
intake: (event: InboundEvent) => Promise<IntakeResult>;
|
|
15
15
|
acquireStream: (bindingId: string, visitorId: string, addressHash: string) => (() => void) | null;
|
|
16
16
|
now: () => number;
|
|
17
17
|
}>): {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
rotate: (bindingId: string, siteKey: string, token: string, addressHash: string) => Promise<VisitorGrant | Readonly<{
|
|
18
|
+
send: (bindingId: string, visitor: AuthenticatedChannelVisitor, requestId: string, text: string) => Promise<IntakeResult>;
|
|
19
|
+
withdraw: (bindingId: string, visitor: AuthenticatedChannelVisitor, rawRequestId: string) => Promise<ChannelWithdrawResult | Readonly<{
|
|
21
20
|
kind: "unauthorized";
|
|
21
|
+
}> | Readonly<{
|
|
22
|
+
kind: "denied";
|
|
23
|
+
reason: "event_conflict" | "new_party_limit" | "banned";
|
|
22
24
|
}>>;
|
|
23
|
-
|
|
25
|
+
latestPending: (bindingId: string, visitor: AuthenticatedChannelVisitor) => Promise<VisitorPendingPrompt | null | Readonly<{
|
|
24
26
|
kind: "unauthorized";
|
|
25
27
|
}>>;
|
|
26
|
-
|
|
28
|
+
open: (bindingId: string, visitor: AuthenticatedChannelVisitor, read: VisitorReadOptions) => Promise<Readonly<{
|
|
29
|
+
kind: "session";
|
|
30
|
+
snapshot: string;
|
|
31
|
+
}> | Readonly<{
|
|
27
32
|
kind: "unauthorized";
|
|
28
33
|
}> | Readonly<{
|
|
29
34
|
kind: "denied";
|
|
30
|
-
reason: "
|
|
35
|
+
reason: "new_party_limit" | "banned";
|
|
36
|
+
}>>;
|
|
37
|
+
watch: (bindingId: string, visitor: AuthenticatedChannelVisitor, canRead: (visitorId: string) => Promise<boolean>) => Promise<Readonly<{
|
|
38
|
+
kind: "stream";
|
|
39
|
+
body: ReadableStream<Uint8Array>;
|
|
40
|
+
}> | Readonly<{
|
|
41
|
+
kind: "empty" | "unauthorized";
|
|
42
|
+
}> | Readonly<{
|
|
43
|
+
kind: "denied";
|
|
44
|
+
reason: "suspended" | "stream_limit";
|
|
31
45
|
}>>;
|
|
32
|
-
|
|
46
|
+
};
|
|
47
|
+
/** Hub's token-bearing channel uses the same conversation decisions as a
|
|
48
|
+
* standalone Agent whose edge already authenticated the central visitor. */
|
|
49
|
+
export declare function createVisitorChannel(options: Parameters<typeof createAuthenticatedVisitorChannel>[0] & Readonly<{
|
|
50
|
+
visitors: () => ChannelVisitors;
|
|
51
|
+
}>): {
|
|
52
|
+
mint: (bindingId: string, siteKey: string, addressHash: string) => Promise<VisitorGrant>;
|
|
53
|
+
refresh: (bindingId: string, secret: string) => Promise<VisitorGrant>;
|
|
54
|
+
rotate: (bindingId: string, siteKey: string, token: string, addressHash: string) => Promise<VisitorGrant | Readonly<{
|
|
33
55
|
kind: "unauthorized";
|
|
34
56
|
}>>;
|
|
57
|
+
send: (bindingId: string, token: string, requestId: string, text: string) => Promise<Readonly<{
|
|
58
|
+
kind: "accepted";
|
|
59
|
+
sessionId: string;
|
|
60
|
+
commandId: string;
|
|
61
|
+
delivery: "new" | "replay";
|
|
62
|
+
}> | Readonly<{
|
|
63
|
+
kind: "held";
|
|
64
|
+
sessionId: string;
|
|
65
|
+
delivery: "new" | "replay";
|
|
66
|
+
}> | Readonly<{
|
|
67
|
+
kind: "denied";
|
|
68
|
+
reason: "unmapped" | "suspended" | "banned" | "too_long" | "party_daily_limit" | "new_party_limit" | "rate_limited" | "event_conflict";
|
|
69
|
+
}> | {
|
|
70
|
+
readonly kind: "unauthorized";
|
|
71
|
+
}>;
|
|
72
|
+
withdraw: (bindingId: string, token: string, requestId: string) => Promise<Readonly<{
|
|
73
|
+
status: "unknown";
|
|
74
|
+
}> | Readonly<{
|
|
75
|
+
status: "accepted";
|
|
76
|
+
commandId: string;
|
|
77
|
+
sessionId?: string;
|
|
78
|
+
}> | Readonly<{
|
|
79
|
+
kind: "unauthorized";
|
|
80
|
+
}> | Readonly<{
|
|
81
|
+
kind: "denied";
|
|
82
|
+
reason: "event_conflict" | "new_party_limit" | "banned";
|
|
83
|
+
}> | {
|
|
84
|
+
readonly kind: "unauthorized";
|
|
85
|
+
}>;
|
|
86
|
+
latestPending: (bindingId: string, token: string) => Promise<Readonly<{
|
|
87
|
+
requestId: string;
|
|
88
|
+
commandId: string;
|
|
89
|
+
text: string;
|
|
90
|
+
delivery: "steer" | "followUp";
|
|
91
|
+
images?: readonly Readonly<{
|
|
92
|
+
type: "image";
|
|
93
|
+
data: string;
|
|
94
|
+
mimeType: string;
|
|
95
|
+
}>[] | undefined;
|
|
96
|
+
}> | Readonly<{
|
|
97
|
+
kind: "unauthorized";
|
|
98
|
+
}> | {
|
|
99
|
+
readonly kind: "unauthorized";
|
|
100
|
+
} | null>;
|
|
35
101
|
open: (bindingId: string, token: string, read: VisitorReadOptions) => Promise<Readonly<{
|
|
36
102
|
kind: "session";
|
|
37
103
|
snapshot: string;
|
|
@@ -40,7 +106,9 @@ export declare function createVisitorChannel(options: Readonly<{
|
|
|
40
106
|
}> | Readonly<{
|
|
41
107
|
kind: "denied";
|
|
42
108
|
reason: "new_party_limit" | "banned";
|
|
43
|
-
}
|
|
109
|
+
}> | {
|
|
110
|
+
readonly kind: "unauthorized";
|
|
111
|
+
}>;
|
|
44
112
|
watch: (bindingId: string, token: string, canRead: (visitorId: string) => Promise<boolean>) => Promise<Readonly<{
|
|
45
113
|
kind: "stream";
|
|
46
114
|
body: ReadableStream<Uint8Array>;
|
|
@@ -49,5 +117,7 @@ export declare function createVisitorChannel(options: Readonly<{
|
|
|
49
117
|
}> | Readonly<{
|
|
50
118
|
kind: "denied";
|
|
51
119
|
reason: "suspended" | "stream_limit";
|
|
52
|
-
}
|
|
120
|
+
}> | {
|
|
121
|
+
readonly kind: "unauthorized";
|
|
122
|
+
}>;
|
|
53
123
|
};
|