@ray-js/t-agent 0.0.5 → 0.0.7-beta-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-zh_CN.md +4 -4
- package/README.md +2 -2
- package/dist/chat/ChatAgent.js +16 -8
- package/dist/chat/ChatMessage.d.ts +1 -1
- package/dist/chat/ChatSession.d.ts +1 -1
- package/dist/chat/ChatSession.js +1 -1
- package/dist/chat/ChatTile.d.ts +1 -0
- package/dist/chat/ChatTile.js +8 -0
- package/dist/chat/Logger.js +6 -3
- package/dist/chat/createChatAgent.d.ts +2 -2
- package/dist/chat/types.d.ts +2 -1
- package/dist/plugins/ui.js +1 -0
- package/package.json +2 -2
package/README-zh_CN.md
CHANGED
|
@@ -84,7 +84,7 @@ const createAgent = () => {
|
|
|
84
84
|
hello.bubble.setText('Hello, world!');
|
|
85
85
|
result.messages.push(hello);
|
|
86
86
|
// 持久化消息,下次进入时会展示
|
|
87
|
-
await hello.persist(
|
|
87
|
+
await hello.persist();
|
|
88
88
|
});
|
|
89
89
|
|
|
90
90
|
// 恢复聊天时,发送一条消息
|
|
@@ -95,7 +95,7 @@ const createAgent = () => {
|
|
|
95
95
|
|
|
96
96
|
welcomeBack.bubble.setText('Welcome back');
|
|
97
97
|
result.messages.push(welcomeBack);
|
|
98
|
-
await welcomeBack.persist(
|
|
98
|
+
await welcomeBack.persist();
|
|
99
99
|
});
|
|
100
100
|
return agent;
|
|
101
101
|
};
|
|
@@ -667,7 +667,7 @@ const createAgent = () => {
|
|
|
667
667
|
withUI(), // 一般都需要应用 withUI 插件
|
|
668
668
|
withAssistant({
|
|
669
669
|
channel: 'your-channel-id', // 输入你的智能体ID
|
|
670
|
-
multiModal: false, // 是否开启多模态,默认为
|
|
670
|
+
multiModal: false, // 是否开启多模态,默认为 false
|
|
671
671
|
}),
|
|
672
672
|
withBuildIn()
|
|
673
673
|
);
|
|
@@ -685,7 +685,7 @@ const createAgent = () => {
|
|
|
685
685
|
参数:
|
|
686
686
|
|
|
687
687
|
- `channel` 智能体 ID
|
|
688
|
-
- `multiModal` 是否开启多模态,默认为
|
|
688
|
+
- `multiModal` 是否开启多模态,默认为 false
|
|
689
689
|
- `wireInputToAssistant` 是否将输入块传递给智能体,默认为 true,设置为 false 时,需要你自己编写 onInputBlocksPush Hook 来处理输入块
|
|
690
690
|
- `historySize` 历史消息大小,默认为 100
|
|
691
691
|
|
package/README.md
CHANGED
|
@@ -95,7 +95,7 @@ const createAgent = () => {
|
|
|
95
95
|
|
|
96
96
|
welcomeBack.bubble.setText('Welcome back');
|
|
97
97
|
result.messages.push(welcomeBack);
|
|
98
|
-
await welcomeBack.persist(
|
|
98
|
+
await welcomeBack.persist();
|
|
99
99
|
});
|
|
100
100
|
return agent;
|
|
101
101
|
};
|
|
@@ -679,7 +679,7 @@ This plugin facilitates communication with applet AI agent platforms.
|
|
|
679
679
|
Parameters:
|
|
680
680
|
|
|
681
681
|
- `channel`: Agent ID
|
|
682
|
-
- `multiModal`: Enable multi-modal? Defaults to
|
|
682
|
+
- `multiModal`: Enable multi-modal? Defaults to false
|
|
683
683
|
- `wireInputToAssistant`: Should input blocks be passed to the agent? Defaults to true. Set to false if you plan to handle input blocks manually with the onInputBlocksPush Hook.
|
|
684
684
|
- `historySize`: Size of message history, default is 100.
|
|
685
685
|
|
package/dist/chat/ChatAgent.js
CHANGED
|
@@ -82,18 +82,20 @@ export default class ChatAgent {
|
|
|
82
82
|
await this.hooks.callHook('onChatStart:before', result);
|
|
83
83
|
await this.hooks.callHook('onChatStart', result);
|
|
84
84
|
await this.hooks.callHook('onChatStart:after', result);
|
|
85
|
-
logger.debug('
|
|
85
|
+
logger.debug('%conChatStart', 'background: gray; color: white', result);
|
|
86
86
|
} else {
|
|
87
87
|
await this.hooks.callHook('onChatResume:before', result);
|
|
88
88
|
await this.hooks.callHook('onChatResume', result);
|
|
89
89
|
await this.hooks.callHook('onChatResume:after', result);
|
|
90
|
-
logger.debug('
|
|
90
|
+
logger.debug('%conChatResume', 'background: gray; color: white', result);
|
|
91
91
|
}
|
|
92
92
|
await this.hooks.callHook('onMessageListInit:before', result);
|
|
93
93
|
await this.hooks.callHook('onMessageListInit', result);
|
|
94
94
|
this.session.initMessages(result.messages);
|
|
95
95
|
await this.hooks.callHook('onMessageListInit:after', result);
|
|
96
|
+
logger.debug('%conMessageListInit', 'background: gray; color: white', result);
|
|
96
97
|
await this.hooks.callHook('onAgentStart:after');
|
|
98
|
+
logger.debug('%conAgentStart', 'background: gray; color: white');
|
|
97
99
|
});
|
|
98
100
|
});
|
|
99
101
|
/**
|
|
@@ -109,6 +111,7 @@ export default class ChatAgent {
|
|
|
109
111
|
hook.removeAllHooks();
|
|
110
112
|
}
|
|
111
113
|
await this.hooks.callHook('onAgentDispose:after');
|
|
114
|
+
logger.debug('%conAgentDispose', 'background: gray; color: white');
|
|
112
115
|
this.hooks.removeAllHooks();
|
|
113
116
|
});
|
|
114
117
|
});
|
|
@@ -119,7 +122,10 @@ export default class ChatAgent {
|
|
|
119
122
|
* @param signal abort signal
|
|
120
123
|
*/
|
|
121
124
|
_defineProperty(this, "pushInputBlocks", (blocks, signal) => {
|
|
122
|
-
logger.debug('
|
|
125
|
+
logger.debug('%conInputBlocksPush', 'background: gray; color: white', {
|
|
126
|
+
blocks,
|
|
127
|
+
signal
|
|
128
|
+
});
|
|
123
129
|
return this.runWithCatchError(async () => {
|
|
124
130
|
await this.hooks.callHook('onInputBlocksPush:before', blocks, signal);
|
|
125
131
|
await this.hooks.callHook('onInputBlocksPush', blocks, signal);
|
|
@@ -141,15 +147,15 @@ export default class ChatAgent {
|
|
|
141
147
|
* @param payload message payload
|
|
142
148
|
*/
|
|
143
149
|
_defineProperty(this, "emitTileEvent", (tileId, payload) => {
|
|
144
|
-
logger.debug('emitTileEvent', {
|
|
145
|
-
tileId,
|
|
146
|
-
payload
|
|
147
|
-
});
|
|
148
150
|
return this.runWithCatchError(async () => {
|
|
149
151
|
const tile = this.session.getTileById(tileId);
|
|
150
152
|
await this.hooks.callHook('onTileEvent:before', tile, payload);
|
|
151
153
|
await this.hooks.callHook('onTileEvent', tile, payload);
|
|
152
154
|
await this.hooks.callHook('onTileEvent:after', tile, payload);
|
|
155
|
+
logger.debug('%conTileEvent', 'background: gray; color: white', {
|
|
156
|
+
tileId,
|
|
157
|
+
payload
|
|
158
|
+
});
|
|
153
159
|
});
|
|
154
160
|
});
|
|
155
161
|
/**
|
|
@@ -192,6 +198,7 @@ export default class ChatAgent {
|
|
|
192
198
|
await this.runWithCatchError(async () => {
|
|
193
199
|
try {
|
|
194
200
|
const parts = response.parts();
|
|
201
|
+
let partText = '';
|
|
195
202
|
var _iteratorAbruptCompletion = false;
|
|
196
203
|
var _didIteratorError = false;
|
|
197
204
|
var _iteratorError;
|
|
@@ -201,6 +208,7 @@ export default class ChatAgent {
|
|
|
201
208
|
{
|
|
202
209
|
message.setMeta(part.meta);
|
|
203
210
|
if (part.type === 'text') {
|
|
211
|
+
partText = part.text;
|
|
204
212
|
text = await textCompose(message, part.text, ChatMessageStatus.UPDATING);
|
|
205
213
|
await message.set({
|
|
206
214
|
status: ChatMessageStatus.UPDATING
|
|
@@ -239,7 +247,7 @@ export default class ChatAgent {
|
|
|
239
247
|
}
|
|
240
248
|
}
|
|
241
249
|
}
|
|
242
|
-
text = await textCompose(message,
|
|
250
|
+
text = await textCompose(message, partText, ChatMessageStatus.FINISH);
|
|
243
251
|
await message.set({
|
|
244
252
|
status: ChatMessageStatus.FINISH
|
|
245
253
|
}).bubble.setText(text).update();
|
|
@@ -19,7 +19,7 @@ export default class ChatMessage implements ChatMessageObject {
|
|
|
19
19
|
update(): Promise<void>;
|
|
20
20
|
remove(): Promise<void>;
|
|
21
21
|
_setIsShow(): void;
|
|
22
|
-
persist(payload
|
|
22
|
+
persist(payload?: any): Promise<void>;
|
|
23
23
|
setTilesLocked(locked: boolean): this;
|
|
24
24
|
removeTile(tile: ChatTile): void;
|
|
25
25
|
addTile(type: string, data: any, id?: string): ChatTile<any>;
|
|
@@ -9,7 +9,7 @@ export default class ChatSession {
|
|
|
9
9
|
private tileIdIndex;
|
|
10
10
|
hooks: Hookable<ChatSessionHooks>;
|
|
11
11
|
isNewChat: boolean;
|
|
12
|
-
sessionId: string;
|
|
12
|
+
sessionId: string | null;
|
|
13
13
|
readonly messages: Map<string, ChatMessage>;
|
|
14
14
|
constructor(agent: ChatAgent);
|
|
15
15
|
set: (key: string, value: any) => Promise<void>;
|
package/dist/chat/ChatSession.js
CHANGED
|
@@ -9,7 +9,7 @@ export default class ChatSession {
|
|
|
9
9
|
_defineProperty(this, "data", new Map());
|
|
10
10
|
_defineProperty(this, "tileIdIndex", new Map());
|
|
11
11
|
_defineProperty(this, "isNewChat", true);
|
|
12
|
-
_defineProperty(this, "sessionId",
|
|
12
|
+
_defineProperty(this, "sessionId", null);
|
|
13
13
|
_defineProperty(this, "messages", new Map());
|
|
14
14
|
_defineProperty(this, "set", async (key, value) => {
|
|
15
15
|
const oldValue = this.data.get(key);
|
package/dist/chat/ChatTile.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export default class ChatTile<T = any> implements ChatTileObject<T> {
|
|
|
11
11
|
constructor(message: ChatMessage, type: string, data?: T, children?: ChatTile[], id?: string);
|
|
12
12
|
setLocked(value: boolean): this;
|
|
13
13
|
addTile(type: string, data: any, id?: string): ChatTile<any>;
|
|
14
|
+
removeTile(tile: ChatTile): this;
|
|
14
15
|
/**
|
|
15
16
|
* 同 message 的 show
|
|
16
17
|
*/
|
package/dist/chat/ChatTile.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
2
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
3
|
+
import "core-js/modules/esnext.iterator.constructor.js";
|
|
3
4
|
import "core-js/modules/esnext.iterator.map.js";
|
|
4
5
|
import "core-js/modules/web.dom-collections.iterator.js";
|
|
5
6
|
import { generateId } from './utils';
|
|
@@ -29,6 +30,13 @@ export default class ChatTile {
|
|
|
29
30
|
this.children.push(tile);
|
|
30
31
|
return tile;
|
|
31
32
|
}
|
|
33
|
+
removeTile(tile) {
|
|
34
|
+
const index = this.children.indexOf(tile);
|
|
35
|
+
if (index !== -1) {
|
|
36
|
+
this.children.splice(index, 1);
|
|
37
|
+
}
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
32
40
|
|
|
33
41
|
/**
|
|
34
42
|
* 同 message 的 show
|
package/dist/chat/Logger.js
CHANGED
|
@@ -72,11 +72,14 @@ export default class Logger {
|
|
|
72
72
|
}
|
|
73
73
|
_output(level, args) {
|
|
74
74
|
if (!muted && passLevel(level)) {
|
|
75
|
-
|
|
75
|
+
let prefix = this.prefix.join(' ');
|
|
76
|
+
if (typeof args[0] === 'string') {
|
|
77
|
+
prefix = "".concat(prefix, " ").concat(args.shift());
|
|
78
|
+
}
|
|
76
79
|
if (typeof console[level] === 'function') {
|
|
77
|
-
console[level](...args);
|
|
80
|
+
console[level](prefix, ...args);
|
|
78
81
|
} else {
|
|
79
|
-
console.log(...args);
|
|
82
|
+
console.log(prefix, ...args);
|
|
80
83
|
}
|
|
81
84
|
}
|
|
82
85
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ChatAgentPlugin } from './types';
|
|
2
2
|
import ChatAgent from './ChatAgent';
|
|
3
|
-
type ExtractPluginReturnType<T extends ChatAgentPlugin<any>[]> = T extends [infer F, ...infer R] ? F extends ChatAgentPlugin<infer U> ? R extends ChatAgentPlugin<any>[] ? U & ExtractPluginReturnType<R> : U :
|
|
4
|
-
export declare function createChatAgent<T extends ChatAgentPlugin<any>[]>(...plugins: T): ChatAgent<
|
|
3
|
+
type ExtractPluginReturnType<T extends ChatAgentPlugin<any>[]> = T extends [infer F, ...infer R] ? F extends ChatAgentPlugin<infer U> ? R extends ChatAgentPlugin<any>[] ? U & ExtractPluginReturnType<R> : U : any : Record<string, unknown>;
|
|
4
|
+
export declare function createChatAgent<T extends ChatAgentPlugin<any>[]>(...plugins: T): ChatAgent<ExtractPluginReturnType<T>>;
|
|
5
5
|
export declare function applyChatAgentPlugins<T extends Record<string, unknown>, P extends ChatAgentPlugin<any>[]>(agent: ChatAgent<T>, ...plugins: P): ChatAgent<T & ExtractPluginReturnType<P>>;
|
|
6
6
|
export {};
|
package/dist/chat/types.d.ts
CHANGED
|
@@ -54,10 +54,11 @@ export declare enum ChatCardType {
|
|
|
54
54
|
BUILD_IN = "buildIn",
|
|
55
55
|
LOW_CODE = "lowCode"
|
|
56
56
|
}
|
|
57
|
-
export interface ChatCardObject<T = any> {
|
|
57
|
+
export interface ChatCardObject<T = any, S = any> {
|
|
58
58
|
cardCode: string;
|
|
59
59
|
cardType: ChatCardType;
|
|
60
60
|
cardData: T;
|
|
61
|
+
cardState?: S;
|
|
61
62
|
}
|
|
62
63
|
export interface ChatTileObject<T = any> {
|
|
63
64
|
id: string;
|
package/dist/plugins/ui.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ray-js/t-agent",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7-beta-1",
|
|
4
4
|
"author": "Tuya.inc",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"private": false,
|
|
@@ -26,5 +26,5 @@
|
|
|
26
26
|
"build": "ray build --type=component --output dist",
|
|
27
27
|
"clean": "rimraf ./dist"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "95aecc47d002cbf5e608c129478905c7fb458ea9"
|
|
30
30
|
}
|