@jini-ai/http-kit 0.2.1

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 (227) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +107 -0
  3. package/dist/active-context.d.ts +99 -0
  4. package/dist/active-context.d.ts.map +1 -0
  5. package/dist/active-context.js +77 -0
  6. package/dist/active-context.js.map +1 -0
  7. package/dist/adapter.d.ts +36 -0
  8. package/dist/adapter.d.ts.map +1 -0
  9. package/dist/adapter.js +92 -0
  10. package/dist/adapter.js.map +1 -0
  11. package/dist/agents.d.ts +55 -0
  12. package/dist/agents.d.ts.map +1 -0
  13. package/dist/agents.js +23 -0
  14. package/dist/agents.js.map +1 -0
  15. package/dist/api-security-middleware.d.ts +146 -0
  16. package/dist/api-security-middleware.d.ts.map +1 -0
  17. package/dist/api-security-middleware.js +276 -0
  18. package/dist/api-security-middleware.js.map +1 -0
  19. package/dist/attachments.d.ts +317 -0
  20. package/dist/attachments.d.ts.map +1 -0
  21. package/dist/attachments.js +664 -0
  22. package/dist/attachments.js.map +1 -0
  23. package/dist/cancel-owned-runs.d.ts +44 -0
  24. package/dist/cancel-owned-runs.d.ts.map +1 -0
  25. package/dist/cancel-owned-runs.js +35 -0
  26. package/dist/cancel-owned-runs.js.map +1 -0
  27. package/dist/compat.d.ts +22 -0
  28. package/dist/compat.d.ts.map +1 -0
  29. package/dist/compat.js +17 -0
  30. package/dist/compat.js.map +1 -0
  31. package/dist/component-catalog.d.ts +74 -0
  32. package/dist/component-catalog.d.ts.map +1 -0
  33. package/dist/component-catalog.js +74 -0
  34. package/dist/component-catalog.js.map +1 -0
  35. package/dist/connectors.d.ts +165 -0
  36. package/dist/connectors.d.ts.map +1 -0
  37. package/dist/connectors.js +474 -0
  38. package/dist/connectors.js.map +1 -0
  39. package/dist/daemon-status.d.ts +72 -0
  40. package/dist/daemon-status.d.ts.map +1 -0
  41. package/dist/daemon-status.js +60 -0
  42. package/dist/daemon-status.js.map +1 -0
  43. package/dist/db-ops.d.ts +116 -0
  44. package/dist/db-ops.d.ts.map +1 -0
  45. package/dist/db-ops.js +191 -0
  46. package/dist/db-ops.js.map +1 -0
  47. package/dist/delegated-tools.d.ts +46 -0
  48. package/dist/delegated-tools.d.ts.map +1 -0
  49. package/dist/delegated-tools.js +155 -0
  50. package/dist/delegated-tools.js.map +1 -0
  51. package/dist/express/run-stream.d.ts +15 -0
  52. package/dist/express/run-stream.d.ts.map +1 -0
  53. package/dist/express/run-stream.js +11 -0
  54. package/dist/express/run-stream.js.map +1 -0
  55. package/dist/express-index.d.ts +32 -0
  56. package/dist/express-index.d.ts.map +1 -0
  57. package/dist/express-index.js +14 -0
  58. package/dist/express-index.js.map +1 -0
  59. package/dist/fastify/adapter.d.ts +31 -0
  60. package/dist/fastify/adapter.d.ts.map +1 -0
  61. package/dist/fastify/adapter.js +64 -0
  62. package/dist/fastify/adapter.js.map +1 -0
  63. package/dist/fastify/agents.d.ts +13 -0
  64. package/dist/fastify/agents.d.ts.map +1 -0
  65. package/dist/fastify/agents.js +7 -0
  66. package/dist/fastify/agents.js.map +1 -0
  67. package/dist/fastify/api-security-middleware.d.ts +64 -0
  68. package/dist/fastify/api-security-middleware.d.ts.map +1 -0
  69. package/dist/fastify/api-security-middleware.js +139 -0
  70. package/dist/fastify/api-security-middleware.js.map +1 -0
  71. package/dist/fastify/compat.d.ts +22 -0
  72. package/dist/fastify/compat.d.ts.map +1 -0
  73. package/dist/fastify/compat.js +16 -0
  74. package/dist/fastify/compat.js.map +1 -0
  75. package/dist/fastify/daemon-status.d.ts +22 -0
  76. package/dist/fastify/daemon-status.d.ts.map +1 -0
  77. package/dist/fastify/daemon-status.js +9 -0
  78. package/dist/fastify/daemon-status.js.map +1 -0
  79. package/dist/fastify/host-tools.d.ts +13 -0
  80. package/dist/fastify/host-tools.d.ts.map +1 -0
  81. package/dist/fastify/host-tools.js +8 -0
  82. package/dist/fastify/host-tools.js.map +1 -0
  83. package/dist/fastify/index.d.ts +36 -0
  84. package/dist/fastify/index.d.ts.map +1 -0
  85. package/dist/fastify/index.js +18 -0
  86. package/dist/fastify/index.js.map +1 -0
  87. package/dist/fastify/local-daemon-request.d.ts +43 -0
  88. package/dist/fastify/local-daemon-request.d.ts.map +1 -0
  89. package/dist/fastify/local-daemon-request.js +155 -0
  90. package/dist/fastify/local-daemon-request.js.map +1 -0
  91. package/dist/fastify/origin.d.ts +21 -0
  92. package/dist/fastify/origin.d.ts.map +1 -0
  93. package/dist/fastify/origin.js +14 -0
  94. package/dist/fastify/origin.js.map +1 -0
  95. package/dist/fastify/request.d.ts +20 -0
  96. package/dist/fastify/request.d.ts.map +1 -0
  97. package/dist/fastify/request.js +25 -0
  98. package/dist/fastify/request.js.map +1 -0
  99. package/dist/fastify/response.d.ts +20 -0
  100. package/dist/fastify/response.d.ts.map +1 -0
  101. package/dist/fastify/response.js +41 -0
  102. package/dist/fastify/response.js.map +1 -0
  103. package/dist/fastify/route-registration-guard.d.ts +70 -0
  104. package/dist/fastify/route-registration-guard.d.ts.map +1 -0
  105. package/dist/fastify/route-registration-guard.js +69 -0
  106. package/dist/fastify/route-registration-guard.js.map +1 -0
  107. package/dist/fastify/run-stream.d.ts +18 -0
  108. package/dist/fastify/run-stream.d.ts.map +1 -0
  109. package/dist/fastify/run-stream.js +10 -0
  110. package/dist/fastify/run-stream.js.map +1 -0
  111. package/dist/fastify/runs.d.ts +17 -0
  112. package/dist/fastify/runs.d.ts.map +1 -0
  113. package/dist/fastify/runs.js +33 -0
  114. package/dist/fastify/runs.js.map +1 -0
  115. package/dist/frontend-control.d.ts +131 -0
  116. package/dist/frontend-control.d.ts.map +1 -0
  117. package/dist/frontend-control.js +77 -0
  118. package/dist/frontend-control.js.map +1 -0
  119. package/dist/frontend-sessions.d.ts +100 -0
  120. package/dist/frontend-sessions.d.ts.map +1 -0
  121. package/dist/frontend-sessions.js +180 -0
  122. package/dist/frontend-sessions.js.map +1 -0
  123. package/dist/health.d.ts +91 -0
  124. package/dist/health.d.ts.map +1 -0
  125. package/dist/health.js +53 -0
  126. package/dist/health.js.map +1 -0
  127. package/dist/host-tools.d.ts +174 -0
  128. package/dist/host-tools.d.ts.map +1 -0
  129. package/dist/host-tools.js +338 -0
  130. package/dist/host-tools.js.map +1 -0
  131. package/dist/index.d.ts +86 -0
  132. package/dist/index.d.ts.map +1 -0
  133. package/dist/index.js +40 -0
  134. package/dist/index.js.map +1 -0
  135. package/dist/local-daemon-request.d.ts +44 -0
  136. package/dist/local-daemon-request.d.ts.map +1 -0
  137. package/dist/local-daemon-request.js +145 -0
  138. package/dist/local-daemon-request.js.map +1 -0
  139. package/dist/media.d.ts +131 -0
  140. package/dist/media.d.ts.map +1 -0
  141. package/dist/media.js +352 -0
  142. package/dist/media.js.map +1 -0
  143. package/dist/memory.d.ts +230 -0
  144. package/dist/memory.d.ts.map +1 -0
  145. package/dist/memory.js +331 -0
  146. package/dist/memory.js.map +1 -0
  147. package/dist/model-proxy.d.ts +45 -0
  148. package/dist/model-proxy.d.ts.map +1 -0
  149. package/dist/model-proxy.js +619 -0
  150. package/dist/model-proxy.js.map +1 -0
  151. package/dist/origin-validation.d.ts +64 -0
  152. package/dist/origin-validation.d.ts.map +1 -0
  153. package/dist/origin-validation.js +226 -0
  154. package/dist/origin-validation.js.map +1 -0
  155. package/dist/origin.d.ts +32 -0
  156. package/dist/origin.d.ts.map +1 -0
  157. package/dist/origin.js +14 -0
  158. package/dist/origin.js.map +1 -0
  159. package/dist/pack-http.d.ts +30 -0
  160. package/dist/pack-http.d.ts.map +1 -0
  161. package/dist/pack-http.js +12 -0
  162. package/dist/pack-http.js.map +1 -0
  163. package/dist/raw-sse.d.ts +44 -0
  164. package/dist/raw-sse.d.ts.map +1 -0
  165. package/dist/raw-sse.js +93 -0
  166. package/dist/raw-sse.js.map +1 -0
  167. package/dist/remote-run-events.d.ts +66 -0
  168. package/dist/remote-run-events.d.ts.map +1 -0
  169. package/dist/remote-run-events.js +230 -0
  170. package/dist/remote-run-events.js.map +1 -0
  171. package/dist/request.d.ts +19 -0
  172. package/dist/request.d.ts.map +1 -0
  173. package/dist/request.js +25 -0
  174. package/dist/request.js.map +1 -0
  175. package/dist/research.d.ts +42 -0
  176. package/dist/research.d.ts.map +1 -0
  177. package/dist/research.js +316 -0
  178. package/dist/research.js.map +1 -0
  179. package/dist/response.d.ts +14 -0
  180. package/dist/response.d.ts.map +1 -0
  181. package/dist/response.js +45 -0
  182. package/dist/response.js.map +1 -0
  183. package/dist/route-manifest.d.ts +31 -0
  184. package/dist/route-manifest.d.ts.map +1 -0
  185. package/dist/route-manifest.js +103 -0
  186. package/dist/route-manifest.js.map +1 -0
  187. package/dist/route-registration-guard.d.ts +65 -0
  188. package/dist/route-registration-guard.d.ts.map +1 -0
  189. package/dist/route-registration-guard.js +71 -0
  190. package/dist/route-registration-guard.js.map +1 -0
  191. package/dist/routines.d.ts +114 -0
  192. package/dist/routines.d.ts.map +1 -0
  193. package/dist/routines.js +320 -0
  194. package/dist/routines.js.map +1 -0
  195. package/dist/run-stream.d.ts +60 -0
  196. package/dist/run-stream.d.ts.map +1 -0
  197. package/dist/run-stream.js +108 -0
  198. package/dist/run-stream.js.map +1 -0
  199. package/dist/runs.d.ts +79 -0
  200. package/dist/runs.d.ts.map +1 -0
  201. package/dist/runs.js +232 -0
  202. package/dist/runs.js.map +1 -0
  203. package/dist/sse.d.ts +139 -0
  204. package/dist/sse.d.ts.map +1 -0
  205. package/dist/sse.js +157 -0
  206. package/dist/sse.js.map +1 -0
  207. package/dist/terminals.d.ts +125 -0
  208. package/dist/terminals.d.ts.map +1 -0
  209. package/dist/terminals.js +349 -0
  210. package/dist/terminals.js.map +1 -0
  211. package/dist/tool-catalog.d.ts +68 -0
  212. package/dist/tool-catalog.d.ts.map +1 -0
  213. package/dist/tool-catalog.js +68 -0
  214. package/dist/tool-catalog.js.map +1 -0
  215. package/dist/types.d.ts +58 -0
  216. package/dist/types.d.ts.map +1 -0
  217. package/dist/types.js +5 -0
  218. package/dist/types.js.map +1 -0
  219. package/dist/workspace-root.d.ts +69 -0
  220. package/dist/workspace-root.d.ts.map +1 -0
  221. package/dist/workspace-root.js +63 -0
  222. package/dist/workspace-root.js.map +1 -0
  223. package/dist/xai.d.ts +86 -0
  224. package/dist/xai.d.ts.map +1 -0
  225. package/dist/xai.js +668 -0
  226. package/dist/xai.js.map +1 -0
  227. package/package.json +58 -0
