@fungi.computer/oyster 0.49.1 → 0.50.1

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.
@@ -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
+ }