@michengai/dsh-im-connect 0.1.13 → 0.1.15

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.
@@ -50,6 +50,6 @@ export interface EngineConfig {
50
50
  model: string
51
51
  agentPreset: string
52
52
  mergeTimeoutSecs: number
53
- permissionPreset: 'read-only' | 'workspace-write' | 'full-access'
53
+ permissionPreset: string
54
54
  reasoningEffort?: string
55
55
  }
package/src/index.ts CHANGED
@@ -10,7 +10,7 @@ import { ChannelManager } from './manager.js'
10
10
  import type { EngineConfig } from './engine/types.js'
11
11
 
12
12
  export const name = 'dsh-im-connect'
13
- export const inject = ['webServer', 'credentials', 'agents', 'agentPresets', 'agentDefaultModel', 'llm']
13
+ export const inject = ['webServer', 'credentials', 'agents', 'agentPresets', 'agentDefaultModel', 'llm', 'permissionPresets']
14
14
 
15
15
  export interface PluginConfig {
16
16
  stateDir: string
@@ -31,6 +31,7 @@ export const Config: Schema<PluginConfig> = Schema.object({
31
31
  })
32
32
 
33
33
  export function apply(ctx: Context, config: PluginConfig): void {
34
+ const permissionPresets = (ctx as Context & { permissionPresets: { defaultPreset: string } }).permissionPresets
34
35
  const stateDir = config.stateDir !== ''
35
36
  ? config.stateDir
36
37
  : join(process.env.DSH_HOME ?? join(homedir(), '.dsh'), 'dsh-im-connect')
@@ -48,7 +49,7 @@ export function apply(ctx: Context, config: PluginConfig): void {
48
49
  model: config.model,
49
50
  agentPreset: config.agentPreset || 'standard',
50
51
  mergeTimeoutSecs: config.mergeTimeoutSecs || 5,
51
- permissionPreset: 'read-only',
52
+ permissionPreset: permissionPresets.defaultPreset,
52
53
  }
53
54
 
54
55
  const applyStarted = Date.now()
@@ -75,4 +76,3 @@ export {
75
76
  export { splitText } from './engine/split.js'
76
77
 
77
78
 
78
-
package/src/manager.ts CHANGED
@@ -39,14 +39,26 @@ interface PendingRequest {
39
39
  time: number
40
40
  }
41
41
 
42
- interface Persisted {
42
+ interface Persisted {
43
43
  channels: Record<string, ChannelState>
44
44
  allowlist: Record<string, string[]>
45
45
  pending: Record<string, PendingRequest[]>
46
46
  assistant?: AssistantModel
47
47
  cwd?: string
48
- permission?: PermissionPreset
49
- }
48
+ permission?: PermissionPreset
49
+ }
50
+
51
+ export interface PermissionOptionView {
52
+ value: string
53
+ name: string
54
+ description?: string
55
+ }
56
+
57
+ interface PermissionPresetService {
58
+ readonly names: readonly string[]
59
+ readonly defaultPreset: string
60
+ optionOf(name: string): PermissionOptionView
61
+ }
50
62
 
51
63
  export class ChannelManager {
52
64
  private readonly file: string
@@ -267,7 +279,14 @@ export class ChannelManager {
267
279
  const parts = url.pathname.split('/').filter(Boolean)
268
280
  if (parts[2] === 'assistant' && parts.length === 3) {
269
281
  if (req.method === 'GET') {
270
- send(res, 200, { ok: true, assistant: this.currentAssistant(), cwd: this.currentWorkspace(), permission: this.currentPermission(), providers: await this.listModelCatalog() })
282
+ send(res, 200, {
283
+ ok: true,
284
+ assistant: this.currentAssistant(),
285
+ cwd: this.currentWorkspace(),
286
+ permission: this.currentPermission(),
287
+ permissions: this.permissionOptions(),
288
+ providers: await this.listModelCatalog(),
289
+ })
271
290
  return
272
291
  }
273
292
  if (req.method === 'POST') {
@@ -422,8 +441,8 @@ export class ChannelManager {
422
441
  this.applyWorkspace(cwd)
423
442
  this.log(`[manager] 工作区已设为 ${cwd}`)
424
443
  }
425
- if (hasPermission) {
426
- const permission = normalizePermission(input.permission)
444
+ if (hasPermission) {
445
+ const permission = normalizePermission(input.permission, this.permissionPresets().names)
427
446
  if (!permission) return { ok: false, error: '请选择权限' }
428
447
  this.store.permission = permission
429
448
  this.applyPermission(permission)
@@ -453,16 +472,26 @@ export class ChannelManager {
453
472
  this.engine?.setCwd(next)
454
473
  }
455
474
 
456
- currentPermission(): PermissionPreset {
457
- return this.store.permission || this.engineConfig.permissionPreset || 'read-only'
458
- }
459
-
460
- private applyPermission(permission?: PermissionPreset): void {
461
- const next = normalizePermission(permission)
462
- if (!next) return
463
- this.engineConfig.permissionPreset = next
464
- this.engine?.setPermission(next)
465
- }
475
+ currentPermission(): PermissionPreset {
476
+ const official = this.permissionPresets()
477
+ return normalizePermission(this.store.permission ?? this.engineConfig.permissionPreset, official.names) ?? official.defaultPreset
478
+ }
479
+
480
+ private applyPermission(permission?: PermissionPreset): void {
481
+ const next = normalizePermission(permission, this.permissionPresets().names)
482
+ if (!next) return
483
+ this.engineConfig.permissionPreset = next
484
+ this.engine?.setPermission(next)
485
+ }
486
+
487
+ permissionOptions(): PermissionOptionView[] {
488
+ const official = this.permissionPresets()
489
+ return official.names.map((name) => official.optionOf(name))
490
+ }
491
+
492
+ private permissionPresets(): PermissionPresetService {
493
+ return (this.ctx as Context & { permissionPresets: PermissionPresetService }).permissionPresets
494
+ }
466
495
 
467
496
  private async listModelCatalog(): Promise<Array<{ id: string; name: string; models: Array<{ id: string; name: string }> }>> {
468
497
  const llm = (this.ctx as Context & {
@@ -2,9 +2,6 @@ declare module '@larksuiteoapi/node-sdk'
2
2
  declare module '@wecom/aibot-node-sdk'
3
3
  declare module 'dingtalk-stream'
4
4
  declare module 'qrcode'
5
- declare module '@deepseek-ai/dsh-sandbox-policy' {
6
- export function setSandboxMode(session: unknown, mode: 'read-only' | 'workspace-write' | 'danger-full-access'): void
7
- }
8
5
  declare module '@deepseek-ai/dsh-agent' {
9
6
  export function installModelSelection(agentCtx: unknown, selection: {
10
7
  current: { provider: string; model: string; reasoningEffort?: string }