autotouch-cli 0.2.116__tar.gz → 0.2.117__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/PKG-INFO +3 -3
  2. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/README.md +2 -2
  3. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/cli.py +46 -0
  4. autotouch_cli-0.2.117/autotouch_cli/commands/companies.py +174 -0
  5. autotouch_cli-0.2.117/autotouch_cli/commands/crm.py +275 -0
  6. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/commands/leads.py +119 -0
  7. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/data/CLI_REFERENCE.md +783 -363
  8. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/data/cli-manifest.json +8918 -6285
  9. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/parser.py +25 -0
  10. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli.egg-info/PKG-INFO +3 -3
  11. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli.egg-info/SOURCES.txt +2 -0
  12. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/pyproject.toml +1 -1
  13. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/MANIFEST.in +0 -0
  14. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/__init__.py +0 -0
  15. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/cli_contracts.py +0 -0
  16. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/commands/__init__.py +0 -0
  17. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/commands/agents.py +0 -0
  18. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/commands/auth.py +0 -0
  19. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/commands/capacity.py +0 -0
  20. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/commands/cells.py +0 -0
  21. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/commands/columns.py +0 -0
  22. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/commands/integrations.py +0 -0
  23. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/commands/jobs.py +0 -0
  24. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/commands/linkedin.py +0 -0
  25. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/commands/list_build.py +0 -0
  26. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/commands/outreach.py +0 -0
  27. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/commands/prompts.py +0 -0
  28. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/commands/rows.py +0 -0
  29. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/commands/search.py +0 -0
  30. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/commands/sender_accounts.py +0 -0
  31. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/commands/sequences.py +0 -0
  32. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/commands/tables.py +0 -0
  33. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/commands/tasks.py +0 -0
  34. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/commands/webhooks.py +0 -0
  35. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/commands/workspace_secrets.py +0 -0
  36. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/core/__init__.py +0 -0
  37. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/core/auth.py +0 -0
  38. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/core/config.py +0 -0
  39. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/core/csv_import.py +0 -0
  40. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/core/http.py +0 -0
  41. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/core/io.py +0 -0
  42. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/core/output.py +0 -0
  43. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/core/polling.py +0 -0
  44. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/core/run.py +0 -0
  45. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/core/validation.py +0 -0
  46. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/exceptions.py +0 -0
  47. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/mongo_status.py +0 -0
  48. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/parser_groups.py +0 -0
  49. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/sequence_support.py +0 -0
  50. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli/templates.py +0 -0
  51. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli.egg-info/dependency_links.txt +0 -0
  52. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli.egg-info/entry_points.txt +0 -0
  53. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli.egg-info/requires.txt +0 -0
  54. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_cli.egg-info/top_level.txt +0 -0
  55. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_shared/__init__.py +0 -0
  56. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_shared/linkedin_contract.py +0 -0
  57. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_shared/linkedin_filters.py +0 -0
  58. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_shared/list_build_contract.py +0 -0
  59. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_shared/pipeline_patterns.py +0 -0
  60. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_shared/product_lifecycle.py +0 -0
  61. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_shared/product_use_cases.py +0 -0
  62. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_shared/provider_registry.py +0 -0
  63. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_shared/search_contract.py +0 -0
  64. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/autotouch_shared/workflow_plans.py +0 -0
  65. {autotouch_cli-0.2.116 → autotouch_cli-0.2.117}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: autotouch-cli
3
- Version: 0.2.116
3
+ Version: 0.2.117
4
4
  Summary: Autotouch Smart Table CLI
5
5
  Project-URL: Homepage, https://app.autotouch.ai
6
6
  Project-URL: Documentation, https://github.com/nicolonic/autotouch_main/tree/main/docs/research-table/reference
@@ -223,7 +223,7 @@ Keep `requiredVariables` limited to variables that the sequence actually needs.
223
223
 
224
224
  Version guard:
225
225
 
226
- - Use `autotouch --version` before relying on recipe defaults. This repo expects `autotouch-cli` `0.2.116` or newer.
226
+ - Use `autotouch --version` before relying on recipe defaults. This repo expects `autotouch-cli` `0.2.117` or newer.
227
227
  - If `python3 -m pip install -U autotouch-cli` upgrades the package but `which autotouch` still points at an older shim, run the upgraded binary directly or fix PATH before creating production sequences.
228
228
  - Before authoring a LinkedIn sequence, inspect the live recipe:
229
229
 
@@ -353,7 +353,7 @@ For automation or agent-driven setup, use:
353
353
  - `autotouch cli-reference` for the shipped parser-generated reference
354
354
  - `autotouch capabilities --output json` for provider/workflow contracts
355
355
  - `autotouch capabilities operations search "find work emails"` and `autotouch capabilities operations get research_table.email_finder` to map product operations to the current CLI command path
