MCPcopy Create free account
hub / github.com/clawbot7/cli-gateway / BranchingRpc

Class BranchingRpc

test/bindingRuntime.misc.test.ts:102–175  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100}
101
102class BranchingRpc implements StdioProcess {
103 private handlers: Array<(m: JsonRpcMessage) => void> = [];
104 written: JsonRpcMessage[] = [];
105 promptRequests: JsonRpcRequest[] = [];
106
107 private readonly updates: any[];
108 private readonly loadSession: boolean;
109 private sessionId = 'sess-branch';
110
111 constructor(params: { updates: any[]; loadSession: boolean }) {
112 this.updates = params.updates;
113 this.loadSession = params.loadSession;
114 }
115
116 write(message: JsonRpcMessage): void {
117 this.written.push(message);
118 if (!('method' in message)) return;
119
120 const req = message as JsonRpcRequest;
121 if (req.method === 'initialize') {
122 queueMicrotask(() => {
123 this.emit({
124 jsonrpc: '2.0',
125 id: req.id,
126 result: {
127 protocolVersion: 1,
128 agentCapabilities: { loadSession: this.loadSession },
129 },
130 } as JsonRpcResponse);
131 });
132 return;
133 }
134
135 if (req.method === 'session/new') {
136 queueMicrotask(() => {
137 this.emit({
138 jsonrpc: '2.0',
139 id: req.id,
140 result: { sessionId: this.sessionId },
141 } as JsonRpcResponse);
142 });
143 return;
144 }
145
146 if (req.method === 'session/prompt') {
147 this.promptRequests.push(req);
148 queueMicrotask(() => {
149 this.updates.forEach((update) => {
150 this.emit({
151 jsonrpc: '2.0',
152 method: 'session/update',
153 params: { sessionId: this.sessionId, update },
154 } as any);
155 });
156 this.emit({
157 jsonrpc: '2.0',
158 id: req.id,
159 result: { stopReason: 'end' },

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected