GoodBuddy Agents / Validate Agent source (push) Canceled after 0s
GoodBuddy Agents / Build darwin arm64 Agent (push) Canceled after 0s
GoodBuddy Agents / Build linux arm64 Agent (push) Canceled after 0s
GoodBuddy Agents / Build linux x64 Agent (push) Canceled after 0s
Cross-platform packages / Validate source (push) Canceled after 0s
Cross-platform packages / Authorize desktop packaging (push) Canceled after 0s
Cross-platform packages / linux arm64 (push) Canceled after 0s
Cross-platform packages / macos arm64 (push) Canceled after 0s
Cross-platform packages / windows arm64 (push) Canceled after 0s
Cross-platform packages / linux x64 (push) Canceled after 0s
Cross-platform packages / macos x64 (push) Canceled after 0s
Cross-platform packages / windows x64 (push) Canceled after 0s
Cross-platform packages / Publish GitHub and OSS release (push) Canceled after 0s
Keep interactive questions and answered cards at their original position in conversation history, including remote reception, recovery, and reopening. Preserve legacy history placement without a database migration. Move supplementary guidance into shared accessible contextual-help popovers across pages and settings. Add keyboard, modal, accessibility, and Electron regressions, plus bounded opt-in live canvas-analysis validation. Remove unused Agent, Runtime, and in-memory graph-search helpers, obsolete mocks and browser copy; reuse the existing package-size formatter. Keep production execution paths, protocol schemas, and released data migrations. Validation: targeted cleanup tests, typecheck, lint, shared Linux Host attach/read/re-attach, and added help/Electron checks passed. Final full-suite verification passed 4,858 tests with 67 skipped and zero failures (412 files passed, 9 skipped). Focused help checks passed 54 tests, including Electron style comparisons and Chromium accessibility descriptions. Details and validation boundaries are recorded in feature docs. Release note: 修复交互式问答在回答后排到后续输出末尾的问题,重新打开会话仍保留提问位置。页面和设置中的补充说明改为标题或字段旁的按需帮助,支持鼠标与键盘操作。
224 lines
5.8 KiB
TypeScript
224 lines
5.8 KiB
TypeScript
import type { ChannelExecutor } from './channel-driver'
|
|
import { ChannelService } from './channel-service'
|
|
import {
|
|
DingTalkChannelDriver,
|
|
type DingTalkChannelDriverOptions
|
|
} from './dingtalk-channel-driver'
|
|
import {
|
|
normalizeDingTalkStaffId,
|
|
type DingTalkTransportFactory
|
|
} from './dingtalk-driver'
|
|
import {
|
|
WeComChannelDriver,
|
|
type WeComChannelDriverOptions
|
|
} from './wecom-channel-driver'
|
|
import type { WeComTransportFactory } from './wecom-driver'
|
|
|
|
type ChannelEnvironmentConfig =
|
|
| {
|
|
channel: 'dingtalk'
|
|
clientId: string
|
|
clientSecret: string
|
|
allowedSenderIds: readonly string[]
|
|
allowGroupMessages: boolean
|
|
}
|
|
| {
|
|
channel: 'wecom'
|
|
botId: string
|
|
secret: string
|
|
allowedSenderIds: readonly string[]
|
|
allowGroupMessages: boolean
|
|
}
|
|
|
|
export type EnvironmentChannelService = Pick<
|
|
ChannelService,
|
|
'start' | 'stop'
|
|
>
|
|
|
|
export type EnvironmentChannelBootstrapOptions = {
|
|
executor: ChannelExecutor
|
|
env?: NodeJS.ProcessEnv
|
|
dingtalkTransportFactory?: DingTalkTransportFactory
|
|
wecomTransportFactory?: WeComTransportFactory
|
|
createDingTalkDriver?: (
|
|
options: DingTalkChannelDriverOptions
|
|
) => DingTalkChannelDriver
|
|
createWeComDriver?: (
|
|
options: WeComChannelDriverOptions
|
|
) => WeComChannelDriver
|
|
createService?: (
|
|
driver: DingTalkChannelDriver | WeComChannelDriver,
|
|
executor: ChannelExecutor,
|
|
options: {
|
|
allowedSenderIds: readonly string[]
|
|
allowGroupMessages: boolean
|
|
}
|
|
) => EnvironmentChannelService
|
|
onStartError?: (channel: string, error: string) => void
|
|
}
|
|
|
|
function optionalCredential(
|
|
env: NodeJS.ProcessEnv,
|
|
name: string
|
|
): string | undefined {
|
|
const value = env[name]
|
|
if (value === undefined || value.trim() === '') {
|
|
return undefined
|
|
}
|
|
return value.trim()
|
|
}
|
|
|
|
function parseBoolean(
|
|
env: NodeJS.ProcessEnv,
|
|
name: string
|
|
): boolean {
|
|
const raw = env[name]
|
|
if (raw === undefined || raw === '') {
|
|
return false
|
|
}
|
|
if (raw === 'true') {
|
|
return true
|
|
}
|
|
if (raw === 'false') {
|
|
return false
|
|
}
|
|
throw new Error(`${name} 必须是 true 或 false`)
|
|
}
|
|
|
|
function parseList(
|
|
env: NodeJS.ProcessEnv,
|
|
name: string
|
|
): readonly string[] {
|
|
const raw = env[name]
|
|
if (raw === undefined || raw === '') {
|
|
return []
|
|
}
|
|
const values = raw.split(',').map((value) => value.trim())
|
|
if (values.some((value) => value === '')) {
|
|
throw new Error(`${name} 包含空白身份`)
|
|
}
|
|
return [...new Set(values)]
|
|
}
|
|
|
|
export function parseChannelEnvironment(
|
|
env: NodeJS.ProcessEnv
|
|
): readonly ChannelEnvironmentConfig[] {
|
|
const configs: ChannelEnvironmentConfig[] = []
|
|
const dingTalkClientId = optionalCredential(
|
|
env,
|
|
'GOODBUDDY_DINGTALK_CLIENT_ID'
|
|
)
|
|
const dingTalkClientSecret = optionalCredential(
|
|
env,
|
|
'GOODBUDDY_DINGTALK_CLIENT_SECRET'
|
|
)
|
|
const dingTalkAllowedSenderIds = parseList(
|
|
env,
|
|
'GOODBUDDY_DINGTALK_ALLOWED_SENDERS'
|
|
).map(normalizeDingTalkStaffId)
|
|
const dingTalkAllowGroupMessages = parseBoolean(
|
|
env,
|
|
'GOODBUDDY_DINGTALK_ALLOW_GROUPS'
|
|
)
|
|
if (
|
|
dingTalkClientId &&
|
|
dingTalkClientSecret &&
|
|
dingTalkAllowedSenderIds.length > 0
|
|
) {
|
|
configs.push({
|
|
channel: 'dingtalk',
|
|
clientId: dingTalkClientId,
|
|
clientSecret: dingTalkClientSecret,
|
|
allowedSenderIds: dingTalkAllowedSenderIds,
|
|
allowGroupMessages: dingTalkAllowGroupMessages
|
|
})
|
|
}
|
|
|
|
const weComBotId = optionalCredential(
|
|
env,
|
|
'GOODBUDDY_WECOM_BOT_ID'
|
|
)
|
|
const weComSecret = optionalCredential(
|
|
env,
|
|
'GOODBUDDY_WECOM_SECRET'
|
|
)
|
|
const weComAllowedSenderIds = parseList(
|
|
env,
|
|
'GOODBUDDY_WECOM_ALLOWED_SENDERS'
|
|
)
|
|
const weComAllowGroupMessages = parseBoolean(
|
|
env,
|
|
'GOODBUDDY_WECOM_ALLOW_GROUPS'
|
|
)
|
|
if (
|
|
weComBotId &&
|
|
weComSecret &&
|
|
weComAllowedSenderIds.length > 0
|
|
) {
|
|
configs.push({
|
|
channel: 'wecom',
|
|
botId: weComBotId,
|
|
secret: weComSecret,
|
|
allowedSenderIds: weComAllowedSenderIds,
|
|
allowGroupMessages: weComAllowGroupMessages
|
|
})
|
|
}
|
|
return configs
|
|
}
|
|
|
|
export function startEnvironmentChannels(
|
|
options: EnvironmentChannelBootstrapOptions
|
|
): readonly EnvironmentChannelService[] {
|
|
let configs: readonly ChannelEnvironmentConfig[]
|
|
try {
|
|
configs = parseChannelEnvironment(options.env ?? process.env)
|
|
} catch {
|
|
options.onStartError?.('environment', '通道环境变量配置无效')
|
|
return []
|
|
}
|
|
const services = configs.map((config) => {
|
|
const driver =
|
|
config.channel === 'dingtalk'
|
|
? (options.createDingTalkDriver ??
|
|
((driverOptions) =>
|
|
new DingTalkChannelDriver(driverOptions)))({
|
|
clientId: config.clientId,
|
|
clientSecret: config.clientSecret,
|
|
allowedSenderIds: config.allowedSenderIds,
|
|
...(options.dingtalkTransportFactory
|
|
? {
|
|
transportFactory:
|
|
options.dingtalkTransportFactory
|
|
}
|
|
: {})
|
|
})
|
|
: (options.createWeComDriver ??
|
|
((driverOptions) =>
|
|
new WeComChannelDriver(driverOptions)))({
|
|
botId: config.botId,
|
|
secret: config.secret,
|
|
...(options.wecomTransportFactory
|
|
? { transportFactory: options.wecomTransportFactory }
|
|
: {})
|
|
})
|
|
const service = (
|
|
options.createService ??
|
|
((channelDriver, executor, serviceOptions) =>
|
|
new ChannelService(channelDriver, executor, serviceOptions))
|
|
)(driver, options.executor, {
|
|
allowedSenderIds: config.allowedSenderIds,
|
|
allowGroupMessages: config.allowGroupMessages
|
|
})
|
|
void Promise.resolve()
|
|
.then(() => service.start())
|
|
.catch(() => {
|
|
options.onStartError?.(
|
|
config.channel,
|
|
`${config.channel} 通道启动失败`
|
|
)
|
|
})
|
|
return service
|
|
})
|
|
return services
|
|
}
|