@lcas58/esmi-api-types 1.0.23 → 1.0.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,3 +6,4 @@ export declare const discover: AppRouteHandler<DiscoverRoute>;
6
6
  export declare const discoverExternal: AppRouteHandler<DiscoverExternalRoute>;
7
7
  export declare const saveExternal: AppRouteHandler<SaveExternalRoute>;
8
8
  export declare const chat: AppRouteHandler<ChatRoute>;
9
+ export declare const chatStream: (c: Parameters<AppRouteHandler<ChatRoute>>[0]) => Promise<Response>;
@@ -1,11 +1,13 @@
1
1
  import { and, eq, gte, ilike, inArray, isNotNull, lte } from "drizzle-orm";
2
+ import { streamSSE } from "hono/streaming";
2
3
  import * as HttpStatusCodes from "stoker/http-status-codes";
3
4
  import * as HttpStatusPhrases from "stoker/http-status-phrases";
4
- import { agentEventsToRaw, runChatAgent, runExternalDiscoveryAgent } from "../../agent/runner.js";
5
+ import { agentEventsToRaw, runChatAgent, runExternalDiscoveryAgent, runStreamingChatAgent } from "../../agent/runner.js";
5
6
  import { getKnownExternalUrls, saveEvents, searchLocalEvents } from "../../agent/tools.js";
6
7
  import { createDb } from "../../db/index.js";
7
8
  import { event, location } from "../../db/schema/index.js";
8
9
  import { buildCacheKey, buildSeenKey, getCachedDiscovery, markUrlsSeen, setCachedDiscovery } from "../../lib/discovery-cache.js";
