t3-code-android-nightly/packages/effect-acp/test/fixtures/acp-mock-peer.ts
Julius Marminge de34391427
feat(orchestrator): introduce new orchestrator (#2829)
Co-authored-by: maria-rcks <maria@kuuro.net>
Co-authored-by: Bilal Bakr <62337003+Bil0000@users.noreply.github.com>
Co-authored-by: shivam <91240327+shivamhwp@users.noreply.github.com>
Co-authored-by: Vitalii Yehorov <vitalyiegorov@gmail.com>
Co-authored-by: Jake Leventhal <jakeleventhal@me.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Alex Southwell <saphid@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Nicholas Wasmiller <derped@mineperial.com>
Co-authored-by: PB <poilmb@gmail.com>
Co-authored-by: Exotic <118054752+extoci@users.noreply.github.com>
Co-authored-by: Yash Singh <saiansh2525@gmail.com>
Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Theo Browne <me@t3.gg>
Co-authored-by: Gabriel De Andrade <30420087+gabrielelpidio@users.noreply.github.com>
Co-authored-by: Dara Adedeji <76637177+SunkenInTime@users.noreply.github.com>
Co-authored-by: scratchyone <scratchywon@gmail.com>
Co-authored-by: Dominic Roy <dominic@sdko.org>
Co-authored-by: chukfinley <chuk@chuk.dev>
Co-authored-by: Primož Ajdišek <bigpod@bigpod.si>
Co-authored-by: benthecarman <benthecarman@live.com>
Co-authored-by: NaveDanan <nave0712@gmail.com>
Co-authored-by: aaditagrawal <103925638+aaditagrawal@users.noreply.github.com>
Co-authored-by: Aditya Garud <153842990+yashranaway@users.noreply.github.com>
Co-authored-by: Nick Anisimov <n.anisimov.23@gmail.com>
Co-authored-by: MacKinley Smith <smithmackinley@gmail.com>
Co-authored-by: Yordis Prieto <yordis.prieto@gmail.com>
Co-authored-by: t3-code[bot] <269035359+t3-code[bot]@users.noreply.github.com>
Co-authored-by: AKolenda <akole779@mtroyal.ca>
Co-authored-by: Guillermo Casanova <75276669+Gigioxx@users.noreply.github.com>
Co-authored-by: Otavio Salvador <otavio@ossystems.com.br>
Co-authored-by: Shirish Pothi <183252392+shirishpothi@users.noreply.github.com>
Co-authored-by: Ishaan Kothari <ishaanko.mail@gmail.com>
Co-authored-by: Bob Fowler <bob@rjf.ca>
Co-authored-by: Anton Bezdenezhnykh <gamer392@yandex.ru>
Co-authored-by: ValeraZSD <48602572+ValeraZSD@users.noreply.github.com>
Co-authored-by: Ephraim <ephraim39hr14m@gmail.com>
Co-authored-by: Ryan Ilano <ryanilano@users.noreply.github.com>
Co-authored-by: Alex <me@pixp.cc>
Co-authored-by: maco <gosarmarcel7@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Tristan Knight <admin@snappeh.com>
Co-authored-by: PR Batch Tester <agent@local.test>
Co-authored-by: oliver <97427849+flamboh@users.noreply.github.com>
Co-authored-by: kamkm <99585688+Kamkmgamer@users.noreply.github.com>
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
2026-10-02 12:22:22 -07:00

242 lines
6.7 KiB
TypeScript

import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as NodeServices from "@effect/platform-node/NodeServices";
import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
import * as AcpAgent from "../../src/agent.ts";
if (process.env.ACP_MOCK_STDOUT_PREFIX !== undefined) {
process.stdout.write(process.env.ACP_MOCK_STDOUT_PREFIX);
}
if (process.env.ACP_MOCK_MALFORMED_OUTPUT === "1") {
process.stdout.write("{not-json}\n");
process.exit(Number(process.env.ACP_MOCK_MALFORMED_OUTPUT_EXIT_CODE ?? "0"));
}
if (process.env.ACP_MOCK_EXIT_IMMEDIATELY_CODE !== undefined) {
process.exit(Number(process.env.ACP_MOCK_EXIT_IMMEDIATELY_CODE));
}
const sessionId = "mock-session-1";
const v2Management = process.env.ACP_MOCK_V2_MANAGEMENT === "1";
const unknownVariants = process.env.ACP_MOCK_UNKNOWN_VARIANTS === "1";
const mcpOverAcp = process.env.ACP_MOCK_MCP_OVER_ACP === "1";
const program = Effect.gen(function* () {
const agent = yield* AcpAgent.AcpAgent;
yield* agent.handleInitialize(() =>
Effect.succeed({
protocolVersion: 2,
capabilities: {
session: {
...(v2Management ? { delete: {} } : {}),
...(mcpOverAcp ? { mcp: { acp: {} } } : {}),
},
...(v2Management ? { providers: {} } : {}),
},
info: {
name: "mock-agent",
version: "0.0.0",
},
...(process.env.ACP_MOCK_CUSTOM_AUTH === "1"
? { authMethods: [{ type: "custom_future", methodId: "custom", name: "Future auth" }] }
: {}),
...(process.env.ACP_MOCK_ENV_VAR_AUTH === "1"
? {
authMethods: [
{
type: "env_var",
methodId: "api_key",
name: "API key",
vars: [{ name: "MOCK_API_KEY", label: "Mock API key" }],
link: "https://example.test/keys",
},
],
}
: {}),
}),
);
yield* agent.handleAuthenticate(() => Effect.succeed({}));
yield* agent.handleLogout(() => Effect.succeed({}));
yield* agent.handleCreateSession(() =>
Effect.succeed({
sessionId,
}),
);
yield* agent.handleLoadSession(() => Effect.succeed({}));
yield* agent.handleListSessions(() =>
Effect.succeed({
sessions: [
{
sessionId,
cwd: process.cwd(),
},
],
}),
);
yield* agent.handleDeleteSession(() => Effect.succeed({}));
yield* agent.handleListProviders(() =>
Effect.succeed({
providers: [
{
providerId: "mock-provider",
supported: ["openai"],
required: false,
current: null,
},
],
}),
);
yield* agent.handleSetProvider(() => Effect.succeed({}));
yield* agent.handleDisableProvider(() => Effect.succeed({}));
yield* agent.handlePrompt(() =>
Effect.gen(function* () {
if (mcpOverAcp) {
const connected = yield* agent.client.connectMcp({ serverId: "t3-code" });
yield* agent.client.messageMcp({
connectionId: connected.connectionId,
method: "tools/list",
});
yield* agent.client.notifyMcp({
connectionId: connected.connectionId,
method: "notifications/initialized",
});
yield* agent.client.disconnectMcp({ connectionId: connected.connectionId });
}
if (unknownVariants) {
yield* agent.client.sessionUpdate({
sessionId,
update: {
sessionUpdate: "agent_message_chunk",
messageId: "future-content",
content: { type: "chart", points: [] },
},
});
yield* agent.client.sessionUpdate({
sessionId,
update: { sessionUpdate: "timeline_update", entries: [] },
});
}
yield* agent.client.requestPermission({
sessionId,
title: "Read project files",
options: [
{
optionId: "allow",
name: "Allow",
kind: "allow_once",
},
],
subject: {
type: "tool_call",
toolCall: {
toolCallId: "tool-1",
title: "Read project files",
},
},
});
yield* agent.client.elicit({
sessionId,
message: "Need confirmation before continuing.",
mode: "form",
requestedSchema: {
type: "object",
title: "Need confirmation",
properties: {
approved: {
type: "boolean",
title: "Approved",
},
},
required: ["approved"],
},
});
yield* agent.client.sessionUpdate({
sessionId,
update: {
sessionUpdate: "plan_update",
plan: {
type: "items",
planId: "mock-plan",
entries: [
{
content: "Inspect the repository",
priority: "high",
status: "in_progress",
},
],
},
},
});
if (process.env.ACP_MOCK_V2_DIFF === "1") {
yield* agent.client.sessionUpdate({
sessionId,
update: {
sessionUpdate: "tool_call_update",
toolCallId: "tool-diff",
content: [
{
type: "diff",
changes: [
{
operation: "move",
oldPath: "/workspace/old.ts",
path: "/workspace/new.ts",
fileType: "text",
mimeType: "text/typescript",
},
],
patch: {
format: "git_patch",
text: "diff --git a/old.ts b/new.ts\nsimilarity index 100%\nrename from old.ts\nrename to new.ts\n",
},
},
],
},
});
}
yield* agent.client.elicitationComplete({
elicitationId: "elicitation-1",
});
yield* agent.client.extRequest("x/typed_request", {
message: process.env.ACP_MOCK_BAD_TYPED_REQUEST === "1" ? 123 : "hello from typed request",
});
yield* agent.client.extNotification("x/typed_notification", {
count: 2,
});
yield* agent.client.sessionUpdate({
sessionId,
update: { sessionUpdate: "state_update", state: "idle", stopReason: "end_turn" },
});
return {};
}),
);
yield* agent.handleUnknownExtRequest((method, params) =>
Effect.succeed({
echoedMethod: method,
echoedParams: params ?? null,
}),
);
return yield* Effect.never;
});
program.pipe(
Effect.provide(Layer.provide(AcpAgent.layerStdio(), NodeServices.layer)),
NodeRuntime.runMain,
);