@fungi.computer/oyster 0.47.2 → 0.47.4
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/dist/host.d.ts +6 -4
- package/dist/host.js +26 -5
- package/dist/mcp.d.ts +31 -13
- package/dist/mcp.js +16 -3
- package/dist/page/storage-events.d.ts +41 -0
- package/dist/page/storage-events.js +102 -0
- package/dist/page/storage-notice.d.ts +3 -0
- package/dist/page/storage-notice.js +28 -0
- package/dist/page/storage.js +53 -9
- package/dist/page-script.js +1 -1
- package/dist/storage-watch-stream.d.ts +13 -0
- package/dist/storage-watch-stream.js +19 -0
- package/dist/storage-watch-wire.d.ts +29 -0
- package/dist/storage-watch-wire.js +24 -0
- package/dist/workers.d.ts +3 -2
- package/dist/workers.js +10 -17
- package/docs/api/host.md +2 -3
- package/docs/api/mcp.md +20 -8
- package/docs/api/workers.md +26 -32
- package/package.json +11 -11
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as Stream from "effect/Stream";
|
|
2
|
+
import type { AppStorageEvent, AppStorageError, AppStorageResult } from "@fungi.computer/agar/storage";
|
|
3
|
+
import type { StorageWatch } from "./storage-watch-wire.js";
|
|
4
|
+
/** The owner's answer for one key: its change stream, or why it refuses it. */
|
|
5
|
+
export type StorageKeyWatch = AppStorageResult<Stream.Stream<AppStorageEvent | null, AppStorageError>>;
|
|
6
|
+
/**
|
|
7
|
+
* Merge the owner's per-key change streams into one stream of server-sent
|
|
8
|
+
* watch frames, each key admitted by `openKey` under fresh authority. A
|
|
9
|
+
* refused key is a `rejected` frame carrying its code while the rest keep
|
|
10
|
+
* flowing. The result is pull-driven, and cancelling it interrupts every key's
|
|
11
|
+
* own subscription.
|
|
12
|
+
*/
|
|
13
|
+
export declare function storageWatchStream(watches: readonly StorageWatch[], openKey: (watch: StorageWatch) => Promise<StorageKeyWatch>): ReadableStream<Uint8Array>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as Stream from "effect/Stream";
|
|
3
|
+
/**
|
|
4
|
+
* Merge the owner's per-key change streams into one stream of server-sent
|
|
5
|
+
* watch frames, each key admitted by `openKey` under fresh authority. A
|
|
6
|
+
* refused key is a `rejected` frame carrying its code while the rest keep
|
|
7
|
+
* flowing. The result is pull-driven, and cancelling it interrupts every key's
|
|
8
|
+
* own subscription.
|
|
9
|
+
*/
|
|
10
|
+
export function storageWatchStream(watches, openKey) {
|
|
11
|
+
const encoder = new TextEncoder();
|
|
12
|
+
const encode = (frame) => encoder.encode(`event: watch\ndata: ${JSON.stringify(frame)}\n\n`);
|
|
13
|
+
const one = (watch, index) => Stream.unwrap(Effect.map(Effect.promise(() => openKey(watch)), (opened) => opened.kind === "rejected"
|
|
14
|
+
? Stream.make(encode({ watch: index, kind: "rejected", code: opened.code }))
|
|
15
|
+
: opened.value.pipe(Stream.map((event) => encode(event === null
|
|
16
|
+
? { watch: index, kind: "ready" }
|
|
17
|
+
: { watch: index, kind: "changed", event })))));
|
|
18
|
+
return Stream.toReadableStream(Stream.mergeAll(watches.map(one), { concurrency: "unbounded" }));
|
|
19
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema";
|
|
2
|
+
/** One page watches many storage keys; browsers cap HTTP/1.1 hosts at six connections. */
|
|
3
|
+
export declare const maxStorageWatches = 64;
|
|
4
|
+
/** One watched storage key, named by the installation that owns it. */
|
|
5
|
+
export declare const storageWatchSchema: Schema.Tuple<readonly [Schema.String, Schema.String]>;
|
|
6
|
+
export type StorageWatch = typeof storageWatchSchema.Type;
|
|
7
|
+
/**
|
|
8
|
+
* What the shared stream says about one watch, by its position in the request:
|
|
9
|
+
* the key is ready, the key changed, or the owner refused the watch with the
|
|
10
|
+
* same code a dedicated read would have carried.
|
|
11
|
+
*/
|
|
12
|
+
export declare const storageWatchFrameSchema: Schema.Union<readonly [Schema.Struct<{
|
|
13
|
+
readonly watch: Schema.Number;
|
|
14
|
+
readonly kind: Schema.Literal<"ready">;
|
|
15
|
+
}>, Schema.Struct<{
|
|
16
|
+
readonly watch: Schema.Number;
|
|
17
|
+
readonly kind: Schema.Literal<"changed">;
|
|
18
|
+
readonly event: Schema.Struct<{
|
|
19
|
+
readonly appId: Schema.String;
|
|
20
|
+
readonly key: Schema.String;
|
|
21
|
+
readonly scope: Schema.Literals<readonly ["team", "member"]>;
|
|
22
|
+
readonly revision: Schema.Int;
|
|
23
|
+
}>;
|
|
24
|
+
}>, Schema.Struct<{
|
|
25
|
+
readonly watch: Schema.Number;
|
|
26
|
+
readonly kind: Schema.Literal<"rejected">;
|
|
27
|
+
readonly code: Schema.Literals<readonly ["invalid", "undeclared_key", "scope_not_declared", "owner_required", "too_large", "quota_exceeded", "conflict", "unavailable"]>;
|
|
28
|
+
}>]>;
|
|
29
|
+
export type StorageWatchFrame = typeof storageWatchFrameSchema.Type;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema";
|
|
2
|
+
import { appStorageErrorCodeSchema, appStorageEventSchema, } from "@fungi.computer/agar/storage";
|
|
3
|
+
/** One page watches many storage keys; browsers cap HTTP/1.1 hosts at six connections. */
|
|
4
|
+
export const maxStorageWatches = 64;
|
|
5
|
+
/** One watched storage key, named by the installation that owns it. */
|
|
6
|
+
export const storageWatchSchema = Schema.Tuple([Schema.String, Schema.String]);
|
|
7
|
+
/**
|
|
8
|
+
* What the shared stream says about one watch, by its position in the request:
|
|
9
|
+
* the key is ready, the key changed, or the owner refused the watch with the
|
|
10
|
+
* same code a dedicated read would have carried.
|
|
11
|
+
*/
|
|
12
|
+
export const storageWatchFrameSchema = Schema.Union([
|
|
13
|
+
Schema.Struct({ watch: Schema.Number, kind: Schema.Literal("ready") }),
|
|
14
|
+
Schema.Struct({
|
|
15
|
+
watch: Schema.Number,
|
|
16
|
+
kind: Schema.Literal("changed"),
|
|
17
|
+
event: appStorageEventSchema,
|
|
18
|
+
}),
|
|
19
|
+
Schema.Struct({
|
|
20
|
+
watch: Schema.Number,
|
|
21
|
+
kind: Schema.Literal("rejected"),
|
|
22
|
+
code: appStorageErrorCodeSchema,
|
|
23
|
+
}),
|
|
24
|
+
]);
|
package/dist/workers.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { type BrowserBinding } from "./browser/sessions.js";
|
|
|
8
8
|
import { type InstallationOperationRequest, type InstallationOperationReply } from "./installation-operations.js";
|
|
9
9
|
import { installationWorkerEntrypoint } from "./installation-execution.js";
|
|
10
10
|
export { installationWorkerEntrypoint };
|
|
11
|
+
import type { StorageWatch } from "./storage-watch-wire.js";
|
|
11
12
|
import { type BackgroundSyncRefusal } from "@fungi.computer/puffball/background-replay";
|
|
12
13
|
import { type TenantScope, type TenantId } from "./tenant.js";
|
|
13
14
|
import { type GillCall, type GillReply } from "@fungi.computer/gills";
|
|
@@ -213,8 +214,8 @@ export declare class OysterRegistry<Env extends OysterWorkerEnv = OysterWorkerEn
|
|
|
213
214
|
storageClaim(installationId: string, ownerId: string, input: AppStorageClaim): Promise<AppStorageResult<AppStorageClaimed>>;
|
|
214
215
|
/** Storage for a live owner method frame; no guest-selected installation or member. */
|
|
215
216
|
storageBackend(raw: InvocationFacts, method: string, args: readonly unknown[], tenantId: TenantId): Promise<OysterBindingResult>;
|
|
216
|
-
/**
|
|
217
|
-
|
|
217
|
+
/** Watch many storage keys as one stream, each under fresh owner admission. */
|
|
218
|
+
storageWatch(ownerId: string, watches: readonly StorageWatch[]): ReadableStream<Uint8Array>;
|
|
218
219
|
private storageResult;
|
|
219
220
|
private storageOwner;
|
|
220
221
|
/**
|
package/dist/workers.js
CHANGED
|
@@ -18,6 +18,7 @@ import { installationWorkerEntrypoint } from "./installation-execution.js";
|
|
|
18
18
|
export { installationWorkerEntrypoint };
|
|
19
19
|
import { approvedBindingGrants, scopedBindings } from "./apps/gate.js";
|
|
20
20
|
import { appMethodReplySchema } from "@fungi.computer/agar/backend";
|
|
21
|
+
import { storageWatchStream } from "./storage-watch-stream.js";
|
|
21
22
|
import { nativeGitFrameMethods, nativeGitMethodNameSchema, } from "@fungi.computer/agar/git-rpc";
|
|
22
23
|
import { backgroundOriginKey, actorLane, mayDefer, } from "@fungi.computer/puffball/background-replay";
|
|
23
24
|
import { emptyAppDeclaration, appBackendBindingKinds, } from "@fungi.computer/puffball/app";
|
|
@@ -33,7 +34,6 @@ import { fileCapabilities } from "./files.js";
|
|
|
33
34
|
import { DurableObject } from "cloudflare:workers";
|
|
34
35
|
import * as Effect from "effect/Effect";
|
|
35
36
|
import * as Schema from "effect/Schema";
|
|
36
|
-
import * as Stream from "effect/Stream";
|
|
37
37
|
import { parseReleaseId, parseSha256Digest, } from "@fungi.computer/puffball";
|
|
38
38
|
import { releaseSchema } from "@fungi.computer/puffball/effect";
|
|
39
39
|
import { AppInstanceError, } from "./index.js";
|
|
@@ -275,21 +275,14 @@ export class OysterRegistry extends DurableObject {
|
|
|
275
275
|
return Promise.resolve({ kind: "rejected", code: "invalid" });
|
|
276
276
|
}
|
|
277
277
|
}
|
|
278
|
-
/**
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
return
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
.pipe(Stream.map((event) => new TextEncoder().encode(event === null
|
|
287
|
-
? "event: ready\ndata: {}\n\n"
|
|
288
|
-
: `event: changed\ndata: ${JSON.stringify(event)}\n\n`)))), {
|
|
289
|
-
headers: {
|
|
290
|
-
"Content-Type": "text/event-stream",
|
|
291
|
-
"Cache-Control": "no-store",
|
|
292
|
-
},
|
|
278
|
+
/** Watch many storage keys as one stream, each under fresh owner admission. */
|
|
279
|
+
storageWatch(ownerId, watches) {
|
|
280
|
+
return storageWatchStream(watches, async ([installationId, key]) => {
|
|
281
|
+
const view = this.storageView(installationId, () => Promise.resolve(ownerId));
|
|
282
|
+
const admitted = await this.storageResult(view.read(key));
|
|
283
|
+
return admitted.kind === "rejected"
|
|
284
|
+
? admitted
|
|
285
|
+
: { kind: "accepted", value: view.events(key) };
|
|
293
286
|
});
|
|
294
287
|
}
|
|
295
288
|
storageResult(program) {
|
|
@@ -1424,8 +1417,8 @@ export function oysterWorkerHost(env, auth, options = {}) {
|
|
|
1424
1417
|
write: (input) => registry().storageWrite(installationId, ownerId, input),
|
|
1425
1418
|
reset: (input) => registry().storageReset(installationId, ownerId, input),
|
|
1426
1419
|
claim: (input) => registry().storageClaim(installationId, ownerId, input),
|
|
1427
|
-
events: (key) => registry().storageEvents(installationId, ownerId, key),
|
|
1428
1420
|
}),
|
|
1421
|
+
watchStorage: (ownerId, watches) => registry().storageWatch(ownerId, watches),
|
|
1429
1422
|
},
|
|
1430
1423
|
guestLimits: guestLimits(options.guestLimits),
|
|
1431
1424
|
artifacts,
|
package/docs/api/host.md
CHANGED
|
@@ -528,9 +528,8 @@ type OysterHost = Readonly<{
|
|
|
528
528
|
}>;
|
|
529
529
|
installing?: readonly InstallingApp[];
|
|
530
530
|
}>>;
|
|
531
|
-
storage: Pick<AppStorageWire, "read" | "write" | "reset" | "claim"
|
|
532
|
-
|
|
533
|
-
}>;
|
|
531
|
+
storage: Pick<AppStorageWire, "read" | "write" | "reset" | "claim">;
|
|
532
|
+
watchStorage: Promise<ReadableStream<Uint8Array<ArrayBufferLike>>>;
|
|
534
533
|
}>;
|
|
535
534
|
homeInstallationId?: string;
|
|
536
535
|
pageScript?: string;
|
package/docs/api/mcp.md
CHANGED
|
@@ -96,9 +96,15 @@ type ComputerControlPort = Readonly<{
|
|
|
96
96
|
running: "running";
|
|
97
97
|
sleeping: "sleeping";
|
|
98
98
|
starting: "starting";
|
|
99
|
-
start_failed: "start_failed";
|
|
100
99
|
}>;
|
|
101
100
|
}
|
|
101
|
+
| {
|
|
102
|
+
state: z.ZodLiteral<"start_failed">;
|
|
103
|
+
}
|
|
104
|
+
| {
|
|
105
|
+
state: z.ZodLiteral<"start_failed">;
|
|
106
|
+
reason: z.ZodString;
|
|
107
|
+
}
|
|
102
108
|
| {
|
|
103
109
|
state: z.ZodLiteral<"queued">;
|
|
104
110
|
position: z.ZodNumber;
|
|
@@ -110,9 +116,15 @@ type ComputerControlPort = Readonly<{
|
|
|
110
116
|
running: "running";
|
|
111
117
|
sleeping: "sleeping";
|
|
112
118
|
starting: "starting";
|
|
113
|
-
start_failed: "start_failed";
|
|
114
119
|
}>;
|
|
115
120
|
}
|
|
121
|
+
| {
|
|
122
|
+
state: z.ZodLiteral<"start_failed">;
|
|
123
|
+
}
|
|
124
|
+
| {
|
|
125
|
+
state: z.ZodLiteral<"start_failed">;
|
|
126
|
+
reason: z.ZodString;
|
|
127
|
+
}
|
|
116
128
|
| {
|
|
117
129
|
state: z.ZodLiteral<"queued">;
|
|
118
130
|
position: z.ZodNumber;
|
|
@@ -274,16 +286,16 @@ One set of schemas and operations for MCP and direct broker invocation.
|
|
|
274
286
|
| `state` | `object` | - | - |
|
|
275
287
|
| `state.replay` | `"safe"` | - | - |
|
|
276
288
|
| `state.access` | `"read"` | - | - |
|
|
277
|
-
| `state.description` | `string` | `"Read runtime state without waking a Computer, including its live admission queue position."`
|
|
278
|
-
| `state.input` | `ZodObject`\<\{ `computerId`: `ZodString`; \}, `$strict`\>
|
|
279
|
-
| `state.output` | `
|
|
280
|
-
| `state.execute()` | (`input`, `context`) => `Promise`\< \| \{ `state`: `"running"` \| `"sleeping"` \| `"starting"` \| `"start_failed"`; \} \| \{ `state`: `"queued"`; `position`: `number`; \}\>
|
|
289
|
+
| `state.description` | `string` | `"Read runtime state without waking a Computer, including its live admission queue position. Pass reason: true to get why a failed start failed."` | - |
|
|
290
|
+
| `state.input` | `ZodObject`\<\{ `computerId`: `ZodString`; `reason`: `ZodExactOptional`\<`ZodLiteral`\<`true`\>\>; \}, `$strict`\> | `fleetStateRead` | - |
|
|
291
|
+
| `state.output` | `ZodUnion`\<readonly \[`ZodObject`\<\{ `state`: `ZodEnum`\<\{ `running`: `"running"`; `sleeping`: `"sleeping"`; `starting`: `"starting"`; \}\>; \}, `$strict`\>, `ZodObject`\<\{ `state`: `ZodLiteral`\<`"start_failed"`\>; \}, `$strict`\>, `ZodObject`\<\{ `state`: `ZodLiteral`\<`"start_failed"`\>; `reason`: `ZodString`; \}, `$strict`\>, `ZodObject`\<\{ `state`: `ZodLiteral`\<`"queued"`\>; `position`: `ZodNumber`; \}, `$strict`\>\]\> | `computerStateSchema` | - |
|
|
292
|
+
| `state.execute()` | (`input`, `context`) => `Promise`\< \| \{ `state`: `"running"` \| `"sleeping"` \| `"starting"`; \} \| \{ `state`: `"start_failed"`; \} \| \{ `state`: `"start_failed"`; `reason`: `string`; \} \| \{ `state`: `"queued"`; `position`: `number`; \}\> | - | Return liveness without waking the runtime. |
|
|
281
293
|
| `start` | `object` | - | - |
|
|
282
294
|
| `start.replay` | `"unsafe"` | - | - |
|
|
283
295
|
| `start.description` | `string` | `"Start a hosted Computer through ordinary admission. Waits until connected; poll computers.state while queued. Safe to retry."` | - |
|
|
284
296
|
| `start.input` | `ZodObject`\<\{ `computerId`: `ZodString`; \}, `$strict`\> | `fleetComputerId` | - |
|
|
285
|
-
| `start.output` | `
|
|
286
|
-
| `start.execute()` | (`input`, `context`) => `Promise`\< \| \{ `state`: `"running"` \| `"sleeping"` \| `"starting"` \| `"start_failed"`; \} \| \{ `state`: `"queued"`; `position`: `number`; \}\>
|
|
297
|
+
| `start.output` | `ZodUnion`\<readonly \[`ZodObject`\<\{ `state`: `ZodEnum`\<\{ `running`: `"running"`; `sleeping`: `"sleeping"`; `starting`: `"starting"`; \}\>; \}, `$strict`\>, `ZodObject`\<\{ `state`: `ZodLiteral`\<`"start_failed"`\>; \}, `$strict`\>, `ZodObject`\<\{ `state`: `ZodLiteral`\<`"start_failed"`\>; `reason`: `ZodString`; \}, `$strict`\>, `ZodObject`\<\{ `state`: `ZodLiteral`\<`"queued"`\>; `position`: `ZodNumber`; \}, `$strict`\>\]\> | `computerStateSchema` | - |
|
|
298
|
+
| `start.execute()` | (`input`, `context`) => `Promise`\< \| \{ `state`: `"running"` \| `"sleeping"` \| `"starting"`; \} \| \{ `state`: `"start_failed"`; \} \| \{ `state`: `"start_failed"`; `reason`: `string`; \} \| \{ `state`: `"queued"`; `position`: `number`; \}\> | - | Admit and start this Computer. |
|
|
287
299
|
| `create` | `object` | - | - |
|
|
288
300
|
| `create.replay` | `"unsafe"` | - | - |
|
|
289
301
|
| `create.description` | `string` | `"Create a Computer with an optional friendly name and size (small, default or large; default when omitted). Request identity is generated automatically. If the outcome is uncertain, retry with its returned requestId and the original name and size input; do not start a second creation."` | - |
|