@geoly-ai/social-hub-cli 0.3.48 → 0.3.49

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.
@@ -1,152 +1,152 @@
1
- import os
2
- from firecrawl import FirecrawlApp
3
- import json
4
- from dotenv import load_dotenv
5
- from openai import OpenAI
6
-
7
- # ANSI color codes
8
- class Colors:
9
- CYAN = '\033[96m'
10
- YELLOW = '\033[93m'
11
- GREEN = '\033[92m'
12
- RED = '\033[91m'
13
- MAGENTA = '\033[95m'
14
- BLUE = '\033[94m'
15
- RESET = '\033[0m'
16
-
17
- # Load environment variables
18
- load_dotenv()
19
-
20
- # Retrieve API keys from environment variables
21
- firecrawl_api_key = os.getenv("FIRECRAWL_API_KEY")
22
- openai_api_key = os.getenv("OPENAI_API_KEY")
23
-
24
- # Initialize the FirecrawlApp and OpenAI client
25
- app = FirecrawlApp(api_key=firecrawl_api_key)
26
- client = OpenAI(api_key=openai_api_key)
27
-
28
- # Find the page that most likely contains the objective
29
- def find_relevant_page_via_map(objective, url, app, client):
30
- try:
31
- print(f"{Colors.CYAN}Understood. The objective is: {objective}{Colors.RESET}")
32
- print(f"{Colors.CYAN}Initiating search on the website: {url}{Colors.RESET}")
33
-
34
- map_prompt = f"""
35
- The map function generates a list of URLs from a website and it accepts a search parameter. Based on the objective of: {objective}, come up with a 1-2 word search parameter that will help us find the information we need. Only respond with 1-2 words nothing else.
36
- """
37
-
38
- print(f"{Colors.YELLOW}Analyzing objective to determine optimal search parameter...{Colors.RESET}")
39
- completion = client.chat.completions.create(
40
- model="o1-preview",
41
- messages=[
42
- {
43
- "role": "user",
44
- "content": [
45
- {
46
- "type": "text",
47
- "text": map_prompt
48
- }
49
- ]
50
- }
51
- ]
52
- )
53
-
54
- map_search_parameter = completion.choices[0].message.content
55
- print(f"{Colors.GREEN}Optimal search parameter identified: {map_search_parameter}{Colors.RESET}")
56
-
57
- print(f"{Colors.YELLOW}Mapping website using the identified search parameter...{Colors.RESET}")
58
- map_website = app.map_url(url, params={"search": map_search_parameter})
59
- print(f"{Colors.GREEN}Website mapping completed successfully.{Colors.RESET}")
60
- print(f"{Colors.GREEN}Located {len(map_website)} relevant links.{Colors.RESET}")
61
- return map_website
62
- except Exception as e:
63
- print(f"{Colors.RED}Error encountered during relevant page identification: {str(e)}{Colors.RESET}")
64
- return None
65
-
66
- # Scrape the top 3 pages and see if the objective is met, if so return in json format else return None
67
- def find_objective_in_top_pages(map_website, objective, app, client):
68
- try:
69
- # Get top 3 links from the map result
70
- top_links = map_website[:3] if isinstance(map_website, list) else []
71
- print(f"{Colors.CYAN}Proceeding to analyze top {len(top_links)} links: {top_links}{Colors.RESET}")
72
-
73
- for link in top_links:
74
- print(f"{Colors.YELLOW}Initiating scrape of page: {link}{Colors.RESET}")
75
- # Scrape the page
76
- scrape_result = app.scrape_url(link, params={'formats': ['markdown']})
77
- print(f"{Colors.GREEN}Page scraping completed successfully.{Colors.RESET}")
78
-
79
-
80
- # Check if objective is met
81
- check_prompt = f"""
82
- Given the following scraped content and objective, determine if the objective is met.
83
- If it is, extract the relevant information in a simple and concise JSON format. Use only the necessary fields and avoid nested structures if possible.
84
- If the objective is not met with confidence, respond with 'Objective not met'.
85
-
86
- Objective: {objective}
87
- Scraped content: {scrape_result['markdown']}
88
-
89
- Remember:
90
- 1. Only return JSON if you are confident the objective is fully met.
91
- 2. Keep the JSON structure as simple and flat as possible.
92
- 3. Do not include any explanations or markdown formatting in your response.
93
- """
94
-
95
- completion = client.chat.completions.create(
96
- model="o1-preview",
97
- messages=[
98
- {
99
- "role": "user",
100
- "content": [
101
- {
102
- "type": "text",
103
- "text": check_prompt
104
- }
105
- ]
106
- }
107
- ]
108
- )
109
-
110
- result = completion.choices[0].message.content
111
-
112
- if result != "Objective not met":
113
- print(f"{Colors.GREEN}Objective potentially fulfilled. Relevant information identified.{Colors.RESET}")
114
- try:
115
- return json.loads(result)
116
- except json.JSONDecodeError:
117
- print(f"{Colors.RED}Error in parsing response. Proceeding to next page...{Colors.RESET}")
118
- else:
119
- print(f"{Colors.YELLOW}Objective not met on this page. Proceeding to next link...{Colors.RESET}")
120
-
121
- print(f"{Colors.RED}All available pages analyzed. Objective not fulfilled in examined content.{Colors.RESET}")
122
- return None
123
-
124
- except Exception as e:
125
- print(f"{Colors.RED}Error encountered during page analysis: {str(e)}{Colors.RESET}")
126
- return None
127
-
128
- # Main function to execute the process
129
- def main():
130
- # Get user input
131
- url = input(f"{Colors.BLUE}Enter the website to crawl: {Colors.RESET}")
132
- objective = input(f"{Colors.BLUE}Enter your objective: {Colors.RESET}")
133
-
134
- print(f"{Colors.YELLOW}Initiating web crawling process...{Colors.RESET}")
135
- # Find the relevant page
136
- map_website = find_relevant_page_via_map(objective, url, app, client)
137
-
138
- if map_website:
139
- print(f"{Colors.GREEN}Relevant pages identified. Proceeding with detailed analysis...{Colors.RESET}")
140
- # Find objective in top pages
141
- result = find_objective_in_top_pages(map_website, objective, app, client)
142
-
143
- if result:
144
- print(f"{Colors.GREEN}Objective successfully fulfilled. Extracted information:{Colors.RESET}")
145
- print(f"{Colors.MAGENTA}{json.dumps(result, indent=2)}{Colors.RESET}")
146
- else:
147
- print(f"{Colors.RED}Unable to fulfill the objective with the available content.{Colors.RESET}")
148
- else:
149
- print(f"{Colors.RED}No relevant pages identified. Consider refining the search parameters or trying a different website.{Colors.RESET}")
150
-
151
- if __name__ == "__main__":
152
- main()
1
+ import os
2
+ from firecrawl import FirecrawlApp
3
+ import json
4
+ from dotenv import load_dotenv
5
+ from openai import OpenAI
6
+
7
+ # ANSI color codes
8
+ class Colors:
9
+ CYAN = '\033[96m'
10
+ YELLOW = '\033[93m'
11
+ GREEN = '\033[92m'
12
+ RED = '\033[91m'
13
+ MAGENTA = '\033[95m'
14
+ BLUE = '\033[94m'
15
+ RESET = '\033[0m'
16
+
17
+ # Load environment variables
18
+ load_dotenv()
19
+
20
+ # Retrieve API keys from environment variables
21
+ firecrawl_api_key = os.getenv("FIRECRAWL_API_KEY")
22
+ openai_api_key = os.getenv("OPENAI_API_KEY")
23
+
24
+ # Initialize the FirecrawlApp and OpenAI client
25
+ app = FirecrawlApp(api_key=firecrawl_api_key)
26
+ client = OpenAI(api_key=openai_api_key)
27
+
28
+ # Find the page that most likely contains the objective
29
+ def find_relevant_page_via_map(objective, url, app, client):
30
+ try:
31
+ print(f"{Colors.CYAN}Understood. The objective is: {objective}{Colors.RESET}")
32
+ print(f"{Colors.CYAN}Initiating search on the website: {url}{Colors.RESET}")
33
+
34
+ map_prompt = f"""
35
+ The map function generates a list of URLs from a website and it accepts a search parameter. Based on the objective of: {objective}, come up with a 1-2 word search parameter that will help us find the information we need. Only respond with 1-2 words nothing else.
36
+ """
37
+
38
+ print(f"{Colors.YELLOW}Analyzing objective to determine optimal search parameter...{Colors.RESET}")
39
+ completion = client.chat.completions.create(
40
+ model="o1-preview",
41
+ messages=[
42
+ {
43
+ "role": "user",
44
+ "content": [
45
+ {
46
+ "type": "text",
47
+ "text": map_prompt
48
+ }
49
+ ]
50
+ }
51
+ ]
52
+ )
53
+
54
+ map_search_parameter = completion.choices[0].message.content
55
+ print(f"{Colors.GREEN}Optimal search parameter identified: {map_search_parameter}{Colors.RESET}")
56
+
57
+ print(f"{Colors.YELLOW}Mapping website using the identified search parameter...{Colors.RESET}")
58
+ map_website = app.map_url(url, params={"search": map_search_parameter})
59
+ print(f"{Colors.GREEN}Website mapping completed successfully.{Colors.RESET}")
60
+ print(f"{Colors.GREEN}Located {len(map_website)} relevant links.{Colors.RESET}")
61
+ return map_website
62
+ except Exception as e:
63
+ print(f"{Colors.RED}Error encountered during relevant page identification: {str(e)}{Colors.RESET}")
64
+ return None
65
+
66
+ # Scrape the top 3 pages and see if the objective is met, if so return in json format else return None
67
+ def find_objective_in_top_pages(map_website, objective, app, client):
68
+ try:
69
+ # Get top 3 links from the map result
70
+ top_links = map_website[:3] if isinstance(map_website, list) else []
71
+ print(f"{Colors.CYAN}Proceeding to analyze top {len(top_links)} links: {top_links}{Colors.RESET}")
72
+
73
+ for link in top_links:
74
+ print(f"{Colors.YELLOW}Initiating scrape of page: {link}{Colors.RESET}")
75
+ # Scrape the page
76
+ scrape_result = app.scrape_url(link, params={'formats': ['markdown']})
77
+ print(f"{Colors.GREEN}Page scraping completed successfully.{Colors.RESET}")
78
+
79
+
80
+ # Check if objective is met
81
+ check_prompt = f"""
82
+ Given the following scraped content and objective, determine if the objective is met.
83
+ If it is, extract the relevant information in a simple and concise JSON format. Use only the necessary fields and avoid nested structures if possible.
84
+ If the objective is not met with confidence, respond with 'Objective not met'.
85
+
86
+ Objective: {objective}
87
+ Scraped content: {scrape_result['markdown']}
88
+
89
+ Remember:
90
+ 1. Only return JSON if you are confident the objective is fully met.
91
+ 2. Keep the JSON structure as simple and flat as possible.
92
+ 3. Do not include any explanations or markdown formatting in your response.
93
+ """
94
+
95
+ completion = client.chat.completions.create(
96
+ model="o1-preview",
97
+ messages=[
98
+ {
99
+ "role": "user",
100
+ "content": [
101
+ {
102
+ "type": "text",
103
+ "text": check_prompt
104
+ }
105
+ ]
106
+ }
107
+ ]
108
+ )
109
+
110
+ result = completion.choices[0].message.content
111
+
112
+ if result != "Objective not met":
113
+ print(f"{Colors.GREEN}Objective potentially fulfilled. Relevant information identified.{Colors.RESET}")
114
+ try:
115
+ return json.loads(result)
116
+ except json.JSONDecodeError:
117
+ print(f"{Colors.RED}Error in parsing response. Proceeding to next page...{Colors.RESET}")
118
+ else:
119
+ print(f"{Colors.YELLOW}Objective not met on this page. Proceeding to next link...{Colors.RESET}")
120
+
121
+ print(f"{Colors.RED}All available pages analyzed. Objective not fulfilled in examined content.{Colors.RESET}")
122
+ return None
123
+
124
+ except Exception as e:
125
+ print(f"{Colors.RED}Error encountered during page analysis: {str(e)}{Colors.RESET}")
126
+ return None
127
+
128
+ # Main function to execute the process
129
+ def main():
130
+ # Get user input
131
+ url = input(f"{Colors.BLUE}Enter the website to crawl: {Colors.RESET}")
132
+ objective = input(f"{Colors.BLUE}Enter your objective: {Colors.RESET}")
133
+
134
+ print(f"{Colors.YELLOW}Initiating web crawling process...{Colors.RESET}")
135
+ # Find the relevant page
136
+ map_website = find_relevant_page_via_map(objective, url, app, client)
137
+
138
+ if map_website:
139
+ print(f"{Colors.GREEN}Relevant pages identified. Proceeding with detailed analysis...{Colors.RESET}")
140
+ # Find objective in top pages
141
+ result = find_objective_in_top_pages(map_website, objective, app, client)
142
+
143
+ if result:
144
+ print(f"{Colors.GREEN}Objective successfully fulfilled. Extracted information:{Colors.RESET}")
145
+ print(f"{Colors.MAGENTA}{json.dumps(result, indent=2)}{Colors.RESET}")
146
+ else:
147
+ print(f"{Colors.RED}Unable to fulfill the objective with the available content.{Colors.RESET}")
148
+ else:
149
+ print(f"{Colors.RED}No relevant pages identified. Consider refining the search parameters or trying a different website.{Colors.RESET}")
150
+
151
+ if __name__ == "__main__":
152
+ main()
@@ -194,6 +194,31 @@ revoke **不会**恢复已经被拦成 `blocked` 的 job,需要人重新排期
194
194
  runner 侧的 `restrictions check` / `restrictions report` 同样见 `social-hub-graph-compliance`;