356
- - `autotouch --version` should be `0.2.116` or newer for product-operation discovery via `capabilities operations list/search/get`, structured company list builds without user-supplied keywords, stored list-build input lookup, research-workspace list-build guidance, the cleaned single LinkedIn-sourced list-build path, Exa Company Search up to 100 results, scheduled agent `--target ACCOUNTS|LEADS`, `agents signals --target`, the `agent_to_sequence` and `agent_to_leads` workflow scaffolds, paced HTTP Request column contracts, branch-aware LinkedIn sequence recipes, `LINKEDIN_MESSAGE` best-available delivery versus `LINKEDIN_CHAT_MESSAGE` chat-only guidance, sequence campaign intake guards before mutating objects, real agent soft-delete with associated-table handling, research-table sequence handoff assignee and active-sequence-conflict guard config, backend-owned directional source/destination helpers, goal-level workflow plans, website visitor/external intent webhook workflow guidance, create-time agent assignment defaults, company-page signal configuration guidance, sequence authoring warnings when AI draft is mixed with fixed templates, sender-account discovery/management for explicit sequence routing, mixed parent-row/child-list Sync to Table and Sync to Leads recipe configs, and company variable guidance for `company_name_clean` versus internal match keys
356
+ - `autotouch --version` should be `0.2.117` or newer for product-operation discovery via `capabilities operations list/search/get`, CRM custom-field catalog/create/update commands, lead/company custom-field value writes, structured company list builds without user-supplied keywords, stored list-build input lookup, research-workspace list-build guidance, the cleaned single LinkedIn-sourced list-build path, Exa Company Search up to 100 results, scheduled agent `--target ACCOUNTS|LEADS`, `agents signals --target`, the `agent_to_sequence` and `agent_to_leads` workflow scaffolds, paced HTTP Request column contracts, branch-aware LinkedIn sequence recipes, `LINKEDIN_MESSAGE` best-available delivery versus `LINKEDIN_CHAT_MESSAGE` chat-only guidance, sequence campaign intake guards before mutating objects, real agent soft-delete with associated-table handling, research-table sequence handoff assignee and active-sequence-conflict guard config, backend-owned directional source/destination helpers, goal-level workflow plans, website visitor/external intent webhook workflow guidance, create-time agent assignment defaults, company-page signal configuration guidance, sequence authoring warnings when AI draft is mixed with fixed templates, sender-account discovery/management for explicit sequence routing, mixed parent-row/child-list Sync to Table and Sync to Leads recipe configs, and company variable guidance for `company_name_clean` versus internal match keys
357
357
  - `autotouch capabilities --output json --select list_builds` for documented list-build inputs such as geography IDs, company size buckets, profile language, and company IDs
358
358
  - `autotouch integrations list` and `autotouch integrations status --provider <provider>` before choosing source/destination workflows
359
359
  - `autotouch workflows plan --type bulk_outreach` and `autotouch workflows scaffold --type bulk_outreach --out-dir workflow` for goal-level workflow planning
@@ -198,7 +198,7 @@ Keep `requiredVariables` limited to variables that the sequence actually needs.
198
198
 
199
199
  Version guard:
200
200
 
201
- - Use `autotouch --version` before relying on recipe defaults. This repo expects `autotouch-cli` `0.2.116` or newer.
201
+ - Use `autotouch --version` before relying on recipe defaults. This repo expects `autotouch-cli` `0.2.117` or newer.
202
202
  - If `python3 -m pip install -U autotouch-cli` upgrades the package but `which autotouch` still points at an older shim, run the upgraded binary directly or fix PATH before creating production sequences.
203
203
  - Before authoring a LinkedIn sequence, inspect the live recipe:
204
204
 
@@ -328,7 +328,7 @@ For automation or agent-driven setup, use:
328
328
  - `autotouch cli-reference` for the shipped parser-generated reference
329
329
  - `autotouch capabilities --output json` for provider/workflow contracts
330
330
  - `autotouch capabilities operations search "find work emails"` and `autotouch capabilities operations get research_table.email_finder` to map product operations to the current CLI command path
