@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/db-ops.d.ts DELETED
@@ -1,116 +0,0 @@
1
- import type { Express } from 'express';
2
- import type { Principal, ToolPolicy, ToolRegistration } from '@jini-ai/core';
3
- import type { ToolExecutor } from '@jini-ai/daemon';
4
- import { type AdapterContext } from './adapter.js';
5
- /** The `ToolRegistry` id `GET /api/daemon/db` executes through. */
6
- export declare const DB_INSPECT_TOOL_ID = "daemon.db.inspect";
7
- /** The `ToolRegistry` id `POST /api/daemon/db/verify` executes through. */
8
- export declare const DB_VERIFY_TOOL_ID = "daemon.db.verify";
9
- /** The `ToolRegistry` id `POST /api/daemon/db/vacuum` executes through. */
10
- export declare const DB_VACUUM_TOOL_ID = "daemon.db.vacuum";
11
- export interface DaemonDbTableInfo {
12
- readonly name: string;
13
- readonly rowCount: number;
14
- }
15
- /** Structurally identical to `@jini-ai/sqlite-chat`'s `DaemonDbStatusReport` — defined locally so this package incurs no `better-sqlite3` dependency. */
16
- export interface DaemonDbStatusReport {
17
- readonly kind: 'sqlite' | 'postgres';
18
- readonly location: string;
19
- readonly sizeBytes: number;
20
- readonly schemaVersion: number | null;
21
- readonly tables: readonly DaemonDbTableInfo[];
22
- readonly generatedAt: number;
23
- }
24
- export type DbIntegrityIssueKind = 'integrity' | 'foreign_key';
25
- export interface DbIntegrityIssue {
26
- readonly kind: DbIntegrityIssueKind;
27
- readonly message: string;
28
- }
29
- /** Structurally identical to `@jini-ai/sqlite-chat`'s `DbIntegrityReport`. */
30
- export interface DbIntegrityReport {
31
- readonly ok: boolean;
32
- readonly mode: 'integrity_check' | 'quick_check';
33
- readonly issues: readonly DbIntegrityIssue[];
34
- readonly elapsedMs: number;
35
- readonly generatedAt: number;
36
- }
37
- export interface DaemonDbVacuumResult {
38
- readonly ok: true;
39
- readonly beforeBytes: number;
40
- readonly afterBytes: number;
41
- readonly reclaimedBytes: number;
42
- readonly elapsedMs: number;
43
- }
44
- /** The real collaborator a host injects — typically backed by `@jini-ai/sqlite-chat`'s `inspectSqliteDatabase`/`verifySqliteIntegrity` plus a small `vacuum` wrapper around `db.exec('VACUUM')`. */
45
- export interface DaemonDbOperations {
46
- inspect(): Promise<DaemonDbStatusReport> | DaemonDbStatusReport;
47
- verify(quick: boolean): Promise<DbIntegrityReport> | DbIntegrityReport;
48
- vacuum(): Promise<DaemonDbVacuumResult> | DaemonDbVacuumResult;
49
- }
50
- /**
51
- * Deny-by-default `ToolPolicy` shared by all three DB tools — every call is
52
- * denied, unconditionally, regardless of principal. Matching
53
- * `@jini-ai/deploy`'s `denyAllDeployPublishPolicy` precedent: a host must
54
- * explicitly opt in with its own policy (e.g. role-gated, or "same principal
55
- * that owns the daemon process") rather than getting a working DB inspector
56
- * for free merely by registering the tools. `inspect`/`verify` disclose
57
- * internal schema and row-count information; `vacuum` rewrites the database
58
- * file in place — none of the three has a safe "mostly harmless" default the
59
- * way a pure read-only, non-sensitive tool might.
60
- */
61
- export declare const denyAllDaemonDbPolicy: ToolPolicy;
62
- export interface CreateDaemonDbToolRegistrationsOptions {
63
- readonly operations: DaemonDbOperations;
64
- /** Defaults to {@link denyAllDaemonDbPolicy} — see its doc for why a permissive default was rejected. Applies to all three tools; pass distinct `ToolRegistration.policy` values by registering them individually if a host wants per-operation rules. */
65
- readonly policy?: ToolPolicy;
66
- readonly requiresConfirmation?: boolean;
67
- readonly timeoutMs?: number;
68
- }
69
- export interface DaemonDbToolRegistrations {
70
- readonly inspect: ToolRegistration;
71
- readonly verify: ToolRegistration;
72
- readonly vacuum: ToolRegistration;
73
- }
74
- /**
75
- * Builds the three `{descriptor, handler, policy}` triples a host registers
76
- * against `@jini-ai/core`'s `ToolRegistry` so the DB operations become
77
- * reachable only via `ToolExecutor.execute(principal, run, toolId, input)` —
78
- * never by a route calling `operations.inspect()`/`verify()`/`vacuum()`
79
- * directly, which would bypass authorization and the audit trail entirely.
80
- *
81
- * @complexity O(1) to build the three registrations; each handler's own cost is `operations`'s.
82
- * @overallScore 100/100
83
- */
84
- export declare function createDaemonDbToolRegistrations(options: CreateDaemonDbToolRegistrationsOptions): DaemonDbToolRegistrations;
85
- /** Diagnostic detail for an internal-error response the public API deliberately does not disclose (SEC-005, matching `runs.ts`'s `RunInternalErrorContext`): a `failed`/`timed-out`/`cancelled` tool execution can embed schema names, file paths, or a raw SQLite error message. */
86
- export interface DaemonDbInternalErrorContext {
87
- readonly source: 'db-inspect' | 'db-verify' | 'db-vacuum';
88
- readonly correlationId: string;
89
- readonly error: unknown;
90
- }
91
- export interface DaemonDbHttpDeps {
92
- readonly toolExecutor: ToolExecutor;
93
- /**
94
- * The identity these routes execute tool calls as. A fixed, host-supplied
95
- * value rather than derived per-request — this transport has no session/
96
- * identity subsystem of its own (see `packages/http/source-map.md`'s
97
- * `ExecutionDelegate` design-decision note); a host that needs per-request
98
- * principals should resolve one from its own auth layer and construct
99
- * `DaemonDbHttpDeps` per request, or supply a `ToolPolicy` that inspects
100
- * something other than `Principal` to make its decision.
101
- */
102
- readonly principal: Principal;
103
- /** Host-owned sink for the real exception behind a generic `INTERNAL_ERROR` response (SEC-005). Defaults to `console.error`. */
104
- readonly onInternalError?: (context: DaemonDbInternalErrorContext) => void;
105
- }
106
- /** `GET /api/daemon/db` — the database inventory (schema version, tables, row counts, size). */
107
- export declare const daemonDbInspectRoute: import("./types.js").JsonRouteSpec<void, DaemonDbStatusReport, DaemonDbHttpDeps>;
108
- /** `POST /api/daemon/db/verify?quick=` — `PRAGMA integrity_check`/`quick_check` plus `foreign_key_check`. */
109
- export declare const daemonDbVerifyRoute: import("./types.js").JsonRouteSpec<{
110
- quick: boolean;
111
- }, DbIntegrityReport, DaemonDbHttpDeps>;
112
- /** `POST /api/daemon/db/vacuum` — runs `VACUUM` and reports bytes reclaimed. */
113
- export declare const daemonDbVacuumRoute: import("./types.js").JsonRouteSpec<void, DaemonDbVacuumResult, DaemonDbHttpDeps>;
114
- /** Mounts all three DB-ops routes on `app`. A pack's `http(app, services)` calls this directly. */
115
- export declare function registerDaemonDbRoutes(app: Express, deps: DaemonDbHttpDeps, adapter: AdapterContext): void;
116
- //# sourceMappingURL=db-ops.d.ts.map
package/dist/db-ops.js DELETED
@@ -1,191 +0,0 @@
1
- /**
2
- * @module db-ops
3
- *
4
- * Daemon DB inspect/verify/vacuum operations, wired through the
5
- * tool-execution boundary (`@jini-ai/core`'s `tool-registry.ts` + `@jini-ai/daemon`'s
6
- * `tool-executor.ts`) rather than called directly from a route handler.
7
- * Ported from OD's `apps/daemon/src/routes/daemon.ts` `GET /api/daemon/db`,
8
- * `POST /api/daemon/db/verify`, `POST /api/daemon/db/vacuum` (see
9
- * `source-map.md`'s routes-classification table, row `#12 daemon.ts`: "generic
10
- * in shape but depend on a separate `storage/db-inspect.ts` port not built
11
- * this round" — that port now exists as `@jini-ai/sqlite-chat`'s `db-inspect.ts`).
12
- *
13
- * This module does **not** depend on `@jini-ai/sqlite-chat` or `better-sqlite3` at
14
- * all: `DaemonDbOperations` is a plain injected interface (structurally
15
- * compatible with `@jini-ai/sqlite-chat`'s `inspectSqliteDatabase`/
16
- * `verifySqliteIntegrity` return shapes, so a caller can wire those in with
17
- * zero adapter code) — the same "caller supplies the real collaborator"
18
- * convention `daemon-status.ts`/`host-tools.ts` already established in this
19
- * package.
20
- *
21
- * **Why the tool-execution boundary, not a plain route handler calling
22
- * `DaemonDbOperations` directly:** these three operations reveal internal
23
- * schema/row-count/file-size information (`inspect`/`verify`) and rewrite the
24
- * database file in place (`vacuum`) — real security stakes the task brief
25
- * that added this module named explicitly. OD's own origin gated only
26
- * `verify`/`vacuum` behind `requireLocalDaemonRequest` and left `GET
27
- * /api/daemon/db` completely ungated — a real pre-existing gap, not carried
28
- * forward here. Per this repo's binding tool-execution-boundary precedent
29
- * (`packages/deploy/src/tool.ts`'s `deploy.publish`, `packages/daemon/src/
30
- * delegated-tool-bridge.ts`), the actual work happens only inside a
31
- * `ToolHandler` `ToolExecutor.execute` invokes after `ToolPolicy.authorize`
32
- * allows it — never directly from `registerDaemonDbRoutes`' handlers. All
33
- * three routes also keep `requireSameOrigin: true` as a first line of
34
- * defense (matching `daemon-status.ts`'s shutdown route), but that transport
35
- * gate is defense in depth, not a substitute for the tool-execution
36
- * boundary — see {@link denyAllDaemonDbPolicy}'s doc for why the default
37
- * policy denies every call rather than allowing one.
38
- */
39
- import { randomUUID } from 'node:crypto';
40
- import { createApiError } from '@jini-ai/protocol';
41
- import { defineJsonRoute, mountJsonRoute } from './adapter.js';
42
- import { validationError } from './request.js';
43
- import { err, ok } from './types.js';
44
- /** The `ToolRegistry` id `GET /api/daemon/db` executes through. */
45
- export const DB_INSPECT_TOOL_ID = 'daemon.db.inspect';
46
- /** The `ToolRegistry` id `POST /api/daemon/db/verify` executes through. */
47
- export const DB_VERIFY_TOOL_ID = 'daemon.db.verify';
48
- /** The `ToolRegistry` id `POST /api/daemon/db/vacuum` executes through. */
49
- export const DB_VACUUM_TOOL_ID = 'daemon.db.vacuum';
50
- /**
51
- * Deny-by-default `ToolPolicy` shared by all three DB tools — every call is
52
- * denied, unconditionally, regardless of principal. Matching
53
- * `@jini-ai/deploy`'s `denyAllDeployPublishPolicy` precedent: a host must
54
- * explicitly opt in with its own policy (e.g. role-gated, or "same principal
55
- * that owns the daemon process") rather than getting a working DB inspector
56
- * for free merely by registering the tools. `inspect`/`verify` disclose
57
- * internal schema and row-count information; `vacuum` rewrites the database
58
- * file in place — none of the three has a safe "mostly harmless" default the
59
- * way a pure read-only, non-sensitive tool might.
60
- */
61
- export const denyAllDaemonDbPolicy = {
62
- authorize: () => 'deny',
63
- };
64
- function isRecord(value) {
65
- return typeof value === 'object' && value !== null && !Array.isArray(value);
66
- }
67
- /**
68
- * Builds the three `{descriptor, handler, policy}` triples a host registers
69
- * against `@jini-ai/core`'s `ToolRegistry` so the DB operations become
70
- * reachable only via `ToolExecutor.execute(principal, run, toolId, input)` —
71
- * never by a route calling `operations.inspect()`/`verify()`/`vacuum()`
72
- * directly, which would bypass authorization and the audit trail entirely.
73
- *
74
- * @complexity O(1) to build the three registrations; each handler's own cost is `operations`'s.
75
- * @overallScore 100/100
76
- */
77
- export function createDaemonDbToolRegistrations(options) {
78
- const { operations, policy = denyAllDaemonDbPolicy, requiresConfirmation, timeoutMs } = options;
79
- const descriptorExtras = {
80
- ...(requiresConfirmation !== undefined ? { requiresConfirmation } : {}),
81
- ...(timeoutMs !== undefined ? { timeoutMs } : {}),
82
- };
83
- return {
84
- inspect: {
85
- descriptor: {
86
- id: DB_INSPECT_TOOL_ID,
87
- description: 'Inspects the daemon SQLite database: schema version, table list, row counts, on-disk size.',
88
- ...descriptorExtras,
89
- },
90
- policy,
91
- handler: async () => operations.inspect(),
92
- },
93
- verify: {
94
- descriptor: {
95
- id: DB_VERIFY_TOOL_ID,
96
- description: 'Runs a SQLite integrity/foreign-key check against the daemon database.',
97
- ...descriptorExtras,
98
- },
99
- policy,
100
- handler: async (ctx) => {
101
- const input = isRecord(ctx.input) ? ctx.input : {};
102
- return operations.verify(input.quick === true);
103
- },
104
- },
105
- vacuum: {
106
- descriptor: {
107
- id: DB_VACUUM_TOOL_ID,
108
- description: 'Runs SQLite VACUUM against the daemon database and reports reclaimed bytes.',
109
- ...descriptorExtras,
110
- },
111
- policy,
112
- handler: async () => operations.vacuum(),
113
- },
114
- };
115
- }
116
- function defaultDaemonDbInternalErrorSink(context) {
117
- // eslint-disable-next-line no-console
118
- console.error(`[@jini-ai/http-kit] internal error (${context.source}, correlationId=${context.correlationId})`, context.error);
119
- }
120
- /** Every DB-ops call gets its own opaque, single-use `RunRef` — these are one-off operations requests, not steps of a longer-lived agent run, so there is no real run to attach the audit trail to. */
121
- function freshRun() {
122
- return { id: randomUUID() };
123
- }
124
- function toolResultToApiResult(deps, source, result) {
125
- switch (result.status) {
126
- case 'completed':
127
- return ok(result.output);
128
- case 'denied':
129
- return err(createApiError('TOOL_OPERATION_DENIED', 'this operation was denied by policy'));
130
- case 'confirmation-denied':
131
- return err(createApiError('TOOL_OPERATION_DENIED', 'this operation was denied during confirmation'));
132
- case 'timed-out':
133
- case 'cancelled':
134
- case 'failed': {
135
- const correlationId = randomUUID();
136
- const sink = deps.onInternalError ?? defaultDaemonDbInternalErrorSink;
137
- sink({ source, correlationId, error: result.status === 'failed' ? result.error : result.status });
138
- return err(createApiError('INTERNAL_ERROR', 'an internal error occurred', { requestId: correlationId }));
139
- }
140
- }
141
- }
142
- /** `GET /api/daemon/db` — the database inventory (schema version, tables, row counts, size). */
143
- export const daemonDbInspectRoute = defineJsonRoute({
144
- method: 'get',
145
- path: '/api/daemon/db',
146
- requireSameOrigin: true,
147
- parse: () => ok(undefined),
148
- handle: async (_input, deps) => {
149
- const result = await deps.toolExecutor.execute(deps.principal, freshRun(), DB_INSPECT_TOOL_ID, undefined);
150
- return toolResultToApiResult(deps, 'db-inspect', result);
151
- },
152
- });
153
- function parseDbVerifyInput(input) {
154
- const raw = input.query.quick;
155
- if (raw === undefined)
156
- return ok({ quick: false });
157
- if (typeof raw !== 'string') {
158
- return err(validationError('quick must be a single query-string value when provided'));
159
- }
160
- const normalized = raw.toLowerCase();
161
- return ok({ quick: normalized === '1' || normalized === 'true' });
162
- }
163
- /** `POST /api/daemon/db/verify?quick=` — `PRAGMA integrity_check`/`quick_check` plus `foreign_key_check`. */
164
- export const daemonDbVerifyRoute = defineJsonRoute({
165
- method: 'post',
166
- path: '/api/daemon/db/verify',
167
- requireSameOrigin: true,
168
- parse: parseDbVerifyInput,
169
- handle: async (input, deps) => {
170
- const result = await deps.toolExecutor.execute(deps.principal, freshRun(), DB_VERIFY_TOOL_ID, input);
171
- return toolResultToApiResult(deps, 'db-verify', result);
172
- },
173
- });
174
- /** `POST /api/daemon/db/vacuum` — runs `VACUUM` and reports bytes reclaimed. */
175
- export const daemonDbVacuumRoute = defineJsonRoute({
176
- method: 'post',
177
- path: '/api/daemon/db/vacuum',
178
- requireSameOrigin: true,
179
- parse: () => ok(undefined),
180
- handle: async (_input, deps) => {
181
- const result = await deps.toolExecutor.execute(deps.principal, freshRun(), DB_VACUUM_TOOL_ID, undefined);
182
- return toolResultToApiResult(deps, 'db-vacuum', result);
183
- },
184
- });
185
- /** Mounts all three DB-ops routes on `app`. A pack's `http(app, services)` calls this directly. */
186
- export function registerDaemonDbRoutes(app, deps, adapter) {
187
- mountJsonRoute(app, daemonDbInspectRoute, deps, adapter);
188
- mountJsonRoute(app, daemonDbVerifyRoute, deps, adapter);
189
- mountJsonRoute(app, daemonDbVacuumRoute, deps, adapter);
190
- }
191
- //# sourceMappingURL=db-ops.js.map
@@ -1,146 +0,0 @@
1
- import type { Express } from 'express';
2
- import type { Principal, ToolRegistry } from '@jini-ai/core';
3
- import { type RunLifecycle, type ToolExecutionResult, type ToolExecutor } from '@jini-ai/daemon';
4
- import { type AdapterContext } from './adapter.js';
5
- import * as readOnlyTools from './read-only-tools.js';
6
- export interface DelegatedToolExecuteRequest {
7
- readonly runId: string;
8
- readonly toolUseId: string;
9
- readonly toolId: string;
10
- readonly input?: unknown;
11
- /**
12
- * When `true`, the call is refused unless `toolId`'s registration declares itself read-only
13
- * (`@jini-ai/core`'s `isReadOnlyTool`). Set by a caller that has already promised ITS own caller
14
- * that the surface only reads — `@jini-ai/mcp`'s `execute_readonly_delegated_tool`, whose
15
- * `readOnlyHint: true` annotation is exactly such a promise.
16
- *
17
- * The constraint is enforced HERE rather than in the calling process because only this side can
18
- * resolve a tool id against the live `ToolRegistry`. A caller-side check would be a claim; this
19
- * is the fact.
20
- *
21
- * Omitted means unconstrained, which is what every existing caller sends — the original
22
- * `execute_delegated_tool` path is untouched by this field's existence.
23
- */
24
- readonly requireReadOnly?: boolean;
25
- }
26
- export interface DelegatedToolExecuteResponse {
27
- readonly result: ToolExecutionResult;
28
- }
29
- /**
30
- * Diagnostic detail for an internal-error response the public API deliberately does not
31
- * disclose (SEC-005), matching `runs.ts`'s `RunInternalErrorContext` precedent: a thrown
32
- * `ToolExecutor`/registry failure can embed tool-handler internals no HTTP caller should see.
33
- */
34
- export interface DelegatedToolsInternalErrorContext {
35
- readonly source: 'delegated-tool-execute' | 'resolve-principal';
36
- readonly runId: string;
37
- readonly toolId: string;
38
- readonly correlationId: string;
39
- readonly error: unknown;
40
- /**
41
- * The settled status when the failure is a `ToolExecutionResult` this route will not show as-is
42
- * (`timed-out`, `cancelled`, or a `failed` the host did not mark model-safe); absent when `error`
43
- * is a thrown exception. Lets a host word a timeout differently from a crash without parsing
44
- * `error`, which for a settled result is only `result.error ?? result.status`.
45
- */
46
- readonly status?: 'timed-out' | 'cancelled' | 'failed';
47
- }
48
- export interface DelegatedToolsHttpDeps {
49
- readonly lifecycle: RunLifecycle;
50
- readonly toolExecutor: ToolExecutor;
51
- /** Host-owned: resolves the `Principal` a given delegated-tool-call request executes as. Mandatory — see module doc; there is no safe default identity this package could assume on a host's behalf. */
52
- readonly resolvePrincipal: (request: DelegatedToolExecuteRequest) => Principal | Promise<Principal>;
53
- /** Host-owned sink for the real exception behind a generic `INTERNAL_ERROR` response (SEC-005). Defaults to `console.error`. */
54
- readonly onInternalError?: (context: DelegatedToolsInternalErrorContext) => void;
55
- /**
56
- * The same `ToolRegistry` `deps.toolExecutor` was built over, supplied so a
57
- * {@link DelegatedToolExecuteRequest.requireReadOnly} call can be checked against the descriptor
58
- * that will actually run. Descriptors only — this route never gains a way to reach a handler.
59
- *
60
- * Optional so that mounting this route stays a non-breaking one-liner for every host that
61
- * predates the constraint. A host that omits it does not get a WEAKER gate: a `requireReadOnly`
62
- * call it cannot verify is refused outright ({@link READ_ONLY_UNVERIFIABLE_MESSAGE}), never
63
- * waived. Unconstrained calls behave identically with or without it.
64
- */
65
- readonly toolRegistry?: ToolRegistry;
66
- /**
67
- * Host opt-in: returns `true` for a `failed` result whose `error` text the HOST has already made
68
- * safe to show the model — secret values blanked, an error id minted — so this route answers it
69
- * with `422 TOOL_EXECUTION_FAILED` carrying that text, not the SEC-005-redacted 500. The model then
70
- * sees why the tool failed (e.g. "no frontend is bound…") instead of an opaque INTERNAL_ERROR.
71
- *
72
- * Only consulted for `status: 'failed'` with a non-empty `error`; every other outcome, and every
73
- * failure it returns `false` for, keeps the existing mapping. Omitted (the default), nothing
74
- * changes — a host that has no redaction layer must not wire this, because this route does no
75
- * redaction of its own on this path.
76
- */
77
- readonly isModelSafeToolFailure?: (result: ToolExecutionResult) => boolean;
78
- /**
79
- * Host opt-in: the model-safe text to send in place of `'an internal error occurred'` for every
80
- * failure this route would otherwise answer with the SEC-005-redacted `500 INTERNAL_ERROR` — a
81
- * thrown executor (e.g. an unknown tool id), a throwing `resolvePrincipal`, `timed-out`,
82
- * `cancelled`, and a `failed` result `isModelSafeToolFailure` did not vouch for. Without it, those
83
- * reach the model as a bare "INTERNAL_ERROR" it can neither act on nor report.
84
- *
85
- * The response keeps `500 INTERNAL_ERROR` and its `requestId`; only `message` changes, and
86
- * `onInternalError` still receives the raw failure first. Returning `undefined` or `''` keeps the
87
- * generic message for that failure, and so does a describer that throws — a broken describer can
88
- * never turn a 500 into a leak or a crash. Omitted (the default), nothing changes. The host owns
89
- * redaction here exactly as for `isModelSafeToolFailure`: this route sends the returned text
90
- * verbatim.
91
- */
92
- readonly describeInternalError?: (context: DelegatedToolsInternalErrorContext) => string | undefined;
93
- }
94
- /**
95
- * Refusal text for a `requireReadOnly` call naming a tool that is not registered read-only —
96
- * including one that is not registered at all, which is the same answer for the same reason
97
- * (nothing corroborates that it only reads).
98
- *
99
- * Names the tool and the remedy, because the caller is a model choosing between two gateways and
100
- * "denied" alone would leave it guessing which one to try. `describe_tool` already discloses
101
- * whether an id exists, so distinguishing "unknown" from "writes" here would buy the caller nothing
102
- * and cost a second message to keep in step.
103
- */
104
- export declare function readOnlyRefusalMessage(toolId: string): string;
105
- /**
106
- * Refusal text for a `requireReadOnly` call this host has no way to check, because it mounted the
107
- * route without {@link DelegatedToolsHttpDeps.toolRegistry}.
108
- *
109
- * Refusing is the only safe answer: the alternative — running the call because the constraint could
110
- * not be evaluated — would let a write through a caller that annotated itself read-only, which is
111
- * strictly worse than having no read-only gateway at all. The message names the missing dep so the
112
- * fix is one line in the host's own wiring rather than an investigation.
113
- */
114
- export declare const READ_ONLY_UNVERIFIABLE_MESSAGE = "this host cannot verify read-only tools \u2014 POST /api/delegated-tool-calls was mounted without DelegatedToolsHttpDeps.toolRegistry, so a requireReadOnly call cannot be checked and is refused";
115
- export type { ReadOnlyConstrainedPrincipal } from './read-only-tools.js';
116
- /** Compatibility wrapper; new object-shaped API lives at ./read-only-tools. */
117
- export declare function constrainPrincipalToReadOnlyTools(principal: Principal): readOnlyTools.ReadOnlyConstrainedPrincipal;
118
- /** Compatibility wrapper preserving the existing principal argument. */
119
- export declare function principalIsReadOnlyConstrained(principal: Principal): boolean;
120
- /** Compatibility wrapper using the shared fail-closed dispatch decision. */
121
- export declare function refuseNonReadOnlyDispatch(options: {
122
- readonly principal: Principal;
123
- readonly toolId: string;
124
- readonly registry: Pick<ToolRegistry, 'list'> | undefined;
125
- }): string | null;
126
- export interface ReadOnlyToolConstraintDeps {
127
- readonly registry: Pick<ToolRegistry, 'list'> | undefined;
128
- }
129
- /**
130
- * Compatibility wrapper. Compose innermost, directly around the bare executor,
131
- * so nested calls by outer decorators still pass through the shared gate.
132
- */
133
- export declare function withReadOnlyToolConstraint(inner: ToolExecutor, deps: ReadOnlyToolConstraintDeps): ToolExecutor;
134
- /**
135
- * `POST /api/delegated-tool-calls` — executes one delegated tool call against an already-started
136
- * run. Maps `ToolExecutionResult.status` to the HTTP response via `toolExecutionResultToApiResult`
137
- * above — mirroring `db-ops.ts`'s precedent for the identical status union rather than treating
138
- * every business outcome as a `200`. A genuinely unexpected throw (an unregistered `toolId` — a
139
- * routing/programming error per `ToolExecutor.execute`'s own contract — or a race where the run
140
- * became terminal between this route's existence check and the bridge's first emitted event)
141
- * reaches the same SEC-005 redaction path.
142
- */
143
- export declare const delegatedToolExecuteRoute: import("./types.js").JsonRouteSpec<DelegatedToolExecuteRequest, DelegatedToolExecuteResponse, DelegatedToolsHttpDeps>;
144
- /** Mounts `POST /api/delegated-tool-calls` on `app`. A pack's `http(app, services)` calls this directly. */
145
- export declare function registerDelegatedToolRoutes(app: Express, deps: DelegatedToolsHttpDeps, adapter: AdapterContext): void;
146
- //# sourceMappingURL=delegated-tools.d.ts.map