@contextableai/clawg-ui 0.2.9 → 0.3.1

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@contextableai/clawg-ui",
3
- "version": "0.2.9",
3
+ "version": "0.3.1",
4
4
  "description": "AG-UI protocol channel plugin for OpenClaw — connect CopilotKit and AG-UI clients to your OpenClaw gateway",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -16,7 +16,14 @@
16
16
  "agent",
17
17
  "channel-plugin"
18
18
  ],
19
+ "main": "./dist/index.js",
20
+ "files": [
21
+ "dist",
22
+ "openclaw.plugin.json"
23
+ ],
19
24
  "scripts": {
25
+ "build": "tsc",
26
+ "prepublishOnly": "npm run build",
20
27
  "test": "vitest run"
21
28
  },
22
29
  "dependencies": {
@@ -27,11 +34,15 @@
27
34
  "openclaw": "*"
28
35
  },
29
36
  "devDependencies": {
37
+ "@types/node": "^25.3.5",
38
+ "commander": "^14.0.3",
39
+ "openclaw": "file:../openclaw",
40
+ "typescript": "^5.9.3",
30
41
  "vitest": "^3.0.0"
31
42
  },
32
43
  "openclaw": {
33
44
  "extensions": [
34
- "./index.ts"
45
+ "./dist/index.js"
35
46
  ],
36
47
  "channel": {
37
48
  "id": "clawg-ui",
package/CHANGELOG.md DELETED
@@ -1,105 +0,0 @@
1
- # Changelog
2
-
3
- ## 0.2.9 (2026-03-06)
4
-
5
- ### Fixed
6
- - Add `auth: "plugin"` to `registerHttpRoute` call — required by OpenClaw 2026.3.2; omitting it silently dropped the `/v1/clawg-ui` route, causing 404s
7
- - Pass `{ channel, accountId }` object to `readAllowFromStore` instead of a bare string — fixes 403 responses for approved devices after the pairing API changed in 2026.3.2
8
- - Add `pairing_code` and `bearer_token` at the root of the 403 pairing response alongside the existing nested `error.pairing` fields — restores compatibility with Kotlin `ClawgUIPairingResponse` clients expecting flat fields
9
- - Add diagnostic `console.log` for 400 responses to aid debugging of malformed requests
10
-
11
- ### Changed
12
- - README event table was missing `TOOL_CALL_ARGS` and `TOOL_CALL_RESULT`; `tools` field incorrectly said "reserved for future use"
13
- - Integration tests used the gateway token directly instead of an HMAC-signed device token, causing 401s against v0.2.0+ servers
14
- - "Missing auth" integration test expected 401 instead of 403 (pairing initiation)
15
-
16
- ### Added
17
- - "Tool call events" documentation section explaining client vs server tool flows and diagnostic tips
18
- - Unit tests for `handleBeforeToolCall` and `handleToolResultPersist` hook handlers (`src/tool-hooks.test.ts`)
19
- - Extracted hook handlers from `index.ts` into exported named functions for testability (no behavioral change)
20
- - Integration tests now accept `CLAWG_UI_DEVICE_TOKEN` or auto-generate one from `OPENCLAW_GATEWAY_TOKEN` + `CLAWG_UI_DEVICE_ID`
21
-
22
- ## Unreleased
23
-
24
- ## 0.2.8 (2026-02-26)
25
-
26
- ### Fixed
27
- - Remove literal `process.env` from a code comment in `http-handler.ts` that was itself triggering the security scanner — the comment documenting the v0.2.5/v0.2.6 fix contained the exact pattern the scanner flags
28
-
29
- ## 0.2.7 (2026-02-18)
30
-
31
- ### Fixed
32
- - Close open text messages before emitting `RUN_FINISHED` in `splitRunIfToolFired()` — fixes `AGUIError: Cannot send 'RUN_FINISHED' while text messages are still active` when text streaming is followed by a server-side tool call and then more text
33
-
34
- ## 0.2.6 (2026-02-10)
35
-
36
- ### Fixed
37
- - Move gateway secret resolution into its own module (`gateway-secret.ts`) so the HTTP handler file contains zero `process.env` references — eliminates plugin security scanner warning ("Environment variable access combined with network send")
38
-
39
- ## 0.2.5 (2026-02-10)
40
-
41
- ### Fixed
42
- - Resolve gateway secret at factory initialization time instead of per-request to eliminate plugin security scanner warning ("Environment variable access combined with network send")
43
-
44
- ## 0.2.4 (2026-02-06)
45
-
46
- ### Changed
47
- - Separate tool call events and text message events into distinct AG-UI runs — when text follows a tool call, the tool run is finished and a new run (with a unique runId) is started for the text messages
48
-
49
- ## 0.2.3 (2026-02-06)
50
-
51
- ### Fixed
52
- - Append `\n\n` paragraph joiner to streamed text deltas so chunks render with proper spacing
53
- - Include `runId` in all `TEXT_MESSAGE_START`, `TEXT_MESSAGE_CONTENT`, and `TEXT_MESSAGE_END` events for AG-UI protocol compliance
54
-
55
- ### Changed
56
- - Set channel defaults to `blockStreaming: true` and `chunkMode: "newline"` for correct paragraph-based streaming out of the box
57
- - Clean up multi-run logic for tool-call-then-text flows (single run per request)
58
-
59
- ## 0.2.2 (2026-02-05)
60
-
61
- ### Fixed
62
- - Include `messageId` in `TOOL_CALL_RESULT` events as required by AG-UI client v0.0.43 Zod schema
63
-
64
- ### Added
65
- - Debug logging throughout tool call flow for easier troubleshooting
66
-
67
- ## 0.2.1 (2026-02-05)
68
-
69
- ### Fixed
70
- - Return HTTP 429 `rate_limit` error when max pending pairing requests (3) is reached, instead of returning an empty pairing code
71
-
72
- ## 0.2.0 (2026-02-04)
73
-
74
- ### Added
75
- - **Device pairing authentication** - Secure per-device access control
76
- - HMAC-signed device tokens (no master token exposure)
77
- - Pairing approval workflow (`openclaw pairing approve clawg-ui <code>`)
78
- - New CLI command: `openclaw clawg-ui devices` - List approved devices
79
-
80
- ### Changed
81
- - **Breaking:** Direct bearer token authentication using `OPENCLAW_GATEWAY_TOKEN` is now deprecated and no longer supported. All clients must use device pairing.
82
-
83
- ### Security
84
- - Device tokens are HMAC-signed and do not expose the gateway's master secret
85
- - Pending pairing requests expire after 1 hour (max 3 per channel)
86
- - Each device requires explicit approval by the gateway owner
87
-
88
- ## 0.1.1 (2026-02-03)
89
-
90
- ### Changed
91
- - Endpoint path changed from `/v1/agui` to `/v1/clawg-ui`
92
- - Package name changed to `@contextableai/clawg-ui`
93
-
94
- ## 0.1.0 (2026-02-02)
95
-
96
- Initial release.
97
-
98
- - AG-UI protocol endpoint at `/v1/agui` for OpenClaw gateway
99
- - SSE streaming of agent responses as AG-UI events (`RUN_STARTED`, `TEXT_MESSAGE_START`, `TEXT_MESSAGE_CONTENT`, `TEXT_MESSAGE_END`, `TOOL_CALL_START`, `TOOL_CALL_END`, `RUN_FINISHED`, `RUN_ERROR`)
100
- - Bearer token authentication using the gateway token
101
- - Content negotiation via `@ag-ui/encoder` (SSE and protobuf support)
102
- - Standard OpenClaw channel plugin (`agui`) for gateway status visibility
103
- - Agent routing via `X-OpenClaw-Agent-Id` header
104
- - Abort on client disconnect
105
- - Compatible with `@ag-ui/client` `HttpAgent`, CopilotKit, and any AG-UI consumer
package/clawgui.png DELETED
Binary file
package/index.ts DELETED
@@ -1,182 +0,0 @@
1
- import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
2
- import type { Command } from "commander";
3
- import { emptyPluginConfigSchema } from "openclaw/plugin-sdk";
4
- import { randomUUID } from "node:crypto";
5
- import { EventType } from "@ag-ui/core";
6
- import { aguiChannelPlugin } from "./src/channel.js";
7
- import { createAguiHttpHandler } from "./src/http-handler.js";
8
- import { clawgUiToolFactory } from "./src/client-tools.js";
9
- import {
10
- getWriter,
11
- getMessageId,
12
- pushToolCallId,
13
- popToolCallId,
14
- isClientTool,
15
- setClientToolCalled,
16
- setToolFiredInRun,
17
- } from "./src/tool-store.js";
18
-
19
- // ---------------------------------------------------------------------------
20
- // Hook handlers — exported for testability
21
- // ---------------------------------------------------------------------------
22
-
23
- export interface BeforeToolCallEvent {
24
- toolName: string;
25
- params?: Record<string, unknown>;
26
- }
27
-
28
- export interface ToolCallContext {
29
- sessionKey?: string;
30
- }
31
-
32
- /**
33
- * Handles the `before_tool_call` OpenClaw hook.
34
- * Emits TOOL_CALL_START + TOOL_CALL_ARGS (and TOOL_CALL_END for client tools).
35
- */
36
- export function handleBeforeToolCall(
37
- event: BeforeToolCallEvent,
38
- ctx: ToolCallContext,
39
- ): void {
40
- const sk = ctx.sessionKey;
41
- console.log(
42
- `[clawg-ui] before_tool_call: tool=${event.toolName}, sessionKey=${sk ?? "none"}, hasParams=${!!(event.params && Object.keys(event.params).length > 0)}, params=${JSON.stringify(event.params ?? {})}`,
43
- );
44
- if (!sk) {
45
- console.log(`[clawg-ui] before_tool_call: skipping, no sessionKey`);
46
- return;
47
- }
48
- const writer = getWriter(sk);
49
- if (!writer) {
50
- console.log(
51
- `[clawg-ui] before_tool_call: skipping, no writer for sessionKey=${sk}`,
52
- );
53
- return;
54
- }
55
- const toolCallId = `tool-${randomUUID()}`;
56
- console.log(
57
- `[clawg-ui] before_tool_call: emitting TOOL_CALL_START, toolCallId=${toolCallId}`,
58
- );
59
- writer({
60
- type: EventType.TOOL_CALL_START,
61
- toolCallId,
62
- toolCallName: event.toolName,
63
- });
64
- setToolFiredInRun(sk);
65
- if (event.params && Object.keys(event.params).length > 0) {
66
- console.log(
67
- `[clawg-ui] before_tool_call: emitting TOOL_CALL_ARGS, params=${JSON.stringify(event.params)}`,
68
- );
69
- writer({
70
- type: EventType.TOOL_CALL_ARGS,
71
- toolCallId,
72
- delta: JSON.stringify(event.params),
73
- });
74
- }
75
-
76
- if (isClientTool(sk, event.toolName)) {
77
- // Client tool: emit TOOL_CALL_END now. The run will finish and the
78
- // client initiates a new run with the tool result.
79
- console.log(
80
- `[clawg-ui] before_tool_call: client tool detected, emitting TOOL_CALL_END immediately`,
81
- );
82
- writer({
83
- type: EventType.TOOL_CALL_END,
84
- toolCallId,
85
- });
86
- setClientToolCalled(sk);
87
- } else {
88
- // Server tool: push ID so tool_result_persist can emit
89
- // TOOL_CALL_RESULT + TOOL_CALL_END after execute() completes.
90
- console.log(
91
- `[clawg-ui] before_tool_call: server tool, pushing toolCallId to stack`,
92
- );
93
- pushToolCallId(sk, toolCallId);
94
- }
95
- }
96
-
97
- /**
98
- * Handles the `tool_result_persist` OpenClaw hook.
99
- * Emits TOOL_CALL_RESULT + TOOL_CALL_END for server-side tools.
100
- */
101
- export function handleToolResultPersist(
102
- event: Record<string, unknown>,
103
- ctx: ToolCallContext,
104
- ): void {
105
- const sk = ctx.sessionKey;
106
- console.log(
107
- `[clawg-ui] tool_result_persist: sessionKey=${sk ?? "none"}, event=${JSON.stringify(event)}`,
108
- );
109
- if (!sk) {
110
- console.log(
111
- `[clawg-ui] tool_result_persist: skipping, no sessionKey`,
112
- );
113
- return;
114
- }
115
- const writer = getWriter(sk);
116
- const toolCallId = popToolCallId(sk);
117
- const messageId = getMessageId(sk);
118
- console.log(
119
- `[clawg-ui] tool_result_persist: writer=${writer ? "present" : "missing"}, toolCallId=${toolCallId ?? "none"}, messageId=${messageId ?? "none"}`,
120
- );
121
- if (writer && toolCallId && messageId) {
122
- console.log(
123
- `[clawg-ui] tool_result_persist: emitting TOOL_CALL_RESULT and TOOL_CALL_END`,
124
- );
125
- writer({
126
- type: EventType.TOOL_CALL_RESULT,
127
- toolCallId,
128
- messageId,
129
- content: "",
130
- });
131
- writer({
132
- type: EventType.TOOL_CALL_END,
133
- toolCallId,
134
- });
135
- }
136
- }
137
-
138
- const plugin = {
139
- id: "clawg-ui",
140
- name: "CLAWG-UI",
141
- description: "AG-UI protocol endpoint for CopilotKit and HttpAgent clients",
142
- configSchema: emptyPluginConfigSchema(),
143
- register(api: OpenClawPluginApi) {
144
- api.registerChannel({ plugin: aguiChannelPlugin });
145
- api.registerTool(clawgUiToolFactory);
146
- api.registerHttpRoute({
147
- path: "/v1/clawg-ui",
148
- auth: "plugin",
149
- handler: createAguiHttpHandler(api),
150
- });
151
-
152
- api.on("before_tool_call", handleBeforeToolCall);
153
- api.on("tool_result_persist", handleToolResultPersist);
154
-
155
- // CLI commands for device management
156
- api.registerCli(
157
- ({ program }: { program: Command }) => {
158
- const clawgUi = program
159
- .command("clawg-ui")
160
- .description("CLAWG-UI (AG-UI) channel commands");
161
-
162
- clawgUi
163
- .command("devices")
164
- .description("List approved devices")
165
- .action(async () => {
166
- const devices = await api.runtime.channel.pairing.readAllowFromStore("clawg-ui");
167
- if (devices.length === 0) {
168
- console.log("No approved devices.");
169
- return;
170
- }
171
- console.log("Approved devices:");
172
- for (const deviceId of devices) {
173
- console.log(` ${deviceId}`);
174
- }
175
- });
176
- },
177
- { commands: ["clawg-ui"] },
178
- );
179
- },
180
- };
181
-
182
- export default plugin;
package/src/channel.ts DELETED
@@ -1,37 +0,0 @@
1
- import type { ChannelPlugin } from "openclaw/plugin-sdk";
2
-
3
- type ResolvedAguiAccount = {
4
- accountId: string;
5
- enabled: boolean;
6
- configured: boolean;
7
- };
8
-
9
- export const aguiChannelPlugin: ChannelPlugin<ResolvedAguiAccount> = {
10
- id: "clawg-ui",
11
- meta: {
12
- id: "clawg-ui",
13
- label: "AG-UI",
14
- selectionLabel: "AG-UI (CopilotKit / HttpAgent)",
15
- docsPath: "/channels/agui",
16
- docsLabel: "agui",
17
- blurb: "AG-UI protocol endpoint for CopilotKit and HttpAgent clients.",
18
- order: 90,
19
- },
20
- capabilities: {
21
- chatTypes: ["direct"],
22
- blockStreaming: true,
23
- },
24
- config: {
25
- listAccountIds: () => ["default"],
26
- resolveAccount: () => ({
27
- accountId: "default",
28
- enabled: true,
29
- configured: true,
30
- }),
31
- defaultAccountId: () => "default",
32
- },
33
- pairing: {
34
- idLabel: "clawgUiDeviceId",
35
- normalizeAllowEntry: (entry: string) => entry.replace(/^clawg-ui:/i, "").toLowerCase(),
36
- },
37
- };
@@ -1,51 +0,0 @@
1
- import { popTools } from "./tool-store.js";
2
-
3
- /**
4
- * Plugin tool factory registered via `api.registerTool`.
5
- * Receives the full `OpenClawPluginToolContext` including `sessionKey`,
6
- * so it's fully reentrant across concurrent requests.
7
- *
8
- * Returns AG-UI client-provided tools converted to agent tools,
9
- * or null if no client tools were stashed for this session.
10
- */
11
- export function clawgUiToolFactory(ctx: { sessionKey?: string }) {
12
- const sessionKey = ctx.sessionKey;
13
- console.log(`[clawg-ui] clawgUiToolFactory: sessionKey=${sessionKey ?? "none"}`);
14
- if (!sessionKey) {
15
- console.log(`[clawg-ui] clawgUiToolFactory: returning null, no sessionKey`);
16
- return null;
17
- }
18
- const clientTools = popTools(sessionKey);
19
- console.log(`[clawg-ui] clawgUiToolFactory: popped ${clientTools.length} client tools`);
20
- if (clientTools.length === 0) {
21
- console.log(`[clawg-ui] clawgUiToolFactory: returning null, no client tools`);
22
- return null;
23
- }
24
- console.log(`[clawg-ui] clawgUiToolFactory: creating ${clientTools.length} agent tools`);
25
- for (const t of clientTools) {
26
- console.log(`[clawg-ui] creating tool: name=${t.name}, description=${t.description ?? "(none)"}, hasParams=${!!t.parameters}, params=${JSON.stringify(t.parameters ?? {})}`);
27
- }
28
- return clientTools.map((t) => ({
29
- name: t.name,
30
- label: t.name,
31
- description: t.description,
32
- parameters: t.parameters ?? { type: "object", properties: {} },
33
- async execute(_toolCallId: string, args: unknown) {
34
- // Client-side tools are fire-and-forget per AG-UI protocol.
35
- // TOOL_CALL_START/ARGS/END are emitted by the before_tool_call hook.
36
- // The run ends, and the client initiates a new run with the tool result.
37
- // Return args so the agent loop can continue (the dispatcher will
38
- // suppress any text output after a client tool call).
39
- console.log(`[clawg-ui] client tool execute: name=${t.name}, args=${JSON.stringify(args)}`);
40
- return {
41
- content: [
42
- {
43
- type: "text" as const,
44
- text: JSON.stringify(args),
45
- },
46
- ],
47
- details: { clientTool: true, name: t.name, args },
48
- };
49
- },
50
- }));
51
- }
@@ -1,20 +0,0 @@
1
- import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
2
-
3
- /**
4
- * Resolve the gateway HMAC secret from config or environment variables.
5
- *
6
- * This lives in its own module so that the HTTP handler file contains zero
7
- * `process.env` references — plugin security scanners flag "env access +
8
- * network send" when both appear in the same source file.
9
- */
10
- export function resolveGatewaySecret(api: OpenClawPluginApi): string | null {
11
- const gatewayAuth = api.config.gateway?.auth;
12
- const secret =
13
- (gatewayAuth as Record<string, unknown> | undefined)?.token ??
14
- process.env.OPENCLAW_GATEWAY_TOKEN ??
15
- process.env.CLAWDBOT_GATEWAY_TOKEN;
16
- if (typeof secret === "string" && secret) {
17
- return secret;
18
- }
19
- return null;
20
- }