@ray-js/t-agent-plugin-aistream 0.2.6-beta-2 → 0.2.6-beta-4

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.
@@ -253,9 +253,10 @@ export class AIStreamSession {
253
253
  bizTag: BizTag.DEFAULT,
254
254
  ownerId
255
255
  }, this.options), {}, {
256
- extParams: _objectSpread({
256
+ extParams: _objectSpread(_objectSpread({}, this.options.extParams), {}, {
257
+ // chatId 之前可能是 undefined,这里要覆盖掉
257
258
  chatId
258
- }, this.options.extParams)
259
+ })
259
260
  });
260
261
  const [error, result] = await tryCatchTTT(() => queryAgentToken(options));
261
262
  if (error) {
@@ -95,20 +95,34 @@ mock.hooks.hook('disconnect', context => {
95
95
  mock.data.set('sessionMap', new Map());
96
96
  });
97
97
  mock.hooks.hook('queryAgentToken', context => {
98
- var _context$options$extP, _context$options$extP2;
98
+ var _context$options$extP, _context$options$extP2, _context$options$extP3;
99
99
  const agentToken = generateId();
100
100
  const map = mock.data.get('tokenMap');
101
101
  map.set(agentToken, {
102
102
  onlyAsr: ((_context$options$extP = context.options.extParams) === null || _context$options$extP === void 0 ? void 0 : _context$options$extP.onlyAsr) || false,
103
103
  needTts: ((_context$options$extP2 = context.options.extParams) === null || _context$options$extP2 === void 0 ? void 0 : _context$options$extP2.needTts) || false
104
104
  });
105
+ let chatId;
106
+ if (((_context$options$extP3 = context.options.extParams) === null || _context$options$extP3 === void 0 ? void 0 : _context$options$extP3.dialogueMode) === 1) {
107
+ var _context$options$extP4;
108
+ if ((_context$options$extP4 = context.options.extParams) !== null && _context$options$extP4 !== void 0 && _context$options$extP4.chatId) {
109
+ // 如果参数有传吗,则使用传入的 chatId
110
+ chatId = context.options.extParams.chatId;
111
+ } else {
112
+ // 使用生成的 id
113
+ chatId = "chatId-".concat(generateId());
114
+ }
115
+ }
105
116
  context.result = {
106
117
  agentToken,
107
118
  bizConfig: {
108
119
  bizCode: BizCode.CHAT,
109
120
  sendData: ['audio', 'video', 'text', 'image'],
110
121
  revData: ['text', 'audio']
111
- }
122
+ },
123
+ extParams: JSON.stringify({
124
+ chatId
125
+ })
112
126
  };
113
127
  });
114
128
  const dispatch = (type, detail) => {
@@ -258,7 +272,8 @@ mock.hooks.hook('sendEventEnd', async context => {
258
272
  }
259
273
  const ctx = {
260
274
  data: event.data,
261
- responseText: ''
275
+ responseText: '',
276
+ wordDelayMs: 100
262
277
  };
263
278
  const [error] = await tryCatch(() => mock.hooks.callHook('sendToAIStream', ctx));
264
279
  if (error) {
@@ -283,6 +298,7 @@ mock.hooks.hook('sendEventEnd', async context => {
283
298
  return;
284
299
  }
285
300
  const text = ctx.responseText || '⚠️ No mock text response matched!';
301
+ const wordDelayMs = ctx.wordDelayMs || 100;
286
302
  const words = splitString(text);
287
303
  if (event.controller.signal.aborted || session.closed) {
288
304
  return;
@@ -295,7 +311,7 @@ mock.hooks.hook('sendEventEnd', async context => {
295
311
  const bizId = generateId();
296
312
  event.replyText(StreamFlag.START);
297
313
  for (const word of words) {
298
- await mock.sleep(100);
314
+ await mock.sleep(wordDelayMs);
299
315
  if (event.controller.signal.aborted || session.closed) {
300
316
  return;
301
317
  }
@@ -15,6 +15,7 @@ export interface SendToAIStreamContext {
15
15
  userData?: Attribute[];
16
16
  }>;
17
17
  responseText: string | undefined;
18
+ wordDelayMs: number;
18
19
  responseSkills?: ReceivedTextSkillPacketBody[];
19
20
  }
20
21
  interface AsrDetectionContext {
@@ -1,4 +1,5 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import "core-js/modules/es.global-this.js";
2
3
  import { isDevTools } from './ttt';
3
4
  import logger from './logger';
4
5
  import { mock } from './mock';
@@ -6,6 +7,9 @@ import { TTTError } from './errors';
6
7
  let callId = 100000;
7
8
  export const getEnableMock = () => {
8
9
  try {
10
+ if ((globalThis === null || globalThis === void 0 ? void 0 : globalThis.__AIStreamEnableMock) != null) {
11
+ return globalThis.__AIStreamEnableMock;
12
+ }
9
13
  const result = ty.getStorageSync({
10
14
  key: 'AIStreamEnableMock'
11
15
  });
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-2",
3
+ "version": "0.2.6-beta-4",
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": "fa6602d3d1a9c14187a8f524302317ed22fec7c3"
38
+ "gitHead": "c1afc79e00950e8eb385ec233f74e1677a9c93cf"
39
39
  }