@michengai/dsh-im-connect 1.0.11 → 1.0.13
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 +15 -0
- package/CHANGELOG.zh-CN.md +15 -0
- package/README.md +28 -3
- package/README.zh-CN.md +28 -3
- package/client.js +438 -17
- package/lib/api-base.d.ts +21 -0
- package/lib/api-base.d.ts.map +1 -0
- package/lib/api-base.js +51 -0
- package/lib/api-base.js.map +1 -0
- package/lib/channels/channel-image-download.d.ts +8 -5
- package/lib/channels/channel-image-download.d.ts.map +1 -1
- package/lib/channels/channel-image-download.js +70 -2
- package/lib/channels/channel-image-download.js.map +1 -1
- package/lib/channels/diagnostics.d.ts +1 -1
- package/lib/channels/diagnostics.d.ts.map +1 -1
- package/lib/channels/diagnostics.js +2 -2
- package/lib/channels/diagnostics.js.map +1 -1
- package/lib/channels/discord.d.ts +3 -0
- package/lib/channels/discord.d.ts.map +1 -1
- package/lib/channels/discord.js +56 -7
- package/lib/channels/discord.js.map +1 -1
- package/lib/channels/factory.d.ts.map +1 -1
- package/lib/channels/factory.js +8 -2
- package/lib/channels/factory.js.map +1 -1
- package/lib/channels/file-send.d.ts +1 -1
- package/lib/channels/file-send.d.ts.map +1 -1
- package/lib/channels/file-send.js +2 -2
- package/lib/channels/file-send.js.map +1 -1
- package/lib/channels/meta.d.ts +2 -0
- package/lib/channels/meta.d.ts.map +1 -1
- package/lib/channels/meta.js +2 -0
- package/lib/channels/meta.js.map +1 -1
- package/lib/channels/telegram.d.ts +2 -0
- package/lib/channels/telegram.d.ts.map +1 -1
- package/lib/channels/telegram.js +29 -6
- package/lib/channels/telegram.js.map +1 -1
- package/lib/client.js +523 -21
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +10 -6
- package/lib/index.js.map +1 -1
- package/lib/manager.d.ts +15 -0
- package/lib/manager.d.ts.map +1 -1
- package/lib/manager.js +221 -32
- package/lib/manager.js.map +1 -1
- package/lib/plugin-updater.d.ts +1 -0
- package/lib/plugin-updater.d.ts.map +1 -1
- package/lib/plugin-updater.js +7 -0
- package/lib/plugin-updater.js.map +1 -1
- package/package.json +5 -4
- package/src/api-base.ts +45 -0
- package/src/channels/channel-image-download.ts +83 -5
- package/src/channels/diagnostics.ts +2 -2
- package/src/channels/discord.ts +49 -7
- package/src/channels/factory.ts +8 -2
- package/src/channels/file-send.ts +2 -2
- package/src/channels/meta.ts +4 -0
- package/src/channels/telegram.ts +22 -6
- package/src/index.ts +12 -6
- package/src/manager.ts +214 -31
- package/src/plugin-update-ui.js +36 -5
- package/src/plugin-updater.ts +8 -1
package/lib/index.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ export interface PluginConfig {
|
|
|
14
14
|
agentPreset: string;
|
|
15
15
|
mergeTimeoutSecs: number;
|
|
16
16
|
topicNaming: TopicMode;
|
|
17
|
+
updater?: boolean;
|
|
18
|
+
onlineUpdate?: boolean;
|
|
17
19
|
}
|
|
18
20
|
export declare const Config: Schema<PluginConfig>;
|
|
19
21
|
export declare function apply(ctx: Context, config: PluginConfig): void;
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,MAAM,MAAM,0BAA0B,CAAA;AAM7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAIxD,eAAO,MAAM,IAAI,mBAAmB,CAAA;AACpC,eAAO,MAAM,MAAM,UAQlB,CAAA;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAA;IAChB,GAAG,EAAE,MAAM,CAAA;IACX,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,MAAM,CAAA;IACnB,gBAAgB,EAAE,MAAM,CAAA;IACxB,WAAW,EAAE,SAAS,CAAA;CACvB;AAED,eAAO,MAAM,MAAM,EAAE,MAAM,CAAC,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,MAAM,MAAM,0BAA0B,CAAA;AAM7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAIxD,eAAO,MAAM,IAAI,mBAAmB,CAAA;AACpC,eAAO,MAAM,MAAM,UAQlB,CAAA;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAA;IAChB,GAAG,EAAE,MAAM,CAAA;IACX,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,MAAM,CAAA;IACnB,gBAAgB,EAAE,MAAM,CAAA;IACxB,WAAW,EAAE,SAAS,CAAA;IACtB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB;AAED,eAAO,MAAM,MAAM,EAAE,MAAM,CAAC,YAAY,CAUtC,CAAA;AAEF,wBAAgB,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI,CA2C9D;AAED,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACjF,OAAO,EACL,SAAS,EACT,iBAAiB,EACjB,iBAAiB,EACjB,UAAU,EACV,aAAa,EACb,aAAa,EACb,YAAY,GACb,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA"}
|
package/lib/index.js
CHANGED
|
@@ -23,13 +23,11 @@ export const Config = Schema.object({
|
|
|
23
23
|
agentPreset: Schema.string().default('standard'),
|
|
24
24
|
mergeTimeoutSecs: Schema.number().default(5),
|
|
25
25
|
topicNaming: Schema.union(['once', 'follow', 'off']).default('once'),
|
|
26
|
+
updater: Schema.boolean(),
|
|
27
|
+
onlineUpdate: Schema.boolean(),
|
|
26
28
|
});
|
|
27
29
|
export function apply(ctx, config) {
|
|
28
|
-
|
|
29
|
-
endpoint: '/api/michengai/dsh-im-connect/update',
|
|
30
|
-
packageName: '@michengai/dsh-im-connect',
|
|
31
|
-
manifestUrl: new URL('../package.json', import.meta.url),
|
|
32
|
-
}), 'im-connect.plugin-updater');
|
|
30
|
+
const hostUpdateDisabled = config.updater === false || config.onlineUpdate === false;
|
|
33
31
|
const permissionPresets = ctx.permissionPresets;
|
|
34
32
|
const stateDir = config.stateDir !== ''
|
|
35
33
|
? config.stateDir
|
|
@@ -52,8 +50,14 @@ export function apply(ctx, config) {
|
|
|
52
50
|
topicNaming: config.topicNaming ?? 'once',
|
|
53
51
|
};
|
|
54
52
|
const applyStarted = Date.now();
|
|
55
|
-
const manager = new ChannelManager({ ctx, stateDir, log, engineConfig });
|
|
53
|
+
const manager = new ChannelManager({ ctx, stateDir, log, engineConfig, hostUpdateDisabled });
|
|
56
54
|
log(`[boot] ChannelManager 构造 ${Date.now() - applyStarted}ms`);
|
|
55
|
+
ctx.effect(() => registerPluginUpdater(ctx, {
|
|
56
|
+
endpoint: '/api/michengai/dsh-im-connect/update',
|
|
57
|
+
packageName: '@michengai/dsh-im-connect',
|
|
58
|
+
manifestUrl: new URL('../package.json', import.meta.url),
|
|
59
|
+
isEnabled: async () => !hostUpdateDisabled && manager.isUpdateEnabled(),
|
|
60
|
+
}), 'im-connect.plugin-updater');
|
|
57
61
|
ctx.effect(() => {
|
|
58
62
|
manager.registerApi(ctx);
|
|
59
63
|
// 卸载或初始化失败后不再恢复会话;保留一个完整异常链,避免后台拒绝终止宿主。
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,MAAM,MAAM,0BAA0B,CAAA;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAG7C,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAA;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAE3D,MAAM,CAAC,MAAM,IAAI,GAAG,gBAAgB,CAAA;AACpC,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,WAAW;IACX,aAAa;IACb,QAAQ;IACR,cAAc;IACd,mBAAmB;IACnB,KAAK;IACL,mBAAmB;CACpB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,MAAM,MAAM,0BAA0B,CAAA;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAG7C,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAA;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAE3D,MAAM,CAAC,MAAM,IAAI,GAAG,gBAAgB,CAAA;AACpC,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,WAAW;IACX,aAAa;IACb,QAAQ;IACR,cAAc;IACd,mBAAmB;IACnB,KAAK;IACL,mBAAmB;CACpB,CAAA;AAcD,MAAM,CAAC,MAAM,MAAM,GAAyB,MAAM,CAAC,MAAM,CAAC;IACxD,QAAQ,EAA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AAK,IAAI,EAAE,CAAC,CAAC,kBAAkB,IAAI,OAAO,CAAC,eAAe,EAAE;KACxE,CAAC,EAAE,2BAA2B,CAAC,CAAA;IAChC,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE;QACd,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;QACxB,wCAAwC;QACxC,KAAK,OAAO,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,oBAAoB,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;YAClF,OAAO,CAAC,MAAM,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,kBAAkB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QACzH,CAAC,CAAC,CAAA;QACF,GAAG,CAAC,mBAAmB,IAAI,CAAC,GAAG,EAAE,GAAG,YAAY,IAAI,CAAC,CAAA;QACrD,OAAO,GAAG,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,KAAK,OAAO,CAAC,KAAK,EAAE,CAAA,CAAC,CAAC,CAAA;IAC7D,CAAC,EAAE,kBAAkB,CAAC,CAAA;AACxB,CAAC;AAED,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACjF,OAAO,EACL,SAAS,EACT,iBAAiB,EACjB,iBAAiB,EACjB,UAAU,EACV,aAAa,EACb,aAAa,EACb,YAAY,GACb,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA"}
|
package/lib/manager.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { ChannelId, SessionRecord } from './engine/session-id.js';
|
|
|
6
6
|
import { type AssistantModel, type PermissionPreset } from './engine/assistant-settings.js';
|
|
7
7
|
import type { EngineConfig, SendMode } from './engine/types.js';
|
|
8
8
|
export declare const API_CLIENT_HEADER = "x-dsh-im-connect-client";
|
|
9
|
+
type ChannelProxyMode = 'inherit' | 'direct' | 'custom';
|
|
9
10
|
interface ApiBodyReadResult {
|
|
10
11
|
body: Record<string, unknown>;
|
|
11
12
|
oversized: boolean;
|
|
@@ -54,6 +55,9 @@ export interface AccountView {
|
|
|
54
55
|
commandPermissions: CommandPermissions;
|
|
55
56
|
privateAccess: 'approved' | 'all';
|
|
56
57
|
sendMode: SendMode;
|
|
58
|
+
proxyMode: ChannelProxyMode;
|
|
59
|
+
proxyConfigured: boolean;
|
|
60
|
+
proxyUrl?: string;
|
|
57
61
|
lastCheckedAt?: string;
|
|
58
62
|
}
|
|
59
63
|
interface AccountDiagnosticResult {
|
|
@@ -75,6 +79,7 @@ export interface ChannelView {
|
|
|
75
79
|
key: string;
|
|
76
80
|
label: string;
|
|
77
81
|
secret?: boolean;
|
|
82
|
+
settingsOnly?: boolean;
|
|
78
83
|
}>;
|
|
79
84
|
connected: boolean;
|
|
80
85
|
receiveEnabled: boolean;
|
|
@@ -105,8 +110,10 @@ export declare class ChannelManager {
|
|
|
105
110
|
private readonly log;
|
|
106
111
|
private readonly ctx;
|
|
107
112
|
private readonly engineConfig;
|
|
113
|
+
private readonly hostUpdateDisabled;
|
|
108
114
|
private store;
|
|
109
115
|
private readonly running;
|
|
116
|
+
private readonly proxyUrlCache;
|
|
110
117
|
private readonly diagnosticJobs;
|
|
111
118
|
private readonly diagnosticAbort;
|
|
112
119
|
private readonly channelOperations;
|
|
@@ -117,8 +124,11 @@ export declare class ChannelManager {
|
|
|
117
124
|
stateDir: string;
|
|
118
125
|
log: (line: string) => void;
|
|
119
126
|
engineConfig: EngineConfig;
|
|
127
|
+
hostUpdateDisabled?: boolean;
|
|
120
128
|
});
|
|
121
129
|
list(): ChannelView[];
|
|
130
|
+
private hydrateProxyUrl;
|
|
131
|
+
private hydrateProxyUrls;
|
|
122
132
|
private accountView;
|
|
123
133
|
channelSessions(): {
|
|
124
134
|
id: ChannelId;
|
|
@@ -146,6 +156,11 @@ export declare class ChannelManager {
|
|
|
146
156
|
initEnabled(): Promise<void>;
|
|
147
157
|
registerApi(ctx: Context): void;
|
|
148
158
|
disposeApi(): void;
|
|
159
|
+
getSidebarEntry(): boolean;
|
|
160
|
+
setSidebarEntry(enabled: boolean): Promise<boolean>;
|
|
161
|
+
isHostUpdateDisabled(): boolean;
|
|
162
|
+
isUpdateEnabled(): boolean;
|
|
163
|
+
setOnlineUpdate(enabled: boolean): Promise<boolean>;
|
|
149
164
|
currentAssistant(): AssistantModel | undefined;
|
|
150
165
|
updateAccount(accountId: string, input: Record<string, unknown>): Promise<{
|
|
151
166
|
ok: boolean;
|
package/lib/manager.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../src/manager.ts"],"names":[],"mappings":"AACA,OAAO,EAA+B,KAAK,kBAAkB,EAAE,MAAM,iCAAiC,CAAA;AACtG,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAKlD,OAAO,EAAmB,KAAK,eAAe,EAAE,MAAM,gCAAgC,CAAA;AACtF,OAAO,EAAE,KAAK,eAAe,EAA0B,MAAM,2BAA2B,CAAA;AAKxF,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAMtE,OAAO,EAAwE,KAAK,cAAc,EAAE,KAAK,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AACjK,OAAO,KAAK,EAAkB,YAAY,EAAa,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAK1F,eAAO,MAAM,iBAAiB,4BAA4B,CAAA;
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../src/manager.ts"],"names":[],"mappings":"AACA,OAAO,EAA+B,KAAK,kBAAkB,EAAE,MAAM,iCAAiC,CAAA;AACtG,OAAO,KAAK,EAAE,OAAO,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AAO,CAAC,KAAK;CAGd"}
|
package/lib/manager.js
CHANGED
|
@@ -22,6 +22,25 @@ import { sameWorkspacePath } from './engine/workspace-path.js';
|
|
|
22
22
|
export const API_CLIENT_HEADER = 'x-dsh-im-connect-client';
|
|
23
23
|
const MAX_API_BODY_BYTES = 1024 * 1024;
|
|
24
24
|
const ACCOUNT_REMARK_LIMIT = 40;
|
|
25
|
+
const PROXY_SUPPORTED_PLATFORMS = new Set(['telegram', 'discord']);
|
|
26
|
+
function supportsProxy(platform) {
|
|
27
|
+
return PROXY_SUPPORTED_PLATFORMS.has(platform);
|
|
28
|
+
}
|
|
29
|
+
function normalizeProxyUrl(input) {
|
|
30
|
+
if (typeof input !== 'string' || !input.trim())
|
|
31
|
+
return undefined;
|
|
32
|
+
try {
|
|
33
|
+
const url = new URL(input.trim());
|
|
34
|
+
if (!['http:', 'https:'].includes(url.protocol) || !url.hostname || url.port && Number(url.port) > 65535
|
|
35
|
+
|| url.username || url.password
|
|
36
|
+
|| url.pathname !== '/' || url.search || url.hash)
|
|
37
|
+
return undefined;
|
|
38
|
+
return url.toString();
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
25
44
|
/** 消息发送方式只有排队与插话两档;缺失或未知值一律回到排队,保持旧配置语义。 */
|
|
26
45
|
function normalizeSendMode(input) {
|
|
27
46
|
return input === 'steer' ? 'steer' : 'queue';
|
|
@@ -125,8 +144,10 @@ export class ChannelManager {
|
|
|
125
144
|
log;
|
|
126
145
|
ctx;
|
|
127
146
|
engineConfig;
|
|
147
|
+
hostUpdateDisabled;
|
|
128
148
|
store = { channels: {}, allowlist: {}, pending: {} };
|
|
129
149
|
running = new Map();
|
|
150
|
+
proxyUrlCache = new Map();
|
|
130
151
|
diagnosticJobs = new Map();
|
|
131
152
|
diagnosticAbort = new AbortController();
|
|
132
153
|
channelOperations = new KeyedSerialQueue();
|
|
@@ -137,6 +158,7 @@ export class ChannelManager {
|
|
|
137
158
|
this.ctx = options.ctx;
|
|
138
159
|
this.engineConfig = options.engineConfig;
|
|
139
160
|
this.stateDir = options.stateDir;
|
|
161
|
+
this.hostUpdateDisabled = options.hostUpdateDisabled === true;
|
|
140
162
|
this.file = join(options.stateDir, 'channels.json');
|
|
141
163
|
this.sessions = new SessionMapStore(join(options.stateDir, 'sessions.json'));
|
|
142
164
|
this.log = options.log;
|
|
@@ -197,6 +219,37 @@ export class ChannelManager {
|
|
|
197
219
|
};
|
|
198
220
|
});
|
|
199
221
|
}
|
|
222
|
+
async hydrateProxyUrl(accountId, state) {
|
|
223
|
+
const platform = this.platformOf(accountId, state);
|
|
224
|
+
if (!supportsProxy(platform)) {
|
|
225
|
+
this.proxyUrlCache.delete(accountId);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
const config = state.config ?? {};
|
|
229
|
+
if (config.proxyMode !== 'custom') {
|
|
230
|
+
this.proxyUrlCache.delete(accountId);
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
if (this.proxyUrlCache.has(accountId)) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
let proxyUrl = config.proxyUrl;
|
|
237
|
+
if (!proxyUrl && config.proxyUrlRef) {
|
|
238
|
+
try {
|
|
239
|
+
proxyUrl = await this.vault.resolve(config.proxyUrlRef);
|
|
240
|
+
}
|
|
241
|
+
catch {
|
|
242
|
+
this.log(`[manager] ${CHANNEL_META[platform]?.label ?? platform} 代理地址读取失败`);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (proxyUrl)
|
|
246
|
+
this.proxyUrlCache.set(accountId, proxyUrl);
|
|
247
|
+
else
|
|
248
|
+
this.proxyUrlCache.delete(accountId);
|
|
249
|
+
}
|
|
250
|
+
async hydrateProxyUrls() {
|
|
251
|
+
await Promise.all(Object.entries(this.store.channels).map(([accountId, state]) => this.hydrateProxyUrl(accountId, state)));
|
|
252
|
+
}
|
|
200
253
|
accountView(accountId, state) {
|
|
201
254
|
const platform = this.platformOf(accountId, state);
|
|
202
255
|
const config = state.config ?? {};
|
|
@@ -235,6 +288,11 @@ export class ChannelManager {
|
|
|
235
288
|
commandPermissions: normalizeCommandPermissions(state.commandPermissions),
|
|
236
289
|
privateAccess: state.privateAccess === 'all' ? 'all' : 'approved',
|
|
237
290
|
sendMode: normalizeSendMode(state.sendMode),
|
|
291
|
+
proxyMode: supportsProxy(platform) && (config.proxyMode === 'direct' || config.proxyMode === 'custom') ? config.proxyMode : 'inherit',
|
|
292
|
+
proxyConfigured: supportsProxy(platform) && config.proxyMode === 'custom'
|
|
293
|
+
? this.proxyUrlCache.has(accountId)
|
|
294
|
+
: supportsProxy(platform) && Boolean(config.proxyUrlRef || config.proxyUrl),
|
|
295
|
+
...(supportsProxy(platform) && this.proxyUrlCache.has(accountId) ? { proxyUrl: this.proxyUrlCache.get(accountId) } : {}),
|
|
238
296
|
lastCheckedAt: state.lastCheckedAt,
|
|
239
297
|
};
|
|
240
298
|
}
|
|
@@ -366,6 +424,7 @@ export class ChannelManager {
|
|
|
366
424
|
await this.vault.unset(ref);
|
|
367
425
|
}
|
|
368
426
|
delete this.store.channels[id];
|
|
427
|
+
this.proxyUrlCache.delete(id);
|
|
369
428
|
delete this.store.allowlist[id];
|
|
370
429
|
delete this.store.pending[id];
|
|
371
430
|
this.engine.clearAllowed(id);
|
|
@@ -379,6 +438,7 @@ export class ChannelManager {
|
|
|
379
438
|
async initEnabled() {
|
|
380
439
|
if (this.disposed)
|
|
381
440
|
return;
|
|
441
|
+
await this.hydrateProxyUrls();
|
|
382
442
|
const started = Date.now();
|
|
383
443
|
await this.migrateLegacyWeixinToken().catch((error) => {
|
|
384
444
|
this.log(`[manager] 迁移旧版微信 token 失败,已保留原文件: ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -416,16 +476,63 @@ export class ChannelManager {
|
|
|
416
476
|
return body;
|
|
417
477
|
};
|
|
418
478
|
const dispatch = async (method, path, readBody, send) => {
|
|
419
|
-
const payload = () =>
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
479
|
+
const payload = async () => {
|
|
480
|
+
await this.hydrateProxyUrls();
|
|
481
|
+
return {
|
|
482
|
+
ok: true,
|
|
483
|
+
channels: this.list(),
|
|
484
|
+
groups: this.channelSessions(),
|
|
485
|
+
pending: this.pendingRequests(),
|
|
486
|
+
assistant: this.currentAssistant(),
|
|
487
|
+
};
|
|
488
|
+
};
|
|
426
489
|
try {
|
|
427
490
|
// 路由段统一从插件前缀之后开始,身份认证只由下方入口负责。
|
|
428
491
|
const parts = ('/dsh-im-connect/api' + path).split('/').filter(Boolean);
|
|
492
|
+
if (parts[2] === 'sidebar-entry' && parts.length === 3) {
|
|
493
|
+
if (method === 'GET' || method === 'HEAD') {
|
|
494
|
+
send(200, method === 'HEAD' ? undefined : { ok: true, enabled: this.getSidebarEntry() });
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
if (method === 'POST') {
|
|
498
|
+
const body = await readBody();
|
|
499
|
+
if (!body || typeof body.enabled !== 'boolean') {
|
|
500
|
+
send(400, { ok: false, error: 'enabled 必须是布尔值' });
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
const enabled = await this.setSidebarEntry(body.enabled);
|
|
504
|
+
send(200, { ok: true, enabled });
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
send(405, { ok: false, error: 'method not allowed' });
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
if (parts[2] === 'online-update' && parts.length === 3) {
|
|
511
|
+
if (method === 'GET' || method === 'HEAD') {
|
|
512
|
+
send(200, method === 'HEAD' ? undefined : {
|
|
513
|
+
ok: true,
|
|
514
|
+
enabled: this.isUpdateEnabled(),
|
|
515
|
+
locked: this.isHostUpdateDisabled(),
|
|
516
|
+
});
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
if (method === 'POST') {
|
|
520
|
+
if (this.isHostUpdateDisabled()) {
|
|
521
|
+
send(403, { ok: false, error: '在线更新已被宿主配置锁定禁用' });
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
const body = await readBody();
|
|
525
|
+
if (!body || typeof body.enabled !== 'boolean') {
|
|
526
|
+
send(400, { ok: false, error: 'enabled 必须是布尔值' });
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
const enabled = await this.setOnlineUpdate(body.enabled);
|
|
530
|
+
send(200, { ok: true, enabled });
|
|
531
|
+
return;
|
|
532
|
+
}
|
|
533
|
+
send(405, { ok: false, error: 'method not allowed' });
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
429
536
|
if (parts[2] === 'assistant' && parts.length === 3) {
|
|
430
537
|
if (method === 'GET') {
|
|
431
538
|
send(200, {
|
|
@@ -486,7 +593,7 @@ export class ChannelManager {
|
|
|
486
593
|
return;
|
|
487
594
|
}
|
|
488
595
|
if (parts[2] === 'channels' && parts.length === 3 && method === 'GET') {
|
|
489
|
-
send(200, payload());
|
|
596
|
+
send(200, await payload());
|
|
490
597
|
return;
|
|
491
598
|
}
|
|
492
599
|
if (parts[2] === 'channels' && parts.length === 6 && parts[4] === 'qr') {
|
|
@@ -687,6 +794,33 @@ export class ChannelManager {
|
|
|
687
794
|
void this.channelOperations.run(id, () => this.stopOne(id));
|
|
688
795
|
this.engine.dispose();
|
|
689
796
|
}
|
|
797
|
+
getSidebarEntry() {
|
|
798
|
+
return this.store.sidebarEntry === true;
|
|
799
|
+
}
|
|
800
|
+
async setSidebarEntry(enabled) {
|
|
801
|
+
if (typeof enabled !== 'boolean')
|
|
802
|
+
throw new Error('enabled 必须是布尔值');
|
|
803
|
+
this.store.sidebarEntry = enabled;
|
|
804
|
+
this.flush();
|
|
805
|
+
return enabled;
|
|
806
|
+
}
|
|
807
|
+
isHostUpdateDisabled() {
|
|
808
|
+
return this.hostUpdateDisabled;
|
|
809
|
+
}
|
|
810
|
+
isUpdateEnabled() {
|
|
811
|
+
if (this.hostUpdateDisabled)
|
|
812
|
+
return false;
|
|
813
|
+
return this.store.onlineUpdate !== false;
|
|
814
|
+
}
|
|
815
|
+
async setOnlineUpdate(enabled) {
|
|
816
|
+
if (typeof enabled !== 'boolean')
|
|
817
|
+
throw new Error('enabled 必须是布尔值');
|
|
818
|
+
if (this.hostUpdateDisabled)
|
|
819
|
+
throw new Error('在线更新已被宿主配置锁定禁用');
|
|
820
|
+
this.store.onlineUpdate = enabled;
|
|
821
|
+
this.flush();
|
|
822
|
+
return enabled;
|
|
823
|
+
}
|
|
690
824
|
currentAssistant() {
|
|
691
825
|
return normalizeAssistantModel(this.store.assistant ?? this.engineConfig);
|
|
692
826
|
}
|
|
@@ -698,6 +832,24 @@ export class ChannelManager {
|
|
|
698
832
|
if (!state)
|
|
699
833
|
return { ok: false, error: '账号不存在' };
|
|
700
834
|
const platform = this.platformOf(accountId, state);
|
|
835
|
+
const hasProxySettings = Object.hasOwn(input, 'proxyMode') || Object.hasOwn(input, 'proxyUrl');
|
|
836
|
+
if (hasProxySettings && !supportsProxy(platform))
|
|
837
|
+
return { ok: false, error: '当前渠道不支持账号级代理' };
|
|
838
|
+
const previousProxyMode = state.config?.proxyMode === 'direct' || state.config?.proxyMode === 'custom' ? state.config.proxyMode : 'inherit';
|
|
839
|
+
const requestedProxyMode = input.proxyMode === undefined ? previousProxyMode : input.proxyMode;
|
|
840
|
+
if (hasProxySettings && !['inherit', 'direct', 'custom'].includes(String(requestedProxyMode)))
|
|
841
|
+
return { ok: false, error: '代理模式无效' };
|
|
842
|
+
let nextProxyUrl;
|
|
843
|
+
if (supportsProxy(platform) && requestedProxyMode === 'custom') {
|
|
844
|
+
if (typeof input.proxyUrl === 'string' && input.proxyUrl.trim()) {
|
|
845
|
+
nextProxyUrl = normalizeProxyUrl(input.proxyUrl);
|
|
846
|
+
if (!nextProxyUrl)
|
|
847
|
+
return { ok: false, error: '代理地址无效:仅支持不含路径、查询参数、片段或认证信息的 HTTP(S) 代理地址。' };
|
|
848
|
+
}
|
|
849
|
+
else if (!state.config?.proxyUrlRef && !state.config?.proxyUrl) {
|
|
850
|
+
return { ok: false, error: '手动配置代理时必须填写代理地址' };
|
|
851
|
+
}
|
|
852
|
+
}
|
|
701
853
|
const normalized = await this.normalizeAccountSettings(platform, input, state);
|
|
702
854
|
if (!normalized.ok)
|
|
703
855
|
return normalized;
|
|
@@ -723,9 +875,39 @@ export class ChannelManager {
|
|
|
723
875
|
state.privateAccess = normalized.settings.privateAccess;
|
|
724
876
|
// 发送方式按注入时机读取,不需要重载会话。
|
|
725
877
|
state.sendMode = normalized.settings.sendMode;
|
|
878
|
+
if (supportsProxy(platform) && !this.proxyUrlCache.has(accountId)) {
|
|
879
|
+
await this.hydrateProxyUrl(accountId, state);
|
|
880
|
+
}
|
|
881
|
+
const previousProxyUrl = this.proxyUrlCache.get(accountId);
|
|
882
|
+
const proxyModeChanged = requestedProxyMode !== previousProxyMode;
|
|
883
|
+
const proxyUrlChanged = requestedProxyMode === 'custom'
|
|
884
|
+
&& nextProxyUrl !== undefined
|
|
885
|
+
&& nextProxyUrl !== previousProxyUrl;
|
|
886
|
+
const proxyChanged = supportsProxy(platform) && hasProxySettings && (proxyModeChanged || proxyUrlChanged);
|
|
887
|
+
if (supportsProxy(platform) && hasProxySettings) {
|
|
888
|
+
const config = { ...(state.config ?? {}) };
|
|
889
|
+
if (requestedProxyMode === 'custom') {
|
|
890
|
+
if (proxyUrlChanged && nextProxyUrl) {
|
|
891
|
+
config.proxyUrl = nextProxyUrl;
|
|
892
|
+
state.config = await this.persistSecrets(platform, accountId, config);
|
|
893
|
+
this.proxyUrlCache.set(accountId, nextProxyUrl);
|
|
894
|
+
}
|
|
895
|
+
state.config = { ...(state.config ?? config), proxyMode: 'custom' };
|
|
896
|
+
}
|
|
897
|
+
else if (proxyModeChanged) {
|
|
898
|
+
const ref = config.proxyUrlRef || credentialRef(accountId, 'proxyUrl');
|
|
899
|
+
await this.vault.unset(ref);
|
|
900
|
+
delete config.proxyUrl;
|
|
901
|
+
delete config.proxyUrlRef;
|
|
902
|
+
state.config = { ...config, proxyMode: requestedProxyMode };
|
|
903
|
+
this.proxyUrlCache.delete(accountId);
|
|
904
|
+
}
|
|
905
|
+
}
|
|
726
906
|
this.flush();
|
|
727
907
|
if (reloadSessions)
|
|
728
908
|
await this.engine.reloadChannel(accountId, { resetSessions });
|
|
909
|
+
if (proxyChanged && this.running.has(accountId))
|
|
910
|
+
await this.startOne(accountId);
|
|
729
911
|
return { ok: true, account: this.accountView(accountId, state) };
|
|
730
912
|
});
|
|
731
913
|
}
|
|
@@ -796,7 +978,8 @@ export class ChannelManager {
|
|
|
796
978
|
await this.startOne(accountId);
|
|
797
979
|
return { ok: true };
|
|
798
980
|
}
|
|
799
|
-
catch {
|
|
981
|
+
catch (error) {
|
|
982
|
+
this.log(`[manager] 重新连接 ${accountId} 失败: ${error instanceof Error ? error.message : String(error)}`);
|
|
800
983
|
return { ok: false, error: '重新连接失败,请查看本机日志' };
|
|
801
984
|
}
|
|
802
985
|
});
|
|
@@ -950,30 +1133,31 @@ export class ChannelManager {
|
|
|
950
1133
|
if (this.disposed)
|
|
951
1134
|
return;
|
|
952
1135
|
const accountDir = this.accountStateDir(id, platform);
|
|
953
|
-
|
|
954
|
-
accountId: id,
|
|
955
|
-
accountLabel: state.name || `${CHANNEL_META[platform].label}账号`,
|
|
956
|
-
host: this.ctx,
|
|
957
|
-
onWeixinBotToken: async (token) => {
|
|
958
|
-
const ref = credentialRef(id, 'botToken');
|
|
959
|
-
if (token)
|
|
960
|
-
await this.vault.set(ref, token);
|
|
961
|
-
else
|
|
962
|
-
await this.vault.unset(ref);
|
|
963
|
-
},
|
|
964
|
-
});
|
|
965
|
-
if (!adapter)
|
|
966
|
-
throw new Error('凭据不足,无法启动渠道');
|
|
967
|
-
if (platform === 'weixin') {
|
|
968
|
-
this.seedAllowedUser(id, readWeixinAllowedUserId(accountDir) || resolved.allowedUserId);
|
|
969
|
-
}
|
|
970
|
-
this.seedAllowedUser(id, resolved.ownerOpenId || resolved.allowedUserId);
|
|
971
|
-
this.engine.register(adapter);
|
|
972
|
-
this.running.set(id, adapter);
|
|
1136
|
+
let adapter;
|
|
973
1137
|
// 渠道网络异常时 start 可能永久挂起,超时按启动失败处理(catch 会顺带 stop)
|
|
974
1138
|
const START_TIMEOUT_MS = 30_000;
|
|
975
1139
|
let startTimer;
|
|
976
1140
|
try {
|
|
1141
|
+
adapter = createChannelAdapter(platform, resolved, this.log, accountDir, {
|
|
1142
|
+
accountId: id,
|
|
1143
|
+
accountLabel: state.name || `${CHANNEL_META[platform].label}账号`,
|
|
1144
|
+
host: this.ctx,
|
|
1145
|
+
onWeixinBotToken: async (token) => {
|
|
1146
|
+
const ref = credentialRef(id, 'botToken');
|
|
1147
|
+
if (token)
|
|
1148
|
+
await this.vault.set(ref, token);
|
|
1149
|
+
else
|
|
1150
|
+
await this.vault.unset(ref);
|
|
1151
|
+
},
|
|
1152
|
+
});
|
|
1153
|
+
if (!adapter)
|
|
1154
|
+
throw new Error('凭据不足,无法启动渠道');
|
|
1155
|
+
if (platform === 'weixin') {
|
|
1156
|
+
this.seedAllowedUser(id, readWeixinAllowedUserId(accountDir) || resolved.allowedUserId);
|
|
1157
|
+
}
|
|
1158
|
+
this.seedAllowedUser(id, resolved.ownerOpenId || resolved.allowedUserId);
|
|
1159
|
+
this.engine.register(adapter);
|
|
1160
|
+
this.running.set(id, adapter);
|
|
977
1161
|
await Promise.race([
|
|
978
1162
|
adapter.start(),
|
|
979
1163
|
new Promise((_, reject) => {
|
|
@@ -988,10 +1172,13 @@ export class ChannelManager {
|
|
|
988
1172
|
}
|
|
989
1173
|
}
|
|
990
1174
|
catch (error) {
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
1175
|
+
if (adapter) {
|
|
1176
|
+
this.engine.unregister(id);
|
|
1177
|
+
this.running.delete(id);
|
|
1178
|
+
await Promise.resolve(adapter.stop()).catch(() => undefined);
|
|
1179
|
+
}
|
|
994
1180
|
const message = error instanceof Error ? error.message : String(error);
|
|
1181
|
+
this.log(`[manager] 启动 ${id} 失败: ${message}`);
|
|
995
1182
|
if (state) {
|
|
996
1183
|
state.lastError = '连接失败,请查看本机日志';
|
|
997
1184
|
this.flush();
|
|
@@ -1070,6 +1257,8 @@ export class ChannelManager {
|
|
|
1070
1257
|
assistant: normalizeAssistantModel(parsed.assistant ?? {}),
|
|
1071
1258
|
cwd: normalizeWorkspacePath(parsed.cwd),
|
|
1072
1259
|
permission: normalizePermission(parsed.permission),
|
|
1260
|
+
sidebarEntry: typeof parsed.sidebarEntry === 'boolean' ? parsed.sidebarEntry : undefined,
|
|
1261
|
+
onlineUpdate: typeof parsed.onlineUpdate === 'boolean' ? parsed.onlineUpdate : undefined,
|
|
1073
1262
|
};
|
|
1074
1263
|
}
|
|
1075
1264
|
catch (error) {
|