(
self,
at: str,
payload: Dict[str, Any],
*,
project_id: Optional[str] = None,
token_id: Optional[int] = None,
action: str = "VIDEO_GENERATION",
account_id: Optional[str] = None,
)
| 2673 | ) |
| 2674 | |
| 2675 | async def stream_flow_creation_agent( |
| 2676 | self, |
| 2677 | at: str, |
| 2678 | payload: Dict[str, Any], |
| 2679 | *, |
| 2680 | project_id: Optional[str] = None, |
| 2681 | token_id: Optional[int] = None, |
| 2682 | action: str = "VIDEO_GENERATION", |
| 2683 | account_id: Optional[str] = None, |
| 2684 | ) -> List[Dict[str, Any]]: |
| 2685 | url = f"{self.api_base_url}/flowCreationAgent:streamChat?alt=sse" |
| 2686 | headers = self._build_browser_style_control_headers( |
| 2687 | referer="https://labs.google/", |
| 2688 | origin="https://labs.google", |
| 2689 | account_id=account_id, |
| 2690 | content_type="application/json", |
| 2691 | accept_language=self._get_primary_accept_language(), |
| 2692 | ) |
| 2693 | headers["Accept"] = "text/event-stream, text/event-stream" |
| 2694 | |
| 2695 | if config.captcha_method == "browser" and project_id: |
| 2696 | from .browser_captcha import BrowserCaptchaService |
| 2697 | |
| 2698 | service = await BrowserCaptchaService.get_instance(self.db) |
| 2699 | response_payload, _browser_ref, fingerprint = await service.submit_flow_request( |
| 2700 | project_id=project_id, |
| 2701 | action=action, |
| 2702 | token_id=token_id, |
| 2703 | url=url, |
| 2704 | at_token=at, |
| 2705 | json_data=payload, |
| 2706 | timeout=self._get_video_submit_timeout(), |
| 2707 | ) |
| 2708 | self._set_request_fingerprint(fingerprint if fingerprint else None) |
| 2709 | |
| 2710 | status_code = int(response_payload.get("status") or 0) |
| 2711 | raw_text = response_payload.get("text") or "" |
| 2712 | if status_code >= 400: |
| 2713 | error_reason = f"HTTP Error {status_code}" |
| 2714 | parsed_body = None |
| 2715 | try: |
| 2716 | parsed_body = json.loads(raw_text) if raw_text else None |
| 2717 | except Exception: |
| 2718 | parsed_body = None |
| 2719 | if isinstance(parsed_body, dict) and "error" in parsed_body: |
| 2720 | error_info = parsed_body["error"] or {} |
| 2721 | error_message = error_info.get("message", "") |
| 2722 | details = error_info.get("details", []) |
| 2723 | for detail in details or []: |
| 2724 | if isinstance(detail, dict) and detail.get("reason"): |
| 2725 | error_reason = detail.get("reason") |
| 2726 | break |
| 2727 | if error_message: |
| 2728 | error_reason = f"{error_reason}: {error_message}" |
| 2729 | elif raw_text: |
| 2730 | error_reason = f"HTTP Error {status_code}: {raw_text[:200]}" |
| 2731 | raise Exception(error_reason) |
| 2732 | else: |
no test coverage detected