Skip to content

Commit fb1e271

Browse files
committed
fix:Don't set default imageId
1 parent 26465cf commit fb1e271

5 files changed

Lines changed: 22 additions & 131 deletions

File tree

agb/agb.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from agb.api.client import Client as mcp_client
1313
from agb.api.models import (
1414
CreateSessionRequest,
15-
GetMcpResourceRequest,
1615
ReleaseSessionRequest,
1716
CreateSessionResponse,
1817
)
@@ -50,8 +49,8 @@ def __init__(self, api_key: str = "", cfg: Optional[Config] = None):
5049
self.config = load_config(cfg)
5150

5251
self.api_key = api_key
53-
self.endpoint = self.config .endpoint
54-
self.timeout_ms = self.config .timeout_ms
52+
self.endpoint = self.config.endpoint
53+
self.timeout_ms = self.config.timeout_ms
5554

5655
# Initialize the HTTP API client with the complete config
5756
self.client = mcp_client(self.config)
@@ -76,14 +75,19 @@ def create(self, params: Optional[CreateSessionParams] = None) -> SessionResult:
7675

7776
request = CreateSessionRequest(authorization=f"Bearer {self.api_key}")
7877

79-
# Use default image if no image_id specified
80-
if not params.image_id:
81-
params.image_id = "code_latest"
82-
else:
78+
if params.image_id:
8379
request.image_id = params.image_id
8480

8581
response : CreateSessionResponse = self.client.create_mcp_session(request)
8682

83+
# Check if response is empty
84+
if response is None:
85+
return SessionResult(
86+
request_id="",
87+
success=False,
88+
error_message="OpenAPI client returned None response",
89+
)
90+
8791
try:
8892
print("Response body:")
8993
print(response.to_dict())

agb/api/base_service.py

Lines changed: 2 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ def _call_mcp_tool(self, name: str, args: Dict[str, Any], read_timeout: int = No
8383

8484
if response.is_tool_successful():
8585
# Tool execution successful
86-
print("response.json_data =", response.json_data)
87-
result = self._parse_response_body(response.json_data or {})
86+
result = response.get_tool_result()
8887
return OperationResult(request_id=request_id, success=True, data=result)
8988
else:
9089
# Tool execution failed
@@ -120,105 +119,4 @@ def _call_mcp_tool(self, name: str, args: Dict[str, Any], read_timeout: int = No
120119
request_id=request_id,
121120
success=False,
122121
error_message=f"Failed to call MCP tool {name}: {handled_error}",
123-
)
124-
125-
def _sanitize_error(self, error_str: str) -> str:
126-
"""
127-
Sanitizes error messages to remove sensitive information like API keys.
128-
129-
Args:
130-
error_str (str): The error string to sanitize.
131-
132-
Returns:
133-
str: The sanitized error string.
134-
"""
135-
import re
136-
137-
if not error_str:
138-
return error_str
139-
140-
# Remove API key from URLs
141-
# Pattern: apiKey=akm-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
142-
api_key_pattern = re.compile(r'apiKey=akm-[a-f0-9-]+')
143-
error_str = api_key_pattern.sub('apiKey=***REDACTED***', error_str)
144-
145-
# Remove API key from Bearer tokens
146-
# Pattern: Bearer akm-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
147-
bearer_pattern = re.compile(r'Bearer akm-[a-f0-9-]+')
148-
error_str = bearer_pattern.sub('Bearer ***REDACTED***', error_str)
149-
150-
# Remove API key from query parameters
151-
# Pattern: &apiKey=akm-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
152-
query_pattern = re.compile(r'&apiKey=akm-[a-f0-9-]+')
153-
error_str = query_pattern.sub('&apiKey=***REDACTED***', error_str)
154-
155-
# Remove API key from URL paths
156-
# Pattern: /callTool?apiKey=akm-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
157-
url_pattern = re.compile(r'/callTool\?apiKey=akm-[a-f0-9-]+')
158-
error_str = url_pattern.sub('/callTool?apiKey=***REDACTED***', error_str)
159-
160-
return error_str
161-
162-
def _parse_response_body(
163-
self, body: Dict[str, Any], parse_json: bool = False
164-
) -> Any:
165-
"""
166-
Parses the response body from the MCP tool.
167-
168-
Args:
169-
body (Dict[str, Any]): The response body.
170-
parse_json (bool, optional): Whether to parse the text as JSON.
171-
Defaults to False.
172-
173-
Returns:
174-
Any: The parsed content. If parse_json is True, returns the parsed
175-
JSON object; otherwise returns the raw text.
176-
177-
178-
Raises:
179-
AGBError: If the response contains errors or is invalid.
180-
"""
181-
try:
182-
response_data = body.get("data", {})
183-
if response_data.get("isError", False):
184-
error_content = response_data.get("content", [])
185-
try:
186-
print("error_content =")
187-
print(json.dumps(error_content, ensure_ascii=False, indent=2))
188-
except Exception:
189-
print(f"error_content: {error_content}")
190-
error_message = "; ".join(
191-
item.get("text", "Unknown error")
192-
for item in error_content
193-
if isinstance(item, dict)
194-
)
195-
raise AGBError(f"Error in response: {error_message}")
196-
197-
198-
if not response_data:
199-
raise AGBError("No data field in response")
200-
201-
# Handle 'content' field for other methods
202-
content = response_data.get("content", [])
203-
if not content or not isinstance(content, list):
204-
raise AGBError("No content found in response")
205-
206-
content_item = content[0]
207-
text_string = content_item.get("text")
208-
209-
# Allow text field to be empty string
210-
if text_string is None:
211-
raise AGBError("Text field not found in response")
212-
213-
return text_string
214-
215-
except AGBError as e:
216-
# Transform AGBError to the expected type
217-
handled_error = self._handle_error(e)
218-
raise handled_error
219-
except Exception as e:
220-
# Transform AGBError to the expected type
221-
handled_error = self._handle_error(
222-
AGBError(f"Error parsing response body: {e}")
223-
)
224-
raise handled_error
122+
)

