yap2app 1.2.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.
package/bin/cli.bundle.js CHANGED
@@ -1,5 +1,3 @@
1
- #!/usr/bin/env node
2
- import { createRequire } from 'module'; const require = createRequire(import.meta.url);
3
1
  var __create = Object.create;
4
2
  var __defProp = Object.defineProperty;
5
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -7755,35 +7753,95 @@ var server = http.createServer(async (req, res) => {
7755
7753
  res.writeHead(404, headers);
7756
7754
  res.end(JSON.stringify({ error: "Endpoint Not Found", path: pathname }));
7757
7755
  });
7756
+ var CLOUD_URL = process.env.YAP2APP_CLOUD_URL || "https://yap2app-dot-cybage-hackathon.uc.r.appspot.com";
7757
+ async function sendCloudHeartbeat() {
7758
+ try {
7759
+ const context = await scanCodebase(PROJECT_ROOT);
7760
+ const payload = {
7761
+ pair_code: PAIR_CODE,
7762
+ project_name: path2.basename(PROJECT_ROOT),
7763
+ project_root: PROJECT_ROOT,
7764
+ framework: context.framework || "plain_html_css_js",
7765
+ context,
7766
+ version: CLI_VERSION
7767
+ };
7768
+ const res = await fetch(`${CLOUD_URL}/api/v1/bridge/heartbeat`, {
7769
+ method: "POST",
7770
+ headers: { "Content-Type": "application/json" },
7771
+ body: JSON.stringify(payload)
7772
+ });
7773
+ if (res.ok) {
7774
+ const data = await res.json();
7775
+ if (data.pending_writes_count > 0) {
7776
+ await pollAndExecuteCloudWrites();
7777
+ }
7778
+ }
7779
+ } catch (err) {
7780
+ }
7781
+ }
7782
+ async function pollAndExecuteCloudWrites() {
7783
+ try {
7784
+ const res = await fetch(`${CLOUD_URL}/api/v1/bridge/poll-writes?pair_code=${encodeURIComponent(PAIR_CODE)}`);
7785
+ if (!res.ok) return;
7786
+ const data = await res.json();
7787
+ const tasks = data.pending_tasks || [];
7788
+ for (const task of tasks) {
7789
+ const written = [];
7790
+ for (const file of task.files || []) {
7791
+ const fullPath = safeResolvePath(PROJECT_ROOT, file.path);
7792
+ await fs2.mkdir(path2.dirname(fullPath), { recursive: true });
7793
+ await fs2.writeFile(fullPath, file.content, "utf8");
7794
+ console.log(` [bridge] Wrote ${file.path}`);
7795
+ written.push(file.path);
7796
+ }
7797
+ await fetch(`${CLOUD_URL}/api/v1/bridge/complete-write`, {
7798
+ method: "POST",
7799
+ headers: { "Content-Type": "application/json" },
7800
+ body: JSON.stringify({
7801
+ task_id: task.task_id,
7802
+ success: true,
7803
+ written,
7804
+ message: `Successfully wrote ${written.length} files to ${path2.basename(PROJECT_ROOT)}`
7805
+ })
7806
+ });
7807
+ }
7808
+ } catch (err) {
7809
+ console.error(" [bridge] Cloud write sync error:", err.message);
7810
+ }
7811
+ }
7758
7812
  server.on("error", (err) => {
7759
7813
  if (err && err.code === "EADDRINUSE") {
7760
7814
  console.log(`
7761
7815
  ---------------------------------------------------------------`);
7762
7816
  console.log(`Yap2App Local Bridge v${CLI_VERSION}`);
7817
+ console.log(`Pair Code: ${PAIR_CODE}`);
7763
7818
  console.log(`Local Endpoint: http://127.0.0.1:${PORT}`);
7764
7819
  console.log(`Active Workspace: ${PROJECT_ROOT}`);
7765
7820
  console.log(`Status: Already active & ready on port ${PORT}`);
7766
7821
  console.log(`---------------------------------------------------------------
7767
7822
  `);
7768
- console.log(`Bridge is running.`);
7823
+ console.log(`Bridge is running & synced.`);
7769
7824
  console.log(`Open Web Studio in your browser to sync components to this workspace.`);
7770
7825
  console.log(`Press Ctrl/Cmd+C to stop.
7771
7826
  `);
7827
+ sendCloudHeartbeat();
7828
+ setInterval(sendCloudHeartbeat, 3e3);
7772
7829
  return;
7773
7830
  }
7774
7831
  console.error(" [bridge] Error:", err.message || err);
7775
7832
  });
