The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import type { EnvironmentId, OrchestrationV2ThreadTranscript } from "@t3tools/contracts"; |
| 2 | import { toKindScopedComposerContextId } from "@t3tools/shared/composerContextReferences"; |
| 3 | import { threadTranscriptHeader } from "@t3tools/shared/threadTranscript"; |
| 4 | import * as DateTime from "effect/DateTime"; |
| 5 | |
| 6 | export function threadContextAttachment( |
| 7 | environmentId: EnvironmentId, |
| 8 | transcript: OrchestrationV2ThreadTranscript, |
| 9 | ): File { |
| 10 | const updatedAt = DateTime.formatIso(transcript.updatedAt); |
| 11 | const name = toKindScopedComposerContextId( |
| 12 | "thread", |
| 13 | `${environmentId}:${transcript.threadId}:${updatedAt}`, |
| 14 | ); |
| 15 | const title = transcript.title.replace(/[^\p{L}\p{N}._ -]/gu, "_").slice(0, 64) || "Thread"; |
| 16 | return new File( |
| 17 | [ |
| 18 | threadTranscriptHeader(environmentId, transcript), |
| 19 | ...transcript.items.map((row) => `${JSON.stringify(row)}\n`), |
| 20 | ], |
| 21 | `${title}-${name.slice(-16)}.jsonl`, |
| 22 | { type: "application/x-ndjson" }, |
| 23 | ); |
| 24 | } |