331
- - `autotouch --version` should be `0.2.116` or newer for product-operation discovery via `capabilities operations list/search/get`, structured company list builds without user-supplied keywords, stored list-build input lookup, research-workspace list-build guidance, the cleaned single LinkedIn-sourced list-build path, Exa Company Search up to 100 results, scheduled agent `--target ACCOUNTS|LEADS`, `agents signals --target`, the `agent_to_sequence` and `agent_to_leads` workflow scaffolds, paced HTTP Request column contracts, branch-aware LinkedIn sequence recipes, `LINKEDIN_MESSAGE` best-available delivery versus `LINKEDIN_CHAT_MESSAGE` chat-only guidance, sequence campaign intake guards before mutating objects, real agent soft-delete with associated-table handling, research-table sequence handoff assignee and active-sequence-conflict guard config, backend-owned directional source/destination helpers, goal-level workflow plans, website visitor/external intent webhook workflow guidance, create-time agent assignment defaults, company-page signal configuration guidance, sequence authoring warnings when AI draft is mixed with fixed templates, sender-account discovery/management for explicit sequence routing, mixed parent-row/child-list Sync to Table and Sync to Leads recipe configs, and company variable guidance for `company_name_clean` versus internal match keys
331
+ - `autotouch --version` should be `0.2.117` or newer for product-operation discovery via `capabilities operations list/search/get`, CRM custom-field catalog/create/update commands, lead/company custom-field value writes, structured company list builds without user-supplied keywords, stored list-build input lookup, research-workspace list-build guidance, the cleaned single LinkedIn-sourced list-build path, Exa Company Search up to 100 results, scheduled agent `--target ACCOUNTS|LEADS`, `agents signals --target`, the `agent_to_sequence` and `agent_to_leads` workflow scaffolds, paced HTTP Request column contracts, branch-aware LinkedIn sequence recipes, `LINKEDIN_MESSAGE` best-available delivery versus `LINKEDIN_CHAT_MESSAGE` chat-only guidance, sequence campaign intake guards before mutating objects, real agent soft-delete with associated-table handling, research-table sequence handoff assignee and active-sequence-conflict guard config, backend-owned directional source/destination helpers, goal-level workflow plans, website visitor/external intent webhook workflow guidance, create-time agent assignment defaults, company-page signal configuration guidance, sequence authoring warnings when AI draft is mixed with fixed templates, sender-account discovery/management for explicit sequence routing, mixed parent-row/child-list Sync to Table and Sync to Leads recipe configs, and company variable guidance for `company_name_clean` versus internal match keys
332
332
  - `autotouch capabilities --output json --select list_builds` for documented list-build inputs such as geography IDs, company size buckets, profile language, and company IDs
333
333
  - `autotouch integrations list` and `autotouch integrations status --provider <provider>` before choosing source/destination workflows
334
334
  - `autotouch workflows plan --type bulk_outreach` and `autotouch workflows scaffold --type bulk_outreach --out-dir workflow` for goal-level workflow planning
@@ -54,6 +54,17 @@ from autotouch_cli.commands.columns import (
54
54
  cmd_columns_test_http_request as cmd_columns_test_http_request_impl,
55
55
  cmd_columns_update as cmd_columns_update_impl,
56
56
  )
