@ray-js/t-agent 0.2.8-beta.1 → 0.2.8-beta.3

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.
@@ -29,7 +29,7 @@ export default class ChatBubbleTile extends ChatTile<BubbleTileData> {
29
29
  id: string;
30
30
  type: string;
31
31
  locked: boolean;
32
- children: import("./types").ChatTileObject<any>[];
33
- fallback?: import("./types").TipTileData | undefined;
32
+ children: import("./types").ChatTileObject[];
33
+ fallback?: import("./types").TipTileData;
34
34
  };
35
35
  }
@@ -66,7 +66,7 @@ export default class ChatMessage {
66
66
  show() {
67
67
  return this.agent.runWithCatchError(async () => {
68
68
  if (this._isShow) {
69
- console.warn('message is already show');
69
+ logger.warn('message is already show');
70
70
  return;
71
71
  }
72
72
  await this.agent.hooks.callHook('onMessageChange:before', 'show', this);
@@ -79,7 +79,7 @@ export default class ChatMessage {
79
79
  update() {
80
80
  return this.agent.runWithCatchError(async () => {
81
81
  if (!this._isShow) {
82
- console.warn('message is not show');
82
+ logger.warn('message is not show');
83
83
  return;
84
84
  }
85
85
  await this.agent.hooks.callHook('onMessageChange:before', 'update', this);
@@ -94,12 +94,13 @@ export default class ChatMessage {
94
94
  remove() {
95
95
  return this.agent.runWithCatchError(async () => {
96
96
  if (!this._isShow) {
97
- console.warn('message is not show');
97
+ logger.warn('message is not show');
98
98
  return;
99
99
  }
100
100
  await this.agent.hooks.callHook('onMessageChange:before', 'remove', this);
101
101
  await this.agent.hooks.callHook('onMessageChange', 'remove', this);
102
102
  this.agent.session.unbindMessage(this);
103
+ this._isShow = false;
103
104
  await this.agent.hooks.callHook('onMessageChange:after', 'remove', this);
104
105
  });
105
106
  }
@@ -14,7 +14,7 @@ export default class ChatSession {
14
14
  constructor(agent: ChatAgent);
15
15
  initValue: (key: string, value: any) => void;
16
16
  set: (key: string, value: any) => Promise<void>;
17
- get: <T = any>(key: string, defaultValue?: T | undefined) => any;
17
+ get: <T = any>(key: string, defaultValue?: T) => T;
18
18
  getData: () => Record<string, any>;
19
19
  initMessages: (messages: ChatMessage[]) => void;
20
20
  getTileById: (id: string) => ChatTile<any> | undefined;
@@ -22,7 +22,7 @@ export default class ChatSession {
22
22
  unbindTile: (tile: ChatTile) => void;
23
23
  bindMessage: (message: ChatMessage) => void;
24
24
  unbindMessage: (message: ChatMessage) => void;
25
- onChange: (fn: ChatSessionHooks['onChange']) => () => void;
25
+ onChange: (fn: ChatSessionHooks["onChange"]) => () => void;
26
26
  getLatestMessage: () => ChatMessage | undefined;
27
27
  dispose: () => Promise<void>;
28
28
  }
@@ -100,10 +100,5 @@ export default class ChatSession {
100
100
  });
101
101
  this.agent = agent;
102
102
  this.hooks = createHooks();
103
- const hooks = ['onChange'];
104
- for (let i = 0; i < hooks.length; i++) {
105
- const hook = hooks[i];
106
- this[hook] = fn => this.hooks.hook(hook, fn);
107
- }
108
103
  }
109
104
  }
@@ -1,3 +1,4 @@
1
+ /* istanbul ignore file */
1
2
  import ChatAgent from './ChatAgent';
2
3
  import ChatSession from './ChatSession';
3
4
  import StreamResponse from './StreamResponse';
package/dist/chat/json.js CHANGED
@@ -297,6 +297,7 @@ function strip(tokens) {
297
297
  // Dangling key
298
298
  // Check "aggressive" strip for empty objects logic from original
299
299
  const n = types.length;
300
+ /* istanbul ignore else -- n<2 is structurally unreachable: a dangling IsKey string always has at least a preceding '{' token */
300
301
  if (n >= 2) {
301
302
  const t2Type = types[n - 2];
302
303
  const t2Val = values[n - 2];
@@ -309,6 +310,8 @@ function strip(tokens) {
309
310
  continue;
310
311
  }
311
312
  }
313
+
314
+ /* istanbul ignore next: defensive branch for malformed token sequences */
312
315
  if (t2Type === TokenType.Paren && t2Val === '[') {
313
316
  if (n >= 3 && types[n - 3] === TokenType.Delimiter) {
314
317
  // , [ "key" -> pop 3
@@ -345,6 +348,7 @@ function strip(tokens) {
345
348
  }
346
349
  if (t === TokenType.Paren) {
347
350
  if (v === '[') {
351
+ /* istanbul ignore next: defensive branch for malformed token sequences */
348
352
  if (types.length >= 2 && types[types.length - 2] === TokenType.Delimiter) {
349
353
  types.length -= 2;
350
354
  values.length -= 2;
@@ -372,6 +376,7 @@ function unstrip(tokens) {
372
376
  const t = types[i];
373
377
  const v = values[i];
374
378
  if (t === TokenType.Brace) {
379
+ /* istanbul ignore else -- tokenizer only emits '{' or '}' for Brace tokens */
375
380
  if (v === '{') {
376
381
  stack.push('}');
377
382
  } else if (v === '}') {
@@ -380,6 +385,7 @@ function unstrip(tokens) {
380
385
  stack.pop();
381
386
  }
382
387
  } else if (t === TokenType.Paren) {
388
+ /* istanbul ignore else -- tokenizer only emits '[' or ']' for Paren tokens */
383
389
  if (v === '[') {
384
390
  stack.push(']');
385
391
  } else if (v === ']') {
@@ -442,7 +448,6 @@ function generate(tokens) {
442
448
 
443
449
  /** * Best-effort partial JSON parser: tries to complete dangling structures * and then JSON.parse */
444
450
  function stripCodeFence(input) {
445
- if (typeof input !== 'string') return input;
446
451
  const trimmed = input.trim();
447
452
 
448
453
  // 只处理以 ``` 或 ~~~ 开头的
@@ -1,3 +1,5 @@
1
+ /* istanbul ignore file */
2
+
1
3
  export let ChatCardType = /*#__PURE__*/function (ChatCardType) {
2
4
  ChatCardType["CUSTOM"] = "custom";
3
5
  ChatCardType["BUILD_IN"] = "buildIn";
@@ -21,7 +21,6 @@ export function deepCloneToPlainObject(obj) {
21
21
 
22
22
  // 如果是基本类型(数字、字符串、布尔等),直接返回自身;函数在 JSON 中会被忽略
23
23
  if (typeof obj !== 'object') return obj;
24
- if (typeof obj === 'function') return undefined;
25
24
 
26
25
  // 如果对象已被处理过,直接返回缓存结果,防止循环引用
27
26
  if (visited.has(obj)) return visited.get(obj);
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ /* istanbul ignore file */
1
2
  export * from './chat';
2
3
  export * from './plugins/ui';
3
4
  export * from './plugins/debug';
@@ -46,9 +46,9 @@ export declare function withUI(): (agent: ChatAgent) => {
46
46
  hooks: import("hookable").Hookable<UIHooks, string>;
47
47
  ui: {
48
48
  callHook: <K extends keyof UIHooks>(hookName: K, payload: UIHooks[K] extends (context: UIHooksContext<infer P, any>) => void ? P : never) => Promise<UIHooks[K] extends (context: UIHooksContext<any, infer R>) => void ? R : null>;
49
- hook: <K_1 extends keyof UIHooks>(hookName: K_1, fn: UIHooks[K_1]) => () => void;
49
+ hook: <K extends keyof UIHooks>(hookName: K, fn: UIHooks[K]) => () => void;
50
50
  emitter: Emitter;
51
51
  emitEvent: <T extends keyof UIEventMap>(eventName: T, detail: UIEventMap[T]) => void;
52
- onEvent: <T_1 extends keyof UIEventMap>(eventName: T_1, handler: (detail: UIEventMap[T_1]) => void) => () => void;
52
+ onEvent: <T extends keyof UIEventMap>(eventName: T, handler: (detail: UIEventMap[T]) => void) => () => void;
53
53
  };
54
54
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/t-agent",
3
- "version": "0.2.8-beta.1",
3
+ "version": "0.2.8-beta.3",
4
4
  "author": "Tuya.inc",
5
5
  "license": "MIT",
6
6
  "private": false,
@@ -24,7 +24,9 @@
24
24
  "scripts": {
25
25
  "dev": "ray start --type=component --output dist --emit-declaration-dev",
26
26
  "build": "ray build --type=component --output dist",
27
- "clean": "rimraf ./dist"
27
+ "clean": "rimraf ./dist",
28
+ "test": "jest --runInBand",
29
+ "test:coverage": "jest --runInBand --coverage"
28
30
  },
29
- "gitHead": "040499ca11aedda3246121f880807da0f8af3cc9"
31
+ "gitHead": "938bc0c7da7d23dbbad8c3c14c97e5f4007f06f7"
30
32
  }