@cuylabs/channel-m365-slack-agent-core 0.3.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/LICENSE +201 -0
- package/README.md +32 -0
- package/dist/index.d.ts +230 -0
- package/dist/index.js +290 -0
- package/docs/m365-slack.md +139 -0
- package/package.json +74 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# @cuylabs/channel-m365-slack-agent-core
|
|
2
|
+
|
|
3
|
+
M365/Azure Bot Service Slack transport for `@cuylabs/agent-core`.
|
|
4
|
+
|
|
5
|
+
Use this package when Slack traffic should arrive through Azure Bot Service and
|
|
6
|
+
the Microsoft Agents hosting stack instead of Slack Bolt.
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
import { mountM365SlackAgent } from "@cuylabs/channel-m365-slack-agent-core";
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Install:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pnpm add @cuylabs/channel-m365-slack-agent-core @cuylabs/channel-m365-slack @cuylabs/channel-slack @cuylabs/channel-m365-agent-core @microsoft/agents-hosting @microsoft/agents-activity express
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
This package depends on:
|
|
19
|
+
|
|
20
|
+
- `@cuylabs/channel-m365-slack` for Slack payload parsing from M365
|
|
21
|
+
`channelData`
|
|
22
|
+
- `@cuylabs/channel-slack` for shared Slack formatting, session, and ambient
|
|
23
|
+
context primitives
|
|
24
|
+
- `@cuylabs/channel-m365-agent-core` for the Microsoft Agents / CloudAdapter base
|
|
25
|
+
transport
|
|
26
|
+
- `@microsoft/agents-*` peers for runtime hosting types and adapters
|
|
27
|
+
|
|
28
|
+
Internally this package imports only the
|
|
29
|
+
`@cuylabs/channel-slack/core` subpath, so it does not depend on Bolt,
|
|
30
|
+
Socket Mode, or direct Slack runtime code.
|
|
31
|
+
|
|
32
|
+
See [docs/m365-slack.md](./docs/m365-slack.md) for setup and behavior details.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { M365ChannelAdapter, M365ChannelOptions, M365TurnRequestContext, M365TurnPreparation } from '@cuylabs/channel-m365-agent-core';
|
|
2
|
+
import { TurnContext, AuthConfiguration, CloudAdapter } from '@microsoft/agents-hosting';
|
|
3
|
+
import { SlackMessageFormattingOptions, SlackActivityInfo, SlackAmbientTurnContext } from '@cuylabs/channel-slack/core';
|
|
4
|
+
import { Server } from 'node:http';
|
|
5
|
+
import { AgentTurnSource } from '@cuylabs/agent-core';
|
|
6
|
+
import { Application } from 'express';
|
|
7
|
+
import { SlackM365ChannelData, SlackM365MessagePayload } from '@cuylabs/channel-m365-slack';
|
|
8
|
+
export { SlackM365ChannelData, SlackM365MessagePayload, parseSlackM365Activity, parseSlackM365ChannelData } from '@cuylabs/channel-m365-slack';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* M365 Slack Channel Adapter
|
|
12
|
+
*
|
|
13
|
+
* Extends `@cuylabs/channel-m365-agent-core` to add Slack-specific parsing and
|
|
14
|
+
* ambient context when the agent is deployed via the Azure Bot Service Slack
|
|
15
|
+
* channel connector.
|
|
16
|
+
*
|
|
17
|
+
* This adapter is the Slack equivalent of `createTeamsChannelAdapter`:
|
|
18
|
+
* - It wraps `createM365ChannelAdapter` — you still use `CloudAdapter` and
|
|
19
|
+
* `authorizeJWT`, and activities arrive as regular Bot Framework activities.
|
|
20
|
+
* - It enriches each turn with a parsed `SlackActivityInfo` from the
|
|
21
|
+
* `activity.channelData.SlackMessage` payload that ABS embeds.
|
|
22
|
+
* - It stores Slack-specific scope attributes for observability.
|
|
23
|
+
* - It exposes `currentM365SlackTurnContext()` inside tools and middleware.
|
|
24
|
+
*
|
|
25
|
+
* ## When to use this vs `createSlackChannelAdapter`
|
|
26
|
+
*
|
|
27
|
+
* | | `createSlackChannelAdapter` | `createM365SlackChannelAdapter` |
|
|
28
|
+
* |---|---|---|
|
|
29
|
+
* | Transport | @slack/bolt directly | CloudAdapter + ABS Slack channel |
|
|
30
|
+
* | Azure Bot registration | Not needed | Required |
|
|
31
|
+
* | Shared Teams + Slack Azure reg | No | Yes |
|
|
32
|
+
* | Slack Block Kit / native API | Full control | Limited (ABS normalises) |
|
|
33
|
+
* | Auth/verification | Bolt signing secret | Entra JWT |
|
|
34
|
+
*
|
|
35
|
+
* ## Assistant pane limitation
|
|
36
|
+
*
|
|
37
|
+
* Azure Bot Service's Slack channel connector relays Slack `message` events
|
|
38
|
+
* as Bot Framework activities, but it does **not** relay
|
|
39
|
+
* `assistant_thread_started` / `assistant_thread_context_changed` events,
|
|
40
|
+
* and it does not surface Slack's assistant-pane utilities
|
|
41
|
+
* (`assistant.threads.setStatus` / `setSuggestedPrompts` / `setTitle`).
|
|
42
|
+
*
|
|
43
|
+
* If you need the modern Slack Assistant UX (status pane, suggested prompts,
|
|
44
|
+
* `chatStream` with `task_display_mode`, feedback blocks), use the direct
|
|
45
|
+
* Slack adapter package. Plain DM and `app_mention` flows work fine through
|
|
46
|
+
* this M365-backed path.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { mountM365SlackAgent } from "@cuylabs/channel-m365-slack-agent-core";
|
|
51
|
+
*
|
|
52
|
+
* await mountM365SlackAgent(agent);
|
|
53
|
+
* // → listens on /api/messages with CloudAdapter auth
|
|
54
|
+
* // Requires the same env vars as channel-m365-agent-core
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
interface M365SlackTurnRequestContext extends M365TurnRequestContext {
|
|
59
|
+
/** Parsed Slack activity metadata (when channelId === "slack") */
|
|
60
|
+
slack: SlackActivityInfo;
|
|
61
|
+
}
|
|
62
|
+
type M365SlackTurnPreparation = M365TurnPreparation;
|
|
63
|
+
interface M365SlackSessionRequestContext {
|
|
64
|
+
/** Raw M365 turn context for the active ABS Slack activity. */
|
|
65
|
+
turnContext: TurnContext;
|
|
66
|
+
/** Parsed Slack activity metadata. */
|
|
67
|
+
slack: SlackActivityInfo;
|
|
68
|
+
/** M365 conversation ID from the activity. */
|
|
69
|
+
conversationId: string;
|
|
70
|
+
/** M365 channel ID, normally `"slack"`. */
|
|
71
|
+
channelId: string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Options for the M365-backed Slack channel adapter.
|
|
75
|
+
*
|
|
76
|
+
* Identical to `M365ChannelOptions` with one addition: `prepareTurn` receives
|
|
77
|
+
* a `M365SlackTurnRequestContext` that includes the parsed `slack` metadata.
|
|
78
|
+
*/
|
|
79
|
+
interface M365SlackChannelOptions extends Omit<M365ChannelOptions, "prepareTurn">, SlackMessageFormattingOptions {
|
|
80
|
+
/**
|
|
81
|
+
* Prepare an agent turn from the full Slack + M365 request context.
|
|
82
|
+
*
|
|
83
|
+
* Called for every message. Returns an optional system override, scope
|
|
84
|
+
* attributes, or per-turn ambient context.
|
|
85
|
+
*/
|
|
86
|
+
prepareTurn?: (request: M365SlackTurnRequestContext) => M365SlackTurnPreparation | Promise<M365SlackTurnPreparation>;
|
|
87
|
+
/**
|
|
88
|
+
* Resolve the agent-core session ID from parsed Slack metadata.
|
|
89
|
+
*
|
|
90
|
+
* Use this for thread-aware Slack-via-ABS sessions. When omitted, the
|
|
91
|
+
* adapter preserves the base M365 `conversation-id` session behavior unless
|
|
92
|
+
* `sessionStrategy` / `resolveSessionId` are configured directly.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* resolveSession: ({ slack }) => resolveM365SlackThreadSessionId(slack)
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
resolveSession?: (request: M365SlackSessionRequestContext) => string | Promise<string>;
|
|
100
|
+
/**
|
|
101
|
+
* Hook called for every turn, before the adapter's own handling.
|
|
102
|
+
*
|
|
103
|
+
* Return `next()` to continue normal processing.
|
|
104
|
+
*/
|
|
105
|
+
onTurn?: (context: TurnContext, next: () => Promise<void>) => Promise<void>;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* The adapter returned by `createM365SlackChannelAdapter`.
|
|
109
|
+
*
|
|
110
|
+
* Exposes the underlying `m365` base adapter for advanced use cases.
|
|
111
|
+
*/
|
|
112
|
+
interface M365SlackChannelAdapter extends M365ChannelAdapter {
|
|
113
|
+
/**
|
|
114
|
+
* The underlying base M365 channel adapter.
|
|
115
|
+
*/
|
|
116
|
+
m365: M365ChannelAdapter;
|
|
117
|
+
}
|
|
118
|
+
declare function createM365SlackChannelAdapter(options: M365SlackChannelOptions): M365SlackChannelAdapter;
|
|
119
|
+
/**
|
|
120
|
+
* Read the parsed Slack activity info from the current M365 turn context.
|
|
121
|
+
*
|
|
122
|
+
* Works inside tools and middleware when using `createM365SlackChannelAdapter`.
|
|
123
|
+
* Returns `undefined` when called outside a Slack turn.
|
|
124
|
+
*
|
|
125
|
+
* ```ts
|
|
126
|
+
* import { currentM365SlackTurnContext } from "@cuylabs/channel-m365-slack-agent-core";
|
|
127
|
+
*
|
|
128
|
+
* const ctx = currentM365SlackTurnContext();
|
|
129
|
+
* ctx?.slack.channelId; // "C01234..."
|
|
130
|
+
* ctx?.slack.threadTs; // "1617000000.000100"
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
declare function currentM365SlackTurnContext(): Readonly<SlackAmbientTurnContext> | undefined;
|
|
134
|
+
declare function resolveM365SlackThreadSessionId(slack: SlackActivityInfo): string;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Express integration for the M365-backed Slack channel adapter.
|
|
138
|
+
*
|
|
139
|
+
* Mirrors the Teams mounting style — uses `CloudAdapter`
|
|
140
|
+
* with Entra JWT auth, and serves the standard `/api/messages` route.
|
|
141
|
+
*
|
|
142
|
+
* Requires the same env vars as `mountM365Agent`:
|
|
143
|
+
* - `MicrosoftAppId`
|
|
144
|
+
* - `MicrosoftAppPassword`
|
|
145
|
+
* - `MicrosoftAppTenantId` (optional for multi-tenant)
|
|
146
|
+
*
|
|
147
|
+
* In Azure Bot Service you configure the Slack channel connector separately
|
|
148
|
+
* in the Azure portal — the agent code itself doesn't change.
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```ts
|
|
152
|
+
* import { createAgent } from "@cuylabs/agent-core";
|
|
153
|
+
* import { anthropic } from "@ai-sdk/anthropic";
|
|
154
|
+
* import { mountM365SlackAgent } from "@cuylabs/channel-m365-slack-agent-core";
|
|
155
|
+
*
|
|
156
|
+
* const agent = createAgent({ model: anthropic("claude-sonnet-4-20250514") });
|
|
157
|
+
* await mountM365SlackAgent(agent);
|
|
158
|
+
* // → CloudAdapter listening on port 3978 at /api/messages
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
|
|
162
|
+
interface MountM365SlackAgentOptions extends Omit<M365SlackChannelOptions, "agent" | "source"> {
|
|
163
|
+
/**
|
|
164
|
+
* Route path for the messages endpoint.
|
|
165
|
+
* @default "/api/messages"
|
|
166
|
+
*/
|
|
167
|
+
path?: string;
|
|
168
|
+
/**
|
|
169
|
+
* M365 auth configuration. If not provided, loaded from environment
|
|
170
|
+
* variables (`MicrosoftAppId`, `MicrosoftAppPassword`, `MicrosoftAppTenantId`).
|
|
171
|
+
*/
|
|
172
|
+
authConfig?: AuthConfiguration;
|
|
173
|
+
/**
|
|
174
|
+
* Port to listen on.
|
|
175
|
+
* Set to `null` to skip `app.listen()` — caller manages the server.
|
|
176
|
+
* @default process.env.PORT || 3978
|
|
177
|
+
*/
|
|
178
|
+
port?: number | null;
|
|
179
|
+
/**
|
|
180
|
+
* Optional host/interface passed to `app.listen(port, host)`.
|
|
181
|
+
*/
|
|
182
|
+
host?: string;
|
|
183
|
+
/**
|
|
184
|
+
* Pre-existing CloudAdapter instance.
|
|
185
|
+
*/
|
|
186
|
+
adapter?: CloudAdapter;
|
|
187
|
+
/**
|
|
188
|
+
* Pre-existing Express app.
|
|
189
|
+
*/
|
|
190
|
+
app?: Application;
|
|
191
|
+
}
|
|
192
|
+
interface MountM365SlackAgentResult {
|
|
193
|
+
/** The Express application */
|
|
194
|
+
app: Application;
|
|
195
|
+
/** The M365 Slack channel adapter */
|
|
196
|
+
channelAdapter: ReturnType<typeof createM365SlackChannelAdapter>;
|
|
197
|
+
/** The CloudAdapter instance */
|
|
198
|
+
cloudAdapter: CloudAdapter;
|
|
199
|
+
/** The Node HTTP server when `listen()` was started */
|
|
200
|
+
server?: Server;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Mount an agent-core-compatible turn source as a Slack bot via Azure Bot
|
|
204
|
+
* Service + CloudAdapter.
|
|
205
|
+
*
|
|
206
|
+
* This is identical to `mountTeamsAgent` in structure — it mounts a
|
|
207
|
+
* `POST /api/messages` route with Entra JWT auth. Azure Bot Service's Slack
|
|
208
|
+
* channel connector handles translating Slack events into Activities before
|
|
209
|
+
* they reach this endpoint.
|
|
210
|
+
*/
|
|
211
|
+
declare function mountM365SlackAgent(source: AgentTurnSource, options?: MountM365SlackAgentOptions): Promise<MountM365SlackAgentResult>;
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Slack channelData parsing for Azure Bot Service / Microsoft 365 Activity
|
|
215
|
+
* payloads.
|
|
216
|
+
*
|
|
217
|
+
* The parser itself lives in `@cuylabs/channel-m365-slack`; this adapter keeps
|
|
218
|
+
* the `TurnContext` convenience wrapper used by the agent-core runtime layer.
|
|
219
|
+
*/
|
|
220
|
+
|
|
221
|
+
type SlackABSMessagePayload = SlackM365MessagePayload;
|
|
222
|
+
type SlackABSChannelData = SlackM365ChannelData;
|
|
223
|
+
declare function parseSlackChannelData(channelData: unknown): SlackABSChannelData | undefined;
|
|
224
|
+
/**
|
|
225
|
+
* Parse a `TurnContext` whose activity arrived via the Azure Bot Service Slack
|
|
226
|
+
* channel into a `SlackActivityInfo`.
|
|
227
|
+
*/
|
|
228
|
+
declare function parseSlackActivity(context: TurnContext): SlackActivityInfo | undefined;
|
|
229
|
+
|
|
230
|
+
export { type M365SlackChannelAdapter, type M365SlackChannelOptions, type M365SlackSessionRequestContext, type M365SlackTurnPreparation, type M365SlackTurnRequestContext, type MountM365SlackAgentOptions, type MountM365SlackAgentResult, type SlackABSChannelData, type SlackABSMessagePayload, createM365SlackChannelAdapter, currentM365SlackTurnContext, mountM365SlackAgent, parseSlackActivity, parseSlackChannelData, resolveM365SlackThreadSessionId };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
// src/adapter.ts
|
|
2
|
+
import {
|
|
3
|
+
createM365ChannelAdapter,
|
|
4
|
+
currentM365TurnContext
|
|
5
|
+
} from "@cuylabs/channel-m365-agent-core";
|
|
6
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
7
|
+
import {
|
|
8
|
+
resolveSlackMessageFormatter,
|
|
9
|
+
resolveThreadAwareSlackSessionId
|
|
10
|
+
} from "@cuylabs/channel-slack/core";
|
|
11
|
+
|
|
12
|
+
// src/channel-data.ts
|
|
13
|
+
import {
|
|
14
|
+
parseSlackM365Activity,
|
|
15
|
+
parseSlackM365ChannelData
|
|
16
|
+
} from "@cuylabs/channel-m365-slack";
|
|
17
|
+
function parseSlackChannelData(channelData) {
|
|
18
|
+
return parseSlackM365ChannelData(channelData);
|
|
19
|
+
}
|
|
20
|
+
function parseSlackActivity(context) {
|
|
21
|
+
return parseSlackM365Activity(context.activity);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// src/adapter.ts
|
|
25
|
+
function createM365SlackChannelAdapter(options) {
|
|
26
|
+
const {
|
|
27
|
+
agent,
|
|
28
|
+
prepareTurn,
|
|
29
|
+
onTurn: onTurnHook,
|
|
30
|
+
resolveSession,
|
|
31
|
+
resolveSessionId,
|
|
32
|
+
resolveMessage,
|
|
33
|
+
sessionStrategy,
|
|
34
|
+
source,
|
|
35
|
+
formatChatMarkdown,
|
|
36
|
+
formatMessageText,
|
|
37
|
+
...baseOptions
|
|
38
|
+
} = options;
|
|
39
|
+
const sessionTurnContext = new AsyncLocalStorage();
|
|
40
|
+
const messageFormatter = resolveSlackMessageFormatter({
|
|
41
|
+
formatChatMarkdown,
|
|
42
|
+
formatMessageText
|
|
43
|
+
});
|
|
44
|
+
const turnSource = source ?? agent;
|
|
45
|
+
const base = createM365ChannelAdapter({
|
|
46
|
+
...baseOptions,
|
|
47
|
+
...turnSource ? {
|
|
48
|
+
source: wrapM365SlackSource(
|
|
49
|
+
turnSource,
|
|
50
|
+
messageFormatter,
|
|
51
|
+
sessionTurnContext
|
|
52
|
+
)
|
|
53
|
+
} : {},
|
|
54
|
+
...resolveM365SlackSessionOptions({
|
|
55
|
+
resolveSession,
|
|
56
|
+
resolveSessionId,
|
|
57
|
+
sessionStrategy,
|
|
58
|
+
sessionTurnContext
|
|
59
|
+
}),
|
|
60
|
+
...resolveMessage ? { resolveMessage } : {
|
|
61
|
+
resolveMessage: (context) => {
|
|
62
|
+
const slack = parseSlackActivity(context);
|
|
63
|
+
if (slack) {
|
|
64
|
+
return slack.text;
|
|
65
|
+
}
|
|
66
|
+
return context.activity.text;
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
prepareTurn: async (request) => {
|
|
70
|
+
const slack = parseSlackActivity(request.turnContext);
|
|
71
|
+
if (!slack && request.turnContext.activity.channelId !== "slack") {
|
|
72
|
+
return {};
|
|
73
|
+
}
|
|
74
|
+
const enrichedRequest = {
|
|
75
|
+
...request,
|
|
76
|
+
slack: slack ?? buildFallbackSlackInfo(request)
|
|
77
|
+
};
|
|
78
|
+
const prepared = prepareTurn ? await prepareTurn(enrichedRequest) : void 0;
|
|
79
|
+
return {
|
|
80
|
+
...prepared ?? {},
|
|
81
|
+
scopeName: prepared?.scopeName?.trim() || "slack-activity",
|
|
82
|
+
scopeAttributes: {
|
|
83
|
+
slackChannelId: enrichedRequest.slack.channelId,
|
|
84
|
+
slackChannelType: enrichedRequest.slack.channelType,
|
|
85
|
+
slackUserId: enrichedRequest.slack.userId,
|
|
86
|
+
slackTeamId: enrichedRequest.slack.teamId,
|
|
87
|
+
slackThreadTs: enrichedRequest.slack.threadTs,
|
|
88
|
+
slackIsMention: enrichedRequest.slack.isMention,
|
|
89
|
+
...prepared?.scopeAttributes ?? {}
|
|
90
|
+
},
|
|
91
|
+
context: {
|
|
92
|
+
...prepared?.context ?? {},
|
|
93
|
+
// Stored as "slack" key — read via currentM365SlackTurnContext()
|
|
94
|
+
slack: enrichedRequest.slack
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
async function coreHandler(context) {
|
|
100
|
+
if (context.activity.channelId !== "slack") {
|
|
101
|
+
await base.handler(context);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
await sessionTurnContext.run(context, () => base.handler(context));
|
|
105
|
+
}
|
|
106
|
+
async function handler(context) {
|
|
107
|
+
if (onTurnHook) {
|
|
108
|
+
await onTurnHook(context, () => coreHandler(context));
|
|
109
|
+
} else {
|
|
110
|
+
await coreHandler(context);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
...base,
|
|
115
|
+
handler,
|
|
116
|
+
m365: base
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function currentM365SlackTurnContext() {
|
|
120
|
+
const m365 = currentM365TurnContext();
|
|
121
|
+
const slack = m365?.context?.slack;
|
|
122
|
+
if (!isSlackActivityInfo(slack) || !m365) return void 0;
|
|
123
|
+
return {
|
|
124
|
+
slackActivity: slack,
|
|
125
|
+
user: {
|
|
126
|
+
userId: slack.userId,
|
|
127
|
+
channelId: slack.channelId,
|
|
128
|
+
teamId: slack.teamId,
|
|
129
|
+
threadTs: slack.threadTs,
|
|
130
|
+
messageTs: slack.messageTs
|
|
131
|
+
},
|
|
132
|
+
sessionId: m365.sessionId,
|
|
133
|
+
message: m365.message,
|
|
134
|
+
context: m365.context
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function resolveM365SlackSessionOptions({
|
|
138
|
+
resolveSession,
|
|
139
|
+
resolveSessionId,
|
|
140
|
+
sessionStrategy,
|
|
141
|
+
sessionTurnContext
|
|
142
|
+
}) {
|
|
143
|
+
if (!resolveSession) {
|
|
144
|
+
return {
|
|
145
|
+
...sessionStrategy ? { sessionStrategy } : {},
|
|
146
|
+
...resolveSessionId ? { resolveSessionId } : {}
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
sessionStrategy: "custom",
|
|
151
|
+
resolveSessionId: async (conversationId, channelId) => {
|
|
152
|
+
const turnContext = sessionTurnContext.getStore();
|
|
153
|
+
if (!turnContext || turnContext.activity.channelId !== "slack") {
|
|
154
|
+
return resolveSessionId ? resolveSessionId(conversationId, channelId) : conversationId;
|
|
155
|
+
}
|
|
156
|
+
return resolveSession({
|
|
157
|
+
turnContext,
|
|
158
|
+
conversationId,
|
|
159
|
+
channelId,
|
|
160
|
+
slack: parseSlackActivity(turnContext) ?? buildFallbackSlackInfoFromTurn(turnContext, conversationId)
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
function wrapM365SlackSource(source, formatMessageText, sessionTurnContext) {
|
|
166
|
+
return {
|
|
167
|
+
async *chat(sessionId, message, options) {
|
|
168
|
+
const shouldFormat = sessionTurnContext.getStore()?.activity.channelId === "slack";
|
|
169
|
+
for await (const event of source.chat(sessionId, message, options)) {
|
|
170
|
+
if (shouldFormat && event.type === "text-delta") {
|
|
171
|
+
yield { ...event, text: formatMessageText(event.text) };
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
if (shouldFormat && event.type === "complete" && event.output) {
|
|
175
|
+
yield { ...event, output: formatMessageText(event.output) };
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
yield event;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
function buildFallbackSlackInfoFromTurn(turnContext, conversationId) {
|
|
184
|
+
return {
|
|
185
|
+
channelId: conversationId,
|
|
186
|
+
channelType: "unknown",
|
|
187
|
+
userId: turnContext.activity.from?.id ?? "unknown",
|
|
188
|
+
teamId: turnContext.activity.conversation?.tenantId,
|
|
189
|
+
threadTs: void 0,
|
|
190
|
+
messageTs: void 0,
|
|
191
|
+
text: turnContext.activity.text ?? "",
|
|
192
|
+
isMention: false
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
function resolveM365SlackThreadSessionId(slack) {
|
|
196
|
+
return resolveThreadAwareSlackSessionId(slack);
|
|
197
|
+
}
|
|
198
|
+
function buildFallbackSlackInfo(request) {
|
|
199
|
+
const userId = request.user.userId;
|
|
200
|
+
const channelId = request.user.conversationId;
|
|
201
|
+
return {
|
|
202
|
+
channelId,
|
|
203
|
+
channelType: "unknown",
|
|
204
|
+
userId,
|
|
205
|
+
teamId: request.user.tenantId,
|
|
206
|
+
threadTs: void 0,
|
|
207
|
+
messageTs: void 0,
|
|
208
|
+
text: request.message,
|
|
209
|
+
isMention: false
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
function isSlackActivityInfo(value) {
|
|
213
|
+
if (!value || typeof value !== "object") return false;
|
|
214
|
+
const candidate = value;
|
|
215
|
+
return typeof candidate.channelId === "string" && typeof candidate.channelType === "string" && typeof candidate.userId === "string" && typeof candidate.text === "string" && typeof candidate.isMention === "boolean";
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// src/express.ts
|
|
219
|
+
import {
|
|
220
|
+
adaptJwtMiddleware,
|
|
221
|
+
processWithAdapter
|
|
222
|
+
} from "@cuylabs/channel-m365-agent-core/express-compat";
|
|
223
|
+
async function mountM365SlackAgent(source, options = {}) {
|
|
224
|
+
const expressModule = await import("express");
|
|
225
|
+
const hostingModule = await import("@microsoft/agents-hosting");
|
|
226
|
+
const {
|
|
227
|
+
path: routePath = "/api/messages",
|
|
228
|
+
authConfig: providedAuthConfig,
|
|
229
|
+
port: portOption,
|
|
230
|
+
host,
|
|
231
|
+
adapter: providedAdapter,
|
|
232
|
+
app: providedApp,
|
|
233
|
+
...adapterOptions
|
|
234
|
+
} = options;
|
|
235
|
+
const authConfig = hostingModule.getAuthConfigWithDefaults(providedAuthConfig);
|
|
236
|
+
const cloudAdapter = providedAdapter ?? new hostingModule.CloudAdapter(authConfig);
|
|
237
|
+
const expressApp = providedApp ?? expressModule.default();
|
|
238
|
+
const channelAdapter = createM365SlackChannelAdapter({
|
|
239
|
+
source,
|
|
240
|
+
...adapterOptions
|
|
241
|
+
});
|
|
242
|
+
const jsonParser = expressModule.json();
|
|
243
|
+
const jwtAuthorizer = adaptJwtMiddleware(hostingModule, authConfig);
|
|
244
|
+
expressApp.post(
|
|
245
|
+
routePath,
|
|
246
|
+
jsonParser,
|
|
247
|
+
jwtAuthorizer,
|
|
248
|
+
(req, res) => processWithAdapter(
|
|
249
|
+
cloudAdapter,
|
|
250
|
+
req,
|
|
251
|
+
res,
|
|
252
|
+
(context) => channelAdapter.handler(context)
|
|
253
|
+
)
|
|
254
|
+
);
|
|
255
|
+
const port = portOption === void 0 ? resolvePort(process.env.PORT) : portOption;
|
|
256
|
+
let server;
|
|
257
|
+
if (port !== null) {
|
|
258
|
+
const onListen = () => {
|
|
259
|
+
process.stdout.write(
|
|
260
|
+
`M365 Slack agent listening on port ${port} \u2014 appId: ${authConfig.clientId ?? "(not set)"}
|
|
261
|
+
`
|
|
262
|
+
);
|
|
263
|
+
};
|
|
264
|
+
server = host ? expressApp.listen(port, host, onListen) : expressApp.listen(port, onListen);
|
|
265
|
+
}
|
|
266
|
+
return {
|
|
267
|
+
app: expressApp,
|
|
268
|
+
channelAdapter,
|
|
269
|
+
cloudAdapter,
|
|
270
|
+
server
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
function resolvePort(port) {
|
|
274
|
+
if (!port) return 3978;
|
|
275
|
+
const parsed = Number(port);
|
|
276
|
+
if (!Number.isInteger(parsed) || parsed < 0) {
|
|
277
|
+
throw new Error(`Invalid PORT value: ${port}`);
|
|
278
|
+
}
|
|
279
|
+
return parsed;
|
|
280
|
+
}
|
|
281
|
+
export {
|
|
282
|
+
createM365SlackChannelAdapter,
|
|
283
|
+
currentM365SlackTurnContext,
|
|
284
|
+
mountM365SlackAgent,
|
|
285
|
+
parseSlackActivity,
|
|
286
|
+
parseSlackChannelData,
|
|
287
|
+
parseSlackM365Activity,
|
|
288
|
+
parseSlackM365ChannelData,
|
|
289
|
+
resolveM365SlackThreadSessionId
|
|
290
|
+
};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# M365-Backed Slack Mode
|
|
2
|
+
|
|
3
|
+
Use this mode when Slack traffic should share the same Azure Bot Service and
|
|
4
|
+
`@microsoft/agents-hosting` stack you already use for Microsoft 365 channels.
|
|
5
|
+
|
|
6
|
+
## Main APIs
|
|
7
|
+
|
|
8
|
+
- `createM365SlackChannelAdapter(...)`
|
|
9
|
+
- `mountM365SlackAgent(...)`
|
|
10
|
+
- `currentM365SlackTurnContext()`
|
|
11
|
+
- `parseSlackChannelData(...)`
|
|
12
|
+
- `parseSlackActivity(...)`
|
|
13
|
+
- `resolveM365SlackThreadSessionId(...)`
|
|
14
|
+
|
|
15
|
+
## Required Dependencies
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pnpm add @cuylabs/channel-m365-slack-agent-core @cuylabs/channel-m365-slack @cuylabs/channel-slack @cuylabs/channel-m365-agent-core @microsoft/agents-hosting @microsoft/agents-activity express
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The adapter uses `@cuylabs/channel-m365-slack` to parse Slack payloads embedded
|
|
22
|
+
in M365 `channelData`, and `@cuylabs/channel-slack/core` for shared Slack
|
|
23
|
+
formatting, session, and context primitives. It does not import Bolt, Socket
|
|
24
|
+
Mode, or direct Slack app runtime code.
|
|
25
|
+
|
|
26
|
+
## Required Environment
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
OPENAI_API_KEY=...
|
|
30
|
+
MicrosoftAppId=...
|
|
31
|
+
MicrosoftAppPassword=...
|
|
32
|
+
MicrosoftAppTenantId=...
|
|
33
|
+
PORT=3978
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Endpoint Shape
|
|
37
|
+
|
|
38
|
+
This path uses the same default endpoint as the M365 package:
|
|
39
|
+
|
|
40
|
+
```text
|
|
41
|
+
/api/messages
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Azure Bot Service should be configured to deliver Slack-originated activities
|
|
45
|
+
to that endpoint.
|
|
46
|
+
|
|
47
|
+
## What Happens on the Wire
|
|
48
|
+
|
|
49
|
+
Azure Bot Service normalizes Slack events into Bot Framework activities:
|
|
50
|
+
|
|
51
|
+
- `activity.channelId === "slack"`
|
|
52
|
+
- Slack-native metadata is embedded in `activity.channelData`
|
|
53
|
+
- the raw Slack message payload is typically available as `channelData.SlackMessage`
|
|
54
|
+
|
|
55
|
+
This package turns that embedded payload back into `SlackActivityInfo` so your
|
|
56
|
+
agent code can still reason about Slack concepts like:
|
|
57
|
+
|
|
58
|
+
- channel ID
|
|
59
|
+
- thread timestamp
|
|
60
|
+
- user ID
|
|
61
|
+
- Slack channel type
|
|
62
|
+
- mention status and other Slack message metadata when ABS preserved it
|
|
63
|
+
|
|
64
|
+
## Quick Start
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
import { createAgent } from "@cuylabs/agent-core";
|
|
68
|
+
import { openai } from "@ai-sdk/openai";
|
|
69
|
+
import { mountM365SlackAgent } from "@cuylabs/channel-m365-slack-agent-core";
|
|
70
|
+
|
|
71
|
+
const agent = createAgent({
|
|
72
|
+
model: openai("gpt-4o-mini"),
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
await mountM365SlackAgent(agent, {
|
|
76
|
+
prepareTurn: ({ slack, user }) => ({
|
|
77
|
+
system: `Help Slack user ${slack.userId}.`,
|
|
78
|
+
scopeName: "slack-activity",
|
|
79
|
+
scopeAttributes: {
|
|
80
|
+
slackChannelId: slack.channelId,
|
|
81
|
+
tenantId: user.tenantId,
|
|
82
|
+
},
|
|
83
|
+
}),
|
|
84
|
+
});
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
By default, M365-backed Slack inherits the base M365 conversation-session
|
|
88
|
+
behavior. If you want Slack thread sessions, wire the Slack resolver explicitly:
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
import {
|
|
92
|
+
createM365SlackChannelAdapter,
|
|
93
|
+
resolveM365SlackThreadSessionId,
|
|
94
|
+
} from "@cuylabs/channel-m365-slack-agent-core";
|
|
95
|
+
|
|
96
|
+
const adapter = createM365SlackChannelAdapter({
|
|
97
|
+
source: agent,
|
|
98
|
+
resolveSession: ({ slack }) => resolveM365SlackThreadSessionId(slack),
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## When This Mode Is a Good Fit
|
|
103
|
+
|
|
104
|
+
- you already run Teams or other M365 channels through `channel-m365-agent-core`
|
|
105
|
+
- you want one ingress/auth pattern for both Teams and Slack
|
|
106
|
+
- you are comfortable reasoning at the Bot Framework transport layer
|
|
107
|
+
|
|
108
|
+
## Limits Compared to Direct Slack
|
|
109
|
+
|
|
110
|
+
This is not a full replacement for native Bolt when you need every Slack-native surface.
|
|
111
|
+
|
|
112
|
+
Compared with direct Slack mode:
|
|
113
|
+
|
|
114
|
+
- the host transport is mediated through Azure Bot Service
|
|
115
|
+
- Slack payload details depend on what ABS preserves in `channelData`
|
|
116
|
+
- Slack-native install/event management happens in Azure and Slack configuration, not purely in your app code
|
|
117
|
+
- Slack Assistant pane events such as `assistant_thread_started` and
|
|
118
|
+
`assistant_thread_context_changed` do not arrive as native Bolt Assistant
|
|
119
|
+
lifecycle callbacks
|
|
120
|
+
- Assistant utilities such as `assistant.threads.setStatus`,
|
|
121
|
+
`setSuggestedPrompts`, `setTitle`, and native `chatStream` task display mode
|
|
122
|
+
are direct-Slack features
|
|
123
|
+
- Block Kit action callbacks and modal submissions used by
|
|
124
|
+
`createSlackInteractiveController(...)` are direct-Slack features; ABS does
|
|
125
|
+
not preserve them as the direct Bolt path does
|
|
126
|
+
|
|
127
|
+
## Parsing Helpers
|
|
128
|
+
|
|
129
|
+
Use `parseSlackChannelData(...)` when you need the raw ABS-specific shape.
|
|
130
|
+
|
|
131
|
+
Use `parseSlackActivity(...)` when you want the normalized `SlackActivityInfo`.
|
|
132
|
+
|
|
133
|
+
That distinction matters:
|
|
134
|
+
|
|
135
|
+
- `parseSlackChannelData(...)` is the transport detail
|
|
136
|
+
- `parseSlackActivity(...)` is the application-facing abstraction
|
|
137
|
+
|
|
138
|
+
Inside tools or middleware, use `currentM365SlackTurnContext()` to read the
|
|
139
|
+
Slack activity metadata parsed from the M365 ambient turn context.
|
package/package.json
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cuylabs/channel-m365-slack-agent-core",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "M365/Azure Bot Service Slack transport for @cuylabs/agent-core",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"docs",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@cuylabs/agent-core": "^7.2.0",
|
|
22
|
+
"@cuylabs/channel-m365": "^0.3.0",
|
|
23
|
+
"@cuylabs/channel-m365-agent-core": "^0.3.0",
|
|
24
|
+
"@cuylabs/channel-m365-slack": "^0.3.0",
|
|
25
|
+
"@cuylabs/channel-slack": "^0.3.0"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"@microsoft/agents-activity": "^1.5.0",
|
|
29
|
+
"@microsoft/agents-hosting": "^1.5.0",
|
|
30
|
+
"express": ">=4.21.0 || >=5.0.0"
|
|
31
|
+
},
|
|
32
|
+
"peerDependenciesMeta": {
|
|
33
|
+
"express": {
|
|
34
|
+
"optional": true
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@microsoft/agents-activity": "^1.5.3",
|
|
39
|
+
"@microsoft/agents-hosting": "^1.5.3",
|
|
40
|
+
"@types/express": "^5.0.0",
|
|
41
|
+
"@types/node": "^22.0.0",
|
|
42
|
+
"express": "^5.2.1",
|
|
43
|
+
"tsup": "^8.0.0",
|
|
44
|
+
"typescript": "^5.7.0",
|
|
45
|
+
"vitest": "^4.0.18"
|
|
46
|
+
},
|
|
47
|
+
"keywords": [
|
|
48
|
+
"agent",
|
|
49
|
+
"slack",
|
|
50
|
+
"m365",
|
|
51
|
+
"azure-bot-service",
|
|
52
|
+
"channel"
|
|
53
|
+
],
|
|
54
|
+
"license": "Apache-2.0",
|
|
55
|
+
"repository": {
|
|
56
|
+
"type": "git",
|
|
57
|
+
"url": "https://github.com/cuylabs-ai/agent-channels-ts.git",
|
|
58
|
+
"directory": "packages/channel-m365-slack-agent-core"
|
|
59
|
+
},
|
|
60
|
+
"engines": {
|
|
61
|
+
"node": ">=20"
|
|
62
|
+
},
|
|
63
|
+
"publishConfig": {
|
|
64
|
+
"access": "public"
|
|
65
|
+
},
|
|
66
|
+
"scripts": {
|
|
67
|
+
"build": "tsup src/index.ts --format esm --dts --clean",
|
|
68
|
+
"dev": "tsup src/index.ts --format esm --dts --watch",
|
|
69
|
+
"typecheck": "tsc --noEmit",
|
|
70
|
+
"test": "vitest run",
|
|
71
|
+
"test:watch": "vitest",
|
|
72
|
+
"clean": "rm -rf dist"
|
|
73
|
+
}
|
|
74
|
+
}
|