@fungi.computer/oyster 0.49.0 → 0.50.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/dist/app-region.js +16 -5
- package/dist/computer-api.d.ts +397 -0
- package/dist/computer-api.js +157 -0
- package/dist/computer-control-port.d.ts +17 -0
- package/dist/embed-metafiles.js +1 -1
- package/dist/embed-scripts.js +1 -1
- package/dist/mcp.d.ts +61 -0
- package/dist/mcp.js +54 -0
- package/dist/standalone/computer-api.d.ts +6 -0
- package/dist/standalone/computer-api.js +122 -0
- package/dist/standalone/computer-control.js +31 -0
- package/dist/standalone/computer.d.ts +5 -0
- package/dist/standalone/computer.js +57 -0
- package/dist/standalone/owner-routes.d.ts +1 -1
- package/dist/standalone/owner-routes.js +2 -0
- package/dist/standalone/registry.d.ts +1 -1
- package/docs/api/computer-api.md +529 -0
- package/docs/api/mcp.md +74 -46
- package/docs/api/modules.md +1 -0
- package/docs/api/workers.md +16 -16
- package/package.json +8 -4
package/dist/mcp.d.ts
CHANGED
|
@@ -91,6 +91,29 @@ declare const fleetDetachment: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
91
91
|
uncertain: "uncertain";
|
|
92
92
|
}>;
|
|
93
93
|
}, z.core.$strict>], "kind">;
|
|
94
|
+
declare const fleetStop: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
95
|
+
kind: z.ZodLiteral<"stopped">;
|
|
96
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
97
|
+
kind: z.ZodEnum<{
|
|
98
|
+
denied: "denied";
|
|
99
|
+
busy: "busy";
|
|
100
|
+
uncertain: "uncertain";
|
|
101
|
+
}>;
|
|
102
|
+
}, z.core.$strict>], "kind">;
|
|
103
|
+
declare const fleetDelete: z.ZodObject<{
|
|
104
|
+
computerId: z.ZodString;
|
|
105
|
+
confirmHandle: z.ZodString;
|
|
106
|
+
}, z.core.$strict>;
|
|
107
|
+
declare const fleetDeletion: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
108
|
+
kind: z.ZodLiteral<"deleted">;
|
|
109
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
110
|
+
kind: z.ZodEnum<{
|
|
111
|
+
denied: "denied";
|
|
112
|
+
uncertain: "uncertain";
|
|
113
|
+
unsupported: "unsupported";
|
|
114
|
+
mismatch: "mismatch";
|
|
115
|
+
}>;
|
|
116
|
+
}, z.core.$strict>], "kind">;
|
|
94
117
|
declare const fleetCreation: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
95
118
|
kind: z.ZodLiteral<"created">;
|
|
96
119
|
requestId: z.ZodString;
|
|
@@ -244,6 +267,44 @@ export declare function computerControlSpecs(port: ComputerControlPort): {
|
|
|
244
267
|
/** Mint one identity or preserve the requestId for an uncertain retry. */
|
|
245
268
|
execute: (input: z.output<typeof fleetCreate>, context: InvocationContext) => Promise<z.output<typeof fleetCreation>>;
|
|
246
269
|
};
|
|
270
|
+
stop: {
|
|
271
|
+
replay: "unsafe";
|
|
272
|
+
description: string;
|
|
273
|
+
input: z.ZodObject<{
|
|
274
|
+
computerId: z.ZodString;
|
|
275
|
+
}, z.core.$strict>;
|
|
276
|
+
output: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
277
|
+
kind: z.ZodLiteral<"stopped">;
|
|
278
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
279
|
+
kind: z.ZodEnum<{
|
|
280
|
+
denied: "denied";
|
|
281
|
+
busy: "busy";
|
|
282
|
+
uncertain: "uncertain";
|
|
283
|
+
}>;
|
|
284
|
+
}, z.core.$strict>], "kind">;
|
|
285
|
+
/** End the runtime; the Computer and its Workspace stay. */
|
|
286
|
+
execute: (input: z.output<typeof fleetComputerId>, context: InvocationContext) => Promise<z.output<typeof fleetStop>>;
|
|
287
|
+
};
|
|
288
|
+
delete: {
|
|
289
|
+
replay: "unsafe";
|
|
290
|
+
description: string;
|
|
291
|
+
input: z.ZodObject<{
|
|
292
|
+
computerId: z.ZodString;
|
|
293
|
+
confirmHandle: z.ZodString;
|
|
294
|
+
}, z.core.$strict>;
|
|
295
|
+
output: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
296
|
+
kind: z.ZodLiteral<"deleted">;
|
|
297
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
298
|
+
kind: z.ZodEnum<{
|
|
299
|
+
denied: "denied";
|
|
300
|
+
uncertain: "uncertain";
|
|
301
|
+
unsupported: "unsupported";
|
|
302
|
+
mismatch: "mismatch";
|
|
303
|
+
}>;
|
|
304
|
+
}, z.core.$strict>], "kind">;
|
|
305
|
+
/** Match the handle to the Computer's own name before anything is erased. */
|
|
306
|
+
execute: (input: z.output<typeof fleetDelete>, context: InvocationContext) => Promise<z.output<typeof fleetDeletion>>;
|
|
307
|
+
};
|
|
247
308
|
backends: {
|
|
248
309
|
replay: "safe";
|
|
249
310
|
description: string;
|
package/dist/mcp.js
CHANGED
|
@@ -89,6 +89,22 @@ const fleetDetachment = z.discriminatedUnion("kind", [
|
|
|
89
89
|
z.strictObject({ kind: z.literal("detached"), detached: z.boolean() }),
|
|
90
90
|
z.strictObject({ kind: z.enum(["denied", "uncertain", "invalid"]) }),
|
|
91
91
|
]);
|
|
92
|
+
const fleetStop = z.discriminatedUnion("kind", [
|
|
93
|
+
z.strictObject({ kind: z.literal("stopped") }),
|
|
94
|
+
z.strictObject({ kind: z.enum(["denied", "busy", "uncertain"]) }),
|
|
95
|
+
]);
|
|
96
|
+
const fleetDelete = z.strictObject({
|
|
97
|
+
computerId: fleetComputerId.shape.computerId,
|
|
98
|
+
confirmHandle: z.string().min(1).max(256),
|
|
99
|
+
});
|
|
100
|
+
const fleetDeletion = z.discriminatedUnion("kind", [
|
|
101
|
+
z.strictObject({ kind: z.literal("deleted") }),
|
|
102
|
+
z.strictObject({
|
|
103
|
+
kind: z.enum(["denied", "mismatch", "unsupported", "uncertain"]),
|
|
104
|
+
}),
|
|
105
|
+
]);
|
|
106
|
+
/** Directory pages read to find one Computer's name; a Team never has more. */
|
|
107
|
+
const maximumDirectoryPages = 20;
|
|
92
108
|
const fleetCreation = z.discriminatedUnion("kind", [
|
|
93
109
|
z.strictObject({
|
|
94
110
|
kind: z.literal("created"),
|
|
@@ -150,6 +166,36 @@ export function computerControlSpecs(port) {
|
|
|
150
166
|
return { ...result, requestId };
|
|
151
167
|
},
|
|
152
168
|
},
|
|
169
|
+
stop: {
|
|
170
|
+
replay: "unsafe",
|
|
171
|
+
description: 'Stop a Computer now and free its running slot. Running commands end; files are kept and the next start brings it back. Only the signed-in owner may; "busy" means it is starting or finishing an operation, so try again.',
|
|
172
|
+
input: fleetComputerId,
|
|
173
|
+
output: fleetStop,
|
|
174
|
+
/** End the runtime; the Computer and its Workspace stay. */
|
|
175
|
+
execute: (input, context) => port.stop(input.computerId, context),
|
|
176
|
+
},
|
|
177
|
+
delete: {
|
|
178
|
+
replay: "unsafe",
|
|
179
|
+
description: 'Delete a Computer and erase its Workspace, permanently. Pass its exact name as confirmHandle; a different handle deletes nothing. Only the signed-in owner may, never a Team key or an Agent. "uncertain" means retry: a delete cut short finishes on the next attempt.',
|
|
180
|
+
input: fleetDelete,
|
|
181
|
+
output: fleetDeletion,
|
|
182
|
+
/** Match the handle to the Computer's own name before anything is erased. */
|
|
183
|
+
execute: async (input, context) => {
|
|
184
|
+
let name;
|
|
185
|
+
for (let page = 0, offset = 0; page < maximumDirectoryPages && name === undefined; page += 1) {
|
|
186
|
+
const listed = await port.list({ limit: 100, offset }, context);
|
|
187
|
+
name = listed.computers.find((computer) => computer.computerId === input.computerId)?.name;
|
|
188
|
+
if (listed.nextOffset === null)
|
|
189
|
+
break;
|
|
190
|
+
offset = listed.nextOffset;
|
|
191
|
+
}
|
|
192
|
+
if (name === undefined)
|
|
193
|
+
return { kind: "denied" };
|
|
194
|
+
if (name !== input.confirmHandle)
|
|
195
|
+
return { kind: "mismatch" };
|
|
196
|
+
return port.delete(input.computerId, context);
|
|
197
|
+
},
|
|
198
|
+
},
|
|
153
199
|
backends: {
|
|
154
200
|
replay: "safe",
|
|
155
201
|
description: "List one Computer's attached execution backends (platform container, on-box VM, members' machines) with live status.",
|
|
@@ -652,6 +698,14 @@ export function oysterMcpCatalogLoad(host) {
|
|
|
652
698
|
...fleetSpecs.create,
|
|
653
699
|
confirm: true,
|
|
654
700
|
}),
|
|
701
|
+
stop: Mycelium.operation({
|
|
702
|
+
...fleetSpecs.stop,
|
|
703
|
+
confirm: true,
|
|
704
|
+
}),
|
|
705
|
+
delete: Mycelium.operation({
|
|
706
|
+
...fleetSpecs.delete,
|
|
707
|
+
confirm: true,
|
|
708
|
+
}),
|
|
655
709
|
backends: Mycelium.operation(fleetSpecs.backends),
|
|
656
710
|
attachLocal: Mycelium.operation(fleetSpecs.attachLocal),
|
|
657
711
|
detachLocal: Mycelium.operation(fleetSpecs.detachLocal),
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Routes } from "../authorization.js";
|
|
2
|
+
import type { OysterEnv } from "../host.js";
|
|
3
|
+
import type { StandaloneRegistryRpc } from "./registry.js";
|
|
4
|
+
import type { ComputerDO } from "./computer.js";
|
|
5
|
+
/** Only the live tenant owner and an inventoried Computer reach the native port. */
|
|
6
|
+
export declare function standaloneComputerApiRoutes(registry: () => Pick<StandaloneRegistryRpc, "computerFleet">, computer: (id: string) => Pick<ComputerDO, "apiOperation">): Routes<OysterEnv>;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema";
|
|
2
|
+
import { bodyLimit } from "hono/body-limit";
|
|
3
|
+
import { computerApiBodyBytes, computerApiDotSegment, computerApiId, computerApiOperations, computerApiRequestSchema, } from "../computer-api.js";
|
|
4
|
+
import { owner, routes } from "../authorization.js";
|
|
5
|
+
import { sameOriginReadRequest, sameOriginRequest } from "../request-origin.js";
|
|
6
|
+
/** `application/json`, with or without parameters; any other media type is not a JSON body. */
|
|
7
|
+
function isJsonBody(contentType) {
|
|
8
|
+
return (contentType?.split(";")[0]?.trim().toLowerCase() === "application/json");
|
|
9
|
+
}
|
|
10
|
+
/** The only fields a request may name a machine path in; other fields are decoded by the operation. */
|
|
11
|
+
const pathFields = Schema.Struct({
|
|
12
|
+
path: Schema.optionalKey(Schema.String),
|
|
13
|
+
cwd: Schema.optionalKey(Schema.String),
|
|
14
|
+
});
|
|
15
|
+
/** Only the live tenant owner and an inventoried Computer reach the native port. */
|
|
16
|
+
export function standaloneComputerApiRoutes(registry, computer) {
|
|
17
|
+
const table = routes();
|
|
18
|
+
const strict = { onExcessProperty: "error" };
|
|
19
|
+
const decode = Schema.decodeUnknownSync(computerApiRequestSchema, strict);
|
|
20
|
+
const query = Schema.Record(Schema.String, Schema.Array(Schema.String).check(Schema.isBetweenLength(1, 1)));
|
|
21
|
+
const methods = {
|
|
22
|
+
get: "GET",
|
|
23
|
+
post: "POST",
|
|
24
|
+
put: "PUT",
|
|
25
|
+
delete: "DELETE",
|
|
26
|
+
};
|
|
27
|
+
for (const operation of computerApiOperations) {
|
|
28
|
+
table.on([methods[operation.method]], `/api/computers/:computerId${operation.path}`, owner("direct-or-app"), async (context, { principal }) => {
|
|
29
|
+
context.header("Cache-Control", "no-store");
|
|
30
|
+
// The owner cookie is the only credential, so the request must prove
|
|
31
|
+
// where it came from and say it is JSON before anything is admitted: a
|
|
32
|
+
// page on a sibling site can otherwise post a text/plain form whose
|
|
33
|
+
// body is valid JSON. A reading route needs only no foreign provenance.
|
|
34
|
+
const mutates = operation.method !== "get";
|
|
35
|
+
if (!(mutates
|
|
36
|
+
? sameOriginRequest(context.req.raw)
|
|
37
|
+
: sameOriginReadRequest(context.req.raw)))
|
|
38
|
+
return context.json({ error: "cross_origin" }, 403);
|
|
39
|
+
if ((operation.method === "post" || operation.method === "put") &&
|
|
40
|
+
!isJsonBody(context.req.header("content-type")))
|
|
41
|
+
return context.json({ error: "unsupported_media_type" }, 415);
|
|
42
|
+
let id;
|
|
43
|
+
try {
|
|
44
|
+
id = Schema.decodeUnknownSync(computerApiId)(context.req.param("computerId"));
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return context.json({ error: "invalid" }, 400);
|
|
48
|
+
}
|
|
49
|
+
const admit = async () => {
|
|
50
|
+
const result = await registry().computerFleet(principal.actor.memberId, { operation: "resolve", computerId: id });
|
|
51
|
+
return result !== null && !("error" in result);
|
|
52
|
+
};
|
|
53
|
+
try {
|
|
54
|
+
if (!(await admit()))
|
|
55
|
+
return context.json({ error: "denied" }, 403);
|
|
56
|
+
let request;
|
|
57
|
+
try {
|
|
58
|
+
let input;
|
|
59
|
+
if (operation.method === "get" || operation.method === "delete") {
|
|
60
|
+
if (context.req.url.length > 8192)
|
|
61
|
+
return context.json({ error: "too_large" }, 413);
|
|
62
|
+
const parameters = Schema.decodeUnknownSync(query)(context.req.queries());
|
|
63
|
+
input = Object.fromEntries(Object.entries(parameters).map(([key, values]) => [
|
|
64
|
+
key,
|
|
65
|
+
["lines", "limit", "offset"].includes(key)
|
|
66
|
+
? Schema.decodeUnknownSync(Schema.NumberFromString)(values[0])
|
|
67
|
+
: values[0],
|
|
68
|
+
]));
|
|
69
|
+
}
|
|
70
|
+
else
|
|
71
|
+
input = await context.req.json();
|
|
72
|
+
const { path, cwd } = Schema.decodeUnknownSync(pathFields)(input);
|
|
73
|
+
if ([path, cwd].some((value) => value !== undefined && computerApiDotSegment.test(value)))
|
|
74
|
+
return context.json({ error: "invalid_path" }, 400);
|
|
75
|
+
request = decode({ operation: operation.operation, input });
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return context.json({ error: "invalid" }, 400);
|
|
79
|
+
}
|
|
80
|
+
// Body consumption may await a client; re-admit before any native mutation.
|
|
81
|
+
if (!(await admit()))
|
|
82
|
+
return context.json({ error: "denied" }, 403);
|
|
83
|
+
const action = operation.action;
|
|
84
|
+
const result = await computer(id).apiOperation({
|
|
85
|
+
computerId: id,
|
|
86
|
+
actions: new Set([action]),
|
|
87
|
+
expiresAt: Date.now() + 60_000,
|
|
88
|
+
provenance: { actor: `owner:${principal.actor.memberId}` },
|
|
89
|
+
}, request);
|
|
90
|
+
if ("error" in result) {
|
|
91
|
+
switch (result.error) {
|
|
92
|
+
case "too_large":
|
|
93
|
+
return context.json({ error: "too_large" }, 413);
|
|
94
|
+
case "denied":
|
|
95
|
+
return context.json({ error: "denied" }, 403);
|
|
96
|
+
case "not_found":
|
|
97
|
+
return context.json({ error: "not_found" }, 404);
|
|
98
|
+
case "conflict":
|
|
99
|
+
return context.json({ error: "conflict" }, 409);
|
|
100
|
+
case "invalid":
|
|
101
|
+
return context.json({ error: "invalid" }, 400);
|
|
102
|
+
default:
|
|
103
|
+
return context.json({ error: "unavailable" }, 503);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return context.json(result);
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
// Native errors may contain commands, file content or provider credentials.
|
|
110
|
+
return context.json({ error: "unavailable" }, 503);
|
|
111
|
+
}
|
|
112
|
+
}, {
|
|
113
|
+
middleware: [
|
|
114
|
+
bodyLimit({
|
|
115
|
+
maxSize: computerApiBodyBytes,
|
|
116
|
+
onError: (context) => context.json({ error: "too_large" }, 413),
|
|
117
|
+
}),
|
|
118
|
+
],
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
return table;
|
|
122
|
+
}
|
|
@@ -19,6 +19,7 @@ const inventoryError = z.strictObject({
|
|
|
19
19
|
const backendList = z.strictObject({
|
|
20
20
|
backends: z.array(computerBackendViewSchema),
|
|
21
21
|
});
|
|
22
|
+
const stopped = z.strictObject({ state: z.literal("sleeping") });
|
|
22
23
|
const attachedBackend = z.strictObject({ backendId: z.string() });
|
|
23
24
|
const detachedBackend = z.strictObject({ detached: z.boolean() });
|
|
24
25
|
/** A typed refusal from the owner-admitted fleet, as the MCP result kinds. */
|
|
@@ -48,6 +49,36 @@ export function standaloneComputerControl(registry, memberId) {
|
|
|
48
49
|
list: async (page) => teamComputerDirectorySchema.parse(inventoryPage.parse(available(await fleet({ operation: "list", page })))),
|
|
49
50
|
state: async (computerId) => computerStateSchema.parse(available(await fleet({ operation: "state", computerId }))),
|
|
50
51
|
start: async (computerId) => computerStateSchema.parse(available(await fleet({ operation: "start", computerId }))),
|
|
52
|
+
stop: async (computerId) => {
|
|
53
|
+
let result;
|
|
54
|
+
try {
|
|
55
|
+
result = await fleet({ operation: "stop", computerId });
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
// The runtime may have stopped before the RPC failed; the caller retries.
|
|
59
|
+
return { kind: "uncertain" };
|
|
60
|
+
}
|
|
61
|
+
if (result === null)
|
|
62
|
+
return { kind: "denied" };
|
|
63
|
+
const error = inventoryError.safeParse(result);
|
|
64
|
+
if (error.success) {
|
|
65
|
+
switch (error.data.error) {
|
|
66
|
+
case "busy":
|
|
67
|
+
return { kind: "busy" };
|
|
68
|
+
case "owner_required":
|
|
69
|
+
case "not_owner":
|
|
70
|
+
case "unknown_computer":
|
|
71
|
+
return { kind: "denied" };
|
|
72
|
+
default:
|
|
73
|
+
return { kind: "uncertain" };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
stopped.parse(result);
|
|
77
|
+
return { kind: "stopped" };
|
|
78
|
+
},
|
|
79
|
+
// Oyster has no delete path: inventory retirement here would leave the
|
|
80
|
+
// Computer's Workspace and runtime behind, so it refuses plainly.
|
|
81
|
+
delete: () => Promise.resolve({ kind: "unsupported" }),
|
|
51
82
|
create: async (input) => {
|
|
52
83
|
let result;
|
|
53
84
|
try {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ComputerApiRequest } from "../computer-api.js";
|
|
1
2
|
import { type ComputerSize } from "@fungi.computer/computer/backing";
|
|
2
3
|
import { type AppMethodRefusedReply } from "@fungi.computer/agar/backend";
|
|
3
4
|
import type { WatchdogSqliteOwner } from "@fungi.computer/watchdog";
|
|
@@ -214,6 +215,10 @@ export declare class ComputerDO extends NativeComputerDO implements ComputerFetc
|
|
|
214
215
|
protected attachedBackends(): readonly AttachedBackend[];
|
|
215
216
|
/** One advertised Computer tool, accepted against the host-issued grant. */
|
|
216
217
|
tool(authority: ComputerGrant, capabilityId: string, input: ComputerValue): Promise<StandaloneComputerResult>;
|
|
218
|
+
/** Public REST reuses native receipts, process retention and files; it owns no store. */
|
|
219
|
+
apiOperation(authority: ComputerGrant, request: ComputerApiRequest): Promise<StandaloneComputerResult | Readonly<{
|
|
220
|
+
error: "too_large" | "unavailable" | "denied";
|
|
221
|
+
}>>;
|
|
217
222
|
/** JSON operations keep the Computer's maintained parsers and execution engine. */
|
|
218
223
|
value(authority: ComputerGrant, action: ComputerAction, input: ComputerValue, executionContext?: ComputerValue): Promise<StandaloneComputerResult>;
|
|
219
224
|
fileList(authority: ComputerGrant, path: string, limit: number, offset: number): Promise<{
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { agentWorkspacePath } from "@fungi.computer/computer/files";
|
|
2
2
|
import { PortAccessError } from "@fungi.computer/computer/port-access";
|
|
3
|
+
import { ComputerFileTooLargeError, ComputerProcessNotFoundError, ComputerPortReservedError, maximumFileBytes, genericComputerExecutionBudget, } from "@fungi.computer/computer-contract";
|
|
4
|
+
import { computerApiRequestSchema, } from "../computer-api.js";
|
|
3
5
|
import { attachedBackendId, computerSizeSchema, defaultComputerSize, hostedBackingSchema, } from "@fungi.computer/computer/backing";
|
|
4
6
|
import { appMethodRefusalStatus, appMethodRefusedReplySchema, } from "@fungi.computer/agar/backend";
|
|
5
7
|
import * as Schema from "effect/Schema";
|
|
@@ -578,6 +580,61 @@ export class ComputerDO extends NativeComputerDO {
|
|
|
578
580
|
: undefined;
|
|
579
581
|
return output.parse(await this.callAfterAcceptance(tool, input, accept, vault));
|
|
580
582
|
}
|
|
583
|
+
/** Public REST reuses native receipts, process retention and files; it owns no store. */
|
|
584
|
+
async apiOperation(authority, request) {
|
|
585
|
+
try {
|
|
586
|
+
const parsed = Schema.decodeUnknownSync(computerApiRequestSchema, {
|
|
587
|
+
onExcessProperty: "error",
|
|
588
|
+
})(request);
|
|
589
|
+
switch (parsed.operation) {
|
|
590
|
+
case "exec":
|
|
591
|
+
return await this.executeOperationAfterAcceptance({ ...parsed.input, timeoutMs: parsed.input.timeoutMs ?? 10_000 }, () => {
|
|
592
|
+
this.#accept(authority, "exec");
|
|
593
|
+
}, "exec", genericComputerExecutionBudget);
|
|
594
|
+
case "start":
|
|
595
|
+
return await this.value(authority, "processStart", {
|
|
596
|
+
...parsed.input,
|
|
597
|
+
requestScope: `rest:${authority.provenance.actor}`,
|
|
598
|
+
});
|
|
599
|
+
case "logs":
|
|
600
|
+
return await this.value(authority, "processLogs", parsed.input);
|
|
601
|
+
case "kill":
|
|
602
|
+
return await this.value(authority, "processKill", parsed.input);
|
|
603
|
+
case "read":
|
|
604
|
+
return readOutputSchema.parse(await this.callAfterAcceptance("read", parsed.input, () => {
|
|
605
|
+
this.#accept(authority, "files.read");
|
|
606
|
+
}));
|
|
607
|
+
case "write":
|
|
608
|
+
if (new TextEncoder().encode(parsed.input.content).byteLength >
|
|
609
|
+
maximumFileBytes)
|
|
610
|
+
return { error: "too_large" };
|
|
611
|
+
return await this.value(authority, "files.write", parsed.input);
|
|
612
|
+
case "list":
|
|
613
|
+
return await this.value(authority, "files.list", parsed.input);
|
|
614
|
+
case "remove":
|
|
615
|
+
return await this.value(authority, "files.remove", parsed.input);
|
|
616
|
+
case "expose":
|
|
617
|
+
return await this.value(authority, "exposePort", parsed.input);
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
catch (cause) {
|
|
621
|
+
if (cause instanceof ComputerFileTooLargeError)
|
|
622
|
+
return { error: "too_large" };
|
|
623
|
+
if (cause instanceof ComputerProcessNotFoundError ||
|
|
624
|
+
missingFile.safeParse(cause).success)
|
|
625
|
+
return { error: "not_found" };
|
|
626
|
+
if (cause instanceof z.ZodError ||
|
|
627
|
+
Schema.isSchemaError(cause) ||
|
|
628
|
+
cause instanceof ComputerPortReservedError)
|
|
629
|
+
return { error: "invalid" };
|
|
630
|
+
if (cause instanceof ComputerOperationConflictError ||
|
|
631
|
+
cause instanceof ComputerPortConflictError)
|
|
632
|
+
return { error: "conflict" };
|
|
633
|
+
if (cause instanceof FleetGrantRefused)
|
|
634
|
+
return { error: "denied" };
|
|
635
|
+
return { error: "unavailable" };
|
|
636
|
+
}
|
|
637
|
+
}
|
|
581
638
|
/** JSON operations keep the Computer's maintained parsers and execution engine. */
|
|
582
639
|
async value(authority, action, input, executionContext) {
|
|
583
640
|
// Only an exact public grant rides along, and only on a native command.
|
|
@@ -12,6 +12,6 @@ import { type AppSourceBindingEnv } from "./app-source.js";
|
|
|
12
12
|
import type { StandaloneComputerEnv } from "./computer.js";
|
|
13
13
|
import type { StandaloneWorkflowEnv } from "./workflows.js";
|
|
14
14
|
/** The bindings the standalone owner routes reach, resolved per request. */
|
|
15
|
-
export type StandaloneOwnerRoutesEnv = AppSourceBindingEnv & Pick<StandaloneAgentsEnv, "AGENTS" | "OYSTER_ORIGIN"> & Pick<StandaloneComputerEnv, "REGISTRY"> & Pick<StandaloneAgentsEnv, "AGENT_DIRECTORY"> & Pick<StandaloneWorkflowEnv, "WORKFLOW_RUNS">;
|
|
15
|
+
export type StandaloneOwnerRoutesEnv = AppSourceBindingEnv & Pick<StandaloneAgentsEnv, "AGENTS" | "OYSTER_ORIGIN"> & Pick<StandaloneComputerEnv, "REGISTRY" | "COMPUTER"> & Pick<StandaloneAgentsEnv, "AGENT_DIRECTORY"> & Pick<StandaloneWorkflowEnv, "WORKFLOW_RUNS">;
|
|
16
16
|
/** Every owner route the standalone root adds to its tenant host. */
|
|
17
17
|
export declare function standaloneOwnerRoutes(env: StandaloneOwnerRoutesEnv, scope: TenantScope, hostFor: () => Promise<Pick<OysterHost, "installations">>): Routes<OysterEnv>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { standaloneComputerApiRoutes } from "./computer-api.js";
|
|
1
2
|
import { defaultTenant } from "../tenant.js";
|
|
2
3
|
import { agentDirectoryForScope } from "./agent-directory.js";
|
|
3
4
|
import { standaloneAgentComputerRoutes } from "./agent-computers.js";
|
|
@@ -16,6 +17,7 @@ export function standaloneOwnerRoutes(env, scope, hostFor) {
|
|
|
16
17
|
const owned = appSourceOwnerRoutes(env, scope)
|
|
17
18
|
.include(standaloneBuildRoutes(registry))
|
|
18
19
|
.include(trialStarterRoutes(registry))
|
|
20
|
+
.include(standaloneComputerApiRoutes(registry, (id) => env.COMPUTER.getByName(id)))
|
|
19
21
|
.include(standaloneComputerFleetRoutes(registry))
|
|
20
22
|
.include(standaloneAgentComputerRoutes({
|
|
21
23
|
attach: (principal, command) => directory().attachComputer(command, principal, scope.tenantId),
|
|
@@ -57,7 +57,7 @@ export declare abstract class StandaloneRegistry extends OysterRegistry implemen
|
|
|
57
57
|
state: "failed" | "installing" | "needs-runtime";
|
|
58
58
|
appId?: string | undefined;
|
|
59
59
|
reason?: {
|
|
60
|
-
code: "unknown" | "
|
|
60
|
+
code: "unknown" | "unsupported" | "build_failed" | "network";
|
|
61
61
|
message: string;
|
|
62
62
|
} | undefined;
|
|
63
63
|
}[]>;
|