2026-11-08 08:30:54 +08:00
|
|
|
import type { Context } from '@deepseek-ai/cordis'
|
2026-11-16 12:05:30 +08:00
|
|
|
import { Config, addressesOf, mailboxOf } from './config.js'
|
|
|
|
|
import { MailGateway } from './gateway.js'
|
|
|
|
|
import { MailGatewayService } from './service.js'
|
|
|
|
|
|
|
|
|
|
export { Config } from './config.js'
|
2026-11-08 08:30:54 +08:00
|
|
|
|
|
|
|
|
export const name = 'dsh-mail-sender'
|
2026-11-17 08:17:54 +08:00
|
|
|
export const inject = ['agents', 'sessions', 'settings']
|
2026-11-08 08:30:54 +08:00
|
|
|
|
2026-11-16 12:05:30 +08:00
|
|
|
/**
|
|
|
|
|
* 常驻入口:邮件驱动会话,而不是等待模型调用的 Tool。
|
|
|
|
|
* 所有 IMAP/SMTP 资源与监听都收在 ctx.effect 里按序回收。
|
|
|
|
|
*/
|
2026-11-08 08:30:54 +08:00
|
|
|
export function apply(ctx: Context, config: Config): void {
|
2026-11-16 12:05:30 +08:00
|
|
|
const gateway = new MailGateway(ctx, mailboxOf(config), addressesOf(config))
|
|
|
|
|
new MailGatewayService(ctx, gateway, config, name)
|
2026-11-08 08:30:54 +08:00
|
|
|
|
|
|
|
|
ctx.effect(() => {
|
2026-11-16 12:05:30 +08:00
|
|
|
const disposeGateway = gateway.start()
|
|
|
|
|
const on = ctx.on as unknown as (event: string, listener: () => void) => () => void
|
|
|
|
|
const off = on('loader/volatile-update', () => {
|
|
|
|
|
gateway.reload(mailboxOf(config), addressesOf(config))
|
|
|
|
|
})
|
|
|
|
|
return async () => {
|
|
|
|
|
off()
|
|
|
|
|
await disposeGateway()
|
2026-11-08 08:30:54 +08:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|