@aipanel/core 1.2.3 → 1.2.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/es/types.d.ts +4 -0
- package/es/utils.d.ts +10 -0
- package/es/utils.mjs +7 -0
- package/lib/types.d.ts +4 -0
- package/lib/utils.cjs +8 -0
- package/lib/utils.d.ts +10 -0
- package/package.json +1 -1
package/es/types.d.ts
CHANGED
|
@@ -72,6 +72,8 @@ export interface LogFileConfig {
|
|
|
72
72
|
* 选中的元素信息
|
|
73
73
|
*/
|
|
74
74
|
export interface SelectedElement {
|
|
75
|
+
/** 节点唯一 id(`@节点[n<id>]` 引用标记与上下文注入共用;由 ensureNodeId 分配) */
|
|
76
|
+
id?: string;
|
|
75
77
|
/** 文件路径 */
|
|
76
78
|
filePath: string | null;
|
|
77
79
|
/** 行号 */
|
|
@@ -145,6 +147,8 @@ export interface AIPanelWidgetSession {
|
|
|
145
147
|
* 挂件选中的元素
|
|
146
148
|
*/
|
|
147
149
|
export interface AIPanelSelectedElement {
|
|
150
|
+
/** 节点唯一 id(与 SelectedElement.id 同源,`@节点[n<id>]` 标记与上下文注入共用) */
|
|
151
|
+
id?: string;
|
|
148
152
|
filePath: string | null;
|
|
149
153
|
line: number | null;
|
|
150
154
|
column: number | null;
|
package/es/utils.d.ts
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview 通用工具函数
|
|
3
3
|
*/
|
|
4
|
+
/**
|
|
5
|
+
* 取(或生成)元素的节点唯一 id:优先复用已赋值的 id,否则生成随机 id 并写回元素。
|
|
6
|
+
* 同一引用在会话标记(`@节点[n<id>]`)与上下文注入里使用同一个 id;
|
|
7
|
+
* 不同包(client / dsh-client / context 端点)共用此实现,保证 id 体系一致。
|
|
8
|
+
* @param element - 携带可选 id 的元素对象(会被写回生成的 id)
|
|
9
|
+
* @returns 该元素最终使用的节点 id
|
|
10
|
+
*/
|
|
11
|
+
export declare function ensureNodeId(element: {
|
|
12
|
+
id?: string;
|
|
13
|
+
}): string;
|
|
4
14
|
/**
|
|
5
15
|
* 截断字符串到指定长度
|
|
6
16
|
* @param value - 要截断的字符串
|
package/es/utils.mjs
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
function ensureNodeId(element) {
|
|
2
|
+
if (element.id) return element.id;
|
|
3
|
+
const random = typeof crypto !== "undefined" && typeof crypto.randomUUID === "function" ? crypto.randomUUID().replace(/-/g, "").slice(0, 8) : Math.random().toString(36).slice(2, 10);
|
|
4
|
+
element.id = `n${random}`;
|
|
5
|
+
return element.id;
|
|
6
|
+
}
|
|
1
7
|
function truncate(value, maxLength) {
|
|
2
8
|
if (value.length <= maxLength) {
|
|
3
9
|
return value;
|
|
@@ -47,6 +53,7 @@ function extractTextFromResponse(data) {
|
|
|
47
53
|
export {
|
|
48
54
|
base64Decode,
|
|
49
55
|
base64Encode,
|
|
56
|
+
ensureNodeId,
|
|
50
57
|
extractTextFromResponse,
|
|
51
58
|
sleep,
|
|
52
59
|
truncate
|
package/lib/types.d.ts
CHANGED
|
@@ -72,6 +72,8 @@ export interface LogFileConfig {
|
|
|
72
72
|
* 选中的元素信息
|
|
73
73
|
*/
|
|
74
74
|
export interface SelectedElement {
|
|
75
|
+
/** 节点唯一 id(`@节点[n<id>]` 引用标记与上下文注入共用;由 ensureNodeId 分配) */
|
|
76
|
+
id?: string;
|
|
75
77
|
/** 文件路径 */
|
|
76
78
|
filePath: string | null;
|
|
77
79
|
/** 行号 */
|
|
@@ -145,6 +147,8 @@ export interface AIPanelWidgetSession {
|
|
|
145
147
|
* 挂件选中的元素
|
|
146
148
|
*/
|
|
147
149
|
export interface AIPanelSelectedElement {
|
|
150
|
+
/** 节点唯一 id(与 SelectedElement.id 同源,`@节点[n<id>]` 标记与上下文注入共用) */
|
|
151
|
+
id?: string;
|
|
148
152
|
filePath: string | null;
|
|
149
153
|
line: number | null;
|
|
150
154
|
column: number | null;
|
package/lib/utils.cjs
CHANGED
|
@@ -19,11 +19,18 @@ var utils_exports = {};
|
|
|
19
19
|
__export(utils_exports, {
|
|
20
20
|
base64Decode: () => base64Decode,
|
|
21
21
|
base64Encode: () => base64Encode,
|
|
22
|
+
ensureNodeId: () => ensureNodeId,
|
|
22
23
|
extractTextFromResponse: () => extractTextFromResponse,
|
|
23
24
|
sleep: () => sleep,
|
|
24
25
|
truncate: () => truncate
|
|
25
26
|
});
|
|
26
27
|
module.exports = __toCommonJS(utils_exports);
|
|
28
|
+
function ensureNodeId(element) {
|
|
29
|
+
if (element.id) return element.id;
|
|
30
|
+
const random = typeof crypto !== "undefined" && typeof crypto.randomUUID === "function" ? crypto.randomUUID().replace(/-/g, "").slice(0, 8) : Math.random().toString(36).slice(2, 10);
|
|
31
|
+
element.id = `n${random}`;
|
|
32
|
+
return element.id;
|
|
33
|
+
}
|
|
27
34
|
function truncate(value, maxLength) {
|
|
28
35
|
if (value.length <= maxLength) {
|
|
29
36
|
return value;
|
|
@@ -74,6 +81,7 @@ function extractTextFromResponse(data) {
|
|
|
74
81
|
0 && (module.exports = {
|
|
75
82
|
base64Decode,
|
|
76
83
|
base64Encode,
|
|
84
|
+
ensureNodeId,
|
|
77
85
|
extractTextFromResponse,
|
|
78
86
|
sleep,
|
|
79
87
|
truncate
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview 通用工具函数
|
|
3
3
|
*/
|
|
4
|
+
/**
|
|
5
|
+
* 取(或生成)元素的节点唯一 id:优先复用已赋值的 id,否则生成随机 id 并写回元素。
|
|
6
|
+
* 同一引用在会话标记(`@节点[n<id>]`)与上下文注入里使用同一个 id;
|
|
7
|
+
* 不同包(client / dsh-client / context 端点)共用此实现,保证 id 体系一致。
|
|
8
|
+
* @param element - 携带可选 id 的元素对象(会被写回生成的 id)
|
|
9
|
+
* @returns 该元素最终使用的节点 id
|
|
10
|
+
*/
|
|
11
|
+
export declare function ensureNodeId(element: {
|
|
12
|
+
id?: string;
|
|
13
|
+
}): string;
|
|
4
14
|
/**
|
|
5
15
|
* 截断字符串到指定长度
|
|
6
16
|
* @param value - 要截断的字符串
|