@workclaw/cli 1.0.17 → 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) {
@@ -93,13 +95,38 @@ async function httpPost(url, data, config) {
93
95
  debugLog(`[HTTP POST] 请求地址: ${url}`);
94
96
  debugLog(`[HTTP POST] 请求参数: ${JSON.stringify(data)}`);
95
97
  debugLog(`[HTTP POST] 请求头: ${JSON.stringify(config?.headers || {})}`);
96
- const response = await client.post(url, data, config);
97
- debugLog(`[HTTP POST] 响应状态: ${response.status}`);
98
- debugLog(`[HTTP POST] 响应内容: ${JSON.stringify(response.data)}`);
99
- return {
100
- status: response.status,
101
- data: response.data
102
- };
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
+ }
103
130
  }
104
131
  async function login(phone, password, env) {
105
132
  const config = getConfig(env);
@@ -107,18 +134,26 @@ async function login(phone, password, env) {
107
134
  debugLog("[登录] 开始登录...");
108
135
  debugLog(`[登录] 请求地址: ${url}`);
109
136
  debugLog(`[登录] 请求参数: phone=${phone}, password=***`);
110
- const response = await httpPost(url, {
111
- phone,
112
- userPass: password
113
- });
114
- const data = response.data;
115
- debugLog(`[登录] 响应数据: ${JSON.stringify(data)}`);
116
- if (data.code === 200 && data.data?.token) {
117
- debugLog("[登录] 登录成功,获取到 token");
118
- return data.data.token;
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);
119
156
  }
120
- debugLog("[登录] 登录失败");
121
- throw new AppError$1(ERROR_CODES$1.LOGIN_FAILED, data.message || "登录失败");
122
157
  }
123
158
  async function fetchBoundConfig(token, phone, env) {
124
159
  const config = getConfig(env);
@@ -127,40 +162,48 @@ async function fetchBoundConfig(token, phone, env) {
127
162
  debugLog(`[获取绑定配置] 请求地址: ${url}`);
128
163
  debugLog(`[获取绑定配置] 请求参数: phone=${phone}, localCode=001`);
129
164
  debugLog(`[获取绑定配置] 请求头: Authorization=${token.substring(0, 20)}...`);
130
- const response = await httpPost(url, {
131
- phone,
132
- localCode: "001"
133
- }, {
134
- headers: {
135
- Authorization: token
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;
136
197
  }
137
- });
138
- const data = response.data;
139
- debugLog(`[获取绑定配置] 响应数据: ${JSON.stringify(data)}`);
140
- if (data.code === 200 && data.data) {
141
- const boundConfig = {
142
- appKey: data.data.app_key,
143
- appSecret: data.data.app_secret,
144
- userId: data.data.user_id,
145
- agentId: data.data.agent_id || data.data.agents?.[0]?.id,
146
- modelApiKey: data.data.model_api_key,
147
- modelApiBaseUrl: data.data.model_api_base_url
148
- };
149
- debugLog("[获取绑定配置] 获取绑定配置成功");
150
- debugLog(`[获取绑定配置] appKey: ${boundConfig.appKey}`);
151
- debugLog(`[获取绑定配置] appSecret: ${boundConfig.appSecret ? "***" : "undefined"}`);
152
- debugLog(`[获取绑定配置] userId: ${boundConfig.userId}`);
153
- debugLog(`[获取绑定配置] agentId: ${boundConfig.agentId}`);
154
- debugLog(`[获取绑定配置] modelApiKey: ${boundConfig.modelApiKey || "undefined"}`);
155
- debugLog(`[获取绑定配置] modelApiBaseUrl: ${boundConfig.modelApiBaseUrl || "undefined"}`);
156
- if (!boundConfig.appKey || !boundConfig.appSecret || !boundConfig.agentId) {
157
- debugLog("[获取绑定配置] 缺少必要字段");
158
- 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;
159
203
  }
160
- return boundConfig;
204
+ debugLog(`[获取绑定配置] 发生错误: ${error.message}`);
205
+ throw new AppError$1(ERROR_CODES$1.GET_BOUND_CONFIG_FAILED, error.message);
161
206
  }
162
- debugLog("[获取绑定配置] 获取绑定配置失败");
163
- throw new AppError$1(ERROR_CODES$1.GET_BOUND_CONFIG_FAILED, data.message || data.msg || "获取绑定配置失败");
164
207
  }
165
208
  var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz";
166
209
  function int2char(n) {
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env node
2
- import("./index-39c6v1yS.js").then((cli) => {
2
+ import("./index-DrOcptQl.js").then((cli) => {
3
3
  cli.default();
4
4
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@workclaw/cli",
3
3
  "type": "module",
4
- "version": "1.0.17",
4
+ "version": "1.0.18",
5
5
  "description": "WorkClaw CLI 工具 - 用于初始化和配置 WorkClaw 插件",
6
6
  "license": "MIT",
7
7
  "keywords": [