This commit is contained in:
Timothy Jaeryang Baek
2026-07-23 19:17:19 -04:00
parent f2dd88285a
commit 9a49b271aa
4 changed files with 22 additions and 15 deletions
+12 -10
View File
@@ -2157,23 +2157,25 @@ def extract_skill_ids_from_messages(messages: list[dict]) -> set[str]:
return ids
SKILL_MENTION_STRIP_RE = re.compile(r'<(?:\$[^|>]+(?:\|([^>]*))?|/[^|>]+\|([^>]*))>')
def strip_skill_mentions(messages: list[dict]) -> None:
"""Replace <$skillId|label> and </skillId|label> mention tags with the label in-place."""
strip_re = re.compile(r'<(?:\$[^|>]+(?:\|([^>]*))?|/[^|>]+\|([^>]*))>')
def label(match):
return match.group(1) or match.group(2) or ''
for message in messages:
content = message.get('content')
if isinstance(content, str) and strip_re.search(content):
message['content'] = strip_re.sub(label, content).strip()
if isinstance(content, str) and SKILL_MENTION_STRIP_RE.search(content):
message['content'] = SKILL_MENTION_STRIP_RE.sub(label, content).strip()
elif isinstance(content, list):
for part in content:
if isinstance(part, dict) and part.get('type') == 'text':
text = part.get('text', '')
if strip_re.search(text):
part['text'] = strip_re.sub(label, text).strip()
if SKILL_MENTION_STRIP_RE.search(text):
part['text'] = SKILL_MENTION_STRIP_RE.sub(label, text).strip()
async def connect_mcp_server(
@@ -4789,12 +4791,12 @@ async def streaming_chat_response_handler(response, ctx):
params = {}
if tool_args and tool_args.strip():
try:
params = ast.literal_eval(tool_args)
except Exception as e:
log.debug(e)
params = json.loads(tool_args)
except Exception:
try:
params = json.loads(tool_args)
except Exception:
params = ast.literal_eval(tool_args)
except Exception as e:
log.debug(e)
return None
tool_call.setdefault('function', {})['arguments'] = json.dumps(params)
return params
+6 -2
View File
@@ -207,6 +207,7 @@ async def load_tool_module_by_id(tool_id, content=None):
if not ENABLE_PLUGINS:
raise RuntimeError('Plugins are disabled by ENABLE_PLUGINS=false')
frontmatter = None
if content is None:
tool = await Tools.get_tool_by_id(tool_id)
if not tool:
@@ -238,7 +239,8 @@ async def load_tool_module_by_id(tool_id, content=None):
# Executing the modified content in the created module's namespace
exec(content, module.__dict__)
frontmatter = extract_frontmatter(content)
if frontmatter is None:
frontmatter = extract_frontmatter(content)
log.info(f'Loaded module: {module.__name__}')
# Create and return the object if the class 'Tools' is found in the module
@@ -258,6 +260,7 @@ async def load_function_module_by_id(function_id: str, content: str | None = Non
if not ENABLE_PLUGINS:
raise RuntimeError('Plugins are disabled by ENABLE_PLUGINS=false')
frontmatter = None
if content is None:
function = await Functions.get_function_by_id(function_id)
if not function:
@@ -286,7 +289,8 @@ async def load_function_module_by_id(function_id: str, content: str | None = Non
# Execute the modified content in the created module's namespace
exec(content, module.__dict__)
frontmatter = extract_frontmatter(content)
if frontmatter is None:
frontmatter = extract_frontmatter(content)
log.info(f'Loaded module: {module.__name__}')
# Create appropriate object based on available class type in the module