@ray-js/t-agent 0.2.7 → 0.2.8-beta.2

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.
@@ -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';
@@ -11,4 +12,5 @@ export { createHooks, Hookable } from 'hookable';
11
12
  export { ChatAgent, ChatSession, StreamResponse, ChatTile, ChatBubbleTile, ChatMessage, generateId, getLogger, Logger, Emitter, EmitterEvent, isAbortError, shuffleWithSeed };
12
13
  export * from './createChatAgent';
13
14
  export * from './types';
14
- export * from './json';
15
+ export * from './json';
16
+ export * from './deepmerge';
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";
@@ -1,5 +1,4 @@
1
1
  export declare function generateId(length?: number): string;
2
2
  export declare function deepCloneToPlainObject(obj: any, visited?: WeakMap<object, any>): any;
3
- export declare function deepMerge(target: any, source: any): any;
4
3
  export declare function isAbortError(reason: any): any;
5
4
  export declare function shuffleWithSeed<T>(array: T[], seed: string): T[];
@@ -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);
@@ -86,29 +85,6 @@ export function deepCloneToPlainObject(obj) {
86
85
  }
87
86
  return clonedObj;
88
87
  }
89
- export function deepMerge(target, source) {
90
- if (typeof target !== 'object' || target === null) {
91
- return source; // 如果目标不是对象,直接返回来源
92
- }
93
- if (typeof source !== 'object' || source === null) {
94
- return target; // 如果来源不是对象,返回目标
95
- }
96
- for (const key in source) {
97
- if (Object.prototype.hasOwnProperty.call(source, key)) {
98
- const sourceValue = source[key];
99
- const targetValue = target[key];
100
-
101
- // 如果是对象,递归合并
102
- if (typeof sourceValue === 'object' && sourceValue !== null) {
103
- target[key] = deepMerge(Array.isArray(targetValue) ? [] : targetValue || {}, sourceValue);
104
- } else {
105
- // 否则直接赋值
106
- target[key] = sourceValue;
107
- }
108
- }
109
- }
110
- return target;
111
- }
112
88
  export function isAbortError(reason) {
113
89
  return reason && typeof Error !== 'undefined' && reason instanceof Error && reason.name === 'AbortError';
114
90
  }
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.7",
3
+ "version": "0.2.8-beta.2",
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": "3afabdd5b9a063d70157f69158ef8edccfdac012"
31
+ "gitHead": "450ca8d41536094b3bea57198fd7724ba6812438"
30
32
  }