wi-chat 0.0.0-stage → 0.4.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/dist/core/index.cjs +2 -0
- package/dist/core/index.d.ts +13 -0
- package/dist/core/index.js +454 -0
- package/dist/core/useAgent.d.ts +35 -0
- package/dist/core/useChat.d.ts +195 -0
- package/dist/core/useChatSession.d.ts +89 -0
- package/dist/core/useHistory.d.ts +63 -0
- package/dist/index.cjs +2 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +81 -0
- package/dist/mobile-ui/chat/ChatContainer.vue.d.ts +129 -0
- package/dist/mobile-ui/chat/ChatMessagesView.vue.d.ts +77 -0
- package/dist/mobile-ui/chat/types.d.ts +9 -0
- package/dist/mobile-ui/index.cjs +2 -0
- package/dist/mobile-ui/index.d.ts +7 -0
- package/dist/mobile-ui/index.js +225 -0
- package/dist/mobile-ui/inputbox/Inputbox.vue.d.ts +95 -0
- package/dist/mobile-ui/style.css +1 -0
- package/dist/parser/answer.d.ts +51 -0
- package/dist/parser/answerCom/iframePage/parseIframePage.d.ts +49 -0
- package/dist/parser/answerCom/iframePage/types.d.ts +11 -0
- package/dist/parser/answerCom/knowledgeStream/parseKnowledgeStream.d.ts +54 -0
- package/dist/parser/answerCom/knowledgeStream/types.d.ts +27 -0
- package/dist/parser/answerCom/outputFile/parseOutputFile.d.ts +43 -0
- package/dist/parser/answerCom/outputFile/types.d.ts +17 -0
- package/dist/parser/answerCom/recordset/parseRecordset.d.ts +48 -0
- package/dist/parser/answerCom/recordset/types.d.ts +36 -0
- package/dist/parser/attach/attachActions.d.ts +43 -0
- package/dist/parser/attach/index.d.ts +9 -0
- package/dist/parser/attach/parseAttach.d.ts +27 -0
- package/dist/parser/attach/types.d.ts +48 -0
- package/dist/parser/deepThinking/parseDeepThinking.d.ts +30 -0
- package/dist/parser/deepThinking/types.d.ts +14 -0
- package/dist/parser/history/history.d.ts +54 -0
- package/dist/parser/history/index.d.ts +7 -0
- package/dist/parser/index.cjs +3 -0
- package/dist/parser/index.d.ts +45 -0
- package/dist/parser/index.js +479 -0
- package/dist/parser/message.d.ts +60 -0
- package/dist/parser/registry.d.ts +81 -0
- package/dist/parser/sse.d.ts +34 -0
- package/dist/parser/stream.d.ts +8 -0
- package/dist/renderers/aiAnswer/AiAnswerBubble.vue.d.ts +58 -0
- package/dist/renderers/aiAnswer/contentMap.d.ts +13 -0
- package/dist/renderers/deepThinking/DeepThinkingSteps.vue.d.ts +21 -0
- package/dist/renderers/iframePage/IframePage.vue.d.ts +19 -0
- package/dist/renderers/iframePage/useIframePage.d.ts +64 -0
- package/dist/renderers/index.cjs +2 -0
- package/dist/renderers/index.d.ts +12 -0
- package/dist/renderers/index.js +609 -0
- package/dist/renderers/knowledgeStream/KnowledgeStreamResult.vue.d.ts +19 -0
- package/dist/renderers/outputFile/OutputFile.vue.d.ts +19 -0
- package/dist/renderers/outputFile/useOutputFile.d.ts +85 -0
- package/dist/renderers/style.css +1 -0
- package/dist/request/api.d.ts +132 -0
- package/dist/request/client.d.ts +30 -0
- package/dist/request/index.cjs +4 -0
- package/dist/request/index.d.ts +18 -0
- package/dist/request/index.js +264 -0
- package/dist/request/login.d.ts +37 -0
- package/dist/request/ws.d.ts +91 -0
- package/dist/style.css +24 -0
- package/dist/styles/github.css +2 -0
- package/dist/styles/katex.css +2 -0
- package/dist/theme/index.cjs +3 -0
- package/dist/theme/index.d.ts +3 -0
- package/dist/theme/index.js +37 -0
- package/dist/theme/theme.d.ts +40 -0
- package/dist/tools/attachDownload.d.ts +20 -0
- package/dist/tools/index.cjs +17 -0
- package/dist/tools/index.d.ts +8 -0
- package/dist/tools/index.js +251 -0
- package/dist/tools/markdown/MarkdownContent.vue.d.ts +36 -0
- package/dist/tools/markdown/imagePreview.d.ts +15 -0
- package/dist/tools/markdown/index.d.ts +5 -0
- package/dist/tools/markdown/renderMarkdown.d.ts +22 -0
- package/dist/tools/markdown/tableDownload.d.ts +14 -0
- package/dist/tools/stream.d.ts +9 -0
- package/dist/tools/style.css +1 -0
- package/dist/tools/useAutoScroll.d.ts +31 -0
- package/dist/web-ui/attach/AttachmentCard.vue.d.ts +91 -0
- package/dist/web-ui/attach/AttachmentList.vue.d.ts +94 -0
- package/dist/web-ui/attach/types.d.ts +5 -0
- package/dist/web-ui/chat/ChatContainer.vue.d.ts +165 -0
- package/dist/web-ui/chat/ChatMessagesView.vue.d.ts +88 -0
- package/dist/web-ui/chat/types.d.ts +24 -0
- package/dist/web-ui/envswitch/EnvSwitch.vue.d.ts +67 -0
- package/dist/web-ui/envswitch/types.d.ts +22 -0
- package/dist/web-ui/index.cjs +2 -0
- package/dist/web-ui/index.d.ts +14 -0
- package/dist/web-ui/index.js +1048 -0
- package/dist/web-ui/inputbox/Inputbox.vue.d.ts +215 -0
- package/dist/web-ui/recordset/RecordsetTable.vue.d.ts +37 -0
- package/dist/web-ui/recordset/webAnswerContentMap.d.ts +9 -0
- package/dist/web-ui/style.css +1 -0
- package/package.json +124 -4
- package/styles/github.css +2 -0
- package/styles/katex.css +2 -0
- package/README.md +0 -3
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { ComputedRef, MaybeRefOrGetter, Ref } from 'vue';
|
|
2
|
+
import { AiAnswerReport, OutputFileValue } from 'wi-chat/parser';
|
|
3
|
+
|
|
4
|
+
/** 文件预览类型 */
|
|
5
|
+
export type OutputFilePreviewKind = 'image' | 'pdf' | 'html' | 'text' | 'code' | 'audio' | 'video' | 'office' | 'unknown';
|
|
6
|
+
/** 宿主接管预览时收到的请求 */
|
|
7
|
+
export interface OutputFilePreviewRequest {
|
|
8
|
+
/** 文件 id */
|
|
9
|
+
fileId: string;
|
|
10
|
+
/** 文件名(含扩展名) */
|
|
11
|
+
fileName: string;
|
|
12
|
+
/** 加载文件二进制(带缓存) */
|
|
13
|
+
loadFile: () => Promise<Blob>;
|
|
14
|
+
/** 下载文件(已加载时直接复用缓存) */
|
|
15
|
+
download: () => Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
/** 宿主注入的 outputFile 配置(provide/inject 通道,见 provideOutputFileConfig) */
|
|
18
|
+
export interface OutputFileConfig {
|
|
19
|
+
/**
|
|
20
|
+
* 按 file_id 加载文件二进制(推荐):宿主用自己的请求层实现,
|
|
21
|
+
* 可携带鉴权头、走 POST /file/download_file 等。
|
|
22
|
+
*/
|
|
23
|
+
loadFile?: (fileId: string) => Promise<Blob>;
|
|
24
|
+
/**
|
|
25
|
+
* 文件直链(loadFile 缺省时使用):本模块用 fetch 拉取并转 Blob。
|
|
26
|
+
* 内置 Web 消息视图默认注入 ChatApi.getFileUrl 的结果。
|
|
27
|
+
*/
|
|
28
|
+
getFileUrl?: (fileId: string) => string;
|
|
29
|
+
/** 追加请求头(如 wisession),仅 getFileUrl 的 fetch 路径使用 */
|
|
30
|
+
getHeaders?: () => Record<string, string>;
|
|
31
|
+
/**
|
|
32
|
+
* 完全接管预览:提供后点击文件卡片不再渲染内置抽屉,
|
|
33
|
+
* 由宿主打开自己的侧边栏 / 弹窗等。
|
|
34
|
+
*/
|
|
35
|
+
openPreview?: (request: OutputFilePreviewRequest) => void;
|
|
36
|
+
/** 自定义下载:缺省用 Blob + a[download] 触发浏览器下载 */
|
|
37
|
+
downloadFile?: (payload: {
|
|
38
|
+
fileId: string;
|
|
39
|
+
fileName: string;
|
|
40
|
+
blob: Blob;
|
|
41
|
+
}) => void;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* 宿主注入 outputFile 配置:在组件 setup 内调用一次,其组件树内的 OutputFile
|
|
45
|
+
* (含懒加载渲染器)即可通过 useOutputFile 读到。
|
|
46
|
+
* @param config 宿主配置(loadFile / getFileUrl / openPreview / downloadFile 等)
|
|
47
|
+
*/
|
|
48
|
+
export declare const provideOutputFileConfig: (config: OutputFileConfig) => void;
|
|
49
|
+
/** useOutputFile 返回值:纯 UI 组件渲染文件卡片与预览抽屉所需的全部状态 */
|
|
50
|
+
export interface UseOutputFileReturn {
|
|
51
|
+
/** 文件 id */
|
|
52
|
+
fileId: ComputedRef<string>;
|
|
53
|
+
/** 文件名(缺省「未命名文件」) */
|
|
54
|
+
fileName: ComputedRef<string>;
|
|
55
|
+
/** 扩展名(小写,无扩展名时为空串) */
|
|
56
|
+
extension: ComputedRef<string>;
|
|
57
|
+
/** 预览类型 */
|
|
58
|
+
previewKind: ComputedRef<OutputFilePreviewKind>;
|
|
59
|
+
/** 文件大小文案(未加载时为空串) */
|
|
60
|
+
fileSize: ComputedRef<string>;
|
|
61
|
+
/** 内置抽屉是否可见 */
|
|
62
|
+
visible: Ref<boolean>;
|
|
63
|
+
/** 文件是否加载中 */
|
|
64
|
+
loading: Ref<boolean>;
|
|
65
|
+
/** 加载 / 下载错误文案 */
|
|
66
|
+
error: Ref<string>;
|
|
67
|
+
/** 是否属于暂不支持在线预览的类型(Office / 二进制未知类型) */
|
|
68
|
+
unsupported: Ref<boolean>;
|
|
69
|
+
/** 文本 / HTML / 代码预览内容 */
|
|
70
|
+
textContent: Ref<string>;
|
|
71
|
+
/** 图片 / PDF / 音视频预览的 object URL */
|
|
72
|
+
objectUrl: Ref<string>;
|
|
73
|
+
/** 打开预览(有 openPreview 时交给宿主) */
|
|
74
|
+
open: () => Promise<void>;
|
|
75
|
+
/** 关闭内置抽屉 */
|
|
76
|
+
close: () => void;
|
|
77
|
+
/** 下载文件 */
|
|
78
|
+
download: () => Promise<void>;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* outputFile 操作逻辑:从 report 算出文件信息,并提供加载 / 预览 / 下载能力。
|
|
82
|
+
* @param report output_file 报告(支持 ref / getter / 直接对象,流式更新时自动重算)
|
|
83
|
+
* @returns 文件信息、抽屉状态与操作方法
|
|
84
|
+
*/
|
|
85
|
+
export declare const useOutputFile: (report: MaybeRefOrGetter<AiAnswerReport<OutputFileValue> | undefined>) => UseOutputFileReturn;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@charset "UTF-8";.flex[data-v-efad55c8]{display:flex}.justify-start[data-v-efad55c8]{justify-content:flex-start}.ai-answer-bubble[data-v-efad55c8]{width:100%;min-width:0;color:#27344d;font-size:14px;line-height:1.75;word-break:break-word}.ai-answer-bubble__error[data-v-efad55c8]{color:#f56c6c}.ai-answer-bubble__status[data-v-efad55c8]{margin-top:4px;color:#8a93a6;font-size:12px}.ai-answer-bubble__loading[data-v-efad55c8]{display:flex;align-items:center;gap:8px;color:#76819a}.ai-answer-bubble__pulse[data-v-efad55c8]{width:7px;height:7px;border-radius:50%;background:var(--wi-chat-primary);box-shadow:0 0 #5b7fff4d;animation:wi-answer-pulse-efad55c8 1.6s ease-out infinite}@keyframes wi-answer-pulse-efad55c8{70%{box-shadow:0 0 0 6px #5b7fff00}to{box-shadow:0 0 #5b7fff00}}.deep-thinking[data-v-c6f5cb64]{margin-bottom:12px;overflow:hidden;border:1px solid color-mix(in srgb,var(--wi-chat-primary) 20%,transparent);border-radius:9px;background:color-mix(in srgb,var(--wi-chat-primary) 6%,#fff)}.deep-thinking__header[data-v-c6f5cb64]{display:flex;align-items:center;gap:8px;width:100%;padding:9px 11px;border:0;background:transparent;color:#53617c;cursor:pointer;transition:background-color .2s ease,color .2s ease}.deep-thinking__header[data-v-c6f5cb64]:hover{background:color-mix(in srgb,var(--wi-chat-primary) 8%,transparent);color:var(--wi-chat-primary)}.deep-thinking__title[data-v-c6f5cb64]{display:flex;flex:1;align-items:center;gap:8px;text-align:left;font-weight:600}.deep-thinking__title[data-v-c6f5cb64]:before{width:6px;height:6px;border-radius:50%;background:var(--wi-chat-primary);content:""}.deep-thinking__count[data-v-c6f5cb64],.deep-thinking__index[data-v-c6f5cb64]{display:inline-flex;align-items:center;justify-content:center;min-width:20px;height:20px;border-radius:50%;font-size:12px}.deep-thinking__count[data-v-c6f5cb64]{background:color-mix(in srgb,var(--wi-chat-primary) 10%,transparent);color:var(--wi-chat-primary);font-weight:600}.deep-thinking__list[data-v-c6f5cb64]{display:flex;flex-direction:column;gap:9px;padding:10px 11px 11px;border-top:1px solid #e8ecf8;background:#ffffffb8;color:#5f6d87}.deep-thinking__item[data-v-c6f5cb64]{display:grid;grid-template-columns:20px minmax(0,1fr);gap:8px;font-size:13px;line-height:20px}.deep-thinking__index[data-v-c6f5cb64]{border:1px solid #dce3f3;background:#fff;color:#687597}.deep-thinking__item[data-v-c6f5cb64] p{margin:0}.knowledge-result>div+div[data-v-1827e802]{margin-top:12px}.knowledge-result[data-v-1827e802] .markdown-it{overflow-wrap:break-word}.knowledge-result[data-v-1827e802] .wi-md-table-wrap{position:relative}.knowledge-result[data-v-1827e802] .wi-md-table-download{position:absolute;top:4px;right:4px;display:inline-flex;align-items:center;justify-content:center;padding:4px;border:1px solid var(--wi-chat-border, #e1e4e8);border-radius:4px;background:var(--wi-chat-bg, #fff);color:var(--wi-chat-text-secondary, #8a93a6);cursor:pointer;opacity:0;transition:opacity .2s ease;z-index:10}.knowledge-result[data-v-1827e802] .wi-md-table-wrap:hover .wi-md-table-download{opacity:1}.knowledge-result[data-v-1827e802] .wi-md-table-download:hover{color:var(--wi-chat-primary, #5b7fff);border-color:var(--wi-chat-primary, #5b7fff)}.wi-output-file[data-v-f61a91b5]{width:100%;max-width:380px}.wi-output-file__card[data-v-f61a91b5]{display:flex;align-items:center;gap:12px;width:100%;padding:12px 14px;border:1px solid var(--wi-chat-border, #e1e4e8);border-left:3px solid var(--wi-chat-primary, #5b7fff);border-radius:12px;background:var(--wi-chat-bg, #fff);cursor:pointer;transition:border-color .16s ease,box-shadow .16s ease,transform .16s ease}.wi-output-file__card[data-v-f61a91b5]:hover,.wi-output-file__card[data-v-f61a91b5]:focus-visible{border-color:color-mix(in srgb,var(--wi-chat-primary, #5b7fff) 45%,#fff);box-shadow:0 10px 26px #2d5ba021;outline:none;transform:translateY(-1px)}.wi-output-file__icon[data-v-f61a91b5]{display:grid;flex:0 0 40px;width:40px;height:46px;place-items:center;border:1px solid #e4ebf5;border-radius:9px;background:#f3f7fd;color:var(--wi-chat-primary, #5b7fff)}.wi-output-file__icon svg[data-v-f61a91b5]{width:22px;height:22px}.wi-output-file__icon.is-image[data-v-f61a91b5]{background:#eefbf4;border-color:#d6f0e0;color:#16a34a}.wi-output-file__icon.is-pdf[data-v-f61a91b5]{background:#fff1f0;border-color:#fbd9d6;color:#e5484d}.wi-output-file__icon.is-office[data-v-f61a91b5]{background:#eef4ff;border-color:#dbe7ff;color:#2f6feb}.wi-output-file__icon.is-audio[data-v-f61a91b5],.wi-output-file__icon.is-video[data-v-f61a91b5]{background:#f6efff;border-color:#ead9ff;color:#8b5cf6}.wi-output-file__icon.is-text[data-v-f61a91b5],.wi-output-file__icon.is-code[data-v-f61a91b5],.wi-output-file__icon.is-html[data-v-f61a91b5]{background:#f4f6fa;border-color:#e3e8f0;color:#536176}.wi-output-file__info[data-v-f61a91b5]{flex:1;min-width:0}.wi-output-file__name[data-v-f61a91b5]{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--wi-chat-text, #27344d);font-size:14px;font-weight:600}.wi-output-file__meta[data-v-f61a91b5]{display:flex;align-items:center;gap:8px;margin-top:4px;color:var(--wi-chat-text-secondary, #8a93a6);font-size:11px}.wi-output-file__ext[data-v-f61a91b5]{font-weight:600;letter-spacing:.04em}.wi-output-file__download[data-v-f61a91b5]{display:grid;flex:0 0 32px;width:32px;height:32px;place-items:center;border:1px solid var(--wi-chat-border, #e1e4e8);border-radius:8px;background:#f7f9fc;color:#536176;cursor:pointer;transition:color .15s ease,background .15s ease,border-color .15s ease}.wi-output-file__download[data-v-f61a91b5]:hover,.wi-output-file__download[data-v-f61a91b5]:focus-visible{border-color:var(--wi-chat-primary, #5b7fff);background:var(--wi-chat-primary, #5b7fff);color:#fff;outline:none}.wi-output-file__download svg[data-v-f61a91b5]{width:16px;height:16px}.wi-output-file-mask[data-v-f61a91b5]{position:fixed;top:0;right:0;bottom:0;left:0;z-index:3000;display:flex;justify-content:flex-end;background:#0f172a52}.wi-output-file-drawer[data-v-f61a91b5]{display:flex;flex-direction:column;width:min(620px,92vw);height:100%;background:var(--wi-chat-bg, #fff);box-shadow:-12px 0 32px #0f172a2e}@media (max-width: 640px){.wi-output-file-drawer[data-v-f61a91b5]{width:100vw}}.wi-output-file-drawer__head[data-v-f61a91b5]{display:flex;align-items:flex-start;gap:12px;padding:16px 18px;border-bottom:1px solid var(--wi-chat-border, #e1e4e8)}.wi-output-file-drawer__title[data-v-f61a91b5]{flex:1;min-width:0}.wi-output-file-drawer__ext[data-v-f61a91b5]{display:inline-block;padding:2px 6px;border-radius:4px;background:#eef2ff;color:var(--wi-chat-primary, #5b7fff);font-size:11px;font-weight:600;letter-spacing:.04em}.wi-output-file-drawer__name[data-v-f61a91b5]{margin-top:6px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--wi-chat-text, #27344d);font-size:15px;font-weight:600}.wi-output-file-drawer__size[data-v-f61a91b5]{margin-top:4px;color:var(--wi-chat-text-secondary, #8a93a6);font-size:12px}.wi-output-file-drawer__actions[data-v-f61a91b5]{display:flex;flex:0 0 auto;gap:8px}.wi-output-file-drawer__btn[data-v-f61a91b5]{padding:5px 12px;border:1px solid var(--wi-chat-border, #e1e4e8);border-radius:7px;background:#f7f9fc;color:#536176;font-family:inherit;font-size:12px;cursor:pointer}.wi-output-file-drawer__btn[data-v-f61a91b5]:hover,.wi-output-file-drawer__btn[data-v-f61a91b5]:focus-visible{border-color:var(--wi-chat-primary, #5b7fff);color:var(--wi-chat-primary, #5b7fff);outline:none}.wi-output-file-drawer__btn--close[data-v-f61a91b5]{padding:3px 10px;font-size:18px;line-height:1.2}.wi-output-file-drawer__body[data-v-f61a91b5]{flex:1;min-height:0;padding:16px 18px;overflow:auto;background:#f8fafc}.wi-output-file-drawer__state[data-v-f61a91b5]{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:12px;height:100%;color:var(--wi-chat-text-secondary, #8a93a6);font-size:13px;text-align:center}.wi-output-file-drawer__state.is-error[data-v-f61a91b5]{color:#f56c6c}.wi-output-file-drawer__state p[data-v-f61a91b5]{margin:0}.wi-output-file-drawer__image[data-v-f61a91b5]{display:block;max-width:100%;margin:0 auto;border-radius:8px;background:#fff}.wi-output-file-drawer__frame[data-v-f61a91b5]{width:100%;height:100%;min-height:70vh;border:0;border-radius:8px;background:#fff}.wi-output-file-drawer__media[data-v-f61a91b5]{display:block;width:100%;max-height:70vh;margin:0 auto}.wi-output-file-drawer__text[data-v-f61a91b5]{min-height:100%;margin:0;padding:14px;border:1px solid var(--wi-chat-border, #e1e4e8);border-radius:8px;background:#fff;color:var(--wi-chat-text, #27344d);font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,monospace;font-size:12.5px;line-height:1.6;white-space:pre-wrap;word-break:break-word}.wi-output-file-fade-enter-active[data-v-f61a91b5],.wi-output-file-fade-leave-active[data-v-f61a91b5]{transition:opacity .18s ease}.wi-output-file-fade-enter-from[data-v-f61a91b5],.wi-output-file-fade-leave-to[data-v-f61a91b5]{opacity:0}.iframe-page__frame[data-v-f4c94a4e]{width:100%;border:0}.iframe-page__frame--url[data-v-f4c94a4e]{height:var(--wi-chat-iframe-url-height, 70vh)}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { WsChunkSender } from './ws';
|
|
2
|
+
|
|
3
|
+
/** 历史分组项 */
|
|
4
|
+
export interface HistoryGroup {
|
|
5
|
+
/** 分组 id */
|
|
6
|
+
group_id: string;
|
|
7
|
+
/** 分组标题 */
|
|
8
|
+
group_title?: string;
|
|
9
|
+
/** 分组内会话条数 */
|
|
10
|
+
chat_count?: string | number;
|
|
11
|
+
/** 创建时间(排序键,缺失视为最旧) */
|
|
12
|
+
create_time?: string;
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
}
|
|
15
|
+
/** 历史分组列表响应 */
|
|
16
|
+
export interface HistoryGroupsResult {
|
|
17
|
+
/** 业务成功标记(false 时 client 层已抛错,正常不会见到 false) */
|
|
18
|
+
json_ok?: boolean;
|
|
19
|
+
/** 分组列表(后端原序,未排序) */
|
|
20
|
+
groups?: HistoryGroup[];
|
|
21
|
+
[key: string]: any;
|
|
22
|
+
}
|
|
23
|
+
/** 会话明细记录 */
|
|
24
|
+
export interface HistoryDetailItem {
|
|
25
|
+
/** 明细 id(用于拉取对应单条回答) */
|
|
26
|
+
history_id?: string;
|
|
27
|
+
/** 用户提问文本 */
|
|
28
|
+
question?: string;
|
|
29
|
+
/** 提问时间 */
|
|
30
|
+
create_time?: string;
|
|
31
|
+
[key: string]: any;
|
|
32
|
+
}
|
|
33
|
+
/** 智能体条目 */
|
|
34
|
+
export interface AgentEntryItem {
|
|
35
|
+
/** 智能体入口 ID */
|
|
36
|
+
entry_id: string;
|
|
37
|
+
/** 智能体名称/标题 */
|
|
38
|
+
entry_title?: string;
|
|
39
|
+
/** 智能体图标/图片 ID */
|
|
40
|
+
image_id?: string;
|
|
41
|
+
/** 是否启用 */
|
|
42
|
+
entry_enable?: boolean;
|
|
43
|
+
/** 分组名称 */
|
|
44
|
+
entry_group?: string;
|
|
45
|
+
[key: string]: any;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 对话 + 历史业务端点聚合(由 createChatApi 基于 request 客户端构造)
|
|
49
|
+
*/
|
|
50
|
+
export interface ChatApi {
|
|
51
|
+
/** 拉取历史分组列表(返回后端原序,按 create_time 排序由上层处理) */
|
|
52
|
+
getHistoryGroups(): Promise<HistoryGroupsResult>;
|
|
53
|
+
/** 创建历史分组(groupTitle 为新组标题),返回含 group_id 的响应 */
|
|
54
|
+
createHistoryGroup(groupTitle: string): Promise<{
|
|
55
|
+
group_id?: string;
|
|
56
|
+
[key: string]: any;
|
|
57
|
+
}>;
|
|
58
|
+
/** 删除历史分组(groupId 为目标分组 id) */
|
|
59
|
+
deleteHistoryGroup(groupId: string): Promise<any>;
|
|
60
|
+
/** 修改历史分组标题(groupId 为目标分组 id,title 为新标题) */
|
|
61
|
+
setHistoryGroupTitle(groupId: string, title: string): Promise<any>;
|
|
62
|
+
/**
|
|
63
|
+
* 拉取某分组下的会话明细(仅用户提问记录,回答需按 history_id 另行拉取)。
|
|
64
|
+
* lastEnd 为起始明细序号(默认 0 = 从最近一条往回取),lastCount 为拉取条数(默认 10)。
|
|
65
|
+
*/
|
|
66
|
+
getHistoryDetail(groupId: string, lastEnd?: number, lastCount?: number): Promise<HistoryDetailItem[]>;
|
|
67
|
+
/** 拉取单条明细(historyId)对应的完整回答(reports 等原始结构) */
|
|
68
|
+
getHistoryAnswer(historyId: string): Promise<any>;
|
|
69
|
+
/**
|
|
70
|
+
* 获取系统默认智能体 ID
|
|
71
|
+
*/
|
|
72
|
+
getDefaultLlmId(): Promise<{
|
|
73
|
+
default_entry_id?: string;
|
|
74
|
+
[key: string]: any;
|
|
75
|
+
}>;
|
|
76
|
+
/**
|
|
77
|
+
* 按分组/角色拉取智能体列表
|
|
78
|
+
* @param params entry_group 默认 '智能助手'
|
|
79
|
+
*/
|
|
80
|
+
getLlmEntryListByRole(params?: {
|
|
81
|
+
entry_group?: string;
|
|
82
|
+
}): Promise<{
|
|
83
|
+
values?: AgentEntryItem[];
|
|
84
|
+
[key: string]: any;
|
|
85
|
+
}>;
|
|
86
|
+
/**
|
|
87
|
+
* 获取文件访问完整 URL(针对 algorithm/get_file_data)
|
|
88
|
+
* @param fileId 文件/图片 ID
|
|
89
|
+
*/
|
|
90
|
+
getFileUrl?(fileId: string): string;
|
|
91
|
+
/**
|
|
92
|
+
* WebSocket 流式提问:底层通过 WebSocket 连接 /chat/ws 端点交互,
|
|
93
|
+
* 并封装返回符合 SSE 规范的可读字节流(`ReadableStream<Uint8Array>`),
|
|
94
|
+
* 供上层 `consumeStream` 与 `useChat` 无缝消费。
|
|
95
|
+
* params.question 为提问文本,params.historyGroupId 为目标分组 id,
|
|
96
|
+
* params.entryId 为可选入口 id;params.files 为可选附件文件列表;
|
|
97
|
+
* params.incPrevQuestion 为是否携带之前对话(inc_prev_question:'Y' 不忽略(默认)/ 'N' 忽略);
|
|
98
|
+
* params.onOpen 为连接建立且首包发完后的回调(传输层选项,不会混入发给后端的载荷),
|
|
99
|
+
* 入参为绑定当前连接的分片发送器,可在流结束前向同一条连接追发任意载荷;
|
|
100
|
+
* signal 用于中断(stopQuestion)。
|
|
101
|
+
*/
|
|
102
|
+
questionStream(params: {
|
|
103
|
+
/** 提问文本 */
|
|
104
|
+
question: string;
|
|
105
|
+
/** 目标历史分组 id */
|
|
106
|
+
historyGroupId: string;
|
|
107
|
+
/** 入口(智能体)id */
|
|
108
|
+
entryId?: string;
|
|
109
|
+
/** 附件文件列表(自动序列化为 Base64 结构) */
|
|
110
|
+
files?: File[];
|
|
111
|
+
/** 是否携带之前对话(映射为 inc_prev_question),缺省 'Y' 不忽略 */
|
|
112
|
+
incPrevQuestion?: 'Y' | 'N';
|
|
113
|
+
/**
|
|
114
|
+
* 连接建立且首包载荷发送完毕后的回调:入参为绑定当前连接的分片发送器
|
|
115
|
+
* (B/M/E 分帧追发;连接关闭或流结束后调用静默丢弃)。不透传到后端载荷。
|
|
116
|
+
*/
|
|
117
|
+
onOpen?: (sendInChunks: WsChunkSender) => void;
|
|
118
|
+
/** 其余字段原样透传到首包 payload:如 ext_args 扩展参数(JSON 字符串)、raw_mode / tables / metrics / group_type 等 */
|
|
119
|
+
[key: string]: unknown;
|
|
120
|
+
}, signal?: AbortSignal): Promise<ReadableStream<Uint8Array>>;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* 基于 request 客户端聚合业务 API。
|
|
124
|
+
* @param client 请求客户端(createRequest 的产物,或测试注入的 stub),需提供 post / stream 两个方法
|
|
125
|
+
* @returns 对话 + 历史业务端点集合(见 ChatApi)
|
|
126
|
+
*/
|
|
127
|
+
export declare const createChatApi: (client: {
|
|
128
|
+
baseURL?: string;
|
|
129
|
+
getSession?: () => string | null | undefined;
|
|
130
|
+
post: <T = any>(url: string, data?: Record<string, unknown> | FormData) => Promise<T>;
|
|
131
|
+
stream: (url: string, data?: Record<string, unknown> | FormData, signal?: AbortSignal) => Promise<ReadableStream<Uint8Array>>;
|
|
132
|
+
}) => ChatApi;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** wisession 过期需重新认证标记错误 */
|
|
2
|
+
export declare class AuthExpiredError extends Error {
|
|
3
|
+
constructor(message?: string);
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* 判断错误是否为主动取消(AbortController 触发)。
|
|
7
|
+
* axios(含 fetch 适配器)取消抛 CanceledError(code ERR_CANCELED),
|
|
8
|
+
* 原生 fetch abort 抛 name 为 AbortError 的 DOMException,两种都算。
|
|
9
|
+
*/
|
|
10
|
+
export declare const isCancelError: (error: unknown) => boolean;
|
|
11
|
+
export interface RequestOptions {
|
|
12
|
+
/** 后端基础地址(不含结尾斜杠) */
|
|
13
|
+
baseURL: string;
|
|
14
|
+
/** 提供 wisession 请求头(登录后返回) */
|
|
15
|
+
getWisession?: () => string;
|
|
16
|
+
/** 别名:获取当前登录态 session(若有) */
|
|
17
|
+
getSession?: () => string | null | undefined;
|
|
18
|
+
}
|
|
19
|
+
export interface RequestClient {
|
|
20
|
+
/** 后端基础地址(不含结尾斜杠) */
|
|
21
|
+
baseURL?: string;
|
|
22
|
+
/** 获取当前登录态 session(若有) */
|
|
23
|
+
getSession?: () => string | null | undefined;
|
|
24
|
+
/** 普通业务请求(form-urlencoded),返回解析后的响应对象 */
|
|
25
|
+
post<T = any>(url: string, data?: Record<string, unknown> | FormData): Promise<T>;
|
|
26
|
+
/** SSE 流式请求(form-urlencoded 或 FormData),返回可流式消费的 ReadableStream<Uint8Array> */
|
|
27
|
+
stream(url: string, data?: Record<string, unknown> | FormData, signal?: AbortSignal): Promise<ReadableStream<Uint8Array>>;
|
|
28
|
+
}
|
|
29
|
+
/** 创建请求客户端 */
|
|
30
|
+
export declare const createRequest: (options: RequestOptions) => RequestClient;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
"use strict";var j=Object.create;var A=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var T=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var G=(e,o,t,s)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of Q(o))!q.call(e,r)&&r!==t&&A(e,r,{get:()=>o[r],enumerable:!(s=O(o,r))||s.enumerable});return e};var H=(e,o,t)=>(t=e!=null?j(T(e)):{},G(o||!e||!e.__esModule?A(t,"default",{value:e,enumerable:!0}):t,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("axios");class R extends Error{constructor(o="登录已过期,请重新认证"){super(o),this.name="AuthExpiredError"}}const $=e=>b.isCancel(e)||e instanceof Error&&(e.name==="AbortError"||e.name==="CanceledError"),B=e=>new URLSearchParams(Object.entries(e).reduce((o,[t,s])=>(o[t]=String(s),o),{})),D={},k=e=>{const{baseURL:o,getWisession:t,getSession:s}=e,r=o.replace(/\/$/,""),n=s??t,i=(d=!1)=>{const c={};d||(c["Content-Type"]="application/x-www-form-urlencoded");const u=n==null?void 0:n();return u&&(c.wisession=u),c};return{baseURL:r,getSession:n,post:async(d,c=D)=>{const u=typeof FormData<"u"&&c instanceof FormData,p=u?c:B(c),a=(await b.post(`${r}${d}`,p,{headers:i(u)})).data;if((a==null?void 0:a.err_code)==="AUTH")throw new R;if((a==null?void 0:a.json_ok)===!1)throw new Error((a==null?void 0:a.json_msg)||(a==null?void 0:a.message)||(a==null?void 0:a.err_msg)||"请求失败");return a},stream:async(d,c=D,u)=>{const p=typeof FormData<"u"&&c instanceof FormData,w=p?c:B(c);return(await b.post(`${r}${d}`,w,{headers:i(p),adapter:"fetch",responseType:"stream",signal:u})).data}}},v="MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC8Qa+e4QjNlfSR55RGHeltMDqYJR1UCCpWzqY0xV9rgcGKXB3PzvBwn5PUUzPehGHHDXrpU4/gmcDZCjJly9hoI9NPKtjhi3bRFV7aHX0B4ms0S2ImYKtdRR7uSQfJPQFwr6fVOCs2bcPcJMYmSuJZXRKO/Fr7ZD5Uhlkcg5KGzQIDAQAB",P=async e=>{const o=(await import("jsencrypt")).default,t=new o({});t.setPublicKey(v);const s=t.encrypt(e);if(s===!1)throw new Error("密码加密失败");return s},J=async(e,o)=>{const{user:t,pass:s,...r}=o,n={};Object.entries(r).forEach(([y,h])=>{h!==void 0&&(n[y]=h)}),n.user=t,n.pass=await P(s);const i=await e.post("/login",n);if(!i.wisession)throw new Error("登录失败:未返回 wisession");return i},m=async e=>{const o="name"in e&&typeof e.name=="string"?e.name:"",t=e.type||"";if(typeof FileReader<"u")return new Promise((s,r)=>{const n=new FileReader;n.onload=()=>{const i=String(n.result??"");s({name:o,"content-type":t,data:i.split(",")[1]??i})},n.onerror=()=>r(n.error),n.readAsDataURL(e)});if(typeof e.arrayBuffer=="function"){const s=await e.arrayBuffer(),r=typeof Buffer<"u"?Buffer.from(s).toString("base64"):btoa(String.fromCharCode(...new Uint8Array(s)));return{name:o,"content-type":t,data:r}}return{name:o,"content-type":t,data:""}},M=(e,o,t)=>{Object.prototype.hasOwnProperty.call(e,o)?e[o]=Array.isArray(e[o])?[...e[o],t]:[e[o],t]:e[o]=t},U=async e=>{const o={};if(typeof FormData<"u"&&e instanceof FormData)for(const[t,s]of e.entries()){const r=typeof Blob<"u"&&s instanceof Blob?await m(s):s;M(o,t,r)}else if(e&&typeof e=="object")for(const[t,s]of Object.entries(e))typeof Blob<"u"&&s instanceof Blob?o[t]=await m(s):Array.isArray(s)?o[t]=await Promise.all(s.map(async r=>typeof Blob<"u"&&r instanceof Blob?await m(r):r)):o[t]=s;return o.files&&!Array.isArray(o.files)&&(o.files=[o.files]),o.type="chat_stream",o},x=(e,o)=>{const t=e?e.endsWith("/")?e:`${e}/`:"/",s=typeof window<"u"&&window.location?window.location.origin:"http://localhost",r=new URL("chat/ws",new URL(t,s));return r.protocol==="http:"?r.protocol="ws:":r.protocol==="https:"?r.protocol="wss:":typeof window<"u"&&window.location?r.protocol=window.location.protocol==="https:"?"wss:":"ws:":r.protocol.startsWith("ws")||(r.protocol="ws:"),o&&r.searchParams.set("session_id",String(o)),r.toString()},L=async e=>typeof e=="string"?e:typeof Blob<"u"&&e instanceof Blob?e.text():e instanceof ArrayBuffer?new TextDecoder().decode(e):String(e??""),S=(e,o,t=8e3)=>{const s=Math.max(t,1),r=Math.ceil(o.length/s)||1;for(let n=0;n<r;n++){const i=o.slice(n*s,(n+1)*s),y=n===r-1?"E":n===0?"B":"M";e.send(`${y}${i}`)}},W=async e=>{const{baseURL:o,data:t,sessionId:s,signal:r,chunkSize:n=8e3,WebSocketClass:i=typeof WebSocket<"u"?WebSocket:void 0,onOpen:y}=e;if(!i)throw new Error("当前运行环境不支持 WebSocket");const h=await U(t),d=x(o,s),c=new TextEncoder;return new ReadableStream({start(u){let p=!1,w=!1;const a=new i(d),E=()=>{if(!p){p=!0;try{u.close()}catch{}try{a.close()}catch{}}},g=f=>{if(!p){p=!0;try{u.error(f)}catch{}try{a.close()}catch{}}};a.onopen=()=>{try{S(a,JSON.stringify(h),n),y==null||y((f,l)=>{p||a.readyState!==1||S(a,f,l??n)})}catch(f){g(f)}},a.onmessage=async f=>{try{w=!0;const l=await L(f.data);if(!l)return;const F=c.encode(`data: ${l}
|
|
2
|
+
|
|
3
|
+
`);u.enqueue(F);try{const _=JSON.parse(l);(_==null?void 0:_.mode)==="finish"&&E()}catch{}}catch(l){g(l)}},a.onclose=()=>{if(!w){g(new Error("WebSocket 连接已断开(未收到任何回答数据)"));return}E()},a.onerror=f=>{g(f)};const C=()=>{const f=r==null?void 0:r.reason,l=f instanceof Error?f:new DOMException(typeof f=="string"?f:"The user aborted a request.","AbortError");g(l)};r&&(r.aborted?C():r.addEventListener("abort",C,{once:!0}))}})},I=e=>{const o=(e.baseURL||"").replace(/\/$/,"");return{getFileUrl(t){return t?t.startsWith("http://")||t.startsWith("https://")||t.startsWith("/")?t:`${o}/algorithm/get_file_data?file_id=${t}`:""},async getHistoryGroups(){return e.post("/history/get_history_groups",{})},async createHistoryGroup(t){return e.post("/history/create_history_group",{group_title:t})},async deleteHistoryGroup(t){return e.post("/history/delete_history_group",{history_group_id:t})},async setHistoryGroupTitle(t,s){return e.post("/history/set_history_group_title",{history_group_id:t,title:s})},async getHistoryDetail(t,s=0,r=10){const n=await e.post("/history/query_history_detail",{history_group_id:t,last_end:s,last_count:r});return(n==null?void 0:n.details)||[]},async getHistoryAnswer(t){return e.post("/history/get_history_answer",{history_id:t})},async getDefaultLlmId(){return e.post("/admin/get_default_llm_id",{})},async getLlmEntryListByRole(t={entry_group:"智能助手"}){return e.post("/admin/get_llm_entry_list_by_role",t)},async questionStream(t,s){var a;const{question:r,historyGroupId:n,entryId:i,files:y,incPrevQuestion:h,onOpen:d,...c}=t,p={question:r,history_group_id:n,entry_id:i??"",inc_prev_question:h??"Y",...c};y&&y.length>0&&(p.files=y);const w=((a=e.getSession)==null?void 0:a.call(e))??(typeof localStorage<"u"?localStorage.getItem("access-session"):null);return W({baseURL:e.baseURL,data:p,sessionId:w,signal:s,onOpen:d})}}};exports.AuthExpiredError=R;exports.buildChatWsUrl=x;exports.createChatApi=I;exports.createRequest=k;exports.fileToBase64=m;exports.formDataToJson=U;exports.isCancelError=$;exports.login=J;exports.openChatWebSocketStream=W;exports.pwdEncrypt=P;exports.resolveMessageData=L;exports.sendPayloadInChunks=S;
|
|
4
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* wi-chat-request —— 对话 + 历史的业务请求层
|
|
3
|
+
*
|
|
4
|
+
* axios 封装:普通请求(post) + SSE 流(stream),统一处理 json_ok / AUTH;
|
|
5
|
+
* WebSocket 对话流(ws):分片帧传输与 ReadableStream 封装;
|
|
6
|
+
* 含登录(pwdEncrypt / login)、历史分组 CRUD、会话明细/回答、question_stream。
|
|
7
|
+
*
|
|
8
|
+
* 注意:全部用具名 re-export 而非 export *——TS < 5.0 的 nodenext 下 star 转发成员
|
|
9
|
+
* 不物化(消费端报 TS2305),且 vite/esbuild 隔离转译要求类型显式标注 export type。
|
|
10
|
+
*/
|
|
11
|
+
export { AuthExpiredError, isCancelError, createRequest } from './client';
|
|
12
|
+
export type { RequestOptions, RequestClient } from './client';
|
|
13
|
+
export { pwdEncrypt, login } from './login';
|
|
14
|
+
export type { LoginParams, LoginResult } from './login';
|
|
15
|
+
export { createChatApi } from './api';
|
|
16
|
+
export type { HistoryGroup, HistoryGroupsResult, HistoryDetailItem, AgentEntryItem, ChatApi } from './api';
|
|
17
|
+
export { fileToBase64, formDataToJson, buildChatWsUrl, resolveMessageData, sendPayloadInChunks, openChatWebSocketStream } from './ws';
|
|
18
|
+
export type { FileJsonValue, ChatWsStreamOptions, WsChunkSender } from './ws';
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import b from "axios";
|
|
2
|
+
class R extends Error {
|
|
3
|
+
constructor(o = "登录已过期,请重新认证") {
|
|
4
|
+
super(o), this.name = "AuthExpiredError";
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
const G = (e) => b.isCancel(e) || e instanceof Error && (e.name === "AbortError" || e.name === "CanceledError"), B = (e) => new URLSearchParams(
|
|
8
|
+
Object.entries(e).reduce((o, [t, s]) => (o[t] = String(s), o), {})
|
|
9
|
+
), A = {}, H = (e) => {
|
|
10
|
+
const { baseURL: o, getWisession: t, getSession: s } = e, r = o.replace(/\/$/, ""), n = s ?? t, i = (d = !1) => {
|
|
11
|
+
const c = {};
|
|
12
|
+
d || (c["Content-Type"] = "application/x-www-form-urlencoded");
|
|
13
|
+
const u = n == null ? void 0 : n();
|
|
14
|
+
return u && (c.wisession = u), c;
|
|
15
|
+
};
|
|
16
|
+
return {
|
|
17
|
+
baseURL: r,
|
|
18
|
+
getSession: n,
|
|
19
|
+
post: async (d, c = A) => {
|
|
20
|
+
const u = typeof FormData < "u" && c instanceof FormData, p = u ? c : B(c), a = (await b.post(`${r}${d}`, p, {
|
|
21
|
+
headers: i(u)
|
|
22
|
+
})).data;
|
|
23
|
+
if ((a == null ? void 0 : a.err_code) === "AUTH")
|
|
24
|
+
throw new R();
|
|
25
|
+
if ((a == null ? void 0 : a.json_ok) === !1)
|
|
26
|
+
throw new Error((a == null ? void 0 : a.json_msg) || (a == null ? void 0 : a.message) || (a == null ? void 0 : a.err_msg) || "请求失败");
|
|
27
|
+
return a;
|
|
28
|
+
},
|
|
29
|
+
stream: async (d, c = A, u) => {
|
|
30
|
+
const p = typeof FormData < "u" && c instanceof FormData, w = p ? c : B(c);
|
|
31
|
+
return (await b.post(`${r}${d}`, w, {
|
|
32
|
+
headers: i(p),
|
|
33
|
+
// 浏览器下 XHR 不支持流式读取(response.data 会变成整包 String),
|
|
34
|
+
// 必须强制 fetch 适配器才能拿到 ReadableStream
|
|
35
|
+
adapter: "fetch",
|
|
36
|
+
responseType: "stream",
|
|
37
|
+
signal: u
|
|
38
|
+
})).data;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}, P = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC8Qa+e4QjNlfSR55RGHeltMDqYJR1UCCpWzqY0xV9rgcGKXB3PzvBwn5PUUzPehGHHDXrpU4/gmcDZCjJly9hoI9NPKtjhi3bRFV7aHX0B4ms0S2ImYKtdRR7uSQfJPQFwr6fVOCs2bcPcJMYmSuJZXRKO/Fr7ZD5Uhlkcg5KGzQIDAQAB", U = async (e) => {
|
|
42
|
+
const o = (await import("jsencrypt")).default, t = new o({});
|
|
43
|
+
t.setPublicKey(P);
|
|
44
|
+
const s = t.encrypt(e);
|
|
45
|
+
if (s === !1)
|
|
46
|
+
throw new Error("密码加密失败");
|
|
47
|
+
return s;
|
|
48
|
+
}, O = async (e, o) => {
|
|
49
|
+
const { user: t, pass: s, ...r } = o, n = {};
|
|
50
|
+
Object.entries(r).forEach(([y, h]) => {
|
|
51
|
+
h !== void 0 && (n[y] = h);
|
|
52
|
+
}), n.user = t, n.pass = await U(s);
|
|
53
|
+
const i = await e.post("/login", n);
|
|
54
|
+
if (!i.wisession)
|
|
55
|
+
throw new Error("登录失败:未返回 wisession");
|
|
56
|
+
return i;
|
|
57
|
+
}, _ = async (e) => {
|
|
58
|
+
const o = "name" in e && typeof e.name == "string" ? e.name : "", t = e.type || "";
|
|
59
|
+
if (typeof FileReader < "u")
|
|
60
|
+
return new Promise((s, r) => {
|
|
61
|
+
const n = new FileReader();
|
|
62
|
+
n.onload = () => {
|
|
63
|
+
const i = String(n.result ?? "");
|
|
64
|
+
s({
|
|
65
|
+
name: o,
|
|
66
|
+
"content-type": t,
|
|
67
|
+
data: i.split(",")[1] ?? i
|
|
68
|
+
});
|
|
69
|
+
}, n.onerror = () => r(n.error), n.readAsDataURL(e);
|
|
70
|
+
});
|
|
71
|
+
if (typeof e.arrayBuffer == "function") {
|
|
72
|
+
const s = await e.arrayBuffer(), r = typeof Buffer < "u" ? Buffer.from(s).toString("base64") : btoa(String.fromCharCode(...new Uint8Array(s)));
|
|
73
|
+
return {
|
|
74
|
+
name: o,
|
|
75
|
+
"content-type": t,
|
|
76
|
+
data: r
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
name: o,
|
|
81
|
+
"content-type": t,
|
|
82
|
+
data: ""
|
|
83
|
+
};
|
|
84
|
+
}, x = (e, o, t) => {
|
|
85
|
+
Object.prototype.hasOwnProperty.call(e, o) ? e[o] = Array.isArray(e[o]) ? [...e[o], t] : [e[o], t] : e[o] = t;
|
|
86
|
+
}, L = async (e) => {
|
|
87
|
+
const o = {};
|
|
88
|
+
if (typeof FormData < "u" && e instanceof FormData)
|
|
89
|
+
for (const [t, s] of e.entries()) {
|
|
90
|
+
const r = typeof Blob < "u" && s instanceof Blob ? await _(s) : s;
|
|
91
|
+
x(o, t, r);
|
|
92
|
+
}
|
|
93
|
+
else if (e && typeof e == "object")
|
|
94
|
+
for (const [t, s] of Object.entries(e))
|
|
95
|
+
typeof Blob < "u" && s instanceof Blob ? o[t] = await _(s) : Array.isArray(s) ? o[t] = await Promise.all(
|
|
96
|
+
s.map(
|
|
97
|
+
async (r) => typeof Blob < "u" && r instanceof Blob ? await _(r) : r
|
|
98
|
+
)
|
|
99
|
+
) : o[t] = s;
|
|
100
|
+
return o.files && !Array.isArray(o.files) && (o.files = [o.files]), o.type = "chat_stream", o;
|
|
101
|
+
}, F = (e, o) => {
|
|
102
|
+
const t = e ? e.endsWith("/") ? e : `${e}/` : "/", s = typeof window < "u" && window.location ? window.location.origin : "http://localhost", r = new URL("chat/ws", new URL(t, s));
|
|
103
|
+
return r.protocol === "http:" ? r.protocol = "ws:" : r.protocol === "https:" ? r.protocol = "wss:" : typeof window < "u" && window.location ? r.protocol = window.location.protocol === "https:" ? "wss:" : "ws:" : r.protocol.startsWith("ws") || (r.protocol = "ws:"), o && r.searchParams.set("session_id", String(o)), r.toString();
|
|
104
|
+
}, W = async (e) => typeof e == "string" ? e : typeof Blob < "u" && e instanceof Blob ? e.text() : e instanceof ArrayBuffer ? new TextDecoder().decode(e) : String(e ?? ""), C = (e, o, t = 8e3) => {
|
|
105
|
+
const s = Math.max(t, 1), r = Math.ceil(o.length / s) || 1;
|
|
106
|
+
for (let n = 0; n < r; n++) {
|
|
107
|
+
const i = o.slice(n * s, (n + 1) * s), y = n === r - 1 ? "E" : n === 0 ? "B" : "M";
|
|
108
|
+
e.send(`${y}${i}`);
|
|
109
|
+
}
|
|
110
|
+
}, Q = async (e) => {
|
|
111
|
+
const {
|
|
112
|
+
baseURL: o,
|
|
113
|
+
data: t,
|
|
114
|
+
sessionId: s,
|
|
115
|
+
signal: r,
|
|
116
|
+
chunkSize: n = 8e3,
|
|
117
|
+
WebSocketClass: i = typeof WebSocket < "u" ? WebSocket : void 0,
|
|
118
|
+
onOpen: y
|
|
119
|
+
} = e;
|
|
120
|
+
if (!i)
|
|
121
|
+
throw new Error("当前运行环境不支持 WebSocket");
|
|
122
|
+
const h = await L(t), d = F(o, s), c = new TextEncoder();
|
|
123
|
+
return new ReadableStream({
|
|
124
|
+
start(u) {
|
|
125
|
+
let p = !1, w = !1;
|
|
126
|
+
const a = new i(d), S = () => {
|
|
127
|
+
if (!p) {
|
|
128
|
+
p = !0;
|
|
129
|
+
try {
|
|
130
|
+
u.close();
|
|
131
|
+
} catch {
|
|
132
|
+
}
|
|
133
|
+
try {
|
|
134
|
+
a.close();
|
|
135
|
+
} catch {
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}, m = (f) => {
|
|
139
|
+
if (!p) {
|
|
140
|
+
p = !0;
|
|
141
|
+
try {
|
|
142
|
+
u.error(f);
|
|
143
|
+
} catch {
|
|
144
|
+
}
|
|
145
|
+
try {
|
|
146
|
+
a.close();
|
|
147
|
+
} catch {
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
a.onopen = () => {
|
|
152
|
+
try {
|
|
153
|
+
C(a, JSON.stringify(h), n), y == null || y((f, l) => {
|
|
154
|
+
p || a.readyState !== 1 || C(a, f, l ?? n);
|
|
155
|
+
});
|
|
156
|
+
} catch (f) {
|
|
157
|
+
m(f);
|
|
158
|
+
}
|
|
159
|
+
}, a.onmessage = async (f) => {
|
|
160
|
+
try {
|
|
161
|
+
w = !0;
|
|
162
|
+
const l = await W(f.data);
|
|
163
|
+
if (!l)
|
|
164
|
+
return;
|
|
165
|
+
const D = c.encode(`data: ${l}
|
|
166
|
+
|
|
167
|
+
`);
|
|
168
|
+
u.enqueue(D);
|
|
169
|
+
try {
|
|
170
|
+
const g = JSON.parse(l);
|
|
171
|
+
(g == null ? void 0 : g.mode) === "finish" && S();
|
|
172
|
+
} catch {
|
|
173
|
+
}
|
|
174
|
+
} catch (l) {
|
|
175
|
+
m(l);
|
|
176
|
+
}
|
|
177
|
+
}, a.onclose = () => {
|
|
178
|
+
if (!w) {
|
|
179
|
+
m(new Error("WebSocket 连接已断开(未收到任何回答数据)"));
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
S();
|
|
183
|
+
}, a.onerror = (f) => {
|
|
184
|
+
m(f);
|
|
185
|
+
};
|
|
186
|
+
const E = () => {
|
|
187
|
+
const f = r == null ? void 0 : r.reason, l = f instanceof Error ? f : new DOMException(typeof f == "string" ? f : "The user aborted a request.", "AbortError");
|
|
188
|
+
m(l);
|
|
189
|
+
};
|
|
190
|
+
r && (r.aborted ? E() : r.addEventListener("abort", E, { once: !0 }));
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}, $ = (e) => {
|
|
194
|
+
const o = (e.baseURL || "").replace(/\/$/, "");
|
|
195
|
+
return {
|
|
196
|
+
getFileUrl(t) {
|
|
197
|
+
return t ? t.startsWith("http://") || t.startsWith("https://") || t.startsWith("/") ? t : `${o}/algorithm/get_file_data?file_id=${t}` : "";
|
|
198
|
+
},
|
|
199
|
+
async getHistoryGroups() {
|
|
200
|
+
return e.post("/history/get_history_groups", {});
|
|
201
|
+
},
|
|
202
|
+
async createHistoryGroup(t) {
|
|
203
|
+
return e.post("/history/create_history_group", { group_title: t });
|
|
204
|
+
},
|
|
205
|
+
async deleteHistoryGroup(t) {
|
|
206
|
+
return e.post("/history/delete_history_group", { history_group_id: t });
|
|
207
|
+
},
|
|
208
|
+
async setHistoryGroupTitle(t, s) {
|
|
209
|
+
return e.post("/history/set_history_group_title", { history_group_id: t, title: s });
|
|
210
|
+
},
|
|
211
|
+
async getHistoryDetail(t, s = 0, r = 10) {
|
|
212
|
+
const n = await e.post("/history/query_history_detail", {
|
|
213
|
+
history_group_id: t,
|
|
214
|
+
last_end: s,
|
|
215
|
+
last_count: r
|
|
216
|
+
});
|
|
217
|
+
return (n == null ? void 0 : n.details) || [];
|
|
218
|
+
},
|
|
219
|
+
async getHistoryAnswer(t) {
|
|
220
|
+
return e.post("/history/get_history_answer", { history_id: t });
|
|
221
|
+
},
|
|
222
|
+
async getDefaultLlmId() {
|
|
223
|
+
return e.post("/admin/get_default_llm_id", {});
|
|
224
|
+
},
|
|
225
|
+
async getLlmEntryListByRole(t = { entry_group: "智能助手" }) {
|
|
226
|
+
return e.post("/admin/get_llm_entry_list_by_role", t);
|
|
227
|
+
},
|
|
228
|
+
async questionStream(t, s) {
|
|
229
|
+
var a;
|
|
230
|
+
const { question: r, historyGroupId: n, entryId: i, files: y, incPrevQuestion: h, onOpen: d, ...c } = t, p = {
|
|
231
|
+
question: r,
|
|
232
|
+
history_group_id: n,
|
|
233
|
+
entry_id: i ?? "",
|
|
234
|
+
inc_prev_question: h ?? "Y",
|
|
235
|
+
...c
|
|
236
|
+
};
|
|
237
|
+
y && y.length > 0 && (p.files = y);
|
|
238
|
+
const w = ((a = e.getSession) == null ? void 0 : a.call(e)) ?? (typeof localStorage < "u" ? localStorage.getItem("access-session") : null);
|
|
239
|
+
return Q({
|
|
240
|
+
baseURL: e.baseURL,
|
|
241
|
+
data: p,
|
|
242
|
+
sessionId: w,
|
|
243
|
+
signal: s,
|
|
244
|
+
// 传输层选项:连接就绪后向外部交出分片发送器(不混入发给后端的载荷)
|
|
245
|
+
onOpen: d
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
};
|
|
250
|
+
export {
|
|
251
|
+
R as AuthExpiredError,
|
|
252
|
+
F as buildChatWsUrl,
|
|
253
|
+
$ as createChatApi,
|
|
254
|
+
H as createRequest,
|
|
255
|
+
_ as fileToBase64,
|
|
256
|
+
L as formDataToJson,
|
|
257
|
+
G as isCancelError,
|
|
258
|
+
O as login,
|
|
259
|
+
Q as openChatWebSocketStream,
|
|
260
|
+
U as pwdEncrypt,
|
|
261
|
+
W as resolveMessageData,
|
|
262
|
+
C as sendPayloadInChunks
|
|
263
|
+
};
|
|
264
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 登录能力:密码加密(jsencrypt)+ /login 接口
|
|
3
|
+
*
|
|
4
|
+
* jsencrypt 以 UMD 形式依赖 `window`,属于浏览器专用;
|
|
5
|
+
* 这里用动态 import 延迟加载,避免在 Node 环境(如单元测试)import 本模块时崩溃。
|
|
6
|
+
*/
|
|
7
|
+
/** 密码 RSA 加密(失败时抛错,绝不发送明文密码);异步加载 jsencrypt */
|
|
8
|
+
export declare const pwdEncrypt: (pwd: string) => Promise<string>;
|
|
9
|
+
export interface LoginParams {
|
|
10
|
+
/** 登录账号 */
|
|
11
|
+
user: string;
|
|
12
|
+
/** 登录密码(明文传入,login 内部 RSA 加密后发送) */
|
|
13
|
+
pass: string;
|
|
14
|
+
/** 登录端类型:标识从哪个端登录(可选) */
|
|
15
|
+
client?: string;
|
|
16
|
+
/** 对接项目系统标识(可选) */
|
|
17
|
+
system_name?: string;
|
|
18
|
+
/** 其余任意字段直接展开透传到 /login 请求体(如验证码、租户等,可选) */
|
|
19
|
+
[key: string]: unknown;
|
|
20
|
+
}
|
|
21
|
+
export interface LoginResult {
|
|
22
|
+
json_ok?: boolean;
|
|
23
|
+
wisession?: string;
|
|
24
|
+
phone?: string;
|
|
25
|
+
id?: string;
|
|
26
|
+
name?: string;
|
|
27
|
+
real_name?: string;
|
|
28
|
+
[key: string]: any;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* 登录接口。前提:request 需先配置 baseURL;本函数通过 request 的 post 调用 /login。
|
|
32
|
+
* user / pass 外的其余字段(client / system_name 及任意自定义参数)平铺展开透传。
|
|
33
|
+
* @returns 登录结果(含 wisession)
|
|
34
|
+
*/
|
|
35
|
+
export declare const login: (request: {
|
|
36
|
+
post: <T = any>(url: string, data?: Record<string, unknown>) => Promise<T>;
|
|
37
|
+
}, params: LoginParams) => Promise<LoginResult>;
|