MCPcopy
hub / github.com/cline/cline / createConnectorRuntimeTurnStream

Function createConnectorRuntimeTurnStream

apps/cli/src/connectors/runtime-turn.ts:134–341  ·  view source on GitHub ↗
(input: {
	client: HubSessionClient;
	sessionId: string;
	request: ChatRunTurnRequest;
	clientId: string;
	logger: CliLoggerAdapter;
	transport: string;
	conversationId: string;
	onToolStatus?: (message: string) => Promise<void>;
	onApprovalRequested?: (approval: PendingConnectorApproval) => Promise<void>;
	onCompleted?: (result: {
		text: string;
		finishReason?: string;
		iterations?: number;
	}) => Promise<void>;
	onFailed?: (error: Error) => Promise<void>;
})

Source from the content-addressed store, hash-verified

132}
133
134export function createConnectorRuntimeTurnStream(input: {
135 client: HubSessionClient;
136 sessionId: string;
137 request: ChatRunTurnRequest;
138 clientId: string;
139 logger: CliLoggerAdapter;
140 transport: string;
141 conversationId: string;
142 onToolStatus?: (message: string) => Promise<void>;
143 onApprovalRequested?: (approval: PendingConnectorApproval) => Promise<void>;
144 onCompleted?: (result: {
145 text: string;
146 finishReason?: string;
147 iterations?: number;
148 }) => Promise<void>;
149 onFailed?: (error: Error) => Promise<void>;
150}): AsyncIterable<string> {
151 let lastStatusMessage = "";
152
153 return {
154 [Symbol.asyncIterator]: async function* () {
155 const queue: QueueItem[] = [];
156 let notify: (() => void) | undefined;
157 let streamedText = "";
158 let closed = false;
159 let failed = false;
160
161 const push = (item: QueueItem) => {
162 queue.push(item);
163 notify?.();
164 notify = undefined;
165 };
166
167 const postStatus = async (message: string): Promise<void> => {
168 if (!message || message === lastStatusMessage) {
169 return;
170 }
171 lastStatusMessage = message;
172 await input.onToolStatus?.(message);
173 };
174
175 const stopStreaming = input.client.streamEvents(
176 {
177 clientId: input.clientId,
178 sessionIds: [input.sessionId],
179 },
180 {
181 onEvent: (event) => {
182 if (event.eventType === "approval.requested") {
183 const approvalId =
184 typeof event.payload.approvalId === "string"
185 ? event.payload.approvalId.trim()
186 : "";
187 const toolCallId =
188 typeof event.payload.toolCallId === "string"
189 ? event.payload.toolCallId.trim()
190 : "";
191 const toolName =

Callers 2

handleConnectorUserTurnFunction · 0.90

Calls 9

parseToolApprovalInputFunction · 0.85
postStatusFunction · 0.85
pushFunction · 0.85
resolveTextDeltaFunction · 0.85
StringInterface · 0.85
streamEventsMethod · 0.80
sendRuntimeSessionMethod · 0.80
logMethod · 0.65

Tested by

no test coverage detected