Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
feat: typescript deps in ade
Andy Li1ff243459838
diff --git a/letta/schemas/tool.py b/letta/schemas/tool.pyindex 92022fa23..6dd77ac6d 100644--- a/letta/schemas/tool.py+++ b/letta/schemas/tool.py@@ -1,6 +1,6 @@from typing import Any, Dict, List, Optional-from pydantic import Field, model_validator+from pydantic import ConfigDict, Field, model_validatorfrom letta.constants import (COMPOSIO_TOOL_TAG_NAME,@@ -237,10 +237,10 @@ class ToolUpdate(LettaBase):return_char_limit: Optional[int] = Field(None, description="The maximum number of characters in the response.")pip_requirements: list[PipRequirement] | None = Field(None, description="Optional list of pip packages required by this tool.")npm_requirements: list[NpmRequirement] | None = Field(None, description="Optional list of npm packages required by this tool.")+ metadata_: Optional[Dict[str, Any]] = Field(None, description="A dictionary of additional metadata for the tool.")- class Config:- extra = "ignore" # Allows extra fields without validation errors- # TODO: Remove this, and clean usage of ToolUpdate everywhere else+ model_config = ConfigDict(extra="ignore") # Allows extra fields without validation errors+ # TODO: Remove this, and clean usage of ToolUpdate everywhere elseclass ToolRunFromSource(LettaBase):diff --git a/letta/server/rest_api/routers/v1/tools.py b/letta/server/rest_api/routers/v1/tools.pyindex e841a64f6..1e2e81391 100644--- a/letta/server/rest_api/routers/v1/tools.py+++ b/letta/server/rest_api/routers/v1/tools.py@@ -774,7 +774,8 @@ async def connect_mcp_server(class CodeInput(BaseModel):- code: str = Field(..., description="Python source code to parse for JSON schema")+ code: str = Field(..., description="Source code to parse for JSON schema")+ source_type: Optional[str] = Field("python", description="The source type of the code (python or typescript)")@router.post("/generate-schema", response_model=Dict[str, Any], operation_id="generate_json_schema")@@ -784,10 +785,17 @@ async def generate_json_schema(actor_id: Optional[str] = Header(None, alias="user_id"),):"""- Generate a JSON schema from the given Python source code defining a function or class.+ Generate a JSON schema from the given source code defining a function or class.+ Supports both Python and TypeScript source code."""try:- schema = derive_openai_json_schema(source_code=request.code)+ if request.source_type == "typescript":+ from letta.functions.typescript_parser import derive_typescript_json_schema++ schema = derive_typescript_json_schema(source_code=request.code)+ else:+ # Default to Python for backwards compatibility+ schema = derive_openai_json_schema(source_code=request.code)return schemaexcept Exception as e:diff --git a/letta/services/tool_manager.py b/letta/services/tool_manager.pyindex c798af93b..966029216 100644--- a/letta/services/tool_manager.py+++ b/letta/services/tool_manager.py@@ -459,7 +459,16 @@ class ToolManager:else:# For non-MCP tools, preserve existing behaviorif "source_code" in update_data.keys() and not bypass_name_check:- derived_schema = derive_openai_json_schema(source_code=update_data["source_code"])+ # Check source type to use appropriate parser+ source_type = update_data.get("source_type", current_tool.source_type)+ if source_type == "typescript":+ from letta.functions.typescript_parser import derive_typescript_json_schema++ derived_schema = derive_typescript_json_schema(source_code=update_data["source_code"])+ else:+ # Default to Python for backwards compatibility+ derived_schema = derive_openai_json_schema(source_code=update_data["source_code"])+new_name = derived_schema["name"]if "json_schema" not in update_data.keys():new_schema = derived_schema@@ -533,8 +542,15 @@ class ToolManager:# TODO: I feel like it's bad if json_schema strays from source code so# if source code is provided, always derive the name from itif "source_code" in update_data.keys() and not bypass_name_check:- # derive the schema from source code to get the function name- derived_schema = derive_openai_json_schema(source_code=update_data["source_code"])+ # Check source type to use appropriate parser+ source_type = update_data.get("source_type", current_tool.source_type)+ if source_type == "typescript":+ from letta.functions.typescript_parser import derive_typescript_json_schema++ derived_schema = derive_typescript_json_schema(source_code=update_data["source_code"])+ else:+ # Default to Python for backwards compatibility+ derived_schema = derive_openai_json_schema(source_code=update_data["source_code"])new_name = derived_schema["name"]# if json_schema wasn't provided, use the derived schema