@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.
@@ -90,13 +90,26 @@ export function createAppRegion(native, deliver) {
90
90
  };
91
91
  const connects = new Map();
92
92
  const regionFull = (reason) => Response.json({ error: "region_full", reason }, { status: 429 });
93
+ // Each socket's decoded host stamp, filled when connect stamps it or, after
94
+ // a hibernation wake, by the first read of its native attachment. Only the
95
+ // supervisor writes an attachment, once at admission, so a cached stamp
96
+ // never goes stale; connect and every reply then cost no parse per socket.
97
+ const stamps = new WeakMap();
98
+ const remember = (socket, connection, caller) => {
99
+ const stamp = { connection, caller, key: callerKey(caller) };
100
+ stamps.set(socket, stamp);
101
+ return stamp;
102
+ };
93
103
  const attachment = (socket) => {
104
+ const known = stamps.get(socket);
105
+ if (known !== undefined)
106
+ return known;
94
107
  const parsed = attachmentSchema.safeParse(socket.deserializeAttachment());
95
108
  if (!parsed.success)
96
109
  return null;
97
110
  const caller = appMethodCallerSchema.safeParse(parsed.data.caller);
98
111
  return caller.success
99
- ? { connection: parsed.data.connection, caller: caller.data }
112
+ ? remember(socket, parsed.data.connection, caller.data)
100
113
  : null;
101
114
  };
