@@ -17,6 +17,8 @@ type AuthContext = { ok: true; agentId?: string } | { ok: false; response: Respo
1717type DirectReadMode = "full" | "since_breakpoint" | "since_message" ;
1818type InboxMode = "unread" | "all" | "recent" ;
1919type MarkReadTargetType = "thread" | "conversation" | "suggestion" | "mention" | "todo" ;
20+ type LiveReceiptState = "active" | "waiting_on_peer" | "waiting_on_operator" | "settled_by_agent" | "operator_stop_needed" ;
21+ type LiveSessionStatus = LiveReceiptState | "stopped" ;
2022type ForumSpec = {
2123 slug : string ;
2224 name : string ;
@@ -54,6 +56,8 @@ const markReadAcceptedAliases = {
5456 mention : [ "mentions" ] ,
5557 todo : [ "todos" ] ,
5658} ;
59+ const liveReceiptStates : LiveReceiptState [ ] = [ "active" , "waiting_on_peer" , "waiting_on_operator" , "settled_by_agent" , "operator_stop_needed" ] ;
60+ const liveSessionStatuses : LiveSessionStatus [ ] = [ ...liveReceiptStates , "stopped" ] ;
5761
5862declare class D1Database {
5963 prepare ( query : string ) : D1PreparedStatement ;
@@ -701,7 +705,7 @@ function apiSchemas() {
701705 forumThreadFields : [ "readState" , "unread" , "visibilityReason" , "latestItemId" , "latestItemAt" , "lastReadItemId" , "lastReadAt" ] ,
702706 } ,
703707 heartbeat : "GET /agent/heartbeat/:agentId" ,
704- liveReceipt : { agentId : "string" , state : [ "active" , "waiting_on_peer" , "settled_by_agent" , "operator_stop_needed" ] , note : "string" , lastSeenMessageId : "string optional" } ,
708+ liveReceipt : { agentId : "string" , state : liveReceiptStates , note : "string" , lastSeenMessageId : "string optional" } ,
705709 gate : { title : "string" , body : "string" , producerAgentId : "string" , consumerAgentId : "string" , ownerAgentId : "string" , requiredEvidence : "string[]" } ,
706710 gateStatus : { agentId : "string" , status : [ "open" , "waiting" , "satisfied" , "blocked" , "closed" ] , evidence : "string[] optional" } ,
707711 } ,
@@ -2335,7 +2339,7 @@ async function listLiveConversations(env: Env, status?: string | null) {
23352339
23362340async function updateLiveConversation ( request : Request , env : Env , sessionId : string ) {
23372341 const input = await body ( request ) ;
2338- if ( ! [ "active" , "waiting_on_peer" , "settled_by_agent" , "operator_stop_needed" , "stopped" ] . includes ( String ( input . status ) ) ) {
2342+ if ( ! liveSessionStatuses . includes ( String ( input . status ) as LiveSessionStatus ) ) {
23392343 return json ( { error : "Invalid live conversation status." } , 400 ) ;
23402344 }
23412345 const db = requireDb ( env ) ;
@@ -2359,7 +2363,7 @@ async function upsertLiveReceipt(request: Request, env: Env, sessionId: string,
23592363 const input = await body ( request ) ;
23602364 const agentId = String ( input . agentId ?? "" ) ;
23612365 const state = String ( input . state ?? "" ) ;
2362- if ( ! [ "active" , "waiting_on_peer" , "settled_by_agent" , "operator_stop_needed" ] . includes ( state ) ) {
2366+ if ( ! liveReceiptStates . includes ( state as LiveReceiptState ) ) {
23632367 return json ( { error : "Invalid receipt state." } , 400 ) ;
23642368 }
23652369 const database = db . db ;
@@ -2396,6 +2400,8 @@ async function upsertLiveReceipt(request: Request, env: Env, sessionId: string,
23962400 ) ;
23972401 const nextStatus = receipts . some ( ( receipt ) => receipt . state === "operator_stop_needed" ) || settled
23982402 ? "operator_stop_needed"
2403+ : receipts . some ( ( receipt ) => receipt . state === "waiting_on_operator" )
2404+ ? "waiting_on_operator"
23992405 : receipts . some ( ( receipt ) => receipt . state === "waiting_on_peer" )
24002406 ? "waiting_on_peer"
24012407 : "active" ;
0 commit comments