@somecat/ai-assist-sdk 1.1.4 → 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.
@@ -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' | 'history' | 'info';
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 { l as e, a as t, c as o, i as r, m as n, f as g, n as i, e as u, h as f, g as p, o as C, j as x, q as c, t as d, d as l, b as v, r as S, v as h, k as M, w as m, s as A, x as E, u as Q } from "./chunks/index-DctVgLU4.mjs";
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 extractPlainText,
7
+ n as ensureTitleConversation,
8
+ i as extractPlainText,
8
9
  g as formatQuestions,
9
- i as getAppConfig,
10
- u as getConfig,
11
- f as getConversationList,
12
- p as getConversationMessages,
13
- C as getMessageInfo,
14
- x as getPersonalInfo,
15
- c as getSuggestedQuestions,
16
- d as http,
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
- v as processSSEData,
19
- S as renderMarkdown,
20
- h as request,
21
- M as setConfig,
19
+ S as processSSEData,
20
+ A as renderMarkdown,
21
+ M as request,
22
+ h as setConfig,
22
23
  m as statusText,
23
- A as stopMessage,
24
- E as textError,
25
- Q as useClipboard
24
+ E as stopMessage,
25
+ Q as textError,
26
+ T as updateConversation,
27
+ b as useClipboard
26
28
  };
@@ -5,9 +5,11 @@ interface AnswerProps {
5
5
  };
6
6
  defaultRecommend?: string[];
7
7
  onConversationCreated?: (id: string) => void;
8
+ onTitleGenerated?: (title: string) => void;
8
9
  }
9
10
  export interface AnswerRef {
10
11
  goHistoryMessage: (appConversationId: string) => void;
12
+ createNewConversation: () => void;
11
13
  }
12
14
  declare const Answer: import('react').ForwardRefExoticComponent<AnswerProps & import('react').RefAttributes<AnswerRef>>;
13
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
- onAnswer: () => void;
5
- onEditTitle: (text: string) => void;
4
+ onNewConversation: () => void;
6
5
  }
7
6
  declare const History: React.FC<HistoryProps>;
8
7
  export default History;
@@ -1,8 +1,11 @@
1
1
  import { MessageStatus } from '../../../../core/types';
2
2
  /**
3
3
  * 流式 Markdown 渲染器 — 逐字打字机效果
4
- * 通过 requestAnimationFrame 逐字递增显示内容,
5
- * 使用 dangerouslySetInnerHTML + renderMarkdown 避免 ReactMarkdown 的性能开销
4
+ *
5
+ * 采用「字符/秒」时间驱动模型 + 小数累加器,根据积压量平滑分配显示时间:
6
+ * - 基准速率 CPS_BASE:正常逐字节奏,即使单字符也缓慢呈现
7
+ * - 积压越多速率越快,但封顶 CPS_MAX,避免一个时刻涌来的多段内容瞬间铺满
8
+ * - 跨帧累积小数进度,保证低速率下也能均匀推进
6
9
  */
7
10
  declare const StreamingMarkdown: React.FC<{
8
11
  content: string;
@@ -14,17 +14,19 @@ interface UseChatActionsParams {
14
14
  scrollToBottom: () => void;
15
15
  STATUS: Record<string, MessageStatus>;
16
16
  cfg: AiAssistConfig;
17
+ onTitleGenerated?: (title: string) => void;
17
18
  }
18
19
  /**
19
20
  * 对话操作:发送消息 / 重新生成 / 停止 / 加载历史会话
20
21
  *
21
22
  * 内部管理两个 AbortController(first / again)用于中断 SSE 连接。
22
23
  */
23
- export declare function useChatActions({ messages, setMessages, userInput, setUserInput, isGenerating, setIsGenerating, lastUserMessage, setLastUserMessage, conversationIdRef, doStreamRequest, issTopRef, scrollToBottom, STATUS, cfg, }: UseChatActionsParams): {
24
+ export declare function useChatActions({ messages, setMessages, userInput, setUserInput, isGenerating, setIsGenerating, lastUserMessage, setLastUserMessage, conversationIdRef, doStreamRequest, issTopRef, scrollToBottom, STATUS, cfg, onTitleGenerated, }: UseChatActionsParams): {
24
25
  sendMessage: () => Promise<void>;
25
26
  regenerateResponse: () => Promise<void>;
26
27
  toggleStop: () => Promise<void>;
27
28
  goHistoryMessage: (appConversationId: string) => Promise<void>;
28
29
  initConversation: () => Promise<void>;
30
+ resetConversation: () => void;
29
31
  };
30
32
  export {};