Skip to content

Commit c2eeb94

Browse files
committed
Fix the JSON Error
1 parent 112b476 commit c2eeb94

5 files changed

Lines changed: 35 additions & 11 deletions

File tree

app/api/chat/route.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,24 @@ export const maxDuration = 300;
88
export async function POST(req: Request) {
99
const {
1010
message,
11+
mode,
1112
plannerModel,
1213
workerModel,
1314
sandboxProvider,
1415
repoUrl,
1516
} = await req.json();
1617

1718
const resolvedApiKey = process.env.GOOGLE_API_KEY || process.env.GOOGLE_GENERATIVE_AI_API_KEY;
18-
const useReal = !!resolvedApiKey && process.env.SIMULATION_MODE !== 'true';
19+
const realBlockedBySimulation = process.env.SIMULATION_MODE === 'true';
20+
const canUseReal = !!resolvedApiKey && !realBlockedBySimulation;
21+
const requestedMode = mode === 'real'
22+
? 'real'
23+
: mode === 'simulation'
24+
? 'simulation'
25+
: canUseReal
26+
? 'real'
27+
: 'simulation';
28+
const useReal = requestedMode === 'real' && canUseReal;
1929

2030
const config: VrlmConfig = {
2131
...DEFAULT_CONFIG,
@@ -35,6 +45,21 @@ export async function POST(req: Request) {
3545
controller.enqueue(encoder.encode(`data: ${JSON.stringify(event)}\n\n`));
3646
}
3747

48+
if (requestedMode === 'real' && !canUseReal) {
49+
const reason = !resolvedApiKey
50+
? 'GOOGLE_API_KEY is not set'
51+
: 'SIMULATION_MODE is true';
52+
53+
send({
54+
type: 'error',
55+
data: {
56+
message: `Real mode was requested, but ${reason}. The runtime never started, so no Docker sandboxes were created.`,
57+
},
58+
});
59+
controller.close();
60+
return;
61+
}
62+
3863
if (useReal) {
3964
const emitter = new VrlmEventEmitter();
4065
const runtime = new VrlmRuntime(emitter, config);

app/demo/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ export default function DemoPage() {
264264
headers: { 'Content-Type': 'application/json' },
265265
body: JSON.stringify({
266266
message,
267+
mode,
267268
sandboxProvider: settings.sandboxProvider,
268269
repoUrl: settings.repoUrl,
269270
plannerModel: settings.plannerModel,

lib/vrlm/runtime.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { generateText, stepCountIs, ToolLoopAgent } from 'ai';
1+
import { generateObject, generateText, stepCountIs, ToolLoopAgent } from 'ai';
22
import { z } from 'zod';
33
import { gateway } from '../gateway';
44
import { createAgentTools } from './tools';
@@ -143,17 +143,15 @@ export class VrlmRuntime {
143143
// ── Planner ─────────────────────────────────────────────────────────────────
144144

145145
private async runPlanner(goal: string): Promise<WorkerPlan> {
146-
const { text } = await generateText({
146+
const { object } = await generateObject({
147147
model: gateway(this.config.plannerModel, this.config.googleApiKey),
148148
system: PLANNER_SYSTEM_PROMPT,
149149
prompt: buildPlannerPrompt(goal),
150+
schema: WorkerPlanSchema,
151+
schemaName: 'WorkerPlan',
150152
maxOutputTokens: 2000,
151153
});
152-
153-
// Strip markdown code fences if model wrapped in ```json ... ```
154-
const clean = text.replace(/^```(?:json)?\n?/m, '').replace(/\n?```$/m, '').trim();
155-
const raw = JSON.parse(clean);
156-
return WorkerPlanSchema.parse(raw);
154+
return WorkerPlanSchema.parse(object);
157155
}
158156

159157
// ── Worker ──────────────────────────────────────────────────────────────────

packages/cli/package-lock.json

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

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "agentnetes",
3-
"version": "0.1.7",
3+
"version": "0.1.8",
44
"description": "Zero to a self-organizing AI agency. On demand.",
55
"keywords": [
66
"ai",

0 commit comments

Comments
 (0)