@konneal/engine 0.2.47 → 0.2.49

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.
Files changed (33) hide show
  1. package/dist/ask-OH5KPHZA.js +12 -0
  2. package/dist/attachments.d.ts +31 -0
  3. package/dist/{chunk-SE67PTJ6.js → chunk-4KA34NMU.js} +140 -5
  4. package/dist/{chunk-AKAFLMIB.js → chunk-DMIOBGQU.js} +4 -4
  5. package/dist/{chunk-R2V3X6SQ.js → chunk-JWTIPQ4L.js} +1 -1
  6. package/dist/{chunk-4GJGBGJK.js → chunk-O6VZIDPW.js} +1 -1
  7. package/dist/{chunk-N2UOENDY.js → chunk-VVLNUHW2.js} +19 -2
  8. package/dist/{chunk-V46XM2GU.js → chunk-Z24IAKB6.js} +9 -0
  9. package/dist/config.d.ts +9 -0
  10. package/dist/entailment.d.ts +5 -0
  11. package/dist/env.d.ts +1 -0
  12. package/dist/openapi-surface.gen.d.ts +1 -1
  13. package/dist/openapi-types.d.ts +149 -0
  14. package/dist/search-KNB2S2PS.js +12 -0
  15. package/dist/worker_mcp/src/index.js +2 -2
  16. package/dist/worker_public/src/config.js +1 -1
  17. package/dist/worker_public/src/index.js +121 -119
  18. package/dist/worker_public/src/requestScope.js +2 -2
  19. package/package.json +1 -1
  20. package/workers/worker_public/migrations/0017_attachments.sql +12 -0
  21. package/workers/worker_public/openapi.yaml +69 -0
  22. package/workers/worker_public/schema.sql +10 -0
  23. package/workers/worker_public/src/ask.ts +23 -2
  24. package/workers/worker_public/src/attachments.ts +102 -0
  25. package/workers/worker_public/src/config.ts +9 -0
  26. package/workers/worker_public/src/entailment.ts +15 -0
  27. package/workers/worker_public/src/env.ts +1 -0
  28. package/workers/worker_public/src/index.ts +42 -0
  29. package/workers/worker_public/src/openapi-surface.gen.ts +24 -0
  30. package/workers/worker_public/src/ports/blobs.ts +1 -0
  31. package/workers/worker_public/src/ports/cloudflare/adapters.ts +3 -0
  32. package/dist/ask-6QPD3QA5.js +0 -12
  33. package/dist/search-QZDQVB57.js +0 -12
@@ -24,6 +24,8 @@ import { json, err, corsHeaders, withCors, readJson, authenticate, type ApiKey }
24
24
  import { handleSearch } from "./search";
25
25
  import { handleEnrich, handleSectionUnit, handleCaption, handleVectors, handleJudge, handleCreateKey, handleListKeys, handleRevokeKey, handleKeyUsage } from "./admin";
26
26
  import { handleResearch } from "./research";
27
+ import { uploadAttachment, readAttachment, deleteAttachment, type AttachmentDeps } from "./attachments";
28
+ import { cfBlobs } from "./ports/cloudflare/adapters";
27
29
  import { handleAsk } from "./ask";
28
30
  import { handleMcp } from "./mcp";
29
31
 
@@ -80,6 +82,42 @@ function opWriteRefused(c: RouteContext, who: { write: boolean } | Response): Re
80
82
  return null;
81
83
  }
82
84
 
