@ycodium-ai/plugin-webhook-notify 0.1.0

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 (2) hide show
  1. package/dist/index.js +73 -0
  2. package/package.json +36 -0
package/dist/index.js ADDED
@@ -0,0 +1,73 @@
1
+ // ../../packages/plugin-api/src/index.ts
2
+ var PLUGIN_API_VERSION = 1;
3
+ var definePlugin = (definition) => definition;
4
+
5
+ // src/index.ts
6
+ var REQUEST_TIMEOUT_MS = 1e4;
7
+ var readUrl = (config) => {
8
+ const value = config["url"];
9
+ return typeof value === "string" && value.length > 0 ? value : null;
10
+ };
11
+ var describeError = (error) => error instanceof Error ? error.message : String(error);
12
+ var webhookPayload = (event) => ({
13
+ event: event.kind,
14
+ threadId: event.threadId,
15
+ summary: event.summary,
16
+ occurredAt: event.occurredAt,
17
+ eventId: event.eventId
18
+ });
19
+ var webhookNotifyPlugin = definePlugin({
20
+ id: "webhook-notify",
21
+ apiVersion: PLUGIN_API_VERSION,
22
+ activate: (ctx) => {
23
+ const disposeController = new AbortController();
24
+ const notify = async (event) => {
25
+ const url = readUrl(ctx.config);
26
+ if (url === null) return;
27
+ try {
28
+ const response = await ctx.http(url, {
29
+ method: "POST",
30
+ headers: { "content-type": "application/json" },
31
+ body: JSON.stringify(webhookPayload(event)),
32
+ signal: AbortSignal.any([
33
+ AbortSignal.timeout(REQUEST_TIMEOUT_MS),
34
+ disposeController.signal
35
+ ])
36
+ });
37
+ if (!response.ok) {
38
+ ctx.log.warn("webhook notify received a non-2xx response", {
39
+ url,
40
+ status: response.status,
41
+ kind: event.kind
42
+ });
43
+ }
44
+ } catch (error) {
45
+ ctx.log.warn("webhook notify request failed", {
46
+ url,
47
+ kind: event.kind,
48
+ detail: describeError(error)
49
+ });
50
+ }
51
+ };
52
+ ctx.events.on("thread.settled", notify);
53
+ ctx.events.on("thread.failed", notify);
54
+ ctx.settingsCard({
55
+ title: "Webhook notifications",
56
+ description: "POST a JSON notification when a thread settles or fails.",
57
+ fields: [
58
+ {
59
+ key: "url",
60
+ kind: "text",
61
+ label: "Webhook URL",
62
+ description: "Leave empty to disable notifications.",
63
+ placeholder: "https://example.com/hooks/ycodium"
64
+ }
65
+ ]
66
+ });
67
+ ctx.onDispose(() => disposeController.abort());
68
+ }
69
+ });
70
+ var index_default = webhookNotifyPlugin;
71
+ export {
72
+ index_default as default
73
+ };
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@ycodium-ai/plugin-webhook-notify",
3
+ "version": "0.1.0",
4
+ "description": "Posts to a URL you choose whenever a thread finishes or fails.",
5
+ "keywords": [
6
+ "webhook",
7
+ "ycodium",
8
+ "ycodium-plugin"
9
+ ],
10
+ "license": "UNLICENSED",
11
+ "files": [
12
+ "dist"
13
+ ],
14
+ "type": "module",
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "devDependencies": {
19
+ "@effect/vitest": "4.0.0-beta.103",
20
+ "esbuild": "0.28.1",
21
+ "vite-plus": "0.2.2",
22
+ "ycodium-plugin-api": "0.0.35"
23
+ },
24
+ "ycodium": {
25
+ "plugin": "./dist/index.js",
26
+ "displayName": "Webhook notifications",
27
+ "description": "Posts to a URL you choose whenever a thread finishes or fails.",
28
+ "icon": "webhook",
29
+ "permissions": []
30
+ },
31
+ "scripts": {
32
+ "build": "node build.mjs",
33
+ "typecheck": "tsgo --noEmit",
34
+ "test": "vp test run --passWithNoTests"
35
+ }
36
+ }