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, 03:37 UTC
| 1 | import * as Schema from "effect/Schema"; |
| 2 | import { IsoDateTime, ProviderThreadId, TrimmedNonEmptyString } from "./baseSchemas.ts"; |
| 3 | import { ThreadId } from "./baseSchemas.ts"; |
| 4 | import { |
| 5 | getProviderAttachmentLimitError, |
| 6 | PROVIDER_SEND_TURN_MAX_INPUT_CHARS, |
| 7 | ChatAttachment, |
| 8 | } from "./chatAttachment.ts"; |
| 9 | import { ModelSelection } from "./modelSelection.ts"; |
| 10 | import { ProviderInteractionMode } from "./providerPolicy.ts"; |
| 11 | import { SignInUrl } from "./providerSetup.ts"; |
| 12 | |
| 13 | export const ProviderSendTurnInput = Schema.Struct({ |
| 14 | threadId: ThreadId, |
| 15 | /** Internal recovery: permits empty turns only for adapters supporting promptless continuation. */ |
| 16 | continuation: Schema.optional(Schema.Boolean), |
| 17 | input: Schema.optional( |
| 18 | TrimmedNonEmptyString.check(Schema.isMaxLength(PROVIDER_SEND_TURN_MAX_INPUT_CHARS)), |
| 19 | ), |
| 20 | attachments: Schema.optional( |
| 21 | Schema.Array(ChatAttachment).check( |
| 22 | Schema.makeFilter((attachments) => getProviderAttachmentLimitError(attachments) ?? true), |
| 23 | ), |
| 24 | ), |
| 25 | modelSelection: Schema.optional(ModelSelection), |
| 26 | interactionMode: Schema.optional(ProviderInteractionMode), |
| 27 | }); |
| 28 | export type ProviderSendTurnInput = typeof ProviderSendTurnInput.Type; |
| 29 | |
| 30 | export const ProviderUploadFeedbackInput = Schema.Struct({ |
| 31 | threadId: ThreadId, |
| 32 | reason: Schema.optional(TrimmedNonEmptyString), |
| 33 | }); |
| 34 | export type ProviderUploadFeedbackInput = typeof ProviderUploadFeedbackInput.Type; |
| 35 | |
| 36 | export const ProviderUploadFeedbackResult = Schema.Struct({ |
| 37 | feedbackId: TrimmedNonEmptyString, |
| 38 | }); |
| 39 | export type ProviderUploadFeedbackResult = typeof ProviderUploadFeedbackResult.Type; |
| 40 | |
| 41 | const McpServerName = TrimmedNonEmptyString.check(Schema.isMaxLength(256)); |
| 42 | |
| 43 | /** One of an agent's MCP servers, in the thread whose session asked for a sign-in. */ |
| 44 | export const ProviderMcpSignInStartInput = Schema.Struct({ |
| 45 | threadId: ThreadId, |
| 46 | providerThreadId: ProviderThreadId, |
| 47 | server: McpServerName, |
| 48 | }); |
| 49 | export type ProviderMcpSignInStartInput = typeof ProviderMcpSignInStartInput.Type; |
| 50 | |
| 51 | export const ProviderMcpSignInStartResult = Schema.Struct({ |
| 52 | /** The page to approve the sign-in on; null when the server needs none any more. */ |
| 53 | authorizationUrl: Schema.NullOr(SignInUrl), |
| 54 | /** The environment's time when it found the server already signed in. */ |
| 55 | signedInAt: Schema.NullOr(IsoDateTime), |
| 56 | }); |
| 57 | export type ProviderMcpSignInStartResult = typeof ProviderMcpSignInStartResult.Type; |
| 58 | |
| 59 | export const ProviderMcpSignInCompleteInput = Schema.Struct({ |
| 60 | ...ProviderMcpSignInStartInput.fields, |
| 61 | /** The address the browser was sent to after approving, usually a localhost page. */ |
| 62 | callbackUrl: TrimmedNonEmptyString.check(Schema.isMaxLength(16_384)), |
| 63 | }); |
| 64 | export type ProviderMcpSignInCompleteInput = typeof ProviderMcpSignInCompleteInput.Type; |
| 65 | |
| 66 | export const ProviderMcpSignInCompleteResult = Schema.Struct({ |
| 67 | /** The environment's time, so a later notice that needs a sign-in again offers one. */ |
| 68 | signedInAt: IsoDateTime, |
| 69 | }); |
| 70 | export type ProviderMcpSignInCompleteResult = typeof ProviderMcpSignInCompleteResult.Type; |
| 71 | |
| 72 | /** Safe to show: never carries the callback URL, codes or tokens. */ |
| 73 | export class ProviderMcpSignInError extends Schema.TaggedError<ProviderMcpSignInError>()( |
| 74 | "ProviderMcpSignInError", |
| 75 | { |
| 76 | server: Schema.String, |
| 77 | detail: Schema.String, |
| 78 | }, |
| 79 | ) { |
| 80 | override get message(): string { |
| 81 | return this.detail; |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | export class ProviderUploadFeedbackError extends Schema.TaggedError<ProviderUploadFeedbackError>()( |
| 86 | "ProviderUploadFeedbackError", |
| 87 | { |
| 88 | threadId: ThreadId, |
| 89 | cause: Schema.optional(Schema.Defect()), |
| 90 | }, |
| 91 | ) { |
| 92 | override get message(): string { |
| 93 | return `Failed to upload feedback for thread ${this.threadId}.`; |
| 94 | } |
| 95 | } |