ng-directive-zero 1.0.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/README.md +86 -0
- package/fesm2022/ng-directive-zero.mjs +2475 -0
- package/fesm2022/ng-directive-zero.mjs.map +1 -0
- package/index.d.ts +5 -0
- package/lib/components/agentation/agentation.component.d.ts +54 -0
- package/lib/components/annotation-panel/annotation-panel.component.d.ts +84 -0
- package/lib/components/inline-editor/inline-editor.component.d.ts +53 -0
- package/lib/components/markers-panel/markers-panel.component.d.ts +47 -0
- package/lib/components/overlay/overlay.component.d.ts +171 -0
- package/lib/components/settings-panel/settings-panel.component.d.ts +48 -0
- package/lib/components/toolbar/toolbar.component.d.ts +56 -0
- package/lib/models/component-node.interface.d.ts +154 -0
- package/lib/ng-directive-zero.module.d.ts +35 -0
- package/lib/services/component-walker.service.d.ts +109 -0
- package/lib/services/data-sanitizer.service.d.ts +65 -0
- package/lib/services/mcp.service.d.ts +43 -0
- package/lib/services/prompt-generator.service.d.ts +74 -0
- package/package.json +39 -0
- package/public-api.d.ts +13 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { ComponentNode } from '../models/component-node.interface';
|
|
2
|
+
import * as i0 from "@angular/core";
|
|
3
|
+
/**
|
|
4
|
+
* ComponentWalkerService
|
|
5
|
+
*
|
|
6
|
+
* 核心服務:從 DOM 元素獲取 Angular 組件資訊
|
|
7
|
+
* 使用 Angular 的 ng.getComponent() 等開發模式 API
|
|
8
|
+
*
|
|
9
|
+
* 效能要求:執行時間 < 16ms (1 frame)
|
|
10
|
+
*/
|
|
11
|
+
export declare class ComponentWalkerService {
|
|
12
|
+
private uidCounter;
|
|
13
|
+
/**
|
|
14
|
+
* 檢查是否在開發模式下且 ng API 可用
|
|
15
|
+
*/
|
|
16
|
+
isAvailable(): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* 從 DOM 元素獲取 Angular 組件節點資訊
|
|
19
|
+
*
|
|
20
|
+
* @param element - 目標 DOM 元素
|
|
21
|
+
* @returns ComponentNode 或 null(如果不是 Angular 組件)
|
|
22
|
+
*/
|
|
23
|
+
getComponentNode(element: HTMLElement): ComponentNode | null;
|
|
24
|
+
/**
|
|
25
|
+
* 創建 DOM 節點組件資訊 (用於 Root Component 內的普通元素)
|
|
26
|
+
*/
|
|
27
|
+
private createDomNode;
|
|
28
|
+
/**
|
|
29
|
+
* 獲取組件定義 (ɵcmp)
|
|
30
|
+
*/
|
|
31
|
+
private getComponentDef;
|
|
32
|
+
/**
|
|
33
|
+
* 從組件定義提取 selector
|
|
34
|
+
*/
|
|
35
|
+
private extractSelector;
|
|
36
|
+
/**
|
|
37
|
+
* 提取 @Input 綁定的當前值
|
|
38
|
+
*/
|
|
39
|
+
private extractInputValues;
|
|
40
|
+
/**
|
|
41
|
+
* 提取 @Output 事件名稱
|
|
42
|
+
*/
|
|
43
|
+
private extractOutputNames;
|
|
44
|
+
/**
|
|
45
|
+
* 提取非 Input/Output 的公開屬性
|
|
46
|
+
*/
|
|
47
|
+
private extractPublicProperties;
|
|
48
|
+
/**
|
|
49
|
+
* 清理值以便序列化
|
|
50
|
+
*/
|
|
51
|
+
private sanitizeValue;
|
|
52
|
+
/**
|
|
53
|
+
* 檢查是否為 RxJS Observable
|
|
54
|
+
*/
|
|
55
|
+
private isObservable;
|
|
56
|
+
/**
|
|
57
|
+
* 獲取父組件資訊
|
|
58
|
+
*/
|
|
59
|
+
private getParentInfo;
|
|
60
|
+
/**
|
|
61
|
+
* 找到組件的 host 元素
|
|
62
|
+
*/
|
|
63
|
+
private findComponentHost;
|
|
64
|
+
/**
|
|
65
|
+
* 計算 DOM 路徑
|
|
66
|
+
*/
|
|
67
|
+
private computeDomPath;
|
|
68
|
+
/**
|
|
69
|
+
* 提取關鍵 computed styles
|
|
70
|
+
*/
|
|
71
|
+
private extractComputedStyles;
|
|
72
|
+
/**
|
|
73
|
+
* 生成唯一 ID
|
|
74
|
+
*/
|
|
75
|
+
private generateUid;
|
|
76
|
+
/**
|
|
77
|
+
* 獲取元素的祖先鏈(從當前元素到根)
|
|
78
|
+
* 用於層級麵包屑導航
|
|
79
|
+
*
|
|
80
|
+
* @param element - 起始 DOM 元素
|
|
81
|
+
* @param maxDepth - 最大深度(預設 10,避免過長)
|
|
82
|
+
* @returns ComponentNode 陣列,索引 0 為當前元素,依次向上
|
|
83
|
+
*/
|
|
84
|
+
getAncestorChain(element: HTMLElement, maxDepth?: number): ComponentNode[];
|
|
85
|
+
/**
|
|
86
|
+
* 簡化版:僅獲取祖先元素的基本資訊(用於麵包屑顯示)
|
|
87
|
+
* 效能更佳,不需要完整的 ComponentNode
|
|
88
|
+
*
|
|
89
|
+
* @param element - 起始 DOM 元素
|
|
90
|
+
* @param maxDepth - 最大深度
|
|
91
|
+
* @returns 簡化的祖先資訊陣列
|
|
92
|
+
*/
|
|
93
|
+
getAncestorBreadcrumbs(element: HTMLElement, maxDepth?: number): AncestorBreadcrumb[];
|
|
94
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<ComponentWalkerService, never>;
|
|
95
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<ComponentWalkerService>;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* 祖先麵包屑項目(輕量版)
|
|
99
|
+
*/
|
|
100
|
+
export interface AncestorBreadcrumb {
|
|
101
|
+
/** 顯示標籤 */
|
|
102
|
+
label: string;
|
|
103
|
+
/** 對應的 DOM 元素 */
|
|
104
|
+
element: HTMLElement;
|
|
105
|
+
/** 是否為 Angular 組件 */
|
|
106
|
+
isComponent: boolean;
|
|
107
|
+
/** 深度(0 = 當前元素) */
|
|
108
|
+
depth: number;
|
|
109
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
/**
|
|
3
|
+
* DataSanitizerService
|
|
4
|
+
*
|
|
5
|
+
* 資料清洗服務:將組件資料轉換為 AI 友好的格式
|
|
6
|
+
*
|
|
7
|
+
* 清洗規則:
|
|
8
|
+
* 1. 移除 Angular 內部屬性 (__ngContext__, ɵcmp 等)
|
|
9
|
+
* 2. 將 Function 類型轉為描述字串
|
|
10
|
+
* 3. 過濾 Observable/Subject(只保留類型名稱)
|
|
11
|
+
* 4. 過濾大型資料(Base64 > 1KB)
|
|
12
|
+
* 5. 避免循環引用
|
|
13
|
+
*/
|
|
14
|
+
export declare class DataSanitizerService {
|
|
15
|
+
/** Angular 內部屬性前綴 */
|
|
16
|
+
private readonly INTERNAL_PREFIXES;
|
|
17
|
+
/** 最大字串長度 */
|
|
18
|
+
private readonly MAX_STRING_LENGTH;
|
|
19
|
+
/** 最大陣列長度 */
|
|
20
|
+
private readonly MAX_ARRAY_LENGTH;
|
|
21
|
+
/** 最大物件深度 */
|
|
22
|
+
private readonly MAX_DEPTH;
|
|
23
|
+
/**
|
|
24
|
+
* 清洗單一值
|
|
25
|
+
*/
|
|
26
|
+
sanitize(value: unknown, depth?: number): unknown;
|
|
27
|
+
/**
|
|
28
|
+
* 清洗字串
|
|
29
|
+
*/
|
|
30
|
+
private sanitizeString;
|
|
31
|
+
/**
|
|
32
|
+
* 清洗函數
|
|
33
|
+
*/
|
|
34
|
+
private sanitizeFunction;
|
|
35
|
+
/**
|
|
36
|
+
* 清洗陣列
|
|
37
|
+
*/
|
|
38
|
+
private sanitizeArray;
|
|
39
|
+
/**
|
|
40
|
+
* 清洗物件
|
|
41
|
+
*/
|
|
42
|
+
private sanitizeObject;
|
|
43
|
+
/**
|
|
44
|
+
* 檢查是否為內部屬性
|
|
45
|
+
*/
|
|
46
|
+
private isInternalProperty;
|
|
47
|
+
/**
|
|
48
|
+
* 檢查是否為 RxJS Observable
|
|
49
|
+
*/
|
|
50
|
+
private isObservable;
|
|
51
|
+
/**
|
|
52
|
+
* 檢查是否為 RxJS Subject
|
|
53
|
+
*/
|
|
54
|
+
private isSubject;
|
|
55
|
+
/**
|
|
56
|
+
* 檢查是否為 Promise
|
|
57
|
+
*/
|
|
58
|
+
private isPromise;
|
|
59
|
+
/**
|
|
60
|
+
* 批量清洗 Record
|
|
61
|
+
*/
|
|
62
|
+
sanitizeRecord(record: Record<string, unknown>): Record<string, unknown>;
|
|
63
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<DataSanitizerService, never>;
|
|
64
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<DataSanitizerService>;
|
|
65
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { HttpClient } from '@angular/common/http';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { UserAnnotation } from '../models/component-node.interface';
|
|
4
|
+
import * as i0 from "@angular/core";
|
|
5
|
+
export interface McpStatus {
|
|
6
|
+
connected: boolean;
|
|
7
|
+
sessionId?: string;
|
|
8
|
+
lastError?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface McpAnnotation extends UserAnnotation {
|
|
11
|
+
id: string;
|
|
12
|
+
sessionId: string;
|
|
13
|
+
url: string;
|
|
14
|
+
status: 'pending' | 'acknowledged' | 'resolved' | 'dismissed';
|
|
15
|
+
}
|
|
16
|
+
export declare class McpService {
|
|
17
|
+
private http;
|
|
18
|
+
private readonly API_URL;
|
|
19
|
+
private _status;
|
|
20
|
+
status$: Observable<McpStatus>;
|
|
21
|
+
private _annotations;
|
|
22
|
+
annotations$: Observable<McpAnnotation[]>;
|
|
23
|
+
constructor(http: HttpClient);
|
|
24
|
+
/**
|
|
25
|
+
* Check if the MCP server is reachable
|
|
26
|
+
*/
|
|
27
|
+
checkConnection(): Promise<boolean>;
|
|
28
|
+
/**
|
|
29
|
+
* Establish a new session or restore existing one
|
|
30
|
+
*/
|
|
31
|
+
connect(existingSessionId?: string): Promise<string>;
|
|
32
|
+
/**
|
|
33
|
+
* Send an annotation to the MCP server
|
|
34
|
+
*/
|
|
35
|
+
sendAnnotation(annotation: UserAnnotation): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Poll for updates (e.g., resolve/dismiss status from agent)
|
|
38
|
+
*/
|
|
39
|
+
private startPolling;
|
|
40
|
+
private updateStatus;
|
|
41
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<McpService, never>;
|
|
42
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<McpService>;
|
|
43
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { ComponentNode, UserAnnotation, OutputDetail } from '../models/component-node.interface';
|
|
2
|
+
import { DataSanitizerService } from './data-sanitizer.service';
|
|
3
|
+
import * as i0 from "@angular/core";
|
|
4
|
+
/**
|
|
5
|
+
* PromptGeneratorService
|
|
6
|
+
*
|
|
7
|
+
* 提示生成服務:根據 OutputDetail 模式生成不同詳細程度的輸出
|
|
8
|
+
*
|
|
9
|
+
* Modes:
|
|
10
|
+
* - compact: 最簡潔,只有元素類型和 feedback
|
|
11
|
+
* - standard: 標準,包含 DOM Path、Position、基本 Styles
|
|
12
|
+
* - detailed: 詳細,包含所有屬性和上下文
|
|
13
|
+
* - forensic: 完整,包含所有可用資訊(舊版相容)
|
|
14
|
+
*/
|
|
15
|
+
export declare class PromptGeneratorService {
|
|
16
|
+
private dataSanitizer;
|
|
17
|
+
constructor(dataSanitizer: DataSanitizerService);
|
|
18
|
+
/**
|
|
19
|
+
* 生成 Page Feedback 輸出(多標記)
|
|
20
|
+
*/
|
|
21
|
+
generatePageFeedback(markers: Array<{
|
|
22
|
+
target: ComponentNode;
|
|
23
|
+
intent: string;
|
|
24
|
+
}>, options: {
|
|
25
|
+
outputDetail: OutputDetail;
|
|
26
|
+
pageUrl?: string;
|
|
27
|
+
viewport?: {
|
|
28
|
+
width: number;
|
|
29
|
+
height: number;
|
|
30
|
+
};
|
|
31
|
+
userAgent?: string;
|
|
32
|
+
timestamp?: number;
|
|
33
|
+
}): string;
|
|
34
|
+
/**
|
|
35
|
+
* 生成單個標記的輸出
|
|
36
|
+
*/
|
|
37
|
+
generateMarkerOutput(node: ComponentNode, intent: string, index: number, outputDetail: OutputDetail): string;
|
|
38
|
+
/**
|
|
39
|
+
* Compact 模式:最簡潔
|
|
40
|
+
*/
|
|
41
|
+
private generateCompact;
|
|
42
|
+
/**
|
|
43
|
+
* Standard 模式:標準
|
|
44
|
+
*/
|
|
45
|
+
private generateStandard;
|
|
46
|
+
/**
|
|
47
|
+
* Detailed 模式:詳細
|
|
48
|
+
*/
|
|
49
|
+
private generateDetailed;
|
|
50
|
+
/**
|
|
51
|
+
* Forensic 模式:完整(舊版相容格式)
|
|
52
|
+
*/
|
|
53
|
+
private generateForensic;
|
|
54
|
+
/**
|
|
55
|
+
* 生成完整的 AI Prompt(舊版兼容)
|
|
56
|
+
*/
|
|
57
|
+
generatePrompt(annotation: UserAnnotation): string;
|
|
58
|
+
/**
|
|
59
|
+
* 僅生成組件資訊(舊版兼容)
|
|
60
|
+
*/
|
|
61
|
+
generateComponentInfo(node: ComponentNode): string;
|
|
62
|
+
private getPathFromUrl;
|
|
63
|
+
private getElementType;
|
|
64
|
+
private formatDomPath;
|
|
65
|
+
private extractCssClasses;
|
|
66
|
+
private extractKeyStyles;
|
|
67
|
+
private formatAllStyles;
|
|
68
|
+
private getTextContent;
|
|
69
|
+
private getAccessibility;
|
|
70
|
+
private getNearbyElements;
|
|
71
|
+
private escapeMarkdown;
|
|
72
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<PromptGeneratorService, never>;
|
|
73
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<PromptGeneratorService>;
|
|
74
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ng-directive-zero",
|
|
3
|
+
"version": "1.0.5",
|
|
4
|
+
"description": "Angular implementation of Agentation",
|
|
5
|
+
"author": "Andy Chou",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"angular",
|
|
9
|
+
"agentation",
|
|
10
|
+
"annotation"
|
|
11
|
+
],
|
|
12
|
+
"peerDependencies": {
|
|
13
|
+
"@angular/common": ">=14.0.0 <21.0.0",
|
|
14
|
+
"@angular/core": ">=14.0.0 <21.0.0"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"tslib": "^2.3.0"
|
|
18
|
+
},
|
|
19
|
+
"sideEffects": false,
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/ivan9527945/ng-directive-zero"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://github.com/ivan9527945/ng-directive-zero",
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/ivan9527945/ng-directive-zero/issues"
|
|
27
|
+
},
|
|
28
|
+
"module": "fesm2022/ng-directive-zero.mjs",
|
|
29
|
+
"typings": "index.d.ts",
|
|
30
|
+
"exports": {
|
|
31
|
+
"./package.json": {
|
|
32
|
+
"default": "./package.json"
|
|
33
|
+
},
|
|
34
|
+
".": {
|
|
35
|
+
"types": "./index.d.ts",
|
|
36
|
+
"default": "./fesm2022/ng-directive-zero.mjs"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
package/public-api.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from './lib/ng-directive-zero.module';
|
|
2
|
+
export * from './lib/models/component-node.interface';
|
|
3
|
+
export * from './lib/services/component-walker.service';
|
|
4
|
+
export * from './lib/services/data-sanitizer.service';
|
|
5
|
+
export * from './lib/services/prompt-generator.service';
|
|
6
|
+
export * from './lib/services/mcp.service';
|
|
7
|
+
export * from './lib/components/overlay/overlay.component';
|
|
8
|
+
export * from './lib/components/annotation-panel/annotation-panel.component';
|
|
9
|
+
export * from './lib/components/toolbar/toolbar.component';
|
|
10
|
+
export * from './lib/components/settings-panel/settings-panel.component';
|
|
11
|
+
export * from './lib/components/markers-panel/markers-panel.component';
|
|
12
|
+
export * from './lib/components/inline-editor/inline-editor.component';
|
|
13
|
+
export * from './lib/components/agentation/agentation.component';
|