10
+ import { chatRequestSchema } from "./events.routes.js";
9
11
  export const list = async (c) => {
10
12
  const { db } = createDb(c.env);
11
13
  const query = c.req.valid("query");
@@ -204,9 +206,44 @@ export const chat = async (c) => {
204
206
  const { db } = createDb(c.env);
205
207
  const result = await runChatAgent(c.env, db, {
206
208
  message: body.message,
209
+ sportId: body.sportId,
210
+ sportName: body.sportName,
207
211
  history: body.history,
208
212
  city: body.city,
209
213
  state: body.state,
210
214
  });
211
215
  return c.json(result, HttpStatusCodes.OK);
212
216
  };
217
+ export const chatStream = async (c) => {
218
+ const rawBody = await c.req.json();
219
+ const parsed = chatRequestSchema.safeParse(rawBody);
220
+ if (!parsed.success) {
221
+ return c.json({ message: "Invalid request body" }, HttpStatusCodes.UNPROCESSABLE_ENTITY);
222
+ }
223
+ const user = c.get("user");
224
+ if (!user) {
225
+ return c.json({ message: "Unauthorized" }, HttpStatusCodes.UNAUTHORIZED);
226
+ }
227
+ const { db } = createDb(c.env);
228
+ const body = parsed.data;
229
+ return streamSSE(c, async (stream) => {
230
+ const writer = async (event) => {
231
+ await stream.writeSSE({ data: JSON.stringify(event) });
232
+ };
233
+ try {
234
+ await runStreamingChatAgent(c.env, db, {
235
+ message: body.message,
236
+ sportId: body.sportId,
237
+ sportName: body.sportName,
238
+ history: body.history,
239
+ city: body.city,
240
+ state: body.state,
241
+ }, writer);
242
+ }
243
+ catch (err) {
244
+ console.error("[chatStream] error:", err);
245
+ await stream.writeSSE({ data: JSON.stringify({ type: "error", message: "Stream failed" }) });
246
+ await stream.writeSSE({ data: JSON.stringify({ type: "done" }) });
247
+ }
248
+ });
249
+ };
@@ -335,6 +335,8 @@ declare const router: import("@hono/zod-openapi").OpenAPIHono<import("../../shar
335
335
  input: {
336
336
  json: {
337
337
  message: string;
338
+ sportId: string;
339
+ sportName: string;
338
340
  city?: string | undefined;
339
341
  state?: string | undefined;
340
342
  history?: {
@@ -352,6 +354,8 @@ declare const router: import("@hono/zod-openapi").OpenAPIHono<import("../../shar
352
354
  input: {
353
355
  json: {
354
356
  message: string;
357
+ sportId: string;
358
+ sportName: string;
355
359
  city?: string | undefined;
356
360
  state?: string | undefined;
357
361
  history?: {
@@ -1,4 +1,5 @@
1
1
  import { createRouter } from "../../lib/create-app.js";
2
+ import { isAuth } from "../../middlewares/is-auth.js";
2
3
  import * as handlers from "./events.handlers.js";
3
4
  import * as routes from "./events.routes.js";
4
5
  const router = createRouter()
@@ -8,4 +9,6 @@ const router = createRouter()
8
9
  .openapi(routes.discoverExternal, handlers.discoverExternal)
9
10
  .openapi(routes.saveExternal, handlers.saveExternal)
10
11
  .openapi(routes.chat, handlers.chat);
12
+ // SSE streaming route (not in OpenAPI spec — SSE responses can't be modeled in JSON schema)
13
+ router.post("/events/chat/stream", isAuth(), handlers.chatStream);
11
14
  export default router;
@@ -1401,6 +1401,8 @@ export declare const saveExternal: {
1401
1401
  };
1402
1402
  export declare const chatRequestSchema: z.ZodObject<{
1403
1403
  message: z.ZodString;
1404
+ sportId: z.ZodString;
1405
+ sportName: z.ZodString;
1404
1406
  history: z.ZodOptional<z.ZodArray<z.ZodObject<{
1405
1407
  role: z.ZodEnum<["user", "assistant"]>;
1406
1408
  content: z.ZodString;
@@ -1415,6 +1417,8 @@ export declare const chatRequestSchema: z.ZodObject<{
1415
1417
  state: z.ZodOptional<z.ZodString>;
1416
1418
  }, "strip", z.ZodTypeAny, {
1417
1419
  message: string;
1420
+ sportId: string;
1421
+ sportName: string;
1418
1422
  city?: string | undefined;
1419
1423
  state?: string | undefined;
1420
1424
  history?: {
@@ -1423,6 +1427,8 @@ export declare const chatRequestSchema: z.ZodObject<{
1423
1427
  }[] | undefined;
1424
1428
  }, {
1425
1429
  message: string;
1430
+ sportId: string;
1431
+ sportName: string;
1426
1432
  city?: string | undefined;
1427
1433
  state?: string | undefined;
1428
1434
  history?: {
@@ -1517,6 +1523,8 @@ export declare const chat: {
1517
1523
  "application/json": {
1518
1524
  schema: z.ZodObject<{
1519
1525
  message: z.ZodString;
1526
+ sportId: z.ZodString;
1527
+ sportName: z.ZodString;
1520
1528
  history: z.ZodOptional<z.ZodArray<z.ZodObject<{
1521
1529
  role: z.ZodEnum<["user", "assistant"]>;
1522
1530
  content: z.ZodString;
@@ -1531,6 +1539,8 @@ export declare const chat: {
1531
1539
  state: z.ZodOptional<z.ZodString>;
1532
1540
  }, "strip", z.ZodTypeAny, {
1533
1541
  message: string;
1542
+ sportId: string;
1543
+ sportName: string;
1534
1544
  city?: string | undefined;
1535
1545
  state?: string | undefined;
1536
1546
  history?: {
@@ -1539,6 +1549,8 @@ export declare const chat: {
1539
1549
  }[] | undefined;
1540
1550
  }, {
1541
1551
  message: string;
1552
+ sportId: string;
1553
+ sportName: string;
1542
1554
  city?: string | undefined;
1543
1555
  state?: string | undefined;
1544
1556
  history?: {
@@ -86,6 +86,8 @@ const chatMessageSchema = z.object({
86
86
  });
87
87
  export const chatRequestSchema = z.object({
88
88
  message: z.string().min(1),
89
+ sportId: z.string().min(1),
90
+ sportName: z.string().min(1),
89
91
  history: z.array(chatMessageSchema).optional(),
90
92
  city: z.string().optional(),
91
93
  state: z.string().optional(),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lcas58/esmi-api-types",
3
3
  "type": "module",
4
- "version": "1.0.23",
4
+ "version": "1.0.25",
5
5
  "license": "MIT",
6
6
  "exports": {
7
7
  ".": {