agent-builder-gateway-sdk 0.2.0__py3-none-any.whl → 0.3.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of agent-builder-gateway-sdk might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: agent-builder-gateway-sdk
3
- Version: 0.2.0
3
+ Version: 0.3.1
4
4
  Summary: Python SDK for Agent Builder Gateway - 用于 AI 构建的程序调用预制件
5
5
  Author: Agent Builder Team
6
6
  License: MIT
@@ -52,8 +52,16 @@ client = GatewayClient(jwt_token="your-jwt-token")
52
52
 
53
53
  # 或使用 API Key
54
54
  client = GatewayClient(api_key="sk-xxx")
55
+
56
+ # 白名单模式(适用于 OpenHands 等白名单环境)
57
+ client = GatewayClient() # 无需提供认证信息
55
58
  ```
56
59
 
60
+ **白名单模式说明**:
61
+ - 如果你的环境已配置白名单(如 OpenHands、内部开发环境),可以直接创建客户端而无需提供认证信息
62
+ - SDK 会以无鉴权模式发送请求,由 Gateway 基于 IP 白名单进行验证
63
+ - 这种模式简化了开发流程,无需管理 token
64
+
57
65
  ### 调用预制件
58
66
 
59
67
  ```python
@@ -0,0 +1,10 @@
1
+ gateway_sdk/__init__.py,sha256=lgBWm1gkpX8nGx-weoJbpQeHRYygJu5XBhB-ienHq5I,655
2
+ gateway_sdk/auth.py,sha256=Nx0p9FYZHBoQeN8SO2nn7MKH2y02v3UR3M8bYqhQG0w,1165
3
+ gateway_sdk/client.py,sha256=FezonUYj9q6-TQXOArmD1VHcSzs4bHoX6ZaxC2bsx3k,7778
4
+ gateway_sdk/exceptions.py,sha256=fIrhKC8vIaocXvyK56OEKPGHn8drvGh6nElnyR0Z71A,1897
5
+ gateway_sdk/models.py,sha256=ge96k0Qcii7ESEwJQoO5fZwUZBcVbe2Ccgna3kPOAB8,6072
6
+ gateway_sdk/streaming.py,sha256=nwRWxKP5bU8uIMIv_82DyFws9djnEKdAxW6S4L9KtPI,1092
7
+ agent_builder_gateway_sdk-0.3.1.dist-info/METADATA,sha256=HfRsk9tFyBL4dEmhv2JRgsBhXF6J2kHveVGMNcOVJHw,6391
8
+ agent_builder_gateway_sdk-0.3.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
9
+ agent_builder_gateway_sdk-0.3.1.dist-info/licenses/LICENSE,sha256=C3JXUJe4vPtoVe1lp7O4WeGtH71JWYrRaCufEoJ84K0,1076
10
+ agent_builder_gateway_sdk-0.3.1.dist-info/RECORD,,
gateway_sdk/client.py CHANGED
@@ -38,14 +38,15 @@ class GatewayClient:
38
38
  api_key: API Key(优先级高)
39
39
  jwt_token: JWT Token(用于 AI 构建的程序)
40
40
  timeout: 请求超时时间(秒)
