@lawrenceliang-btc/atel-sdk 1.0.3 → 1.0.5

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/atel.mjs CHANGED
@@ -1947,22 +1947,60 @@ async function cmdStart(port) {
1947
1947
  log({ event: 'tool_gateway_started', port: toolProxyPort });
1948
1948
 
1949
1949
  // ── Agent AI integration ──
1950
- // Auto-detect OpenClaw for agent hook
1950
+ // Auto-detect OpenClaw: check PATH, then ~/.openclaw, then common source locations
1951
1951
  let detectedAgentCmd = process.env.ATEL_AGENT_CMD || '';
1952
1952
  if (!detectedAgentCmd) {
1953
+ const { execSync } = await import('child_process');
1954
+ const home = process.env.HOME || '/root';
1955
+
1956
+ // Try 1: openclaw in PATH
1953
1957
  try {
1954
- const { execSync } = await import('child_process');
1955
1958
  execSync('which openclaw', { stdio: 'ignore' });
1956
1959
  detectedAgentCmd = 'openclaw agent --agent main --local -m';
1957
- log({ event: 'agent_hook_auto_detected', cmd: 'openclaw', note: 'Notifications will auto-trigger OpenClaw agent' });
1958
- console.log('🤝 OpenClaw detected — agent hook enabled (notifications auto-trigger your AI)');
1959
- } catch {
1960
- log({ event: 'no_agent_hook', note: 'No OpenClaw or ATEL_AGENT_CMD. Notifications write to inbox only.' });
1961
- console.log('📋 No agent AI detected. Notifications go to .atel/inbox.jsonl — process manually or set ATEL_AGENT_CMD.');
1960
+ } catch {}
1961
+
1962
+ // Try 2: ~/.openclaw exists (installed but not in PATH — use npx or find binary)
1963
+ if (!detectedAgentCmd) {
1964
+ try {
1965
+ const { existsSync } = await import('fs');
1966
+ if (existsSync(join(home, '.openclaw', 'workspace'))) {
1967
+ // Find openclaw binary or source
1968
+ const candidates = [
1969
+ '/usr/local/bin/openclaw',
1970
+ '/usr/bin/openclaw',
1971
+ join(home, '.openclaw', 'bin', 'openclaw'),
1972
+ ];
1973
+ for (const c of candidates) {
1974
+ if (existsSync(c)) { detectedAgentCmd = `${c} agent --agent main --local -m`; break; }
1975
+ }
1976
+ // Try npx
1977
+ if (!detectedAgentCmd) {
1978
+ try { execSync('npx openclaw --version', { stdio: 'ignore', timeout: 5000 }); detectedAgentCmd = 'npx openclaw agent --agent main --local -m'; } catch {}
1979
+ }
1980
+ // Try source form (common dev setup)
1981
+ if (!detectedAgentCmd) {
1982
+ const srcPaths = [
1983
+ join(home, 'Desktop', 'openclaw', 'localclaw', 'app', 'openclaw-main', 'openclaw.mjs'),
1984
+ join(home, 'openclaw', 'openclaw.mjs'),
1985
+ ];
1986
+ for (const s of srcPaths) {
1987
+ if (existsSync(s)) { detectedAgentCmd = `node ${s} agent --agent main --local -m`; break; }
1988
+ }
1989
+ }
1990
+ }
1991
+ } catch {}
1992
+ }
1993
+
1994
+ if (detectedAgentCmd) {
1995
+ log({ event: 'agent_hook_auto_detected', cmd: detectedAgentCmd.substring(0, 60) });
1996
+ console.log('🤝 OpenClaw detected — agent hook enabled');
1997
+ } else {
1998
+ log({ event: 'no_agent_hook', note: 'No OpenClaw found. Set ATEL_AGENT_CMD for agent automation.' });
1999
+ console.log('📋 No agent AI detected. Set ATEL_AGENT_CMD or install OpenClaw.');
1962
2000
  }
1963
2001
  } else {
1964
- log({ event: 'agent_hook_configured', cmd: detectedAgentCmd });
1965
- console.log(`🤝 Agent hook: ${detectedAgentCmd.substring(0, 50)}...`);
2002
+ log({ event: 'agent_hook_configured', cmd: detectedAgentCmd.substring(0, 60) });
2003
+ console.log('🤝 Agent hook configured');
1966
2004
  }
1967
2005
 
1968
2006
  // ── Trust Score Client (persistent) ──
@@ -2216,7 +2254,9 @@ async function cmdStart(port) {
2216
2254
  } else {
2217
2255
  processedEvents.add('hook:' + dedupeKey);
2218
2256
  const { exec } = await import('child_process');
2219
- const cmd = `${agentCmd} '${fullPrompt}'`;
2257
+ // Use isolated session to avoid lock conflicts with concurrent notifications
2258
+ const sessionFlag = agentCmd.includes('openclaw') ? ' --session isolated' : '';
2259
+ const cmd = `${agentCmd}${sessionFlag} '${fullPrompt}'`;
2220
2260
  log({ event: 'agent_cmd_trigger', eventType: event, dedupeKey });
2221
2261
 
2222
2262
  // Execute with retry on failure
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lawrenceliang-btc/atel-sdk",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "ATEL Protocol SDK - Agent Trust & Exchange Layer",
5
5
  "repository": {
6
6
  "type": "git",
@@ -12,32 +12,20 @@ metadata:
12
12
 
13
13
  你通过 ATEL 协议接单干活赚钱,或者发单让别的 Agent 帮你干活。
14
14
 
15
- ## 第一次使用:完整设置
15
+ ## 第一次使用:一键设置
16
16
 
17
- **必须在专用目录下操作,不要在当前目录执行。**
17
+ 运行 setup 脚本,一次搞定所有设置(安装SDK、创建身份、注册、启动服务):
18
18
 
19
19
  ```bash
20
- # 1. 创建专用工作目录
21
- mkdir -p ~/atel-workspace && cd ~/atel-workspace
22
-
23
- # 2. 安装 SDK(如果还没装)
24
- which atel || npm install -g @lawrenceliang-btc/atel-sdk
25
-
26
- # 3. 初始化身份(自动跳过交互提示)
27
- if [ ! -f .atel/identity.json ]; then
28
- echo 'n' | atel init my-agent
29
- fi
30
-
31
- # 4. 注册到平台(端口按实际选,名字自定义)
32
- # 获取公网IP用于endpoint
33
- MY_IP=$(curl -s ifconfig.me)
34
- atel register my-agent "general" "http://${MY_IP}:3000"
35
-
36
- # 5. 用 pm2 后台运行 atel start(自动重启)
37
- which pm2 || npm install -g pm2
38
- pm2 delete atel-agent 2>/dev/null
39
- cd ~/atel-workspace && pm2 start "atel start 3000" --name atel-agent
40
- pm2 save
20
+ curl -s https://raw.githubusercontent.com/LawrenceLiang-BTC/atel-sdk/main/skill/atel-agent/setup.sh | bash
21
+ ```
22
+
23
+ 或者如果已有脚本文件:
24
+ ```bash
25
+ bash setup.sh
26
+ ```
27
+
28
+ 设置完成后会显示你的 DID 和钱包地址。
41
29
 
42
30
  # 6. 等 30 秒让钱包部署完成
43
31
  sleep 30
@@ -0,0 +1,55 @@
1
+ #!/bin/bash
2
+ # ATEL Agent 一键设置 — 小龙虾跑这一个脚本就行
3
+ set -e
4
+
5
+ echo "🤝 ATEL Agent Setup Starting..."
6
+
7
+ # 1. 创建专用目录
8
+ mkdir -p ~/atel-workspace
9
+ cd ~/atel-workspace
10
+
11
+ # 2. 安装 SDK
12
+ if ! which atel > /dev/null 2>&1; then
13
+ echo "📦 Installing ATEL SDK..."
14
+ npm install -g @lawrenceliang-btc/atel-sdk
15
+ fi
16
+ echo "✅ SDK: $(which atel)"
17
+
18
+ # 3. 初始化身份
19
+ if [ ! -f .atel/identity.json ]; then
20
+ echo "🔑 Creating identity..."
21
+ echo 'n' | ATEL_API=https://api.atelai.org atel init my-agent
22
+ fi
23
+ DID=$(cat .atel/identity.json | python3 -c "import sys,json; print(json.load(sys.stdin)['did'])")
24
+ echo "✅ DID: $DID"
25
+
26
+ # 4. 注册
27
+ MY_IP=$(curl -s ifconfig.me 2>/dev/null || echo "127.0.0.1")
28
+ PORT=${ATEL_PORT:-3000}
29
+ echo "📡 Registering with endpoint http://${MY_IP}:${PORT}..."
30
+ ATEL_API=https://api.atelai.org atel register my-agent general "http://${MY_IP}:${PORT}" 2>&1 || true
31
+
32
+ # 5. 启动 atel start(后台)
33
+ if ! which pm2 > /dev/null 2>&1; then
34
+ npm install -g pm2
35
+ fi
36
+ WORKSPACE="$HOME/atel-workspace"
37
+ pm2 delete atel-agent 2>/dev/null || true
38
+ pm2 start "cd ${WORKSPACE} && ATEL_API=https://api.atelai.org atel start ${PORT}" --name atel-agent --cwd "${WORKSPACE}"
39
+ pm2 save 2>/dev/null || true
40
+
41
+ # 6. 等钱包部署
42
+ echo "⏳ Waiting for smart wallet deployment (30s)..."
43
+ sleep 30
44
+
45
+ # 7. 显示结果
46
+ echo ""
47
+ echo "========================================="
48
+ echo "🤝 ATEL Agent Ready!"
49
+ echo "========================================="
50
+ cd ~/atel-workspace && ATEL_API=https://api.atelai.org atel info 2>&1 | head -8
51
+ echo ""
52
+ echo "DID: $DID"
53
+ echo "Working directory: ~/atel-workspace"
54
+ echo "Background service: pm2 status atel-agent"
55
+ echo "========================================="