package/dist/media.js ADDED
@@ -0,0 +1,352 @@
1
+ /**
2
+ * @module media
3
+ *
4
+ * `POST /api/media/generate`, `GET /api/media/tasks`, `GET /api/media/tasks/:id`, `DELETE
5
+ * /api/media/tasks/:id` — an HTTP route pack over narrow, transport-owned engine/task-store ports.
6
+ * A product composition root may satisfy those ports with `@jini-ai/media`; locked `@jini-ai/http-kit`
7
+ * deliberately does not point down into that incubating implementation package.
8
+ *
9
+ * Follows the "request-now, poll-later" async-task shape `@jini-ai/media`'s own `MediaTaskStore` doc
10
+ * describes: `POST /api/media/generate` creates a task, kicks off `MediaDispatchEngine.generate()`
11
+ * in the background (never awaited by the response — a real provider call can take tens of
12
+ * seconds), and returns the freshly-`'queued'` task immediately. A caller polls
13
+ * `GET /api/media/tasks/:id` until the task reaches a terminal status (`'done'`/`'failed'`/
14
+ * `'interrupted'`), mirroring `routines.ts`'s `POST /api/routines/:id/run` (`202`, poll separately)
15
+ * rather than `runs.ts`'s SSE stream — media generation has no meaningful intermediate event
16
+ * stream the way a run does, just one eventual result.
17
+ *
18
+ * **Where generated bytes land** (per `@jini-ai/media`'s own boundary doc on `MediaGenerationRequest`/
19
+ * `MediaGenerationResult`: "this engine performs no filesystem I/O... a host pairs this with its
20
+ * own wiring to decide where generated bytes land"): this route pack encodes the result as a
21
+ * base64 `data:` URL and stores it directly in `MediaTask.file` (a deliberately untyped `unknown`
22
+ * field — see `task-store.ts`'s own doc). This is the simplest host-owned answer that needs no new
23
+ * storage port of its own; a host that wants generated bytes written to a real asset store instead
24
+ * can layer that on top by reading `MediaTask.file` off a terminal task and re-persisting it
25
+ * elsewhere — this route pack does not preclude that, it just doesn't invent a new persistence
26
+ * abstraction to do it for a caller who hasn't asked for one (matching `packages/deploy/source-
27
+ * map.md`'s "no speculative port" precedent).
28
+ *
29
+ * **`ownerRef`** is the same opaque, host-defined scoping key `MediaTaskStore` itself already
30
+ * uses (e.g. a run id) — this route pack has no `Project`/`Workspace` noun of its own, matching
31
+ * `active-context.ts`/`delegated-tools.ts`'s precedent for the same category of coupling.
32
+ *
33
+ * **SEC-005 redaction**: `MediaDispatchEngine.generate()` can throw a raw vendor-SDK/network
34
+ * error (API keys, response bodies) that must never reach an HTTP caller verbatim — matching
35
+ * `delegated-tools.ts`'s `reportInternalError` pattern exactly (a correlation-id-bearing generic
36
+ * `INTERNAL_ERROR`, the real error only reaching a host-owned sink). Applied to the background
37
+ * generation failure path (recorded on the task's own `error` field, `message` already redacted
38
+ * the same way) as well as the sync per-request validation-throw path (`POST /api/media/generate`
39
+ * itself can throw before ever creating a task — an unregistered `toolId`-shaped programming
40
+ * error, per `MediaDispatchEngine.generate`'s own contract).
41
+ */
42
+ import { randomUUID } from 'node:crypto';
43
+ import { createApiError } from '@jini-ai/protocol';
44
+ import { defineJsonRoute, mountJsonRoute } from './adapter.js';
45
+ import { validationError } from './request.js';
46
+ import { err, ok } from './types.js';
47
+ const SURFACES = new Set(['image', 'video', 'audio']);
48
+ const AUDIO_KINDS = new Set(['music', 'speech', 'sfx']);
49
+ const SPEECH_FORMATS = new Set(['mp3', 'wav', 'flac', 'aac', 'opus']);
50
+ function defaultInternalErrorSink(context) {
51
+ // eslint-disable-next-line no-console
52
+ console.error(`[@jini-ai/http-kit] internal error (${context.source}, correlationId=${context.correlationId})`, context.error);
53
+ }
54
+ function reportInternalError(deps, source, error, taskId, ownerRef) {
55
+ const correlationId = randomUUID();
56
+ const sink = deps.onInternalError ?? defaultInternalErrorSink;
57
+ sink({ source, taskId, ownerRef, correlationId, error });
58
+ return createApiError('INTERNAL_ERROR', 'an internal error occurred', { requestId: correlationId });
59
+ }
60
+ function isRecord(value) {
61
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
62
+ }
63
+ function requireNonEmptyString(body, key) {
64
+ const value = body[key];
65
+ return typeof value === 'string' && value.trim().length > 0 ? value : undefined;
66
+ }
67
+ function parseOptionalString(body, key) {
68
+ const value = body[key];
69
+ if (value === undefined)
70
+ return ok(undefined);
71
+ if (typeof value !== 'string')
72
+ return err(validationError(`${key} must be a string when provided`));
73
+ return ok(value);
74
+ }
75
+ function parseOptionalNumber(body, key) {
76
+ const value = body[key];
77
+ if (value === undefined)
78
+ return ok(undefined);
79
+ if (typeof value !== 'number' || !Number.isFinite(value))
80
+ return err(validationError(`${key} must be a finite number when provided`));
81
+ return ok(value);
82
+ }
83
+ function parseOptionalBoolean(body, key) {
84
+ const value = body[key];
85
+ if (value === undefined)
86
+ return ok(undefined);
87
+ if (typeof value !== 'boolean')
88
+ return err(validationError(`${key} must be a boolean when provided`));
89
+ return ok(value);
90
+ }
91
+ function parseImageReference(value, field) {
92
+ if (!isRecord(value) || typeof value.dataUrl !== 'string' || value.dataUrl.trim().length === 0) {
93
+ return err(validationError(`${field} must be an object with a non-empty dataUrl string`));
94
+ }
95
+ return ok({ dataUrl: value.dataUrl });
96
+ }
97
+ function parseOptionalImageRef(body) {
98
+ const value = body.imageRef;
99
+ if (value === undefined)
100
+ return ok(undefined);
101
+ return parseImageReference(value, 'imageRef');
102
+ }
103
+ function parseOptionalImageRefs(body) {
104
+ const value = body.imageRefs;
105
+ if (value === undefined)
106
+ return ok(undefined);
107
+ if (!Array.isArray(value))
108
+ return err(validationError('imageRefs must be an array when provided'));
109
+ const refs = [];
110
+ for (let i = 0; i < value.length; i += 1) {
111
+ const parsed = parseImageReference(value[i], `imageRefs[${i}]`);
112
+ if (!parsed.ok)
113
+ return parsed;
114
+ refs.push(parsed.value);
115
+ }
116
+ return ok(refs);
117
+ }
118
+ function parseMediaGenerate(input) {
119
+ if (!isRecord(input.body))
120
+ return err(validationError('body must be a JSON object'));
121
+ const body = input.body;
122
+ const ownerRef = requireNonEmptyString(body, 'ownerRef');
123
+ if (ownerRef === undefined) {
124
+ return err(validationError('ownerRef must be a non-empty string', [{ path: 'ownerRef', message: 'required non-empty string' }]));
125
+ }
126
+ const surface = body.surface;
127
+ if (typeof surface !== 'string' || !SURFACES.has(surface)) {
128
+ return err(validationError('surface must be one of: image, video, audio'));
129
+ }
130
+ const model = requireNonEmptyString(body, 'model');
131
+ if (model === undefined) {
132
+ return err(validationError('model must be a non-empty string', [{ path: 'model', message: 'required non-empty string' }]));
133
+ }
134
+ const audioKind = body.audioKind;
135
+ if (audioKind !== undefined && (typeof audioKind !== 'string' || !AUDIO_KINDS.has(audioKind))) {
136
+ return err(validationError('audioKind must be one of: music, speech, sfx when provided'));
137
+ }
138
+ const speechFormat = body.speechFormat;
139
+ if (speechFormat !== undefined && (typeof speechFormat !== 'string' || !SPEECH_FORMATS.has(speechFormat))) {
140
+ return err(validationError('speechFormat must be one of: mp3, wav, flac, aac, opus when provided'));
141
+ }
142
+ const prompt = parseOptionalString(body, 'prompt');
143
+ if (!prompt.ok)
144
+ return prompt;
145
+ const aspect = parseOptionalString(body, 'aspect');
146
+ if (!aspect.ok)
147
+ return aspect;
148
+ const voice = parseOptionalString(body, 'voice');
149
+ if (!voice.ok)
150
+ return voice;
151
+ const language = parseOptionalString(body, 'language');
152
+ if (!language.ok)
153
+ return language;
154
+ const wireModel = parseOptionalString(body, 'wireModel');
155
+ if (!wireModel.ok)
156
+ return wireModel;
157
+ const length = parseOptionalNumber(body, 'length');
158
+ if (!length.ok)
159
+ return length;
160
+ const duration = parseOptionalNumber(body, 'duration');
161
+ if (!duration.ok)
162
+ return duration;
163
+ const promptInfluence = parseOptionalNumber(body, 'promptInfluence');
164
+ if (!promptInfluence.ok)
165
+ return promptInfluence;
166
+ const loop = parseOptionalBoolean(body, 'loop');
167
+ if (!loop.ok)
168
+ return loop;
169
+ const imageRef = parseOptionalImageRef(body);
170
+ if (!imageRef.ok)
171
+ return imageRef;
172
+ const imageRefs = parseOptionalImageRefs(body);
173
+ if (!imageRefs.ok)
174
+ return imageRefs;
175
+ return ok({
176
+ ownerRef,
177
+ request: {
178
+ surface: surface,
179
+ model,
180
+ ...(prompt.value !== undefined ? { prompt: prompt.value } : {}),
181
+ ...(aspect.value !== undefined ? { aspect: aspect.value } : {}),
182
+ ...(length.value !== undefined ? { length: length.value } : {}),
183
+ ...(duration.value !== undefined ? { duration: duration.value } : {}),
184
+ ...(voice.value !== undefined ? { voice: voice.value } : {}),
185
+ ...(audioKind !== undefined ? { audioKind: audioKind } : {}),
186
+ ...(language.value !== undefined ? { language: language.value } : {}),
187
+ ...(loop.value !== undefined ? { loop: loop.value } : {}),
188
+ ...(promptInfluence.value !== undefined ? { promptInfluence: promptInfluence.value } : {}),
189
+ ...(imageRef.value !== undefined ? { imageRef: imageRef.value } : {}),
190
+ ...(imageRefs.value !== undefined ? { imageRefs: imageRefs.value } : {}),
191
+ ...(wireModel.value !== undefined ? { wireModel: wireModel.value } : {}),
192
+ ...(speechFormat !== undefined ? { speechFormat: speechFormat } : {}),
193
+ },
194
+ });
195
+ }
196
+ function parseTaskId(input) {
197
+ const id = input.params.id;
198
+ return typeof id === 'string' && id.length > 0 ? ok(id) : err(validationError('id must be a non-empty path parameter'));
199
+ }
200
+ function parseMediaTaskListQuery(input) {
201
+ const raw = input.query.ownerRef;
202
+ const ownerRef = Array.isArray(raw) ? raw[0] : raw;
203
+ if (typeof ownerRef !== 'string' || ownerRef.trim().length === 0) {
204
+ return err(validationError('ownerRef query parameter is required', [{ path: 'ownerRef', message: 'required non-empty string' }]));
205
+ }
206
+ const includeTerminalRaw = input.query.includeTerminal;
207
+ const includeTerminal = (Array.isArray(includeTerminalRaw) ? includeTerminalRaw[0] : includeTerminalRaw) === 'true';
208
+ return ok({ ownerRef, options: { includeTerminal } });
209
+ }
210
+ /**
211
+ * Runs the real generation in the background and patches the task to its terminal state.
212
+ * Deliberately fire-and-forget from `mediaGenerateRoute.handle`'s own perspective — the HTTP
213
+ * response has already returned the `'queued'` task by the time this settles.
214
+ */
215
+ async function runMediaGenerationInBackground(deps, taskId, ownerRef, request) {
216
+ try {
217
+ await deps.taskStore.update(taskId, { status: 'running' });
218
+ const result = await deps.engine.generate(request);
219
+ const base64 = result.bytes.toString('base64');
220
+ const mime = mimeTypeForSurface(request.surface, request.speechFormat);
221
+ await deps.taskStore.update(taskId, {
222
+ status: 'done',
223
+ file: {
224
+ dataUrl: `data:${mime};base64,${base64}`,
225
+ providerId: result.providerId,
226
+ providerNote: result.providerNote,
227
+ ...(result.suggestedExt !== undefined ? { suggestedExt: result.suggestedExt } : {}),
228
+ usedStubFallback: result.usedStubFallback,
229
+ },
230
+ progress: result.warnings,
231
+ endedAt: Date.now(),
232
+ });
233
+ }
234
+ catch (error) {
235
+ const apiError = reportInternalError(deps, 'media-generate-dispatch', error, taskId, ownerRef);
236
+ try {
237
+ await deps.taskStore.update(taskId, {
238
+ status: 'failed',
239
+ error: { message: apiError.message, code: apiError.code },
240
+ endedAt: Date.now(),
241
+ });
242
+ }
243
+ catch (writeError) {
244
+ // The task store can legitimately already be closed by the time a slow in-flight
245
+ // generation's failure settles (e.g. daemon shutdown mid-generation — a real vendor call
246
+ // can take "tens of seconds" per this module's own doc). This function is invoked
247
+ // fire-and-forget (`void runMediaGenerationInBackground(...)` in `mediaGenerateRoute.handle`
248
+ // below), so letting this secondary write failure propagate would reject an unobserved
249
+ // promise — an unhandled rejection that crashes a default-configured Node process over a
250
+ // condition that isn't actually fatal (the real generation failure was already reported
251
+ // above; this is only "the store couldn't also persist that fact"). Reported through the
252
+ // same sink, never rethrown.
253
+ reportInternalError(deps, 'media-generate-dispatch', writeError, taskId, ownerRef);
254
+ }
255
+ }
256
+ }
257
+ /** A minimal, real content-type per surface — enough for a caller to render/play the resulting data URL without needing to know each vendor's own response shape. */
258
+ function mimeTypeForSurface(surface, speechFormat) {
259
+ if (surface === 'image')
260
+ return 'image/png';
261
+ if (surface === 'video')
262
+ return 'video/mp4';
263
+ const format = speechFormat ?? 'mp3';
264
+ const audioMimeByFormat = {
265
+ mp3: 'audio/mpeg',
266
+ wav: 'audio/wav',
267
+ flac: 'audio/flac',
268
+ aac: 'audio/aac',
269
+ opus: 'audio/opus',
270
+ };
271
+ return audioMimeByFormat[format];
272
+ }
273
+ export const mediaGenerateRoute = defineJsonRoute({
274
+ method: 'post',
275
+ path: '/api/media/generate',
276
+ requireSameOrigin: true,
277
+ parse: parseMediaGenerate,
278
+ handle: async ({ ownerRef, request }, deps) => {
279
+ let task;
280
+ try {
281
+ task = await deps.taskStore.create({
282
+ id: randomUUID(),
283
+ ownerRef,
284
+ status: 'queued',
285
+ surface: request.surface,
286
+ model: request.model,
287
+ });
288
+ }
289
+ catch (error) {
290
+ return err(reportInternalError(deps, 'media-task-store', error, null, ownerRef));
291
+ }
292
+ void runMediaGenerationInBackground(deps, task.id, ownerRef, request);
293
+ return ok({ task });
294
+ },
295
+ successStatus: 202,
296
+ });
297
+ export const mediaTaskGetRoute = defineJsonRoute({
298
+ method: 'get',
299
+ path: '/api/media/tasks/:id',
300
+ parse: parseTaskId,
301
+ handle: async (id, deps) => {
302
+ try {
303
+ const task = await deps.taskStore.get(id);
304
+ return task === null ? err(createApiError('NOT_FOUND', 'media task not found')) : ok({ task });
305
+ }
306
+ catch (error) {
307
+ return err(reportInternalError(deps, 'media-task-store', error, id, null));
308
+ }
309
+ },
310
+ });
311
+ export const mediaTaskDeleteRoute = defineJsonRoute({
312
+ method: 'delete',
313
+ path: '/api/media/tasks/:id',
314
+ requireSameOrigin: true,
315
+ parse: parseTaskId,
316
+ handle: async (id, deps) => {
317
+ let ownerRef = null;
318
+ try {
319
+ const existing = await deps.taskStore.get(id);
320
+ if (existing === null)
321
+ return err(createApiError('NOT_FOUND', 'media task not found'));
322
+ ownerRef = existing.ownerRef;
323
+ await deps.taskStore.delete(id);
324
+ return ok({ ok: true });
325
+ }
326
+ catch (error) {
327
+ return err(reportInternalError(deps, 'media-task-store', error, id, ownerRef));
328
+ }
329
+ },
330
+ });
331
+ export const mediaTaskListRoute = defineJsonRoute({
332
+ method: 'get',
333
+ path: '/api/media/tasks',
334
+ parse: parseMediaTaskListQuery,
335
+ handle: async ({ ownerRef, options }, deps) => {
336
+ try {
337
+ const tasks = await deps.taskStore.listByOwner(ownerRef, options);
338
+ return ok({ tasks });
339
+ }
340
+ catch (error) {
341
+ return err(reportInternalError(deps, 'media-task-store', error, null, ownerRef));
342
+ }
343
+ },
344
+ });
345
+ /** Mounts every media route on `app`. A pack's `http(app, services)` calls this directly. */
346
+ export function registerMediaRoutes(app, deps, adapter) {
347
+ mountJsonRoute(app, mediaGenerateRoute, deps, adapter);
348
+ mountJsonRoute(app, mediaTaskGetRoute, deps, adapter);
349
+ mountJsonRoute(app, mediaTaskDeleteRoute, deps, adapter);
350
+ mountJsonRoute(app, mediaTaskListRoute, deps, adapter);
351
+ }
352
+ //# sourceMappingURL=media.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"media.js","sourceRoot":"","sources":["../src/media.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,cAAc,EAAuB,MAAM,cAAc,CAAC;AACpF,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,GAAG,EAAE,EAAE,EAAuC,MAAM,YAAY,CAAC;AAkG1E,MAAM,QAAQ,GAA8B,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;AACjF,MAAM,WAAW,GAA2B,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC;AAChF,M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AAkB,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AACzD,CAAC"}
@@ -0,0 +1,230 @@
1
+ /**
2
+ * @module memory
3
+ *
4
+ * Generic memory/notes HTTP surface — thin route wrappers over a
5
+ * frontmatter-backed note store, an extraction-attempt log, and a
6
+ * verify-outcome log, plus a multiplexed SSE change feed. Ported from OD's
7
+ * `apps/daemon/src/routes/memory.ts` (690 lines) — see `source-map.md`'s
8
+ * 2026-07-21 memory-routes section for the full per-route classification.
9
+ *
10
+ * **Deliberately does NOT depend on `@jini-ai/memory`.** That package exists in
11
+ * this repo (`packages/memory/`, `createNoteStore`/`createExtractionLog`/
12
+ * `createVerifyLog` structurally match every collaborator type below field
13
+ * for field), but it is listed in this repo's root `UNLOCKED.md` with
14
+ * `"lockedPackagesMayImport": false` — `@jini-ai/http-kit` is one of
15
+ * `scripts/check-engine-boundaries.ts`'s fourteen locked packages, so
16
+ * importing `@jini-ai/memory` directly would fail `pnpm guard`'s R7 check
17
+ * outright (the same constraint `packages/media/src/sqlite-task-store.ts`'s
18
+ * `ADS-memory/reports/proposals/PROP-media-durable-tasks-2026-07-21.md`
19
+ * documents for `@jini-ai/sqlite`/`@jini-ai/media`). The types below
20
+ * (`MemoryNoteStore`/`MemoryExtractionLog`/`MemoryVerifyLog`) are local,
21
+ * structural mirrors of `@jini-ai/memory`'s real `NoteStore`/`ExtractionLog`/
22
+ * `VerifyLog` interfaces — a real `@jini-ai/memory` instance satisfies them
23
+ * with zero adapter code (this is the same "host supplies the real
24
+ * collaborator" DI convention `daemon-status.ts`/`host-tools.ts`/`db-ops.ts`
25
+ * already established), but this package incurs no dependency on it, locked
26
+ * or not. If/when `@jini-ai/memory` is promoted to `"stable"`, a follow-up can
27
+ * replace these local types with direct imports — a mechanical change, not
28
+ * a redesign, since the shapes already match.
29
+ *
30
+ * **Ported (generic, no OD coupling):** the config `enabled` toggle, entry
31
+ * CRUD (`POST /api/memory`, `GET/PUT/DELETE /api/memory/:id`), the tree
32
+ * view and single-node patch, the raw index text, the extraction/
33
+ * verification history lists + clear/remove, and the multiplexed
34
+ * `change`/`extraction`/`verify` SSE feed.
35
+ *
36
+ * **Explicitly NOT ported (OD-PRODUCT or missing-primitive, see
37
+ * `source-map.md` for the full reasoning per route):**
38
+ * - `POST /api/memory/rules/suggest` — OD's canvas/deck-annotation shape.
39
+ * - `POST /api/memory/connectors/suggest` / `.../connectors/extract` — OD's
40
+ * project-scoped connector-mining pipeline.
41
+ * - `POST /api/memory/extract` — the heuristic-regex pre-turn phase and the
42
+ * BYOK-chat-provider-passthrough LLM post-turn phase are both OD-specific
43
+ * composition, per this repo's root `AGENTS.md`'s existing note that
44
+ * `@jini-ai/memory`'s "heuristic-regex... prompt-composition pieces" were
45
+ * "explicitly left un-ported."
46
+ * - `GET /api/memory/system-prompt` — depends on `composeMemoryBody`, which
47
+ * does not exist anywhere in `@jini-ai/memory` yet (same `AGENTS.md` note).
48
+ * - The four extra `MemoryConfigPatch` boolean toggles
49
+ * (`chatExtractionEnabled`/`profileEnabled`/`rewriteEnabled`/
50
+ * `verifyEnabled`) and the whole `extraction` (LLM-provider) config
51
+ * sub-object: `@jini-ai/memory`'s `NoteStoreOptions` is `{enabled: boolean}`
52
+ * only — a real, documented capability gap in the underlying store, not a
53
+ * route-level scoping choice. A host needing those toggles today has to
54
+ * layer its own config storage alongside `NoteStore.writeConfig`.
55
+ */
56
+ import type { Express } from 'express';
57
+ import { type AdapterContext } from './adapter.js';
58
+ export interface MemoryNoteEntrySummary {
59
+ readonly id: string;
60
+ readonly name: string;
61
+ readonly description: string;
62
+ readonly type: string;
63
+ readonly updatedAt: number;
64
+ }
65
+ export interface MemoryNoteEntry extends MemoryNoteEntrySummary {
66
+ readonly body: string;
67
+ }
68
+ export interface MemoryTreeNode {
69
+ readonly id: string;
70
+ readonly parentId: string | null;
71
+ readonly path: string;
72
+ readonly name: string;
73
+ readonly description: string;
74
+ readonly kind: 'folder' | 'entry';
75
+ readonly type: string;
76
+ readonly createdAt: string;
77
+ readonly updatedAt: string;
78
+ readonly childrenCount: number;
79
+ }
80
+ export interface MemoryNoteStoreOptions {
81
+ readonly enabled: boolean;
82
+ }
83
+ /** Minimal event-emitter surface every collaborator's `events` field needs — satisfied structurally by a real `node:events` `EventEmitter`. */
84
+ export interface MemoryChangeEmitter {
85
+ on(event: string, listener: (event: unknown) => void): unknown;
86
+ off(event: string, listener: (event: unknown) => void): unknown;
87
+ }
88
+ export interface MemoryNoteStore {
89
+ readonly events: MemoryChangeEmitter;
90
+ dir(dataDir: string): string;
91
+ readConfig(dataDir: string): Promise<MemoryNoteStoreOptions>;
92
+ writeConfig(dataDir: string, patch: Partial<MemoryNoteStoreOptions>): Promise<MemoryNoteStoreOptions>;
93
+ readIndex(dataDir: string): Promise<string>;
94
+ writeIndex(dataDir: string, body: string): Promise<void>;
95
+ listEntries(dataDir: string): Promise<readonly MemoryNoteEntrySummary[]>;
96
+ readEntry(dataDir: string, id: string): Promise<MemoryNoteEntry | null>;
97
+ upsertEntry(dataDir: string, input: {
98
+ id?: string;
99
+ name: string;
100
+ description?: string;
101
+ type: string;
102
+ body?: string;
103
+ }): Promise<MemoryNoteEntry>;
104
+ deleteEntry(dataDir: string, id: string): Promise<void>;
105
+ updateTreeNode(dataDir: string, id: string, patch: {
106
+ name?: string;
107
+ description?: string;
108
+ type?: string;
109
+ body?: string;
110
+ }): Promise<MemoryNoteEntry>;
111
+ buildTree(dataDir: string): Promise<readonly MemoryTreeNode[]>;
112
+ }
113
+ export interface MemoryExtractionLog {
114
+ readonly events: MemoryChangeEmitter;
115
+ list(): readonly unknown[];
116
+ remove(id: string): number;
117
+ clear(): number;
118
+ }
119
+ export interface MemoryVerifyLog {
120
+ readonly events: MemoryChangeEmitter;
121
+ list(): readonly unknown[];
122
+ remove(id: string): number;
123
+ clear(): number;
124
+ }
125
+ export interface MemoryHttpDeps {
126
+ readonly notes: MemoryNoteStore;
127
+ readonly extractions: MemoryExtractionLog;
128
+ readonly verifications: MemoryVerifyLog;
129
+ /** Forwarded verbatim to every `MemoryNoteStore`/log call — the same `dataDir` a host passes to its own `createNoteStore`-backed instance. */
130
+ readonly dataDir: string;
131
+ }
132
+ export interface MemoryOverviewResponse {
133
+ readonly enabled: boolean;
134
+ readonly rootDir: string;
135
+ readonly index: string;
136
+ readonly entries: readonly MemoryNoteEntrySummary[];
137
+ }
138
+ export declare const memoryOverviewRoute: import("./types.js").JsonRouteSpec<void, MemoryOverviewResponse, MemoryHttpDeps>;
139
+ export interface MemoryTreeResponse {
140
+ readonly enabled: boolean;
141
+ readonly rootDir: string;
142
+ readonly tree: readonly MemoryTreeNode[];
143
+ }
144
+ export declare const memoryTreeRoute: import("./types.js").JsonRouteSpec<void, MemoryTreeResponse, MemoryHttpDeps>;
145
+ export interface MemoryTreeNodePatch {
146
+ readonly name?: string;
147
+ readonly description?: string;
148
+ readonly type?: string;
149
+ readonly body?: string;
150
+ }
151
+ interface MemoryUpdateTreeNodeInput {
152
+ readonly id: string;
153
+ readonly patch: MemoryTreeNodePatch;
154
+ }
155
+ export interface MemoryUpdateTreeNodeResponse {
156
+ readonly entry: MemoryNoteEntry;
157
+ readonly tree: readonly MemoryTreeNode[];
158
+ }
159
+ export declare const memoryUpdateTreeNodeRoute: import("./types.js").JsonRouteSpec<MemoryUpdateTreeNodeInput, MemoryUpdateTreeNodeResponse, MemoryHttpDeps>;
160
+ export interface MemoryIndexResponse {
161
+ readonly index: string;
162
+ }
163
+ export declare const memoryWriteIndexRoute: import("./types.js").JsonRouteSpec<string, MemoryIndexResponse, MemoryHttpDeps>;
164
+ export interface MemoryConfigResponse {
165
+ readonly enabled: boolean;
166
+ }
167
+ export declare const memoryWriteConfigRoute: import("./types.js").JsonRouteSpec<Partial<MemoryNoteStoreOptions>, MemoryConfigResponse, MemoryHttpDeps>;
168
+ export interface MemoryExtractionsResponse {
169
+ readonly extractions: readonly unknown[];
170
+ }
171
+ export declare const memoryListExtractionsRoute: import("./types.js").JsonRouteSpec<void, MemoryExtractionsResponse, MemoryHttpDeps>;
172
+ export interface MemoryRemovedResponse {
173
+ readonly removed: number;
174
+ }
175
+ export declare const memoryClearExtractionsRoute: import("./types.js").JsonRouteSpec<void, MemoryRemovedResponse, MemoryHttpDeps>;
176
+ export declare const memoryRemoveExtractionRoute: import("./types.js").JsonRouteSpec<string, MemoryRemovedResponse, MemoryHttpDeps>;
177
+ export interface MemoryVerificationsResponse {
178
+ readonly verifications: readonly unknown[];
179
+ }
180
+ export declare const memoryListVerificationsRoute: import("./types.js").JsonRouteSpec<void, MemoryVerificationsResponse, MemoryHttpDeps>;
181
+ export declare const memoryClearVerificationsRoute: import("./types.js").JsonRouteSpec<void, MemoryRemovedResponse, MemoryHttpDeps>;
182
+ export declare const memoryRemoveVerificationRoute: import("./types.js").JsonRouteSpec<string, MemoryRemovedResponse, MemoryHttpDeps>;
183
+ export interface MemoryEntryInput {
184
+ readonly id?: string;
185
+ readonly name: string;
186
+ readonly description?: string;
187
+ readonly type: string;
188
+ readonly body?: string;
189
+ }
190
+ export interface MemoryEntryResponse {
191
+ readonly entry: MemoryNoteEntry;
192
+ }
193
+ export declare const memoryCreateEntryRoute: import("./types.js").JsonRouteSpec<MemoryEntryInput, MemoryEntryResponse, MemoryHttpDeps>;
194
+ export declare const memoryReadEntryRoute: import("./types.js").JsonRouteSpec<string, MemoryEntryResponse, MemoryHttpDeps>;
195
+ interface MemoryUpdateEntryInput {
196
+ readonly id: string;
197
+ readonly input: MemoryEntryInput;
198
+ }
199
+ export declare const memoryUpdateEntryRoute: import("./types.js").JsonRouteSpec<MemoryUpdateEntryInput, MemoryEntryResponse, MemoryHttpDeps>;
200
+ export interface MemoryDeleteEntryResponse {
201
+ readonly ok: true;
202
+ }
203
+ export declare const memoryDeleteEntryRoute: import("./types.js").JsonRouteSpec<string, MemoryDeleteEntryResponse, MemoryHttpDeps>;
204
+ /**
205
+ * `GET /api/memory/events` — one SSE connection multiplexing three channels
206
+ * (matching OD's own reasoning: "so the browser opens one connection instead
207
+ * of two/three"): `connected` (once, on open), `change` (relayed from
208
+ * `deps.notes.events`), `extraction` (relayed from `deps.extractions.events`,
209
+ * whose underlying event name is `'attempt'` — see `@jini-ai/memory`'s
210
+ * `extraction-log.ts`), and `verify` (relayed from `deps.verifications.events`).
211
+ * Uses `sse.ts`'s generic channel rather than OD's bespoke `createSseResponse`;
212
+ * no Last-Event-ID replay (unlike `runs.ts`) since none of the three
213
+ * underlying emitters buffer history for reconnect — this mirrors the OD
214
+ * origin's own behavior (a live tail only, no replay).
215
+ *
216
+ * Bypasses `mountJsonRoute` (raw `app.get`, for the SSE response shape), so it does not get
217
+ * `requireSameOrigin` for free the way the JSON routes below do — the guard is applied here
218
+ * directly, before the SSE channel is opened, so a cross-origin request never gets a stream.
219
+ */
220
+ export declare function registerMemoryEventStream(app: Express, deps: MemoryHttpDeps, adapter: AdapterContext): void;
221
+ /**
222
+ * Mounts every ported memory route. Static sub-resources (`/tree`,
223
+ * `/index`, `/config`, `/events`, `/extractions`, `/verifications`) are
224
+ * mounted BEFORE the `/api/memory/:id` catch-all routes, preserving OD's own
225
+ * ordering discipline ("so an `index`/`config`/`extract` slug can't shadow
226
+ * the real handlers") — Express matches routes in registration order.
227
+ */
228
+ export declare function registerMemoryRoutes(app: Express, deps: MemoryHttpDeps, adapter: AdapterContext): void;
229
+ export {};
230
+ //# sourceMappingURL=memory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,OAAO,KAAK,EAAE,OAAO,EAAqB,MAAM,SAAS,CAAC;AAE1D,OAAO,EAAmC,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAYpF,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,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