15EM_JS(
char*, WasmConfig_GetString, (
const char* path,
const char* defaultVal), {
17 var config = window.YAZE_CONFIG || {};
18 var parts = UTF8ToString(path).split(
'.');
20 for (var i = 0; i < parts.length; i++) {
21 if (value && typeof value ===
'object' && parts[i] in value) {
22 value = value[parts[i]];
24 value = UTF8ToString(defaultVal);
28 if (typeof value !==
'string') {
29 value = UTF8ToString(defaultVal);
31 var lengthBytes = lengthBytesUTF8(value) + 1;
32 var stringOnWasmHeap = _malloc(lengthBytes);
33 stringToUTF8(value, stringOnWasmHeap, lengthBytes);
34 return stringOnWasmHeap;
36 console.error(
'[WasmConfig] Error reading string:', e);
37 var def = UTF8ToString(defaultVal);
38 var len = lengthBytesUTF8(def) + 1;
39 var ptr = _malloc(len);
40 stringToUTF8(def, ptr, len);
46EM_JS(
double, WasmConfig_GetNumber, (
const char* path,
double defaultVal), {
48 var config = window.YAZE_CONFIG || {};
49 var parts = UTF8ToString(path).split(
'.');
51 for (var i = 0; i < parts.length; i++) {
52 if (value && typeof value ===
'object' && parts[i] in value) {
53 value = value[parts[i]];
58 return typeof value ===
'number' ? value : defaultVal;
60 console.error(
'[WasmConfig] Error reading number:', e);
66EM_JS(
int, WasmConfig_GetInt, (
const char* path,
int defaultVal), {
68 var config = window.YAZE_CONFIG || {};
69 var parts = UTF8ToString(path).split(
'.');
71 for (var i = 0; i < parts.length; i++) {
72 if (value && typeof value ===
'object' && parts[i] in value) {
73 value = value[parts[i]];
78 return typeof value ===
'number' ? Math.floor(value) : defaultVal;
80 console.error(
'[WasmConfig] Error reading int:', e);
89 bool expected =
false;
90 if (!loading_.compare_exchange_strong(expected,
true,
91 std::memory_order_acq_rel)) {
100 char* server_url = WasmConfig_GetString(
"collaboration.serverUrl",
"");
105 WasmConfig_GetNumber(
"collaboration.userTimeoutSeconds", 30.0);
107 WasmConfig_GetNumber(
"collaboration.cursorSendIntervalMs", 100.0) / 1000.0;
109 WasmConfig_GetInt(
"collaboration.maxChangeSizeBytes", 1024));
113 WasmConfig_GetInt(
"autosave.intervalSeconds", 60);
115 WasmConfig_GetInt(
"autosave.maxRecoverySlots", 5);
119 WasmConfig_GetInt(
"terminal.maxHistoryItems", 50);
121 WasmConfig_GetInt(
"terminal.maxOutputLines", 1000);
124 ui.
min_zoom =
static_cast<float>(WasmConfig_GetNumber(
"ui.minZoom", 0.25));
125 ui.
max_zoom =
static_cast<float>(WasmConfig_GetNumber(
"ui.maxZoom", 4.0));
127 WasmConfig_GetInt(
"ui.touchGestureThreshold", 10);
130 char* cache_version = WasmConfig_GetString(
"cache.version",
"v1");
135 WasmConfig_GetInt(
"cache.maxRomCacheSizeMb", 100);
138 ai.
enabled = WasmConfig_GetInt(
"ai.enabled", 1) != 0;
139 char* ai_model = WasmConfig_GetString(
"ai.model",
"gemini-2.5-flash");
140 ai.
model = std::string(ai_model);
143 char* ai_endpoint = WasmConfig_GetString(
"ai.endpoint",
"");
150 char* server_repo = WasmConfig_GetString(
"deployment.serverRepo",
151 "https://github.com/scawful/yaze-server");
157 char* protocol_version = WasmConfig_GetString(
"deployment.protocolVersion",
"2.0");
159 free(protocol_version);
161 loaded_.store(
true, std::memory_order_release);
162 loading_.store(
false, std::memory_order_release);
166 static WasmConfig instance;
EM_JS(void, CallJsAiDriver,(const char *history_json), { if(window.yaze &&window.yaze.ai &&window.yaze.ai.processAgentRequest) { window.yaze.ai.processAgentRequest(UTF8ToString(history_json));} else { console.error("AI Driver not found in window.yaze.ai.processAgentRequest");} })