@burdenoff/microfe-botmanor 2026.1120.27 → 2026.1120.28
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/HandoffConfigPanel.js +133 -132
- package/dist/botlit/components/HandoffConfigPanel.js.map +1 -1
- package/dist/botlit/components/HandoffTargetPickers.d.ts +28 -0
- package/dist/botlit/components/HandoffTargetPickers.js +180 -0
- package/dist/botlit/components/HandoffTargetPickers.js.map +1 -0
- package/dist/botlit/hooks/index.js +2 -2
- package/dist/botlit/hooks/useHandoffInbox.d.ts +26 -0
- package/dist/botlit/hooks/useHandoffInbox.js +126 -0
- package/dist/botlit/hooks/useHandoffInbox.js.map +1 -0
- package/dist/botlit/hooks/useHandoffs.js +36 -63
- package/dist/botlit/hooks/useHandoffs.js.map +1 -1
- package/dist/botlit/hooks/useMyIntegrationConnections.d.ts +4 -0
- package/dist/botlit/hooks/useMyIntegrationConnections.js +26 -0
- package/dist/botlit/hooks/useMyIntegrationConnections.js.map +1 -0
- package/dist/botlit/hooks/useWorkspaceMemberDirectory.d.ts +26 -0
- package/dist/botlit/hooks/useWorkspaceMemberDirectory.js +84 -0
- package/dist/botlit/hooks/useWorkspaceMemberDirectory.js.map +1 -0
- package/dist/botlit/pages/BotChannelsTab.js +288 -250
- package/dist/botlit/pages/BotChannelsTab.js.map +1 -1
- package/dist/botlit/pages/HandoffsPage.js +190 -149
- package/dist/botlit/pages/HandoffsPage.js.map +1 -1
- package/dist/botlit/utils/handoffInbox.d.ts +64 -0
- package/dist/botlit/utils/handoffInbox.js +62 -0
- package/dist/botlit/utils/handoffInbox.js.map +1 -0
- package/dist/generated/wspace-operations.d.ts +160 -0
- package/dist/generated/wspace-operations.js +128 -87
- package/dist/generated/wspace-operations.js.map +1 -1
- package/dist/generated/wspace-types.js +8 -6
- package/dist/generated/wspace-types.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { useTr as e } from "../../shared/hooks/useTr.js";
|
|
2
|
+
import { shortUserLabel as t } from "../hooks/useWorkspaceMemberDirectory.js";
|
|
3
|
+
import { memberRoleOptions as n, nextListboxIndex as r, teammateCandidates as i } from "../utils/handoffInbox.js";
|
|
4
|
+
import { Button as a } from "./Button.js";
|
|
5
|
+
import { Input as o } from "./Input.js";
|
|
6
|
+
import { useMemo as s, useState as c } from "react";
|
|
7
|
+
import { jsx as l, jsxs as u } from "react/jsx-runtime";
|
|
8
|
+
import { X as d } from "lucide-react";
|
|
9
|
+
// src/botlit/components/HandoffTargetPickers.tsx
|
|
10
|
+
var f = "h-10 w-full rounded-md border border-border-default bg-bg-surface px-3 text-sm text-text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary", p = 50, m = ({ label: n, value: r, byId: i, onChange: o }) => {
|
|
11
|
+
let s = e();
|
|
12
|
+
return r.length === 0 ? null : /* @__PURE__ */ l("ul", {
|
|
13
|
+
className: "flex flex-wrap gap-2",
|
|
14
|
+
"aria-label": n,
|
|
15
|
+
children: r.map((e) => {
|
|
16
|
+
let n = i.get(e), c = n?.displayName ?? t(e);
|
|
17
|
+
return /* @__PURE__ */ u("li", {
|
|
18
|
+
className: "flex items-center gap-1 rounded-full border border-border-subtle bg-bg-sunken py-0.5 pl-3 pr-1",
|
|
19
|
+
children: [
|
|
20
|
+
/* @__PURE__ */ l("span", { children: c }),
|
|
21
|
+
n ? null : /* @__PURE__ */ l("span", {
|
|
22
|
+
className: "text-xs text-text-secondary",
|
|
23
|
+
children: s("botlit.handoffs.config.notAMember", "(not in this workspace)")
|
|
24
|
+
}),
|
|
25
|
+
/* @__PURE__ */ l(a, {
|
|
26
|
+
type: "button",
|
|
27
|
+
variant: "ghost",
|
|
28
|
+
size: "icon",
|
|
29
|
+
className: "h-6 w-6",
|
|
30
|
+
"aria-label": s("botlit.handoffs.config.removeTeammate", "Remove {{name}}", { name: c }),
|
|
31
|
+
onClick: () => o(r.filter((t) => t !== e)),
|
|
32
|
+
children: /* @__PURE__ */ l(d, {
|
|
33
|
+
size: 12,
|
|
34
|
+
"aria-hidden": "true"
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
]
|
|
38
|
+
}, e);
|
|
39
|
+
})
|
|
40
|
+
});
|
|
41
|
+
}, h = ({ listId: t, optionId: n, options: r, activeIndex: i, onHighlight: a, onChoose: o }) => {
|
|
42
|
+
let s = e();
|
|
43
|
+
return /* @__PURE__ */ l("ul", {
|
|
44
|
+
id: t,
|
|
45
|
+
role: "listbox",
|
|
46
|
+
className: "max-h-48 overflow-y-auto rounded-md border border-border-subtle",
|
|
47
|
+
"aria-label": s("botlit.handoffs.config.teammates", "Teammates"),
|
|
48
|
+
children: r.map((e, t) => /* @__PURE__ */ u("li", {
|
|
49
|
+
id: n(e.userId),
|
|
50
|
+
role: "option",
|
|
51
|
+
"aria-selected": t === i,
|
|
52
|
+
className: `flex w-full cursor-pointer items-center justify-between gap-2 px-3 py-2 text-left hover:bg-accent ${t === i ? "bg-accent" : ""}`,
|
|
53
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
54
|
+
onMouseEnter: () => a(t),
|
|
55
|
+
onClick: () => o(e.userId),
|
|
56
|
+
children: [/* @__PURE__ */ u("span", { children: [/* @__PURE__ */ l("span", {
|
|
57
|
+
className: "font-medium text-text-primary",
|
|
58
|
+
children: e.displayName
|
|
59
|
+
}), e.email ? /* @__PURE__ */ l("span", {
|
|
60
|
+
className: "ml-2 text-text-secondary",
|
|
61
|
+
children: e.email
|
|
62
|
+
}) : null] }), /* @__PURE__ */ l("span", {
|
|
63
|
+
className: "text-xs text-text-secondary",
|
|
64
|
+
children: e.role
|
|
65
|
+
})]
|
|
66
|
+
}, e.userId))
|
|
67
|
+
});
|
|
68
|
+
}, g = ({ loading: t, query: n }) => {
|
|
69
|
+
let r = e();
|
|
70
|
+
return t ? /* @__PURE__ */ l("p", {
|
|
71
|
+
role: "status",
|
|
72
|
+
className: "text-text-secondary",
|
|
73
|
+
children: r("botlit.handoffs.config.loadingMembers", "Loading teammates…")
|
|
74
|
+
}) : /* @__PURE__ */ l("p", {
|
|
75
|
+
className: "text-text-secondary",
|
|
76
|
+
children: n.trim() ? r("botlit.handoffs.config.noTeammateMatch", "No teammate matches \"{{query}}\".", { query: n.trim() }) : r("botlit.handoffs.config.allTeammatesChosen", "Every teammate is already chosen.")
|
|
77
|
+
});
|
|
78
|
+
}, _ = ({ id: t, label: n, members: d, loading: f, error: _, onRetry: v, value: y, onChange: b }) => {
|
|
79
|
+
let x = e(), [S, C] = c(""), [w, T] = c(0), E = s(() => new Map(d.map((e) => [e.userId, e])), [d]), D = i(d, y, S).slice(0, p), O = `${t}-options`, k = (e) => `${t}-option-${e}`, A = Math.min(w, D.length - 1), j = D[A], M = !f && D.length > 0, N = (e) => {
|
|
80
|
+
b([...y, e]), C(""), T(0);
|
|
81
|
+
};
|
|
82
|
+
return _ ? /* @__PURE__ */ u("div", {
|
|
83
|
+
className: "grid gap-2 text-sm",
|
|
84
|
+
children: [
|
|
85
|
+
/* @__PURE__ */ l("label", {
|
|
86
|
+
htmlFor: t,
|
|
87
|
+
className: "font-medium text-text-primary",
|
|
88
|
+
children: n
|
|
89
|
+
}),
|
|
90
|
+
/* @__PURE__ */ l(m, {
|
|
91
|
+
label: n,
|
|
92
|
+
value: y,
|
|
93
|
+
byId: E,
|
|
94
|
+
onChange: b
|
|
95
|
+
}),
|
|
96
|
+
/* @__PURE__ */ u("div", {
|
|
97
|
+
role: "alert",
|
|
98
|
+
className: "flex flex-wrap items-center gap-2 text-status-error-text",
|
|
99
|
+
children: [/* @__PURE__ */ l("span", { children: _.message }), /* @__PURE__ */ l(a, {
|
|
100
|
+
type: "button",
|
|
101
|
+
size: "sm",
|
|
102
|
+
variant: "outline",
|
|
103
|
+
onClick: v,
|
|
104
|
+
children: x("common.tryAgain", "Try again")
|
|
105
|
+
})]
|
|
106
|
+
})
|
|
107
|
+
]
|
|
108
|
+
}) : /* @__PURE__ */ u("div", {
|
|
109
|
+
className: "grid gap-2 text-sm",
|
|
110
|
+
children: [
|
|
111
|
+
/* @__PURE__ */ l("label", {
|
|
112
|
+
htmlFor: t,
|
|
113
|
+
className: "font-medium text-text-primary",
|
|
114
|
+
children: n
|
|
115
|
+
}),
|
|
116
|
+
/* @__PURE__ */ l(m, {
|
|
117
|
+
label: n,
|
|
118
|
+
value: y,
|
|
119
|
+
byId: E,
|
|
120
|
+
onChange: b
|
|
121
|
+
}),
|
|
122
|
+
/* @__PURE__ */ l(o, {
|
|
123
|
+
id: t,
|
|
124
|
+
role: "combobox",
|
|
125
|
+
"aria-autocomplete": "list",
|
|
126
|
+
"aria-expanded": M,
|
|
127
|
+
"aria-controls": O,
|
|
128
|
+
"aria-activedescendant": M && j ? k(j.userId) : void 0,
|
|
129
|
+
value: S,
|
|
130
|
+
onChange: (e) => {
|
|
131
|
+
C(e.target.value), T(0);
|
|
132
|
+
},
|
|
133
|
+
onKeyDown: (e) => {
|
|
134
|
+
let t = r(e.key, A, D.length);
|
|
135
|
+
t === null ? e.key === "Enter" && j ? (e.preventDefault(), N(j.userId)) : e.key === "Escape" && S && (e.preventDefault(), C(""), T(0)) : (e.preventDefault(), T(t));
|
|
136
|
+
},
|
|
137
|
+
placeholder: x("botlit.handoffs.config.searchTeammates", "Search teammates by name or email")
|
|
138
|
+
}),
|
|
139
|
+
M ? /* @__PURE__ */ l(h, {
|
|
140
|
+
listId: O,
|
|
141
|
+
optionId: k,
|
|
142
|
+
options: D,
|
|
143
|
+
activeIndex: A,
|
|
144
|
+
onHighlight: T,
|
|
145
|
+
onChoose: N
|
|
146
|
+
}) : /* @__PURE__ */ l(g, {
|
|
147
|
+
loading: f,
|
|
148
|
+
query: S
|
|
149
|
+
})
|
|
150
|
+
]
|
|
151
|
+
});
|
|
152
|
+
}, v = ({ id: t, label: r, members: i, value: a, onChange: o }) => {
|
|
153
|
+
let c = e(), d = s(() => n(i.map((e) => e.role), a), [i, a]), p = (e) => i.filter((t) => t.role.toLowerCase() === e.toLowerCase()).length;
|
|
154
|
+
return /* @__PURE__ */ u("div", {
|
|
155
|
+
className: "grid gap-1 text-sm",
|
|
156
|
+
children: [/* @__PURE__ */ l("label", {
|
|
157
|
+
htmlFor: t,
|
|
158
|
+
className: "font-medium text-text-primary",
|
|
159
|
+
children: r
|
|
160
|
+
}), /* @__PURE__ */ u("select", {
|
|
161
|
+
id: t,
|
|
162
|
+
className: f,
|
|
163
|
+
value: a,
|
|
164
|
+
onChange: (e) => o(e.target.value),
|
|
165
|
+
children: [/* @__PURE__ */ l("option", {
|
|
166
|
+
value: "",
|
|
167
|
+
children: c("botlit.handoffs.config.noRole", "No role")
|
|
168
|
+
}), d.map((e) => /* @__PURE__ */ l("option", {
|
|
169
|
+
value: e,
|
|
170
|
+
children: c("botlit.handoffs.config.roleOption", "{{role}} ({{count}} members)", {
|
|
171
|
+
role: e,
|
|
172
|
+
count: p(e)
|
|
173
|
+
})
|
|
174
|
+
}, e))]
|
|
175
|
+
})]
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
|
+
export { _ as MemberMultiSelect, v as MemberRoleSelect };
|
|
179
|
+
|
|
180
|
+
//# sourceMappingURL=HandoffTargetPickers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HandoffTargetPickers.js","names":["SELECT_CLASS","MAX_CANDIDATES","ChosenTeammates","t","useTr","value","label","member","byId","userId","name","shortUserLabel","Button","onChange","entry","X","TeammateOptions","listId","options","optionId","index","activeIndex","event","onHighlight","onChoose","TeammateListStatus","loading","query","MemberMultiSelect","setQuery","useState","active","setActive","useMemo","members","shown","teammateCandidates","id","activeMember","expanded","choose","error","onRetry","Input","next","nextListboxIndex","MemberRoleSelect","memberRoleOptions","holders","role"],"sources":["../../../src/botlit/components/HandoffTargetPickers.tsx"],"sourcesContent":["/**\n * Handoff target pickers (BOFF-15472)\n * @module botlit/components\n *\n * \"Who takes over\" used to be a comma-separated list of auth user ids and a\n * free-text role, so one typo routed a handoff to nobody. These controls pick\n * teammates by name from the workspace directory and the role from the roles\n * workspace members actually hold. They still produce the same values the\n * handoff config stores: user ids and a role name.\n */\n\nimport type { FC, KeyboardEvent } from 'react';\nimport { useMemo, useState } from 'react';\nimport { X } from 'lucide-react';\n\nimport { useTr } from '../../shared/hooks/useTr';\nimport { shortUserLabel, type DirectoryMember } from '../hooks/useWorkspaceMemberDirectory';\nimport { memberRoleOptions, nextListboxIndex, teammateCandidates } from '../utils/handoffInbox';\nimport { Button } from './Button';\nimport { Input } from './Input';\n\nconst SELECT_CLASS =\n 'h-10 w-full rounded-md border border-border-default bg-bg-surface px-3 text-sm text-text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary';\n\nexport interface MemberMultiSelectProps {\n id: string;\n label: string;\n members: DirectoryMember[];\n loading: boolean;\n error: Error | undefined;\n onRetry: () => void;\n value: string[];\n onChange: (userIds: string[]) => void;\n}\n\n/** The most candidates the list shows at once; typing narrows it. */\nconst MAX_CANDIDATES = 50;\n\n/** The chosen teammates as removable chips. */\nconst ChosenTeammates: FC<{\n label: string;\n value: string[];\n byId: ReadonlyMap<string, DirectoryMember>;\n onChange: (userIds: string[]) => void;\n}> = ({ label, value, byId, onChange }) => {\n const t = useTr();\n if (value.length === 0) return null;\n return (\n <ul className=\"flex flex-wrap gap-2\" aria-label={label}>\n {value.map((userId) => {\n const member = byId.get(userId);\n const name = member?.displayName ?? shortUserLabel(userId);\n return (\n <li\n key={userId}\n className=\"flex items-center gap-1 rounded-full border border-border-subtle bg-bg-sunken py-0.5 pl-3 pr-1\"\n >\n <span>{name}</span>\n {member ? null : (\n <span className=\"text-xs text-text-secondary\">\n {t('botlit.handoffs.config.notAMember', '(not in this workspace)')}\n </span>\n )}\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"icon\"\n className=\"h-6 w-6\"\n aria-label={t('botlit.handoffs.config.removeTeammate', 'Remove {{name}}', { name })}\n onClick={() => onChange(value.filter((entry) => entry !== userId))}\n >\n <X size={12} aria-hidden=\"true\" />\n </Button>\n </li>\n );\n })}\n </ul>\n );\n};\n\n/** The listbox half of the combobox; focus stays in the search field. */\nconst TeammateOptions: FC<{\n listId: string;\n optionId: (userId: string) => string;\n options: DirectoryMember[];\n activeIndex: number;\n onHighlight: (index: number) => void;\n onChoose: (userId: string) => void;\n}> = ({ listId, optionId, options, activeIndex, onHighlight, onChoose }) => {\n const t = useTr();\n return (\n <ul\n id={listId}\n role=\"listbox\"\n className=\"max-h-48 overflow-y-auto rounded-md border border-border-subtle\"\n aria-label={t('botlit.handoffs.config.teammates', 'Teammates')}\n >\n {options.map((member, index) => (\n <li\n key={member.userId}\n id={optionId(member.userId)}\n role=\"option\"\n aria-selected={index === activeIndex}\n className={`flex w-full cursor-pointer items-center justify-between gap-2 px-3 py-2 text-left hover:bg-accent ${\n index === activeIndex ? 'bg-accent' : ''\n }`}\n // Keep focus in the search field, so the next keystroke still searches.\n onMouseDown={(event) => event.preventDefault()}\n onMouseEnter={() => onHighlight(index)}\n onClick={() => onChoose(member.userId)}\n >\n <span>\n <span className=\"font-medium text-text-primary\">{member.displayName}</span>\n {member.email ? <span className=\"ml-2 text-text-secondary\">{member.email}</span> : null}\n </span>\n <span className=\"text-xs text-text-secondary\">{member.role}</span>\n </li>\n ))}\n </ul>\n );\n};\n\n/** What shows under the search field when there are no options to list. */\nconst TeammateListStatus: FC<{ loading: boolean; query: string }> = ({ loading, query }) => {\n const t = useTr();\n if (loading) {\n return (\n <p role=\"status\" className=\"text-text-secondary\">\n {t('botlit.handoffs.config.loadingMembers', 'Loading teammates…')}\n </p>\n );\n }\n return (\n <p className=\"text-text-secondary\">\n {query.trim()\n ? t('botlit.handoffs.config.noTeammateMatch', 'No teammate matches \"{{query}}\".', {\n query: query.trim(),\n })\n : t('botlit.handoffs.config.allTeammatesChosen', 'Every teammate is already chosen.')}\n </p>\n );\n};\n\n/**\n * Chips for the chosen teammates plus a searchable list to add more. The search\n * field and the list follow the ARIA combobox pattern: arrow keys, Home and End\n * move through the options, Enter adds the highlighted one, Escape clears the\n * search.\n */\nexport const MemberMultiSelect: FC<MemberMultiSelectProps> = ({\n id,\n label,\n members,\n loading,\n error,\n onRetry,\n value,\n onChange,\n}) => {\n const t = useTr();\n const [query, setQuery] = useState('');\n const [active, setActive] = useState(0);\n const byId = useMemo(() => new Map(members.map((member) => [member.userId, member])), [members]);\n const shown = teammateCandidates(members, value, query).slice(0, MAX_CANDIDATES);\n const listId = `${id}-options`;\n const optionId = (userId: string) => `${id}-option-${userId}`;\n // The list shrinks as people are added or the search narrows; keep the\n // highlight on a real option.\n const activeIndex = Math.min(active, shown.length - 1);\n const activeMember = shown[activeIndex];\n const expanded = !loading && shown.length > 0;\n\n const choose = (userId: string) => {\n onChange([...value, userId]);\n setQuery('');\n // The full list comes back; start again at its first option.\n setActive(0);\n };\n\n const onSearchKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {\n const next = nextListboxIndex(event.key, activeIndex, shown.length);\n if (next !== null) {\n event.preventDefault();\n setActive(next);\n } else if (event.key === 'Enter' && activeMember) {\n // Keep Enter from submitting the surrounding form.\n event.preventDefault();\n choose(activeMember.userId);\n } else if (event.key === 'Escape' && query) {\n event.preventDefault();\n setQuery('');\n setActive(0);\n }\n };\n\n if (error) {\n return (\n <div className=\"grid gap-2 text-sm\">\n <label htmlFor={id} className=\"font-medium text-text-primary\">\n {label}\n </label>\n <ChosenTeammates label={label} value={value} byId={byId} onChange={onChange} />\n <div role=\"alert\" className=\"flex flex-wrap items-center gap-2 text-status-error-text\">\n <span>{error.message}</span>\n <Button type=\"button\" size=\"sm\" variant=\"outline\" onClick={onRetry}>\n {t('common.tryAgain', 'Try again')}\n </Button>\n </div>\n </div>\n );\n }\n\n return (\n <div className=\"grid gap-2 text-sm\">\n <label htmlFor={id} className=\"font-medium text-text-primary\">\n {label}\n </label>\n <ChosenTeammates label={label} value={value} byId={byId} onChange={onChange} />\n <Input\n id={id}\n role=\"combobox\"\n aria-autocomplete=\"list\"\n aria-expanded={expanded}\n aria-controls={listId}\n aria-activedescendant={expanded && activeMember ? optionId(activeMember.userId) : undefined}\n value={query}\n onChange={(event) => {\n setQuery(event.target.value);\n setActive(0);\n }}\n onKeyDown={onSearchKeyDown}\n placeholder={t(\n 'botlit.handoffs.config.searchTeammates',\n 'Search teammates by name or email'\n )}\n />\n {expanded ? (\n <TeammateOptions\n listId={listId}\n optionId={optionId}\n options={shown}\n activeIndex={activeIndex}\n onHighlight={setActive}\n onChoose={choose}\n />\n ) : (\n <TeammateListStatus loading={loading} query={query} />\n )}\n </div>\n );\n};\n\nexport interface MemberRoleSelectProps {\n id: string;\n label: string;\n members: DirectoryMember[];\n value: string;\n onChange: (role: string) => void;\n}\n\n/** The membership role whose holders all get the handoff. */\nexport const MemberRoleSelect: FC<MemberRoleSelectProps> = ({\n id,\n label,\n members,\n value,\n onChange,\n}) => {\n const t = useTr();\n const options = useMemo(\n () =>\n memberRoleOptions(\n members.map((member) => member.role),\n value\n ),\n [members, value]\n );\n const holders = (role: string) =>\n members.filter((member) => member.role.toLowerCase() === role.toLowerCase()).length;\n\n return (\n <div className=\"grid gap-1 text-sm\">\n <label htmlFor={id} className=\"font-medium text-text-primary\">\n {label}\n </label>\n <select\n id={id}\n className={SELECT_CLASS}\n value={value}\n onChange={(event) => onChange(event.target.value)}\n >\n <option value=\"\">{t('botlit.handoffs.config.noRole', 'No role')}</option>\n {options.map((role) => (\n <option key={role} value={role}>\n {t('botlit.handoffs.config.roleOption', '{{role}} ({{count}} members)', {\n role,\n count: holders(role),\n })}\n </option>\n ))}\n </select>\n </div>\n );\n};\n"],"mappings":";;;;;;;;;AAqBA,IAAMA,IACJ,+KAcIC,IAAiB,IAGjBC,KAKA,EAAE,UAAO,UAAO,SAAM,kBAAe;CACzC,IAAMC,IAAIC,EAAM;CAEhB,OADIC,EAAM,WAAW,IAAU,OAE7B,kBAAC,MAAD;EAAI,WAAU;EAAuB,cAAYC;EAC9C,UAAAD,EAAM,KAAK,MAAW;GACrB,I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+C,EAC1D,OACA,UACA,YACA,UACA,kBACI;CACJ,IAAM3C,IAAIC,EAAM,GACVc,IAAUe,QAEZc,EACEb,EAAQ,KAAK,MAAW3B,EAAO,IAAI,GACnCF,CACF,GACF,CAAC6B,GAAS7B,CAAK,CACjB,GACM2C,KAAW,MACfd,EAAQ,QAAQ,MAAW3B,EAAO,KAAK,YAAY,MAAM0C,EAAK,YAAY,CAAC,CAAC,CAAC;CAE/E,OACE,kBAAC,OAAD;EAAK,WAAU;EAAf,UAAA,CACE,kBAAC,SAAD;GAAO,SAASZ;GAAI,WAAU;GAC3B,UAAA/B;EACI,CAAA,GACP,kBAAC,UAAD;GACM;GACJ,WAAWN;GACJ;GACP,WAAW,MAAUa,EAASS,EAAM,OAAO,KAAK;GAJlD,UAAA,CAME,kBAAC,UAAD;IAAQ,OAAM;IAAI,UAAAnB,EAAE,iCAAiC,SAAS;GAAU,CAAA,GACvEe,EAAQ,KAAK,MACZ,kBAAC,UAAD;IAAmB,OAAO+B;IACvB,UAAA9C,EAAE,qCAAqC,gCAAgC;KACtE;KACA,OAAO6C,EAAQC,CAAI;IACrB,CAAC;GACK,GALKA,CAKL,CACT,CACK;EACL,CAAA,CAAA;;AAET"}
|
|
@@ -17,5 +17,5 @@ import { storePackageDescription as Ee, storePackageName as De, useInstallPackag
|
|
|
17
17
|
import "./useLLMProviders.js";
|
|
18
18
|
import { useGlobalChannels as Ie, useInitiateSlackConnect as Le, useLinkIntegrationConnection as Re, useMyUserPlatformConnection as ze, useRevokeSlackConnection as Be, useToggleSlackNotifications as Ve } from "./useUserPlatformConnection.js";
|
|
19
19
|
import { useConfigureSupervisor as He, useRunSupervisorNow as Ue, useSupervisorConfig as We, useSupervisorRuns as Ge } from "./useAiOperations.js";
|
|
20
|
-
import { isActiveHandoff as Ke, useAcceptHandoff as qe, useAssignHandoff as Je, useHandoffConfig as Ye,
|
|
21
|
-
export { M as PLATFORM_CREDENTIALS, h as a2aAgentSkillCount, pe as buildBucketTree, N as connectorPlatform, Ke as isActiveHandoff, i as isMCPServerHealthy, a as mcpServerDescription, o as mcpServerEndpoint, X as promptTemplateVariables, _ as routeMetadataString, me as searchTreeRows, Ee as storePackageDescription, De as storePackageName, g as useA2AAgents, qe as useAcceptHandoff, P as useActiveOrganizationId, oe as useAgentBindings, n as useAgents, e as useAllBots, he as useAllBuckets, v as useAllChannelConnectors, y as useAllChannelRoutes, U as useApplyRetention, Je as useAssignHandoff, b as useBotChannelRoutes, t as useBots, ge as useBucket, _e as useBucketBranch, ve as useBucketContents, ye as useBucketCount, be as useBucketSearch, xe as useBuckets, x as useChannelConnector, S as useChannelConnectors, C as useChannelOverview, w as useChannelRoutes, Se as useChildBuckets, He as useConfigureSupervisor, Ce as useCreateBucket, T as useCreateChannelConnector, E as useCreateChannelRoute, s as useCreateMCPServer, R as useCreatePolicy, Z as useCreatePromptTemplate, G as useCreateSkill, we as useDeleteBucket, D as useDeleteChannelConnector, O as useDeleteChannelRoute, c as useDeleteMCPServer, z as useDeletePolicy, Q as useDeletePromptTemplate, K as useDeleteSkill, $ as useDuplicatePromptTemplate, de as useExecutionSummary, fe as useExecutions, k as useFindChannelConnector, Ie as useGlobalChannels, Ye as useHandoffConfig, Xe as
|
|
20
|
+
import { isActiveHandoff as Ke, useAcceptHandoff as qe, useAssignHandoff as Je, useHandoffConfig as Ye, useHandoffTranscript as Xe, useRejectHandoff as Ze, useReleaseHandoff as Qe, useReplyToHandoff as $e, useResolveHandoff as et, useUpsertHandoffConfig as tt } from "./useHandoffs.js";
|
|
21
|
+
export { M as PLATFORM_CREDENTIALS, h as a2aAgentSkillCount, pe as buildBucketTree, N as connectorPlatform, Ke as isActiveHandoff, i as isMCPServerHealthy, a as mcpServerDescription, o as mcpServerEndpoint, X as promptTemplateVariables, _ as routeMetadataString, me as searchTreeRows, Ee as storePackageDescription, De as storePackageName, g as useA2AAgents, qe as useAcceptHandoff, P as useActiveOrganizationId, oe as useAgentBindings, n as useAgents, e as useAllBots, he as useAllBuckets, v as useAllChannelConnectors, y as useAllChannelRoutes, U as useApplyRetention, Je as useAssignHandoff, b as useBotChannelRoutes, t as useBots, ge as useBucket, _e as useBucketBranch, ve as useBucketContents, ye as useBucketCount, be as useBucketSearch, xe as useBuckets, x as useChannelConnector, S as useChannelConnectors, C as useChannelOverview, w as useChannelRoutes, Se as useChildBuckets, He as useConfigureSupervisor, Ce as useCreateBucket, T as useCreateChannelConnector, E as useCreateChannelRoute, s as useCreateMCPServer, R as useCreatePolicy, Z as useCreatePromptTemplate, G as useCreateSkill, we as useDeleteBucket, D as useDeleteChannelConnector, O as useDeleteChannelRoute, c as useDeleteMCPServer, z as useDeletePolicy, Q as useDeletePromptTemplate, K as useDeleteSkill, $ as useDuplicatePromptTemplate, de as useExecutionSummary, fe as useExecutions, k as useFindChannelConnector, Ie as useGlobalChannels, Ye as useHandoffConfig, Xe as useHandoffTranscript, F as useInboundChannel, Le as useInitiateSlackConnect, Oe as useInstallPackage, ke as useInstalledPackageCount, Ae as useInstalledPackages, Re as useLinkIntegrationConnection, ee as useLoadPromptTemplateUsage, l as useMCPResources, u as useMCPServer, d as useMCPTools, ze as useMyUserPlatformConnection, te as usePagedPromptTemplates, B as usePolicies, V as usePolicy, ne as usePromptTemplate, se as usePromptTemplateVersions, re as usePromptTemplates, I as useProvisionChannel, Ze as useRejectHandoff, Qe as useReleaseHandoff, ie as useRenderPromptTemplate, $e as useReplyToHandoff, et as useResolveHandoff, W as useRetentionStatus, r as useRetrievalProfiles, Be as useRevokeSlackConnection, Ue as useRunSupervisorNow, ce as useSavePromptTemplateVersion, le as useSetAgentBindings, q as useSkill, J as useSkills, je as useStorePackage, Me as useStorePackageCount, Ne as useStorePackages, We as useSupervisorConfig, Ge as useSupervisorRuns, f as useTestMCPConnection, ue as useTestPromptTemplate, Ve as useToggleSlackNotifications, Pe as useUninstallPackage, Te as useUpdateBucket, A as useUpdateChannelConnector, j as useUpdateChannelRoute, Fe as useUpdateInstalledPackage, p as useUpdateMCPServer, m as useUpdateMCPTool, H as useUpdatePolicy, ae as useUpdatePromptTemplate, Y as useUpdateSkill, tt as useUpsertHandoffConfig, L as validateCredentials };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { BotmanorHandoffStatus } from '../../generated/wspace-types';
|
|
2
|
+
import { HandoffRecord } from './useHandoffs';
|
|
3
|
+
export interface HandoffInboxResult {
|
|
4
|
+
items: HandoffRecord[];
|
|
5
|
+
total: number;
|
|
6
|
+
hasMore: boolean;
|
|
7
|
+
/** True only for the first read of a filter; background refreshes keep the list. */
|
|
8
|
+
loading: boolean;
|
|
9
|
+
/** True while a refresh (manual or automatic) is running. */
|
|
10
|
+
refreshing: boolean;
|
|
11
|
+
loadingMore: boolean;
|
|
12
|
+
/** The last failed read. The previously loaded list stays visible alongside it. */
|
|
13
|
+
error: Error | undefined;
|
|
14
|
+
/** Ids that arrived in a background refresh and have not been acknowledged. */
|
|
15
|
+
newIds: ReadonlySet<string>;
|
|
16
|
+
/** Re-reads every loaded page now. */
|
|
17
|
+
refresh: () => Promise<void>;
|
|
18
|
+
loadMore: () => Promise<void>;
|
|
19
|
+
/** Clears the "new" marks. */
|
|
20
|
+
acknowledgeNew: () => void;
|
|
21
|
+
}
|
|
22
|
+
export declare function useHandoffInbox(options: {
|
|
23
|
+
statuses?: BotmanorHandoffStatus[];
|
|
24
|
+
/** Background refresh interval; defaults to INBOX_REFRESH_MS. */
|
|
25
|
+
refreshMs?: number;
|
|
26
|
+
}): HandoffInboxResult;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { HandoffQueueDocument as e } from "../../generated/wspace-operations.js";
|
|
2
|
+
import { extractGraphqlFailureMessage as t } from "../utils/errors.js";
|
|
3
|
+
import { mergeHandoffPages as n, newHandoffIds as r } from "../utils/handoffInbox.js";
|
|
4
|
+
import { useWorkspaceClient as i, useWorkspaceId as a } from "./internal/workspaceGateway.js";
|
|
5
|
+
import { useCallback as o, useEffect as s, useRef as c, useState as l } from "react";
|
|
6
|
+
// src/botlit/hooks/useHandoffInbox.ts
|
|
7
|
+
function u(e) {
|
|
8
|
+
let n = t(e);
|
|
9
|
+
return n ? Error(n, { cause: e }) : e instanceof Error ? e : Error("Failed to load the handoff queue", { cause: e });
|
|
10
|
+
}
|
|
11
|
+
var d = /* @__PURE__ */ new Set();
|
|
12
|
+
function f(t) {
|
|
13
|
+
let f = i(), p = a(), { statuses: m } = t, h = t.refreshMs ?? 2e4, g = m?.join(",") ?? "", [_, v] = l([]), [y, b] = l(0), [x, S] = l(!1), [C, w] = l(() => p ? {
|
|
14
|
+
token: 0,
|
|
15
|
+
kind: "initial"
|
|
16
|
+
} : null), [T, E] = l(), [D, O] = l(d), k = c(1), A = c(null), j = c(0), M = c(null), N = c(0), P = o((e) => {
|
|
17
|
+
if (M.current !== null) return null;
|
|
18
|
+
N.current += 1;
|
|
19
|
+
let t = N.current;
|
|
20
|
+
return M.current = t, w({
|
|
21
|
+
token: t,
|
|
22
|
+
kind: e
|
|
23
|
+
}), t;
|
|
24
|
+
}, []), F = o((e) => {
|
|
25
|
+
M.current === e && (M.current = null), w((t) => t?.token === e ? null : t);
|
|
26
|
+
}, []), I = o(async (t) => {
|
|
27
|
+
let n = await f.query({
|
|
28
|
+
query: e,
|
|
29
|
+
variables: {
|
|
30
|
+
...g ? { statuses: g.split(",") } : {},
|
|
31
|
+
pagination: {
|
|
32
|
+
limit: 100,
|
|
33
|
+
offset: t
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
fetchPolicy: "network-only"
|
|
37
|
+
}), r = n.error;
|
|
38
|
+
if (r != null) throw r;
|
|
39
|
+
let i = n.data?.handoffQueue;
|
|
40
|
+
return {
|
|
41
|
+
items: i?.items ?? [],
|
|
42
|
+
total: i?.total ?? 0,
|
|
43
|
+
hasMore: i?.hasMore ?? !1
|
|
44
|
+
};
|
|
45
|
+
}, [f, g]), L = o(async (e) => {
|
|
46
|
+
if (!p) return;
|
|
47
|
+
let t = P(e === "initial" ? "initial" : "refresh");
|
|
48
|
+
if (t === null) return;
|
|
49
|
+
let i = j.current;
|
|
50
|
+
try {
|
|
51
|
+
let t = await Promise.all(Array.from({ length: k.current }, (e, t) => I(t * 100))), a = t.findIndex((e) => !e.hasMore), o = a === -1 ? t : t.slice(0, a + 1);
|
|
52
|
+
if (i !== j.current) return;
|
|
53
|
+
let s = n(o.map((e) => e.items)), c = o[o.length - 1], l = A.current;
|
|
54
|
+
if (l && e === "background") {
|
|
55
|
+
let e = r(l, s);
|
|
56
|
+
e.length > 0 && O((t) => /* @__PURE__ */ new Set([...t, ...e]));
|
|
57
|
+
}
|
|
58
|
+
A.current = new Set(s.map((e) => e.id)), v(s), b(c?.total ?? 0), S(c?.hasMore ?? !1), E(void 0);
|
|
59
|
+
} catch (e) {
|
|
60
|
+
i === j.current && E(u(e));
|
|
61
|
+
} finally {
|
|
62
|
+
F(t);
|
|
63
|
+
}
|
|
64
|
+
}, [
|
|
65
|
+
P,
|
|
66
|
+
I,
|
|
67
|
+
F,
|
|
68
|
+
p
|
|
69
|
+
]);
|
|
70
|
+
s(() => {
|
|
71
|
+
j.current += 1, M.current = null, k.current = 1, A.current = null, v([]), b(0), S(!1), O(d), E(void 0), L("initial");
|
|
72
|
+
}, [L]), s(() => {
|
|
73
|
+
if (!p) return;
|
|
74
|
+
let e = () => globalThis.document?.visibilityState !== "hidden", t = globalThis.setInterval(() => {
|
|
75
|
+
e() && L("background");
|
|
76
|
+
}, h), n = () => {
|
|
77
|
+
e() && L("background");
|
|
78
|
+
};
|
|
79
|
+
return globalThis.document?.addEventListener("visibilitychange", n), globalThis.addEventListener?.("focus", n), () => {
|
|
80
|
+
globalThis.clearInterval(t), globalThis.document?.removeEventListener("visibilitychange", n), globalThis.removeEventListener?.("focus", n);
|
|
81
|
+
};
|
|
82
|
+
}, [
|
|
83
|
+
L,
|
|
84
|
+
h,
|
|
85
|
+
p
|
|
86
|
+
]);
|
|
87
|
+
let R = o(async () => {
|
|
88
|
+
if (!x) return;
|
|
89
|
+
let e = P("more");
|
|
90
|
+
if (e === null) return;
|
|
91
|
+
let t = j.current;
|
|
92
|
+
try {
|
|
93
|
+
let e = await I(k.current * 100);
|
|
94
|
+
if (t !== j.current) return;
|
|
95
|
+
k.current += 1;
|
|
96
|
+
let r = n([_, e.items]);
|
|
97
|
+
A.current = new Set(r.map((e) => e.id)), v(r), b(e.total), S(e.hasMore), E(void 0);
|
|
98
|
+
} catch (e) {
|
|
99
|
+
t === j.current && E(u(e));
|
|
100
|
+
} finally {
|
|
101
|
+
F(e);
|
|
102
|
+
}
|
|
103
|
+
}, [
|
|
104
|
+
P,
|
|
105
|
+
I,
|
|
106
|
+
x,
|
|
107
|
+
_,
|
|
108
|
+
F
|
|
109
|
+
]), z = o(() => L("manual"), [L]), B = o(() => O(d), []);
|
|
110
|
+
return {
|
|
111
|
+
items: _,
|
|
112
|
+
total: y,
|
|
113
|
+
hasMore: x,
|
|
114
|
+
loading: C?.kind === "initial",
|
|
115
|
+
refreshing: C?.kind === "refresh",
|
|
116
|
+
loadingMore: C?.kind === "more",
|
|
117
|
+
error: T,
|
|
118
|
+
newIds: D,
|
|
119
|
+
refresh: z,
|
|
120
|
+
loadMore: R,
|
|
121
|
+
acknowledgeNew: B
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
export { f as useHandoffInbox };
|
|
125
|
+
|
|
126
|
+
//# sourceMappingURL=useHandoffInbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useHandoffInbox.js","names":["toError","message","extractGraphqlFailureMessage","cause","EMPTY_IDS","useHandoffInbox","client","useWorkspaceClient","workspaceId","useWorkspaceId","options","refreshMs","statusKey","statuses","items","setItems","useState","total","setTotal","hasMore","setHasMore","inFlight","setInFlight","error","setError","newIds","setNewIds","pagesRef","useRef","knownRef","generationRef","busyRef","tokenRef","begin","useCallback","token","settle","current","fetchPage","result","HandoffQueueDocument","operationError","queue","read","mode","generation","fetched","index","end","page","pages","merged","mergeHandoffPages","last","known","arrived","newHandoffIds","previous","item","useEffect","visible","timer","onReturn","loadMore","refresh","acknowledgeNew"],"sources":["../../../src/botlit/hooks/useHandoffInbox.ts"],"sourcesContent":["/**\n * Team inbox queue (BOFF-15472)\n * @module botlit/hooks\n *\n * The handoff queue as the inbox needs it:\n * - paged past the server's 100-row cap with \"Load more\";\n * - re-read every INBOX_REFRESH_MS while the page is visible, and when the\n * tab regains focus or visibility, without blanking the list;\n * - handoffs that arrive in a background refresh are reported as new, so the\n * page can say so instead of silently reshuffling the list.\n *\n * A refresh re-reads every page loaded so far, so an accepted or resolved\n * handoff leaves the \"Active\" view wherever it sits in the list.\n */\n\nimport { useCallback, useEffect, useRef, useState } from 'react';\n\nimport { HandoffQueueDocument, type HandoffQueueQuery } from '../../generated/wspace-operations';\nimport type { BotmanorHandoffStatus } from '../../generated/wspace-types';\nimport { extractGraphqlFailureMessage } from '../utils/errors';\nimport {\n INBOX_PAGE_SIZE,\n INBOX_REFRESH_MS,\n mergeHandoffPages,\n newHandoffIds,\n} from '../utils/handoffInbox';\nimport { useWorkspaceClient, useWorkspaceId } from './internal/workspaceGateway';\nimport type { HandoffRecord } from './useHandoffs';\n\nexport interface HandoffInboxResult {\n items: HandoffRecord[];\n total: number;\n hasMore: boolean;\n /** True only for the first read of a filter; background refreshes keep the list. */\n loading: boolean;\n /** True while a refresh (manual or automatic) is running. */\n refreshing: boolean;\n loadingMore: boolean;\n /** The last failed read. The previously loaded list stays visible alongside it. */\n error: Error | undefined;\n /** Ids that arrived in a background refresh and have not been acknowledged. */\n newIds: ReadonlySet<string>;\n /** Re-reads every loaded page now. */\n refresh: () => Promise<void>;\n loadMore: () => Promise<void>;\n /** Clears the \"new\" marks. */\n acknowledgeNew: () => void;\n}\n\ninterface Page {\n items: HandoffRecord[];\n total: number;\n hasMore: boolean;\n}\n\nfunction toError(cause: unknown): Error {\n const message = extractGraphqlFailureMessage(cause);\n if (message) return new Error(message, { cause });\n if (cause instanceof Error) return cause;\n return new Error('Failed to load the handoff queue', { cause });\n}\n\nconst EMPTY_IDS: ReadonlySet<string> = new Set();\n\n/** The one read running for the current filter; reads never overlap. */\ninterface InFlight {\n /** Unique per read, so a read that settles late can't clear a newer one. */\n token: number;\n kind: 'initial' | 'refresh' | 'more';\n}\n\nexport function useHandoffInbox(options: {\n statuses?: BotmanorHandoffStatus[];\n /** Background refresh interval; defaults to INBOX_REFRESH_MS. */\n refreshMs?: number;\n}): HandoffInboxResult {\n const client = useWorkspaceClient();\n const workspaceId = useWorkspaceId();\n const { statuses } = options;\n const refreshMs = options.refreshMs ?? INBOX_REFRESH_MS;\n const statusKey = statuses?.join(',') ?? '';\n\n const [items, setItems] = useState<HandoffRecord[]>([]);\n const [total, setTotal] = useState(0);\n const [hasMore, setHasMore] = useState(false);\n // Starts as an initial read when there is a workspace, so the first frame\n // shows the loading state instead of an empty queue.\n const [inFlight, setInFlight] = useState<InFlight | null>(() =>\n workspaceId ? { token: 0, kind: 'initial' } : null\n );\n const [error, setError] = useState<Error | undefined>();\n const [newIds, setNewIds] = useState<ReadonlySet<string>>(EMPTY_IDS);\n\n /** Pages loaded for the current filter; a refresh re-reads this many. */\n const pagesRef = useRef(1);\n /** Ids shown after the last successful read of the current filter. */\n const knownRef = useRef<Set<string> | null>(null);\n /** Bumped on every filter change, so a late response of an old filter is dropped. */\n const generationRef = useRef(0);\n /** Token of the read holding the guard; null when none runs. */\n const busyRef = useRef<number | null>(null);\n const tokenRef = useRef(0);\n\n /** Takes the guard for a new read, or returns null when one is running. */\n const begin = useCallback((kind: InFlight['kind']): number | null => {\n if (busyRef.current !== null) return null;\n tokenRef.current += 1;\n const token = tokenRef.current;\n busyRef.current = token;\n setInFlight({ token, kind });\n return token;\n }, []);\n\n /** Releases the guard and the flag, unless a newer read already took them. */\n const settle = useCallback((token: number) => {\n if (busyRef.current === token) busyRef.current = null;\n setInFlight((current) => (current?.token === token ? null : current));\n }, []);\n\n const fetchPage = useCallback(\n async (offset: number): Promise<Page> => {\n const result = await client.query<HandoffQueueQuery>({\n query: HandoffQueueDocument,\n variables: {\n ...(statusKey ? { statuses: statusKey.split(',') } : {}),\n pagination: { limit: INBOX_PAGE_SIZE, offset },\n },\n fetchPolicy: 'network-only',\n });\n const operationError = (result as { error?: unknown }).error;\n if (operationError != null) throw operationError;\n const queue = result.data?.handoffQueue;\n return {\n items: queue?.items ?? [],\n total: queue?.total ?? 0,\n hasMore: queue?.hasMore ?? false,\n };\n },\n [client, statusKey]\n );\n\n const read = useCallback(\n async (mode: 'initial' | 'manual' | 'background') => {\n if (!workspaceId) return;\n const token = begin(mode === 'initial' ? 'initial' : 'refresh');\n if (token === null) return;\n const generation = generationRef.current;\n try {\n // Every loaded page at once: the offsets are known, so one round trip.\n const fetched = await Promise.all(\n Array.from({ length: pagesRef.current }, (_, index) => fetchPage(index * INBOX_PAGE_SIZE))\n );\n // The queue may have shrunk since: stop at the first page that ends it.\n const end = fetched.findIndex((page) => !page.hasMore);\n const pages = end === -1 ? fetched : fetched.slice(0, end + 1);\n if (generation !== generationRef.current) return;\n const merged = mergeHandoffPages(pages.map((page) => page.items));\n const last = pages[pages.length - 1];\n const known = knownRef.current;\n if (known && mode === 'background') {\n const arrived = newHandoffIds(known, merged);\n if (arrived.length > 0) {\n setNewIds((previous) => new Set([...previous, ...arrived]));\n }\n }\n knownRef.current = new Set(merged.map((item) => item.id));\n setItems(merged);\n setTotal(last?.total ?? 0);\n setHasMore(last?.hasMore ?? false);\n setError(undefined);\n } catch (cause) {\n if (generation === generationRef.current) setError(toError(cause));\n } finally {\n // Token-matched, so a read of an old filter can't clear the new one's.\n settle(token);\n }\n },\n [begin, fetchPage, settle, workspaceId]\n );\n\n // A new filter starts over at page one with nothing marked new.\n useEffect(() => {\n generationRef.current += 1;\n // A read of the old filter may still be running; its late result is\n // dropped by the generation check, and the new filter reads right away.\n busyRef.current = null;\n pagesRef.current = 1;\n knownRef.current = null;\n setItems([]);\n setTotal(0);\n setHasMore(false);\n setNewIds(EMPTY_IDS);\n setError(undefined);\n void read('initial');\n }, [read]);\n\n // Background refresh while visible, and on returning to the tab.\n useEffect(() => {\n if (!workspaceId) return undefined;\n const visible = () => globalThis.document?.visibilityState !== 'hidden';\n const timer = globalThis.setInterval(() => {\n if (visible()) void read('background');\n }, refreshMs);\n const onReturn = () => {\n if (visible()) void read('background');\n };\n globalThis.document?.addEventListener('visibilitychange', onReturn);\n globalThis.addEventListener?.('focus', onReturn);\n return () => {\n globalThis.clearInterval(timer);\n globalThis.document?.removeEventListener('visibilitychange', onReturn);\n globalThis.removeEventListener?.('focus', onReturn);\n };\n }, [read, refreshMs, workspaceId]);\n\n const loadMore = useCallback(async () => {\n if (!hasMore) return;\n // The same guard as `read`, so a background refresh can't land after this\n // page and replace it with the shorter list it started with.\n const token = begin('more');\n if (token === null) return;\n const generation = generationRef.current;\n try {\n // Page-aligned, like `read`: deduplication can leave fewer items than\n // pages × page size, and both paths must ask for the same windows.\n const page = await fetchPage(pagesRef.current * INBOX_PAGE_SIZE);\n if (generation !== generationRef.current) return;\n pagesRef.current += 1;\n const merged = mergeHandoffPages([items, page.items]);\n knownRef.current = new Set(merged.map((item) => item.id));\n setItems(merged);\n setTotal(page.total);\n setHasMore(page.hasMore);\n setError(undefined);\n } catch (cause) {\n if (generation === generationRef.current) setError(toError(cause));\n } finally {\n settle(token);\n }\n }, [begin, fetchPage, hasMore, items, settle]);\n\n const refresh = useCallback(() => read('manual'), [read]);\n const acknowledgeNew = useCallback(() => setNewIds(EMPTY_IDS), []);\n\n return {\n items,\n total,\n hasMore,\n loading: inFlight?.kind === 'initial',\n refreshing: inFlight?.kind === 'refresh',\n loadingMore: inFlight?.kind === 'more',\n error,\n newIds,\n refresh,\n loadMore,\n acknowledgeNew,\n };\n}\n"],"mappings":";;;;;;AAuDA,SAASA,EAAQ,GAAuB;CACtC,IAAMC,IAAUC,EAA6BC,CAAK;CAGlD,OAFIF,IAAoB,MAAMA,GAAS,EAAE,SAAM,CAAC,IAC5CE,aAAiB,QAAcA,IACxB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AAJA,EAAS,UAAU,IAAI,IAAIE,EAAO,KAAK,MAASO,EAAK,EAAE,CAAC,GACxD3C,EAASoC,CAAM,GACfjC,EAAS+B,EAAK,KAAK,GACnB7B,EAAW6B,EAAK,OAAO,GACvBzB,EAAS,KAAA,CAAS;EACpB,SAASrB,GAAO;GACd,AAAI0C,MAAef,EAAc,WAASN,EAASxB,EAAQG,CAAK,CAAC;EACnE,UAAU;GACR,EAAOgC,CAAK;EACd;CACF,GAAG;EAACF;EAAOK;EAAWnB;EAASL;EAAOsB;CAAM,CAAC,GAEvC4B,IAAU9B,QAAkBS,EAAK,QAAQ,GAAG,CAACA,CAAI,CAAC,GAClDsB,IAAiB/B,QAAkBR,EAAUtB,CAAS,GAAG,CAAC,CAAC;CAEjE,OAAO;EACL;EACA;EACA;EACA,SAASiB,GAAU,SAAS;EAC5B,YAAYA,GAAU,SAAS;EAC/B,aAAaA,GAAU,SAAS;EAChC;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { AcceptHandoffDocument as e, AssignHandoffDocument as t, HandoffConfigDocument as n,
|
|
2
|
-
import { BotmanorHandoffStatus as
|
|
3
|
-
import { useWorkspaceId as
|
|
4
|
-
import { useMemo as
|
|
1
|
+
import { AcceptHandoffDocument as e, AssignHandoffDocument as t, HandoffConfigDocument as n, HandoffTranscriptDocument as r, RejectHandoffDocument as i, ReleaseHandoffDocument as a, ReplyToHandoffDocument as o, ResolveHandoffDocument as s, UpsertHandoffConfigDocument as c } from "../../generated/wspace-operations.js";
|
|
2
|
+
import { BotmanorHandoffStatus as l } from "../../generated/wspace-types.js";
|
|
3
|
+
import { useWorkspaceId as u, useWorkspaceMutation as d, useWorkspaceQuery as f } from "./internal/workspaceGateway.js";
|
|
4
|
+
import { useMemo as p } from "react";
|
|
5
5
|
// src/botlit/hooks/useHandoffs.ts
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
var m = [
|
|
7
|
+
l.Requested,
|
|
8
|
+
l.Assigned,
|
|
9
|
+
l.Accepted
|
|
10
10
|
];
|
|
11
|
-
function
|
|
12
|
-
return
|
|
11
|
+
function h(e) {
|
|
12
|
+
return m.includes(e);
|
|
13
13
|
}
|
|
14
|
-
function
|
|
15
|
-
let t =
|
|
16
|
-
return
|
|
14
|
+
function g(e) {
|
|
15
|
+
let t = u(), r = p(() => ({ agentId: e ?? "" }), [e]);
|
|
16
|
+
return f({
|
|
17
17
|
document: n,
|
|
18
18
|
variables: r,
|
|
19
19
|
select: (e) => e?.handoffConfig ?? null,
|
|
@@ -22,36 +22,9 @@ function _(e) {
|
|
|
22
22
|
errorMessage: "Failed to load handoff configuration"
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
...n ? { agentId: n } : {},
|
|
29
|
-
...i && i.length > 0 ? { statuses: i } : {},
|
|
30
|
-
pagination: {
|
|
31
|
-
limit: v,
|
|
32
|
-
offset: 0
|
|
33
|
-
}
|
|
34
|
-
}), [n, i]);
|
|
35
|
-
return p({
|
|
36
|
-
document: r,
|
|
37
|
-
variables: a,
|
|
38
|
-
select: (e) => ({
|
|
39
|
-
items: e?.handoffQueue.items ?? [],
|
|
40
|
-
total: e?.handoffQueue.total ?? 0,
|
|
41
|
-
hasMore: e?.handoffQueue.hasMore ?? !1
|
|
42
|
-
}),
|
|
43
|
-
fallback: {
|
|
44
|
-
items: [],
|
|
45
|
-
total: 0,
|
|
46
|
-
hasMore: !1
|
|
47
|
-
},
|
|
48
|
-
enabled: !!t,
|
|
49
|
-
errorMessage: "Failed to load the handoff queue"
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
function b(e) {
|
|
53
|
-
let [t, n] = f({
|
|
54
|
-
document: l,
|
|
25
|
+
function _(e) {
|
|
26
|
+
let [t, n] = d({
|
|
27
|
+
document: c,
|
|
55
28
|
variables: (t) => ({
|
|
56
29
|
agentId: e,
|
|
57
30
|
input: t
|
|
@@ -61,46 +34,46 @@ function b(e) {
|
|
|
61
34
|
});
|
|
62
35
|
return [t, n];
|
|
63
36
|
}
|
|
64
|
-
function
|
|
65
|
-
return
|
|
37
|
+
function v(e, t, n) {
|
|
38
|
+
return d({
|
|
66
39
|
document: e,
|
|
67
40
|
variables: (e) => ({ id: e }),
|
|
68
41
|
select: t,
|
|
69
42
|
errorMessage: n
|
|
70
43
|
});
|
|
71
44
|
}
|
|
72
|
-
function
|
|
73
|
-
return
|
|
45
|
+
function y() {
|
|
46
|
+
return v(e, (e) => e?.acceptHandoff, "Failed to accept the handoff");
|
|
74
47
|
}
|
|
75
|
-
function
|
|
76
|
-
return
|
|
48
|
+
function b() {
|
|
49
|
+
return v(a, (e) => e?.releaseHandoff, "Failed to release the handoff");
|
|
77
50
|
}
|
|
78
|
-
function
|
|
79
|
-
return
|
|
51
|
+
function x() {
|
|
52
|
+
return v(s, (e) => e?.resolveHandoff, "Failed to resolve the handoff");
|
|
80
53
|
}
|
|
81
|
-
function
|
|
82
|
-
return
|
|
54
|
+
function S() {
|
|
55
|
+
return v(i, (e) => e?.rejectHandoff, "Failed to reject the handoff");
|
|
83
56
|
}
|
|
84
|
-
function
|
|
85
|
-
return
|
|
57
|
+
function C() {
|
|
58
|
+
return d({
|
|
86
59
|
document: t,
|
|
87
60
|
variables: (e) => ({ ...e }),
|
|
88
61
|
select: (e) => e?.assignHandoff,
|
|
89
62
|
errorMessage: "Failed to assign the handoff"
|
|
90
63
|
});
|
|
91
64
|
}
|
|
92
|
-
function
|
|
93
|
-
return
|
|
94
|
-
document:
|
|
65
|
+
function w() {
|
|
66
|
+
return d({
|
|
67
|
+
document: o,
|
|
95
68
|
variables: (e) => ({ ...e }),
|
|
96
69
|
select: (e) => e?.replyToHandoff,
|
|
97
70
|
errorMessage: "Failed to send the reply"
|
|
98
71
|
});
|
|
99
72
|
}
|
|
100
|
-
function
|
|
101
|
-
let t =
|
|
102
|
-
return
|
|
103
|
-
document:
|
|
73
|
+
function T(e) {
|
|
74
|
+
let t = u(), n = p(() => ({ id: e ?? "" }), [e]);
|
|
75
|
+
return f({
|
|
76
|
+
document: r,
|
|
104
77
|
variables: n,
|
|
105
78
|
select: (e) => e?.handoffTranscript ?? [],
|
|
106
79
|
fallback: [],
|
|
@@ -108,6 +81,6 @@ function O(e) {
|
|
|
108
81
|
errorMessage: "Failed to load the conversation"
|
|
109
82
|
});
|
|
110
83
|
}
|
|
111
|
-
export {
|
|
84
|
+
export { m as ACTIVE_HANDOFF_STATUSES, h as isActiveHandoff, y as useAcceptHandoff, C as useAssignHandoff, g as useHandoffConfig, T as useHandoffTranscript, S as useRejectHandoff, b as useReleaseHandoff, w as useReplyToHandoff, x as useResolveHandoff, _ as useUpsertHandoffConfig };
|
|
112
85
|
|
|
113
86
|
//# sourceMappingURL=useHandoffs.js.map
|
|
@@ -1 +1 @@
|
|
|
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,OA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,GAAQP,KAAeiC;EAChC,cAAc;CAChB,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"useHandoffs.js","names":["ACTIVE_HANDOFF_STATUSES","BotmanorHandoffStatus","isActiveHandoff","status","useHandoffConfig","workspaceId","useWorkspaceId","variables","useMemo","agentId","useWorkspaceQuery","HandoffConfigDocument","data","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,GA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ACV;EACA,SAAS,MAAStB,GAAM,qBAAqB,CAAC;EAC9C,UAAU,CAAC;EACX,SAAS,GAAQP,KAAe4B;EAChC,cAAc;CAChB,CAAC;AACH"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { BotmanorMyIntegrationConnectionsQuery } from '../../generated/wspace-operations';
|
|
2
|
+
import { QueryResult } from './internal/workspaceGateway';
|
|
3
|
+
export type MyIntegrationConnection = NonNullable<BotmanorMyIntegrationConnectionsQuery['getConnections']>['items'][number];
|
|
4
|
+
export declare function useMyIntegrationConnections(enabled: boolean): QueryResult<MyIntegrationConnection[]>;
|