@rethinking-studio/clawcontrol 1.0.2 → 1.0.3
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/index.ts +11 -18
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -76,8 +76,8 @@ const clawcontrolOnboardingAdapter: ChannelOnboardingAdapter = {
|
|
|
76
76
|
},
|
|
77
77
|
configure: async ({ cfg, prompter }) => {
|
|
78
78
|
const account = resolveClawControlAccount(cfg);
|
|
79
|
-
const
|
|
80
|
-
|
|
79
|
+
const defaultUrl = 'http://8.140.58.48:3000';
|
|
80
|
+
const baseUrl = defaultUrl
|
|
81
81
|
const proceed = await prompter.confirm({
|
|
82
82
|
message: '是否现在生成配对码?',
|
|
83
83
|
initialValue: true,
|
|
@@ -88,39 +88,30 @@ const clawcontrolOnboardingAdapter: ChannelOnboardingAdapter = {
|
|
|
88
88
|
|
|
89
89
|
await prompter.note('Creating pairing token...');
|
|
90
90
|
|
|
91
|
+
// 使用 GET + 浏览器 User-Agent(部分 WAF/Nginx 会拦截 curl/Node 请求)
|
|
91
92
|
let createRes: Response;
|
|
92
93
|
try {
|
|
93
94
|
createRes = await fetch(`${baseUrl}/plugin/create-pairing-token`, {
|
|
94
|
-
|
|
95
|
-
headers: { 'Content-Type': 'application/json' },
|
|
96
|
-
body: JSON.stringify({ backendUrl: baseUrl }),
|
|
95
|
+
headers: { 'User-Agent': 'Mozilla/5.0 (compatible; ClawControl/1.0)' },
|
|
97
96
|
});
|
|
98
97
|
} catch (e: any) {
|
|
99
98
|
const code = e?.cause?.code ?? e?.code;
|
|
100
99
|
const msg = code === 'ECONNREFUSED'
|
|
101
100
|
? `Cannot connect to ${baseUrl} - is the backend running? Default: https://clawai.rethinkingstudio.com`
|
|
102
101
|
: code === 'ENOTFOUND'
|
|
103
|
-
? `DNS lookup failed for ${baseUrl} - check network`
|
|
102
|
+
? `DNS lookup failed for ${baseUrl} - check network. Set CLAWCONTROL_BACKEND_URL if using different backend`
|
|
104
103
|
: e?.message || String(e);
|
|
105
104
|
throw new Error(`Fetch failed: ${msg}`);
|
|
106
105
|
}
|
|
107
106
|
|
|
108
107
|
if (!createRes.ok) {
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
try {
|
|
112
|
-
const parsed = JSON.parse(errText);
|
|
113
|
-
if (parsed.details) errMsg = `${parsed.error}: ${parsed.details}`;
|
|
114
|
-
else if (parsed.error) errMsg = parsed.error;
|
|
115
|
-
} catch {
|
|
116
|
-
/* use raw text */
|
|
117
|
-
}
|
|
118
|
-
throw new Error(`Failed to create pairing token: ${errMsg}`);
|
|
108
|
+
const err = await createRes.text();
|
|
109
|
+
throw new Error(`Failed to create pairing token: ${err}`);
|
|
119
110
|
}
|
|
120
111
|
|
|
121
112
|
const { pairingToken, expiresIn } = (await createRes.json()) as { pairingToken: string; expiresIn: number };
|
|
122
113
|
|
|
123
|
-
const qrContent = JSON.stringify({
|
|
114
|
+
const qrContent = JSON.stringify({ pairingToken });
|
|
124
115
|
|
|
125
116
|
await prompter.note(
|
|
126
117
|
`Scan the QR code below with ClawControl iOS App (expires in ${expiresIn}s):`
|
|
@@ -138,7 +129,9 @@ const clawcontrolOnboardingAdapter: ChannelOnboardingAdapter = {
|
|
|
138
129
|
|
|
139
130
|
while (Date.now() < deadline) {
|
|
140
131
|
await new Promise((r) => setTimeout(r, pollInterval));
|
|
141
|
-
const statusRes = await fetch(`${baseUrl}/plugin/pairing-status?pairingToken=${encodeURIComponent(pairingToken)}
|
|
132
|
+
const statusRes = await fetch(`${baseUrl}/plugin/pairing-status?pairingToken=${encodeURIComponent(pairingToken)}`, {
|
|
133
|
+
headers: { 'User-Agent': 'Mozilla/5.0 (compatible; ClawControl/1.0)' },
|
|
134
|
+
});
|
|
142
135
|
const status = (await statusRes.json()) as { status: string; claimed?: boolean; apiToken?: string };
|
|
143
136
|
if (status.claimed && status.apiToken) {
|
|
144
137
|
apiToken = status.apiToken;
|