@zhin.js/adapter-discord 1.1.18 → 1.1.20
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 +46 -0
- package/README.md +10 -3
- package/adapters/discord/index.js +3 -23
- package/adapters/discord/index.ts +2 -27
- package/agents/discord/skills/discord/tools/send_embed/index.js +1 -1
- package/agents/discord/skills/discord/tools/send_embed/index.ts +1 -1
- package/agents/discord/skills/discord-guild/tools/create_thread/index.js +6 -2
- package/agents/discord/skills/discord-guild/tools/create_thread/index.ts +5 -2
- package/agents/discord/skills/discord-guild/tools/forum_post/index.js +1 -1
- package/agents/discord/skills/discord-guild/tools/forum_post/index.ts +1 -1
- package/commands/discord/endpoint/definition.js +0 -2
- package/commands/discord/endpoint/definition.ts +0 -2
- package/lib/adapter.d.ts +14 -0
- package/lib/adapter.js +55 -0
- package/lib/client.d.ts +9 -9
- package/lib/client.js +0 -2
- package/lib/console-spec.js +9 -0
- package/lib/console.d.ts +1 -7
- package/lib/console.js +2 -5
- package/lib/endpoint.d.ts +36 -32
- package/lib/endpoint.js +174 -170
- package/lib/gateway.d.ts +6 -124
- package/lib/gateway.js +88 -63
- package/lib/index.d.ts +4 -3
- package/lib/index.js +3 -2
- package/lib/protocol.d.ts +4 -0
- package/lib/protocol.js +1 -0
- package/lib/webhook.d.ts +2 -3
- package/lib/webhook.js +42 -30
- package/package.json +18 -18
- package/plugin.js +1 -4
- package/src/adapter.ts +38 -0
- package/src/client.ts +6 -12
- package/src/console-spec.ts +9 -0
- package/src/console.ts +2 -6
- package/src/endpoint.ts +197 -172
- package/src/gateway.ts +103 -151
- package/src/index.ts +2 -3
- package/src/protocol.ts +5 -0
- package/src/webhook.ts +42 -32
- package/lib/discord-runtime-state.d.ts +0 -1
- package/lib/discord-runtime-state.js +0 -6
- package/src/discord-runtime-state.ts +0 -7
package/src/client.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
1
|
+
import type { ClientEvents } from 'discord.js';
|
|
2
|
+
import type { DiscordAdapter } from './adapter.js';
|
|
3
|
+
import type { DiscordGatewayEndpoint, DiscordInteractionsEndpoint } from './endpoint.js';
|
|
3
4
|
import type { DiscordClientTransport } from './gateway.js';
|
|
4
5
|
|
|
5
6
|
/** Exact Client variants produced by the Gateway and Interactions Endpoints. */
|
|
6
|
-
export type DiscordClient =
|
|
7
|
-
export type DiscordClientEventMap = Record<string, unknown>;
|
|
7
|
+
export type DiscordClient = DiscordGatewayEndpoint | DiscordInteractionsEndpoint;
|
|
8
|
+
export type DiscordClientEventMap = { readonly [K in keyof ClientEvents]: ClientEvents[K][0] } & Record<string, unknown>;
|
|
8
9
|
|
|
9
10
|
/** Narrow an adapter Client for Gateway-only SDK operations. */
|
|
10
11
|
export function requireDiscordGatewayClient(client: DiscordClient): DiscordClientTransport {
|
|
@@ -13,12 +14,5 @@ export function requireDiscordGatewayClient(client: DiscordClient): DiscordClien
|
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
declare module '@zhin.js/feature-kit' {
|
|
16
|
-
interface
|
|
17
|
-
readonly discord: {
|
|
18
|
-
readonly client: DiscordClient;
|
|
19
|
-
readonly events: DiscordClientEventMap;
|
|
20
|
-
};
|
|
21
|
-
}
|
|
17
|
+
interface AdapterRegistry { readonly discord: DiscordAdapter; }
|
|
22
18
|
}
|
|
23
|
-
|
|
24
|
-
export const discordClient = defineEndpointClient<DiscordClient, DiscordClientEventMap>('discord');
|
package/src/console-spec.ts
CHANGED
|
@@ -8,6 +8,15 @@ export const discordConsoleSpec = {
|
|
|
8
8
|
adapterDisplayName: 'Discord',
|
|
9
9
|
fields: [
|
|
10
10
|
{ key: 'token', required: true, env: true, description: 'Discord bot token' },
|
|
11
|
+
{ key: 'connection', description: 'gateway or interactions' },
|
|
12
|
+
{ key: 'applicationId', description: 'Application ID for Interactions; identity changes replace the account' },
|
|
13
|
+
{ key: 'publicKey', description: 'Application Ed25519 public key' },
|
|
14
|
+
{ key: 'interactionsPath', description: 'Local Interactions route' },
|
|
15
|
+
{ key: 'restApiProxy.port', type: 'number', description: 'Configured REST loopback proxy port' },
|
|
16
|
+
{ key: 'gatewayFaultProxyUrl', description: 'Configured local Gateway fault proxy URL' },
|
|
17
|
+
{ key: 'defaultActivity.name', description: 'SDK activity name' },
|
|
18
|
+
{ key: 'defaultActivity.type', description: 'PLAYING, STREAMING, LISTENING, WATCHING or COMPETING' },
|
|
19
|
+
{ key: 'defaultActivity.url', description: 'SDK activity URL' },
|
|
11
20
|
] as readonly AdapterConsoleField[],
|
|
12
21
|
docsUrl: 'https://zhin.js.org/adapters/discord',
|
|
13
22
|
readPermission: 'discord:read',
|
package/src/console.ts
CHANGED
|
@@ -3,19 +3,15 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 页面绑定 `pages/index`,读取 / 写入分别要求 `<adapter>:read` / `<adapter>:write`。
|
|
5
5
|
*/
|
|
6
|
-
import { createAdapterConsoleRpc
|
|
6
|
+
import { createAdapterConsoleRpc } from 'zhin.js/adapter';
|
|
7
7
|
import type { PluginConsoleRpc } from 'zhin.js';
|
|
8
|
-
import { discordRuntimeStateToken } from './discord-runtime-state.js';
|
|
9
8
|
import { discordConsoleSpec } from './console-spec.js';
|
|
10
9
|
|
|
11
10
|
export function createDiscordConsoleRpc(
|
|
12
|
-
resources: AdapterConsoleResources,
|
|
13
11
|
getConfig: () => unknown,
|
|
14
12
|
): PluginConsoleRpc {
|
|
15
|
-
const state = resources.use(discordRuntimeStateToken);
|
|
16
13
|
return createAdapterConsoleRpc({
|
|
17
14
|
...discordConsoleSpec,
|
|
18
|
-
running: () => state.endpoints.values(),
|
|
19
15
|
getConfig,
|
|
20
|
-
}
|
|
16
|
+
});
|
|
21
17
|
}
|