@burdenoff/microfe-botmanor 2026.1120.8 → 2026.1120.10
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/botlit/components/ChannelSetupPanels.d.ts +5 -0
- package/dist/botlit/components/ChannelSetupPanels.js +19 -15
- package/dist/botlit/components/ChannelSetupPanels.js.map +1 -1
- package/dist/botlit/components/HandoffConfigPanel.js +14 -2
- package/dist/botlit/components/HandoffConfigPanel.js.map +1 -1
- package/dist/botlit/hooks/index.d.ts +2 -2
- package/dist/botlit/hooks/index.js +2 -2
- package/dist/botlit/hooks/useChannelSetup.d.ts +21 -4
- package/dist/botlit/hooks/useChannelSetup.js +128 -32
- package/dist/botlit/hooks/useChannelSetup.js.map +1 -1
- package/dist/botlit/hooks/useHandoffs.d.ts +28 -1
- package/dist/botlit/hooks/useHandoffs.js +68 -33
- package/dist/botlit/hooks/useHandoffs.js.map +1 -1
- package/dist/botlit/pages/BotChannelsTab.js +1 -0
- package/dist/botlit/pages/BotChannelsTab.js.map +1 -1
- package/dist/botlit/pages/ChannelDetailPage.js +381 -380
- package/dist/botlit/pages/ChannelDetailPage.js.map +1 -1
- package/dist/botlit/pages/HandoffsPage.js +255 -74
- package/dist/botlit/pages/HandoffsPage.js.map +1 -1
- package/dist/generated/wspace-operations.d.ts +134 -0
- package/dist/generated/wspace-operations.js +111 -66
- package/dist/generated/wspace-operations.js.map +1 -1
- package/dist/generated/wspace-types.d.ts +56 -0
- package/dist/generated/wspace-types.js +9 -7
- package/dist/generated/wspace-types.js.map +1 -1
- package/package.json +1 -1
|
@@ -4,7 +4,7 @@ import { useWorkspaceScopedGlobalClient as n } from "./internal/globalWorkspaceS
|
|
|
4
4
|
import { useCallback as r, useEffect as i, useRef as a, useState as o } from "react";
|
|
5
5
|
import { gql as s } from "@apollo/client";
|
|
6
6
|
// src/botlit/hooks/useChannelSetup.ts
|
|
7
|
-
var c = {
|
|
7
|
+
var c = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i, l = {
|
|
8
8
|
SLACK: {
|
|
9
9
|
platform: "SLACK",
|
|
10
10
|
authType: "BOT_TOKEN",
|
|
@@ -21,7 +21,101 @@ var c = {
|
|
|
21
21
|
placeholder: "Signing secret",
|
|
22
22
|
secret: !0
|
|
23
23
|
}],
|
|
24
|
-
inboundHint: "In your Slack app, open Event Subscriptions, turn events on and paste this as the Request URL. Subscribe the bot to message.channels, message.im and app_mention, then reinstall the app."
|
|
24
|
+
inboundHint: "In your Slack app, open Event Subscriptions, turn events on and paste this as the Request URL. Subscribe the bot to message.channels, message.im and app_mention, then reinstall the app.",
|
|
25
|
+
usesInboundUrl: !0
|
|
26
|
+
},
|
|
27
|
+
TEAMS: {
|
|
28
|
+
platform: "TEAMS",
|
|
29
|
+
authType: "BOT_TOKEN",
|
|
30
|
+
fields: [
|
|
31
|
+
{
|
|
32
|
+
key: "appId",
|
|
33
|
+
label: "Microsoft App ID",
|
|
34
|
+
description: "Azure portal → your Azure Bot → Settings → Configuration → Microsoft App ID (a GUID).",
|
|
35
|
+
placeholder: "00000000-0000-0000-0000-000000000000",
|
|
36
|
+
secret: !1,
|
|
37
|
+
pattern: c,
|
|
38
|
+
patternMessage: "Microsoft App ID must be a GUID"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
key: "appPassword",
|
|
42
|
+
label: "Client Secret",
|
|
43
|
+
description: "Configuration → Manage Password (or Microsoft Entra ID → App registrations → the bot app) → Certificates & secrets → New client secret. Copy the secret Value, not its ID.",
|
|
44
|
+
placeholder: "Client secret value",
|
|
45
|
+
secret: !0
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
key: "tenantId",
|
|
49
|
+
label: "App Tenant ID",
|
|
50
|
+
description: "Azure Bot → Configuration → App Tenant ID (Microsoft Entra ID → Overview → Tenant ID). The bot must be Single Tenant.",
|
|
51
|
+
placeholder: "00000000-0000-0000-0000-000000000000",
|
|
52
|
+
secret: !1,
|
|
53
|
+
pattern: c,
|
|
54
|
+
patternMessage: "App Tenant ID must be a GUID"
|
|
55
|
+
}
|
|
56
|
+
],
|
|
57
|
+
inboundHint: "In the Azure portal open your Azure Bot → Configuration, paste this as the Messaging endpoint and Apply. Under Channels, add Microsoft Teams. Then install the bot in Teams (a Teams app whose bot id is the Microsoft App ID) and message it; in a channel, @mention it.",
|
|
58
|
+
usesInboundUrl: !0
|
|
59
|
+
},
|
|
60
|
+
WHATSAPP: {
|
|
61
|
+
platform: "WHATSAPP",
|
|
62
|
+
authType: "BOT_TOKEN",
|
|
63
|
+
fields: [
|
|
64
|
+
{
|
|
65
|
+
key: "phoneNumberId",
|
|
66
|
+
label: "Phone Number ID",
|
|
67
|
+
description: "Meta app dashboard → WhatsApp → API Setup → Phone number ID (not the phone number itself).",
|
|
68
|
+
placeholder: "123456789012345",
|
|
69
|
+
secret: !1,
|
|
70
|
+
pattern: /^\d{5,20}$/,
|
|
71
|
+
patternMessage: "Phone Number ID must be digits only"
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
key: "accessToken",
|
|
75
|
+
label: "Access Token",
|
|
76
|
+
description: "A permanent token: Meta Business Settings → Users → System users → Generate new token for this app with whatsapp_business_messaging and whatsapp_business_management. The API Setup token expires after 24 hours.",
|
|
77
|
+
placeholder: "EAA…",
|
|
78
|
+
secret: !0
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
key: "appSecret",
|
|
82
|
+
label: "App Secret",
|
|
83
|
+
description: "Meta app dashboard → App settings → Basic → App secret (Show).",
|
|
84
|
+
placeholder: "App secret",
|
|
85
|
+
secret: !0
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
key: "verifyToken",
|
|
89
|
+
label: "Verify Token",
|
|
90
|
+
description: "Any value you choose. Paste the same value as the Verify token when you set up the webhook in Meta.",
|
|
91
|
+
placeholder: "Generate or paste a token",
|
|
92
|
+
secret: !0,
|
|
93
|
+
generatable: !0
|
|
94
|
+
}
|
|
95
|
+
],
|
|
96
|
+
inboundHint: "In the Meta app dashboard open WhatsApp → Configuration → Webhook → Edit. Paste this as the Callback URL and your Verify Token, then Verify and save. Under Webhook fields, subscribe to messages.",
|
|
97
|
+
usesInboundUrl: !0
|
|
98
|
+
},
|
|
99
|
+
DISCORD: {
|
|
100
|
+
platform: "DISCORD",
|
|
101
|
+
authType: "BOT_TOKEN",
|
|
102
|
+
fields: [{
|
|
103
|
+
key: "botToken",
|
|
104
|
+
label: "Bot Token",
|
|
105
|
+
description: "Discord Developer Portal → your application → Bot → Reset Token. Turn on Message Content Intent on the same page.",
|
|
106
|
+
placeholder: "Bot token",
|
|
107
|
+
secret: !0
|
|
108
|
+
}, {
|
|
109
|
+
key: "guildId",
|
|
110
|
+
label: "Server ID",
|
|
111
|
+
description: "Discord → User Settings → Advanced → Developer Mode on, then right-click your server → Copy Server ID.",
|
|
112
|
+
placeholder: "123456789012345678",
|
|
113
|
+
secret: !1,
|
|
114
|
+
pattern: /^\d{17,20}$/,
|
|
115
|
+
patternMessage: "Server ID must be a 17-20 digit number"
|
|
116
|
+
}],
|
|
117
|
+
inboundHint: "Discord delivers messages to the bot over its Gateway connection, so no URL is needed: leave Interactions Endpoint URL empty. In the Developer Portal → Bot, turn on Message Content Intent. Invite the bot to your server (OAuth2 → URL Generator → scope bot, permissions View Channels, Send Messages and Read Message History), then message or @mention it.",
|
|
118
|
+
usesInboundUrl: !1
|
|
25
119
|
},
|
|
26
120
|
WEBHOOK: {
|
|
27
121
|
platform: "WEBHOOK",
|
|
@@ -41,23 +135,24 @@ var c = {
|
|
|
41
135
|
secret: !0,
|
|
42
136
|
generatable: !0
|
|
43
137
|
}],
|
|
44
|
-
inboundHint: "POST each inbound message here as JSON ({\"event\":\"message\",\"id\",\"sender_id\",\"text\",\"conversation_id\"}), signed with the signing secret in the X-Signature header."
|
|
138
|
+
inboundHint: "POST each inbound message here as JSON ({\"event\":\"message\",\"id\",\"sender_id\",\"text\",\"conversation_id\"}), signed with the signing secret in the X-Signature header.",
|
|
139
|
+
usesInboundUrl: !0
|
|
45
140
|
}
|
|
46
|
-
},
|
|
141
|
+
}, u = {
|
|
47
142
|
SLACK: "SLACK",
|
|
48
143
|
TEAMS: "TEAMS",
|
|
49
144
|
DISCORD: "DISCORD",
|
|
50
145
|
WHATSAPP: "WHATSAPP",
|
|
51
146
|
WEBHOOK: "WEBHOOK"
|
|
52
147
|
};
|
|
53
|
-
function
|
|
54
|
-
return
|
|
148
|
+
function d(e) {
|
|
149
|
+
return u[e];
|
|
55
150
|
}
|
|
56
|
-
function
|
|
151
|
+
function f() {
|
|
57
152
|
let e = /* @__PURE__ */ new Uint8Array(32);
|
|
58
153
|
return crypto.getRandomValues(e), Array.from(e, (e) => e.toString(16).padStart(2, "0")).join("");
|
|
59
154
|
}
|
|
60
|
-
function
|
|
155
|
+
function p(e, t) {
|
|
61
156
|
for (let n of e.fields) {
|
|
62
157
|
let e = t[n.key]?.trim() ?? "";
|
|
63
158
|
if (!e) return `${n.label} is required`;
|
|
@@ -70,13 +165,14 @@ function f(e, t) {
|
|
|
70
165
|
}
|
|
71
166
|
if (t.protocol !== "https:") return `${n.label} must use https`;
|
|
72
167
|
}
|
|
168
|
+
if (n.pattern && !n.pattern.test(e)) return n.patternMessage ?? `${n.label} is not valid`;
|
|
73
169
|
}
|
|
74
170
|
return null;
|
|
75
171
|
}
|
|
76
|
-
function
|
|
172
|
+
function m() {
|
|
77
173
|
return e().organizationId || null;
|
|
78
174
|
}
|
|
79
|
-
var
|
|
175
|
+
var h = s`
|
|
80
176
|
query BotmanorInboundChannel($id: ID!) {
|
|
81
177
|
getChannel(id: $id) {
|
|
82
178
|
id
|
|
@@ -88,46 +184,46 @@ var m = s`
|
|
|
88
184
|
inboundWebhookUrl
|
|
89
185
|
}
|
|
90
186
|
}
|
|
91
|
-
`,
|
|
187
|
+
`, g = s`
|
|
92
188
|
mutation BotmanorCreateSetupChannel($input: CreateChannelInput!) {
|
|
93
189
|
createChannel(input: $input) {
|
|
94
190
|
id
|
|
95
191
|
}
|
|
96
192
|
}
|
|
97
|
-
`,
|
|
193
|
+
`, _ = s`
|
|
98
194
|
mutation BotmanorCreateSetupConnection($input: CreateConnectionInput!) {
|
|
99
195
|
createConnection(input: $input) {
|
|
100
196
|
id
|
|
101
197
|
}
|
|
102
198
|
}
|
|
103
|
-
`,
|
|
199
|
+
`, v = s`
|
|
104
200
|
mutation BotmanorDeleteSetupChannel($id: ID!) {
|
|
105
201
|
deleteChannel(id: $id)
|
|
106
202
|
}
|
|
107
203
|
`;
|
|
108
|
-
function
|
|
204
|
+
function y(e, n) {
|
|
109
205
|
let r = t(e);
|
|
110
206
|
return r ? Error(r, { cause: e }) : e instanceof Error ? e : Error(n, { cause: e });
|
|
111
207
|
}
|
|
112
|
-
function
|
|
208
|
+
function b(e, t) {
|
|
113
209
|
let n = e.error;
|
|
114
|
-
if (n != null) throw
|
|
210
|
+
if (n != null) throw y(n, t);
|
|
115
211
|
}
|
|
116
|
-
function
|
|
117
|
-
let { client: t, context: s } = n(), [c, l] = o(null), [u, d] = o(!1), [f, p] = o(void 0),
|
|
118
|
-
let n = ++
|
|
212
|
+
function x(e) {
|
|
213
|
+
let { client: t, context: s } = n(), [c, l] = o(null), [u, d] = o(!1), [f, p] = o(void 0), m = a(0), g = r(async () => {
|
|
214
|
+
let n = ++m.current, r = () => n === m.current;
|
|
119
215
|
if (l(null), p(void 0), e) {
|
|
120
216
|
d(!0);
|
|
121
217
|
try {
|
|
122
218
|
let n = await t.query({
|
|
123
|
-
query:
|
|
219
|
+
query: h,
|
|
124
220
|
variables: { id: e },
|
|
125
221
|
fetchPolicy: "network-only",
|
|
126
222
|
context: s
|
|
127
223
|
});
|
|
128
|
-
|
|
224
|
+
b(n, "Failed to load the channel"), r() && l(n.data?.getChannel ?? null);
|
|
129
225
|
} catch (e) {
|
|
130
|
-
r() && p(
|
|
226
|
+
r() && p(y(e, "Failed to load the channel"));
|
|
131
227
|
} finally {
|
|
132
228
|
r() && d(!1);
|
|
133
229
|
}
|
|
@@ -146,10 +242,10 @@ function b(e) {
|
|
|
146
242
|
refetch: g
|
|
147
243
|
};
|
|
148
244
|
}
|
|
149
|
-
function
|
|
245
|
+
function S() {
|
|
150
246
|
let { client: e, context: t } = n(), [i, a] = o(!1), s = r(async (n) => {
|
|
151
|
-
|
|
152
|
-
mutation:
|
|
247
|
+
b(await e.mutate({
|
|
248
|
+
mutation: v,
|
|
153
249
|
variables: { id: n },
|
|
154
250
|
context: t
|
|
155
251
|
}), "Failed to delete the channel");
|
|
@@ -161,7 +257,7 @@ function x() {
|
|
|
161
257
|
let a;
|
|
162
258
|
try {
|
|
163
259
|
let s = await e.mutate({
|
|
164
|
-
mutation:
|
|
260
|
+
mutation: g,
|
|
165
261
|
variables: { input: {
|
|
166
262
|
name: n,
|
|
167
263
|
description: r || void 0,
|
|
@@ -171,15 +267,15 @@ function x() {
|
|
|
171
267
|
} },
|
|
172
268
|
context: t
|
|
173
269
|
});
|
|
174
|
-
|
|
270
|
+
b(s, "Failed to create the channel"), a = s.data?.createChannel?.id;
|
|
175
271
|
} catch (e) {
|
|
176
|
-
throw
|
|
272
|
+
throw y(e, "Failed to create the channel");
|
|
177
273
|
}
|
|
178
274
|
if (!a) throw Error("Failed to create the channel");
|
|
179
275
|
let l = Object.fromEntries(o.fields.map((e) => [e.key, c[e.key]?.trim() ?? ""]));
|
|
180
276
|
try {
|
|
181
|
-
|
|
182
|
-
mutation:
|
|
277
|
+
b(await e.mutate({
|
|
278
|
+
mutation: _,
|
|
183
279
|
variables: { input: {
|
|
184
280
|
channelId: a,
|
|
185
281
|
authType: o.authType,
|
|
@@ -188,7 +284,7 @@ function x() {
|
|
|
188
284
|
context: t
|
|
189
285
|
}), "Failed to save the channel credentials");
|
|
190
286
|
} catch (e) {
|
|
191
|
-
throw await s(a).catch(() => void 0),
|
|
287
|
+
throw await s(a).catch(() => void 0), y(e, "Failed to save the channel credentials");
|
|
192
288
|
}
|
|
193
289
|
return a;
|
|
194
290
|
} finally {
|
|
@@ -203,6 +299,6 @@ function x() {
|
|
|
203
299
|
loading: i
|
|
204
300
|
};
|
|
205
301
|
}
|
|
206
|
-
export {
|
|
302
|
+
export { l as PLATFORM_CREDENTIALS, d as connectorPlatform, f as generateSigningSecret, m as useActiveOrganizationId, x as useInboundChannel, S as useProvisionChannel, p as validateCredentials };
|
|
207
303
|
|
|
208
304
|
//# sourceMappingURL=useChannelSetup.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useChannelSetup.js","names":["PLATFORM_CREDENTIALS","CONNECTOR_PLATFORM","connectorPlatform","connectorType","generateSigningSecret","bytes","byte","validateCredentials","field","definition","value","values","parsed","useActiveOrganizationId","useBotlit","GetInboundChannelDocument","CreateSetupChannelDocument","CreateSetupConnectionDocument","DeleteSetupChannelDocument","toError","message","extractGraphqlFailureMessage","cause","fallback","throwIfOperationFailed","operationError","result","useInboundChannel","useWorkspaceScopedGlobalClient","data","setData","useState","loading","setLoading","error","setError","latestRequest","useRef","refetch","useCallback","request","isLatest","channelId","client","context","useEffect","useProvisionChannel","discard","created","description","trimmed","credentials"],"sources":["../../../src/botlit/hooks/useChannelSetup.ts"],"sourcesContent":["/**\n * Channel setup hooks (BOFF-15360)\n * @module botlit/hooks\n *\n * A BotManor channel connector names a channel on global-channel-svc through\n * `credentialsRefId`. That global channel holds the platform credentials (a\n * Slack bot token and signing secret, a webhook's signing secret and reply\n * URL, …) and publishes the public URL the platform must call with inbound\n * events (`Channel.inboundWebhookUrl`, set once an ACTIVE connector binds the\n * channel to this workspace).\n *\n * These hooks let the connector form create that channel with its credentials\n * and the detail page show its inbound URL, all through the shell's global\n * gateway client, scoped to the active workspace's organization (see\n * `internal/globalWorkspaceScope`). The documents are written inline, like `GetChannels` in\n * `useUserPlatformConnection`: `inboundWebhookUrl` / `inboundWorkspaceId` are\n * newer than the checked-in `graphql/global.graphql`, which cannot be\n * re-pulled while gateway introspection is disabled.\n */\n\nimport { useCallback, useEffect, useRef, useState } from 'react';\nimport { gql } from '@apollo/client';\n\nimport { useBotlit } from '../providers/BotlitProvider';\nimport { extractGraphqlFailureMessage } from '../utils/errors';\nimport { useWorkspaceScopedGlobalClient } from './internal/globalWorkspaceScope';\n\n// ============================================================================\n// Platform credential definitions\n// ============================================================================\n\n/** Global-channel platforms a connector type delivers through. */\nexport type ChannelSetupPlatform = 'SLACK' | 'TEAMS' | 'DISCORD' | 'WHATSAPP' | 'WEBHOOK';\n\n/** `ChannelAuthType` values the setup form sends. */\ntype ChannelSetupAuthType = 'BOT_TOKEN' | 'WEBHOOK';\n\nexport interface CredentialFieldDefinition {\n /** Key stored on the channel connection's credentials. */\n key: string;\n label: string;\n description: string;\n placeholder: string;\n /** Rendered as a password input and never shown again after saving. */\n secret: boolean;\n /** Offer a \"Generate\" button producing a random 64-hex-character secret. */\n generatable?: boolean;\n /** Must be an absolute https URL. */\n url?: boolean;\n}\n\nexport interface PlatformCredentialDefinition {\n platform: ChannelSetupPlatform;\n authType: ChannelSetupAuthType;\n fields: CredentialFieldDefinition[];\n /** Where to paste the inbound webhook URL on the platform side. */\n inboundHint: string;\n}\n\n/**\n * Connector types whose credentials the form can collect directly. The keys\n * are the ones global-channel-svc reads: Slack sends with `botToken` and\n * verifies inbound requests with `signingSecret`; a generic webhook verifies\n * with `webhookSecret` (HMAC-SHA256 hex in `X-Signature`) and POSTs replies\n * to `targetUrl`.\n */\nexport const PLATFORM_CREDENTIALS: Readonly<Record<string, PlatformCredentialDefinition>> = {\n SLACK: {\n platform: 'SLACK',\n authType: 'BOT_TOKEN',\n fields: [\n {\n key: 'botToken',\n label: 'Bot User OAuth Token',\n description: 'Slack app → OAuth & Permissions. Starts with xoxb-.',\n placeholder: 'xoxb-…',\n secret: true,\n },\n {\n key: 'signingSecret',\n label: 'Signing Secret',\n description: 'Slack app → Basic Information → App Credentials.',\n placeholder: 'Signing secret',\n secret: true,\n },\n ],\n inboundHint:\n 'In your Slack app, open Event Subscriptions, turn events on and paste this as the Request URL. Subscribe the bot to message.channels, message.im and app_mention, then reinstall the app.',\n },\n WEBHOOK: {\n platform: 'WEBHOOK',\n authType: 'WEBHOOK',\n fields: [\n {\n key: 'targetUrl',\n label: 'Reply URL',\n description: 'The bot POSTs its replies to this https URL.',\n placeholder: 'https://example.com/bot-replies',\n secret: false,\n url: true,\n },\n {\n key: 'webhookSecret',\n label: 'Signing Secret',\n description:\n 'Your sender signs each request body with HMAC-SHA256 using this secret and sends the hex digest in the X-Signature header.',\n placeholder: 'Generate or paste a secret',\n secret: true,\n generatable: true,\n },\n ],\n inboundHint:\n 'POST each inbound message here as JSON ({\"event\":\"message\",\"id\",\"sender_id\",\"text\",\"conversation_id\"}), signed with the signing secret in the X-Signature header.',\n },\n};\n\n/** Connector type → the global-channel platform it uses (none for widget/custom). */\nconst CONNECTOR_PLATFORM: Readonly<Record<string, ChannelSetupPlatform>> = {\n SLACK: 'SLACK',\n TEAMS: 'TEAMS',\n DISCORD: 'DISCORD',\n WHATSAPP: 'WHATSAPP',\n WEBHOOK: 'WEBHOOK',\n};\n\nexport function connectorPlatform(connectorType: string): ChannelSetupPlatform | undefined {\n return CONNECTOR_PLATFORM[connectorType];\n}\n\n/** A random 32-byte secret, hex encoded, from the browser's CSPRNG. */\nexport function generateSigningSecret(): string {\n const bytes = new Uint8Array(32);\n crypto.getRandomValues(bytes);\n return Array.from(bytes, (byte) => byte.toString(16).padStart(2, '0')).join('');\n}\n\n/**\n * Returns the first problem with the entered credentials, or null when they\n * are complete. Every field is required.\n */\nexport function validateCredentials(\n definition: PlatformCredentialDefinition,\n values: Record<string, string>\n): string | null {\n for (const field of definition.fields) {\n const value = values[field.key]?.trim() ?? '';\n if (!value) return `${field.label} is required`;\n if (field.url) {\n let parsed: URL;\n try {\n parsed = new URL(value);\n } catch {\n return `${field.label} must be a valid URL`;\n }\n if (parsed.protocol !== 'https:') return `${field.label} must use https`;\n }\n }\n return null;\n}\n\n// ============================================================================\n// Organization\n// ============================================================================\n\n/**\n * The shell's active organization (the host passes it with the workspace).\n * Global channels belong to an organization, so creating one needs it.\n */\nexport function useActiveOrganizationId(): string | null {\n return useBotlit().organizationId || null;\n}\n\n// ============================================================================\n// Documents\n// ============================================================================\n\nconst GetInboundChannelDocument = gql`\n query BotmanorInboundChannel($id: ID!) {\n getChannel(id: $id) {\n id\n name\n platform\n status\n isConnected\n inboundWorkspaceId\n inboundWebhookUrl\n }\n }\n`;\n\nconst CreateSetupChannelDocument = gql`\n mutation BotmanorCreateSetupChannel($input: CreateChannelInput!) {\n createChannel(input: $input) {\n id\n }\n }\n`;\n\nconst CreateSetupConnectionDocument = gql`\n mutation BotmanorCreateSetupConnection($input: CreateConnectionInput!) {\n createConnection(input: $input) {\n id\n }\n }\n`;\n\nconst DeleteSetupChannelDocument = gql`\n mutation BotmanorDeleteSetupChannel($id: ID!) {\n deleteChannel(id: $id)\n }\n`;\n\nexport interface InboundChannelData {\n id: string;\n name: string;\n platform: string;\n status: string;\n isConnected: boolean;\n inboundWorkspaceId: string | null;\n inboundWebhookUrl: string | null;\n}\n\nfunction toError(cause: unknown, fallback: string): Error {\n const message = extractGraphqlFailureMessage(cause);\n if (message) return new Error(message, { cause });\n return cause instanceof Error ? cause : new Error(fallback, { cause });\n}\n\n/**\n * Apollo v4 resolves (rather than rejects) with `error` set when the server\n * answers with GraphQL errors; surface those as a failure like a rejection.\n */\nfunction throwIfOperationFailed(result: unknown, fallback: string): void {\n const operationError = (result as { error?: unknown }).error;\n if (operationError != null) throw toError(operationError, fallback);\n}\n\n// ============================================================================\n// Hook: useInboundChannel\n// ============================================================================\n\ninterface UseInboundChannelResult {\n data: InboundChannelData | null;\n loading: boolean;\n error: Error | undefined;\n refetch: () => Promise<void>;\n}\n\n/** The global channel a connector names, with its inbound webhook URL. */\nexport function useInboundChannel(channelId: string | null | undefined): UseInboundChannelResult {\n const { client, context } = useWorkspaceScopedGlobalClient();\n const [data, setData] = useState<InboundChannelData | null>(null);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | undefined>(undefined);\n /** Only the latest request may set state: a slower answer for a previous channel is dropped. */\n const latestRequest = useRef(0);\n\n const refetch = useCallback(async () => {\n const request = ++latestRequest.current;\n const isLatest = () => request === latestRequest.current;\n setData(null);\n setError(undefined);\n if (!channelId) return;\n setLoading(true);\n try {\n const result = await client.query<{ getChannel: InboundChannelData | null }>({\n query: GetInboundChannelDocument,\n variables: { id: channelId },\n fetchPolicy: 'network-only',\n context,\n });\n throwIfOperationFailed(result, 'Failed to load the channel');\n if (isLatest()) setData(result.data?.getChannel ?? null);\n } catch (cause) {\n if (isLatest()) setError(toError(cause, 'Failed to load the channel'));\n } finally {\n if (isLatest()) setLoading(false);\n }\n }, [channelId, client, context]);\n\n useEffect(() => {\n void refetch();\n }, [refetch]);\n\n return { data, loading, error, refetch };\n}\n\n// ============================================================================\n// Hook: useProvisionChannel\n// ============================================================================\n\nexport interface ProvisionChannelInput {\n name: string;\n description?: string;\n organizationId: string;\n definition: PlatformCredentialDefinition;\n credentials: Record<string, string>;\n}\n\ninterface UseProvisionChannelResult {\n /** Creates the global channel and its connection; resolves to the channel id. */\n provision: (input: ProvisionChannelInput) => Promise<string>;\n /** Deletes a channel `provision` created (rollback when the connector fails). */\n discard: (channelId: string) => Promise<void>;\n loading: boolean;\n}\n\nexport function useProvisionChannel(): UseProvisionChannelResult {\n const { client, context } = useWorkspaceScopedGlobalClient();\n const [loading, setLoading] = useState(false);\n\n const discard = useCallback(\n async (channelId: string) => {\n const result = await client.mutate({\n mutation: DeleteSetupChannelDocument,\n variables: { id: channelId },\n context,\n });\n throwIfOperationFailed(result, 'Failed to delete the channel');\n },\n [client, context]\n );\n\n const provision = useCallback(\n async ({\n name,\n description,\n organizationId,\n definition,\n credentials,\n }: ProvisionChannelInput): Promise<string> => {\n setLoading(true);\n try {\n let channelId: string | undefined;\n try {\n const created = await client.mutate<{ createChannel: { id: string } | null }>({\n mutation: CreateSetupChannelDocument,\n variables: {\n input: {\n name,\n description: description || undefined,\n platform: definition.platform,\n channelType: 'COMMUNICATION',\n organizationId,\n },\n },\n context,\n });\n throwIfOperationFailed(created, 'Failed to create the channel');\n channelId = created.data?.createChannel?.id;\n } catch (cause) {\n throw toError(cause, 'Failed to create the channel');\n }\n if (!channelId) throw new Error('Failed to create the channel');\n\n const trimmed = Object.fromEntries(\n definition.fields.map((field) => [field.key, credentials[field.key]?.trim() ?? ''])\n );\n try {\n const connected = await client.mutate({\n mutation: CreateSetupConnectionDocument,\n variables: {\n input: { channelId, authType: definition.authType, credentials: trimmed },\n },\n context,\n });\n throwIfOperationFailed(connected, 'Failed to save the channel credentials');\n } catch (cause) {\n // A channel without its credentials can never deliver: remove it so\n // a retry starts clean instead of leaving an orphan behind.\n await discard(channelId).catch(() => undefined);\n throw toError(cause, 'Failed to save the channel credentials');\n }\n return channelId;\n } finally {\n setLoading(false);\n }\n },\n [client, context, discard]\n );\n\n return { provision, discard, loading };\n}\n"],"mappings":";;;;;;AAkEA,IAAaA,IAA+E;CAC1F,OAAO;EACL,UAAU;EACV,UAAU;EACV,QAAQ,CACN;GACE,KAAK;GACL,OAAO;GACP,aAAa;GACb,aAAa;GACb,QAAQ;EACV,GACA;GACE,KAAK;GACL,OAAO;GACP,aAAa;GACb,aAAa;GACb,QAAQ;EACV,CACF;EACA,aACE;CACJ;CACA,SAAS;EACP,UAAU;EACV,UAAU;EACV,QAAQ,CACN;GACE,KAAK;GACL,OAAO;GACP,aAAa;GACb,aAAa;GACb,QAAQ;GACR,KAAK;EACP,GACA;GACE,KAAK;GACL,OAAO;GACP,aACE;GACF,aAAa;GACb,QAAQ;GACR,aAAa;EACf,CACF;EACA,aACE;CACJ;AACF,GAGMC,IAAqE;CACzE,OAAO;CACP,OAAO;CACP,SAAS;CACT,UAAU;CACV,SAAS;AACX;AAEA,SAAgBC,EAAkB,GAAyD;CACzF,OAAOD,EAAmBE;AAC5B;AAGA,SAAgBC,IAAgC;CAC9C,IAAMC,oB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AAe,KAAA;OAC5B,UAAUxC,EAAW;OACrB,aAAa;OACb;MACF,EACF;MACA;KACF,CAAC;KAED,AADAe,EAAuBwB,GAAS,8BAA8B,GAC9D,IAAYA,EAAQ,MAAM,eAAe;IAC3C,SAAS1B,GAAO;KACd,MAAMH,EAAQG,GAAO,8BAA8B;IACrD;IACA,IAAI,CAACoB,GAAW,MAAU,MAAM,8BAA8B;IAE9D,IAAMQ,IAAU,OAAO,YACrBzC,EAAW,OAAO,KAAK,MAAU,CAACD,EAAM,KAAK2C,EAAY3C,EAAM,IAAI,EAAE,KAAK,KAAK,EAAE,CAAC,CACpF;IACA,IAAI;KAQF,EAAuB,MAPCmC,EAAO,OAAO;MACpC,UAAU1B;MACV,WAAW,EACT,OAAO;OAAE;OAAW,UAAUR,EAAW;OAAU,aAAayC;MAAQ,EAC1E;MACA;KACF,CAAC,GACiC,wCAAwC;IAC5E,SAAS5B,GAAO;KAId,MADA,MAAMyB,EAAQL,CAAS,CAAC,CAAC,YAAY,KAAA,CAAS,GACxCvB,EAAQG,GAAO,wCAAwC;IAC/D;IACA,OAAOoB;GACT,UAAU;IACR,EAAW,EAAK;GAClB;EACF,GACA;GAACC;GAAQC;GAASG;EAAO,CAGlB;EAAW;EAAS;CAAQ;AACvC"}
|
|
1
|
+
{"version":3,"file":"useChannelSetup.js","names":["GUID","PLATFORM_CREDENTIALS","CONNECTOR_PLATFORM","connectorPlatform","connectorType","generateSigningSecret","bytes","byte","validateCredentials","field","definition","value","values","parsed","useActiveOrganizationId","useBotlit","GetInboundChannelDocument","CreateSetupChannelDocument","CreateSetupConnectionDocument","DeleteSetupChannelDocument","toError","message","extractGraphqlFailureMessage","cause","fallback","throwIfOperationFailed","operationError","result","useInboundChannel","useWorkspaceScopedGlobalClient","data","setData","useState","loading","setLoading","error","setError","latestRequest","useRef","refetch","useCallback","request","isLatest","channelId","client","context","useEffect","useProvisionChannel","discard","created","description","trimmed","credentials"],"sources":["../../../src/botlit/hooks/useChannelSetup.ts"],"sourcesContent":["/**\n * Channel setup hooks (BOFF-15360)\n * @module botlit/hooks\n *\n * A BotManor channel connector names a channel on global-channel-svc through\n * `credentialsRefId`. That global channel holds the platform credentials (a\n * Slack bot token and signing secret, a webhook's signing secret and reply\n * URL, …) and publishes the public URL the platform must call with inbound\n * events (`Channel.inboundWebhookUrl`, set once an ACTIVE connector binds the\n * channel to this workspace).\n *\n * These hooks let the connector form create that channel with its credentials\n * and the detail page show its inbound URL, all through the shell's global\n * gateway client, scoped to the active workspace's organization (see\n * `internal/globalWorkspaceScope`). The documents are written inline, like `GetChannels` in\n * `useUserPlatformConnection`: `inboundWebhookUrl` / `inboundWorkspaceId` are\n * newer than the checked-in `graphql/global.graphql`, which cannot be\n * re-pulled while gateway introspection is disabled.\n */\n\nimport { useCallback, useEffect, useRef, useState } from 'react';\nimport { gql } from '@apollo/client';\n\nimport { useBotlit } from '../providers/BotlitProvider';\nimport { extractGraphqlFailureMessage } from '../utils/errors';\nimport { useWorkspaceScopedGlobalClient } from './internal/globalWorkspaceScope';\n\n// ============================================================================\n// Platform credential definitions\n// ============================================================================\n\n/** Global-channel platforms a connector type delivers through. */\nexport type ChannelSetupPlatform = 'SLACK' | 'TEAMS' | 'DISCORD' | 'WHATSAPP' | 'WEBHOOK';\n\n/** `ChannelAuthType` values the setup form sends. */\ntype ChannelSetupAuthType = 'BOT_TOKEN' | 'WEBHOOK';\n\nexport interface CredentialFieldDefinition {\n /** Key stored on the channel connection's credentials. */\n key: string;\n label: string;\n description: string;\n placeholder: string;\n /** Rendered as a password input and never shown again after saving. */\n secret: boolean;\n /** Offer a \"Generate\" button producing a random 64-hex-character secret. */\n generatable?: boolean;\n /** Must be an absolute https URL. */\n url?: boolean;\n /** The value must match this pattern (whole value), else `patternMessage`. */\n pattern?: RegExp;\n patternMessage?: string;\n}\n\nexport interface PlatformCredentialDefinition {\n platform: ChannelSetupPlatform;\n authType: ChannelSetupAuthType;\n fields: CredentialFieldDefinition[];\n /** Where to paste the inbound webhook URL on the platform side. */\n inboundHint: string;\n /**\n * False when the platform does not call a URL (Discord: messages arrive\n * over the bot's Gateway connection); the card then shows only the hint.\n */\n usesInboundUrl: boolean;\n}\n\n/** A Microsoft Entra GUID. */\nconst GUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\n\n/**\n * Connector types whose credentials the form can collect directly. The keys\n * are the ones global-channel-svc reads:\n * - Slack sends with `botToken` and verifies inbound requests with\n * `signingSecret`.\n * - Microsoft Teams (an Azure Bot): `appId` is the audience inbound Bot\n * Framework tokens must carry; `appId` + `appPassword` + `tenantId` get the\n * token replies are posted with.\n * - WhatsApp (Cloud API): inbound requests are verified with `appSecret`\n * (X-Hub-Signature-256) and the subscription check with `verifyToken`;\n * replies are sent from `phoneNumberId` with `accessToken`.\n * - Discord: the bot (`botToken`) receives messages over its Gateway\n * connection; `guildId` names the server whose messages this channel takes.\n * - A generic webhook verifies with `webhookSecret` (HMAC-SHA256 hex in\n * `X-Signature`) and POSTs replies to `targetUrl`.\n */\nexport const PLATFORM_CREDENTIALS: Readonly<Record<string, PlatformCredentialDefinition>> = {\n SLACK: {\n platform: 'SLACK',\n authType: 'BOT_TOKEN',\n fields: [\n {\n key: 'botToken',\n label: 'Bot User OAuth Token',\n description: 'Slack app → OAuth & Permissions. Starts with xoxb-.',\n placeholder: 'xoxb-…',\n secret: true,\n },\n {\n key: 'signingSecret',\n label: 'Signing Secret',\n description: 'Slack app → Basic Information → App Credentials.',\n placeholder: 'Signing secret',\n secret: true,\n },\n ],\n inboundHint:\n 'In your Slack app, open Event Subscriptions, turn events on and paste this as the Request URL. Subscribe the bot to message.channels, message.im and app_mention, then reinstall the app.',\n usesInboundUrl: true,\n },\n TEAMS: {\n platform: 'TEAMS',\n authType: 'BOT_TOKEN',\n fields: [\n {\n key: 'appId',\n label: 'Microsoft App ID',\n description:\n 'Azure portal → your Azure Bot → Settings → Configuration → Microsoft App ID (a GUID).',\n placeholder: '00000000-0000-0000-0000-000000000000',\n secret: false,\n pattern: GUID,\n patternMessage: 'Microsoft App ID must be a GUID',\n },\n {\n key: 'appPassword',\n label: 'Client Secret',\n description:\n 'Configuration → Manage Password (or Microsoft Entra ID → App registrations → the bot app) → Certificates & secrets → New client secret. Copy the secret Value, not its ID.',\n placeholder: 'Client secret value',\n secret: true,\n },\n {\n key: 'tenantId',\n label: 'App Tenant ID',\n description:\n 'Azure Bot → Configuration → App Tenant ID (Microsoft Entra ID → Overview → Tenant ID). The bot must be Single Tenant.',\n placeholder: '00000000-0000-0000-0000-000000000000',\n secret: false,\n pattern: GUID,\n patternMessage: 'App Tenant ID must be a GUID',\n },\n ],\n inboundHint:\n 'In the Azure portal open your Azure Bot → Configuration, paste this as the Messaging endpoint and Apply. Under Channels, add Microsoft Teams. Then install the bot in Teams (a Teams app whose bot id is the Microsoft App ID) and message it; in a channel, @mention it.',\n usesInboundUrl: true,\n },\n WHATSAPP: {\n platform: 'WHATSAPP',\n authType: 'BOT_TOKEN',\n fields: [\n {\n key: 'phoneNumberId',\n label: 'Phone Number ID',\n description:\n 'Meta app dashboard → WhatsApp → API Setup → Phone number ID (not the phone number itself).',\n placeholder: '123456789012345',\n secret: false,\n pattern: /^\\d{5,20}$/,\n patternMessage: 'Phone Number ID must be digits only',\n },\n {\n key: 'accessToken',\n label: 'Access Token',\n description:\n 'A permanent token: Meta Business Settings → Users → System users → Generate new token for this app with whatsapp_business_messaging and whatsapp_business_management. The API Setup token expires after 24 hours.',\n placeholder: 'EAA…',\n secret: true,\n },\n {\n key: 'appSecret',\n label: 'App Secret',\n description: 'Meta app dashboard → App settings → Basic → App secret (Show).',\n placeholder: 'App secret',\n secret: true,\n },\n {\n key: 'verifyToken',\n label: 'Verify Token',\n description:\n 'Any value you choose. Paste the same value as the Verify token when you set up the webhook in Meta.',\n placeholder: 'Generate or paste a token',\n secret: true,\n generatable: true,\n },\n ],\n inboundHint:\n 'In the Meta app dashboard open WhatsApp → Configuration → Webhook → Edit. Paste this as the Callback URL and your Verify Token, then Verify and save. Under Webhook fields, subscribe to messages.',\n usesInboundUrl: true,\n },\n DISCORD: {\n platform: 'DISCORD',\n authType: 'BOT_TOKEN',\n fields: [\n {\n key: 'botToken',\n label: 'Bot Token',\n description:\n 'Discord Developer Portal → your application → Bot → Reset Token. Turn on Message Content Intent on the same page.',\n placeholder: 'Bot token',\n secret: true,\n },\n {\n key: 'guildId',\n label: 'Server ID',\n description:\n 'Discord → User Settings → Advanced → Developer Mode on, then right-click your server → Copy Server ID.',\n placeholder: '123456789012345678',\n secret: false,\n pattern: /^\\d{17,20}$/,\n patternMessage: 'Server ID must be a 17-20 digit number',\n },\n ],\n inboundHint:\n 'Discord delivers messages to the bot over its Gateway connection, so no URL is needed: leave Interactions Endpoint URL empty. In the Developer Portal → Bot, turn on Message Content Intent. Invite the bot to your server (OAuth2 → URL Generator → scope bot, permissions View Channels, Send Messages and Read Message History), then message or @mention it.',\n usesInboundUrl: false,\n },\n WEBHOOK: {\n platform: 'WEBHOOK',\n authType: 'WEBHOOK',\n fields: [\n {\n key: 'targetUrl',\n label: 'Reply URL',\n description: 'The bot POSTs its replies to this https URL.',\n placeholder: 'https://example.com/bot-replies',\n secret: false,\n url: true,\n },\n {\n key: 'webhookSecret',\n label: 'Signing Secret',\n description:\n 'Your sender signs each request body with HMAC-SHA256 using this secret and sends the hex digest in the X-Signature header.',\n placeholder: 'Generate or paste a secret',\n secret: true,\n generatable: true,\n },\n ],\n inboundHint:\n 'POST each inbound message here as JSON ({\"event\":\"message\",\"id\",\"sender_id\",\"text\",\"conversation_id\"}), signed with the signing secret in the X-Signature header.',\n usesInboundUrl: true,\n },\n};\n\n/** Connector type → the global-channel platform it uses (none for widget/custom). */\nconst CONNECTOR_PLATFORM: Readonly<Record<string, ChannelSetupPlatform>> = {\n SLACK: 'SLACK',\n TEAMS: 'TEAMS',\n DISCORD: 'DISCORD',\n WHATSAPP: 'WHATSAPP',\n WEBHOOK: 'WEBHOOK',\n};\n\nexport function connectorPlatform(connectorType: string): ChannelSetupPlatform | undefined {\n return CONNECTOR_PLATFORM[connectorType];\n}\n\n/** A random 32-byte secret, hex encoded, from the browser's CSPRNG. */\nexport function generateSigningSecret(): string {\n const bytes = new Uint8Array(32);\n crypto.getRandomValues(bytes);\n return Array.from(bytes, (byte) => byte.toString(16).padStart(2, '0')).join('');\n}\n\n/**\n * Returns the first problem with the entered credentials, or null when they\n * are complete. Every field is required.\n */\nexport function validateCredentials(\n definition: PlatformCredentialDefinition,\n values: Record<string, string>\n): string | null {\n for (const field of definition.fields) {\n const value = values[field.key]?.trim() ?? '';\n if (!value) return `${field.label} is required`;\n if (field.url) {\n let parsed: URL;\n try {\n parsed = new URL(value);\n } catch {\n return `${field.label} must be a valid URL`;\n }\n if (parsed.protocol !== 'https:') return `${field.label} must use https`;\n }\n if (field.pattern && !field.pattern.test(value)) {\n return field.patternMessage ?? `${field.label} is not valid`;\n }\n }\n return null;\n}\n\n// ============================================================================\n// Organization\n// ============================================================================\n\n/**\n * The shell's active organization (the host passes it with the workspace).\n * Global channels belong to an organization, so creating one needs it.\n */\nexport function useActiveOrganizationId(): string | null {\n return useBotlit().organizationId || null;\n}\n\n// ============================================================================\n// Documents\n// ============================================================================\n\nconst GetInboundChannelDocument = gql`\n query BotmanorInboundChannel($id: ID!) {\n getChannel(id: $id) {\n id\n name\n platform\n status\n isConnected\n inboundWorkspaceId\n inboundWebhookUrl\n }\n }\n`;\n\nconst CreateSetupChannelDocument = gql`\n mutation BotmanorCreateSetupChannel($input: CreateChannelInput!) {\n createChannel(input: $input) {\n id\n }\n }\n`;\n\nconst CreateSetupConnectionDocument = gql`\n mutation BotmanorCreateSetupConnection($input: CreateConnectionInput!) {\n createConnection(input: $input) {\n id\n }\n }\n`;\n\nconst DeleteSetupChannelDocument = gql`\n mutation BotmanorDeleteSetupChannel($id: ID!) {\n deleteChannel(id: $id)\n }\n`;\n\nexport interface InboundChannelData {\n id: string;\n name: string;\n platform: string;\n status: string;\n isConnected: boolean;\n inboundWorkspaceId: string | null;\n inboundWebhookUrl: string | null;\n}\n\nfunction toError(cause: unknown, fallback: string): Error {\n const message = extractGraphqlFailureMessage(cause);\n if (message) return new Error(message, { cause });\n return cause instanceof Error ? cause : new Error(fallback, { cause });\n}\n\n/**\n * Apollo v4 resolves (rather than rejects) with `error` set when the server\n * answers with GraphQL errors; surface those as a failure like a rejection.\n */\nfunction throwIfOperationFailed(result: unknown, fallback: string): void {\n const operationError = (result as { error?: unknown }).error;\n if (operationError != null) throw toError(operationError, fallback);\n}\n\n// ============================================================================\n// Hook: useInboundChannel\n// ============================================================================\n\ninterface UseInboundChannelResult {\n data: InboundChannelData | null;\n loading: boolean;\n error: Error | undefined;\n refetch: () => Promise<void>;\n}\n\n/** The global channel a connector names, with its inbound webhook URL. */\nexport function useInboundChannel(channelId: string | null | undefined): UseInboundChannelResult {\n const { client, context } = useWorkspaceScopedGlobalClient();\n const [data, setData] = useState<InboundChannelData | null>(null);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | undefined>(undefined);\n /** Only the latest request may set state: a slower answer for a previous channel is dropped. */\n const latestRequest = useRef(0);\n\n const refetch = useCallback(async () => {\n const request = ++latestRequest.current;\n const isLatest = () => request === latestRequest.current;\n setData(null);\n setError(undefined);\n if (!channelId) return;\n setLoading(true);\n try {\n const result = await client.query<{ getChannel: InboundChannelData | null }>({\n query: GetInboundChannelDocument,\n variables: { id: channelId },\n fetchPolicy: 'network-only',\n context,\n });\n throwIfOperationFailed(result, 'Failed to load the channel');\n if (isLatest()) setData(result.data?.getChannel ?? null);\n } catch (cause) {\n if (isLatest()) setError(toError(cause, 'Failed to load the channel'));\n } finally {\n if (isLatest()) setLoading(false);\n }\n }, [channelId, client, context]);\n\n useEffect(() => {\n void refetch();\n }, [refetch]);\n\n return { data, loading, error, refetch };\n}\n\n// ============================================================================\n// Hook: useProvisionChannel\n// ============================================================================\n\nexport interface ProvisionChannelInput {\n name: string;\n description?: string;\n organizationId: string;\n definition: PlatformCredentialDefinition;\n credentials: Record<string, string>;\n}\n\ninterface UseProvisionChannelResult {\n /** Creates the global channel and its connection; resolves to the channel id. */\n provision: (input: ProvisionChannelInput) => Promise<string>;\n /** Deletes a channel `provision` created (rollback when the connector fails). */\n discard: (channelId: string) => Promise<void>;\n loading: boolean;\n}\n\nexport function useProvisionChannel(): UseProvisionChannelResult {\n const { client, context } = useWorkspaceScopedGlobalClient();\n const [loading, setLoading] = useState(false);\n\n const discard = useCallback(\n async (channelId: string) => {\n const result = await client.mutate({\n mutation: DeleteSetupChannelDocument,\n variables: { id: channelId },\n context,\n });\n throwIfOperationFailed(result, 'Failed to delete the channel');\n },\n [client, context]\n );\n\n const provision = useCallback(\n async ({\n name,\n description,\n organizationId,\n definition,\n credentials,\n }: ProvisionChannelInput): Promise<string> => {\n setLoading(true);\n try {\n let channelId: string | undefined;\n try {\n const created = await client.mutate<{ createChannel: { id: string } | null }>({\n mutation: CreateSetupChannelDocument,\n variables: {\n input: {\n name,\n description: description || undefined,\n platform: definition.platform,\n channelType: 'COMMUNICATION',\n organizationId,\n },\n },\n context,\n });\n throwIfOperationFailed(created, 'Failed to create the channel');\n channelId = created.data?.createChannel?.id;\n } catch (cause) {\n throw toError(cause, 'Failed to create the channel');\n }\n if (!channelId) throw new Error('Failed to create the channel');\n\n const trimmed = Object.fromEntries(\n definition.fields.map((field) => [field.key, credentials[field.key]?.trim() ?? ''])\n );\n try {\n const connected = await client.mutate({\n mutation: CreateSetupConnectionDocument,\n variables: {\n input: { channelId, authType: definition.authType, credentials: trimmed },\n },\n context,\n });\n throwIfOperationFailed(connected, 'Failed to save the channel credentials');\n } catch (cause) {\n // A channel without its credentials can never deliver: remove it so\n // a retry starts clean instead of leaving an orphan behind.\n await discard(channelId).catch(() => undefined);\n throw toError(cause, 'Failed to save the channel credentials');\n }\n return channelId;\n } finally {\n setLoading(false);\n }\n },\n [client, context, discard]\n );\n\n return { provision, discard, loading };\n}\n"],"mappings":";;;;;;AAoEA,IAAMA,IAAO,mEAkBAC,IAA+E;CAC1F,OAAO;EACL,UAAU;EACV,UAAU;EACV,QAAQ,CACN;GACE,KAAK;GACL,OAAO;GACP,aAAa;GACb,aAAa;GACb,QAAQ;EACV,GACA;GACE,KAAK;GACL,OAAO;GACP,aAAa;GACb,aAAa;GACb,QAAQ;EACV,CACF;EACA,aACE;EACF,gBAAgB;CAClB;CACA,OAAO;EACL,UAAU;EACV,UAAU;EACV,QAAQ;GACN;IACE,KAAK;IACL,OAAO;IACP,aACE;IACF,aAAa;IACb,QAAQ;IACR,SAASD;IACT,gBAAgB;GAClB;GACA;IACE,KAAK;IACL,OAAO;IACP,aACE;IACF,aAAa;IACb,QAAQ;GACV;GACA;IACE,KAAK;IACL,OAAO;IACP,aACE;IACF,aAAa;IACb,QAAQ;IACR,SAASA;IACT,gBAAgB;GAClB;EACF;EACA,aACE;EACF,gBAAgB;CAClB;CACA,UAAU;EACR,UAAU;EACV,UAAU;EACV,QAAQ;GACN;IACE,KAAK;IACL,OAAO;IACP,aACE;IACF,aAAa;IACb,QAAQ;IACR,SAAS;IACT,gBAAgB;GAClB;GACA;IACE,KAAK;IACL,OAAO;IACP,aACE;IACF,aAAa;IACb,QAAQ;GACV;GACA;IACE,KAAK;IACL,OAAO;IACP,aAAa;IACb,aAAa;IACb,QAAQ;GACV;GACA;IACE,KAAK;IACL,OAAO;IACP,aACE;IACF,aAAa;IACb,QAAQ;IACR,aAAa;GACf;EACF;EACA,aACE;EACF,gBAAgB;CAClB;CACA,SAAS;EACP,UAAU;EACV,UAAU;EACV,QAAQ,CACN;GACE,KAAK;GACL,OAAO;GACP,aACE;GACF,aAAa;GACb,QAAQ;EACV,GACA;GACE,KAAK;GACL,OAAO;GACP,aACE;GACF,aAAa;GACb,QAAQ;GACR,SAAS;GACT,gBAAgB;EAClB,CACF;EACA,aACE;EACF,gBAAgB;CAClB;CACA,SAAS;EACP,UAAU;EACV,UAAU;EACV,QAAQ,CACN;GACE,KA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ACvC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BotmanorHandoffFallbackBehavior, BotmanorHandoffStatus, BotmanorHandoffTrigger, BotmanorHandoffConfigInput } from '../../generated/wspace-types';
|
|
1
|
+
import { BotmanorHandoffMessageRole, BotmanorHandoffFallbackBehavior, BotmanorHandoffStatus, BotmanorHandoffTrigger, BotmanorHandoffConfigInput } from '../../generated/wspace-types';
|
|
2
2
|
import { MutationState, QueryResult } from './internal/workspaceGateway';
|
|
3
3
|
export interface HandoffCustomIntentRecord {
|
|
4
4
|
name: string;
|
|
@@ -22,6 +22,8 @@ export interface HandoffConfigRecord {
|
|
|
22
22
|
notifyPush: boolean;
|
|
23
23
|
fallbackBehavior: BotmanorHandoffFallbackBehavior;
|
|
24
24
|
handoffMessage?: string | null;
|
|
25
|
+
/** Minutes to the first human reply (BOFF-15360). */
|
|
26
|
+
slaMinutes: number;
|
|
25
27
|
updatedAt?: string | null;
|
|
26
28
|
}
|
|
27
29
|
export interface HandoffEventRecord {
|
|
@@ -47,6 +49,19 @@ export interface HandoffRecord {
|
|
|
47
49
|
acceptedAt?: string | null;
|
|
48
50
|
resolvedAt?: string | null;
|
|
49
51
|
releasedAt?: string | null;
|
|
52
|
+
/** BOFF-15360 — when the first human reply is due, and whether it came late. */
|
|
53
|
+
slaDueAt?: string | null;
|
|
54
|
+
firstResponseAt?: string | null;
|
|
55
|
+
slaBreached: boolean;
|
|
56
|
+
/** Platform the customer writes from; null for web chat (no operator reply). */
|
|
57
|
+
replyChannel?: string | null;
|
|
58
|
+
}
|
|
59
|
+
export interface HandoffMessageRecord {
|
|
60
|
+
id: string;
|
|
61
|
+
role: BotmanorHandoffMessageRole;
|
|
62
|
+
authorId: string;
|
|
63
|
+
text: string;
|
|
64
|
+
createdAt: string;
|
|
50
65
|
}
|
|
51
66
|
export declare const ACTIVE_HANDOFF_STATUSES: readonly BotmanorHandoffStatus[];
|
|
52
67
|
export declare function isActiveHandoff(status: BotmanorHandoffStatus): boolean;
|
|
@@ -75,4 +90,16 @@ export declare function useAcceptHandoff(): readonly [(id: string) => Promise<Ha
|
|
|
75
90
|
export declare function useReleaseHandoff(): readonly [(id: string) => Promise<HandoffTransitionResult>, MutationState<HandoffTransitionResult>];
|
|
76
91
|
export declare function useResolveHandoff(): readonly [(id: string) => Promise<HandoffTransitionResult>, MutationState<HandoffTransitionResult>];
|
|
77
92
|
export declare function useRejectHandoff(): readonly [(id: string) => Promise<HandoffTransitionResult>, MutationState<HandoffTransitionResult>];
|
|
93
|
+
/** BOFF-15360 — assign a handoff to a workspace member. */
|
|
94
|
+
export declare function useAssignHandoff(): readonly [(input: {
|
|
95
|
+
id: string;
|
|
96
|
+
assigneeId: string;
|
|
97
|
+
}) => Promise<HandoffTransitionResult>, MutationState<HandoffTransitionResult>];
|
|
98
|
+
/** BOFF-15360 — the operator's reply, sent in the customer's own thread. */
|
|
99
|
+
export declare function useReplyToHandoff(): readonly [(input: {
|
|
100
|
+
id: string;
|
|
101
|
+
message: string;
|
|
102
|
+
}) => Promise<HandoffTransitionResult>, MutationState<HandoffTransitionResult>];
|
|
103
|
+
/** BOFF-15360 — the handoff thread, oldest first. */
|
|
104
|
+
export declare function useHandoffTranscript(handoffId: string | undefined): QueryResult<HandoffMessageRecord[]>;
|
|
78
105
|
export {};
|
|
@@ -1,31 +1,39 @@
|
|
|
1
|
-
import { AcceptHandoffDocument as e,
|
|
2
|
-
import { BotmanorHandoffStatus as
|
|
3
|
-
import { useWorkspaceId as
|
|
4
|
-
import { useMemo as
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { AcceptHandoffDocument as e, AssignHandoffDocument as t, HandoffConfigDocument as n, HandoffQueueDocument as r, HandoffTranscriptDocument as i, RejectHandoffDocument as a, ReleaseHandoffDocument as o, ReplyToHandoffDocument as s, ResolveHandoffDocument as c, UpsertHandoffConfigDocument as l } from "../../generated/wspace-operations.js";
|
|
2
|
+
import { BotmanorHandoffStatus as u } from "../../generated/wspace-types.js";
|
|
3
|
+
import { useWorkspaceId as d, useWorkspaceMutation as f, useWorkspaceQuery as p } from "./internal/workspaceGateway.js";
|
|
4
|
+
import { useMemo as m } from "react";
|
|
5
|
+
// src/botlit/hooks/useHandoffs.ts
|
|
6
|
+
var h = [
|
|
7
|
+
u.Requested,
|
|
8
|
+
u.Assigned,
|
|
9
|
+
u.Accepted
|
|
10
|
+
];
|
|
11
|
+
function g(e) {
|
|
12
|
+
return h.includes(e);
|
|
13
|
+
}
|
|
14
|
+
function _(e) {
|
|
15
|
+
let t = d(), r = m(() => ({ agentId: e ?? "" }), [e]);
|
|
16
|
+
return p({
|
|
17
|
+
document: n,
|
|
18
|
+
variables: r,
|
|
11
19
|
select: (e) => e?.handoffConfig ?? null,
|
|
12
20
|
fallback: null,
|
|
13
|
-
enabled: !!(
|
|
21
|
+
enabled: !!(t && e),
|
|
14
22
|
errorMessage: "Failed to load handoff configuration"
|
|
15
23
|
});
|
|
16
24
|
}
|
|
17
|
-
var
|
|
18
|
-
function
|
|
19
|
-
let t =
|
|
20
|
-
...
|
|
25
|
+
var v = 100;
|
|
26
|
+
function y(e) {
|
|
27
|
+
let t = d(), n = e.agentId, i = e.statuses, a = m(() => ({
|
|
28
|
+
...n ? { agentId: n } : {},
|
|
21
29
|
...i && i.length > 0 ? { statuses: i } : {},
|
|
22
30
|
pagination: {
|
|
23
|
-
limit:
|
|
31
|
+
limit: v,
|
|
24
32
|
offset: 0
|
|
25
33
|
}
|
|
26
|
-
}), [
|
|
27
|
-
return
|
|
28
|
-
document:
|
|
34
|
+
}), [n, i]);
|
|
35
|
+
return p({
|
|
36
|
+
document: r,
|
|
29
37
|
variables: a,
|
|
30
38
|
select: (e) => ({
|
|
31
39
|
items: e?.handoffQueue.items ?? [],
|
|
@@ -41,9 +49,9 @@ function m(e) {
|
|
|
41
49
|
errorMessage: "Failed to load the handoff queue"
|
|
42
50
|
});
|
|
43
51
|
}
|
|
44
|
-
function
|
|
45
|
-
let [t, n] =
|
|
46
|
-
document:
|
|
52
|
+
function b(e) {
|
|
53
|
+
let [t, n] = f({
|
|
54
|
+
document: l,
|
|
47
55
|
variables: (t) => ({
|
|
48
56
|
agentId: e,
|
|
49
57
|
input: t
|
|
@@ -53,26 +61,53 @@ function h(e) {
|
|
|
53
61
|
});
|
|
54
62
|
return [t, n];
|
|
55
63
|
}
|
|
56
|
-
function
|
|
57
|
-
return
|
|
64
|
+
function x(e, t, n) {
|
|
65
|
+
return f({
|
|
58
66
|
document: e,
|
|
59
67
|
variables: (e) => ({ id: e }),
|
|
60
68
|
select: t,
|
|
61
69
|
errorMessage: n
|
|
62
70
|
});
|
|
63
71
|
}
|
|
64
|
-
function
|
|
65
|
-
return
|
|
72
|
+
function S() {
|
|
73
|
+
return x(e, (e) => e?.acceptHandoff, "Failed to accept the handoff");
|
|
74
|
+
}
|
|
75
|
+
function C() {
|
|
76
|
+
return x(o, (e) => e?.releaseHandoff, "Failed to release the handoff");
|
|
66
77
|
}
|
|
67
|
-
function
|
|
68
|
-
return
|
|
78
|
+
function w() {
|
|
79
|
+
return x(c, (e) => e?.resolveHandoff, "Failed to resolve the handoff");
|
|
69
80
|
}
|
|
70
|
-
function
|
|
71
|
-
return
|
|
81
|
+
function T() {
|
|
82
|
+
return x(a, (e) => e?.rejectHandoff, "Failed to reject the handoff");
|
|
72
83
|
}
|
|
73
|
-
function
|
|
74
|
-
return
|
|
84
|
+
function E() {
|
|
85
|
+
return f({
|
|
86
|
+
document: t,
|
|
87
|
+
variables: (e) => ({ ...e }),
|
|
88
|
+
select: (e) => e?.assignHandoff,
|
|
89
|
+
errorMessage: "Failed to assign the handoff"
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
function D() {
|
|
93
|
+
return f({
|
|
94
|
+
document: s,
|
|
95
|
+
variables: (e) => ({ ...e }),
|
|
96
|
+
select: (e) => e?.replyToHandoff,
|
|
97
|
+
errorMessage: "Failed to send the reply"
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
function O(e) {
|
|
101
|
+
let t = d(), n = m(() => ({ id: e ?? "" }), [e]);
|
|
102
|
+
return p({
|
|
103
|
+
document: i,
|
|
104
|
+
variables: n,
|
|
105
|
+
select: (e) => e?.handoffTranscript ?? [],
|
|
106
|
+
fallback: [],
|
|
107
|
+
enabled: !!(t && e),
|
|
108
|
+
errorMessage: "Failed to load the conversation"
|
|
109
|
+
});
|
|
75
110
|
}
|
|
76
|
-
export {
|
|
111
|
+
export { h as ACTIVE_HANDOFF_STATUSES, g as isActiveHandoff, S as useAcceptHandoff, E as useAssignHandoff, _ as useHandoffConfig, y as useHandoffQueue, O as useHandoffTranscript, T as useRejectHandoff, C as useReleaseHandoff, D as useReplyToHandoff, w as useResolveHandoff, b as useUpsertHandoffConfig };
|
|
77
112
|
|
|
78
113
|
//# sourceMappingURL=useHandoffs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useHandoffs.js","names":["BotmanorHandoffStatus","useHandoffConfig","workspaceId","useWorkspaceId","useWorkspaceQuery","HandoffConfigDocument","agentId","data","QUEUE_PAGE_LIMIT","useHandoffQueue","options","statuses","variables","useMemo","HandoffQueueDocument","useUpsertHandoffConfig","mutate","state","useWorkspaceMutation","UpsertHandoffConfigDocument","useHandoffTransition","useAcceptHandoff","AcceptHandoffDocument","useReleaseHandoff","ReleaseHandoffDocument","useResolveHandoff","ResolveHandoffDocument","useRejectHandoff","RejectHandoffDocument"],"sources":["../../../src/botlit/hooks/useHandoffs.ts"],"sourcesContent":["/**\n * Handoff hooks (BOFF-5813)\n * @module botlit/hooks\n *\n * Backed by the live `handoffConfig` / `handoffQueue` / `conversationHandoff`\n * queries and the upsert / request / accept / release / resolve / reject\n * mutations on wspace-botmanor-svc.\n */\n\nimport {\n AcceptHandoffDocument,\n ConversationHandoffDocument,\n HandoffConfigDocument,\n HandoffQueueDocument,\n RejectHandoffDocument,\n ReleaseHandoffDocument,\n RequestHandoffDocument,\n ResolveHandoffDocument,\n UpsertHandoffConfigDocument,\n type AcceptHandoffMutation,\n type ConversationHandoffQuery,\n type HandoffConfigQuery,\n type HandoffQueueQuery,\n type RejectHandoffMutation,\n type ReleaseHandoffMutation,\n type RequestHandoffMutation,\n type ResolveHandoffMutation,\n type UpsertHandoffConfigMutation,\n} from '../../generated/wspace-operations';\nimport {\n BotmanorHandoffFallbackBehavior,\n BotmanorHandoffStatus,\n BotmanorHandoffTrigger,\n type BotmanorHandoffConfigInput,\n} from '../../generated/wspace-types';\nimport { useMemo } from 'react';\n\nimport {\n useWorkspaceId,\n useWorkspaceMutation,\n useWorkspaceQuery,\n type MutationState,\n type QueryResult,\n} from './internal/workspaceGateway';\n\nexport interface HandoffCustomIntentRecord {\n name: string;\n pattern: string;\n isRegex: boolean;\n}\n\nexport interface HandoffConfigRecord {\n agentId: string;\n enabled: boolean;\n explicitRequest: boolean;\n lowConfidence: boolean;\n lowConfidenceThreshold: number;\n repeatedFailures: boolean;\n repeatedFailuresConsecutive: number;\n policyRefusal: boolean;\n customIntents: HandoffCustomIntentRecord[];\n targetUserIds: string[];\n targetRole?: string | null;\n notifyInApp: boolean;\n notifyEmail: boolean;\n notifyPush: boolean;\n fallbackBehavior: BotmanorHandoffFallbackBehavior;\n handoffMessage?: string | null;\n updatedAt?: string | null;\n}\n\nexport interface HandoffEventRecord {\n at: string;\n actorId: string;\n from?: BotmanorHandoffStatus | null;\n to: BotmanorHandoffStatus;\n note?: string | null;\n}\n\nexport interface HandoffRecord {\n id: string;\n agentId: string;\n conversationKey: string;\n conversationId?: string | null;\n status: BotmanorHandoffStatus;\n trigger: BotmanorHandoffTrigger;\n reason: string;\n userMessage?: string | null;\n assignedToId?: string | null;\n executionId?: string | null;\n events: HandoffEventRecord[];\n createdAt: string;\n acceptedAt?: string | null;\n resolvedAt?: string | null;\n releasedAt?: string | null;\n}\n\nexport const ACTIVE_HANDOFF_STATUSES: readonly BotmanorHandoffStatus[] = [\n BotmanorHandoffStatus.Requested,\n BotmanorHandoffStatus.Assigned,\n BotmanorHandoffStatus.Accepted,\n];\n\nexport function isActiveHandoff(status: BotmanorHandoffStatus): boolean {\n return ACTIVE_HANDOFF_STATUSES.includes(status);\n}\n\nexport function useHandoffConfig(\n agentId: string | undefined\n): QueryResult<HandoffConfigRecord | null> {\n const workspaceId = useWorkspaceId();\n return useWorkspaceQuery<HandoffConfigQuery, HandoffConfigRecord | null>({\n document: HandoffConfigDocument,\n variables: { agentId: agentId ?? '' },\n select: (data) => data?.handoffConfig ?? null,\n fallback: null,\n enabled: Boolean(workspaceId && agentId),\n errorMessage: 'Failed to load handoff configuration',\n });\n}\n\nexport interface HandoffQueueResult {\n items: HandoffRecord[];\n total: number;\n hasMore: boolean;\n}\n\nconst QUEUE_PAGE_LIMIT = 100;\n\nexport function useHandoffQueue(options: {\n agentId?: string;\n statuses?: BotmanorHandoffStatus[];\n}): QueryResult<HandoffQueueResult> {\n const workspaceId = useWorkspaceId();\n const agentId = options.agentId;\n const statuses = options.statuses;\n // Stable identity — see useHandoffConfig.\n const variables = useMemo(\n () => ({\n ...(agentId ? { agentId } : {}),\n ...(statuses && statuses.length > 0 ? { statuses } : {}),\n pagination: { limit: QUEUE_PAGE_LIMIT, offset: 0 },\n }),\n [agentId, statuses]\n );\n return useWorkspaceQuery<HandoffQueueQuery, HandoffQueueResult>({\n document: HandoffQueueDocument,\n variables,\n select: (data) => ({\n items: data?.handoffQueue.items ?? [],\n total: data?.handoffQueue.total ?? 0,\n hasMore: data?.handoffQueue.hasMore ?? false,\n }),\n fallback: { items: [], total: 0, hasMore: false },\n enabled: Boolean(workspaceId),\n errorMessage: 'Failed to load the handoff queue',\n });\n}\n\nexport function useConversationHandoff(\n agentId: string | undefined,\n conversationKey: string | undefined\n): QueryResult<HandoffRecord | null> {\n const workspaceId = useWorkspaceId();\n // Stable identity — see useHandoffConfig.\n const variables = useMemo(\n () => ({ agentId: agentId ?? '', conversationKey: conversationKey ?? '' }),\n [agentId, conversationKey]\n );\n return useWorkspaceQuery<ConversationHandoffQuery, HandoffRecord | null>({\n document: ConversationHandoffDocument,\n variables,\n select: (data) => data?.conversationHandoff ?? null,\n fallback: null,\n enabled: Boolean(workspaceId && agentId && conversationKey),\n errorMessage: 'Failed to load the conversation handoff',\n });\n}\n\nexport function useUpsertHandoffConfig(agentId: string) {\n const [mutate, state] = useWorkspaceMutation<\n UpsertHandoffConfigMutation,\n BotmanorHandoffConfigInput,\n HandoffConfigRecord\n >({\n document: UpsertHandoffConfigDocument,\n variables: (input) => ({ agentId, input }),\n select: (data) => data?.upsertHandoffConfig,\n errorMessage: 'Failed to save handoff configuration',\n });\n return [mutate, state] as const;\n}\n\nexport function useRequestHandoff() {\n const [mutate, state] = useWorkspaceMutation<\n RequestHandoffMutation,\n { agentId: string; conversationKey: string; reason?: string },\n HandoffRecord\n >({\n document: RequestHandoffDocument,\n variables: (input) => ({ ...input }),\n select: (data) => data?.requestHandoff,\n errorMessage: 'Failed to request a human',\n });\n return [mutate, state] as const;\n}\n\ninterface HandoffTransitionResult {\n id: string;\n status: BotmanorHandoffStatus;\n}\n\nfunction useHandoffTransition<TMutation>(\n document: Parameters<typeof useWorkspaceMutation>[0]['document'],\n select: (data: TMutation | undefined) => HandoffTransitionResult | undefined,\n errorMessage: string\n): readonly [\n (id: string) => Promise<HandoffTransitionResult>,\n MutationState<HandoffTransitionResult>,\n] {\n return useWorkspaceMutation<TMutation, string, HandoffTransitionResult>({\n document,\n variables: (id) => ({ id }),\n select,\n errorMessage,\n });\n}\n\nexport function useAcceptHandoff() {\n return useHandoffTransition<AcceptHandoffMutation>(\n AcceptHandoffDocument,\n (data) => data?.acceptHandoff,\n 'Failed to accept the handoff'\n );\n}\n\nexport function useReleaseHandoff() {\n return useHandoffTransition<ReleaseHandoffMutation>(\n ReleaseHandoffDocument,\n (data) => data?.releaseHandoff,\n 'Failed to release the handoff'\n );\n}\n\nexport function useResolveHandoff() {\n return useHandoffTransition<ResolveHandoffMutation>(\n ResolveHandoffDocument,\n (data) => data?.resolveHandoff,\n 'Failed to resolve the handoff'\n );\n}\n\nexport function useRejectHandoff() {\n return useHandoffTransition<RejectHandoffMutation>(\n RejectHandoffDocument,\n (data) => data?.rejectHandoff,\n 'Failed to reject the handoff'\n );\n}\n"],"mappings":";;;;AAkGEA,EAAsB,WACtBA,EAAsB,UACtBA,EAAsB;AAOxB,SAAgBC,EACd,GACyC;CACzC,IAAMC,IAAcC,EAAe;CACnC,OAAOC,EAAkE;EACvE,UAAUC;EACV,WAAW,EAAE,SAASC,KAAW,GAAG;EACpC,SAAS,MAASC,GAAM,iBAAiB;EACzC,UAAU;EACV,SAAS,GAAQL,KAAeI;EAChC,cAAc;CAChB,CAAC;AACH;AAQA,IAAME,IAAmB;AAEzB,SAAgBC,EAAgB,GAGI;CAClC,IAAMP,IAAcC,EAAe,GAC7BG,IAAUI,EAAQ,SAClBC,IAAWD,EAAQ,UAEnBE,IAAYC,SACT;EACL,GAAIP,IAAU,EAAE,WAAQ,IAAI,CAAC;EAC7B,GAAIK,KAAYA,EAAS,SAAS,IAAI,EAAE,YAAS,IAAI,CAAC;EACtD,YAAY;GAAE,OAAOH;GAAkB,QAAQ;EAAE;CACnD,IACA,CAACF,GAASK,CAAQ,CACpB;CACA,OAAOP,EAAyD;EAC9D,UAAUU;EACV;EACA,SAAS,OAAU;GACjB,OAAOP,GAAM,aAAa,SAAS,CAAC;GACpC,OAAOA,GAAM,aAAa,SAAS;GACnC,SAASA,GAAM,aAAa,WAAW;EACzC;EACA,UAAU;GAAE,OAAO,CAAC;GAAG,OAAO;GAAG,SAAS;EAAM;EAChD,SAAS,EAAQL;EACjB,cAAc;CAChB,CAAC;AACH;AAsBA,SAAgBa,EAAuB,GAAiB;CACtD,IAAM,CAACC,GAAQC,KAASC,EAItB;EACA,UAAUC;EACV,YAAY,OAAW;GAAE;GAAS;EAAM;EACxC,SAAS,MAASZ,GAAM;EACxB,cAAc;CAChB,CAAC;CACD,OAAO,CAACS,GAAQC,CAAK;AACvB;AAqBA,SAASG,EACP,GACA,GACA,GAIA;CACA,OAAOF,EAAiE;EACtE;EACA,YAAY,OAAQ,EAAE,MAAG;EACzB;EACA;CACF,CAAC;AACH;AAEA,SAAgBG,IAAmB;CACjC,OAAOD,EACLE,IACC,MAASf,GAAM,eAChB,8BACF;AACF;AAEA,SAAgBgB,IAAoB;CAClC,OAAOH,EACLI,IACC,MAASjB,GAAM,gBAChB,+BACF;AACF;AAEA,SAAgBkB,IAAoB;CAClC,OAAOL,EACLM,IACC,MAASnB,GAAM,gBAChB,+BACF;AACF;AAEA,SAAgBoB,IAAmB;CACjC,OAAOP,EACLQ,IACC,MAASrB,GAAM,eAChB,8BACF;AACF"}
|
|
1
|
+
{"version":3,"file":"useHandoffs.js","names":["ACTIVE_HANDOFF_STATUSES","BotmanorHandoffStatus","isActiveHandoff","status","useHandoffConfig","workspaceId","useWorkspaceId","variables","useMemo","agentId","useWorkspaceQuery","HandoffConfigDocument","data","QUEUE_PAGE_LIMIT","useHandoffQueue","options","statuses","HandoffQueueDocument","useUpsertHandoffConfig","mutate","state","useWorkspaceMutation","UpsertHandoffConfigDocument","useHandoffTransition","useAcceptHandoff","AcceptHandoffDocument","useReleaseHandoff","ReleaseHandoffDocument","useResolveHandoff","ResolveHandoffDocument","useRejectHandoff","RejectHandoffDocument","useAssignHandoff","AssignHandoffDocument","input","useReplyToHandoff","ReplyToHandoffDocument","useHandoffTranscript","handoffId","HandoffTranscriptDocument"],"sources":["../../../src/botlit/hooks/useHandoffs.ts"],"sourcesContent":["/**\n * Handoff hooks (BOFF-5813)\n * @module botlit/hooks\n *\n * Backed by the live `handoffConfig` / `handoffQueue` / `conversationHandoff`\n * / `handoffTranscript` queries and the upsert / request / accept / assign /\n * reply / release / resolve / reject mutations on wspace-botmanor-svc.\n */\n\nimport {\n AcceptHandoffDocument,\n AssignHandoffDocument,\n HandoffTranscriptDocument,\n ReplyToHandoffDocument,\n type AssignHandoffMutation,\n type HandoffTranscriptQuery,\n type ReplyToHandoffMutation,\n ConversationHandoffDocument,\n HandoffConfigDocument,\n HandoffQueueDocument,\n RejectHandoffDocument,\n ReleaseHandoffDocument,\n RequestHandoffDocument,\n ResolveHandoffDocument,\n UpsertHandoffConfigDocument,\n type AcceptHandoffMutation,\n type ConversationHandoffQuery,\n type HandoffConfigQuery,\n type HandoffQueueQuery,\n type RejectHandoffMutation,\n type ReleaseHandoffMutation,\n type RequestHandoffMutation,\n type ResolveHandoffMutation,\n type UpsertHandoffConfigMutation,\n} from '../../generated/wspace-operations';\nimport {\n BotmanorHandoffMessageRole,\n BotmanorHandoffFallbackBehavior,\n BotmanorHandoffStatus,\n BotmanorHandoffTrigger,\n type BotmanorHandoffConfigInput,\n} from '../../generated/wspace-types';\nimport { useMemo } from 'react';\n\nimport {\n useWorkspaceId,\n useWorkspaceMutation,\n useWorkspaceQuery,\n type MutationState,\n type QueryResult,\n} from './internal/workspaceGateway';\n\nexport interface HandoffCustomIntentRecord {\n name: string;\n pattern: string;\n isRegex: boolean;\n}\n\nexport interface HandoffConfigRecord {\n agentId: string;\n enabled: boolean;\n explicitRequest: boolean;\n lowConfidence: boolean;\n lowConfidenceThreshold: number;\n repeatedFailures: boolean;\n repeatedFailuresConsecutive: number;\n policyRefusal: boolean;\n customIntents: HandoffCustomIntentRecord[];\n targetUserIds: string[];\n targetRole?: string | null;\n notifyInApp: boolean;\n notifyEmail: boolean;\n notifyPush: boolean;\n fallbackBehavior: BotmanorHandoffFallbackBehavior;\n handoffMessage?: string | null;\n /** Minutes to the first human reply (BOFF-15360). */\n slaMinutes: number;\n updatedAt?: string | null;\n}\n\nexport interface HandoffEventRecord {\n at: string;\n actorId: string;\n from?: BotmanorHandoffStatus | null;\n to: BotmanorHandoffStatus;\n note?: string | null;\n}\n\nexport interface HandoffRecord {\n id: string;\n agentId: string;\n conversationKey: string;\n conversationId?: string | null;\n status: BotmanorHandoffStatus;\n trigger: BotmanorHandoffTrigger;\n reason: string;\n userMessage?: string | null;\n assignedToId?: string | null;\n executionId?: string | null;\n events: HandoffEventRecord[];\n createdAt: string;\n acceptedAt?: string | null;\n resolvedAt?: string | null;\n releasedAt?: string | null;\n /** BOFF-15360 — when the first human reply is due, and whether it came late. */\n slaDueAt?: string | null;\n firstResponseAt?: string | null;\n slaBreached: boolean;\n /** Platform the customer writes from; null for web chat (no operator reply). */\n replyChannel?: string | null;\n}\n\nexport interface HandoffMessageRecord {\n id: string;\n role: BotmanorHandoffMessageRole;\n authorId: string;\n text: string;\n createdAt: string;\n}\n\nexport const ACTIVE_HANDOFF_STATUSES: readonly BotmanorHandoffStatus[] = [\n BotmanorHandoffStatus.Requested,\n BotmanorHandoffStatus.Assigned,\n BotmanorHandoffStatus.Accepted,\n];\n\nexport function isActiveHandoff(status: BotmanorHandoffStatus): boolean {\n return ACTIVE_HANDOFF_STATUSES.includes(status);\n}\n\nexport function useHandoffConfig(\n agentId: string | undefined\n): QueryResult<HandoffConfigRecord | null> {\n const workspaceId = useWorkspaceId();\n // Stable identity: useWorkspaceQuery refetches whenever `variables` changes,\n // so an inline object re-requested the config on every render (BOFF-15360).\n const variables = useMemo(() => ({ agentId: agentId ?? '' }), [agentId]);\n return useWorkspaceQuery<HandoffConfigQuery, HandoffConfigRecord | null>({\n document: HandoffConfigDocument,\n variables,\n select: (data) => data?.handoffConfig ?? null,\n fallback: null,\n enabled: Boolean(workspaceId && agentId),\n errorMessage: 'Failed to load handoff configuration',\n });\n}\n\nexport interface HandoffQueueResult {\n items: HandoffRecord[];\n total: number;\n hasMore: boolean;\n}\n\nconst QUEUE_PAGE_LIMIT = 100;\n\nexport function useHandoffQueue(options: {\n agentId?: string;\n statuses?: BotmanorHandoffStatus[];\n}): QueryResult<HandoffQueueResult> {\n const workspaceId = useWorkspaceId();\n const agentId = options.agentId;\n const statuses = options.statuses;\n // Stable identity — see useHandoffConfig.\n const variables = useMemo(\n () => ({\n ...(agentId ? { agentId } : {}),\n ...(statuses && statuses.length > 0 ? { statuses } : {}),\n pagination: { limit: QUEUE_PAGE_LIMIT, offset: 0 },\n }),\n [agentId, statuses]\n );\n return useWorkspaceQuery<HandoffQueueQuery, HandoffQueueResult>({\n document: HandoffQueueDocument,\n variables,\n select: (data) => ({\n items: data?.handoffQueue.items ?? [],\n total: data?.handoffQueue.total ?? 0,\n hasMore: data?.handoffQueue.hasMore ?? false,\n }),\n fallback: { items: [], total: 0, hasMore: false },\n enabled: Boolean(workspaceId),\n errorMessage: 'Failed to load the handoff queue',\n });\n}\n\nexport function useConversationHandoff(\n agentId: string | undefined,\n conversationKey: string | undefined\n): QueryResult<HandoffRecord | null> {\n const workspaceId = useWorkspaceId();\n // Stable identity — see useHandoffConfig.\n const variables = useMemo(\n () => ({ agentId: agentId ?? '', conversationKey: conversationKey ?? '' }),\n [agentId, conversationKey]\n );\n return useWorkspaceQuery<ConversationHandoffQuery, HandoffRecord | null>({\n document: ConversationHandoffDocument,\n variables,\n select: (data) => data?.conversationHandoff ?? null,\n fallback: null,\n enabled: Boolean(workspaceId && agentId && conversationKey),\n errorMessage: 'Failed to load the conversation handoff',\n });\n}\n\nexport function useUpsertHandoffConfig(agentId: string) {\n const [mutate, state] = useWorkspaceMutation<\n UpsertHandoffConfigMutation,\n BotmanorHandoffConfigInput,\n HandoffConfigRecord\n >({\n document: UpsertHandoffConfigDocument,\n variables: (input) => ({ agentId, input }),\n select: (data) => data?.upsertHandoffConfig,\n errorMessage: 'Failed to save handoff configuration',\n });\n return [mutate, state] as const;\n}\n\nexport function useRequestHandoff() {\n const [mutate, state] = useWorkspaceMutation<\n RequestHandoffMutation,\n { agentId: string; conversationKey: string; reason?: string },\n HandoffRecord\n >({\n document: RequestHandoffDocument,\n variables: (input) => ({ ...input }),\n select: (data) => data?.requestHandoff,\n errorMessage: 'Failed to request a human',\n });\n return [mutate, state] as const;\n}\n\ninterface HandoffTransitionResult {\n id: string;\n status: BotmanorHandoffStatus;\n}\n\nfunction useHandoffTransition<TMutation>(\n document: Parameters<typeof useWorkspaceMutation>[0]['document'],\n select: (data: TMutation | undefined) => HandoffTransitionResult | undefined,\n errorMessage: string\n): readonly [\n (id: string) => Promise<HandoffTransitionResult>,\n MutationState<HandoffTransitionResult>,\n] {\n return useWorkspaceMutation<TMutation, string, HandoffTransitionResult>({\n document,\n variables: (id) => ({ id }),\n select,\n errorMessage,\n });\n}\n\nexport function useAcceptHandoff() {\n return useHandoffTransition<AcceptHandoffMutation>(\n AcceptHandoffDocument,\n (data) => data?.acceptHandoff,\n 'Failed to accept the handoff'\n );\n}\n\nexport function useReleaseHandoff() {\n return useHandoffTransition<ReleaseHandoffMutation>(\n ReleaseHandoffDocument,\n (data) => data?.releaseHandoff,\n 'Failed to release the handoff'\n );\n}\n\nexport function useResolveHandoff() {\n return useHandoffTransition<ResolveHandoffMutation>(\n ResolveHandoffDocument,\n (data) => data?.resolveHandoff,\n 'Failed to resolve the handoff'\n );\n}\n\nexport function useRejectHandoff() {\n return useHandoffTransition<RejectHandoffMutation>(\n RejectHandoffDocument,\n (data) => data?.rejectHandoff,\n 'Failed to reject the handoff'\n );\n}\n\n/** BOFF-15360 — assign a handoff to a workspace member. */\nexport function useAssignHandoff() {\n return useWorkspaceMutation<\n AssignHandoffMutation,\n { id: string; assigneeId: string },\n HandoffTransitionResult\n >({\n document: AssignHandoffDocument,\n variables: (input) => ({ ...input }),\n select: (data) => data?.assignHandoff,\n errorMessage: 'Failed to assign the handoff',\n });\n}\n\n/** BOFF-15360 — the operator's reply, sent in the customer's own thread. */\nexport function useReplyToHandoff() {\n return useWorkspaceMutation<\n ReplyToHandoffMutation,\n { id: string; message: string },\n HandoffTransitionResult\n >({\n document: ReplyToHandoffDocument,\n variables: (input) => ({ ...input }),\n select: (data) => data?.replyToHandoff,\n errorMessage: 'Failed to send the reply',\n });\n}\n\n/** BOFF-15360 — the handoff thread, oldest first. */\nexport function useHandoffTranscript(\n handoffId: string | undefined\n): QueryResult<HandoffMessageRecord[]> {\n const workspaceId = useWorkspaceId();\n const variables = useMemo(() => ({ id: handoffId ?? '' }), [handoffId]);\n return useWorkspaceQuery<HandoffTranscriptQuery, HandoffMessageRecord[]>({\n document: HandoffTranscriptDocument,\n variables,\n select: (data) => data?.handoffTranscript ?? [],\n fallback: [],\n enabled: Boolean(workspaceId && handoffId),\n errorMessage: 'Failed to load the conversation',\n });\n}\n"],"mappings":";;;;;AAwHA,IAAaA,IAA4D;CACvEC,EAAsB;CACtBA,EAAsB;CACtBA,EAAsB;AACxB;AAEA,SAAgBC,EAAgB,GAAwC;CACtE,OAAOF,EAAwB,SAASG,CAAM;AAChD;AAEA,SAAgBC,EACd,GACyC;CACzC,IAAMC,IAAcC,EAAe,GAG7BC,IAAYC,SAAe,EAAE,SAASC,KAAW,GAAG,IAAI,CAACA,CAAO,CAAC;CACvE,OAAOC,EAAkE;EACvE,UAAUC;EACV;EACA,SAAS,MAASC,GAAM,iBAAiB;EACzC,UAAU;EACV,SAAS,GAAQP,KAAeI;EAChC,cAAc;CAChB,CAAC;AACH;AAQA,IAAMI,IAAmB;AAEzB,SAAgBC,EAAgB,GAGI;CAClC,IAAMT,IAAcC,EAAe,GAC7BG,IAAUM,EAAQ,SAClBC,IAAWD,EAAQ,UAEnBR,IAAYC,SACT;EACL,GAAIC,IAAU,EAAE,WAAQ,IAAI,CAAC;EAC7B,GAAIO,KAAYA,EAAS,SAAS,IAAI,EAAE,YAAS,IAAI,CAAC;EACtD,YAAY;GAAE,OAAOH;GAAkB,QAAQ;EAAE;CACnD,IACA,CAACJ,GAASO,CAAQ,CACpB;CACA,OAAON,EAAyD;EAC9D,UAAUO;EACV;EACA,SAAS,OAAU;GACjB,OAAOL,GAAM,aAAa,SAAS,CAAC;GACpC,OAAOA,GAAM,aAAa,SAAS;GACnC,SAASA,GAAM,aAAa,WAAW;EACzC;EACA,UAAU;GAAE,OAAO,CAAC;GAAG,OAAO;GAAG,SAAS;EAAM;EAChD,SAAS,EAAQP;EACjB,cAAc;CAChB,CAAC;AACH;AAsBA,SAAgBa,EAAuB,GAAiB;CACtD,IAAM,CAACC,GAAQC,KAASC,EAItB;EACA,UAAUC;EACV,YAAY,OAAW;GAAE;GAAS;EAAM;EACxC,SAAS,MAASV,GAAM;EACxB,cAAc;CAChB,CAAC;CACD,OAAO,CAACO,GAAQC,CAAK;AACvB;AAqBA,SAASG,EACP,GACA,GACA,GAIA;CACA,OAAOF,EAAiE;EACtE;EACA,YAAY,OAAQ,EAAE,MAAG;EACzB;EACA;CACF,CAAC;AACH;AAEA,SAAgBG,IAAmB;CACjC,OAAOD,EACLE,IACC,MAASb,GAAM,eAChB,8BACF;AACF;AAEA,SAAgBc,IAAoB;CAClC,OAAOH,EACLI,IACC,MAASf,GAAM,gBAChB,+BACF;AACF;AAEA,SAAgBgB,IAAoB;CAClC,OAAOL,EACLM,IACC,MAASjB,GAAM,gBAChB,+BACF;AACF;AAEA,SAAgBkB,IAAmB;CACjC,OAAOP,EACLQ,IACC,MAASnB,GAAM,eAChB,8BACF;AACF;AAGA,SAAgBoB,IAAmB;CACjC,OAAOX,EAIL;EACA,UAAUY;EACV,YAAY,OAAW,EAAE,GAAGC,EAAM;EAClC,SAAS,MAAStB,GAAM;EACxB,cAAc;CAChB,CAAC;AACH;AAGA,SAAgBuB,IAAoB;CAClC,OAAOd,EAIL;EACA,UAAUe;EACV,YAAY,OAAW,EAAE,GAAGF,EAAM;EAClC,SAAS,MAAStB,GAAM;EACxB,cAAc;CAChB,CAAC;AACH;AAGA,SAAgByB,EACd,GACqC;CACrC,IAAMhC,IAAcC,EAAe,GAC7BC,IAAYC,SAAe,EAAE,IAAI8B,KAAa,GAAG,IAAI,CAACA,CAAS,CAAC;CACtE,OAAO5B,EAAkE;EACvE,UAAU6B;EACV;EACA,SAAS,MAAS3B,GAAM,qBAAqB,CAAC;EAC9C,UAAU,CAAC;EACX,SAAS,GAAQP,KAAeiC;EAChC,cAAc;CAChB,CAAC;AACH"}
|
|
@@ -609,6 +609,7 @@ var pe = ({ routeId: e, connectorId: t, channelId: n, platform: r, onRemoved: o,
|
|
|
609
609
|
connectorActive: j,
|
|
610
610
|
workspaceId: g,
|
|
611
611
|
hint: S[o.type]?.inboundHint,
|
|
612
|
+
usesInboundUrl: S[o.type]?.usesInboundUrl ?? !0,
|
|
612
613
|
onRefresh: () => void I()
|
|
613
614
|
}),
|
|
614
615
|
/* @__PURE__ */ B(s, {
|