@openagents-org/agent-connector 0.1.5 → 0.1.7

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/package.json +1 -1
  2. package/src/daemon.js +47 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openagents-org/agent-connector",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Agent management CLI and library for OpenAgents — install, configure, and run AI coding agents",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/src/daemon.js CHANGED
@@ -471,13 +471,58 @@ class Daemon {
471
471
  }
472
472
  }
473
473
 
474
+ /**
475
+ * Build workspace context preamble for CLI agents.
476
+ * Teaches the agent about shared workspace APIs (browser, files).
477
+ */
478
+ _buildWorkspaceContext(agentCfg, network) {
479
+ const baseUrl = 'https://workspace-endpoint.openagents.org';
480
+ const h = `Authorization: Bearer ${network.token}`;
481
+ const wsId = network.id;
482
+ const name = agentCfg.name;
483
+
484
+ return [
485
+ '=== WORKSPACE CONTEXT ===',
486
+ `You are agent "${name}" in workspace "${network.slug}".`,
487
+ 'You have access to shared workspace tools via HTTP API. Use your exec tool to run curl commands.',
488
+ '',
489
+ '## Shared Browser',
490
+ 'The workspace has a shared browser visible to all users and agents.',
491
+ `Open tab: curl -s -X POST ${baseUrl}/v1/browser/tabs -H "${h}" -H "Content-Type: application/json" -d '{"url":"URL","network":"${wsId}","source":"openagents:${name}"}'`,
492
+ `Read page: curl -s -H "${h}" ${baseUrl}/v1/browser/tabs/TAB_ID/snapshot`,
493
+ `Screenshot: curl -s -H "${h}" ${baseUrl}/v1/browser/tabs/TAB_ID/screenshot`,
494
+ `Navigate: curl -s -X POST ${baseUrl}/v1/browser/tabs/TAB_ID/navigate -H "${h}" -H "Content-Type: application/json" -d '{"url":"URL"}'`,
495
+ `Click: curl -s -X POST ${baseUrl}/v1/browser/tabs/TAB_ID/click -H "${h}" -H "Content-Type: application/json" -d '{"selector":"CSS_SELECTOR"}'`,
496
+ `Type: curl -s -X POST ${baseUrl}/v1/browser/tabs/TAB_ID/type -H "${h}" -H "Content-Type: application/json" -d '{"selector":"CSS_SELECTOR","text":"TEXT"}'`,
497
+ `Close: curl -s -X DELETE -H "${h}" ${baseUrl}/v1/browser/tabs/TAB_ID`,
498
+ `List tabs: curl -s -H "${h}" ${baseUrl}/v1/browser/tabs?network=${wsId}`,
499
+ '(Replace TAB_ID with the id from the open response)',
500
+ '',
501
+ '## Workspace Files',
502
+ `List: curl -s -H "${h}" ${baseUrl}/v1/files?network=${wsId}`,
503
+ `Read: curl -s -H "${h}" ${baseUrl}/v1/files/FILE_PATH?network=${wsId}`,
504
+ `Write: curl -s -X PUT ${baseUrl}/v1/files/FILE_PATH -H "${h}" -H "Content-Type: application/json" -d '{"content":"...","network":"${wsId}"}'`,
505
+ '=== END WORKSPACE CONTEXT ===',
506
+ '',
507
+ ].join('\n');
508
+ }
509
+
474
510
  _runCliAgent(binary, message, channel, agentCfg, network, env) {
475
511
  return new Promise((resolve, reject) => {
476
512
  const sessionKey = `openagents-${network.id.slice(0, 8)}-${channel.slice(-8)}`;
477
513
  const agentId = agentCfg.openclaw_agent_id || 'main';
478
514
 
515
+ // Prepend workspace context on first message in a session
516
+ const contextKey = `${agentCfg.name}:${sessionKey}`;
517
+ let fullMessage = message;
518
+ if (!this._sessionContextSent) this._sessionContextSent = new Set();
519
+ if (!this._sessionContextSent.has(contextKey)) {
520
+ fullMessage = this._buildWorkspaceContext(agentCfg, network) + message;
521
+ this._sessionContextSent.add(contextKey);
522
+ }
523
+
479
524
  const args = ['agent', '--local', '--agent', agentId,
480
- '--session-id', sessionKey, '--message', message, '--json'];
525
+ '--session-id', sessionKey, '--message', fullMessage, '--json'];
481
526
 
482
527
  this._log(`${agentCfg.name} CLI: ${binary} ${args.slice(0, 5).join(' ')} ...`);
483
528
 
@@ -763,11 +808,7 @@ class Daemon {
763
808
  try {
764
809
  if (!fs.existsSync(pidFile)) return null;
765
810
  const pid = parseInt(fs.readFileSync(pidFile, 'utf-8').trim(), 10);
766
- if (isNaN(pid)) return null;
767
- if (Daemon._isAlive(pid)) return pid;
768
- // Stale
769
- try { fs.unlinkSync(pidFile); } catch {}
770
- return null;
811
+ return isNaN(pid) ? null : pid;
771
812
  } catch {
772
813
  return null;
773
814
  }