@contextableai/clawg-ui 0.3.3 → 0.4.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/README.md +22 -1
- package/dist/index.js +6 -1
- package/dist/src/http-handler.d.ts +1 -0
- package/dist/src/http-handler.js +37 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -133,9 +133,30 @@ function App() {
|
|
|
133
133
|
}
|
|
134
134
|
```
|
|
135
135
|
|
|
136
|
+
## Agent discovery (`/info`)
|
|
137
|
+
|
|
138
|
+
The plugin registers a `/v1/clawg-ui/info` endpoint that CopilotKit and other AG-UI clients use to discover available agents. Accepts GET or POST.
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
curl http://localhost:18789/v1/clawg-ui/info \
|
|
142
|
+
-H "Authorization: Bearer <device-token>"
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Response:
|
|
146
|
+
|
|
147
|
+
```json
|
|
148
|
+
{
|
|
149
|
+
"agents": {
|
|
150
|
+
"main": { "name": "main", "description": "Default agent" }
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
The response reflects the agents configured in OpenClaw's `agents.list` config. If no agents are configured, a default `"main"` agent is returned.
|
|
156
|
+
|
|
136
157
|
## Request format
|
|
137
158
|
|
|
138
|
-
The endpoint accepts a POST with a JSON body matching the AG-UI `RunAgentInput` schema:
|
|
159
|
+
The run endpoint accepts a POST with a JSON body matching the AG-UI `RunAgentInput` schema:
|
|
139
160
|
|
|
140
161
|
| Field | Type | Required | Description |
|
|
141
162
|
|---|---|---|---|
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { emptyPluginConfigSchema } from "openclaw/plugin-sdk";
|
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
3
|
import { EventType } from "@ag-ui/core";
|
|
4
4
|
import { aguiChannelPlugin } from "./src/channel.js";
|
|
5
|
-
import { createAguiHttpHandler } from "./src/http-handler.js";
|
|
5
|
+
import { createAguiHttpHandler, createAguiInfoHandler } from "./src/http-handler.js";
|
|
6
6
|
import { clawgUiToolFactory } from "./src/client-tools.js";
|
|
7
7
|
import { getWriter, getMessageId, pushToolCallId, popToolCallId, isClientTool, setClientToolCalled, setToolFiredInRun, } from "./src/tool-store.js";
|
|
8
8
|
/**
|
|
@@ -97,6 +97,11 @@ const plugin = {
|
|
|
97
97
|
auth: "plugin",
|
|
98
98
|
handler: createAguiHttpHandler(api),
|
|
99
99
|
});
|
|
100
|
+
api.registerHttpRoute({
|
|
101
|
+
path: "/v1/clawg-ui/info",
|
|
102
|
+
auth: "plugin",
|
|
103
|
+
handler: createAguiInfoHandler(api),
|
|
104
|
+
});
|
|
100
105
|
api.on("before_tool_call", handleBeforeToolCall);
|
|
101
106
|
api.on("tool_result_persist", handleToolResultPersist);
|
|
102
107
|
// CLI commands for device management
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
2
|
import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
|
|
3
3
|
export declare function createAguiHttpHandler(api: OpenClawPluginApi): (req: IncomingMessage, res: ServerResponse) => Promise<void>;
|
|
4
|
+
export declare function createAguiInfoHandler(api: OpenClawPluginApi): (_req: IncomingMessage, res: ServerResponse) => Promise<void>;
|
package/dist/src/http-handler.js
CHANGED
|
@@ -12,8 +12,8 @@ function sendJson(res, status, body) {
|
|
|
12
12
|
res.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
13
13
|
res.end(JSON.stringify(body));
|
|
14
14
|
}
|
|
15
|
-
function sendMethodNotAllowed(res) {
|
|
16
|
-
res.setHeader("Allow",
|
|
15
|
+
function sendMethodNotAllowed(res, allow = "POST") {
|
|
16
|
+
res.setHeader("Allow", allow);
|
|
17
17
|
res.statusCode = 405;
|
|
18
18
|
res.setHeader("Content-Type", "text/plain; charset=utf-8");
|
|
19
19
|
res.end("Method Not Allowed");
|
|
@@ -254,6 +254,13 @@ export function createAguiHttpHandler(api) {
|
|
|
254
254
|
});
|
|
255
255
|
return;
|
|
256
256
|
}
|
|
257
|
+
// CopilotKit single-transport sends { method: "info" } to the main URL
|
|
258
|
+
if (body &&
|
|
259
|
+
typeof body === "object" &&
|
|
260
|
+
body.method === "info") {
|
|
261
|
+
sendJson(res, 200, buildAgentsResponse(runtime));
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
257
264
|
const input = body;
|
|
258
265
|
const threadId = input.threadId || `clawg-ui-${randomUUID()}`;
|
|
259
266
|
const runId = input.runId || `clawg-ui-run-${randomUUID()}`;
|
|
@@ -551,3 +558,31 @@ export function createAguiHttpHandler(api) {
|
|
|
551
558
|
}
|
|
552
559
|
};
|
|
553
560
|
}
|
|
561
|
+
// ---------------------------------------------------------------------------
|
|
562
|
+
// /info handler — agent discovery for CopilotKit
|
|
563
|
+
// ---------------------------------------------------------------------------
|
|
564
|
+
function buildAgentsResponse(runtime) {
|
|
565
|
+
const cfg = runtime.config.loadConfig();
|
|
566
|
+
const agentList = cfg
|
|
567
|
+
.agents?.list ?? [];
|
|
568
|
+
const agents = {};
|
|
569
|
+
for (const agent of agentList) {
|
|
570
|
+
const name = agent.name ?? agent.id;
|
|
571
|
+
agents[agent.id] = { name, description: name };
|
|
572
|
+
}
|
|
573
|
+
// If no agents configured, expose a default "main" agent
|
|
574
|
+
if (Object.keys(agents).length === 0) {
|
|
575
|
+
agents["main"] = { name: "main", description: "Default agent" };
|
|
576
|
+
}
|
|
577
|
+
return { agents };
|
|
578
|
+
}
|
|
579
|
+
export function createAguiInfoHandler(api) {
|
|
580
|
+
const runtime = api.runtime;
|
|
581
|
+
return async function handleAguiInfo(_req, res) {
|
|
582
|
+
if (_req.method !== "GET" && _req.method !== "POST") {
|
|
583
|
+
sendMethodNotAllowed(res, "GET, POST");
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
sendJson(res, 200, buildAgentsResponse(runtime));
|
|
587
|
+
};
|
|
588
|
+
}
|
package/package.json
CHANGED