@giselles-ai/browser-tool 0.1.0
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/LICENSE +201 -0
- package/dist/dom/index.d.ts +38 -0
- package/dist/dom/index.js +336 -0
- package/dist/index.d.ts +281 -0
- package/dist/index.js +114 -0
- package/dist/mcp-server/index.d.ts +2 -0
- package/dist/mcp-server/index.js +342 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
type FieldKind = "text" | "textarea" | "select" | "checkbox" | "radio";
|
|
2
|
+
type SnapshotField = {
|
|
3
|
+
fieldId: string;
|
|
4
|
+
selector: string;
|
|
5
|
+
kind: FieldKind;
|
|
6
|
+
label: string;
|
|
7
|
+
name?: string;
|
|
8
|
+
required: boolean;
|
|
9
|
+
placeholder?: string;
|
|
10
|
+
currentValue: string | boolean;
|
|
11
|
+
options?: string[];
|
|
12
|
+
};
|
|
13
|
+
type FillAction = {
|
|
14
|
+
action: "fill";
|
|
15
|
+
fieldId: string;
|
|
16
|
+
value: string;
|
|
17
|
+
};
|
|
18
|
+
type ClickAction = {
|
|
19
|
+
action: "click";
|
|
20
|
+
fieldId: string;
|
|
21
|
+
};
|
|
22
|
+
type SelectAction = {
|
|
23
|
+
action: "select";
|
|
24
|
+
fieldId: string;
|
|
25
|
+
value: string;
|
|
26
|
+
};
|
|
27
|
+
type BrowserToolAction = FillAction | ClickAction | SelectAction;
|
|
28
|
+
type ExecutionReport = {
|
|
29
|
+
applied: number;
|
|
30
|
+
skipped: number;
|
|
31
|
+
warnings: string[];
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
declare function execute(actions: BrowserToolAction[], fields: SnapshotField[], root?: ParentNode): ExecutionReport;
|
|
35
|
+
|
|
36
|
+
declare function snapshot(root?: ParentNode): SnapshotField[];
|
|
37
|
+
|
|
38
|
+
export { execute, snapshot };
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
// src/dom/executor.ts
|
|
2
|
+
function escapeForSelector(value) {
|
|
3
|
+
if (typeof CSS !== "undefined" && typeof CSS.escape === "function") {
|
|
4
|
+
return CSS.escape(value);
|
|
5
|
+
}
|
|
6
|
+
return value.replace(/(["\\])/g, "\\$1");
|
|
7
|
+
}
|
|
8
|
+
function safeQuery(root, selector) {
|
|
9
|
+
try {
|
|
10
|
+
return root.querySelector(selector);
|
|
11
|
+
} catch {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function resolveElement(actionFieldId, fields, root) {
|
|
16
|
+
if (actionFieldId.startsWith("bt:")) {
|
|
17
|
+
const browserToolId = actionFieldId.slice("bt:".length);
|
|
18
|
+
const direct = safeQuery(
|
|
19
|
+
root,
|
|
20
|
+
`[data-browser-tool-id="${escapeForSelector(browserToolId)}"]`
|
|
21
|
+
);
|
|
22
|
+
if (direct) {
|
|
23
|
+
return direct;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (actionFieldId.startsWith("css:")) {
|
|
27
|
+
const selector = actionFieldId.slice("css:".length);
|
|
28
|
+
const direct = safeQuery(root, selector);
|
|
29
|
+
if (direct) {
|
|
30
|
+
return direct;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const field = fields.find((candidate) => candidate.fieldId === actionFieldId);
|
|
34
|
+
if (!field) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
return safeQuery(root, field.selector);
|
|
38
|
+
}
|
|
39
|
+
function setNativeValue(target, value) {
|
|
40
|
+
const prototype = target instanceof HTMLTextAreaElement ? HTMLTextAreaElement.prototype : HTMLInputElement.prototype;
|
|
41
|
+
const descriptor = Object.getOwnPropertyDescriptor(prototype, "value");
|
|
42
|
+
if (descriptor?.set) {
|
|
43
|
+
descriptor.set.call(target, value);
|
|
44
|
+
} else {
|
|
45
|
+
target.value = value;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function emitInputEvents(target) {
|
|
49
|
+
target.dispatchEvent(new Event("input", { bubbles: true }));
|
|
50
|
+
target.dispatchEvent(new Event("change", { bubbles: true }));
|
|
51
|
+
}
|
|
52
|
+
function execute(actions, fields, root = document) {
|
|
53
|
+
const report = {
|
|
54
|
+
applied: 0,
|
|
55
|
+
skipped: 0,
|
|
56
|
+
warnings: []
|
|
57
|
+
};
|
|
58
|
+
for (const action of actions) {
|
|
59
|
+
const element = resolveElement(action.fieldId, fields, root);
|
|
60
|
+
if (!element) {
|
|
61
|
+
report.skipped += 1;
|
|
62
|
+
report.warnings.push(`Element not found for fieldId: ${action.fieldId}`);
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (action.action === "click") {
|
|
66
|
+
if (element instanceof HTMLElement) {
|
|
67
|
+
element.click();
|
|
68
|
+
report.applied += 1;
|
|
69
|
+
} else {
|
|
70
|
+
report.skipped += 1;
|
|
71
|
+
report.warnings.push(
|
|
72
|
+
`Click target is not an HTMLElement: ${action.fieldId}`
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (action.action === "fill") {
|
|
78
|
+
if (element instanceof HTMLInputElement) {
|
|
79
|
+
const type = element.type.toLowerCase();
|
|
80
|
+
if (type === "checkbox" || type === "radio") {
|
|
81
|
+
report.skipped += 1;
|
|
82
|
+
report.warnings.push(
|
|
83
|
+
`fill is not supported for ${type}: ${action.fieldId}`
|
|
84
|
+
);
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
setNativeValue(element, action.value);
|
|
88
|
+
emitInputEvents(element);
|
|
89
|
+
report.applied += 1;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (element instanceof HTMLTextAreaElement) {
|
|
93
|
+
setNativeValue(element, action.value);
|
|
94
|
+
emitInputEvents(element);
|
|
95
|
+
report.applied += 1;
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (element instanceof HTMLSelectElement) {
|
|
99
|
+
report.skipped += 1;
|
|
100
|
+
report.warnings.push(
|
|
101
|
+
`fill is not supported for select: ${action.fieldId}`
|
|
102
|
+
);
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
report.skipped += 1;
|
|
106
|
+
report.warnings.push(`Unsupported fill target: ${action.fieldId}`);
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (!(element instanceof HTMLSelectElement)) {
|
|
110
|
+
report.skipped += 1;
|
|
111
|
+
report.warnings.push(
|
|
112
|
+
`select action target is not a <select>: ${action.fieldId}`
|
|
113
|
+
);
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
const matchedOption = Array.from(element.options).find(
|
|
117
|
+
(option) => option.value === action.value || option.text.trim() === action.value
|
|
118
|
+
);
|
|
119
|
+
const nextValue = matchedOption ? matchedOption.value : action.value;
|
|
120
|
+
element.value = nextValue;
|
|
121
|
+
if (element.value !== nextValue) {
|
|
122
|
+
report.skipped += 1;
|
|
123
|
+
report.warnings.push(
|
|
124
|
+
`Option not found for select action: ${action.fieldId}`
|
|
125
|
+
);
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
emitInputEvents(element);
|
|
129
|
+
report.applied += 1;
|
|
130
|
+
}
|
|
131
|
+
return report;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// src/dom/snapshot.ts
|
|
135
|
+
var EXCLUDED_INPUT_TYPES = /* @__PURE__ */ new Set([
|
|
136
|
+
"hidden",
|
|
137
|
+
"submit",
|
|
138
|
+
"button",
|
|
139
|
+
"file",
|
|
140
|
+
"reset",
|
|
141
|
+
"image"
|
|
142
|
+
]);
|
|
143
|
+
function normalizeText(input) {
|
|
144
|
+
if (!input) {
|
|
145
|
+
return "";
|
|
146
|
+
}
|
|
147
|
+
return input.replace(/\s+/g, " ").trim();
|
|
148
|
+
}
|
|
149
|
+
function escapeForSelector2(value) {
|
|
150
|
+
if (typeof CSS !== "undefined" && typeof CSS.escape === "function") {
|
|
151
|
+
return CSS.escape(value);
|
|
152
|
+
}
|
|
153
|
+
return value.replace(/(["\\])/g, "\\$1");
|
|
154
|
+
}
|
|
155
|
+
function isElementVisible(element) {
|
|
156
|
+
if (!(element instanceof HTMLElement)) {
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
if (element.hidden || element.getAttribute("aria-hidden") === "true") {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
const style = window.getComputedStyle(element);
|
|
163
|
+
if (style.display === "none" || style.visibility === "hidden") {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
function inferKind(element) {
|
|
169
|
+
if (element instanceof HTMLTextAreaElement) {
|
|
170
|
+
return "textarea";
|
|
171
|
+
}
|
|
172
|
+
if (element instanceof HTMLSelectElement) {
|
|
173
|
+
return "select";
|
|
174
|
+
}
|
|
175
|
+
if (element instanceof HTMLInputElement) {
|
|
176
|
+
const type = (element.type || "text").toLowerCase();
|
|
177
|
+
if (EXCLUDED_INPUT_TYPES.has(type)) {
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
if (type === "checkbox") {
|
|
181
|
+
return "checkbox";
|
|
182
|
+
}
|
|
183
|
+
if (type === "radio") {
|
|
184
|
+
return "radio";
|
|
185
|
+
}
|
|
186
|
+
return "text";
|
|
187
|
+
}
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
function queryLabelByFor(element) {
|
|
191
|
+
const id = element.getAttribute("id");
|
|
192
|
+
if (!id) {
|
|
193
|
+
return "";
|
|
194
|
+
}
|
|
195
|
+
const label = document.querySelector(`label[for="${escapeForSelector2(id)}"]`);
|
|
196
|
+
return normalizeText(label?.textContent);
|
|
197
|
+
}
|
|
198
|
+
function queryAriaLabelledby(element) {
|
|
199
|
+
const labelledby = normalizeText(element.getAttribute("aria-labelledby"));
|
|
200
|
+
if (!labelledby) {
|
|
201
|
+
return "";
|
|
202
|
+
}
|
|
203
|
+
const ids = labelledby.split(/\s+/).filter(Boolean);
|
|
204
|
+
const parts = ids.map((id) => document.getElementById(id)).map((node) => normalizeText(node?.textContent)).filter(Boolean);
|
|
205
|
+
return normalizeText(parts.join(" "));
|
|
206
|
+
}
|
|
207
|
+
function resolveLabel(element) {
|
|
208
|
+
const fromFor = queryLabelByFor(element);
|
|
209
|
+
if (fromFor) {
|
|
210
|
+
return fromFor;
|
|
211
|
+
}
|
|
212
|
+
const fromAriaLabel = normalizeText(element.getAttribute("aria-label"));
|
|
213
|
+
if (fromAriaLabel) {
|
|
214
|
+
return fromAriaLabel;
|
|
215
|
+
}
|
|
216
|
+
const fromAriaLabelledBy = queryAriaLabelledby(element);
|
|
217
|
+
if (fromAriaLabelledBy) {
|
|
218
|
+
return fromAriaLabelledBy;
|
|
219
|
+
}
|
|
220
|
+
const fromAncestorLabel = normalizeText(
|
|
221
|
+
element.closest("label")?.textContent
|
|
222
|
+
);
|
|
223
|
+
if (fromAncestorLabel) {
|
|
224
|
+
return fromAncestorLabel;
|
|
225
|
+
}
|
|
226
|
+
return normalizeText(element.getAttribute("name")) || normalizeText(element.getAttribute("id")) || "unnamed-field";
|
|
227
|
+
}
|
|
228
|
+
function selectorIsUnique(selector, element) {
|
|
229
|
+
try {
|
|
230
|
+
const nodes = document.querySelectorAll(selector);
|
|
231
|
+
return nodes.length === 1 && nodes[0] === element;
|
|
232
|
+
} catch {
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
function buildUniqueCssSelector(element) {
|
|
237
|
+
const dataBrowserToolId = element.getAttribute("data-browser-tool-id");
|
|
238
|
+
if (dataBrowserToolId) {
|
|
239
|
+
return `[data-browser-tool-id="${escapeForSelector2(dataBrowserToolId)}"]`;
|
|
240
|
+
}
|
|
241
|
+
const id = element.getAttribute("id");
|
|
242
|
+
if (id) {
|
|
243
|
+
return `#${escapeForSelector2(id)}`;
|
|
244
|
+
}
|
|
245
|
+
const segments = [];
|
|
246
|
+
let node = element;
|
|
247
|
+
while (node && node !== document.documentElement) {
|
|
248
|
+
const tag = node.tagName.toLowerCase();
|
|
249
|
+
const currentTagName = node.tagName;
|
|
250
|
+
const parentElement = node.parentElement;
|
|
251
|
+
if (!parentElement) {
|
|
252
|
+
segments.unshift(tag);
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
const siblingCandidates = Array.from(parentElement.children).filter(
|
|
256
|
+
(candidate) => candidate.tagName === currentTagName
|
|
257
|
+
);
|
|
258
|
+
const nth = siblingCandidates.indexOf(node) + 1;
|
|
259
|
+
segments.unshift(`${tag}:nth-of-type(${nth})`);
|
|
260
|
+
const candidateSelector = segments.join(" > ");
|
|
261
|
+
if (selectorIsUnique(candidateSelector, element)) {
|
|
262
|
+
return candidateSelector;
|
|
263
|
+
}
|
|
264
|
+
node = parentElement;
|
|
265
|
+
}
|
|
266
|
+
return segments.join(" > ") || element.tagName.toLowerCase();
|
|
267
|
+
}
|
|
268
|
+
function readCurrentValue(element) {
|
|
269
|
+
if (element instanceof HTMLInputElement) {
|
|
270
|
+
const type = (element.type || "text").toLowerCase();
|
|
271
|
+
if (type === "checkbox" || type === "radio") {
|
|
272
|
+
return element.checked;
|
|
273
|
+
}
|
|
274
|
+
return element.value;
|
|
275
|
+
}
|
|
276
|
+
if (element instanceof HTMLTextAreaElement || element instanceof HTMLSelectElement) {
|
|
277
|
+
return element.value;
|
|
278
|
+
}
|
|
279
|
+
return "";
|
|
280
|
+
}
|
|
281
|
+
function readOptions(element) {
|
|
282
|
+
if (element instanceof HTMLSelectElement) {
|
|
283
|
+
const options = Array.from(element.options).map((option) => normalizeText(option.textContent) || option.value).filter(Boolean);
|
|
284
|
+
return options.length > 0 ? options : void 0;
|
|
285
|
+
}
|
|
286
|
+
if (element instanceof HTMLInputElement && element.type === "radio" && element.name) {
|
|
287
|
+
const selector = `input[type="radio"][name="${escapeForSelector2(element.name)}"]`;
|
|
288
|
+
const options = Array.from(document.querySelectorAll(selector)).map((node) => node instanceof HTMLInputElement ? node.value : "").filter(Boolean);
|
|
289
|
+
return options.length > 0 ? options : void 0;
|
|
290
|
+
}
|
|
291
|
+
return void 0;
|
|
292
|
+
}
|
|
293
|
+
function snapshot(root) {
|
|
294
|
+
const queryRoot = root ?? document;
|
|
295
|
+
const candidates = Array.from(
|
|
296
|
+
queryRoot.querySelectorAll("input, textarea, select")
|
|
297
|
+
);
|
|
298
|
+
const seenFieldIds = /* @__PURE__ */ new Set();
|
|
299
|
+
const fields = [];
|
|
300
|
+
for (const element of candidates) {
|
|
301
|
+
if (!isElementVisible(element)) {
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
const kind = inferKind(element);
|
|
305
|
+
if (!kind) {
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
const dataBrowserToolId = normalizeText(
|
|
309
|
+
element.getAttribute("data-browser-tool-id")
|
|
310
|
+
);
|
|
311
|
+
const selector = dataBrowserToolId ? `[data-browser-tool-id="${escapeForSelector2(dataBrowserToolId)}"]` : buildUniqueCssSelector(element);
|
|
312
|
+
const fieldId = dataBrowserToolId ? `bt:${dataBrowserToolId}` : `css:${selector}`;
|
|
313
|
+
if (seenFieldIds.has(fieldId)) {
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
seenFieldIds.add(fieldId);
|
|
317
|
+
const required = element.hasAttribute("required") || element.getAttribute("aria-required") === "true";
|
|
318
|
+
const placeholder = element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement ? normalizeText(element.placeholder) || void 0 : void 0;
|
|
319
|
+
fields.push({
|
|
320
|
+
fieldId,
|
|
321
|
+
selector,
|
|
322
|
+
kind,
|
|
323
|
+
label: resolveLabel(element),
|
|
324
|
+
name: normalizeText(element.getAttribute("name")) || void 0,
|
|
325
|
+
required,
|
|
326
|
+
placeholder,
|
|
327
|
+
currentValue: readCurrentValue(element),
|
|
328
|
+
options: readOptions(element)
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
return fields;
|
|
332
|
+
}
|
|
333
|
+
export {
|
|
334
|
+
execute,
|
|
335
|
+
snapshot
|
|
336
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
type FieldKind = "text" | "textarea" | "select" | "checkbox" | "radio";
|
|
4
|
+
type SnapshotField = {
|
|
5
|
+
fieldId: string;
|
|
6
|
+
selector: string;
|
|
7
|
+
kind: FieldKind;
|
|
8
|
+
label: string;
|
|
9
|
+
name?: string;
|
|
10
|
+
required: boolean;
|
|
11
|
+
placeholder?: string;
|
|
12
|
+
currentValue: string | boolean;
|
|
13
|
+
options?: string[];
|
|
14
|
+
};
|
|
15
|
+
type FillAction = {
|
|
16
|
+
action: "fill";
|
|
17
|
+
fieldId: string;
|
|
18
|
+
value: string;
|
|
19
|
+
};
|
|
20
|
+
type ClickAction = {
|
|
21
|
+
action: "click";
|
|
22
|
+
fieldId: string;
|
|
23
|
+
};
|
|
24
|
+
type SelectAction = {
|
|
25
|
+
action: "select";
|
|
26
|
+
fieldId: string;
|
|
27
|
+
value: string;
|
|
28
|
+
};
|
|
29
|
+
type BrowserToolAction = FillAction | ClickAction | SelectAction;
|
|
30
|
+
type ExecutionReport = {
|
|
31
|
+
applied: number;
|
|
32
|
+
skipped: number;
|
|
33
|
+
warnings: string[];
|
|
34
|
+
};
|
|
35
|
+
type BrowserToolStatus = "idle" | "snapshotting" | "planning" | "ready" | "applying" | "error";
|
|
36
|
+
type BridgeErrorCode = "UNAUTHORIZED" | "NO_BROWSER" | "TIMEOUT" | "INVALID_RESPONSE" | "NOT_FOUND" | "INTERNAL";
|
|
37
|
+
declare const fieldKindSchema: z.ZodEnum<{
|
|
38
|
+
text: "text";
|
|
39
|
+
textarea: "textarea";
|
|
40
|
+
select: "select";
|
|
41
|
+
checkbox: "checkbox";
|
|
42
|
+
radio: "radio";
|
|
43
|
+
}>;
|
|
44
|
+
declare const snapshotFieldSchema: z.ZodObject<{
|
|
45
|
+
fieldId: z.ZodString;
|
|
46
|
+
selector: z.ZodString;
|
|
47
|
+
kind: z.ZodEnum<{
|
|
48
|
+
text: "text";
|
|
49
|
+
textarea: "textarea";
|
|
50
|
+
select: "select";
|
|
51
|
+
checkbox: "checkbox";
|
|
52
|
+
radio: "radio";
|
|
53
|
+
}>;
|
|
54
|
+
label: z.ZodString;
|
|
55
|
+
name: z.ZodOptional<z.ZodString>;
|
|
56
|
+
required: z.ZodBoolean;
|
|
57
|
+
placeholder: z.ZodOptional<z.ZodString>;
|
|
58
|
+
currentValue: z.ZodUnion<readonly [z.ZodString, z.ZodBoolean]>;
|
|
59
|
+
options: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
60
|
+
}, z.core.$strip>;
|
|
61
|
+
declare const fillActionSchema: z.ZodObject<{
|
|
62
|
+
action: z.ZodLiteral<"fill">;
|
|
63
|
+
fieldId: z.ZodString;
|
|
64
|
+
value: z.ZodString;
|
|
65
|
+
}, z.core.$strip>;
|
|
66
|
+
declare const clickActionSchema: z.ZodObject<{
|
|
67
|
+
action: z.ZodLiteral<"click">;
|
|
68
|
+
fieldId: z.ZodString;
|
|
69
|
+
}, z.core.$strip>;
|
|
70
|
+
declare const selectActionSchema: z.ZodObject<{
|
|
71
|
+
action: z.ZodLiteral<"select">;
|
|
72
|
+
fieldId: z.ZodString;
|
|
73
|
+
value: z.ZodString;
|
|
74
|
+
}, z.core.$strip>;
|
|
75
|
+
declare const browserToolActionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
76
|
+
action: z.ZodLiteral<"fill">;
|
|
77
|
+
fieldId: z.ZodString;
|
|
78
|
+
value: z.ZodString;
|
|
79
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
80
|
+
action: z.ZodLiteral<"click">;
|
|
81
|
+
fieldId: z.ZodString;
|
|
82
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
83
|
+
action: z.ZodLiteral<"select">;
|
|
84
|
+
fieldId: z.ZodString;
|
|
85
|
+
value: z.ZodString;
|
|
86
|
+
}, z.core.$strip>], "action">;
|
|
87
|
+
declare const executionReportSchema: z.ZodObject<{
|
|
88
|
+
applied: z.ZodNumber;
|
|
89
|
+
skipped: z.ZodNumber;
|
|
90
|
+
warnings: z.ZodArray<z.ZodString>;
|
|
91
|
+
}, z.core.$strip>;
|
|
92
|
+
declare const snapshotRequestSchema: z.ZodObject<{
|
|
93
|
+
type: z.ZodLiteral<"snapshot_request">;
|
|
94
|
+
requestId: z.ZodString;
|
|
95
|
+
instruction: z.ZodString;
|
|
96
|
+
document: z.ZodOptional<z.ZodString>;
|
|
97
|
+
}, z.core.$strip>;
|
|
98
|
+
declare const executeRequestSchema: z.ZodObject<{
|
|
99
|
+
type: z.ZodLiteral<"execute_request">;
|
|
100
|
+
requestId: z.ZodString;
|
|
101
|
+
actions: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
102
|
+
action: z.ZodLiteral<"fill">;
|
|
103
|
+
fieldId: z.ZodString;
|
|
104
|
+
value: z.ZodString;
|
|
105
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
106
|
+
action: z.ZodLiteral<"click">;
|
|
107
|
+
fieldId: z.ZodString;
|
|
108
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
109
|
+
action: z.ZodLiteral<"select">;
|
|
110
|
+
fieldId: z.ZodString;
|
|
111
|
+
value: z.ZodString;
|
|
112
|
+
}, z.core.$strip>], "action">>;
|
|
113
|
+
fields: z.ZodArray<z.ZodObject<{
|
|
114
|
+
fieldId: z.ZodString;
|
|
115
|
+
selector: z.ZodString;
|
|
116
|
+
kind: z.ZodEnum<{
|
|
117
|
+
text: "text";
|
|
118
|
+
textarea: "textarea";
|
|
119
|
+
select: "select";
|
|
120
|
+
checkbox: "checkbox";
|
|
121
|
+
radio: "radio";
|
|
122
|
+
}>;
|
|
123
|
+
label: z.ZodString;
|
|
124
|
+
name: z.ZodOptional<z.ZodString>;
|
|
125
|
+
required: z.ZodBoolean;
|
|
126
|
+
placeholder: z.ZodOptional<z.ZodString>;
|
|
127
|
+
currentValue: z.ZodUnion<readonly [z.ZodString, z.ZodBoolean]>;
|
|
128
|
+
options: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
129
|
+
}, z.core.$strip>>;
|
|
130
|
+
}, z.core.$strip>;
|
|
131
|
+
declare const bridgeRequestSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
132
|
+
type: z.ZodLiteral<"snapshot_request">;
|
|
133
|
+
requestId: z.ZodString;
|
|
134
|
+
instruction: z.ZodString;
|
|
135
|
+
document: z.ZodOptional<z.ZodString>;
|
|
136
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
137
|
+
type: z.ZodLiteral<"execute_request">;
|
|
138
|
+
requestId: z.ZodString;
|
|
139
|
+
actions: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
140
|
+
action: z.ZodLiteral<"fill">;
|
|
141
|
+
fieldId: z.ZodString;
|
|
142
|
+
value: z.ZodString;
|
|
143
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
144
|
+
action: z.ZodLiteral<"click">;
|
|
145
|
+
fieldId: z.ZodString;
|
|
146
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
147
|
+
action: z.ZodLiteral<"select">;
|
|
148
|
+
fieldId: z.ZodString;
|
|
149
|
+
value: z.ZodString;
|
|
150
|
+
}, z.core.$strip>], "action">>;
|
|
151
|
+
fields: z.ZodArray<z.ZodObject<{
|
|
152
|
+
fieldId: z.ZodString;
|
|
153
|
+
selector: z.ZodString;
|
|
154
|
+
kind: z.ZodEnum<{
|
|
155
|
+
text: "text";
|
|
156
|
+
textarea: "textarea";
|
|
157
|
+
select: "select";
|
|
158
|
+
checkbox: "checkbox";
|
|
159
|
+
radio: "radio";
|
|
160
|
+
}>;
|
|
161
|
+
label: z.ZodString;
|
|
162
|
+
name: z.ZodOptional<z.ZodString>;
|
|
163
|
+
required: z.ZodBoolean;
|
|
164
|
+
placeholder: z.ZodOptional<z.ZodString>;
|
|
165
|
+
currentValue: z.ZodUnion<readonly [z.ZodString, z.ZodBoolean]>;
|
|
166
|
+
options: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
167
|
+
}, z.core.$strip>>;
|
|
168
|
+
}, z.core.$strip>], "type">;
|
|
169
|
+
declare const snapshotResponseSchema: z.ZodObject<{
|
|
170
|
+
type: z.ZodLiteral<"snapshot_response">;
|
|
171
|
+
requestId: z.ZodString;
|
|
172
|
+
fields: z.ZodArray<z.ZodObject<{
|
|
173
|
+
fieldId: z.ZodString;
|
|
174
|
+
selector: z.ZodString;
|
|
175
|
+
kind: z.ZodEnum<{
|
|
176
|
+
text: "text";
|
|
177
|
+
textarea: "textarea";
|
|
178
|
+
select: "select";
|
|
179
|
+
checkbox: "checkbox";
|
|
180
|
+
radio: "radio";
|
|
181
|
+
}>;
|
|
182
|
+
label: z.ZodString;
|
|
183
|
+
name: z.ZodOptional<z.ZodString>;
|
|
184
|
+
required: z.ZodBoolean;
|
|
185
|
+
placeholder: z.ZodOptional<z.ZodString>;
|
|
186
|
+
currentValue: z.ZodUnion<readonly [z.ZodString, z.ZodBoolean]>;
|
|
187
|
+
options: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
188
|
+
}, z.core.$strip>>;
|
|
189
|
+
}, z.core.$strip>;
|
|
190
|
+
declare const executeResponseSchema: z.ZodObject<{
|
|
191
|
+
type: z.ZodLiteral<"execute_response">;
|
|
192
|
+
requestId: z.ZodString;
|
|
193
|
+
report: z.ZodObject<{
|
|
194
|
+
applied: z.ZodNumber;
|
|
195
|
+
skipped: z.ZodNumber;
|
|
196
|
+
warnings: z.ZodArray<z.ZodString>;
|
|
197
|
+
}, z.core.$strip>;
|
|
198
|
+
}, z.core.$strip>;
|
|
199
|
+
declare const errorResponseSchema: z.ZodObject<{
|
|
200
|
+
type: z.ZodLiteral<"error_response">;
|
|
201
|
+
requestId: z.ZodString;
|
|
202
|
+
message: z.ZodString;
|
|
203
|
+
}, z.core.$strip>;
|
|
204
|
+
declare const bridgeResponseSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
205
|
+
type: z.ZodLiteral<"snapshot_response">;
|
|
206
|
+
requestId: z.ZodString;
|
|
207
|
+
fields: z.ZodArray<z.ZodObject<{
|
|
208
|
+
fieldId: z.ZodString;
|
|
209
|
+
selector: z.ZodString;
|
|
210
|
+
kind: z.ZodEnum<{
|
|
211
|
+
text: "text";
|
|
212
|
+
textarea: "textarea";
|
|
213
|
+
select: "select";
|
|
214
|
+
checkbox: "checkbox";
|
|
215
|
+
radio: "radio";
|
|
216
|
+
}>;
|
|
217
|
+
label: z.ZodString;
|
|
218
|
+
name: z.ZodOptional<z.ZodString>;
|
|
219
|
+
required: z.ZodBoolean;
|
|
220
|
+
placeholder: z.ZodOptional<z.ZodString>;
|
|
221
|
+
currentValue: z.ZodUnion<readonly [z.ZodString, z.ZodBoolean]>;
|
|
222
|
+
options: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
223
|
+
}, z.core.$strip>>;
|
|
224
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
225
|
+
type: z.ZodLiteral<"execute_response">;
|
|
226
|
+
requestId: z.ZodString;
|
|
227
|
+
report: z.ZodObject<{
|
|
228
|
+
applied: z.ZodNumber;
|
|
229
|
+
skipped: z.ZodNumber;
|
|
230
|
+
warnings: z.ZodArray<z.ZodString>;
|
|
231
|
+
}, z.core.$strip>;
|
|
232
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
233
|
+
type: z.ZodLiteral<"error_response">;
|
|
234
|
+
requestId: z.ZodString;
|
|
235
|
+
message: z.ZodString;
|
|
236
|
+
}, z.core.$strip>], "type">;
|
|
237
|
+
declare const dispatchSuccessSchema: z.ZodObject<{
|
|
238
|
+
ok: z.ZodLiteral<true>;
|
|
239
|
+
response: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
240
|
+
type: z.ZodLiteral<"snapshot_response">;
|
|
241
|
+
requestId: z.ZodString;
|
|
242
|
+
fields: z.ZodArray<z.ZodObject<{
|
|
243
|
+
fieldId: z.ZodString;
|
|
244
|
+
selector: z.ZodString;
|
|
245
|
+
kind: z.ZodEnum<{
|
|
246
|
+
text: "text";
|
|
247
|
+
textarea: "textarea";
|
|
248
|
+
select: "select";
|
|
249
|
+
checkbox: "checkbox";
|
|
250
|
+
radio: "radio";
|
|
251
|
+
}>;
|
|
252
|
+
label: z.ZodString;
|
|
253
|
+
name: z.ZodOptional<z.ZodString>;
|
|
254
|
+
required: z.ZodBoolean;
|
|
255
|
+
placeholder: z.ZodOptional<z.ZodString>;
|
|
256
|
+
currentValue: z.ZodUnion<readonly [z.ZodString, z.ZodBoolean]>;
|
|
257
|
+
options: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
258
|
+
}, z.core.$strip>>;
|
|
259
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
260
|
+
type: z.ZodLiteral<"execute_response">;
|
|
261
|
+
requestId: z.ZodString;
|
|
262
|
+
report: z.ZodObject<{
|
|
263
|
+
applied: z.ZodNumber;
|
|
264
|
+
skipped: z.ZodNumber;
|
|
265
|
+
warnings: z.ZodArray<z.ZodString>;
|
|
266
|
+
}, z.core.$strip>;
|
|
267
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
268
|
+
type: z.ZodLiteral<"error_response">;
|
|
269
|
+
requestId: z.ZodString;
|
|
270
|
+
message: z.ZodString;
|
|
271
|
+
}, z.core.$strip>], "type">;
|
|
272
|
+
}, z.core.$strip>;
|
|
273
|
+
declare const dispatchErrorSchema: z.ZodObject<{
|
|
274
|
+
ok: z.ZodLiteral<false>;
|
|
275
|
+
errorCode: z.ZodUnion<readonly [z.ZodLiteral<"UNAUTHORIZED">, z.ZodLiteral<"NO_BROWSER">, z.ZodLiteral<"TIMEOUT">, z.ZodLiteral<"INVALID_RESPONSE">, z.ZodLiteral<"NOT_FOUND">, z.ZodLiteral<"INTERNAL">]>;
|
|
276
|
+
message: z.ZodString;
|
|
277
|
+
}, z.core.$strip>;
|
|
278
|
+
type BridgeRequest = z.infer<typeof bridgeRequestSchema>;
|
|
279
|
+
type BridgeResponse = z.infer<typeof bridgeResponseSchema>;
|
|
280
|
+
|
|
281
|
+
export { type BridgeErrorCode, type BridgeRequest, type BridgeResponse, type BrowserToolAction, type BrowserToolStatus, type ClickAction, type ExecutionReport, type FieldKind, type FillAction, type SelectAction, type SnapshotField, bridgeRequestSchema, bridgeResponseSchema, browserToolActionSchema, clickActionSchema, dispatchErrorSchema, dispatchSuccessSchema, errorResponseSchema, executeRequestSchema, executeResponseSchema, executionReportSchema, fieldKindSchema, fillActionSchema, selectActionSchema, snapshotFieldSchema, snapshotRequestSchema, snapshotResponseSchema };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// src/types.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
var fieldKindSchema = z.enum([
|
|
4
|
+
"text",
|
|
5
|
+
"textarea",
|
|
6
|
+
"select",
|
|
7
|
+
"checkbox",
|
|
8
|
+
"radio"
|
|
9
|
+
]);
|
|
10
|
+
var snapshotFieldSchema = z.object({
|
|
11
|
+
fieldId: z.string().min(1),
|
|
12
|
+
selector: z.string().min(1),
|
|
13
|
+
kind: fieldKindSchema,
|
|
14
|
+
label: z.string().min(1),
|
|
15
|
+
name: z.string().optional(),
|
|
16
|
+
required: z.boolean(),
|
|
17
|
+
placeholder: z.string().optional(),
|
|
18
|
+
currentValue: z.union([z.string(), z.boolean()]),
|
|
19
|
+
options: z.array(z.string()).optional()
|
|
20
|
+
});
|
|
21
|
+
var fillActionSchema = z.object({
|
|
22
|
+
action: z.literal("fill"),
|
|
23
|
+
fieldId: z.string().min(1),
|
|
24
|
+
value: z.string()
|
|
25
|
+
});
|
|
26
|
+
var clickActionSchema = z.object({
|
|
27
|
+
action: z.literal("click"),
|
|
28
|
+
fieldId: z.string().min(1)
|
|
29
|
+
});
|
|
30
|
+
var selectActionSchema = z.object({
|
|
31
|
+
action: z.literal("select"),
|
|
32
|
+
fieldId: z.string().min(1),
|
|
33
|
+
value: z.string()
|
|
34
|
+
});
|
|
35
|
+
var browserToolActionSchema = z.discriminatedUnion("action", [
|
|
36
|
+
fillActionSchema,
|
|
37
|
+
clickActionSchema,
|
|
38
|
+
selectActionSchema
|
|
39
|
+
]);
|
|
40
|
+
var executionReportSchema = z.object({
|
|
41
|
+
applied: z.number().int().nonnegative(),
|
|
42
|
+
skipped: z.number().int().nonnegative(),
|
|
43
|
+
warnings: z.array(z.string())
|
|
44
|
+
});
|
|
45
|
+
var snapshotRequestSchema = z.object({
|
|
46
|
+
type: z.literal("snapshot_request"),
|
|
47
|
+
requestId: z.string().min(1),
|
|
48
|
+
instruction: z.string().min(1),
|
|
49
|
+
document: z.string().optional()
|
|
50
|
+
});
|
|
51
|
+
var executeRequestSchema = z.object({
|
|
52
|
+
type: z.literal("execute_request"),
|
|
53
|
+
requestId: z.string().min(1),
|
|
54
|
+
actions: z.array(browserToolActionSchema),
|
|
55
|
+
fields: z.array(snapshotFieldSchema)
|
|
56
|
+
});
|
|
57
|
+
var bridgeRequestSchema = z.discriminatedUnion("type", [
|
|
58
|
+
snapshotRequestSchema,
|
|
59
|
+
executeRequestSchema
|
|
60
|
+
]);
|
|
61
|
+
var snapshotResponseSchema = z.object({
|
|
62
|
+
type: z.literal("snapshot_response"),
|
|
63
|
+
requestId: z.string().min(1),
|
|
64
|
+
fields: z.array(snapshotFieldSchema)
|
|
65
|
+
});
|
|
66
|
+
var executeResponseSchema = z.object({
|
|
67
|
+
type: z.literal("execute_response"),
|
|
68
|
+
requestId: z.string().min(1),
|
|
69
|
+
report: executionReportSchema
|
|
70
|
+
});
|
|
71
|
+
var errorResponseSchema = z.object({
|
|
72
|
+
type: z.literal("error_response"),
|
|
73
|
+
requestId: z.string().min(1),
|
|
74
|
+
message: z.string().min(1)
|
|
75
|
+
});
|
|
76
|
+
var bridgeResponseSchema = z.discriminatedUnion("type", [
|
|
77
|
+
snapshotResponseSchema,
|
|
78
|
+
executeResponseSchema,
|
|
79
|
+
errorResponseSchema
|
|
80
|
+
]);
|
|
81
|
+
var dispatchSuccessSchema = z.object({
|
|
82
|
+
ok: z.literal(true),
|
|
83
|
+
response: bridgeResponseSchema
|
|
84
|
+
});
|
|
85
|
+
var dispatchErrorSchema = z.object({
|
|
86
|
+
ok: z.literal(false),
|
|
87
|
+
errorCode: z.union([
|
|
88
|
+
z.literal("UNAUTHORIZED"),
|
|
89
|
+
z.literal("NO_BROWSER"),
|
|
90
|
+
z.literal("TIMEOUT"),
|
|
91
|
+
z.literal("INVALID_RESPONSE"),
|
|
92
|
+
z.literal("NOT_FOUND"),
|
|
93
|
+
z.literal("INTERNAL")
|
|
94
|
+
]),
|
|
95
|
+
message: z.string()
|
|
96
|
+
});
|
|
97
|
+
export {
|
|
98
|
+
bridgeRequestSchema,
|
|
99
|
+
bridgeResponseSchema,
|
|
100
|
+
browserToolActionSchema,
|
|
101
|
+
clickActionSchema,
|
|
102
|
+
dispatchErrorSchema,
|
|
103
|
+
dispatchSuccessSchema,
|
|
104
|
+
errorResponseSchema,
|
|
105
|
+
executeRequestSchema,
|
|
106
|
+
executeResponseSchema,
|
|
107
|
+
executionReportSchema,
|
|
108
|
+
fieldKindSchema,
|
|
109
|
+
fillActionSchema,
|
|
110
|
+
selectActionSchema,
|
|
111
|
+
snapshotFieldSchema,
|
|
112
|
+
snapshotRequestSchema,
|
|
113
|
+
snapshotResponseSchema
|
|
114
|
+
};
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
// src/mcp-server/index.ts
|
|
2
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
+
|
|
5
|
+
// src/mcp-server/bridge-client.ts
|
|
6
|
+
import { randomUUID } from "crypto";
|
|
7
|
+
|
|
8
|
+
// src/types.ts
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
var fieldKindSchema = z.enum([
|
|
11
|
+
"text",
|
|
12
|
+
"textarea",
|
|
13
|
+
"select",
|
|
14
|
+
"checkbox",
|
|
15
|
+
"radio"
|
|
16
|
+
]);
|
|
17
|
+
var snapshotFieldSchema = z.object({
|
|
18
|
+
fieldId: z.string().min(1),
|
|
19
|
+
selector: z.string().min(1),
|
|
20
|
+
kind: fieldKindSchema,
|
|
21
|
+
label: z.string().min(1),
|
|
22
|
+
name: z.string().optional(),
|
|
23
|
+
required: z.boolean(),
|
|
24
|
+
placeholder: z.string().optional(),
|
|
25
|
+
currentValue: z.union([z.string(), z.boolean()]),
|
|
26
|
+
options: z.array(z.string()).optional()
|
|
27
|
+
});
|
|
28
|
+
var fillActionSchema = z.object({
|
|
29
|
+
action: z.literal("fill"),
|
|
30
|
+
fieldId: z.string().min(1),
|
|
31
|
+
value: z.string()
|
|
32
|
+
});
|
|
33
|
+
var clickActionSchema = z.object({
|
|
34
|
+
action: z.literal("click"),
|
|
35
|
+
fieldId: z.string().min(1)
|
|
36
|
+
});
|
|
37
|
+
var selectActionSchema = z.object({
|
|
38
|
+
action: z.literal("select"),
|
|
39
|
+
fieldId: z.string().min(1),
|
|
40
|
+
value: z.string()
|
|
41
|
+
});
|
|
42
|
+
var browserToolActionSchema = z.discriminatedUnion("action", [
|
|
43
|
+
fillActionSchema,
|
|
44
|
+
clickActionSchema,
|
|
45
|
+
selectActionSchema
|
|
46
|
+
]);
|
|
47
|
+
var executionReportSchema = z.object({
|
|
48
|
+
applied: z.number().int().nonnegative(),
|
|
49
|
+
skipped: z.number().int().nonnegative(),
|
|
50
|
+
warnings: z.array(z.string())
|
|
51
|
+
});
|
|
52
|
+
var snapshotRequestSchema = z.object({
|
|
53
|
+
type: z.literal("snapshot_request"),
|
|
54
|
+
requestId: z.string().min(1),
|
|
55
|
+
instruction: z.string().min(1),
|
|
56
|
+
document: z.string().optional()
|
|
57
|
+
});
|
|
58
|
+
var executeRequestSchema = z.object({
|
|
59
|
+
type: z.literal("execute_request"),
|
|
60
|
+
requestId: z.string().min(1),
|
|
61
|
+
actions: z.array(browserToolActionSchema),
|
|
62
|
+
fields: z.array(snapshotFieldSchema)
|
|
63
|
+
});
|
|
64
|
+
var bridgeRequestSchema = z.discriminatedUnion("type", [
|
|
65
|
+
snapshotRequestSchema,
|
|
66
|
+
executeRequestSchema
|
|
67
|
+
]);
|
|
68
|
+
var snapshotResponseSchema = z.object({
|
|
69
|
+
type: z.literal("snapshot_response"),
|
|
70
|
+
requestId: z.string().min(1),
|
|
71
|
+
fields: z.array(snapshotFieldSchema)
|
|
72
|
+
});
|
|
73
|
+
var executeResponseSchema = z.object({
|
|
74
|
+
type: z.literal("execute_response"),
|
|
75
|
+
requestId: z.string().min(1),
|
|
76
|
+
report: executionReportSchema
|
|
77
|
+
});
|
|
78
|
+
var errorResponseSchema = z.object({
|
|
79
|
+
type: z.literal("error_response"),
|
|
80
|
+
requestId: z.string().min(1),
|
|
81
|
+
message: z.string().min(1)
|
|
82
|
+
});
|
|
83
|
+
var bridgeResponseSchema = z.discriminatedUnion("type", [
|
|
84
|
+
snapshotResponseSchema,
|
|
85
|
+
executeResponseSchema,
|
|
86
|
+
errorResponseSchema
|
|
87
|
+
]);
|
|
88
|
+
var dispatchSuccessSchema = z.object({
|
|
89
|
+
ok: z.literal(true),
|
|
90
|
+
response: bridgeResponseSchema
|
|
91
|
+
});
|
|
92
|
+
var dispatchErrorSchema = z.object({
|
|
93
|
+
ok: z.literal(false),
|
|
94
|
+
errorCode: z.union([
|
|
95
|
+
z.literal("UNAUTHORIZED"),
|
|
96
|
+
z.literal("NO_BROWSER"),
|
|
97
|
+
z.literal("TIMEOUT"),
|
|
98
|
+
z.literal("INVALID_RESPONSE"),
|
|
99
|
+
z.literal("NOT_FOUND"),
|
|
100
|
+
z.literal("INTERNAL")
|
|
101
|
+
]),
|
|
102
|
+
message: z.string()
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// src/mcp-server/bridge-client.ts
|
|
106
|
+
function requiredEnv(name) {
|
|
107
|
+
const value = process.env[name]?.trim();
|
|
108
|
+
if (!value) {
|
|
109
|
+
throw new Error(`Missing required environment variable: ${name}`);
|
|
110
|
+
}
|
|
111
|
+
return value;
|
|
112
|
+
}
|
|
113
|
+
function trimTrailingSlash(input) {
|
|
114
|
+
return input.replace(/\/+$/, "");
|
|
115
|
+
}
|
|
116
|
+
var BridgeClient = class {
|
|
117
|
+
baseUrl;
|
|
118
|
+
sessionId;
|
|
119
|
+
token;
|
|
120
|
+
timeoutMs;
|
|
121
|
+
vercelProtectionBypass;
|
|
122
|
+
giselleProtectionBypass;
|
|
123
|
+
constructor(input) {
|
|
124
|
+
this.baseUrl = trimTrailingSlash(input.baseUrl);
|
|
125
|
+
this.sessionId = input.sessionId;
|
|
126
|
+
this.token = input.token;
|
|
127
|
+
this.timeoutMs = input.timeoutMs ?? 2e4;
|
|
128
|
+
this.vercelProtectionBypass = input.vercelProtectionBypass?.trim() || null;
|
|
129
|
+
this.giselleProtectionBypass = input.giselleProtectionBypass?.trim() || null;
|
|
130
|
+
}
|
|
131
|
+
async requestSnapshot(input) {
|
|
132
|
+
const response = await this.dispatch({
|
|
133
|
+
type: "snapshot_request",
|
|
134
|
+
requestId: randomUUID(),
|
|
135
|
+
instruction: input.instruction,
|
|
136
|
+
document: input.document
|
|
137
|
+
});
|
|
138
|
+
if (response.type !== "snapshot_response") {
|
|
139
|
+
throw new Error(`Unexpected bridge response type: ${response.type}`);
|
|
140
|
+
}
|
|
141
|
+
return response.fields;
|
|
142
|
+
}
|
|
143
|
+
async requestExecute(input) {
|
|
144
|
+
const response = await this.dispatch({
|
|
145
|
+
type: "execute_request",
|
|
146
|
+
requestId: randomUUID(),
|
|
147
|
+
actions: input.actions,
|
|
148
|
+
fields: input.fields
|
|
149
|
+
});
|
|
150
|
+
if (response.type !== "execute_response") {
|
|
151
|
+
throw new Error(`Unexpected bridge response type: ${response.type}`);
|
|
152
|
+
}
|
|
153
|
+
return response.report;
|
|
154
|
+
}
|
|
155
|
+
async dispatch(request) {
|
|
156
|
+
const payload = bridgeRequestSchema.parse(request);
|
|
157
|
+
let response;
|
|
158
|
+
try {
|
|
159
|
+
const headers = {
|
|
160
|
+
"content-type": "application/json"
|
|
161
|
+
};
|
|
162
|
+
if (this.vercelProtectionBypass) {
|
|
163
|
+
headers["x-vercel-protection-bypass"] = this.vercelProtectionBypass;
|
|
164
|
+
}
|
|
165
|
+
if (this.giselleProtectionBypass) {
|
|
166
|
+
headers["x-giselle-protection-bypass"] = this.giselleProtectionBypass;
|
|
167
|
+
}
|
|
168
|
+
response = await fetch(`${this.baseUrl}`, {
|
|
169
|
+
method: "POST",
|
|
170
|
+
headers,
|
|
171
|
+
body: JSON.stringify({
|
|
172
|
+
type: "bridge.dispatch",
|
|
173
|
+
sessionId: this.sessionId,
|
|
174
|
+
token: this.token,
|
|
175
|
+
timeoutMs: this.timeoutMs,
|
|
176
|
+
request: payload
|
|
177
|
+
})
|
|
178
|
+
});
|
|
179
|
+
} catch (error) {
|
|
180
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
181
|
+
throw new Error(
|
|
182
|
+
[
|
|
183
|
+
"Bridge dispatch network request failed.",
|
|
184
|
+
`baseUrl=${this.baseUrl}`,
|
|
185
|
+
"Ensure BROWSER_TOOL_BRIDGE_BASE_URL is reachable from the sandbox runtime.",
|
|
186
|
+
`cause=${message}`
|
|
187
|
+
].join(" ")
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
const body = await response.json().catch(() => null);
|
|
191
|
+
const failure = dispatchErrorSchema.safeParse(body);
|
|
192
|
+
if (failure.success) {
|
|
193
|
+
throw new Error(`[${failure.data.errorCode}] ${failure.data.message}`);
|
|
194
|
+
}
|
|
195
|
+
const success = dispatchSuccessSchema.safeParse(body);
|
|
196
|
+
if (!success.success) {
|
|
197
|
+
throw new Error("Bridge dispatch returned an unexpected payload.");
|
|
198
|
+
}
|
|
199
|
+
if (!response.ok) {
|
|
200
|
+
throw new Error(`Bridge dispatch failed with HTTP ${response.status}.`);
|
|
201
|
+
}
|
|
202
|
+
const parsedResponse = bridgeResponseSchema.parse(success.data.response);
|
|
203
|
+
return parsedResponse;
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
function createBridgeClientFromEnv() {
|
|
207
|
+
const vercelProtectionBypass = process.env.VERCEL_PROTECTION_BYPASS;
|
|
208
|
+
const giselleProtectionBypass = process.env.GISELLE_PROTECTION_BYPASS;
|
|
209
|
+
console.error(
|
|
210
|
+
`[bridge-client] VERCEL_PROTECTION_BYPASS=${vercelProtectionBypass?.trim() ? "(set)" : "(unset)"}`
|
|
211
|
+
);
|
|
212
|
+
console.error(
|
|
213
|
+
`[bridge-client] GISELLE_PROTECTION_BYPASS=${giselleProtectionBypass?.trim() ? "(set)" : "(unset)"}`
|
|
214
|
+
);
|
|
215
|
+
return new BridgeClient({
|
|
216
|
+
baseUrl: requiredEnv("BROWSER_TOOL_BRIDGE_BASE_URL"),
|
|
217
|
+
sessionId: requiredEnv("BROWSER_TOOL_BRIDGE_SESSION_ID"),
|
|
218
|
+
token: requiredEnv("BROWSER_TOOL_BRIDGE_TOKEN"),
|
|
219
|
+
vercelProtectionBypass,
|
|
220
|
+
giselleProtectionBypass
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// src/mcp-server/tools/execute-form-actions.ts
|
|
225
|
+
import { z as z2 } from "zod";
|
|
226
|
+
var executeFormActionsInputShape = {
|
|
227
|
+
actions: z2.array(browserToolActionSchema),
|
|
228
|
+
fields: z2.array(snapshotFieldSchema)
|
|
229
|
+
};
|
|
230
|
+
var executeFormActionsInputSchema = z2.object(executeFormActionsInputShape);
|
|
231
|
+
async function runExecuteFormActions(input, bridgeClient) {
|
|
232
|
+
const parsed = executeFormActionsInputSchema.parse(input);
|
|
233
|
+
return await bridgeClient.requestExecute({
|
|
234
|
+
actions: parsed.actions,
|
|
235
|
+
fields: parsed.fields
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// src/mcp-server/tools/get-form-snapshot.ts
|
|
240
|
+
async function runGetFormSnapshot(bridgeClient) {
|
|
241
|
+
const fields = await bridgeClient.requestSnapshot({
|
|
242
|
+
instruction: "snapshot"
|
|
243
|
+
});
|
|
244
|
+
return { fields };
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// src/mcp-server/index.ts
|
|
248
|
+
var server = new McpServer(
|
|
249
|
+
{
|
|
250
|
+
name: "giselles-browser-tool-mcp-server",
|
|
251
|
+
version: "0.2.0"
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
instructions: [
|
|
255
|
+
"You are a Browser Tool agent that fills web forms on behalf of the user.",
|
|
256
|
+
"",
|
|
257
|
+
"When the user asks you to fill a form or interact with a web page, follow these steps in order:",
|
|
258
|
+
"",
|
|
259
|
+
"1. Call `getFormSnapshot` (no arguments) to get the list of form fields currently visible in the browser.",
|
|
260
|
+
"2. Based on the user's instruction and the returned fields, plan which actions to perform.",
|
|
261
|
+
" Each action must reference a `fieldId` from the snapshot. Allowed actions:",
|
|
262
|
+
" - `fill`: Set the value of a text/textarea field. Requires `fieldId` and `value`.",
|
|
263
|
+
" - `select`: Choose an option in a select/radio field. Requires `fieldId` and `value` (must be one of the field's `options`).",
|
|
264
|
+
" - `click`: Click a checkbox or button. Requires only `fieldId`.",
|
|
265
|
+
"3. Call `executeFormActions` with the planned `actions` array and the `fields` array from step 1.",
|
|
266
|
+
"",
|
|
267
|
+
"Rules:",
|
|
268
|
+
"- Always call `getFormSnapshot` first before planning any actions.",
|
|
269
|
+
"- Only use `fieldId` values that appear in the snapshot response. Never invent field IDs.",
|
|
270
|
+
"- If the user's instruction is ambiguous or no matching field exists, explain the issue instead of guessing.",
|
|
271
|
+
"- Pass the `fields` array from the snapshot response unchanged to `executeFormActions`."
|
|
272
|
+
].join("\n")
|
|
273
|
+
}
|
|
274
|
+
);
|
|
275
|
+
server.registerTool("getFormSnapshot", {}, async () => {
|
|
276
|
+
try {
|
|
277
|
+
const bridgeClient = createBridgeClientFromEnv();
|
|
278
|
+
const output = await runGetFormSnapshot(bridgeClient);
|
|
279
|
+
return {
|
|
280
|
+
content: [
|
|
281
|
+
{
|
|
282
|
+
type: "text",
|
|
283
|
+
text: JSON.stringify(output)
|
|
284
|
+
}
|
|
285
|
+
],
|
|
286
|
+
structuredContent: output
|
|
287
|
+
};
|
|
288
|
+
} catch (error) {
|
|
289
|
+
const message = error instanceof Error ? error.message : "Failed to get form snapshot.";
|
|
290
|
+
const stack = error instanceof Error ? error.stack : void 0;
|
|
291
|
+
console.error(`[mcp getFormSnapshot] ${message}`);
|
|
292
|
+
if (stack) {
|
|
293
|
+
console.error(stack);
|
|
294
|
+
}
|
|
295
|
+
return {
|
|
296
|
+
isError: true,
|
|
297
|
+
content: [
|
|
298
|
+
{
|
|
299
|
+
type: "text",
|
|
300
|
+
text: message
|
|
301
|
+
}
|
|
302
|
+
]
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
server.registerTool(
|
|
307
|
+
"executeFormActions",
|
|
308
|
+
{ inputSchema: executeFormActionsInputShape },
|
|
309
|
+
async (input) => {
|
|
310
|
+
try {
|
|
311
|
+
const bridgeClient = createBridgeClientFromEnv();
|
|
312
|
+
const output = await runExecuteFormActions(input, bridgeClient);
|
|
313
|
+
return {
|
|
314
|
+
content: [
|
|
315
|
+
{
|
|
316
|
+
type: "text",
|
|
317
|
+
text: JSON.stringify(output)
|
|
318
|
+
}
|
|
319
|
+
],
|
|
320
|
+
structuredContent: output
|
|
321
|
+
};
|
|
322
|
+
} catch (error) {
|
|
323
|
+
const message = error instanceof Error ? error.message : "Failed to execute form actions.";
|
|
324
|
+
const stack = error instanceof Error ? error.stack : void 0;
|
|
325
|
+
console.error(`[mcp executeFormActions] ${message}`);
|
|
326
|
+
if (stack) {
|
|
327
|
+
console.error(stack);
|
|
328
|
+
}
|
|
329
|
+
return {
|
|
330
|
+
isError: true,
|
|
331
|
+
content: [
|
|
332
|
+
{
|
|
333
|
+
type: "text",
|
|
334
|
+
text: message
|
|
335
|
+
}
|
|
336
|
+
]
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
);
|
|
341
|
+
var transport = new StdioServerTransport();
|
|
342
|
+
await server.connect(transport);
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@giselles-ai/browser-tool",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/giselles-ai/agent-container.git",
|
|
10
|
+
"directory": "packages/browser-tool"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.js",
|
|
19
|
+
"default": "./dist/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./dom": {
|
|
22
|
+
"types": "./dist/dom/index.d.ts",
|
|
23
|
+
"import": "./dist/dom/index.js",
|
|
24
|
+
"default": "./dist/dom/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./mcp-server": {
|
|
27
|
+
"types": "./dist/mcp-server/index.d.ts",
|
|
28
|
+
"import": "./dist/mcp-server/index.js",
|
|
29
|
+
"default": "./dist/mcp-server/index.js"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
34
|
+
"zod": "4.3.6"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/node": "25.0.10",
|
|
38
|
+
"tsup": "8.5.1",
|
|
39
|
+
"typescript": "5.9.3"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsup --config tsup.ts",
|
|
43
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
44
|
+
"format": "pnpm exec biome check --write ."
|
|
45
|
+
}
|
|
46
|
+
}
|