Skip to content

Commit 7caa4d7

Browse files
author
Dylan Huang
committed
data is being set properly
1 parent 58d8150 commit 7caa4d7

File tree

6 files changed

+85
-191
lines changed

6 files changed

+85
-191
lines changed

eval_protocol/utils/logs_server.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import asyncio
2-
from contextlib import asynccontextmanager
32
import json
43
import logging
54
import os
65
import time
6+
from contextlib import asynccontextmanager
77
from typing import List, Optional
8-
from watchdog.events import FileSystemEventHandler, FileSystemEvent
9-
from watchdog.observers import Observer
108

119
import uvicorn
1210
from fastapi import FastAPI, WebSocket, WebSocketDisconnect
11+
from watchdog.events import FileSystemEvent, FileSystemEventHandler
12+
from watchdog.observers import Observer
1313

1414
from eval_protocol.dataset_logger import default_logger
1515
from eval_protocol.utils.vite_server import ViteServer
@@ -79,7 +79,9 @@ async def connect(self, websocket: WebSocket):
7979
logs = default_logger.read()
8080
asyncio.run_coroutine_threadsafe(
8181
websocket.send_text(
82-
json.dumps({"type": "initialize_logs", "logs": [log.model_dump_json() for log in logs]})
82+
json.dumps(
83+
{"type": "initialize_logs", "logs": [log.model_dump_json(exclude_none=True) for log in logs]}
84+
)
8385
),
8486
self._loop,
8587
)

vite-app/src/App.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@ import { useEffect, useRef } from "react";
22
import { makeAutoObservable } from "mobx";
33
import { observer } from "mobx-react";
44
import Dashboard from "./components/Dashboard";
5-
import type { EvaluationRow } from "./types/eval-protocol";
6-
interface FileUpdate {
7-
type: "file_changed" | "file_created" | "file_deleted";
8-
path: string;
9-
timestamp: string;
10-
}
5+
import { EvaluationRowSchema, type EvaluationRow } from "./types/eval-protocol";
6+
import { WebSocketServerMessageSchema } from "./types/websocket";
117

128
class GlobalState {
139
isConnected: boolean = false;
@@ -21,7 +17,7 @@ class GlobalState {
2117
}
2218
}
2319

24-
const state = new GlobalState();
20+
export const state = new GlobalState();
2521

2622
const BASE_DELAY = 1000; // 1 second
2723
const MAX_RECONNECT_ATTEMPTS = 5;
@@ -47,8 +43,15 @@ const App = observer(() => {
4743

4844
ws.onmessage = (event) => {
4945
try {
50-
const update: FileUpdate = JSON.parse(event.data);
51-
console.log(update);
46+
const update = WebSocketServerMessageSchema.parse(
47+
JSON.parse(event.data)
48+
);
49+
if (update.type === "initialize_logs") {
50+
const rows: EvaluationRow[] = update.logs.map((log) => {
51+
return EvaluationRowSchema.parse(JSON.parse(log));
52+
});
53+
state.setDataset(rows);
54+
}
5255
} catch (error) {
5356
console.error("Failed to parse WebSocket message:", error);
5457
}
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { observer } from "mobx-react";
2+
import { state } from "../App";
23

34
const Dashboard = observer(() => {
4-
return <div>Dashboard</div>;
5+
return (
6+
<div>
7+
Dashboard<div>{JSON.stringify(state.dataset)}</div>
8+
</div>
9+
);
510
});
611

712
export default Dashboard;

vite-app/src/types/eval-protocol-utils.ts

Lines changed: 0 additions & 176 deletions
This file was deleted.

vite-app/src/types/eval-protocol.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ export const EvaluationRowSchema = z.object({
8181
ground_truth: z.string().optional().describe('Optional ground truth reference for this evaluation.'),
8282
evaluation_result: EvaluateResultSchema.optional().describe('The evaluation result for this row/trajectory.'),
8383
usage: CompletionUsageSchema.optional().describe('Token usage statistics from LLM calls during execution.'),
84-
created_at: z.date().default(() => new Date()).describe('The timestamp when the row was created.')
84+
created_at: z.preprocess(
85+
(val) => typeof val === "string" ? new Date(val) : val,
86+
z.date()
87+
).describe('The timestamp when the row was created. Accepts string and parses to Date.')
8588
});
8689

8790
// Agent Evaluation Framework (V2) schemas

vite-app/src/types/websocket.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// WebSocket message types based on logs_server.py
2+
import { z } from 'zod';
3+
4+
// Zod Schemas for runtime validation
5+
6+
// File update message schema
7+
export const FileUpdateMessageSchema = z.object({
8+
type: z.enum(['file_created', 'file_changed', 'file_deleted']),
9+
path: z.string(),
10+
timestamp: z.number(),
11+
contents: z.string().nullable().optional(),
12+
});
13+
14+
// Initialize logs message schema
15+
export const InitializeLogsMessageSchema = z.object({
16+
type: z.literal('initialize_logs'),
17+
logs: z.array(z.string()),
18+
});
19+
20+
// Union schema for all WebSocket server messages
21+
export const WebSocketServerMessageSchema = z.discriminatedUnion('type', [
22+
FileUpdateMessageSchema,
23+
InitializeLogsMessageSchema,
24+
] as const);
25+
26+
// Server status response schema
27+
export const ServerStatusResponseSchema = z.object({
28+
status: z.literal('ok'),
29+
build_dir: z.string(),
30+
active_connections: z.number(),
31+
watch_paths: z.array(z.string()),
32+
});
33+
34+
// File system event schema
35+
export const FileSystemEventSchema = z.object({
36+
type: z.enum(['file_created', 'file_changed', 'file_deleted']),
37+
path: z.string(),
38+
timestamp: z.number(),
39+
contents: z.string().nullable().optional(),
40+
});
41+
42+
// Log entry schema
43+
export const LogEntrySchema = z.object({
44+
id: z.string(),
45+
timestamp: z.string(),
46+
level: z.enum(['DEBUG', 'INFO', 'WARNING', 'ERROR']),
47+
message: z.string(),
48+
metadata: z.record(z.string(), z.any()).optional(),
49+
});
50+
51+
// Type inference from Zod schemas
52+
export type FileUpdateMessage = z.infer<typeof FileUpdateMessageSchema>;
53+
export type InitializeLogsMessage = z.infer<typeof InitializeLogsMessageSchema>;
54+
export type WebSocketServerMessage = z.infer<typeof WebSocketServerMessageSchema>;
55+
export type ServerStatusResponse = z.infer<typeof ServerStatusResponseSchema>;
56+
export type FileSystemEvent = z.infer<typeof FileSystemEventSchema>;
57+
export type LogEntry = z.infer<typeof LogEntrySchema>;

0 commit comments

Comments
 (0)