@a2hmarket/a2hmarket 0.6.0 → 0.6.2

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.
@@ -6,7 +6,20 @@
6
6
  "skills": ["./skills"],
7
7
  "configSchema": {
8
8
  "type": "object",
9
- "properties": {},
9
+ "properties": {
10
+ "agentId": { "type": "string", "description": "A2H Market agent ID" },
11
+ "agentKey": { "type": "string", "description": "A2H Market agent key (HMAC signing)" },
12
+ "apiUrl": { "type": "string", "description": "A2H Market API base URL" },
13
+ "mqttUrl": { "type": "string", "description": "MQTT broker URL for A2A messaging" },
14
+ "tempoPrivateKey": { "type": "string", "description": "Solana private key for Tempo payments" },
15
+ "notify": {
16
+ "type": "object",
17
+ "properties": {
18
+ "channel": { "type": "string", "description": "Notification channel (feishu, discord, etc.)" },
19
+ "target": { "type": "string", "description": "Target ID for notifications" }
20
+ }
21
+ }
22
+ },
10
23
  "additionalProperties": false
11
24
  }
12
25
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@a2hmarket/a2hmarket",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "index.ts",
@@ -424,7 +424,22 @@ async function runUninstall() {
424
424
  }
425
425
  }
426
426
 
427
- // 3. Restart gateway
427
+ // 3. Clean openclaw.json plugin config
428
+ try {
429
+ const configPath = join(OPENCLAW_DIR, "openclaw.json");
430
+ const cfg = JSON.parse(readFileSync(configPath, "utf-8"));
431
+ const entry = cfg?.plugins?.entries?.a2hmarket;
432
+ if (entry) {
433
+ // Reset to minimal — keep enabled:false so openclaw knows it was uninstalled
434
+ cfg.plugins.entries.a2hmarket = { enabled: false };
435
+ writeFileSync(configPath, JSON.stringify(cfg, null, 2) + "\n");
436
+ log(` ${CHECK} openclaw.json 已清理`);
437
+ }
438
+ } catch {
439
+ log(` ${WARN} openclaw.json 清理跳过`);
440
+ }
441
+
442
+ // 4. Restart gateway
428
443
  try {
429
444
  execSync("openclaw gateway restart 2>&1", { encoding: "utf-8", stdio: "pipe" });
430
445
  log(` ${CHECK} Gateway 已重启`);
@@ -637,43 +652,7 @@ async function main() {
637
652
  log(` ${WARN} 模块链接失败: ${err.message}`);
638
653
  }
639
654
 
640
- // ── Step 3.6: Ensure a2h tools in alsoAllow ────────────────────
641
- // If tools.alsoAllow exists (whitelist mode), add a2h tools to it.
642
- log(` 配置工具权限...`);
643
- try {
644
- const configPath = join(OPENCLAW_DIR, "openclaw.json");
645
- const cfg = JSON.parse(readFileSync(configPath, "utf-8"));
646
- const alsoAllow = cfg?.tools?.alsoAllow;
647
- if (Array.isArray(alsoAllow)) {
648
- const a2hTools = [
649
- "a2h_status", "a2h_profile_get", "a2h_profile_upload_qrcode",
650
- "a2h_profile_delete_qrcode", "a2h_file_upload",
651
- "a2h_works_search", "a2h_works_list", "a2h_works_publish",
652
- "a2h_works_update", "a2h_works_delete",
653
- "a2h_order_create", "a2h_order_action", "a2h_order_get", "a2h_order_list",
654
- "a2h_send",
655
- ];
656
- let added = 0;
657
- for (const t of a2hTools) {
658
- if (!alsoAllow.includes(t)) {
659
- alsoAllow.push(t);
660
- added++;
661
- }
662
- }
663
- if (added > 0) {
664
- writeFileSync(configPath, JSON.stringify(cfg, null, 2) + "\n");
665
- log(` ${CHECK} ${added} 个 a2h 工具已添加到工具白名单`);
666
- } else {
667
- log(` ${CHECK} 工具白名单已包含 a2h 工具`);
668
- }
669
- } else {
670
- log(` ${CHECK} 无工具白名单限制`);
671
- }
672
- } catch {
673
- log(` ${WARN} 工具权限配置跳过`);
674
- }
675
-
676
- // ── Step 4: Save credentials ───────────────────────────────────
655
+ // ── Step 4: Save credentials & configure openclaw.json ───────
677
656
  logStep(4, "保存配置");
678
657
  mkdirSync(DATA_DIR, { recursive: true });
679
658
 
@@ -705,7 +684,6 @@ async function main() {
705
684
  let target = "";
706
685
 
707
686
  if (chosen.name === "feishu") {
708
- // Auto-detect feishu target or ask
709
687
  target = detectFeishuTarget() || "";
710
688
  if (target) {
711
689
  log(` 检测到飞书用户: ${CYAN}${target}${RESET}`);
@@ -733,8 +711,63 @@ async function main() {
733
711
  log(` ${DIM}未检测到可用渠道,跳过通知配置${RESET}`);
734
712
  }
735
713
 
714
+ // Save credentials file (fallback for dev mode)
736
715
  writeFileSync(CREDS_FILE, JSON.stringify(credsData, null, 2) + "\n");
737
- log(` ${CHECK} 凭证已保存`);
716
+ log(` ${CHECK} 凭证文件已保存`);
717
+
718
+ // Write credentials into openclaw.json → plugins.entries.a2hmarket
719
+ // This is the primary config path — api.pluginConfig reads from here
720
+ log(` 写入 openclaw.json...`);
721
+ try {
722
+ const configPath = join(OPENCLAW_DIR, "openclaw.json");
723
+ const cfg = JSON.parse(readFileSync(configPath, "utf-8"));
724
+
725
+ // Ensure plugins.entries.a2hmarket exists
726
+ if (!cfg.plugins) cfg.plugins = {};
727
+ if (!cfg.plugins.entries) cfg.plugins.entries = {};
728
+ const entry = cfg.plugins.entries.a2hmarket ?? {};
729
+
730
+ // Write credentials into plugin entry
731
+ entry.enabled = true;
732
+ entry.agentId = agentId;
733
+ entry.agentKey = agentKey;
734
+ entry.apiUrl = apiUrl;
735
+ entry.mqttUrl = mqttUrl;
736
+ if (credsData.notify) {
737
+ entry.notify = credsData.notify;
738
+ }
739
+ cfg.plugins.entries.a2hmarket = entry;
740
+
741
+ // Ensure a2h tools in alsoAllow (if whitelist mode is active)
742
+ if (!cfg.tools) cfg.tools = {};
743
+ if (Array.isArray(cfg.tools.alsoAllow)) {
744
+ const a2hTools = [
745
+ "a2h_status", "a2h_profile_get", "a2h_profile_upload_qrcode",
746
+ "a2h_profile_delete_qrcode", "a2h_file_upload",
747
+ "a2h_works_search", "a2h_works_list", "a2h_works_publish",
748
+ "a2h_works_update", "a2h_works_delete",
749
+ "a2h_order_create", "a2h_order_action", "a2h_order_get", "a2h_order_list",
750
+ "a2h_send", "a2h_inbox_history",
751
+ "a2h_address_list", "a2h_address_create", "a2h_address_delete", "a2h_address_set_default",
752
+ "a2h_discussion_publish", "a2h_discussion_reply", "a2h_discussion_list",
753
+ "a2h_tempo_pay", "a2h_tempo_balance",
754
+ ];
755
+ let added = 0;
756
+ for (const t of a2hTools) {
757
+ if (!cfg.tools.alsoAllow.includes(t)) {
758
+ cfg.tools.alsoAllow.push(t);
759
+ added++;
760
+ }
761
+ }
762
+ if (added > 0) log(` ${CHECK} ${added} 个工具已添加到白名单`);
763
+ }
764
+
765
+ writeFileSync(configPath, JSON.stringify(cfg, null, 2) + "\n");
766
+ log(` ${CHECK} openclaw.json 已更新`);
767
+ } catch (err) {
768
+ log(` ${WARN} openclaw.json 写入失败: ${err.message}`);
769
+ log(` ${DIM}插件将使用凭证文件作为回退${RESET}`);
770
+ }
738
771
 
739
772
  // ── Step 5: Restart gateway ────────────────────────────────────
740
773
  logStep(5, "启动服务");
@@ -45,7 +45,7 @@ async function mqttSendText(
45
45
  }
46
46
  }
47
47
 
48
- // ── Re-export notifyHuman for external callers ──────────────────────────
48
+ // ── Re-export for external callers ──────────────────────────────────────
49
49
 
50
50
  export { notifyHuman as notifyHumanCard } from "./notify.js";
51
51
 
@@ -81,7 +81,7 @@ export async function startAgentService(ctx: AgentServiceContext): Promise<void>
81
81
  ctx.log.info(`inbound from ${event.senderId}: ${event.text.slice(0, 80)}`);
82
82
 
83
83
  // ① Custom notification: notify human about incoming message
84
- notifyHumanCard("inbound", event.senderId, event.text.slice(0, 500), creds.agentId, notifyLog);
84
+ notifyHuman("inbound", event.senderId, event.text.slice(0, 500), creds.agentId, notifyLog);
85
85
 
86
86
  // ② Dispatch to OpenClaw Agent via Channel Plugin SDK
87
87
  // Agent has full access to a2h_* tools