@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.
Files changed (56) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/README.md +58 -335
  3. package/adapters/dingtalk.ts +26 -0
  4. package/agent/tools/add_chat_members.ts +22 -0
  5. package/agent/tools/create_chat.ts +23 -0
  6. package/agent/tools/dept_info.ts +17 -0
  7. package/agent/tools/get_dept_users.ts +18 -0
  8. package/agent/tools/get_user.ts +17 -0
  9. package/agent/tools/list_departments.ts +18 -0
  10. package/agent/tools/send_work_notice.ts +20 -0
  11. package/agent/tools/update_chat.ts +27 -0
  12. package/lib/dingtalk-agent-deps.d.ts +26 -0
  13. package/lib/dingtalk-agent-deps.js +30 -0
  14. package/lib/endpoint.d.ts +45 -36
  15. package/lib/endpoint.js +199 -434
  16. package/lib/index.d.ts +5 -15
  17. package/lib/index.js +5 -219
  18. package/lib/platform-permit.d.ts +1 -2
  19. package/lib/platform-permit.js +4 -2
  20. package/lib/protocol.d.ts +121 -0
  21. package/lib/protocol.js +221 -0
  22. package/lib/webhook.d.ts +13 -0
  23. package/lib/webhook.js +48 -0
  24. package/package.json +51 -19
  25. package/plugin.ts +12 -0
  26. package/schema.json +23 -0
  27. package/src/dingtalk-agent-deps.ts +58 -0
  28. package/src/endpoint.ts +263 -479
  29. package/src/index.ts +46 -235
  30. package/src/platform-permit.ts +1 -2
  31. package/src/protocol.ts +338 -0
  32. package/src/webhook.ts +76 -0
  33. package/lib/adapter.d.ts +0 -19
  34. package/lib/adapter.d.ts.map +0 -1
  35. package/lib/adapter.js +0 -40
  36. package/lib/adapter.js.map +0 -1
  37. package/lib/endpoint.d.ts.map +0 -1
  38. package/lib/endpoint.js.map +0 -1
  39. package/lib/index.d.ts.map +0 -1
  40. package/lib/index.js.map +0 -1
  41. package/lib/platform-permit.d.ts.map +0 -1
  42. package/lib/platform-permit.js.map +0 -1
  43. package/lib/segment-mapper.d.ts +0 -2
  44. package/lib/segment-mapper.d.ts.map +0 -1
  45. package/lib/segment-mapper.js +0 -2
  46. package/lib/segment-mapper.js.map +0 -1
  47. package/lib/types.d.ts +0 -58
  48. package/lib/types.d.ts.map +0 -1
  49. package/lib/types.js +0 -5
  50. package/lib/types.js.map +0 -1
  51. package/plugin.yml +0 -3
  52. package/src/adapter.ts +0 -46
  53. package/src/segment-mapper.ts +0 -1
  54. package/src/types.ts +0 -56
  55. /package/{skills/dingtalk → agent}/PERMITS.md +0 -0
  56. /package/{skills/dingtalk/SKILL.md → agent/skills/dingtalk.md} +0 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zhin.js/adapter-dingtalk",
3
- "version": "4.0.1",
4
- "description": "Zhin.js adapter for DingTalk (钉钉)",
3
+ "version": "4.0.3",
4
+ "description": "Zhin.js DingTalk (钉钉) adapter for Plugin Runtime (HTTP webhook)",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
7
7
  "types": "./lib/index.d.ts",
@@ -32,31 +32,49 @@
32
32
  "type": "git",
33
33
  "directory": "plugins/adapters/dingtalk"
34
34
  },
35
- "devDependencies": {
36
- "@types/koa": "^3.0.3",
37
- "@types/node": "^26.1.0",
38
- "typescript": "^6.0.3",
39
- "zhin.js": "4.1.1",
40
- "@zhin.js/host-router": "2.0.2"
35
+ "dependencies": {
36
+ "@zhin.js/adapter": "1.0.1",
37
+ "@zhin.js/core": "1.3.5",
38
+ "@zhin.js/host-http": "1.0.1",
39
+ "@zhin.js/logger": "1.0.75",
40
+ "@zhin.js/plugin-runtime": "1.0.1"
41
41
  },
42
42
  "peerDependencies": {
43
- "@zhin.js/host-router": "2.0.2",
44
- "zhin.js": "4.1.1"
43
+ "zod": "^4.0.0",
44
+ "@zhin.js/adapter": "1.0.1",
45
+ "@zhin.js/agent": "1.0.4",
46
+ "@zhin.js/core": "1.3.5",
47
+ "@zhin.js/host-http": "1.0.1",
48
+ "@zhin.js/plugin-runtime": "1.0.1",
49
+ "zhin.js": "4.1.3"
45
50
  },
46
51
  "peerDependenciesMeta": {
47
- "@zhin.js/host-router": {
48
- "optional": false
52
+ "zhin.js": {
53
+ "optional": true
54
+ },
55
+ "@zhin.js/agent": {
56
+ "optional": true
57
+ },
58
+ "zod": {
59
+ "optional": true
49
60
  }
50
61
  },
62
+ "devDependencies": {
63
+ "@types/node": "^26.1.0",
64
+ "typescript": "^6.0.3",
65
+ "vitest": "^4.1.10",
66
+ "zod": "^4.4.3",
67
+ "@zhin.js/agent": "1.0.4",
68
+ "zhin.js": "4.1.3"
69
+ },
51
70
  "files": [
71
+ "adapters",
72
+ "plugin.ts",
73
+ "schema.json",
52
74
  "src",
53
75
  "lib",
54
- "client",
55
- "dist",
56
- "skills",
57
- "plugin.yml",
76
+ "agent",
58
77
  "README.md",
59
- "node",
60
78
  "CHANGELOG.md"
61
79
  ],
62
80
  "publishConfig": {
@@ -66,9 +84,23 @@
66
84
  "engines": {
67
85
  "node": "^20.19.0 || >=22.12.0"
68
86
  },
87
+ "zhin": {
88
+ "protocol": 1,
89
+ "type": "plugin",
90
+ "entry": "./plugin.ts",
91
+ "engine": "^1.0.0",
92
+ "runtime": "trusted",
93
+ "features": [
94
+ {
95
+ "package": "@zhin.js/adapter",
96
+ "api": "^1.0.0"
97
+ }
98
+ ],
99
+ "plugins": []
100
+ },
69
101
  "scripts": {
70
- "build": "pnpm build:node",
102
+ "build": "tsc",
71
103
  "clean": "rimraf lib",
72
- "build:node": "tsc"
104
+ "test": "NODE_OPTIONS=--experimental-strip-types vitest run --root ../../.. plugins/adapters/dingtalk/tests"
73
105
  }
74
106
  }
package/plugin.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { definePlugin } from '@zhin.js/plugin-runtime';
2
+ import { registerDingtalkPlatformPermitChecker } from './src/platform-permit.js';
3
+
4
+ export default definePlugin({
5
+ name: 'dingtalk',
6
+ metadata: {
7
+ displayName: 'DingTalk (钉钉) Adapter',
8
+ },
9
+ setup() {
10
+ return registerDingtalkPlatformPermitChecker();
11
+ },
12
+ });
package/schema.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "type": "object",
4
+ "additionalProperties": false,
5
+ "properties": {
6
+ "name": {
7
+ "type": "string",
8
+ "default": "dingtalk-bot"
9
+ },
10
+ "appKey": { "type": "string" },
11
+ "appSecret": { "type": "string" },
12
+ "webhookPath": {
13
+ "type": "string",
14
+ "default": "/dingtalk/webhook"
15
+ },
16
+ "robotCode": { "type": "string" },
17
+ "apiBaseUrl": {
18
+ "type": "string",
19
+ "default": "https://oapi.dingtalk.com"
20
+ }
21
+ },
22
+ "required": ["appKey", "appSecret"]
23
+ }
@@ -0,0 +1,58 @@
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
+
6
+ export interface DingtalkAgentEndpoint {
7
+ getUserInfo(userId: string): Promise<unknown>;
8
+ getDepartmentUsers(deptId: number): Promise<unknown[]>;
9
+ sendWorkNotice(userIdList: string[], content: unknown): Promise<boolean>;
10
+ getDepartmentList(deptId?: number): Promise<unknown[]>;
11
+ getDepartmentInfo(deptId: number): Promise<unknown>;
12
+ createChat(name: string, ownerUserId: string, userIdList: string[]): Promise<string | null>;
13
+ getChatInfo(chatId: string): Promise<unknown>;
14
+ updateChat(
15
+ chatId: string,
16
+ options: {
17
+ name?: string;
18
+ owner?: string;
19
+ add_useridlist?: string[];
20
+ del_useridlist?: string[];
21
+ },
22
+ ): Promise<boolean>;
23
+ }
24
+
25
+ export interface DingtalkAgentDeps {
26
+ getEndpoint: (endpointId: string) => DingtalkAgentEndpoint;
27
+ }
28
+
29
+ const endpoints = new Map<string, DingtalkAgentEndpoint>();
30
+ let override: DingtalkAgentDeps | null = null;
31
+
32
+ export function registerDingtalkAgentEndpoint(
33
+ endpointId: string,
34
+ endpoint: DingtalkAgentEndpoint,
35
+ ): () => void {
36
+ endpoints.set(endpointId, endpoint);
37
+ return () => {
38
+ if (endpoints.get(endpointId) === endpoint) {
39
+ endpoints.delete(endpointId);
40
+ }
41
+ };
42
+ }
43
+
44
+ /** Optional override used by tests / transitional callers. Pass `null` to clear. */
45
+ export function setDingtalkAgentDeps(deps: DingtalkAgentDeps | null): void {
46
+ override = deps;
47
+ }
48
+
49
+ export function getDingtalkAgentDeps(): DingtalkAgentDeps {
50
+ if (override) return override;
51
+ return {
52
+ getEndpoint(endpointId) {
53
+ const endpoint = endpoints.get(endpointId);
54
+ if (!endpoint) throw new Error(`Endpoint ${endpointId} 不存在`);
55
+ return endpoint;
56
+ },
57
+ };
58
+ }