| ... | @@ -82,6 +82,11 @@ const payloadKind = (payload: unknown): CodexAppServerPayloadKind => { | ... | @@ -82,6 +82,11 @@ const payloadKind = (payload: unknown): CodexAppServerPayloadKind => { |
| 82 | return typeof payload; | 82 | return typeof payload; |
| 83 | }; | 83 | }; |
| 84 | | 84 | |
| | 85 | const protocolMessageFields = ["id", "method", "params", "result", "error"] as const; |
| | 86 | |
| | 87 | export const CodexAppServerProtocolMessageField = Schema.Literals(protocolMessageFields); |
| | 88 | export type CodexAppServerProtocolMessageField = typeof CodexAppServerProtocolMessageField.Type; |
| | 89 | |
| 85 | export interface CodexAppServerRequestDiagnostics { | 90 | export interface CodexAppServerRequestDiagnostics { |
| 86 | readonly method?: string; | 91 | readonly method?: string; |
| 87 | readonly requestId?: string; | 92 | readonly requestId?: string; |
| ... | @@ -157,7 +162,8 @@ export class CodexAppServerProtocolParseError extends Schema.TaggedErrorClass<Co | ... | @@ -157,7 +162,8 @@ export class CodexAppServerProtocolParseError extends Schema.TaggedErrorClass<Co |
| 157 | operation: CodexAppServerProtocolParseOperation, | 162 | operation: CodexAppServerProtocolParseOperation, |
| 158 | method: Schema.optionalKey(Schema.String), | 163 | method: Schema.optionalKey(Schema.String), |
| 159 | requestId: Schema.optionalKey(Schema.String), | 164 | requestId: Schema.optionalKey(Schema.String), |
| 160 | detail: Schema.optionalKey(Schema.String), | 165 | payloadKind: Schema.optionalKey(CodexAppServerPayloadKind), |
| | 166 | presentFields: Schema.optionalKey(Schema.Array(CodexAppServerProtocolMessageField)), |
| 161 | issueCount: Schema.optionalKey(Schema.Number), | 167 | issueCount: Schema.optionalKey(Schema.Number), |
| 162 | issueKinds: Schema.optionalKey(Schema.Array(CodexAppServerSchemaIssueKind)), | 168 | issueKinds: Schema.optionalKey(Schema.Array(CodexAppServerSchemaIssueKind)), |
| 163 | maximumPathDepth: Schema.optionalKey(Schema.Number), | 169 | maximumPathDepth: Schema.optionalKey(Schema.Number), |
| ... | @@ -196,6 +202,31 @@ export class CodexAppServerProtocolParseError extends Schema.TaggedErrorClass<Co | ... | @@ -196,6 +202,31 @@ export class CodexAppServerProtocolParseError extends Schema.TaggedErrorClass<Co |
| 196 | cause, | 202 | cause, |
| 197 | }); | 203 | }); |
| 198 | } | 204 | } |
| | 205 | |
| | 206 | static fromUnroutableMessage(message: unknown) { |
| | 207 | const diagnostics = { payloadKind: payloadKind(message) }; |
| | 208 | if (typeof message !== "object" || message === null || Array.isArray(message)) { |
| | 209 | return new CodexAppServerProtocolParseError({ |
| | 210 | operation: "route-wire-message", |
| | 211 | ...diagnostics, |
| | 212 | }); |
| | 213 | } |
| | 214 | |
| | 215 | const presentFields = protocolMessageFields.filter((field) => field in message); |
| | 216 | const method = |
| | 217 | "method" in message && typeof message.method === "string" ? message.method : undefined; |
| | 218 | const requestId = |
| | 219 | "id" in message && (typeof message.id === "string" || typeof message.id === "number") |
| | 220 | ? String(message.id) |
| | 221 | : undefined; |
| | 222 | return new CodexAppServerProtocolParseError({ |
| | 223 | operation: "route-wire-message", |
| | 224 | ...diagnostics, |
| | 225 | presentFields, |
| | 226 | ...(method === undefined ? {} : { method }), |
| | 227 | ...(requestId === undefined ? {} : { requestId }), |
| | 228 | }); |
| | 229 | } |
| 199 | } | 230 | } |
| 200 | | 231 | |
| 201 | export class CodexAppServerTransportError extends Schema.TaggedErrorClass<CodexAppServerTransportError>()( | 232 | export class CodexAppServerTransportError extends Schema.TaggedErrorClass<CodexAppServerTransportError>()( |