@aheart-ui/ai 0.0.0-stage → 1.0.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 +21 -0
- package/README.md +21 -2
- package/es/actions.vue.d.ts +34 -0
- package/es/actions.vue.js +27 -0
- package/es/actions.vue2.js +4 -0
- package/es/agent-execution.vue.d.ts +106 -0
- package/es/agent-execution.vue.js +441 -0
- package/es/agent-execution.vue2.js +4 -0
- package/es/agent-workbench.vue.d.ts +186 -0
- package/es/agent-workbench.vue.js +537 -0
- package/es/agent-workbench.vue2.js +4 -0
- package/es/attachments.vue.d.ts +39 -0
- package/es/attachments.vue.js +39 -0
- package/es/attachments.vue2.js +4 -0
- package/es/bubble.vue.d.ts +27 -0
- package/es/bubble.vue.js +82 -0
- package/es/bubble.vue2.js +4 -0
- package/es/chat-panel.vue.d.ts +108 -0
- package/es/chat-panel.vue.js +330 -0
- package/es/chat-panel.vue2.js +4 -0
- package/es/conversations.vue.d.ts +39 -0
- package/es/conversations.vue.js +29 -0
- package/es/conversations.vue2.js +4 -0
- package/es/form-field.vue.d.ts +28 -0
- package/es/form-field.vue.js +176 -0
- package/es/form-field.vue2.js +4 -0
- package/es/form-schema.d.ts +73 -0
- package/es/form-schema.js +105 -0
- package/es/form.vue.d.ts +81 -0
- package/es/form.vue.js +376 -0
- package/es/form.vue2.js +4 -0
- package/es/index.d.ts +20 -0
- package/es/index.js +42 -0
- package/es/package.json +3 -0
- package/es/process.vue.d.ts +30 -0
- package/es/process.vue.js +29 -0
- package/es/process.vue2.js +4 -0
- package/es/prompts.vue.d.ts +39 -0
- package/es/prompts.vue.js +33 -0
- package/es/prompts.vue2.js +4 -0
- package/es/safe-markdown.d.ts +3 -0
- package/es/safe-markdown.js +23 -0
- package/es/sender.vue.d.ts +52 -0
- package/es/sender.vue.js +46 -0
- package/es/sender.vue2.js +4 -0
- package/es/sources.vue.d.ts +30 -0
- package/es/sources.vue.js +34 -0
- package/es/sources.vue2.js +4 -0
- package/es/stream-reducer.d.ts +35 -0
- package/es/stream-reducer.js +85 -0
- package/es/style.css +1586 -0
- package/es/thought-chain.vue.d.ts +30 -0
- package/es/thought-chain.vue.js +15 -0
- package/es/thought-chain.vue2.js +4 -0
- package/es/types.d.ts +203 -0
- package/es/welcome.vue.d.ts +41 -0
- package/es/welcome.vue.js +27 -0
- package/es/welcome.vue2.js +4 -0
- package/lib/actions.vue.d.ts +34 -0
- package/lib/actions.vue.js +1 -0
- package/lib/actions.vue2.js +1 -0
- package/lib/agent-execution.vue.d.ts +106 -0
- package/lib/agent-execution.vue.js +1 -0
- package/lib/agent-execution.vue2.js +1 -0
- package/lib/agent-workbench.vue.d.ts +186 -0
- package/lib/agent-workbench.vue.js +1 -0
- package/lib/agent-workbench.vue2.js +1 -0
- package/lib/attachments.vue.d.ts +39 -0
- package/lib/attachments.vue.js +1 -0
- package/lib/attachments.vue2.js +1 -0
- package/lib/bubble.vue.d.ts +27 -0
- package/lib/bubble.vue.js +1 -0
- package/lib/bubble.vue2.js +1 -0
- package/lib/chat-panel.vue.d.ts +108 -0
- package/lib/chat-panel.vue.js +1 -0
- package/lib/chat-panel.vue2.js +1 -0
- package/lib/conversations.vue.d.ts +39 -0
- package/lib/conversations.vue.js +1 -0
- package/lib/conversations.vue2.js +1 -0
- package/lib/form-field.vue.d.ts +28 -0
- package/lib/form-field.vue.js +1 -0
- package/lib/form-field.vue2.js +1 -0
- package/lib/form-schema.d.ts +73 -0
- package/lib/form-schema.js +1 -0
- package/lib/form.vue.d.ts +81 -0
- package/lib/form.vue.js +1 -0
- package/lib/form.vue2.js +1 -0
- package/lib/index.d.ts +20 -0
- package/lib/index.js +1 -0
- package/lib/package.json +3 -0
- package/lib/process.vue.d.ts +30 -0
- package/lib/process.vue.js +1 -0
- package/lib/process.vue2.js +1 -0
- package/lib/prompts.vue.d.ts +39 -0
- package/lib/prompts.vue.js +1 -0
- package/lib/prompts.vue2.js +1 -0
- package/lib/safe-markdown.d.ts +3 -0
- package/lib/safe-markdown.js +2 -0
- package/lib/sender.vue.d.ts +52 -0
- package/lib/sender.vue.js +1 -0
- package/lib/sender.vue2.js +1 -0
- package/lib/sources.vue.d.ts +30 -0
- package/lib/sources.vue.js +1 -0
- package/lib/sources.vue2.js +1 -0
- package/lib/stream-reducer.d.ts +35 -0
- package/lib/stream-reducer.js +1 -0
- package/lib/style.css +1586 -0
- package/lib/thought-chain.vue.d.ts +30 -0
- package/lib/thought-chain.vue.js +1 -0
- package/lib/thought-chain.vue2.js +1 -0
- package/lib/types.d.ts +203 -0
- package/lib/welcome.vue.d.ts +41 -0
- package/lib/welcome.vue.js +1 -0
- package/lib/welcome.vue2.js +1 -0
- package/package.json +70 -3
package/es/bubble.vue.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { defineComponent as d, computed as c, openBlock as s, createElementBlock as a, normalizeClass as y, createElementVNode as t, toDisplayString as l, createVNode as r, unref as h, Fragment as i, createCommentVNode as n, renderSlot as f } from "vue";
|
|
2
|
+
import S from "./attachments.vue.js";
|
|
3
|
+
import k from "./process.vue.js";
|
|
4
|
+
import N from "./sources.vue.js";
|
|
5
|
+
import { renderSafeMarkdown as A } from "./safe-markdown.js";
|
|
6
|
+
const B = { class: "aheart-ai-bubble__header" }, $ = { class: "aheart-ai-bubble__content" }, I = {
|
|
7
|
+
key: 0,
|
|
8
|
+
class: "aheart-ai-bubble__tool-call",
|
|
9
|
+
"aria-label": "工具调用摘要"
|
|
10
|
+
}, R = { class: "aheart-ai-bubble__tool-heading" }, v = { class: "aheart-ai-bubble__tool-details" }, V = { key: 0 }, E = { key: 0 }, F = {
|
|
11
|
+
key: 1,
|
|
12
|
+
class: "aheart-ai-bubble__error"
|
|
13
|
+
}, M = /* @__PURE__ */ d({
|
|
14
|
+
name: "AAIBubble",
|
|
15
|
+
__name: "bubble",
|
|
16
|
+
props: {
|
|
17
|
+
message: {},
|
|
18
|
+
contentRenderer: { type: Function }
|
|
19
|
+
},
|
|
20
|
+
setup(e) {
|
|
21
|
+
const o = e, b = c(() => ({ user: "你", assistant: "AI 助手", system: "系统", tool: "工具" })[o.message.role]), g = c(() => {
|
|
22
|
+
var m;
|
|
23
|
+
return o.message.toolCall ? "" : ((m = o.contentRenderer) == null ? void 0 : m.call(o, o.message)) ?? A(o.message.content);
|
|
24
|
+
}), C = d({
|
|
25
|
+
name: "AIBubbleRenderNode",
|
|
26
|
+
props: {
|
|
27
|
+
node: { type: null, default: void 0 }
|
|
28
|
+
},
|
|
29
|
+
setup(m) {
|
|
30
|
+
return () => m.node;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
return (m, u) => (s(), a("article", {
|
|
34
|
+
class: y(["aheart-ai-bubble", `is-${e.message.role}`])
|
|
35
|
+
}, [
|
|
36
|
+
t("header", B, l(b.value), 1),
|
|
37
|
+
t("p", $, [
|
|
38
|
+
r(h(C), { node: g.value }, null, 8, ["node"])
|
|
39
|
+
]),
|
|
40
|
+
e.message.toolCall ? (s(), a("section", I, [
|
|
41
|
+
t("header", R, [
|
|
42
|
+
t("strong", null, l(e.message.toolCall.name), 1),
|
|
43
|
+
t("span", null, l(e.message.toolCall.summary), 1)
|
|
44
|
+
]),
|
|
45
|
+
t("dl", v, [
|
|
46
|
+
e.message.toolCall.inputSummary || e.message.toolCall.inputStatus ? (s(), a(i, { key: 0 }, [
|
|
47
|
+
u[0] || (u[0] = t("dt", null, "输入", -1)),
|
|
48
|
+
t("dd", null, [
|
|
49
|
+
t("span", null, l(e.message.toolCall.inputSummary), 1),
|
|
50
|
+
e.message.toolCall.inputStatus ? (s(), a("small", V, l(e.message.toolCall.inputStatus), 1)) : n("", !0)
|
|
51
|
+
])
|
|
52
|
+
], 64)) : n("", !0),
|
|
53
|
+
e.message.toolCall.resultSummary || e.message.toolCall.resultStatus ? (s(), a(i, { key: 1 }, [
|
|
54
|
+
u[1] || (u[1] = t("dt", null, "结果", -1)),
|
|
55
|
+
t("dd", null, [
|
|
56
|
+
t("span", null, l(e.message.toolCall.resultSummary), 1),
|
|
57
|
+
e.message.toolCall.resultStatus ? (s(), a("small", E, l(e.message.toolCall.resultStatus), 1)) : n("", !0)
|
|
58
|
+
])
|
|
59
|
+
], 64)) : n("", !0),
|
|
60
|
+
e.message.toolCall.error ? (s(), a(i, { key: 2 }, [
|
|
61
|
+
u[2] || (u[2] = t("dt", null, "错误", -1)),
|
|
62
|
+
t("dd", null, l(e.message.toolCall.error), 1)
|
|
63
|
+
], 64)) : n("", !0)
|
|
64
|
+
])
|
|
65
|
+
])) : n("", !0),
|
|
66
|
+
e.message.error ? (s(), a("p", F, l(e.message.error), 1)) : n("", !0),
|
|
67
|
+
r(k, {
|
|
68
|
+
items: e.message.process
|
|
69
|
+
}, null, 8, ["items"]),
|
|
70
|
+
r(N, {
|
|
71
|
+
sources: e.message.sources
|
|
72
|
+
}, null, 8, ["sources"]),
|
|
73
|
+
r(S, {
|
|
74
|
+
items: e.message.attachments
|
|
75
|
+
}, null, 8, ["items"]),
|
|
76
|
+
f(m.$slots, "actions", { message: e.message })
|
|
77
|
+
], 2));
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
export {
|
|
81
|
+
M as default
|
|
82
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { AIAttachment, AIConversation, AIMessage, AIPrompt, AITransport, AITransportV2 } from './types';
|
|
2
|
+
declare const _default: import("@vue/runtime-core").DefineComponent<import("@vue/runtime-core").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
|
|
3
|
+
messages?: AIMessage[] | undefined;
|
|
4
|
+
defaultMessages?: AIMessage[] | undefined;
|
|
5
|
+
transport: AITransport | AITransportV2;
|
|
6
|
+
conversationId?: string | undefined;
|
|
7
|
+
conversations?: AIConversation[] | undefined;
|
|
8
|
+
activeConversation?: string | undefined;
|
|
9
|
+
prompts?: AIPrompt[] | undefined;
|
|
10
|
+
attachments?: AIAttachment[] | undefined;
|
|
11
|
+
welcomeTitle?: string | undefined;
|
|
12
|
+
welcomeDescription?: string | undefined;
|
|
13
|
+
disabled?: boolean | undefined;
|
|
14
|
+
maxReconnectAttempts?: number | undefined;
|
|
15
|
+
}>, {
|
|
16
|
+
messages: () => never[];
|
|
17
|
+
defaultMessages: () => never[];
|
|
18
|
+
conversationId: undefined;
|
|
19
|
+
conversations: () => never[];
|
|
20
|
+
activeConversation: undefined;
|
|
21
|
+
prompts: () => never[];
|
|
22
|
+
attachments: () => never[];
|
|
23
|
+
welcomeTitle: string;
|
|
24
|
+
welcomeDescription: string;
|
|
25
|
+
disabled: boolean;
|
|
26
|
+
maxReconnectAttempts: number;
|
|
27
|
+
}>>, {}, {}, {}, {}, import("@vue/runtime-core").ComponentOptionsMixin, import("@vue/runtime-core").ComponentOptionsMixin, {
|
|
28
|
+
error: (error: string) => void;
|
|
29
|
+
send: (content: string) => void;
|
|
30
|
+
retry: (message: AIMessage) => void;
|
|
31
|
+
regenerate: (message: AIMessage) => void;
|
|
32
|
+
edit: (message: AIMessage, content: string) => void;
|
|
33
|
+
copy: (message: AIMessage) => void;
|
|
34
|
+
stop: () => void;
|
|
35
|
+
"update:messages": (messages: AIMessage[]) => void;
|
|
36
|
+
"update:activeConversation": (key: string) => void;
|
|
37
|
+
"update:attachments": (attachments: AIAttachment[]) => void;
|
|
38
|
+
"stream-status": (status: string) => void;
|
|
39
|
+
"stream-reject": (reason: string) => void;
|
|
40
|
+
}, string, import("@vue/runtime-core").PublicProps, Readonly<import("@vue/runtime-core").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
|
|
41
|
+
messages?: AIMessage[] | undefined;
|
|
42
|
+
defaultMessages?: AIMessage[] | undefined;
|
|
43
|
+
transport: AITransport | AITransportV2;
|
|
44
|
+
conversationId?: string | undefined;
|
|
45
|
+
conversations?: AIConversation[] | undefined;
|
|
46
|
+
activeConversation?: string | undefined;
|
|
47
|
+
prompts?: AIPrompt[] | undefined;
|
|
48
|
+
attachments?: AIAttachment[] | undefined;
|
|
49
|
+
welcomeTitle?: string | undefined;
|
|
50
|
+
welcomeDescription?: string | undefined;
|
|
51
|
+
disabled?: boolean | undefined;
|
|
52
|
+
maxReconnectAttempts?: number | undefined;
|
|
53
|
+
}>, {
|
|
54
|
+
messages: () => never[];
|
|
55
|
+
defaultMessages: () => never[];
|
|
56
|
+
conversationId: undefined;
|
|
57
|
+
conversations: () => never[];
|
|
58
|
+
activeConversation: undefined;
|
|
59
|
+
prompts: () => never[];
|
|
60
|
+
attachments: () => never[];
|
|
61
|
+
welcomeTitle: string;
|
|
62
|
+
welcomeDescription: string;
|
|
63
|
+
disabled: boolean;
|
|
64
|
+
maxReconnectAttempts: number;
|
|
65
|
+
}>>> & Readonly<{
|
|
66
|
+
onError?: ((error: string) => any) | undefined;
|
|
67
|
+
onSend?: ((content: string) => any) | undefined;
|
|
68
|
+
onRetry?: ((message: AIMessage) => any) | undefined;
|
|
69
|
+
onRegenerate?: ((message: AIMessage) => any) | undefined;
|
|
70
|
+
onEdit?: ((message: AIMessage, content: string) => any) | undefined;
|
|
71
|
+
onCopy?: ((message: AIMessage) => any) | undefined;
|
|
72
|
+
onStop?: (() => any) | undefined;
|
|
73
|
+
"onUpdate:messages"?: ((messages: AIMessage[]) => any) | undefined;
|
|
74
|
+
"onUpdate:activeConversation"?: ((key: string) => any) | undefined;
|
|
75
|
+
"onUpdate:attachments"?: ((attachments: AIAttachment[]) => any) | undefined;
|
|
76
|
+
"onStream-status"?: ((status: string) => any) | undefined;
|
|
77
|
+
"onStream-reject"?: ((reason: string) => any) | undefined;
|
|
78
|
+
}>, {
|
|
79
|
+
conversationId: string;
|
|
80
|
+
messages: AIMessage[];
|
|
81
|
+
disabled: boolean;
|
|
82
|
+
attachments: AIAttachment[];
|
|
83
|
+
conversations: AIConversation[];
|
|
84
|
+
prompts: AIPrompt[];
|
|
85
|
+
defaultMessages: AIMessage[];
|
|
86
|
+
activeConversation: string;
|
|
87
|
+
welcomeTitle: string;
|
|
88
|
+
welcomeDescription: string;
|
|
89
|
+
maxReconnectAttempts: number;
|
|
90
|
+
}, {}, {}, {}, string, import("@vue/runtime-core").ComponentProvideOptions, true, {}, any>;
|
|
91
|
+
export default _default;
|
|
92
|
+
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
93
|
+
type __VLS_TypePropsToRuntimeProps<T> = {
|
|
94
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
95
|
+
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
96
|
+
} : {
|
|
97
|
+
type: import('vue').PropType<T[K]>;
|
|
98
|
+
required: true;
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
type __VLS_WithDefaults<P, D> = {
|
|
102
|
+
[K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & {
|
|
103
|
+
default: D[K];
|
|
104
|
+
}> : P[K];
|
|
105
|
+
};
|
|
106
|
+
type __VLS_Prettify<T> = {
|
|
107
|
+
[K in keyof T]: T[K];
|
|
108
|
+
} & {};
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import { defineComponent as he, getCurrentInstance as ke, ref as k, onBeforeUpdate as Ce, computed as X, watch as Y, onBeforeUnmount as _e, openBlock as g, createElementBlock as C, createBlock as oe, createCommentVNode as E, createElementVNode as U, Fragment as xe, renderList as $e, withCtx as we, createVNode as z, toDisplayString as Ie } from "vue";
|
|
2
|
+
import Ae from "./attachments.vue.js";
|
|
3
|
+
import Se from "./bubble.vue.js";
|
|
4
|
+
import Re from "./conversations.vue.js";
|
|
5
|
+
import Ve from "./prompts.vue.js";
|
|
6
|
+
import Ee from "./sender.vue.js";
|
|
7
|
+
import Be from "./welcome.vue.js";
|
|
8
|
+
import { createAIStreamReducer as De } from "./stream-reducer.js";
|
|
9
|
+
const Me = {
|
|
10
|
+
class: "aheart-ai-chat-panel",
|
|
11
|
+
"aria-label": "AI 对话"
|
|
12
|
+
}, Ue = { class: "aheart-ai-chat-panel__surface" }, Pe = {
|
|
13
|
+
key: 0,
|
|
14
|
+
class: "aheart-ai-chat-panel__messages",
|
|
15
|
+
role: "log",
|
|
16
|
+
"aria-live": "polite",
|
|
17
|
+
"aria-relevant": "additions text"
|
|
18
|
+
}, Ne = {
|
|
19
|
+
class: "aheart-ai-chat-panel__message-actions",
|
|
20
|
+
"aria-label": "消息操作"
|
|
21
|
+
}, Te = ["aria-label", "onClick"], je = ["disabled", "onClick"], Fe = ["disabled", "onClick"], Oe = ["disabled", "onClick"], Ke = {
|
|
22
|
+
key: 1,
|
|
23
|
+
class: "aheart-ai-chat-panel__empty"
|
|
24
|
+
}, Le = { class: "aheart-ai-chat-panel__composer" }, ze = {
|
|
25
|
+
key: 0,
|
|
26
|
+
class: "aheart-ai-chat-panel__stream-reconnecting",
|
|
27
|
+
role: "status",
|
|
28
|
+
"aria-live": "polite"
|
|
29
|
+
}, Ge = {
|
|
30
|
+
key: 1,
|
|
31
|
+
class: "aheart-ai-chat-panel__editing",
|
|
32
|
+
role: "status"
|
|
33
|
+
}, He = {
|
|
34
|
+
class: "aheart-ai-visually-hidden",
|
|
35
|
+
role: "status",
|
|
36
|
+
"aria-live": "polite"
|
|
37
|
+
}, tt = /* @__PURE__ */ he({
|
|
38
|
+
name: "AAIChatPanel",
|
|
39
|
+
__name: "chat-panel",
|
|
40
|
+
props: {
|
|
41
|
+
messages: { default: () => [] },
|
|
42
|
+
defaultMessages: { default: () => [] },
|
|
43
|
+
transport: {},
|
|
44
|
+
conversationId: { default: void 0 },
|
|
45
|
+
conversations: { default: () => [] },
|
|
46
|
+
activeConversation: { default: void 0 },
|
|
47
|
+
prompts: { default: () => [] },
|
|
48
|
+
attachments: { default: () => [] },
|
|
49
|
+
welcomeTitle: { default: "你好,我能为你做些什么?" },
|
|
50
|
+
welcomeDescription: { default: "描述目标、补充上下文,或从建议任务开始。" },
|
|
51
|
+
disabled: { type: Boolean, default: !1 },
|
|
52
|
+
maxReconnectAttempts: { default: 1 }
|
|
53
|
+
},
|
|
54
|
+
emits: ["update:messages", "update:activeConversation", "update:attachments", "send", "stop", "retry", "regenerate", "edit", "copy", "error", "stream-status", "stream-reject"],
|
|
55
|
+
setup(m, { emit: re }) {
|
|
56
|
+
const i = m, n = re, _ = ke(), Z = (e) => Object.prototype.hasOwnProperty.call((_ == null ? void 0 : _.vnode.props) ?? {}, e), q = k(Z("messages"));
|
|
57
|
+
Ce(() => {
|
|
58
|
+
q.value = Z("messages");
|
|
59
|
+
});
|
|
60
|
+
const f = () => q.value, G = k([...i.defaultMessages]), l = k(f() ? [...i.messages] : [...G.value]), S = k(""), u = k(!1), y = k(), R = k(), B = k(), P = k(""), x = k("idle");
|
|
61
|
+
let p = 0, ne = 0;
|
|
62
|
+
const w = X(() => f() ? i.messages : G.value), H = X(() => i.conversationId ?? i.activeConversation), le = X(() => {
|
|
63
|
+
if (x.value === "reconnecting") return "";
|
|
64
|
+
if (!f() && u.value && P.value) return `AI 回复:${P.value}`;
|
|
65
|
+
const e = [...w.value].reverse().find((a) => a.role === "assistant");
|
|
66
|
+
return e ? e.status === "streaming" ? "正在生成" : e.status === "stopped" ? "已停止生成" : e.status === "error" ? "生成失败" : e.status === "complete" ? "已完成生成" : "" : "";
|
|
67
|
+
}), $ = (e) => {
|
|
68
|
+
e === "idle" && u.value && (x.value === "streaming" || x.value === "reconnecting") || x.value !== e && (x.value = e, n("stream-status", e));
|
|
69
|
+
};
|
|
70
|
+
Y(
|
|
71
|
+
() => i.messages,
|
|
72
|
+
(e) => {
|
|
73
|
+
f() && !u.value && (l.value = [...e]);
|
|
74
|
+
},
|
|
75
|
+
{ deep: !0 }
|
|
76
|
+
);
|
|
77
|
+
const T = (e) => `${e}-${Date.now()}-${ne++}`, D = (e) => {
|
|
78
|
+
l.value = e, f() || (G.value = e), n("update:messages", e);
|
|
79
|
+
}, j = (e, a) => {
|
|
80
|
+
D(l.value.map((t) => t.id === e ? { ...t, ...a } : t));
|
|
81
|
+
}, ie = (e, a, t) => e == null ? void 0 : e.map((s) => s.status === "pending" || s.status === "running" ? { ...s, status: a, ...t && !s.detail ? { detail: t } : {} } : s), M = (e, a, t) => {
|
|
82
|
+
const s = l.value.find((d) => d.id === e);
|
|
83
|
+
if (!s) return;
|
|
84
|
+
const o = a === "complete" ? "complete" : a === "stopped" ? "stopped" : "error";
|
|
85
|
+
j(e, {
|
|
86
|
+
status: a,
|
|
87
|
+
...t ? { error: t } : {},
|
|
88
|
+
process: ie(s.process, o, t)
|
|
89
|
+
}), a === "complete" ? $("completed") : a === "stopped" ? $("cancelled") : a === "error" && $("error");
|
|
90
|
+
}, ce = (e, a) => {
|
|
91
|
+
const t = l.value.find((s) => s.id === e);
|
|
92
|
+
if (!t) return !1;
|
|
93
|
+
if (a.type === "text-delta")
|
|
94
|
+
f() || (P.value = a.delta), j(e, { content: `${t.content}${a.delta}` });
|
|
95
|
+
else if (a.type === "process") {
|
|
96
|
+
const s = [...(t.process ?? []).filter((o) => o.id !== a.item.id), a.item];
|
|
97
|
+
j(e, { process: s });
|
|
98
|
+
} else if (a.type === "sources")
|
|
99
|
+
j(e, { sources: a.sources });
|
|
100
|
+
else {
|
|
101
|
+
if (a.type === "done")
|
|
102
|
+
return M(e, "complete"), !0;
|
|
103
|
+
if (a.type === "cancelled")
|
|
104
|
+
return M(e, "stopped"), !0;
|
|
105
|
+
if (a.type === "error")
|
|
106
|
+
return M(e, "error", a.error), n("error", a.error), !0;
|
|
107
|
+
}
|
|
108
|
+
return !1;
|
|
109
|
+
}, J = async (e, a = {}) => {
|
|
110
|
+
var te, ae, se;
|
|
111
|
+
const t = {
|
|
112
|
+
id: T("assistant"),
|
|
113
|
+
role: "assistant",
|
|
114
|
+
content: "",
|
|
115
|
+
status: "streaming"
|
|
116
|
+
}, s = ((ae = (te = _ == null ? void 0 : _.proxy) == null ? void 0 : te.$el) == null ? void 0 : ae.ownerDocument) ?? (typeof document < "u" ? document : void 0), o = new (((se = s == null ? void 0 : s.defaultView) == null ? void 0 : se.AbortController) ?? AbortController)(), d = ++p, r = i.transport, N = r && "version" in r && r.version === "2", F = T("request");
|
|
117
|
+
u.value = !0, $("streaming"), y.value = o, R.value = t.id, P.value = "", N && f() ? l.value = [...e, t] : D([...e, t]), N && f() && n("update:messages", [...e, t]);
|
|
118
|
+
try {
|
|
119
|
+
if (N) {
|
|
120
|
+
const b = {
|
|
121
|
+
version: "2",
|
|
122
|
+
requestId: F,
|
|
123
|
+
messageId: t.id,
|
|
124
|
+
idempotencyKey: T("idempotency"),
|
|
125
|
+
conversationId: H.value,
|
|
126
|
+
messages: e,
|
|
127
|
+
...a.action && { action: a.action },
|
|
128
|
+
...a.messageId && { targetMessageId: a.messageId }
|
|
129
|
+
}, c = De({ requestId: F, messageId: t.id, maxReconnectAttempts: i.maxReconnectAttempts });
|
|
130
|
+
let V = r.send(b, o.signal), O = 0, K = !1, L = !1;
|
|
131
|
+
for (; !K; )
|
|
132
|
+
try {
|
|
133
|
+
for await (const h of V) {
|
|
134
|
+
if (d !== p || o.signal.aborted) break;
|
|
135
|
+
const v = c.dispatch(h);
|
|
136
|
+
if (v.diagnostic.kind === "protocol-error") {
|
|
137
|
+
const Q = c.failRecovery(`协议错误:${v.diagnostic.reason ?? "invalid envelope"}`, !1);
|
|
138
|
+
n("stream-reject", v.diagnostic.reason ?? "协议错误"), $(Q.status), n("error", Q.message.error ?? "协议错误");
|
|
139
|
+
const ye = { ...t, ...Q.message };
|
|
140
|
+
l.value = [...e, ye], f() ? n("update:messages", l.value) : D(l.value), L = !0, K = !0;
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
$(v.status), (v.status === "completed" || v.status === "cancelled" || v.status === "error") && (K = !0);
|
|
144
|
+
const be = { ...t, ...v.message };
|
|
145
|
+
if (l.value = [...e, be], f() ? n("update:messages", l.value) : D(l.value), !f() && h.type === "text-delta" && v.diagnostic.kind === "accepted" && (P.value = h.delta), v.status === "completed" || v.status === "cancelled" || v.status === "error") {
|
|
146
|
+
K = !0;
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
if (v.recoveryRequired) break;
|
|
150
|
+
}
|
|
151
|
+
if (d !== p || o.signal.aborted) break;
|
|
152
|
+
const I = c.getState();
|
|
153
|
+
if (I.status === "completed" || I.status === "cancelled" || I.status === "error") break;
|
|
154
|
+
if (L || !("resume" in r) || !r.resume || O >= Math.max(0, Number.isSafeInteger(i.maxReconnectAttempts) ? i.maxReconnectAttempts : 1)) {
|
|
155
|
+
let h = r.resume ? c.recover({ reason: L ? "protocol" : "eof" }) : c.failRecovery("连接中断,请重试");
|
|
156
|
+
h.status === "reconnecting" && L && (h = c.failRecovery("协议错误", !1)), $(h.status);
|
|
157
|
+
const v = { ...t, ...h.message };
|
|
158
|
+
l.value = [...e, v], f() ? n("update:messages", l.value) : D(l.value);
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
O += 1;
|
|
162
|
+
const A = c.recover({ reason: "eof" });
|
|
163
|
+
$(A.status), V = r.resume({ ...b, resume: c.getState().cursor }, o.signal);
|
|
164
|
+
} catch {
|
|
165
|
+
if (d !== p || o.signal.aborted) break;
|
|
166
|
+
let A = r.resume ? c.recover({ reason: "transport" }) : c.failRecovery("连接中断,请重试", !0);
|
|
167
|
+
if ($(A.status), A.status === "error") {
|
|
168
|
+
const h = { ...t, ...A.message };
|
|
169
|
+
l.value = [...e, h], f() ? n("update:messages", l.value) : D(l.value);
|
|
170
|
+
}
|
|
171
|
+
if (!("resume" in r) || !r.resume || A.status === "error" || O >= (i.maxReconnectAttempts ?? 1)) break;
|
|
172
|
+
O += 1, V = r.resume({ ...b, resume: c.getState().cursor }, o.signal);
|
|
173
|
+
}
|
|
174
|
+
if (d === p && !o.signal.aborted) {
|
|
175
|
+
const I = c.getState(), A = { ...t, ...I.message };
|
|
176
|
+
l.value = [...e, A], I.status === "error" && n("error", I.message.error ?? "生成失败");
|
|
177
|
+
}
|
|
178
|
+
} else {
|
|
179
|
+
const b = r;
|
|
180
|
+
for await (const V of b.send({ conversationId: H.value, messages: e, ...a.action && { action: a.action }, ...a.messageId && { messageId: a.messageId } }, o.signal))
|
|
181
|
+
if (d !== p || o.signal.aborted || ce(t.id, V)) break;
|
|
182
|
+
const c = l.value.find((V) => V.id === t.id);
|
|
183
|
+
(c == null ? void 0 : c.status) === "streaming" && d === p && M(t.id, "complete");
|
|
184
|
+
}
|
|
185
|
+
} catch (b) {
|
|
186
|
+
const c = String(b instanceof Error ? b.message : b);
|
|
187
|
+
if (o.signal.aborted || d !== p)
|
|
188
|
+
return;
|
|
189
|
+
M(t.id, "error", c), n("error", c);
|
|
190
|
+
} finally {
|
|
191
|
+
y.value === o && (u.value = !1, x.value = w.value.some((b) => b.status === "streaming") ? "streaming" : "idle", y.value = void 0, R.value = void 0, l.value = [...w.value]);
|
|
192
|
+
}
|
|
193
|
+
}, W = async (e) => {
|
|
194
|
+
const a = (e ?? S.value).trim();
|
|
195
|
+
if (!a || u.value || i.disabled) return;
|
|
196
|
+
if (B.value) {
|
|
197
|
+
const o = B.value, d = [...w.value], r = d.findIndex((F) => F.id === o.id);
|
|
198
|
+
if (r < 0) return;
|
|
199
|
+
const N = { ...o, content: a, status: "complete" };
|
|
200
|
+
S.value = "", B.value = void 0, n("edit", o, a), await J([...d.slice(0, r), N], { action: "edit", messageId: o.id });
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
const t = {
|
|
204
|
+
id: T("user"),
|
|
205
|
+
role: "user",
|
|
206
|
+
content: a,
|
|
207
|
+
status: "complete",
|
|
208
|
+
...i.attachments.length && { attachments: [...i.attachments] }
|
|
209
|
+
}, s = [...w.value, t];
|
|
210
|
+
S.value = "", n("send", a), i.attachments.length && n("update:attachments", []), await J(s);
|
|
211
|
+
}, ee = async (e, a) => {
|
|
212
|
+
if (u.value || i.disabled) return;
|
|
213
|
+
const t = [...w.value], s = t.findIndex((r) => r.id === e.id);
|
|
214
|
+
if (s < 1) return;
|
|
215
|
+
const o = t.slice(0, s);
|
|
216
|
+
[...o].reverse().find((r) => r.role === "user") && (n(a === "retry" ? "retry" : "regenerate", e), await J(o, { action: a, messageId: e.id }));
|
|
217
|
+
}, ue = (e) => ee(e, "retry"), de = (e) => ee(e, "regenerate"), ve = (e) => {
|
|
218
|
+
u.value || i.disabled || (B.value = e, S.value = e.content);
|
|
219
|
+
}, me = () => {
|
|
220
|
+
B.value = void 0, S.value = "";
|
|
221
|
+
}, fe = (e) => {
|
|
222
|
+
var t, s, o, d, r;
|
|
223
|
+
const a = (o = (s = (t = _ == null ? void 0 : _.proxy) == null ? void 0 : t.$el) == null ? void 0 : s.ownerDocument) == null ? void 0 : o.defaultView;
|
|
224
|
+
(r = (d = a == null ? void 0 : a.navigator) == null ? void 0 : d.clipboard) == null || r.writeText(e.content), n("copy", e);
|
|
225
|
+
}, pe = (e) => {
|
|
226
|
+
n("update:attachments", i.attachments.filter((a) => a.id !== e.id));
|
|
227
|
+
}, ge = () => {
|
|
228
|
+
p += 1;
|
|
229
|
+
const e = y.value;
|
|
230
|
+
R.value && M(R.value, "stopped"), e == null || e.abort(), y.value = void 0, R.value = void 0, u.value = !1, n("stop");
|
|
231
|
+
};
|
|
232
|
+
return Y(H, (e, a) => {
|
|
233
|
+
var t;
|
|
234
|
+
e !== a && (p += 1, (t = y.value) == null || t.abort(), y.value = void 0, R.value = void 0, u.value = !1, x.value = "idle");
|
|
235
|
+
}), Y(() => i.transport, (e, a) => {
|
|
236
|
+
var t;
|
|
237
|
+
e !== a && (p += 1, (t = y.value) == null || t.abort(), y.value = void 0, R.value = void 0, u.value = !1, x.value = "idle");
|
|
238
|
+
}), _e(() => {
|
|
239
|
+
var e;
|
|
240
|
+
p += 1, (e = y.value) == null || e.abort();
|
|
241
|
+
}), (e, a) => (g(), C("section", Me, [
|
|
242
|
+
m.conversations.length ? (g(), oe(Re, {
|
|
243
|
+
key: 0,
|
|
244
|
+
"model-value": m.activeConversation,
|
|
245
|
+
conversations: m.conversations,
|
|
246
|
+
"onUpdate:modelValue": a[0] || (a[0] = (t) => n("update:activeConversation", t))
|
|
247
|
+
}, null, 8, ["model-value", "conversations"])) : E("", !0),
|
|
248
|
+
U("div", Ue, [
|
|
249
|
+
w.value.length ? (g(), C("div", Pe, [
|
|
250
|
+
(g(!0), C(xe, null, $e(w.value, (t) => (g(), oe(Se, {
|
|
251
|
+
key: t.id,
|
|
252
|
+
"data-message-id": t.id,
|
|
253
|
+
message: t
|
|
254
|
+
}, {
|
|
255
|
+
actions: we(() => [
|
|
256
|
+
U("div", Ne, [
|
|
257
|
+
t.content ? (g(), C("button", {
|
|
258
|
+
key: 0,
|
|
259
|
+
type: "button",
|
|
260
|
+
"data-action": "copy",
|
|
261
|
+
"aria-label": `复制${t.role === "user" ? "问题" : "回答"}`,
|
|
262
|
+
onClick: (s) => fe(t)
|
|
263
|
+
}, " 复制 ", 8, Te)) : E("", !0),
|
|
264
|
+
t.role === "user" ? (g(), C("button", {
|
|
265
|
+
key: 1,
|
|
266
|
+
type: "button",
|
|
267
|
+
"data-action": "edit",
|
|
268
|
+
disabled: m.disabled || u.value,
|
|
269
|
+
onClick: (s) => ve(t)
|
|
270
|
+
}, " 编辑 ", 8, je)) : E("", !0),
|
|
271
|
+
t.role === "assistant" && (t.status === "error" || t.status === "stopped") && t.retryable !== !1 ? (g(), C("button", {
|
|
272
|
+
key: 2,
|
|
273
|
+
type: "button",
|
|
274
|
+
"data-action": "retry",
|
|
275
|
+
disabled: m.disabled || u.value,
|
|
276
|
+
onClick: (s) => ue(t)
|
|
277
|
+
}, " 重试 ", 8, Fe)) : E("", !0),
|
|
278
|
+
t.role === "assistant" && t.status === "complete" ? (g(), C("button", {
|
|
279
|
+
key: 3,
|
|
280
|
+
type: "button",
|
|
281
|
+
"data-action": "regenerate",
|
|
282
|
+
disabled: m.disabled || u.value,
|
|
283
|
+
onClick: (s) => de(t)
|
|
284
|
+
}, " 重新生成 ", 8, Oe)) : E("", !0)
|
|
285
|
+
])
|
|
286
|
+
]),
|
|
287
|
+
_: 2
|
|
288
|
+
}, 1032, ["data-message-id", "message"]))), 128))
|
|
289
|
+
])) : (g(), C("div", Ke, [
|
|
290
|
+
z(Be, {
|
|
291
|
+
title: m.welcomeTitle,
|
|
292
|
+
description: m.welcomeDescription
|
|
293
|
+
}, null, 8, ["title", "description"]),
|
|
294
|
+
z(Ve, {
|
|
295
|
+
prompts: m.prompts,
|
|
296
|
+
disabled: m.disabled || u.value,
|
|
297
|
+
onSelect: a[1] || (a[1] = (t) => W(t.label))
|
|
298
|
+
}, null, 8, ["prompts", "disabled"])
|
|
299
|
+
])),
|
|
300
|
+
U("div", Le, [
|
|
301
|
+
x.value === "reconnecting" ? (g(), C("p", ze, "正在恢复连接")) : E("", !0),
|
|
302
|
+
B.value ? (g(), C("div", Ge, [
|
|
303
|
+
a[3] || (a[3] = U("span", null, "正在编辑已发送的问题", -1)),
|
|
304
|
+
U("button", {
|
|
305
|
+
type: "button",
|
|
306
|
+
onClick: me
|
|
307
|
+
}, "取消编辑")
|
|
308
|
+
])) : E("", !0),
|
|
309
|
+
z(Ae, {
|
|
310
|
+
items: m.attachments,
|
|
311
|
+
removable: "",
|
|
312
|
+
onRemove: pe
|
|
313
|
+
}, null, 8, ["items"]),
|
|
314
|
+
z(Ee, {
|
|
315
|
+
modelValue: S.value,
|
|
316
|
+
"onUpdate:modelValue": a[2] || (a[2] = (t) => S.value = t),
|
|
317
|
+
disabled: m.disabled,
|
|
318
|
+
loading: u.value,
|
|
319
|
+
onSubmit: W,
|
|
320
|
+
onStop: ge
|
|
321
|
+
}, null, 8, ["modelValue", "disabled", "loading"])
|
|
322
|
+
])
|
|
323
|
+
]),
|
|
324
|
+
U("p", He, Ie(le.value), 1)
|
|
325
|
+
]));
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
export {
|
|
329
|
+
tt as default
|
|
330
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { AIConversation } from './types';
|
|
2
|
+
declare const _default: import("@vue/runtime-core").DefineComponent<import("@vue/runtime-core").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
|
|
3
|
+
modelValue?: string | undefined;
|
|
4
|
+
conversations?: AIConversation[] | undefined;
|
|
5
|
+
}>, {
|
|
6
|
+
modelValue: undefined;
|
|
7
|
+
conversations: () => never[];
|
|
8
|
+
}>>, {}, {}, {}, {}, import("@vue/runtime-core").ComponentOptionsMixin, import("@vue/runtime-core").ComponentOptionsMixin, {
|
|
9
|
+
"update:modelValue": (key: string) => void;
|
|
10
|
+
}, string, import("@vue/runtime-core").PublicProps, Readonly<import("@vue/runtime-core").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
|
|
11
|
+
modelValue?: string | undefined;
|
|
12
|
+
conversations?: AIConversation[] | undefined;
|
|
13
|
+
}>, {
|
|
14
|
+
modelValue: undefined;
|
|
15
|
+
conversations: () => never[];
|
|
16
|
+
}>>> & Readonly<{
|
|
17
|
+
"onUpdate:modelValue"?: ((key: string) => any) | undefined;
|
|
18
|
+
}>, {
|
|
19
|
+
modelValue: string;
|
|
20
|
+
conversations: AIConversation[];
|
|
21
|
+
}, {}, {}, {}, string, import("@vue/runtime-core").ComponentProvideOptions, true, {}, any>;
|
|
22
|
+
export default _default;
|
|
23
|
+
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
24
|
+
type __VLS_TypePropsToRuntimeProps<T> = {
|
|
25
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
26
|
+
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
27
|
+
} : {
|
|
28
|
+
type: import('vue').PropType<T[K]>;
|
|
29
|
+
required: true;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
type __VLS_WithDefaults<P, D> = {
|
|
33
|
+
[K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & {
|
|
34
|
+
default: D[K];
|
|
35
|
+
}> : P[K];
|
|
36
|
+
};
|
|
37
|
+
type __VLS_Prettify<T> = {
|
|
38
|
+
[K in keyof T]: T[K];
|
|
39
|
+
} & {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { defineComponent as s, openBlock as t, createElementBlock as l, Fragment as i, renderList as r, normalizeClass as d, toDisplayString as u } from "vue";
|
|
2
|
+
const c = {
|
|
3
|
+
class: "aheart-ai-conversations",
|
|
4
|
+
"aria-label": "会话列表"
|
|
5
|
+
}, m = ["disabled", "aria-current", "onClick"], f = /* @__PURE__ */ s({
|
|
6
|
+
name: "AAIConversations",
|
|
7
|
+
__name: "conversations",
|
|
8
|
+
props: {
|
|
9
|
+
modelValue: { default: void 0 },
|
|
10
|
+
conversations: { default: () => [] }
|
|
11
|
+
},
|
|
12
|
+
emits: ["update:modelValue"],
|
|
13
|
+
setup(a, { emit: n }) {
|
|
14
|
+
const o = n;
|
|
15
|
+
return (k, p) => (t(), l("nav", c, [
|
|
16
|
+
(t(!0), l(i, null, r(a.conversations, (e) => (t(), l("button", {
|
|
17
|
+
key: e.key,
|
|
18
|
+
type: "button",
|
|
19
|
+
class: d({ "is-active": e.key === a.modelValue }),
|
|
20
|
+
disabled: e.disabled,
|
|
21
|
+
"aria-current": e.key === a.modelValue ? "page" : void 0,
|
|
22
|
+
onClick: (b) => o("update:modelValue", e.key)
|
|
23
|
+
}, u(e.label), 11, m))), 128))
|
|
24
|
+
]));
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
export {
|
|
28
|
+
f as default
|
|
29
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { AIFormFieldV1 } from './form-schema';
|
|
2
|
+
declare const _default: import("@vue/runtime-core").DefineComponent<import("@vue/runtime-core").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<{
|
|
3
|
+
field: AIFormFieldV1;
|
|
4
|
+
value: unknown;
|
|
5
|
+
disabled?: boolean | undefined;
|
|
6
|
+
error?: string | undefined;
|
|
7
|
+
}>>, {
|
|
8
|
+
focus: () => void;
|
|
9
|
+
}, {}, {}, {}, import("@vue/runtime-core").ComponentOptionsMixin, import("@vue/runtime-core").ComponentOptionsMixin, {
|
|
10
|
+
update: (value: unknown) => void;
|
|
11
|
+
}, string, import("@vue/runtime-core").PublicProps, Readonly<import("@vue/runtime-core").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<{
|
|
12
|
+
field: AIFormFieldV1;
|
|
13
|
+
value: unknown;
|
|
14
|
+
disabled?: boolean | undefined;
|
|
15
|
+
error?: string | undefined;
|
|
16
|
+
}>>> & Readonly<{
|
|
17
|
+
onUpdate?: ((value: unknown) => any) | undefined;
|
|
18
|
+
}>, {}, {}, {}, {}, string, import("@vue/runtime-core").ComponentProvideOptions, true, {}, any>;
|
|
19
|
+
export default _default;
|
|
20
|
+
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
21
|
+
type __VLS_TypePropsToRuntimeProps<T> = {
|
|
22
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
23
|
+
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
24
|
+
} : {
|
|
25
|
+
type: import('vue').PropType<T[K]>;
|
|
26
|
+
required: true;
|
|
27
|
+
};
|
|
28
|
+
};
|