@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
@@ -0,0 +1,179 @@
1
+ /**
2
+ * @file Shared site-path checks: decoded, dot-resolved segments and origin tracking.
3
+ *
4
+ * Why the rule is not `path.startsWith("/admin")`:
5
+ * - `/administer-survey` is ordinary site content and must keep working, so the comparison is per
6
+ * SEGMENT, not per prefix.
7
+ * - `/%61dmin` is compared AFTER one percent-decode, not on the raw bytes. Express (which routes on
8
+ * the raw path) and browsers (which do not decode `%61` in a path) do NOT treat it as `/admin`; a
9
+ * proxy or server that decodes before routing does. Refusing it is deliberate over-refusal — the
10
+ * safe direction for a rule whose job is to keep public redirects and fetches off the admin
11
+ * surface.
12
+ * - `/ADMIN` reaches the same Express mount (Express matches paths case-insensitively by default),
13
+ * so the comparison is case-folded.
14
+ * - `/blog/../admin` is `/admin` by the time a browser issues the request, so dot segments are
15
+ * resolved first.
16
+ *
17
+ */
18
+ /**
19
+ * Two hosts this deployment can never actually reach, used only so `new URL()` has a base to
20
+ * resolve a site-relative reference against. `.invalid` is reserved by RFC 2606 precisely for this.
21
+ *
22
+ * There are TWO because one base is NAMEABLE (t85 independent review, 2026-09-16). With a single
23
+ * base, `//reserved-path-probe.invalid/x` resolves to that very origin, so "did the origin survive"
24
+ * answered yes for a reference that leaves the site — reachable as `/store/buy`'s `returnTo`, which
25
+ * sent `Location: //reserved-path-probe.invalid/x`. Requiring the resolved origin to TRACK whichever
26
+ * base it was given leaves no origin an input can name, which is a structural answer rather than a
27
+ * denylist of the sentinel's spellings (the same reasoning as the probe itself — see
28
+ * {@link checkSiteRelativeTarget}). Both are bare origins, so a reference resolves to the same
29
+ * pathname against either.
30
+ */
31
+ const PROBE_ORIGIN = "http://reserved-path-probe.invalid";
32
+ const SECOND_PROBE_ORIGIN = "http://reserved-path-probe-2.invalid";
33
+ /**
34
+ * Whether `value` contains a C0 or C1 control character.
35
+ *
36
+ * CR/LF in a request target is HTTP request splitting and in a `Location` header is response
37
+ * splitting; NUL and friends are path-truncation tricks.
38
+ *
39
+ * @param required.value - Any string, already decoded or not.
40
+ * @returns `true` if any code unit is in `U+0000`–`U+001F` or `U+007F`–`U+009F`.
41
+ * @complexity O(n) in the string length.
42
+ * @example hasControlCharacter({ value: "/ok" }, {}); // => false
43
+ */
44
+ export function hasControlCharacter({ value }, _optional = {}) {
45
+ for (let index = 0; index < value.length; index += 1) {
46
+ const code = value.charCodeAt(index);
47
+ if (code <= 0x1f || (code >= 0x7f && code <= 0x9f))
48
+ return true;
49
+ }
50
+ return false;
51
+ }
52
+ /**
53
+ * Resolve `.` and `..` segments, RFC 3986 §5.2.4 style, on an already-decoded path.
54
+ *
55
+ * Done by hand rather than with a second `new URL()` pass because a decoded path can contain a
56
+ * literal `?` or `#` (from `%3F`/`%23`), and the URL parser would treat those as a query/fragment
57
+ * delimiter and TRUNCATE the path — turning `/x#/../admin` into `/x` and losing the very segment
58
+ * this check exists to find. A browser does no such thing: it never decodes `%23` before splitting
59
+ * the path, so the truncation would be a false negative, not a match for real behavior.
60
+ *
61
+ * Empty segments are dropped, so `//admin` collapses to `/admin`. That is deliberately stricter
62
+ * than a URL parser (which preserves `//`); over-matching here only ever refuses more.
63
+ *
64
+ * @param path - A decoded path, expected to start with `/`.
65
+ * @returns The path with dot segments removed, always starting with `/`.
66
+ * @complexity O(n) in the path length.
67
+ * @example resolveDotSegments("/blog/../admin"); // => "/admin"
68
+ */
69
+ function resolveDotSegments(path) {
70
+ const out = [];
71
+ for (const segment of path.split("/")) {
72
+ if (segment === "" || segment === ".")
73
+ continue;
74
+ if (segment === "..") {
75
+ out.pop();
76
+ continue;
77
+ }
78
+ out.push(segment);
79
+ }
80
+ return `/${out.join("/")}`;
81
+ }
82
+ /**
83
+ * The actual per-segment rule, on a pathname string that is guaranteed to have come from a real
84
+ * `URL` (see {@link checkSitePathname}, this function's only caller). Kept private: a bare
85
+ * string carries no proof it was ever parsed — the query/fragment stripping, dot-segment removal
86
+ * relative to a real origin, etc. are exactly what `new URL()` already did before that caller
87
+ * reaches this. Do not export this directly.
88
+ *
89
+ * Order is load-bearing: decode ONCE, then resolve dot segments, then compare the first segment
90
+ * case-folded. Decoding first is what catches `/%61dmin` (over-refusal for Express and browsers, a
91
+ * real match for a decoding proxy — see the module doc); resolving dot segments after the decode is
92
+ * what catches `/blog/%2e%2e/admin`. Exactly one decode pass models one decoding intermediary:
93
+ * `/%2561dmin` would need two, so it stays allowed.
94
+ *
95
+ * @param pathname - An already-parsed `URL`'s `.pathname` (no query, no fragment).
96
+ * @returns `{ kind: "ok" }` when it is ordinary site content; otherwise the arm naming the refusal.
97
+ * @complexity O(n) in the pathname length.
98
+ */
99
+ function checkDecodedSitePathname(pathname, reservedSegments) {
100
+ let decoded;
101
+ try {
102
+ decoded = decodeURIComponent(pathname);
103
+ }
104
+ catch {
105
+ return { kind: "malformed-encoding" };
106
+ }
107
+ if (decoded.includes("\\") || hasControlCharacter({ value: decoded }, {}))
108
+ return { kind: "disallowed-character" };
109
+ const first = (resolveDotSegments(decoded).split("/")[1] ?? "").toLowerCase();
110
+ if (reservedSegments.has(first))
111
+ return { kind: "reserved", surface: first };
112
+ return { kind: "ok" };
113
+ }
114
+ /**
115
+ * Classify an already-parsed URL's pathname against the admin application's URL space.
116
+ *
117
+ * Takes the {@link URL} itself, not a bare pathname string, so this cannot be handed a raw,
118
+ * unparsed reference by accident: a string has no way to prove it went through `new URL()` first,
119
+ * and this rule's whole design (see the module doc) depends on comparing the DECODED, dot-resolved
120
+ * form a URL parser would actually produce. A caller that only has a raw string — a stored redirect
121
+ * target, anything from user input — must go through {@link checkSiteRelativeTarget} instead, which
122
+ * parses it (and rejects what doesn't parse) before this check ever runs.
123
+ *
124
+ * PRECONDITION: the caller has already established that `url` is on the site's own origin. This
125
+ * function reads only `pathname`, so `new URL("//admin", base)` (host `admin`, pathname `/`)
126
+ * returns `ok`. It deliberately does not compare origins itself: `platform/routing` cannot use
127
+ * `features/origin`'s normalizer, and a string `URL.origin` comparison is wrong for redirect
128
+ * candidates (`https://site./admin`). Callers: `checkSiteRelativeTarget` (probe-origin check),
129
+ * `site-inspection`'s `resolveWithinOrigin`, and `features/redirects/reserved-destination.ts` (the
130
+ * origin oracle's `isSameOrigin`).
131
+ *
132
+ * @param required.url - An already-parsed `URL`; only `url.pathname` is read.
133
+ * @param required.reservedSegments - First segments reserved by the host, stored case-folded.
134
+ * @returns `{ kind: "ok" }` when it is ordinary site content; otherwise the arm naming the refusal.
135
+ * @complexity O(n) in the pathname length.
136
+ * @example checkSitePathname({ url: new URL("/administer-survey", "http://x.invalid"), reservedSegments: new Set(["admin", "api"]) }, {}); // => { kind: "ok" }
137
+ * @example checkSitePathname({ url: new URL("/%61dmin/settings", "http://x.invalid"), reservedSegments: new Set(["admin", "api"]) }, {}); // => { kind: "reserved", surface: "admin" }
138
+ */
139
+ export function checkSitePathname({ url, reservedSegments }, _optional = {}) {
140
+ return checkDecodedSitePathname(url.pathname, reservedSegments);
141
+ }
142
+ /**
143
+ * Classify a raw, site-relative reference (a stored redirect target, a caller-supplied path)
144
+ * against the admin application's URL space, including the structural check that it is site-
145
+ * relative at all.
146
+ *
147
+ * The structural pass runs FIRST and matters on its own: `/\evil.example` begins with exactly one
148
+ * slash, so a `startsWith("//")` or scheme test calls it site-relative, while `new URL()` — and
149
+ * every browser following a `Location` — reads the backslash as a separator and lands on
150
+ * `evil.example`. Resolving against a probe origin and asserting the origin TRACKED that base is a
151
+ * structural answer to that instead of a pattern someone has to keep correct — done against two
152
+ * different bases so the probe origin itself is not a nameable way to pass (see
153
+ * {@link PROBE_ORIGIN}).
154
+ *
155
+ * @param required.raw - The untrusted reference, expected to be site-relative.
156
+ * @param required.reservedSegments - First segments reserved by the host, stored case-folded.
157
+ * @returns `{ kind: "ok" }` when it stays on this site and names ordinary content; otherwise the
158
+ * arm naming the refusal.
159
+ * @complexity O(n) in the reference length.
160
+ * @example checkSiteRelativeTarget({ raw: "/new", reservedSegments: new Set(["admin", "api"]) }, {}); // => { kind: "ok" }
161
+ * @example checkSiteRelativeTarget({ raw: "/\\evil.example", reservedSegments: new Set(["admin", "api"]) }, {}); // => { kind: "off-origin" }
162
+ */
163
+ export function checkSiteRelativeTarget({ raw, reservedSegments }, _optional = {}) {
164
+ if (hasControlCharacter({ value: raw }, {}))
165
+ return { kind: "disallowed-character" };
166
+ let parsed;
167
+ let reparsed;
168
+ try {
169
+ parsed = new URL(raw, PROBE_ORIGIN);
170
+ reparsed = new URL(raw, SECOND_PROBE_ORIGIN);
171
+ }
172
+ catch {
173
+ return { kind: "unparseable" };
174
+ }
175
+ if (parsed.origin !== PROBE_ORIGIN || reparsed.origin !== SECOND_PROBE_ORIGIN)
176
+ return { kind: "off-origin" };
177
+ return checkSitePathname({ url: parsed, reservedSegments }, {});
178
+ }
179
+ //# sourceMappingURL=site-path.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jini-ai/http-kit",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Generic Express transport primitives, request parsing, response serialization, origin guards and route-pack mounting.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -15,7 +15,7 @@
15
15
  ".": "node",
