@usecrow/client 0.1.16 → 0.1.17

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.cts CHANGED
@@ -1,137 +1,5 @@
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
- }
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
@@ -421,4 +289,4 @@ declare function parseSSEChunk(chunk: string): Generator<string>;
421
289
  */
422
290
  declare function streamResponse(response: Response, signal?: AbortSignal): AsyncGenerator<StreamEvent>;
423
291
 
424
- export { type ActiveWorkflow, type Citation, type ContextData, type Conversation, ConversationManager, CrowClient, type CrowClientConfig, type CrowEventCallbacks, type IdentifyOptions, IdentityManager, type IdentityState, type Message, type StreamEvent, type ToolHandler, type ToolHandlers, ToolManager, type ToolResult, type WorkflowTodo, parseSSEChunk, parseSSEData, streamResponse };
292
+ export { ContextData, Conversation, ConversationManager, CrowClient, CrowClientConfig, CrowEventCallbacks, IdentifyOptions, IdentityManager, IdentityState, Message, StreamEvent, ToolHandlers, ToolManager, ToolResult, parseSSEChunk, parseSSEData, streamResponse };
package/dist/index.d.ts CHANGED
@@ -1,137 +1,5 @@
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
- }
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
@@ -421,4 +289,4 @@ declare function parseSSEChunk(chunk: string): Generator<string>;
421
289
  */
422
290
  declare function streamResponse(response: Response, signal?: AbortSignal): AsyncGenerator<StreamEvent>;
423
291
 
424
- export { type ActiveWorkflow, type Citation, type ContextData, type Conversation, ConversationManager, CrowClient, type CrowClientConfig, type CrowEventCallbacks, type IdentifyOptions, IdentityManager, type IdentityState, type Message, type StreamEvent, type ToolHandler, type ToolHandlers, ToolManager, type ToolResult, type WorkflowTodo, parseSSEChunk, parseSSEData, streamResponse };
292
+ export { ContextData, Conversation, ConversationManager, CrowClient, CrowClientConfig, CrowEventCallbacks, IdentifyOptions, IdentityManager, IdentityState, Message, StreamEvent, ToolHandlers, ToolManager, ToolResult, 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.filter((msg) => msg.role !== "tool" && !msg.content.startsWith("[Client Tool Result:")).map((msg, idx) => ({
279
+ return messages.map((msg, idx) => ({
280
280
  id: `history-${idx}`,
281
281
  content: this.parseContent(msg.content),
282
282
  role: msg.role === "assistant" ? "assistant" : "user",
@@ -830,7 +830,249 @@ var CrowClient = class {
830
830
  this.loadingListeners.clear();
831
831
  }
832
832
  };
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
+ };
833
1075
 
834
- export { ConversationManager, CrowClient, IdentityManager, ToolManager, parseSSEChunk, parseSSEData, streamResponse };
1076
+ export { ConversationManager, CrowBrowserUse, CrowClient, IdentityManager, ToolManager, parseSSEChunk, parseSSEData, streamResponse };
835
1077
  //# sourceMappingURL=index.js.map
836
1078
  //# sourceMappingURL=index.js.map