@cuylabs/channel-slack 0.9.0 → 0.11.0
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/README.md +15 -2
- package/dist/adapter/index.d.ts +53 -0
- package/dist/adapter/index.js +13 -0
- package/dist/app-surface.d.ts +86 -0
- package/dist/app-surface.js +15 -0
- package/dist/app.d.ts +58 -0
- package/dist/app.js +86 -0
- package/dist/artifacts/index.d.ts +57 -3
- package/dist/artifacts/index.js +88 -0
- package/dist/assistant/index.d.ts +18 -53
- package/dist/assistant/index.js +15 -184
- package/dist/bolt-app-BM0tiL7c.d.ts +49 -0
- package/dist/{chunk-TWJGVDA2.js → chunk-37RN2YUI.js} +88 -1
- package/dist/chunk-IAQXQESO.js +1008 -0
- package/dist/chunk-LFQCINHI.js +187 -0
- package/dist/chunk-Q6YX7HHK.js +1062 -0
- package/dist/chunk-RHOIVQLD.js +127 -0
- package/dist/chunk-RTDLIYEE.js +446 -0
- package/dist/core.d.ts +5 -201
- package/dist/core.js +10 -12
- package/dist/feedback/index.d.ts +2 -2
- package/dist/feedback/index.js +5 -120
- package/dist/formatting-C-kwQseI.d.ts +25 -0
- package/dist/index.d.ts +8 -1
- package/dist/index.js +18 -12
- package/dist/interactive/index.d.ts +4 -91
- package/dist/options-B0xQCaez.d.ts +221 -0
- package/dist/options-DQacQDmD.d.ts +368 -0
- package/dist/runtime/index.d.ts +46 -0
- package/dist/runtime/index.js +10 -0
- package/dist/socket.d.ts +142 -0
- package/dist/socket.js +77 -0
- package/dist/transports/index.d.ts +2 -1
- package/dist/transports/socket/index.d.ts +4 -49
- package/dist/turn-BGAXddH_.d.ts +178 -0
- package/dist/types-Cywfj8Mj.d.ts +91 -0
- package/dist/types-wLZzyI9r.d.ts +375 -0
- package/docs/reference/exports.md +5 -1
- package/package.json +28 -3
- package/dist/chunk-ISOMBQXE.js +0 -89
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createSlackAssistantBridge
|
|
3
|
+
} from "./chunk-Q6YX7HHK.js";
|
|
4
|
+
import {
|
|
5
|
+
createSlackFeedbackBlock
|
|
6
|
+
} from "./chunk-RHOIVQLD.js";
|
|
7
|
+
import {
|
|
8
|
+
createSlackChannelAdapter
|
|
9
|
+
} from "./chunk-RTDLIYEE.js";
|
|
10
|
+
|
|
11
|
+
// src/app-surface.ts
|
|
12
|
+
var DEFAULT_TIMEOUT_MS = 12e4;
|
|
13
|
+
var DEFAULT_STREAM_ERROR_MESSAGE = "I ran into an error while preparing this answer. Please try again.";
|
|
14
|
+
function installSlackAppSurface(boltApp, options) {
|
|
15
|
+
const {
|
|
16
|
+
respondToMentions,
|
|
17
|
+
respondToMessages,
|
|
18
|
+
respondToChannelMessages,
|
|
19
|
+
resolveMessage,
|
|
20
|
+
feedback: feedbackOption,
|
|
21
|
+
onFeedback,
|
|
22
|
+
timeoutMs,
|
|
23
|
+
logger,
|
|
24
|
+
source,
|
|
25
|
+
prepareTurn,
|
|
26
|
+
resolveSession,
|
|
27
|
+
interactive,
|
|
28
|
+
viewWorkflows,
|
|
29
|
+
...assistantBridgeOptions
|
|
30
|
+
} = options;
|
|
31
|
+
const feedbackConfig = feedbackOption === false ? void 0 : feedbackOption ?? (onFeedback ? { onFeedback } : {});
|
|
32
|
+
const assistantFeedback = feedbackOption === false ? false : feedbackConfig;
|
|
33
|
+
const feedbackBlock = feedbackConfig ? createSlackFeedbackBlock(feedbackConfig) : void 0;
|
|
34
|
+
const formatStreamError = assistantBridgeOptions.formatStreamError ?? (() => DEFAULT_STREAM_ERROR_MESSAGE);
|
|
35
|
+
const formatting = assistantBridgeOptions.formatChatMarkdown;
|
|
36
|
+
const channelSource = createErrorTranslatingSource(source, formatStreamError);
|
|
37
|
+
const channelFinalArgs = mergeChatStreamFinalArgs(
|
|
38
|
+
assistantBridgeOptions.chatStreamFinalArgs,
|
|
39
|
+
feedbackBlock
|
|
40
|
+
);
|
|
41
|
+
const bridge = createSlackAssistantBridge({
|
|
42
|
+
...assistantBridgeOptions,
|
|
43
|
+
source,
|
|
44
|
+
...assistantFeedback !== void 0 ? { feedback: assistantFeedback } : {},
|
|
45
|
+
...timeoutMs !== void 0 ? { timeoutMs } : {},
|
|
46
|
+
...logger ? { logger } : {},
|
|
47
|
+
...prepareTurn ? { prepareTurn: toAssistantPrepareTurn(prepareTurn) } : {},
|
|
48
|
+
...resolveSession ? { resolveSession: toAssistantResolveSession(resolveSession) } : {},
|
|
49
|
+
...interactive ? { handleInteractiveRequest: interactive.handleInteractiveRequest } : {}
|
|
50
|
+
});
|
|
51
|
+
bridge.install(boltApp);
|
|
52
|
+
const channelAdapter = createSlackChannelAdapter({
|
|
53
|
+
source: channelSource,
|
|
54
|
+
sessionStrategy: assistantBridgeOptions.sessionStrategy,
|
|
55
|
+
...resolveSession ? { resolveSession } : {},
|
|
56
|
+
...prepareTurn ? { prepareTurn } : {},
|
|
57
|
+
...interactive ? { handleInteractiveRequest: interactive.handleInteractiveRequest } : {},
|
|
58
|
+
streamingMode: "chat-stream",
|
|
59
|
+
showReasoning: assistantBridgeOptions.showReasoning,
|
|
60
|
+
showToolUsage: assistantBridgeOptions.showToolUsage,
|
|
61
|
+
showSubagentToolUsage: assistantBridgeOptions.showSubagentToolUsage,
|
|
62
|
+
showSubagentResultInTask: assistantBridgeOptions.showSubagentResultInTask,
|
|
63
|
+
formatToolTitle: assistantBridgeOptions.formatToolTitle,
|
|
64
|
+
formatToolUpdate: assistantBridgeOptions.formatToolUpdate,
|
|
65
|
+
formatToolDetails: assistantBridgeOptions.formatToolDetails,
|
|
66
|
+
formatToolResultOutput: assistantBridgeOptions.formatToolResultOutput,
|
|
67
|
+
formatToolError: assistantBridgeOptions.formatToolError,
|
|
68
|
+
formatReasoningUpdate: assistantBridgeOptions.formatReasoningUpdate,
|
|
69
|
+
chatStreamBufferSize: assistantBridgeOptions.chatStreamBufferSize,
|
|
70
|
+
chatStreamStartArgs: {
|
|
71
|
+
...assistantBridgeOptions.chatStreamStartArgs ?? {},
|
|
72
|
+
task_display_mode: assistantBridgeOptions.taskDisplayMode ?? "timeline"
|
|
73
|
+
},
|
|
74
|
+
publishFinalResponseArtifact: assistantBridgeOptions.publishFinalResponseArtifact,
|
|
75
|
+
finalResponseArtifactMode: assistantBridgeOptions.finalResponseArtifactMode,
|
|
76
|
+
finalResponseArtifactStreamThreshold: assistantBridgeOptions.finalResponseArtifactStreamThreshold,
|
|
77
|
+
formatFinalResponseArtifactContinuationNotice: assistantBridgeOptions.formatFinalResponseArtifactContinuationNotice,
|
|
78
|
+
formatFinalResponseArtifactMessage: assistantBridgeOptions.formatFinalResponseArtifactMessage,
|
|
79
|
+
onFinalResponseArtifactError: assistantBridgeOptions.onFinalResponseArtifactError,
|
|
80
|
+
...typeof assistantBridgeOptions.initialStatus === "object" && assistantBridgeOptions.initialStatus !== null ? { initialStatus: assistantBridgeOptions.initialStatus } : {},
|
|
81
|
+
...formatting?.formatChatMarkdown !== void 0 ? { formatChatMarkdown: formatting.formatChatMarkdown } : {},
|
|
82
|
+
...formatting?.formatMessageText ? { formatMessageText: formatting.formatMessageText } : {},
|
|
83
|
+
timeout: timeoutMs ?? DEFAULT_TIMEOUT_MS,
|
|
84
|
+
respondToMentions: respondToMentions !== false,
|
|
85
|
+
respondToMessages: respondToMessages !== false,
|
|
86
|
+
respondToChannelMessages: respondToChannelMessages === true,
|
|
87
|
+
...resolveMessage ? { resolveMessage } : {},
|
|
88
|
+
chatStreamFinalArgs: channelFinalArgs,
|
|
89
|
+
...logger ? { logger } : {},
|
|
90
|
+
...logger ? {
|
|
91
|
+
onError: async (error, info) => {
|
|
92
|
+
logger.warn?.("slack channel turn failed", {
|
|
93
|
+
error: formatErrorForLog(error),
|
|
94
|
+
channelId: info.channelId,
|
|
95
|
+
userId: info.userId
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
} : {}
|
|
99
|
+
});
|
|
100
|
+
channelAdapter.mount(boltApp);
|
|
101
|
+
interactive?.install(boltApp);
|
|
102
|
+
viewWorkflows?.install(boltApp);
|
|
103
|
+
return { bridge };
|
|
104
|
+
}
|
|
105
|
+
function mergeChatStreamFinalArgs(base, feedbackBlock) {
|
|
106
|
+
if (!base && !feedbackBlock) {
|
|
107
|
+
return void 0;
|
|
108
|
+
}
|
|
109
|
+
const configuredBlocks = Array.isArray(base?.blocks) ? base.blocks : [];
|
|
110
|
+
const blocks = feedbackBlock ? [...configuredBlocks, feedbackBlock] : configuredBlocks;
|
|
111
|
+
return {
|
|
112
|
+
...base ?? {},
|
|
113
|
+
...blocks.length > 0 ? { blocks } : {}
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function toAssistantPrepareTurn(prepareTurn) {
|
|
117
|
+
return (request) => prepareTurn(toAppTurnRequest(request));
|
|
118
|
+
}
|
|
119
|
+
function toAssistantResolveSession(resolveSession) {
|
|
120
|
+
return (request) => resolveSession(toAppTurnRequest(request));
|
|
121
|
+
}
|
|
122
|
+
function toAppTurnRequest(request) {
|
|
123
|
+
const user = {
|
|
124
|
+
userId: request.message.userId,
|
|
125
|
+
channelId: request.message.channelId,
|
|
126
|
+
teamId: request.message.teamId ?? request.auth.teamId,
|
|
127
|
+
threadTs: request.message.threadTs,
|
|
128
|
+
messageTs: request.message.messageTs
|
|
129
|
+
};
|
|
130
|
+
return {
|
|
131
|
+
slackActivity: request.message,
|
|
132
|
+
user,
|
|
133
|
+
sessionId: request.sessionId,
|
|
134
|
+
message: request.message.text,
|
|
135
|
+
auth: request.auth,
|
|
136
|
+
threadContext: request.threadContext,
|
|
137
|
+
assistant: request.assistant,
|
|
138
|
+
client: request.client,
|
|
139
|
+
rawArgs: request.rawArgs
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
function createErrorTranslatingSource(source, formatStreamError) {
|
|
143
|
+
return {
|
|
144
|
+
chat(sessionId, message, options) {
|
|
145
|
+
const events = source.chat(sessionId, message, options);
|
|
146
|
+
return translateErrors(events, formatStreamError);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
async function* translateErrors(events, formatStreamError) {
|
|
151
|
+
try {
|
|
152
|
+
for await (const event of events) {
|
|
153
|
+
if (event.type === "error") {
|
|
154
|
+
yield {
|
|
155
|
+
type: "text-delta",
|
|
156
|
+
text: `
|
|
157
|
+
|
|
158
|
+
${formatStreamError(toError(event.error))}`
|
|
159
|
+
};
|
|
160
|
+
yield { type: "complete" };
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
yield event;
|
|
164
|
+
}
|
|
165
|
+
} catch (error) {
|
|
166
|
+
yield {
|
|
167
|
+
type: "text-delta",
|
|
168
|
+
text: `
|
|
169
|
+
|
|
170
|
+
${formatStreamError(toError(error))}`
|
|
171
|
+
};
|
|
172
|
+
yield { type: "complete" };
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
function toError(value) {
|
|
176
|
+
return value instanceof Error ? value : new Error(String(value));
|
|
177
|
+
}
|
|
178
|
+
function formatErrorForLog(error) {
|
|
179
|
+
if (error instanceof Error) {
|
|
180
|
+
return error.stack ?? error.message;
|
|
181
|
+
}
|
|
182
|
+
return String(error);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export {
|
|
186
|
+
installSlackAppSurface
|
|
187
|
+
};
|