Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions backend/consensus/decisions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from typing import Any

from backend.node.types import NodeConfig
from backend.consensus.effects import (
AddTimestampEffect,
StatusUpdateEffect,
Expand Down Expand Up @@ -320,7 +321,7 @@ def decide_accepted(
contract_address: str | None,
code_slot_b64: str | None,
to_address: str,
leader_node_config: dict,
leader_node_config: NodeConfig,
) -> tuple[list[Effect], list[Effect], ConsensusRound, ConsensusRound | None]:
"""Decide effects for AcceptedState.

Expand Down Expand Up @@ -478,7 +479,7 @@ def decide_finalizing(
tx_hash: str,
tx_status_accepted: bool,
execution_result_success: bool,
leader_node_config: dict,
leader_node_config: NodeConfig,
) -> tuple[list[Effect], list[Effect], bool]:
"""Decide effects for FinalizingState.

Expand Down
29 changes: 25 additions & 4 deletions backend/domain/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,40 @@
import datetime
from enum import Enum, IntEnum
import os
from typing import NotRequired, TypedDict
from backend.database_handler.models import TransactionStatus
from backend.database_handler.types import ConsensusData
from backend.database_handler.contract_snapshot import ContractSnapshot


class LLMProviderConfig(TypedDict, total=False):
temperature: float
max_tokens: int
use_max_completion_tokens: bool


class PluginConfig(TypedDict, total=False):
api_key_env_var: str
api_url: str
mock_response: dict
Comment on lines +21 to +24
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Missing mock_web_response field in PluginConfig.

Based on the relevant code snippet from backend/validators/__init__.py:203-215, the mock_web_response key is actively read from plugin_config:

if (
    "mock_web_response" in val.llmprovider.plugin_config
    and len(val.llmprovider.plugin_config["mock_web_response"]) > 0
):

This field should be added to PluginConfig to ensure type consistency and avoid type checker warnings.

Proposed fix
 class PluginConfig(TypedDict, total=False):
     api_key_env_var: str
     api_url: str
     mock_response: dict
+    mock_web_response: dict
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/domain/types.py` around lines 21 - 24, The PluginConfig TypedDict is
missing the mock_web_response key used elsewhere; update the PluginConfig
definition to include a mock_web_response field (same shape as other mock
fields, e.g., mock_web_response: dict) so type checkers recognize accesses like
plugin_config["mock_web_response"] and avoid warnings; modify the PluginConfig
class in types.py to add this field.



class ProviderParams(TypedDict):
provider: str
model: str
config: LLMProviderConfig
plugin: str
plugin_config: PluginConfig


@dataclass
class SimValidatorConfig:
stake: int
provider: str
model: str
config: dict
config: LLMProviderConfig
plugin: str
plugin_config: dict
plugin_config: PluginConfig

@classmethod
def from_dict(cls, d: dict) -> "SimValidatorConfig":
Expand Down Expand Up @@ -80,9 +101,9 @@ def to_dict(self) -> dict:
class LLMProvider:
provider: str
model: str
config: dict
config: LLMProviderConfig
plugin: str
plugin_config: dict
plugin_config: PluginConfig
id: int | None = None

def __hash__(self):
Expand Down
4 changes: 2 additions & 2 deletions backend/node/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import backend.node.genvm.base as genvmbase
import backend.node.genvm.origin.calldata as calldata
from backend.database_handler.contract_snapshot import ContractSnapshot
from backend.node.types import Receipt, ExecutionMode, Vote, ExecutionResultStatus
from backend.node.types import Receipt, ExecutionMode, Vote, ExecutionResultStatus, NodeConfig
from backend.protocol_rpc.message_handler.base import IMessageHandler
from .genvm.origin import logger as genvm_logger
from .genvm.origin import public_abi
Expand Down Expand Up @@ -659,7 +659,7 @@ async def exec_transaction(self, transaction: Transaction) -> Receipt:

return receipt

def _create_enhanced_node_config(self, host_data: dict | None) -> dict:
def _create_enhanced_node_config(self, host_data: dict | None) -> NodeConfig:
"""
Create enhanced node_config that includes both primary and fallback provider info.

Expand Down
19 changes: 17 additions & 2 deletions backend/node/types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dataclasses import dataclass, field
from enum import Enum
from typing import Iterable, Optional, Literal
from typing import Iterable, Optional, Literal, NotRequired, TypedDict
import base64
import hashlib
import json
Expand Down Expand Up @@ -226,14 +226,29 @@ def from_dict(cls, input: dict) -> "PendingTransaction":
)


class NodeConfig(TypedDict, total=False):
address: str
stake: int
provider: str
model: str
config: dict
plugin: str
plugin_config: dict
private_key: str | None
fallback_validator: str | None
id: int
primary_model: dict | None
secondary_model: dict | None


@dataclass
class Receipt:
result: bytes
calldata: bytes
gas_used: int
mode: ExecutionMode
contract_state: dict[str, str]
node_config: dict
node_config: NodeConfig
execution_result: ExecutionResultStatus
eq_outputs: dict[int, str] | None = None
vote: Optional[Vote] = None
Expand Down
14 changes: 7 additions & 7 deletions backend/protocol_rpc/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from backend.database_handler.llm_providers import LLMProviderRegistry
from backend.rollup.consensus_service import ConsensusService
from backend.database_handler.models import Base, TransactionStatus
from backend.domain.types import LLMProvider, Validator, TransactionType, SimConfig
from backend.domain.types import LLMProvider, LLMProviderConfig, PluginConfig, ProviderParams, Validator, TransactionType, SimConfig
from backend.node.create_nodes.providers import (
get_default_provider_for,
validate_provider,
Expand Down Expand Up @@ -270,7 +270,7 @@ async def check_with_semaphore(genvm_manager, provider):


@check_forbidden_method_in_hosted_studio
def add_provider(session: Session, params: dict) -> int:
def add_provider(session: Session, params: ProviderParams) -> int:
"""Add a provider using the request-scoped session."""
llm_provider_registry = LLMProviderRegistry(session)

Expand All @@ -288,7 +288,7 @@ def add_provider(session: Session, params: dict) -> int:


@check_forbidden_method_in_hosted_studio
def update_provider(session: Session, id: int, params: dict) -> None:
def update_provider(session: Session, id: int, params: ProviderParams) -> None:
"""Update a provider using the request-scoped session."""
llm_provider_registry = LLMProviderRegistry(session)

Expand Down Expand Up @@ -317,9 +317,9 @@ async def create_validator(
stake: int,
provider: str,
model: str,
config: dict | None = None,
config: LLMProviderConfig | None = None,
plugin: str | None = None,
plugin_config: dict | None = None,
plugin_config: PluginConfig | None = None,
) -> dict:
# fallback for default provider
llm_provider = None
Expand Down Expand Up @@ -420,9 +420,9 @@ async def update_validator(
stake: int,
provider: str,
model: str,
config: dict | None = None,
config: LLMProviderConfig | None = None,
plugin: str | None = None,
plugin_config: dict | None = None,
plugin_config: PluginConfig | None = None,
) -> dict:
# Remove validation while adding migration to update the db address
# if not accounts_manager.is_valid_address(validator_address):
Expand Down
11 changes: 6 additions & 5 deletions backend/protocol_rpc/rpc_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
)
from backend.protocol_rpc.rpc_decorators import rpc
from backend.protocol_rpc.rpc_endpoint_manager import LogPolicy
from backend.domain.types import LLMProviderConfig, PluginConfig, ProviderParams


# ---------------------------------------------------------------------------
Expand Down Expand Up @@ -79,7 +80,7 @@ def reset_defaults_llm_providers(

@rpc.method("sim_addProvider")
def add_provider(
params: dict,
params: ProviderParams,
session: Session = Depends(get_db_session),
) -> int:
return impl.add_provider(session=session, params=params)
Expand All @@ -88,7 +89,7 @@ def add_provider(
@rpc.method("sim_updateProvider")
def update_provider(
id: int,
params: dict,
params: ProviderParams,
session: Session = Depends(get_db_session),
) -> None:
return impl.update_provider(session=session, id=id, params=params)
Expand All @@ -107,9 +108,9 @@ async def create_validator(
stake: int,
provider: str,
model: str,
config: dict | None = None,
config: LLMProviderConfig | None = None,
plugin: str | None = None,
plugin_config: dict | None = None,
plugin_config: PluginConfig | None = None,
session: Session = Depends(get_db_session),
validators_manager=Depends(get_validators_manager),
) -> dict:
Expand Down Expand Up @@ -170,7 +171,7 @@ async def update_validator(
provider: str | None = None,
model: str | None = None,
plugin: str | None = None,
plugin_config: dict | None = None,
plugin_config: PluginConfig | None = None,
session: Session = Depends(get_db_session),
validators_manager=Depends(get_validators_manager),
) -> dict:
Expand Down