@jini-ai/http-kit 0.4.0 → 0.4.2

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 (64) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/adapter.d.ts +12 -5
  3. package/dist/adapter.js +32 -4
  4. package/dist/index.d.ts +9 -139
  5. package/dist/types.d.ts +38 -3
  6. package/dist/verified-origin/index.d.ts +1 -0
  7. package/dist/verified-origin/index.js +1 -0
  8. package/dist/verified-origin/site-path.d.ts +113 -0
  9. package/dist/verified-origin/site-path.js +179 -0
  10. package/package.json +23 -9
  11. package/dist/active-context.d.ts +0 -99
  12. package/dist/active-context.js +0 -77
  13. package/dist/agents.d.ts +0 -64
  14. package/dist/agents.js +0 -23
  15. package/dist/attachments.d.ts +0 -534
  16. package/dist/attachments.js +0 -1032
  17. package/dist/cancel-owned-runs.d.ts +0 -44
  18. package/dist/cancel-owned-runs.js +0 -35
  19. package/dist/component-catalog.d.ts +0 -74
  20. package/dist/component-catalog.js +0 -74
  21. package/dist/connectors.d.ts +0 -165
  22. package/dist/connectors.js +0 -474
  23. package/dist/daemon-status.d.ts +0 -72
  24. package/dist/daemon-status.js +0 -60
  25. package/dist/db-ops.d.ts +0 -116
  26. package/dist/db-ops.js +0 -191
  27. package/dist/delegated-tools.d.ts +0 -146
  28. package/dist/delegated-tools.js +0 -286
  29. package/dist/frontend-control.d.ts +0 -131
  30. package/dist/frontend-control.js +0 -77
  31. package/dist/frontend-sessions.d.ts +0 -100
  32. package/dist/frontend-sessions.js +0 -180
  33. package/dist/health.d.ts +0 -91
  34. package/dist/health.js +0 -53
  35. package/dist/host-tools.d.ts +0 -174
  36. package/dist/host-tools.js +0 -338
  37. package/dist/media.d.ts +0 -131
  38. package/dist/media.js +0 -352
  39. package/dist/memory.d.ts +0 -230
  40. package/dist/memory.js +0 -331
  41. package/dist/model-proxy.d.ts +0 -45
  42. package/dist/model-proxy.js +0 -619
  43. package/dist/origin-validation.d.ts +0 -64
  44. package/dist/origin-validation.js +0 -226
  45. package/dist/read-only-tools.d.ts +0 -67
  46. package/dist/read-only-tools.js +0 -59
  47. package/dist/remote-run-events.d.ts +0 -66
  48. package/dist/remote-run-events.js +0 -230
  49. package/dist/research.d.ts +0 -42
  50. package/dist/research.js +0 -316
  51. package/dist/route-manifest.d.ts +0 -31
  52. package/dist/route-manifest.js +0 -103
  53. package/dist/routines.d.ts +0 -114
  54. package/dist/routines.js +0 -320
  55. package/dist/runs.d.ts +0 -79
  56. package/dist/runs.js +0 -232
  57. package/dist/terminals.d.ts +0 -125
  58. package/dist/terminals.js +0 -349
  59. package/dist/tool-catalog.d.ts +0 -68
  60. package/dist/tool-catalog.js +0 -68
  61. package/dist/workspace-root.d.ts +0 -69
  62. package/dist/workspace-root.js +0 -63
  63. package/dist/xai.d.ts +0 -86
  64. package/dist/xai.js +0 -668
