@2en/clawly-plugins 1.17.5 → 1.18.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.
package/gateway/index.ts CHANGED
@@ -3,6 +3,7 @@ import {registerAgentSend} from './agent'
3
3
  import {registerChannelsConfigure} from './channels-configure'
4
4
  import {registerClawhub2gateway} from './clawhub2gateway'
5
5
  import {registerConfigRepair} from './config-repair'
6
+ import {registerPairing} from './pairing'
6
7
  import {registerMemoryBrowser} from './memory'
7
8
  import {registerNotification} from './notification'
8
9
  import {registerOfflinePush} from './offline-push'
@@ -19,4 +20,5 @@ export function registerGateway(api: PluginApi) {
19
20
  registerChannelsConfigure(api)
20
21
  registerOfflinePush(api)
21
22
  registerConfigRepair(api)
23
+ registerPairing(api)
22
24
  }
package/gateway/memory.ts CHANGED
@@ -45,8 +45,13 @@ function resolveStateDir(api: PluginApi): string {
45
45
  }
46
46
 
47
47
  /** Read agents list from openclaw.json (cached). */
48
- let _cachedAgentsList: Array<{id?: string; default?: boolean; workspace?: string}> | null | undefined
49
- function readAgentsList(api: PluginApi): Array<{id?: string; default?: boolean; workspace?: string}> | null {
48
+ let _cachedAgentsList:
49
+ | Array<{id?: string; default?: boolean; workspace?: string}>
50
+ | null
51
+ | undefined
52
+ function readAgentsList(
53
+ api: PluginApi,
54
+ ): Array<{id?: string; default?: boolean; workspace?: string}> | null {
50
55
  if (_cachedAgentsList !== undefined) return _cachedAgentsList
51
56
  try {
52
57
  const stateDir = resolveStateDir(api)
@@ -76,6 +81,7 @@ function readAgentWorkspace(api: PluginApi, agentId?: string): string | null {
76
81
  let agent: (typeof agents)[number] | undefined
77
82
  if (agentId) {
78
83
  agent = agents.find((a) => a.id === agentId)
84
+ if (!agent) return null
79
85
  }
80
86
  if (!agent) {
81
87
  agent = agents.find((a) => a.default) ?? agents[0]
@@ -0,0 +1,42 @@
1
+ import {$} from 'zx'
2
+ import type {PluginApi} from '../index'
3
+ import {stripCliLogs} from '../lib/stripCliLogs'
4
+
5
+ $.verbose = false
6
+
7
+ export function registerPairing(api: PluginApi) {
8
+ api.registerGatewayMethod('clawly.pairing.list', async ({params, respond}) => {
9
+ const channel = typeof params.channel === 'string' ? params.channel.trim() : ''
10
+ if (!channel) {
11
+ respond(false, undefined, {code: 'invalid_params', message: 'channel is required'})
12
+ return
13
+ }
14
+ try {
15
+ const result = await $`openclaw pairing list ${channel} --json`
16
+ const parsed = JSON.parse(stripCliLogs(result.stdout))
17
+ respond(true, parsed)
18
+ } catch (err) {
19
+ const msg = err instanceof Error ? err.message : String(err)
20
+ api.logger.error(`pairing.list: ${msg}`)
21
+ respond(false, undefined, {code: 'cli_error', message: msg})
22
+ }
23
+ })
24
+ api.registerGatewayMethod('clawly.pairing.approve', async ({params, respond}) => {
25
+ const channel = typeof params.channel === 'string' ? params.channel.trim() : ''
26
+ const code = typeof params.code === 'string' ? params.code.trim() : ''
27
+ if (!channel || !code) {
28
+ respond(false, undefined, {code: 'invalid_params', message: 'channel and code are required'})
29
+ return
30
+ }
31
+ try {
32
+ const result = await $`openclaw pairing approve ${channel} ${code}`
33
+ respond(true, {ok: true, output: result.stdout.trim()})
34
+ } catch (err) {
35
+ const msg = err instanceof Error ? err.message : String(err)
36
+ api.logger.error(`pairing.approve: ${msg}`)
37
+ respond(false, undefined, {code: 'cli_error', message: msg})
38
+ }
39
+ })
40
+
41
+ api.logger.info('pairing: registered clawly.pairing.list + clawly.pairing.approve')
42
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@2en/clawly-plugins",
3
- "version": "1.17.5",
3
+ "version": "1.18.0",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "repository": {