@jini-ai/http-kit 0.7.1 → 0.7.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.
- package/CHANGELOG.md +8 -0
- package/dist/active-context.d.ts +99 -0
- package/dist/active-context.js +77 -0
- package/dist/agents.d.ts +64 -0
- package/dist/agents.js +23 -0
- package/dist/attachments.d.ts +534 -0
- package/dist/attachments.js +1032 -0
- package/dist/cancel-owned-runs.d.ts +44 -0
- package/dist/cancel-owned-runs.js +35 -0
- package/dist/component-catalog.d.ts +74 -0
- package/dist/component-catalog.js +74 -0
- package/dist/connectors.d.ts +165 -0
- package/dist/connectors.js +474 -0
- package/dist/daemon-status.d.ts +72 -0
- package/dist/daemon-status.js +60 -0
- package/dist/db-ops.d.ts +116 -0
- package/dist/db-ops.js +191 -0
- package/dist/delegated-tools.d.ts +146 -0
- package/dist/delegated-tools.js +286 -0
- package/dist/frontend-control.d.ts +131 -0
- package/dist/frontend-control.js +77 -0
- package/dist/frontend-sessions.d.ts +100 -0
- package/dist/frontend-sessions.js +180 -0
- package/dist/health.d.ts +91 -0
- package/dist/health.js +53 -0
- package/dist/host-tools.d.ts +174 -0
- package/dist/host-tools.js +338 -0
- package/dist/media.d.ts +131 -0
- package/dist/media.js +352 -0
- package/dist/memory.d.ts +230 -0
- package/dist/memory.js +331 -0
- package/dist/model-proxy.d.ts +45 -0
- package/dist/model-proxy.js +619 -0
- package/dist/origin-validation.d.ts +64 -0
- package/dist/origin-validation.js +226 -0
- package/dist/read-only-tools.d.ts +67 -0
- package/dist/read-only-tools.js +59 -0
- package/dist/remote-run-events.d.ts +66 -0
- package/dist/remote-run-events.js +230 -0
- package/dist/research.d.ts +42 -0
- package/dist/research.js +316 -0
- package/dist/route-manifest.d.ts +31 -0
- package/dist/route-manifest.js +103 -0
- package/dist/routines.d.ts +114 -0
- package/dist/routines.js +320 -0
- package/dist/runs.d.ts +79 -0
- package/dist/runs.js +232 -0
- package/dist/terminals.d.ts +125 -0
- package/dist/terminals.js +349 -0
- package/dist/tool-catalog.d.ts +68 -0
- package/dist/tool-catalog.js +68 -0
- package/dist/workspace-root.d.ts +69 -0
- package/dist/workspace-root.js +63 -0
- package/dist/xai.d.ts +86 -0
- package/dist/xai.js +668 -0
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,99 @@
|
|
|
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
|
|
@@ -0,0 +1,77 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
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
|