@@ -1,64 +0,0 @@
1
- /**
2
- * Same-origin / allow-listed-origin validation primitives for a locally-bound HTTP server:
3
- * loopback + private-LAN host/IP classification, an explicit origin allow-list read from env,
4
- * and the top-level `isLocalSameOrigin` decision `origin-guard.ts` wraps in the module's
5
- * `Result` pipeline. Framework-independent — operates on plain header values, not an Express
6
- * `Request`.
7
- */
8
- export interface ParsedHostHeader {
9
- hostname: string;
10
- host: string;
11
- port: string;
12
- }
13
- export interface RequestWithOriginHeaders {
14
- headers?: {
15
- host?: unknown;
16
- origin?: unknown;
17
- 'sec-fetch-site'?: unknown;
18
- };
19
- }
20
- /**
21
- * Extra allow-listed origins, comma-separated, read from `JINI_ALLOWED_ORIGINS`.
22
- *
23
- * Deliberately never throws. This runs inside {@link isLocalSameOrigin}, which every same-origin
24
- * check across the whole HTTP surface calls fresh on every incoming request — a config typo here
25
- * used to throw a `TypeError` synchronously, and depending on which route it happened to hit, that
26
- * either 500'd every request for the process's life or, worse, became an unhandled promise
27
- * rejection with nothing to catch it (`attachments.ts`'s hand-mounted routes, `model-proxy.ts`'s
28
- * `:provider` catch-all — see each file's own regression test). A malformed entry is dropped from
29
- * the allow-list and logged instead, so the daemon degrades to "one fewer trusted origin," never
30
- * "every request breaks." Call {@link assertValidAllowedOrigins} once at host startup to catch a
31
- * misconfiguration loudly before any request-serving traffic exists at all — that is where a typo
32
- * should actually be caught, not on the hot path.
33
- */
34
- export declare function configuredAllowedOrigins(env?: NodeJS.ProcessEnv): string[];
35
- /**
36
- * Boot-time companion to {@link configuredAllowedOrigins}: throws, naming every malformed entry,
37
- * instead of silently dropping them. Meant to be called exactly once, early in host startup
38
- * (before the HTTP server accepts connections), so a misconfigured `JINI_ALLOWED_ORIGINS` fails
39
- * the boot loudly rather than quietly serving with a smaller-than-intended allow-list — or, before
40
- * this function existed, throwing on the first request that happened to reach the same-origin
41
- * guard instead of at boot.
42
- */
43
- export declare function assertValidAllowedOrigins(env?: NodeJS.ProcessEnv): void;
44
- export declare function configuredAllowedHosts(origins?: string[]): string[];
45
- /** The primary bound port plus an optional secondary web port from `JINI_WEB_PORT`. */
46
- export declare function allowedBrowserPorts(port: number | string | null | undefined, env?: NodeJS.ProcessEnv): number[];
47
- export declare function parseHostHeader(value: unknown): ParsedHostHeader | null;
48
- export declare function isPrivateIpv4(hostname: unknown): boolean;
49
- export declare function isIpLiteralHostname(hostname: unknown): boolean;
50
- export declare function isLoopbackOrPrivateLanHost(hostname: unknown): boolean;
51
- export declare function isAllowedBrowserHost(hostHeader: unknown, ports: number[], bindHost: string, extraAllowedOrigins: string[]): boolean;
52
- export declare function isAllowedBrowserOrigin(origin: unknown, hostHeader: unknown, ports: number[], bindHost: string, extraAllowedOrigins: string[]): boolean;
53
- /**
54
- * Top-level same-origin decision for a locally-bound HTTP server: same-origin GETs (which
55
- * browsers may send with no `Origin` header per the Fetch spec) are accepted via the `Host`
56
- * header + `Sec-Fetch-Site: same-origin` signal (a header set by the user agent, unforgeable
57
- * from JavaScript); cross-origin requests must present an `Origin` that resolves to a loopback,
58
- * private-LAN, or explicitly allow-listed (`JINI_ALLOWED_ORIGINS`) origin. Reverse-proxy
59
- * deployments are supported by trusting an `Origin` that exactly matches an allow-listed entry,
60
- * since the `Host` header a proxied daemon sees is the proxy's upstream address, not the
61
- * browser-visible origin.
62
- */
63
- export declare function isLocalSameOrigin(req: RequestWithOriginHeaders, port: number | string | null | undefined, env?: NodeJS.ProcessEnv): boolean;
64
- //# sourceMappingURL=origin-validation.d.ts.map
@@ -1,226 +0,0 @@
1
- /**
2
- * Same-origin / allow-listed-origin validation primitives for a locally-bound HTTP server:
3
- * loopback + private-LAN host/IP classification, an explicit origin allow-list read from env,
4
- * and the top-level `isLocalSameOrigin` decision `origin-guard.ts` wraps in the module's
5
- * `Result` pipeline. Framework-independent — operates on plain header values, not an Express
6
- * `Request`.
7
- */
8
- /**
9
- * Splits and trims the raw `JINI_ALLOWED_ORIGINS` value into individual candidate entries.
10
- * Shared by {@link configuredAllowedOrigins} (lenient, per-request) and
11
- * {@link assertValidAllowedOrigins} (strict, boot-time) so the two can never drift on what counts
12
- * as "one entry."
13
- */
14
- function splitAllowedOriginsEnv(env) {
15
- const raw = env.JINI_ALLOWED_ORIGINS || '';
16
- if (!raw.trim())
17
- return [];
18
- return raw
19
- .split(',')
20
- .map((origin) => origin.trim())
21
- .filter(Boolean);
22
- }
23
- /** Normalizes one `JINI_ALLOWED_ORIGINS` entry into a `protocol://host` origin, or `undefined` if it isn't a valid http(s) origin. */
24
- function parseAllowedOrigin(entry) {
25
- let parsed;
26
- try {
27
- parsed = new URL(entry);
28
- }
29
- catch {
30
- return undefined;
31
- }
32
- if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:')
33
- return undefined;
34
- return parsed.origin;
35
- }
36
- /**
37
- * Extra allow-listed origins, comma-separated, read from `JINI_ALLOWED_ORIGINS`.
38
- *
39
- * Deliberately never throws. This runs inside {@link isLocalSameOrigin}, which every same-origin
40
- * check across the whole HTTP surface calls fresh on every incoming request — a config typo here
41
- * used to throw a `TypeError` synchronously, and depending on which route it happened to hit, that
42
- * either 500'd every request for the process's life or, worse, became an unhandled promise
43
- * rejection with nothing to catch it (`attachments.ts`'s hand-mounted routes, `model-proxy.ts`'s
44
- * `:provider` catch-all — see each file's own regression test). A malformed entry is dropped from
45
- * the allow-list and logged instead, so the daemon degrades to "one fewer trusted origin," never
46
- * "every request breaks." Call {@link assertValidAllowedOrigins} once at host startup to catch a
47
- * misconfiguration loudly before any request-serving traffic exists at all — that is where a typo
48
- * should actually be caught, not on the hot path.
49
- */
50
- export function configuredAllowedOrigins(env = process.env) {
51
- const origins = [];
52
- for (const entry of splitAllowedOriginsEnv(env)) {
53
- const origin = parseAllowedOrigin(entry);
54
- if (origin === undefined) {
55
- console.warn(`[@jini-ai/http-kit] ignoring malformed JINI_ALLOWED_ORIGINS entry (must be an http:// or https:// origin): ${entry}`);
56
- continue;
57
- }
58
- origins.push(origin);
59
- }
60
- return origins;
61
- }
62
- /**
63
- * Boot-time companion to {@link configuredAllowedOrigins}: throws, naming every malformed entry,
64
- * instead of silently dropping them. Meant to be called exactly once, early in host startup
65
- * (before the HTTP server accepts connections), so a misconfigured `JINI_ALLOWED_ORIGINS` fails
66
- * the boot loudly rather than quietly serving with a smaller-than-intended allow-list — or, before
67
- * this function existed, throwing on the first request that happened to reach the same-origin
68
- * guard instead of at boot.
69
- */
70
- export function assertValidAllowedOrigins(env = process.env) {
71
- const invalid = splitAllowedOriginsEnv(env).filter((entry) => parseAllowedOrigin(entry) === undefined);
72
- if (invalid.length === 0)
73
- return;
74
- throw new Error(`JINI_ALLOWED_ORIGINS has ${invalid.length} invalid entr${invalid.length === 1 ? 'y' : 'ies'} ` +
75
- `(must be http:// or https:// origins): ${invalid.join(', ')}`);
76
- }
77
- export function configuredAllowedHosts(origins = configuredAllowedOrigins()) {
78
- return origins.map((origin) => new URL(origin).host);
79
- }
80
- /** The primary bound port plus an optional secondary web port from `JINI_WEB_PORT`. */
81
- export function allowedBrowserPorts(port, env = process.env) {
82
- const ports = [];
83
- const primary = Number(port);
84
- if (primary)
85
- ports.push(primary);
86
- const webPort = Number(env.JINI_WEB_PORT);
87
- if (webPort && webPort !== primary)
88
- ports.push(webPort);
89
- return ports;
90
- }
91
- export function parseHostHeader(value) {
92
- const raw = String(headerValue(value) || '').trim();
93
- if (!raw)
94
- return null;
95
- try {
96
- const parsed = new URL(`http://${raw}`);
97
- return { hostname: parsed.hostname, host: parsed.host, port: parsed.port || '80' };
98
- }
99
- catch {
100
- return null;
101
- }
102
- }
103
- export function isPrivateIpv4(hostname) {
104
- const parts = String(hostname || '').split('.');
105
- if (parts.length !== 4)
106
- return false;
107
- if (!parts.every((part) => /^\d+$/.test(part)))
108
- return false;
109
- const octets = parts.map((part) => Number(part));
110
- if (!octets.every((n) => Number.isInteger(n) && n >= 0 && n <= 255))
111
- return false;
112
- const [a, b] = octets;
113
- return (a === 10 ||
114
- (a === 172 && b >= 16 && b <= 31) ||
115
- (a === 192 && b === 168) ||
116
- (a === 169 && b === 254));
117
- }
118
- export function isIpLiteralHostname(hostname) {
119
- const host = String(hostname || '').trim();
120
- if (!host)
121
- return false;
122
- if (host.startsWith('[') && host.endsWith(']'))
123
- return true;
124
- const parts = host.split('.');
125
- if (parts.length !== 4)
126
- return false;
127
- if (!parts.every((part) => /^\d+$/.test(part)))
128
- return false;
129
- return parts.map(Number).every((n) => Number.isInteger(n) && n >= 0 && n <= 255);
130
- }
131
- export function isLoopbackOrPrivateLanHost(hostname) {
132
- const host = String(hostname || '').toLowerCase();
133
- return (host === 'localhost' ||
134
- host === '127.0.0.1' ||
135
- host === '::1' ||
136
- host === '[::1]' ||
137
- host === '0.0.0.0' ||
138
- host === '::' ||
139
- isPrivateIpv4(host));
140
- }
141
- export function isAllowedBrowserHost(hostHeader, ports, bindHost, extraAllowedOrigins) {
142
- const requestHost = parseHostHeader(hostHeader);
143
- if (!requestHost)
144
- return false;
145
- const loopbackHosts = ['127.0.0.1', 'localhost', '[::1]'];
146
- const explicitHosts = new Set([
147
- ...ports.flatMap((p) => [...loopbackHosts.map((h) => `${h}:${p}`), `${bindHost}:${p}`]),
148
- ...configuredAllowedHosts(extraAllowedOrigins),
149
- ]);
150
- if (explicitHosts.has(requestHost.host))
151
- return true;
152
- if (!ports.map(String).includes(requestHost.port))
153
- return false;
154
- return isLoopbackOrPrivateLanHost(requestHost.hostname);
155
- }
156
- export function isAllowedBrowserOrigin(origin, hostHeader, ports, bindHost, extraAllowedOrigins) {
157
- if (extraAllowedOrigins.includes(String(origin)))
158
- return true;
159
- let parsedOrigin;
160
- try {
161
- parsedOrigin = new URL(String(origin));
162
- }
163
- catch {
164
- return false;
165
- }
166
- if (parsedOrigin.protocol !== 'http:' && parsedOrigin.protocol !== 'https:')
167
- return false;
168
- const requestHost = parseHostHeader(hostHeader);
169
- if (!requestHost)
170
- return false;
171
- const schemes = ['http', 'https'];
172
- const loopbackHosts = ['127.0.0.1', 'localhost', '[::1]'];
173
- const explicitOrigins = new Set(ports.flatMap((p) => [
174
- ...schemes.flatMap((s) => loopbackHosts.map((h) => `${s}://${h}:${p}`)),
175
- ...schemes.map((s) => `${s}://${bindHost}:${p}`),
176
- ]));
177
- if (explicitOrigins.has(String(origin)))
178
- return true;
179
- const originPort = parsedOrigin.port || (parsedOrigin.protocol === 'https:' ? '443' : '80');
180
- if (!ports.map(String).includes(originPort))
181
- return false;
182
- if (parsedOrigin.hostname !== requestHost.hostname)
183
- return false;
184
- return isLoopbackOrPrivateLanHost(parsedOrigin.hostname);
185
- }
186
- /**
187
- * Top-level same-origin decision for a locally-bound HTTP server: same-origin GETs (which
188
- * browsers may send with no `Origin` header per the Fetch spec) are accepted via the `Host`
189
- * header + `Sec-Fetch-Site: same-origin` signal (a header set by the user agent, unforgeable
190
- * from JavaScript); cross-origin requests must present an `Origin` that resolves to a loopback,
191
- * private-LAN, or explicitly allow-listed (`JINI_ALLOWED_ORIGINS`) origin. Reverse-proxy
192
- * deployments are supported by trusting an `Origin` that exactly matches an allow-listed entry,
193
- * since the `Host` header a proxied daemon sees is the proxy's upstream address, not the
194
- * browser-visible origin.
195
- */
196
- export function isLocalSameOrigin(req, port, env = process.env) {
197
- const host = String(headerValue(req.headers?.host) || '');
198
- const origin = headerValue(req.headers?.origin);
199
- const ports = allowedBrowserPorts(port, env);
200
- const bindHost = env.JINI_BIND_HOST || '127.0.0.1';
201
- const extraAllowedOrigins = configuredAllowedOrigins(env);
202
- const ipOnlyExtraOrigins = extraAllowedOrigins.filter((o) => isIpLiteralHostname(new URL(o).hostname));
203
- const localHostAllowed = isAllowedBrowserHost(host, ports, bindHost, ipOnlyExtraOrigins);
204
- if (origin == null || origin === '') {
205
- if (localHostAllowed)
206
- return true;
207
- const fetchSite = headerValue(req.headers?.['sec-fetch-site']);
208
- if (fetchSite === 'same-origin') {
209
- return isAllowedBrowserHost(host, ports, bindHost, extraAllowedOrigins);
210
- }
211
- return false;
212
- }
213
- if (extraAllowedOrigins.includes(origin))
214
- return true;
215
- if (!isAllowedBrowserHost(host, ports, bindHost, extraAllowedOrigins))
216
- return false;
217
- return isAllowedBrowserOrigin(origin, host, ports, bindHost, extraAllowedOrigins);
218
- }
219
- function headerValue(value) {
220
- if (Array.isArray(value)) {
221
- const first = value[0];
222
- return first == null ? undefined : String(first);
223
- }
224
- return value == null ? undefined : String(value);
225
- }
226
- //# sourceMappingURL=origin-validation.js.map
@@ -1,67 +0,0 @@
1
- import { type Principal, type ToolRegistry } from '@jini-ai/core';
2
- import type { ToolExecutor } from '@jini-ai/daemon';
3
- export interface ReadOnlyConstrainedPrincipal extends Principal {
4
- readonly toolAccess: 'read-only';
5
- }
6
- /** Required host wording; absent metadata is always a refusal. */
7
- export interface ReadOnlyToolMessages {
8
- readonly unverifiableMessage: string;
9
- toolRefusalMessage(required: {
10
- toolId: string;
11
- }): string;
12
- }
13
- export interface IdGenerator {
14
- newId(): string;
15
- }
16
- export interface ReadOnlyToolCheckRequired {
17
- readonly toolId: string;
18
- readonly registry: Pick<ToolRegistry, 'list'> | undefined;
19
- readonly messages: ReadOnlyToolMessages;
20
- }
21
- export interface ReadOnlyToolConstraintRequired {
22
- readonly inner: ToolExecutor;
23
- readonly registry: Pick<ToolRegistry, 'list'> | undefined;
24
- readonly idGenerator: IdGenerator;
25
- readonly messages: ReadOnlyToolMessages;
26
- }
27
- /** @returns A copied, attenuated principal; its roles are unchanged. */
28
- export declare function constrainPrincipalToReadOnlyTools({ principal }: {
29
- principal: Principal;
30
- }, _optional?: Record<string, never>): ReadOnlyConstrainedPrincipal;
31
- /** @returns Whether attenuation survived the executor/decorator boundary. */
32
- export declare function principalIsReadOnlyConstrained({ principal }: {
33
- principal: Principal;
34
- }, _optional?: Record<string, never>): boolean;
35
- /** @returns Required host wording for an unknown or non-read-only tool. */
36
- export declare function readOnlyToolRefusalMessage({ toolId, messages }: {
37
- toolId: string;
38
- messages: ReadOnlyToolMessages;
39
- }, _optional?: Record<string, never>): string;
40
- /**
41
- * Single read-only registration decision, shared by routes and inner dispatch.
42
- * @returns Null for an explicitly read-only registration, otherwise host refusal text.
43
- */
44
- export declare function checkReadOnlyTool({ toolId, registry, messages }: ReadOnlyToolCheckRequired, _optional?: Record<string, never>): string | null;
45
- /**
46
- * Preflight for every dispatch, including a recovery tool the caller never named.
47
- * @returns Null for unconstrained principals or safe reads; otherwise refusal text.
48
- */
49
- export declare function refuseNonReadOnlyDispatch(required: ReadOnlyToolCheckRequired & {
50
- readonly principal: Principal;
51
- }, _optional?: Record<string, never>): string | null;
52
- /** @returns Caller-formatted recovery refusal, preserving the original refusal verbatim as input. */
53
- export declare function readOnlyRemedyRefusalMessage({ refusal, formatMessage }: {
54
- refusal: string;
55
- formatMessage: (required: {
56
- refusal: string;
57
- }) => string;
58
- }, _optional?: Record<string, never>): string;
59
- /**
60
- * Gate every dispatch before its handler runs. Compose directly around the bare
61
- * executor, beneath all decorators that can issue nested/recovery dispatches.
62
- * Wrapping only a fully composed stack cannot intercept its inner references.
63
- * @param required - Executor, registry, denial ID source and required host wording.
64
- * @returns An executor using the existing kernel port's positional methods.
65
- */
66
- export declare function withReadOnlyToolConstraint({ inner, registry, idGenerator, messages }: ReadOnlyToolConstraintRequired, _optional?: Record<string, never>): ToolExecutor;
67
- //# sourceMappingURL=read-only-tools.d.ts.map
@@ -1,59 +0,0 @@
1
- import { isReadOnlyTool } from '@jini-ai/core';
2
- /** @returns A copied, attenuated principal; its roles are unchanged. */
3
- export function constrainPrincipalToReadOnlyTools({ principal }, _optional = {}) {
4
- return { ...principal, toolAccess: 'read-only' };
5
- }
6
- /** @returns Whether attenuation survived the executor/decorator boundary. */
7
- export function principalIsReadOnlyConstrained({ principal }, _optional = {}) {
8
- return principal.toolAccess === 'read-only';
9
- }
10
- /** @returns Required host wording for an unknown or non-read-only tool. */
11
- export function readOnlyToolRefusalMessage({ toolId, messages }, _optional = {}) {
12
- return messages.toolRefusalMessage({ toolId });
13
- }
14
- /**
15
- * Single read-only registration decision, shared by routes and inner dispatch.
16
- * @returns Null for an explicitly read-only registration, otherwise host refusal text.
17
- */
18
- export function checkReadOnlyTool({ toolId, registry, messages }, _optional = {}) {
19
- if (registry === undefined)
20
- return messages.unverifiableMessage;
21
- const descriptor = registry.list().find((candidate) => candidate.id === toolId);
22
- if (isReadOnlyTool(descriptor))
23
- return null;
24
- return readOnlyToolRefusalMessage({ toolId, messages });
25
- }
26
- /**
27
- * Preflight for every dispatch, including a recovery tool the caller never named.
28
- * @returns Null for unconstrained principals or safe reads; otherwise refusal text.
29
- */
30
- export function refuseNonReadOnlyDispatch(required, _optional = {}) {
31
- if (!principalIsReadOnlyConstrained({ principal: required.principal }))
32
- return null;
33
- return checkReadOnlyTool(required);
34
- }
35
- /** @returns Caller-formatted recovery refusal, preserving the original refusal verbatim as input. */
36
- export function readOnlyRemedyRefusalMessage({ refusal, formatMessage }, _optional = {}) {
37
- return formatMessage({ refusal });
38
- }
39
- /**
40
- * Gate every dispatch before its handler runs. Compose directly around the bare
41
- * executor, beneath all decorators that can issue nested/recovery dispatches.
42
- * Wrapping only a fully composed stack cannot intercept its inner references.
43
- * @param required - Executor, registry, denial ID source and required host wording.
44
- * @returns An executor using the existing kernel port's positional methods.
45
- */
46
- export function withReadOnlyToolConstraint({ inner, registry, idGenerator, messages }, _optional = {}) {
47
- return {
48
- execute: async (principal, run, toolId, input, signal, emitSurface) => {
49
- const refusal = refuseNonReadOnlyDispatch({ principal, toolId, registry, messages });
50
- if (refusal !== null)
51
- return { executionId: idGenerator.newId(), status: 'denied', error: refusal };
52
- return inner.execute(principal, run, toolId, input, signal, emitSurface);
53
- },
54
- resumeConfirmation: (executionId, decision) => inner.resumeConfirmation(executionId, decision),
55
- cancel: (executionId) => inner.cancel(executionId),
56
- getAuditRecord: (executionId) => inner.getAuditRecord(executionId),
57
- };
58
- }
59
- //# sourceMappingURL=read-only-tools.js.map
@@ -1,66 +0,0 @@
1
- import type { Express, NextFunction, Request, Response } from 'express';
2
- import type { RemoteToolEventRecorder, RunLifecycle } from '@jini-ai/daemon';
3
- import { type AdapterContext } from './adapter.js';
4
- export interface RemoteToolBridgeTokenConfig {
5
- /** Env var name for the required shared secret. Defaults to `JINI_REMOTE_TOOL_BRIDGE_TOKEN`. */
6
- readonly tokenEnvVar?: string;
7
- }
8
- export interface RemoteRunEventInternalErrorContext {
9
- readonly source: 'tool-use' | 'tool-result';
10
- readonly correlationId: string;
11
- readonly error: unknown;
12
- }
13
- export interface RemoteRunEventHttpDeps {
14
- /** Used to distinguish "unknown run" (404) from other outcomes before recording — same precedent as `delegated-tools.ts`'s `delegatedToolExecuteRoute` — and again afterwards to classify a recorder failure (see {@link toRemoteEventError}). */
15
- readonly lifecycle: RunLifecycle;
16
- readonly recorder: RemoteToolEventRecorder;
17
- readonly tokenConfig?: RemoteToolBridgeTokenConfig;
18
- /** Defaults to `process.env`. Threaded through so tests never have to mutate real process env. */
19
- readonly env?: NodeJS.ProcessEnv;
20
- /** Host-owned sink for the real exception behind a generic `INTERNAL_ERROR` response (SEC-005). Defaults to `console.error`. */
21
- readonly onInternalError?: (context: RemoteRunEventInternalErrorContext) => void;
22
- }
23
- /**
24
- * Gates both remote-run-event routes behind a dedicated shared secret. Unlike
25
- * `registerApiBearerAuthMiddleware`, there is no "unset means open" or "disabled" mode: a route
26
- * that lets a caller inject events into someone else's run must never silently run unauthenticated
27
- * just because a host forgot to configure the token. If the token isn't configured, the route
28
- * fails closed with 503, not 200.
29
- *
30
- * Kept as its own middleware rather than folded into `api-security-middleware.ts`'s
31
- * `requireStrictBearerToken` (which has the identical fail-closed/no-loopback-exemption posture)
32
- * because these two routes own their own error codes — `REMOTE_TOOL_BRIDGE_*`, distinct from the
33
- * general API token's, so an operator can tell which secret is missing from the response alone.
34
- * The *decision* logic is shared: header parsing and the constant-time comparison both come from
35
- * that module, so the two gates cannot drift on what counts as a well-formed header or on
36
- * comparison safety.
37
- */
38
- export declare function requireRemoteToolBridgeToken(deps: {
39
- readonly tokenConfig?: RemoteToolBridgeTokenConfig;
40
- readonly env?: NodeJS.ProcessEnv;
41
- }): (req: Request, res: Response, next: NextFunction) => void;
42
- export interface RemoteToolUseRequest {
43
- readonly runId: string;
44
- readonly toolUseId: string;
45
- readonly toolId: string;
46
- readonly input?: unknown;
47
- }
48
- export interface RemoteToolResultRequest {
49
- readonly runId: string;
50
- readonly toolUseId: string;
51
- readonly content: string;
52
- readonly isError?: boolean;
53
- }
54
- export interface RemoteRunEventResponse {
55
- readonly recorded: true;
56
- }
57
- export declare const remoteToolUseRoute: import("./types.js").JsonRouteSpec<RemoteToolUseRequest, RemoteRunEventResponse, RemoteRunEventHttpDeps>;
58
- export declare const remoteToolResultRoute: import("./types.js").JsonRouteSpec<RemoteToolResultRequest, RemoteRunEventResponse, RemoteRunEventHttpDeps>;
59
- /**
60
- * Mounts both remote-run-event routes on `app`, gated by {@link requireRemoteToolBridgeToken}.
61
- * Unlike `registerRunRoutes`/`registerDelegatedToolRoutes`, these routes do not use
62
- * `requireSameOrigin` — they are not meant to be called from a browser at all, only from a host's
63
- * own trusted backend process, so the dedicated bearer token above is the sole gate.
64
- */
65
- export declare function registerRemoteRunEventRoutes(app: Express, deps: RemoteRunEventHttpDeps, adapter: AdapterContext): void;
66
- //# sourceMappingURL=remote-run-events.d.ts.map