@comate/zulu 1.4.0-beta.3 → 1.4.0-beta.4
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.
- package/comate-engine/assets/skills/create-image/SKILL.md +14 -9
- package/comate-engine/assets/skills/create-skill/SKILL.md +1 -2
- package/comate-engine/assets/skills/get-ugate-token/SKILL.md +97 -13
- package/comate-engine/assets/skills/get-ugate-token/getUgateToken.py +99 -5
- package/comate-engine/fallbackServer.js +1 -1
- package/comate-engine/node_modules/@baidu/comate-browser-use/dist/launch-chrome/index.js +1 -1
- package/comate-engine/node_modules/@baidu/comate-browser-use/package.json +5 -5
- package/comate-engine/package.json +1 -1
- package/comate-engine/server.js +38 -32
- package/dist/bundle/index.js +3 -3
- package/package.json +1 -1
|
@@ -41,6 +41,8 @@ Generate new images or edit existing ones using Google's Nano Banana Pro API (Ge
|
|
|
41
41
|
**macOS / Linux (bash/zsh):**
|
|
42
42
|
|
|
43
43
|
```bash
|
|
44
|
+
mkdir -p .comate/images
|
|
45
|
+
|
|
44
46
|
curl -s -X POST https://comate.baidu-int.com/api/aidevops/autocomate/rest/autowork/v1/generate-image \
|
|
45
47
|
-H "Content-Type: application/json" \
|
|
46
48
|
-H "login-name: ${COMATE_USERNAME_ENCRYPTED}" \
|
|
@@ -49,7 +51,7 @@ curl -s -X POST https://comate.baidu-int.com/api/aidevops/autocomate/rest/autowo
|
|
|
49
51
|
"resolution": "1K"
|
|
50
52
|
}' \
|
|
51
53
|
| jq -r '.candidates[0].content.parts[] | select(.inlineData) | .inlineData.data' \
|
|
52
|
-
| base64 --decode > output-name.png
|
|
54
|
+
| base64 --decode > .comate/images/output-name.png
|
|
53
55
|
```
|
|
54
56
|
|
|
55
57
|
**Windows (PowerShell):**
|
|
@@ -70,8 +72,9 @@ $imgBase64 = $response.candidates[0].content.parts |
|
|
|
70
72
|
Where-Object { $_.inlineData } |
|
|
71
73
|
Select-Object -First 1 -ExpandProperty inlineData |
|
|
72
74
|
Select-Object -ExpandProperty data
|
|
75
|
+
New-Item -ItemType Directory -Force -Path ".comate/images" | Out-Null
|
|
73
76
|
[System.IO.File]::WriteAllBytes(
|
|
74
|
-
(Join-Path (Get-Location) "output-name.png"),
|
|
77
|
+
(Join-Path (Get-Location) ".comate\images\output-name.png"),
|
|
75
78
|
[System.Convert]::FromBase64String($imgBase64)
|
|
76
79
|
)
|
|
77
80
|
```
|
|
@@ -103,12 +106,13 @@ cat > /tmp/request.json << EOF
|
|
|
103
106
|
EOF
|
|
104
107
|
|
|
105
108
|
# Step 3: send request
|
|
109
|
+
mkdir -p .comate/images
|
|
106
110
|
curl -s -X POST https://comate.baidu-int.com/api/aidevops/autocomate/rest/autowork/v1/generate-image \
|
|
107
111
|
-H "Content-Type: application/json" \
|
|
108
112
|
-H "login-name: ${COMATE_USERNAME_ENCRYPTED}" \
|
|
109
113
|
-d @/tmp/request.json \
|
|
110
114
|
| jq -r '.candidates[0].content.parts[] | select(.inlineData) | .inlineData.data' \
|
|
111
|
-
| base64 --decode > output-name.png
|
|
115
|
+
| base64 --decode > .comate/images/output-name.png
|
|
112
116
|
```
|
|
113
117
|
|
|
114
118
|
**Windows (PowerShell):**
|
|
@@ -146,8 +150,9 @@ $outBase64 = $response.candidates[0].content.parts |
|
|
|
146
150
|
Select-Object -First 1 -ExpandProperty inlineData |
|
|
147
151
|
Select-Object -ExpandProperty data
|
|
148
152
|
|
|
153
|
+
New-Item -ItemType Directory -Force -Path ".comate\images" | Out-Null
|
|
149
154
|
[System.IO.File]::WriteAllBytes(
|
|
150
|
-
(Join-Path (Get-Location) "output-name.png"),
|
|
155
|
+
(Join-Path (Get-Location) ".comate\images\output-name.png"),
|
|
151
156
|
[System.Convert]::FromBase64String($outBase64)
|
|
152
157
|
)
|
|
153
158
|
```
|
|
@@ -222,11 +227,11 @@ $resolution = if ($maxDim -ge 3000) { "4K" }
|
|
|
222
227
|
## Output
|
|
223
228
|
|
|
224
229
|
- Saves PNG to `.comate/images` directory, if directory is not exist, you need to create it.
|
|
225
|
-
- Script outputs the
|
|
226
|
-
- **Do not read the image back** - display the image using markdown syntax: ``
|
|
232
|
+
- **Display the image path only once** using a relative path (e.g. `.comate/images/output-name.png`)
|
|
233
|
+
- Relative paths are REQUIRED (e.g. paths starting with `./` or directly with the directory name);
|
|
234
|
+
- do NOT use absolute paths (e.g. paths starting with `/` on Unix or `C:\` on Windows are forbidden);
|
|
230
235
|
- do NOT repeat the path multiple times in the conversation
|
|
231
236
|
|
|
232
237
|
---
|
|
@@ -79,7 +79,6 @@ Based on the user interview, fill in these components:
|
|
|
79
79
|
|
|
80
80
|
- **name**: Skill identifier
|
|
81
81
|
- **description**: When to trigger, what it does. This is the primary triggering mechanism - include both what the skill does AND specific contexts for when to use it. All "when to use" info goes here, not in the body. Note: currently Comate has a tendency to "undertrigger" skills -- to not use them when they'd be useful. To combat this, please make the skill descriptions a little bit "pushy". So for instance, instead of "How to build a simple fast dashboard to display internal Anthropic data.", you might write "How to build a simple fast dashboard to display internal Anthropic data. Make sure to use this skill whenever the user mentions dashboards, data visualization, internal metrics, or wants to display any kind of company data, even if they don't explicitly ask for a 'dashboard.'"
|
|
82
|
-
- **compatibility**: Required tools, dependencies (optional, rarely needed)
|
|
83
82
|
- **the rest of the skill :)**
|
|
84
83
|
|
|
85
84
|
### Skill Writing Guide
|
|
@@ -446,4 +445,4 @@ Repeating one more time the core loop here for emphasis:
|
|
|
446
445
|
- Repeat until you and the user are satisfied
|
|
447
446
|
- Package the final skill and return it to the user.
|
|
448
447
|
|
|
449
|
-
Please add steps to your TodoList, if you have such a thing, to make sure you don't forget.
|
|
448
|
+
Please add steps to your TodoList, if you have such a thing, to make sure you don't forget.
|
|
@@ -15,21 +15,23 @@ metadata:
|
|
|
15
15
|
**核心特性:**
|
|
16
16
|
- 所有 token 都是永久有效的
|
|
17
17
|
- 支持用户手动输入 token
|
|
18
|
+
- **仅沙盒环境支持 ugate/邮箱授权开关管理,Mac 和 Windows 环境不支持**
|
|
18
19
|
- 用户名: ${COMATE_USERNAME}
|
|
19
|
-
-
|
|
20
|
-
|
|
20
|
+
- skill 所在的路径是:${COMATE_SKILL_DIR},
|
|
21
21
|
|
|
22
22
|
## 文件结构
|
|
23
23
|
|
|
24
24
|
```
|
|
25
|
-
|
|
25
|
+
get-ugate-token/
|
|
26
26
|
├── SKILL.md # 技能说明文档
|
|
27
27
|
└── getUgateToken.py # Python 主脚本
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
##
|
|
30
|
+
## 功能列表
|
|
31
|
+
|
|
32
|
+
### 1. Token 管理
|
|
31
33
|
|
|
32
|
-
|
|
34
|
+
#### 手动输入 Token
|
|
33
35
|
|
|
34
36
|
**当用户发送格式为 `ugate token: xxxx` 或 `ugate token:xxxx`(中文冒号)的消息时:**
|
|
35
37
|
|
|
@@ -41,17 +43,17 @@ ${COMATE_SKILL_DIR}/
|
|
|
41
43
|
|
|
42
44
|
```bash
|
|
43
45
|
# 用户发送消息:ugate token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...
|
|
44
|
-
USER_MESSAGE="ugate token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9..." python3
|
|
46
|
+
USER_MESSAGE="ugate token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9..." python3 getUgateToken.py ${COMATE_USERNAME} 2>&1
|
|
45
47
|
TOKEN_SAVED:Token 已保存
|
|
46
48
|
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...
|
|
47
49
|
```
|
|
48
50
|
|
|
49
|
-
|
|
51
|
+
#### 检查缓存的 token
|
|
50
52
|
|
|
51
53
|
- 检查文件 `~/.config/uuap/.eac_ugate_token_${COMATE_USERNAME}` 是否存在
|
|
52
54
|
- 如果文件存在,直接返回缓存的 token(永久有效)
|
|
53
55
|
|
|
54
|
-
|
|
56
|
+
#### 需要手动获取 token
|
|
55
57
|
|
|
56
58
|
如果缓存不存在:
|
|
57
59
|
|
|
@@ -63,6 +65,74 @@ eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...
|
|
|
63
65
|
- 复制页面内容
|
|
64
66
|
- 将内容发送给技能调用者
|
|
65
67
|
|
|
68
|
+
### 2. 授权开关管理
|
|
69
|
+
|
|
70
|
+
通过 `aigate-cli policy` 命令管理 ugate 和邮箱授权开关。
|
|
71
|
+
|
|
72
|
+
#### 开启 Ugate 用户授权
|
|
73
|
+
|
|
74
|
+
**触发关键词:**
|
|
75
|
+
- 开启ugate / 开启 ugate / 打开ugate / 打开 ugate
|
|
76
|
+
- 开启我的ugate / 开启我的 ugate
|
|
77
|
+
- 开启ugate授权 / 开启 ugate 授权
|
|
78
|
+
- 开启用户授权 / 打开用户授权
|
|
79
|
+
- 身份授权开启 / 开启身份授权 / 打开身份授权
|
|
80
|
+
|
|
81
|
+
**执行命令:** `aigate-cli policy -c=on -n=ugate`
|
|
82
|
+
|
|
83
|
+
**示例:**
|
|
84
|
+
```bash
|
|
85
|
+
USER_MESSAGE="开启我的ugate授权" python3 ${COMATE_SKILL_DIR}/getUgateToken.py ${COMATE_USERNAME}
|
|
86
|
+
# 输出: POLICY_RESULT:✅ Ugate 用户授权已开启
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
#### 关闭 Ugate 用户授权
|
|
90
|
+
|
|
91
|
+
**触发关键词:**
|
|
92
|
+
- 关闭ugate / 关闭 ugate / 取消ugate / 取消 ugate
|
|
93
|
+
- 关闭我的ugate / 关闭我的 ugate
|
|
94
|
+
- 关闭ugate授权 / 关闭 ugate 授权
|
|
95
|
+
- 关闭用户授权 / 取消用户授权
|
|
96
|
+
- 身份授权取消 / 取消身份授权 / 关闭身份授权
|
|
97
|
+
|
|
98
|
+
**执行命令:** `aigate-cli policy -c=off -n=ugate`
|
|
99
|
+
|
|
100
|
+
**示例:**
|
|
101
|
+
```bash
|
|
102
|
+
USER_MESSAGE="关闭ugate授权" python3 ${COMATE_SKILL_DIR}/getUgateToken.py ${COMATE_USERNAME}
|
|
103
|
+
# 输出: POLICY_RESULT:✅ Ugate 用户授权已关闭
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
#### 开启邮箱授权
|
|
107
|
+
|
|
108
|
+
**触发关键词:**
|
|
109
|
+
- 开启邮箱 / 打开邮箱 / 开启邮箱授权
|
|
110
|
+
- 开启我的邮箱 / 打开我的邮箱授权
|
|
111
|
+
- 邮箱授权开启 / 邮箱开启
|
|
112
|
+
|
|
113
|
+
**执行命令:** `aigate-cli policy -c=on -n=mail`
|
|
114
|
+
|
|
115
|
+
**示例:**
|
|
116
|
+
```bash
|
|
117
|
+
USER_MESSAGE="开启邮箱授权" python3 ${COMATE_SKILL_DIR}/getUgateToken.py ${COMATE_USERNAME}
|
|
118
|
+
# 输出: POLICY_RESULT:✅ 邮箱授权已开启
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
#### 关闭邮箱授权
|
|
122
|
+
|
|
123
|
+
**触发关键词:**
|
|
124
|
+
- 关闭邮箱 / 取消邮箱 / 关闭邮箱授权
|
|
125
|
+
- 关闭我的邮箱 / 取消我的邮箱授权
|
|
126
|
+
- 邮箱授权关闭 / 邮箱关闭
|
|
127
|
+
|
|
128
|
+
**执行命令:** `aigate-cli policy -c=off -n=mail`
|
|
129
|
+
|
|
130
|
+
**示例:**
|
|
131
|
+
```bash
|
|
132
|
+
USER_MESSAGE="关闭邮箱授权" python3 ${COMATE_SKILL_DIR}/getUgateToken.py ${COMATE_USERNAME}
|
|
133
|
+
# 输出: POLICY_RESULT:✅ 邮箱授权已关闭
|
|
134
|
+
```
|
|
135
|
+
|
|
66
136
|
## 使用方法
|
|
67
137
|
|
|
68
138
|
```bash
|
|
@@ -71,6 +141,12 @@ python3 ${COMATE_SKILL_DIR}/getUgateToken.py ${COMATE_USERNAME}
|
|
|
71
141
|
|
|
72
142
|
# 手动输入 token(通过 USER_MESSAGE 环境变量)
|
|
73
143
|
USER_MESSAGE="ugate token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9..." python3 ${COMATE_SKILL_DIR}/getUgateToken.py ${COMATE_USERNAME}
|
|
144
|
+
|
|
145
|
+
# 开启 ugate 授权
|
|
146
|
+
USER_MESSAGE="开启ugate授权" python3 ${COMATE_SKILL_DIR}/getUgateToken.py ${COMATE_USERNAME}
|
|
147
|
+
|
|
148
|
+
# 关闭邮箱授权
|
|
149
|
+
USER_MESSAGE="关闭邮箱授权" python3 ${COMATE_SKILL_DIR}/getUgateToken.py ${COMATE_USERNAME}
|
|
74
150
|
```
|
|
75
151
|
|
|
76
152
|
## 输出格式
|
|
@@ -95,10 +171,17 @@ eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...
|
|
|
95
171
|
脚本会输出到 stderr 并以退出码 2 退出:
|
|
96
172
|
|
|
97
173
|
```bash
|
|
98
|
-
$ python3 getUgateToken.py ${COMATE_USERNAME} 2>&1
|
|
174
|
+
$ python3 ${COMATE_SKILL_DIR}/getUgateToken.py ${COMATE_USERNAME} 2>&1
|
|
99
175
|
NEED_MANUAL_TOKEN:请点击 https://uuap.baidu.com/agent/token 获取token,然后复制内容发送给我
|
|
100
176
|
```
|
|
101
177
|
|
|
178
|
+
### Policy 操作场景
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
$ USER_MESSAGE="开启ugate授权" python3 ${COMATE_SKILL_DIR}/getUgateToken.py ${COMATE_USERNAME}
|
|
182
|
+
POLICY_RESULT:✅ Ugate 用户授权已开启
|
|
183
|
+
```
|
|
184
|
+
|
|
102
185
|
## 强制刷新
|
|
103
186
|
|
|
104
187
|
当用户消息中包含以下关键词时,会忽略缓存:
|
|
@@ -124,7 +207,7 @@ USER_MESSAGE="刷新ugate" python3 ${COMATE_SKILL_DIR}/getUgateToken.py ${COMATE
|
|
|
124
207
|
|
|
125
208
|
## 环境变量依赖
|
|
126
209
|
|
|
127
|
-
- `USER_MESSAGE` -
|
|
210
|
+
- `USER_MESSAGE` - 用户原始消息(可选,用于判断操作意图)
|
|
128
211
|
|
|
129
212
|
## 缓存机制
|
|
130
213
|
|
|
@@ -149,8 +232,8 @@ USER_MESSAGE="刷新ugate" python3 ${COMATE_SKILL_DIR}/getUgateToken.py ${COMATE
|
|
|
149
232
|
|
|
150
233
|
## 退出码说明
|
|
151
234
|
|
|
152
|
-
- **0**:
|
|
153
|
-
- **1**:
|
|
235
|
+
- **0**: 成功(token 返回或 policy 操作成功)
|
|
236
|
+
- **1**: 错误(参数缺失、policy 操作失败等)
|
|
154
237
|
- **2**: 需要手动获取 token(缓存无效,请提示用户访问 https://uuap.baidu.com/agent/token)
|
|
155
238
|
|
|
156
239
|
## 注意事项
|
|
@@ -158,4 +241,5 @@ USER_MESSAGE="刷新ugate" python3 ${COMATE_SKILL_DIR}/getUgateToken.py ${COMATE
|
|
|
158
241
|
- token 会缓存到本地文件中,避免重复获取
|
|
159
242
|
- 每个用户有独立的缓存文件,互不干扰
|
|
160
243
|
- 所有 token 都是永久有效的
|
|
161
|
-
- **手动输入 token 格式:** `ugate token: <token内容>` 或 `ugate token:<token内容>`(中文冒号)
|
|
244
|
+
- **手动输入 token 格式:** `ugate token: <token内容>` 或 `ugate token:<token内容>`(中文冒号)
|
|
245
|
+
- **Policy 操作依赖:** 需要系统已安装 `aigate-cli` 命令行工具,按说说明请参考:https://ku.baidu-int.com/knowledge/HFVrC7hq1Q/HXFtYvbMQj/TNoZ2M6o-t/dDqIxL3md2Nm0X
|
|
@@ -2,13 +2,16 @@
|
|
|
2
2
|
# -*- coding: utf-8 -*-
|
|
3
3
|
"""
|
|
4
4
|
获取并缓存 ugate token(多用户版本,永久有效)
|
|
5
|
+
支持管理 ugate/邮箱授权开关
|
|
5
6
|
"""
|
|
6
7
|
|
|
7
8
|
import os
|
|
8
9
|
import sys
|
|
9
10
|
import json
|
|
10
11
|
import re
|
|
12
|
+
import subprocess
|
|
11
13
|
from pathlib import Path
|
|
14
|
+
from shutil import which
|
|
12
15
|
|
|
13
16
|
# 配置常量
|
|
14
17
|
CACHE_DIR = Path.home() / ".config" / "uuap"
|
|
@@ -29,6 +32,36 @@ FORCE_REFRESH_KEYWORDS = [
|
|
|
29
32
|
"忽略缓存",
|
|
30
33
|
]
|
|
31
34
|
|
|
35
|
+
# Policy 操作关键词
|
|
36
|
+
POLICY_KEYWORDS = {
|
|
37
|
+
"ugate_on": [
|
|
38
|
+
"开启ugate", "开启 ugate", "打开ugate", "打开 ugate",
|
|
39
|
+
"开启我的ugate", "开启我的 ugate", "打开我的ugate", "打开我的 ugate",
|
|
40
|
+
"开启ugate授权", "开启 ugate 授权", "打开ugate授权", "打开 ugate 授权",
|
|
41
|
+
"开启我的ugate授权", "开启我的 ugate 授权", "ugate授权开启", "ugate 授权开启",
|
|
42
|
+
"开启用户授权", "打开用户授权",
|
|
43
|
+
"身份授权开启", "开启身份授权", "打开身份授权",
|
|
44
|
+
],
|
|
45
|
+
"ugate_off": [
|
|
46
|
+
"关闭ugate", "关闭 ugate", "取消ugate", "取消 ugate",
|
|
47
|
+
"关闭我的ugate", "关闭我的 ugate", "取消我的ugate", "取消我的 ugate",
|
|
48
|
+
"关闭ugate授权", "关闭 ugate 授权", "取消ugate授权", "取消 ugate 授权",
|
|
49
|
+
"关闭我的ugate授权", "关闭我的 ugate 授权", "ugate授权关闭", "ugate 授权关闭",
|
|
50
|
+
"关闭用户授权", "取消用户授权",
|
|
51
|
+
"身份授权取消", "取消身份授权", "关闭身份授权",
|
|
52
|
+
],
|
|
53
|
+
"mail_on": [
|
|
54
|
+
"开启邮箱", "打开邮箱", "开启邮箱授权", "打开邮箱授权",
|
|
55
|
+
"开启我的邮箱", "打开我的邮箱", "开启我的邮箱授权", "打开我的邮箱授权",
|
|
56
|
+
"邮箱授权开启", "邮箱开启",
|
|
57
|
+
],
|
|
58
|
+
"mail_off": [
|
|
59
|
+
"关闭邮箱", "取消邮箱", "关闭邮箱授权", "取消邮箱授权",
|
|
60
|
+
"关闭我的邮箱", "取消我的邮箱", "关闭我的邮箱授权", "取消我的邮箱授权",
|
|
61
|
+
"邮箱授权关闭", "邮箱关闭",
|
|
62
|
+
],
|
|
63
|
+
}
|
|
64
|
+
|
|
32
65
|
|
|
33
66
|
def get_cache_file(username):
|
|
34
67
|
"""根据用户名获取对应的缓存文件路径"""
|
|
@@ -44,6 +77,59 @@ def should_force_refresh(user_message):
|
|
|
44
77
|
return any(keyword in user_message_lower for keyword in FORCE_REFRESH_KEYWORDS)
|
|
45
78
|
|
|
46
79
|
|
|
80
|
+
def detect_policy_action(user_message):
|
|
81
|
+
"""
|
|
82
|
+
检测用户消息是否包含 policy 操作意图
|
|
83
|
+
|
|
84
|
+
Returns:
|
|
85
|
+
tuple: (action, name) 例如 ('on', 'ugate') 或 ('off', 'mail'),如果无匹配则返回 None
|
|
86
|
+
"""
|
|
87
|
+
if not user_message:
|
|
88
|
+
return None
|
|
89
|
+
|
|
90
|
+
for action_type, keywords in POLICY_KEYWORDS.items():
|
|
91
|
+
for keyword in keywords:
|
|
92
|
+
if keyword in user_message:
|
|
93
|
+
parts = action_type.split('_')
|
|
94
|
+
return (parts[1], parts[0]) # ('on', 'ugate') 或 ('off', 'mail')
|
|
95
|
+
|
|
96
|
+
return None
|
|
97
|
+
|
|
98
|
+
def execute_policy(command, name):
|
|
99
|
+
"""
|
|
100
|
+
执行 aigate-cli policy 命令
|
|
101
|
+
|
|
102
|
+
Args:
|
|
103
|
+
command: 'on' 或 'off'
|
|
104
|
+
name: 'ugate' 或 'mail'
|
|
105
|
+
|
|
106
|
+
Returns:
|
|
107
|
+
tuple: (success, message)
|
|
108
|
+
"""
|
|
109
|
+
try:
|
|
110
|
+
result = subprocess.run(
|
|
111
|
+
['aigate-cli', 'policy', '-c=' + command, '-n=' + name],
|
|
112
|
+
capture_output=True,
|
|
113
|
+
text=True,
|
|
114
|
+
timeout=30
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
if result.returncode == 0:
|
|
118
|
+
action_text = "开启" if command == "on" else "关闭"
|
|
119
|
+
name_text = "Ugate 用户授权" if name == "ugate" else "邮箱授权"
|
|
120
|
+
return (True, f"✅ {name_text}已{action_text}")
|
|
121
|
+
else:
|
|
122
|
+
error_msg = result.stderr.strip() if result.stderr else "未知错误"
|
|
123
|
+
return (False, f"❌ 操作失败: {error_msg}")
|
|
124
|
+
|
|
125
|
+
except FileNotFoundError:
|
|
126
|
+
return (False, "❌ aigate-cli 命令未找到,请确认已安装")
|
|
127
|
+
except subprocess.TimeoutExpired:
|
|
128
|
+
return (False, "❌ 操作超时")
|
|
129
|
+
except Exception as e:
|
|
130
|
+
return (False, f"❌ 执行出错: {str(e)}")
|
|
131
|
+
|
|
132
|
+
|
|
47
133
|
def extract_manual_token(user_message):
|
|
48
134
|
"""
|
|
49
135
|
从用户消息中提取手动输入的 token
|
|
@@ -119,10 +205,18 @@ def main():
|
|
|
119
205
|
|
|
120
206
|
username = sys.argv[1]
|
|
121
207
|
|
|
122
|
-
#
|
|
208
|
+
# 获取用户消息(用于判断操作意图)
|
|
123
209
|
user_message = os.environ.get('USER_MESSAGE', '')
|
|
124
210
|
|
|
125
|
-
# 1.
|
|
211
|
+
# 1. 检测是否为 policy 操作
|
|
212
|
+
policy_action = detect_policy_action(user_message)
|
|
213
|
+
if policy_action:
|
|
214
|
+
command, name = policy_action
|
|
215
|
+
success, message = execute_policy(command, name)
|
|
216
|
+
print(f"POLICY_RESULT:{message}")
|
|
217
|
+
sys.exit(0 if success else 1)
|
|
218
|
+
|
|
219
|
+
# 2. 检查用户是否手动输入了 token(格式:ugate token: xxxx)
|
|
126
220
|
manual_token = extract_manual_token(user_message)
|
|
127
221
|
if manual_token:
|
|
128
222
|
# 保存到缓存(永久有效)
|
|
@@ -131,17 +225,17 @@ def main():
|
|
|
131
225
|
print(manual_token)
|
|
132
226
|
return
|
|
133
227
|
|
|
134
|
-
#
|
|
228
|
+
# 3. 检查是否需要强制刷新
|
|
135
229
|
force_refresh = should_force_refresh(user_message)
|
|
136
230
|
|
|
137
|
-
#
|
|
231
|
+
# 4. 尝试从缓存获取(除非强制刷新)
|
|
138
232
|
if not force_refresh:
|
|
139
233
|
cached_token = get_cached_token(username)
|
|
140
234
|
if cached_token:
|
|
141
235
|
print(cached_token)
|
|
142
236
|
return
|
|
143
237
|
|
|
144
|
-
#
|
|
238
|
+
# 5. 缓存不存在或强制刷新,提示用户手动获取 token
|
|
145
239
|
print(f"NEED_MANUAL_TOKEN:请点击 https://uuap.baidu.com/agent/token 获取token,然后复制内容发送给我", file=sys.stderr)
|
|
146
240
|
sys.exit(2)
|
|
147
241
|
|