85
+ async function attachmentsUploadRoute(c: RouteContext): Promise<Response> {
86
+ const session = await sessionFrom(c.req, c.env as any);
87
+ if (!session) return withCors(err(401, "unauthorized", "Sign in to store attachments"), corsHeaders(c.req));
88
+ const deps: AttachmentDeps = { blobs: cfBlobs(c.env.CHAT_UPLOADS), store: c.env.DB };
89
+ const body = await readJson(c.req);
90
+ const out = await uploadAttachment(deps, session.sub, String(body?.data_url ?? ""));
91
+ if (out instanceof Response) return withCors(out, corsHeaders(c.req));
92
+ return withCors(json({ id: out.id }, 201), corsHeaders(c.req));
93
+ }
94
+
95
+ async function attachmentsListRoute(c: RouteContext): Promise<Response> {
96
+ const session = await sessionFrom(c.req, c.env as any);
97
+ if (!session) return withCors(err(401, "unauthorized", "Sign in to list attachments"), corsHeaders(c.req));
98
+ const rows = await c.env.DB.prepare("SELECT id, mime, bytes, created_at FROM attachments WHERE sub = ?1 ORDER BY created_at DESC LIMIT 200")
99
+ .bind(session.sub)
100
+ .all();
101
+ return withCors(json({ attachments: rows.results ?? [] }), corsHeaders(c.req));
102
+ }
103
+
104
+ async function attachmentsGetRoute(c: RouteContext): Promise<Response> {
105
+ const session = await sessionFrom(c.req, c.env as any);
106
+ if (!session) return err(404, "not_found", "No such attachment");
107
+ const deps: AttachmentDeps = { blobs: cfBlobs(c.env.CHAT_UPLOADS), store: c.env.DB };
108
+ const out = await readAttachment(deps, session.sub, c.params.id!);
109
+ return out ?? err(404, "not_found", "No such attachment");
110
+ }
111
+
112
+ async function attachmentsDeleteRoute(c: RouteContext): Promise<Response> {
113
+ const session = await sessionFrom(c.req, c.env as any);
114
+ if (!session) return withCors(err(401, "unauthorized", "Sign in to manage attachments"), corsHeaders(c.req));
115
+ const deps: AttachmentDeps = { blobs: cfBlobs(c.env.CHAT_UPLOADS), store: c.env.DB };
116
+ const gone = await deleteAttachment(deps, session.sub, c.params.id!);
117
+ if (!gone) return withCors(err(404, "not_found", "No such attachment"), corsHeaders(c.req));
118
+ return withCors(json({ ok: true }), corsHeaders(c.req));
119
+ }
120
+
83
121
  async function memoriesRoute(c: RouteContext): Promise<Response> {
84
122
  const who = await opIdentity(c, "Sign in to use memory files");
85
123
  if (who instanceof Response) return withCors(who, corsHeaders(c.req));
@@ -583,6 +621,10 @@ const OPENAPI_HANDLERS: Record<OpenApiOperationId, RouteHandler> = {
583
621
  appendMessage: appendMessageRoute,
584
622
  shareConversation: shareRoute,
585
623
  getShared: getSharedRoute,
624
+ uploadAttachment: attachmentsUploadRoute,
625
+ listAttachments: attachmentsListRoute,
626
+ getAttachment: attachmentsGetRoute,
627
+ deleteAttachment: attachmentsDeleteRoute,
586
628
  listMemories: memoriesRoute,
587
629
  createMemory: memoriesRoute,
588
630
  deleteMemory: memoriesRoute,
@@ -29,6 +29,10 @@ export type OpenApiOperationId =
29
29
  | "appendMessage"
30
30
  | "shareConversation"
31
31
  | "getShared"
32
+ | "uploadAttachment"
33
+ | "listAttachments"
34
+ | "getAttachment"
35
+ | "deleteAttachment"
32
36
  | "listMemories"
33
37
  | "createMemory"
34
38
  | "deleteMemory"
@@ -170,6 +174,26 @@ export const OPENAPI_SURFACE: readonly (Omit<OpenApiRoute, "operationId"> & { op
170
174
  "pattern": "/api/shared/:slug",
171
175
  "operationId": "getShared"
172
176
  },
177
+ {
178
+ "method": "POST",
179
+ "pattern": "/api/attachments",
180
+ "operationId": "uploadAttachment"
181
+ },
182
+ {
183
+ "method": "GET",
184
+ "pattern": "/api/attachments",
185
+ "operationId": "listAttachments"
186
+ },
187
+ {
188
+ "method": "GET",
189
+ "pattern": "/api/attachments/:id",
190
+ "operationId": "getAttachment"
191
+ },
192
+ {
193
+ "method": "DELETE",
194
+ "pattern": "/api/attachments/:id",
195
+ "operationId": "deleteAttachment"
196
+ },
173
197
  {
174
198
  "method": "GET",
175
199
  "pattern": "/api/memories",
@@ -4,4 +4,5 @@
4
4
  export interface Blobs {
5
5
  get(key: string): Promise<{ body: ReadableStream | null; contentType?: string } | null>;
6
6
  put(key: string, value: string | ReadableStream | ArrayBuffer, contentType?: string): Promise<void>;
7
+ delete(key: string): Promise<void>;
7
8
  }
@@ -164,6 +164,9 @@ export function cfBlobs(bucket: unknown): Blobs {
164
164
  async put(key, value, contentType) {
165
165
  await r2.put(key, value, contentType ? { httpMetadata: { contentType } } : undefined);
166
166
  },
167
+ async delete(key) {
168
+ await r2.delete(key);
169
+ },
167
170
  };
168
171
  }
169
172
 
@@ -1,12 +0,0 @@
1
- import {
2
- handleAsk
3
- } from "./chunk-SE67PTJ6.js";
4
- import "./chunk-N2UOENDY.js";
5
- import "./chunk-R2V3X6SQ.js";
6
- import "./chunk-A3QHHUN5.js";
7
- import "./chunk-4GJGBGJK.js";
8
- import "./chunk-V46XM2GU.js";
9
- import "./chunk-3FYJM7LH.js";
10
- export {
11
- handleAsk
12
- };
@@ -1,12 +0,0 @@
1
- import {
2
- handleSearch
3
- } from "./chunk-AKAFLMIB.js";
4
- import "./chunk-N2UOENDY.js";
5
- import "./chunk-R2V3X6SQ.js";
6
- import "./chunk-A3QHHUN5.js";
7
- import "./chunk-4GJGBGJK.js";
8
- import "./chunk-V46XM2GU.js";
9
- import "./chunk-3FYJM7LH.js";
10
- export {
11
- handleSearch
12
- };