@artooi/ag-ui-web-component 0.2.0 → 0.2.2
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/CHANGELOG.md +55 -1
- package/README.md +15 -5
- package/dist/ag-ui-web-component.bundle.js +28 -25
- package/dist/ag-ui-web-component.bundle.js.map +3 -3
- package/dist/core/ag_ui_chat.d.ts +9 -0
- package/dist/core/ag_ui_chat.d.ts.map +1 -1
- package/dist/core/agui_client.d.ts +13 -0
- package/dist/core/agui_client.d.ts.map +1 -1
- package/dist/index.js +118 -23
- package/dist/index.js.map +2 -2
- package/dist/tools/route_map.d.ts.map +1 -1
- package/dist/tools/state_hook.d.ts.map +1 -1
- package/dist/ui/styles.d.ts +1 -1
- package/dist/ui/styles.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/core/ag_ui_chat.ts +116 -18
- package/src/core/agui_client.ts +18 -0
- package/src/tools/route_map.ts +3 -2
- package/src/tools/state_hook.ts +12 -3
- package/src/ui/styles.ts +4 -1
- package/src/version.ts +1 -1
|
@@ -91,6 +91,15 @@ export declare class AgUiChat extends HTMLElement {
|
|
|
91
91
|
* this from the current page; a missing placeholder blocks the send.
|
|
92
92
|
*/
|
|
93
93
|
skillContext: () => Record<string, unknown>;
|
|
94
|
+
/**
|
|
95
|
+
* Friendly display labels for tool-call cards, keyed by tool name (e.g.
|
|
96
|
+
* `{ list_projects: "Search projects" }`). Used as a fallback when a tool has
|
|
97
|
+
* no `x-summary` in its own schema — chiefly **server-side tools** (drf-mcp,
|
|
98
|
+
* `@tool` registry), whose schema never reaches the browser (AG-UI streams
|
|
99
|
+
* only the tool-call name). Client tools should prefer `x-summary` on their
|
|
100
|
+
* schema; this map is the seam for everything else.
|
|
101
|
+
*/
|
|
102
|
+
toolSummaries: Record<string, string>;
|
|
94
103
|
constructor();
|
|
95
104
|
/** Attributes whose late changes must reflect in already-rendered chrome. */
|
|
96
105
|
static get observedAttributes(): string[];
|
|
@@ -1 +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IA0Gf;;;;;;OAMG;IACH,aAAa,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,GAAG,cAAc;CAmVlE"}
|
|
@@ -40,8 +40,21 @@ export interface AgUiClientHandlers {
|
|
|
40
40
|
onTextEnd(buffer: string): void;
|
|
41
41
|
/** Fired when the agent finishes calling a tool (server- or frontend-side). */
|
|
42
42
|
onToolCall(call: AgUiToolCall): void;
|
|
43
|
+
/**
|
|
44
|
+
* Fired when a server-side tool's result streams back (AG-UI's
|
|
45
|
+
* `TOOL_CALL_RESULT`). Frontend tools don't emit this — the client supplies
|
|
46
|
+
* their result itself — so this is the channel for server-executed output.
|
|
47
|
+
*/
|
|
48
|
+
onToolResult(toolCallId: string, content: string): void;
|
|
43
49
|
onRunEnd(): void;
|
|
44
50
|
onError(message: string): void;
|
|
51
|
+
/**
|
|
52
|
+
* Fired exactly once when the whole interaction settles — after the run loop
|
|
53
|
+
* ends for any reason (a server-only round, frontend-tool rounds exhausted,
|
|
54
|
+
* or an error). The terminal guarantee that the UI returns to rest (pending
|
|
55
|
+
* indicator cleared, input re-enabled) no matter how the run finished.
|
|
56
|
+
*/
|
|
57
|
+
onSettled(): void;
|
|
45
58
|
}
|
|
46
59
|
/**
|
|
47
60
|
* Provider of the per-run frontend tool catalog and context. Both are read
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agui_client.d.ts","sourceRoot":"","sources":["../../src/core/agui_client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAoC,MAAM,eAAe,CAAC;AACrF,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAG1D,8DAA8D;AAC9D,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,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AErB;IAED,wEAAwE;IACxE,IAAI,QAAQ,IAAI,SAAS,OAAO,EAAE,CAEjC;IAED;;;;;;OAMG;IACG,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAM1C;;;;OAIG;IACG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAI7B,0EAA0E;IAC1E,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;CAoFzD"}
|
package/dist/index.js
CHANGED
|
@@ -143,7 +143,7 @@ function createRouteTools(getRouteMap, getNavigate) {
|
|
|
143
143
|
{
|
|
144
144
|
name: "list_routes",
|
|
145
145
|
description: "List the routes the app can navigate to. Each route's `pathParams` names the dynamic segments to pass as `params` to `navigate_to_route`.",
|
|
146
|
-
parameters: { type: "object", properties: {}, required: [] },
|
|
146
|
+
parameters: { type: "object", properties: {}, required: [], [X_SUMMARY_KEY]: "List pages" },
|
|
147
147
|
handler: () => getRouteMap().map((route) => ({ ...route, pathParams: pathParamNames(route.path) }))
|
|
148
148
|
},
|
|
149
149
|
{
|
|
@@ -156,7 +156,8 @@ function createRouteTools(getRouteMap, getNavigate) {
|
|
|
156
156
|
params: { type: "object" }
|
|
157
157
|
},
|
|
158
158
|
required: ["route_id"],
|
|
159
|
-
[X_NAVIGATES_KEY]: true
|
|
159
|
+
[X_NAVIGATES_KEY]: true,
|
|
160
|
+
[X_SUMMARY_KEY]: "Navigate"
|
|
160
161
|
},
|
|
161
162
|
handler: (args) => {
|
|
162
163
|
const routeId = args["route_id"];
|
|
@@ -185,7 +186,12 @@ function createStateHookTools(hook) {
|
|
|
185
186
|
{
|
|
186
187
|
name: `read_${hook.name}`,
|
|
187
188
|
description: `Read the "${hook.name}" state.`,
|
|
188
|
-
parameters: {
|
|
189
|
+
parameters: {
|
|
190
|
+
type: "object",
|
|
191
|
+
properties: {},
|
|
192
|
+
required: [],
|
|
193
|
+
[X_SUMMARY_KEY]: `Read ${hook.name}`
|
|
194
|
+
},
|
|
189
195
|
handler: () => hook.read()
|
|
190
196
|
}
|
|
191
197
|
];
|
|
@@ -194,7 +200,11 @@ function createStateHookTools(hook) {
|
|
|
194
200
|
tools.push({
|
|
195
201
|
name: `set_${hook.name}`,
|
|
196
202
|
description: `Update the "${hook.name}" state.`,
|
|
197
|
-
parameters: {
|
|
203
|
+
parameters: {
|
|
204
|
+
...hook.schema ?? { type: "object" },
|
|
205
|
+
[X_DESTRUCTIVE_KEY]: true,
|
|
206
|
+
[X_SUMMARY_KEY]: `Update ${hook.name}`
|
|
207
|
+
},
|
|
198
208
|
handler: (args) => write(args)
|
|
199
209
|
});
|
|
200
210
|
}
|
|
@@ -3145,7 +3155,10 @@ var STYLES = `
|
|
|
3145
3155
|
}
|
|
3146
3156
|
|
|
3147
3157
|
/* \u2500\u2500 Incoming-text animations (data-text-animation) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
3148
|
-
|
|
3158
|
+
/* .message--restored (rehydrated history) is excluded: entrance animations are
|
|
3159
|
+
for freshly-arriving messages, not the whole transcript replaying on reload.
|
|
3160
|
+
Word mode is excluded implicitly \u2014 restored bubbles aren't wrapped. */
|
|
3161
|
+
:host([data-text-animation="fade"]) .message--assistant:not(.message--restored) {
|
|
3149
3162
|
animation: ag-ui-msg-fade 0.25s ease both;
|
|
3150
3163
|
}
|
|
3151
3164
|
|
|
@@ -3669,6 +3682,8 @@ var AgUiClient = class {
|
|
|
3669
3682
|
await this.#runLoop();
|
|
3670
3683
|
} catch (error) {
|
|
3671
3684
|
this.#handlers.onError(error instanceof Error ? error.message : String(error));
|
|
3685
|
+
} finally {
|
|
3686
|
+
this.#handlers.onSettled();
|
|
3672
3687
|
}
|
|
3673
3688
|
}
|
|
3674
3689
|
async #runLoop() {
|
|
@@ -3726,6 +3741,9 @@ var AgUiClient = class {
|
|
|
3726
3741
|
pending.push(call);
|
|
3727
3742
|
h.onToolCall(call);
|
|
3728
3743
|
},
|
|
3744
|
+
onToolCallResultEvent({ event }) {
|
|
3745
|
+
h.onToolResult(event.toolCallId, event.content);
|
|
3746
|
+
},
|
|
3729
3747
|
onRunErrorEvent({ event }) {
|
|
3730
3748
|
h.onError(event.message);
|
|
3731
3749
|
},
|
|
@@ -3877,9 +3895,24 @@ var AgUiChat = class extends HTMLElement {
|
|
|
3877
3895
|
* this from the current page; a missing placeholder blocks the send.
|
|
3878
3896
|
*/
|
|
3879
3897
|
skillContext = () => ({});
|
|
3898
|
+
/**
|
|
3899
|
+
* Friendly display labels for tool-call cards, keyed by tool name (e.g.
|
|
3900
|
+
* `{ list_projects: "Search projects" }`). Used as a fallback when a tool has
|
|
3901
|
+
* no `x-summary` in its own schema — chiefly **server-side tools** (drf-mcp,
|
|
3902
|
+
* `@tool` registry), whose schema never reaches the browser (AG-UI streams
|
|
3903
|
+
* only the tool-call name). Client tools should prefer `x-summary` on their
|
|
3904
|
+
* schema; this map is the seam for everything else.
|
|
3905
|
+
*/
|
|
3906
|
+
toolSummaries = {};
|
|
3880
3907
|
#toolRegistry = new ClientToolRegistry();
|
|
3881
3908
|
/** Tool-call cards awaiting execution, keyed by call id. */
|
|
3882
3909
|
#toolCards = /* @__PURE__ */ new Map();
|
|
3910
|
+
/**
|
|
3911
|
+
* Call ids whose card was already settled from a streamed server-side result
|
|
3912
|
+
* (`TOOL_CALL_RESULT`), so the post-run executeTool sweep doesn't overwrite
|
|
3913
|
+
* the real output with the generic "executed on the server" fallback.
|
|
3914
|
+
*/
|
|
3915
|
+
#serverSettled = /* @__PURE__ */ new Set();
|
|
3883
3916
|
#root;
|
|
3884
3917
|
#chat;
|
|
3885
3918
|
#messages;
|
|
@@ -3890,6 +3923,10 @@ var AgUiChat = class extends HTMLElement {
|
|
|
3890
3923
|
#skillHint;
|
|
3891
3924
|
#client = null;
|
|
3892
3925
|
#streamingBubble = null;
|
|
3926
|
+
// Text deltas applied to the current streaming bubble. >1 ⇒ the message
|
|
3927
|
+
// revealed progressively as it streamed, so the word reveal must not re-animate
|
|
3928
|
+
// it; ≤1 ⇒ it arrived at once and the word reveal is appropriate.
|
|
3929
|
+
#streamDeltas = 0;
|
|
3893
3930
|
#pending = null;
|
|
3894
3931
|
#threadId = "";
|
|
3895
3932
|
#initialMessages = [];
|
|
@@ -3949,7 +3986,12 @@ var AgUiChat = class extends HTMLElement {
|
|
|
3949
3986
|
{
|
|
3950
3987
|
name: "read_page",
|
|
3951
3988
|
description: "Read the current page's structure (fields, buttons, route). Call after acting to observe the result within the same turn.",
|
|
3952
|
-
parameters: {
|
|
3989
|
+
parameters: {
|
|
3990
|
+
type: "object",
|
|
3991
|
+
properties: {},
|
|
3992
|
+
required: [],
|
|
3993
|
+
[X_SUMMARY_KEY]: "Read the page"
|
|
3994
|
+
},
|
|
3953
3995
|
handler: () => getPageMap()
|
|
3954
3996
|
}
|
|
3955
3997
|
];
|
|
@@ -4107,6 +4149,7 @@ var AgUiChat = class extends HTMLElement {
|
|
|
4107
4149
|
this.#streamingBubble = null;
|
|
4108
4150
|
this.#hidePending();
|
|
4109
4151
|
this.#toolCards.clear();
|
|
4152
|
+
this.#serverSettled.clear();
|
|
4110
4153
|
this.#initialMessages = [];
|
|
4111
4154
|
this.#messages.replaceChildren();
|
|
4112
4155
|
this.#threadId = this.conversationStore.threadId();
|
|
@@ -4130,16 +4173,53 @@ var AgUiChat = class extends HTMLElement {
|
|
|
4130
4173
|
await this.#resumeFrom(checkpoint);
|
|
4131
4174
|
}
|
|
4132
4175
|
}
|
|
4133
|
-
/**
|
|
4176
|
+
/**
|
|
4177
|
+
* Replay a restored message: text bubbles *and* tool activity. An assistant
|
|
4178
|
+
* turn may carry `toolCalls` (rendered as cards) and/or text; a `tool` turn
|
|
4179
|
+
* carries a result that settles the matching card. So a refreshed page shows
|
|
4180
|
+
* the full transcript — tool calls and their results — not just the prose.
|
|
4181
|
+
*/
|
|
4134
4182
|
#renderHistoricMessage(message) {
|
|
4135
|
-
|
|
4183
|
+
const text2 = typeof message.content === "string" ? message.content : "";
|
|
4184
|
+
if (message.role === MESSAGE_ROLE.USER) {
|
|
4185
|
+
if (text2 !== "") {
|
|
4186
|
+
this.appendMessage(MESSAGE_ROLE.USER, text2);
|
|
4187
|
+
}
|
|
4136
4188
|
return;
|
|
4137
4189
|
}
|
|
4138
|
-
if (message.role === MESSAGE_ROLE.
|
|
4139
|
-
|
|
4140
|
-
|
|
4141
|
-
|
|
4190
|
+
if (message.role === MESSAGE_ROLE.ASSISTANT) {
|
|
4191
|
+
if (text2 !== "") {
|
|
4192
|
+
this.appendMessage(MESSAGE_ROLE.ASSISTANT, text2).classList.add("message--restored");
|
|
4193
|
+
}
|
|
4194
|
+
const toolCalls = message.toolCalls;
|
|
4195
|
+
if (toolCalls !== void 0) {
|
|
4196
|
+
for (const call of toolCalls) {
|
|
4197
|
+
this.#cardFor({
|
|
4198
|
+
id: call.id,
|
|
4199
|
+
name: call.function.name,
|
|
4200
|
+
args: this.#parseArgs(call.function.arguments)
|
|
4201
|
+
});
|
|
4202
|
+
}
|
|
4203
|
+
}
|
|
4204
|
+
return;
|
|
4205
|
+
}
|
|
4206
|
+
if (message.role === "tool") {
|
|
4207
|
+
const card = this.#toolCards.get(message.toolCallId);
|
|
4208
|
+
if (card !== void 0) {
|
|
4209
|
+
card.settle(TOOL_CALL_STATUS.DONE, message.content);
|
|
4210
|
+
}
|
|
4211
|
+
}
|
|
4212
|
+
}
|
|
4213
|
+
/** Parse a tool call's JSON `arguments` string from history into an object. */
|
|
4214
|
+
#parseArgs(raw) {
|
|
4215
|
+
try {
|
|
4216
|
+
const parsed = JSON.parse(raw);
|
|
4217
|
+
if (typeof parsed === "object" && parsed !== null) {
|
|
4218
|
+
return parsed;
|
|
4219
|
+
}
|
|
4220
|
+
} catch {
|
|
4142
4221
|
}
|
|
4222
|
+
return {};
|
|
4143
4223
|
}
|
|
4144
4224
|
/**
|
|
4145
4225
|
* Word-by-word reveal for the `word` text-animation mode, applied to a
|
|
@@ -4305,8 +4385,9 @@ var AgUiChat = class extends HTMLElement {
|
|
|
4305
4385
|
this.#toolCards.delete(call.id);
|
|
4306
4386
|
const tool = this.#resolveTool(call.name);
|
|
4307
4387
|
if (tool === null) {
|
|
4308
|
-
|
|
4309
|
-
|
|
4388
|
+
if (!this.#serverSettled.has(call.id)) {
|
|
4389
|
+
card.settle(TOOL_CALL_STATUS.DONE, "No result returned.");
|
|
4390
|
+
}
|
|
4310
4391
|
return null;
|
|
4311
4392
|
}
|
|
4312
4393
|
if (await this.#needsConfirmation(call, tool)) {
|
|
@@ -4358,15 +4439,27 @@ var AgUiChat = class extends HTMLElement {
|
|
|
4358
4439
|
onTextDelta: (buffer) => {
|
|
4359
4440
|
this.#hidePending();
|
|
4360
4441
|
this.#streamInto(buffer);
|
|
4442
|
+
this.#streamDeltas += 1;
|
|
4361
4443
|
},
|
|
4362
4444
|
onTextEnd: (buffer) => {
|
|
4363
|
-
this.#
|
|
4445
|
+
const bubble = this.#streamInto(buffer);
|
|
4446
|
+
if (this.#streamDeltas <= 1) {
|
|
4447
|
+
this.#revealWords(bubble);
|
|
4448
|
+
}
|
|
4364
4449
|
this.#streamingBubble = null;
|
|
4365
4450
|
},
|
|
4366
4451
|
onToolCall: (call) => {
|
|
4367
4452
|
this.#hidePending();
|
|
4368
4453
|
this.#cardFor(call);
|
|
4369
4454
|
},
|
|
4455
|
+
onToolResult: (toolCallId, content) => {
|
|
4456
|
+
const card = this.#toolCards.get(toolCallId);
|
|
4457
|
+
if (card === void 0) {
|
|
4458
|
+
return;
|
|
4459
|
+
}
|
|
4460
|
+
card.settle(TOOL_CALL_STATUS.DONE, content);
|
|
4461
|
+
this.#serverSettled.add(toolCallId);
|
|
4462
|
+
},
|
|
4370
4463
|
onRunEnd: () => {
|
|
4371
4464
|
this.#hidePending();
|
|
4372
4465
|
this.#send.disabled = false;
|
|
@@ -4377,6 +4470,11 @@ var AgUiChat = class extends HTMLElement {
|
|
|
4377
4470
|
this.#revealWords(this.appendMessage(MESSAGE_ROLE.ASSISTANT, `\u26A0\uFE0F ${message}`));
|
|
4378
4471
|
this.#send.disabled = false;
|
|
4379
4472
|
this.#streamingBubble = null;
|
|
4473
|
+
},
|
|
4474
|
+
onSettled: () => {
|
|
4475
|
+
this.#hidePending();
|
|
4476
|
+
this.#send.disabled = false;
|
|
4477
|
+
this.#streamingBubble = null;
|
|
4380
4478
|
}
|
|
4381
4479
|
};
|
|
4382
4480
|
}
|
|
@@ -4410,6 +4508,7 @@ var AgUiChat = class extends HTMLElement {
|
|
|
4410
4508
|
#streamInto(buffer) {
|
|
4411
4509
|
if (this.#streamingBubble === null) {
|
|
4412
4510
|
this.#streamingBubble = this.appendMessage(MESSAGE_ROLE.ASSISTANT, "");
|
|
4511
|
+
this.#streamDeltas = 0;
|
|
4413
4512
|
}
|
|
4414
4513
|
this.#streamingBubble.innerHTML = renderMarkdown(buffer);
|
|
4415
4514
|
this.#messages.scrollTop = this.#messages.scrollHeight;
|
|
@@ -4426,13 +4525,9 @@ var AgUiChat = class extends HTMLElement {
|
|
|
4426
4525
|
if (existing !== void 0) {
|
|
4427
4526
|
return existing;
|
|
4428
4527
|
}
|
|
4429
|
-
const
|
|
4430
|
-
const
|
|
4431
|
-
|
|
4432
|
-
call.args,
|
|
4433
|
-
this.toolDisplay,
|
|
4434
|
-
typeof summary === "string" ? summary : void 0
|
|
4435
|
-
);
|
|
4528
|
+
const labelled = this.#resolveTool(call.name)?.parameters[X_SUMMARY_KEY];
|
|
4529
|
+
const summary = typeof labelled === "string" ? labelled : this.toolSummaries[call.name];
|
|
4530
|
+
const card = new ToolCallCard(call.name, call.args, this.toolDisplay, summary);
|
|
4436
4531
|
this.#toolCards.set(call.id, card);
|
|
4437
4532
|
this.#messages.appendChild(card.element);
|
|
4438
4533
|
this.#messages.scrollTop = this.#messages.scrollHeight;
|
|
@@ -4604,7 +4699,7 @@ function setControlValue(el, value) {
|
|
|
4604
4699
|
}
|
|
4605
4700
|
|
|
4606
4701
|
// src/version.ts
|
|
4607
|
-
var VERSION = "0.2.
|
|
4702
|
+
var VERSION = "0.2.2";
|
|
4608
4703
|
export {
|
|
4609
4704
|
AgUiChat,
|
|
4610
4705
|
AgUiClient,
|