@jini-ai/http-kit 0.3.3 → 0.3.6
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.
- package/dist/adapter.d.ts +26 -0
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +36 -0
- package/dist/adapter.js.map +1 -1
- package/dist/agents.d.ts +2 -1
- package/dist/agents.d.ts.map +1 -1
- package/dist/agents.js.map +1 -1
- package/dist/attachments.d.ts +219 -2
- package/dist/attachments.d.ts.map +1 -1
- package/dist/attachments.js +384 -16
- package/dist/attachments.js.map +1 -1
- package/dist/delegated-tools.d.ts +2 -2
- package/dist/delegated-tools.js +2 -2
- package/dist/express/run-stream.d.ts +15 -0
- package/dist/express/run-stream.d.ts.map +1 -0
- package/dist/express/run-stream.js +11 -0
- package/dist/express/run-stream.js.map +1 -0
- package/dist/express-index.d.ts +32 -0
- package/dist/express-index.d.ts.map +1 -0
- package/dist/express-index.js +14 -0
- package/dist/express-index.js.map +1 -0
- package/dist/fastify/adapter.d.ts +31 -0
- package/dist/fastify/adapter.d.ts.map +1 -0
- package/dist/fastify/adapter.js +64 -0
- package/dist/fastify/adapter.js.map +1 -0
- package/dist/fastify/agents.d.ts +13 -0
- package/dist/fastify/agents.d.ts.map +1 -0
- package/dist/fastify/agents.js +7 -0
- package/dist/fastify/agents.js.map +1 -0
- package/dist/fastify/api-security-middleware.d.ts +64 -0
- package/dist/fastify/api-security-middleware.d.ts.map +1 -0
- package/dist/fastify/api-security-middleware.js +139 -0
- package/dist/fastify/api-security-middleware.js.map +1 -0
- package/dist/fastify/compat.d.ts +22 -0
- package/dist/fastify/compat.d.ts.map +1 -0
- package/dist/fastify/compat.js +16 -0
- package/dist/fastify/compat.js.map +1 -0
- package/dist/fastify/daemon-status.d.ts +22 -0
- package/dist/fastify/daemon-status.d.ts.map +1 -0
- package/dist/fastify/daemon-status.js +9 -0
- package/dist/fastify/daemon-status.js.map +1 -0
- package/dist/fastify/host-tools.d.ts +13 -0
- package/dist/fastify/host-tools.d.ts.map +1 -0
- package/dist/fastify/host-tools.js +8 -0
- package/dist/fastify/host-tools.js.map +1 -0
- package/dist/fastify/index.d.ts +36 -0
- package/dist/fastify/index.d.ts.map +1 -0
- package/dist/fastify/index.js +18 -0
- package/dist/fastify/index.js.map +1 -0
- package/dist/fastify/local-daemon-request.d.ts +43 -0
- package/dist/fastify/local-daemon-request.d.ts.map +1 -0
- package/dist/fastify/local-daemon-request.js +155 -0
- package/dist/fastify/local-daemon-request.js.map +1 -0
- package/dist/fastify/origin.d.ts +21 -0
- package/dist/fastify/origin.d.ts.map +1 -0
- package/dist/fastify/origin.js +14 -0
- package/dist/fastify/origin.js.map +1 -0
- package/dist/fastify/request.d.ts +20 -0
- package/dist/fastify/request.d.ts.map +1 -0
- package/dist/fastify/request.js +25 -0
- package/dist/fastify/request.js.map +1 -0
- package/dist/fastify/response.d.ts +20 -0
- package/dist/fastify/response.d.ts.map +1 -0
- package/dist/fastify/response.js +41 -0
- package/dist/fastify/response.js.map +1 -0
- package/dist/fastify/route-registration-guard.d.ts +70 -0
- package/dist/fastify/route-registration-guard.d.ts.map +1 -0
- package/dist/fastify/route-registration-guard.js +69 -0
- package/dist/fastify/route-registration-guard.js.map +1 -0
- package/dist/fastify/run-stream.d.ts +18 -0
- package/dist/fastify/run-stream.d.ts.map +1 -0
- package/dist/fastify/run-stream.js +10 -0
- package/dist/fastify/run-stream.js.map +1 -0
- package/dist/fastify/runs.d.ts +17 -0
- package/dist/fastify/runs.d.ts.map +1 -0
- package/dist/fastify/runs.js +33 -0
- package/dist/fastify/runs.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/run-stream.d.ts +60 -0
- package/dist/run-stream.d.ts.map +1 -0
- package/dist/run-stream.js +108 -0
- package/dist/run-stream.js.map +1 -0
- package/package.json +6 -6
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { handleRunEventStreamRequest, runCancelRoute, runListRoute, runStartRoute, runStatusRoute } from '../runs.js';
|
|
2
|
+
import { mountJsonRoute } from './adapter.js';
|
|
3
|
+
/** Reads a reconnect cursor from the `Last-Event-ID` header, falling back to an `afterCursor` query parameter — the Fastify-request-shaped equivalent of `../sse.js`'s `requestedAfterCursor` (Fastify already parses both `.headers` and `.query` for us, so no Express-`Request`-shaped adapter object is needed here). */
|
|
4
|
+
function requestedAfterCursorFastify(request) {
|
|
5
|
+
const header = request.headers['last-event-id'];
|
|
6
|
+
const headerValue = Array.isArray(header) ? header[0] : header;
|
|
7
|
+
if (headerValue !== undefined && headerValue.length > 0)
|
|
8
|
+
return headerValue;
|
|
9
|
+
const query = request.query?.afterCursor;
|
|
10
|
+
return typeof query === 'string' && query.length > 0 ? query : null;
|
|
11
|
+
}
|
|
12
|
+
/** Mounts `GET /api/runs/:runId/events` on `app` via Fastify's native `route()` (matching `mountJsonRoute`'s own registration mechanism, unlike `fastify/run-stream.ts`'s `.get()` shorthand — kept consistent within this file since `registerRunRoutes` below mounts both through the same `app`), hijacking the reply so `handleRunEventStreamRequest` can write the raw SSE stream directly. */
|
|
13
|
+
export function registerRunEventStream(app, deps) {
|
|
14
|
+
app.route({
|
|
15
|
+
method: 'GET',
|
|
16
|
+
url: '/api/runs/:runId/events',
|
|
17
|
+
exposeHeadRoute: false,
|
|
18
|
+
handler: async (request, reply) => {
|
|
19
|
+
reply.hijack();
|
|
20
|
+
const runId = request.params.runId ?? '';
|
|
21
|
+
await handleRunEventStreamRequest(reply.raw, runId, requestedAfterCursorFastify(request), deps);
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
/** Mounts create/status/cancel JSON endpoints and the SSE event stream as one run transport — the Fastify-native equivalent of `../runs.js`'s `registerRunRoutes`, mounting the identical `JsonRouteSpec` objects. */
|
|
26
|
+
export function registerRunRoutes(app, deps, adapter) {
|
|
27
|
+
mountJsonRoute(app, runStartRoute, deps, adapter);
|
|
28
|
+
mountJsonRoute(app, runListRoute, deps, adapter);
|
|
29
|
+
mountJsonRoute(app, runStatusRoute, deps, adapter);
|
|
30
|
+
mountJsonRoute(app, runCancelRoute, deps, adapter);
|
|
31
|
+
registerRunEventStream(app, deps);
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=runs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runs.js","sourceRoot":"","sources":["../../src/fastify/runs.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,2BAA2B,EAAE,cAAc,EAAE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACtH,OAAO,EAAE,cAAc,EAAuB,MAAM,cAAc,CAAC;AAEnE,6TAA6T;AAC7T,SAAS,2BAA2B,CAAC,OAAuB;IAC1D,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;IAChD,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IAC/D,IAAI,WAAW,KAAK,SAAS,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,WAAW,CAAC;IAC5E,MAAM,KAAK,GAAI,OAAO,CAAC,KAA6C,EAAE,WAAW,CAAC;IAClF,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AACtE,CAAC;AAED,oYAAoY;AACpY,MAAM,UAAU,sBAAsB,CAAC,GAAoB,EAAE,IAAiB;IAC5E,GAAG,CAAC,KAAK,CAAC;QACR,MAAM,EAAE,KAAK;QACb,GAAG,EAAE,yBAAyB;QAC9B,eAAe,EAAE,KAAK;QACtB,OAAO,EAAE,KAAK,EAAE,OAAuB,EAAE,KAAmB,EAAE,EAAE;YAC9D,KAAK,CAAC,MAAM,EAAE,CAAC;YACf,MAAM,KAAK,GAAI,OAAO,CAAC,MAA6B,CAAC,KAAK,IAAI,EAAE,CAAC;YACjE,MAAM,2BAA2B,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,EAAE,2BAA2B,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,CAAC;QAClG,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED,sNAAsN;AACtN,MAAM,UAAU,iBAAiB,CAAC,GAAoB,EAAE,IAAiB,EAAE,OAAuB;IAChG,cAAc,CAAC,GAAG,EAAE,aAAa,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAClD,cAAc,CAAC,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACjD,cAAc,CAAC,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACnD,cAAc,CAAC,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACnD,sBAAsB,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AACpC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export { err, ok } from './types.js';
|
|
|
22
22
|
export type { ParsedHostHeader, RequestWithOriginHeaders, } from './origin-validation.js';
|
|
23
23
|
export { allowedBrowserPorts, assertValidAllowedOrigins, configuredAllowedHosts, configuredAllowedOrigins, isAllowedBrowserHost, isAllowedBrowserOrigin, isIpLiteralHostname, isLoopbackOrPrivateLanHost, isLocalSameOrigin, isPrivateIpv4, parseHostHeader, } from './origin-validation.js';
|
|
24
24
|
export type { AdapterContext } from './adapter.js';
|
|
25
|
-
export { defineJsonRoute, mountJsonRoute } from './adapter.js';
|
|
25
|
+
export { ClientFacingError, defineJsonRoute, mountJsonRoute } from './adapter.js';
|
|
26
26
|
export type { InstallRouteRegistrationGuardOptions, RouteRegistration } from './route-registration-guard.js';
|
|
27
27
|
export { getRouteRegistrationInventory, guardedRouteKey, installRouteRegistrationGuard, } from './route-registration-guard.js';
|
|
28
28
|
export type { CreateSseChannelOptions, SseChannel, SseEvent } from './sse.js';
|
|
@@ -78,7 +78,7 @@ export type { ResearchHttpDeps, ResearchInternalErrorContext, ResearchProviderCr
|
|
|
78
78
|
export { registerResearchRoutes, researchSearchRoute } from './research.js';
|
|
79
79
|
export type { MediaGenerateResponse, MediaHttpDeps, MediaInternalErrorContext, MediaTaskDeleteResponse, MediaTaskListResponse, MediaTaskResponse, } from './media.js';
|
|
80
80
|
export { mediaGenerateRoute, mediaTaskDeleteRoute, mediaTaskGetRoute, mediaTaskListRoute, registerMediaRoutes, } from './media.js';
|
|
81
|
-
export type { AttachmentClaim, AttachmentRejectionReason, AttachmentsHttpDeps, AttachmentsInternalErrorContext, AttachmentStore, AttachmentUploadResponse, CreateDiskAttachmentStoreOptions, ObservedAttachmentIdentity, RecordedAttachmentIdentity, StoredAttachment, } from './attachments.js';
|
|
81
|
+
export type { AttachmentClaim, AttachmentRejectionReason, AttachmentsHttpDeps, AttachmentsInternalErrorContext, AttachmentStore, AttachmentUploadResponse, CreateDiskAttachmentStoreOptions, ObservedAttachmentIdentity, PendingAttachmentSummary, RecordedAttachmentIdentity, StoredAttachment, } from './attachments.js';
|
|
82
82
|
export { ATTACHMENTS_ROUTE_PATH, AttachmentRejectedError, createDiskAttachmentStore, detectAttachmentKind, handleAttachmentCleanup, handleAttachmentUpload, isUnchangedAttachment, registerAttachmentRoutes, sanitizeAttachmentName, writeBoundedAttachmentBody, } from './attachments.js';
|
|
83
83
|
export type { XaiAuthStatusResponse, XaiHttpDeps, XaiInternalErrorContext, XaiOauthStartResponse, XaiOkResponse, XaiSearchResponse, } from './xai.js';
|
|
84
84
|
export { registerXaiRoutes, xaiAuthStatusRoute, xaiOauthCancelRoute, xaiOauthCompleteRoute, xaiOauthDisconnectRoute, xaiOauthStartRoute, xaiSearchRoute, } from './xai.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,YAAY,EACV,OAAO,EACP,UAAU,EACV,WAAW,EACX,aAAa,EACb,MAAM,EACN,iBAAiB,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAErC,YAAY,EACV,gBAAgB,EAChB,wBAAwB,GACzB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,mBAAmB,EACnB,yBAAyB,EACzB,sBAAsB,EACtB,wBAAwB,EACxB,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,EACnB,0BAA0B,EAC1B,iBAAiB,EACjB,aAAa,EACb,eAAe,GAChB,MAAM,wBAAwB,CAAC;AAEhC,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,YAAY,EACV,OAAO,EACP,UAAU,EACV,WAAW,EACX,aAAa,EACb,MAAM,EACN,iBAAiB,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAErC,YAAY,EACV,gBAAgB,EAChB,wBAAwB,GACzB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,mBAAmB,EACnB,yBAAyB,EACzB,sBAAsB,EACtB,wBAAwB,EACxB,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,EACnB,0BAA0B,EAC1B,iBAAiB,EACjB,aAAa,EACb,eAAe,GAChB,MAAM,wBAAwB,CAAC;AAEhC,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAA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3B,sBAAsB,EACtB,cAAc,GACf,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAE5E,YAAY,EACV,qBAAqB,EACrB,aAAa,EACb,yBAAyB,EACzB,uBAAuB,EACvB,qBAAqB,EACrB,iBAAiB,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,eAAe,EACf,yBAAyB,EACzB,mBAAmB,EACnB,+BAA+B,EAC/B,eAAe,EACf,wBAAwB,EACxB,gCAAgC,EAChC,0BAA0B,EAC1B,wBAAwB,EACxB,0BAA0B,EAC1B,gBAAgB,GACjB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,yBAAyB,EACzB,oBAAoB,EACpB,uBAAuB,EACvB,sBAAsB,EACtB,qBAAqB,EACrB,wBAAwB,EACxB,sBAAsB,EACtB,0BAA0B,GAC3B,MAAM,kBAAkB,CAAC;AAE1B,YAAY,EACV,qBAAqB,EACrB,WAAW,EACX,uBAAuB,EACvB,qBAAqB,EACrB,aAAa,EACb,iBAAiB,GAClB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,uBAAuB,EACvB,kBAAkB,EAClB,cAAc,GACf,MAAM,UAAU,CAAC;AAMlB,OAAO,EACL,oBAAoB,EACpB,4BAA4B,EAC5B,YAAY,IAAI,kBAAkB,GACnC,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { err, ok } from './types.js';
|
|
2
2
|
export { allowedBrowserPorts, assertValidAllowedOrigins, configuredAllowedHosts, configuredAllowedOrigins, isAllowedBrowserHost, isAllowedBrowserOrigin, isIpLiteralHostname, isLoopbackOrPrivateLanHost, isLocalSameOrigin, isPrivateIpv4, parseHostHeader, } from './origin-validation.js';
|
|
3
|
-
export { defineJsonRoute, mountJsonRoute } from './adapter.js';
|
|
3
|
+
export { ClientFacingError, defineJsonRoute, mountJsonRoute } from './adapter.js';
|
|
4
4
|
export { getRouteRegistrationInventory, guardedRouteKey, installRouteRegistrationGuard, } from './route-registration-guard.js';
|
|
5
5
|
export { createSseChannel, DEFAULT_MAX_QUEUED_SSE_EVENTS, requestedAfterCursor, sendRawApiError } from './sse.js';
|
|
6
6
|
export { createSseResponse } from './raw-sse.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA2BA,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAMrC,OAAO,EACL,mBAAmB,EACnB,yBAAyB,EACzB,sBAAsB,EACtB,wBAAwB,EACxB,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,EACnB,0BAA0B,EAC1B,iBAAiB,EACjB,aAAa,EACb,eAAe,GAChB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA2BA,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAMrC,OAAO,EACL,mBAAmB,EACnB,yBAAyB,EACzB,sBAAsB,EACtB,wBAAwB,EACxB,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,EACnB,0BAA0B,EAC1B,iBAAiB,EACjB,aAAa,EACb,eAAe,GAChB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAGlF,OAAO,EACL,6BA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AkB,GACnC,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module run-stream
|
|
3
|
+
*
|
|
4
|
+
* An encoder-driven SSE run-stream route: subscribes to a run via `@jini-ai/daemon`'s
|
|
5
|
+
* `RunLifecycle.stream`, pipes every event through a composition-root-supplied protocol encoder,
|
|
6
|
+
* and writes each non-null event to the SSE response opened by `createSseResponse`.
|
|
7
|
+
* `handleRunStreamRequest` is the core
|
|
8
|
+
* — it only ever touches `node:http`'s `IncomingMessage`/`ServerResponse` — and
|
|
9
|
+
* `registerRunStreamRoute` below is Express's own thin mounting glue (Express's `Request`/
|
|
10
|
+
* `Response` already *are* Node's raw `http.IncomingMessage`/`http.ServerResponse`, so resolving
|
|
11
|
+
* `req.params.runId` and handing the request/response straight through is the whole job).
|
|
12
|
+
*/
|
|
13
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
14
|
+
import type { RunLifecycle } from '@jini-ai/daemon';
|
|
15
|
+
import type { RunProtocolEvent } from '@jini-ai/protocol';
|
|
16
|
+
import type { Express } from 'express';
|
|
17
|
+
/** Backward-compatible route path used by the AG-UI composition. The handler itself is encoder-agnostic. */
|
|
18
|
+
export declare const RUN_STREAM_ROUTE_PATH = "/api/runs/:runId/agui-stream";
|
|
19
|
+
export interface RunStreamEncoder {
|
|
20
|
+
encode(event: RunProtocolEvent, context: {
|
|
21
|
+
readonly runId: string;
|
|
22
|
+
}): unknown | null;
|
|
23
|
+
}
|
|
24
|
+
export interface RunStreamInternalErrorContext {
|
|
25
|
+
readonly source: 'encoder' | 'lifecycle' | 'route';
|
|
26
|
+
readonly runId: string;
|
|
27
|
+
readonly error: unknown;
|
|
28
|
+
}
|
|
29
|
+
export interface RunStreamDeps {
|
|
30
|
+
readonly lifecycle: RunLifecycle;
|
|
31
|
+
/** Protocol adapter supplied by the composition root (for example `createGenUiEncoder()`). */
|
|
32
|
+
readonly encoder: RunStreamEncoder;
|
|
33
|
+
/** Host-owned sink for failures that must not escape an async Express handler. Defaults to `console.error`. */
|
|
34
|
+
readonly onInternalError?: (context: RunStreamInternalErrorContext) => void;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Handles one encoded SSE run-stream request end to end. Opens the SSE connection immediately (an
|
|
38
|
+
* SSE endpoint commits to `text/event-stream` headers before it can know whether `runId` is
|
|
39
|
+
* valid), then subscribes to the run: a replay-then-live-subscribe `unknown-run`/`replay-gap`/
|
|
40
|
+
* `invalid-cursor` result is reported as one `{ error }` SSE data event before closing (there is
|
|
41
|
+
* no JSON-status-code channel left once SSE headers are already committed). On the happy path,
|
|
42
|
+
* every event `RunLifecycle` delivers is encoded and forwarded; the connection closes itself once
|
|
43
|
+
* the run's own terminal `'end'` event has been forwarded (a driver's contract with
|
|
44
|
+
* `RunLifecycle` guarantees no further events follow a run's `'end')`, so nothing is lost by
|
|
45
|
+
* closing right after it). If the client disconnects first, `createSseResponse`'s own
|
|
46
|
+
* `req.on('close', ...)` fires first, which (via `onClose` here) unsubscribes from the run so a
|
|
47
|
+
* disconnected client never leaves a dangling `RunLifecycle` subscriber.
|
|
48
|
+
*
|
|
49
|
+
* @param req - The raw request `createSseResponse` opens the stream against.
|
|
50
|
+
* @param res - The raw response `createSseResponse` opens the stream against.
|
|
51
|
+
* @param runId - The run to stream, already resolved by the caller's transport-specific glue.
|
|
52
|
+
* @param deps.lifecycle - The `RunLifecycle` to subscribe to.
|
|
53
|
+
* @param deps.encoder - The protocol adapter chosen by the composition root.
|
|
54
|
+
* @complexity O(1) plus the supplied encoder's per-event cost and `RunLifecycle.stream`'s replay cost.
|
|
55
|
+
* @overallScore 100/100
|
|
56
|
+
*/
|
|
57
|
+
export declare function handleRunStreamRequest(req: IncomingMessage, res: ServerResponse, runId: string, deps: RunStreamDeps): Promise<void>;
|
|
58
|
+
/** Mounts the encoder-driven SSE run-stream route on `app`. */
|
|
59
|
+
export declare function registerRunStreamRoute(app: Express, deps: RunStreamDeps): void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AAI,CAAC,CAuCf;AAED,+DAA+D;AAC/D,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,aAAa,GAAG,IAAI,CAiB9E"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { createSseResponse } from './raw-sse.js';
|
|
2
|
+
/** Backward-compatible route path used by the AG-UI composition. The handler itself is encoder-agnostic. */
|
|
3
|
+
export const RUN_STREAM_ROUTE_PATH = '/api/runs/:runId/agui-stream';
|
|
4
|
+
function reportRunStreamInternalError(deps, source, runId, error) {
|
|
5
|
+
const context = { source, runId, error };
|
|
6
|
+
try {
|
|
7
|
+
if (deps.onInternalError) {
|
|
8
|
+
deps.onInternalError(context);
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
// eslint-disable-next-line no-console
|
|
12
|
+
console.error(`[@jini-ai/http-kit] internal error (run-stream:${source}, runId=${runId})`, error);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
catch (sinkError) {
|
|
16
|
+
// A diagnostic sink must never turn an already-contained stream failure into an unhandled
|
|
17
|
+
// rejection of its own.
|
|
18
|
+
// eslint-disable-next-line no-console
|
|
19
|
+
console.error(`[@jini-ai/http-kit] internal error sink failed (run-stream:${source}, runId=${runId})`, sinkError);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Handles one encoded SSE run-stream request end to end. Opens the SSE connection immediately (an
|
|
24
|
+
* SSE endpoint commits to `text/event-stream` headers before it can know whether `runId` is
|
|
25
|
+
* valid), then subscribes to the run: a replay-then-live-subscribe `unknown-run`/`replay-gap`/
|
|
26
|
+
* `invalid-cursor` result is reported as one `{ error }` SSE data event before closing (there is
|
|
27
|
+
* no JSON-status-code channel left once SSE headers are already committed). On the happy path,
|
|
28
|
+
* every event `RunLifecycle` delivers is encoded and forwarded; the connection closes itself once
|
|
29
|
+
* the run's own terminal `'end'` event has been forwarded (a driver's contract with
|
|
30
|
+
* `RunLifecycle` guarantees no further events follow a run's `'end')`, so nothing is lost by
|
|
31
|
+
* closing right after it). If the client disconnects first, `createSseResponse`'s own
|
|
32
|
+
* `req.on('close', ...)` fires first, which (via `onClose` here) unsubscribes from the run so a
|
|
33
|
+
* disconnected client never leaves a dangling `RunLifecycle` subscriber.
|
|
34
|
+
*
|
|
35
|
+
* @param req - The raw request `createSseResponse` opens the stream against.
|
|
36
|
+
* @param res - The raw response `createSseResponse` opens the stream against.
|
|
37
|
+
* @param runId - The run to stream, already resolved by the caller's transport-specific glue.
|
|
38
|
+
* @param deps.lifecycle - The `RunLifecycle` to subscribe to.
|
|
39
|
+
* @param deps.encoder - The protocol adapter chosen by the composition root.
|
|
40
|
+
* @complexity O(1) plus the supplied encoder's per-event cost and `RunLifecycle.stream`'s replay cost.
|
|
41
|
+
* @overallScore 100/100
|
|
42
|
+
*/
|
|
43
|
+
export async function handleRunStreamRequest(req, res, runId, deps) {
|
|
44
|
+
let unsubscribe;
|
|
45
|
+
const connection = createSseResponse(req, res, {
|
|
46
|
+
onClose: () => unsubscribe?.(),
|
|
47
|
+
});
|
|
48
|
+
const encoder = deps.encoder;
|
|
49
|
+
let result;
|
|
50
|
+
try {
|
|
51
|
+
result = await deps.lifecycle.stream(runId, (event) => {
|
|
52
|
+
if (connection.closed)
|
|
53
|
+
return;
|
|
54
|
+
try {
|
|
55
|
+
const encoded = encoder.encode(event, { runId });
|
|
56
|
+
if (encoded != null)
|
|
57
|
+
connection.send(encoded);
|
|
58
|
+
if (event.kind === 'end')
|
|
59
|
+
connection.close();
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
reportRunStreamInternalError(deps, 'encoder', runId, error);
|
|
63
|
+
connection.close();
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
reportRunStreamInternalError(deps, 'lifecycle', runId, error);
|
|
69
|
+
connection.close();
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (result.kind !== 'ok') {
|
|
73
|
+
connection.send({ error: result.kind });
|
|
74
|
+
connection.close();
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
// Assigned even when the run was already terminal (in which case the driver-facing 'end' event
|
|
78
|
+
// was already replayed synchronously above, already closing the connection, and `unsubscribe`
|
|
79
|
+
// here is `RunLifecycle`'s own no-op stub for that case) — keeping this assignment unconditional
|
|
80
|
+
// avoids a branch whose two arms would otherwise do the same thing.
|
|
81
|
+
unsubscribe = result.unsubscribe;
|
|
82
|
+
// The raw request can close while RunLifecycle is still awaiting durable replay. In that
|
|
83
|
+
// window `onClose` runs before `unsubscribe` exists, so clean up immediately once it arrives.
|
|
84
|
+
if (connection.closed)
|
|
85
|
+
unsubscribe();
|
|
86
|
+
}
|
|
87
|
+
/** Mounts the encoder-driven SSE run-stream route on `app`. */
|
|
88
|
+
export function registerRunStreamRoute(app, deps) {
|
|
89
|
+
app.get(RUN_STREAM_ROUTE_PATH, async (req, res) => {
|
|
90
|
+
// `:runId` is a required path segment of RUN_STREAM_ROUTE_PATH — this handler is only ever
|
|
91
|
+
// reached via a URL that already matched it, so the param is always present at runtime even
|
|
92
|
+
// though @types/express types every param as possibly `undefined` in general.
|
|
93
|
+
const runId = req.params.runId;
|
|
94
|
+
try {
|
|
95
|
+
await handleRunStreamRequest(req, res, runId, deps);
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
reportRunStreamInternalError(deps, 'route', runId, error);
|
|
99
|
+
if (!res.headersSent) {
|
|
100
|
+
res.status(500).json({ error: { code: 'INTERNAL_ERROR', message: 'an internal error occurred' } });
|
|
101
|
+
}
|
|
102
|
+
else if (!res.writableEnded) {
|
|
103
|
+
res.end();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=run-stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-stream.js","sourceRoot":"","sources":["../src/run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5F,8EAA8E;QAC9E,MAAM,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC,KAAM,CAAC;QAChC,IAAI,CAAC;YACH,MAAM,sBAAsB,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QACtD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,4BAA4B,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;YAC1D,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;gBACrB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAE,4BAA4B,EAAE,EAAE,CAAC,CAAC;YACrG,CAAC;iBAAM,IAAI,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC;gBAC9B,GAAG,CAAC,GAAG,EAAE,CAAC;YACZ,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jini-ai/http-kit",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
4
4
|
"description": "Composable Express route packs and JSON-route transport for a @jini-ai/core daemon composition: request parsing, response serialization, same-origin guard, and a route-pack registrar.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -38,16 +38,16 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"express": "^4.21.0",
|
|
41
|
-
"@jini-ai/agent-runtime": "0.3.
|
|
42
|
-
"@jini-ai/daemon": "0.3.2",
|
|
43
|
-
"@jini-ai/protocol": "0.3.1",
|
|
41
|
+
"@jini-ai/agent-runtime": "0.3.6",
|
|
44
42
|
"@jini-ai/core": "0.3.1",
|
|
45
|
-
"@jini-ai/
|
|
43
|
+
"@jini-ai/daemon": "0.3.6",
|
|
44
|
+
"@jini-ai/platform": "0.3.0",
|
|
45
|
+
"@jini-ai/protocol": "0.3.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@types/express": "^4.17.21",
|
|
49
49
|
"@vitest/coverage-v8": "^2.1.9",
|
|
50
|
-
"@jini-ai/chat": "0.3.
|
|
50
|
+
"@jini-ai/chat": "0.3.6"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
53
|
"build": "tsc -p tsconfig.json",
|