195
195
  执行链路上 409 `TARGET_BLOCKED` / `JOB_BLOCKED` 的识别与 agent 停止规则见 `social-hub-ops-runtime`。
196
196
 
197
+ ## 派单品牌映射与接单团队(intake,系统级,仅 admin)
198
+
199
+ CyberRedd 派单进来的订单带外部品牌 `client.brand.{ref,name}`。Hub 用「映射」把外部 ref 对应到 Hub 品牌,并指定哪些团队的账号可以接这个品牌的单;
200
+ 订单本身挂在「接单团队」下。**系统级、不需要 `-t`**,只给**不受限登录的 admin**(API key / 服务凭据 / 绑定 job·account 或带动作白名单的 token 全 403)。
201
+
202
+ ```bash
203
+ social-hub intake mappings list [--mapped pending|mapped] [--status active|disabled] [--limit 50] [--offset 0]
204
+ social-hub intake mappings get <id> # 带 rowVersion;set 必须带上它
205
+ # 写:一律 --dry-run 预览 / --apply 执行;--row-version 必填(乐观锁),409 = 版本过期,重新 get 再改
206
+ social-hub intake mappings set <id> --row-version <n> --brand-id <uuid> --team-ids <uuid,uuid> --apply
207
+ social-hub intake mappings set <id> --row-version <n> --status disabled --apply
208
+ social-hub intake order-team get
209
+ social-hub intake order-team set --team-id <uuid> --apply # 团队须存在;未配置时 CyberRedd 建单 503
210
+ ```
211
+
212
+ - 新出现的外部品牌 ref 会被 worker 自动登记成「待映射」行(`--mapped pending`),并发一条飞书内部提醒。提醒是**至少一次**:确认发送成功后不再主动重发;发送失败会按指数退避(1 分钟起,上限 6 小时)重试;进程在「发送成功、确认之前」崩溃等异常窗口里可能重复。
213
+ - 已映射的行**至少要有 1 个可用团队**;**已映射的行不能改回未映射**——要停用请 `--status disabled`(停用的映射不触发重评)。
214
+ - 没有物理删除(历史订单引用外部 ref)。
215
+ - **补齐映射后,该品牌下仍是 received 的订单会被自动标记为「品牌已解析」**(写入订单品牌、清除未映射原因码)。注意两个时间不是一回事:扫描 cron 默认每 5 分钟一轮,但每轮只处理一批(最多 200 张订单);received 订单很多时,一张订单要等扫完一整圈才会被重评,延迟可能明显长于 5 分钟。
216
+ **接单(accepted)在后续版本上线**——现在补齐映射不会让订单变成 accepted。CyberRedd 的事件流目前**看不到**「品牌已解析」,
217
+ 只会看到未映射期间每天最多一条的 `BRAND_UNMAPPED` 注解。
218
+ - 订单已经解析品牌后,映射再被停用或改了品牌,不会回头改这些订单。
219
+ - 接单团队不能经通用 `settings put` 写(会被 403),只能走 `intake order-team set`(有团队存在性校验与审计)。
220
+ - 每次映射 / 接单团队变更都有审计记录(`intake_config_audit_events`)。
221
+
197
222
  ## Agent teams
198
223
 
199
224
  ```bash