mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
The CLI now measures the serialized runtime request against the shared 1 MiB local transport limit before writing any bytes. Oversized requests fail with invalid_argument and requestSent=false instead of being cut off by the server mid-frame, and the client skips mutation recovery for these unsent requests so it never suggests resending the same payload. Co-authored-by: Neil <4138956+nwparker@users.noreply.github.com>
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import { RuntimeClientError, RuntimeRpcFailureError } from './types'
|
|
|
|
export function attachMutationRecovery(
|
|
error: unknown,
|
|
requestId: string | undefined,
|
|
originalCommand?: string[],
|
|
unsent = false
|
|
): unknown {
|
|
if (!requestId || !(error instanceof RuntimeClientError)) {
|
|
return error
|
|
}
|
|
const data = {
|
|
...(error.data && typeof error.data === 'object' ? error.data : {}),
|
|
orchestrationRequestId: requestId,
|
|
...(originalCommand ? { originalCommand } : {}),
|
|
...(unsent ? { requestSent: false } : {})
|
|
}
|
|
if (error instanceof RuntimeRpcFailureError) {
|
|
return new RuntimeRpcFailureError({
|
|
...error.response,
|
|
error: {
|
|
...error.response.error,
|
|
message: `${error.message} Orchestration mutation request ID: ${requestId}.`,
|
|
data
|
|
}
|
|
})
|
|
}
|
|
return new RuntimeClientError(
|
|
error.code,
|
|
`${error.message} Orchestration mutation request ID: ${requestId}.`,
|
|
data
|
|
)
|
|
}
|
|
|
|
/** True when this invocation never sent the request. */
|
|
export function isRequestUnsent(error: unknown): boolean {
|
|
const data: unknown = error instanceof RuntimeClientError ? error.data : undefined
|
|
return (
|
|
typeof data === 'object' && data !== null && 'requestSent' in data && data.requestSent === false
|
|
)
|
|
}
|