@dhf-openclaw/grix 0.4.9 → 0.4.11

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dhf-openclaw/grix",
3
- "version": "0.4.9",
4
- "description": "Connect OpenClaw to grix.dhf.pub for OpenClaw website management with mobile PWA support",
3
+ "version": "0.4.11",
4
+ "description": "Unified Grix OpenClaw plugin with channel transport, typed admin tools, and operator CLI",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "exports": {
@@ -28,9 +28,7 @@
28
28
  "README.md",
29
29
  "openclaw.plugin.json",
30
30
  "dist/index.js",
31
- "skills/message-send/SKILL.md",
32
- "skills/message-unsend/SKILL.md",
33
- "skills/message-unsend/flowchart.mermaid"
31
+ "skills"
34
32
  ],
35
33
  "publishConfig": {
36
34
  "access": "public",
@@ -44,7 +42,7 @@
44
42
  "publish:npm": "npm run publish:npm:preview",
45
43
  "publish:npm:preview": "bash ./scripts/publish_npm.sh",
46
44
  "publish:npm:release": "bash ./scripts/publish_npm.sh --publish",
47
- "test": "node --test src/*.test.ts"
45
+ "test": "node --test src/*.test.ts src/admin/*.test.ts"
48
46
  },
49
47
  "devDependencies": {
50
48
  "esbuild": "0.27.4",
@@ -0,0 +1,81 @@
1
+ ---
2
+ name: grix-admin
3
+ description: 负责 OpenClaw 本地配置与后续 agent 管理;支持接收 grix-register 交接参数直接落地,也支持在已有主密钥下新建 agent 再落地。
4
+ ---
5
+
6
+ # Grix Agent Admin
7
+
8
+ `grix-admin` 只负责本地配置和管理动作。支持两个入口模式,二选一执行。
9
+
10
+ ## Mode A: bind-local(来自 grix-register 的首次交接)
11
+
12
+ 输入参数(全必填):
13
+
14
+ 1. `mode=bind-local`
15
+ 2. `agent_name`
16
+ 3. `agent_id`
17
+ 4. `api_endpoint`
18
+ 5. `api_key`
19
+
20
+ 执行规则:
21
+
22
+ 1. 不做远端创建,直接执行本地绑定:
23
+
24
+ ```bash
25
+ scripts/grix_agent_bind.py configure-local-openclaw \
26
+ --agent-name <agent_name> \
27
+ --agent-id <agent_id> \
28
+ --api-endpoint '<api_endpoint>' \
29
+ --api-key '<api_key>' \
30
+ --apply
31
+ ```
32
+
33
+ 2. 可选执行检查:
34
+
35
+ ```bash
36
+ scripts/grix_agent_bind.py inspect-local-openclaw --agent-name <agent_name>
37
+ ```
38
+
39
+ ## Mode B: create-and-bind(已有主密钥时的后续管理)
40
+
41
+ 输入参数:
42
+
43
+ 1. `agentName`(必填):`^[a-z][a-z0-9-]{2,31}$`
44
+ 2. `describeMessageTool`(必填):`actions` 非空
45
+ 3. `accountId`(可选)
46
+ 4. `avatarUrl`(可选)
47
+
48
+ 执行规则:
49
+
50
+ 1. 先检查 `~/.openclaw/openclaw.json` 的 `channels.grix.apiKey`。
51
+ 2. 若缺失或为空,说明主通道还没完成,不做本模式,立刻切回 `grix-register`。
52
+ 3. 若已存在,再调用 `grix_agent_admin` 创建远端 agent(仅一次,不自动重试)。
53
+ 4. 创建成功后,执行本地绑定命令(同 Mode A)。
54
+
55
+ ## Guardrails(两种模式都适用)
56
+
57
+ 1. Never ask user for website account/password.
58
+ 2. `bind-local` 模式禁止再次回调 `grix-register`,避免循环路由。
59
+ 3. 远端创建(Mode B)视为非幂等,不确认不自动重试。
60
+ 4. 完整 `api_key` 仅一次性回传,不要重复明文回显。
61
+ 5. 本地 `--apply` 没成功前,不得宣称配置完成。
62
+
63
+ ## Error Handling Rules
64
+
65
+ 1. `bind-local` 缺少字段:明确指出缺哪个字段并停止。
66
+ 2. invalid name(Mode B):要求用户提供合法小写英文名。
67
+ 3. `403/20011`:提示 owner 授权 `agent.api.create`。
68
+ 4. `401/10001`:检查本地 `agent_api_key` 或 grix 账号配置。
69
+ 5. `409/20002`:要求更换 agent 名称。
70
+ 6. 本地 apply 失败:返回失败命令与结果并停止。
71
+
72
+ ## Response Style
73
+
74
+ 1. 明确写出当前执行的是 `bind-local` 还是 `create-and-bind`。
75
+ 2. 分阶段汇报:远端(如有)+ 本地绑定。
76
+ 3. 明确说明本地是否已生效,失败则给具体原因。
77
+
78
+ ## References
79
+
80
+ 1. [references/api-contract.md](references/api-contract.md)
81
+ 2. [scripts/grix_agent_bind.py](scripts/grix_agent_bind.py)
@@ -0,0 +1,106 @@
1
+ # API Contract
2
+
3
+ ## Purpose
4
+
5
+ `grix-admin` 负责本地绑定,支持两种入口:
6
+
7
+ 1. `bind-local`:接收 `grix-register` 交接参数,直接本地绑定。
8
+ 2. `create-and-bind`:在已有主密钥下先远端创建,再本地绑定。
9
+
10
+ ## Base Rules
11
+
12
+ 1. Base path: `/v1/agent-api`
13
+ 2. Auth: `Authorization: Bearer <agent_api_key>`
14
+ 3. Caller must be `provider_type=3` and `status=active`.
15
+ 4. Route must pass scope middleware before service business checks.
16
+ 5. Do not ask users to provide website account/password for this flow.
17
+
18
+ ## Action Mapping (create-and-bind only)
19
+
20
+ | Tool | Method | Route | Required Scope |
21
+ |---|---|---|---|
22
+ | `grix_agent_admin` | `POST` | `/agents/create` | `agent.api.create` |
23
+
24
+ ## Payload Template
25
+
26
+ ```json
27
+ {
28
+ "agentName": "ops-assistant",
29
+ "avatarUrl": "https://example.com/avatar.png",
30
+ "describeMessageTool": {
31
+ "actions": ["unsend", "delete"]
32
+ }
33
+ }
34
+ ```
35
+
36
+ `agentName` validation rule for this skill:
37
+
38
+ - regex: `^[a-z][a-z0-9-]{2,31}$`
39
+ - only lowercase English letters, digits, and hyphen
40
+
41
+ `describeMessageTool` is required and must align with OpenClaw SDK discovery shape (`actions` required, optional `capabilities` and `schema`).
42
+
43
+ ## Success Payload Highlights
44
+
45
+ ```json
46
+ {
47
+ "code": 0,
48
+ "data": {
49
+ "id": "2029786829095440384",
50
+ "agent_name": "ops-assistant",
51
+ "provider_type": 3,
52
+ "api_endpoint": "ws://host/v1/agent-api/ws?agent_id=2029786829095440384",
53
+ "api_key": "ak_2029786829095440384_xxx",
54
+ "api_key_hint": "xxxxxx12"
55
+ }
56
+ }
57
+ ```
58
+
59
+ ## Error Matrix
60
+
61
+ | HTTP/BizCode | Meaning | Skill Response |
62
+ |---|---|---|
63
+ | `403/20011` | `agent.api.create` scope missing | Ask owner to grant scope |
64
+ | `401/10001` | invalid or missing auth | Check `api_key` and account config |
65
+ | `403/10002` | caller agent inactive / invalid provider | Ask owner to activate caller agent |
66
+ | `409/20002` | duplicate agent name | Ask user for another `agent_name` |
67
+ | `400/20004` | owner quota exceeded | Ask owner to clean up unused agents |
68
+ | `400/10003` | invalid payload | Ask for corrected parameters |
69
+
70
+ ## Retry Policy
71
+
72
+ 1. Never auto-retry `agent_api_create` unless user explicitly confirms.
73
+ 2. Do not retry scope/auth/parameter failures.
74
+ 3. Network transient errors can be retried once after explicit confirmation.
75
+
76
+ ## Post-Create Handover
77
+
78
+ After `code=0` (or when using `bind-local` mode), continue with local OpenClaw binding via bundled script:
79
+
80
+ 1. apply local changes directly:
81
+ - `scripts/grix_agent_bind.py configure-local-openclaw --agent-name <agent_name> --agent-id <agent_id> --api-endpoint '<api_endpoint>' --api-key '<api_key>' --apply`
82
+ 2. optionally run inspect after apply when you need state verification:
83
+ - `scripts/grix_agent_bind.py inspect-local-openclaw --agent-name <agent_name>`
84
+
85
+ Local apply writes:
86
+
87
+ 1. `agents.list` entry
88
+ 2. `channels.grix.accounts.<agent_name>` entry
89
+ 3. `bindings` route for `channel=grix`
90
+ 4. required tools config and gateway restart
91
+
92
+ ## bind-local Input Contract
93
+
94
+ When called from `grix-register`, `grix-admin` should accept:
95
+
96
+ ```json
97
+ {
98
+ "mode": "bind-local",
99
+ "agent_name": "grix-main",
100
+ "agent_id": "2029786829095440384",
101
+ "api_endpoint": "wss://grix.dhf.pub/v1/agent-api/ws?agent_id=2029786829095440384",
102
+ "api_key": "ak_xxx"
103
+ }
104
+ ```
105
+
106
+ In this mode, skip remote create and execute local bind directly.