@somecat/ai-assist-sdk 1.1.2 → 1.1.8
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/ai-assist-sdk.css +1 -1
- package/dist/chunks/index-CgnkZbtP.mjs +149 -0
- package/dist/chunks/{index-DctVgLU4.mjs → index-DwhpwWON.mjs} +2236 -2179
- package/dist/core/services/api.d.ts +6 -0
- package/dist/core/types/index.d.ts +4 -1
- package/dist/core/utils/index.d.ts +7 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +19 -17
- package/dist/react/components/Answer.d.ts +3 -2
- package/dist/react/components/History.d.ts +1 -2
- package/dist/react/components/answer/components/AgentThoughtBlock.d.ts +5 -0
- package/dist/react/components/answer/components/ChatInput.d.ts +13 -0
- package/dist/react/components/answer/components/MessageItem.d.ts +9 -0
- package/dist/react/components/answer/components/StreamingMarkdown.d.ts +15 -0
- package/dist/react/components/answer/components/ThinkingBlock.d.ts +6 -0
- package/dist/react/components/answer/hooks/useChatActions.d.ts +32 -0
- package/dist/react/components/answer/hooks/useMessagesBatch.d.ts +11 -0
- package/dist/react/components/answer/hooks/useSSEStream.d.ts +26 -0
- package/dist/react/components/answer/hooks/useScrollManager.d.ts +12 -0
- package/dist/react/components/answer/status.d.ts +10 -0
- package/dist/react/index.mjs +9594 -9329
- package/dist/vue/components/answer/composables/useChatActions.d.ts +3 -1
- package/dist/vue/components/answer/composables/useTypewriter.d.ts +2 -0
- package/dist/vue/index.mjs +804 -695
- package/package.json +3 -1
- package/dist/chunks/index-Co5SARS3.mjs +0 -152
|
@@ -2,10 +2,16 @@ import { AiAssistConfig, PersonalInfo, ConversationItem, ConversationMessageItem
|
|
|
2
2
|
export declare const createConversation: (apis: AiAssistConfig["apis"]) => Promise<{
|
|
3
3
|
conversation: ConversationItem;
|
|
4
4
|
} | undefined>;
|
|
5
|
+
/**
|
|
6
|
+
* 获取(或首次创建)标题生成专用对话ID。
|
|
7
|
+
* 根据 titleGenerateApp 创建一个专用会话,全局缓存,后续复用。
|
|
8
|
+
*/
|
|
9
|
+
export declare const ensureTitleConversation: (apis: AiAssistConfig["apis"], titleGenerateApp: string) => Promise<string | null>;
|
|
5
10
|
export declare const getConversationList: (apis: AiAssistConfig["apis"]) => Promise<{
|
|
6
11
|
conversationList: ConversationItem[];
|
|
7
12
|
} | null>;
|
|
8
13
|
export declare const deleteConversation: (apis: AiAssistConfig["apis"], appConversationId: string) => Promise<void>;
|
|
14
|
+
export declare const updateConversation: (apis: AiAssistConfig["apis"], appConversationId: string, conversationName: string) => Promise<void>;
|
|
9
15
|
export declare const getConversationMessages: (apis: AiAssistConfig["apis"], appConversationId: string) => Promise<{
|
|
10
16
|
messages: ConversationMessageItem[];
|
|
11
17
|
} | null>;
|
|
@@ -4,6 +4,8 @@ export interface AiAssistConfig {
|
|
|
4
4
|
token: string;
|
|
5
5
|
appKey?: string;
|
|
6
6
|
app?: number;
|
|
7
|
+
/** 生成对话标题的 AI 智能体 app 标识,默认 'dialog_title_generate' */
|
|
8
|
+
titleGenerateApp?: string;
|
|
7
9
|
defaultSayhello?: {
|
|
8
10
|
text1: string;
|
|
9
11
|
text2: string;
|
|
@@ -19,13 +21,14 @@ export interface AiAssistConfig {
|
|
|
19
21
|
getConversationListApi?: string;
|
|
20
22
|
getConversationMessagesApi?: string;
|
|
21
23
|
deleteConversationApi?: string;
|
|
24
|
+
updateConversationApi?: string;
|
|
22
25
|
getSuggestedQuestionsApi?: string;
|
|
23
26
|
getMessageInfoApi?: string;
|
|
24
27
|
getAppConfigApi?: string;
|
|
25
28
|
getPersonalInfoApi?: string;
|
|
26
29
|
};
|
|
27
30
|
}
|
|
28
|
-
export type ViewStatus = 'answer' | '
|
|
31
|
+
export type ViewStatus = 'answer' | 'info';
|
|
29
32
|
export type MessageStatus = 'thinking' | 'rethinking' | 'answering' | 'paused' | 'completed' | 'stop' | 'error';
|
|
30
33
|
export interface MessageSegment {
|
|
31
34
|
type: 'thinking' | 'agent_thought' | 'answer';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MessageStatus } from '../types';
|
|
1
|
+
import { MessageStatus, HistoryItem } from '../types';
|
|
2
2
|
export declare const useClipboard: () => {
|
|
3
3
|
copy: (text: string) => Promise<void>;
|
|
4
4
|
isCopied: boolean;
|
|
@@ -12,3 +12,9 @@ export declare const processSSEData: (sseData: string) => string;
|
|
|
12
12
|
export declare const parseSSEData: (sseData: string) => string;
|
|
13
13
|
export { renderMarkdown, preprocessStreamingMarkdown } from './markdown';
|
|
14
14
|
export { showToast, type ToastType } from './toast';
|
|
15
|
+
export interface HistoryGroup {
|
|
16
|
+
label: string;
|
|
17
|
+
items: HistoryItem[];
|
|
18
|
+
}
|
|
19
|
+
/** 按今天 / 7天内 / 30天内 / 年-月 分组,空组不返回 */
|
|
20
|
+
export declare const groupHistoryByTime: (items: HistoryItem[]) => HistoryGroup[];
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export type { AiAssistConfig, ViewStatus, MessageStatus, ChatMessage, ConversationItem, ConversationMessageItem, HistoryItem, PersonalInfo, } from './core/types';
|
|
2
2
|
export { setConfig, getConfig, request, http, createAuthAxios, } from './core/services/request';
|
|
3
|
-
export { createConversation, getConversationList, deleteConversation, getConversationMessages, chatQuery, stopMessage, getSuggestedQuestions, getMessageInfo, getAppConfig, getPersonalInfo, } from './core/services/api';
|
|
3
|
+
export { createConversation, ensureTitleConversation, getConversationList, deleteConversation, updateConversation, getConversationMessages, chatQuery, stopMessage, getSuggestedQuestions, getMessageInfo, getAppConfig, getPersonalInfo, } from './core/services/api';
|
|
4
4
|
export { useClipboard, extractPlainText, statusText, formatQuestions, textError, processSSEData, parseSSEData, renderMarkdown, } from './core/utils';
|
package/dist/index.mjs
CHANGED
|
@@ -1,26 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { m as e, a as t, c as o, j as r, e as n, n as i, f as g, o as u, d as C, i as p, g as f, q as d, k as v, t as x, v as c, w as l, x as S, r as A, y as M, l as h, z as m, s as E, A as Q, b as T, u as b } from "./chunks/index-DwhpwWON.mjs";
|
|
2
2
|
export {
|
|
3
3
|
e as chatQuery,
|
|
4
4
|
t as createAuthAxios,
|
|
5
5
|
o as createConversation,
|
|
6
6
|
r as deleteConversation,
|
|
7
|
-
n as
|
|
7
|
+
n as ensureTitleConversation,
|
|
8
|
+
i as extractPlainText,
|
|
8
9
|
g as formatQuestions,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
u as getAppConfig,
|
|
11
|
+
C as getConfig,
|
|
12
|
+
p as getConversationList,
|
|
13
|
+
f as getConversationMessages,
|
|
14
|
+
d as getMessageInfo,
|
|
15
|
+
v as getPersonalInfo,
|
|
16
|
+
x as getSuggestedQuestions,
|
|
17
|
+
c as http,
|
|
17
18
|
l as parseSSEData,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
S as processSSEData,
|
|
20
|
+
A as renderMarkdown,
|
|
21
|
+
M as request,
|
|
22
|
+
h as setConfig,
|
|
22
23
|
m as statusText,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
E as stopMessage,
|
|
25
|
+
Q as textError,
|
|
26
|
+
T as updateConversation,
|
|
27
|
+
b as useClipboard
|
|
26
28
|
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { default as React } from 'react';
|
|
2
1
|
interface AnswerProps {
|
|
3
2
|
defaultSayhello?: {
|
|
4
3
|
text1: string;
|
|
@@ -6,9 +5,11 @@ interface AnswerProps {
|
|
|
6
5
|
};
|
|
7
6
|
defaultRecommend?: string[];
|
|
8
7
|
onConversationCreated?: (id: string) => void;
|
|
8
|
+
onTitleGenerated?: (title: string) => void;
|
|
9
9
|
}
|
|
10
10
|
export interface AnswerRef {
|
|
11
11
|
goHistoryMessage: (appConversationId: string) => void;
|
|
12
|
+
createNewConversation: () => void;
|
|
12
13
|
}
|
|
13
|
-
declare const Answer:
|
|
14
|
+
declare const Answer: import('react').ForwardRefExoticComponent<AnswerProps & import('react').RefAttributes<AnswerRef>>;
|
|
14
15
|
export default Answer;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
2
|
interface HistoryProps {
|
|
3
3
|
onHistoryDetail: (appConversationId: string) => void;
|
|
4
|
-
|
|
5
|
-
onEditTitle: (text: string) => void;
|
|
4
|
+
onNewConversation: () => void;
|
|
6
5
|
}
|
|
7
6
|
declare const History: React.FC<HistoryProps>;
|
|
8
7
|
export default History;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
interface ChatInputProps {
|
|
2
|
+
value: string;
|
|
3
|
+
onChange: (value: string) => void;
|
|
4
|
+
onSend: () => void;
|
|
5
|
+
onStop: () => void;
|
|
6
|
+
isGenerating: boolean;
|
|
7
|
+
lastUserMessage: string;
|
|
8
|
+
hasScroll: boolean;
|
|
9
|
+
isAtBottom: boolean;
|
|
10
|
+
onScrollToBottom: () => void;
|
|
11
|
+
}
|
|
12
|
+
declare const ChatInput: React.FC<ChatInputProps>;
|
|
13
|
+
export default ChatInput;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ChatMessage } from '../../../../core/types';
|
|
2
|
+
interface MessageItemProps {
|
|
3
|
+
msg: ChatMessage;
|
|
4
|
+
index: number;
|
|
5
|
+
scrollToBottom: () => void;
|
|
6
|
+
onRegenerate: () => void;
|
|
7
|
+
}
|
|
8
|
+
declare const MessageItem: React.FC<MessageItemProps>;
|
|
9
|
+
export default MessageItem;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { MessageStatus } from '../../../../core/types';
|
|
2
|
+
/**
|
|
3
|
+
* 流式 Markdown 渲染器 — 逐字打字机效果
|
|
4
|
+
*
|
|
5
|
+
* 采用「字符/秒」时间驱动模型 + 小数累加器,根据积压量平滑分配显示时间:
|
|
6
|
+
* - 基准速率 CPS_BASE:正常逐字节奏,即使单字符也缓慢呈现
|
|
7
|
+
* - 积压越多速率越快,但封顶 CPS_MAX,避免一个时刻涌来的多段内容瞬间铺满
|
|
8
|
+
* - 跨帧累积小数进度,保证低速率下也能均匀推进
|
|
9
|
+
*/
|
|
10
|
+
declare const StreamingMarkdown: React.FC<{
|
|
11
|
+
content: string;
|
|
12
|
+
status: MessageStatus;
|
|
13
|
+
onContentGrow?: () => void;
|
|
14
|
+
}>;
|
|
15
|
+
export default StreamingMarkdown;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ChatMessage, MessageStatus, AiAssistConfig } from '../../../../core/types';
|
|
2
|
+
interface UseChatActionsParams {
|
|
3
|
+
messages: ChatMessage[];
|
|
4
|
+
setMessages: React.Dispatch<React.SetStateAction<ChatMessage[]>>;
|
|
5
|
+
userInput: string;
|
|
6
|
+
setUserInput: React.Dispatch<React.SetStateAction<string>>;
|
|
7
|
+
isGenerating: boolean;
|
|
8
|
+
setIsGenerating: React.Dispatch<React.SetStateAction<boolean>>;
|
|
9
|
+
lastUserMessage: string;
|
|
10
|
+
setLastUserMessage: React.Dispatch<React.SetStateAction<string>>;
|
|
11
|
+
conversationIdRef: React.MutableRefObject<string>;
|
|
12
|
+
doStreamRequest: (apiUrl: string, bodyData: Record<string, any>, aiIndex: number, signal: AbortSignal, isRetry?: boolean) => Promise<void>;
|
|
13
|
+
issTopRef: React.MutableRefObject<boolean>;
|
|
14
|
+
scrollToBottom: () => void;
|
|
15
|
+
STATUS: Record<string, MessageStatus>;
|
|
16
|
+
cfg: AiAssistConfig;
|
|
17
|
+
onTitleGenerated?: (title: string) => void;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 对话操作:发送消息 / 重新生成 / 停止 / 加载历史会话
|
|
21
|
+
*
|
|
22
|
+
* 内部管理两个 AbortController(first / again)用于中断 SSE 连接。
|
|
23
|
+
*/
|
|
24
|
+
export declare function useChatActions({ messages, setMessages, userInput, setUserInput, isGenerating, setIsGenerating, lastUserMessage, setLastUserMessage, conversationIdRef, doStreamRequest, issTopRef, scrollToBottom, STATUS, cfg, onTitleGenerated, }: UseChatActionsParams): {
|
|
25
|
+
sendMessage: () => Promise<void>;
|
|
26
|
+
regenerateResponse: () => Promise<void>;
|
|
27
|
+
toggleStop: () => Promise<void>;
|
|
28
|
+
goHistoryMessage: (appConversationId: string) => Promise<void>;
|
|
29
|
+
initConversation: () => Promise<void>;
|
|
30
|
+
resetConversation: () => void;
|
|
31
|
+
};
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ChatMessage } from '../../../../core/types';
|
|
2
|
+
/**
|
|
3
|
+
* RAF 批量更新:将同一帧内的多次 setMessages 合并为一次渲染,避免频繁触发 React 重渲染。
|
|
4
|
+
*
|
|
5
|
+
* - batchSetMessages: 传入更新函数,延迟到下一帧统一写入
|
|
6
|
+
* - flushBatch: 立即刷出所有待处理更新(用于终止/错误等需要即时反馈的场景)
|
|
7
|
+
*/
|
|
8
|
+
export declare function useMessagesBatch(setMessages: React.Dispatch<React.SetStateAction<ChatMessage[]>>): {
|
|
9
|
+
batchSetMessages: (updater: (prev: ChatMessage[]) => ChatMessage[]) => void;
|
|
10
|
+
flushBatch: () => void;
|
|
11
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ChatMessage, MessageStatus, AiAssistConfig } from '../../../../core/types';
|
|
2
|
+
interface UseSSEStreamParams {
|
|
3
|
+
setMessages: React.Dispatch<React.SetStateAction<ChatMessage[]>>;
|
|
4
|
+
setIsGenerating: React.Dispatch<React.SetStateAction<boolean>>;
|
|
5
|
+
setLastUserMessage: React.Dispatch<React.SetStateAction<string>>;
|
|
6
|
+
batchSetMessages: (updater: (prev: ChatMessage[]) => ChatMessage[]) => void;
|
|
7
|
+
flushBatch: () => void;
|
|
8
|
+
STATUS: Record<string, MessageStatus>;
|
|
9
|
+
cfg: AiAssistConfig;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* SSE 流式请求:处理 think_message / agent_thought / message 等事件的分段拼接与状态流转。
|
|
13
|
+
*
|
|
14
|
+
* 内部管理:
|
|
15
|
+
* - segmentsRef: 每条 AI 消息的分段数组(支持 thinking/agent_thought/answer 穿插)
|
|
16
|
+
* - currentSegTypeRef: 当前正在写入的 segment 类型
|
|
17
|
+
* - thinkingStartTimeRef / agentThoughtStartTimeRef: 用于计算耗时
|
|
18
|
+
* - issTopRef: 是否已手动停止
|
|
19
|
+
*
|
|
20
|
+
* 对外暴露 doStreamRequest 与 issTopRef(toggleStop 需读写)。
|
|
21
|
+
*/
|
|
22
|
+
export declare function useSSEStream({ setMessages, setIsGenerating, setLastUserMessage, batchSetMessages, flushBatch, STATUS, cfg, }: UseSSEStreamParams): {
|
|
23
|
+
doStreamRequest: (apiUrl: string, bodyData: Record<string, any>, aiIndex: number, signal: AbortSignal, isRetry?: boolean) => Promise<void>;
|
|
24
|
+
issTopRef: import('react').RefObject<boolean>;
|
|
25
|
+
};
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* 聊天容器滚动状态管理
|
|
4
|
+
* - isAtBottom: 用户是否滚动到底部
|
|
5
|
+
* - hasScroll: 容器是否出现滚动条
|
|
6
|
+
*/
|
|
7
|
+
export declare function useScrollManager(chatBoxRef: RefObject<HTMLDivElement | null>): {
|
|
8
|
+
isAtBottom: boolean;
|
|
9
|
+
hasScroll: boolean;
|
|
10
|
+
scrollToBottom: () => void;
|
|
11
|
+
checkScrollStatus: () => void;
|
|
12
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { MessageStatus } from '../../../core/types';
|
|
2
|
+
export declare const STATUS: {
|
|
3
|
+
THINKING: MessageStatus;
|
|
4
|
+
RETHINKING: MessageStatus;
|
|
5
|
+
ANSWERING: MessageStatus;
|
|
6
|
+
PAUSED: MessageStatus;
|
|
7
|
+
COMPLETED: MessageStatus;
|
|
8
|
+
STOP: MessageStatus;
|
|
9
|
+
ERROR: MessageStatus;
|
|
10
|
+
};
|