@giselles-ai/browser-tool 0.1.17 → 0.1.18
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/relay/index.d.ts +89 -1
- package/dist/relay/index.js +55 -0
- package/package.json +1 -1
package/dist/relay/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Redis from 'ioredis';
|
|
2
|
+
import { z } from 'zod';
|
|
2
3
|
|
|
3
4
|
declare function createRelayHandler(): {
|
|
4
5
|
GET: (request: Request) => Promise<Response>;
|
|
@@ -7,6 +8,79 @@ declare function createRelayHandler(): {
|
|
|
7
8
|
};
|
|
8
9
|
|
|
9
10
|
type RelayErrorCode = "UNAUTHORIZED" | "NO_BROWSER" | "TIMEOUT" | "INVALID_RESPONSE" | "NOT_FOUND" | "INTERNAL";
|
|
11
|
+
declare const relayRequestSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
12
|
+
type: z.ZodLiteral<"snapshot_request">;
|
|
13
|
+
requestId: z.ZodString;
|
|
14
|
+
instruction: z.ZodString;
|
|
15
|
+
document: z.ZodOptional<z.ZodString>;
|
|
16
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
17
|
+
type: z.ZodLiteral<"execute_request">;
|
|
18
|
+
requestId: z.ZodString;
|
|
19
|
+
actions: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
20
|
+
action: z.ZodLiteral<"fill">;
|
|
21
|
+
fieldId: z.ZodString;
|
|
22
|
+
value: z.ZodString;
|
|
23
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
24
|
+
action: z.ZodLiteral<"click">;
|
|
25
|
+
fieldId: z.ZodString;
|
|
26
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
27
|
+
action: z.ZodLiteral<"select">;
|
|
28
|
+
fieldId: z.ZodString;
|
|
29
|
+
value: z.ZodString;
|
|
30
|
+
}, z.core.$strip>], "action">>;
|
|
31
|
+
fields: z.ZodArray<z.ZodObject<{
|
|
32
|
+
fieldId: z.ZodString;
|
|
33
|
+
selector: z.ZodString;
|
|
34
|
+
kind: z.ZodEnum<{
|
|
35
|
+
text: "text";
|
|
36
|
+
textarea: "textarea";
|
|
37
|
+
select: "select";
|
|
38
|
+
checkbox: "checkbox";
|
|
39
|
+
radio: "radio";
|
|
40
|
+
}>;
|
|
41
|
+
label: z.ZodString;
|
|
42
|
+
name: z.ZodOptional<z.ZodString>;
|
|
43
|
+
required: z.ZodBoolean;
|
|
44
|
+
placeholder: z.ZodOptional<z.ZodString>;
|
|
45
|
+
currentValue: z.ZodUnion<readonly [z.ZodString, z.ZodBoolean]>;
|
|
46
|
+
options: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
47
|
+
}, z.core.$strip>>;
|
|
48
|
+
}, z.core.$strip>], "type">;
|
|
49
|
+
declare const relayResponseSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
50
|
+
type: z.ZodLiteral<"snapshot_response">;
|
|
51
|
+
requestId: z.ZodString;
|
|
52
|
+
fields: z.ZodArray<z.ZodObject<{
|
|
53
|
+
fieldId: z.ZodString;
|
|
54
|
+
selector: z.ZodString;
|
|
55
|
+
kind: z.ZodEnum<{
|
|
56
|
+
text: "text";
|
|
57
|
+
textarea: "textarea";
|
|
58
|
+
select: "select";
|
|
59
|
+
checkbox: "checkbox";
|
|
60
|
+
radio: "radio";
|
|
61
|
+
}>;
|
|
62
|
+
label: z.ZodString;
|
|
63
|
+
name: z.ZodOptional<z.ZodString>;
|
|
64
|
+
required: z.ZodBoolean;
|
|
65
|
+
placeholder: z.ZodOptional<z.ZodString>;
|
|
66
|
+
currentValue: z.ZodUnion<readonly [z.ZodString, z.ZodBoolean]>;
|
|
67
|
+
options: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
68
|
+
}, z.core.$strip>>;
|
|
69
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
70
|
+
type: z.ZodLiteral<"execute_response">;
|
|
71
|
+
requestId: z.ZodString;
|
|
72
|
+
report: z.ZodObject<{
|
|
73
|
+
applied: z.ZodNumber;
|
|
74
|
+
skipped: z.ZodNumber;
|
|
75
|
+
warnings: z.ZodArray<z.ZodString>;
|
|
76
|
+
}, z.core.$strip>;
|
|
77
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
78
|
+
type: z.ZodLiteral<"error_response">;
|
|
79
|
+
requestId: z.ZodString;
|
|
80
|
+
message: z.ZodString;
|
|
81
|
+
}, z.core.$strip>], "type">;
|
|
82
|
+
type RelayRequest = z.infer<typeof relayRequestSchema>;
|
|
83
|
+
type RelayResponse = z.infer<typeof relayResponseSchema>;
|
|
10
84
|
|
|
11
85
|
declare global {
|
|
12
86
|
var __browserToolRelayRedis: Redis | undefined;
|
|
@@ -23,4 +97,18 @@ declare function createRelaySession(): Promise<{
|
|
|
23
97
|
}>;
|
|
24
98
|
declare function toRelayError(error: unknown): RelayStoreError;
|
|
25
99
|
|
|
26
|
-
|
|
100
|
+
type RelayRequestSubscription = {
|
|
101
|
+
nextRequest(): Promise<RelayRequest>;
|
|
102
|
+
close(): Promise<void>;
|
|
103
|
+
};
|
|
104
|
+
declare function createRelayRequestSubscription(input: {
|
|
105
|
+
sessionId: string;
|
|
106
|
+
token: string;
|
|
107
|
+
}): Promise<RelayRequestSubscription>;
|
|
108
|
+
declare function sendRelayResponse(input: {
|
|
109
|
+
sessionId: string;
|
|
110
|
+
token: string;
|
|
111
|
+
response: RelayResponse;
|
|
112
|
+
}): Promise<void>;
|
|
113
|
+
|
|
114
|
+
export { type RelayRequestSubscription, createRelayHandler, createRelayRequestSubscription, createRelaySession, sendRelayResponse, toRelayError };
|
package/dist/relay/index.js
CHANGED
|
@@ -789,8 +789,63 @@ function createRelayHandler() {
|
|
|
789
789
|
OPTIONS: (request) => new Response(null, { status: 204, headers: corsHeaders(request) })
|
|
790
790
|
};
|
|
791
791
|
}
|
|
792
|
+
|
|
793
|
+
// src/relay/request-subscription.ts
|
|
794
|
+
async function createRelayRequestSubscription(input) {
|
|
795
|
+
await assertRelaySession(input.sessionId, input.token);
|
|
796
|
+
const subscriber = createRelaySubscriber();
|
|
797
|
+
const channel = relayRequestChannel(input.sessionId);
|
|
798
|
+
await subscriber.subscribe(channel);
|
|
799
|
+
const nextRequest = () => {
|
|
800
|
+
return new Promise((resolve, reject) => {
|
|
801
|
+
const onMessage = (_channel, message) => {
|
|
802
|
+
if (_channel !== channel) {
|
|
803
|
+
return;
|
|
804
|
+
}
|
|
805
|
+
let parsed = null;
|
|
806
|
+
try {
|
|
807
|
+
const raw = JSON.parse(message);
|
|
808
|
+
const safe = relayRequestSchema.safeParse(raw);
|
|
809
|
+
if (!safe.success) {
|
|
810
|
+
return;
|
|
811
|
+
}
|
|
812
|
+
parsed = safe.data;
|
|
813
|
+
} catch {
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
cleanup();
|
|
817
|
+
resolve(parsed);
|
|
818
|
+
};
|
|
819
|
+
const onError = (error) => {
|
|
820
|
+
cleanup();
|
|
821
|
+
reject(error);
|
|
822
|
+
};
|
|
823
|
+
const cleanup = () => {
|
|
824
|
+
subscriber.off("message", onMessage);
|
|
825
|
+
subscriber.off("error", onError);
|
|
826
|
+
};
|
|
827
|
+
subscriber.on("message", onMessage);
|
|
828
|
+
subscriber.on("error", onError);
|
|
829
|
+
});
|
|
830
|
+
};
|
|
831
|
+
const close = async () => {
|
|
832
|
+
await subscriber.unsubscribe(channel).catch(() => void 0);
|
|
833
|
+
await subscriber.quit().catch(() => {
|
|
834
|
+
subscriber.disconnect();
|
|
835
|
+
});
|
|
836
|
+
};
|
|
837
|
+
return {
|
|
838
|
+
nextRequest,
|
|
839
|
+
close
|
|
840
|
+
};
|
|
841
|
+
}
|
|
842
|
+
async function sendRelayResponse(input) {
|
|
843
|
+
await resolveRelayResponse(input);
|
|
844
|
+
}
|
|
792
845
|
export {
|
|
793
846
|
createRelayHandler,
|
|
847
|
+
createRelayRequestSubscription,
|
|
794
848
|
createRelaySession,
|
|
849
|
+
sendRelayResponse,
|
|
795
850
|
toRelayError
|
|
796
851
|
};
|