@jini-ai/http-kit 0.7.2 → 0.7.3-next.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 (124) hide show
  1. package/CHANGELOG.md +2 -10
  2. package/README.md +6 -6
  3. package/dist/adapter.d.ts +7 -50
  4. package/dist/adapter.js +12 -54
  5. package/dist/api-security-middleware.d.ts +0 -16
  6. package/dist/api-security-middleware.js +2 -18
  7. package/dist/index.d.ts +10 -15
  8. package/dist/index.js +7 -10
  9. package/dist/internal-error.d.ts +42 -0
  10. package/dist/internal-error.js +48 -0
  11. package/dist/local-daemon-request.d.ts +11 -4
  12. package/dist/local-daemon-request.js +1 -28
  13. package/dist/middleware.d.ts +1 -0
  14. package/dist/middleware.js +1 -0
  15. package/dist/node-bridge.d.ts +108 -0
  16. package/dist/node-bridge.js +356 -0
  17. package/dist/observability.d.ts +3 -14
  18. package/dist/origin.d.ts +13 -30
  19. package/dist/origin.js +13 -13
  20. package/dist/range.d.ts +53 -0
  21. package/dist/range.js +93 -0
  22. package/dist/rate-limit.d.ts +1 -13
  23. package/dist/rate-limit.js +5 -2
  24. package/dist/request.d.ts +2 -13
  25. package/dist/request.js +0 -13
  26. package/dist/response.d.ts +8 -7
  27. package/dist/response.js +0 -36
  28. package/dist/route-registration-guard.d.ts +14 -0
  29. package/dist/route-registration-guard.js +17 -0
  30. package/dist/run-credentials.d.ts +73 -0
  31. package/dist/run-credentials.js +71 -0
  32. package/dist/settings/contracts.d.ts +49 -0
  33. package/dist/settings/contracts.js +2 -0
  34. package/dist/settings/http-request.d.ts +36 -0
  35. package/dist/settings/http-request.js +50 -0
  36. package/dist/settings/http.d.ts +10 -0
  37. package/dist/settings/http.js +216 -0
  38. package/dist/settings/index.d.ts +4 -0
  39. package/dist/settings/index.js +3 -0
  40. package/dist/settings/shared.d.ts +16 -0
  41. package/dist/settings/shared.js +16 -0
  42. package/dist/settings/stream.d.ts +25 -0
  43. package/dist/settings/stream.js +180 -0
  44. package/dist/sse.d.ts +1 -15
  45. package/dist/sse.js +77 -72
  46. package/dist/trust-proxy.d.ts +36 -0
  47. package/dist/trust-proxy.js +45 -0
  48. package/dist/types.d.ts +4 -52
  49. package/dist/types.js +1 -4
  50. package/package.json +24 -14
  51. package/dist/active-context.d.ts +0 -99
  52. package/dist/active-context.js +0 -77
  53. package/dist/agents.d.ts +0 -64
  54. package/dist/agents.js +0 -23
  55. package/dist/attachments.d.ts +0 -534
  56. package/dist/attachments.js +0 -1032
  57. package/dist/cancel-owned-runs.d.ts +0 -44
  58. package/dist/cancel-owned-runs.js +0 -35
  59. package/dist/component-catalog.d.ts +0 -74
  60. package/dist/component-catalog.js +0 -74
  61. package/dist/connectors.d.ts +0 -165
  62. package/dist/connectors.js +0 -474
  63. package/dist/daemon-status.d.ts +0 -72
  64. package/dist/daemon-status.js +0 -60
  65. package/dist/db-ops.d.ts +0 -116
  66. package/dist/db-ops.js +0 -191
  67. package/dist/delegated-tools.d.ts +0 -146
  68. package/dist/delegated-tools.js +0 -286
  69. package/dist/frontend-control.d.ts +0 -131
  70. package/dist/frontend-control.js +0 -77
  71. package/dist/frontend-sessions.d.ts +0 -100
  72. package/dist/frontend-sessions.js +0 -180
  73. package/dist/health.d.ts +0 -91
  74. package/dist/health.js +0 -53
  75. package/dist/host-tools.d.ts +0 -174
  76. package/dist/host-tools.js +0 -338
  77. package/dist/media.d.ts +0 -131
  78. package/dist/media.js +0 -352
  79. package/dist/memory.d.ts +0 -230
  80. package/dist/memory.js +0 -331
  81. package/dist/model-proxy.d.ts +0 -45
  82. package/dist/model-proxy.js +0 -619
  83. package/dist/origin-validation.d.ts +0 -64
  84. package/dist/origin-validation.js +0 -226
  85. package/dist/raw-sse.d.ts +0 -49
  86. package/dist/raw-sse.js +0 -92
  87. package/dist/read-only-tools.d.ts +0 -67
  88. package/dist/read-only-tools.js +0 -59
  89. package/dist/remote-run-events.d.ts +0 -66
  90. package/dist/remote-run-events.js +0 -230
  91. package/dist/research.d.ts +0 -42
  92. package/dist/research.js +0 -316
  93. package/dist/route-manifest.d.ts +0 -31
  94. package/dist/route-manifest.js +0 -103
  95. package/dist/routines.d.ts +0 -114
  96. package/dist/routines.js +0 -320
  97. package/dist/runs.d.ts +0 -79
  98. package/dist/runs.js +0 -232
  99. package/dist/terminals.d.ts +0 -125
  100. package/dist/terminals.js +0 -349
  101. package/dist/tool-catalog.d.ts +0 -68
  102. package/dist/tool-catalog.js +0 -68
  103. package/dist/verified-origin/configured-origin.d.ts +0 -37
  104. package/dist/verified-origin/configured-origin.js +0 -99
  105. package/dist/verified-origin/index.d.ts +0 -7
  106. package/dist/verified-origin/index.js +0 -6
  107. package/dist/verified-origin/loopback-host.d.ts +0 -9
  108. package/dist/verified-origin/loopback-host.js +0 -17
  109. package/dist/verified-origin/origin.d.ts +0 -64
  110. package/dist/verified-origin/origin.js +0 -162
  111. package/dist/verified-origin/ports.d.ts +0 -38
  112. package/dist/verified-origin/ports.js +0 -2
  113. package/dist/verified-origin/repo.memory.d.ts +0 -32
  114. package/dist/verified-origin/repo.memory.js +0 -34
  115. package/dist/verified-origin/site-path.d.ts +0 -113
  116. package/dist/verified-origin/site-path.js +0 -188
  117. package/dist/verified-origin/types.d.ts +0 -33
  118. package/dist/verified-origin/types.js +0 -30
  119. package/dist/verified-origin.d.ts +0 -2
  120. package/dist/verified-origin.js +0 -2
  121. package/dist/workspace-root.d.ts +0 -69
  122. package/dist/workspace-root.js +0 -63
  123. package/dist/xai.d.ts +0 -86
  124. package/dist/xai.js +0 -668
