@eidentic/browser 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/README.md +104 -0
- package/dist/index.cjs +158 -0
- package/dist/index.d.cts +98 -0
- package/dist/index.d.ts +98 -0
- package/dist/index.js +131 -0
- package/package.json +68 -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 Derivative
|
|
95
|
+
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, excluding
|
|
103
|
+
those notices that do not pertain to any part of the Derivative
|
|
104
|
+
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 do
|
|
117
|
+
not modify the License. You may add Your own attribution notices
|
|
118
|
+
within Derivative Works that You distribute, alongside or as an
|
|
119
|
+
addendum to the NOTICE text from the Work, provided that such
|
|
120
|
+
additional attribution notices cannot be construed as modifying
|
|
121
|
+
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 2026 Baran Özdemir
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# @eidentic/browser
|
|
2
|
+
|
|
3
|
+
Sealed browser-automation tools for Eidentic — first-class sandboxed browser tools over an
|
|
4
|
+
injected `PageLike` page. Pass any object that satisfies the `PageLike` interface: a real
|
|
5
|
+
Playwright `Page`, or a faithful in-memory fake for tests.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @eidentic/browser playwright-core
|
|
11
|
+
npx playwright install chromium
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { chromium } from "playwright-core";
|
|
18
|
+
import { browserTools } from "@eidentic/browser";
|
|
19
|
+
import { Agent } from "eidentic";
|
|
20
|
+
|
|
21
|
+
const browser = await chromium.launch({ headless: true });
|
|
22
|
+
const context = await browser.newContext();
|
|
23
|
+
const page = await context.newPage();
|
|
24
|
+
|
|
25
|
+
const agent = new Agent({
|
|
26
|
+
id: "web-agent",
|
|
27
|
+
model,
|
|
28
|
+
store,
|
|
29
|
+
tools: browserTools(page, {
|
|
30
|
+
allowlist: ["example.com", "docs.example.com"],
|
|
31
|
+
}),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
for await (const ev of agent.query("What is on the homepage of example.com?", { sessionId: "s-1" })) {
|
|
35
|
+
if (ev.kind === "text_delta") process.stdout.write(ev.delta);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
await browser.close();
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Tools
|
|
42
|
+
|
|
43
|
+
| Tool ID | Side effect | Description |
|
|
44
|
+
|---|---|---|
|
|
45
|
+
| `browser_navigate` | `destructive` | Navigate to an `http(s)` URL. Validates before AND after navigation (redirect escape detection). |
|
|
46
|
+
| `browser_read` | `read-only` | Read current page title, URL, and text (body or a CSS selector). Truncated to `maxContentBytes`. |
|
|
47
|
+
| `browser_click` | `destructive` | Click an element by CSS selector. Errors are tool errors, not throws. |
|
|
48
|
+
| `browser_fill` | `destructive` | Fill an input by CSS selector. Errors are tool errors, not throws. |
|
|
49
|
+
|
|
50
|
+
## Security
|
|
51
|
+
|
|
52
|
+
Every `browser_navigate` call:
|
|
53
|
+
1. Validates the target URL scheme (`http`/`https` only).
|
|
54
|
+
2. Checks the host against the private-IP/loopback/metadata blocklist (SSRF defense, mirrors `@eidentic/tools`).
|
|
55
|
+
3. Checks the host against your `allowlist` (when configured).
|
|
56
|
+
4. After `goto()`, **re-validates `page.url()`** — so server-side redirects that would escape the
|
|
57
|
+
allowlist or land on a private host are caught and returned as tool errors before the agent can act on them.
|
|
58
|
+
|
|
59
|
+
## Options
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
browserTools(page, {
|
|
63
|
+
// Optional: restrict navigation to these hostnames (and their subdomains).
|
|
64
|
+
// Omit for no restriction; pass [] to deny all navigation.
|
|
65
|
+
allowlist?: string[];
|
|
66
|
+
|
|
67
|
+
// Default: true. Set to false only in controlled test environments.
|
|
68
|
+
blockPrivateHosts?: boolean;
|
|
69
|
+
|
|
70
|
+
// Max UTF-8 bytes in browser_read results. Default: 512 KB.
|
|
71
|
+
maxContentBytes?: number;
|
|
72
|
+
})
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## PageLike interface
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
interface PageLike {
|
|
79
|
+
goto(url: string): Promise<unknown>;
|
|
80
|
+
content(): Promise<string>;
|
|
81
|
+
innerText(selector: string): Promise<string>;
|
|
82
|
+
click(selector: string): Promise<void>;
|
|
83
|
+
fill(selector: string, value: string): Promise<void>;
|
|
84
|
+
url(): string;
|
|
85
|
+
title(): Promise<string>;
|
|
86
|
+
screenshot?(): Promise<Uint8Array>; // optional, not exposed as a tool in v1
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
A real `playwright-core` `Page` satisfies this interface structurally. No adapter needed.
|
|
91
|
+
|
|
92
|
+
## Roadmap
|
|
93
|
+
|
|
94
|
+
- `browser_screenshot`: returns a base64-encoded screenshot string. Not in v1 because binary results
|
|
95
|
+
don't compose cleanly with text tool results; the encoding overhead and context-window cost warrant
|
|
96
|
+
a dedicated design.
|
|
97
|
+
|
|
98
|
+
## Links
|
|
99
|
+
|
|
100
|
+
- [GitHub](https://github.com/eidentic/eidentic)
|
|
101
|
+
- [Issue tracker](https://github.com/eidentic/eidentic/issues)
|
|
102
|
+
- [Root README](https://github.com/eidentic/eidentic#readme)
|
|
103
|
+
|
|
104
|
+
Apache-2.0
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
browserTools: () => browserTools,
|
|
24
|
+
hostAllowed: () => import_tools2.hostAllowed,
|
|
25
|
+
isBlockedHost: () => import_tools2.isBlockedHost
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
var import_zod = require("zod");
|
|
29
|
+
var import_core = require("@eidentic/core");
|
|
30
|
+
var import_tools = require("@eidentic/tools");
|
|
31
|
+
var import_tools2 = require("@eidentic/tools");
|
|
32
|
+
var DEFAULT_MAX_CONTENT_BYTES = 512 * 1024;
|
|
33
|
+
var TRUNCATION_MARKER = "\n\u2026[content truncated]";
|
|
34
|
+
function assertNavigableUrl(rawUrl, opts) {
|
|
35
|
+
let parsed;
|
|
36
|
+
try {
|
|
37
|
+
parsed = new URL(rawUrl);
|
|
38
|
+
} catch {
|
|
39
|
+
throw new Error(`browser: invalid URL`);
|
|
40
|
+
}
|
|
41
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
42
|
+
throw new Error(`browser: only http(s) URLs are allowed (got ${parsed.protocol})`);
|
|
43
|
+
}
|
|
44
|
+
if (opts.blockPrivateHosts && (0, import_tools.isBlockedHost)(parsed.hostname)) {
|
|
45
|
+
throw new Error(
|
|
46
|
+
`browser: host is a blocked private/loopback/metadata address: ${parsed.hostname}`
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
if (opts.allowlist !== void 0 && !(0, import_tools.hostAllowed)(parsed.hostname, opts.allowlist)) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
`browser: host not on allowlist: ${parsed.hostname}`
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
return parsed;
|
|
55
|
+
}
|
|
56
|
+
function truncateContent(text, maxBytes) {
|
|
57
|
+
const buf = Buffer.from(text, "utf8");
|
|
58
|
+
if (buf.length <= maxBytes) return text;
|
|
59
|
+
const markerBuf = Buffer.from(TRUNCATION_MARKER, "utf8");
|
|
60
|
+
const cutBytes = maxBytes - markerBuf.length;
|
|
61
|
+
return buf.subarray(0, cutBytes > 0 ? cutBytes : 0).toString("utf8") + TRUNCATION_MARKER;
|
|
62
|
+
}
|
|
63
|
+
function browserTools(page, opts) {
|
|
64
|
+
const blockPrivateHosts = opts?.blockPrivateHosts ?? true;
|
|
65
|
+
const maxContentBytes = opts?.maxContentBytes ?? DEFAULT_MAX_CONTENT_BYTES;
|
|
66
|
+
const guardOpts = { allowlist: opts?.allowlist, blockPrivateHosts };
|
|
67
|
+
const navigateTool = (0, import_core.createTool)({
|
|
68
|
+
id: "browser_navigate",
|
|
69
|
+
description: "Navigate the browser page to an http(s) URL. Only http(s) schemes are accepted. Private/loopback/metadata hosts are always rejected (SSRF defense). When an egress allowlist is configured, the host must be on it. After navigation, the final URL is re-validated to detect redirect-based escapes \u2014 the tool errors if the page was redirected off the allowlist.",
|
|
70
|
+
inputSchema: import_zod.z.object({
|
|
71
|
+
url: import_zod.z.string().describe("Absolute http(s) URL to navigate to")
|
|
72
|
+
}),
|
|
73
|
+
sideEffect: "destructive",
|
|
74
|
+
execute: async ({ input }) => {
|
|
75
|
+
assertNavigableUrl(input.url, guardOpts);
|
|
76
|
+
try {
|
|
77
|
+
await page.goto(input.url);
|
|
78
|
+
} catch (err) {
|
|
79
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
80
|
+
throw new Error(`browser_navigate: goto failed: ${msg}`);
|
|
81
|
+
}
|
|
82
|
+
const finalUrl = page.url();
|
|
83
|
+
try {
|
|
84
|
+
assertNavigableUrl(finalUrl, guardOpts);
|
|
85
|
+
} catch (err) {
|
|
86
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
87
|
+
throw new Error(
|
|
88
|
+
`browser_navigate: redirect to blocked/disallowed URL detected after navigation: ${msg}`
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
return { navigated: true, url: finalUrl };
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
const readTool = (0, import_core.createTool)({
|
|
95
|
+
id: "browser_read",
|
|
96
|
+
description: "Read the current page's title, URL, and text content. When `selector` is provided, returns innerText of that element; otherwise returns innerText of the `body` element. Content is truncated to the configured `maxContentBytes` limit.",
|
|
97
|
+
inputSchema: import_zod.z.object({
|
|
98
|
+
selector: import_zod.z.string().optional().describe("CSS selector to read (defaults to `body` if omitted)")
|
|
99
|
+
}),
|
|
100
|
+
sideEffect: "read-only",
|
|
101
|
+
execute: async ({ input }) => {
|
|
102
|
+
const title = await page.title();
|
|
103
|
+
const url = page.url();
|
|
104
|
+
const sel = input.selector ?? "body";
|
|
105
|
+
let text;
|
|
106
|
+
try {
|
|
107
|
+
text = await page.innerText(sel);
|
|
108
|
+
} catch (err) {
|
|
109
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
110
|
+
return { error: `browser_read: innerText failed for selector "${sel}": ${msg}`, title, url };
|
|
111
|
+
}
|
|
112
|
+
const truncated = truncateContent(text, maxContentBytes);
|
|
113
|
+
return { title, url, text: truncated, truncated: truncated !== text };
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
const clickTool = (0, import_core.createTool)({
|
|
117
|
+
id: "browser_click",
|
|
118
|
+
description: "Click an element on the current page identified by a CSS selector. Selector errors (element not found, ambiguous) are surfaced as tool errors, not throws.",
|
|
119
|
+
inputSchema: import_zod.z.object({
|
|
120
|
+
selector: import_zod.z.string().describe("CSS selector of the element to click")
|
|
121
|
+
}),
|
|
122
|
+
sideEffect: "destructive",
|
|
123
|
+
execute: async ({ input }) => {
|
|
124
|
+
try {
|
|
125
|
+
await page.click(input.selector);
|
|
126
|
+
return { clicked: true, selector: input.selector };
|
|
127
|
+
} catch (err) {
|
|
128
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
129
|
+
return { error: `browser_click: click failed for selector "${input.selector}": ${msg}`, clicked: false };
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
const fillTool = (0, import_core.createTool)({
|
|
134
|
+
id: "browser_fill",
|
|
135
|
+
description: "Fill an input, textarea, or contenteditable element on the current page identified by a CSS selector. Selector errors are surfaced as tool errors, not throws.",
|
|
136
|
+
inputSchema: import_zod.z.object({
|
|
137
|
+
selector: import_zod.z.string().describe("CSS selector of the input element to fill"),
|
|
138
|
+
value: import_zod.z.string().describe("Value to fill into the element")
|
|
139
|
+
}),
|
|
140
|
+
sideEffect: "destructive",
|
|
141
|
+
execute: async ({ input }) => {
|
|
142
|
+
try {
|
|
143
|
+
await page.fill(input.selector, input.value);
|
|
144
|
+
return { filled: true, selector: input.selector };
|
|
145
|
+
} catch (err) {
|
|
146
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
147
|
+
return { error: `browser_fill: fill failed for selector "${input.selector}": ${msg}`, filled: false };
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
return [navigateTool, readTool, clickTool, fillTool];
|
|
152
|
+
}
|
|
153
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
154
|
+
0 && (module.exports = {
|
|
155
|
+
browserTools,
|
|
156
|
+
hostAllowed,
|
|
157
|
+
isBlockedHost
|
|
158
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Tool } from '@eidentic/core';
|
|
2
|
+
export { hostAllowed, isBlockedHost } from '@eidentic/tools';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Minimal structural interface for a browser page that `browserTools` can operate on.
|
|
6
|
+
*
|
|
7
|
+
* Designed as a strict subset of Playwright's `Page` type — a real `playwright-core`
|
|
8
|
+
* `Page` instance satisfies this interface without any adapter. You can also pass a
|
|
9
|
+
* faithful in-memory fake for tests (see `FakePage` in the test suite).
|
|
10
|
+
*
|
|
11
|
+
* `screenshot` is intentionally optional: it is NOT surfaced as a tool in v1 (binary
|
|
12
|
+
* results don't compose cleanly with text tool results). Roadmap: a future `browser_screenshot`
|
|
13
|
+
* tool returning a base64-encoded image string.
|
|
14
|
+
*/
|
|
15
|
+
interface PageLike {
|
|
16
|
+
/** Navigate to `url`. Returns when navigation is complete. */
|
|
17
|
+
goto(url: string): Promise<unknown>;
|
|
18
|
+
/** Return the full HTML content of the current page. */
|
|
19
|
+
content(): Promise<string>;
|
|
20
|
+
/** Return the innerText of the element matching `selector`. Throws if not found. */
|
|
21
|
+
innerText(selector: string): Promise<string>;
|
|
22
|
+
/** Click the element matching `selector`. */
|
|
23
|
+
click(selector: string): Promise<void>;
|
|
24
|
+
/** Fill an input element matching `selector` with `value`. */
|
|
25
|
+
fill(selector: string, value: string): Promise<void>;
|
|
26
|
+
/** Return the current page URL string. */
|
|
27
|
+
url(): string;
|
|
28
|
+
/** Return the page title. */
|
|
29
|
+
title(): Promise<string>;
|
|
30
|
+
/** Optional: capture a screenshot as raw bytes (not exposed as a tool in v1). Roadmap item. */
|
|
31
|
+
screenshot?(): Promise<Uint8Array>;
|
|
32
|
+
}
|
|
33
|
+
interface BrowserToolsOptions {
|
|
34
|
+
/**
|
|
35
|
+
* Egress allowlist of hostnames for browser navigation (§5.6 / §10.3). A host is allowed when
|
|
36
|
+
* it equals an entry OR is a subdomain of an entry (suffix match on a dot boundary).
|
|
37
|
+
*
|
|
38
|
+
* - **Omitted (`undefined`):** no domain restriction — any public http(s) host may be navigated to.
|
|
39
|
+
* - **Empty array (`[]`):** denies ALL navigation (explicit lockdown).
|
|
40
|
+
* - **Non-empty:** restricts navigation to the listed hosts (and their subdomains).
|
|
41
|
+
*
|
|
42
|
+
* In every mode, private / loopback / link-local / cloud-metadata hosts are ALWAYS rejected
|
|
43
|
+
* (SSRF defense, see `isBlockedHost` from `@eidentic/tools`).
|
|
44
|
+
*
|
|
45
|
+
* Every navigation, including model-driven `browser_navigate` calls, is re-validated:
|
|
46
|
+
* the tool validates the target URL before `goto()`, and then re-validates the URL reported
|
|
47
|
+
* by `page.url()` AFTER navigation completes — so redirect-based escapes are detected and
|
|
48
|
+
* surfaced as tool errors.
|
|
49
|
+
*/
|
|
50
|
+
allowlist?: string[];
|
|
51
|
+
/**
|
|
52
|
+
* When true (default), private/loopback/link-local/cloud-metadata IP literals are always
|
|
53
|
+
* rejected regardless of the allowlist (SSRF defense-in-depth).
|
|
54
|
+
* Set to false only in controlled test environments.
|
|
55
|
+
*/
|
|
56
|
+
blockPrivateHosts?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Maximum number of UTF-8 bytes to include in `browser_read` results.
|
|
59
|
+
* Defaults to 512 KB. Content exceeding this limit is truncated with a marker.
|
|
60
|
+
*/
|
|
61
|
+
maxContentBytes?: number;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Sealed browser-automation tools over an injected `PageLike` page.
|
|
65
|
+
*
|
|
66
|
+
* Returns an array of Eidentic `Tool` definitions:
|
|
67
|
+
* - `browser_navigate` (destructive): validates URL + allowlist + private-host guard, then navigates.
|
|
68
|
+
* After navigation, re-validates `page.url()` to detect redirect-based escapes.
|
|
69
|
+
* - `browser_read` (read-only): returns page title + URL + innerText of a selector (or `body`),
|
|
70
|
+
* truncated to `opts.maxContentBytes`.
|
|
71
|
+
* - `browser_click` (destructive): clicks a CSS selector; selector errors are surfaced as tool errors.
|
|
72
|
+
* - `browser_fill` (destructive): fills an input by CSS selector; selector errors are tool errors.
|
|
73
|
+
*
|
|
74
|
+
* Every tool receives the page at call time via the closure — no singleton page state is held.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* import { chromium } from "playwright-core";
|
|
79
|
+
* import { browserTools } from "@eidentic/browser";
|
|
80
|
+
* import { Agent } from "eidentic";
|
|
81
|
+
*
|
|
82
|
+
* const browser = await chromium.launch();
|
|
83
|
+
* const page = await browser.newPage();
|
|
84
|
+
*
|
|
85
|
+
* const agent = new Agent({
|
|
86
|
+
* id: "web-agent",
|
|
87
|
+
* model,
|
|
88
|
+
* store,
|
|
89
|
+
* tools: browserTools(page, { allowlist: ["example.com"] }),
|
|
90
|
+
* });
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* @note No `browser_screenshot` tool in v1 — binary results don't compose with text tool results.
|
|
94
|
+
* Roadmap: a future release will return a base64-encoded image string.
|
|
95
|
+
*/
|
|
96
|
+
declare function browserTools(page: PageLike, opts?: BrowserToolsOptions): Tool[];
|
|
97
|
+
|
|
98
|
+
export { type BrowserToolsOptions, type PageLike, browserTools };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Tool } from '@eidentic/core';
|
|
2
|
+
export { hostAllowed, isBlockedHost } from '@eidentic/tools';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Minimal structural interface for a browser page that `browserTools` can operate on.
|
|
6
|
+
*
|
|
7
|
+
* Designed as a strict subset of Playwright's `Page` type — a real `playwright-core`
|
|
8
|
+
* `Page` instance satisfies this interface without any adapter. You can also pass a
|
|
9
|
+
* faithful in-memory fake for tests (see `FakePage` in the test suite).
|
|
10
|
+
*
|
|
11
|
+
* `screenshot` is intentionally optional: it is NOT surfaced as a tool in v1 (binary
|
|
12
|
+
* results don't compose cleanly with text tool results). Roadmap: a future `browser_screenshot`
|
|
13
|
+
* tool returning a base64-encoded image string.
|
|
14
|
+
*/
|
|
15
|
+
interface PageLike {
|
|
16
|
+
/** Navigate to `url`. Returns when navigation is complete. */
|
|
17
|
+
goto(url: string): Promise<unknown>;
|
|
18
|
+
/** Return the full HTML content of the current page. */
|
|
19
|
+
content(): Promise<string>;
|
|
20
|
+
/** Return the innerText of the element matching `selector`. Throws if not found. */
|
|
21
|
+
innerText(selector: string): Promise<string>;
|
|
22
|
+
/** Click the element matching `selector`. */
|
|
23
|
+
click(selector: string): Promise<void>;
|
|
24
|
+
/** Fill an input element matching `selector` with `value`. */
|
|
25
|
+
fill(selector: string, value: string): Promise<void>;
|
|
26
|
+
/** Return the current page URL string. */
|
|
27
|
+
url(): string;
|
|
28
|
+
/** Return the page title. */
|
|
29
|
+
title(): Promise<string>;
|
|
30
|
+
/** Optional: capture a screenshot as raw bytes (not exposed as a tool in v1). Roadmap item. */
|
|
31
|
+
screenshot?(): Promise<Uint8Array>;
|
|
32
|
+
}
|
|
33
|
+
interface BrowserToolsOptions {
|
|
34
|
+
/**
|
|
35
|
+
* Egress allowlist of hostnames for browser navigation (§5.6 / §10.3). A host is allowed when
|
|
36
|
+
* it equals an entry OR is a subdomain of an entry (suffix match on a dot boundary).
|
|
37
|
+
*
|
|
38
|
+
* - **Omitted (`undefined`):** no domain restriction — any public http(s) host may be navigated to.
|
|
39
|
+
* - **Empty array (`[]`):** denies ALL navigation (explicit lockdown).
|
|
40
|
+
* - **Non-empty:** restricts navigation to the listed hosts (and their subdomains).
|
|
41
|
+
*
|
|
42
|
+
* In every mode, private / loopback / link-local / cloud-metadata hosts are ALWAYS rejected
|
|
43
|
+
* (SSRF defense, see `isBlockedHost` from `@eidentic/tools`).
|
|
44
|
+
*
|
|
45
|
+
* Every navigation, including model-driven `browser_navigate` calls, is re-validated:
|
|
46
|
+
* the tool validates the target URL before `goto()`, and then re-validates the URL reported
|
|
47
|
+
* by `page.url()` AFTER navigation completes — so redirect-based escapes are detected and
|
|
48
|
+
* surfaced as tool errors.
|
|
49
|
+
*/
|
|
50
|
+
allowlist?: string[];
|
|
51
|
+
/**
|
|
52
|
+
* When true (default), private/loopback/link-local/cloud-metadata IP literals are always
|
|
53
|
+
* rejected regardless of the allowlist (SSRF defense-in-depth).
|
|
54
|
+
* Set to false only in controlled test environments.
|
|
55
|
+
*/
|
|
56
|
+
blockPrivateHosts?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Maximum number of UTF-8 bytes to include in `browser_read` results.
|
|
59
|
+
* Defaults to 512 KB. Content exceeding this limit is truncated with a marker.
|
|
60
|
+
*/
|
|
61
|
+
maxContentBytes?: number;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Sealed browser-automation tools over an injected `PageLike` page.
|
|
65
|
+
*
|
|
66
|
+
* Returns an array of Eidentic `Tool` definitions:
|
|
67
|
+
* - `browser_navigate` (destructive): validates URL + allowlist + private-host guard, then navigates.
|
|
68
|
+
* After navigation, re-validates `page.url()` to detect redirect-based escapes.
|
|
69
|
+
* - `browser_read` (read-only): returns page title + URL + innerText of a selector (or `body`),
|
|
70
|
+
* truncated to `opts.maxContentBytes`.
|
|
71
|
+
* - `browser_click` (destructive): clicks a CSS selector; selector errors are surfaced as tool errors.
|
|
72
|
+
* - `browser_fill` (destructive): fills an input by CSS selector; selector errors are tool errors.
|
|
73
|
+
*
|
|
74
|
+
* Every tool receives the page at call time via the closure — no singleton page state is held.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* import { chromium } from "playwright-core";
|
|
79
|
+
* import { browserTools } from "@eidentic/browser";
|
|
80
|
+
* import { Agent } from "eidentic";
|
|
81
|
+
*
|
|
82
|
+
* const browser = await chromium.launch();
|
|
83
|
+
* const page = await browser.newPage();
|
|
84
|
+
*
|
|
85
|
+
* const agent = new Agent({
|
|
86
|
+
* id: "web-agent",
|
|
87
|
+
* model,
|
|
88
|
+
* store,
|
|
89
|
+
* tools: browserTools(page, { allowlist: ["example.com"] }),
|
|
90
|
+
* });
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* @note No `browser_screenshot` tool in v1 — binary results don't compose with text tool results.
|
|
94
|
+
* Roadmap: a future release will return a base64-encoded image string.
|
|
95
|
+
*/
|
|
96
|
+
declare function browserTools(page: PageLike, opts?: BrowserToolsOptions): Tool[];
|
|
97
|
+
|
|
98
|
+
export { type BrowserToolsOptions, type PageLike, browserTools };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { createTool } from "@eidentic/core";
|
|
4
|
+
import { hostAllowed, isBlockedHost } from "@eidentic/tools";
|
|
5
|
+
import { hostAllowed as hostAllowed2, isBlockedHost as isBlockedHost2 } from "@eidentic/tools";
|
|
6
|
+
var DEFAULT_MAX_CONTENT_BYTES = 512 * 1024;
|
|
7
|
+
var TRUNCATION_MARKER = "\n\u2026[content truncated]";
|
|
8
|
+
function assertNavigableUrl(rawUrl, opts) {
|
|
9
|
+
let parsed;
|
|
10
|
+
try {
|
|
11
|
+
parsed = new URL(rawUrl);
|
|
12
|
+
} catch {
|
|
13
|
+
throw new Error(`browser: invalid URL`);
|
|
14
|
+
}
|
|
15
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
16
|
+
throw new Error(`browser: only http(s) URLs are allowed (got ${parsed.protocol})`);
|
|
17
|
+
}
|
|
18
|
+
if (opts.blockPrivateHosts && isBlockedHost(parsed.hostname)) {
|
|
19
|
+
throw new Error(
|
|
20
|
+
`browser: host is a blocked private/loopback/metadata address: ${parsed.hostname}`
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
if (opts.allowlist !== void 0 && !hostAllowed(parsed.hostname, opts.allowlist)) {
|
|
24
|
+
throw new Error(
|
|
25
|
+
`browser: host not on allowlist: ${parsed.hostname}`
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
return parsed;
|
|
29
|
+
}
|
|
30
|
+
function truncateContent(text, maxBytes) {
|
|
31
|
+
const buf = Buffer.from(text, "utf8");
|
|
32
|
+
if (buf.length <= maxBytes) return text;
|
|
33
|
+
const markerBuf = Buffer.from(TRUNCATION_MARKER, "utf8");
|
|
34
|
+
const cutBytes = maxBytes - markerBuf.length;
|
|
35
|
+
return buf.subarray(0, cutBytes > 0 ? cutBytes : 0).toString("utf8") + TRUNCATION_MARKER;
|
|
36
|
+
}
|
|
37
|
+
function browserTools(page, opts) {
|
|
38
|
+
const blockPrivateHosts = opts?.blockPrivateHosts ?? true;
|
|
39
|
+
const maxContentBytes = opts?.maxContentBytes ?? DEFAULT_MAX_CONTENT_BYTES;
|
|
40
|
+
const guardOpts = { allowlist: opts?.allowlist, blockPrivateHosts };
|
|
41
|
+
const navigateTool = createTool({
|
|
42
|
+
id: "browser_navigate",
|
|
43
|
+
description: "Navigate the browser page to an http(s) URL. Only http(s) schemes are accepted. Private/loopback/metadata hosts are always rejected (SSRF defense). When an egress allowlist is configured, the host must be on it. After navigation, the final URL is re-validated to detect redirect-based escapes \u2014 the tool errors if the page was redirected off the allowlist.",
|
|
44
|
+
inputSchema: z.object({
|
|
45
|
+
url: z.string().describe("Absolute http(s) URL to navigate to")
|
|
46
|
+
}),
|
|
47
|
+
sideEffect: "destructive",
|
|
48
|
+
execute: async ({ input }) => {
|
|
49
|
+
assertNavigableUrl(input.url, guardOpts);
|
|
50
|
+
try {
|
|
51
|
+
await page.goto(input.url);
|
|
52
|
+
} catch (err) {
|
|
53
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
54
|
+
throw new Error(`browser_navigate: goto failed: ${msg}`);
|
|
55
|
+
}
|
|
56
|
+
const finalUrl = page.url();
|
|
57
|
+
try {
|
|
58
|
+
assertNavigableUrl(finalUrl, guardOpts);
|
|
59
|
+
} catch (err) {
|
|
60
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
61
|
+
throw new Error(
|
|
62
|
+
`browser_navigate: redirect to blocked/disallowed URL detected after navigation: ${msg}`
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
return { navigated: true, url: finalUrl };
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
const readTool = createTool({
|
|
69
|
+
id: "browser_read",
|
|
70
|
+
description: "Read the current page's title, URL, and text content. When `selector` is provided, returns innerText of that element; otherwise returns innerText of the `body` element. Content is truncated to the configured `maxContentBytes` limit.",
|
|
71
|
+
inputSchema: z.object({
|
|
72
|
+
selector: z.string().optional().describe("CSS selector to read (defaults to `body` if omitted)")
|
|
73
|
+
}),
|
|
74
|
+
sideEffect: "read-only",
|
|
75
|
+
execute: async ({ input }) => {
|
|
76
|
+
const title = await page.title();
|
|
77
|
+
const url = page.url();
|
|
78
|
+
const sel = input.selector ?? "body";
|
|
79
|
+
let text;
|
|
80
|
+
try {
|
|
81
|
+
text = await page.innerText(sel);
|
|
82
|
+
} catch (err) {
|
|
83
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
84
|
+
return { error: `browser_read: innerText failed for selector "${sel}": ${msg}`, title, url };
|
|
85
|
+
}
|
|
86
|
+
const truncated = truncateContent(text, maxContentBytes);
|
|
87
|
+
return { title, url, text: truncated, truncated: truncated !== text };
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
const clickTool = createTool({
|
|
91
|
+
id: "browser_click",
|
|
92
|
+
description: "Click an element on the current page identified by a CSS selector. Selector errors (element not found, ambiguous) are surfaced as tool errors, not throws.",
|
|
93
|
+
inputSchema: z.object({
|
|
94
|
+
selector: z.string().describe("CSS selector of the element to click")
|
|
95
|
+
}),
|
|
96
|
+
sideEffect: "destructive",
|
|
97
|
+
execute: async ({ input }) => {
|
|
98
|
+
try {
|
|
99
|
+
await page.click(input.selector);
|
|
100
|
+
return { clicked: true, selector: input.selector };
|
|
101
|
+
} catch (err) {
|
|
102
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
103
|
+
return { error: `browser_click: click failed for selector "${input.selector}": ${msg}`, clicked: false };
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
const fillTool = createTool({
|
|
108
|
+
id: "browser_fill",
|
|
109
|
+
description: "Fill an input, textarea, or contenteditable element on the current page identified by a CSS selector. Selector errors are surfaced as tool errors, not throws.",
|
|
110
|
+
inputSchema: z.object({
|
|
111
|
+
selector: z.string().describe("CSS selector of the input element to fill"),
|
|
112
|
+
value: z.string().describe("Value to fill into the element")
|
|
113
|
+
}),
|
|
114
|
+
sideEffect: "destructive",
|
|
115
|
+
execute: async ({ input }) => {
|
|
116
|
+
try {
|
|
117
|
+
await page.fill(input.selector, input.value);
|
|
118
|
+
return { filled: true, selector: input.selector };
|
|
119
|
+
} catch (err) {
|
|
120
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
121
|
+
return { error: `browser_fill: fill failed for selector "${input.selector}": ${msg}`, filled: false };
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
return [navigateTool, readTool, clickTool, fillTool];
|
|
126
|
+
}
|
|
127
|
+
export {
|
|
128
|
+
browserTools,
|
|
129
|
+
hostAllowed2 as hostAllowed,
|
|
130
|
+
isBlockedHost2 as isBlockedHost
|
|
131
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@eidentic/browser",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/eidentic/eidentic.git",
|
|
12
|
+
"directory": "packages/browser"
|
|
13
|
+
},
|
|
14
|
+
"main": "./dist/index.cjs",
|
|
15
|
+
"module": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js",
|
|
21
|
+
"require": "./dist/index.cjs"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"sideEffects": false,
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"LICENSE",
|
|
28
|
+
"README.md"
|
|
29
|
+
],
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"zod": "^4.0.0",
|
|
32
|
+
"@eidentic/core": "0.1.0",
|
|
33
|
+
"@eidentic/tools": "0.1.0"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"playwright-core": ">=1.40"
|
|
37
|
+
},
|
|
38
|
+
"peerDependenciesMeta": {
|
|
39
|
+
"playwright-core": {
|
|
40
|
+
"optional": true
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"playwright-core": "^1.52.0"
|
|
45
|
+
},
|
|
46
|
+
"description": "Sealed browser-automation tools for Eidentic — first-class sandboxed browser tools over an injected Playwright-like page (PageLike interface).",
|
|
47
|
+
"keywords": [
|
|
48
|
+
"ai",
|
|
49
|
+
"agents",
|
|
50
|
+
"typescript",
|
|
51
|
+
"eidentic",
|
|
52
|
+
"browser",
|
|
53
|
+
"playwright",
|
|
54
|
+
"automation",
|
|
55
|
+
"tools"
|
|
56
|
+
],
|
|
57
|
+
"homepage": "https://github.com/eidentic/eidentic#readme",
|
|
58
|
+
"bugs": {
|
|
59
|
+
"url": "https://github.com/eidentic/eidentic/issues"
|
|
60
|
+
},
|
|
61
|
+
"engines": {
|
|
62
|
+
"node": ">=22"
|
|
63
|
+
},
|
|
64
|
+
"scripts": {
|
|
65
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --clean",
|
|
66
|
+
"typecheck": "tsc --noEmit"
|
|
67
|
+
}
|
|
68
|
+
}
|