@usecrow/client 0.1.19 → 0.1.20
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/browser.cjs +284 -0
- package/dist/browser.cjs.map +1 -0
- package/dist/browser.d.cts +52 -0
- package/dist/browser.d.ts +52 -0
- package/dist/browser.js +278 -0
- package/dist/browser.js.map +1 -0
- package/dist/browserUse-CZNpayEF.d.cts +188 -0
- package/dist/browserUse-CZNpayEF.d.ts +188 -0
- package/dist/index.cjs +243 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -135
- package/dist/index.d.ts +3 -135
- package/dist/index.js +243 -1
- package/dist/index.js.map +1 -1
- package/package.json +17 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,137 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
interface CrowClientConfig {
|
|
5
|
-
/** Your Crow product ID from the dashboard */
|
|
6
|
-
productId: string;
|
|
7
|
-
/** API URL (defaults to https://api.usecrow.org) */
|
|
8
|
-
apiUrl?: string;
|
|
9
|
-
/** Default model to use */
|
|
10
|
-
model?: string;
|
|
11
|
-
}
|
|
12
|
-
interface IdentifyOptions {
|
|
13
|
-
/** JWT token from your backend for user verification */
|
|
14
|
-
token: string;
|
|
15
|
-
/** Optional user display name */
|
|
16
|
-
name?: string;
|
|
17
|
-
/** Optional user email */
|
|
18
|
-
email?: string;
|
|
19
|
-
/** Any additional metadata */
|
|
20
|
-
[key: string]: unknown;
|
|
21
|
-
}
|
|
22
|
-
interface IdentityState {
|
|
23
|
-
token: string | null;
|
|
24
|
-
metadata: Record<string, unknown>;
|
|
25
|
-
isVerified: boolean;
|
|
26
|
-
}
|
|
27
|
-
interface Message {
|
|
28
|
-
id: string;
|
|
29
|
-
content: string;
|
|
30
|
-
role: 'user' | 'assistant';
|
|
31
|
-
timestamp: Date;
|
|
32
|
-
/** Citations from knowledge base */
|
|
33
|
-
citations?: Citation[];
|
|
34
|
-
/** Claude's reasoning/thinking trace */
|
|
35
|
-
thinking?: string;
|
|
36
|
-
/** Whether thinking is complete */
|
|
37
|
-
thinkingComplete?: boolean;
|
|
38
|
-
}
|
|
39
|
-
interface Citation {
|
|
40
|
-
document_id: string;
|
|
41
|
-
filename: string;
|
|
42
|
-
similarity?: number;
|
|
43
|
-
image_url?: string;
|
|
44
|
-
page?: number;
|
|
45
|
-
}
|
|
46
|
-
type StreamEvent = {
|
|
47
|
-
type: 'content';
|
|
48
|
-
text: string;
|
|
49
|
-
accumulated: string;
|
|
50
|
-
} | {
|
|
51
|
-
type: 'thinking';
|
|
52
|
-
content: string;
|
|
53
|
-
} | {
|
|
54
|
-
type: 'thinking_complete';
|
|
55
|
-
} | {
|
|
56
|
-
type: 'citations';
|
|
57
|
-
citations: Citation[];
|
|
58
|
-
} | {
|
|
59
|
-
type: 'tool_call_start';
|
|
60
|
-
toolName: string;
|
|
61
|
-
arguments: Record<string, unknown>;
|
|
62
|
-
} | {
|
|
63
|
-
type: 'tool_call_complete';
|
|
64
|
-
toolName: string;
|
|
65
|
-
success: boolean;
|
|
66
|
-
} | {
|
|
67
|
-
type: 'client_tool_call';
|
|
68
|
-
toolName: string;
|
|
69
|
-
arguments: Record<string, unknown>;
|
|
70
|
-
} | {
|
|
71
|
-
type: 'workflow_started';
|
|
72
|
-
name: string;
|
|
73
|
-
todos: WorkflowTodo[];
|
|
74
|
-
} | {
|
|
75
|
-
type: 'workflow_todo_updated';
|
|
76
|
-
todoId: string;
|
|
77
|
-
status: 'pending' | 'completed';
|
|
78
|
-
} | {
|
|
79
|
-
type: 'workflow_ended';
|
|
80
|
-
} | {
|
|
81
|
-
type: 'workflow_complete_prompt';
|
|
82
|
-
} | {
|
|
83
|
-
type: 'verification_status';
|
|
84
|
-
isVerified: boolean;
|
|
85
|
-
} | {
|
|
86
|
-
type: 'conversation_id';
|
|
87
|
-
conversationId: string;
|
|
88
|
-
} | {
|
|
89
|
-
type: 'error';
|
|
90
|
-
message: string;
|
|
91
|
-
} | {
|
|
92
|
-
type: 'done';
|
|
93
|
-
};
|
|
94
|
-
type ToolHandler = (args: Record<string, unknown>) => Promise<ToolResult> | ToolResult;
|
|
95
|
-
interface ToolResult {
|
|
96
|
-
status: 'success' | 'error';
|
|
97
|
-
data?: unknown;
|
|
98
|
-
error?: string;
|
|
99
|
-
}
|
|
100
|
-
type ToolHandlers = Record<string, ToolHandler>;
|
|
101
|
-
interface Conversation {
|
|
102
|
-
id: string;
|
|
103
|
-
name: string | null;
|
|
104
|
-
created_at: string;
|
|
105
|
-
updated_at: string;
|
|
106
|
-
}
|
|
107
|
-
interface WorkflowTodo {
|
|
108
|
-
id: string;
|
|
109
|
-
text: string;
|
|
110
|
-
status: 'pending' | 'completed';
|
|
111
|
-
}
|
|
112
|
-
interface ActiveWorkflow {
|
|
113
|
-
name: string;
|
|
114
|
-
todos: WorkflowTodo[];
|
|
115
|
-
isComplete?: boolean;
|
|
116
|
-
}
|
|
117
|
-
interface ContextData {
|
|
118
|
-
/** Current page URL or path */
|
|
119
|
-
page?: string;
|
|
120
|
-
/** Custom context data */
|
|
121
|
-
[key: string]: unknown;
|
|
122
|
-
}
|
|
123
|
-
interface CrowEventCallbacks {
|
|
124
|
-
onMessage?: (message: Message) => void;
|
|
125
|
-
onMessageUpdate?: (messageId: string, updates: Partial<Message>) => void;
|
|
126
|
-
onToolCall?: (event: StreamEvent & {
|
|
127
|
-
type: 'tool_call_start' | 'tool_call_complete' | 'client_tool_call';
|
|
128
|
-
}) => void;
|
|
129
|
-
onWorkflow?: (event: StreamEvent & {
|
|
130
|
-
type: 'workflow_started' | 'workflow_todo_updated' | 'workflow_ended' | 'workflow_complete_prompt';
|
|
131
|
-
}) => void;
|
|
132
|
-
onVerificationStatus?: (isVerified: boolean) => void;
|
|
133
|
-
onError?: (error: Error) => void;
|
|
134
|
-
}
|
|
1
|
+
import { C as CrowClientConfig, a as CrowEventCallbacks, I as IdentifyOptions, T as ToolHandlers, b as ContextData, M as Message, c as Conversation, S as StreamEvent, d as IdentityState, e as ToolResult } from './browserUse-CZNpayEF.cjs';
|
|
2
|
+
export { A as ActiveWorkflow, f as Citation, g as CrowBrowserUse, h as ToolHandler, W as WorkflowTodo } from './browserUse-CZNpayEF.cjs';
|
|
135
3
|
|
|
136
4
|
/**
|
|
137
5
|
* CrowClient - Main headless client for Crow AI agents
|
|
@@ -440,4 +308,4 @@ declare const DEFAULT_TOOLS: {
|
|
|
440
308
|
type DefaultToolName = keyof typeof DEFAULT_TOOLS;
|
|
441
309
|
declare const DEFAULT_TOOL_NAMES: DefaultToolName[];
|
|
442
310
|
|
|
443
|
-
export {
|
|
311
|
+
export { ContextData, Conversation, ConversationManager, CrowClient, CrowClientConfig, CrowEventCallbacks, DEFAULT_TOOLS, DEFAULT_TOOL_NAMES, type DefaultToolName, IdentifyOptions, IdentityManager, IdentityState, Message, StreamEvent, ToolHandlers, ToolManager, ToolResult, parseSSEChunk, parseSSEData, streamResponse };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,137 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
interface CrowClientConfig {
|
|
5
|
-
/** Your Crow product ID from the dashboard */
|
|
6
|
-
productId: string;
|
|
7
|
-
/** API URL (defaults to https://api.usecrow.org) */
|
|
8
|
-
apiUrl?: string;
|
|
9
|
-
/** Default model to use */
|
|
10
|
-
model?: string;
|
|
11
|
-
}
|
|
12
|
-
interface IdentifyOptions {
|
|
13
|
-
/** JWT token from your backend for user verification */
|
|
14
|
-
token: string;
|
|
15
|
-
/** Optional user display name */
|
|
16
|
-
name?: string;
|
|
17
|
-
/** Optional user email */
|
|
18
|
-
email?: string;
|
|
19
|
-
/** Any additional metadata */
|
|
20
|
-
[key: string]: unknown;
|
|
21
|
-
}
|
|
22
|
-
interface IdentityState {
|
|
23
|
-
token: string | null;
|
|
24
|
-
metadata: Record<string, unknown>;
|
|
25
|
-
isVerified: boolean;
|
|
26
|
-
}
|
|
27
|
-
interface Message {
|
|
28
|
-
id: string;
|
|
29
|
-
content: string;
|
|
30
|
-
role: 'user' | 'assistant';
|
|
31
|
-
timestamp: Date;
|
|
32
|
-
/** Citations from knowledge base */
|
|
33
|
-
citations?: Citation[];
|
|
34
|
-
/** Claude's reasoning/thinking trace */
|
|
35
|
-
thinking?: string;
|
|
36
|
-
/** Whether thinking is complete */
|
|
37
|
-
thinkingComplete?: boolean;
|
|
38
|
-
}
|
|
39
|
-
interface Citation {
|
|
40
|
-
document_id: string;
|
|
41
|
-
filename: string;
|
|
42
|
-
similarity?: number;
|
|
43
|
-
image_url?: string;
|
|
44
|
-
page?: number;
|
|
45
|
-
}
|
|
46
|
-
type StreamEvent = {
|
|
47
|
-
type: 'content';
|
|
48
|
-
text: string;
|
|
49
|
-
accumulated: string;
|
|
50
|
-
} | {
|
|
51
|
-
type: 'thinking';
|
|
52
|
-
content: string;
|
|
53
|
-
} | {
|
|
54
|
-
type: 'thinking_complete';
|
|
55
|
-
} | {
|
|
56
|
-
type: 'citations';
|
|
57
|
-
citations: Citation[];
|
|
58
|
-
} | {
|
|
59
|
-
type: 'tool_call_start';
|
|
60
|
-
toolName: string;
|
|
61
|
-
arguments: Record<string, unknown>;
|
|
62
|
-
} | {
|
|
63
|
-
type: 'tool_call_complete';
|
|
64
|
-
toolName: string;
|
|
65
|
-
success: boolean;
|
|
66
|
-
} | {
|
|
67
|
-
type: 'client_tool_call';
|
|
68
|
-
toolName: string;
|
|
69
|
-
arguments: Record<string, unknown>;
|
|
70
|
-
} | {
|
|
71
|
-
type: 'workflow_started';
|
|
72
|
-
name: string;
|
|
73
|
-
todos: WorkflowTodo[];
|
|
74
|
-
} | {
|
|
75
|
-
type: 'workflow_todo_updated';
|
|
76
|
-
todoId: string;
|
|
77
|
-
status: 'pending' | 'completed';
|
|
78
|
-
} | {
|
|
79
|
-
type: 'workflow_ended';
|
|
80
|
-
} | {
|
|
81
|
-
type: 'workflow_complete_prompt';
|
|
82
|
-
} | {
|
|
83
|
-
type: 'verification_status';
|
|
84
|
-
isVerified: boolean;
|
|
85
|
-
} | {
|
|
86
|
-
type: 'conversation_id';
|
|
87
|
-
conversationId: string;
|
|
88
|
-
} | {
|
|
89
|
-
type: 'error';
|
|
90
|
-
message: string;
|
|
91
|
-
} | {
|
|
92
|
-
type: 'done';
|
|
93
|
-
};
|
|
94
|
-
type ToolHandler = (args: Record<string, unknown>) => Promise<ToolResult> | ToolResult;
|
|
95
|
-
interface ToolResult {
|
|
96
|
-
status: 'success' | 'error';
|
|
97
|
-
data?: unknown;
|
|
98
|
-
error?: string;
|
|
99
|
-
}
|
|
100
|
-
type ToolHandlers = Record<string, ToolHandler>;
|
|
101
|
-
interface Conversation {
|
|
102
|
-
id: string;
|
|
103
|
-
name: string | null;
|
|
104
|
-
created_at: string;
|
|
105
|
-
updated_at: string;
|
|
106
|
-
}
|
|
107
|
-
interface WorkflowTodo {
|
|
108
|
-
id: string;
|
|
109
|
-
text: string;
|
|
110
|
-
status: 'pending' | 'completed';
|
|
111
|
-
}
|
|
112
|
-
interface ActiveWorkflow {
|
|
113
|
-
name: string;
|
|
114
|
-
todos: WorkflowTodo[];
|
|
115
|
-
isComplete?: boolean;
|
|
116
|
-
}
|
|
117
|
-
interface ContextData {
|
|
118
|
-
/** Current page URL or path */
|
|
119
|
-
page?: string;
|
|
120
|
-
/** Custom context data */
|
|
121
|
-
[key: string]: unknown;
|
|
122
|
-
}
|
|
123
|
-
interface CrowEventCallbacks {
|
|
124
|
-
onMessage?: (message: Message) => void;
|
|
125
|
-
onMessageUpdate?: (messageId: string, updates: Partial<Message>) => void;
|
|
126
|
-
onToolCall?: (event: StreamEvent & {
|
|
127
|
-
type: 'tool_call_start' | 'tool_call_complete' | 'client_tool_call';
|
|
128
|
-
}) => void;
|
|
129
|
-
onWorkflow?: (event: StreamEvent & {
|
|
130
|
-
type: 'workflow_started' | 'workflow_todo_updated' | 'workflow_ended' | 'workflow_complete_prompt';
|
|
131
|
-
}) => void;
|
|
132
|
-
onVerificationStatus?: (isVerified: boolean) => void;
|
|
133
|
-
onError?: (error: Error) => void;
|
|
134
|
-
}
|
|
1
|
+
import { C as CrowClientConfig, a as CrowEventCallbacks, I as IdentifyOptions, T as ToolHandlers, b as ContextData, M as Message, c as Conversation, S as StreamEvent, d as IdentityState, e as ToolResult } from './browserUse-CZNpayEF.js';
|
|
2
|
+
export { A as ActiveWorkflow, f as Citation, g as CrowBrowserUse, h as ToolHandler, W as WorkflowTodo } from './browserUse-CZNpayEF.js';
|
|
135
3
|
|
|
136
4
|
/**
|
|
137
5
|
* CrowClient - Main headless client for Crow AI agents
|
|
@@ -440,4 +308,4 @@ declare const DEFAULT_TOOLS: {
|
|
|
440
308
|
type DefaultToolName = keyof typeof DEFAULT_TOOLS;
|
|
441
309
|
declare const DEFAULT_TOOL_NAMES: DefaultToolName[];
|
|
442
310
|
|
|
443
|
-
export {
|
|
311
|
+
export { ContextData, Conversation, ConversationManager, CrowClient, CrowClientConfig, CrowEventCallbacks, DEFAULT_TOOLS, DEFAULT_TOOL_NAMES, type DefaultToolName, IdentifyOptions, IdentityManager, IdentityState, Message, StreamEvent, ToolHandlers, ToolManager, ToolResult, parseSSEChunk, parseSSEData, streamResponse };
|
package/dist/index.js
CHANGED
|
@@ -848,7 +848,249 @@ var CrowClient = class {
|
|
|
848
848
|
this.loadingListeners.clear();
|
|
849
849
|
}
|
|
850
850
|
};
|
|
851
|
+
var PageControllerModule = null;
|
|
852
|
+
async function getPageController() {
|
|
853
|
+
if (!PageControllerModule) {
|
|
854
|
+
try {
|
|
855
|
+
PageControllerModule = await import('@page-agent/page-controller');
|
|
856
|
+
} catch (error) {
|
|
857
|
+
throw new Error(
|
|
858
|
+
'PageController not available. Either import from "@usecrow/client/browser" or install @page-agent/page-controller as a dependency.'
|
|
859
|
+
);
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
return PageControllerModule.PageController;
|
|
863
|
+
}
|
|
864
|
+
var CrowBrowserUse = class {
|
|
865
|
+
constructor(config) {
|
|
866
|
+
this.pageController = null;
|
|
867
|
+
this.sessionId = null;
|
|
868
|
+
this.maxSteps = 20;
|
|
869
|
+
this.config = config;
|
|
870
|
+
}
|
|
871
|
+
/**
|
|
872
|
+
* Initialize PageController with non-blocking pointer
|
|
873
|
+
*/
|
|
874
|
+
async initPageController() {
|
|
875
|
+
if (this.pageController) {
|
|
876
|
+
return this.pageController;
|
|
877
|
+
}
|
|
878
|
+
try {
|
|
879
|
+
const PageController = await getPageController();
|
|
880
|
+
this.pageController = new PageController({
|
|
881
|
+
enableMask: true,
|
|
882
|
+
viewportExpansion: 500,
|
|
883
|
+
highlightLabelOpacity: 0,
|
|
884
|
+
// Hide numbered labels from users
|
|
885
|
+
highlightOpacity: 0
|
|
886
|
+
// Hide highlight boxes from users
|
|
887
|
+
});
|
|
888
|
+
await this.pageController.showMask();
|
|
889
|
+
const mask = this.pageController.mask;
|
|
890
|
+
if (mask?.wrapper) {
|
|
891
|
+
mask.wrapper.style.pointerEvents = "none";
|
|
892
|
+
}
|
|
893
|
+
console.log("[CrowBrowserUse] PageController initialized with non-blocking pointer");
|
|
894
|
+
return this.pageController;
|
|
895
|
+
} catch (error) {
|
|
896
|
+
console.error("[CrowBrowserUse] Failed to import @page-agent/page-controller:", error);
|
|
897
|
+
throw new Error(
|
|
898
|
+
"Failed to initialize browser automation. Make sure @page-agent/page-controller is installed."
|
|
899
|
+
);
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
/**
|
|
903
|
+
* Execute a browser automation task
|
|
904
|
+
*/
|
|
905
|
+
async execute(task) {
|
|
906
|
+
console.log("[CrowBrowserUse] Starting task:", task);
|
|
907
|
+
try {
|
|
908
|
+
const controller = await this.initPageController();
|
|
909
|
+
const startResponse = await this.startSession(task);
|
|
910
|
+
this.sessionId = startResponse.session_id;
|
|
911
|
+
this.maxSteps = startResponse.max_steps;
|
|
912
|
+
console.log("[CrowBrowserUse] Session started:", this.sessionId);
|
|
913
|
+
let stepCount = 0;
|
|
914
|
+
let lastActionResult;
|
|
915
|
+
while (stepCount < this.maxSteps) {
|
|
916
|
+
stepCount++;
|
|
917
|
+
const browserState = await controller.getBrowserState();
|
|
918
|
+
const stepResponse = await this.processStep(browserState, lastActionResult);
|
|
919
|
+
if (stepResponse.done) {
|
|
920
|
+
console.log("[CrowBrowserUse] Task completed:", stepResponse.message);
|
|
921
|
+
await this.cleanup();
|
|
922
|
+
return {
|
|
923
|
+
status: stepResponse.success ? "success" : "error",
|
|
924
|
+
data: {
|
|
925
|
+
message: stepResponse.message,
|
|
926
|
+
steps: stepCount
|
|
927
|
+
},
|
|
928
|
+
error: stepResponse.success ? void 0 : stepResponse.message
|
|
929
|
+
};
|
|
930
|
+
}
|
|
931
|
+
if (stepResponse.error) {
|
|
932
|
+
console.error("[CrowBrowserUse] Error:", stepResponse.error);
|
|
933
|
+
await this.cleanup();
|
|
934
|
+
return {
|
|
935
|
+
status: "error",
|
|
936
|
+
error: stepResponse.error
|
|
937
|
+
};
|
|
938
|
+
}
|
|
939
|
+
if (stepResponse.action) {
|
|
940
|
+
lastActionResult = await this.executeAction(controller, stepResponse.action);
|
|
941
|
+
console.log(`[CrowBrowserUse] Step ${stepCount}:`, lastActionResult);
|
|
942
|
+
}
|
|
943
|
+
if (stepResponse.reflection) {
|
|
944
|
+
console.log("[CrowBrowserUse] Reflection:", stepResponse.reflection.next_goal);
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
await this.cleanup();
|
|
948
|
+
return {
|
|
949
|
+
status: "error",
|
|
950
|
+
error: `Task incomplete after ${this.maxSteps} steps`
|
|
951
|
+
};
|
|
952
|
+
} catch (error) {
|
|
953
|
+
console.error("[CrowBrowserUse] Error:", error);
|
|
954
|
+
await this.cleanup();
|
|
955
|
+
return {
|
|
956
|
+
status: "error",
|
|
957
|
+
error: error instanceof Error ? error.message : String(error)
|
|
958
|
+
};
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
/**
|
|
962
|
+
* Start a browser-use session on the server
|
|
963
|
+
*/
|
|
964
|
+
async startSession(task) {
|
|
965
|
+
const response = await fetch(`${this.config.apiUrl}/api/browser-use/start`, {
|
|
966
|
+
method: "POST",
|
|
967
|
+
headers: { "Content-Type": "application/json" },
|
|
968
|
+
body: JSON.stringify({
|
|
969
|
+
product_id: this.config.productId,
|
|
970
|
+
task
|
|
971
|
+
})
|
|
972
|
+
});
|
|
973
|
+
if (!response.ok) {
|
|
974
|
+
const error = await response.json().catch(() => ({ detail: "Unknown error" }));
|
|
975
|
+
throw new Error(error.detail || `Failed to start session: ${response.status}`);
|
|
976
|
+
}
|
|
977
|
+
return response.json();
|
|
978
|
+
}
|
|
979
|
+
/**
|
|
980
|
+
* Process a step on the server
|
|
981
|
+
*/
|
|
982
|
+
async processStep(browserState, actionResult) {
|
|
983
|
+
const response = await fetch(`${this.config.apiUrl}/api/browser-use/step`, {
|
|
984
|
+
method: "POST",
|
|
985
|
+
headers: { "Content-Type": "application/json" },
|
|
986
|
+
body: JSON.stringify({
|
|
987
|
+
session_id: this.sessionId,
|
|
988
|
+
product_id: this.config.productId,
|
|
989
|
+
browser_state: browserState,
|
|
990
|
+
action_result: actionResult
|
|
991
|
+
})
|
|
992
|
+
});
|
|
993
|
+
if (!response.ok) {
|
|
994
|
+
const error = await response.json().catch(() => ({ detail: "Unknown error" }));
|
|
995
|
+
throw new Error(error.detail || `Failed to process step: ${response.status}`);
|
|
996
|
+
}
|
|
997
|
+
return response.json();
|
|
998
|
+
}
|
|
999
|
+
/**
|
|
1000
|
+
* Execute an action using PageController
|
|
1001
|
+
*/
|
|
1002
|
+
async executeAction(controller, action) {
|
|
1003
|
+
const actionName = Object.keys(action)[0];
|
|
1004
|
+
const actionParams = action[actionName];
|
|
1005
|
+
try {
|
|
1006
|
+
switch (actionName) {
|
|
1007
|
+
case "click_element_by_index": {
|
|
1008
|
+
const result = await controller.clickElement(actionParams.index);
|
|
1009
|
+
return result.message;
|
|
1010
|
+
}
|
|
1011
|
+
case "input_text": {
|
|
1012
|
+
const result = await controller.inputText(
|
|
1013
|
+
actionParams.index,
|
|
1014
|
+
actionParams.text
|
|
1015
|
+
);
|
|
1016
|
+
return result.message;
|
|
1017
|
+
}
|
|
1018
|
+
case "select_dropdown_option": {
|
|
1019
|
+
const result = await controller.selectOption(
|
|
1020
|
+
actionParams.index,
|
|
1021
|
+
actionParams.text
|
|
1022
|
+
);
|
|
1023
|
+
return result.message;
|
|
1024
|
+
}
|
|
1025
|
+
case "scroll": {
|
|
1026
|
+
const result = await controller.scroll({
|
|
1027
|
+
down: actionParams.down,
|
|
1028
|
+
numPages: actionParams.num_pages,
|
|
1029
|
+
pixels: actionParams.pixels,
|
|
1030
|
+
index: actionParams.index
|
|
1031
|
+
});
|
|
1032
|
+
return result.message;
|
|
1033
|
+
}
|
|
1034
|
+
case "scroll_horizontally": {
|
|
1035
|
+
const result = await controller.scrollHorizontally({
|
|
1036
|
+
right: actionParams.right,
|
|
1037
|
+
pixels: actionParams.pixels,
|
|
1038
|
+
index: actionParams.index
|
|
1039
|
+
});
|
|
1040
|
+
return result.message;
|
|
1041
|
+
}
|
|
1042
|
+
case "wait": {
|
|
1043
|
+
const seconds = actionParams.seconds || 1;
|
|
1044
|
+
await new Promise((resolve) => setTimeout(resolve, seconds * 1e3));
|
|
1045
|
+
return `Waited ${seconds} seconds`;
|
|
1046
|
+
}
|
|
1047
|
+
case "done": {
|
|
1048
|
+
return "Task completed";
|
|
1049
|
+
}
|
|
1050
|
+
default:
|
|
1051
|
+
return `Unknown action: ${actionName}`;
|
|
1052
|
+
}
|
|
1053
|
+
} catch (error) {
|
|
1054
|
+
return `Action failed: ${error instanceof Error ? error.message : String(error)}`;
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
/**
|
|
1058
|
+
* Cleanup resources
|
|
1059
|
+
*/
|
|
1060
|
+
async cleanup() {
|
|
1061
|
+
if (this.pageController) {
|
|
1062
|
+
try {
|
|
1063
|
+
await this.pageController.hideMask();
|
|
1064
|
+
await this.pageController.cleanUpHighlights();
|
|
1065
|
+
this.pageController.dispose();
|
|
1066
|
+
} catch (error) {
|
|
1067
|
+
console.warn("[CrowBrowserUse] Cleanup error:", error);
|
|
1068
|
+
}
|
|
1069
|
+
this.pageController = null;
|
|
1070
|
+
}
|
|
1071
|
+
if (this.sessionId) {
|
|
1072
|
+
try {
|
|
1073
|
+
await fetch(`${this.config.apiUrl}/api/browser-use/end`, {
|
|
1074
|
+
method: "POST",
|
|
1075
|
+
headers: { "Content-Type": "application/json" },
|
|
1076
|
+
body: JSON.stringify({
|
|
1077
|
+
session_id: this.sessionId,
|
|
1078
|
+
product_id: this.config.productId
|
|
1079
|
+
})
|
|
1080
|
+
});
|
|
1081
|
+
} catch (error) {
|
|
1082
|
+
}
|
|
1083
|
+
this.sessionId = null;
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
/**
|
|
1087
|
+
* Stop the current task
|
|
1088
|
+
*/
|
|
1089
|
+
async stop() {
|
|
1090
|
+
await this.cleanup();
|
|
1091
|
+
}
|
|
1092
|
+
};
|
|
851
1093
|
|
|
852
|
-
export { ConversationManager, CrowClient, DEFAULT_TOOLS, DEFAULT_TOOL_NAMES, IdentityManager, ToolManager, parseSSEChunk, parseSSEData, streamResponse };
|
|
1094
|
+
export { ConversationManager, CrowBrowserUse, CrowClient, DEFAULT_TOOLS, DEFAULT_TOOL_NAMES, IdentityManager, ToolManager, parseSSEChunk, parseSSEData, streamResponse };
|
|
853
1095
|
//# sourceMappingURL=index.js.map
|
|
854
1096
|
//# sourceMappingURL=index.js.map
|