102
115
  const apply = async (raw) => {
@@ -153,10 +166,7 @@ export function createAppRegion(native, deliver) {
153
166
  if (sockets.length >= appRegionLimits.socketsPerInstance)
154
167
  return regionFull("Region socket limit reached");
155
168
  const key = callerKey(stamped);
156
- const held = sockets.filter((socket) => {
157
- const stamp = attachment(socket);
158
- return stamp !== null && callerKey(stamp.caller) === key;
159
- }).length;
169
+ const held = sockets.filter((socket) => attachment(socket)?.key === key).length;
160
170
  if (held >= appRegionLimits.socketsPerCaller)
161
171
  return regionFull("Region socket share reached");
162
172
  const now = native.now();
@@ -175,6 +185,7 @@ export function createAppRegion(native, deliver) {
175
185
  const connection = regionIds.connection.generate();
176
186
  native.accept(server);
177
187
  server.serializeAttachment({ connection, caller: stamped });
188
+ remember(server, connection, stamped);
178
189
  try {
179
190
  await apply(await deliverConnect({
180
191
  kind: "connect",
@@ -0,0 +1,397 @@
1
+ import * as Schema from "effect/Schema";
2
+ import * as z from "zod";
3
+ /** A `..` segment: paths stay whole-machine for the owner, but never ambiguous. */
4
+ export declare const computerApiDotSegment: RegExp;
5
+ /** HTTP envelopes are bounded before JSON parsing, including escaped file text. */
6
+ export declare const computerApiBodyBytes: number;
7
+ /** The inventory identity is independent of the currently selected UI Computer. */
8
+ export declare const computerApiId: Schema.String;
9
+ /** These schemas own the public wire grammar; OpenAPI is projected from them. */
10
+ export declare const computerApiInputs: {
11
+ exec: Schema.Struct<{
12
+ readonly requestId: Schema.String;
13
+ readonly timeoutMs: Schema.optionalKey<Schema.Int>;
14
+ readonly command: Schema.String;
15
+ readonly cwd: Schema.optionalKey<Schema.String>;
16
+ }>;
17
+ start: Schema.Struct<{
18
+ readonly requestId: Schema.String;
19
+ readonly command: Schema.String;
20
+ readonly cwd: Schema.optionalKey<Schema.String>;
21
+ }>;
22
+ logs: Schema.Struct<{
23
+ readonly id: Schema.String;
24
+ readonly lines: Schema.optionalKey<Schema.Int>;
25
+ }>;
26
+ kill: Schema.Struct<{
27
+ readonly id: Schema.String;
28
+ }>;
29
+ read: Schema.Struct<{
30
+ readonly path: Schema.String;
31
+ }>;
32
+ write: Schema.Struct<{
33
+ readonly path: Schema.String;
34
+ readonly content: Schema.String;
35
+ }>;
36
+ list: Schema.Struct<{
37
+ readonly path: Schema.optionalKey<Schema.String>;
38
+ readonly limit: Schema.optionalKey<Schema.Int>;
39
+ readonly offset: Schema.optionalKey<Schema.Int>;
40
+ }>;
41
+ remove: Schema.Struct<{
42
+ readonly path: Schema.String;
43
+ }>;
44
+ expose: Schema.Struct<{
45
+ readonly port: Schema.Int;
46
+ }>;
47
+ };
48
+ /** The native owner receives a closed, typed operation, never an arbitrary method name. */
49
+ export declare const computerApiRequestSchema: Schema.Union<readonly [Schema.Struct<{
50
+ readonly operation: Schema.Literal<"exec">;
51
+ readonly input: Schema.Struct<{
52
+ readonly requestId: Schema.String;
53
+ readonly timeoutMs: Schema.optionalKey<Schema.Int>;
54
+ readonly command: Schema.String;
55
+ readonly cwd: Schema.optionalKey<Schema.String>;
56
+ }>;
57
+ }>, Schema.Struct<{
58
+ readonly operation: Schema.Literal<"start">;
59
+ readonly input: Schema.Struct<{
60
+ readonly requestId: Schema.String;
61
+ readonly command: Schema.String;
62
+ readonly cwd: Schema.optionalKey<Schema.String>;
63
+ }>;
64
+ }>, Schema.Struct<{
65
+ readonly operation: Schema.Literal<"logs">;
66
+ readonly input: Schema.Struct<{
67
+ readonly id: Schema.String;
68
+ readonly lines: Schema.optionalKey<Schema.Int>;
69
+ }>;
70
+ }>, Schema.Struct<{
71
+ readonly operation: Schema.Literal<"kill">;
72
+ readonly input: Schema.Struct<{
73
+ readonly id: Schema.String;
74
+ }>;
75
+ }>, Schema.Struct<{
76
+ readonly operation: Schema.Literal<"read">;
77
+ readonly input: Schema.Struct<{
78
+ readonly path: Schema.String;
79
+ }>;
80
+ }>, Schema.Struct<{
81
+ readonly operation: Schema.Literal<"write">;
82
+ readonly input: Schema.Struct<{
83
+ readonly path: Schema.String;
84
+ readonly content: Schema.String;
85
+ }>;
86
+ }>, Schema.Struct<{
87
+ readonly operation: Schema.Literal<"list">;
88
+ readonly input: Schema.Struct<{
89
+ readonly path: Schema.optionalKey<Schema.String>;
90
+ readonly limit: Schema.optionalKey<Schema.Int>;
91
+ readonly offset: Schema.optionalKey<Schema.Int>;
92
+ }>;
93
+ }>, Schema.Struct<{
94
+ readonly operation: Schema.Literal<"remove">;
95
+ readonly input: Schema.Struct<{
96
+ readonly path: Schema.String;
97
+ }>;
98
+ }>, Schema.Struct<{
99
+ readonly operation: Schema.Literal<"expose">;
100
+ readonly input: Schema.Struct<{
101
+ readonly port: Schema.Int;
102
+ }>;
103
+ }>]>;
104
+ /** A decoded REST operation, with no caller-supplied authority. */
105
+ export type ComputerApiRequest = typeof computerApiRequestSchema.Type;
106
+ /** Shared REST operations for Oyster and the Team Computers OpenAPI document. */
107
+ export declare const computerApiOperations: readonly [{
108
+ readonly operation: "exec";
109
+ readonly method: "post";
110
+ readonly path: "/exec";
111
+ readonly action: "exec";
112
+ readonly output: z.ZodObject<{
113
+ requestId: z.ZodUUID;
114
+ status: z.ZodEnum<{
115
+ readonly accepted: "accepted";
116
+ readonly running: "running";
117
+ readonly succeeded: "succeeded";
118
+ readonly failed: "failed";
119
+ readonly unknown: "unknown";
120
+ readonly expired: "expired";
121
+ }>;
122
+ output: z.ZodNullable<z.ZodObject<{
123
+ status: z.ZodEnum<{
124
+ readonly completed: "completed";
125
+ readonly failed: "failed";
126
+ readonly cancelled: "cancelled";
127
+ }>;
128
+ exitCode: z.ZodNumber;
129
+ stdout: z.ZodString;
130
+ stderr: z.ZodString;
131
+ truncated: z.ZodUnion<readonly [z.ZodLiteral<false>, z.ZodArray<z.ZodObject<{
132
+ stream: z.ZodEnum<{
133
+ readonly stdout: "stdout";
134
+ readonly stderr: "stderr";
135
+ }>;
136
+ keptBytes: z.ZodNumber;
137
+ totalBytes: z.ZodNumber;
138
+ }, z.core.$strict>>]>;
139
+ }, z.core.$strict>>;
140
+ }, z.core.$strict>;
141
+ }, {
142
+ readonly operation: "start";
143
+ readonly method: "post";
144
+ readonly path: "/processes/start";
145
+ readonly action: "processStart";
146
+ readonly output: z.ZodObject<{
147
+ id: z.ZodLazy<z.ZodString & z.ZodType<import("@fungi.computer/cairn").CairnId<"computer-process", "process", 1>, string, z.core.$ZodTypeInternals<import("@fungi.computer/cairn").CairnId<"computer-process", "process", 1>, string>>>;
148
+ port: z.ZodNullable<z.ZodLazy<z.ZodNumber>>;
149
+ command: z.ZodString;
150
+ cwd: z.ZodNullable<z.ZodString>;
151
+ state: z.ZodEnum<{
152
+ readonly running: "running";
153
+ readonly exited: "exited";
154
+ readonly uncertain: "uncertain";
155
+ }>;
156
+ exitCode: z.ZodNullable<z.ZodNumber>;
157
+ sync: z.ZodEnum<{
158
+ readonly synced: "synced";
159
+ readonly pending: "pending";
160
+ readonly unknown: "unknown";
161
+ }>;
162
+ startedAt: z.ZodNumber;
163
+ endedAt: z.ZodNullable<z.ZodNumber>;
164
+ endedReason: z.ZodNullable<z.ZodLiteral<"idle-sleep">>;
165
+ }, z.core.$strict>;
166
+ }, {
167
+ readonly operation: "logs";
168
+ readonly method: "get";
169
+ readonly path: "/processes/logs";
170
+ readonly action: "processLogs";
171
+ readonly output: z.ZodObject<{
172
+ process: z.ZodObject<{
173
+ id: z.ZodLazy<z.ZodString & z.ZodType<import("@fungi.computer/cairn").CairnId<"computer-process", "process", 1>, string, z.core.$ZodTypeInternals<import("@fungi.computer/cairn").CairnId<"computer-process", "process", 1>, string>>>;
174
+ port: z.ZodNullable<z.ZodLazy<z.ZodNumber>>;
175
+ command: z.ZodString;
176
+ cwd: z.ZodNullable<z.ZodString>;
177
+ state: z.ZodEnum<{
178
+ readonly running: "running";
179
+ readonly exited: "exited";
180
+ readonly uncertain: "uncertain";
181
+ }>;
182
+ exitCode: z.ZodNullable<z.ZodNumber>;
183
+ sync: z.ZodEnum<{
184
+ readonly synced: "synced";
185
+ readonly pending: "pending";
186
+ readonly unknown: "unknown";
187
+ }>;
188
+ startedAt: z.ZodNumber;
189
+ endedAt: z.ZodNullable<z.ZodNumber>;
190
+ endedReason: z.ZodNullable<z.ZodLiteral<"idle-sleep">>;
191
+ }, z.core.$strict>;
192
+ lines: z.ZodArray<z.ZodString>;
193
+ truncated: z.ZodBoolean;
194
+ }, z.core.$strict>;
195
+ }, {
196
+ readonly operation: "kill";
197
+ readonly method: "post";
198
+ readonly path: "/processes/kill";
199
+ readonly action: "processKill";
200
+ readonly output: z.ZodLazy<z.ZodObject<{
201
+ process: z.ZodObject<{
202
+ id: z.ZodLazy<z.ZodString & z.ZodType<import("@fungi.computer/cairn").CairnId<"computer-process", "process", 1>, string, z.core.$ZodTypeInternals<import("@fungi.computer/cairn").CairnId<"computer-process", "process", 1>, string>>>;
203
+ port: z.ZodNullable<z.ZodLazy<z.ZodNumber>>;
204
+ command: z.ZodString;
205
+ cwd: z.ZodNullable<z.ZodString>;
206
+ state: z.ZodEnum<{
207
+ readonly running: "running";
208
+ readonly exited: "exited";
209
+ readonly uncertain: "uncertain";
210
+ }>;
211
+ exitCode: z.ZodNullable<z.ZodNumber>;
212
+ sync: z.ZodEnum<{
213
+ readonly synced: "synced";
214
+ readonly pending: "pending";
215
+ readonly unknown: "unknown";
216
+ }>;
217
+ startedAt: z.ZodNumber;
218
+ endedAt: z.ZodNullable<z.ZodNumber>;
219
+ endedReason: z.ZodNullable<z.ZodLiteral<"idle-sleep">>;
220
+ }, z.core.$strict>;
221
+ signalled: z.ZodBoolean;
222
+ }, z.core.$strict>>;
223
+ }, {
224
+ readonly operation: "read";
225
+ readonly method: "get";
226
+ readonly path: "/files";
227
+ readonly action: "files.read";
228
+ readonly output: z.ZodLazy<z.ZodObject<{
229
+ path: z.ZodString;
230
+ content: z.ZodString;
231
+ }, z.core.$strict>>;
232
+ }, {
233
+ readonly operation: "write";
234
+ readonly method: "put";
235
+ readonly path: "/files";
236
+ readonly action: "files.write";
237
+ readonly output: z.ZodLazy<z.ZodObject<{
238
+ path: z.ZodString;
239
+ bytes: z.ZodNumber;
240
+ }, z.core.$strict>>;
241
+ }, {
242
+ readonly operation: "list";
243
+ readonly method: "get";
244
+ readonly path: "/files/list";
245
+ readonly action: "files.list";
246
+ readonly output: z.ZodLazy<z.ZodObject<{
247
+ path: z.ZodString;
248
+ entries: z.ZodArray<z.ZodLazy<z.ZodObject<{
249
+ name: z.ZodString;
250
+ size: z.ZodNumber;
251
+ modifiedAt: z.ZodNumber;
252
+ type: z.ZodEnum<{
253
+ readonly file: "file";
254
+ readonly directory: "directory";
255
+ readonly symlink: "symlink";
256
+ }>;
257
+ }, z.core.$strict>>>;
258
+ nextOffset: z.ZodNullable<z.ZodNumber>;
259
+ }, z.core.$strict>>;
260
+ }, {
261
+ readonly operation: "remove";
262
+ readonly method: "delete";
263
+ readonly path: "/files";
264
+ readonly action: "files.remove";
265
+ readonly output: z.ZodObject<{
266
+ path: z.ZodString;
267
+ }, z.core.$strict>;
268
+ }, {
269
+ readonly operation: "expose";
270
+ readonly method: "post";
271
+ readonly path: "/ports";
272
+ readonly action: "exposePort";
273
+ readonly output: z.ZodLazy<z.ZodObject<{
274
+ port: z.ZodLazy<z.ZodNumber>;
275
+ exposed: z.ZodBoolean;
276
+ }, z.core.$strict>>;
277
+ }];
278
+ /** Project the same runtime request schema into the existing OpenAPI registry. */
279
+ export declare function computerApiInputDocument(operation: ComputerApiRequest["operation"]): import("effect/JsonSchema").JsonSchema;
280
+ /** Native Computer contracts continue to own their bounded response shapes. */
281
+ export declare function computerApiOutputDocument(operation: (typeof computerApiOperations)[number]): z.core.ZodStandardJSONSchemaPayload<z.ZodObject<{
282
+ requestId: z.ZodUUID;
283
+ status: z.ZodEnum<{
284
+ readonly accepted: "accepted";
285
+ readonly running: "running";
286
+ readonly succeeded: "succeeded";
287
+ readonly failed: "failed";
288
+ readonly unknown: "unknown";
289
+ readonly expired: "expired";
290
+ }>;
291
+ output: z.ZodNullable<z.ZodObject<{
292
+ status: z.ZodEnum<{
293
+ readonly completed: "completed";
294
+ readonly failed: "failed";
295
+ readonly cancelled: "cancelled";
296
+ }>;
297
+ exitCode: z.ZodNumber;
298
+ stdout: z.ZodString;
299
+ stderr: z.ZodString;
300
+ truncated: z.ZodUnion<readonly [z.ZodLiteral<false>, z.ZodArray<z.ZodObject<{
301
+ stream: z.ZodEnum<{
302
+ readonly stdout: "stdout";
303
+ readonly stderr: "stderr";
304
+ }>;
305
+ keptBytes: z.ZodNumber;
306
+ totalBytes: z.ZodNumber;
307
+ }, z.core.$strict>>]>;
308
+ }, z.core.$strict>>;
309
+ }, z.core.$strict> | z.ZodObject<{
310
+ id: z.ZodLazy<z.ZodString & z.ZodType<import("@fungi.computer/cairn").CairnId<"computer-process", "process", 1>, string, z.core.$ZodTypeInternals<import("@fungi.computer/cairn").CairnId<"computer-process", "process", 1>, string>>>;
311
+ port: z.ZodNullable<z.ZodLazy<z.ZodNumber>>;
312
+ command: z.ZodString;
313
+ cwd: z.ZodNullable<z.ZodString>;
314
+ state: z.ZodEnum<{
315
+ readonly running: "running";
316
+ readonly exited: "exited";
317
+ readonly uncertain: "uncertain";
318
+ }>;
319
+ exitCode: z.ZodNullable<z.ZodNumber>;
320
+ sync: z.ZodEnum<{
321
+ readonly synced: "synced";
322
+ readonly pending: "pending";
323
+ readonly unknown: "unknown";
324
+ }>;
325
+ startedAt: z.ZodNumber;
326
+ endedAt: z.ZodNullable<z.ZodNumber>;
327
+ endedReason: z.ZodNullable<z.ZodLiteral<"idle-sleep">>;
328
+ }, z.core.$strict> | z.ZodObject<{
329
+ process: z.ZodObject<{
330
+ id: z.ZodLazy<z.ZodString & z.ZodType<import("@fungi.computer/cairn").CairnId<"computer-process", "process", 1>, string, z.core.$ZodTypeInternals<import("@fungi.computer/cairn").CairnId<"computer-process", "process", 1>, string>>>;
331
+ port: z.ZodNullable<z.ZodLazy<z.ZodNumber>>;
332
+ command: z.ZodString;
333
+ cwd: z.ZodNullable<z.ZodString>;
334
+ state: z.ZodEnum<{
335
+ readonly running: "running";
336
+ readonly exited: "exited";
337
+ readonly uncertain: "uncertain";
338
+ }>;
339
+ exitCode: z.ZodNullable<z.ZodNumber>;
340
+ sync: z.ZodEnum<{
341
+ readonly synced: "synced";
342
+ readonly pending: "pending";
343
+ readonly unknown: "unknown";
344
+ }>;
345
+ startedAt: z.ZodNumber;
346
+ endedAt: z.ZodNullable<z.ZodNumber>;
347
+ endedReason: z.ZodNullable<z.ZodLiteral<"idle-sleep">>;
348
+ }, z.core.$strict>;
349
+ lines: z.ZodArray<z.ZodString>;
350
+ truncated: z.ZodBoolean;
351
+ }, z.core.$strict> | z.ZodLazy<z.ZodObject<{
352
+ process: z.ZodObject<{
353
+ id: z.ZodLazy<z.ZodString & z.ZodType<import("@fungi.computer/cairn").CairnId<"computer-process", "process", 1>, string, z.core.$ZodTypeInternals<import("@fungi.computer/cairn").CairnId<"computer-process", "process", 1>, string>>>;
354
+ port: z.ZodNullable<z.ZodLazy<z.ZodNumber>>;
355
+ command: z.ZodString;
356
+ cwd: z.ZodNullable<z.ZodString>;
357
+ state: z.ZodEnum<{
358
+ readonly running: "running";
359
+ readonly exited: "exited";
360
+ readonly uncertain: "uncertain";
361
+ }>;
362
+ exitCode: z.ZodNullable<z.ZodNumber>;
363
+ sync: z.ZodEnum<{
364
+ readonly synced: "synced";
365
+ readonly pending: "pending";
366
+ readonly unknown: "unknown";
367
+ }>;
368
+ startedAt: z.ZodNumber;
369
+ endedAt: z.ZodNullable<z.ZodNumber>;
370
+ endedReason: z.ZodNullable<z.ZodLiteral<"idle-sleep">>;
371
+ }, z.core.$strict>;
372
+ signalled: z.ZodBoolean;
373
+ }, z.core.$strict>> | z.ZodLazy<z.ZodObject<{
374
+ path: z.ZodString;
375
+ content: z.ZodString;
376
+ }, z.core.$strict>> | z.ZodLazy<z.ZodObject<{
377
+ path: z.ZodString;
378
+ bytes: z.ZodNumber;
379
+ }, z.core.$strict>> | z.ZodLazy<z.ZodObject<{
380
+ path: z.ZodString;
381
+ entries: z.ZodArray<z.ZodLazy<z.ZodObject<{
382
+ name: z.ZodString;
383
+ size: z.ZodNumber;
384
+ modifiedAt: z.ZodNumber;
385
+ type: z.ZodEnum<{
386
+ readonly file: "file";
387
+ readonly directory: "directory";
388
+ readonly symlink: "symlink";
389
+ }>;
390
+ }, z.core.$strict>>>;
391
+ nextOffset: z.ZodNullable<z.ZodNumber>;
392
+ }, z.core.$strict>> | z.ZodObject<{
393
+ path: z.ZodString;
394
+ }, z.core.$strict> | z.ZodLazy<z.ZodObject<{
395
+ port: z.ZodLazy<z.ZodNumber>;
396
+ exposed: z.ZodBoolean;
397
+ }, z.core.$strict>>>;
@@ -0,0 +1,157 @@
1
+ import * as Schema from "effect/Schema";
2
+ import * as z from "zod";
3
+ import { maximumCommandCharacters, maximumFileBytes, maximumListEntries, maximumProcessLogLines, genericComputerExecutionBudget, computerOperationResultSchema, computerProcessSchema, processLogsOutputSchema, processKillOutputSchema, readOutputSchema, writeOutputSchema, listOutputSchema, removeOutputSchema, computerPortOutputSchema, } from "@fungi.computer/computer-contract";
4
+ const text = (maximum) => Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(maximum));
5
+ const integer = (minimum, maximum) => Schema.Int.check(Schema.isBetween({ minimum, maximum }));
6
+ /** A `..` segment: paths stay whole-machine for the owner, but never ambiguous. */
7
+ export const computerApiDotSegment = /(?:^|\/)\.\.(?:\/|$)/u;
8
+ const path = text(4096).check(Schema.isPattern(/^(?!.*(?:^|\/)\.\.(?:\/|$))\/[^\0]*$/u));
9
+ const command = {
10
+ command: text(maximumCommandCharacters),
11
+ cwd: Schema.optionalKey(path),
12
+ };
13
+ /** HTTP envelopes are bounded before JSON parsing, including escaped file text. */
14
+ export const computerApiBodyBytes = maximumFileBytes * 6 + 8192;
15
+ /** The inventory identity is independent of the currently selected UI Computer. */
16
+ export const computerApiId = text(256);
17
+ /** These schemas own the public wire grammar; OpenAPI is projected from them. */
18
+ export const computerApiInputs = {
19
+ exec: Schema.Struct({
20
+ ...command,
21
+ requestId: Schema.String.check(Schema.isUUID(7)),
22
+ timeoutMs: Schema.optionalKey(integer(1, genericComputerExecutionBudget.maximumTimeMs)),
23
+ }),
24
+ start: Schema.Struct({ ...command, requestId: text(256) }),
25
+ logs: Schema.Struct({
26
+ id: text(256),
27
+ lines: Schema.optionalKey(integer(1, maximumProcessLogLines)),
28
+ }),
29
+ kill: Schema.Struct({ id: text(256) }),
30
+ read: Schema.Struct({ path }),
31
+ write: Schema.Struct({
32
+ path,
33
+ content: Schema.String.check(Schema.isMaxLength(maximumFileBytes)),
34
+ }),
35
+ list: Schema.Struct({
36
+ path: Schema.optionalKey(path),
37
+ limit: Schema.optionalKey(integer(1, maximumListEntries)),
38
+ offset: Schema.optionalKey(integer(0, Number.MAX_SAFE_INTEGER)),
39
+ }),
40
+ remove: Schema.Struct({ path }),
41
+ expose: Schema.Struct({ port: integer(1, 65535) }),
42
+ };
43
+ /** The native owner receives a closed, typed operation, never an arbitrary method name. */
44
+ export const computerApiRequestSchema = Schema.Union([
45
+ Schema.Struct({
46
+ operation: Schema.Literal("exec"),
47
+ input: computerApiInputs.exec,
48
+ }),
49
+ Schema.Struct({
50
+ operation: Schema.Literal("start"),
51
+ input: computerApiInputs.start,
52
+ }),
53
+ Schema.Struct({
54
+ operation: Schema.Literal("logs"),
55
+ input: computerApiInputs.logs,
56
+ }),
57
+ Schema.Struct({
58
+ operation: Schema.Literal("kill"),
59
+ input: computerApiInputs.kill,
60
+ }),
61
+ Schema.Struct({
62
+ operation: Schema.Literal("read"),
63
+ input: computerApiInputs.read,
64
+ }),
65
+ Schema.Struct({
66
+ operation: Schema.Literal("write"),
67
+ input: computerApiInputs.write,
68
+ }),
69
+ Schema.Struct({
70
+ operation: Schema.Literal("list"),
71
+ input: computerApiInputs.list,
72
+ }),
73
+ Schema.Struct({
74
+ operation: Schema.Literal("remove"),
75
+ input: computerApiInputs.remove,
76
+ }),
77
+ Schema.Struct({
78
+ operation: Schema.Literal("expose"),
79
+ input: computerApiInputs.expose,
80
+ }),
81
+ ]);
82
+ /** Shared REST operations for Oyster and the Team Computers OpenAPI document. */
83
+ export const computerApiOperations = [
84
+ {
85
+ operation: "exec",
86
+ method: "post",
87
+ path: "/exec",
88
+ action: "exec",
89
+ output: computerOperationResultSchema,
90
+ },
91
+ {
92
+ operation: "start",
93
+ method: "post",
94
+ path: "/processes/start",
95
+ action: "processStart",
96
+ output: computerProcessSchema,
97
+ },
98
+ {
99
+ operation: "logs",
100
+ method: "get",
101
+ path: "/processes/logs",
102
+ action: "processLogs",
103
+ output: processLogsOutputSchema,
104
+ },
105
+ {
106
+ operation: "kill",
107
+ method: "post",
108
+ path: "/processes/kill",
109
+ action: "processKill",
110
+ output: processKillOutputSchema,
111
+ },
112
+ {
113
+ operation: "read",
114
+ method: "get",
115
+ path: "/files",
116
+ action: "files.read",
117
+ output: readOutputSchema,
118
+ },
119
+ {
120
+ operation: "write",
121
+ method: "put",
122
+ path: "/files",
123
+ action: "files.write",
124
+ output: writeOutputSchema,
125
+ },
126
+ {
127
+ operation: "list",
128
+ method: "get",
129
+ path: "/files/list",
130
+ action: "files.list",
131
+ output: listOutputSchema,
132
+ },
133
+ {
134
+ operation: "remove",
135
+ method: "delete",
136
+ path: "/files",
137
+ action: "files.remove",
138
+ output: removeOutputSchema,
139
+ },
140
+ {
141
+ operation: "expose",
142
+ method: "post",
143
+ path: "/ports",
144
+ action: "exposePort",
145
+ output: computerPortOutputSchema,
146
+ },
147
+ ];
148
+ /** Project the same runtime request schema into the existing OpenAPI registry. */
149
+ export function computerApiInputDocument(operation) {
150
+ return Schema.toJsonSchemaDocument(computerApiInputs[operation], {
151
+ onExcessProperty: "error",
152
+ }).schema;
153
+ }
154
+ /** Native Computer contracts continue to own their bounded response shapes. */
155
+ export function computerApiOutputDocument(operation) {
156
+ return z.toJSONSchema(operation.output);
157
+ }
@@ -14,6 +14,23 @@ export type ComputerControlPort = Readonly<{
14
14
  state(computerId: string, context: InvocationContext): Promise<z.output<typeof computerStateSchema>>;
15
15
  /** Start one inventoried hosted Computer through the host's admission. */
16
16
  start(computerId: string, context: InvocationContext): Promise<z.output<typeof computerStateSchema>>;
17
+ /** Stop one Computer now; its files are kept. Only the signed-in owner may. */
18
+ stop(computerId: string, context: InvocationContext): Promise<{
19
+ kind: "stopped";
20
+ } | {
21
+ kind: "denied" | "busy" | "uncertain";
22
+ }>;
23
+ /**
24
+ * Delete one Computer and erase its Workspace. The caller has already matched
25
+ * the person's typed handle to the Computer's name. Only the signed-in owner
26
+ * may; a host with no delete path answers "unsupported". "uncertain" means
27
+ * retry: a delete cut short finishes on the next attempt.
28
+ */
29
+ delete(computerId: string, context: InvocationContext): Promise<{
30
+ kind: "deleted";
31
+ } | {
32
+ kind: "denied" | "unsupported" | "uncertain";
33
+ }>;
17
34
  /** Create or replay a durable receipt tied to this request identity. */
18
35
  create(input: z.output<typeof computerCreateRequestSchema>, context: InvocationContext): Promise<{
19
36
  kind: "created";