@fungi.computer/shiitake 0.1.0 → 0.3.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 +155 -34
- package/dist/agent-control.d.ts +78 -11
- package/dist/agent-control.js +273 -70
- package/dist/client-entry.d.ts +15 -8
- package/dist/client-entry.js +7 -5
- package/dist/client-wire.d.ts +24 -8
- package/dist/client-wire.js +53 -11
- package/dist/client.d.ts +56 -11
- package/dist/client.js +1 -1
- package/dist/cloudflare.d.ts +42 -23
- package/dist/cloudflare.js +76 -54
- package/dist/cold-sessions.d.ts +28 -0
- package/dist/cold-sessions.js +1 -0
- package/dist/delegation.d.ts +214 -0
- package/dist/delegation.js +319 -0
- package/dist/effect.d.ts +1 -1
- package/dist/errors.d.ts +2 -2
- package/dist/errors.js +2 -2
- package/dist/extension-contract.d.ts +10 -2
- package/dist/extensions.d.ts +6 -2
- package/dist/fleet.d.ts +52 -34
- package/dist/fleet.js +101 -63
- package/dist/hosted.js +1 -0
- package/dist/http-routes.d.ts +106 -22
- package/dist/http-routes.js +18 -1
- package/dist/index.d.ts +3 -2
- package/dist/internal/accepted-run-executor.d.ts +5 -0
- package/dist/internal/accepted-run-executor.js +10 -4
- package/dist/internal/admission-door.d.ts +3 -0
- package/dist/internal/admission-door.js +12 -2
- package/dist/internal/client-boundary.js +7 -1
- package/dist/internal/compaction/compaction-slot.d.ts +36 -0
- package/dist/internal/compaction/compaction-slot.js +41 -0
- package/dist/internal/compaction/compaction.d.ts +7 -4
- package/dist/internal/compaction/compaction.js +59 -30
- package/dist/internal/compaction/session-compaction.d.ts +8 -16
- package/dist/internal/compaction/session-compaction.js +358 -119
- package/dist/internal/compaction/settings.js +5 -0
- package/dist/internal/compaction/utils.d.ts +19 -16
- package/dist/internal/compaction/utils.js +30 -84
- package/dist/internal/contracts.d.ts +40 -13
- package/dist/internal/coordinator.js +28 -10
- package/dist/internal/effect-client.d.ts +4 -2
- package/dist/internal/effect-client.js +29 -0
- package/dist/internal/effect-contracts.d.ts +17 -4
- package/dist/internal/extension-runtime.d.ts +5 -0
- package/dist/internal/extension-runtime.js +184 -89
- package/dist/internal/host-meta.d.ts +7 -0
- package/dist/internal/model-acquisition.js +7 -1
- package/dist/internal/model-preference.d.ts +2 -0
- package/dist/internal/model-preference.js +2 -1
- package/dist/internal/promise-facade.js +4 -16
- package/dist/internal/run-failure-reason.d.ts +10 -0
- package/dist/internal/run-failure-reason.js +19 -0
- package/dist/internal/run-scope.d.ts +4 -1
- package/dist/internal/run-scope.js +38 -5
- package/dist/internal/runtime-coordinator.d.ts +2 -1
- package/dist/internal/runtime-coordinator.js +65 -4
- package/dist/internal/runtime-core.js +1 -0
- package/dist/internal/runtime-reconciliation.js +42 -6
- package/dist/internal/session-context.d.ts +1 -2
- package/dist/internal/session-context.js +8 -30
- package/dist/internal/session-status.d.ts +2 -1
- package/dist/internal/session-status.js +4 -1
- package/dist/internal/woodstock/client-projection.d.ts +6 -5
- package/dist/internal/woodstock/client-projection.js +79 -53
- package/dist/internal/woodstock/cold-sessions.d.ts +4 -0
- package/dist/internal/woodstock/cold-sessions.js +90 -0
- package/dist/internal/woodstock/extension-store.d.ts +2 -0
- package/dist/internal/woodstock/extension-store.js +4 -0
- package/dist/internal/woodstock/fleet-store.d.ts +3 -3
- package/dist/internal/woodstock/fleet-store.js +16 -11
- package/dist/internal/woodstock/index.d.ts +11 -3
- package/dist/internal/woodstock/index.js +33 -14
- package/dist/internal/woodstock/progress.d.ts +14 -1
- package/dist/internal/woodstock/progress.js +97 -19
- package/dist/internal/woodstock/run-recovery.js +6 -4
- package/dist/internal/woodstock/session-attention.d.ts +1 -1
- package/dist/internal/woodstock/session-attention.js +2 -2
- package/dist/internal/woodstock/session-entry.d.ts +109 -42
- package/dist/internal/woodstock/session-entry.js +63 -20
- package/dist/internal/woodstock/session-inbox.js +2 -0
- package/dist/internal/woodstock/session-store.d.ts +104 -24
- package/dist/internal/woodstock/session-store.js +937 -246
- package/dist/internal/woodstock/storage-admission.d.ts +8 -8
- package/dist/internal/woodstock/storage-admission.js +8 -34
- package/dist/internal/woodstock/storage-conformance.d.ts +15 -0
- package/dist/internal/woodstock/storage-conformance.js +489 -0
- package/dist/model-preference.d.ts +2 -2
- package/dist/model-preference.js +2 -2
- package/dist/node.js +1 -1
- package/dist/remote-client.js +8 -1
- package/dist/session-attention.d.ts +8 -1
- package/dist/session-attention.js +6 -1
- package/dist/testing.js +1 -0
- package/docs/api/README.md +18 -16
- package/docs/api/agent-control.md +172 -2
- package/docs/api/client-entry.md +26 -10
- package/docs/api/client.md +153 -37
- package/docs/api/cloudflare.md +76 -23
- package/docs/api/delegation.md +485 -0
- package/docs/api/effect.md +20 -2
- package/docs/api/extensions.md +21 -9
- package/docs/api/fleet.md +149 -122
- package/docs/api/http.md +4 -1
- package/docs/api/index.md +116 -20
- package/docs/api/internal/woodstock/storage-conformance.md +81 -0
- package/docs/api/model-preference.md +17 -0
- package/docs/api/testing.md +16 -4
- package/package.json +26 -14
- package/dist/internal/browser-sessions.d.ts +0 -31
- package/dist/internal/browser-sessions.js +0 -173
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
/** One ephemeral browser host per Session, borrowed by run and SSE scopes. */
|
|
2
|
-
export class BrowserSessions {
|
|
3
|
-
open;
|
|
4
|
-
hasSession;
|
|
5
|
-
generation = 0;
|
|
6
|
-
closed = false;
|
|
7
|
-
hosts = new Map();
|
|
8
|
-
constructor(open, hasSession) {
|
|
9
|
-
this.open = open;
|
|
10
|
-
this.hasSession = hasSession;
|
|
11
|
-
}
|
|
12
|
-
async clear() {
|
|
13
|
-
this.generation += 1;
|
|
14
|
-
const old = [...this.hosts.values()];
|
|
15
|
-
this.hosts.clear();
|
|
16
|
-
await Promise.all(old.flatMap((entry) => [...entry.connections].map((close) => close())));
|
|
17
|
-
}
|
|
18
|
-
async close() {
|
|
19
|
-
this.closed = true;
|
|
20
|
-
await this.clear();
|
|
21
|
-
}
|
|
22
|
-
async fetch(request) {
|
|
23
|
-
if (this.closed)
|
|
24
|
-
return new Response(null, { status: 410 });
|
|
25
|
-
const generation = this.generation;
|
|
26
|
-
const path = new URL(request.url).pathname;
|
|
27
|
-
const browserRoute = /^\/browser\/sessions\/([^/]+)\/browser\/(events|claims|results)$/u.exec(path);
|
|
28
|
-
if (browserRoute === null)
|
|
29
|
-
return new Response("Not found", { status: 404 });
|
|
30
|
-
let sessionId;
|
|
31
|
-
try {
|
|
32
|
-
sessionId = decodeURIComponent(browserRoute[1] ?? "");
|
|
33
|
-
}
|
|
34
|
-
catch {
|
|
35
|
-
return new Response("Not found", { status: 404 });
|
|
36
|
-
}
|
|
37
|
-
const route = browserRoute[2];
|
|
38
|
-
if (!sessionId || !route)
|
|
39
|
-
return new Response("Not found", { status: 404 });
|
|
40
|
-
let entry = this.hosts.get(sessionId);
|
|
41
|
-
if (entry === undefined) {
|
|
42
|
-
if (route !== "events")
|
|
43
|
-
return new Response("Not found", { status: 404 });
|
|
44
|
-
if (!(await this.hasSession(sessionId)))
|
|
45
|
-
return new Response("Not found", { status: 404 });
|
|
46
|
-
if (generation !== this.generation)
|
|
47
|
-
return new Response(null, { status: 404 });
|
|
48
|
-
entry = this.hosts.get(sessionId) ?? this.createHost(sessionId);
|
|
49
|
-
}
|
|
50
|
-
const target = new URL(request.url);
|
|
51
|
-
target.pathname = `/browser/${route}`;
|
|
52
|
-
if (route !== "events")
|
|
53
|
-
return entry.host.fetch(new Request(target, request));
|
|
54
|
-
return this.openEvents(new Request(target, request), sessionId, entry, generation);
|
|
55
|
-
}
|
|
56
|
-
/** Own the async transport opening until its stream joins the connection scope. */
|
|
57
|
-
async openEvents(request, sessionId, entry, generation) {
|
|
58
|
-
entry.browserConnections += 1;
|
|
59
|
-
try {
|
|
60
|
-
const response = await entry.host.fetch(request);
|
|
61
|
-
if (generation !== this.generation) {
|
|
62
|
-
// The maintained transport may finish opening after teardown. Its
|
|
63
|
-
// late scope belongs to the old generation and must never escape.
|
|
64
|
-
await response.body?.cancel();
|
|
65
|
-
this.releaseBrowserConnection(sessionId, entry);
|
|
66
|
-
return new Response(null, { status: 404 });
|
|
67
|
-
}
|
|
68
|
-
if (!response.ok || response.body === null) {
|
|
69
|
-
this.releaseBrowserConnection(sessionId, entry);
|
|
70
|
-
return response;
|
|
71
|
-
}
|
|
72
|
-
return this.trackBrowserConnection(response, sessionId, entry);
|
|
73
|
-
}
|
|
74
|
-
catch (error) {
|
|
75
|
-
this.releaseBrowserConnection(sessionId, entry);
|
|
76
|
-
throw error;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
createHost(sessionId) {
|
|
80
|
-
const entry = {
|
|
81
|
-
host: this.open(sessionId),
|
|
82
|
-
activeRuns: 0,
|
|
83
|
-
browserConnections: 0,
|
|
84
|
-
connections: new Set(),
|
|
85
|
-
};
|
|
86
|
-
this.hosts.set(sessionId, entry);
|
|
87
|
-
return entry;
|
|
88
|
-
}
|
|
89
|
-
acquire(sessionId) {
|
|
90
|
-
if (this.closed)
|
|
91
|
-
throw new Error("Browser host is closed");
|
|
92
|
-
const entry = this.hosts.get(sessionId) ?? this.createHost(sessionId);
|
|
93
|
-
entry.activeRuns += 1;
|
|
94
|
-
let released = false;
|
|
95
|
-
return {
|
|
96
|
-
host: entry.host,
|
|
97
|
-
release: () => {
|
|
98
|
-
if (released)
|
|
99
|
-
return;
|
|
100
|
-
released = true;
|
|
101
|
-
entry.activeRuns -= 1;
|
|
102
|
-
this.releaseIdleHost(sessionId, entry);
|
|
103
|
-
},
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
releaseBrowserConnection(sessionId, entry) {
|
|
107
|
-
entry.browserConnections -= 1;
|
|
108
|
-
this.releaseIdleHost(sessionId, entry);
|
|
109
|
-
}
|
|
110
|
-
releaseIdleHost(sessionId, entry) {
|
|
111
|
-
if (entry.activeRuns === 0 &&
|
|
112
|
-
entry.browserConnections === 0 &&
|
|
113
|
-
this.hosts.get(sessionId) === entry)
|
|
114
|
-
this.hosts.delete(sessionId);
|
|
115
|
-
}
|
|
116
|
-
trackBrowserConnection(response, sessionId, entry) {
|
|
117
|
-
const reader = response.body?.getReader();
|
|
118
|
-
if (reader === undefined) {
|
|
119
|
-
this.releaseBrowserConnection(sessionId, entry);
|
|
120
|
-
return response;
|
|
121
|
-
}
|
|
122
|
-
let released = false;
|
|
123
|
-
let controller;
|
|
124
|
-
const close = async () => {
|
|
125
|
-
if (released)
|
|
126
|
-
return;
|
|
127
|
-
release();
|
|
128
|
-
controller.close();
|
|
129
|
-
await reader.cancel();
|
|
130
|
-
};
|
|
131
|
-
const release = () => {
|
|
132
|
-
if (released)
|
|
133
|
-
return;
|
|
134
|
-
released = true;
|
|
135
|
-
entry.connections.delete(close);
|
|
136
|
-
this.releaseBrowserConnection(sessionId, entry);
|
|
137
|
-
};
|
|
138
|
-
entry.connections.add(close);
|
|
139
|
-
const body = new ReadableStream({
|
|
140
|
-
start: (streamController) => {
|
|
141
|
-
controller = streamController;
|
|
142
|
-
},
|
|
143
|
-
pull: async (controller) => {
|
|
144
|
-
try {
|
|
145
|
-
const next = await reader.read();
|
|
146
|
-
if (released)
|
|
147
|
-
return;
|
|
148
|
-
if (next.done) {
|
|
149
|
-
controller.close();
|
|
150
|
-
release();
|
|
151
|
-
}
|
|
152
|
-
else
|
|
153
|
-
controller.enqueue(next.value);
|
|
154
|
-
}
|
|
155
|
-
catch (error) {
|
|
156
|
-
if (released)
|
|
157
|
-
return;
|
|
158
|
-
controller.error(error);
|
|
159
|
-
release();
|
|
160
|
-
}
|
|
161
|
-
},
|
|
162
|
-
cancel: async (reason) => {
|
|
163
|
-
release();
|
|
164
|
-
await reader.cancel(reason);
|
|
165
|
-
},
|
|
166
|
-
});
|
|
167
|
-
return new Response(body, {
|
|
168
|
-
status: response.status,
|
|
169
|
-
statusText: response.statusText,
|
|
170
|
-
headers: response.headers,
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
}
|