@burdenoff/microfe-botmanor 2026.1118.5 → 2026.1118.6
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 +21 -0
- package/dist/botlit/components/ChannelSetupPanels.js +139 -0
- package/dist/botlit/components/ChannelSetupPanels.js.map +1 -0
- package/dist/botlit/hooks/index.d.ts +3 -1
- package/dist/botlit/hooks/index.js +13 -12
- package/dist/botlit/hooks/useChannelSetup.d.ts +96 -0
- package/dist/botlit/hooks/useChannelSetup.js +199 -0
- package/dist/botlit/hooks/useChannelSetup.js.map +1 -0
- package/dist/botlit/hooks/useChannels.d.ts +6 -0
- package/dist/botlit/hooks/useChannels.js +80 -58
- package/dist/botlit/hooks/useChannels.js.map +1 -1
- package/dist/botlit/hooks/useUserPlatformConnection.d.ts +1 -0
- package/dist/botlit/hooks/useUserPlatformConnection.js +1 -0
- package/dist/botlit/hooks/useUserPlatformConnection.js.map +1 -1
- package/dist/botlit/pages/BotChannelsTab.js +204 -186
- package/dist/botlit/pages/BotChannelsTab.js.map +1 -1
- package/dist/botlit/pages/ChannelDetailPage.js +658 -526
- package/dist/botlit/pages/ChannelDetailPage.js.map +1 -1
- package/dist/botlit/pages/ChannelsPage.js +2 -1
- package/dist/botlit/pages/ChannelsPage.js.map +1 -1
- package/dist/botlit/providers/BotlitProvider.js +39 -35
- package/dist/botlit/providers/BotlitProvider.js.map +1 -1
- package/dist/botlit/types/index.d.ts +2 -0
- package/dist/botlit/utils/channelConnectors.d.ts +16 -0
- package/dist/botlit/utils/channelConnectors.js +24 -0
- package/dist/botlit/utils/channelConnectors.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { InboundChannelData, PlatformCredentialDefinition } from '../hooks/useChannelSetup';
|
|
3
|
+
interface ChannelCredentialFieldsProps {
|
|
4
|
+
definition: PlatformCredentialDefinition;
|
|
5
|
+
values: Record<string, string>;
|
|
6
|
+
onChange: (values: Record<string, string>) => void;
|
|
7
|
+
}
|
|
8
|
+
export declare const ChannelCredentialFields: FC<ChannelCredentialFieldsProps>;
|
|
9
|
+
interface InboundWebhookCardProps {
|
|
10
|
+
channel: InboundChannelData | null;
|
|
11
|
+
loading: boolean;
|
|
12
|
+
error: Error | undefined;
|
|
13
|
+
/** Is the connector ACTIVE? Only an ACTIVE connector binds the channel. */
|
|
14
|
+
connectorActive: boolean;
|
|
15
|
+
workspaceId: string | undefined;
|
|
16
|
+
/** Platform-specific instructions for where the URL goes. */
|
|
17
|
+
hint?: string;
|
|
18
|
+
onRefresh: () => void;
|
|
19
|
+
}
|
|
20
|
+
export declare const InboundWebhookCard: FC<InboundWebhookCardProps>;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { Card as e, CardContent as t, CardDescription as n, CardHeader as r, CardTitle as i } from "./Card.js";
|
|
2
|
+
import { Button as a } from "./Button.js";
|
|
3
|
+
import { Badge as o } from "./Badge.js";
|
|
4
|
+
import { FormField as s, Input as c } from "./Input.js";
|
|
5
|
+
import { isNative as l, nativeCopyText as u, nativeToast as d } from "../../utils/nativeBridge.js";
|
|
6
|
+
import { generateSigningSecret as f } from "../hooks/useChannelSetup.js";
|
|
7
|
+
import { jsx as p, jsxs as m } from "react/jsx-runtime";
|
|
8
|
+
import { Copy as h, KeyRound as g, Link2 as _, Loader2 as v, RefreshCw as y } from "lucide-react";
|
|
9
|
+
import { toast as b } from "sonner";
|
|
10
|
+
// src/botlit/components/ChannelSetupPanels.tsx
|
|
11
|
+
var x = ({ definition: e, values: t, onChange: n }) => /* @__PURE__ */ m("div", {
|
|
12
|
+
className: "space-y-4",
|
|
13
|
+
children: [e.fields.map((e) => /* @__PURE__ */ p(s, {
|
|
14
|
+
label: e.label,
|
|
15
|
+
description: e.description,
|
|
16
|
+
required: !0,
|
|
17
|
+
children: /* @__PURE__ */ m("div", {
|
|
18
|
+
className: "flex gap-2",
|
|
19
|
+
children: [
|
|
20
|
+
/* @__PURE__ */ p(c, {
|
|
21
|
+
"aria-label": e.label,
|
|
22
|
+
type: e.secret ? "password" : e.url ? "url" : "text",
|
|
23
|
+
autoComplete: "off",
|
|
24
|
+
placeholder: e.placeholder,
|
|
25
|
+
value: t[e.key] ?? "",
|
|
26
|
+
onChange: (r) => n({
|
|
27
|
+
...t,
|
|
28
|
+
[e.key]: r.target.value
|
|
29
|
+
})
|
|
30
|
+
}),
|
|
31
|
+
e.generatable && /* @__PURE__ */ p(a, {
|
|
32
|
+
type: "button",
|
|
33
|
+
variant: "outline",
|
|
34
|
+
leftIcon: /* @__PURE__ */ p(y, { size: 14 }),
|
|
35
|
+
onClick: () => n({
|
|
36
|
+
...t,
|
|
37
|
+
[e.key]: f()
|
|
38
|
+
}),
|
|
39
|
+
children: "Generate"
|
|
40
|
+
}),
|
|
41
|
+
e.generatable && t[e.key] && /* @__PURE__ */ p(a, {
|
|
42
|
+
type: "button",
|
|
43
|
+
variant: "outline",
|
|
44
|
+
size: "icon",
|
|
45
|
+
"aria-label": `Copy ${e.label}`,
|
|
46
|
+
title: `Copy ${e.label}`,
|
|
47
|
+
onClick: () => void S(t[e.key] ?? "", e.label),
|
|
48
|
+
children: /* @__PURE__ */ p(h, { size: 14 })
|
|
49
|
+
})
|
|
50
|
+
]
|
|
51
|
+
})
|
|
52
|
+
}, e.key)), /* @__PURE__ */ m("p", {
|
|
53
|
+
className: "flex items-start gap-2 text-xs text-text-secondary",
|
|
54
|
+
children: [/* @__PURE__ */ p(g, {
|
|
55
|
+
size: 14,
|
|
56
|
+
className: "mt-0.5 shrink-0"
|
|
57
|
+
}), "Credentials are stored encrypted on the channel and are never shown again. Copy a generated secret now if your sender needs it."]
|
|
58
|
+
})]
|
|
59
|
+
});
|
|
60
|
+
async function S(e, t) {
|
|
61
|
+
await u(e) ? (b.success(`${t} copied`), l() && d("Copied")) : b.error(`Could not copy the ${t.toLowerCase()}`);
|
|
62
|
+
}
|
|
63
|
+
var C = ({ channel: s, loading: l, error: u, connectorActive: d, workspaceId: f, hint: g, onRefresh: b }) => {
|
|
64
|
+
let x = !!(s && f && s.inboundWorkspaceId === f), C;
|
|
65
|
+
if (l && !s) C = /* @__PURE__ */ m("div", {
|
|
66
|
+
className: "flex items-center gap-2 py-2 text-sm text-text-secondary",
|
|
67
|
+
children: [/* @__PURE__ */ p(v, {
|
|
68
|
+
size: 14,
|
|
69
|
+
className: "animate-spin"
|
|
70
|
+
}), "Loading the channel…"]
|
|
71
|
+
});
|
|
72
|
+
else if (u) C = /* @__PURE__ */ p("p", {
|
|
73
|
+
className: "text-sm text-status-error-text",
|
|
74
|
+
children: u.message
|
|
75
|
+
});
|
|
76
|
+
else if (!s) C = /* @__PURE__ */ p("p", {
|
|
77
|
+
className: "text-sm text-text-secondary",
|
|
78
|
+
children: "The linked channel was not found. Edit the connector or create a new one with credentials."
|
|
79
|
+
});
|
|
80
|
+
else if (!d) C = /* @__PURE__ */ p("p", {
|
|
81
|
+
className: "text-sm text-text-secondary",
|
|
82
|
+
children: "Activate this connector to bind the channel to this workspace. The platform can only deliver messages to an active connector."
|
|
83
|
+
});
|
|
84
|
+
else if (!x) C = /* @__PURE__ */ p("p", {
|
|
85
|
+
className: "text-sm text-text-secondary",
|
|
86
|
+
children: "The channel is not bound to this workspace yet. Refresh in a moment; if it stays unbound, deactivate and activate the connector again."
|
|
87
|
+
});
|
|
88
|
+
else if (!s.inboundWebhookUrl) C = /* @__PURE__ */ p("p", {
|
|
89
|
+
className: "text-sm text-text-secondary",
|
|
90
|
+
children: "The channel is bound, but the platform does not publish an inbound webhook URL in this environment yet."
|
|
91
|
+
});
|
|
92
|
+
else {
|
|
93
|
+
let e = s.inboundWebhookUrl;
|
|
94
|
+
C = /* @__PURE__ */ m("div", {
|
|
95
|
+
className: "space-y-3",
|
|
96
|
+
children: [/* @__PURE__ */ m("div", {
|
|
97
|
+
className: "flex gap-2",
|
|
98
|
+
children: [/* @__PURE__ */ p(c, {
|
|
99
|
+
"aria-label": "Inbound webhook URL",
|
|
100
|
+
value: e,
|
|
101
|
+
readOnly: !0,
|
|
102
|
+
className: "font-mono text-xs",
|
|
103
|
+
onFocus: (e) => e.currentTarget.select()
|
|
104
|
+
}), /* @__PURE__ */ p(a, {
|
|
105
|
+
variant: "outline",
|
|
106
|
+
leftIcon: /* @__PURE__ */ p(h, { size: 14 }),
|
|
107
|
+
onClick: () => void S(e, "Webhook URL"),
|
|
108
|
+
children: "Copy"
|
|
109
|
+
})]
|
|
110
|
+
}), g && /* @__PURE__ */ p("p", {
|
|
111
|
+
className: "text-sm text-text-secondary",
|
|
112
|
+
children: g
|
|
113
|
+
})]
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
return /* @__PURE__ */ m(e, { children: [/* @__PURE__ */ m(r, {
|
|
117
|
+
className: "flex flex-row items-start justify-between",
|
|
118
|
+
children: [/* @__PURE__ */ m("div", { children: [/* @__PURE__ */ m(i, {
|
|
119
|
+
className: "flex items-center gap-2",
|
|
120
|
+
children: [/* @__PURE__ */ p(_, { size: 18 }), "Inbound Webhook"]
|
|
121
|
+
}), /* @__PURE__ */ p(n, { children: "The platform sends incoming messages for this channel to this URL" })] }), /* @__PURE__ */ m("div", {
|
|
122
|
+
className: "flex items-center gap-2",
|
|
123
|
+
children: [s && /* @__PURE__ */ p(o, {
|
|
124
|
+
variant: x ? "success" : "outline",
|
|
125
|
+
children: x ? "Bound to this workspace" : "Not bound"
|
|
126
|
+
}), /* @__PURE__ */ p(a, {
|
|
127
|
+
variant: "ghost",
|
|
128
|
+
size: "icon",
|
|
129
|
+
"aria-label": "Refresh the channel",
|
|
130
|
+
title: "Refresh",
|
|
131
|
+
onClick: b,
|
|
132
|
+
children: /* @__PURE__ */ p(y, { size: 14 })
|
|
133
|
+
})]
|
|
134
|
+
})]
|
|
135
|
+
}), /* @__PURE__ */ p(t, { children: C })] });
|
|
136
|
+
};
|
|
137
|
+
export { x as ChannelCredentialFields, C as InboundWebhookCard };
|
|
138
|
+
|
|
139
|
+
//# sourceMappingURL=ChannelSetupPanels.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChannelSetupPanels.js","names":["ChannelCredentialFields","definition","FormField","field","Input","values","onChange","event","Button","RefreshCw","generateSigningSecret","copyToClipboard","Copy","KeyRound","nativeCopyText","value","toast","label","isNative","nativeToast","InboundWebhookCard","boundHere","channel","workspaceId","body","loading","Loader2","error","connectorActive","url","hint","Card","CardHeader","CardTitle","Link2","CardDescription","Badge","onRefresh","CardContent"],"sources":["../../../src/botlit/components/ChannelSetupPanels.tsx"],"sourcesContent":["/**\n * Channel setup panels (BOFF-15360)\n * @module botlit/components\n *\n * - `ChannelCredentialFields`: the platform credentials a new connector's\n * global channel is created with (Slack bot token + signing secret, a\n * webhook's reply URL + signing secret).\n * - `InboundWebhookCard`: the public URL the platform must call with inbound\n * events (`Channel.inboundWebhookUrl`), with a copy button and the\n * platform-specific instructions.\n */\n\nimport type { FC } from 'react';\nimport { Copy, KeyRound, Link2, Loader2, RefreshCw } from 'lucide-react';\nimport { toast } from 'sonner';\n\nimport { Card, CardContent, CardDescription, CardHeader, CardTitle } from './Card';\nimport { Button } from './Button';\nimport { Badge } from './Badge';\nimport { Input, FormField } from './Input';\nimport { isNative, nativeCopyText, nativeToast } from '../../utils/nativeBridge';\nimport {\n generateSigningSecret,\n type InboundChannelData,\n type PlatformCredentialDefinition,\n} from '../hooks/useChannelSetup';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// ChannelCredentialFields\n// ─────────────────────────────────────────────────────────────────────────────\n\ninterface ChannelCredentialFieldsProps {\n definition: PlatformCredentialDefinition;\n values: Record<string, string>;\n onChange: (values: Record<string, string>) => void;\n}\n\nexport const ChannelCredentialFields: FC<ChannelCredentialFieldsProps> = ({\n definition,\n values,\n onChange,\n}) => (\n <div className=\"space-y-4\">\n {definition.fields.map((field) => (\n <FormField key={field.key} label={field.label} description={field.description} required>\n <div className=\"flex gap-2\">\n <Input\n aria-label={field.label}\n type={field.secret ? 'password' : field.url ? 'url' : 'text'}\n autoComplete=\"off\"\n placeholder={field.placeholder}\n value={values[field.key] ?? ''}\n onChange={(event) => onChange({ ...values, [field.key]: event.target.value })}\n />\n {field.generatable && (\n <Button\n type=\"button\"\n variant=\"outline\"\n leftIcon={<RefreshCw size={14} />}\n onClick={() => onChange({ ...values, [field.key]: generateSigningSecret() })}\n >\n Generate\n </Button>\n )}\n {field.generatable && values[field.key] && (\n <Button\n type=\"button\"\n variant=\"outline\"\n size=\"icon\"\n aria-label={`Copy ${field.label}`}\n title={`Copy ${field.label}`}\n onClick={() => void copyToClipboard(values[field.key] ?? '', field.label)}\n >\n <Copy size={14} />\n </Button>\n )}\n </div>\n </FormField>\n ))}\n <p className=\"flex items-start gap-2 text-xs text-text-secondary\">\n <KeyRound size={14} className=\"mt-0.5 shrink-0\" />\n Credentials are stored encrypted on the channel and are never shown again. Copy a generated\n secret now if your sender needs it.\n </p>\n </div>\n);\n\nasync function copyToClipboard(value: string, label: string): Promise<void> {\n const copied = await nativeCopyText(value);\n if (copied) {\n toast.success(`${label} copied`);\n if (isNative()) void nativeToast('Copied');\n } else {\n toast.error(`Could not copy the ${label.toLowerCase()}`);\n }\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// InboundWebhookCard\n// ─────────────────────────────────────────────────────────────────────────────\n\ninterface InboundWebhookCardProps {\n channel: InboundChannelData | null;\n loading: boolean;\n error: Error | undefined;\n /** Is the connector ACTIVE? Only an ACTIVE connector binds the channel. */\n connectorActive: boolean;\n workspaceId: string | undefined;\n /** Platform-specific instructions for where the URL goes. */\n hint?: string;\n onRefresh: () => void;\n}\n\nexport const InboundWebhookCard: FC<InboundWebhookCardProps> = ({\n channel,\n loading,\n error,\n connectorActive,\n workspaceId,\n hint,\n onRefresh,\n}) => {\n const boundHere = Boolean(channel && workspaceId && channel.inboundWorkspaceId === workspaceId);\n\n let body;\n if (loading && !channel) {\n body = (\n <div className=\"flex items-center gap-2 py-2 text-sm text-text-secondary\">\n <Loader2 size={14} className=\"animate-spin\" />\n Loading the channel…\n </div>\n );\n } else if (error) {\n body = <p className=\"text-sm text-status-error-text\">{error.message}</p>;\n } else if (!channel) {\n body = (\n <p className=\"text-sm text-text-secondary\">\n The linked channel was not found. Edit the connector or create a new one with credentials.\n </p>\n );\n } else if (!connectorActive) {\n body = (\n <p className=\"text-sm text-text-secondary\">\n Activate this connector to bind the channel to this workspace. The platform can only deliver\n messages to an active connector.\n </p>\n );\n } else if (!boundHere) {\n body = (\n <p className=\"text-sm text-text-secondary\">\n The channel is not bound to this workspace yet. Refresh in a moment; if it stays unbound,\n deactivate and activate the connector again.\n </p>\n );\n } else if (!channel.inboundWebhookUrl) {\n body = (\n <p className=\"text-sm text-text-secondary\">\n The channel is bound, but the platform does not publish an inbound webhook URL in this\n environment yet.\n </p>\n );\n } else {\n const url = channel.inboundWebhookUrl;\n body = (\n <div className=\"space-y-3\">\n <div className=\"flex gap-2\">\n <Input\n aria-label=\"Inbound webhook URL\"\n value={url}\n readOnly\n className=\"font-mono text-xs\"\n onFocus={(event) => event.currentTarget.select()}\n />\n <Button\n variant=\"outline\"\n leftIcon={<Copy size={14} />}\n onClick={() => void copyToClipboard(url, 'Webhook URL')}\n >\n Copy\n </Button>\n </div>\n {hint && <p className=\"text-sm text-text-secondary\">{hint}</p>}\n </div>\n );\n }\n\n return (\n <Card>\n <CardHeader className=\"flex flex-row items-start justify-between\">\n <div>\n <CardTitle className=\"flex items-center gap-2\">\n <Link2 size={18} />\n Inbound Webhook\n </CardTitle>\n <CardDescription>\n The platform sends incoming messages for this channel to this URL\n </CardDescription>\n </div>\n <div className=\"flex items-center gap-2\">\n {channel && (\n <Badge variant={boundHere ? 'success' : 'outline'}>\n {boundHere ? 'Bound to this workspace' : 'Not bound'}\n </Badge>\n )}\n <Button\n variant=\"ghost\"\n size=\"icon\"\n aria-label=\"Refresh the channel\"\n title=\"Refresh\"\n onClick={onRefresh}\n >\n <RefreshCw size={14} />\n </Button>\n </div>\n </CardHeader>\n <CardContent>{body}</CardContent>\n </Card>\n );\n};\n"],"mappings":";;;;;;;;;;AAqCA,IAAaA,KAA6D,EACxE,eACA,WACA,kBAEA,kBAAC,OAAD;CAAK,WAAU;CAAf,UAAA,CACGC,EAAW,OAAO,KAAK,MACtB,kBAACC,GAAD;EAA2B,OAAOC,EAAM;EAAO,aAAaA,EAAM;EAAa,UAAA;EAC7E,UAAA,kBAAC,OAAD;GAAK,WAAU;GAAf,UAAA;IACE,kBAACC,GAAD;KACE,cAAYD,EAAM;KAClB,MAAMA,EAAM,SAAS,aAAaA,EAAM,MAAM,QAAQ;KACtD,cAAa;KACb,aAAaA,EAAM;KACnB,OAAOE,EAAOF,EAAM,QAAQ;KAC5B,WAAW,MAAUG,EAAS;MAAE,GAAGD;OAASF,EAAM,MAAMI,EAAM,OAAO;KAAM,CAAC;IAC7E,CAAA;IACAJ,EAAM,eACL,kBAACK,GAAD;KACE,MAAK;KACL,SAAQ;KACR,UAAU,kBAACC,GAAD,EAAW,MAAM,GAAK,CAAA;KAChC,eAAeH,EAAS;MAAE,GAAGD;OAASF,EAAM,MAAMO,EAAsB;KAAE,CAAC;KAC5E,UAAA;IAEO,CAAA;IAETP,EAAM,eAAeE,EAAOF,EAAM,QACjC,kBAACK,GAAD;KACE,MAAK;KACL,SAAQ;KACR,MAAK;KACL,cAAY,QAAQL,EAAM;KAC1B,OAAO,QAAQA,EAAM;KACrB,eAAe,KAAKQ,EAAgBN,EAAOF,EAAM,QAAQ,IAAIA,EAAM,KAAK;KAExE,UAAA,kBAACS,GAAD,EAAM,MAAM,GAAK,CAAA;IACX,CAAA;GAEP;;CACI,GAjCKT,EAAM,GAiCX,CACZ,GACD,kBAAC,KAAD;EAAG,WAAU;EAAb,UAAA,CACE,kBAACU,GAAD;GAAU,MAAM;GAAI,WAAU;EAAmB,CAAA,GAAC,iIAGjD;CACA,CAAA,CAAA;;AAGP,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Aa;KACvD,UAAA;IAEO,CAAA,CACL;GACJ,CAAA,GAAAC,KAAQ,kBAAC,KAAD;IAAG,WAAU;IAA+B,UAAAA;GAAQ,CAAA,CAC1D;;CAET;CAEA,OACE,kBAACC,GAAD,EAAA,UAAA,CACE,kBAACC,GAAD;EAAY,WAAU;EAAtB,UAAA,CACE,kBAAC,OAAD,EAAA,UAAA,CACE,kBAACC,GAAD;GAAW,WAAU;GAArB,UAAA,CACE,kBAACC,GAAD,EAAO,MAAM,GAAK,CAAA,GAAC,iBAEV;EACX,CAAA,GAAA,kBAACC,GAAD,EAAA,UAAiB,oEAEA,CAAA,CACd,EAAA,CAAA,GACL,kBAAC,OAAD;GAAK,WAAU;GAAf,UAAA,CACGb,KACC,kBAACc,GAAD;IAAO,SAASf,IAAY,YAAY;IACrC,UAAAA,IAAY,4BAA4B;GACpC,CAAA,GAET,kBAACb,GAAD;IACE,SAAQ;IACR,MAAK;IACL,cAAW;IACX,OAAM;IACN,SAAS6B;IAET,UAAA,kBAAC5B,GAAD,EAAW,MAAM,GAAK,CAAA;GAChB,CAAA,CACL;EACK,CAAA,CAAA;CACZ,CAAA,GAAA,kBAAC6B,GAAD,EAAA,UAAcd,EAAkB,CAAA,CAC5B,EAAA,CAAA;AAEV"}
|
|
@@ -12,8 +12,10 @@ export { useMCPServers, useMCPServer, useMCPResources, useMCPTools, useCreateMCP
|
|
|
12
12
|
export type { MCPServerRecord, MCPToolRecord, MCPResourceRecord } from './useMCPServers';
|
|
13
13
|
export { useA2AAgents, useA2AAgent, useRegisterA2AAgent, useUpdateA2AAgent, useDeleteA2AAgent, useValidateA2AAgent, validateAgentCard, a2aAgentSkillCount, a2aKeys, } from './useA2A';
|
|
14
14
|
export type { A2AAgentRecord } from './useA2A';
|
|
15
|
-
export { useChannelConnectors, useChannelConnector, useCreateChannelConnector, useUpdateChannelConnector, useDeleteChannelConnector, useChannelRoutes, useBotChannelRoutes, useChannelRoute, useCreateChannelRoute, useUpdateChannelRoute, useDeleteChannelRoute, routeMetadataString, channelKeys, } from './useChannels';
|
|
15
|
+
export { useChannelConnectors, useChannelConnector, useCreateChannelConnector, useUpdateChannelConnector, useDeleteChannelConnector, useFindChannelConnector, useChannelRoutes, useBotChannelRoutes, useChannelRoute, useCreateChannelRoute, useUpdateChannelRoute, useDeleteChannelRoute, routeMetadataString, channelKeys, } from './useChannels';
|
|
16
16
|
export type { ChannelConnectorRecord, ChannelRouteRecord } from './useChannels';
|
|
17
|
+
export { PLATFORM_CREDENTIALS, connectorPlatform, generateSigningSecret, validateCredentials, useActiveOrganizationId, useInboundChannel, useProvisionChannel, } from './useChannelSetup';
|
|
18
|
+
export type { CredentialFieldDefinition, PlatformCredentialDefinition, InboundChannelData, } from './useChannelSetup';
|
|
17
19
|
export { usePolicies, usePolicy, useCreatePolicy, useUpdatePolicy, useDeletePolicy, usePoliciesByType, policyKeys, } from './usePolicies';
|
|
18
20
|
export type { PolicyRecord } from './usePolicies';
|
|
19
21
|
export { useRetentionStatus, useApplyRetention } from './useRetention';
|
|
@@ -4,16 +4,17 @@ import "./useKnowledgeBases.js";
|
|
|
4
4
|
import { useRetrievalProfiles as n } from "./useRetrievalProfiles.js";
|
|
5
5
|
import { isMCPServerHealthy as r, mcpServerDescription as i, mcpServerEndpoint as a, useCreateMCPServer as o, useDeleteMCPServer as s, useMCPResources as c, useMCPServer as l, useMCPTools as u, useTestMCPConnection as d, useUpdateMCPServer as f, useUpdateMCPTool as p } from "./useMCPServers.js";
|
|
6
6
|
import { a2aAgentSkillCount as m, useA2AAgents as h } from "./useA2A.js";
|
|
7
|
-
import { routeMetadataString as g, useBotChannelRoutes as _, useChannelConnector as v, useChannelConnectors as y, useChannelRoutes as b, useCreateChannelConnector as x, useCreateChannelRoute as S, useDeleteChannelConnector as C, useDeleteChannelRoute as w,
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
7
|
+
import { routeMetadataString as g, useBotChannelRoutes as _, useChannelConnector as v, useChannelConnectors as y, useChannelRoutes as b, useCreateChannelConnector as x, useCreateChannelRoute as S, useDeleteChannelConnector as C, useDeleteChannelRoute as w, useFindChannelConnector as T, useUpdateChannelConnector as E } from "./useChannels.js";
|
|
8
|
+
import { PLATFORM_CREDENTIALS as D, connectorPlatform as O, useActiveOrganizationId as k, useInboundChannel as A, useProvisionChannel as j, validateCredentials as M } from "./useChannelSetup.js";
|
|
9
|
+
import { useCreatePolicy as N, useDeletePolicy as P, usePolicies as F, usePolicy as I, useUpdatePolicy as L } from "./usePolicies.js";
|
|
10
|
+
import { useApplyRetention as R, useRetentionStatus as z } from "./useRetention.js";
|
|
11
|
+
import { useCreateSkill as B, useDeleteSkill as V, useSkill as H, useSkills as U, useUpdateSkill as W } from "./useSkills.js";
|
|
12
|
+
import { promptTemplateVariables as G, useCreatePromptTemplate as K, useDeletePromptTemplate as q, usePromptTemplate as J, usePromptTemplates as Y, useRenderPromptTemplate as X, useUpdatePromptTemplate as Z } from "./usePromptTemplates.js";
|
|
13
|
+
import { summariseExecutions as Q, useExecutions as $ } from "./useExecutions.js";
|
|
14
|
+
import { useBucket as ee, useBucketTree as te, useBuckets as ne, useChildBuckets as re, useCreateBucket as ie, useDeleteBucket as ae, useUpdateBucket as oe } from "./useBuckets.js";
|
|
15
|
+
import { storePackageDescription as se, storePackageName as ce, useInstallPackage as le, useInstalledPackages as ue, usePinPackageVersion as de, useStorePackage as fe, useStorePackages as pe, useUninstallPackage as me, useUpdateInstalledPackage as he } from "./useStore.js";
|
|
15
16
|
import "./useLLMProviders.js";
|
|
16
|
-
import { useInitiateSlackConnect as
|
|
17
|
-
import { useConfigureSupervisor as
|
|
18
|
-
import { useAcceptHandoff as
|
|
19
|
-
export { m as a2aAgentSkillCount, r as isMCPServerHealthy, i as mcpServerDescription, a as mcpServerEndpoint,
|
|
17
|
+
import { useGlobalChannels as ge, useInitiateSlackConnect as _e, useLinkIntegrationConnection as ve, useMyUserPlatformConnection as ye, useRevokeSlackConnection as be, useToggleSlackNotifications as xe } from "./useUserPlatformConnection.js";
|
|
18
|
+
import { useConfigureSupervisor as Se, useRunSupervisorNow as Ce, useSupervisorConfig as we, useSupervisorRuns as Te } from "./useAiOperations.js";
|
|
19
|
+
import { useAcceptHandoff as Ee, useHandoffConfig as De, useHandoffQueue as Oe, useRejectHandoff as ke, useReleaseHandoff as Ae, useResolveHandoff as je, useUpsertHandoffConfig as Me } from "./useHandoffs.js";
|
|
20
|
+
export { D as PLATFORM_CREDENTIALS, m as a2aAgentSkillCount, O as connectorPlatform, r as isMCPServerHealthy, i as mcpServerDescription, a as mcpServerEndpoint, G as promptTemplateVariables, g as routeMetadataString, se as storePackageDescription, ce as storePackageName, Q as summariseExecutions, h as useA2AAgents, Ee as useAcceptHandoff, k as useActiveOrganizationId, t as useAgents, R as useApplyRetention, _ as useBotChannelRoutes, e as useBots, ee as useBucket, te as useBucketTree, ne as useBuckets, v as useChannelConnector, y as useChannelConnectors, b as useChannelRoutes, re as useChildBuckets, Se as useConfigureSupervisor, ie as useCreateBucket, x as useCreateChannelConnector, S as useCreateChannelRoute, o as useCreateMCPServer, N as useCreatePolicy, K as useCreatePromptTemplate, B as useCreateSkill, ae as useDeleteBucket, C as useDeleteChannelConnector, w as useDeleteChannelRoute, s as useDeleteMCPServer, P as useDeletePolicy, q as useDeletePromptTemplate, V as useDeleteSkill, $ as useExecutions, T as useFindChannelConnector, ge as useGlobalChannels, De as useHandoffConfig, Oe as useHandoffQueue, A as useInboundChannel, _e as useInitiateSlackConnect, le as useInstallPackage, ue as useInstalledPackages, ve as useLinkIntegrationConnection, c as useMCPResources, l as useMCPServer, u as useMCPTools, ye as useMyUserPlatformConnection, de as usePinPackageVersion, F as usePolicies, I as usePolicy, J as usePromptTemplate, Y as usePromptTemplates, j as useProvisionChannel, ke as useRejectHandoff, Ae as useReleaseHandoff, X as useRenderPromptTemplate, je as useResolveHandoff, z as useRetentionStatus, n as useRetrievalProfiles, be as useRevokeSlackConnection, Ce as useRunSupervisorNow, H as useSkill, U as useSkills, fe as useStorePackage, pe as useStorePackages, we as useSupervisorConfig, Te as useSupervisorRuns, d as useTestMCPConnection, xe as useToggleSlackNotifications, me as useUninstallPackage, oe as useUpdateBucket, E as useUpdateChannelConnector, he as useUpdateInstalledPackage, f as useUpdateMCPServer, p as useUpdateMCPTool, L as useUpdatePolicy, Z as useUpdatePromptTemplate, W as useUpdateSkill, Me as useUpsertHandoffConfig, M as validateCredentials };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Channel setup hooks (BOFF-15360)
|
|
3
|
+
* @module botlit/hooks
|
|
4
|
+
*
|
|
5
|
+
* A BotManor channel connector names a channel on global-channel-svc through
|
|
6
|
+
* `credentialsRefId`. That global channel holds the platform credentials (a
|
|
7
|
+
* Slack bot token and signing secret, a webhook's signing secret and reply
|
|
8
|
+
* URL, …) and publishes the public URL the platform must call with inbound
|
|
9
|
+
* events (`Channel.inboundWebhookUrl`, set once an ACTIVE connector binds the
|
|
10
|
+
* channel to this workspace).
|
|
11
|
+
*
|
|
12
|
+
* These hooks let the connector form create that channel with its credentials
|
|
13
|
+
* and the detail page show its inbound URL, all through the shell's global
|
|
14
|
+
* gateway client. The documents are written inline, like `GetChannels` in
|
|
15
|
+
* `useUserPlatformConnection`: `inboundWebhookUrl` / `inboundWorkspaceId` are
|
|
16
|
+
* newer than the checked-in `graphql/global.graphql`, which cannot be
|
|
17
|
+
* re-pulled while gateway introspection is disabled.
|
|
18
|
+
*/
|
|
19
|
+
/** Global-channel platforms a connector type delivers through. */
|
|
20
|
+
export type ChannelSetupPlatform = 'SLACK' | 'TEAMS' | 'DISCORD' | 'WHATSAPP' | 'WEBHOOK';
|
|
21
|
+
/** `ChannelAuthType` values the setup form sends. */
|
|
22
|
+
type ChannelSetupAuthType = 'BOT_TOKEN' | 'WEBHOOK';
|
|
23
|
+
export interface CredentialFieldDefinition {
|
|
24
|
+
/** Key stored on the channel connection's credentials. */
|
|
25
|
+
key: string;
|
|
26
|
+
label: string;
|
|
27
|
+
description: string;
|
|
28
|
+
placeholder: string;
|
|
29
|
+
/** Rendered as a password input and never shown again after saving. */
|
|
30
|
+
secret: boolean;
|
|
31
|
+
/** Offer a "Generate" button producing a random 64-hex-character secret. */
|
|
32
|
+
generatable?: boolean;
|
|
33
|
+
/** Must be an absolute https URL. */
|
|
34
|
+
url?: boolean;
|
|
35
|
+
}
|
|
36
|
+
export interface PlatformCredentialDefinition {
|
|
37
|
+
platform: ChannelSetupPlatform;
|
|
38
|
+
authType: ChannelSetupAuthType;
|
|
39
|
+
fields: CredentialFieldDefinition[];
|
|
40
|
+
/** Where to paste the inbound webhook URL on the platform side. */
|
|
41
|
+
inboundHint: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Connector types whose credentials the form can collect directly. The keys
|
|
45
|
+
* are the ones global-channel-svc reads: Slack sends with `botToken` and
|
|
46
|
+
* verifies inbound requests with `signingSecret`; a generic webhook verifies
|
|
47
|
+
* with `webhookSecret` (HMAC-SHA256 hex in `X-Signature`) and POSTs replies
|
|
48
|
+
* to `targetUrl`.
|
|
49
|
+
*/
|
|
50
|
+
export declare const PLATFORM_CREDENTIALS: Readonly<Record<string, PlatformCredentialDefinition>>;
|
|
51
|
+
export declare function connectorPlatform(connectorType: string): ChannelSetupPlatform | undefined;
|
|
52
|
+
/** A random 32-byte secret, hex encoded, from the browser's CSPRNG. */
|
|
53
|
+
export declare function generateSigningSecret(): string;
|
|
54
|
+
/**
|
|
55
|
+
* Returns the first problem with the entered credentials, or null when they
|
|
56
|
+
* are complete. Every field is required.
|
|
57
|
+
*/
|
|
58
|
+
export declare function validateCredentials(definition: PlatformCredentialDefinition, values: Record<string, string>): string | null;
|
|
59
|
+
/**
|
|
60
|
+
* The shell's active organization (the host passes it with the workspace).
|
|
61
|
+
* Global channels belong to an organization, so creating one needs it.
|
|
62
|
+
*/
|
|
63
|
+
export declare function useActiveOrganizationId(): string | null;
|
|
64
|
+
export interface InboundChannelData {
|
|
65
|
+
id: string;
|
|
66
|
+
name: string;
|
|
67
|
+
platform: string;
|
|
68
|
+
status: string;
|
|
69
|
+
isConnected: boolean;
|
|
70
|
+
inboundWorkspaceId: string | null;
|
|
71
|
+
inboundWebhookUrl: string | null;
|
|
72
|
+
}
|
|
73
|
+
interface UseInboundChannelResult {
|
|
74
|
+
data: InboundChannelData | null;
|
|
75
|
+
loading: boolean;
|
|
76
|
+
error: Error | undefined;
|
|
77
|
+
refetch: () => Promise<void>;
|
|
78
|
+
}
|
|
79
|
+
/** The global channel a connector names, with its inbound webhook URL. */
|
|
80
|
+
export declare function useInboundChannel(channelId: string | null | undefined): UseInboundChannelResult;
|
|
81
|
+
export interface ProvisionChannelInput {
|
|
82
|
+
name: string;
|
|
83
|
+
description?: string;
|
|
84
|
+
organizationId: string;
|
|
85
|
+
definition: PlatformCredentialDefinition;
|
|
86
|
+
credentials: Record<string, string>;
|
|
87
|
+
}
|
|
88
|
+
interface UseProvisionChannelResult {
|
|
89
|
+
/** Creates the global channel and its connection; resolves to the channel id. */
|
|
90
|
+
provision: (input: ProvisionChannelInput) => Promise<string>;
|
|
91
|
+
/** Deletes a channel `provision` created (rollback when the connector fails). */
|
|
92
|
+
discard: (channelId: string) => Promise<void>;
|
|
93
|
+
loading: boolean;
|
|
94
|
+
}
|
|
95
|
+
export declare function useProvisionChannel(): UseProvisionChannelResult;
|
|
96
|
+
export {};
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { useBotlit as e } from "../providers/BotlitProvider.js";
|
|
2
|
+
import { extractGraphqlFailureMessage as t } from "../utils/errors.js";
|
|
3
|
+
import { useCallback as n, useEffect as r, useRef as i, useState as a } from "react";
|
|
4
|
+
import { gql as o } from "@apollo/client";
|
|
5
|
+
import { useGatewayClient as s } from "@burdenoff/fe-libs/shared/graphql";
|
|
6
|
+
// src/botlit/hooks/useChannelSetup.ts
|
|
7
|
+
var c = {
|
|
8
|
+
SLACK: {
|
|
9
|
+
platform: "SLACK",
|
|
10
|
+
authType: "BOT_TOKEN",
|
|
11
|
+
fields: [{
|
|
12
|
+
key: "botToken",
|
|
13
|
+
label: "Bot User OAuth Token",
|
|
14
|
+
description: "Slack app → OAuth & Permissions. Starts with xoxb-.",
|
|
15
|
+
placeholder: "xoxb-…",
|
|
16
|
+
secret: !0
|
|
17
|
+
}, {
|
|
18
|
+
key: "signingSecret",
|
|
19
|
+
label: "Signing Secret",
|
|
20
|
+
description: "Slack app → Basic Information → App Credentials.",
|
|
21
|
+
placeholder: "Signing secret",
|
|
22
|
+
secret: !0
|
|
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."
|
|
25
|
+
},
|
|
26
|
+
WEBHOOK: {
|
|
27
|
+
platform: "WEBHOOK",
|
|
28
|
+
authType: "WEBHOOK",
|
|
29
|
+
fields: [{
|
|
30
|
+
key: "targetUrl",
|
|
31
|
+
label: "Reply URL",
|
|
32
|
+
description: "The bot POSTs its replies to this https URL.",
|
|
33
|
+
placeholder: "https://example.com/bot-replies",
|
|
34
|
+
secret: !1,
|
|
35
|
+
url: !0
|
|
36
|
+
}, {
|
|
37
|
+
key: "webhookSecret",
|
|
38
|
+
label: "Signing Secret",
|
|
39
|
+
description: "Your sender signs each request body with HMAC-SHA256 using this secret and sends the hex digest in the X-Signature header.",
|
|
40
|
+
placeholder: "Generate or paste a secret",
|
|
41
|
+
secret: !0,
|
|
42
|
+
generatable: !0
|
|
43
|
+
}],
|
|
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."
|
|
45
|
+
}
|
|
46
|
+
}, l = {
|
|
47
|
+
SLACK: "SLACK",
|
|
48
|
+
TEAMS: "TEAMS",
|
|
49
|
+
DISCORD: "DISCORD",
|
|
50
|
+
WHATSAPP: "WHATSAPP",
|
|
51
|
+
WEBHOOK: "WEBHOOK"
|
|
52
|
+
};
|
|
53
|
+
function u(e) {
|
|
54
|
+
return l[e];
|
|
55
|
+
}
|
|
56
|
+
function d() {
|
|
57
|
+
let e = /* @__PURE__ */ new Uint8Array(32);
|
|
58
|
+
return crypto.getRandomValues(e), Array.from(e, (e) => e.toString(16).padStart(2, "0")).join("");
|
|
59
|
+
}
|
|
60
|
+
function f(e, t) {
|
|
61
|
+
for (let n of e.fields) {
|
|
62
|
+
let e = t[n.key]?.trim() ?? "";
|
|
63
|
+
if (!e) return `${n.label} is required`;
|
|
64
|
+
if (n.url) {
|
|
65
|
+
let t;
|
|
66
|
+
try {
|
|
67
|
+
t = new URL(e);
|
|
68
|
+
} catch {
|
|
69
|
+
return `${n.label} must be a valid URL`;
|
|
70
|
+
}
|
|
71
|
+
if (t.protocol !== "https:") return `${n.label} must use https`;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
function p() {
|
|
77
|
+
return e().organizationId || null;
|
|
78
|
+
}
|
|
79
|
+
var m = o`
|
|
80
|
+
query BotmanorInboundChannel($id: ID!) {
|
|
81
|
+
getChannel(id: $id) {
|
|
82
|
+
id
|
|
83
|
+
name
|
|
84
|
+
platform
|
|
85
|
+
status
|
|
86
|
+
isConnected
|
|
87
|
+
inboundWorkspaceId
|
|
88
|
+
inboundWebhookUrl
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
`, h = o`
|
|
92
|
+
mutation BotmanorCreateSetupChannel($input: CreateChannelInput!) {
|
|
93
|
+
createChannel(input: $input) {
|
|
94
|
+
id
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
`, g = o`
|
|
98
|
+
mutation BotmanorCreateSetupConnection($input: CreateConnectionInput!) {
|
|
99
|
+
createConnection(input: $input) {
|
|
100
|
+
id
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
`, _ = o`
|
|
104
|
+
mutation BotmanorDeleteSetupChannel($id: ID!) {
|
|
105
|
+
deleteChannel(id: $id)
|
|
106
|
+
}
|
|
107
|
+
`;
|
|
108
|
+
function v(e, n) {
|
|
109
|
+
let r = t(e);
|
|
110
|
+
return r ? Error(r, { cause: e }) : e instanceof Error ? e : Error(n, { cause: e });
|
|
111
|
+
}
|
|
112
|
+
function y(e, t) {
|
|
113
|
+
let n = e.error;
|
|
114
|
+
if (n != null) throw v(n, t);
|
|
115
|
+
}
|
|
116
|
+
function b() {
|
|
117
|
+
return s("global");
|
|
118
|
+
}
|
|
119
|
+
function x(e) {
|
|
120
|
+
let t = b(), [o, s] = a(null), [c, l] = a(!1), [u, d] = a(void 0), f = i(0), p = n(async () => {
|
|
121
|
+
let n = ++f.current, r = () => n === f.current;
|
|
122
|
+
if (s(null), d(void 0), e) {
|
|
123
|
+
l(!0);
|
|
124
|
+
try {
|
|
125
|
+
let n = await t.query({
|
|
126
|
+
query: m,
|
|
127
|
+
variables: { id: e },
|
|
128
|
+
fetchPolicy: "network-only"
|
|
129
|
+
});
|
|
130
|
+
y(n, "Failed to load the channel"), r() && s(n.data?.getChannel ?? null);
|
|
131
|
+
} catch (e) {
|
|
132
|
+
r() && d(v(e, "Failed to load the channel"));
|
|
133
|
+
} finally {
|
|
134
|
+
r() && l(!1);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}, [e, t]);
|
|
138
|
+
return r(() => {
|
|
139
|
+
p();
|
|
140
|
+
}, [p]), {
|
|
141
|
+
data: o,
|
|
142
|
+
loading: c,
|
|
143
|
+
error: u,
|
|
144
|
+
refetch: p
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function S() {
|
|
148
|
+
let e = b(), [t, r] = a(!1), i = n(async (t) => {
|
|
149
|
+
y(await e.mutate({
|
|
150
|
+
mutation: _,
|
|
151
|
+
variables: { id: t }
|
|
152
|
+
}), "Failed to delete the channel");
|
|
153
|
+
}, [e]);
|
|
154
|
+
return {
|
|
155
|
+
provision: n(async ({ name: t, description: n, organizationId: a, definition: o, credentials: s }) => {
|
|
156
|
+
r(!0);
|
|
157
|
+
try {
|
|
158
|
+
let r;
|
|
159
|
+
try {
|
|
160
|
+
let i = await e.mutate({
|
|
161
|
+
mutation: h,
|
|
162
|
+
variables: { input: {
|
|
163
|
+
name: t,
|
|
164
|
+
description: n || void 0,
|
|
165
|
+
platform: o.platform,
|
|
166
|
+
channelType: "COMMUNICATION",
|
|
167
|
+
organizationId: a
|
|
168
|
+
} }
|
|
169
|
+
});
|
|
170
|
+
y(i, "Failed to create the channel"), r = i.data?.createChannel?.id;
|
|
171
|
+
} catch (e) {
|
|
172
|
+
throw v(e, "Failed to create the channel");
|
|
173
|
+
}
|
|
174
|
+
if (!r) throw Error("Failed to create the channel");
|
|
175
|
+
let c = Object.fromEntries(o.fields.map((e) => [e.key, s[e.key]?.trim() ?? ""]));
|
|
176
|
+
try {
|
|
177
|
+
y(await e.mutate({
|
|
178
|
+
mutation: g,
|
|
179
|
+
variables: { input: {
|
|
180
|
+
channelId: r,
|
|
181
|
+
authType: o.authType,
|
|
182
|
+
credentials: c
|
|
183
|
+
} }
|
|
184
|
+
}), "Failed to save the channel credentials");
|
|
185
|
+
} catch (e) {
|
|
186
|
+
throw await i(r).catch(() => void 0), v(e, "Failed to save the channel credentials");
|
|
187
|
+
}
|
|
188
|
+
return r;
|
|
189
|
+
} finally {
|
|
190
|
+
r(!1);
|
|
191
|
+
}
|
|
192
|
+
}, [e, i]),
|
|
193
|
+
discard: i,
|
|
194
|
+
loading: t
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
export { c as PLATFORM_CREDENTIALS, u as connectorPlatform, d as generateSigningSecret, p as useActiveOrganizationId, x as useInboundChannel, S as useProvisionChannel, f as validateCredentials };
|
|
198
|
+
|
|
199
|
+
//# sourceMappingURL=useChannelSetup.js.map
|
|
@@ -0,0 +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","useGlobalClient","useGatewayClient","useInboundChannel","client","data","setData","useState","loading","setLoading","error","setError","latestRequest","useRef","refetch","useCallback","request","isLatest","channelId","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. 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, type ApolloClient } from '@apollo/client';\nimport { useGatewayClient } from '@burdenoff/fe-libs/shared/graphql';\n\nimport { useBotlit } from '../providers/BotlitProvider';\nimport { extractGraphqlFailureMessage } from '../utils/errors';\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\nfunction useGlobalClient(): ApolloClient {\n return useGatewayClient('global');\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 = useGlobalClient();\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 });\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]);\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 = useGlobalClient();\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 });\n throwIfOperationFailed(result, 'Failed to delete the channel');\n },\n [client]\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 });\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 });\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, discard]\n );\n\n return { provision, discard, loading };\n}\n"],"mappings":";;;;;;AAiEA,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,oBAAQ,IAAI,WAAW,EAAE;CAE/B,OADA,OAAO,gBAAgBA,CAAK,GACrB,MAAM,KAAKA,IAAQ,MAASC,EAAK,SAAS,EAAE,CAAC,CAAC,SAAS,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE;AAChF;AAMA,SAAgBC,EACd,GACA,GACe;CACf,KAAK,IAAMC,KAASC,EAAW,QAAQ;EACrC,IAAMC,IAAQC,EAAOH,EAAM,IAAI,EAAE,KAAK,KAAK;EAC3C,IAAI,CAACE,GAAO,OAAO,GAAGF,EAAM,MAAM;EAClC,IAAIA,EAAM,KAAK;GACb,IAAII;GACJ,IAAI;IACF,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AuB,MANCsB,EAAO,OAAO;MACpC,UAAUb;MACV,WAAW,EACT,OAAO;OAAE;OAAW,UAAUR,EAAW;OAAU,aAAayC;MAAQ,EAC1E;KACF,CAAC,GACiC,wCAAwC;IAC5E,SAAS5B,GAAO;KAId,MADA,MAAMyB,EAAQH,CAAS,CAAC,CAAC,YAAY,KAAA,CAAS,GACxCzB,EAAQG,GAAO,wCAAwC;IAC/D;IACA,OAAOsB;GACT,UAAU;IACR,EAAW,EAAK;GAClB;EACF,GACA,CAACd,GAAQiB,CAAO,CAGT;EAAW;EAAS;CAAQ;AACvC"}
|
|
@@ -75,6 +75,12 @@ export declare const channelKeys: {
|
|
|
75
75
|
};
|
|
76
76
|
export declare function useChannelConnectors(filter?: ChannelFilter): QueryResult<ChannelConnectorRecord[]>;
|
|
77
77
|
export declare function useChannelConnector(connectorId: string | undefined): QueryResult<ChannelConnectorRecord | null>;
|
|
78
|
+
/**
|
|
79
|
+
* Looks up whether this workspace already has a connector naming a global
|
|
80
|
+
* channel. Resolves to the connector, null when there is none, and rejects
|
|
81
|
+
* when the lookup itself fails (the answer is then unknown).
|
|
82
|
+
*/
|
|
83
|
+
export declare function useFindChannelConnector(): (channelId: string) => Promise<ChannelConnectorRecord | null>;
|
|
78
84
|
export declare function useCreateChannelConnector(): readonly [(input: CreateChannelConnectorVariables) => Promise<ChannelConnectorRecord>, import('./internal/workspaceGateway').MutationState<ChannelConnectorRecord>];
|
|
79
85
|
export declare function useUpdateChannelConnector(): readonly [(input: UpdateChannelConnectorVariables) => Promise<ChannelConnectorRecord>, import('./internal/workspaceGateway').MutationState<ChannelConnectorRecord>];
|
|
80
86
|
export declare function useDeleteChannelConnector(): readonly [(input: string) => Promise<boolean>, import('./internal/workspaceGateway').MutationState<boolean>];
|