@zhin.js/adapter-slack 4.0.1 → 4.1.1
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/CHANGELOG.md +59 -0
- package/README.md +77 -160
- package/adapters/slack.ts +34 -0
- package/{skills/slack/SKILL.md → agent/skills/slack.md} +2 -0
- package/agent/tools/add_reaction.ts +26 -0
- package/agent/tools/archive_channel.ts +24 -0
- package/agent/tools/edit_message.ts +28 -0
- package/agent/tools/invite_to_channel.ts +26 -0
- package/agent/tools/pin_message.ts +26 -0
- package/agent/tools/remove_reaction.ts +26 -0
- package/agent/tools/set_purpose.ts +26 -0
- package/agent/tools/set_topic.ts +26 -0
- package/agent/tools/unarchive.ts +24 -0
- package/agent/tools/unpin_message.ts +26 -0
- package/agent/tools/user_info.ts +31 -0
- package/lib/endpoint.d.ts +133 -94
- package/lib/endpoint.js +270 -612
- package/lib/index.d.ts +11 -10
- package/lib/index.js +11 -252
- package/lib/markdown-to-mrkdwn.d.ts +9 -0
- package/lib/markdown-to-mrkdwn.js +121 -0
- package/lib/mrkdwn-to-markdown.d.ts +4 -0
- package/lib/mrkdwn-to-markdown.js +30 -0
- package/lib/platform-permit.d.ts +1 -2
- package/lib/platform-permit.js +4 -2
- package/lib/protocol.d.ts +143 -0
- package/lib/protocol.js +225 -0
- package/lib/slack-agent-deps.d.ts +28 -0
- package/lib/slack-agent-deps.js +30 -0
- package/lib/slack-inbound-filter.d.ts +12 -0
- package/lib/slack-inbound-filter.js +46 -0
- package/lib/slack-message-ref.d.ts +7 -0
- package/lib/slack-message-ref.js +17 -0
- package/lib/slack-outbound.d.ts +24 -0
- package/lib/slack-outbound.js +109 -0
- package/lib/slack-reaction.d.ts +1 -0
- package/lib/slack-reaction.js +26 -0
- package/lib/slack-response-url.d.ts +5 -0
- package/lib/slack-response-url.js +16 -0
- package/lib/webhook.d.ts +14 -0
- package/lib/webhook.js +69 -0
- package/package.json +53 -14
- package/plugin.ts +13 -0
- package/schema.json +38 -0
- package/src/endpoint.ts +339 -647
- package/src/index.ts +65 -277
- package/src/markdown-to-mrkdwn.ts +117 -0
- package/src/mrkdwn-to-markdown.ts +29 -0
- package/src/platform-permit.ts +1 -2
- package/src/protocol.ts +380 -0
- package/src/slack-agent-deps.ts +57 -0
- package/src/slack-inbound-filter.ts +60 -0
- package/src/slack-message-ref.ts +18 -0
- package/src/slack-outbound.ts +167 -0
- package/src/slack-reaction.ts +23 -0
- package/src/slack-response-url.ts +26 -0
- package/src/webhook.ts +103 -0
- package/lib/adapter.d.ts +0 -19
- package/lib/adapter.d.ts.map +0 -1
- package/lib/adapter.js +0 -46
- package/lib/adapter.js.map +0 -1
- package/lib/endpoint.d.ts.map +0 -1
- package/lib/endpoint.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/platform-permit.d.ts.map +0 -1
- package/lib/platform-permit.js.map +0 -1
- package/lib/segment-mapper.d.ts +0 -2
- package/lib/segment-mapper.d.ts.map +0 -1
- package/lib/segment-mapper.js +0 -2
- package/lib/segment-mapper.js.map +0 -1
- package/lib/types.d.ts +0 -17
- package/lib/types.d.ts.map +0 -1
- package/lib/types.js +0 -2
- package/lib/types.js.map +0 -1
- package/plugin.yml +0 -3
- package/src/adapter.ts +0 -54
- package/src/segment-mapper.ts +0 -1
- package/src/types.ts +0 -18
- /package/{skills/slack → agent}/PERMITS.md +0 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { getSlackAgentDeps } from '../../src/slack-agent-deps.js';
|
|
4
|
+
|
|
5
|
+
export default defineAgentTool<{
|
|
6
|
+
endpoint_id: string;
|
|
7
|
+
user_id: string;
|
|
8
|
+
}>({
|
|
9
|
+
description: '查询 Slack 用户详细信息',
|
|
10
|
+
inputSchema: z.object({
|
|
11
|
+
endpoint_id: z.string().describe('Endpoint 名称'),
|
|
12
|
+
user_id: z.string().describe('用户 ID'),
|
|
13
|
+
}),
|
|
14
|
+
platforms: ['slack'],
|
|
15
|
+
tags: ['slack'],
|
|
16
|
+
async execute({ endpoint_id, user_id }) {
|
|
17
|
+
const { getEndpoint } = getSlackAgentDeps();
|
|
18
|
+
const endpoint = getEndpoint(endpoint_id);
|
|
19
|
+
const user = await endpoint.getUserInfo(user_id);
|
|
20
|
+
return {
|
|
21
|
+
id: user.id,
|
|
22
|
+
name: user.name,
|
|
23
|
+
real_name: user.real_name,
|
|
24
|
+
display_name: user.profile?.display_name,
|
|
25
|
+
email: user.profile?.email,
|
|
26
|
+
is_admin: user.is_admin,
|
|
27
|
+
is_bot: user.is_bot,
|
|
28
|
+
status_text: user.profile?.status_text,
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
});
|
package/lib/endpoint.d.ts
CHANGED
|
@@ -1,108 +1,147 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
|
|
1
|
+
import type { EndpointInstance } from '@zhin.js/adapter';
|
|
2
|
+
import type { MessageGateway } from '@zhin.js/core/runtime';
|
|
3
|
+
import type { HttpHost } from '@zhin.js/host-http';
|
|
4
|
+
import type { CapabilityId } from '@zhin.js/plugin-runtime';
|
|
5
|
+
import { type ResolvedSlackConfig, type SlackEvent, type SlackInteractionPayload, type SlackMessageEvent, type SlackSlashCommand } from './protocol.js';
|
|
6
|
+
import { type SlackChatClient } from './slack-outbound.js';
|
|
7
|
+
import { type SlackWebhookHandler } from './webhook.js';
|
|
8
|
+
export interface SlackSocketLike {
|
|
9
|
+
on(event: string, handler: (args: {
|
|
10
|
+
ack: () => Promise<void>;
|
|
11
|
+
body: unknown;
|
|
12
|
+
}) => void | Promise<void>): void;
|
|
13
|
+
start(): Promise<void>;
|
|
14
|
+
disconnect(): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
export interface SlackWebClientLike extends SlackChatClient {
|
|
17
|
+
auth: {
|
|
18
|
+
test(): Promise<{
|
|
19
|
+
user_id?: string;
|
|
20
|
+
user?: string;
|
|
21
|
+
}>;
|
|
22
|
+
};
|
|
23
|
+
conversations: {
|
|
24
|
+
invite(opts: {
|
|
25
|
+
channel: string;
|
|
26
|
+
users: string;
|
|
27
|
+
}): Promise<unknown>;
|
|
28
|
+
kick(opts: {
|
|
29
|
+
channel: string;
|
|
30
|
+
user: string;
|
|
31
|
+
}): Promise<unknown>;
|
|
32
|
+
setTopic(opts: {
|
|
33
|
+
channel: string;
|
|
34
|
+
topic: string;
|
|
35
|
+
}): Promise<unknown>;
|
|
36
|
+
setPurpose(opts: {
|
|
37
|
+
channel: string;
|
|
38
|
+
purpose: string;
|
|
39
|
+
}): Promise<unknown>;
|
|
40
|
+
archive(opts: {
|
|
41
|
+
channel: string;
|
|
42
|
+
}): Promise<unknown>;
|
|
43
|
+
unarchive(opts: {
|
|
44
|
+
channel: string;
|
|
45
|
+
}): Promise<unknown>;
|
|
46
|
+
rename(opts: {
|
|
47
|
+
channel: string;
|
|
48
|
+
name: string;
|
|
49
|
+
}): Promise<unknown>;
|
|
50
|
+
members(opts: {
|
|
51
|
+
channel: string;
|
|
52
|
+
}): Promise<{
|
|
53
|
+
members?: string[];
|
|
54
|
+
}>;
|
|
55
|
+
info(opts: {
|
|
56
|
+
channel: string;
|
|
57
|
+
}): Promise<{
|
|
58
|
+
channel?: unknown;
|
|
59
|
+
}>;
|
|
60
|
+
};
|
|
61
|
+
users: {
|
|
62
|
+
info(opts: {
|
|
63
|
+
user: string;
|
|
64
|
+
}): Promise<{
|
|
65
|
+
user?: unknown;
|
|
66
|
+
}>;
|
|
67
|
+
};
|
|
68
|
+
reactions: {
|
|
69
|
+
add(opts: {
|
|
70
|
+
channel: string;
|
|
71
|
+
timestamp: string;
|
|
72
|
+
name: string;
|
|
73
|
+
}): Promise<unknown>;
|
|
74
|
+
remove(opts: {
|
|
75
|
+
channel: string;
|
|
76
|
+
timestamp: string;
|
|
77
|
+
name: string;
|
|
78
|
+
}): Promise<unknown>;
|
|
79
|
+
};
|
|
80
|
+
pins: {
|
|
81
|
+
add(opts: {
|
|
82
|
+
channel: string;
|
|
83
|
+
timestamp: string;
|
|
84
|
+
}): Promise<unknown>;
|
|
85
|
+
remove(opts: {
|
|
86
|
+
channel: string;
|
|
87
|
+
timestamp: string;
|
|
88
|
+
}): Promise<unknown>;
|
|
89
|
+
};
|
|
90
|
+
chat: SlackChatClient['chat'] & {
|
|
91
|
+
delete(opts: {
|
|
92
|
+
channel: string;
|
|
93
|
+
ts: string;
|
|
94
|
+
}): Promise<unknown>;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
export interface SlackEndpointOptions {
|
|
98
|
+
readonly id: CapabilityId;
|
|
99
|
+
readonly gateway: MessageGateway;
|
|
100
|
+
readonly config: ResolvedSlackConfig;
|
|
101
|
+
readonly http?: HttpHost;
|
|
102
|
+
readonly createClient?: (token: string) => SlackWebClientLike;
|
|
103
|
+
readonly createSocket?: (opts: {
|
|
104
|
+
readonly appToken: string;
|
|
105
|
+
readonly clientPingTimeout: number;
|
|
106
|
+
}) => SlackSocketLike;
|
|
107
|
+
}
|
|
108
|
+
export declare class SlackEndpoint implements EndpointInstance, SlackWebhookHandler {
|
|
5
109
|
#private;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
* @param users 用户 ID 列表
|
|
30
|
-
*/
|
|
110
|
+
constructor(options: SlackEndpointOptions);
|
|
111
|
+
get client(): SlackWebClientLike | undefined;
|
|
112
|
+
get platformUserId(): string | undefined;
|
|
113
|
+
get config(): ResolvedSlackConfig;
|
|
114
|
+
start(): Promise<void>;
|
|
115
|
+
open(): void;
|
|
116
|
+
close(): void;
|
|
117
|
+
stop(): Promise<void>;
|
|
118
|
+
send({ target, payload }: {
|
|
119
|
+
readonly target: string;
|
|
120
|
+
readonly payload: unknown;
|
|
121
|
+
}): Promise<string>;
|
|
122
|
+
/** Test / internal: admit a message event when open. */
|
|
123
|
+
admit(event: SlackMessageEvent | SlackEvent): void;
|
|
124
|
+
admitInteraction(payload: SlackInteractionPayload): void;
|
|
125
|
+
admitSlashCommand(cmd: SlackSlashCommand): void;
|
|
126
|
+
handleEnvelope(body: unknown): void;
|
|
127
|
+
trackMessageChannel(ts: string, channel: string): void;
|
|
128
|
+
resolveMessageRef(messageId: string, channelHint?: string): {
|
|
129
|
+
channel: string;
|
|
130
|
+
ts: string;
|
|
131
|
+
} | null;
|
|
132
|
+
editMessage(channel: string, messageTs: string, content: unknown): Promise<void>;
|
|
31
133
|
inviteToChannel(channel: string, users: string[]): Promise<boolean>;
|
|
32
|
-
/**
|
|
33
|
-
* 从频道踢出用户
|
|
34
|
-
* @param channel 频道 ID
|
|
35
|
-
* @param user 用户 ID
|
|
36
|
-
*/
|
|
37
134
|
kickFromChannel(channel: string, user: string): Promise<boolean>;
|
|
38
|
-
/**
|
|
39
|
-
* 设置频道话题
|
|
40
|
-
* @param channel 频道 ID
|
|
41
|
-
* @param topic 话题
|
|
42
|
-
*/
|
|
43
135
|
setChannelTopic(channel: string, topic: string): Promise<boolean>;
|
|
44
|
-
/**
|
|
45
|
-
* 设置频道目的
|
|
46
|
-
* @param channel 频道 ID
|
|
47
|
-
* @param purpose 目的
|
|
48
|
-
*/
|
|
49
136
|
setChannelPurpose(channel: string, purpose: string): Promise<boolean>;
|
|
50
|
-
/**
|
|
51
|
-
* 归档频道
|
|
52
|
-
* @param channel 频道 ID
|
|
53
|
-
*/
|
|
54
137
|
archiveChannel(channel: string): Promise<boolean>;
|
|
55
|
-
/**
|
|
56
|
-
* 取消归档频道
|
|
57
|
-
* @param channel 频道 ID
|
|
58
|
-
*/
|
|
59
138
|
unarchiveChannel(channel: string): Promise<boolean>;
|
|
60
|
-
/**
|
|
61
|
-
* 重命名频道
|
|
62
|
-
* @param channel 频道 ID
|
|
63
|
-
* @param name 新名称
|
|
64
|
-
*/
|
|
65
139
|
renameChannel(channel: string, name: string): Promise<boolean>;
|
|
66
|
-
/**
|
|
67
|
-
* 获取频道成员列表
|
|
68
|
-
* @param channel 频道 ID
|
|
69
|
-
*/
|
|
70
140
|
getChannelMembers(channel: string): Promise<string[]>;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
* @param channel 频道 ID
|
|
74
|
-
*/
|
|
75
|
-
getChannelInfo(channel: string): Promise<any>;
|
|
76
|
-
/**
|
|
77
|
-
* 获取用户信息
|
|
78
|
-
* @param user 用户 ID
|
|
79
|
-
*/
|
|
80
|
-
getUserInfo(user: string): Promise<any>;
|
|
81
|
-
/**
|
|
82
|
-
* 添加消息反应
|
|
83
|
-
* @param channel 频道 ID
|
|
84
|
-
* @param timestamp 消息时间戳
|
|
85
|
-
* @param name 表情名称
|
|
86
|
-
*/
|
|
141
|
+
getChannelInfo(channel: string): Promise<unknown>;
|
|
142
|
+
getUserInfo(user: string): Promise<unknown>;
|
|
87
143
|
addReaction(channel: string, timestamp: string, name: string): Promise<boolean>;
|
|
88
|
-
/**
|
|
89
|
-
* 移除消息反应
|
|
90
|
-
* @param channel 频道 ID
|
|
91
|
-
* @param timestamp 消息时间戳
|
|
92
|
-
* @param name 表情名称
|
|
93
|
-
*/
|
|
94
144
|
removeReaction(channel: string, timestamp: string, name: string): Promise<boolean>;
|
|
95
|
-
/**
|
|
96
|
-
* 置顶消息
|
|
97
|
-
* @param channel 频道 ID
|
|
98
|
-
* @param timestamp 消息时间戳
|
|
99
|
-
*/
|
|
100
145
|
pinMessage(channel: string, timestamp: string): Promise<boolean>;
|
|
101
|
-
/**
|
|
102
|
-
* 取消置顶消息
|
|
103
|
-
* @param channel 频道 ID
|
|
104
|
-
* @param timestamp 消息时间戳
|
|
105
|
-
*/
|
|
106
146
|
unpinMessage(channel: string, timestamp: string): Promise<boolean>;
|
|
107
147
|
}
|
|
108
|
-
//# sourceMappingURL=endpoint.d.ts.map
|