Share dialogs pick-folder result schema across runtime and renderer
Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
1 parent
00896ff92b
commit
0a877b5a7e
4 files changed
+23
-10
No files matched your search
@@ -14,6 +14,7 @@ import {
|
||||
agentSessionIdSchema,
|
||||
appBootstrapResultSchema,
|
||||
appHealthResultSchema,
|
||||
dialogsPickFolderResultSchema,
|
||||
providerSessionListSchema,
|
||||
providerSessionSchema,
|
||||
providerTurnStartResultSchema,
|
||||
@@ -459,13 +460,8 @@ class WsNativeApiClient {
|
||||
remove: async (id) => this.requestParsed("todos.remove", todoListSchema, id),
|
||||
},
|
||||
dialogs: {
|
||||
pickFolder: async () => {
|
||||
const value = await this.request("dialogs.pickFolder");
|
||||
if (value === null || typeof value === "string") {
|
||||
return value;
|
||||
}
|
||||
throw new Error("Runtime method 'dialogs.pickFolder' returned invalid response payload.");
|
||||
},
|
||||
pickFolder: async () =>
|
||||
this.requestParsed("dialogs.pickFolder", dialogsPickFolderResultSchema),
|
||||
},
|
||||
terminal: {
|
||||
run: async (input) => this.requestParsed("terminal.run", terminalCommandResultSchema, input),
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
DEFAULT_MODEL,
|
||||
appBootstrapResultSchema,
|
||||
appHealthResultSchema,
|
||||
dialogsPickFolderResultSchema,
|
||||
type ProviderSession,
|
||||
type WsClientMessage,
|
||||
type WsResponseMessage,
|
||||
@@ -47,7 +48,6 @@ const shellOpenInEditorInputSchema = z.object({
|
||||
cwd: z.string().min(1),
|
||||
editor: z.enum(EDITORS.map((entry) => entry.id) as [string, ...string[]]),
|
||||
});
|
||||
const pickFolderResultSchema = z.string().nullable();
|
||||
|
||||
interface RuntimeApiServerOptions {
|
||||
port: number;
|
||||
@@ -564,7 +564,8 @@ export async function startRuntimeApiServer(
|
||||
if (method === "todos.remove")
|
||||
return todoListSchema.parse(await todoStore.remove(todoIdSchema.parse(params)));
|
||||
|
||||
if (method === "dialogs.pickFolder") return pickFolderResultSchema.parse(await pickFolder());
|
||||
if (method === "dialogs.pickFolder")
|
||||
return dialogsPickFolderResultSchema.parse(await pickFolder());
|
||||
if (method === "terminal.run") {
|
||||
return terminalCommandResultSchema.parse(
|
||||
await runTerminalCommand(terminalCommandInputSchema.parse(params), launchCwd),
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { appBootstrapResultSchema, appHealthResultSchema } from "./ipc";
|
||||
import {
|
||||
appBootstrapResultSchema,
|
||||
appHealthResultSchema,
|
||||
dialogsPickFolderResultSchema,
|
||||
} from "./ipc";
|
||||
|
||||
describe("appBootstrapResultSchema", () => {
|
||||
it("accepts valid bootstrap payloads", () => {
|
||||
@@ -95,3 +99,14 @@ describe("appHealthResultSchema", () => {
|
||||
).toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe("dialogsPickFolderResultSchema", () => {
|
||||
it("accepts null and string folder selections", () => {
|
||||
expect(dialogsPickFolderResultSchema.parse(null)).toBeNull();
|
||||
expect(dialogsPickFolderResultSchema.parse("/workspace")).toBe("/workspace");
|
||||
});
|
||||
|
||||
it("rejects non-string non-null selections", () => {
|
||||
expect(() => dialogsPickFolderResultSchema.parse(123)).toThrow();
|
||||
});
|
||||
});
|
||||
@@ -36,6 +36,7 @@ export const appHealthResultSchema = z.object({
|
||||
sessionCount: z.number().int().min(0),
|
||||
activeClientConnected: z.boolean(),
|
||||
});
|
||||
export const dialogsPickFolderResultSchema = z.string().nullable();
|
||||
|
||||
export type AppBootstrapResult = z.infer<typeof appBootstrapResultSchema>;
|
||||
export type AppHealthResult = z.infer<typeof appHealthResultSchema>;
|
||||
|
||||
Reference in new issue
Block a user