| 409 | private promptRequestId: number | null = null; |
| 410 | |
| 411 | write(message: JsonRpcMessage): void { |
| 412 | if (!('method' in message)) return; |
| 413 | const req = message as JsonRpcRequest; |
| 414 | |
| 415 | if (req.method === 'initialize') { |
| 416 | queueMicrotask(() => { |
| 417 | this.emit({ |
| 418 | jsonrpc: '2.0', |
| 419 | id: req.id, |
| 420 | result: { |
| 421 | protocolVersion: 1, |
| 422 | agentCapabilities: { loadSession: false }, |
| 423 | }, |
| 424 | } as JsonRpcResponse); |
| 425 | }); |
| 426 | return; |
| 427 | } |
| 428 | |
| 429 | if (req.method === 'session/new') { |
| 430 | queueMicrotask(() => { |
| 431 | this.emit({ |
| 432 | jsonrpc: '2.0', |
| 433 | id: req.id, |
| 434 | result: { sessionId: this.sessionId }, |
| 435 | } as JsonRpcResponse); |
| 436 | }); |
| 437 | return; |
| 438 | } |
| 439 | |
| 440 | if (req.method === 'session/prompt') { |
| 441 | this.promptRequestId = Number(req.id); |
| 442 | queueMicrotask(() => { |
| 443 | this.emit({ |
| 444 | jsonrpc: '2.0', |
| 445 | method: 'session/update', |
| 446 | params: { |
| 447 | sessionId: this.sessionId, |
| 448 | update: { |
| 449 | sessionUpdate: 'tool_call', |
| 450 | toolCallId: 'flush-1', |
| 451 | title: 'terminal/create', |
| 452 | }, |
| 453 | }, |
| 454 | } as any); |
| 455 | |
| 456 | this.emit({ |
| 457 | jsonrpc: '2.0', |
| 458 | method: 'session/update', |
| 459 | params: { |
| 460 | sessionId: this.sessionId, |
| 461 | update: { |
| 462 | sessionUpdate: 'tool_call_update', |
| 463 | toolCallId: 'flush-1', |
| 464 | title: 'terminal/create', |
| 465 | status: 'completed', |
| 466 | }, |
| 467 | }, |
| 468 | } as any); |