Spaces:
Running
Running
Staging: verified Slack identity and read-only sessions (51e9935d)
Browse files- src/lib/server/slack/bot.ts +25 -22
src/lib/server/slack/bot.ts
CHANGED
|
@@ -1018,33 +1018,36 @@ export class MlSlackBot {
|
|
| 1018 |
const budget = conv?.mlBudget;
|
| 1019 |
const text = `**Session status**\n\n${status}\n馃捇 Jobs ${formatMicroUsd(budget?.spentMicroUsd ?? 0)} spent 路 ${formatMicroUsd(budget ? reservedMicroUsd(budget) : 0)} reserved 路 ${formatMicroUsd(budget?.totalMicroUsd ?? 0)} budget`;
|
| 1020 |
const viewUrl = chatLink(thread) ?? viewerLink(thread.conversationId.toHexString());
|
| 1021 |
-
const
|
| 1022 |
-
.
|
| 1023 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1024 |
if (delivery?.digest === digest) return;
|
| 1025 |
const payload = {
|
| 1026 |
channel: thread.channel,
|
| 1027 |
text,
|
| 1028 |
blocks: [
|
| 1029 |
-
...messageBlocks(text,
|
| 1030 |
-
...(
|
| 1031 |
-
? [
|
| 1032 |
-
{
|
| 1033 |
-
type: "actions" as const,
|
| 1034 |
-
elements: [
|
| 1035 |
-
{
|
| 1036 |
-
type: "button" as const,
|
| 1037 |
-
action_id: "ml_intern_view",
|
| 1038 |
-
text: {
|
| 1039 |
-
type: "plain_text" as const,
|
| 1040 |
-
text: thread.hfUserId ? "Open in HuggingChat" : "Open session",
|
| 1041 |
-
},
|
| 1042 |
-
url: viewUrl,
|
| 1043 |
-
},
|
| 1044 |
-
],
|
| 1045 |
-
},
|
| 1046 |
-
]
|
| 1047 |
-
: []),
|
| 1048 |
{ type: "divider" as const },
|
| 1049 |
],
|
| 1050 |
parse: "none" as const,
|
|
|
|
| 1018 |
const budget = conv?.mlBudget;
|
| 1019 |
const text = `**Session status**\n\n${status}\n馃捇 Jobs ${formatMicroUsd(budget?.spentMicroUsd ?? 0)} spent 路 ${formatMicroUsd(budget ? reservedMicroUsd(budget) : 0)} reserved 路 ${formatMicroUsd(budget?.totalMicroUsd ?? 0)} budget`;
|
| 1020 |
const viewUrl = chatLink(thread) ?? viewerLink(thread.conversationId.toHexString());
|
| 1021 |
+
const buttons = [
|
| 1022 |
+
...actions.map((action) => ({
|
| 1023 |
+
type: "button" as const,
|
| 1024 |
+
action_id: action.id,
|
| 1025 |
+
text: { type: "plain_text" as const, text: action.label },
|
| 1026 |
+
value: action.value,
|
| 1027 |
+
...(action.id === STOP_ACTION ? { style: "danger" as const } : {}),
|
| 1028 |
+
})),
|
| 1029 |
+
...(viewUrl
|
| 1030 |
+
? [
|
| 1031 |
+
{
|
| 1032 |
+
type: "button" as const,
|
| 1033 |
+
action_id: "ml_intern_view",
|
| 1034 |
+
text: {
|
| 1035 |
+
type: "plain_text" as const,
|
| 1036 |
+
text: thread.hfUserId ? "Open in HuggingChat" : "Open session",
|
| 1037 |
+
},
|
| 1038 |
+
url: viewUrl,
|
| 1039 |
+
},
|
| 1040 |
+
]
|
| 1041 |
+
: []),
|
| 1042 |
+
];
|
| 1043 |
+
const digest = createHash("sha256").update(JSON.stringify({ text, buttons })).digest("hex");
|
| 1044 |
if (delivery?.digest === digest) return;
|
| 1045 |
const payload = {
|
| 1046 |
channel: thread.channel,
|
| 1047 |
text,
|
| 1048 |
blocks: [
|
| 1049 |
+
...messageBlocks(text, []),
|
| 1050 |
+
...(buttons.length ? [{ type: "actions" as const, elements: buttons }] : []),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1051 |
{ type: "divider" as const },
|
| 1052 |
],
|
| 1053 |
parse: "none" as const,
|