@gakr-gakr/synology-chat 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.
- package/api.ts +3 -0
- package/autobot.plugin.json +22 -0
- package/channel-plugin-api.ts +1 -0
- package/contract-api.ts +1 -0
- package/index.ts +16 -0
- package/package.json +46 -0
- package/setup-api.ts +1 -0
- package/setup-entry.ts +9 -0
- package/src/accounts.ts +151 -0
- package/src/approval-auth.ts +22 -0
- package/src/channel.test-mocks.ts +176 -0
- package/src/channel.ts +435 -0
- package/src/client.ts +329 -0
- package/src/config-schema.ts +11 -0
- package/src/gateway-runtime.ts +212 -0
- package/src/inbound-context.ts +10 -0
- package/src/inbound-event.ts +175 -0
- package/src/runtime.ts +8 -0
- package/src/security-audit.ts +28 -0
- package/src/security.ts +107 -0
- package/src/session-key.ts +21 -0
- package/src/setup-surface.ts +334 -0
- package/src/types.ts +59 -0
- package/src/webhook-handler.ts +652 -0
- package/tsconfig.json +16 -0
package/api.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "synology-chat",
|
|
3
|
+
"activation": {
|
|
4
|
+
"onStartup": false
|
|
5
|
+
},
|
|
6
|
+
"channels": ["synology-chat"],
|
|
7
|
+
"channelEnvVars": {
|
|
8
|
+
"synology-chat": [
|
|
9
|
+
"SYNOLOGY_CHAT_TOKEN",
|
|
10
|
+
"SYNOLOGY_CHAT_INCOMING_URL",
|
|
11
|
+
"SYNOLOGY_NAS_HOST",
|
|
12
|
+
"SYNOLOGY_ALLOWED_USER_IDS",
|
|
13
|
+
"SYNOLOGY_RATE_LIMIT",
|
|
14
|
+
"AUTOBOT_BOT_NAME"
|
|
15
|
+
]
|
|
16
|
+
},
|
|
17
|
+
"configSchema": {
|
|
18
|
+
"type": "object",
|
|
19
|
+
"additionalProperties": false,
|
|
20
|
+
"properties": {}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { synologyChatPlugin } from "./src/channel.js";
|
package/contract-api.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { collectSynologyChatSecurityAuditFindings } from "./src/security-audit.js";
|
package/index.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineBundledChannelEntry } from "autobot/plugin-sdk/channel-entry-contract";
|
|
2
|
+
|
|
3
|
+
export default defineBundledChannelEntry({
|
|
4
|
+
id: "synology-chat",
|
|
5
|
+
name: "Synology Chat",
|
|
6
|
+
description: "Native Synology Chat channel plugin for AutoBot",
|
|
7
|
+
importMetaUrl: import.meta.url,
|
|
8
|
+
plugin: {
|
|
9
|
+
specifier: "./channel-plugin-api.js",
|
|
10
|
+
exportName: "synologyChatPlugin",
|
|
11
|
+
},
|
|
12
|
+
runtime: {
|
|
13
|
+
specifier: "./api.js",
|
|
14
|
+
exportName: "setSynologyRuntime",
|
|
15
|
+
},
|
|
16
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gakr-gakr/synology-chat",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Synology Chat channel plugin for AutoBot",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/autobot/autobot"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"@gakr-gakr/plugin-sdk": "workspace:*"
|
|
12
|
+
},
|
|
13
|
+
"autobot": {
|
|
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 AutoBot with full agent capabilities.",
|
|
25
|
+
"order": 90
|
|
26
|
+
},
|
|
27
|
+
"install": {
|
|
28
|
+
"npmSpec": "@gakr-gakr/synology-chat",
|
|
29
|
+
"defaultChoice": "npm",
|
|
30
|
+
"minHostVersion": ">=2026.4.10"
|
|
31
|
+
},
|
|
32
|
+
"compat": {
|
|
33
|
+
"pluginApi": ">=2026.5.19"
|
|
34
|
+
},
|
|
35
|
+
"build": {
|
|
36
|
+
"autobotVersion": "2026.5.19"
|
|
37
|
+
},
|
|
38
|
+
"release": {
|
|
39
|
+
"publishToClawHub": true,
|
|
40
|
+
"publishToNpm": true
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"zod": "4.4.3"
|
|
45
|
+
}
|
|
46
|
+
}
|
package/setup-api.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { synologyChatSetupAdapter, synologyChatSetupWizard } from "./src/setup-surface.js";
|
package/setup-entry.ts
ADDED
package/src/accounts.ts
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
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 AutoBotConfig,
|
|
11
|
+
} from "autobot/plugin-sdk/account-resolution";
|
|
12
|
+
import { resolveDangerousNameMatchingEnabled } from "autobot/plugin-sdk/dangerous-name-runtime";
|
|
13
|
+
import type {
|
|
14
|
+
SynologyChatChannelConfig,
|
|
15
|
+
ResolvedSynologyChatAccount,
|
|
16
|
+
SynologyWebhookPathSource,
|
|
17
|
+
} from "./types.js";
|
|
18
|
+
|
|
19
|
+
/** Extract the channel config from the full AutoBot config object. */
|
|
20
|
+
function getChannelConfig(cfg: AutoBotConfig): SynologyChatChannelConfig | undefined {
|
|
21
|
+
return cfg?.channels?.["synology-chat"] as SynologyChatChannelConfig | undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function resolveImplicitAccountId(channelCfg: SynologyChatChannelConfig): string | undefined {
|
|
25
|
+
return channelCfg.token || process.env.SYNOLOGY_CHAT_TOKEN ? DEFAULT_ACCOUNT_ID : undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function getRawAccountConfig(
|
|
29
|
+
channelCfg: SynologyChatChannelConfig,
|
|
30
|
+
accountId: string,
|
|
31
|
+
): SynologyChatChannelConfig {
|
|
32
|
+
if (accountId === DEFAULT_ACCOUNT_ID) {
|
|
33
|
+
return channelCfg;
|
|
34
|
+
}
|
|
35
|
+
return channelCfg.accounts?.[accountId] ?? {};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function hasExplicitWebhookPath(rawAccount: SynologyChatChannelConfig | undefined): boolean {
|
|
39
|
+
return typeof rawAccount?.webhookPath === "string" && rawAccount.webhookPath.trim().length > 0;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function resolveWebhookPathSource(params: {
|
|
43
|
+
accountId: string;
|
|
44
|
+
channelCfg: SynologyChatChannelConfig;
|
|
45
|
+
rawAccount: SynologyChatChannelConfig;
|
|
46
|
+
}): SynologyWebhookPathSource {
|
|
47
|
+
if (hasExplicitWebhookPath(params.rawAccount)) {
|
|
48
|
+
return "explicit";
|
|
49
|
+
}
|
|
50
|
+
if (params.accountId !== DEFAULT_ACCOUNT_ID && hasExplicitWebhookPath(params.channelCfg)) {
|
|
51
|
+
return "inherited-base";
|
|
52
|
+
}
|
|
53
|
+
return "default";
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Parse allowedUserIds from string or array to string[]. */
|
|
57
|
+
function parseAllowedUserIds(raw: string | string[] | undefined): string[] {
|
|
58
|
+
if (!raw) {
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
if (Array.isArray(raw)) {
|
|
62
|
+
return raw.filter(Boolean);
|
|
63
|
+
}
|
|
64
|
+
return raw
|
|
65
|
+
.split(",")
|
|
66
|
+
.map((s) => s.trim())
|
|
67
|
+
.filter(Boolean);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function parseRateLimitPerMinute(raw: string | undefined): number {
|
|
71
|
+
if (raw == null) {
|
|
72
|
+
return 30;
|
|
73
|
+
}
|
|
74
|
+
const trimmed = raw.trim();
|
|
75
|
+
if (!/^-?\d+$/.test(trimmed)) {
|
|
76
|
+
return 30;
|
|
77
|
+
}
|
|
78
|
+
return Number.parseInt(trimmed, 10);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* List all configured account IDs for this channel.
|
|
83
|
+
* Returns ["default"] if there's a base config, plus any named accounts.
|
|
84
|
+
*/
|
|
85
|
+
export function listAccountIds(cfg: AutoBotConfig): string[] {
|
|
86
|
+
const channelCfg = getChannelConfig(cfg);
|
|
87
|
+
if (!channelCfg) {
|
|
88
|
+
return [];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return listCombinedAccountIds({
|
|
92
|
+
configuredAccountIds: Object.keys(channelCfg.accounts ?? {}),
|
|
93
|
+
implicitAccountId: resolveImplicitAccountId(channelCfg),
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Resolve a specific account by ID with full defaults applied.
|
|
99
|
+
* Falls back to env vars for the "default" account.
|
|
100
|
+
*/
|
|
101
|
+
export function resolveAccount(
|
|
102
|
+
cfg: AutoBotConfig,
|
|
103
|
+
accountId?: string | null,
|
|
104
|
+
): ResolvedSynologyChatAccount {
|
|
105
|
+
const channelCfg = getChannelConfig(cfg) ?? {};
|
|
106
|
+
const id = accountId || DEFAULT_ACCOUNT_ID;
|
|
107
|
+
const accountOverrides =
|
|
108
|
+
id === DEFAULT_ACCOUNT_ID ? undefined : (channelCfg.accounts?.[id] ?? undefined);
|
|
109
|
+
const rawAccount = getRawAccountConfig(channelCfg, id);
|
|
110
|
+
const merged = resolveMergedAccountConfig<Record<string, unknown> & SynologyChatChannelConfig>({
|
|
111
|
+
channelConfig: channelCfg as Record<string, unknown> & SynologyChatChannelConfig,
|
|
112
|
+
accounts: channelCfg.accounts as
|
|
113
|
+
| Record<string, Partial<Record<string, unknown> & SynologyChatChannelConfig>>
|
|
114
|
+
| undefined,
|
|
115
|
+
accountId: id,
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// Env var fallbacks (primarily for the "default" account)
|
|
119
|
+
const envToken = process.env.SYNOLOGY_CHAT_TOKEN ?? "";
|
|
120
|
+
const envIncomingUrl = process.env.SYNOLOGY_CHAT_INCOMING_URL ?? "";
|
|
121
|
+
const envNasHost = process.env.SYNOLOGY_NAS_HOST ?? "localhost";
|
|
122
|
+
const envAllowedUserIds = process.env.SYNOLOGY_ALLOWED_USER_IDS ?? "";
|
|
123
|
+
const envRateLimitValue = parseRateLimitPerMinute(process.env.SYNOLOGY_RATE_LIMIT);
|
|
124
|
+
const envBotName = process.env.AUTOBOT_BOT_NAME ?? "AutoBot";
|
|
125
|
+
const webhookPathSource = resolveWebhookPathSource({ accountId: id, channelCfg, rawAccount });
|
|
126
|
+
const dangerouslyAllowInheritedWebhookPath =
|
|
127
|
+
rawAccount.dangerouslyAllowInheritedWebhookPath ??
|
|
128
|
+
channelCfg.dangerouslyAllowInheritedWebhookPath ??
|
|
129
|
+
false;
|
|
130
|
+
|
|
131
|
+
// Merge: account override > base channel config > env var
|
|
132
|
+
return {
|
|
133
|
+
accountId: id,
|
|
134
|
+
enabled: merged.enabled ?? true,
|
|
135
|
+
token: merged.token ?? envToken,
|
|
136
|
+
incomingUrl: merged.incomingUrl ?? envIncomingUrl,
|
|
137
|
+
nasHost: merged.nasHost ?? envNasHost,
|
|
138
|
+
webhookPath: merged.webhookPath ?? "/webhook/synology",
|
|
139
|
+
webhookPathSource,
|
|
140
|
+
dangerouslyAllowNameMatching: resolveDangerousNameMatchingEnabled({
|
|
141
|
+
providerConfig: channelCfg,
|
|
142
|
+
accountConfig: accountOverrides,
|
|
143
|
+
}),
|
|
144
|
+
dangerouslyAllowInheritedWebhookPath,
|
|
145
|
+
dmPolicy: merged.dmPolicy ?? "allowlist",
|
|
146
|
+
allowedUserIds: parseAllowedUserIds(merged.allowedUserIds ?? envAllowedUserIds),
|
|
147
|
+
rateLimitPerMinute: merged.rateLimitPerMinute ?? envRateLimitValue,
|
|
148
|
+
botName: merged.botName ?? envBotName,
|
|
149
|
+
allowInsecureSsl: merged.allowInsecureSsl ?? false,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createResolvedApproverActionAuthAdapter,
|
|
3
|
+
resolveApprovalApprovers,
|
|
4
|
+
} from "autobot/plugin-sdk/approval-auth-runtime";
|
|
5
|
+
import { resolveAccount } from "./accounts.js";
|
|
6
|
+
|
|
7
|
+
function normalizeSynologyChatApproverId(value: string | number): string | undefined {
|
|
8
|
+
const trimmed = String(value).trim();
|
|
9
|
+
return /^\d+$/.test(trimmed) ? trimmed : undefined;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const synologyChatApprovalAuth = createResolvedApproverActionAuthAdapter({
|
|
13
|
+
channelLabel: "Synology Chat",
|
|
14
|
+
resolveApprovers: ({ cfg, accountId }) => {
|
|
15
|
+
const account = resolveAccount(cfg ?? {}, accountId);
|
|
16
|
+
return resolveApprovalApprovers({
|
|
17
|
+
allowFrom: account.allowedUserIds,
|
|
18
|
+
normalizeApprover: normalizeSynologyChatApproverId,
|
|
19
|
+
});
|
|
20
|
+
},
|
|
21
|
+
normalizeSenderId: (value) => normalizeSynologyChatApproverId(value),
|
|
22
|
+
});
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
+
import type { Mock } from "vitest";
|
|
3
|
+
import { vi } from "vitest";
|
|
4
|
+
|
|
5
|
+
type RegisteredRoute = {
|
|
6
|
+
path: string;
|
|
7
|
+
accountId: string;
|
|
8
|
+
handler: (req: IncomingMessage, res: ServerResponse) => Promise<void>;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const registerPluginHttpRouteMock: Mock<(params: RegisteredRoute) => () => void> = vi.fn(
|
|
12
|
+
() => vi.fn(),
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
export const dispatchReplyWithBufferedBlockDispatcher: Mock<
|
|
16
|
+
() => Promise<{ counts: Record<string, number> }>
|
|
17
|
+
> = vi.fn().mockResolvedValue({ counts: {} });
|
|
18
|
+
export const finalizeInboundContextMock: Mock<
|
|
19
|
+
(ctx: Record<string, unknown>) => Record<string, unknown>
|
|
20
|
+
> = vi.fn((ctx) => ctx);
|
|
21
|
+
export const buildChannelInboundEventContextMock: Mock<
|
|
22
|
+
(params: {
|
|
23
|
+
channel: string;
|
|
24
|
+
accountId?: string;
|
|
25
|
+
timestamp?: number;
|
|
26
|
+
from: string;
|
|
27
|
+
sender: { id: string; name?: string };
|
|
28
|
+
conversation: { kind: string; label?: string };
|
|
29
|
+
route: {
|
|
30
|
+
accountId?: string;
|
|
31
|
+
routeSessionKey: string;
|
|
32
|
+
dispatchSessionKey?: string;
|
|
33
|
+
};
|
|
34
|
+
reply: { to: string; originatingTo: string };
|
|
35
|
+
message: {
|
|
36
|
+
rawBody: string;
|
|
37
|
+
bodyForAgent?: string;
|
|
38
|
+
commandBody?: string;
|
|
39
|
+
};
|
|
40
|
+
extra?: Record<string, unknown>;
|
|
41
|
+
}) => Record<string, unknown>
|
|
42
|
+
> = vi.fn((params) =>
|
|
43
|
+
finalizeInboundContextMock({
|
|
44
|
+
Body: params.message.rawBody,
|
|
45
|
+
BodyForAgent: params.message.bodyForAgent ?? params.message.rawBody,
|
|
46
|
+
RawBody: params.message.rawBody,
|
|
47
|
+
CommandBody: params.message.commandBody ?? params.message.rawBody,
|
|
48
|
+
From: params.from,
|
|
49
|
+
To: params.reply.to,
|
|
50
|
+
SessionKey: params.route.dispatchSessionKey ?? params.route.routeSessionKey,
|
|
51
|
+
AccountId: params.route.accountId ?? params.accountId,
|
|
52
|
+
OriginatingChannel: params.channel,
|
|
53
|
+
OriginatingTo: params.reply.originatingTo,
|
|
54
|
+
ChatType: params.conversation.kind,
|
|
55
|
+
SenderName: params.sender.name,
|
|
56
|
+
SenderId: params.sender.id,
|
|
57
|
+
Provider: params.channel,
|
|
58
|
+
Surface: params.channel,
|
|
59
|
+
ConversationLabel: params.conversation.label,
|
|
60
|
+
Timestamp: params.timestamp,
|
|
61
|
+
...params.extra,
|
|
62
|
+
}),
|
|
63
|
+
);
|
|
64
|
+
export const resolveAgentRouteMock: Mock<
|
|
65
|
+
(params: { accountId?: string }) => { agentId: string; sessionKey: string; accountId: string }
|
|
66
|
+
> = vi.fn((params) => {
|
|
67
|
+
const accountId = params.accountId?.trim() || "default";
|
|
68
|
+
return {
|
|
69
|
+
agentId: `agent-${accountId}`,
|
|
70
|
+
sessionKey: `agent:agent-${accountId}:main`,
|
|
71
|
+
accountId,
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
let mockRuntimeConfig: unknown = {};
|
|
75
|
+
|
|
76
|
+
export function setSynologyRuntimeConfigForTest(cfg: unknown): void {
|
|
77
|
+
mockRuntimeConfig = cfg;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function readRequestBodyWithLimitForTest(req: IncomingMessage): Promise<string> {
|
|
81
|
+
return await new Promise<string>((resolve, reject) => {
|
|
82
|
+
const chunks: Buffer[] = [];
|
|
83
|
+
req.on("data", (chunk) => {
|
|
84
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
85
|
+
});
|
|
86
|
+
req.on("end", () => resolve(Buffer.concat(chunks).toString("utf8")));
|
|
87
|
+
req.on("error", reject);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
vi.mock("autobot/plugin-sdk/setup", async () => {
|
|
92
|
+
const actual = await vi.importActual<object>("autobot/plugin-sdk/setup");
|
|
93
|
+
return {
|
|
94
|
+
...actual,
|
|
95
|
+
DEFAULT_ACCOUNT_ID: "default",
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
vi.mock("autobot/plugin-sdk/channel-config-schema", async () => {
|
|
100
|
+
const actual = await vi.importActual<object>("autobot/plugin-sdk/channel-config-schema");
|
|
101
|
+
return {
|
|
102
|
+
...actual,
|
|
103
|
+
buildChannelConfigSchema: vi.fn((schema: unknown) => ({ schema })),
|
|
104
|
+
};
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
vi.mock("autobot/plugin-sdk/webhook-ingress", async () => {
|
|
108
|
+
const actual = await vi.importActual<object>("autobot/plugin-sdk/webhook-ingress");
|
|
109
|
+
return {
|
|
110
|
+
...actual,
|
|
111
|
+
registerPluginHttpRoute: registerPluginHttpRouteMock,
|
|
112
|
+
readRequestBodyWithLimit: vi.fn(readRequestBodyWithLimitForTest),
|
|
113
|
+
isRequestBodyLimitError: vi.fn(() => false),
|
|
114
|
+
requestBodyErrorToText: vi.fn(() => "Request body too large"),
|
|
115
|
+
createFixedWindowRateLimiter: vi.fn(() => ({
|
|
116
|
+
isRateLimited: vi.fn(() => false),
|
|
117
|
+
size: vi.fn(() => 0),
|
|
118
|
+
clear: vi.fn(),
|
|
119
|
+
})),
|
|
120
|
+
};
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
vi.mock("./client.js", () => ({
|
|
124
|
+
sendMessage: vi.fn().mockResolvedValue(true),
|
|
125
|
+
sendFileUrl: vi.fn().mockResolvedValue(true),
|
|
126
|
+
resolveLegacyWebhookNameToChatUserId: vi.fn().mockResolvedValue(undefined),
|
|
127
|
+
}));
|
|
128
|
+
|
|
129
|
+
vi.mock("./runtime.js", () => ({
|
|
130
|
+
getSynologyRuntime: vi.fn(() => ({
|
|
131
|
+
config: { current: vi.fn(() => mockRuntimeConfig) },
|
|
132
|
+
channel: {
|
|
133
|
+
routing: {
|
|
134
|
+
resolveAgentRoute: resolveAgentRouteMock,
|
|
135
|
+
},
|
|
136
|
+
reply: {
|
|
137
|
+
finalizeInboundContext: finalizeInboundContextMock,
|
|
138
|
+
dispatchReplyWithBufferedBlockDispatcher,
|
|
139
|
+
},
|
|
140
|
+
session: {
|
|
141
|
+
resolveStorePath: vi.fn(() => "/tmp/autobot/synology-chat-sessions.json"),
|
|
142
|
+
recordInboundSession: vi.fn(async () => undefined),
|
|
143
|
+
},
|
|
144
|
+
turn: {
|
|
145
|
+
run: vi.fn(async (params) => {
|
|
146
|
+
const input = await params.adapter.ingest(params.raw);
|
|
147
|
+
if (!input) {
|
|
148
|
+
return { admission: { kind: "drop", reason: "ingest-null" }, dispatched: false };
|
|
149
|
+
}
|
|
150
|
+
const resolved = await params.adapter.resolveTurn(input, {
|
|
151
|
+
kind: "message",
|
|
152
|
+
canStartAgentTurn: true,
|
|
153
|
+
});
|
|
154
|
+
const dispatchResult = await resolved.dispatchReplyWithBufferedBlockDispatcher({
|
|
155
|
+
ctx: resolved.ctxPayload,
|
|
156
|
+
cfg: mockRuntimeConfig,
|
|
157
|
+
dispatcherOptions: {
|
|
158
|
+
...resolved.dispatcherOptions,
|
|
159
|
+
deliver: resolved.delivery.deliver,
|
|
160
|
+
onError: resolved.delivery.onError,
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
return {
|
|
164
|
+
admission: { kind: "dispatch" },
|
|
165
|
+
dispatched: true,
|
|
166
|
+
dispatchResult,
|
|
167
|
+
ctxPayload: resolved.ctxPayload,
|
|
168
|
+
routeSessionKey: resolved.routeSessionKey,
|
|
169
|
+
};
|
|
170
|
+
}),
|
|
171
|
+
buildContext: buildChannelInboundEventContextMock,
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
})),
|
|
175
|
+
setSynologyRuntime: vi.fn(),
|
|
176
|
+
}));
|