Skip to content

Commit 43a494b

Browse files
committed
feat: start work on file reading and writing
1 parent a57f568 commit 43a494b

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

‎protocol/constants.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ export const COMMAND_TYPES = [
3939
"UPLOAD_BACKUP",
4040
"FETCH_LOGS",
4141
"FILES_LIST",
42+
"FILES_READ",
43+
"FILES_WRITE",
4244
"FILES_DELETE",
4345
"FILES_INSTALL_FROM_URL",
4446
] as const;

‎protocol/schemas.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,22 @@ const filesListCommand = z.object({
112112
payload: z.object({ path: z.string() }),
113113
type: z.literal("FILES_LIST"),
114114
});
115+
const filesReadCommand = z.object({
116+
id: z.string().min(1),
117+
issuedAt: z.string().datetime(),
118+
payload: z.object({ path: z.string().min(1) }),
119+
type: z.literal("FILES_READ"),
120+
});
121+
const filesWriteCommand = z.object({
122+
id: z.string().min(1),
123+
issuedAt: z.string().datetime(),
124+
payload: z.object({
125+
content: z.string(),
126+
encoding: z.enum(["utf-8", "base64"]).default("utf-8"),
127+
path: z.string().min(1),
128+
}),
129+
type: z.literal("FILES_WRITE"),
130+
});
115131
const filesDeleteCommand = z.object({
116132
id: z.string().min(1),
117133
issuedAt: z.string().datetime(),
@@ -141,6 +157,8 @@ export const commandSchema = z.discriminatedUnion("type", [
141157
uploadBackupCommand,
142158
fetchLogsCommand,
143159
filesListCommand,
160+
filesReadCommand,
161+
filesWriteCommand,
144162
filesDeleteCommand,
145163
filesInstallFromUrlCommand,
146164
]);
@@ -158,6 +176,16 @@ export const filesListResultSchema = z.object({
158176
path: z.string(),
159177
});
160178
export type FilesListResult = z.infer<typeof filesListResultSchema>;
179+
180+
export const filesReadResultSchema = z.object({
181+
content: z.string(),
182+
encoding: z.enum(["utf-8", "base64"]),
183+
path: z.string(),
184+
size: z.number().int().nonnegative(),
185+
truncated: z.boolean(),
186+
});
187+
export type FilesReadResult = z.infer<typeof filesReadResultSchema>;
188+
161189
export type Command = z.infer<typeof commandSchema>;
162190

163191
export const commandEnvelopeSchema = z.object({

0 commit comments

Comments
 (0)