agentgram 0.0.0-stage → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +201 -2
- package/dist/index.d.ts +762 -0
- package/dist/index.js +3945 -0
- package/dist/index.js.map +1 -0
- package/package.json +59 -4
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,762 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import * as child_process from 'node:child_process';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* AgentGram Domain Types & Data Contracts
|
|
6
|
+
* Strict types for configuration, security, Telegram Bot API, and OpenCode events.
|
|
7
|
+
*/
|
|
8
|
+
type ExecutionMode = 'read' | 'build' | 'auto';
|
|
9
|
+
type PermissionDecision = 'allow' | 'reject' | 'ask';
|
|
10
|
+
interface AgentgramConfig {
|
|
11
|
+
botToken: string;
|
|
12
|
+
allowedChatId: string;
|
|
13
|
+
targetDir: string;
|
|
14
|
+
defaultAgent: string;
|
|
15
|
+
defaultModel: string;
|
|
16
|
+
favoriteModels: string[];
|
|
17
|
+
dailyLimit: number;
|
|
18
|
+
runTimeout: number;
|
|
19
|
+
language: 'en' | 'ar';
|
|
20
|
+
denyPatterns: string[];
|
|
21
|
+
allowedPaths: string[];
|
|
22
|
+
channel?: string;
|
|
23
|
+
engine?: string;
|
|
24
|
+
workspaces: string[];
|
|
25
|
+
extra: Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
type PromptCategory = 'role_hijack' | 'boundary_escape' | 'exfiltration' | 'obfuscation' | 'clean';
|
|
28
|
+
interface PromptDetectionResult {
|
|
29
|
+
blocked: boolean;
|
|
30
|
+
reason: string;
|
|
31
|
+
confidence: number;
|
|
32
|
+
category?: PromptCategory;
|
|
33
|
+
}
|
|
34
|
+
interface QuarantineResult {
|
|
35
|
+
envelope: string;
|
|
36
|
+
block: string;
|
|
37
|
+
nonce: string;
|
|
38
|
+
}
|
|
39
|
+
interface PathCheckResult {
|
|
40
|
+
ok: boolean;
|
|
41
|
+
reason: string;
|
|
42
|
+
}
|
|
43
|
+
interface ServiceStatus {
|
|
44
|
+
installed: boolean;
|
|
45
|
+
running: boolean;
|
|
46
|
+
system: string;
|
|
47
|
+
path?: string | undefined;
|
|
48
|
+
}
|
|
49
|
+
interface InlineKeyboardButton {
|
|
50
|
+
text: string;
|
|
51
|
+
callback_data?: string | undefined;
|
|
52
|
+
url?: string | undefined;
|
|
53
|
+
}
|
|
54
|
+
interface InlineKeyboardMarkup {
|
|
55
|
+
inline_keyboard: InlineKeyboardButton[][];
|
|
56
|
+
}
|
|
57
|
+
interface TelegramUser {
|
|
58
|
+
id: number;
|
|
59
|
+
is_bot: boolean;
|
|
60
|
+
first_name: string;
|
|
61
|
+
last_name?: string;
|
|
62
|
+
username?: string;
|
|
63
|
+
}
|
|
64
|
+
interface TelegramChat {
|
|
65
|
+
id: number;
|
|
66
|
+
type: string;
|
|
67
|
+
title?: string;
|
|
68
|
+
username?: string;
|
|
69
|
+
}
|
|
70
|
+
interface TelegramPhotoSize {
|
|
71
|
+
file_id: string;
|
|
72
|
+
file_unique_id: string;
|
|
73
|
+
width: number;
|
|
74
|
+
height: number;
|
|
75
|
+
file_size?: number;
|
|
76
|
+
}
|
|
77
|
+
interface TelegramMessage {
|
|
78
|
+
message_id: number;
|
|
79
|
+
from?: TelegramUser;
|
|
80
|
+
chat: TelegramChat;
|
|
81
|
+
date: number;
|
|
82
|
+
text?: string;
|
|
83
|
+
caption?: string;
|
|
84
|
+
photo?: TelegramPhotoSize[];
|
|
85
|
+
reply_to_message?: TelegramMessage;
|
|
86
|
+
}
|
|
87
|
+
interface CallbackQuery {
|
|
88
|
+
id: string;
|
|
89
|
+
from: TelegramUser;
|
|
90
|
+
message?: TelegramMessage;
|
|
91
|
+
data?: string;
|
|
92
|
+
}
|
|
93
|
+
interface TelegramUpdate {
|
|
94
|
+
update_id: number;
|
|
95
|
+
message?: TelegramMessage;
|
|
96
|
+
callback_query?: CallbackQuery;
|
|
97
|
+
}
|
|
98
|
+
interface OpenCodeToolCall {
|
|
99
|
+
id: string;
|
|
100
|
+
tool: string;
|
|
101
|
+
call_id?: string;
|
|
102
|
+
status: 'running' | 'done' | 'error';
|
|
103
|
+
args?: Record<string, unknown>;
|
|
104
|
+
output?: string;
|
|
105
|
+
title?: string;
|
|
106
|
+
}
|
|
107
|
+
interface OpenCodeRun {
|
|
108
|
+
sessionId: string;
|
|
109
|
+
agent: string;
|
|
110
|
+
model: string;
|
|
111
|
+
mode: ExecutionMode;
|
|
112
|
+
startedAt: number;
|
|
113
|
+
userMsgId?: number | undefined;
|
|
114
|
+
userMessages: Set<string>;
|
|
115
|
+
text: Record<string, string>;
|
|
116
|
+
textOrder: string[];
|
|
117
|
+
msgOfPart: Record<string, number>;
|
|
118
|
+
tools: Record<string, OpenCodeToolCall>;
|
|
119
|
+
toolOrder: string[];
|
|
120
|
+
files: Set<string>;
|
|
121
|
+
cmds: number;
|
|
122
|
+
busy: boolean;
|
|
123
|
+
done: boolean;
|
|
124
|
+
error?: string | null | undefined;
|
|
125
|
+
}
|
|
126
|
+
interface OpenCodePermissionRequest {
|
|
127
|
+
id: string;
|
|
128
|
+
permission: string;
|
|
129
|
+
patterns?: string[];
|
|
130
|
+
metadata?: {
|
|
131
|
+
command?: string;
|
|
132
|
+
filepath?: string;
|
|
133
|
+
[key: string]: unknown;
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
interface OpenCodeQuestionOption {
|
|
137
|
+
label: string;
|
|
138
|
+
description?: string;
|
|
139
|
+
}
|
|
140
|
+
interface OpenCodeQuestionRequest {
|
|
141
|
+
id: string;
|
|
142
|
+
question: string;
|
|
143
|
+
header?: string;
|
|
144
|
+
options: OpenCodeQuestionOption[];
|
|
145
|
+
multiple?: boolean;
|
|
146
|
+
custom?: boolean;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
declare class PromptInjectionGuard {
|
|
150
|
+
/**
|
|
151
|
+
* Count hidden zero-width and BiDi characters in text.
|
|
152
|
+
*/
|
|
153
|
+
countHiddenChars(text: string): number;
|
|
154
|
+
/**
|
|
155
|
+
* Normalize Unicode (NFKC) and strip zero-width and BiDi override evasion characters.
|
|
156
|
+
*/
|
|
157
|
+
sanitizeText(text: string): string;
|
|
158
|
+
/**
|
|
159
|
+
* Neutralize boundary and system delimiter tags so they cannot be escaped.
|
|
160
|
+
*/
|
|
161
|
+
neutralizeDelimiters(text: string): string;
|
|
162
|
+
/**
|
|
163
|
+
* Check text for prompt injection, jailbreaks, and delimiter escapes.
|
|
164
|
+
*/
|
|
165
|
+
detect(rawText: string): PromptDetectionResult;
|
|
166
|
+
/**
|
|
167
|
+
* Isolate untrusted reports, logs, and external texts inside a cryptographically signed quarantine block.
|
|
168
|
+
*/
|
|
169
|
+
quarantine(text: string, limit?: number): QuarantineResult;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
declare const DEFAULT_DENY_PATTERNS: RegExp[];
|
|
173
|
+
declare class SecurityPolicy {
|
|
174
|
+
readonly targetDir: string;
|
|
175
|
+
readonly allowedPaths: string[];
|
|
176
|
+
readonly denyPatterns: RegExp[];
|
|
177
|
+
readonly promptGuard: PromptInjectionGuard;
|
|
178
|
+
constructor(targetDir: string, customPatterns?: string[], allowedPaths?: string[]);
|
|
179
|
+
/**
|
|
180
|
+
* Check if a command matches any forbidden patterns. Returns list of matched regex sources.
|
|
181
|
+
*/
|
|
182
|
+
checkCommand(commandStr: string): string[];
|
|
183
|
+
/**
|
|
184
|
+
* Verify file operations remain within the project scope or allowed path boundaries.
|
|
185
|
+
*/
|
|
186
|
+
checkFilePath(filePath: string): PathCheckResult;
|
|
187
|
+
checkPrompt(text: string): PromptDetectionResult;
|
|
188
|
+
sanitizePrompt(text: string): string;
|
|
189
|
+
quarantineUntrustedData(text: string, limit?: number): QuarantineResult;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
declare const LEGACY_CONFIG_DIR: string;
|
|
193
|
+
declare const AGENTGRAM_CONFIG_DIR: string;
|
|
194
|
+
declare function getGlobalConfigDir(): string;
|
|
195
|
+
declare function ensureConfigDirs(): void;
|
|
196
|
+
declare function computeWorkspaceId(directory: string): string;
|
|
197
|
+
declare class ConfigManager {
|
|
198
|
+
config: AgentgramConfig;
|
|
199
|
+
readonly workspaceId: string;
|
|
200
|
+
readonly globalConfigPath: string;
|
|
201
|
+
readonly projectConfigPath: string;
|
|
202
|
+
readonly legacyProjectConfigPath: string;
|
|
203
|
+
readonly stateDir: string;
|
|
204
|
+
readonly roomStatePath: string;
|
|
205
|
+
readonly gatePath: string;
|
|
206
|
+
readonly auditPath: string;
|
|
207
|
+
constructor(targetDir?: string, customConfigPath?: string);
|
|
208
|
+
load(): void;
|
|
209
|
+
merge(data: Record<string, unknown>): void;
|
|
210
|
+
saveGlobal(): void;
|
|
211
|
+
saveProject(): void;
|
|
212
|
+
addWorkspace(newWorkspace: string): boolean;
|
|
213
|
+
removeWorkspace(workspace: string): boolean;
|
|
214
|
+
validate(): string[];
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* AgentGram Pluggable Communication Channel Contract
|
|
219
|
+
* Hexagonal architecture port for messaging and interaction channels (Telegram, Console, Slack, Discord, Webhook, etc.)
|
|
220
|
+
* Pure Node.js with zero runtime dependencies.
|
|
221
|
+
*/
|
|
222
|
+
interface ChannelButton {
|
|
223
|
+
text: string;
|
|
224
|
+
callbackData?: string | undefined;
|
|
225
|
+
url?: string | undefined;
|
|
226
|
+
}
|
|
227
|
+
interface ChannelKeyboard {
|
|
228
|
+
rows: ChannelButton[][];
|
|
229
|
+
}
|
|
230
|
+
interface ChannelSendOptions {
|
|
231
|
+
replyMarkup?: ChannelKeyboard | undefined;
|
|
232
|
+
replyToMessageId?: string | number | undefined;
|
|
233
|
+
parseMode?: 'HTML' | 'Markdown' | 'None' | undefined;
|
|
234
|
+
disableWebPagePreview?: boolean | undefined;
|
|
235
|
+
}
|
|
236
|
+
interface ChannelMessageResult {
|
|
237
|
+
messageId: string | number;
|
|
238
|
+
chatId: string;
|
|
239
|
+
timestamp: number;
|
|
240
|
+
}
|
|
241
|
+
interface IncomingChannelMessage {
|
|
242
|
+
id: string | number;
|
|
243
|
+
senderId: string;
|
|
244
|
+
chatId: string;
|
|
245
|
+
text: string;
|
|
246
|
+
timestamp: number;
|
|
247
|
+
replyToMessageId?: string | number | undefined;
|
|
248
|
+
raw?: unknown;
|
|
249
|
+
}
|
|
250
|
+
interface IncomingChannelAction {
|
|
251
|
+
id: string;
|
|
252
|
+
senderId: string;
|
|
253
|
+
chatId: string;
|
|
254
|
+
actionData: string;
|
|
255
|
+
messageId?: string | number | undefined;
|
|
256
|
+
raw?: unknown;
|
|
257
|
+
}
|
|
258
|
+
interface ChannelUpdateHandler {
|
|
259
|
+
onMessage(msg: IncomingChannelMessage): Promise<void>;
|
|
260
|
+
onAction(action: IncomingChannelAction): Promise<void>;
|
|
261
|
+
onError?(err: Error): void;
|
|
262
|
+
}
|
|
263
|
+
interface IChannelAdapter {
|
|
264
|
+
readonly id: string;
|
|
265
|
+
readonly name: string;
|
|
266
|
+
/**
|
|
267
|
+
* Start listening for incoming user messages and interactive actions.
|
|
268
|
+
*/
|
|
269
|
+
startListening(handler: ChannelUpdateHandler): Promise<void>;
|
|
270
|
+
/**
|
|
271
|
+
* Stop listening / close active polling or connection.
|
|
272
|
+
*/
|
|
273
|
+
stopListening(): Promise<void> | void;
|
|
274
|
+
/**
|
|
275
|
+
* Send a message to the target recipient/channel.
|
|
276
|
+
*/
|
|
277
|
+
sendMessage(recipientId: string, text: string, options?: ChannelSendOptions): Promise<ChannelMessageResult>;
|
|
278
|
+
/**
|
|
279
|
+
* Edit an existing message in-place.
|
|
280
|
+
*/
|
|
281
|
+
editMessage(recipientId: string, messageId: string | number, text: string, options?: ChannelSendOptions): Promise<void>;
|
|
282
|
+
/**
|
|
283
|
+
* Acknowledge or answer an interactive action / callback.
|
|
284
|
+
*/
|
|
285
|
+
answerAction(actionId: string, text?: string): Promise<void>;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
interface SendMessageOptions {
|
|
289
|
+
replyMarkup?: InlineKeyboardMarkup | undefined;
|
|
290
|
+
replyToMessageId?: number | undefined;
|
|
291
|
+
disableWebPagePreview?: boolean | undefined;
|
|
292
|
+
}
|
|
293
|
+
declare function escapeHtml(text: string): string;
|
|
294
|
+
declare class TelegramClient {
|
|
295
|
+
private readonly token;
|
|
296
|
+
private readonly agent;
|
|
297
|
+
private readonly baseUri;
|
|
298
|
+
constructor(token: string);
|
|
299
|
+
callApi<T = unknown>(method: string, payload?: Record<string, unknown>, retries?: number): Promise<T>;
|
|
300
|
+
private postJson;
|
|
301
|
+
sendMessage(chatId: string | number, text: string, options?: SendMessageOptions): Promise<TelegramMessage>;
|
|
302
|
+
editMessageText(chatId: string | number, messageId: number, text: string, options?: SendMessageOptions): Promise<TelegramMessage | boolean>;
|
|
303
|
+
answerCallbackQuery(callbackQueryId: string, text?: string, showAlert?: boolean): Promise<boolean>;
|
|
304
|
+
getUpdates(offset?: number, timeout?: number): Promise<TelegramUpdate[]>;
|
|
305
|
+
getMe(): Promise<{
|
|
306
|
+
id: number;
|
|
307
|
+
username?: string;
|
|
308
|
+
first_name: string;
|
|
309
|
+
}>;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Telegram Channel Adapter for AgentGram
|
|
314
|
+
* Production-ready default communication channel wrapping Telegram Bot API.
|
|
315
|
+
* Pure Node.js with zero runtime dependencies.
|
|
316
|
+
*/
|
|
317
|
+
|
|
318
|
+
declare function toTelegramMarkup(keyboard?: ChannelKeyboard): InlineKeyboardMarkup | undefined;
|
|
319
|
+
declare function fromTelegramMarkup(markup?: InlineKeyboardMarkup): ChannelKeyboard | undefined;
|
|
320
|
+
declare class TelegramChannelAdapter implements IChannelAdapter {
|
|
321
|
+
readonly id = "telegram";
|
|
322
|
+
readonly name = "Telegram Bot";
|
|
323
|
+
readonly client: TelegramClient;
|
|
324
|
+
private isListening;
|
|
325
|
+
private pollOffset;
|
|
326
|
+
constructor(clientOrToken: TelegramClient | string);
|
|
327
|
+
startListening(handler: ChannelUpdateHandler): Promise<void>;
|
|
328
|
+
stopListening(): void;
|
|
329
|
+
private processUpdate;
|
|
330
|
+
sendMessage(recipientId: string, text: string, options?: ChannelSendOptions): Promise<ChannelMessageResult>;
|
|
331
|
+
editMessage(recipientId: string, messageId: string | number, text: string, options?: ChannelSendOptions): Promise<void>;
|
|
332
|
+
answerAction(actionId: string, text?: string): Promise<void>;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
declare class ConsoleChannelAdapter implements IChannelAdapter {
|
|
336
|
+
private readonly input;
|
|
337
|
+
private readonly output;
|
|
338
|
+
readonly id = "console";
|
|
339
|
+
readonly name = "Terminal Console";
|
|
340
|
+
private rl?;
|
|
341
|
+
private isListening;
|
|
342
|
+
private messageCounter;
|
|
343
|
+
private activeKeyboard;
|
|
344
|
+
constructor(input?: NodeJS.ReadableStream, output?: NodeJS.WritableStream);
|
|
345
|
+
startListening(handler: ChannelUpdateHandler): Promise<void>;
|
|
346
|
+
stopListening(): void;
|
|
347
|
+
sendMessage(recipientId: string, text: string, options?: ChannelSendOptions): Promise<ChannelMessageResult>;
|
|
348
|
+
editMessage(_recipientId: string, messageId: string | number, text: string, options?: ChannelSendOptions): Promise<void>;
|
|
349
|
+
answerAction(_actionId: string, text?: string): Promise<void>;
|
|
350
|
+
private renderKeyboard;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Pluggable Channel Adapter Registry
|
|
355
|
+
* Pure Node.js with zero runtime dependencies.
|
|
356
|
+
*/
|
|
357
|
+
|
|
358
|
+
type ChannelFactory = (config: AgentgramConfig) => IChannelAdapter;
|
|
359
|
+
declare class ChannelRegistry {
|
|
360
|
+
private static factories;
|
|
361
|
+
static register(id: string, factory: ChannelFactory): void;
|
|
362
|
+
static get(id: string, config: AgentgramConfig): IChannelAdapter;
|
|
363
|
+
static has(id: string): boolean;
|
|
364
|
+
static list(): string[];
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* AgentGram Pluggable AI Coding Agent Engine Contract
|
|
369
|
+
* Hexagonal architecture port for AI coding engines & agent CLIs (OpenCode, Claude Code, Aider, Shell, etc.)
|
|
370
|
+
* Pure Node.js with zero runtime dependencies.
|
|
371
|
+
*/
|
|
372
|
+
|
|
373
|
+
interface AgentSession {
|
|
374
|
+
id: string;
|
|
375
|
+
workspaceDir: string;
|
|
376
|
+
title?: string | undefined;
|
|
377
|
+
}
|
|
378
|
+
interface AgentSessionOptions {
|
|
379
|
+
workspaceDir?: string | undefined;
|
|
380
|
+
title?: string | undefined;
|
|
381
|
+
agent?: string | undefined;
|
|
382
|
+
model?: string | undefined;
|
|
383
|
+
}
|
|
384
|
+
interface AgentEngineToolCall {
|
|
385
|
+
id: string;
|
|
386
|
+
tool: string;
|
|
387
|
+
status: 'running' | 'done' | 'error';
|
|
388
|
+
args?: Record<string, unknown>;
|
|
389
|
+
output?: string;
|
|
390
|
+
title?: string;
|
|
391
|
+
}
|
|
392
|
+
interface AgentEngineEvent {
|
|
393
|
+
type: string;
|
|
394
|
+
properties?: Record<string, unknown>;
|
|
395
|
+
[key: string]: unknown;
|
|
396
|
+
}
|
|
397
|
+
interface IAgentEngine extends EventEmitter {
|
|
398
|
+
readonly id: string;
|
|
399
|
+
readonly name: string;
|
|
400
|
+
workspaceDir: string;
|
|
401
|
+
/**
|
|
402
|
+
* Connect to or start the underlying agent engine server / runtime.
|
|
403
|
+
*/
|
|
404
|
+
connect(): Promise<void>;
|
|
405
|
+
/**
|
|
406
|
+
* Disconnect or stop the agent engine server / processes.
|
|
407
|
+
*/
|
|
408
|
+
disconnect(): Promise<void> | void;
|
|
409
|
+
/**
|
|
410
|
+
* Create or initialize a conversation session.
|
|
411
|
+
*/
|
|
412
|
+
createSession(options?: AgentSessionOptions): Promise<AgentSession>;
|
|
413
|
+
/**
|
|
414
|
+
* Submit a coding task / prompt to the engine.
|
|
415
|
+
*/
|
|
416
|
+
submitPrompt(sessionId: string, prompt: string, agent?: string, model?: string): Promise<void>;
|
|
417
|
+
/**
|
|
418
|
+
* Abort or cancel an ongoing run.
|
|
419
|
+
*/
|
|
420
|
+
abortSession(sessionId: string): Promise<void>;
|
|
421
|
+
/**
|
|
422
|
+
* Respond to an interactive tool execution permission request.
|
|
423
|
+
*/
|
|
424
|
+
replyPermission(permissionId: string, decision: 'allow' | 'reject'): Promise<void>;
|
|
425
|
+
/**
|
|
426
|
+
* Get working directory git diff / changes.
|
|
427
|
+
*/
|
|
428
|
+
getDiff(): Promise<string>;
|
|
429
|
+
/**
|
|
430
|
+
* Switch the active working directory / workspace.
|
|
431
|
+
*/
|
|
432
|
+
setWorkspace(directory: string): Promise<void> | void;
|
|
433
|
+
/**
|
|
434
|
+
* List available models from the engine.
|
|
435
|
+
*/
|
|
436
|
+
listModels?(): Promise<Array<{
|
|
437
|
+
id: string;
|
|
438
|
+
name?: string;
|
|
439
|
+
}>>;
|
|
440
|
+
/**
|
|
441
|
+
* List available agents from the engine.
|
|
442
|
+
*/
|
|
443
|
+
listAgents?(): Promise<Array<{
|
|
444
|
+
name: string;
|
|
445
|
+
description?: string;
|
|
446
|
+
}>>;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
declare function getFreePort(): Promise<number>;
|
|
450
|
+
interface OpenCodeEvent {
|
|
451
|
+
type: string;
|
|
452
|
+
properties?: Record<string, unknown>;
|
|
453
|
+
[key: string]: unknown;
|
|
454
|
+
}
|
|
455
|
+
declare class OpenCodeClient extends EventEmitter {
|
|
456
|
+
readonly baseUrl: string;
|
|
457
|
+
private readonly password?;
|
|
458
|
+
readonly directory: string;
|
|
459
|
+
private serverProcess?;
|
|
460
|
+
private sseReq?;
|
|
461
|
+
private isConnected;
|
|
462
|
+
constructor(baseUrl: string, password?: string, directory?: string);
|
|
463
|
+
getHeaders(): Record<string, string>;
|
|
464
|
+
request<T = unknown>(method: string, endpoint: string, body?: Record<string, unknown>): Promise<T>;
|
|
465
|
+
/**
|
|
466
|
+
* Start consuming Server-Sent Events (SSE) from the OpenCode server.
|
|
467
|
+
*/
|
|
468
|
+
connectEventStream(): void;
|
|
469
|
+
disconnectEventStream(): void;
|
|
470
|
+
submitPrompt(sessionId: string, prompt: string, agent?: string, model?: string): Promise<unknown>;
|
|
471
|
+
replyPermission(permissionId: string, decision: 'allow' | 'reject'): Promise<unknown>;
|
|
472
|
+
replyQuestion(questionId: string, answers: string[]): Promise<unknown>;
|
|
473
|
+
abortSession(sessionId: string): Promise<unknown>;
|
|
474
|
+
getDiff(): Promise<string>;
|
|
475
|
+
listAgents(): Promise<Array<{
|
|
476
|
+
name: string;
|
|
477
|
+
description?: string;
|
|
478
|
+
}>>;
|
|
479
|
+
listModels(): Promise<Array<{
|
|
480
|
+
id: string;
|
|
481
|
+
name?: string;
|
|
482
|
+
}>>;
|
|
483
|
+
listSessions(): Promise<Array<{
|
|
484
|
+
id: string;
|
|
485
|
+
title?: string;
|
|
486
|
+
}>>;
|
|
487
|
+
createSession(title?: string): Promise<{
|
|
488
|
+
id: string;
|
|
489
|
+
title?: string;
|
|
490
|
+
}>;
|
|
491
|
+
/**
|
|
492
|
+
* Spawns an OpenCode server process locally on loopback.
|
|
493
|
+
*/
|
|
494
|
+
static spawnServer(targetDir: string, port?: number): Promise<{
|
|
495
|
+
client: OpenCodeClient;
|
|
496
|
+
proc: child_process.ChildProcess;
|
|
497
|
+
port: number;
|
|
498
|
+
}>;
|
|
499
|
+
killServer(): void;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* OpenCode Engine Adapter for AgentGram
|
|
504
|
+
* Default production coding agent engine wrapping local loopback OpenCode server.
|
|
505
|
+
* Pure Node.js with zero runtime dependencies.
|
|
506
|
+
*/
|
|
507
|
+
|
|
508
|
+
declare class OpenCodeAdapter extends EventEmitter implements IAgentEngine {
|
|
509
|
+
readonly id = "opencode";
|
|
510
|
+
readonly name = "OpenCode Agent";
|
|
511
|
+
workspaceDir: string;
|
|
512
|
+
client: OpenCodeClient;
|
|
513
|
+
private readonly boundEventHandler;
|
|
514
|
+
constructor(clientOrUrl: OpenCodeClient | string, workspaceDir?: string);
|
|
515
|
+
connect(): Promise<void>;
|
|
516
|
+
disconnect(): void;
|
|
517
|
+
createSession(options?: AgentSessionOptions): Promise<AgentSession>;
|
|
518
|
+
submitPrompt(sessionId: string, prompt: string, agent?: string, model?: string): Promise<void>;
|
|
519
|
+
abortSession(sessionId: string): Promise<void>;
|
|
520
|
+
replyPermission(permissionId: string, decision: 'allow' | 'reject'): Promise<void>;
|
|
521
|
+
getDiff(): Promise<string>;
|
|
522
|
+
setWorkspace(directory: string): void;
|
|
523
|
+
listModels(): Promise<Array<{
|
|
524
|
+
id: string;
|
|
525
|
+
name?: string;
|
|
526
|
+
}>>;
|
|
527
|
+
listAgents(): Promise<Array<{
|
|
528
|
+
name: string;
|
|
529
|
+
description?: string;
|
|
530
|
+
}>>;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
interface ShellEngineOptions {
|
|
534
|
+
workspaceDir?: string;
|
|
535
|
+
cliCommand?: string;
|
|
536
|
+
args?: string[];
|
|
537
|
+
env?: Record<string, string>;
|
|
538
|
+
}
|
|
539
|
+
declare class ShellEngineAdapter extends EventEmitter implements IAgentEngine {
|
|
540
|
+
readonly id = "shell";
|
|
541
|
+
readonly name: string;
|
|
542
|
+
workspaceDir: string;
|
|
543
|
+
private readonly cliCommand;
|
|
544
|
+
private readonly defaultArgs;
|
|
545
|
+
private activeProcess?;
|
|
546
|
+
activeSessionId?: string | undefined;
|
|
547
|
+
constructor(options?: ShellEngineOptions);
|
|
548
|
+
connect(): Promise<void>;
|
|
549
|
+
disconnect(): void;
|
|
550
|
+
createSession(options?: AgentSessionOptions): Promise<AgentSession>;
|
|
551
|
+
submitPrompt(sessionId: string, prompt: string, _agent?: string, _model?: string): Promise<void>;
|
|
552
|
+
abortSession(_sessionId: string): Promise<void>;
|
|
553
|
+
replyPermission(_permissionId: string, _decision: 'allow' | 'reject'): Promise<void>;
|
|
554
|
+
getDiff(): Promise<string>;
|
|
555
|
+
setWorkspace(directory: string): void;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* Pluggable AI Coding Agent Engine Registry
|
|
560
|
+
* Pure Node.js with zero runtime dependencies.
|
|
561
|
+
*/
|
|
562
|
+
|
|
563
|
+
type EngineFactory = (config: AgentgramConfig) => IAgentEngine;
|
|
564
|
+
declare class EngineRegistry {
|
|
565
|
+
private static factories;
|
|
566
|
+
static register(id: string, factory: EngineFactory): void;
|
|
567
|
+
static get(id: string, config: AgentgramConfig): IAgentEngine;
|
|
568
|
+
static has(id: string): boolean;
|
|
569
|
+
static list(): string[];
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
declare const SYSTEM_HEADER: (targetDir: string) => string;
|
|
573
|
+
declare function parseCallback(data: string): [string, string | null];
|
|
574
|
+
declare function decidePermission(props: {
|
|
575
|
+
permission?: string;
|
|
576
|
+
metadata?: Record<string, unknown>;
|
|
577
|
+
patterns?: string[];
|
|
578
|
+
}, mode?: ExecutionMode, policy?: SecurityPolicy): {
|
|
579
|
+
decision: 'ask' | 'allow' | 'reject';
|
|
580
|
+
reason?: string;
|
|
581
|
+
};
|
|
582
|
+
declare function permissionKeyboard(permId: string, lang?: 'en' | 'ar'): ChannelKeyboard & InlineKeyboardMarkup;
|
|
583
|
+
interface ControlRoomOptions {
|
|
584
|
+
channel: IChannelAdapter;
|
|
585
|
+
engine: IAgentEngine;
|
|
586
|
+
configManager: ConfigManager;
|
|
587
|
+
}
|
|
588
|
+
declare class ControlRoom {
|
|
589
|
+
readonly channel: IChannelAdapter;
|
|
590
|
+
engine: IAgentEngine;
|
|
591
|
+
readonly cfgManager: ConfigManager;
|
|
592
|
+
policy: SecurityPolicy;
|
|
593
|
+
readonly allowedChatId: string;
|
|
594
|
+
targetDir: string;
|
|
595
|
+
currentMode: ExecutionMode;
|
|
596
|
+
currentAgent: string;
|
|
597
|
+
currentModel: string;
|
|
598
|
+
language: 'en' | 'ar';
|
|
599
|
+
private activeRun;
|
|
600
|
+
private alwaysAllowedPerms;
|
|
601
|
+
private missionCardMsgId;
|
|
602
|
+
private updateTimer;
|
|
603
|
+
private activeSkill;
|
|
604
|
+
isListening: boolean;
|
|
605
|
+
constructor(options: ControlRoomOptions);
|
|
606
|
+
constructor(tg: TelegramClient, oc: OpenCodeClient, cfgManager: ConfigManager);
|
|
607
|
+
get tg(): TelegramClient;
|
|
608
|
+
get oc(): OpenCodeClient;
|
|
609
|
+
set oc(client: OpenCodeClient);
|
|
610
|
+
private setupEngineEvents;
|
|
611
|
+
start(): Promise<void>;
|
|
612
|
+
stop(): void;
|
|
613
|
+
private handleUserMessage;
|
|
614
|
+
guardedSubmit(promptText: string, replyToMsgId?: string | number): Promise<void>;
|
|
615
|
+
private handleCallback;
|
|
616
|
+
private handleEngineEvent;
|
|
617
|
+
private startMissionCardTicker;
|
|
618
|
+
private renderMissionCardText;
|
|
619
|
+
private updateMissionCard;
|
|
620
|
+
/**
|
|
621
|
+
* The complete, feature-rich 5-row interactive home keyboard with all 14 buttons.
|
|
622
|
+
*/
|
|
623
|
+
getMainKeyboard(): ChannelKeyboard & InlineKeyboardMarkup;
|
|
624
|
+
private wrapKeyboard;
|
|
625
|
+
private sendAgentsMenu;
|
|
626
|
+
sendModelsMenu(page?: number): Promise<void>;
|
|
627
|
+
private sendModeMenu;
|
|
628
|
+
private sendSessionsMenu;
|
|
629
|
+
private sendStatusReport;
|
|
630
|
+
private getAllAvailableSkills;
|
|
631
|
+
sendSkillsMenu(page?: number): Promise<void>;
|
|
632
|
+
private sendUsageReport;
|
|
633
|
+
private sendLanguageMenu;
|
|
634
|
+
private sendHandoffReport;
|
|
635
|
+
private sendWorkspaceMenu;
|
|
636
|
+
switchWorkspace(newPath: string): Promise<void>;
|
|
637
|
+
sendDiff(): Promise<void>;
|
|
638
|
+
abortCurrentRun(): Promise<void>;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
declare const MACOS_PLIST_NAME = "com.agentgram.plist";
|
|
642
|
+
declare const LINUX_SERVICE_NAME = "agentgram.service";
|
|
643
|
+
declare function getEntryPoint(): string;
|
|
644
|
+
declare class ServiceManager {
|
|
645
|
+
static install(targetDir?: string): {
|
|
646
|
+
success: boolean;
|
|
647
|
+
message: string;
|
|
648
|
+
};
|
|
649
|
+
static uninstall(): {
|
|
650
|
+
success: boolean;
|
|
651
|
+
message: string;
|
|
652
|
+
};
|
|
653
|
+
static status(): ServiceStatus;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
/**
|
|
657
|
+
* Type-Safe Internationalization (i18n) Module
|
|
658
|
+
* Supports English (default) and Arabic out of the box.
|
|
659
|
+
*/
|
|
660
|
+
declare const TRANSLATIONS: {
|
|
661
|
+
readonly en: {
|
|
662
|
+
readonly btn_stop: "⏹ Stop";
|
|
663
|
+
readonly btn_diff: "📤 Diff";
|
|
664
|
+
readonly btn_status: "📊 Status";
|
|
665
|
+
readonly btn_agents: "🧠 Agents";
|
|
666
|
+
readonly btn_models: "🤖 Models";
|
|
667
|
+
readonly btn_mode: "🔒 Mode";
|
|
668
|
+
readonly btn_sessions: "📂 Sessions";
|
|
669
|
+
readonly btn_new: "✨ New";
|
|
670
|
+
readonly btn_usage: "📈 Usage";
|
|
671
|
+
readonly btn_skills: "🧰 Skills";
|
|
672
|
+
readonly btn_workspaces: "📁 Projects";
|
|
673
|
+
readonly btn_handoff: "🔁 Handoff";
|
|
674
|
+
readonly btn_help: "❓ Help";
|
|
675
|
+
readonly btn_language: "🌐 Language";
|
|
676
|
+
readonly btn_back: "⬅️ Back";
|
|
677
|
+
readonly btn_all_models: "➡️ All Models";
|
|
678
|
+
readonly btn_favorites: "⭐ Favorites";
|
|
679
|
+
readonly btn_next: "➡️ Next";
|
|
680
|
+
readonly perm_allow_once: "✅ Allow Once";
|
|
681
|
+
readonly perm_always_allow: "♾️ Always Allow";
|
|
682
|
+
readonly perm_reject: "⛔ Reject";
|
|
683
|
+
readonly perm_stop_session: "🛑 Stop Session";
|
|
684
|
+
readonly btn_done_submit: "✅ Done (Submit)";
|
|
685
|
+
readonly btn_cancel: "❌ Cancel";
|
|
686
|
+
readonly welcome: "⚡ <b>AgentGram Mission Control</b>\nWorkspace: <code>{target}</code>\nConnected to OpenCode. Send your prompt or tap a command below:";
|
|
687
|
+
readonly room_busy: "⚠️ <b>Agent is busy</b> — wait for it to finish or tap ⏹ Stop.";
|
|
688
|
+
readonly room_stopped: "🛑 Agent run stopped.";
|
|
689
|
+
readonly permission_prompt: "🔒 <b>Permission Required</b>\nTool: <code>{tool}</code>\nPattern: <code>{pattern}</code>\n{details}";
|
|
690
|
+
readonly permission_allowed_once: "✅ Allowed once: <code>{tool}</code>";
|
|
691
|
+
readonly permission_always_allowed: "♾️ Allowed always for this session: <code>{tool}</code>";
|
|
692
|
+
readonly permission_rejected: "⛔ Rejected: <code>{tool}</code>";
|
|
693
|
+
readonly prompt_injection_blocked: "🛡️ <b>Prompt Blocked by Security Shield</b>\nReason: <code>{reason}</code>\nConfidence: <b>{confidence}%</b>";
|
|
694
|
+
readonly policy_denied: "⛔ <b>Blocked by Security Policy</b>\nDeny rule matched: <code>{hits}</code>";
|
|
695
|
+
readonly select_agent: "🧠 <b>Select AI Agent</b> (Current: <b>{agent}</b>)";
|
|
696
|
+
readonly select_model: "🤖 <b>Select LLM Model</b> (Current: <b>{model}</b>)";
|
|
697
|
+
readonly select_mode: "🔒 <b>Execution Mode</b> (Current: <b>{mode}</b>)\nread: Refuses modifications · build: Interactive buttons · auto: Auto-approves safe commands.";
|
|
698
|
+
readonly select_workspace: "📁 <b>Projects & Workspaces</b> (Current: <b>{ws}</b>)\nSelect a project to switch or type <code>/cd <path_or_name></code>:";
|
|
699
|
+
readonly ws_changed: "📁 Switched workspace to <b>{name}</b>!\nPath: <code>{ws}</code>\n🌿 Branch: <code>{branch}</code> · Modified: <code>{dirty}</code>";
|
|
700
|
+
readonly ws_not_found: "❌ Workspace path not found: <code>{path}</code>";
|
|
701
|
+
readonly ws_busy: "⚠️ A task is currently running in <code>{ws}</code>. Stop it with /stop before switching.";
|
|
702
|
+
readonly select_language: "🌐 <b>Select Language</b> (Current: <b>English</b>)";
|
|
703
|
+
readonly lang_changed: "🌐 Language switched to <b>English</b>.";
|
|
704
|
+
readonly help_title: "⚡ <b>AgentGram Commands & Shortcuts</b>";
|
|
705
|
+
};
|
|
706
|
+
readonly ar: {
|
|
707
|
+
readonly btn_stop: "⏹ إيقاف";
|
|
708
|
+
readonly btn_diff: "📤 الفروقات";
|
|
709
|
+
readonly btn_status: "📊 الحالة";
|
|
710
|
+
readonly btn_agents: "🧠 الوكلاء";
|
|
711
|
+
readonly btn_models: "🤖 الموديلات";
|
|
712
|
+
readonly btn_mode: "🔒 الوضع";
|
|
713
|
+
readonly btn_sessions: "📂 الجلسات";
|
|
714
|
+
readonly btn_new: "✨ جديد";
|
|
715
|
+
readonly btn_usage: "📈 الاستهلاك";
|
|
716
|
+
readonly btn_skills: "🧰 المهارات";
|
|
717
|
+
readonly btn_workspaces: "📁 المشاريع";
|
|
718
|
+
readonly btn_handoff: "🔁 تسليم";
|
|
719
|
+
readonly btn_help: "❓ مساعدة";
|
|
720
|
+
readonly btn_language: "🌐 اللغة";
|
|
721
|
+
readonly btn_back: "⬅️ رجوع";
|
|
722
|
+
readonly btn_all_models: "➡️ المزيد";
|
|
723
|
+
readonly btn_favorites: "⭐ المفضلة";
|
|
724
|
+
readonly btn_next: "➡️ التالي";
|
|
725
|
+
readonly perm_allow_once: "✅ مرة واحدة";
|
|
726
|
+
readonly perm_always_allow: "♾️ سماح دائماً";
|
|
727
|
+
readonly perm_reject: "⛔ رفض";
|
|
728
|
+
readonly perm_stop_session: "🛑 إنهاء الجلسة";
|
|
729
|
+
readonly btn_done_submit: "✅ تم (إرسال الإجابة)";
|
|
730
|
+
readonly btn_cancel: "❌ إلغاء";
|
|
731
|
+
readonly welcome: "⚡ <b>كابينة تحكم AgentGram</b>\nمساحة العمل: <code>{target}</code>\nمتصل بـ OpenCode. أرسل مهمتك أو اختر من القائمة:";
|
|
732
|
+
readonly room_busy: "⚠️ <b>الوكيل يعمل حالياً</b> — انتظر انتهاء المهمة أو اضغط ⏹ إيقاف.";
|
|
733
|
+
readonly room_stopped: "🛑 تم إيقاف عمل الوكيل.";
|
|
734
|
+
readonly permission_prompt: "🔒 <b>طلب إذن تشغيل</b>\nالأداة: <code>{tool}</code>\nالنمط: <code>{pattern}</code>\n{details}";
|
|
735
|
+
readonly permission_allowed_once: "✅ تم السماح لمرة واحدة: <code>{tool}</code>";
|
|
736
|
+
readonly permission_always_allowed: "♾️ تم السماح دائماً لهذه الجلسة: <code>{tool}</code>";
|
|
737
|
+
readonly permission_rejected: "⛔ تم الرفض: <code>{tool}</code>";
|
|
738
|
+
readonly prompt_injection_blocked: "🛡️ <b>تم حظر الرسالة بدرع الحماية</b>\nالسبب: <code>{reason}</code>\nمستوى الثقة: <b>{confidence}%</b>";
|
|
739
|
+
readonly policy_denied: "⛔ <b>مرفوض بسياسة الأمان</b>\nتطابق مع قاعدة الحظر: <code>{hits}</code>";
|
|
740
|
+
readonly select_agent: "🧠 <b>اختر الوكيل الذكي</b> (الحالي: <b>{agent}</b>)";
|
|
741
|
+
readonly select_model: "🤖 <b>اختر موديل الذكاء الاصطناعي</b> (الحالي: <b>{model}</b>)";
|
|
742
|
+
readonly select_mode: "🔒 <b>وضع التشغيل</b> (الحالي: <b>{mode}</b>)\nread: قراءة فقط · build: أزرار موافقة تفاعلية · auto: تشغيل تلقائي آمن.";
|
|
743
|
+
readonly select_workspace: "📁 <b>المشاريع ومساحات العمل</b> (الحالي: <b>{ws}</b>)\nاضغط للتبديل لأي مشروع فوراً أو اكتب <code>/cd <مسار_أو_اسم></code>:";
|
|
744
|
+
readonly ws_changed: "📁 تم تغيير مساحة العمل إلى <b>{name}</b> بنجاح!\nالمسار: <code>{ws}</code>\n🌿 الفرع: <code>{branch}</code> · الملفات المعدلة: <code>{dirty}</code>";
|
|
745
|
+
readonly ws_not_found: "❌ مسار المشروع غير موجود: <code>{path}</code>";
|
|
746
|
+
readonly ws_busy: "⚠️ يوجد مهمة تعمل حالياً في <code>{ws}</code>. يرجى إيقافها أولاً بـ /stop قبل التبديل.";
|
|
747
|
+
readonly select_language: "🌐 <b>اختر اللغة / Select Language</b> (الحالية: <b>العربية</b>)";
|
|
748
|
+
readonly lang_changed: "🌐 تم تحويل لغة الواجهة إلى <b>العربية</b>.";
|
|
749
|
+
readonly help_title: "⚡ <b>أوامر وتحكم AgentGram</b>";
|
|
750
|
+
};
|
|
751
|
+
};
|
|
752
|
+
type Language = 'en' | 'ar';
|
|
753
|
+
type TranslationKey = keyof typeof TRANSLATIONS.en;
|
|
754
|
+
declare function t(key: TranslationKey, lang?: Language, params?: Record<string, string | number>): string;
|
|
755
|
+
|
|
756
|
+
declare const VERSION = "2.0.4";
|
|
757
|
+
/**
|
|
758
|
+
* Main entry point for CLI execution.
|
|
759
|
+
*/
|
|
760
|
+
declare function runCli(argv?: string[]): Promise<void>;
|
|
761
|
+
|
|
762
|
+
export { AGENTGRAM_CONFIG_DIR, type AgentEngineEvent, type AgentEngineToolCall, type AgentSession, type AgentSessionOptions, type AgentgramConfig, type CallbackQuery, type ChannelButton, type ChannelFactory, type ChannelKeyboard, type ChannelMessageResult, ChannelRegistry, type ChannelSendOptions, type ChannelUpdateHandler, ConfigManager, ConsoleChannelAdapter, ControlRoom, DEFAULT_DENY_PATTERNS, type EngineFactory, EngineRegistry, type ExecutionMode, type IAgentEngine, type IChannelAdapter, type IncomingChannelAction, type IncomingChannelMessage, type InlineKeyboardButton, type InlineKeyboardMarkup, LEGACY_CONFIG_DIR, LINUX_SERVICE_NAME, type Language, MACOS_PLIST_NAME, OpenCodeAdapter, OpenCodeClient, type OpenCodeEvent, type OpenCodePermissionRequest, type OpenCodeQuestionOption, type OpenCodeQuestionRequest, type OpenCodeRun, type OpenCodeToolCall, type PathCheckResult, type PermissionDecision, type PromptCategory, type PromptDetectionResult, PromptInjectionGuard, type QuarantineResult, SYSTEM_HEADER, SecurityPolicy, ServiceManager, type ServiceStatus, ShellEngineAdapter, type ShellEngineOptions, TRANSLATIONS, TelegramChannelAdapter, type TelegramChat, TelegramClient, type TelegramMessage, type TelegramPhotoSize, type TelegramUpdate, type TelegramUser, type TranslationKey, VERSION, computeWorkspaceId, decidePermission, ensureConfigDirs, escapeHtml, fromTelegramMarkup, getEntryPoint, getFreePort, getGlobalConfigDir, parseCallback, permissionKeyboard, runCli, t, toTelegramMarkup, TRANSLATIONS as translations };
|