tg-claude 0.1.0
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/README.md +175 -0
- package/bin/cli.js +2 -0
- package/dist/claude/ClaudeProcess.d.ts +77 -0
- package/dist/claude/ClaudeProcess.d.ts.map +1 -0
- package/dist/claude/ClaudeProcess.js +270 -0
- package/dist/claude/ClaudeProcess.js.map +1 -0
- package/dist/claude/EventAdapter.d.ts +44 -0
- package/dist/claude/EventAdapter.d.ts.map +1 -0
- package/dist/claude/EventAdapter.js +129 -0
- package/dist/claude/EventAdapter.js.map +1 -0
- package/dist/claude/index.d.ts +10 -0
- package/dist/claude/index.d.ts.map +1 -0
- package/dist/claude/index.js +9 -0
- package/dist/claude/index.js.map +1 -0
- package/dist/claude/types.d.ts +244 -0
- package/dist/claude/types.d.ts.map +1 -0
- package/dist/claude/types.js +8 -0
- package/dist/claude/types.js.map +1 -0
- package/dist/env.d.ts +21 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +49 -0
- package/dist/env.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +360 -0
- package/dist/index.js.map +1 -0
- package/dist/parser/AnsiStripper.d.ts +54 -0
- package/dist/parser/AnsiStripper.d.ts.map +1 -0
- package/dist/parser/AnsiStripper.js +115 -0
- package/dist/parser/AnsiStripper.js.map +1 -0
- package/dist/parser/OptionExtractor.d.ts +31 -0
- package/dist/parser/OptionExtractor.d.ts.map +1 -0
- package/dist/parser/OptionExtractor.js +91 -0
- package/dist/parser/OptionExtractor.js.map +1 -0
- package/dist/parser/OutputParser.d.ts +121 -0
- package/dist/parser/OutputParser.d.ts.map +1 -0
- package/dist/parser/OutputParser.js +306 -0
- package/dist/parser/OutputParser.js.map +1 -0
- package/dist/parser/PromptDetector.d.ts +20 -0
- package/dist/parser/PromptDetector.d.ts.map +1 -0
- package/dist/parser/PromptDetector.js +68 -0
- package/dist/parser/PromptDetector.js.map +1 -0
- package/dist/parser/index.d.ts +7 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +5 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/types.d.ts +73 -0
- package/dist/parser/types.d.ts.map +1 -0
- package/dist/parser/types.js +2 -0
- package/dist/parser/types.js.map +1 -0
- package/dist/pty/OutputBuffer.d.ts +39 -0
- package/dist/pty/OutputBuffer.d.ts.map +1 -0
- package/dist/pty/OutputBuffer.js +55 -0
- package/dist/pty/OutputBuffer.js.map +1 -0
- package/dist/pty/PtyProcess.d.ts +47 -0
- package/dist/pty/PtyProcess.d.ts.map +1 -0
- package/dist/pty/PtyProcess.js +94 -0
- package/dist/pty/PtyProcess.js.map +1 -0
- package/dist/pty/PtyService.d.ts +55 -0
- package/dist/pty/PtyService.d.ts.map +1 -0
- package/dist/pty/PtyService.js +115 -0
- package/dist/pty/PtyService.js.map +1 -0
- package/dist/pty/index.d.ts +5 -0
- package/dist/pty/index.d.ts.map +1 -0
- package/dist/pty/index.js +4 -0
- package/dist/pty/index.js.map +1 -0
- package/dist/pty/types.d.ts +36 -0
- package/dist/pty/types.d.ts.map +1 -0
- package/dist/pty/types.js +2 -0
- package/dist/pty/types.js.map +1 -0
- package/dist/router/BoundedQueue.d.ts +57 -0
- package/dist/router/BoundedQueue.d.ts.map +1 -0
- package/dist/router/BoundedQueue.js +86 -0
- package/dist/router/BoundedQueue.js.map +1 -0
- package/dist/router/EventRouter.d.ts +103 -0
- package/dist/router/EventRouter.d.ts.map +1 -0
- package/dist/router/EventRouter.js +169 -0
- package/dist/router/EventRouter.js.map +1 -0
- package/dist/router/index.d.ts +13 -0
- package/dist/router/index.d.ts.map +1 -0
- package/dist/router/index.js +12 -0
- package/dist/router/index.js.map +1 -0
- package/dist/router/types.d.ts +104 -0
- package/dist/router/types.d.ts.map +1 -0
- package/dist/router/types.js +6 -0
- package/dist/router/types.js.map +1 -0
- package/dist/telegram/TelegramBot.d.ts +151 -0
- package/dist/telegram/TelegramBot.d.ts.map +1 -0
- package/dist/telegram/TelegramBot.js +514 -0
- package/dist/telegram/TelegramBot.js.map +1 -0
- package/dist/telegram/index.d.ts +7 -0
- package/dist/telegram/index.d.ts.map +1 -0
- package/dist/telegram/index.js +6 -0
- package/dist/telegram/index.js.map +1 -0
- package/dist/telegram/types.d.ts +30 -0
- package/dist/telegram/types.d.ts.map +1 -0
- package/dist/telegram/types.js +5 -0
- package/dist/telegram/types.js.map +1 -0
- package/dist/terminal/TerminalInterface.d.ts +61 -0
- package/dist/terminal/TerminalInterface.d.ts.map +1 -0
- package/dist/terminal/TerminalInterface.js +218 -0
- package/dist/terminal/TerminalInterface.js.map +1 -0
- package/dist/terminal/index.d.ts +3 -0
- package/dist/terminal/index.d.ts.map +1 -0
- package/dist/terminal/index.js +2 -0
- package/dist/terminal/index.js.map +1 -0
- package/dist/terminal/types.d.ts +17 -0
- package/dist/terminal/types.d.ts.map +1 -0
- package/dist/terminal/types.js +2 -0
- package/dist/terminal/types.js.map +1 -0
- package/package.json +43 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TUI box drawing characters to strip from summaries
|
|
3
|
+
*/
|
|
4
|
+
const TUI_CHARS_REGEX = /[─│┌┐└┘├┤┬┴┼═║╔╗╚╝╠╣╦╩╬]/g;
|
|
5
|
+
/**
|
|
6
|
+
* EventAdapter bridges ClaudeProcess events to EventRouter format.
|
|
7
|
+
*
|
|
8
|
+
* Subscribes to ClaudeProcess events and publishes corresponding
|
|
9
|
+
* OutboundEvents to the router for Telegram integration.
|
|
10
|
+
*/
|
|
11
|
+
export class EventAdapter {
|
|
12
|
+
claudeProcess;
|
|
13
|
+
router;
|
|
14
|
+
sessionId;
|
|
15
|
+
_lastSessionId = null;
|
|
16
|
+
_textBuffer = '';
|
|
17
|
+
_hasQuestion = false;
|
|
18
|
+
constructor(claudeProcess, router, sessionId) {
|
|
19
|
+
this.claudeProcess = claudeProcess;
|
|
20
|
+
this.router = router;
|
|
21
|
+
this.sessionId = sessionId;
|
|
22
|
+
this.subscribeToEvents();
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Subscribe to ClaudeProcess events and wire to router
|
|
26
|
+
*/
|
|
27
|
+
subscribeToEvents() {
|
|
28
|
+
// Accumulate text output for context
|
|
29
|
+
this.claudeProcess.on('text', (event) => {
|
|
30
|
+
this._textBuffer += event.text;
|
|
31
|
+
});
|
|
32
|
+
// Log tool usage for debugging/status
|
|
33
|
+
this.claudeProcess.on('tool_use', (event) => {
|
|
34
|
+
console.log(`[ADAPTER] Tool use: ${event.name}`);
|
|
35
|
+
if (event.name === 'AskUserQuestion') {
|
|
36
|
+
console.log(`[ADAPTER] AskUserQuestion input:`, JSON.stringify(event.input, null, 2));
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
// Log tool results for debugging/status
|
|
40
|
+
this.claudeProcess.on('tool_result', (event) => {
|
|
41
|
+
const preview = event.result.slice(0, 100);
|
|
42
|
+
console.log(`[ADAPTER] Tool result: ${preview}${event.result.length > 100 ? '...' : ''}`);
|
|
43
|
+
});
|
|
44
|
+
// Handle AskUserQuestion - publish prompt event to router
|
|
45
|
+
this.claudeProcess.on('question', (event) => {
|
|
46
|
+
this._hasQuestion = true;
|
|
47
|
+
console.log(`[ADAPTER] Question detected: ${event.question}`);
|
|
48
|
+
// Convert to PromptOption format (index is 1-based)
|
|
49
|
+
const options = event.options.map((opt, idx) => ({
|
|
50
|
+
index: idx + 1,
|
|
51
|
+
text: `${opt.label} - ${opt.description}`,
|
|
52
|
+
selected: idx === 0, // First option selected by default
|
|
53
|
+
}));
|
|
54
|
+
const promptEvent = {
|
|
55
|
+
type: 'blocking-prompt',
|
|
56
|
+
question: event.question,
|
|
57
|
+
options,
|
|
58
|
+
rawContext: this._textBuffer.slice(-500), // Last 500 chars of context
|
|
59
|
+
timestamp: Date.now(),
|
|
60
|
+
multiSelect: event.multiSelect, // Pass through multiSelect flag
|
|
61
|
+
};
|
|
62
|
+
this.router.publishOutbound({
|
|
63
|
+
sessionId: this.sessionId,
|
|
64
|
+
type: 'prompt',
|
|
65
|
+
payload: promptEvent,
|
|
66
|
+
timestamp: Date.now(),
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
// Handle completion - publish to router (skip if question was asked)
|
|
70
|
+
this.claudeProcess.on('complete', (event) => {
|
|
71
|
+
this._lastSessionId = event.sessionId;
|
|
72
|
+
// Skip completion notification if a question was asked
|
|
73
|
+
// (user needs to respond to question first)
|
|
74
|
+
if (this._hasQuestion) {
|
|
75
|
+
console.log(`[ADAPTER] Complete (skipped notification - awaiting question response): sessionId=${event.sessionId}, cost=$${event.cost.toFixed(4)}`);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const summary = this.cleanResult(event.result);
|
|
79
|
+
const payload = {
|
|
80
|
+
summary,
|
|
81
|
+
duration: event.duration,
|
|
82
|
+
};
|
|
83
|
+
console.log(`[ADAPTER] Complete: sessionId=${event.sessionId}, cost=$${event.cost.toFixed(4)}`);
|
|
84
|
+
this.router.publishOutbound({
|
|
85
|
+
sessionId: this.sessionId,
|
|
86
|
+
type: 'completion',
|
|
87
|
+
payload,
|
|
88
|
+
timestamp: Date.now(),
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Clean result text for Telegram
|
|
94
|
+
* - Strips TUI box drawing characters
|
|
95
|
+
* - Returns "Task completed" if empty after cleaning
|
|
96
|
+
*/
|
|
97
|
+
cleanResult(result) {
|
|
98
|
+
// Strip TUI box drawing characters
|
|
99
|
+
const cleaned = result.replace(TUI_CHARS_REGEX, '').trim();
|
|
100
|
+
// Return default if empty
|
|
101
|
+
return cleaned || 'Task completed';
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Get the session ID from Claude's last run (for --resume)
|
|
105
|
+
*/
|
|
106
|
+
get lastSessionId() {
|
|
107
|
+
return this._lastSessionId;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Get accumulated text output
|
|
111
|
+
*/
|
|
112
|
+
get textBuffer() {
|
|
113
|
+
return this._textBuffer;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Check if a question was asked in this turn
|
|
117
|
+
*/
|
|
118
|
+
get hasQuestion() {
|
|
119
|
+
return this._hasQuestion;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Clear text buffer and question state for new conversation turn
|
|
123
|
+
*/
|
|
124
|
+
reset() {
|
|
125
|
+
this._textBuffer = '';
|
|
126
|
+
this._hasQuestion = false;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=EventAdapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventAdapter.js","sourceRoot":"","sources":["../../src/claude/EventAdapter.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,MAAM,eAAe,GAAG,2BAA2B,CAAC;AAEpD;;;;;GAKG;AACH,MAAM,OAAO,YAAY;IAMJ;IACA;IACA;IAPX,cAAc,GAAkB,IAAI,CAAC;IACrC,WAAW,GAAG,EAAE,CAAC;IACjB,YAAY,GAAG,KAAK,CAAC;IAE7B,YACmB,aAA4B,EAC5B,MAAmB,EACnB,SAAiB;QAFjB,kBAAa,GAAb,aAAa,CAAe;QAC5B,WAAM,GAAN,MAAM,CAAa;QACnB,cAAS,GAAT,SAAS,CAAQ;QAElC,IAAI,CAAC,iBAAiB,EAAE,CAAC;IAC3B,CAAC;IAED;;OAEG;IACK,iBAAiB;QACvB,qCAAqC;QACrC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE;YACtC,IAAI,CAAC,WAAW,IAAI,KAAK,CAAC,IAAI,CAAC;QACjC,CAAC,CAAC,CAAC;QAEH,sCAAsC;QACtC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC,UAAU,EAAE,CAAC,KAAK,E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AAC,SAAS;gBACzB,IAAI,EAAE,YAAY;gBAClB,OAAO;gBACP,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;aACtB,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACK,WAAW,CAAC,MAAc;QAChC,mCAAmC;QACnC,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QAE3D,0BAA0B;QAC1B,OAAO,OAAO,IAAI,gBAAgB,CAAC;IACrC,CAAC;IAED;;OAEG;IACH,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;IAED;;OAEG;IACH,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;IAC5B,CAAC;CACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude CLI integration module
|
|
3
|
+
*
|
|
4
|
+
* Provides subprocess management for Claude CLI with stream-json output parsing.
|
|
5
|
+
* This replaces PTY-based ANSI parsing with structured JSON events.
|
|
6
|
+
*/
|
|
7
|
+
export { ClaudeProcess } from './ClaudeProcess.js';
|
|
8
|
+
export { EventAdapter } from './EventAdapter.js';
|
|
9
|
+
export type { BaseMessage, SystemInitMessage, SystemHookMessage, SystemMessage, TextBlock, ToolUseBlock, ContentBlock, MessageUsage, AssistantMessage, ToolResultContent, UserMessage, ResultSubtype, ResultMessage, StreamMessage, InitEvent, TextEvent, ToolUseEvent, ToolResultEvent, CompleteEvent, ErrorType, ErrorEvent, PermissionMode, ClaudeProcessOptions, ClaudeProcessEvents, } from './types.js';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/claude/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,YAAY,EAEV,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EACb,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACX,aAAa,EACb,aAAa,EACb,aAAa,EAEb,SAAS,EACT,SAAS,EACT,YAAY,EACZ,eAAe,EACf,aAAa,EACb,SAAS,EACT,UAAU,EAEV,cAAc,EACd,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude CLI integration module
|
|
3
|
+
*
|
|
4
|
+
* Provides subprocess management for Claude CLI with stream-json output parsing.
|
|
5
|
+
* This replaces PTY-based ANSI parsing with structured JSON events.
|
|
6
|
+
*/
|
|
7
|
+
export { ClaudeProcess } from './ClaudeProcess.js';
|
|
8
|
+
export { EventAdapter } from './EventAdapter.js';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/claude/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stream-JSON message type definitions for Claude CLI output
|
|
3
|
+
*
|
|
4
|
+
* These types match the NDJSON output from:
|
|
5
|
+
* claude -p "prompt" --output-format stream-json --verbose
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Base fields present on all stream-json messages
|
|
9
|
+
*/
|
|
10
|
+
export interface BaseMessage {
|
|
11
|
+
type: string;
|
|
12
|
+
uuid: string;
|
|
13
|
+
session_id: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* System initialization message - first message in stream
|
|
17
|
+
*/
|
|
18
|
+
export interface SystemInitMessage extends BaseMessage {
|
|
19
|
+
type: 'system';
|
|
20
|
+
subtype: 'init';
|
|
21
|
+
cwd: string;
|
|
22
|
+
tools: string[];
|
|
23
|
+
mcp_servers: Array<{
|
|
24
|
+
name: string;
|
|
25
|
+
status: string;
|
|
26
|
+
}>;
|
|
27
|
+
model: string;
|
|
28
|
+
permissionMode: string;
|
|
29
|
+
claude_code_version: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* System hook messages (pre/post execution hooks)
|
|
33
|
+
*/
|
|
34
|
+
export interface SystemHookMessage extends BaseMessage {
|
|
35
|
+
type: 'system';
|
|
36
|
+
subtype: 'hook_started' | 'hook_response';
|
|
37
|
+
hook_id: string;
|
|
38
|
+
hook_name: string;
|
|
39
|
+
hook_event: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Union of system message types
|
|
43
|
+
*/
|
|
44
|
+
export type SystemMessage = SystemInitMessage | SystemHookMessage;
|
|
45
|
+
/**
|
|
46
|
+
* Text content block in assistant response
|
|
47
|
+
*/
|
|
48
|
+
export interface TextBlock {
|
|
49
|
+
type: 'text';
|
|
50
|
+
text: string;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Tool use content block in assistant response
|
|
54
|
+
*/
|
|
55
|
+
export interface ToolUseBlock {
|
|
56
|
+
type: 'tool_use';
|
|
57
|
+
id: string;
|
|
58
|
+
name: string;
|
|
59
|
+
input: Record<string, unknown>;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Union of content block types
|
|
63
|
+
*/
|
|
64
|
+
export type ContentBlock = TextBlock | ToolUseBlock;
|
|
65
|
+
/**
|
|
66
|
+
* Usage statistics for a message
|
|
67
|
+
*/
|
|
68
|
+
export interface MessageUsage {
|
|
69
|
+
input_tokens: number;
|
|
70
|
+
output_tokens: number;
|
|
71
|
+
cache_creation_input_tokens?: number;
|
|
72
|
+
cache_read_input_tokens?: number;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Assistant response message containing text and/or tool use
|
|
76
|
+
*/
|
|
77
|
+
export interface AssistantMessage extends BaseMessage {
|
|
78
|
+
type: 'assistant';
|
|
79
|
+
message: {
|
|
80
|
+
model: string;
|
|
81
|
+
id: string;
|
|
82
|
+
role: 'assistant';
|
|
83
|
+
content: ContentBlock[];
|
|
84
|
+
stop_reason: string | null;
|
|
85
|
+
usage: MessageUsage;
|
|
86
|
+
};
|
|
87
|
+
parent_tool_use_id: string | null;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Tool result content in user message
|
|
91
|
+
*/
|
|
92
|
+
export interface ToolResultContent {
|
|
93
|
+
type: 'tool_result';
|
|
94
|
+
content: string;
|
|
95
|
+
is_error: boolean;
|
|
96
|
+
tool_use_id: string;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* User message containing tool results
|
|
100
|
+
*/
|
|
101
|
+
export interface UserMessage extends BaseMessage {
|
|
102
|
+
type: 'user';
|
|
103
|
+
message: {
|
|
104
|
+
role: 'user';
|
|
105
|
+
content: ToolResultContent[];
|
|
106
|
+
};
|
|
107
|
+
tool_use_result?: string;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Result subtypes indicating how the session ended
|
|
111
|
+
*/
|
|
112
|
+
export type ResultSubtype = 'success' | 'error_max_turns' | 'error_during_execution';
|
|
113
|
+
/**
|
|
114
|
+
* Final result message - last message in stream
|
|
115
|
+
*/
|
|
116
|
+
export interface ResultMessage extends BaseMessage {
|
|
117
|
+
type: 'result';
|
|
118
|
+
subtype: ResultSubtype;
|
|
119
|
+
is_error: boolean;
|
|
120
|
+
duration_ms: number;
|
|
121
|
+
num_turns: number;
|
|
122
|
+
result: string;
|
|
123
|
+
total_cost_usd: number;
|
|
124
|
+
usage: MessageUsage;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Union of all stream-json message types
|
|
128
|
+
*/
|
|
129
|
+
export type StreamMessage = SystemInitMessage | SystemHookMessage | AssistantMessage | UserMessage | ResultMessage;
|
|
130
|
+
/**
|
|
131
|
+
* Event emitted when session initializes
|
|
132
|
+
*/
|
|
133
|
+
export interface InitEvent {
|
|
134
|
+
sessionId: string;
|
|
135
|
+
tools: string[];
|
|
136
|
+
model: string;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Event emitted for text content from assistant
|
|
140
|
+
*/
|
|
141
|
+
export interface TextEvent {
|
|
142
|
+
text: string;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Event emitted when assistant uses a tool
|
|
146
|
+
*/
|
|
147
|
+
export interface ToolUseEvent {
|
|
148
|
+
id: string;
|
|
149
|
+
name: string;
|
|
150
|
+
input: Record<string, unknown>;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Event emitted when tool execution completes
|
|
154
|
+
*/
|
|
155
|
+
export interface ToolResultEvent {
|
|
156
|
+
result: string;
|
|
157
|
+
isError: boolean;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Event emitted when session completes
|
|
161
|
+
*/
|
|
162
|
+
export interface CompleteEvent {
|
|
163
|
+
result: string;
|
|
164
|
+
sessionId: string;
|
|
165
|
+
cost: number;
|
|
166
|
+
duration: number;
|
|
167
|
+
isError: boolean;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Error event types
|
|
171
|
+
*/
|
|
172
|
+
export type ErrorType = 'parse' | 'exit' | 'spawn';
|
|
173
|
+
/**
|
|
174
|
+
* Event emitted on errors
|
|
175
|
+
*/
|
|
176
|
+
export interface ErrorEvent {
|
|
177
|
+
type: ErrorType;
|
|
178
|
+
message: string;
|
|
179
|
+
details?: {
|
|
180
|
+
line?: string;
|
|
181
|
+
code?: number;
|
|
182
|
+
stderr?: string;
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Option in an AskUserQuestion
|
|
187
|
+
*/
|
|
188
|
+
export interface QuestionOption {
|
|
189
|
+
label: string;
|
|
190
|
+
description: string;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* A single question from AskUserQuestion tool
|
|
194
|
+
*/
|
|
195
|
+
export interface Question {
|
|
196
|
+
question: string;
|
|
197
|
+
header: string;
|
|
198
|
+
options: QuestionOption[];
|
|
199
|
+
multiSelect: boolean;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Input structure for AskUserQuestion tool
|
|
203
|
+
*/
|
|
204
|
+
export interface AskUserQuestionInput {
|
|
205
|
+
questions: Question[];
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Event emitted when Claude asks a question via AskUserQuestion
|
|
209
|
+
*/
|
|
210
|
+
export interface QuestionEvent {
|
|
211
|
+
question: string;
|
|
212
|
+
options: QuestionOption[];
|
|
213
|
+
multiSelect: boolean;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Permission modes for Claude CLI
|
|
217
|
+
*/
|
|
218
|
+
export type PermissionMode = 'default' | 'acceptEdits' | 'bypassPermissions' | 'dontAsk';
|
|
219
|
+
/**
|
|
220
|
+
* Options for spawning a ClaudeProcess
|
|
221
|
+
*/
|
|
222
|
+
export interface ClaudeProcessOptions {
|
|
223
|
+
/** Working directory for Claude CLI */
|
|
224
|
+
cwd: string;
|
|
225
|
+
/** Prompt to send to Claude */
|
|
226
|
+
prompt: string;
|
|
227
|
+
/** Session ID for resuming a conversation */
|
|
228
|
+
sessionId?: string;
|
|
229
|
+
/** Permission mode for tool usage */
|
|
230
|
+
permissionMode?: PermissionMode;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Event map for ClaudeProcess typed events
|
|
234
|
+
*/
|
|
235
|
+
export interface ClaudeProcessEvents {
|
|
236
|
+
init: (event: InitEvent) => void;
|
|
237
|
+
text: (event: TextEvent) => void;
|
|
238
|
+
tool_use: (event: ToolUseEvent) => void;
|
|
239
|
+
tool_result: (event: ToolResultEvent) => void;
|
|
240
|
+
question: (event: QuestionEvent) => void;
|
|
241
|
+
complete: (event: CompleteEvent) => void;
|
|
242
|
+
error: (event: ErrorEvent) => void;
|
|
243
|
+
}
|
|
244
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/claude/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;CACpB;AAMD;;GAEG;AACH,MAAM,WAAW,iBAAkB,SAAQ,WAAW;IACpD,IAAI,EAAE,QAAQ,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,WAAW,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACrD,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,MAAM,CAAC;IACvB,mBAAmB,EAAE,MAAM,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,iBAAkB,SAAQ,WAAW;IACpD,IAAI,EAAE,QAAQ,CAAC;IACf,OAAO,EAAE,cAAc,GAAG,eAAe,CAAC;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM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ACH,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;IACjC,IAAI,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;IACjC,QAAQ,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC;IACxC,WAAW,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC;IAC9C,QAAQ,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;IACzC,QAAQ,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;IACzC,KAAK,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;CACpC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/claude/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
package/dist/env.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import 'dotenv/config';
|
|
2
|
+
export interface EnvConfig {
|
|
3
|
+
telegramBotToken: string | undefined;
|
|
4
|
+
telegramUserId: number | undefined;
|
|
5
|
+
hasTelegram: boolean;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Validate environment variables and return typed config.
|
|
9
|
+
* Does NOT exit on missing vars - that's handled by caller based on context.
|
|
10
|
+
* Returns parsed/validated values for use throughout app.
|
|
11
|
+
*/
|
|
12
|
+
export declare function loadEnv(): EnvConfig;
|
|
13
|
+
/**
|
|
14
|
+
* Validate that Telegram credentials are present.
|
|
15
|
+
* Call this when Telegram is required (not optional).
|
|
16
|
+
*/
|
|
17
|
+
export declare function requireTelegram(env: EnvConfig): asserts env is EnvConfig & {
|
|
18
|
+
telegramBotToken: string;
|
|
19
|
+
telegramUserId: number;
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=env.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AAEvB,MAAM,WAAW,SAAS;IACxB,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,WAAW,EAAE,OAAO,CAAC;CACtB;AAED;;;;GAIG;AACH,wBAAgB,OAAO,IAAI,SAAS,CAqBnC;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,SAAS,GAAG,OAAO,CAAC,GAAG,IAAI,SAAS,GAAG;IAAE,gBAAgB,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,CAAA;CAAE,CAoB/H"}
|
package/dist/env.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import 'dotenv/config';
|
|
2
|
+
/**
|
|
3
|
+
* Validate environment variables and return typed config.
|
|
4
|
+
* Does NOT exit on missing vars - that's handled by caller based on context.
|
|
5
|
+
* Returns parsed/validated values for use throughout app.
|
|
6
|
+
*/
|
|
7
|
+
export function loadEnv() {
|
|
8
|
+
const token = process.env.TELEGRAM_BOT_TOKEN;
|
|
9
|
+
const userIdRaw = process.env.TELEGRAM_USER_ID;
|
|
10
|
+
let userId;
|
|
11
|
+
if (userIdRaw) {
|
|
12
|
+
const parsed = parseInt(userIdRaw, 10);
|
|
13
|
+
if (isNaN(parsed)) {
|
|
14
|
+
console.error('\nConfiguration Error:\n');
|
|
15
|
+
console.error(' TELEGRAM_USER_ID must be a number');
|
|
16
|
+
console.error(' Get your numeric ID from @userinfobot on Telegram\n');
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
userId = parsed;
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
telegramBotToken: token,
|
|
23
|
+
telegramUserId: userId,
|
|
24
|
+
hasTelegram: Boolean(token && userId),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Validate that Telegram credentials are present.
|
|
29
|
+
* Call this when Telegram is required (not optional).
|
|
30
|
+
*/
|
|
31
|
+
export function requireTelegram(env) {
|
|
32
|
+
const errors = [];
|
|
33
|
+
if (!env.telegramBotToken) {
|
|
34
|
+
errors.push('TELEGRAM_BOT_TOKEN is required');
|
|
35
|
+
errors.push(' -> Get it from @BotFather on Telegram');
|
|
36
|
+
}
|
|
37
|
+
if (!env.telegramUserId) {
|
|
38
|
+
errors.push('TELEGRAM_USER_ID is required');
|
|
39
|
+
errors.push(' -> Get your numeric ID from @userinfobot on Telegram');
|
|
40
|
+
}
|
|
41
|
+
if (errors.length > 0) {
|
|
42
|
+
console.error('\nMissing required environment variables:\n');
|
|
43
|
+
errors.forEach(e => console.error(` ${e}`));
|
|
44
|
+
console.error('\nSee README.md for setup instructions.');
|
|
45
|
+
console.error('Or copy .env.example to .env and fill in values.\n');
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=env.js.map
|
package/dist/env.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AAQvB;;;;GAIG;AACH,MAAM,UAAU,OAAO;IACrB,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC;IAC7C,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC;IAE/C,IAAI,MAA0B,CAAC;IAC/B,IAAI,SAAS,EAAE,CAAC;QACd,MAAM,MAAM,GAAG,QAAQ,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;QACvC,IAAI,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;YAClB,OAAO,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;YAC1C,OAAO,CAAC,KAAK,CAAC,qCAAqC,CAAC,CAAC;YACrD,OAAO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