|
9 | 9 | from agent_core import action |
10 | 10 |
|
11 | 11 |
|
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). |
53 | 16 |
|
54 | 17 |
|
55 | 18 | @action( |
@@ -207,8 +170,10 @@ def connect_integration(input_data: dict) -> dict: |
207 | 170 | if input_data.get("simulated_mode"): |
208 | 171 | return {"status": "success", "message": "Simulated mode", "auth_type": "token"} |
209 | 172 |
|
| 173 | + from app.data.action.integrations._helpers import normalize_integration_id |
| 174 | + |
210 | 175 | 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) |
212 | 177 | credentials = input_data.get("credentials", {}) or {} |
213 | 178 | auth_method = input_data.get("auth_method", "").strip().lower() |
214 | 179 |
|
@@ -474,27 +439,33 @@ def check_integration_status(input_data: dict) -> dict: |
474 | 439 | "message": "Simulated", |
475 | 440 | } |
476 | 441 |
|
| 442 | + from app.data.action.integrations._helpers import ( |
| 443 | + GOOGLE_FAMILY, |
| 444 | + GOOGLE_UMBRELLA, |
| 445 | + normalize_integration_id, |
| 446 | + ) |
| 447 | + |
477 | 448 | integration_id = input_data.get("integration_id", "").strip().lower() |
478 | 449 | session_id = input_data.get("session_id", "").strip() |
479 | 450 |
|
480 | 451 | if not integration_id: |
481 | 452 | return {"status": "error", "message": "integration_id is required."} |
482 | 453 |
|
483 | 454 | # 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) |
485 | 456 |
|
486 | 457 | # 'google' / 'google workspace' is not a single integration — the Workspace |
487 | 458 | # apps are tracked separately. Guide the caller to the specific app instead |
488 | 459 | # of failing with a bare "unknown integration". |
489 | | - if integration_id in _GOOGLE_UMBRELLA: |
| 460 | + if integration_id in GOOGLE_UMBRELLA: |
490 | 461 | return { |
491 | 462 | "status": "error", |
492 | 463 | "connected": False, |
493 | 464 | "accounts": [], |
494 | 465 | "message": ( |
495 | 466 | "'google' is not a single integration — Google Workspace apps are " |
496 | 467 | "tracked separately. Check the specific app instead: " |
497 | | - + ", ".join(_GOOGLE_FAMILY) |
| 468 | + + ", ".join(GOOGLE_FAMILY) |
498 | 469 | + "." |
499 | 470 | ), |
500 | 471 | } |
@@ -608,8 +579,10 @@ def disconnect_integration(input_data: dict) -> dict: |
608 | 579 | if input_data.get("simulated_mode"): |
609 | 580 | return {"status": "success", "message": "Simulated mode"} |
610 | 581 |
|
| 582 | + from app.data.action.integrations._helpers import normalize_integration_id |
| 583 | + |
611 | 584 | 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) |
613 | 586 | account_id = input_data.get("account_id", "").strip() or None |
614 | 587 |
|
615 | 588 | if not integration_id: |
|
0 commit comments