Skip to content

Commit c9a3aea

Browse files
working rest client
1 parent 25035bb commit c9a3aea

File tree

15 files changed

+680
-176
lines changed

15 files changed

+680
-176
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Generated stuff
44
dist
55
tests
6+
test.ts
67

78
### macOS ###
89
*.DS_Store

openapi-sandbox.json

Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
{
2+
"openapi": "3.0.0",
3+
"info": {
4+
"title": "Sandbox API",
5+
"description": "API for interacting with sandbox",
6+
"version": "1.0.0"
7+
},
8+
"paths": {
9+
"/fs/writefile": {
10+
"post": {
11+
"summary": "Write to a file",
12+
"description": "Write content to a file at the specified path",
13+
"operationId": "writeFile",
14+
"requestBody": {
15+
"required": true,
16+
"content": {
17+
"application/json": {
18+
"schema": {
19+
"$ref": "#/components/schemas/WriteFileRequest"
20+
}
21+
}
22+
}
23+
},
24+
"responses": {
25+
"200": {
26+
"description": "Successful operation",
27+
"content": {
28+
"application/json": {
29+
"schema": {
30+
"allOf": [
31+
{
32+
"$ref": "#/components/schemas/SuccessResponse"
33+
},
34+
{
35+
"type": "object",
36+
"properties": {
37+
"result": {
38+
"type": "object",
39+
"properties": {}
40+
}
41+
}
42+
}
43+
]
44+
}
45+
}
46+
}
47+
},
48+
"400": {
49+
"description": "Error writing file",
50+
"content": {
51+
"application/json": {
52+
"schema": {
53+
"allOf": [
54+
{
55+
"$ref": "#/components/schemas/ErrorResponse"
56+
},
57+
{
58+
"type": "object",
59+
"properties": {
60+
"error": {
61+
"oneOf": [
62+
{
63+
"$ref": "#/components/schemas/DefaultError"
64+
},
65+
{
66+
"$ref": "#/components/schemas/RawFsError"
67+
}
68+
],
69+
"discriminator": {
70+
"propertyName": "code"
71+
}
72+
}
73+
}
74+
}
75+
]
76+
}
77+
}
78+
}
79+
}
80+
}
81+
}
82+
}
83+
},
84+
"components": {
85+
"schemas": {
86+
"SuccessResponse": {
87+
"type": "object",
88+
"properties": {
89+
"status": {
90+
"type": "number",
91+
"enum": [0],
92+
"description": "Status code for successful operations"
93+
},
94+
"result": {
95+
"type": "object",
96+
"description": "Result payload for the operation"
97+
}
98+
},
99+
"required": ["status", "result"]
100+
},
101+
"ErrorResponse": {
102+
"type": "object",
103+
"properties": {
104+
"status": {
105+
"type": "number",
106+
"enum": [1],
107+
"description": "Status code for error operations"
108+
},
109+
"error": {
110+
"oneOf": [
111+
{
112+
"$ref": "#/components/schemas/DefaultError"
113+
},
114+
{
115+
"$ref": "#/components/schemas/RawFsError"
116+
}
117+
],
118+
"discriminator": {
119+
"propertyName": "code"
120+
}
121+
}
122+
},
123+
"required": ["status", "error"]
124+
},
125+
"DefaultError": {
126+
"type": "object",
127+
"properties": {
128+
"code": {
129+
"$ref": "#/components/schemas/PitcherErrorCode",
130+
"description": "Error code identifying the type of error"
131+
},
132+
"data": {
133+
"type": "object",
134+
"description": "Additional error details",
135+
"nullable": true
136+
},
137+
"publicMessage": {
138+
"type": "string",
139+
"description": "Human-readable error message that can be displayed to users",
140+
"nullable": true
141+
}
142+
},
143+
"required": ["code"]
144+
},
145+
"RawFsError": {
146+
"type": "object",
147+
"properties": {
148+
"code": {
149+
"type": "number",
150+
"enum": [102],
151+
"description": "RAWFS_ERROR code"
152+
},
153+
"data": {
154+
"type": "object",
155+
"properties": {
156+
"errno": {
157+
"type": ["number", "null"],
158+
"description": "File system error number, or null if not available"
159+
}
160+
},
161+
"required": ["errno"]
162+
},
163+
"publicMessage": {
164+
"type": "string",
165+
"description": "Human-readable error message that can be displayed to users",
166+
"nullable": true
167+
}
168+
},
169+
"required": ["code", "data"]
170+
},
171+
"PitcherErrorCode": {
172+
"type": "integer",
173+
"description": "Enumeration of error codes",
174+
"enum": [
175+
0, 1, 2, 3, 100, 101, 102, 200, 201, 204, 300, 400, 404, 410, 420,
176+
430, 440, 450, 460, 470, 500, 600, 601, 602, 704, 800, 801, 802, 803,
177+
814
178+
],
179+
"x-enum-descriptions": [
180+
"CRITICAL_ERROR",
181+
"FEATURE_UNAVAILABLE",
182+
"NO_ACCESS",
183+
"RATE_LIMIT",
184+
"INVALID_ID",
185+
"INVALID_PATH",
186+
"RAWFS_ERROR",
187+
"SHELL_NOT_ACCESSIBLE",
188+
"SHELL_CLOSED",
189+
"SHELL_NOT_FOUND",
190+
"MODEL_NOT_FOUND",
191+
"GIT_OPERATION_IN_PROGRESS",
192+
"GIT_REMOTE_FILE_NOT_FOUND",
193+
"GIT_FETCH_FAIL",
194+
"GIT_PULL_CONFLICT",
195+
"GIT_RESET_LOCAL_REMOTE_ERROR",
196+
"GIT_PUSH_FAIL",
197+
"GIT_RESET_CHECKOUT_INITIAL_BRANCH_FAIL",
198+
"GIT_PULL_FAIL",
199+
"GIT_TRANSPOSE_LINES_FAIL",
200+
"CHANNEL_NOT_FOUND",
201+
"CONFIG_FILE_ALREADY_EXISTS",
202+
"TASK_NOT_FOUND",
203+
"COMMAND_ALREADY_CONFIGURED",
204+
"COMMAND_NOT_FOUND",
205+
"AI_NOT_AVAILABLE",
206+
"PROMPT_TOO_BIG",
207+
"FAILED_TO_RESPOND",
208+
"AI_TOO_FREQUENT_REQUESTS",
209+
"AI_CHAT_NOT_FOUND"
210+
]
211+
},
212+
"WriteFileRequest": {
213+
"type": "object",
214+
"properties": {
215+
"path": {
216+
"type": "string",
217+
"description": "File path to write to"
218+
},
219+
"content": {
220+
"type": "string",
221+
"format": "binary",
222+
"description": "File content as binary data (Uint8Array)"
223+
},
224+
"create": {
225+
"type": "boolean",
226+
"description": "Whether to create the file if it doesn't exist",
227+
"default": false
228+
},
229+
"overwrite": {
230+
"type": "boolean",
231+
"description": "Whether to overwrite the file if it exists",
232+
"default": false
233+
}
234+
},
235+
"required": ["path", "content"]
236+
}
237+
}
238+
}
239+
}

