const { GOBARE_API: API, GOBARE_TOKEN: TOKEN } = process.env as Record<string, string>;
const AUTH = { Authorization: `Bearer ${TOKEN}`, "content-type": "application/json" };
async function call(method: string, path: string, body?: unknown) {
const response = await fetch(API + path, {
method,
headers: AUTH,
body: body === undefined ? undefined : JSON.stringify(body),
});
if (!response.ok) throw new Error(`${method} ${path} → ${response.status} ${await response.text()}`);
return response.json();
}
/** Send a message and wait for the round to finish. */
async function say(sessionId: string, text: string) {
await call("POST", `/v1/sessions/${sessionId}/events`, {
events: [{ type: "input.message", content: text }],
});
for (;;) {
const [turn] = (await call("GET", `/v1/sessions/${sessionId}/turns?limit=1`)).data;
if (turn && turn.status !== "working" && turn.artifacts !== "pending") return turn;
await new Promise((resolve) => setTimeout(resolve, 5000));
}
}
const session = await call("POST", "/v1/sessions", {
agent: {
model: "MiniMax-M3",
// True of every round. The task itself goes in the message.
instructions:
"Write TypeScript with explicit types. Run what you write before calling it done. " +
"Never ask the user a clarifying question: state your assumption and continue.",
},
});
console.log("session", session.id);
await say(session.id, "Build /workspace/robots.ts: a warehouse robot status API with " +
"GET /robots/:id/status returning battery and current task. Smoke test it.");
console.log("after round 1:", (await call("GET", `/v1/sessions/${session.id}`)).environment.state);
// …hours later, in a different process. All you kept was the session id.
await say(session.id, "Add test coverage for that API, including the case where the robot id does not exist.");
console.log("after round 2:", (await call("GET", `/v1/sessions/${session.id}`)).environment.state);
const { data: items } = await call("GET", `/v1/sessions/${session.id}/items?limit=200&order=asc`);
console.log(`${items.length} items across both rounds, one continuous record`);