Share agent.write input schema across runtime and contracts
Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
1 parent
ebd984dd4e
commit
a59108c31f
3 files changed
+40
-8
No files matched your search
@@ -2,7 +2,6 @@ import { spawn } from "node:child_process";
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { z } from "zod";
|
||||
import { WebSocket, WebSocketServer, type RawData } from "ws";
|
||||
|
||||
import {
|
||||
@@ -22,6 +21,7 @@ import {
|
||||
WS_CLOSE_REASONS,
|
||||
agentConfigSchema,
|
||||
agentSessionIdSchema,
|
||||
agentWriteInputSchema,
|
||||
newTodoInputSchema,
|
||||
todoIdSchema,
|
||||
providerInterruptTurnInputSchema,
|
||||
@@ -32,6 +32,7 @@ import {
|
||||
providerSessionSchema,
|
||||
providerStopSessionInputSchema,
|
||||
providerTurnStartResultSchema,
|
||||
type TerminalCommandInput,
|
||||
shellOpenInEditorInputSchema,
|
||||
terminalCommandResultSchema,
|
||||
terminalCommandInputSchema,
|
||||
@@ -43,11 +44,6 @@ import { ProcessManager } from "../../desktop/src/processManager";
|
||||
import { ProviderManager } from "../../desktop/src/providerManager";
|
||||
import { TodoStore } from "../../desktop/src/todoStore";
|
||||
|
||||
const agentWriteInputSchema = z.object({
|
||||
sessionId: z.string().min(1),
|
||||
data: z.string(),
|
||||
});
|
||||
|
||||
interface RuntimeApiServerOptions {
|
||||
port: number;
|
||||
launchCwd: string;
|
||||
@@ -258,7 +254,7 @@ async function pickFolder(): Promise<string | null> {
|
||||
}
|
||||
|
||||
async function runTerminalCommand(
|
||||
parsed: z.infer<typeof terminalCommandInputSchema>,
|
||||
parsed: TerminalCommandInput,
|
||||
defaultCwd: string,
|
||||
) {
|
||||
const providedCwd = parsed.cwd ?? defaultCwd;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { agentConfigSchema, agentExitSchema, outputChunkSchema } from "./agent";
|
||||
import { agentConfigSchema, agentExitSchema, agentWriteInputSchema, outputChunkSchema } from "./agent";
|
||||
|
||||
describe("agentConfigSchema", () => {
|
||||
it("accepts valid agent configs", () => {
|
||||
@@ -47,6 +47,34 @@ describe("outputChunkSchema", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("agentWriteInputSchema", () => {
|
||||
it("accepts valid write payloads", () => {
|
||||
const parsed = agentWriteInputSchema.parse({
|
||||
sessionId: "agent-1",
|
||||
data: "ping\n",
|
||||
});
|
||||
|
||||
expect(parsed.sessionId).toBe("agent-1");
|
||||
});
|
||||
|
||||
it("rejects invalid write payloads", () => {
|
||||
expect(() =>
|
||||
agentWriteInputSchema.parse({
|
||||
sessionId: "",
|
||||
data: "ping\n",
|
||||
}),
|
||||
).toThrow();
|
||||
|
||||
expect(() =>
|
||||
agentWriteInputSchema.parse({
|
||||
sessionId: "agent-1",
|
||||
data: "ping\n",
|
||||
unexpected: true,
|
||||
}),
|
||||
).toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe("agentExitSchema", () => {
|
||||
it("accepts exit payloads", () => {
|
||||
const parsed = agentExitSchema.parse({
|
||||
|
||||
@@ -10,6 +10,13 @@ export const agentConfigSchema = z.object({
|
||||
usePty: z.boolean().optional(),
|
||||
}).strict();
|
||||
|
||||
export const agentWriteInputSchema = z
|
||||
.object({
|
||||
sessionId: z.string().min(1),
|
||||
data: z.string(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
export const outputChunkSchema = z.object({
|
||||
sessionId: z.string(),
|
||||
stream: z.enum(["stdout", "stderr"]),
|
||||
@@ -23,5 +30,6 @@ export const agentExitSchema = z.object({
|
||||
}).strict();
|
||||
|
||||
export type AgentConfig = z.infer<typeof agentConfigSchema>;
|
||||
export type AgentWriteInput = z.infer<typeof agentWriteInputSchema>;
|
||||
export type OutputChunk = z.infer<typeof outputChunkSchema>;
|
||||
export type AgentExit = z.infer<typeof agentExitSchema>;
|
||||
Reference in new issue
Block a user