@actagent/synology-chat 2026.6.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.md ADDED
@@ -0,0 +1,11 @@
1
+ # ACTAgent Synology Chat
2
+
3
+ Official ACTAgent channel plugin for Synology Chat conversations and direct messages.
4
+
5
+ Install from ACTAgent:
6
+
7
+ ```bash
8
+ actagent plugin add @actagent/synology-chat
9
+ ```
10
+
11
+ Configure Synology Chat credentials and allowed conversations in ACTAgent, then use the plugin to route messages between Synology Chat and ACTAgent agents.
@@ -0,0 +1,24 @@
1
+ {
2
+ "id": "synology-chat",
3
+ "name": "Synology Chat",
4
+ "description": "Synology Chat channel plugin for ACTAgent channels and direct messages.",
5
+ "activation": {
6
+ "onStartup": false
7
+ },
8
+ "channels": ["synology-chat"],
9
+ "channelEnvVars": {
10
+ "synology-chat": [
11
+ "SYNOLOGY_CHAT_TOKEN",
12
+ "SYNOLOGY_CHAT_INCOMING_URL",
13
+ "SYNOLOGY_NAS_HOST",
14
+ "SYNOLOGY_ALLOWED_USER_IDS",
15
+ "SYNOLOGY_RATE_LIMIT",
16
+ "ACTAGENT_BOT_NAME"
17
+ ]
18
+ },
19
+ "configSchema": {
20
+ "type": "object",
21
+ "additionalProperties": false,
22
+ "properties": {}
23
+ }
24
+ }
package/api.ts ADDED
@@ -0,0 +1,4 @@
1
+ // Synology Chat API module exposes the plugin public contract.
2
+ export { synologyChatPlugin } from "./src/channel.js";
3
+ export { setSynologyRuntime } from "./src/runtime.js";
4
+ export { collectSynologyChatSecurityAuditFindings } from "./src/security-audit.js";
@@ -0,0 +1,2 @@
1
+ // Synology Chat API module exposes the plugin public contract.
2
+ export { synologyChatPlugin } from "./src/channel.js";
@@ -0,0 +1,2 @@
1
+ // Synology Chat API module exposes the plugin public contract.
2
+ export { collectSynologyChatSecurityAuditFindings } from "./src/security-audit.js";
package/index.ts ADDED
@@ -0,0 +1,17 @@
1
+ // Synology Chat plugin entrypoint registers its ACTAgent integration.
2
+ import { defineBundledChannelEntry } from "actagent/plugin-sdk/channel-entry-contract";
3
+
4
+ export default defineBundledChannelEntry({
5
+ id: "synology-chat",
6
+ name: "Synology Chat",
7
+ description: "Native Synology Chat channel plugin for ACTAgent",
8
+ importMetaUrl: import.meta.url,
9
+ plugin: {
10
+ specifier: "./channel-plugin-api.js",
11
+ exportName: "synologyChatPlugin",
12
+ },
13
+ runtime: {
14
+ specifier: "./api.js",
15
+ exportName: "setSynologyRuntime",
16
+ },
17
+ });
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@actagent/synology-chat",
3
+ "version": "2026.6.2",
4
+ "lockfileVersion": 3,
5
+ "requires": true,
6
+ "packages": {
7
+ "": {
8
+ "name": "@actagent/synology-chat",
9
+ "version": "2026.6.2",
10
+ "dependencies": {
11
+ "zod": "4.4.3"
12
+ }
13
+ },
14
+ "node_modules/zod": {
15
+ "version": "4.4.3",
16
+ "resolved": "https://registry.npmjs.org/zod/-/zod-4.4.3.tgz",
17
+ "integrity": "sha512-ytENFjIJFl2UwYglde2jchW2Hwm4GJFLDiSXWdTrJQBIN9Fcyp7n4DhxJEiWNAJMV1/BqWfW/kkg71UDcHJyTQ==",
18
+ "license": "MIT",
19
+ "funding": {
20
+ "url": "https://github.com/sponsors/colinhacks"
21
+ }
22
+ }
23
+ }
24
+ }
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@actagent/synology-chat",
3
+ "version": "2026.6.2",
4
+ "description": "Synology Chat channel plugin for ACTAgent channels and direct messages.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/actagent/actagent"
8
+ },
9
+ "type": "module",
10
+ "devDependencies": {
11
+ "@actagent/plugin-sdk": "workspace:*"
12
+ },
13
+ "actagent": {
14
+ "extensions": [
15
+ "./index.ts"
16
+ ],
17
+ "setupEntry": "./setup-entry.ts",
18
+ "channel": {
19
+ "id": "synology-chat",
20
+ "label": "Synology Chat",
21
+ "selectionLabel": "Synology Chat (Webhook)",
22
+ "docsPath": "/channels/synology-chat",
23
+ "docsLabel": "synology-chat",
24
+ "blurb": "Connect your Synology NAS Chat to ACTAgent with full agent capabilities.",
25
+ "order": 90
26
+ },
27
+ "install": {
28
+ "npmSpec": "@actagent/synology-chat",
29
+ "defaultChoice": "npm",
30
+ "minHostVersion": ">=2026.4.10"
31
+ },
32
+ "compat": {
33
+ "pluginApi": ">=2026.6.2"
34
+ },
35
+ "build": {
36
+ "actagentVersion": "2026.6.2"
37
+ },
38
+ "release": {
39
+ "publishToACTAgentHub": true,
40
+ "publishToNpm": true
41
+ }
42
+ },
43
+ "dependencies": {
44
+ "zod": "4.4.3"
45
+ }
46
+ }
package/setup-api.ts ADDED
@@ -0,0 +1,2 @@
1
+ // Synology Chat API module exposes the plugin public contract.
2
+ export { synologyChatSetupAdapter, synologyChatSetupWizard } from "./src/setup-surface.js";
package/setup-entry.ts ADDED
@@ -0,0 +1,10 @@
1
+ // Synology Chat plugin module implements setup entry behavior.
2
+ import { defineBundledChannelSetupEntry } from "actagent/plugin-sdk/channel-entry-contract";
3
+
4
+ export default defineBundledChannelSetupEntry({
5
+ importMetaUrl: import.meta.url,
6
+ plugin: {
7
+ specifier: "./api.js",
8
+ exportName: "synologyChatPlugin",
9
+ },
10
+ });
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Account resolution: reads config from channels.synology-chat,
3
+ * merges per-account overrides, falls back to environment variables.
4
+ */
5
+
6
+ import {
7
+ DEFAULT_ACCOUNT_ID,
8
+ listCombinedAccountIds,
9
+ resolveMergedAccountConfig,
10
+ type ACTAgentConfig,
11
+ } from "actagent/plugin-sdk/account-resolution";
12
+ import { resolveDangerousNameMatchingEnabled } from "actagent/plugin-sdk/dangerous-name-runtime";
13
+ import { parseStrictInteger } from "actagent/plugin-sdk/number-runtime";
14
+ import { normalizeStringEntries } from "actagent/plugin-sdk/string-coerce-runtime";
15
+ import type {
16
+ SynologyChatChannelConfig,
17
+ ResolvedSynologyChatAccount,
18
+ SynologyWebhookPathSource,
19
+ } from "./types.js";
20
+
21
+ /** Extract the channel config from the full ACTAgent config object. */
22
+ function getChannelConfig(cfg: ACTAgentConfig): SynologyChatChannelConfig | undefined {
23
+ return cfg?.channels?.["synology-chat"] as SynologyChatChannelConfig | undefined;
24
+ }
25
+
26
+ function resolveImplicitAccountId(channelCfg: SynologyChatChannelConfig): string | undefined {
27
+ return channelCfg.token || process.env.SYNOLOGY_CHAT_TOKEN ? DEFAULT_ACCOUNT_ID : undefined;
28
+ }
29
+
30
+ function getRawAccountConfig(
31
+ channelCfg: SynologyChatChannelConfig,
32
+ accountId: string,
33
+ ): SynologyChatChannelConfig {
34
+ if (accountId === DEFAULT_ACCOUNT_ID) {
35
+ return channelCfg;
36
+ }
37
+ return channelCfg.accounts?.[accountId] ?? {};
38
+ }
39
+
40
+ function hasExplicitWebhookPath(rawAccount: SynologyChatChannelConfig | undefined): boolean {
41
+ return typeof rawAccount?.webhookPath === "string" && rawAccount.webhookPath.trim().length > 0;
42
+ }
43
+
44
+ function resolveWebhookPathSource(params: {
45
+ accountId: string;
46
+ channelCfg: SynologyChatChannelConfig;
47
+ rawAccount: SynologyChatChannelConfig;
48
+ }): SynologyWebhookPathSource {
49
+ if (hasExplicitWebhookPath(params.rawAccount)) {
50
+ return "explicit";
51
+ }
52
+ if (params.accountId !== DEFAULT_ACCOUNT_ID && hasExplicitWebhookPath(params.channelCfg)) {
53
+ return "inherited-base";
54
+ }
55
+ return "default";
56
+ }
57
+
58
+ /** Parse allowedUserIds from string or array to string[]. */
59
+ function parseAllowedUserIds(raw: string | string[] | undefined): string[] {
60
+ if (!raw) {
61
+ return [];
62
+ }
63
+ if (Array.isArray(raw)) {
64
+ return raw.filter(Boolean);
65
+ }
66
+ return normalizeStringEntries(raw.split(","));
67
+ }
68
+
69
+ function normalizeRateLimitPerMinuteValue(raw: unknown): number | undefined {
70
+ if (typeof raw === "number") {
71
+ return Number.isSafeInteger(raw) && raw >= 0 ? raw : undefined;
72
+ }
73
+ if (typeof raw !== "string") {
74
+ return undefined;
75
+ }
76
+ const trimmed = raw.trim();
77
+ if (!/^\d+$/.test(trimmed)) {
78
+ return undefined;
79
+ }
80
+ const parsed = parseStrictInteger(trimmed);
81
+ return parsed != null && parsed >= 0 ? parsed : undefined;
82
+ }
83
+
84
+ function parseRateLimitPerMinute(raw: string | undefined): number {
85
+ return normalizeRateLimitPerMinuteValue(raw) ?? 30;
86
+ }
87
+
88
+ /**
89
+ * List all configured account IDs for this channel.
90
+ * Returns ["default"] if there's a base config, plus any named accounts.
91
+ */
92
+ export function listAccountIds(cfg: ACTAgentConfig): string[] {
93
+ const channelCfg = getChannelConfig(cfg);
94
+ if (!channelCfg) {
95
+ return [];
96
+ }
97
+
98
+ return listCombinedAccountIds({
99
+ configuredAccountIds: Object.keys(channelCfg.accounts ?? {}),
100
+ implicitAccountId: resolveImplicitAccountId(channelCfg),
101
+ });
102
+ }
103
+
104
+ /**
105
+ * Resolve a specific account by ID with full defaults applied.
106
+ * Falls back to env vars for the "default" account.
107
+ */
108
+ export function resolveAccount(
109
+ cfg: ACTAgentConfig,
110
+ accountId?: string | null,
111
+ ): ResolvedSynologyChatAccount {
112
+ const channelCfg = getChannelConfig(cfg) ?? {};
113
+ const id = accountId || DEFAULT_ACCOUNT_ID;
114
+ const accountOverrides =
115
+ id === DEFAULT_ACCOUNT_ID ? undefined : (channelCfg.accounts?.[id] ?? undefined);
116
+ const rawAccount = getRawAccountConfig(channelCfg, id);
117
+ const merged = resolveMergedAccountConfig<Record<string, unknown> & SynologyChatChannelConfig>({
118
+ channelConfig: channelCfg as Record<string, unknown> & SynologyChatChannelConfig,
119
+ accounts: channelCfg.accounts as
120
+ | Record<string, Partial<Record<string, unknown> & SynologyChatChannelConfig>>
121
+ | undefined,
122
+ accountId: id,
123
+ });
124
+
125
+ // Env var fallbacks (primarily for the "default" account)
126
+ const envToken = process.env.SYNOLOGY_CHAT_TOKEN ?? "";
127
+ const envIncomingUrl = process.env.SYNOLOGY_CHAT_INCOMING_URL ?? "";
128
+ const envNasHost = process.env.SYNOLOGY_NAS_HOST ?? "localhost";
129
+ const envAllowedUserIds = process.env.SYNOLOGY_ALLOWED_USER_IDS ?? "";
130
+ const envRateLimitValue = parseRateLimitPerMinute(process.env.SYNOLOGY_RATE_LIMIT);
131
+ const envBotName = process.env.ACTAGENT_BOT_NAME ?? "ACTAgent";
132
+ const webhookPathSource = resolveWebhookPathSource({ accountId: id, channelCfg, rawAccount });
133
+ const dangerouslyAllowInheritedWebhookPath =
134
+ rawAccount.dangerouslyAllowInheritedWebhookPath ??
135
+ channelCfg.dangerouslyAllowInheritedWebhookPath ??
136
+ false;
137
+
138
+ // Merge: account override > base channel config > env var
139
+ return {
140
+ accountId: id,
141
+ enabled: merged.enabled ?? true,
142
+ token: merged.token ?? envToken,
143
+ incomingUrl: merged.incomingUrl ?? envIncomingUrl,
144
+ nasHost: merged.nasHost ?? envNasHost,
145
+ webhookPath: merged.webhookPath ?? "/webhook/synology",
146
+ webhookPathSource,
147
+ dangerouslyAllowNameMatching: resolveDangerousNameMatchingEnabled({
148
+ providerConfig: channelCfg,
149
+ accountConfig: accountOverrides,
150
+ }),
151
+ dangerouslyAllowInheritedWebhookPath,
152
+ dmPolicy: merged.dmPolicy ?? "allowlist",
153
+ allowedUserIds: parseAllowedUserIds(merged.allowedUserIds ?? envAllowedUserIds),
154
+ rateLimitPerMinute:
155
+ normalizeRateLimitPerMinuteValue(merged.rateLimitPerMinute) ?? envRateLimitValue,
156
+ botName: merged.botName ?? envBotName,
157
+ allowInsecureSsl: merged.allowInsecureSsl ?? false,
158
+ };
159
+ }
@@ -0,0 +1,18 @@
1
+ // Synology Chat tests cover approval auth plugin behavior.
2
+ import { describe, expect, it } from "vitest";
3
+ import { synologyChatApprovalAuth } from "./approval-auth.js";
4
+
5
+ describe("synologyChatApprovalAuth", () => {
6
+ it("authorizes numeric Synology Chat user ids", () => {
7
+ const cfg = { channels: { "synology-chat": { allowedUserIds: ["123"] } } };
8
+
9
+ expect(
10
+ synologyChatApprovalAuth.authorizeActorAction({
11
+ cfg,
12
+ senderId: "123",
13
+ action: "approve",
14
+ approvalKind: "plugin",
15
+ }),
16
+ ).toEqual({ authorized: true });
17
+ });
18
+ });
@@ -0,0 +1,23 @@
1
+ // Synology Chat plugin module implements approval auth behavior.
2
+ import {
3
+ createResolvedApproverActionAuthAdapter,
4
+ resolveApprovalApprovers,
5
+ } from "actagent/plugin-sdk/approval-auth-runtime";
6
+ import { resolveAccount } from "./accounts.js";
7
+
8
+ function normalizeSynologyChatApproverId(value: string | number): string | undefined {
9
+ const trimmed = String(value).trim();
10
+ return /^\d+$/.test(trimmed) ? trimmed : undefined;
11
+ }
12
+
13
+ export const synologyChatApprovalAuth = createResolvedApproverActionAuthAdapter({
14
+ channelLabel: "Synology Chat",
15
+ resolveApprovers: ({ cfg, accountId }) => {
16
+ const account = resolveAccount(cfg ?? {}, accountId);
17
+ return resolveApprovalApprovers({
18
+ allowFrom: account.allowedUserIds,
19
+ normalizeApprover: normalizeSynologyChatApproverId,
20
+ });
21
+ },
22
+ normalizeSenderId: (value) => normalizeSynologyChatApproverId(value),
23
+ });
@@ -0,0 +1,205 @@
1
+ // Synology Chat tests cover channel.integration plugin behavior.
2
+ import type { IncomingMessage, ServerResponse } from "node:http";
3
+ import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
4
+ import {
5
+ buildChannelInboundEventContextMock,
6
+ dispatchReplyWithBufferedBlockDispatcher,
7
+ finalizeInboundContextMock,
8
+ registerPluginHttpRouteMock,
9
+ resolveAgentRouteMock,
10
+ setSynologyRuntimeConfigForTest,
11
+ } from "./channel.test-mocks.js";
12
+ import { makeFormBody, makeReq, makeRes } from "./test-http-utils.js";
13
+
14
+ type _RegisteredRoute = {
15
+ path: string;
16
+ accountId: string;
17
+ handler: (req: IncomingMessage, res: ServerResponse) => Promise<void>;
18
+ };
19
+
20
+ let createSynologyChatPlugin: typeof import("./channel.js").createSynologyChatPlugin;
21
+
22
+ function makeStartContext<T>(cfg: T, accountId: string, abortSignal: AbortSignal) {
23
+ setSynologyRuntimeConfigForTest(cfg);
24
+ return {
25
+ cfg,
26
+ accountId,
27
+ log: { info: vi.fn(), warn: vi.fn(), error: vi.fn() },
28
+ abortSignal,
29
+ };
30
+ }
31
+
32
+ function requireRecord(value: unknown, label: string): Record<string, unknown> {
33
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
34
+ throw new Error(`expected ${label} to be a record`);
35
+ }
36
+ return value as Record<string, unknown>;
37
+ }
38
+
39
+ function requireMockCall<TArgs extends unknown[]>(
40
+ mock: { mock: { calls: TArgs[] } },
41
+ index: number,
42
+ label: string,
43
+ ): TArgs {
44
+ const call = mock.mock.calls[index];
45
+ if (!call) {
46
+ throw new Error(`expected ${label}`);
47
+ }
48
+ return call;
49
+ }
50
+
51
+ describe("Synology channel wiring integration", () => {
52
+ beforeAll(async () => {
53
+ ({ createSynologyChatPlugin } = await import("./channel.js"));
54
+ });
55
+
56
+ beforeEach(() => {
57
+ registerPluginHttpRouteMock.mockClear();
58
+ dispatchReplyWithBufferedBlockDispatcher.mockClear();
59
+ buildChannelInboundEventContextMock.mockClear();
60
+ finalizeInboundContextMock.mockClear();
61
+ resolveAgentRouteMock.mockClear();
62
+ setSynologyRuntimeConfigForTest({});
63
+ });
64
+
65
+ it("registers real webhook handler with resolved account config and enforces allowlist", async () => {
66
+ const plugin = createSynologyChatPlugin();
67
+ const abortController = new AbortController();
68
+ const cfg = {
69
+ channels: {
70
+ "synology-chat": {
71
+ enabled: true,
72
+ accounts: {
73
+ alerts: {
74
+ enabled: true,
75
+ token: "valid-token",
76
+ incomingUrl: "https://nas.example.com/incoming",
77
+ webhookPath: "/webhook/synology-alerts",
78
+ dmPolicy: "allowlist",
79
+ allowedUserIds: ["456"],
80
+ },
81
+ },
82
+ },
83
+ },
84
+ };
85
+
86
+ const started = plugin.gateway.startAccount(
87
+ makeStartContext(cfg, "alerts", abortController.signal),
88
+ );
89
+ expect(registerPluginHttpRouteMock).toHaveBeenCalledTimes(1);
90
+
91
+ const firstCall = registerPluginHttpRouteMock.mock.calls[0];
92
+ if (!firstCall) {
93
+ throw new Error("Expected registerPluginHttpRoute to be called");
94
+ }
95
+ const registered = firstCall[0];
96
+ expect(registered.path).toBe("/webhook/synology-alerts");
97
+ expect(registered.accountId).toBe("alerts");
98
+
99
+ const req = makeReq(
100
+ "POST",
101
+ makeFormBody({
102
+ token: "valid-token",
103
+ user_id: "123",
104
+ username: "unauthorized-user",
105
+ text: "Hello",
106
+ }),
107
+ );
108
+ const res = makeRes();
109
+ await registered.handler(req, res);
110
+
111
+ expect(res.status).toBe(403);
112
+ expect(res.body).toContain("not authorized");
113
+ expect(dispatchReplyWithBufferedBlockDispatcher).not.toHaveBeenCalled();
114
+ abortController.abort();
115
+ await started;
116
+ });
117
+
118
+ it("isolates same user_id across different accounts", async () => {
119
+ const plugin = createSynologyChatPlugin();
120
+ const alphaAbortController = new AbortController();
121
+ const betaAbortController = new AbortController();
122
+ const cfg = {
123
+ channels: {
124
+ "synology-chat": {
125
+ enabled: true,
126
+ accounts: {
127
+ alpha: {
128
+ enabled: true,
129
+ token: "token-alpha",
130
+ incomingUrl: "https://nas.example.com/incoming-alpha",
131
+ webhookPath: "/webhook/synology-alpha",
132
+ dmPolicy: "open",
133
+ allowedUserIds: ["*"],
134
+ },
135
+ beta: {
136
+ enabled: true,
137
+ token: "token-beta",
138
+ incomingUrl: "https://nas.example.com/incoming-beta",
139
+ webhookPath: "/webhook/synology-beta",
140
+ dmPolicy: "open",
141
+ allowedUserIds: ["*"],
142
+ },
143
+ },
144
+ },
145
+ },
146
+ session: {
147
+ dmScope: "main" as const,
148
+ },
149
+ };
150
+
151
+ const alphaStarted = plugin.gateway.startAccount(
152
+ makeStartContext(cfg, "alpha", alphaAbortController.signal),
153
+ );
154
+ const betaStarted = plugin.gateway.startAccount(
155
+ makeStartContext(cfg, "beta", betaAbortController.signal),
156
+ );
157
+
158
+ expect(registerPluginHttpRouteMock).toHaveBeenCalledTimes(2);
159
+ const [alphaRoute] = requireMockCall(registerPluginHttpRouteMock, 0, "alpha Synology route");
160
+ const [betaRoute] = requireMockCall(registerPluginHttpRouteMock, 1, "beta Synology route");
161
+
162
+ const alphaReq = makeReq(
163
+ "POST",
164
+ makeFormBody({
165
+ token: "token-alpha",
166
+ user_id: "123",
167
+ username: "alice",
168
+ text: "alpha secret",
169
+ }),
170
+ );
171
+ const alphaRes = makeRes();
172
+ await alphaRoute.handler(alphaReq, alphaRes);
173
+
174
+ const betaReq = makeReq(
175
+ "POST",
176
+ makeFormBody({
177
+ token: "token-beta",
178
+ user_id: "123",
179
+ username: "bob",
180
+ text: "beta secret",
181
+ }),
182
+ );
183
+ const betaRes = makeRes();
184
+ await betaRoute.handler(betaReq, betaRes);
185
+
186
+ expect(alphaRes.status).toBe(204);
187
+ expect(betaRes.status).toBe(204);
188
+ expect(dispatchReplyWithBufferedBlockDispatcher).toHaveBeenCalledTimes(2);
189
+ expect(finalizeInboundContextMock).toHaveBeenCalledTimes(2);
190
+
191
+ const [alphaCtx] = requireMockCall(finalizeInboundContextMock, 0, "alpha inbound context");
192
+ const [betaCtx] = requireMockCall(finalizeInboundContextMock, 1, "beta inbound context");
193
+ const alphaContext = requireRecord(alphaCtx, "alpha inbound context");
194
+ expect(alphaContext.AccountId).toBe("alpha");
195
+ expect(alphaContext.SessionKey).toBe("agent:agent-alpha:synology-chat:alpha:direct:123");
196
+ const betaContext = requireRecord(betaCtx, "beta inbound context");
197
+ expect(betaContext.AccountId).toBe("beta");
198
+ expect(betaContext.SessionKey).toBe("agent:agent-beta:synology-chat:beta:direct:123");
199
+
200
+ alphaAbortController.abort();
201
+ betaAbortController.abort();
202
+ await alphaStarted;
203
+ await betaStarted;
204
+ });
205
+ });