feat: integrate mobile work chat and Gitea delivery
This commit is contained in:
@@ -2,26 +2,27 @@ import { env } from "@code/env/server";
|
||||
import { Console, Effect, FiberSet, Result, Stream } from "effect";
|
||||
|
||||
import { makeAgentOsRuntime } from "./agent-os";
|
||||
import { ConvexControlPlane, type DaemonCommand } from "./convex";
|
||||
import { ConvexControlPlane } from "./convex";
|
||||
import type { DaemonCommand } from "./convex";
|
||||
|
||||
const errorMessage = (cause: unknown) =>
|
||||
cause instanceof Error ? cause.message : String(cause);
|
||||
|
||||
export const runDaemon = Effect.scoped(
|
||||
Effect.gen(function* () {
|
||||
Effect.gen(function* runDaemon() {
|
||||
const controlPlane = yield* ConvexControlPlane;
|
||||
const agentOs = yield* makeAgentOsRuntime;
|
||||
const sessionId = crypto.randomUUID();
|
||||
const hostname = yield* Effect.promise(() => import("node:os")).pipe(
|
||||
Effect.map((os) => os.hostname())
|
||||
);
|
||||
const fibers = yield* FiberSet.make<void>();
|
||||
const fibers = yield* FiberSet.make();
|
||||
|
||||
yield* controlPlane.connect({
|
||||
sessionId,
|
||||
architecture: process.arch,
|
||||
hostname,
|
||||
platform: process.platform,
|
||||
architecture: process.arch,
|
||||
sessionId,
|
||||
});
|
||||
yield* Console.log(`daemon ${env.DAEMON_ID} connected as ${sessionId}`);
|
||||
|
||||
@@ -40,33 +41,37 @@ export const runDaemon = Effect.scoped(
|
||||
Effect.forkScoped
|
||||
);
|
||||
|
||||
const processCommand = Effect.fn("Daemon.processCommand")(function* (
|
||||
candidate: DaemonCommand
|
||||
) {
|
||||
const command = yield* controlPlane.claim(candidate._id, sessionId);
|
||||
if (!command) {
|
||||
return;
|
||||
const processCommand = Effect.fn("Daemon.processCommand")(
|
||||
function* processCommand(candidate: DaemonCommand) {
|
||||
const command = yield* controlPlane.claim(candidate._id, sessionId);
|
||||
if (!command) {
|
||||
return;
|
||||
}
|
||||
const started = yield* controlPlane.start(command._id, sessionId);
|
||||
if (!started) {
|
||||
return;
|
||||
}
|
||||
yield* controlPlane.recordEvent({
|
||||
commandId: command._id,
|
||||
data: { actorKey: command.actorKey, method: command.method },
|
||||
kind: "command.started",
|
||||
});
|
||||
const result = yield* agentOs.execute(command).pipe(Effect.result);
|
||||
if (Result.isSuccess(result)) {
|
||||
yield* controlPlane.succeed(
|
||||
command._id,
|
||||
sessionId,
|
||||
result.success ?? null
|
||||
);
|
||||
return;
|
||||
}
|
||||
yield* controlPlane.fail(
|
||||
command._id,
|
||||
sessionId,
|
||||
errorMessage(result.failure)
|
||||
);
|
||||
}
|
||||
const started = yield* controlPlane.start(command._id, sessionId);
|
||||
if (!started) {
|
||||
return;
|
||||
}
|
||||
yield* controlPlane.recordEvent({
|
||||
commandId: command._id,
|
||||
kind: "command.started",
|
||||
data: { method: command.method, actorKey: command.actorKey },
|
||||
});
|
||||
const result = yield* agentOs.execute(command).pipe(Effect.result);
|
||||
if (Result.isSuccess(result)) {
|
||||
yield* controlPlane.succeed(command._id, sessionId, result.success);
|
||||
return;
|
||||
}
|
||||
yield* controlPlane.fail(
|
||||
command._id,
|
||||
sessionId,
|
||||
errorMessage(result.failure)
|
||||
);
|
||||
});
|
||||
);
|
||||
|
||||
yield* controlPlane.commands.pipe(
|
||||
Stream.runForEach((commands) =>
|
||||
|
||||
Reference in New Issue
Block a user