import { getAccessToken } from './dist/auth/token-refresh.js'; import { getAccountId } from './dist/auth/token-refresh.js'; const accessToken = await getAccessToken(); const accountId = await getAccountId(); if (!accessToken || !accountId) { console.error('No token or account ID'); process.exit(1); } const instructions = await import('./dist/prompts/index.js').then(m => m.getCodexInstructions('gpt-5.1')); const response = await fetch('https://chatgpt.com/backend-api/codex/responses', { method: 'POST', headers: { 'Authorization': `Bearer ${accessToken}`, 'openai-account-id': accountId, 'openai-beta': 'responses=2', 'openai-originator': 'codex_cli_rs', 'Content-Type': 'application/json', }, body: JSON.stringify({ model: 'gpt-5.1', input: [ { type: 'message', role: 'user', content: [ { type: 'input_text', text: 'Hello, say hi in one word' } ] } ], stream: true, store: false, reasoning: { effort: 'medium', summary: 'auto' }, instructions: instructions }) }); console.log('Status:', response.status); const reader = response.body.getReader(); const decoder = new TextDecoder(); let buffer = ''; let chunks = 0; while (true) { const { done, value } = await reader.read(); if (done) break; buffer += decoder.decode(value, { stream: true }); const lines = buffer.split('\n'); buffer = lines.pop() || ''; for (const line of lines) { if (line.startsWith('data: ')) { chunks++; const data = line.substring(6); if (data.trim() !== '[DONE]') { try { const parsed = JSON.parse(data); console.log(`Chunk ${chunks}: type="${parsed.type}", delta=`, parsed.delta ? JSON.stringify(parsed.delta).substring(0, 100) : 'N/A'); if (chunks >= 10) process.exit(0); } catch (e) { console.log(`Raw chunk ${chunks}:`, data.substring(0, 100)); } } } } }