1- import {
2- formatThreadBindingDurationLabel ,
3- getThreadBindingManager ,
4- resolveThreadBindingIdleTimeoutMs ,
5- resolveThreadBindingInactivityExpiresAt ,
6- resolveThreadBindingMaxAgeExpiresAt ,
7- resolveThreadBindingMaxAgeMs ,
8- setThreadBindingIdleTimeoutBySessionKey ,
9- setThreadBindingMaxAgeBySessionKey ,
10- } from "../../../extensions/discord/src/monitor/thread-bindings.js" ;
11- import {
12- setTelegramThreadBindingIdleTimeoutBySessionKey ,
13- setTelegramThreadBindingMaxAgeBySessionKey ,
14- } from "../../../extensions/telegram/src/thread-bindings.js" ;
151import { resolveFastModeState } from "../../agents/fast-mode.js" ;
2+ import { formatThreadBindingDurationLabel } from "../../channels/thread-bindings-messages.js" ;
163import { parseDurationMs } from "../../cli/parse-duration.js" ;
174import { isRestartEnabled } from "../../config/commands.js" ;
185import { logVerbose } from "../../globals.js" ;
196import { getSessionBindingService } from "../../infra/outbound/session-binding-service.js" ;
207import type { SessionBindingRecord } from "../../infra/outbound/session-binding-service.js" ;
218import { scheduleGatewaySigusr1Restart , triggerOpenClawRestart } from "../../infra/restart.js" ;
229import { loadCostUsageSummary , loadSessionCostSummary } from "../../infra/session-cost-usage.js" ;
10+ import { createPluginRuntime } from "../../plugins/runtime/index.js" ;
2311import { formatTokenCount , formatUsd } from "../../utils/usage-format.js" ;
2412import { parseActivationCommand } from "../group-activation.js" ;
2513import { parseSendPolicyCommand } from "../send-policy.js" ;
@@ -34,6 +22,7 @@ const SESSION_COMMAND_PREFIX = "/session";
3422const SESSION_DURATION_OFF_VALUES = new Set ( [ "off" , "disable" , "disabled" , "none" , "0" ] ) ;
3523const SESSION_ACTION_IDLE = "idle" ;
3624const SESSION_ACTION_MAX_AGE = "max-age" ;
25+ const channelRuntime = createPluginRuntime ( ) . channel ;
3726
3827function resolveSessionCommandUsage ( ) {
3928 return "Usage: /session idle <duration|off> | /session max-age <duration|off> (example: /session idle 24h)" ;
@@ -385,7 +374,9 @@ export const handleSessionCommand: CommandHandler = async (params, allowTextComm
385374 params . ctx . MessageThreadId != null ? String ( params . ctx . MessageThreadId ) . trim ( ) : "" ;
386375 const telegramConversationId = onTelegram ? resolveTelegramConversationId ( params ) : undefined ;
387376
388- const discordManager = onDiscord ? getThreadBindingManager ( accountId ) : null ;
377+ const discordManager = onDiscord
378+ ? channelRuntime . discord . threadBindings . getManager ( accountId )
379+ : null ;
389380 if ( onDiscord && ! discordManager ) {
390381 return {
391382 shouldContinue : false ,
@@ -433,27 +424,27 @@ export const handleSessionCommand: CommandHandler = async (params, allowTextComm
433424 }
434425
435426 const idleTimeoutMs = onDiscord
436- ? resolveThreadBindingIdleTimeoutMs ( {
427+ ? channelRuntime . discord . threadBindings . resolveIdleTimeoutMs ( {
437428 record : discordBinding ! ,
438429 defaultIdleTimeoutMs : discordManager ! . getIdleTimeoutMs ( ) ,
439430 } )
440431 : resolveTelegramBindingDurationMs ( telegramBinding ! , "idleTimeoutMs" , 24 * 60 * 60 * 1000 ) ;
441432 const idleExpiresAt = onDiscord
442- ? resolveThreadBindingInactivityExpiresAt ( {
433+ ? channelRuntime . discord . threadBindings . resolveInactivityExpiresAt ( {
443434 record : discordBinding ! ,
444435 defaultIdleTimeoutMs : discordManager ! . getIdleTimeoutMs ( ) ,
445436 } )
446437 : idleTimeoutMs > 0
447438 ? resolveTelegramBindingLastActivityAt ( telegramBinding ! ) + idleTimeoutMs
448439 : undefined ;
449440 const maxAgeMs = onDiscord
450- ? resolveThreadBindingMaxAgeMs ( {
441+ ? channelRuntime . discord . threadBindings . resolveMaxAgeMs ( {
451442 record : discordBinding ! ,
452443 defaultMaxAgeMs : discordManager ! . getMaxAgeMs ( ) ,
453444 } )
454445 : resolveTelegramBindingDurationMs ( telegramBinding ! , "maxAgeMs" , 0 ) ;
455446 const maxAgeExpiresAt = onDiscord
456- ? resolveThreadBindingMaxAgeExpiresAt ( {
447+ ? channelRuntime . discord . threadBindings . resolveMaxAgeExpiresAt ( {
457448 record : discordBinding ! ,
458449 defaultMaxAgeMs : discordManager ! . getMaxAgeMs ( ) ,
459450 } )
@@ -528,24 +519,24 @@ export const handleSessionCommand: CommandHandler = async (params, allowTextComm
528519 const updatedBindings = ( ( ) => {
529520 if ( onDiscord ) {
530521 return action === SESSION_ACTION_IDLE
531- ? setThreadBindingIdleTimeoutBySessionKey ( {
522+ ? channelRuntime . discord . threadBindings . setIdleTimeoutBySessionKey ( {
532523 targetSessionKey : discordBinding ! . targetSessionKey ,
533524 accountId,
534525 idleTimeoutMs : durationMs ,
535526 } )
536- : setThreadBindingMaxAgeBySessionKey ( {
527+ : channelRuntime . discord . threadBindings . setMaxAgeBySessionKey ( {
537528 targetSessionKey : discordBinding ! . targetSessionKey ,
538529 accountId,
539530 maxAgeMs : durationMs ,
540531 } ) ;
541532 }
542533 return action === SESSION_ACTION_IDLE
543- ? setTelegramThreadBindingIdleTimeoutBySessionKey ( {
534+ ? channelRuntime . telegram . threadBindings . setIdleTimeoutBySessionKey ( {
544535 targetSessionKey : telegramBinding ! . targetSessionKey ,
545536 accountId,
546537 idleTimeoutMs : durationMs ,
547538 } )
548- : setTelegramThreadBindingMaxAgeBySessionKey ( {
539+ : channelRuntime . telegram . threadBindings . setMaxAgeBySessionKey ( {
549540 targetSessionKey : telegramBinding ! . targetSessionKey ,
550541 accountId,
551542 maxAgeMs : durationMs ,
0 commit comments