@giselles-ai/browser-tool 0.1.2 → 0.1.4
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/dist/index.d.ts +6 -6
- package/dist/index.js +5 -5
- package/dist/mcp-server/index.js +34 -34
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ type ExecutionReport = {
|
|
|
33
33
|
warnings: string[];
|
|
34
34
|
};
|
|
35
35
|
type BrowserToolStatus = "idle" | "snapshotting" | "planning" | "ready" | "applying" | "error";
|
|
36
|
-
type
|
|
36
|
+
type RelayErrorCode = "UNAUTHORIZED" | "NO_BROWSER" | "TIMEOUT" | "INVALID_RESPONSE" | "NOT_FOUND" | "INTERNAL";
|
|
37
37
|
declare const fieldKindSchema: z.ZodEnum<{
|
|
38
38
|
text: "text";
|
|
39
39
|
textarea: "textarea";
|
|
@@ -128,7 +128,7 @@ declare const executeRequestSchema: z.ZodObject<{
|
|
|
128
128
|
options: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
129
129
|
}, z.core.$strip>>;
|
|
130
130
|
}, z.core.$strip>;
|
|
131
|
-
declare const
|
|
131
|
+
declare const relayRequestSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
132
132
|
type: z.ZodLiteral<"snapshot_request">;
|
|
133
133
|
requestId: z.ZodString;
|
|
134
134
|
instruction: z.ZodString;
|
|
@@ -201,7 +201,7 @@ declare const errorResponseSchema: z.ZodObject<{
|
|
|
201
201
|
requestId: z.ZodString;
|
|
202
202
|
message: z.ZodString;
|
|
203
203
|
}, z.core.$strip>;
|
|
204
|
-
declare const
|
|
204
|
+
declare const relayResponseSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
205
205
|
type: z.ZodLiteral<"snapshot_response">;
|
|
206
206
|
requestId: z.ZodString;
|
|
207
207
|
fields: z.ZodArray<z.ZodObject<{
|
|
@@ -275,7 +275,7 @@ declare const dispatchErrorSchema: z.ZodObject<{
|
|
|
275
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
276
|
message: z.ZodString;
|
|
277
277
|
}, z.core.$strip>;
|
|
278
|
-
type
|
|
279
|
-
type
|
|
278
|
+
type RelayRequest = z.infer<typeof relayRequestSchema>;
|
|
279
|
+
type RelayResponse = z.infer<typeof relayResponseSchema>;
|
|
280
280
|
|
|
281
|
-
export { type
|
|
281
|
+
export { type BrowserToolAction, type BrowserToolStatus, type ClickAction, type ExecutionReport, type FieldKind, type FillAction, type RelayErrorCode, type RelayRequest, type RelayResponse, type SelectAction, type SnapshotField, browserToolActionSchema, clickActionSchema, dispatchErrorSchema, dispatchSuccessSchema, errorResponseSchema, executeRequestSchema, executeResponseSchema, executionReportSchema, fieldKindSchema, fillActionSchema, relayRequestSchema, relayResponseSchema, selectActionSchema, snapshotFieldSchema, snapshotRequestSchema, snapshotResponseSchema };
|
package/dist/index.js
CHANGED
|
@@ -54,7 +54,7 @@ var executeRequestSchema = z.object({
|
|
|
54
54
|
actions: z.array(browserToolActionSchema),
|
|
55
55
|
fields: z.array(snapshotFieldSchema)
|
|
56
56
|
});
|
|
57
|
-
var
|
|
57
|
+
var relayRequestSchema = z.discriminatedUnion("type", [
|
|
58
58
|
snapshotRequestSchema,
|
|
59
59
|
executeRequestSchema
|
|
60
60
|
]);
|
|
@@ -73,14 +73,14 @@ var errorResponseSchema = z.object({
|
|
|
73
73
|
requestId: z.string().min(1),
|
|
74
74
|
message: z.string().min(1)
|
|
75
75
|
});
|
|
76
|
-
var
|
|
76
|
+
var relayResponseSchema = z.discriminatedUnion("type", [
|
|
77
77
|
snapshotResponseSchema,
|
|
78
78
|
executeResponseSchema,
|
|
79
79
|
errorResponseSchema
|
|
80
80
|
]);
|
|
81
81
|
var dispatchSuccessSchema = z.object({
|
|
82
82
|
ok: z.literal(true),
|
|
83
|
-
response:
|
|
83
|
+
response: relayResponseSchema
|
|
84
84
|
});
|
|
85
85
|
var dispatchErrorSchema = z.object({
|
|
86
86
|
ok: z.literal(false),
|
|
@@ -95,8 +95,6 @@ var dispatchErrorSchema = z.object({
|
|
|
95
95
|
message: z.string()
|
|
96
96
|
});
|
|
97
97
|
export {
|
|
98
|
-
bridgeRequestSchema,
|
|
99
|
-
bridgeResponseSchema,
|
|
100
98
|
browserToolActionSchema,
|
|
101
99
|
clickActionSchema,
|
|
102
100
|
dispatchErrorSchema,
|
|
@@ -107,6 +105,8 @@ export {
|
|
|
107
105
|
executionReportSchema,
|
|
108
106
|
fieldKindSchema,
|
|
109
107
|
fillActionSchema,
|
|
108
|
+
relayRequestSchema,
|
|
109
|
+
relayResponseSchema,
|
|
110
110
|
selectActionSchema,
|
|
111
111
|
snapshotFieldSchema,
|
|
112
112
|
snapshotRequestSchema,
|
package/dist/mcp-server/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
3
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
4
|
|
|
5
|
-
// src/mcp-server/
|
|
5
|
+
// src/mcp-server/relay-client.ts
|
|
6
6
|
import { randomUUID } from "crypto";
|
|
7
7
|
|
|
8
8
|
// src/types.ts
|
|
@@ -61,7 +61,7 @@ var executeRequestSchema = z.object({
|
|
|
61
61
|
actions: z.array(browserToolActionSchema),
|
|
62
62
|
fields: z.array(snapshotFieldSchema)
|
|
63
63
|
});
|
|
64
|
-
var
|
|
64
|
+
var relayRequestSchema = z.discriminatedUnion("type", [
|
|
65
65
|
snapshotRequestSchema,
|
|
66
66
|
executeRequestSchema
|
|
67
67
|
]);
|
|
@@ -80,14 +80,14 @@ var errorResponseSchema = z.object({
|
|
|
80
80
|
requestId: z.string().min(1),
|
|
81
81
|
message: z.string().min(1)
|
|
82
82
|
});
|
|
83
|
-
var
|
|
83
|
+
var relayResponseSchema = z.discriminatedUnion("type", [
|
|
84
84
|
snapshotResponseSchema,
|
|
85
85
|
executeResponseSchema,
|
|
86
86
|
errorResponseSchema
|
|
87
87
|
]);
|
|
88
88
|
var dispatchSuccessSchema = z.object({
|
|
89
89
|
ok: z.literal(true),
|
|
90
|
-
response:
|
|
90
|
+
response: relayResponseSchema
|
|
91
91
|
});
|
|
92
92
|
var dispatchErrorSchema = z.object({
|
|
93
93
|
ok: z.literal(false),
|
|
@@ -102,7 +102,7 @@ var dispatchErrorSchema = z.object({
|
|
|
102
102
|
message: z.string()
|
|
103
103
|
});
|
|
104
104
|
|
|
105
|
-
// src/mcp-server/
|
|
105
|
+
// src/mcp-server/relay-client.ts
|
|
106
106
|
function requiredEnv(name) {
|
|
107
107
|
const value = process.env[name]?.trim();
|
|
108
108
|
if (!value) {
|
|
@@ -113,15 +113,15 @@ function requiredEnv(name) {
|
|
|
113
113
|
function trimTrailingSlash(input) {
|
|
114
114
|
return input.replace(/\/+$/, "");
|
|
115
115
|
}
|
|
116
|
-
var
|
|
117
|
-
|
|
116
|
+
var RelayClient = class {
|
|
117
|
+
url;
|
|
118
118
|
sessionId;
|
|
119
119
|
token;
|
|
120
120
|
timeoutMs;
|
|
121
121
|
vercelProtectionBypass;
|
|
122
122
|
giselleProtectionBypass;
|
|
123
123
|
constructor(input) {
|
|
124
|
-
this.
|
|
124
|
+
this.url = trimTrailingSlash(input.url);
|
|
125
125
|
this.sessionId = input.sessionId;
|
|
126
126
|
this.token = input.token;
|
|
127
127
|
this.timeoutMs = input.timeoutMs ?? 2e4;
|
|
@@ -136,7 +136,7 @@ var BridgeClient = class {
|
|
|
136
136
|
document: input.document
|
|
137
137
|
});
|
|
138
138
|
if (response.type !== "snapshot_response") {
|
|
139
|
-
throw new Error(`Unexpected
|
|
139
|
+
throw new Error(`Unexpected relay response type: ${response.type}`);
|
|
140
140
|
}
|
|
141
141
|
return response.fields;
|
|
142
142
|
}
|
|
@@ -148,12 +148,12 @@ var BridgeClient = class {
|
|
|
148
148
|
fields: input.fields
|
|
149
149
|
});
|
|
150
150
|
if (response.type !== "execute_response") {
|
|
151
|
-
throw new Error(`Unexpected
|
|
151
|
+
throw new Error(`Unexpected relay response type: ${response.type}`);
|
|
152
152
|
}
|
|
153
153
|
return response.report;
|
|
154
154
|
}
|
|
155
155
|
async dispatch(request) {
|
|
156
|
-
const payload =
|
|
156
|
+
const payload = relayRequestSchema.parse(request);
|
|
157
157
|
let response;
|
|
158
158
|
try {
|
|
159
159
|
const headers = {
|
|
@@ -165,11 +165,11 @@ var BridgeClient = class {
|
|
|
165
165
|
if (this.giselleProtectionBypass) {
|
|
166
166
|
headers["x-giselle-protection-bypass"] = this.giselleProtectionBypass;
|
|
167
167
|
}
|
|
168
|
-
response = await fetch(`${this.
|
|
168
|
+
response = await fetch(`${this.url}`, {
|
|
169
169
|
method: "POST",
|
|
170
170
|
headers,
|
|
171
171
|
body: JSON.stringify({
|
|
172
|
-
type: "
|
|
172
|
+
type: "relay.dispatch",
|
|
173
173
|
sessionId: this.sessionId,
|
|
174
174
|
token: this.token,
|
|
175
175
|
timeoutMs: this.timeoutMs,
|
|
@@ -180,9 +180,9 @@ var BridgeClient = class {
|
|
|
180
180
|
const message = error instanceof Error ? error.message : String(error);
|
|
181
181
|
throw new Error(
|
|
182
182
|
[
|
|
183
|
-
"
|
|
184
|
-
`
|
|
185
|
-
"Ensure
|
|
183
|
+
"Relay dispatch network request failed.",
|
|
184
|
+
`url=${this.url}`,
|
|
185
|
+
"Ensure BROWSER_TOOL_RELAY_URL is reachable from the sandbox runtime.",
|
|
186
186
|
`cause=${message}`
|
|
187
187
|
].join(" ")
|
|
188
188
|
);
|
|
@@ -194,28 +194,28 @@ var BridgeClient = class {
|
|
|
194
194
|
}
|
|
195
195
|
const success = dispatchSuccessSchema.safeParse(body);
|
|
196
196
|
if (!success.success) {
|
|
197
|
-
throw new Error("
|
|
197
|
+
throw new Error("Relay dispatch returned an unexpected payload.");
|
|
198
198
|
}
|
|
199
199
|
if (!response.ok) {
|
|
200
|
-
throw new Error(`
|
|
200
|
+
throw new Error(`Relay dispatch failed with HTTP ${response.status}.`);
|
|
201
201
|
}
|
|
202
|
-
const parsedResponse =
|
|
202
|
+
const parsedResponse = relayResponseSchema.parse(success.data.response);
|
|
203
203
|
return parsedResponse;
|
|
204
204
|
}
|
|
205
205
|
};
|
|
206
|
-
function
|
|
206
|
+
function createRelayClientFromEnv() {
|
|
207
207
|
const vercelProtectionBypass = process.env.VERCEL_PROTECTION_BYPASS;
|
|
208
208
|
const giselleProtectionBypass = process.env.GISELLE_PROTECTION_BYPASS;
|
|
209
209
|
console.error(
|
|
210
|
-
`[
|
|
210
|
+
`[relay-client] VERCEL_PROTECTION_BYPASS=${vercelProtectionBypass?.trim() ? "(set)" : "(unset)"}`
|
|
211
211
|
);
|
|
212
212
|
console.error(
|
|
213
|
-
`[
|
|
213
|
+
`[relay-client] GISELLE_PROTECTION_BYPASS=${giselleProtectionBypass?.trim() ? "(set)" : "(unset)"}`
|
|
214
214
|
);
|
|
215
|
-
return new
|
|
216
|
-
|
|
217
|
-
sessionId: requiredEnv("
|
|
218
|
-
token: requiredEnv("
|
|
215
|
+
return new RelayClient({
|
|
216
|
+
url: requiredEnv("BROWSER_TOOL_RELAY_URL"),
|
|
217
|
+
sessionId: requiredEnv("BROWSER_TOOL_RELAY_SESSION_ID"),
|
|
218
|
+
token: requiredEnv("BROWSER_TOOL_RELAY_TOKEN"),
|
|
219
219
|
vercelProtectionBypass,
|
|
220
220
|
giselleProtectionBypass
|
|
221
221
|
});
|
|
@@ -228,17 +228,17 @@ var executeFormActionsInputShape = {
|
|
|
228
228
|
fields: z2.array(snapshotFieldSchema)
|
|
229
229
|
};
|
|
230
230
|
var executeFormActionsInputSchema = z2.object(executeFormActionsInputShape);
|
|
231
|
-
async function runExecuteFormActions(input,
|
|
231
|
+
async function runExecuteFormActions(input, relayClient) {
|
|
232
232
|
const parsed = executeFormActionsInputSchema.parse(input);
|
|
233
|
-
return await
|
|
233
|
+
return await relayClient.requestExecute({
|
|
234
234
|
actions: parsed.actions,
|
|
235
235
|
fields: parsed.fields
|
|
236
236
|
});
|
|
237
237
|
}
|
|
238
238
|
|
|
239
239
|
// src/mcp-server/tools/get-form-snapshot.ts
|
|
240
|
-
async function runGetFormSnapshot(
|
|
241
|
-
const fields = await
|
|
240
|
+
async function runGetFormSnapshot(relayClient) {
|
|
241
|
+
const fields = await relayClient.requestSnapshot({
|
|
242
242
|
instruction: "snapshot"
|
|
243
243
|
});
|
|
244
244
|
return { fields };
|
|
@@ -274,8 +274,8 @@ var server = new McpServer(
|
|
|
274
274
|
);
|
|
275
275
|
server.registerTool("getFormSnapshot", {}, async () => {
|
|
276
276
|
try {
|
|
277
|
-
const
|
|
278
|
-
const output = await runGetFormSnapshot(
|
|
277
|
+
const relayClient = createRelayClientFromEnv();
|
|
278
|
+
const output = await runGetFormSnapshot(relayClient);
|
|
279
279
|
return {
|
|
280
280
|
content: [
|
|
281
281
|
{
|
|
@@ -308,8 +308,8 @@ server.registerTool(
|
|
|
308
308
|
{ inputSchema: executeFormActionsInputShape },
|
|
309
309
|
async (input) => {
|
|
310
310
|
try {
|
|
311
|
-
const
|
|
312
|
-
const output = await runExecuteFormActions(input,
|
|
311
|
+
const relayClient = createRelayClientFromEnv();
|
|
312
|
+
const output = await runExecuteFormActions(input, relayClient);
|
|
313
313
|
return {
|
|
314
314
|
content: [
|
|
315
315
|
{
|