@michengai/dsh-im-connect 1.0.19 → 1.0.21
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 +12 -0
- package/CHANGELOG.zh-CN.md +12 -0
- package/README.md +8 -0
- package/README.zh-CN.md +8 -0
- package/client.js +103 -23
- package/lib/api-base.d.ts +1 -1
- package/lib/api-base.js +1 -1
- package/lib/client.js +104 -24
- package/lib/engine/command-messages.d.ts +3 -0
- package/lib/engine/command-messages.d.ts.map +1 -1
- package/lib/engine/command-messages.js +3 -0
- package/lib/engine/command-messages.js.map +1 -1
- package/lib/engine/gateway.d.ts +9 -0
- package/lib/engine/gateway.d.ts.map +1 -1
- package/lib/engine/gateway.js +44 -0
- package/lib/engine/gateway.js.map +1 -1
- package/lib/engine/router.d.ts +21 -0
- package/lib/engine/router.d.ts.map +1 -1
- package/lib/engine/router.js +36 -0
- package/lib/engine/router.js.map +1 -1
- package/lib/engine/session-id.d.ts +2 -0
- package/lib/engine/session-id.d.ts.map +1 -1
- package/lib/engine/session-id.js.map +1 -1
- package/lib/engine/types.d.ts +2 -0
- package/lib/engine/types.d.ts.map +1 -1
- package/lib/manager.d.ts +4 -0
- package/lib/manager.d.ts.map +1 -1
- package/lib/manager.js +16 -4
- package/lib/manager.js.map +1 -1
- package/package.json +1 -1
- package/src/api-base.ts +1 -1
- package/src/engine/command-messages.ts +4 -0
- package/src/engine/gateway.ts +43 -0
- package/src/engine/router.ts +43 -0
- package/src/engine/session-id.ts +2 -0
- package/src/engine/types.ts +2 -0
- package/src/manager.ts +20 -5
package/src/manager.ts
CHANGED
|
@@ -56,6 +56,12 @@ function normalizeSegmentSecs(input: unknown): number | undefined {
|
|
|
56
56
|
return Math.min(60, Math.max(0, Math.round(input)))
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
/** 空闲新开会话分钟数:0 表示关闭,限制为非负整数;缺失或非法值返回 undefined 交给上一层回退。 */
|
|
60
|
+
function normalizeIdleMinutes(input: unknown): number | undefined {
|
|
61
|
+
if (typeof input !== 'number' || !Number.isFinite(input)) return undefined
|
|
62
|
+
return Math.max(0, Math.round(input))
|
|
63
|
+
}
|
|
64
|
+
|
|
59
65
|
function channelAutoPrefix(platform: ChannelId): string {
|
|
60
66
|
return `${CHANNEL_META[platform].label}账号`
|
|
61
67
|
}
|
|
@@ -182,6 +188,8 @@ export interface ChannelState {
|
|
|
182
188
|
segmentDelayMinSecs?: number
|
|
183
189
|
/** 分段消息之间随机间隔的上界(秒)。 */
|
|
184
190
|
segmentDelayMaxSecs?: number
|
|
191
|
+
/** 空闲新开会话分钟数:缺省为 0 表示关闭。 */
|
|
192
|
+
sessionIdleMinutes?: number
|
|
185
193
|
lastCheckedAt?: string
|
|
186
194
|
}
|
|
187
195
|
|
|
@@ -209,6 +217,8 @@ export interface AccountView {
|
|
|
209
217
|
segmentReplySupported: boolean
|
|
210
218
|
segmentDelayMinSecs: number
|
|
211
219
|
segmentDelayMaxSecs: number
|
|
220
|
+
/** 空闲新开会话分钟数:0 表示关闭。 */
|
|
221
|
+
sessionIdleMinutes: number
|
|
212
222
|
proxyMode: ChannelProxyMode
|
|
213
223
|
proxyConfigured: boolean
|
|
214
224
|
proxyUrl?: string
|
|
@@ -426,6 +436,7 @@ export class ChannelManager {
|
|
|
426
436
|
segmentReplySupported: segmentSupported,
|
|
427
437
|
segmentDelayMinSecs: segmentDelay.min,
|
|
428
438
|
segmentDelayMaxSecs: segmentDelay.max,
|
|
439
|
+
sessionIdleMinutes: normalizeIdleMinutes(state.sessionIdleMinutes) ?? 0,
|
|
429
440
|
proxyMode: supportsProxy(platform) && (config.proxyMode === 'direct' || config.proxyMode === 'custom') ? config.proxyMode : 'inherit',
|
|
430
441
|
proxyConfigured: supportsProxy(platform) && config.proxyMode === 'custom'
|
|
431
442
|
? this.proxyUrlCache.has(accountId)
|
|
@@ -495,6 +506,7 @@ export class ChannelManager {
|
|
|
495
506
|
...(normalized.settings.segmentReply !== undefined ? { segmentReply: normalized.settings.segmentReply } : {}),
|
|
496
507
|
...(normalized.settings.segmentDelayMinSecs !== undefined ? { segmentDelayMinSecs: normalized.settings.segmentDelayMinSecs } : {}),
|
|
497
508
|
...(normalized.settings.segmentDelayMaxSecs !== undefined ? { segmentDelayMaxSecs: normalized.settings.segmentDelayMaxSecs } : {}),
|
|
509
|
+
...(normalized.settings.sessionIdleMinutes !== undefined ? { sessionIdleMinutes: normalized.settings.sessionIdleMinutes } : {}),
|
|
498
510
|
enabled: true,
|
|
499
511
|
receiveEnabled: true,
|
|
500
512
|
config: nextConfig,
|
|
@@ -876,7 +888,7 @@ export class ChannelManager {
|
|
|
876
888
|
}
|
|
877
889
|
}
|
|
878
890
|
|
|
879
|
-
const basePath = '/api/dsh-im-connect'
|
|
891
|
+
const basePath = '/api/michengai/dsh-im-connect'
|
|
880
892
|
const dispose = webServer.register({
|
|
881
893
|
kind: 'prefix',
|
|
882
894
|
path: basePath,
|
|
@@ -910,7 +922,7 @@ export class ChannelManager {
|
|
|
910
922
|
},
|
|
911
923
|
})
|
|
912
924
|
if (typeof dispose === 'function') this.apiDisposers.push(dispose)
|
|
913
|
-
this.log('[manager] API 已注册 /api/dsh-im-connect')
|
|
925
|
+
this.log('[manager] API 已注册 /api/michengai/dsh-im-connect')
|
|
914
926
|
}
|
|
915
927
|
|
|
916
928
|
disposeApi(): void {
|
|
@@ -1011,6 +1023,7 @@ export class ChannelManager {
|
|
|
1011
1023
|
state.privateAccess = normalized.settings.privateAccess
|
|
1012
1024
|
// 发送方式按注入时机读取,不需要重载会话。
|
|
1013
1025
|
state.sendMode = normalized.settings.sendMode
|
|
1026
|
+
if (normalized.settings.sessionIdleMinutes !== undefined) state.sessionIdleMinutes = normalized.settings.sessionIdleMinutes
|
|
1014
1027
|
if (normalized.settings.segmentReply !== undefined) state.segmentReply = normalized.settings.segmentReply
|
|
1015
1028
|
if (normalized.settings.segmentDelayMinSecs !== undefined) state.segmentDelayMinSecs = normalized.settings.segmentDelayMinSecs
|
|
1016
1029
|
if (normalized.settings.segmentDelayMaxSecs !== undefined) state.segmentDelayMaxSecs = normalized.settings.segmentDelayMaxSecs
|
|
@@ -1462,7 +1475,7 @@ export class ChannelManager {
|
|
|
1462
1475
|
return ordinal
|
|
1463
1476
|
}
|
|
1464
1477
|
|
|
1465
|
-
private async normalizeAccountSettings(platform: ChannelId, input: Record<string, unknown>, previous: ChannelState): Promise<{ ok: true; settings: { name: string; nameOrdinal: number; assistant: AssistantModel; agentPreset: string; cwd: string; permission: PermissionPreset; commandPermissions: CommandPermissions; privateAccess: 'approved' | 'all'; sendMode: SendMode; segmentReply?: boolean; segmentDelayMinSecs?: number; segmentDelayMaxSecs?: number } } | { ok: false; error: string }> {
|
|
1478
|
+
private async normalizeAccountSettings(platform: ChannelId, input: Record<string, unknown>, previous: ChannelState): Promise<{ ok: true; settings: { name: string; nameOrdinal: number; assistant: AssistantModel; agentPreset: string; cwd: string; permission: PermissionPreset; commandPermissions: CommandPermissions; privateAccess: 'approved' | 'all'; sendMode: SendMode; sessionIdleMinutes?: number; segmentReply?: boolean; segmentDelayMinSecs?: number; segmentDelayMaxSecs?: number } } | { ok: false; error: string }> {
|
|
1466
1479
|
const agentPreset = input.agentPreset ?? previous.agentPreset ?? this.engineConfig.agentPreset ?? 'standard'
|
|
1467
1480
|
if (typeof agentPreset !== 'string' || !agentPreset.trim()) return { ok: false, error: '请选择 Agent 预设' }
|
|
1468
1481
|
if (input.agentPreset !== undefined) {
|
|
@@ -1485,6 +1498,7 @@ export class ChannelManager {
|
|
|
1485
1498
|
if (!permission) return { ok: false, error: '请选择权限' }
|
|
1486
1499
|
const privateAccess = input.privateAccess === 'all' || (input.privateAccess === undefined && previous.privateAccess === 'all') ? 'all' : 'approved'
|
|
1487
1500
|
const sendMode = normalizeSendMode(input.sendMode === undefined ? previous.sendMode : input.sendMode)
|
|
1501
|
+
const sessionIdleMinutes = normalizeIdleMinutes(input.sessionIdleMinutes) ?? previous.sessionIdleMinutes
|
|
1488
1502
|
// 未传就从状态里沿用;显式传布尔值才覆盖,避免旧客户端保存时把开关打回默认。
|
|
1489
1503
|
// 只有已开放分段回复的渠道才保存开关,未验证渠道一律记为关闭。
|
|
1490
1504
|
const segmentReply = channelSupportsSegmentReply(platform)
|
|
@@ -1501,7 +1515,7 @@ export class ChannelManager {
|
|
|
1501
1515
|
if ([...trimmed].length > ACCOUNT_REMARK_LIMIT) return { ok: false, error: `账号备注不能超过 ${ACCOUNT_REMARK_LIMIT} 个字符` }
|
|
1502
1516
|
if (/[\u0000-\u001F\u007F]/.test(trimmed)) return { ok: false, error: '账号备注不能包含换行或控制字符' }
|
|
1503
1517
|
const name = trimmed || autoAccountName(platform, nameOrdinal)
|
|
1504
|
-
return { ok: true, settings: { name, nameOrdinal, assistant, agentPreset, cwd, permission, privateAccess, sendMode, segmentReply, segmentDelayMinSecs, segmentDelayMaxSecs, commandPermissions } }
|
|
1518
|
+
return { ok: true, settings: { name, nameOrdinal, assistant, agentPreset, cwd, permission, privateAccess, sendMode, sessionIdleMinutes, segmentReply, segmentDelayMinSecs, segmentDelayMaxSecs, commandPermissions } }
|
|
1505
1519
|
}
|
|
1506
1520
|
|
|
1507
1521
|
private accountIdFor(platform: ChannelId, config: Record<string, string>): string {
|
|
@@ -1561,6 +1575,7 @@ export class ChannelManager {
|
|
|
1561
1575
|
&& (state.segmentReply ?? this.engineConfig.segmentReply) === true,
|
|
1562
1576
|
segmentDelayMinSecs: this.segmentDelayRange(state).min,
|
|
1563
1577
|
segmentDelayMaxSecs: this.segmentDelayRange(state).max,
|
|
1578
|
+
sessionIdleMinutes: normalizeIdleMinutes(state.sessionIdleMinutes) ?? 0,
|
|
1564
1579
|
}
|
|
1565
1580
|
}
|
|
1566
1581
|
|
|
@@ -1635,7 +1650,7 @@ function pairingSettings(input?: Record<string, unknown>): Record<string, string
|
|
|
1635
1650
|
if (!input) return {}
|
|
1636
1651
|
const out: Record<string, string> = {}
|
|
1637
1652
|
if (input.commandPermissions !== undefined) out.__setting_commandPermissions = JSON.stringify(normalizeCommandPermissions(input.commandPermissions))
|
|
1638
|
-
for (const key of ['name', 'provider', 'model', 'reasoningEffort', 'cwd', 'permission', 'privateAccess', 'sendMode', 'segmentReply', 'segmentDelayMinSecs', 'segmentDelayMaxSecs', 'agentPreset']) {
|
|
1653
|
+
for (const key of ['name', 'provider', 'model', 'reasoningEffort', 'cwd', 'permission', 'privateAccess', 'sendMode', 'sessionIdleMinutes', 'segmentReply', 'segmentDelayMinSecs', 'segmentDelayMaxSecs', 'agentPreset']) {
|
|
1639
1654
|
const value = input[key]
|
|
1640
1655
|
if (value !== undefined && value !== null) out[`__setting_${key}`] = String(value)
|
|
1641
1656
|
}
|