package-lock.json

Lines changed: 24 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@
5757
"build:esbuild": "node esbuild.cjs",
5858
"build:cjs:types": "tsc -p ./tsconfig.build-cjs.json --emitDeclarationOnly",
5959
"build:esm:types": "tsc -p ./tsconfig.build-esm.json --emitDeclarationOnly",
60-
"build-openapi": "rimraf src/client && curl -o openapi.json https://api.codesandbox.io/meta/openapi && npx prettier --write ./openapi.json && node_modules/.bin/openapi-ts -i ./openapi.json -o src/client -c @hey-api/client-fetch",
60+
"build-openapi": "rimraf src/client && curl -o openapi.json https://api.codesandbox.io/meta/openapi && npx prettier --write ./openapi.json && node_modules/.bin/openapi-ts -i ./openapi.json -o src/client -c @hey-api/client-fetch && npm run build-openapi-rest",
6161
"build-openapi:staging": "rimraf src/client && curl -o openapi.json https://api.codesandbox.stream/meta/openapi && npx prettier --write ./openapi.json && node_modules/.bin/openapi-ts -i ./openapi.json -o src/client -c @hey-api/client-fetch",
62+
"build-openapi-rest": "node_modules/.bin/openapi-ts -i ./openapi-sandbox.json -o src/client-rest -c @hey-api/client-fetch",
6263
"clean": "rimraf ./dist",
6364
"typecheck": "tsc --noEmit",
6465
"format": "prettier '**/*.{md,js,jsx,json,ts,tsx}' --write",
@@ -103,5 +104,7 @@
103104
"why-is-node-running": "^2.3.0",
104105
"yargs": "^17.7.2"
105106
},
106-
"dependencies": {}
107+
"dependencies": {
108+
"@msgpack/msgpack": "^3.1.0"
109+
}
107110
}

0 commit comments

Comments
 (0)