@reconcrap/boss-recommend-mcp 1.3.32 → 1.3.33

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,103 +1,103 @@
1
- import CDP from 'chrome-remote-interface';
2
-
3
- export class ChromeClient {
4
- constructor(port = 9222) {
5
- this.port = port;
6
- this.client = null;
7
- }
8
-
9
- async connect(targetMatcher) {
10
- const targets = await CDP.List({ port: this.port });
11
- const target = targets.find((item) => targetMatcher(item));
12
-
13
- if (!target) {
14
- throw new Error('Could not find a matching Chrome tab. Make sure Boss chat is open.');
15
- }
16
-
17
- this.client = await CDP({ port: this.port, target });
18
- const { Runtime, DOM, Page, Input, Network } = this.client;
19
-
20
- await Promise.all([
21
- Runtime.enable(),
22
- DOM.enable(),
23
- Page.enable(),
24
- Network && typeof Network.enable === 'function' ? Network.enable() : Promise.resolve(),
25
- ]);
26
-
27
- this.Runtime = Runtime;
28
- this.DOM = DOM;
29
- this.Page = Page;
30
- this.Input = Input;
31
- this.Network = Network || null;
32
-
33
- return target;
34
- }
35
-
36
- async evaluate(expression) {
37
- const result = await this.Runtime.evaluate({
38
- expression,
39
- returnByValue: true,
40
- awaitPromise: true,
41
- });
42
-
43
- if (result.exceptionDetails) {
44
- const description =
45
- result.exceptionDetails.exception?.description ||
46
- result.exceptionDetails.text ||
47
- 'Chrome evaluation failed';
48
- throw new Error(description);
49
- }
50
-
51
- return result.result?.value;
52
- }
53
-
54
- async callFunction(fn, arg = null) {
55
- const expression = `(${fn.toString()})(${JSON.stringify(arg)})`;
56
- return this.evaluate(expression);
57
- }
58
-
59
- async pressEnter() {
60
- const payload = {
61
- windowsVirtualKeyCode: 13,
62
- nativeVirtualKeyCode: 13,
63
- code: 'Enter',
64
- key: 'Enter',
65
- unmodifiedText: '\r',
66
- text: '\r',
67
- };
68
-
69
- await this.Input.dispatchKeyEvent({
70
- type: 'keyDown',
71
- ...payload,
72
- });
73
- await this.Input.dispatchKeyEvent({
74
- type: 'keyUp',
75
- ...payload,
76
- });
77
- }
78
-
79
- async pressEscape() {
80
- const payload = {
81
- windowsVirtualKeyCode: 27,
82
- nativeVirtualKeyCode: 27,
83
- code: 'Escape',
84
- key: 'Escape',
85
- };
86
-
87
- await this.Input.dispatchKeyEvent({
88
- type: 'keyDown',
89
- ...payload,
90
- });
91
- await this.Input.dispatchKeyEvent({
92
- type: 'keyUp',
93
- ...payload,
94
- });
95
- }
96
-
97
- async close() {
98
- if (this.client) {
99
- await this.client.close();
100
- this.client = null;
101
- }
102
- }
103
- }
1
+ import CDP from 'chrome-remote-interface';
2
+
3
+ export class ChromeClient {
4
+ constructor(port = 9222) {
5
+ this.port = port;
6
+ this.client = null;
7
+ }
8
+
9
+ async connect(targetMatcher) {
10
+ const targets = await CDP.List({ port: this.port });
11
+ const target = targets.find((item) => targetMatcher(item));
12
+
13
+ if (!target) {
14
+ throw new Error('Could not find a matching Chrome tab. Make sure Boss chat is open.');
15
+ }
16
+
17
+ this.client = await CDP({ port: this.port, target });
18
+ const { Runtime, DOM, Page, Input, Network } = this.client;
19
+
20
+ await Promise.all([
21
+ Runtime.enable(),
22
+ DOM.enable(),
23
+ Page.enable(),
24
+ Network && typeof Network.enable === 'function' ? Network.enable() : Promise.resolve(),
25
+ ]);
26
+
27
+ this.Runtime = Runtime;
28
+ this.DOM = DOM;
29
+ this.Page = Page;
30
+ this.Input = Input;
31
+ this.Network = Network || null;
32
+
33
+ return target;
34
+ }
35
+
36
+ async evaluate(expression) {
37
+ const result = await this.Runtime.evaluate({
38
+ expression,
39
+ returnByValue: true,
40
+ awaitPromise: true,
41
+ });
42
+
43
+ if (result.exceptionDetails) {
44
+ const description =
45
+ result.exceptionDetails.exception?.description ||
46
+ result.exceptionDetails.text ||
47
+ 'Chrome evaluation failed';
48
+ throw new Error(description);
49
+ }
50
+
51
+ return result.result?.value;
52
+ }
53
+
54
+ async callFunction(fn, arg = null) {
55
+ const expression = `(${fn.toString()})(${JSON.stringify(arg)})`;
56
+ return this.evaluate(expression);
57
+ }
58
+
59
+ async pressEnter() {
60
+ const payload = {
61
+ windowsVirtualKeyCode: 13,
62
+ nativeVirtualKeyCode: 13,
63
+ code: 'Enter',
64
+ key: 'Enter',
65
+ unmodifiedText: '\r',
66
+ text: '\r',
67
+ };
68
+
69
+ await this.Input.dispatchKeyEvent({
70
+ type: 'keyDown',
71
+ ...payload,
72
+ });
73
+ await this.Input.dispatchKeyEvent({
74
+ type: 'keyUp',
75
+ ...payload,
76
+ });
77
+ }
78
+
79
+ async pressEscape() {
80
+ const payload = {
81
+ windowsVirtualKeyCode: 27,
82
+ nativeVirtualKeyCode: 27,
83
+ code: 'Escape',
84
+ key: 'Escape',
85
+ };
86
+
87
+ await this.Input.dispatchKeyEvent({
88
+ type: 'keyDown',
89
+ ...payload,
90
+ });
91
+ await this.Input.dispatchKeyEvent({
92
+ type: 'keyUp',
93
+ ...payload,
94
+ });
95
+ }
96
+
97
+ async close() {
98
+ if (this.client) {
99
+ await this.client.close();
100
+ this.client = null;
101
+ }
102
+ }
103
+ }