agentic-factory-bridge 1.1.0 → 1.2.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/bridge.js +146 -2
  2. package/package.json +1 -1
package/bridge.js CHANGED
@@ -57,6 +57,7 @@ const RATE_LIMITS = {
57
57
  execute: { windowMs: 60000, max: 10 },
58
58
  install: { windowMs: 3600000, max: 2 },
59
59
  register: { windowMs: 3600000, max: 3 },
60
+ update: { windowMs: 3600000, max: 3 },
60
61
  };
61
62
 
62
63
  // In-memory store limits
@@ -155,7 +156,7 @@ function requireBridgeAuth(req, res, next) {
155
156
 
156
157
  const rateLimitStore = new Map();
157
158
 
158
- function rateLimit(key, config) {
159
+ function rateLimit(key, config = { windowMs: 60000, max: 10 }) {
159
160
  return (req, res, next) => {
160
161
  const ip = req.ip || req.connection.remoteAddress || 'unknown';
161
162
  const storeKey = `${key}:${ip}`;
@@ -668,7 +669,7 @@ app.get('/agents/:name/check', (req, res) => {
668
669
  app.post(
669
670
  '/agents/install',
670
671
  requireBridgeAuth,
671
- rateLimit('install'),
672
+ rateLimit('install', RATE_LIMITS.install),
672
673
  express.json(),
673
674
  async (req, res) => {
674
675
  const { agentId } = req.body;
@@ -1026,6 +1027,136 @@ app.post(
1026
1027
  },
1027
1028
  );
1028
1029
 
1030
+ // ---------------------------------------------------------------------------
1031
+ // Auto-Update
1032
+ // ---------------------------------------------------------------------------
1033
+
1034
+ /**
1035
+ * Check the latest version of the bridge on npm registry.
1036
+ * Returns { current, latest, updateAvailable }.
1037
+ */
1038
+ function checkNpmVersion() {
1039
+ return new Promise((resolve) => {
1040
+ const proc = spawn('npm', ['view', 'agentic-factory-bridge', 'version'], {
1041
+ stdio: ['pipe', 'pipe', 'pipe'],
1042
+ timeout: 15000,
1043
+ shell: true,
1044
+ });
1045
+ let stdout = '';
1046
+ let stderr = '';
1047
+ proc.stdout.on('data', (data) => {
1048
+ stdout += data.toString();
1049
+ });
1050
+ proc.stderr.on('data', (data) => {
1051
+ stderr += data.toString();
1052
+ });
1053
+ proc.on('close', (code) => {
1054
+ if (code === 0 && stdout.trim()) {
1055
+ const latest = stdout.trim();
1056
+ const updateAvailable = latest !== BRIDGE_VERSION;
1057
+ resolve({ current: BRIDGE_VERSION, latest, updateAvailable });
1058
+ } else {
1059
+ resolve({
1060
+ current: BRIDGE_VERSION,
1061
+ latest: null,
1062
+ updateAvailable: false,
1063
+ error: stderr.trim() || 'Failed to query npm registry',
1064
+ });
1065
+ }
1066
+ });
1067
+ proc.on('error', (err) => {
1068
+ resolve({
1069
+ current: BRIDGE_VERSION,
1070
+ latest: null,
1071
+ updateAvailable: false,
1072
+ error: err.message,
1073
+ });
1074
+ });
1075
+ });
1076
+ }
1077
+
1078
+ app.get('/check-update', async (_req, res) => {
1079
+ try {
1080
+ const result = await checkNpmVersion();
1081
+ console.log(
1082
+ `[bridge] Update check: current=${result.current}, latest=${result.latest}, updateAvailable=${result.updateAvailable}`,
1083
+ );
1084
+ res.json(result);
1085
+ } catch (err) {
1086
+ res.json({
1087
+ current: BRIDGE_VERSION,
1088
+ latest: null,
1089
+ updateAvailable: false,
1090
+ error: err.message,
1091
+ });
1092
+ }
1093
+ });
1094
+
1095
+ app.post(
1096
+ '/self-update',
1097
+ requireBridgeAuth,
1098
+ rateLimit('update', RATE_LIMITS.update),
1099
+ async (_req, res) => {
1100
+ console.log('[bridge] Self-update: installing latest version via npm...');
1101
+ try {
1102
+ const installResult = await new Promise((resolve, reject) => {
1103
+ const proc = spawn('npm', ['install', '-g', 'agentic-factory-bridge@latest'], {
1104
+ stdio: ['pipe', 'pipe', 'pipe'],
1105
+ timeout: 120000,
1106
+ shell: true,
1107
+ });
1108
+ let stdout = '';
1109
+ let stderr = '';
1110
+ proc.stdout.on('data', (data) => {
1111
+ stdout += data.toString();
1112
+ console.log(`[bridge] npm update stdout: ${data.toString().trim()}`);
1113
+ });
1114
+ proc.stderr.on('data', (data) => {
1115
+ stderr += data.toString();
1116
+ });
1117
+ proc.on('close', (code) => {
1118
+ if (code === 0) resolve({ success: true, stdout, stderr });
1119
+ else
1120
+ reject(
1121
+ new Error(
1122
+ `npm install -g agentic-factory-bridge@latest failed with code ${code}: ${stderr || stdout}`,
1123
+ ),
1124
+ );
1125
+ });
1126
+ proc.on('error', (err) => {
1127
+ reject(new Error(`Failed to spawn npm: ${err.message}`));
1128
+ });
1129
+ });
1130
+
1131
+ // Check new version
1132
+ const versionCheck = await checkNpmVersion();
1133
+
1134
+ res.json({
1135
+ success: true,
1136
+ message: 'Bridge updated successfully. Restart the bridge to apply.',
1137
+ previousVersion: BRIDGE_VERSION,
1138
+ newVersion: versionCheck.latest || 'unknown',
1139
+ restartRequired: true,
1140
+ });
1141
+
1142
+ // Auto-restart after 2 seconds to let the response be sent
1143
+ console.log('[bridge] Update complete. Restarting in 2 seconds...');
1144
+ setTimeout(() => {
1145
+ process.exit(0); // Exit — systemd/pm2/npm script will restart, or user restarts manually
1146
+ }, 2000);
1147
+ } catch (err) {
1148
+ console.error(`[bridge] Self-update error: ${err.message}`);
1149
+ res.status(500).json({
1150
+ success: false,
1151
+ message: `Update failed: ${err.message}`,
1152
+ previousVersion: BRIDGE_VERSION,
1153
+ newVersion: null,
1154
+ restartRequired: false,
1155
+ });
1156
+ }
1157
+ },
1158
+ );
1159
+
1029
1160
  // ---------------------------------------------------------------------------
1030
1161
  // Start server
1031
1162
  // ---------------------------------------------------------------------------
@@ -1056,4 +1187,17 @@ app.listen(PORT, '127.0.0.1', () => {
1056
1187
  console.log(` Bridge secret: ${BRIDGE_SECRET.substring(0, 16)}...`);
1057
1188
  console.log('');
1058
1189
  }
1190
+
1191
+ // Startup update check (non-blocking)
1192
+ checkNpmVersion().then((result) => {
1193
+ if (result.updateAvailable) {
1194
+ console.log(' +----------------------------------------------+');
1195
+ console.log(` | [!] Update available: v${result.latest.padEnd(21)}|`);
1196
+ console.log(` | Current: v${BRIDGE_VERSION.padEnd(29)}|`);
1197
+ console.log(' | Run: npm update -g agentic-factory-bridge |');
1198
+ console.log(' | Or update from the marketplace UI |');
1199
+ console.log(' +----------------------------------------------+');
1200
+ console.log('');
1201
+ }
1202
+ });
1059
1203
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentic-factory-bridge",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "Local bridge for Atos Agentic Factory — connects the marketplace to OpenCode CLI on your machine",
5
5
  "main": "bridge.js",
6
6
  "bin": {