MCPcopy Create free account
hub / github.com/ephraimduncan/opencode-cursor / start

Function start

src/proxy.ts:1162–1318  ·  view source on GitHub ↗
(controller)

Source from the content-addressed store, hash-verified

1160
1161 const stream = new ReadableStream({
1162 start(controller) {
1163 const encoder = new TextEncoder();
1164 let closed = false;
1165 const sendSSE = (data: object) => {
1166 if (closed) return;
1167 controller.enqueue(encoder.encode(`data: ${JSON.stringify(data)}\n\n`));
1168 };
1169 const sendDone = () => {
1170 if (closed) return;
1171 controller.enqueue(encoder.encode("data: [DONE]\n\n"));
1172 };
1173 const closeController = () => {
1174 if (closed) return;
1175 closed = true;
1176 controller.close();
1177 };
1178
1179 const makeChunk = (
1180 delta: Record<string, unknown>,
1181 finishReason: string | null = null,
1182 ) => ({
1183 id: completionId,
1184 object: "chat.completion.chunk",
1185 created,
1186 model: modelId,
1187 choices: [{ index: 0, delta, finish_reason: finishReason }],
1188 });
1189
1190 const makeUsageChunk = () => {
1191 const { prompt_tokens, completion_tokens, total_tokens } = computeUsage(state);
1192 return {
1193 id: completionId,
1194 object: "chat.completion.chunk",
1195 created,
1196 model: modelId,
1197 choices: [],
1198 usage: { prompt_tokens, completion_tokens, total_tokens },
1199 };
1200 };
1201
1202 const state: StreamState = {
1203 toolCallIndex: 0,
1204 pendingExecs: [],
1205 outputTokens: 0,
1206 totalTokens: 0,
1207 };
1208 const tagFilter = createThinkingTagFilter();
1209
1210 let mcpExecReceived = false;
1211
1212 const processChunk = createConnectFrameParser(
1213 (messageBytes) => {
1214 try {
1215 const serverMessage = fromBinary(
1216 AgentServerMessageSchema,
1217 messageBytes,
1218 );
1219 processServerMessage(

Callers

nothing calls this directly

Calls 9

createThinkingTagFilterFunction · 0.85
createConnectFrameParserFunction · 0.85
processServerMessageFunction · 0.85
sendSSEFunction · 0.85
makeChunkFunction · 0.85
sendDoneFunction · 0.85
closeControllerFunction · 0.85
parseConnectEndStreamFunction · 0.85
makeUsageChunkFunction · 0.85

Tested by

no test coverage detected