Skip to content

Commit 309b2cd

Browse files
committed
fix: name '_INTEGRATION_ALIASES' is not defined
1 parent 2b10f0c commit 309b2cd

2 files changed

Lines changed: 72 additions & 46 deletions

File tree

app/data/action/integrations/_helpers.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,59 @@ async def send_discord_message(input_data: dict) -> dict:
3232
from typing import Any, Callable, Dict, Optional
3333

3434

35+
# Common aliases the agent/user might use → canonical registered integration id.
36+
# Google Workspace apps in particular are frequently referred to by short names
37+
# or lumped under "google", which is not itself an integration.
38+
#
39+
# These live here (not in an action module) because action handlers are executed
40+
# via exec() on their own extracted source — module-level names in the action
41+
# file are NOT in scope at runtime. Handlers must import these inside the function
42+
# body, the same way they import run_client/with_client.
43+
INTEGRATION_ALIASES = {
44+
"mail": "gmail",
45+
"googlemail": "gmail",
46+
"google mail": "gmail",
47+
"drive": "google_drive",
48+
"gdrive": "google_drive",
49+
"googledrive": "google_drive",
50+
"google drive": "google_drive",
51+
"docs": "google_docs",
52+
"gdocs": "google_docs",
53+
"googledocs": "google_docs",
54+
"google docs": "google_docs",
55+
"google_doc": "google_docs",
56+
"calendar": "google_calendar",
57+
"gcal": "google_calendar",
58+
"gcalendar": "google_calendar",
59+
"google calendar": "google_calendar",
60+
"youtube": "google_youtube",
61+
}
62+
63+
# Umbrella terms that aren't a single integration — Google Workspace apps are
64+
# tracked individually, so callers must check the specific app.
65+
GOOGLE_UMBRELLA = {
66+
"google",
67+
"google workspace",
68+
"google_workspace",
69+
"workspace",
70+
"gsuite",
71+
"g suite",
72+
"google suite",
73+
}
74+
GOOGLE_FAMILY = (
75+
"gmail",
76+
"google_drive",
77+
"google_docs",
78+
"google_calendar",
79+
"google_youtube",
80+
)
81+
82+
83+
def normalize_integration_id(integration_id: str) -> str:
84+
"""Map a user/agent-supplied integration name through known aliases."""
85+
return INTEGRATION_ALIASES.get(integration_id, integration_id)
86+
87+
3588
def record_outgoing_message(platform_name: str, recipient: str, text: str) -> None:
3689
"""Best-effort: record an outgoing platform message into the agent's conversation history.
3790

app/data/action/integrations/integration_management.py

Lines changed: 19 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -9,47 +9,10 @@
99
from agent_core import action
1010

1111

12-
# Common aliases the agent/user might use → canonical registered integration id.
13-
# Google Workspace apps in particular are frequently referred to by short names
14-
# or lumped under "google", which is not itself an integration.
15-
_INTEGRATION_ALIASES = {
16-
"mail": "gmail",
17-
"googlemail": "gmail",
18-
"google mail": "gmail",
19-
"drive": "google_drive",
20-
"gdrive": "google_drive",
21-
"googledrive": "google_drive",
22-
"google drive": "google_drive",
23-
"docs": "google_docs",
24-
"gdocs": "google_docs",
25-
"googledocs": "google_docs",
26-
"google docs": "google_docs",
27-
"google_doc": "google_docs",
28-
"calendar": "google_calendar",
29-
"gcal": "google_calendar",
30-
"gcalendar": "google_calendar",
31-
"google calendar": "google_calendar",
32-
"youtube": "google_youtube",
33-
}
34-
35-
# Umbrella terms that aren't a single integration — Google Workspace apps are
36-
# tracked individually, so callers must check the specific app.
37-
_GOOGLE_UMBRELLA = {
38-
"google",
39-
"google workspace",
40-
"google_workspace",
41-
"workspace",
42-
"gsuite",
43-
"g suite",
44-
"google suite",
45-
}
46-
_GOOGLE_FAMILY = (
47-
"gmail",
48-
"google_drive",
49-
"google_docs",
50-
"google_calendar",
51-
"google_youtube",
52-
)
12+
# NOTE: integration alias/umbrella constants live in
13+
# app.data.action.integrations._helpers and are imported INSIDE each handler.
14+
# Action handlers run via exec() on their own extracted source, so module-level
15+
# names defined here would NOT be in scope at runtime (NameError).
5316

5417

5518
@action(
@@ -207,8 +170,10 @@ def connect_integration(input_data: dict) -> dict:
207170
if input_data.get("simulated_mode"):
208171
return {"status": "success", "message": "Simulated mode", "auth_type": "token"}
209172

173+
from app.data.action.integrations._helpers import normalize_integration_id
174+
210175
integration_id = input_data.get("integration_id", "").strip().lower()
211-
integration_id = _INTEGRATION_ALIASES.get(integration_id, integration_id)
176+
integration_id = normalize_integration_id(integration_id)
212177
credentials = input_data.get("credentials", {}) or {}
213178
auth_method = input_data.get("auth_method", "").strip().lower()
214179

@@ -474,27 +439,33 @@ def check_integration_status(input_data: dict) -> dict:
474439
"message": "Simulated",
475440
}
476441

442+
from app.data.action.integrations._helpers import (
443+
GOOGLE_FAMILY,
444+
GOOGLE_UMBRELLA,
445+
normalize_integration_id,
446+
)
447+
477448
integration_id = input_data.get("integration_id", "").strip().lower()
478449
session_id = input_data.get("session_id", "").strip()
479450

480451
if not integration_id:
481452
return {"status": "error", "message": "integration_id is required."}
482453

483454
# Normalize common aliases (e.g. 'gdrive' → 'google_drive').
484-
integration_id = _INTEGRATION_ALIASES.get(integration_id, integration_id)
455+
integration_id = normalize_integration_id(integration_id)
485456

486457
# 'google' / 'google workspace' is not a single integration — the Workspace
487458
# apps are tracked separately. Guide the caller to the specific app instead
488459
# of failing with a bare "unknown integration".
489-
if integration_id in _GOOGLE_UMBRELLA:
460+
if integration_id in GOOGLE_UMBRELLA:
490461
return {
491462
"status": "error",
492463
"connected": False,
493464
"accounts": [],
494465
"message": (
495466
"'google' is not a single integration — Google Workspace apps are "
496467
"tracked separately. Check the specific app instead: "
497-
+ ", ".join(_GOOGLE_FAMILY)
468+
+ ", ".join(GOOGLE_FAMILY)
498469
+ "."
499470
),
500471
}
@@ -608,8 +579,10 @@ def disconnect_integration(input_data: dict) -> dict:
608579
if input_data.get("simulated_mode"):
609580
return {"status": "success", "message": "Simulated mode"}
610581

582+
from app.data.action.integrations._helpers import normalize_integration_id
583+
611584
integration_id = input_data.get("integration_id", "").strip().lower()
612-
integration_id = _INTEGRATION_ALIASES.get(integration_id, integration_id)
585+
integration_id = normalize_integration_id(integration_id)
613586
account_id = input_data.get("account_id", "").strip() or None
614587

615588
if not integration_id:

0 commit comments

Comments
 (0)