opencode-discord-notify 0.3.0 → 0.3.2
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/README-JP.md +2 -2
- package/README.md +2 -2
- package/dist/index.d.ts +1 -64
- package/dist/index.js +19 -3
- package/package.json +1 -1
package/README-JP.md
CHANGED
|
@@ -63,7 +63,7 @@ OpenCode を再起動してください。
|
|
|
63
63
|
- `DISCORD_WEBHOOK_PERMISSION_MENTION`: `permission.updated` の通知本文に付けるメンション(`DISCORD_WEBHOOK_COMPLETE_MENTION` へのフォールバックなし。`@everyone` または `@here` のみ許容。Forum webhook の仕様上、ping は常に発生しない)
|
|
64
64
|
- `DISCORD_WEBHOOK_EXCLUDE_INPUT_CONTEXT`: `1` のとき input context(`<file>` から始まる user `text` part)を通知しない(デフォルト: `1` / `0` で無効化)
|
|
65
65
|
- `DISCORD_WEBHOOK_SHOW_ERROR_ALERT`: `1` のとき Discord webhook の送信が失敗した場合に OpenCode TUI のトーストを表示します(429 含む)(デフォルト: `1` / `0` で無効化)
|
|
66
|
-
- `
|
|
66
|
+
- `DISCORD_SEND_PARAMS`: embed の fields として送るキーをカンマ区切りで指定。指定可能キー: `sessionID`, `permissionID`, `type`, `pattern`, `messageID`, `callID`, `partID`, `role`, `directory`, `projectID`。未設定・空文字・空要素のみの場合は全て選択。`session.created` は `DISCORD_SEND_PARAMS` に関わらず `sessionID`, `projectID`, `directory` を必ず含みます。
|
|
67
67
|
|
|
68
68
|
## 仕様メモ
|
|
69
69
|
|
|
@@ -88,7 +88,7 @@ OpenCode を再起動してください。
|
|
|
88
88
|
- embed タイトルは `User says` / `Agent says` です
|
|
89
89
|
- `tool`: 通知しない
|
|
90
90
|
- `reasoning`: 通知しない(内部思考が含まれる可能性があるため)
|
|
91
|
-
- `
|
|
91
|
+
- `DISCORD_SEND_PARAMS` の制御対象は embed の fields のみです(title/description/content/timestamp などは対象外)。また `share` は fields としては送りません(Session started の embed URL には `shareUrl` を使います)。
|
|
92
92
|
|
|
93
93
|
## 動作確認(手動)
|
|
94
94
|
|
package/README.md
CHANGED
|
@@ -65,7 +65,7 @@ Optional:
|
|
|
65
65
|
- `DISCORD_WEBHOOK_PERMISSION_MENTION`: mention to put in `permission.updated` messages (no fallback to `DISCORD_WEBHOOK_COMPLETE_MENTION`; only `@everyone` or `@here` supported; Forum webhooks may not actually ping due to Discord behavior)
|
|
66
66
|
- `DISCORD_WEBHOOK_EXCLUDE_INPUT_CONTEXT`: when set to `1`, exclude "input context" (user `text` parts that start with `<file>`) from notifications (default: `1`; set to `0` to disable)
|
|
67
67
|
- `DISCORD_WEBHOOK_SHOW_ERROR_ALERT`: when set to `1`, show an OpenCode TUI toast when Discord webhook requests fail (includes 429). (default: `1`; set to `0` to disable)
|
|
68
|
-
- `
|
|
68
|
+
- `DISCORD_SEND_PARAMS`: comma-separated list of keys to include as embed fields. Allowed keys: `sessionID`, `permissionID`, `type`, `pattern`, `messageID`, `callID`, `partID`, `role`, `directory`, `projectID`. If unset, empty, or containing only empty elements, all keys are selected. `session.created` always includes `sessionID`, `projectID`, `directory` regardless.
|
|
69
69
|
|
|
70
70
|
## Notes / behavior
|
|
71
71
|
|
|
@@ -90,7 +90,7 @@ Optional:
|
|
|
90
90
|
- Embed titles are `User says` / `Agent says`
|
|
91
91
|
- `tool`: not posted
|
|
92
92
|
- `reasoning`: not posted (to avoid exposing internal thoughts)
|
|
93
|
-
- `
|
|
93
|
+
- `DISCORD_SEND_PARAMS` controls embed fields only (it does not affect title/description/content/timestamp). `share` is not an embed field (but Session started uses `shareUrl` as the embed URL).
|
|
94
94
|
|
|
95
95
|
## Manual test
|
|
96
96
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,68 +1,5 @@
|
|
|
1
1
|
import { Plugin } from '@opencode-ai/plugin';
|
|
2
2
|
|
|
3
|
-
type DiscordWebhookMessageResponse = {
|
|
4
|
-
id: string;
|
|
5
|
-
channel_id: string;
|
|
6
|
-
};
|
|
7
|
-
type DiscordEmbed = {
|
|
8
|
-
title?: string;
|
|
9
|
-
description?: string;
|
|
10
|
-
url?: string;
|
|
11
|
-
color?: number;
|
|
12
|
-
timestamp?: string;
|
|
13
|
-
fields?: Array<{
|
|
14
|
-
name: string;
|
|
15
|
-
value: string;
|
|
16
|
-
inline?: boolean;
|
|
17
|
-
}>;
|
|
18
|
-
};
|
|
19
|
-
type DiscordAllowedMentions = {
|
|
20
|
-
parse?: Array<'everyone' | 'roles' | 'users'>;
|
|
21
|
-
roles?: string[];
|
|
22
|
-
users?: string[];
|
|
23
|
-
};
|
|
24
|
-
type DiscordExecuteWebhookBody = {
|
|
25
|
-
content?: string;
|
|
26
|
-
username?: string;
|
|
27
|
-
avatar_url?: string;
|
|
28
|
-
thread_name?: string;
|
|
29
|
-
embeds?: DiscordEmbed[];
|
|
30
|
-
allowed_mentions?: DiscordAllowedMentions;
|
|
31
|
-
};
|
|
32
|
-
declare function toIsoTimestamp(ms: unknown): string | undefined;
|
|
33
|
-
declare function buildFields(fields: Array<[string, unknown]>, inline?: boolean): DiscordEmbed['fields'];
|
|
34
|
-
declare function buildMention(mention: string | undefined, nameForLog: string): {
|
|
35
|
-
content?: string;
|
|
36
|
-
allowed_mentions?: DiscordAllowedMentions;
|
|
37
|
-
} | undefined;
|
|
38
|
-
declare function buildTodoChecklist(todos: unknown): string;
|
|
39
|
-
type ToastVariant = 'info' | 'success' | 'warning' | 'error';
|
|
40
|
-
type MaybeAlertError = (input: {
|
|
41
|
-
key: string;
|
|
42
|
-
title?: string;
|
|
43
|
-
message: string;
|
|
44
|
-
variant: ToastVariant;
|
|
45
|
-
}) => Promise<void>;
|
|
46
|
-
type PostDiscordWebhookDeps = {
|
|
47
|
-
showErrorAlert: boolean;
|
|
48
|
-
maybeAlertError: MaybeAlertError;
|
|
49
|
-
waitOnRateLimitMs: number;
|
|
50
|
-
fetchImpl?: typeof fetch;
|
|
51
|
-
sleepImpl?: (ms: number) => Promise<void>;
|
|
52
|
-
};
|
|
53
|
-
declare function postDiscordWebhook(input: {
|
|
54
|
-
webhookUrl: string;
|
|
55
|
-
threadId?: string;
|
|
56
|
-
wait?: boolean;
|
|
57
|
-
body: DiscordExecuteWebhookBody;
|
|
58
|
-
}, deps: PostDiscordWebhookDeps): Promise<DiscordWebhookMessageResponse | undefined>;
|
|
59
3
|
declare const plugin: Plugin;
|
|
60
|
-
declare const __test__: {
|
|
61
|
-
buildMention: typeof buildMention;
|
|
62
|
-
buildTodoChecklist: typeof buildTodoChecklist;
|
|
63
|
-
buildFields: typeof buildFields;
|
|
64
|
-
toIsoTimestamp: typeof toIsoTimestamp;
|
|
65
|
-
postDiscordWebhook: typeof postDiscordWebhook;
|
|
66
|
-
};
|
|
67
4
|
|
|
68
|
-
export {
|
|
5
|
+
export { plugin as default };
|
package/dist/index.js
CHANGED
|
@@ -262,7 +262,7 @@ var plugin = async ({ client }) => {
|
|
|
262
262
|
const showErrorAlert = showErrorAlertRaw !== "0";
|
|
263
263
|
const waitOnRateLimitMs = 1e4;
|
|
264
264
|
const toastCooldownMs = 3e4;
|
|
265
|
-
const sendParams = parseSendParams(getEnv("
|
|
265
|
+
const sendParams = parseSendParams(getEnv("DISCORD_SEND_PARAMS"));
|
|
266
266
|
const lastAlertAtByKey = /* @__PURE__ */ new Map();
|
|
267
267
|
const showToast = async ({ title, message, variant }) => {
|
|
268
268
|
try {
|
|
@@ -285,6 +285,19 @@ var plugin = async ({ client }) => {
|
|
|
285
285
|
lastAlertAtByKey.set(key, now);
|
|
286
286
|
await showToast({ title, message, variant });
|
|
287
287
|
};
|
|
288
|
+
const MISSING_URL_KEY = "discord_webhook_missing_url";
|
|
289
|
+
async function showMissingUrlToastOnce() {
|
|
290
|
+
const now = Date.now();
|
|
291
|
+
const last = lastAlertAtByKey.get(MISSING_URL_KEY);
|
|
292
|
+
if (last !== void 0 && now - last < toastCooldownMs) return;
|
|
293
|
+
lastAlertAtByKey.set(MISSING_URL_KEY, now);
|
|
294
|
+
await showToast({
|
|
295
|
+
title: "Discord webhook not configured",
|
|
296
|
+
message: "DISCORD_WEBHOOK_URL is not set. Please configure it to enable Discord notifications.",
|
|
297
|
+
variant: "warning"
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
if (!webhookUrl) void showMissingUrlToastOnce();
|
|
288
301
|
const postDeps = {
|
|
289
302
|
showErrorAlert,
|
|
290
303
|
maybeAlertError,
|
|
@@ -356,6 +369,10 @@ var plugin = async ({ client }) => {
|
|
|
356
369
|
return void 0;
|
|
357
370
|
}
|
|
358
371
|
function enqueueToThread(sessionID, body) {
|
|
372
|
+
if (!webhookUrl) {
|
|
373
|
+
void showMissingUrlToastOnce();
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
359
376
|
const queue = pendingPostsBySession.get(sessionID) ?? [];
|
|
360
377
|
queue.push(body);
|
|
361
378
|
pendingPostsBySession.set(sessionID, queue);
|
|
@@ -571,7 +588,7 @@ var plugin = async ({ client }) => {
|
|
|
571
588
|
}
|
|
572
589
|
};
|
|
573
590
|
};
|
|
574
|
-
|
|
591
|
+
plugin.__test__ = {
|
|
575
592
|
buildMention,
|
|
576
593
|
buildTodoChecklist,
|
|
577
594
|
buildFields,
|
|
@@ -580,6 +597,5 @@ var __test__ = {
|
|
|
580
597
|
};
|
|
581
598
|
var index_default = plugin;
|
|
582
599
|
export {
|
|
583
|
-
__test__,
|
|
584
600
|
index_default as default
|
|
585
601
|
};
|