16
16
  "./rate-limit": "node",
17
17
  "./middleware": "node",
18
- "./verified-origin": "node",
18
+ "./verified-origin": "universal",
19
19
  "./observability": "node"
20
20
  },
21
21
  "runtime": "node"
@@ -67,15 +67,29 @@
67
67
  "access": "public",
68
68
  "registry": "https://registry.npmjs.org"
69
69
  },
70
- "dependencies": {
71
- "express": "^4.21.0",
72
- "@jini-ai/core": "0.4.0",
73
- "@jini-ai/protocol": "0.4.0",
74
- "@jini-ai/platform": "0.5.0"
75
- },
76
70
  "devDependencies": {
77
71
  "@types/express": "^4.17.21",
78
- "@vitest/coverage-v8": "^2.1.9"
72
+ "@vitest/coverage-v8": "^2.1.9",
73
+ "express": "^4.21.0",
74
+ "@jini-ai/core": "0.4.6",
75
+ "@jini-ai/platform": "0.5.7",
76
+ "@jini-ai/protocol": "0.4.4"
77
+ },
78
+ "dependencies": {
79
+ "@jini-ai/protocol": "^0.4.4",
80
+ "@jini-ai/core": "^0.4.6"
81
+ },
82
+ "peerDependencies": {
83
+ "@jini-ai/platform": "^0.5.1",
84
+ "express": "^4.21.0 || ^5.0.0"
85
+ },
86
+ "peerDependenciesMeta": {
87
+ "@jini-ai/platform": {
88
+ "optional": true
89
+ },
90
+ "express": {
91
+ "optional": true
92
+ }
79
93
  },
