Mercurial
comparison seobeo/examples/sse_server_example.c @ 260:1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
Integrate the production JRPG chat with Seobeo streaming, Deita persistence, and a Bazel-managed Copilot SDK and LiteLLM inference stack.
Co-authored-by: Copilot <[email protected]>
| author | MrJuneJune <mrjunejune@users.noreply.github.com> |
|---|---|
| date | Wed, 05 Aug 2026 09:19:41 -0700 |
| parents | 609d3c6aff4e |
| children |
comparison
equal
deleted
inserted
replaced
| 259:667156fcd3e3 | 260:1f9877b637e9 |
|---|---|
| 1 #include "seobeo/seobeo.h" | 1 #include "seobeo/seobeo.h" |
| 2 | 2 |
| 3 #include <stdio.h> | |
| 3 #include <unistd.h> | 4 #include <unistd.h> |
| 4 | 5 |
| 5 static void Send_Later(void *p_context) | 6 static void Send_Later(void *p_context) |
| 6 { | 7 { |
| 7 Seobeo_SSE_Stream *p_stream = p_context; | 8 Seobeo_SSE_Stream *p_stream = p_context; |
| 32 if (result != SEOBEO_WORKER_OK) | 33 if (result != SEOBEO_WORKER_OK) |
| 33 Seobeo_SSE_Release(p_stream); | 34 Seobeo_SSE_Release(p_stream); |
| 34 } | 35 } |
| 35 } | 36 } |
| 36 | 37 |
| 38 static void Post_Events( | |
| 39 Seobeo_SSE_Stream *p_stream, | |
| 40 Seobeo_Request_Entry *p_request, | |
| 41 Dowa_Arena *p_arena) | |
| 42 { | |
| 43 (void)p_arena; | |
| 44 Seobeo_Request_Entry *p_topic = | |
| 45 Dowa_HashMap_Get_Ptr(p_request, ":topic"); | |
| 46 Seobeo_Request_Entry *p_body = | |
| 47 Dowa_HashMap_Get_Ptr(p_request, "Body"); | |
| 48 char event[256]; | |
| 49 int length = snprintf( | |
| 50 event, | |
| 51 sizeof(event), | |
| 52 "topic=%s body=%s", | |
| 53 p_topic ? p_topic->value : "", | |
| 54 p_body ? p_body->value : ""); | |
| 55 if (length > 0 && (size_t)length < sizeof(event)) | |
| 56 Seobeo_SSE_Send_Data(p_stream, event); | |
| 57 } | |
| 58 | |
| 37 static Seobeo_Request_Entry *Health( | 59 static Seobeo_Request_Entry *Health( |
| 38 Seobeo_Request_Entry *p_request, | 60 Seobeo_Request_Entry *p_request, |
| 39 Dowa_Arena *p_arena) | 61 Dowa_Arena *p_arena) |
| 40 { | 62 { |
| 41 (void)p_request; | 63 (void)p_request; |
| 53 int main(int argc, char **argv) | 75 int main(int argc, char **argv) |
| 54 { | 76 { |
| 55 const char *port = argc > 1 ? argv[1] : "18081"; | 77 const char *port = argc > 1 ? argv[1] : "18081"; |
| 56 Seobeo_Router_Init(); | 78 Seobeo_Router_Init(); |
| 57 Seobeo_Router_Register_SSE("/events", Events); | 79 Seobeo_Router_Register_SSE("/events", Events); |
| 80 Seobeo_Router_Register_SSE_Method( | |
| 81 "POST", | |
| 82 "/events/:topic", | |
| 83 Post_Events); | |
| 58 Seobeo_Router_Register("GET", "/health", Health); | 84 Seobeo_Router_Register("GET", "/health", Health); |
| 59 int result = Seobeo_Web_Server_Start_On( | 85 int result = Seobeo_Web_Server_Start_On( |
| 60 "127.0.0.1", | 86 "127.0.0.1", |
| 61 "seobeo/examples", | 87 "seobeo/examples", |
| 62 port, | 88 port, |