t3-code-android-nightly/packages/effect-codex-app-server/test/examples/codex-app-server-probe.ts
Julius Marminge ecfdda5fa8
refactor: layer variables are named layer or layerXyz (#16282)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-05 18:39:51 -07:00

67 lines
2 KiB
TypeScript

import * as Console from "effect/Console";
import * as Effect from "effect/Effect";
import { ChildProcess, ChildProcessSpawner } from "effect/process";
import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
import * as NodeServices from "@effect/platform-node/NodeServices";
import * as CodexClient from "../../src/client.ts";
const program = Effect.gen(function* () {
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
const handle = yield* spawner.spawn(
ChildProcess.make(process.env.CODEX_BIN ?? "codex", ["app-server"], {
cwd: process.cwd(),
shell: false,
}),
);
const layerCodex = CodexClient.layerChildProcess(handle, {
logIncoming: true,
logOutgoing: true,
});
yield* Effect.gen(function* () {
const client = yield* CodexClient.CodexAppServerClient;
yield* client.handleServerRequest("item/tool/requestUserInput", (payload) =>
Effect.succeed({
answers: Object.fromEntries(
payload.questions.map((question) => [
question.id,
{
answers:
question.options && question.options.length > 0
? [question.options[0]!.label]
: ["ok"],
},
]),
),
}),
);
const initialized = yield* client.request("initialize", {
clientInfo: {
name: "effect-codex-app-server-probe",
title: "Effect Codex App Server Probe",
version: "0.0.0",
},
capabilities: {
experimentalApi: true,
optOutNotificationMethods: null,
},
});
yield* Console.log("initialize", initialized);
yield* client.notify("initialized", undefined);
const account = yield* client.request("account/read", {});
yield* Console.log("account/read", account);
const skills = yield* client.request("skills/list", {
cwds: [process.cwd()],
});
yield* Console.log("skills/list", skills);
}).pipe(Effect.provide(layerCodex));
});
program.pipe(Effect.scoped, Effect.provide(NodeServices.layer), NodeRuntime.runMain);