compile: thread initiated_by through CompileRequest and metrics extras
Lets metrics overlays distinguish agent-triggered compiles from manual ones (the AI assistant's compiles were previously invisible in project counters). Loose optional field — omitted means manual.
This commit is contained in:
parent
986b532922
commit
730ab02bca
|
|
@ -181,6 +181,10 @@ class CompileRequest(BaseModel):
|
||||||
# the arduino-esp32 component is left out of the build entirely. None /
|
# the arduino-esp32 component is left out of the build entirely. None /
|
||||||
# 'arduino' = classic Arduino sketch compile. ESP32 boards only.
|
# 'arduino' = classic Arduino sketch compile. ESP32 boards only.
|
||||||
language: str | None = None
|
language: str | None = None
|
||||||
|
# Who triggered this compile: None/'user' = manual UI action,
|
||||||
|
# 'agent' = the AI assistant's compile_sketch tool. Metrics overlays
|
||||||
|
# use it to keep agent activity distinguishable from the user's own.
|
||||||
|
initiated_by: str | None = None
|
||||||
|
|
||||||
|
|
||||||
class CompileResponse(BaseModel):
|
class CompileResponse(BaseModel):
|
||||||
|
|
@ -509,6 +513,7 @@ async def _compile_job(
|
||||||
"file_count": len(files),
|
"file_count": len(files),
|
||||||
"has_wifi": response.has_wifi,
|
"has_wifi": response.has_wifi,
|
||||||
"async": True,
|
"async": True,
|
||||||
|
"initiated_by": request.initiated_by,
|
||||||
"partition_scheme": (request.board_options or {}).get("partitionScheme"),
|
"partition_scheme": (request.board_options or {}).get("partitionScheme"),
|
||||||
"spiffs_file_count": len(request.spiffs_files or []),
|
"spiffs_file_count": len(request.spiffs_files or []),
|
||||||
},
|
},
|
||||||
|
|
@ -530,7 +535,7 @@ async def _compile_job(
|
||||||
success=False,
|
success=False,
|
||||||
duration_ms=int((time.monotonic() - started) * 1000),
|
duration_ms=int((time.monotonic() - started) * 1000),
|
||||||
error_kind="exception",
|
error_kind="exception",
|
||||||
extra={"file_count": len(files), "exception": str(exc)[:200], "async": True},
|
extra={"file_count": len(files), "exception": str(exc)[:200], "async": True, "initiated_by": request.initiated_by},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -563,7 +568,7 @@ async def compile_sketch(
|
||||||
success=False,
|
success=False,
|
||||||
duration_ms=int((time.monotonic() - started) * 1000),
|
duration_ms=int((time.monotonic() - started) * 1000),
|
||||||
error_kind="exception",
|
error_kind="exception",
|
||||||
extra={"file_count": len(files), "exception": str(e)[:200]},
|
extra={"file_count": len(files), "exception": str(e)[:200], "initiated_by": request.initiated_by},
|
||||||
request=http_request,
|
request=http_request,
|
||||||
)
|
)
|
||||||
raise HTTPException(status_code=500, detail=str(e))
|
raise HTTPException(status_code=500, detail=str(e))
|
||||||
|
|
@ -579,6 +584,7 @@ async def compile_sketch(
|
||||||
extra={
|
extra={
|
||||||
"file_count": len(files),
|
"file_count": len(files),
|
||||||
"has_wifi": response.has_wifi,
|
"has_wifi": response.has_wifi,
|
||||||
|
"initiated_by": request.initiated_by,
|
||||||
"partition_scheme": (request.board_options or {}).get("partitionScheme"),
|
"partition_scheme": (request.board_options or {}).get("partitionScheme"),
|
||||||
"spiffs_file_count": len(request.spiffs_files or []),
|
"spiffs_file_count": len(request.spiffs_files or []),
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,9 @@ export interface CompileExtras {
|
||||||
// ESP-IDF project (user app_main, no arduino-esp32 component). Omitted /
|
// ESP-IDF project (user app_main, no arduino-esp32 component). Omitted /
|
||||||
// undefined = classic Arduino sketch compile. ESP32 boards only.
|
// undefined = classic Arduino sketch compile. ESP32 boards only.
|
||||||
language?: 'espidf';
|
language?: 'espidf';
|
||||||
|
// Who triggered the compile — 'agent' when the AI assistant's tool did.
|
||||||
|
// Threads through to backend metrics; omitted = manual user action.
|
||||||
|
initiatedBy?: 'agent';
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CompileResult {
|
export interface CompileResult {
|
||||||
|
|
@ -118,6 +121,7 @@ export async function compileCode(
|
||||||
spiffs_files,
|
spiffs_files,
|
||||||
libraries,
|
libraries,
|
||||||
language: extras?.language ?? null,
|
language: extras?.language ?? null,
|
||||||
|
initiated_by: extras?.initiatedBy ?? null,
|
||||||
},
|
},
|
||||||
{ withCredentials: true, timeout: 30000 },
|
{ withCredentials: true, timeout: 30000 },
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue