-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstate.ts
More file actions
151 lines (126 loc) · 5.71 KB
/
Copy pathstate.ts
File metadata and controls
151 lines (126 loc) · 5.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/**
* Discord Bot State
*
* Shared state containers used across handlers.
*/
import { Client, GatewayIntentBits } from 'discord.js';
// Discord client singleton
export const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
]
});
// Track if bot is ready
export let isBotReady = false;
export function setBotReady(ready: boolean): void {
isBotReady = ready;
}
// Active WebSocket connections (runnerId -> ws)
export const runnerConnections = new Map<string, any>();
// Pending approvals now use unified permissionStateStore (see permissions/state-store.ts)
// Allowed tools per session (sessionId -> Set of toolNames that are auto-approved)
export const allowedTools = new Map<string, Set<string>>();
// Action items extracted from sessions (sessionId -> actionItems)
export const actionItems = new Map<string, string[]>();
// Streaming message tracker (sessionId -> message state)
export interface StreamingMessage {
messageId: string;
lastUpdateTime: number;
content: string;
outputType: string;
accumulatedContent?: string; // Tracks the full accumulated content for the message
}
export const streamingMessages = new Map<string, StreamingMessage>();
// Session creation state (userId -> creation wizard state)
export interface SessionCreationState {
step: 'select_runner' | 'select_cli' | 'select_plugin' | 'select_folder' | 'complete';
runnerId?: string;
cliType?: 'claude' | 'gemini' | 'codex' | 'terminal';
plugin?: 'tmux' | 'print' | 'stream' | 'claude-sdk' | 'codex-sdk' | 'gemini-sdk';
folder?: string; // Pre-selected folder (for "New Session" button)
folderPath?: string;
options?: {
approvalMode?: 'manual' | 'autoSafe' | 'auto';
skipPermissions?: boolean;
thinkingLevel?: 'off' | 'low' | 'medium' | 'high' | 'auto' | 'default_on';
maxThinkingTokens?: number;
maxTurns?: number;
maxBudgetUsd?: number;
model?: string;
fallbackModel?: string;
agent?: string;
permissionMode?: 'default' | 'acceptEdits';
[key: string]: any;
};
messageId?: string;
projectChannelId?: string;
targetThreadId?: string;
}
export const sessionCreationState = new Map<string, SessionCreationState>();
// Session status tracker (sessionId -> status)
export type SessionStatus = 'idle' | 'working' | 'waiting' | 'offline' | 'error';
export const sessionStatuses = new Map<string, SessionStatus>();
// Pending terminal list requests (runnerId -> interaction info)
export interface PendingTerminalListRequest {
interactionToken: string;
applicationId: string;
runnerName: string;
requestedAt: number;
}
export const pendingTerminalListRequests = new Map<string, PendingTerminalListRequest>();
// Assistant streaming messages tracker (runnerId -> message state)
export const assistantStreamingMessages = new Map<string, StreamingMessage>();
// Multi-select question state (requestId -> multi-select state)
export interface MultiSelectState {
requestId: string;
sessionId: string;
runnerId: string;
selectedOptions: Set<string>; // Set of selected option numbers
options: string[]; // All available options
isMultiSelect: boolean;
hasOther: boolean;
toolName: string;
timestamp: Date;
}
export const multiSelectState = new Map<string, MultiSelectState>();
// User scope preference (userId -> scope)
export type UserScope = 'session' | 'project' | 'global';
export const userScopePreferences = new Map<string, UserScope>();
// Pending permission confirmations (requestId -> confirmation state)
export interface PendingPermissionConfirmation {
requestId: string;
interaction: any;
userId: string;
username: string;
toolName: string;
behavior: 'allow' | 'deny';
scope?: string;
timeout: NodeJS.Timeout;
}
export const pendingPermissionConfirmations = new Map<string, PendingPermissionConfirmation>();
// Pending runner config updates (requestId -> timeout)
export const pendingRunnerConfigUpdates = new Map<string, NodeJS.Timeout>();
export const pendingRunnerHealthRequests = new Map<string, { resolve: (data: any | null) => void; timeout: NodeJS.Timeout }>();
export const pendingRunnerLogsRequests = new Map<string, { resolve: (data: any | null) => void; timeout: NodeJS.Timeout }>();
export const pendingCodexThreadListRequests = new Map<string, { resolve: (data: any | null) => void; timeout: NodeJS.Timeout }>();
export const pendingModelListRequests = new Map<string, { resolve: (data: any | null) => void; timeout: NodeJS.Timeout }>();
export interface RunnerModelCacheEntry {
runnerId: string;
cliType: 'claude' | 'codex';
models: Array<{ id: string; label: string; description?: string; isDefault?: boolean }>;
defaultModel?: string | null;
nextCursor?: string | null;
fetchedAt: number;
}
export const runnerModelCache = new Map<string, RunnerModelCacheEntry>();
export const codexThreadCache = new Map<string, { runnerId: string; cwd?: string; preview?: string; updatedAt?: number; createdAt?: number; lastSeen: number }>();
// One-shot suppression for reconnect reattach flows (sessionId -> suppress next session_ready post)
export const suppressSessionReadyNotification = new Set<string>();
// Track sessions that have already received "Session Ready" notification (to prevent duplicate pings)
export const sessionReadyNotified = new Set<string>();
// Pending attach-to-approve fallback notices (sessionId -> timeout + target thread)
export const pendingSyncedAttachFallbacks = new Map<string, { threadId: string; timeout: NodeJS.Timeout }>();
// Runner memory tracking (runnerId -> memory in MB)
export const runnerMemoryUsage = new Map<string, number>();