@artooi/ag-ui-web-component 0.2.2 → 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/CHANGELOG.md +57 -1
- package/README.md +14 -6
- package/dist/ag-ui-web-component.bundle.js +23 -23
- package/dist/ag-ui-web-component.bundle.js.map +4 -4
- package/dist/core/ag_ui_chat.d.ts +7 -0
- package/dist/core/ag_ui_chat.d.ts.map +1 -1
- package/dist/core/create_http_agent.d.ts +9 -0
- package/dist/core/create_http_agent.d.ts.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +91 -13
- package/dist/index.js.map +3 -3
- package/dist/tools/parse_tool_catalog.d.ts +19 -0
- package/dist/tools/parse_tool_catalog.d.ts.map +1 -0
- package/dist/ui/prettify_tool_name.d.ts +11 -0
- package/dist/ui/prettify_tool_name.d.ts.map +1 -0
- package/dist/ui/render_markdown.d.ts +10 -1
- package/dist/ui/render_markdown.d.ts.map +1 -1
- package/package.json +2 -3
- package/src/core/ag_ui_chat.ts +47 -5
- package/src/core/create_http_agent.ts +23 -2
- package/src/index.ts +3 -1
- package/src/tools/parse_tool_catalog.ts +36 -0
- package/src/ui/prettify_tool_name.ts +16 -0
- package/src/ui/render_markdown.ts +37 -11
- package/src/version.ts +1 -1
|
@@ -36,6 +36,13 @@ export declare class AgUiChat extends HTMLElement {
|
|
|
36
36
|
agentFactory: AgentFactory;
|
|
37
37
|
/** Extra HTTP headers for the AG-UI endpoint (e.g. CSRF). */
|
|
38
38
|
headers: Record<string, string>;
|
|
39
|
+
/**
|
|
40
|
+
* Permit `<img>` in rendered assistant markdown. **Off by default**: a
|
|
41
|
+
* model-controlled image URL is fetched with no user interaction, which
|
|
42
|
+
* makes it a zero-click exfiltration channel for prompt-injected page
|
|
43
|
+
* data. Enable only when the content source is trusted.
|
|
44
|
+
*/
|
|
45
|
+
allowImages: boolean;
|
|
39
46
|
/** When true, destructive tools execute without a confirmation modal. */
|
|
40
47
|
autoConfirm: boolean;
|
|
41
48
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ag_ui_chat.d.ts","sourceRoot":"","sources":["../../src/core/ag_ui_chat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAW,IAAI,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EACL,YAAY,EAOb,MAAM,iBAAiB,CAAC;AAGzB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,KAAK,UAAU,EAAsB,MAAM,kCAAkC,CAAC;AAGvF,OAAO,EAAwB,KAAK,OAAO,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"ag_ui_chat.d.ts","sourceRoot":"","sources":["../../src/core/ag_ui_chat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAW,IAAI,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EACL,YAAY,EAOb,MAAM,iBAAiB,CAAC;AAGzB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,KAAK,UAAU,EAAsB,MAAM,kCAAkC,CAAC;AAGvF,OAAO,EAAwB,KAAK,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE1E,OAAO,EAAoB,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACxE,OAAO,EAAwB,KAAK,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAO9E,OAAO,EAAgB,KAAK,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAO7E,OAAO,EACL,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EAE1B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,KAAK,YAAY,EAAmB,MAAM,wBAAwB,CAAC;AAE5E,8CAA8C;AAC9C,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,YAAY,CAAC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,OAAO,CAAC,CAAc;IAEzD;;;;;;;OAOG;IACH,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAM;;IAqD3C,6EAA6E;IAC7E,MAAM,KAAK,kBAAkB,IAAI,MAAM,EAAE,CAExC;IAED,wBAAwB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;IAM7F,kDAAkD;IAClD,YAAY,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI;IAIpC,wEAAwE;IACxE,iBAAiB,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI;IA0DxC,kEAAkE;IAClE,IAAI,QAAQ,IAAI,MAAM,CAErB;IAKD,IAAI,QAAQ,CAAC,KAAK,EAAE,MAAM,EAEzB;IAED;;;OAGG;IACH,IAAI,WAAW,IAAI,eAAe,CAMjC;IAED,IAAI,WAAW,CAAC,KAAK,EAAE,eAAe,EAErC;IAED,iBAAiB,IAAI,IAAI;IAyBzB;;;OAGG;IACH,SAAS,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,GAAG,IAAI;IAoEzC,gFAAgF;IAChF,IAAI,SAAS,IAAI,OAAO,CAEvB;IAID,IAAI,SAAS,CAAC,KAAK,EAAE,OAAO,EAE3B;IAED;;;;OAIG;IACH,YAAY,CAAC,SAAS,EAAE,OAAO,GAAG,IAAI;IAgBtC,qEAAqE;IACrE,eAAe,IAAI,IAAI;IAIvB;;;OAGG;IACH,OAAO,IAAI,IAAI;IA0Gf;;;;;;OAMG;IACH,aAAa,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,GAAG,cAAc;CA6VlE"}
|
|
@@ -4,6 +4,15 @@ import type { Message } from "@ag-ui/core";
|
|
|
4
4
|
export interface HttpAgentOptions {
|
|
5
5
|
endpoint: string;
|
|
6
6
|
headers?: Record<string, string>;
|
|
7
|
+
/**
|
|
8
|
+
* Live header source, re-read on **every** request. `HttpAgent` bakes the
|
|
9
|
+
* static `headers` into its constructor and the element caches the agent
|
|
10
|
+
* for the whole conversation — so a rotated token (CSRF, short-lived JWT)
|
|
11
|
+
* would otherwise never reach the agent endpoint and a long session 401s
|
|
12
|
+
* mid-conversation. When set, the fetch wrapper overlays these values on
|
|
13
|
+
* each call; `headers` still seeds the initial/static configuration.
|
|
14
|
+
*/
|
|
15
|
+
getHeaders?: () => Record<string, string>;
|
|
7
16
|
/** Stable conversation id, so the agent's runs share a thread. */
|
|
8
17
|
threadId?: string;
|
|
9
18
|
/** Rehydrated history to seed the agent with (durable conversation). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create_http_agent.d.ts","sourceRoot":"","sources":["../../src/core/create_http_agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAa,MAAM,eAAe,CAAC;AAC9D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C,0CAA0C;AAC1C,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,kEAAkE;IAClE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wEAAwE;IACxE,eAAe,CAAC,EAAE,SAAS,OAAO,EAAE,CAAC;CACtC;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,aAAa,
|
|
1
|
+
{"version":3,"file":"create_http_agent.d.ts","sourceRoot":"","sources":["../../src/core/create_http_agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAa,MAAM,eAAe,CAAC;AAC9D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C,0CAA0C;AAC1C,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC;;;;;;;OAOG;IACH,UAAU,CAAC,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,kEAAkE;IAClE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wEAAwE;IACxE,eAAe,CAAC,EAAE,SAAS,OAAO,EAAE,CAAC;CACtC;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,aAAa,CA4BxE;AAED,2EAA2E;AAC3E,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE,gBAAgB,KAAK,aAAa,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -12,10 +12,12 @@ export { type ClientTool, ClientToolRegistry } from "./tools/client_tool_registr
|
|
|
12
12
|
export { isDestructive } from "./tools/is_destructive.js";
|
|
13
13
|
export { isNavigates } from "./tools/is_navigates.js";
|
|
14
14
|
export { createPageMapContext, type PageMap } from "./tools/page_map.js";
|
|
15
|
+
export { parseToolCatalog, type ToolCatalogEntry } from "./tools/parse_tool_catalog.js";
|
|
15
16
|
export { createRouteTools, type Route, type RouteMap, type RouteWithParams, } from "./tools/route_map.js";
|
|
16
17
|
export { createStateHookTools, type StateHook } from "./tools/state_hook.js";
|
|
17
18
|
export { type ConfirmationRequest, requestConfirmation } from "./ui/confirmation_card.js";
|
|
18
|
-
export {
|
|
19
|
+
export { prettifyToolName } from "./ui/prettify_tool_name.js";
|
|
20
|
+
export { type RenderMarkdownOptions, renderMarkdown } from "./ui/render_markdown.js";
|
|
19
21
|
export { type SettledStatus, ToolCallCard, type ToolCallStatus, type ToolDisplayMode, } from "./ui/tool_call_card.js";
|
|
20
22
|
export { VERSION } from "./version.js";
|
|
21
23
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"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B,CAAC;AACrF,OAAO,EACL,KAAK,aAAa,EAClB,YAAY,EACZ,KAAK,cAAc,EACnB,KAAK,eAAe,GACrB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -106,6 +106,26 @@ function createPageMapContext(getPageMap, autoInject) {
|
|
|
106
106
|
return [{ description: "page_map", value: JSON.stringify(getPageMap()) }];
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
// src/tools/parse_tool_catalog.ts
|
|
110
|
+
function parseToolCatalog(data) {
|
|
111
|
+
const out = {};
|
|
112
|
+
if (!Array.isArray(data)) {
|
|
113
|
+
return out;
|
|
114
|
+
}
|
|
115
|
+
for (const entry of data) {
|
|
116
|
+
if (entry === null || typeof entry !== "object") {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
const record = entry;
|
|
120
|
+
const name = record["name"];
|
|
121
|
+
const summary = record["summary"];
|
|
122
|
+
if (typeof name === "string" && typeof summary === "string") {
|
|
123
|
+
out[name] = summary;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return out;
|
|
127
|
+
}
|
|
128
|
+
|
|
109
129
|
// src/tools/route_map.ts
|
|
110
130
|
var PATH_PARAM_RE = /:([A-Za-z_][A-Za-z0-9_]*)/g;
|
|
111
131
|
function pathParamNames(path) {
|
|
@@ -251,6 +271,15 @@ function requestConfirmation(host, request) {
|
|
|
251
271
|
});
|
|
252
272
|
}
|
|
253
273
|
|
|
274
|
+
// src/ui/prettify_tool_name.ts
|
|
275
|
+
function prettifyToolName(name) {
|
|
276
|
+
const spaced = name.replace(/[._-]+/g, " ").trim();
|
|
277
|
+
if (spaced === "") {
|
|
278
|
+
return name;
|
|
279
|
+
}
|
|
280
|
+
return spaced.charAt(0).toUpperCase() + spaced.slice(1);
|
|
281
|
+
}
|
|
282
|
+
|
|
254
283
|
// node_modules/.pnpm/dompurify@3.4.7/node_modules/dompurify/dist/purify.es.mjs
|
|
255
284
|
function _arrayLikeToArray(r, a) {
|
|
256
285
|
(null == a || a > r.length) && (a = r.length);
|
|
@@ -2691,7 +2720,7 @@ var Vt = b.parse;
|
|
|
2691
2720
|
var Yt = x.lex;
|
|
2692
2721
|
|
|
2693
2722
|
// src/ui/render_markdown.ts
|
|
2694
|
-
|
|
2723
|
+
var parser = new q({ gfm: true, breaks: true });
|
|
2695
2724
|
var ALLOWED_TAGS = [
|
|
2696
2725
|
"a",
|
|
2697
2726
|
"p",
|
|
@@ -2722,13 +2751,18 @@ var ALLOWED_TAGS = [
|
|
|
2722
2751
|
"tbody",
|
|
2723
2752
|
"tr",
|
|
2724
2753
|
"th",
|
|
2725
|
-
"td"
|
|
2726
|
-
"img"
|
|
2754
|
+
"td"
|
|
2727
2755
|
];
|
|
2728
|
-
var ALLOWED_ATTR = ["href", "title", "class"
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2756
|
+
var ALLOWED_ATTR = ["href", "title", "class"];
|
|
2757
|
+
var ALLOWED_TAGS_WITH_IMAGES = [...ALLOWED_TAGS, "img"];
|
|
2758
|
+
var ALLOWED_ATTR_WITH_IMAGES = [...ALLOWED_ATTR, "src", "alt", "width", "height"];
|
|
2759
|
+
function renderMarkdown(text2, options) {
|
|
2760
|
+
const allowImages = options?.allowImages === true;
|
|
2761
|
+
const rendered = parser.parse(text2, { async: false });
|
|
2762
|
+
const clean = purify.sanitize(rendered, {
|
|
2763
|
+
ALLOWED_TAGS: allowImages ? ALLOWED_TAGS_WITH_IMAGES : ALLOWED_TAGS,
|
|
2764
|
+
ALLOWED_ATTR: allowImages ? ALLOWED_ATTR_WITH_IMAGES : ALLOWED_ATTR
|
|
2765
|
+
});
|
|
2732
2766
|
const template = document.createElement("template");
|
|
2733
2767
|
template.innerHTML = clean;
|
|
2734
2768
|
for (const anchor of template.content.querySelectorAll("a[href]")) {
|
|
@@ -3814,8 +3848,20 @@ function createHttpAgent(options) {
|
|
|
3814
3848
|
// HttpAgent invokes its configured fetch as a method (`this.fetch(...)`),
|
|
3815
3849
|
// which would rebind the global `fetch` to the agent instance and trigger
|
|
3816
3850
|
// "Illegal invocation" in browsers. Wrap it so `fetch` is always called as
|
|
3817
|
-
// a free function with the correct receiver.
|
|
3818
|
-
|
|
3851
|
+
// a free function with the correct receiver. The wrapper also overlays
|
|
3852
|
+
// `getHeaders()` per request, so header rotation (CSRF, short-lived JWT)
|
|
3853
|
+
// reaches the stream even though the agent instance is cached.
|
|
3854
|
+
fetch: (url, init) => {
|
|
3855
|
+
const fresh = options.getHeaders?.();
|
|
3856
|
+
if (fresh === void 0) {
|
|
3857
|
+
return fetch(url, init);
|
|
3858
|
+
}
|
|
3859
|
+
const headers = new Headers(init?.headers);
|
|
3860
|
+
for (const [name, value] of Object.entries(fresh)) {
|
|
3861
|
+
headers.set(name, value);
|
|
3862
|
+
}
|
|
3863
|
+
return fetch(url, { ...init, headers });
|
|
3864
|
+
},
|
|
3819
3865
|
// Spread conditionally: under `exactOptionalPropertyTypes` an explicit
|
|
3820
3866
|
// `undefined` is not assignable to these optional config fields.
|
|
3821
3867
|
...options.threadId !== void 0 ? { threadId: options.threadId } : {},
|
|
@@ -3830,6 +3876,13 @@ var AgUiChat = class extends HTMLElement {
|
|
|
3830
3876
|
agentFactory = createHttpAgent;
|
|
3831
3877
|
/** Extra HTTP headers for the AG-UI endpoint (e.g. CSRF). */
|
|
3832
3878
|
headers = {};
|
|
3879
|
+
/**
|
|
3880
|
+
* Permit `<img>` in rendered assistant markdown. **Off by default**: a
|
|
3881
|
+
* model-controlled image URL is fetched with no user interaction, which
|
|
3882
|
+
* makes it a zero-click exfiltration channel for prompt-injected page
|
|
3883
|
+
* data. Enable only when the content source is trusted.
|
|
3884
|
+
*/
|
|
3885
|
+
allowImages = false;
|
|
3833
3886
|
/** When true, destructive tools execute without a confirmation modal. */
|
|
3834
3887
|
autoConfirm = false;
|
|
3835
3888
|
/**
|
|
@@ -3904,6 +3957,12 @@ var AgUiChat = class extends HTMLElement {
|
|
|
3904
3957
|
* schema; this map is the seam for everything else.
|
|
3905
3958
|
*/
|
|
3906
3959
|
toolSummaries = {};
|
|
3960
|
+
/**
|
|
3961
|
+
* Card labels fetched from a server tool catalog (`data-tools-url`), keyed by
|
|
3962
|
+
* tool name. The base layer behind {@link toolSummaries}: an explicit entry in
|
|
3963
|
+
* `toolSummaries` wins, this fills the rest. Populated once on connect.
|
|
3964
|
+
*/
|
|
3965
|
+
#toolCatalog = {};
|
|
3907
3966
|
#toolRegistry = new ClientToolRegistry();
|
|
3908
3967
|
/** Tool-call cards awaiting execution, keyed by call id. */
|
|
3909
3968
|
#toolCards = /* @__PURE__ */ new Map();
|
|
@@ -4038,9 +4097,22 @@ var AgUiChat = class extends HTMLElement {
|
|
|
4038
4097
|
this.setAttribute("collapsed", "");
|
|
4039
4098
|
}
|
|
4040
4099
|
this.#initSkills();
|
|
4100
|
+
void this.#fetchToolCatalog();
|
|
4041
4101
|
this.#threadId = this.conversationStore.threadId();
|
|
4042
4102
|
void this.#rehydrate();
|
|
4043
4103
|
}
|
|
4104
|
+
/** Fetch the server tool-label catalog from `data-tools-url`, if set. */
|
|
4105
|
+
async #fetchToolCatalog() {
|
|
4106
|
+
const url = this.getAttribute("data-tools-url");
|
|
4107
|
+
if (url === null) {
|
|
4108
|
+
return;
|
|
4109
|
+
}
|
|
4110
|
+
try {
|
|
4111
|
+
const response = await fetch(url, { headers: this.headers });
|
|
4112
|
+
this.#toolCatalog = parseToolCatalog(await response.json());
|
|
4113
|
+
} catch {
|
|
4114
|
+
}
|
|
4115
|
+
}
|
|
4044
4116
|
/**
|
|
4045
4117
|
* Replace the host-supplied (client) skill catalog. Merged after the embedded
|
|
4046
4118
|
* and fetched skills (so a client skill overrides a same-named server one).
|
|
@@ -4248,7 +4320,7 @@ var AgUiChat = class extends HTMLElement {
|
|
|
4248
4320
|
const bubble = document.createElement("div");
|
|
4249
4321
|
bubble.className = `message message--${role}`;
|
|
4250
4322
|
if (role === MESSAGE_ROLE.ASSISTANT) {
|
|
4251
|
-
bubble.innerHTML = renderMarkdown(content);
|
|
4323
|
+
bubble.innerHTML = renderMarkdown(content, { allowImages: this.allowImages });
|
|
4252
4324
|
} else {
|
|
4253
4325
|
bubble.textContent = content;
|
|
4254
4326
|
}
|
|
@@ -4356,6 +4428,10 @@ var AgUiChat = class extends HTMLElement {
|
|
|
4356
4428
|
const agent = this.agentFactory({
|
|
4357
4429
|
endpoint: this.endpoint,
|
|
4358
4430
|
headers: this.headers,
|
|
4431
|
+
// Live getter: the client is built once and cached, but a rotated
|
|
4432
|
+
// token must still reach every request — the factory's fetch wrapper
|
|
4433
|
+
// re-reads this on each call.
|
|
4434
|
+
getHeaders: () => this.headers,
|
|
4359
4435
|
threadId: this.#threadId,
|
|
4360
4436
|
initialMessages: this.#initialMessages
|
|
4361
4437
|
});
|
|
@@ -4510,7 +4586,7 @@ var AgUiChat = class extends HTMLElement {
|
|
|
4510
4586
|
this.#streamingBubble = this.appendMessage(MESSAGE_ROLE.ASSISTANT, "");
|
|
4511
4587
|
this.#streamDeltas = 0;
|
|
4512
4588
|
}
|
|
4513
|
-
this.#streamingBubble.innerHTML = renderMarkdown(buffer);
|
|
4589
|
+
this.#streamingBubble.innerHTML = renderMarkdown(buffer, { allowImages: this.allowImages });
|
|
4514
4590
|
this.#messages.scrollTop = this.#messages.scrollHeight;
|
|
4515
4591
|
return this.#streamingBubble;
|
|
4516
4592
|
}
|
|
@@ -4526,7 +4602,7 @@ var AgUiChat = class extends HTMLElement {
|
|
|
4526
4602
|
return existing;
|
|
4527
4603
|
}
|
|
4528
4604
|
const labelled = this.#resolveTool(call.name)?.parameters[X_SUMMARY_KEY];
|
|
4529
|
-
const summary = typeof labelled === "string" ? labelled : this.toolSummaries[call.name];
|
|
4605
|
+
const summary = typeof labelled === "string" ? labelled : this.toolSummaries[call.name] ?? this.#toolCatalog[call.name] ?? prettifyToolName(call.name);
|
|
4530
4606
|
const card = new ToolCallCard(call.name, call.args, this.toolDisplay, summary);
|
|
4531
4607
|
this.#toolCards.set(call.id, card);
|
|
4532
4608
|
this.#messages.appendChild(card.element);
|
|
@@ -4699,7 +4775,7 @@ function setControlValue(el, value) {
|
|
|
4699
4775
|
}
|
|
4700
4776
|
|
|
4701
4777
|
// src/version.ts
|
|
4702
|
-
var VERSION = "0.
|
|
4778
|
+
var VERSION = "0.3.1";
|
|
4703
4779
|
export {
|
|
4704
4780
|
AgUiChat,
|
|
4705
4781
|
AgUiClient,
|
|
@@ -4729,9 +4805,11 @@ export {
|
|
|
4729
4805
|
highlightThenClick,
|
|
4730
4806
|
isDestructive,
|
|
4731
4807
|
isNavigates,
|
|
4808
|
+
parseToolCatalog,
|
|
4732
4809
|
prefersReducedMotion,
|
|
4733
4810
|
pressButton,
|
|
4734
4811
|
pressThenClick,
|
|
4812
|
+
prettifyToolName,
|
|
4735
4813
|
renderMarkdown,
|
|
4736
4814
|
requestConfirmation,
|
|
4737
4815
|
scrollIntoCenterView,
|