dooers-agents-client 0.9.2 → 0.11.0
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/README.md +4 -4
- package/dist/main.cjs +117 -20
- package/dist/main.cjs.map +1 -1
- package/dist/main.d.cts +33 -2
- package/dist/main.d.ts +33 -2
- package/dist/main.js +117 -21
- package/dist/main.js.map +1 -1
- package/package.json +1 -1
package/dist/main.d.cts
CHANGED
|
@@ -115,6 +115,8 @@ interface AudioDisplayPart {
|
|
|
115
115
|
mimeType?: string;
|
|
116
116
|
duration?: number;
|
|
117
117
|
filename?: string;
|
|
118
|
+
/** Upload ref when present on the wire (replay / blob key correlation). */
|
|
119
|
+
refId?: string;
|
|
118
120
|
}
|
|
119
121
|
interface ImageDisplayPart {
|
|
120
122
|
type: 'image';
|
|
@@ -124,6 +126,7 @@ interface ImageDisplayPart {
|
|
|
124
126
|
height?: number;
|
|
125
127
|
alt?: string;
|
|
126
128
|
filename?: string;
|
|
129
|
+
refId?: string;
|
|
127
130
|
}
|
|
128
131
|
interface DocumentDisplayPart {
|
|
129
132
|
type: 'document';
|
|
@@ -131,6 +134,7 @@ interface DocumentDisplayPart {
|
|
|
131
134
|
filename?: string;
|
|
132
135
|
mimeType?: string;
|
|
133
136
|
sizeBytes?: number;
|
|
137
|
+
refId?: string;
|
|
134
138
|
}
|
|
135
139
|
type DisplayContentPart = TextDisplayPart | AudioDisplayPart | ImageDisplayPart | DocumentDisplayPart;
|
|
136
140
|
type ContentPart = SendContentPart;
|
|
@@ -230,6 +234,8 @@ interface User {
|
|
|
230
234
|
userId: string;
|
|
231
235
|
userName?: string | null;
|
|
232
236
|
userEmail?: string | null;
|
|
237
|
+
userMobileNumber?: string | null;
|
|
238
|
+
userWhatsappNumber?: string | null;
|
|
233
239
|
identityIds?: string[];
|
|
234
240
|
systemRole: string;
|
|
235
241
|
organizationRole: string;
|
|
@@ -414,11 +420,15 @@ interface AgentConnectionConfig {
|
|
|
414
420
|
userId?: string;
|
|
415
421
|
userName?: string;
|
|
416
422
|
userEmail?: string;
|
|
423
|
+
userMobileNumber?: string;
|
|
424
|
+
userWhatsappNumber?: string;
|
|
417
425
|
identityIds?: string[];
|
|
418
426
|
systemRole?: string;
|
|
419
427
|
organizationRole?: string;
|
|
420
428
|
workspaceRole?: string;
|
|
421
429
|
authToken?: string;
|
|
430
|
+
channel?: string;
|
|
431
|
+
channelMeta?: Record<string, unknown>;
|
|
422
432
|
}
|
|
423
433
|
type OnErrorCallback = (error: {
|
|
424
434
|
code: string;
|
|
@@ -478,6 +488,9 @@ declare class AgentClient {
|
|
|
478
488
|
private lastThreadListCursor;
|
|
479
489
|
private isLoadingMore;
|
|
480
490
|
private eventPaginationCursors;
|
|
491
|
+
/** Active settings subscription — restored after reconnect. */
|
|
492
|
+
private settingsSubscription;
|
|
493
|
+
private pingTimer;
|
|
481
494
|
constructor(callbacks: AgentActions);
|
|
482
495
|
setOnError(cb: OnErrorCallback | null): void;
|
|
483
496
|
setUploadUrl(url: string | undefined): void;
|
|
@@ -486,6 +499,12 @@ declare class AgentClient {
|
|
|
486
499
|
/** Sync active thread id for chat uploads (must match persisted thread for signed URL keys). */
|
|
487
500
|
setUploadThreadId(threadId: string | undefined): void;
|
|
488
501
|
setUploadRunId(runId: string | undefined): void;
|
|
502
|
+
/**
|
|
503
|
+
* Merge connection metadata without tearing down the WebSocket.
|
|
504
|
+
* Use for handshake token refresh and identity/role updates on an open session.
|
|
505
|
+
*/
|
|
506
|
+
updateConnectionConfig(config: Partial<AgentConnectionConfig>): void;
|
|
507
|
+
isConnected(): boolean;
|
|
489
508
|
upload(file: File | Blob, options?: {
|
|
490
509
|
filename?: string;
|
|
491
510
|
}): Promise<UploadResult>;
|
|
@@ -523,6 +542,7 @@ declare class AgentClient {
|
|
|
523
542
|
formEventId: string;
|
|
524
543
|
cancelled: boolean;
|
|
525
544
|
values: Record<string, unknown>;
|
|
545
|
+
metadata?: Record<string, unknown>;
|
|
526
546
|
}): Promise<{
|
|
527
547
|
threadId: string;
|
|
528
548
|
}>;
|
|
@@ -530,8 +550,12 @@ declare class AgentClient {
|
|
|
530
550
|
private createConnection;
|
|
531
551
|
private authenticate;
|
|
532
552
|
private route;
|
|
553
|
+
private resubscribeSettings;
|
|
554
|
+
private startHeartbeat;
|
|
555
|
+
private stopHeartbeat;
|
|
533
556
|
private scheduleReconnect;
|
|
534
557
|
private send;
|
|
558
|
+
private withChannelMetadata;
|
|
535
559
|
private sendRaw;
|
|
536
560
|
/** Resolve relative URLs in event content parts against the agent's HTTP base. */
|
|
537
561
|
private resolveEventUrls;
|
|
@@ -694,16 +718,23 @@ interface AgentProviderProps {
|
|
|
694
718
|
userId?: string;
|
|
695
719
|
userName?: string;
|
|
696
720
|
userEmail?: string;
|
|
721
|
+
userMobileNumber?: string;
|
|
722
|
+
userWhatsappNumber?: string;
|
|
697
723
|
identityIds?: string[];
|
|
698
724
|
systemRole?: string;
|
|
699
725
|
organizationRole?: string;
|
|
700
726
|
workspaceRole?: string;
|
|
701
727
|
authToken?: string;
|
|
728
|
+
channel?: string;
|
|
729
|
+
channelMeta?: Record<string, unknown>;
|
|
702
730
|
uploadUrl?: string;
|
|
703
731
|
onError?: OnErrorCallback;
|
|
704
732
|
children: ReactNode;
|
|
705
733
|
}
|
|
706
|
-
declare function AgentProvider({ url, agentId, organizationId, workspaceId, userId, userName, userEmail, identityIds, systemRole, organizationRole, workspaceRole, authToken, uploadUrl, onError, children, }: AgentProviderProps): react_jsx_runtime.JSX.Element;
|
|
734
|
+
declare function AgentProvider({ url, agentId, organizationId, workspaceId, userId, userName, userEmail, userMobileNumber, userWhatsappNumber, identityIds, systemRole, organizationRole, workspaceRole, authToken, channel, channelMeta, uploadUrl, onError, children, }: AgentProviderProps): react_jsx_runtime.JSX.Element;
|
|
707
735
|
declare function useAgentContext(): AgentContextValue;
|
|
708
736
|
|
|
709
|
-
|
|
737
|
+
/** Must match `package.json` `"version"` (connect frame telemetry). */
|
|
738
|
+
declare const PACKAGE_VERSION: "0.10.0";
|
|
739
|
+
|
|
740
|
+
export { type Actor, type AgentConnectionConfig, AgentProvider, type AgentProviderProps, AgentServerClient, type AnalyticsEvent, type AudioDisplayPart, type AudioPart, type AudioSendPart, type ConnectionStatus, type ContentPart, type DisplayContentPart, type DocumentDisplayPart, type DocumentPart, type DocumentSendPart, type EventType, type FeedbackTarget, type FeedbackType, type FormCheckboxElement, type FormElement, type FormEventData, type FormFileElement, type FormFileMetadata, type FormOption, type FormRadioElement, type FormResponseEventData, type FormSelectElement, type FormSize, type FormTextElement, type FormTextareaElement, type ImageDisplayPart, type ImagePart, type ImageSendPart, type OnErrorCallback, PACKAGE_VERSION, type PublicSettingsSchemaResult, type Run, type RunStatus, type SendContentPart, type SettingsField, type SettingsFieldGroup, type SettingsFieldType, type SettingsFieldVisibility, type SettingsFileMetadata, type SettingsItem, type SettingsSelectOption, type TextDisplayPart, type TextPart, type TextSendPart, type Thread, type ThreadEvent, type ThreadState, type UploadResult, type User, apiMessagesUrlToWebSocketUrl, isSettingsFieldGroup, toFormElement, toFormEventData, toFormResponseEventData, useAgentContext, useAnalytics, useAudioRecorder, useConnection, useFeedback, useForm, useFormFileUpload, useMessage, useSettings, useSettingsFileUpload, useThreadDetails, useThreadEvents, useThreadsActions, useThreadsList, useUpload };
|
package/dist/main.d.ts
CHANGED
|
@@ -115,6 +115,8 @@ interface AudioDisplayPart {
|
|
|
115
115
|
mimeType?: string;
|
|
116
116
|
duration?: number;
|
|
117
117
|
filename?: string;
|
|
118
|
+
/** Upload ref when present on the wire (replay / blob key correlation). */
|
|
119
|
+
refId?: string;
|
|
118
120
|
}
|
|
119
121
|
interface ImageDisplayPart {
|
|
120
122
|
type: 'image';
|
|
@@ -124,6 +126,7 @@ interface ImageDisplayPart {
|
|
|
124
126
|
height?: number;
|
|
125
127
|
alt?: string;
|
|
126
128
|
filename?: string;
|
|
129
|
+
refId?: string;
|
|
127
130
|
}
|
|
128
131
|
interface DocumentDisplayPart {
|
|
129
132
|
type: 'document';
|
|
@@ -131,6 +134,7 @@ interface DocumentDisplayPart {
|
|
|
131
134
|
filename?: string;
|
|
132
135
|
mimeType?: string;
|
|
133
136
|
sizeBytes?: number;
|
|
137
|
+
refId?: string;
|
|
134
138
|
}
|
|
135
139
|
type DisplayContentPart = TextDisplayPart | AudioDisplayPart | ImageDisplayPart | DocumentDisplayPart;
|
|
136
140
|
type ContentPart = SendContentPart;
|
|
@@ -230,6 +234,8 @@ interface User {
|
|
|
230
234
|
userId: string;
|
|
231
235
|
userName?: string | null;
|
|
232
236
|
userEmail?: string | null;
|
|
237
|
+
userMobileNumber?: string | null;
|
|
238
|
+
userWhatsappNumber?: string | null;
|
|
233
239
|
identityIds?: string[];
|
|
234
240
|
systemRole: string;
|
|
235
241
|
organizationRole: string;
|
|
@@ -414,11 +420,15 @@ interface AgentConnectionConfig {
|
|
|
414
420
|
userId?: string;
|
|
415
421
|
userName?: string;
|
|
416
422
|
userEmail?: string;
|
|
423
|
+
userMobileNumber?: string;
|
|
424
|
+
userWhatsappNumber?: string;
|
|
417
425
|
identityIds?: string[];
|
|
418
426
|
systemRole?: string;
|
|
419
427
|
organizationRole?: string;
|
|
420
428
|
workspaceRole?: string;
|
|
421
429
|
authToken?: string;
|
|
430
|
+
channel?: string;
|
|
431
|
+
channelMeta?: Record<string, unknown>;
|
|
422
432
|
}
|
|
423
433
|
type OnErrorCallback = (error: {
|
|
424
434
|
code: string;
|
|
@@ -478,6 +488,9 @@ declare class AgentClient {
|
|
|
478
488
|
private lastThreadListCursor;
|
|
479
489
|
private isLoadingMore;
|
|
480
490
|
private eventPaginationCursors;
|
|
491
|
+
/** Active settings subscription — restored after reconnect. */
|
|
492
|
+
private settingsSubscription;
|
|
493
|
+
private pingTimer;
|
|
481
494
|
constructor(callbacks: AgentActions);
|
|
482
495
|
setOnError(cb: OnErrorCallback | null): void;
|
|
483
496
|
setUploadUrl(url: string | undefined): void;
|
|
@@ -486,6 +499,12 @@ declare class AgentClient {
|
|
|
486
499
|
/** Sync active thread id for chat uploads (must match persisted thread for signed URL keys). */
|
|
487
500
|
setUploadThreadId(threadId: string | undefined): void;
|
|
488
501
|
setUploadRunId(runId: string | undefined): void;
|
|
502
|
+
/**
|
|
503
|
+
* Merge connection metadata without tearing down the WebSocket.
|
|
504
|
+
* Use for handshake token refresh and identity/role updates on an open session.
|
|
505
|
+
*/
|
|
506
|
+
updateConnectionConfig(config: Partial<AgentConnectionConfig>): void;
|
|
507
|
+
isConnected(): boolean;
|
|
489
508
|
upload(file: File | Blob, options?: {
|
|
490
509
|
filename?: string;
|
|
491
510
|
}): Promise<UploadResult>;
|
|
@@ -523,6 +542,7 @@ declare class AgentClient {
|
|
|
523
542
|
formEventId: string;
|
|
524
543
|
cancelled: boolean;
|
|
525
544
|
values: Record<string, unknown>;
|
|
545
|
+
metadata?: Record<string, unknown>;
|
|
526
546
|
}): Promise<{
|
|
527
547
|
threadId: string;
|
|
528
548
|
}>;
|
|
@@ -530,8 +550,12 @@ declare class AgentClient {
|
|
|
530
550
|
private createConnection;
|
|
531
551
|
private authenticate;
|
|
532
552
|
private route;
|
|
553
|
+
private resubscribeSettings;
|
|
554
|
+
private startHeartbeat;
|
|
555
|
+
private stopHeartbeat;
|
|
533
556
|
private scheduleReconnect;
|
|
534
557
|
private send;
|
|
558
|
+
private withChannelMetadata;
|
|
535
559
|
private sendRaw;
|
|
536
560
|
/** Resolve relative URLs in event content parts against the agent's HTTP base. */
|
|
537
561
|
private resolveEventUrls;
|
|
@@ -694,16 +718,23 @@ interface AgentProviderProps {
|
|
|
694
718
|
userId?: string;
|
|
695
719
|
userName?: string;
|
|
696
720
|
userEmail?: string;
|
|
721
|
+
userMobileNumber?: string;
|
|
722
|
+
userWhatsappNumber?: string;
|
|
697
723
|
identityIds?: string[];
|
|
698
724
|
systemRole?: string;
|
|
699
725
|
organizationRole?: string;
|
|
700
726
|
workspaceRole?: string;
|
|
701
727
|
authToken?: string;
|
|
728
|
+
channel?: string;
|
|
729
|
+
channelMeta?: Record<string, unknown>;
|
|
702
730
|
uploadUrl?: string;
|
|
703
731
|
onError?: OnErrorCallback;
|
|
704
732
|
children: ReactNode;
|
|
705
733
|
}
|
|
706
|
-
declare function AgentProvider({ url, agentId, organizationId, workspaceId, userId, userName, userEmail, identityIds, systemRole, organizationRole, workspaceRole, authToken, uploadUrl, onError, children, }: AgentProviderProps): react_jsx_runtime.JSX.Element;
|
|
734
|
+
declare function AgentProvider({ url, agentId, organizationId, workspaceId, userId, userName, userEmail, userMobileNumber, userWhatsappNumber, identityIds, systemRole, organizationRole, workspaceRole, authToken, channel, channelMeta, uploadUrl, onError, children, }: AgentProviderProps): react_jsx_runtime.JSX.Element;
|
|
707
735
|
declare function useAgentContext(): AgentContextValue;
|
|
708
736
|
|
|
709
|
-
|
|
737
|
+
/** Must match `package.json` `"version"` (connect frame telemetry). */
|
|
738
|
+
declare const PACKAGE_VERSION: "0.10.0";
|
|
739
|
+
|
|
740
|
+
export { type Actor, type AgentConnectionConfig, AgentProvider, type AgentProviderProps, AgentServerClient, type AnalyticsEvent, type AudioDisplayPart, type AudioPart, type AudioSendPart, type ConnectionStatus, type ContentPart, type DisplayContentPart, type DocumentDisplayPart, type DocumentPart, type DocumentSendPart, type EventType, type FeedbackTarget, type FeedbackType, type FormCheckboxElement, type FormElement, type FormEventData, type FormFileElement, type FormFileMetadata, type FormOption, type FormRadioElement, type FormResponseEventData, type FormSelectElement, type FormSize, type FormTextElement, type FormTextareaElement, type ImageDisplayPart, type ImagePart, type ImageSendPart, type OnErrorCallback, PACKAGE_VERSION, type PublicSettingsSchemaResult, type Run, type RunStatus, type SendContentPart, type SettingsField, type SettingsFieldGroup, type SettingsFieldType, type SettingsFieldVisibility, type SettingsFileMetadata, type SettingsItem, type SettingsSelectOption, type TextDisplayPart, type TextPart, type TextSendPart, type Thread, type ThreadEvent, type ThreadState, type UploadResult, type User, apiMessagesUrlToWebSocketUrl, isSettingsFieldGroup, toFormElement, toFormEventData, toFormResponseEventData, useAgentContext, useAnalytics, useAudioRecorder, useConnection, useFeedback, useForm, useFormFileUpload, useMessage, useSettings, useSettingsFileUpload, useThreadDetails, useThreadEvents, useThreadsActions, useThreadsList, useUpload };
|
package/dist/main.js
CHANGED
|
@@ -22,6 +22,9 @@ function apiMessagesUrlToWebSocketUrl(url) {
|
|
|
22
22
|
throw new Error("API Messages URL must start with http://, https://, ws://, or wss://");
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
// src/version.ts
|
|
26
|
+
var PACKAGE_VERSION = "0.10.0";
|
|
27
|
+
|
|
25
28
|
// src/types.ts
|
|
26
29
|
function isSettingsFieldGroup(item) {
|
|
27
30
|
return "fields" in item && Array.isArray(item.fields);
|
|
@@ -32,6 +35,8 @@ function toUser(w) {
|
|
|
32
35
|
userId: w.user_id,
|
|
33
36
|
userName: w.user_name,
|
|
34
37
|
userEmail: w.user_email,
|
|
38
|
+
userMobileNumber: w.user_mobile_number,
|
|
39
|
+
userWhatsappNumber: w.user_whatsapp_number,
|
|
35
40
|
identityIds: w.identity_ids,
|
|
36
41
|
systemRole: w.system_role,
|
|
37
42
|
organizationRole: w.organization_role,
|
|
@@ -63,7 +68,8 @@ function toDisplayContentPart(w) {
|
|
|
63
68
|
url: w.url,
|
|
64
69
|
mimeType: w.mime_type,
|
|
65
70
|
duration: w.duration,
|
|
66
|
-
filename: w.filename
|
|
71
|
+
filename: w.filename,
|
|
72
|
+
...w.ref_id ? { refId: w.ref_id } : {}
|
|
67
73
|
};
|
|
68
74
|
case "image":
|
|
69
75
|
return {
|
|
@@ -73,7 +79,8 @@ function toDisplayContentPart(w) {
|
|
|
73
79
|
width: w.width,
|
|
74
80
|
height: w.height,
|
|
75
81
|
alt: w.alt,
|
|
76
|
-
filename: w.filename
|
|
82
|
+
filename: w.filename,
|
|
83
|
+
...w.ref_id ? { refId: w.ref_id } : {}
|
|
77
84
|
};
|
|
78
85
|
case "document":
|
|
79
86
|
return {
|
|
@@ -81,7 +88,8 @@ function toDisplayContentPart(w) {
|
|
|
81
88
|
url: w.url,
|
|
82
89
|
filename: w.filename,
|
|
83
90
|
mimeType: w.mime_type,
|
|
84
|
-
sizeBytes: w.size_bytes
|
|
91
|
+
sizeBytes: w.size_bytes,
|
|
92
|
+
...w.ref_id ? { refId: w.ref_id } : {}
|
|
85
93
|
};
|
|
86
94
|
}
|
|
87
95
|
}
|
|
@@ -276,6 +284,7 @@ function toWireContentPart(p) {
|
|
|
276
284
|
var MAX_RECONNECT_ATTEMPTS = 5;
|
|
277
285
|
var RECONNECT_DELAYS = [1e3, 2e3, 4e3, 8e3, 16e3];
|
|
278
286
|
var SEND_MESSAGE_TIMEOUT = 3e4;
|
|
287
|
+
var PING_INTERVAL_MS = 3e4;
|
|
279
288
|
function blobPartFilename(blob, override) {
|
|
280
289
|
const o = (override ?? "").trim();
|
|
281
290
|
if (o) return o;
|
|
@@ -408,7 +417,8 @@ var AgentClient = class {
|
|
|
408
417
|
config = {
|
|
409
418
|
organizationId: "",
|
|
410
419
|
workspaceId: "",
|
|
411
|
-
userId: ""
|
|
420
|
+
userId: "",
|
|
421
|
+
channel: "dooers-platform"
|
|
412
422
|
};
|
|
413
423
|
connectFrameId = "";
|
|
414
424
|
isIntentionallyClosed = false;
|
|
@@ -427,6 +437,9 @@ var AgentClient = class {
|
|
|
427
437
|
isLoadingMore = false;
|
|
428
438
|
// Event pagination cursors per thread
|
|
429
439
|
eventPaginationCursors = /* @__PURE__ */ new Map();
|
|
440
|
+
/** Active settings subscription — restored after reconnect. */
|
|
441
|
+
settingsSubscription = null;
|
|
442
|
+
pingTimer = null;
|
|
430
443
|
constructor(callbacks) {
|
|
431
444
|
this.callbacks = callbacks;
|
|
432
445
|
}
|
|
@@ -447,6 +460,16 @@ var AgentClient = class {
|
|
|
447
460
|
setUploadRunId(runId) {
|
|
448
461
|
this.uploadRunId = (runId ?? "").trim();
|
|
449
462
|
}
|
|
463
|
+
/**
|
|
464
|
+
* Merge connection metadata without tearing down the WebSocket.
|
|
465
|
+
* Use for handshake token refresh and identity/role updates on an open session.
|
|
466
|
+
*/
|
|
467
|
+
updateConnectionConfig(config) {
|
|
468
|
+
this.config = { ...this.config, ...config };
|
|
469
|
+
}
|
|
470
|
+
isConnected() {
|
|
471
|
+
return this.ws?.readyState === WebSocket.OPEN;
|
|
472
|
+
}
|
|
450
473
|
async upload(file, options) {
|
|
451
474
|
if (!this.uploadUrl) {
|
|
452
475
|
throw new Error("uploadUrl not configured");
|
|
@@ -530,6 +553,7 @@ var AgentClient = class {
|
|
|
530
553
|
}
|
|
531
554
|
disconnect() {
|
|
532
555
|
this.isIntentionallyClosed = true;
|
|
556
|
+
this.stopHeartbeat();
|
|
533
557
|
if (this.reconnectTimer) {
|
|
534
558
|
clearTimeout(this.reconnectTimer);
|
|
535
559
|
this.reconnectTimer = null;
|
|
@@ -595,13 +619,17 @@ var AgentClient = class {
|
|
|
595
619
|
}
|
|
596
620
|
// --- Settings ---
|
|
597
621
|
subscribeSettings(options) {
|
|
622
|
+
const audience = options?.audience ?? "user";
|
|
623
|
+
const agentOwnerUserId = options?.agentOwnerUserId ?? null;
|
|
624
|
+
this.settingsSubscription = { audience, agentOwnerUserId };
|
|
598
625
|
this.send("settings.subscribe", {
|
|
599
626
|
agent_id: this.agentId,
|
|
600
|
-
audience
|
|
601
|
-
agent_owner_user_id:
|
|
627
|
+
audience,
|
|
628
|
+
agent_owner_user_id: agentOwnerUserId
|
|
602
629
|
});
|
|
603
630
|
}
|
|
604
631
|
unsubscribeSettings() {
|
|
632
|
+
this.settingsSubscription = null;
|
|
605
633
|
this.send("settings.unsubscribe", { agent_id: this.agentId });
|
|
606
634
|
}
|
|
607
635
|
patchSetting(fieldId, value) {
|
|
@@ -695,9 +723,7 @@ var AgentClient = class {
|
|
|
695
723
|
content
|
|
696
724
|
}
|
|
697
725
|
};
|
|
698
|
-
|
|
699
|
-
payload.metadata = params.metadata;
|
|
700
|
-
}
|
|
726
|
+
payload.metadata = this.withChannelMetadata(params.metadata);
|
|
701
727
|
this.sendRaw({
|
|
702
728
|
id: clientEventId,
|
|
703
729
|
type: "event.create",
|
|
@@ -725,7 +751,8 @@ var AgentClient = class {
|
|
|
725
751
|
values: params.values
|
|
726
752
|
}
|
|
727
753
|
}
|
|
728
|
-
}
|
|
754
|
+
},
|
|
755
|
+
metadata: this.withChannelMetadata(params.metadata)
|
|
729
756
|
});
|
|
730
757
|
return promise;
|
|
731
758
|
}
|
|
@@ -745,6 +772,7 @@ var AgentClient = class {
|
|
|
745
772
|
});
|
|
746
773
|
}
|
|
747
774
|
createConnection() {
|
|
775
|
+
this.stopHeartbeat();
|
|
748
776
|
if (this.ws) {
|
|
749
777
|
this.abortPendingMessages("Connection lost; reconnecting");
|
|
750
778
|
this.ws.onopen = null;
|
|
@@ -785,13 +813,15 @@ var AgentClient = class {
|
|
|
785
813
|
user_id: this.config.userId ?? "",
|
|
786
814
|
user_name: this.config.userName ?? null,
|
|
787
815
|
user_email: this.config.userEmail ?? null,
|
|
816
|
+
user_mobile_number: this.config.userMobileNumber ?? null,
|
|
817
|
+
user_whatsapp_number: this.config.userWhatsappNumber ?? null,
|
|
788
818
|
identity_ids: this.config.identityIds ?? [],
|
|
789
819
|
system_role: this.config.systemRole ?? "user",
|
|
790
820
|
organization_role: this.config.organizationRole ?? "member",
|
|
791
821
|
workspace_role: this.config.workspaceRole ?? "member"
|
|
792
822
|
},
|
|
793
823
|
auth_token: this.config.authToken,
|
|
794
|
-
client: { name: "dooers-agents-client", version:
|
|
824
|
+
client: { name: "dooers-agents-client", version: PACKAGE_VERSION }
|
|
795
825
|
}
|
|
796
826
|
});
|
|
797
827
|
}
|
|
@@ -810,6 +840,8 @@ var AgentClient = class {
|
|
|
810
840
|
after_event_id: afterEventId
|
|
811
841
|
});
|
|
812
842
|
}
|
|
843
|
+
this.resubscribeSettings();
|
|
844
|
+
this.startHeartbeat();
|
|
813
845
|
} else {
|
|
814
846
|
this.callbacks.setConnectionStatus("error", frame.payload.error?.message);
|
|
815
847
|
}
|
|
@@ -951,7 +983,28 @@ var AgentClient = class {
|
|
|
951
983
|
break;
|
|
952
984
|
}
|
|
953
985
|
}
|
|
986
|
+
resubscribeSettings() {
|
|
987
|
+
if (!this.settingsSubscription) return;
|
|
988
|
+
this.send("settings.subscribe", {
|
|
989
|
+
agent_id: this.agentId,
|
|
990
|
+
audience: this.settingsSubscription.audience,
|
|
991
|
+
agent_owner_user_id: this.settingsSubscription.agentOwnerUserId
|
|
992
|
+
});
|
|
993
|
+
}
|
|
994
|
+
startHeartbeat() {
|
|
995
|
+
this.stopHeartbeat();
|
|
996
|
+
this.pingTimer = setInterval(() => {
|
|
997
|
+
this.send("ping", {});
|
|
998
|
+
}, PING_INTERVAL_MS);
|
|
999
|
+
}
|
|
1000
|
+
stopHeartbeat() {
|
|
1001
|
+
if (this.pingTimer) {
|
|
1002
|
+
clearInterval(this.pingTimer);
|
|
1003
|
+
this.pingTimer = null;
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
954
1006
|
scheduleReconnect() {
|
|
1007
|
+
this.stopHeartbeat();
|
|
955
1008
|
if (this.reconnectAttempts >= MAX_RECONNECT_ATTEMPTS) {
|
|
956
1009
|
this.abortPendingMessages("Connection lost after maximum retries");
|
|
957
1010
|
this.callbacks.setReconnectFailed();
|
|
@@ -969,6 +1022,17 @@ var AgentClient = class {
|
|
|
969
1022
|
send(type, payload) {
|
|
970
1023
|
this.sendRaw({ id: crypto.randomUUID(), type, payload });
|
|
971
1024
|
}
|
|
1025
|
+
withChannelMetadata(metadata) {
|
|
1026
|
+
const channel = (this.config.channel || "dooers-platform").trim() || "dooers-platform";
|
|
1027
|
+
const base = metadata ? { ...metadata } : {};
|
|
1028
|
+
if (!("channel" in base)) {
|
|
1029
|
+
base.channel = channel;
|
|
1030
|
+
}
|
|
1031
|
+
if (this.config.channelMeta && !("channel_meta" in base)) {
|
|
1032
|
+
base.channel_meta = this.config.channelMeta;
|
|
1033
|
+
}
|
|
1034
|
+
return Object.keys(base).length > 0 ? base : void 0;
|
|
1035
|
+
}
|
|
972
1036
|
sendRaw(frame) {
|
|
973
1037
|
if (!this.ws || this.ws.readyState !== WebSocket.OPEN) return;
|
|
974
1038
|
this.ws.send(JSON.stringify(frame));
|
|
@@ -1410,11 +1474,15 @@ function AgentProvider({
|
|
|
1410
1474
|
userId,
|
|
1411
1475
|
userName,
|
|
1412
1476
|
userEmail,
|
|
1477
|
+
userMobileNumber,
|
|
1478
|
+
userWhatsappNumber,
|
|
1413
1479
|
identityIds,
|
|
1414
1480
|
systemRole,
|
|
1415
1481
|
organizationRole,
|
|
1416
1482
|
workspaceRole,
|
|
1417
1483
|
authToken,
|
|
1484
|
+
channel,
|
|
1485
|
+
channelMeta,
|
|
1418
1486
|
uploadUrl,
|
|
1419
1487
|
onError,
|
|
1420
1488
|
children
|
|
@@ -1435,35 +1503,63 @@ function AgentProvider({
|
|
|
1435
1503
|
clientRef.current?.setUploadAgentId(agentId);
|
|
1436
1504
|
}, [agentId]);
|
|
1437
1505
|
const identityIdsKey = identityIds?.join(",") ?? "";
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1506
|
+
const channelMetaKey = channelMeta ? JSON.stringify(channelMeta) : "";
|
|
1507
|
+
const connectionConfig = useMemo(() => {
|
|
1508
|
+
let parsedChannelMeta;
|
|
1509
|
+
if (channelMetaKey) {
|
|
1510
|
+
try {
|
|
1511
|
+
parsedChannelMeta = JSON.parse(channelMetaKey);
|
|
1512
|
+
} catch {
|
|
1513
|
+
parsedChannelMeta = channelMeta;
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
return {
|
|
1441
1517
|
organizationId,
|
|
1442
1518
|
workspaceId,
|
|
1443
1519
|
userId,
|
|
1444
1520
|
userName,
|
|
1445
1521
|
userEmail,
|
|
1522
|
+
userMobileNumber,
|
|
1523
|
+
userWhatsappNumber,
|
|
1446
1524
|
identityIds: identityIdsKey ? identityIdsKey.split(",") : void 0,
|
|
1447
1525
|
systemRole,
|
|
1448
1526
|
organizationRole,
|
|
1449
1527
|
workspaceRole,
|
|
1450
|
-
authToken
|
|
1451
|
-
|
|
1452
|
-
|
|
1528
|
+
authToken,
|
|
1529
|
+
channel,
|
|
1530
|
+
channelMeta: parsedChannelMeta
|
|
1531
|
+
};
|
|
1453
1532
|
}, [
|
|
1454
|
-
url,
|
|
1455
|
-
agentId,
|
|
1456
1533
|
organizationId,
|
|
1457
1534
|
workspaceId,
|
|
1458
1535
|
userId,
|
|
1459
1536
|
userName,
|
|
1460
1537
|
userEmail,
|
|
1538
|
+
userMobileNumber,
|
|
1539
|
+
userWhatsappNumber,
|
|
1461
1540
|
identityIdsKey,
|
|
1462
1541
|
systemRole,
|
|
1463
1542
|
organizationRole,
|
|
1464
1543
|
workspaceRole,
|
|
1465
|
-
authToken
|
|
1544
|
+
authToken,
|
|
1545
|
+
channel,
|
|
1546
|
+
channelMetaKey,
|
|
1547
|
+
channelMeta
|
|
1466
1548
|
]);
|
|
1549
|
+
const connectionConfigRef = useRef(connectionConfig);
|
|
1550
|
+
connectionConfigRef.current = connectionConfig;
|
|
1551
|
+
useEffect(() => {
|
|
1552
|
+
if (!url || !agentId) {
|
|
1553
|
+
clientRef.current?.disconnect();
|
|
1554
|
+
return;
|
|
1555
|
+
}
|
|
1556
|
+
clientRef.current?.connect(url, agentId, connectionConfigRef.current);
|
|
1557
|
+
return () => clientRef.current?.disconnect();
|
|
1558
|
+
}, [url, agentId]);
|
|
1559
|
+
useEffect(() => {
|
|
1560
|
+
if (!url || !agentId) return;
|
|
1561
|
+
clientRef.current?.updateConnectionConfig(connectionConfig);
|
|
1562
|
+
}, [url, agentId, connectionConfig]);
|
|
1467
1563
|
const contextValue = useMemo(
|
|
1468
1564
|
() => ({ store: storeRef.current, client: clientRef.current }),
|
|
1469
1565
|
[]
|
|
@@ -1915,6 +2011,6 @@ function useUpload() {
|
|
|
1915
2011
|
return { upload, isUploading };
|
|
1916
2012
|
}
|
|
1917
2013
|
|
|
1918
|
-
export { AgentProvider, AgentServerClient, apiMessagesUrlToWebSocketUrl, isSettingsFieldGroup, toFormElement, toFormEventData, toFormResponseEventData, useAgentContext, useAnalytics, useAudioRecorder, useConnection, useFeedback, useForm, useFormFileUpload, useMessage, useSettings, useSettingsFileUpload, useThreadDetails, useThreadEvents, useThreadsActions, useThreadsList, useUpload };
|
|
2014
|
+
export { AgentProvider, AgentServerClient, PACKAGE_VERSION, apiMessagesUrlToWebSocketUrl, isSettingsFieldGroup, toFormElement, toFormEventData, toFormResponseEventData, useAgentContext, useAnalytics, useAudioRecorder, useConnection, useFeedback, useForm, useFormFileUpload, useMessage, useSettings, useSettingsFileUpload, useThreadDetails, useThreadEvents, useThreadsActions, useThreadsList, useUpload };
|
|
1919
2015
|
//# sourceMappingURL=main.js.map
|
|
1920
2016
|
//# sourceMappingURL=main.js.map
|