Derive concrete output IDs from the resolved input entries. Extracts the wildcard key values from the LLM-provided concrete input IDs and substitutes them into the output pattern.
(
output_pattern: WildcardId,
resolved_inputs: list[CallbackInputs],
)
| 431 | |
| 432 | |
| 433 | def _derive_output_ids( |
| 434 | output_pattern: WildcardId, |
| 435 | resolved_inputs: list[CallbackInputs], |
| 436 | ) -> list[WildcardId] | None: |
| 437 | """Derive concrete output IDs from the resolved input entries. |
| 438 | |
| 439 | Extracts the wildcard key values from the LLM-provided concrete |
| 440 | input IDs and substitutes them into the output pattern. |
| 441 | """ |
| 442 | wildcard_keys = [ |
| 443 | k |
| 444 | for k, v in output_pattern.items() |
| 445 | if isinstance(v, list) and len(v) == 1 and v[0] in _WILDCARD_VALUES |
| 446 | ] |
| 447 | if not wildcard_keys: |
| 448 | return None |
| 449 | |
| 450 | def _substitute(item_id: WildcardId) -> WildcardId | None: |
| 451 | if not isinstance(item_id, dict): |
| 452 | return None |
| 453 | output_id = dict(output_pattern) |
| 454 | for wk in wildcard_keys: |
| 455 | if wk in item_id: |
| 456 | output_id[wk] = item_id[wk] |
| 457 | return output_id |
| 458 | |
| 459 | for entry in resolved_inputs: |
| 460 | # ALL/ALLSMALLER: nested array of {id, property, value} dicts |
| 461 | if isinstance(entry, list) and entry: |
| 462 | concrete_ids = [] |
| 463 | for item in entry: |
| 464 | item_id = item.get("id") |
| 465 | if isinstance(item_id, dict): |
| 466 | out = _substitute(item_id) |
| 467 | if out: |
| 468 | concrete_ids.append(out) |
| 469 | if concrete_ids: |
| 470 | return concrete_ids |
| 471 | # MATCH: single {id, property, value} dict |
| 472 | elif isinstance(entry, dict): |
| 473 | entry_id = entry.get("id") |
| 474 | if isinstance(entry_id, dict): |
| 475 | out = _substitute(entry_id) |
| 476 | if out: |
| 477 | return [out] |
| 478 | |
| 479 | return None |
no test coverage detected
searching dependent graphs…