@marketrix.ai/widget 3.8.506 → 3.8.507
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/src/sdk/contract.d.ts +16 -105
- package/dist/src/sdk/contracts/activityLog.d.ts +32 -210
- package/dist/src/sdk/contracts/entities.d.ts +21 -59
- package/dist/src/sdk/index.d.ts +16 -105
- package/dist/src/services/ChatService.d.ts +1 -1
- package/dist/widget.mjs +1 -1
- package/package.json +1 -1
|
@@ -1,110 +1,21 @@
|
|
|
1
1
|
export declare const widgetContract: {
|
|
2
2
|
activityLogCreate: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<import("zod").ZodObject<{
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
created_by: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
20
|
-
}, import("zod/v4/core").$loose>>>;
|
|
21
|
-
type: import("zod").ZodEnum<{
|
|
22
|
-
update_workspace: "update_workspace";
|
|
23
|
-
update_user: "update_user";
|
|
24
|
-
create_application: "create_application";
|
|
25
|
-
update_application: "update_application";
|
|
26
|
-
delete_application: "delete_application";
|
|
27
|
-
create_widget: "create_widget";
|
|
28
|
-
update_widget: "update_widget";
|
|
29
|
-
delete_widget: "delete_widget";
|
|
30
|
-
create_knowledge: "create_knowledge";
|
|
31
|
-
update_knowledge: "update_knowledge";
|
|
32
|
-
delete_knowledge: "delete_knowledge";
|
|
33
|
-
request_membership: "request_membership";
|
|
34
|
-
invite_user: "invite_user";
|
|
35
|
-
create_workspace: "create_workspace";
|
|
36
|
-
trial_started: "trial_started";
|
|
37
|
-
trial_ending_soon: "trial_ending_soon";
|
|
38
|
-
trial_ended: "trial_ended";
|
|
39
|
-
subscription_created: "subscription_created";
|
|
40
|
-
subscription_canceled: "subscription_canceled";
|
|
41
|
-
plan_changed: "plan_changed";
|
|
42
|
-
payment_succeeded: "payment_succeeded";
|
|
43
|
-
payment_failed: "payment_failed";
|
|
44
|
-
widget_question: "widget_question";
|
|
45
|
-
start_simulation: "start_simulation";
|
|
46
|
-
create_workflow: "create_workflow";
|
|
47
|
-
update_workflow: "update_workflow";
|
|
48
|
-
delete_workflow: "delete_workflow";
|
|
49
|
-
toggle_workflow: "toggle_workflow";
|
|
50
|
-
slack_command: "slack_command";
|
|
51
|
-
publish_survey: "publish_survey";
|
|
52
|
-
unpublish_survey: "unpublish_survey";
|
|
53
|
-
delete_survey_response: "delete_survey_response";
|
|
54
|
-
}>;
|
|
55
|
-
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
56
|
-
id: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
57
|
-
created_at: import("zod").ZodOptional<import("zod").ZodCoercedDate<unknown>>;
|
|
58
|
-
updated_at: import("zod").ZodOptional<import("zod").ZodCoercedDate<unknown>>;
|
|
59
|
-
workspace_id: import("zod").ZodNumber;
|
|
60
|
-
user_id: import("zod").ZodNullable<import("zod").ZodNumber>;
|
|
61
|
-
type: import("zod").ZodEnum<{
|
|
62
|
-
update_workspace: "update_workspace";
|
|
63
|
-
update_user: "update_user";
|
|
64
|
-
create_application: "create_application";
|
|
65
|
-
update_application: "update_application";
|
|
66
|
-
delete_application: "delete_application";
|
|
67
|
-
create_widget: "create_widget";
|
|
68
|
-
update_widget: "update_widget";
|
|
69
|
-
delete_widget: "delete_widget";
|
|
70
|
-
create_knowledge: "create_knowledge";
|
|
71
|
-
update_knowledge: "update_knowledge";
|
|
72
|
-
delete_knowledge: "delete_knowledge";
|
|
73
|
-
request_membership: "request_membership";
|
|
74
|
-
invite_user: "invite_user";
|
|
75
|
-
create_workspace: "create_workspace";
|
|
76
|
-
trial_started: "trial_started";
|
|
77
|
-
trial_ending_soon: "trial_ending_soon";
|
|
78
|
-
trial_ended: "trial_ended";
|
|
79
|
-
subscription_created: "subscription_created";
|
|
80
|
-
subscription_canceled: "subscription_canceled";
|
|
81
|
-
plan_changed: "plan_changed";
|
|
82
|
-
payment_succeeded: "payment_succeeded";
|
|
83
|
-
payment_failed: "payment_failed";
|
|
84
|
-
widget_question: "widget_question";
|
|
85
|
-
start_simulation: "start_simulation";
|
|
86
|
-
create_workflow: "create_workflow";
|
|
87
|
-
update_workflow: "update_workflow";
|
|
88
|
-
delete_workflow: "delete_workflow";
|
|
89
|
-
toggle_workflow: "toggle_workflow";
|
|
90
|
-
slack_command: "slack_command";
|
|
91
|
-
publish_survey: "publish_survey";
|
|
92
|
-
unpublish_survey: "unpublish_survey";
|
|
93
|
-
delete_survey_response: "delete_survey_response";
|
|
94
|
-
}>;
|
|
95
|
-
metadata: import("zod").ZodOptional<import("zod").ZodObject<{
|
|
96
|
-
details: import("zod").ZodOptional<import("zod").ZodString>;
|
|
97
|
-
id: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
98
|
-
type: import("zod").ZodOptional<import("zod").ZodString>;
|
|
99
|
-
name: import("zod").ZodOptional<import("zod").ZodString>;
|
|
100
|
-
target_user_id: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
101
|
-
target_user_email: import("zod").ZodOptional<import("zod").ZodString>;
|
|
102
|
-
reason: import("zod").ZodOptional<import("zod").ZodString>;
|
|
103
|
-
ip_address: import("zod").ZodOptional<import("zod").ZodString>;
|
|
104
|
-
user_agent: import("zod").ZodOptional<import("zod").ZodString>;
|
|
105
|
-
widget_type: import("zod").ZodOptional<import("zod").ZodString>;
|
|
106
|
-
created_by: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
107
|
-
}, import("zod/v4/core").$loose>>;
|
|
3
|
+
type: import("zod").ZodLiteral<"widget_question">;
|
|
4
|
+
metadata: import("zod").ZodObject<{
|
|
5
|
+
question: import("zod").ZodString;
|
|
6
|
+
mode: import("zod").ZodEnum<{
|
|
7
|
+
tell: "tell";
|
|
8
|
+
show: "show";
|
|
9
|
+
do: "do";
|
|
10
|
+
}>;
|
|
11
|
+
chat_id: import("zod").ZodString;
|
|
12
|
+
timestamp: import("zod").ZodString;
|
|
13
|
+
marketrix_id: import("zod").ZodString;
|
|
14
|
+
marketrix_key: import("zod").ZodString;
|
|
15
|
+
user_id: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
16
|
+
}, import("zod/v4/core").$strict>;
|
|
17
|
+
}, import("zod/v4/core").$strict>, import("zod").ZodObject<{
|
|
18
|
+
success: import("zod").ZodLiteral<true>;
|
|
108
19
|
}, import("zod/v4/core").$strip>, Record<never, never>, Record<never, never>>;
|
|
109
20
|
chatCreate: import("@orpc/contract").ContractProcedureBuilderWithOutput<import("@orpc/contract").Schema<unknown, unknown>, import("zod").ZodString, Record<never, never>, Record<never, never>>;
|
|
110
21
|
widgetDefaultGet: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<import("zod").ZodObject<{
|
|
@@ -6,111 +6,22 @@ import { z } from 'zod';
|
|
|
6
6
|
*/
|
|
7
7
|
export declare const ACTIVITY_RETENTION_DAYS = 90;
|
|
8
8
|
export declare const activityLogCreate: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
created_by: z.ZodOptional<z.ZodNumber>;
|
|
26
|
-
}, z.core.$loose>>>;
|
|
27
|
-
type: z.ZodEnum<{
|
|
28
|
-
update_workspace: "update_workspace";
|
|
29
|
-
update_user: "update_user";
|
|
30
|
-
create_application: "create_application";
|
|
31
|
-
update_application: "update_application";
|
|
32
|
-
delete_application: "delete_application";
|
|
33
|
-
create_widget: "create_widget";
|
|
34
|
-
update_widget: "update_widget";
|
|
35
|
-
delete_widget: "delete_widget";
|
|
36
|
-
create_knowledge: "create_knowledge";
|
|
37
|
-
update_knowledge: "update_knowledge";
|
|
38
|
-
delete_knowledge: "delete_knowledge";
|
|
39
|
-
request_membership: "request_membership";
|
|
40
|
-
invite_user: "invite_user";
|
|
41
|
-
create_workspace: "create_workspace";
|
|
42
|
-
trial_started: "trial_started";
|
|
43
|
-
trial_ending_soon: "trial_ending_soon";
|
|
44
|
-
trial_ended: "trial_ended";
|
|
45
|
-
subscription_created: "subscription_created";
|
|
46
|
-
subscription_canceled: "subscription_canceled";
|
|
47
|
-
plan_changed: "plan_changed";
|
|
48
|
-
payment_succeeded: "payment_succeeded";
|
|
49
|
-
payment_failed: "payment_failed";
|
|
50
|
-
widget_question: "widget_question";
|
|
51
|
-
start_simulation: "start_simulation";
|
|
52
|
-
create_workflow: "create_workflow";
|
|
53
|
-
update_workflow: "update_workflow";
|
|
54
|
-
delete_workflow: "delete_workflow";
|
|
55
|
-
toggle_workflow: "toggle_workflow";
|
|
56
|
-
slack_command: "slack_command";
|
|
57
|
-
publish_survey: "publish_survey";
|
|
58
|
-
unpublish_survey: "unpublish_survey";
|
|
59
|
-
delete_survey_response: "delete_survey_response";
|
|
60
|
-
}>;
|
|
61
|
-
}, z.core.$strip>, z.ZodObject<{
|
|
62
|
-
id: z.ZodOptional<z.ZodNumber>;
|
|
63
|
-
created_at: z.ZodOptional<z.ZodCoercedDate<unknown>>;
|
|
64
|
-
updated_at: z.ZodOptional<z.ZodCoercedDate<unknown>>;
|
|
65
|
-
workspace_id: z.ZodNumber;
|
|
66
|
-
user_id: z.ZodNullable<z.ZodNumber>;
|
|
67
|
-
type: z.ZodEnum<{
|
|
68
|
-
update_workspace: "update_workspace";
|
|
69
|
-
update_user: "update_user";
|
|
70
|
-
create_application: "create_application";
|
|
71
|
-
update_application: "update_application";
|
|
72
|
-
delete_application: "delete_application";
|
|
73
|
-
create_widget: "create_widget";
|
|
74
|
-
update_widget: "update_widget";
|
|
75
|
-
delete_widget: "delete_widget";
|
|
76
|
-
create_knowledge: "create_knowledge";
|
|
77
|
-
update_knowledge: "update_knowledge";
|
|
78
|
-
delete_knowledge: "delete_knowledge";
|
|
79
|
-
request_membership: "request_membership";
|
|
80
|
-
invite_user: "invite_user";
|
|
81
|
-
create_workspace: "create_workspace";
|
|
82
|
-
trial_started: "trial_started";
|
|
83
|
-
trial_ending_soon: "trial_ending_soon";
|
|
84
|
-
trial_ended: "trial_ended";
|
|
85
|
-
subscription_created: "subscription_created";
|
|
86
|
-
subscription_canceled: "subscription_canceled";
|
|
87
|
-
plan_changed: "plan_changed";
|
|
88
|
-
payment_succeeded: "payment_succeeded";
|
|
89
|
-
payment_failed: "payment_failed";
|
|
90
|
-
widget_question: "widget_question";
|
|
91
|
-
start_simulation: "start_simulation";
|
|
92
|
-
create_workflow: "create_workflow";
|
|
93
|
-
update_workflow: "update_workflow";
|
|
94
|
-
delete_workflow: "delete_workflow";
|
|
95
|
-
toggle_workflow: "toggle_workflow";
|
|
96
|
-
slack_command: "slack_command";
|
|
97
|
-
publish_survey: "publish_survey";
|
|
98
|
-
unpublish_survey: "unpublish_survey";
|
|
99
|
-
delete_survey_response: "delete_survey_response";
|
|
100
|
-
}>;
|
|
101
|
-
metadata: z.ZodOptional<z.ZodObject<{
|
|
102
|
-
details: z.ZodOptional<z.ZodString>;
|
|
103
|
-
id: z.ZodOptional<z.ZodNumber>;
|
|
104
|
-
type: z.ZodOptional<z.ZodString>;
|
|
105
|
-
name: z.ZodOptional<z.ZodString>;
|
|
106
|
-
target_user_id: z.ZodOptional<z.ZodNumber>;
|
|
107
|
-
target_user_email: z.ZodOptional<z.ZodString>;
|
|
108
|
-
reason: z.ZodOptional<z.ZodString>;
|
|
109
|
-
ip_address: z.ZodOptional<z.ZodString>;
|
|
110
|
-
user_agent: z.ZodOptional<z.ZodString>;
|
|
111
|
-
widget_type: z.ZodOptional<z.ZodString>;
|
|
112
|
-
created_by: z.ZodOptional<z.ZodNumber>;
|
|
113
|
-
}, z.core.$loose>>;
|
|
9
|
+
type: z.ZodLiteral<"widget_question">;
|
|
10
|
+
metadata: z.ZodObject<{
|
|
11
|
+
question: z.ZodString;
|
|
12
|
+
mode: z.ZodEnum<{
|
|
13
|
+
tell: "tell";
|
|
14
|
+
show: "show";
|
|
15
|
+
do: "do";
|
|
16
|
+
}>;
|
|
17
|
+
chat_id: z.ZodString;
|
|
18
|
+
timestamp: z.ZodString;
|
|
19
|
+
marketrix_id: z.ZodString;
|
|
20
|
+
marketrix_key: z.ZodString;
|
|
21
|
+
user_id: z.ZodOptional<z.ZodNumber>;
|
|
22
|
+
}, z.core.$strict>;
|
|
23
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
24
|
+
success: z.ZodLiteral<true>;
|
|
114
25
|
}, z.core.$strip>, Record<never, never>, Record<never, never>>;
|
|
115
26
|
export declare const activityLogSearch: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
|
|
116
27
|
workspace_id: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
|
|
@@ -213,111 +124,22 @@ export declare const activityLogSearch: import("@orpc/contract").ContractProcedu
|
|
|
213
124
|
}, z.core.$strip>, Record<never, never>, Record<never, never>>;
|
|
214
125
|
export declare const activityLogRoutes: {
|
|
215
126
|
activityLogCreate: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
created_by: z.ZodOptional<z.ZodNumber>;
|
|
233
|
-
}, z.core.$loose>>>;
|
|
234
|
-
type: z.ZodEnum<{
|
|
235
|
-
update_workspace: "update_workspace";
|
|
236
|
-
update_user: "update_user";
|
|
237
|
-
create_application: "create_application";
|
|
238
|
-
update_application: "update_application";
|
|
239
|
-
delete_application: "delete_application";
|
|
240
|
-
create_widget: "create_widget";
|
|
241
|
-
update_widget: "update_widget";
|
|
242
|
-
delete_widget: "delete_widget";
|
|
243
|
-
create_knowledge: "create_knowledge";
|
|
244
|
-
update_knowledge: "update_knowledge";
|
|
245
|
-
delete_knowledge: "delete_knowledge";
|
|
246
|
-
request_membership: "request_membership";
|
|
247
|
-
invite_user: "invite_user";
|
|
248
|
-
create_workspace: "create_workspace";
|
|
249
|
-
trial_started: "trial_started";
|
|
250
|
-
trial_ending_soon: "trial_ending_soon";
|
|
251
|
-
trial_ended: "trial_ended";
|
|
252
|
-
subscription_created: "subscription_created";
|
|
253
|
-
subscription_canceled: "subscription_canceled";
|
|
254
|
-
plan_changed: "plan_changed";
|
|
255
|
-
payment_succeeded: "payment_succeeded";
|
|
256
|
-
payment_failed: "payment_failed";
|
|
257
|
-
widget_question: "widget_question";
|
|
258
|
-
start_simulation: "start_simulation";
|
|
259
|
-
create_workflow: "create_workflow";
|
|
260
|
-
update_workflow: "update_workflow";
|
|
261
|
-
delete_workflow: "delete_workflow";
|
|
262
|
-
toggle_workflow: "toggle_workflow";
|
|
263
|
-
slack_command: "slack_command";
|
|
264
|
-
publish_survey: "publish_survey";
|
|
265
|
-
unpublish_survey: "unpublish_survey";
|
|
266
|
-
delete_survey_response: "delete_survey_response";
|
|
267
|
-
}>;
|
|
268
|
-
}, z.core.$strip>, z.ZodObject<{
|
|
269
|
-
id: z.ZodOptional<z.ZodNumber>;
|
|
270
|
-
created_at: z.ZodOptional<z.ZodCoercedDate<unknown>>;
|
|
271
|
-
updated_at: z.ZodOptional<z.ZodCoercedDate<unknown>>;
|
|
272
|
-
workspace_id: z.ZodNumber;
|
|
273
|
-
user_id: z.ZodNullable<z.ZodNumber>;
|
|
274
|
-
type: z.ZodEnum<{
|
|
275
|
-
update_workspace: "update_workspace";
|
|
276
|
-
update_user: "update_user";
|
|
277
|
-
create_application: "create_application";
|
|
278
|
-
update_application: "update_application";
|
|
279
|
-
delete_application: "delete_application";
|
|
280
|
-
create_widget: "create_widget";
|
|
281
|
-
update_widget: "update_widget";
|
|
282
|
-
delete_widget: "delete_widget";
|
|
283
|
-
create_knowledge: "create_knowledge";
|
|
284
|
-
update_knowledge: "update_knowledge";
|
|
285
|
-
delete_knowledge: "delete_knowledge";
|
|
286
|
-
request_membership: "request_membership";
|
|
287
|
-
invite_user: "invite_user";
|
|
288
|
-
create_workspace: "create_workspace";
|
|
289
|
-
trial_started: "trial_started";
|
|
290
|
-
trial_ending_soon: "trial_ending_soon";
|
|
291
|
-
trial_ended: "trial_ended";
|
|
292
|
-
subscription_created: "subscription_created";
|
|
293
|
-
subscription_canceled: "subscription_canceled";
|
|
294
|
-
plan_changed: "plan_changed";
|
|
295
|
-
payment_succeeded: "payment_succeeded";
|
|
296
|
-
payment_failed: "payment_failed";
|
|
297
|
-
widget_question: "widget_question";
|
|
298
|
-
start_simulation: "start_simulation";
|
|
299
|
-
create_workflow: "create_workflow";
|
|
300
|
-
update_workflow: "update_workflow";
|
|
301
|
-
delete_workflow: "delete_workflow";
|
|
302
|
-
toggle_workflow: "toggle_workflow";
|
|
303
|
-
slack_command: "slack_command";
|
|
304
|
-
publish_survey: "publish_survey";
|
|
305
|
-
unpublish_survey: "unpublish_survey";
|
|
306
|
-
delete_survey_response: "delete_survey_response";
|
|
307
|
-
}>;
|
|
308
|
-
metadata: z.ZodOptional<z.ZodObject<{
|
|
309
|
-
details: z.ZodOptional<z.ZodString>;
|
|
310
|
-
id: z.ZodOptional<z.ZodNumber>;
|
|
311
|
-
type: z.ZodOptional<z.ZodString>;
|
|
312
|
-
name: z.ZodOptional<z.ZodString>;
|
|
313
|
-
target_user_id: z.ZodOptional<z.ZodNumber>;
|
|
314
|
-
target_user_email: z.ZodOptional<z.ZodString>;
|
|
315
|
-
reason: z.ZodOptional<z.ZodString>;
|
|
316
|
-
ip_address: z.ZodOptional<z.ZodString>;
|
|
317
|
-
user_agent: z.ZodOptional<z.ZodString>;
|
|
318
|
-
widget_type: z.ZodOptional<z.ZodString>;
|
|
319
|
-
created_by: z.ZodOptional<z.ZodNumber>;
|
|
320
|
-
}, z.core.$loose>>;
|
|
127
|
+
type: z.ZodLiteral<"widget_question">;
|
|
128
|
+
metadata: z.ZodObject<{
|
|
129
|
+
question: z.ZodString;
|
|
130
|
+
mode: z.ZodEnum<{
|
|
131
|
+
tell: "tell";
|
|
132
|
+
show: "show";
|
|
133
|
+
do: "do";
|
|
134
|
+
}>;
|
|
135
|
+
chat_id: z.ZodString;
|
|
136
|
+
timestamp: z.ZodString;
|
|
137
|
+
marketrix_id: z.ZodString;
|
|
138
|
+
marketrix_key: z.ZodString;
|
|
139
|
+
user_id: z.ZodOptional<z.ZodNumber>;
|
|
140
|
+
}, z.core.$strict>;
|
|
141
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
142
|
+
success: z.ZodLiteral<true>;
|
|
321
143
|
}, z.core.$strip>, Record<never, never>, Record<never, never>>;
|
|
322
144
|
activityLogSearch: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
|
|
323
145
|
workspace_id: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
|
|
@@ -92,9 +92,9 @@ export declare const ApplicationEntitySchema: z.ZodObject<{
|
|
|
92
92
|
website: "website";
|
|
93
93
|
}>;
|
|
94
94
|
url: z.ZodString;
|
|
95
|
-
username: z.
|
|
96
|
-
password: z.
|
|
97
|
-
allowed_domains: z.
|
|
95
|
+
username: z.ZodNullable<z.ZodString>;
|
|
96
|
+
password: z.ZodNullable<z.ZodString>;
|
|
97
|
+
allowed_domains: z.ZodArray<z.ZodString>;
|
|
98
98
|
}, z.core.$strip>;
|
|
99
99
|
export type ApplicationData = z.infer<typeof ApplicationEntitySchema>;
|
|
100
100
|
/** Used for all API responses; password is write-only and never returned to clients. */
|
|
@@ -110,8 +110,8 @@ export declare const ApplicationReadSchema: z.ZodObject<{
|
|
|
110
110
|
name: z.ZodString;
|
|
111
111
|
url: z.ZodString;
|
|
112
112
|
workspace_id: z.ZodNumber;
|
|
113
|
-
username: z.
|
|
114
|
-
allowed_domains: z.
|
|
113
|
+
username: z.ZodNullable<z.ZodString>;
|
|
114
|
+
allowed_domains: z.ZodArray<z.ZodString>;
|
|
115
115
|
}, z.core.$strip>;
|
|
116
116
|
export type ApplicationReadData = z.infer<typeof ApplicationReadSchema>;
|
|
117
117
|
export declare const WidgetChipSchema: z.ZodObject<{
|
|
@@ -363,57 +363,19 @@ export declare const ActivityLogEntitySchema: z.ZodObject<{
|
|
|
363
363
|
}, z.core.$loose>>;
|
|
364
364
|
}, z.core.$strip>;
|
|
365
365
|
export type ActivityLogData = z.infer<typeof ActivityLogEntitySchema>;
|
|
366
|
-
export declare const
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
widget_type: z.ZodOptional<z.ZodString>;
|
|
383
|
-
created_by: z.ZodOptional<z.ZodNumber>;
|
|
384
|
-
}, z.core.$loose>>>;
|
|
385
|
-
type: z.ZodEnum<{
|
|
386
|
-
update_workspace: "update_workspace";
|
|
387
|
-
update_user: "update_user";
|
|
388
|
-
create_application: "create_application";
|
|
389
|
-
update_application: "update_application";
|
|
390
|
-
delete_application: "delete_application";
|
|
391
|
-
create_widget: "create_widget";
|
|
392
|
-
update_widget: "update_widget";
|
|
393
|
-
delete_widget: "delete_widget";
|
|
394
|
-
create_knowledge: "create_knowledge";
|
|
395
|
-
update_knowledge: "update_knowledge";
|
|
396
|
-
delete_knowledge: "delete_knowledge";
|
|
397
|
-
request_membership: "request_membership";
|
|
398
|
-
invite_user: "invite_user";
|
|
399
|
-
create_workspace: "create_workspace";
|
|
400
|
-
trial_started: "trial_started";
|
|
401
|
-
trial_ending_soon: "trial_ending_soon";
|
|
402
|
-
trial_ended: "trial_ended";
|
|
403
|
-
subscription_created: "subscription_created";
|
|
404
|
-
subscription_canceled: "subscription_canceled";
|
|
405
|
-
plan_changed: "plan_changed";
|
|
406
|
-
payment_succeeded: "payment_succeeded";
|
|
407
|
-
payment_failed: "payment_failed";
|
|
408
|
-
widget_question: "widget_question";
|
|
409
|
-
start_simulation: "start_simulation";
|
|
410
|
-
create_workflow: "create_workflow";
|
|
411
|
-
update_workflow: "update_workflow";
|
|
412
|
-
delete_workflow: "delete_workflow";
|
|
413
|
-
toggle_workflow: "toggle_workflow";
|
|
414
|
-
slack_command: "slack_command";
|
|
415
|
-
publish_survey: "publish_survey";
|
|
416
|
-
unpublish_survey: "unpublish_survey";
|
|
417
|
-
delete_survey_response: "delete_survey_response";
|
|
418
|
-
}>;
|
|
419
|
-
}, z.core.$strip>;
|
|
366
|
+
export declare const WidgetQuestionLogSchema: z.ZodObject<{
|
|
367
|
+
type: z.ZodLiteral<"widget_question">;
|
|
368
|
+
metadata: z.ZodObject<{
|
|
369
|
+
question: z.ZodString;
|
|
370
|
+
mode: z.ZodEnum<{
|
|
371
|
+
tell: "tell";
|
|
372
|
+
show: "show";
|
|
373
|
+
do: "do";
|
|
374
|
+
}>;
|
|
375
|
+
chat_id: z.ZodString;
|
|
376
|
+
timestamp: z.ZodString;
|
|
377
|
+
marketrix_id: z.ZodString;
|
|
378
|
+
marketrix_key: z.ZodString;
|
|
379
|
+
user_id: z.ZodOptional<z.ZodNumber>;
|
|
380
|
+
}, z.core.$strict>;
|
|
381
|
+
}, z.core.$strict>;
|
package/dist/src/sdk/index.d.ts
CHANGED
|
@@ -1,111 +1,22 @@
|
|
|
1
1
|
export declare const configureSdk: (apiUrl: string) => void;
|
|
2
2
|
export declare const sdk: {
|
|
3
3
|
activityLogCreate: import("@orpc/contract").ContractProcedureClient<Record<never, never>, import("zod").ZodObject<{
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
created_by: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
21
|
-
}, import("zod/v4/core").$loose>>>;
|
|
22
|
-
type: import("zod").ZodEnum<{
|
|
23
|
-
update_workspace: "update_workspace";
|
|
24
|
-
update_user: "update_user";
|
|
25
|
-
create_application: "create_application";
|
|
26
|
-
update_application: "update_application";
|
|
27
|
-
delete_application: "delete_application";
|
|
28
|
-
create_widget: "create_widget";
|
|
29
|
-
update_widget: "update_widget";
|
|
30
|
-
delete_widget: "delete_widget";
|
|
31
|
-
create_knowledge: "create_knowledge";
|
|
32
|
-
update_knowledge: "update_knowledge";
|
|
33
|
-
delete_knowledge: "delete_knowledge";
|
|
34
|
-
request_membership: "request_membership";
|
|
35
|
-
invite_user: "invite_user";
|
|
36
|
-
create_workspace: "create_workspace";
|
|
37
|
-
trial_started: "trial_started";
|
|
38
|
-
trial_ending_soon: "trial_ending_soon";
|
|
39
|
-
trial_ended: "trial_ended";
|
|
40
|
-
subscription_created: "subscription_created";
|
|
41
|
-
subscription_canceled: "subscription_canceled";
|
|
42
|
-
plan_changed: "plan_changed";
|
|
43
|
-
payment_succeeded: "payment_succeeded";
|
|
44
|
-
payment_failed: "payment_failed";
|
|
45
|
-
widget_question: "widget_question";
|
|
46
|
-
start_simulation: "start_simulation";
|
|
47
|
-
create_workflow: "create_workflow";
|
|
48
|
-
update_workflow: "update_workflow";
|
|
49
|
-
delete_workflow: "delete_workflow";
|
|
50
|
-
toggle_workflow: "toggle_workflow";
|
|
51
|
-
slack_command: "slack_command";
|
|
52
|
-
publish_survey: "publish_survey";
|
|
53
|
-
unpublish_survey: "unpublish_survey";
|
|
54
|
-
delete_survey_response: "delete_survey_response";
|
|
55
|
-
}>;
|
|
56
|
-
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
57
|
-
id: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
58
|
-
created_at: import("zod").ZodOptional<import("zod").ZodCoercedDate<unknown>>;
|
|
59
|
-
updated_at: import("zod").ZodOptional<import("zod").ZodCoercedDate<unknown>>;
|
|
60
|
-
workspace_id: import("zod").ZodNumber;
|
|
61
|
-
user_id: import("zod").ZodNullable<import("zod").ZodNumber>;
|
|
62
|
-
type: import("zod").ZodEnum<{
|
|
63
|
-
update_workspace: "update_workspace";
|
|
64
|
-
update_user: "update_user";
|
|
65
|
-
create_application: "create_application";
|
|
66
|
-
update_application: "update_application";
|
|
67
|
-
delete_application: "delete_application";
|
|
68
|
-
create_widget: "create_widget";
|
|
69
|
-
update_widget: "update_widget";
|
|
70
|
-
delete_widget: "delete_widget";
|
|
71
|
-
create_knowledge: "create_knowledge";
|
|
72
|
-
update_knowledge: "update_knowledge";
|
|
73
|
-
delete_knowledge: "delete_knowledge";
|
|
74
|
-
request_membership: "request_membership";
|
|
75
|
-
invite_user: "invite_user";
|
|
76
|
-
create_workspace: "create_workspace";
|
|
77
|
-
trial_started: "trial_started";
|
|
78
|
-
trial_ending_soon: "trial_ending_soon";
|
|
79
|
-
trial_ended: "trial_ended";
|
|
80
|
-
subscription_created: "subscription_created";
|
|
81
|
-
subscription_canceled: "subscription_canceled";
|
|
82
|
-
plan_changed: "plan_changed";
|
|
83
|
-
payment_succeeded: "payment_succeeded";
|
|
84
|
-
payment_failed: "payment_failed";
|
|
85
|
-
widget_question: "widget_question";
|
|
86
|
-
start_simulation: "start_simulation";
|
|
87
|
-
create_workflow: "create_workflow";
|
|
88
|
-
update_workflow: "update_workflow";
|
|
89
|
-
delete_workflow: "delete_workflow";
|
|
90
|
-
toggle_workflow: "toggle_workflow";
|
|
91
|
-
slack_command: "slack_command";
|
|
92
|
-
publish_survey: "publish_survey";
|
|
93
|
-
unpublish_survey: "unpublish_survey";
|
|
94
|
-
delete_survey_response: "delete_survey_response";
|
|
95
|
-
}>;
|
|
96
|
-
metadata: import("zod").ZodOptional<import("zod").ZodObject<{
|
|
97
|
-
details: import("zod").ZodOptional<import("zod").ZodString>;
|
|
98
|
-
id: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
99
|
-
type: import("zod").ZodOptional<import("zod").ZodString>;
|
|
100
|
-
name: import("zod").ZodOptional<import("zod").ZodString>;
|
|
101
|
-
target_user_id: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
102
|
-
target_user_email: import("zod").ZodOptional<import("zod").ZodString>;
|
|
103
|
-
reason: import("zod").ZodOptional<import("zod").ZodString>;
|
|
104
|
-
ip_address: import("zod").ZodOptional<import("zod").ZodString>;
|
|
105
|
-
user_agent: import("zod").ZodOptional<import("zod").ZodString>;
|
|
106
|
-
widget_type: import("zod").ZodOptional<import("zod").ZodString>;
|
|
107
|
-
created_by: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
108
|
-
}, import("zod/v4/core").$loose>>;
|
|
4
|
+
type: import("zod").ZodLiteral<"widget_question">;
|
|
5
|
+
metadata: import("zod").ZodObject<{
|
|
6
|
+
question: import("zod").ZodString;
|
|
7
|
+
mode: import("zod").ZodEnum<{
|
|
8
|
+
tell: "tell";
|
|
9
|
+
show: "show";
|
|
10
|
+
do: "do";
|
|
11
|
+
}>;
|
|
12
|
+
chat_id: import("zod").ZodString;
|
|
13
|
+
timestamp: import("zod").ZodString;
|
|
14
|
+
marketrix_id: import("zod").ZodString;
|
|
15
|
+
marketrix_key: import("zod").ZodString;
|
|
16
|
+
user_id: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
17
|
+
}, import("zod/v4/core").$strict>;
|
|
18
|
+
}, import("zod/v4/core").$strict>, import("zod").ZodObject<{
|
|
19
|
+
success: import("zod").ZodLiteral<true>;
|
|
109
20
|
}, import("zod/v4/core").$strip>, Record<never, never>>;
|
|
110
21
|
chatCreate: import("@orpc/contract").ContractProcedureClient<Record<never, never>, import("@orpc/contract").Schema<unknown, unknown>, import("zod").ZodString, Record<never, never>>;
|
|
111
22
|
widgetDefaultGet: import("@orpc/contract").ContractProcedureClient<Record<never, never>, import("zod").ZodObject<{
|
|
@@ -14,5 +14,5 @@
|
|
|
14
14
|
* `send` propagates to `ChatContext`, which renders the error turn.
|
|
15
15
|
*/
|
|
16
16
|
import { type InstructionType } from '../sdk';
|
|
17
|
-
import {
|
|
17
|
+
import type { CredentialedConfig } from './StorageService';
|
|
18
18
|
export declare function chatPost(config: CredentialedConfig, message: string, mode: InstructionType, requestId: string): Promise<void>;
|
package/dist/widget.mjs
CHANGED
|
@@ -17,7 +17,7 @@ return v(gs,{toast:e,className:"mtx-toast",render:/* @__PURE__ */b(nc,{align:"ce
|
|
|
17
17
|
/* @__PURE__ */b(Ya,{src:Oa,alt:"",size:28,rounded:"pill"}),
|
|
18
18
|
/* @__PURE__ */v(rc,{grow:!0,minWidth:"0",children:[/* @__PURE__ */b(Es,{render:/* @__PURE__ */b(dc,{as:"span",block:!0,inheritColor:!0,truncate:!0,weight:"medium",style:{fontSize:"13px",color:t.titleColor,...e.actionProps&&{whiteSpace:"normal"}}})}),null!=e.description&&/* @__PURE__ */b(Cs,{render:/* @__PURE__ */b(dc,{as:"span",block:!0,inheritColor:!0,truncate:!0,style:{fontSize:"12px",color:t.bodyColor,opacity:.8}})})]}),e.actionProps&&/* @__PURE__ */b(_s,{render:/* @__PURE__ */b(Ga,{type:"button",variant:"ghost",shape:"pill",size:"sm",style:{color:t.titleColor,backgroundColor:t.actionBackground,border:t.border}})}),
|
|
19
19
|
/* @__PURE__ */b(As,{onMouseDown:e=>e.preventDefault(),render:/* @__PURE__ */b(ac,{label:"Dismiss",size:"xs",tone:"inherit",style:{color:t.closeColor,padding:"2px"}}),children:/* @__PURE__ */b(sc,{name:"closeSmall",size:12})})]},e.id)})},pc=({children:e,container:t,offsetBottom:n=20})=>/* @__PURE__ */v(Oi,{children:[e,/* @__PURE__ */b(js,{container:t??void 0,children:/* @__PURE__ */b(es,{className:"mtx-toast-viewport",style:{zIndex:2147483004,bottom:`${n}px`},children:/* @__PURE__ */b(hc,{})})})]}),fc=({error:e,onClearError:t,onRetry:n,greeting:r,greetingBody:o,onGreetingDismiss:i})=>{const{add:s,close:c}=Ra();return a(()=>{null!=e?s({id:"error",type:"error",title:e,timeout:0,priority:"high",onClose:t,...n&&{actionProps:{children:"Retry",onClick:n}}}):c("error")},[e,n,s,c,t]),a(()=>{r?s({id:"greeting",type:"info",title:r,description:o,timeout:8e3,onClose:i}):c("greeting")},[r,o,s,c,i]),null},mc=/* @__PURE__ */new Set(["button","link","textbox","checkbox","radio","switch","tab","menuitem"]);function gc(e){return Array.from(e.querySelectorAll('a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])')).filter(e=>null!==e.offsetParent&&!function(e){for(let t=e;t;t=t.parentElement)if("true"===t.getAttribute("aria-hidden"))return!0;return!1}(e))}function*yc(e){let t=e;for(;t;){yield t;const e=t.getRootNode();t=t.parentElement??(e instanceof ShadowRoot?e.host:null)}}function bc(e){if(!(e instanceof Element))return!1;try{const t=e.tagName.toLowerCase();if(!("button"===t||"input"===t||"textarea"===t||"select"===t||"a"===t&&e.hasAttribute("href")||mc.has(e.getAttribute("role")??"")||"true"===e.getAttribute("contenteditable")||e.hasAttribute("onclick")||parseInt(e.getAttribute("tabindex")??"-1",10)>=0))return!1;const n=window.getComputedStyle(e);if("none"===n.display||"none"===n.pointerEvents)return!1;const r=e.getBoundingClientRect();if(r.width<=0||r.height<=0)return!1;for(const o of yc(e))if(o!==e){const e=window.getComputedStyle(o).overflow;if("hidden"===e||"clip"===e){const e=o.getBoundingClientRect();if(r.right<e.left||r.left>e.right||r.bottom<e.top||r.top>e.bottom)return!1}if(o===document.body)break}for(let o=e.getRootNode();o instanceof ShadowRoot;o=o.host.getRootNode()){const e=o.host.getBoundingClientRect();if(e.width<=0||e.height<=0)return!1}return!0}catch(t){return console.error("[isIndexable] Unexpected error:",t),!1}}var vc=["id","type","role","aria-label","name","href"],wc=new class{index=/* @__PURE__ */new Map;elementToSequence=/* @__PURE__ */new WeakMap;generateAnchoredSelector(e){const t=[];let n=e;for(;n!==document.body;){const e=n.id?`#${CSS.escape(n.id)}`:"";if(e&&1===document.querySelectorAll(e).length)return t.unshift(e),t.join(" > ");const r=n.parentElement;if(!r)break;const o=n.tagName,i=Array.from(r.children).filter(e=>e.tagName===o),s=i.length>1?`:nth-of-type(${i.indexOf(n)+1})`:"";t.unshift(o.toLowerCase()+s),n=r}return["body",...t].join(" > ")}indexElements(){this.index.clear(),this.elementToSequence=/* @__PURE__ */new WeakMap;const e=document.createTreeWalker(document.body,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>{if(e instanceof HTMLElement&&null===e.offsetParent&&"BODY"!==e.tagName){const t=window.getComputedStyle(e),n="fixed"===t.position||"sticky"===t.position;if("none"===t.display)return NodeFilter.FILTER_REJECT;if(!n){let t=e.parentElement,n=!1;for(;t&&t!==document.body;){const e=window.getComputedStyle(t);if("fixed"===e.position||"sticky"===e.position){n=!0;break}t=t.parentElement}if(!n)return NodeFilter.FILTER_REJECT}}return NodeFilter.FILTER_ACCEPT}});let t=e.nextNode(),n=0;for(;t;){const r=t instanceof HTMLElement?t:null;if(r){const e=r.matches('a[href], button, input, textarea, select, [role="button"]'),t=r.classList.contains("cursor-pointer")||r.classList.contains("clickable"),o="function"==typeof r.onclick;(e||t||o||bc(r))&&(this.index.set(n,{element:r,selector:this.generateAnchoredSelector(r),identity:vc.map(e=>r.getAttribute(e))}),this.elementToSequence.set(r,n),n++)}t=e.nextNode()}}reindexAndSnapshot(){this.indexElements();const e=document.documentElement.cloneNode(!0);for(const[n,{selector:r}]of this.index.entries())try{e.querySelector(r)?.setAttribute("data-id",n.toString())}catch(t){console.warn(`[DomService] Failed to tag index ${n}:`,t)}return e.outerHTML}getSequenceForElement(e){return this.elementToSequence.get(e)}notInteractableReason(e,t){if(!document.body.contains(e))return`ELEMENT_NOT_INTERACTABLE: Element ${t} is not in the DOM`;const n=function(e){if(!0===e.disabled)return"is a disabled control";if("true"===e.getAttribute("aria-disabled"))return"is aria-disabled";for(const t of yc(e))if(t.hasAttribute("inert"))return"is inside an inert subtree";return null}(e);if(n)return`ELEMENT_NOT_INTERACTABLE: Element ${t} ${n}`;const r=window.getComputedStyle(e);if("none"===r.display)return`ELEMENT_NOT_INTERACTABLE: Element ${t} has display:none`;if("hidden"===r.visibility)return`ELEMENT_NOT_INTERACTABLE: Element ${t} has visibility:hidden`;if(0===parseFloat(r.opacity))return`ELEMENT_NOT_INTERACTABLE: Element ${t} has opacity:0`;const o=e.getBoundingClientRect();if(0===o.width||0===o.height)return`ELEMENT_NOT_INTERACTABLE: Element ${t} has zero dimensions`;const i=o.left+o.width/2,s=o.top+o.height/2,a=document.elementFromPoint(i,s);if(a&&a!==e&&!e.contains(a)&&!a.closest("#marketrix-show-highlight, #marketrix-show-popup, .marketrix-widget-container")){const e=a.tagName.toLowerCase();return`ELEMENT_OBSCURED: Element ${t} is covered by ${a.className?`${e}.${a.className.split(" ")[0]}`:e}. The obscuring element may be a modal or overlay that needs to be dismissed first.`}return null}getValidatedElement(e){const t=this.index.get(e);if(!t)return{element:null,error:`Element ${e} not found`};const n=!document.contains(t.element),r=vc.some((e,n)=>t.element.getAttribute(e)!==t.identity[n]);if(n||r)return{element:null,error:`DOM_CHANGED: Element at index ${e} ${n?"no longer exists":"has changed"}. Call get_html to get updated indices.`};const o=this.notInteractableReason(t.element,e);return o?{element:null,error:o}:{element:t.element}}},xc=e=>e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement,Sc=e=>e instanceof HTMLButtonElement||"button"===e.getAttribute("role");function kc(e,t){const n=1===t?"ArrowDown":"ArrowUp",r=e.selectedIndex+t;return r<0||r>=e.options.length?`${n}: already at ${1===t?"last":"first"} option`:(e.selectedIndex=r,e.dispatchEvent(new Event("change",{bubbles:!0})),`${n}: selected "${e.options[r].text}"`)}function Cc(e,t){const n=e.value,r=e.selectionStart??n.length,o=e.selectionEnd??n.length;let i,s;if(r!==o)i=n.slice(0,r)+n.slice(o),s=r;else if("Backspace"===t&&r>0)i=n.slice(0,r-1)+n.slice(o),s=r-1;else{if(!("Delete"===t&&r<n.length))return`${t}: ${"Backspace"===t?"cursor at start":"cursor at end"}, nothing to delete`;i=n.slice(0,r)+n.slice(r+1),s=r}return function(e,t,n){Ec(e,t),e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0})),e.setSelectionRange(n,n)}(e,i,s),`${t}: deleted character, value is now "${i}"`}function Ec(e,t){const n=Object.getOwnPropertyDescriptor(e instanceof HTMLTextAreaElement?HTMLTextAreaElement.prototype:HTMLInputElement.prototype,"value")?.set;n?n.call(e,t):e.value=t}var Ic=["scroll","resize","touchmove","wheel"],Mc=new class{currentPopup=null;currentHighlight=null;currentElement=null;currentOptions=null;currentPromise=null;resolvePromise=null;rejectPromise=null;clickHandler=null;scrollHandler=null;visibilityCheckInterval=null;async showToolAction(e){const{element:t,explanation:n,isClickAction:r=!1,browserToolName:o}=e;return this.currentOptions?.element===t&&this.currentOptions.explanation===n&&this.currentOptions.browserToolName===o&&this.currentPromise||(this.cleanup(),this.currentOptions=e,this.currentElement=t,t.scrollIntoView({behavior:"instant",block:"center",inline:"center"}),this.createHighlight(),this.createPopup(n,r),this.setupPositionUpdates(),this.setupVisibilityMonitoring(),r&&this.setupClickHandler(),this.currentPromise=new Promise((e,t)=>{this.resolvePromise=e,this.rejectPromise=t})),this.currentPromise}cleanup(){if(this.takeSettlers().reject?.(/* @__PURE__ */new Error("Cancelled by cleanup")),this.clickHandler&&(document.removeEventListener("click",this.clickHandler,{capture:!0}),this.clickHandler=null),this.scrollHandler){for(const e of Ic)window.removeEventListener(e,this.scrollHandler,{capture:!0});this.scrollHandler=null}this.visibilityCheckInterval&&(clearInterval(this.visibilityCheckInterval),this.visibilityCheckInterval=null),this.currentPopup?.remove(),this.currentHighlight?.remove(),document.getElementById("marketrix-show-popup")?.remove(),document.getElementById("marketrix-show-highlight")?.remove(),this.currentPopup=null,this.currentHighlight=null,this.currentElement=null,this.currentOptions=null,this.currentPromise=null}settle(e){const{resolve:t,reject:n}=this.takeSettlers();e?n?.(new Error(e)):t?.(),this.cleanup()}takeSettlers(){const e={resolve:this.resolvePromise,reject:this.rejectPromise};return this.resolvePromise=null,this.rejectPromise=null,e}createHighlight(){const e=document.createElement("div");e.id="marketrix-show-highlight",e.style.cssText="position:fixed;border:3px solid #3b82f6;border-radius:4px;box-shadow:0 0 0 4px rgba(59,130,246,0.2),0 0 20px rgba(59,130,246,0.4);z-index:2147483645;pointer-events:none;transition:none;",document.body.appendChild(e),this.currentHighlight=e,this.trackElement()}trackElement(){if(!this.currentElement||!this.currentHighlight)return;const e=this.currentElement.getBoundingClientRect();Object.assign(this.currentHighlight.style,{top:`${e.top}px`,left:`${e.left}px`,width:`${e.width}px`,height:`${e.height}px`}),this.updatePopupPosition()}createPopup(e,t){const n=document.createElement("div");n.id="marketrix-show-popup",n.innerHTML=t?`<div style="font-weight: 500; color: #1f2937; font-size: 12px;">${this.escapeHtml(e)}</div>`:`<div style="margin-bottom:12px;font-weight:500;color:#1f2937;font-size:12px;">${this.escapeHtml(e)}</div><div style="display:flex;gap:8px;justify-content:flex-end;"><button id="marketrix-show-continue" style="background:#3b82f6;color:white;border:none;border-radius:6px;padding:8px 16px;font-size:12px;font-weight:500;cursor:pointer;">Continue</button></div>`,n.style.cssText="position: fixed; width: 320px; background: white; border-radius: 8px;\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); z-index: 2147483646; padding: 16px;",document.body.appendChild(n),this.currentPopup=n,t||window.requestAnimationFrame(()=>{n.querySelector("#marketrix-show-continue")?.addEventListener("click",e=>{e.stopPropagation(),this.settle()})}),this.updatePopupPosition()}setupPositionUpdates(){this.scrollHandler=()=>this.trackElement();for(const e of Ic)window.addEventListener(e,this.scrollHandler,{capture:!0,passive:!0})}updatePopupPosition(){if(!this.currentPopup||!this.currentElement)return;const e=this.currentElement.getBoundingClientRect(),t=10,n=e.left+e.width/2,r=e.top+e.height/2,o=[{left:e.right+20,top:r-60},{left:e.left-320-20,top:r-60},{left:n-160,top:e.top-120-20},{left:n-160,top:e.bottom+20}];let i=o[0];for(const s of o)if(s.left>=t&&s.left+320<=window.innerWidth-t&&s.top>=t&&s.top+120<=window.innerHeight-t){i=s;break}this.currentPopup.style.left=`${Math.max(t,Math.min(i.left,window.innerWidth-320-t))}px`,this.currentPopup.style.top=`${Math.max(t,Math.min(i.top,window.innerHeight-120-t))}px`}setupClickHandler(){this.clickHandler=e=>{this.currentElement&&this.resolvePromise&&e.composedPath().includes(this.currentElement)&&(e.preventDefault(),e.stopPropagation(),this.settle())},document.addEventListener("click",this.clickHandler,{capture:!0})}setupVisibilityMonitoring(){this.visibilityCheckInterval=setInterval(()=>{const e=this.currentElement;if(!e)return;const t=e.getBoundingClientRect();if(t.bottom<0||t.top>window.innerHeight||t.right<0||t.left>window.innerWidth)return void this.settle("ELEMENT_OFF_SCREEN: The highlighted element scrolled out of view");const n=wc.getSequenceForElement(e)??-1,r=wc.notInteractableReason(e,n);r&&this.settle(r)},200)}escapeHtml(e){const t=document.createElement("div");return t.textContent=e,t.innerHTML}},Tc=e=>({success:!0,data:{text:e}}),Rc=e=>({success:!0,data:e}),Oc=e=>({success:!1,error:e}),Ac=(e,t)=>({success:!0,data:{text:e},afterResponseAttempt:t}),_c="finish",Dc=new class{tools={navigate:{label:"Navigating",run:e=>this.navigate(e)},search_web:{label:"Searching",run:e=>this.search(e)},click_element:{label:"Clicking element",waitForUser:!0,run:e=>this.clickElement(e)},type_text:{label:"Typing text",waitForUser:!0,run:e=>this.typeText(e)},scroll:{label:"Scrolling",run:e=>this.scroll(e)},scroll_to_text:{label:"Scrolling to text",run:e=>this.scrollToText(e)},extract:{label:"Extracting content",run:e=>this.extract(e)},go_back:{label:"Going back",run:()=>this.goBack()},wait_seconds:{label:"Waiting",run:e=>this.wait(e)},select_dropdown:{label:"Selecting option",waitForUser:!0,run:e=>this.selectDropdownOption(e)},get_dropdown_options:{label:"Reading dropdown options",run:e=>this.getDropdownOptions(e)},send_keys:{label:"Pressing key",waitForUser:!0,run:e=>this.sendKeys(e)},close_tab:{label:"Closing tab",run:()=>this.closeTab()},[_c]:{label:"Done",run:e=>this.done(e)},get_html:{label:"Reading the page",run:()=>this.getHtml()},get_screenshot:{label:"Taking screenshot",run:()=>this.getScreenshot()}};element(e){if(void 0===e)throw new Error("Index required");const{element:t,error:n}=wc.getValidatedElement(e);if(!t)throw new Error(n||`Element ${e} not found`);return t}selectElement(e){const t=this.element(e);if(!(t instanceof HTMLSelectElement))throw new Error(`Element ${e} is not a select element`);return t}getFriendlyToolName(e){return this.tools[e]?.label??e}isWaitForUserTool(e){return!!this.tools[e]?.waitForUser}async executeTool(e,t,n,r=""){const o=t,i=this.tools[e];try{return"show"===n&&i?.waitForUser&&void 0!==o.index&&await Mc.showToolAction({element:this.element(o.index),explanation:r||`Execute ${e}`,browserToolName:e,isClickAction:"click_element"===e}),i?await i.run(o):Oc(`Unknown tool: ${e}`)}catch(s){return Oc(cr(s))}}navigate(e){const t=(e=>{if(!e)return null;try{const t=new URL(e,window.location.href);return"http:"===t.protocol||"https:"===t.protocol?t.href:null}catch{return null}})(e.url);return t?e.new_tab?window.open(t,"_blank")?Tc(`Opened ${t} in new tab`):Oc("The browser blocked opening a new tab"):Ac(`Navigating to ${t}`,()=>{window.location.href=t}):Oc("An http(s) URL is required")}search(e){if(!e.query)return Oc("Query is required");const t=e.engine||"duckduckgo",n=encodeURIComponent(e.query);let r=`https://duckduckgo.com/?q=${n}`;return"google"===t&&(r=`https://www.google.com/search?q=${n}`),"bing"===t&&(r=`https://www.bing.com/search?q=${n}`),Ac(`Searching for "${e.query}" on ${t}`,()=>{window.location.href=r})}async clickElement(e){const t=this.element(e.index);return t.scrollIntoView({behavior:"smooth",block:"center"}),await new Promise(e=>setTimeout(e,100)),Ac(`Clicking element ${e.index}`,()=>t.click())}typeText(e){if(void 0===e.text)return Oc("Text required");const t=!1!==e.clear,n=this.element(e.index);if(xc(n))n.focus(),Ec(n,t?e.text:n.value+e.text),n.dispatchEvent(new InputEvent("input",{bubbles:!0,cancelable:!0,inputType:"insertText",data:e.text})),n.dispatchEvent(new Event("change",{bubbles:!0})),n.dispatchEvent(new Event("blur",{bubbles:!0}));else if(n.isContentEditable){n.focus();const r=window.getSelection();if(t?r?.selectAllChildren(n):r?.collapse(n,n.childNodes.length),!document.execCommand("insertText",!1,e.text))return Oc(`Could not insert text into element ${e.index}`)}else"value"in n?(n.value=e.text,n.dispatchEvent(new Event("input",{bubbles:!0})),n.dispatchEvent(new Event("change",{bubbles:!0}))):(n.textContent=e.text,n.dispatchEvent(new Event("input",{bubbles:!0})));return Tc(`Typed text into element ${e.index}`)}scroll(e){const t=.8*window.innerHeight;switch(e.direction){case"down":window.scrollBy({top:t,behavior:"smooth"});break;case"up":window.scrollBy({top:-t,behavior:"smooth"});break;case"left":window.scrollBy({left:-t,behavior:"smooth"});break;case"right":window.scrollBy({left:t,behavior:"smooth"});break;default:return Oc("Invalid direction")}return Tc(`Scrolled ${e.direction}`)}scrollToText(e){if(!e.text)return Oc("Text required");const t=document.createTreeWalker(document.body,NodeFilter.SHOW_TEXT);let n;for(;n=t.nextNode();)if(n.textContent?.includes(e.text)&&n.parentElement)return n.parentElement.scrollIntoView({behavior:"smooth",block:"center"}),Tc(`Scrolled to "${e.text}"`);return Oc(`Text "${e.text}" not found`)}extract(e){const t=!1!==e.extract_links,n={title:document.title,url:window.location.href,text:document.body.innerText.slice(0,1e4),links:t?Array.from(document.querySelectorAll("a[href]")).slice(0,100).map(e=>({text:e.textContent?.trim()||"",href:e.getAttribute("href")})):[]};return Rc(n)}goBack(){return window.history.length<=1?Oc("No history"):Ac("Going back",()=>window.history.back())}async wait({seconds:e}){return void 0===e?Oc("Seconds required"):(await new Promise(t=>setTimeout(t,1e3*e)),Tc(`Waited ${e}s`))}selectDropdownOption(e){if(!e.option)return Oc("Option required");const t=this.selectElement(e.index),n=Array.from(t.options).find(t=>t.value===e.option||t.text===e.option);return n?(t.value=n.value,t.dispatchEvent(new Event("change",{bubbles:!0})),Tc(`Selected ${e.option}`)):Oc(`Option ${e.option} not found`)}getDropdownOptions(e){const t=Array.from(this.selectElement(e.index).options).map(e=>({value:e.value,text:e.text}));return Rc({options:t})}sendKeys(e){if(!e.keys)return Oc("Keys required");const t=this.element(e.index);t.focus(),t.dispatchEvent(new KeyboardEvent("keydown",{key:e.keys,bubbles:!0,cancelable:!0})),t.dispatchEvent(new KeyboardEvent("keyup",{key:e.keys,bubbles:!0,cancelable:!0}));const n=function(e,t){switch(t){case"Tab":case"Shift+Tab":{const n="Tab"===t?1:-1,r=gc(document),o=r.indexOf(e),i=-1===o?void 0:r[o+n];return i?(i.focus(),`${t}: moved focus to ${i.tagName.toLowerCase()}${i.id?`#${i.id}`:""}`):`${t}: no ${n>0?"next":"previous"} focusable element`}case"Enter":if(Sc(e))return e.click(),"Enter: clicked button";if(xc(e)){const t=e.closest("form");if(t){const e=t.querySelector('button[type="submit"], input[type="submit"]');return e?(e.click(),"Enter: clicked form submit button"):(t.requestSubmit(),"Enter: submitted form")}}return e instanceof HTMLAnchorElement?(e.click(),"Enter: clicked link"):"Enter: dispatched event";case"Escape":return e.blur(),document.dispatchEvent(new KeyboardEvent("keydown",{key:"Escape",bubbles:!0,cancelable:!0})),"Escape: blurred element and dispatched to document";case" ":case"Space":return e instanceof HTMLInputElement&&("checkbox"===e.type||"radio"===e.type)?(e.click(),`Space: toggled ${e.type}`):Sc(e)?(e.click(),"Space: clicked button"):"Space: dispatched event";case"ArrowDown":return e instanceof HTMLSelectElement?kc(e,1):"ArrowDown: dispatched event";case"ArrowUp":return e instanceof HTMLSelectElement?kc(e,-1):"ArrowUp: dispatched event";case"Home":return xc(e)?(e.setSelectionRange(0,0),"Home: moved cursor to start"):"Home: dispatched event";case"End":if(xc(e)){const t=e.value.length;return e.setSelectionRange(t,t),"End: moved cursor to end"}return"End: dispatched event";case"Backspace":return xc(e)?Cc(e,"Backspace"):"Backspace: dispatched event";case"Delete":return xc(e)?Cc(e,"Delete"):"Delete: dispatched event";default:return null}}(t,e.keys);return Tc(n||`Sent keys ${e.keys}`)}closeTab(){return window.close(),window.closed?Tc("Tab closed"):Oc("The browser refused to close a tab this script did not open")}done(e){return Tc(e.message||"Task ended")}getHtml(){return Tc(wc.reindexAndSnapshot())}async getScreenshot(){const e=fr();if(!e)return Oc("The visitor is not sharing their screen.");const t=document.createElement("video");try{t.srcObject=e,t.autoplay=!0,t.style.display="none",document.body.appendChild(t),await new Promise((e,n)=>{const r=setTimeout(()=>n(/* @__PURE__ */new Error("Screen capture produced no frame")),5e3);t.onloadeddata=()=>{clearTimeout(r),e()},t.onerror=()=>{clearTimeout(r),n(/* @__PURE__ */new Error("Screen capture failed"))}});const n=document.createElement("canvas");n.width=t.videoWidth,n.height=t.videoHeight;const r=n.getContext("2d");return r?(r.drawImage(t,0,0),Tc(n.toDataURL("image/jpeg",.75))):Oc("Could not read the shared screen: the browser refused a 2d canvas context.")}finally{t.remove()}}},Pc={show:"Show",tell:"Tell",do:"Do"},Nc=e=>Pc[e];function Lc(e,t){for(let n=e.length-1;n>=0;n--)if(t(e[n]))return n;return-1}function Fc({messages:e,isTaskRunning:t,currentMode:n}){const r=e=>"agent"===e.sender&&!e.isSystemMessage&&!e.isScreenAccessRequest&&!e.taskStatus,o=e=>e.isPlaceholder&&void 0===e.mode||e.mode===n,i=[];!t||"show"!==n&&"do"!==n||i.push(e=>r(e)&&o(e)&&!!e.isPlaceholder,e=>r(e)&&o(e)),i.push(e=>r(e)&&!!e.isPlaceholder,r);const s=Lc(e,e=>"agent"===e.sender&&!!e.taskStatus)+1,a=e.slice(s);for(const c of i){const e=Lc(a,c);if(e>=0)return{index:s+e,message:a[e]}}return console.warn("[MessageFinder] No message found for progress update",{totalMessages:e.length,isTaskRunning:t,currentMode:n}),null}var zc=e=>e.replace(/\(?cancelled by cleanup\)?/gi,"").trim();function Bc(e,t,n){if(t<0)return e;const r=[...e.parts];return r[t]={...r[t],...n},{...e,parts:r}}var $c=(e,t)=>e.parts.findIndex(e=>"progress"===e.type&&"in_progress"===e.status&&e.browserToolName===t);function Wc(e,t,n,r={}){return{id:`${e}-${globalThis.crypto.randomUUID()}`,content:n,sender:t,timestamp:/* @__PURE__ */new Date,parts:n?[{type:"text",content:n}]:[],...r}}var Uc=(e,t,n="user-message")=>Wc(n,"user",e.trim(),{mode:t}),Hc=e=>Wc("agent-message","agent",e.trim()),jc=(e,t)=>Wc(t,"agent",e,{isSystemMessage:!0}),qc=e=>e.filter(e=>"text"===e.type).map(e=>e.content).join("\n"),Vc=e=>({state:e,effects:[]});function Yc(e,t,n,r,o,i,s){const a=Fc({messages:e,isTaskRunning:t,currentMode:n});if(!a)return e;let c=a.message;if("failed"===i?c=function(e,t,n){const r=$c(e,t);if(r<0)return e;const o=zc(e.parts[r].content),i=zc(n);return Bc(e,r,{status:"failed",content:i?`${o} (${i})`:o})}(c,r,s||""):"finish"!==r&&(c="in_progress"===i?function(e,t,n){const r=zc(n),o=$c(e,t);return o>=0?Bc(e,o,{content:r}):{...e,parts:[...e.parts,{type:"progress",content:r,status:"in_progress",browserToolName:t}]}}(c,r,o||Dc.getFriendlyToolName(r)):((e,t)=>Bc(e,$c(e,t),{status:"completed"}))(c,r)),t&&("show"===n||"do"===n)){const e="in_progress"===i&&"show"===n&&Dc.isWaitForUserTool(r);c={...c,placeholderState:e?"waiting-for-user":"thinking"}}const l=[...e];return l[a.index]=c,l}var Kc=(e,t)=>"running"===e.task.phase?e.task.mode??t:t,Xc=e=>({...e,isPlaceholder:!1}),Gc=e=>"stopped"===e.phase?e:{phase:"idle"};function Jc(e,t,n){const r=Fc({messages:e.messages,isTaskRunning:"running"===e.task.phase,currentMode:Kc(e,t)}),o=[...e.messages];return r&&(o[r.index]=Xc(n(r.message))),{messages:o,task:Gc(e.task)}}var Zc={completed:"done",failed:"failed",stopped:"stopped"};function Qc(e,t,n,r){const o=e.messages.map(e=>{if(e.id!==t)return e;const o=[...e.parts],i=o[o.length-1],s="text"===i?.type&&!0===i.streaming,a={type:"text",content:r&&s?i.content+n:n,...r&&{streaming:!0}};return s?o[o.length-1]=a:o.push(a),{...e,content:qc(o),isPlaceholder:!1,placeholderState:void 0,parts:o}});return{...e,messages:o}}var el=(e,t)=>{const n=[...e.parts,{type:"text",content:t}];return{...e,content:qc(n),parts:n}},tl=(e,t)=>({...Xc(el(e,t)),placeholderState:void 0,taskStatus:"failed"});function nl(e,t,n){const r=e.messages.map(e=>e.id===t?tl(e,n):e);return{...e,messages:r}}var rl=n(void 0),ol=({children:e})=>{const[t,n]=h({isOpen:!1,activeView:"home",currentMode:"tell"}),r=u(()=>({setActiveView:e=>n(t=>({...t,activeView:e})),toggleWidget:()=>n(e=>({...e,isOpen:!e.isOpen})),closeWidget:()=>n(e=>({...e,isOpen:!1})),setMode:e=>n(t=>({...t,currentMode:e})),setError:e=>n(t=>({...t,error:e})),applyState:e=>n(t=>({...t,...e}))}),[]);/* @__PURE__ */
|
|
20
|
-
return b(rl.Provider,{value:{uiState:t,uiActions:r},children:e})},il=()=>{const e=s(rl);if(!e)throw new Error("useUIStateContext must be used within UIStateProvider");return e},sl=n(void 0),al=({children:e,previewMode:t=!1})=>{const{uiState:n,uiActions:r}=il(),[o,s]=h(()=>({messages:[],task:{phase:"idle"}})),c=d(o),l=d(n.currentMode);l.current=n.currentMode;const p=d(/* @__PURE__ */new Set),f=i(e=>{const t=c.current,n=e(t);n===t||n.messages===t.messages&&n.task===t.task||(c.current=n,s(n))},[]),m=i(e=>{f(t=>({...t,messages:[...t.messages,e]}))},[f]),g=i((e,t)=>{f(n=>({...n,messages:n.messages.map(n=>n.id===e?{...n,...t}:n)}))},[f]),y=i(e=>{f(t=>({...t,messages:t.messages.filter(t=>t.id!==e)}))},[f]),v=i(e=>{f(t=>({...t,messages:e}))},[f]),w=i(()=>{f(e=>({...e,messages:[]}))},[f]),x=i(()=>{f(e=>({...e,task:{phase:"idle"}}))},[f]),S=o.messages.filter(e=>e.isPlaceholder).map(e=>`${e.id}:${e.parts.length}`).join(" ");a(()=>{const e=S.split(" ").filter(Boolean).map(e=>e.split(":")[0]).map(e=>setTimeout(()=>f(t=>function(e,t){const n=e.messages.find(e=>e.id===t);return n?.isPlaceholder&&"waiting-for-user"!==n.placeholderState?nl(e,t,"This is taking longer than expected. Please try again."):e}(t,e)),12e4));return()=>e.forEach(clearTimeout)},[S,f]);const k=i(async(e,n,r)=>{const o=n??l.current;if(t)return r||m(Uc(e,o)),void m(Hc("This is a preview. In production, I'll respond to your messages here."));const i=Le.getCredentialedConfig();if(!i)return console.error("Config not loaded or incomplete"),void m(Hc("Configuration error: Missing API credentials. Please check your widget settings."));r||m(Uc(e,o));const s=(e=>Wc("temp","agent","",{mode:e,isPlaceholder:!0,placeholderState:"thinking"}))(o);f(e=>function(e,t){return{messages:[...e.messages,t],task:{phase:"idle"}}}(e,s));try{await async function(e,t,n,r){const o=await Fe.getOrCreateChatId(),i={question:t,mode:n,chat_id:
|
|
20
|
+
return b(rl.Provider,{value:{uiState:t,uiActions:r},children:e})},il=()=>{const e=s(rl);if(!e)throw new Error("useUIStateContext must be used within UIStateProvider");return e},sl=n(void 0),al=({children:e,previewMode:t=!1})=>{const{uiState:n,uiActions:r}=il(),[o,s]=h(()=>({messages:[],task:{phase:"idle"}})),c=d(o),l=d(n.currentMode);l.current=n.currentMode;const p=d(/* @__PURE__ */new Set),f=i(e=>{const t=c.current,n=e(t);n===t||n.messages===t.messages&&n.task===t.task||(c.current=n,s(n))},[]),m=i(e=>{f(t=>({...t,messages:[...t.messages,e]}))},[f]),g=i((e,t)=>{f(n=>({...n,messages:n.messages.map(n=>n.id===e?{...n,...t}:n)}))},[f]),y=i(e=>{f(t=>({...t,messages:t.messages.filter(t=>t.id!==e)}))},[f]),v=i(e=>{f(t=>({...t,messages:e}))},[f]),w=i(()=>{f(e=>({...e,messages:[]}))},[f]),x=i(()=>{f(e=>({...e,task:{phase:"idle"}}))},[f]),S=o.messages.filter(e=>e.isPlaceholder).map(e=>`${e.id}:${e.parts.length}`).join(" ");a(()=>{const e=S.split(" ").filter(Boolean).map(e=>e.split(":")[0]).map(e=>setTimeout(()=>f(t=>function(e,t){const n=e.messages.find(e=>e.id===t);return n?.isPlaceholder&&"waiting-for-user"!==n.placeholderState?nl(e,t,"This is taking longer than expected. Please try again."):e}(t,e)),12e4));return()=>e.forEach(clearTimeout)},[S,f]);const k=i(async(e,n,r)=>{const o=n??l.current;if(t)return r||m(Uc(e,o)),void m(Hc("This is a preview. In production, I'll respond to your messages here."));const i=Le.getCredentialedConfig();if(!i)return console.error("Config not loaded or incomplete"),void m(Hc("Configuration error: Missing API credentials. Please check your widget settings."));r||m(Uc(e,o));const s=(e=>Wc("temp","agent","",{mode:e,isPlaceholder:!0,placeholderState:"thinking"}))(o);f(e=>function(e,t){return{messages:[...e.messages,t],task:{phase:"idle"}}}(e,s));try{await async function(e,t,n,r){const o=await Fe.getOrCreateChatId(),i={question:t,mode:n,chat_id:o,timestamp:/* @__PURE__ */(new Date).toISOString(),marketrix_id:e.mtxId,marketrix_key:e.mtxKey,...e.userId?{user_id:e.userId}:{}};Te.activityLogCreate({type:"widget_question",metadata:i}).catch(e=>console.warn("[ChatService] Failed to log widget question:",e));const s={type:`chat/${n}`,request_id:r,content:t};await dr.ready(o),await dr.send(s)}(i,e,o,s.id)}catch(a){console.error("Failed to send message:",a),f(e=>nl(e,s.id,"I'm sorry, I encountered an error processing your request. Please try again."))}},[t,m,f]);a(()=>{if(t)return;const e=async e=>{const{toolCallId:t,tool:n,args:o,mode:i,explanation:s}=e,a=await Dc.executeTool(n,o,i,s),c=a.success?void 0:a.error;f(e=>function(e,t,n,r,o,i){return{...e,messages:Yc(e.messages,"running"===e.task.phase,Kc(e,o),t,n,r,i)}}(e,n,s,c?"failed":"completed",l.current,c)),c||"finish"!==n||f(e=>function(e,t){return Jc(e,t,e=>({...e,taskStatus:"done",parts:e.parts.filter(e=>"progress"!==e.type)}))}(e,l.current)),await dr.send({type:"tool/response",tool_call_id:t,success:a.success,...a.success&&{data:JSON.stringify(a.data)},error:c}).catch(e=>{console.error("Failed to send tool response:",e),r.setError("Could not report that step back to the assistant — it may stop responding.")}),a.success&&a.afterResponseAttempt?.()},n={onMessage:t=>{if("tool/call"===t.type){const e=t.tool_call_id;if(p.current.has(e))return;p.current.add(e),p.current.size>1e3&&(p.current=new Set([...p.current].slice(-500)))}else"task/status"===t.type&&t.status in Zc&&p.current.clear();let n=[];f(e=>{const r=function(e,t,n){switch(t.type){case"tool/call":{if("stopped"===e.task.phase)return Vc(e);const r="running"===e.task.phase?e.task:{phase:"running",mode:t.mode||n},o=t.explanation||"";return{state:{messages:Yc(e.messages,!0,r.mode??n,t.browser_tool,o,"in_progress"),task:r},effects:[{type:"executeTool",toolCallId:t.tool_call_id,tool:t.browser_tool,args:t.args,mode:t.mode||n,explanation:o}]}}case"task/status":{if("running"===t.status)return Vc(e);const r=t.status,o=e=>t.message?el(e,t.message):e;return{state:Jc(e,n,"has_question"===r?e=>({...o(e),placeholderState:"waiting-for-user"}):e=>({...o(e),taskStatus:Zc[r]})),effects:[]}}case"chat/delta":return{state:Qc(e,t.request_id,t.text,!0),effects:[]};case"chat/response":return{state:Qc(e,t.request_id,t.text,!1),effects:[]};case"chat/error":return{state:nl(e,t.request_id,`Error: ${t.error}`),effects:[]};default:return Vc(e)}}(e,t,l.current);return n=r.effects,r.state});for(const o of n)e(o).catch(e=>{console.error("[Widget] Tool call failed:",e),r.setError("Something went wrong running that step. Please try again.")})},onError:e=>{r.setError(e.message),e instanceof ur&&f(t=>function(e,t){return{messages:e.messages.map(e=>e.isPlaceholder?tl(e,t):e),task:Gc(e.task)}}(t,e.message))}};return dr.addCallbacks(n),()=>{dr.removeCallbacks(n)}},[t,f,r]);const C=i(async()=>{f(e=>function(e,t){return{...Jc(e,t,e=>({...e,taskStatus:"stopped"})),task:{phase:"stopped"}}}(e,l.current)),t||dr.send({type:"chat/stop"}).catch(e=>{console.error("Failed to stop task remotely:",e),r.setError("Could not stop the assistant — it may still be working.")})},[t,f,r]),E=u(()=>({addMessage:m,updateMessage:g,removeMessage:y,setMessages:v,clearMessages:w,messageDispatch:k}),[m,g,y,v,w,k]),I=u(()=>({resetTask:x,stopTask:C}),[x,C]);/* @__PURE__ */
|
|
21
21
|
return b(sl.Provider,{value:{messages:o.messages,chatActions:E,taskState:o.task,taskActions:I},children:e})},cl=()=>{const e=s(sl);if(!e)throw new Error("useChatContext must be used within ChatProvider");return e},ll=n(null),ul=()=>{const{uiState:e}=il(),{messages:t}=cl();return a(()=>{const{currentMode:n,isOpen:r}=e;var o;o={messages:t,currentMode:n,isOpen:r},Le.updateContext({...o,messages:o.messages.map(({videoStream:e,...t})=>{const n=t.timestamp.toISOString();if(!e)return{...t,timestamp:n};const r="Screen sharing ended";return{...t,timestamp:n,content:r,isSystemMessage:!0,parts:[{type:"text",content:r}]}})})},[t,e]),null},dl=({children:e,previewMode:t})=>{const{uiActions:n}=il(),{chatActions:r}=cl(),[o,i]=h(!1);return a(()=>{if(t)return;let e=!1;return(async()=>{const{messages:t,...o}=function(){const{chat_id:e,config:t,timestamp:n,messages:r,...o}=Le.getContext();return{...o,messages:r.map(e=>{const t=[...e.parts],n=e.content.trim();return 0===t.length&&n&&t.push({type:"text",content:n}),{...e,timestamp:new Date(e.timestamp),parts:t}})}}();n.applyState(o),r.setMessages(t),i(!0);const s=await Fe.getOrCreateChatId();e||dr.connect(s).catch(e=>console.error("Initial stream connection failed:",e))})().catch(t=>{e||(console.error("Widget initialization failed:",t),n.setError("Widget failed to initialise — please refresh the page."))}),()=>{e=!0}},[]),/* @__PURE__ */v(y,{children:[e,o&&/* @__PURE__ */b(ul,{})]})},hl=({children:e,previewMode:t=!1})=>/* @__PURE__ */b(ol,{children:/* @__PURE__ */b(al,{previewMode:t,children:/* @__PURE__ */b(dl,{previewMode:t,children:e})})}),pl=/^#?([a-f\d]{3}|[a-f\d]{6})$/i,fl=/^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/i;function ml(e){const t=pl.exec(e.trim());if(t){const e=t[1],[n,r,o]=(3===e.length?[e[0]+e[0],e[1]+e[1],e[2]+e[2]]:[e.slice(0,2),e.slice(2,4),e.slice(4,6)]).map(e=>parseInt(e,16));return{r:n,g:r,b:o}}const n=fl.exec(e.trim());if(!n)return null;const[r,o,i]=[n[1],n[2],n[3]].map(Number);return r>255||o>255||i>255?null:{r:r,g:o,b:i}}function gl(e){const t=ml(e);if(!t)return"#000000";const[n,r,o]=[t.r/255,t.g/255,t.b/255].map(e=>e<=.03928?e/12.92:Math.pow((e+.055)/1.055,2.4));return.2126*n+.7152*r+.0722*o>.5?"#000000":"#ffffff"}function yl(e,t){const n=ml(e);return n?`rgba(${n.r}, ${n.g}, ${n.b}, ${t})`:e}function bl(e){return e.includes("gradient")?e:`linear-gradient(135deg, ${e} 0%, ${e} 100%)`}var vl={widget_background_color:"#ffffff",widget_text_color:"#1f2937",widget_border_color:"#e5e7eb",widget_accent_color:"#3b82f6",widget_secondary_color:"#6b7280"},wl=n(null),xl=()=>{const e=s(wl);if(!e)throw new Error("useWidgetConfig must be used within WidgetRoot");return e},Sl=()=>{const{uiState:e,uiActions:t}=il(),{messages:n,chatActions:r,taskState:o,taskActions:i}=cl();return{state:u(()=>({...e,messages:n,isTaskRunning:"running"===o.phase,isAwaitingReply:n.some(e=>e.isPlaceholder)}),[e,n,o]),actions:u(()=>({...t,...i,...r,clearChatHistory:()=>{r.clearMessages(),i.resetTask(),t.setError(void 0)}}),[t,i,r])}},kl={bottom_right:{vertical:"bottom",horizontal:"right"},bottom_left:{vertical:"bottom",horizontal:"left"},top_right:{vertical:"top",horizontal:"right"},top_left:{vertical:"top",horizontal:"left"}},Cl=Object.keys(kl),El=e=>kl[e],Il=e=>{const{vertical:t,horizontal:n}=El(e);return{[t]:"20px",[n]:"20px"}},Ml={top:"bottom",bottom:"top",left:"right",right:"left"},Tl=(e,t,n,r,o)=>{const{vertical:i,horizontal:s}=El(e);return{x:"left"===s?20:t-20-r,y:"top"===i?20:n-20-o}},Rl=class extends t.Component{state={hasError:!1};static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e,t){console.error(`${this.props.label} Error Boundary caught error:`,e,t)}render(){return this.state.hasError?this.props.fallback??null:this.props.children}},Ol="cubic-bezier(0.16, 1, 0.3, 1)",Al=({onPositionCommit:e})=>{const{isPreviewMode:n=!1,widget_accent_color:r,widget_background_color:o,widget_position:s,widget_position_z_index:a}=xl(),{state:c,actions:u}=Sl(),p=c.isOpen,f=c.isTaskRunning,m=!!c.error,g=!p&&(c.isAwaitingReply||f),y=!p&&f,w=m?"error":"processing",x=d(null),{isDragging:S,pixelPositionStyle:k,onPointerDown:C,onPointerMove:E,onPointerUp:I,onPointerCancel:M,suppressUntilRef:T}=function({position:e,onPositionCommit:n,isPreviewMode:r=!1,wrapperRef:o}){const[s,a]=h(!1),[c,u]=h({w:56,h:56}),[,p]=h(0),f=d(null),m=d(null),g=d(null),y=d(0),b=d([]),v=d(0),w=()=>{null!==g.current&&window.cancelAnimationFrame(g.current),g.current=null};t.useEffect(()=>w,[]),t.useEffect(()=>{if(r)return;const e=()=>p(e=>e+1);return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[r]);const x=i(()=>{if(!o.current||"undefined"==typeof window)return;const e=o.current.getBoundingClientRect();u(t=>t.w===e.width&&t.h===e.height?t:{w:e.width,h:e.height})},[o]);l(()=>{x();const e="undefined"!=typeof window&&o.current?new ResizeObserver(x):null;return e&&o.current&&e.observe(o.current),()=>e?.disconnect()},[x,e,o]);const S="undefined"!=typeof window?window.innerWidth:0,k="undefined"!=typeof window?window.innerHeight:0,C=Tl(e,S,k,c.w,c.h),E=!r&&S>0&&k>0?{left:C.x,top:C.y}:void 0,I=(e,t=.999)=>e/1e3*t/(1-t),M=()=>{w(),o.current&&(o.current.style.transform="",o.current.style.willChange="",o.current.style.transition="",o.current.style.left="",o.current.style.top="")},T=i((e,t)=>{f.current?.();let r=!1;const i=()=>{r=!0,window.clearTimeout(c),t.removeEventListener("transitionend",l),f.current=null},s=()=>{r||(i(),t.style.transition="none",t.style.willChange="",t.style.left="",t.style.top="",n(e),a(!1),requestAnimationFrame(()=>{o.current&&(o.current.style.transition="")}))},c=window.setTimeout(s,650),l=e=>{e.target===t&&"left"===e.propertyName&&s()};t.addEventListener("transitionend",l),f.current=i},[n,o]),R=i((t,r,i)=>{if(!o.current||!E)return M(),n(t),void a(!1);w();const s=o.current,l=Tl(e,S,k,c.w,c.h),u=Tl(t,S,k,c.w,c.h);s.style.transition="none",s.style.transform="none",s.style.willChange="left, top",s.style.left=`${l.x+r}px`,s.style.top=`${l.y+i}px`,requestAnimationFrame(()=>{s.style.transition=`left 600ms ${Ol}, top 600ms ${Ol}`,s.style.left=`${u.x}px`,s.style.top=`${u.y}px`}),T(t,s)},[T,n,E,e,S,k,c.w,c.h,o]),O=e=>{M(),m.current=null,a(!1),e.currentTarget.releasePointerCapture(e.pointerId)};return{isDragging:s,pixelPositionStyle:E,onPointerDown:e=>{m.current={pointerId:e.pointerId,startX:e.clientX,startY:e.clientY,dragging:!1,lastX:0,lastY:0},e.currentTarget.setPointerCapture(e.pointerId)},onPointerMove:e=>{const t=m.current;if(t?.pointerId!==e.pointerId)return;const n=e.clientX-t.startX,r=e.clientY-t.startY;if(!t.dragging&&Math.hypot(n,r)>5&&(t.dragging=!0,a(!0),b.current=[],v.current=0,o.current&&(o.current.style.willChange="transform",o.current.style.transition="none")),!t.dragging)return;t.lastX=n,t.lastY=r;const i=Date.now();i-v.current>=10&&(v.current=i,b.current=[...b.current.slice(-5),{x:e.clientX,y:e.clientY,t:i}]),null===g.current&&(g.current=window.requestAnimationFrame(()=>{g.current=null;const e=m.current,t=o.current;t&&e&&(t.style.transform=`translate3d(${e.lastX}px, ${e.lastY}px, 0)`)}))},onPointerUp:t=>{const n=m.current;if(n?.pointerId===t.pointerId){if(n.dragging){const r=(()=>{const e=b.current;if(e.length<2)return{x:0,y:0};const t=e[e.length-1].t-e[0].t;return t<=0?{x:0,y:0}:{x:(e[e.length-1].x-e[0].x)/t*1e3,y:(e[e.length-1].y-e[0].y)/t*1e3}})(),i=I(r.x),s=I(r.y),a={dx:n.lastX+i,dy:n.lastY+s},c=o.current?.getBoundingClientRect(),l=c?((e,t,n,r,o,i)=>{const s=Tl(t,n,r,o,i),a=s.x+e.dx,c=s.y+e.dy;let l=t,u=1/0;for(const d of Cl){const e=Tl(d,n,r,o,i),t=Math.hypot(a-e.x,c-e.y);t<u&&(u=t,l=d)}return l})(a,e,window.innerWidth,window.innerHeight,c.width,c.height):e;return R(l,n.lastX,n.lastY),y.current=Date.now()+600,m.current=null,void t.currentTarget.releasePointerCapture(t.pointerId)}O(t)}},onPointerCancel:e=>{m.current?.pointerId===e.pointerId&&O(e)},suppressUntilRef:y}}({position:s,onPositionCommit:e,isPreviewMode:n,wrapperRef:x});/* @__PURE__ */
|
|
22
22
|
return b(tc,{ref:x,className:"mtx-fab-anchor","data-animated":S?"false":"true","data-preview":n?"true":"false",style:{zIndex:a,pointerEvents:p?"none":"auto",...S?k:Il(s)},children:/* @__PURE__ */v(tc,{className:"mtx-fab","data-open":p?"true":"false",children:[g&&/* @__PURE__ */b(tc,{className:"mtx-fab-glow","data-tone":w,"aria-hidden":!0}),y&&!S&&/* @__PURE__ */b(Ga,{type:"button",variant:"secondary",size:"sm",className:"mtx-fab-stop","data-side":s.includes("left")?"left":"right",onClick:e=>{e.preventDefault(),e.stopPropagation(),u.stopTask()},children:"Stop"}),
|
|
23
23
|
/* @__PURE__ */b(Ga,{type:"button",variant:"bare",onClick:()=>{Date.now()<T.current||u.toggleWidget()},onDragStart:e=>e.preventDefault(),onPointerDown:C,onPointerMove:E,onPointerUp:I,onPointerCancel:M,className:"mtx-fab-trigger",style:{touchAction:"none",cursor:S?"grabbing":"grab",userSelect:"none",WebkitUserSelect:"none"},"aria-label":p?"Close":"Open","aria-live":"polite",children:/* @__PURE__ */b(nc,{className:"mtx-fab-center",children:/* @__PURE__ */v(tc,{className:"mtx-fab-badge",style:{borderRadius:"12px",backgroundColor:p?o:r,boxShadow:Pa.fab},children:[g&&/* @__PURE__ */b("svg",{className:"mtx-fab-ring","data-tone":w,viewBox:"0 0 54 54",fill:"none","aria-hidden":!0,children:/* @__PURE__ */b("rect",{x:"1.25",y:"1.25",width:"51.5",height:"51.5",rx:13,ry:13})}),
|