Skip to content

Commit

Permalink
feat: Debug agent.execute
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat authored and mirceanis committed Sep 7, 2020
1 parent c936a00 commit fb58ddc
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/daf-core/src/agent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IAgentBase, TMethodMap, IAgentPlugin } from './types'
import Debug from 'debug'

export class Agent implements IAgentBase {
readonly methods: TMethodMap = {}
Expand Down Expand Up @@ -30,7 +31,10 @@ export class Agent implements IAgentBase {
}

async execute<P = any, R = any>(method: string, args: P): Promise<R> {
Debug('daf:agent:' + method)('%o', args)
if (!this.methods[method]) throw Error('Method not available: ' + method)
return this.methods[method](args, { ...this.context, agent: this })
const result = await this.methods[method](args, { ...this.context, agent: this })
Debug('daf:agent:' + method + ':result')('%o', result)
return result
}
}

0 comments on commit fb58ddc

Please sign in to comment.