@agent8/deploy 1.2.0 → 1.3.1

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.
Files changed (2) hide show
  1. package/bin/agent8.js +98 -19
  2. package/package.json +1 -1
package/bin/agent8.js CHANGED
@@ -14,6 +14,7 @@ const prodMode = args.includes("--prod");
14
14
 
15
15
  const envFilePath = path.resolve(process.cwd(), ".env");
16
16
  const deployedFilePath = path.resolve(process.cwd(), ".deployed");
17
+ const crossrampFilePath = path.resolve(process.cwd(), ".crossramp");
17
18
 
18
19
  if (!fs.existsSync(envFilePath)) {
19
20
  fs.writeFileSync(envFilePath, "");
@@ -85,6 +86,64 @@ if (previewMode) {
85
86
  console.log("Default mode: Deploying to verse:", targetVerse);
86
87
  }
87
88
 
89
+ // Prepare authentication headers based on mode
90
+ function getAuthHeaders(formHeaders = {}) {
91
+ if (previewMode || prodMode) {
92
+ return {
93
+ ...formHeaders,
94
+ Authorization: `Bearer ${accessToken}`,
95
+ };
96
+ } else {
97
+ return {
98
+ ...formHeaders,
99
+ };
100
+ }
101
+ }
102
+
103
+ // CrossRamp setup API call
104
+ async function setupCrossRamp(verse, config) {
105
+ try {
106
+ const response = await axios.post(
107
+ `${endpoint}/verses/${verse}/crossramp/setup`,
108
+ {
109
+ uuid: config.uuid,
110
+ project_id: config.project_id,
111
+ },
112
+ { headers: getAuthHeaders() }
113
+ );
114
+
115
+ console.log("CrossRamp setup successful:", response.data.config);
116
+ return true;
117
+ } catch (error) {
118
+ console.error(
119
+ "CrossRamp setup failed:",
120
+ error.response?.data?.message || error.message
121
+ );
122
+ return false;
123
+ }
124
+ }
125
+
126
+ // Load CrossRamp configuration if exists
127
+ let crossrampConfig = null;
128
+ if (fs.existsSync(crossrampFilePath)) {
129
+ try {
130
+ const content = fs.readFileSync(crossrampFilePath, "utf8");
131
+ crossrampConfig = JSON.parse(content);
132
+
133
+ if (!crossrampConfig.uuid || !crossrampConfig.project_id) {
134
+ console.error(
135
+ "Error: .crossramp file must contain 'uuid' and 'project_id'"
136
+ );
137
+ process.exit(1);
138
+ }
139
+
140
+ console.log("CrossRamp configuration detected");
141
+ } catch (error) {
142
+ console.error("Error parsing .crossramp file:", error.message);
143
+ process.exit(1);
144
+ }
145
+ }
146
+
88
147
  // Files to upload
89
148
  const filesToUpload = [];
90
149
  const newHashes = {};
@@ -95,8 +154,17 @@ const calculateFileHash = (filePath) => {
95
154
  return crypto.createHash("md5").update(fileContent).digest("hex");
96
155
  };
97
156
 
98
- // Check for server.js
99
- const serverFilePath = path.resolve(process.cwd(), "server.js");
157
+ // Check for server.js (priority: ./server.js, fallback: ./server/dist/server.js)
158
+ let serverFilePath = path.resolve(process.cwd(), "server.js");
159
+ if (!fs.existsSync(serverFilePath)) {
160
+ // Fallback to ./server/dist/server.js if ./server.js doesn't exist
161
+ const fallbackPath = path.resolve(process.cwd(), "server/dist/server.js");
162
+ if (fs.existsSync(fallbackPath)) {
163
+ serverFilePath = fallbackPath;
164
+ console.log("Found server file: ./server/dist/server.js");
165
+ }
166
+ }
167
+
100
168
  if (fs.existsSync(serverFilePath)) {
101
169
  // Validate server.js syntax before deployment
102
170
  try {
@@ -156,25 +224,25 @@ if (!previewMode) {
156
224
  }
157
225
 
158
226
  if (filesToUpload.length === 0) {
159
- console.log("No changes detected. Nothing to deploy.");
160
- process.exit(0);
161
- }
162
-
163
- console.log(`Found ${filesToUpload.length} files to upload...`);
227
+ if (crossrampConfig) {
228
+ console.log(
229
+ "No file changes detected. Setting up CrossRamp configuration..."
230
+ );
164
231
 
165
- // Prepare authentication headers based on mode
166
- const getAuthHeaders = (formHeaders) => {
167
- if (previewMode || prodMode) {
168
- return {
169
- ...formHeaders,
170
- Authorization: `Bearer ${accessToken}`,
171
- };
232
+ setupCrossRamp(targetVerse, crossrampConfig).then((success) => {
233
+ if (success) {
234
+ console.log("CrossRamp setup completed.");
235
+ }
236
+ process.exit(success ? 0 : 1);
237
+ });
172
238
  } else {
173
- return {
174
- ...formHeaders,
175
- };
239
+ console.log("No changes detected. Nothing to deploy.");
240
+ process.exit(0);
176
241
  }
177
- };
242
+ return;
243
+ }
244
+
245
+ console.log(`Found ${filesToUpload.length} files to upload...`);
178
246
 
179
247
  // Upload files in parallel
180
248
  const uploadPromises = filesToUpload.map((fileInfo) => {
@@ -202,12 +270,23 @@ const uploadPromises = filesToUpload.map((fileInfo) => {
202
270
  });
203
271
 
204
272
  Promise.all(uploadPromises)
205
- .then((results) => {
273
+ .then(async (results) => {
206
274
  const successCount = results.filter(Boolean).length;
207
275
  console.log(
208
276
  `Deployment complete: ${successCount}/${filesToUpload.length} files uploaded successfully.`
209
277
  );
210
278
 
279
+ // CrossRamp setup if config exists and all files uploaded successfully
280
+ if (crossrampConfig && successCount === filesToUpload.length) {
281
+ console.log("Setting up CrossRamp configuration...");
282
+ const success = await setupCrossRamp(targetVerse, crossrampConfig);
283
+ if (!success) {
284
+ console.warn(
285
+ "Warning: CrossRamp setup failed, but files were deployed"
286
+ );
287
+ }
288
+ }
289
+
211
290
  // Save new hashes to .deployed file
212
291
  fs.writeFileSync(deployedFilePath, JSON.stringify(newHashes, null, 2));
213
292
  console.log("Updated .deployed file with new file hashes");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent8/deploy",
3
- "version": "1.2.0",
3
+ "version": "1.3.1",
4
4
  "description": "A CLI tool for running agent8 commands",
5
5
  "main": "index.js",
6
6
  "bin": {