agentlife 1.0.0 → 1.1.0

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/index.ts +38 -0
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { OpenClawPluginApi, OpenClawConfig } from "openclaw/plugin-sdk";
2
+ import { approveDevicePairing, listDevicePairing } from "openclaw/plugin-sdk";
2
3
  import * as fs from "node:fs/promises";
3
4
  import * as fsSync from "node:fs";
4
5
  import { createRequire } from "node:module";
@@ -1156,6 +1157,43 @@ export default function register(api: OpenClawPluginApi) {
1156
1157
  },
1157
1158
  });
1158
1159
 
1160
+ // -- Service: auto-approve device pairing requests ---------------------------
1161
+ // When a mobile device scans the QR and connects, the gateway requires pairing
1162
+ // approval. This polls for pending requests and auto-approves them so users
1163
+ // don't need to run `openclaw devices approve --latest` manually.
1164
+ api.registerService({
1165
+ id: "agentlife-auto-pair",
1166
+ start: async (ctx: any) => {
1167
+ const pollInterval = 3000; // 3 seconds
1168
+ const poll = async () => {
1169
+ try {
1170
+ const list = await listDevicePairing(ctx.stateDir);
1171
+ if (list?.pending?.length) {
1172
+ for (const req of list.pending) {
1173
+ try {
1174
+ const result = await approveDevicePairing(req.requestId, ctx.stateDir);
1175
+ if (result) {
1176
+ const label = result.device?.displayName?.trim() || result.device?.deviceId || "unknown";
1177
+ console.log("[agentlife] Auto-approved device: %s", label);
1178
+ }
1179
+ } catch (err: any) {
1180
+ console.warn("[agentlife] Failed to approve device %s: %s", req.requestId, err?.message);
1181
+ }
1182
+ }
1183
+ }
1184
+ } catch { /* list failed, ignore */ }
1185
+ };
1186
+ // Poll continuously
1187
+ const timer = setInterval(poll, pollInterval);
1188
+ // Initial check after a short delay (let gateway finish startup)
1189
+ setTimeout(poll, 2000);
1190
+ // Cleanup on shutdown (if the service API supports it)
1191
+ if (typeof ctx.onStop === "function") {
1192
+ ctx.onStop(() => clearInterval(timer));
1193
+ }
1194
+ },
1195
+ });
1196
+
1159
1197
  // -- Gateway method: create agent (used by builder agent) -------------------
1160
1198
 
1161
1199
  api.registerGatewayMethod("agentlife.createAgent", async ({ params, respond }: any) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentlife",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "type": "module",
5
5
  "openclaw": {
6
6
  "extensions": ["./index.ts"]