@agentskit/chat-vue 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 AgentsKit
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # @agentskit/chat-vue
2
+
3
+ Native Vue 3 application shell for AgentsKit Chat. It composes `useChat`, `ChatRoot`, and the headless components published by `@agentskit/vue`; chat state and lifecycle remain upstream.
4
+
5
+ ```ts
6
+ import { AgentChat } from '@agentskit/chat-vue'
7
+ ```
8
+
9
+ Use the named scoped slots `container`, `message`, `input`, `thinking`, `confirmation`, and `choiceList` for Vue-native customization.
package/dist/index.cjs ADDED
@@ -0,0 +1,376 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ AgentChat: () => AgentChat,
24
+ ChoiceList: () => ChoiceList,
25
+ StandardComponent: () => StandardComponent,
26
+ toChatCssVariables: () => toChatCssVariables
27
+ });
28
+ module.exports = __toCommonJS(index_exports);
29
+ var import_chat2 = require("@agentskit/chat");
30
+ var import_vue2 = require("@agentskit/vue");
31
+ var import_vue3 = require("vue");
32
+
33
+ // src/StandardComponent.ts
34
+ var import_chat = require("@agentskit/chat");
35
+ var import_vue = require("vue");
36
+ var StandardComponent = (0, import_vue.defineComponent)({
37
+ name: "AgentsKitStandardComponent",
38
+ props: { frame: { type: Object, required: true }, manifest: { type: Object, required: true }, onInteract: { type: Function, required: true }, disabled: Boolean },
39
+ setup(props) {
40
+ const values = (0, import_vue.reactive)({});
41
+ const emit = (event, value) => props.onInteract((0, import_chat.createComponentInteraction)(props.frame, props.manifest, event, value));
42
+ return () => {
43
+ if (!(0, import_chat.resolveComponentFrame)(props.frame, props.manifest).ok || props.frame.componentKey === "choice-list") return null;
44
+ const key = props.frame.componentKey;
45
+ if (key === "button-group") {
46
+ const item = import_chat.ButtonGroupPropsSchema.parse(props.frame.props);
47
+ return (0, import_vue.h)("fieldset", { "aria-label": item.label, "data-ak-component": key }, [(0, import_vue.h)("legend", item.label), ...item.buttons.map((button) => (0, import_vue.h)("button", { type: "button", disabled: props.disabled || button.disabled, onClick: () => emit("select", button.id) }, button.label))]);
48
+ }
49
+ if (key === "form") {
50
+ const item = import_chat.FormPropsSchema.parse(props.frame.props);
51
+ return (0, import_vue.h)("form", { "aria-label": item.title ?? "Form", "data-ak-component": key, onSubmit: (event) => {
52
+ event.preventDefault();
53
+ emit("submit", { ...values });
54
+ } }, [...item.title ? [(0, import_vue.h)("h3", item.title)] : [], ...item.fields.map((field) => (0, import_vue.h)("label", [field.label, field.type === "select" ? (0, import_vue.h)("select", { required: field.required, disabled: props.disabled, value: values[field.id] ?? "", onInput: (event) => {
55
+ if (event.target instanceof HTMLSelectElement) values[field.id] = event.target.value;
56
+ } }, [(0, import_vue.h)("option", { value: "", disabled: true }, "Select\u2026"), ...field.options?.map((option) => (0, import_vue.h)("option", { value: option.id }, option.label)) ?? []]) : (0, import_vue.h)("input", { type: field.type, required: field.required, disabled: props.disabled, placeholder: field.placeholder, onInput: (event) => {
57
+ if (event.target instanceof HTMLInputElement) values[field.id] = field.type === "checkbox" ? event.target.checked : event.target.value;
58
+ } })])), (0, import_vue.h)("button", { type: "submit", disabled: props.disabled }, item.submitLabel)]);
59
+ }
60
+ if (key === "confirmation") {
61
+ const item = import_chat.ConfirmationPropsSchema.parse(props.frame.props);
62
+ return (0, import_vue.h)("section", { "aria-label": item.title, "data-ak-component": key }, [(0, import_vue.h)("h3", item.title), (0, import_vue.h)("p", item.message), (0, import_vue.h)("button", { disabled: props.disabled, onClick: () => emit("confirm") }, item.confirmLabel), (0, import_vue.h)("button", { disabled: props.disabled, onClick: () => emit("cancel") }, item.cancelLabel)]);
63
+ }
64
+ if (key === "progress") {
65
+ const item = import_chat.ProgressPropsSchema.parse(props.frame.props);
66
+ return (0, import_vue.h)("div", { "data-ak-component": key }, [(0, import_vue.h)("label", [item.label, (0, import_vue.h)("progress", { max: 100, value: item.value })]), item.status ? (0, import_vue.h)("p", item.status) : null]);
67
+ }
68
+ if (key === "source-list") {
69
+ const item = import_chat.SourceListPropsSchema.parse(props.frame.props);
70
+ return (0, import_vue.h)("section", { "data-ak-component": key }, [(0, import_vue.h)("h3", item.label), (0, import_vue.h)("ul", item.sources.map((source) => (0, import_vue.h)("li", [source.url ? (0, import_vue.h)("a", { href: source.url, onClick: (event) => {
71
+ event.preventDefault();
72
+ emit("open", source.id);
73
+ } }, source.title) : source.title, source.snippet ? (0, import_vue.h)("p", source.snippet) : null])))]);
74
+ }
75
+ if (key === "link-card") {
76
+ const item = import_chat.LinkCardPropsSchema.parse(props.frame.props);
77
+ return (0, import_vue.h)("a", { href: item.href, "data-ak-component": key, onClick: (event) => {
78
+ event.preventDefault();
79
+ emit("open", item.href);
80
+ } }, [(0, import_vue.h)("strong", item.title), item.description, item.label]);
81
+ }
82
+ if (key === "error-notice") {
83
+ const item = import_chat.ErrorNoticePropsSchema.parse(props.frame.props);
84
+ return (0, import_vue.h)("section", { role: "alert", "data-ak-component": key }, [(0, import_vue.h)("strong", item.title), (0, import_vue.h)("p", item.message), item.code ? (0, import_vue.h)("code", item.code) : null, item.retryLabel ? (0, import_vue.h)("button", { disabled: props.disabled, onClick: () => emit("retry") }, item.retryLabel) : null]);
85
+ }
86
+ if (key === "tool-call") {
87
+ const item = import_chat.ToolCallPropsSchema.parse(props.frame.props);
88
+ return (0, import_vue.h)("section", { role: "status", "data-ak-component": key }, [(0, import_vue.h)("strong", item.name), (0, import_vue.h)("span", item.status), item.arguments ? (0, import_vue.h)("pre", JSON.stringify(item.arguments, null, 2)) : null, item.result === void 0 ? null : (0, import_vue.h)("pre", JSON.stringify(item.result, null, 2))]);
89
+ }
90
+ if (key === "approval-request") {
91
+ const item = import_chat.ApprovalRequestPropsSchema.parse(props.frame.props);
92
+ return (0, import_vue.h)("section", { "aria-label": item.title, "data-ak-component": key }, [(0, import_vue.h)("h3", item.title), (0, import_vue.h)("p", item.description), (0, import_vue.h)("button", { disabled: props.disabled, onClick: () => emit("approve") }, item.approveLabel), (0, import_vue.h)("button", { disabled: props.disabled, onClick: () => emit("deny") }, item.denyLabel)]);
93
+ }
94
+ if (key === "table") {
95
+ const item = import_chat.TablePropsSchema.parse(props.frame.props);
96
+ return (0, import_vue.h)("table", { "data-ak-component": key }, [(0, import_vue.h)("caption", item.caption), (0, import_vue.h)("thead", (0, import_vue.h)("tr", item.columns.map((column) => (0, import_vue.h)("th", { scope: "col" }, column.label)))), (0, import_vue.h)("tbody", item.rows.map((row) => (0, import_vue.h)("tr", item.columns.map((column) => (0, import_vue.h)("td", String(row[column.key] ?? ""))))))]);
97
+ }
98
+ if (key === "file-attachment") {
99
+ const item = import_chat.FileAttachmentPropsSchema.parse(props.frame.props);
100
+ return (0, import_vue.h)("article", { "data-ak-component": key }, [(0, import_vue.h)("strong", item.name), (0, import_vue.h)("span", item.mimeType), item.sizeBytes === void 0 ? null : (0, import_vue.h)("span", `${item.sizeBytes} bytes`), item.url ? (0, import_vue.h)("a", { href: item.url, onClick: (event) => {
101
+ event.preventDefault();
102
+ emit("open", item.url);
103
+ } }, "Open") : null]);
104
+ }
105
+ return (0, import_vue.h)("p", { "data-ak-component-fallback": "" }, (0, import_chat.resolveComponentFallback)(props.frame, props.manifest) ?? "");
106
+ };
107
+ }
108
+ });
109
+
110
+ // src/index.ts
111
+ var toChatCssVariables = (input) => {
112
+ const theme = (0, import_chat2.resolveChatTheme)(input);
113
+ return {
114
+ "--ak-color-bg": theme.colors.background,
115
+ "--ak-color-surface": theme.colors.surface,
116
+ "--ak-color-border": theme.colors.border,
117
+ "--ak-color-text": theme.colors.text,
118
+ "--ak-color-text-muted": theme.colors.muted,
119
+ "--ak-color-bubble-user": theme.colors.accent,
120
+ "--ak-color-bubble-user-text": theme.colors.onAccent,
121
+ "--ak-color-bubble-assistant": theme.colors.surface,
122
+ "--ak-color-bubble-assistant-text": theme.colors.text,
123
+ "--ak-color-input-bg": theme.colors.background,
124
+ "--ak-color-input-border": theme.colors.border,
125
+ "--ak-color-input-focus": theme.colors.accent,
126
+ "--ak-color-button": theme.colors.accent,
127
+ "--ak-color-button-text": theme.colors.onAccent,
128
+ "--ak-color-tool-bg": theme.colors.surface,
129
+ "--ak-color-tool-border": theme.colors.border,
130
+ "--ak-app-color-danger": theme.colors.danger,
131
+ "--ak-font-family": theme.fontFamily === "system" ? "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif" : theme.fontFamily,
132
+ "--ak-radius": `${theme.radius.medium}px`,
133
+ "--ak-radius-lg": `${theme.radius.large}px`,
134
+ "--ak-spacing-sm": `${theme.spacing.small}px`,
135
+ "--ak-spacing-md": `${theme.spacing.medium}px`,
136
+ "--ak-spacing-lg": `${theme.spacing.large}px`
137
+ };
138
+ };
139
+ var ChoiceList = (0, import_vue3.defineComponent)({
140
+ name: "AgentsKitChoiceList",
141
+ props: {
142
+ frame: { type: null, required: true },
143
+ manifest: { type: Object, required: true },
144
+ onSelect: { type: Function, required: true },
145
+ disabled: { type: Boolean, default: false }
146
+ },
147
+ setup(props) {
148
+ return () => {
149
+ const resolved = (0, import_chat2.resolveChoiceListFrame)(props.frame, props.manifest);
150
+ if (!resolved.ok) return null;
151
+ return (0, import_vue3.h)("fieldset", { "aria-label": resolved.props.prompt, "data-ak-component": "choice-list" }, [
152
+ (0, import_vue3.h)("legend", resolved.props.prompt),
153
+ ...resolved.props.choices.map((choice) => (0, import_vue3.h)("button", {
154
+ key: choice.id,
155
+ type: "button",
156
+ disabled: props.disabled,
157
+ onClick: () => props.onSelect((0, import_chat2.selectChoice)(resolved.frame, choice.id))
158
+ }, [(0, import_vue3.h)("span", choice.label), choice.description === void 0 ? null : (0, import_vue3.h)("small", choice.description)]))
159
+ ]);
160
+ };
161
+ }
162
+ });
163
+ var slot = (slots, name, props, fallback) => slots[name]?.(props) ?? fallback();
164
+ var agentChatProps = {
165
+ definition: { type: Object, required: true },
166
+ placeholder: { type: String, default: void 0 },
167
+ onComponentSelect: { type: Function, default: void 0 },
168
+ onComponentInteract: { type: Function, default: void 0 },
169
+ actionConfirmationTtlMs: { type: Number, default: void 0 },
170
+ session: { type: Object, default: void 0 },
171
+ theme: { type: Object, default: void 0 }
172
+ };
173
+ var ChatBinding = (0, import_vue3.defineComponent)({
174
+ name: "AgentsKitChatBinding",
175
+ props: {
176
+ config: { type: Object, required: true },
177
+ onState: { type: Function, required: true }
178
+ },
179
+ setup(props, { slots }) {
180
+ const chat = (0, import_vue2.useChat)(props.config);
181
+ (0, import_vue3.watchEffect)(() => {
182
+ void chat.status;
183
+ void chat.messages;
184
+ props.onState(chat);
185
+ });
186
+ return () => slots.default?.({ chat });
187
+ }
188
+ });
189
+ var AgentChatSession = (0, import_vue3.defineComponent)({
190
+ name: "AgentsKitChatSession",
191
+ props: agentChatProps,
192
+ slots: Object,
193
+ setup(props, { slots }) {
194
+ const session = (0, import_chat2.resolveChatSession)(props.definition, props.session);
195
+ const sessionId = session.sessionId;
196
+ let activeChat = props.definition.chat;
197
+ let pendingChat = activeChat;
198
+ let messages = activeChat.initialMessages;
199
+ let status = "idle";
200
+ let currentChat;
201
+ const bindingRevision = (0, import_vue3.ref)(0);
202
+ const actionError = (0, import_vue3.ref)();
203
+ const editDraft = (0, import_vue3.ref)();
204
+ const resolvedInstances = (0, import_vue3.ref)(/* @__PURE__ */ new Set());
205
+ const confirmation = session.createConfirmation({
206
+ ...props.actionConfirmationTtlMs === void 0 ? {} : { ttlMs: props.actionConfirmationTtlMs },
207
+ chat: {
208
+ proposeToolCall: (proposal) => currentChat.proposeToolCall(proposal),
209
+ approve: (id) => currentChat.approve(id),
210
+ deny: (id, reason) => currentChat.deny(id, reason)
211
+ }
212
+ });
213
+ const fail = (error, fallback) => {
214
+ actionError.value = error instanceof Error ? error : new Error(fallback);
215
+ };
216
+ const selectComponent = (event, frame) => {
217
+ if (resolvedInstances.value.has(event.instanceId)) return;
218
+ actionError.value = void 0;
219
+ resolvedInstances.value.add(event.instanceId);
220
+ try {
221
+ props.onComponentSelect?.(event);
222
+ } catch (error) {
223
+ fail(error, "Component selection callback failed.");
224
+ }
225
+ const action = (0, import_chat2.resolveChoiceAction)(frame, event.choiceId);
226
+ if (action) void confirmation.propose(action).catch((error) => {
227
+ resolvedInstances.value.delete(event.instanceId);
228
+ fail(error, "Action proposal failed.");
229
+ });
230
+ else {
231
+ let submission;
232
+ try {
233
+ submission = props.definition.choiceSubmission?.(frame, event.choiceId, { sessionId });
234
+ } catch (error) {
235
+ resolvedInstances.value.delete(event.instanceId);
236
+ fail(error, "Choice submission authorization failed.");
237
+ return;
238
+ }
239
+ if (submission && "unavailable" in submission) {
240
+ resolvedInstances.value.delete(event.instanceId);
241
+ fail(new Error("This deterministic choice expired. Ask the question again."), "Choice unavailable.");
242
+ return;
243
+ }
244
+ if (submission) void currentChat.send(submission.value).then(
245
+ () => {
246
+ try {
247
+ submission.commit();
248
+ } catch (error) {
249
+ fail(error, "Choice submission settlement failed.");
250
+ }
251
+ },
252
+ (error) => {
253
+ try {
254
+ submission.release();
255
+ } catch {
256
+ } finally {
257
+ resolvedInstances.value.delete(event.instanceId);
258
+ }
259
+ fail(error, "Choice submission failed.");
260
+ }
261
+ );
262
+ }
263
+ };
264
+ const approve = (toolCallId) => {
265
+ const record = confirmation.getByToolCall(toolCallId);
266
+ void (record ? confirmation.approve(record.token, sessionId) : currentChat.approve(toolCallId)).catch((error) => fail(error, "Action approval failed."));
267
+ };
268
+ const deny = (toolCallId, reason) => {
269
+ const record = confirmation.getByToolCall(toolCallId);
270
+ void (record ? confirmation.reject(record.token, sessionId, reason) : currentChat.deny(toolCallId, reason)).catch((error) => fail(error, "Action rejection failed."));
271
+ };
272
+ const runLifecycle = (operation) => {
273
+ actionError.value = void 0;
274
+ void operation.catch((error) => fail(error, "Lifecycle operation failed."));
275
+ };
276
+ const interactComponent = (event) => {
277
+ if (resolvedInstances.value.has(event.instanceId)) return;
278
+ resolvedInstances.value.add(event.instanceId);
279
+ try {
280
+ props.onComponentInteract?.(event);
281
+ } catch (error) {
282
+ resolvedInstances.value.delete(event.instanceId);
283
+ fail(error, "Component interaction callback failed.");
284
+ }
285
+ };
286
+ const renderChat = (chat) => {
287
+ currentChat = chat;
288
+ const nativeSlots = slots;
289
+ const targets = (0, import_chat2.getLifecycleTargets)(chat.messages);
290
+ const messages2 = chat.messages.flatMap((message) => (0, import_chat2.presentChatMessage)(message).map((presentation, index) => {
291
+ if (presentation.kind === "component") {
292
+ const manifest = props.definition.components;
293
+ const resolved = manifest === void 0 ? void 0 : (0, import_chat2.resolveComponentFrame)(presentation.frame, manifest);
294
+ const rendered2 = resolved?.ok ? presentation.frame.componentKey === "choice-list" ? slot(nativeSlots, "choiceList", { frame: presentation.frame, manifest, disabled: resolvedInstances.value.has(presentation.frame.instanceId), onSelect: (event) => selectComponent(event, presentation.frame) }, () => (0, import_vue3.h)(ChoiceList, { frame: presentation.frame, manifest, disabled: resolvedInstances.value.has(presentation.frame.instanceId), onSelect: (event) => selectComponent(event, presentation.frame) })) : slot(nativeSlots, "standardComponent", { frame: presentation.frame, manifest, disabled: resolvedInstances.value.has(presentation.frame.instanceId), onInteract: interactComponent }, () => (0, import_vue3.h)(StandardComponent, { frame: presentation.frame, manifest, disabled: resolvedInstances.value.has(presentation.frame.instanceId), onInteract: interactComponent })) : (0, import_vue3.h)("p", { "data-ak-component-fallback": "" }, (0, import_chat2.formatSemanticFallback)(presentation.frame.fallback));
295
+ return (0, import_vue3.h)(import_vue3.Fragment, { key: `${message.id}:${index}` }, [rendered2]);
296
+ }
297
+ const rendered = presentation.kind === "diagnostic" ? (0, import_vue3.h)("p", { role: "alert", "data-ak-component-diagnostic": presentation.code }, presentation.message) : slot(nativeSlots, "message", { message: presentation.message }, () => (0, import_vue3.h)(import_vue2.Message, { message: presentation.message }));
298
+ return (0, import_vue3.h)(import_vue3.Fragment, { key: `${message.id}:${index}` }, [rendered]);
299
+ }));
300
+ const confirmations = chat.messages.flatMap((message) => message.toolCalls ?? []).map((toolCall) => (0, import_vue3.h)(import_vue3.Fragment, { key: toolCall.id }, [slot(nativeSlots, "confirmation", { toolCall, onApprove: approve, onDeny: deny }, () => (0, import_vue3.h)(import_vue2.ToolConfirmation, { toolCall, onApprove: approve, onDeny: deny }))]));
301
+ const content = [...messages2, ...confirmations, slot(nativeSlots, "thinking", { visible: chat.status === "streaming" }, () => (0, import_vue3.h)(import_vue2.ThinkingIndicator, { visible: chat.status === "streaming" }))];
302
+ const container = slot(nativeSlots, "container", { children: content }, () => (0, import_vue3.h)(import_vue2.ChatRoot, {}, { default: () => content }));
303
+ const error = chat.error ?? actionError.value;
304
+ return (0, import_vue3.h)("section", {
305
+ "aria-label": `${props.definition.id} chat`,
306
+ "data-ak-app-chat": "",
307
+ style: props.theme === void 0 ? void 0 : toChatCssVariables(props.theme)
308
+ }, [
309
+ (0, import_vue3.h)("div", { "aria-live": "polite", "aria-relevant": "additions text", role: "log" }, [container]),
310
+ error ? (0, import_vue3.h)("p", { role: "alert", style: { color: (0, import_chat2.resolveChatTheme)(props.theme).colors.danger } }, error.message) : null,
311
+ chat.status === "streaming" ? (0, import_vue3.h)("button", { type: "button", onClick: chat.stop }, "Stop") : null,
312
+ chat.status !== "streaming" && targets.userId ? (0, import_vue3.h)("div", { "aria-label": "Response actions" }, [
313
+ (0, import_vue3.h)("button", { type: "button", "aria-label": "Retry response", onClick: () => runLifecycle(chat.retry()) }, "Retry"),
314
+ targets.assistantId ? (0, import_vue3.h)("button", { type: "button", "aria-label": "Regenerate response", onClick: () => runLifecycle(chat.regenerate(targets.assistantId)) }, "Regenerate") : null,
315
+ (0, import_vue3.h)("button", { type: "button", onClick: () => {
316
+ editDraft.value = { messageId: targets.userId, content: chat.messages.find((message) => message.id === targets.userId)?.content ?? "" };
317
+ } }, "Edit last message"),
318
+ editDraft.value === void 0 ? null : (0, import_vue3.h)("form", { onSubmit: (event) => {
319
+ event.preventDefault();
320
+ if (!editDraft.value?.content.trim()) return;
321
+ runLifecycle(chat.edit(editDraft.value.messageId, editDraft.value.content));
322
+ editDraft.value = void 0;
323
+ } }, [
324
+ (0, import_vue3.h)("label", ["Edit message", (0, import_vue3.h)("input", { "aria-label": "Edit message", value: editDraft.value.content, onInput: (event) => {
325
+ editDraft.value = { ...editDraft.value, content: event.target.value };
326
+ } })]),
327
+ (0, import_vue3.h)("button", { type: "submit", "aria-label": "Save edit" }, "Save edit"),
328
+ (0, import_vue3.h)("button", { type: "button", onClick: () => {
329
+ editDraft.value = void 0;
330
+ } }, "Cancel edit")
331
+ ])
332
+ ]) : null,
333
+ slot(nativeSlots, "input", { chat, disabled: chat.status === "streaming", placeholder: props.placeholder }, () => (0, import_vue3.h)(import_vue2.InputBar, { chat, disabled: chat.status === "streaming", ...props.placeholder === void 0 ? {} : { placeholder: props.placeholder } }))
334
+ ]);
335
+ };
336
+ return () => {
337
+ pendingChat = props.definition.chat;
338
+ if (activeChat !== pendingChat && status !== "streaming") {
339
+ activeChat = pendingChat;
340
+ bindingRevision.value += 1;
341
+ }
342
+ const config = session.updateChat({ ...activeChat, ...messages === void 0 ? {} : { initialMessages: messages } });
343
+ return (0, import_vue3.h)(ChatBinding, {
344
+ key: bindingRevision.value,
345
+ config,
346
+ onState: (chat) => {
347
+ currentChat = chat;
348
+ messages = chat.messages;
349
+ status = chat.status;
350
+ if (activeChat !== pendingChat && status !== "streaming") {
351
+ activeChat = pendingChat;
352
+ bindingRevision.value += 1;
353
+ }
354
+ }
355
+ }, { default: ({ chat }) => renderChat(chat) });
356
+ };
357
+ }
358
+ });
359
+ var AgentChat = (0, import_vue3.defineComponent)({
360
+ name: "AgentsKitChat",
361
+ props: agentChatProps,
362
+ slots: Object,
363
+ setup(props, { slots }) {
364
+ return () => (0, import_vue3.h)(AgentChatSession, {
365
+ ...props,
366
+ key: `${props.definition.id}:${props.definition.revision ?? 1}:${props.session?.sessionId ?? "new"}`
367
+ }, slots);
368
+ }
369
+ });
370
+ // Annotate the CommonJS export names for ESM import in node:
371
+ 0 && (module.exports = {
372
+ AgentChat,
373
+ ChoiceList,
374
+ StandardComponent,
375
+ toChatCssVariables
376
+ });
@@ -0,0 +1,196 @@
1
+ import * as vue from 'vue';
2
+ import { PropType, VNode, SlotsType, VNodeChild, CSSProperties } from 'vue';
3
+ import { ComponentManifest, ChatDefinition, ChatSession, ChatThemeInput } from '@agentskit/chat';
4
+ export { ChatDefinition } from '@agentskit/chat';
5
+ import { ComponentRenderFrame, ComponentInteractionEvent, ComponentSelectionEvent } from '@agentskit/chat-protocol';
6
+ import { Message, ChatReturn, ToolCall } from '@agentskit/core';
7
+
8
+ interface StandardComponentProps {
9
+ readonly frame: ComponentRenderFrame;
10
+ readonly manifest: ComponentManifest;
11
+ readonly onInteract: (event: ComponentInteractionEvent) => void;
12
+ readonly disabled?: boolean;
13
+ }
14
+ declare const StandardComponent: vue.DefineComponent<vue.ExtractPropTypes<{
15
+ frame: {
16
+ type: PropType<ComponentRenderFrame>;
17
+ required: true;
18
+ };
19
+ manifest: {
20
+ type: PropType<ComponentManifest>;
21
+ required: true;
22
+ };
23
+ onInteract: {
24
+ type: PropType<(event: ComponentInteractionEvent) => void>;
25
+ required: true;
26
+ };
27
+ disabled: BooleanConstructor;
28
+ }>, () => VNode | null, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
29
+ frame: {
30
+ type: PropType<ComponentRenderFrame>;
31
+ required: true;
32
+ };
33
+ manifest: {
34
+ type: PropType<ComponentManifest>;
35
+ required: true;
36
+ };
37
+ onInteract: {
38
+ type: PropType<(event: ComponentInteractionEvent) => void>;
39
+ required: true;
40
+ };
41
+ disabled: BooleanConstructor;
42
+ }>> & Readonly<{}>, {
43
+ disabled: boolean;
44
+ }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
45
+
46
+ type ChatCssVariables = CSSProperties & {
47
+ readonly [key: `--ak-${string}`]: string | number;
48
+ };
49
+ declare const toChatCssVariables: (input?: ChatThemeInput) => ChatCssVariables;
50
+ interface ChoiceListProps {
51
+ readonly frame: unknown;
52
+ readonly manifest: ComponentManifest;
53
+ readonly onSelect: (event: ComponentSelectionEvent) => void;
54
+ readonly disabled?: boolean;
55
+ }
56
+ declare const ChoiceList: vue.DefineComponent<vue.ExtractPropTypes<{
57
+ frame: {
58
+ type: null;
59
+ required: true;
60
+ };
61
+ manifest: {
62
+ type: PropType<ComponentManifest>;
63
+ required: true;
64
+ };
65
+ onSelect: {
66
+ type: PropType<(event: ComponentSelectionEvent) => void>;
67
+ required: true;
68
+ };
69
+ disabled: {
70
+ type: BooleanConstructor;
71
+ default: boolean;
72
+ };
73
+ }>, () => VNode<vue.RendererNode, vue.RendererElement, {
74
+ [key: string]: any;
75
+ }> | null, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
76
+ frame: {
77
+ type: null;
78
+ required: true;
79
+ };
80
+ manifest: {
81
+ type: PropType<ComponentManifest>;
82
+ required: true;
83
+ };
84
+ onSelect: {
85
+ type: PropType<(event: ComponentSelectionEvent) => void>;
86
+ required: true;
87
+ };
88
+ disabled: {
89
+ type: BooleanConstructor;
90
+ default: boolean;
91
+ };
92
+ }>> & Readonly<{}>, {
93
+ disabled: boolean;
94
+ }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
95
+ interface AgentChatProps {
96
+ readonly definition: ChatDefinition;
97
+ readonly placeholder?: string;
98
+ readonly onComponentSelect?: (event: ComponentSelectionEvent) => void;
99
+ readonly onComponentInteract?: (event: ComponentInteractionEvent) => void;
100
+ readonly actionConfirmationTtlMs?: number;
101
+ readonly session?: ChatSession;
102
+ readonly theme?: ChatThemeInput;
103
+ }
104
+ interface AgentChatSlots {
105
+ readonly container?: (props: {
106
+ readonly children: VNodeChild;
107
+ }) => VNode[];
108
+ readonly message?: (props: {
109
+ readonly message: Message;
110
+ }) => VNode[];
111
+ readonly input?: (props: {
112
+ readonly chat: ChatReturn;
113
+ readonly disabled: boolean;
114
+ readonly placeholder?: string;
115
+ }) => VNode[];
116
+ readonly thinking?: (props: {
117
+ readonly visible: boolean;
118
+ }) => VNode[];
119
+ readonly confirmation?: (props: {
120
+ readonly toolCall: ToolCall;
121
+ readonly onApprove: (id: string) => void;
122
+ readonly onDeny: (id: string, reason?: string) => void;
123
+ }) => VNode[];
124
+ readonly choiceList?: (props: ChoiceListProps) => VNode[];
125
+ readonly standardComponent?: (props: StandardComponentProps) => VNode[];
126
+ }
127
+ declare const AgentChat: vue.DefineComponent<vue.ExtractPropTypes<{
128
+ readonly definition: {
129
+ readonly type: PropType<ChatDefinition>;
130
+ readonly required: true;
131
+ };
132
+ readonly placeholder: {
133
+ readonly type: StringConstructor;
134
+ readonly default: undefined;
135
+ };
136
+ readonly onComponentSelect: {
137
+ readonly type: PropType<(event: ComponentSelectionEvent) => void>;
138
+ readonly default: undefined;
139
+ };
140
+ readonly onComponentInteract: {
141
+ readonly type: PropType<(event: ComponentInteractionEvent) => void>;
142
+ readonly default: undefined;
143
+ };
144
+ readonly actionConfirmationTtlMs: {
145
+ readonly type: NumberConstructor;
146
+ readonly default: undefined;
147
+ };
148
+ readonly session: {
149
+ readonly type: PropType<ChatSession>;
150
+ readonly default: undefined;
151
+ };
152
+ readonly theme: {
153
+ readonly type: PropType<ChatThemeInput>;
154
+ readonly default: undefined;
155
+ };
156
+ }>, () => VNode<vue.RendererNode, vue.RendererElement, {
157
+ [key: string]: any;
158
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
159
+ readonly definition: {
160
+ readonly type: PropType<ChatDefinition>;
161
+ readonly required: true;
162
+ };
163
+ readonly placeholder: {
164
+ readonly type: StringConstructor;
165
+ readonly default: undefined;
166
+ };
167
+ readonly onComponentSelect: {
168
+ readonly type: PropType<(event: ComponentSelectionEvent) => void>;
169
+ readonly default: undefined;
170
+ };
171
+ readonly onComponentInteract: {
172
+ readonly type: PropType<(event: ComponentInteractionEvent) => void>;
173
+ readonly default: undefined;
174
+ };
175
+ readonly actionConfirmationTtlMs: {
176
+ readonly type: NumberConstructor;
177
+ readonly default: undefined;
178
+ };
179
+ readonly session: {
180
+ readonly type: PropType<ChatSession>;
181
+ readonly default: undefined;
182
+ };
183
+ readonly theme: {
184
+ readonly type: PropType<ChatThemeInput>;
185
+ readonly default: undefined;
186
+ };
187
+ }>> & Readonly<{}>, {
188
+ readonly placeholder: string;
189
+ readonly onComponentSelect: (event: ComponentSelectionEvent) => void;
190
+ readonly onComponentInteract: (event: ComponentInteractionEvent) => void;
191
+ readonly actionConfirmationTtlMs: number;
192
+ readonly session: ChatSession;
193
+ readonly theme: ChatThemeInput;
194
+ }, SlotsType<AgentChatSlots>, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
195
+
196
+ export { AgentChat, type AgentChatProps, type AgentChatSlots, type ChatCssVariables, ChoiceList, type ChoiceListProps, StandardComponent, type StandardComponentProps, toChatCssVariables };
@@ -0,0 +1,196 @@
1
+ import * as vue from 'vue';
2
+ import { PropType, VNode, SlotsType, VNodeChild, CSSProperties } from 'vue';
3
+ import { ComponentManifest, ChatDefinition, ChatSession, ChatThemeInput } from '@agentskit/chat';
4
+ export { ChatDefinition } from '@agentskit/chat';
5
+ import { ComponentRenderFrame, ComponentInteractionEvent, ComponentSelectionEvent } from '@agentskit/chat-protocol';
6
+ import { Message, ChatReturn, ToolCall } from '@agentskit/core';
7
+
8
+ interface StandardComponentProps {
9
+ readonly frame: ComponentRenderFrame;
10
+ readonly manifest: ComponentManifest;
11
+ readonly onInteract: (event: ComponentInteractionEvent) => void;
12
+ readonly disabled?: boolean;
13
+ }
14
+ declare const StandardComponent: vue.DefineComponent<vue.ExtractPropTypes<{
15
+ frame: {
16
+ type: PropType<ComponentRenderFrame>;
17
+ required: true;
18
+ };
19
+ manifest: {
20
+ type: PropType<ComponentManifest>;
21
+ required: true;
22
+ };
23
+ onInteract: {
24
+ type: PropType<(event: ComponentInteractionEvent) => void>;
25
+ required: true;
26
+ };
27
+ disabled: BooleanConstructor;
28
+ }>, () => VNode | null, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
29
+ frame: {
30
+ type: PropType<ComponentRenderFrame>;
31
+ required: true;
32
+ };
33
+ manifest: {
34
+ type: PropType<ComponentManifest>;
35
+ required: true;
36
+ };
37
+ onInteract: {
38
+ type: PropType<(event: ComponentInteractionEvent) => void>;
39
+ required: true;
40
+ };
41
+ disabled: BooleanConstructor;
42
+ }>> & Readonly<{}>, {
43
+ disabled: boolean;
44
+ }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
45
+
46
+ type ChatCssVariables = CSSProperties & {
47
+ readonly [key: `--ak-${string}`]: string | number;
48
+ };
49
+ declare const toChatCssVariables: (input?: ChatThemeInput) => ChatCssVariables;
50
+ interface ChoiceListProps {
51
+ readonly frame: unknown;
52
+ readonly manifest: ComponentManifest;
53
+ readonly onSelect: (event: ComponentSelectionEvent) => void;
54
+ readonly disabled?: boolean;
55
+ }
56
+ declare const ChoiceList: vue.DefineComponent<vue.ExtractPropTypes<{
57
+ frame: {
58
+ type: null;
59
+ required: true;
60
+ };
61
+ manifest: {
62
+ type: PropType<ComponentManifest>;
63
+ required: true;
64
+ };
65
+ onSelect: {
66
+ type: PropType<(event: ComponentSelectionEvent) => void>;
67
+ required: true;
68
+ };
69
+ disabled: {
70
+ type: BooleanConstructor;
71
+ default: boolean;
72
+ };
73
+ }>, () => VNode<vue.RendererNode, vue.RendererElement, {
74
+ [key: string]: any;
75
+ }> | null, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
76
+ frame: {
77
+ type: null;
78
+ required: true;
79
+ };
80
+ manifest: {
81
+ type: PropType<ComponentManifest>;
82
+ required: true;
83
+ };
84
+ onSelect: {
85
+ type: PropType<(event: ComponentSelectionEvent) => void>;
86
+ required: true;
87
+ };
88
+ disabled: {
89
+ type: BooleanConstructor;
90
+ default: boolean;
91
+ };
92
+ }>> & Readonly<{}>, {
93
+ disabled: boolean;
94
+ }, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
95
+ interface AgentChatProps {
96
+ readonly definition: ChatDefinition;
97
+ readonly placeholder?: string;
98
+ readonly onComponentSelect?: (event: ComponentSelectionEvent) => void;
99
+ readonly onComponentInteract?: (event: ComponentInteractionEvent) => void;
100
+ readonly actionConfirmationTtlMs?: number;
101
+ readonly session?: ChatSession;
102
+ readonly theme?: ChatThemeInput;
103
+ }
104
+ interface AgentChatSlots {
105
+ readonly container?: (props: {
106
+ readonly children: VNodeChild;
107
+ }) => VNode[];
108
+ readonly message?: (props: {
109
+ readonly message: Message;
110
+ }) => VNode[];
111
+ readonly input?: (props: {
112
+ readonly chat: ChatReturn;
113
+ readonly disabled: boolean;
114
+ readonly placeholder?: string;
115
+ }) => VNode[];
116
+ readonly thinking?: (props: {
117
+ readonly visible: boolean;
118
+ }) => VNode[];
119
+ readonly confirmation?: (props: {
120
+ readonly toolCall: ToolCall;
121
+ readonly onApprove: (id: string) => void;
122
+ readonly onDeny: (id: string, reason?: string) => void;
123
+ }) => VNode[];
124
+ readonly choiceList?: (props: ChoiceListProps) => VNode[];
125
+ readonly standardComponent?: (props: StandardComponentProps) => VNode[];
126
+ }
127
+ declare const AgentChat: vue.DefineComponent<vue.ExtractPropTypes<{
128
+ readonly definition: {
129
+ readonly type: PropType<ChatDefinition>;
130
+ readonly required: true;
131
+ };
132
+ readonly placeholder: {
133
+ readonly type: StringConstructor;
134
+ readonly default: undefined;
135
+ };
136
+ readonly onComponentSelect: {
137
+ readonly type: PropType<(event: ComponentSelectionEvent) => void>;
138
+ readonly default: undefined;
139
+ };
140
+ readonly onComponentInteract: {
141
+ readonly type: PropType<(event: ComponentInteractionEvent) => void>;
142
+ readonly default: undefined;
143
+ };
144
+ readonly actionConfirmationTtlMs: {
145
+ readonly type: NumberConstructor;
146
+ readonly default: undefined;
147
+ };
148
+ readonly session: {
149
+ readonly type: PropType<ChatSession>;
150
+ readonly default: undefined;
151
+ };
152
+ readonly theme: {
153
+ readonly type: PropType<ChatThemeInput>;
154
+ readonly default: undefined;
155
+ };
156
+ }>, () => VNode<vue.RendererNode, vue.RendererElement, {
157
+ [key: string]: any;
158
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
159
+ readonly definition: {
160
+ readonly type: PropType<ChatDefinition>;
161
+ readonly required: true;
162
+ };
163
+ readonly placeholder: {
164
+ readonly type: StringConstructor;
165
+ readonly default: undefined;
166
+ };
167
+ readonly onComponentSelect: {
168
+ readonly type: PropType<(event: ComponentSelectionEvent) => void>;
169
+ readonly default: undefined;
170
+ };
171
+ readonly onComponentInteract: {
172
+ readonly type: PropType<(event: ComponentInteractionEvent) => void>;
173
+ readonly default: undefined;
174
+ };
175
+ readonly actionConfirmationTtlMs: {
176
+ readonly type: NumberConstructor;
177
+ readonly default: undefined;
178
+ };
179
+ readonly session: {
180
+ readonly type: PropType<ChatSession>;
181
+ readonly default: undefined;
182
+ };
183
+ readonly theme: {
184
+ readonly type: PropType<ChatThemeInput>;
185
+ readonly default: undefined;
186
+ };
187
+ }>> & Readonly<{}>, {
188
+ readonly placeholder: string;
189
+ readonly onComponentSelect: (event: ComponentSelectionEvent) => void;
190
+ readonly onComponentInteract: (event: ComponentInteractionEvent) => void;
191
+ readonly actionConfirmationTtlMs: number;
192
+ readonly session: ChatSession;
193
+ readonly theme: ChatThemeInput;
194
+ }, SlotsType<AgentChatSlots>, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
195
+
196
+ export { AgentChat, type AgentChatProps, type AgentChatSlots, type ChatCssVariables, ChoiceList, type ChoiceListProps, StandardComponent, type StandardComponentProps, toChatCssVariables };
package/dist/index.js ADDED
@@ -0,0 +1,348 @@
1
+ // src/index.ts
2
+ import { formatSemanticFallback, getLifecycleTargets, presentChatMessage, resolveChatSession, resolveChatTheme, resolveChoiceAction, resolveChoiceListFrame, resolveComponentFrame as resolveComponentFrame2, selectChoice } from "@agentskit/chat";
3
+ import { ChatRoot, InputBar, Message, ThinkingIndicator, ToolConfirmation, useChat } from "@agentskit/vue";
4
+ import { defineComponent as defineComponent2, Fragment, h as h2, ref, watchEffect } from "vue";
5
+
6
+ // src/StandardComponent.ts
7
+ import { ApprovalRequestPropsSchema, ButtonGroupPropsSchema, ConfirmationPropsSchema, ErrorNoticePropsSchema, FileAttachmentPropsSchema, FormPropsSchema, LinkCardPropsSchema, ProgressPropsSchema, SourceListPropsSchema, TablePropsSchema, ToolCallPropsSchema, createComponentInteraction, resolveComponentFallback, resolveComponentFrame } from "@agentskit/chat";
8
+ import { defineComponent, h, reactive } from "vue";
9
+ var StandardComponent = defineComponent({
10
+ name: "AgentsKitStandardComponent",
11
+ props: { frame: { type: Object, required: true }, manifest: { type: Object, required: true }, onInteract: { type: Function, required: true }, disabled: Boolean },
12
+ setup(props) {
13
+ const values = reactive({});
14
+ const emit = (event, value) => props.onInteract(createComponentInteraction(props.frame, props.manifest, event, value));
15
+ return () => {
16
+ if (!resolveComponentFrame(props.frame, props.manifest).ok || props.frame.componentKey === "choice-list") return null;
17
+ const key = props.frame.componentKey;
18
+ if (key === "button-group") {
19
+ const item = ButtonGroupPropsSchema.parse(props.frame.props);
20
+ return h("fieldset", { "aria-label": item.label, "data-ak-component": key }, [h("legend", item.label), ...item.buttons.map((button) => h("button", { type: "button", disabled: props.disabled || button.disabled, onClick: () => emit("select", button.id) }, button.label))]);
21
+ }
22
+ if (key === "form") {
23
+ const item = FormPropsSchema.parse(props.frame.props);
24
+ return h("form", { "aria-label": item.title ?? "Form", "data-ak-component": key, onSubmit: (event) => {
25
+ event.preventDefault();
26
+ emit("submit", { ...values });
27
+ } }, [...item.title ? [h("h3", item.title)] : [], ...item.fields.map((field) => h("label", [field.label, field.type === "select" ? h("select", { required: field.required, disabled: props.disabled, value: values[field.id] ?? "", onInput: (event) => {
28
+ if (event.target instanceof HTMLSelectElement) values[field.id] = event.target.value;
29
+ } }, [h("option", { value: "", disabled: true }, "Select\u2026"), ...field.options?.map((option) => h("option", { value: option.id }, option.label)) ?? []]) : h("input", { type: field.type, required: field.required, disabled: props.disabled, placeholder: field.placeholder, onInput: (event) => {
30
+ if (event.target instanceof HTMLInputElement) values[field.id] = field.type === "checkbox" ? event.target.checked : event.target.value;
31
+ } })])), h("button", { type: "submit", disabled: props.disabled }, item.submitLabel)]);
32
+ }
33
+ if (key === "confirmation") {
34
+ const item = ConfirmationPropsSchema.parse(props.frame.props);
35
+ return h("section", { "aria-label": item.title, "data-ak-component": key }, [h("h3", item.title), h("p", item.message), h("button", { disabled: props.disabled, onClick: () => emit("confirm") }, item.confirmLabel), h("button", { disabled: props.disabled, onClick: () => emit("cancel") }, item.cancelLabel)]);
36
+ }
37
+ if (key === "progress") {
38
+ const item = ProgressPropsSchema.parse(props.frame.props);
39
+ return h("div", { "data-ak-component": key }, [h("label", [item.label, h("progress", { max: 100, value: item.value })]), item.status ? h("p", item.status) : null]);
40
+ }
41
+ if (key === "source-list") {
42
+ const item = SourceListPropsSchema.parse(props.frame.props);
43
+ return h("section", { "data-ak-component": key }, [h("h3", item.label), h("ul", item.sources.map((source) => h("li", [source.url ? h("a", { href: source.url, onClick: (event) => {
44
+ event.preventDefault();
45
+ emit("open", source.id);
46
+ } }, source.title) : source.title, source.snippet ? h("p", source.snippet) : null])))]);
47
+ }
48
+ if (key === "link-card") {
49
+ const item = LinkCardPropsSchema.parse(props.frame.props);
50
+ return h("a", { href: item.href, "data-ak-component": key, onClick: (event) => {
51
+ event.preventDefault();
52
+ emit("open", item.href);
53
+ } }, [h("strong", item.title), item.description, item.label]);
54
+ }
55
+ if (key === "error-notice") {
56
+ const item = ErrorNoticePropsSchema.parse(props.frame.props);
57
+ return h("section", { role: "alert", "data-ak-component": key }, [h("strong", item.title), h("p", item.message), item.code ? h("code", item.code) : null, item.retryLabel ? h("button", { disabled: props.disabled, onClick: () => emit("retry") }, item.retryLabel) : null]);
58
+ }
59
+ if (key === "tool-call") {
60
+ const item = ToolCallPropsSchema.parse(props.frame.props);
61
+ return h("section", { role: "status", "data-ak-component": key }, [h("strong", item.name), h("span", item.status), item.arguments ? h("pre", JSON.stringify(item.arguments, null, 2)) : null, item.result === void 0 ? null : h("pre", JSON.stringify(item.result, null, 2))]);
62
+ }
63
+ if (key === "approval-request") {
64
+ const item = ApprovalRequestPropsSchema.parse(props.frame.props);
65
+ return h("section", { "aria-label": item.title, "data-ak-component": key }, [h("h3", item.title), h("p", item.description), h("button", { disabled: props.disabled, onClick: () => emit("approve") }, item.approveLabel), h("button", { disabled: props.disabled, onClick: () => emit("deny") }, item.denyLabel)]);
66
+ }
67
+ if (key === "table") {
68
+ const item = TablePropsSchema.parse(props.frame.props);
69
+ return h("table", { "data-ak-component": key }, [h("caption", item.caption), h("thead", h("tr", item.columns.map((column) => h("th", { scope: "col" }, column.label)))), h("tbody", item.rows.map((row) => h("tr", item.columns.map((column) => h("td", String(row[column.key] ?? ""))))))]);
70
+ }
71
+ if (key === "file-attachment") {
72
+ const item = FileAttachmentPropsSchema.parse(props.frame.props);
73
+ return h("article", { "data-ak-component": key }, [h("strong", item.name), h("span", item.mimeType), item.sizeBytes === void 0 ? null : h("span", `${item.sizeBytes} bytes`), item.url ? h("a", { href: item.url, onClick: (event) => {
74
+ event.preventDefault();
75
+ emit("open", item.url);
76
+ } }, "Open") : null]);
77
+ }
78
+ return h("p", { "data-ak-component-fallback": "" }, resolveComponentFallback(props.frame, props.manifest) ?? "");
79
+ };
80
+ }
81
+ });
82
+
83
+ // src/index.ts
84
+ var toChatCssVariables = (input) => {
85
+ const theme = resolveChatTheme(input);
86
+ return {
87
+ "--ak-color-bg": theme.colors.background,
88
+ "--ak-color-surface": theme.colors.surface,
89
+ "--ak-color-border": theme.colors.border,
90
+ "--ak-color-text": theme.colors.text,
91
+ "--ak-color-text-muted": theme.colors.muted,
92
+ "--ak-color-bubble-user": theme.colors.accent,
93
+ "--ak-color-bubble-user-text": theme.colors.onAccent,
94
+ "--ak-color-bubble-assistant": theme.colors.surface,
95
+ "--ak-color-bubble-assistant-text": theme.colors.text,
96
+ "--ak-color-input-bg": theme.colors.background,
97
+ "--ak-color-input-border": theme.colors.border,
98
+ "--ak-color-input-focus": theme.colors.accent,
99
+ "--ak-color-button": theme.colors.accent,
100
+ "--ak-color-button-text": theme.colors.onAccent,
101
+ "--ak-color-tool-bg": theme.colors.surface,
102
+ "--ak-color-tool-border": theme.colors.border,
103
+ "--ak-app-color-danger": theme.colors.danger,
104
+ "--ak-font-family": theme.fontFamily === "system" ? "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif" : theme.fontFamily,
105
+ "--ak-radius": `${theme.radius.medium}px`,
106
+ "--ak-radius-lg": `${theme.radius.large}px`,
107
+ "--ak-spacing-sm": `${theme.spacing.small}px`,
108
+ "--ak-spacing-md": `${theme.spacing.medium}px`,
109
+ "--ak-spacing-lg": `${theme.spacing.large}px`
110
+ };
111
+ };
112
+ var ChoiceList = defineComponent2({
113
+ name: "AgentsKitChoiceList",
114
+ props: {
115
+ frame: { type: null, required: true },
116
+ manifest: { type: Object, required: true },
117
+ onSelect: { type: Function, required: true },
118
+ disabled: { type: Boolean, default: false }
119
+ },
120
+ setup(props) {
121
+ return () => {
122
+ const resolved = resolveChoiceListFrame(props.frame, props.manifest);
123
+ if (!resolved.ok) return null;
124
+ return h2("fieldset", { "aria-label": resolved.props.prompt, "data-ak-component": "choice-list" }, [
125
+ h2("legend", resolved.props.prompt),
126
+ ...resolved.props.choices.map((choice) => h2("button", {
127
+ key: choice.id,
128
+ type: "button",
129
+ disabled: props.disabled,
130
+ onClick: () => props.onSelect(selectChoice(resolved.frame, choice.id))
131
+ }, [h2("span", choice.label), choice.description === void 0 ? null : h2("small", choice.description)]))
132
+ ]);
133
+ };
134
+ }
135
+ });
136
+ var slot = (slots, name, props, fallback) => slots[name]?.(props) ?? fallback();
137
+ var agentChatProps = {
138
+ definition: { type: Object, required: true },
139
+ placeholder: { type: String, default: void 0 },
140
+ onComponentSelect: { type: Function, default: void 0 },
141
+ onComponentInteract: { type: Function, default: void 0 },
142
+ actionConfirmationTtlMs: { type: Number, default: void 0 },
143
+ session: { type: Object, default: void 0 },
144
+ theme: { type: Object, default: void 0 }
145
+ };
146
+ var ChatBinding = defineComponent2({
147
+ name: "AgentsKitChatBinding",
148
+ props: {
149
+ config: { type: Object, required: true },
150
+ onState: { type: Function, required: true }
151
+ },
152
+ setup(props, { slots }) {
153
+ const chat = useChat(props.config);
154
+ watchEffect(() => {
155
+ void chat.status;
156
+ void chat.messages;
157
+ props.onState(chat);
158
+ });
159
+ return () => slots.default?.({ chat });
160
+ }
161
+ });
162
+ var AgentChatSession = defineComponent2({
163
+ name: "AgentsKitChatSession",
164
+ props: agentChatProps,
165
+ slots: Object,
166
+ setup(props, { slots }) {
167
+ const session = resolveChatSession(props.definition, props.session);
168
+ const sessionId = session.sessionId;
169
+ let activeChat = props.definition.chat;
170
+ let pendingChat = activeChat;
171
+ let messages = activeChat.initialMessages;
172
+ let status = "idle";
173
+ let currentChat;
174
+ const bindingRevision = ref(0);
175
+ const actionError = ref();
176
+ const editDraft = ref();
177
+ const resolvedInstances = ref(/* @__PURE__ */ new Set());
178
+ const confirmation = session.createConfirmation({
179
+ ...props.actionConfirmationTtlMs === void 0 ? {} : { ttlMs: props.actionConfirmationTtlMs },
180
+ chat: {
181
+ proposeToolCall: (proposal) => currentChat.proposeToolCall(proposal),
182
+ approve: (id) => currentChat.approve(id),
183
+ deny: (id, reason) => currentChat.deny(id, reason)
184
+ }
185
+ });
186
+ const fail = (error, fallback) => {
187
+ actionError.value = error instanceof Error ? error : new Error(fallback);
188
+ };
189
+ const selectComponent = (event, frame) => {
190
+ if (resolvedInstances.value.has(event.instanceId)) return;
191
+ actionError.value = void 0;
192
+ resolvedInstances.value.add(event.instanceId);
193
+ try {
194
+ props.onComponentSelect?.(event);
195
+ } catch (error) {
196
+ fail(error, "Component selection callback failed.");
197
+ }
198
+ const action = resolveChoiceAction(frame, event.choiceId);
199
+ if (action) void confirmation.propose(action).catch((error) => {
200
+ resolvedInstances.value.delete(event.instanceId);
201
+ fail(error, "Action proposal failed.");
202
+ });
203
+ else {
204
+ let submission;
205
+ try {
206
+ submission = props.definition.choiceSubmission?.(frame, event.choiceId, { sessionId });
207
+ } catch (error) {
208
+ resolvedInstances.value.delete(event.instanceId);
209
+ fail(error, "Choice submission authorization failed.");
210
+ return;
211
+ }
212
+ if (submission && "unavailable" in submission) {
213
+ resolvedInstances.value.delete(event.instanceId);
214
+ fail(new Error("This deterministic choice expired. Ask the question again."), "Choice unavailable.");
215
+ return;
216
+ }
217
+ if (submission) void currentChat.send(submission.value).then(
218
+ () => {
219
+ try {
220
+ submission.commit();
221
+ } catch (error) {
222
+ fail(error, "Choice submission settlement failed.");
223
+ }
224
+ },
225
+ (error) => {
226
+ try {
227
+ submission.release();
228
+ } catch {
229
+ } finally {
230
+ resolvedInstances.value.delete(event.instanceId);
231
+ }
232
+ fail(error, "Choice submission failed.");
233
+ }
234
+ );
235
+ }
236
+ };
237
+ const approve = (toolCallId) => {
238
+ const record = confirmation.getByToolCall(toolCallId);
239
+ void (record ? confirmation.approve(record.token, sessionId) : currentChat.approve(toolCallId)).catch((error) => fail(error, "Action approval failed."));
240
+ };
241
+ const deny = (toolCallId, reason) => {
242
+ const record = confirmation.getByToolCall(toolCallId);
243
+ void (record ? confirmation.reject(record.token, sessionId, reason) : currentChat.deny(toolCallId, reason)).catch((error) => fail(error, "Action rejection failed."));
244
+ };
245
+ const runLifecycle = (operation) => {
246
+ actionError.value = void 0;
247
+ void operation.catch((error) => fail(error, "Lifecycle operation failed."));
248
+ };
249
+ const interactComponent = (event) => {
250
+ if (resolvedInstances.value.has(event.instanceId)) return;
251
+ resolvedInstances.value.add(event.instanceId);
252
+ try {
253
+ props.onComponentInteract?.(event);
254
+ } catch (error) {
255
+ resolvedInstances.value.delete(event.instanceId);
256
+ fail(error, "Component interaction callback failed.");
257
+ }
258
+ };
259
+ const renderChat = (chat) => {
260
+ currentChat = chat;
261
+ const nativeSlots = slots;
262
+ const targets = getLifecycleTargets(chat.messages);
263
+ const messages2 = chat.messages.flatMap((message) => presentChatMessage(message).map((presentation, index) => {
264
+ if (presentation.kind === "component") {
265
+ const manifest = props.definition.components;
266
+ const resolved = manifest === void 0 ? void 0 : resolveComponentFrame2(presentation.frame, manifest);
267
+ const rendered2 = resolved?.ok ? presentation.frame.componentKey === "choice-list" ? slot(nativeSlots, "choiceList", { frame: presentation.frame, manifest, disabled: resolvedInstances.value.has(presentation.frame.instanceId), onSelect: (event) => selectComponent(event, presentation.frame) }, () => h2(ChoiceList, { frame: presentation.frame, manifest, disabled: resolvedInstances.value.has(presentation.frame.instanceId), onSelect: (event) => selectComponent(event, presentation.frame) })) : slot(nativeSlots, "standardComponent", { frame: presentation.frame, manifest, disabled: resolvedInstances.value.has(presentation.frame.instanceId), onInteract: interactComponent }, () => h2(StandardComponent, { frame: presentation.frame, manifest, disabled: resolvedInstances.value.has(presentation.frame.instanceId), onInteract: interactComponent })) : h2("p", { "data-ak-component-fallback": "" }, formatSemanticFallback(presentation.frame.fallback));
268
+ return h2(Fragment, { key: `${message.id}:${index}` }, [rendered2]);
269
+ }
270
+ const rendered = presentation.kind === "diagnostic" ? h2("p", { role: "alert", "data-ak-component-diagnostic": presentation.code }, presentation.message) : slot(nativeSlots, "message", { message: presentation.message }, () => h2(Message, { message: presentation.message }));
271
+ return h2(Fragment, { key: `${message.id}:${index}` }, [rendered]);
272
+ }));
273
+ const confirmations = chat.messages.flatMap((message) => message.toolCalls ?? []).map((toolCall) => h2(Fragment, { key: toolCall.id }, [slot(nativeSlots, "confirmation", { toolCall, onApprove: approve, onDeny: deny }, () => h2(ToolConfirmation, { toolCall, onApprove: approve, onDeny: deny }))]));
274
+ const content = [...messages2, ...confirmations, slot(nativeSlots, "thinking", { visible: chat.status === "streaming" }, () => h2(ThinkingIndicator, { visible: chat.status === "streaming" }))];
275
+ const container = slot(nativeSlots, "container", { children: content }, () => h2(ChatRoot, {}, { default: () => content }));
276
+ const error = chat.error ?? actionError.value;
277
+ return h2("section", {
278
+ "aria-label": `${props.definition.id} chat`,
279
+ "data-ak-app-chat": "",
280
+ style: props.theme === void 0 ? void 0 : toChatCssVariables(props.theme)
281
+ }, [
282
+ h2("div", { "aria-live": "polite", "aria-relevant": "additions text", role: "log" }, [container]),
283
+ error ? h2("p", { role: "alert", style: { color: resolveChatTheme(props.theme).colors.danger } }, error.message) : null,
284
+ chat.status === "streaming" ? h2("button", { type: "button", onClick: chat.stop }, "Stop") : null,
285
+ chat.status !== "streaming" && targets.userId ? h2("div", { "aria-label": "Response actions" }, [
286
+ h2("button", { type: "button", "aria-label": "Retry response", onClick: () => runLifecycle(chat.retry()) }, "Retry"),
287
+ targets.assistantId ? h2("button", { type: "button", "aria-label": "Regenerate response", onClick: () => runLifecycle(chat.regenerate(targets.assistantId)) }, "Regenerate") : null,
288
+ h2("button", { type: "button", onClick: () => {
289
+ editDraft.value = { messageId: targets.userId, content: chat.messages.find((message) => message.id === targets.userId)?.content ?? "" };
290
+ } }, "Edit last message"),
291
+ editDraft.value === void 0 ? null : h2("form", { onSubmit: (event) => {
292
+ event.preventDefault();
293
+ if (!editDraft.value?.content.trim()) return;
294
+ runLifecycle(chat.edit(editDraft.value.messageId, editDraft.value.content));
295
+ editDraft.value = void 0;
296
+ } }, [
297
+ h2("label", ["Edit message", h2("input", { "aria-label": "Edit message", value: editDraft.value.content, onInput: (event) => {
298
+ editDraft.value = { ...editDraft.value, content: event.target.value };
299
+ } })]),
300
+ h2("button", { type: "submit", "aria-label": "Save edit" }, "Save edit"),
301
+ h2("button", { type: "button", onClick: () => {
302
+ editDraft.value = void 0;
303
+ } }, "Cancel edit")
304
+ ])
305
+ ]) : null,
306
+ slot(nativeSlots, "input", { chat, disabled: chat.status === "streaming", placeholder: props.placeholder }, () => h2(InputBar, { chat, disabled: chat.status === "streaming", ...props.placeholder === void 0 ? {} : { placeholder: props.placeholder } }))
307
+ ]);
308
+ };
309
+ return () => {
310
+ pendingChat = props.definition.chat;
311
+ if (activeChat !== pendingChat && status !== "streaming") {
312
+ activeChat = pendingChat;
313
+ bindingRevision.value += 1;
314
+ }
315
+ const config = session.updateChat({ ...activeChat, ...messages === void 0 ? {} : { initialMessages: messages } });
316
+ return h2(ChatBinding, {
317
+ key: bindingRevision.value,
318
+ config,
319
+ onState: (chat) => {
320
+ currentChat = chat;
321
+ messages = chat.messages;
322
+ status = chat.status;
323
+ if (activeChat !== pendingChat && status !== "streaming") {
324
+ activeChat = pendingChat;
325
+ bindingRevision.value += 1;
326
+ }
327
+ }
328
+ }, { default: ({ chat }) => renderChat(chat) });
329
+ };
330
+ }
331
+ });
332
+ var AgentChat = defineComponent2({
333
+ name: "AgentsKitChat",
334
+ props: agentChatProps,
335
+ slots: Object,
336
+ setup(props, { slots }) {
337
+ return () => h2(AgentChatSession, {
338
+ ...props,
339
+ key: `${props.definition.id}:${props.definition.revision ?? 1}:${props.session?.sessionId ?? "new"}`
340
+ }, slots);
341
+ }
342
+ });
343
+ export {
344
+ AgentChat,
345
+ ChoiceList,
346
+ StandardComponent,
347
+ toChatCssVariables
348
+ };
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@agentskit/chat-vue",
3
+ "version": "0.1.0",
4
+ "description": "Vue application shell for AgentsKit Chat.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/AgentsKit-io/agentskit-chat.git",
9
+ "directory": "packages/vue"
10
+ },
11
+ "homepage": "https://github.com/AgentsKit-io/agentskit-chat#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/AgentsKit-io/agentskit-chat/issues"
14
+ },
15
+ "type": "module",
16
+ "main": "./dist/index.cjs",
17
+ "module": "./dist/index.js",
18
+ "types": "./dist/index.d.ts",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "import": "./dist/index.js",
23
+ "require": "./dist/index.cjs"
24
+ }
25
+ },
26
+ "files": [
27
+ "dist"
28
+ ],
29
+ "dependencies": {
30
+ "@agentskit/chat": "0.1.0",
31
+ "@agentskit/chat-protocol": "0.1.0"
32
+ },
33
+ "peerDependencies": {
34
+ "@agentskit/vue": "^0.4.4",
35
+ "vue": "^3.4.0"
36
+ },
37
+ "devDependencies": {
38
+ "@agentskit/core": "^1.12.2",
39
+ "@agentskit/vue": "^0.4.4",
40
+ "happy-dom": "^20.10.3",
41
+ "tsup": "^8.5.1",
42
+ "vue": "^3.5.38"
43
+ },
44
+ "publishConfig": {
45
+ "access": "public",
46
+ "provenance": true
47
+ },
48
+ "scripts": {
49
+ "build": "tsup src/index.ts --format esm,cjs --dts --clean --external vue --external @agentskit/vue",
50
+ "lint": "tsc --noEmit",
51
+ "test": "pnpm --filter @agentskit/chat build && vitest run --environment happy-dom --coverage"
52
+ }
53
+ }