Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
Add cloud event trigger management API (SKY-18463) (#8933)
Aaron Perez1e5e185b0928
diff --git a/docs/cloud/integrations.mdx b/docs/cloud/integrations.mdxindex 363cee311..59d271ca1 100644--- a/docs/cloud/integrations.mdx+++ b/docs/cloud/integrations.mdx@@ -105,33 +105,31 @@ Per-client details, tool scopes and troubleshooting are on [MCP and coding agent## Automation platforms-Zapier, Make, n8n and Workato connect from their side: you add Skyvern inside the platform and paste your [API key](/cloud/account#api-keys). The tiles on the Integrations page link to each platform's Skyvern listing.+Build a workflow in Skyvern before adding its run action in a builder. All four connections use an organization API key from [Settings → API keys](/cloud/account#api-keys), sent in the `x-api-key` header. Save the key in the builder's Skyvern connection, not in a workflow input. Organization keys have full access to your organization; scoped API keys are coming.-All four follow the same pattern:--1. **Build the agent in Skyvern first.** The platform's "run an agent" step only lists agents that already exist.-2. **Run it.** Choose the agent and fill in its inputs. Add a webhook callback URL if you want the platform to hear back when the run finishes, rather than polling.-3. **Get the result.** Use the platform's "get" step with the run ID: agent run IDs start with `wr_`, task run IDs with `tsk_`.--<Tip>-Watch progress in the Skyvern app while you test. Every run started from a platform appears in your run history like any other run. See [Runs and schedules](/cloud/runs).-</Tip>+For Skyvern Cloud, the API base URL is `https://api.skyvern.com`. For a self-hosted deployment, use its API origin and make sure the builder can reach it. The n8n node exposes a **Base URL** credential field (default: `https://api.skyvern.com`); enter the origin only, without `/api/v1`, because the node adds API paths itself. The Zapier, Make and Workato listings do not show a custom base URL field; contact Skyvern Support to confirm self-hosted support before connecting.### Zapier-Add Skyvern in your Zap and paste your API key. Listing: [zapier.com/apps/skyvern](https://zapier.com/apps/skyvern/integrations).+[Add Skyvern from the Zapier listing](https://zapier.com/apps/skyvern/integrations), create a connection with your organization API key, then add **Run a Workflow** to your Zap. Use **Get a Workflow** with the returned workflow run ID to retrieve its result. The current Run a Workflow action's workflow and input fields may not load reliably; verify the workflow exists and the connection uses the right key, but setup alone cannot fix an app-side loading issue.### Make-Add Skyvern in your scenario and paste your API key. Listing: [make.com/en/integrations/skyvern-ai](https://www.make.com/en/integrations/skyvern-ai).+[Add a Skyvern module from the Make listing](https://www.make.com/en/integrations/skyvern-ai) to your scenario and click **Create a connection**. Enter your organization API key, then choose **Run a Workflow** or **Run a Task**. Use **Get a Workflow** or **Get a Task** with the returned run ID to retrieve the result.### n8n-Install the community node [`n8n-nodes-skyvern`](https://www.npmjs.com/package/n8n-nodes-skyvern), add it to your workflow and paste your API key.+The [verified Skyvern node listing](https://n8n.io/integrations/skyvern/) requires a one-time install by an n8n instance owner or admin: open the Nodes panel (+), find Skyvern under **More from the community**, and select **Install**. Everyone on the instance can then add it to workflows. On n8n Cloud, the owner controls verified-node availability in the Cloud Admin Panel; on self-hosted n8n, the admin controls it through environment variables. Create a Skyvern API credential with your organization key and, for self-hosted Skyvern, the API **Base URL**. Choose the **Workflow** or **Task** resource and a dispatch operation, then use the matching Get operation with the returned run ID. For **Get Workflow**, also select the same workflow (or provide its ID) in **Workflow Name or ID**, and enter the returned run ID in **Workflow Run ID**. The node's workflow selector lists at most 100 workflows.### Workato-Add the Skyvern connector to your recipe and paste your API key. Listing: [workato.com/integrations/skyvern](https://www.workato.com/integrations/skyvern).+[Add the Skyvern connector from the Workato listing](https://www.workato.com/integrations/skyvern) to a recipe and create its connection with your organization API key. Choose **Run a Workflow** or **Create and Run Task**. Workato's **Get Workflow** action looks up a workflow by workflow ID; it does not retrieve a workflow run. Pair **Create and Run Task V2** with **Get Task V2** and its returned `tsk_v2_...` ID; for v1 tasks, use **Get Task** with the task ID.++Workflow run IDs start with `wr_`; v1 task IDs start with `tsk_`, and Task V2 IDs start with `tsk_v2_`. A run may finish after the builder's action returns. Use the matching Get action when that builder provides one, or watch the run in Skyvern history. If a Run action offers a webhook callback URL, you can provide one that Skyvern can reach instead of polling.++<Tip>+Watch progress in the Skyvern app while you test. Every run started from a platform appears in your run history like any other run. See [Runs and schedules](/cloud/runs).+</Tip>## Nextdiff --git a/skyvern/forge/sdk/core/security.py b/skyvern/forge/sdk/core/security.pyindex af52d9861..187b6fa95 100644--- a/skyvern/forge/sdk/core/security.py+++ b/skyvern/forge/sdk/core/security.py@@ -1,6 +1,7 @@import hashlibimport hmacimport json+import uuidfrom dataclasses import dataclassfrom datetime import datetime, timedeltafrom typing import Any, Union@@ -45,7 +46,8 @@ def create_access_token(expire = datetime.utcnow() + timedelta(minutes=settings.ACCESS_TOKEN_EXPIRE_MINUTES,)- to_encode = {"exp": expire, "sub": str(subject)}+ # jti keeps two keys minted for the same subject in the same second distinct.+ to_encode = {"exp": expire, "sub": str(subject), "jti": uuid.uuid4().hex}if token_type is not None:to_encode["token_type"] = token_typeencoded_jwt = jwt.encode(diff --git a/skyvern/forge/sdk/services/org_auth_service.py b/skyvern/forge/sdk/services/org_auth_service.pyindex 11fe0925b..9d6cc074c 100644--- a/skyvern/forge/sdk/services/org_auth_service.py+++ b/skyvern/forge/sdk/services/org_auth_service.py@@ -48,6 +48,12 @@ class ApiKeyValidationResult:token: OrganizationAuthToken+@dataclass(frozen=True)+class _CachedOrganizationAuth:+ organization: Organization+ token_id: str++def _normalize_api_key_with_flags(raw_api_key: str) -> tuple[str, dict[str, bool]]:normalized = raw_api_keyflags = {@@ -284,6 +290,9 @@ async def _get_current_org_for_token_types(await resolve_request_principal(validation.organization.organization_id,api_key_type=_api_key_type(_decode_token_before_cache(x_api_key)),+ api_key_token_id=(+ validation.token.id if validation.token.token_type == OrganizationAuthTokenType.api else None+ ),bearer_token=_extract_bearer_token(authorization),)return validation.organization@@ -716,7 +725,7 @@ async def _get_current_org_cached(*,user_agent: str | None = None,fern_language: str | None = None,-) -> Organization:+) -> _CachedOrganizationAuth:"""Validate API-key authentication and cache successful results for one minute."""cache_key = (x_api_key, db)try:@@ -737,10 +746,11 @@ async def _get_current_org_cached(user_agent=user_agent,fern_language=fern_language,)+ cached_auth = _CachedOrganizationAuth(validation.organization, validation.token.id)if invalidation_generation == _current_org_cache_invalidation_generation:- _current_org_cache[cache_key] = validation.organization- return validation.organization+ _current_org_cache[cache_key] = cached_auth+ return cached_authdef _claims_ui_session(payload: dict[str, object] | None) -> bool:@@ -771,17 +781,21 @@ async def get_current_org_cached(fern_language=fern_language,)organization = validation.organization+ token_id = validation.token.id if validation.token.token_type == OrganizationAuthTokenType.api else Noneelse:- organization = await _get_current_org_cached(+ cached_auth = await _get_current_org_cached(x_api_key,db,user_agent=user_agent,fern_language=fern_language,)+ organization = cached_auth.organization+ token_id = cached_auth.token_idapply_request_org_context(organization)await resolve_request_principal(organization.organization_id,api_key_type=_api_key_type(payload),+ api_key_token_id=token_id,bearer_token=_extract_bearer_token(authorization),)return organization@@ -795,7 +809,7 @@ def invalidate_cached_org(organization_id: str) -> None:keys_to_remove = [keyfor key, value in list(_current_org_cache.items())- if isinstance(value, Organization) and value.organization_id == organization_id+ if isinstance(value, _CachedOrganizationAuth) and value.organization.organization_id == organization_id]for key in keys_to_remove:_current_org_cache.pop(key, None)diff --git a/skyvern/forge/sdk/services/request_principal.py b/skyvern/forge/sdk/services/request_principal.pyindex 8dc807bff..868c15bb2 100644--- a/skyvern/forge/sdk/services/request_principal.py+++ b/skyvern/forge/sdk/services/request_principal.py@@ -55,6 +55,7 @@ class BearerIdentityResolution:class RequestPrincipal:organization_id: strauth_kind: AuthKind+ api_key_token_id: str | None = Noneuser_id: str | None = Noneorg_role: str | None = Noneorg_role_claim: str | None = None@@ -65,7 +66,7 @@ def synthetic_user_id(organization_id: str) -> str:return f"{organization_id}_user"-_ResolutionKey = tuple[str, str | None, bytes | None]+_ResolutionKey = tuple[str, str | None, str | None, bytes | None]_request_principal: ContextVar[tuple[_ResolutionKey, RequestPrincipal, BearerIdentityStatus] | None] = ContextVar("request_principal", default=None)@@ -111,11 +112,17 @@ async def resolve_request_principal(organization_id: str,*,api_key_type: OrganizationAuthTokenType | None = None,+ api_key_token_id: str | None = None,bearer_token: str | None = None,) -> RequestPrincipal:"""Record the caller's identity after auth without changing the request outcome."""bearer_hash = hashlib.sha256(bearer_token.encode()).digest() if bearer_token else None- resolution_key = (organization_id, api_key_type.value if api_key_type is not None else None, bearer_hash)+ resolution_key = (+ organization_id,+ api_key_type.value if api_key_type is not None else None,+ api_key_token_id,+ bearer_hash,+ )identity_key = (organization_id, bearer_hash)request_state = get_request_principal_state()if request_state is not None:@@ -137,6 +144,7 @@ async def resolve_request_principal(principal = RequestPrincipal(organization_id=organization_id,auth_kind=_auth_kind(api_key_type, identity is not None),+ api_key_token_id=api_key_token_id,user_id=identity.user_id if identity else None,org_role=identity.org_role if identity else None,org_role_claim=identity.org_role_claim if identity else None,@@ -158,6 +166,7 @@ async def resolve_request_principal(principal = RequestPrincipal(organization_id=organization_id,auth_kind=_auth_kind(api_key_type, identity is not None),+ api_key_token_id=api_key_token_id,user_id=identity.user_id if identity else None,org_role=identity.org_role if identity else None,org_role_claim=identity.org_role_claim if identity else None,diff --git a/tests/unit/test_org_auth_service.py b/tests/unit/test_org_auth_service.pyindex 3959b6ae1..6464c2004 100644--- a/tests/unit/test_org_auth_service.py+++ b/tests/unit/test_org_auth_service.py@@ -115,6 +115,17 @@ def test_debug_fields_report_no_shadow_decode_for_unchanged_value() -> None:assert debug_fields["normalized_api_key_error_type"] is None+def test_keys_minted_for_one_org_with_the_same_expiry_are_distinct() -> None:+ first = create_access_token("o_test", expires_delta=timedelta(hours=1))+ second = create_access_token("o_test", expires_delta=timedelta(hours=1))+ claims = [+ jwt.decode(token, settings.SECRET_KEY, algorithms=[settings.SIGNATURE_ALGORITHM]) for token in (first, second)+ ]++ assert first != second+ assert claims[0]["sub"] == claims[1]["sub"] == "o_test"++def test_debug_fields_show_when_normalized_token_would_decode(monkeypatch) -> None:token = create_access_token("o_test")monkeypatch.setattr(org_auth_service.time, "time", lambda: 0)@@ -300,6 +311,28 @@ async def test_get_current_org_cached_rejects_rotated_key_after_invalidation() -assert organizations.validate_calls == 3+async def test_get_current_org_cached_preserves_token_id_on_cache_miss_and_hit(monkeypatch) -> None:+ api_key = create_access_token("org-a", expires_delta=timedelta(hours=1))+ organizations = _RotatingAuthOrganizations({api_key: True})+ db = _AuthDatabase(organizations)+ monkeypatch.setattr(org_auth_service.app, "AGENT_FUNCTION", AgentFunction())+ request_principal._request_principal.set(None)++ await org_auth_service.get_current_org_cached(api_key, db)+ principal_on_miss = get_request_principal()+ assert principal_on_miss is not None+ assert principal_on_miss.api_key_token_id == "oat_test"++ request_principal._request_principal.set(None)+ await org_auth_service.get_current_org_cached(api_key, db)+ principal_on_hit = get_request_principal()++ assert principal_on_hit is not None+ assert principal_on_hit.api_key_token_id == "oat_test"+ assert organizations.validate_calls == 1++@pytest.mark.asyncioasync def test_get_current_org_cached_coalesces_concurrent_cache_misses(monkeypatch) -> None:cache = org_auth_service._current_org_cache@@ -314,7 +347,7 @@ async def test_get_current_org_cached_coalesces_concurrent_cache_misses(monkeyparesolve_calls += 1validation_started.set()await release_validation.wait()- return SimpleNamespace(organization=organization)+ return SimpleNamespace(organization=organization, token=_make_auth_token(_api_key, valid=True))monkeypatch.setattr(org_auth_service, "resolve_org_from_api_key", resolve_api_key)db = object()@@ -348,7 +381,7 @@ async def test_get_current_org_cached_does_not_recache_after_invalidation_duringif resolve_calls == 1:validation_started.set()await release_validation.wait()- return SimpleNamespace(organization=organization)+ return SimpleNamespace(organization=organization, token=_make_auth_token(_api_key, valid=True))monkeypatch.setattr(org_auth_service, "resolve_org_from_api_key", resolve_api_key)db = object()@@ -369,9 +402,9 @@ def test_invalidate_cached_org_drops_only_matching_entries() -> None:cache.clear()org_a = _make_org("org-a")org_b = _make_org("org-b")- cache[("api-key-a", "db")] = org_a- cache[("api-key-a-rotated", "db")] = org_a- cache[("api-key-b", "db")] = org_b+ cache[("api-key-a", "db")] = org_auth_service._CachedOrganizationAuth(org_a, "token-a")+ cache[("api-key-a-rotated", "db")] = org_auth_service._CachedOrganizationAuth(org_a, "token-a-rotated")+ cache[("api-key-b", "db")] = org_auth_service._CachedOrganizationAuth(org_b, "token-b")org_auth_service.invalidate_cached_org("org-a")@@ -385,7 +418,7 @@ def test_invalidate_cached_org_is_noop_when_id_absent() -> None:cache = org_auth_service._current_org_cachecache.clear()org = _make_org("org-a")- cache[("api-key", "db")] = org+ cache[("api-key", "db")] = org_auth_service._CachedOrganizationAuth(org, "token-a")org_auth_service.invalidate_cached_org("never-seen")@@ -1155,7 +1188,9 @@ def _principal_app() -> FastAPI:def principal() -> dict[str, object] | None:resolved = get_request_principal()- return asdict(resolved) if resolved else None+ return (+ {key: value for key, value in asdict(resolved).items() if key != "api_key_token_id"} if resolved else None+ )@fastapi_app.post("/org")async def org(_: Organization = Depends(org_auth_service.get_current_org)) -> dict[str, object] | None:@@ -1508,7 +1543,10 @@ async def test_concurrent_principal_resolutions_keep_one_canonical_result(await asyncio.sleep(0)release_first_lookup.set()first, second = await asyncio.wait_for(asyncio.gather(first_task, second_task), timeout=1)- return [asdict(first), asdict(second)]+ return [+ {key: value for key, value in asdict(principal).items() if key != "api_key_token_id"}+ for principal in (first, second)+ ]async with httpx.AsyncClient(transport=httpx.ASGITransport(app=fastapi_app), base_url="http://test") as client:response = await client.post("/concurrent-principals")