@ray-js/t-agent 0.2.8-beta.1 → 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.
- package/README-zh_CN.md +1 -1
- package/README.md +1 -1
- package/dist/chat/ChatBubbleTile.d.ts +2 -2
- package/dist/chat/ChatMessage.js +4 -3
- package/dist/chat/ChatSession.d.ts +2 -2
- package/dist/chat/ChatSession.js +0 -5
- package/dist/chat/index.js +1 -0
- package/dist/chat/json.js +6 -1
- package/dist/chat/types.js +2 -0
- package/dist/chat/utils.js +0 -1
- package/dist/index.js +1 -0
- package/dist/plugins/ui.d.ts +2 -2
- package/package.json +5 -3
package/README-zh_CN.md
CHANGED
|
@@ -854,7 +854,7 @@ Hooks:
|
|
|
854
854
|
|
|
855
855
|
提供 MCP 服务暴露能力,可以实现让 Agent 调用小程序里面提供的 tool,实现操作蓝牙设备,调用自定义 api,读取本地文件等功能,使用时先需要在智能体节点上开启“设备 MCP”,此外,MCP tool 的名字必须以 `device.` 开头。
|
|
856
856
|
|
|
857
|
-

|
|
858
858
|
|
|
859
859
|
**使用前提**:
|
|
860
860
|
|
package/README.md
CHANGED
|
@@ -849,7 +849,7 @@ Offers built-in features including smart home device control and knowledge base
|
|
|
849
849
|
|
|
850
850
|
Provides MCP service exposure capability so the Agent can call tools implemented inside the mini-program, such as operating Bluetooth devices, calling custom APIs, or reading local files. Before using it, enable "Device MCP" on the agent node. In addition, MCP tool names must start with `device.`.
|
|
851
851
|
|
|
852
|
-

|
|
853
853
|
|
|
854
854
|
**Prerequisites**:
|
|
855
855
|
|
|
@@ -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
|
|
33
|
-
fallback?: import("./types").TipTileData
|
|
32
|
+
children: import("./types").ChatTileObject[];
|
|
33
|
+
fallback?: import("./types").TipTileData;
|
|
34
34
|
};
|
|
35
35
|
}
|
package/dist/chat/ChatMessage.js
CHANGED
|
@@ -66,7 +66,7 @@ export default class ChatMessage {
|
|
|
66
66
|
show() {
|
|
67
67
|
return this.agent.runWithCatchError(async () => {
|
|
68
68
|
if (this._isShow) {
|
|
69
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
17
|
+
get: <T = any>(key: string, defaultValue?: T) => any;
|
|
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[
|
|
25
|
+
onChange: (fn: ChatSessionHooks["onChange"]) => () => void;
|
|
26
26
|
getLatestMessage: () => ChatMessage | undefined;
|
|
27
27
|
dispose: () => Promise<void>;
|
|
28
28
|
}
|
package/dist/chat/ChatSession.js
CHANGED
|
@@ -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
|
}
|
package/dist/chat/index.js
CHANGED
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
|
// 只处理以 ``` 或 ~~~ 开头的
|
package/dist/chat/types.js
CHANGED
package/dist/chat/utils.js
CHANGED
|
@@ -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
package/dist/plugins/ui.d.ts
CHANGED
|
@@ -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: <
|
|
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: <
|
|
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.
|
|
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": "
|
|
31
|
+
"gitHead": "450ca8d41536094b3bea57198fd7724ba6812438"
|
|
30
32
|
}
|