@contextableai/clawg-ui 0.4.2 → 0.4.4

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.
@@ -154,6 +154,16 @@ function buildBodyFromMessages(messages) {
154
154
  };
155
155
  }
156
156
  // ---------------------------------------------------------------------------
157
+ // Format AG-UI context entries for the LLM prompt
158
+ // ---------------------------------------------------------------------------
159
+ function formatContextEntries(context) {
160
+ const entries = context.filter((c) => c.description || c.value);
161
+ if (entries.length === 0)
162
+ return undefined;
163
+ const parts = entries.map((c) => `### ${c.description}\n${c.value}`);
164
+ return `\n\n## Context provided by the UI\n\n${parts.join("\n\n")}`;
165
+ }
166
+ // ---------------------------------------------------------------------------
157
167
  // HTTP handler factory
158
168
  // ---------------------------------------------------------------------------
159
169
  export function createAguiHttpHandler(api) {
@@ -283,6 +293,10 @@ export function createAguiHttpHandler(api) {
283
293
  }
284
294
  // Build body from messages
285
295
  const { body: messageBody } = buildBodyFromMessages(messages);
296
+ // Format AG-UI context entries (if any) for injection into the agent prompt
297
+ const contextSuffix = Array.isArray(input.context) && input.context.length > 0
298
+ ? formatContextEntries(input.context)
299
+ : undefined;
286
300
  if (!messageBody.trim()) {
287
301
  console.log(`[clawg-ui] 400: empty extracted body, roles=[${messages.map((m) => m.role).join(",")}], contents=[${messages.map((m) => JSON.stringify(m.content)).join(",")}]`);
288
302
  sendJson(res, 400, {
@@ -295,10 +309,14 @@ export function createAguiHttpHandler(api) {
295
309
  }
296
310
  // Resolve agent route
297
311
  const cfg = runtime.config.loadConfig();
312
+ const agentIdHeader = typeof req.headers["x-openclaw-agent-id"] === "string"
313
+ ? req.headers["x-openclaw-agent-id"]
314
+ : undefined;
298
315
  const route = runtime.channel.routing.resolveAgentRoute({
299
316
  cfg,
300
317
  channel: "clawg-ui",
301
318
  peer: { kind: "dm", id: `clawg-ui-${threadId}` },
319
+ accountId: agentIdHeader,
302
320
  });
303
321
  // Set up SSE via EventEncoder
304
322
  const accept = typeof req.headers.accept === "string"
@@ -397,6 +415,7 @@ export function createAguiHttpHandler(api) {
397
415
  });
398
416
  const ctxPayload = runtime.channel.reply.finalizeInboundContext({
399
417
  Body: envelopedBody,
418
+ BodyForAgent: contextSuffix ? envelopedBody + contextSuffix : undefined,
400
419
  RawBody: messageBody,
401
420
  CommandBody: messageBody,
402
421
  From: `clawg-ui:${deviceId}`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contextableai/clawg-ui",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
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",