@somecat/ai-assist-sdk 1.0.0 → 1.1.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.
@@ -0,0 +1,65 @@
1
+ import { Ref } from '../../../../../vue/dist/vue.esm-bundler.js';
2
+ import { ChatMessage, MessageStatus, AiAssistConfig } from '../../../../core/types';
3
+ interface UseChatActionsParams {
4
+ messages: Ref<ChatMessage[]>;
5
+ userInput: Ref<string>;
6
+ isGenerating: Ref<boolean>;
7
+ lastUserMessage: Ref<string>;
8
+ conversationId: Ref<string>;
9
+ doStreamRequest: (apiUrl: string, bodyData: Record<string, any>, aiIndex: number, signal: AbortSignal, isRetry?: boolean) => Promise<void>;
10
+ issTop: Ref<boolean>;
11
+ scrollToBottom: () => void;
12
+ STATUS: Record<string, MessageStatus>;
13
+ cfg: AiAssistConfig;
14
+ }
15
+ /**
16
+ * 对话操作:发送消息 / 重新生成 / 停止 / 加载历史会话
17
+ *
18
+ * 内部管理两个 AbortController(first / again)用于中断 SSE 连接。
19
+ */
20
+ export declare function useChatActions({ messages, userInput, isGenerating, lastUserMessage, conversationId, doStreamRequest, issTop, scrollToBottom, STATUS, cfg, }: UseChatActionsParams): {
21
+ sendMessage: () => Promise<void>;
22
+ regenerateResponse: () => Promise<void>;
23
+ toggleStop: () => Promise<void>;
24
+ goHistoryMessage: (appConversationId: string) => Promise<void>;
25
+ initConversation: () => Promise<void>;
26
+ controllers: {
27
+ first: {
28
+ readonly signal: {
29
+ readonly aborted: boolean;
30
+ onabort: ((this: AbortSignal, ev: Event) => any) | null;
31
+ readonly reason: any;
32
+ throwIfAborted: () => void;
33
+ addEventListener: {
34
+ <K extends keyof AbortSignalEventMap>(type: K, listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
35
+ (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
36
+ };
37
+ removeEventListener: {
38
+ <K extends keyof AbortSignalEventMap>(type: K, listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
39
+ (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
40
+ };
41
+ dispatchEvent: (event: Event) => boolean;
42
+ };
43
+ abort: (reason?: any) => void;
44
+ };
45
+ again: {
46
+ readonly signal: {
47
+ readonly aborted: boolean;
48
+ onabort: ((this: AbortSignal, ev: Event) => any) | null;
49
+ readonly reason: any;
50
+ throwIfAborted: () => void;
51
+ addEventListener: {
52
+ <K extends keyof AbortSignalEventMap>(type: K, listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
53
+ (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
54
+ };
55
+ removeEventListener: {
56
+ <K extends keyof AbortSignalEventMap>(type: K, listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
57
+ (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
58
+ };
59
+ dispatchEvent: (event: Event) => boolean;
60
+ };
61
+ abort: (reason?: any) => void;
62
+ };
63
+ };
64
+ };
65
+ export {};
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 代码块增强:为 markdown 渲染出的 <pre> 添加语言标签和复制按钮
3
+ */
4
+ export declare function useCodeBlocks(): {
5
+ enhanceCodeBlocks: (container: HTMLElement) => void;
6
+ };
@@ -0,0 +1,12 @@
1
+ import { Ref } from '../../../../../vue/dist/vue.esm-bundler.js';
2
+ import { ChatMessage } from '../../../../core/types';
3
+ /**
4
+ * RAF 批量更新:将同一帧内的多次 messages 赋值合并为一次,避免频繁触发响应式更新。
5
+ *
6
+ * - batchMessagesUpdate: 传入更新函数,延迟到下一帧统一写入
7
+ * - flushMessagesBatch: 立即刷出所有待处理更新(用于终止/错误等需要即时反馈的场景)
8
+ */
9
+ export declare function useMessagesBatch(messages: Ref<ChatMessage[]>): {
10
+ batchMessagesUpdate: (updater: (msgs: ChatMessage[]) => ChatMessage[]) => void;
11
+ flushMessagesBatch: () => void;
12
+ };
@@ -0,0 +1,27 @@
1
+ import { Ref } from '../../../../../vue/dist/vue.esm-bundler.js';
2
+ import { ChatMessage, MessageStatus, AiAssistConfig } from '../../../../core/types';
3
+ interface UseSSEStreamParams {
4
+ messages: Ref<ChatMessage[]>;
5
+ isGenerating: Ref<boolean>;
6
+ lastUserMessage: Ref<string>;
7
+ batchMessagesUpdate: (updater: (msgs: ChatMessage[]) => ChatMessage[]) => void;
8
+ flushMessagesBatch: () => void;
9
+ STATUS: Record<string, MessageStatus>;
10
+ cfg: AiAssistConfig;
11
+ }
12
+ /**
13
+ * SSE 流式请求:处理 think_message / agent_thought / message 等事件的分段拼接与状态流转。
14
+ *
15
+ * 内部管理:
16
+ * - segmentsMap: 每条 AI 消息的分段数组(支持 thinking/agent_thought/answer 穿插)
17
+ * - currentSegType: 当前正在写入的 segment 类型
18
+ * - thinkingStartTimes / agentThoughtStartTimes: 用于计算耗时
19
+ * - issTop: 是否已手动停止
20
+ *
21
+ * 对外暴露 doStreamRequest 与 issTop(toggleStop 需读写)。
22
+ */
23
+ export declare function useSSEStream({ messages, isGenerating, lastUserMessage, batchMessagesUpdate, flushMessagesBatch, STATUS, cfg, }: UseSSEStreamParams): {
24
+ doStreamRequest: (apiUrl: string, bodyData: Record<string, any>, aiIndex: number, signal: AbortSignal, isRetry?: boolean) => Promise<void>;
25
+ issTop: Ref<boolean, boolean>;
26
+ };
27
+ export {};
@@ -0,0 +1,12 @@
1
+ import { Ref } from '../../../../../vue/dist/vue.esm-bundler.js';
2
+ /**
3
+ * 聊天容器滚动状态管理
4
+ * - isAtBottom: 用户是否滚动到底部
5
+ * - hasScroll: 容器是否出现滚动条
6
+ */
7
+ export declare function useScrollManager(chatBoxRef: Ref<HTMLElement | null>): {
8
+ isAtBottom: Ref<boolean, boolean>;
9
+ hasScroll: Ref<boolean, boolean>;
10
+ scrollToBottom: () => void;
11
+ checkScrollStatus: () => void;
12
+ };
@@ -0,0 +1,21 @@
1
+ import { Ref } from '../../../../../vue/dist/vue.esm-bundler.js';
2
+ import { ChatMessage, MessageSegment, MessageStatus } from '../../../../core/types';
3
+ /**
4
+ * 打字机效果:对正在流式输出(ANSWERING)的 AI 消息做逐字/渐进显示动画。
5
+ *
6
+ * - displayedContent: 每条 AI 消息当前已渲染的内容(可能是 content 的子串)
7
+ * - streamingIndexRef: 每条消息已显示到的字符位置
8
+ * - getSegmentDisplayContent: 对 segments 模式下最后一个 answer segment 应用打字机截断
9
+ *
10
+ * @param messages 消息列表 ref
11
+ * @param scrollToBottom 滚动到底部回调(打字机推进时调用)
12
+ * @param ANSWERING 流式回答中的状态值
13
+ */
14
+ export declare function useTypewriter(messages: Ref<ChatMessage[]>, scrollToBottom: () => void, ANSWERING: MessageStatus): {
15
+ displayedContent: import('../../../../../vue/dist/vue.esm-bundler.js').Reactive<Map<number, string>>;
16
+ streamingIndexRef: Ref<Map<number, number> & Omit<Map<number, number>, keyof Map<any, any>>, Map<number, number> | (Map<number, number> & Omit<Map<number, number>, keyof Map<any, any>>)>;
17
+ startTypewriter: () => void;
18
+ flushTypewriter: () => void;
19
+ getSegmentDisplayContent: (msgIdx: number, segIdx: number, seg: MessageSegment, msg: ChatMessage) => string;
20
+ stopTypewriter: () => void;
21
+ };