Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2e8b8740a1 | ||
|
|
2afe2abe5e | ||
|
|
1c691e0ebb | ||
|
|
15f47dbd9b | ||
|
|
1bcfc88f58 | ||
|
|
2ba58076fa | ||
|
|
c27109cc20 |
No files matched your search
@@ -1,7 +1,8 @@
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { assert, it } from "@effect/vitest";
|
||||
import { assertSuccess } from "@effect/vitest/utils";
|
||||
import { FileSystem, Path, Effect } from "effect";
|
||||
import { FileSystem, Path, Effect, Sink, Stream } from "effect";
|
||||
import { ChildProcessSpawner } from "effect/unstable/process";
|
||||
|
||||
import {
|
||||
isCommandAvailable,
|
||||
@@ -475,20 +476,53 @@ it.layer(NodeServices.layer)("resolveEditorLaunch", (it) => {
|
||||
});
|
||||
|
||||
it.layer(NodeServices.layer)("launchDetached", (it) => {
|
||||
it.effect("resolves when command can be spawned", () =>
|
||||
it.effect("spawns through the Effect child process service", () =>
|
||||
Effect.gen(function* () {
|
||||
let capturedCommand: unknown;
|
||||
let unrefCalled = false;
|
||||
const spawner = ChildProcessSpawner.make((command) =>
|
||||
Effect.sync(() => {
|
||||
capturedCommand = command;
|
||||
return ChildProcessSpawner.makeHandle({
|
||||
pid: ChildProcessSpawner.ProcessId(123),
|
||||
exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(0)),
|
||||
isRunning: Effect.succeed(false),
|
||||
kill: () => Effect.void,
|
||||
unref: Effect.sync(() => {
|
||||
unrefCalled = true;
|
||||
return Effect.void;
|
||||
}),
|
||||
stdin: Sink.drain,
|
||||
stdout: Stream.empty,
|
||||
stderr: Stream.empty,
|
||||
all: Stream.empty,
|
||||
getInputFd: () => Sink.drain,
|
||||
getOutputFd: () => Stream.empty,
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
const result = yield* launchDetached({
|
||||
command: process.execPath,
|
||||
args: ["-e", "process.exit(0)"],
|
||||
}).pipe(Effect.result);
|
||||
}).pipe(
|
||||
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
|
||||
Effect.result,
|
||||
);
|
||||
|
||||
assertSuccess(result, undefined);
|
||||
assert.isTrue(unrefCalled);
|
||||
assert.deepInclude(capturedCommand as Record<string, unknown>, {
|
||||
command: process.execPath,
|
||||
args: ["-e", "process.exit(0)"],
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("rejects when command does not exist", () =>
|
||||
Effect.gen(function* () {
|
||||
const result = yield* launchDetached({
|
||||
command: `t3code-no-such-command-${Date.now()}`,
|
||||
command: "t3code-no-such-command-effect-child-process",
|
||||
args: [],
|
||||
}).pipe(Effect.result);
|
||||
assert.equal(result._tag, "Failure");
|
||||
|
||||
+43
-31
@@ -6,11 +6,10 @@
|
||||
*
|
||||
* @module Open
|
||||
*/
|
||||
import { spawn } from "node:child_process";
|
||||
|
||||
import { EDITORS, OpenError, type EditorId } from "@t3tools/contracts";
|
||||
import { isCommandAvailable, type CommandAvailabilityOptions } from "@t3tools/shared/shell";
|
||||
import { Context, Effect, Layer } from "effect";
|
||||
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
|
||||
|
||||
// ==============================
|
||||
// Definitions
|
||||
@@ -182,44 +181,54 @@ export const resolveEditorLaunch = Effect.fn("resolveEditorLaunch")(function* (
|
||||
return { command: fileManagerCommandForPlatform(platform), args: [input.cwd] };
|
||||
});
|
||||
|
||||
export const launchDetached = (launch: EditorLaunch) =>
|
||||
const launchDetachedWithSpawner = (
|
||||
launch: EditorLaunch,
|
||||
spawner: ChildProcessSpawner.ChildProcessSpawner["Service"],
|
||||
) =>
|
||||
Effect.gen(function* () {
|
||||
if (!isCommandAvailable(launch.command)) {
|
||||
return yield* new OpenError({ message: `Editor command not found: ${launch.command}` });
|
||||
}
|
||||
|
||||
yield* Effect.callback<void, OpenError>((resume) => {
|
||||
let child;
|
||||
try {
|
||||
yield* Effect.scoped(
|
||||
Effect.gen(function* () {
|
||||
const isWin32 = process.platform === "win32";
|
||||
child = spawn(
|
||||
launch.command,
|
||||
isWin32 ? launch.args.map((a) => `"${a}"`) : [...launch.args],
|
||||
{
|
||||
detached: true,
|
||||
stdio: "ignore",
|
||||
shell: isWin32,
|
||||
},
|
||||
const child = yield* spawner
|
||||
.spawn(
|
||||
ChildProcess.make(
|
||||
launch.command,
|
||||
isWin32 ? launch.args.map((a) => `"${a}"`) : [...launch.args],
|
||||
{
|
||||
detached: true,
|
||||
stdin: "ignore",
|
||||
stdout: "ignore",
|
||||
stderr: "ignore",
|
||||
shell: isWin32,
|
||||
},
|
||||
),
|
||||
)
|
||||
.pipe(
|
||||
Effect.mapError(
|
||||
(cause) => new OpenError({ message: "failed to spawn detached process", cause }),
|
||||
),
|
||||
);
|
||||
const _reref = yield* child.unref.pipe(
|
||||
Effect.mapError(
|
||||
(cause) => new OpenError({ message: "failed to unref detached process", cause }),
|
||||
),
|
||||
);
|
||||
} catch (error) {
|
||||
return resume(
|
||||
Effect.fail(new OpenError({ message: "failed to spawn detached process", cause: error })),
|
||||
);
|
||||
}
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
const handleSpawn = () => {
|
||||
child.unref();
|
||||
resume(Effect.void);
|
||||
};
|
||||
|
||||
child.once("spawn", handleSpawn);
|
||||
child.once("error", (cause) =>
|
||||
resume(Effect.fail(new OpenError({ message: "failed to spawn detached process", cause }))),
|
||||
);
|
||||
});
|
||||
export const launchDetached = (launch: EditorLaunch) =>
|
||||
Effect.gen(function* () {
|
||||
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
||||
return yield* launchDetachedWithSpawner(launch, spawner);
|
||||
});
|
||||
|
||||
const make = Effect.gen(function* () {
|
||||
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
||||
const open = yield* Effect.tryPromise({
|
||||
try: () => import("open"),
|
||||
catch: (cause) => new OpenError({ message: "failed to load browser opener", cause }),
|
||||
@@ -230,8 +239,11 @@ const make = Effect.gen(function* () {
|
||||
Effect.tryPromise({
|
||||
try: () => open.default(target),
|
||||
catch: (cause) => new OpenError({ message: "Browser auto-open failed", cause }),
|
||||
}),
|
||||
openInEditor: (input) => Effect.flatMap(resolveEditorLaunch(input), launchDetached),
|
||||
}).pipe(Effect.asVoid),
|
||||
openInEditor: (input) =>
|
||||
Effect.flatMap(resolveEditorLaunch(input), (launch) =>
|
||||
launchDetachedWithSpawner(launch, spawner),
|
||||
),
|
||||
} satisfies OpenShape;
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
import { CommandId, EventId, ProjectId } from "@t3tools/contracts";
|
||||
import { assert, it } from "@effect/vitest";
|
||||
import { DateTime, Duration, Effect, Random } from "effect";
|
||||
import { TestClock } from "effect/testing";
|
||||
|
||||
import { decideOrchestrationCommand } from "./decider.ts";
|
||||
import { createEmptyReadModel, projectEvent } from "./projector.ts";
|
||||
|
||||
const projectId = ProjectId.make("project-clock");
|
||||
const createdAt = "2026-01-01T00:00:00.000Z";
|
||||
const zeroRandomService = {
|
||||
nextIntUnsafe: () => 0,
|
||||
nextDoubleUnsafe: () => 0,
|
||||
};
|
||||
|
||||
it.effect("uses the Effect clock for generated project update timestamps", () =>
|
||||
Effect.gen(function* () {
|
||||
const readModel = yield* projectEvent(createEmptyReadModel(createdAt), {
|
||||
sequence: 1,
|
||||
eventId: EventId.make("evt-project-clock"),
|
||||
aggregateKind: "project",
|
||||
aggregateId: projectId,
|
||||
type: "project.created",
|
||||
occurredAt: createdAt,
|
||||
commandId: CommandId.make("cmd-project-clock-create"),
|
||||
causationEventId: null,
|
||||
correlationId: CommandId.make("cmd-project-clock-create"),
|
||||
metadata: {},
|
||||
payload: {
|
||||
projectId,
|
||||
title: "Clock",
|
||||
workspaceRoot: "/tmp/clock",
|
||||
defaultModelSelection: null,
|
||||
scripts: [],
|
||||
createdAt,
|
||||
updatedAt: createdAt,
|
||||
},
|
||||
});
|
||||
|
||||
yield* TestClock.adjust(Duration.seconds(5));
|
||||
const expectedNow = DateTime.formatIso(yield* DateTime.now);
|
||||
const result = yield* decideOrchestrationCommand({
|
||||
command: {
|
||||
type: "project.meta.update",
|
||||
commandId: CommandId.make("cmd-project-clock-update"),
|
||||
projectId,
|
||||
title: "Clock Updated",
|
||||
},
|
||||
readModel,
|
||||
});
|
||||
const events = Array.isArray(result) ? [...result] : [result];
|
||||
assert.lengthOf(events, 1);
|
||||
const event = events[0];
|
||||
if (!event) {
|
||||
assert.fail("expected a project meta-updated event");
|
||||
return;
|
||||
}
|
||||
if (event.type !== "project.meta-updated") {
|
||||
assert.fail(`expected project.meta-updated, received ${event.type}`);
|
||||
return;
|
||||
}
|
||||
|
||||
assert.equal(event.occurredAt, expectedNow);
|
||||
assert.equal(event.eventId, EventId.make("00000000-0000-4000-8000-000000000000"));
|
||||
assert.equal(event.payload.updatedAt, expectedNow);
|
||||
}).pipe(
|
||||
Effect.provide(TestClock.layer()),
|
||||
Effect.provideService(Random.Random, zeroRandomService),
|
||||
),
|
||||
);
|
||||
@@ -3,7 +3,7 @@ import type {
|
||||
OrchestrationEvent,
|
||||
OrchestrationReadModel,
|
||||
} from "@t3tools/contracts";
|
||||
import { Effect } from "effect";
|
||||
import { DateTime, Effect, Random } from "effect";
|
||||
|
||||
import { OrchestrationCommandInvariantError } from "./Errors.ts";
|
||||
import {
|
||||
@@ -17,15 +17,9 @@ import {
|
||||
} from "./commandInvariants.ts";
|
||||
import { projectEvent } from "./projector.ts";
|
||||
|
||||
const nowIso = () => new Date().toISOString();
|
||||
const defaultMetadata: Omit<OrchestrationEvent, "sequence" | "type" | "payload"> = {
|
||||
eventId: crypto.randomUUID() as OrchestrationEvent["eventId"],
|
||||
aggregateKind: "thread",
|
||||
aggregateId: "" as OrchestrationEvent["aggregateId"],
|
||||
occurredAt: nowIso(),
|
||||
commandId: null,
|
||||
const nowIso = Effect.map(DateTime.now, DateTime.formatIso);
|
||||
const defaultMetadata: Pick<OrchestrationEvent, "causationEventId" | "metadata"> = {
|
||||
causationEventId: null,
|
||||
correlationId: null,
|
||||
metadata: {},
|
||||
};
|
||||
|
||||
@@ -36,17 +30,17 @@ function withEventBase(
|
||||
readonly occurredAt: string;
|
||||
readonly metadata?: OrchestrationEvent["metadata"];
|
||||
},
|
||||
): Omit<OrchestrationEvent, "sequence" | "type" | "payload"> {
|
||||
return {
|
||||
): Effect.Effect<Omit<OrchestrationEvent, "sequence" | "type" | "payload">> {
|
||||
return Effect.map(Random.nextUUIDv4, (eventId) => ({
|
||||
...defaultMetadata,
|
||||
eventId: crypto.randomUUID() as OrchestrationEvent["eventId"],
|
||||
eventId: eventId as OrchestrationEvent["eventId"],
|
||||
aggregateKind: input.aggregateKind,
|
||||
aggregateId: input.aggregateId,
|
||||
occurredAt: input.occurredAt,
|
||||
commandId: input.commandId,
|
||||
correlationId: input.commandId,
|
||||
metadata: input.metadata ?? {},
|
||||
};
|
||||
}));
|
||||
}
|
||||
|
||||
type PlannedOrchestrationEvent = Omit<OrchestrationEvent, "sequence">;
|
||||
@@ -101,12 +95,12 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
});
|
||||
|
||||
return {
|
||||
...withEventBase({
|
||||
...(yield* withEventBase({
|
||||
aggregateKind: "project",
|
||||
aggregateId: command.projectId,
|
||||
occurredAt: command.createdAt,
|
||||
commandId: command.commandId,
|
||||
}),
|
||||
})),
|
||||
type: "project.created",
|
||||
payload: {
|
||||
projectId: command.projectId,
|
||||
@@ -126,14 +120,14 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
command,
|
||||
projectId: command.projectId,
|
||||
});
|
||||
const occurredAt = nowIso();
|
||||
const occurredAt = yield* nowIso;
|
||||
return {
|
||||
...withEventBase({
|
||||
...(yield* withEventBase({
|
||||
aggregateKind: "project",
|
||||
aggregateId: command.projectId,
|
||||
occurredAt,
|
||||
commandId: command.commandId,
|
||||
}),
|
||||
})),
|
||||
type: "project.meta-updated",
|
||||
payload: {
|
||||
projectId: command.projectId,
|
||||
@@ -183,14 +177,14 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
});
|
||||
}
|
||||
|
||||
const occurredAt = nowIso();
|
||||
const occurredAt = yield* nowIso;
|
||||
return {
|
||||
...withEventBase({
|
||||
...(yield* withEventBase({
|
||||
aggregateKind: "project",
|
||||
aggregateId: command.projectId,
|
||||
occurredAt,
|
||||
commandId: command.commandId,
|
||||
}),
|
||||
})),
|
||||
type: "project.deleted" as const,
|
||||
payload: {
|
||||
projectId: command.projectId,
|
||||
@@ -211,12 +205,12 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
threadId: command.threadId,
|
||||
});
|
||||
return {
|
||||
...withEventBase({
|
||||
...(yield* withEventBase({
|
||||
aggregateKind: "thread",
|
||||
aggregateId: command.threadId,
|
||||
occurredAt: command.createdAt,
|
||||
commandId: command.commandId,
|
||||
}),
|
||||
})),
|
||||
type: "thread.created",
|
||||
payload: {
|
||||
threadId: command.threadId,
|
||||
@@ -239,14 +233,14 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
command,
|
||||
threadId: command.threadId,
|
||||
});
|
||||
const occurredAt = nowIso();
|
||||
const occurredAt = yield* nowIso;
|
||||
return {
|
||||
...withEventBase({
|
||||
...(yield* withEventBase({
|
||||
aggregateKind: "thread",
|
||||
aggregateId: command.threadId,
|
||||
occurredAt,
|
||||
commandId: command.commandId,
|
||||
}),
|
||||
})),
|
||||
type: "thread.deleted",
|
||||
payload: {
|
||||
threadId: command.threadId,
|
||||
@@ -261,14 +255,14 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
command,
|
||||
threadId: command.threadId,
|
||||
});
|
||||
const occurredAt = nowIso();
|
||||
const occurredAt = yield* nowIso;
|
||||
return {
|
||||
...withEventBase({
|
||||
...(yield* withEventBase({
|
||||
aggregateKind: "thread",
|
||||
aggregateId: command.threadId,
|
||||
occurredAt,
|
||||
commandId: command.commandId,
|
||||
}),
|
||||
})),
|
||||
type: "thread.archived",
|
||||
payload: {
|
||||
threadId: command.threadId,
|
||||
@@ -284,14 +278,14 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
command,
|
||||
threadId: command.threadId,
|
||||
});
|
||||
const occurredAt = nowIso();
|
||||
const occurredAt = yield* nowIso;
|
||||
return {
|
||||
...withEventBase({
|
||||
...(yield* withEventBase({
|
||||
aggregateKind: "thread",
|
||||
aggregateId: command.threadId,
|
||||
occurredAt,
|
||||
commandId: command.commandId,
|
||||
}),
|
||||
})),
|
||||
type: "thread.unarchived",
|
||||
payload: {
|
||||
threadId: command.threadId,
|
||||
@@ -306,14 +300,14 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
command,
|
||||
threadId: command.threadId,
|
||||
});
|
||||
const occurredAt = nowIso();
|
||||
const occurredAt = yield* nowIso;
|
||||
return {
|
||||
...withEventBase({
|
||||
...(yield* withEventBase({
|
||||
aggregateKind: "thread",
|
||||
aggregateId: command.threadId,
|
||||
occurredAt,
|
||||
commandId: command.commandId,
|
||||
}),
|
||||
})),
|
||||
type: "thread.meta-updated",
|
||||
payload: {
|
||||
threadId: command.threadId,
|
||||
@@ -334,14 +328,14 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
command,
|
||||
threadId: command.threadId,
|
||||
});
|
||||
const occurredAt = nowIso();
|
||||
const occurredAt = yield* nowIso;
|
||||
return {
|
||||
...withEventBase({
|
||||
...(yield* withEventBase({
|
||||
aggregateKind: "thread",
|
||||
aggregateId: command.threadId,
|
||||
occurredAt,
|
||||
commandId: command.commandId,
|
||||
}),
|
||||
})),
|
||||
type: "thread.runtime-mode-set",
|
||||
payload: {
|
||||
threadId: command.threadId,
|
||||
@@ -357,14 +351,14 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
command,
|
||||
threadId: command.threadId,
|
||||
});
|
||||
const occurredAt = nowIso();
|
||||
const occurredAt = yield* nowIso;
|
||||
return {
|
||||
...withEventBase({
|
||||
...(yield* withEventBase({
|
||||
aggregateKind: "thread",
|
||||
aggregateId: command.threadId,
|
||||
occurredAt,
|
||||
commandId: command.commandId,
|
||||
}),
|
||||
})),
|
||||
type: "thread.interaction-mode-set",
|
||||
payload: {
|
||||
threadId: command.threadId,
|
||||
@@ -405,12 +399,12 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
});
|
||||
}
|
||||
const userMessageEvent: Omit<OrchestrationEvent, "sequence"> = {
|
||||
...withEventBase({
|
||||
...(yield* withEventBase({
|
||||
aggregateKind: "thread",
|
||||
aggregateId: command.threadId,
|
||||
occurredAt: command.createdAt,
|
||||
commandId: command.commandId,
|
||||
}),
|
||||
})),
|
||||
type: "thread.message-sent",
|
||||
payload: {
|
||||
threadId: command.threadId,
|
||||
@@ -425,12 +419,12 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
},
|
||||
};
|
||||
const turnStartRequestedEvent: Omit<OrchestrationEvent, "sequence"> = {
|
||||
...withEventBase({
|
||||
...(yield* withEventBase({
|
||||
aggregateKind: "thread",
|
||||
aggregateId: command.threadId,
|
||||
occurredAt: command.createdAt,
|
||||
commandId: command.commandId,
|
||||
}),
|
||||
})),
|
||||
causationEventId: userMessageEvent.eventId,
|
||||
type: "thread.turn-start-requested",
|
||||
payload: {
|
||||
@@ -456,12 +450,12 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
threadId: command.threadId,
|
||||
});
|
||||
return {
|
||||
...withEventBase({
|
||||
...(yield* withEventBase({
|
||||
aggregateKind: "thread",
|
||||
aggregateId: command.threadId,
|
||||
occurredAt: command.createdAt,
|
||||
commandId: command.commandId,
|
||||
}),
|
||||
})),
|
||||
type: "thread.turn-interrupt-requested",
|
||||
payload: {
|
||||
threadId: command.threadId,
|
||||
@@ -478,7 +472,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
threadId: command.threadId,
|
||||
});
|
||||
return {
|
||||
...withEventBase({
|
||||
...(yield* withEventBase({
|
||||
aggregateKind: "thread",
|
||||
aggregateId: command.threadId,
|
||||
occurredAt: command.createdAt,
|
||||
@@ -486,7 +480,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
metadata: {
|
||||
requestId: command.requestId,
|
||||
},
|
||||
}),
|
||||
})),
|
||||
type: "thread.approval-response-requested",
|
||||
payload: {
|
||||
threadId: command.threadId,
|
||||
@@ -504,7 +498,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
threadId: command.threadId,
|
||||
});
|
||||
return {
|
||||
...withEventBase({
|
||||
...(yield* withEventBase({
|
||||
aggregateKind: "thread",
|
||||
aggregateId: command.threadId,
|
||||
occurredAt: command.createdAt,
|
||||
@@ -512,7 +506,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
metadata: {
|
||||
requestId: command.requestId,
|
||||
},
|
||||
}),
|
||||
})),
|
||||
type: "thread.user-input-response-requested",
|
||||
payload: {
|
||||
threadId: command.threadId,
|
||||
@@ -530,12 +524,12 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
threadId: command.threadId,
|
||||
});
|
||||
return {
|
||||
...withEventBase({
|
||||
...(yield* withEventBase({
|
||||
aggregateKind: "thread",
|
||||
aggregateId: command.threadId,
|
||||
occurredAt: command.createdAt,
|
||||
commandId: command.commandId,
|
||||
}),
|
||||
})),
|
||||
type: "thread.checkpoint-revert-requested",
|
||||
payload: {
|
||||
threadId: command.threadId,
|
||||
@@ -552,12 +546,12 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
threadId: command.threadId,
|
||||
});
|
||||
return {
|
||||
...withEventBase({
|
||||
...(yield* withEventBase({
|
||||
aggregateKind: "thread",
|
||||
aggregateId: command.threadId,
|
||||
occurredAt: command.createdAt,
|
||||
commandId: command.commandId,
|
||||
}),
|
||||
})),
|
||||
type: "thread.session-stop-requested",
|
||||
payload: {
|
||||
threadId: command.threadId,
|
||||
@@ -573,13 +567,13 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
threadId: command.threadId,
|
||||
});
|
||||
return {
|
||||
...withEventBase({
|
||||
...(yield* withEventBase({
|
||||
aggregateKind: "thread",
|
||||
aggregateId: command.threadId,
|
||||
occurredAt: command.createdAt,
|
||||
commandId: command.commandId,
|
||||
metadata: {},
|
||||
}),
|
||||
})),
|
||||
type: "thread.session-set",
|
||||
payload: {
|
||||
threadId: command.threadId,
|
||||
@@ -595,12 +589,12 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
threadId: command.threadId,
|
||||
});
|
||||
return {
|
||||
...withEventBase({
|
||||
...(yield* withEventBase({
|
||||
aggregateKind: "thread",
|
||||
aggregateId: command.threadId,
|
||||
occurredAt: command.createdAt,
|
||||
commandId: command.commandId,
|
||||
}),
|
||||
})),
|
||||
type: "thread.message-sent",
|
||||
payload: {
|
||||
threadId: command.threadId,
|
||||
@@ -622,12 +616,12 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
threadId: command.threadId,
|
||||
});
|
||||
return {
|
||||
...withEventBase({
|
||||
...(yield* withEventBase({
|
||||
aggregateKind: "thread",
|
||||
aggregateId: command.threadId,
|
||||
occurredAt: command.createdAt,
|
||||
commandId: command.commandId,
|
||||
}),
|
||||
})),
|
||||
type: "thread.message-sent",
|
||||
payload: {
|
||||
threadId: command.threadId,
|
||||
@@ -649,12 +643,12 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
threadId: command.threadId,
|
||||
});
|
||||
return {
|
||||
...withEventBase({
|
||||
...(yield* withEventBase({
|
||||
aggregateKind: "thread",
|
||||
aggregateId: command.threadId,
|
||||
occurredAt: command.createdAt,
|
||||
commandId: command.commandId,
|
||||
}),
|
||||
})),
|
||||
type: "thread.proposed-plan-upserted",
|
||||
payload: {
|
||||
threadId: command.threadId,
|
||||
@@ -670,12 +664,12 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
threadId: command.threadId,
|
||||
});
|
||||
return {
|
||||
...withEventBase({
|
||||
...(yield* withEventBase({
|
||||
aggregateKind: "thread",
|
||||
aggregateId: command.threadId,
|
||||
occurredAt: command.createdAt,
|
||||
commandId: command.commandId,
|
||||
}),
|
||||
})),
|
||||
type: "thread.turn-diff-completed",
|
||||
payload: {
|
||||
threadId: command.threadId,
|
||||
@@ -697,12 +691,12 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
threadId: command.threadId,
|
||||
});
|
||||
return {
|
||||
...withEventBase({
|
||||
...(yield* withEventBase({
|
||||
aggregateKind: "thread",
|
||||
aggregateId: command.threadId,
|
||||
occurredAt: command.createdAt,
|
||||
commandId: command.commandId,
|
||||
}),
|
||||
})),
|
||||
type: "thread.reverted",
|
||||
payload: {
|
||||
threadId: command.threadId,
|
||||
@@ -726,13 +720,13 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
.requestId as OrchestrationEvent["metadata"]["requestId"])
|
||||
: undefined;
|
||||
return {
|
||||
...withEventBase({
|
||||
...(yield* withEventBase({
|
||||
aggregateKind: "thread",
|
||||
aggregateId: command.threadId,
|
||||
occurredAt: command.createdAt,
|
||||
commandId: command.commandId,
|
||||
...(requestId !== undefined ? { metadata: { requestId } } : {}),
|
||||
}),
|
||||
})),
|
||||
type: "thread.activity-appended",
|
||||
payload: {
|
||||
threadId: command.threadId,
|
||||
|
||||
@@ -2267,7 +2267,7 @@ export const ChatComposer = memo(
|
||||
}`
|
||||
: phase === "disconnected"
|
||||
? "Ask for follow-up changes or attach images"
|
||||
: "Ask anything, @tag files/folders, or use / to show available commands"
|
||||
: "Ask anything, @tag files/folders, $use skills, or / for commands"
|
||||
}
|
||||
disabled={
|
||||
isConnecting ||
|
||||
|
||||
@@ -520,19 +520,27 @@ function WorkingTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "workin
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Self-ticking components — bypass LegendList memoisation entirely.
|
||||
// Each owns a `nowMs` state value consumed in the render output so the
|
||||
// React Compiler cannot elide the re-render as a no-op.
|
||||
// Self-ticking labels — update their own text nodes so elapsed-time display
|
||||
// does not create a React commit every second while a response is streaming.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/** Live "Working for Xs" label. */
|
||||
function WorkingTimer({ createdAt }: { createdAt: string }) {
|
||||
const [nowMs, setNowMs] = useState(() => Date.now());
|
||||
const textRef = useRef<HTMLSpanElement>(null);
|
||||
const initialText = formatWorkingTimerNow(createdAt);
|
||||
|
||||
useEffect(() => {
|
||||
const id = setInterval(() => setNowMs(Date.now()), 1000);
|
||||
const updateText = () => {
|
||||
if (textRef.current) {
|
||||
textRef.current.textContent = formatWorkingTimerNow(createdAt);
|
||||
}
|
||||
};
|
||||
updateText();
|
||||
const id = setInterval(updateText, 1000);
|
||||
return () => clearInterval(id);
|
||||
}, [createdAt]);
|
||||
return <>{formatWorkingTimer(createdAt, new Date(nowMs).toISOString()) ?? "0s"}</>;
|
||||
|
||||
return <span ref={textRef}>{initialText}</span>;
|
||||
}
|
||||
|
||||
/** Live timestamp + elapsed duration for a streaming assistant message. */
|
||||
@@ -545,15 +553,28 @@ function LiveMessageMeta({
|
||||
durationStart: string | null | undefined;
|
||||
timestampFormat: TimestampFormat;
|
||||
}) {
|
||||
const [nowMs, setNowMs] = useState(() => Date.now());
|
||||
const textRef = useRef<HTMLSpanElement>(null);
|
||||
const initialText = formatLiveMessageMetaNow(createdAt, durationStart, timestampFormat);
|
||||
|
||||
useEffect(() => {
|
||||
const id = setInterval(() => setNowMs(Date.now()), 1000);
|
||||
const updateText = () => {
|
||||
if (textRef.current) {
|
||||
textRef.current.textContent = formatLiveMessageMetaNow(
|
||||
createdAt,
|
||||
durationStart,
|
||||
timestampFormat,
|
||||
);
|
||||
}
|
||||
};
|
||||
updateText();
|
||||
if (!durationStart) {
|
||||
return;
|
||||
}
|
||||
const id = setInterval(updateText, 1000);
|
||||
return () => clearInterval(id);
|
||||
}, [durationStart]);
|
||||
const elapsed = durationStart
|
||||
? formatElapsed(durationStart, new Date(nowMs).toISOString())
|
||||
: null;
|
||||
return <>{formatMessageMeta(createdAt, elapsed, timestampFormat)}</>;
|
||||
}, [createdAt, durationStart, timestampFormat]);
|
||||
|
||||
return <span ref={textRef}>{initialText}</span>;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -860,6 +881,19 @@ function formatWorkingTimer(startIso: string, endIso: string): string | null {
|
||||
return seconds > 0 ? `${minutes}m ${seconds}s` : `${minutes}m`;
|
||||
}
|
||||
|
||||
function formatWorkingTimerNow(startIso: string): string {
|
||||
return formatWorkingTimer(startIso, new Date().toISOString()) ?? "0s";
|
||||
}
|
||||
|
||||
function formatLiveMessageMetaNow(
|
||||
createdAt: string,
|
||||
durationStart: string | null | undefined,
|
||||
timestampFormat: TimestampFormat,
|
||||
): string {
|
||||
const elapsed = durationStart ? formatElapsed(durationStart, new Date().toISOString()) : null;
|
||||
return formatMessageMeta(createdAt, elapsed, timestampFormat);
|
||||
}
|
||||
|
||||
function formatMessageMeta(
|
||||
createdAt: string,
|
||||
duration: string | null,
|
||||
|
||||
@@ -4,6 +4,12 @@ import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { make as makeJsonSchemaGenerator } from "@effect/openapi-generator/JsonSchemaGenerator";
|
||||
import { Effect, FileSystem, Layer, Logger, Path, Schema } from "effect";
|
||||
import {
|
||||
FetchHttpClient,
|
||||
HttpClient,
|
||||
HttpClientRequest,
|
||||
HttpClientResponse,
|
||||
} from "effect/unstable/http";
|
||||
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
|
||||
|
||||
const UPSTREAM_REF = "be75785504ff152fa6333e380a2d50642f42fba0";
|
||||
@@ -21,6 +27,13 @@ const GithubContentEntries = Schema.Array(
|
||||
);
|
||||
type GithubContentEntry = (typeof GithubContentEntries.Type)[number];
|
||||
|
||||
const JsonSchemaDocument = Schema.StructWithRest(
|
||||
Schema.Struct({
|
||||
definitions: Schema.optionalKey(Schema.Record(Schema.String, Schema.Json)),
|
||||
}),
|
||||
[Schema.Record(Schema.String, Schema.Json)],
|
||||
);
|
||||
|
||||
interface GeneratedPaths {
|
||||
readonly generatedDir: string;
|
||||
readonly schemaOutputPath: string;
|
||||
@@ -143,40 +156,19 @@ const ensureGeneratedDir = Effect.fn("ensureGeneratedDir")(function* () {
|
||||
});
|
||||
|
||||
const fetchText = Effect.fn("fetchText")(function* (url: string) {
|
||||
const response = yield* Effect.tryPromise({
|
||||
try: () =>
|
||||
fetch(url, {
|
||||
headers: {
|
||||
"user-agent": USER_AGENT,
|
||||
},
|
||||
}),
|
||||
catch: (cause) =>
|
||||
new GeneratorError({
|
||||
detail: `Failed to fetch ${url}`,
|
||||
cause,
|
||||
}),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const detail = yield* Effect.tryPromise({
|
||||
try: () => response.text(),
|
||||
catch: () => "",
|
||||
});
|
||||
return yield* Effect.fail(
|
||||
new GeneratorError({
|
||||
detail: `Failed to download ${url}: ${response.status} ${detail}`,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
return yield* Effect.tryPromise({
|
||||
try: () => response.text(),
|
||||
catch: (cause) =>
|
||||
new GeneratorError({
|
||||
detail: `Failed to read response body for ${url}`,
|
||||
cause,
|
||||
}),
|
||||
});
|
||||
return yield* HttpClientRequest.get(url).pipe(
|
||||
HttpClientRequest.setHeader("user-agent", USER_AGENT),
|
||||
HttpClient.execute,
|
||||
Effect.flatMap(HttpClientResponse.filterStatusOk),
|
||||
Effect.flatMap((okResponse) => okResponse.text),
|
||||
Effect.mapError(
|
||||
(cause) =>
|
||||
new GeneratorError({
|
||||
detail: `Failed to fetch ${url}`,
|
||||
cause,
|
||||
}),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
const fetchDirectoryEntries = Effect.fn("fetchDirectoryEntries")(function* (path: string) {
|
||||
@@ -548,9 +540,7 @@ const generateFiles = Effect.fn("generateFiles")(function* () {
|
||||
|
||||
for (const file of jsonSchemaFiles) {
|
||||
const raw = yield* fetchText(file.downloadUrl);
|
||||
const parsed = JSON.parse(raw) as {
|
||||
readonly definitions?: Record<string, typeof Schema.Json.Type>;
|
||||
} & Record<string, typeof Schema.Json.Type>;
|
||||
const parsed = yield* Schema.decodeEffect(Schema.fromJsonString(JsonSchemaDocument))(raw);
|
||||
const localDefinitionNames = new Map(
|
||||
Object.keys(parsed.definitions ?? {}).map((definitionName) => [
|
||||
definitionName,
|
||||
@@ -767,6 +757,12 @@ const generateFiles = Effect.fn("generateFiles")(function* () {
|
||||
|
||||
generateFiles().pipe(
|
||||
Effect.scoped,
|
||||
Effect.provide(Layer.mergeAll(Logger.layer([Logger.consolePretty()]), NodeServices.layer)),
|
||||
Effect.provide(
|
||||
Layer.mergeAll(
|
||||
Logger.layer([Logger.consolePretty()]),
|
||||
NodeServices.layer,
|
||||
FetchHttpClient.layer,
|
||||
),
|
||||
),
|
||||
NodeRuntime.runMain,
|
||||
);
|
||||
Reference in new issue
Block a user