@workclaw/cli 1.0.16 → 1.0.18
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.
|
@@ -29,8 +29,10 @@ const ERROR_CODES$1 = {
|
|
|
29
29
|
LOGIN_FAILED: "LOGIN_FAILED",
|
|
30
30
|
GET_BOUND_CONFIG_FAILED: "GET_BOUND_CONFIG_FAILED",
|
|
31
31
|
NODE_VERSION_LOW: "NODE_VERSION_LOW",
|
|
32
|
+
NODE_NOT_FOUND: "NODE_NOT_FOUND",
|
|
32
33
|
NPM_NOT_FOUND: "NPM_NOT_FOUND",
|
|
33
|
-
NPM_INSTALL_FAILED: "NPM_INSTALL_FAILED"
|
|
34
|
+
NPM_INSTALL_FAILED: "NPM_INSTALL_FAILED",
|
|
35
|
+
CONFIG_WRITE_FAILED: "CONFIG_WRITE_FAILED"
|
|
34
36
|
};
|
|
35
37
|
let AppError$1 = class AppError extends Error {
|
|
36
38
|
constructor(code, message) {
|
|
@@ -90,52 +92,118 @@ function createHttpClient() {
|
|
|
90
92
|
}
|
|
91
93
|
async function httpPost(url, data, config) {
|
|
92
94
|
const client = createHttpClient();
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
debugLog(`[HTTP POST] 请求地址: ${url}`);
|
|
96
|
+
debugLog(`[HTTP POST] 请求参数: ${JSON.stringify(data)}`);
|
|
97
|
+
debugLog(`[HTTP POST] 请求头: ${JSON.stringify(config?.headers || {})}`);
|
|
98
|
+
try {
|
|
99
|
+
const response = await client.post(url, data, config);
|
|
100
|
+
debugLog(`[HTTP POST] 响应状态: ${response.status}`);
|
|
101
|
+
debugLog(`[HTTP POST] 响应内容: ${JSON.stringify(response.data)}`);
|
|
102
|
+
return {
|
|
103
|
+
status: response.status,
|
|
104
|
+
data: response.data
|
|
105
|
+
};
|
|
106
|
+
} catch (error) {
|
|
107
|
+
const axiosError = error;
|
|
108
|
+
if (axiosError.response) {
|
|
109
|
+
const responseData = axiosError.response.data;
|
|
110
|
+
debugLog(`[HTTP POST] 响应状态: ${axiosError.response.status}`);
|
|
111
|
+
debugLog(`[HTTP POST] 响应状态文本: ${axiosError.response.statusText}`);
|
|
112
|
+
debugLog(`[HTTP POST] 响应数据: ${JSON.stringify(responseData)}`);
|
|
113
|
+
if (typeof responseData === "string") {
|
|
114
|
+
throw new Error(`请求失败 (${axiosError.response.status}): ${responseData}`);
|
|
115
|
+
} else if (responseData && typeof responseData === "object" && "message" in responseData) {
|
|
116
|
+
throw new Error(`请求失败 (${axiosError.response.status}): ${responseData.message}`);
|
|
117
|
+
} else {
|
|
118
|
+
throw new Error(`请求失败 (${axiosError.response.status}): ${axiosError.response.statusText}`);
|
|
119
|
+
}
|
|
120
|
+
} else if (axiosError.request) {
|
|
121
|
+
debugLog(`[HTTP POST] 未收到响应`);
|
|
122
|
+
debugLog(`[HTTP POST] 错误信息: ${axiosError.message}`);
|
|
123
|
+
throw new Error(`网络错误: ${axiosError.message}`);
|
|
124
|
+
} else {
|
|
125
|
+
debugLog(`[HTTP POST] 请求配置错误`);
|
|
126
|
+
debugLog(`[HTTP POST] 错误信息: ${axiosError.message}`);
|
|
127
|
+
throw new Error(`请求配置错误: ${axiosError.message}`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
98
130
|
}
|
|
99
131
|
async function login(phone, password, env) {
|
|
100
132
|
const config = getConfig(env);
|
|
101
133
|
const url = `${config.API.TUZAI_BASE_URL}/user/login/pass`;
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
134
|
+
debugLog("[登录] 开始登录...");
|
|
135
|
+
debugLog(`[登录] 请求地址: ${url}`);
|
|
136
|
+
debugLog(`[登录] 请求参数: phone=${phone}, password=***`);
|
|
137
|
+
try {
|
|
138
|
+
const response = await httpPost(url, {
|
|
139
|
+
phone,
|
|
140
|
+
userPass: password
|
|
141
|
+
});
|
|
142
|
+
const data = response.data;
|
|
143
|
+
debugLog(`[登录] 响应数据: ${JSON.stringify(data)}`);
|
|
144
|
+
if (data.code === 200 && data.data?.token) {
|
|
145
|
+
debugLog("[登录] 登录成功,获取到 token");
|
|
146
|
+
return data.data.token;
|
|
147
|
+
}
|
|
148
|
+
debugLog("[登录] 登录失败");
|
|
149
|
+
throw new AppError$1(ERROR_CODES$1.LOGIN_FAILED, data.message || "登录失败");
|
|
150
|
+
} catch (error) {
|
|
151
|
+
if (error instanceof AppError$1) {
|
|
152
|
+
throw error;
|
|
153
|
+
}
|
|
154
|
+
debugLog(`[登录] 发生错误: ${error.message}`);
|
|
155
|
+
throw new AppError$1(ERROR_CODES$1.LOGIN_FAILED, error.message);
|
|
109
156
|
}
|
|
110
|
-
throw new AppError$1(ERROR_CODES$1.LOGIN_FAILED, data.message || "登录失败");
|
|
111
157
|
}
|
|
112
158
|
async function fetchBoundConfig(token, phone, env) {
|
|
113
159
|
const config = getConfig(env);
|
|
114
160
|
const url = `${config.API.TUZAI_BASE_URL}/work-bot/local/bound/init`;
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
161
|
+
debugLog("[获取绑定配置] 开始获取绑定配置...");
|
|
162
|
+
debugLog(`[获取绑定配置] 请求地址: ${url}`);
|
|
163
|
+
debugLog(`[获取绑定配置] 请求参数: phone=${phone}, localCode=001`);
|
|
164
|
+
debugLog(`[获取绑定配置] 请求头: Authorization=${token.substring(0, 20)}...`);
|
|
165
|
+
try {
|
|
166
|
+
const response = await httpPost(url, {
|
|
167
|
+
phone,
|
|
168
|
+
localCode: "001"
|
|
169
|
+
}, {
|
|
170
|
+
headers: {
|
|
171
|
+
Authorization: token
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
const data = response.data;
|
|
175
|
+
debugLog(`[获取绑定配置] 响应数据: ${JSON.stringify(data)}`);
|
|
176
|
+
if (data.code === 200 && data.data) {
|
|
177
|
+
const boundConfig = {
|
|
178
|
+
appKey: data.data.app_key,
|
|
179
|
+
appSecret: data.data.app_secret,
|
|
180
|
+
userId: data.data.user_id,
|
|
181
|
+
agentId: data.data.agent_id || data.data.agents?.[0]?.id,
|
|
182
|
+
modelApiKey: data.data.model_api_key,
|
|
183
|
+
modelApiBaseUrl: data.data.model_api_base_url
|
|
184
|
+
};
|
|
185
|
+
debugLog("[获取绑定配置] 获取绑定配置成功");
|
|
186
|
+
debugLog(`[获取绑定配置] appKey: ${boundConfig.appKey}`);
|
|
187
|
+
debugLog(`[获取绑定配置] appSecret: ${boundConfig.appSecret ? "***" : "undefined"}`);
|
|
188
|
+
debugLog(`[获取绑定配置] userId: ${boundConfig.userId}`);
|
|
189
|
+
debugLog(`[获取绑定配置] agentId: ${boundConfig.agentId}`);
|
|
190
|
+
debugLog(`[获取绑定配置] modelApiKey: ${boundConfig.modelApiKey || "undefined"}`);
|
|
191
|
+
debugLog(`[获取绑定配置] modelApiBaseUrl: ${boundConfig.modelApiBaseUrl || "undefined"}`);
|
|
192
|
+
if (!boundConfig.appKey || !boundConfig.appSecret || !boundConfig.agentId) {
|
|
193
|
+
debugLog("[获取绑定配置] 缺少必要字段");
|
|
194
|
+
throw new AppError$1(ERROR_CODES$1.GET_BOUND_CONFIG_FAILED, "获取绑定配置失败:缺少必要字段");
|
|
195
|
+
}
|
|
196
|
+
return boundConfig;
|
|
121
197
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
appSecret: data.data.app_secret,
|
|
128
|
-
userId: data.data.user_id,
|
|
129
|
-
agentId: data.data.agent_id || data.data.agents?.[0]?.id,
|
|
130
|
-
modelApiKey: data.data.model_api_key,
|
|
131
|
-
modelApiBaseUrl: data.data.model_api_base_url
|
|
132
|
-
};
|
|
133
|
-
if (!boundConfig.appKey || !boundConfig.appSecret || !boundConfig.agentId) {
|
|
134
|
-
throw new AppError$1(ERROR_CODES$1.GET_BOUND_CONFIG_FAILED, "获取绑定配置失败:缺少必要字段");
|
|
198
|
+
debugLog("[获取绑定配置] 获取绑定配置失败");
|
|
199
|
+
throw new AppError$1(ERROR_CODES$1.GET_BOUND_CONFIG_FAILED, data.message || data.msg || "获取绑定配置失败");
|
|
200
|
+
} catch (error) {
|
|
201
|
+
if (error instanceof AppError$1) {
|
|
202
|
+
throw error;
|
|
135
203
|
}
|
|
136
|
-
|
|
204
|
+
debugLog(`[获取绑定配置] 发生错误: ${error.message}`);
|
|
205
|
+
throw new AppError$1(ERROR_CODES$1.GET_BOUND_CONFIG_FAILED, error.message);
|
|
137
206
|
}
|
|
138
|
-
throw new AppError$1(ERROR_CODES$1.GET_BOUND_CONFIG_FAILED, data.message || data.msg || "获取绑定配置失败");
|
|
139
207
|
}
|
|
140
208
|
var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz";
|
|
141
209
|
function int2char(n) {
|
package/dist/index.js
CHANGED