Expose recorded background task timing and progress metadata
This commit is contained in:
+17
-8
@@ -818,12 +818,14 @@ func (c *Chat) handleNotification(msg rpcMessage) {
|
||||
return
|
||||
}
|
||||
var params struct {
|
||||
ThreadID string `json:"threadId"`
|
||||
TurnID string `json:"turnId"`
|
||||
ItemID string `json:"itemId"`
|
||||
Delta string `json:"delta"`
|
||||
Item json.RawMessage `json:"item"`
|
||||
Turn struct {
|
||||
StartedAtMS int64 `json:"startedAtMs"`
|
||||
CompletedAtMS int64 `json:"completedAtMs"`
|
||||
ThreadID string `json:"threadId"`
|
||||
TurnID string `json:"turnId"`
|
||||
ItemID string `json:"itemId"`
|
||||
Delta string `json:"delta"`
|
||||
Item json.RawMessage `json:"item"`
|
||||
Turn struct {
|
||||
ID string `json:"id"`
|
||||
Status string `json:"status"`
|
||||
} `json:"turn"`
|
||||
@@ -861,9 +863,9 @@ func (c *Chat) handleNotification(msg rpcMessage) {
|
||||
c.mu.Unlock()
|
||||
c.emit(stepFrame(params.ThreadID, protocol.ChatStepEnded, completedID))
|
||||
case "item/started":
|
||||
c.handleItem(params.ThreadID, params.ItemID, params.Item, false, params.TurnID)
|
||||
c.handleTimedItem(params.ThreadID, params.ItemID, params.Item, false, params.StartedAtMS, 0, params.TurnID)
|
||||
case "item/completed":
|
||||
c.handleItem(params.ThreadID, params.ItemID, params.Item, true, params.TurnID)
|
||||
c.handleTimedItem(params.ThreadID, params.ItemID, params.Item, true, 0, params.CompletedAtMS, params.TurnID)
|
||||
case "thread/compacted":
|
||||
// Deprecated ContextCompactedNotification has only threadId/turnId.
|
||||
// Modern item lifecycles are correlated more precisely; never let this
|
||||
@@ -890,6 +892,10 @@ func (c *Chat) handleNotification(msg rpcMessage) {
|
||||
}
|
||||
|
||||
func (c *Chat) handleItem(threadID, itemID string, raw json.RawMessage, completed bool, nativeTurnID ...string) {
|
||||
c.handleTimedItem(threadID, itemID, raw, completed, 0, 0, nativeTurnID...)
|
||||
}
|
||||
|
||||
func (c *Chat) handleTimedItem(threadID, itemID string, raw json.RawMessage, completed bool, startedAt, completedAt int64, nativeTurnID ...string) {
|
||||
var record item
|
||||
if err := json.Unmarshal(raw, &record); err != nil {
|
||||
return
|
||||
@@ -897,6 +903,7 @@ func (c *Chat) handleItem(threadID, itemID string, raw json.RawMessage, complete
|
||||
if record.ID == "" {
|
||||
record.ID = itemID
|
||||
}
|
||||
record.startedAtMS, record.completedAtMS = startedAt, completedAt
|
||||
switch record.Type {
|
||||
case "contextCompaction":
|
||||
if record.ID == "" {
|
||||
@@ -994,6 +1001,8 @@ func (t turn) createdAtMillis() int64 {
|
||||
}
|
||||
|
||||
type item struct {
|
||||
startedAtMS int64
|
||||
completedAtMS int64
|
||||
Raw json.RawMessage `json:"-"`
|
||||
ID string `json:"id"`
|
||||
ClientID string `json:"clientId"`
|
||||
|
||||
Reference in New Issue
Block a user