@zhin.js/adapter-kook 1.1.25 → 1.1.27
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 +173 -0
- package/LICENSE +21 -0
- package/PERMITS.md +20 -14
- package/README.md +6 -2
- package/adapters/kook/index.js +3 -0
- package/adapters/kook/index.ts +3 -0
- package/agents/kook/conversation.js +88 -0
- package/agents/kook/conversation.ts +99 -0
- package/agents/kook/messages.js +16 -0
- package/agents/kook/messages.ts +16 -0
- package/agents/kook/skills/kook/tools/blacklist/index.js +9 -6
- package/agents/kook/skills/kook/tools/blacklist/index.ts +9 -7
- package/agents/kook/skills/kook/tools/create_role/index.js +5 -6
- package/agents/kook/skills/kook/tools/create_role/index.ts +6 -7
- package/agents/kook/skills/kook/tools/delete_role/index.js +5 -6
- package/agents/kook/skills/kook/tools/delete_role/index.ts +6 -7
- package/agents/kook/skills/kook/tools/grant_role/index.js +9 -7
- package/agents/kook/skills/kook/tools/grant_role/index.ts +9 -8
- package/agents/kook/skills/kook/tools/list_roles/index.js +5 -7
- package/agents/kook/skills/kook/tools/list_roles/index.ts +6 -8
- package/agents/kook/skills/kook/tools/revoke_role/index.js +9 -7
- package/agents/kook/skills/kook/tools/revoke_role/index.ts +9 -8
- package/lib/console-spec.js +148 -13
- package/lib/endpoint.d.ts +2 -1
- package/lib/endpoint.js +27 -12
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/platform-permit.d.ts +4 -19
- package/lib/platform-permit.js +7 -46
- package/lib/protocol.d.ts +1 -5
- package/lib/protocol.js +3 -28
- package/lib/sender-roles.d.ts +6 -6
- package/lib/sender-roles.js +55 -21
- package/lib/webhook.d.ts +1 -2
- package/lib/webhook.js +13 -33
- package/package.json +23 -26
- package/plugin.js +0 -6
- package/schema.json +0 -56
- package/src/console-spec.ts +148 -13
- package/src/endpoint.ts +27 -13
- package/src/index.ts +1 -7
- package/src/platform-permit.ts +5 -70
- package/src/protocol.ts +4 -33
- package/src/sender-roles.ts +59 -27
- package/src/webhook.ts +14 -36
package/src/webhook.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { endpointSpec, type Endpoint } from 'zhin.js/adapter';
|
|
|
2
2
|
/**
|
|
3
3
|
* KOOK webhook HTTP: verify → parse → admit.
|
|
4
4
|
*/
|
|
5
|
-
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
6
5
|
import type { HttpHost, HttpRouteRegistration } from '@zhin.js/host-http';
|
|
7
6
|
import { formatCompact, getLogger } from '@zhin.js/logger';
|
|
8
7
|
import {
|
|
@@ -34,17 +33,14 @@ export function registerKookWebhookRoutes(
|
|
|
34
33
|
): HttpRouteRegistration[] {
|
|
35
34
|
const path = handler.endpointConfig.webhookPath;
|
|
36
35
|
return [
|
|
37
|
-
http.route('POST', path,
|
|
38
|
-
await handleKookWebhookRequest(request, response, handler);
|
|
39
|
-
}, { summary: 'KOOK webhook callback', tags: ['kook'] }),
|
|
36
|
+
http.route('POST', path, (request) => handleKookWebhookRequest(request, handler), { summary: 'KOOK webhook callback', tags: ['kook'] }),
|
|
40
37
|
];
|
|
41
38
|
}
|
|
42
39
|
|
|
43
40
|
export async function handleKookWebhookRequest(
|
|
44
|
-
request:
|
|
45
|
-
response: ServerResponse,
|
|
41
|
+
request: Request,
|
|
46
42
|
handler: KookWebhookHandler,
|
|
47
|
-
): Promise<
|
|
43
|
+
): Promise<Response> {
|
|
48
44
|
try {
|
|
49
45
|
const rawBody = await readRequestBody(request);
|
|
50
46
|
let frame: KookWebhookFrame;
|
|
@@ -56,46 +52,32 @@ export async function handleKookWebhookRequest(
|
|
|
56
52
|
ok: false,
|
|
57
53
|
error: error instanceof Error ? error.message : String(error),
|
|
58
54
|
}));
|
|
59
|
-
|
|
60
|
-
response.end(JSON.stringify({ message: 'Invalid webhook payload' }));
|
|
61
|
-
return;
|
|
55
|
+
return new Response(JSON.stringify({ message: 'Invalid webhook payload' }), { status: 400, headers: { 'Content-Type': 'application/json' } });
|
|
62
56
|
}
|
|
63
57
|
|
|
64
58
|
const event = frame.d;
|
|
65
59
|
if (!event || typeof event !== 'object') {
|
|
66
|
-
|
|
67
|
-
response.end(JSON.stringify({ message: 'OK' }));
|
|
68
|
-
return;
|
|
60
|
+
return new Response(JSON.stringify({ message: 'OK' }), { status: 200, headers: { 'Content-Type': 'application/json' } });
|
|
69
61
|
}
|
|
70
62
|
|
|
71
63
|
if (isKookWebhookChallenge(event)) {
|
|
72
64
|
if (!verifyKookWebhookToken(handler.endpointConfig.verifyToken, event.verify_token)) {
|
|
73
|
-
|
|
74
|
-
response.end(JSON.stringify({ message: 'Invalid verify_token' }));
|
|
75
|
-
return;
|
|
65
|
+
return new Response(JSON.stringify({ message: 'Invalid verify_token' }), { status: 403, headers: { 'Content-Type': 'application/json' } });
|
|
76
66
|
}
|
|
77
|
-
|
|
78
|
-
response.end(JSON.stringify({ challenge: event.challenge ?? '' }));
|
|
79
|
-
return;
|
|
67
|
+
return new Response(JSON.stringify({ challenge: event.challenge ?? '' }), { status: 200, headers: { 'Content-Type': 'application/json' } });
|
|
80
68
|
}
|
|
81
69
|
|
|
82
70
|
if (!verifyKookWebhookToken(handler.endpointConfig.verifyToken, event.verify_token)) {
|
|
83
|
-
|
|
84
|
-
response.end(JSON.stringify({ message: 'Invalid verify_token' }));
|
|
85
|
-
return;
|
|
71
|
+
return new Response(JSON.stringify({ message: 'Invalid verify_token' }), { status: 403, headers: { 'Content-Type': 'application/json' } });
|
|
86
72
|
}
|
|
87
73
|
|
|
88
74
|
if (!handler.isOpen) {
|
|
89
|
-
|
|
90
|
-
response.end(JSON.stringify({ message: 'Endpoint unavailable' }));
|
|
91
|
-
return;
|
|
75
|
+
return new Response(JSON.stringify({ message: 'Endpoint unavailable' }), { status: 503, headers: { 'Content-Type': 'application/json' } });
|
|
92
76
|
}
|
|
93
|
-
await handler[endpointSpec].events.run(async () => {
|
|
77
|
+
return await handler[endpointSpec].events.run(async () => {
|
|
94
78
|
if (frame.sn != null) {
|
|
95
79
|
if (!handler.checkAndRememberSn(frame.sn)) {
|
|
96
|
-
|
|
97
|
-
response.end(JSON.stringify({ message: 'OK' }));
|
|
98
|
-
return;
|
|
80
|
+
return new Response(JSON.stringify({ message: 'OK' }), { status: 200, headers: { 'Content-Type': 'application/json' } });
|
|
99
81
|
}
|
|
100
82
|
}
|
|
101
83
|
|
|
@@ -103,17 +85,13 @@ export async function handleKookWebhookRequest(
|
|
|
103
85
|
await handler.admitEvent(event);
|
|
104
86
|
} catch {
|
|
105
87
|
if (frame.sn != null) handler.forgetSn?.(frame.sn);
|
|
106
|
-
|
|
107
|
-
response.end(JSON.stringify({ message: 'Admission unavailable' }));
|
|
108
|
-
return;
|
|
88
|
+
return new Response(JSON.stringify({ message: 'Admission unavailable' }), { status: 503, headers: { 'Content-Type': 'application/json' } });
|
|
109
89
|
}
|
|
110
90
|
|
|
111
|
-
|
|
112
|
-
response.end(JSON.stringify({ message: 'OK' }));
|
|
91
|
+
return new Response(JSON.stringify({ message: 'OK' }), { status: 200, headers: { 'Content-Type': 'application/json' } });
|
|
113
92
|
});
|
|
114
93
|
} catch (error) {
|
|
115
94
|
logger.error('KOOK webhook error:', error);
|
|
116
|
-
|
|
117
|
-
response.end(JSON.stringify({ message: 'OK' }));
|
|
95
|
+
return new Response(JSON.stringify({ message: 'OK' }), { status: 200, headers: { 'Content-Type': 'application/json' } });
|
|
118
96
|
}
|
|
119
97
|
}
|