@done-coding/forge-kit-agent 0.0.0-stage → 0.100.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,54 @@
|
|
|
1
|
+
var AiChatRoleEnum = /* @__PURE__ */ ((AiChatRoleEnum2) => {
|
|
2
|
+
AiChatRoleEnum2["USER"] = "user";
|
|
3
|
+
AiChatRoleEnum2["AI"] = "ai";
|
|
4
|
+
return AiChatRoleEnum2;
|
|
5
|
+
})(AiChatRoleEnum || {});
|
|
6
|
+
class AiToolDeniedError extends Error {
|
|
7
|
+
constructor(message = "用户拒绝了该工具调用") {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = "AiToolDeniedError";
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
const normalizeParts = (message) => {
|
|
13
|
+
const source = message.parts !== void 0 ? message.parts : message.content !== void 0 ? [{ type: "text", text: message.content }] : [];
|
|
14
|
+
return source.reduce((acc, part) => {
|
|
15
|
+
const prev = acc[acc.length - 1];
|
|
16
|
+
if (part.type === "text" && prev && prev.type === "text") {
|
|
17
|
+
acc[acc.length - 1] = { type: "text", text: prev.text + part.text };
|
|
18
|
+
return acc;
|
|
19
|
+
}
|
|
20
|
+
acc.push(part);
|
|
21
|
+
return acc;
|
|
22
|
+
}, []);
|
|
23
|
+
};
|
|
24
|
+
const aiIsDataPart = (part) => part.type.startsWith("data-");
|
|
25
|
+
const aiDataPartToWireText = (part) => {
|
|
26
|
+
let payload;
|
|
27
|
+
try {
|
|
28
|
+
payload = JSON.stringify(part.data) ?? String(part.data);
|
|
29
|
+
} catch {
|
|
30
|
+
payload = String(part.data);
|
|
31
|
+
}
|
|
32
|
+
return `[${part.type}]
|
|
33
|
+
${payload}`;
|
|
34
|
+
};
|
|
35
|
+
const toOpenAIMessages = (messages) => messages.reduce((acc, message) => {
|
|
36
|
+
const content = normalizeParts(message).map((part) => {
|
|
37
|
+
if (part.type === "text") {
|
|
38
|
+
return part.text;
|
|
39
|
+
}
|
|
40
|
+
return aiIsDataPart(part) ? aiDataPartToWireText(part) : "";
|
|
41
|
+
}).filter(Boolean).join("\n\n");
|
|
42
|
+
if (content) {
|
|
43
|
+
acc.push({ role: message.role, content });
|
|
44
|
+
}
|
|
45
|
+
return acc;
|
|
46
|
+
}, []);
|
|
47
|
+
export {
|
|
48
|
+
AiChatRoleEnum,
|
|
49
|
+
AiToolDeniedError,
|
|
50
|
+
aiDataPartToWireText,
|
|
51
|
+
aiIsDataPart,
|
|
52
|
+
normalizeParts,
|
|
53
|
+
toOpenAIMessages
|
|
54
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const getCssWithUnit = (value) => {
|
|
2
|
+
if (value === void 0 || value === null) {
|
|
3
|
+
return void 0;
|
|
4
|
+
}
|
|
5
|
+
if (typeof value === "number") {
|
|
6
|
+
return `${value}px`;
|
|
7
|
+
}
|
|
8
|
+
const trimmed = String(value).trim();
|
|
9
|
+
if (/^[+-]?\d+(\.\d+)?$/.test(trimmed)) {
|
|
10
|
+
return `${trimmed}px`;
|
|
11
|
+
}
|
|
12
|
+
return value;
|
|
13
|
+
};
|
|
14
|
+
const formatTimestamp = (ts, format = "YYYY-MM-DD HH:mm:ss") => {
|
|
15
|
+
const ms = ts < 1e12 ? ts * 1e3 : ts;
|
|
16
|
+
const date = new Date(ms);
|
|
17
|
+
if (Number.isNaN(date.getTime())) {
|
|
18
|
+
return "";
|
|
19
|
+
}
|
|
20
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
21
|
+
const map = {
|
|
22
|
+
YYYY: String(date.getFullYear()),
|
|
23
|
+
MM: pad(date.getMonth() + 1),
|
|
24
|
+
DD: pad(date.getDate()),
|
|
25
|
+
HH: pad(date.getHours()),
|
|
26
|
+
mm: pad(date.getMinutes()),
|
|
27
|
+
ss: pad(date.getSeconds())
|
|
28
|
+
};
|
|
29
|
+
return format.replace(/YYYY|MM|DD|HH|mm|ss/g, (token) => map[token]);
|
|
30
|
+
};
|
|
31
|
+
export {
|
|
32
|
+
formatTimestamp,
|
|
33
|
+
getCssWithUnit
|
|
34
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { requestLlmText } from "./request-llm.mjs";
|
|
2
|
+
const buildJsonSystemPrompt = (schema) => "你是结构化填充助手,严格只输出一个 JSON 对象。两种意图:ⓐ 用户给了一段含具体信息的文本 → 抽取字段值,没提到或不确定的字段填 null,不要编造;ⓑ 用户明确要求模拟/生成/编一份示例数据 → 按其要求生成合理的示例值填满相关字段。字段契约(JSON Schema;顶层 description 是这份数据的用途):\n" + JSON.stringify(schema);
|
|
3
|
+
const getJsonFromLlm = async (options) => {
|
|
4
|
+
const { sseUrl, model, headers, body, schema, prompt, systemPrompt } = options;
|
|
5
|
+
const { content } = await requestLlmText({
|
|
6
|
+
sseUrl,
|
|
7
|
+
model,
|
|
8
|
+
headers,
|
|
9
|
+
body: { response_format: { type: "json_object" }, ...body },
|
|
10
|
+
messages: [
|
|
11
|
+
{
|
|
12
|
+
role: "system",
|
|
13
|
+
content: systemPrompt ?? buildJsonSystemPrompt(schema)
|
|
14
|
+
},
|
|
15
|
+
{ role: "user", content: prompt }
|
|
16
|
+
]
|
|
17
|
+
});
|
|
18
|
+
try {
|
|
19
|
+
return JSON.parse(content);
|
|
20
|
+
} catch {
|
|
21
|
+
throw new Error(`LLM 未返回合法 JSON:${content.slice(0, 80)}`);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
export {
|
|
25
|
+
getJsonFromLlm
|
|
26
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { parseSSEEventLine } from "../hooks/sse.mjs";
|
|
2
|
+
const requestLlmThrowUpstream = async (res) => {
|
|
3
|
+
var _a, _b, _c;
|
|
4
|
+
const errText = await res.text();
|
|
5
|
+
let upstream = errText.slice(0, 160);
|
|
6
|
+
try {
|
|
7
|
+
upstream = ((_c = (_b = (_a = JSON.parse(errText)) == null ? void 0 : _a.error) == null ? void 0 : _b.message) == null ? void 0 : _c.slice(0, 160)) ?? upstream;
|
|
8
|
+
} catch {
|
|
9
|
+
}
|
|
10
|
+
throw new Error(`LLM 上游 ${res.status}:${upstream}`);
|
|
11
|
+
};
|
|
12
|
+
const requestLlmDrainSse = async (res, onDelta) => {
|
|
13
|
+
var _a;
|
|
14
|
+
const reader = (_a = res.body) == null ? void 0 : _a.getReader();
|
|
15
|
+
if (!reader) throw new Error("LLM 响应声明为 SSE 但无可读流");
|
|
16
|
+
const decoder = new TextDecoder();
|
|
17
|
+
let buffer = "";
|
|
18
|
+
let content = "";
|
|
19
|
+
let errorMsg;
|
|
20
|
+
const consume = (line) => {
|
|
21
|
+
const frame = parseSSEEventLine(line);
|
|
22
|
+
if (!frame) return;
|
|
23
|
+
if (frame.type === "error") errorMsg = frame.errorMsg ?? "回答生成失败";
|
|
24
|
+
if (frame.content) {
|
|
25
|
+
content += frame.content;
|
|
26
|
+
onDelta == null ? void 0 : onDelta(frame.content);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
for (; ; ) {
|
|
30
|
+
const { done, value } = await reader.read();
|
|
31
|
+
if (done) break;
|
|
32
|
+
buffer += decoder.decode(value, { stream: true });
|
|
33
|
+
const lines = buffer.split("\n");
|
|
34
|
+
buffer = lines.pop() ?? "";
|
|
35
|
+
lines.forEach(consume);
|
|
36
|
+
}
|
|
37
|
+
if (buffer.trim()) consume(buffer);
|
|
38
|
+
if (errorMsg) throw new Error(errorMsg);
|
|
39
|
+
return content;
|
|
40
|
+
};
|
|
41
|
+
const requestLlmText = async (options) => {
|
|
42
|
+
var _a, _b, _c;
|
|
43
|
+
const { sseUrl, model, headers, body, messages, stream = false } = options;
|
|
44
|
+
const resolvedHeaders = typeof headers === "function" ? await headers() : headers;
|
|
45
|
+
const res = await fetch(sseUrl, {
|
|
46
|
+
method: "POST",
|
|
47
|
+
headers: { "Content-Type": "application/json", ...resolvedHeaders },
|
|
48
|
+
body: JSON.stringify({ model, stream, messages, ...body })
|
|
49
|
+
});
|
|
50
|
+
if (!res.ok) await requestLlmThrowUpstream(res);
|
|
51
|
+
const contentType = res.headers.get("content-type") ?? "";
|
|
52
|
+
if (contentType.includes("text/event-stream")) {
|
|
53
|
+
return { content: await requestLlmDrainSse(res, options.onDelta) };
|
|
54
|
+
}
|
|
55
|
+
const data = await res.json();
|
|
56
|
+
return { content: ((_c = (_b = (_a = data == null ? void 0 : data.choices) == null ? void 0 : _a[0]) == null ? void 0 : _b.message) == null ? void 0 : _c.content) ?? "", raw: data };
|
|
57
|
+
};
|
|
58
|
+
export {
|
|
59
|
+
requestLlmText
|
|
60
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,85 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@done-coding/forge-kit-agent",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.100.0",
|
|
4
|
+
"description": "Vue 3 AI 对话与智能体 UI 组件库",
|
|
5
|
+
"private": false,
|
|
6
|
+
"module": "es/index.mjs",
|
|
7
|
+
"types": "types/index.d.ts",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./types/index.d.ts",
|
|
12
|
+
"import": "./es/index.mjs"
|
|
13
|
+
},
|
|
14
|
+
"./es/style.css": "./es/style.css",
|
|
15
|
+
"./style.css": "./es/style.css"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"es",
|
|
19
|
+
"types"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"serve": "vite",
|
|
23
|
+
"predev": "dc-inject",
|
|
24
|
+
"dev": "vite --config vite.demo.config.ts",
|
|
25
|
+
"prehotBuild": "dc-inject",
|
|
26
|
+
"hotBuild": "vite build -w -m hotBuild",
|
|
27
|
+
"prebuild": "rimraf types && dc-inject",
|
|
28
|
+
"build": "vue-tsc && vite build",
|
|
29
|
+
"prepack": "pnpm build",
|
|
30
|
+
"typecheck:demo": "vue-tsc -p tsconfig.demo.json --noEmit",
|
|
31
|
+
"test": "vitest --config vite.demo.config.ts",
|
|
32
|
+
"test:ci": "vitest run --config vite.demo.config.ts && pnpm typecheck:demo",
|
|
33
|
+
"coverage": "vitest run --coverage --config vite.demo.config.ts",
|
|
34
|
+
"e2e": "playwright test",
|
|
35
|
+
"e2e:serve": "vite --config vite.demo.config.ts --port 5183 --strictPort",
|
|
36
|
+
"e2e:install": "playwright install chromium",
|
|
37
|
+
"typecheck": "vue-tsc --noEmit",
|
|
38
|
+
"prepublishOnly": "node ../../scripts/forge-release.mjs --check-stamp"
|
|
39
|
+
},
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "https://github.com/done-coding/done-coding-forge.git",
|
|
43
|
+
"directory": "packages/forge-kit-agent"
|
|
44
|
+
},
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public",
|
|
47
|
+
"registry": "https://registry.npmjs.org/"
|
|
48
|
+
},
|
|
49
|
+
"author": "JustSoSu",
|
|
50
|
+
"license": "MIT",
|
|
51
|
+
"sideEffects": false,
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@done-coding/cli-inject": "0.6.3",
|
|
54
|
+
"@playwright/test": "^1.45.0",
|
|
55
|
+
"@types/lodash": "^4.17.0",
|
|
56
|
+
"@types/node": "^18.0.0",
|
|
57
|
+
"@vitejs/plugin-vue": "^5.0.4",
|
|
58
|
+
"@vitejs/plugin-vue-jsx": "^4.1.2",
|
|
59
|
+
"@vitest/coverage-istanbul": "^1.6.1",
|
|
60
|
+
"@vue/shared": "^3.4.0",
|
|
61
|
+
"happy-dom": "^14.12.3",
|
|
62
|
+
"less": "^4.2.0",
|
|
63
|
+
"rimraf": "^5.0.1",
|
|
64
|
+
"typescript": "^5.8.3",
|
|
65
|
+
"vite": "^5.2.0",
|
|
66
|
+
"vite-plugin-dts": "^4.5.4",
|
|
67
|
+
"vitest": "^1.6.1",
|
|
68
|
+
"vue-tsc": "^2.2.12"
|
|
69
|
+
},
|
|
70
|
+
"peerDependencies": {
|
|
71
|
+
"@element-plus/icons-vue": "^2.3.1",
|
|
72
|
+
"element-plus": "^2.7.0",
|
|
73
|
+
"lodash": "^4.17.21",
|
|
74
|
+
"vue": "^3.4.0"
|
|
75
|
+
},
|
|
76
|
+
"dependencies": {
|
|
77
|
+
"dexie": "^4.4.3",
|
|
78
|
+
"vue-element-plus-x": "^1.3.98"
|
|
79
|
+
},
|
|
80
|
+
"engines": {
|
|
81
|
+
"node": ">=18.0.0",
|
|
82
|
+
"pnpm": ">=9.0.0"
|
|
83
|
+
},
|
|
84
|
+
"gitHead": "2eb50e25a430fe59d79c19c32ecdcfd6cb11608d"
|
|
85
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DeepReadonly } from 'vue';
|
|
2
|
+
/**
|
|
3
|
+
* bridge 响应式配置 hook 对外契约——`config` 只读响应式视图 + `update` 增量更新。
|
|
4
|
+
*
|
|
5
|
+
* 泛型 `C` 为业务自定义的配置 map(顶层每个 key 对应一组配置对象);基座对 `C`
|
|
6
|
+
* 的字段语义不透明,只提供「响应式持有 + 单字段一级浅合并 update + 只读暴露」三件事。
|
|
7
|
+
*/
|
|
8
|
+
export interface BridgeConfigHook<C extends object> {
|
|
9
|
+
/** 配置只读响应式视图(`readonly(reactive(...))`,经 `update` 后自动跟随) */
|
|
10
|
+
config: DeepReadonly<C>;
|
|
11
|
+
/** 单字段一级浅合并 update(`Object.assign` 派发到对应 reactive 子配置) */
|
|
12
|
+
update: <K extends keyof C>(key: K, partial: Partial<C[K]>) => void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* bridge 响应式配置 hook 工厂。
|
|
16
|
+
*
|
|
17
|
+
* 接收初始配置 map,整体 `reactive()` 化;对外返回 `update`(单字段一级浅合并
|
|
18
|
+
* `Object.assign`,[MUST NOT] 深合并 / merge / clone)+ `config`(`readonly()` 只读视图)。
|
|
19
|
+
* 每次 `createBridge` 调用各自闭包内构造一份,零模块级单例(守实例隔离)。
|
|
20
|
+
*/
|
|
21
|
+
export declare function createBridgeConfigHook<C extends object>(init: C): BridgeConfigHook<C>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { App, DeepReadonly } from 'vue';
|
|
2
|
+
import { createUseState } from './state';
|
|
3
|
+
import { BridgePluginLike } from './plugin';
|
|
4
|
+
export { createUseState, type UseStateOptions } from './state';
|
|
5
|
+
export { createStorageWithNamespace } from './storage';
|
|
6
|
+
export { BRIDGE_KEY } from '../inject/key';
|
|
7
|
+
export type { BridgePlugin, BridgePluginInstall, BridgePluginContext, BridgePluginLike, BridgePluginBridgeSlice, } from './plugin';
|
|
8
|
+
/** `createBridge` 入参。 */
|
|
9
|
+
export interface BridgeOptions<C extends object> {
|
|
10
|
+
/** 初始配置 map(业务自定义;基座对字段语义不透明) */
|
|
11
|
+
config: C;
|
|
12
|
+
/**
|
|
13
|
+
* 命名空间(派生内部 storage / useState 的 key 前缀)。
|
|
14
|
+
* 不传或为空串时兜底为 `"BRIDGE"`(空串额外 console.error 告警)。
|
|
15
|
+
*/
|
|
16
|
+
namespace?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* bridge 实例类型。
|
|
20
|
+
*
|
|
21
|
+
* 一个**可作为 Vue 插件安装**(`app.use(bridge)`)、**自身又是插件宿主**
|
|
22
|
+
* (`bridge.use(plugin)`)的轻量基座,内含只读响应式配置 + 增量 update +
|
|
23
|
+
* 命名空间化的 storage / useState 原语。泛型 `C` = 业务配置 map。
|
|
24
|
+
*/
|
|
25
|
+
export interface Bridge<C extends object = Record<string, object>> {
|
|
26
|
+
/** 配置只读响应式视图(经 `update` 后自动跟随;[MUST NOT] 解构/快照取值) */
|
|
27
|
+
config: DeepReadonly<C>;
|
|
28
|
+
/** 单字段一级浅合并 update(未传字段保留;[MUST NOT] 期望深合并) */
|
|
29
|
+
update: <K extends keyof C>(key: K, partial: Partial<C[K]>) => void;
|
|
30
|
+
/**
|
|
31
|
+
* 安装 bridge 插件。
|
|
32
|
+
*
|
|
33
|
+
* 插件状态按 bridge 实例隔离;同一插件引用或同名插件重复安装时会跳过。
|
|
34
|
+
* `app.use(bridge)` 只负责 Vue provide,完整插件扩展走本方法。
|
|
35
|
+
*/
|
|
36
|
+
use: <Options = unknown>(plugin: BridgePluginLike<C, Options>, options?: Options) => Bridge<C>;
|
|
37
|
+
/**
|
|
38
|
+
* Vue 插件 install。
|
|
39
|
+
*
|
|
40
|
+
* `app.use(bridge)` 经 `app.provide(BRIDGE_KEY, bridge)` 全局注入整个 bridge 实例;
|
|
41
|
+
* 子组件 `inject(BRIDGE_KEY)` 拿到整 bridge。**opt-in**:不 `app.use(bridge)` 则
|
|
42
|
+
* inject 返回 undefined。
|
|
43
|
+
*/
|
|
44
|
+
install: (app: App) => App;
|
|
45
|
+
/** 返回 bridge 内部派生的命名空间化 storage 实例(引用稳定,多次调用 `===`) */
|
|
46
|
+
getStorage: () => Storage;
|
|
47
|
+
/** bridge 内部派生 useState 实例方法(ns 已绑定,调用方零 ns 参) */
|
|
48
|
+
useState: ReturnType<typeof createUseState>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* bridge 无状态纯工厂:接收 options,内部立即初始化,返回可直接使用的 `Bridge` 实例。
|
|
52
|
+
*
|
|
53
|
+
* 实例状态(config / storage / 插件宿主)仅存在于本次调用的闭包内,工厂自身零状态、
|
|
54
|
+
* 零模块级单例(避免 dist/src 双 module instance 分裂;[MUST NOT] 用 globalThis 兜底)。
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* interface AppConfig {
|
|
58
|
+
* base: { title: string };
|
|
59
|
+
* theme: { dark: boolean };
|
|
60
|
+
* }
|
|
61
|
+
* const bridge = createBridge<AppConfig>({
|
|
62
|
+
* namespace: "myapp",
|
|
63
|
+
* config: { base: { title: "Hi" }, theme: { dark: false } },
|
|
64
|
+
* });
|
|
65
|
+
* app.use(bridge); // Vue 插件:provide BRIDGE_KEY
|
|
66
|
+
* bridge.use(somePlugin, { ... }); // 插件宿主:扩展能力
|
|
67
|
+
* bridge.update("theme", { dark: true }); // 单字段浅合并
|
|
68
|
+
*/
|
|
69
|
+
export declare function createBridge<C extends object>(options: BridgeOptions<C>): Bridge<C>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Bridge } from './index';
|
|
2
|
+
/**
|
|
3
|
+
* 插件可访问的 bridge 视图。
|
|
4
|
+
*
|
|
5
|
+
* 屏蔽运行时编排入口(`use` / `install`);插件只通过公开 bridge 能力(`config` /
|
|
6
|
+
* `update` / `getStorage` / `useState`)与受控 action 工作,不访问 bridge 内部闭包状态。
|
|
7
|
+
*/
|
|
8
|
+
export type BridgePluginBridgeSlice<C extends object> = Omit<Bridge<C>, "use" | "install">;
|
|
9
|
+
/**
|
|
10
|
+
* bridge 插件安装上下文。
|
|
11
|
+
*
|
|
12
|
+
* 插件只通过公开 bridge 实例与受控 action 工作,不访问 bridge 内部闭包状态。
|
|
13
|
+
*/
|
|
14
|
+
export interface BridgePluginContext<C extends object> {
|
|
15
|
+
/** 当前安装插件的 bridge 可用能力 */
|
|
16
|
+
bridge: BridgePluginBridgeSlice<C>;
|
|
17
|
+
/** 配置更新 action 的便捷引用 */
|
|
18
|
+
update: <K extends keyof C>(key: K, partial: Partial<C[K]>) => void;
|
|
19
|
+
}
|
|
20
|
+
/** bridge 插件安装函数。 */
|
|
21
|
+
export type BridgePluginInstall<C extends object, Options = unknown> = (ctx: BridgePluginContext<C>, options?: Options) => void;
|
|
22
|
+
/** bridge 对象插件。 */
|
|
23
|
+
export interface BridgePlugin<C extends object, Options = unknown> {
|
|
24
|
+
/** 插件名;存在时用于跨对象实例的幂等安装 */
|
|
25
|
+
name?: string;
|
|
26
|
+
/** 插件安装函数 */
|
|
27
|
+
install: BridgePluginInstall<C, Options>;
|
|
28
|
+
}
|
|
29
|
+
/** bridge 支持函数插件与对象插件两种形态。 */
|
|
30
|
+
export type BridgePluginLike<C extends object, Options = unknown> = BridgePlugin<C, Options> | BridgePluginInstall<C, Options>;
|
|
31
|
+
/** 创建单个 bridge 实例专属的插件安装宿主。 */
|
|
32
|
+
export declare function createBridgePluginHost<C extends object>(): {
|
|
33
|
+
use: <Options = unknown>(payload: {
|
|
34
|
+
bridge: Bridge<C>;
|
|
35
|
+
update: BridgePluginContext<C>["update"];
|
|
36
|
+
plugin: BridgePluginLike<C, Options>;
|
|
37
|
+
options?: Options;
|
|
38
|
+
}) => Bridge<C>;
|
|
39
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface UseStateOptions {
|
|
2
|
+
/** 是否调试 */
|
|
3
|
+
debug: boolean;
|
|
4
|
+
/** 模块命名空间 */
|
|
5
|
+
moduleKey: string;
|
|
6
|
+
/** 缓存 */
|
|
7
|
+
cache?: boolean;
|
|
8
|
+
/** 缓存实现 */
|
|
9
|
+
storage?: Storage;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* 创建 useState 工厂
|
|
13
|
+
* ---
|
|
14
|
+
* 工厂模式:上层传入命名空间,基座不感知具体值
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* const useState = createUseState("myapp");
|
|
18
|
+
* const moduleState = useState({ count: 0 }, { debug: true, moduleKey: "counter" });
|
|
19
|
+
* // cacheKey 形如 "myapp/useState/counter"
|
|
20
|
+
*/
|
|
21
|
+
export declare const createUseState: (factoryNamespace: string) => <S extends Record<string, any> = Record<string, any>>(initState: S | (() => S), { debug, moduleKey, cache, storage }?: UseStateOptions) => {
|
|
22
|
+
state: any;
|
|
23
|
+
getStateInit: () => S;
|
|
24
|
+
resetState: () => void;
|
|
25
|
+
updateState: (newStateObj?: Partial<S>) => void;
|
|
26
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 创建带命名空间的 localStorage 实例
|
|
3
|
+
* ---
|
|
4
|
+
* 工厂模式:上层传入命名空间,基座不感知具体值
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* const myStorage = createStorageWithNamespace("myapp");
|
|
8
|
+
* myStorage.setItem("token", "xxx"); // 实际写入 localStorage 的 key 为 "myapp/token"
|
|
9
|
+
*/
|
|
10
|
+
export declare const createStorageWithNamespace: (namespace: string) => Storage;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { AiDataPart, AiToolPart, XBubbleListItemProps } from '../../types';
|
|
2
|
+
import { CodeBlockHeaderExpose } from 'vue-element-plus-x/types/components/XMarkdownCore/components/CodeBlock/shiki-header';
|
|
3
|
+
type __VLS_Props = {
|
|
4
|
+
item: XBubbleListItemProps;
|
|
5
|
+
codeXSlot: CodeBlockHeaderExpose;
|
|
6
|
+
/** 展示打字机效果的消息uuid */
|
|
7
|
+
typingMsgUuid?: string;
|
|
8
|
+
/**
|
|
9
|
+
* markdown 是否允许内联 HTML(透传 XMarkdown allowHtml)。
|
|
10
|
+
* ----
|
|
11
|
+
* 默认 true(沿用既有口径);AiDialogue 不传 → 行为零变。
|
|
12
|
+
*/
|
|
13
|
+
allowHtml?: boolean;
|
|
14
|
+
};
|
|
15
|
+
declare function __VLS_template(): {
|
|
16
|
+
attrs: Partial<{}>;
|
|
17
|
+
slots: Readonly<{
|
|
18
|
+
/** 业务 data part 渲染口;缺省退回平台占位。 */
|
|
19
|
+
part: (props: {
|
|
20
|
+
part: AiDataPart;
|
|
21
|
+
item: XBubbleListItemProps;
|
|
22
|
+
}) => unknown;
|
|
23
|
+
/** 工具调用 part 渲染口(generative UI / 人在环表单);缺省退回平台状态机块。 */
|
|
24
|
+
tool: (props: {
|
|
25
|
+
part: AiToolPart;
|
|
26
|
+
item: XBubbleListItemProps;
|
|
27
|
+
}) => unknown;
|
|
28
|
+
}> & {
|
|
29
|
+
/** 业务 data part 渲染口;缺省退回平台占位。 */
|
|
30
|
+
part: (props: {
|
|
31
|
+
part: AiDataPart;
|
|
32
|
+
item: XBubbleListItemProps;
|
|
33
|
+
}) => unknown;
|
|
34
|
+
/** 工具调用 part 渲染口(generative UI / 人在环表单);缺省退回平台状态机块。 */
|
|
35
|
+
tool: (props: {
|
|
36
|
+
part: AiToolPart;
|
|
37
|
+
item: XBubbleListItemProps;
|
|
38
|
+
}) => unknown;
|
|
39
|
+
};
|
|
40
|
+
refs: {};
|
|
41
|
+
rootEl: HTMLDivElement;
|
|
42
|
+
};
|
|
43
|
+
type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
|
|
44
|
+
declare const __VLS_component: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {} & {
|
|
45
|
+
typingFinished: (uuid: string) => any;
|
|
46
|
+
}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
47
|
+
onTypingFinished?: ((uuid: string) => any) | undefined;
|
|
48
|
+
}>, {
|
|
49
|
+
allowHtml: boolean;
|
|
50
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, HTMLDivElement>;
|
|
51
|
+
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
|
|
52
|
+
export default _default;
|
|
53
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
54
|
+
new (): {
|
|
55
|
+
$slots: S;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { XBubbleListItemProps } from '../../types';
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
item: XBubbleListItemProps;
|
|
4
|
+
};
|
|
5
|
+
declare const _default: 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>;
|
|
6
|
+
export default _default;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CodeBlockExpose } from 'vue-element-plus-x/types/components/XMarkdownCore/components/CodeBlock/shiki-header';
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
/** 库注入的代码块 expose(含 raw / isExpand / toggleExpand / copyCode) */
|
|
4
|
+
codeBlock: CodeBlockExpose;
|
|
5
|
+
};
|
|
6
|
+
declare const _default: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
7
|
+
export default _default;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { XBubbleListItemProps } from '../../types';
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
/** 展示的内容
|
|
4
|
+
* ---
|
|
5
|
+
* 不看 item.content
|
|
6
|
+
*/
|
|
7
|
+
textShow: string;
|
|
8
|
+
/** 分割符 */
|
|
9
|
+
splitMark?: string;
|
|
10
|
+
/** 消息对象 */
|
|
11
|
+
item: XBubbleListItemProps;
|
|
12
|
+
};
|
|
13
|
+
declare function __VLS_template(): {
|
|
14
|
+
attrs: Partial<{}>;
|
|
15
|
+
slots: {
|
|
16
|
+
default?(_: {
|
|
17
|
+
text: string;
|
|
18
|
+
}): any;
|
|
19
|
+
default?(_: {
|
|
20
|
+
text: string;
|
|
21
|
+
}): any;
|
|
22
|
+
};
|
|
23
|
+
refs: {};
|
|
24
|
+
rootEl: HTMLDivElement;
|
|
25
|
+
};
|
|
26
|
+
type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
|
|
27
|
+
declare const __VLS_component: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
28
|
+
splitMark: 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,9 @@
|
|
|
1
|
+
import { AiMessagePart, XBubbleListItemProps } from '../../types';
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
/** 非 text part(reasoning / tool-call / file / data-*) */
|
|
4
|
+
part: AiMessagePart;
|
|
5
|
+
/** 气泡项(reasoning 标题态取 isAborted;缺省时降级为无中止态) */
|
|
6
|
+
item?: XBubbleListItemProps;
|
|
7
|
+
};
|
|
8
|
+
declare const _default: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
9
|
+
export default _default;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { XBubbleListItemProps } from '../../types';
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
/** 正在思考 */
|
|
4
|
+
isThinking?: boolean;
|
|
5
|
+
/**
|
|
6
|
+
* 消息对象(isAborted / thinkTime 驱动标题态)。
|
|
7
|
+
* q21yfk 起可选——reasoning part 路径(AiPartRenderer)复用本组件时可无完整 item。
|
|
8
|
+
*/
|
|
9
|
+
item?: XBubbleListItemProps;
|
|
10
|
+
/** 思考耗时(秒),优先于 `item.thinkTime`(reasoning part 自带耗时时用) */
|
|
11
|
+
thinkTime?: number;
|
|
12
|
+
};
|
|
13
|
+
declare function __VLS_template(): {
|
|
14
|
+
attrs: Partial<{}>;
|
|
15
|
+
slots: {
|
|
16
|
+
default?(_: {}): any;
|
|
17
|
+
};
|
|
18
|
+
refs: {};
|
|
19
|
+
rootEl: HTMLDivElement;
|
|
20
|
+
};
|
|
21
|
+
type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
|
|
22
|
+
declare const __VLS_component: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
23
|
+
isThinking: boolean;
|
|
24
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, HTMLDivElement>;
|
|
25
|
+
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
|
|
26
|
+
export default _default;
|
|
27
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
28
|
+
new (): {
|
|
29
|
+
$slots: S;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AiTypewriterProps } from '../../types';
|
|
2
|
+
declare function __VLS_template(): {
|
|
3
|
+
attrs: Partial<{}>;
|
|
4
|
+
slots: {
|
|
5
|
+
default?(_: {
|
|
6
|
+
textShow: string;
|
|
7
|
+
}): any;
|
|
8
|
+
};
|
|
9
|
+
refs: {};
|
|
10
|
+
rootEl: any;
|
|
11
|
+
};
|
|
12
|
+
type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
|
|
13
|
+
declare const __VLS_component: import('vue').DefineComponent<AiTypewriterProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {} & {
|
|
14
|
+
finished: () => any;
|
|
15
|
+
}, string, import('vue').PublicProps, Readonly<AiTypewriterProps> & Readonly<{
|
|
16
|
+
onFinished?: (() => any) | undefined;
|
|
17
|
+
}>, {
|
|
18
|
+
step: number;
|
|
19
|
+
interval: number;
|
|
20
|
+
suffix: string;
|
|
21
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
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,28 @@
|
|
|
1
|
+
import { AiAskExpose } from '../../hooks/expose';
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
isDarkTheme: boolean;
|
|
4
|
+
};
|
|
5
|
+
declare function __VLS_template(): {
|
|
6
|
+
attrs: Partial<{}>;
|
|
7
|
+
slots: {
|
|
8
|
+
default?(_: {}): any;
|
|
9
|
+
};
|
|
10
|
+
refs: {};
|
|
11
|
+
rootEl: any;
|
|
12
|
+
};
|
|
13
|
+
type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
|
|
14
|
+
declare const __VLS_component: import('vue').DefineComponent<__VLS_Props, {
|
|
15
|
+
/** 向**当前激活会话**发一条消息(等价快捷问题卡的点击) */
|
|
16
|
+
ask: (params: Parameters<AiAskExpose>[0]) => Promise<import('../..').AiSessionBaseSimpleInfo> | undefined;
|
|
17
|
+
/** 当前激活会话的输入框(focus / blur / openHeader / closeHeader) */
|
|
18
|
+
sender: () => import('../..').AiSenderExpose | undefined;
|
|
19
|
+
/** 会话级操作(create / switch)——由 AiDialogueGroup 注册,单会话场景为 undefined */
|
|
20
|
+
sessionOperate: () => import('../..').AiSessionOperateExpose | undefined;
|
|
21
|
+
}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
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
|
+
};
|