7776
7833
  async function startBridge(port = PORT) {
7777
- server.listen(port, "0.0.0.0", () => {
7834
+ server.listen(port, () => {
7778
7835
  console.log(`
7779
7836
  ---------------------------------------------------------------`);
7780
7837
  console.log(`Yap2App Local Bridge v${CLI_VERSION}`);
7838
+ console.log(`Pair Code: ${PAIR_CODE}`);
7781
7839
  console.log(`Local Endpoint: http://127.0.0.1:${port}`);
7782
7840
  console.log(`Active Workspace: ${PROJECT_ROOT}`);
7783
7841
  console.log(`Web Studio: https://yap2app-dot-cybage-hackathon.uc.r.appspot.com`);
7784
7842
  console.log(`---------------------------------------------------------------
7785
7843
  `);
7786
- console.log(`Bridge is running.`);
7844
+ console.log(`Bridge is running & synced.`);
7787
7845
  console.log(`Open Web Studio in your browser to automatically connect and sync.`);
7788
7846
  console.log(`Press Ctrl/Cmd+C to stop.
7789
7847
  `);
@@ -7797,6 +7855,8 @@ async function startBridge(port = PORT) {
7797
7855
  }
7798
7856
  } catch (e) {
7799
7857
  }
7858
+ sendCloudHeartbeat();
7859
+ setInterval(sendCloudHeartbeat, 3e3);
7800
7860
  }
7801
7861
  var isDirectRun = Boolean(typeof process !== "undefined" && process.argv && process.argv[1] && (process.argv[1].endsWith("bridge.js") || process.argv[1].endsWith("bridge")));
7802
7862
  if (isDirectRun) {
package/bin/cli.js CHANGED
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env node
2
- import { createRequire } from 'module'; const require = createRequire(import.meta.url);
3
2
  var __create = Object.create;
4
3
  var __defProp = Object.defineProperty;
5
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -7755,35 +7754,95 @@ var server = http.createServer(async (req, res) => {
7755
7754
  res.writeHead(404, headers);
7756
7755
  res.end(JSON.stringify({ error: "Endpoint Not Found", path: pathname }));
7757
7756
  });
7757
+ var CLOUD_URL = process.env.YAP2APP_CLOUD_URL || "https://yap2app-dot-cybage-hackathon.uc.r.appspot.com";
7758
+ async function sendCloudHeartbeat() {
7759
+ try {
7760
+ const context = await scanCodebase(PROJECT_ROOT);
7761
+ const payload = {
7762
+ pair_code: PAIR_CODE,
7763
+ project_name: path2.basename(PROJECT_ROOT),
7764
+ project_root: PROJECT_ROOT,
7765
+ framework: context.framework || "plain_html_css_js",
7766
+ context,
7767
+ version: CLI_VERSION
7768
+ };
7769
+ const res = await fetch(`${CLOUD_URL}/api/v1/bridge/heartbeat`, {
7770
+ method: "POST",
7771
+ headers: { "Content-Type": "application/json" },
7772
+ body: JSON.stringify(payload)
7773
+ });
7774
+ if (res.ok) {
7775
+ const data = await res.json();
7776
+ if (data.pending_writes_count > 0) {
7777
+ await pollAndExecuteCloudWrites();
7778
+ }
7779
+ }
7780
+ } catch (err) {
7781
+ }
7782
+ }
7783
+ async function pollAndExecuteCloudWrites() {
7784
+ try {
7785
+ const res = await fetch(`${CLOUD_URL}/api/v1/bridge/poll-writes?pair_code=${encodeURIComponent(PAIR_CODE)}`);
7786
+ if (!res.ok) return;
7787
+ const data = await res.json();
7788
+ const tasks = data.pending_tasks || [];
7789
+ for (const task of tasks) {
7790
+ const written = [];
7791
+ for (const file of task.files || []) {
7792
+ const fullPath = safeResolvePath(PROJECT_ROOT, file.path);
7793
+ await fs2.mkdir(path2.dirname(fullPath), { recursive: true });
7794
+ await fs2.writeFile(fullPath, file.content, "utf8");
7795
+ console.log(` [bridge] Wrote ${file.path}`);
7796
+ written.push(file.path);
7797
+ }
7798
+ await fetch(`${CLOUD_URL}/api/v1/bridge/complete-write`, {
7799
+ method: "POST",
7800
+ headers: { "Content-Type": "application/json" },
7801
+ body: JSON.stringify({
7802
+ task_id: task.task_id,
7803
+ success: true,
7804
+ written,
7805
+ message: `Successfully wrote ${written.length} files to ${path2.basename(PROJECT_ROOT)}`
7806
+ })
7807
+ });
7808
+ }
7809
+ } catch (err) {
7810
+ console.error(" [bridge] Cloud write sync error:", err.message);
7811
+ }
7812
+ }
7758
7813
  server.on("error", (err) => {
7759
7814
  if (err && err.code === "EADDRINUSE") {
7760
7815
  console.log(`
7761
7816
  ---------------------------------------------------------------`);
7762
7817
  console.log(`Yap2App Local Bridge v${CLI_VERSION}`);
7818
+ console.log(`Pair Code: ${PAIR_CODE}`);
7763
7819
  console.log(`Local Endpoint: http://127.0.0.1:${PORT}`);
7764
7820
  console.log(`Active Workspace: ${PROJECT_ROOT}`);
7765
7821
  console.log(`Status: Already active & ready on port ${PORT}`);
7766
7822
  console.log(`---------------------------------------------------------------
7767
7823
  `);
7768
- console.log(`Bridge is running.`);
7824
+ console.log(`Bridge is running & synced.`);
7769
7825
  console.log(`Open Web Studio in your browser to sync components to this workspace.`);
7770
7826
  console.log(`Press Ctrl/Cmd+C to stop.
7771
7827
  `);
7828
+ sendCloudHeartbeat();
7829
+ setInterval(sendCloudHeartbeat, 3e3);
7772
7830
  return;
7773
7831
  }
7774
7832
  console.error(" [bridge] Error:", err.message || err);
7775
7833
  });
7776
7834
  async function startBridge(port = PORT) {
7777
- server.listen(port, "0.0.0.0", () => {
7835
+ server.listen(port, () => {
7778
7836
  console.log(`
7779
7837
  ---------------------------------------------------------------`);
7780
7838
  console.log(`Yap2App Local Bridge v${CLI_VERSION}`);
7839
+ console.log(`Pair Code: ${PAIR_CODE}`);
7781
7840
  console.log(`Local Endpoint: http://127.0.0.1:${port}`);
7782
7841
  console.log(`Active Workspace: ${PROJECT_ROOT}`);
7783
7842
  console.log(`Web Studio: https://yap2app-dot-cybage-hackathon.uc.r.appspot.com`);
7784
7843
  console.log(`---------------------------------------------------------------
7785
7844
  `);
7786
- console.log(`Bridge is running.`);
7845
+ console.log(`Bridge is running & synced.`);
7787
7846
  console.log(`Open Web Studio in your browser to automatically connect and sync.`);
7788
7847
  console.log(`Press Ctrl/Cmd+C to stop.
7789
7848
  `);
@@ -7797,6 +7856,8 @@ async function startBridge(port = PORT) {
7797
7856
  }
7798
7857
  } catch (e) {
7799
7858
  }
7859
+ sendCloudHeartbeat();
7860
+ setInterval(sendCloudHeartbeat, 3e3);
7800
7861
  }
7801
7862
  var isDirectRun = Boolean(typeof process !== "undefined" && process.argv && process.argv[1] && (process.argv[1].endsWith("bridge.js") || process.argv[1].endsWith("bridge")));
7802
7863
  if (isDirectRun) {
package/bridge.js CHANGED
@@ -237,32 +237,102 @@ const server = http.createServer(async (req, res) => {
237
237
  res.end(JSON.stringify({ error: 'Endpoint Not Found', path: pathname }));
238
238
  });
239
239
 
240
+ const CLOUD_URL = process.env.YAP2APP_CLOUD_URL || 'https://yap2app-dot-cybage-hackathon.uc.r.appspot.com';
241
+
242
+ async function sendCloudHeartbeat() {
243
+ try {
244
+ const context = await scanCodebase(PROJECT_ROOT);
245
+ const payload = {
246
+ pair_code: PAIR_CODE,
247
+ project_name: path.basename(PROJECT_ROOT),
248
+ project_root: PROJECT_ROOT,
249
+ framework: context.framework || 'plain_html_css_js',
250
+ context: context,
251
+ version: CLI_VERSION
252
+ };
253
+
254
+ const res = await fetch(`${CLOUD_URL}/api/v1/bridge/heartbeat`, {
255
+ method: 'POST',
256
+ headers: { 'Content-Type': 'application/json' },
257
+ body: JSON.stringify(payload)
258
+ });
259
+
260
+ if (res.ok) {
261
+ const data = await res.json();
262
+ if (data.pending_writes_count > 0) {
263
+ await pollAndExecuteCloudWrites();
264
+ }
265
+ }
266
+ } catch (err) {
267
+ // Quiet fallback if offline or unreachable
268
+ }
269
+ }
270
+
271
+ async function pollAndExecuteCloudWrites() {
272
+ try {
273
+ const res = await fetch(`${CLOUD_URL}/api/v1/bridge/poll-writes?pair_code=${encodeURIComponent(PAIR_CODE)}`);
274
+ if (!res.ok) return;
275
+ const data = await res.json();
276
+ const tasks = data.pending_tasks || [];
277
+
278
+ for (const task of tasks) {
279
+ const written = [];
280
+ for (const file of task.files || []) {
281
+ const fullPath = safeResolvePath(PROJECT_ROOT, file.path);
282
+ await fs.mkdir(path.dirname(fullPath), { recursive: true });
283
+ await fs.writeFile(fullPath, file.content, 'utf8');
284
+ console.log(` [bridge] Wrote ${file.path}`);
285
+ written.push(file.path);
286
+ }
287
+
288
+ await fetch(`${CLOUD_URL}/api/v1/bridge/complete-write`, {
289
+ method: 'POST',
290
+ headers: { 'Content-Type': 'application/json' },
291
+ body: JSON.stringify({
292
+ task_id: task.task_id,
293
+ success: true,
294
+ written,
295
+ message: `Successfully wrote ${written.length} files to ${path.basename(PROJECT_ROOT)}`
296
+ })
297
+ });
298
+ }
299
+ } catch (err) {
300
+ console.error(' [bridge] Cloud write sync error:', err.message);
301
+ }
302
+ }
303
+
240
304
  // Gracefully handle EADDRINUSE without crashing
241
305
  server.on('error', (err) => {
242
306
  if (err && err.code === 'EADDRINUSE') {
243
307
  console.log(`\n---------------------------------------------------------------`);
244
308
  console.log(`Yap2App Local Bridge v${CLI_VERSION}`);
309
+ console.log(`Pair Code: ${PAIR_CODE}`);
245
310
  console.log(`Local Endpoint: http://127.0.0.1:${PORT}`);
246
311
  console.log(`Active Workspace: ${PROJECT_ROOT}`);
247
312
  console.log(`Status: Already active & ready on port ${PORT}`);
248
313
  console.log(`---------------------------------------------------------------\n`);
249
- console.log(`Bridge is running.`);
314
+ console.log(`Bridge is running & synced.`);
250
315
  console.log(`Open Web Studio in your browser to sync components to this workspace.`);
251
316
  console.log(`Press Ctrl/Cmd+C to stop.\n`);
317
+
318
+ // Still maintain cloud heartbeat even if port was bound by another process
319
+ sendCloudHeartbeat();
320
+ setInterval(sendCloudHeartbeat, 3000);
252
321
  return;
253
322
  }
254
323
  console.error(' [bridge] Error:', err.message || err);
255
324
  });
256
325
 
257
326
  export async function startBridge(port = PORT) {
258
- server.listen(port, '0.0.0.0', () => {
327
+ server.listen(port, () => {
259
328
  console.log(`\n---------------------------------------------------------------`);
260
329
  console.log(`Yap2App Local Bridge v${CLI_VERSION}`);
330
+ console.log(`Pair Code: ${PAIR_CODE}`);
261
331
  console.log(`Local Endpoint: http://127.0.0.1:${port}`);
262
332
  console.log(`Active Workspace: ${PROJECT_ROOT}`);
263
333
  console.log(`Web Studio: https://yap2app-dot-cybage-hackathon.uc.r.appspot.com`);
264
334
  console.log(`---------------------------------------------------------------\n`);
265
- console.log(`Bridge is running.`);
335
+ console.log(`Bridge is running & synced.`);
266
336
  console.log(`Open Web Studio in your browser to automatically connect and sync.`);
267
337
  console.log(`Press Ctrl/Cmd+C to stop.\n`);
268
338
  });
@@ -275,6 +345,10 @@ export async function startBridge(port = PORT) {
275
345
  console.log(` Yap2App will automatically scaffold directories and write files when synced from Web Studio.\n`);
276
346
  }
277
347
  } catch (e) {}
348
+
349
+ // Start bidirectional cloud relay heartbeat
350
+ sendCloudHeartbeat();
351
+ setInterval(sendCloudHeartbeat, 3000);
278
352
  }
279
353
 
280
354
  // Direct execution
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yap2app",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "type": "module",
5
5
  "description": "Autonomous Vibe-to-Prod Localhost Bridge & Model Context Protocol (MCP) Server",
6
6
  "main": "bin/cli.bundle.js",