57
+ from autotouch_cli.commands.companies import (
58
+ CompanyCommandRuntime as CompanyCommandHandlerRuntime,
59
+ cmd_companies_custom_fields_bulk_set as cmd_companies_custom_fields_bulk_set_impl,
60
+ cmd_companies_custom_fields_set as cmd_companies_custom_fields_set_impl,
61
+ )
62
+ from autotouch_cli.commands.crm import (
63
+ CrmCommandRuntime as CrmCommandHandlerRuntime,
64
+ cmd_crm_fields_create as cmd_crm_fields_create_impl,
65
+ cmd_crm_fields_list as cmd_crm_fields_list_impl,
66
+ cmd_crm_fields_update as cmd_crm_fields_update_impl,
67
+ )
57
68
  from autotouch_cli.commands.cells import (
58
69
  CellCommandRuntime as CellCommandHandlerRuntime,
59
70
  cmd_cells_get as cmd_cells_get_impl,
@@ -95,6 +106,8 @@ from autotouch_cli.commands.leads import (
95
106
  LeadCommandRuntime as LeadCommandHandlerRuntime,
96
107
  cmd_leads_count as cmd_leads_count_impl,
97
108
  cmd_leads_create as cmd_leads_create_impl,
109
+ cmd_leads_custom_fields_bulk_set as cmd_leads_custom_fields_bulk_set_impl,
110
+ cmd_leads_custom_fields_set as cmd_leads_custom_fields_set_impl,
98
111
  cmd_leads_filters_metadata as cmd_leads_filters_metadata_impl,
99
112
  cmd_leads_get as cmd_leads_get_impl,
100
113
  cmd_leads_query as cmd_leads_query_impl,
@@ -1398,6 +1411,28 @@ def _lead_command_runtime() -> LeadCommandHandlerRuntime:
1398
1411
  )
1399
1412
 
1400
1413
 
1414
+ def _company_command_runtime() -> CompanyCommandHandlerRuntime:
1415
+ return CompanyCommandHandlerRuntime(
1416
+ resolve_token=_resolve_token,
1417
+ request_api=_request_api,
1418
+ print_json=lambda data, compact=False: _print_json(data, compact=compact),
1419
+ load_json_input=_load_json_input,
1420
+ split_cli_string_values=_split_cli_string_values,
1421
+ parse_string_list_payload=_parse_string_list_payload,
1422
+ dedupe_keep_order=_dedupe_keep_order,
1423
+ normalize_string_value=_normalize_string_value,
1424
+ )
1425
+
1426
+
1427
+ def _crm_command_runtime() -> CrmCommandHandlerRuntime:
1428
+ return CrmCommandHandlerRuntime(
1429
+ resolve_token=_resolve_token,
1430
+ request_api=_request_api,
1431
+ print_json=lambda data, compact=False: _print_json(data, compact=compact),
1432
+ load_json_input=_load_json_input,
1433
+ )
1434
+
1435
+
1401
1436
  def _search_command_runtime() -> SearchCommandHandlerRuntime:
1402
1437
  return SearchCommandHandlerRuntime(
1403
1438
  resolve_token=_resolve_token,
@@ -1594,6 +1629,11 @@ _register("integrations_recipe", cmd_integrations_recipe_impl, _integration_comm
1594
1629
  _register("integrations_from_crm_status", cmd_integrations_from_crm_status_impl, _integration_command_runtime)
1595
1630
  _register("integrations_to_crm_status", cmd_integrations_to_crm_status_impl, _integration_command_runtime)
1596
1631
 
1632
+ # -- CRM commands --
1633
+ _register("crm_fields_list", cmd_crm_fields_list_impl, _crm_command_runtime)
1634
+ _register("crm_fields_create", cmd_crm_fields_create_impl, _crm_command_runtime)
1635
+ _register("crm_fields_update", cmd_crm_fields_update_impl, _crm_command_runtime)
1636
+
1597
1637
  # -- Outreach commands --
1598
1638
  _register("outreach_accounts_list", cmd_outreach_accounts_list_impl, _outreach_command_runtime)
1599
1639
  _register("outreach_campaigns_list", cmd_outreach_campaigns_list_impl, _outreach_command_runtime)
@@ -1616,6 +1656,8 @@ _register("leads_query", cmd_leads_query_impl, _lead_command_runtime)
1616
1656
  _register("leads_get", cmd_leads_get_impl, _lead_command_runtime)
1617
1657
  _register("leads_create", cmd_leads_create_impl, _lead_command_runtime)
1618
1658
  _register("leads_update", cmd_leads_update_impl, _lead_command_runtime)
1659
+ _register("leads_custom_fields_set", cmd_leads_custom_fields_set_impl, _lead_command_runtime)
1660
+ _register("leads_custom_fields_bulk_set", cmd_leads_custom_fields_bulk_set_impl, _lead_command_runtime)
1619
1661
  _register("leads_upsert_contact_channels", cmd_leads_upsert_contact_channels_impl, _lead_command_runtime)
1620
1662
  _register("leads_count", cmd_leads_count_impl, _lead_command_runtime)
1621
1663
  _register("leads_stats", cmd_leads_stats_impl, _lead_command_runtime)
@@ -1625,6 +1667,10 @@ _register("leads_research_tables", cmd_leads_research_tables_impl, _lead_command
1625
1667
  _register("leads_update_status", cmd_leads_update_status_impl, _lead_command_runtime)
1626
1668
  _register("leads_reassign_owner", cmd_leads_reassign_owner_impl, _lead_command_runtime)
1627
1669
 
1670
+ # -- Company commands --
1671
+ _register("companies_custom_fields_set", cmd_companies_custom_fields_set_impl, _company_command_runtime)
1672
+ _register("companies_custom_fields_bulk_set", cmd_companies_custom_fields_bulk_set_impl, _company_command_runtime)
1673
+
1628
1674
  # -- Task commands --
1629
1675
  _register("tasks_query", cmd_tasks_query_impl, _task_command_runtime)
1630
1676
  _register("tasks_count", cmd_tasks_count_impl, _task_command_runtime)
@@ -0,0 +1,174 @@
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ from dataclasses import dataclass
5
+ from typing import Any, Callable, Dict, List, Optional
6
+
7
+ from autotouch_cli.exceptions import AutotouchInputError
8
+
9
+
10
+ @dataclass(frozen=True)
11
+ class CompanyCommandRuntime:
12
+ resolve_token: Callable[[Optional[str], bool], Optional[str]]
13
+ request_api: Callable[..., Any]
14
+ print_json: Callable[[Any, bool], None]
15
+ load_json_input: Callable[..., Any]
16
+ split_cli_string_values: Callable[[Optional[List[str]]], List[str]]
17
+ parse_string_list_payload: Callable[..., List[str]]
18
+ dedupe_keep_order: Callable[[List[str]], List[str]]
19
+ normalize_string_value: Callable[[Any], str]
20
+
21
+
22
+ def _load_company_ids(args: argparse.Namespace, *, runtime: CompanyCommandRuntime) -> List[str]:
23
+ company_ids = runtime.split_cli_string_values(getattr(args, "company_id", None))
24
+ payload = runtime.load_json_input(
25
+ inline_json=getattr(args, "company_ids_json", None),
26
+ file_path=getattr(args, "company_ids_file", None),
27
+ context="company_ids",
28
+ default=None,
29
+ )
30
+ if payload is not None:
31
+ company_ids.extend(runtime.parse_string_list_payload(payload, context="company_ids", key="company_ids"))
32
+ return runtime.dedupe_keep_order(company_ids)
33
+
34
+
35
+ def _load_custom_field_values_from_flags(args: argparse.Namespace, *, runtime: CompanyCommandRuntime) -> Dict[str, Any]:
36
+ field_key = runtime.normalize_string_value(getattr(args, "field_key", None))
37
+ if not field_key:
38
+ raise AutotouchInputError("--field-key is required unless --data-json/--data-file provides values")
39
+
40
+ has_value = getattr(args, "value", None) is not None
41
+ has_value_json = getattr(args, "value_json", None) is not None or getattr(args, "value_file", None) is not None
42
+ clear = bool(getattr(args, "clear", False))
43
+ selected_modes = sum(1 for enabled in (has_value, has_value_json, clear) if enabled)
44
+ if selected_modes != 1:
45
+ raise AutotouchInputError("provide exactly one of --value, --value-json/--value-file, or --clear")
46
+
47
+ if clear:
48
+ value: Any = None
49
+ elif has_value_json:
50
+ value = runtime.load_json_input(
51
+ inline_json=getattr(args, "value_json", None),
52
+ file_path=getattr(args, "value_file", None),
53
+ context="value",
54
+ default=None,
55
+ )
56
+ else:
57
+ value = getattr(args, "value", None)
58
+ return {field_key: value}
59
+
60
+
61
+ def _load_company_custom_fields_payload(args: argparse.Namespace, *, runtime: CompanyCommandRuntime) -> Dict[str, Any]:
62
+ explicit_payload = runtime.load_json_input(
63
+ inline_json=getattr(args, "data_json", None),
64
+ file_path=getattr(args, "data_file", None),
65
+ context="data",
66
+ default=None,
67
+ )
68
+ if explicit_payload is not None:
69
+ if not isinstance(explicit_payload, dict):
70
+ raise AutotouchInputError("company custom field payload must be a JSON object")
71
+ return explicit_payload
72
+ return {"values": _load_custom_field_values_from_flags(args, runtime=runtime)}
73
+
74
+
75
+ def _load_company_bulk_custom_fields_payload(args: argparse.Namespace, *, runtime: CompanyCommandRuntime) -> Dict[str, Any]:
76
+ explicit_payload = runtime.load_json_input(
77
+ inline_json=getattr(args, "data_json", None),
78
+ file_path=getattr(args, "data_file", None),
79
+ context="data",
80
+ default=None,
81
+ )
82
+ if explicit_payload is not None:
83
+ if not isinstance(explicit_payload, dict):
84
+ raise AutotouchInputError("bulk company custom field payload must be a JSON object")
85
+ return explicit_payload
86
+
87
+ company_ids = _load_company_ids(args, runtime=runtime)
88
+ if not company_ids:
89
+ raise AutotouchInputError("provide company ids or an explicit --data-json/--data-file selection")
90
+ return {
91
+ "company_ids": company_ids,
92
+ "values": _load_custom_field_values_from_flags(args, runtime=runtime),
93
+ }
94
+
95
+
96
+ def cmd_companies_custom_fields_set(args: argparse.Namespace, *, runtime: CompanyCommandRuntime) -> None:
97
+ token = runtime.resolve_token(args.token, required=True)
98
+ payload = _load_company_custom_fields_payload(args, runtime=runtime)
99
+ data = runtime.request_api(
100
+ "PATCH",
101
+ f"/api/companies/{args.company_id}/custom-fields",
102
+ base_url=args.base_url,
103
+ token=token,
104
+ use_x_api_key=args.use_x_api_key,
105
+ payload=payload,
106
+ timeout=args.timeout,
107
+ verbose=args.verbose,
108
+ )
109
+ runtime.print_json(data, args.compact)
110
+
111
+
112
+ def cmd_companies_custom_fields_bulk_set(args: argparse.Namespace, *, runtime: CompanyCommandRuntime) -> None:
113
+ token = runtime.resolve_token(args.token, required=True)
114
+ payload = _load_company_bulk_custom_fields_payload(args, runtime=runtime)
115
+ data = runtime.request_api(
116
+ "POST",
117
+ "/api/companies/bulk_custom_fields",
118
+ base_url=args.base_url,
119
+ token=token,
120
+ use_x_api_key=args.use_x_api_key,
121
+ payload=payload,
122
+ timeout=args.timeout,
123
+ verbose=args.verbose,
124
+ )
125
+ runtime.print_json(data, args.compact)
126
+
127
+
128
+ def _add_custom_field_value_arguments(parser: argparse.ArgumentParser) -> None:
129
+ parser.add_argument("--data-json", help="Explicit custom field payload JSON")
130
+ parser.add_argument("--data-file", help="Path to custom field payload JSON file")
131
+ parser.add_argument("--field-key", help="Custom field key from `autotouch crm fields list`, not label or id")
132
+ value_group = parser.add_mutually_exclusive_group()
133
+ value_group.add_argument("--value", help="String value to write")
134
+ value_group.add_argument("--value-json", help="Typed JSON value to write")
135
+ value_group.add_argument("--value-file", help="Path to JSON value to write")
136
+ value_group.add_argument("--clear", action="store_true", help="Clear the custom field value")
137
+
138
+
139
+ def register_companies_subcommands(
140
+ subparsers: argparse._SubParsersAction[argparse.ArgumentParser],
141
+ *,
142
+ add_api_common_arguments: Callable[[argparse.ArgumentParser], None],
143
+ handlers: Dict[str, Callable[[argparse.Namespace], None]],
144
+ ) -> None:
145
+ parser = subparsers.add_parser("companies", help="Company workspace operations")
146
+ parser._codex_examples = [
147
+ "autotouch companies custom-fields set --company-id <COMPANY_ID> --field-key account_tier --value strategic",
148
+ "autotouch companies custom-fields bulk-set --company-id <COMPANY_ID> --field-key account_tier --value strategic",
149
+ ]
150
+ companies_sub = parser.add_subparsers(dest="companies_cmd", required=True)
151
+
152
+ custom_fields_parser = companies_sub.add_parser("custom-fields", help="Set company custom field values")
153
+ custom_fields_sub = custom_fields_parser.add_subparsers(dest="companies_custom_fields_cmd", required=True)
154
+
155
+ set_parser = custom_fields_sub.add_parser("set", help="Set one custom field value on one company")
156
+ set_parser.add_argument("--company-id", required=True)
157
+ _add_custom_field_value_arguments(set_parser)
158
+ add_api_common_arguments(set_parser)
159
+ set_parser.set_defaults(func=handlers["custom_fields_set"])
160
+
161
+ bulk_set_parser = custom_fields_sub.add_parser(
162
+ "bulk-set",
163
+ help="Set one custom field value on selected companies",
164
+ )
165
+ bulk_set_parser.add_argument(
166
+ "--company-id",
167
+ action="append",
168
+ help="Company id (repeatable; comma-separated also supported)",
169
+ )
170
+ bulk_set_parser.add_argument("--company-ids-json", help="JSON array or object with company_ids[]")
171
+ bulk_set_parser.add_argument("--company-ids-file", help="Path to JSON file with company_ids[]")
172
+ _add_custom_field_value_arguments(bulk_set_parser)
173
+ add_api_common_arguments(bulk_set_parser)
174
+ bulk_set_parser.set_defaults(func=handlers["custom_fields_bulk_set"])
@@ -0,0 +1,275 @@
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ from dataclasses import dataclass
5
+ from typing import Any, Callable, Dict, List, Optional
6
+
7
+ from autotouch_cli.exceptions import AutotouchInputError
8
+
9
+
10
+ CRM_FIELD_ENTITY_TYPES = ("lead", "company")
11
+ CRM_FIELD_DATA_TYPES = ("text", "number", "date", "boolean", "select", "multi_select")
12
+ CRM_FIELD_USAGES = (
13
+ "profile",
14
+ "table",
15
+ "sync_to_leads",
16
+ "filter",
17
+ "sort",
18
+ "search",
19
+ "task_context",
20
+ "sequence_variables",
21
+ "ai_context",
22
+ )
23
+
24
+
25
+ @dataclass(frozen=True)
26
+ class CrmCommandRuntime:
27
+ resolve_token: Callable[[Optional[str], bool], Optional[str]]
28
+ request_api: Callable[..., Any]
29
+ print_json: Callable[[Any, bool], None]
30
+ load_json_input: Callable[..., Any]
31
+
32
+
33
+ def _compact_dict(data: Dict[str, Any]) -> Dict[str, Any]:
34
+ return {key: value for key, value in data.items() if value is not None}
35
+
36
+
37
+ def _parse_option(raw: str) -> Dict[str, str]:
38
+ text = str(raw or "").strip()
39
+ if not text:
40
+ raise AutotouchInputError("--option values cannot be empty")
41
+ if "=" in text:
42
+ value, label = text.split("=", 1)
43
+ else:
44
+ value = text
45
+ label = text
46
+ value = value.strip()
47
+ label = label.strip()
48
+ color = ""
49
+ if ":#" in label:
50
+ label, color_tail = label.rsplit(":#", 1)
51
+ color = f"#{color_tail.strip()}"
52
+ label = label.strip()
53
+ if not value or not label:
54
+ raise AutotouchInputError("--option must be VALUE=Label or VALUE=Label:#hex")
55
+ option: Dict[str, str] = {"value": value, "label": label}
56
+ if color:
57
+ option["color"] = color
58
+ return option
59
+
60
+
61
+ def _load_options(args: argparse.Namespace, *, runtime: CrmCommandRuntime) -> Optional[List[Dict[str, Any]]]:
62
+ inline = getattr(args, "options_json", None)
63
+ file_path = getattr(args, "options_file", None)
64
+ loaded = runtime.load_json_input(
65
+ inline_json=inline,
66
+ file_path=file_path,
67
+ context="options",
68
+ default=None,
69
+ )
70
+ cli_options = [_parse_option(raw) for raw in (getattr(args, "option", None) or [])]
71
+ if loaded is not None:
72
+ if not isinstance(loaded, list):
73
+ raise AutotouchInputError("options payload must be a JSON array")
74
+ if cli_options:
75
+ raise AutotouchInputError("pass either --option or --options-json/--options-file, not both")
76
+ return loaded
77
+ if cli_options:
78
+ return cli_options
79
+ return None
80
+
81
+
82
+ def _flag_value(args: argparse.Namespace, name: str) -> Optional[bool]:
83
+ return getattr(args, name, None)
84
+
85
+
86
+ def _definition_payload(args: argparse.Namespace, *, runtime: CrmCommandRuntime, create: bool) -> Dict[str, Any]:
87
+ explicit = runtime.load_json_input(
88
+ inline_json=getattr(args, "data_json", None),
89
+ file_path=getattr(args, "data_file", None),
90
+ context="data",
91
+ default=None,
92
+ )
93
+ if explicit is not None:
94
+ if not isinstance(explicit, dict):
95
+ raise AutotouchInputError("CRM custom field payload must be a JSON object")
96
+ return explicit
97
+
98
+ payload: Dict[str, Any] = {}
99
+ if create:
100
+ payload["entity_type"] = getattr(args, "entity", None)
101
+ payload["label"] = getattr(args, "label", None)
102
+ payload["data_type"] = getattr(args, "type", None)
103
+ if not payload["entity_type"] or not payload["label"] or not payload["data_type"]:
104
+ raise AutotouchInputError("--entity, --label, and --type are required unless --data-json/--data-file is provided")
105
+ else:
106
+ label = str(getattr(args, "label", "") or "").strip()
107
+ if label:
108
+ payload["label"] = label
109
+
110
+ key = str(getattr(args, "key", "") or "").strip()
111
+ if key:
112
+ if not create:
113
+ raise AutotouchInputError("CRM custom field keys are not editable")
114
+ payload["key"] = key
115
+
116
+ options = _load_options(args, runtime=runtime)
117
+ if options is not None:
118
+ payload["options"] = options
119
+
120
+ for attr in (
121
+ "is_filterable",
122
+ "is_sortable",
123
+ "is_searchable",
124
+ "include_in_sequence_variables",
125
+ "include_in_task_context",
126
+ "include_in_ai_context",
127
+ ):
128
+ value = _flag_value(args, attr)
129
+ if value is not None:
130
+ payload[attr] = value
131
+
132
+ if not payload:
133
+ raise AutotouchInputError("provide at least one CRM custom field update")
134
+ return _compact_dict(payload)
135
+
136
+
137
+ def cmd_crm_fields_list(args: argparse.Namespace, *, runtime: CrmCommandRuntime) -> None:
138
+ token = runtime.resolve_token(args.token, required=True)
139
+ include_standard = not bool(getattr(args, "custom_only", False))
140
+ params = _compact_dict(
141
+ {
142
+ "entity_type": getattr(args, "entity", None),
143
+ "usage": getattr(args, "usage", None),
144
+ "include_standard": include_standard,
145
+ }
146
+ )
147
+ data = runtime.request_api(
148
+ "GET",
149
+ "/api/crm/fields",
150
+ base_url=args.base_url,
151
+ token=token,
152
+ use_x_api_key=args.use_x_api_key,
153
+ params=params,
154
+ timeout=args.timeout,
155
+ verbose=args.verbose,
156
+ )
157
+ runtime.print_json(data, args.compact)
158
+
159
+
160
+ def cmd_crm_fields_create(args: argparse.Namespace, *, runtime: CrmCommandRuntime) -> None:
161
+ token = runtime.resolve_token(args.token, required=True)
162
+ payload = _definition_payload(args, runtime=runtime, create=True)
163
+ data = runtime.request_api(
164
+ "POST",
165
+ "/api/crm/custom-fields",
166
+ base_url=args.base_url,
167
+ token=token,
168
+ use_x_api_key=args.use_x_api_key,
169
+ payload=payload,
170
+ timeout=args.timeout,
171
+ verbose=args.verbose,
172
+ )
173
+ runtime.print_json(data, args.compact)
174
+
175
+
176
+ def cmd_crm_fields_update(args: argparse.Namespace, *, runtime: CrmCommandRuntime) -> None:
177
+ token = runtime.resolve_token(args.token, required=True)
178
+ payload = _definition_payload(args, runtime=runtime, create=False)
179
+ data = runtime.request_api(
180
+ "PATCH",
181
+ f"/api/crm/custom-fields/{args.field_id}",
182
+ base_url=args.base_url,
183
+ token=token,
184
+ use_x_api_key=args.use_x_api_key,
185
+ payload=payload,
186
+ timeout=args.timeout,
187
+ verbose=args.verbose,
188
+ )
189
+ runtime.print_json(data, args.compact)
190
+
191
+
192
+ def _add_definition_payload_args(parser: argparse.ArgumentParser, *, create: bool) -> None:
193
+ parser.add_argument("--data-json", help="Explicit CRM custom field payload JSON")
194
+ parser.add_argument("--data-file", help="Path to CRM custom field payload JSON file")
195
+ if create:
196
+ parser.add_argument("--entity", choices=CRM_FIELD_ENTITY_TYPES, help="Custom field entity type")
197
+ parser.add_argument("--key", help="Optional stable snake_case key; derived from label when omitted")
198
+ parser.add_argument("--type", choices=CRM_FIELD_DATA_TYPES, help="Custom field data type")
199
+ parser.add_argument("--label", help="Custom field display label")
200
+ parser.add_argument(
201
+ "--option",
202
+ action="append",
203
+ help="Select option as VALUE=Label or VALUE=Label:#hex; repeat for select/multi_select fields",
204
+ )
205
+ parser.add_argument("--options-json", help="JSON array of option objects")
206
+ parser.add_argument("--options-file", help="Path to JSON array of option objects")
207
+ _add_nullable_boolean_pair(parser, "is_filterable", "--filterable", "--not-filterable")
208
+ _add_nullable_boolean_pair(parser, "is_sortable", "--sortable", "--not-sortable")
209
+ _add_nullable_boolean_pair(parser, "is_searchable", "--searchable", "--not-searchable")
210
+ _add_nullable_boolean_pair(
211
+ parser,
212
+ "include_in_sequence_variables",
213
+ "--include-in-sequence-variables",
214
+ "--exclude-from-sequence-variables",
215
+ )
216
+ _add_nullable_boolean_pair(
217
+ parser,
218
+ "include_in_task_context",
219
+ "--include-in-task-context",
220
+ "--exclude-from-task-context",
221
+ )
222
+ _add_nullable_boolean_pair(
223
+ parser,
224
+ "include_in_ai_context",
225
+ "--include-in-ai-context",
226
+ "--exclude-from-ai-context",
227
+ )
228
+
229
+
230
+ def _add_nullable_boolean_pair(
231
+ parser: argparse.ArgumentParser,
232
+ dest: str,
233
+ positive: str,
234
+ negative: str,
235
+ ) -> None:
236
+ group = parser.add_mutually_exclusive_group()
237
+ group.add_argument(positive, dest=dest, action="store_true")
238
+ group.add_argument(negative, dest=dest, action="store_false")
239
+ parser.set_defaults(**{dest: None})
240
+
241
+
242
+ def register_crm_subcommands(
243
+ subparsers: argparse._SubParsersAction[argparse.ArgumentParser],
244
+ *,
245
+ add_api_common_arguments: Callable[[argparse.ArgumentParser], None],
246
+ handlers: Dict[str, Callable[[argparse.Namespace], None]],
247
+ ) -> None:
248
+ parser = subparsers.add_parser("crm", help="CRM workspace field catalog and custom fields")
249
+ parser._codex_examples = [
250
+ "autotouch crm fields list --entity lead --custom-only",
251
+ "autotouch crm fields create --entity lead --label Priority --type select --option high=High --option low=Low",
252
+ "autotouch crm fields update --field-id <FIELD_ID> --label 'Lead priority'",
253
+ ]
254
+ crm_sub = parser.add_subparsers(dest="crm_cmd", required=True)
255
+
256
+ fields_parser = crm_sub.add_parser("fields", help="CRM lead/company field catalog")
257
+ fields_sub = fields_parser.add_subparsers(dest="crm_fields_cmd", required=True)
258
+
259
+ list_parser = fields_sub.add_parser("list", help="List standard and custom CRM fields")
260
+ list_parser.add_argument("--entity", choices=CRM_FIELD_ENTITY_TYPES, help="Filter by lead or company fields")
261
+ list_parser.add_argument("--usage", choices=CRM_FIELD_USAGES, help="Filter field catalog by usage")
262
+ list_parser.add_argument("--custom-only", action="store_true", help="Return only organization-defined custom fields")
263
+ add_api_common_arguments(list_parser)
264
+ list_parser.set_defaults(func=handlers["fields_list"])
265
+
266
+ create_parser = fields_sub.add_parser("create", help="Create a lead or company custom field definition")
267
+ _add_definition_payload_args(create_parser, create=True)
268
+ add_api_common_arguments(create_parser)
269
+ create_parser.set_defaults(func=handlers["fields_create"])
270
+
271
+ update_parser = fields_sub.add_parser("update", help="Update a CRM custom field definition")
272
+ update_parser.add_argument("--field-id", required=True, help="Custom field definition id from crm fields list")
273
+ _add_definition_payload_args(update_parser, create=False)
274
+ add_api_common_arguments(update_parser)
275
+ update_parser.set_defaults(func=handlers["fields_update"])