feat: wire Cordis apply lifecycle with soft-fail token check

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
owo
2026-08-14 16:30:48 +08:00
co-authored by Cursor
parent cdfe81cd9e
commit 27f02b7460
3 changed files with 55 additions and 6 deletions
+4 -4
View File
@@ -3,10 +3,10 @@ import type { AgentHandle } from '@deepseek-ai/dsh-agent'
import { createUserMessage } from '@deepseek-ai/dsh-llm/message'
import type { ContentBlock, TextBlock } from '@deepseek-ai/dsh-llm/types'
import { SessionId, type SessionEvent } from '@deepseek-ai/dsh-session/types'
import { isAuthorized } from './auth.ts'
import { TelegramClient, type TelegramClientLike, type TelegramUpdate } from './client.ts'
import { MSG, parseCommand } from './commands.ts'
import { markdownToHtml, splitMessage } from './format.ts'
import { isAuthorized } from './auth.js'
import { TelegramClient, type TelegramClientLike, type TelegramUpdate } from './client.js'
import { MSG, parseCommand } from './commands.js'
import { markdownToHtml, splitMessage } from './format.js'
export interface TelegramBridgeOptions {
token: string
+30 -2
View File
@@ -1,5 +1,6 @@
import type { Context } from '@deepseek-ai/cordis'
import Schema from '@deepseek-ai/schemastery'
import { TelegramBridge } from './bridge.js'
export const name = 'dsh-telegram-channel'
export const inject = ['agents']
@@ -26,6 +27,33 @@ export const Config: Schema<TelegramChannelConfig> = Schema.object({
cwd: Schema.string(),
})
export function apply(_ctx: Context, _config: TelegramChannelConfig): void {
// Task 6 fills this in
export function apply(ctx: Context, config: TelegramChannelConfig): void {
const token = (config.token && config.token.length > 0)
? config.token
: (process.env.DSH_TELEGRAM_TOKEN ?? '')
if (!token) {
ctx.logger.error(
'dsh-telegram-channel: missing bot token (set config.token or DSH_TELEGRAM_TOKEN); polling not started',
)
return
}
const bridge = new TelegramBridge(ctx, {
token,
allowedUserIds: config.allowedUserIds ?? [],
allowAllUsers: config.allowAllUsers ?? false,
provider: config.provider ?? 'deepseek-official',
model: config.model ?? 'deepseek-v4-flash',
maxMessageLength: config.maxMessageLength ?? 4096,
cwd: config.cwd ?? process.cwd(),
})
ctx.effect(() => {
bridge.start()
return () => { void bridge.stop() }
}, 'dsh-telegram-channel.serve')
}
export * from './format.js'
export * from './client.js'
export * from './auth.js'
export * from './commands.js'
export * from './bridge.js'