@michengai/dsh-im-connect 0.1.0 → 0.1.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.en.md +224 -0
- package/README.md +204 -19
- package/assets/branding/dsh-banner.png +0 -0
- package/assets/screenshots/dingtalk-chat.jpg +0 -0
- package/assets/screenshots/feishu-chat.jpg +0 -0
- package/assets/screenshots/qq-chat.jpg +0 -0
- package/assets/screenshots/settings-channels.png +0 -0
- package/assets/screenshots/telegram-chat.jpg +0 -0
- package/assets/screenshots/wecom-chat.jpg +0 -0
- package/assets/screenshots/wecom-qr.png +0 -0
- package/assets/screenshots/weixin-chat.jpg +0 -0
- package/assets/screenshots/workspace-channels.png +0 -0
- package/client.js +158 -82
- package/lib/channels/dingtalk-card.d.ts +2 -1
- package/lib/channels/dingtalk-card.d.ts.map +1 -1
- package/lib/channels/dingtalk-card.js +13 -5
- package/lib/channels/dingtalk-card.js.map +1 -1
- package/lib/channels/dingtalk.d.ts +19 -0
- package/lib/channels/dingtalk.d.ts.map +1 -1
- package/lib/channels/dingtalk.js +30 -16
- package/lib/channels/dingtalk.js.map +1 -1
- package/lib/channels/factory.d.ts.map +1 -1
- package/lib/channels/factory.js +3 -0
- package/lib/channels/factory.js.map +1 -1
- package/lib/channels/feishu.d.ts.map +1 -1
- package/lib/channels/feishu.js +5 -2
- package/lib/channels/feishu.js.map +1 -1
- package/lib/channels/meta.d.ts.map +1 -1
- package/lib/channels/meta.js +11 -0
- package/lib/channels/meta.js.map +1 -1
- package/lib/channels/qq.d.ts +9 -0
- package/lib/channels/qq.d.ts.map +1 -0
- package/lib/channels/qq.js +279 -0
- package/lib/channels/qq.js.map +1 -0
- package/lib/channels/qr/hub.d.ts +4 -1
- package/lib/channels/qr/hub.d.ts.map +1 -1
- package/lib/channels/qr/hub.js +27 -0
- package/lib/channels/qr/hub.js.map +1 -1
- package/lib/channels/qr/qq.d.ts +18 -0
- package/lib/channels/qr/qq.d.ts.map +1 -0
- package/lib/channels/qr/qq.js +86 -0
- package/lib/channels/qr/qq.js.map +1 -0
- package/lib/channels/qr/shared.d.ts +3 -0
- package/lib/channels/qr/shared.d.ts.map +1 -1
- package/lib/channels/qr/shared.js.map +1 -1
- package/lib/channels/telegram.d.ts.map +1 -1
- package/lib/channels/telegram.js +39 -8
- package/lib/channels/telegram.js.map +1 -1
- package/lib/channels/wecom.d.ts +1 -0
- package/lib/channels/wecom.d.ts.map +1 -1
- package/lib/channels/wecom.js +35 -15
- package/lib/channels/wecom.js.map +1 -1
- package/lib/channels/weixin.d.ts.map +1 -1
- package/lib/channels/weixin.js +9 -18
- package/lib/channels/weixin.js.map +1 -1
- package/lib/client.js +158 -82
- package/lib/engine/gateway.d.ts +3 -10
- package/lib/engine/gateway.d.ts.map +1 -1
- package/lib/engine/gateway.js +54 -65
- package/lib/engine/gateway.js.map +1 -1
- package/lib/engine/quiet-logger.d.ts +9 -0
- package/lib/engine/quiet-logger.d.ts.map +1 -0
- package/lib/engine/quiet-logger.js +26 -0
- package/lib/engine/quiet-logger.js.map +1 -0
- package/lib/engine/reply-stream.d.ts +25 -0
- package/lib/engine/reply-stream.d.ts.map +1 -0
- package/lib/engine/reply-stream.js +62 -0
- package/lib/engine/reply-stream.js.map +1 -0
- package/lib/engine/session-id.d.ts +1 -1
- package/lib/engine/session-id.d.ts.map +1 -1
- package/lib/engine/session-id.js +1 -1
- package/lib/engine/session-id.js.map +1 -1
- package/lib/engine/types.d.ts +0 -2
- package/lib/engine/types.d.ts.map +1 -1
- package/lib/index.d.ts +0 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +0 -2
- package/lib/index.js.map +1 -1
- package/lib/manager.d.ts +1 -12
- package/lib/manager.d.ts.map +1 -1
- package/lib/manager.js +165 -167
- package/lib/manager.js.map +1 -1
- package/package.json +15 -4
- package/src/channels/dingtalk-card.ts +13 -6
- package/src/channels/dingtalk.ts +43 -18
- package/src/channels/factory.ts +8 -2
- package/src/channels/feishu.ts +6 -2
- package/src/channels/meta.ts +13 -0
- package/src/channels/qq.ts +302 -0
- package/src/channels/qr/hub.ts +27 -3
- package/src/channels/qr/qq.ts +91 -0
- package/src/channels/qr/shared.ts +4 -0
- package/src/channels/telegram.ts +39 -9
- package/src/channels/wecom.ts +37 -16
- package/src/channels/weixin.ts +44 -52
- package/src/engine/gateway.ts +316 -325
- package/src/engine/quiet-logger.ts +23 -0
- package/src/engine/reply-stream.ts +67 -0
- package/src/engine/session-id.ts +3 -2
- package/src/engine/types.ts +1 -3
- package/src/index.ts +2 -5
- package/src/manager.ts +542 -569
- package/src/engine/access.ts +0 -17
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** 渠道 SDK 日志:只上报告警和错误,不打印握手 info。 */
|
|
2
|
+
export function quietSdkLogger(log: (line: string) => void, prefix: string) {
|
|
3
|
+
const emit = (args: unknown[]) => {
|
|
4
|
+
const text = args.map((item) => typeof item === 'string' ? item : safe(item)).join(' ').trim()
|
|
5
|
+
if (text) log(`[${prefix}] ${text}`)
|
|
6
|
+
}
|
|
7
|
+
return {
|
|
8
|
+
debug: () => undefined,
|
|
9
|
+
info: () => undefined,
|
|
10
|
+
trace: () => undefined,
|
|
11
|
+
warn: (...args: unknown[]) => emit(args),
|
|
12
|
+
error: (...args: unknown[]) => emit(args),
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function safe(value: unknown): string {
|
|
17
|
+
if (value instanceof Error) return value.message
|
|
18
|
+
try {
|
|
19
|
+
return JSON.stringify(value)
|
|
20
|
+
} catch {
|
|
21
|
+
return String(value)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/** 把模型增量收成一条回复流,避免并发重复开流。 */
|
|
2
|
+
import type { ReplyStream } from './types.js'
|
|
3
|
+
|
|
4
|
+
export function isAssistantTextDelta(chunk?: { type?: string; text?: string }): chunk is { type?: string; text: string } {
|
|
5
|
+
if (!chunk || typeof chunk.text !== 'string' || chunk.text.length === 0) return false
|
|
6
|
+
return !chunk.type || chunk.type === 'text' || chunk.type === 'text-delta'
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class ReplyStreamHub {
|
|
10
|
+
private readonly streams = new Map<string, ReplyStream>()
|
|
11
|
+
private readonly texts = new Map<string, string>()
|
|
12
|
+
private readonly tails = new Map<string, Promise<void>>()
|
|
13
|
+
private readonly delivered = new Set<string>()
|
|
14
|
+
// 回合纪元:reset 时自增,迟到的旧回合增量据此丢弃,不会重建流
|
|
15
|
+
private readonly generations = new Map<string, number>()
|
|
16
|
+
|
|
17
|
+
onTextDelta(key: string, delta: string, start: () => Promise<ReplyStream | undefined>): Promise<void> {
|
|
18
|
+
const generation = this.generations.get(key) ?? 0
|
|
19
|
+
const prev = this.tails.get(key) ?? Promise.resolve()
|
|
20
|
+
const next = prev.catch(() => undefined).then(async () => {
|
|
21
|
+
if (generation !== (this.generations.get(key) ?? 0)) return
|
|
22
|
+
let stream = this.streams.get(key)
|
|
23
|
+
if (!stream) {
|
|
24
|
+
stream = await start()
|
|
25
|
+
// start 期间可能刚被 reset(模型切换等),旧回合的流不再入表
|
|
26
|
+
if (generation !== (this.generations.get(key) ?? 0)) return
|
|
27
|
+
if (!stream) return
|
|
28
|
+
this.streams.set(key, stream)
|
|
29
|
+
this.texts.set(key, '')
|
|
30
|
+
this.delivered.delete(key)
|
|
31
|
+
}
|
|
32
|
+
const acc = (this.texts.get(key) ?? '') + delta
|
|
33
|
+
this.texts.set(key, acc)
|
|
34
|
+
await stream.update(acc)
|
|
35
|
+
})
|
|
36
|
+
this.tails.set(key, next)
|
|
37
|
+
return next
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async take(key: string): Promise<{ stream?: ReplyStream; text: string }> {
|
|
41
|
+
await (this.tails.get(key) ?? Promise.resolve()).catch(() => undefined)
|
|
42
|
+
const stream = this.streams.get(key)
|
|
43
|
+
const text = this.texts.get(key) ?? ''
|
|
44
|
+
this.streams.delete(key)
|
|
45
|
+
this.texts.delete(key)
|
|
46
|
+
this.tails.delete(key)
|
|
47
|
+
return { stream, text }
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
markDelivered(key: string): void {
|
|
51
|
+
this.delivered.add(key)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
consumeDelivered(key: string): boolean {
|
|
55
|
+
return this.delivered.delete(key)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
reset(key: string): void {
|
|
59
|
+
// 新回合开始:清掉上一回合可能残留的流与累计文本,避免新内容拼进旧卡片
|
|
60
|
+
this.generations.set(key, (this.generations.get(key) ?? 0) + 1)
|
|
61
|
+
this.streams.delete(key)
|
|
62
|
+
this.texts.delete(key)
|
|
63
|
+
this.tails.delete(key)
|
|
64
|
+
this.delivered.delete(key)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
package/src/engine/session-id.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export const IM_ORIGIN = 'im'
|
|
3
3
|
export const IM_SESSION_PREFIX = 'im:'
|
|
4
4
|
|
|
5
|
-
export type ChannelId = 'dingtalk' | 'feishu' | 'lark' | 'weixin' | 'wecom' | 'telegram'
|
|
5
|
+
export type ChannelId = 'dingtalk' | 'feishu' | 'lark' | 'weixin' | 'wecom' | 'qq' | 'telegram'
|
|
6
6
|
export type ChatKind = 'dm' | 'group'
|
|
7
7
|
|
|
8
8
|
export interface SessionRecord {
|
|
@@ -31,7 +31,7 @@ export function isImSessionId(sessionId: string): boolean {
|
|
|
31
31
|
return sessionId.startsWith(IM_SESSION_PREFIX)
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
const CHANNEL_IDS: readonly ChannelId[] = ['dingtalk', 'feishu', 'lark', 'weixin', 'wecom', 'telegram']
|
|
34
|
+
const CHANNEL_IDS: readonly ChannelId[] = ['dingtalk', 'feishu', 'lark', 'weixin', 'wecom', 'qq', 'telegram']
|
|
35
35
|
const STAMP_RE = /^\d{13,}$/
|
|
36
36
|
|
|
37
37
|
export function parseImSessionId(sessionId: string): { channel: ChannelId; kind: ChatKind; chatId: string } | undefined {
|
|
@@ -63,3 +63,4 @@ export function isTaskSession(input: { id?: string; origin?: string; blank?: boo
|
|
|
63
63
|
if (input.origin === 'subagent') return false
|
|
64
64
|
return true
|
|
65
65
|
}
|
|
66
|
+
|
package/src/engine/types.ts
CHANGED
|
@@ -37,7 +37,6 @@ export interface ChannelAdapter {
|
|
|
37
37
|
loginUrl?(): string | undefined
|
|
38
38
|
sendAction?(chatId: string, action: 'typing'): Promise<void>
|
|
39
39
|
sendMedia?(chatId: string, filePath: string, caption?: string): Promise<void>
|
|
40
|
-
authorizes?(userId: string): boolean | undefined
|
|
41
40
|
beginReply?(chatId: string): Promise<ReplyStream>
|
|
42
41
|
/** 企业微信等回调通道不能等合并窗口,必须立刻处理。 */
|
|
43
42
|
skipMerge?: boolean
|
|
@@ -48,8 +47,7 @@ export interface EngineConfig {
|
|
|
48
47
|
provider: string
|
|
49
48
|
model: string
|
|
50
49
|
agentPreset: string
|
|
51
|
-
allowAllUsers: boolean
|
|
52
50
|
mergeTimeoutSecs: number
|
|
53
51
|
permissionPreset: 'read-only' | 'workspace-write' | 'full-access'
|
|
54
52
|
reasoningEffort?: string
|
|
55
|
-
}
|
|
53
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -18,7 +18,6 @@ export interface PluginConfig {
|
|
|
18
18
|
provider: string
|
|
19
19
|
model: string
|
|
20
20
|
agentPreset: string
|
|
21
|
-
allowAllUsers: boolean
|
|
22
21
|
mergeTimeoutSecs: number
|
|
23
22
|
}
|
|
24
23
|
|
|
@@ -28,7 +27,6 @@ export const Config: Schema<PluginConfig> = Schema.object({
|
|
|
28
27
|
provider: Schema.string().default(''),
|
|
29
28
|
model: Schema.string().default(''),
|
|
30
29
|
agentPreset: Schema.string().default('standard'),
|
|
31
|
-
allowAllUsers: Schema.boolean().default(true),
|
|
32
30
|
mergeTimeoutSecs: Schema.number().default(5),
|
|
33
31
|
})
|
|
34
32
|
|
|
@@ -49,7 +47,6 @@ export function apply(ctx: Context, config: PluginConfig): void {
|
|
|
49
47
|
provider: config.provider,
|
|
50
48
|
model: config.model,
|
|
51
49
|
agentPreset: config.agentPreset || 'standard',
|
|
52
|
-
allowAllUsers: config.allowAllUsers,
|
|
53
50
|
mergeTimeoutSecs: config.mergeTimeoutSecs || 5,
|
|
54
51
|
permissionPreset: 'full-access',
|
|
55
52
|
}
|
|
@@ -77,5 +74,5 @@ export {
|
|
|
77
74
|
} from './engine/session-id.js'
|
|
78
75
|
export { splitText } from './engine/split.js'
|
|
79
76
|
|
|
80
|
-
|
|
81
|
-
|
|
77
|
+
|
|
78
|
+
|