Co-authored-by: Julius Marminge <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
25 lines
957 B
TypeScript
25 lines
957 B
TypeScript
import type { EnvironmentId, OrchestrationV2ThreadTranscript } from "@t3tools/contracts";
|
|
import { toKindScopedComposerContextId } from "@t3tools/shared/composerContextReferences";
|
|
import { threadTranscriptHeader } from "@t3tools/shared/threadTranscript";
|
|
import * as DateTime from "effect/DateTime";
|
|
|
|
export function threadContextAttachment(
|
|
environmentId: EnvironmentId,
|
|
transcript: OrchestrationV2ThreadTranscript,
|
|
): File {
|
|
const updatedAt = DateTime.formatIso(transcript.updatedAt);
|
|
const name = toKindScopedComposerContextId(
|
|
"thread",
|
|
`${environmentId}:${transcript.threadId}:${updatedAt}`,
|
|
);
|
|
const title = transcript.title.replace(/[^\p{L}\p{N}._ -]/gu, "_").slice(0, 64) || "Thread";
|
|
return new File(
|
|
[
|
|
threadTranscriptHeader(environmentId, transcript),
|
|
...transcript.items.map((row) => `${JSON.stringify(row)}\n`),
|
|
],
|
|
`${title}-${name.slice(-16)}.jsonl`,
|
|
{ type: "application/x-ndjson" },
|
|
);
|
|
}
|