Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
import * as NodeFS from "node:fs";
import * as NodeOS from "node:os";
import * as NodePath from "node:path";
import { ProviderDriverKind } from "@akeru/contracts";
import { it } from "@effect/vitest";
import * as Effect from "effect/Effect";
import { describe, expect } from "vite-plus/test";
import { AgentController } from "../Services/AgentController.ts";
import {
codexThreadId,
codexInstanceId,
codexSelection,
} from "./test-support/agentControllerFixtures.ts";
import {
makeBridge,
provideController,
resolveCodex,
} from "./test-support/agentControllerLayers.ts";
import { mastraHarnessFixture } from "./test-support/agentControllerHarness.ts";
describe("AgentControllerLive", () => {
it.effect("reads persisted image attachments for Mastra turns", () => {
const bridge = makeBridge();
const mastra = mastraHarnessFixture();
const baseDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "akeru-mastra-image-"));
const attachmentsDir = NodePath.join(baseDir, "userdata", "attachments");
NodeFS.mkdirSync(attachmentsDir, { recursive: true });
NodeFS.writeFileSync(NodePath.join(attachmentsDir, "image-1.png"), "image");
return provideController(
Effect.gen(function* () {
const controller = yield* AgentController;
yield* resolveCodex(controller);
yield* controller.startSession(codexThreadId, {
threadId: codexThreadId,
provider: ProviderDriverKind.make("codex"),
providerInstanceId: codexInstanceId,
cwd: process.cwd(),
modelSelection: codexSelection,
runtimeMode: "full-access",
});
yield* controller.sendTurn({
threadId: codexThreadId,
input: "Inspect this image.",
attachments: [
{
type: "image",
id: "image-1",
name: "screenshot.png",
mimeType: "image/png",
sizeBytes: 5,
},
],
});
expect(mastra.sendMessage).toHaveBeenCalledWith({
content: `Inspect this image.\n\n[Attached image "screenshot.png" is saved at: ${NodePath.join(attachmentsDir, "image-1.png")}]`,
files: [
{
data: "aW1hZ2U=",
mediaType: "image/png",
filename: "screenshot.png",
},
],
});
}).pipe(
Effect.ensuring(
Effect.sync(() => NodeFS.rmSync(baseDir, { recursive: true, force: true })),
),
),
bridge.service,
mastra.factory,
undefined,
baseDir,
);
});
});