// Actual command recognizer, message/report parsing and stop-readiness boundary. const fs = require('node:fs'), path = require('node:path'); const root = path.resolve(__dirname, '..'); const read = p => fs.readFileSync(path.join(root, p), 'utf8'); const src = read('components/application/service/conv_service/src/volc_conv.c'); const json = path.join('E:/Codex/toolchains/esp-idf-v5.5.1/components/json/cJSON'); function section(start, end) { const a = src.indexOf(start), b = src.indexOf(end, a + start.length); if (a < 0 || b < 0) throw new Error('Missing production section ' + start); return src.slice(a, b); } process.stdout.write(read('components/application/service/conv_service/inc/call_voice_end.h').replace('#pragma once', '') + '\n' + read('components/application/service/conv_service/src/call_voice_end.c').replace('#include "call_voice_end.h"', '') + '\n' + fs.readFileSync(path.join(json, 'cJSON.h'), 'utf8') + '\n' + fs.readFileSync(path.join(json, 'cJSON.c'), 'utf8').replace('#include "cJSON.h"', '') + String.raw` #include #include #include typedef void *volc_engine_t; typedef void *volc_hal_player_t; typedef struct {int unused;} volc_message_info_t; typedef struct {void *player_handle[1];} volc_hal_context_t; static volc_hal_context_t hal={{(void*)1}}; static struct {void *engine;int wait_time;} conv_service; static bool is_stop,stop_requested,session_started_reported,rtc=true,player_quiet=true; static call_voice_end_t voice_end; static atomic_uint voice_finish_serial,last_voice_received_ms; static atomic_bool local_speech_active; static uint64_t now_ms; static cJSON *queue[8];static unsigned head,tail,turns,round_id; static void *platform_report_queue=(void*)1; #define pdTRUE 1 #define VOLC_HAL_PLAYER_AUDIO 0 #define VOLC_FUNCTION_CALL_EXEC 1 #define VOLC_FUNCTION_CALL_TRIGGER 2 #define LOGI(...) ((void)0) #define LOGE(...) ((void)0) static uint64_t volc_osal_get_time_ms(void){return now_ms;} static bool platform_runtime_rtc(void){return rtc;} static volc_hal_context_t *volc_get_global_hal_context(void){return &hal;} static bool volc_hal_player_voice_quiet(void *p,unsigned ms){assert(p&&(ms==600));return player_quiet;} static void volc_hal_player_play_data(void *p,const void *d,size_t n){(void)p;(void)d;(void)n;} static void volc_hal_player_finish_segment(void *p){(void)p;} static void call_idle_activity(void){} static void platform_conversation_observe(const char *type){(void)type;} static void __on_subtitle_message_received(const cJSON *j){(void)j;} static const char *volc_current_user_id(void *e,bool remote){(void)e;return remote?"bot":"user";} static int platform_conversation_turn(const char *s,const char *id,const char *text){assert(s&&id&&text);turns++;return 0;} static int platform_conversation_started(const char *ref){assert(ref);return 0;} static void aios_event_pub(int id,cJSON *j,void *u){(void)id;(void)u;cJSON_Delete(j);} static int xQueueSend(void *q,cJSON **p,unsigned ticks){(void)q;(void)ticks;if(tail-head==8)return 0;queue[tail++%8]=*p;return pdTRUE;} static int xQueueReceive(void *q,cJSON **p,unsigned ticks){(void)q;(void)ticks;if(head==tail)return 0;*p=queue[head++%8];return pdTRUE;} ` + section('/* Called only by the conversation task,', '\nvoid conv_ai_service_init()') + String.raw` static void subtitle(const char *user,const char *text,bool definite,bool paragraph){ cJSON *j=cJSON_CreateObject(),*list=cJSON_AddArrayToObject(j,"data"),*line=cJSON_CreateObject(); cJSON_AddStringToObject(j,"type","subtitle");cJSON_AddItemToArray(list,line); cJSON_AddStringToObject(line,"userId",user);cJSON_AddStringToObject(line,"text",text); cJSON_AddNumberToObject(line,"sequence",tail);cJSON_AddBoolToObject(line,"definite",definite);cJSON_AddBoolToObject(line,"paragraph",paragraph); cJSON_AddNumberToObject(line,"roundId",++round_id); char *s=cJSON_PrintUnformatted(j);cJSON_Delete(j);char b[1024]="subv0000"; assert(strlen(s)+8