fix(core): preserve provider session failures
This commit is contained in:
parent
c45d1db9a0
commit
f8e5b12f41
13 changed files with 359 additions and 22 deletions
|
|
@ -50,6 +50,10 @@ const stepSettlementOptions = {
|
|||
|
||||
export const UnknownError = SessionMessage.UnknownError
|
||||
export type UnknownError = SessionMessage.UnknownError
|
||||
export const ProviderError = SessionMessage.ProviderError
|
||||
export type ProviderError = SessionMessage.ProviderError
|
||||
export const Error = SessionMessage.Error
|
||||
export type Error = SessionMessage.Error
|
||||
|
||||
export const AgentSwitched = Event.define({
|
||||
type: "session.next.agent.switched",
|
||||
|
|
@ -188,7 +192,7 @@ export namespace Step {
|
|||
schema: {
|
||||
...Base,
|
||||
assistantMessageID: SessionMessageID.ID,
|
||||
error: UnknownError,
|
||||
error: Error,
|
||||
},
|
||||
})
|
||||
export type Failed = typeof Failed.Type
|
||||
|
|
|
|||
|
|
@ -17,6 +17,33 @@ export const UnknownError = Schema.Struct({
|
|||
message: Schema.String,
|
||||
}).annotate({ identifier: "Session.Error.Unknown" })
|
||||
|
||||
export const ProviderErrorCategory = Schema.Literals([
|
||||
"invalid-request",
|
||||
"no-route",
|
||||
"authentication",
|
||||
"rate-limit",
|
||||
"quota-exceeded",
|
||||
"content-policy",
|
||||
"provider-internal",
|
||||
"transport",
|
||||
"invalid-provider-output",
|
||||
"unknown",
|
||||
])
|
||||
export type ProviderErrorCategory = typeof ProviderErrorCategory.Type
|
||||
|
||||
export interface ProviderError extends Schema.Schema.Type<typeof ProviderError> {}
|
||||
export const ProviderError = Schema.Struct({
|
||||
type: Schema.Literal("provider"),
|
||||
category: ProviderErrorCategory,
|
||||
message: Schema.String,
|
||||
status: Schema.Finite.pipe(Schema.optional),
|
||||
retryable: Schema.Boolean,
|
||||
retryAfterMs: Schema.Finite.pipe(Schema.optional),
|
||||
}).annotate({ identifier: "Session.Error.Provider" })
|
||||
|
||||
export const Error = Schema.Union([UnknownError, ProviderError]).pipe(Schema.toTaggedUnion("type"))
|
||||
export type Error = UnknownError | ProviderError
|
||||
|
||||
const Base = {
|
||||
id: ID,
|
||||
metadata: Schema.Record(Schema.String, Schema.Unknown).pipe(Schema.optional),
|
||||
|
|
@ -173,7 +200,7 @@ export const Assistant = Schema.Struct({
|
|||
reasoning: Schema.Finite,
|
||||
cache: Schema.Struct({ read: Schema.Finite, write: Schema.Finite }),
|
||||
}).pipe(Schema.optional),
|
||||
error: UnknownError.pipe(Schema.optional),
|
||||
error: Error.pipe(Schema.optional),
|
||||
time: Schema.Struct({
|
||||
created: DateTimeUtcFromMillis,
|
||||
completed: DateTimeUtcFromMillis.pipe(Schema.optional),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue