@done-coding/forge-kit-agent 0.0.0-stage → 0.100.0-alpha.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 +53 -2
- package/es/_virtual/_plugin-vue_export-helper.mjs +10 -0
- package/es/components/bubble/AiBubbleContent.vue.mjs +7 -0
- package/es/components/bubble/AiBubbleContent.vue2.mjs +209 -0
- package/es/components/bubble/AiBubbleFooter.vue.mjs +7 -0
- package/es/components/bubble/AiBubbleFooter.vue2.mjs +91 -0
- package/es/components/bubble/AiCodeHeaderControl.vue.mjs +7 -0
- package/es/components/bubble/AiCodeHeaderControl.vue2.mjs +97 -0
- package/es/components/bubble/AiContentSplit.vue.mjs +70 -0
- package/es/components/bubble/AiContentSplit.vue2.mjs +4 -0
- package/es/components/bubble/AiPartRenderer.vue.mjs +7 -0
- package/es/components/bubble/AiPartRenderer.vue2.mjs +184 -0
- package/es/components/bubble/AiThinkBox.vue.mjs +7 -0
- package/es/components/bubble/AiThinkBox.vue2.mjs +155 -0
- package/es/components/bubble/AiTypewriter.vue.mjs +81 -0
- package/es/components/bubble/AiTypewriter.vue2.mjs +4 -0
- package/es/components/config/AiConfigProvider.vue.mjs +31 -0
- package/es/components/config/AiConfigProvider.vue2.mjs +4 -0
- package/es/components/dialogue/AiDialogue.vue.mjs +7 -0
- package/es/components/dialogue/AiDialogue.vue2.mjs +242 -0
- package/es/components/dialogue/AiDialogueGroup.vue.mjs +7 -0
- package/es/components/dialogue/AiDialogueGroup.vue2.mjs +133 -0
- package/es/components/dialogue/AiDialogueWrap.vue.mjs +7 -0
- package/es/components/dialogue/AiDialogueWrap.vue2.mjs +73 -0
- package/es/components/dialogue/AiMessageList.vue.mjs +7 -0
- package/es/components/dialogue/AiMessageList.vue2.mjs +111 -0
- package/es/components/json-trigger/LlmJsonTrigger.vue.mjs +7 -0
- package/es/components/json-trigger/LlmJsonTrigger.vue2.mjs +130 -0
- package/es/components/operation/AiOperationBar.vue.mjs +7 -0
- package/es/components/operation/AiOperationBar.vue2.mjs +174 -0
- package/es/components/operation/AiOperationBtns.vue.mjs +7 -0
- package/es/components/operation/AiOperationBtns.vue2.mjs +140 -0
- package/es/components/sender/AiSender.vue.mjs +7 -0
- package/es/components/sender/AiSender.vue2.mjs +74 -0
- package/es/components/sender/AiSenderHeader.vue.mjs +7 -0
- package/es/components/sender/AiSenderHeader.vue2.mjs +78 -0
- package/es/hooks/CodeXSlot.mjs +20 -0
- package/es/hooks/SessionExpose.mjs +81 -0
- package/es/hooks/agent-tools.mjs +95 -0
- package/es/hooks/agent.mjs +143 -0
- package/es/hooks/bubble-list.mjs +64 -0
- package/es/hooks/expose.mjs +133 -0
- package/es/hooks/fix-bubble-list-bug.mjs +65 -0
- package/es/hooks/sender-history.mjs +28 -0
- package/es/hooks/sender.mjs +197 -0
- package/es/hooks/session-list.mjs +154 -0
- package/es/hooks/sse.mjs +401 -0
- package/es/hooks/storage.mjs +217 -0
- package/es/hooks/theme.mjs +253 -0
- package/es/hooks/use-density.mjs +100 -0
- package/es/hooks/use-empty-state-center.mjs +40 -0
- package/es/hooks/use-keyboard-inset.mjs +87 -0
- package/es/index.mjs +68 -0
- package/es/style.css +836 -0
- package/es/types/index.mjs +54 -0
- package/es/utils/index.mjs +34 -0
- package/es/utils/json-from-llm.mjs +26 -0
- package/es/utils/request-llm.mjs +60 -0
- package/package.json +83 -4
- package/types/bridge/config-hook.d.ts +21 -0
- package/types/bridge/index.d.ts +69 -0
- package/types/bridge/plugin.d.ts +39 -0
- package/types/bridge/state.d.ts +26 -0
- package/types/bridge/storage.d.ts +10 -0
- package/types/components/bubble/AiBubbleContent.vue.d.ts +57 -0
- package/types/components/bubble/AiBubbleFooter.vue.d.ts +6 -0
- package/types/components/bubble/AiCodeHeaderControl.vue.d.ts +7 -0
- package/types/components/bubble/AiContentSplit.vue.d.ts +36 -0
- package/types/components/bubble/AiPartRenderer.vue.d.ts +9 -0
- package/types/components/bubble/AiThinkBox.vue.d.ts +31 -0
- package/types/components/bubble/AiTypewriter.vue.d.ts +28 -0
- package/types/components/config/AiConfigProvider.vue.d.ts +28 -0
- package/types/components/dialogue/AiDialogue.vue.d.ts +546 -0
- package/types/components/dialogue/AiDialogueGroup.vue.d.ts +49 -0
- package/types/components/dialogue/AiDialogueWrap.vue.d.ts +38 -0
- package/types/components/dialogue/AiMessageList.vue.d.ts +65 -0
- package/types/components/json-trigger/LlmJsonTrigger.vue.d.ts +43 -0
- package/types/components/json-trigger/types.d.ts +12 -0
- package/types/components/operation/AiOperationBar.vue.d.ts +36 -0
- package/types/components/operation/AiOperationBtns.vue.d.ts +27 -0
- package/types/components/sender/AiSender.vue.d.ts +38 -0
- package/types/components/sender/AiSenderHeader.vue.d.ts +28 -0
- package/types/hooks/CodeXSlot.d.ts +7 -0
- package/types/hooks/SessionExpose.d.ts +20 -0
- package/types/hooks/agent-tools.d.ts +67 -0
- package/types/hooks/agent.d.ts +43 -0
- package/types/hooks/bubble-list.d.ts +22 -0
- package/types/hooks/expose.d.ts +111 -0
- package/types/hooks/fix-bubble-list-bug.d.ts +8 -0
- package/types/hooks/sender-history.d.ts +41 -0
- package/types/hooks/sender.d.ts +101 -0
- package/types/hooks/session-list.d.ts +36 -0
- package/types/hooks/sse.d.ts +239 -0
- package/types/hooks/storage.d.ts +70 -0
- package/types/hooks/theme.d.ts +37 -0
- package/types/hooks/use-density.d.ts +66 -0
- package/types/hooks/use-empty-state-center.d.ts +23 -0
- package/types/hooks/use-keyboard-inset.d.ts +37 -0
- package/types/index.d.ts +26 -0
- package/types/inject/key.d.ts +20 -0
- package/types/types/index.d.ts +612 -0
- package/types/utils/index.d.ts +29 -0
- package/types/utils/json-from-llm.d.ts +35 -0
- package/types/utils/request-llm.d.ts +44 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { AiDataPart, AiMessage, AiToolPart } from '../../types';
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
/** 受控消息列表(对外业界对齐结构 {id,role,parts|content})。 */
|
|
4
|
+
messages: AiMessage[];
|
|
5
|
+
/** 透传 AiBubbleContent markdown allowHtml;默认 true(与 AiDialogue 同口径)。 */
|
|
6
|
+
allowHtml?: boolean;
|
|
7
|
+
/** 用户气泡最大宽度,默认 '100%'。 */
|
|
8
|
+
bubbleMaxWidth?: string;
|
|
9
|
+
};
|
|
10
|
+
declare function __VLS_template(): {
|
|
11
|
+
attrs: Partial<{}>;
|
|
12
|
+
slots: Readonly<{
|
|
13
|
+
/** 业务 data part 渲染口;缺省时平台占位兜底。 */
|
|
14
|
+
part: (props: {
|
|
15
|
+
part: AiDataPart;
|
|
16
|
+
message: AiMessage;
|
|
17
|
+
}) => unknown;
|
|
18
|
+
/**
|
|
19
|
+
* 工具调用 part 渲染口(generative UI / 人在环表单);缺省退回平台状态机块。
|
|
20
|
+
* ----
|
|
21
|
+
* 与 `#part` 分开而非合并:作用域直接是 `AiToolPart`(`name`/`state`/`input`/`output`
|
|
22
|
+
* 无需再收窄),且不改既有 `#part` 的 data-only 语义。未接管的工具用导出的
|
|
23
|
+
* `AiPartRenderer` 退回默认渲染即可。
|
|
24
|
+
*/
|
|
25
|
+
tool: (props: {
|
|
26
|
+
part: AiToolPart;
|
|
27
|
+
message: AiMessage;
|
|
28
|
+
}) => unknown;
|
|
29
|
+
/** 空列表态。 */
|
|
30
|
+
empty: () => unknown;
|
|
31
|
+
}> & {
|
|
32
|
+
/** 业务 data part 渲染口;缺省时平台占位兜底。 */
|
|
33
|
+
part: (props: {
|
|
34
|
+
part: AiDataPart;
|
|
35
|
+
message: AiMessage;
|
|
36
|
+
}) => unknown;
|
|
37
|
+
/**
|
|
38
|
+
* 工具调用 part 渲染口(generative UI / 人在环表单);缺省退回平台状态机块。
|
|
39
|
+
* ----
|
|
40
|
+
* 与 `#part` 分开而非合并:作用域直接是 `AiToolPart`(`name`/`state`/`input`/`output`
|
|
41
|
+
* 无需再收窄),且不改既有 `#part` 的 data-only 语义。未接管的工具用导出的
|
|
42
|
+
* `AiPartRenderer` 退回默认渲染即可。
|
|
43
|
+
*/
|
|
44
|
+
tool: (props: {
|
|
45
|
+
part: AiToolPart;
|
|
46
|
+
message: AiMessage;
|
|
47
|
+
}) => unknown;
|
|
48
|
+
/** 空列表态。 */
|
|
49
|
+
empty: () => unknown;
|
|
50
|
+
};
|
|
51
|
+
refs: {};
|
|
52
|
+
rootEl: any;
|
|
53
|
+
};
|
|
54
|
+
type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
|
|
55
|
+
declare const __VLS_component: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
56
|
+
allowHtml: boolean;
|
|
57
|
+
bubbleMaxWidth: string;
|
|
58
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
59
|
+
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
|
|
60
|
+
export default _default;
|
|
61
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
62
|
+
new (): {
|
|
63
|
+
$slots: S;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { AiSSEHeaders } from '../../types';
|
|
2
|
+
import { LlmJsonTriggerReceipt } from './types';
|
|
3
|
+
type __VLS_Props = {
|
|
4
|
+
/** duck:数据契约获取(是表单还是别的,本组件不关心) */
|
|
5
|
+
getSchema: () => Promise<Record<string, any>>;
|
|
6
|
+
/** duck:数据落地(怎么填、填到哪归消费方),返回回执供展示撤销 */
|
|
7
|
+
onData: (data: Record<string, any>) => LlmJsonTriggerReceipt;
|
|
8
|
+
/** OpenAI Chat Completions 端点(同 AiSSEOptions.sseUrl) */
|
|
9
|
+
sseUrl: string;
|
|
10
|
+
/** 模型标识(body.model 同名键覆盖之) */
|
|
11
|
+
model?: string;
|
|
12
|
+
/** 附加/覆盖请求头(函数形态每次发起前求值) */
|
|
13
|
+
headers?: AiSSEHeaders | (() => AiSSEHeaders | Promise<AiSSEHeaders>);
|
|
14
|
+
/** 附加/覆盖请求体字段(浅合并覆盖内置,同 AiSSEOptions.body 语义) */
|
|
15
|
+
body?: Record<string, unknown>;
|
|
16
|
+
/** 整体覆盖默认双意图系统提示词 */
|
|
17
|
+
systemPrompt?: string;
|
|
18
|
+
/** textarea 占位文案 */
|
|
19
|
+
placeholder?: string;
|
|
20
|
+
};
|
|
21
|
+
declare function __VLS_template(): {
|
|
22
|
+
attrs: Partial<{}>;
|
|
23
|
+
slots: {
|
|
24
|
+
trigger?(_: {}): any;
|
|
25
|
+
};
|
|
26
|
+
refs: {};
|
|
27
|
+
rootEl: any;
|
|
28
|
+
};
|
|
29
|
+
type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
|
|
30
|
+
declare const __VLS_component: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
31
|
+
model: string;
|
|
32
|
+
headers: AiSSEHeaders | (() => AiSSEHeaders | Promise<AiSSEHeaders>);
|
|
33
|
+
body: Record<string, unknown>;
|
|
34
|
+
placeholder: string;
|
|
35
|
+
systemPrompt: string;
|
|
36
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
37
|
+
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
|
|
38
|
+
export default _default;
|
|
39
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
40
|
+
new (): {
|
|
41
|
+
$slots: S;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* json-trigger 族对外类型(gf9z3w)。
|
|
3
|
+
*
|
|
4
|
+
* duck 契约的一半:消费方实现 `onData` 返回本回执——撤销**机制**(怎么回滚)归
|
|
5
|
+
* 消费方,撤销**按钮**(何时展示、谁触发)归 LlmJsonTrigger。
|
|
6
|
+
*/
|
|
7
|
+
export interface LlmJsonTriggerReceipt {
|
|
8
|
+
/** 实际应用(写入)的条目数 */
|
|
9
|
+
appliedCount: number;
|
|
10
|
+
/** 整体撤销本次应用 */
|
|
11
|
+
undo: () => void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { AiOperationBarProps } from '../../types';
|
|
2
|
+
type __VLS_Props = AiOperationBarProps;
|
|
3
|
+
type __VLS_PublicProps = {
|
|
4
|
+
"activeSessionId"?: string;
|
|
5
|
+
"isCollapsed"?: boolean;
|
|
6
|
+
} & __VLS_Props;
|
|
7
|
+
declare function __VLS_template(): {
|
|
8
|
+
attrs: Partial<{}>;
|
|
9
|
+
slots: {
|
|
10
|
+
logo?(_: {}): any;
|
|
11
|
+
};
|
|
12
|
+
refs: {};
|
|
13
|
+
rootEl: HTMLDivElement;
|
|
14
|
+
};
|
|
15
|
+
type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
|
|
16
|
+
declare const __VLS_component: import('vue').DefineComponent<__VLS_PublicProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
|
|
17
|
+
"update:activeSessionId": (value: string) => any;
|
|
18
|
+
"update:isCollapsed": (value: boolean) => any;
|
|
19
|
+
} & {
|
|
20
|
+
sessionListLodeMore: () => any;
|
|
21
|
+
}, string, import('vue').PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
|
|
22
|
+
onSessionListLodeMore?: (() => any) | undefined;
|
|
23
|
+
"onUpdate:activeSessionId"?: ((value: string) => any) | undefined;
|
|
24
|
+
"onUpdate:isCollapsed"?: ((value: boolean) => any) | undefined;
|
|
25
|
+
}>, {
|
|
26
|
+
position: "left" | "right";
|
|
27
|
+
collapsedWidth: number | string;
|
|
28
|
+
unCollapseWidth: number | string;
|
|
29
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, HTMLDivElement>;
|
|
30
|
+
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
|
|
31
|
+
export default _default;
|
|
32
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
33
|
+
new (): {
|
|
34
|
+
$slots: S;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AiOperationBtnsProps } from '../../types';
|
|
2
|
+
declare function __VLS_template(): {
|
|
3
|
+
attrs: Partial<{}>;
|
|
4
|
+
slots: {
|
|
5
|
+
logo?(_: {
|
|
6
|
+
size: string;
|
|
7
|
+
mode: string;
|
|
8
|
+
}): any;
|
|
9
|
+
};
|
|
10
|
+
refs: {};
|
|
11
|
+
rootEl: HTMLDivElement;
|
|
12
|
+
};
|
|
13
|
+
type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
|
|
14
|
+
declare const __VLS_component: import('vue').DefineComponent<AiOperationBtnsProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {} & {
|
|
15
|
+
"toggle-collapsed": () => any;
|
|
16
|
+
"create-session": () => any;
|
|
17
|
+
}, string, import('vue').PublicProps, Readonly<AiOperationBtnsProps> & Readonly<{
|
|
18
|
+
"onToggle-collapsed"?: (() => any) | undefined;
|
|
19
|
+
"onCreate-session"?: (() => any) | undefined;
|
|
20
|
+
}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, HTMLDivElement>;
|
|
21
|
+
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
|
|
22
|
+
export default _default;
|
|
23
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
24
|
+
new (): {
|
|
25
|
+
$slots: S;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { AiSenderProps } from '../../types';
|
|
2
|
+
type __VLS_Props = AiSenderProps;
|
|
3
|
+
type __VLS_PublicProps = {
|
|
4
|
+
modelValue?: string;
|
|
5
|
+
} & __VLS_Props;
|
|
6
|
+
declare function __VLS_template(): {
|
|
7
|
+
attrs: Partial<{}>;
|
|
8
|
+
slots: {
|
|
9
|
+
header?(_: {}): any;
|
|
10
|
+
prefix?(_: {}): any;
|
|
11
|
+
'action-list'?(_: {}): any;
|
|
12
|
+
footer?(_: {}): any;
|
|
13
|
+
};
|
|
14
|
+
refs: {};
|
|
15
|
+
rootEl: any;
|
|
16
|
+
};
|
|
17
|
+
type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
|
|
18
|
+
declare const __VLS_component: import('vue').DefineComponent<__VLS_PublicProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
|
|
19
|
+
"update:modelValue": (value: string) => any;
|
|
20
|
+
} & {
|
|
21
|
+
cancel: (value: string) => any;
|
|
22
|
+
submit: (value: string) => any;
|
|
23
|
+
}, string, import('vue').PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
|
|
24
|
+
onCancel?: ((value: string) => any) | undefined;
|
|
25
|
+
onSubmit?: ((value: string) => any) | undefined;
|
|
26
|
+
"onUpdate:modelValue"?: ((value: string) => any) | undefined;
|
|
27
|
+
}>, {
|
|
28
|
+
variant: "default" | "updown";
|
|
29
|
+
placeholder: string;
|
|
30
|
+
submitType: import('../..').AiSenderSubmitType;
|
|
31
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
32
|
+
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
|
|
33
|
+
export default _default;
|
|
34
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
35
|
+
new (): {
|
|
36
|
+
$slots: S;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
/** 欢迎语;不传时按有无 swiftAsk 取默认(见 greetingText) */
|
|
3
|
+
greeting?: string;
|
|
4
|
+
/** 快捷问题(点击即发送);空/不传 → 整块建议卡不渲染 */
|
|
5
|
+
swiftAsk?: string[];
|
|
6
|
+
/** logo 图片地址(外部传入);优先级 #logo slot > logoUrl > 不渲染 */
|
|
7
|
+
logoUrl?: string;
|
|
8
|
+
};
|
|
9
|
+
declare function __VLS_template(): {
|
|
10
|
+
attrs: Partial<{}>;
|
|
11
|
+
slots: {
|
|
12
|
+
logo?(_: {
|
|
13
|
+
size: "25px";
|
|
14
|
+
mode: string;
|
|
15
|
+
}): any;
|
|
16
|
+
};
|
|
17
|
+
refs: {};
|
|
18
|
+
rootEl: HTMLDivElement;
|
|
19
|
+
};
|
|
20
|
+
type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
|
|
21
|
+
declare const __VLS_component: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, HTMLDivElement>;
|
|
22
|
+
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
|
|
23
|
+
export default _default;
|
|
24
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
25
|
+
new (): {
|
|
26
|
+
$slots: S;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { XMarkdown } from 'vue-element-plus-x';
|
|
2
|
+
type CodeXSlotHeader = Pick<NonNullable<InstanceType<typeof XMarkdown>["$props"]["codeXSlot"]>, "codeHeader" | "codeHeaderLanguage" | "codeHeaderControl" | "viewCodeHeader" | "viewCodeCloseBtn" | "viewCodeContent" | "codeMermaidHeaderControl">;
|
|
3
|
+
/** 代码插槽 */
|
|
4
|
+
export declare const useCodeXSlot: () => {
|
|
5
|
+
codeXSlot: import('vue').ComputedRef<CodeXSlotHeader>;
|
|
6
|
+
};
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ComputedRef, Ref } from 'vue';
|
|
2
|
+
import { AiBubbleListExpose, AiSenderExpose, AiSessionOperateExpose } from './expose';
|
|
3
|
+
import { AiSenderSubmitOptions } from './sender';
|
|
4
|
+
import { XConversationItem } from '../types';
|
|
5
|
+
/** 单个会话expose */
|
|
6
|
+
export declare const useSessionExpose: ({ senderValue, isResponding, sessionInfo, handleCancel, handleSubmit, }: {
|
|
7
|
+
senderValue: Ref<string>;
|
|
8
|
+
isResponding: ComputedRef<boolean>;
|
|
9
|
+
/** 当前会话信息 */
|
|
10
|
+
sessionInfo: ComputedRef<Readonly<XConversationItem>> | Ref<Readonly<XConversationItem>>;
|
|
11
|
+
/** 取消当前回复 */
|
|
12
|
+
handleCancel: () => void;
|
|
13
|
+
/** 提交问题(第二参承载 `ask({ parts })` 的结构化卡片) */
|
|
14
|
+
handleSubmit: (valueInit: string, options?: AiSenderSubmitOptions) => void;
|
|
15
|
+
}) => {
|
|
16
|
+
senderExpose: import('vue').ShallowRef<AiSenderExpose | undefined, AiSenderExpose | undefined>;
|
|
17
|
+
bubbleListExpose: import('vue').ShallowRef<AiBubbleListExpose | undefined, AiBubbleListExpose | undefined>;
|
|
18
|
+
};
|
|
19
|
+
/** 会话(级别)操作 安装/注册 至 provide */
|
|
20
|
+
export declare const useSessionOperateMount: (activeSessionId: Ref<string | undefined> | ComputedRef<string | undefined>, sessionOperate: AiSessionOperateExpose) => void;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { AiChatCompletionMessage, AiMessagePart, AiTool, AiToolCtx, AiToolExecutor } from '../types';
|
|
2
|
+
import { AiMergedToolCall } from './sse';
|
|
3
|
+
/**
|
|
4
|
+
* 工具循环的纯函数层(`useAiAgent` 私有 · 不出桶 · 规则 22)
|
|
5
|
+
* ============================================================================
|
|
6
|
+
* 把「投影 / 裁决 / 回发消息 / 落 part 状态」四件事从循环主干里抽出——主干只剩
|
|
7
|
+
* 「发一轮 → 有调用就跑 → 再发一轮」的编排骨架,本文件全是可单测的纯函数。
|
|
8
|
+
* 删掉工具能力 = 删本文件 + `agent.ts` + 三个透传 prop,主干零残留。
|
|
9
|
+
* ============================================================================
|
|
10
|
+
*/
|
|
11
|
+
/** 单个工具调用的裁决结果 */
|
|
12
|
+
export interface AiAgentToolOutcome {
|
|
13
|
+
/** = wire `tool_calls[].id`,同时是 `AiToolPart.id` */
|
|
14
|
+
toolCallId: string;
|
|
15
|
+
/** 工具名 */
|
|
16
|
+
toolName: string;
|
|
17
|
+
/** 落到 part 上的终态 */
|
|
18
|
+
state: "output-available" | "output-error" | "output-denied";
|
|
19
|
+
/** 成功结果(output-available) */
|
|
20
|
+
output?: unknown;
|
|
21
|
+
/** 失败 / 拒绝原因(output-error / output-denied) */
|
|
22
|
+
errorText?: string;
|
|
23
|
+
/** 回发给模型的 `role:"tool"` 消息正文 */
|
|
24
|
+
content: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* 注册表 → wire `body.tools`。
|
|
28
|
+
* ----
|
|
29
|
+
* 只投影模型选型需要的三项;`execute` 是本地实现**不上线**,`annotations` 也不发
|
|
30
|
+
* (OpenAI function 对象不接受未知字段,严格端点会 400——库不替消费方冒这个险)。
|
|
31
|
+
*/
|
|
32
|
+
export declare const agentToolProjectWire: (tools: readonly AiTool[]) => Array<Record<string, unknown>>;
|
|
33
|
+
/**
|
|
34
|
+
* 取该调用的执行体:注册表 `execute` 优先,回落 `onToolCall` 兜底。
|
|
35
|
+
* ----
|
|
36
|
+
* 两者都无 → `undefined` = 本端无法答复该调用。
|
|
37
|
+
*/
|
|
38
|
+
export declare const agentToolResolveExecutor: (toolName: string | undefined, tools: readonly AiTool[], onToolCall?: AiToolExecutor) => AiToolExecutor | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* 本轮调用是否**全部**可答复。
|
|
41
|
+
* ----
|
|
42
|
+
* [MUST] 全有全无:OpenAI 要求每个 `tool_calls[].id` 都有对应 `role:"tool"` 回复,
|
|
43
|
+
* 少一条下一轮直接 400。故只要有一个答不上,就一个都不执行(避免白跑副作用)、
|
|
44
|
+
* 直接收敛为 `unhandled-tool-calls`,把 part 原样交给消费方渲染。
|
|
45
|
+
*/
|
|
46
|
+
export declare const agentToolCanHandleAll: (calls: readonly AiMergedToolCall[], tools: readonly AiTool[], onToolCall?: AiToolExecutor) => boolean;
|
|
47
|
+
/** 结果 → tool 消息正文(字符串原样,其余 JSON 序列化;不可序列化时退回 String) */
|
|
48
|
+
export declare const agentToolStringify: (value: unknown) => string;
|
|
49
|
+
/**
|
|
50
|
+
* 跑一个工具调用,把三种归宿归一成 `AiAgentToolOutcome`。
|
|
51
|
+
* ----
|
|
52
|
+
* [MUST NOT] 让异常逃逸——循环靠「每个调用都有 outcome」保证续轮消息完整。
|
|
53
|
+
*/
|
|
54
|
+
export declare const agentToolRun: (call: AiMergedToolCall, executor: AiToolExecutor,
|
|
55
|
+
/** 本轮上下文(`AiToolCtx` 里除调用身份之外的部分) */
|
|
56
|
+
run: Pick<AiToolCtx, "step" | "signal">) => Promise<AiAgentToolOutcome>;
|
|
57
|
+
/**
|
|
58
|
+
* 本轮的 assistant 消息(wire)——续轮上下文里 `tool_calls` 与其结果 [MUST] 成对出现。
|
|
59
|
+
* ----
|
|
60
|
+
* `content` 用**本步新增**正文(非累计全文),否则多步循环会把前几步正文重复喂回去。
|
|
61
|
+
* 纯工具轮无正文 → `null`(OpenAI 允许)。
|
|
62
|
+
*/
|
|
63
|
+
export declare const agentToolBuildAssistantMessage: (stepText: string, calls: readonly AiMergedToolCall[]) => AiChatCompletionMessage;
|
|
64
|
+
/** 裁决结果 → `role:"tool"` 回发消息(一个调用一条,顺序与调用一致) */
|
|
65
|
+
export declare const agentToolBuildResultMessages: (outcomes: readonly AiAgentToolOutcome[]) => AiChatCompletionMessage[];
|
|
66
|
+
/** 裁决结果落到 parts 上(按 `id` upsert,推进五态状态机的后半程) */
|
|
67
|
+
export declare const agentToolApplyOutcomes: (parts: readonly AiMessagePart[], outcomes: readonly AiAgentToolOutcome[]) => AiMessagePart[];
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { AiAgentStopReason, AiTool, AiToolExecutor, XBubbleListItemProps } from '../types';
|
|
2
|
+
import { AiSSEOptions } from './sse';
|
|
3
|
+
/**
|
|
4
|
+
* 工具循环默认轮数上限。
|
|
5
|
+
* ----
|
|
6
|
+
* 取 10 对齐 OpenAI Agents SDK `max_turns=10`(业界可引默认值,非自造)。
|
|
7
|
+
*/
|
|
8
|
+
export declare const AI_AGENT_DEFAULT_MAX_STEPS = 10;
|
|
9
|
+
/** webAgent 工具循环选项(= `useAiSSE` 选项 + 工具三参;种子参数由本层内部接管) */
|
|
10
|
+
export interface AiAgentRunOptions<T extends XBubbleListItemProps = XBubbleListItemProps> extends Omit<AiSSEOptions<T>, "initialContent" | "initialParts" | "initialPartOffsets" | "projectToolCallParts"> {
|
|
11
|
+
/**
|
|
12
|
+
* 前端工具注册表。
|
|
13
|
+
* ----
|
|
14
|
+
* 库把它投影成 wire `body.tools`;带 `execute` 者由本层执行并回发结果,
|
|
15
|
+
* 不带者只投影 schema(回来的 tool_calls 原样渲染成 part,不续轮)。
|
|
16
|
+
* **消费方显式传的 `body.tools` 整体覆盖本投影**(两者二选一,[MUST NOT] 混用)。
|
|
17
|
+
*/
|
|
18
|
+
tools?: readonly AiTool[];
|
|
19
|
+
/**
|
|
20
|
+
* 兜底执行体:注册表里没有 `execute` 的调用交给它。
|
|
21
|
+
* ----
|
|
22
|
+
* 与 `AiTool.execute` 同签名;工具名在 `ctx.toolName`。
|
|
23
|
+
*/
|
|
24
|
+
onToolCall?: AiToolExecutor;
|
|
25
|
+
/**
|
|
26
|
+
* LLM 请求总轮数上限(含首轮),默认 {@link AI_AGENT_DEFAULT_MAX_STEPS}。
|
|
27
|
+
* ----
|
|
28
|
+
* 触顶即停:**不执行**该轮工具(结果无处回发,白跑副作用),未答复的 part 停在
|
|
29
|
+
* `input-available`,`stopReason` 置 `"max-steps"`。
|
|
30
|
+
* [MUST NOT] 因触顶写 `errorMsg`——那会让整轮回复被历史过滤器踢出上下文。
|
|
31
|
+
*/
|
|
32
|
+
maxSteps?: number;
|
|
33
|
+
}
|
|
34
|
+
/** webAgent 工具循环 */
|
|
35
|
+
export declare const useAiAgent: <T extends XBubbleListItemProps = XBubbleListItemProps>({ tools, onToolCall, maxSteps, messages, body, finish, changeMessage, ...sseOptions }: AiAgentRunOptions<T>) => {
|
|
36
|
+
start: () => Promise<void>;
|
|
37
|
+
symbol: symbol;
|
|
38
|
+
input: string;
|
|
39
|
+
isResponding: import('vue').ComputedRef<boolean>;
|
|
40
|
+
cancel: () => void;
|
|
41
|
+
/** 收敛原因(run 结束后可读) */
|
|
42
|
+
stopReason: import('vue').ComputedRef<AiAgentStopReason | undefined>;
|
|
43
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ComputedRef, Reactive, Ref } from 'vue';
|
|
2
|
+
import { XBubbleListItemProps, XConversationItem } from '../types';
|
|
3
|
+
import { AiDb } from './storage';
|
|
4
|
+
/** 应用 bubbleList 组件的 作用域 */
|
|
5
|
+
export interface BubbleListScopedOptions {
|
|
6
|
+
db?: AiDb;
|
|
7
|
+
/** 当前会话信息 */
|
|
8
|
+
sessionInfo: ComputedRef<Readonly<XConversationItem>> | Ref<Readonly<XConversationItem>>;
|
|
9
|
+
/** 添加会话到列表 */
|
|
10
|
+
addSessionToList: (sessionInfo: XConversationItem) => void;
|
|
11
|
+
/** 更新会话信息 */
|
|
12
|
+
updateSession: (data: Required<Pick<XConversationItem, "id">> & Partial<Omit<XConversationItem, "id">>) => void;
|
|
13
|
+
}
|
|
14
|
+
/** 应用 bubbleList 组件的 作用域 */
|
|
15
|
+
export declare const useBubbleListScoped: <T extends XBubbleListItemProps = XBubbleListItemProps>({ db, sessionInfo, addSessionToList, updateSession, }: BubbleListScopedOptions) => {
|
|
16
|
+
isLoadMoreLoading: ComputedRef<boolean>;
|
|
17
|
+
isLoadMoreFinished: ComputedRef<boolean>;
|
|
18
|
+
list: ComputedRef<readonly XBubbleListItemProps[]>;
|
|
19
|
+
addBubble: (item: T) => Reactive<T>;
|
|
20
|
+
updateMessage: ({ uuid, ...rest }: Required<Pick<XBubbleListItemProps, "uuid">> & Partial<Omit<XBubbleListItemProps, "uuid">>) => Promise<number>;
|
|
21
|
+
loadMore: () => Promise<XBubbleListItemProps[]>;
|
|
22
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { ComputedRef } from 'vue';
|
|
2
|
+
import { AiMessagePart, AiSessionBaseSimpleInfo } from '../types';
|
|
3
|
+
/** 输入框expose */
|
|
4
|
+
export interface AiSenderExpose {
|
|
5
|
+
/** 失去焦点 */
|
|
6
|
+
blur: () => void;
|
|
7
|
+
/** 输入框聚焦 */
|
|
8
|
+
focus: (type?: "all" | "start" | "end") => void;
|
|
9
|
+
/** 打开头部 */
|
|
10
|
+
openHeader: () => void;
|
|
11
|
+
/** 关闭头部 */
|
|
12
|
+
closeHeader: () => void;
|
|
13
|
+
}
|
|
14
|
+
/** 聊天气泡列表expose */
|
|
15
|
+
export interface AiBubbleListExpose {
|
|
16
|
+
/** 聊天气泡列表滚动到底部 */
|
|
17
|
+
scrollToBottom: () => void;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* `ask()` 入参。
|
|
21
|
+
* ----
|
|
22
|
+
* `value` 与 `parts` **至少给一个**(两者皆空 → 报错,与手打空消息同口径);
|
|
23
|
+
* 两者同给 = 一条带正文又带卡片的用户消息。
|
|
24
|
+
*/
|
|
25
|
+
export interface AiAskParams {
|
|
26
|
+
/** 询问值(要发送的消息文本);纯卡片消息可不给 */
|
|
27
|
+
value?: string;
|
|
28
|
+
/**
|
|
29
|
+
* 以**用户名义**随本条消息发出的结构化 parts(数据卡 / 引用卡 / 附件)。
|
|
30
|
+
* ----
|
|
31
|
+
* 渲染走 `AiDialogue` 的 `#part` / `#tool` 转发口(与 AI 侧同一条链);
|
|
32
|
+
* 回发走默认 wire 映射(`data-*` → `[<type>]\n<JSON>` 文本段)或消费方自己的
|
|
33
|
+
* `sseMessagesSerializer`。
|
|
34
|
+
*/
|
|
35
|
+
parts?: AiMessagePart[];
|
|
36
|
+
}
|
|
37
|
+
/** 问答expose */
|
|
38
|
+
/**
|
|
39
|
+
* @return 返回会话id 如果没有说明 为成功发起
|
|
40
|
+
*/
|
|
41
|
+
export type AiAskExpose = (params: AiAskParams) => Promise<AiSessionBaseSimpleInfo>;
|
|
42
|
+
/** 会话级别操作 expose */
|
|
43
|
+
export interface AiSessionOperateExpose {
|
|
44
|
+
/** 创建新会话 */
|
|
45
|
+
create: () => Promise<AiSessionBaseSimpleInfo>;
|
|
46
|
+
/** 切换对话 */
|
|
47
|
+
switch: (id: string) => Promise<void>;
|
|
48
|
+
}
|
|
49
|
+
/** ai 单个会话整体 expose */
|
|
50
|
+
export interface AiSessionExpose {
|
|
51
|
+
/** 会话id */
|
|
52
|
+
sessionId: string;
|
|
53
|
+
/** 输入框 */
|
|
54
|
+
sender?: AiSenderExpose;
|
|
55
|
+
/** 聊天气泡列表 */
|
|
56
|
+
bubbleList?: AiBubbleListExpose;
|
|
57
|
+
/** 问答 */
|
|
58
|
+
ask?: AiAskExpose;
|
|
59
|
+
}
|
|
60
|
+
/** ai expose */
|
|
61
|
+
export interface AiExpose extends Pick<AiSessionExpose, "sender" | "bubbleList" | "ask"> {
|
|
62
|
+
/** 激活的会话id */
|
|
63
|
+
activeSessionId?: string;
|
|
64
|
+
/** 会话级别操作 */
|
|
65
|
+
sessionOperate?: AiSessionOperateExpose;
|
|
66
|
+
/** 会话expose map */
|
|
67
|
+
sessionExposeMap: Map<string, AiSessionExpose>;
|
|
68
|
+
}
|
|
69
|
+
/** 添加 session expose */
|
|
70
|
+
export type AiAddSessionExpose = (id: string, expose: AiSessionExpose) => void;
|
|
71
|
+
/** 移除 session expose */
|
|
72
|
+
export type AiRemoveSessionExpose = (id: string) => void;
|
|
73
|
+
/** 设置 激活的会话 */
|
|
74
|
+
export type AiSetActiveSessionId = (id?: string) => void;
|
|
75
|
+
/** 挂载会话级别操作 */
|
|
76
|
+
export type AiMountSessionOperate = (expose?: AiSessionOperateExpose) => void;
|
|
77
|
+
/** (是中转暴露)子组件的expose key */
|
|
78
|
+
export type AiExposeChildKeys = Extract<keyof AiExpose, "sender" | "bubbleList">;
|
|
79
|
+
/** 目标(组件自身)创建的expose key */
|
|
80
|
+
export type AiExposeTargetKeys = Exclude<keyof AiExpose, AiExposeChildKeys>;
|
|
81
|
+
/** ai 相关 expose provide key */
|
|
82
|
+
export declare const AI_EXPOSE_PROVIDE: {
|
|
83
|
+
/** expose */
|
|
84
|
+
AI_EXPOSE: symbol;
|
|
85
|
+
/** 添加 session expose */
|
|
86
|
+
AI_ADD_SESSION_EXPOSE: symbol;
|
|
87
|
+
/** 移除 session expose */
|
|
88
|
+
AI_REMOVE_SESSION_EXPOSE: symbol;
|
|
89
|
+
/** 设置聚焦的会话id */
|
|
90
|
+
AI_SET_ACTIVE_SESSION_ID: symbol;
|
|
91
|
+
/** 挂载会话级别的操作 */
|
|
92
|
+
AI_MOUNT_SESSION_OPERATE: symbol;
|
|
93
|
+
/** 单个 会话 expose */
|
|
94
|
+
AI_SESSION_EXPOSE: symbol;
|
|
95
|
+
};
|
|
96
|
+
/** 各组件的expose provide */
|
|
97
|
+
export declare const useAiExposeProvide: () => {
|
|
98
|
+
aiExpose: ComputedRef<AiExpose>;
|
|
99
|
+
};
|
|
100
|
+
/** 各组件的expose inject */
|
|
101
|
+
export declare const useAiExposeInject: () => {
|
|
102
|
+
aiExpose: ComputedRef<AiExpose> | undefined;
|
|
103
|
+
};
|
|
104
|
+
/** expose 控制 */
|
|
105
|
+
export declare const useExposeCtrl: <T>(getTargetExpose: () => T, setTargetExpose: (expose?: T) => void) => void;
|
|
106
|
+
/** 当前 ai 会话(组件AiDialogue) provide */
|
|
107
|
+
export declare const useAiSessionProvide: (sessionExpose: ComputedRef<AiSessionExpose>) => void;
|
|
108
|
+
/** 当前 ai 会话(组件AiDialogue) 子组件注入 */
|
|
109
|
+
export declare const useAiSessionInject: () => {
|
|
110
|
+
sessionExpose: ComputedRef<AiSessionExpose> | undefined;
|
|
111
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AiBubbleListExpose } from './expose';
|
|
2
|
+
/** 修复bubbleList 滚动动画 bug */
|
|
3
|
+
export declare const useFixBubbleListBug: (getBubbleListExpose: () => AiBubbleListExpose | undefined) => {
|
|
4
|
+
fixBugCls: string;
|
|
5
|
+
noScrollAnimation: import('vue').ComputedRef<boolean>;
|
|
6
|
+
historyRenderScrollShield: () => void;
|
|
7
|
+
currentFirstAskScrollShield: () => Promise<void>;
|
|
8
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { AiChatCompletionMessage, AiMessage, AiMessagePart, XBubbleListItemProps } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* 对话历史组装(sender 私有 · 纯函数 · 不出桶)
|
|
4
|
+
* ============================================================================
|
|
5
|
+
* 把气泡列表快照转成 `AiMessage[]`,再交序列化器(默认 `toOpenAIMessages`)转成
|
|
6
|
+
* OpenAI wire `messages[]`,供 `useAiSSE` 发出多轮上下文。
|
|
7
|
+
* 主干 `handleSubmit` 只留一行委托(规则 21/22:过程逻辑不铺在主干)。
|
|
8
|
+
* ============================================================================
|
|
9
|
+
*/
|
|
10
|
+
/** 本轮发送内容(文本与 parts 至少一个非空,由 `handleSubmit` 前置校验) */
|
|
11
|
+
export interface SenderHistoryInput {
|
|
12
|
+
/** 本轮用户输入文本 */
|
|
13
|
+
value?: string;
|
|
14
|
+
/** 本轮以用户名义携带的 parts(`ask({ parts })`) */
|
|
15
|
+
parts?: readonly AiMessagePart[];
|
|
16
|
+
}
|
|
17
|
+
/** wire 序列化器(默认 `toOpenAIMessages`,消费方可经 `sseMessagesSerializer` 整条替换) */
|
|
18
|
+
export type SenderHistorySerializer = (messages: AiMessage[]) => AiChatCompletionMessage[];
|
|
19
|
+
/** 组装选项(两项都来自 `AiDialogue` 的同名 prop) */
|
|
20
|
+
export interface SenderHistoryOptions {
|
|
21
|
+
/**
|
|
22
|
+
* 携带的历史消息**条数**上限(不含本轮):
|
|
23
|
+
* `undefined` = 全量;`<= 0` = 不带历史(等价单轮);`n > 0` = 取最近 n 条。
|
|
24
|
+
*/
|
|
25
|
+
historyLimit?: number;
|
|
26
|
+
/** `AiMessage[]` → wire 的序列化器,默认 `toOpenAIMessages` */
|
|
27
|
+
serializer?: SenderHistorySerializer;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 组装本轮请求的 wire messages。
|
|
31
|
+
* ----
|
|
32
|
+
* @param bubbles 气泡列表**快照**([MUST] 在本轮 addBubble 之前取,否则会把本轮 user
|
|
33
|
+
* 与空的 ai 占位气泡一并卷入)
|
|
34
|
+
* @param input 本轮用户输入(本函数负责追加,不依赖调用方)
|
|
35
|
+
* @param options `historyLimit` + `serializer`(后者**整批(历史 + 本轮)一次性**
|
|
36
|
+
* 拿到全部消息,消费方由此能做跨消息的映射——合并 / 插 system /
|
|
37
|
+
* 改形状,[MUST NOT] 拆成两次调用)
|
|
38
|
+
*
|
|
39
|
+
* [MUST NOT] 修改入参(返回新数组)。
|
|
40
|
+
*/
|
|
41
|
+
export declare const senderBuildMessages: (bubbles: readonly XBubbleListItemProps[], input: SenderHistoryInput, { historyLimit, serializer }?: SenderHistoryOptions) => AiChatCompletionMessage[];
|