MCPcopy Create free account
hub / github.com/tiann/hapi / updateAgentState

Method updateAgentState

cli/src/api/apiSession.ts:647–681  ·  view source on GitHub ↗
(handler: (state: AgentState) => AgentState)

Source from the content-addressed store, hash-verified

645 }
646
647 updateAgentState(handler: (state: AgentState) => AgentState): void {
648 this.agentStateLock.inLock(async () => {
649 await backoff(async () => {
650 const current = this.agentState ?? ({} as AgentState)
651 const updated = handler(current)
652
653 const answer = await this.socket.emitWithAck('update-state', {
654 sid: this.sessionId,
655 expectedVersion: this.agentStateVersion,
656 agentState: updated
657 }) as unknown
658
659 applyVersionedAck(answer, {
660 valueKey: 'agentState',
661 parseValue: (value) => {
662 const parsed = AgentStateSchema.safeParse(value)
663 return parsed.success ? parsed.data : null
664 },
665 applyValue: (value) => {
666 this.agentState = value
667 },
668 applyVersion: (version) => {
669 this.agentStateVersion = version
670 },
671 logInvalidValue: (context, version) => {
672 const suffix = context === 'success' ? 'ack' : 'version-mismatch ack'
673 logger.debug(`[API] Ignoring invalid agentState value from ${suffix}`, { version })
674 },
675 invalidResponseMessage: 'Invalid update-state response',
676 errorMessage: 'Agent state update failed',
677 versionMismatchMessage: 'Agent state version mismatch'
678 })
679 })
680 })
681 }
682
683 private async waitForConnected(timeoutMs: number): Promise<boolean> {
684 if (this.socket.connected) {

Callers 15

autoApproveMethod · 0.80
addPendingRequestFunction · 0.80
finalizeRequestFunction · 0.80
cancelPendingRequestsFunction · 0.80
handleBlockingRequestMethod · 0.80
handleResponseMethod · 0.80
cancelAllMethod · 0.80
handleHookEventFunction · 0.80
autoApproveMethod · 0.80
denyForPlanModeMethod · 0.80
completeAutoApprovalMethod · 0.80
setControlledByUserFunction · 0.80

Calls 4

applyVersionedAckFunction · 0.90
handlerFunction · 0.85
inLockMethod · 0.80
debugMethod · 0.80

Tested by

no test coverage detected