@zhin.js/adapter-dingtalk 4.0.1 → 4.0.3
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 +56 -0
- package/README.md +58 -335
- package/adapters/dingtalk.ts +26 -0
- package/agent/tools/add_chat_members.ts +22 -0
- package/agent/tools/create_chat.ts +23 -0
- package/agent/tools/dept_info.ts +17 -0
- package/agent/tools/get_dept_users.ts +18 -0
- package/agent/tools/get_user.ts +17 -0
- package/agent/tools/list_departments.ts +18 -0
- package/agent/tools/send_work_notice.ts +20 -0
- package/agent/tools/update_chat.ts +27 -0
- package/lib/dingtalk-agent-deps.d.ts +26 -0
- package/lib/dingtalk-agent-deps.js +30 -0
- package/lib/endpoint.d.ts +45 -36
- package/lib/endpoint.js +199 -434
- package/lib/index.d.ts +5 -15
- package/lib/index.js +5 -219
- package/lib/platform-permit.d.ts +1 -2
- package/lib/platform-permit.js +4 -2
- package/lib/protocol.d.ts +121 -0
- package/lib/protocol.js +221 -0
- package/lib/webhook.d.ts +13 -0
- package/lib/webhook.js +48 -0
- package/package.json +51 -19
- package/plugin.ts +12 -0
- package/schema.json +23 -0
- package/src/dingtalk-agent-deps.ts +58 -0
- package/src/endpoint.ts +263 -479
- package/src/index.ts +46 -235
- package/src/platform-permit.ts +1 -2
- package/src/protocol.ts +338 -0
- package/src/webhook.ts +76 -0
- package/lib/adapter.d.ts +0 -19
- package/lib/adapter.d.ts.map +0 -1
- package/lib/adapter.js +0 -40
- 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 -58
- package/lib/types.d.ts.map +0 -1
- package/lib/types.js +0 -5
- package/lib/types.js.map +0 -1
- package/plugin.yml +0 -3
- package/src/adapter.ts +0 -46
- package/src/segment-mapper.ts +0 -1
- package/src/types.ts +0 -56
- /package/{skills/dingtalk → agent}/PERMITS.md +0 -0
- /package/{skills/dingtalk/SKILL.md → agent/skills/dingtalk.md} +0 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { getDingtalkAgentDeps } from '../../src/dingtalk-agent-deps.js';
|
|
4
|
+
export default defineAgentTool<{ endpoint_id: string; chat_id: string; name?: string; owner?: string; add_members?: string; remove_members?: string }>({
|
|
5
|
+
description: '更新钉钉群聊设置(改名、换群主、增减成员)',
|
|
6
|
+
inputSchema: z.object({
|
|
7
|
+
endpoint_id: z.string().describe('Endpoint 名称'),
|
|
8
|
+
chat_id: z.string().describe('群聊 ID'),
|
|
9
|
+
name: z.string().optional().describe('新群名(可选)'),
|
|
10
|
+
owner: z.string().optional().describe('新群主 userId(可选)'),
|
|
11
|
+
add_members: z.string().optional().describe('要添加的成员 userId,逗号分隔(可选)'),
|
|
12
|
+
remove_members: z.string().optional().describe('要移除的成员 userId,逗号分隔(可选)'),
|
|
13
|
+
}),
|
|
14
|
+
platforms: ['dingtalk'],
|
|
15
|
+
tags: ['dingtalk'],
|
|
16
|
+
async execute({ endpoint_id, chat_id, name, owner, add_members, remove_members }: { endpoint_id: string; chat_id: string; name?: string; owner?: string; add_members?: string; remove_members?: string }) {
|
|
17
|
+
const endpoint = getDingtalkAgentDeps().getEndpoint(endpoint_id);
|
|
18
|
+
const options: Record<string, unknown> = {};
|
|
19
|
+
if (name) options.name = name;
|
|
20
|
+
if (owner) options.owner = owner;
|
|
21
|
+
if (add_members) options.add_useridlist = add_members.split(',').map((s: string) => s.trim());
|
|
22
|
+
if (remove_members) options.del_useridlist = remove_members.split(',').map((s: string) => s.trim());
|
|
23
|
+
await endpoint.updateChat(chat_id, options);
|
|
24
|
+
return { success: true, message: '群聊设置已更新' };
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent tool deps for dingtalk (user / dept / chat / work notice).
|
|
3
|
+
* Endpoints register themselves on start; tools look up by endpoint id.
|
|
4
|
+
*/
|
|
5
|
+
export interface DingtalkAgentEndpoint {
|
|
6
|
+
getUserInfo(userId: string): Promise<unknown>;
|
|
7
|
+
getDepartmentUsers(deptId: number): Promise<unknown[]>;
|
|
8
|
+
sendWorkNotice(userIdList: string[], content: unknown): Promise<boolean>;
|
|
9
|
+
getDepartmentList(deptId?: number): Promise<unknown[]>;
|
|
10
|
+
getDepartmentInfo(deptId: number): Promise<unknown>;
|
|
11
|
+
createChat(name: string, ownerUserId: string, userIdList: string[]): Promise<string | null>;
|
|
12
|
+
getChatInfo(chatId: string): Promise<unknown>;
|
|
13
|
+
updateChat(chatId: string, options: {
|
|
14
|
+
name?: string;
|
|
15
|
+
owner?: string;
|
|
16
|
+
add_useridlist?: string[];
|
|
17
|
+
del_useridlist?: string[];
|
|
18
|
+
}): Promise<boolean>;
|
|
19
|
+
}
|
|
20
|
+
export interface DingtalkAgentDeps {
|
|
21
|
+
getEndpoint: (endpointId: string) => DingtalkAgentEndpoint;
|
|
22
|
+
}
|
|
23
|
+
export declare function registerDingtalkAgentEndpoint(endpointId: string, endpoint: DingtalkAgentEndpoint): () => void;
|
|
24
|
+
/** Optional override used by tests / transitional callers. Pass `null` to clear. */
|
|
25
|
+
export declare function setDingtalkAgentDeps(deps: DingtalkAgentDeps | null): void;
|
|
26
|
+
export declare function getDingtalkAgentDeps(): DingtalkAgentDeps;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent tool deps for dingtalk (user / dept / chat / work notice).
|
|
3
|
+
* Endpoints register themselves on start; tools look up by endpoint id.
|
|
4
|
+
*/
|
|
5
|
+
const endpoints = new Map();
|
|
6
|
+
let override = null;
|
|
7
|
+
export function registerDingtalkAgentEndpoint(endpointId, endpoint) {
|
|
8
|
+
endpoints.set(endpointId, endpoint);
|
|
9
|
+
return () => {
|
|
10
|
+
if (endpoints.get(endpointId) === endpoint) {
|
|
11
|
+
endpoints.delete(endpointId);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/** Optional override used by tests / transitional callers. Pass `null` to clear. */
|
|
16
|
+
export function setDingtalkAgentDeps(deps) {
|
|
17
|
+
override = deps;
|
|
18
|
+
}
|
|
19
|
+
export function getDingtalkAgentDeps() {
|
|
20
|
+
if (override)
|
|
21
|
+
return override;
|
|
22
|
+
return {
|
|
23
|
+
getEndpoint(endpointId) {
|
|
24
|
+
const endpoint = endpoints.get(endpointId);
|
|
25
|
+
if (!endpoint)
|
|
26
|
+
throw new Error(`Endpoint ${endpointId} 不存在`);
|
|
27
|
+
return endpoint;
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
package/lib/endpoint.d.ts
CHANGED
|
@@ -1,41 +1,51 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* DingTalkEndpoint — lifecycle, outbound, admit, OpenAPI helpers for agent tools.
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
4
|
+
import type { EndpointInstance } from '@zhin.js/adapter';
|
|
5
|
+
import type { MessageGateway } from '@zhin.js/core/runtime';
|
|
6
|
+
import type { HttpHost } from '@zhin.js/host-http';
|
|
7
|
+
import type { CapabilityId } from '@zhin.js/plugin-runtime';
|
|
8
|
+
import { type DingTalkEvent, type DingTalkMessage, type ResolvedDingTalkConfig } from './protocol.js';
|
|
9
|
+
export type DingTalkFetch = (url: string, init?: {
|
|
10
|
+
readonly method?: string;
|
|
11
|
+
readonly headers?: Record<string, string>;
|
|
12
|
+
readonly body?: string;
|
|
13
|
+
}) => Promise<{
|
|
14
|
+
readonly ok: boolean;
|
|
15
|
+
readonly status: number;
|
|
16
|
+
text(): Promise<string>;
|
|
17
|
+
json(): Promise<unknown>;
|
|
18
|
+
}>;
|
|
19
|
+
export interface DingTalkEndpointOptions {
|
|
20
|
+
readonly id: CapabilityId;
|
|
21
|
+
readonly gateway: MessageGateway;
|
|
22
|
+
readonly http: HttpHost;
|
|
23
|
+
readonly config: ResolvedDingTalkConfig;
|
|
24
|
+
readonly fetch?: DingTalkFetch;
|
|
25
|
+
}
|
|
26
|
+
export declare class DingTalkEndpoint implements EndpointInstance {
|
|
27
|
+
#private;
|
|
28
|
+
constructor(options: DingTalkEndpointOptions);
|
|
29
|
+
/** Used by webhook handler. */
|
|
30
|
+
get isOpen(): boolean;
|
|
31
|
+
get config(): ResolvedDingTalkConfig;
|
|
32
|
+
start(): Promise<void>;
|
|
33
|
+
open(): void;
|
|
34
|
+
close(): void;
|
|
35
|
+
stop(): Promise<void>;
|
|
36
|
+
send({ target, payload }: {
|
|
37
|
+
readonly target: string;
|
|
38
|
+
readonly payload: unknown;
|
|
39
|
+
}): Promise<string>;
|
|
40
|
+
/** Test / internal: admit a parsed event when open (non-webhook path). */
|
|
41
|
+
admit(event: DingTalkEvent | DingTalkMessage): void;
|
|
42
|
+
getUserInfo(userId: string): Promise<unknown>;
|
|
43
|
+
getDepartmentUsers(deptId: number): Promise<unknown[]>;
|
|
44
|
+
sendWorkNotice(userIdList: string[], content: unknown): Promise<boolean>;
|
|
45
|
+
getDepartmentList(deptId?: number): Promise<unknown[]>;
|
|
46
|
+
getDepartmentInfo(deptId: number): Promise<unknown>;
|
|
37
47
|
createChat(name: string, ownerUserId: string, userIdList: string[]): Promise<string | null>;
|
|
38
|
-
getChatInfo(chatId: string): Promise<
|
|
48
|
+
getChatInfo(chatId: string): Promise<unknown>;
|
|
39
49
|
updateChat(chatId: string, options: {
|
|
40
50
|
name?: string;
|
|
41
51
|
owner?: string;
|
|
@@ -43,4 +53,3 @@ export declare class DingTalkEndpoint implements Endpoint<DingTalkEndpointConfig
|
|
|
43
53
|
del_useridlist?: string[];
|
|
44
54
|
}): Promise<boolean>;
|
|
45
55
|
}
|
|
46
|
-
//# sourceMappingURL=endpoint.d.ts.map
|