The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as Schema from "effect/Schema"; |
| 2 | |
| 3 | import { |
| 4 | CommandId, |
| 5 | IsoDateTime, |
| 6 | NonNegativeInt, |
| 7 | ThreadId, |
| 8 | TrimmedNonEmptyString, |
| 9 | } from "./baseSchemas.ts"; |
| 10 | import { ThreadLinkedPullRequest } from "./threadPullRequest.ts"; |
| 11 | import { ThreadTitleRegeneration } from "./threadTitle.ts"; |
| 12 | |
| 13 | export function hasOnlyPairedSurrogates(value: string): boolean { |
| 14 | for (let index = 0; index < value.length; index += 1) { |
| 15 | const codeUnit = value.charCodeAt(index); |
| 16 | if (codeUnit >= 0xd800 && codeUnit <= 0xdbff) { |
| 17 | const nextCodeUnit = value.charCodeAt(index + 1); |
| 18 | if (index + 1 >= value.length || nextCodeUnit < 0xdc00 || nextCodeUnit > 0xdfff) { |
| 19 | return false; |
| 20 | } |
| 21 | index += 1; |
| 22 | } else if (codeUnit >= 0xdc00 && codeUnit <= 0xdfff) { |
| 23 | return false; |
| 24 | } |
| 25 | } |
| 26 | return true; |
| 27 | } |
| 28 | |
| 29 | const ThreadMetadataTitle = TrimmedNonEmptyString.check(Schema.isMaxLength(512)).annotate({ |
| 30 | description: "New concise display title. Required only when action is rename.", |
| 31 | }); |
| 32 | |
| 33 | const ThreadMetadataClientRequestId = TrimmedNonEmptyString.check(Schema.isMaxLength(256)) |
| 34 | .check( |
| 35 | Schema.makeFilter((value) => |
| 36 | hasOnlyPairedSurrogates(value) |
| 37 | ? true |
| 38 | : "clientRequestId must contain valid paired Unicode surrogates.", |
| 39 | ), |
| 40 | ) |
| 41 | .annotate({ description: "Stable idempotency key to reuse when retrying this mutation." }); |
| 42 | |
| 43 | export const ThreadMetadataMcpAction = Schema.Literals(["rename", "regenerate_title"]); |
| 44 | export type ThreadMetadataMcpAction = typeof ThreadMetadataMcpAction.Type; |
| 45 | |
| 46 | export const ThreadMetadataMcpUpdateInput = Schema.Struct({ |
| 47 | threadId: Schema.optional(ThreadId), |
| 48 | action: ThreadMetadataMcpAction, |
| 49 | title: Schema.optional(ThreadMetadataTitle), |
| 50 | clientRequestId: Schema.optional(ThreadMetadataClientRequestId), |
| 51 | }).check( |
| 52 | Schema.makeFilter((input) => |
| 53 | (input.action === "rename") === (input.title !== undefined) |
| 54 | ? true |
| 55 | : "rename requires title; regenerate_title does not accept one.", |
| 56 | ), |
| 57 | ); |
| 58 | export type ThreadMetadataMcpUpdateInput = typeof ThreadMetadataMcpUpdateInput.Type; |
| 59 | |
| 60 | export const ThreadMetadataMcpUpdateResult = Schema.Struct({ |
| 61 | threadId: ThreadId, |
| 62 | action: ThreadMetadataMcpAction, |
| 63 | commandId: CommandId, |
| 64 | sequence: NonNegativeInt, |
| 65 | title: Schema.String, |
| 66 | titleRegeneration: Schema.NullOr(ThreadTitleRegeneration), |
| 67 | linkedPullRequest: Schema.NullOr(ThreadLinkedPullRequest), |
| 68 | updatedAt: IsoDateTime, |
| 69 | }); |
| 70 | export type ThreadMetadataMcpUpdateResult = typeof ThreadMetadataMcpUpdateResult.Type; |