WeKnora/internal/models/chat
wizardchen 92e02c1d49 chore(llm): add fire-once OpenAI-layer stream diagnostic logs
Add per-stream once-only logs at the OpenAI-protocol layer so we can
triage streaming behavior (natural-stop vs tool-call, TTFC, ordering of
reasoning/content/tool_calls) without grepping through every delta.

streamState now tracks:
  - streamStartedAt    : baseline for elapsed_ms on each fire-once log
  - firstContentSeen   : delta.Content first appearance
  - firstReasoningSeen : reasoning_content first appearance
  - firstToolCallSeen / noToolCallStopLogged (existing flags retained)

Logs emitted at most once per stream:
  [LLM Stream] First reasoning_content at OpenAI layer (len, preview, elapsed_ms)
  [LLM Stream] First delta.Content at OpenAI layer (len, preview, tool_call_seen, thinking_seen, elapsed_ms)
  [LLM Stream] First tool_calls delta at OpenAI layer (count, first_id, first_name, first_content_seen, thinking_seen, elapsed_ms)
  [LLM Stream] Natural-stop at OpenAI layer (finish=stop, tool_calls field never observed, thinking_seen, first_content_seen, elapsed_ms)

Together with the existing agent-layer "Natural-stop candidate detected"
log this lets a single grep reconstruct the temporal layout of one stream
(reasoning -> content -> tool_call OR natural-stop) and tell apart:
  (A) tool_calls field truly absent (real natural-stop)
  (B) tool_calls field arrived but high-level marker not yet emitted

Pure logging change; no behavior change. Previews use the existing
truncateForDebug helper (rune-safe, capped at 80 chars).
2026-05-07 18:28:28 +08:00
..
chat.go feat(observability): integrate Langfuse for LLM token tracking and tracing 2026-04-24 10:29:19 +08:00
chat_provider_spec.go refactor: Simplify WeKnoraCloud request customization and message conversion 2026-04-23 17:52:43 +08:00
config_from_model_test.go feat(models): support custom HTTP headers across all remote model calls 2026-04-23 23:36:40 +08:00
image_resolve.go feat: enhance multimodal support and image handling 2026-03-16 02:26:47 +08:00
json_field_extractor.go feat: implement final_answer tool and enhance agent duration tracking 2026-03-09 11:46:56 +08:00
json_field_extractor_test.go feat: implement final_answer tool and enhance agent duration tracking 2026-03-09 11:46:56 +08:00
langfuse_wrapper.go feat(observability): integrate Langfuse for LLM token tracking and tracing 2026-04-24 10:29:19 +08:00
llm_debug.go feat(logger): implement LLM debug logging functionality 2026-04-16 23:15:02 +08:00
llm_debug_wrapper.go feat(logger): implement LLM debug logging functionality 2026-04-16 23:15:02 +08:00
ollama.go refactor(chat): simplify temperature option handling in chat request builders 2026-03-31 12:19:22 +08:00
remote_api.go chore(llm): add fire-once OpenAI-layer stream diagnostic logs 2026-05-07 18:28:28 +08:00
remote_api_test.go fix: improve tenant access token logging and update test cases 2026-04-22 21:17:30 +08:00
sse_reader.go fix: ReadEvent incompatible sse data format 2026-04-20 22:29:38 +08:00