@michengai/dsh-im-connect 0.1.49 → 0.1.50
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 +6 -0
- package/CHANGELOG.zh-CN.md +6 -0
- package/README.md +2 -2
- package/README.zh-CN.md +2 -2
- package/lib/engine/chat-commands.d.ts.map +1 -1
- package/lib/engine/chat-commands.js +2 -1
- package/lib/engine/chat-commands.js.map +1 -1
- package/lib/engine/file-delivery.d.ts +0 -1
- package/lib/engine/file-delivery.d.ts.map +1 -1
- package/lib/engine/file-delivery.js +4 -3
- package/lib/engine/file-delivery.js.map +1 -1
- package/lib/engine/gateway.d.ts.map +1 -1
- package/lib/engine/gateway.js +4 -3
- package/lib/engine/gateway.js.map +1 -1
- package/lib/engine/router.d.ts.map +1 -1
- package/lib/engine/router.js +7 -6
- package/lib/engine/router.js.map +1 -1
- package/lib/engine/session-history.d.ts +22 -0
- package/lib/engine/session-history.d.ts.map +1 -0
- package/lib/engine/session-history.js +31 -0
- package/lib/engine/session-history.js.map +1 -0
- package/package.json +14 -14
- package/src/engine/chat-commands.ts +3 -2
- package/src/engine/file-delivery.ts +4 -4
- package/src/engine/gateway.ts +4 -4
- package/src/engine/router.ts +9 -8
- package/src/engine/session-history.ts +38 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@michengai/dsh-im-connect",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.50",
|
|
4
4
|
"description": "DeepSeek Harness IM 助理:把本机 agent 接到微信、企微、钉钉、飞书、QQ、Telegram,会话与网页任务分列。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"packageManager": "pnpm@11.22.0",
|
|
@@ -53,13 +53,13 @@
|
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"@deepseek-ai/cordis": "^4.0.2",
|
|
56
|
-
"@deepseek-ai/dsh-agent": "0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2",
|
|
57
|
-
"@deepseek-ai/dsh-client-locale": "0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2",
|
|
58
|
-
"@deepseek-ai/dsh-client-runtime": "0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2",
|
|
59
|
-
"@deepseek-ai/dsh-client-ui-primitives": "0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2",
|
|
60
|
-
"@deepseek-ai/dsh-client-ui-settings": "0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2",
|
|
61
|
-
"@deepseek-ai/dsh-client-ui-slots": "0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2",
|
|
62
|
-
"@deepseek-ai/dsh-host-webserver": "0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2",
|
|
56
|
+
"@deepseek-ai/dsh-agent": "0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.6-alpha.1",
|
|
57
|
+
"@deepseek-ai/dsh-client-locale": "0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.6-alpha.1",
|
|
58
|
+
"@deepseek-ai/dsh-client-runtime": "0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.6-alpha.1",
|
|
59
|
+
"@deepseek-ai/dsh-client-ui-primitives": "0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.6-alpha.1",
|
|
60
|
+
"@deepseek-ai/dsh-client-ui-settings": "0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.6-alpha.1",
|
|
61
|
+
"@deepseek-ai/dsh-client-ui-slots": "0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.6-alpha.1",
|
|
62
|
+
"@deepseek-ai/dsh-host-webserver": "0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.6-alpha.1",
|
|
63
63
|
"@deepseek-ai/schemastery": "^3.18.2"
|
|
64
64
|
},
|
|
65
65
|
"peerDependenciesMeta": {
|
|
@@ -69,12 +69,12 @@
|
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@deepseek-ai/cordis": "^4.0.2",
|
|
72
|
-
"@deepseek-ai/dsh-agent": "0.1.
|
|
73
|
-
"@deepseek-ai/dsh-client-locale": "0.1.
|
|
74
|
-
"@deepseek-ai/dsh-client-ui-primitives": "0.1.
|
|
75
|
-
"@deepseek-ai/dsh-client-ui-settings": "0.1.
|
|
76
|
-
"@deepseek-ai/dsh-client-ui-slots": "0.1.
|
|
77
|
-
"@deepseek-ai/dsh-host-webserver": "0.1.
|
|
72
|
+
"@deepseek-ai/dsh-agent": "0.1.6-alpha.1",
|
|
73
|
+
"@deepseek-ai/dsh-client-locale": "0.1.6-alpha.1",
|
|
74
|
+
"@deepseek-ai/dsh-client-ui-primitives": "0.1.6-alpha.1",
|
|
75
|
+
"@deepseek-ai/dsh-client-ui-settings": "0.1.6-alpha.1",
|
|
76
|
+
"@deepseek-ai/dsh-client-ui-slots": "0.1.6-alpha.1",
|
|
77
|
+
"@deepseek-ai/dsh-host-webserver": "0.1.6-alpha.1",
|
|
78
78
|
"@deepseek-ai/schemastery": "^3.18.2",
|
|
79
79
|
"@types/node": "^22.10.0",
|
|
80
80
|
"@types/qrcode": "^1.5.6",
|
|
@@ -6,6 +6,7 @@ import { AsyncLocalStorage } from 'node:async_hooks'
|
|
|
6
6
|
import { randomUUID } from 'node:crypto'
|
|
7
7
|
import type { ChannelAdapter, ImMessage } from './types.js'
|
|
8
8
|
import { commandNavigation, extensionHelp, extensionReply, oneLine, related } from './command-replies.js'
|
|
9
|
+
import { readSessionHistory } from './session-history.js'
|
|
9
10
|
import type { SessionRouter } from './router.js'
|
|
10
11
|
|
|
11
12
|
const modelDefaultHint = () => replyText('与 Chat 一致,此操作也会尝试保存后续 Chat 新会话的默认模型选择;已有其他会话不会主动修改。')
|
|
@@ -167,9 +168,9 @@ export class ChatCommands {
|
|
|
167
168
|
let cwd: string | undefined
|
|
168
169
|
let model: Selection | undefined
|
|
169
170
|
try {
|
|
170
|
-
const session = (binding.handle?.agent as | { session?: {
|
|
171
|
+
const session = (binding.handle?.agent as | { session?: { id?: string; header?: { cwd?: string }; events?: readonly { type: string; data?: Selection }[] } } | undefined)?.session
|
|
171
172
|
cwd = session?.header?.cwd
|
|
172
|
-
model = (
|
|
173
|
+
model = (await readSessionHistory(this.host, session, signal) ?? []).findLast((event) => event.type === 'model/selection')?.data as Selection | undefined
|
|
173
174
|
} catch { /* 继续尝试宿主快照,不能改用账号默认值冒充实际配置。 */ }
|
|
174
175
|
const [snapshot, rows] = await Promise.all([
|
|
175
176
|
model?.provider && model.model ? undefined : this.optional((sig) => this.snapshot(binding.sessionId, sig), signal),
|
|
@@ -2,12 +2,12 @@ import { basename, resolve } from 'node:path'
|
|
|
2
2
|
import type { ChannelAdapter } from './types.js'
|
|
3
3
|
import { KeyedSerialQueue } from './keyed-queue.js'
|
|
4
4
|
import { replyText, withReplyLocale } from './command-locale.js'
|
|
5
|
+
import { readLiveSessionHistory } from './session-history.js'
|
|
5
6
|
|
|
6
7
|
type Event = { type?: string; seq?: number; surfaceOp?: unknown; data?: any }
|
|
7
8
|
export interface DeliverySession {
|
|
8
9
|
id?: string
|
|
9
10
|
header?: { cwd?: string }
|
|
10
|
-
snapshotEvents?: () => readonly Event[]
|
|
11
11
|
events?: readonly Event[]
|
|
12
12
|
}
|
|
13
13
|
|
|
@@ -32,8 +32,8 @@ function mutationPath(name: string, raw: unknown): string | undefined {
|
|
|
32
32
|
|
|
33
33
|
/** 只选当前回复所在回合、已成功产生或明确 present 的文件。 */
|
|
34
34
|
export function filesForReply(events: readonly Event[], closing: Event): { turn: number; paths: string[] } | undefined {
|
|
35
|
-
|
|
36
|
-
if (end < 0)
|
|
35
|
+
let end = events.findIndex(event => event === closing || (closing.seq !== undefined && event.seq === closing.seq))
|
|
36
|
+
if (end < 0) end = events.length
|
|
37
37
|
if (closing.surfaceOp !== 'append' || closing.data?.interrupted
|
|
38
38
|
|| closing.data?.message?.content?.some((part: any) => part.type === 'tool-call')) return
|
|
39
39
|
const prefix = events.slice(0, end)
|
|
@@ -72,7 +72,7 @@ export class FileDelivery {
|
|
|
72
72
|
const initial = target()
|
|
73
73
|
return this.queue.run(String(session.id), async () => {
|
|
74
74
|
if (this.lifetime.signal.aborted) { ok = false; return }
|
|
75
|
-
const selected = filesForReply(session
|
|
75
|
+
const selected = filesForReply(readLiveSessionHistory(session) ?? [], closing)
|
|
76
76
|
if (!selected?.paths.length) return
|
|
77
77
|
onContent?.()
|
|
78
78
|
if (!initial) { ok = false; return }
|
package/src/engine/gateway.ts
CHANGED
|
@@ -15,6 +15,7 @@ import { SessionRouter } from './router.js'
|
|
|
15
15
|
import { initialSessionTitle, readSessionTitle } from './session-title.js'
|
|
16
16
|
import { SeenStore } from './seen-store.js'
|
|
17
17
|
import { SessionMapStore } from './session-store.js'
|
|
18
|
+
import { readSessionHistory } from './session-history.js'
|
|
18
19
|
import { type ChatKind } from './session-id.js'
|
|
19
20
|
import { canAnswerToolApproval, decideAccess } from './access.js'
|
|
20
21
|
import { splitText } from './split.js'
|
|
@@ -32,7 +33,6 @@ interface AgentLike {
|
|
|
32
33
|
id?: string
|
|
33
34
|
session?: {
|
|
34
35
|
id?: string
|
|
35
|
-
snapshotEvents?: () => readonly { type?: string; data?: Record<string, unknown> }[]
|
|
36
36
|
events?: readonly { type?: string; data?: Record<string, unknown> }[]
|
|
37
37
|
}
|
|
38
38
|
}
|
|
@@ -672,7 +672,7 @@ export class ImEngine {
|
|
|
672
672
|
await this.deliver(channel, binding.chatId, '当前用户可以私聊,但工具调用审批仅限已批准用户;请在网页端处理。')
|
|
673
673
|
return DELEGATE_INTERACTION
|
|
674
674
|
}
|
|
675
|
-
const prompt = withReplyLocale(this.ctx, () => this.approvalPrompt(req))
|
|
675
|
+
const prompt = await withReplyLocale(this.ctx, () => this.approvalPrompt(req))
|
|
676
676
|
if (!prompt) {
|
|
677
677
|
await this.deliver(channel, binding.chatId, '该操作需要审批,但无法在 IM 中完整展示;请在网页端处理。')
|
|
678
678
|
return DELEGATE_INTERACTION
|
|
@@ -886,7 +886,7 @@ export class ImEngine {
|
|
|
886
886
|
})
|
|
887
887
|
}
|
|
888
888
|
|
|
889
|
-
private approvalPrompt(req: ApprovalRequestLike): string | undefined {
|
|
889
|
+
private async approvalPrompt(req: ApprovalRequestLike): Promise<string | undefined> {
|
|
890
890
|
const toolName = req.toolName?.trim() || (req.session ? '工具操作' : '')
|
|
891
891
|
if (!toolName) return undefined
|
|
892
892
|
const lines = [
|
|
@@ -898,7 +898,7 @@ export class ImEngine {
|
|
|
898
898
|
if (req.agent && !callId) return undefined
|
|
899
899
|
if (callId) {
|
|
900
900
|
const session = req.agent?.session
|
|
901
|
-
const events =
|
|
901
|
+
const events = await readSessionHistory(this.ctx, session) ?? []
|
|
902
902
|
const event = events.findLast((item) => {
|
|
903
903
|
if (item.type === 'tool/call') return item.data?.callId === callId
|
|
904
904
|
if (item.type === 'tool/code-dispatch-start' || item.type === 'tool/ptc-dispatch-start') return item.data?.subCallId === callId
|
package/src/engine/router.ts
CHANGED
|
@@ -7,6 +7,7 @@ import type { EngineConfig } from './types.js'
|
|
|
7
7
|
import { KeyedSerialQueue } from './keyed-queue.js'
|
|
8
8
|
import { sameWorkspacePath } from './workspace-path.js'
|
|
9
9
|
import { readSessionTitle } from './session-title.js'
|
|
10
|
+
import { readSessionHistory } from './session-history.js'
|
|
10
11
|
|
|
11
12
|
const DEFAULT_DISPOSE_TIMEOUT_MS = 10_000
|
|
12
13
|
|
|
@@ -21,7 +22,7 @@ function storedHeader(item: unknown): StoredHeader {
|
|
|
21
22
|
return header
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
type SetupAgent = { session?: {
|
|
25
|
+
type SetupAgent = { session?: { id?: string; events?: readonly { type: string }[] } }
|
|
25
26
|
|
|
26
27
|
export interface ChatBinding {
|
|
27
28
|
key: string
|
|
@@ -451,7 +452,7 @@ export class SessionRouter {
|
|
|
451
452
|
}
|
|
452
453
|
const liveAgent = this.ctx.agents?.get?.(record.sessionId)
|
|
453
454
|
if (liveAgent) {
|
|
454
|
-
this.syncStoredTitle(record.sessionId, liveAgent)
|
|
455
|
+
await this.syncStoredTitle(record.sessionId, liveAgent)
|
|
455
456
|
const binding: ChatBinding = {
|
|
456
457
|
key: sessionKeyOf(record.channel, record.kind, record.chatId),
|
|
457
458
|
channelId: record.channel,
|
|
@@ -472,7 +473,7 @@ export class SessionRouter {
|
|
|
472
473
|
},
|
|
473
474
|
setup: this.presetSetup(record.channel, record.agentPreset, true),
|
|
474
475
|
})
|
|
475
|
-
this.syncStoredTitle(record.sessionId, handle.agent)
|
|
476
|
+
await this.syncStoredTitle(record.sessionId, handle.agent)
|
|
476
477
|
await this.attachWorkspace(record.sessionId, record.channel, record.cwd)
|
|
477
478
|
return {
|
|
478
479
|
key: sessionKeyOf(record.channel, record.kind, record.chatId),
|
|
@@ -542,9 +543,9 @@ export class SessionRouter {
|
|
|
542
543
|
this.log(`[boot] attachMappedSessions ${Date.now() - started}ms`)
|
|
543
544
|
}
|
|
544
545
|
|
|
545
|
-
private syncStoredTitle(sessionId: string, agent: unknown): void {
|
|
546
|
-
const session = (agent as { session?: {
|
|
547
|
-
const events =
|
|
546
|
+
private async syncStoredTitle(sessionId: string, agent: unknown): Promise<void> {
|
|
547
|
+
const session = (agent as { session?: { id?: string; events?: readonly { type: string; data?: unknown }[] } } | undefined)?.session
|
|
548
|
+
const events = await readSessionHistory(this.ctx, session) ?? []
|
|
548
549
|
const latest = readSessionTitle(events.findLast(event => event.type === 'session/title')?.data)
|
|
549
550
|
if (latest) this.setTitle(sessionId, latest.title, latest.source)
|
|
550
551
|
}
|
|
@@ -631,9 +632,9 @@ export class SessionRouter {
|
|
|
631
632
|
// 0.1.5 显式传入 Agent;仅旧版单参数契约读取作用域属性。
|
|
632
633
|
const agent = explicitAgent ?? (agentCtx as { agent?: SetupAgent }).agent
|
|
633
634
|
const session = agent?.session
|
|
634
|
-
const events =
|
|
635
|
+
const events = await readSessionHistory(ctx, session)
|
|
635
636
|
// 在挂载前读取历史;来源不可读取时也不冒险覆盖已有权限。
|
|
636
|
-
const preservePermission = restoring && (!events || events.some(event => ['permission/preset', 'sandbox/mode', 'approval/policy'].includes(event.type)))
|
|
637
|
+
const preservePermission = restoring && (!events || events.some(event => ['permission/preset', 'sandbox/mode', 'approval/policy'].includes(event.type ?? '')))
|
|
637
638
|
if (ctx.agentPresets?.mount) await ctx.agentPresets.mount(agentCtx, preset)
|
|
638
639
|
// Account defaults belong in agentOptions (including on legacy Hosts),
|
|
639
640
|
// not a second installModelSelection middleware. Its outer after-next
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export type HistoryEvent = { type?: string; seq?: number; surfaceOp?: unknown; data?: any }
|
|
2
|
+
export type HistorySession = {
|
|
3
|
+
id?: string
|
|
4
|
+
events?: readonly HistoryEvent[]
|
|
5
|
+
snapshotEvents?: () => readonly HistoryEvent[]
|
|
6
|
+
}
|
|
7
|
+
export type HistoryHost = { get?(name: string): unknown }
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 官方 Session 没有公开 events,同步活日志是 snapshotEvents。
|
|
11
|
+
* events 只服务夹具和非官方对象;空数组继续往下看,避免把“还没写上”当成没有历史。
|
|
12
|
+
*/
|
|
13
|
+
export function readLiveSessionHistory(session?: HistorySession): readonly HistoryEvent[] | undefined {
|
|
14
|
+
if (Array.isArray(session?.events) && session.events.length > 0) return session.events
|
|
15
|
+
if (typeof session?.snapshotEvents === 'function') {
|
|
16
|
+
const snapshot = session.snapshotEvents()
|
|
17
|
+
if (Array.isArray(snapshot)) return snapshot
|
|
18
|
+
}
|
|
19
|
+
if (Array.isArray(session?.events)) return session.events
|
|
20
|
+
return undefined
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** 冷读优先 inspect;空结果或失败再回退活日志,不能把一次空存储前缀当成日志不存在。 */
|
|
24
|
+
export async function readSessionHistory(
|
|
25
|
+
host: HistoryHost | undefined,
|
|
26
|
+
session: HistorySession | undefined,
|
|
27
|
+
signal?: AbortSignal,
|
|
28
|
+
): Promise<readonly HistoryEvent[] | undefined> {
|
|
29
|
+
const id = session?.id
|
|
30
|
+
const controller = host?.get?.('sessionController') as { inspect?(sessionId: string, signal?: AbortSignal): Promise<{ events?: readonly HistoryEvent[] }> } | undefined
|
|
31
|
+
if (id && typeof controller?.inspect === 'function') {
|
|
32
|
+
try {
|
|
33
|
+
const inspection = await controller.inspect(id, signal)
|
|
34
|
+
if (Array.isArray(inspection?.events) && inspection.events.length > 0) return inspection.events
|
|
35
|
+
} catch { /* 继续回退,不能把一次冷读失败当成日志不存在。 */ }
|
|
36
|
+
}
|
|
37
|
+
return readLiveSessionHistory(session)
|
|
38
|
+
}
|