@ray-js/t-agent-plugin-aistream 0.2.6-beta-3 → 0.2.6-beta-5
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/utils/defaultMock.js +4 -2
- package/dist/utils/mock.d.ts +1 -0
- package/dist/withAIStream.d.ts +5 -1
- package/dist/withAIStream.js +10 -0
- package/package.json +2 -2
|
@@ -272,7 +272,8 @@ mock.hooks.hook('sendEventEnd', async context => {
|
|
|
272
272
|
}
|
|
273
273
|
const ctx = {
|
|
274
274
|
data: event.data,
|
|
275
|
-
responseText: ''
|
|
275
|
+
responseText: '',
|
|
276
|
+
wordDelayMs: 100
|
|
276
277
|
};
|
|
277
278
|
const [error] = await tryCatch(() => mock.hooks.callHook('sendToAIStream', ctx));
|
|
278
279
|
if (error) {
|
|
@@ -297,6 +298,7 @@ mock.hooks.hook('sendEventEnd', async context => {
|
|
|
297
298
|
return;
|
|
298
299
|
}
|
|
299
300
|
const text = ctx.responseText || '⚠️ No mock text response matched!';
|
|
301
|
+
const wordDelayMs = ctx.wordDelayMs || 100;
|
|
300
302
|
const words = splitString(text);
|
|
301
303
|
if (event.controller.signal.aborted || session.closed) {
|
|
302
304
|
return;
|
|
@@ -309,7 +311,7 @@ mock.hooks.hook('sendEventEnd', async context => {
|
|
|
309
311
|
const bizId = generateId();
|
|
310
312
|
event.replyText(StreamFlag.START);
|
|
311
313
|
for (const word of words) {
|
|
312
|
-
await mock.sleep(
|
|
314
|
+
await mock.sleep(wordDelayMs);
|
|
313
315
|
if (event.controller.signal.aborted || session.closed) {
|
|
314
316
|
return;
|
|
315
317
|
}
|
package/dist/utils/mock.d.ts
CHANGED
package/dist/withAIStream.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChatAgent, ChatCardObject, ChatMessage, ChatTile, GetChatPluginHandler, InputBlock } from '@ray-js/t-agent';
|
|
1
|
+
import { ChatAgent, ChatCardObject, ChatMessage, ChatMessageStatus, ChatTile, GetChatPluginHandler, InputBlock } from '@ray-js/t-agent';
|
|
2
2
|
import { TTTAction } from './utils';
|
|
3
3
|
import { ConnectClientType, ReceivedTextSkillPacketBody } from './AIStreamTypes';
|
|
4
4
|
import { ChatHistoryStore, StoredMessageObject } from './ChatHistoryStore';
|
|
@@ -42,6 +42,9 @@ export interface AIStreamHooks {
|
|
|
42
42
|
onMessageParse: (msgItem: StoredMessageObject, result: {
|
|
43
43
|
messages: ChatMessage[];
|
|
44
44
|
}) => void;
|
|
45
|
+
onTextCompose: (respMsg: ChatMessage, status: ChatMessageStatus, result: {
|
|
46
|
+
text: string;
|
|
47
|
+
}) => void;
|
|
45
48
|
onSkillCompose: (skill: ReceivedTextSkillPacketBody[], respMsg: ChatMessage, result: {
|
|
46
49
|
messages: ChatMessage[];
|
|
47
50
|
}) => void;
|
|
@@ -78,6 +81,7 @@ export declare function withAIStream(options?: AIStreamOptions): (agent: ChatAge
|
|
|
78
81
|
data: string;
|
|
79
82
|
}>;
|
|
80
83
|
onSkillCompose: (fn: AIStreamHooks['onSkillCompose']) => () => void;
|
|
84
|
+
onTextCompose: (fn: AIStreamHooks['onTextCompose']) => () => void;
|
|
81
85
|
onSkillsEnd: (fn: AIStreamHooks['onSkillsEnd']) => () => void;
|
|
82
86
|
onCardsReceived: (fn: AIStreamHooks['onCardsReceived']) => () => void;
|
|
83
87
|
onTTTAction: (fn: AIStreamHooks['onTTTAction']) => () => void;
|
package/dist/withAIStream.js
CHANGED
|
@@ -354,6 +354,13 @@ export function withAIStream() {
|
|
|
354
354
|
logger.debug('withAIStream chat agent.flushStreamToShow');
|
|
355
355
|
const result = {
|
|
356
356
|
messages: await agent.flushStreamToShow(message, response, {
|
|
357
|
+
textCompose: async (message, text, status) => {
|
|
358
|
+
const result = {
|
|
359
|
+
text
|
|
360
|
+
};
|
|
361
|
+
await hooks.callHook('onTextCompose', message, status, result);
|
|
362
|
+
return result.text;
|
|
363
|
+
},
|
|
357
364
|
attachmentCompose: async (respMsg, part) => {
|
|
358
365
|
const result = {
|
|
359
366
|
messages: []
|
|
@@ -555,6 +562,9 @@ export function withAIStream() {
|
|
|
555
562
|
onSkillCompose: fn => {
|
|
556
563
|
return hooks.hook('onSkillCompose', fn);
|
|
557
564
|
},
|
|
565
|
+
onTextCompose: fn => {
|
|
566
|
+
return hooks.hook('onTextCompose', fn);
|
|
567
|
+
},
|
|
558
568
|
onSkillsEnd,
|
|
559
569
|
onCardsReceived: fn => {
|
|
560
570
|
return hooks.hook('onCardsReceived', fn);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ray-js/t-agent-plugin-aistream",
|
|
3
|
-
"version": "0.2.6-beta-
|
|
3
|
+
"version": "0.2.6-beta-5",
|
|
4
4
|
"author": "Tuya.inc",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"private": false,
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/url-parse": "^1.4.11"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "60f0d3f33a78b76aae90b22942d9bf64c430e565"
|
|
39
39
|
}
|