File size: 1,363 Bytes
2814685
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# coding: utf-8
# Copyright (c) 2025 inclusionAI.

HOOK_TEMPLATE = """
import traceback

from aworld.core.context.base import Context

from aworld.core.event.base import Message, Constants, TopicType
from aworld.runners.hook.hooks import *
from aworld.runners.hook.hook_factory import HookFactory
from aworld.logs.util import logger

from aworld.utils.common import convert_to_snake


@HookFactory.register(name="{name}",
                      desc="{desc}")
class {name}({point}Hook):
    def name(self):
        return convert_to_snake("{name}")

    async def exec(self, message: Message) -> Message:
        {func_import}import {func}
        try:
            res = {func}(message)
            if not res:
                raise ValueError(f"{func} no result return.")
            return Message(payload=res,
                           session_id=Context.instance().session_id,
                           sender="{name}",
                           category=Constants.TASK,
                           topic="{topic}")
        except Exception as e:
            logger.error(traceback.format_exc())
            return Message(payload=str(e),
                           session_id=Context.instance().session_id,
                           sender="{name}",
                           category=Constants.TASK,
                           topic=TopicType.ERROR)
"""