@contextableai/clawg-ui 0.4.3 → 0.4.5
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/dist/src/http-handler.js +15 -0
- package/package.json +1 -1
package/dist/src/http-handler.js
CHANGED
|
@@ -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, {
|
|
@@ -401,6 +415,7 @@ export function createAguiHttpHandler(api) {
|
|
|
401
415
|
});
|
|
402
416
|
const ctxPayload = runtime.channel.reply.finalizeInboundContext({
|
|
403
417
|
Body: envelopedBody,
|
|
418
|
+
BodyForAgent: contextSuffix ? envelopedBody + contextSuffix : undefined,
|
|
404
419
|
RawBody: messageBody,
|
|
405
420
|
CommandBody: messageBody,
|
|
406
421
|
From: `clawg-ui:${deviceId}`,
|
package/package.json
CHANGED