80
94
  "scripts": {
81
95
  "build": "tsc -p tsconfig.json",
@@ -1,99 +0,0 @@
1
- /**
2
- * @module active-context
3
- *
4
- * Generic "what resource is the caller currently focused on?" channel: an
5
- * in-memory, TTL-scoped pointer a client POSTs to record its current focus
6
- * and GETs to read back (resolved against a real display name via an
7
- * injected lookup). Ported from the routes-classification table's
8
- * `active-context.ts` MIXED row (see `source-map.md`) — the origin's only
9
- * real coupling was `handleGetActive` calling into an OD project store to
10
- * resolve a display name; the TTL store and both handlers were already
11
- * product-neutral, and all handlers are synchronous (no async risk).
12
- *
13
- * The origin's `projectId`/`fileName` fields are generalized here to a
14
- * single opaque `resourceRef` (was `projectId`) plus an optional `detail`
15
- * string (was `fileName` — a sub-locator within that resource), matching
16
- * the source-map's own "renaming to a generic resource ref" note. The
17
- * origin's `deps.getProject` lookup becomes an injected `resolveResource`
18
- * dependency, matching this branch's DI convention (see
19
- * `daemon-status.ts`/`host-tools.ts`: real collaborators supplied by the
20
- * caller rather than read from a global store).
21
- */
22
- import type { Express } from 'express';
23
- import { type AdapterContext } from './adapter.js';
24
- /** How long a recorded focus stays valid before a GET treats it as stale and clears it. */
25
- export declare const ACTIVE_CONTEXT_TTL_MS: number;
26
- interface ActiveContext {
27
- resourceRef: string;
28
- detail: string | null;
29
- ts: number;
30
- }
31
- interface ActiveContextStore {
32
- current: ActiveContext | null;
33
- }
34
- type SetActiveInput = {
35
- kind: 'clear';
36
- } | {
37
- kind: 'set';
38
- resourceRef: string;
39
- detail: string | null;
40
- };
41
- type SetActiveOutput = {
42
- active: false;
43
- } | {
44
- active: true;
45
- resourceRef: string;
46
- detail: string | null;
47
- ts: number;
48
- };
49
- type GetActiveOutput = {
50
- active: false;
51
- } | {
52
- active: true;
53
- resourceRef: string;
54
- resourceName: string | null;
55
- detail: string | null;
56
- ts: number;
57
- ageMs: number;
58
- };
59
- /** A resolved resource's display name. `resolveResource` itself may return `null`/`undefined` (not this type) when the caller has no entry at all for a given resource ref (e.g. unknown or deleted). */
60
- export interface ActiveContextResource {
61
- readonly name?: string | null;
62
- }
63
- /** What a caller must supply to mount the active-context routes. */
64
- export interface ActiveContextDeps {
65
- /**
66
- * Resolves a display name for a resource ref (was OD's project store's
67
- * `getProject`). Injected so this module has no dependency on any
68
- * particular resource store; may return `null`/`undefined` if the ref is
69
- * unknown.
70
- */
71
- resolveResource: (resourceRef: string) => ActiveContextResource | null | undefined;
72
- /** Returns the current time in epoch ms. Defaults to `Date.now` when omitted. */
73
- now?: () => number;
74
- }
75
- /**
76
- * Internal deps threaded to both handlers: the caller-supplied
77
- * {@link ActiveContextDeps} plus the shared in-memory store built once per
78
- * `registerActiveContextRoutes` call, so the two routes see the same state.
79
- */
80
- interface ActiveContextRouteDeps {
81
- store: ActiveContextStore;
82
- resolveResource: ActiveContextDeps['resolveResource'];
83
- now: () => number;
84
- }
85
- /**
86
- * `POST /api/active` — records (or, with `{active: false}`, clears) the
87
- * caller's current resource focus.
88
- */
89
- export declare const setActiveRoute: import("./types.js").JsonRouteSpec<SetActiveInput, SetActiveOutput, ActiveContextRouteDeps>;
90
- /**
91
- * `GET /api/active` — reads back the current resource focus, resolving a
92
- * display name for it, or `{active: false}` if nothing is set or the
93
- * recorded focus has aged past {@link ACTIVE_CONTEXT_TTL_MS}.
94
- */
95
- export declare const getActiveRoute: import("./types.js").JsonRouteSpec<void, GetActiveOutput, ActiveContextRouteDeps>;
96
- /** Mounts both active-context routes on `app`, sharing one in-memory store between them. A pack's `http(app, services)` calls this directly. */
97
- export declare function registerActiveContextRoutes(app: Express, deps: ActiveContextDeps, adapter: AdapterContext): void;
98
- export {};
99
- //# sourceMappingURL=active-context.d.ts.map
@@ -1,77 +0,0 @@
1
- import { createApiError } from '@jini-ai/protocol';
2
- import { defineJsonRoute, mountJsonRoute } from './adapter.js';
3
- import { err, ok } from './types.js';
4
- /** How long a recorded focus stays valid before a GET treats it as stale and clears it. */
5
- export const ACTIVE_CONTEXT_TTL_MS = 5 * 60 * 1000;
6
- function parseSetActive(raw) {
7
- const body = (raw.body ?? {});
8
- if (body.active === false) {
9
- return ok({ kind: 'clear' });
10
- }
11
- const resourceRef = typeof body.resourceRef === 'string' ? body.resourceRef : '';
12
- if (!resourceRef) {
13
- return err(createApiError('BAD_REQUEST', 'resourceRef is required'));
14
- }
15
- const detail = typeof body.detail === 'string' && body.detail.length > 0 ? body.detail : null;
16
- return ok({ kind: 'set', resourceRef, detail });
17
- }
18
- function handleSetActive(input, deps) {
19
- if (input.kind === 'clear') {
20
- deps.store.current = null;
21
- return ok({ active: false });
22
- }
23
- const next = { resourceRef: input.resourceRef, detail: input.detail, ts: deps.now() };
24
- deps.store.current = next;
25
- return ok({ active: true, ...next });
26
- }
27
- function handleGetActive(_input, deps) {
28
- const current = deps.store.current;
29
- if (!current || deps.now() - current.ts > ACTIVE_CONTEXT_TTL_MS) {
30
- deps.store.current = null;
31
- return ok({ active: false });
32
- }
33
- const resource = deps.resolveResource(current.resourceRef);
34
- return ok({
35
- active: true,
36
- resourceRef: current.resourceRef,
37
- resourceName: resource?.name ?? null,
38
- detail: current.detail,
39
- ts: current.ts,
40
- ageMs: deps.now() - current.ts,
41
- });
42
- }
43
- /**
44
- * `POST /api/active` — records (or, with `{active: false}`, clears) the
45
- * caller's current resource focus.
46
- */
47
- export const setActiveRoute = defineJsonRoute({
48
- method: 'post',
49
- path: '/api/active',
50
- requireSameOrigin: true,
51
- parse: parseSetActive,
52
- handle: handleSetActive,
53
- });
54
- /**
55
- * `GET /api/active` — reads back the current resource focus, resolving a
56
- * display name for it, or `{active: false}` if nothing is set or the
57
- * recorded focus has aged past {@link ACTIVE_CONTEXT_TTL_MS}.
58
- */
59
- export const getActiveRoute = defineJsonRoute({
60
- method: 'get',
61
- path: '/api/active',
62
- requireSameOrigin: true,
63
- parse: () => ok(undefined),
64
- handle: handleGetActive,
65
- });
66
- /** Mounts both active-context routes on `app`, sharing one in-memory store between them. A pack's `http(app, services)` calls this directly. */
67
- export function registerActiveContextRoutes(app, deps, adapter) {
68
- const store = { current: null };
69
- const routeDeps = {
70
- store,
71
- resolveResource: deps.resolveResource,
72
- now: deps.now ?? (() => Date.now()),
73
- };
74
- mountJsonRoute(app, setActiveRoute, routeDeps, adapter);
75
- mountJsonRoute(app, getActiveRoute, routeDeps, adapter);
76
- }
77
- //# sourceMappingURL=active-context.js.map
package/dist/agents.d.ts DELETED
@@ -1,64 +0,0 @@
1
- /**
2
- * @module agents
3
- *
4
- * `GET /api/agents` — lists the agents a host can expose to a client,
5
- * including host-probed availability/model metadata when supplied.
6
- * `POST /api/agents/rescan` asks the host to invalidate its discovery cache
7
- * and probe again.
8
- *
9
- * `listAgents` is injected (matching `daemon-status.ts`/`active-context.ts`'s
10
- * DI convention) rather than this module importing `@jini-ai/agent-runtime`
11
- * directly — a host typically already has that package's `AGENT_DEFS` array
12
- * in scope and just needs to project it, and this keeps `@jini-ai/http-kit` from
13
- * taking on a dependency on subprocess discovery. The host owns probing,
14
- * timeouts, caching, PATH/env policy, and the projection of spawn-only
15
- * metadata; this transport only serializes the safe summary.
16
- */
17
- import type { Express } from 'express';
18
- import { type AdapterContext } from './adapter.js';
19
- export interface AgentModelSummary {
20
- readonly id: string;
21
- readonly label: string;
22
- }
23
- /**
24
- * Client-safe agent discovery data. Optional probe fields preserve the
25
- * original static-registry contract for hosts that only expose `{id, name}`.
26
- * Spawn internals (`bin`, resolved path, argv builders, env) never cross HTTP.
27
- */
28
- export interface AgentSummary {
29
- readonly id: string;
30
- readonly name: string;
31
- readonly available?: boolean;
32
- readonly version?: string | null;
33
- readonly authStatus?: 'ok' | 'missing' | 'unknown';
34
- readonly models?: readonly AgentModelSummary[];
35
- readonly reasoningOptions?: readonly AgentModelSummary[];
36
- readonly modelsSource?: 'live' | 'fallback';
37
- readonly supportsCustomModel?: boolean;
38
- readonly diagnostic?: string;
39
- /**
40
- * Whether this runtime can receive external MCP servers (the host application's or this engine's
41
- * own tools) at all, per
42
- * `@jini-ai/agent-runtime`'s `runtimeSupportsExternalTools(def)` — the def-level source of
43
- * truth. `undefined` means the host did not populate this field (pre-existing hosts on an older
44
- * `@jini-ai/http-kit` continue to omit it); a UI gating on this should treat `undefined` the same
45
- * as `true` (no known reason to warn) rather than assuming the worst.
46
- */
47
- readonly supportsTools?: boolean;
48
- }
49
- export interface AgentsHttpDeps {
50
- /** Returns the host's cached or freshly resolved client-safe agent inventory. */
51
- readonly listAgents: () => Promise<readonly AgentSummary[]> | readonly AgentSummary[];
52
- /** Forces host-owned discovery to run again. Falls back to `listAgents` when omitted. */
53
- readonly rescanAgents?: () => Promise<readonly AgentSummary[]> | readonly AgentSummary[];
54
- }
55
- export interface AgentListResponse {
56
- readonly agents: readonly AgentSummary[];
57
- }
58
- /** `GET /api/agents` — read-only, no side effects; matches `runListRoute`/`runStatusRoute`'s posture of not requiring same-origin. */
59
- export declare const agentListRoute: import("./types.js").JsonRouteSpec<void, AgentListResponse, AgentsHttpDeps>;
60
- /** `POST /api/agents/rescan` — explicit state refresh, protected by the local same-origin gate. */
61
- export declare const agentRescanRoute: import("./types.js").JsonRouteSpec<void, AgentListResponse, AgentsHttpDeps>;
62
- /** Mounts the read and explicit-rescan agent discovery routes. */
63
- export declare function registerAgentRoutes(app: Express, deps: AgentsHttpDeps, adapter: AdapterContext): void;
64
- //# sourceMappingURL=agents.d.ts.map
package/dist/agents.js DELETED
@@ -1,23 +0,0 @@
1
- import { defineJsonRoute, mountJsonRoute } from './adapter.js';
2
- import { ok } from './types.js';
3
- /** `GET /api/agents` — read-only, no side effects; matches `runListRoute`/`runStatusRoute`'s posture of not requiring same-origin. */
4
- export const agentListRoute = defineJsonRoute({
5
- method: 'get',
6
- path: '/api/agents',
7
- parse: () => ok(undefined),
8
- handle: async (_input, deps) => ok({ agents: await deps.listAgents() }),
9
- });
10
- /** `POST /api/agents/rescan` — explicit state refresh, protected by the local same-origin gate. */
11
- export const agentRescanRoute = defineJsonRoute({
12
- method: 'post',
13
- path: '/api/agents/rescan',
14
- requireSameOrigin: true,
15
- parse: () => ok(undefined),
16
- handle: async (_input, deps) => ok({ agents: await (deps.rescanAgents ?? deps.listAgents)() }),
17
- });
18
- /** Mounts the read and explicit-rescan agent discovery routes. */
19
- export function registerAgentRoutes(app, deps, adapter) {
20
- mountJsonRoute(app, agentListRoute, deps, adapter);
21
- mountJsonRoute(app, agentRescanRoute, deps, adapter);
22
- }
23
- //# sourceMappingURL=agents.js.map