Skip to content

Commit 17eb588

Browse files
committed
Mechanical: Apply formatting to Python files
1 parent 9be6501 commit 17eb588

24 files changed

Lines changed: 2393 additions & 1604 deletions

File tree

agent_sdks/python/src/a2ui/parser/streaming.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,10 @@ def traverse(obj, parent_key=None):
10461046
if not any(ec["id"] == placeholder_id for ec in extra_components):
10471047
extra_components.append(placeholder_comp)
10481048

1049-
if not valid_children and field in ("children", "explicitList"):
1049+
if not valid_children and field in (
1050+
"children",
1051+
"explicitList",
1052+
):
10501053
# If list is empty, check if it was partial in the buffer
10511054
# (meaning it's a sequence that started but hasn't yielded items yet)
10521055
term = f'"{field}"'

agent_sdks/python/src/a2ui/parser/streaming_v08.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ def __init__(self, catalog=None):
3333
def _placeholder_component(self) -> Dict[str, Any]:
3434
"""Returns the placeholder component."""
3535
return {
36-
'component': {
37-
'Row': {
38-
'children': {'explicitList': []},
36+
"component": {
37+
"Row": {
38+
"children": {"explicitList": []},
3939
}
4040
}
4141
}
@@ -75,9 +75,9 @@ def get_latest_value(key: str) -> Optional[str]:
7575
if match:
7676
return match.group(1)
7777

78-
self.surface_id = get_latest_value('surfaceId')
78+
self.surface_id = get_latest_value("surfaceId")
7979

80-
parsed_root = get_latest_value('root')
80+
parsed_root = get_latest_value("root")
8181
if parsed_root is not None:
8282
self.root_id = parsed_root
8383

@@ -121,7 +121,7 @@ def _handle_complete_object(
121121
surface_id = val.get(SURFACE_ID_KEY) or surface_id
122122

123123
self.surface_id = surface_id
124-
sid = self.surface_id or 'unknown'
124+
sid = self.surface_id or "unknown"
125125

126126
if MSG_TYPE_DELETE_SURFACE in obj:
127127
if sid in self._yielded_surfaces_set or self._buffered_start_message:
@@ -144,7 +144,7 @@ def _handle_complete_object(
144144
br_val = obj[MSG_TYPE_BEGIN_RENDERING]
145145
if isinstance(br_val, dict):
146146
self.surface_id = br_val.get(SURFACE_ID_KEY, self.surface_id)
147-
self.root_id = br_val.get('root', self.root_id or DEFAULT_ROOT_ID)
147+
self.root_id = br_val.get("root", self.root_id or DEFAULT_ROOT_ID)
148148
self._buffered_start_message = obj
149149

150150
# Yield beginRendering immediately when it completes
@@ -164,10 +164,10 @@ def _handle_complete_object(
164164

165165
if MSG_TYPE_SURFACE_UPDATE in obj:
166166
self.add_msg_type(MSG_TYPE_SURFACE_UPDATE)
167-
components = obj[MSG_TYPE_SURFACE_UPDATE].get('components', [])
167+
components = obj[MSG_TYPE_SURFACE_UPDATE].get("components", [])
168168
for comp in components:
169-
if isinstance(comp, dict) and 'id' in comp:
170-
self._seen_components[comp['id']] = comp
169+
if isinstance(comp, dict) and "id" in comp:
170+
self._seen_components[comp["id"]] = comp
171171
self.yield_reachable(messages, check_root=True, raise_on_orphans=False)
172172
return True
173173

@@ -209,17 +209,17 @@ def _get_active_msg_type_for_components(self) -> Optional[str]:
209209
def _deduplicate_data_model(self, m: Dict[str, Any], strict_integrity: bool) -> bool:
210210
if MSG_TYPE_DATA_MODEL_UPDATE in m:
211211
dm = m[MSG_TYPE_DATA_MODEL_UPDATE]
212-
raw_contents = dm.get('contents', {})
212+
raw_contents = dm.get("contents", {})
213213
contents_dict = {}
214214
if isinstance(raw_contents, list):
215215
for entry in raw_contents:
216-
if isinstance(entry, dict) and 'key' in entry:
217-
key = entry['key']
216+
if isinstance(entry, dict) and "key" in entry:
217+
key = entry["key"]
218218
val = (
219-
entry.get('valueString')
220-
or entry.get('valueNumber')
221-
or entry.get('valueBoolean')
222-
or entry.get('valueMap')
219+
entry.get("valueString")
220+
or entry.get("valueNumber")
221+
or entry.get("valueBoolean")
222+
or entry.get("valueMap")
223223
)
224224
if key and val is not None:
225225
contents_dict[key] = val

agent_sdks/python/src/a2ui/parser/streaming_v09.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ def __init__(self, catalog=None):
3434
def _placeholder_component(self) -> Dict[str, Any]:
3535
"""Returns a v0.9 flat style placeholder component specification."""
3636
return {
37-
'component': 'Row',
38-
'children': [],
37+
"component": "Row",
38+
"children": [],
3939
}
4040

4141
@property
@@ -67,9 +67,9 @@ def get_latest_value(key: str) -> Optional[str]:
6767
if match:
6868
return match.group(1)
6969

70-
self.surface_id = get_latest_value('surfaceId')
70+
self.surface_id = get_latest_value("surfaceId")
7171

72-
parsed_root = get_latest_value('root')
72+
parsed_root = get_latest_value("root")
7373
if parsed_root is not None:
7474
self.root_id = parsed_root
7575

@@ -105,13 +105,13 @@ def _handle_complete_object(
105105
surface_id = val.get(SURFACE_ID_KEY) or surface_id
106106

107107
self.surface_id = surface_id
108-
sid = self.surface_id or 'unknown'
108+
sid = self.surface_id or "unknown"
109109

110110
# v0.9 Specific Handling
111111
if MSG_TYPE_CREATE_SURFACE in obj:
112112
val = obj[MSG_TYPE_CREATE_SURFACE]
113113
if isinstance(val, dict):
114-
self.root_id = val.get('root', self.root_id or DEFAULT_ROOT_ID)
114+
self.root_id = val.get("root", self.root_id or DEFAULT_ROOT_ID)
115115
self._buffered_start_message = obj
116116

117117
# Yield createSurface immediately when it completes
@@ -131,12 +131,12 @@ def _handle_complete_object(
131131
if MSG_TYPE_UPDATE_COMPONENTS in obj:
132132
self.add_msg_type(MSG_TYPE_UPDATE_COMPONENTS)
133133
self.root_id = obj[MSG_TYPE_UPDATE_COMPONENTS].get(
134-
'root', self.root_id or DEFAULT_ROOT_ID
134+
"root", self.root_id or DEFAULT_ROOT_ID
135135
)
136-
components = obj[MSG_TYPE_UPDATE_COMPONENTS].get('components', [])
136+
components = obj[MSG_TYPE_UPDATE_COMPONENTS].get("components", [])
137137
for comp in components:
138-
if isinstance(comp, dict) and 'id' in comp:
139-
self._seen_components[comp['id']] = comp
138+
if isinstance(comp, dict) and "id" in comp:
139+
self._seen_components[comp["id"]] = comp
140140
self.yield_reachable(messages, check_root=True, raise_on_orphans=False)
141141
return True
142142

@@ -161,7 +161,7 @@ def _construct_sniffed_data_model_message(
161161
self, active_msg_type: str, delta_msg_payload: Dict[str, Any]
162162
) -> Dict[str, Any]:
163163
"""Returns the message to yield for a partial data model update for v0.9."""
164-
return {'version': 'v0.9', active_msg_type: delta_msg_payload}
164+
return {"version": "v0.9", active_msg_type: delta_msg_payload}
165165

166166
def _sniff_partial_data_model(self, messages: List[ResponsePart]) -> None:
167167
"""Sniffs for partial data model updates in v0.9 (value property)."""
@@ -170,7 +170,7 @@ def _sniff_partial_data_model(self, messages: List[ResponsePart]) -> None:
170170
return
171171

172172
for b_type, start_idx in reversed(self._brace_stack):
173-
if b_type != '{':
173+
if b_type != "{":
174174
continue
175175
raw_fragment = self._json_buffer[start_idx:]
176176
if not raw_fragment:
@@ -183,8 +183,8 @@ def _sniff_partial_data_model(self, messages: List[ResponsePart]) -> None:
183183
except json.JSONDecodeError:
184184
# Fallback: iteratively strip from the last comma
185185
trimmed = raw_fragment
186-
while ',' in trimmed:
187-
trimmed = trimmed.rsplit(',', 1)[0]
186+
while "," in trimmed:
187+
trimmed = trimmed.rsplit(",", 1)[0]
188188
try:
189189
fixed_trimmed = self._fix_json(trimmed)
190190
if fixed_trimmed:
@@ -196,8 +196,8 @@ def _sniff_partial_data_model(self, messages: List[ResponsePart]) -> None:
196196
if obj and isinstance(obj, dict) and msg_type in obj:
197197

198198
dm_obj = obj[msg_type]
199-
if isinstance(dm_obj, dict) and 'value' in dm_obj:
200-
value_map = dm_obj['value']
199+
if isinstance(dm_obj, dict) and "value" in dm_obj:
200+
value_map = dm_obj["value"]
201201
if isinstance(value_map, dict):
202202
# Find delta against yielded data model
203203
delta = {}
@@ -206,10 +206,10 @@ def _sniff_partial_data_model(self, messages: List[ResponsePart]) -> None:
206206
delta[k] = v
207207

208208
if delta:
209-
sid = dm_obj.get(SURFACE_ID_KEY) or self._surface_id or 'default'
209+
sid = dm_obj.get(SURFACE_ID_KEY) or self._surface_id or "default"
210210
delta_msg_payload = {
211211
SURFACE_ID_KEY: sid,
212-
'value': delta,
212+
"value": delta,
213213
}
214214
delta_msg = self._construct_sniffed_data_model_message(
215215
msg_type, delta_msg_payload
@@ -230,12 +230,12 @@ def _construct_partial_message(
230230
}
231231
if self.surface_id:
232232
payload[SURFACE_ID_KEY] = self.surface_id
233-
return {'version': 'v0.9', MSG_TYPE_UPDATE_COMPONENTS: payload}
233+
return {"version": "v0.9", MSG_TYPE_UPDATE_COMPONENTS: payload}
234234

235235
@property
236236
def _yielded_surfaces_set(self) -> Set[str]:
237237
"""Provides access to version-specific yielded surfaces set."""
238-
if not hasattr(self, '_yielded_create_surfaces'):
238+
if not hasattr(self, "_yielded_create_surfaces"):
239239
self._yielded_create_surfaces: Set[str] = set()
240240
return self._yielded_create_surfaces
241241

@@ -255,13 +255,13 @@ def _deduplicate_data_model(self, m: Dict[str, Any], strict_integrity: bool) ->
255255
if isinstance(udm, dict):
256256
is_new = False
257257
for k, v in udm.items():
258-
if k not in (SURFACE_ID_KEY, 'root') and self._yielded_data_model.get(k) != v:
258+
if k not in (SURFACE_ID_KEY, "root") and self._yielded_data_model.get(k) != v:
259259
is_new = True
260260
break
261261
if not is_new and strict_integrity:
262262
return False
263263
# Update yielded model
264264
for k, v in udm.items():
265-
if k not in (SURFACE_ID_KEY, 'root'):
265+
if k not in (SURFACE_ID_KEY, "root"):
266266
self._yielded_data_model[k] = v
267267
return True

agent_sdks/python/src/a2ui/schema/common_modifiers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ def remove_strict_validation(schema):
1717
if isinstance(schema, dict):
1818
new_schema = {k: remove_strict_validation(v) for k, v in schema.items()}
1919
if (
20-
'additionalProperties' in new_schema
21-
and new_schema['additionalProperties'] is False
20+
"additionalProperties" in new_schema
21+
and new_schema["additionalProperties"] is False
2222
):
23-
del new_schema['additionalProperties']
23+
del new_schema["additionalProperties"]
2424
return new_schema
2525
elif isinstance(schema, list):
2626
return [remove_strict_validation(item) for item in schema]

agent_sdks/python/src/a2ui/schema/validator.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,10 @@ def validate(
305305
ref_map = extract_component_ref_fields(self._catalog)
306306
root_id = _find_root_id(messages, surface_id)
307307
_validate_component_integrity(
308-
root_id, components, ref_map, skip_root_check=not strict_integrity
308+
root_id,
309+
components,
310+
ref_map,
311+
skip_root_check=not strict_integrity,
309312
)
310313
analyze_topology(
311314
root_id, components, ref_map, raise_on_orphans=strict_integrity

0 commit comments

Comments
 (0)