ai-client-sdk 3.0.9 → 4.0.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/ai-client-sdk.mjs +53281 -15793
- package/dist/ai-client-sdk.umd.js +402 -86
- package/dist/index.d.ts +19 -10
- package/dist/utils/agent.d.ts +5 -0
- package/dist/view/App.d.ts +28 -0
- package/dist/view/{template.d.ts → components/MessageItem.d.ts} +6 -3
- package/dist/view/event.d.ts +1 -2
- package/dist/view/index.d.ts +10 -2
- package/package.json +8 -2
- package/dist/view/dom.d.ts +0 -57
package/dist/index.d.ts
CHANGED
|
@@ -14,22 +14,31 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
import { tools } from './utils/tools';
|
|
18
|
+
import { Agent, type Message, type StreamResult, type AssistantMessage } from './utils/agent';
|
|
19
|
+
export interface PanelElement extends HTMLElement {
|
|
20
|
+
ready(): Promise<void>;
|
|
21
|
+
pushMessage(message: Message): Promise<void>;
|
|
22
|
+
pushMessages(messages: Message[]): Promise<void>;
|
|
23
|
+
pushLoadingMessage(): Promise<void>;
|
|
24
|
+
updateLoadingMessageReasoningContent(content: string): Promise<void>;
|
|
25
|
+
updateLoadingMessageContent(content: string): Promise<void>;
|
|
26
|
+
}
|
|
19
27
|
interface Config {
|
|
20
28
|
container: HTMLElement | null;
|
|
21
29
|
}
|
|
22
30
|
export declare class AIChatPanel {
|
|
23
31
|
on: <T extends "send" | "create">(type: T, listener: (...args: {
|
|
24
|
-
send: [message:
|
|
32
|
+
send: [message: Message];
|
|
25
33
|
create: [];
|
|
26
34
|
}[T]) => void | Promise<void>) => void;
|
|
27
|
-
|
|
28
|
-
pushMessages: (messages: import(".").Message[]) => void;
|
|
29
|
-
pushLoadingMessage: () => void;
|
|
30
|
-
updateLoadingMessageReasoningContent: (content: string) => void;
|
|
31
|
-
updateLoadingMessageContent: (content: string) => void;
|
|
32
|
-
finishLoadingMessage: () => void;
|
|
33
|
-
setUserInputValue: (value: string) => void;
|
|
35
|
+
private readonly panelElement;
|
|
34
36
|
constructor(config: Config);
|
|
37
|
+
ready(): Promise<void>;
|
|
38
|
+
pushMessage(message: Message): Promise<void>;
|
|
39
|
+
pushMessages(messages: Message[]): Promise<void>;
|
|
40
|
+
pushLoadingMessage(): Promise<void>;
|
|
41
|
+
updateLoadingMessageReasoningContent(content: string): Promise<void>;
|
|
42
|
+
updateLoadingMessageContent(content: string): Promise<void>;
|
|
35
43
|
}
|
|
44
|
+
export { tools, Agent, type Message, type StreamResult, type AssistantMessage };
|
package/dist/utils/agent.d.ts
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
import Ajv from 'ajv';
|
|
18
|
+
import { type PanelElement } from '../index';
|
|
18
19
|
declare function abort(): void;
|
|
19
20
|
interface StringParameter {
|
|
20
21
|
type: 'string';
|
|
@@ -128,16 +129,19 @@ type ToolCall = {
|
|
|
128
129
|
};
|
|
129
130
|
};
|
|
130
131
|
interface SimpleMessage {
|
|
132
|
+
id: string;
|
|
131
133
|
role: 'system' | 'user';
|
|
132
134
|
content: string;
|
|
133
135
|
}
|
|
134
136
|
interface AssistantMessage {
|
|
137
|
+
id: string;
|
|
135
138
|
role: 'assistant';
|
|
136
139
|
content: string;
|
|
137
140
|
reasoning_content?: string;
|
|
138
141
|
tool_calls?: ToolCall[] | null;
|
|
139
142
|
}
|
|
140
143
|
interface ToolMessage {
|
|
144
|
+
id: string;
|
|
141
145
|
role: 'tool';
|
|
142
146
|
content: string;
|
|
143
147
|
tool_call_id: string;
|
|
@@ -146,6 +150,7 @@ type Message = SimpleMessage | AssistantMessage | ToolMessage;
|
|
|
146
150
|
interface Params {
|
|
147
151
|
tools?: string[];
|
|
148
152
|
roundsLeft?: number;
|
|
153
|
+
panel?: Pick<PanelElement, 'pushLoadingMessage' | 'updateLoadingMessageContent'>;
|
|
149
154
|
}
|
|
150
155
|
interface Chunk {
|
|
151
156
|
choices: Array<{
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 shichzh
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { type Message } from '../utils/agent';
|
|
17
|
+
export interface AppRef {
|
|
18
|
+
pushMessage: (message: Message) => void;
|
|
19
|
+
pushMessages: (messages: Message[]) => void;
|
|
20
|
+
pushLoadingMessage: () => void;
|
|
21
|
+
updateLoadingMessageReasoningContent: (content: string) => void;
|
|
22
|
+
updateLoadingMessageContent: (content: string) => void;
|
|
23
|
+
}
|
|
24
|
+
interface AppProps {
|
|
25
|
+
onReady: () => void;
|
|
26
|
+
}
|
|
27
|
+
declare const App: import("react").ForwardRefExoticComponent<AppProps & import("react").RefAttributes<AppRef>>;
|
|
28
|
+
export default App;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright 2025 Hughe5
|
|
3
2
|
* Copyright 2026 shichzh
|
|
4
3
|
*
|
|
5
4
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -14,5 +13,9 @@
|
|
|
14
13
|
* See the License for the specific language governing permissions and
|
|
15
14
|
* limitations under the License.
|
|
16
15
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
import { type Message } from '../../utils/agent';
|
|
17
|
+
interface MessageItemProps {
|
|
18
|
+
message: Message;
|
|
19
|
+
}
|
|
20
|
+
declare const MessageItem: import("react").ForwardRefExoticComponent<MessageItemProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
21
|
+
export default MessageItem;
|
package/dist/view/event.d.ts
CHANGED
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
import { type Message } from '../utils/agent';
|
|
18
|
-
declare function bindEvents(): void;
|
|
19
18
|
type EventType = 'send' | 'create';
|
|
20
19
|
type EventParams = {
|
|
21
20
|
send: [message: Message];
|
|
@@ -28,4 +27,4 @@ declare class EventManager {
|
|
|
28
27
|
emit: <T extends EventType>(type: T, ...args: EventParams[T]) => Promise<void>;
|
|
29
28
|
}
|
|
30
29
|
declare const eventManager: EventManager;
|
|
31
|
-
export {
|
|
30
|
+
export { eventManager };
|
package/dist/view/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright
|
|
2
|
+
* Copyright 2026 shichzh
|
|
3
3
|
*
|
|
4
4
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
* you may not use this file except in compliance with the License.
|
|
@@ -13,4 +13,12 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
import { RefObject } from 'react';
|
|
17
|
+
import { AppRef } from './App';
|
|
18
|
+
interface Params {
|
|
19
|
+
domNode: ShadowRoot;
|
|
20
|
+
onReady: () => void;
|
|
21
|
+
}
|
|
22
|
+
type Result = RefObject<AppRef | null>;
|
|
23
|
+
declare const init: ({ domNode, onReady }: Params) => Result;
|
|
24
|
+
export { init, type Result };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai-client-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "用于开发 AI 应用,适配任意前端框架,兼容多种大模型,提供对话界面、Function Calling、Agent、工作流等",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Hughe5",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"test": "vitest",
|
|
45
45
|
"test:run": "vitest run",
|
|
46
46
|
"test:coverage": "vitest run --coverage",
|
|
47
|
-
"check-license": "addlicense -check -c \"
|
|
47
|
+
"check-license": "addlicense -check -c \"Copyright\" -l apache \"examples\" \"src\""
|
|
48
48
|
},
|
|
49
49
|
"keywords": [
|
|
50
50
|
"ai",
|
|
@@ -67,11 +67,15 @@
|
|
|
67
67
|
"pure-javascript"
|
|
68
68
|
],
|
|
69
69
|
"dependencies": {
|
|
70
|
+
"@ant-design/cssinjs": "^2.1.2",
|
|
70
71
|
"ajv": "^8.17.1",
|
|
72
|
+
"antd": "^6.3.7",
|
|
71
73
|
"chrono-node": "^2.8.3",
|
|
72
74
|
"dayjs": "^1.11.13",
|
|
73
75
|
"dompurify": "^3.2.7",
|
|
74
76
|
"lodash-es": "^4.17.21",
|
|
77
|
+
"react": "^19.2.5",
|
|
78
|
+
"react-dom": "^19.2.5",
|
|
75
79
|
"rehype-stringify": "^10.0.1",
|
|
76
80
|
"remark-gfm": "^4.0.1",
|
|
77
81
|
"remark-parse": "^11.0.0",
|
|
@@ -80,6 +84,8 @@
|
|
|
80
84
|
},
|
|
81
85
|
"devDependencies": {
|
|
82
86
|
"@types/lodash-es": "^4.17.12",
|
|
87
|
+
"@types/react": "^19.2.14",
|
|
88
|
+
"@types/react-dom": "^19.2.3",
|
|
83
89
|
"@vitest/coverage-v8": "^3.2.4",
|
|
84
90
|
"eslint": "^9.30.1",
|
|
85
91
|
"globals": "^16.3.0",
|
package/dist/view/dom.d.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2025 Hughe5
|
|
3
|
-
* Copyright 2026 shichzh
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
* you may not use this file except in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
* See the License for the specific language governing permissions and
|
|
15
|
-
* limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
import type { Message } from '../utils/agent';
|
|
18
|
-
interface Elements {
|
|
19
|
-
root: ShadowRoot;
|
|
20
|
-
userInputContainer: HTMLElement;
|
|
21
|
-
userInput: HTMLTextAreaElement;
|
|
22
|
-
submitIcon: HTMLButtonElement;
|
|
23
|
-
stopIcon: HTMLButtonElement;
|
|
24
|
-
messagesContainer: HTMLElement;
|
|
25
|
-
createButton: HTMLButtonElement;
|
|
26
|
-
}
|
|
27
|
-
declare function cacheElements(root: ShadowRoot): Elements;
|
|
28
|
-
declare function getElements(): Elements;
|
|
29
|
-
declare class MessagesContainerRender {
|
|
30
|
-
#private;
|
|
31
|
-
createCopyButton(message: Message): Element | null;
|
|
32
|
-
createMessage(message: Message): HTMLDivElement;
|
|
33
|
-
updateMessageContent(messageElement: Element, content: string): void;
|
|
34
|
-
pushMessage: (message: Message | undefined) => void;
|
|
35
|
-
pushMessages: (messages: Message[]) => void;
|
|
36
|
-
pushLoadingMessage: () => void;
|
|
37
|
-
finishLoadingMessage: () => void;
|
|
38
|
-
updateLoadingMessageContent: (content: string) => void;
|
|
39
|
-
updateLoadingMessageReasoningContent: (content: string) => void;
|
|
40
|
-
clear(): void;
|
|
41
|
-
setPaddingBottom(): void;
|
|
42
|
-
}
|
|
43
|
-
declare const userInputRender: {
|
|
44
|
-
readonly value: string;
|
|
45
|
-
setValue(value: string): void;
|
|
46
|
-
clear(): void;
|
|
47
|
-
focus(): void;
|
|
48
|
-
};
|
|
49
|
-
declare const buttonRender: {
|
|
50
|
-
default(): void;
|
|
51
|
-
chatting(): void;
|
|
52
|
-
};
|
|
53
|
-
declare const alertRender: {
|
|
54
|
-
show(text: string): void;
|
|
55
|
-
};
|
|
56
|
-
declare const messagesContainerRender: MessagesContainerRender;
|
|
57
|
-
export { cacheElements, getElements, messagesContainerRender, userInputRender, buttonRender, alertRender, };
|