Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

claudeHistoryWorker.ts

32 lines1.1 KB

1import { forkSession, getSessionMessages } from "@anthropic-ai/claude-agent-sdk";
2import * as Schema from "effect/Schema";
3​
4// Nothing here may run on import: inside the executable `import.meta.main` is
5// true for the whole bundle.
6const decodeHistoryOptions = Schema.decodeSync(
7 Schema.fromJsonString(
8 Schema.Struct({
9 dir: Schema.optionalKey(Schema.String),
10 includeSystemMessages: Schema.optionalKey(Schema.Boolean),
11 upToMessageId: Schema.optionalKey(Schema.String),
12 }),
13 ),
14);
15​
16export async function runClaudeHistoryWorker(
17 method: string | undefined,
18 sessionId: string | undefined,
19 rawOptions: string | undefined,
20): Promise<void> {
21 const options = decodeHistoryOptions(rawOptions ?? "{}");
22 if (!sessionId) throw new Error("Claude history session id is required.");
23 const result =
24 method === "getSessionMessages"
25 ? await getSessionMessages(sessionId, options)
26 : method === "forkSession"
27 ? await forkSession(sessionId, options)
28 : (() => {
29 throw new Error("Unknown Claude history operation.");
30 })();
31 process.stdout.write(JSON.stringify(result));