soar-chatbot 0.0.0-stage → 0.1.1

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/README.md CHANGED
@@ -1,3 +1,54 @@
1
- # Temporary Holding Version
1
+ # nebula-chatbot
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 可复用的星云 AI 机器人对话组件,基于 React 18 + Ant Design 5。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ npm install nebula-chatbot antd react react-dom
9
+ ```
10
+
11
+ ## 使用
12
+
13
+ ```tsx
14
+ import { ChatBot } from 'nebula-chatbot';
15
+ import 'nebula-chatbot/dist/style.css';
16
+
17
+ export default function App() {
18
+ return (
19
+ <ChatBot
20
+ apiConfig={{
21
+ baseUrl: '/',
22
+ getToken: () => sessionStorage.getItem('saas-token'),
23
+ channelCode: 'your-channel-code',
24
+ proappEnvCode: 'your-proapp-code',
25
+ onUnauthorized: () => {
26
+ // 处理登录失效
27
+ },
28
+ }}
29
+ />
30
+ );
31
+ }
32
+ ```
33
+
34
+ ## Props
35
+
36
+ `apiConfig` 可选,不传时组件会尝试从 `sessionStorage`/`localStorage` 读取 `saas-token` 和 `proappEnvLayout`,以兼容原有接入方式。
37
+
38
+ | 字段 | 类型 | 说明 |
39
+ | --- | --- | --- |
40
+ | `baseUrl` | `string` | 接口根路径,默认 `/` |
41
+ | `token` | `string \| () => string \| null` | 登录 token,默认从 storage 读取 |
42
+ | `saasAgent` | `string` | 请求头 `saas-agent`,默认 `qj-pc` |
43
+ | `channelCode` | `string` | 渠道编码 |
44
+ | `proappEnvCode` | `string` | 应用环境编码 |
45
+ | `onUnauthorized` | `() => void` | 登录失效回调 |
46
+
47
+ ## 开发
48
+
49
+ ```bash
50
+ npm install
51
+ npm run build
52
+ ```
53
+
54
+ 构建产物在 `dist/`,包括 `index.js`、`index.cjs`、`index.d.ts` 和 `style.css`。
@@ -0,0 +1,7 @@
1
+ import './ChatBot.scss';
2
+ import type { ChatbotApiConfig } from './api';
3
+ export interface ChatBotProps {
4
+ apiConfig?: ChatbotApiConfig;
5
+ }
6
+ export declare const ChatBot: ({ apiConfig }: ChatBotProps) => import("react").JSX.Element;
7
+ export default ChatBot;
package/dist/api.d.ts ADDED
@@ -0,0 +1,143 @@
1
+ /**
2
+ * AI 对话接口封装。
3
+ * 参考 ai-agent 项目(src/api/request.js、agent.js、model.js、chat.js、session.js、chatmessage.js):
4
+ * - 请求头自动注入 saas-token 与 saas-agent=qj-pc
5
+ * - 智能体/模型/会话/消息为 form-urlencoded POST
6
+ * - 对话为 JSON + SSE 流式响应
7
+ * - 域名取自 config/dev.js(生产为 '/',走当前域名相对路径)
8
+ */
9
+ export interface ChatbotApiConfig {
10
+ baseUrl?: string;
11
+ token?: string | (() => string | null);
12
+ saasAgent?: string;
13
+ channelCode?: string;
14
+ proappEnvCode?: string;
15
+ onUnauthorized?: () => void;
16
+ }
17
+ export declare function configureApi(config: ChatbotApiConfig): void;
18
+ export interface AgentItem {
19
+ agentCode?: string;
20
+ agentName?: string;
21
+ modelCode?: string;
22
+ modelName?: string;
23
+ agentDescription?: string;
24
+ agentModelTypes?: string | string[] | unknown;
25
+ agentSubtitle?: string;
26
+ agentSubTitle?: string;
27
+ agentRoleName?: string;
28
+ agentTypeName?: string;
29
+ agentType?: string;
30
+ agentTags?: string;
31
+ agenttypeUrl?: string;
32
+ agenttypeUrl1?: string;
33
+ agenttypeUrl2?: string;
34
+ [key: string]: unknown;
35
+ }
36
+ export interface ModelItem {
37
+ modelCode?: string;
38
+ modelName?: string;
39
+ modelProvider?: string;
40
+ modelBradnCode?: string;
41
+ modelBradnName?: string;
42
+ modelIsActive?: number | boolean;
43
+ default?: boolean | number;
44
+ [key: string]: unknown;
45
+ }
46
+ export interface UserpromptItem {
47
+ userpromptName?: string;
48
+ userpromptContent?: string;
49
+ userpromptSystemPrompt?: string;
50
+ promptContent?: string;
51
+ content?: string;
52
+ title?: string;
53
+ name?: string;
54
+ userpromptPriority?: number | string;
55
+ [key: string]: unknown;
56
+ }
57
+ export declare function queryAgents(): Promise<AgentItem[]>;
58
+ export declare function queryModels(params?: Record<string, unknown>): Promise<ModelItem[]>;
59
+ export declare function queryUserpromptPage(agentCode: string): Promise<UserpromptItem[]>;
60
+ export interface FalgSettingItem {
61
+ flagSettingId?: string | number | null;
62
+ flagSettingType?: string;
63
+ flagSettingCode?: string;
64
+ flagSettingInfo?: string | Record<string, unknown> | null;
65
+ [key: string]: unknown;
66
+ }
67
+ export declare function queryFalgSettingPage(params?: Record<string, unknown>): Promise<FalgSettingItem[]>;
68
+ export declare function saveFalgSetting(params?: Record<string, unknown>): Promise<unknown>;
69
+ export declare function updateFalgSetting(params?: Record<string, unknown>): Promise<unknown>;
70
+ export interface SessionItem {
71
+ sessionCode?: string;
72
+ sessionId?: string | number | null;
73
+ sessionTitle?: string;
74
+ agentCode?: string;
75
+ agentName?: string;
76
+ createTime?: string | number;
77
+ createDate?: string;
78
+ updateTime?: string | number;
79
+ gmtCreate?: string | number;
80
+ gmtModified?: string | number;
81
+ [key: string]: unknown;
82
+ }
83
+ export type ChatmessageRecord = Record<string, unknown>;
84
+ export declare function querySessionPage(params?: {
85
+ agentCode?: string;
86
+ page?: number;
87
+ rows?: number;
88
+ sessionCode?: string;
89
+ orderStr?: string;
90
+ url?: string;
91
+ }): Promise<SessionItem[]>;
92
+ export declare function deleteSession(sessionId: string): Promise<unknown>;
93
+ export declare function queryChatmessagePage(params?: {
94
+ sessionCode?: string;
95
+ agentCode?: string;
96
+ page?: number;
97
+ rows?: number;
98
+ orderStr?: string;
99
+ url?: string;
100
+ }): Promise<ChatmessageRecord[]>;
101
+ export interface ChatStreamMessage {
102
+ text: string;
103
+ thinking?: string;
104
+ isToolCall?: boolean;
105
+ toolCall?: string;
106
+ toolCallContent?: unknown;
107
+ toolResult?: unknown;
108
+ fileDownload?: Record<string, unknown>;
109
+ errorMsg?: string;
110
+ sessionCode?: string | null;
111
+ }
112
+ export interface ChatStreamCallbacks {
113
+ onMessage?: (msg: ChatStreamMessage) => void;
114
+ onDone?: (data: {
115
+ sessionCode?: string | null;
116
+ }) => void;
117
+ onError?: (error: Error) => void;
118
+ onFinished?: (data: {
119
+ sessionCode?: string | null;
120
+ success: boolean;
121
+ }) => void;
122
+ }
123
+ export declare function sendChatMessage(params: {
124
+ message: string;
125
+ agentCode?: string;
126
+ sessionCode?: string | null;
127
+ attachments?: unknown[];
128
+ modelCode?: string;
129
+ agentTypeUrl?: string;
130
+ }, callbacks: ChatStreamCallbacks): AbortController;
131
+ export interface UploadedFile {
132
+ ossUrl?: string;
133
+ fileName?: string;
134
+ mimeType?: string;
135
+ [key: string]: unknown;
136
+ }
137
+ export declare function uploadFiles(files: File[]): Promise<UploadedFile[]>;
138
+ export declare function transcribeAudio(params: {
139
+ agentCode?: string;
140
+ base64Data?: string;
141
+ audioUrl?: string;
142
+ mimeType?: string;
143
+ }): Promise<string>;