支持部分agent实时更新上下文用量信息
This commit is contained in:
@@ -33,6 +33,7 @@ import type {
|
||||
PermissionOptionInfo,
|
||||
SessionConfigOptionInfo,
|
||||
SessionModeStateInfo,
|
||||
SessionUsageUpdateInfo,
|
||||
FixAction,
|
||||
PromptCapabilitiesInfo,
|
||||
PromptInputBlock,
|
||||
@@ -88,6 +89,7 @@ export interface ConnectionState {
|
||||
modes: SessionModeStateInfo | null
|
||||
configOptions: SessionConfigOptionInfo[] | null
|
||||
availableCommands: AvailableCommandInfo[] | null
|
||||
usage: SessionUsageUpdateInfo | null
|
||||
liveMessage: LiveMessage | null
|
||||
pendingPermission: PendingPermission | null
|
||||
error: string | null
|
||||
@@ -177,6 +179,11 @@ type Action =
|
||||
contextKey: string
|
||||
commands: AvailableCommandInfo[]
|
||||
}
|
||||
| {
|
||||
type: "USAGE_UPDATE"
|
||||
contextKey: string
|
||||
usage: SessionUsageUpdateInfo
|
||||
}
|
||||
|
||||
type StreamingAction =
|
||||
| { type: "CONTENT_DELTA"; contextKey: string; text: string }
|
||||
@@ -441,6 +448,7 @@ function connectionsReducer(
|
||||
modes: null,
|
||||
configOptions: null,
|
||||
availableCommands: null,
|
||||
usage: null,
|
||||
liveMessage: null,
|
||||
pendingPermission: null,
|
||||
error: null,
|
||||
@@ -883,6 +891,23 @@ function connectionsReducer(
|
||||
return next
|
||||
}
|
||||
|
||||
case "USAGE_UPDATE": {
|
||||
const conn = state.get(action.contextKey)
|
||||
if (!conn) return state
|
||||
if (
|
||||
conn.usage?.used === action.usage.used &&
|
||||
conn.usage?.size === action.usage.size
|
||||
) {
|
||||
return state
|
||||
}
|
||||
const next = new Map(state)
|
||||
next.set(action.contextKey, {
|
||||
...conn,
|
||||
usage: action.usage,
|
||||
})
|
||||
return next
|
||||
}
|
||||
|
||||
default:
|
||||
return state
|
||||
}
|
||||
@@ -1395,6 +1420,17 @@ export function AcpConnectionsProvider({ children }: { children: ReactNode }) {
|
||||
commands: e.commands,
|
||||
})
|
||||
break
|
||||
case "usage_update":
|
||||
flushStreamingQueue()
|
||||
dispatch({
|
||||
type: "USAGE_UPDATE",
|
||||
contextKey,
|
||||
usage: {
|
||||
used: e.used,
|
||||
size: e.size,
|
||||
},
|
||||
})
|
||||
break
|
||||
}
|
||||
},
|
||||
[dispatch, enqueueStreamingAction, flushStreamingQueue, t]
|
||||
|
||||
Reference in New Issue
Block a user