package/dist/runs.js DELETED
@@ -1,232 +0,0 @@
1
- /**
2
- * Generic HTTP/SSE projection of the kernel RunLifecycle. The routes own no
3
- * agent, tool, or product vocabulary: a host optionally supplies `onStarted`
4
- * to attach its chosen driver after the lifecycle has durably recorded start.
5
- */
6
- import { randomUUID } from 'node:crypto';
7
- import { createApiError } from '@jini-ai/protocol';
8
- import { defineJsonRoute, mountJsonRoute } from './adapter.js';
9
- import { validationError } from './request.js';
10
- import { sendApiError } from './response.js';
11
- import { createSseChannel, requestedAfterCursor, sendRawApiError } from './sse.js';
12
- import { err, ok } from './types.js';
13
- /** Default sink when a host does not supply `onInternalError`: still observable, never silent. */
14
- function defaultInternalErrorSink(context) {
15
- // eslint-disable-next-line no-console
16
- console.error(`[@jini-ai/http-kit] internal error (${context.source}, correlationId=${context.correlationId})`, context.error);
17
- }
18
- /**
19
- * Logs the real failure server-side and returns the generic, correlation-id-bearing public error
20
- * (SEC-005: never the raw exception). `runId` is mandatory — both real call sites (`run-start`,
21
- * after a durably-created run's id is already known; `run-stream`, against an already-parsed path
22
- * parameter) always have one in hand, so an optional field with an unreachable "no runId" branch
23
- * was speculative flexibility no caller ever exercised.
24
- */
25
- function reportInternalError(deps, source, error, runId) {
26
- const correlationId = randomUUID();
27
- const sink = deps.onInternalError ?? defaultInternalErrorSink;
28
- sink({ source, runId, correlationId, error });
29
- return createApiError('INTERNAL_ERROR', 'an internal error occurred', { requestId: correlationId });
30
- }
31
- function isRecord(value) {
32
- return typeof value === 'object' && value !== null && !Array.isArray(value);
33
- }
34
- function optionalString(body, key) {
35
- const value = body[key];
36
- if (value === undefined)
37
- return undefined;
38
- return typeof value === 'string' && value.trim().length > 0 ? value : null;
39
- }
40
- function parseRunCreate(input) {
41
- if (!isRecord(input.body))
42
- return err(validationError('body must be a JSON object'));
43
- const contextRef = optionalString(input.body, 'contextRef');
44
- if (contextRef === undefined || contextRef === null) {
45
- return err(validationError('contextRef must be a non-empty string', [{ path: 'contextRef', message: 'required non-empty string' }]));
46
- }
47
- const agentId = optionalString(input.body, 'agentId');
48
- const idempotencyKey = optionalString(input.body, 'idempotencyKey');
49
- if (agentId === null || idempotencyKey === null) {
50
- return err(validationError('optional string fields must be non-empty when provided'));
51
- }
52
- return ok({
53
- contextRef,
54
- ...(agentId === undefined ? {} : { agentId }),
55
- ...(idempotencyKey === undefined ? {} : { idempotencyKey }),
56
- });
57
- }
58
- function parseRunList(input) {
59
- const value = input.query.contextRef;
60
- if (value === undefined)
61
- return ok({});
62
- if (typeof value !== 'string' || value.length === 0) {
63
- return err(validationError('contextRef must be a non-empty string when provided', [{ path: 'contextRef', message: 'non-empty string when provided' }]));
64
- }
65
- return ok({ contextRef: value });
66
- }
67
- function parseRunId(input) {
68
- const runId = input.params.runId;
69
- return typeof runId === 'string' && runId.length > 0
70
- ? ok(runId)
71
- : err(validationError('runId must be a non-empty path parameter'));
72
- }
73
- function parseRunCancel(input) {
74
- const parsedRunId = parseRunId(input);
75
- if (!parsedRunId.ok)
76
- return parsedRunId;
77
- if (input.body === undefined || input.body === null)
78
- return ok({ runId: parsedRunId.value });
79
- if (!isRecord(input.body))
80
- return err(validationError('body must be a JSON object when provided'));
81
- const reason = optionalString(input.body, 'reason');
82
- if (reason === null)
83
- return err(validationError('reason must be a non-empty string when provided'));
84
- return ok({ runId: parsedRunId.value, ...(reason === undefined ? {} : { reason }) });
85
- }
86
- export const runStartRoute = defineJsonRoute({
87
- method: 'post',
88
- path: '/api/runs',
89
- requireSameOrigin: true,
90
- parse: parseRunCreate,
91
- handle: async (input, deps) => {
92
- const startInput = input;
93
- const started = await deps.lifecycle.start(startInput);
94
- if (started.started && deps.onStarted) {
95
- try {
96
- await deps.onStarted({ request: input, run: started.run, lifecycle: deps.lifecycle });
97
- }
98
- catch (error) {
99
- await deps.lifecycle.finish({ runId: started.run.id, status: 'failed', code: null, signal: null, resumable: false });
100
- return err(reportInternalError(deps, 'run-start', error, started.run.id));
101
- }
102
- }
103
- // A host-owned driver may finish immediately (for example, a single-step
104
- // run). Return the lifecycle's current view rather than the snapshot
105
- // captured before invoking that driver.
106
- const run = (await deps.lifecycle.get(started.run.id)) ?? started.run;
107
- return ok({ run, started: started.started });
108
- },
109
- successStatus: 201,
110
- });
111
- /** `GET /api/runs` — lists runs, optionally scoped to a `contextRef` query parameter. */
112
- export const runListRoute = defineJsonRoute({
113
- method: 'get',
114
- path: '/api/runs',
115
- parse: parseRunList,
116
- handle: async (input, deps) => ok({ runs: await deps.lifecycle.list(input.contextRef) }),
117
- });
118
- export const runStatusRoute = defineJsonRoute({
119
- method: 'get',
120
- path: '/api/runs/:runId',
121
- parse: parseRunId,
122
- handle: async (runId, deps) => {
123
- const run = await deps.lifecycle.get(runId);
124
- return run === undefined ? err(createApiError('NOT_FOUND', `run "${runId}" was not found`)) : ok({ run });
125
- },
126
- });
127
- export const runCancelRoute = defineJsonRoute({
128
- method: 'post',
129
- path: '/api/runs/:runId/cancel',
130
- requireSameOrigin: true,
131
- parse: parseRunCancel,
132
- handle: async (input, deps) => {
133
- const run = await deps.lifecycle.get(input.runId);
134
- if (run === undefined)
135
- return err(createApiError('NOT_FOUND', `run "${input.runId}" was not found`));
136
- return ok({ run: await deps.lifecycle.cancel(input) });
137
- },
138
- });
139
- function sendStreamFailure(res, kind) {
140
- if (kind.kind === 'unknown-run') {
141
- sendRawApiError(res, 404, createApiError('NOT_FOUND', 'run was not found'));
142
- return;
143
- }
144
- if (kind.kind === 'invalid-cursor') {
145
- sendRawApiError(res, 400, createApiError('BAD_REQUEST', `invalid replay cursor "${kind.requestedCursor}"`));
146
- return;
147
- }
148
- sendRawApiError(res, 409, createApiError('CONFLICT', `replay gap after cursor "${kind.requestedCursor}"`, {
149
- details: { oldestAvailableCursor: kind.oldestAvailableCursor },
150
- }));
151
- }
152
- /**
153
- * The core of `GET /api/runs/:runId/events` — canonical events as SSE, with Last-Event-ID
154
- * reconnect support. Takes `runId`/`afterCursor` already resolved by the caller. `res` is typed
155
- * against the raw `node:http` `ServerResponse` rather than Express's own `Response` type — Express's
156
- * `Response` extends it directly, so this is a no-op widening, the same pattern `run-stream.ts`'s
157
- * AG-UI handler already established.
158
- */
159
- export async function handleRunEventStreamRequest(res, runId, afterCursor, deps) {
160
- if (runId.length === 0) {
161
- sendRawApiError(res, 400, createApiError('BAD_REQUEST', 'runId must be a non-empty path parameter'));
162
- return;
163
- }
164
- // `createSseChannel` (`sse.ts`) owns the bounded queue, backpressure, and client-disconnect
165
- // handling that used to be inlined here — see that module's doc for the generalization.
166
- const channel = createSseChannel(res, { isEndEvent: (event) => event.kind === 'end' });
167
- let unsubscribeFn = null;
168
- channel.onClose(() => {
169
- const stop = unsubscribeFn;
170
- unsubscribeFn = null;
171
- stop?.();
172
- });
173
- try {
174
- const subscribed = await deps.lifecycle.stream(runId, channel.enqueue, { afterCursor });
175
- if (subscribed.kind !== 'ok') {
176
- // Nothing was ever subscribed, so `abandon()` has nothing to unsubscribe — it only marks
177
- // the channel closed. `res` itself is untouched, leaving `sendStreamFailure` free to send
178
- // a normal JSON error response instead of an SSE stream.
179
- channel.abandon();
180
- sendStreamFailure(res, subscribed);
181
- return;
182
- }
183
- if (channel.isClosed()) {
184
- // The client already disconnected (or the bounded queue already gave up) while
185
- // `stream()` was resolving — unsubscribe immediately instead of leaking it.
186
- subscribed.unsubscribe();
187
- return;
188
- }
189
- unsubscribeFn = subscribed.unsubscribe;
190
- channel.open();
191
- }
192
- catch (error) {
193
- if (!res.headersSent) {
194
- // `channel.open()` never ran (or never got past `flushHeaders`) — abandon without
195
- // touching `res`, so the JSON error response below is the only thing written.
196
- // Using `channel.end()` here instead would end the response before this write, turning
197
- // it into a write-after-end failure.
198
- channel.abandon();
199
- sendRawApiError(res, 500, reportInternalError(deps, 'run-stream', error, runId));
200
- return;
201
- }
202
- // Headers were already sent (the stream had started, or `open()` partially ran before
203
- // throwing) — end the stream itself rather than attempting a second, incompatible response.
204
- channel.end();
205
- }
206
- }
207
- /**
208
- * Path {@link registerRunEventStream} mounts. Exported as a constant so a caller that needs to know
209
- * this route exists — a reverse proxy's forward list, `route-manifest.ts` — references it rather than
210
- * restating the literal and later drifting from it.
211
- */
212
- export const RUN_EVENTS_ROUTE_PATH = '/api/runs/:runId/events';
213
- /** Express mounting glue for {@link handleRunEventStreamRequest} — resolves `runId`/`afterCursor` from an Express `Request` and hands the request straight through. */
214
- export function registerRunEventStream(app, deps) {
215
- app.get(RUN_EVENTS_ROUTE_PATH, async (req, res) => {
216
- const runId = req.params.runId;
217
- if (typeof runId !== 'string' || runId.length === 0) {
218
- sendApiError(res, 400, createApiError('BAD_REQUEST', 'runId must be a non-empty path parameter'));
219
- return;
220
- }
221
- await handleRunEventStreamRequest(res, runId, requestedAfterCursor(req), deps);
222
- });
223
- }
224
- /** Mounts create/status/cancel JSON endpoints and the SSE event stream as one run transport. */
225
- export function registerRunRoutes(app, deps, adapter) {
226
- mountJsonRoute(app, runStartRoute, deps, adapter);
227
- mountJsonRoute(app, runListRoute, deps, adapter);
228
- mountJsonRoute(app, runStatusRoute, deps, adapter);
229
- mountJsonRoute(app, runCancelRoute, deps, adapter);
230
- registerRunEventStream(app, deps);
231
- }
232
- //# sourceMappingURL=runs.js.map
@@ -1,125 +0,0 @@
1
- import type { Express } from 'express';
2
- import type { Principal } from '@jini-ai/core';
3
- import type { TerminalSessionActionResult, TerminalSessionInfo, TerminalSessionManager } from '@jini-ai/daemon';
4
- import type { ToolExecutor } from '@jini-ai/daemon';
5
- import { type AdapterContext } from './adapter.js';
6
- import { type WorkspaceRootResolver } from './workspace-root.js';
7
- import { type Result } from './types.js';
8
- /** Diagnostic detail for an internal-error response the public API deliberately does not disclose (SEC-005, matching `runs.ts`/`db-ops.ts`): a spawn failure (e.g. a missing/uncompiled native addon) can embed executable paths or host detail. */
9
- export interface TerminalsInternalErrorContext {
10
- readonly source: 'terminal-create';
11
- readonly correlationId: string;
12
- readonly error: unknown;
13
- }
14
- /** Everything this route pack needs from the host. */
15
- export interface TerminalsHttpDeps {
16
- readonly manager: TerminalSessionManager;
17
- readonly toolExecutor: ToolExecutor;
18
- /** The identity these routes act as — same fixed, host-supplied-value shape as `db-ops.ts`'s `DaemonDbHttpDeps.principal` (this transport has no session/identity subsystem of its own). */
19
- readonly principal: Principal;
20
- /** Resolves a `resourceRef` to a spawn working directory. Defaults to {@link denyAllWorkspaceRoots} — a host that never wires a real resolver gets a 404 on every create call, never a guessed path (see `workspace-root.ts`). */
21
- readonly resolveRoot?: WorkspaceRootResolver;
22
- /** Host-owned sink for the real exception behind a generic `INTERNAL_ERROR` response (SEC-005). Defaults to `console.error`. */
23
- readonly onInternalError?: (context: TerminalsInternalErrorContext) => void;
24
- }
25
- export interface TerminalCreateRequest {
26
- readonly resourceRef: string;
27
- readonly detail?: string;
28
- readonly cols?: number;
29
- readonly rows?: number;
30
- readonly shell?: string;
31
- }
32
- /**
33
- * `POST /api/terminals` — the one gated call (see module doc). Resolves
34
- * `resourceRef` to a working directory the same way `host-tools.ts`'s
35
- * open-in route does, then authorizes+spawns the session through
36
- * `ToolExecutor.execute(..., 'terminal.create', ...)`.
37
- */
38
- export declare const terminalCreateRoute: import("./types.js").JsonRouteSpec<TerminalCreateRequest, TerminalSessionInfo, TerminalsHttpDeps>;
39
- export interface TerminalListResponse {
40
- readonly terminals: readonly TerminalSessionInfo[];
41
- }
42
- /** `GET /api/terminals` — sessions the calling principal owns, optionally narrowed by `resourceRef`. Never gated through `ToolExecutor` — a read scoped to the caller's own sessions, matching `runs.ts`'s `runListRoute` precedent. */
43
- export declare const terminalListRoute: import("./types.js").JsonRouteSpec<{
44
- resourceRef?: string;
45
- }, TerminalListResponse, TerminalsHttpDeps>;
46
- export interface TerminalActionResponse {
47
- readonly ok: boolean;
48
- readonly terminal?: TerminalSessionInfo;
49
- }
50
- /**
51
- * Exported (not just internal) so the `result.session === null` branch — a real race
52
- * (`write`/`resize`/`kill` finding metadata for an id whose underlying session was concurrently
53
- * killed between the ownership check and the critical section, per `@jini-ai/daemon`'s
54
- * `terminal-session.ts` `currentSnapshot`) — is directly unit-testable against a synthetic
55
- * `TerminalSessionActionResult` rather than requiring a real, hard-to-deterministically-force race
56
- * through the full `TerminalSessionManager`. Matches this file's own `createDeferredEndGate`
57
- * precedent for the same "extract into a directly-testable pure function" shape.
58
- */
59
- export declare function actionResultToApiResult(result: TerminalSessionActionResult, notFoundMessage: string): Result<TerminalActionResponse>;
60
- /** `POST /api/terminals/:id/stdin` — writes `data` to the session's pty. Ownership-checked by `deps.manager.write` directly, not re-gated through `ToolExecutor` (see module doc). */
61
- export declare const terminalStdinRoute: import("./types.js").JsonRouteSpec<{
62
- id: string;
63
- data: string;
64
- }, TerminalActionResponse, TerminalsHttpDeps>;
65
- /** `POST /api/terminals/:id/resize` — resizes the session's pty. */
66
- export declare const terminalResizeRoute: import("./types.js").JsonRouteSpec<{
67
- id: string;
68
- cols: number;
69
- rows: number;
70
- }, TerminalActionResponse, TerminalsHttpDeps>;
71
- /** `POST /api/terminals/:id/kill` — sends `SIGTERM` to the session's pty. */
72
- export declare const terminalKillRoute: import("./types.js").JsonRouteSpec<string, TerminalActionResponse, TerminalsHttpDeps>;
73
- /** `DELETE /api/terminals/:id` — alias for `kill`, matching OD's dual `POST .../kill` / `DELETE` routes. */
74
- export declare const terminalDeleteRoute: import("./types.js").JsonRouteSpec<string, TerminalActionResponse, TerminalsHttpDeps>;
75
- /** The one method {@link createDeferredEndGate} needs from `sse.ts`'s channel — narrowed so the gate is unit-testable against a bare fake, not a real `SseChannel`. */
76
- interface DeferredEndChannel {
77
- end(): void;
78
- }
79
- /**
80
- * The `channelOpened`/`endRequestedBeforeOpen` state machine `registerTerminalEventStream`'s
81
- * `TerminalSseSink.end()` needs, extracted into its own directly-testable unit — see that
82
- * function's inline comment for *why* the deferral exists (an already-exited session's replay
83
- * path can call `end()` before `open()` has ever run).
84
- *
85
- * **On the `markOpened()`-then-`end()` ordering (opened=true when `end()` runs):** this is the
86
- * ordering every *currently reachable* production call graph in this repo takes for a live
87
- * session that exits while already streaming — but it is unreachable through that graph, not
88
- * unreachable in principle. `@jini-ai/platform`'s `TerminalService.finish()` (`packages/platform/src/
89
- * terminal.ts`) calls `sink.send('exit', ...)` immediately before `sink.end()` for every live
90
- * client; `send()` here forwards straight to `channel.enqueue()`, whose `isEndEvent: (e) => e.kind
91
- * === 'exit'` match auto-closes the channel *synchronously inside that same `enqueue()` call* —
92
- * which synchronously runs `registerTerminalEventStream`'s own `channel.onClose` callback, which
93
- * detaches this sink from `TerminalService`'s `session.clients` before `finish()`'s own, separate
94
- * `sink.end()` loop ever runs. That loop iterates `session.clients` fresh at call time (not a
95
- * snapshot taken before `emit()`), so by the time it runs, this sink has already removed itself —
96
- * `sink.end()` is consequently never invoked while `channelOpened` is `true` via any call graph
97
- * this repo's own `@jini-ai/platform` + `@jini-ai/http-kit` composition can currently produce (confirmed by
98
- * instrumenting the real call path directly, not inferred from reading the source — a synchronous
99
- * console probe in `end()` never fired across this file's full "live-exit-while-streaming" test).
100
- * That is a fact about today's specific `TerminalService`/`SseChannel` wiring, not a proof that no
101
- * future caller of `TerminalSseSink` could ever call `end()` post-open (a hypothetical non-SSE
102
- * sink, or a future `TerminalService` exit reason not preceded by a matching `send()`, would hit
103
- * exactly this branch) — so the branch stays as real, intentional defensive code, tested directly
104
- * here rather than deleted for being unreachable *today* or left silently uncovered.
105
- */
106
- export declare function createDeferredEndGate(channel: DeferredEndChannel): {
107
- markOpened(): void;
108
- end(): void;
109
- };
110
- /**
111
- * `GET /api/terminals/:id/stream` — SSE, with `Last-Event-ID`/`afterCursor`
112
- * reconnect replay (via `sse.ts`'s `requestedAfterCursor`, the same helper
113
- * `runs.ts` uses). Adapts `deps.manager.attach`'s push/end
114
- * `TerminalSseSink` to `sse.ts`'s generic channel, mirroring
115
- * `registerRunEventStream`'s adaptation of `RunLifecycle.stream`.
116
- *
117
- * Bypasses `mountJsonRoute` (raw `app.get`, for the SSE response shape), so it does not get
118
- * `requireSameOrigin` for free the way the JSON routes above do — the guard is applied here
119
- * directly, before the SSE channel is opened, so a cross-origin request never gets a stream.
120
- */
121
- export declare function registerTerminalEventStream(app: Express, deps: TerminalsHttpDeps, adapter: AdapterContext): void;
122
- /** Mounts every terminal route (`list`/`create`/`stdin`/`resize`/`kill`/`delete`/`stream`) on `app`. A pack's `http(app, services)` calls this directly. */
123
- export declare function registerTerminalRoutes(app: Express, deps: TerminalsHttpDeps, adapter: AdapterContext): void;
124
- export {};
125
- //# sourceMappingURL=terminals.d.ts.map