@usecrow/client 0.1.17 → 0.1.19
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.cjs +21 -244
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +154 -3
- package/dist/index.d.ts +154 -3
- package/dist/index.js +20 -244
- package/dist/index.js.map +1 -1
- package/package.json +1 -14
- package/dist/browser.cjs +0 -284
- package/dist/browser.cjs.map +0 -1
- package/dist/browser.d.cts +0 -52
- package/dist/browser.d.ts +0 -52
- package/dist/browser.js +0 -278
- package/dist/browser.js.map +0 -1
- package/dist/browserUse-CZNpayEF.d.cts +0 -188
- package/dist/browserUse-CZNpayEF.d.ts +0 -188
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,137 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Core types for @usecrow/client
|
|
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
|
+
}
|
|
3
135
|
|
|
4
136
|
/**
|
|
5
137
|
* CrowClient - Main headless client for Crow AI agents
|
|
@@ -289,4 +421,23 @@ declare function parseSSEChunk(chunk: string): Generator<string>;
|
|
|
289
421
|
*/
|
|
290
422
|
declare function streamResponse(response: Response, signal?: AbortSignal): AsyncGenerator<StreamEvent>;
|
|
291
423
|
|
|
292
|
-
|
|
424
|
+
/**
|
|
425
|
+
* SDK Default Tools - automatically registered, zero configuration
|
|
426
|
+
*
|
|
427
|
+
* These tools are built into the Crow SDK and available to all agents
|
|
428
|
+
* without any user configuration required.
|
|
429
|
+
*/
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* SDK Default Tools - automatically registered, zero configuration
|
|
433
|
+
*/
|
|
434
|
+
declare const DEFAULT_TOOLS: {
|
|
435
|
+
/**
|
|
436
|
+
* Refresh the current page in the user's browser
|
|
437
|
+
*/
|
|
438
|
+
readonly refreshPage: () => Promise<ToolResult>;
|
|
439
|
+
};
|
|
440
|
+
type DefaultToolName = keyof typeof DEFAULT_TOOLS;
|
|
441
|
+
declare const DEFAULT_TOOL_NAMES: DefaultToolName[];
|
|
442
|
+
|
|
443
|
+
export { type ActiveWorkflow, type Citation, type ContextData, type Conversation, ConversationManager, CrowClient, type CrowClientConfig, type CrowEventCallbacks, DEFAULT_TOOLS, DEFAULT_TOOL_NAMES, type DefaultToolName, type IdentifyOptions, IdentityManager, type IdentityState, type Message, type StreamEvent, type ToolHandler, type ToolHandlers, ToolManager, type ToolResult, type WorkflowTodo, parseSSEChunk, parseSSEData, streamResponse };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,137 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Core types for @usecrow/client
|
|
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
|
+
}
|
|
3
135
|
|
|
4
136
|
/**
|
|
5
137
|
* CrowClient - Main headless client for Crow AI agents
|
|
@@ -289,4 +421,23 @@ declare function parseSSEChunk(chunk: string): Generator<string>;
|
|
|
289
421
|
*/
|
|
290
422
|
declare function streamResponse(response: Response, signal?: AbortSignal): AsyncGenerator<StreamEvent>;
|
|
291
423
|
|
|
292
|
-
|
|
424
|
+
/**
|
|
425
|
+
* SDK Default Tools - automatically registered, zero configuration
|
|
426
|
+
*
|
|
427
|
+
* These tools are built into the Crow SDK and available to all agents
|
|
428
|
+
* without any user configuration required.
|
|
429
|
+
*/
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* SDK Default Tools - automatically registered, zero configuration
|
|
433
|
+
*/
|
|
434
|
+
declare const DEFAULT_TOOLS: {
|
|
435
|
+
/**
|
|
436
|
+
* Refresh the current page in the user's browser
|
|
437
|
+
*/
|
|
438
|
+
readonly refreshPage: () => Promise<ToolResult>;
|
|
439
|
+
};
|
|
440
|
+
type DefaultToolName = keyof typeof DEFAULT_TOOLS;
|
|
441
|
+
declare const DEFAULT_TOOL_NAMES: DefaultToolName[];
|
|
442
|
+
|
|
443
|
+
export { type ActiveWorkflow, type Citation, type ContextData, type Conversation, ConversationManager, CrowClient, type CrowClientConfig, type CrowEventCallbacks, DEFAULT_TOOLS, DEFAULT_TOOL_NAMES, type DefaultToolName, type IdentifyOptions, IdentityManager, type IdentityState, type Message, type StreamEvent, type ToolHandler, type ToolHandlers, ToolManager, type ToolResult, type WorkflowTodo, parseSSEChunk, parseSSEData, streamResponse };
|
package/dist/index.js
CHANGED
|
@@ -276,7 +276,7 @@ var ConversationManager = class {
|
|
|
276
276
|
* Parse history messages from API format
|
|
277
277
|
*/
|
|
278
278
|
parseHistoryMessages(messages) {
|
|
279
|
-
return messages.map((msg, idx) => ({
|
|
279
|
+
return messages.filter((msg) => msg.role !== "tool" && !msg.content.startsWith("[Client Tool Result:")).map((msg, idx) => ({
|
|
280
280
|
id: `history-${idx}`,
|
|
281
281
|
content: this.parseContent(msg.content),
|
|
282
282
|
role: msg.role === "assistant" ? "assistant" : "user",
|
|
@@ -440,6 +440,22 @@ async function* streamResponse(response, signal) {
|
|
|
440
440
|
}
|
|
441
441
|
}
|
|
442
442
|
|
|
443
|
+
// src/defaultTools.ts
|
|
444
|
+
var DEFAULT_TOOLS = {
|
|
445
|
+
/**
|
|
446
|
+
* Refresh the current page in the user's browser
|
|
447
|
+
*/
|
|
448
|
+
refreshPage: async () => {
|
|
449
|
+
try {
|
|
450
|
+
window.location.reload();
|
|
451
|
+
return { status: "success", data: { message: "Page refresh initiated" } };
|
|
452
|
+
} catch (error) {
|
|
453
|
+
return { status: "error", error: String(error) };
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
};
|
|
457
|
+
var DEFAULT_TOOL_NAMES = Object.keys(DEFAULT_TOOLS);
|
|
458
|
+
|
|
443
459
|
// src/CrowClient.ts
|
|
444
460
|
var DEFAULT_API_URL = "https://api.usecrow.org";
|
|
445
461
|
var DEFAULT_MODEL = "claude-sonnet-4-20250514";
|
|
@@ -465,6 +481,8 @@ var CrowClient = class {
|
|
|
465
481
|
this.config.productId,
|
|
466
482
|
this.config.apiUrl
|
|
467
483
|
);
|
|
484
|
+
this.tools.register(DEFAULT_TOOLS);
|
|
485
|
+
console.log("[Crow] Default tools registered:", DEFAULT_TOOL_NAMES.join(", "));
|
|
468
486
|
this.identity.subscribe((state) => {
|
|
469
487
|
this.callbacks.onVerificationStatus?.(state.isVerified);
|
|
470
488
|
});
|
|
@@ -830,249 +848,7 @@ var CrowClient = class {
|
|
|
830
848
|
this.loadingListeners.clear();
|
|
831
849
|
}
|
|
832
850
|
};
|
|
833
|
-
var PageControllerModule = null;
|
|
834
|
-
async function getPageController() {
|
|
835
|
-
if (!PageControllerModule) {
|
|
836
|
-
try {
|
|
837
|
-
PageControllerModule = await import('@page-agent/page-controller');
|
|
838
|
-
} catch (error) {
|
|
839
|
-
throw new Error(
|
|
840
|
-
'PageController not available. Either import from "@usecrow/client/browser" or install @page-agent/page-controller as a dependency.'
|
|
841
|
-
);
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
return PageControllerModule.PageController;
|
|
845
|
-
}
|
|
846
|
-
var CrowBrowserUse = class {
|
|
847
|
-
constructor(config) {
|
|
848
|
-
this.pageController = null;
|
|
849
|
-
this.sessionId = null;
|
|
850
|
-
this.maxSteps = 20;
|
|
851
|
-
this.config = config;
|
|
852
|
-
}
|
|
853
|
-
/**
|
|
854
|
-
* Initialize PageController with non-blocking pointer
|
|
855
|
-
*/
|
|
856
|
-
async initPageController() {
|
|
857
|
-
if (this.pageController) {
|
|
858
|
-
return this.pageController;
|
|
859
|
-
}
|
|
860
|
-
try {
|
|
861
|
-
const PageController = await getPageController();
|
|
862
|
-
this.pageController = new PageController({
|
|
863
|
-
enableMask: true,
|
|
864
|
-
viewportExpansion: 500,
|
|
865
|
-
highlightLabelOpacity: 0,
|
|
866
|
-
// Hide numbered labels from users
|
|
867
|
-
highlightOpacity: 0
|
|
868
|
-
// Hide highlight boxes from users
|
|
869
|
-
});
|
|
870
|
-
await this.pageController.showMask();
|
|
871
|
-
const mask = this.pageController.mask;
|
|
872
|
-
if (mask?.wrapper) {
|
|
873
|
-
mask.wrapper.style.pointerEvents = "none";
|
|
874
|
-
}
|
|
875
|
-
console.log("[CrowBrowserUse] PageController initialized with non-blocking pointer");
|
|
876
|
-
return this.pageController;
|
|
877
|
-
} catch (error) {
|
|
878
|
-
console.error("[CrowBrowserUse] Failed to import @page-agent/page-controller:", error);
|
|
879
|
-
throw new Error(
|
|
880
|
-
"Failed to initialize browser automation. Make sure @page-agent/page-controller is installed."
|
|
881
|
-
);
|
|
882
|
-
}
|
|
883
|
-
}
|
|
884
|
-
/**
|
|
885
|
-
* Execute a browser automation task
|
|
886
|
-
*/
|
|
887
|
-
async execute(task) {
|
|
888
|
-
console.log("[CrowBrowserUse] Starting task:", task);
|
|
889
|
-
try {
|
|
890
|
-
const controller = await this.initPageController();
|
|
891
|
-
const startResponse = await this.startSession(task);
|
|
892
|
-
this.sessionId = startResponse.session_id;
|
|
893
|
-
this.maxSteps = startResponse.max_steps;
|
|
894
|
-
console.log("[CrowBrowserUse] Session started:", this.sessionId);
|
|
895
|
-
let stepCount = 0;
|
|
896
|
-
let lastActionResult;
|
|
897
|
-
while (stepCount < this.maxSteps) {
|
|
898
|
-
stepCount++;
|
|
899
|
-
const browserState = await controller.getBrowserState();
|
|
900
|
-
const stepResponse = await this.processStep(browserState, lastActionResult);
|
|
901
|
-
if (stepResponse.done) {
|
|
902
|
-
console.log("[CrowBrowserUse] Task completed:", stepResponse.message);
|
|
903
|
-
await this.cleanup();
|
|
904
|
-
return {
|
|
905
|
-
status: stepResponse.success ? "success" : "error",
|
|
906
|
-
data: {
|
|
907
|
-
message: stepResponse.message,
|
|
908
|
-
steps: stepCount
|
|
909
|
-
},
|
|
910
|
-
error: stepResponse.success ? void 0 : stepResponse.message
|
|
911
|
-
};
|
|
912
|
-
}
|
|
913
|
-
if (stepResponse.error) {
|
|
914
|
-
console.error("[CrowBrowserUse] Error:", stepResponse.error);
|
|
915
|
-
await this.cleanup();
|
|
916
|
-
return {
|
|
917
|
-
status: "error",
|
|
918
|
-
error: stepResponse.error
|
|
919
|
-
};
|
|
920
|
-
}
|
|
921
|
-
if (stepResponse.action) {
|
|
922
|
-
lastActionResult = await this.executeAction(controller, stepResponse.action);
|
|
923
|
-
console.log(`[CrowBrowserUse] Step ${stepCount}:`, lastActionResult);
|
|
924
|
-
}
|
|
925
|
-
if (stepResponse.reflection) {
|
|
926
|
-
console.log("[CrowBrowserUse] Reflection:", stepResponse.reflection.next_goal);
|
|
927
|
-
}
|
|
928
|
-
}
|
|
929
|
-
await this.cleanup();
|
|
930
|
-
return {
|
|
931
|
-
status: "error",
|
|
932
|
-
error: `Task incomplete after ${this.maxSteps} steps`
|
|
933
|
-
};
|
|
934
|
-
} catch (error) {
|
|
935
|
-
console.error("[CrowBrowserUse] Error:", error);
|
|
936
|
-
await this.cleanup();
|
|
937
|
-
return {
|
|
938
|
-
status: "error",
|
|
939
|
-
error: error instanceof Error ? error.message : String(error)
|
|
940
|
-
};
|
|
941
|
-
}
|
|
942
|
-
}
|
|
943
|
-
/**
|
|
944
|
-
* Start a browser-use session on the server
|
|
945
|
-
*/
|
|
946
|
-
async startSession(task) {
|
|
947
|
-
const response = await fetch(`${this.config.apiUrl}/api/browser-use/start`, {
|
|
948
|
-
method: "POST",
|
|
949
|
-
headers: { "Content-Type": "application/json" },
|
|
950
|
-
body: JSON.stringify({
|
|
951
|
-
product_id: this.config.productId,
|
|
952
|
-
task
|
|
953
|
-
})
|
|
954
|
-
});
|
|
955
|
-
if (!response.ok) {
|
|
956
|
-
const error = await response.json().catch(() => ({ detail: "Unknown error" }));
|
|
957
|
-
throw new Error(error.detail || `Failed to start session: ${response.status}`);
|
|
958
|
-
}
|
|
959
|
-
return response.json();
|
|
960
|
-
}
|
|
961
|
-
/**
|
|
962
|
-
* Process a step on the server
|
|
963
|
-
*/
|
|
964
|
-
async processStep(browserState, actionResult) {
|
|
965
|
-
const response = await fetch(`${this.config.apiUrl}/api/browser-use/step`, {
|
|
966
|
-
method: "POST",
|
|
967
|
-
headers: { "Content-Type": "application/json" },
|
|
968
|
-
body: JSON.stringify({
|
|
969
|
-
session_id: this.sessionId,
|
|
970
|
-
product_id: this.config.productId,
|
|
971
|
-
browser_state: browserState,
|
|
972
|
-
action_result: actionResult
|
|
973
|
-
})
|
|
974
|
-
});
|
|
975
|
-
if (!response.ok) {
|
|
976
|
-
const error = await response.json().catch(() => ({ detail: "Unknown error" }));
|
|
977
|
-
throw new Error(error.detail || `Failed to process step: ${response.status}`);
|
|
978
|
-
}
|
|
979
|
-
return response.json();
|
|
980
|
-
}
|
|
981
|
-
/**
|
|
982
|
-
* Execute an action using PageController
|
|
983
|
-
*/
|
|
984
|
-
async executeAction(controller, action) {
|
|
985
|
-
const actionName = Object.keys(action)[0];
|
|
986
|
-
const actionParams = action[actionName];
|
|
987
|
-
try {
|
|
988
|
-
switch (actionName) {
|
|
989
|
-
case "click_element_by_index": {
|
|
990
|
-
const result = await controller.clickElement(actionParams.index);
|
|
991
|
-
return result.message;
|
|
992
|
-
}
|
|
993
|
-
case "input_text": {
|
|
994
|
-
const result = await controller.inputText(
|
|
995
|
-
actionParams.index,
|
|
996
|
-
actionParams.text
|
|
997
|
-
);
|
|
998
|
-
return result.message;
|
|
999
|
-
}
|
|
1000
|
-
case "select_dropdown_option": {
|
|
1001
|
-
const result = await controller.selectOption(
|
|
1002
|
-
actionParams.index,
|
|
1003
|
-
actionParams.text
|
|
1004
|
-
);
|
|
1005
|
-
return result.message;
|
|
1006
|
-
}
|
|
1007
|
-
case "scroll": {
|
|
1008
|
-
const result = await controller.scroll({
|
|
1009
|
-
down: actionParams.down,
|
|
1010
|
-
numPages: actionParams.num_pages,
|
|
1011
|
-
pixels: actionParams.pixels,
|
|
1012
|
-
index: actionParams.index
|
|
1013
|
-
});
|
|
1014
|
-
return result.message;
|
|
1015
|
-
}
|
|
1016
|
-
case "scroll_horizontally": {
|
|
1017
|
-
const result = await controller.scrollHorizontally({
|
|
1018
|
-
right: actionParams.right,
|
|
1019
|
-
pixels: actionParams.pixels,
|
|
1020
|
-
index: actionParams.index
|
|
1021
|
-
});
|
|
1022
|
-
return result.message;
|
|
1023
|
-
}
|
|
1024
|
-
case "wait": {
|
|
1025
|
-
const seconds = actionParams.seconds || 1;
|
|
1026
|
-
await new Promise((resolve) => setTimeout(resolve, seconds * 1e3));
|
|
1027
|
-
return `Waited ${seconds} seconds`;
|
|
1028
|
-
}
|
|
1029
|
-
case "done": {
|
|
1030
|
-
return "Task completed";
|
|
1031
|
-
}
|
|
1032
|
-
default:
|
|
1033
|
-
return `Unknown action: ${actionName}`;
|
|
1034
|
-
}
|
|
1035
|
-
} catch (error) {
|
|
1036
|
-
return `Action failed: ${error instanceof Error ? error.message : String(error)}`;
|
|
1037
|
-
}
|
|
1038
|
-
}
|
|
1039
|
-
/**
|
|
1040
|
-
* Cleanup resources
|
|
1041
|
-
*/
|
|
1042
|
-
async cleanup() {
|
|
1043
|
-
if (this.pageController) {
|
|
1044
|
-
try {
|
|
1045
|
-
await this.pageController.hideMask();
|
|
1046
|
-
await this.pageController.cleanUpHighlights();
|
|
1047
|
-
this.pageController.dispose();
|
|
1048
|
-
} catch (error) {
|
|
1049
|
-
console.warn("[CrowBrowserUse] Cleanup error:", error);
|
|
1050
|
-
}
|
|
1051
|
-
this.pageController = null;
|
|
1052
|
-
}
|
|
1053
|
-
if (this.sessionId) {
|
|
1054
|
-
try {
|
|
1055
|
-
await fetch(`${this.config.apiUrl}/api/browser-use/end`, {
|
|
1056
|
-
method: "POST",
|
|
1057
|
-
headers: { "Content-Type": "application/json" },
|
|
1058
|
-
body: JSON.stringify({
|
|
1059
|
-
session_id: this.sessionId,
|
|
1060
|
-
product_id: this.config.productId
|
|
1061
|
-
})
|
|
1062
|
-
});
|
|
1063
|
-
} catch (error) {
|
|
1064
|
-
}
|
|
1065
|
-
this.sessionId = null;
|
|
1066
|
-
}
|
|
1067
|
-
}
|
|
1068
|
-
/**
|
|
1069
|
-
* Stop the current task
|
|
1070
|
-
*/
|
|
1071
|
-
async stop() {
|
|
1072
|
-
await this.cleanup();
|
|
1073
|
-
}
|
|
1074
|
-
};
|
|
1075
851
|
|
|
1076
|
-
export { ConversationManager,
|
|
852
|
+
export { ConversationManager, CrowClient, DEFAULT_TOOLS, DEFAULT_TOOL_NAMES, IdentityManager, ToolManager, parseSSEChunk, parseSSEData, streamResponse };
|
|
1077
853
|
//# sourceMappingURL=index.js.map
|
|
1078
854
|
//# sourceMappingURL=index.js.map
|