fix(ui): surface model retry status (NAN-34) (#5504)
This commit is contained in:
1 parent
0b1fa0c3e4
commit
b581a496a6
52 files changed
+1697
-55
No files matched your search
@@ -6,5 +6,9 @@
|
||||
{"event":"recovery_state","chat_id":"chat","status":"resuming","recovery_id":"r1","attempts":0},
|
||||
{"event":"recovery_state","chat_id":"chat","status":"awaiting_user","recovery_id":"r1","attempts":1,"reason":"tool_state_unknown","can_continue":false},
|
||||
{"event":"recovery_state","chat_id":"chat","status":"recovered","recovery_id":"r1","attempts":1},
|
||||
{"event":"recovery_state","chat_id":"chat","status":"failed","recovery_id":"r1","attempts":2}
|
||||
{"event":"recovery_state","chat_id":"chat","status":"failed","recovery_id":"r1","attempts":2},
|
||||
{"event":"retry_status","chat_id":"chat","state":"waiting","attempt":1,"max_attempts":4,"error_kind":"connection","retry_after_s":2},
|
||||
{"event":"retry_status","chat_id":"chat","state":"recovered","attempt":2,"max_attempts":4,"error_kind":"connection"},
|
||||
{"event":"retry_status","chat_id":"chat","state":"cleared","attempt":2,"max_attempts":4,"error_kind":"connection"},
|
||||
{"event":"retry_status","chat_id":"chat","state":"exhausted","attempt":4,"max_attempts":4,"error_kind":"connection"}
|
||||
]
|
||||
@@ -14,7 +14,16 @@ export interface ContextCompaction {
|
||||
phase: "started" | "succeeded" | "failed" | "cancelled"
|
||||
}
|
||||
|
||||
export interface RetryStatus {
|
||||
state: "waiting" | "recovered" | "cleared" | "exhausted"
|
||||
attempt: number
|
||||
max_attempts?: number
|
||||
error_kind: string
|
||||
retry_after_s?: number
|
||||
}
|
||||
|
||||
export type NotificationEvent =
|
||||
| ({ event: "retry_status"; chat_id: string; turn_id?: string } & RetryStatus)
|
||||
| ({ event: "recovery_state"; chat_id: string; turn_id?: string } & RecoveryState)
|
||||
| {
|
||||
event: "context_compaction"
|
||||
@@ -49,8 +58,11 @@ export function isRecoveryState(value: unknown): value is RecoveryState {
|
||||
/** Undefined means another protocol family; null means a malformed notification. */
|
||||
export function decodeNotification(value: unknown): NotificationEvent | null | undefined {
|
||||
if (!isRecord(value)) return undefined
|
||||
if (value.event !== "recovery_state" && value.event !== "context_compaction") return undefined
|
||||
if (!["recovery_state", "context_compaction", "retry_status"].includes(String(value.event))) return undefined
|
||||
if (typeof value.chat_id !== "string" || !optional(value.turn_id, "string")) return null
|
||||
if (value.event === "retry_status") {
|
||||
return isRetryStatus(value) ? value as unknown as NotificationEvent : null
|
||||
}
|
||||
if (value.event === "recovery_state") {
|
||||
return isRecoveryState(value) ? value as unknown as NotificationEvent : null
|
||||
}
|
||||
@@ -58,6 +70,23 @@ export function decodeNotification(value: unknown): NotificationEvent | null | u
|
||||
&& isCompactionPhase(value.phase) ? value as unknown as NotificationEvent : null
|
||||
}
|
||||
|
||||
function isRetryStatus(value: Record<string, unknown>): boolean {
|
||||
return typeof value.state === "string"
|
||||
&& ["waiting", "recovered", "cleared", "exhausted"].includes(value.state)
|
||||
&& typeof value.attempt === "number"
|
||||
&& Number.isInteger(value.attempt)
|
||||
&& value.attempt >= 1
|
||||
&& (value.max_attempts === undefined
|
||||
|| (typeof value.max_attempts === "number"
|
||||
&& Number.isInteger(value.max_attempts)
|
||||
&& value.max_attempts >= value.attempt))
|
||||
&& typeof value.error_kind === "string"
|
||||
&& (value.retry_after_s === undefined
|
||||
|| (typeof value.retry_after_s === "number"
|
||||
&& Number.isFinite(value.retry_after_s)
|
||||
&& value.retry_after_s >= 0))
|
||||
}
|
||||
|
||||
/** A terminal history row must not regress when an older live event arrives. */
|
||||
export function acceptsCompactionPhase(
|
||||
current: ContextCompaction["phase"] | undefined,
|
||||
|
||||
Reference in new issue
Block a user