Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(warehouse): add peec ai actions and tag groups tables (#113307)

Tom Owers71cd8df78175
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
index d2bf2ab54ac0..d9e868ec0616 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
@@ -6510,6 +6510,15 @@ Diffed against: <https://raw.githubusercontent.com/PaystackOSS/openapi/main/dist
Note: paystack.com/docs/api is behind Cloudflare (403 to curl), so I used the vendor's own published OpenAPI repo PaystackOSS/openapi (dist/paystack.yaml, 125 paths). Coverage of the classic payments objects is good; the gaps are ledger/reconciliation and commerce.
+## PeecAI — gaps
+
+Today (9): `actions`, `archived_prompts`, `brands`, `chats`, `model_channels`, `prompts`, `tag_groups`, `tags`, `topics`
+
+Diffed against: <https://api.peec.ai/customer/v1/openapi/json>
+
+- [x] `/actions/list` — Peec-generated and customer-written actions per project, with status, impact and assignee (high)
+- [x] `/tag-groups` — lookup resolving the user-defined `group` values on the tags we already sync, with their shared color (low)
+
## Pendo — **thin**
Today (5): `accounts`, `features`, `guides`, `pages`, `visitors`
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/peec_ai/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/peec_ai/canonical_descriptions.py
index 0eabf13661b6..3408d587f643 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/peec_ai/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/peec_ai/canonical_descriptions.py
@@ -70,4 +70,36 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"is_active": "Whether this channel is active for the project.",
},
},
+ "tag_groups": {
+ "description": "User-defined tag groups, each with its shared color and tag count.",
+ "docs_url": "https://docs.peec.ai/api-reference/project/list-tag-groups",
+ "columns": {
+ "group": "The tag group name. Matches the group column in tags.",
+ "color": "The color shared by every tag in the group.",
+ "tag_count": "The number of tags in the group.",
+ },
+ },
+ "actions": {
+ "description": "Actions to improve AI visibility, both Peec-generated and customer-written.",
+ "docs_url": "https://docs.peec.ai/api-reference/actions/list-actions",
+ "columns": {
+ "id": "The unique action ID.",
+ "type": "The action type, such as a template action, content brief, or SEO issue.",
+ "status": "The action status: PENDING, ACCEPTED, REJECTED, or COMPLETED.",
+ "title": "What the action asks you to do.",
+ "group": "The kind of surface the action lands on.",
+ "target": "Whether the action lands on an owned page or an earned third-party page.",
+ "platform": "The third-party domain the action targets, or null for own-site actions.",
+ "topic_id": "The topic the action relates to.",
+ "source": "The page the action targets.",
+ "impact": "The expected gain if the action is completed, banded across the project's actions.",
+ "created_at": "When the action was created.",
+ "status_updated_at": "When the status last changed, or null while still pending.",
+ "created_by": "Who wrote the action: peec or customer.",
+ "priority": "The priority the customer set, or null if not set.",
+ "assignee_user_id": "The project member assigned to the action.",
+ "due_on": "The due date in the project's timezone.",
+ "tag_ids": "Tags the customer filed the action under.",
+ },
+ },
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/peec_ai/peec_ai.py b/products/warehouse_sources/backend/temporal/data_imports/sources/peec_ai/peec_ai.py
index abecef553da1..cb6541632d5f 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/peec_ai/peec_ai.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/peec_ai/peec_ai.py
@@ -9,6 +9,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.res
from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.typing import (
Endpoint,
EndpointResource,
+ PaginatorConfig,
RESTAPIConfig,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManager
@@ -89,13 +90,28 @@ def peec_ai_source(
end_date = resume.end_date or end_date
params.update(start_date=start_date, end_date=end_date)
- endpoint_config: Endpoint = {"path": definition["path"], "data_selector": "data", "params": params}
+ method = definition.get("method", "GET")
+ endpoint_config: Endpoint = {"path": definition["path"], "method": method, "data_selector": "data"}
+ if method == "POST":
+ endpoint_config["json"] = params
+ else:
+ endpoint_config["params"] = params
+
+ paginator: PaginatorConfig = "single_page"
+ if definition.get("paginated", True):
+ paginator = {
+ "type": "offset",
+ "limit": PAGE_SIZE,
+ "total_path": definition["total_path"],
+ "param_location": "json" if method == "POST" else "query",
+ }
+
resource_config: EndpointResource = {"name": endpoint, "endpoint": endpoint_config}
rest_config: RESTAPIConfig = {
"client": {
"base_url": f"{BASE_URL}/{api_version}/",
"auth": {"type": "api_key", "api_key": config.api_key, "name": "x-api-key", "location": "header"},
- "paginator": {"type": "offset", "limit": PAGE_SIZE, "total_path": definition["total_path"]},
+ "paginator": paginator,
"request_timeout": 30,
},
"resources": [resource_config],
@@ -118,7 +134,7 @@ def peec_ai_source(
return SourceResponse(
name=endpoint,
items=lambda: resource,
- primary_keys=["id"],
+ primary_keys=definition.get("primary_keys", ["id"]),
sort_mode="asc" if endpoint == "chats" else None,
on_complete=resumable_source_manager.clear_state,
)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/peec_ai/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/peec_ai/settings.py
index 8d899bde53b5..ef09ba1281e9 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/peec_ai/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/peec_ai/settings.py
@@ -1,4 +1,4 @@
-from typing import TypedDict
+from typing import Literal, NotRequired, TypedDict
from products.warehouse_sources.backend.temporal.data_imports.sources.common.schema import incremental_field
from products.warehouse_sources.backend.types import IncrementalFieldType
@@ -11,6 +11,9 @@ class PeecAIEndpoint(TypedDict):
path: str
params: dict[str, str]
total_path: str | None
+ method: NotRequired[Literal["GET", "POST"]]
+ paginated: NotRequired[bool]
+ primary_keys: NotRequired[list[str]]
ENDPOINTS: dict[str, PeecAIEndpoint] = {
@@ -25,6 +28,20 @@ ENDPOINTS: dict[str, PeecAIEndpoint] = {
"topics": {"path": "topics", "params": {}, "total_path": "total_count"},
"tags": {"path": "tags", "params": {}, "total_path": "total_count"},
"model_channels": {"path": "model-channels", "params": {}, "total_path": None},
+ "tag_groups": {
+ "path": "tag-groups",
+ "params": {},
+ "total_path": None,
+ "paginated": False,
+ "primary_keys": ["group"],
+ },
+ # The default impact order shifts as statuses change, so offset pages need a stable order.
+ "actions": {
+ "path": "actions/list",
+ "params": {"order_by": "created_at", "direction": "asc"},
+ "total_path": "total_count",
+ "method": "POST",
+ },
}
INCREMENTAL_FIELDS = {"chats": [incremental_field("date", IncrementalFieldType.Date)]}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/peec_ai/tests/test_peec_ai.py b/products/warehouse_sources/backend/temporal/data_imports/sources/peec_ai/tests/test_peec_ai.py
index eae2968cbba3..f6565b368429 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/peec_ai/tests/test_peec_ai.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/peec_ai/tests/test_peec_ai.py
@@ -189,6 +189,37 @@ def test_model_channels_stops_at_empty_page_without_total(
assert all("project_id" not in request_params(request) for request in http.requests)
+def test_actions_paginate_through_post_body(http: HTTPStub, config: PeecAISourceConfig, manager: MagicMock) -> None:
+ http.responses = [
+ (200, {"data": [{"id": "a"}, {"id": "b"}], "total_count": 3}),
+ (200, {"data": [{"id": "c"}], "total_count": 3}),
+ ]
+ batches = list(items(peec_ai_source(config, "actions", "v1", 1, "job", manager, False, None)))
+ assert [row for batch in batches for row in batch] == [{"id": "a"}, {"id": "b"}, {"id": "c"}]
+ for offset, request in zip([0, 2], http.requests, strict=True):
+ assert request.method == "POST"
+ assert request.url == "https://api.peec.ai/customer/v1/actions/list"
+ assert request.body is not None
+ assert json.loads(request.body) == {
+ "project_id": "or_example",
+ "order_by": "created_at",
+ "direction": "asc",
+ "limit": 2,
+ "offset": offset,
+ }
+
+
+def test_tag_groups_fetch_one_unpaginated_page(http: HTTPStub, config: PeecAISourceConfig, manager: MagicMock) -> None:
+ rows = [{"group": "persona", "color": "blue", "tag_count": 3}, {"group": "region", "color": None, "tag_count": 1}]
+ http.responses = [(200, {"data": rows})]
+ response = peec_ai_source(config, "tag_groups", "v1", 1, "job", manager, False, None)
+ assert list(items(response)) == [rows]
+ assert response.primary_keys == ["group"]
+ assert len(http.requests) == 1
+ assert request_params(http.requests[0]) == {"project_id": ["or_example"]}
+ manager.save_state.assert_not_called()
+
+
@pytest.mark.parametrize("status", [429, 500])
def test_sync_retries_transient_errors(
http: HTTPStub, config: PeecAISourceConfig, manager: MagicMock, status: int