Refactor agent loop (#4412)

This commit is contained in:
Dax
2025-11-17 10:57:18 -05:00
committed by GitHub
parent 9fd43ec616
commit a1214fff2e
22 changed files with 1297 additions and 1324 deletions

View File

@@ -26,6 +26,9 @@ import type {
SessionCreateData,
SessionCreateResponses,
SessionCreateErrors,
SessionStatusData,
SessionStatusResponses,
SessionStatusErrors,
SessionDeleteData,
SessionDeleteResponses,
SessionDeleteErrors,
@@ -306,6 +309,16 @@ class Session extends _HeyApiClient {
})
}
/**
* Get session status
*/
public status<ThrowOnError extends boolean = false>(options?: Options<SessionStatusData, ThrowOnError>) {
return (options?.client ?? this._client).get<SessionStatusResponses, SessionStatusErrors, ThrowOnError>({
url: "/session/status",
...options,
})
}
/**
* Delete a session and all its data
*/

View File

@@ -42,6 +42,15 @@ export type UserMessage = {
body?: string
diffs: Array<FileDiff>
}
agent: string
model: {
providerID: string
modelID: string
}
system?: string
tools?: {
[key: string]: boolean
}
}
export type ProviderAuthError = {
@@ -114,6 +123,7 @@ export type AssistantMessage = {
write: number
}
}
finish?: string
}
export type Message = UserMessage | AssistantMessage
@@ -348,6 +358,13 @@ export type RetryPart = {
}
}
export type CompactionPart = {
id: string
sessionID: string
messageID: string
type: "compaction"
}
export type Part =
| TextPart
| ReasoningPart
@@ -359,6 +376,7 @@ export type Part =
| PatchPart
| AgentPart
| RetryPart
| CompactionPart
export type EventMessagePartUpdated = {
type: "message.part.updated"
@@ -377,13 +395,6 @@ export type EventMessagePartRemoved = {
}
}
export type EventSessionCompacted = {
type: "session.compacted"
properties: {
sessionID: string
}
}
export type Permission = {
id: string
type: string
@@ -414,6 +425,13 @@ export type EventPermissionReplied = {
}
}
export type EventSessionCompacted = {
type: "session.compacted"
properties: {
sessionID: string
}
}
export type EventFileEdited = {
type: "file.edited"
properties: {
@@ -458,6 +476,27 @@ export type EventCommandExecuted = {
}
}
export type SessionStatus =
| {
type: "idle"
}
| {
type: "retry"
attempt: number
message: string
}
| {
type: "busy"
}
export type EventSessionStatus = {
type: "session.status"
properties: {
sessionID: string
status: SessionStatus
}
}
export type EventSessionIdle = {
type: "session.idle"
properties: {
@@ -598,12 +637,13 @@ export type Event =
| EventMessageRemoved
| EventMessagePartUpdated
| EventMessagePartRemoved
| EventSessionCompacted
| EventPermissionUpdated
| EventPermissionReplied
| EventSessionCompacted
| EventFileEdited
| EventTodoUpdated
| EventCommandExecuted
| EventSessionStatus
| EventSessionIdle
| EventSessionCreated
| EventSessionUpdated
@@ -1613,6 +1653,35 @@ export type SessionCreateResponses = {
export type SessionCreateResponse = SessionCreateResponses[keyof SessionCreateResponses]
export type SessionStatusData = {
body?: never
path?: never
query?: {
directory?: string
}
url: "/session/status"
}
export type SessionStatusErrors = {
/**
* Bad request
*/
400: BadRequestError
}
export type SessionStatusError = SessionStatusErrors[keyof SessionStatusErrors]
export type SessionStatusResponses = {
/**
* Get session status
*/
200: {
[key: string]: SessionStatus
}
}
export type SessionStatusResponse = SessionStatusResponses[keyof SessionStatusResponses]
export type SessionDeleteData = {
body?: never
path: {