@fonz/tgcc 0.6.18 → 0.6.19
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/dist/bridge.js +41 -11
- package/dist/bridge.js.map +1 -1
- package/dist/streaming.d.ts +61 -89
- package/dist/streaming.js +669 -677
- package/dist/streaming.js.map +1 -1
- package/dist/telegram-html-ast.js +3 -0
- package/dist/telegram-html-ast.js.map +1 -1
- package/package.json +1 -1
package/dist/streaming.d.ts
CHANGED
|
@@ -56,91 +56,78 @@ export declare class StreamAccumulator {
|
|
|
56
56
|
private splitThreshold;
|
|
57
57
|
private logger?;
|
|
58
58
|
private onError?;
|
|
59
|
+
private segments;
|
|
59
60
|
private tgMessageId;
|
|
60
|
-
private buffer;
|
|
61
|
-
private thinkingBuffer;
|
|
62
|
-
private imageBase64Buffer;
|
|
63
|
-
private currentBlockType;
|
|
64
|
-
private lastEditTime;
|
|
65
|
-
private editTimer;
|
|
66
|
-
private thinkingIndicatorShown;
|
|
67
|
-
private thinkingMessageId;
|
|
68
61
|
private messageIds;
|
|
69
|
-
|
|
62
|
+
sealed: boolean;
|
|
70
63
|
private sendQueue;
|
|
71
64
|
private turnUsage;
|
|
72
|
-
/** Usage from the most recent message_start event — represents a single API call's context (not cumulative). */
|
|
73
65
|
private _lastMsgStartCtx;
|
|
74
|
-
private
|
|
66
|
+
private currentBlockType;
|
|
67
|
+
private currentBlockId;
|
|
68
|
+
private currentSegmentIdx;
|
|
75
69
|
private toolInputBuffers;
|
|
76
|
-
private
|
|
77
|
-
private
|
|
70
|
+
private imageBase64Buffer;
|
|
71
|
+
private lastEditTime;
|
|
72
|
+
private flushTimer;
|
|
73
|
+
private dirty;
|
|
74
|
+
private turnStartTime;
|
|
75
|
+
private firstSendReady;
|
|
76
|
+
private firstSendTimer;
|
|
77
|
+
private toolHideTimers;
|
|
78
78
|
constructor(options: StreamAccumulatorOptions);
|
|
79
79
|
get allMessageIds(): number[];
|
|
80
80
|
/** Set usage stats for the current turn (called from bridge on result event) */
|
|
81
81
|
setTurnUsage(usage: TurnUsage): void;
|
|
82
|
+
/** Append a supervisor message segment. Renders in stream order with everything else. */
|
|
83
|
+
addSupervisorMessage(text: string): void;
|
|
82
84
|
handleEvent(event: StreamInnerEvent): Promise<void>;
|
|
83
85
|
private onContentBlockStart;
|
|
84
86
|
private onContentBlockDelta;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
private buildConsolidatedToolHtml;
|
|
93
|
-
/** Resolved tool result stats, keyed by blockId */
|
|
94
|
-
private toolResolvedStats;
|
|
95
|
-
/** Edit the consolidated tool message with current state of all tools. */
|
|
96
|
-
private updateConsolidatedToolMessage;
|
|
97
|
-
/** Update a tool indicator message with input preview once the JSON value is complete. */
|
|
98
|
-
private toolIndicatorLastSummary;
|
|
99
|
-
private updateToolIndicatorWithInput;
|
|
100
|
-
/** MCP media tools — on success, delete indicator (the media was sent directly). On failure, keep + react ❌. */
|
|
87
|
+
private onContentBlockStop;
|
|
88
|
+
/** Resolve a tool indicator with success/failure status. Called by bridge on tool_result. */
|
|
89
|
+
resolveToolMessage(blockId: string, isError: boolean, errorMessage?: string, resultContent?: string, toolUseResult?: Record<string, unknown>): void;
|
|
90
|
+
/** Update a sub-agent segment status (called by bridge on task_started/progress/completed). */
|
|
91
|
+
updateSubAgentSegment(blockId: string, status: 'running' | 'dispatched' | 'completed', label?: string): void;
|
|
92
|
+
/** Append a high-signal progress line to a sub-agent segment (called by bridge on task_progress). */
|
|
93
|
+
appendSubAgentProgress(blockId: string, description: string, lastToolName?: string): void;
|
|
101
94
|
private static MCP_MEDIA_TOOLS;
|
|
102
|
-
/**
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
private
|
|
111
|
-
/**
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
*/
|
|
115
|
-
private buildFullText;
|
|
116
|
-
private doEdit;
|
|
95
|
+
/** Render all segments to one HTML string. */
|
|
96
|
+
renderHtml(): string;
|
|
97
|
+
/** Force any pending timer to fire immediately and await the send queue.
|
|
98
|
+
* Bypasses the first-send gate (like finalize). Useful in tests. */
|
|
99
|
+
flush(): Promise<void>;
|
|
100
|
+
/** Mark dirty and schedule a throttled flush. The single entry point for all renders.
|
|
101
|
+
* Data in → dirty flag → throttled flush → TG edit. One path, no re-entrant loops. */
|
|
102
|
+
private flushInFlight;
|
|
103
|
+
private requestRender;
|
|
104
|
+
/** Timer callback: consumes dirty flag and chains one _doSendOrEdit onto sendQueue. */
|
|
105
|
+
private flushRender;
|
|
106
|
+
/** Split oversized message — called from within the sendQueue chain, uses _doSendOrEdit directly. */
|
|
117
107
|
private splitMessage;
|
|
118
|
-
|
|
119
|
-
private
|
|
108
|
+
private checkFirstSendReady;
|
|
109
|
+
private clearFirstSendTimer;
|
|
110
|
+
/** Force-split when a text segment exceeds 50KB */
|
|
111
|
+
private forceSplitText;
|
|
120
112
|
finalize(): Promise<void>;
|
|
121
|
-
private
|
|
122
|
-
|
|
123
|
-
|
|
113
|
+
private sendOrEdit;
|
|
114
|
+
private _doSendOrEdit;
|
|
115
|
+
private sendImage;
|
|
116
|
+
/** Soft reset: clear per-API-call transient state. Segments and tgMessageId persist across
|
|
117
|
+
* tool-use loop iterations within the same turn. */
|
|
124
118
|
softReset(): void;
|
|
125
|
-
/** Full reset:
|
|
126
|
-
* Chains on the existing sendQueue so any pending finalize() edits complete first.
|
|
127
|
-
* Consolidated tool message resets so next turn starts a fresh batch. */
|
|
119
|
+
/** Full reset: clear everything for a new turn. */
|
|
128
120
|
reset(): void;
|
|
121
|
+
private clearFlushTimer;
|
|
129
122
|
}
|
|
123
|
+
/** Format a task_progress event into a single HTML-safe progress line.
|
|
124
|
+
* Returns null if the event has no useful display content. */
|
|
125
|
+
export declare function formatProgressLine(description: string, lastToolName?: string): string | null;
|
|
130
126
|
/** Format usage stats as an HTML italic footer line */
|
|
131
127
|
export declare function formatUsageFooter(usage: TurnUsage, _model?: string): string;
|
|
132
128
|
export declare function isSubAgentTool(toolName: string): boolean;
|
|
133
|
-
/** Extract a human-readable summary from partial/complete JSON tool input.
|
|
134
|
-
* Looks for prompt, task, command, description fields — returns the first found, truncated.
|
|
135
|
-
*/
|
|
136
129
|
export declare function extractSubAgentSummary(jsonInput: string, maxLen?: number): string;
|
|
137
|
-
/** Priority index for a label source field. Lower = better. */
|
|
138
130
|
export declare function labelFieldPriority(field: string | null): number;
|
|
139
|
-
/**
|
|
140
|
-
* Extract a human-readable label for a sub-agent from its JSON tool input.
|
|
141
|
-
* Returns { label, field } so callers can track priority and upgrade labels
|
|
142
|
-
* when higher-priority fields become available during streaming.
|
|
143
|
-
*/
|
|
144
131
|
export declare function extractAgentLabel(jsonInput: string): {
|
|
145
132
|
label: string;
|
|
146
133
|
field: string | null;
|
|
@@ -155,7 +142,9 @@ export interface SubAgentInfo {
|
|
|
155
142
|
labelField: string | null;
|
|
156
143
|
agentName: string;
|
|
157
144
|
inputPreview: string;
|
|
145
|
+
startTime: number;
|
|
158
146
|
dispatchedAt: number | null;
|
|
147
|
+
progressLines: string[];
|
|
159
148
|
}
|
|
160
149
|
export interface SubAgentSender {
|
|
161
150
|
sendMessage(chatId: number | string, text: string, parseMode?: string): Promise<number>;
|
|
@@ -166,7 +155,6 @@ export interface SubAgentTrackerOptions {
|
|
|
166
155
|
chatId: number | string;
|
|
167
156
|
sender: SubAgentSender;
|
|
168
157
|
}
|
|
169
|
-
/** A single mailbox message from a CC background sub-agent. */
|
|
170
158
|
export interface MailboxMessage {
|
|
171
159
|
from: string;
|
|
172
160
|
text: string;
|
|
@@ -175,14 +163,13 @@ export interface MailboxMessage {
|
|
|
175
163
|
color?: string;
|
|
176
164
|
read: boolean;
|
|
177
165
|
}
|
|
178
|
-
/** Callback invoked when all tracked sub-agents have reported via mailbox. */
|
|
179
166
|
export type AllAgentsReportedCallback = () => void;
|
|
180
167
|
export declare class SubAgentTracker {
|
|
181
168
|
private chatId;
|
|
182
169
|
private sender;
|
|
183
170
|
private agents;
|
|
184
171
|
private blockToAgent;
|
|
185
|
-
private
|
|
172
|
+
private standaloneMsgId;
|
|
186
173
|
private sendQueue;
|
|
187
174
|
private teamName;
|
|
188
175
|
private mailboxPath;
|
|
@@ -190,58 +177,43 @@ export declare class SubAgentTracker {
|
|
|
190
177
|
private lastMailboxCount;
|
|
191
178
|
private onAllReported;
|
|
192
179
|
hasPendingFollowUp: boolean;
|
|
180
|
+
/** When true, stream events update agent metadata but do NOT create TG messages.
|
|
181
|
+
* Set to false after the main turn bubble is sealed to allow standalone status bubble. */
|
|
182
|
+
private inTurn;
|
|
193
183
|
constructor(options: SubAgentTrackerOptions);
|
|
194
184
|
get activeAgents(): SubAgentInfo[];
|
|
195
|
-
/** Returns true if any sub-agents were tracked in this turn (including completed ones) */
|
|
196
185
|
get hadSubAgents(): boolean;
|
|
197
|
-
/** Returns true if any sub-agents are in dispatched state (spawned but no result yet) */
|
|
198
186
|
get hasDispatchedAgents(): boolean;
|
|
199
|
-
/**
|
|
200
|
-
|
|
201
|
-
*/
|
|
187
|
+
/** Called after the main bubble is sealed. Creates standalone status bubble for any dispatched agents. */
|
|
188
|
+
startPostTurnTracking(): Promise<void>;
|
|
202
189
|
markDispatchedAsReportedInMain(): void;
|
|
203
190
|
handleEvent(event: StreamInnerEvent): Promise<void>;
|
|
204
|
-
/** Handle a tool_result event — marks the sub-agent as completed with collapsible result */
|
|
205
|
-
/** Set agent metadata from structured tool_use_result */
|
|
206
191
|
setAgentMetadata(toolUseId: string, meta: {
|
|
207
192
|
agentName?: string;
|
|
208
193
|
agentType?: string;
|
|
209
194
|
color?: string;
|
|
210
195
|
}): void;
|
|
211
|
-
/** Mark an agent as completed externally (e.g. from bridge follow-up) */
|
|
212
196
|
markCompleted(toolUseId: string, _reason: string): void;
|
|
213
197
|
handleToolResult(toolUseId: string, result: string): Promise<void>;
|
|
214
198
|
private onBlockStart;
|
|
215
|
-
/** Build and edit the shared sub-agent status message. */
|
|
216
|
-
private updateConsolidatedAgentMessage;
|
|
217
199
|
private onInputDelta;
|
|
218
200
|
private onBlockStop;
|
|
219
|
-
/** Start a periodic timer that edits the message with elapsed time */
|
|
220
|
-
/** Set callback invoked when ALL dispatched sub-agents have mailbox results. */
|
|
221
201
|
setOnAllReported(cb: AllAgentsReportedCallback | null): void;
|
|
222
|
-
/** Set the CC team name (extracted from spawn confirmation tool_result). */
|
|
223
202
|
setTeamName(name: string): void;
|
|
224
203
|
get currentTeamName(): string | null;
|
|
225
204
|
get isMailboxWatching(): boolean;
|
|
226
|
-
/** Start watching the mailbox file for sub-agent results. */
|
|
227
205
|
startMailboxWatch(): void;
|
|
228
|
-
/** Stop watching the mailbox file. */
|
|
229
206
|
stopMailboxWatch(): void;
|
|
230
|
-
/** Read and parse the mailbox file. Returns [] on any error. */
|
|
231
207
|
private readMailboxMessages;
|
|
232
|
-
/** Process new mailbox messages and update sub-agent TG messages. */
|
|
233
208
|
private processMailbox;
|
|
234
|
-
/** Find a tracked sub-agent whose label matches the mailbox message's `from` field. */
|
|
235
209
|
private findAgentByFrom;
|
|
236
|
-
|
|
237
|
-
handleTaskStarted(toolUseId: string, description: string, taskType?: string): void;
|
|
238
|
-
/** Handle a system task_progress event — update the sub-agent status with current activity. */
|
|
210
|
+
handleTaskStarted(toolUseId: string, description: string, _taskType?: string): void;
|
|
239
211
|
handleTaskProgress(toolUseId: string, description: string, lastToolName?: string): void;
|
|
240
|
-
/** Handle a system task_completed event. */
|
|
241
212
|
handleTaskCompleted(toolUseId: string): void;
|
|
242
|
-
/** Build
|
|
243
|
-
private
|
|
244
|
-
/**
|
|
213
|
+
/** Build the standalone status bubble HTML. */
|
|
214
|
+
private buildStandaloneHtml;
|
|
215
|
+
/** Edit the standalone status bubble with current state. */
|
|
216
|
+
private updateStandaloneMessage;
|
|
245
217
|
getAgentByToolUseId(toolUseId: string): SubAgentInfo | undefined;
|
|
246
218
|
reset(): void;
|
|
247
219
|
}
|