41
+
42
+ Note:
43
+ 如果不提供 api_key 或 jwt_token,客户端将在无鉴权模式下工作。
44
+ 这适用于配置了白名单的环境(如 OpenHands)。
41
45
  """
42
46
  self.base_url = base_url.rstrip("/")
43
47
  self.auth = AuthManager(api_key=api_key, jwt_token=jwt_token)
44
48
  self.timeout = timeout
45
49
 
46
- if not self.auth.is_authenticated():
47
- raise AuthenticationError("必须提供 api_key 或 jwt_token")
48
-
49
50
  def run(
50
51
  self,
51
52
  prefab_id: str,
gateway_sdk/models.py CHANGED
@@ -66,13 +66,112 @@ class PrefabResult:
66
66
  return default
67
67
 
68
68
  def get_result(self) -> Any:
69
- """获取业务结果"""
70
- if self.output:
71
- return self.output.get("result", self.output)
72
- return None
69
+ """
70
+ 获取完整的 output 字典(保持向后兼容)
71
+
72
+ Returns:
73
+ 完整的 output 字典,包含 status, output, files 等
74
+ """
75
+ return self.output
76
+
77
+ def get_function_result(self) -> Dict[str, Any]:
78
+ """
79
+ 获取预制件函数的返回值(对应 manifest.returns)
80
+
81
+ 这是响应的嵌套结构:
82
+ - result.output 是 Gateway 的响应
83
+ - result.output['output'] 是预制件函数的实际返回值
84
+
85
+ Returns:
86
+ 预制件函数的返回值字典
87
+
88
+ Example:
89
+ >>> result = client.run(...)
90
+ >>> function_result = result.get_function_result()
91
+ >>> if function_result.get('success'):
92
+ ... print(function_result.get('message'))
93
+ """
94
+ if self.output and isinstance(self.output, dict):
95
+ return self.output.get('output', {})
96
+ return {}
97
+
98
+ def get_business_success(self) -> bool:
99
+ """
100
+ 判断业务是否成功(检查函数返回值中的 success 字段)
101
+
102
+ 注意:
103
+ - result.is_success() 表示 SDK 调用成功
104
+ - result.get_business_success() 表示业务逻辑成功
105
+
106
+ Returns:
107
+ 业务是否成功
108
+
109
+ Example:
110
+ >>> result = client.run(...)
111
+ >>> if result.is_success() and result.get_business_success():
112
+ ... print("调用成功且业务成功")
113
+ """
114
+ function_result = self.get_function_result()
115
+ return function_result.get('success', False)
116
+
117
+ def get_business_message(self) -> str:
118
+ """
119
+ 获取业务消息
120
+
121
+ Returns:
122
+ 业务消息字符串,如果没有消息则返回空字符串
123
+
124
+ Example:
125
+ >>> result = client.run(...)
126
+ >>> print(f"消息: {result.get_business_message()}")
127
+ """
128
+ function_result = self.get_function_result()
129
+ return function_result.get('message', '')
130
+
131
+ def get_business_error(self) -> Optional[str]:
132
+ """
133
+ 获取业务错误信息
134
+
135
+ Returns:
136
+ 错误信息字符串,如果没有错误则返回 None
137
+
138
+ Example:
139
+ >>> result = client.run(...)
140
+ >>> if not result.get_business_success():
141
+ ... print(f"错误: {result.get_business_error()}")
142
+ """
143
+ function_result = self.get_function_result()
144
+ return function_result.get('error')
145
+
146
+ def get_business_error_code(self) -> Optional[str]:
147
+ """
148
+ 获取业务错误代码
149
+
150
+ Returns:
151
+ 错误代码字符串,如果没有错误码则返回 None
152
+
153
+ Example:
154
+ >>> result = client.run(...)
155
+ >>> if not result.get_business_success():
156
+ ... print(f"错误码: {result.get_business_error_code()}")
157
+ """
158
+ function_result = self.get_function_result()
159
+ return function_result.get('error_code')
73
160
 
74
161
  def get_files(self) -> Dict[str, List[str]]:
75
- """获取输出文件"""
162
+ """
163
+ 获取输出文件(S3 URL 列表)
164
+
165
+ Returns:
166
+ 文件字典,key 对应 manifest.files 中定义的 key
167
+
168
+ Example:
169
+ >>> result = client.run(...)
170
+ >>> output_files = result.get_files()
171
+ >>> # 获取特定 key 的输出文件
172
+ >>> if 'output' in output_files:
173
+ ... s3_url = output_files['output'][0]
174
+ """
76
175
  if self.output:
77
176
  return self.output.get("files", {})
78
177
  return {}
@@ -1,10 +0,0 @@
1
- gateway_sdk/__init__.py,sha256=lgBWm1gkpX8nGx-weoJbpQeHRYygJu5XBhB-ienHq5I,655
2
- gateway_sdk/auth.py,sha256=Nx0p9FYZHBoQeN8SO2nn7MKH2y02v3UR3M8bYqhQG0w,1165
3
- gateway_sdk/client.py,sha256=GZh2SyQ_598ex1LebSy6ajN9F3APckn7O1u0TrpmpsU,7708
4
- gateway_sdk/exceptions.py,sha256=fIrhKC8vIaocXvyK56OEKPGHn8drvGh6nElnyR0Z71A,1897
5
- gateway_sdk/models.py,sha256=_3MspU7qDNTsCppzWxgr-sNhjdVzu6QVVZHpqw4lVMs,2731
6
- gateway_sdk/streaming.py,sha256=nwRWxKP5bU8uIMIv_82DyFws9djnEKdAxW6S4L9KtPI,1092
7
- agent_builder_gateway_sdk-0.2.0.dist-info/METADATA,sha256=tBJr9Lfbo28xXzpyxeTnXRMHqmCR6-VtY7Kx4rgZr8k,5966
8
- agent_builder_gateway_sdk-0.2.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
9
- agent_builder_gateway_sdk-0.2.0.dist-info/licenses/LICENSE,sha256=C3JXUJe4vPtoVe1lp7O4WeGtH71JWYrRaCufEoJ84K0,1076
10
- agent_builder_gateway_sdk-0.2.0.dist-info/RECORD,,