agb/api/models/create_session_response.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def __init__(
6767
success: bool,
6868
json_data: Optional[Dict[str, Any]] = None,
6969
text: Optional[str] = None,
70+
error: Optional[str] = None,
7071
request_id: Optional[str] = None
7172
):
7273
self.status_code = status_code
@@ -75,6 +76,7 @@ def __init__(
7576
self.success = success
7677
self.json_data = json_data
7778
self.text = text
79+
self.error = error
7880
self.request_id = request_id
7981

8082
# Parse fields from JSON data
@@ -124,6 +126,8 @@ def get_resource_url(self) -> Optional[str]:
124126

125127
def get_error_message(self) -> str:
126128
"""Get error message"""
129+
if self.error:
130+
return self.error
127131
if self.data and self.data.err_msg:
128132
return self.data.err_msg
129133
if self.message:
@@ -144,6 +148,8 @@ def to_dict(self) -> Dict[str, Any]:
144148
result['json'] = self.json_data
145149
if self.text:
146150
result['text'] = self.text
151+
if self.error:
152+
result['error'] = self.error
147153

148154
return result
149155

agb/modules/browser/browser_agent.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,7 @@ def act(self, page, action_input: Union[ObserveResult, ActOptions]) -> 'ActResul
115115
# Map snake_case keys to ActResult members
116116
message = data.get("message", "")
117117
action = data.get("action", "")
118-
119-
# Parse the message to extract the actual success status
120-
# Format: "is_done=False success=True extracted_content='...'"
121-
if message:
122-
# Check if message contains success=True
123-
if "success=True" in message:
124-
success = True
125-
elif "success=False" in message:
126-
success = False
127-
# If success=None, keep the original value
118+
success = data.get("success", False)
128119

129120
return ActResult(success=success, message=message, action=action)
130121
else:
@@ -173,15 +164,7 @@ async def act_async(self, page, action_input: Union[ObserveResult, ActOptions])
173164
# Map snake_case keys to ActResult members
174165
message = data.get("message", "")
175166
action = data.get("action", "")
176-
177-
# Parse the message to extract the actual success status
178-
# Format: "is_done=True success=True extracted_content='...'"
179-
if message:
180-
# Extract success value from message
181-
if "success=True" in message:
182-
success = True
183-
elif "is_done=False" in message or "error=" in message:
184-
success = False
167+
success = data.get("success", False)
185168

186169
return ActResult(success=success, message=message, action=action)
187170
else:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ dependencies = [
2828
"pydantic>=2.0",
2929
"aiohttp>=3.12.5",
3030
]
31-
version = "0.1.0"
31+
version = "0.1.1"
3232

3333
[project.optional-dependencies]
3434
test = [

0 commit comments

Comments
 (0)