@michengai/dsh-im-connect 1.0.21 → 1.0.23
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 +14 -0
- package/CHANGELOG.zh-CN.md +14 -0
- package/README.md +10 -10
- package/README.zh-CN.md +10 -10
- package/client.js +144 -30
- package/lib/channels/telegram.d.ts.map +1 -1
- package/lib/channels/telegram.js +17 -3
- package/lib/channels/telegram.js.map +1 -1
- package/lib/client.js +144 -30
- package/lib/engine/file-delivery.d.ts +1 -3
- package/lib/engine/file-delivery.d.ts.map +1 -1
- package/lib/engine/file-delivery.js +2 -51
- package/lib/engine/file-delivery.js.map +1 -1
- package/lib/engine/types.d.ts +3 -0
- package/lib/engine/types.d.ts.map +1 -1
- package/lib/manager.d.ts +3 -0
- package/lib/manager.d.ts.map +1 -1
- package/lib/manager.js +43 -9
- package/lib/manager.js.map +1 -1
- package/package.json +1 -1
- package/src/channels/telegram.ts +17 -3
- package/src/engine/file-delivery.ts +2 -34
- package/src/engine/types.ts +3 -0
- package/src/manager.ts +48 -9
package/src/engine/types.ts
CHANGED
|
@@ -15,7 +15,10 @@ export interface ImMessage {
|
|
|
15
15
|
text: string
|
|
16
16
|
kind?: 'dm' | 'group'
|
|
17
17
|
addressed?: boolean
|
|
18
|
+
/** 去重键。渠道内唯一即可,不必是平台消息 id。 */
|
|
18
19
|
messageId?: string
|
|
20
|
+
/** 平台侧的消息 id,用于表情回应等只认平台 id 的接口。 */
|
|
21
|
+
platformMessageId?: string
|
|
19
22
|
actionToken?: string
|
|
20
23
|
context?: Record<string, unknown>
|
|
21
24
|
media?: ImMedia[]
|
package/src/manager.ts
CHANGED
|
@@ -254,6 +254,8 @@ interface PendingRequest {
|
|
|
254
254
|
time: number
|
|
255
255
|
}
|
|
256
256
|
|
|
257
|
+
export type EntryLocation = 'both' | 'sidebar' | 'settings'
|
|
258
|
+
|
|
257
259
|
interface Persisted {
|
|
258
260
|
version?: 2
|
|
259
261
|
/** v2 起按账号实例 ID 存储;旧版按渠道 ID 的记录会原位升级为首个账号。 */
|
|
@@ -264,6 +266,7 @@ interface Persisted {
|
|
|
264
266
|
agentPreset?: string
|
|
265
267
|
cwd?: string
|
|
266
268
|
permission?: PermissionPreset
|
|
269
|
+
entryLocation?: EntryLocation
|
|
267
270
|
sidebarEntry?: boolean
|
|
268
271
|
onlineUpdate?: boolean
|
|
269
272
|
taskTreeSessions?: boolean
|
|
@@ -650,17 +653,32 @@ export class ChannelManager {
|
|
|
650
653
|
const parts = ('/dsh-im-connect/api' + path).split('/').filter(Boolean)
|
|
651
654
|
if (parts[2] === 'sidebar-entry' && parts.length === 3) {
|
|
652
655
|
if (method === 'GET' || method === 'HEAD') {
|
|
653
|
-
|
|
656
|
+
const location = this.getEntryLocation()
|
|
657
|
+
send(200, method === 'HEAD' ? undefined : { ok: true, location, enabled: location !== 'settings' })
|
|
654
658
|
return
|
|
655
659
|
}
|
|
656
660
|
if (method === 'POST') {
|
|
657
661
|
const body = await readBody()
|
|
658
|
-
if (!body
|
|
659
|
-
send(400, { ok: false, error: '
|
|
662
|
+
if (!body) {
|
|
663
|
+
send(400, { ok: false, error: '请求体不能为空' })
|
|
660
664
|
return
|
|
661
665
|
}
|
|
662
|
-
|
|
663
|
-
|
|
666
|
+
if (typeof body.location === 'string') {
|
|
667
|
+
const loc = body.location
|
|
668
|
+
if (loc !== 'both' && loc !== 'sidebar' && loc !== 'settings') {
|
|
669
|
+
send(400, { ok: false, error: 'location 必须是 both、sidebar 或 settings' })
|
|
670
|
+
return
|
|
671
|
+
}
|
|
672
|
+
const location = await this.setEntryLocation(loc)
|
|
673
|
+
send(200, { ok: true, location, enabled: location !== 'settings' })
|
|
674
|
+
return
|
|
675
|
+
}
|
|
676
|
+
if (typeof body.enabled === 'boolean') {
|
|
677
|
+
const location = await this.setEntryLocation(body.enabled ? 'both' : 'settings')
|
|
678
|
+
send(200, { ok: true, location, enabled: location !== 'settings' })
|
|
679
|
+
return
|
|
680
|
+
}
|
|
681
|
+
send(400, { ok: false, error: '缺少合法的 location 或 enabled 参数' })
|
|
664
682
|
return
|
|
665
683
|
}
|
|
666
684
|
send(405, { ok: false, error: 'method not allowed' })
|
|
@@ -936,14 +954,30 @@ export class ChannelManager {
|
|
|
936
954
|
this.engine.dispose()
|
|
937
955
|
}
|
|
938
956
|
|
|
957
|
+
getEntryLocation(): EntryLocation {
|
|
958
|
+
if (this.store.entryLocation === 'both' || this.store.entryLocation === 'sidebar' || this.store.entryLocation === 'settings') {
|
|
959
|
+
return this.store.entryLocation
|
|
960
|
+
}
|
|
961
|
+
return this.store.sidebarEntry === true ? 'both' : 'settings'
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
async setEntryLocation(location: EntryLocation): Promise<EntryLocation> {
|
|
965
|
+
if (location !== 'both' && location !== 'sidebar' && location !== 'settings') {
|
|
966
|
+
throw new Error("location must be one of 'both', 'sidebar', or 'settings'")
|
|
967
|
+
}
|
|
968
|
+
this.store.entryLocation = location
|
|
969
|
+
this.store.sidebarEntry = location !== 'settings'
|
|
970
|
+
this.flush()
|
|
971
|
+
return location
|
|
972
|
+
}
|
|
973
|
+
|
|
939
974
|
getSidebarEntry(): boolean {
|
|
940
|
-
return this.
|
|
975
|
+
return this.getEntryLocation() !== 'settings'
|
|
941
976
|
}
|
|
942
977
|
|
|
943
978
|
async setSidebarEntry(enabled: boolean): Promise<boolean> {
|
|
944
979
|
if (typeof enabled !== 'boolean') throw new Error('enabled 必须是布尔值')
|
|
945
|
-
this.
|
|
946
|
-
this.flush()
|
|
980
|
+
await this.setEntryLocation(enabled ? 'both' : 'settings')
|
|
947
981
|
return enabled
|
|
948
982
|
}
|
|
949
983
|
|
|
@@ -1403,7 +1437,12 @@ export class ChannelManager {
|
|
|
1403
1437
|
assistant: normalizeAssistantModel(parsed.assistant ?? {}),
|
|
1404
1438
|
cwd: normalizeWorkspacePath(parsed.cwd),
|
|
1405
1439
|
permission: normalizePermission(parsed.permission),
|
|
1406
|
-
|
|
1440
|
+
entryLocation: (parsed.entryLocation === 'both' || parsed.entryLocation === 'sidebar' || parsed.entryLocation === 'settings')
|
|
1441
|
+
? parsed.entryLocation
|
|
1442
|
+
: (typeof parsed.sidebarEntry === 'boolean' ? (parsed.sidebarEntry ? 'both' : 'settings') : undefined),
|
|
1443
|
+
sidebarEntry: typeof parsed.sidebarEntry === 'boolean'
|
|
1444
|
+
? parsed.sidebarEntry
|
|
1445
|
+
: (parsed.entryLocation ? parsed.entryLocation !== 'settings' : undefined),
|
|
1407
1446
|
onlineUpdate: typeof parsed.onlineUpdate === 'boolean' ? parsed.onlineUpdate : undefined,
|
|
1408
1447
|
taskTreeSessions: typeof parsed.taskTreeSessions === 'boolean' ? parsed.taskTreeSessions : undefined,
|
|
1409
1448
|
}
|