plazbot-cli 0.3.2 → 0.3.5
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/studio/components/App.js +38 -31
- package/dist/studio/components/ChatLog.js +49 -21
- package/dist/studio/components/ConnectCard.js +85 -0
- package/dist/studio/components/Footer.js +1 -1
- package/dist/studio/components/Input.js +143 -11
- package/dist/studio/connect/api.js +66 -0
- package/dist/studio/connect/polling.js +76 -0
- package/dist/studio/connect/types.js +72 -0
- package/dist/studio/runRepl.js +5 -0
- package/dist/studio/state/store.js +13 -12
- package/package.json +1 -1
- package/src/studio/components/App.tsx +41 -33
- package/src/studio/components/ChatLog.tsx +58 -32
- package/src/studio/components/{WhatsappConnectCard.tsx → ConnectCard.tsx} +54 -22
- package/src/studio/components/Footer.tsx +1 -1
- package/src/studio/components/Input.tsx +159 -15
- package/src/studio/{whatsapp → connect}/api.ts +11 -9
- package/src/studio/{whatsapp → connect}/polling.ts +26 -25
- package/src/studio/connect/types.ts +139 -0
- package/src/studio/runRepl.tsx +6 -0
- package/src/studio/state/store.ts +26 -20
- package/dist/studio/components/WhatsappConnectCard.js +0 -57
- package/src/studio/whatsapp/types.ts +0 -80
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Types and helpers for the "connect WhatsApp from Agent Studio" flow.
|
|
3
|
-
*
|
|
4
|
-
* The backend tool `connect_whatsapp` emits a `tool_result` chunk with
|
|
5
|
-
* `type: "whatsapp_link"`. When `data.shortUrl` is present we render an
|
|
6
|
-
* inline card with the onboarding link and start polling the workspace
|
|
7
|
-
* until the new integration appears. Baseline of "known" ids comes from
|
|
8
|
-
* the server (`existingIntegrationIds`) to avoid race conditions.
|
|
9
|
-
*
|
|
10
|
-
* Mirror of /Plazbot-Front-v2.0/src/modules/agentStudio/whatsappConnect.ts
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
export interface WhatsappLinkData {
|
|
14
|
-
shortUrl?: string | null;
|
|
15
|
-
/** "whatsapp" (Cloud API) | "whatsapp_business" (Business app / QR) */
|
|
16
|
-
linkType?: string;
|
|
17
|
-
expiresAt?: string;
|
|
18
|
-
isNewLink?: boolean;
|
|
19
|
-
alreadyConnected?: boolean;
|
|
20
|
-
connectedNumbers?: Array<{ id?: string; number?: string; alias?: string }>;
|
|
21
|
-
existingIntegrationIds?: string[];
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export type WaConnectStatus =
|
|
25
|
-
| 'waiting' // card visible, polling active
|
|
26
|
-
| 'activating' // integration detected, activating via API
|
|
27
|
-
| 'connected' // activated successfully
|
|
28
|
-
| 'timeout' // attempts exhausted
|
|
29
|
-
| 'cancelled' // user cancelled
|
|
30
|
-
| 'error'; // activation failed
|
|
31
|
-
|
|
32
|
-
export interface WaConnectState {
|
|
33
|
-
/** Stable id used by the store + card. */
|
|
34
|
-
id: string;
|
|
35
|
-
linkData: WhatsappLinkData;
|
|
36
|
-
status: WaConnectStatus;
|
|
37
|
-
/** Message id this card anchors to in the chat log. */
|
|
38
|
-
anchorMessageId: string;
|
|
39
|
-
connectedNumber?: string;
|
|
40
|
-
errorMessage?: string;
|
|
41
|
-
attempt: number;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/** Minimal shape of an integration item as returned by GET /api/workspace/{id}. */
|
|
45
|
-
export interface WorkspaceIntegrationItem {
|
|
46
|
-
id?: string;
|
|
47
|
-
type?: string;
|
|
48
|
-
cellphoneNumber?: string;
|
|
49
|
-
cellphoneNumberFormat?: string;
|
|
50
|
-
creationDate?: string;
|
|
51
|
-
isActive?: number | boolean;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export const WA_POLL_INTERVAL_MS = 5000;
|
|
55
|
-
export const WA_POLL_MAX_ATTEMPTS = 60; // 5 minutes
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Returns a new whatsapp integration whose id is NOT in the baseline.
|
|
59
|
-
* If multiple are new, picks the most recently created one.
|
|
60
|
-
*/
|
|
61
|
-
export function findNewWhatsappIntegration(
|
|
62
|
-
integrations: WorkspaceIntegrationItem[] | undefined,
|
|
63
|
-
knownIds: Set<string>,
|
|
64
|
-
): WorkspaceIntegrationItem | null {
|
|
65
|
-
if (!integrations?.length) return null;
|
|
66
|
-
|
|
67
|
-
const candidates = integrations.filter(
|
|
68
|
-
(i) =>
|
|
69
|
-
(i.type === 'whatsapp' || i.type === 'whatsapp_business') &&
|
|
70
|
-
!!i.id &&
|
|
71
|
-
!knownIds.has(i.id as string),
|
|
72
|
-
);
|
|
73
|
-
if (!candidates.length) return null;
|
|
74
|
-
|
|
75
|
-
return candidates.reduce((latest, current) => {
|
|
76
|
-
const a = latest.creationDate ? new Date(latest.creationDate).getTime() : 0;
|
|
77
|
-
const b = current.creationDate ? new Date(current.creationDate).getTime() : 0;
|
|
78
|
-
return b > a ? current : latest;
|
|
79
|
-
});
|
|
80
|
-
}
|