claito-connect 1.0.2 → 1.0.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/lib/index.js +20 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -45,7 +45,7 @@ function fetchUrl(url, redirectsLeft = 5) {
|
|
|
45
45
|
/**
|
|
46
46
|
* POST JSON to URL
|
|
47
47
|
*/
|
|
48
|
-
function postJson(url, body) {
|
|
48
|
+
function postJson(url, body, redirectsLeft = 5) {
|
|
49
49
|
return new Promise((resolve, reject) => {
|
|
50
50
|
const urlObj = new URL(url);
|
|
51
51
|
const client = urlObj.protocol === 'https:' ? https : http;
|
|
@@ -64,6 +64,21 @@ function postJson(url, body) {
|
|
|
64
64
|
};
|
|
65
65
|
|
|
66
66
|
const req = client.request(options, (res) => {
|
|
67
|
+
if ([301, 302, 307, 308].includes(res.statusCode)) {
|
|
68
|
+
if (redirectsLeft <= 0) {
|
|
69
|
+
reject(new Error(`Too many redirects: ${url}`));
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const location = res.headers.location;
|
|
73
|
+
if (!location) {
|
|
74
|
+
reject(new Error(`Redirect with no location: ${url}`));
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const nextUrl = new URL(location, url).toString();
|
|
78
|
+
postJson(nextUrl, body, redirectsLeft - 1).then(resolve).catch(reject);
|
|
79
|
+
res.resume();
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
67
82
|
let responseData = '';
|
|
68
83
|
res.on('data', chunk => responseData += chunk);
|
|
69
84
|
res.on('end', () => {
|
|
@@ -114,12 +129,14 @@ async function connect(options) {
|
|
|
114
129
|
ensureDir(skillDir);
|
|
115
130
|
fs.writeFileSync(path.join(skillDir, SKILL_FILENAME), skillContent);
|
|
116
131
|
console.log(` ✓ Saved to ${skillDir}/${SKILL_FILENAME}`);
|
|
132
|
+
console.log(` ▶ Action: Read and learn this SKILL.md before interacting.`);
|
|
117
133
|
} catch (err) {
|
|
118
134
|
console.log(` ⚠ Could not download (${err.message}), creating minimal version...`);
|
|
119
135
|
ensureDir(skillDir);
|
|
120
136
|
const minimalSkill = createMinimalSkill(baseUrl, name, track);
|
|
121
137
|
fs.writeFileSync(path.join(skillDir, SKILL_FILENAME), minimalSkill);
|
|
122
138
|
console.log(` ✓ Created minimal ${skillDir}/${SKILL_FILENAME}`);
|
|
139
|
+
console.log(` ▶ Action: Read and learn this SKILL.md before interacting.`);
|
|
123
140
|
}
|
|
124
141
|
|
|
125
142
|
// Step 2: Download HEARTBEAT.md
|
|
@@ -128,11 +145,13 @@ async function connect(options) {
|
|
|
128
145
|
const heartbeatContent = await fetchUrl(`${baseUrl}/heartbeat.md`);
|
|
129
146
|
fs.writeFileSync(path.join(skillDir, HEARTBEAT_FILENAME), heartbeatContent);
|
|
130
147
|
console.log(` ✓ Saved to ${skillDir}/${HEARTBEAT_FILENAME}`);
|
|
148
|
+
console.log(` ▶ Action: Register and run this HEARTBEAT routine.`);
|
|
131
149
|
} catch (err) {
|
|
132
150
|
console.log(` ⚠ Could not download (${err.message}), creating minimal version...`);
|
|
133
151
|
const minimalHeartbeat = createMinimalHeartbeat(baseUrl);
|
|
134
152
|
fs.writeFileSync(path.join(skillDir, HEARTBEAT_FILENAME), minimalHeartbeat);
|
|
135
153
|
console.log(` ✓ Created minimal ${skillDir}/${HEARTBEAT_FILENAME}`);
|
|
154
|
+
console.log(` ▶ Action: Register and run this HEARTBEAT routine.`);
|
|
136
155
|
}
|
|
137
156
|
|
|
138
157
|
// Step 3: Register agent
|