@@ -21,13 +21,13 @@ const colors = {
2121}
2222
2323/**
24- * @import { ResponsesInput, ResponseInputItem } from './types.d.ts'
25- * @param {ResponsesInput } chatInput
26- * @returns {Promise<ResponseInputItem []> }
24+ * @import { ChatInput, Message } from './types.d.ts'
25+ * @param {ChatInput } chatInput
26+ * @returns {Promise<Message []> }
2727 */
2828async function sendToServer ( chatInput ) {
2929 // Send the request to the server
30- const response = await fetch ( 'https://hyperparam.app/api/functions/openai/responses ' , {
30+ const response = await fetch ( 'https://hyperparam.app/api/functions/chat ' , {
3131 method : 'POST' ,
3232 headers : { 'Content-Type' : 'application/json' } ,
3333 body : JSON . stringify ( chatInput ) ,
@@ -38,7 +38,7 @@ async function sendToServer(chatInput) {
3838 }
3939
4040 // Process the streaming response
41- /** @type {ResponseInputItem [] } */
41+ /** @type {Message [] } */
4242 const incoming = [ ]
4343 const reader = response . body ?. getReader ( )
4444 if ( ! reader ) throw new Error ( 'No response body' )
@@ -89,11 +89,13 @@ async function sendToServer(chatInput) {
8989 summary : chunk . item . summary ,
9090 }
9191 incoming . push ( reasoningItem )
92- } else if ( ! chunk . key ) {
93- console . log ( 'Unknown chunk' , chunk )
92+ } else if ( chunk . key || chunk . type === 'response.completed' ) {
93+ // ignore
94+ } else {
95+ console . log ( '\nUnknown chunk' , chunk )
9496 }
9597 } catch ( err ) {
96- console . error ( 'Error parsing chunk' , err )
98+ console . error ( '\nError parsing chunk' , err )
9799 }
98100 }
99101 }
@@ -105,15 +107,15 @@ async function sendToServer(chatInput) {
105107 * Will mutate the messages array!
106108 *
107109 * @import { ResponseFunctionToolCall, ToolHandler } from './types.d.ts'
108- * @param {ResponseInputItem[] } input
110+ * @param {Message[][] } messages
109111 * @returns {Promise<void> }
110112 */
111- async function sendMessages ( input ) {
112- /** @type {ResponsesInput } */
113+ async function sendMessages ( messages ) {
114+ /** @type {ChatInput } */
113115 const chatInput = {
114116 model : 'gpt-5' ,
115117 instructions,
116- input ,
118+ messages ,
117119 reasoning : {
118120 effort : 'low' ,
119121 } ,
@@ -174,13 +176,13 @@ async function sendMessages(input) {
174176 }
175177 }
176178
177- input . push ( ... incoming )
179+ messages . push ( incoming )
178180
179181 // send messages with tool results
180- await sendMessages ( input )
182+ await sendMessages ( messages )
181183 } else {
182184 // no tool calls, just append incoming messages
183- input . push ( ... incoming )
185+ messages . push ( incoming )
184186 }
185187}
186188
@@ -231,7 +233,7 @@ function writeWithColor() {
231233}
232234
233235export function chat ( ) {
234- /** @type {ResponseInputItem [] } */
236+ /** @type {Message[] [] } */
235237 const messages = [ ]
236238 process . stdin . setEncoding ( 'utf-8' )
237239
@@ -245,7 +247,7 @@ export function chat() {
245247 try {
246248 write ( colors . user , 'answer: ' , colors . normal )
247249 outputMode = 'text' // switch to text output mode
248- messages . push ( { role : 'user' , content : input . trim ( ) } )
250+ messages . push ( [ { role : 'user' , content : input . trim ( ) } ] )
249251 await sendMessages ( messages )
250252 } catch ( error ) {
251253 console . error ( colors . error , '\n' + error )
0 commit comments