@fungi.computer/oyster 0.13.0 → 0.14.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 +30 -15
- package/dist/agents.js +2 -1
- package/dist/approval-home.js +4 -2
- package/dist/boot-host-script.js +1 -1
- package/dist/browser/cdp-client.d.ts +1 -1
- package/dist/browser/cdp-client.js +73 -37
- package/dist/browser/errors.d.ts +2 -0
- package/dist/browser/lease-registry.d.ts +5 -1
- package/dist/browser/lease-registry.js +2 -6
- package/dist/build/candidate-cli.mjs +267 -246
- package/dist/build/definition-emission.js +17 -3
- package/dist/build/local-build.d.ts +6 -0
- package/dist/build/local-build.js +104 -91
- package/dist/build/process-group.d.ts +6 -0
- package/dist/build/process-group.js +92 -0
- package/dist/build.d.ts +1 -1
- package/dist/build.js +1 -1
- package/dist/embed-metafiles.js +2 -2
- package/dist/embed-scripts.js +1 -1
- package/dist/git-journal.js +12 -9
- package/dist/hello-app-script.js +1 -1
- package/dist/host-page-assets.js +1 -1
- package/dist/host-page.d.ts +6 -1
- package/dist/host-page.js +40 -0
- package/dist/host.js +24 -9
- package/dist/installation-operations.js +1 -1
- package/dist/machine-link/host.js +18 -13
- package/dist/pack.d.ts +3 -1
- package/dist/pack.js +28 -7
- package/dist/page/app-permissions.js +3 -13
- package/dist/page-script.js +2 -2
- package/dist/standalone/agent-mail.d.ts +38 -11
- package/dist/standalone/agent-mail.js +8 -22
- package/dist/standalone/agents.d.ts +1 -0
- package/dist/standalone/agents.js +30 -5
- package/dist/standalone/hello-app.d.ts +4 -1
- package/dist/standalone/hello-app.js +67 -22
- package/dist/standalone/hello-lesson.d.ts +2 -0
- package/dist/standalone/hello-lesson.js +36 -0
- package/dist/standalone/local-desktop.d.ts +6 -4
- package/dist/standalone/local-desktop.js +39 -20
- package/dist/standalone/sign-in-link.d.ts +2 -1
- package/dist/standalone/sign-in-link.js +58 -17
- package/dist/standalone/try-cli.d.ts +12 -9
- package/dist/standalone/try-cli.js +490 -138
- package/docs/api/browser.md +24 -7
- package/docs/api/pack.md +3 -2
- package/docs/api/workers-git.md +2 -2
- package/docs/api/workers.md +2 -2
- package/docs/site/agent-quickstart.mdx +109 -354
- package/examples/standalone/wrangler.jsonc +1 -1
- package/package.json +24 -24
|
@@ -42,7 +42,7 @@ export type CdpClient = Readonly<{
|
|
|
42
42
|
timeoutMs?: number;
|
|
43
43
|
signal?: AbortSignal;
|
|
44
44
|
}>) => Promise<Json>;
|
|
45
|
-
/** Resolves on the next matching event, or
|
|
45
|
+
/** Resolves on the next matching event, or rejects on timeout or closure. */
|
|
46
46
|
waitForEvent: (method: string, options: Readonly<{
|
|
47
47
|
sessionId?: string;
|
|
48
48
|
timeoutMs: number;
|
|
@@ -56,11 +56,28 @@ function readCdpMessage(event) {
|
|
|
56
56
|
/** Wrap one connected CDP socket with id-correlated calls and event waits. */
|
|
57
57
|
export function createCdpClient(socket) {
|
|
58
58
|
const pending = new Map();
|
|
59
|
-
const waiters =
|
|
59
|
+
const waiters = new Set();
|
|
60
60
|
const subscribers = new Set();
|
|
61
61
|
let nextRequestNumber = 1;
|
|
62
62
|
let closed = false;
|
|
63
|
+
const terminate = (message) => {
|
|
64
|
+
if (closed)
|
|
65
|
+
return;
|
|
66
|
+
closed = true;
|
|
67
|
+
const error = new CloudBrowserUpstreamError({
|
|
68
|
+
op: "cdp.socket",
|
|
69
|
+
status: null,
|
|
70
|
+
message,
|
|
71
|
+
});
|
|
72
|
+
for (const call of pending.values())
|
|
73
|
+
call.reject(error);
|
|
74
|
+
for (const waiter of waiters)
|
|
75
|
+
waiter.reject(error);
|
|
76
|
+
subscribers.clear();
|
|
77
|
+
};
|
|
63
78
|
socket.addEventListener("message", (event) => {
|
|
79
|
+
if (closed)
|
|
80
|
+
return;
|
|
64
81
|
const frame = readCdpMessage(event);
|
|
65
82
|
if (frame.kind === "unreadable")
|
|
66
83
|
return;
|
|
@@ -69,7 +86,6 @@ export function createCdpClient(socket) {
|
|
|
69
86
|
const waiting = pending.get(message.id);
|
|
70
87
|
if (waiting === undefined)
|
|
71
88
|
return;
|
|
72
|
-
pending.delete(message.id);
|
|
73
89
|
if (message.error !== undefined)
|
|
74
90
|
waiting.reject(new CloudBrowserUpstreamError({
|
|
75
91
|
op: "cdp.call",
|
|
@@ -85,28 +101,19 @@ export function createCdpClient(socket) {
|
|
|
85
101
|
for (const subscriber of subscribers)
|
|
86
102
|
if (subscriber.method === message.method)
|
|
87
103
|
subscriber.listener(message.params ?? null, message.sessionId);
|
|
88
|
-
for (
|
|
89
|
-
|
|
90
|
-
if (waiter?.method === message.method &&
|
|
104
|
+
for (const waiter of waiters) {
|
|
105
|
+
if (waiter.method === message.method &&
|
|
91
106
|
(waiter.sessionId === undefined ||
|
|
92
107
|
waiter.sessionId === message.sessionId)) {
|
|
93
|
-
waiters.splice(index, 1);
|
|
94
108
|
waiter.resolve(message.params ?? null);
|
|
95
109
|
}
|
|
96
110
|
}
|
|
97
111
|
});
|
|
98
112
|
socket.addEventListener("close", () => {
|
|
99
|
-
|
|
100
|
-
for (const { reject } of pending.values())
|
|
101
|
-
reject(new CloudBrowserUpstreamError({
|
|
102
|
-
op: "cdp.socket",
|
|
103
|
-
status: null,
|
|
104
|
-
message: "browser CDP socket closed",
|
|
105
|
-
}));
|
|
106
|
-
pending.clear();
|
|
113
|
+
terminate("browser CDP socket closed");
|
|
107
114
|
});
|
|
108
115
|
socket.addEventListener("error", () => {
|
|
109
|
-
|
|
116
|
+
terminate("browser CDP socket failed");
|
|
110
117
|
});
|
|
111
118
|
return {
|
|
112
119
|
call: (method, params, options) => new Promise((resolve, reject) => {
|
|
@@ -118,66 +125,95 @@ export function createCdpClient(socket) {
|
|
|
118
125
|
}));
|
|
119
126
|
return;
|
|
120
127
|
}
|
|
128
|
+
if (options?.signal?.aborted) {
|
|
129
|
+
reject(new CloudBrowserTimeout({ op: method, timeoutMs: 0 }));
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
121
132
|
const requestNumber = nextRequestNumber;
|
|
122
133
|
nextRequestNumber += 1;
|
|
123
134
|
const timeoutMs = options?.timeoutMs ?? 15_000;
|
|
124
135
|
const timer = setTimeout(() => {
|
|
125
|
-
|
|
126
|
-
reject(new CloudBrowserTimeout({ op: method, timeoutMs }));
|
|
136
|
+
call.reject(new CloudBrowserTimeout({ op: method, timeoutMs }));
|
|
127
137
|
}, timeoutMs);
|
|
128
138
|
const onAbort = () => {
|
|
139
|
+
call.reject(new CloudBrowserTimeout({ op: method, timeoutMs: 0 }));
|
|
140
|
+
};
|
|
141
|
+
const cleanup = () => {
|
|
129
142
|
pending.delete(requestNumber);
|
|
130
143
|
clearTimeout(timer);
|
|
131
|
-
|
|
144
|
+
options?.signal?.removeEventListener("abort", onAbort);
|
|
132
145
|
};
|
|
133
|
-
|
|
134
|
-
pending.set(requestNumber, {
|
|
146
|
+
const call = {
|
|
135
147
|
resolve: (value) => {
|
|
136
|
-
|
|
137
|
-
options?.signal?.removeEventListener("abort", onAbort);
|
|
148
|
+
cleanup();
|
|
138
149
|
resolve(value);
|
|
139
150
|
},
|
|
140
151
|
reject: (error) => {
|
|
141
|
-
|
|
142
|
-
options?.signal?.removeEventListener("abort", onAbort);
|
|
152
|
+
cleanup();
|
|
143
153
|
reject(error);
|
|
144
154
|
},
|
|
145
|
-
}
|
|
155
|
+
};
|
|
156
|
+
pending.set(requestNumber, call);
|
|
157
|
+
options?.signal?.addEventListener("abort", onAbort, { once: true });
|
|
146
158
|
const frame = { id: requestNumber, method, params };
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
159
|
+
try {
|
|
160
|
+
socket.send(JSON.stringify(options?.sessionId === undefined
|
|
161
|
+
? frame
|
|
162
|
+
: { ...frame, sessionId: options.sessionId }));
|
|
163
|
+
}
|
|
164
|
+
catch (cause) {
|
|
165
|
+
cleanup();
|
|
166
|
+
throw new CloudBrowserUpstreamError({
|
|
167
|
+
op: method,
|
|
168
|
+
status: null,
|
|
169
|
+
message: "Could not send the browser CDP command",
|
|
170
|
+
cause,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
150
173
|
}),
|
|
151
174
|
waitForEvent: (method, options) => new Promise((resolve, reject) => {
|
|
175
|
+
if (closed) {
|
|
176
|
+
reject(new CloudBrowserUpstreamError({
|
|
177
|
+
op: method,
|
|
178
|
+
status: null,
|
|
179
|
+
message: "browser CDP socket is closed",
|
|
180
|
+
}));
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
const cleanup = () => {
|
|
184
|
+
waiters.delete(waiter);
|
|
185
|
+
clearTimeout(timer);
|
|
186
|
+
};
|
|
152
187
|
const waiter = {
|
|
153
188
|
method,
|
|
154
189
|
sessionId: options.sessionId,
|
|
155
190
|
resolve: (value) => {
|
|
156
|
-
|
|
191
|
+
cleanup();
|
|
157
192
|
resolve(value);
|
|
158
193
|
},
|
|
194
|
+
reject: (error) => {
|
|
195
|
+
cleanup();
|
|
196
|
+
reject(error);
|
|
197
|
+
},
|
|
159
198
|
};
|
|
160
199
|
const timer = setTimeout(() => {
|
|
161
|
-
|
|
162
|
-
if (index >= 0)
|
|
163
|
-
waiters.splice(index, 1);
|
|
164
|
-
reject(new CloudBrowserTimeout({
|
|
200
|
+
waiter.reject(new CloudBrowserTimeout({
|
|
165
201
|
op: method,
|
|
166
202
|
timeoutMs: options.timeoutMs,
|
|
167
203
|
}));
|
|
168
204
|
}, options.timeoutMs);
|
|
169
|
-
waiters.
|
|
205
|
+
waiters.add(waiter);
|
|
170
206
|
}),
|
|
171
207
|
on: (method, listener) => {
|
|
172
208
|
const subscriber = { method, listener };
|
|
173
|
-
|
|
209
|
+
if (!closed)
|
|
210
|
+
subscribers.add(subscriber);
|
|
174
211
|
return () => {
|
|
175
212
|
subscribers.delete(subscriber);
|
|
176
213
|
};
|
|
177
214
|
},
|
|
178
215
|
close: () => {
|
|
179
|
-
|
|
180
|
-
subscribers.clear();
|
|
216
|
+
terminate("browser CDP socket closed");
|
|
181
217
|
socket.close();
|
|
182
218
|
},
|
|
183
219
|
};
|
package/dist/browser/errors.d.ts
CHANGED
|
@@ -22,6 +22,8 @@ export declare class CloudBrowserUpstreamError extends CloudBrowserUpstreamError
|
|
|
22
22
|
readonly op: string;
|
|
23
23
|
readonly status: number | null;
|
|
24
24
|
readonly message: string;
|
|
25
|
+
/** Original transport failure retained for host diagnostics. */
|
|
26
|
+
readonly cause?: unknown;
|
|
25
27
|
}> {
|
|
26
28
|
}
|
|
27
29
|
declare const CloudBrowserTimeout_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
@@ -40,7 +40,11 @@ export type LeaseRegistry = Readonly<{
|
|
|
40
40
|
/** Turn a reservation into an open lease. */
|
|
41
41
|
/** `openedAt` is when the provider session was requested: lifetime and billing start there. */
|
|
42
42
|
register: (leaseId: string, owner: LeaseOwner, openedAt: number) => void;
|
|
43
|
-
/**
|
|
43
|
+
/**
|
|
44
|
+
* Throws `CloudBrowserLeaseNotFound` for a wrong owner, unknown, or expired
|
|
45
|
+
* lease. Expired records remain until the browser owner releases them for
|
|
46
|
+
* provider cleanup and settlement.
|
|
47
|
+
*/
|
|
44
48
|
touch: (leaseId: string, owner: LeaseOwner) => void;
|
|
45
49
|
release: (leaseId: string) => void;
|
|
46
50
|
/** Leases past their idle timeout or max lifetime, for a reap sweep. */
|
|
@@ -49,10 +49,8 @@ export function createLeaseRegistry(config) {
|
|
|
49
49
|
if (lease === undefined)
|
|
50
50
|
throw new CloudBrowserLeaseNotFound({ leaseId });
|
|
51
51
|
const at = now();
|
|
52
|
-
if (isExpired(lease, at))
|
|
53
|
-
leases.delete(leaseId);
|
|
52
|
+
if (isExpired(lease, at))
|
|
54
53
|
throw new CloudBrowserLeaseNotFound({ leaseId });
|
|
55
|
-
}
|
|
56
54
|
if (!ownedBy(lease, owner))
|
|
57
55
|
throw new CloudBrowserLeaseNotFound({ leaseId });
|
|
58
56
|
if (lease.paused)
|
|
@@ -64,10 +62,8 @@ export function createLeaseRegistry(config) {
|
|
|
64
62
|
if (lease === undefined)
|
|
65
63
|
throw new CloudBrowserLeaseNotFound({ leaseId });
|
|
66
64
|
const at = now();
|
|
67
|
-
if (isExpired(lease, at))
|
|
68
|
-
leases.delete(leaseId);
|
|
65
|
+
if (isExpired(lease, at))
|
|
69
66
|
throw new CloudBrowserLeaseNotFound({ leaseId });
|
|
70
|
-
}
|
|
71
67
|
if (lease.teamId !== teamId)
|
|
72
68
|
throw new CloudBrowserLeaseNotFound({ leaseId });
|
|
73
69
|
lease.lastActiveAt = at;
|