Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions apps/server/src/cli/thread.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
latestRunError,
launchModelSelection,
readLatestMessages,
readOutputSchema,
resolveProject,
threadCommand,
type ThreadTools,
Expand Down Expand Up @@ -524,6 +525,21 @@ it.effect("start rejects a repeated --option before reaching the server", () =>
),
);

it.effect("--output-schema reads a ~/ path from the home directory", () =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const home = yield* fs.makeTempDirectoryScoped({ prefix: "t3-thread-schema-" });
yield* fs.writeFileString(path.join(home, "schema.json"), '{"type":"object"}');

const output = yield* readOutputSchema(Option.some("~/schema.json")).pipe(
Effect.provideService(HostProcess.HomeDirectory, home),
);

assert.deepStrictEqual(output, { outputSchema: { type: "object" } });
}).pipe(Effect.provide(NodeServices.layer)),
);

/** Serves t3_thread_read pages the way the server does: positions count every item. */
const timelineTools = (types: ReadonlyArray<string>) => {
const items = types.map((type, position) => ({ position, itemId: `item-${position}`, type }));
Expand Down
6 changes: 4 additions & 2 deletions apps/server/src/cli/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -846,14 +846,16 @@ const outputSchemaFlag = Flag.String("output-schema").pipe(
const decodeOutputSchema = Schema.decodeUnknownEffect(
Schema.fromJsonString(Schema.Record(Schema.String, Schema.Json)),
);
const readOutputSchema = Effect.fn("cli.thread.readOutputSchema")(function* (
export const readOutputSchema = Effect.fn("cli.thread.readOutputSchema")(function* (
path: Option.Option<string>,
) {
if (Option.isNone(path)) return {};
const fileSystem = yield* FileSystem.FileSystem;
const usage = () =>
new ThreadUsageError({ detail: `${path.value} does not hold a JSON Schema object.` });
const text = yield* fileSystem.readFileString(path.value).pipe(Effect.mapError(usage));
const text = yield* fileSystem
.readFileString(yield* expandHomePath(path.value))
.pipe(Effect.mapError(usage));
return { outputSchema: yield* decodeOutputSchema(text).pipe(Effect.mapError(usage)) };
});
const messageArgument = Argument.String("message").pipe(
Expand Down
Loading